brainclaw 0.29.2 → 1.5.4

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 (197) hide show
  1. package/LICENSE +21 -74
  2. package/README.md +199 -176
  3. package/dist/brainclaw-vscode.vsix +0 -0
  4. package/dist/cli.js +710 -25
  5. package/dist/commands/accept.js +3 -0
  6. package/dist/commands/add-step.js +11 -26
  7. package/dist/commands/agent-board.js +70 -3
  8. package/dist/commands/audit.js +19 -0
  9. package/dist/commands/check-policy.js +54 -0
  10. package/dist/commands/check-security-mcp.js +145 -0
  11. package/dist/commands/check-security.js +106 -0
  12. package/dist/commands/claim-resource.js +1 -0
  13. package/dist/commands/codev.js +672 -0
  14. package/dist/commands/compact.js +74 -0
  15. package/dist/commands/complete-step.js +16 -26
  16. package/dist/commands/constraint.js +8 -20
  17. package/dist/commands/decision.js +9 -20
  18. package/dist/commands/delete-plan.js +10 -12
  19. package/dist/commands/delete-step.js +16 -0
  20. package/dist/commands/dispatch.js +163 -0
  21. package/dist/commands/doctor.js +1122 -49
  22. package/dist/commands/enable-agent.js +1 -0
  23. package/dist/commands/export.js +280 -22
  24. package/dist/commands/handoff.js +33 -0
  25. package/dist/commands/harvest.js +189 -0
  26. package/dist/commands/hooks.js +82 -25
  27. package/dist/commands/inbox.js +169 -0
  28. package/dist/commands/init.js +38 -31
  29. package/dist/commands/install-hooks.js +71 -44
  30. package/dist/commands/link.js +89 -0
  31. package/dist/commands/list-claims.js +48 -3
  32. package/dist/commands/list-plans.js +129 -25
  33. package/dist/commands/loops-handlers.js +409 -0
  34. package/dist/commands/mcp-read-handlers.js +1628 -0
  35. package/dist/commands/mcp-schemas.generated.js +269 -0
  36. package/dist/commands/mcp.js +4224 -1501
  37. package/dist/commands/plan-resource.js +64 -0
  38. package/dist/commands/plan.js +12 -26
  39. package/dist/commands/prune.js +37 -2
  40. package/dist/commands/reflect.js +20 -7
  41. package/dist/commands/release-claim.js +11 -6
  42. package/dist/commands/release-notes.js +170 -0
  43. package/dist/commands/repair.js +210 -0
  44. package/dist/commands/run-profile.js +57 -0
  45. package/dist/commands/sequence.js +113 -0
  46. package/dist/commands/session-end.js +423 -14
  47. package/dist/commands/session-start.js +214 -41
  48. package/dist/commands/setup-security.js +103 -0
  49. package/dist/commands/setup.js +42 -4
  50. package/dist/commands/stale.js +109 -0
  51. package/dist/commands/switch.js +100 -2
  52. package/dist/commands/trap.js +14 -31
  53. package/dist/commands/update-handoff.js +63 -4
  54. package/dist/commands/update-plan.js +21 -28
  55. package/dist/commands/update-step.js +37 -0
  56. package/dist/commands/upgrade.js +313 -6
  57. package/dist/commands/usage.js +102 -0
  58. package/dist/commands/version.js +20 -0
  59. package/dist/commands/who.js +33 -5
  60. package/dist/commands/worktree.js +105 -0
  61. package/dist/core/actions.js +315 -0
  62. package/dist/core/agent-capability.js +610 -17
  63. package/dist/core/agent-context.js +7 -1
  64. package/dist/core/agent-files.js +1169 -85
  65. package/dist/core/agent-integrations.js +160 -5
  66. package/dist/core/agent-inventory.js +2 -0
  67. package/dist/core/agent-profiles.js +93 -0
  68. package/dist/core/agent-registry.js +162 -30
  69. package/dist/core/agentrun-reconciler.js +345 -0
  70. package/dist/core/agentruns.js +424 -0
  71. package/dist/core/ai-agent-detection.js +31 -10
  72. package/dist/core/archival.js +77 -0
  73. package/dist/core/assignment-sweeper.js +82 -0
  74. package/dist/core/assignments.js +367 -0
  75. package/dist/core/audit.js +30 -0
  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 +381 -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/events.js +106 -2
  98. package/dist/core/execution-adapters.js +154 -0
  99. package/dist/core/execution-context.js +63 -0
  100. package/dist/core/execution-profile.js +270 -0
  101. package/dist/core/execution.js +255 -0
  102. package/dist/core/facade-schema.js +81 -0
  103. package/dist/core/federation-cloud.js +99 -0
  104. package/dist/core/federation-message.js +52 -0
  105. package/dist/core/federation-transport.js +65 -0
  106. package/dist/core/gc-semantic.js +482 -0
  107. package/dist/core/governance.js +247 -0
  108. package/dist/core/guards.js +19 -0
  109. package/dist/core/ideation.js +72 -0
  110. package/dist/core/identity.js +110 -25
  111. package/dist/core/ids.js +6 -0
  112. package/dist/core/input-validation.js +2 -2
  113. package/dist/core/instruction-templates.js +344 -136
  114. package/dist/core/io.js +90 -11
  115. package/dist/core/lock.js +6 -2
  116. package/dist/core/loops/brief-assembly.js +213 -0
  117. package/dist/core/loops/facade-schema.js +148 -0
  118. package/dist/core/loops/index.js +7 -0
  119. package/dist/core/loops/iteration-engine.js +139 -0
  120. package/dist/core/loops/lock.js +385 -0
  121. package/dist/core/loops/store.js +201 -0
  122. package/dist/core/loops/types.js +403 -0
  123. package/dist/core/loops/verbs.js +534 -0
  124. package/dist/core/markdown.js +15 -3
  125. package/dist/core/memory-compactor.js +432 -0
  126. package/dist/core/memory-git.js +152 -8
  127. package/dist/core/messaging.js +278 -0
  128. package/dist/core/migration.js +32 -1
  129. package/dist/core/mutation-pipeline.js +4 -2
  130. package/dist/core/operations/memory-mutation.js +129 -0
  131. package/dist/core/operations/memory-write.js +78 -0
  132. package/dist/core/operations/plan.js +190 -0
  133. package/dist/core/policy.js +169 -0
  134. package/dist/core/reputation.js +9 -3
  135. package/dist/core/schema.js +491 -6
  136. package/dist/core/search.js +21 -2
  137. package/dist/core/security-cache.js +71 -0
  138. package/dist/core/security-guard.js +152 -0
  139. package/dist/core/security-scoring.js +86 -0
  140. package/dist/core/sequence.js +130 -0
  141. package/dist/core/socket-client.js +113 -0
  142. package/dist/core/staleness.js +246 -0
  143. package/dist/core/state.js +98 -22
  144. package/dist/core/store-resolution.js +43 -11
  145. package/dist/core/toml-writer.js +76 -0
  146. package/dist/core/upgrades/backup.js +232 -0
  147. package/dist/core/upgrades/health-check.js +169 -0
  148. package/dist/core/upgrades/patches/candidate-archive.js +145 -0
  149. package/dist/core/upgrades/patches/handoff-review-strip.js +128 -0
  150. package/dist/core/upgrades/patches/provenance-rollout.js +136 -0
  151. package/dist/core/upgrades/schema-version.js +97 -0
  152. package/dist/core/worktree.js +606 -0
  153. package/dist/facts.js +114 -0
  154. package/dist/facts.json +111 -0
  155. package/docs/architecture/project-refs.md +5 -1
  156. package/docs/cli.md +690 -43
  157. package/docs/concepts/ideation-loop.md +317 -0
  158. package/docs/concepts/loop-engine.md +456 -0
  159. package/docs/concepts/mcp-governance.md +268 -0
  160. package/docs/concepts/memory-staleness.md +122 -0
  161. package/docs/concepts/multi-agent-workflows.md +166 -0
  162. package/docs/concepts/plans-and-claims.md +31 -6
  163. package/docs/concepts/project-md-convention.md +35 -0
  164. package/docs/concepts/troubleshooting.md +220 -0
  165. package/docs/concepts/upgrade-cli.md +202 -0
  166. package/docs/concepts/upgrade-dogfood-procedure.md +114 -0
  167. package/docs/context-format-changelog.md +2 -2
  168. package/docs/context-format.md +2 -2
  169. package/docs/index.md +68 -0
  170. package/docs/integrations/agents.md +15 -16
  171. package/docs/integrations/cline.md +88 -0
  172. package/docs/integrations/codex.md +75 -23
  173. package/docs/integrations/continue.md +60 -0
  174. package/docs/integrations/copilot.md +67 -9
  175. package/docs/integrations/kilocode.md +72 -0
  176. package/docs/integrations/mcp.md +304 -21
  177. package/docs/integrations/mistral-vibe.md +122 -0
  178. package/docs/integrations/opencode.md +84 -0
  179. package/docs/integrations/overview.md +23 -8
  180. package/docs/integrations/roo.md +74 -0
  181. package/docs/integrations/windsurf.md +83 -0
  182. package/docs/mcp-schema-changelog.md +191 -1
  183. package/docs/playbooks/integration/index.md +121 -0
  184. package/docs/playbooks/productivity/index.md +102 -0
  185. package/docs/playbooks/team/index.md +122 -0
  186. package/docs/product/agent-first-model.md +184 -0
  187. package/docs/product/entity-model-audit.md +462 -0
  188. package/docs/product/positioning.md +10 -10
  189. package/docs/quickstart-existing-project.md +135 -0
  190. package/docs/quickstart.md +124 -37
  191. package/docs/release-maintenance.md +79 -0
  192. package/docs/review.md +2 -0
  193. package/docs/server-operations.md +118 -0
  194. package/package.json +21 -13
  195. package/dist/commands/claude-desktop-extension.js +0 -18
  196. package/dist/commands/diff.js +0 -99
  197. package/dist/core/claude-desktop-extension.js +0 -224
