brainclaw 1.9.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 (91) hide show
  1. package/README.md +585 -499
  2. package/dist/brainclaw-vscode.vsix +0 -0
  3. package/dist/commands/harvest.js +1 -1
  4. package/dist/commands/hooks.js +73 -73
  5. package/dist/commands/init.js +1 -1
  6. package/dist/commands/install-hooks.js +78 -78
  7. package/dist/commands/mcp-read-handlers.js +57 -14
  8. package/dist/commands/mcp.js +79 -13
  9. package/dist/commands/switch.js +26 -5
  10. package/dist/commands/version.js +1 -1
  11. package/dist/core/agent-capability.js +19 -4
  12. package/dist/core/agent-files.js +119 -119
  13. package/dist/core/codev-prompts.js +38 -38
  14. package/dist/core/default-profiles/doctor.yaml +11 -11
  15. package/dist/core/default-profiles/janitor.yaml +11 -11
  16. package/dist/core/default-profiles/onboarder.yaml +11 -11
  17. package/dist/core/default-profiles/reviewer.yaml +13 -13
  18. package/dist/core/dispatcher.js +1 -1
  19. package/dist/core/entity-operations.js +29 -3
  20. package/dist/core/execution.js +1 -1
  21. package/dist/core/loops/verbs.js +0 -1
  22. package/dist/core/messaging.js +2 -2
  23. package/dist/core/protocol-skills.js +164 -164
  24. package/dist/core/runtime-signals.js +1 -1
  25. package/dist/core/search.js +19 -2
  26. package/dist/core/security-guard.js +207 -207
  27. package/dist/core/spawn-check.js +16 -2
  28. package/dist/core/staleness.js +1 -1
  29. package/dist/core/store-resolution.js +26 -7
  30. package/dist/core/worktree.js +18 -18
  31. package/dist/facts.js +3 -3
  32. package/dist/facts.json +2 -2
  33. package/docs/PROTOCOL.md +1 -1
  34. package/docs/adapters/openclaw.md +43 -43
  35. package/docs/architecture/project-refs.md +328 -328
  36. package/docs/cli.md +2093 -2093
  37. package/docs/concepts/coordination.md +52 -52
  38. package/docs/concepts/coordinator-runbook.md +129 -129
  39. package/docs/concepts/dispatch-lifecycle.md +245 -245
  40. package/docs/concepts/event-log-store.md +928 -928
  41. package/docs/concepts/ideation-loop.md +317 -317
  42. package/docs/concepts/loop-engine.md +520 -511
  43. package/docs/concepts/mcp-governance.md +268 -268
  44. package/docs/concepts/memory.md +84 -84
  45. package/docs/concepts/multi-agent-workflows.md +167 -167
  46. package/docs/concepts/observer-protocol.md +361 -361
  47. package/docs/concepts/plans-and-claims.md +217 -217
  48. package/docs/concepts/project-md-convention.md +35 -35
  49. package/docs/concepts/runtime-notes.md +38 -38
  50. package/docs/concepts/troubleshooting.md +254 -254
  51. package/docs/concepts/workspace-bootstrapping.md +142 -142
  52. package/docs/context-format-changelog.md +35 -35
  53. package/docs/context-format.md +48 -48
  54. package/docs/index.md +65 -65
  55. package/docs/integrations/agents.md +158 -158
  56. package/docs/integrations/claude-code.md +23 -23
  57. package/docs/integrations/cline.md +77 -77
  58. package/docs/integrations/continue.md +55 -55
  59. package/docs/integrations/copilot.md +68 -68
  60. package/docs/integrations/cursor.md +23 -23
  61. package/docs/integrations/kilocode.md +72 -72
  62. package/docs/integrations/mcp.md +377 -377
  63. package/docs/integrations/mistral-vibe.md +122 -122
  64. package/docs/integrations/openclaw.md +92 -92
  65. package/docs/integrations/opencode.md +84 -84
  66. package/docs/integrations/overview.md +115 -115
  67. package/docs/integrations/roo.md +71 -71
  68. package/docs/integrations/windsurf.md +77 -77
  69. package/docs/mcp-schema-changelog.md +360 -356
  70. package/docs/playbooks/integration/index.md +121 -121
  71. package/docs/playbooks/orchestration.md +37 -0
  72. package/docs/playbooks/productivity/index.md +99 -99
  73. package/docs/playbooks/team/index.md +117 -117
  74. package/docs/product/agent-first-model.md +184 -184
  75. package/docs/product/entity-model-audit.md +462 -462
  76. package/docs/product/positioning.md +86 -86
  77. package/docs/quickstart-existing-project.md +107 -107
  78. package/docs/quickstart.md +183 -183
  79. package/docs/release-maintenance.md +79 -79
  80. package/docs/reputation.md +52 -52
  81. package/docs/review.md +45 -45
  82. package/docs/security.md +212 -212
  83. package/docs/server-operations.md +118 -118
  84. package/docs/storage.md +106 -106
  85. package/package.json +80 -65
  86. package/docs/concepts/event-log-store-critique-A.md +0 -333
  87. package/docs/concepts/event-log-store-critique-B.md +0 -353
  88. package/docs/concepts/event-log-store-phase0-measurements.md +0 -58
  89. package/docs/concepts/event-log-store-proposal-A.md +0 -365
  90. package/docs/concepts/event-log-store-proposal-B.md +0 -404
  91. package/docs/concepts/identity-model-proposal.md +0 -371
