brainclaw 0.28.0 → 1.5.3

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 (198) hide show
  1. package/README.md +193 -170
  2. package/dist/brainclaw-vscode.vsix +0 -0
  3. package/dist/cli.js +683 -23
  4. package/dist/commands/accept.js +3 -0
  5. package/dist/commands/add-step.js +11 -26
  6. package/dist/commands/agent-board.js +70 -3
  7. package/dist/commands/audit.js +19 -0
  8. package/dist/commands/check-policy.js +54 -0
  9. package/dist/commands/check-security-mcp.js +145 -0
  10. package/dist/commands/check-security.js +106 -0
  11. package/dist/commands/claim-resource.js +1 -0
  12. package/dist/commands/codev.js +672 -0
  13. package/dist/commands/compact.js +74 -0
  14. package/dist/commands/complete-step.js +16 -26
  15. package/dist/commands/constraint.js +8 -20
  16. package/dist/commands/decision.js +9 -20
  17. package/dist/commands/delete-plan.js +10 -12
  18. package/dist/commands/delete-step.js +16 -0
  19. package/dist/commands/dispatch.js +163 -0
  20. package/dist/commands/doctor.js +1122 -49
  21. package/dist/commands/enable-agent.js +1 -0
  22. package/dist/commands/export.js +280 -22
  23. package/dist/commands/handoff.js +33 -0
  24. package/dist/commands/harvest.js +189 -0
  25. package/dist/commands/hooks.js +82 -25
  26. package/dist/commands/inbox.js +169 -0
  27. package/dist/commands/init.js +38 -31
  28. package/dist/commands/install-hooks.js +71 -44
  29. package/dist/commands/link.js +89 -0
  30. package/dist/commands/list-claims.js +48 -3
  31. package/dist/commands/list-plans.js +129 -25
  32. package/dist/commands/loops-handlers.js +409 -0
  33. package/dist/commands/mcp-read-handlers.js +1628 -0
  34. package/dist/commands/mcp-schemas.generated.js +74 -0
  35. package/dist/commands/mcp.js +4244 -1475
  36. package/dist/commands/plan-resource.js +64 -0
  37. package/dist/commands/plan.js +12 -26
  38. package/dist/commands/prune.js +37 -2
  39. package/dist/commands/reflect.js +20 -7
  40. package/dist/commands/release-claim.js +11 -6
  41. package/dist/commands/release-notes.js +170 -0
  42. package/dist/commands/repair.js +210 -0
  43. package/dist/commands/run-profile.js +57 -0
  44. package/dist/commands/sequence.js +113 -0
  45. package/dist/commands/session-end.js +423 -14
  46. package/dist/commands/session-start.js +214 -41
  47. package/dist/commands/setup-security.js +103 -0
  48. package/dist/commands/setup.js +42 -4
  49. package/dist/commands/stale.js +109 -0
  50. package/dist/commands/switch.js +131 -10
  51. package/dist/commands/trap.js +14 -31
  52. package/dist/commands/update-handoff.js +63 -4
  53. package/dist/commands/update-plan.js +21 -28
  54. package/dist/commands/update-step.js +37 -0
  55. package/dist/commands/upgrade.js +313 -6
  56. package/dist/commands/usage.js +102 -0
  57. package/dist/commands/version.js +20 -0
  58. package/dist/commands/who.js +124 -0
  59. package/dist/commands/worktree.js +105 -0
  60. package/dist/core/actions.js +315 -0
  61. package/dist/core/agent-capability.js +610 -17
  62. package/dist/core/agent-context.js +7 -1
  63. package/dist/core/agent-files.js +1169 -85
  64. package/dist/core/agent-integrations.js +160 -5
  65. package/dist/core/agent-inventory.js +2 -0
  66. package/dist/core/agent-profiles.js +93 -0
  67. package/dist/core/agent-registry.js +162 -30
  68. package/dist/core/agentrun-reconciler.js +345 -0
  69. package/dist/core/agentruns.js +424 -0
  70. package/dist/core/ai-agent-detection.js +31 -10
  71. package/dist/core/archival.js +77 -0
  72. package/dist/core/assignment-sweeper.js +82 -0
  73. package/dist/core/assignments.js +367 -0
  74. package/dist/core/audit.js +30 -0
  75. package/dist/core/bootstrap.js +61 -10
  76. package/dist/core/brainclaw-version.js +94 -2
  77. package/dist/core/candidates.js +93 -2
  78. package/dist/core/claims.js +419 -0
  79. package/dist/core/codev-metrics.js +77 -0
  80. package/dist/core/codev-personas.js +31 -0
  81. package/dist/core/codev-plan-gen.js +35 -0
  82. package/dist/core/codev-prompts.js +74 -0
  83. package/dist/core/codev-responses.js +62 -0
  84. package/dist/core/codev-rounds.js +218 -0
  85. package/dist/core/config.js +4 -0
  86. package/dist/core/context.js +454 -34
  87. package/dist/core/coordination.js +201 -6
  88. package/dist/core/cross-project.js +230 -16
  89. package/dist/core/default-profiles/doctor.yaml +11 -0
  90. package/dist/core/default-profiles/janitor.yaml +11 -0
  91. package/dist/core/default-profiles/onboarder.yaml +11 -0
  92. package/dist/core/default-profiles/reviewer.yaml +13 -0
  93. package/dist/core/dispatcher.js +1189 -0
  94. package/dist/core/duplicates.js +2 -2
  95. package/dist/core/entity-operations.js +450 -0
  96. package/dist/core/entity-registry.js +344 -0
  97. package/dist/core/event-log.js +1 -0
  98. package/dist/core/events.js +106 -2
  99. package/dist/core/execution-adapters.js +154 -0
  100. package/dist/core/execution-context.js +63 -0
  101. package/dist/core/execution-profile.js +270 -0
  102. package/dist/core/execution.js +255 -0
  103. package/dist/core/facade-schema.js +81 -0
  104. package/dist/core/federation-cloud.js +99 -0
  105. package/dist/core/federation-message.js +52 -0
  106. package/dist/core/federation-transport.js +65 -0
  107. package/dist/core/gc-semantic.js +482 -0
  108. package/dist/core/governance.js +247 -0
  109. package/dist/core/guards.js +19 -0
  110. package/dist/core/ideation.js +72 -0
  111. package/dist/core/identity.js +252 -28
  112. package/dist/core/ids.js +6 -0
  113. package/dist/core/input-validation.js +2 -2
  114. package/dist/core/instruction-templates.js +344 -136
  115. package/dist/core/io.js +90 -11
  116. package/dist/core/lock.js +6 -2
  117. package/dist/core/loops/brief-assembly.js +213 -0
  118. package/dist/core/loops/facade-schema.js +148 -0
  119. package/dist/core/loops/index.js +7 -0
  120. package/dist/core/loops/iteration-engine.js +139 -0
  121. package/dist/core/loops/lock.js +385 -0
  122. package/dist/core/loops/store.js +201 -0
  123. package/dist/core/loops/types.js +403 -0
  124. package/dist/core/loops/verbs.js +534 -0
  125. package/dist/core/markdown.js +15 -3
  126. package/dist/core/memory-compactor.js +432 -0
  127. package/dist/core/memory-git.js +152 -8
  128. package/dist/core/messaging.js +278 -0
  129. package/dist/core/migration.js +32 -1
  130. package/dist/core/mutation-pipeline.js +4 -2
  131. package/dist/core/operations/memory-mutation.js +129 -0
  132. package/dist/core/operations/memory-write.js +78 -0
  133. package/dist/core/operations/plan.js +190 -0
  134. package/dist/core/policy.js +169 -0
  135. package/dist/core/repo-analysis.js +67 -0
  136. package/dist/core/reputation.js +9 -3
  137. package/dist/core/schema.js +546 -21
  138. package/dist/core/search.js +21 -2
  139. package/dist/core/security-cache.js +71 -0
  140. package/dist/core/security-guard.js +152 -0
  141. package/dist/core/security-scoring.js +86 -0
  142. package/dist/core/sequence.js +130 -0
  143. package/dist/core/socket-client.js +113 -0
  144. package/dist/core/staleness.js +246 -0
  145. package/dist/core/state.js +98 -22
  146. package/dist/core/store-resolution.js +54 -12
  147. package/dist/core/toml-writer.js +76 -0
  148. package/dist/core/upgrades/backup.js +232 -0
  149. package/dist/core/upgrades/health-check.js +169 -0
  150. package/dist/core/upgrades/patches/candidate-archive.js +145 -0
  151. package/dist/core/upgrades/patches/handoff-review-strip.js +128 -0
  152. package/dist/core/upgrades/patches/provenance-rollout.js +136 -0
  153. package/dist/core/upgrades/schema-version.js +97 -0
  154. package/dist/core/worktree.js +606 -0
  155. package/dist/facts.js +114 -0
  156. package/dist/facts.json +111 -0
  157. package/docs/architecture/project-refs.md +5 -1
  158. package/docs/cli.md +690 -43
  159. package/docs/concepts/ideation-loop.md +317 -0
  160. package/docs/concepts/loop-engine.md +456 -0
  161. package/docs/concepts/mcp-governance.md +268 -0
  162. package/docs/concepts/memory-staleness.md +122 -0
  163. package/docs/concepts/multi-agent-workflows.md +166 -0
  164. package/docs/concepts/plans-and-claims.md +31 -6
  165. package/docs/concepts/project-md-convention.md +35 -0
  166. package/docs/concepts/troubleshooting.md +220 -0
  167. package/docs/concepts/upgrade-cli.md +202 -0
  168. package/docs/concepts/upgrade-dogfood-procedure.md +114 -0
  169. package/docs/context-format-changelog.md +2 -2
  170. package/docs/context-format.md +2 -2
  171. package/docs/index.md +68 -0
  172. package/docs/integrations/agents.md +15 -16
  173. package/docs/integrations/cline.md +88 -0
  174. package/docs/integrations/codex.md +75 -23
  175. package/docs/integrations/continue.md +60 -0
  176. package/docs/integrations/copilot.md +67 -9
  177. package/docs/integrations/kilocode.md +72 -0
  178. package/docs/integrations/mcp.md +304 -21
  179. package/docs/integrations/mistral-vibe.md +122 -0
  180. package/docs/integrations/opencode.md +84 -0
  181. package/docs/integrations/overview.md +23 -8
  182. package/docs/integrations/roo.md +74 -0
  183. package/docs/integrations/windsurf.md +83 -0
  184. package/docs/mcp-schema-changelog.md +191 -1
  185. package/docs/playbooks/integration/index.md +121 -0
  186. package/docs/playbooks/productivity/index.md +102 -0
  187. package/docs/playbooks/team/index.md +122 -0
  188. package/docs/product/agent-first-model.md +184 -0
  189. package/docs/product/entity-model-audit.md +462 -0
  190. package/docs/quickstart-existing-project.md +135 -0
  191. package/docs/quickstart.md +124 -37
  192. package/docs/release-maintenance.md +79 -0
  193. package/docs/review.md +2 -0
  194. package/docs/server-operations.md +118 -0
  195. package/package.json +20 -12
  196. package/dist/commands/claude-desktop-extension.js +0 -18
  197. package/dist/commands/diff.js +0 -99
  198. package/dist/core/claude-desktop-extension.js +0 -224