@@ -0,0 +1,136 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { z } from 'zod';
4
+ /**
5
+ * Provenance rollout (P6.3) — v1.0 schema migration patch.
6
+ *
7
+ * Stamps every pre-existing memory record with a `provenance` field
8
+ * of kind `legacy`. From v1.0 onward, write paths populate the
9
+ * typed discriminated-union provenance (agent / auto_reflect / user /
10
+ * loop_artifact / federation / correction / legacy); legacy records
11
+ * keep the `legacy` tag so default read filters can exclude them
12
+ * until an operator promotes them.
13
+ *
14
+ * Scope: decisions, constraints, traps, handoffs, runtime_notes.
15
+ *
16
+ * Auto-reflect retroactive detection: not attempted. Pre-v1.0 records
17
+ * do not carry a reliable marker distinguishing auto-reflect writes
18
+ * from human-authored writes at the entity level. Stamping every
19
+ * pre-existing record as `legacy` is the safe default — new
20
+ * auto-reflect writes from v1.0 onward carry the correct provenance
21
+ * from birth.
22
+ *
23
+ * Like the other patches, implementation uses raw JSON read/write
24
+ * (no Zod round-trip) so unknown fields survive the rewrite.
25
+ */
26
+ export const MIGRATIONS_ARCHIVE_SUBPATH = path.join('archive', 'migrations');
27
+ export const PROVENANCE_ROLLOUT_LOG = 'provenance-rollout.json';
28
+ export const PROVENANCE_ENTITY_LAYOUTS = [
29
+ { kind: 'decision', dir: path.join('memory', 'decisions'), recursive: false },
30
+ { kind: 'constraint', dir: path.join('memory', 'constraints'), recursive: false },
31
+ { kind: 'trap', dir: path.join('memory', 'traps'), recursive: false },
32
+ { kind: 'handoff', dir: path.join('coordination', 'handoffs'), recursive: false },
33
+ { kind: 'runtime_note', dir: path.join('coordination', 'runtime'), recursive: true },
34
+ ];
35
+ export const ProvenanceRolloutEntrySchema = z.object({
36
+ kind: z.enum(['decision', 'constraint', 'trap', 'handoff', 'runtime_note']),
37
+ id: z.string(),
38
+ short_label: z.string().nullable(),
39
+ record_path: z.string(),
40
+ stamped_kind: z.literal('legacy'),
41
+ stamped_at: z.string().datetime(),
42
+ });
43
+ export const ProvenanceRolloutLogSchema = z.object({
44
+ schema_version: z.literal(1),
45
+ stamped_at: z.string().datetime(),
46
+ reason: z.string(),
47
+ count: z.number().int().nonnegative(),
48
+ counts_by_kind: z.record(z.string(), z.number().int().nonnegative()),
49
+ entries: z.array(ProvenanceRolloutEntrySchema),
50
+ });
51
+ export function rolloutProvenance(options) {
52
+ const { storePath } = options;
53
+ const now = (options.now ?? (() => new Date()))();
54
+ const dateStamp = now.toISOString().slice(0, 10);
55
+ const logDir = path.join(storePath, MIGRATIONS_ARCHIVE_SUBPATH, dateStamp);
56
+ const logPath = path.join(logDir, PROVENANCE_ROLLOUT_LOG);
57
+ const reason = options.reason ?? 'v1.0 schema migration (P6.3): stamp legacy provenance on pre-existing memory records';
58
+ let scanned = 0;
59
+ const entries = [];
60
+ const countsByKind = {};
61
+ for (const layout of PROVENANCE_ENTITY_LAYOUTS) {
62
+ const fullDir = path.join(storePath, layout.dir);
63
+ const files = listJsonFiles(fullDir, layout.recursive);
64
+ scanned += files.length;
65
+ for (const file of files) {
66
+ const raw = JSON.parse(fs.readFileSync(file, 'utf-8'));
67
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
68
+ throw new Error(`provenance-rollout: ${file} is not a JSON object`);
69
+ }
70
+ const obj = raw;
71
+ if (obj.provenance !== undefined) {
72
+ if (isValidV1Provenance(obj.provenance))
73
+ continue;
74
+ throw new Error(`provenance-rollout: ${file} has a malformed \`provenance\` field; ` +
75
+ `expected an object with a known kind, got ${JSON.stringify(obj.provenance)}`);
76
+ }
77
+ const entry = {
78
+ kind: layout.kind,
79
+ id: typeof obj.id === 'string' ? obj.id : path.basename(file, '.json'),
80
+ short_label: typeof obj.short_label === 'string' ? obj.short_label : null,
81
+ record_path: path.relative(storePath, file).split(path.sep).join('/'),
82
+ stamped_kind: 'legacy',
83
+ stamped_at: now.toISOString(),
84
+ };
85
+ entries.push(entry);
86
+ countsByKind[layout.kind] = (countsByKind[layout.kind] ?? 0) + 1;
87
+ if (!options.dryRun) {
88
+ const next = { ...obj, provenance: { kind: 'legacy' } };
89
+ fs.writeFileSync(file, JSON.stringify(next, null, 2), 'utf-8');
90
+ }
91
+ }
92
+ }
93
+ if (entries.length === 0) {
94
+ return { status: 'noop', scanned, stamped: [], countsByKind, logPath: null };
95
+ }
96
+ if (options.dryRun) {
97
+ return { status: 'planned', scanned, stamped: entries, countsByKind, logPath };
98
+ }
99
+ fs.mkdirSync(logDir, { recursive: true });
100
+ const log = {
101
+ schema_version: 1,
102
+ stamped_at: now.toISOString(),
103
+ reason,
104
+ count: entries.length,
105
+ counts_by_kind: countsByKind,
106
+ entries,
107
+ };
108
+ fs.writeFileSync(logPath, JSON.stringify(log, null, 2), 'utf-8');
109
+ return { status: 'stamped', scanned, stamped: entries, countsByKind, logPath };
110
+ }
111
+ const V1_PROVENANCE_KINDS = new Set([
112
+ 'agent', 'auto_reflect', 'user', 'loop_artifact', 'federation', 'correction', 'legacy',
113
+ ]);
114
+ function isValidV1Provenance(value) {
115
+ if (!value || typeof value !== 'object' || Array.isArray(value))
116
+ return false;
117
+ const kind = value.kind;
118
+ return typeof kind === 'string' && V1_PROVENANCE_KINDS.has(kind);
119
+ }
120
+ function listJsonFiles(dir, recursive) {
121
+ if (!fs.existsSync(dir))
122
+ return [];
123
+ const out = [];
124
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
125
+ const full = path.join(dir, entry.name);
126
+ if (entry.isFile() && entry.name.endsWith('.json')) {
127
+ out.push(full);
128
+ continue;
129
+ }
130
+ if (recursive && entry.isDirectory()) {
131
+ out.push(...listJsonFiles(full, true));
132
+ }
133
+ }
134
+ return out;
135
+ }
136
+ //# sourceMappingURL=provenance-rollout.js.map
@@ -0,0 +1,97 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { z } from 'zod';
4
+ import { writeFileAtomic } from '../io.js';
5
+ /**
6
+ * Store schema version tracker — distinct from the MCP SCHEMA_VERSION
7
+ * constant (which tracks what the *server* expects). This file tracks
8
+ * what the *store* is currently at.
9
+ *
10
+ * Lives at `.brainclaw/schema-version.json`. Absent = implicit 0.6.0
11
+ * (the pre-migration baseline).
12
+ *
13
+ * The history trail records every upgrade transition so an operator
14
+ * can audit what ran, when, and which patches landed — useful when
15
+ * dogfooding across two installations and comparing them.
16
+ */
17
+ export const SCHEMA_VERSION_FILE = 'schema-version.json';
18
+ /** Implicit baseline when `.brainclaw/schema-version.json` is absent. */
19
+ export const IMPLICIT_BASELINE_VERSION = '0.6.0';
20
+ /** Known store schema states for the v1 upgrade/rollback flow. */
21
+ export const KNOWN_STORE_SCHEMA_VERSIONS = [IMPLICIT_BASELINE_VERSION, '0.7.0', '0.8.0'];
22
+ /** Target of a `--to=1.0` upgrade (migration-complete marker). */
23
+ export const V1_TARGET_SCHEMA_VERSION = '0.8.0';
24
+ export const SchemaVersionTransitionSchema = z.object({
25
+ from: z.string(),
26
+ to: z.string(),
27
+ at: z.string().datetime(),
28
+ patches: z.array(z.string()),
29
+ reason: z.string().optional(),
30
+ });
31
+ export const SchemaVersionFileSchema = z.object({
32
+ schema_version: z.literal(1),
33
+ current: z.string(),
34
+ history: z.array(SchemaVersionTransitionSchema),
35
+ });
36
+ export function schemaVersionFilePath(storePath) {
37
+ return path.join(storePath, SCHEMA_VERSION_FILE);
38
+ }
39
+ export function readSchemaVersion(storePath) {
40
+ const file = schemaVersionFilePath(storePath);
41
+ if (!fs.existsSync(file)) {
42
+ return { present: false, current: IMPLICIT_BASELINE_VERSION, history: [] };
43
+ }
44
+ const raw = JSON.parse(fs.readFileSync(file, 'utf-8'));
45
+ const parsed = SchemaVersionFileSchema.parse(raw);
46
+ return { present: true, current: parsed.current, history: parsed.history };
47
+ }
48
+ /**
49
+ * Record a schema-version transition. Idempotent — if the store is
50
+ * already at the target version the call is a noop. Otherwise,
51
+ * appends a transition entry to the history and writes the file
52
+ * atomically.
53
+ */
54
+ export function bumpSchemaVersion(options) {
55
+ const now = (options.now ?? (() => new Date()))();
56
+ const file = schemaVersionFilePath(options.storePath);
57
+ const existing = readSchemaVersion(options.storePath);
58
+ if (existing.current === options.to) {
59
+ return {
60
+ status: 'noop',
61
+ from: existing.current,
62
+ to: options.to,
63
+ filePath: file,
64
+ transitions: existing.history.length,
65
+ };
66
+ }
67
+ if (options.dryRun) {
68
+ return {
69
+ status: 'planned',
70
+ from: existing.current,
71
+ to: options.to,
72
+ filePath: file,
73
+ transitions: existing.history.length + 1,
74
+ };
75
+ }
76
+ const transition = {
77
+ from: existing.current,
78
+ to: options.to,
79
+ at: now.toISOString(),
80
+ patches: options.patches,
81
+ reason: options.reason,
82
+ };
83
+ const next = {
84
+ schema_version: 1,
85
+ current: options.to,
86
+ history: [...existing.history, transition],
87
+ };
88
+ writeFileAtomic(file, JSON.stringify(next, null, 2));
89
+ return {
90
+ status: 'bumped',
91
+ from: existing.current,
92
+ to: options.to,
93
+ filePath: file,
94
+ transitions: next.history.length,
95
+ };
96
+ }
97
+ //# sourceMappingURL=schema-version.js.map