@memnexus-ai/mx-agent-cli 0.1.294-next.0 → 0.1.295-next.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 (450) hide show
  1. package/dist/__tests__/agents-md-canonicalization.test.js +31 -1
  2. package/dist/__tests__/agents-md-canonicalization.test.js.map +1 -1
  3. package/dist/__tests__/behavioral-extraction.test.js +50 -0
  4. package/dist/__tests__/behavioral-extraction.test.js.map +1 -1
  5. package/dist/__tests__/bootstrap-behavioral-contract.test.js +6 -3
  6. package/dist/__tests__/bootstrap-behavioral-contract.test.js.map +1 -1
  7. package/dist/__tests__/bundle-config.test.js +28 -2
  8. package/dist/__tests__/bundle-config.test.js.map +1 -1
  9. package/dist/__tests__/catalog-interaction.test.d.ts +25 -0
  10. package/dist/__tests__/catalog-interaction.test.d.ts.map +1 -0
  11. package/dist/__tests__/catalog-interaction.test.js +269 -0
  12. package/dist/__tests__/catalog-interaction.test.js.map +1 -0
  13. package/dist/__tests__/catalog-named-memories.test.d.ts +2 -0
  14. package/dist/__tests__/catalog-named-memories.test.d.ts.map +1 -0
  15. package/dist/__tests__/catalog-named-memories.test.js +204 -0
  16. package/dist/__tests__/catalog-named-memories.test.js.map +1 -0
  17. package/dist/__tests__/catalog-origin-main.test.d.ts +15 -0
  18. package/dist/__tests__/catalog-origin-main.test.d.ts.map +1 -0
  19. package/dist/__tests__/catalog-origin-main.test.js +296 -0
  20. package/dist/__tests__/catalog-origin-main.test.js.map +1 -0
  21. package/dist/__tests__/catalog.test.d.ts +2 -0
  22. package/dist/__tests__/catalog.test.d.ts.map +1 -0
  23. package/dist/__tests__/catalog.test.js +131 -0
  24. package/dist/__tests__/catalog.test.js.map +1 -0
  25. package/dist/__tests__/cli-build-integration.test.d.ts +2 -0
  26. package/dist/__tests__/cli-build-integration.test.d.ts.map +1 -0
  27. package/dist/__tests__/cli-build-integration.test.js +64 -0
  28. package/dist/__tests__/cli-build-integration.test.js.map +1 -0
  29. package/dist/__tests__/cli-build.test.d.ts +2 -0
  30. package/dist/__tests__/cli-build.test.d.ts.map +1 -0
  31. package/dist/__tests__/cli-build.test.js +640 -0
  32. package/dist/__tests__/cli-build.test.js.map +1 -0
  33. package/dist/__tests__/codex-deploy-config.test.js +60 -0
  34. package/dist/__tests__/codex-deploy-config.test.js.map +1 -1
  35. package/dist/__tests__/completion-rows-discriminate.test.d.ts +20 -0
  36. package/dist/__tests__/completion-rows-discriminate.test.d.ts.map +1 -0
  37. package/dist/__tests__/completion-rows-discriminate.test.js +481 -0
  38. package/dist/__tests__/completion-rows-discriminate.test.js.map +1 -0
  39. package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts +2 -0
  40. package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts.map +1 -0
  41. package/dist/__tests__/config-fidelity-archived-symlinks.test.js +127 -0
  42. package/dist/__tests__/config-fidelity-archived-symlinks.test.js.map +1 -0
  43. package/dist/__tests__/config-fidelity-display.test.d.ts +2 -0
  44. package/dist/__tests__/config-fidelity-display.test.d.ts.map +1 -0
  45. package/dist/__tests__/config-fidelity-display.test.js +77 -0
  46. package/dist/__tests__/config-fidelity-display.test.js.map +1 -0
  47. package/dist/__tests__/config-fidelity.test.js +166 -33
  48. package/dist/__tests__/config-fidelity.test.js.map +1 -1
  49. package/dist/__tests__/config-generation-gate.test.js +78 -0
  50. package/dist/__tests__/config-generation-gate.test.js.map +1 -1
  51. package/dist/__tests__/config-sync.test.js +35 -0
  52. package/dist/__tests__/config-sync.test.js.map +1 -1
  53. package/dist/__tests__/coordination-401-production-wiring.test.js +12 -7
  54. package/dist/__tests__/coordination-401-production-wiring.test.js.map +1 -1
  55. package/dist/__tests__/coordination-401-recovery.test.js +39 -32
  56. package/dist/__tests__/coordination-401-recovery.test.js.map +1 -1
  57. package/dist/__tests__/coordination-brief-pin.test.js +21 -8
  58. package/dist/__tests__/coordination-brief-pin.test.js.map +1 -1
  59. package/dist/__tests__/coordination-client.test.js +227 -3
  60. package/dist/__tests__/coordination-client.test.js.map +1 -1
  61. package/dist/__tests__/coordination-credential-endpoint.test.d.ts +24 -0
  62. package/dist/__tests__/coordination-credential-endpoint.test.d.ts.map +1 -0
  63. package/dist/__tests__/coordination-credential-endpoint.test.js +1230 -0
  64. package/dist/__tests__/coordination-credential-endpoint.test.js.map +1 -0
  65. package/dist/__tests__/coordination-memory.test.js +20 -4
  66. package/dist/__tests__/coordination-memory.test.js.map +1 -1
  67. package/dist/__tests__/coordination-provision.test.js +22 -14
  68. package/dist/__tests__/coordination-provision.test.js.map +1 -1
  69. package/dist/__tests__/coordination-status-registration.test.d.ts +16 -0
  70. package/dist/__tests__/coordination-status-registration.test.d.ts.map +1 -0
  71. package/dist/__tests__/coordination-status-registration.test.js +480 -0
  72. package/dist/__tests__/coordination-status-registration.test.js.map +1 -0
  73. package/dist/__tests__/coordination-token-multitenant.test.js +11 -11
  74. package/dist/__tests__/coordination-token-multitenant.test.js.map +1 -1
  75. package/dist/__tests__/coordination-token.test.js +35 -28
  76. package/dist/__tests__/coordination-token.test.js.map +1 -1
  77. package/dist/__tests__/creation-pr-class-check.test.d.ts +17 -0
  78. package/dist/__tests__/creation-pr-class-check.test.d.ts.map +1 -0
  79. package/dist/__tests__/creation-pr-class-check.test.js +346 -0
  80. package/dist/__tests__/creation-pr-class-check.test.js.map +1 -0
  81. package/dist/__tests__/digest-team-omission.test.d.ts +15 -0
  82. package/dist/__tests__/digest-team-omission.test.d.ts.map +1 -0
  83. package/dist/__tests__/digest-team-omission.test.js +247 -0
  84. package/dist/__tests__/digest-team-omission.test.js.map +1 -0
  85. package/dist/__tests__/doctor-worktree-path.test.d.ts +17 -0
  86. package/dist/__tests__/doctor-worktree-path.test.d.ts.map +1 -0
  87. package/dist/__tests__/doctor-worktree-path.test.js +158 -0
  88. package/dist/__tests__/doctor-worktree-path.test.js.map +1 -0
  89. package/dist/__tests__/fleet-data.test.js +40 -7
  90. package/dist/__tests__/fleet-data.test.js.map +1 -1
  91. package/dist/__tests__/fleet-tmux.test.js +2 -2
  92. package/dist/__tests__/fleet-tmux.test.js.map +1 -1
  93. package/dist/__tests__/generate-claude.test.js +137 -3
  94. package/dist/__tests__/generate-claude.test.js.map +1 -1
  95. package/dist/__tests__/git-env.test.d.ts +14 -0
  96. package/dist/__tests__/git-env.test.d.ts.map +1 -0
  97. package/dist/__tests__/git-env.test.js +131 -0
  98. package/dist/__tests__/git-env.test.js.map +1 -0
  99. package/dist/__tests__/git-identity-isolation.test.d.ts +33 -0
  100. package/dist/__tests__/git-identity-isolation.test.d.ts.map +1 -0
  101. package/dist/__tests__/git-identity-isolation.test.js +626 -0
  102. package/dist/__tests__/git-identity-isolation.test.js.map +1 -0
  103. package/dist/__tests__/hook-heal.test.js +17 -0
  104. package/dist/__tests__/hook-heal.test.js.map +1 -1
  105. package/dist/__tests__/init-coordination-url.test.d.ts +11 -0
  106. package/dist/__tests__/init-coordination-url.test.d.ts.map +1 -0
  107. package/dist/__tests__/init-coordination-url.test.js +114 -0
  108. package/dist/__tests__/init-coordination-url.test.js.map +1 -0
  109. package/dist/__tests__/memory-autocreate.test.js +574 -8
  110. package/dist/__tests__/memory-autocreate.test.js.map +1 -1
  111. package/dist/__tests__/memory-log-result.test.d.ts +13 -0
  112. package/dist/__tests__/memory-log-result.test.d.ts.map +1 -0
  113. package/dist/__tests__/memory-log-result.test.js +113 -0
  114. package/dist/__tests__/memory-log-result.test.js.map +1 -0
  115. package/dist/__tests__/memory-named-exists.test.d.ts +16 -0
  116. package/dist/__tests__/memory-named-exists.test.d.ts.map +1 -0
  117. package/dist/__tests__/memory-named-exists.test.js +288 -0
  118. package/dist/__tests__/memory-named-exists.test.js.map +1 -0
  119. package/dist/__tests__/mx-agent-cli-pin-validation.test.js +23 -47
  120. package/dist/__tests__/mx-agent-cli-pin-validation.test.js.map +1 -1
  121. package/dist/__tests__/mx-agent-cli-version-pin.test.js +34 -88
  122. package/dist/__tests__/mx-agent-cli-version-pin.test.js.map +1 -1
  123. package/dist/__tests__/new-project-first-team.test.d.ts +15 -0
  124. package/dist/__tests__/new-project-first-team.test.d.ts.map +1 -0
  125. package/dist/__tests__/new-project-first-team.test.js +263 -0
  126. package/dist/__tests__/new-project-first-team.test.js.map +1 -0
  127. package/dist/__tests__/otel-env.test.d.ts +2 -0
  128. package/dist/__tests__/otel-env.test.d.ts.map +1 -0
  129. package/dist/__tests__/otel-env.test.js +127 -0
  130. package/dist/__tests__/otel-env.test.js.map +1 -0
  131. package/dist/__tests__/project-config.test.js +283 -1
  132. package/dist/__tests__/project-config.test.js.map +1 -1
  133. package/dist/__tests__/provision-behavioral-contract.test.js +96 -4
  134. package/dist/__tests__/provision-behavioral-contract.test.js.map +1 -1
  135. package/dist/__tests__/provision-catalog-precondition.test.d.ts +26 -0
  136. package/dist/__tests__/provision-catalog-precondition.test.d.ts.map +1 -0
  137. package/dist/__tests__/provision-catalog-precondition.test.js +620 -0
  138. package/dist/__tests__/provision-catalog-precondition.test.js.map +1 -0
  139. package/dist/__tests__/provision-completion-rows.test.d.ts +17 -0
  140. package/dist/__tests__/provision-completion-rows.test.d.ts.map +1 -0
  141. package/dist/__tests__/provision-completion-rows.test.js +3095 -0
  142. package/dist/__tests__/provision-completion-rows.test.js.map +1 -0
  143. package/dist/__tests__/provision-identity-gate.test.d.ts +20 -0
  144. package/dist/__tests__/provision-identity-gate.test.d.ts.map +1 -0
  145. package/dist/__tests__/provision-identity-gate.test.js +600 -0
  146. package/dist/__tests__/provision-identity-gate.test.js.map +1 -0
  147. package/dist/__tests__/provision-resume.test.d.ts +26 -0
  148. package/dist/__tests__/provision-resume.test.d.ts.map +1 -0
  149. package/dist/__tests__/provision-resume.test.js +1164 -0
  150. package/dist/__tests__/provision-resume.test.js.map +1 -0
  151. package/dist/__tests__/provision-roleguide-anchors.test.d.ts +27 -0
  152. package/dist/__tests__/provision-roleguide-anchors.test.d.ts.map +1 -0
  153. package/dist/__tests__/provision-roleguide-anchors.test.js +747 -0
  154. package/dist/__tests__/provision-roleguide-anchors.test.js.map +1 -0
  155. package/dist/__tests__/provision-skeleton-fill.test.d.ts +16 -0
  156. package/dist/__tests__/provision-skeleton-fill.test.d.ts.map +1 -0
  157. package/dist/__tests__/provision-skeleton-fill.test.js +488 -0
  158. package/dist/__tests__/provision-skeleton-fill.test.js.map +1 -0
  159. package/dist/__tests__/provision-teambuilder-flow.test.js +93 -7
  160. package/dist/__tests__/provision-teambuilder-flow.test.js.map +1 -1
  161. package/dist/__tests__/repo-guard-wiring.test.d.ts +21 -0
  162. package/dist/__tests__/repo-guard-wiring.test.d.ts.map +1 -0
  163. package/dist/__tests__/repo-guard-wiring.test.js +638 -0
  164. package/dist/__tests__/repo-guard-wiring.test.js.map +1 -0
  165. package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts +2 -0
  166. package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts.map +1 -0
  167. package/dist/__tests__/runtime-codex-gateway-pilot.test.js +309 -0
  168. package/dist/__tests__/runtime-codex-gateway-pilot.test.js.map +1 -0
  169. package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts +2 -0
  170. package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts.map +1 -0
  171. package/dist/__tests__/runtime-codex-gateway-provider.test.js +163 -0
  172. package/dist/__tests__/runtime-codex-gateway-provider.test.js.map +1 -0
  173. package/dist/__tests__/runtime-identity.test.d.ts +2 -0
  174. package/dist/__tests__/runtime-identity.test.d.ts.map +1 -0
  175. package/dist/__tests__/runtime-identity.test.js +117 -0
  176. package/dist/__tests__/runtime-identity.test.js.map +1 -0
  177. package/dist/__tests__/session-pause-provisioning.test.js +6 -1
  178. package/dist/__tests__/session-pause-provisioning.test.js.map +1 -1
  179. package/dist/__tests__/session-record-disclosure.test.d.ts +24 -0
  180. package/dist/__tests__/session-record-disclosure.test.d.ts.map +1 -0
  181. package/dist/__tests__/session-record-disclosure.test.js +494 -0
  182. package/dist/__tests__/session-record-disclosure.test.js.map +1 -0
  183. package/dist/__tests__/session.test.js +35 -0
  184. package/dist/__tests__/session.test.js.map +1 -1
  185. package/dist/__tests__/slug-validation.test.js +27 -21
  186. package/dist/__tests__/slug-validation.test.js.map +1 -1
  187. package/dist/__tests__/standards-injection.test.js +23 -1
  188. package/dist/__tests__/standards-injection.test.js.map +1 -1
  189. package/dist/__tests__/start-interactive-role.test.d.ts +22 -0
  190. package/dist/__tests__/start-interactive-role.test.d.ts.map +1 -0
  191. package/dist/__tests__/start-interactive-role.test.js +204 -0
  192. package/dist/__tests__/start-interactive-role.test.js.map +1 -0
  193. package/dist/__tests__/start-team-identity.test.d.ts +25 -0
  194. package/dist/__tests__/start-team-identity.test.d.ts.map +1 -0
  195. package/dist/__tests__/start-team-identity.test.js +307 -0
  196. package/dist/__tests__/start-team-identity.test.js.map +1 -0
  197. package/dist/__tests__/team-memory-commands.test.js +142 -19
  198. package/dist/__tests__/team-memory-commands.test.js.map +1 -1
  199. package/dist/__tests__/template-sync.test.d.ts +19 -0
  200. package/dist/__tests__/template-sync.test.d.ts.map +1 -0
  201. package/dist/__tests__/template-sync.test.js +270 -0
  202. package/dist/__tests__/template-sync.test.js.map +1 -0
  203. package/dist/__tests__/test-project.test.d.ts +18 -0
  204. package/dist/__tests__/test-project.test.d.ts.map +1 -0
  205. package/dist/__tests__/test-project.test.js +465 -0
  206. package/dist/__tests__/test-project.test.js.map +1 -0
  207. package/dist/__tests__/usage-per-call-grouping.test.d.ts +25 -0
  208. package/dist/__tests__/usage-per-call-grouping.test.d.ts.map +1 -0
  209. package/dist/__tests__/usage-per-call-grouping.test.js +952 -0
  210. package/dist/__tests__/usage-per-call-grouping.test.js.map +1 -0
  211. package/dist/__tests__/verify-hooks-check-all.test.d.ts +32 -0
  212. package/dist/__tests__/verify-hooks-check-all.test.d.ts.map +1 -0
  213. package/dist/__tests__/verify-hooks-check-all.test.js +553 -0
  214. package/dist/__tests__/verify-hooks-check-all.test.js.map +1 -0
  215. package/dist/__tests__/worktree-sync-fixture.test.d.ts +17 -0
  216. package/dist/__tests__/worktree-sync-fixture.test.d.ts.map +1 -0
  217. package/dist/__tests__/worktree-sync-fixture.test.js +519 -0
  218. package/dist/__tests__/worktree-sync-fixture.test.js.map +1 -0
  219. package/dist/__tests__/worktree-sync-hardening.test.d.ts +13 -0
  220. package/dist/__tests__/worktree-sync-hardening.test.d.ts.map +1 -0
  221. package/dist/__tests__/worktree-sync-hardening.test.js +919 -0
  222. package/dist/__tests__/worktree-sync-hardening.test.js.map +1 -0
  223. package/dist/__tests__/worktree-sync-shell-free.test.d.ts +25 -0
  224. package/dist/__tests__/worktree-sync-shell-free.test.d.ts.map +1 -0
  225. package/dist/__tests__/worktree-sync-shell-free.test.js +185 -0
  226. package/dist/__tests__/worktree-sync-shell-free.test.js.map +1 -0
  227. package/dist/__tests__/worktree.test.js +75 -1
  228. package/dist/__tests__/worktree.test.js.map +1 -1
  229. package/dist/agent-config/.mx-config-generation.json +2 -2
  230. package/dist/agent-config/AGENTS.md.template +2 -2
  231. package/dist/agent-config/agents/bar-raiser.md +34 -1
  232. package/dist/agent-config/agents/red-team.md +34 -1
  233. package/dist/agent-config/agents/security-reviewer.md +22 -1
  234. package/dist/agent-config/claude-md/CLAUDE.core.md +6 -1
  235. package/dist/agent-config/claude-md/CLAUDE.overlay.memnexus.md +1 -3
  236. package/dist/agent-config/coordination-rosters.generated.json +10 -0
  237. package/dist/agent-config/hooks/HOOK-TIMEOUTS.md +27 -1
  238. package/dist/agent-config/hooks/OR-TRUE-AUDIT.md +8 -8
  239. package/dist/agent-config/hooks/auto-capture-precompact.sh +279 -0
  240. package/dist/agent-config/hooks/auto-capture-session-end.sh +277 -0
  241. package/dist/agent-config/hooks/coordination-brief.sh +290 -245
  242. package/dist/agent-config/hooks/deploy-verification-reminder.sh +359 -22
  243. package/dist/agent-config/hooks/git-mutation-guard.sh +85 -13
  244. package/dist/agent-config/hooks/session-idle-gate.sh +177 -12
  245. package/dist/agent-config/hooks/subagent-write-guard.sh +670 -0
  246. package/dist/agent-config/hooks/worktree-guard.sh +36 -7
  247. package/dist/agent-config/settings.json +15 -2
  248. package/dist/agent-config/shared/creation-pr-review-checklist.md +317 -0
  249. package/dist/commands/bootstrap.d.ts.map +1 -1
  250. package/dist/commands/bootstrap.js +22 -10
  251. package/dist/commands/bootstrap.js.map +1 -1
  252. package/dist/commands/config.d.ts.map +1 -1
  253. package/dist/commands/config.js +28 -1
  254. package/dist/commands/config.js.map +1 -1
  255. package/dist/commands/coordination.d.ts +150 -8
  256. package/dist/commands/coordination.d.ts.map +1 -1
  257. package/dist/commands/coordination.js +519 -25
  258. package/dist/commands/coordination.js.map +1 -1
  259. package/dist/commands/create.d.ts +913 -1
  260. package/dist/commands/create.d.ts.map +1 -1
  261. package/dist/commands/create.js +4879 -345
  262. package/dist/commands/create.js.map +1 -1
  263. package/dist/commands/digest.d.ts.map +1 -1
  264. package/dist/commands/digest.js +91 -7
  265. package/dist/commands/digest.js.map +1 -1
  266. package/dist/commands/fleet-tmux.js +1 -1
  267. package/dist/commands/fleet-tmux.js.map +1 -1
  268. package/dist/commands/init.d.ts +8 -0
  269. package/dist/commands/init.d.ts.map +1 -1
  270. package/dist/commands/init.js +26 -1
  271. package/dist/commands/init.js.map +1 -1
  272. package/dist/commands/list.d.ts +32 -1
  273. package/dist/commands/list.d.ts.map +1 -1
  274. package/dist/commands/list.js +98 -5
  275. package/dist/commands/list.js.map +1 -1
  276. package/dist/commands/new.d.ts +2 -0
  277. package/dist/commands/new.d.ts.map +1 -1
  278. package/dist/commands/new.js +114 -21
  279. package/dist/commands/new.js.map +1 -1
  280. package/dist/commands/session.js +1 -1
  281. package/dist/commands/session.js.map +1 -1
  282. package/dist/commands/start.d.ts +38 -0
  283. package/dist/commands/start.d.ts.map +1 -1
  284. package/dist/commands/start.js +171 -8
  285. package/dist/commands/start.js.map +1 -1
  286. package/dist/commands/sync.d.ts +57 -0
  287. package/dist/commands/sync.d.ts.map +1 -1
  288. package/dist/commands/sync.js +117 -3
  289. package/dist/commands/sync.js.map +1 -1
  290. package/dist/commands/usage.d.ts +64 -0
  291. package/dist/commands/usage.d.ts.map +1 -1
  292. package/dist/commands/usage.js +96 -3
  293. package/dist/commands/usage.js.map +1 -1
  294. package/dist/commands/verify-hooks.d.ts +37 -1
  295. package/dist/commands/verify-hooks.d.ts.map +1 -1
  296. package/dist/commands/verify-hooks.js +114 -2
  297. package/dist/commands/verify-hooks.js.map +1 -1
  298. package/dist/commands/window.d.ts +10 -0
  299. package/dist/commands/window.d.ts.map +1 -0
  300. package/dist/commands/window.js +265 -0
  301. package/dist/commands/window.js.map +1 -0
  302. package/dist/commands/worktree-sync.d.ts +54 -0
  303. package/dist/commands/worktree-sync.d.ts.map +1 -0
  304. package/dist/commands/worktree-sync.js +135 -0
  305. package/dist/commands/worktree-sync.js.map +1 -0
  306. package/dist/index.d.ts.map +1 -1
  307. package/dist/index.js +122 -11
  308. package/dist/index.js.map +1 -1
  309. package/dist/lib/agent-session.d.ts.map +1 -1
  310. package/dist/lib/agent-session.js +6 -1
  311. package/dist/lib/agent-session.js.map +1 -1
  312. package/dist/lib/catalog.d.ts +321 -2
  313. package/dist/lib/catalog.d.ts.map +1 -1
  314. package/dist/lib/catalog.js +490 -11
  315. package/dist/lib/catalog.js.map +1 -1
  316. package/dist/lib/claude.d.ts +53 -23
  317. package/dist/lib/claude.d.ts.map +1 -1
  318. package/dist/lib/claude.js +306 -17
  319. package/dist/lib/claude.js.map +1 -1
  320. package/dist/lib/cli-build.d.ts +172 -0
  321. package/dist/lib/cli-build.d.ts.map +1 -0
  322. package/dist/lib/cli-build.js +654 -0
  323. package/dist/lib/cli-build.js.map +1 -0
  324. package/dist/lib/code-context-file.d.ts +109 -0
  325. package/dist/lib/code-context-file.d.ts.map +1 -0
  326. package/dist/lib/code-context-file.js +219 -0
  327. package/dist/lib/code-context-file.js.map +1 -0
  328. package/dist/lib/code-context-file.test.d.ts +19 -0
  329. package/dist/lib/code-context-file.test.d.ts.map +1 -0
  330. package/dist/lib/code-context-file.test.js +202 -0
  331. package/dist/lib/code-context-file.test.js.map +1 -0
  332. package/dist/lib/config-fidelity.d.ts +40 -20
  333. package/dist/lib/config-fidelity.d.ts.map +1 -1
  334. package/dist/lib/config-fidelity.js +144 -56
  335. package/dist/lib/config-fidelity.js.map +1 -1
  336. package/dist/lib/coordination-client.d.ts +73 -0
  337. package/dist/lib/coordination-client.d.ts.map +1 -1
  338. package/dist/lib/coordination-client.js +180 -8
  339. package/dist/lib/coordination-client.js.map +1 -1
  340. package/dist/lib/coordination-token.d.ts +304 -6
  341. package/dist/lib/coordination-token.d.ts.map +1 -1
  342. package/dist/lib/coordination-token.js +851 -52
  343. package/dist/lib/coordination-token.js.map +1 -1
  344. package/dist/lib/fleet-data.d.ts +34 -0
  345. package/dist/lib/fleet-data.d.ts.map +1 -1
  346. package/dist/lib/fleet-data.js +37 -9
  347. package/dist/lib/fleet-data.js.map +1 -1
  348. package/dist/lib/fleet-render.js +1 -1
  349. package/dist/lib/fleet-render.js.map +1 -1
  350. package/dist/lib/git-identity.d.ts +302 -0
  351. package/dist/lib/git-identity.d.ts.map +1 -0
  352. package/dist/lib/git-identity.js +546 -0
  353. package/dist/lib/git-identity.js.map +1 -0
  354. package/dist/lib/hook-staleness.d.ts +95 -0
  355. package/dist/lib/hook-staleness.d.ts.map +1 -0
  356. package/dist/lib/hook-staleness.js +304 -0
  357. package/dist/lib/hook-staleness.js.map +1 -0
  358. package/dist/lib/jsonl.d.ts +270 -2
  359. package/dist/lib/jsonl.d.ts.map +1 -1
  360. package/dist/lib/jsonl.js +472 -76
  361. package/dist/lib/jsonl.js.map +1 -1
  362. package/dist/lib/memory.d.ts +350 -23
  363. package/dist/lib/memory.d.ts.map +1 -1
  364. package/dist/lib/memory.js +751 -38
  365. package/dist/lib/memory.js.map +1 -1
  366. package/dist/lib/otel-env.d.ts +90 -0
  367. package/dist/lib/otel-env.d.ts.map +1 -0
  368. package/dist/lib/otel-env.js +98 -0
  369. package/dist/lib/otel-env.js.map +1 -0
  370. package/dist/lib/project-config.d.ts +167 -0
  371. package/dist/lib/project-config.d.ts.map +1 -1
  372. package/dist/lib/project-config.js +321 -5
  373. package/dist/lib/project-config.js.map +1 -1
  374. package/dist/lib/projects-registry.d.ts +82 -0
  375. package/dist/lib/projects-registry.d.ts.map +1 -0
  376. package/dist/lib/projects-registry.js +145 -0
  377. package/dist/lib/projects-registry.js.map +1 -0
  378. package/dist/lib/projects-registry.test.d.ts +2 -0
  379. package/dist/lib/projects-registry.test.d.ts.map +1 -0
  380. package/dist/lib/projects-registry.test.js +176 -0
  381. package/dist/lib/projects-registry.test.js.map +1 -0
  382. package/dist/lib/repo-guard-scope.d.ts +126 -0
  383. package/dist/lib/repo-guard-scope.d.ts.map +1 -0
  384. package/dist/lib/repo-guard-scope.js +249 -0
  385. package/dist/lib/repo-guard-scope.js.map +1 -0
  386. package/dist/lib/roster.d.ts +87 -0
  387. package/dist/lib/roster.d.ts.map +1 -0
  388. package/dist/lib/roster.js +332 -0
  389. package/dist/lib/roster.js.map +1 -0
  390. package/dist/lib/roster.test.d.ts +15 -0
  391. package/dist/lib/roster.test.d.ts.map +1 -0
  392. package/dist/lib/roster.test.js +299 -0
  393. package/dist/lib/roster.test.js.map +1 -0
  394. package/dist/lib/runtime/codex-adapter.d.ts.map +1 -1
  395. package/dist/lib/runtime/codex-adapter.js +5 -0
  396. package/dist/lib/runtime/codex-adapter.js.map +1 -1
  397. package/dist/lib/runtime/codex-config.d.ts +129 -0
  398. package/dist/lib/runtime/codex-config.d.ts.map +1 -1
  399. package/dist/lib/runtime/codex-config.js +225 -0
  400. package/dist/lib/runtime/codex-config.js.map +1 -1
  401. package/dist/lib/runtime/identity.d.ts +72 -0
  402. package/dist/lib/runtime/identity.d.ts.map +1 -0
  403. package/dist/lib/runtime/identity.js +128 -0
  404. package/dist/lib/runtime/identity.js.map +1 -0
  405. package/dist/lib/standards.d.ts +10 -1
  406. package/dist/lib/standards.d.ts.map +1 -1
  407. package/dist/lib/standards.js +8 -1
  408. package/dist/lib/standards.js.map +1 -1
  409. package/dist/lib/team-identity.d.ts +134 -0
  410. package/dist/lib/team-identity.d.ts.map +1 -0
  411. package/dist/lib/team-identity.js +193 -0
  412. package/dist/lib/team-identity.js.map +1 -0
  413. package/dist/lib/templates.d.ts +29 -2
  414. package/dist/lib/templates.d.ts.map +1 -1
  415. package/dist/lib/templates.js +1042 -82
  416. package/dist/lib/templates.js.map +1 -1
  417. package/dist/lib/test-project.d.ts +95 -0
  418. package/dist/lib/test-project.d.ts.map +1 -0
  419. package/dist/lib/test-project.js +103 -0
  420. package/dist/lib/test-project.js.map +1 -0
  421. package/dist/lib/vault.d.ts +60 -0
  422. package/dist/lib/vault.d.ts.map +1 -0
  423. package/dist/lib/vault.js +102 -0
  424. package/dist/lib/vault.js.map +1 -0
  425. package/dist/lib/vault.test.d.ts +17 -0
  426. package/dist/lib/vault.test.d.ts.map +1 -0
  427. package/dist/lib/vault.test.js +169 -0
  428. package/dist/lib/vault.test.js.map +1 -0
  429. package/dist/lib/window-view.d.ts +63 -0
  430. package/dist/lib/window-view.d.ts.map +1 -0
  431. package/dist/lib/window-view.js +217 -0
  432. package/dist/lib/window-view.js.map +1 -0
  433. package/dist/lib/window-view.test.d.ts +2 -0
  434. package/dist/lib/window-view.test.d.ts.map +1 -0
  435. package/dist/lib/window-view.test.js +168 -0
  436. package/dist/lib/window-view.test.js.map +1 -0
  437. package/dist/lib/worktree-sync.d.ts +439 -0
  438. package/dist/lib/worktree-sync.d.ts.map +1 -0
  439. package/dist/lib/worktree-sync.js +1167 -0
  440. package/dist/lib/worktree-sync.js.map +1 -0
  441. package/dist/lib/worktree.d.ts +58 -1
  442. package/dist/lib/worktree.d.ts.map +1 -1
  443. package/dist/lib/worktree.js +91 -4
  444. package/dist/lib/worktree.js.map +1 -1
  445. package/dist/standards/decision-request.md +8 -0
  446. package/dist/standards/po-communication-standard.md +126 -0
  447. package/dist/standards/report-format.md +8 -0
  448. package/dist/standards/writing-standard.md +146 -4
  449. package/package.json +1 -1
  450. package/scripts/generate-claude.mjs +119 -46
