@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
@@ -0,0 +1,546 @@
1
+ /**
2
+ * git-identity -- the per-team git identity `mx-agent provision` writes into the
3
+ * worktree it is provisioning, and the values every commit from that worktree
4
+ * then carries (#440 part A).
5
+ *
6
+ * WHAT THIS FIXES. Every team's worktree here is a LINKED worktree of one shared
7
+ * repository, and every one of them resolved `user.name` from the single file
8
+ * `/workspace/.git/config`. Eight worktrees, one identity, so `git log` could not
9
+ * say which team produced a commit. The design memory
10
+ * `0aaa2f4f-5614-442b-afb5-47c8aa600ea1` and `docs/agent-github-identity-setup.md`
11
+ * both prescribed plain `git config user.name <slug>` for this, which is the one
12
+ * mechanism that makes it WORSE: from a linked worktree that writes the shared
13
+ * file, so the first team to provision reassigns the identity of every other
14
+ * team's live session, and the next team to provision overwrites it again.
15
+ *
16
+ * SO `--worktree` IS THE MECHANISM AND PLAIN `git config` IS FORBIDDEN HERE
17
+ * (issue #440, comment 5559622174, which supersedes the environment-variable
18
+ * choice in comment 5559576380). `git config --worktree` writes
19
+ * `$GIT_COMMON_DIR/worktrees/<name>/config.worktree`, which only that worktree
20
+ * reads. Nothing in this module ever runs `git config` without `--worktree`
21
+ * except to READ, and the two read call sites are named in their own comments.
22
+ *
23
+ * `--worktree` NEEDS `extensions.worktreeConfig=true` ON THE SHARED REPOSITORY,
24
+ * AND THIS MODULE NEVER ENABLES IT. Enabling it is a change to state shared by
25
+ * every worktree on the machine, it is the bootstrap lead's to make after the
26
+ * pre-flight check below, and a provisioning run is not the place to make a
27
+ * change whose reach is every other team. When the extension is off this module
28
+ * WRITES NOTHING and returns a refusal naming the command an operator must run.
29
+ *
30
+ * That refusal is belt on top of braces rather than the only guard. Measured in
31
+ * a throwaway repository on git 2.49.0, 2026-09-06: with the extension off,
32
+ * `git config --worktree user.name alpha` exits 128 with `fatal: --worktree
33
+ * cannot be used with multiple working trees unless the config extension
34
+ * worktreeConfig is enabled`, and the shared config is byte-identical
35
+ * afterwards. Git itself fails closed here; there is no silent fall-through to
36
+ * the shared file. The detection exists so an operator reads one sentence with a
37
+ * remedy instead of a git fatal, not because the write would otherwise land
38
+ * somewhere dangerous.
39
+ *
40
+ * IT IS ATTRIBUTION, NOT AUTHENTICATION. Any session can set any name, so a
41
+ * commit's author records which worktree produced it and proves nothing about
42
+ * who that session was. The same caveat the design records about the app setting
43
+ * a passing check without doing the work applies here, and it should survive
44
+ * into every document that describes this (#440, comment 5559576380, "Should Fix
45
+ * items").
46
+ *
47
+ * NOTHING HERE THROWS. Every failure is a returned outcome with a `kind`, for
48
+ * the reason `lib/claude.ts:549-557` gives about the behavioral block: an
49
+ * identity that could not be written degrades attribution and does not endanger
50
+ * the worktree, so it warns and continues rather than refusing a creation that
51
+ * has already made a worktree, a catalog entry and three memories.
52
+ */
53
+ import { spawnSync } from 'child_process';
54
+ import { isValidProjectSlug } from './slug.js';
55
+ // One-line collapse and length cap for a git-supplied value. `behavioral-injection`
56
+ // imports nothing local, so this direction cannot cycle; `lib/claude.ts` imports
57
+ // this module and must not be imported back.
58
+ import { sanitizeForMessage } from './behavioral-injection.js';
59
+ /**
60
+ * The domain every team's git email is under. Resolves to no GitHub account by
61
+ * design: a `Co-authored-by` trailer naming it persists as text in the commit
62
+ * body and shows as an unlinked co-author, which is what `git log` attribution
63
+ * needs and is NOT a GitHub identity (#440, comment 5555802652).
64
+ */
65
+ export const TEAM_EMAIL_DOMAIN = 'mx-agent.local';
66
+ /** The two config keys this module owns. Nothing else is written. */
67
+ export const IDENTITY_KEYS = ['user.name', 'user.email'];
68
+ /** `<slug>@mx-agent.local`. */
69
+ export function teamGitEmail(slug) {
70
+ return `${slug}@${TEAM_EMAIL_DOMAIN}`;
71
+ }
72
+ /**
73
+ * The trailer that carries this team's attribution through a squash merge.
74
+ *
75
+ * ONE DEFINITION, for the reason `behavioralPointerLine` states about the
76
+ * pointer line (`lib/claude.ts:735-745`): the generator that writes the
77
+ * instruction into `CLAUDE.local.md` and any later reader of a commit body would
78
+ * otherwise hold two copies of the literal and drift silently.
79
+ *
80
+ * GitHub aggregates `Co-authored-by` trailers from a branch's commits into the
81
+ * squash commit body rather than dropping them, measured on this repository's
82
+ * own `main`: 12 of the last 60 commits carry trailers, every one of them a
83
+ * squash merge, and two carry 7 and 9 (#440, comment 5555802652). That is what
84
+ * makes the trailer the durable half of the attribution, since the branch-level
85
+ * author does not reach `main` under a squash.
86
+ */
87
+ export function teamCoAuthorTrailer(slug) {
88
+ return `Co-authored-by: ${slug} <${teamGitEmail(slug)}>`;
89
+ }
90
+ /**
91
+ * Run git and return its trimmed stdout, or null when it did not exit 0.
92
+ *
93
+ * ARRAY FORM, NEVER A SHELL STRING. Every value this module passes git comes
94
+ * from a slug `isValidProjectSlug` accepted or from a path the caller resolved,
95
+ * and `spawnSync` with an argv array means neither is ever parsed by a shell.
96
+ * The slug check also guarantees a leading `[a-z]` (`lib/slug.ts:22`), so a
97
+ * value can never be read by git as an option.
98
+ */
99
+ function git(args, cwd) {
100
+ const r = spawnSync('git', args, {
101
+ cwd,
102
+ encoding: 'utf-8',
103
+ stdio: ['ignore', 'pipe', 'pipe'],
104
+ });
105
+ if (r.error || r.status !== 0)
106
+ return null;
107
+ return (r.stdout ?? '').trim();
108
+ }
109
+ /**
110
+ * RUN git once and report whether it succeeded, with its stderr when it did not.
111
+ *
112
+ * Named for the fact that it EXECUTES: the write path calls it, so a reader must
113
+ * not take it for a formatter over a result someone else produced. The stderr is
114
+ * collapsed to one line and bounded at 240 characters before it can reach a
115
+ * terminal, the same defence `sanitizeForMessage` gives elsewhere: git's message
116
+ * is three lines here and an operator reads it inside a row detail.
117
+ */
118
+ function runGit(args, cwd) {
119
+ const r = spawnSync('git', args, {
120
+ cwd,
121
+ encoding: 'utf-8',
122
+ stdio: ['ignore', 'pipe', 'pipe'],
123
+ });
124
+ if (!r.error && r.status === 0)
125
+ return { ok: true, err: '' };
126
+ const text = r.error ? r.error.message : (r.stderr ?? '');
127
+ return { ok: false, err: text.replace(/\s+/g, ' ').trim().slice(0, 240) };
128
+ }
129
+ // ── The pre-flight check ─────────────────────────────────────────────────────
130
+ /**
131
+ * The three settings that decide whether enabling `extensions.worktreeConfig` on
132
+ * a shared repository is additive or needs a manual migration first.
133
+ *
134
+ * FROM GIT'S OWN DOCUMENTATION, not from a test that happened to pass.
135
+ * `git-worktree(1)`, CONFIGURATION FILE: "Note that in this file, the exception
136
+ * for `core.bare` and `core.worktree` is gone. If they exist in
137
+ * `$GIT_DIR/config`, you must move them to the `config.worktree` of the main
138
+ * worktree. `core.bare` should not be shared if the value is `core.bare=true`.
139
+ * `core.sparseCheckout` should not be shared, unless you are sure you always use
140
+ * sparse checkout for all worktrees."
141
+ *
142
+ * The bootstrap lead's own test of additivity ran in a repository where all
143
+ * three were absent, which is why it read as unconditional (#440, comment
144
+ * 5559669566). This function is the condition stated as a check.
145
+ */
146
+ export const PREFLIGHT_KEYS = ['core.bare', 'core.worktree', 'core.sparseCheckout'];
147
+ /**
148
+ * Read the three settings and say whether enabling the extension is additive
149
+ * right now.
150
+ *
151
+ * READ-ONLY AND RUN AT THE MOMENT OF USE. It is not a fact established once: any
152
+ * team's change could set one of these between a plan and its implementation,
153
+ * and nothing would announce it (#440, comment 5559669566, "They are checked
154
+ * again at implementation time because they can change").
155
+ *
156
+ * `--local` deliberately. The question is what is in THIS repository's config,
157
+ * not what a global or system file also supplies: the migration git describes
158
+ * is a migration of `$GIT_DIR/config`, and a `core.bare` inherited from a global
159
+ * file is not in that file and is not what needs moving.
160
+ */
161
+ export function checkWorktreeConfigPreflight(repoPath) {
162
+ // Cheapest proof that this is a git repository at all, and the one call whose
163
+ // failure means every reading below would be meaningless rather than absent.
164
+ const inRepo = git(['-C', repoPath, 'rev-parse', '--git-dir']);
165
+ if (inRepo === null) {
166
+ return {
167
+ safe: false,
168
+ readings: [],
169
+ alreadyEnabled: false,
170
+ couldNotRun: `${repoPath} is not a readable git repository`,
171
+ };
172
+ }
173
+ const alreadyEnabled = readWorktreeConfigExtension(repoPath) === true;
174
+ const readings = PREFLIGHT_KEYS.map((key) => {
175
+ const value = git(['-C', repoPath, 'config', '--local', '--get', key]);
176
+ if (key === 'core.bare') {
177
+ // Unset or false is the shareable value; `true` is the one git names.
178
+ const safe = value === null || value.toLowerCase() === 'false';
179
+ return {
180
+ key,
181
+ value,
182
+ safe,
183
+ why: safe
184
+ ? 'unset or false, which git names as safe to share'
185
+ : 'core.bare=true must move to the main worktree\'s config.worktree before the extension is enabled',
186
+ };
187
+ }
188
+ if (key === 'core.worktree') {
189
+ const safe = value === null;
190
+ return {
191
+ key,
192
+ value,
193
+ safe,
194
+ why: safe
195
+ ? 'unset'
196
+ : 'a value must move to the main worktree\'s config.worktree before the extension is enabled',
197
+ };
198
+ }
199
+ const safe = value === null;
200
+ return {
201
+ key,
202
+ value,
203
+ safe,
204
+ why: safe
205
+ ? 'unset'
206
+ : 'set, so it would stop being shared: enable only if every worktree uses sparse checkout',
207
+ };
208
+ });
209
+ return {
210
+ safe: readings.every((r) => r.safe),
211
+ readings,
212
+ alreadyEnabled,
213
+ couldNotRun: null,
214
+ };
215
+ }
216
+ /** One line per reading, for a message or a report. */
217
+ export function describePreflight(p) {
218
+ if (p.couldNotRun)
219
+ return `could not run: ${p.couldNotRun}`;
220
+ return p.readings.map((r) => `${r.key}=${r.value ?? '<unset>'} (${r.safe ? 'ok' : 'BLOCKS'})`).join(', ');
221
+ }
222
+ // ── Reading the extension and the worktree's own identity ────────────────────
223
+ /**
224
+ * Whether `extensions.worktreeConfig` is on, or null when the repository could
225
+ * not be read.
226
+ *
227
+ * A READ WITHOUT `--worktree`, and one of only two in this module. The extension
228
+ * lives in the shared config by definition, so there is nothing per-worktree to
229
+ * ask for, and a read cannot write.
230
+ */
231
+ export function readWorktreeConfigExtension(repoOrWorktreePath) {
232
+ const raw = git(['-C', repoOrWorktreePath, 'config', '--type=bool', '--get', 'extensions.worktreeConfig']);
233
+ if (raw === null) {
234
+ // Exit 1 for "unset" and exit 128 for "not a repository" are two different
235
+ // answers, and only the second is unreadable. Distinguish them, so a
236
+ // non-repository is never reported as a repository with the extension off.
237
+ return git(['-C', repoOrWorktreePath, 'rev-parse', '--git-dir']) === null ? null : false;
238
+ }
239
+ return raw === 'true';
240
+ }
241
+ /**
242
+ * What this worktree's own config.worktree holds, read back from disk.
243
+ *
244
+ * THE ARTIFACT, NOT THE WRITE'S RETURN VALUE. Completion row 15 calls this for
245
+ * the reason row 14 re-reads `dist/index.js` rather than trusting the build
246
+ * result (`commands/create.ts:3377-3380`): the row reports what exists now, so a
247
+ * value written by this run and removed since is not an asserted row, and a
248
+ * `--recheck`, which writes nothing, gets a real answer from the same function.
249
+ */
250
+ export function readTeamGitIdentity(worktreePath) {
251
+ const extensionEnabled = readWorktreeConfigExtension(worktreePath) === true;
252
+ if (!extensionEnabled) {
253
+ return { name: null, email: null, effectiveNameOrigin: null, extensionEnabled: false };
254
+ }
255
+ const name = git(['-C', worktreePath, 'config', '--worktree', '--get', 'user.name']);
256
+ const email = git(['-C', worktreePath, 'config', '--worktree', '--get', 'user.email']);
257
+ // The second read without `--worktree`. It asks which FILE the value a commit
258
+ // would use comes from, which is the only way to tell a per-worktree value
259
+ // from the shared fallback that happens to hold the same string.
260
+ //
261
+ // `--show-origin` prints `<type>:<path>\t<value>`, where the type is `file`,
262
+ // `blob`, `command line`, `standard input` or `submodule-blob`. Only `file` is
263
+ // reachable here and only `file` is unwrapped: any other type is returned as
264
+ // git printed it, so it cannot end in `config.worktree` and the caller reads
265
+ // it as "not this worktree's own file" rather than as a path.
266
+ const origin = git(['-C', worktreePath, 'config', '--show-origin', '--get', 'user.name']);
267
+ const originField = origin === null ? null : (origin.split('\t')[0] ?? null);
268
+ const effectiveNameOrigin = originField !== null && originField.startsWith('file:')
269
+ ? originField.slice('file:'.length)
270
+ : originField;
271
+ return { name, email, effectiveNameOrigin, extensionEnabled };
272
+ }
273
+ /**
274
+ * Read this worktree's git identity and say whether it is this team's own.
275
+ *
276
+ * READS THE ARTIFACT, NOT A WRITE'S RETURN VALUE, for the reason
277
+ * `readTeamGitIdentity`'s header gives: the answer must be the same for a fresh
278
+ * provision, a resume, a `--recheck` that writes nothing, and an
279
+ * `mx-agent start` days later that never calls the writer at all. A state
280
+ * threaded down from `writeTeamGitIdentity` would be available on exactly one
281
+ * of those four paths, and `mx-agent start` regenerates `CLAUDE.local.md` on
282
+ * every session.
283
+ *
284
+ * The isolation criterion is the strict one row 15 already applied: the name and
285
+ * email must match the team AND the effective `user.name` must resolve from a
286
+ * `config.worktree`. A shared config that happens to hold the team's name is not
287
+ * isolation, and accepting it would report success for the exact defect #440
288
+ * exists to prevent (#440, comment 5555843161).
289
+ */
290
+ export function describeTeamGitIdentityState(worktreePath, slug) {
291
+ const base = {
292
+ name: null,
293
+ email: null,
294
+ effectiveAuthor: null,
295
+ effectiveNameOrigin: null,
296
+ };
297
+ if (!worktreePath) {
298
+ return {
299
+ ...base,
300
+ isolated: false,
301
+ code: 'no-worktree-path',
302
+ couldNotRun: true,
303
+ reason: 'no worktree path to read the per-worktree git config from',
304
+ };
305
+ }
306
+ const extension = readWorktreeConfigExtension(worktreePath);
307
+ if (extension === null) {
308
+ return {
309
+ ...base,
310
+ isolated: false,
311
+ code: 'unreadable',
312
+ couldNotRun: true,
313
+ reason: `${worktreePath} is not a git repository this run can read`,
314
+ };
315
+ }
316
+ // The author a commit would carry is read whatever the extension holds: with
317
+ // the extension off it is the whole answer, and with it on it is what proves
318
+ // the value comes from this worktree's own file.
319
+ const effective = readEffectiveAuthor(worktreePath);
320
+ if (extension === false) {
321
+ return {
322
+ ...base,
323
+ ...effective,
324
+ isolated: false,
325
+ code: 'extension-disabled',
326
+ couldNotRun: true,
327
+ reason: 'extensions.worktreeConfig is not enabled on the shared repository, so git refuses '
328
+ + '--worktree and no per-worktree identity exists to read',
329
+ };
330
+ }
331
+ const read = readTeamGitIdentity(worktreePath);
332
+ const expectedEmail = teamGitEmail(slug);
333
+ const fromOwnFile = read.effectiveNameOrigin !== null && read.effectiveNameOrigin.endsWith('config.worktree');
334
+ if (read.name === slug && read.email === expectedEmail && fromOwnFile) {
335
+ return {
336
+ isolated: true,
337
+ code: 'isolated',
338
+ couldNotRun: false,
339
+ name: read.name,
340
+ email: read.email,
341
+ effectiveAuthor: effective.effectiveAuthor,
342
+ effectiveNameOrigin: read.effectiveNameOrigin,
343
+ reason: `resolved from ${read.effectiveNameOrigin}`,
344
+ };
345
+ }
346
+ if (read.name === null && read.email === null) {
347
+ return {
348
+ ...base,
349
+ ...effective,
350
+ isolated: false,
351
+ code: 'unset',
352
+ couldNotRun: false,
353
+ reason: 'this worktree sets no user.name or user.email of its own',
354
+ };
355
+ }
356
+ const wrong = [];
357
+ if (read.name !== slug) {
358
+ wrong.push(`user.name is ${read.name === null ? 'unset for this worktree' : JSON.stringify(read.name)}`);
359
+ }
360
+ if (read.email !== expectedEmail) {
361
+ wrong.push(`user.email is ${read.email === null ? 'unset for this worktree' : JSON.stringify(read.email)}`);
362
+ }
363
+ if (read.name === slug && read.email === expectedEmail && !fromOwnFile) {
364
+ wrong.push(`the values match but the effective user.name resolves from ${read.effectiveNameOrigin ?? 'an unreadable origin'}, `
365
+ + 'not this worktree\'s own config.worktree, so it is the shared identity rather than this team\'s');
366
+ }
367
+ return {
368
+ isolated: false,
369
+ code: 'mismatch',
370
+ couldNotRun: false,
371
+ name: read.name,
372
+ email: read.email,
373
+ effectiveAuthor: effective.effectiveAuthor,
374
+ effectiveNameOrigin: read.effectiveNameOrigin,
375
+ reason: sanitizeOneLine(wrong.join('; ')),
376
+ };
377
+ }
378
+ /**
379
+ * `<name> <<email>>` git would put on a commit made here now, with the file the
380
+ * name came from.
381
+ *
382
+ * A READ WITHOUT `--worktree`, the third and last in this module, and the point
383
+ * of it: it asks what a commit ACTUALLY gets, which with the extension off is
384
+ * the shared identity and is the fact the refused block has to state.
385
+ *
386
+ * Both values are sanitized here rather than at each sink. They come out of a
387
+ * config file this command does not own, they end up in `CLAUDE.local.md`, and
388
+ * `git config` can store a value containing a newline.
389
+ */
390
+ function readEffectiveAuthor(worktreePath) {
391
+ const name = git(['-C', worktreePath, 'config', '--get', 'user.name']);
392
+ const email = git(['-C', worktreePath, 'config', '--get', 'user.email']);
393
+ const origin = git(['-C', worktreePath, 'config', '--show-origin', '--get', 'user.name']);
394
+ const originField = origin === null ? null : (origin.split('\t')[0] ?? null);
395
+ const effectiveNameOrigin = originField !== null && originField.startsWith('file:')
396
+ ? originField.slice('file:'.length)
397
+ : originField;
398
+ if (name === null && email === null)
399
+ return { effectiveAuthor: null, effectiveNameOrigin };
400
+ return {
401
+ effectiveAuthor: sanitizeOneLine(`${name ?? '<unset>'} <${email ?? '<unset>'}>`),
402
+ effectiveNameOrigin,
403
+ };
404
+ }
405
+ /** One line, bounded, with C0/C1 replaced. The same defence `runGit` applies to stderr. */
406
+ function sanitizeOneLine(value) {
407
+ return sanitizeForMessage(value.replace(/\s+/g, ' ').trim(), 240);
408
+ }
409
+ /**
410
+ * Write `user.name` and `user.email` for ONE worktree, or refuse and write
411
+ * nothing.
412
+ *
413
+ * FOUR GUARDS RUN BEFORE ANY WRITE, and each one exists because the failure it
414
+ * prevents is silent:
415
+ *
416
+ * 1. THE SLUG IS RE-VALIDATED. `isValidProjectSlug` is the same rule the
417
+ * coordination service applies (`lib/slug.ts:1-19`), and the caller already
418
+ * applies it, and it runs again here for the reason `writeCodeContextFile`
419
+ * re-validates its four values (`commands/create.ts:5302-5306`): a value
420
+ * reaching this point that no earlier gate covered is a bug worth naming
421
+ * rather than passing to git.
422
+ * 2. THE PATH MUST BE A LINKED WORKTREE. `git rev-parse --absolute-git-dir`
423
+ * equal to `--git-common-dir` is the main checkout, where `--worktree`
424
+ * writes `$GIT_COMMON_DIR/config.worktree` — a file inside the shared `.git`
425
+ * that only the main worktree reads. Measured 2026-09-06: writing there
426
+ * leaves every linked worktree's resolution untouched, so it is not the
427
+ * eight-worktree defect, and provisioning still has no business setting an
428
+ * identity on the operator's own checkout.
429
+ * 3. THE EXTENSION MUST BE ON, and this function never turns it on. See the
430
+ * module header.
431
+ * 4. THE SHARED CONFIG IS SNAPSHOTTED BEFORE AND AFTER. This is the control
432
+ * that would catch the original defect if it ever came back by a route the
433
+ * three guards above do not cover: two `--local --get` reads, compared. A
434
+ * change across a write that only used `--worktree` is not something this
435
+ * module can cause, which is exactly why observing one is worth a loud
436
+ * refusal rather than a silent pass.
437
+ *
438
+ * IDEMPOTENT. A resume, and a re-provision of a team that already has an
439
+ * identity, both write the same two values again and report `written`. There is
440
+ * no separate "already correct" outcome, because the operator's next action is
441
+ * the same either way and a second kind would only be another branch to test.
442
+ */
443
+ export function writeTeamGitIdentity(opts) {
444
+ const { worktreePath, slug } = opts;
445
+ // Guard 1.
446
+ if (!isValidProjectSlug(slug)) {
447
+ return {
448
+ kind: 'refused',
449
+ code: 'invalid-slug',
450
+ // JSON.stringify for the reason `invalidProjectSlugMessage` gives
451
+ // (`lib/slug.ts:44`, CWE-117): the value reaches a terminal line.
452
+ detail: `team slug ${JSON.stringify(slug)} is not a valid slug, so no git identity was written`,
453
+ };
454
+ }
455
+ // Guard 2.
456
+ const gitDir = git(['-C', worktreePath, 'rev-parse', '--absolute-git-dir']);
457
+ const commonDir = git(['-C', worktreePath, 'rev-parse', '--path-format=absolute', '--git-common-dir']);
458
+ if (gitDir === null || commonDir === null) {
459
+ return {
460
+ kind: 'refused',
461
+ code: 'not-a-worktree',
462
+ detail: `${worktreePath} is not a git worktree this run can read, so no git identity was written`,
463
+ };
464
+ }
465
+ if (gitDir === commonDir) {
466
+ return {
467
+ kind: 'refused',
468
+ code: 'main-worktree',
469
+ detail: `${worktreePath} is the main checkout, not a linked worktree. A per-team identity is written `
470
+ + 'only into a linked worktree, so nothing was written',
471
+ };
472
+ }
473
+ // Guard 3.
474
+ const extension = readWorktreeConfigExtension(worktreePath);
475
+ if (extension !== true) {
476
+ const preflight = checkWorktreeConfigPreflight(commonDir);
477
+ const remedy = preflight.safe
478
+ ? `Enable it once on the shared repository: git -C ${commonDir} config extensions.worktreeConfig true`
479
+ : `Enabling it needs a migration first (git-worktree(1), CONFIGURATION FILE): ${describePreflight(preflight)}`;
480
+ return {
481
+ kind: 'refused',
482
+ code: 'extension-disabled',
483
+ detail: (extension === null
484
+ ? 'extensions.worktreeConfig could not be read on the shared repository'
485
+ : 'extensions.worktreeConfig is not enabled on the shared repository')
486
+ + `, so git refuses --worktree and this run wrote NO identity for ${slug}. `
487
+ + 'Plain `git config` is not the fallback: from a linked worktree it writes the shared config '
488
+ + `and reassigns every worktree's identity at once (#440). ${remedy}. `
489
+ + `Pre-flight: ${describePreflight(preflight)}`,
490
+ };
491
+ }
492
+ // Guard 4, first half.
493
+ const sharedBefore = readSharedIdentity(commonDir);
494
+ const name = slug;
495
+ const email = teamGitEmail(slug);
496
+ for (const [key, value] of [['user.name', name], ['user.email', email]]) {
497
+ // THE ONLY WRITES IN THIS MODULE, and both carry `--worktree`.
498
+ const run = runGit(['-C', worktreePath, 'config', '--worktree', key, value]);
499
+ if (!run.ok) {
500
+ return {
501
+ kind: 'refused',
502
+ code: 'write-failed',
503
+ detail: `git config --worktree ${key} failed for ${slug}: ${run.err}`,
504
+ };
505
+ }
506
+ }
507
+ // Guard 4, second half.
508
+ const sharedAfter = readSharedIdentity(commonDir);
509
+ if (sharedBefore.name !== sharedAfter.name || sharedBefore.email !== sharedAfter.email) {
510
+ return {
511
+ kind: 'refused',
512
+ code: 'shared-config-changed',
513
+ detail: `the shared repository's user.name/user.email changed while writing ${slug}'s per-worktree `
514
+ + `identity (${sharedBefore.name ?? '<unset>'}/${sharedBefore.email ?? '<unset>'} -> `
515
+ + `${sharedAfter.name ?? '<unset>'}/${sharedAfter.email ?? '<unset>'}). This run wrote only `
516
+ + `--worktree values and cannot have caused it. Inspect ${commonDir}/config before relying on `
517
+ + 'any worktree\'s identity',
518
+ };
519
+ }
520
+ // READ BACK WHAT WAS WRITTEN before claiming it (AGENTS.md, "Tools that fail
521
+ // silently"). An exit 0 says the call succeeded, not that the stored value is
522
+ // the one asked for.
523
+ const readBack = readTeamGitIdentity(worktreePath);
524
+ if (readBack.name !== name || readBack.email !== email) {
525
+ return {
526
+ kind: 'refused',
527
+ code: 'write-failed',
528
+ detail: `wrote ${name} <${email}> for this worktree and read back `
529
+ + `${readBack.name ?? '<unset>'} <${readBack.email ?? '<unset>'}>`,
530
+ };
531
+ }
532
+ return { kind: 'written', name, email, originFile: readBack.effectiveNameOrigin };
533
+ }
534
+ /**
535
+ * The shared repository's own `user.name` and `user.email`.
536
+ *
537
+ * `--local` against the common directory, so it reads the one file the original
538
+ * defect would have written and nothing that a per-worktree file supplies.
539
+ */
540
+ function readSharedIdentity(commonDir) {
541
+ return {
542
+ name: git(['-C', commonDir, 'config', '--local', '--get', 'user.name']),
543
+ email: git(['-C', commonDir, 'config', '--local', '--get', 'user.email']),
544
+ };
545
+ }
546
+ //# sourceMappingURL=git-identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-identity.js","sourceRoot":"","sources":["../../src/lib/git-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,oFAAoF;AACpF,iFAAiF;AACjF,6CAA6C;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAElD,qEAAqE;AACrE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,WAAW,EAAE,YAAY,CAAU,CAAC;AAElE,+BAA+B;AAC/B,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,GAAG,IAAI,IAAI,iBAAiB,EAAE,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,U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AI,QAAQ,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;QACvD,OAAO;YACL,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,cAAc;YACpB,MAAM,EACJ,SAAS,IAAI,KAAK,KAAK,oCAAoC;kBACzD,GAAG,QAAQ,CAAC,IAAI,IAAI,SAAS,KAAK,QAAQ,CAAC,KAAK,IAAI,SAAS,GAAG;SACrE,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,mBAAmB,EAAE,CAAC;AACpF,CAAC;AAED;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,SAAiB;IAC3C,OAAO;QACL,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;QACvE,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;KAC1E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * hook-staleness.ts — is a MATERIALISED hook behind its source? (#306)
3
+ *
4
+ * PROBLEM. `hook-completeness.ts` answers "is a registered hook PRESENT". A hook
5
+ * that is present but STALE passes that check and is never reported. The
6
+ * measured harm (v23 runtime probe, 2026-08-30): the pre-#298
7
+ * `coordination-brief.sh` prints nothing on any stream and exits 0 when `az` is
8
+ * unavailable, so a session starts believing it has no coordination. The
9
+ * registration strings in `agent-config/settings.json` run a present hook
10
+ * directly (`[ -f "$H" ] && [ ! -L "$H" ] && exec bash "$H"`) and reach
11
+ * `hook-launcher.sh` only when the file is MISSING, so the launcher's auto-heal
12
+ * never sees this state. Before this module the only detector was
13
+ * `mx-agent doctor`, run by hand.
14
+ *
15
+ * WHAT IT COMPARES. The bytes of each materialised `.claude/hooks/<name>`
16
+ * against the bytes of `origin/<baseBranch>:<configSource>/hooks/<name>` — the
17
+ * same reference `verifyAndHealHooks` materialises from (claude.ts:1236-1287)
18
+ * and the same one `reportConfigFidelity` reads (config-fidelity.ts). One
19
+ * reference point, not two: #247's false-DRIFT mechanism needs a base layer at
20
+ * `origin/main` AND an overlay at the worktree's own base, and this check has
21
+ * only the first, so it is immune to #247 by construction.
22
+ *
23
+ * NO FETCH. A checker must not perform network I/O as a side effect
24
+ * (config-fidelity.ts:862-866). When `origin/<baseBranch>` is not present
25
+ * locally the verdict is COULD_NOT_COMPARE with a reason that names the fetch —
26
+ * never FRESH. Passed, failed and could-not-run are three outcomes.
27
+ *
28
+ * WHICH FILES. The candidate names are the intersection of (a) the entries of
29
+ * the worktree's `.claude/hooks/` and (b) the hook basenames the worktree's
30
+ * `.claude/settings.json` REGISTERS. Nothing else is read. The registered set is
31
+ * what bounds the printed file name to a reviewed value: anyone who can write
32
+ * into `.claude/hooks/` can otherwise choose the text this check prints into a
33
+ * session (#306 criterion 4).
34
+ *
35
+ * WHERE THE TWO SETTINGS COME FROM. `baseBranch` and `configSource` are read
36
+ * from `mx-agent.config.json` at the worktree path. That file is absent in most
37
+ * worktrees, and the defaults it falls back to (`main` and
38
+ * `mx-agent-system/agent-config`) are the intended answer for that case, not a
39
+ * degraded one: they are the same pair every other caller defaults to, and a
40
+ * worktree that has no project config is a worktree tracking the repository's
41
+ * own layout. `baseBranch` is checked against BASE_BRANCH_RE before use,
42
+ * because it is a worktree-writable value that would otherwise be printed
43
+ * verbatim into a session.
44
+ *
45
+ * SPAWN BUDGET. One `git cat-file --batch` for the whole set in the common
46
+ * (fresh) case, plus one `git hash-object` only when something is stale. The
47
+ * SessionStart budget is 300 ms for the whole command (#306 criterion 1d); a
48
+ * per-file `git show` would be 44 processes and would not meet it.
49
+ */
50
+ export type HookStalenessVerdict = 'FRESH' | 'STALE' | 'COULD_NOT_COMPARE';
51
+ export interface StaleHook {
52
+ /** Basename under `.claude/hooks/`. Always matches HOOK_NAME_RE. */
53
+ name: string;
54
+ /** `git hash-object` of the deployed file. */
55
+ deployedOid: string;
56
+ /** Object id of `origin/<baseBranch>:<configSource>/hooks/<name>`. */
57
+ sourceOid: string;
58
+ }
59
+ export interface HookStalenessResult {
60
+ verdict: HookStalenessVerdict;
61
+ /** The branch the comparison ran against, for the caller's message. */
62
+ baseBranch: string;
63
+ /**
64
+ * The 40-character commit id `origin/<baseBranch>` resolved to, when it
65
+ * resolved at all. The whole verdict rests on that one local ref, which no
66
+ * fetch refreshed, so a reader who wants to check the claim before running
67
+ * the remedy needs to know which commit it was compared against. Absent when
68
+ * the check bailed before the ref probe.
69
+ */
70
+ anchor?: string;
71
+ /** How many hooks were actually byte-compared. */
72
+ compared: number;
73
+ /** Deployed hooks whose bytes differ from the source. */
74
+ stale: StaleHook[];
75
+ /**
76
+ * Why a comparison could not be made. Non-empty means the FRESH answer is not
77
+ * available for at least part of the set — the caller must not report fresh.
78
+ */
79
+ undetermined: string[];
80
+ }
81
+ /**
82
+ * Byte-compare every registered, materialised hook against
83
+ * `origin/<baseBranch>`. Never throws: every failure becomes an `undetermined`
84
+ * reason and the COULD_NOT_COMPARE verdict.
85
+ *
86
+ * `opts.path` is the worktree, and the project config is read from THAT
87
+ * directory rather than through `findProjectRoot()`, which ascends to the main
88
+ * worktree. The check reports on the worktree it runs in, and it must not read
89
+ * a directory outside it.
90
+ */
91
+ export declare function checkHookStaleness(worktreePath: string, opts?: {
92
+ baseBranch?: string;
93
+ configSource?: string;
94
+ }): HookStalenessResult;
95
+ //# sourceMappingURL=hook-staleness.d.ts.map