@@ -18,164 +18,164 @@
18
18
  * fallback (cold-start / worktree-without-.brainclaw cases), and stay capped at
19
19
  * 3 for this version.
20
20
  */
21
- const SESSION_BODY = `# brainclaw-session
22
-
23
- Open / resume / close a working session on a brainclaw project. Prefer the MCP
24
- facade; the \`brainclaw …\` CLI is the fallback when the MCP server is not
25
- reachable (cold start, or a worktree without \`.brainclaw/\`).
26
-
27
- ## When to use
28
-
29
- - Starting a NEW session on a brainclaw project — any first call in the session, or after a context compaction.
30
- - RESUMING outstanding work — \`BRAINCLAW_CLAIM_ID\` is set, or the operator says "continue X".
31
- - About to EDIT a specific scope (file / dir / feature) that should be reserved against other agents.
32
-
33
- ## Workflow
34
-
35
- 1. \`bclaw_work(intent='consult')\` — loads project memory and reports active claims. Read \`bootstrap_recommended\`: if true the project has no usable PROJECT.md (see \`brainclaw-multi-agent\` → bootstrap loop).
36
- 2. If you will edit a scope, claim it: \`bclaw_work(intent='execute', scope='<path-or-feature>')\`. The response's \`claim_id\` is yours; \`claim_status='created'\` = new, \`'existing'\` = resumed.
37
- 3. Do the work. Honor the \`warnings\` array (claim conflicts, sensitive paths, high-severity traps on your scope).
38
- 4. When done (committed, tested), \`bclaw_session_end(autoRelease: true)\` — closes the session record and releases your remaining claims. \`autoRelease\` defaults to false; pass it explicitly or claims survive the session.
39
-
40
- CLI fallback: \`brainclaw context --json\` · \`brainclaw claim create "<desc>" --scope <path>\` · \`brainclaw session-end --auto-release\`.
41
-
42
- ## Anti-rationalizations
43
-
44
- - **"I'm just exploring, I'll skip session-end."** → A live claim outlives a crash. The next agent sees your stale claim and is blocked. Calling \`bclaw_session_end(autoRelease: true)\` is the zero-cost guarantee — without the flag the claim survives.
45
- - **"I know the project, I don't need to consult."** → State changes between sessions (commits, new traps, new constraints). Consult is cheap and surfaces what you'd miss.
46
- - **"I'll claim later once I know the exact scope."** → Claim-before-edit IS the contract; it is exactly what prevents races with parallel agents.
47
-
48
- ## Red flags
49
-
50
- - \`claim_conflicts\` reports another agent's claim on your target scope → STOP. Route through coordination (\`bclaw_coordinate intent='reroute'\` or ask the operator); never override silently.
51
- - High-severity \`[trap]\`/\`[constraint]\` warning on your scope → read it before editing.
52
- - \`bootstrap_recommended=true\` while you're about to make architectural calls → the project has no PROJECT.md; consider a bootstrap loop first.
53
-
54
- ## Verification
55
-
56
- - The \`claim_id\` returned stays stable across subsequent calls (session continuity).
57
- - After session-end, \`bclaw_find(entity='claim', filter={status:'active'})\` shows no active claim of yours on the scope.
58
-
59
- ## See also
60
-
61
- - \`brainclaw-memory-capture\` — for decisions/traps captured DURING the session.
62
- - \`brainclaw-multi-agent\` — for delegating part of the work.
21
+ const SESSION_BODY = `# brainclaw-session
22
+
23
+ Open / resume / close a working session on a brainclaw project. Prefer the MCP
24
+ facade; the \`brainclaw …\` CLI is the fallback when the MCP server is not
25
+ reachable (cold start, or a worktree without \`.brainclaw/\`).
26
+
27
+ ## When to use
28
+
29
+ - Starting a NEW session on a brainclaw project — any first call in the session, or after a context compaction.
30
+ - RESUMING outstanding work — \`BRAINCLAW_CLAIM_ID\` is set, or the operator says "continue X".
31
+ - About to EDIT a specific scope (file / dir / feature) that should be reserved against other agents.
32
+
33
+ ## Workflow
34
+
35
+ 1. \`bclaw_work(intent='consult')\` — loads project memory and reports active claims. Read \`bootstrap_recommended\`: if true the project has no usable PROJECT.md (see \`brainclaw-multi-agent\` → bootstrap loop).
36
+ 2. If you will edit a scope, claim it: \`bclaw_work(intent='execute', scope='<path-or-feature>')\`. The response's \`claim_id\` is yours; \`claim_status='created'\` = new, \`'existing'\` = resumed.
37
+ 3. Do the work. Honor the \`warnings\` array (claim conflicts, sensitive paths, high-severity traps on your scope).
38
+ 4. When done (committed, tested), \`bclaw_session_end(autoRelease: true)\` — closes the session record and releases your remaining claims. \`autoRelease\` defaults to false; pass it explicitly or claims survive the session.
39
+
40
+ CLI fallback: \`brainclaw context --json\` · \`brainclaw claim create "<desc>" --scope <path>\` · \`brainclaw session-end --auto-release\`.
41
+
42
+ ## Anti-rationalizations
43
+
44
+ - **"I'm just exploring, I'll skip session-end."** → A live claim outlives a crash. The next agent sees your stale claim and is blocked. Calling \`bclaw_session_end(autoRelease: true)\` is the zero-cost guarantee — without the flag the claim survives.
45
+ - **"I know the project, I don't need to consult."** → State changes between sessions (commits, new traps, new constraints). Consult is cheap and surfaces what you'd miss.
46
+ - **"I'll claim later once I know the exact scope."** → Claim-before-edit IS the contract; it is exactly what prevents races with parallel agents.
47
+
48
+ ## Red flags
49
+
50
+ - \`claim_conflicts\` reports another agent's claim on your target scope → STOP. Route through coordination (\`bclaw_coordinate intent='reroute'\` or ask the operator); never override silently.
51
+ - High-severity \`[trap]\`/\`[constraint]\` warning on your scope → read it before editing.
52
+ - \`bootstrap_recommended=true\` while you're about to make architectural calls → the project has no PROJECT.md; consider a bootstrap loop first.
53
+
54
+ ## Verification
55
+
56
+ - The \`claim_id\` returned stays stable across subsequent calls (session continuity).
57
+ - After session-end, \`bclaw_find(entity='claim', filter={status:'active'})\` shows no active claim of yours on the scope.
58
+
59
+ ## See also
60
+
61
+ - \`brainclaw-memory-capture\` — for decisions/traps captured DURING the session.
62
+ - \`brainclaw-multi-agent\` — for delegating part of the work.
63
63
  `;
