brainclaw 1.9.1 → 1.10.0

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 (71) hide show
  1. package/README.md +47 -1
  2. package/dist/brainclaw-vscode.vsix +0 -0
  3. package/dist/cli.js +18 -1
  4. package/dist/commands/code-map.js +129 -0
  5. package/dist/commands/codev.js +7 -0
  6. package/dist/commands/mcp.js +121 -0
  7. package/dist/commands/run-profile.js +3 -2
  8. package/dist/commands/switch.js +100 -89
  9. package/dist/core/agent-files.js +12 -0
  10. package/dist/core/code-map/backend.js +123 -0
  11. package/dist/core/code-map/core.js +81 -0
  12. package/dist/core/code-map/drafts.js +2 -0
  13. package/dist/core/code-map/extractor.js +29 -0
  14. package/dist/core/code-map/finalizer.js +191 -0
  15. package/dist/core/code-map/freshness.js +108 -0
  16. package/dist/core/code-map/ids.js +0 -0
  17. package/dist/core/code-map/importable.js +35 -0
  18. package/dist/core/code-map/indexes.js +197 -0
  19. package/dist/core/code-map/lang/java/imports.scm +17 -0
  20. package/dist/core/code-map/lang/java/index.js +254 -0
  21. package/dist/core/code-map/lang/java/tags.scm +48 -0
  22. package/dist/core/code-map/lang/php/imports.scm +21 -0
  23. package/dist/core/code-map/lang/php/index.js +251 -0
  24. package/dist/core/code-map/lang/php/tags.scm +44 -0
  25. package/dist/core/code-map/lang/provider.js +9 -0
  26. package/dist/core/code-map/lang/providers.js +24 -0
  27. package/dist/core/code-map/lang/python/imports.scm +90 -0
  28. package/dist/core/code-map/lang/python/index.js +364 -0
  29. package/dist/core/code-map/lang/python/tags.scm +81 -0
  30. package/dist/core/code-map/lang/query-runtime.js +374 -0
  31. package/dist/core/code-map/lang/registry.js +125 -0
  32. package/dist/core/code-map/lang/typescript/imports.scm +90 -0
  33. package/dist/core/code-map/lang/typescript/index.js +306 -0
  34. package/dist/core/code-map/lang/typescript/tags.js.scm +106 -0
  35. package/dist/core/code-map/lang/typescript/tags.scm +151 -0
  36. package/dist/core/code-map/lock.js +210 -0
  37. package/dist/core/code-map/materialized.js +51 -0
  38. package/dist/core/code-map/memory-reader.js +59 -0
  39. package/dist/core/code-map/paths.js +53 -0
  40. package/dist/core/code-map/query.js +568 -0
  41. package/dist/core/code-map/refresh.js +0 -0
  42. package/dist/core/code-map/resolve.js +177 -0
  43. package/dist/core/code-map/store.js +206 -0
  44. package/dist/core/code-map/types.js +288 -0
  45. package/dist/core/code-map/vocabulary.js +57 -0
  46. package/dist/core/code-map/wasm-loader.js +294 -0
  47. package/dist/core/code-map/work-section.js +206 -0
  48. package/dist/core/codev-rounds.js +4 -0
  49. package/dist/core/execution-adapters.js +11 -10
  50. package/dist/core/execution-profile.js +58 -0
  51. package/dist/core/facade-schema.js +9 -0
  52. package/dist/core/instruction-templates.js +2 -0
  53. package/dist/core/mcp-command-resolution.js +3 -1
  54. package/dist/core/store-resolution.js +41 -4
  55. package/dist/facts.js +9 -5
  56. package/dist/facts.json +8 -4
  57. package/dist/vendor/web-tree-sitter/tree-sitter.js +3980 -0
  58. package/dist/vendor/web-tree-sitter/tree-sitter.wasm +0 -0
  59. package/dist/wasm/tree-sitter-java.wasm +0 -0
  60. package/dist/wasm/tree-sitter-javascript.wasm +0 -0
  61. package/dist/wasm/tree-sitter-php.wasm +0 -0
  62. package/dist/wasm/tree-sitter-python.wasm +0 -0
  63. package/dist/wasm/tree-sitter-tsx.wasm +0 -0
  64. package/dist/wasm/tree-sitter-typescript.wasm +0 -0
  65. package/dist/wasm/tree-sitter.wasm +0 -0
  66. package/docs/cli.md +46 -8
  67. package/docs/code-map.md +198 -0
  68. package/docs/integrations/mcp.md +13 -6
  69. package/docs/mcp-schema-changelog.md +7 -3
  70. package/docs/quickstart.md +1 -1
  71. package/package.json +11 -6
