@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,439 @@
1
+ /**
2
+ * worktree-sync.ts — in-process worktree synchronisation with namespaced
3
+ * checkpoint refs (#172, revision 4; closes the post-squash-merge deadlock #156).
4
+ *
5
+ * ── WHAT THIS REPLACES ────────────────────────────────────────────────────
6
+ * The `mx-post-merge-sync` skill runs `git stash push` then `git reset --hard`
7
+ * from Bash. `refs/stash` is ONE repository-global stack shared by every linked
8
+ * worktree, so a positional pop can restore another team's entry. This module
9
+ * writes one ref per worktree per checkpoint instead: no stack, and nothing
10
+ * another worktree can pop.
11
+ *
12
+ * ── WHAT THE LEADER-LOCK CHECK DOES AND DOES NOT DO ───────────────────────
13
+ * `leader-lock.ts:12-14` states that sub-agent teammates are spawned via the
14
+ * Task tool INSIDE a leader session and never touch the leader lock. So the
15
+ * lock cannot observe teammates, and this module never claims it does. Step 0
16
+ * establishes only that a live leader session exists in this worktree. It does
17
+ * NOT establish that the caller is that leader rather than one of its
18
+ * teammates, because a teammate runs with the same worktree cwd and the same
19
+ * lock file present, and no signal available here separates the two.
20
+ *
21
+ * ── WHAT HAPPENS WHEN THE PROCESS DIES MID-SYNC ───────────────────────────
22
+ * An `in-progress` audit record is written before the destructive step and a
23
+ * terminal record after it, correlated by `runId`. An `in-progress` record with
24
+ * no matching terminal record is a run that died during the destructive step.
25
+ * That record is the ONLY protection, and it is deliberate: this module
26
+ * registers no signal handler. See the comment above the record for the
27
+ * measurement. A killed sync leaves the sync lock file behind; the next run
28
+ * reclaims it after finding the recorded pid gone.
29
+ *
30
+ * ── RESIDUAL RISK, STATED RATHER THAN MITIGATED ───────────────────────────
31
+ * A teammate writing files during the reset or the rebase can still lose work.
32
+ * The quiescence sample (steps 4 and 6) brackets the checkpoint, not the
33
+ * destructive step, and its mtime comparison is bounded by filesystem
34
+ * resolution. The step-0a assertion is self-reported by the party that wants
35
+ * the sync to proceed: it is a weaker, self-administered substitute for asking
36
+ * the coordinator, not that step. It is recorded so a lost-work investigation
37
+ * names a party. It supplies no independent verification.
38
+ *
39
+ * ── SHELL-FREE INVARIANT (success criterion 6) ────────────────────────────
40
+ * Every git and gh invocation ORIGINATING HERE goes through {@link runGit} /
41
+ * {@link runGh}, which call `execFileSync` with an argv array. No shell string,
42
+ * no `shell: true`, anywhere in this file. Two reused helpers from
43
+ * `lib/worktree.ts` (`getCurrentBranch`, `fetchOrigin`) do use `execSync` with
44
+ * a shell, and that is the documented residual: both take only `cwd` and both
45
+ * run hardcoded literals, so there is no interpolation surface. NOTHING
46
+ * interpolated may be routed through them.
47
+ */
48
+ /** Namespace for checkpoint refs. Not under `refs/heads` or `refs/tags`, so no
49
+ * branch listing, no push by default, and no interaction with `refs/stash`. */
50
+ export declare const CHECKPOINT_NAMESPACE = "refs/mx/checkpoint";
51
+ /** Retention, per the plan's Retention section. Named refs are GC roots, so an
52
+ * unbounded namespace pins every checkpointed tree forever. */
53
+ export declare const MAX_CHECKPOINTS_PER_WORKTREE = 20;
54
+ export declare const CHECKPOINT_RETENTION_DAYS = 14;
55
+ /** Audit log path component. One line per run, every path including refusals. */
56
+ export declare const AUDIT_LOG_FILENAME = "worktree-sync.jsonl";
57
+ /**
58
+ * The eleven fields the plan's Audit section names, plus `runId`, in written
59
+ * order.
60
+ *
61
+ * `runId` is the twelfth and it is required by the crash-durability fix (red
62
+ * team Finding 1). A run that reaches step 7 writes TWO records, one
63
+ * `in-progress` before the destructive step and one terminal record after, and
64
+ * with several worktrees appending to one file there is otherwise no way to say
65
+ * which terminal record closes which start. An `in-progress` record with no
66
+ * matching terminal record IS the signal that a run was killed mid-step-7.
67
+ *
68
+ * This changes criterion 9's literal wording, which says exactly one line per
69
+ * run. The criterion's intent, that no run goes unrecorded, is strengthened
70
+ * rather than weakened: the invariant now enforced is exactly one TERMINAL
71
+ * record per run.
72
+ */
73
+ export declare const AUDIT_FIELDS: readonly ["runId", "timestamp", "worktree", "caller", "quiescenceAsserted", "baseRef", "headBefore", "headAfter", "checkpointRef", "syncBranch", "refsPruned", "outcome"];
74
+ export type AuditField = (typeof AUDIT_FIELDS)[number];
75
+ /** Which arm of step 7 ran. `null` when step 7 was never reached. */
76
+ export type SyncBranch = 'reset' | 'rebase-onto' | 'rebase';
77
+ export type SyncOutcome = 'ok'
78
+ /** Written before step 7 begins. A record left at this value is a run that
79
+ * died during the destructive step. */
80
+ | 'in-progress'
81
+ /** The working tree was restored, but the restore hit a merge conflict and
82
+ * the tree was returned to the committed state. The checkpoint ref holds
83
+ * everything. */
84
+ | 'restore-conflict' | 'refused-no-leader-lock' | 'refused-no-quiescence-assertion' | 'refused-sync-lock-held' | 'refused-not-quiescent' | 'refused-invalid-checkpoint-ref' | 'refused-no-origin-remote' | 'refused-detached-head' | 'refused-base-ref-missing' | 'refused-fetch-failed' | 'refused-rebase-in-progress' | 'refused-status-unreadable' | 'refused-squash-point-not-ancestor'
85
+ /** A real merge conflict during the rebase. */
86
+ | 'conflict'
87
+ /** The rebase failed for a reason that is NOT a merge conflict: disk full,
88
+ * permissions, a refused start. Told apart from `conflict` so an operator
89
+ * reading the log is not sent to look for conflict markers that never
90
+ * existed (red team Finding 6). */
91
+ | 'rebase-failed'
92
+ /** The checkpoint was written but the restore could not be prepared or
93
+ * applied. NEVER reported as `ok`: the whole point is that a run which
94
+ * cannot put the work back does not claim it did. */
95
+ | 'restore-failed' | 'error';
96
+ export interface SyncAuditRecord {
97
+ /** Correlates the `in-progress` record with its terminal record. */
98
+ runId: string;
99
+ timestamp: string;
100
+ worktree: string;
101
+ caller: string;
102
+ /** The step-0a assertion, verbatim as the caller supplied it. */
103
+ quiescenceAsserted: boolean;
104
+ baseRef: string | null;
105
+ headBefore: string | null;
106
+ headAfter: string | null;
107
+ checkpointRef: string | null;
108
+ syncBranch: SyncBranch | null;
109
+ refsPruned: string[];
110
+ outcome: SyncOutcome;
111
+ }
112
+ export interface ExecResult {
113
+ status: number;
114
+ stdout: string;
115
+ stderr: string;
116
+ }
117
+ export interface ExecOptions {
118
+ cwd?: string;
119
+ env?: NodeJS.ProcessEnv;
120
+ timeoutMs?: number;
121
+ }
122
+ /**
123
+ * Argv-only process runner. The signature takes `args` as a separate array on
124
+ * purpose: there is no way to express a shell string through it, so criterion
125
+ * 6 holds by the shape of the seam and not only by the discipline of callers.
126
+ */
127
+ export type ExecFileFn = (file: string, args: readonly string[], options?: ExecOptions) => ExecResult;
128
+ /**
129
+ * Default runner: `execFileSync` with an argv array. Never a shell string,
130
+ * never `shell: true`. A non-zero exit is returned as a status rather than
131
+ * thrown, so every caller decides for itself whether the failure is fatal.
132
+ */
133
+ export declare const defaultExecFile: ExecFileFn;
134
+ export interface SyncDeps {
135
+ /** Epoch milliseconds. */
136
+ now?: () => number;
137
+ homeDir?: () => string;
138
+ exec?: ExecFileFn;
139
+ /** Six lowercase hex characters for the ref suffix. */
140
+ rand6?: () => string;
141
+ /** Reused unchanged from lib/worktree.ts — see the shell-free note above. */
142
+ getCurrentBranch?: (cwd: string) => string | null;
143
+ fetchOrigin?: (cwd: string) => boolean;
144
+ hasOriginRemote?: (cwd: string) => boolean;
145
+ refExists?: (ref: string, cwd: string) => boolean;
146
+ /** Step-0 gate. Defaults to {@link checkLeaderGate}. The seam exists because
147
+ * the real gate reads `/proc` for a PID whose cwd is the worktree, which a
148
+ * test runner is not; nothing in production overrides it. */
149
+ leaderGate?: (worktreePath: string) => LeaderGate;
150
+ /** Sink for operator-facing lines. Collected rather than printed, so tests
151
+ * read them and the command file owns stdout. */
152
+ emit?: (line: string) => void;
153
+ }
154
+ export declare function runGit(cwd: string, args: readonly string[], deps?: SyncDeps, env?: NodeJS.ProcessEnv): ExecResult;
155
+ export declare function runGh(cwd: string, args: readonly string[], deps?: SyncDeps): ExecResult;
156
+ /**
157
+ * `refs/mx/checkpoint/<worktree>/<epoch-ms>-<rand6>`.
158
+ *
159
+ * Epoch MILLISECONDS plus six random hex characters. Seconds alone collide on a
160
+ * same-second retry; an ISO timestamp contains colons and `check-ref-format`
161
+ * rejects it. Both verified in this repository on 2026-08-25 and reproduced by
162
+ * two reviewers.
163
+ */
164
+ export declare function buildCheckpointRef(worktreeName: string, epochMs: number, rand6: string): string;
165
+ /** The `for-each-ref` pattern covering one worktree's checkpoints. */
166
+ export declare function checkpointRefPattern(worktreeName: string): string;
167
+ /**
168
+ * Ask git whether a ref name is well-formed. The command REFUSES rather than
169
+ * constructing an invalid ref: a worktree name containing a space produces
170
+ * `refs/mx/checkpoint/bad name/...`, which `git check-ref-format` rejects
171
+ * (exit 1, verified). Validating the WHOLE ref rather than the name segment
172
+ * catches every other rejected character in one call.
173
+ */
174
+ export declare function isValidRefName(ref: string, cwd: string, deps?: SyncDeps): boolean;
175
+ export interface TreeSample {
176
+ head: string | null;
177
+ digest: string;
178
+ /** Raw porcelain status, kept for the operator-facing abort message. */
179
+ status: string;
180
+ /**
181
+ * False when `git status` itself failed. A failed status returns an empty
182
+ * string, which reads as "clean tree" and would send the run past the
183
+ * checkpoint into a `reset --hard`. Passed, failed and could-not-run are
184
+ * three results, so the caller refuses on this rather than guessing.
185
+ */
186
+ readable: boolean;
187
+ }
188
+ /**
189
+ * A digest of everything a concurrent writer could change cheaply: HEAD, the
190
+ * full porcelain status including untracked files, and per-path size and mtime.
191
+ *
192
+ * Size is in the digest because an APPEND to an already-modified tracked file
193
+ * leaves the porcelain line identical (` M path`) and can leave mtime unchanged
194
+ * within one filesystem tick. Size changes on every append, so the common
195
+ * background-writer shape is caught even at one-second mtime resolution. A
196
+ * same-length overwrite inside one tick is not caught, and that is the bound.
197
+ */
198
+ export declare function sampleWorkingTree(cwd: string, deps?: SyncDeps): TreeSample;
199
+ export declare function isDirty(sample: TreeSample): boolean;
200
+ export interface CheckpointResult {
201
+ ok: boolean;
202
+ ref: string | null;
203
+ commit: string | null;
204
+ /**
205
+ * A second commit holding ONLY tracked modifications, parented on the same
206
+ * HEAD. This is what {@link restoreCheckpoint} replays. It is deliberately
207
+ * not published under a ref: it is an implementation detail of the restore,
208
+ * and `ref` above is the thing an operator recovers from.
209
+ *
210
+ * Null when the tracked state is identical to HEAD, meaning only untracked
211
+ * files were dirty and there is nothing to replay.
212
+ */
213
+ restoreCommit: string | null;
214
+ /**
215
+ * Why the restore tree could not be built, or null when it built fine.
216
+ *
217
+ * This exists because `restoreCommit === null` is ambiguous on its own: it is
218
+ * also the legitimate "no tracked file changed" case. Treating the two the
219
+ * same is exactly how a failed restore came to report success.
220
+ */
221
+ restoreError: string | null;
222
+ /**
223
+ * A commit holding the REAL INDEX as it stood before the sync, parented on
224
+ * HEAD. It is the checkpoint commit's SECOND parent, so an operator reads it
225
+ * as `<ref>^2` exactly as they would read `stash@{0}^2`.
226
+ *
227
+ * Null when the index is identical to HEAD, meaning nothing was staged.
228
+ */
229
+ indexCommit: string | null;
230
+ error?: string;
231
+ }
232
+ /**
233
+ * Commit the working tree and index to a namespaced ref without touching HEAD,
234
+ * the real index, or the working tree.
235
+ *
236
+ * A temporary `GIT_INDEX_FILE` holds the staging: `read-tree HEAD` seeds it with
237
+ * the committed state, `add -A --` layers the working tree over it (tracked
238
+ * modifications, deletions, and untracked non-ignored files), `write-tree`
239
+ * turns that into a tree object and `commit-tree` into a commit parented on
240
+ * HEAD. Only then does `update-ref` publish the name. The developer's own
241
+ * index is never opened.
242
+ *
243
+ * THREE commits are written, and each one is measured rather than assumed.
244
+ *
245
+ * 1. `indexCommit`, the real index as it stands BEFORE anything else runs.
246
+ * This is security review Must Fix 2. `read-tree HEAD` followed by
247
+ * `add -A` overwrites the index entry for every path with the working-tree
248
+ * version, so for a path in `MM` state (staged, then edited again) the
249
+ * staged blob is captured nowhere and `reset --hard HEAD` at step 7 leaves
250
+ * it dangling. `git stash push` keeps both, at `stash@{0}` and
251
+ * `stash@{0}^2`. This mirrors that shape exactly: the checkpoint commit's
252
+ * second parent IS the index commit, so `<ref>^2:<path>` yields the staged
253
+ * bytes and `<ref>:<path>` the working-tree bytes. Verified on git 2.49.0.
254
+ * 2. The full working tree, tracked plus untracked non-ignored. This is what
255
+ * the published ref points at, and it is what RECOVERY reads.
256
+ * 3. `restoreCommit`, tracked modifications only. `git cherry-pick -n` of the
257
+ * FULL commit fails with exit 128, "The following untracked working tree
258
+ * files would be overwritten by merge", because the untracked files are
259
+ * additions in that commit and already exist on disk. The tracked-only
260
+ * commit built with `add -u` cherry-picks cleanly and leaves untracked files
261
+ * alone, which is `git stash apply` semantics. So RESTORE reads this one.
262
+ */
263
+ export declare function createCheckpoint(cwd: string, worktreeName: string, deps?: SyncDeps): CheckpointResult;
264
+ export type RestoreOutcome = 'restored' | 'nothing-to-restore' | 'conflict' | 'error';
265
+ export interface RestoreResult {
266
+ outcome: RestoreOutcome;
267
+ detail?: string;
268
+ }
269
+ /**
270
+ * Replay the checkpointed tracked modifications onto the post-sync HEAD.
271
+ *
272
+ * This is the second half of `git stash` semantics. The plan says the
273
+ * checkpoint replaces every use of `git stash` in a sync path, and
274
+ * `mx-post-merge-sync/SKILL.md:59-74` applies its stash back by SHA after the
275
+ * reset. Saving without applying loses the working state of any teammate who
276
+ * did not read the invoking session's console, and no cross-session channel
277
+ * relays that message.
278
+ *
279
+ * `cherry-pick -n` gives a real three-way merge against the new HEAD, so a
280
+ * change that main also made does not silently clobber main's version.
281
+ *
282
+ * ON CONFLICT the working tree is returned to the committed state rather than
283
+ * left with conflict markers. `git cherry-pick --abort` does not work here:
284
+ * under `-n` git writes no CHERRY_PICK_HEAD, and abort exits 128 with "no
285
+ * cherry-pick or revert in progress", leaving the `UU` entries in place
286
+ * (probe, git 2.49.0). `reset --hard HEAD` is the cleanup that works, and it is
287
+ * safe precisely because the published checkpoint ref still holds everything.
288
+ */
289
+ export declare function restoreCheckpoint(cwd: string, restoreCommit: string | null, deps?: SyncDeps, indexCommit?: string | null, headBefore?: string | null): RestoreResult;
290
+ export interface CheckpointRef {
291
+ ref: string;
292
+ /** Committer date, epoch SECONDS. */
293
+ committedAt: number;
294
+ }
295
+ export declare function listCheckpoints(cwd: string, worktreeName: string, deps?: SyncDeps): CheckpointRef[];
296
+ export interface PruneOptions {
297
+ cwd: string;
298
+ worktreeName: string;
299
+ olderThanDays?: number;
300
+ /** `null` disables the count cap — used by the manual age-only prune. */
301
+ maxKeep?: number | null;
302
+ deps?: SyncDeps;
303
+ }
304
+ /**
305
+ * Delete checkpoint refs past retention. Two independent rules, both applied:
306
+ * anything older than `olderThanDays`, and anything beyond the newest
307
+ * `maxKeep`. Returns the refs actually deleted.
308
+ */
309
+ export declare function pruneCheckpoints(options: PruneOptions): string[];
310
+ /** Parse `--older-than 14d`. Accepts a bare integer as days. Returns null on
311
+ * anything else rather than guessing a unit. */
312
+ export declare function parseOlderThan(value: string): number | null;
313
+ /**
314
+ * The sync-exclusive lock prevents two syncs racing. It is unrelated to the
315
+ * teammate-concurrency hazard and is not counted as a mitigation for it.
316
+ *
317
+ * It lives under `~/.mx-agent/locks/`, NOT in the worktree: a lock file at the
318
+ * worktree root is not covered by this repository's `.gitignore` (which names
319
+ * `.mx-leader.lock` and root-anchored `/.mx-*.json`), so it could ride into a
320
+ * commit on `git add -A`, and the checkpoint's own `add -A` would capture it.
321
+ */
322
+ export declare function syncLockPath(worktreeName: string, deps?: SyncDeps): string;
323
+ export type SyncLockResult = {
324
+ ok: true;
325
+ path: string;
326
+ } | {
327
+ ok: false;
328
+ heldBy: number | null;
329
+ path: string;
330
+ };
331
+ export declare function acquireSyncLock(worktreeName: string, deps?: SyncDeps): SyncLockResult;
332
+ export declare function releaseSyncLock(worktreeName: string, deps?: SyncDeps): void;
333
+ export declare function auditLogPath(deps?: SyncDeps): string;
334
+ /**
335
+ * Append exactly one JSON line. Returns false when the append failed, and the
336
+ * caller says so out loud: a sanctioned destructive git operation that leaves
337
+ * no record is the thing `git-mutation-guard.sh` was hardened against, so a
338
+ * silent logging failure is not an acceptable outcome here.
339
+ *
340
+ * WRITE-TARGET HARDENING (security review, Must Fix 1). The naive
341
+ * `mkdirSync` + `appendFileSync` form has three measured defects, all three
342
+ * already reproduced against `git-mutation-guard.sh` and recorded in its header
343
+ * at `:244-259`:
344
+ *
345
+ * 1. A SYMLINK at the leaf is followed, so the record is appended to a file
346
+ * outside the log directory, and the call returns success. The "this run
347
+ * is unrecorded" warning therefore never prints, which is worse than a
348
+ * failed write: the command asserts a record exists when it does not.
349
+ * 2. A FIFO at the leaf blocks `open()` forever with no reader. That hang
350
+ * happens inside the terminal write, which runs AFTER the destructive step,
351
+ * so the process stops with the reset already done and the `finally` never
352
+ * releases the sync lock. Every later sync in that worktree then refuses.
353
+ * 3. A symlinked log DIRECTORY survives a leaf-only check, because both
354
+ * `mkdirSync` and the append follow directory symlinks.
355
+ *
356
+ * Any process running as the agent user can plant these, and a teammate in this
357
+ * worktree is exactly such a process. The guard's header says bash cannot
358
+ * express the flags that close 1 and 2. Node can, so this does:
359
+ * `O_NOFOLLOW` refuses a symlinked leaf, `O_NONBLOCK` refuses to block on a
360
+ * FIFO, and both are decided by the kernel inside the one `open()` call rather
361
+ * than by a check-then-use. `lstat` on the directory closes 3, and `fstat` on
362
+ * the returned descriptor confirms what was actually opened.
363
+ */
364
+ export declare function appendAuditLine(record: SyncAuditRecord, deps?: SyncDeps): boolean;
365
+ export type LeaderGate = {
366
+ held: true;
367
+ } | {
368
+ held: false;
369
+ reason: string;
370
+ };
371
+ /**
372
+ * Step 0. Refuse unless a live leader session exists in this worktree.
373
+ *
374
+ * Read the module header before extending this: the lock cannot see teammates,
375
+ * and it does not prove the caller IS the leader. It proves a leader session
376
+ * exists here. A stale or absent lock refuses; an indeterminate probe with a
377
+ * fresh heartbeat passes, because `/proc` being unreadable must not brick a
378
+ * legitimate sync (the fail-open contract in leader-lock.ts).
379
+ */
380
+ export declare function checkLeaderGate(worktreePath: string, deps?: SyncDeps): LeaderGate;
381
+ /**
382
+ * The last commit of this branch's merged pull request, read from
383
+ * `gh pr view --json commits` rather than guessed. Returns null when there is
384
+ * no merged PR for the branch, when gh is missing or unauthenticated, or when
385
+ * the payload does not parse: every one of those routes to the plain rebase
386
+ * arm, which is correct-but-slower rather than wrong.
387
+ */
388
+ /** A full 40-character hex object name and nothing else. Anything that fails
389
+ * this never reaches a git command line. */
390
+ export declare const OID_RE: RegExp;
391
+ export interface SquashPoint {
392
+ oid: string;
393
+ prNumber: number;
394
+ }
395
+ export declare function findSquashPoint(cwd: string, branch: string, deps?: SyncDeps): SquashPoint | null;
396
+ /**
397
+ * True when some multi-step git operation is half-finished in this worktree.
398
+ *
399
+ * `MERGE_HEAD` and `CHERRY_PICK_HEAD` matter as much as the rebase states: step
400
+ * 7 runs `reset --hard HEAD`, which clears an in-progress merge and discards
401
+ * whatever conflict resolution the operator had done so far, with no warning
402
+ * and nothing to recover from because that work was never committed anywhere.
403
+ * `REVERT_HEAD` is included for the same reason.
404
+ */
405
+ export declare function pendingGitOperation(cwd: string, deps?: SyncDeps): string | null;
406
+ /** True when a rebase specifically is in progress. Step 8 uses this to decide
407
+ * whether a failed rebase left state worth aborting. Uses `--git-path` so it
408
+ * is correct in a LINKED worktree, where the state lives under
409
+ * `.git/worktrees/<name>/` and not `.git/`. */
410
+ export declare function rebaseInProgress(cwd: string, deps?: SyncDeps): boolean;
411
+ export interface RunSyncOptions {
412
+ worktreePath: string;
413
+ /** Step 0a. The caller's assertion that no teammate is active here. */
414
+ assertNoTeammatesActive: boolean;
415
+ /** Recorded in the audit line as the party that ran the sync. */
416
+ caller: string;
417
+ baseBranch: string;
418
+ worktreeName?: string;
419
+ /** Reapply the checkpoint after a successful sync. Defaults to true. */
420
+ restore?: boolean;
421
+ deps?: SyncDeps;
422
+ }
423
+ export interface RunSyncResult {
424
+ exitCode: number;
425
+ audit: SyncAuditRecord;
426
+ checkpointRef: string | null;
427
+ lines: string[];
428
+ auditWritten: boolean;
429
+ }
430
+ /**
431
+ * The nine-step algorithm from #172, in the plan's order.
432
+ *
433
+ * The checkpoint is step 5: after the quiescence sample at step 4 and before
434
+ * the destructive step at step 7, with a re-sample at step 6 that aborts on
435
+ * change. That ordering puts the checkpoint as late as the design allows, to
436
+ * shrink the window rather than pretend it is closed. Do not reorder it.
437
+ */
438
+ export declare function runWorktreeSyncCore(options: RunSyncOptions): RunSyncResult;
439
+ //# sourceMappingURL=worktree-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worktree-sync.d.ts","sourceRoot":"","sources":["../../src/lib/worktree-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AA+BH;gFACgF;AAChF,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AAEzD;gEACgE;AAChE,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAC/C,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C,iFAAiF;AACjF,eAAO,MAAM,kBAAkB,wBAAwB,CAAC;AAExD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,YAAY,2KAaf,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD,qEAAqE;AACrE,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,aAAa,GAAG,QAAQ,CAAC;AAE5D,MAAM,MAAM,WAAW,GACnB,IAAI;AACN;wCACwC;GACtC,aAAa;AACf;;kBAEkB;GAChB,kBAAkB,GAClB,wBAAwB,GACxB,iCAAiC,GACjC,wBAAwB,GACxB,uBAAuB,GACvB,gCAAgC,GAChC,0BAA0B,GAC1B,uBAAuB,GACvB,0BAA0B,GAC1B,sBAAsB,GACtB,4BAA4B,GAC5B,2BAA2B,GAC3B,mCAAmC;AACrC,+CAA+C;GAC7C,UAAU;AACZ;;;oCAGoC;GAClC,eAAe;AACjB;;sDAEsD;GACpD,gBAAgB,GAChB,OAAO,CAAC;AAEZ,MAAM,WAAW,eAAe;IAC9B,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE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