64
- const MEMORY_CAPTURE_BODY = `# brainclaw-memory-capture
65
-
66
- Capture project memory at the RIGHT granularity and type, so it is retrievable
67
- later. The entity type is not cosmetic — it drives retrieval and surfacing.
68
-
69
- ## When to use
70
-
71
- - You made a **design call** future agents must respect → **decision**.
72
- - You hit an **externally-imposed rule** you cannot relax alone → **constraint**.
73
- - You found an **environment / process pitfall** another agent would also hit → **trap**.
74
- - You finished a chunk of work to be consumed by another agent → **handoff**.
75
- - A keep-worthy observation that is not a hard decision/constraint/trap → **runtime_note** (lowest signal).
76
- - You are genuinely unsure of the type → **candidate** (carries a proposed \`type\`; a reviewer reclassifies).
77
-
78
- ## Workflow
79
-
80
- 1. Pick the type:
81
-
82
- \`\`\`
83
- Negotiated + recorded as the way forward? → decision
84
- Imposed externally, cannot be relaxed by you? → constraint
85
- About HOW the system/env/tools behave (not WHAT)? → trap
86
- A "danger ahead" pointer for a future agent? → trap
87
- Output of work to be consumed by another agent? → handoff
88
- Unsure between decision/constraint/trap? → candidate (with type)
89
- Else → runtime_note
90
- \`\`\`
91
-
92
- 2. Write via the canonical grammar: \`bclaw_create(entity='<type>', data={ text, author, ...optional })\`. Declare the classifying field yourself (caller assertion wins over keyword heuristics): for a \`decision\` set \`outcome\` (one of \`approved | rejected | deferred | pending\` — \`pending\` until ratified); for a \`trap\` set \`severity\` (\`low | medium | high\`, defaults to medium); for a \`constraint\` set \`category\`; for a \`candidate\` its proposed \`type\` (\`constraint | decision | trap | handoff\` — required). \`handoff\` is NOT created via bclaw_create — use \`brainclaw handoff "<text>"\` (CLI) or let \`bclaw_session_end(reflectHandoff: true)\` materialize one from commits. For free-form capture restricted to \`decision | trap | constraint | note\`, \`bclaw_quick_capture(text, type)\` is the shortcut.
93
- 3. Verify it is re-readable: \`bclaw_get(entity='<type>', id='<id>')\` returns your content. If \`bclaw_create\` returned \`validation_error\` (e.g. \`outcome\` not in enum), fix the field and retry — the error message lists the accepted values.
94
-
95
- CLI fallback: \`brainclaw memory create <type> "<text>"\` (decision | constraint | trap | handoff via top-level \`brainclaw handoff "<text>"\`).
96
-
97
- ## Anti-rationalizations
98
-
99
- - **"I'll write a runtime_note, I'm unsure of the type."** → Notes are the lowest-signal type (aggregated, not surfaced). If it's actionable, pick decision/constraint/trap — being wrong is fine, that's what candidates are for.
100
- - **"I'll add it as a decision AND a runtime_note to be safe."** → Duplicates pollute search and retrieval. Pick ONE.
101
- - **"I'll write the decision without an outcome."** → \`outcome\` is optional but enum-validated when set; an invalid value (e.g. \`proposed\`, \`accepted\`) is rejected with the accepted list (\`approved | rejected | deferred | pending\`). Set \`pending\` early if not yet ratified — it makes the lifecycle explicit and lets reviewers transition it cleanly.
102
- - **"A 5-line trap for a 1-line problem."** → Traps are read under pressure. Severity + symptom + mitigation, scannable.
103
-
104
- ## Red flags
105
-
106
- - The content already exists under a different id → \`bclaw_find\` first; \`bclaw_update\` the existing one instead of duplicating.
107
- - You're about to write 10+ items at once → pause; you're dumping context, not capturing signal. Consolidate.
108
- - The "decision" was proposed by someone else and not yet accepted → it's a \`candidate\`, not a \`decision\`.
109
-
110
- ## Verification
111
-
112
- - \`bclaw_create\` returns an id (e.g. \`dec_…\`).
113
- - \`bclaw_get(entity='<type>', id)\` returns identical content; \`bclaw_search\`/\`bclaw_find\` index it.
114
- - Traps surface in \`bclaw_work\` warnings on the relevant scope.
115
-
116
- ## See also
117
-
118
- - \`brainclaw-session\` — capture happens DURING a session.
119
- - \`brainclaw-multi-agent\` — capture review findings as decisions/traps.
64
+ const MEMORY_CAPTURE_BODY = `# brainclaw-memory-capture
65
+
66
+ Capture project memory at the RIGHT granularity and type, so it is retrievable
67
+ later. The entity type is not cosmetic — it drives retrieval and surfacing.
68
+
69
+ ## When to use
70
+
71
+ - You made a **design call** future agents must respect → **decision**.
72
+ - You hit an **externally-imposed rule** you cannot relax alone → **constraint**.
73
+ - You found an **environment / process pitfall** another agent would also hit → **trap**.
74
+ - You finished a chunk of work to be consumed by another agent → **handoff**.
75
+ - A keep-worthy observation that is not a hard decision/constraint/trap → **runtime_note** (lowest signal).
76
+ - You are genuinely unsure of the type → **candidate** (carries a proposed \`type\`; a reviewer reclassifies).
77
+
78
+ ## Workflow
79
+
80
+ 1. Pick the type:
81
+
82
+ \`\`\`
83
+ Negotiated + recorded as the way forward? → decision
84
+ Imposed externally, cannot be relaxed by you? → constraint
85
+ About HOW the system/env/tools behave (not WHAT)? → trap
86
+ A "danger ahead" pointer for a future agent? → trap
87
+ Output of work to be consumed by another agent? → handoff
88
+ Unsure between decision/constraint/trap? → candidate (with type)
89
+ Else → runtime_note
90
+ \`\`\`
91
+
92
+ 2. Write via the canonical grammar: \`bclaw_create(entity='<type>', data={ text, author, ...optional })\`. Declare the classifying field yourself (caller assertion wins over keyword heuristics): for a \`decision\` set \`outcome\` (one of \`approved | rejected | deferred | pending\` — \`pending\` until ratified); for a \`trap\` set \`severity\` (\`low | medium | high\`, defaults to medium); for a \`constraint\` set \`category\`; for a \`candidate\` its proposed \`type\` (\`constraint | decision | trap | handoff\` — required). \`handoff\` is NOT created via bclaw_create — use \`brainclaw handoff "<text>"\` (CLI) or let \`bclaw_session_end(reflectHandoff: true)\` materialize one from commits. For free-form capture restricted to \`decision | trap | constraint | note\`, \`bclaw_quick_capture(text, type)\` is the shortcut.
93
+ 3. Verify it is re-readable: \`bclaw_get(entity='<type>', id='<id>')\` returns your content. If \`bclaw_create\` returned \`validation_error\` (e.g. \`outcome\` not in enum), fix the field and retry — the error message lists the accepted values.
94
+
95
+ CLI fallback: \`brainclaw memory create <type> "<text>"\` (decision | constraint | trap | handoff via top-level \`brainclaw handoff "<text>"\`).
96
+
97
+ ## Anti-rationalizations
98
+
99
+ - **"I'll write a runtime_note, I'm unsure of the type."** → Notes are the lowest-signal type (aggregated, not surfaced). If it's actionable, pick decision/constraint/trap — being wrong is fine, that's what candidates are for.
100
+ - **"I'll add it as a decision AND a runtime_note to be safe."** → Duplicates pollute search and retrieval. Pick ONE.
101
+ - **"I'll write the decision without an outcome."** → \`outcome\` is optional but enum-validated when set; an invalid value (e.g. \`proposed\`, \`accepted\`) is rejected with the accepted list (\`approved | rejected | deferred | pending\`). Set \`pending\` early if not yet ratified — it makes the lifecycle explicit and lets reviewers transition it cleanly.
102
+ - **"A 5-line trap for a 1-line problem."** → Traps are read under pressure. Severity + symptom + mitigation, scannable.
103
+
104
+ ## Red flags
105
+
106
+ - The content already exists under a different id → \`bclaw_find\` first; \`bclaw_update\` the existing one instead of duplicating.
107
+ - You're about to write 10+ items at once → pause; you're dumping context, not capturing signal. Consolidate.
108
+ - The "decision" was proposed by someone else and not yet accepted → it's a \`candidate\`, not a \`decision\`.
109
+
110
+ ## Verification
111
+
112
+ - \`bclaw_create\` returns an id (e.g. \`dec_…\`).
113
+ - \`bclaw_get(entity='<type>', id)\` returns identical content; \`bclaw_search\`/\`bclaw_find\` index it.
114
+ - Traps surface in \`bclaw_work\` warnings on the relevant scope.
115
+
116
+ ## See also
117
+
118
+ - \`brainclaw-session\` — capture happens DURING a session.
119
+ - \`brainclaw-multi-agent\` — capture review findings as decisions/traps.
120
120
  `;
121
- const MULTI_AGENT_BODY = `# brainclaw-multi-agent
122
-
123
- Coordinate work across agents — delegate, request review, drive parallel
124
- dispatch, run multi-turn loops. Use when the work exceeds one agent's
125
- competence or when parallelism gains outweigh orchestration cost.
126
-
127
- ## When to use
128
-
129
- - A second pair of eyes before merging → **review loop**.
130
- - An open-ended design needing multiple perspectives → **ideation loop** (or **bootstrap loop** for PROJECT.md genesis).
131
- - N independent sub-tasks runnable in parallel → **dispatch**.
132
- - You're inside a loop someone else opened and must drive your turn → **loop verbs**.
133
-
134
- ## Workflow — pick the verb first
135
-
136
- \`\`\`
137
- Delegate a scope (with a claim)? → bclaw_coordinate(intent='assign')
138
- Ask an agent for input, no claim? → bclaw_coordinate(intent='consult')
139
- Review a commit / branch / candidate? → bclaw_coordinate(intent='review', open_loop=true)
140
- Brainstorm with multiple agents? → bclaw_coordinate(intent='ideate')
141
- Parallelize a sequence's lanes? → bclaw_dispatch(intent='execute')
142
- Drive YOUR turn in an open loop? → bclaw_loop(intent='turn|complete_turn|advance|close')
143
- \`\`\`
144
-
145
- ### Review loop
146
- 1. Commit your changes first (or pass \`allow_dirty=true\` only if the worker doesn't need the dirty files — it spawns from HEAD).
147
- 2. \`bclaw_coordinate(intent='review', open_loop=true, review_mode='symmetric', targetAgents=['<agent>'], scope='<commit/branch/feature>', task='<what to review + acceptance bar>')\`.
148
- 3. Verify the worker is ALIVE — \`bclaw_dispatch_status(target_id='<asgn_…>')\` (health verdict + recommended action), not the bare \`delivered_and_started\` return.
149
- 4. When findings land, apply fixes / push back via another turn.
150
- 5. \`bclaw_loop(intent='close', loop_id='<id>', status='completed', reason='<verdict>')\`; release the worker's claim.
151
-
152
- ### Parallel dispatch
153
- 1. A sequence with lane declarations (or a plan with lanes).
154
- 2. \`bclaw_dispatch(intent='execute')\` fans the items across agents per their lanes. Before merging the lanes back, run \`brainclaw worktree check\` (pre-merge conflict detection).
155
-
156
- ## Anti-rationalizations
157
-
158
- - **"I'll call \`bclaw_loop(intent='open')\` to start the review."** → STOP. \`open\` creates the loop WITHOUT dispatching a turn; the reviewer never gets the work. Use \`bclaw_coordinate(intent='review', open_loop=true)\` — it opens AND dispatches.
159
- - **"It returned \`delivered_and_started\`, so the worker is running."** → That only means the brief-ack sentinel was touched. Verify with \`bclaw_dispatch_status\`; spawns die silently.
160
- - **"I'll dispatch with uncommitted changes, the worker will see them."** → It spawns from HEAD in a worktree; your dirty files are invisible. Commit, or pass \`allow_dirty=true\` consciously.
161
-
162
- ## Red flags
163
-
164
- - \`agent_run.status='running'\` but the worker pid is dead → silent spawn death; check the captured stderr, retry or reassign. (Do NOT trust a stale \`LANE-RESULT.json\` inherited by the worktree — verify its \`assignment_id\` matches.)
165
- - Cross-project dispatch (\`project='<other>'\`) → auto-spawn is disabled by design; the target picks the brief up async via its own \`bclaw_work\`. Don't block waiting.
166
- - A dispatched worker operates in a worktree that has no \`.brainclaw/\` → its MCP/CLI may be limited (trp#336); it falls back to file-based output. Expect a file deliverable, harvest it.
167
-
168
- ## Verification
169
-
170
- - Dispatch: \`bclaw_dispatch_status(target_id)\` returns \`healthy\` (pid alive, recent fs activity), or a terminal verdict with a recommended next action.
171
- - Review loop: \`bclaw_loop(intent='get', loop_id)\` shows the reviewer slot \`done\` and the findings artifact attached.
172
- - Bootstrap/ideate: at converge the loop is \`completed\` (and for bootstrap, PROJECT.md is materialized at the project root).
173
-
174
- ## See also
175
-
176
- - \`brainclaw-session\` — start a session BEFORE dispatching.
177
- - \`brainclaw-memory-capture\` — capture review findings as typed memory.
178
- - Docs: \`docs/concepts/loop-engine.md\`, \`docs/concepts/dispatch-lifecycle.md\`, \`docs/concepts/parallel-merge-protocol.md\`.
121
+ const MULTI_AGENT_BODY = `# brainclaw-multi-agent
122
+
123
+ Coordinate work across agents — delegate, request review, drive parallel
124
+ dispatch, run multi-turn loops. Use when the work exceeds one agent's
125
+ competence or when parallelism gains outweigh orchestration cost.
126
+
127
+ ## When to use
128
+
129
+ - A second pair of eyes before merging → **review loop**.
130
+ - An open-ended design needing multiple perspectives → **ideation loop** (or **bootstrap loop** for PROJECT.md genesis).
131
+ - N independent sub-tasks runnable in parallel → **dispatch**.
132
+ - You're inside a loop someone else opened and must drive your turn → **loop verbs**.
133
+
134
+ ## Workflow — pick the verb first
135
+
136
+ \`\`\`
137
+ Delegate a scope (with a claim)? → bclaw_coordinate(intent='assign')
138
+ Ask an agent for input, no claim? → bclaw_coordinate(intent='consult')
139
+ Review a commit / branch / candidate? → bclaw_coordinate(intent='review', open_loop=true)
140
+ Brainstorm with multiple agents? → bclaw_coordinate(intent='ideate')
141
+ Parallelize a sequence's lanes? → bclaw_dispatch(intent='execute')
142
+ Drive YOUR turn in an open loop? → bclaw_loop(intent='turn|complete_turn|advance|close')
143
+ \`\`\`
144
+
145
+ ### Review loop
146
+ 1. Commit your changes first (or pass \`allow_dirty=true\` only if the worker doesn't need the dirty files — it spawns from HEAD).
147
+ 2. \`bclaw_coordinate(intent='review', open_loop=true, review_mode='symmetric', targetAgents=['<agent>'], scope='<commit/branch/feature>', task='<what to review + acceptance bar>')\`.
148
+ 3. Verify the worker is ALIVE — \`bclaw_dispatch_status(target_id='<asgn_…>')\` (health verdict + recommended action), not the bare \`delivered_and_started\` return.
149
+ 4. When findings land, apply fixes / push back via another turn.
150
+ 5. \`bclaw_loop(intent='close', loop_id='<id>', status='completed', reason='<verdict>')\`; release the worker's claim.
151
+
152
+ ### Parallel dispatch
153
+ 1. A sequence with lane declarations (or a plan with lanes).
154
+ 2. \`bclaw_dispatch(intent='execute')\` fans the items across agents per their lanes. Before merging the lanes back, run \`brainclaw worktree check\` (pre-merge conflict detection).
155
+
156
+ ## Anti-rationalizations
157
+
158
+ - **"I'll call \`bclaw_loop(intent='open')\` to start the review."** → STOP. \`open\` creates the loop WITHOUT dispatching a turn; the reviewer never gets the work. Use \`bclaw_coordinate(intent='review', open_loop=true)\` — it opens AND dispatches.
159
+ - **"It returned \`delivered_and_started\`, so the worker is running."** → That only means the brief-ack sentinel was touched. Verify with \`bclaw_dispatch_status\`; spawns die silently.
160
+ - **"I'll dispatch with uncommitted changes, the worker will see them."** → It spawns from HEAD in a worktree; your dirty files are invisible. Commit, or pass \`allow_dirty=true\` consciously.
161
+
162
+ ## Red flags
163
+
164
+ - \`agent_run.status='running'\` but the worker pid is dead → silent spawn death; check the captured stderr, retry or reassign. (Do NOT trust a stale \`LANE-RESULT.json\` inherited by the worktree — verify its \`assignment_id\` matches.)
165
+ - Cross-project dispatch (\`project='<other>'\`) → auto-spawn is disabled by design; the target picks the brief up async via its own \`bclaw_work\`. Don't block waiting.
166
+ - A dispatched worker operates in a worktree that has no \`.brainclaw/\` → its MCP/CLI may be limited (trp#336); it falls back to file-based output. Expect a file deliverable, harvest it.
167
+
168
+ ## Verification
169
+
170
+ - Dispatch: \`bclaw_dispatch_status(target_id)\` returns \`healthy\` (pid alive, recent fs activity), or a terminal verdict with a recommended next action.
171
+ - Review loop: \`bclaw_loop(intent='get', loop_id)\` shows the reviewer slot \`done\` and the findings artifact attached.
172
+ - Bootstrap/ideate: at converge the loop is \`completed\` (and for bootstrap, PROJECT.md is materialized at the project root).
173
+
174
+ ## See also
175
+
176
+ - \`brainclaw-session\` — start a session BEFORE dispatching.
177
+ - \`brainclaw-memory-capture\` — capture review findings as typed memory.
178
+ - Docs: \`docs/concepts/loop-engine.md\`, \`docs/concepts/dispatch-lifecycle.md\`, \`docs/concepts/parallel-merge-protocol.md\`.
179
179
  `;
180
180
  /** The single source of truth for what ships in the protocol-skills pack. */
181
181
  export const PROTOCOL_SKILLS = [
@@ -197,14 +197,14 @@ export const PROTOCOL_SKILLS = [
197
197
  ];
198
198
  /** Render the full SKILL.md (frontmatter + body) for a protocol skill. */
199
199
  export function renderProtocolSkill(skill, brainclawVersion) {
200
- return `---
201
- name: ${skill.id}
202
- description: '${skill.description.replace(/'/g, "''")}'
203
- metadata:
204
- protocol: true
205
- brainclaw_version: ${brainclawVersion}
206
- ---
207
-
200
+ return `---
201
+ name: ${skill.id}
202
+ description: '${skill.description.replace(/'/g, "''")}'
203
+ metadata:
204
+ protocol: true
205
+ brainclaw_version: ${brainclawVersion}
206
+ ---
207
+
208
208
  ${skill.body}`;
209
209
  }
210
210
  //# sourceMappingURL=protocol-skills.js.map
@@ -214,7 +214,7 @@ export function latestWorktreeFileMtimeMs(worktreePath, maxDepth = 4) {
214
214
  * file in its worktree. Lets the reconciler / dispatch_status distinguish
215
215
  * "no heartbeat BUT fs active" (working — e.g. codex streaming to stderr, or
216
216
  * claude -p editing files) from "no heartbeat AND fs inert" (genuinely stalled),
217
- * fixing the false-`stalled` verdict (debrief LeaseUp P1#1). Returns undefined
217
+ * fixing the false-`stalled` verdict (field debrief P1#1). Returns undefined
218
218
  * when nothing is observable.
219
219
  */
220
220
  export function latestActivityMs(root, assignmentId, worktreePath) {
@@ -10,9 +10,16 @@ function tokenize(text) {
10
10
  .split(/\s+/)
11
11
  .filter(t => t.length > 1);
12
12
  }
13
- function buildCorpus(state, includePending, cwd) {
13
+ function isLegacyDocument(document) {
14
+ return document.provenance !== null
15
+ && typeof document.provenance === 'object'
16
+ && document.provenance.kind === 'legacy';
17
+ }
18
+ function buildCorpus(state, includePending, cwd, includeLegacy = false) {
14
19
  const docs = [];
15
20
  const add = (section, item) => {
21
+ if (!includeLegacy && isLegacyDocument({ ...item, section }))
22
+ return;
16
23
  const textParts = [item.text, item.author ?? '', ...(item.tags ?? []), ...(item.related_paths ?? [])];
17
24
  docs.push({ ...item, section, terms: tokenize(textParts.join(' ')) });
18
25
  };
@@ -128,7 +135,17 @@ export function searchCorpus(documents, options) {
128
135
  }
129
136
  export function search(options) {
130
137
  const state = loadState(options.cwd);
131
- const corpus = buildCorpus(state, options.includePending ?? false, options.cwd);
138
+ const corpus = buildCorpus(state, options.includePending ?? false, options.cwd, options.includeLegacy === true);
132
139
  return searchCorpus(corpus, options);
133
140
  }
141
+ export function countLegacySearchMatches(options) {
142
+ const state = loadState(options.cwd);
143
+ const legacyCorpus = buildCorpus(state, options.includePending ?? false, options.cwd, true)
144
+ .filter(isLegacyDocument);
145
+ return searchCorpus(legacyCorpus, {
146
+ ...options,
147
+ includeLegacy: true,
148
+ maxResults: Number.MAX_SAFE_INTEGER,
149
+ }).length;
150
+ }
134
151
  //# sourceMappingURL=search.js.map