@aibyzero/cm-workflow 0.17.1 → 0.18.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/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +23 -0
- package/CHANGELOG.md +224 -0
- package/README.md +14 -3
- package/THIRD_PARTY_NOTICES.md +13 -0
- package/VERSION +1 -1
- package/compat/claude-commands/cm-challenge.md +3 -0
- package/docs/architecture.md +11 -0
- package/docs/cm-control-policy-v2.md +127 -9
- package/docs/installation.md +310 -4
- package/docs/js-workflow-control.md +150 -15
- package/docs/live-evidence-drivers.md +28 -4
- package/docs/out-of-scope/README.md +25 -0
- package/docs/out-of-scope/background-supervisor.md +32 -0
- package/docs/reviewed-integration.md +48 -0
- package/docs/user-guide.md +50 -21
- package/install-codex.sh +331 -18
- package/install.ps1 +28 -2
- package/install.sh +321 -17
- package/package.json +2 -1
- package/runtime/js/cm-ai/batch-location.mjs +55 -0
- package/runtime/js/cm-ai/batch-plan.mjs +242 -0
- package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
- package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +83 -14
- package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-admission.mjs +18 -12
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
- package/runtime/js/cm-ai/codex-config.mjs +6 -2
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
- package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
- package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
- package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
- package/runtime/js/cm-ai/control-policy.mjs +21 -4
- package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
- package/runtime/js/cm-ai/drive-core.mjs +114 -11
- package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
- package/runtime/js/cm-ai/effect-contract.mjs +11 -2
- package/runtime/js/cm-ai/execution-policy.mjs +3 -1
- package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
- package/runtime/js/cm-ai/execution-store.mjs +60 -17
- package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
- package/runtime/js/cm-ai/host-check.mjs +11 -5
- package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
- package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
- package/runtime/js/cm-ai/host-replay.mjs +148 -0
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
- package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
- package/runtime/js/cm-ai/live-evidence.mjs +28 -6
- package/runtime/js/cm-ai/operator-guidance.mjs +9 -2
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
- package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
- package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
- package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
- package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
- package/runtime/js/cm-ai/review-package.mjs +79 -7
- package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
- package/runtime/js/cm-ai/review-presentation.mjs +177 -8
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
- package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
- package/runtime/js/cm-ai/scope-revision.mjs +38 -0
- package/runtime/js/cm-ai/specification-material.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +242 -39
- package/runtime/js/cm-ai/verification-auto.mjs +38 -0
- package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
- package/runtime/js/cm-ai/worker-claude.mjs +35 -13
- package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
- package/runtime/js/cm-ai/worker-codex.mjs +41 -7
- package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
- package/runtime/js/cm-fix/cause-package.mjs +46 -1
- package/runtime/js/cm-fix/command-correction.mjs +37 -0
- package/runtime/js/cm-fix/cooperative.mjs +12 -0
- package/runtime/js/cm-fix/dossier.mjs +8 -2
- package/runtime/js/cm-fix/execution.mjs +578 -100
- package/runtime/js/cm-fix/final-review.mjs +39 -8
- package/runtime/js/cm-fix/finish.mjs +15 -11
- package/runtime/js/cm-fix/host-review.mjs +65 -10
- package/runtime/js/cm-fix/host.mjs +35 -12
- package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
- package/runtime/js/cm-fix/metrics.mjs +18 -5
- package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
- package/runtime/js/cm-fix/regression.mjs +16 -7
- package/runtime/js/cm-fix/repair.mjs +29 -8
- package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
- package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
- package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
- package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
- package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
- package/runtime/js/cm-fix/review-verification.mjs +214 -0
- package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
- package/runtime/js/cm-fix/start.mjs +6 -3
- package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
- package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
- package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
- package/runtime/js/cm-prd/accepted-design.mjs +8 -0
- package/runtime/js/cm-prd/analysis.mjs +13 -9
- package/runtime/js/cm-prd/change.mjs +37 -16
- package/runtime/js/cm-prd/draft-save.mjs +13 -6
- package/runtime/js/cm-prd/draft.mjs +31 -3
- package/runtime/js/cm-prd/failed-correction.mjs +19 -3
- package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
- package/runtime/js/cm-prd/review-correction.mjs +6 -4
- package/runtime/js/cm-prd/review-disposition.mjs +7 -1
- package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
- package/runtime/js/cm-prd/self-check.mjs +125 -6
- package/runtime/js/cm-prd/session.mjs +30 -1
- package/runtime/js/cm-prd/summary.mjs +11 -5
- package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
- package/runtime/js/cm-prd/tree-digest.mjs +34 -0
- package/runtime/js/cm-prd/validation-reason.mjs +8 -4
- package/runtime/js/cm-security/scan.mjs +1 -1
- package/runtime/js/commander/decision.mjs +44 -0
- package/runtime/js/commander/dispatch-registry.mjs +110 -0
- package/runtime/js/commander/ledger.mjs +265 -0
- package/runtime/js/commander/preflight.mjs +107 -0
- package/runtime/js/notify-later.mjs +13 -0
- package/runtime/js/notify-send.mjs +6 -2
- package/runtime/js/notify.mjs +570 -63
- package/runtime/js/review-findings.mjs +38 -0
- package/runtime/js/session-boundary.mjs +56 -0
- package/runtime/js/session-handoff.mjs +68 -0
- package/runtime/js/spec-task-line.mjs +27 -13
- package/runtime/js/specs-status.mjs +1 -1
- package/runtime/js/task-scope.mjs +197 -0
- package/runtime/logging.md +6 -1
- package/runtime/model-efficiency.md +69 -10
- package/runtime/orchestration.md +3 -1
- package/runtime/project-learning.md +2 -0
- package/runtime/review.md +3 -2
- package/runtime/test-contract.md +1 -0
- package/scripts/ci-test-weights.json +3 -0
- package/scripts/cm-ai-admission.mjs +11 -5
- package/scripts/cm-ai-admission.test.mjs +23 -2
- package/scripts/cm-ai-batch-drive.mjs +79 -18
- package/scripts/cm-ai-batch-drive.test.mjs +169 -3
- package/scripts/cm-ai-batch-host.mjs +38 -9
- package/scripts/cm-ai-batch-host.test.mjs +6 -5
- package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
- package/scripts/cm-ai-batch-location.test.mjs +57 -0
- package/scripts/cm-ai-batch-plan.mjs +52 -0
- package/scripts/cm-ai-batch-plan.test.mjs +397 -0
- package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
- package/scripts/cm-ai-batch-run.mjs +471 -57
- package/scripts/cm-ai-batch-run.test.mjs +23 -4
- package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
- package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
- package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
- package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
- package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
- package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
- package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
- package/scripts/cm-ai-control-launch.test.mjs +21 -0
- package/scripts/cm-ai-control-policy.test.mjs +14 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
- package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
- package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
- package/scripts/cm-ai-development-rework.test.mjs +423 -0
- package/scripts/cm-ai-drive.mjs +73 -17
- package/scripts/cm-ai-drive.test.mjs +34 -2
- package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
- package/scripts/cm-ai-host.mjs +60 -19
- package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
- package/scripts/cm-ai-integration-independence.test.mjs +23 -0
- package/scripts/cm-ai-integration-launch.test.mjs +240 -0
- package/scripts/cm-ai-integration-preview.mjs +41 -0
- package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
- package/scripts/cm-ai-nested-execution.test.mjs +29 -1
- package/scripts/cm-ai-operator-guidance.test.mjs +16 -1
- package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
- package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
- package/scripts/cm-ai-review-failure.test.mjs +150 -5
- package/scripts/cm-ai-run.mjs +88 -21
- package/scripts/cm-ai-scope-revision.test.mjs +341 -0
- package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
- package/scripts/cm-ai-supersede.test.mjs +28 -0
- package/scripts/cm-ai-verification-auto.test.mjs +99 -0
- package/scripts/cm-announce-hook.mjs +35 -8
- package/scripts/cm-announce-hook.test.mjs +25 -0
- package/scripts/cm-challenge.test.mjs +61 -0
- package/scripts/cm-check-drive-files.mjs +1 -1
- package/scripts/cm-check-runtime.sh +58 -1
- package/scripts/cm-claude-developer-worker.test.mjs +56 -7
- package/scripts/cm-claude-install-layout.test.mjs +1 -1
- package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
- package/scripts/cm-claude-review-stream.test.mjs +13 -0
- package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
- package/scripts/cm-codex-developer-worker.test.mjs +120 -0
- package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
- package/scripts/cm-codex-prompt-input.test.mjs +153 -0
- package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
- package/scripts/cm-commander-ledger.test.mjs +260 -0
- package/scripts/cm-commander-p2.test.mjs +295 -0
- package/scripts/cm-commander-preflight.mjs +84 -0
- package/scripts/cm-commander.mjs +116 -0
- package/scripts/cm-config-lock.mjs +35 -0
- package/scripts/cm-controlled-correction.test.mjs +10 -1
- package/scripts/cm-developer-failure-code.test.mjs +62 -0
- package/scripts/cm-display-task-id.test.mjs +41 -0
- package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
- package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
- package/scripts/cm-external-batch-host.test.mjs +4 -3
- package/scripts/cm-external-process-cleanup.test.mjs +128 -0
- package/scripts/cm-external-qa-fix.test.mjs +89 -7
- package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
- package/scripts/cm-failover.mjs +48 -10
- package/scripts/cm-failover.test.mjs +46 -0
- package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
- package/scripts/cm-fix-command-correction.mjs +17 -0
- package/scripts/cm-fix-command-correction.test.mjs +211 -0
- package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
- package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
- package/scripts/cm-fix-drive.mjs +33 -5
- package/scripts/cm-fix-drive.test.mjs +49 -0
- package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
- package/scripts/cm-fix-host-review.test.mjs +21 -9
- package/scripts/cm-fix-host.mjs +26 -8
- package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
- package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
- package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
- package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
- package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
- package/scripts/cm-fix-review-preflight.mjs +24 -0
- package/scripts/cm-fix-review-storage.test.mjs +233 -0
- package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
- package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
- package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
- package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
- package/scripts/cm-fix-review-verification.test.mjs +146 -0
- package/scripts/cm-fix-revision-transport.test.mjs +81 -0
- package/scripts/cm-fix-source-correction.test.mjs +296 -0
- package/scripts/cm-fix-test-type-correction.mjs +18 -0
- package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
- package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
- package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
- package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
- package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
- package/scripts/cm-fix-verification-recovery.mjs +33 -0
- package/scripts/cm-host-qa-executor.test.mjs +77 -0
- package/scripts/cm-host-replay.test.mjs +176 -0
- package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
- package/scripts/cm-install-manifest.sh +351 -0
- package/scripts/cm-live-evidence.test.mjs +59 -1
- package/scripts/cm-log-event.mjs +61 -10
- package/scripts/cm-log-event.test.mjs +121 -1
- package/scripts/cm-matt-skills.mjs +576 -0
- package/scripts/cm-matt-skills.test.mjs +550 -0
- package/scripts/cm-notify-command.test.mjs +42 -10
- package/scripts/cm-notify.mjs +14 -10
- package/scripts/cm-notify.test.mjs +575 -59
- package/scripts/cm-patrol.mjs +4 -1
- package/scripts/cm-patrol.test.mjs +23 -5
- package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
- package/scripts/cm-prd-completion.test.mjs +56 -13
- package/scripts/cm-prd-design-phase.test.mjs +78 -8
- package/scripts/cm-prd-draft-save.test.mjs +12 -0
- package/scripts/cm-prd-draft.test.mjs +1 -1
- package/scripts/cm-prd-drive.mjs +13 -6
- package/scripts/cm-prd-drive.test.mjs +45 -1
- package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
- package/scripts/cm-prd-host.mjs +10 -5
- package/scripts/cm-prd-host.test.mjs +4 -2
- package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
- package/scripts/cm-prd-review-disposition.test.mjs +124 -8
- package/scripts/cm-prd-revision.test.mjs +1 -1
- package/scripts/cm-prd-self-check-revision.test.mjs +1 -1
- package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
- package/scripts/cm-prd-self-check.test.mjs +105 -5
- package/scripts/cm-prd-summary.test.mjs +24 -3
- package/scripts/cm-prd-task-grouping.test.mjs +6 -6
- package/scripts/cm-prd-tree-digest.test.mjs +74 -0
- package/scripts/cm-refactor-drive.mjs +2 -1
- package/scripts/cm-refactor-drive.test.mjs +9 -0
- package/scripts/cm-release-smoke.sh +1 -1
- package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
- package/scripts/cm-skill-hints-exam.mjs +149 -0
- package/scripts/cm-skill-hints-install.test.mjs +168 -0
- package/scripts/cm-skill-hints.exam.json +706 -0
- package/scripts/cm-skill-hints.json +119 -0
- package/scripts/cm-skill-hints.mjs +669 -0
- package/scripts/cm-skill-hints.test.mjs +831 -0
- package/scripts/cm-skill-judge.mjs +181 -0
- package/scripts/cm-skill-judge.test.mjs +255 -0
- package/scripts/cm-specs-status.test.mjs +4 -2
- package/scripts/cm-start-check.mjs +208 -0
- package/scripts/cm-start-check.test.mjs +321 -0
- package/scripts/cm-task-gate.mjs +150 -29
- package/scripts/cm-task-gate.test.mjs +73 -1
- package/scripts/cm-task-id-grammar.test.mjs +66 -0
- package/scripts/cm-task-scope.test.mjs +308 -0
- package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
- package/scripts/cm-upgrade-compat.test.mjs +239 -0
- package/scripts/cm-workflow-config.mjs +12 -2
- package/scripts/fixtures/fix-verification-claude.mjs +44 -0
- package/scripts/fixtures/reviewed-integration.mjs +202 -0
- package/scripts/scan-public-safety.py +1 -0
- package/scripts/session-boundary.test.mjs +170 -0
- package/scripts/test-npm-install.py +14 -3
- package/scripts/test-shell-compat.sh +2 -0
- package/scripts/validate-public-repo.py +1 -0
- package/scripts/validate-test-cases.mjs +3 -2
- package/skills/cm-ai/SKILL.md +5 -2
- package/skills/cm-ai/references/N4-review.md +2 -1
- package/skills/cm-ai/references/N6-qa-eval.md +3 -1
- package/skills/cm-ai/references/N8-finish.md +22 -0
- package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
- package/skills/cm-ai/references/js-host-recovery.md +79 -3
- package/skills/cm-ai/references/js-host.md +56 -16
- package/skills/cm-challenge/SKILL.md +65 -0
- package/skills/cm-challenge/evals/README.md +18 -0
- package/skills/cm-challenge/evals/trigger-cases.json +20 -0
- package/skills/cm-challenge/evals/trigger-config.json +28 -0
- package/skills/cm-challenge/references/examples.md +15 -0
- package/skills/cm-check/SKILL.md +5 -0
- package/skills/cm-check/references/js-host.md +2 -0
- package/skills/cm-fix/SKILL.md +12 -3
- package/skills/cm-fix/references/command-correction.md +67 -0
- package/skills/cm-fix/references/isolated-review.md +54 -0
- package/skills/cm-fix/references/js-host.md +62 -2
- package/skills/cm-fix/references/test-type-correction.md +72 -0
- package/skills/cm-fix/references/verification-recovery.md +114 -0
- package/skills/cm-idea/SKILL.md +2 -0
- package/skills/cm-idea/references/js-host.md +2 -0
- package/skills/cm-notify/SKILL.md +2 -0
- package/skills/cm-prd/SKILL.md +12 -8
- package/skills/cm-prd/references/brownfield.md +8 -1
- package/skills/cm-prd/references/change-mode.md +6 -0
- package/skills/cm-prd/references/greenfield.md +4 -0
- package/skills/cm-prd/references/js-host.md +4 -2
- package/skills/cm-prd/references/spec-self-check.md +5 -1
- package/skills/cm-refactor/SKILL.md +8 -0
- package/skills/cm-refactor/references/js-host.md +2 -0
- package/skills/cm-test/SKILL.md +4 -0
- package/templates/dashboard/dashboard.html +2 -2
- package/templates/pixel/cm-pixel.html +1 -1
- package/templates/pixel/cm-pixel.sh +1 -1
- package/templates/pixel/dev/template.html +1 -1
- package/templates/statusline/cm-statusline.sh +1 -1
|
@@ -6,6 +6,9 @@ import {need,json,digest,shape} from '../cm-ai/effect-contract.mjs';
|
|
|
6
6
|
import {readExecutionPolicy} from '../cm-ai/execution-policy.mjs';
|
|
7
7
|
import {recoverPrdResponse,readPrdRepairBinding} from './response-recovery.mjs';
|
|
8
8
|
import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
9
|
+
import {TASK_GRAMMAR} from '../spec-task-line.mjs';
|
|
10
|
+
import {readSpecsStatus} from '../specs-status.mjs';
|
|
11
|
+
import {PRD_SELF_CHECK_RULES,PRD_SELF_CHECK_RULE_VERSIONS} from './self-check.mjs';
|
|
9
12
|
|
|
10
13
|
export function readPrdSessionFile(root,relative){
|
|
11
14
|
if(!['state.json','inputs-replaced.json'].includes(relative))return readCmInitSource(root,relative)?.toString('utf8')??null;
|
|
@@ -28,6 +31,23 @@ export function replaceSessionFile(root,relative,before,after){
|
|
|
28
31
|
}finally{if(fd!==undefined)fs.closeSync(fd);try{fs.unlinkSync(tmp);}catch(e){if(e.code!=='ENOENT')throw e;}}
|
|
29
32
|
}
|
|
30
33
|
export const MAX_ANSWER_DISCARDS=2;
|
|
34
|
+
// The task grammar and self-check rule a session binds when it is created; they
|
|
35
|
+
// govern only operations it starts later (an active operation keeps its own rule).
|
|
36
|
+
// A session created before they were recorded keeps what was published then, as
|
|
37
|
+
// literals that never follow the current constants.
|
|
38
|
+
export const PRD_SESSION_LEGACY_VERSIONS=Object.freeze({taskGrammar:2,selfCheckRules:3});
|
|
39
|
+
// No state yet: the session about to be created binds the current ones, unless its
|
|
40
|
+
// specs directory was already published under an earlier grammar (a status without
|
|
41
|
+
// taskGrammar is grammar 1, an explicit 2 stays 2): one directory keeps one grammar,
|
|
42
|
+
// so a `开发:` line is never checked as grammar 3 and then published as prose.
|
|
43
|
+
export function prdSessionVersions(state,specs=null){
|
|
44
|
+
if(state==null){
|
|
45
|
+
const status=specs===null?{kind:'missing'}:readSpecsStatus(specs);
|
|
46
|
+
return status.kind==='missing'||status.kind==='valid'&&status.value.taskGrammar===TASK_GRAMMAR
|
|
47
|
+
?{taskGrammar:TASK_GRAMMAR,selfCheckRules:PRD_SELF_CHECK_RULES}:{...PRD_SESSION_LEGACY_VERSIONS};
|
|
48
|
+
}
|
|
49
|
+
return Object.hasOwn(state,'selfCheckRules')?{taskGrammar:state.taskGrammar,selfCheckRules:state.selfCheckRules}:{...PRD_SESSION_LEGACY_VERSIONS};
|
|
50
|
+
}
|
|
31
51
|
export function openPrdSession({specs,sessionId,identity,executionPolicy=null}){
|
|
32
52
|
need(/^prd-[a-zA-Z0-9-]{1,80}$/.test(sessionId),'prd_session_id_invalid');
|
|
33
53
|
for(const relative of ['.reviews','.reviews/prd-sessions',`.reviews/prd-sessions/${sessionId}`]){
|
|
@@ -45,8 +65,12 @@ export function openPrdSession({specs,sessionId,identity,executionPolicy=null}){
|
|
|
45
65
|
const lockBytes=JSON.stringify({pid:process.pid,nonce:randomUUID()});
|
|
46
66
|
const fd=fs.openSync(lock,'wx',0o600);try{fs.writeFileSync(fd,lockBytes);fs.fsyncSync(fd);}finally{fs.closeSync(fd);}
|
|
47
67
|
let bytes=read(),state=bytes===null?{version:executionPolicy===null?1:2,identity,checkpoint:null,active:null,segments:{},
|
|
68
|
+
...prdSessionVersions(null,specs),
|
|
48
69
|
...(executionPolicy===null?{}:{executionPolicy:readExecutionPolicy(executionPolicy),responseRepairs:[]})}:JSON.parse(bytes);
|
|
49
70
|
try{need([1,2].includes(state.version)&&digest(state.identity)===digest(identity),'prd_session_identity_changed');
|
|
71
|
+
need(Object.hasOwn(state,'taskGrammar')===Object.hasOwn(state,'selfCheckRules')&&(!Object.hasOwn(state,'taskGrammar')
|
|
72
|
+
||Number.isSafeInteger(state.taskGrammar)&&state.taskGrammar>=2&&state.taskGrammar<=TASK_GRAMMAR
|
|
73
|
+
&&PRD_SELF_CHECK_RULE_VERSIONS.includes(state.selfCheckRules)),'prd_session_versions_invalid');
|
|
50
74
|
if(state.version===2){readExecutionPolicy(state.executionPolicy);need(Array.isArray(state.responseRepairs),'prd_recovery_binding');}
|
|
51
75
|
else need(executionPolicy===null,'execution_policy_legacy_run');}
|
|
52
76
|
catch(e){fs.unlinkSync(lock);throw e;}
|
|
@@ -96,7 +120,12 @@ export function openPrdSession({specs,sessionId,identity,executionPolicy=null}){
|
|
|
96
120
|
originalStateSha256:createHash('sha256').update(bytes).digest('hex'),repair:call.responseRepair});
|
|
97
121
|
save();return json(call.responseRepair);
|
|
98
122
|
},
|
|
99
|
-
|
|
123
|
+
// An operation records the self-check rule it started under; one begun before
|
|
124
|
+
// rules were recorded replays under rule 1, so a reply registered then is judged as then.
|
|
125
|
+
begin(request,before,{selfCheckRules=null}={}){need(state.active===null,'prd_operation_recovery_required');
|
|
126
|
+
state.active={request,before,calls:[],...(selfCheckRules===null?{}:{selfCheckRules})};cursor=0;save();},
|
|
127
|
+
selfCheckRules(){return state.active?.selfCheckRules??1;},
|
|
128
|
+
versions(){return prdSessionVersions(state);},
|
|
100
129
|
replay(){need(state.active!==null,'prd_nothing_to_resume');cursor=0;return json(state.active,12*1024*1024);},
|
|
101
130
|
commit(checkpoint){state.checkpoint=checkpoint;state.active=null;save();},
|
|
102
131
|
checkpoint(checkpoint){state.checkpoint=checkpoint;save();},
|
|
@@ -7,11 +7,13 @@ import path from 'node:path';
|
|
|
7
7
|
import {createHash} from 'node:crypto';
|
|
8
8
|
import {TextDecoder} from 'node:util';
|
|
9
9
|
import {readSpecsStatus,writeSpecsStatus} from '../specs-status.mjs';
|
|
10
|
+
import {TASK_GRAMMAR} from '../spec-task-line.mjs';
|
|
10
11
|
import {buildManifest} from '../../../scripts/cm-spec-manifest.mjs';
|
|
11
12
|
import {inspectPrdReview} from '../../../scripts/cm-prd-review-gate.mjs';
|
|
12
13
|
import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
13
14
|
import {inspectPrdFindings} from './review-findings.mjs';
|
|
14
15
|
import {checkPrdDraftMechanics} from './self-check.mjs';
|
|
16
|
+
import {prdTaskScopeOptions} from './task-scope-record.mjs';
|
|
15
17
|
import {need,json,shape,digest} from '../cm-ai/effect-contract.mjs';
|
|
16
18
|
import {inspectPrdFailedCorrection} from './failed-correction.mjs';
|
|
17
19
|
import {prdDesignRiskSignals} from './design-risk.mjs';
|
|
@@ -113,16 +115,20 @@ export function inspectPrdSummaryEvidence(specs,{currentFeatures}={}){
|
|
|
113
115
|
features.push({directory,reviews,cases,...(revision?{selfCheckRevision:{reason:revision.reason,round:revision.round,
|
|
114
116
|
changedFiles:revision.features.find(f=>f.directory===directory).changedFiles}}:{}),...(currentFeatures===undefined?{}:{historical})});
|
|
115
117
|
}
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
+
const checked=documents.filter(item=>currentFeatures===undefined||currentFeatures.includes(item.directory));
|
|
119
|
+
const mechanical=checkPrdDraftMechanics({draftDigest:digest(evidenceFiles),features:checked},
|
|
120
|
+
prdTaskScopeOptions(specs,checked.map(item=>item.directory)));
|
|
118
121
|
return json({specs,specFiles,features,documents,mechanical,evidenceFiles,
|
|
119
122
|
...(predecessor?{predecessor}:{}),
|
|
120
123
|
...(currentFeatures===undefined?{}:{currentFeatures})},1024*1024);
|
|
121
124
|
}
|
|
122
125
|
|
|
123
|
-
|
|
126
|
+
// taskGrammar is the one the publishing session bound (session.mjs); a first
|
|
127
|
+
// publication writes it, an earlier status keeps its own grammar (or none, grammar 1).
|
|
128
|
+
export function publishPrdAwaitingReview({specs,summary,writeEnabled,recover=false,taskGrammar=2}){
|
|
124
129
|
assertPrdBatchActive(specs);
|
|
125
130
|
need(writeEnabled===true,'prd_summary_write_not_enabled');
|
|
131
|
+
need(Number.isSafeInteger(taskGrammar)&&taskGrammar>=2&&taskGrammar<=TASK_GRAMMAR,'prd_task_grammar_invalid');
|
|
126
132
|
need(summary.status==='human_summary_prepared'&&summary.readyForAwaitingReview===true
|
|
127
133
|
&&summary.blockers.length===0,'prd_summary_not_ready');
|
|
128
134
|
const scope={currentFeatures:summary.currentFeatures};
|
|
@@ -144,8 +150,8 @@ export function publishPrdAwaitingReview({specs,summary,writeEnabled,recover=fal
|
|
|
144
150
|
const status={status:'awaiting_review',summaryDigest:summary.summaryDigest,at:new Date().toISOString(),features:before.features.map(item=>item.directory),
|
|
145
151
|
specFiles:before.specFiles,testCases:before.specFiles.filter(item=>item.path.endsWith('/test-cases.json')),approval:null,
|
|
146
152
|
...(prior.kind==='valid'&&Object.hasOwn(prior.value,'revisionDigest')?{revisionDigest:prior.value.revisionDigest}:{}),
|
|
147
|
-
// A first publication has no earlier approval to reinterpret: bind grammar
|
|
148
|
-
...(prior.kind==='missing'
|
|
153
|
+
// A first publication has no earlier approval to reinterpret: bind the session's grammar.
|
|
154
|
+
...(prior.kind==='missing'?{taskGrammar}:prior.kind==='valid'&&Object.hasOwn(prior.value,'taskGrammar')?{taskGrammar:prior.value.taskGrammar}:{})};
|
|
149
155
|
const bytes=Buffer.from(JSON.stringify(status)+'\n'),target=path.join(specs,'.cm-specs-status');
|
|
150
156
|
try{
|
|
151
157
|
writeSpecsStatus(specs,status,{beforeRename:()=>{
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Whether a saved feature's tasks.md is held to the per-task scope check.
|
|
2
|
+
//
|
|
3
|
+
// A fresh draft and a change proposal are checked under the session's rule; the
|
|
4
|
+
// later re-checks of the saved files (split correction, disposition, summary) run
|
|
5
|
+
// outside that session and used to fall back to rule 1, so a correction could
|
|
6
|
+
// drop a task's scope unnoticed. The save now records, per feature and before any
|
|
7
|
+
// spec byte is written, whether the saved tasks.md carries scopes and which tasks
|
|
8
|
+
// may stay without one: only tasks an approval covered (approvedScopeExemptions),
|
|
9
|
+
// never tasks that merely appear in an unapproved draft. No record (a draft saved
|
|
10
|
+
// before this rule, or one without scopes) keeps the old behaviour.
|
|
11
|
+
// A save made under self-check rule 4 or later also records that rule
|
|
12
|
+
// (selfCheckRules), so the re-checks read its tasks.md as grammar 3 and keep the
|
|
13
|
+
// session-task checks; a record without it (an earlier rule, or an operation that
|
|
14
|
+
// began before operations recorded their rule) keeps the old behaviour.
|
|
15
|
+
import fs from 'node:fs';
|
|
16
|
+
import path from 'node:path';
|
|
17
|
+
import {createHash} from 'node:crypto';
|
|
18
|
+
import {need} from '../cm-ai/effect-contract.mjs';
|
|
19
|
+
import {parseFeatureTaskText} from '../cm-ai/cm-ai-admission.mjs';
|
|
20
|
+
import {checkPrdDraftMechanics,PRD_SELF_CHECK_RULE_VERSIONS} from './self-check.mjs';
|
|
21
|
+
import {readPrdSessionFile,replaceSessionFile} from './session.mjs';
|
|
22
|
+
import {normalizeRuntimeMarkBytes} from '../../../scripts/cm-spec-manifest.mjs';
|
|
23
|
+
|
|
24
|
+
const SCOPE_CODES=new Set(['task_scope_invalid','task_scope_missing']);
|
|
25
|
+
const recordPath=directory=>`.reviews/prd-${directory.replace(/^\d+\./,'')}-task-scope.json`;
|
|
26
|
+
|
|
27
|
+
function taskIds(text,grammar){
|
|
28
|
+
if(typeof text!=='string')return [];
|
|
29
|
+
const parsed=parseFeatureTaskText(text,{grammar});
|
|
30
|
+
return parsed.error?[]:parsed.tasks.map(task=>task.id).sort();
|
|
31
|
+
}
|
|
32
|
+
function parseRecord(raw){
|
|
33
|
+
let value;try{value=JSON.parse(raw);}catch{value=null;}
|
|
34
|
+
need(value!==null&&typeof value==='object'&&value.version===1&&typeof value.enforced==='boolean'
|
|
35
|
+
&&Array.isArray(value.exempt)&&value.exempt.every(id=>typeof id==='string')
|
|
36
|
+
&&(!Object.hasOwn(value,'selfCheckRules')||PRD_SELF_CHECK_RULE_VERSIONS.includes(value.selfCheckRules)&&value.selfCheckRules>=4)
|
|
37
|
+
&&Object.keys(value).length===(Object.hasOwn(value,'selfCheckRules')?4:3),'prd_task_scope_record_invalid');
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
// The record texts a change snapshot binds (only features that have one).
|
|
41
|
+
export function prdTaskScopeRecords(specs,directories){
|
|
42
|
+
const records={};
|
|
43
|
+
for(const directory of directories){const raw=readPrdSessionFile(specs,recordPath(directory));if(raw!==null)records[directory]=raw;}
|
|
44
|
+
return records;
|
|
45
|
+
}
|
|
46
|
+
// {directory: {exempt}} for a change. A feature whose tasks.md is exactly the
|
|
47
|
+
// approved bytes exempts the tasks of that approval, read with its grammar. An
|
|
48
|
+
// unapproved state (a draft, or a change awaiting review) keeps what its own save
|
|
49
|
+
// recorded, which traces back to an approval or is empty.
|
|
50
|
+
export function approvedScopeExemptions(before,directories,grammar){
|
|
51
|
+
let status=null;try{status=JSON.parse(before.status??'null');}catch{status=null;}
|
|
52
|
+
const approved=status?.status==='approved'&&Array.isArray(status.specFiles)?status.specFiles:[];
|
|
53
|
+
// Approval rows are semantic digests (runtime [x] marks reset), current or legacy rule.
|
|
54
|
+
const digests=text=>[{},{legacy:true}].map(options=>
|
|
55
|
+
createHash('sha256').update(normalizeRuntimeMarkBytes(Buffer.from(text),'tasks.md',options)).digest('hex'));
|
|
56
|
+
return Object.fromEntries(directories.map(directory=>{
|
|
57
|
+
const file=`${directory}/tasks.md`,text=before.files[file];
|
|
58
|
+
if(typeof text==='string'&&approved.some(item=>item?.path===file&&digests(text).includes(item.sha256)))
|
|
59
|
+
return [directory,{exempt:taskIds(text,grammar)}];
|
|
60
|
+
const record=before.scopeRecords?.[directory];
|
|
61
|
+
return [directory,{exempt:record===undefined?[]:parseRecord(record).exempt}];
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// `exemptions` maps a directory to {exempt} (a change) or is empty (a new draft).
|
|
66
|
+
// `selfCheckRules` is the rule of the saving operation (session.mjs); only rule 4
|
|
67
|
+
// and later are written, since earlier rules add nothing beyond the scope record.
|
|
68
|
+
export function recordPrdTaskScopes(specs,features,exemptions={},{selfCheckRules=1}={}){
|
|
69
|
+
need(PRD_SELF_CHECK_RULE_VERSIONS.includes(selfCheckRules),'prd_self_check_rules_invalid');
|
|
70
|
+
const reviews=path.join(specs,'.reviews');
|
|
71
|
+
try{fs.mkdirSync(reviews,{mode:0o700});}catch(error){if(error.code!=='EEXIST')throw error;}
|
|
72
|
+
need(fs.realpathSync(reviews)===reviews,'prd_task_scope_record_invalid');
|
|
73
|
+
for(const feature of features){
|
|
74
|
+
if(!feature.documents.some(doc=>doc.path==='tasks.md'))continue;
|
|
75
|
+
const exempt=[...(exemptions[feature.directory]?.exempt??[])].sort();
|
|
76
|
+
const report=checkPrdDraftMechanics({draftDigest:'task-scope-record',features:[feature]},
|
|
77
|
+
{scopes:{[feature.directory]:{exempt}}});
|
|
78
|
+
const enforced=!report.findings.some(item=>SCOPE_CODES.has(item.code));
|
|
79
|
+
const relative=recordPath(feature.directory),bytes=JSON.stringify({version:1,enforced,exempt,
|
|
80
|
+
...(selfCheckRules>=4?{selfCheckRules}:{})})+'\n';
|
|
81
|
+
const prior=readPrdSessionFile(specs,relative);
|
|
82
|
+
if(prior!==bytes)replaceSessionFile(specs,relative,prior,bytes);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// The checkPrdDraftMechanics options a re-check of saved features must use.
|
|
87
|
+
export function prdTaskScopeOptions(specs,directories){
|
|
88
|
+
const scopes={},sessionTasks=[];
|
|
89
|
+
for(const directory of typeof directories==='string'?[directories]:directories){
|
|
90
|
+
const raw=readPrdSessionFile(specs,recordPath(directory));
|
|
91
|
+
if(raw===null)continue;
|
|
92
|
+
const value=parseRecord(raw);
|
|
93
|
+
if(value.enforced)scopes[directory]={exempt:value.exempt};
|
|
94
|
+
if(Object.hasOwn(value,'selfCheckRules'))sessionTasks.push(directory);
|
|
95
|
+
}
|
|
96
|
+
return {...(Object.keys(scopes).length?{scopes}:{}),...(sessionTasks.length?{sessionTasks}:{})};
|
|
97
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Asset inventory needs exact byte hashes, not decoded document contents.
|
|
2
|
+
// Keep memory bounded; document readers retain their separate size limits.
|
|
3
|
+
// Like readCmInitSource, the path is walked from the specs root: no segment
|
|
4
|
+
// may be a link, every parent must be a directory, the file a single-link file.
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import {createHash} from 'node:crypto';
|
|
8
|
+
import {need} from '../cm-ai/effect-contract.mjs';
|
|
9
|
+
const same=(a,b)=>['dev','ino','size','mtimeMs','ctimeMs','nlink'].every(key=>a[key]===b[key]);
|
|
10
|
+
function walk(root,relative){
|
|
11
|
+
need(typeof relative==='string'&&relative.split('/').every(part=>part&&part!=='.'&&part!=='..')
|
|
12
|
+
&&!relative.includes('\\')&&!relative.includes('\0'),'prd_change_asset_invalid');
|
|
13
|
+
const segments=relative.split('/');let current=root,stat;
|
|
14
|
+
for(let i=0;i<segments.length;i++){
|
|
15
|
+
current=path.join(current,segments[i]);stat=fs.lstatSync(current);
|
|
16
|
+
need(!stat.isSymbolicLink(),'prd_change_asset_invalid');
|
|
17
|
+
if(i<segments.length-1)need(stat.isDirectory(),'prd_change_asset_invalid');
|
|
18
|
+
}
|
|
19
|
+
need(stat.isFile()&&stat.nlink===1,'prd_change_asset_invalid');
|
|
20
|
+
return {file:current,stat};
|
|
21
|
+
}
|
|
22
|
+
export function prdTreeFileDigest(root,relative){
|
|
23
|
+
const {file,stat:before}=walk(root,relative);
|
|
24
|
+
const fd=fs.openSync(file,fs.constants.O_RDONLY|(fs.constants.O_NOFOLLOW??0)|(fs.constants.O_NONBLOCK??0));
|
|
25
|
+
try{
|
|
26
|
+
need(same(before,fs.fstatSync(fd)),'prd_change_inputs_changed');
|
|
27
|
+
const hash=createHash('sha256'),buffer=Buffer.alloc(64*1024);let bytes=0,count;
|
|
28
|
+
while((count=fs.readSync(fd,buffer,0,buffer.length,null))>0){hash.update(buffer.subarray(0,count));bytes+=count;}
|
|
29
|
+
// The same path, walked again, must still name the file that was read.
|
|
30
|
+
need(bytes===before.size&&same(before,fs.fstatSync(fd))&&same(before,walk(root,relative).stat),
|
|
31
|
+
'prd_change_inputs_changed');
|
|
32
|
+
return hash.digest('hex');
|
|
33
|
+
}finally{fs.closeSync(fd);}
|
|
34
|
+
}
|
|
@@ -6,14 +6,18 @@ export function needPrd(ok,code,reason){
|
|
|
6
6
|
try{need(ok,code);}catch(error){throw tagDiagnosticReason(error,reason);}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export
|
|
10
|
-
|
|
9
|
+
export const PRD_DRAFT_LIMIT=64*1024;
|
|
10
|
+
// limit: an assembled tasks_after_design draft also carries the accepted
|
|
11
|
+
// requirements/design the reply left out; only the reply itself is 64 KiB.
|
|
12
|
+
export function prdDraftJson(raw,limit=PRD_DRAFT_LIMIT){
|
|
13
|
+
try{return json(raw,limit);}catch(error){
|
|
11
14
|
if(error.code==='limit_exceeded'){
|
|
12
15
|
// The input is a parsed host reply. Do not include its contents in diagnostics.
|
|
13
16
|
let actualBytes=null;
|
|
14
17
|
try{actualBytes=Buffer.byteLength(JSON.stringify(raw));}catch{/* original error wins */}
|
|
15
|
-
tagDiagnosticReason(error,{field:'draft',expected:'one submission must be <= 65536 bytes (64 KiB)'
|
|
16
|
-
|
|
18
|
+
tagDiagnosticReason(error,{field:'draft',expected:limit===PRD_DRAFT_LIMIT?'one submission must be <= 65536 bytes (64 KiB)'
|
|
19
|
+
:`the assembled draft must be <= ${limit} bytes (64 KiB plus the accepted requirements/design)`,
|
|
20
|
+
limitBytes:limit,actualBytes});
|
|
17
21
|
}
|
|
18
22
|
throw error;
|
|
19
23
|
}
|
|
@@ -21,7 +21,7 @@ const environment=(home,project)=>({PATH:cleanPath(project),HOME:home,USERPROFIL
|
|
|
21
21
|
...(process.env.SystemRoot?{SystemRoot:process.env.SystemRoot}:{}),
|
|
22
22
|
GIT_NO_REPLACE_OBJECTS:'1',GIT_NO_LAZY_FETCH:'1',GIT_TERMINAL_PROMPT:'0',
|
|
23
23
|
GIT_CONFIG_NOSYSTEM:'1',GIT_CONFIG_GLOBAL:os.devNull});
|
|
24
|
-
const git=(project,args,optional=false)=>{
|
|
24
|
+
export const git=(project,args,optional=false)=>{
|
|
25
25
|
// Git status/diff can run clean/process filters. Suppress every configured driver,
|
|
26
26
|
// including required=true, in addition to fsmonitor, external diff and textconv.
|
|
27
27
|
let boundary=project;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Commander phase 2: one decision per run that needs attention, with its reason.
|
|
2
|
+
// It reads only what the journal recorded (state, code, pending). The real
|
|
3
|
+
// recovery exit depends on live status (pendingAction, budgets, verdicts,
|
|
4
|
+
// whether an old process has exited), so the table commits only where the
|
|
5
|
+
// record alone settles it; everywhere else it says "read status" and lists the
|
|
6
|
+
// exits that status may offer, marking those that need the user's approval.
|
|
7
|
+
// Every decision's first step is reading the run's own status.
|
|
8
|
+
import {REVIEW_RETRY_CODES} from '../cm-ai/durable-runner-state.mjs';
|
|
9
|
+
|
|
10
|
+
const STATUS='先用原 PLAN 读 status,以返回的 pendingAction 为准';
|
|
11
|
+
const APPROVAL='(需用户批准)';
|
|
12
|
+
const EXHAUSTED=/(_retry_limit|_redispatch_limit|_recheck_limit|_redo_limit|effect_interrupt_limit|review_abandon_budget_exhausted)$/;
|
|
13
|
+
const DEFECT=new Set(['execution_error','workflow_error','store_failure','runner_store_changed','checkpoint_package_material_invalid']);
|
|
14
|
+
const DEVELOP_RETRY=new Set(['develop_call_timeout','develop_checks_not_passed','develop_empty_changes','develop_package_too_large',
|
|
15
|
+
'develop_requirement_missing','develop_unchanged_after_review','check_answer_missing','check_answer_invalid',
|
|
16
|
+
'check_output_out_of_scope','developer_result_invalid','documentation_sync_answer_missing']);
|
|
17
|
+
|
|
18
|
+
export const DECISIONS=Object.freeze(['wait','spec_change','human_sync','escalate','read_status']);
|
|
19
|
+
|
|
20
|
+
// Any listed exit that needs approval makes the whole decision need it.
|
|
21
|
+
const decide=(decision,needsApproval,why,steps,candidates=[])=>({decision,
|
|
22
|
+
needsApproval:needsApproval||candidates.some(candidate=>candidate.includes(APPROVAL)),why,steps:[STATUS,...steps],candidates});
|
|
23
|
+
|
|
24
|
+
export function decideRecovery({state=null,code=null,pending=null,verified=true}={}){
|
|
25
|
+
if(!verified)return decide('read_status',false,'本版本回放不了这条运行的记录,状态未校验',[]);
|
|
26
|
+
if(pending)return decide('wait',false,`记录里有未结的 ${pending},可能仍在执行`,['确认执行它的宿主或会话是否还在;还在就等,不重派']);
|
|
27
|
+
if(code==='spec_drift')return decide('spec_change',true,'已批准规格被改动,运行被挡住',['规格改动需用户确认:还原,或重新批准后按 status 给出的换绑出口处理']);
|
|
28
|
+
if(code==='protected_scope')return decide('human_sync',true,'scope 含受保护路径,开发不能写它',['由用户走人工通道同步受保护文件,再把它移出 scope']);
|
|
29
|
+
if(DEFECT.has(code)||state==='unknown')return decide('escalate',true,`${code??state} 不是靠重试能解决的,可能是工作流缺陷`,
|
|
30
|
+
['保留原运行与记录,交维护者排查;不重派、不改写历史']);
|
|
31
|
+
// From here the record does not settle the exit; status does.
|
|
32
|
+
if(REVIEW_RETRY_CODES.includes(code))return decide('read_status',true,`审查没拿到结论(${code}),能否重派取决于额度和旧进程是否已退出`,[],
|
|
33
|
+
['宿主自动重派(status 给 resume 时)','abandon_review:确认旧审查进程已退出后授权'+APPROVAL,'额度用尽时 supersede 重开'+APPROVAL]);
|
|
34
|
+
if(DEVELOP_RETRY.has(code))return decide('read_status',false,`${code} 通常在本运行内还有重试或重做出口`,[],
|
|
35
|
+
['宿主自动继续(status 给 resume / advance 时)','develop_redo:先确认会话已停写,固定原状态目标'+APPROVAL,'名额用尽时 supersede 重开'+APPROVAL]);
|
|
36
|
+
if(code==='review_package_changed')return decide('read_status',false,'审查包与记录不符,能否继续取决于已记录的审查结论',[],
|
|
37
|
+
['按 status 继续','还原改动后继续','supersede 重开'+APPROVAL]);
|
|
38
|
+
if(code==='review_blocked'||code==='review_not_approved')return decide('read_status',true,`审查对交付本身给了结论(${code})`,[],
|
|
39
|
+
['status 给出的返工出口','supersede 重开'+APPROVAL]);
|
|
40
|
+
if(typeof code==='string'&&EXHAUSTED.test(code))return decide('read_status',true,`本运行的名额已用尽(${code})`,[],
|
|
41
|
+
['development_rework:严格绑定的情形下原运行仍可返工'+APPROVAL,'supersede 重开:先 inspect-history 取 supersedeTarget'+APPROVAL]);
|
|
42
|
+
if(state==='cancelled')return decide('read_status',true,'运行已取消',[],['supersede 重开'+APPROVAL,'把任务标 DROPPED'+APPROVAL]);
|
|
43
|
+
return decide('read_status',false,`决策表没有收录 ${code??state}`,[]);
|
|
44
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Commander phase 2: every job the commander sends out (a driver step, a check
|
|
2
|
+
// command, a Codex review, a wait) is registered with a deadline before it
|
|
3
|
+
// starts and marked done when its result is read. The ledger reports anything
|
|
4
|
+
// past its deadline, so a job that hangs is found on the next commander step
|
|
5
|
+
// instead of hours later. This registry is the commander's own record: it is
|
|
6
|
+
// kept under the CM home, never in specs (which would drift the approved
|
|
7
|
+
// manifest), and it grants nothing to the job it describes.
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import os from 'node:os';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import {createHash,randomUUID} from 'node:crypto';
|
|
12
|
+
|
|
13
|
+
export const REGISTRY_VERSION=1;
|
|
14
|
+
const MAX_DEADLINE_MINUTES=24*60;
|
|
15
|
+
const LINE_LIMIT=16*1024,FILE_LIMIT=8*1024*1024;
|
|
16
|
+
const RESOURCE=/^device:[A-Za-z0-9-]{1,64}$/;
|
|
17
|
+
const fail=code=>{throw Object.assign(new Error(code),{code});};
|
|
18
|
+
const home=()=>process.env.CM_WORKFLOW_HOME||path.join(os.homedir(),'.cm-workflow');
|
|
19
|
+
|
|
20
|
+
export function registryDir(specsDir){
|
|
21
|
+
const key=createHash('sha256').update(fs.realpathSync(specsDir)).digest('hex').slice(0,16);
|
|
22
|
+
return path.join(home(),'commander',key);
|
|
23
|
+
}
|
|
24
|
+
const fileOf=specsDir=>path.join(registryDir(specsDir),'dispatch.jsonl');
|
|
25
|
+
|
|
26
|
+
// Device ids are compared in one form everywhere.
|
|
27
|
+
export const normalizeResource=resource=>resource.startsWith('device:')?`device:${resource.slice(7).toUpperCase()}`:resource;
|
|
28
|
+
|
|
29
|
+
// Rows are read back strictly: a bad line is counted and never guessed at, and
|
|
30
|
+
// a done row only closes an id that was added.
|
|
31
|
+
function parseRegistry(text){
|
|
32
|
+
const jobs=new Map();let invalid=0;
|
|
33
|
+
for(const line of text.split('\n')){
|
|
34
|
+
if(!line)continue;
|
|
35
|
+
let row;try{row=JSON.parse(line);}catch{invalid++;continue;}
|
|
36
|
+
if(row?.v!==REGISTRY_VERSION||typeof row.id!=='string'||!Number.isFinite(Date.parse(row.at))){invalid++;continue;}
|
|
37
|
+
if(row.op==='add'&&!jobs.has(row.id)&&typeof row.label==='string'&&Number.isFinite(Date.parse(row.deadline)))
|
|
38
|
+
jobs.set(row.id,{id:row.id,label:row.label,startedAt:row.at,deadline:row.deadline,runId:row.runId??null,
|
|
39
|
+
resources:Array.isArray(row.resources)?row.resources.filter(r=>typeof r==='string'&&RESOURCE.test(r)).map(normalizeResource):[],
|
|
40
|
+
doneAt:null,outcome:null});
|
|
41
|
+
else if(row.op==='done'&&jobs.get(row.id)?.doneAt===null){const job=jobs.get(row.id);job.doneAt=row.at;job.outcome=row.outcome??null;}
|
|
42
|
+
else invalid++;
|
|
43
|
+
}
|
|
44
|
+
return {jobs,invalid,torn:text.length>0&&!text.endsWith('\n')};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// An unreadable file, bad rows or a torn tail are reported to the caller,
|
|
48
|
+
// which must not read them as "no jobs".
|
|
49
|
+
export function readRegistry(specsDir){
|
|
50
|
+
const file=fileOf(specsDir);
|
|
51
|
+
try{const stat=fs.lstatSync(file);if(!stat.isFile()||stat.size>FILE_LIMIT)return {jobs:new Map(),invalid:0,torn:false,error:'registry_unreadable'};
|
|
52
|
+
return {...parseRegistry(fs.readFileSync(file,'utf8')),error:null};}
|
|
53
|
+
catch(error){return {jobs:new Map(),invalid:0,torn:false,error:error.code==='ENOENT'?null:(error.code??'registry_unreadable')};}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// The registry's own health in one word, or null when it is sound.
|
|
57
|
+
export const registryProblem=registry=>registry.error??(registry.torn?'registry_torn':registry.invalid?`registry_invalid_rows:${registry.invalid}`:null);
|
|
58
|
+
|
|
59
|
+
// One writer at a time: an exclusive lock file around the whole read-check-
|
|
60
|
+
// append, released in finally. A stale lock is reported, never broken. Inside
|
|
61
|
+
// the lock the file must end on a line boundary: a torn tail would swallow the
|
|
62
|
+
// next row, so the append is refused and the bytes are left for inspection.
|
|
63
|
+
function withLock(specsDir,write){
|
|
64
|
+
const dir=registryDir(specsDir);fs.mkdirSync(dir,{recursive:true,mode:0o700});
|
|
65
|
+
const lock=path.join(dir,'dispatch.lock'),file=path.join(dir,'dispatch.jsonl');let fd;
|
|
66
|
+
try{fd=fs.openSync(lock,'wx',0o600);}catch(error){if(error.code==='EEXIST')fail('registry_locked');throw error;}
|
|
67
|
+
try{
|
|
68
|
+
let text='';try{text=fs.readFileSync(file,'utf8');}catch(error){if(error.code!=='ENOENT')throw error;}
|
|
69
|
+
if(text&&!text.endsWith('\n'))fail('registry_torn');
|
|
70
|
+
const registry=parseRegistry(text);
|
|
71
|
+
const row=write(registry),line=JSON.stringify(row)+'\n';
|
|
72
|
+
if(Buffer.byteLength(line)>LINE_LIMIT)fail('registry_row_too_large');
|
|
73
|
+
fs.appendFileSync(file,line,{mode:0o600});
|
|
74
|
+
return row;
|
|
75
|
+
}finally{fs.closeSync(fd);fs.rmSync(lock,{force:true});}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function addDispatch(specsDir,{label,deadlineMinutes,runId=null,resources=[],now=new Date().toISOString(),id=randomUUID()}){
|
|
79
|
+
if(typeof label!=='string'||!label.trim()||label.length>200||/[\r\n\0]/.test(label))fail('invalid_label');
|
|
80
|
+
if(!Number.isInteger(deadlineMinutes)||deadlineMinutes<1||deadlineMinutes>MAX_DEADLINE_MINUTES)fail('invalid_deadline');
|
|
81
|
+
if(runId!==null&&!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(runId))fail('invalid_run_id');
|
|
82
|
+
if(!Array.isArray(resources)||!resources.every(r=>typeof r==='string'&&RESOURCE.test(r)))fail('invalid_resource');
|
|
83
|
+
const start=Date.parse(now);if(!Number.isFinite(start))fail('invalid_now');
|
|
84
|
+
const deadline=new Date(start+deadlineMinutes*60000).toISOString();
|
|
85
|
+
withLock(specsDir,registry=>{
|
|
86
|
+
if(registry.jobs.has(id))fail('dispatch_exists');
|
|
87
|
+
return {v:REGISTRY_VERSION,op:'add',id,at:new Date(start).toISOString(),label:label.trim(),deadline,runId,resources:resources.map(normalizeResource)};
|
|
88
|
+
});
|
|
89
|
+
return {id,deadline};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// The eligibility check and the done row share one lock, so two finishers
|
|
93
|
+
// cannot both report success.
|
|
94
|
+
export function finishDispatch(specsDir,{id,outcome='done',now=new Date().toISOString()}){
|
|
95
|
+
if(!['done','failed','abandoned'].includes(outcome))fail('invalid_outcome');
|
|
96
|
+
const at=Date.parse(now);if(!Number.isFinite(at))fail('invalid_now');
|
|
97
|
+
withLock(specsDir,registry=>{
|
|
98
|
+
const job=registry.jobs.get(id);
|
|
99
|
+
if(!job)fail('unknown_dispatch');if(job.doneAt!==null)fail('dispatch_already_done');
|
|
100
|
+
return {v:REGISTRY_VERSION,op:'done',id,at:new Date(at).toISOString(),outcome};
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Open jobs, each marked overdue once its deadline has passed.
|
|
105
|
+
export function openDispatches(registry,now){
|
|
106
|
+
const nowMs=Date.parse(now);
|
|
107
|
+
return [...registry.jobs.values()].filter(job=>job.doneAt===null)
|
|
108
|
+
.map(job=>({...job,overdueMinutes:Math.max(0,Math.floor((nowMs-Date.parse(job.deadline))/60000)),
|
|
109
|
+
overdue:nowMs>Date.parse(job.deadline)}));
|
|
110
|
+
}
|