@memnexus-ai/mx-agent-cli 0.1.294 → 0.1.296-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 (649) 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__/claude-local-sanitizer.test.d.ts +24 -0
  26. package/dist/__tests__/claude-local-sanitizer.test.d.ts.map +1 -0
  27. package/dist/__tests__/claude-local-sanitizer.test.js +906 -0
  28. package/dist/__tests__/claude-local-sanitizer.test.js.map +1 -0
  29. package/dist/__tests__/cli-build-integration.test.d.ts +2 -0
  30. package/dist/__tests__/cli-build-integration.test.d.ts.map +1 -0
  31. package/dist/__tests__/cli-build-integration.test.js +64 -0
  32. package/dist/__tests__/cli-build-integration.test.js.map +1 -0
  33. package/dist/__tests__/cli-build.test.d.ts +2 -0
  34. package/dist/__tests__/cli-build.test.d.ts.map +1 -0
  35. package/dist/__tests__/cli-build.test.js +640 -0
  36. package/dist/__tests__/cli-build.test.js.map +1 -0
  37. package/dist/__tests__/codex-deploy-config.test.js +60 -0
  38. package/dist/__tests__/codex-deploy-config.test.js.map +1 -1
  39. package/dist/__tests__/completion-rows-discriminate.test.d.ts +20 -0
  40. package/dist/__tests__/completion-rows-discriminate.test.d.ts.map +1 -0
  41. package/dist/__tests__/completion-rows-discriminate.test.js +481 -0
  42. package/dist/__tests__/completion-rows-discriminate.test.js.map +1 -0
  43. package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts +2 -0
  44. package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts.map +1 -0
  45. package/dist/__tests__/config-fidelity-archived-symlinks.test.js +127 -0
  46. package/dist/__tests__/config-fidelity-archived-symlinks.test.js.map +1 -0
  47. package/dist/__tests__/config-fidelity-display.test.d.ts +2 -0
  48. package/dist/__tests__/config-fidelity-display.test.d.ts.map +1 -0
  49. package/dist/__tests__/config-fidelity-display.test.js +77 -0
  50. package/dist/__tests__/config-fidelity-display.test.js.map +1 -0
  51. package/dist/__tests__/config-fidelity.test.js +166 -33
  52. package/dist/__tests__/config-fidelity.test.js.map +1 -1
  53. package/dist/__tests__/config-generation-gate.test.js +78 -0
  54. package/dist/__tests__/config-generation-gate.test.js.map +1 -1
  55. package/dist/__tests__/config-sync.test.js +89 -1
  56. package/dist/__tests__/config-sync.test.js.map +1 -1
  57. package/dist/__tests__/coordination-401-production-wiring.test.js +12 -7
  58. package/dist/__tests__/coordination-401-production-wiring.test.js.map +1 -1
  59. package/dist/__tests__/coordination-401-recovery.test.js +39 -32
  60. package/dist/__tests__/coordination-401-recovery.test.js.map +1 -1
  61. package/dist/__tests__/coordination-brief-pin.test.js +21 -8
  62. package/dist/__tests__/coordination-brief-pin.test.js.map +1 -1
  63. package/dist/__tests__/coordination-client.test.js +316 -3
  64. package/dist/__tests__/coordination-client.test.js.map +1 -1
  65. package/dist/__tests__/coordination-credential-endpoint.test.d.ts +24 -0
  66. package/dist/__tests__/coordination-credential-endpoint.test.d.ts.map +1 -0
  67. package/dist/__tests__/coordination-credential-endpoint.test.js +1290 -0
  68. package/dist/__tests__/coordination-credential-endpoint.test.js.map +1 -0
  69. package/dist/__tests__/coordination-memory.test.js +20 -4
  70. package/dist/__tests__/coordination-memory.test.js.map +1 -1
  71. package/dist/__tests__/coordination-provision.test.js +22 -14
  72. package/dist/__tests__/coordination-provision.test.js.map +1 -1
  73. package/dist/__tests__/coordination-status-registration.test.d.ts +16 -0
  74. package/dist/__tests__/coordination-status-registration.test.d.ts.map +1 -0
  75. package/dist/__tests__/coordination-status-registration.test.js +480 -0
  76. package/dist/__tests__/coordination-status-registration.test.js.map +1 -0
  77. package/dist/__tests__/coordination-token-multitenant.test.js +24 -24
  78. package/dist/__tests__/coordination-token-multitenant.test.js.map +1 -1
  79. package/dist/__tests__/coordination-token.test.js +35 -28
  80. package/dist/__tests__/coordination-token.test.js.map +1 -1
  81. package/dist/__tests__/creation-pr-class-check.test.d.ts +17 -0
  82. package/dist/__tests__/creation-pr-class-check.test.d.ts.map +1 -0
  83. package/dist/__tests__/creation-pr-class-check.test.js +346 -0
  84. package/dist/__tests__/creation-pr-class-check.test.js.map +1 -0
  85. package/dist/__tests__/decision-check.test.d.ts +2 -0
  86. package/dist/__tests__/decision-check.test.d.ts.map +1 -0
  87. package/dist/__tests__/decision-check.test.js +105 -0
  88. package/dist/__tests__/decision-check.test.js.map +1 -0
  89. package/dist/__tests__/digest-team-omission.test.d.ts +15 -0
  90. package/dist/__tests__/digest-team-omission.test.d.ts.map +1 -0
  91. package/dist/__tests__/digest-team-omission.test.js +247 -0
  92. package/dist/__tests__/digest-team-omission.test.js.map +1 -0
  93. package/dist/__tests__/doctor-worktree-path.test.d.ts +17 -0
  94. package/dist/__tests__/doctor-worktree-path.test.d.ts.map +1 -0
  95. package/dist/__tests__/doctor-worktree-path.test.js +158 -0
  96. package/dist/__tests__/doctor-worktree-path.test.js.map +1 -0
  97. package/dist/__tests__/fleet-data.test.js +40 -7
  98. package/dist/__tests__/fleet-data.test.js.map +1 -1
  99. package/dist/__tests__/fleet-tmux.test.js +2 -2
  100. package/dist/__tests__/fleet-tmux.test.js.map +1 -1
  101. package/dist/__tests__/generate-claude.test.js +137 -3
  102. package/dist/__tests__/generate-claude.test.js.map +1 -1
  103. package/dist/__tests__/git-env.test.d.ts +14 -0
  104. package/dist/__tests__/git-env.test.d.ts.map +1 -0
  105. package/dist/__tests__/git-env.test.js +131 -0
  106. package/dist/__tests__/git-env.test.js.map +1 -0
  107. package/dist/__tests__/git-identity-isolation.test.d.ts +33 -0
  108. package/dist/__tests__/git-identity-isolation.test.d.ts.map +1 -0
  109. package/dist/__tests__/git-identity-isolation.test.js +626 -0
  110. package/dist/__tests__/git-identity-isolation.test.js.map +1 -0
  111. package/dist/__tests__/harness-extract.test.d.ts +19 -0
  112. package/dist/__tests__/harness-extract.test.d.ts.map +1 -0
  113. package/dist/__tests__/harness-extract.test.js +566 -0
  114. package/dist/__tests__/harness-extract.test.js.map +1 -0
  115. package/dist/__tests__/harness-wiring.test.d.ts +16 -0
  116. package/dist/__tests__/harness-wiring.test.d.ts.map +1 -0
  117. package/dist/__tests__/harness-wiring.test.js +469 -0
  118. package/dist/__tests__/harness-wiring.test.js.map +1 -0
  119. package/dist/__tests__/hook-heal.test.js +17 -0
  120. package/dist/__tests__/hook-heal.test.js.map +1 -1
  121. package/dist/__tests__/init-coordination-url.test.d.ts +11 -0
  122. package/dist/__tests__/init-coordination-url.test.d.ts.map +1 -0
  123. package/dist/__tests__/init-coordination-url.test.js +114 -0
  124. package/dist/__tests__/init-coordination-url.test.js.map +1 -0
  125. package/dist/__tests__/memory-autocreate.test.js +574 -8
  126. package/dist/__tests__/memory-autocreate.test.js.map +1 -1
  127. package/dist/__tests__/memory-log-result.test.d.ts +13 -0
  128. package/dist/__tests__/memory-log-result.test.d.ts.map +1 -0
  129. package/dist/__tests__/memory-log-result.test.js +113 -0
  130. package/dist/__tests__/memory-log-result.test.js.map +1 -0
  131. package/dist/__tests__/memory-named-exists.test.d.ts +16 -0
  132. package/dist/__tests__/memory-named-exists.test.d.ts.map +1 -0
  133. package/dist/__tests__/memory-named-exists.test.js +288 -0
  134. package/dist/__tests__/memory-named-exists.test.js.map +1 -0
  135. package/dist/__tests__/mx-agent-cli-pin-validation.test.js +23 -47
  136. package/dist/__tests__/mx-agent-cli-pin-validation.test.js.map +1 -1
  137. package/dist/__tests__/mx-agent-cli-version-pin.test.js +34 -88
  138. package/dist/__tests__/mx-agent-cli-version-pin.test.js.map +1 -1
  139. package/dist/__tests__/new-project-first-team.test.d.ts +15 -0
  140. package/dist/__tests__/new-project-first-team.test.d.ts.map +1 -0
  141. package/dist/__tests__/new-project-first-team.test.js +263 -0
  142. package/dist/__tests__/new-project-first-team.test.js.map +1 -0
  143. package/dist/__tests__/otel-env.test.d.ts +2 -0
  144. package/dist/__tests__/otel-env.test.d.ts.map +1 -0
  145. package/dist/__tests__/otel-env.test.js +127 -0
  146. package/dist/__tests__/otel-env.test.js.map +1 -0
  147. package/dist/__tests__/project-config.test.js +283 -1
  148. package/dist/__tests__/project-config.test.js.map +1 -1
  149. package/dist/__tests__/provision-behavioral-contract.test.js +96 -4
  150. package/dist/__tests__/provision-behavioral-contract.test.js.map +1 -1
  151. package/dist/__tests__/provision-catalog-precondition.test.d.ts +26 -0
  152. package/dist/__tests__/provision-catalog-precondition.test.d.ts.map +1 -0
  153. package/dist/__tests__/provision-catalog-precondition.test.js +620 -0
  154. package/dist/__tests__/provision-catalog-precondition.test.js.map +1 -0
  155. package/dist/__tests__/provision-completion-rows.test.d.ts +17 -0
  156. package/dist/__tests__/provision-completion-rows.test.d.ts.map +1 -0
  157. package/dist/__tests__/provision-completion-rows.test.js +3187 -0
  158. package/dist/__tests__/provision-completion-rows.test.js.map +1 -0
  159. package/dist/__tests__/provision-identity-gate.test.d.ts +20 -0
  160. package/dist/__tests__/provision-identity-gate.test.d.ts.map +1 -0
  161. package/dist/__tests__/provision-identity-gate.test.js +600 -0
  162. package/dist/__tests__/provision-identity-gate.test.js.map +1 -0
  163. package/dist/__tests__/provision-resume.test.d.ts +26 -0
  164. package/dist/__tests__/provision-resume.test.d.ts.map +1 -0
  165. package/dist/__tests__/provision-resume.test.js +1164 -0
  166. package/dist/__tests__/provision-resume.test.js.map +1 -0
  167. package/dist/__tests__/provision-roleguide-anchors.test.d.ts +27 -0
  168. package/dist/__tests__/provision-roleguide-anchors.test.d.ts.map +1 -0
  169. package/dist/__tests__/provision-roleguide-anchors.test.js +747 -0
  170. package/dist/__tests__/provision-roleguide-anchors.test.js.map +1 -0
  171. package/dist/__tests__/provision-skeleton-fill.test.d.ts +16 -0
  172. package/dist/__tests__/provision-skeleton-fill.test.d.ts.map +1 -0
  173. package/dist/__tests__/provision-skeleton-fill.test.js +488 -0
  174. package/dist/__tests__/provision-skeleton-fill.test.js.map +1 -0
  175. package/dist/__tests__/provision-teambuilder-flow.test.js +93 -7
  176. package/dist/__tests__/provision-teambuilder-flow.test.js.map +1 -1
  177. package/dist/__tests__/repo-guard-wiring.test.d.ts +21 -0
  178. package/dist/__tests__/repo-guard-wiring.test.d.ts.map +1 -0
  179. package/dist/__tests__/repo-guard-wiring.test.js +638 -0
  180. package/dist/__tests__/repo-guard-wiring.test.js.map +1 -0
  181. package/dist/__tests__/report-format.test.d.ts +2 -0
  182. package/dist/__tests__/report-format.test.d.ts.map +1 -0
  183. package/dist/__tests__/report-format.test.js +219 -0
  184. package/dist/__tests__/report-format.test.js.map +1 -0
  185. package/dist/__tests__/row15-detail-sanitizer.test.d.ts +20 -0
  186. package/dist/__tests__/row15-detail-sanitizer.test.d.ts.map +1 -0
  187. package/dist/__tests__/row15-detail-sanitizer.test.js +61 -0
  188. package/dist/__tests__/row15-detail-sanitizer.test.js.map +1 -0
  189. package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts +2 -0
  190. package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts.map +1 -0
  191. package/dist/__tests__/runtime-codex-gateway-pilot.test.js +309 -0
  192. package/dist/__tests__/runtime-codex-gateway-pilot.test.js.map +1 -0
  193. package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts +2 -0
  194. package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts.map +1 -0
  195. package/dist/__tests__/runtime-codex-gateway-provider.test.js +163 -0
  196. package/dist/__tests__/runtime-codex-gateway-provider.test.js.map +1 -0
  197. package/dist/__tests__/runtime-identity.test.d.ts +2 -0
  198. package/dist/__tests__/runtime-identity.test.d.ts.map +1 -0
  199. package/dist/__tests__/runtime-identity.test.js +117 -0
  200. package/dist/__tests__/runtime-identity.test.js.map +1 -0
  201. package/dist/__tests__/session-pause-provisioning.test.js +6 -1
  202. package/dist/__tests__/session-pause-provisioning.test.js.map +1 -1
  203. package/dist/__tests__/session-record-disclosure.test.d.ts +24 -0
  204. package/dist/__tests__/session-record-disclosure.test.d.ts.map +1 -0
  205. package/dist/__tests__/session-record-disclosure.test.js +494 -0
  206. package/dist/__tests__/session-record-disclosure.test.js.map +1 -0
  207. package/dist/__tests__/session.test.js +35 -0
  208. package/dist/__tests__/session.test.js.map +1 -1
  209. package/dist/__tests__/slug-validation.test.js +27 -21
  210. package/dist/__tests__/slug-validation.test.js.map +1 -1
  211. package/dist/__tests__/standards-injection.test.d.ts +2 -0
  212. package/dist/__tests__/standards-injection.test.d.ts.map +1 -0
  213. package/dist/__tests__/standards-injection.test.js +179 -0
  214. package/dist/__tests__/standards-injection.test.js.map +1 -0
  215. package/dist/__tests__/start-interactive-role.test.d.ts +22 -0
  216. package/dist/__tests__/start-interactive-role.test.d.ts.map +1 -0
  217. package/dist/__tests__/start-interactive-role.test.js +204 -0
  218. package/dist/__tests__/start-interactive-role.test.js.map +1 -0
  219. package/dist/__tests__/start-team-identity.test.d.ts +25 -0
  220. package/dist/__tests__/start-team-identity.test.d.ts.map +1 -0
  221. package/dist/__tests__/start-team-identity.test.js +307 -0
  222. package/dist/__tests__/start-team-identity.test.js.map +1 -0
  223. package/dist/__tests__/team-memory-commands.test.js +142 -19
  224. package/dist/__tests__/team-memory-commands.test.js.map +1 -1
  225. package/dist/__tests__/template-sync.test.d.ts +19 -0
  226. package/dist/__tests__/template-sync.test.d.ts.map +1 -0
  227. package/dist/__tests__/template-sync.test.js +270 -0
  228. package/dist/__tests__/template-sync.test.js.map +1 -0
  229. package/dist/__tests__/test-project.test.d.ts +18 -0
  230. package/dist/__tests__/test-project.test.d.ts.map +1 -0
  231. package/dist/__tests__/test-project.test.js +465 -0
  232. package/dist/__tests__/test-project.test.js.map +1 -0
  233. package/dist/__tests__/usage-per-call-grouping.test.d.ts +25 -0
  234. package/dist/__tests__/usage-per-call-grouping.test.d.ts.map +1 -0
  235. package/dist/__tests__/usage-per-call-grouping.test.js +952 -0
  236. package/dist/__tests__/usage-per-call-grouping.test.js.map +1 -0
  237. package/dist/__tests__/verify-hooks-check-all.test.d.ts +32 -0
  238. package/dist/__tests__/verify-hooks-check-all.test.d.ts.map +1 -0
  239. package/dist/__tests__/verify-hooks-check-all.test.js +553 -0
  240. package/dist/__tests__/verify-hooks-check-all.test.js.map +1 -0
  241. package/dist/__tests__/worktree-sync-fixture.test.d.ts +17 -0
  242. package/dist/__tests__/worktree-sync-fixture.test.d.ts.map +1 -0
  243. package/dist/__tests__/worktree-sync-fixture.test.js +519 -0
  244. package/dist/__tests__/worktree-sync-fixture.test.js.map +1 -0
  245. package/dist/__tests__/worktree-sync-hardening.test.d.ts +13 -0
  246. package/dist/__tests__/worktree-sync-hardening.test.d.ts.map +1 -0
  247. package/dist/__tests__/worktree-sync-hardening.test.js +919 -0
  248. package/dist/__tests__/worktree-sync-hardening.test.js.map +1 -0
  249. package/dist/__tests__/worktree-sync-shell-free.test.d.ts +25 -0
  250. package/dist/__tests__/worktree-sync-shell-free.test.d.ts.map +1 -0
  251. package/dist/__tests__/worktree-sync-shell-free.test.js +185 -0
  252. package/dist/__tests__/worktree-sync-shell-free.test.js.map +1 -0
  253. package/dist/__tests__/worktree.test.js +75 -1
  254. package/dist/__tests__/worktree.test.js.map +1 -1
  255. package/dist/agent-config/.mx-config-generation.json +2 -2
  256. package/dist/agent-config/AGENTS.md.template +2 -2
  257. package/dist/agent-config/agents/bar-raiser.md +34 -1
  258. package/dist/agent-config/agents/red-team.md +34 -1
  259. package/dist/agent-config/agents/security-reviewer.md +22 -1
  260. package/dist/agent-config/claude-md/CLAUDE.core.md +6 -1
  261. package/dist/agent-config/claude-md/CLAUDE.overlay.memnexus.md +1 -3
  262. package/dist/agent-config/coordination-rosters.generated.json +10 -0
  263. package/dist/agent-config/hooks/HOOK-TIMEOUTS.md +27 -1
  264. package/dist/agent-config/hooks/OR-TRUE-AUDIT.md +8 -8
  265. package/dist/agent-config/hooks/auto-capture-precompact.sh +180 -83
  266. package/dist/agent-config/hooks/auto-capture-session-end.sh +216 -87
  267. package/dist/agent-config/hooks/auto-checkpoint.sh +75 -5
  268. package/dist/agent-config/hooks/coordination-brief.sh +290 -245
  269. package/dist/agent-config/hooks/deploy-verification-reminder.sh +359 -22
  270. package/dist/agent-config/hooks/git-mutation-guard.sh +85 -13
  271. package/dist/agent-config/hooks/observability-sync.sh +46 -9
  272. package/dist/agent-config/hooks/session-idle-gate.sh +177 -12
  273. package/dist/agent-config/hooks/subagent-write-guard.sh +670 -0
  274. package/dist/agent-config/hooks/worktree-guard.sh +36 -7
  275. package/dist/agent-config/settings.json +15 -2
  276. package/dist/agent-config/shared/creation-pr-review-checklist.md +317 -0
  277. package/dist/commands/bootstrap.d.ts.map +1 -1
  278. package/dist/commands/bootstrap.js +22 -10
  279. package/dist/commands/bootstrap.js.map +1 -1
  280. package/dist/commands/config-sync.d.ts +37 -0
  281. package/dist/commands/config-sync.d.ts.map +1 -1
  282. package/dist/commands/config-sync.js +36 -18
  283. package/dist/commands/config-sync.js.map +1 -1
  284. package/dist/commands/config.d.ts.map +1 -1
  285. package/dist/commands/config.js +28 -1
  286. package/dist/commands/config.js.map +1 -1
  287. package/dist/commands/coordination.d.ts +150 -8
  288. package/dist/commands/coordination.d.ts.map +1 -1
  289. package/dist/commands/coordination.js +524 -25
  290. package/dist/commands/coordination.js.map +1 -1
  291. package/dist/commands/create.d.ts +922 -1
  292. package/dist/commands/create.d.ts.map +1 -1
  293. package/dist/commands/create.js +4934 -345
  294. package/dist/commands/create.js.map +1 -1
  295. package/dist/commands/dashboard.d.ts.map +1 -1
  296. package/dist/commands/dashboard.js +10 -2
  297. package/dist/commands/dashboard.js.map +1 -1
  298. package/dist/commands/decision.d.ts +20 -0
  299. package/dist/commands/decision.d.ts.map +1 -0
  300. package/dist/commands/decision.js +54 -0
  301. package/dist/commands/decision.js.map +1 -0
  302. package/dist/commands/digest.d.ts.map +1 -1
  303. package/dist/commands/digest.js +91 -7
  304. package/dist/commands/digest.js.map +1 -1
  305. package/dist/commands/fleet-tmux.js +1 -1
  306. package/dist/commands/fleet-tmux.js.map +1 -1
  307. package/dist/commands/init.d.ts +8 -0
  308. package/dist/commands/init.d.ts.map +1 -1
  309. package/dist/commands/init.js +26 -1
  310. package/dist/commands/init.js.map +1 -1
  311. package/dist/commands/list.d.ts +32 -1
  312. package/dist/commands/list.d.ts.map +1 -1
  313. package/dist/commands/list.js +98 -5
  314. package/dist/commands/list.js.map +1 -1
  315. package/dist/commands/monitor.d.ts.map +1 -1
  316. package/dist/commands/monitor.js +8 -2
  317. package/dist/commands/monitor.js.map +1 -1
  318. package/dist/commands/new.d.ts +2 -0
  319. package/dist/commands/new.d.ts.map +1 -1
  320. package/dist/commands/new.js +114 -21
  321. package/dist/commands/new.js.map +1 -1
  322. package/dist/commands/report.d.ts +33 -0
  323. package/dist/commands/report.d.ts.map +1 -0
  324. package/dist/commands/report.js +73 -0
  325. package/dist/commands/report.js.map +1 -0
  326. package/dist/commands/session.js +1 -1
  327. package/dist/commands/session.js.map +1 -1
  328. package/dist/commands/start.d.ts +42 -0
  329. package/dist/commands/start.d.ts.map +1 -1
  330. package/dist/commands/start.js +183 -8
  331. package/dist/commands/start.js.map +1 -1
  332. package/dist/commands/sync.d.ts +57 -0
  333. package/dist/commands/sync.d.ts.map +1 -1
  334. package/dist/commands/sync.js +117 -3
  335. package/dist/commands/sync.js.map +1 -1
  336. package/dist/commands/update.d.ts +13 -1
  337. package/dist/commands/update.d.ts.map +1 -1
  338. package/dist/commands/update.js +50 -1
  339. package/dist/commands/update.js.map +1 -1
  340. package/dist/commands/usage.d.ts +64 -0
  341. package/dist/commands/usage.d.ts.map +1 -1
  342. package/dist/commands/usage.js +96 -3
  343. package/dist/commands/usage.js.map +1 -1
  344. package/dist/commands/verify-hooks.d.ts +37 -1
  345. package/dist/commands/verify-hooks.d.ts.map +1 -1
  346. package/dist/commands/verify-hooks.js +114 -2
  347. package/dist/commands/verify-hooks.js.map +1 -1
  348. package/dist/commands/window.d.ts +10 -0
  349. package/dist/commands/window.d.ts.map +1 -0
  350. package/dist/commands/window.js +265 -0
  351. package/dist/commands/window.js.map +1 -0
  352. package/dist/commands/worktree-sync.d.ts +54 -0
  353. package/dist/commands/worktree-sync.d.ts.map +1 -0
  354. package/dist/commands/worktree-sync.js +135 -0
  355. package/dist/commands/worktree-sync.js.map +1 -0
  356. package/dist/index.d.ts.map +1 -1
  357. package/dist/index.js +189 -14
  358. package/dist/index.js.map +1 -1
  359. package/dist/lib/agent-session.d.ts +12 -0
  360. package/dist/lib/agent-session.d.ts.map +1 -1
  361. package/dist/lib/agent-session.js +189 -42
  362. package/dist/lib/agent-session.js.map +1 -1
  363. package/dist/lib/behavioral-injection.d.ts +9 -0
  364. package/dist/lib/behavioral-injection.d.ts.map +1 -1
  365. package/dist/lib/behavioral-injection.js +10 -1
  366. package/dist/lib/behavioral-injection.js.map +1 -1
  367. package/dist/lib/catalog.d.ts +321 -2
  368. package/dist/lib/catalog.d.ts.map +1 -1
  369. package/dist/lib/catalog.js +490 -11
  370. package/dist/lib/catalog.js.map +1 -1
  371. package/dist/lib/claude.d.ts +113 -23
  372. package/dist/lib/claude.d.ts.map +1 -1
  373. package/dist/lib/claude.js +498 -32
  374. package/dist/lib/claude.js.map +1 -1
  375. package/dist/lib/cli-build.d.ts +172 -0
  376. package/dist/lib/cli-build.d.ts.map +1 -0
  377. package/dist/lib/cli-build.js +654 -0
  378. package/dist/lib/cli-build.js.map +1 -0
  379. package/dist/lib/code-context-file.d.ts +109 -0
  380. package/dist/lib/code-context-file.d.ts.map +1 -0
  381. package/dist/lib/code-context-file.js +219 -0
  382. package/dist/lib/code-context-file.js.map +1 -0
  383. package/dist/lib/code-context-file.test.d.ts +19 -0
  384. package/dist/lib/code-context-file.test.d.ts.map +1 -0
  385. package/dist/lib/code-context-file.test.js +202 -0
  386. package/dist/lib/code-context-file.test.js.map +1 -0
  387. package/dist/lib/config-fidelity.d.ts +40 -20
  388. package/dist/lib/config-fidelity.d.ts.map +1 -1
  389. package/dist/lib/config-fidelity.js +144 -56
  390. package/dist/lib/config-fidelity.js.map +1 -1
  391. package/dist/lib/coordination-client.d.ts +101 -0
  392. package/dist/lib/coordination-client.d.ts.map +1 -1
  393. package/dist/lib/coordination-client.js +232 -8
  394. package/dist/lib/coordination-client.js.map +1 -1
  395. package/dist/lib/coordination-token.d.ts +333 -6
  396. package/dist/lib/coordination-token.d.ts.map +1 -1
  397. package/dist/lib/coordination-token.js +875 -52
  398. package/dist/lib/coordination-token.js.map +1 -1
  399. package/dist/lib/decision-check.d.ts +48 -0
  400. package/dist/lib/decision-check.d.ts.map +1 -0
  401. package/dist/lib/decision-check.js +149 -0
  402. package/dist/lib/decision-check.js.map +1 -0
  403. package/dist/lib/fleet-data.d.ts +34 -0
  404. package/dist/lib/fleet-data.d.ts.map +1 -1
  405. package/dist/lib/fleet-data.js +37 -9
  406. package/dist/lib/fleet-data.js.map +1 -1
  407. package/dist/lib/fleet-render.js +1 -1
  408. package/dist/lib/fleet-render.js.map +1 -1
  409. package/dist/lib/git-identity.d.ts +302 -0
  410. package/dist/lib/git-identity.d.ts.map +1 -0
  411. package/dist/lib/git-identity.js +546 -0
  412. package/dist/lib/git-identity.js.map +1 -0
  413. package/dist/lib/harness/console/announce.d.ts +45 -0
  414. package/dist/lib/harness/console/announce.d.ts.map +1 -0
  415. package/dist/lib/harness/console/announce.js +48 -0
  416. package/dist/lib/harness/console/announce.js.map +1 -0
  417. package/dist/lib/harness/console/announce.test.d.ts +2 -0
  418. package/dist/lib/harness/console/announce.test.d.ts.map +1 -0
  419. package/dist/lib/harness/console/announce.test.js +104 -0
  420. package/dist/lib/harness/console/announce.test.js.map +1 -0
  421. package/dist/lib/harness/console/by-session.d.ts +50 -0
  422. package/dist/lib/harness/console/by-session.d.ts.map +1 -0
  423. package/dist/lib/harness/console/by-session.js +83 -0
  424. package/dist/lib/harness/console/by-session.js.map +1 -0
  425. package/dist/lib/harness/console/by-session.test.d.ts +2 -0
  426. package/dist/lib/harness/console/by-session.test.d.ts.map +1 -0
  427. package/dist/lib/harness/console/by-session.test.js +86 -0
  428. package/dist/lib/harness/console/by-session.test.js.map +1 -0
  429. package/dist/lib/harness/console/console.d.ts +67 -0
  430. package/dist/lib/harness/console/console.d.ts.map +1 -0
  431. package/dist/lib/harness/console/console.js +373 -0
  432. package/dist/lib/harness/console/console.js.map +1 -0
  433. package/dist/lib/harness/console/console.test.d.ts +2 -0
  434. package/dist/lib/harness/console/console.test.d.ts.map +1 -0
  435. package/dist/lib/harness/console/console.test.js +269 -0
  436. package/dist/lib/harness/console/console.test.js.map +1 -0
  437. package/dist/lib/harness/console/decision-request.d.ts +32 -0
  438. package/dist/lib/harness/console/decision-request.d.ts.map +1 -0
  439. package/dist/lib/harness/console/decision-request.js +112 -0
  440. package/dist/lib/harness/console/decision-request.js.map +1 -0
  441. package/dist/lib/harness/console/decision-request.test.d.ts +2 -0
  442. package/dist/lib/harness/console/decision-request.test.d.ts.map +1 -0
  443. package/dist/lib/harness/console/decision-request.test.js +75 -0
  444. package/dist/lib/harness/console/decision-request.test.js.map +1 -0
  445. package/dist/lib/harness/console/fixtures.d.ts +16 -0
  446. package/dist/lib/harness/console/fixtures.d.ts.map +1 -0
  447. package/dist/lib/harness/console/fixtures.js +49 -0
  448. package/dist/lib/harness/console/fixtures.js.map +1 -0
  449. package/dist/lib/harness/console/index.d.ts +15 -0
  450. package/dist/lib/harness/console/index.d.ts.map +1 -0
  451. package/dist/lib/harness/console/index.js +14 -0
  452. package/dist/lib/harness/console/index.js.map +1 -0
  453. package/dist/lib/harness/console/rank.d.ts +73 -0
  454. package/dist/lib/harness/console/rank.d.ts.map +1 -0
  455. package/dist/lib/harness/console/rank.js +113 -0
  456. package/dist/lib/harness/console/rank.js.map +1 -0
  457. package/dist/lib/harness/console/rank.test.d.ts +2 -0
  458. package/dist/lib/harness/console/rank.test.d.ts.map +1 -0
  459. package/dist/lib/harness/console/rank.test.js +124 -0
  460. package/dist/lib/harness/console/rank.test.js.map +1 -0
  461. package/dist/lib/harness/console/render.d.ts +22 -0
  462. package/dist/lib/harness/console/render.d.ts.map +1 -0
  463. package/dist/lib/harness/console/render.js +65 -0
  464. package/dist/lib/harness/console/render.js.map +1 -0
  465. package/dist/lib/harness/console/render.test.d.ts +2 -0
  466. package/dist/lib/harness/console/render.test.d.ts.map +1 -0
  467. package/dist/lib/harness/console/render.test.js +96 -0
  468. package/dist/lib/harness/console/render.test.js.map +1 -0
  469. package/dist/lib/harness/console/replay-cli.test.d.ts +2 -0
  470. package/dist/lib/harness/console/replay-cli.test.d.ts.map +1 -0
  471. package/dist/lib/harness/console/replay-cli.test.js +96 -0
  472. package/dist/lib/harness/console/replay-cli.test.js.map +1 -0
  473. package/dist/lib/harness/console/replay.d.ts +36 -0
  474. package/dist/lib/harness/console/replay.d.ts.map +1 -0
  475. package/dist/lib/harness/console/replay.js +59 -0
  476. package/dist/lib/harness/console/replay.js.map +1 -0
  477. package/dist/lib/harness/console/replay.test.d.ts +2 -0
  478. package/dist/lib/harness/console/replay.test.d.ts.map +1 -0
  479. package/dist/lib/harness/console/replay.test.js +81 -0
  480. package/dist/lib/harness/console/replay.test.js.map +1 -0
  481. package/dist/lib/harness/console/turn-reader.d.ts +50 -0
  482. package/dist/lib/harness/console/turn-reader.d.ts.map +1 -0
  483. package/dist/lib/harness/console/turn-reader.js +184 -0
  484. package/dist/lib/harness/console/turn-reader.js.map +1 -0
  485. package/dist/lib/harness/console/turn-reader.test.d.ts +2 -0
  486. package/dist/lib/harness/console/turn-reader.test.d.ts.map +1 -0
  487. package/dist/lib/harness/console/turn-reader.test.js +108 -0
  488. package/dist/lib/harness/console/turn-reader.test.js.map +1 -0
  489. package/dist/lib/harness/console/types.d.ts +109 -0
  490. package/dist/lib/harness/console/types.d.ts.map +1 -0
  491. package/dist/lib/harness/console/types.js +2 -0
  492. package/dist/lib/harness/console/types.js.map +1 -0
  493. package/dist/lib/harness/contract.d.ts +229 -0
  494. package/dist/lib/harness/contract.d.ts.map +1 -0
  495. package/dist/lib/harness/contract.js +22 -0
  496. package/dist/lib/harness/contract.js.map +1 -0
  497. package/dist/lib/harness/credential.d.ts +23 -0
  498. package/dist/lib/harness/credential.d.ts.map +1 -0
  499. package/dist/lib/harness/credential.js +81 -0
  500. package/dist/lib/harness/credential.js.map +1 -0
  501. package/dist/lib/harness/credential.test.d.ts +2 -0
  502. package/dist/lib/harness/credential.test.d.ts.map +1 -0
  503. package/dist/lib/harness/credential.test.js +74 -0
  504. package/dist/lib/harness/credential.test.js.map +1 -0
  505. package/dist/lib/harness/evaluate.d.ts +390 -0
  506. package/dist/lib/harness/evaluate.d.ts.map +1 -0
  507. package/dist/lib/harness/evaluate.js +988 -0
  508. package/dist/lib/harness/evaluate.js.map +1 -0
  509. package/dist/lib/harness/evaluate.test.d.ts +2 -0
  510. package/dist/lib/harness/evaluate.test.d.ts.map +1 -0
  511. package/dist/lib/harness/evaluate.test.js +621 -0
  512. package/dist/lib/harness/evaluate.test.js.map +1 -0
  513. package/dist/lib/harness/extract.d.ts +152 -0
  514. package/dist/lib/harness/extract.d.ts.map +1 -0
  515. package/dist/lib/harness/extract.js +1601 -0
  516. package/dist/lib/harness/extract.js.map +1 -0
  517. package/dist/lib/harness/gate.d.ts +48 -0
  518. package/dist/lib/harness/gate.d.ts.map +1 -0
  519. package/dist/lib/harness/gate.js +60 -0
  520. package/dist/lib/harness/gate.js.map +1 -0
  521. package/dist/lib/harness/gate.test.d.ts +2 -0
  522. package/dist/lib/harness/gate.test.d.ts.map +1 -0
  523. package/dist/lib/harness/gate.test.js +111 -0
  524. package/dist/lib/harness/gate.test.js.map +1 -0
  525. package/dist/lib/harness/self-check.d.ts +59 -0
  526. package/dist/lib/harness/self-check.d.ts.map +1 -0
  527. package/dist/lib/harness/self-check.js +56 -0
  528. package/dist/lib/harness/self-check.js.map +1 -0
  529. package/dist/lib/harness/self-check.test.d.ts +2 -0
  530. package/dist/lib/harness/self-check.test.d.ts.map +1 -0
  531. package/dist/lib/harness/self-check.test.js +43 -0
  532. package/dist/lib/harness/self-check.test.js.map +1 -0
  533. package/dist/lib/harness/transcript.d.ts +65 -0
  534. package/dist/lib/harness/transcript.d.ts.map +1 -0
  535. package/dist/lib/harness/transcript.js +144 -0
  536. package/dist/lib/harness/transcript.js.map +1 -0
  537. package/dist/lib/harness/transcript.test.d.ts +2 -0
  538. package/dist/lib/harness/transcript.test.d.ts.map +1 -0
  539. package/dist/lib/harness/transcript.test.js +118 -0
  540. package/dist/lib/harness/transcript.test.js.map +1 -0
  541. package/dist/lib/harness-wiring.d.ts +145 -0
  542. package/dist/lib/harness-wiring.d.ts.map +1 -0
  543. package/dist/lib/harness-wiring.js +280 -0
  544. package/dist/lib/harness-wiring.js.map +1 -0
  545. package/dist/lib/hook-staleness.d.ts +95 -0
  546. package/dist/lib/hook-staleness.d.ts.map +1 -0
  547. package/dist/lib/hook-staleness.js +304 -0
  548. package/dist/lib/hook-staleness.js.map +1 -0
  549. package/dist/lib/jsonl.d.ts +270 -2
  550. package/dist/lib/jsonl.d.ts.map +1 -1
  551. package/dist/lib/jsonl.js +472 -76
  552. package/dist/lib/jsonl.js.map +1 -1
  553. package/dist/lib/memory.d.ts +350 -23
  554. package/dist/lib/memory.d.ts.map +1 -1
  555. package/dist/lib/memory.js +751 -38
  556. package/dist/lib/memory.js.map +1 -1
  557. package/dist/lib/otel-env.d.ts +90 -0
  558. package/dist/lib/otel-env.d.ts.map +1 -0
  559. package/dist/lib/otel-env.js +98 -0
  560. package/dist/lib/otel-env.js.map +1 -0
  561. package/dist/lib/project-config.d.ts +167 -0
  562. package/dist/lib/project-config.d.ts.map +1 -1
  563. package/dist/lib/project-config.js +321 -5
  564. package/dist/lib/project-config.js.map +1 -1
  565. package/dist/lib/projects-registry.d.ts +82 -0
  566. package/dist/lib/projects-registry.d.ts.map +1 -0
  567. package/dist/lib/projects-registry.js +145 -0
  568. package/dist/lib/projects-registry.js.map +1 -0
  569. package/dist/lib/projects-registry.test.d.ts +2 -0
  570. package/dist/lib/projects-registry.test.d.ts.map +1 -0
  571. package/dist/lib/projects-registry.test.js +176 -0
  572. package/dist/lib/projects-registry.test.js.map +1 -0
  573. package/dist/lib/repo-guard-scope.d.ts +126 -0
  574. package/dist/lib/repo-guard-scope.d.ts.map +1 -0
  575. package/dist/lib/repo-guard-scope.js +249 -0
  576. package/dist/lib/repo-guard-scope.js.map +1 -0
  577. package/dist/lib/report-format.d.ts +132 -0
  578. package/dist/lib/report-format.d.ts.map +1 -0
  579. package/dist/lib/report-format.js +317 -0
  580. package/dist/lib/report-format.js.map +1 -0
  581. package/dist/lib/roster.d.ts +99 -0
  582. package/dist/lib/roster.d.ts.map +1 -0
  583. package/dist/lib/roster.js +336 -0
  584. package/dist/lib/roster.js.map +1 -0
  585. package/dist/lib/roster.test.d.ts +15 -0
  586. package/dist/lib/roster.test.d.ts.map +1 -0
  587. package/dist/lib/roster.test.js +299 -0
  588. package/dist/lib/roster.test.js.map +1 -0
  589. package/dist/lib/runtime/codex-adapter.d.ts.map +1 -1
  590. package/dist/lib/runtime/codex-adapter.js +5 -0
  591. package/dist/lib/runtime/codex-adapter.js.map +1 -1
  592. package/dist/lib/runtime/codex-config.d.ts +129 -0
  593. package/dist/lib/runtime/codex-config.d.ts.map +1 -1
  594. package/dist/lib/runtime/codex-config.js +225 -0
  595. package/dist/lib/runtime/codex-config.js.map +1 -1
  596. package/dist/lib/runtime/identity.d.ts +72 -0
  597. package/dist/lib/runtime/identity.d.ts.map +1 -0
  598. package/dist/lib/runtime/identity.js +128 -0
  599. package/dist/lib/runtime/identity.js.map +1 -0
  600. package/dist/lib/standards.d.ts +99 -0
  601. package/dist/lib/standards.d.ts.map +1 -0
  602. package/dist/lib/standards.js +201 -0
  603. package/dist/lib/standards.js.map +1 -0
  604. package/dist/lib/team-identity.d.ts +134 -0
  605. package/dist/lib/team-identity.d.ts.map +1 -0
  606. package/dist/lib/team-identity.js +193 -0
  607. package/dist/lib/team-identity.js.map +1 -0
  608. package/dist/lib/templates.d.ts +29 -2
  609. package/dist/lib/templates.d.ts.map +1 -1
  610. package/dist/lib/templates.js +1042 -82
  611. package/dist/lib/templates.js.map +1 -1
  612. package/dist/lib/terminal-ui.d.ts.map +1 -1
  613. package/dist/lib/terminal-ui.js +12 -1
  614. package/dist/lib/terminal-ui.js.map +1 -1
  615. package/dist/lib/test-project.d.ts +95 -0
  616. package/dist/lib/test-project.d.ts.map +1 -0
  617. package/dist/lib/test-project.js +103 -0
  618. package/dist/lib/test-project.js.map +1 -0
  619. package/dist/lib/vault.d.ts +60 -0
  620. package/dist/lib/vault.d.ts.map +1 -0
  621. package/dist/lib/vault.js +102 -0
  622. package/dist/lib/vault.js.map +1 -0
  623. package/dist/lib/vault.test.d.ts +17 -0
  624. package/dist/lib/vault.test.d.ts.map +1 -0
  625. package/dist/lib/vault.test.js +169 -0
  626. package/dist/lib/vault.test.js.map +1 -0
  627. package/dist/lib/window-view.d.ts +63 -0
  628. package/dist/lib/window-view.d.ts.map +1 -0
  629. package/dist/lib/window-view.js +217 -0
  630. package/dist/lib/window-view.js.map +1 -0
  631. package/dist/lib/window-view.test.d.ts +2 -0
  632. package/dist/lib/window-view.test.d.ts.map +1 -0
  633. package/dist/lib/window-view.test.js +168 -0
  634. package/dist/lib/window-view.test.js.map +1 -0
  635. package/dist/lib/worktree-sync.d.ts +439 -0
  636. package/dist/lib/worktree-sync.d.ts.map +1 -0
  637. package/dist/lib/worktree-sync.js +1167 -0
  638. package/dist/lib/worktree-sync.js.map +1 -0
  639. package/dist/lib/worktree.d.ts +58 -1
  640. package/dist/lib/worktree.d.ts.map +1 -1
  641. package/dist/lib/worktree.js +91 -4
  642. package/dist/lib/worktree.js.map +1 -1
  643. package/dist/standards/decision-request.md +98 -0
  644. package/dist/standards/fail-loud-standard.md +495 -0
  645. package/dist/standards/po-communication-standard.md +126 -0
  646. package/dist/standards/report-format.md +128 -0
  647. package/dist/standards/writing-standard.md +382 -0
  648. package/package.json +3 -2
  649. package/scripts/generate-claude.mjs +119 -46
