@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.
- package/README.md +20 -0
- package/dist/atm.js +328 -0
- package/dist/atm.mjs +4 -0
- package/dist/commands/actor-registry.js +359 -0
- package/dist/commands/actor-session.js +214 -0
- package/dist/commands/actor.js +342 -0
- package/dist/commands/agent-confidence.js +137 -0
- package/dist/commands/agent-pack.js +327 -0
- package/dist/commands/atm-chart/compatibility.js +287 -0
- package/dist/commands/atm-chart/constants.js +60 -0
- package/dist/commands/atm-chart/render-verify.js +276 -0
- package/dist/commands/atm-chart/semver.js +62 -0
- package/dist/commands/atm-chart/types.js +1 -0
- package/dist/commands/atm-chart.js +49 -0
- package/dist/commands/atom-capsule.js +265 -0
- package/dist/commands/atom-ref.js +71 -0
- package/dist/commands/atomize.js +338 -0
- package/dist/commands/baseline.js +285 -0
- package/dist/commands/batch/checkpoint-commit-window-policy.js +22 -0
- package/dist/commands/batch/deliver-and-close-forwarding.js +60 -0
- package/dist/commands/batch/implementation.js +861 -0
- package/dist/commands/batch/plan-executor.js +314 -0
- package/dist/commands/batch/runner-recovery-forwarding.js +47 -0
- package/dist/commands/batch.js +1 -0
- package/dist/commands/bootstrap-entry.js +32 -0
- package/dist/commands/bootstrap.js +8 -0
- package/dist/commands/broker/batch-execute-actions.js +506 -0
- package/dist/commands/broker/broker-decision-observation.js +1 -0
- package/dist/commands/broker/census/index.js +4 -0
- package/dist/commands/broker/implementation.js +59 -0
- package/dist/commands/broker/migrate/implementation.js +114 -0
- package/dist/commands/broker/mutation-helpers.js +105 -0
- package/dist/commands/broker/parallel-admission/closure-observation.js +92 -0
- package/dist/commands/broker/parallel-admission/final-verdict.js +168 -0
- package/dist/commands/broker/parser.js +495 -0
- package/dist/commands/broker/persistence.js +73 -0
- package/dist/commands/broker/plan-batch-action.js +178 -0
- package/dist/commands/broker/policy-actions.js +64 -0
- package/dist/commands/broker/post-compose-semantic-validation.js +143 -0
- package/dist/commands/broker/proposal-actions.js +149 -0
- package/dist/commands/broker/publication-takeover-admission.js +36 -0
- package/dist/commands/broker/reconcile/implementation.js +35 -0
- package/dist/commands/broker/registry-actions.js +309 -0
- package/dist/commands/broker/replay/closure-policy.js +332 -0
- package/dist/commands/broker/replay/command-backed-matrix.js +59 -0
- package/dist/commands/broker/replay/dashboard-lifecycle-observations.js +90 -0
- package/dist/commands/broker/replay/dashboard-ticket-observations.js +41 -0
- package/dist/commands/broker/replay/dashboard-view-model.js +203 -0
- package/dist/commands/broker/replay/dashboard.js +31 -0
- package/dist/commands/broker/replay/dogfood-orchestrator.js +117 -0
- package/dist/commands/broker/replay/final-closure-reader.js +181 -0
- package/dist/commands/broker/replay/implementation.js +264 -0
- package/dist/commands/broker/replay/run-manifest.js +26 -0
- package/dist/commands/broker/replay-actions.js +198 -0
- package/dist/commands/broker/runner-sync-supersession.js +6 -0
- package/dist/commands/broker/shared-delivery-commit-transaction.js +155 -0
- package/dist/commands/broker/shared-surface.js +260 -0
- package/dist/commands/broker/steward-queues.js +542 -0
- package/dist/commands/broker/steward-runtime-actions.js +295 -0
- package/dist/commands/broker/types.js +1 -0
- package/dist/commands/broker/wave-scheduler-actions.js +73 -0
- package/dist/commands/broker-conflict-resolution.js +66 -0
- package/dist/commands/broker.js +1 -0
- package/dist/commands/budget.js +108 -0
- package/dist/commands/build-release-hygiene.js +94 -0
- package/dist/commands/cache.js +235 -0
- package/dist/commands/candidates.js +509 -0
- package/dist/commands/cleanup/index.js +1 -0
- package/dist/commands/cleanup/run.js +38 -0
- package/dist/commands/command-specs/_common.js +24 -0
- package/dist/commands/command-specs/actor.spec.js +33 -0
- package/dist/commands/command-specs/agent-pack.spec.js +24 -0
- package/dist/commands/command-specs/atm-chart.spec.js +21 -0
- package/dist/commands/command-specs/atom-capsule.spec.js +30 -0
- package/dist/commands/command-specs/atom-ref.spec.js +20 -0
- package/dist/commands/command-specs/atomize.spec.js +40 -0
- package/dist/commands/command-specs/baseline.spec.js +25 -0
- package/dist/commands/command-specs/batch.spec.js +59 -0
- package/dist/commands/command-specs/bootstrap.spec.js +19 -0
- package/dist/commands/command-specs/broker.spec.js +95 -0
- package/dist/commands/command-specs/budget.spec.js +23 -0
- package/dist/commands/command-specs/cache.spec.js +24 -0
- package/dist/commands/command-specs/candidates.spec.js +24 -0
- package/dist/commands/command-specs/cleanup.spec.js +21 -0
- package/dist/commands/command-specs/create-map.spec.js +25 -0
- package/dist/commands/command-specs/create.spec.js +20 -0
- package/dist/commands/command-specs/daemon.spec.js +22 -0
- package/dist/commands/command-specs/doctor.spec.js +18 -0
- package/dist/commands/command-specs/emergency.spec.js +34 -0
- package/dist/commands/command-specs/evidence.spec.js +104 -0
- package/dist/commands/command-specs/experience.spec.js +26 -0
- package/dist/commands/command-specs/explain.spec.js +18 -0
- package/dist/commands/command-specs/framework-mode.spec.js +28 -0
- package/dist/commands/command-specs/git-hooks.spec.js +21 -0
- package/dist/commands/command-specs/git.spec.js +84 -0
- package/dist/commands/command-specs/guard.spec.js +30 -0
- package/dist/commands/command-specs/guide.spec.js +34 -0
- package/dist/commands/command-specs/handoff.spec.js +19 -0
- package/dist/commands/command-specs/health-report.spec.js +16 -0
- package/dist/commands/command-specs/hook.spec.js +22 -0
- package/dist/commands/command-specs/identity.spec.js +34 -0
- package/dist/commands/command-specs/init.spec.js +21 -0
- package/dist/commands/command-specs/integration.spec.js +43 -0
- package/dist/commands/command-specs/internal-release.spec.js +30 -0
- package/dist/commands/command-specs/lane.spec.js +32 -0
- package/dist/commands/command-specs/lock.spec.js +21 -0
- package/dist/commands/command-specs/map-capsule.spec.js +27 -0
- package/dist/commands/command-specs/migrate.spec.js +23 -0
- package/dist/commands/command-specs/next.spec.js +68 -0
- package/dist/commands/command-specs/orient.spec.js +15 -0
- package/dist/commands/command-specs/plan.spec.js +58 -0
- package/dist/commands/command-specs/police.spec.js +22 -0
- package/dist/commands/command-specs/quickfix.spec.js +21 -0
- package/dist/commands/command-specs/registry-diff.spec.js +21 -0
- package/dist/commands/command-specs/registry.spec.js +35 -0
- package/dist/commands/command-specs/replacement-lane.spec.js +25 -0
- package/dist/commands/command-specs/rescue.spec.js +29 -0
- package/dist/commands/command-specs/residue.spec.js +37 -0
- package/dist/commands/command-specs/review-advisory.spec.js +27 -0
- package/dist/commands/command-specs/review.spec.js +28 -0
- package/dist/commands/command-specs/rollback.spec.js +29 -0
- package/dist/commands/command-specs/route.spec.js +43 -0
- package/dist/commands/command-specs/self-host-alpha.spec.js +18 -0
- package/dist/commands/command-specs/spec.spec.js +17 -0
- package/dist/commands/command-specs/start.spec.js +22 -0
- package/dist/commands/command-specs/status.spec.js +16 -0
- package/dist/commands/command-specs/task-view.spec.js +18 -0
- package/dist/commands/command-specs/taskflow.spec.js +77 -0
- package/dist/commands/command-specs/tasks.spec.js +157 -0
- package/dist/commands/command-specs/team.spec.js +159 -0
- package/dist/commands/command-specs/telemetry.spec.js +55 -0
- package/dist/commands/command-specs/test.spec.js +39 -0
- package/dist/commands/command-specs/upgrade.spec.js +62 -0
- package/dist/commands/command-specs/validate.spec.js +28 -0
- package/dist/commands/command-specs/verify.spec.js +20 -0
- package/dist/commands/command-specs/welcome.spec.js +18 -0
- package/dist/commands/command-specs/write-ticket.spec.js +34 -0
- package/dist/commands/command-specs.js +150 -0
- package/dist/commands/create-map.js +285 -0
- package/dist/commands/create.js +106 -0
- package/dist/commands/daemon.js +268 -0
- package/dist/commands/doctor/constants.js +76 -0
- package/dist/commands/doctor/lifecycle.js +106 -0
- package/dist/commands/doctor/policy.js +114 -0
- package/dist/commands/doctor/readiness.js +114 -0
- package/dist/commands/doctor/run-doctor.js +356 -0
- package/dist/commands/doctor/types.js +1 -0
- package/dist/commands/doctor/utilities.js +120 -0
- package/dist/commands/doctor.js +1 -0
- package/dist/commands/emergency/context.js +21 -0
- package/dist/commands/emergency/gate.js +103 -0
- package/dist/commands/emergency/leases.js +154 -0
- package/dist/commands/emergency/protected-override-audit.js +122 -0
- package/dist/commands/emergency/registry.js +176 -0
- package/dist/commands/emergency.js +219 -0
- package/dist/commands/evidence/bundle-io/implementation.js +896 -0
- package/dist/commands/evidence/bundle-io.js +1 -0
- package/dist/commands/evidence/command-runs.js +280 -0
- package/dist/commands/evidence/evidence-store.js +94 -0
- package/dist/commands/evidence/historical-batch-finalize.js +1 -0
- package/dist/commands/evidence/historical-batch.js +1 -0
- package/dist/commands/evidence/missing-report.js +380 -0
- package/dist/commands/evidence/observed-source-loader.js +54 -0
- package/dist/commands/evidence/shared-utils.js +18 -0
- package/dist/commands/evidence/validator-classification.js +182 -0
- package/dist/commands/evidence/verbs/add.js +1 -0
- package/dist/commands/evidence/verbs/diagnose.js +190 -0
- package/dist/commands/evidence/verbs/diff.js +1 -0
- package/dist/commands/evidence/verbs/git-head-backfill.js +1 -0
- package/dist/commands/evidence/verbs/missing.js +1 -0
- package/dist/commands/evidence/verbs/run.js +287 -0
- package/dist/commands/evidence/verbs/validators.js +1 -0
- package/dist/commands/evidence/verbs/verify.js +1 -0
- package/dist/commands/evidence/verbs/wave-exit-observer.js +212 -0
- package/dist/commands/evidence.js +39 -0
- package/dist/commands/experience.js +242 -0
- package/dist/commands/explain.js +49 -0
- package/dist/commands/first-use-notice.js +54 -0
- package/dist/commands/framework-development/build-release-hygiene-hints.js +7 -0
- package/dist/commands/framework-development/closure-packet/diagnostics.js +24 -0
- package/dist/commands/framework-development/closure-packet/schema-fragments.js +1 -0
- package/dist/commands/framework-development/closure-packet/validator-contract.js +1 -0
- package/dist/commands/framework-development/closure-packet-schema/implementation.js +1134 -0
- package/dist/commands/framework-development/closure-packet-schema.js +3 -0
- package/dist/commands/framework-development/critical-path-gate.js +1 -0
- package/dist/commands/framework-development/framework-lock-context.js +35 -0
- package/dist/commands/framework-development/framework-temp-lock-projection.js +81 -0
- package/dist/commands/framework-development/framework-temp-publication-capability.js +270 -0
- package/dist/commands/framework-development/historical-delivery-provenance.js +12 -0
- package/dist/commands/framework-development/path-classification.js +34 -0
- package/dist/commands/framework-development/runner-publication-close-handoff.js +86 -0
- package/dist/commands/framework-development/runner-publication-lifecycle.js +412 -0
- package/dist/commands/framework-development/runner-publication-receipt.js +29 -0
- package/dist/commands/framework-development/runner-sync-admission.js +337 -0
- package/dist/commands/framework-development/runner-sync-lease-health.js +36 -0
- package/dist/commands/framework-development/runner-sync-queue-ownership.js +202 -0
- package/dist/commands/framework-development/sha256-normalization.js +1 -0
- package/dist/commands/framework-development/temp-claim.js +1 -0
- package/dist/commands/framework-development.js +7 -0
- package/dist/commands/git/record-commit.js +2 -0
- package/dist/commands/git-governance/branch-commit-coordinator.js +119 -0
- package/dist/commands/git-governance/commit-bundle-filter.js +37 -0
- package/dist/commands/git-governance/commit-scope-policy.js +182 -0
- package/dist/commands/git-governance/governance-residue-policy.js +18 -0
- package/dist/commands/git-governance/implementation/admission-command.js +231 -0
- package/dist/commands/git-governance/implementation/branch-commit-window.js +204 -0
- package/dist/commands/git-governance/implementation/broker-hook-bypass-preflight.js +227 -0
- package/dist/commands/git-governance/implementation/command-router.js +199 -0
- package/dist/commands/git-governance/implementation/commit-attempt-boundary.js +76 -0
- package/dist/commands/git-governance/implementation/commit-authority-scopes.js +61 -0
- package/dist/commands/git-governance/implementation/commit-bundle-resolution.js +502 -0
- package/dist/commands/git-governance/implementation/commit-bundle-selection.js +9 -0
- package/dist/commands/git-governance/implementation/commit-candidate-preparation.js +68 -0
- package/dist/commands/git-governance/implementation/commit-command.js +198 -0
- package/dist/commands/git-governance/implementation/commit-execution.js +400 -0
- package/dist/commands/git-governance/implementation/commit-framework-branch.js +105 -0
- package/dist/commands/git-governance/implementation/commit-task-scoped-branch.js +161 -0
- package/dist/commands/git-governance/implementation/dry-run-purity.js +54 -0
- package/dist/commands/git-governance/implementation/framework-commit-claim-guard.js +21 -0
- package/dist/commands/git-governance/implementation/framework-hook-identity.js +12 -0
- package/dist/commands/git-governance/implementation/git-command-options.js +258 -0
- package/dist/commands/git-governance/implementation/git-config-port.js +25 -0
- package/dist/commands/git-governance/implementation/git-head-evidence-transaction.js +275 -0
- package/dist/commands/git-governance/implementation/git-index-lock-recovery.js +41 -0
- package/dist/commands/git-governance/implementation/git-index-transaction.js +415 -0
- package/dist/commands/git-governance/implementation/git-process-port.js +261 -0
- package/dist/commands/git-governance/implementation/hook-bypass-commit-boundary.js +20 -0
- package/dist/commands/git-governance/implementation/hook-failure-diagnostics.js +59 -0
- package/dist/commands/git-governance/implementation/identity-check-command.js +403 -0
- package/dist/commands/git-governance/implementation/index-restoration.js +80 -0
- package/dist/commands/git-governance/implementation/lease-command.js +112 -0
- package/dist/commands/git-governance/implementation/live-index-drain.js +124 -0
- package/dist/commands/git-governance/implementation/live-index-lock-retry.js +72 -0
- package/dist/commands/git-governance/implementation/live-index-reconciliation.js +420 -0
- package/dist/commands/git-governance/implementation/pathspec-argv-batching.js +124 -0
- package/dist/commands/git-governance/implementation/push-command.js +485 -0
- package/dist/commands/git-governance/implementation/record-bundle-inspection.js +244 -0
- package/dist/commands/git-governance/implementation/record-commit-command.js +262 -0
- package/dist/commands/git-governance/implementation/sealed-commit-attribution.js +429 -0
- package/dist/commands/git-governance/implementation/task-scope-staging.js +383 -0
- package/dist/commands/git-governance/implementation.js +11 -0
- package/dist/commands/git-governance/protected-governance-state.js +136 -0
- package/dist/commands/git-governance/record-commit-payload-assertion.js +48 -0
- package/dist/commands/git-governance/record-only-block-lifecycle-bridge.js +227 -0
- package/dist/commands/git-governance/task-scoped-commit-transaction.js +42 -0
- package/dist/commands/git-governance/validate-atom-file-size.js +54 -0
- package/dist/commands/git-governance/work-admission-check.js +201 -0
- package/dist/commands/git-governance.js +338 -0
- package/dist/commands/git-head-evidence.js +354 -0
- package/dist/commands/git-index-ownership.js +411 -0
- package/dist/commands/git-worktree-readiness.js +127 -0
- package/dist/commands/git.js +169 -0
- package/dist/commands/glossary-data.js +52 -0
- package/dist/commands/governance-runtime.js +198 -0
- package/dist/commands/guard.js +338 -0
- package/dist/commands/guide.js +486 -0
- package/dist/commands/handoff.js +107 -0
- package/dist/commands/hash-placeholder-audit.js +57 -0
- package/dist/commands/health-report.js +30 -0
- package/dist/commands/help.js +69 -0
- package/dist/commands/hook/commit-range-guard/args.js +48 -0
- package/dist/commands/hook/commit-range-guard/baseline.js +43 -0
- package/dist/commands/hook/commit-range-guard/implementation.js +514 -0
- package/dist/commands/hook/commit-range-guard/support.js +6 -0
- package/dist/commands/hook/commit-range-guard.js +4 -0
- package/dist/commands/hook/context-map-advisor.js +210 -0
- package/dist/commands/hook/git-hooks-installer.js +156 -0
- package/dist/commands/hook/git-index-diagnostics.js +81 -0
- package/dist/commands/hook/pre-commit/close-transaction-receipt.js +110 -0
- package/dist/commands/hook/pre-commit/committed-task-context.js +37 -0
- package/dist/commands/hook/pre-commit/cross-file-consistency.js +423 -0
- package/dist/commands/hook/pre-commit/cross-task-admission.js +135 -0
- package/dist/commands/hook/pre-commit/failure-envelope.js +340 -0
- package/dist/commands/hook/pre-commit/framework-lock-context.js +9 -0
- package/dist/commands/hook/pre-commit/framework-temp-claim-attribution.js +29 -0
- package/dist/commands/hook/pre-commit/implementation.js +433 -0
- package/dist/commands/hook/pre-commit/input-state.js +208 -0
- package/dist/commands/hook/pre-commit/residue-candidates.js +15 -0
- package/dist/commands/hook/pre-commit/scope-ownership.js +380 -0
- package/dist/commands/hook/pre-commit/support.js +965 -0
- package/dist/commands/hook/pre-commit/team-gate-findings.js +19 -0
- package/dist/commands/hook/pre-commit.js +2 -0
- package/dist/commands/hook/pre-push.js +447 -0
- package/dist/commands/hook.js +65 -0
- package/dist/commands/identity.js +244 -0
- package/dist/commands/init.js +201 -0
- package/dist/commands/integration/adapter-parity.js +74 -0
- package/dist/commands/integration/adapters.js +127 -0
- package/dist/commands/integration/bootstrap.js +109 -0
- package/dist/commands/integration/health.js +253 -0
- package/dist/commands/integration/install.js +46 -0
- package/dist/commands/integration/list.js +16 -0
- package/dist/commands/integration/run.js +208 -0
- package/dist/commands/integration/types.js +1 -0
- package/dist/commands/integration-hooks/implementation.js +807 -0
- package/dist/commands/integration-hooks.js +1 -0
- package/dist/commands/integration.js +5 -0
- package/dist/commands/internal-release/command.js +113 -0
- package/dist/commands/internal-release/constants.js +5 -0
- package/dist/commands/internal-release/options.js +79 -0
- package/dist/commands/internal-release/publication.js +104 -0
- package/dist/commands/internal-release/scratch.js +72 -0
- package/dist/commands/internal-release/support.js +79 -0
- package/dist/commands/internal-release/target-sync.js +122 -0
- package/dist/commands/internal-release/types.js +1 -0
- package/dist/commands/internal-release.js +2 -0
- package/dist/commands/lane-session/adopt-rebind.js +113 -0
- package/dist/commands/lane-session/capability-authority.js +223 -0
- package/dist/commands/lane-session/events.js +102 -0
- package/dist/commands/lane-session/mutation-authority-adapter.js +96 -0
- package/dist/commands/lane-session/mutation-status-command.js +61 -0
- package/dist/commands/lane-session/proxy-receipt.js +219 -0
- package/dist/commands/lane-session/redaction.js +66 -0
- package/dist/commands/lane-session/resolve.js +114 -0
- package/dist/commands/lane-session/store.js +336 -0
- package/dist/commands/lane.js +550 -0
- package/dist/commands/lock.js +132 -0
- package/dist/commands/map-capsule.js +194 -0
- package/dist/commands/migrate.js +193 -0
- package/dist/commands/next/active-work-summary.js +88 -0
- package/dist/commands/next/broker-queue-admission.js +95 -0
- package/dist/commands/next/channel-strategy.js +172 -0
- package/dist/commands/next/claim-admission.js +254 -0
- package/dist/commands/next/claim-cleanup.js +24 -0
- package/dist/commands/next/claim-conflict-log.js +122 -0
- package/dist/commands/next/claim-delivery-admission.js +35 -0
- package/dist/commands/next/claim-early-results.js +120 -0
- package/dist/commands/next/claim-helpers.js +81 -0
- package/dist/commands/next/claim-lane-session.js +38 -0
- package/dist/commands/next/claim-orchestration.js +579 -0
- package/dist/commands/next/claim-parallel-preflight.js +368 -0
- package/dist/commands/next/claim-readiness.js +158 -0
- package/dist/commands/next/claim-scope-expansion-admission.js +22 -0
- package/dist/commands/next/cross-repo-framework-result.js +40 -0
- package/dist/commands/next/foreign-dirty-wip-admission.js +162 -0
- package/dist/commands/next/governance-readiness.js +149 -0
- package/dist/commands/next/intent-normalizers.js +212 -0
- package/dist/commands/next/match-and-sort.js +183 -0
- package/dist/commands/next/next-action-assembly.js +118 -0
- package/dist/commands/next/oversized-extraction-admission.js +79 -0
- package/dist/commands/next/plan-scoped-preflight.js +145 -0
- package/dist/commands/next/planning-root-preference.js +264 -0
- package/dist/commands/next/playbook-projection/active-work-summary.js +380 -0
- package/dist/commands/next/playbook-projection/channel-playbook.js +198 -0
- package/dist/commands/next/playbook-projection/governance-readiness.js +67 -0
- package/dist/commands/next/playbook-projection/legacy-guidance.js +151 -0
- package/dist/commands/next/playbook-projection/message-assembly.js +120 -0
- package/dist/commands/next/playbook-projection/task-reservation-projection.js +126 -0
- package/dist/commands/next/playbook-projection/task-routing.js +275 -0
- package/dist/commands/next/playbook-projection.js +7 -0
- package/dist/commands/next/profiler.js +22 -0
- package/dist/commands/next/prompt-guidance-result.js +177 -0
- package/dist/commands/next/prompt-result-contracts.js +273 -0
- package/dist/commands/next/prompt-results.js +505 -0
- package/dist/commands/next/prompt-scope-resolution.js +12 -0
- package/dist/commands/next/proposal-lane.js +122 -0
- package/dist/commands/next/result-compaction.js +120 -0
- package/dist/commands/next/route-predicates.js +112 -0
- package/dist/commands/next/route-resolution/artifact-scope.js +215 -0
- package/dist/commands/next/route-resolution/intent.js +163 -0
- package/dist/commands/next/route-resolution/matching.js +446 -0
- package/dist/commands/next/route-resolution/pending-worktree.js +257 -0
- package/dist/commands/next/route-resolution/queue-inspection.js +391 -0
- package/dist/commands/next/route-resolution/runtime.js +111 -0
- package/dist/commands/next/route-resolution/task-card-discovery.js +190 -0
- package/dist/commands/next/route-resolution.js +7 -0
- package/dist/commands/next/runner-mode.js +98 -0
- package/dist/commands/next/runner-recovery-claim-authorization.js +30 -0
- package/dist/commands/next/task-scoped-claim-command.js +24 -0
- package/dist/commands/next/view-projections.js +51 -0
- package/dist/commands/next/worktree-hints.js +11 -0
- package/dist/commands/next-active-batch.js +39 -0
- package/dist/commands/next.js +257 -0
- package/dist/commands/orient.js +22 -0
- package/dist/commands/output-projection.js +37 -0
- package/dist/commands/plan.js +458 -0
- package/dist/commands/planning-repo-root.js +312 -0
- package/dist/commands/planning-root-resolution-cache.js +0 -0
- package/dist/commands/police.js +166 -0
- package/dist/commands/quickfix.js +76 -0
- package/dist/commands/registry/lineage-normalization.js +125 -0
- package/dist/commands/registry-diff.js +145 -0
- package/dist/commands/registry-shared.js +153 -0
- package/dist/commands/registry.js +533 -0
- package/dist/commands/replacement-lane.js +82 -0
- package/dist/commands/rescue.js +306 -0
- package/dist/commands/residue.js +483 -0
- package/dist/commands/review-advisory.js +480 -0
- package/dist/commands/review.js +514 -0
- package/dist/commands/rollback.js +271 -0
- package/dist/commands/route/files.js +42 -0
- package/dist/commands/route/freeze-patch.js +141 -0
- package/dist/commands/route/lifecycle.js +206 -0
- package/dist/commands/route/main.js +10 -0
- package/dist/commands/route/parser.js +177 -0
- package/dist/commands/route/takeover.js +152 -0
- package/dist/commands/route/types.js +2 -0
- package/dist/commands/route/validation.js +77 -0
- package/dist/commands/route.js +1 -0
- package/dist/commands/runner-sync.js +2 -0
- package/dist/commands/runtime-adapter-readiness.js +150 -0
- package/dist/commands/self-host-alpha.js +293 -0
- package/dist/commands/shared/command-manifest.js +104 -0
- package/dist/commands/shared/command-spec-output.js +304 -0
- package/dist/commands/shared/identity-normalization.js +208 -0
- package/dist/commands/shared/option-and-file-tools.js +451 -0
- package/dist/commands/shared/result-core.js +292 -0
- package/dist/commands/shared.js +3 -0
- package/dist/commands/spec-shared.js +108 -0
- package/dist/commands/spec.js +13 -0
- package/dist/commands/start.js +115 -0
- package/dist/commands/status.js +214 -0
- package/dist/commands/task-direction/active-locks.js +98 -0
- package/dist/commands/task-direction/scope-policy.js +104 -0
- package/dist/commands/task-direction/support.js +204 -0
- package/dist/commands/task-direction.js +305 -0
- package/dist/commands/task-intent.js +163 -0
- package/dist/commands/task-ledger.js +149 -0
- package/dist/commands/task-view.js +146 -0
- package/dist/commands/taskflow/auto-evidence-mapper.js +147 -0
- package/dist/commands/taskflow/branch-commit-queue-gate.js +127 -0
- package/dist/commands/taskflow/broker-gate.js +253 -0
- package/dist/commands/taskflow/close-orchestration.js +511 -0
- package/dist/commands/taskflow/close-owned-delivery-dirty-admission.js +70 -0
- package/dist/commands/taskflow/close-preflight.js +403 -0
- package/dist/commands/taskflow/close-side-effect-reconcile.js +51 -0
- package/dist/commands/taskflow/close-transaction-hook-receipt.js +36 -0
- package/dist/commands/taskflow/close-transaction-mutex.js +108 -0
- package/dist/commands/taskflow/closeback-orchestration.js +204 -0
- package/dist/commands/taskflow/commit-bundle-assembly.js +613 -0
- package/dist/commands/taskflow/commit-messages.js +9 -0
- package/dist/commands/taskflow/cross-authority-closeback.js +308 -0
- package/dist/commands/taskflow/current-task-close-evidence.js +51 -0
- package/dist/commands/taskflow/dirty-blockers.js +46 -0
- package/dist/commands/taskflow/governance-dirty-deferral.js +21 -0
- package/dist/commands/taskflow/historical-close-preflight.js +426 -0
- package/dist/commands/taskflow/host-opener-policy.js +229 -0
- package/dist/commands/taskflow/implementation.js +722 -0
- package/dist/commands/taskflow/markdown-paths.js +7 -0
- package/dist/commands/taskflow/profile-loader.js +280 -0
- package/dist/commands/taskflow/runner-publication-close-queue.js +31 -0
- package/dist/commands/taskflow/runner-recovery-forwarding.js +55 -0
- package/dist/commands/taskflow/runner-selection-evidence.js +26 -0
- package/dist/commands/taskflow/task-scope.js +84 -0
- package/dist/commands/taskflow/transaction-status.js +3 -0
- package/dist/commands/taskflow/write-readiness.js +323 -0
- package/dist/commands/taskflow.js +1 -0
- package/dist/commands/tasks/acceptance-evidence-import.js +119 -0
- package/dist/commands/tasks/canonical-task-id-boundary.js +23 -0
- package/dist/commands/tasks/claim-intent.js +110 -0
- package/dist/commands/tasks/claim-orchestrator.js +559 -0
- package/dist/commands/tasks/claim-ownership.js +145 -0
- package/dist/commands/tasks/claim-preparation.js +251 -0
- package/dist/commands/tasks/claim-repair-diagnostics.js +466 -0
- package/dist/commands/tasks/claim-work-admission.js +290 -0
- package/dist/commands/tasks/close-governance.js +173 -0
- package/dist/commands/tasks/close-helpers/broker-admission-explanation.js +75 -0
- package/dist/commands/tasks/close-helpers/close-artifact-staging.js +257 -0
- package/dist/commands/tasks/close-helpers/close-window-diagnostics.js +172 -0
- package/dist/commands/tasks/close-helpers/task-transition-writer.js +108 -0
- package/dist/commands/tasks/close-orchestrator/acceptance-evidence-gate.js +84 -0
- package/dist/commands/tasks/close-orchestrator/close-result.js +35 -0
- package/dist/commands/tasks/close-orchestrator/close-write.js +200 -0
- package/dist/commands/tasks/close-orchestrator/closure-packet.js +109 -0
- package/dist/commands/tasks/close-orchestrator/historical-context.js +48 -0
- package/dist/commands/tasks/close-orchestrator/runner-recovery.js +30 -0
- package/dist/commands/tasks/close-orchestrator.js +535 -0
- package/dist/commands/tasks/close-window-lock.js +420 -0
- package/dist/commands/tasks/close-window-residue-classification.js +137 -0
- package/dist/commands/tasks/close-window-staged-index-admission.js +20 -0
- package/dist/commands/tasks/closeout-provenance.js +126 -0
- package/dist/commands/tasks/closeout-signaling.js +1 -0
- package/dist/commands/tasks/command-dispatch.js +86 -0
- package/dist/commands/tasks/contract-import-recovery.js +17 -0
- package/dist/commands/tasks/deliver-close-orchestrator.js +251 -0
- package/dist/commands/tasks/dependency-gate.js +429 -0
- package/dist/commands/tasks/dependency-gates.js +1 -0
- package/dist/commands/tasks/generated-residue-policy.js +121 -0
- package/dist/commands/tasks/historical-delivery.js +411 -0
- package/dist/commands/tasks/import-card-contract-validation.js +124 -0
- package/dist/commands/tasks/import-orchestrator.js +488 -0
- package/dist/commands/tasks/import-planning-authority.js +1 -0
- package/dist/commands/tasks/import-task.js +150 -0
- package/dist/commands/tasks/import-validation.js +70 -0
- package/dist/commands/tasks/import-verify.js +195 -0
- package/dist/commands/tasks/is-frontmatter-scalar-helper.js +9 -0
- package/dist/commands/tasks/legacy/compat-command-map.js +4 -0
- package/dist/commands/tasks/legacy/implementation.js +1176 -0
- package/dist/commands/tasks/legacy/repair-reconcile-lane.js +3 -0
- package/dist/commands/tasks/legacy/transition-compat.js +3 -0
- package/dist/commands/tasks/legacy-impl.js +2 -0
- package/dist/commands/tasks/lifecycle-state.js +151 -0
- package/dist/commands/tasks/normalize-string-value-helper.js +6 -0
- package/dist/commands/tasks/normalize-task-document-id-helper.js +7 -0
- package/dist/commands/tasks/plan-import-boundary.js +58 -0
- package/dist/commands/tasks/planning-mirror-close-diagnostics.js +95 -0
- package/dist/commands/tasks/planning-root-authorship.js +153 -0
- package/dist/commands/tasks/planning-source-seal-policy.js +125 -0
- package/dist/commands/tasks/public-surface.js +11 -0
- package/dist/commands/tasks/read-projection.js +213 -0
- package/dist/commands/tasks/realign-plan-source.js +437 -0
- package/dist/commands/tasks/reconcile-orchestrator.js +342 -0
- package/dist/commands/tasks/release-wip-transaction.js +59 -0
- package/dist/commands/tasks/repair-claim-orchestrator.js +174 -0
- package/dist/commands/tasks/repairclose-orchestrator.js +232 -0
- package/dist/commands/tasks/residue-diagnostics.js +175 -0
- package/dist/commands/tasks/result-contracts.js +43 -0
- package/dist/commands/tasks/scope-amendment/implementation.js +137 -0
- package/dist/commands/tasks/scope-lock-diagnostics.js +234 -0
- package/dist/commands/tasks/scope-preflight/implementation.js +24 -0
- package/dist/commands/tasks/scope-queue.js +13 -0
- package/dist/commands/tasks/seal-plan-source.js +98 -0
- package/dist/commands/tasks/sha256-helper.js +7 -0
- package/dist/commands/tasks/status-triangulation.js +284 -0
- package/dist/commands/tasks/surface-invariants.js +84 -0
- package/dist/commands/tasks/takeover-evidence.js +29 -0
- package/dist/commands/tasks/task-atomization-policy-import.js +139 -0
- package/dist/commands/tasks/task-card-contract-import.js +336 -0
- package/dist/commands/tasks/task-card-writer.js +13 -0
- package/dist/commands/tasks/task-file-io-helpers.js +62 -0
- package/dist/commands/tasks/task-frontmatter-fidelity.js +269 -0
- package/dist/commands/tasks/task-git-helpers.js +40 -0
- package/dist/commands/tasks/task-import-diagnostics.js +45 -0
- package/dist/commands/tasks/task-import-status-normalization.js +20 -0
- package/dist/commands/tasks/task-import-validators.js +442 -0
- package/dist/commands/tasks/task-ledger-readers.js +102 -0
- package/dist/commands/tasks/task-markdown-helpers.js +358 -0
- package/dist/commands/tasks/task-option-parsers/close-delivery-options.js +156 -0
- package/dist/commands/tasks/task-option-parsers/create-close-options.js +233 -0
- package/dist/commands/tasks/task-option-parsers/helpers.js +37 -0
- package/dist/commands/tasks/task-option-parsers/misc-claim-options.js +350 -0
- package/dist/commands/tasks/task-option-parsers/scope-options.js +211 -0
- package/dist/commands/tasks/task-option-parsers/status-options.js +43 -0
- package/dist/commands/tasks/task-option-parsers.js +6 -0
- package/dist/commands/tasks/task-transition-helpers.js +166 -0
- package/dist/commands/tasks/task-work-admission-import.js +54 -0
- package/dist/commands/tasks/verify-orchestrator.js +160 -0
- package/dist/commands/tasks.js +5 -0
- package/dist/commands/team/admission-command.js +7 -0
- package/dist/commands/team/admission.js +141 -0
- package/dist/commands/team/command-registry.js +26 -0
- package/dist/commands/team/composer.js +78 -0
- package/dist/commands/team/cost-command.js +27 -0
- package/dist/commands/team/efficiency-controller.js +198 -0
- package/dist/commands/team/execute-command.js +6 -0
- package/dist/commands/team/growth-contract.js +128 -0
- package/dist/commands/team/legacy/broker-observability.js +366 -0
- package/dist/commands/team/legacy/command-runner.js +348 -0
- package/dist/commands/team/legacy/crew-decision-policy.js +418 -0
- package/dist/commands/team/legacy/handoff-handler.js +60 -0
- package/dist/commands/team/legacy/implementer-selector-policy.js +209 -0
- package/dist/commands/team/legacy/lifecycle-handler.js +163 -0
- package/dist/commands/team/legacy/patrol-contracts.js +212 -0
- package/dist/commands/team/legacy/patrol-handler.js +213 -0
- package/dist/commands/team/legacy/permission-lease-policy.js +386 -0
- package/dist/commands/team/legacy/plan-orchestration.js +360 -0
- package/dist/commands/team/legacy/planning-context.js +314 -0
- package/dist/commands/team/legacy/provider-execution.js +337 -0
- package/dist/commands/team/legacy/runtime-contracts.js +241 -0
- package/dist/commands/team/legacy/runtime-governance.js +419 -0
- package/dist/commands/team/legacy/team-run-runtime.js +186 -0
- package/dist/commands/team/legacy/team-run-store.js +160 -0
- package/dist/commands/team/legacy/team-utils.js +102 -0
- package/dist/commands/team/legacy/types.js +150 -0
- package/dist/commands/team/plan-command.js +4 -0
- package/dist/commands/team/proposal-workspace.js +139 -0
- package/dist/commands/team/provider-preflight.js +57 -0
- package/dist/commands/team/report-command.js +14 -0
- package/dist/commands/team/role-provider-resolution.js +46 -0
- package/dist/commands/team/role-skill-packs.js +238 -0
- package/dist/commands/team/runtime-bridges.js +81 -0
- package/dist/commands/team/runtime-tier-contract.js +32 -0
- package/dist/commands/team/scheduler.js +165 -0
- package/dist/commands/team/shadow-plan.js +77 -0
- package/dist/commands/team/shadow-workspace.js +1 -0
- package/dist/commands/team/start-command.js +4 -0
- package/dist/commands/team/status-command.js +4 -0
- package/dist/commands/team/team-execution-lane.js +66 -0
- package/dist/commands/team/team-route-map.js +55 -0
- package/dist/commands/team-knowledge/actions.js +210 -0
- package/dist/commands/team-knowledge/main.js +36 -0
- package/dist/commands/team-knowledge/metadata.js +120 -0
- package/dist/commands/team-knowledge/permission.js +34 -0
- package/dist/commands/team-knowledge/ranking.js +186 -0
- package/dist/commands/team-knowledge/runtime-utils.js +105 -0
- package/dist/commands/team-knowledge/spec.js +30 -0
- package/dist/commands/team-knowledge/summary.js +55 -0
- package/dist/commands/team-knowledge/text-utils.js +29 -0
- package/dist/commands/team-knowledge/types.js +1 -0
- package/dist/commands/team-knowledge.js +2 -0
- package/dist/commands/team-legacy.js +101 -0
- package/dist/commands/team-runtime-cleanup.js +56 -0
- package/dist/commands/team-runtime-gates.js +198 -0
- package/dist/commands/team-wave.js +387 -0
- package/dist/commands/team.js +2 -0
- package/dist/commands/telemetry.js +149 -0
- package/dist/commands/test-catalog.js +354 -0
- package/dist/commands/test.js +301 -0
- package/dist/commands/upgrade/canary.js +45 -0
- package/dist/commands/upgrade/experimental.js +97 -0
- package/dist/commands/upgrade/next-action-hint.js +56 -0
- package/dist/commands/upgrade/path-helpers.js +66 -0
- package/dist/commands/upgrade/proposal/context-budget.js +187 -0
- package/dist/commands/upgrade/proposal/guided-legacy.js +90 -0
- package/dist/commands/upgrade/proposal/inputs.js +86 -0
- package/dist/commands/upgrade/proposal/parse.js +221 -0
- package/dist/commands/upgrade/proposal/types.js +1 -0
- package/dist/commands/upgrade/proposal.js +4 -0
- package/dist/commands/upgrade/safe-upgrade.js +339 -0
- package/dist/commands/upgrade/scan.js +76 -0
- package/dist/commands/upgrade-map-propose.js +64 -0
- package/dist/commands/upgrade.js +106 -0
- package/dist/commands/validate.js +429 -0
- package/dist/commands/validation-obligations.js +142 -0
- package/dist/commands/verify.js +151 -0
- package/dist/commands/welcome.js +180 -0
- package/dist/commands/work-channels.js +493 -0
- package/dist/commands/write-ticket.js +226 -0
- package/dist/config/env-registry.js +88 -0
- package/dist/index.js +350 -0
- package/dist/migration/codemod-registry.js +82 -0
- package/dist/migration/migration-index.json +15 -0
- package/dist/plugin-registry.js +49 -0
- package/dist/startup-integrity.js +88 -0
- package/dist/startup-known-bad.js +187 -0
- package/dist/telemetry/index.js +78 -0
- package/dist/temp-workspace.js +49 -0
- package/package.json +102 -0
|
@@ -0,0 +1,965 @@
|
|
|
1
|
+
export { inspectSameFileClaimOwnership } from './scope-ownership.js';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { existsSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { findCloseCommitWindowCoveringPaths, readActiveCloseCommitWindows } from '../../framework-development.js';
|
|
6
|
+
import { findActorByResolvedId, inspectTrackedActorRegistryState, readRuntimeIdentityDefault, readRuntimeIdentityForActor } from '../../actor-registry.js';
|
|
7
|
+
import { resolveActorWorkSession } from '../../actor-session.js';
|
|
8
|
+
import { hasLiveFrameworkTempClaimAttribution } from './framework-temp-claim-attribution.js';
|
|
9
|
+
import { CliError, quoteCliValue, relativePathFrom } from '../../shared.js';
|
|
10
|
+
import { isPlanningMirrorPath, isTaskDirectionPathCandidate, readActiveTaskDirectionLocks } from '../../task-direction.js';
|
|
11
|
+
import { isPathAllowedByScope, listActiveBatchRuns } from '../../work-channels.js';
|
|
12
|
+
import { buildPendingCheckpointCommitWindow } from '../../batch.js';
|
|
13
|
+
import { listTaskOwnedProtectedOverrideAuditFiles } from '../../git-governance.js';
|
|
14
|
+
import { findCaseInsensitiveRelativePath, taskIdsEqual, taskIdsInclude } from '../../tasks/task-import-validators.js';
|
|
15
|
+
import { normalizeRelativePath, runGit, runGitScalar } from '../git-index-diagnostics.js';
|
|
16
|
+
import { normalizeOptionalText, readGitObjectText, readJsonText } from '../commit-range-guard.js';
|
|
17
|
+
import { readStagedFiles } from './input-state.js';
|
|
18
|
+
import { resolveCommittedTaskContext } from './committed-task-context.js';
|
|
19
|
+
export const INVARIANT_TASK_AUDIT_CODES = new Set(['ATM_TASK_AUDIT_CROSS_REPO_DONE_WITHOUT_PACKET', 'ATM_TASK_AUDIT_BULK_CLOSE_WITHOUT_MANIFEST']);
|
|
20
|
+
const textFileExtensions = new Set(['.cjs', '.css', '.html', '.js', '.json', '.jsx', '.md', '.mjs', '.ps1', '.sh', '.ts', '.tsx', '.txt', '.yaml', '.yml']);
|
|
21
|
+
export function isResolutionAuthorizedCurrentTask(cwd, taskId, conflictTaskId) {
|
|
22
|
+
const artifactPath = normalizeOptionalText(process.env.ATM_COMMIT_BROKER_CONFLICT_RESOLUTION);
|
|
23
|
+
if (!artifactPath || !taskId)
|
|
24
|
+
return false;
|
|
25
|
+
try {
|
|
26
|
+
const artifact = JSON.parse(readFileSync(path.resolve(cwd, artifactPath), 'utf8'));
|
|
27
|
+
const blocked = Array.isArray(artifact.blockedTaskIds) ? artifact.blockedTaskIds.map((value) => String(value).trim()) : [];
|
|
28
|
+
return artifact.schemaId === 'atm.brokerConflictResolution.v1' && String(artifact.primaryTaskId ?? '').trim() === taskId && String(artifact.currentAllowedTaskId ?? '').trim() === taskId && blocked.includes(conflictTaskId);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function selectRelevantDirectionLocksForCommit(input) {
|
|
35
|
+
const currentTaskAllowedFiles = uniqueSorted([...input.taskGovernedCommitAllowedFiles, ...input.closeCommitWindowAllowedFiles, ...input.closeCommitWindowPlanningMirrorFiles]);
|
|
36
|
+
return input.activeDirectionLocks.filter((lock) => {
|
|
37
|
+
if (input.committingTaskId && taskIdsEqual(lock.taskId, input.committingTaskId)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return input.stagedFiles.some((entry) => {
|
|
41
|
+
if (isTaskDirectionPreCommitExempt(entry))
|
|
42
|
+
return false;
|
|
43
|
+
if (currentTaskAllowedFiles.length > 0 && isPathAllowedByTaskDirection(entry, currentTaskAllowedFiles)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return isPathAllowedByTaskDirection(entry, lock.allowedFiles) || isPlanningMirrorPath(entry, lock.planningMirrorPaths ?? []);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export function isTaskDirectionPreCommitExempt(value) {
|
|
51
|
+
const normalized = normalizeRelativePath(value).toLowerCase();
|
|
52
|
+
return normalized.startsWith('.atm/history/task-events/') || normalized.startsWith('.atm/history/evidence/') || normalized.startsWith('.atm/runtime/locks/') || normalized.startsWith('.atm/runtime/task-queues/') || normalized.startsWith('.atm/runtime/batch-runs/') || normalized.startsWith('.atm/runtime/task-direction-locks/');
|
|
53
|
+
}
|
|
54
|
+
export function collectStagedBatchCheckpointScopeFiles(cwd, stagedFiles) {
|
|
55
|
+
const stagedSet = new Set(stagedFiles.map((entry) => normalizeRelativePath(entry)));
|
|
56
|
+
const allowedFiles = [];
|
|
57
|
+
for (const file of stagedFiles) {
|
|
58
|
+
const normalized = normalizeRelativePath(file);
|
|
59
|
+
const lower = normalized.toLowerCase();
|
|
60
|
+
if (!lower.startsWith('.atm/history/tasks/') || !lower.endsWith('.json')) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const task = readJsonFile(path.join(cwd, normalized));
|
|
64
|
+
if (task?.status !== 'done')
|
|
65
|
+
continue;
|
|
66
|
+
const taskId = typeof task.workItemId === 'string' ? task.workItemId : path.basename(normalized, '.json');
|
|
67
|
+
const lastTransitionId = typeof task.lastTransitionId === 'string' ? task.lastTransitionId : '';
|
|
68
|
+
const expectedEventPath = `.atm/history/task-events/${taskId}/${lastTransitionId}.json`;
|
|
69
|
+
if (!lastTransitionId || !stagedSet.has(expectedEventPath)) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const event = readJsonFile(path.join(cwd, expectedEventPath));
|
|
73
|
+
const closure = event?.closure;
|
|
74
|
+
if (typeof event?.command !== 'string' || !event.command.startsWith('node atm.mjs tasks close') || (!event.command.includes('--from-batch-checkpoint') && closure?.schemaId !== 'atm.taskClosureTransition.v1')) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
allowedFiles.push(normalized);
|
|
78
|
+
allowedFiles.push(...extractCheckpointTaskScopeFiles(task));
|
|
79
|
+
}
|
|
80
|
+
return uniqueSorted(allowedFiles);
|
|
81
|
+
}
|
|
82
|
+
export function collectFrameworkTempClaimAllowedFiles(cwd) {
|
|
83
|
+
const lockRoot = path.join(cwd, '.atm', 'runtime', 'locks');
|
|
84
|
+
if (!existsSync(lockRoot))
|
|
85
|
+
return [];
|
|
86
|
+
const allowedFiles = [];
|
|
87
|
+
for (const entry of readdirSync(lockRoot).filter((fileName) => fileName.startsWith('ATM-FRAMEWORK-TEMP-') && fileName.endsWith('.lock.json'))) {
|
|
88
|
+
const lock = readJsonFile(path.join(lockRoot, entry));
|
|
89
|
+
collectStringArrayField(lock?.files, allowedFiles);
|
|
90
|
+
}
|
|
91
|
+
return uniqueSorted(allowedFiles.map(normalizeRelativePath).filter(isTaskDirectionPathCandidate));
|
|
92
|
+
}
|
|
93
|
+
export function collectCloseCommitWindowPlanningMirrorFiles(cwd) {
|
|
94
|
+
const files = [];
|
|
95
|
+
for (const win of readActiveCloseCommitWindows(cwd)) {
|
|
96
|
+
const task = readJsonFile(path.join(cwd, '.atm', 'history', 'tasks', `${win.taskId}.json`));
|
|
97
|
+
if (!task || typeof task !== 'object')
|
|
98
|
+
continue;
|
|
99
|
+
const source = isPlainObject(task.source) ? task.source : null;
|
|
100
|
+
const planPath = typeof source?.planPath === 'string' ? normalizeRelativePath(source.planPath) : '';
|
|
101
|
+
if (planPath)
|
|
102
|
+
files.push(planPath);
|
|
103
|
+
collectStringArrayField(task.planningMirrorPaths, files);
|
|
104
|
+
}
|
|
105
|
+
return uniqueSorted(files.map(normalizeRelativePath).filter(isTaskDirectionPathCandidate));
|
|
106
|
+
}
|
|
107
|
+
export function collectTaskGovernedCommitAllowedFiles(cwd, taskId) {
|
|
108
|
+
if (!taskId)
|
|
109
|
+
return [];
|
|
110
|
+
const files = [`.atm/history/tasks/${taskId}.json`, `.atm/history/evidence/${taskId}.json`, `.atm/history/evidence/${taskId}.bundle-manifest.json`, `.atm/history/evidence/${taskId}.closure-packet.json`, `.atm/history/task-events/${taskId}/**`];
|
|
111
|
+
const task = readJsonFile(path.join(cwd, '.atm', 'history', 'tasks', `${taskId}.json`));
|
|
112
|
+
if (task && typeof task === 'object') {
|
|
113
|
+
const source = isPlainObject(task.source) ? task.source : null;
|
|
114
|
+
const planPath = typeof source?.planPath === 'string' ? normalizeRelativePath(source.planPath) : '';
|
|
115
|
+
if (planPath)
|
|
116
|
+
files.push(planPath);
|
|
117
|
+
collectStringArrayField(task.planningMirrorPaths, files);
|
|
118
|
+
}
|
|
119
|
+
const actorRegistryState = inspectTrackedActorRegistryState(cwd);
|
|
120
|
+
if (actorRegistryState.tracked && (actorRegistryState.staged || actorRegistryState.unstaged)) {
|
|
121
|
+
files.push(actorRegistryState.path);
|
|
122
|
+
}
|
|
123
|
+
files.push(...listTaskOwnedProtectedOverrideAuditFiles(cwd, taskId));
|
|
124
|
+
return uniqueSorted(files.map(normalizeRelativePath).filter(isTaskDirectionPathCandidate));
|
|
125
|
+
}
|
|
126
|
+
function extractCheckpointTaskScopeFiles(task) {
|
|
127
|
+
const candidates = [];
|
|
128
|
+
collectStringArrayField(task.scope, candidates);
|
|
129
|
+
collectStringArrayField(task.scopePaths, candidates);
|
|
130
|
+
collectStringArrayField(task.deliverables, candidates);
|
|
131
|
+
collectStringArrayField(task.files, candidates);
|
|
132
|
+
collectStringArrayField(task.allowedFiles, candidates);
|
|
133
|
+
const targetWork = isPlainObject(task.targetWork) ? task.targetWork : null;
|
|
134
|
+
if (targetWork) {
|
|
135
|
+
collectStringArrayField(targetWork.allowedFiles, candidates);
|
|
136
|
+
collectStringArrayField(targetWork.files, candidates);
|
|
137
|
+
}
|
|
138
|
+
return uniqueSorted(candidates.map(normalizeRelativePath).filter(isTaskDirectionPathCandidate));
|
|
139
|
+
}
|
|
140
|
+
function collectStringArrayField(value, output) {
|
|
141
|
+
if (!Array.isArray(value))
|
|
142
|
+
return;
|
|
143
|
+
for (const entry of value) {
|
|
144
|
+
if (typeof entry === 'string')
|
|
145
|
+
output.push(entry);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function isPlainObject(value) {
|
|
149
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Evaluates protected evidence as a task-scoped bundle. Evidence filenames are
|
|
153
|
+
* intentionally not an authority: append-only evidence commonly carries a
|
|
154
|
+
* semantic suffix, so identity must come from the staged ledger, transition,
|
|
155
|
+
* or the evidence payload itself.
|
|
156
|
+
*/
|
|
157
|
+
export function classifyProtectedEvidenceBundle(cwd, stagedFiles) {
|
|
158
|
+
const contexts = new Map();
|
|
159
|
+
const evidenceByPath = new Map();
|
|
160
|
+
const evidenceRecords = new Map();
|
|
161
|
+
const lockBackedRunnerReceipts = new Set();
|
|
162
|
+
const linkedRunnerReceiptTaskId = (file, evidence, taskId) => {
|
|
163
|
+
if (evidence?.schemaId !== 'atm.runnerSyncReceipt.v1' || !taskId)
|
|
164
|
+
return taskId;
|
|
165
|
+
const lockRoot = path.join(cwd, '.atm', 'runtime', 'locks');
|
|
166
|
+
for (const entry of existsSync(lockRoot) ? readdirSync(lockRoot) : []) {
|
|
167
|
+
if (!entry.endsWith('.lock.json'))
|
|
168
|
+
continue;
|
|
169
|
+
const lock = readJsonFile(path.join(lockRoot, entry));
|
|
170
|
+
const declaredFiles = Array.isArray(lock?.files) ? lock.files.map(normalizeRelativePath) : [];
|
|
171
|
+
if (lock?.workItemId === taskId && normalizeRelativePath(file) === `.atm/history/evidence/${taskId}.runner-sync-receipt.json` && lock?.actorId === evidence?.actorId) {
|
|
172
|
+
const context = contexts.get(taskId) ?? { ledger: false, event: false };
|
|
173
|
+
context.event = true;
|
|
174
|
+
contexts.set(taskId, context);
|
|
175
|
+
lockBackedRunnerReceipts.add(file.toLowerCase());
|
|
176
|
+
return taskId;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return taskId;
|
|
180
|
+
};
|
|
181
|
+
const markContext = (taskId, field) => {
|
|
182
|
+
const normalizedTaskId = normalizeOptionalText(taskId);
|
|
183
|
+
if (!normalizedTaskId)
|
|
184
|
+
return;
|
|
185
|
+
const context = contexts.get(normalizedTaskId) ?? { ledger: false, event: false };
|
|
186
|
+
context[field] = true;
|
|
187
|
+
contexts.set(normalizedTaskId, context);
|
|
188
|
+
};
|
|
189
|
+
for (const entry of stagedFiles) {
|
|
190
|
+
const normalized = normalizeRelativePath(entry);
|
|
191
|
+
const lower = normalized.toLowerCase();
|
|
192
|
+
const absolutePath = path.join(cwd, normalized);
|
|
193
|
+
const stagedJson = readStagedJsonFile(cwd, normalized);
|
|
194
|
+
const ledgerMatch = normalized.match(/^\.atm\/history\/tasks\/([^/]+)\.json$/i);
|
|
195
|
+
if (ledgerMatch) {
|
|
196
|
+
const ledger = stagedJson;
|
|
197
|
+
markContext(typeof ledger?.workItemId === 'string' ? ledger.workItemId : ledgerMatch[1], 'ledger');
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
const eventMatch = normalized.match(/^\.atm\/history\/task-events\/([^/]+)\//i);
|
|
201
|
+
if (eventMatch) {
|
|
202
|
+
const event = stagedJson;
|
|
203
|
+
markContext(typeof event?.taskId === 'string' ? event.taskId : eventMatch[1], 'event');
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (!lower.startsWith('.atm/history/evidence/') || lower.startsWith('.atm/history/evidence/historical-batches/'))
|
|
207
|
+
continue;
|
|
208
|
+
const evidence = stagedJson;
|
|
209
|
+
const taskIds = new Set();
|
|
210
|
+
if (typeof evidence?.taskId === 'string')
|
|
211
|
+
taskIds.add(linkedRunnerReceiptTaskId(normalized, evidence, evidence.taskId));
|
|
212
|
+
if (Array.isArray(evidence?.attestations))
|
|
213
|
+
for (const attestation of evidence.attestations)
|
|
214
|
+
if (typeof attestation?.taskId === 'string')
|
|
215
|
+
taskIds.add(attestation.taskId);
|
|
216
|
+
if (Array.isArray(evidence?.tasks))
|
|
217
|
+
for (const task of evidence.tasks)
|
|
218
|
+
if (typeof task?.taskId === 'string')
|
|
219
|
+
taskIds.add(task.taskId);
|
|
220
|
+
evidenceByPath.set(lower, [...taskIds].sort((left, right) => left.localeCompare(right)));
|
|
221
|
+
evidenceRecords.set(lower, evidence);
|
|
222
|
+
}
|
|
223
|
+
function readStagedJsonFile(cwd, relativePath) {
|
|
224
|
+
const stagedText = readGitObjectText(cwd, `:${normalizeRelativePath(relativePath)}`);
|
|
225
|
+
if (!stagedText)
|
|
226
|
+
return null;
|
|
227
|
+
try {
|
|
228
|
+
return JSON.parse(stagedText);
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const decisions = new Map();
|
|
235
|
+
const normalizedStringSet = (value) => Array.isArray(value) ? [...new Set(value.filter((entry) => typeof entry === 'string').map((entry) => entry.trim()).filter(Boolean))].sort((left, right) => left.localeCompare(right)) : [];
|
|
236
|
+
const sameStringSet = (left, right) => JSON.stringify(left) === JSON.stringify(right);
|
|
237
|
+
const attestedTemporaryProducerIds = new Set();
|
|
238
|
+
for (const evidence of evidenceRecords.values()) {
|
|
239
|
+
if (evidence?.schemaId !== 'atm.runnerSyncReceipt.v1' || typeof evidence?.taskId !== 'string')
|
|
240
|
+
continue;
|
|
241
|
+
const closingTaskId = evidence.taskId.trim();
|
|
242
|
+
const linkedTaskIds = normalizedStringSet(evidence.linkedTaskIds);
|
|
243
|
+
const memberTaskIds = normalizedStringSet(evidence.memberTaskIds);
|
|
244
|
+
const groupTaskIds = normalizedStringSet(evidence?.groupManifest?.memberTaskIds);
|
|
245
|
+
const childTaskIds = normalizedStringSet(Array.isArray(evidence?.childAttribution?.members) ? evidence.childAttribution.members.map((entry) => entry?.taskId) : []);
|
|
246
|
+
if (!closingTaskId.startsWith('ATM-FRAMEWORK-TEMP-') && linkedTaskIds.includes(closingTaskId) && memberTaskIds.length > 0 && memberTaskIds.every((taskId) => taskId.startsWith('ATM-FRAMEWORK-TEMP-')) && sameStringSet(memberTaskIds, groupTaskIds) && evidence?.childAttribution?.complete === true && sameStringSet(memberTaskIds, childTaskIds))
|
|
247
|
+
for (const taskId of memberTaskIds)
|
|
248
|
+
attestedTemporaryProducerIds.add(taskId);
|
|
249
|
+
}
|
|
250
|
+
const bundleTaskIds = new Set([...contexts.keys(), ...[...evidenceByPath.values()].flat().filter((taskId) => !attestedTemporaryProducerIds.has(taskId))]);
|
|
251
|
+
for (const [file, taskIds] of evidenceByPath) {
|
|
252
|
+
const isIndependentRunnerWitness = lockBackedRunnerReceipts.has(file) && taskIds.length === 1 && Boolean(contexts.get(taskIds[0])?.event);
|
|
253
|
+
const isAttestedTemporaryProducerReceipt = taskIds.length === 1 && attestedTemporaryProducerIds.has(taskIds[0]) && evidenceRecords.get(file)?.schemaId === 'atm.runnerSyncReceipt.v1';
|
|
254
|
+
if (bundleTaskIds.size > 1 && !isIndependentRunnerWitness && !isAttestedTemporaryProducerReceipt) {
|
|
255
|
+
decisions.set(file, { ok: false, taskId: null, reason: 'bundle-with-ambiguous-task-ids' });
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (taskIds.length !== 1) {
|
|
259
|
+
decisions.set(file, { ok: false, taskId: null, reason: taskIds.length === 0 ? 'evidence-without-semantic-task-id' : 'evidence-with-ambiguous-task-ids' });
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
const taskId = taskIds[0];
|
|
263
|
+
const context = contexts.get(taskId);
|
|
264
|
+
const committedContext = context?.ledger || context?.event ? null : resolveCommittedTaskContext(cwd, taskId);
|
|
265
|
+
decisions.set(file, isAttestedTemporaryProducerReceipt || context?.ledger || context?.event || committedContext?.ok
|
|
266
|
+
? { ok: true, taskId, reason: null }
|
|
267
|
+
: { ok: false, taskId, reason: committedContext?.reason ?? 'evidence-without-staged-task-context' });
|
|
268
|
+
}
|
|
269
|
+
return { contexts, decisions };
|
|
270
|
+
}
|
|
271
|
+
export function inspectProtectedAtmStateChanges(cwd, stagedFiles) {
|
|
272
|
+
const protectedFiles = stagedFiles.filter((entry) => isProtectedAtmManagedStatePath(entry) || isStaticEvidenceArtifactPath(entry));
|
|
273
|
+
const findings = [];
|
|
274
|
+
const activeBatches = listActiveBatchRuns(cwd);
|
|
275
|
+
const stagedBatch = activeBatches.find((batchRun) => batchRun.taskIds.some((taskId) => protectedFiles.some((file) => normalizeRelativePath(file).toLowerCase() === `.atm/history/tasks/${taskId.toLowerCase()}.json`))) ?? null;
|
|
276
|
+
const pendingBatchCheckpointWindow = activeBatches.map((batchRun) => buildPendingCheckpointCommitWindow(cwd, batchRun, null)).find((window) => window && protectedFiles.every((file) => isPathAllowedByScope(file, uniqueSorted([...window.commitFiles, ...window.changedFiles])))) ?? null;
|
|
277
|
+
const batchDeliverAndCloseCommit = process.env.ATM_BATCH_DELIVER_AND_CLOSE === '1';
|
|
278
|
+
const nonAtmStagedFiles = stagedFiles.map((entry) => normalizeRelativePath(entry)).filter((entry) => !entry.toLowerCase().startsWith('.atm/'));
|
|
279
|
+
if (stagedBatch?.status === 'active' && !batchDeliverAndCloseCommit && !pendingBatchCheckpointWindow && nonAtmStagedFiles.length > 0 && !hasStagedBatchCheckpointClosure(cwd, protectedFiles, stagedBatch.taskIds, stagedBatch.batchId)) {
|
|
280
|
+
const requiredCommand = `node atm.mjs batch checkpoint --actor <id> --batch ${stagedBatch.batchId} --json`;
|
|
281
|
+
findings.push({ file: nonAtmStagedFiles[0] ?? '<staged-files>', reason: 'batch-commit-before-checkpoint', detail: `Active batch ${stagedBatch.batchId} has not checkpointed the staged deliverable commit. Run ${requiredCommand} first, then commit the deliverables together with the checkpoint task/evidence/events.`, requiredCommand });
|
|
282
|
+
}
|
|
283
|
+
if (protectedFiles.length === 0) {
|
|
284
|
+
return { ok: findings.length === 0, files: [], findings };
|
|
285
|
+
}
|
|
286
|
+
const stagedTaskIds = inferTaskIdsFromStagedFiles(stagedFiles);
|
|
287
|
+
if (stagedTaskIds.length === 1 && inspectHistoricalLedgerRestoreStagedArtifacts(cwd, stagedTaskIds[0], stagedFiles).ok) {
|
|
288
|
+
return { ok: findings.length === 0, files: protectedFiles, findings };
|
|
289
|
+
}
|
|
290
|
+
const stagedSet = new Set(protectedFiles.map((entry) => normalizeRelativePath(entry)));
|
|
291
|
+
const singleStagedTaskId = stagedTaskIds.length === 1 ? stagedTaskIds[0] : null;
|
|
292
|
+
const effectiveSingleStagedTaskId = singleStagedTaskId ?? pendingBatchCheckpointWindow?.taskId ?? null;
|
|
293
|
+
const pendingBatchCheckpointAllowedFiles = pendingBatchCheckpointWindow ? uniqueSorted([...pendingBatchCheckpointWindow.commitFiles, ...pendingBatchCheckpointWindow.changedFiles]) : [];
|
|
294
|
+
const protectedEvidenceBundle = classifyProtectedEvidenceBundle(cwd, stagedFiles);
|
|
295
|
+
for (const file of protectedFiles) {
|
|
296
|
+
const normalized = normalizeRelativePath(file);
|
|
297
|
+
const lower = normalized.toLowerCase();
|
|
298
|
+
const absolutePath = path.join(cwd, normalized);
|
|
299
|
+
if (lower.startsWith('.atm/history/evidence/') && !lower.startsWith('.atm/history/evidence/historical-batches/')) {
|
|
300
|
+
const decision = protectedEvidenceBundle.decisions.get(lower);
|
|
301
|
+
if (!decision?.ok) {
|
|
302
|
+
findings.push({ file: normalized, reason: 'evidence-file-missing-task-context', detail: `Evidence updates must carry one semantic task identity and a matching staged task ledger or transition event (${decision?.reason ?? 'missing-evidence-decision'}).` });
|
|
303
|
+
}
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
if (isProtectedAtmRuntimeStatePath(normalized)) {
|
|
307
|
+
findings.push({ file: normalized, reason: 'runtime-state-must-not-be-committed', detail: 'Runtime lock, queue, or active-session state must stay ephemeral and must not be committed.' });
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if (lower.startsWith('.atm/history/task-events/')) {
|
|
311
|
+
const event = readJsonFile(absolutePath);
|
|
312
|
+
const command = typeof event?.command === 'string' ? event.command.trim() : '';
|
|
313
|
+
if (event?.schemaId !== 'atm.taskTransition.v1' || typeof event?.transitionId !== 'string' || typeof event?.taskId !== 'string') {
|
|
314
|
+
findings.push({ file: normalized, reason: 'task-transition-json-invalid', detail: 'Task transition event is missing atm.taskTransition.v1 metadata.' });
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (!command.startsWith('node atm.mjs ')) {
|
|
318
|
+
findings.push({ file: normalized, reason: 'task-transition-command-invalid', detail: 'Task transition event does not record a node atm.mjs command as its source.' });
|
|
319
|
+
}
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
if (lower.startsWith('.atm/history/tasks/')) {
|
|
323
|
+
const task = readJsonFile(absolutePath);
|
|
324
|
+
const taskId = typeof task?.workItemId === 'string' ? task.workItemId : path.basename(normalized, '.json');
|
|
325
|
+
const lastTransitionId = typeof task?.lastTransitionId === 'string' ? task.lastTransitionId : '';
|
|
326
|
+
const expectedEventPath = `.atm/history/task-events/${taskId}/${lastTransitionId}.json`;
|
|
327
|
+
const stagedEventPath = lastTransitionId ? findCaseInsensitiveRelativePath(stagedSet, expectedEventPath) : null;
|
|
328
|
+
if (!lastTransitionId || !stagedEventPath) {
|
|
329
|
+
findings.push({ file: normalized, reason: 'task-file-missing-transition', detail: 'Task ledger change must be committed with its matching staged task transition event.' });
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
const event = readJsonFile(path.join(cwd, stagedEventPath));
|
|
333
|
+
const taskBytes = readFileSync(absolutePath);
|
|
334
|
+
const expectedSha = sha256(taskBytes);
|
|
335
|
+
const releaseOnlyExpectedSha = taskReleaseOnlyTransitionSha(task, event);
|
|
336
|
+
const owningBatch = activeBatches.find((batchRun) => taskIdsInclude(batchRun.taskIds, taskId)) ?? null;
|
|
337
|
+
if (event?.schemaId !== 'atm.taskTransition.v1' || event?.transitionId !== lastTransitionId || typeof event?.taskId !== 'string' || !taskIdsEqual(event.taskId, taskId) || event?.taskPath !== normalized || (event?.taskSha256 !== expectedSha && event?.taskSha256 !== releaseOnlyExpectedSha) || typeof event?.command !== 'string' || !event.command.startsWith('node atm.mjs ')) {
|
|
338
|
+
findings.push({ file: normalized, reason: 'task-file-transition-mismatch', detail: 'Task ledger change does not match a valid staged ATM CLI transition event.' });
|
|
339
|
+
}
|
|
340
|
+
else if (owningBatch?.status === 'active' && typeof event?.command === 'string' && event.command.startsWith('node atm.mjs tasks close') && !event.command.includes('--from-batch-checkpoint') && event?.closure?.schemaId !== 'atm.taskClosureTransition.v1') {
|
|
341
|
+
const requiredCommand = `node atm.mjs batch checkpoint --actor <id> --batch ${owningBatch.batchId} --json`;
|
|
342
|
+
findings.push({ file: normalized, reason: 'batch-close-must-use-checkpoint', detail: `Task ${taskId} belongs to active batch ${owningBatch.batchId};
|
|
343
|
+
direct tasks close is not allowed. Use batch checkpoint so ATM can close, advance, and claim the next queue head.`, requiredCommand });
|
|
344
|
+
}
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (lower.startsWith('.atm/history/evidence/')) {
|
|
348
|
+
const evidence = readJsonFile(absolutePath);
|
|
349
|
+
if (lower.startsWith('.atm/history/evidence/historical-batches/')) {
|
|
350
|
+
const envelopeTasks = Array.isArray(evidence?.tasks) ? evidence.tasks : [];
|
|
351
|
+
const taskIds = envelopeTasks.map((entry) => entry && typeof entry === 'object' && !Array.isArray(entry) ? entry.taskId : null).filter((entry) => typeof entry === 'string' && entry.trim().length > 0);
|
|
352
|
+
const hasBatchTaskContext = taskIds.some((taskId) => {
|
|
353
|
+
const normalizedTaskId = taskId.toLowerCase();
|
|
354
|
+
const hasSiblingTask = stagedSet.has(`.atm/history/tasks/${taskId}.json`);
|
|
355
|
+
const hasSiblingEvent = protectedFiles.some((entry) => {
|
|
356
|
+
const candidate = normalizeRelativePath(entry).toLowerCase();
|
|
357
|
+
return candidate.startsWith(`.atm/history/task-events/${normalizedTaskId}/`);
|
|
358
|
+
});
|
|
359
|
+
return hasSiblingTask || hasSiblingEvent;
|
|
360
|
+
});
|
|
361
|
+
if (taskIds.length === 0 || !hasBatchTaskContext) {
|
|
362
|
+
findings.push({ file: normalized, reason: 'evidence-file-missing-task-context', detail: 'Historical batch evidence updates must travel with at least one staged task ledger change or transition event referenced by the batch envelope.' });
|
|
363
|
+
}
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (pendingBatchCheckpointAllowedFiles.length > 0 && isPathAllowedByScope(normalized, pendingBatchCheckpointAllowedFiles)) {
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (effectiveSingleStagedTaskId && isNestedEvidenceArtifactPath(normalized)) {
|
|
370
|
+
const taskIdLower = effectiveSingleStagedTaskId.toLowerCase();
|
|
371
|
+
const hasSiblingTask = stagedSet.has(`.atm/history/tasks/${effectiveSingleStagedTaskId}.json`);
|
|
372
|
+
const hasSiblingEvent = protectedFiles.some((entry) => {
|
|
373
|
+
const candidate = normalizeRelativePath(entry).toLowerCase();
|
|
374
|
+
return candidate.startsWith(`.atm/history/task-events/${taskIdLower}/`);
|
|
375
|
+
});
|
|
376
|
+
const hasSiblingTaskEvidence = stagedSet.has(`.atm/history/evidence/${effectiveSingleStagedTaskId}.json`);
|
|
377
|
+
if (hasSiblingTask || hasSiblingEvent || hasSiblingTaskEvidence) {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
const taskId = typeof evidence?.taskId === 'string' ? evidence.taskId : path.basename(normalized, '.json');
|
|
382
|
+
const hasSiblingTask = stagedSet.has(`.atm/history/tasks/${taskId}.json`);
|
|
383
|
+
const hasSiblingEvent = protectedFiles.some((entry) => {
|
|
384
|
+
const candidate = normalizeRelativePath(entry).toLowerCase();
|
|
385
|
+
return candidate.startsWith(`.atm/history/task-events/${taskId.toLowerCase()}/`);
|
|
386
|
+
});
|
|
387
|
+
if (!hasSiblingTask && !hasSiblingEvent) {
|
|
388
|
+
findings.push({ file: normalized, reason: 'evidence-file-missing-task-context', detail: 'Evidence updates must travel with the related staged task ledger change or transition event.' });
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (isStaticEvidenceArtifactPath(normalized)) {
|
|
392
|
+
const hasSiblingEvidence = protectedFiles.some((entry) => {
|
|
393
|
+
const candidate = normalizeRelativePath(entry).toLowerCase();
|
|
394
|
+
return candidate.startsWith('.atm/history/evidence/');
|
|
395
|
+
});
|
|
396
|
+
const hasSiblingTaskOrEvent = protectedFiles.some((entry) => {
|
|
397
|
+
const candidate = normalizeRelativePath(entry).toLowerCase();
|
|
398
|
+
return candidate.startsWith('.atm/history/tasks/') || candidate.startsWith('.atm/history/task-events/');
|
|
399
|
+
});
|
|
400
|
+
if (!hasSiblingEvidence || !hasSiblingTaskOrEvent) {
|
|
401
|
+
findings.push({ file: normalized, reason: 'static-evidence-artifact-without-cli-context', detail: `Static evidence artifacts under atomic_workbench/evidence or atomic_workbench/reports cannot stand alone; commit them together with ATM CLI evidence/task transition context.` });
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return { ok: findings.length === 0, files: protectedFiles, findings };
|
|
406
|
+
}
|
|
407
|
+
function isNestedEvidenceArtifactPath(value) {
|
|
408
|
+
const normalized = normalizeRelativePath(value).toLowerCase();
|
|
409
|
+
if (!normalized.startsWith('.atm/history/evidence/'))
|
|
410
|
+
return false;
|
|
411
|
+
const relative = normalized.slice('.atm/history/evidence/'.length);
|
|
412
|
+
return relative.includes('/');
|
|
413
|
+
}
|
|
414
|
+
function hasStagedBatchCheckpointClosure(cwd, protectedFiles, batchTaskIds, batchId = null) {
|
|
415
|
+
const protectedSet = new Set(protectedFiles.map((entry) => normalizeRelativePath(entry).toLowerCase()));
|
|
416
|
+
for (const file of protectedFiles) {
|
|
417
|
+
const normalized = normalizeRelativePath(file);
|
|
418
|
+
const lower = normalized.toLowerCase();
|
|
419
|
+
if (!lower.startsWith('.atm/history/task-events/') || !lower.endsWith('.json')) {
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
const event = readJsonFile(path.join(cwd, normalized));
|
|
423
|
+
const closure = event?.closure;
|
|
424
|
+
if (typeof event?.command === 'string' && event.command.startsWith('node atm.mjs ') && (event.command.includes('--from-batch-checkpoint') || closure?.schemaId === 'atm.taskClosureTransition.v1') && (!batchId || event.command.includes(`--batch ${batchId}`) || closure?.batchId === batchId)) {
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
for (const file of protectedFiles) {
|
|
429
|
+
const normalized = normalizeRelativePath(file);
|
|
430
|
+
const lower = normalized.toLowerCase();
|
|
431
|
+
if (!lower.startsWith('.atm/history/tasks/') || !lower.endsWith('.json')) {
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
const task = readJsonFile(path.join(cwd, normalized));
|
|
435
|
+
const taskId = typeof task?.workItemId === 'string' ? task.workItemId : path.basename(normalized, '.json');
|
|
436
|
+
if ((!batchId && !batchTaskIds.includes(taskId)) || task?.status !== 'done') {
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
const lastTransitionId = typeof task?.lastTransitionId === 'string' ? task.lastTransitionId : '';
|
|
440
|
+
const expectedEventPath = `.atm/history/task-events/${taskId}/${lastTransitionId}.json`;
|
|
441
|
+
if (!lastTransitionId || !protectedSet.has(expectedEventPath.toLowerCase())) {
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
const event = readJsonFile(path.join(cwd, expectedEventPath));
|
|
445
|
+
const closure = event?.closure;
|
|
446
|
+
if (typeof event?.command === 'string' && event.command.startsWith('node atm.mjs ') && (event.command.includes('--from-batch-checkpoint') || closure?.schemaId === 'atm.taskClosureTransition.v1') && (!batchId || event.command.includes(`--batch ${batchId}`) || closure?.batchId === batchId)) {
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
function isProtectedAtmManagedStatePath(value) {
|
|
453
|
+
const normalized = normalizeRelativePath(value).toLowerCase();
|
|
454
|
+
return normalized.startsWith('.atm/history/tasks/') || normalized.startsWith('.atm/history/task-events/') || normalized.startsWith('.atm/history/evidence/') || isProtectedAtmRuntimeStatePath(normalized);
|
|
455
|
+
}
|
|
456
|
+
export function inspectCommitAttribution(cwd, stagedFiles) {
|
|
457
|
+
const actorId = normalizeOptionalText(process.env.ATM_COMMIT_ACTOR_ID);
|
|
458
|
+
const taskId = normalizeOptionalText(process.env.ATM_COMMIT_TASK_ID);
|
|
459
|
+
const claimLeaseId = normalizeOptionalText(process.env.ATM_COMMIT_CLAIM_LEASE_ID);
|
|
460
|
+
const sessionId = normalizeOptionalText(process.env.ATM_COMMIT_SESSION_ID);
|
|
461
|
+
const stagedSet = new Set(stagedFiles.map((entry) => normalizeRelativePath(entry).toLowerCase()));
|
|
462
|
+
const stagedTaskIds = inferTaskIdsFromStagedFiles(stagedFiles);
|
|
463
|
+
const knownStagedTaskIds = stagedTaskIds.filter((candidate) => taskLedgerEntryExistsOrIsStaged(cwd, candidate, stagedSet));
|
|
464
|
+
const pendingBatchCheckpointTaskId = resolvePendingBatchCheckpointTaskId(cwd, stagedFiles);
|
|
465
|
+
const findings = [];
|
|
466
|
+
const suggestedTaskId = pendingBatchCheckpointTaskId ?? (knownStagedTaskIds.length === 1 ? knownStagedTaskIds[0] : knownStagedTaskIds[0] ?? null);
|
|
467
|
+
const actorRegistryState = inspectTrackedActorRegistryState(cwd);
|
|
468
|
+
if (actorRegistryState.blocking) {
|
|
469
|
+
const governedRecoveryCommand = suggestedTaskId ? `git add ${quoteCliValue(actorRegistryState.path)} && node atm.mjs git commit --actor <id> --task ${suggestedTaskId} --message "<summary>" --json` : `node atm.mjs git commit --actor <id> --message "<summary>" --json`;
|
|
470
|
+
findings.push({ code: 'ATM_COMMIT_ACTOR_REGISTRY_UNSTAGED', source: 'commit-attribution', detail: `Tracked actor registry ${actorRegistryState.path} has ${actorRegistryState.status === 'mixed' ? 'both staged and unstaged' : 'unstaged'} changes. Governed node atm.mjs git commit can auto-stage that tracked registry when it belongs to the governed commit surface, but bare git commit cannot. Re-run through the ATM wrapper or restore the drift first.`, requiredCommand: governedRecoveryCommand, classification: 'current-task' });
|
|
471
|
+
return { ok: false, findings };
|
|
472
|
+
}
|
|
473
|
+
if (!actorId && !taskId && !sessionId) {
|
|
474
|
+
if (stagedTaskIds.length > 0) {
|
|
475
|
+
const wrapperRequired = { code: 'ATM_GIT_COMMIT_WRAPPER_REQUIRED', source: 'commit-attribution', detail: 'Staged ATM task/evidence changes must commit through node atm.mjs git commit so ATM can bind author, session, claim, and trailers consistently. Direct git commit remains valid for read-only git and non-governed maintenance.', requiredCommand: suggestedTaskId ? `node atm.mjs git commit --actor <id> --task ${suggestedTaskId} --message "<summary>" --json` : 'node atm.mjs git commit --actor <id> --task <task> --message "<summary>" --json', classification: 'current-task' };
|
|
476
|
+
return { ok: false, findings: [wrapperRequired] };
|
|
477
|
+
}
|
|
478
|
+
return { ok: true, findings };
|
|
479
|
+
}
|
|
480
|
+
const effectiveTaskId = taskId ?? pendingBatchCheckpointTaskId ?? (knownStagedTaskIds.length === 1 ? knownStagedTaskIds[0] : null);
|
|
481
|
+
if (!actorId || (stagedTaskIds.length > 0 && !effectiveTaskId)) {
|
|
482
|
+
findings.push({ code: 'ATM_GIT_COMMIT_WRAPPER_REQUIRED', source: 'commit-attribution', detail: 'Governed task commits must use node atm.mjs git commit --actor <id> --task <task> --message "<summary>" so ATM can bind author, session, claim, and trailers consistently. Bare git commit is not banned for inspection or non-governed files.', requiredCommand: 'node atm.mjs git commit --actor <id> --task <task> --message "<summary>" --json', classification: 'current-task' });
|
|
483
|
+
return { ok: false, findings };
|
|
484
|
+
}
|
|
485
|
+
if (!effectiveTaskId) {
|
|
486
|
+
const expectedIdentity = resolveExpectedGitIdentityForActor(cwd, actorId);
|
|
487
|
+
findings.push(...collectIdentityProvenanceFindings(actorId, expectedIdentity));
|
|
488
|
+
const authorName = normalizeOptionalText(process.env.GIT_AUTHOR_NAME) ?? runGitScalar(cwd, ['config', '--local', '--get', 'user.name']);
|
|
489
|
+
const authorEmail = normalizeOptionalText(process.env.GIT_AUTHOR_EMAIL) ?? runGitScalar(cwd, ['config', '--local', '--get', 'user.email']);
|
|
490
|
+
if (!expectedIdentity.gitName || !expectedIdentity.gitEmail) {
|
|
491
|
+
findings.push({ code: 'ATM_COMMIT_IDENTITY_PROFILE_MISSING', source: 'commit-attribution', detail: `Actor ${actorId} has no resolved git identity profile in actor registry or .atm/runtime/identity/default.json.`, requiredCommand: buildIdentitySetRequiredCommand(cwd, actorId), classification: 'current-task' });
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
if (authorName !== expectedIdentity.gitName) {
|
|
495
|
+
findings.push({ code: 'ATM_COMMIT_AUTHOR_NAME_MISMATCH', source: 'commit-attribution', detail: `Commit author name is ${authorName ?? 'unset'}, expected ${expectedIdentity.gitName}.`, classification: 'current-task' });
|
|
496
|
+
}
|
|
497
|
+
if (authorEmail !== expectedIdentity.gitEmail) {
|
|
498
|
+
findings.push({ code: 'ATM_COMMIT_AUTHOR_EMAIL_MISMATCH', source: 'commit-attribution', detail: `Commit author email is ${authorEmail ?? 'unset'}, expected ${expectedIdentity.gitEmail}.`, classification: 'current-task' });
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return { ok: findings.length === 0, findings };
|
|
502
|
+
}
|
|
503
|
+
const task = readJsonFile(path.join(cwd, '.atm', 'history', 'tasks', `${effectiveTaskId}.json`));
|
|
504
|
+
const claim = parseHookTaskClaim(task?.claim);
|
|
505
|
+
const mirrorSyncOnly = inspectMirrorSyncOnlyStagedArtifacts(cwd, effectiveTaskId, stagedFiles);
|
|
506
|
+
const historicalLedgerRestore = inspectHistoricalLedgerRestoreStagedArtifacts(cwd, effectiveTaskId, stagedFiles);
|
|
507
|
+
const closeCommitWindow = inspectCloseCommitWindowStagedArtifacts(cwd, effectiveTaskId, stagedFiles);
|
|
508
|
+
const pendingBatchCheckpoint = inspectPendingBatchCheckpointStagedArtifacts(cwd, effectiveTaskId, stagedFiles);
|
|
509
|
+
const bypassesActiveSession = mirrorSyncOnly.ok || historicalLedgerRestore.ok || closeCommitWindow.ok || pendingBatchCheckpoint.ok;
|
|
510
|
+
const claimForSession = bypassesActiveSession ? null : claim;
|
|
511
|
+
const session = bypassesActiveSession && !sessionId ? null : resolveActorWorkSession(cwd, { sessionId, actorId, taskId: effectiveTaskId, claimLeaseId: claimLeaseId ?? claimForSession?.leaseId ?? null, includeNonActive: true });
|
|
512
|
+
const frameworkTempClaimAttribution = hasLiveFrameworkTempClaimAttribution({ cwd, actorId, taskId: effectiveTaskId });
|
|
513
|
+
if (!session && !bypassesActiveSession && !frameworkTempClaimAttribution) {
|
|
514
|
+
findings.push({ code: 'ATM_COMMIT_SESSION_MISSING', source: 'commit-attribution', detail: `No ATM work session matched actor ${actorId} and task ${effectiveTaskId}. Claim the task through ATM before committing.`, requiredCommand: `node atm.mjs next --claim --actor ${actorId} --prompt "${effectiveTaskId}" --json`, classification: 'current-task' });
|
|
515
|
+
return { ok: false, findings };
|
|
516
|
+
}
|
|
517
|
+
if (session && session.actorId !== actorId) {
|
|
518
|
+
findings.push({ code: 'ATM_COMMIT_SESSION_ACTOR_MISMATCH', source: 'commit-attribution', detail: `Session ${session.sessionId} belongs to ${session.actorId}, not ${actorId}.`, classification: 'current-task' });
|
|
519
|
+
}
|
|
520
|
+
if (session && session.taskId !== effectiveTaskId) {
|
|
521
|
+
findings.push({ code: 'ATM_COMMIT_SESSION_TASK_MISMATCH', source: 'commit-attribution', detail: `Session ${session.sessionId} is for ${session.taskId}, not ${effectiveTaskId}.`, classification: 'current-task' });
|
|
522
|
+
}
|
|
523
|
+
if (session && (claimLeaseId ?? claimForSession?.leaseId ?? null) && session.claimLeaseId !== (claimLeaseId ?? claimForSession?.leaseId ?? null)) {
|
|
524
|
+
findings.push({ code: 'ATM_COMMIT_SESSION_CLAIM_MISMATCH', source: 'commit-attribution', detail: `Session ${session.sessionId} is bound to claim ${session.claimLeaseId ?? 'unset'}, not ${(claimLeaseId ?? claimForSession?.leaseId) ?? 'unset'}.`, classification: 'current-task' });
|
|
525
|
+
}
|
|
526
|
+
const expectedIdentity = resolveExpectedGitIdentityForActor(cwd, actorId);
|
|
527
|
+
findings.push(...collectIdentityProvenanceFindings(actorId, expectedIdentity));
|
|
528
|
+
const authorName = normalizeOptionalText(process.env.GIT_AUTHOR_NAME) ?? runGitScalar(cwd, ['config', '--local', '--get', 'user.name']);
|
|
529
|
+
const authorEmail = normalizeOptionalText(process.env.GIT_AUTHOR_EMAIL) ?? runGitScalar(cwd, ['config', '--local', '--get', 'user.email']);
|
|
530
|
+
if (!expectedIdentity.gitName || !expectedIdentity.gitEmail) {
|
|
531
|
+
findings.push({ code: 'ATM_COMMIT_IDENTITY_PROFILE_MISSING', source: 'commit-attribution', detail: `Actor ${actorId} has no resolved git identity profile in actor registry or .atm/runtime/identity/default.json.`, requiredCommand: buildIdentitySetRequiredCommand(cwd, actorId), classification: 'current-task' });
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
if (authorName !== expectedIdentity.gitName) {
|
|
535
|
+
findings.push({ code: 'ATM_COMMIT_AUTHOR_NAME_MISMATCH', source: 'commit-attribution', detail: `Commit author name is ${authorName ?? 'unset'}, expected ${expectedIdentity.gitName}.`, classification: 'current-task' });
|
|
536
|
+
}
|
|
537
|
+
if (authorEmail !== expectedIdentity.gitEmail) {
|
|
538
|
+
findings.push({ code: 'ATM_COMMIT_AUTHOR_EMAIL_MISMATCH', source: 'commit-attribution', detail: `Commit author email is ${authorEmail ?? 'unset'}, expected ${expectedIdentity.gitEmail}.`, classification: 'current-task' });
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return { ok: findings.length === 0, findings };
|
|
542
|
+
}
|
|
543
|
+
function taskLedgerEntryExistsOrIsStaged(cwd, taskId, stagedSet) {
|
|
544
|
+
const normalizedTaskId = normalizeRelativePath(taskId);
|
|
545
|
+
if (!normalizedTaskId)
|
|
546
|
+
return false;
|
|
547
|
+
const taskPath = `.atm/history/tasks/${normalizedTaskId}.json`;
|
|
548
|
+
return stagedSet.has(taskPath.toLowerCase()) || existsSync(path.join(cwd, taskPath));
|
|
549
|
+
}
|
|
550
|
+
export function inspectCloseCommitWindowStagedArtifacts(cwd, taskId, stagedFiles) {
|
|
551
|
+
if (stagedFiles.length === 0) {
|
|
552
|
+
return { ok: false, reason: 'no-staged-files' };
|
|
553
|
+
}
|
|
554
|
+
const activeTaskWindow = readActiveCloseCommitWindows(cwd).find((entry) => entry.taskId === taskId) ?? null;
|
|
555
|
+
if (activeTaskWindow && stagedFiles.every((filePath) => isAllowedCloseCommitGovernanceArtifactPath(filePath, taskId))) {
|
|
556
|
+
return { ok: true, reason: 'active-close-commit-window-governance-bundle' };
|
|
557
|
+
}
|
|
558
|
+
const windowRecord = findCloseCommitWindowCoveringPaths(cwd, stagedFiles);
|
|
559
|
+
if (!windowRecord) {
|
|
560
|
+
return { ok: false, reason: 'no-covering-window' };
|
|
561
|
+
}
|
|
562
|
+
if (windowRecord.taskId !== taskId) {
|
|
563
|
+
return { ok: false, reason: `window-task-mismatch:${windowRecord.taskId}` };
|
|
564
|
+
}
|
|
565
|
+
return { ok: true, reason: null };
|
|
566
|
+
}
|
|
567
|
+
function isAllowedCloseCommitGovernanceArtifactPath(filePath, taskId) {
|
|
568
|
+
const normalized = normalizeRelativePath(filePath);
|
|
569
|
+
const normalizedTaskId = taskId.toLowerCase();
|
|
570
|
+
const lower = normalized.toLowerCase();
|
|
571
|
+
return lower === `.atm/history/tasks/${normalizedTaskId}.json` || lower === `.atm/history/evidence/${normalizedTaskId}.json` || lower === `.atm/history/evidence/${normalizedTaskId}.bundle-manifest.json` || lower === `.atm/history/evidence/${normalizedTaskId}.closure-packet.json` || (lower.startsWith(`.atm/history/task-events/${normalizedTaskId}/`) && lower.endsWith('.json'));
|
|
572
|
+
}
|
|
573
|
+
function isStaticEvidenceArtifactPath(value) {
|
|
574
|
+
const normalized = normalizeRelativePath(value).toLowerCase();
|
|
575
|
+
if (normalized.startsWith('atomic_workbench/evidence/') && normalized.endsWith('.json')) {
|
|
576
|
+
return true;
|
|
577
|
+
}
|
|
578
|
+
if (normalized.startsWith('atomic_workbench/reports/') && normalized.endsWith('.json')) {
|
|
579
|
+
return true;
|
|
580
|
+
}
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
function isProtectedAtmRuntimeStatePath(value) {
|
|
584
|
+
const normalized = normalizeRelativePath(value).toLowerCase();
|
|
585
|
+
return normalized.startsWith('.atm/runtime/locks/') || normalized.startsWith('.atm/runtime/task-direction-locks/') || normalized.startsWith('.atm/runtime/task-queues/') || normalized.startsWith('.atm/runtime/batch-runs/') || normalized.startsWith('.atm/runtime/sessions/') || normalized.startsWith('.atm/runtime/identity/') || normalized === '.atm/runtime/current-task.json' || normalized === '.atm/runtime/guidance/active-session.json';
|
|
586
|
+
}
|
|
587
|
+
function readJsonFile(filePath) {
|
|
588
|
+
if (!existsSync(filePath))
|
|
589
|
+
return null;
|
|
590
|
+
try {
|
|
591
|
+
return JSON.parse(readFileSync(filePath, 'utf8'));
|
|
592
|
+
}
|
|
593
|
+
catch {
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
export function inspectEmergencyUseAudit(cwd, stagedFiles) {
|
|
598
|
+
const useFiles = stagedFiles.map(normalizeRelativePath).filter((entry) => /^\.atm\/runtime\/emergency\/uses\/[^/]+\.json$/i.test(entry));
|
|
599
|
+
const findings = [];
|
|
600
|
+
for (const useFile of useFiles) {
|
|
601
|
+
const use = readJsonFile(path.resolve(cwd, useFile));
|
|
602
|
+
const leaseId = typeof use?.leaseId === 'string' ? use.leaseId.trim() : '';
|
|
603
|
+
const leasePath = leaseId ? `.atm/runtime/emergency/leases/${leaseId}.json` : undefined;
|
|
604
|
+
const lease = leasePath ? readJsonFile(path.resolve(cwd, leasePath)) : null;
|
|
605
|
+
if (!leaseId || !lease) {
|
|
606
|
+
findings.push({ code: 'ATM_EMERGENCY_USE_LEASE_MISSING', file: useFile, leasePath, detail: `Emergency use record ${useFile} must have a matching staged or tracked lease record.` });
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
const usedCount = typeof lease.usedCount === 'number' ? lease.usedCount : Number(lease.usedCount ?? 0);
|
|
610
|
+
if (!Number.isFinite(usedCount) || usedCount < 1) {
|
|
611
|
+
findings.push({ code: 'ATM_EMERGENCY_USE_LEASE_NOT_USED', file: useFile, leasePath, detail: `Emergency lease ${leaseId} must be marked used before committing use record ${useFile}.` });
|
|
612
|
+
}
|
|
613
|
+
if (String(lease.permission ?? '') !== String(use?.permission ?? '')) {
|
|
614
|
+
findings.push({ code: 'ATM_EMERGENCY_USE_PERMISSION_MISMATCH', file: useFile, leasePath, detail: `Emergency use permission ${String(use?.permission ?? '<missing>')} does not match lease ${String(lease.permission ?? '<missing>')}.` });
|
|
615
|
+
}
|
|
616
|
+
const leaseTaskId = lease.taskId == null ? null : String(lease.taskId);
|
|
617
|
+
const useTaskId = use?.taskId == null ? null : String(use.taskId);
|
|
618
|
+
if (leaseTaskId && useTaskId && leaseTaskId !== useTaskId) {
|
|
619
|
+
findings.push({ code: 'ATM_EMERGENCY_USE_TASK_MISMATCH', file: useFile, leasePath, detail: `Emergency use task ${useTaskId} does not match lease task ${leaseTaskId}.` });
|
|
620
|
+
}
|
|
621
|
+
const leaseActorId = typeof lease.actorId === 'string' ? lease.actorId : null;
|
|
622
|
+
const useActorId = use?.actorId == null ? null : String(use.actorId);
|
|
623
|
+
if (leaseActorId && useActorId && leaseActorId !== useActorId) {
|
|
624
|
+
findings.push({ code: 'ATM_EMERGENCY_USE_ACTOR_MISMATCH', file: useFile, leasePath, detail: `Emergency use actor ${useActorId} does not match lease actor ${leaseActorId}.` });
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
return { ok: findings.length === 0, inspectedUseFiles: useFiles, findings };
|
|
628
|
+
}
|
|
629
|
+
export function inferTaskIdsFromStagedFiles(stagedFiles) {
|
|
630
|
+
const taskIds = new Set();
|
|
631
|
+
for (const file of stagedFiles) {
|
|
632
|
+
const normalized = normalizeRelativePath(file);
|
|
633
|
+
const taskMatch = normalized.match(/^\.atm\/history\/tasks\/([^/]+)\.json$/i);
|
|
634
|
+
if (taskMatch) {
|
|
635
|
+
taskIds.add(taskMatch[1]);
|
|
636
|
+
continue;
|
|
637
|
+
}
|
|
638
|
+
const closurePacketMatch = normalized.match(/^\.atm\/history\/evidence\/([^/]+)\.closure-packet\.json$/i);
|
|
639
|
+
if (closurePacketMatch) {
|
|
640
|
+
taskIds.add(closurePacketMatch[1]);
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
const bundleManifestMatch = normalized.match(/^\.atm\/history\/evidence\/([^/]+)\.bundle-manifest\.json$/i);
|
|
644
|
+
if (bundleManifestMatch) {
|
|
645
|
+
taskIds.add(bundleManifestMatch[1]);
|
|
646
|
+
continue;
|
|
647
|
+
}
|
|
648
|
+
const eventMatch = normalized.match(/^\.atm\/history\/task-events\/([^/]+)\//i);
|
|
649
|
+
if (eventMatch) {
|
|
650
|
+
taskIds.add(eventMatch[1]);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return [...taskIds].sort((left, right) => left.localeCompare(right));
|
|
654
|
+
}
|
|
655
|
+
export function resolvePendingBatchCheckpointTaskId(cwd, stagedFiles) {
|
|
656
|
+
const activeBatches = listActiveBatchRuns(cwd);
|
|
657
|
+
const window = activeBatches.map((batchRun) => buildPendingCheckpointCommitWindow(cwd, batchRun, null)).find((candidate) => candidate && stagedFiles.every((file) => isPathAllowedByScope(file, uniqueSorted([...candidate.commitFiles, ...candidate.changedFiles])))) ?? null;
|
|
658
|
+
return window?.taskId ?? null;
|
|
659
|
+
}
|
|
660
|
+
export function inspectPendingBatchCheckpointStagedArtifacts(cwd, taskId, stagedFiles) {
|
|
661
|
+
const pendingTaskId = resolvePendingBatchCheckpointTaskId(cwd, stagedFiles);
|
|
662
|
+
if (!pendingTaskId) {
|
|
663
|
+
return { ok: false, reason: 'no-pending-batch-checkpoint-window' };
|
|
664
|
+
}
|
|
665
|
+
if (!taskIdsEqual(pendingTaskId, taskId)) {
|
|
666
|
+
return { ok: false, reason: `window-task-mismatch:${pendingTaskId}` };
|
|
667
|
+
}
|
|
668
|
+
return { ok: true, reason: 'pending-batch-checkpoint-window' };
|
|
669
|
+
}
|
|
670
|
+
export function resolveResidueTaskId(cwd) {
|
|
671
|
+
const committingTaskId = typeof process.env.ATM_COMMIT_TASK_ID === 'string' ? process.env.ATM_COMMIT_TASK_ID.trim() : '';
|
|
672
|
+
if (committingTaskId) {
|
|
673
|
+
return committingTaskId;
|
|
674
|
+
}
|
|
675
|
+
const stagedTaskIds = inferTaskIdsFromStagedFiles(readStagedFiles(cwd));
|
|
676
|
+
if (stagedTaskIds.length === 1) {
|
|
677
|
+
return stagedTaskIds[0];
|
|
678
|
+
}
|
|
679
|
+
const activeLocks = readActiveTaskDirectionLocks(cwd);
|
|
680
|
+
if (activeLocks.length === 1) {
|
|
681
|
+
return activeLocks[0].taskId;
|
|
682
|
+
}
|
|
683
|
+
return null;
|
|
684
|
+
}
|
|
685
|
+
export function isUnconsumedCloseWindowDeferralSnapshot(cwd, relativePath) {
|
|
686
|
+
if (!/close-window-governance-dirty-/.test(relativePath))
|
|
687
|
+
return false;
|
|
688
|
+
try {
|
|
689
|
+
const snapshot = JSON.parse(readFileSync(path.join(cwd, relativePath), 'utf8'));
|
|
690
|
+
return snapshot.schemaId === 'atm.closeWindowGovernanceDirtySnapshot.v1' && snapshot.restoredAt === null;
|
|
691
|
+
}
|
|
692
|
+
catch {
|
|
693
|
+
return true;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
export function cleanupAutoGeneratedResidue(cwd, findings) {
|
|
697
|
+
const cleaned = [];
|
|
698
|
+
for (const finding of findings) {
|
|
699
|
+
if (finding.cleanupAction === 'remove' && isUnconsumedCloseWindowDeferralSnapshot(cwd, finding.path)) {
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
if (finding.cleanupAction === 'restore') {
|
|
703
|
+
try {
|
|
704
|
+
runGit(cwd, ['restore', '--staged', '--worktree', '--source=HEAD', '--', finding.path]);
|
|
705
|
+
}
|
|
706
|
+
catch {
|
|
707
|
+
try {
|
|
708
|
+
runGit(cwd, ['rm', '--cached', '--quiet', '--ignore-unmatch', '--', finding.path]);
|
|
709
|
+
}
|
|
710
|
+
catch { }
|
|
711
|
+
try {
|
|
712
|
+
rmSync(path.join(cwd, finding.path), { force: true });
|
|
713
|
+
}
|
|
714
|
+
catch { }
|
|
715
|
+
}
|
|
716
|
+
cleaned.push(finding);
|
|
717
|
+
continue;
|
|
718
|
+
}
|
|
719
|
+
if (finding.cleanupAction === 'remove') {
|
|
720
|
+
try {
|
|
721
|
+
const absolutePath = path.join(cwd, finding.path);
|
|
722
|
+
const stats = statSync(absolutePath);
|
|
723
|
+
if (stats.isDirectory()) {
|
|
724
|
+
rmSync(absolutePath, { recursive: true, force: true });
|
|
725
|
+
}
|
|
726
|
+
else {
|
|
727
|
+
rmSync(absolutePath, { force: true });
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
catch { }
|
|
731
|
+
cleaned.push(finding);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return cleaned;
|
|
735
|
+
}
|
|
736
|
+
export function isActionableManualResidue(filePath) {
|
|
737
|
+
const lower = normalizeRelativePath(filePath).toLowerCase();
|
|
738
|
+
return lower.startsWith('.atm/runtime/snapshots/') || /^\.atm\/history\/reports\/.+\.json$/.test(lower) || /^\.atm\/history\/protected-override-audit\/.+\.json$/.test(lower) || /^\.atm\/history\/evidence\/[^/]+\.bundle-manifest\.json$/.test(lower) || /^\.atm\/history\/evidence\/[^/]+\.closure-packet\.json$/.test(lower) || /^\.atm\/history\/task-events\/[^/]+\/.+(?:close|reconcile|repair-closure).+\.json$/.test(lower);
|
|
739
|
+
}
|
|
740
|
+
export function inspectMirrorSyncOnlyStagedArtifacts(cwd, taskId, stagedFiles) {
|
|
741
|
+
if (stagedFiles.length === 0) {
|
|
742
|
+
return { ok: false, reason: 'no-staged-files' };
|
|
743
|
+
}
|
|
744
|
+
const expectedTaskPath = `.atm/history/tasks/${taskId}.json`.toLowerCase();
|
|
745
|
+
let hasTaskLedger = false;
|
|
746
|
+
let hasImportEvent = false;
|
|
747
|
+
for (const file of stagedFiles) {
|
|
748
|
+
const normalized = normalizeRelativePath(file);
|
|
749
|
+
const lower = normalized.toLowerCase();
|
|
750
|
+
if (lower === expectedTaskPath) {
|
|
751
|
+
hasTaskLedger = true;
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
if (lower.startsWith(`.atm/history/task-events/${taskId.toLowerCase()}/`) && lower.includes('import') && lower.endsWith('.json')) {
|
|
755
|
+
hasImportEvent = true;
|
|
756
|
+
continue;
|
|
757
|
+
}
|
|
758
|
+
if (lower.startsWith('.atm/history/reports/task-import/') && lower.endsWith('.json') && taskImportReportReferencesTask(cwd, normalized, taskId)) {
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
return { ok: false, reason: `unexpected-staged-file:${normalized}` };
|
|
762
|
+
}
|
|
763
|
+
return { ok: hasTaskLedger && hasImportEvent, reason: hasTaskLedger && hasImportEvent ? null : 'incomplete-mirror-sync-artifacts' };
|
|
764
|
+
}
|
|
765
|
+
export function inspectTaskOpenImportBundleStagedArtifacts(cwd, stagedFiles) {
|
|
766
|
+
const taskIds = inferTaskIdsFromStagedFiles(stagedFiles);
|
|
767
|
+
if (taskIds.length !== 1) {
|
|
768
|
+
return { ok: false, taskId: null, reason: taskIds.length === 0 ? 'no-task-id' : 'multiple-task-ids' };
|
|
769
|
+
}
|
|
770
|
+
const taskId = taskIds[0];
|
|
771
|
+
const report = inspectMirrorSyncOnlyStagedArtifacts(cwd, taskId, stagedFiles);
|
|
772
|
+
return { ok: report.ok, taskId, reason: report.reason };
|
|
773
|
+
}
|
|
774
|
+
export function inspectHistoricalLedgerRestoreStagedArtifacts(cwd, taskId, stagedFiles) {
|
|
775
|
+
if (stagedFiles.length === 0) {
|
|
776
|
+
return { ok: false, reason: 'no-staged-files' };
|
|
777
|
+
}
|
|
778
|
+
const normalizedTaskId = taskId.toLowerCase();
|
|
779
|
+
const expectedTaskPath = `.atm/history/tasks/${taskId}.json`.toLowerCase();
|
|
780
|
+
const expectedEvidencePath = `.atm/history/evidence/${taskId}.json`.toLowerCase();
|
|
781
|
+
const expectedClosurePacketPath = `.atm/history/evidence/${taskId}.closure-packet.json`.toLowerCase();
|
|
782
|
+
const expectedGitHeadEvidencePath = '.atm/history/evidence/git-head.jsonl';
|
|
783
|
+
let hasTaskLedger = false;
|
|
784
|
+
let hasEvidenceBundle = false;
|
|
785
|
+
let hasClosurePacket = false;
|
|
786
|
+
let hasTaskEvent = false;
|
|
787
|
+
let hasGitHeadEvidence = false;
|
|
788
|
+
for (const file of stagedFiles) {
|
|
789
|
+
const normalized = normalizeRelativePath(file);
|
|
790
|
+
const lower = normalized.toLowerCase();
|
|
791
|
+
if (lower === expectedTaskPath) {
|
|
792
|
+
hasTaskLedger = true;
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
if (lower === expectedEvidencePath) {
|
|
796
|
+
hasEvidenceBundle = true;
|
|
797
|
+
continue;
|
|
798
|
+
}
|
|
799
|
+
if (lower === expectedClosurePacketPath) {
|
|
800
|
+
hasClosurePacket = true;
|
|
801
|
+
continue;
|
|
802
|
+
}
|
|
803
|
+
if (lower === expectedGitHeadEvidencePath) {
|
|
804
|
+
hasGitHeadEvidence = true;
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
807
|
+
if (lower.startsWith(`.atm/history/task-events/${normalizedTaskId}/`) && lower.endsWith('.json')) {
|
|
808
|
+
hasTaskEvent = true;
|
|
809
|
+
continue;
|
|
810
|
+
}
|
|
811
|
+
return { ok: false, reason: `unexpected-staged-file:${normalized}` };
|
|
812
|
+
}
|
|
813
|
+
if (!hasTaskLedger)
|
|
814
|
+
return { ok: false, reason: 'missing-task-ledger' };
|
|
815
|
+
if (!hasClosurePacket)
|
|
816
|
+
return { ok: false, reason: 'missing-closure-packet' };
|
|
817
|
+
if (!hasTaskEvent)
|
|
818
|
+
return { ok: false, reason: 'missing-task-event' };
|
|
819
|
+
const taskDocument = readStagedJsonFile(cwd, `.atm/history/tasks/${taskId}.json`);
|
|
820
|
+
if (!taskDocument || taskDocument.status !== 'done')
|
|
821
|
+
return { ok: false, reason: 'task-not-done' };
|
|
822
|
+
if (typeof taskDocument.workItemId === 'string' && taskDocument.workItemId !== taskId) {
|
|
823
|
+
return { ok: false, reason: 'task-id-mismatch' };
|
|
824
|
+
}
|
|
825
|
+
const closurePacket = readStagedJsonFile(cwd, `.atm/history/evidence/${taskId}.closure-packet.json`);
|
|
826
|
+
if (!closurePacket || closurePacket.taskId !== taskId) {
|
|
827
|
+
return { ok: false, reason: 'closure-packet-task-id-mismatch' };
|
|
828
|
+
}
|
|
829
|
+
const evidence = readStagedJsonFile(cwd, `.atm/history/evidence/${taskId}.json`);
|
|
830
|
+
for (const eventPath of stagedFiles.filter((file) => normalizeRelativePath(file).toLowerCase().startsWith(`.atm/history/task-events/${normalizedTaskId}/`))) {
|
|
831
|
+
const event = readStagedJsonFile(cwd, eventPath);
|
|
832
|
+
const command = typeof event?.command === 'string' ? event.command.trim() : '';
|
|
833
|
+
if (!event || event.schemaId !== 'atm.taskTransition.v1' || event.taskId !== taskId || typeof event.transitionId !== 'string' || !command.startsWith('node atm.mjs ')) {
|
|
834
|
+
return { ok: false, reason: `task-event-invalid:${normalizeRelativePath(eventPath)}` };
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
if (!hasEvidenceBundle) {
|
|
838
|
+
if (!hasGitHeadEvidence) {
|
|
839
|
+
return { ok: false, reason: 'missing-evidence-bundle' };
|
|
840
|
+
}
|
|
841
|
+
const repairEventPaths = stagedFiles.filter((file) => normalizeRelativePath(file).toLowerCase().startsWith(`.atm/history/task-events/${normalizedTaskId}/`));
|
|
842
|
+
const repairOnly = repairEventPaths.length > 0 && repairEventPaths.every((eventPath) => {
|
|
843
|
+
const event = readStagedJsonFile(cwd, eventPath);
|
|
844
|
+
return event?.action === 'repair-closure';
|
|
845
|
+
});
|
|
846
|
+
if (!repairOnly) {
|
|
847
|
+
return { ok: false, reason: 'missing-evidence-bundle' };
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
else if (!evidence || evidence.taskId !== taskId) {
|
|
851
|
+
return { ok: false, reason: 'evidence-task-id-mismatch' };
|
|
852
|
+
}
|
|
853
|
+
return { ok: true, reason: null };
|
|
854
|
+
}
|
|
855
|
+
function readStagedJsonFile(cwd, relativeFile) {
|
|
856
|
+
const result = runGit(cwd, ['show', `:${normalizeRelativePath(relativeFile)}`]);
|
|
857
|
+
if (result.exitCode !== 0)
|
|
858
|
+
return null;
|
|
859
|
+
return readJsonText(result.stdout);
|
|
860
|
+
}
|
|
861
|
+
function taskImportReportReferencesTask(cwd, file, taskId) {
|
|
862
|
+
try {
|
|
863
|
+
const content = readFileSync(path.join(cwd, file), 'utf8');
|
|
864
|
+
const parsed = JSON.parse(content);
|
|
865
|
+
return JSON.stringify(parsed).includes(`"${taskId}"`);
|
|
866
|
+
}
|
|
867
|
+
catch {
|
|
868
|
+
return false;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
export function parseHookTaskClaim(value) {
|
|
872
|
+
if (!isPlainObject(value))
|
|
873
|
+
return null;
|
|
874
|
+
const actorId = normalizeOptionalText(value.actorId);
|
|
875
|
+
const leaseId = normalizeOptionalText(value.leaseId);
|
|
876
|
+
return actorId && leaseId ? { actorId, leaseId } : null;
|
|
877
|
+
}
|
|
878
|
+
export function resolveExpectedGitIdentityForActor(cwd, actorId) {
|
|
879
|
+
const actorRecord = findActorByResolvedId(cwd, { actorId, source: 'option' });
|
|
880
|
+
const actorIdentity = readRuntimeIdentityForActor(cwd, actorId);
|
|
881
|
+
const defaultIdentity = readRuntimeIdentityDefault(cwd);
|
|
882
|
+
const defaultMatches = defaultIdentity?.actorId === actorId;
|
|
883
|
+
const source = actorRecord?.gitName || actorRecord?.gitEmail ? 'actor-registry' : actorIdentity?.gitName || actorIdentity?.gitEmail ? 'actor-runtime' : defaultMatches && (defaultIdentity?.gitName || defaultIdentity?.gitEmail) ? 'matching-default' : 'missing';
|
|
884
|
+
return { gitName: actorRecord?.gitName ?? actorIdentity?.gitName ?? (defaultMatches ? defaultIdentity?.gitName ?? null : null), gitEmail: actorRecord?.gitEmail ?? actorIdentity?.gitEmail ?? (defaultMatches ? defaultIdentity?.gitEmail ?? null : null), editor: actorRecord?.editor ?? actorIdentity?.editor ?? (defaultMatches ? defaultIdentity?.editor ?? null : null), provider: actorRecord?.provider ?? actorIdentity?.provider ?? (defaultMatches ? defaultIdentity?.provider ?? null : null), source };
|
|
885
|
+
}
|
|
886
|
+
export function collectIdentityProvenanceFindings(actorId, expectedIdentity) {
|
|
887
|
+
const findings = [];
|
|
888
|
+
const currentEditor = normalizeOptionalText(process.env.ATM_EDITOR_ID) ?? (normalizeOptionalText(process.env.CODEX_HOME) ? 'codex' : null);
|
|
889
|
+
const currentProvider = normalizeOptionalText(process.env.ATM_PROVIDER_ID);
|
|
890
|
+
if (expectedIdentity.editor && currentEditor && expectedIdentity.editor !== currentEditor) {
|
|
891
|
+
findings.push({ code: 'ATM_COMMIT_IDENTITY_EDITOR_MISMATCH', source: 'commit-attribution', detail: `Actor ${actorId} identity is bound to editor ${expectedIdentity.editor}, but the current environment reports ${currentEditor}.`, requiredCommand: `node atm.mjs identity set --actor ${quoteCliValue(actorId)} --editor ${quoteCliValue(currentEditor)} --git-name "<git user.name>" --git-email "<git user.email>" --json`, classification: 'current-task' });
|
|
892
|
+
}
|
|
893
|
+
if (expectedIdentity.provider && currentProvider && expectedIdentity.provider !== currentProvider) {
|
|
894
|
+
findings.push({ code: 'ATM_COMMIT_IDENTITY_PROVIDER_MISMATCH', source: 'commit-attribution', detail: `Actor ${actorId} identity is bound to provider ${expectedIdentity.provider}, but the current environment reports ${currentProvider}.`, requiredCommand: `node atm.mjs identity set --actor ${quoteCliValue(actorId)} --provider ${quoteCliValue(currentProvider)} --git-name "<git user.name>" --git-email "<git user.email>" --json`, classification: 'current-task' });
|
|
895
|
+
}
|
|
896
|
+
return findings;
|
|
897
|
+
}
|
|
898
|
+
export function buildIdentitySetRequiredCommand(cwd, actorId) {
|
|
899
|
+
const gitName = runGitScalar(cwd, ['config', '--local', '--get', 'user.name']) ?? '<git user.name>';
|
|
900
|
+
const gitEmail = runGitScalar(cwd, ['config', '--local', '--get', 'user.email']) ?? '<git user.email>';
|
|
901
|
+
return `node atm.mjs identity set --actor ${quoteCliValue(actorId)} --git-name ${quoteCliValue(gitName)} --git-email ${quoteCliValue(gitEmail)} --json`;
|
|
902
|
+
}
|
|
903
|
+
export function isPathAllowedByTaskDirection(filePath, allowedFiles) {
|
|
904
|
+
const normalizedFile = normalizeRelativePath(filePath).toLowerCase();
|
|
905
|
+
const cwd = process.cwd();
|
|
906
|
+
return allowedFiles.some((candidate) => {
|
|
907
|
+
let relCandidate = candidate;
|
|
908
|
+
if (path.isAbsolute(candidate)) {
|
|
909
|
+
relCandidate = relativePathFrom(cwd, candidate);
|
|
910
|
+
}
|
|
911
|
+
return matchesTaskDirectionPath(normalizedFile, normalizeRelativePath(relCandidate).toLowerCase());
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
function matchesTaskDirectionPath(filePath, allowedPath) {
|
|
915
|
+
if (!allowedPath)
|
|
916
|
+
return false;
|
|
917
|
+
if (allowedPath.includes('*')) {
|
|
918
|
+
const pattern = allowedPath.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*\*/g, '::DOUBLE_STAR::').replace(/\*/g, '[^/]*').replace(/::DOUBLE_STAR::/g, '.*');
|
|
919
|
+
return new RegExp(`^${pattern}$`, 'i').test(filePath);
|
|
920
|
+
}
|
|
921
|
+
if (filePath === allowedPath)
|
|
922
|
+
return true;
|
|
923
|
+
if (allowedPath.endsWith('/'))
|
|
924
|
+
return filePath.startsWith(allowedPath);
|
|
925
|
+
const allowedPathHasExtension = /\.[a-z0-9]+$/i.test(allowedPath);
|
|
926
|
+
return !allowedPathHasExtension && filePath.startsWith(`${allowedPath}/`);
|
|
927
|
+
}
|
|
928
|
+
export function uniqueSorted(values) {
|
|
929
|
+
return [...new Set(values)].sort((left, right) => left.localeCompare(right));
|
|
930
|
+
}
|
|
931
|
+
function sha256(value) {
|
|
932
|
+
return `sha256:${createHash('sha256').update(value).digest('hex')}`;
|
|
933
|
+
}
|
|
934
|
+
function taskReleaseOnlyTransitionSha(task, event) {
|
|
935
|
+
if (!task || typeof task !== 'object' || Array.isArray(task))
|
|
936
|
+
return null;
|
|
937
|
+
if (!event || typeof event !== 'object' || Array.isArray(event))
|
|
938
|
+
return null;
|
|
939
|
+
const eventRecord = event;
|
|
940
|
+
if (eventRecord.action !== 'close')
|
|
941
|
+
return null;
|
|
942
|
+
const taskRecord = task;
|
|
943
|
+
const lock = taskRecord.taskDirectionLock;
|
|
944
|
+
if (!lock || typeof lock !== 'object' || Array.isArray(lock))
|
|
945
|
+
return null;
|
|
946
|
+
const lockRecord = lock;
|
|
947
|
+
if (lockRecord.status !== 'released' || lockRecord.released !== true)
|
|
948
|
+
return null;
|
|
949
|
+
const normalizedTask = { ...taskRecord, taskDirectionLock: { ...lockRecord, status: 'active' } };
|
|
950
|
+
delete normalizedTask.taskDirectionLock.released;
|
|
951
|
+
delete normalizedTask.taskDirectionLock.releasedAt;
|
|
952
|
+
delete normalizedTask.taskDirectionLock.releasedBy;
|
|
953
|
+
return sha256(`${JSON.stringify(normalizedTask, null, 2)}\n`);
|
|
954
|
+
}
|
|
955
|
+
function sameStringSet(left, right) {
|
|
956
|
+
const normalize = (values) => [...new Set(values.map((value) => String(value).trim()).filter(Boolean))].sort();
|
|
957
|
+
return JSON.stringify(normalize(left)) === JSON.stringify(normalize(right));
|
|
958
|
+
}
|
|
959
|
+
function requireValue(argv, index, flag) {
|
|
960
|
+
const value = argv[index + 1];
|
|
961
|
+
if (!value || value.startsWith('--')) {
|
|
962
|
+
throw new CliError('ATM_CLI_USAGE', `hook command requires a value for ${flag}`, { exitCode: 2 });
|
|
963
|
+
}
|
|
964
|
+
return value;
|
|
965
|
+
}
|