@@ -0,0 +1,74 @@
1
+ /**
2
+ * CLI command: brainclaw compact
3
+ *
4
+ * LLM-driven semantic memory compaction — assess pressure or archive old items.
5
+ *
6
+ * @module
7
+ */
8
+ import { memoryExists } from '../core/io.js';
9
+ import { compact as gcCompact, assessMemoryPressure, buildCompactionTemplate } from '../core/gc-semantic.js';
10
+ export function runCompact(options = {}) {
11
+ if (!memoryExists(process.cwd())) {
12
+ console.error('Project memory not initialized. Run `brainclaw init` first.');
13
+ process.exit(1);
14
+ }
15
+ // --assess mode: show pressure assessment and template only, no archiving
16
+ if (options.assess) {
17
+ const assessment = assessMemoryPressure();
18
+ const maxItems = options.maxItems ?? 20;
19
+ const selected = assessment.eligible_items.slice(0, maxItems);
20
+ console.log(`Memory pressure: ${assessment.pressure ? 'YES' : 'no'}`);
21
+ console.log(` Done plans: ${assessment.done_plans} (threshold: ${assessment.thresholds.plans})`);
22
+ console.log(` Closed handoffs: ${assessment.closed_handoffs} (threshold: ${assessment.thresholds.handoffs})`);
23
+ console.log(` Eligible items: ${assessment.eligible_items.length}`);
24
+ if (selected.length > 0) {
25
+ console.log('');
26
+ console.log(buildCompactionTemplate(selected));
27
+ }
28
+ else {
29
+ console.log('No items eligible for compaction.');
30
+ }
31
+ return;
32
+ }
33
+ // Default mode: compact (archive eligible items)
34
+ const result = gcCompact({
35
+ dryRun: options.dryRun,
36
+ maxItems: options.maxItems,
37
+ minAgeDays: options.minAge,
38
+ dedupHandoffs: !options.noDedupHandoffs,
39
+ purgeReleasedClaims: !options.noPurgeClaims,
40
+ purgeSessionNotes: !options.noPurgeSessionNotes,
41
+ });
42
+ if (result.dry_run) {
43
+ console.log(`šŸ” Dry run — ${result.eligible_count} plan/handoff item(s) eligible for compaction.`);
44
+ }
45
+ else {
46
+ console.log(`āœ” Compacted ${result.archived_count}/${result.eligible_count} plan/handoff item(s).`);
47
+ if (result.backup_path) {
48
+ console.log(`Backup: ${result.backup_path}`);
49
+ }
50
+ }
51
+ // Post-v1 extension summaries (pln#436)
52
+ const extras = [];
53
+ if ((result.claims_archived ?? 0) > 0) {
54
+ extras.push(`${result.claims_archived} released claim(s)`);
55
+ }
56
+ if ((result.session_notes_archived ?? 0) > 0) {
57
+ extras.push(`${result.session_notes_archived} session runtime_note(s)`);
58
+ }
59
+ if ((result.handoffs_deduped ?? 0) > 0) {
60
+ extras.push(`${result.handoffs_deduped} duplicate handoff(s)`);
61
+ }
62
+ if (extras.length > 0) {
63
+ const verb = result.dry_run ? 'eligible' : 'archived';
64
+ console.log(` • ${verb}: ${extras.join(', ')}`);
65
+ }
66
+ if (result.template) {
67
+ console.log('');
68
+ console.log(result.template);
69
+ }
70
+ else if (result.eligible_count === 0 && extras.length === 0) {
71
+ console.log('No items eligible for compaction.');
72
+ }
73
+ }
74
+ //# sourceMappingURL=compact.js.map
@@ -1,32 +1,22 @@
1
- import { loadState, persistState } from '../core/state.js';
2
- import { memoryExists } from '../core/io.js';
3
- import { nowISO } from '../core/ids.js';
1
+ import { requireInitialized } from '../core/guards.js';
2
+ import { completeStep } from '../core/operations/plan.js';
4
3
  export function runCompleteStep(planId, stepId) {
5
- if (!memoryExists()) {
6
- console.error('Error: .brainclaw/ not found. Run `brainclaw init` first.');
7
- process.exit(1);
8
- }
9
- const state = loadState();
10
- const plan = state.plan_items.find((p) => p.id === planId || p.short_label === planId);
11
- if (!plan) {
12
- console.error(`Error: Plan '${planId}' not found.`);
13
- process.exit(1);
4
+ requireInitialized(process.cwd());
5
+ try {
6
+ const result = completeStep({ planId, stepId });
7
+ console.log(`āœ” Step completed: [${result.stepId}]`);
8
+ console.log(` Plan [${result.planId}] progress: ${result.doneSteps}/${result.totalSteps} steps done`);
9
+ if (result.planAutoCompleted) {
10
+ console.log(` All steps done — plan auto-completed.`);
11
+ }
12
+ else if (result.doneSteps === result.totalSteps) {
13
+ console.log(` All steps done — consider: brainclaw update-plan ${result.planId} --status done`);
14
+ }
14
15
  }
15
- const step = (plan.steps ?? []).find((s) => s.id === stepId);
16
- if (!step) {
17
- console.error(`Error: Step '${stepId}' not found in plan '${planId}'.`);
16
+ catch (error) {
17
+ const msg = error instanceof Error ? error.message : String(error);
18
+ console.error(`Error: ${msg}`);
18
19
  process.exit(1);
19
20
  }
20
- step.status = 'done';
21
- step.updated_at = nowISO();
22
- plan.updated_at = nowISO();
23
- persistState(state);
24
- const total = plan.steps.length;
25
- const done = plan.steps.filter((s) => s.status === 'done').length;
26
- console.log(`āœ” Step completed: [${step.id}] ${step.text}`);
27
- console.log(` Plan [${plan.id}] progress: ${done}/${total} steps done`);
28
- if (done === total) {
29
- console.log(` All steps done — consider: brainclaw update-plan ${plan.id} --status done`);
30
- }
31
21
  }
32
22
  //# sourceMappingURL=complete-step.js.map
@@ -1,17 +1,13 @@
1
- import { loadState, persistState } from '../core/state.js';
2
1
  import { resolveCurrentAgentName } from '../core/agent-registry.js';
3
2
  import { loadConfig } from '../core/config.js';
4
- import { generateIdWithLabel, nowISO } from '../core/ids.js';
5
3
  import { scanText } from '../core/security.js';
6
- import { memoryExists } from '../core/io.js';
4
+ import { requireInitialized } from '../core/guards.js';
7
5
  import { validateCliInput } from '../core/input-validation.js';
8
6
  import { resolveTargetStore } from '../core/store-resolution.js';
7
+ import { createConstraint } from '../core/operations/memory-write.js';
9
8
  export function runConstraint(text, options = {}) {
10
9
  const cwd = resolveTargetStore(options.cwd ?? process.cwd(), options.store ?? 'local');
11
- if (!memoryExists(cwd)) {
12
- console.error('Error: .brainclaw/ not found. Run `brainclaw init` first.');
13
- process.exit(1);
14
- }
10
+ requireInitialized(cwd);
15
11
  validateCliInput(text, options.tag);
16
12
  const config = loadConfig(cwd);
17
13
  const warnings = scanText(text, config);
@@ -22,21 +18,13 @@ export function runConstraint(text, options = {}) {
22
18
  process.exit(1);
23
19
  }
24
20
  }
25
- const state = loadState(cwd);
26
- const { id, short_label } = generateIdWithLabel('active_constraints');
27
- const entry = {
28
- id,
29
- short_label,
21
+ const result = createConstraint({
30
22
  text,
31
- created_at: nowISO(),
32
23
  author: options.author ?? resolveCurrentAgentName(cwd),
33
- status: 'active',
34
24
  category: options.category,
35
- tags: options.tag ?? [],
36
- related_paths: options.path,
37
- };
38
- state.active_constraints.push(entry);
39
- persistState(state, cwd);
40
- console.log(`āœ” Constraint added: [${id}] ${text}`);
25
+ tags: options.tag,
26
+ relatedPaths: options.path,
27
+ }, cwd);
28
+ console.log(`āœ” Constraint added: [${result.id}] ${text}`);
41
29
  }
42
30
  //# sourceMappingURL=constraint.js.map
@@ -1,17 +1,13 @@
1
- import { loadState, persistState } from '../core/state.js';
2
1
  import { resolveCurrentAgentName } from '../core/agent-registry.js';
3
2
  import { loadConfig } from '../core/config.js';
4
- import { generateIdWithLabel, nowISO } from '../core/ids.js';
5
3
  import { scanText } from '../core/security.js';
6
- import { memoryExists } from '../core/io.js';
4
+ import { requireInitialized } from '../core/guards.js';
7
5
  import { validateCliInput } from '../core/input-validation.js';
8
6
  import { resolveTargetStore } from '../core/store-resolution.js';
7
+ import { createDecision } from '../core/operations/memory-write.js';
9
8
  export function runDecision(text, options = {}) {
10
9
  const cwd = resolveTargetStore(options.cwd ?? process.cwd(), options.store ?? 'local');
11
- if (!memoryExists(cwd)) {
12
- console.error('Error: .brainclaw/ not found. Run `brainclaw init` first.');
13
- process.exit(1);
14
- }
10
+ requireInitialized(cwd);
15
11
  validateCliInput(text, options.tag);
16
12
  const config = loadConfig(cwd);
17
13
  const warnings = scanText(text, config);
@@ -22,21 +18,14 @@ export function runDecision(text, options = {}) {
22
18
  process.exit(1);
23
19
  }
24
20
  }
25
- const state = loadState(cwd);
26
- const { id, short_label } = generateIdWithLabel('recent_decisions');
27
- const entry = {
28
- id,
29
- short_label,
21
+ const result = createDecision({
30
22
  text,
31
- created_at: nowISO(),
32
23
  author: options.author ?? resolveCurrentAgentName(cwd),
33
24
  outcome: options.outcome,
34
- tags: options.tag ?? [],
35
- related_paths: options.path,
36
- plan_id: options.plan,
37
- };
38
- state.recent_decisions.push(entry);
39
- persistState(state, cwd);
40
- console.log(`āœ” Decision added: [${id}] ${text}`);
25
+ tags: options.tag,
26
+ relatedPaths: options.path,
27
+ planId: options.plan,
28
+ }, cwd);
29
+ console.log(`āœ” Decision added: [${result.id}] ${text}`);
41
30
  }