@@ -196,5 +196,14 @@ export const FacadeResponseSchema = z.object({
196
196
  * remains for the bootstrap hint; new consumers should read this array.
197
197
  */
198
198
  next_actions: z.array(NextActionSchema).optional(),
199
+ /**
200
+ * Code Map P0 (spec §10): opt-in, present ONLY when the project's Code Map
201
+ * manifest carries `code_map_enabled: true`. Absent for every project that
202
+ * has not turned Code Map on (the P0 default), so existing bclaw_work callers
203
+ * are unaffected and the off-path adds no work. Shape mirrors
204
+ * CodeMapWorkSection: { enabled, matches, freshness_badge, missing_index?,
205
+ * lock_wait_ms? }. Passthrough so the section can evolve without a schema bump.
206
+ */
207
+ code_map: z.object({}).passthrough().optional(),
199
208
  });
200
209
  //# sourceMappingURL=facade-schema.js.map
@@ -233,6 +233,7 @@ function renderSessionProtocol() {
233
233
  '1. Call `bclaw_work(intent)` (consult|execute|resume|review) — one call handles session, context, and claim (execute). Every response carries `next_actions` with the exact follow-up calls: follow those instead of memorizing the API.',
234
234
  '2. Canonical grammar for memory objects: `bclaw_find` / `bclaw_get` / `bclaw_create` / `bclaw_update` / `bclaw_remove` / `bclaw_transition` (entity, …).',
235
235
  '3. Do not assume project state without reading brainclaw context first.',
236
+ '4. Before editing unfamiliar code, orient with the **Code Map**: `bclaw_code_brief(target=<symbol|path>)` for a ranked reading list + related decisions/traps, `bclaw_code_find(query=<name>)` to locate a symbol/class/component. Don\'t grep the repo blind when a symbol index already answers "where is X / what should I read first". A `missing_index`/stale badge means run `bclaw_code_refresh` first.',
236
237
  '',
237
238
  'Escalation (only when orchestrating other agents): `bclaw_coordinate(intent=review|consult|assign)`. Verify any dispatch with `bclaw_dispatch_status(target_id)` — trust its sentinel-based verdict, not the tracked pid. Details: `docs/concepts/dispatch-lifecycle.md`.',
238
239
  ].join('\n');
@@ -322,6 +323,7 @@ function renderAvailableTools() {
322
323
  '**Session/claims:** `bclaw_session_start`, `bclaw_session_end`, `bclaw_claim`, `bclaw_release_claim` · **steps:** `bclaw_add_step`, `bclaw_complete_step`, `bclaw_update_step`, `bclaw_delete_step` · **sequences:** `bclaw_list_sequences`, `bclaw_create_sequence`, `bclaw_update_sequence`, `bclaw_delete_sequence`',
323
324
  '**Inbox:** `bclaw_read_inbox`, `bclaw_ack_message`, `bclaw_send_message`, `bclaw_correct_handoff` · **capture:** `bclaw_write_note`, `bclaw_quick_capture(text, type?)` · **search:** `bclaw_search` · **setup:** `bclaw_setup`, `bclaw_bootstrap`, `bclaw_switch`, `bclaw_release_notes`',
324
325
  '**Escalation (orchestrators):** `bclaw_coordinate(intent=review|consult|assign|ideate)` · `bclaw_dispatch(intent=execute)` on an active sequence · `bclaw_loop(intent=turn|complete_turn|advance|close)` to drive turns · `bclaw_dispatch_status(target_id)` to verify',
326
+ '**Code discovery (Code Map):** `bclaw_code_find(query)` locate a symbol/class/component · `bclaw_code_brief(target)` ranked reading list + related memory before editing · `bclaw_code_status` / `bclaw_code_refresh` check freshness / rebuild the symbol+import index. Use it before grepping unfamiliar code — see `docs/code-map.md`.',
325
327
  '',
326
328
  'Responses are self-teaching — follow their `next_actions`. Full catalog + stability contract: `docs/integrations/mcp.md`, `docs/concepts/mcp-governance.md`.',
327
329
  ].join('\n');