@@ -13,8 +13,24 @@ import { removeLock, updateChildPid } from './leader-lock.js';
13
13
  import { startupReport, reportSuccess, reportWarning, reportDim } from './startup-report.js';
14
14
  import { assessSettingsPosture } from './security-posture.js';
15
15
  import { checkHookCompleteness } from './hook-completeness.js';
16
+ import { checkHookStaleness } from './hook-staleness.js';
17
+ import { launchIdentityEnv, sessionIdentity } from './runtime/identity.js';
18
+ import { OTEL_ENDPOINT_KEY, OTEL_PROTOCOL_KEY, OTEL_TOKEN_KEY, otelEnv, } from './otel-env.js';
19
+ import { getConfigValue } from './config.js';
16
20
  import { sanitizeForMessage, checkBehavioralInjection, checkBehavioralCompleteness, checkRoleguideMarkers, extractMarkerBlock, describeBehavioralProblem, resolveBehavioralInjection, REQUIRED_BEHAVIORAL_ELEMENTS, } from './behavioral-injection.js';
17
- import { DEFAULT_SESSION_MODEL } from './project-config.js';
21
+ import { DEFAULT_SESSION_MODEL, loadProjectConfig, resolveProjectConfig } from './project-config.js';
22
+ // ONE definition of the team's git address and its trailer (#440 A). The
23
+ // isolation block below states them to the session; `commands/create.ts` writes
24
+ // the matching config into the worktree. Two copies of either literal would
25
+ // drift the moment one was edited, and the session would then be told to sign
26
+ // commits as an address the config does not set.
27
+ // `describeTeamGitIdentityState` is the third shared definition and the one that
28
+ // keeps this block honest: row 15 and this block branch on the same boolean from
29
+ // the same function, so the file cannot claim an identity the row could not read
30
+ // (#440 part A).
31
+ import { teamGitEmail, teamCoAuthorTrailer, describeTeamGitIdentityState, } from './git-identity.js';
32
+ import { testProjectEnv } from './test-project.js';
33
+ import { resolveStandards } from './standards.js';
18
34
  // ── Logging helpers ───────────────────────────────────────────────────