@@ -417,6 +417,282 @@ mx_verbatim_guard() {
417
417
  return 0
418
418
  }
419
419
 
420
+ # ── 5b. Resolve project scope (codeContext) ──────────────────────────────
421
+ #
422
+ # BACKPORT. The block below is the "Resolve project scope" block of
423
+ # @memnexus-ai/cli@1.7.235, hooks/capture-session-end.sh lines 240 to 493, copied byte
424
+ # for byte apart from the three points this note names. Product owner ruling,
425
+ # 2026-08-22 (AskUserQuestion): "Approve both halves in v5" (plan #67, fixes #62).
426
+ #
427
+ # WHERE THIS FORK DIFFERS FROM UPSTREAM:
428
+ # 1. Section number. Upstream numbers the block 6b. This file's guard is
429
+ # section 5 and its save is section 6, so the block is 5b here. Its
430
+ # position is the same: after the content is built, before the create call.
431
+ # 2. The trap paragraph below names section 3, which is where THIS file arms
432
+ # `trap 'rm -rf "$tmpdir"; _mxht_emit || :; exit 0' EXIT ERR`.
433
+ # Upstream names its own section 5.
434
+ # 3. The create call keeps this fork's `timeout "${AUTO_CAPTURE_TIMEOUT_SECS:-20}"` and
435
+ # `|| true`, not upstream's TIMEOUT_CMD and CREATE_STATUS reporting. The one
436
+ # addition is the --code-context argument.
437
+ #
438
+ # auto-checkpoint.sh gets none of this. It writes a NAMED memory, and scope must
439
+ # not reach that path until memnexus#5470 is resolved (#62).
440
+ #
441
+ # ── upstream block, verbatim from here ──
442
+ # Auto-captured memories carried no scope at all, so they leaked into every
443
+ # team's scoped searches and polluted build_context (#5158, #4957). PR #3281
444
+ # fixed that for the commit path only; this is the same resolution for the
445
+ # capture hooks, using the same sources and the same precedence.
446
+ #
447
+ # Mirrors resolveCommitCodeContext() in cli/src/lib/commit-context/code-context.ts:
448
+ # 1. MX_CODE_CONTEXT env var — operator-controlled, higher trust. It wins over
449
+ # the file (CWE-345): a checked-in file from an untrusted clone must not
450
+ # override the scope the operator set explicitly.
451
+ # 2. <projectRoot>/.mx-code-context.json — repo-controlled, lower trust.
452
+ # 3. Neither present or neither usable -> NO scope. The memory is created
453
+ # unlabeled, exactly as it was before this block existed. No default is
454
+ # invented: a guessed label is invisible to the scope that should see it
455
+ # and visible to one that should not, which is worse than no label.
456
+ #
457
+ # Every command in this block must end up returning 0. The EXIT/ERR trap set in
458
+ # section 3 exits the hook, so a non-zero status here would abandon the capture
459
+ # over a missing config file — a far worse regression than the unlabeled
460
+ # memories this fixes. The absent-config path is the common one today.
461
+ CODE_CONTEXT_MAX_BYTES=65536
462
+
463
+ # Walk up for the git project root, mirroring findProjectRoot() in
464
+ # cli/src/lib/commit-context/local-cache.ts. `-e`, not `-d`: inside a git
465
+ # worktree `.git` is a FILE, and the worktree root — not the main repo — is the
466
+ # project root (the TS uses fs.existsSync, which makes no such distinction).
467
+ find_project_root() { # <start-dir> -> project root on stdout, or nothing
468
+ local dir
469
+ dir=$(cd "$1" 2>/dev/null && pwd -P) || return 0
470
+ while [[ -n "$dir" && "$dir" != "/" ]]; do
471
+ if [[ -e "$dir/.git" ]]; then
472
+ printf '%s' "$dir"
473
+ return 0
474
+ fi
475
+ dir=$(dirname "$dir" 2>/dev/null) || return 0
476
+ done
477
+ return 0
478
+ }
479
+
480
+ # Keep only the six known keys whose values are non-empty strings, cap each,
481
+ # and emit NOTHING when nothing usable remains — so an empty or scope-free
482
+ # object is never passed as if it were a label. Malformed JSON makes jq exit
483
+ # non-zero with no output, which lands in the same "no scope" branch.
484
+ #
485
+ # `-s` (slurp) is load-bearing, not a style choice. jq accepts a STREAM of JSON
486
+ # documents: without `-s` the filter runs once per document and `jq -c` prints
487
+ # one line each, so a config holding two concatenated or newline-separated
488
+ # objects produced a MULTI-LINE string that was passed verbatim as one
489
+ # --code-context argument. parseCodeContextFlag() (cli/src/commands/memories.ts)
490
+ # JSON.parse()s it and process.exit(1)s before any network call — the capture is
491
+ # lost silently, triggered by cloning a repo. The `!= "{}"` guard below did not
492
+ # catch it either: `{"zzz":1}{"team":"b"}` normalizes to the two lines
493
+ # `{}` + `{"team":"b"}`, and that whole string is not `{}`. Slurping into an
494
+ # array and taking the first element means exactly one line can ever be emitted.
495
+ #
496
+ # The cap is 100 CODEPOINTS, deliberately below the server's 200. The server's
497
+ # CodeContextSchema uses Zod `.max(200)`, which counts UTF-16 code units, while
498
+ # jq's `[0:N]` slices by codepoint. Every astral-plane character (emoji, CJK
499
+ # extensions, mathematical alphanumerics) is 1 codepoint but 2 UTF-16 units, so
500
+ # a `[0:200]` cap emitted values of up to 400 units — over the server maximum,
501
+ # a 400 from the API, and the same silent capture loss. Since no codepoint
502
+ # exceeds 2 UTF-16 units, 100 codepoints can never exceed 200 units. Scope
503
+ # labels are short names (product/team/service); the extra truncation is
504
+ # unreachable in practice, and truncating is recoverable where a rejected
505
+ # request is not.
506
+ normalize_code_context() { # JSON on stdin -> normalized JSON object, or nothing
507
+ local out
508
+ out=$(jq -s -c '
509
+ (.[0] // {}) as $raw
510
+ | if ($raw | type) == "object" then
511
+ reduce ("product","repo","service","component","team","role") as $k ({};
512
+ if ($raw[$k] | type) == "string" and ($raw[$k] | length) > 0
513
+ then .[$k] = ($raw[$k][0:100])
514
+ else . end)
515
+ else {} end
516
+ ' 2>/dev/null) || return 0
517
+ # The newline test is belt-and-braces: `-s` already guarantees one document,
518
+ # and jq -c escapes newlines inside string values. Nothing multi-line may ever
519
+ # reach --code-context again, whatever the filter above does.
520
+ if [[ -n "$out" && "$out" != "{}" && "$out" != "null" && "$out" != *$'\n'* ]]; then
521
+ printf '%s' "$out"
522
+ fi
523
+ return 0
524
+ }
525
+
526
+ CODE_CONTEXT_JSON=""
527
+
528
+ # 1. Env var. Tested for presence only — the value is never echoed or logged.
529
+ if [[ -n "${MX_CODE_CONTEXT:-}" ]]; then
530
+ CODE_CONTEXT_JSON=$(printf '%s' "$MX_CODE_CONTEXT" | normalize_code_context) || CODE_CONTEXT_JSON=""
531
+ fi
532
+
533
+ # 2. Repo file — consulted only when the env var yielded nothing usable.
534
+ if [[ -z "$CODE_CONTEXT_JSON" ]]; then
535
+ # ORDER IS LOAD-BEARING: harness-provided project dir, then the worktree path,
536
+ # then the cwd. Each source is TRIED IN TURN, and the transcript's directory
537
+ # is not a source at all. Both properties are corrections to earlier forms and
538
+ # both are pinned by the suite; read this before rewriting the expression.
539
+ #
540
+ # WHY EACH SOURCE IS TRIED SEPARATELY. The earlier form collapsed all three
541
+ # into ONE call: `find_project_root "${CLAUDE_PROJECT_DIR:-${CLAUDE_WORKTREE_PATH:-$(pwd)}}"`.
542
+ # `:-` substitutes only when a variable is UNSET or EMPTY — never when it is
543
+ # set to something useless. So a CLAUDE_PROJECT_DIR that is set but resolves
544
+ # to no repository (a stale path, a deleted directory, a path outside any
545
+ # checkout) consumed the single attempt and the cwd was NEVER consulted.
546
+ # Measured: CLAUDE_PROJECT_DIR=/proc and =/nonexistent/zz each produced
547
+ # {"product":"home","team":"DOTFILES-WRONG-SCOPE"} from the $HOME config.
548
+ # The loop below consults the next source instead, which `:-` cannot express.
549
+ #
550
+ # WHAT IS ACTUALLY KNOWN ABOUT CLAUDE_PROJECT_DIR IN THE CUSTOMER CONTEXT.
551
+ # It is the documented hook variable, and it is the right first source when it
552
+ # is present. This repo does NOT evidence that it is set for hooks installed
553
+ # by `mx mcp install`: every other reference to it is fleet code, and it was
554
+ # measured UNSET in a live Claude Code tool process (a tool process is not a
555
+ # hook process, so that is not disproof — but it is not confirmation either).
556
+ # The expression below is therefore designed to be CORRECT WHEN IT IS ABSENT:
557
+ # an unset or empty value is skipped by the loop and the cwd carries the case.
558
+ # Do not restructure this so that a present CLAUDE_PROJECT_DIR is required.
559
+ # WHY THE TRANSCRIPT DIRECTORY IS NOT A SOURCE. It has no legitimate resolving
560
+ # power, and the reason is DEPTH-INDEPENDENT — do not restate it as a claim
561
+ # about the transcript's nesting. An earlier version of this comment argued
562
+ # from a flat ~/.claude/projects/<slug>/<id>.jsonl layout and enumerated the
563
+ # three directories a walk could reach. That premise is false here. Measured
564
+ # on this machine: transcripts sit at BOTH depth 2 and depth 4 under
565
+ # ~/.claude/projects — 310 at depth 2, 5621 deeper — so any argument of the
566
+ # form "the walk can only ever reach these three named directories" does not
567
+ # hold. The premise that does hold, and that does not depend on depth:
568
+ #
569
+ # .git anywhere under ~/.claude, any depth: 0 (also no .hg, no .svn)
570
+ #
571
+ # An upward walk from any transcript directory traverses only directories
572
+ # inside ~/.claude, none of which carries a repository marker, so it cannot
573
+ # terminate inside that subtree at any depth. That leaves $HOME as its ONLY
574
+ # reachable non-empty outcome, which is precisely the defect this block exists
575
+ # to prevent: keeping dotfiles in git is common, so $HOME/.git exists on many
576
+ # machines, and with $HOME/.mx-code-context.json present every capture from
577
+ # every worktree on the machine was labelled from the home config. A
578
+ # confidently wrong label is worse than no label — invisible to the scope that
579
+ # should see it, visible to one that must not. Do not reintroduce it.
580
+ #
581
+ # CAVEAT, stated because this is a claim about a directory OUTSIDE this
582
+ # repository: it could stop being true, and nothing in this codebase would
583
+ # notice if a repository ever appeared under ~/.claude. Removing the leg does
584
+ # not depend on the caveat holding — the leg is simply gone — but any future
585
+ # argument to reinstate it must re-measure rather than cite this line.
586
+ #
587
+ # WHY $HOME IS REFUSED OUTRIGHT, AND WHY BOTH SIDES ARE CANONICALIZED. Belt
588
+ # and braces for the residual where the cwd itself is $HOME or a directory
589
+ # beneath it whose nearest .git is $HOME's. It also closes a consequence that
590
+ # is easy to miss: CC_ROOT is the basis of the symlink containment test below,
591
+ # so a CC_ROOT of $HOME silently widens "contained in the project" to
592
+ # "anywhere in the home directory", and $HOME/.mx-code-context.json symlinked
593
+ # to any other file under $HOME would resolve and be used. The cost is not
594
+ # supporting a user whose real project IS their home directory; that is the
595
+ # same confusion we want rejected.
596
+ #
597
+ # The comparison MUST canonicalize $HOME. CC_ROOT always arrives canonical —
598
+ # find_project_root builds it with `cd … && pwd -P` — while $HOME arrives
599
+ # verbatim from the environment, so a literal `==` against "$HOME" misses on
600
+ # every spelling that is not byte-identical. Four spellings were measured
601
+ # leaking the home label through a symlinked $HOME/.mx-code-context.json: a
602
+ # trailing slash ("/home/x/"), a "/." suffix ("/home/x/."), $HOME set to a
603
+ # SYMLINK to the real home, and a cwd reached through that same symlink.
604
+ # Symlinked home directories are routine — macOS firmlinks, NFS corporate
605
+ # homes, container images mapping /home/user onto another volume — so the
606
+ # trigger is a normal configuration and the miss is silent: the refusal does
607
+ # not fire, and the containment widening above returns with it. `cd … && pwd -P`
608
+ # is the same primitive find_project_root uses and handles all four in one step.
609
+ #
610
+ # HOME unset, or pointing at nothing, leaves _home_real empty and no refusal
611
+ # fires. That is unchanged from the previous `-n "${HOME:-}"` guard, not a
612
+ # regression. The `|| _home_real=""` is REQUIRED, not decorative: without it a
613
+ # failing `cd` leaves the assignment non-zero and last on its path, which fires
614
+ # the ERR trap and abandons the capture.
615
+ #
616
+ # ERR-TRAP SAFETY — verified, not assumed, because a regression here fires
617
+ # `trap 'exit 0' ERR` and silently abandons the capture. The loop body's only
618
+ # status-bearing statement is a `$(...)` assignment of find_project_root, which
619
+ # returns 0 on every path including the `cd` failure. The break is written as
620
+ # an `if` block for the same reason the $HOME refusal is. The earlier one-line
621
+ # form `[[ -n "$CC_ROOT" ]] && break` returns 1 whenever the loop CONTINUES —
622
+ # an earlier version of this comment claimed it returned 0, which was wrong. It
623
+ # was safe only POSITIONALLY: as a non-final command of an `&&` list it is
624
+ # exempt under the errexit rules, so nothing fired. That safety depends on
625
+ # where the statement sits and would evaporate the moment this loop became the
626
+ # last statement of a function: the function would return 1 and any `$(...)`
627
+ # call of it would fire the trap. The `if` form returns 0 and removes the
628
+ # positional dependence.
629
+ #
630
+ # The same reasoning is why the $HOME refusal is an `if` block ON PURPOSE: the
631
+ # one-line `[[ "$CC_ROOT" == "$_home_real" ]] && CC_ROOT=""` returns 1 when the
632
+ # test is false, and was measured firing the ERR trap when it landed last in an
633
+ # enclosing block. `pwd 2>/dev/null` keeps a deleted cwd from printing "error
634
+ # retrieving current directory" onto the hook's real stderr. This safety comes
635
+ # from find_project_root always returning 0, not from this hook omitting
636
+ # `set -E`, so it survives someone adding `set -E` later. Do not introduce a
637
+ # bare command on this path.
638
+ CC_ROOT=""
639
+ for _cand in "${CLAUDE_PROJECT_DIR:-}" "${CLAUDE_WORKTREE_PATH:-}" "$(pwd 2>/dev/null)"; do
640
+ [[ -n "$_cand" ]] || continue
641
+ CC_ROOT=$(find_project_root "$_cand")
642
+ if [[ -n "$CC_ROOT" ]]; then break; fi
643
+ done
644
+ _home_real=$(cd "${HOME:-/nonexistent}" 2>/dev/null && pwd -P) || _home_real=""
645
+ if [[ -n "$_home_real" && "$CC_ROOT" == "$_home_real" ]]; then
646
+ CC_ROOT=""
647
+ fi
648
+ CC_FILE="${CC_ROOT}/.mx-code-context.json"
649
+ if [[ -n "$CC_ROOT" ]]; then
650
+ # CWE-59. `-f`, `-r` and the read all follow symlinks, so a repo could check
651
+ # in `.mx-code-context.json` as a symlink to any file on the user's machine
652
+ # and the six allowlisted keys of it would be uploaded to the user's own
653
+ # MemNexus account. Resolve the path and require the result to stay inside
654
+ # the project root — the containment this same hook already applies to the
655
+ # transcript path in section 2. Read through the RESOLVED path, so the link
656
+ # is not traversed a second time.
657
+ CC_REAL=$(realpath "$CC_FILE" 2>/dev/null || printf '')
658
+ if [[ -n "$CC_REAL" && "$CC_REAL" == "$CC_ROOT"/* && -f "$CC_REAL" && -r "$CC_REAL" ]]; then
659
+ # One open, bounded at the source (same 64KB bound as the TS resolver).
660
+ # The previous form size-checked with `wc -c` and then re-opened for jq:
661
+ # two opens on a path an untrusted repo controls, so a concurrent writer
662
+ # could present a small file to `wc` and a huge one to `jq` (TOCTOU) on a
663
+ # hot per-turn path. `head -c` bounds the read itself, which changes >64KB
664
+ # from "skipped" to "truncated, then rejected as invalid JSON" — the same
665
+ # observable outcome, no scope.
666
+ #
667
+ # `2>/dev/null` precedes the input redirect ON PURPOSE. Redirections apply
668
+ # left to right, so with `<"$CC_REAL" 2>/dev/null` a file that turned
669
+ # unreadable between the `-r` test and the open makes bash print the full
670
+ # path and "Permission denied" to the hook's REAL stderr, before the
671
+ # discard takes effect. Verified: reversing these two words reintroduces
672
+ # that leak. Do not reorder.
673
+ #
674
+ # The bytes are PIPED into jq, never routed through a variable. Bash
675
+ # strips NUL bytes out of command-substitution output and warns while
676
+ # doing it — from the parent shell reading the substitution, so the
677
+ # `2>/dev/null` above does not suppress that warning. Via a variable,
678
+ # `{"team":"a<NUL>b"}` printed a warning naming this script and line to
679
+ # the hook's real stderr, and then RESOLVED to team "ab": input the file
680
+ # does not contain, silently repaired before validation instead of
681
+ # rejected by it. Piping keeps the NUL inside jq, which rejects the
682
+ # document as malformed. Do not reintroduce an intermediate variable.
683
+ CODE_CONTEXT_JSON=$(head -c "$CODE_CONTEXT_MAX_BYTES" 2>/dev/null <"$CC_REAL" | normalize_code_context) || CODE_CONTEXT_JSON=""
684
+ fi
685
+ fi
686
+ fi
687
+
688
+ # Nothing resolved -> pass nothing at all, so the create command line is
689
+ # byte-identical to the pre-scope version. The `[@]+` guard keeps an empty array
690
+ # safe to expand under `set -u` on bash < 4.4.
691
+ CODE_CONTEXT_ARGS=()
692
+ if [[ -n "$CODE_CONTEXT_JSON" ]]; then
693
+ CODE_CONTEXT_ARGS=(--code-context "$CODE_CONTEXT_JSON")
694
+ fi
695
+
420
696
  # ── 6. Save memory ──────────────────────────────────────────────────────
421
697
  if mx_verbatim_guard "$TRANSCRIPT_PATH" "$CONTENT"; then
422
698
  # Bounded: network write. On timeout we land on the existing `|| true` path —
@@ -425,6 +701,7 @@ if mx_verbatim_guard "$TRANSCRIPT_PATH" "$CONTENT"; then
425
701
  --conversation-id "NEW" \
426
702
  --content "$CONTENT" \
427
703
  --topics "auto-captured,session-summary" \
704
+ "${CODE_CONTEXT_ARGS[@]+"${CODE_CONTEXT_ARGS[@]}"}" \
428
705
  >/dev/null 2>&1 || true
429
706
  fi
430
707