@@ -216,7 +216,9 @@ export function brainclawMcpEntry(agentName, existing, workspacePath) {
216
216
  export function quoteShellArg(arg) {
217
217
  if (/^[A-Za-z0-9_./:=+-]+$/.test(arg))
218
218
  return arg;
219
- return `"${arg.replace(/"/g, '\\"')}"`;
219
+ // Escape backslashes before quotes — otherwise an input like `\"` would
220
+ // collapse to a quote that breaks out of the quoted argument.
221
+ return `"${arg.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
220
222
  }
221
223
  /**
222
224
  * Resolve the brainclaw CLI invocation for hook configs.
@@ -94,8 +94,10 @@ export function resolveTargetStore(cwd = process.cwd(), target = 'local', option
94
94
  * 2. BRAINCLAW_CWD env var → workspace anchor injected by MCP configs
95
95
  * 3. BRAINCLAW_PROJECT env var → resolved by name/path from workspace anchor
96
96
  * 4. Session-scoped active project (from .current-session under the anchor)
97
- * 5. Global active-project.json in workspace root
98
- * 6. Workspace anchor or process.cwd()
97
+ * 5. cwd_child — the child project the agent is physically inside, under the anchor
98
+ * 5b. cwd_child (no anchor) same, ceiling = discovered workspace root (F2)
99
+ * 6. Global active-project.json in workspace root
100
+ * 7. Workspace anchor or process.cwd()
99
101
  */
100
102
  export function resolveEffectiveCwd(options = {}) {
101
103
  return resolveEffectiveCwdInfo(options).cwd;
@@ -138,7 +140,42 @@ export function resolveEffectiveCwdInfo(options = {}) {
138
140
  return { cwd: sp.path, active_source: 'session', resolved_project: { path: sp.path, name: sp.name } };
139
141
  }
140
142
  }
141
- // 5. Global active-project.json from workspace root
143
+ // 5. cwd_child when anchored and the agent is physically inside a child store
144
+ // STRICTLY under the anchor, resolve THAT child rather than the shared global
145
+ // pointer or the anchor root. This is the independence rule: physical location
146
+ // beats a shared/stale global (an agent working in apps/api resolves api, not the
147
+ // monorepo root, and is not hijacked by another agent's global switch).
148
+ //
149
+ // GUARD (Codex review): only fire when baseCwd differs from the anchor AND is
150
+ // at/below it. `findClosestStoreBelow` walks UP to the ceiling but does NOT prove
151
+ // baseCwd sits below it — without the `isAtOrBelow` guard a baseCwd OUTSIDE the
152
+ // anchor could match an unrelated `.brainclaw` before hitting the filesystem root.
153
+ if (baseCwd !== anchorCwd && isAtOrBelow(baseCwd, anchorCwd)) {
154
+ const child = findClosestStoreBelow(baseCwd, anchorCwd);
155
+ if (child && path.resolve(child) !== path.resolve(anchorCwd)) {
156
+ return { cwd: child, active_source: 'cwd_child', resolved_project: projectInfo(child) };
157
+ }
158
+ }
159
+ // 5b. cwd_child (NO anchor) — F2 [trp_71accb07]: even without a BRAINCLAW_CWD
160
+ // anchor, an agent physically inside a child project must resolve THAT
161
+ // child rather than a stale/shared global pointer set by another agent.
162
+ // Ceiling = the discovered workspace root via resolveWorkspaceRoot(baseCwd)
163
+ // — NOT os.homedir() (that would revive the F6 boundary edge and could let
164
+ // an unrelated home store influence a monorepo worker). Same containment
165
+ // guard as the anchored case (isAtOrBelow + a child strictly below).
166
+ // For a single-project repo this is a strict no-op: findClosestStoreBelow
167
+ // walks UP to the ceiling EXCLUSIVELY, so it can never return the lone root
168
+ // store (Codex cadrage non-regression proof, batch 2).
169
+ if (!hasEnvWorkspace) {
170
+ const physicalRoot = resolveWorkspaceRoot(baseCwd, options.storeChainOptions);
171
+ if (physicalRoot && isAtOrBelow(baseCwd, physicalRoot)) {
172
+ const child = findClosestStoreBelow(baseCwd, physicalRoot);
173
+ if (child && path.resolve(child) !== path.resolve(physicalRoot)) {
174
+ return { cwd: child, active_source: 'cwd_child', resolved_project: projectInfo(child) };
175
+ }
176
+ }
177
+ }
178
+ // 6. Global active-project.json from workspace root
142
179
  const wsRoot = hasEnvWorkspace ? anchorCwd : resolveWorkspaceRoot(anchorCwd, options.storeChainOptions);
143
180
  if (wsRoot) {
144
181
  const active = loadActiveProject(wsRoot);
@@ -146,7 +183,7 @@ export function resolveEffectiveCwdInfo(options = {}) {
146
183
  return { cwd: active.path, active_source: 'global', resolved_project: { path: active.path, name: active.name } };
147
184
  }
148
185
  }
149
- // 6. Default
186
+ // 7. Default
150
187
  return { cwd: anchorCwd, active_source: 'cwd', resolved_project: projectInfo(anchorCwd) };
151
188
  }
152
189
  function projectInfo(cwd) {
package/dist/facts.js CHANGED
@@ -1,11 +1,11 @@
1
1
  // Generated by scripts/emit-site-facts.mjs at build time. Do not edit manually.
2
- // Source: brainclaw v1.9.1 on 2026-06-18T15:15:04.496Z
2
+ // Source: brainclaw v1.10.0 on 2026-06-20T21:43:38.629Z
3
3
  export const FACTS = {
4
- "version": "1.9.1",
5
- "generated_at": "2026-06-18T15:15:04.496Z",
4
+ "version": "1.10.0",
5
+ "generated_at": "2026-06-20T21:43:38.629Z",
6
6
  "tools": {
7
- "count": 62,
8
- "published_count": 61,
7
+ "count": 66,
8
+ "published_count": 65,
9
9
  "names": [
10
10
  "bclaw_bootstrap",
11
11
  "bclaw_release_notes",
@@ -31,6 +31,10 @@ export const FACTS = {
31
31
  "bclaw_read_inbox",
32
32
  "bclaw_get_thread",
33
33
  "bclaw_dispatch_status",
34
+ "bclaw_code_status",
35
+ "bclaw_code_find",
36
+ "bclaw_code_brief",
37
+ "bclaw_code_refresh",
34
38
  "bclaw_dispatch",
35
39
  "bclaw_send_message",
36
40
  "bclaw_ack_message",
package/dist/facts.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
- "version": "1.9.1",
3
- "generated_at": "2026-06-18T15:15:04.496Z",
2
+ "version": "1.10.0",
3
+ "generated_at": "2026-06-20T21:43:38.629Z",
4
4
  "tools": {
5
- "count": 62,
6
- "published_count": 61,
5
+ "count": 66,
6
+ "published_count": 65,
7
7
  "names": [
8
8
  "bclaw_bootstrap",
9
9
  "bclaw_release_notes",
@@ -29,6 +29,10 @@
29
29
  "bclaw_read_inbox",
30
30
  "bclaw_get_thread",
31
31
  "bclaw_dispatch_status",
32
+ "bclaw_code_status",
33
+ "bclaw_code_find",
34
+ "bclaw_code_brief",
35
+ "bclaw_code_refresh",
32
36
  "bclaw_dispatch",
33
37
  "bclaw_send_message",
34
38
  "bclaw_ack_message",