@ai-atomic-framework/cli 0.1.0-beta.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 (628) hide show
  1. package/README.md +20 -0
  2. package/dist/atm.js +328 -0
  3. package/dist/atm.mjs +4 -0
  4. package/dist/commands/actor-registry.js +359 -0
  5. package/dist/commands/actor-session.js +214 -0
  6. package/dist/commands/actor.js +342 -0
  7. package/dist/commands/agent-confidence.js +137 -0
  8. package/dist/commands/agent-pack.js +327 -0
  9. package/dist/commands/atm-chart/compatibility.js +287 -0
  10. package/dist/commands/atm-chart/constants.js +60 -0
  11. package/dist/commands/atm-chart/render-verify.js +276 -0
  12. package/dist/commands/atm-chart/semver.js +62 -0
  13. package/dist/commands/atm-chart/types.js +1 -0
  14. package/dist/commands/atm-chart.js +49 -0
  15. package/dist/commands/atom-capsule.js +265 -0
  16. package/dist/commands/atom-ref.js +71 -0
  17. package/dist/commands/atomize.js +338 -0
  18. package/dist/commands/baseline.js +285 -0
  19. package/dist/commands/batch/checkpoint-commit-window-policy.js +22 -0
  20. package/dist/commands/batch/deliver-and-close-forwarding.js +60 -0
  21. package/dist/commands/batch/implementation.js +861 -0
  22. package/dist/commands/batch/plan-executor.js +314 -0
  23. package/dist/commands/batch/runner-recovery-forwarding.js +47 -0
  24. package/dist/commands/batch.js +1 -0
  25. package/dist/commands/bootstrap-entry.js +32 -0
  26. package/dist/commands/bootstrap.js +8 -0
  27. package/dist/commands/broker/batch-execute-actions.js +506 -0
  28. package/dist/commands/broker/broker-decision-observation.js +1 -0
  29. package/dist/commands/broker/census/index.js +4 -0
  30. package/dist/commands/broker/implementation.js +59 -0
  31. package/dist/commands/broker/migrate/implementation.js +114 -0
  32. package/dist/commands/broker/mutation-helpers.js +105 -0
  33. package/dist/commands/broker/parallel-admission/closure-observation.js +92 -0
  34. package/dist/commands/broker/parallel-admission/final-verdict.js +168 -0
  35. package/dist/commands/broker/parser.js +495 -0
  36. package/dist/commands/broker/persistence.js +73 -0
  37. package/dist/commands/broker/plan-batch-action.js +178 -0
  38. package/dist/commands/broker/policy-actions.js +64 -0
  39. package/dist/commands/broker/post-compose-semantic-validation.js +143 -0
  40. package/dist/commands/broker/proposal-actions.js +149 -0
  41. package/dist/commands/broker/publication-takeover-admission.js +36 -0
  42. package/dist/commands/broker/reconcile/implementation.js +35 -0
  43. package/dist/commands/broker/registry-actions.js +309 -0
  44. package/dist/commands/broker/replay/closure-policy.js +332 -0
  45. package/dist/commands/broker/replay/command-backed-matrix.js +59 -0
  46. package/dist/commands/broker/replay/dashboard-lifecycle-observations.js +90 -0
  47. package/dist/commands/broker/replay/dashboard-ticket-observations.js +41 -0
  48. package/dist/commands/broker/replay/dashboard-view-model.js +203 -0
  49. package/dist/commands/broker/replay/dashboard.js +31 -0
  50. package/dist/commands/broker/replay/dogfood-orchestrator.js +117 -0
  51. package/dist/commands/broker/replay/final-closure-reader.js +181 -0
  52. package/dist/commands/broker/replay/implementation.js +264 -0
  53. package/dist/commands/broker/replay/run-manifest.js +26 -0
  54. package/dist/commands/broker/replay-actions.js +198 -0
  55. package/dist/commands/broker/runner-sync-supersession.js +6 -0
  56. package/dist/commands/broker/shared-delivery-commit-transaction.js +155 -0
  57. package/dist/commands/broker/shared-surface.js +260 -0
  58. package/dist/commands/broker/steward-queues.js +542 -0
  59. package/dist/commands/broker/steward-runtime-actions.js +295 -0
  60. package/dist/commands/broker/types.js +1 -0
  61. package/dist/commands/broker/wave-scheduler-actions.js +73 -0
  62. package/dist/commands/broker-conflict-resolution.js +66 -0
  63. package/dist/commands/broker.js +1 -0
  64. package/dist/commands/budget.js +108 -0
  65. package/dist/commands/build-release-hygiene.js +94 -0
  66. package/dist/commands/cache.js +235 -0
  67. package/dist/commands/candidates.js +509 -0
  68. package/dist/commands/cleanup/index.js +1 -0
  69. package/dist/commands/cleanup/run.js +38 -0
  70. package/dist/commands/command-specs/_common.js +24 -0
  71. package/dist/commands/command-specs/actor.spec.js +33 -0
  72. package/dist/commands/command-specs/agent-pack.spec.js +24 -0
  73. package/dist/commands/command-specs/atm-chart.spec.js +21 -0
  74. package/dist/commands/command-specs/atom-capsule.spec.js +30 -0
  75. package/dist/commands/command-specs/atom-ref.spec.js +20 -0
  76. package/dist/commands/command-specs/atomize.spec.js +40 -0
  77. package/dist/commands/command-specs/baseline.spec.js +25 -0
  78. package/dist/commands/command-specs/batch.spec.js +59 -0
  79. package/dist/commands/command-specs/bootstrap.spec.js +19 -0
  80. package/dist/commands/command-specs/broker.spec.js +95 -0
  81. package/dist/commands/command-specs/budget.spec.js +23 -0
  82. package/dist/commands/command-specs/cache.spec.js +24 -0
  83. package/dist/commands/command-specs/candidates.spec.js +24 -0
  84. package/dist/commands/command-specs/cleanup.spec.js +21 -0
  85. package/dist/commands/command-specs/create-map.spec.js +25 -0
  86. package/dist/commands/command-specs/create.spec.js +20 -0
  87. package/dist/commands/command-specs/daemon.spec.js +22 -0
  88. package/dist/commands/command-specs/doctor.spec.js +18 -0
  89. package/dist/commands/command-specs/emergency.spec.js +34 -0
  90. package/dist/commands/command-specs/evidence.spec.js +104 -0
  91. package/dist/commands/command-specs/experience.spec.js +26 -0
  92. package/dist/commands/command-specs/explain.spec.js +18 -0
  93. package/dist/commands/command-specs/framework-mode.spec.js +28 -0
  94. package/dist/commands/command-specs/git-hooks.spec.js +21 -0
  95. package/dist/commands/command-specs/git.spec.js +84 -0
  96. package/dist/commands/command-specs/guard.spec.js +30 -0
  97. package/dist/commands/command-specs/guide.spec.js +34 -0
  98. package/dist/commands/command-specs/handoff.spec.js +19 -0
  99. package/dist/commands/command-specs/health-report.spec.js +16 -0
  100. package/dist/commands/command-specs/hook.spec.js +22 -0
  101. package/dist/commands/command-specs/identity.spec.js +34 -0
  102. package/dist/commands/command-specs/init.spec.js +21 -0
  103. package/dist/commands/command-specs/integration.spec.js +43 -0
  104. package/dist/commands/command-specs/internal-release.spec.js +30 -0
  105. package/dist/commands/command-specs/lane.spec.js +32 -0
  106. package/dist/commands/command-specs/lock.spec.js +21 -0
  107. package/dist/commands/command-specs/map-capsule.spec.js +27 -0
  108. package/dist/commands/command-specs/migrate.spec.js +23 -0
  109. package/dist/commands/command-specs/next.spec.js +68 -0
  110. package/dist/commands/command-specs/orient.spec.js +15 -0
  111. package/dist/commands/command-specs/plan.spec.js +58 -0
  112. package/dist/commands/command-specs/police.spec.js +22 -0
  113. package/dist/commands/command-specs/quickfix.spec.js +21 -0
  114. package/dist/commands/command-specs/registry-diff.spec.js +21 -0
  115. package/dist/commands/command-specs/registry.spec.js +35 -0
  116. package/dist/commands/command-specs/replacement-lane.spec.js +25 -0
  117. package/dist/commands/command-specs/rescue.spec.js +29 -0
  118. package/dist/commands/command-specs/residue.spec.js +37 -0
  119. package/dist/commands/command-specs/review-advisory.spec.js +27 -0
  120. package/dist/commands/command-specs/review.spec.js +28 -0
  121. package/dist/commands/command-specs/rollback.spec.js +29 -0
  122. package/dist/commands/command-specs/route.spec.js +43 -0
  123. package/dist/commands/command-specs/self-host-alpha.spec.js +18 -0
  124. package/dist/commands/command-specs/spec.spec.js +17 -0
  125. package/dist/commands/command-specs/start.spec.js +22 -0
  126. package/dist/commands/command-specs/status.spec.js +16 -0
  127. package/dist/commands/command-specs/task-view.spec.js +18 -0
  128. package/dist/commands/command-specs/taskflow.spec.js +77 -0
  129. package/dist/commands/command-specs/tasks.spec.js +157 -0
  130. package/dist/commands/command-specs/team.spec.js +159 -0
  131. package/dist/commands/command-specs/telemetry.spec.js +55 -0
  132. package/dist/commands/command-specs/test.spec.js +39 -0
  133. package/dist/commands/command-specs/upgrade.spec.js +62 -0
  134. package/dist/commands/command-specs/validate.spec.js +28 -0
  135. package/dist/commands/command-specs/verify.spec.js +20 -0
  136. package/dist/commands/command-specs/welcome.spec.js +18 -0
  137. package/dist/commands/command-specs/write-ticket.spec.js +34 -0
  138. package/dist/commands/command-specs.js +150 -0
  139. package/dist/commands/create-map.js +285 -0
  140. package/dist/commands/create.js +106 -0
  141. package/dist/commands/daemon.js +268 -0
  142. package/dist/commands/doctor/constants.js +76 -0
  143. package/dist/commands/doctor/lifecycle.js +106 -0
  144. package/dist/commands/doctor/policy.js +114 -0
  145. package/dist/commands/doctor/readiness.js +114 -0
  146. package/dist/commands/doctor/run-doctor.js +356 -0
  147. package/dist/commands/doctor/types.js +1 -0
  148. package/dist/commands/doctor/utilities.js +120 -0
  149. package/dist/commands/doctor.js +1 -0
  150. package/dist/commands/emergency/context.js +21 -0
  151. package/dist/commands/emergency/gate.js +103 -0
  152. package/dist/commands/emergency/leases.js +154 -0
  153. package/dist/commands/emergency/protected-override-audit.js +122 -0
  154. package/dist/commands/emergency/registry.js +176 -0
  155. package/dist/commands/emergency.js +219 -0
  156. package/dist/commands/evidence/bundle-io/implementation.js +896 -0
  157. package/dist/commands/evidence/bundle-io.js +1 -0
  158. package/dist/commands/evidence/command-runs.js +280 -0
  159. package/dist/commands/evidence/evidence-store.js +94 -0
  160. package/dist/commands/evidence/historical-batch-finalize.js +1 -0
  161. package/dist/commands/evidence/historical-batch.js +1 -0
  162. package/dist/commands/evidence/missing-report.js +380 -0
  163. package/dist/commands/evidence/observed-source-loader.js +54 -0
  164. package/dist/commands/evidence/shared-utils.js +18 -0
  165. package/dist/commands/evidence/validator-classification.js +182 -0
  166. package/dist/commands/evidence/verbs/add.js +1 -0
  167. package/dist/commands/evidence/verbs/diagnose.js +190 -0
  168. package/dist/commands/evidence/verbs/diff.js +1 -0
  169. package/dist/commands/evidence/verbs/git-head-backfill.js +1 -0
  170. package/dist/commands/evidence/verbs/missing.js +1 -0
  171. package/dist/commands/evidence/verbs/run.js +287 -0
  172. package/dist/commands/evidence/verbs/validators.js +1 -0
  173. package/dist/commands/evidence/verbs/verify.js +1 -0
  174. package/dist/commands/evidence/verbs/wave-exit-observer.js +212 -0
  175. package/dist/commands/evidence.js +39 -0
  176. package/dist/commands/experience.js +242 -0
  177. package/dist/commands/explain.js +49 -0
  178. package/dist/commands/first-use-notice.js +54 -0
  179. package/dist/commands/framework-development/build-release-hygiene-hints.js +7 -0
  180. package/dist/commands/framework-development/closure-packet/diagnostics.js +24 -0
  181. package/dist/commands/framework-development/closure-packet/schema-fragments.js +1 -0
  182. package/dist/commands/framework-development/closure-packet/validator-contract.js +1 -0
  183. package/dist/commands/framework-development/closure-packet-schema/implementation.js +1134 -0
  184. package/dist/commands/framework-development/closure-packet-schema.js +3 -0
  185. package/dist/commands/framework-development/critical-path-gate.js +1 -0
  186. package/dist/commands/framework-development/framework-lock-context.js +35 -0
  187. package/dist/commands/framework-development/framework-temp-lock-projection.js +81 -0
  188. package/dist/commands/framework-development/framework-temp-publication-capability.js +270 -0
  189. package/dist/commands/framework-development/historical-delivery-provenance.js +12 -0
  190. package/dist/commands/framework-development/path-classification.js +34 -0
  191. package/dist/commands/framework-development/runner-publication-close-handoff.js +86 -0
  192. package/dist/commands/framework-development/runner-publication-lifecycle.js +412 -0
  193. package/dist/commands/framework-development/runner-publication-receipt.js +29 -0
  194. package/dist/commands/framework-development/runner-sync-admission.js +337 -0
  195. package/dist/commands/framework-development/runner-sync-lease-health.js +36 -0
  196. package/dist/commands/framework-development/runner-sync-queue-ownership.js +202 -0
  197. package/dist/commands/framework-development/sha256-normalization.js +1 -0
  198. package/dist/commands/framework-development/temp-claim.js +1 -0
  199. package/dist/commands/framework-development.js +7 -0
  200. package/dist/commands/git/record-commit.js +2 -0
  201. package/dist/commands/git-governance/branch-commit-coordinator.js +119 -0
  202. package/dist/commands/git-governance/commit-bundle-filter.js +37 -0
  203. package/dist/commands/git-governance/commit-scope-policy.js +182 -0
  204. package/dist/commands/git-governance/governance-residue-policy.js +18 -0
  205. package/dist/commands/git-governance/implementation/admission-command.js +231 -0
  206. package/dist/commands/git-governance/implementation/branch-commit-window.js +204 -0
  207. package/dist/commands/git-governance/implementation/broker-hook-bypass-preflight.js +227 -0
  208. package/dist/commands/git-governance/implementation/command-router.js +199 -0
  209. package/dist/commands/git-governance/implementation/commit-attempt-boundary.js +76 -0
  210. package/dist/commands/git-governance/implementation/commit-authority-scopes.js +61 -0
  211. package/dist/commands/git-governance/implementation/commit-bundle-resolution.js +502 -0
  212. package/dist/commands/git-governance/implementation/commit-bundle-selection.js +9 -0
  213. package/dist/commands/git-governance/implementation/commit-candidate-preparation.js +68 -0
  214. package/dist/commands/git-governance/implementation/commit-command.js +198 -0
  215. package/dist/commands/git-governance/implementation/commit-execution.js +400 -0
  216. package/dist/commands/git-governance/implementation/commit-framework-branch.js +105 -0
  217. package/dist/commands/git-governance/implementation/commit-task-scoped-branch.js +161 -0
  218. package/dist/commands/git-governance/implementation/dry-run-purity.js +54 -0
  219. package/dist/commands/git-governance/implementation/framework-commit-claim-guard.js +21 -0
  220. package/dist/commands/git-governance/implementation/framework-hook-identity.js +12 -0
  221. package/dist/commands/git-governance/implementation/git-command-options.js +258 -0
  222. package/dist/commands/git-governance/implementation/git-config-port.js +25 -0
  223. package/dist/commands/git-governance/implementation/git-head-evidence-transaction.js +275 -0
  224. package/dist/commands/git-governance/implementation/git-index-lock-recovery.js +41 -0
  225. package/dist/commands/git-governance/implementation/git-index-transaction.js +415 -0
  226. package/dist/commands/git-governance/implementation/git-process-port.js +261 -0
  227. package/dist/commands/git-governance/implementation/hook-bypass-commit-boundary.js +20 -0
  228. package/dist/commands/git-governance/implementation/hook-failure-diagnostics.js +59 -0
  229. package/dist/commands/git-governance/implementation/identity-check-command.js +403 -0
  230. package/dist/commands/git-governance/implementation/index-restoration.js +80 -0
  231. package/dist/commands/git-governance/implementation/lease-command.js +112 -0
  232. package/dist/commands/git-governance/implementation/live-index-drain.js +124 -0
  233. package/dist/commands/git-governance/implementation/live-index-lock-retry.js +72 -0
  234. package/dist/commands/git-governance/implementation/live-index-reconciliation.js +420 -0
  235. package/dist/commands/git-governance/implementation/pathspec-argv-batching.js +124 -0
  236. package/dist/commands/git-governance/implementation/push-command.js +485 -0
  237. package/dist/commands/git-governance/implementation/record-bundle-inspection.js +244 -0
  238. package/dist/commands/git-governance/implementation/record-commit-command.js +262 -0
  239. package/dist/commands/git-governance/implementation/sealed-commit-attribution.js +429 -0
  240. package/dist/commands/git-governance/implementation/task-scope-staging.js +383 -0
  241. package/dist/commands/git-governance/implementation.js +11 -0
  242. package/dist/commands/git-governance/protected-governance-state.js +136 -0
  243. package/dist/commands/git-governance/record-commit-payload-assertion.js +48 -0
  244. package/dist/commands/git-governance/record-only-block-lifecycle-bridge.js +227 -0
  245. package/dist/commands/git-governance/task-scoped-commit-transaction.js +42 -0
  246. package/dist/commands/git-governance/validate-atom-file-size.js +54 -0
  247. package/dist/commands/git-governance/work-admission-check.js +201 -0
  248. package/dist/commands/git-governance.js +338 -0
  249. package/dist/commands/git-head-evidence.js +354 -0
  250. package/dist/commands/git-index-ownership.js +411 -0
  251. package/dist/commands/git-worktree-readiness.js +127 -0
  252. package/dist/commands/git.js +169 -0
  253. package/dist/commands/glossary-data.js +52 -0
  254. package/dist/commands/governance-runtime.js +198 -0
  255. package/dist/commands/guard.js +338 -0
  256. package/dist/commands/guide.js +486 -0
  257. package/dist/commands/handoff.js +107 -0
  258. package/dist/commands/hash-placeholder-audit.js +57 -0
  259. package/dist/commands/health-report.js +30 -0
  260. package/dist/commands/help.js +69 -0
  261. package/dist/commands/hook/commit-range-guard/args.js +48 -0
  262. package/dist/commands/hook/commit-range-guard/baseline.js +43 -0
  263. package/dist/commands/hook/commit-range-guard/implementation.js +514 -0
  264. package/dist/commands/hook/commit-range-guard/support.js +6 -0
  265. package/dist/commands/hook/commit-range-guard.js +4 -0
  266. package/dist/commands/hook/context-map-advisor.js +210 -0
  267. package/dist/commands/hook/git-hooks-installer.js +156 -0
  268. package/dist/commands/hook/git-index-diagnostics.js +81 -0
  269. package/dist/commands/hook/pre-commit/close-transaction-receipt.js +110 -0
  270. package/dist/commands/hook/pre-commit/committed-task-context.js +37 -0
  271. package/dist/commands/hook/pre-commit/cross-file-consistency.js +423 -0
  272. package/dist/commands/hook/pre-commit/cross-task-admission.js +135 -0
  273. package/dist/commands/hook/pre-commit/failure-envelope.js +340 -0
  274. package/dist/commands/hook/pre-commit/framework-lock-context.js +9 -0
  275. package/dist/commands/hook/pre-commit/framework-temp-claim-attribution.js +29 -0
  276. package/dist/commands/hook/pre-commit/implementation.js +433 -0
  277. package/dist/commands/hook/pre-commit/input-state.js +208 -0
  278. package/dist/commands/hook/pre-commit/residue-candidates.js +15 -0
  279. package/dist/commands/hook/pre-commit/scope-ownership.js +380 -0
  280. package/dist/commands/hook/pre-commit/support.js +965 -0
  281. package/dist/commands/hook/pre-commit/team-gate-findings.js +19 -0
  282. package/dist/commands/hook/pre-commit.js +2 -0
  283. package/dist/commands/hook/pre-push.js +447 -0
  284. package/dist/commands/hook.js +65 -0
  285. package/dist/commands/identity.js +244 -0
  286. package/dist/commands/init.js +201 -0
  287. package/dist/commands/integration/adapter-parity.js +74 -0
  288. package/dist/commands/integration/adapters.js +127 -0
  289. package/dist/commands/integration/bootstrap.js +109 -0
  290. package/dist/commands/integration/health.js +253 -0
  291. package/dist/commands/integration/install.js +46 -0
  292. package/dist/commands/integration/list.js +16 -0
  293. package/dist/commands/integration/run.js +208 -0
  294. package/dist/commands/integration/types.js +1 -0
  295. package/dist/commands/integration-hooks/implementation.js +807 -0
  296. package/dist/commands/integration-hooks.js +1 -0
  297. package/dist/commands/integration.js +5 -0
  298. package/dist/commands/internal-release/command.js +113 -0
  299. package/dist/commands/internal-release/constants.js +5 -0
  300. package/dist/commands/internal-release/options.js +79 -0
  301. package/dist/commands/internal-release/publication.js +104 -0
  302. package/dist/commands/internal-release/scratch.js +72 -0
  303. package/dist/commands/internal-release/support.js +79 -0
  304. package/dist/commands/internal-release/target-sync.js +122 -0
  305. package/dist/commands/internal-release/types.js +1 -0
  306. package/dist/commands/internal-release.js +2 -0
  307. package/dist/commands/lane-session/adopt-rebind.js +113 -0
  308. package/dist/commands/lane-session/capability-authority.js +223 -0
  309. package/dist/commands/lane-session/events.js +102 -0
  310. package/dist/commands/lane-session/mutation-authority-adapter.js +96 -0
  311. package/dist/commands/lane-session/mutation-status-command.js +61 -0
  312. package/dist/commands/lane-session/proxy-receipt.js +219 -0
  313. package/dist/commands/lane-session/redaction.js +66 -0
  314. package/dist/commands/lane-session/resolve.js +114 -0
  315. package/dist/commands/lane-session/store.js +336 -0
  316. package/dist/commands/lane.js +550 -0
  317. package/dist/commands/lock.js +132 -0
  318. package/dist/commands/map-capsule.js +194 -0
  319. package/dist/commands/migrate.js +193 -0
  320. package/dist/commands/next/active-work-summary.js +88 -0
  321. package/dist/commands/next/broker-queue-admission.js +95 -0
  322. package/dist/commands/next/channel-strategy.js +172 -0
  323. package/dist/commands/next/claim-admission.js +254 -0
  324. package/dist/commands/next/claim-cleanup.js +24 -0
  325. package/dist/commands/next/claim-conflict-log.js +122 -0
  326. package/dist/commands/next/claim-delivery-admission.js +35 -0
  327. package/dist/commands/next/claim-early-results.js +120 -0
  328. package/dist/commands/next/claim-helpers.js +81 -0
  329. package/dist/commands/next/claim-lane-session.js +38 -0
  330. package/dist/commands/next/claim-orchestration.js +579 -0
  331. package/dist/commands/next/claim-parallel-preflight.js +368 -0
  332. package/dist/commands/next/claim-readiness.js +158 -0
  333. package/dist/commands/next/claim-scope-expansion-admission.js +22 -0
  334. package/dist/commands/next/cross-repo-framework-result.js +40 -0
  335. package/dist/commands/next/foreign-dirty-wip-admission.js +162 -0
  336. package/dist/commands/next/governance-readiness.js +149 -0
  337. package/dist/commands/next/intent-normalizers.js +212 -0
  338. package/dist/commands/next/match-and-sort.js +183 -0
  339. package/dist/commands/next/next-action-assembly.js +118 -0
  340. package/dist/commands/next/oversized-extraction-admission.js +79 -0
  341. package/dist/commands/next/plan-scoped-preflight.js +145 -0
  342. package/dist/commands/next/planning-root-preference.js +264 -0
  343. package/dist/commands/next/playbook-projection/active-work-summary.js +380 -0
  344. package/dist/commands/next/playbook-projection/channel-playbook.js +198 -0
  345. package/dist/commands/next/playbook-projection/governance-readiness.js +67 -0
  346. package/dist/commands/next/playbook-projection/legacy-guidance.js +151 -0
  347. package/dist/commands/next/playbook-projection/message-assembly.js +120 -0
  348. package/dist/commands/next/playbook-projection/task-reservation-projection.js +126 -0
  349. package/dist/commands/next/playbook-projection/task-routing.js +275 -0
  350. package/dist/commands/next/playbook-projection.js +7 -0
  351. package/dist/commands/next/profiler.js +22 -0
  352. package/dist/commands/next/prompt-guidance-result.js +177 -0
  353. package/dist/commands/next/prompt-result-contracts.js +273 -0
  354. package/dist/commands/next/prompt-results.js +505 -0
  355. package/dist/commands/next/prompt-scope-resolution.js +12 -0
  356. package/dist/commands/next/proposal-lane.js +122 -0
  357. package/dist/commands/next/result-compaction.js +120 -0
  358. package/dist/commands/next/route-predicates.js +112 -0
  359. package/dist/commands/next/route-resolution/artifact-scope.js +215 -0
  360. package/dist/commands/next/route-resolution/intent.js +163 -0
  361. package/dist/commands/next/route-resolution/matching.js +446 -0
  362. package/dist/commands/next/route-resolution/pending-worktree.js +257 -0
  363. package/dist/commands/next/route-resolution/queue-inspection.js +391 -0
  364. package/dist/commands/next/route-resolution/runtime.js +111 -0
  365. package/dist/commands/next/route-resolution/task-card-discovery.js +190 -0
  366. package/dist/commands/next/route-resolution.js +7 -0
  367. package/dist/commands/next/runner-mode.js +98 -0
  368. package/dist/commands/next/runner-recovery-claim-authorization.js +30 -0
  369. package/dist/commands/next/task-scoped-claim-command.js +24 -0
  370. package/dist/commands/next/view-projections.js +51 -0
  371. package/dist/commands/next/worktree-hints.js +11 -0
  372. package/dist/commands/next-active-batch.js +39 -0
  373. package/dist/commands/next.js +257 -0
  374. package/dist/commands/orient.js +22 -0
  375. package/dist/commands/output-projection.js +37 -0
  376. package/dist/commands/plan.js +458 -0
  377. package/dist/commands/planning-repo-root.js +312 -0
  378. package/dist/commands/planning-root-resolution-cache.js +0 -0
  379. package/dist/commands/police.js +166 -0
  380. package/dist/commands/quickfix.js +76 -0
  381. package/dist/commands/registry/lineage-normalization.js +125 -0
  382. package/dist/commands/registry-diff.js +145 -0
  383. package/dist/commands/registry-shared.js +153 -0
  384. package/dist/commands/registry.js +533 -0
  385. package/dist/commands/replacement-lane.js +82 -0
  386. package/dist/commands/rescue.js +306 -0
  387. package/dist/commands/residue.js +483 -0
  388. package/dist/commands/review-advisory.js +480 -0
  389. package/dist/commands/review.js +514 -0
  390. package/dist/commands/rollback.js +271 -0
  391. package/dist/commands/route/files.js +42 -0
  392. package/dist/commands/route/freeze-patch.js +141 -0
  393. package/dist/commands/route/lifecycle.js +206 -0
  394. package/dist/commands/route/main.js +10 -0
  395. package/dist/commands/route/parser.js +177 -0
  396. package/dist/commands/route/takeover.js +152 -0
  397. package/dist/commands/route/types.js +2 -0
  398. package/dist/commands/route/validation.js +77 -0
  399. package/dist/commands/route.js +1 -0
  400. package/dist/commands/runner-sync.js +2 -0
  401. package/dist/commands/runtime-adapter-readiness.js +150 -0
  402. package/dist/commands/self-host-alpha.js +293 -0
  403. package/dist/commands/shared/command-manifest.js +104 -0
  404. package/dist/commands/shared/command-spec-output.js +304 -0
  405. package/dist/commands/shared/identity-normalization.js +208 -0
  406. package/dist/commands/shared/option-and-file-tools.js +451 -0
  407. package/dist/commands/shared/result-core.js +292 -0
  408. package/dist/commands/shared.js +3 -0
  409. package/dist/commands/spec-shared.js +108 -0
  410. package/dist/commands/spec.js +13 -0
  411. package/dist/commands/start.js +115 -0
  412. package/dist/commands/status.js +214 -0
  413. package/dist/commands/task-direction/active-locks.js +98 -0
  414. package/dist/commands/task-direction/scope-policy.js +104 -0
  415. package/dist/commands/task-direction/support.js +204 -0
  416. package/dist/commands/task-direction.js +305 -0
  417. package/dist/commands/task-intent.js +163 -0
  418. package/dist/commands/task-ledger.js +149 -0
  419. package/dist/commands/task-view.js +146 -0
  420. package/dist/commands/taskflow/auto-evidence-mapper.js +147 -0
  421. package/dist/commands/taskflow/branch-commit-queue-gate.js +127 -0
  422. package/dist/commands/taskflow/broker-gate.js +253 -0
  423. package/dist/commands/taskflow/close-orchestration.js +511 -0
  424. package/dist/commands/taskflow/close-owned-delivery-dirty-admission.js +70 -0
  425. package/dist/commands/taskflow/close-preflight.js +403 -0
  426. package/dist/commands/taskflow/close-side-effect-reconcile.js +51 -0
  427. package/dist/commands/taskflow/close-transaction-hook-receipt.js +36 -0
  428. package/dist/commands/taskflow/close-transaction-mutex.js +108 -0
  429. package/dist/commands/taskflow/closeback-orchestration.js +204 -0
  430. package/dist/commands/taskflow/commit-bundle-assembly.js +613 -0
  431. package/dist/commands/taskflow/commit-messages.js +9 -0
  432. package/dist/commands/taskflow/cross-authority-closeback.js +308 -0
  433. package/dist/commands/taskflow/current-task-close-evidence.js +51 -0
  434. package/dist/commands/taskflow/dirty-blockers.js +46 -0
  435. package/dist/commands/taskflow/governance-dirty-deferral.js +21 -0
  436. package/dist/commands/taskflow/historical-close-preflight.js +426 -0
  437. package/dist/commands/taskflow/host-opener-policy.js +229 -0
  438. package/dist/commands/taskflow/implementation.js +722 -0
  439. package/dist/commands/taskflow/markdown-paths.js +7 -0
  440. package/dist/commands/taskflow/profile-loader.js +280 -0
  441. package/dist/commands/taskflow/runner-publication-close-queue.js +31 -0
  442. package/dist/commands/taskflow/runner-recovery-forwarding.js +55 -0
  443. package/dist/commands/taskflow/runner-selection-evidence.js +26 -0
  444. package/dist/commands/taskflow/task-scope.js +84 -0
  445. package/dist/commands/taskflow/transaction-status.js +3 -0
  446. package/dist/commands/taskflow/write-readiness.js +323 -0
  447. package/dist/commands/taskflow.js +1 -0
  448. package/dist/commands/tasks/acceptance-evidence-import.js +119 -0
  449. package/dist/commands/tasks/canonical-task-id-boundary.js +23 -0
  450. package/dist/commands/tasks/claim-intent.js +110 -0
  451. package/dist/commands/tasks/claim-orchestrator.js +559 -0
  452. package/dist/commands/tasks/claim-ownership.js +145 -0
  453. package/dist/commands/tasks/claim-preparation.js +251 -0
  454. package/dist/commands/tasks/claim-repair-diagnostics.js +466 -0
  455. package/dist/commands/tasks/claim-work-admission.js +290 -0
  456. package/dist/commands/tasks/close-governance.js +173 -0
  457. package/dist/commands/tasks/close-helpers/broker-admission-explanation.js +75 -0
  458. package/dist/commands/tasks/close-helpers/close-artifact-staging.js +257 -0
  459. package/dist/commands/tasks/close-helpers/close-window-diagnostics.js +172 -0
  460. package/dist/commands/tasks/close-helpers/task-transition-writer.js +108 -0
  461. package/dist/commands/tasks/close-orchestrator/acceptance-evidence-gate.js +84 -0
  462. package/dist/commands/tasks/close-orchestrator/close-result.js +35 -0
  463. package/dist/commands/tasks/close-orchestrator/close-write.js +200 -0
  464. package/dist/commands/tasks/close-orchestrator/closure-packet.js +109 -0
  465. package/dist/commands/tasks/close-orchestrator/historical-context.js +48 -0
  466. package/dist/commands/tasks/close-orchestrator/runner-recovery.js +30 -0
  467. package/dist/commands/tasks/close-orchestrator.js +535 -0
  468. package/dist/commands/tasks/close-window-lock.js +420 -0
  469. package/dist/commands/tasks/close-window-residue-classification.js +137 -0
  470. package/dist/commands/tasks/close-window-staged-index-admission.js +20 -0
  471. package/dist/commands/tasks/closeout-provenance.js +126 -0
  472. package/dist/commands/tasks/closeout-signaling.js +1 -0
  473. package/dist/commands/tasks/command-dispatch.js +86 -0
  474. package/dist/commands/tasks/contract-import-recovery.js +17 -0
  475. package/dist/commands/tasks/deliver-close-orchestrator.js +251 -0
  476. package/dist/commands/tasks/dependency-gate.js +429 -0
  477. package/dist/commands/tasks/dependency-gates.js +1 -0
  478. package/dist/commands/tasks/generated-residue-policy.js +121 -0
  479. package/dist/commands/tasks/historical-delivery.js +411 -0
  480. package/dist/commands/tasks/import-card-contract-validation.js +124 -0
  481. package/dist/commands/tasks/import-orchestrator.js +488 -0
  482. package/dist/commands/tasks/import-planning-authority.js +1 -0
  483. package/dist/commands/tasks/import-task.js +150 -0
  484. package/dist/commands/tasks/import-validation.js +70 -0
  485. package/dist/commands/tasks/import-verify.js +195 -0
  486. package/dist/commands/tasks/is-frontmatter-scalar-helper.js +9 -0
  487. package/dist/commands/tasks/legacy/compat-command-map.js +4 -0
  488. package/dist/commands/tasks/legacy/implementation.js +1176 -0
  489. package/dist/commands/tasks/legacy/repair-reconcile-lane.js +3 -0
  490. package/dist/commands/tasks/legacy/transition-compat.js +3 -0
  491. package/dist/commands/tasks/legacy-impl.js +2 -0
  492. package/dist/commands/tasks/lifecycle-state.js +151 -0
  493. package/dist/commands/tasks/normalize-string-value-helper.js +6 -0
  494. package/dist/commands/tasks/normalize-task-document-id-helper.js +7 -0
  495. package/dist/commands/tasks/plan-import-boundary.js +58 -0
  496. package/dist/commands/tasks/planning-mirror-close-diagnostics.js +95 -0
  497. package/dist/commands/tasks/planning-root-authorship.js +153 -0
  498. package/dist/commands/tasks/planning-source-seal-policy.js +125 -0
  499. package/dist/commands/tasks/public-surface.js +11 -0
  500. package/dist/commands/tasks/read-projection.js +213 -0
  501. package/dist/commands/tasks/realign-plan-source.js +437 -0
  502. package/dist/commands/tasks/reconcile-orchestrator.js +342 -0
  503. package/dist/commands/tasks/release-wip-transaction.js +59 -0
  504. package/dist/commands/tasks/repair-claim-orchestrator.js +174 -0
  505. package/dist/commands/tasks/repairclose-orchestrator.js +232 -0
  506. package/dist/commands/tasks/residue-diagnostics.js +175 -0
  507. package/dist/commands/tasks/result-contracts.js +43 -0
  508. package/dist/commands/tasks/scope-amendment/implementation.js +137 -0
  509. package/dist/commands/tasks/scope-lock-diagnostics.js +234 -0
  510. package/dist/commands/tasks/scope-preflight/implementation.js +24 -0
  511. package/dist/commands/tasks/scope-queue.js +13 -0
  512. package/dist/commands/tasks/seal-plan-source.js +98 -0
  513. package/dist/commands/tasks/sha256-helper.js +7 -0
  514. package/dist/commands/tasks/status-triangulation.js +284 -0
  515. package/dist/commands/tasks/surface-invariants.js +84 -0
  516. package/dist/commands/tasks/takeover-evidence.js +29 -0
  517. package/dist/commands/tasks/task-atomization-policy-import.js +139 -0
  518. package/dist/commands/tasks/task-card-contract-import.js +336 -0
  519. package/dist/commands/tasks/task-card-writer.js +13 -0
  520. package/dist/commands/tasks/task-file-io-helpers.js +62 -0
  521. package/dist/commands/tasks/task-frontmatter-fidelity.js +269 -0
  522. package/dist/commands/tasks/task-git-helpers.js +40 -0
  523. package/dist/commands/tasks/task-import-diagnostics.js +45 -0
  524. package/dist/commands/tasks/task-import-status-normalization.js +20 -0
  525. package/dist/commands/tasks/task-import-validators.js +442 -0
  526. package/dist/commands/tasks/task-ledger-readers.js +102 -0
  527. package/dist/commands/tasks/task-markdown-helpers.js +358 -0
  528. package/dist/commands/tasks/task-option-parsers/close-delivery-options.js +156 -0
  529. package/dist/commands/tasks/task-option-parsers/create-close-options.js +233 -0
  530. package/dist/commands/tasks/task-option-parsers/helpers.js +37 -0
  531. package/dist/commands/tasks/task-option-parsers/misc-claim-options.js +350 -0
  532. package/dist/commands/tasks/task-option-parsers/scope-options.js +211 -0
  533. package/dist/commands/tasks/task-option-parsers/status-options.js +43 -0
  534. package/dist/commands/tasks/task-option-parsers.js +6 -0
  535. package/dist/commands/tasks/task-transition-helpers.js +166 -0
  536. package/dist/commands/tasks/task-work-admission-import.js +54 -0
  537. package/dist/commands/tasks/verify-orchestrator.js +160 -0
  538. package/dist/commands/tasks.js +5 -0
  539. package/dist/commands/team/admission-command.js +7 -0
  540. package/dist/commands/team/admission.js +141 -0
  541. package/dist/commands/team/command-registry.js +26 -0
  542. package/dist/commands/team/composer.js +78 -0
  543. package/dist/commands/team/cost-command.js +27 -0
  544. package/dist/commands/team/efficiency-controller.js +198 -0
  545. package/dist/commands/team/execute-command.js +6 -0
  546. package/dist/commands/team/growth-contract.js +128 -0
  547. package/dist/commands/team/legacy/broker-observability.js +366 -0
  548. package/dist/commands/team/legacy/command-runner.js +348 -0
  549. package/dist/commands/team/legacy/crew-decision-policy.js +418 -0
  550. package/dist/commands/team/legacy/handoff-handler.js +60 -0
  551. package/dist/commands/team/legacy/implementer-selector-policy.js +209 -0
  552. package/dist/commands/team/legacy/lifecycle-handler.js +163 -0
  553. package/dist/commands/team/legacy/patrol-contracts.js +212 -0
  554. package/dist/commands/team/legacy/patrol-handler.js +213 -0
  555. package/dist/commands/team/legacy/permission-lease-policy.js +386 -0
  556. package/dist/commands/team/legacy/plan-orchestration.js +360 -0
  557. package/dist/commands/team/legacy/planning-context.js +314 -0
  558. package/dist/commands/team/legacy/provider-execution.js +337 -0
  559. package/dist/commands/team/legacy/runtime-contracts.js +241 -0
  560. package/dist/commands/team/legacy/runtime-governance.js +419 -0
  561. package/dist/commands/team/legacy/team-run-runtime.js +186 -0
  562. package/dist/commands/team/legacy/team-run-store.js +160 -0
  563. package/dist/commands/team/legacy/team-utils.js +102 -0
  564. package/dist/commands/team/legacy/types.js +150 -0
  565. package/dist/commands/team/plan-command.js +4 -0
  566. package/dist/commands/team/proposal-workspace.js +139 -0
  567. package/dist/commands/team/provider-preflight.js +57 -0
  568. package/dist/commands/team/report-command.js +14 -0
  569. package/dist/commands/team/role-provider-resolution.js +46 -0
  570. package/dist/commands/team/role-skill-packs.js +238 -0
  571. package/dist/commands/team/runtime-bridges.js +81 -0
  572. package/dist/commands/team/runtime-tier-contract.js +32 -0
  573. package/dist/commands/team/scheduler.js +165 -0
  574. package/dist/commands/team/shadow-plan.js +77 -0
  575. package/dist/commands/team/shadow-workspace.js +1 -0
  576. package/dist/commands/team/start-command.js +4 -0
  577. package/dist/commands/team/status-command.js +4 -0
  578. package/dist/commands/team/team-execution-lane.js +66 -0
  579. package/dist/commands/team/team-route-map.js +55 -0
  580. package/dist/commands/team-knowledge/actions.js +210 -0
  581. package/dist/commands/team-knowledge/main.js +36 -0
  582. package/dist/commands/team-knowledge/metadata.js +120 -0
  583. package/dist/commands/team-knowledge/permission.js +34 -0
  584. package/dist/commands/team-knowledge/ranking.js +186 -0
  585. package/dist/commands/team-knowledge/runtime-utils.js +105 -0
  586. package/dist/commands/team-knowledge/spec.js +30 -0
  587. package/dist/commands/team-knowledge/summary.js +55 -0
  588. package/dist/commands/team-knowledge/text-utils.js +29 -0
  589. package/dist/commands/team-knowledge/types.js +1 -0
  590. package/dist/commands/team-knowledge.js +2 -0
  591. package/dist/commands/team-legacy.js +101 -0
  592. package/dist/commands/team-runtime-cleanup.js +56 -0
  593. package/dist/commands/team-runtime-gates.js +198 -0
  594. package/dist/commands/team-wave.js +387 -0
  595. package/dist/commands/team.js +2 -0
  596. package/dist/commands/telemetry.js +149 -0
  597. package/dist/commands/test-catalog.js +354 -0
  598. package/dist/commands/test.js +301 -0
  599. package/dist/commands/upgrade/canary.js +45 -0
  600. package/dist/commands/upgrade/experimental.js +97 -0
  601. package/dist/commands/upgrade/next-action-hint.js +56 -0
  602. package/dist/commands/upgrade/path-helpers.js +66 -0
  603. package/dist/commands/upgrade/proposal/context-budget.js +187 -0
  604. package/dist/commands/upgrade/proposal/guided-legacy.js +90 -0
  605. package/dist/commands/upgrade/proposal/inputs.js +86 -0
  606. package/dist/commands/upgrade/proposal/parse.js +221 -0
  607. package/dist/commands/upgrade/proposal/types.js +1 -0
  608. package/dist/commands/upgrade/proposal.js +4 -0
  609. package/dist/commands/upgrade/safe-upgrade.js +339 -0
  610. package/dist/commands/upgrade/scan.js +76 -0
  611. package/dist/commands/upgrade-map-propose.js +64 -0
  612. package/dist/commands/upgrade.js +106 -0
  613. package/dist/commands/validate.js +429 -0
  614. package/dist/commands/validation-obligations.js +142 -0
  615. package/dist/commands/verify.js +151 -0
  616. package/dist/commands/welcome.js +180 -0
  617. package/dist/commands/work-channels.js +493 -0
  618. package/dist/commands/write-ticket.js +226 -0
  619. package/dist/config/env-registry.js +88 -0
  620. package/dist/index.js +350 -0
  621. package/dist/migration/codemod-registry.js +82 -0
  622. package/dist/migration/migration-index.json +15 -0
  623. package/dist/plugin-registry.js +49 -0
  624. package/dist/startup-integrity.js +88 -0
  625. package/dist/startup-known-bad.js +187 -0
  626. package/dist/telemetry/index.js +78 -0
  627. package/dist/temp-workspace.js +49 -0
  628. package/package.json +102 -0
