brainclaw 1.8.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/README.md +592 -505
  2. package/dist/brainclaw-vscode.vsix +0 -0
  3. package/dist/cli.js +138 -13
  4. package/dist/commands/add-step.js +1 -1
  5. package/dist/commands/bootstrap.js +2 -26
  6. package/dist/commands/check-security-mcp.js +50 -33
  7. package/dist/commands/check-security.js +86 -43
  8. package/dist/commands/claim.js +22 -21
  9. package/dist/commands/confirm.js +26 -0
  10. package/dist/commands/context-diff.js +1 -1
  11. package/dist/commands/dispatch-watch.js +142 -0
  12. package/dist/commands/doctor.js +113 -2
  13. package/dist/commands/estimation-report.js +115 -16
  14. package/dist/commands/harvest.js +286 -23
  15. package/dist/commands/hooks.js +73 -73
  16. package/dist/commands/init.js +124 -22
  17. package/dist/commands/install-hooks.js +78 -78
  18. package/dist/commands/loops-handlers.js +4 -0
  19. package/dist/commands/mcp-read-handlers.js +253 -41
  20. package/dist/commands/mcp.js +664 -102
  21. package/dist/commands/memory.js +21 -17
  22. package/dist/commands/migrate.js +81 -17
  23. package/dist/commands/prune.js +78 -4
  24. package/dist/commands/reflect.js +26 -20
  25. package/dist/commands/register-agent.js +57 -1
  26. package/dist/commands/repair.js +20 -0
  27. package/dist/commands/session-end.js +15 -6
  28. package/dist/commands/session-start.js +18 -1
  29. package/dist/commands/setup-security.js +39 -18
  30. package/dist/commands/setup.js +26 -27
  31. package/dist/commands/stale.js +16 -2
  32. package/dist/commands/switch.js +26 -5
  33. package/dist/commands/uninstall.js +126 -34
  34. package/dist/commands/update-step.js +6 -0
  35. package/dist/commands/version.js +1 -1
  36. package/dist/commands/worktree.js +60 -0
  37. package/dist/core/actions.js +12 -3
  38. package/dist/core/agent-capability.js +30 -17
  39. package/dist/core/agent-files.js +963 -666
  40. package/dist/core/agent-integrations.js +0 -3
  41. package/dist/core/agent-inventory.js +67 -0
  42. package/dist/core/agent-registry.js +163 -29
  43. package/dist/core/agentrun-reconciler.js +33 -2
  44. package/dist/core/agentruns.js +7 -1
  45. package/dist/core/ai-agent-detection.js +31 -44
  46. package/dist/core/archival.js +15 -9
  47. package/dist/core/assignment-reconciler.js +56 -0
  48. package/dist/core/assignment-sweeper.js +127 -4
  49. package/dist/core/assignments.js +69 -11
  50. package/dist/core/bootstrap.js +233 -67
  51. package/dist/core/brainclaw-version.js +22 -0
  52. package/dist/core/candidates.js +21 -1
  53. package/dist/core/claims.js +313 -150
  54. package/dist/core/codev-prompts.js +38 -38
  55. package/dist/core/config.js +6 -1
  56. package/dist/core/context-diff.js +148 -20
  57. package/dist/core/context.js +129 -8
  58. package/dist/core/coordination.js +22 -3
  59. package/dist/core/default-profiles/doctor.yaml +11 -11
  60. package/dist/core/default-profiles/janitor.yaml +11 -11
  61. package/dist/core/default-profiles/onboarder.yaml +11 -11
  62. package/dist/core/default-profiles/reviewer.yaml +13 -13
  63. package/dist/core/dispatch-status.js +79 -5
  64. package/dist/core/dispatcher.js +65 -12
  65. package/dist/core/entity-operations.js +74 -27
  66. package/dist/core/entity-registry.js +31 -5
  67. package/dist/core/event-log.js +138 -21
  68. package/dist/core/events/checkpoint.js +258 -0
  69. package/dist/core/events/genesis.js +220 -0
  70. package/dist/core/events/journal.js +507 -0
  71. package/dist/core/events/materialize.js +126 -0
  72. package/dist/core/events/registry-post-image.js +110 -0
  73. package/dist/core/events/verify.js +109 -0
  74. package/dist/core/execution-adapters.js +23 -0
  75. package/dist/core/execution.js +1 -1
  76. package/dist/core/facade-schema.js +38 -0
  77. package/dist/core/gc-semantic.js +130 -5
  78. package/dist/core/handoff-snapshot.js +68 -0
  79. package/dist/core/ids.js +19 -8
  80. package/dist/core/instruction-templates.js +34 -115
  81. package/dist/core/io.js +39 -3
  82. package/dist/core/json-store.js +10 -1
  83. package/dist/core/lock.js +153 -28
  84. package/dist/core/loops/bootstrap-acquire.js +25 -1
  85. package/dist/core/loops/facade-schema.js +2 -0
  86. package/dist/core/loops/hooks/survey-signals-baseline.js +36 -0
  87. package/dist/core/loops/index.js +1 -0
  88. package/dist/core/loops/presets/bootstrap.js +7 -0
  89. package/dist/core/loops/store.js +17 -0
  90. package/dist/core/loops/verbs.js +24 -2
  91. package/dist/core/markdown.js +8 -76
  92. package/dist/core/mcp-command-resolution.js +245 -0
  93. package/dist/core/memory-compactor.js +5 -3
  94. package/dist/core/memory-lifecycle.js +282 -0
  95. package/dist/core/merge-risk.js +150 -0
  96. package/dist/core/messaging.js +10 -3
  97. package/dist/core/migration.js +11 -1
  98. package/dist/core/observer-mode.js +26 -0
  99. package/dist/core/operations/memory-mutation.js +90 -65
  100. package/dist/core/operations/plan.js +27 -1
  101. package/dist/core/protocol-skills.js +210 -0
  102. package/dist/core/reflection-safety.js +6 -7
  103. package/dist/core/reputation.js +84 -2
  104. package/dist/core/runtime-signals.js +72 -10
  105. package/dist/core/runtime.js +84 -1
  106. package/dist/core/schema.js +114 -0
  107. package/dist/core/search.js +19 -2
  108. package/dist/core/security-detectors.js +125 -0
  109. package/dist/core/security-extract.js +189 -0
  110. package/dist/core/security-guard.js +217 -139
  111. package/dist/core/security-packages.js +121 -0
  112. package/dist/core/security-scoring.js +76 -9
  113. package/dist/core/security.js +34 -2
  114. package/dist/core/sequence.js +11 -2
  115. package/dist/core/setup-flow.js +141 -13
  116. package/dist/core/spawn-check.js +16 -2
  117. package/dist/core/staleness.js +73 -2
  118. package/dist/core/state.js +250 -54
  119. package/dist/core/store-resolution.js +45 -12
  120. package/dist/core/worktree.js +90 -26
  121. package/dist/facts.js +8 -8
  122. package/dist/facts.json +7 -7
  123. package/docs/PROTOCOL.md +223 -0
  124. package/docs/adapters/openclaw.md +43 -43
  125. package/docs/architecture/project-refs.md +328 -328
  126. package/docs/cli.md +2097 -2096
  127. package/docs/concepts/coordination.md +52 -52
  128. package/docs/concepts/coordinator-runbook.md +129 -0
  129. package/docs/concepts/dispatch-lifecycle.md +245 -245
  130. package/docs/concepts/event-log-store.md +928 -0
  131. package/docs/concepts/ideation-loop.md +317 -317
  132. package/docs/concepts/loop-engine.md +520 -511
  133. package/docs/concepts/mcp-governance.md +268 -268
  134. package/docs/concepts/memory.md +89 -88
  135. package/docs/concepts/multi-agent-workflows.md +167 -167
  136. package/docs/concepts/observer-protocol.md +361 -0
  137. package/docs/concepts/parallel-merge-protocol.md +71 -0
  138. package/docs/concepts/plans-and-claims.md +217 -174
  139. package/docs/concepts/project-md-convention.md +35 -35
  140. package/docs/concepts/runtime-notes.md +38 -38
  141. package/docs/concepts/skills.md +78 -0
  142. package/docs/concepts/troubleshooting.md +254 -254
  143. package/docs/concepts/workspace-bootstrapping.md +142 -81
  144. package/docs/context-format-changelog.md +35 -35
  145. package/docs/context-format.md +48 -48
  146. package/docs/index.md +65 -65
  147. package/docs/integrations/agents.md +162 -162
  148. package/docs/integrations/claude-code.md +23 -23
  149. package/docs/integrations/cline.md +87 -88
  150. package/docs/integrations/codex.md +2 -2
  151. package/docs/integrations/continue.md +60 -60
  152. package/docs/integrations/copilot.md +82 -80
  153. package/docs/integrations/cursor.md +23 -23
  154. package/docs/integrations/kilocode.md +72 -72
  155. package/docs/integrations/mcp.md +377 -377
  156. package/docs/integrations/mistral-vibe.md +122 -122
  157. package/docs/integrations/openclaw.md +99 -98
  158. package/docs/integrations/opencode.md +84 -84
  159. package/docs/integrations/overview.md +122 -122
  160. package/docs/integrations/roo.md +74 -74
  161. package/docs/integrations/windsurf.md +83 -83
  162. package/docs/mcp-schema-changelog.md +360 -329
  163. package/docs/playbooks/integration/index.md +121 -121
  164. package/docs/playbooks/orchestration.md +37 -0
  165. package/docs/playbooks/productivity/index.md +99 -99
  166. package/docs/playbooks/team/index.md +117 -117
  167. package/docs/product/agent-first-model.md +184 -184
  168. package/docs/product/entity-model-audit.md +462 -462
  169. package/docs/product/positioning.md +86 -86
  170. package/docs/quickstart-existing-project.md +107 -107
  171. package/docs/quickstart.md +148 -147
  172. package/docs/release-maintenance.md +79 -79
  173. package/docs/reputation.md +52 -52
  174. package/docs/review.md +45 -45
  175. package/docs/security.md +212 -53
  176. package/docs/server-operations.md +118 -118
  177. package/docs/storage.md +110 -108
  178. package/package.json +86 -69
