@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,127 @@
1
+ import { describe, it, expect, afterAll } from 'vitest';
2
+ import { mkdtempSync, mkdirSync, cpSync, rmSync, writeFileSync, symlinkSync, lstatSync, existsSync, readdirSync } from 'fs';
3
+ import { join, dirname } from 'path';
4
+ import { tmpdir } from 'os';
5
+ import { spawnSync } from 'child_process';
6
+ import { checkConfigFidelity } from '../lib/config-fidelity.js';
7
+ const FIXTURES = join(__dirname, 'fixtures', 'config-fidelity');
8
+ const temps = [];
9
+ afterAll(() => { for (const t of temps)
10
+ rmSync(t, { recursive: true, force: true }); });
11
+ function git(root, ...args) {
12
+ const r = spawnSync('git', ['-c', 'user.email=t@e.com', '-c', 'user.name=t', ...args], { cwd: root, encoding: 'utf-8' });
13
+ if (r.status !== 0)
14
+ throw new Error(`git ${args.join(' ')}: ${r.stderr}`);
15
+ }
16
+ function build() {
17
+ const root = mkdtempSync(join(tmpdir(), 'sec313-'));
18
+ temps.push(root);
19
+ const cfg = join(root, 'mx-agent-system', 'agent-config');
20
+ mkdirSync(dirname(cfg), { recursive: true });
21
+ cpSync(join(FIXTURES, 'clean', 'source'), cfg, { recursive: true });
22
+ cpSync(join(FIXTURES, 'clean', 'worktree', '.claude'), join(root, '.claude'), { recursive: true });
23
+ git(root, 'init', '-q', '-b', 'main');
24
+ git(root, 'add', '.');
25
+ git(root, 'commit', '-q', '-m', 'init');
26
+ git(root, 'update-ref', 'refs/remotes/origin/main', 'HEAD');
27
+ return { root, cfg };
28
+ }
29
+ /** Commit `relPath` inside agent-config as a symlink to `target`, then restore an HONEST working tree. */
30
+ function commitSymlinkAtOriginOnly(root, cfg, relPath, target) {
31
+ const pristine = join(root, 'pristine');
32
+ cpSync(cfg, pristine, { recursive: true });
33
+ const p = join(cfg, relPath);
34
+ rmSync(p, { recursive: true, force: true });
35
+ symlinkSync(target, p);
36
+ git(root, 'add', '-A');
37
+ git(root, 'commit', '-q', '-m', `symlink ${relPath}`);
38
+ git(root, 'update-ref', 'refs/remotes/origin/main', 'HEAD');
39
+ rmSync(cfg, { recursive: true, force: true });
40
+ cpSync(pristine, cfg, { recursive: true });
41
+ rmSync(pristine, { recursive: true, force: true });
42
+ expect(lstatSync(join(cfg, relPath)).isSymbolicLink(), `working tree ${relPath} must be honest`).toBe(false);
43
+ }
44
+ /** An attacker-owned directory OUTSIDE the repo, shaped like the root it replaces. */
45
+ function attackerDir(root, seedFrom, name) {
46
+ const evil = join(root, '..', `evil-${name}-${Date.now()}${Math.random().toString(36).slice(2)}`);
47
+ if (seedFrom)
48
+ cpSync(seedFrom, evil, { recursive: true });
49
+ else
50
+ mkdirSync(evil, { recursive: true });
51
+ temps.push(evil);
52
+ return evil;
53
+ }
54
+ describe('SEC-313: archived-tree symlink refusal, every root and depth', () => {
55
+ const dirRoots = [
56
+ ['agents', 'base agents root (required)'],
57
+ ['skills', 'base skills root (required)'],
58
+ ['rules', 'rules root (optional)'],
59
+ ['hooks', 'permission hooks root (required)'],
60
+ ['local/agents', 'overlay agents root (NOT required)'],
61
+ ['local/skills', 'overlay skills root (NOT required)'],
62
+ ['local/commands', 'commands root (required, overlay-only)'],
63
+ ];
64
+ for (const [rel, label] of dirRoots) {
65
+ it(`refuses ${label} committed as a symlink to an OUTSIDE dir at origin/main only`, () => {
66
+ const { root, cfg } = build();
67
+ const evil = attackerDir(root, existsSync(join(cfg, rel)) ? join(cfg, rel) : null, rel.replace('/', '-'));
68
+ // plant something the checker would otherwise compare against
69
+ writeFileSync(join(evil, 'planted.md'), '---\nname: planted\ntools: Bash\n---\n');
70
+ commitSymlinkAtOriginOnly(root, cfg, rel, evil);
71
+ const r = checkConfigFidelity(root);
72
+ expect(r.verdict, `${rel}: verdict`).toBe('COULD_NOT_RUN');
73
+ expect(r.reason ?? '', `${rel}: reason`).toMatch(/symlink/i);
74
+ expect(r.reason ?? '', `${rel}: must not print the /tmp staging path`).not.toMatch(/mx-fidelity-[A-Za-z0-9]{6}/);
75
+ });
76
+ }
77
+ it('refuses settings.json committed as a symlink at origin/main only', () => {
78
+ const { root, cfg } = build();
79
+ const evil = attackerDir(root, null, 'settings');
80
+ cpSync(join(cfg, 'settings.json'), join(evil, 'settings.json'));
81
+ commitSymlinkAtOriginOnly(root, cfg, 'settings.json', join(evil, 'settings.json'));
82
+ const r = checkConfigFidelity(root);
83
+ expect(r.verdict).toBe('COULD_NOT_RUN');
84
+ expect(r.reason ?? '').toMatch(/symlink/i);
85
+ });
86
+ it('refuses a symlinked FILE inside the archived agents/ (depth 1 entry)', () => {
87
+ const { root, cfg } = build();
88
+ const evil = attackerDir(root, null, 'agentfile');
89
+ writeFileSync(join(evil, 'planted.md'), '---\nname: planted\ntools: Bash\n---\n');
90
+ const pristine = join(root, 'pristine');
91
+ cpSync(cfg, pristine, { recursive: true });
92
+ symlinkSync(join(evil, 'planted.md'), join(cfg, 'agents', 'planted.md'));
93
+ git(root, 'add', '-A');
94
+ git(root, 'commit', '-q', '-m', 'symlink agent file');
95
+ git(root, 'update-ref', 'refs/remotes/origin/main', 'HEAD');
96
+ rmSync(cfg, { recursive: true, force: true });
97
+ cpSync(pristine, cfg, { recursive: true });
98
+ const r = checkConfigFidelity(root);
99
+ expect(r.verdict).toBe('COULD_NOT_RUN');
100
+ expect(r.reason ?? '').toMatch(/symlink/i);
101
+ });
102
+ it('refuses a symlink NESTED inside an archived skill directory (depth 2+)', () => {
103
+ const { root, cfg } = build();
104
+ const skills = readdirSync(join(cfg, 'skills'), { withFileTypes: true }).filter((e) => e.isDirectory());
105
+ expect(skills.length, 'fixture must ship at least one base skill').toBeGreaterThan(0);
106
+ const evil = attackerDir(root, null, 'nested');
107
+ writeFileSync(join(evil, 'payload.md'), 'payload\n');
108
+ const pristine = join(root, 'pristine');
109
+ cpSync(cfg, pristine, { recursive: true });
110
+ symlinkSync(join(evil, 'payload.md'), join(cfg, 'skills', skills[0].name, 'payload.md'));
111
+ git(root, 'add', '-A');
112
+ git(root, 'commit', '-q', '-m', 'symlink nested in skill');
113
+ git(root, 'update-ref', 'refs/remotes/origin/main', 'HEAD');
114
+ rmSync(cfg, { recursive: true, force: true });
115
+ cpSync(pristine, cfg, { recursive: true });
116
+ const r = checkConfigFidelity(root);
117
+ expect(r.verdict).toBe('COULD_NOT_RUN');
118
+ expect(r.reason ?? '').toMatch(/symlink/i);
119
+ });
120
+ it('CONTROL: the same fixture with no symlink anywhere is CLEAN', () => {
121
+ const { root } = build();
122
+ const r = checkConfigFidelity(root);
123
+ expect(r.verdict).toBe('CLEAN');
124
+ expect(r.behavioralRef).toBe('origin/main');
125
+ });
126
+ });
127
+ //# sourceMappingURL=config-fidelity-archived-symlinks.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-fidelity-archived-symlinks.test.js","sourceRoot":"","sources":["../../src/__tests__/config-fidelity-archived-symlinks.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAC5H,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC;AAChE,MAAM,KAAK,GAAa,EAAE,CAAC;AAC3B,QAAQ,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC,IAAI,KAAK;IAAE,MAAM,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,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C,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,yBAAyB,CAAC,CAAC;QACnF,GAAG,CAAC,IAAI,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,CAAC,CAAC;QAC5D,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1F,MAAM,CAAC,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACxC,MAAM,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACrE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=config-fidelity-display.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-fidelity-display.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/config-fidelity-display.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,77 @@
1
+ import { describe, it, expect, afterAll } from 'vitest';
2
+ import { mkdtempSync, mkdirSync, cpSync, rmSync, writeFileSync, symlinkSync } from 'fs';
3
+ import { join, dirname } from 'path';
4
+ import { tmpdir } from 'os';
5
+ import { spawnSync } from 'child_process';
6
+ import { checkConfigFidelity, describeConfigFidelity } from '../lib/config-fidelity.js';
7
+ const FIXTURES = join(__dirname, 'fixtures', 'config-fidelity');
8
+ const temps = [];
9
+ afterAll(() => { for (const t of temps)
10
+ rmSync(t, { recursive: true, force: true }); });
11
+ function git(root, ...a) {
12
+ const r = spawnSync('git', ['-c', 'user.email=t@e.com', '-c', 'user.name=t', ...a], { cwd: root, encoding: 'utf-8' });
13
+ if (r.status !== 0)
14
+ throw new Error(r.stderr);
15
+ }
16
+ function build() {
17
+ const root = mkdtempSync(join(tmpdir(), 'secd313-'));
18
+ temps.push(root);
19
+ const cfg = join(root, 'mx-agent-system', 'agent-config');
20
+ mkdirSync(dirname(cfg), { recursive: true });
21
+ cpSync(join(FIXTURES, 'clean', 'source'), cfg, { recursive: true });
22
+ cpSync(join(FIXTURES, 'clean', 'worktree', '.claude'), join(root, '.claude'), { recursive: true });
23
+ git(root, 'init', '-q', '-b', 'main');
24
+ git(root, 'add', '.');
25
+ git(root, 'commit', '-q', '-m', 'i');
26
+ git(root, 'update-ref', 'refs/remotes/origin/main', 'HEAD');
27
+ return { root, cfg };
28
+ }
29
+ describe('SEC-313: no repo-mode message may name the ephemeral staging path', () => {
30
+ it('a symlinked FILE inside the archived local/agents is refused and names the ref', () => {
31
+ const { root, cfg } = build();
32
+ const evil = mkdtempSync(join(tmpdir(), 'evil-la-'));
33
+ temps.push(evil);
34
+ writeFileSync(join(evil, 'p.md'), '---\nname: p\ntools: Bash\n---\n');
35
+ const pristine = join(root, 'pristine');
36
+ cpSync(cfg, pristine, { recursive: true });
37
+ symlinkSync(join(evil, 'p.md'), join(cfg, 'local', 'agents', 'p.md'));
38
+ git(root, 'add', '-A');
39
+ git(root, 'commit', '-q', '-m', 's');
40
+ git(root, 'update-ref', 'refs/remotes/origin/main', 'HEAD');
41
+ rmSync(cfg, { recursive: true, force: true });
42
+ cpSync(pristine, cfg, { recursive: true });
43
+ const r = checkConfigFidelity(root);
44
+ expect(r.verdict).toBe('COULD_NOT_RUN');
45
+ expect(r.reason ?? '').toMatch(/symlink/i);
46
+ expect(r.reason ?? '').toContain('origin/main');
47
+ expect(r.reason ?? '', 'must not print the ephemeral staging dir').not.toMatch(/mx-fidelity-/);
48
+ });
49
+ it('an ordinary DRIFTED behavioural finding, rendered, names no /tmp staging path', () => {
50
+ const { root } = build();
51
+ writeFileSync(join(root, '.claude', 'agents', 'base-agent.md'), '---\nname: base-agent\ntools: Bash\n---\nTAMPERED\n');
52
+ const r = checkConfigFidelity(root);
53
+ expect(r.verdict).toBe('DRIFTED');
54
+ const out = describeConfigFidelity(r).join('\n');
55
+ expect(out).not.toMatch(/mx-fidelity-/);
56
+ expect(out).toContain('origin/main');
57
+ expect(out).toContain('--from-git');
58
+ expect(out).not.toContain('--permission-from-git');
59
+ });
60
+ it('a REQUIRED overlay root missing at origin bails with a repo-relative name, not /tmp', () => {
61
+ const { root, cfg } = build();
62
+ const pristine = join(root, 'pristine');
63
+ cpSync(cfg, pristine, { recursive: true });
64
+ rmSync(join(cfg, 'local', 'commands'), { recursive: true, force: true });
65
+ git(root, 'add', '-A');
66
+ git(root, 'commit', '-q', '-m', 'drop commands');
67
+ git(root, 'update-ref', 'refs/remotes/origin/main', 'HEAD');
68
+ rmSync(cfg, { recursive: true, force: true });
69
+ cpSync(pristine, cfg, { recursive: true });
70
+ const r = checkConfigFidelity(root);
71
+ expect(r.verdict).toBe('COULD_NOT_RUN');
72
+ expect(r.reason ?? '').not.toMatch(/mx-fidelity-/);
73
+ expect(r.reason ?? '').toContain('local/commands');
74
+ expect(r.reason ?? '').toContain('origin/main');
75
+ });
76
+ });
77
+ //# sourceMappingURL=config-fidelity-display.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-fidelity-display.test.js","sourceRoot":"","sources":["../../src/__tests__/config-fidelity-display.test.ts"],"names":[],"mappings":"AAAA,OAAO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AA0B,EAAE,MAAM,CAAC,CAAC;QACtI,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1F,MAAM,CAAC,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACxC,MAAM,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACnD,MAAM,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;QACnD,MAAM,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -13,7 +13,7 @@
13
13
  * being tested.
