@aibyzero/cm-workflow 0.17.1 → 0.19.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 +242 -0
- package/README.md +20 -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/autonomy.mjs +152 -0
- 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 +56 -17
- 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 +115 -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 +581 -65
- 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 +5 -4
- 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 +21 -7
- package/scripts/cm-ai-admission.test.mjs +171 -3
- 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-autonomy.mjs +94 -0
- package/scripts/cm-autonomy.test.mjs +162 -0
- package/scripts/cm-challenge.test.mjs +61 -0
- package/scripts/cm-check-drive-files.mjs +1 -1
- package/scripts/cm-check-runtime.sh +60 -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 +581 -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 +323 -0
- package/scripts/cm-start-check.test.mjs +406 -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 +4 -0
- package/scripts/validate-test-cases.mjs +3 -2
- package/skills/cm-ai/SKILL.md +5 -2
- package/skills/cm-ai/references/N3-execute-task.md +1 -1
- 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 +82 -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 +14 -9
- package/skills/cm-prd/references/brownfield.md +8 -1
- package/skills/cm-prd/references/change-mode.md +8 -1
- package/skills/cm-prd/references/greenfield.md +4 -0
- package/skills/cm-prd/references/js-change-recovery.md +14 -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
|
@@ -7,13 +7,15 @@ import path from 'node:path';
|
|
|
7
7
|
import {createHash} from 'node:crypto';
|
|
8
8
|
import {loadConfig,resolveRole} from '../../../scripts/cm-workflow-config.mjs';
|
|
9
9
|
import {buildManifest} from '../../../scripts/cm-spec-manifest.mjs';
|
|
10
|
-
import {specLines,taskDeclarations,TASK_GRAMMAR,LEGACY_TASK_GRAMMAR} from '../spec-task-line.mjs';
|
|
10
|
+
import {specLines,taskDeclarations,TASK_GRAMMAR,LEGACY_TASK_GRAMMAR,recordedTaskGrammar} from '../spec-task-line.mjs';
|
|
11
11
|
import {inspectPrdReview} from '../../../scripts/cm-prd-review-gate.mjs';
|
|
12
12
|
import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
13
|
+
import {prdTreeFileDigest} from './tree-digest.mjs';
|
|
13
14
|
import {writeImmutableWorkflowFile} from '../cm-ai/review-evidence-file.mjs';
|
|
14
15
|
import {need,json,shape,digest} from '../cm-ai/effect-contract.mjs';
|
|
15
16
|
import {inspectPrdDraft} from './draft.mjs';
|
|
16
|
-
import {checkPrdDraftMechanics,inspectPrdContextCheck} from './self-check.mjs';
|
|
17
|
+
import {checkPrdDraftMechanics,inspectPrdContextCheck,PRD_SELF_CHECK_RULES} from './self-check.mjs';
|
|
18
|
+
import {recordPrdTaskScopes,approvedScopeExemptions,prdTaskScopeRecords} from './task-scope-record.mjs';
|
|
17
19
|
import {replaceSessionFile} from './session.mjs';
|
|
18
20
|
const names=['requirements.md','design.md','tasks.md','test-cases.json'];
|
|
19
21
|
const valid=name=>/^[1-9]\d*\.[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name);
|
|
@@ -29,7 +31,7 @@ export function inspectPrdChangeSnapshot(specs){
|
|
|
29
31
|
const file=`${relative}/${name}`,stat=fs.lstatSync(path.join(specs,file));
|
|
30
32
|
need(!stat.isSymbolicLink(),'prd_change_symlink');
|
|
31
33
|
if(stat.isDirectory())visit(file);
|
|
32
|
-
else
|
|
34
|
+
else tree.push({path:file,sha256:prdTreeFileDigest(specs,file)});
|
|
33
35
|
}};visit(directory);trees[directory]=tree;
|
|
34
36
|
for(const name of names){const file=`${directory}/${name}`,content=read(specs,file);
|
|
35
37
|
need(content!==null||name==='test-cases.json','prd_change_triad_missing');if(content!==null)files[file]=content;}
|
|
@@ -52,7 +54,19 @@ export function inspectPrdChangeSnapshot(specs){
|
|
|
52
54
|
if(bytes!==null)reviews[file]=sha(bytes);
|
|
53
55
|
}
|
|
54
56
|
const status=read(specs,'.cm-specs-status');
|
|
55
|
-
|
|
57
|
+
// Version 2 also binds the task-scope records (task-scope-record.mjs). A
|
|
58
|
+
// snapshot taken before it has no version and is compared in its own shape.
|
|
59
|
+
return json({directories,files,trees,reviews,status,snapshotVersion:2,scopeRecords:prdTaskScopeRecords(specs,directories)},4*1024*1024);
|
|
60
|
+
}
|
|
61
|
+
// The current specs still match a session's snapshot, in that snapshot's shape:
|
|
62
|
+
// version 2 as a whole; an unversioned one that carries scopeRecords (bound only
|
|
63
|
+
// when a record existed) still binds them; one without either binds neither.
|
|
64
|
+
function snapshotUnchanged(specs,before){
|
|
65
|
+
const now=inspectPrdChangeSnapshot(specs);
|
|
66
|
+
if(Object.hasOwn(before,'snapshotVersion'))return digest(now)===digest(before);
|
|
67
|
+
const {snapshotVersion,scopeRecords,...legacy}=now;
|
|
68
|
+
if(Object.hasOwn(before,'scopeRecords'))return digest({...legacy,scopeRecords})===digest(before);
|
|
69
|
+
return digest(legacy)===digest(before);
|
|
56
70
|
}
|
|
57
71
|
// Same declaration grammar as admission and N5 mark-done (spec-task-line.mjs):
|
|
58
72
|
// the approved original is read with the grammar its approval bound, the
|
|
@@ -67,13 +81,13 @@ function taskLines(source,grammar=TASK_GRAMMAR){return new Map(taskDeclarations(
|
|
|
67
81
|
// under another grammar.
|
|
68
82
|
function approvedGrammar(before){
|
|
69
83
|
try{const status=JSON.parse(before.status??'null');
|
|
70
|
-
return ['approved','awaiting_review'].includes(status?.status)
|
|
84
|
+
return ['approved','awaiting_review'].includes(status?.status)?recordedTaskGrammar(status.taskGrammar):LEGACY_TASK_GRAMMAR;}
|
|
71
85
|
catch{return LEGACY_TASK_GRAMMAR;}
|
|
72
86
|
}
|
|
73
87
|
function sourceLines(source){return specLines(source).map(line=>line.body);}
|
|
74
88
|
function userCases(files){return Object.entries(files).filter(([file])=>file.endsWith('/test-cases.json'))
|
|
75
89
|
.flatMap(([file,content])=>JSON.parse(content).cases.filter(c=>c.origin==='user').map(c=>({feature:file.split('/')[0],value:c})));}
|
|
76
|
-
export function inspectPrdChangeProposal(before,raw,selected,config){
|
|
90
|
+
export function inspectPrdChangeProposal(before,raw,selected,config,{rules=PRD_SELF_CHECK_RULES}={}){
|
|
77
91
|
const grammar=approvedGrammar(before);
|
|
78
92
|
shape(raw,['status','summary','features','removed']);need(raw.status==='draft'&&text(raw.summary)&&Array.isArray(raw.features)
|
|
79
93
|
&&Array.isArray(raw.removed)&&new Set(raw.removed).size===raw.removed.length,'prd_change_proposal_invalid');
|
|
@@ -125,7 +139,9 @@ export function inspectPrdChangeProposal(before,raw,selected,config){
|
|
|
125
139
|
const changedUserCases=userCases(before.files).filter(item=>selected.includes(item.feature)
|
|
126
140
|
&&!userCases(files).some(next=>next.feature===item.feature&&digest(next.value)===digest(item.value)));
|
|
127
141
|
const draft={summary:raw.summary,features,draftDigest:digest({summary:raw.summary,features})};
|
|
128
|
-
const mechanics=checkPrdDraftMechanics(draft,{change:true
|
|
142
|
+
const mechanics=checkPrdDraftMechanics(draft,{change:true,rules,
|
|
143
|
+
previous:Object.fromEntries(selected.map(directory=>[directory,before.files[`${directory}/tasks.md`]])),
|
|
144
|
+
...(rules>=3?{scopes:approvedScopeExemptions(before,features.map(feature=>feature.directory),grammar)}:{})});
|
|
129
145
|
need(mechanics.status==='mechanical_subset_passed','prd_change_mechanics_failed');
|
|
130
146
|
return json({...draft,mechanicalSelfCheck:mechanics,removed:raw.removed,files,changedUserCases,
|
|
131
147
|
proposalDigest:digest({before,raw,selected}),counts:{added:resultDirs.filter(dir=>!before.directories.includes(dir)).length,
|
|
@@ -133,7 +149,8 @@ export function inspectPrdChangeProposal(before,raw,selected,config){
|
|
|
133
149
|
preservedCompletedTasks:selected.reduce((n,dir)=>n+completedLines(before.files[`${dir}/tasks.md`],grammar).length,0)}},4*1024*1024);
|
|
134
150
|
}
|
|
135
151
|
|
|
136
|
-
export function createPrdChange({admission,runtime,call,restored=null,selected=[admission.feature],reason=null
|
|
152
|
+
export function createPrdChange({admission,runtime,call,restored=null,selected=[admission.feature],reason=null,
|
|
153
|
+
selfCheckRules=()=>PRD_SELF_CHECK_RULES}){
|
|
137
154
|
assertPrdBatchActive(admission.specs,selected);
|
|
138
155
|
const config=loadConfig({projectRoot:admission.project}),configDigest=digest(config);
|
|
139
156
|
const readUserCases=()=>admission.cases===null?null:{path:admission.cases,
|
|
@@ -141,7 +158,7 @@ export function createPrdChange({admission,runtime,call,restored=null,selected=[
|
|
|
141
158
|
let state=restored?structuredClone(restored):{stage:'ready',before:inspectPrdChangeSnapshot(admission.specs),selected,
|
|
142
159
|
messages:[],analysis:null,parts:null,proposal:null,contextCheck:null,round:0,confirmation:null,reason,configDigest,userCases:readUserCases()};
|
|
143
160
|
need(state.configDigest===configDigest,'prd_change_config_changed');
|
|
144
|
-
const current=()=>need(
|
|
161
|
+
const current=()=>need(snapshotUnchanged(admission.specs,state.before)
|
|
145
162
|
&&digest(loadConfig({projectRoot:admission.project}))===configDigest&&digest(readUserCases())===digest(state.userCases),'prd_change_inputs_changed');
|
|
146
163
|
const invoke=async(kind,payload,signal,role)=>{
|
|
147
164
|
const route=resolveRole(config,role,runtime);need(route.route_state==='current-runtime','prd_change_adapter_unavailable');
|
|
@@ -183,7 +200,7 @@ export function createPrdChange({admission,runtime,call,restored=null,selected=[
|
|
|
183
200
|
if(response.status==='question'){need(text(response.question),'prd_change_reply_invalid');state.messages.push({role:'user',text:answer},{role:'assistant',result:response});state.question=response.question;return this.status();}
|
|
184
201
|
if(response.status==='blocked'){state.stage='blocked';state.analysis=response;return this.status();}
|
|
185
202
|
if(phase==='change_tasks'){
|
|
186
|
-
const proposal=inspectPrdChangeProposal(state.before,response,state.selected,config);
|
|
203
|
+
const proposal=inspectPrdChangeProposal(state.before,response,state.selected,config,{rules:selfCheckRules()});
|
|
187
204
|
need(state.userCases===null||userCases(proposal.files).length>0,'prd_user_cases_missing');
|
|
188
205
|
this.checkParts(proposal.features,proposal.removed,state.parts,true);
|
|
189
206
|
state.proposal=proposal;state.round++;state.stage='change_check';
|
|
@@ -211,7 +228,8 @@ export function createPrdChange({admission,runtime,call,restored=null,selected=[
|
|
|
211
228
|
},
|
|
212
229
|
save(writeEnabled){
|
|
213
230
|
need(writeEnabled===true&&state.stage==='confirmed','prd_change_write_not_enabled');
|
|
214
|
-
const result=applyPrdChange({specs:admission.specs,before:state.before,proposal:state.proposal,selected:state.selected
|
|
231
|
+
const result=applyPrdChange({specs:admission.specs,before:state.before,proposal:state.proposal,selected:state.selected,
|
|
232
|
+
selfCheckRules:selfCheckRules()});
|
|
215
233
|
state.stage='awaiting_review';state.saved=result;return result;
|
|
216
234
|
},
|
|
217
235
|
};
|
|
@@ -239,12 +257,12 @@ export function assertPrdReviewsSettled(specs,selected,{requireSplit=false}={}){
|
|
|
239
257
|
if(requireSplit&&stage==='split')need(gate.outcome==='completed','prd_revision_original_split_required');
|
|
240
258
|
}
|
|
241
259
|
}
|
|
242
|
-
export function applyPrdChange({specs,before,proposal,selected}){
|
|
260
|
+
export function applyPrdChange({specs,before,proposal,selected,selfCheckRules}){
|
|
243
261
|
const reviews=path.join(specs,'.reviews');try{fs.mkdirSync(reviews,{mode:0o700});}catch(e){if(e.code!=='EEXIST')throw e;}
|
|
244
262
|
need(fs.realpathSync(reviews)===reviews,'prd_change_archive_invalid');
|
|
245
263
|
const name=`prd-change-${proposal.proposalDigest}.json`,archive={version:1,before,proposal,selected};
|
|
246
264
|
const existing=read(specs,`.reviews/${name}`);
|
|
247
|
-
if(existing===null){need(
|
|
265
|
+
if(existing===null){need(snapshotUnchanged(specs,before),'prd_change_inputs_changed');assertPrdReviewsSettled(specs,selected);}
|
|
248
266
|
const archiveBytes=JSON.stringify(archive)+'\n';
|
|
249
267
|
if(existing===null)replaceSessionFile(specs,`.reviews/${name}`,null,archiveBytes);
|
|
250
268
|
else need(existing===archiveBytes,'prd_change_archive_changed');
|
|
@@ -266,7 +284,7 @@ export function applyPrdChange({specs,before,proposal,selected}){
|
|
|
266
284
|
for(const dir of actualDirs){
|
|
267
285
|
for(const filename of names)need(!fs.existsSync(path.join(specs,dir,filename))||Object.hasOwn(before.files,`${dir}/${filename}`)||Object.hasOwn(expected,`${dir}/${filename}`),'prd_change_inventory_conflict');
|
|
268
286
|
for(const row of before.trees[dir]??[])if(!names.includes(row.path.slice(dir.length+1)))
|
|
269
|
-
need(
|
|
287
|
+
need(prdTreeFileDigest(specs,row.path)===row.sha256,'prd_change_asset_changed');
|
|
270
288
|
}
|
|
271
289
|
const status=read(specs,'.cm-specs-status');
|
|
272
290
|
if(status!==before.status){const value=JSON.parse(status);need(value.status==='awaiting_review'&&value.revisionDigest===proposal.proposalDigest,'prd_change_status_conflict');}
|
|
@@ -276,8 +294,11 @@ export function applyPrdChange({specs,before,proposal,selected}){
|
|
|
276
294
|
const statusFile='.cm-specs-status',invalidated=JSON.stringify({status:'awaiting_review',revisionDigest:proposal.proposalDigest,
|
|
277
295
|
at:new Date().toISOString(),features:newDirs,specFiles:[],testCases:[],
|
|
278
296
|
// Carry the last approval's tasks.md grammar to the next approval.
|
|
279
|
-
...(approvedGrammar(before)
|
|
297
|
+
...(approvedGrammar(before)!==LEGACY_TASK_GRAMMAR?{taskGrammar:approvedGrammar(before)}:{})})+'\n';
|
|
280
298
|
if(read(specs,statusFile)===before.status)replaceSessionFile(specs,statusFile,before.status,invalidated);
|
|
299
|
+
// Before any spec byte: later re-checks keep the scopes this proposal carries.
|
|
300
|
+
current();recordPrdTaskScopes(specs,proposal.features,
|
|
301
|
+
approvedScopeExemptions(before,proposal.features.map(feature=>feature.directory),approvedGrammar(before)),{selfCheckRules});
|
|
281
302
|
for(const [file,content] of Object.entries(expected)){
|
|
282
303
|
if(!selected.includes(file.split('/')[0])&&oldDirs.includes(file.split('/')[0]))continue;
|
|
283
304
|
current();const dir=path.dirname(path.join(specs,file));try{fs.mkdirSync(dir,{mode:0o700});}catch(e){if(e.code!=='EEXIST')throw e;}
|
|
@@ -299,7 +320,7 @@ export function applyPrdChange({specs,before,proposal,selected}){
|
|
|
299
320
|
need(digest(fs.readdirSync(specs).filter(dir=>/^\d+\./.test(dir)).sort())===digest(newDirs),'prd_change_inventory_conflict');
|
|
300
321
|
const result={status:'awaiting_review',at:JSON.parse(read(specs,statusFile)).at,revisionDigest:proposal.proposalDigest,
|
|
301
322
|
features:newDirs,specFiles,testCases:specFiles.filter(item=>item.path.endsWith('/test-cases.json')),
|
|
302
|
-
...(approvedGrammar(before)
|
|
323
|
+
...(approvedGrammar(before)!==LEGACY_TASK_GRAMMAR?{taskGrammar:approvedGrammar(before)}:{})};
|
|
303
324
|
replaceSessionFile(specs,statusFile,read(specs,statusFile),JSON.stringify(result)+'\n');
|
|
304
325
|
return json({...result,archive:`.reviews/${name}`,counts:proposal.counts,priorReviews:'retained_as_history_not_current_approval',
|
|
305
326
|
next:'human_review_then_explicit_cm_ai',completionAuthorized:false});
|
|
@@ -10,6 +10,7 @@ import {writeImmutableWorkflowFile} from '../cm-ai/review-evidence-file.mjs';
|
|
|
10
10
|
import {need,json,digest} from '../cm-ai/effect-contract.mjs';
|
|
11
11
|
import {inspectPrdFindings} from './review-findings.mjs';
|
|
12
12
|
import {replacePrdDocument} from './review-correction.mjs';
|
|
13
|
+
import {recordPrdTaskScopes} from './task-scope-record.mjs';
|
|
13
14
|
|
|
14
15
|
export function savePrdDraft(input){
|
|
15
16
|
assertPrdBatchActive(input.specs);
|
|
@@ -22,7 +23,9 @@ export function savePrdDesign({specs,writeEnabled,getDraft}){
|
|
|
22
23
|
}
|
|
23
24
|
// Only the analysis owner can supply the original saved promotion and the
|
|
24
25
|
// self-checked successor. Requirements/design are never rewritten here.
|
|
25
|
-
|
|
26
|
+
// `selfCheckRules` (every save): the saving operation's rule, kept in the task-scope
|
|
27
|
+
// record (task-scope-record.mjs) for the later re-checks of these files.
|
|
28
|
+
export function savePrdPromotedDraft({specs,writeEnabled,getDraft,getOriginal,selfCheckRules}){
|
|
26
29
|
assertPrdBatchActive(specs);
|
|
27
30
|
need(writeEnabled===true&&typeof getDraft==='function'&&typeof getOriginal==='function','prd_spec_save_not_enabled');
|
|
28
31
|
const draft=json(getDraft(),256*1024),original=json(getOriginal(),256*1024);
|
|
@@ -31,7 +34,7 @@ export function savePrdPromotedDraft({specs,writeEnabled,getDraft,getOriginal}){
|
|
|
31
34
|
if(draft.features.every(feature=>readCmInitSource(specs,`.reviews/prd-${feature.name}-split-disposition.json`)!==null)){
|
|
32
35
|
for(const feature of draft.features)need(inspectPrdFindings({specs,stage:'split',feature:feature.directory}).gate.outcome==='completed',
|
|
33
36
|
'prd_spec_save_split_disposition_required');
|
|
34
|
-
return savePrdDraft({specs,writeEnabled,getDraft});
|
|
37
|
+
return savePrdDraft({specs,writeEnabled,getDraft,selfCheckRules});
|
|
35
38
|
}
|
|
36
39
|
const files=[];
|
|
37
40
|
for(const feature of draft.features){
|
|
@@ -59,6 +62,7 @@ export function savePrdPromotedDraft({specs,writeEnabled,getDraft,getOriginal}){
|
|
|
59
62
|
need(readCmInitSource(specs,`.reviews/prd-${feature.name}-split${suffix}`)===null,'prd_promoted_save_split_started');
|
|
60
63
|
};
|
|
61
64
|
current();
|
|
65
|
+
recordPrdTaskScopes(specs,draft.features,{},{selfCheckRules});
|
|
62
66
|
const reviews=path.join(specs,'.reviews');
|
|
63
67
|
const name=`prd-task-revision-${original.draftDigest}.md`;
|
|
64
68
|
const bytes=Buffer.from('# Saved draft task revision\n\nNot approval. Original and successor bytes for explicit recovery.\n```json\n'
|
|
@@ -81,7 +85,7 @@ export function savePrdPromotedDraft({specs,writeEnabled,getDraft,getOriginal}){
|
|
|
81
85
|
}catch{return json({status:'draft_save_unknown',archive:`.reviews/${name}`,observedSaved:written,
|
|
82
86
|
next:'inspect_archive_and_files_before_explicit_resume',completionAuthorized:false});}
|
|
83
87
|
}
|
|
84
|
-
function saveDocuments({specs,writeEnabled,getDraft},designOnly){
|
|
88
|
+
function saveDocuments({specs,writeEnabled,getDraft,selfCheckRules},designOnly){
|
|
85
89
|
need(writeEnabled===true&&typeof getDraft==='function','prd_spec_save_not_enabled');
|
|
86
90
|
need(path.isAbsolute(specs)&&fs.realpathSync(specs)===specs,'prd_spec_save_root_invalid');
|
|
87
91
|
const draft=json(getDraft(),256*1024);
|
|
@@ -111,6 +115,8 @@ function saveDocuments({specs,writeEnabled,getDraft},designOnly){
|
|
|
111
115
|
need(before===null||before.equals(file.bytes),'prd_spec_save_conflict');
|
|
112
116
|
if(before!==null)permissions(path.join(specs,file.relative));
|
|
113
117
|
}
|
|
118
|
+
// Before any spec byte: later re-checks of these files read this record.
|
|
119
|
+
if(!designOnly)recordPrdTaskScopes(specs,draft.features,{},{selfCheckRules});
|
|
114
120
|
const saved=[];
|
|
115
121
|
try{
|
|
116
122
|
for(const file of files){
|
|
@@ -167,7 +173,7 @@ export function acceptedPrdDraftForSave(specs,draft){
|
|
|
167
173
|
|
|
168
174
|
// Save only the owner-recorded self-check revision. The immutable record precedes
|
|
169
175
|
// replacement, so a partial write can resume against exactly the same two versions.
|
|
170
|
-
function saveSelfCheckRevision({specs,writeEnabled,getDraft,getSelfCheckRevision,onSelfCheckRevisionSaved}){
|
|
176
|
+
function saveSelfCheckRevision({specs,writeEnabled,getDraft,getSelfCheckRevision,onSelfCheckRevisionSaved,selfCheckRules}){
|
|
171
177
|
need(writeEnabled===true&&typeof onSelfCheckRevisionSaved==='function','prd_spec_save_not_enabled');
|
|
172
178
|
const revision=inspectPrdSelfCheckRevision(getSelfCheckRevision()),draft=json(getDraft(),256*1024);
|
|
173
179
|
const changed=revision.features.filter(f=>f.changedFiles.length);
|
|
@@ -187,7 +193,7 @@ function saveSelfCheckRevision({specs,writeEnabled,getDraft,getSelfCheckRevision
|
|
|
187
193
|
};
|
|
188
194
|
// Completed split receipts own the latest saved version. Never roll them back.
|
|
189
195
|
if(draft.features.some(f=>readCmInitSource(specs,`.reviews/prd-${f.name}-split-disposition.json`)!==null))
|
|
190
|
-
return saveDocuments({specs,writeEnabled,getDraft},false);
|
|
196
|
+
return saveDocuments({specs,writeEnabled,getDraft,selfCheckRules},false);
|
|
191
197
|
current();
|
|
192
198
|
need(draft.draftDigest===revision.draftDigest,'prd_self_check_revision_binding_changed');
|
|
193
199
|
for(const feature of draft.features)for(const suffix of ['-r1.md','-r2.md','-dispatch.json','-disposition.json'])
|
|
@@ -204,12 +210,13 @@ function saveSelfCheckRevision({specs,writeEnabled,getDraft,getSelfCheckRevision
|
|
|
204
210
|
for(const feature of changed)writeImmutableWorkflowFile({reviewsDir:reviews,
|
|
205
211
|
name:path.basename(prdSelfCheckRevisionPath(feature.directory)),bytes:Buffer.from(JSON.stringify(revision)+'\n'),
|
|
206
212
|
validate:file=>need((fs.lstatSync(file).mode&0o777)===0o600,'prd_spec_save_permissions')});
|
|
213
|
+
current();recordPrdTaskScopes(specs,draft.features,{},{selfCheckRules});
|
|
207
214
|
try{
|
|
208
215
|
for(const file of files){
|
|
209
216
|
current();if(readCmInitSource(specs,file.relative).equals(Buffer.from(file.content)))continue;
|
|
210
217
|
replacePrdDocument({specs,relative:file.relative,content:file.content,current});
|
|
211
218
|
}
|
|
212
|
-
const result=saveDocuments({specs,writeEnabled,getDraft},false);
|
|
219
|
+
const result=saveDocuments({specs,writeEnabled,getDraft,selfCheckRules},false);
|
|
213
220
|
if(result.status==='draft_saved')onSelfCheckRevisionSaved();return result;
|
|
214
221
|
}catch{return json({status:'draft_save_unknown',draftDigest:draft.draftDigest,
|
|
215
222
|
next:'inspect_recorded_self_check_revision_before_explicit_resume',completionAuthorized:false});}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import {need,shape,json,digest} from '../cm-ai/effect-contract.mjs';
|
|
4
4
|
import {validateTestCases} from '../../../scripts/validate-test-cases.mjs';
|
|
5
|
-
import {needPrd,prdDraftJson} from './validation-reason.mjs';
|
|
5
|
+
import {needPrd,prdDraftJson,PRD_DRAFT_LIMIT} from './validation-reason.mjs';
|
|
6
6
|
export function prdFeatureInventory(specs){
|
|
7
7
|
return fs.readdirSync(specs).filter(name=>/^\d+\./.test(name)).sort();
|
|
8
8
|
}
|
|
@@ -37,8 +37,36 @@ export function inspectPrdDesignDraft(raw,{nextIndex}){
|
|
|
37
37
|
checks:'design_structure_only',remaining:['design_review','design_disposition','task_generation','spec_self_check','split_review','human_approval'],
|
|
38
38
|
writeAuthorized:false,completionAuthorized:false});
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
// tasks_after_design: a reply may leave out a feature's requirements.md/design.md,
|
|
41
|
+
// which then means byte-identical to the accepted design and is restored here in
|
|
42
|
+
// the accepted order, so the 64 KiB reply limit counts only tasks and test cases.
|
|
43
|
+
// Anything else (another feature list or name, a repeated document path, a status
|
|
44
|
+
// other than draft) is returned unchanged for the original checks to refuse.
|
|
45
|
+
export function withAcceptedPrdDocuments(reply,acceptedDesign){
|
|
46
|
+
if(acceptedDesign==null||reply?.status!=='draft'||!Array.isArray(reply.features)
|
|
47
|
+
||reply.features.length!==acceptedDesign.features.length)return {reply,limit:PRD_DRAFT_LIMIT};
|
|
48
|
+
const features=reply.features.map((feature,index)=>{
|
|
49
|
+
const accepted=acceptedDesign.features[index];
|
|
50
|
+
if(feature?.name!==accepted.name||!Array.isArray(feature.documents)
|
|
51
|
+
||new Set(feature.documents.map(doc=>doc?.path)).size!==feature.documents.length)return feature;
|
|
52
|
+
const given=path=>feature.documents.find(doc=>doc?.path===path);
|
|
53
|
+
return {...feature,documents:[...accepted.documents.map(doc=>given(doc.path)??{path:doc.path,content:doc.content}),
|
|
54
|
+
...feature.documents.filter(doc=>!accepted.documents.some(item=>item.path===doc?.path))]};
|
|
55
|
+
});
|
|
56
|
+
return {reply:{...reply,features},
|
|
57
|
+
limit:PRD_DRAFT_LIMIT+Buffer.byteLength(JSON.stringify(acceptedDesign.features.map(feature=>feature.documents)))};
|
|
58
|
+
}
|
|
59
|
+
// A driver's preflight of a draft reply, in the host's order: the 64 KiB limit on
|
|
60
|
+
// the reply as sent first, then the draft checks on the draft with accepted
|
|
61
|
+
// documents restored. The revision reason is an envelope field, not draft schema.
|
|
62
|
+
export function inspectPrdDraftReply(value,acceptedDesign,options){
|
|
63
|
+
prdDraftJson(value);
|
|
64
|
+
const assembled=withAcceptedPrdDocuments(value,acceptedDesign);
|
|
65
|
+
const {selfCheckRevisionReason,...draftReply}=assembled.reply;
|
|
66
|
+
return inspectPrdDraft(draftReply,{...options,limit:assembled.limit});
|
|
67
|
+
}
|
|
68
|
+
export function inspectPrdDraft(raw,{nextIndex,generateCases,userCasesProvided,limit=PRD_DRAFT_LIMIT}){
|
|
69
|
+
const reply=prdDraftJson(raw,limit);shape(reply,['status','summary','features']);
|
|
42
70
|
need(reply.status==='draft'&&typeof reply.summary==='string'&&reply.summary.trim()
|
|
43
71
|
&&Array.isArray(reply.features)&&reply.features.length>0,'prd_draft_invalid');
|
|
44
72
|
const seen=new Set(),features=[];let userCases=0;
|
|
@@ -4,7 +4,8 @@ import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
|
4
4
|
import {need,shape,digest,json} from '../cm-ai/effect-contract.mjs';
|
|
5
5
|
import {correctionCheckStore} from './correction-check.mjs';
|
|
6
6
|
import {inspectPrdDispositionPlan} from './disposition-plan.mjs';
|
|
7
|
-
import {
|
|
7
|
+
import {matchesPrdDraftMechanics,inspectPrdContextCheck} from './self-check.mjs';
|
|
8
|
+
import {prdTaskScopeOptions} from './task-scope-record.mjs';
|
|
8
9
|
const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
9
10
|
|
|
10
11
|
export function inspectPrdFailedCorrection({specs,receipt}){
|
|
@@ -31,8 +32,23 @@ export function inspectPrdFailedCorrection({specs,receipt}){
|
|
|
31
32
|
&&draft.features[0].directory===feature&&draft.features[0].name===receipt.feature,'prd_failed_check_binding');
|
|
32
33
|
const artifacts=draft.features[0].documents.map(doc=>({path:`${feature}/${doc.path}`,sha256:sha(Buffer.from(doc.content))}));
|
|
33
34
|
need(digest(artifacts)===digest(receipt.artifacts),'prd_failed_check_binding');
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
// The recorded report must be exactly what one known rule version produces.
|
|
36
|
+
const mechanical=draft.mechanicalSelfCheck;
|
|
37
|
+
// Under the scope policy bound into the check input, not the current record.
|
|
38
|
+
const scopes=draft.taskScopes;
|
|
39
|
+
need(scopes===undefined||(scopes!==null&&typeof scopes==='object'&&Object.keys(scopes).every(key=>key===feature)
|
|
40
|
+
&&Array.isArray(scopes[feature]?.exempt)&&scopes[feature].exempt.every(id=>typeof id==='string')
|
|
41
|
+
&&Object.keys(scopes[feature]).length===1),'prd_failed_check_binding');
|
|
42
|
+
// Likewise the rule-4 additions a recorded rule 4 bound (task-scope-record.mjs).
|
|
43
|
+
const sessionTasks=draft.sessionTasks;
|
|
44
|
+
need(sessionTasks===undefined||Array.isArray(sessionTasks)&&sessionTasks.length===1&&sessionTasks[0]===feature,
|
|
45
|
+
'prd_failed_check_binding');
|
|
46
|
+
const bound={...(scopes===undefined?{}:{scopes}),...(sessionTasks===undefined?{}:{sessionTasks})};
|
|
47
|
+
// Evidence recorded before the policy joined the check input has neither:
|
|
48
|
+
// it ran either without a scope record or under the record still on disk.
|
|
49
|
+
need(Object.keys(bound).length?matchesPrdDraftMechanics(draft,mechanical,bound)
|
|
50
|
+
:matchesPrdDraftMechanics(draft,mechanical)||matchesPrdDraftMechanics(draft,mechanical,prdTaskScopeOptions(specs,feature)),
|
|
51
|
+
'prd_failed_check_binding');
|
|
36
52
|
const stored=correctionCheckStore({specs,feature,packageDigest:review.packageDigest,inputDigest:digest(proof.input)}).inspect();
|
|
37
53
|
need(stored.status==='recorded','prd_failed_check_evidence_required');
|
|
38
54
|
need(digest(stored.result)===proof.resultDigest,'prd_failed_check_result_changed');
|
|
@@ -77,6 +77,9 @@ export function replacePrdInputs({session,sessionId,approved,reason,successorSpe
|
|
|
77
77
|
if(required){const gate=inspectPrdReview({stage,feature:slug,evidence:path.join(base,prefix+'-r1.md'),receipt:path.join(base,prefix+'-disposition.json')});
|
|
78
78
|
if(gate.outcome!=='completed')unreviewed.push({feature,stage,outcome:gate.outcome});}
|
|
79
79
|
}
|
|
80
|
+
// The save's task-scope record decides how later re-checks run; keep it with the reviews.
|
|
81
|
+
const scopeRecord=`.reviews/prd-${slug}-task-scope.json`,scopeBytes=readCmInitSource(entry.specs,scopeRecord);
|
|
82
|
+
if(scopeBytes!==null)reviewRecords.push({path:scopeRecord,sha256:sha(scopeBytes),bytes:scopeBytes.toString('base64')});
|
|
80
83
|
}
|
|
81
84
|
const body=json({version:1,status:'inputs_replaced',sessionId,reason,request,oldInputs,replacementInputs,
|
|
82
85
|
successor:{sessionId:successorSessionId,entry:nextEntry,runtime,inputs:inputs(nextEntry)},features,reviewRecords,unreviewed,sessionState},limit);
|
|
@@ -7,6 +7,7 @@ import {TextDecoder} from 'node:util';
|
|
|
7
7
|
import {inspectPrdFindings} from './review-findings.mjs';
|
|
8
8
|
import {inspectPrdDispositionPlan} from './disposition-plan.mjs';
|
|
9
9
|
import {checkPrdDraftMechanics} from './self-check.mjs';
|
|
10
|
+
import {prdTaskScopeOptions} from './task-scope-record.mjs';
|
|
10
11
|
import {inspectPrdDesignDraft} from './draft.mjs';
|
|
11
12
|
import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
12
13
|
import {writeReviewEvidence} from '../cm-ai/review-evidence-file.mjs';
|
|
@@ -18,7 +19,7 @@ function readCorrectionFile(specs,file){
|
|
|
18
19
|
const bytes=readCmInitSource(specs,file);
|
|
19
20
|
need(bytes!==null&&(fs.lstatSync(path.join(specs,file)).mode&0o777)===0o600,'prd_correction_file_invalid');return bytes;
|
|
20
21
|
}
|
|
21
|
-
function inspectProposal(review,proposal){
|
|
22
|
+
function inspectProposal(specs,review,proposal){
|
|
22
23
|
shape(proposal,['decisions','documents']);need(Array.isArray(proposal.documents),'prd_correction_documents_invalid');
|
|
23
24
|
const after=proposal.documents.map(doc=>{
|
|
24
25
|
shape(doc,['path','content']);need(typeof doc.content==='string'&&doc.content.trim(),'prd_correction_content_invalid');
|
|
@@ -33,7 +34,8 @@ function inspectProposal(review,proposal){
|
|
|
33
34
|
inspectPrdDesignDraft({status:'design',summary:'Original design correction',features:[{name,documents}]},
|
|
34
35
|
{nextIndex:Number(feature.split('.')[0])});
|
|
35
36
|
}else{
|
|
36
|
-
const mechanics=checkPrdDraftMechanics({draftDigest:digest(after),features:[{directory:feature,name,documents}]}
|
|
37
|
+
const mechanics=checkPrdDraftMechanics({draftDigest:digest(after),features:[{directory:feature,name,documents}]},
|
|
38
|
+
prdTaskScopeOptions(specs,feature));
|
|
37
39
|
need(mechanics.status==='mechanical_subset_passed','prd_correction_mechanics_failed');
|
|
38
40
|
}
|
|
39
41
|
return {after,plan};
|
|
@@ -60,7 +62,7 @@ export function createPrdCorrectionOwner({correct}){
|
|
|
60
62
|
need(!attempts.has(key),'prd_correction_already_attempted');attempts.add(key);
|
|
61
63
|
const proposal=json(await correct(json({review,documents:before,
|
|
62
64
|
instructions:'Resolve only these original findings. Return {decisions:[{id,status:applied|escalated,evidence:[reason],changedPaths:[path]}],documents:[{path,content}]} with the complete unchanged path inventory. Escalate disagreement or unprovable changes; do not invent human approval. design may change design.md only. Do not write files, change task status, add/remove files, call another reviewer/provider or retry. Corrected split specs will go through the original self-check.'}),signal),256*1024);
|
|
63
|
-
need(!signal.aborted,'cancelled');const {after,plan}=inspectProposal(review,proposal);
|
|
65
|
+
need(!signal.aborted,'cancelled');const {after,plan}=inspectProposal(specs,review,proposal);
|
|
64
66
|
const current=()=>{
|
|
65
67
|
const latest=inspectPrdFindings({specs,stage,feature});
|
|
66
68
|
need(latest.packageDigest===review.packageDigest&&latest.gate.outcome==='resume_disposition'
|
|
@@ -127,7 +129,7 @@ function loadCorrection({specs,stage,feature}){
|
|
|
127
129
|
&&Buffer.from(item.content).toString('utf8')===item.content&&sha(Buffer.from(item.content))===item.sha256,
|
|
128
130
|
'prd_correction_archive_original_mismatch');seen.add(item.path);
|
|
129
131
|
}
|
|
130
|
-
const {after,plan}=inspectProposal(review,value.proposal),states=[];
|
|
132
|
+
const {after,plan}=inspectProposal(specs,review,value.proposal),states=[];
|
|
131
133
|
// V6 (O04): reconcile each reviewed file against the archive: the corrected
|
|
132
134
|
// bytes continue, the original bytes are still to be written, anything else
|
|
133
135
|
// is a conflict for a person (listed with all three digests, never overwritten).
|
|
@@ -9,6 +9,7 @@ import {recordPrdReview,inspectPrdReview} from '../../../scripts/cm-prd-review-g
|
|
|
9
9
|
import {need,json,digest} from '../cm-ai/effect-contract.mjs';
|
|
10
10
|
import {inspectPrdDispositionPlan} from './disposition-plan.mjs';
|
|
11
11
|
import {checkPrdDraftMechanics,inspectPrdContextCheck} from './self-check.mjs';
|
|
12
|
+
import {prdTaskScopeOptions} from './task-scope-record.mjs';
|
|
12
13
|
import {correctionCheckStore} from './correction-check.mjs';
|
|
13
14
|
const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
14
15
|
|
|
@@ -81,7 +82,12 @@ export function createPrdDispositionOwner({checkContext,canRecoverRecorded=()=>f
|
|
|
81
82
|
content:new TextDecoder('utf-8',{fatal:true,ignoreBOM:true}).decode(readCmInitSource(input.specs,item.path))}));
|
|
82
83
|
let draft={draftDigest:digest(input.artifacts),features:[{directory:input.feature,
|
|
83
84
|
name:input.feature.replace(/^\d+\./,''),documents}]};
|
|
84
|
-
|
|
85
|
+
// The scope options join the check input, so the recorded result keeps the
|
|
86
|
+
// policy it was computed under even if a later change rewrites the record.
|
|
87
|
+
const scopeOptions=prdTaskScopeOptions(input.specs,input.feature);
|
|
88
|
+
if(scopeOptions.scopes)draft.taskScopes=scopeOptions.scopes;
|
|
89
|
+
if(scopeOptions.sessionTasks)draft.sessionTasks=scopeOptions.sessionTasks;
|
|
90
|
+
draft.mechanicalSelfCheck=checkPrdDraftMechanics(draft,scopeOptions);
|
|
85
91
|
draft=json(draft,256*1024);
|
|
86
92
|
const review=inspectPrdFindings({specs:input.specs,stage:input.stage,feature:input.feature});
|
|
87
93
|
const checkInput={draft,decisions:input.decisions,review};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {createHash} from 'node:crypto';
|
|
3
3
|
import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
4
4
|
import {need,json,digest,shape} from '../cm-ai/effect-contract.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import {matchesPrdDraftMechanics,inspectPrdContextCheck} from './self-check.mjs';
|
|
6
6
|
const sha=value=>createHash('sha256').update(value).digest('hex');
|
|
7
7
|
const names=['requirements.md','design.md'];
|
|
8
8
|
export const prdSelfCheckRevisionPath=feature=>{
|
|
@@ -35,7 +35,7 @@ export function inspectPrdSelfCheckRevision(value){
|
|
|
35
35
|
need(failedDraft.draftDigest===digest({summary:failedDraft.summary,features:failedDraft.features})
|
|
36
36
|
&&failedSelfCheck.draftDigest===failedDraft.draftDigest&&digest(failedSelfCheck)===revision.failedSelfCheckDigest
|
|
37
37
|
&&digest(failedDraft.mechanicalSelfCheck)===digest(failedSelfCheck.mechanical)
|
|
38
|
-
&&
|
|
38
|
+
&&matchesPrdDraftMechanics(failedDraft,failedSelfCheck.mechanical),'prd_self_check_revision_binding_changed');
|
|
39
39
|
let failed=failedSelfCheck.mechanical.status==='failed';
|
|
40
40
|
if(failedSelfCheck.contextCheck!==null){
|
|
41
41
|
const {draftDigest,features}=failedSelfCheck.contextCheck;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Mechanical subset of the existing Step 10.5 checklist. No semantic approval.
|
|
2
|
-
import {parseFeatureTaskText,validDependencies,declaredAcceptanceIds} from '../cm-ai/cm-ai-admission.mjs';
|
|
2
|
+
import {parseFeatureTaskText,validDependencies,declaredAcceptanceIds,DEPENDENCY} from '../cm-ai/cm-ai-admission.mjs';
|
|
3
|
+
import {specLines,taskLines,TASK_GRAMMAR} from '../spec-task-line.mjs';
|
|
4
|
+
import {parseTaskScopes,BOOTSTRAP_FEATURE,sessionTaskProblem,sessionTaskReason} from '../task-scope.mjs';
|
|
3
5
|
import {validateTestCases} from '../../../scripts/validate-test-cases.mjs';
|
|
4
|
-
import {json,shape,need} from '../cm-ai/effect-contract.mjs';
|
|
6
|
+
import {json,shape,need,digest} from '../cm-ai/effect-contract.mjs';
|
|
5
7
|
|
|
6
8
|
export function inspectPrdContextCheck(raw,draft){
|
|
7
9
|
const report=json(raw,64*1024);shape(report,['draftDigest','features']);
|
|
@@ -39,13 +41,86 @@ function outsideFences(source){
|
|
|
39
41
|
return fence===null?line:'';
|
|
40
42
|
}).join('\n');
|
|
41
43
|
}
|
|
42
|
-
|
|
44
|
+
// Rule 2 adds checks the parser alone cannot make; rule 1 is the original subset.
|
|
45
|
+
// Only a fresh draft round and a change proposal opt into rule 2. Every re-check
|
|
46
|
+
// of material that may predate it (corrections, dispositions, summary) stays on
|
|
47
|
+
// rule 1, and a recorded report is accepted under either rule
|
|
48
|
+
// (matchesPrdDraftMechanics), so sessions started before the upgrade resume as before.
|
|
49
|
+
// Rule 3 adds per-task file scope (task-scope.mjs): every new task must name the
|
|
50
|
+
// files it may change, so parallel work is decided from the approved tasks.md
|
|
51
|
+
// instead of a session's guess. Tasks an approved tasks.md already had may stay
|
|
52
|
+
// without scope (they simply run serially).
|
|
53
|
+
// Rule 4 reads tasks.md as task grammar 3 (`开发: 会话`) and adds the session-task checks.
|
|
54
|
+
export const PRD_SELF_CHECK_RULES=4;
|
|
55
|
+
// Every rule a session, an operation or a recorded report may carry. Earlier rules
|
|
56
|
+
// stay listed explicitly so raising the current one never drops them.
|
|
57
|
+
export const PRD_SELF_CHECK_RULE_VERSIONS=Object.freeze([...new Set([PRD_SELF_CHECK_RULES,3,2,1])]);
|
|
58
|
+
// Task- or dependency-looking lines the parser skips: a task written this way
|
|
59
|
+
// would silently drop out of execution.
|
|
60
|
+
const TASK_LIKE=/^\s*-\s*\[[^\]]*\]\s+(?:~~)?T-/,DEPENDENCY_LIKE=/^\s*-\s*T-\S*\s+依赖(?:\s|$)/;
|
|
61
|
+
function malformedLines(source){
|
|
62
|
+
const counts=new Map();
|
|
63
|
+
for(const line of taskLines(source)){
|
|
64
|
+
if(line.fenced||line.declaration||DEPENDENCY.test(line.body))continue;
|
|
65
|
+
const code=TASK_LIKE.test(line.body)?'tasks_invalid':DEPENDENCY_LIKE.test(line.body)?'dependencies_invalid':null;
|
|
66
|
+
if(code)counts.set(line.body,{code,count:(counts.get(line.body)?.count??0)+1});
|
|
67
|
+
}
|
|
68
|
+
return counts;
|
|
69
|
+
}
|
|
70
|
+
// Unfenced dependency lines as task -> exact prerequisite list.
|
|
71
|
+
function dependencyLines(source){
|
|
72
|
+
const result=new Map();
|
|
73
|
+
for(const line of specLines(source)){
|
|
74
|
+
const match=line.fenced?null:line.body.match(DEPENDENCY);
|
|
75
|
+
if(match&&!result.has(match[1]))result.set(match[1],match[2].split(/[,,]/).map(value=>value.trim()).filter(Boolean).join(','));
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
// Under rule 2 a change proposal is strict only for what it adds: a malformed line
|
|
80
|
+
// is exempt up to the number of times the approved tasks.md already had it, and a
|
|
81
|
+
// dependency on a dropped task is exempt when the approved file had that same line.
|
|
82
|
+
function strictFindings(source,previous,parsed){
|
|
83
|
+
const codes=new Set(),before=previous===null?new Map():malformedLines(previous);
|
|
84
|
+
for(const [body,{code,count}] of malformedLines(source))if(count>(before.get(body)?.count??0))codes.add(code);
|
|
85
|
+
if(!parsed.error){
|
|
86
|
+
const dropped=new Set(parsed.tasks.filter(task=>task.dropped).map(task=>task.id));
|
|
87
|
+
const approved=previous===null?new Map():dependencyLines(previous);
|
|
88
|
+
for(const [taskId,required] of parsed.dependencies)
|
|
89
|
+
if(required.some(id=>dropped.has(id))&&approved.get(taskId)!==required.join(','))codes.add('dependencies_invalid');
|
|
90
|
+
}
|
|
91
|
+
return [...codes];
|
|
92
|
+
}
|
|
93
|
+
// The missing-scope hint text a recorded rule-3 report may carry (persisted
|
|
94
|
+
// reports are matched by digest, so a reworded hint keeps its old form here).
|
|
95
|
+
const SCOPE_HINT='每个任务下写一行缩进子项,例如 - 范围: `src/a.js`, `test/a.test.js`(只有 N.bootstrap 脚手架里列不出文件的任务才写 - 范围: 串行)';
|
|
96
|
+
const SCOPE_HINTS=[SCOPE_HINT,'每个任务下写一行缩进子项,例如 - 范围: `src/a.js`, `test/a.test.js`;列不出文件的任务写 - 范围: 串行'];
|
|
97
|
+
export function matchesPrdDraftMechanics(draft,recorded,options={}){
|
|
98
|
+
const want=digest(recorded);
|
|
99
|
+
return PRD_SELF_CHECK_RULE_VERSIONS.some(rules=>{
|
|
100
|
+
const report=checkPrdDraftMechanics(draft,{...options,rules});
|
|
101
|
+
return SCOPE_HINTS.some(hint=>digest({...report,findings:report.findings.map(item=>
|
|
102
|
+
item.code==='task_scope_missing'?{...item,reason:{...item.reason,expected:hint}}:item)})===want);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// `scopes` ({directory: {exempt:[taskId...]}}) applies only rule 3's per-task scope
|
|
106
|
+
// check, to those features, on top of `rules`. Re-checks of a saved draft
|
|
107
|
+
// (correction, disposition, summary) pass it when the save recorded that the draft
|
|
108
|
+
// carried scopes (task-scope-record.mjs), so a correction cannot drop them while
|
|
109
|
+
// every other check stays on its old rule.
|
|
110
|
+
// `sessionTasks` ([directory...]) likewise applies only what rule 4 adds (tasks.md
|
|
111
|
+
// read as grammar 3, with the session-task checks) to the features whose save
|
|
112
|
+
// recorded rule 4, so a correction cannot move or add a `开发: 会话` mark unnoticed.
|
|
113
|
+
export function checkPrdDraftMechanics(draft,{change=false,previous=null,rules=1,scopes=null,sessionTasks=null}={}){
|
|
114
|
+
need(PRD_SELF_CHECK_RULE_VERSIONS.includes(rules),'prd_self_check_rules_invalid');
|
|
115
|
+
need(sessionTasks===null||Array.isArray(sessionTasks)&&sessionTasks.every(item=>typeof item==='string'),
|
|
116
|
+
'prd_self_check_rules_invalid');
|
|
43
117
|
const findings=[],features=[];
|
|
44
118
|
for(const feature of draft.features){
|
|
45
119
|
const files=new Map(feature.documents.map(document=>[document.path,document.content]));
|
|
46
|
-
const add=code=>findings.push({feature:feature.directory,code,
|
|
120
|
+
const add=(code,reason=null)=>findings.push({feature:feature.directory,code,
|
|
47
121
|
...(code==='dependencies_invalid'?{reason:{field:`${feature.directory}/tasks.md`,
|
|
48
|
-
expected:'One line per task; comma-separated prerequisites, e.g. - T-003 依赖 T-001, T-002'}}:{})
|
|
122
|
+
expected:'One line per task; comma-separated prerequisites, e.g. - T-003 依赖 T-001, T-002'}}:{}),
|
|
123
|
+
...(reason?{reason}:{})});
|
|
49
124
|
const parsed=parseFeatureTaskText(files.get('tasks.md'));
|
|
50
125
|
const acIds=declaredAcceptanceIds(outsideFences(files.get('requirements.md')));
|
|
51
126
|
if(acIds.size===0)add('acceptance_missing');
|
|
@@ -53,10 +128,41 @@ export function checkPrdDraftMechanics(draft,{change=false}={}){
|
|
|
53
128
|
if(parsed.error)add(parsed.error);
|
|
54
129
|
else{
|
|
55
130
|
taskIds=new Set(parsed.tasks.map(task=>task.id));
|
|
56
|
-
|
|
131
|
+
// Dropped tasks stay in tasks.md as history; only the rest is executable work.
|
|
132
|
+
if((rules===1?parsed.tasks:parsed.tasks.filter(task=>!task.dropped)).length>15)add('task_limit_exceeded');
|
|
57
133
|
if(!change&&parsed.tasks.some(task=>task.completed||task.dropped))add('new_task_not_pending');
|
|
58
134
|
if(!validDependencies(parsed.tasks,parsed.dependencies))add('dependencies_invalid');
|
|
59
135
|
}
|
|
136
|
+
if(rules!==1){
|
|
137
|
+
const reported=new Set(findings.filter(item=>item.feature===feature.directory).map(item=>item.code));
|
|
138
|
+
for(const code of strictFindings(files.get('tasks.md'),previous?.[feature.directory]??null,parsed))
|
|
139
|
+
if(!reported.has(code))add(code);
|
|
140
|
+
}
|
|
141
|
+
const scope=scopes!==null&&Object.hasOwn(scopes,feature.directory)?scopes[feature.directory]:null;
|
|
142
|
+
const grammar3=rules>=4||sessionTasks?.includes(feature.directory)===true;
|
|
143
|
+
if((rules>=3||scope!==null)&&!parsed.error){
|
|
144
|
+
// Rules 1-3 predate grammar 3: a `开发:` line there stays prose, as it was then.
|
|
145
|
+
const scopes=parseTaskScopes(files.get('tasks.md'),{grammar:grammar3?TASK_GRAMMAR:2});
|
|
146
|
+
const problems=scopes.errors.map(item=>`${item.taskId??'(无任务)'} 第 ${item.line} 行:${item.message}`);
|
|
147
|
+
// 串行 is the scaffold generator's exit (a N.bootstrap feature), not an opt-out for business tasks.
|
|
148
|
+
if(!BOOTSTRAP_FEATURE.test(feature.directory))for(const id of scopes.serial)problems.push(`${id}:范围: 串行 只用于脚手架功能(N.bootstrap),其余任务要列出文件`);
|
|
149
|
+
if(problems.length)add('task_scope_invalid',{field:`${feature.directory}/tasks.md`,problems:problems.slice(0,10)});
|
|
150
|
+
// Only tasks an approval already covered may stay without scope; the caller
|
|
151
|
+
// derives them from the approval (task-scope-record.mjs), never from a draft.
|
|
152
|
+
const known=new Set(scope?.exempt??[]);
|
|
153
|
+
const missing=parsed.tasks.filter(task=>!task.dropped&&!scopes.tasks.has(task.id)&&!scopes.serial.has(task.id)&&!scopes.errors.some(item=>item.taskId===task.id)
|
|
154
|
+
&&!known.has(task.id)).map(task=>task.id);
|
|
155
|
+
if(missing.length)add('task_scope_missing',{field:`${feature.directory}/tasks.md`,tasks:missing,
|
|
156
|
+
expected:SCOPE_HINT});
|
|
157
|
+
}
|
|
158
|
+
else if(grammar3&&!parsed.error){
|
|
159
|
+
// A rule-4 re-check without the scope check still reports the 开发 line's own
|
|
160
|
+
// grammar errors (bad value, repeated, not under a task), not the rest of rule 3.
|
|
161
|
+
const problems=parseTaskScopes(files.get('tasks.md'),{grammar:TASK_GRAMMAR}).errors.filter(item=>item.developer)
|
|
162
|
+
.map(item=>`${item.taskId??'(无任务)'} 第 ${item.line} 行:${item.message}`);
|
|
163
|
+
if(problems.length)add('task_scope_invalid',{field:`${feature.directory}/tasks.md`,problems:problems.slice(0,10)});
|
|
164
|
+
}
|
|
165
|
+
if(grammar3&&!parsed.error)for(const item of sessionTaskFindings(feature.directory,files.get('tasks.md')))add(item.code,item.reason);
|
|
60
166
|
if(files.has('test-cases.json')){
|
|
61
167
|
let cases;try{cases=JSON.parse(files.get('test-cases.json'));}catch{add('test_cases_invalid');}
|
|
62
168
|
if(cases){
|
|
@@ -76,3 +182,16 @@ export function checkPrdDraftMechanics(draft,{change=false}={}){
|
|
|
76
182
|
'test_contract_applicability','brownfield_references_and_B2_B3_B5_if_applicable'],
|
|
77
183
|
completeSelfCheck:false,independentReview:false,completionAuthorized:false});
|
|
78
184
|
}
|
|
185
|
+
|
|
186
|
+
// Grammar 3 mechanical check (task-scope.mjs sessionTaskProblem): only the explicit
|
|
187
|
+
// `开发: 会话` marks, never a guess at which task needs a session. Findings shaped like
|
|
188
|
+
// checkPrdDraftMechanics' own; empty under grammar 1/2, where the mark is prose, and for
|
|
189
|
+
// a tasks.md the parser already refuses (that finding is reported on its own).
|
|
190
|
+
export function sessionTaskFindings(directory,source,{grammar=TASK_GRAMMAR}={}){
|
|
191
|
+
if(grammar!==TASK_GRAMMAR)return [];
|
|
192
|
+
const parsed=parseFeatureTaskText(source,{grammar});
|
|
193
|
+
if(parsed.error)return [];
|
|
194
|
+
const problem=sessionTaskProblem(parsed.tasks,parseTaskScopes(source,{grammar}).sessions,parsed.dependencies);
|
|
195
|
+
return problem?[{feature:directory,code:problem.code,reason:{field:`${directory}/tasks.md`,tasks:problem.tasks,
|
|
196
|
+
...(problem.dependents?{dependents:problem.dependents}:{}),expected:sessionTaskReason(problem)}}]:[];
|
|
197
|
+
}
|