@@ -1,88 +1,89 @@
1
- # Memory
2
-
3
- brainclaw uses the term **memory** in an explicit, workspace-oriented sense.
4
-
5
- This is not an opaque cloud memory feature.
6
- It is shared project state stored locally in a structured, inspectable form.
7
-
8
- ## What memory includes
9
-
10
- Durable memory can include:
11
-
12
- - **instructions** — agent workflow instructions written to native formats (CLAUDE.md, .cursor/rules/, etc.)
13
- - **constraints** — active project constraints that agents must respect
14
- - **decisions** — logged architectural or process decisions
15
- - **traps** — documented pitfalls to avoid (with severity and remediation)
16
- - **handoffs** — structured context transfers between agents or sessions
17
- - **plans** — shared work items with status, priority, and estimation data
18
- - **claims** — active file/scope ownership signals for collision avoidance
19
- - **runtime notes** — short-lived observations from the current session
20
- - **audit log** — timestamped record of all brainclaw operations in the workspace
21
-
22
- These are the pieces of context that should survive across sessions and be readable by both humans and agents.
23
-
24
- ## Durable vs runtime
25
-
26
- A useful mental model is to separate:
27
-
28
- ### Durable memory
29
- Shared project knowledge worth keeping.
30
-
31
- Examples: constraints, decisions, traps, completed plans, handoffs.
32
-
33
- Shared traps now have a lifecycle too: `active`, `resolved`, or `expired`. Active views such as generated context, status, and `project.md` prioritize only active traps so old machine-setup issues stop polluting the current working set, while the canonical memory still keeps resolved traps for audit and search.
34
-
35
- These live as individual JSON files under `.brainclaw/memory/` (constraints, decisions, traps, instructions) and `.brainclaw/coordination/` (plans, claims, handoffs). They are versioned in `.brainclaw/.git` and shared via Git.
36
-
37
- ### Runtime memory
38
- Operational observations that may be short-lived, host-specific, or private.
39
-
40
- Examples: "this API key only works in staging", "the test server is slow today", temporary notes during a session.
41
-
42
- Runtime notes are stored separately and can be given a TTL so they expire automatically.
43
-
44
- Not everything seen during execution should become canonical memory immediately.
45
-
46
- ## Why explicit memory matters
47
-
48
- Without explicit memory, project context tends to scatter across:
49
-
50
- - chat history
51
- - agent prompts
52
- - personal notes
53
- - unstated assumptions
54
- - hidden tool memory
55
-
56
- brainclaw makes this context visible and versionable.
57
-
58
- ## Readable vs canonical
59
-
60
- brainclaw keeps:
61
-
62
- - canonical structured JSON as the source of truth (individual files under `.brainclaw/memory/` and `.brainclaw/coordination/`)
63
- - a derived readable view (`project.md`) regenerated best-effort from canonical state
64
- - native agent instruction files (`CLAUDE.md`, `.cursor/rules/brainclaw.md`, etc.) generated via `brainclaw export`
65
-
66
- This balances machine reliability with human readability.
67
-
68
- The generated files are **local-only** and should not be committed to Git — each developer regenerates them from their own `.brainclaw/` store. Add them to `.gitignore` (brainclaw does this automatically during `init`).
69
-
70
- ## Accessing memory
71
-
72
- ```bash
73
- brainclaw context # full context as text
74
- brainclaw context --json # full context as JSON (for agents)
75
- brainclaw agent-board # live plan + claim board
76
- brainclaw claim list # active claims
77
- brainclaw plan list # all plans
78
- brainclaw audit # audit log
79
- ```
80
-
81
- MCP tools expose the same data to agents that support the Model Context Protocol.
82
-
83
- ## Related pages
84
-
85
- - [coordination.md](coordination.md)
86
- - [runtime-notes.md](runtime-notes.md)
87
- - [workspace-bootstrapping.md](workspace-bootstrapping.md)
88
- - [plans-and-claims.md](plans-and-claims.md)
1
+ # Memory
2
+
3
+ brainclaw uses the term **memory** in an explicit, workspace-oriented sense.
4
+
5
+ This is not an opaque cloud memory feature.
6
+ It is shared project state stored locally in a structured, inspectable form.
7
+
8
+ ## What memory includes
9
+
10
+ Durable memory can include:
11
+
12
+ - **instructions** — agent workflow instructions written to native formats (CLAUDE.md, .cursor/rules/, etc.)
13
+ - **constraints** — active project constraints that agents must respect
14
+ - **decisions** — logged architectural or process decisions
15
+ - **traps** — documented pitfalls to avoid (with severity and remediation)
16
+ - **handoffs** — structured context transfers between agents or sessions
17
+ - **plans** — shared work items with status, priority, and estimation data
18
+ - **claims** — active file/scope ownership signals for collision avoidance
19
+ - **runtime notes** — short-lived observations from the current session
20
+ - **audit log** — timestamped record of all brainclaw operations in the workspace
21
+
22
+ These are the pieces of context that should survive across sessions and be readable by both humans and agents.
23
+
24
+ ## Durable vs runtime
25
+
26
+ A useful mental model is to separate:
27
+
28
+ ### Durable memory
29
+ Shared project knowledge worth keeping.
30
+
31
+ Examples: constraints, decisions, traps, completed plans, handoffs.
32
+
33
+ Shared traps now have a lifecycle too: `active`, `resolved`, or `expired`. Active views such as generated context and status prioritize only active traps so old machine-setup issues stop polluting the current working set, while the canonical memory still keeps resolved traps for audit and search.
34
+
35
+ These live as individual JSON files under `.brainclaw/memory/` (constraints, decisions, traps, instructions) and `.brainclaw/coordination/` (plans, claims, handoffs). They are versioned in `.brainclaw/.git` and shared via Git.
36
+
37
+ ### Runtime memory
38
+ Operational observations that may be short-lived, host-specific, or private.
39
+
40
+ Examples: "this API key only works in staging", "the test server is slow today", temporary notes during a session.
41
+
42
+ Runtime notes are stored separately and can be given a TTL so they expire automatically.
43
+
44
+ Not everything seen during execution should become canonical memory immediately.
45
+
46
+ ## Why explicit memory matters
47
+
48
+ Without explicit memory, project context tends to scatter across:
49
+
50
+ - chat history
51
+ - agent prompts
52
+ - personal notes
53
+ - unstated assumptions
54
+ - hidden tool memory
55
+
56
+ brainclaw makes this context visible and versionable.
57
+
58
+ ## Readable vs canonical
59
+
60
+ brainclaw keeps:
61
+
62
+ - canonical structured JSON as the source of truth (individual files under `.brainclaw/memory/` and `.brainclaw/coordination/`)
63
+ - a legacy derived readable view (`.brainclaw/project.md`) regenerated best-effort from canonical state
64
+ - root `PROJECT.md` as the stable project vision when present
65
+ - native agent instruction files (`CLAUDE.md`, `.cursor/rules/brainclaw.md`, etc.) generated via `brainclaw export`
66
+
67
+ This balances machine reliability with human readability.
68
+
69
+ The generated files are **local-only** and should not be committed to Git — each developer regenerates them from their own `.brainclaw/` store. Add them to `.gitignore` (brainclaw does this automatically during `init`).
70
+
71
+ ## Accessing memory
72
+
73
+ ```bash
74
+ brainclaw context # full context as text
75
+ brainclaw context --json # full context as JSON (for agents)
76
+ brainclaw agent-board # live plan + claim board
77
+ brainclaw claim list # active claims
78
+ brainclaw plan list # all plans
79
+ brainclaw audit # audit log
80
+ ```
81
+
82
+ MCP tools expose the same data to agents that support the Model Context Protocol.
83
+
84
+ ## Related pages
85
+
86
+ - [coordination.md](coordination.md)
87
+ - [runtime-notes.md](runtime-notes.md)
88
+ - [workspace-bootstrapping.md](workspace-bootstrapping.md)
89
+ - [plans-and-claims.md](plans-and-claims.md)
@@ -1,167 +1,167 @@
1
- # Multi-Agent Workflows
2
-
3
- brainclaw is built around a small set of memory primitives — **plans**, **claims**, **handoffs**, **decisions**, **traps**, and **runtime notes** — that work the same way whether you're orchestrating multiple agents in parallel right now or letting the next agent (or the next you) pick up the work next week.
4
-
5
- This doc walks through four concrete scenarios. Pick the one that matches what you're doing.
6
-
7
- ---
8
-
9
- ## 1. Active orchestration — parallel work across agent instances
10
-
11
- **Scenario** — you have a sequence of independent lanes and want several agents (same agent, different instances, or several different agents) to work on them in parallel.
12
-
13
- **Walkthrough**:
14
-
15
- 1. Capture the work as plans, then group them into a sequence with explicit lane labels and dependencies:
16
-
17
- ```text
18
- bclaw_create(entity="plan", data={ text: "Refactor auth module", … })
19
- bclaw_create(entity="plan", data={ text: "Add e2e tests", … })
20
-
21
- # Then, via CLI or a follow-up call:
22
- brainclaw sequence create "auth-refactor-cycle" --items '[
23
- {"planId":"pln_aaa","rank":1,"lane":"refactor"},
24
- {"planId":"pln_bbb","rank":2,"lane":"tests","hard_after":["pln_aaa"]}
25
- ]' --status active
26
- ```
27
-
28
- 2. Dispatch the sequence — the dispatcher picks up the ready lanes (no `hard_after` blocking), creates one claim + worktree per lane, and routes inbox messages by `claim_id`:
29
-
30
- ```text
31
- bclaw_dispatch(intent="execute", agents=[<your agents>])
32
- ```
33
-
34
- 3. Each spawned worker runs in its own worktree (so concurrent edits don't collide), reads its inbox, and progresses the plan. Coordinator polls `bclaw_context(kind="board")` to follow progress.
35
-
36
- 4. As each lane lands a commit, merge it into master and release the claim. Lanes with `hard_after` unblock automatically once their predecessors are `done`.
37
-
38
- **What the primitives do here**: claims isolate scope per lane, the sequence's `hard_after` graph orders the work, and worktrees give Git-level isolation so parallel commits don't conflict.
39
-
40
- ---
41
-
42
- ## 2. Agent switching — when an agent runs out of credits mid-task
43
-
44
- **Scenario** — your active agent hits a credit/quota limit while a task is half-done. You want the next agent (a different model, a fresh instance, anything you have available) to resume cleanly without re-explaining the whole project.
45
-
46
- **Walkthrough**:
47
-
48
- 1. Before the active agent shuts down, close out properly:
49
-
50
- ```text
51
- bclaw_session_end(narrative="Implemented X. Need to finish Y. Tests for Z still pending.")
52
- ```
53
-
54
- This snapshots the session, releases the active claims, and writes a handoff with the narrative + commit list.
55
-
56
- 2. Bring up the next agent (any compatible one). Its first call is `bclaw_work(intent="resume")`:
57
-
58
- ```text
59
- bclaw_work(intent="resume")
60
- ```
61
-
62
- This returns the session context: open plans, recent decisions, active constraints, known traps, the latest handoff narrative, and any unfinished claims it can adopt.
63
-
64
- 3. The new agent reads the handoff, picks up the right plan, and either creates a fresh claim on the same scope or adopts the existing one:
65
-
66
- ```text
67
- bclaw_work(intent="execute", planId="pln_…", scope="src/...")
68
- ```
69
-
70
- 4. From here on it's a normal session — the new agent has all the context the previous one had.
71
-
72
- **What the primitives do here**: the handoff carries the narrative and the file delta, the session record carries the runtime context, and shared memory (decisions, constraints, traps) means the new agent doesn't relearn what the previous one already knows.
73
-
74
- ---
75
-
76
- ## 3. Project recovery — returning to a project after weeks
77
-
78
- **Scenario** — you (or an agent on your behalf) come back to a project after a couple of weeks. You don't remember exactly where things stood. You want to ramp back up in a few minutes, not an afternoon.
79
-
80
- **Walkthrough**:
81
-
82
- 1. From the project root, ask any compatible agent to load context with the canonical facade:
83
-
84
- ```text
85
- bclaw_work(intent="resume")
86
- ```
87
-
88
- You get back: in-progress plans, blocked plans, decisions taken since you left, active constraints, known traps, recent handoffs, and a session continuity hint (where the last session left off).
89
-
90
- 2. If you want a narrower view focused on one area:
91
-
92
- ```text
93
- bclaw_context(kind="memory", path="src/auth", profile="briefing")
94
- ```
95
-
96
- 3. Capture the things you remember in the moment — even rough — as runtime notes. They live in memory and can be promoted later to durable decisions or traps:
97
-
98
- ```text
99
- bclaw_create(entity="runtime_note", data={ text: "Token rotation logic was the next thing to ship" })
100
- ```
101
-
102
- 4. Pick the next plan, claim its scope, and start working. The agent has everything it needs.
103
-
104
- **What the primitives do here**: durable memory means decisions and constraints survive long absences, the session continuity record bridges the gap between runs, and runtime notes give a low-friction way to capture half-formed ideas as they come back to you.
105
-
106
- ---
107
-
108
- ## 4. Team async — multiple humans and agents on the same project
109
-
110
- **Scenario** — two or more people work on the same project, possibly with their own agents. Everyone needs to see the same plans, the same constraints, the same decisions, without constant Slack pings.
111
-
112
- **Walkthrough**:
113
-
114
- 1. Whenever someone takes a non-trivial decision (architecture, library choice, naming convention), capture it once:
115
-
116
- ```text
117
- bclaw_create(entity="decision", data={ text: "Use OAuth 2.0 with PKCE", outcome: "approved" })
118
- bclaw_create(entity="constraint", data={ text: "All auth endpoints must rate-limit", category: "security" })
119
- bclaw_create(entity="trap", data={ text: "Don't import from src/legacy/", severity: "high" })
120
- ```
121
-
122
- These become visible to every agent (and every teammate's agent) on the next `bclaw_context` call.
123
-
124
- 2. When someone starts a non-trivial chunk of work, claim its scope so others can see it:
125
-
126
- ```text
127
- bclaw_work(intent="execute", scope="src/auth", task="Token rotation rework")
128
- ```
129
-
130
- The agent board (`bclaw_context(kind="board")` or `brainclaw agent-board`) now shows that scope as taken — anyone considering the same area sees the claim and either coordinates or picks something else.
131
-
132
- 3. When work is ready for review, hand it off explicitly. The handoff includes the file delta, the narrative, and any open questions:
133
-
134
- ```text
135
- bclaw_coordinate(intent="review", task="Auth refactor ready for review", scope="src/auth")
136
- ```
137
-
138
- 4. Reviewers pick up the handoff via inbox (`bclaw_read_inbox`) and respond either by accepting + closing it, or by sending back fixes through the same coordination loop.
139
-
140
- **What the primitives do here**: shared memory means every teammate's agent operates with the same constraints and traps, claims prevent double-work even without coordination meetings, and handoffs replace ad-hoc "hey, can you look at this?" pings with auditable artifacts.
141
-
142
- ---
143
-
144
- ## How the four scenarios share the same model
145
-
146
- Notice that the four walkthroughs above use the **same primitives**, just composed differently:
147
-
148
- | Primitive | Active orchestration | Agent switching | Project recovery | Team async |
149
- |---|---|---|---|---|
150
- | **plan** | unit of work in a lane | what the next agent picks up | what you ramp back into | what teammates see in the board |
151
- | **claim** | scope lock per lane | snapshotted on session_end, adoptable later | shows what was in flight | prevents teammates from double-editing |
152
- | **handoff** | between sequential lanes | carries the narrative + delta | bridges across the gap | replaces "ping me when ready" |
153
- | **decision / constraint / trap** | guides every spawned worker | survives the credit-limit cutover | reminds you of past choices | propagates team knowledge |
154
- | **runtime_note** | per-lane observations | quick captures before shutdown | half-formed thoughts on return | informal observations to share |
155
-
156
- You don't pick a "mode" up front. You compose the primitives in whatever way fits the moment, and brainclaw keeps them durable across all of it.
157
-
158
- ---
159
-
160
- ## Next reads
161
-
162
- - [memory.md](memory.md) — what counts as memory and how it's organized
163
- - [plans-and-claims.md](plans-and-claims.md) — coordination layer in depth
164
- - [loop-engine.md](loop-engine.md) — structured multi-turn protocols (review loops, ideation, etc.)
165
- - [dispatch-lifecycle.md](dispatch-lifecycle.md) — what actually happens when a dispatch goes wrong: 6-entity dance, brief-ack sentinel, stdout/stderr logs, observability decision tree
166
- - [memory-staleness.md](memory-staleness.md) — how brainclaw signals when stored items may be outdated
167
- - [../integrations/overview.md](../integrations/overview.md) — connecting your specific agent
1
+ # Multi-Agent Workflows
2
+
3
+ brainclaw is built around a small set of memory primitives — **plans**, **claims**, **handoffs**, **decisions**, **traps**, and **runtime notes** — that work the same way whether you're orchestrating multiple agents in parallel right now or letting the next agent (or the next you) pick up the work next week.
4
+
5
+ This doc walks through four concrete scenarios. Pick the one that matches what you're doing.
6
+
7
+ ---
8
+
9
+ ## 1. Active orchestration — parallel work across agent instances
10
+
11
+ **Scenario** — you have a sequence of independent lanes and want several agents (same agent, different instances, or several different agents) to work on them in parallel.
12
+
13
+ **Walkthrough**:
14
+
15
+ 1. Capture the work as plans, then group them into a sequence with explicit lane labels and dependencies:
16
+
17
+ ```text
18
+ bclaw_create(entity="plan", data={ text: "Refactor auth module", … })
19
+ bclaw_create(entity="plan", data={ text: "Add e2e tests", … })
20
+
21
+ # Then, via CLI or a follow-up call:
22
+ brainclaw sequence create "auth-refactor-cycle" --items '[
23
+ {"planId":"pln_aaa","rank":1,"lane":"refactor"},
24
+ {"planId":"pln_bbb","rank":2,"lane":"tests","hard_after":["pln_aaa"]}
25
+ ]' --status active
26
+ ```
27
+
28
+ 2. Dispatch the sequence — the dispatcher picks up the ready lanes (no `hard_after` blocking), creates one claim + worktree per lane, and routes inbox messages by `claim_id`:
29
+
30
+ ```text
31
+ bclaw_dispatch(intent="execute", agents=[<your agents>])
32
+ ```
33
+
34
+ 3. Each spawned worker runs in its own worktree (so concurrent edits don't collide), reads its inbox, and progresses the plan. Coordinator polls `bclaw_context(kind="board")` to follow progress.
35
+
36
+ 4. As each lane lands a commit, merge it into master and release the claim. Lanes with `hard_after` unblock automatically once their predecessors are `done`.
37
+
38
+ **What the primitives do here**: claims isolate scope per lane, the sequence's `hard_after` graph orders the work, and worktrees give Git-level isolation so parallel commits don't conflict.
39
+
40
+ ---
41
+
42
+ ## 2. Agent switching — when an agent runs out of credits mid-task
43
+
44
+ **Scenario** — your active agent hits a credit/quota limit while a task is half-done. You want the next agent (a different model, a fresh instance, anything you have available) to resume cleanly without re-explaining the whole project.
45
+
46
+ **Walkthrough**:
47
+
48
+ 1. Before the active agent shuts down, close out properly:
49
+
50
+ ```text
51
+ bclaw_session_end(narrative="Implemented X. Need to finish Y. Tests for Z still pending.")
52
+ ```
53
+
54
+ This snapshots the session, releases the active claims, and writes a handoff with the narrative + commit list.
55
+
56
+ 2. Bring up the next agent (any compatible one). Its first call is `bclaw_work(intent="resume")`:
57
+
58
+ ```text
59
+ bclaw_work(intent="resume")
60
+ ```
61
+
62
+ This returns the session context: open plans, recent decisions, active constraints, known traps, the latest handoff narrative, and any unfinished claims it can adopt.
63
+
64
+ 3. The new agent reads the handoff, picks up the right plan, and either creates a fresh claim on the same scope or adopts the existing one:
65
+
66
+ ```text
67
+ bclaw_work(intent="execute", planId="pln_…", scope="src/...")
68
+ ```
69
+
70
+ 4. From here on it's a normal session — the new agent has all the context the previous one had.
71
+
72
+ **What the primitives do here**: the handoff carries the narrative and the file delta, the session record carries the runtime context, and shared memory (decisions, constraints, traps) means the new agent doesn't relearn what the previous one already knows.
73
+
74
+ ---
75
+
76
+ ## 3. Project recovery — returning to a project after weeks
77
+
78
+ **Scenario** — you (or an agent on your behalf) come back to a project after a couple of weeks. You don't remember exactly where things stood. You want to ramp back up in a few minutes, not an afternoon.
79
+
80
+ **Walkthrough**:
81
+
82
+ 1. From the project root, ask any compatible agent to load context with the canonical facade:
83
+
84
+ ```text
85
+ bclaw_work(intent="resume")
86
+ ```
87
+
88
+ You get back: in-progress plans, blocked plans, decisions taken since you left, active constraints, known traps, recent handoffs, and a session continuity hint (where the last session left off).
89
+
90
+ 2. If you want a narrower view focused on one area:
91
+
92
+ ```text
93
+ bclaw_context(kind="memory", path="src/auth", profile="briefing")
94
+ ```
95
+
96
+ 3. Capture the things you remember in the moment — even rough — as runtime notes. They live in memory and can be promoted later to durable decisions or traps:
97
+
98
+ ```text
99
+ bclaw_create(entity="runtime_note", data={ text: "Token rotation logic was the next thing to ship" })
100
+ ```
101
+
102
+ 4. Pick the next plan, claim its scope, and start working. The agent has everything it needs.
103
+
104
+ **What the primitives do here**: durable memory means decisions and constraints survive long absences, the session continuity record bridges the gap between runs, and runtime notes give a low-friction way to capture half-formed ideas as they come back to you.
105
+
106
+ ---
107
+
108
+ ## 4. Team async — multiple humans and agents on the same project
109
+
110
+ **Scenario** — two or more people work on the same project, possibly with their own agents. Everyone needs to see the same plans, the same constraints, the same decisions, without constant Slack pings.
111
+
112
+ **Walkthrough**:
113
+
114
+ 1. Whenever someone takes a non-trivial decision (architecture, library choice, naming convention), capture it once:
115
+
116
+ ```text
117
+ bclaw_create(entity="decision", data={ text: "Use OAuth 2.0 with PKCE", outcome: "approved" })
118
+ bclaw_create(entity="constraint", data={ text: "All auth endpoints must rate-limit", category: "security" })
119
+ bclaw_create(entity="trap", data={ text: "Don't import from src/legacy/", severity: "high" })
120
+ ```
121
+
122
+ These become visible to every agent (and every teammate's agent) on the next `bclaw_context` call.
123
+
124
+ 2. When someone starts a non-trivial chunk of work, claim its scope so others can see it:
125
+
126
+ ```text
127
+ bclaw_work(intent="execute", scope="src/auth", task="Token rotation rework")
128
+ ```
129
+
130
+ The agent board (`bclaw_context(kind="board")` or `brainclaw agent-board`) now shows that scope as taken — anyone considering the same area sees the claim and either coordinates or picks something else.
131
+
132
+ 3. When work is ready for review, hand it off explicitly. The handoff includes the file delta, the narrative, and any open questions:
133
+
134
+ ```text
135
+ bclaw_coordinate(intent="review", task="Auth refactor ready for review", scope="src/auth")
136
+ ```
137
+
138
+ 4. Reviewers pick up the handoff via inbox (`bclaw_read_inbox`) and respond either by accepting + closing it, or by sending back fixes through the same coordination loop.
139
+
140
+ **What the primitives do here**: shared memory means every teammate's agent operates with the same constraints and traps, claims prevent double-work even without coordination meetings, and handoffs replace ad-hoc "hey, can you look at this?" pings with auditable artifacts.
141
+
142
+ ---
143
+
144
+ ## How the four scenarios share the same model
145
+
146
+ Notice that the four walkthroughs above use the **same primitives**, just composed differently:
147
+
148
+ | Primitive | Active orchestration | Agent switching | Project recovery | Team async |
149
+ |---|---|---|---|---|
150
+ | **plan** | unit of work in a lane | what the next agent picks up | what you ramp back into | what teammates see in the board |
151
+ | **claim** | scope lock per lane | snapshotted on session_end, adoptable later | shows what was in flight | prevents teammates from double-editing |
152
+ | **handoff** | between sequential lanes | carries the narrative + delta | bridges across the gap | replaces "ping me when ready" |
153
+ | **decision / constraint / trap** | guides every spawned worker | survives the credit-limit cutover | reminds you of past choices | propagates team knowledge |
154
+ | **runtime_note** | per-lane observations | quick captures before shutdown | half-formed thoughts on return | informal observations to share |
155
+
156
+ You don't pick a "mode" up front. You compose the primitives in whatever way fits the moment, and brainclaw keeps them durable across all of it.
157
+
158
+ ---
159
+
160
+ ## Next reads
161
+
162
+ - [memory.md](memory.md) — what counts as memory and how it's organized
163
+ - [plans-and-claims.md](plans-and-claims.md) — coordination layer in depth
164
+ - [loop-engine.md](loop-engine.md) — structured multi-turn protocols (review loops, ideation, etc.)
165
+ - [dispatch-lifecycle.md](dispatch-lifecycle.md) — what actually happens when a dispatch goes wrong: 6-entity dance, brief-ack sentinel, stdout/stderr logs, observability decision tree
166
+ - [memory-staleness.md](memory-staleness.md) — how brainclaw signals when stored items may be outdated
167
+ - [../integrations/overview.md](../integrations/overview.md) — connecting your specific agent