42
31
  //# sourceMappingURL=decision.js.map
@@ -1,18 +1,16 @@
1
- import { loadState, persistState } from '../core/state.js';
2
- import { memoryExists } from '../core/io.js';
1
+ import { requireInitialized } from '../core/guards.js';
2
+ import { deletePlan } from '../core/operations/plan.js';
3
3
  export function runDeletePlan(id, options = {}) {
4
- if (!memoryExists(options.cwd)) {
5
- console.error('Error: .brainclaw/ not found. Run `brainclaw init` first.');
6
- process.exit(1);
4
+ const cwd = options.cwd ?? process.cwd();
5
+ requireInitialized(cwd);
6
+ try {
7
+ const result = deletePlan(id, cwd);
8
+ console.log(`āœ” Plan item deleted: [${result.id}] ${result.text}`);
7
9
  }
8
- const state = loadState(options.cwd);
9
- const index = state.plan_items.findIndex((item) => item.id === id || item.short_label === id);
10
- if (index < 0) {
11
- console.error(`Error: Plan item '${id}' not found.`);
10
+ catch (error) {
11
+ const msg = error instanceof Error ? error.message : String(error);
12
+ console.error(`Error: ${msg}`);
12
13
  process.exit(1);
13
14
  }
14
- const [plan] = state.plan_items.splice(index, 1);
15
- persistState(state, options.cwd);
16
- console.log(`āœ” Plan item deleted: [${plan.id}] ${plan.text}`);
17
15
  }
18
16
  //# sourceMappingURL=delete-plan.js.map
@@ -0,0 +1,16 @@
1
+ import { requireInitialized } from '../core/guards.js';
2
+ import { deleteStep } from '../core/operations/plan.js';
3
+ export function runDeleteStep(planId, stepId) {
4
+ requireInitialized(process.cwd());
5
+ try {
6
+ const result = deleteStep({ planId, stepId });
7
+ console.log(`āœ” Step deleted: [${result.stepId}]`);
8
+ console.log(` Plan [${result.planId}]: ${result.totalSteps} step(s) remaining (${result.doneSteps} done)`);
9
+ }
10
+ catch (error) {
11
+ const msg = error instanceof Error ? error.message : String(error);
12
+ console.error(`Error: ${msg}`);
13
+ process.exit(1);
14
+ }
15
+ }
16
+ //# sourceMappingURL=delete-step.js.map
@@ -0,0 +1,163 @@
1
+ /**
2
+ * CLI command: brainclaw dispatch
3
+ *
4
+ * Subcommands:
5
+ * brainclaw dispatch analysis — show lane status
6
+ * brainclaw dispatch run — send assignments to available agents
7
+ * brainclaw dispatch run --dry — preview assignments without sending
8
+ *
9
+ * @module
10
+ */
11
+ import { memoryExists } from '../core/io.js';
12
+ import { analyzeSequence, dispatch, dispatchReview } from '../core/dispatcher.js';
13
+ import { resolveCurrentAgentName } from '../core/agent-registry.js';
14
+ export function runDispatchAnalysis(options) {
15
+ const cwd = options.cwd;
16
+ if (!memoryExists(cwd)) {
17
+ console.error('Error: .brainclaw/ not found. Run `brainclaw init` first.');
18
+ process.exit(1);
19
+ }
20
+ const analysis = analyzeSequence(cwd ?? process.cwd());
21
+ if (!analysis) {
22
+ console.log('No active sequence found.');
23
+ return;
24
+ }
25
+ if (options.json) {
26
+ console.log(JSON.stringify(analysis, null, 2));
27
+ return;
28
+ }
29
+ console.log(`\nDispatch Analysis — ${analysis.sequence.name}\n`);
30
+ // Ready
31
+ console.log(`🟢 Ready (${analysis.ready.length}):`);
32
+ for (const r of analysis.ready) {
33
+ const lane = r.lane ? ` [${r.lane}]` : '';
34
+ const assignee = r.plan.assignee ? ` → ${r.plan.assignee}` : '';
35
+ console.log(` ${r.plan.short_label ?? r.plan.id}${lane}${assignee}`);
36
+ console.log(` ${r.plan.text.slice(0, 100)}`);
37
+ console.log(` ${r.reason}`);
38
+ }
39
+ // Active
40
+ if (analysis.active.length > 0) {
41
+ console.log(`\nšŸ”µ Active (${analysis.active.length}):`);
42
+ for (const a of analysis.active) {
43
+ const lane = a.lane ? ` [${a.lane}]` : '';
44
+ // Codex r1 finding: on the dispatch surface, `young` is NOT a no-alarm
45
+ // state — it means the coordinator claim exists but no worker session
46
+ // has adopted it yet. "agent working" would mislead the operator into
47
+ // thinking the lane is actively progressing.
48
+ let status = 'working';
49
+ let livenessTag = '';
50
+ if (a.liveness === 'young' && !a.claim.session_id) {
51
+ status = 'pending adoption';
52
+ }
53
+ else if (a.liveness && a.liveness !== 'live' && a.liveness !== 'young') {
54
+ livenessTag = ` [${a.liveness.toUpperCase()}]`;
55
+ }
56
+ console.log(` ${a.plan.short_label ?? a.plan.id}${lane} — ${a.agent} ${status}${livenessTag}`);
57
+ }
58
+ }
59
+ // Blocked
60
+ if (analysis.blocked.length > 0) {
61
+ console.log(`\nšŸ”“ Blocked (${analysis.blocked.length}):`);
62
+ for (const b of analysis.blocked) {
63
+ const lane = b.lane ? ` [${b.lane}]` : '';
64
+ console.log(` ${b.item.planId}${lane} — ${b.reason}`);
65
+ }
66
+ }
67
+ // Done
68
+ if (analysis.done.length > 0) {
69
+ console.log(`\nāœ… Done (${analysis.done.length})`);
70
+ }
71
+ // Available agents
72
+ console.log(`\nAvailable agents: ${analysis.available_agents.length > 0 ? analysis.available_agents.join(', ') : '(none)'}`);
73
+ console.log('');
74
+ }
75
+ export async function runDispatch(options) {
76
+ const cwd = options.cwd;
77
+ if (!memoryExists(cwd)) {
78
+ console.error('Error: .brainclaw/ not found. Run `brainclaw init` first.');
79
+ process.exit(1);
80
+ }
81
+ const effectiveCwd = cwd ?? process.cwd();
82
+ const dispatcherAgent = options.agent ?? resolveCurrentAgentName(effectiveCwd) ?? 'brainclaw';
83
+ const result = await dispatch({
84
+ agents: options.agents?.split(',').map(a => a.trim()),
85
+ lanes: options.lanes?.split(',').map(l => l.trim()),
86
+ maxAssignments: options.max,
87
+ dryRun: options.dry,
88
+ dispatcherAgent,
89
+ autoExecute: options.spawn,
90
+ }, effectiveCwd);
91
+ if (!result) {
92
+ console.log('No active sequence found.');
93
+ return;
94
+ }
95
+ if (options.json) {
96
+ console.log(JSON.stringify(result, null, 2));
97
+ return;
98
+ }
99
+ const { analysis, result: dispatchResult } = result;
100
+ if (options.dry) {
101
+ console.log(`\nšŸ” Dispatch dry run — ${analysis.sequence.name}\n`);
102
+ }
103
+ else {
104
+ console.log(`\nāœ” Dispatch complete — ${analysis.sequence.name}\n`);
105
+ }
106
+ console.log(` Ready: ${analysis.ready.length} | Active: ${analysis.active.length} | Blocked: ${analysis.blocked.length} | Done: ${analysis.done.length}`);
107
+ if (dispatchResult.messages_sent.length > 0) {
108
+ console.log(`\n ${options.dry ? 'Would assign' : 'Assigned'}:`);
109
+ for (const msg of dispatchResult.messages_sent) {
110
+ const lane = msg.lane ? ` (lane: ${msg.lane})` : '';
111
+ const exec = msg.execution_status ? ` [${msg.execution_status}]` : ' [inbox]';
112
+ console.log(` → ${msg.agent}: ${msg.plan_id}${lane}${exec}`);
113
+ }
114
+ }
115
+ if (dispatchResult.skipped.length > 0) {
116
+ console.log('\n Skipped:');
117
+ for (const skip of dispatchResult.skipped) {
118
+ console.log(` - ${skip.plan_id}: ${skip.reason}`);
119
+ }
120
+ }
121
+ console.log('');
122
+ }
123
+ export function runDispatchReview(options) {
124
+ const cwd = options.cwd;
125
+ if (!memoryExists(cwd)) {
126
+ console.error('Error: .brainclaw/ not found. Run `brainclaw init` first.');
127
+ process.exit(1);
128
+ }
129
+ const effectiveCwd = cwd ?? process.cwd();
130
+ const dispatcherAgent = options.agent ?? resolveCurrentAgentName(effectiveCwd) ?? 'brainclaw';
131
+ const result = dispatchReview({
132
+ handoffId: options.handoff,
133
+ reviewer: options.reviewer,
134
+ dryRun: options.dry,
135
+ dispatcherAgent,
136
+ }, effectiveCwd);
137
+ if (options.json) {
138
+ console.log(JSON.stringify(result, null, 2));
139
+ return;
140
+ }
141
+ if (options.dry) {
142
+ console.log('\nšŸ” Review dispatch dry run\n');
143
+ }
144
+ else {
145
+ console.log('\nāœ” Review dispatch complete\n');
146
+ }
147
+ if (result.reviews_sent.length > 0) {
148
+ for (const r of result.reviews_sent) {
149
+ console.log(` → ${r.reviewer} reviewing ${r.handoff_id}${r.plan_id ? ` (${r.plan_id})` : ''} [inbox]`);
150
+ }
151
+ }
152
+ else {
153
+ console.log(' No handoffs ready for review.');
154
+ }
155
+ if (result.skipped.length > 0) {
156
+ console.log('\n Skipped:');
157
+ for (const s of result.skipped) {
158
+ console.log(` - ${s.handoff_id}: ${s.reason}`);
159
+ }
160
+ }
161
+ console.log('');
162
+ }
163
+ //# sourceMappingURL=dispatch.js.map