From 25f084f9dbb5047c5c91aedcb582d35f4ff95395 Mon Sep 17 00:00:00 2001 From: asepharyana Date: Tue, 14 Jul 2026 08:12:37 +0700 Subject: [PATCH] feat(hive-mind): implement multi-agent orchestration with cognitive cycles - Introduced a new hive-mind architecture that allows the Core Intelligence to issue directives to anonymous processing nodes. - Each node executes its directive and merges output into a collective state, visible to all nodes in real-time. - Added support for dynamic cognitive cycles, enabling flexible task management. - Implemented documentation generation for hive-mind runs, ensuring a durable record of decisions and actions. - Refactored existing company pipeline tools to align with the new hive-mind structure, replacing division-specific prompts with a more generalized approach. - Updated workflow rendering to accommodate hive-mind nodes and their system-assigned designations. - Enhanced error handling and validation for cognitive cycle plans. --- .claude/skills/commit-convention/SKILL.md | 47 +++ CLAUDE.md | 112 +----- README.md | 28 +- docs/CODEMAPS/backend.md | 4 +- src-misc/division-documenter-prompt.txt | 23 -- src-misc/division-implementer-prompt.txt | 21 -- src-misc/division-planner-prompt.txt | 35 -- src-misc/division-tester-prompt.txt | 28 -- src-misc/quality-reviewer-prompt.txt | 19 - src/app/runtime/actions/mod.rs | 142 ++++---- src/app/subagent/auto.rs | 123 +++---- src/app/subagent/division.rs | 308 +++++----------- src/app/subagent/engine.rs | 4 +- src/app/workflow/company.rs | 406 ---------------------- src/app/workflow/docs.rs | 99 ++++++ src/app/workflow/engine.rs | 78 +++-- src/app/workflow/hive_mind.rs | 374 ++++++++++++++++++++ src/app/workflow/mod.rs | 3 +- src/app/workflow/script.rs | 13 + src/resources.rs | 6 - src/tool/mod.rs | 2 +- src/tool/workflow.rs | 132 ++++--- src/view/workflow.rs | 113 ++---- 23 files changed, 895 insertions(+), 1225 deletions(-) create mode 100644 .claude/skills/commit-convention/SKILL.md delete mode 100644 src-misc/division-documenter-prompt.txt delete mode 100644 src-misc/division-implementer-prompt.txt delete mode 100644 src-misc/division-planner-prompt.txt delete mode 100644 src-misc/division-tester-prompt.txt delete mode 100644 src-misc/quality-reviewer-prompt.txt delete mode 100644 src/app/workflow/company.rs create mode 100644 src/app/workflow/docs.rs create mode 100644 src/app/workflow/hive_mind.rs diff --git a/.claude/skills/commit-convention/SKILL.md b/.claude/skills/commit-convention/SKILL.md new file mode 100644 index 0000000..44c6a97 --- /dev/null +++ b/.claude/skills/commit-convention/SKILL.md @@ -0,0 +1,47 @@ +--- +name: commit-convention +description: Conventional Commits format and version-bump rules for this repo (Bahasa Indonesia commit style). Use when creating a git commit in zesdex. +--- + +# Commit Convention + +Gunakan **Conventional Commits** untuk semua commit. Format: + +``` +(): +``` + +**Type & efek ke versi:** + +| Type | Bump | Kapan pakai | +|-------------|-------|------------------------------------------| +| `feat` | minor | Fitur baru | +| `fix` | patch | Perbaikan bug | +| `chore` | patch | Maintenance, update deps, dll | +| `docs` | patch | Perubahan dokumentasi/comment | +| `refactor` | patch | Refactor kode tanpa perubahan fungsional | +| `test` | patch | Nambah/ubah test | +| `style` | patch | Formatting, whitespace, lint | +| `perf` | patch | Optimasi performa | +| `ci` | patch | Perubahan CI/CD | + +**Catatan:** +- **Semua type menghasilkan release** (patch minimal). Tidak ada commit yang "skip release". +- Tambahkan `BREAKING CHANGE:` di body commit untuk bump **major**. +- **Scope** opsional, tapi direkomendasikan (misal `feat(agent):`, `fix(ipc):`). + +### Contoh + +``` +feat(tool): add batch file delete + +chore: bump reqwest to 0.12 + +refactor(harness): flatten guard pipeline + +fix(ipc): reconnect loop on socket timeout + +docs: add architecture diagram to README + +BREAKING CHANGE: IPC frame header changed from 4-byte to 8-byte length +``` diff --git a/CLAUDE.md b/CLAUDE.md index 089ceb2..5d06970 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -2,36 +2,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. -## Build & Test - -```bash -# Build (debug) -cargo build - -# Release build -cargo build --release - -# Run all tests -cargo test - -# Run a single test -cargo test test_name - -# Lint -cargo clippy - -# Lint with warnings-as-errors -cargo clippy -- -D warnings -``` - -Test modules are located inline in production files (not a separate `tests/` dir): -- `src/app/harness.rs` — guard/verdict parsing tests -- `src/app/runtime/stream/mod.rs` — SSE parser tests -- `src/model/memory.rs` — memory CRUD + slugify tests -- `src/model/editlog.rs` — edit log append/reload tests -- `src/tool/fs/helpers.rs` — tool argument extraction tests - -Tests use `#[cfg(test)] mod tests` blocks. There are 37 unit tests total. +Tests use `#[cfg(test)] mod tests` blocks inline in production files (not a separate `tests/` dir). Tracing output goes to `~/.local/share/zesdex/zesdex.log`. Set `RUST_LOG=debug` for verbose logging. @@ -49,23 +20,7 @@ Detailed architecture documentation is in `docs/CODEMAPS/`: | [`docs/CODEMAPS/data.md`](docs/CODEMAPS/data.md) | Persistence, SQLite msglog, memory files, settings/config | | [`docs/CODEMAPS/dependencies.md`](docs/CODEMAPS/dependencies.md) | 23 Rust crates, 5 external services | -### Entry Points - -`src/main.rs` — three modes: -- **Single-process** (default): TUI + agent loop in one process -- **Daemon** (`--daemon`): background Unix socket server, handles LLM calls -- **Attach** (`--attach `): TUI-only client that connects to a daemon - -### Core Flow - -``` -Controller (key input → Action) → Event Loop → LLM stream → Tool execution → State mutation → TUI render - │ │ │ - │ src/controller/input.rs │ src/app/runtime/actions/ │ src/tool/ - └── maps keys to Action enum │── dispatches Action::* └── 37 tool impls - │ matching on Action variant - │── applies state mutations -``` +`docs/runs/` holds an auto-generated audit trail: one markdown file per hive-mind convergence (see below), written deterministically by `app::workflow::docs::write_hive_mind_convergence` — not hand-maintained like `docs/CODEMAPS/`. ### Key Patterns @@ -77,60 +32,21 @@ Controller (key input → Action) → Event Loop → LLM stream → Tool executi - **Tools** — `trait Tool { fn name() -> &str, fn run() -> Result }`, 28 impls, gated by `Harness`. - **Shell safety** — `tool/shell_filter/` blocks credential leaks and destructive git commands. -### Company Pipeline (Division Architecture) +### Hive-Mind Orchestration (Machine Intelligence) -- **5 divisions** in `src/app/subagent/division.rs`: Strategy, Engineering, Quality, Security, Documentation. -- **Pipeline orchestrator** in `src/app/workflow/company.rs`: two modes: - - `run_company_pipeline()` — full 5-division pipeline - - `run_company_pipeline_quick()` — 3-division (Strategy → Engineering → Quality) -- **Auto-CEO trigger** in `run_agent_turn()` (`actions/mod.rs`): detects complex requests via `is_complex_request()` heuristics, auto-delegates to pipeline. -- **Override** via `/pipeline full|quick|skip` sets `MiscState::pipeline_override`, consumed on next turn. -- **Live division progress** in TUI panel (`view/workflow.rs`): shows division name + current tool via `AgentStatus::progress`. +- **A single Core Intelligence spawning anonymous processing nodes.** The Core Intelligence (main agent) compiles a cognitive cycle plan per task: an ordered list of cycles, each cycle a set of processing nodes that run in parallel. Each node's sole identity is its directive (what to do) and an access tier. Cycle count and nodes-per-cycle are entirely Core-Intelligence output. +- **Access tiers** in `src/app/subagent/division.rs` (`tool_scope` module): tool access is granted per node via one of three tiers (`read` / `write` / `full`, see `tool_scope::tools_for`) picked by the Core Intelligence based on what each node's directive actually needs. +- **Orchestrator** in `src/app/workflow/hive_mind.rs`: `run_hive_mind()` executes a `CognitiveCyclePlan { cycles: Vec> }` cycle-by-cycle. Node IDs are system-assigned coordinates (e.g. `"Node-0-1"`). +- **Continuous collective state, not phase-boundary sync**: `engine::execute_primitive`'s `ScopedAgent` arm merges each node's complete output into the shared collective-state channel the instant that node finishes — not after its whole parallel cohort completes — so sibling/later nodes see it in real time. +- **Consensus synthesis, not a per-node summary**: after all cycles complete, `synthesize_consensus()` spawns one final read-only node whose sole directive is to reconcile the entire collective state into a single consensus assessment — a real reasoning pass, not string concatenation, since node outputs can overlap or conflict. +- **Auto-trigger** in `run_agent_turn()` (`actions/mod.rs`): `is_complex_request()` heuristics decide only whether to ask the Core Intelligence to compile a plan at all — the plan's shape is fully dynamic. +- **`hive_mind` tool** (`src/tool/workflow.rs`) is the manual entry point: the calling LLM supplies its own `cycles` array of `{directive, access}` directly. +- **Guaranteed documentation**: after every convergence, `src/app/workflow/docs.rs::write_hive_mind_convergence()` deterministically (not an LLM step, not skippable) writes every node's full output plus the final consensus to `docs/runs/-.md`. +- **Live node progress** in TUI panel (`view/workflow.rs`): shows node designation + current tool via `AgentStatus::progress`. - **Auto inline review** after each edit: `src/app/subagent/auto.rs` — `spawn_quick_review()` injects verdict back into LLM conversation. -- **Background subagents** (test-gen, arch-review, security-review) fire asynchronously at turn end via `TurnEvent::SystemNote`. +- **Background subagents** (test-gen, arch-review, security-review) fire asynchronously at turn end via `TurnEvent::SystemNote`, retrying once on failure and escalating to a blocking (`ESCALATED:`-prefixed, `ToastKind::Error`) notice if the retry also fails. -## Commit Convention - -Gunakan **Conventional Commits** untuk semua commit. Format: - -``` -(): -``` - -**Type & efek ke versi:** - -| Type | Bump | Kapan pakai | -|-------------|-------|------------------------------------------| -| `feat` | minor | Fitur baru | -| `fix` | patch | Perbaikan bug | -| `chore` | patch | Maintenance, update deps, dll | -| `docs` | patch | Perubahan dokumentasi/comment | -| `refactor` | patch | Refactor kode tanpa perubahan fungsional | -| `test` | patch | Nambah/ubah test | -| `style` | patch | Formatting, whitespace, lint | -| `perf` | patch | Optimasi performa | -| `ci` | patch | Perubahan CI/CD | - -**Catatan:** -- **Semua type menghasilkan release** (patch minimal). Tidak ada commit yang "skip release". -- Tambahkan `BREAKING CHANGE:` di body commit untuk bump **major**. -- **Scope** opsional, tapi direkomendasikan (misal `feat(agent):`, `fix(ipc):`). - -### Contoh - -``` -feat(tool): add batch file delete - -chore: bump reqwest to 0.12 - -refactor(harness): flatten guard pipeline - -fix(ipc): reconnect loop on socket timeout - -docs: add architecture diagram to README - -BREAKING CHANGE: IPC frame header changed from 4-byte to 8-byte length -``` +Commit convention (Conventional Commits, Bahasa Indonesia): see the `commit-convention` skill. ## Code Documentation diff --git a/README.md b/README.md index 88329c6..43a9c78 100644 --- a/README.md +++ b/README.md @@ -25,20 +25,14 @@ Zesdex is a Rust-powered AI assistant that operates directly in your terminal vi | **Git** | `git_operator`, `git_worktree`, `git_cred` | | **Memory** | `remember`, `recall`, `forget` | | **Planning** | `plan_enter`, `plan_ready`, `seqthink` | -| **Workflow** | `workflow_run`, `note_finding`, `read_findings`, `company_pipeline` | +| **Workflow** | `workflow_run`, `note_finding`, `read_findings`, `hive_mind` | | **Utility** | `cd`, `dir_list`, `dir_cache_update`, `pong`, `todowrite`, `todofinish` | | **Agent** | `spawn_agents`, `spawn_pipeline` | | **LSP** | `lsp_connect`, `lsp_diagnostics`, `lsp_hover`, `lsp_completion`, `lsp_definition`, `lsp_references`, `lsp_disconnect` | ### Intelligence -- **Company Pipeline** — Autonomous agent orchestration modeled as a company with specialized divisions. The CEO (main agent) automatically delegates work to 5 divisions in sequence: - - ``` - Strategy → Engineering → Quality → Security → Documentation - ``` - - Each division has a dedicated role, toolset, and system prompt. Controlled via `/pipeline full|quick|skip`. +- **Hive-Mind Orchestration** — Autonomous agent orchestration modeled as a distributed machine intelligence (à la Stellaris). The Core Intelligence (main agent) compiles a cognitive cycle plan per task — an ordered list of cycles, each a set of anonymous processing nodes that run in parallel. Every node carries only a directive (what to do) and an access tier (`read`/`write`/`full`); cycle count and nodes-per-cycle are decided per task, not fixed. Every node's output merges into a shared collective state the instant it completes, and a final synthesis node reconciles it into one consensus. Every convergence is written to `docs/runs/*.md`. Manual entry point: the `hive_mind` tool. - **Workflow Engine** — Orchestrate complex multi-step tasks with parallel sub-agents, pipelines, and phased execution. Spawn independent workers that share findings in real-time. - **Self-Learning** — Persistent memory system that stores lessons, references, and project knowledge across sessions. Memories include provenance tracking, lifecycle management, and scope isolation. @@ -96,7 +90,8 @@ src/ │ ├── workflow/ # Workflow engine │ │ ├── script.rs # Workflow script DSL │ │ ├── engine.rs # Workflow executor -│ │ └── company.rs # Company pipeline orchestrator +│ │ ├── hive_mind.rs # Hive-mind orchestrator +│ │ └── docs.rs # Deterministic docs/runs/*.md writer │ ├── mcp/ # MCP client manager │ │ └── manager.rs # MCP server lifecycle and tool exposure │ ├── subagent/ # Sub-agent management @@ -239,12 +234,15 @@ RUST_LOG=debug zesdex | `/help` | Show help | | `/clear` | Clear transcript | | `/model` | Select AI model provider | -| `/pipeline` | Show current pipeline mode | -| `/pipeline full` | Force full company pipeline (5 divisions) on next request | -| `/pipeline quick` | Force quick pipeline (3 divisions) on next request | -| `/pipeline skip` | Skip pipeline — handle next request directly | -| `/exit` | Exit application | -| `/settings` | Open settings | +| `/workflow` | Open the workflow panel | +| `/workflow run