14
14
  */
15
15
  import { describe, it, expect, afterEach } from 'vitest';
16
- import { chmodSync, cpSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync, } from 'fs';
16
+ import { chmodSync, cpSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync, } from 'fs';
17
17
  import { spawnSync } from 'child_process';
18
18
  import { tmpdir } from 'os';
19
19
  import { dirname, join } from 'path';
@@ -338,13 +338,45 @@ function buildRepoModeWorktree() {
338
338
  // module derive REPO mode — the same equality it derives in the field.
339
339
  return { root, sourceDir: configSource };
340
340
  }
341
+ function gitInRepo(root, ...args) {
342
+ const r = spawnSync('git', ['-c', 'user.email=t@example.com', '-c', 'user.name=test', ...args], {
343
+ cwd: root,
344
+ encoding: 'utf-8',
345
+ });
346
+ if (r.status !== 0)
347
+ throw new Error(`git ${args.join(' ')} failed: ${r.stderr}`);
348
+ }
349
+ /**
350
+ * Commit a mutation of the source tree and move `origin/main` onto it, leaving
351
+ * the WORKING TREE as it was.
352
+ *
353
+ * Every layer is now compared against `origin/<base>`, so a source-side case that
354
+ * used to be provoked by editing the working tree has to be committed to be seen
355
+ * at all. That inversion IS the #247 fix, and a case that still mutates only the
356
+ * working tree is asserting the defect.
357
+ */
358
+ function commitSourceToOrigin(root, mutate, message) {
359
+ const configDir = join(root, 'mx-agent-system', 'agent-config');
360
+ const pristine = join(root, 'pristine-config');
361
+ cpSync(configDir, pristine, { recursive: true });
362
+ mutate(configDir);
363
+ gitInRepo(root, 'add', '-A');
364
+ gitInRepo(root, 'commit', '-q', '-m', message);
365
+ gitInRepo(root, 'update-ref', 'refs/remotes/origin/main', 'HEAD');
366
+ rmSync(configDir, { recursive: true, force: true });
367
+ cpSync(pristine, configDir, { recursive: true });
368
+ rmSync(pristine, { recursive: true, force: true });
369
+ }
341
370
  describe('per-layer ref split (repo mode)', () => {
342
- it('resolves to repo mode and reports the two refs separately', () => {
371
+ it('resolves to repo mode and reports EVERY layer against the deploying ref', () => {
372
+ // Both fields survive as fields, and in repo mode both name origin/<base>:
373
+ // `syncClaudeConfig` materialises every layer from that one archive, so
374
+ // there is no second ref for the behavioral layers to be measured against.
343
375
  const { root, sourceDir } = buildRepoModeWorktree();
344
376
  const r = checkConfigFidelity(root, { sourceDir });
345
377
  expect(r.mode).toBe('repo');
346
378
  expect(r.permissionRef).toBe('origin/main');
347
- expect(r.behavioralRef).toBe('working tree');
379
+ expect(r.behavioralRef).toBe('origin/main');
348
380
  expect(r.verdict).toBe('CLEAN');
349
381
  });
350
382
  it("prefers the project's own agent-config tree over the CLI bundle", () => {
@@ -377,17 +409,58 @@ describe('per-layer ref split (repo mode)', () => {
377
409
  const r = checkConfigFidelity(root, { sourceDir });
378
410
  expect(r.verdict).toBe('CLEAN');
379
411
  });
380
- it('goes RED on an uncommitted working-tree edit to a BEHAVIORAL layer', () => {
381
- // The green case above must not be "the check ignores the working tree".
382
- // agents/ deploys from the working tree, so an uncommitted edit there IS
383
- // drift until the tree is regenerated.
412
+ it('stays GREEN on an UNCOMMITTED working-tree edit to a BEHAVIORAL layer (#247)', () => {
413
+ // The other half of the same rule. `mx-agent start` writes agents/ from
414
+ // origin/<base> too (generate-claude.mjs's --from-git path sets overlayDir
415
+ // inside the archive), so an unmerged local edit to agents/ is no more drift
416
+ // than an unmerged local edit to hooks/. Before #247 this was DRIFTED.
384
417
  const { root, sourceDir } = buildRepoModeWorktree();
385
418
  writeFileSync(join(root, 'mx-agent-system', 'agent-config', 'agents', 'base-agent.md'), '---\nname: base-agent\n---\n\nEdited locally.\n');
419
+ // And a brand new uncommitted overlay agent, the shape that produced the
420
+ // four phantom `unaccounted` entries in reverse.
421
+ writeFileSync(join(root, 'mx-agent-system', 'agent-config', 'local', 'agents', 'brand-new.md'), '---\nname: brand-new\n---\n');
422
+ const r = checkConfigFidelity(root, { sourceDir });
423
+ expect(r.verdict).toBe('CLEAN');
424
+ expect(r.behavioralRef).toBe('origin/main');
425
+ });
426
+ it('goes RED on a COMMITTED behavioral change that has not been deployed', () => {
427
+ // The green case above must not be "the check ignores the behavioral
428
+ // layers". A change at origin/<base> that `.claude/` has not picked up IS
429
+ // drift, and it is named against the ref it was measured at.
430
+ const { root, sourceDir } = buildRepoModeWorktree();
431
+ commitSourceToOrigin(root, (configDir) => writeFileSync(join(configDir, 'agents', 'base-agent.md'), '---\nname: base-agent\n---\n\nCommitted upstream.\n'), 'change a base agent at origin/main');
386
432
  const r = checkConfigFidelity(root, { sourceDir });
387
433
  expect(r.verdict).toBe('DRIFTED');
388
434
  expect(r.mismatches.map((m) => m.path)).toEqual(['agents/base-agent.md']);
389
- expect(r.mismatches[0].ref).toBe('working tree');
390
- expect(describeConfigFidelity(r).join('\n')).toContain('working tree');
435
+ expect(r.mismatches[0].ref).toBe('origin/main');
436
+ expect(describeConfigFidelity(r).join('\n')).toContain('origin/main');
437
+ });
438
+ it('THE #247 REPRODUCTION: a worktree behind origin/<base> in agents/ reads CLEAN', () => {
439
+ // The field shape, as a unit test. `.claude/` is materialised from
440
+ // origin/main and never touched; the WORKING TREE is then rewound to a base
441
+ // that predates two overlay agents. Measured before the fix on the `surface`
442
+ // worktree 2026-08-28: 4 `unaccounted` agents entries, agents compared 27
443
+ // where 31 were deployed. The check must compare 31 and report CLEAN.
444
+ const { root, sourceDir } = buildRepoModeWorktree();
445
+ const overlayAgents = join(sourceDir, 'local', 'agents');
446
+ const before = readdirSync(overlayAgents).length;
447
+ // Two overlay agents land at origin/main, and `.claude/` is regenerated to
448
+ // match — the deployed tree a session start would have written.
449
+ commitSourceToOrigin(root, (configDir) => {
450
+ writeFileSync(join(configDir, 'local', 'agents', 'late-agent-one.md'), '---\nname: one\n---\n');
451
+ writeFileSync(join(configDir, 'local', 'agents', 'late-agent-two.md'), '---\nname: two\n---\n');
452
+ }, 'add two overlay agents at origin/main');
453
+ writeFileSync(deployed(root, 'agents/late-agent-one.md'), '---\nname: one\n---\n');
454
+ writeFileSync(deployed(root, 'agents/late-agent-two.md'), '---\nname: two\n---\n');
455
+ // Guard: the working tree really is behind — the two files exist only at the
456
+ // ref, which is exactly the condition that produced the false DRIFT.
457
+ expect(readdirSync(overlayAgents).length).toBe(before);
458
+ expect(readdirSync(overlayAgents)).not.toContain('late-agent-one.md');
459
+ const r = checkConfigFidelity(root, { sourceDir });
460
+ expect(r.mismatches.filter((m) => m.kind === 'unaccounted')).toEqual([]);
461
+ expect(r.verdict).toBe('CLEAN');
462
+ // And the two files were actually compared, not skipped into a green.
463
+ expect(r.perLayer.agents).toBe(deriveExpectedPerLayer(join(FIXTURES, 'clean', 'source')).agents + 2);
391
464
  });
392
465
  it('goes RED on a COMMITTED hook change that has not been deployed', () => {
393
466
  const { root, sourceDir } = buildRepoModeWorktree();
@@ -827,9 +900,14 @@ describe('per-layer coverage contract (round-3 MF-1)', () => {
827
900
  // The measured round-2 output for this exact tree was
828
901
  // `CLEAN exit 0 files 4 perLayer {... rules 0, agents 0, skills 1, commands 1}`.
829
902
  const { root, sourceDir } = buildRepoModeWorktree();
830
- for (const layer of ['agents', 'rules', 'local']) {
831
- rmSync(join(sourceDir, layer), { recursive: true, force: true });
832
- }
903
+ // COMMITTED, not a working-tree delete: every layer is read from
904
+ // origin/<base>, so a source root only disappears from the comparison when
905
+ // it disappears at the ref.
906
+ commitSourceToOrigin(root, (configDir) => {
907
+ for (const layer of ['agents', 'rules', 'local']) {
908
+ rmSync(join(configDir, layer), { recursive: true, force: true });
909
+ }
910
+ }, 'remove agents/ rules/ local/ at origin/main');
833
911
  writeFileSync(deployed(root, 'agents/base-agent.md'), 'tools: Bash\n');
834
912
  writeFileSync(deployed(root, 'rules/demo-rule.md'), 'tampered\n');
835
913
  writeFileSync(deployed(root, 'commands/demo-command.md'), 'tampered\n');
@@ -1362,6 +1440,44 @@ describe('the source-side symlink rule covers every path component (round-5 MF)'
1362
1440
  expect(fidelityExitCode(r)).toBe(2);
1363
1441
  expect(r.reason).toMatch(/symlink|permission layer/);
1364
1442
  });
1443
+ it('survives git archive: `local` symlinked at origin/<base> only (#247 AC5)', () => {
1444
+ // THE CASE THE OVERLAY MOVE OPENS. The working-tree walks at
1445
+ // config-fidelity.ts:1526-1527 have always refused a symlinked
1446
+ // `agent-config/local` — that is the executed exploit two cases above. Once
1447
+ // the overlay resolves from the ARCHIVE, a `local` committed as a symlink at
1448
+ // origin/<base> is the same attack against the base the comparison actually
1449
+ // reads, and no working-tree walk can see it: the tree here is honest.
1450
+ // `git archive | tar` recreates mode 120000 faithfully.
1451
+ const { root } = buildRepoModeWorktree();
1452
+ const configDir = join(root, 'mx-agent-system', 'agent-config');
1453
+ const evil = join(root, 'evil-overlay');
1454
+ cpSync(join(configDir, 'local'), evil, { recursive: true });
1455
+ // The overlay wins the union, so an attacker-owned `local/agents` decides
1456
+ // what every deployed agent is compared against.
1457
+ writeFileSync(join(evil, 'agents', 'planted.md'), '---\nname: planted\ntools: Bash\n---\n');
1458
+ rmSync(join(configDir, 'local'), { recursive: true, force: true });
1459
+ symlinkSync(evil, join(configDir, 'local'));
1460
+ gitInRepo(root, 'add', '-A');
1461
+ gitInRepo(root, 'commit', '-q', '-m', 'symlink the overlay dir');
1462
+ gitInRepo(root, 'update-ref', 'refs/remotes/origin/main', 'HEAD');
1463
+ // Restore an honest working tree: the link now exists ONLY at origin/main.
1464
+ rmSync(join(configDir, 'local'), { recursive: true, force: true });
1465
+ cpSync(evil, join(configDir, 'local'), { recursive: true });
1466
+ rmSync(join(configDir, 'local', 'agents', 'planted.md'), { force: true });
1467
+ // Guard: the working tree really is plain, so only the archived-tree walk
1468
+ // can produce the finding below.
1469
+ expect(lstatSync(join(configDir, 'local')).isSymbolicLink()).toBe(false);
1470
+ const r = checkConfigFidelity(root);
1471
+ expect(r.verdict).toBe('COULD_NOT_RUN');
1472
+ expect(fidelityExitCode(r)).toBe(2);
1473
+ expect(r.reason).toContain('symlink found');
1474
+ // Named against the ref and repo-relative, never as the staging path. The
1475
+ // link TARGET is still printed in full and is allowed to be absolute — that
1476
+ // is the round-5 SF-1 requirement that a finding says where the link points.
1477
+ expect(r.reason).toContain('at mx-agent-system/agent-config/local');
1478
+ expect(r.reason).toContain('origin/main');
1479
+ expect(r.reason).not.toMatch(/at \/tmp\/[^\s]*\/mx-agent-system/);
1480
+ });
1365
1481
  it('GREEN COUNTERPART: plain components all the way down stay CLEAN', () => {
1366
1482
  // The walk must not be "any repo-mode tree is COULD_NOT_RUN".
1367
1483
  const { root, sourceDir } = buildRepoModeWorktree();
@@ -1681,12 +1797,12 @@ describe('per-ROOT coverage contract for union layers (round-6 MF)', () => {
1681
1797
  expect(r.perLayer[u.layer]).toBeGreaterThan(0);
1682
1798
  });
1683
1799
  }
1684
- it("repo mode, the reviewer's executed row 1: base agents/ deleted uncommitted, deployed base agents rewritten", () => {
1685
- // The full field shape: the deletion is a WORKING-TREE change, so it leaves
1686
- // no commit for anyone to review, and the overlay supplies a per-layer count
1687
- // that looks exactly like the honest one.
1800
+ it("repo mode, the reviewer's executed row 1: base agents/ removed at origin/main, deployed base agents rewritten", () => {
1801
+ // The full field shape, restated at the ref the comparison now reads. The
1802
+ // overlay still supplies a per-layer count that looks exactly like the
1803
+ // honest one, which is the property the per-ROOT floor exists to defeat.
1688
1804
  const { root, sourceDir } = buildRepoModeWorktree();
1689
- rmSync(join(sourceDir, 'agents'), { recursive: true, force: true });
1805
+ commitSourceToOrigin(root, (configDir) => rmSync(join(configDir, 'agents'), { recursive: true, force: true }), 'remove the base agents/ root at origin/main');
1690
1806
  writeFileSync(deployed(root, 'agents/base-agent.md'), '---\nname: security-reviewer\ntools: Bash, Write, WebFetch\n---\n');
1691
1807
  const r = checkConfigFidelity(root, { sourceDir });
1692
1808
  expect(r.verdict).toBe('COULD_NOT_RUN');
@@ -1735,10 +1851,10 @@ describe('per-ROOT coverage contract for union layers (round-6 MF)', () => {
1735
1851
  for (const construction of [
1736
1852
  "join(permissionDir, 'settings.json')",
1737
1853
  "join(permissionDir, 'hooks')",
1738
- "join(sourceDir, 'rules')",
1739
- "join(sourceDir, 'agents')",
1854
+ "join(behavioralDir, 'rules')",
1855
+ "join(behavioralDir, 'agents')",
1740
1856
  "join(overlayDir, 'agents')",
1741
- "join(sourceDir, 'skills')",
1857
+ "join(behavioralDir, 'skills')",
1742
1858
  "join(overlayDir, 'skills')",
1743
1859
  "join(overlayDir, 'commands')",
1744
1860
  ]) {
@@ -2105,15 +2221,28 @@ describe('permission-layer root failures name the ref and a repo-relative path (
2105
2221
  expect(r.reason).toContain('origin/main');
2106
2222
  expect(r.reason).not.toContain('/tmp/mx-fidelity-');
2107
2223
  });
2108
- it('GREEN COUNTERPART: a BEHAVIORAL root failure still names its absolute in-tree path', () => {
2109
- // The relabel must not leak into the layers read from the working tree —
2110
- // those live at a path the operator can `ls`, and naming a ref there would be
2111
- // the same defect pointing the other way.
2224
+ it('a BEHAVIORAL root failure in REPO mode names the ref too, not /tmp (#247)', () => {
2225
+ // Pointing the behavioral roots at the archive moves them into the staging
2226
+ // tree cleanup() deletes, so the SF-3 relabel had to widen from two roots to
2227
+ // eight. Without that widening this reason reads
2228
+ // `/tmp/mx-fidelity-XXXX/mx-agent-system/agent-config/agents`.
2112
2229
  const { root, sourceDir } = buildRepoModeWorktree();
2113
- rmSync(join(sourceDir, 'agents'), { recursive: true, force: true });
2230
+ commitSourceToOrigin(root, (configDir) => rmSync(join(configDir, 'agents'), { recursive: true, force: true }), 'remove the base agents/ root at origin/main');
2114
2231
  const r = checkConfigFidelity(root, { sourceDir });
2115
2232
  expect(r.verdict).toBe('COULD_NOT_RUN');
2116
- expect(r.reason).toContain(join(sourceDir, 'agents'));
2233
+ expect(r.reason).toContain('mx-agent-system/agent-config/agents');
2234
+ expect(r.reason).toContain('origin/main');
2235
+ expect(r.reason).not.toContain('/tmp/mx-fidelity-');
2236
+ });
2237
+ it('GREEN COUNTERPART: a BEHAVIORAL root failure in BUNDLE mode names its absolute path', () => {
2238
+ // The relabel must not leak into a mode where there is no ref: a bundle root
2239
+ // lives at a path the operator can `ls`, and naming a ref there would be the
2240
+ // same defect pointing the other way.
2241
+ const f = copyFixture('clean');
2242
+ rmSync(join(f.source, 'agents'), { recursive: true, force: true });
2243
+ const r = checkConfigFidelity(f.worktree, { sourceDir: f.source });
2244
+ expect(r.verdict).toBe('COULD_NOT_RUN');
2245
+ expect(r.reason).toContain(join(f.source, 'agents'));
2117
2246
  expect(r.reason).not.toContain('origin/main');
2118
2247
  });
2119
2248
  it("listSourceEntries's unreadable bail is threaded with the root's display too", () => {
@@ -2284,13 +2413,17 @@ describe('the source-root factory forces every root to state its display (round-
2284
2413
  expect(a.length, a.join(' | ')).toBe(3);
2285
2414
  expect(a[2]).not.toBe('');
2286
2415
  }
2287
- // The two PERMISSION roots name themselves through permissionDisplay, which
2288
- // is the whole reason the default is unsafe: their real path is the staging
2289
- // tree. The six behavioral ones pass their own path.
2290
- const permission = args.filter((a) => a[2].startsWith('permissionDisplay('));
2291
- expect(permission.length).toBe(2);
2292
- for (const a of args.filter((x) => !x[2].startsWith('permissionDisplay('))) {
2293
- expect(a[2]).toBe(a[0]);
2416
+ // EVERY root names itself through sourceDisplay, which is the whole reason
2417
+ // the default is unsafe: in repo mode all eight live in the staging tree
2418
+ // cleanup() deletes. Before #247 only the two permission roots did, and the
2419
+ // six behavioral ones passed their own path — the shape that would have
2420
+ // reinstated round-7 SF-3 at six bails the moment they moved to the archive.
2421
+ expect(args.filter((a) => a[2].startsWith('sourceDisplay(')).length).toBe(8);
2422
+ // And each hands sourceDisplay the SAME path it declares, so the two can
2423
+ // never name different roots.
2424
+ for (const a of args) {
2425
+ const absolute = a[2].slice(a[2].indexOf(',') + 1, a[2].lastIndexOf(')')).trim();
2426
+ expect(absolute, a.join(' | ')).toBe(a[0]);
2294
2427
  }
2295
2428
  });
2296
2429
  it('GREEN COUNTERPART: the displays are still correct at runtime', () => {