19
35
  // These print exactly as before AND mirror a plain-text copy into the
20
36
  // per-invocation StartupReport (#4350). They record with an EXACT level and
@@ -308,6 +324,205 @@ export function extractBehavioralContent(projectRoot, teamSlug, teamsDir = 'mx-a
308
324
  roleguideRelPath: r.roleguideRelPath,
309
325
  };
310
326
  }
327
+ // Written as \u escapes so this source stays pure ASCII: an invisible character
328
+ // pasted literally into a regex is unreviewable (`coordination-render.ts:57-58`).
329
+ //
330
+ // Line terminators a markdown reader or a model can take as a line break that
331
+ // `\n` splitting does not see. Collapsed to a space, as `coordination-render.ts`
332
+ // does, so a value cannot start a line of its own.
333
+ const CLAUDE_LOCAL_LINE_BREAK_RE = /[\u0085\u2028\u2029]+/g;
334
+ // Zero-width and bidirectional formatting characters: the same ranges
335
+ // `coordination-render.ts:60` strips. Dropped, not replaced, so removing them
336
+ // does not change the visible text.
337
+ const CLAUDE_LOCAL_INVISIBLE_RE = /[\u200b-\u200f\u202a-\u202e\u2060-\u2064\u2066-\u206f\ufeff]/g;
338
+ // Every other format character (\p{Cf}) and every default-ignorable code point
339
+ // (\p{Default_Ignorable_Code_Point}, Unicode DerivedCoreProperties.txt): the
340
+ // code points a renderer is told to draw as nothing. Security review of PR
341
+ // #501, comments 5822351133 and 5847050322. The default-ignorable class holds
342
+ // the tag block U+E0000-E0FFF whole, assigned or not (U+E0000 and
343
+ // U+E0002-E001F are \p{Cn}, not \p{Cf}, comment 5822523085), U+034F, the
344
+ // Hangul fillers U+115F, U+1160, U+3164 and U+FFA0, the variation selectors
345
+ // U+180B-180F, U+FE00-FE0F and U+E0100-E01EF, and the reserved U+2065 and
346
+ // U+FFF0-FFF8. The default-ignorable class also holds U+00AD and U+061C.
347
+ // \p{Cf} adds the 32 format characters that are not default-ignorable:
348
+ // U+0600-0605, U+06DD, U+070F, U+0890-0891, U+08E2, U+FFF9-FFFB, U+110BD,
349
+ // U+110CD and U+13430-1343F. Not all of them are invisible: the prepended
350
+ // concatenation marks (U+0600-0605, U+06DD, U+070F, U+0890-0891, U+08E2,
351
+ // U+110BD, U+110CD) draw as visible signs in fonts that support them. They are
352
+ // removed because no legitimate slug, path, branch or git identity holds them.
353
+ // Security review of PR #501, comment 5847118040; the 32 re-measured on Node
354
+ // 22.16.0. Measured over U+0000-U+10FFFF on Node 18.20.8 and 22.16.0: 4,206
355
+ // code points match, a
356
+ // superset of the 460 the earlier explicit list matched, and none is a C0 or
357
+ // C1 control, a line terminator or a backtick. None of these can start a line;
358
+ // each can hide text from a reviewer while a model still reads it. The `u`
359
+ // flag is what enables \p{...} and code points above U+FFFF.
360
+ const CLAUDE_LOCAL_FORMAT_RE = /[\p{Cf}\p{Default_Ignorable_Code_Point}]/gu;
361
+ // A lone UTF-16 surrogate: a high one not followed by a low one, or a low one
362
+ // not preceded by a high one.
363
+ const LONE_SURROGATE_RE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
364
+ /**
365
+ * `String.prototype.toWellFormed`, with a fallback for runtimes without it.
366
+ *
367
+ * `package.json` declares `node >=18`, and `toWellFormed` exists from Node 20.
368
+ * On Node 18 a bare call would throw a TypeError and every `CLAUDE.local.md`
369
+ * generation would fail, so the same replacement (each lone surrogate becomes
370
+ * U+FFFD) is done by a regex there. `native: false` forces the fallback, for
371
+ * the test that covers it. The compile target is ES2022, whose lib does not
372
+ * declare the method, hence the structural type.
373
+ */
374
+ export function toWellFormedString(value, native = true) {
375
+ const s = value;
376
+ if (native && typeof s.toWellFormed === 'function')
377
+ return s.toWellFormed();
378
+ return value.replace(LONE_SURROGATE_RE, '\uFFFD');
379
+ }
380
+ /**
381
+ * Sanitize a value before it is interpolated into a generated `CLAUDE.local.md`
382
+ * (#460). THE SINK IS A MODEL, NOT A TERMINAL.
383
+ *
384
+ * `CLAUDE.local.md` is injected into every turn of the team's sessions, so a
385
+ * value that reaches it is read as part of the session's standing instructions.
386
+ * `sanitizeForMessage` was built for a terminal: it stops escape sequences and
387
+ * line breaks. A model is also misled by characters a terminal ignores:
388
+ * - U+2028, U+2029 and U+0085 can read as a line break, which is what a forged
389
+ * `## Critical Rules (amended)` heading needs. Collapsed to a space.
390
+ * - Zero-width and bidi characters (U+200B-200F, U+202A-202E, U+2060-2064,
391
+ * U+2066-206F, U+FEFF) hide or reorder text a reviewer reads. Dropped.
392
+ * - Every other format character (`\p{Cf}`) and every default-ignorable code
393
+ * point (`\p{Default_Ignorable_Code_Point}`, which holds the whole tag block
394
+ * U+E0000-E0FFF, the Hangul fillers and the variation selectors) hide text
395
+ * the same way. Dropped.
396
+ * - A backtick closes the inline code span every value here is written inside,
397
+ * so the rest of the value is read as prose. Replaced with `'`, which keeps the
398
+ * value legible and cannot close a span.
399
+ * Then `sanitizeForMessage` runs, which replaces C0, C1 and DEL with U+FFFD and
400
+ * caps the length. U+0085 is C1, so the collapse above has to run first.
401
+ *
402
+ * A SEPARATE FUNCTION, NOT A WIDER `sanitizeForMessage`, following
403
+ * `coordination-render.ts`'s `sanitizeField` and #304: the terminal-only callers
404
+ * of `sanitizeForMessage` keep their output. It is the identity function on every
405
+ * slug `isValidProjectSlug` accepts and on every ASCII path without a backtick,
406
+ * so no legitimate team's file changes by one byte.
407
+ */
408
+ export function sanitizeForClaudeLocal(value, maxLength = 200) {
409
+ // WELL-FORMED FIRST (delta security review of PR #501, comment 5822443936,
410
+ // CWE-180). A lone high surrogate, a removable character, then a lone low
411
+ // surrogate would become ONE tag character once the middle is dropped:
412
+ // "x\uDB40\u00AD\uDC41y" turned into U+E0041. `toWellFormedString` replaces every
413
+ // lone surrogate with U+FFFD before any removal runs, so no removal can pair
414
+ // two of them. Reachable through `projectSlug`, which `JSON.parse` reads from
415
+ // `mx-agent.config.json` unvalidated (`project-config.ts:548`).
416
+ const cleaned = toWellFormedString(value)
417
+ .replace(CLAUDE_LOCAL_LINE_BREAK_RE, ' ')
418
+ .replace(CLAUDE_LOCAL_INVISIBLE_RE, '')
419
+ .replace(CLAUDE_LOCAL_FORMAT_RE, '')
420
+ .replace(/`/g, "'");
421
+ return sanitizeForMessage(cleaned, maxLength);
422
+ }
423
+ /**
424
+ * The `## Git Identity` block, in the ONE wording that is true of this worktree.
425
+ *
426
+ * TWO VARIANTS, CHOSEN BY `state.isolated`, which is the same boolean completion
427
+ * row 15 asserts on (`commands/create.ts:3420`). Written: this worktree's own
428
+ * `config.worktree` supplies the team's name and email. Not written: it does
429
+ * not, and the block says so, names the author commits will actually carry, and
430
+ * keeps the trailer instruction because the trailer is then the only per-team
431
+ * attribution left.
432
+ *
433
+ * THE REFUSED VARIANT IS NOT SILENCE. Deleting the block would leave a session
434
+ * with no statement about its own attribution at all, and the trailer
435
+ * instruction is the half that still works when the config write refused. It
436
+ * would also make an absent block ambiguous between "no team" and "team, no
437
+ * identity", which is the distinction this whole change exists to make.
438
+ *
439
+ * IT NAMES NO REMEDY THE SESSION COULD RUN. The fix for the common refusal is
440
+ * `git config extensions.worktreeConfig true` on the SHARED repository, and this
441
+ * file is standing instructions for a team session that must not change state
442
+ * every other team reads. Row 15 carries that command, for the operator. The
443
+ * block tells the session to report the state and names the one command it must
444
+ * NOT reach for.
445
+ *
446
+ * EVERY INTERPOLATED VALUE IS SANITIZED. The slug arrives already sanitized from
447
+ * the caller. `effectiveAuthor`, `reason` and `effectiveNameOrigin` come out of
448
+ * a git config file this command does not own. `describeTeamGitIdentityState`
449
+ * sanitizes the first two for a terminal; all three pass `sanitizeForClaudeLocal`
450
+ * here, because this block is read by a model (#460).
451
+ *
452
+ * AND NO VALUE IN THIS BLOCK BEGINS A LINE (red-team of PR #501, plan #500
453
+ * criterion 2). The sanitizer stops a value from starting a NEW line; it does
454
+ * not stop a value from being the first text on a line the template already
455
+ * starts. In this block each value follows fixed text on its own line, inside a
456
+ * code span the sanitizer's backtick replacement keeps closed. `reason` was
457
+ * written bare at the start of a line, so a reason reading `## ...` rendered as
458
+ * a heading. It is reachable: the `unreadable` reason in `git-identity.ts`
459
+ * begins with the caller's `worktreePath`.
460
+ *
461
+ * THE CLAIM IS ABOUT THIS BLOCK ONLY. Elsewhere in `CLAUDE.local.md` a value can
462
+ * follow a line's opening markup: the behavioral heading is `# ` then the
463
+ * display name, and the isolation list writes `- **Worktree name:** ` then the
464
+ * name. Those are safe because every value passes `sanitizeForClaudeLocal`
465
+ * first, so it holds no line terminator and cannot add a line of its own. The
466
+ * structural test in `claude-local-sanitizer.test.ts` fails on any `${...}` in
467
+ * the content builders that is neither sanitized nor on its commented
468
+ * allowlist. The roleguide content, the standards and the main checkout's
469
+ * `CLAUDE.local.md` are whole documents written in unsanitized: their policy is
470
+ * #504's, not this function's.
471
+ */
472
+ function gitIdentityBlock(safeTeamSlug, state) {
473
+ const trailerAndCaveat = `The address is under \`mx-agent.local\` and resolves to no GitHub account. The trailer stays in the
474
+ commit body as text and shows as an unlinked co-author. It records which worktree produced a
475
+ commit; it is not a GitHub identity and it proves nothing about who the session was.`;
476
+ if (state.isolated) {
477
+ return `
478
+ ## Git Identity
479
+
480
+ This worktree commits as its own team. \`mx-agent provision\` set \`user.name\` and \`user.email\` here
481
+ with \`git config --worktree\`, so they apply to this worktree and to no other (#440).
482
+
483
+ - **Author:** \`${safeTeamSlug} <${teamGitEmail(safeTeamSlug)}>\`
484
+ - End every commit message with this trailer, so the attribution survives a squash merge onto the
485
+ base branch: \`${teamCoAuthorTrailer(safeTeamSlug)}\`
486
+
487
+ ${trailerAndCaveat}
488
+
489
+ If \`git log -1\` in this worktree shows an author that is not the one above, say so rather than
490
+ working around it: the per-worktree config is missing or was overwritten.
491
+ `;
492
+ }
493
+ const authorBullet = state.effectiveAuthor === null
494
+ ? '- **Author your commits will actually carry:** git would not report one.'
495
+ // Cap 300, not 240: the value is already capped at 240 by `sanitizeOneLine`
496
+ // in `git-identity.ts`, and a second, equal cap would truncate its own
497
+ // `… (N chars)` suffix.
498
+ : `- **Author your commits will actually carry:** \`${sanitizeForClaudeLocal(state.effectiveAuthor, 300)}\`, resolved from
499
+ ${state.effectiveNameOrigin === null
500
+ ? 'a file git would not name'
501
+ : `\`${sanitizeForClaudeLocal(state.effectiveNameOrigin)}\``}, which every worktree of this repository shares.`;
502
+ return `
503
+ ## Git Identity
504
+
505
+ **This worktree does NOT commit as its own team.** \`mx-agent provision\` sets \`user.name\` and
506
+ \`user.email\` per worktree with \`git config --worktree\`, and here it wrote neither.
507
+ Reason: \`${sanitizeForClaudeLocal(state.reason, 240)}\`.
508
+
509
+ ${authorBullet}
510
+ - **Intended author, NOT in force:** \`${safeTeamSlug} <${teamGitEmail(safeTeamSlug)}>\`. Do not
511
+ describe a commit from this worktree as coming from this team.
512
+ - End every commit message with this trailer anyway. It is the only per-team attribution available
513
+ in this state, and it survives a squash merge onto the base branch:
514
+ \`${teamCoAuthorTrailer(safeTeamSlug)}\`
515
+
516
+ Do not try to fix this from this session. \`git config user.name\` WITHOUT \`--worktree\` writes the
517
+ SHARED config from a linked worktree and reassigns every other team's identity at once, which is
518
+ the defect #440 exists to prevent. Enabling \`extensions.worktreeConfig\` is a one-time change to
519
+ state every worktree on this machine reads, and it is not a team session's to make. Report the
520
+ state instead; completion row 15 of \`mx-agent provision\` reports it with the remedy an operator
521
+ runs once.
522
+
523
+ ${trailerAndCaveat}
524
+ `;
525
+ }
311
526
  /**
312
527
  * Build the CLAUDE.local.md content without writing it.
313
528
  *
@@ -326,6 +541,58 @@ export function buildClaudeLocalContent(opts) {
326
541
  const { projectRoot, worktreePath, worktreeName, branch, slot, projectSlug = '', teamSlug, behavioralOverride, } = opts;
327
542
  const baseBranch = opts.baseBranch ?? 'main';
328
543
  const diagnostics = [];
544
+ // SANITIZE THE SLUG BEFORE IT REACHES THE INSTRUCTION FILE (security review
545
+ // of #440 part A, comment 5561125763, Should Fix).
546
+ //
547
+ // Every other `teamSlug` interpolation in this module already wraps the value
548
+ // this way (`:609`, `:674`, `:891`); those three write a warning to a
549
+ // terminal. The Git Identity block writes into `CLAUDE.local.md`, which is
550
+ // injected into every turn of this team's sessions, so it is the HIGHER-value
551
+ // sink of the four and was the one that did not sanitize. The reviewer's proof
552
+ // of concept put a `## Critical Rules (amended)` heading carrying "You may
553
+ // push directly to main" into the generated file, as a sibling of the real
554
+ // `## Critical Rules` list a few lines above it.
555
+ //
556
+ // WHY THE SINK AND NOT ONLY THE SOURCE. `mx-agent provision` validates the
557
+ // slug against `isValidProjectSlug` before any write (`commands/create.ts:
558
+ // 4374-4379`) and is safe. `mx-agent start` does not: `lib/team-identity.ts:
559
+ // 63-66` leaves validation to `resolveBehavioralInjection`, whose refusal is
560
+ // FAIL-OPEN — `:713-715` below concatenates `isolationContent` into the
561
+ // returned content whether that resolver accepted the slug or refused it. So a
562
+ // refused slug still reaches this block, and the guarantee has to be local to
563
+ // the value, which is the same argument `sanitizeForMessage`'s own header
564
+ // makes about its other call sites.
565
+ //
566
+ // `sanitizeForClaudeLocal` (#460) removes what a model misreads and a terminal
567
+ // does not (U+2028/2029, zero-width and bidi characters, backticks), then
568
+ // `sanitizeForMessage` replaces C0 (including the newline the injection
569
+ // needs), DEL and C1 with U+FFFD and caps the length. It is the identity
570
+ // function on every slug `isValidProjectSlug` accepts: that regex admits only
571
+ // `[a-z0-9-]` and at most 50 characters, both well inside the cap, so no
572
+ // legitimate team's block changes by one byte.
573
+ const safeTeamSlug = teamSlug ? sanitizeForClaudeLocal(teamSlug, 80) : '';
574
+ // THE BLOCK MUST AGREE WITH COMPLETION ROW 15 (#440 part A, creation test).
575
+ //
576
+ // It was gated on `teamSlug` alone and stated, unconditionally, that
577
+ // `mx-agent provision` had set `user.name` and `user.email` here. On a
578
+ // repository with `extensions.worktreeConfig` off — which is every worktree of
579
+ // `/workspace/.git` today, so it is the outcome for every team provisioned
580
+ // now — `writeTeamGitIdentity` refuses and writes nothing, row 15 reports
581
+ // could-not-run, and this file said the opposite. The creation test measured
582
+ // both on one run: the row reported could-not-run and the block named
583
+ // `creation-probe <creation-probe@mx-agent.local>` while commits from that
584
+ // worktree carried the shared identity. `CLAUDE.local.md` is injected into
585
+ // every turn of the team's sessions, which makes it the highest-leverage place
586
+ // in the system to state something untrue.
587
+ //
588
+ // THE STATE IS READ FROM GIT, not threaded down from `writeTeamGitIdentity`.
589
+ // `mx-agent start` regenerates this file on every session and never calls the
590
+ // writer, so a threaded write outcome would be available on the provisioning
591
+ // path and absent on the one that runs far more often. Reading means both
592
+ // consumers branch on the one `isolated` boolean
593
+ // `describeTeamGitIdentityState` returns, so there is no state where the row
594
+ // reports could-not-run and the file claims an identity was written.
595
+ const gitIdentity = teamSlug ? describeTeamGitIdentityState(worktreePath, teamSlug) : null;
329
596
  // Check if main workspace has a CLAUDE.local.md to merge
330
597
  let mainLocalContent = '';
331
598
  const mainLocalMdPath = join(projectRoot, 'CLAUDE.local.md');
@@ -337,37 +604,49 @@ export function buildClaudeLocalContent(opts) {
337
604
  // ignore
338
605
  }
339
606
  }
607
+ // THE ISOLATION BLOCK'S VALUES PASS THE SAME SANITIZER (#460). None of them
608
+ // was sanitized before. `worktreePath` and `branch` come from the filesystem
609
+ // and git, `worktreeName` and `projectSlug` from the caller, and each is
610
+ // written into the `## Critical Rules` list a forged heading would imitate.
611
+ // The path cap is 4096 (Linux PATH_MAX) so no real path is truncated. `slot`
612
+ // is typed as a number and is stringified through the sanitizer anyway, so the
613
+ // guarantee does not depend on every caller honouring the type.
614
+ const safeWorktreeName = sanitizeForClaudeLocal(worktreeName);
615
+ const safeWorktreePath = sanitizeForClaudeLocal(worktreePath, 4096);
616
+ const safeBranch = branch ? sanitizeForClaudeLocal(branch) : '';
617
+ const safeSlot = sanitizeForClaudeLocal(String(slot));
618
+ const safeProjectSlug = projectSlug ? sanitizeForClaudeLocal(projectSlug) : '';
340
619
  const isolationContent = `# Worktree Isolation Context
341
620
 
342
621
  You are working in an isolated worktree. Follow these rules strictly.
343
622
 
344
623
  ## Your Environment
345
624
 
346
- - **Worktree name:** ${worktreeName}
347
- - **Worktree path:** ${worktreePath}
348
- - **Branch:** ${branch || 'unknown'}
349
- - **Slot:** ${slot}
625
+ - **Worktree name:** ${safeWorktreeName}
626
+ - **Worktree path:** ${safeWorktreePath}
627
+ - **Branch:** ${safeBranch || 'unknown'}
628
+ - **Slot:** ${safeSlot}
350
629
 
351
630
  ## Critical Rules
352
631
 
353
- 1. **Stay in your worktree.** Your working directory is \`${worktreePath}\`. All file paths must be relative to or within this directory.
632
+ 1. **Stay in your worktree.** Your working directory is \`${safeWorktreePath}\`. All file paths must be relative to or within this directory.
354
633
  2. **Never reference \`/workspace\` directly.** That is the main repo. Use your worktree path instead. For example:
355
634
  - Wrong: \`cd /workspace/cli\` or \`npm install --prefix /workspace/cli\`
356
- - Right: \`cd ${worktreePath}/cli\` or \`npm install --prefix ${worktreePath}/cli\`
635
+ - Right: \`cd ${safeWorktreePath}/cli\` or \`npm install --prefix ${safeWorktreePath}/cli\`
357
636
  3. **Use environment variables** when available: \`$CLAUDE_WORKTREE_PATH\` points to your worktree root.
358
- 4. **Do not switch branches.** Stay on \`${branch || 'your current branch'}\`. Branch switching is blocked.
637
+ 4. **Do not switch branches.** Stay on \`${safeBranch || 'your current branch'}\`. Branch switching is blocked.
359
638
  5. **Do not merge or push to main.** Create a PR instead using \`gh pr create\`.
360
- 6. **Push to your branch** with \`git push -u origin ${branch || '<your-branch>'}\`.
361
- ${projectSlug ? `
639
+ 6. **Push to your branch** with \`git push -u origin ${safeBranch || '<your-branch>'}\`.
640
+ ${gitIdentity ? gitIdentityBlock(safeTeamSlug, gitIdentity) : ''}${safeProjectSlug ? `
362
641
  ## Memory Key Scope
363
642
 
364
643
  This project uses a scoped prefix for all named memories to prevent collisions across projects sharing the same MemNexus account.
365
644
 
366
- - **Project slug:** \`${projectSlug}\`
367
- - **Named memory key format:** \`${projectSlug}-<team>-<type>\`
368
- - **Example:** \`${projectSlug}-product-leader-state\` (never \`product-leader-state\`)
645
+ - **Project slug:** \`${safeProjectSlug}\`
646
+ - **Named memory key format:** \`${safeProjectSlug}-<team>-<type>\`
647
+ - **Example:** \`${safeProjectSlug}-product-leader-state\` (never \`product-leader-state\`)
369
648
 
370
- All \`mx memories create --name\` and \`mx memories update --name\` calls MUST use the \`${projectSlug}-\` prefix. This is enforced — keys without the prefix will collide with other projects on this account.
649
+ All \`mx memories create --name\` and \`mx memories update --name\` calls MUST use the \`${safeProjectSlug}-\` prefix. This is enforced — keys without the prefix will collide with other projects on this account.
371
650
  ` : ''}
372
651
  # currentDate
373
652
  Today's date is ${new Date().toISOString().slice(0, 10)}.
@@ -450,9 +729,17 @@ Today's date is ${new Date().toISOString().slice(0, 10)}.
450
729
  rendered: '',
451
730
  };
452
731
  if (behavioral.ok && behavioral.content && behavioral.roleguideRelPath) {
732
+ // THE DISPLAY NAME PASSES THE MODEL-READ SANITIZER (red-team of PR #501 at
733
+ // 2e441cc, finding 1). It comes from the team catalog's `Display name:` line
734
+ // through `safeDisplayName`, whose control-character class admits CR, or
735
+ // from `behavioralOverride.displayName`, which nothing checks. A CR, U+2028
736
+ // or U+2029 in it started a second line, so a display name could write a
737
+ // forged `## Critical Rules (amended)` heading. After the sanitizer the
738
+ // value holds no line terminator, so `# ` plus the value is one line and
739
+ // adds no second heading. Cap 120 matches `safeDisplayName`.
453
740
  behavioralBlock =
454
- `# ${behavioral.displayName} — Behavioral Checks (every-turn reinforcement)\n\n` +
455
- `> These checks are pinned here so they re-inject on every conversation turn. The full charter, scope, agent roster, and start-of-session checklist live in \`${behavioral.roleguideRelPath}\` (read once at session start).\n\n` +
741
+ `# ${sanitizeForClaudeLocal(behavioral.displayName, 120)} — Behavioral Checks (every-turn reinforcement)\n\n` +
742
+ `${behavioralPointerLine(behavioral.roleguideRelPath)}\n\n` +
456
743
  `${behavioral.content}\n\n---\n\n`;
457
744
  // Record the EXACT inserted text so the verifier can assert the delivered
458
745
  // file contains it verbatim (#4707 SF-1).
@@ -483,13 +770,39 @@ Today's date is ${new Date().toISOString().slice(0, 10)}.
483
770
  });
484
771
  }
485
772
  }
773
+ // ── Framework standards, injected on every turn ────────────────────────────
774
+ //
775
+ // The writing standard and the report format ship with the framework rather
776
+ // than with a team, so they are read here rather than from a roleguide. They
777
+ // go in for the reason `product/mx-agent-prd.md:268` records: when we built a
778
+ // mechanism, teams followed the practice, and when we only wrote a rule, they
779
+ // stopped. A standard read once at session start is the second shape.
780
+ //
781
+ // FAIL-OPEN, and never silent. A missing standard degrades the writing and
782
+ // does not endanger the session, so it warns and continues, the same tier as
783
+ // the behavioral block above. The fail-closed control for this pair is
784
+ // `mx-agent report check`, which refuses a report rather than a session.
785
+ const standards = resolveStandards(opts.standardsDir);
786
+ for (const message of standards.warnings) {
787
+ diagnostics.push({ level: 'warn', message, code: 'standards-injection-missing' });
788
+ }
789
+ if (standards.rendered !== '') {
790
+ diagnostics.push({
791
+ level: 'dim',
792
+ message: `Framework standards injected from ${sanitizeForMessage(standards.dir ?? 'unknown')} ` +
793
+ `(${standards.blocks.filter((b) => b.ok).length} of ${standards.blocks.length}, ` +
794
+ `${standards.rendered.split('\n').length} lines)`,
795
+ });
796
+ }
797
+ const standardsBlock = standards.rendered;
486
798
  const content = mainLocalContent
487
- ? `${mainLocalContent}\n\n---\n\n${behavioralBlock}${isolationContent}`
488
- : `${behavioralBlock}${isolationContent}`;
799
+ ? `${mainLocalContent}\n\n---\n\n${behavioralBlock}${standardsBlock}${isolationContent}`
800
+ : `${behavioralBlock}${standardsBlock}${isolationContent}`;
489
801
  return {
490
802
  content,
491
803
  ...(warning ? { warning, warningCode: 'behavioral-injection-missing' } : {}),
492
804
  hasBehavioralBlock: behavioralBlock !== '',
805
+ hasStandardsBlock: standards.complete,
493
806
  behavioral: behavioralInfo,
494
807
  diagnostics,
495
808
  };
@@ -525,6 +838,51 @@ export function writeClaudeLocal(opts) {
525
838
  }
526
839
  return { written, path: localMdPath, behavioral: built.behavioral };
527
840
  }
841
+ /**
842
+ * The pointer line that names which roleguide a worktree was provisioned from.
843
+ *
844
+ * ONE DEFINITION, because two consumers read and write it (red-team round 2,
845
+ * finding 1). This module writes it into `CLAUDE.local.md`, and
846
+ * `commands/create.ts` reads it back as half of the resume identity check
847
+ * (#316). A second copy of the literal in the reader would drift the moment
848
+ * either sentence was edited, and the failure would be silent: the reader would
849
+ * answer "this worktree names no roleguide", which the resume path treats as
850
+ * nothing to compare and lets through.
851
+ */
852
+ const POINTER_PREFIX = '> These checks are pinned here so they re-inject on every conversation turn. '
853
+ + 'The full charter, scope, agent roster, and start-of-session checklist live in `';
854
+ const POINTER_SUFFIX = '` (read once at session start).';
855
+ /** Longest roleguide path the reader will take out of the line. */
856
+ const POINTER_VALUE_MAX = 240;
857
+ /**
858
+ * The path is sanitized HERE, not by the caller (security review of PR #501,
859
+ * comment 5855461725). It is the `Roleguide:` value of a team catalog file or
860
+ * `behavioralOverride.roleguideRelPath`, and the line is written into
861
+ * `CLAUDE.local.md` and `AGENTS.override.md`. The sanitizer is the identity on
862
+ * every ASCII path without a backtick, so `readBehavioralPointer` reads back the
863
+ * same value it did before for every real roleguide path.
864
+ */
865
+ export function behavioralPointerLine(roleguideRelPath) {
866
+ return `${POINTER_PREFIX}${sanitizeForClaudeLocal(roleguideRelPath, POINTER_VALUE_MAX)}${POINTER_SUFFIX}`;
867
+ }
868
+ /**
869
+ * The roleguide path a written `CLAUDE.local.md` names, or null.
870
+ *
871
+ * Null for a file with no such line, an empty value, one over
872
+ * {@link POINTER_VALUE_MAX}, or one holding a backtick or a line break: the
873
+ * value comes off disk and reaches a comparison and a printed refusal.
874
+ */
875
+ export function readBehavioralPointer(localMdContent) {
876
+ const at = localMdContent.indexOf(POINTER_PREFIX);
877
+ if (at === -1)
878
+ return null;
879
+ const rest = localMdContent.slice(at + POINTER_PREFIX.length);
880
+ const end = rest.indexOf(POINTER_SUFFIX);
881
+ if (end <= 0 || end > POINTER_VALUE_MAX)
882
+ return null;
883
+ const value = rest.slice(0, end);
884
+ return /[\r\n`]/.test(value) ? null : value;
885
+ }
528
886
  /**
529
887
  * The header line `writeClaudeLocal` puts above an injected block. The written
530
888
  * file never contains the markers themselves, so this is the only thing a
@@ -908,11 +1266,11 @@ function generatorScriptPath() {
908
1266
  * (hooks block dropped) and an UNRESOLVABLE hook reference as unhealthy, so a
909
1267
  * dropped or malformed registration heals rather than silently passing.
910
1268
  *
911
- * HEAL SOURCE. `--permission-from-git origin/<baseBranch>` rewrites settings.json
912
- * + hooks/ from the reviewed remote snapshot (tamper-resistant) and degrades
913
- * gracefully to the last-known-good cache when offline — the right restore for
914
- * missing guardrails. This mirrors the container-boot invocation, not the
915
- * whole-tree `--from-git` path syncClaudeConfig uses per session.
1269
+ * HEAL SOURCE. `--permission-from-git origin/<baseBranch> --skip-behavioral-layer`
1270
+ * rewrites settings.json + hooks/ from the reviewed remote snapshot
1271
+ * (tamper-resistant) and degrades gracefully to the last-known-good cache when
1272
+ * offline — the right restore for missing guardrails. It writes NOTHING else:
1273
+ * see regeneratePermissionLayer for why the second flag is load-bearing (#247).
916
1274
  *
917
1275
  * FAILURE MODEL — fail OPEN on availability. A generator failure (or a heal that
918
1276
  * does not restore every file) warns LOUDLY, naming every still-unhealthy guard,
@@ -920,6 +1278,37 @@ function generatorScriptPath() {
920
1278
  * silent-degradation risk into an availability outage; the loud, named warning
921
1279
  * keeps the degradation from being silent. Never throws.
922
1280
  */
1281
+ /**
1282
+ * The ONE write path both self-heals use: regenerate the PERMISSION LAYER
1283
+ * (settings.json + hooks/) from `origin/<baseBranch>`. Extracted so the
1284
+ * completeness heal and the staleness heal cannot drift into two different ways
1285
+ * of rewriting it.
1286
+ *
1287
+ * `--skip-behavioral-layer` IS THE WHOLE OF WHAT THIS FUNCTION REGENERATES.
1288
+ * Without it `--permission-from-git` runs `generateClaudeConfigForBoot`, whose
1289
+ * steps 3 to 6 write agents/, skills/, commands/ and rules/ from the WORKING
1290
+ * TREE, and `generateClaudeConfig` rewrites the whole tree on every call. So a
1291
+ * heal firing after `syncClaudeConfig` reverted the origin-sourced behavioural
1292
+ * layers to working-tree content, on a worktree that may be many commits behind,
1293
+ * while its success line named only the hooks it restored (#247, red-team
1294
+ * Critical 1). A heal asked for a missing hook restores that hook.
1295
+ *
1296
+ * The container-boot invocation of `generateClaudeConfigForBoot` is unchanged:
1297
+ * it passes no such flag, and a real container boot still refreshes behavioural
1298
+ * config from local edits, which is a prior red-team CRITICAL 1 fix.
1299
+ */
1300
+ function regeneratePermissionLayer(worktreePath, baseBranch, configSource) {
1301
+ const r = spawnSync(process.execPath, [
1302
+ generatorScriptPath(),
1303
+ '--repo-root', worktreePath,
1304
+ '--dest', join(worktreePath, '.claude'),
1305
+ '--permission-from-git', `origin/${baseBranch}`,
1306
+ '--skip-behavioral-layer',
1307
+ '--config-source', configSource,
1308
+ '--quiet',
1309
+ ], { cwd: worktreePath, encoding: 'utf-8', stdio: 'pipe' });
1310
+ return { status: r.status, stderr: r.stderr ? String(r.stderr).trim() : '' };
1311
+ }
923
1312
  export function verifyAndHealHooks(worktreePath, opts = {}) {
924
1313
  const baseBranch = opts.baseBranch ?? 'main';
925
1314
  const configSource = opts.configSource ?? 'mx-agent-system/agent-config';
@@ -929,14 +1318,7 @@ export function verifyAndHealHooks(worktreePath, opts = {}) {
929
1318
  const problems = describeHookProblems(before);
930
1319
  logWarning(`Hook completeness problem${problems.length === 1 ? '' : 's'} ` +
931
1320
  `(${problems.length}): ${problems.join(', ')} — regenerating from origin/${baseBranch}`);
932
- const genResult = spawnSync(process.execPath, [
933
- generatorScriptPath(),
934
- '--repo-root', worktreePath,
935
- '--dest', join(worktreePath, '.claude'),
936
- '--permission-from-git', `origin/${baseBranch}`,
937
- '--config-source', configSource,
938
- '--quiet',
939
- ], { cwd: worktreePath, encoding: 'utf-8', stdio: 'pipe' });
1321
+ const genResult = regeneratePermissionLayer(worktreePath, baseBranch, configSource);
940
1322
  if (genResult.status !== 0) {
941
1323
  logWarning(`Hook self-heal generator FAILED — session continues with UNHEALTHY guard${problems.length === 1 ? '' : 's'}: ` +
942
1324
  `${problems.join(', ')}` +
@@ -951,8 +1333,69 @@ export function verifyAndHealHooks(worktreePath, opts = {}) {
951
1333
  else {
952
1334
  logWarning(`Hook self-heal INCOMPLETE — still unhealthy after regeneration: ${describeHookProblems(after).join(', ')}. ` +
953
1335
  `Recover manually: node mx-agent-system/cli/scripts/generate-claude.mjs ` +
954
- `--repo-root ${worktreePath} --permission-from-git origin/${baseBranch}`);
1336
+ `--repo-root ${worktreePath} --permission-from-git origin/${baseBranch} ` +
1337
+ `--skip-behavioral-layer`);
1338
+ }
1339
+ }
1340
+ /**
1341
+ * Regenerate `.claude/` when a REGISTERED hook is present but behind
1342
+ * `origin/<baseBranch>` (#306).
1343
+ *
1344
+ * WHY THIS IS SEPARATE FROM verifyAndHealHooks. Completeness asks whether a
1345
+ * registered hook EXISTS; `checkHookCompleteness` returns complete for a file
1346
+ * that is present and stale, and `verifyAndHealHooks` returns early on complete.
1347
+ * So the remedy the staleness line printed, `mx-agent verify-hooks --heal`, did
1348
+ * nothing at all for the state it was printed about. Measured by the qa-tester
1349
+ * at 583ebf9 (PR #309): heal reported completeness OK and exit 0, and the same
1350
+ * STALE line printed again, twice.
1351
+ *
1352
+ * WHY IT IS NOT CALLED FROM verifyAndHealHooks. That function also runs on the
1353
+ * `mx-agent start` path (`start.ts:1300`), where `syncClaudeConfig`
1354
+ * (`claude.ts:1059`) has already regenerated `.claude/` unconditionally from
1355
+ * the same ref. Calling it there would add a second regeneration to every
1356
+ * session start in every worktree for a state that path has already fixed. This
1357
+ * is invoked from the `--heal` command only, which is where the ineffective
1358
+ * remedy was.
1359
+ *
1360
+ * COULD-NOT-COMPARE IS NOT HEALED. When the check cannot compare (no
1361
+ * `origin/<baseBranch>`, no git, an unusable config value) nothing is
1362
+ * regenerated and the outcome says so. Regenerating on an unreadable verdict
1363
+ * would rewrite the permission layer on no evidence.
1364
+ *
1365
+ * Never throws.
1366
+ */
1367
+ export function healStaleHooks(worktreePath, opts = {}) {
1368
+ const baseBranch = opts.baseBranch ?? 'main';
1369
+ const configSource = opts.configSource ?? 'mx-agent-system/agent-config';
1370
+ const base = { before: [], after: [], baseBranch };
1371
+ const before = checkHookStaleness(worktreePath, { baseBranch, configSource });
1372
+ if (before.verdict === 'COULD_NOT_COMPARE') {
1373
+ return { ...base, outcome: 'could-not-compare', detail: before.undetermined };
955
1374
  }
1375
+ if (before.verdict === 'FRESH')
1376
+ return { ...base, outcome: 'fresh', detail: [] };
1377
+ const staleNames = before.stale.map((h) => h.name);
1378
+ const gen = regeneratePermissionLayer(worktreePath, baseBranch, configSource);
1379
+ if (gen.status !== 0) {
1380
+ return {
1381
+ ...base, outcome: 'generator-failed', before: staleNames,
1382
+ after: staleNames, detail: gen.stderr ? [gen.stderr] : [],
1383
+ };
1384
+ }
1385
+ // Re-run the same comparison rather than trusting the generator's exit code:
1386
+ // the question is whether the deployed bytes now equal the source bytes, and
1387
+ // only the check answers that.
1388
+ const after = checkHookStaleness(worktreePath, { baseBranch, configSource });
1389
+ if (after.verdict === 'FRESH') {
1390
+ return { ...base, outcome: 'healed', before: staleNames, detail: [] };
1391
+ }
1392
+ if (after.verdict === 'COULD_NOT_COMPARE') {
1393
+ return { ...base, outcome: 'could-not-compare', before: staleNames, detail: after.undetermined };
1394
+ }
1395
+ return {
1396
+ ...base, outcome: 'still-stale', before: staleNames,
1397
+ after: after.stale.map((h) => h.name), detail: [],
1398
+ };
956
1399
  }
957
1400
  /**
958
1401
  * Flatten a HookCompletenessResult into a labeled, human-readable problem list
@@ -1184,6 +1627,29 @@ export async function launchClaudeSession(opts) {
1184
1627
  CLAUDE_WORKTREE_SLOT: String(slot),
1185
1628
  CLAUDE_WORKTREE_BRANCH: branch || '',
1186
1629
  CLAUDE_TEAM_NAME: teamName,
1630
+ // The test project, for a test team's session and for nothing else (#259).
1631
+ //
1632
+ // EMPTY FOR EVERY REAL TEAM, so their launches are byte-identical to before.
1633
+ // A test team's worktree is a checkout of a repository whose config names
1634
+ // project `mx-agent`, so without this the session would resolve `mx-agent`,
1635
+ // ask for a credential its roster does not hold, and be refused. The value
1636
+ // selects a client-side identity only: the service reads the project off
1637
+ // the token, never off a client assertion.
1638
+ ...testProjectEnv(teamName, resolveProjectConfig(loadProjectConfig(worktreePath)).projectSlug),
1639
+ // Runtime-neutral identity, in the shape the observability `sessions` table
1640
+ // is keyed on. Purely additive: the CLAUDE_* names above are what the hooks
1641
+ // read and are unchanged, so this adds variables and alters nothing.
1642
+ ...launchIdentityEnv({ teamName, worktreeName, branch }),
1643
+ // Native telemetry, and ONLY when an operator has configured an endpoint.
1644
+ // Empty block otherwise, so an un-opted-in fleet is byte-identical to before.
1645
+ // Claude Code only: Codex does not read these, which is why this sits here
1646
+ // rather than beside the identity block in the shared module.
1647
+ ...otelEnv(sessionIdentity({ teamName, worktreeName, branch }), {
1648
+ endpoint: getConfigValue(OTEL_ENDPOINT_KEY),
1649
+ token: getConfigValue(OTEL_TOKEN_KEY),
1650
+ protocol: getConfigValue(OTEL_PROTOCOL_KEY),
1651
+ env: process.env,
1652
+ }),
1187
1653
  };
1188
1654
  console.log();
1189
1655
  console.log(chalk.bold(' Starting Claude Code...'));