@@ -0,0 +1,420 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { normalizeTaskId } from './task-import-validators.js';
5
+ import { normalizeRelativePath } from './task-file-io-helpers.js';
6
+ import { CliError, quoteCliValue, relativePathFrom } from '../shared.js';
7
+ import { inspectGitIndexOwnership } from '../git-index-ownership.js';
8
+ import { evaluateCloseWindowStagedIndexAdmission } from './close-window-staged-index-admission.js';
9
+ import { classifyCloseWindowUnexpectedStaged, residueDisclosure, EMPTY_CLOSE_WINDOW_RESIDUE_DISCLOSURE } from './close-window-residue-classification.js';
10
+ export const CLOSE_WINDOW_STAGED_INDEX_LOCK_SCHEMA_ID = 'atm.closeWindowStagedIndexLock.v1';
11
+ /**
12
+ * Classify staged entries for diagnosis only.
13
+ *
14
+ * This runs where admission already ran, reads only, and cannot change what
15
+ * blocks: the classifier narrows a block's wording and recovery command, never
16
+ * its verdict. Deferral, the lease publication order, and the foreign staged
17
+ * snapshot and restore contract are untouched.
18
+ */
19
+ function diagnoseUnexpectedStaged(cwd, unexpectedStagedFiles) {
20
+ if (unexpectedStagedFiles.length === 0)
21
+ return EMPTY_CLOSE_WINDOW_RESIDUE_DISCLOSURE;
22
+ try {
23
+ return residueDisclosure(classifyCloseWindowUnexpectedStaged({ cwd, unexpectedStagedFiles }));
24
+ }
25
+ catch {
26
+ // Diagnosis must never decide a close. An unreadable evidence directory
27
+ // leaves the original foreign-staged treatment exactly as it was.
28
+ return EMPTY_CLOSE_WINDOW_RESIDUE_DISCLOSURE;
29
+ }
30
+ }
31
+ function resolveGitExecutable() {
32
+ const configured = process.env.ATM_GIT_EXECUTABLE?.trim();
33
+ if (configured && existsSync(configured)) {
34
+ return configured;
35
+ }
36
+ if (process.platform === 'win32') {
37
+ const windowsGit = 'C:\\Program Files\\Git\\cmd\\git.exe';
38
+ if (existsSync(windowsGit)) {
39
+ return windowsGit;
40
+ }
41
+ }
42
+ return 'git';
43
+ }
44
+ function closeWindowStagedIndexLockPath(cwd) {
45
+ return path.join(cwd, '.atm', 'runtime', 'locks', 'close-window-staged-index.lock.json');
46
+ }
47
+ function uniqueSorted(values) {
48
+ return [...new Set(values.map((entry) => normalizeRelativePath(entry)).filter(Boolean))].sort((left, right) => left.localeCompare(right));
49
+ }
50
+ function readStagedFiles(repoRoot) {
51
+ try {
52
+ return uniqueSorted(execFileSync(resolveGitExecutable(), ['diff', '--cached', '--name-only'], {
53
+ cwd: repoRoot,
54
+ encoding: 'utf8',
55
+ stdio: ['ignore', 'pipe', 'ignore']
56
+ }).split(/\r?\n/));
57
+ }
58
+ catch {
59
+ return [];
60
+ }
61
+ }
62
+ function extractGovernanceTaskId(filePath) {
63
+ const normalized = normalizeRelativePath(filePath);
64
+ if (!normalized.startsWith('.atm/history/'))
65
+ return null;
66
+ const tasksMatch = normalized.match(/^\.atm\/history\/tasks\/([^/]+)\.json$/i);
67
+ if (tasksMatch)
68
+ return normalizeTaskId(tasksMatch[1]);
69
+ const evidenceMatch = normalized.match(/^\.atm\/history\/evidence\/([^/.]+)(?:\.[^/]+)?$/i);
70
+ if (evidenceMatch)
71
+ return normalizeTaskId(evidenceMatch[1]);
72
+ const eventMatch = normalized.match(/^\.atm\/history\/task-events\/([^/]+)\//i);
73
+ if (eventMatch)
74
+ return normalizeTaskId(eventMatch[1]);
75
+ return null;
76
+ }
77
+ export function inspectForeignStagedTasksForCloseWindow(input) {
78
+ const expected = new Set(uniqueSorted(input.expectedStageFiles));
79
+ const stagedFiles = readStagedFiles(input.cwd);
80
+ const unexpected = stagedFiles.filter((filePath) => !expected.has(filePath));
81
+ const ownership = inspectGitIndexOwnership({
82
+ cwd: input.cwd,
83
+ taskId: input.taskId,
84
+ stagedFiles: unexpected
85
+ });
86
+ const grouped = new Map();
87
+ for (const entry of ownership.foreignActiveStaged) {
88
+ if (!entry.ownerTaskId)
89
+ continue;
90
+ const bucket = grouped.get(entry.ownerTaskId) ?? [];
91
+ bucket.push(entry.path);
92
+ grouped.set(entry.ownerTaskId, bucket);
93
+ }
94
+ return [...grouped.entries()].map(([foreignTaskId, files]) => {
95
+ const uniqueFiles = uniqueSorted(files);
96
+ return {
97
+ taskId: foreignTaskId,
98
+ stagedFiles: uniqueFiles,
99
+ restoreChoice: `Do not silently unstage ${foreignTaskId}. Wait for that agent to commit, request a Broker index lane, or use an explicit ATM stage-override lease if the human approved disrupting another active agent.`,
100
+ deferCommand: `node atm.mjs git lease stage-override --task ${input.taskId} --actor <actor-id> --paths ${uniqueFiles.map(quoteCliValue).join(',')} --reason "<human-approved reason>" --json`
101
+ };
102
+ });
103
+ }
104
+ function readCloseWindowStagedIndexLock(cwd) {
105
+ const lockPath = closeWindowStagedIndexLockPath(cwd);
106
+ if (!existsSync(lockPath))
107
+ return null;
108
+ try {
109
+ const parsed = JSON.parse(readFileSync(lockPath, 'utf8'));
110
+ if (parsed?.schemaId !== CLOSE_WINDOW_STAGED_INDEX_LOCK_SCHEMA_ID)
111
+ return null;
112
+ // A record written before ownership disclosure existed carries no entries;
113
+ // it reads as an empty set rather than an absent field, so every consumer
114
+ // sees one shape.
115
+ return Array.isArray(parsed.provenResidueEntries) ? parsed : { ...parsed, provenResidueEntries: [] };
116
+ }
117
+ catch {
118
+ return null;
119
+ }
120
+ }
121
+ const INDEX_LOCK_RETRY_DELAYS_MS = [25, 50, 100, 200, 400, 800, 1600];
122
+ const CLOSE_WINDOW_HANDOFF_POLL_MS = 100;
123
+ const CLOSE_WINDOW_HANDOFF_MAX_WAIT_MS = 120_000;
124
+ function isGitIndexLockContention(error) {
125
+ const message = error instanceof Error ? error.message : String(error);
126
+ return /(?:index\.lock|unable to create .*\.git[\\/]index\.lock)/i.test(message);
127
+ }
128
+ function waitForIndexLockRetry(delayMs) {
129
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, delayMs);
130
+ }
131
+ /**
132
+ * Runs one index mutation through a deliberately bounded retry window.
133
+ * A close window never steals a live Git lock: it merely tolerates the short
134
+ * hand-off interval after a child commit/hook releases the shared index.
135
+ */
136
+ export function runGitIndexMutationWithRetry(input) {
137
+ for (let attempt = 0;; attempt += 1) {
138
+ try {
139
+ (input.run ?? (() => execFileSync(resolveGitExecutable(), input.args, {
140
+ cwd: input.cwd,
141
+ stdio: ['ignore', 'pipe', 'pipe']
142
+ })))();
143
+ return;
144
+ }
145
+ catch (error) {
146
+ const delayMs = INDEX_LOCK_RETRY_DELAYS_MS[attempt];
147
+ if (!isGitIndexLockContention(error) || delayMs === undefined) {
148
+ if (isGitIndexLockContention(error)) {
149
+ throw new CliError('ATM_CLOSE_WINDOW_FOREIGN_STAGED_TASKS', `Close window could not ${input.operation} because Git's shared index remained busy.`, {
150
+ exitCode: 1,
151
+ details: {
152
+ recoveryState: 'index-lock-timeout',
153
+ operation: input.operation,
154
+ attempts: attempt + 1,
155
+ remediation: 'Keep the close-window record and durable restore identity intact. Wait for the active Git operation to finish, then retry the governed close or rollback path.'
156
+ }
157
+ });
158
+ }
159
+ throw error;
160
+ }
161
+ waitForIndexLockRetry(delayMs);
162
+ }
163
+ }
164
+ }
165
+ function readStagedIndexEntries(cwd, files) {
166
+ const requested = uniqueSorted(files);
167
+ if (requested.length === 0)
168
+ return [];
169
+ const output = execFileSync(resolveGitExecutable(), ['ls-files', '-s', '--', ...requested], {
170
+ cwd,
171
+ encoding: 'utf8',
172
+ stdio: ['ignore', 'pipe', 'pipe']
173
+ });
174
+ const present = new Map(output.split(/\r?\n/).flatMap((line) => {
175
+ const match = /^(\d+)\s+([0-9a-f]{40,})\s+\d+\t(.+)$/.exec(line.trim());
176
+ return match ? [{ mode: match[1], blobId: match[2], path: normalizeRelativePath(match[3]) }] : [];
177
+ }).filter((entry) => entry.path).map((entry) => [entry.path, entry]));
178
+ return requested.map((filePath) => present.get(filePath) ?? { path: filePath, mode: null, blobId: null });
179
+ }
180
+ function writeForeignStagedSnapshot(cwd, taskId, files) {
181
+ const entries = readStagedIndexEntries(cwd, files);
182
+ const snapshotPath = `.atm/runtime/snapshots/close-window-foreign-staged-${taskId}-${Date.now()}.json`;
183
+ mkdirSync(path.dirname(path.join(cwd, snapshotPath)), { recursive: true });
184
+ writeFileSync(path.join(cwd, snapshotPath), `${JSON.stringify({
185
+ schemaId: 'atm.closeWindowForeignStagedSnapshot.v1',
186
+ taskId,
187
+ createdAt: new Date().toISOString(),
188
+ files: uniqueSorted(files),
189
+ entries
190
+ }, null, 2)}\n`, 'utf8');
191
+ return { snapshotPath, entries };
192
+ }
193
+ function restoreForeignStagedEntries(cwd, entries, recoveryReference) {
194
+ if (entries.length === 0) {
195
+ throw new CliError('ATM_CLOSE_WINDOW_FOREIGN_STAGED_TASKS', 'Close window cannot restore a legacy or incomplete foreign staged snapshot.', {
196
+ exitCode: 1,
197
+ details: {
198
+ recoveryState: 'restore-snapshot-incomplete',
199
+ snapshotPath: recoveryReference,
200
+ remediation: 'The close-window lock and recovery snapshot were retained. Repair the durable snapshot before retrying release; do not delete the snapshot or claim success.'
201
+ }
202
+ });
203
+ }
204
+ for (const entry of entries) {
205
+ const args = entry.mode === null || entry.blobId === null
206
+ ? ['update-index', '--force-remove', '--', entry.path]
207
+ : ['update-index', '--add', '--cacheinfo', `${entry.mode},${entry.blobId},${entry.path}`];
208
+ runGitIndexMutationWithRetry({
209
+ cwd,
210
+ args,
211
+ operation: `restore foreign staged entry ${entry.path}`
212
+ });
213
+ }
214
+ const restored = readStagedIndexEntries(cwd, entries.map((entry) => entry.path));
215
+ const describe = (entry) => `${entry.mode ?? 'deleted'}:${entry.blobId ?? 'deleted'}:${entry.path}`;
216
+ const expected = entries.map(describe).sort();
217
+ const actual = restored.map(describe).sort();
218
+ if (JSON.stringify(actual) !== JSON.stringify(expected)) {
219
+ throw new CliError('ATM_CLOSE_WINDOW_FOREIGN_STAGED_TASKS', 'Close window restored foreign staged entries but byte-identity verification failed.', {
220
+ exitCode: 1,
221
+ details: {
222
+ recoveryState: 'restore-verification-failed',
223
+ snapshotPath: recoveryReference,
224
+ expected,
225
+ actual,
226
+ remediation: 'The close-window lock and recovery snapshot were retained. Do not finalize the close until the foreign index entries match the durable snapshot byte-for-byte.'
227
+ }
228
+ });
229
+ }
230
+ }
231
+ function deferForeignStagedFiles(cwd, taskId, files) {
232
+ const normalizedFiles = uniqueSorted(files);
233
+ if (normalizedFiles.length === 0)
234
+ return null;
235
+ const snapshot = writeForeignStagedSnapshot(cwd, taskId, normalizedFiles);
236
+ runGitIndexMutationWithRetry({
237
+ cwd,
238
+ args: ['restore', '--staged', '--', ...files],
239
+ operation: 'defer foreign staged entries'
240
+ });
241
+ return snapshot;
242
+ }
243
+ function cleanupForeignStagedSnapshot(cwd, snapshotPath) {
244
+ if (!snapshotPath)
245
+ return;
246
+ const absolutePath = path.join(cwd, snapshotPath);
247
+ if (!existsSync(absolutePath))
248
+ return;
249
+ try {
250
+ unlinkSync(absolutePath);
251
+ }
252
+ catch {
253
+ // best-effort runtime residue cleanup
254
+ }
255
+ }
256
+ export function inspectCloseWindowStagedIndexAdmission(input) {
257
+ const existing = readCloseWindowStagedIndexLock(input.cwd);
258
+ const unexpectedStagedTasks = inspectForeignStagedTasksForCloseWindow(input);
259
+ const expected = new Set(uniqueSorted(input.expectedStageFiles));
260
+ const unexpectedStagedFiles = readStagedFiles(input.cwd).filter((filePath) => !expected.has(filePath));
261
+ const diagnosis = diagnoseUnexpectedStaged(input.cwd, unexpectedStagedFiles);
262
+ const decision = evaluateCloseWindowStagedIndexAdmission({ taskId: normalizeTaskId(input.taskId), activeLockTaskId: existing?.status === 'active' ? existing.taskId : null,
263
+ unexpectedStagedFiles, unexpectedStagedTaskIds: unexpectedStagedTasks.map((entry) => entry.taskId), deferForeignStaged: input.deferForeignStaged === true,
264
+ provenResidueFiles: diagnosis.provenResidueFiles, residueDrainCommand: diagnosis.residueDrainCommand });
265
+ return { schemaId: CLOSE_WINDOW_STAGED_INDEX_LOCK_SCHEMA_ID, ok: decision.ok,
266
+ lockPath: relativePathFrom(input.cwd, closeWindowStagedIndexLockPath(input.cwd)), lock: existing, unexpectedStagedTasks,
267
+ foreignStagedSnapshotPath: existing?.foreignStagedSnapshotPath ?? null, blockedCode: decision.blockedCode, blockedSummary: decision.blockedSummary,
268
+ residueDrainCommand: diagnosis.residueDrainCommand, residueDrainCommands: diagnosis.residueDrainCommands,
269
+ provenResidueEntries: diagnosis.provenResidueEntries };
270
+ }
271
+ export function acquireCloseWindowStagedIndexLock(input) {
272
+ const lockPath = closeWindowStagedIndexLockPath(input.cwd);
273
+ const firstExisting = readCloseWindowStagedIndexLock(input.cwd);
274
+ let existing = firstExisting;
275
+ let handoffAttempts = 0;
276
+ const handoffStartedAt = Date.now();
277
+ const maxHandoffWaitMs = input.maxHandoffWaitMs ?? CLOSE_WINDOW_HANDOFF_MAX_WAIT_MS;
278
+ while (input.waitForHandoff === true
279
+ && existing?.status === 'active'
280
+ && existing.taskId !== normalizeTaskId(input.taskId)
281
+ && Date.now() - handoffStartedAt < maxHandoffWaitMs) {
282
+ handoffAttempts += 1;
283
+ (input.waitForHandoffPoll ?? waitForIndexLockRetry)(CLOSE_WINDOW_HANDOFF_POLL_MS);
284
+ existing = readCloseWindowStagedIndexLock(input.cwd);
285
+ }
286
+ const handoffWait = firstExisting?.status === 'active' && firstExisting.taskId !== normalizeTaskId(input.taskId)
287
+ ? {
288
+ waitedForTaskId: firstExisting.taskId,
289
+ waitedMs: Date.now() - handoffStartedAt,
290
+ attempts: handoffAttempts,
291
+ disposition: existing?.status === 'active' && existing.taskId !== normalizeTaskId(input.taskId)
292
+ ? 'timed-out'
293
+ : 'acquired-after-release'
294
+ }
295
+ : {
296
+ waitedForTaskId: normalizeTaskId(input.taskId),
297
+ waitedMs: 0,
298
+ attempts: 0,
299
+ disposition: 'not-required'
300
+ };
301
+ const unexpectedStagedTasks = inspectForeignStagedTasksForCloseWindow({
302
+ cwd: input.cwd,
303
+ taskId: input.taskId,
304
+ expectedStageFiles: input.expectedStageFiles
305
+ });
306
+ const expectedStageFiles = new Set(uniqueSorted(input.expectedStageFiles));
307
+ const unexpectedStagedFiles = readStagedFiles(input.cwd).filter((filePath) => !expectedStageFiles.has(filePath));
308
+ const acquireDiagnosis = diagnoseUnexpectedStaged(input.cwd, unexpectedStagedFiles);
309
+ const admission = evaluateCloseWindowStagedIndexAdmission({ taskId: normalizeTaskId(input.taskId), activeLockTaskId: existing?.status === 'active' ? existing.taskId : null,
310
+ unexpectedStagedFiles, unexpectedStagedTaskIds: unexpectedStagedTasks.map((entry) => entry.taskId), deferForeignStaged: input.deferForeignStaged === true,
311
+ provenResidueFiles: acquireDiagnosis.provenResidueFiles, residueDrainCommand: acquireDiagnosis.residueDrainCommand });
312
+ if (!admission.ok) {
313
+ return {
314
+ schemaId: CLOSE_WINDOW_STAGED_INDEX_LOCK_SCHEMA_ID,
315
+ ok: false,
316
+ lockPath: relativePathFrom(input.cwd, lockPath),
317
+ lock: existing,
318
+ unexpectedStagedTasks,
319
+ foreignStagedSnapshotPath: existing?.foreignStagedSnapshotPath ?? null,
320
+ blockedCode: admission.blockedCode,
321
+ blockedSummary: admission.blockedSummary,
322
+ residueDrainCommand: acquireDiagnosis.residueDrainCommand,
323
+ residueDrainCommands: acquireDiagnosis.residueDrainCommands,
324
+ provenResidueEntries: acquireDiagnosis.provenResidueEntries,
325
+ handoffWait
326
+ };
327
+ }
328
+ // Publish the coordination lease before touching Git's shared index. The
329
+ // former order parked foreign entries first, leaving an index-lock race.
330
+ let record = {
331
+ schemaId: CLOSE_WINDOW_STAGED_INDEX_LOCK_SCHEMA_ID,
332
+ specVersion: '0.1.0',
333
+ taskId: normalizeTaskId(input.taskId),
334
+ actorId: input.actorId,
335
+ acquiredAt: new Date().toISOString(),
336
+ status: 'active',
337
+ expectedStageFiles: uniqueSorted(input.expectedStageFiles),
338
+ foreignStagedSnapshotPath: null,
339
+ foreignStagedEntries: [],
340
+ provenResidueEntries: acquireDiagnosis.provenResidueEntries,
341
+ unexpectedStagedTasks,
342
+ releasedAt: null,
343
+ releaseOutcome: null
344
+ };
345
+ mkdirSync(path.dirname(lockPath), { recursive: true });
346
+ writeFileSync(lockPath, `${JSON.stringify(record, null, 2)}\n`, 'utf8');
347
+ try {
348
+ if (unexpectedStagedFiles.length > 0 && input.deferForeignStaged) {
349
+ const deferred = deferForeignStagedFiles(input.cwd, input.taskId, unexpectedStagedFiles);
350
+ record = {
351
+ ...record,
352
+ foreignStagedSnapshotPath: deferred?.snapshotPath ?? null,
353
+ foreignStagedEntries: deferred?.entries ?? []
354
+ };
355
+ writeFileSync(lockPath, `${JSON.stringify(record, null, 2)}\n`, 'utf8');
356
+ }
357
+ }
358
+ catch (error) {
359
+ unlinkSync(lockPath);
360
+ throw error;
361
+ }
362
+ return {
363
+ schemaId: CLOSE_WINDOW_STAGED_INDEX_LOCK_SCHEMA_ID,
364
+ ok: true,
365
+ lockPath: relativePathFrom(input.cwd, lockPath),
366
+ lock: record,
367
+ unexpectedStagedTasks,
368
+ foreignStagedSnapshotPath: record.foreignStagedSnapshotPath,
369
+ blockedCode: null,
370
+ blockedSummary: null,
371
+ residueDrainCommand: acquireDiagnosis.residueDrainCommand,
372
+ residueDrainCommands: acquireDiagnosis.residueDrainCommands,
373
+ provenResidueEntries: record.provenResidueEntries,
374
+ handoffWait
375
+ };
376
+ }
377
+ export function assertCloseWindowStagingAllowed(input) {
378
+ const lock = readCloseWindowStagedIndexLock(input.cwd);
379
+ if (!lock || lock.status !== 'active')
380
+ return;
381
+ if (lock.taskId === normalizeTaskId(input.taskId))
382
+ return;
383
+ throw new CliError('ATM_CLOSE_WINDOW_STAGED_INDEX_LOCKED', `Close window staged-index lock held by ${lock.taskId} blocks ${input.operation}.`, {
384
+ exitCode: 1,
385
+ details: {
386
+ lockTaskId: lock.taskId,
387
+ operation: input.operation,
388
+ lockPath: relativePathFrom(input.cwd, closeWindowStagedIndexLockPath(input.cwd)),
389
+ requiredCommand: `node atm.mjs tasks status --task ${lock.taskId} --json`
390
+ }
391
+ });
392
+ }
393
+ export function releaseCloseWindowStagedIndexLock(input) {
394
+ const lockPath = closeWindowStagedIndexLockPath(input.cwd);
395
+ const existing = readCloseWindowStagedIndexLock(input.cwd);
396
+ if (!existing || existing.status !== 'active')
397
+ return null;
398
+ if (existing.taskId !== normalizeTaskId(input.taskId))
399
+ return existing;
400
+ if (existing.foreignStagedSnapshotPath) {
401
+ restoreForeignStagedEntries(input.cwd, existing.foreignStagedEntries ?? [], existing.foreignStagedSnapshotPath);
402
+ cleanupForeignStagedSnapshot(input.cwd, existing.foreignStagedSnapshotPath);
403
+ }
404
+ const released = {
405
+ ...existing,
406
+ status: 'released',
407
+ releasedAt: new Date().toISOString(),
408
+ releaseOutcome: input.outcome
409
+ };
410
+ try {
411
+ unlinkSync(lockPath);
412
+ }
413
+ catch {
414
+ writeFileSync(lockPath, `${JSON.stringify(released, null, 2)}\n`, 'utf8');
415
+ }
416
+ return released;
417
+ }
418
+ export function readCloseWindowStagedIndexLockReport(cwd) {
419
+ return readCloseWindowStagedIndexLock(cwd);
420
+ }
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Tell an unreconciled live index apart from another agent's staged work.
3
+ *
4
+ * The close window blocks on staged entries outside the governed bundle. Two
5
+ * completely different conditions produce that symptom. One is genuine foreign
6
+ * work: another lane staged something, and deferring it — parking a byte-exact
7
+ * snapshot and restoring it afterwards — is the right answer. The other is this
8
+ * repository's own reconciliation debt: a governed commit advanced HEAD through
9
+ * a sealed candidate index and the live index never caught up, so paths that
10
+ * were already committed still read as staged changes against HEAD.
11
+ *
12
+ * Deferring the second kind is a null operation by construction. The snapshot
13
+ * is restored byte-identically on release, so the debt is faithfully recreated
14
+ * after the close, and it compounds with every commit taken in that state. The
15
+ * operator is told to defer when what they actually need is to drain.
16
+ *
17
+ * This module only classifies. It never mutates the index, never touches the
18
+ * close-window lease, and never changes what defer parks or restores — the
19
+ * proof is a dry run, and its whole output is a diagnosis.
20
+ */
21
+ import { existsSync, readFileSync, readdirSync } from 'node:fs';
22
+ import path from 'node:path';
23
+ import { drainLiveIndexReconciliationReceipt } from '../git-governance/implementation/live-index-drain.js';
24
+ export const CLOSE_WINDOW_RESIDUE_CLASSIFICATION_SCHEMA_ID = 'atm.closeWindowResidueClassification.v1';
25
+ const EVIDENCE_DIRECTORY = '.atm/history/evidence';
26
+ const RECEIPT_SUFFIX = '.live-index-reconciliation.json';
27
+ function normalize(value) {
28
+ return String(value ?? '').replace(/\\/g, '/').replace(/^\.\//, '').trim();
29
+ }
30
+ function listReceiptTaskIds(cwd) {
31
+ const directory = path.join(cwd, EVIDENCE_DIRECTORY);
32
+ if (!existsSync(directory))
33
+ return [];
34
+ try {
35
+ return readdirSync(directory)
36
+ .filter((entry) => entry.endsWith(RECEIPT_SUFFIX))
37
+ .map((entry) => entry.slice(0, -RECEIPT_SUFFIX.length))
38
+ .filter(Boolean);
39
+ }
40
+ catch {
41
+ return [];
42
+ }
43
+ }
44
+ /**
45
+ * The retained paths a receipt claims, read without proving anything. This is
46
+ * the cheap filter that keeps the expensive per-receipt proof off the close
47
+ * path whenever the staged set has nothing to do with recorded debt.
48
+ */
49
+ function readReceiptRetainedPaths(cwd, taskId) {
50
+ try {
51
+ const parsed = JSON.parse(readFileSync(path.join(cwd, EVIDENCE_DIRECTORY, `${taskId}${RECEIPT_SUFFIX}`), 'utf8'));
52
+ return (parsed.retainedPaths ?? [])
53
+ .map((entry) => (typeof entry?.path === 'string' ? normalize(entry.path) : ''))
54
+ .filter(Boolean);
55
+ }
56
+ catch {
57
+ return [];
58
+ }
59
+ }
60
+ export function classifyCloseWindowUnexpectedStaged(input) {
61
+ const staged = new Set(input.unexpectedStagedFiles.map(normalize).filter(Boolean));
62
+ if (staged.size === 0)
63
+ return classification([], [], []);
64
+ const readRetained = input.readRetainedPaths ?? ((taskId) => readReceiptRetainedPaths(input.cwd, taskId));
65
+ const prove = input.proveDrainable
66
+ ?? ((taskId) => drainLiveIndexReconciliationReceipt({ cwd: input.cwd, taskId, dryRun: true }));
67
+ const provenResidueFiles = new Set();
68
+ const residueSources = [];
69
+ for (const taskId of input.receiptTaskIds ?? listReceiptTaskIds(input.cwd)) {
70
+ if (!readRetained(taskId).some((filePath) => staged.has(filePath)))
71
+ continue;
72
+ let drain;
73
+ try {
74
+ // A dry run proves the pre-state without writing. A receipt that cannot be
75
+ // read or proved simply yields no residue: this classifier only ever
76
+ // narrows a block, so an unreadable receipt leaves the stricter foreign
77
+ // treatment in place.
78
+ drain = prove(taskId);
79
+ }
80
+ catch {
81
+ continue;
82
+ }
83
+ for (const filePath of drain.drainedPaths.map(normalize)) {
84
+ if (!staged.has(filePath) || provenResidueFiles.has(filePath))
85
+ continue;
86
+ provenResidueFiles.add(filePath);
87
+ residueSources.push({
88
+ path: filePath,
89
+ receiptTaskId: taskId,
90
+ firstUnreconciledCommit: drain.headSha
91
+ });
92
+ }
93
+ }
94
+ const foreignStagedFiles = [...staged].filter((filePath) => !provenResidueFiles.has(filePath)).sort();
95
+ return classification([...provenResidueFiles].sort(), residueSources, foreignStagedFiles);
96
+ }
97
+ function classification(provenResidueFiles, residueSources, foreignStagedFiles) {
98
+ return {
99
+ schemaId: CLOSE_WINDOW_RESIDUE_CLASSIFICATION_SCHEMA_ID,
100
+ provenResidueFiles,
101
+ residueSources,
102
+ foreignStagedFiles
103
+ };
104
+ }
105
+ /** The drain command that clears one receipt's proven debt. */
106
+ export function residueDrainCommand(receiptTaskId) {
107
+ return `node atm.mjs git reconcile-live-index --task ${receiptTaskId} --write --json`;
108
+ }
109
+ /**
110
+ * Every drain a residue set needs, one per distinct receipt owner.
111
+ *
112
+ * Naming only the first owner told an operator to run a command that clears
113
+ * part of the debt; the close then blocks again with the identical message, so
114
+ * the instruction reads as if it had failed. Each receipt is drained on its own
115
+ * terms, so the recovery is the whole set, deduplicated and ordered.
116
+ */
117
+ export function residueDrainCommands(sources) {
118
+ return [...new Set(sources.map((entry) => entry.receiptTaskId).filter(Boolean))].sort().map(residueDrainCommand);
119
+ }
120
+ export const EMPTY_CLOSE_WINDOW_RESIDUE_DISCLOSURE = {
121
+ provenResidueFiles: [],
122
+ provenResidueEntries: [],
123
+ residueDrainCommands: [],
124
+ residueDrainCommand: null
125
+ };
126
+ /** Reduce a classification to exactly what the close window records and reports. */
127
+ export function residueDisclosure(classification) {
128
+ const commands = residueDrainCommands(classification.residueSources);
129
+ return {
130
+ provenResidueFiles: classification.provenResidueFiles,
131
+ provenResidueEntries: classification.residueSources
132
+ .map((entry) => ({ path: entry.path, receiptTaskId: entry.receiptTaskId }))
133
+ .sort((left, right) => left.path.localeCompare(right.path) || left.receiptTaskId.localeCompare(right.receiptTaskId)),
134
+ residueDrainCommands: commands,
135
+ residueDrainCommand: commands.length > 0 ? commands.join(' && ') : null
136
+ };
137
+ }
@@ -0,0 +1,20 @@
1
+ export function evaluateCloseWindowStagedIndexAdmission(input) {
2
+ if (input.activeLockTaskId && input.activeLockTaskId !== input.taskId) {
3
+ return { ok: false, blockedCode: 'ATM_CLOSE_WINDOW_STAGED_INDEX_LOCKED', blockedSummary: `Close window staged-index lock is already held by ${input.activeLockTaskId}; wait for release or inspect tasks status before staging.` };
4
+ }
5
+ if (input.unexpectedStagedFiles.length > 0 && !input.deferForeignStaged) {
6
+ const residue = new Set(input.provenResidueFiles ?? []);
7
+ const foreignStagedFiles = input.unexpectedStagedFiles.filter((filePath) => !residue.has(filePath));
8
+ // Deferring proven residue parks a snapshot and restores it byte-identically
9
+ // on release, so it recreates the debt instead of clearing it. When nothing
10
+ // foreign is staged, the honest instruction is to drain, not to defer.
11
+ if (foreignStagedFiles.length === 0 && residue.size > 0) {
12
+ return { ok: false, blockedCode: 'ATM_CLOSE_WINDOW_UNRECONCILED_RESIDUE', blockedSummary: `Close window blocked by ${residue.size} staged path(s) that are this repository's own unreconciled commits, not foreign work; drain the recorded reconciliation debt${input.residueDrainCommand ? ` (${input.residueDrainCommand})` : ''} rather than deferring it.` };
13
+ }
14
+ return { ok: false, blockedCode: 'ATM_CLOSE_WINDOW_FOREIGN_STAGED_TASKS', blockedSummary: (input.unexpectedStagedTaskIds.length > 0
15
+ ? `Close window blocked by foreign staged tasks (${input.unexpectedStagedTaskIds.join(', ')}); defer explicitly or wait for the other agent to commit.`
16
+ : 'Close window blocked by staged entries outside the governed bundle; defer explicitly or reconcile the index before closing.')
17
+ + (residue.size > 0 ? ` ${residue.size} of the staged path(s) are provably this repository's own unreconciled commits and can be drained separately.` : '') };
18
+ }
19
+ return { ok: true, blockedCode: null, blockedSummary: null };
20
+ }