@aibyzero/cm-workflow 0.21.6 → 0.25.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/CHANGELOG.md +58 -0
- package/README.md +18 -3
- package/VERSION +1 -1
- package/docs/architecture.md +9 -0
- package/docs/cm-acceptance-completion.md +3 -1
- package/docs/cm-control-policy-v2.md +35 -3
- package/docs/execution-optimizations.md +1 -1
- package/docs/external-models.md +1 -0
- package/docs/human-correction.md +1 -1
- package/docs/installation.md +42 -16
- package/docs/js-workflow-control.md +65 -30
- package/docs/next-steps.md +10 -0
- package/docs/runtime-failover.md +5 -3
- package/docs/user-guide.md +6 -6
- package/package.json +1 -1
- package/runtime/js/cm-ai/batch-location.mjs +14 -0
- package/runtime/js/cm-ai/batch-plan.mjs +6 -2
- package/runtime/js/cm-ai/checkpoint-package-material.mjs +9 -2
- package/runtime/js/cm-ai/cm-ai-admission.mjs +9 -3
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +51 -8
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +30 -4
- package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -4
- package/runtime/js/cm-ai/delivery-evidence.mjs +3 -1
- package/runtime/js/cm-ai/developer-adapter.mjs +15 -1
- package/runtime/js/cm-ai/drive-core.mjs +50 -6
- package/runtime/js/cm-ai/drive-next-step.mjs +61 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +85 -23
- package/runtime/js/cm-ai/execution-snapshot.mjs +5 -2
- package/runtime/js/cm-ai/execution-store.mjs +21 -3
- package/runtime/js/cm-ai/external-run-guard.mjs +9 -1
- package/runtime/js/cm-ai/host-check.mjs +4 -2
- package/runtime/js/cm-ai/host-conversation-execution.mjs +23 -2
- package/runtime/js/cm-ai/host-handoff.mjs +7 -0
- package/runtime/js/cm-ai/host-progress.mjs +18 -0
- package/runtime/js/cm-ai/host-qa-executor.mjs +47 -15
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +24 -14
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +1 -1
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/operator-guidance.mjs +126 -2
- package/runtime/js/cm-ai/project-qa-gate.mjs +13 -2
- package/runtime/js/cm-ai/provider-review-observation.mjs +7 -3
- package/runtime/js/cm-ai/qa-plan-notes.mjs +106 -0
- package/runtime/js/cm-ai/review-continuation.mjs +102 -0
- package/runtime/js/cm-ai/review-evidence-file.mjs +11 -0
- package/runtime/js/cm-ai/review-package.mjs +25 -4
- package/runtime/js/cm-ai/review-presentation.mjs +31 -14
- package/runtime/js/cm-ai/review-runner.mjs +5 -4
- package/runtime/js/cm-ai/review-verdict-rules.mjs +7 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +30 -1
- package/runtime/js/cm-ai/task-commit-codec.mjs +11 -1
- package/runtime/js/cm-ai/task-commit.mjs +7 -4
- package/runtime/js/cm-ai/task-owner.mjs +5 -2
- package/runtime/js/cm-ai/task-runner.mjs +343 -52
- package/runtime/js/cm-ai/tool-preview.mjs +6 -0
- package/runtime/js/cm-fix/diagnosis.mjs +16 -3
- package/runtime/js/cm-fix/execution.mjs +47 -9
- package/runtime/js/cm-fix/finish.mjs +9 -1
- package/runtime/js/cm-fix/step-timing.mjs +222 -0
- package/runtime/js/cm-idea/session.mjs +22 -3
- package/runtime/js/cm-init/review-evidence.mjs +20 -7
- package/runtime/js/cm-prd/ai-draft.mjs +260 -0
- package/runtime/js/cm-prd/analysis.mjs +27 -9
- package/runtime/js/cm-prd/change.mjs +29 -8
- package/runtime/js/cm-prd/failed-correction.mjs +24 -4
- package/runtime/js/cm-prd/narrow-review.mjs +63 -3
- package/runtime/js/cm-prd/review-correction.mjs +65 -5
- package/runtime/js/cm-prd/review-disposition.mjs +10 -1
- package/runtime/js/cm-prd/self-check.mjs +121 -9
- package/runtime/js/cm-prd/session.mjs +55 -13
- package/runtime/js/cm-prd/summary.mjs +34 -6
- package/runtime/js/cm-prd/task-scope-record.mjs +40 -15
- package/runtime/js/cm-refactor/records.mjs +82 -11
- package/runtime/js/cm-refactor/workflow.mjs +3 -1
- package/runtime/js/executor-version.mjs +81 -0
- package/runtime/js/python-log-writer.mjs +15 -0
- package/runtime/js/run-analysis.mjs +136 -11
- package/runtime/logging.md +6 -0
- package/runtime/review.md +3 -1
- package/runtime/workflow-config.md +1 -1
- package/scripts/ci-test-weights.json +1 -0
- package/scripts/cm-ai-admission.mjs +27 -1
- package/scripts/cm-ai-admission.test.mjs +34 -2
- package/scripts/cm-ai-answer-gap-recheck.test.mjs +3 -2
- package/scripts/cm-ai-batch-drive.mjs +54 -17
- package/scripts/cm-ai-batch-drive.test.mjs +123 -6
- package/scripts/cm-ai-batch-host.mjs +55 -9
- package/scripts/cm-ai-batch-host.test.mjs +22 -3
- package/scripts/cm-ai-batch-location.test.mjs +22 -1
- package/scripts/cm-ai-batch-merge.mjs +102 -0
- package/scripts/cm-ai-batch-plan.mjs +55 -2
- package/scripts/cm-ai-batch-plan.test.mjs +228 -6
- package/scripts/cm-ai-batch-run-fixture.mjs +239 -15
- package/scripts/cm-ai-batch-run-parallel.test.mjs +23 -1
- package/scripts/cm-ai-batch-run.mjs +435 -33
- package/scripts/cm-ai-batch-session-member.test.mjs +85 -0
- package/scripts/cm-ai-check-recheck-cancellation.test.mjs +23 -2
- package/scripts/cm-ai-checkpoint-package-material.test.mjs +28 -0
- package/scripts/cm-ai-completion-summary.test.mjs +2 -1
- package/scripts/cm-ai-control-v2-drive.test.mjs +39 -9
- package/scripts/cm-ai-direct-review.test.mjs +1 -1
- package/scripts/cm-ai-disk-edits.test.mjs +229 -0
- package/scripts/cm-ai-drive-next-step.test.mjs +191 -0
- package/scripts/cm-ai-drive.mjs +66 -14
- package/scripts/cm-ai-drive.test.mjs +13 -3
- package/scripts/cm-ai-host-cli-workflow.test.mjs +4 -2
- package/scripts/cm-ai-host.mjs +16 -8
- package/scripts/cm-ai-host.test.mjs +12 -0
- package/scripts/cm-ai-operator-guidance.test.mjs +132 -1
- package/scripts/cm-ai-project-qa-gate.test.mjs +26 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -0
- package/scripts/cm-ai-review-continuation.test.mjs +335 -0
- package/scripts/cm-ai-review-failure.test.mjs +13 -10
- package/scripts/cm-ai-review-timeout.test.mjs +1 -1
- package/scripts/cm-ai-run.mjs +42 -11
- package/scripts/cm-ai-run.test.mjs +26 -0
- package/scripts/cm-ai-supersede.test.mjs +10 -2
- package/scripts/cm-capability-gate.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +9 -0
- package/scripts/cm-codex-clean-env.test.mjs +40 -0
- package/scripts/cm-codex-prompt-input.test.mjs +2 -1
- package/scripts/cm-developer-self-review.test.mjs +27 -0
- package/scripts/cm-efficiency-presentation-delta.test.mjs +4 -3
- package/scripts/cm-efficiency-response.test.mjs +2 -1
- package/scripts/cm-executor-version-draft.test.mjs +251 -0
- package/scripts/cm-executor-version-entries.test.mjs +93 -0
- package/scripts/cm-executor-version-prd.test.mjs +154 -0
- package/scripts/cm-executor-version-records.test.mjs +256 -0
- package/scripts/cm-executor-version.test.mjs +250 -0
- package/scripts/cm-external-model-host.test.mjs +6 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +1 -1
- package/scripts/cm-fix-closeout-preflight.test.mjs +123 -0
- package/scripts/cm-fix-diagnosis-module-correction.test.mjs +5 -1
- package/scripts/cm-fix-drive.mjs +7 -2
- package/scripts/cm-fix-drive.test.mjs +45 -0
- package/scripts/cm-fix-entry.mjs +5 -2
- package/scripts/cm-fix-frozen-baseline.test.mjs +50 -0
- package/scripts/cm-fix-host.mjs +9 -2
- package/scripts/cm-fix-test-extension.test.mjs +30 -2
- package/scripts/cm-host-check.test.mjs +12 -0
- package/scripts/cm-host-qa-executor.test.mjs +172 -1
- package/scripts/cm-host-qa-policy.test.mjs +55 -1
- package/scripts/cm-idea-drive.mjs +5 -2
- package/scripts/cm-idea-entry.mjs +5 -2
- package/scripts/cm-idea-host.mjs +3 -1
- package/scripts/cm-init-drive.mjs +8 -5
- package/scripts/cm-init-entry.mjs +5 -2
- package/scripts/cm-init-host.mjs +6 -2
- package/scripts/cm-log-event.mjs +10 -2
- package/scripts/cm-log-event.test.mjs +29 -0
- package/scripts/cm-prd-ai-draft-fixture.mjs +18 -0
- package/scripts/cm-prd-ai-draft.test.mjs +505 -0
- package/scripts/cm-prd-answer-gaps.test.mjs +110 -5
- package/scripts/cm-prd-completion.test.mjs +67 -4
- package/scripts/cm-prd-design-phase.test.mjs +48 -13
- package/scripts/cm-prd-drive.mjs +89 -20
- package/scripts/cm-prd-drive.test.mjs +109 -4
- package/scripts/cm-prd-entry.mjs +5 -2
- package/scripts/cm-prd-host.mjs +89 -20
- package/scripts/cm-prd-host.test.mjs +17 -8
- package/scripts/cm-prd-narrow-review.test.mjs +49 -1
- package/scripts/cm-prd-review-disposition.test.mjs +94 -1
- package/scripts/cm-prd-review-gate.mjs +11 -4
- package/scripts/cm-prd-self-check-rules.test.mjs +175 -10
- package/scripts/cm-prd-self-check.test.mjs +1 -1
- package/scripts/cm-refactor-drive.mjs +10 -4
- package/scripts/cm-refactor-entry.mjs +5 -2
- package/scripts/cm-refactor-host.mjs +3 -1
- package/scripts/cm-run-analysis.test.mjs +373 -1
- package/scripts/cm-runtime-i18n.mjs +3 -3
- package/scripts/cm-runtime-install.mjs +19 -10
- package/scripts/cm-runtime.mjs +2 -4
- package/scripts/cm-runtime.test.mjs +55 -13
- package/scripts/cm-skill-hints-autowire.test.mjs +1 -1
- package/scripts/cm-skill-hints-exam.mjs +3 -1
- package/scripts/cm-skill-hints-install.test.mjs +1 -1
- package/scripts/cm-skill-hints.mjs +106 -10
- package/scripts/cm-skill-hints.test.mjs +162 -6
- package/scripts/cm-skill-judge.mjs +2 -1
- package/scripts/cm-statusline.test.mjs +54 -0
- package/scripts/cm-task-gate.mjs +88 -18
- package/scripts/cm-task-scope.test.mjs +1 -1
- package/scripts/cm-test-drive.mjs +13 -8
- package/scripts/cm-test-entry.mjs +5 -2
- package/scripts/cm-test-host.mjs +3 -1
- package/scripts/cm-upgrade-compat-batch.test.mjs +62 -9
- package/scripts/fixtures/fresh-completion-checks.mjs +8 -0
- package/scripts/fixtures/prd-review-gate-python-oracle.py +9 -0
- package/scripts/policy-binding-compat.test.mjs +3 -2
- package/scripts/test-cm-prd-review-gate.py +25 -0
- package/skills/cm-ai/SKILL.md +1 -1
- package/skills/cm-ai/references/N1-init.md +4 -3
- package/skills/cm-ai/references/N4-review.md +6 -3
- package/skills/cm-ai/references/N6-qa-eval.md +3 -1
- package/skills/cm-ai/references/js-host-recovery.md +4 -1
- package/skills/cm-ai/references/js-host.md +25 -5
- package/skills/cm-fix/references/js-host.md +20 -0
- package/skills/cm-fix/references/test-extension.md +1 -1
- package/skills/cm-prd/SKILL.md +8 -6
- package/skills/cm-prd/references/ai-draft.md +81 -0
- package/skills/cm-prd/references/change-mode.md +2 -0
- package/skills/cm-prd/references/greenfield.md +2 -0
- package/skills/cm-prd/references/js-change-recovery.md +2 -2
- package/skills/cm-prd/references/js-host.md +9 -6
- package/skills/cm-prd/references/light-mode.md +19 -0
- package/skills/cm-prd/references/requirement-grilling.md +2 -0
- package/skills/cm-prd/references/spec-self-check.md +1 -0
- package/skills/cm-prd/references/summary-card.md +1 -0
- package/skills/cm-runtime/SKILL.md +6 -6
- package/templates/statusline/cm-statusline.sh +63 -1
package/scripts/cm-prd-host.mjs
CHANGED
|
@@ -14,17 +14,43 @@ import {runPrdHostReview,validatePrdReviewMode} from '../runtime/js/cm-prd/revie
|
|
|
14
14
|
import {inspectPrdFindings} from '../runtime/js/cm-prd/review-findings.mjs';
|
|
15
15
|
import {createPrdDispositionOwner} from '../runtime/js/cm-prd/review-disposition.mjs';
|
|
16
16
|
import {savePrdDraft,savePrdDesign,savePrdPromotedDraft} from '../runtime/js/cm-prd/draft-save.mjs';
|
|
17
|
-
import {createPrdCorrectionOwner,inspectPrdCorrectionRecovery,resumePrdCorrection,prdNarrowChainStarted,inspectPrdNarrowReview,recordPrdNarrowReviewHost} from '../runtime/js/cm-prd/review-correction.mjs';
|
|
17
|
+
import {createPrdCorrectionOwner,assertPrdCorrectionRefused,inspectPrdCorrectionRecovery,resumePrdCorrection,prdNarrowChainStarted,inspectPrdNarrowReview,recordPrdNarrowReviewHost,recordPrdNarrowUserDecisionHost} from '../runtime/js/cm-prd/review-correction.mjs';
|
|
18
18
|
import {createPrdSummaryOwner,publishPrdAwaitingReview} from '../runtime/js/cm-prd/summary.mjs';
|
|
19
|
+
import {PRD_AI_DRAFT_POLICY,PRD_AI_DRAFT_REFUSALS,PRD_AI_DRAFT_CORRECT_INSTRUCTIONS,prdAiDraftAskedIds} from '../runtime/js/cm-prd/ai-draft.mjs';
|
|
19
20
|
import {currentAcceptancePreview} from '../runtime/js/cm-prd/acceptance-preview.mjs';
|
|
20
21
|
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
21
22
|
import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
|
|
23
|
+
import {tagDiagnosticReason} from '../runtime/js/cm-ai/diagnostic-reason.mjs';
|
|
22
24
|
import {need,shape,json,id,digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
23
|
-
import {openPrdSession} from '../runtime/js/cm-prd/session.mjs';
|
|
25
|
+
import {openPrdSession,assertPrdSessionExecutor,MAX_ANSWER_DISCARDS} from '../runtime/js/cm-prd/session.mjs';
|
|
26
|
+
import {EXECUTOR_REASON_CODES} from '../runtime/js/executor-version.mjs';
|
|
24
27
|
import {createPrdChange,assertPrdReviewsSettled} from '../runtime/js/cm-prd/change.mjs';
|
|
25
28
|
import {publishPrdReview,inspectPrdReviewResponse} from '../runtime/js/cm-prd/review-publication.mjs';
|
|
26
29
|
import {abandonPrdReviewAttempt} from './cm-prd-review-gate.mjs';
|
|
27
30
|
|
|
31
|
+
// dogfood 2026-12-01(问题 5、19):请求字段对不上时,错误输出写明多余和缺少的字段名,不只报 invalid_input。
|
|
32
|
+
// 只报本宿主请求里已知的字段名;其他键可能是误放的敏感文本,只报个数(审查 r1)。不回显字段值,返回结果不变。
|
|
33
|
+
const KNOWN_REQUEST_FIELDS=new Set(['requestId','operation','text','stage','feature','packageDigest','round','designSha256',
|
|
34
|
+
'reviewer','sessionId','independent','at','verdict','summary','findings','degradedReason','decisions','artifacts',
|
|
35
|
+
'summaryDigest','draftDigest','risks','reason','proposalDigest','approved','allowUserCaseChanges','mode','binding',
|
|
36
|
+
'successorSpecs','successorSessionId','resolution','decision','userWords','acceptedFindingIds']);
|
|
37
|
+
const fieldList=keys=>{const known=keys.filter(key=>KNOWN_REQUEST_FIELDS.has(key)),unknown=keys.length-known.length;
|
|
38
|
+
return [...known,...(unknown?[`另有 ${unknown} 个非本宿主字段`]:[])].join(', ');};
|
|
39
|
+
function requestShape(request,names){
|
|
40
|
+
try{shape(request,names);}
|
|
41
|
+
catch(error){
|
|
42
|
+
try{
|
|
43
|
+
if(request!==null&&typeof request==='object'&&!Array.isArray(request)){
|
|
44
|
+
const keys=Object.keys(request),extra=keys.filter(key=>!names.includes(key)),missing=names.filter(key=>!Object.hasOwn(request,key));
|
|
45
|
+
const parts=[...(extra.length?[`多余字段:${fieldList(extra)}`]:[]),...(missing.length?[`缺少字段:${fieldList(missing)}`]:[])];
|
|
46
|
+
const operation=typeof request.operation==='string'&&/^[a-z_]{1,40}$/.test(request.operation)?request.operation:'该';
|
|
47
|
+
if(parts.length)tagDiagnosticReason(error,`${operation} 请求${parts.join(';')}`);
|
|
48
|
+
}
|
|
49
|
+
}catch{/* the diagnostic never replaces the original refusal */}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
28
54
|
const sessionFailureCodes=new Set(['prd_operation_recovery_required','prd_host_result_unknown','prd_nothing_to_resume',
|
|
29
55
|
'prd_recovery_binding','prd_recovery_evidence_required','prd_replay_inputs_changed','cancelled','prd_turn_not_ready',
|
|
30
56
|
'prd_review_recovery_required','prd_batch_inputs_replaced','prd_inputs_changed','prd_replacement_authorization_required',
|
|
@@ -33,7 +59,7 @@ const sessionFailureCodes=new Set(['prd_operation_recovery_required','prd_host_r
|
|
|
33
59
|
'prd_predecessor_binding','prd_successor_inputs_changed',
|
|
34
60
|
'prd_answer_discard_limit','prd_correction_recovery_required','prd_review_abandon_not_enabled','prd_review_result_publishable',
|
|
35
61
|
'prd_review_abandon_unavailable','prd_review_abandon_limit','prd_review_abandon_reason_required','prd_review_abandon_binding',
|
|
36
|
-
'prd_correction_recovery_conflict']);
|
|
62
|
+
'prd_correction_recovery_conflict','prd_correction_not_enabled']);
|
|
37
63
|
|
|
38
64
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
39
65
|
let bridge,analysis,session,change=null,started=false,closed=false,record;
|
|
@@ -42,7 +68,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
42
68
|
output.write('replace_inputs {requestId,operation,approved:true,reason,successorSpecs,successorSessionId} ends a changed-input batch with immutable history; read_batch/status remain available. Start the bound fresh specs root with --session SUCCESSOR_ID --predecessor ABSOLUTE_RECEIPT_PATH. No approvals transfer.\n');
|
|
43
69
|
output.write('New and --change SELECTOR share this host. --session prd-ID resumes a durable local conversation; obtain runId from status. resume {requestId,operation,resolution:null|{callId,requestDigest,result,evidence}} consumes only the original host result, never re-dispatches an unknown call. decision {requestId,operation,proposalDigest,approved,allowUserCaseChanges} confirms an exact change proposal; save_draft archives and writes awaiting_review. prepare_revision {requestId,operation,reason} revises the saved current batch with original review history retained; no review counters reset.\n');
|
|
44
70
|
output.write('resume also accepts resolution:{callId,requestDigest,abandon:true,evidence} with result absent: discard the entire pending operation and restore its before checkpoint, only if no call is prd_review. Explicit cancel is terminal: checkpoint cancelled and active cleared; resume cannot continue it. Session failures return {status:blocked,reason,recovery,completionAuthorized:false} (2026-09-17 dogfood: cancelled checkpoint retained active and hid recovery errors).\n');
|
|
45
|
-
output.write('resume resolution:{callId,requestDigest,discard:true,evidence} discards the last RECORDED answer the host then refused (not prd_review
|
|
71
|
+
output.write('resume resolution:{callId,requestDigest,discard:true,evidence} discards the last RECORDED answer the host then refused (not prd_review; prd_correct only in a session created with correctionDiscard, while no correction archive exists and the recorded proposal still fails the same inspection), keeps an append-only discardedAnswers record and asks that call again under the same pending operation; at most 2 per call kind in a session. resolution:{callId,requestDigest,abandonReview:true,evidence} needs --allow-review-write and --allow-review-abandon: only for a pending final_review whose prd_review result was lost or fails publication, it releases the gate claim into prd-<feature>-<stage>-dispatch-abandoned-N.json (at most 2 per feature and stage), records abandonedReviews and restores the before checkpoint; then send final_review again for a fresh independent review. A recorded result that would publish is never abandoned.\n');
|
|
46
72
|
output.write('promote_design {requestId,operation,draftDigest,reason} moves an unreviewed full draft to design while preserving draft and self-check rounds. Saved drafts require complete exact original bytes with private permissions; partial/conflicting saves, prior review and exhausted rounds are rejected. Saved task revisions archive both versions before replacement; no approval is implied.\n');
|
|
47
73
|
output.write('select_design_reviews {requestId,operation,draftDigest,risks:[{feature,signals,evidence}]} at design_ready freezes host-reported Step 9.5 risks for every feature. Only high-risk features may request design review; low-risk exact saved designs continue without it. Not approval; existing attempts cannot be downgraded.\n');
|
|
48
74
|
output.write('plan_design {requestId,operation,text} generates requirements/design only. design_ready permits save_design with --allow-spec-write and original design review. After original design disposition, advance generates tasks from the exact current design, then original self-check/save_draft. No approval is implied.\n');
|
|
@@ -77,8 +103,12 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
77
103
|
let ended=readPrdInputsReplacement(admission.specs,runId);
|
|
78
104
|
need(ended||admission.status==='ready'||options['--session']&&admission.mode==='change'&&admission.reason==='feature_missing','prd_admission_blocked');
|
|
79
105
|
need(fileURLToPath(import.meta.url)===path.join(admission.workflowRoot,'scripts/cm-prd-host.mjs'),'entry_path_invalid');
|
|
106
|
+
// Before the predecessor link or any session directory is written.
|
|
107
|
+
assertPrdSessionExecutor({specs:admission.specs,sessionId:runId});
|
|
80
108
|
const predecessor=bindPrdPredecessor({entry,runtime,sessionId:runId,predecessor:options['--predecessor']});
|
|
81
|
-
session=openPrdSession({specs:admission.specs,sessionId:runId,identity:{entry,runtime,...(predecessor?{predecessor}:{})},executionPolicy:argv.includes('--execution-optimizations')?EXECUTION_POLICY_V1:null
|
|
109
|
+
session=openPrdSession({specs:admission.specs,sessionId:runId,identity:{entry,runtime,...(predecessor?{predecessor}:{})},executionPolicy:argv.includes('--execution-optimizations')?EXECUTION_POLICY_V1:null,
|
|
110
|
+
// Only a session created now in new mode drafts technical details itself; a stored session keeps its own.
|
|
111
|
+
specDrafting:admission.mode==='new'?PRD_AI_DRAFT_POLICY:null});
|
|
82
112
|
if(!ended&&admission.status!=='ready')need(session.state.checkpoint?.change?.stage==='awaiting_review'
|
|
83
113
|
||session.state.active?.request.operation==='save_draft','prd_admission_blocked');
|
|
84
114
|
record=({event,phase='analysis',data={},at=null})=>{
|
|
@@ -108,7 +138,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
108
138
|
checkContext:(payload,signal)=>call('prd_self_check',payload,signal),
|
|
109
139
|
generate:(payload,signal)=>call('prd_generate',payload,signal),
|
|
110
140
|
processMaterials:(payload,signal)=>call('prd_materials',payload,signal),
|
|
111
|
-
analyze:(payload,signal)=>call('prd_analyze',payload,signal),selfCheckRules:()=>session.selfCheckRules()
|
|
141
|
+
analyze:(payload,signal)=>call('prd_analyze',payload,signal),selfCheckRules:()=>session.selfCheckRules(),
|
|
142
|
+
aiDraft:()=>session.aiDraftPolicy()}):null;
|
|
112
143
|
const restoreChange=(restored=null,selected,reason)=>createPrdChange({admission,runtime,call,restored,
|
|
113
144
|
selfCheckRules:()=>session.selfCheckRules(),...(selected?{selected,reason}:{})});
|
|
114
145
|
let reviewState=null;const reviewController=new AbortController();
|
|
@@ -117,7 +148,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
117
148
|
...payload,project:admission.project,analysis:analysis.status(),
|
|
118
149
|
reference:path.join(admission.workflowRoot,'skills/cm-prd/SKILL.md')},signal)});
|
|
119
150
|
const makeCorrect=()=>createPrdCorrectionOwner({correct:(payload,signal)=>call('prd_correct',{
|
|
120
|
-
...payload
|
|
151
|
+
...payload,...(session.aiDraftPolicy()?{instructions:payload.instructions+PRD_AI_DRAFT_CORRECT_INSTRUCTIONS}:{}),
|
|
152
|
+
project:admission.project,specs:admission.specs,
|
|
121
153
|
reference:path.join(admission.workflowRoot,'skills/cm-prd/SKILL.md')},signal)});
|
|
122
154
|
let correct=makeCorrect();
|
|
123
155
|
const dispose=createPrdDispositionOwner({validateCurrent:input=>{if(input.stage==='split')analysis.validateCurrent(input);},canRecoverRecorded:()=>replaying&&session.state.active.calls.some(call=>call.kind==='prd_self_check'&&Object.hasOwn(call,'result')),
|
|
@@ -144,8 +176,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
144
176
|
({callId,requestDigest,kind,status:result===undefined?'unknown':'recorded'}))}:null});
|
|
145
177
|
const handle=async raw=>{
|
|
146
178
|
const request=json(raw);
|
|
147
|
-
need(['start','advance','plan_design','promote_design','select_design_reviews','status','cancel','final_review_package','final_review','review_findings','review_disposition','save_draft','save_design','correct_findings','prepare_summary','publish_summary','inspect_correction','resume_correction','prepare_revision','decision','narrow_review','narrow_status'].includes(request.operation),'host_operation_invalid');
|
|
148
|
-
|
|
179
|
+
need(['start','advance','plan_design','promote_design','select_design_reviews','status','cancel','final_review_package','final_review','review_findings','review_disposition','save_draft','save_design','correct_findings','prepare_summary','publish_summary','inspect_correction','resume_correction','prepare_revision','decision','narrow_review','narrow_status','narrow_user_decision'].includes(request.operation),'host_operation_invalid');
|
|
180
|
+
requestShape(request,['requestId','operation',...(['start','advance','plan_design'].includes(request.operation)?['text']:
|
|
181
|
+
request.operation==='narrow_user_decision'?['stage','feature','packageDigest','round','designSha256','decision','userWords','acceptedFindingIds','at']:
|
|
149
182
|
request.operation==='narrow_review'?['stage','feature','packageDigest','round','designSha256','reviewer','sessionId','independent','at','verdict','summary','findings',...(Object.hasOwn(request,'degradedReason')?['degradedReason']:[])]:
|
|
150
183
|
['final_review_package','review_findings','correct_findings','inspect_correction','resume_correction','narrow_status'].includes(request.operation)?['stage','feature',...(request.operation==='review_findings'&&Object.hasOwn(request,'packageDigest')?['packageDigest','decisions','artifacts']:[])]:
|
|
151
184
|
request.operation==='review_disposition'?['stage','feature','packageDigest','decisions','artifacts']:
|
|
@@ -165,7 +198,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
165
198
|
if(change!==null){
|
|
166
199
|
if(request.operation==='decision')return change.confirm(request);
|
|
167
200
|
if(request.operation==='save_draft'){
|
|
168
|
-
const result=change.save(specWriteEnabled);
|
|
201
|
+
const result=change.save(specWriteEnabled);
|
|
202
|
+
// dogfood 2026-12-01(问题 21):用规格状态的发布时间写这两行,审批时才能按同一秒对上并记下等待时长。
|
|
203
|
+
for(const phase of ['changed','awaiting_review'])record({event:'spec_lifecycle',phase,data:{feature_count:result.features.length},at:result.at??null});
|
|
169
204
|
publishedSummary=true;return result;
|
|
170
205
|
}
|
|
171
206
|
need(['start','advance'].includes(request.operation)&&!publishedSummary,'prd_change_operation_invalid');
|
|
@@ -188,7 +223,11 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
188
223
|
summaryState=null;
|
|
189
224
|
try{
|
|
190
225
|
need(Array.isArray(currentFeatures)&¤tFeatures.length>0,'prd_summary_scope_unknown');
|
|
191
|
-
|
|
226
|
+
const progress=analysis.checkpoint();
|
|
227
|
+
const aiDraft=session.aiDraftPolicy()?{analysisDecisions:progress.result?.productDecisions??[],
|
|
228
|
+
asked:prdAiDraftAskedIds([...progress.messages,...progress.planning])}:null;
|
|
229
|
+
summaryState=await summarize(admission.specs,{currentFeatures,taskGrammar:session.versions().taskGrammar,
|
|
230
|
+
...(aiDraft?{aiDraft}:{})},reviewController.signal);return summaryState;
|
|
192
231
|
}catch(cause){
|
|
193
232
|
// The shared transport redacts thrown errors. Keep this recoverable
|
|
194
233
|
// scope failure visible without changing that transport contract.
|
|
@@ -204,8 +243,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
204
243
|
taskGrammar:session.versions().taskGrammar});
|
|
205
244
|
// Even an uncertain status write must not be silently retried.
|
|
206
245
|
publishedSummary=true;
|
|
246
|
+
// dogfood 2026-12-01(问题 21):用本次发布(或恢复时已核验)的状态时间,审批写入才能按同一秒对上;不再重读状态文件(审查 r1)。
|
|
207
247
|
if(result.status==='awaiting_review')for(const phase of ['generated','awaiting_review'])
|
|
208
|
-
record({event:'spec_lifecycle',phase,data:{feature_count:result.features.length,task_count:summaryState.totals.tasks}});
|
|
248
|
+
record({event:'spec_lifecycle',phase,data:{feature_count:result.features.length,task_count:summaryState.totals.tasks},at:result.at??null});
|
|
209
249
|
return result;
|
|
210
250
|
}
|
|
211
251
|
if(request.operation==='save_draft')return (analysis.checkpoint().selfCheckRevision?savePrdDraft:analysis.status().designPromotion?.saved===true?savePrdPromotedDraft:savePrdDraft)({specs:admission.specs,
|
|
@@ -214,6 +254,12 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
214
254
|
selfCheckRules:session.selfCheckRules()});
|
|
215
255
|
if(request.operation==='save_design')return savePrdDesign({specs:admission.specs,
|
|
216
256
|
writeEnabled:specWriteEnabled,getDraft:()=>analysis.currentDesignForSave()});
|
|
257
|
+
if(request.operation==='narrow_user_decision'){
|
|
258
|
+
need(request.stage==='design','prd_narrow_stage_invalid');need(reviewEnabled,'prd_review_not_enabled');
|
|
259
|
+
const {operation:_operation,requestId:_requestId,stage:_stage,feature:_feature,packageDigest:_packageDigest,...fields}=request;
|
|
260
|
+
return recordPrdNarrowUserDecisionHost({specs:admission.specs,feature:request.feature,packageDigest:request.packageDigest,input:fields,
|
|
261
|
+
authorContextId,writeEnabled:reviewEnabled});
|
|
262
|
+
}
|
|
217
263
|
if(['narrow_review','narrow_status'].includes(request.operation)){
|
|
218
264
|
need(request.stage==='design','prd_narrow_stage_invalid');
|
|
219
265
|
if(request.operation==='narrow_status')return inspectPrdNarrowReview({specs:admission.specs,feature:request.feature});
|
|
@@ -267,7 +313,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
267
313
|
const phaseFor=request=>{
|
|
268
314
|
const stage=change?.status().stage??analysis?.status().stage;
|
|
269
315
|
if(request.operation==='final_review')return request.stage==='design'?['prd-design-review','design_review']:['prd-spec-review','spec_review'];
|
|
270
|
-
if(['review_disposition','correct_findings','narrow_review'].includes(request.operation))return request.stage==='design'?['prd-design-review','design_review']:['prd-spec-review','spec_review'];
|
|
316
|
+
if(['review_disposition','correct_findings','narrow_review','narrow_user_decision'].includes(request.operation))return request.stage==='design'?['prd-design-review','design_review']:['prd-spec-review','spec_review'];
|
|
271
317
|
if(['save_draft','decision'].includes(request.operation)&&change)return ['prd-spec-validation','spec_validation'];
|
|
272
318
|
if(!['start','advance','plan_design'].includes(request.operation))return null;
|
|
273
319
|
if(['ready','awaiting_user'].includes(stage))return ['prd-requirements','requirements_analysis'];
|
|
@@ -280,13 +326,13 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
280
326
|
ended=readPrdInputsReplacement(admission.specs,runId);
|
|
281
327
|
if(request.operation==='status')return status();
|
|
282
328
|
if(request.operation==='repair_review_response'){
|
|
283
|
-
|
|
329
|
+
requestShape(request,['requestId','operation','binding']);need(reviewEnabled,'prd_review_not_enabled');
|
|
284
330
|
need(!ended,'prd_batch_inputs_replaced');
|
|
285
331
|
return {outcome:'original_response_repaired',repair:session.repairReviewResponse(request.binding),completionAuthorized:false};
|
|
286
332
|
}
|
|
287
333
|
if(request.operation==='read_batch')return ended??session.state;
|
|
288
334
|
if(request.operation==='replace_inputs'){
|
|
289
|
-
|
|
335
|
+
requestShape(request,['requestId','operation','approved','reason','successorSpecs','successorSessionId']);
|
|
290
336
|
ended=replacePrdInputs({session,sessionId:runId,approved:request.approved,reason:request.reason,
|
|
291
337
|
successorSpecs:request.successorSpecs,successorSessionId:request.successorSessionId});
|
|
292
338
|
return status();
|
|
@@ -298,12 +344,21 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
298
344
|
need(!reviewController.signal.aborted,'cancelled');
|
|
299
345
|
let operation=request;
|
|
300
346
|
if(request.operation==='resume'){
|
|
301
|
-
|
|
347
|
+
requestShape(request,['requestId','operation','resolution']);
|
|
302
348
|
need(!reviewController.signal.aborted&&session.state.checkpoint?.analysis?.stage!=='cancelled'
|
|
303
349
|
&&session.state.checkpoint?.change?.stage!=='cancelled','cancelled');
|
|
304
350
|
if(request.resolution?.discard===true){
|
|
305
|
-
|
|
306
|
-
|
|
351
|
+
// dogfood 2026-12-01 问题 7: a refused original correction is re-asked only when nothing was written.
|
|
352
|
+
const active=session.state.active,target=active?.calls.find(item=>item.callId===request.resolution.callId);
|
|
353
|
+
let refusal=null;
|
|
354
|
+
if(target?.kind==='prd_correct'&&Object.hasOwn(target,'result')&&active.request.operation==='correct_findings'){
|
|
355
|
+
// Before anything is written: the re-asked correct_findings needs both permissions (review r1 A3).
|
|
356
|
+
need(specWriteEnabled&&reviewEnabled,'prd_correction_not_enabled');
|
|
357
|
+
refusal=assertPrdCorrectionRefused({specs:admission.specs,stage:active.request.stage,feature:active.request.feature,proposal:target.result});
|
|
358
|
+
}
|
|
359
|
+
const {operation:discardedOperation,kind,callId,evidence}=session.discardAnswer(request.resolution,{correctionRefused:refusal!==null});
|
|
360
|
+
record({event:'decision',phase:'recovery',data:{operation:discardedOperation,kind,callId,evidence,outcome:'answer_discarded',
|
|
361
|
+
...(refusal?{refusal}:{})}});
|
|
307
362
|
}else if(request.resolution?.abandonReview===true){
|
|
308
363
|
need(reviewAbandonEnabled,'prd_review_abandon_not_enabled');
|
|
309
364
|
const active=session.state.active,call=active?.calls.find(item=>item.callId===request.resolution.callId);
|
|
@@ -387,8 +442,21 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
387
442
|
const host={handle:async request=>{
|
|
388
443
|
try{return await dispatch(request);}
|
|
389
444
|
catch(cause){
|
|
390
|
-
if(sessionFailureCodes.has(cause?.code))return {status:'blocked',reason:cause.code,
|
|
445
|
+
if(sessionFailureCodes.has(cause?.code)||PRD_AI_DRAFT_REFUSALS.includes(cause?.code))return {status:'blocked',reason:cause.code,
|
|
391
446
|
recovery:status().recovery,completionAuthorized:false};
|
|
447
|
+
// dogfood 2026-12-01 问题 7: say which checks refused the correction (codes and file names only) and the exit.
|
|
448
|
+
if(cause?.code==='prd_correction_mechanics_failed'&&Array.isArray(cause.failedChecks)){
|
|
449
|
+
const recovery=status().recovery,last=recovery?.calls.at(-1),stored=session.state;
|
|
450
|
+
const spent=(stored.discardedAnswers??[]).filter(item=>item.kind==='prd_correct').length>=MAX_ANSWER_DISCARDS;
|
|
451
|
+
return {status:'blocked',reason:cause.code,failedChecks:cause.failedChecks,recovery,
|
|
452
|
+
...(last?.kind==='prd_correct'&&stored.correctionDiscard!==undefined?{guidance:spent?{
|
|
453
|
+
summary:`修正稿没过机械检查,宿主没有写任何规格文件;本会话作废重问 prd_correct 已达上限(${MAX_ANSWER_DISCARDS} 次)。`,
|
|
454
|
+
nextStep:'不能再重问。用 cancel 结束本会话,再以新会话重走修正;或由人核对 failedChecks 后决定。',
|
|
455
|
+
authorizationGranted:false}:{
|
|
456
|
+
summary:'修正稿没过机械检查,宿主没有写任何规格文件。',
|
|
457
|
+
nextStep:`按 failedChecks 修好修正稿,再发 resume,resolution 填 {callId:${last.callId},requestDigest:${last.requestDigest},discard:true,evidence:原因},宿主会重问一次 prd_correct。`,
|
|
458
|
+
authorizationGranted:false}}:{}),completionAuthorized:false};
|
|
459
|
+
}
|
|
392
460
|
throw cause;
|
|
393
461
|
}
|
|
394
462
|
}};
|
|
@@ -402,7 +470,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
402
470
|
return 0;
|
|
403
471
|
}catch(cause){
|
|
404
472
|
if(started&&!closed&&record)try{closed=true;record({event:'run_done',data:{outcome:'incomplete'}});}catch{}
|
|
405
|
-
|
|
473
|
+
const code=cause?.code??'prd_host_failed';
|
|
474
|
+
error.write(JSON.stringify({error:{code,...(EXECUTOR_REASON_CODES.has(code)&&typeof cause.reason==='string'?{reason:cause.reason}:{})}})+'\n');return 1;
|
|
406
475
|
}finally{bridge?.close();session?.close();}
|
|
407
476
|
}
|
|
408
477
|
if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
|
|
@@ -10,6 +10,7 @@ import {fileURLToPath} from 'node:url';
|
|
|
10
10
|
import {analyzeRunRows} from '../runtime/js/run-analysis.mjs';
|
|
11
11
|
import {createCmPrdAnalysis} from '../runtime/js/cm-prd/analysis.mjs';
|
|
12
12
|
import {openPrdSession} from '../runtime/js/cm-prd/session.mjs';
|
|
13
|
+
import {aiDraftAnalyzed,aiDraftQuestion,aiDraftSummaryFields,AI_DRAFT_REQUIREMENTS_NOTE,AI_DRAFT_DESIGN_BASIS} from './cm-prd-ai-draft-fixture.mjs';
|
|
13
14
|
const FIXTURE_TIMEOUT_MS=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000);
|
|
14
15
|
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
15
16
|
for(const mode of ['codex','claude','cancel','cases','materials','draft','self-check'])test(`PRD actual CLI and original log adapter: ${mode}`,{timeout:FIXTURE_TIMEOUT_MS},async()=>{
|
|
@@ -26,7 +27,7 @@ for(const mode of ['codex','claude','cancel','cases','materials','draft','self-c
|
|
|
26
27
|
'--runtime',mode==='claude'?'claude':'codex','--allow-log-write',
|
|
27
28
|
...(mode==='cases'?['--cases',path.join(dir,'cases.md')]:[]),
|
|
28
29
|
...(mode==='self-check'?['--allow-review-write','--allow-disposition-write','--allow-spec-write','--host-context','author-context']:[])],
|
|
29
|
-
{env:{...process.env,CM_WORKFLOW_LOG_HOME:path.join(dir,'mirror')},stdio:['pipe','pipe','pipe']});
|
|
30
|
+
{env:{...process.env,TZ:'America/Los_Angeles',CM_WORKFLOW_LOG_HOME:path.join(dir,'mirror')},stdio:['pipe','pipe','pipe']});
|
|
30
31
|
const closed=once(child,'close'),lines=createInterface({input:child.stdout});
|
|
31
32
|
let sessionId,calls=0,status,stderr='',checks=0,reviewedDraft,summaries=0,firstSummary,currentSummary;child.stderr.on('data',chunk=>{stderr+=chunk;});
|
|
32
33
|
const send=value=>child.stdin.write(JSON.stringify(value)+'\n');
|
|
@@ -43,12 +44,12 @@ for(const mode of ['codex','claude','cancel','cases','materials','draft','self-c
|
|
|
43
44
|
openQuestions:'None in synthetic fixture',risks:'Synthetic responses, not live verification',contextScope:'Targeted',
|
|
44
45
|
platformReadiness:'Not applicable',uiBaseline:'None',designRisk:[{feature:'1.guide',
|
|
45
46
|
signals:{greenfieldAdr:false,architectureOrDataFlow:false,newRuntimeDependencyOrToolchain:false,
|
|
46
|
-
publicContractDataOrSecurity:false,fiveOrMoreFunctions:false},evidence:['Synthetic documentation-only fixture']}]}});continue;
|
|
47
|
+
publicContractDataOrSecurity:false,fiveOrMoreFunctions:false},evidence:['Synthetic documentation-only fixture']}],...aiDraftSummaryFields()}});continue;
|
|
47
48
|
}
|
|
48
49
|
if(message.kind==='prd_correct'){
|
|
49
50
|
send({type:'host_result',sessionId,callId:message.callId,requestDigest:message.requestDigest,
|
|
50
51
|
result:{documents:message.payload.documents.map(item=>({path:item.path,
|
|
51
|
-
content:item.path==='1.guide/design.md'?'## 方案摘要\nCorrected synthetic design':item.content})),
|
|
52
|
+
content:item.path==='1.guide/design.md'?'## 方案摘要\nCorrected synthetic design'+AI_DRAFT_DESIGN_BASIS:item.content})),
|
|
52
53
|
decisions:[{id:'R1',status:'applied',evidence:['Synthetic clarification'],changedPaths:['1.guide/design.md']}]}});continue;
|
|
53
54
|
}
|
|
54
55
|
if(message.kind==='prd_review'){
|
|
@@ -74,7 +75,7 @@ for(const mode of ['codex','claude','cancel','cases','materials','draft','self-c
|
|
|
74
75
|
send({type:'host_result',sessionId,callId:message.callId,requestDigest:message.requestDigest,
|
|
75
76
|
result:{status:'draft',summary:'Synthetic documentation draft',features:[{name:'guide',testCasesReason:'no_observable_behavior',
|
|
76
77
|
documents:['requirements.md','design.md','tasks.md'].map(file=>({path:file,
|
|
77
|
-
content:file==='requirements.md'?'## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Document setup.':file==='tasks.md'?'- [ ] T-001: Update guide\n - 范围: `README.md`':'## 方案摘要\nUnreviewed synthetic design'}))}]}});continue;
|
|
78
|
+
content:file==='requirements.md'?'## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Document setup.'+AI_DRAFT_REQUIREMENTS_NOTE:file==='tasks.md'?'- [ ] T-001: Update guide\n - 范围: `README.md`':'## 方案摘要\nUnreviewed synthetic design'+AI_DRAFT_DESIGN_BASIS}))}]}});continue;
|
|
78
79
|
}
|
|
79
80
|
if(message.kind==='prd_materials'){
|
|
80
81
|
assert.equal(mode,'materials');const source=message.payload.sources[0];
|
|
@@ -91,9 +92,9 @@ for(const mode of ['codex','claude','cancel','cases','materials','draft','self-c
|
|
|
91
92
|
assert.ok(fs.existsSync(path.join(dir,'运行日志.jsonl')));
|
|
92
93
|
if(mode==='cancel'){send({requestId:'cancel',operation:'cancel'});continue;}
|
|
93
94
|
send({type:'host_result',sessionId,callId:message.callId,requestDigest:message.requestDigest,
|
|
94
|
-
result:calls===1?
|
|
95
|
-
{status:'analyzed',summary:'Developer need',sourcePaths:['docs/input.md',
|
|
96
|
-
...(mode==='cases'?[path.join(dir,'cases.md')]:[]),...(mode==='materials'?['docs/extra.pdf']:[])],openQuestions:[]}});
|
|
95
|
+
result:calls===1?aiDraftQuestion('Who uses it?'):
|
|
96
|
+
aiDraftAnalyzed({status:'analyzed',summary:'Developer need',sourcePaths:['docs/input.md',
|
|
97
|
+
...(mode==='cases'?[path.join(dir,'cases.md')]:[]),...(mode==='materials'?['docs/extra.pdf']:[])],openQuestions:[]})});
|
|
97
98
|
}else if(message.requestId==='turn'){
|
|
98
99
|
assert.ok(message.result||mode==='cancel');
|
|
99
100
|
if(mode!=='cancel'&&calls===1)send({requestId:'turn',operation:'advance',text:'Developers'});
|
|
@@ -107,7 +108,7 @@ for(const mode of ['codex','claude','cancel','cases','materials','draft','self-c
|
|
|
107
108
|
}else if(message.requestId==='save'){
|
|
108
109
|
assert.equal(message.result.status,'draft_saved');assert.equal(message.result.artifacts.length,3);
|
|
109
110
|
// The save keeps its operation's rule, so later re-checks of these files use it.
|
|
110
|
-
assert.equal(JSON.parse(fs.readFileSync(path.join(dir,'.reviews/prd-guide-task-scope.json'),'utf8')).selfCheckRules,
|
|
111
|
+
assert.equal(JSON.parse(fs.readFileSync(path.join(dir,'.reviews/prd-guide-task-scope.json'),'utf8')).selfCheckRules,8);
|
|
111
112
|
assert.equal(fs.existsSync(path.join(dir,'.cm-specs-status')),false);
|
|
112
113
|
send({requestId:'package',operation:'final_review_package',stage:'split',feature:'1.guide'});
|
|
113
114
|
}else if(message.requestId==='package'){
|
|
@@ -193,6 +194,14 @@ for(const mode of ['codex','claude','cancel','cases','materials','draft','self-c
|
|
|
193
194
|
if(mode==='draft'){assert(timing.combinedSegments>=3);assert(timing.stages.some(x=>x.stage==='design_generation'));}
|
|
194
195
|
if(mode==='codex'||mode==='claude')assert(timing.closedForInput>=1);
|
|
195
196
|
assert.equal(events.filter(event=>event.event==='run_start').length,1);
|
|
197
|
+
// dogfood 2026-12-01(问题 21):发布行用规格状态的时间,审批写入按同一秒找到它。
|
|
198
|
+
// The host runs under a non-UTC TZ (below), so a row without --at would carry a local offset.
|
|
199
|
+
const statusFile=path.join(dir,'.cm-specs-status');
|
|
200
|
+
if(fs.existsSync(statusFile)&&JSON.parse(fs.readFileSync(statusFile)).status==='awaiting_review'){
|
|
201
|
+
const publishedRows=events.filter(event=>event.event==='spec_lifecycle'&&event.phase==='awaiting_review');
|
|
202
|
+
assert.equal(publishedRows.length,1);
|
|
203
|
+
assert.equal(publishedRows[0].at,`${JSON.parse(fs.readFileSync(statusFile)).at.slice(0,19)}+00:00`);
|
|
204
|
+
}
|
|
196
205
|
const done=events.filter(event=>event.event==='run_done');assert.equal(done.length,1);
|
|
197
206
|
assert.equal(done[0].outcome,mode==='cancel'?'cancelled':'incomplete');
|
|
198
207
|
assert.equal(events.filter(event=>event.event==='decision').length,calls+(mode==='draft'?1:mode==='self-check'?2:0));
|
|
@@ -7,7 +7,8 @@ import {createHash} from 'node:crypto';
|
|
|
7
7
|
import {preparePrdReview} from '../runtime/js/cm-prd/review-preparation.mjs';
|
|
8
8
|
import {publishPrdReview} from '../runtime/js/cm-prd/review-publication.mjs';
|
|
9
9
|
import {recordPrdHostDisposition} from '../runtime/js/cm-prd/review-disposition.mjs';
|
|
10
|
-
import {createPrdCorrectionOwner,inspectPrdNarrowReview,recordPrdNarrowReviewHost
|
|
10
|
+
import {createPrdCorrectionOwner,inspectPrdNarrowReview,recordPrdNarrowReviewHost,recordPrdNarrowUserDecisionHost,
|
|
11
|
+
prdNarrowUserDecisionEvidence} from '../runtime/js/cm-prd/review-correction.mjs';
|
|
11
12
|
import {claimPrdReview,recordPrdReview} from './cm-prd-review-gate.mjs';
|
|
12
13
|
import {narrowCorrectionBytes} from '../runtime/js/cm-prd/narrow-review.mjs';
|
|
13
14
|
import {inspectPrdFindings} from '../runtime/js/cm-prd/review-findings.mjs';
|
|
@@ -115,6 +116,42 @@ test('blocking findings after the second round stop for the user and never relea
|
|
|
115
116
|
assert.equal(fs.existsSync(path.join(ctx.specs,'.reviews/prd-guide-design-disposition.json')),false);
|
|
116
117
|
});
|
|
117
118
|
|
|
119
|
+
const userDecision=(ctx,{round=2,ids=['N2'],words='带着这些风险继续,拆分阶段再补',design=designSha(ctx),decision='accept_risks',author=AUTHOR,writeEnabled=true}={})=>
|
|
120
|
+
recordPrdNarrowUserDecisionHost({specs:ctx.specs,feature:FEATURE,packageDigest:ctx.packageDigest,authorContextId:author,writeEnabled,
|
|
121
|
+
input:{round,designSha256:design,decision,userWords:words,acceptedFindingIds:ids,at:'2026-11-24T02:00:00.000Z'}});
|
|
122
|
+
test('after the second-round stop the user can accept the remaining risks and continue (dogfood: only cancel was left)',async t=>{
|
|
123
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
124
|
+
changes(ctx,1);await narrowCorrection(ctx);changes(ctx,2,['N2']);
|
|
125
|
+
assert.ok(state(ctx).userDecisionOptions.some(item=>item.startsWith('narrow_user_decision')));
|
|
126
|
+
// The decision must cover exactly the blocking findings, quote the user, and is never written implicitly.
|
|
127
|
+
assert.throws(()=>userDecision(ctx,{ids:[]}),/prd_narrow_user_decision_findings_mismatch/);
|
|
128
|
+
assert.throws(()=>userDecision(ctx,{words:' '}),/prd_narrow_user_decision_invalid/);
|
|
129
|
+
assert.throws(()=>userDecision(ctx,{decision:'approve'}),/prd_narrow_user_decision_invalid/);
|
|
130
|
+
assert.throws(()=>userDecision(ctx,{writeEnabled:false}),/prd_narrow_not_enabled/);
|
|
131
|
+
assert.equal(fs.existsSync(path.join(ctx.specs,'.reviews/prd-guide-design-narrow-decision.json')),false);
|
|
132
|
+
const recorded=userDecision(ctx);
|
|
133
|
+
assert.equal(recorded.status,'narrow_user_decision_recorded');assert.equal(recorded.phase.status,'user_accepted');
|
|
134
|
+
assert.equal(recorded.next,'review_disposition');assert.equal(recorded.completionAuthorized,false);
|
|
135
|
+
assert.deepEqual(recorded.acceptedRisks.findings.map(item=>item.id),['N2']);
|
|
136
|
+
// Once decided: no second decision, no more reviews or corrections; the disposition proceeds.
|
|
137
|
+
assert.throws(()=>userDecision(ctx),/prd_narrow_user_decided/);
|
|
138
|
+
assert.throws(()=>narrowReview(ctx,2,{verdict:'approved',findings:[]}),/prd_narrow_user_decided/);
|
|
139
|
+
await assert.rejects(narrowCorrection(ctx,{ids:['N2']}),/prd_narrow_user_decided/);
|
|
140
|
+
assert.equal(disposition(ctx).status,'disposition_recorded');
|
|
141
|
+
const evidence=prdNarrowUserDecisionEvidence({specs:ctx.specs,feature:FEATURE});
|
|
142
|
+
assert.equal(evidence.risks.userWords,'带着这些风险继续,拆分阶段再补');assert.deepEqual(evidence.risks.findings.map(item=>item.id),['N2']);
|
|
143
|
+
});
|
|
144
|
+
test('a user decision is refused before the stop and when the design changed',async t=>{
|
|
145
|
+
const ctx=fixture(t);await originalCorrection(ctx);
|
|
146
|
+
changes(ctx,1);
|
|
147
|
+
assert.throws(()=>userDecision(ctx,{round:1,ids:['N1']}),/prd_narrow_user_decision_not_available/);
|
|
148
|
+
await narrowCorrection(ctx);changes(ctx,2,['N2']);
|
|
149
|
+
assert.throws(()=>userDecision(ctx,{design:'0'.repeat(64)}),/prd_narrow_design_changed/);
|
|
150
|
+
// A tampered decision record fails closed instead of releasing.
|
|
151
|
+
userDecision(ctx);const file=path.join(ctx.specs,'.reviews/prd-guide-design-narrow-decision.json');
|
|
152
|
+
const value=JSON.parse(fs.readFileSync(file,'utf8'));value.acceptedFindingIds=[];fs.writeFileSync(file,JSON.stringify(value)+'\n',{mode:0o600});
|
|
153
|
+
assert.throws(()=>disposition(ctx),/prd_narrow_user_decision_findings_mismatch/);
|
|
154
|
+
});
|
|
118
155
|
test('a correction without its review record is rejected, also a second one after a correction',async t=>{
|
|
119
156
|
const ctx=fixture(t);await originalCorrection(ctx);
|
|
120
157
|
const before=fs.readFileSync(ctx.designFile,'utf8');
|
|
@@ -230,6 +267,17 @@ test('the legacy record entry cannot close a pending narrow round or rewrite the
|
|
|
230
267
|
assert.equal(fs.existsSync(args(1,1).receipt),false);
|
|
231
268
|
assert.equal(recordPrdReview(args(1,1)).outcome,'recorded');
|
|
232
269
|
});
|
|
270
|
+
test('the legacy record entry binds the user decision too (review r2: receipt without the binding blocked the summary)',async t=>{
|
|
271
|
+
const ctx=fixture(t);await originalCorrection(ctx,{escalate:true});
|
|
272
|
+
const args={stage:'design',feature:'guide',evidence:path.join(ctx.specs,'.reviews/prd-guide-design-r1.md'),
|
|
273
|
+
receipt:path.join(ctx.specs,'.reviews/prd-guide-design-disposition.json'),disposition:'escalated',
|
|
274
|
+
finding_count:1,unresolved_count:1,artifact:[path.join(ctx.specs,FEATURE,'design.md')]};
|
|
275
|
+
changes(ctx,1);await narrowCorrection(ctx);changes(ctx,2,['N2']);userDecision(ctx);
|
|
276
|
+
assert.throws(()=>recordPrdReview({...args,narrow_user_decision_sha256:'0'.repeat(64)}),/prd_narrow_user_decision_binding_mismatch|binding does not match/);
|
|
277
|
+
assert.equal(recordPrdReview(args).outcome,'recorded');
|
|
278
|
+
const decision=fs.readFileSync(path.join(ctx.specs,'.reviews/prd-guide-design-narrow-decision.json'));
|
|
279
|
+
assert.equal(JSON.parse(fs.readFileSync(args.receipt,'utf8')).narrow_user_decision_sha256,sha(decision));
|
|
280
|
+
});
|
|
233
281
|
test('review_findings keeps its exact result shape for older sessions',async t=>{
|
|
234
282
|
const ctx=fixture(t);assert.equal(Object.hasOwn(inspectPrdFindings({specs:ctx.specs,stage:'design',feature:FEATURE}),'authorContextId'),false);
|
|
235
283
|
});
|
|
@@ -8,7 +8,7 @@ import {spawnSync} from 'node:child_process';
|
|
|
8
8
|
import {preparePrdReview} from '../runtime/js/cm-prd/review-preparation.mjs';
|
|
9
9
|
import {publishPrdReview} from '../runtime/js/cm-prd/review-publication.mjs';
|
|
10
10
|
import {recordPrdHostDisposition,createPrdDispositionOwner} from '../runtime/js/cm-prd/review-disposition.mjs';
|
|
11
|
-
import {createPrdCorrectionOwner,inspectPrdCorrectionRecovery,resumePrdCorrection} from '../runtime/js/cm-prd/review-correction.mjs';
|
|
11
|
+
import {createPrdCorrectionOwner,inspectPrdCorrectionRecovery,resumePrdCorrection,previewPrdCorrectionProposal,assertPrdCorrectionRefused} from '../runtime/js/cm-prd/review-correction.mjs';
|
|
12
12
|
import {createPrdSummaryOwner,publishPrdAwaitingReview} from '../runtime/js/cm-prd/summary.mjs';
|
|
13
13
|
import {claimPrdReview} from './cm-prd-review-gate.mjs';
|
|
14
14
|
import {recordPrdTaskScopes} from '../runtime/js/cm-prd/task-scope-record.mjs';
|
|
@@ -220,6 +220,41 @@ for(const recorded of [true,false])test(`correction cannot drop a recorded task
|
|
|
220
220
|
else assert.equal((await run).status,'correction_saved');
|
|
221
221
|
});
|
|
222
222
|
|
|
223
|
+
// dogfood 2026-12-01 问题 7: the driver pre-check runs the same inspection read-only, and a refused
|
|
224
|
+
// answer is provably refused only while no archive exists; a passing answer is never re-asked.
|
|
225
|
+
test('问题7: 修正预检与 prd_correct 同一检查;被拒证明只在存档未写且答复仍不过时成立',t=>{
|
|
226
|
+
const {args,save}=fixture(t,{stage:'split',finding:true,scoped:true});save();
|
|
227
|
+
const proposal=dropScope=>({decisions:[{id:'R1',status:'applied',evidence:['Clarified'],
|
|
228
|
+
changedPaths:['1.guide/design.md',...(dropScope?['1.guide/tasks.md']:[])]}],
|
|
229
|
+
documents:args.artifacts.map(item=>{const content=fs.readFileSync(path.join(args.specs,item.path),'utf8');
|
|
230
|
+
return {path:item.path,content:item.path.endsWith('/design.md')?content+'\nSecret clarified text':dropScope&&item.path.endsWith('/tasks.md')?'- [ ] T-001: Guide':content};})});
|
|
231
|
+
const input={specs:args.specs,stage:'split',feature:'1.guide'};
|
|
232
|
+
const refused=previewPrdCorrectionProposal({...input,proposal:proposal(true)});
|
|
233
|
+
assert.deepEqual(refused,{status:'refused',reason:'prd_correction_mechanics_failed',
|
|
234
|
+
failedChecks:[{feature:'1.guide',code:'task_scope_missing',field:'1.guide/tasks.md'}]});
|
|
235
|
+
assert.doesNotMatch(JSON.stringify(refused),/Secret clarified text/);
|
|
236
|
+
assert.deepEqual(previewPrdCorrectionProposal({...input,proposal:proposal(false)}),{status:'passed'});
|
|
237
|
+
assert.equal(assertPrdCorrectionRefused({...input,proposal:proposal(true)}),'prd_correction_mechanics_failed');
|
|
238
|
+
assert.throws(()=>assertPrdCorrectionRefused({...input,proposal:proposal(false)}),{code:'prd_correction_recovery_required'});
|
|
239
|
+
fs.writeFileSync(path.join(args.specs,'.reviews/prd-guide-split-correction.md'),'archive',{mode:0o600});
|
|
240
|
+
assert.throws(()=>assertPrdCorrectionRefused({...input,proposal:proposal(true)}),{code:'prd_correction_recovery_required'});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// Review r1 A2: only an actual mechanical refusal of the proposal qualifies; a check that could not
|
|
244
|
+
// run (damaged task-scope record) or another refusal path never lets an answer be discarded.
|
|
245
|
+
test('问题7 r1-A2: 检查自身出错(任务范围记录损坏)或非机械拒收不算被拒,不准作废',t=>{
|
|
246
|
+
const {args,save}=fixture(t,{stage:'split',finding:true,scoped:true});save();
|
|
247
|
+
const documents=args.artifacts.map(item=>({path:item.path,content:item.path.endsWith('/tasks.md')?'- [ ] T-001: Guide'
|
|
248
|
+
:fs.readFileSync(path.join(args.specs,item.path),'utf8')+(item.path.endsWith('/design.md')?'\nClarified':'')}));
|
|
249
|
+
const proposal={decisions:[{id:'R1',status:'applied',evidence:['Clarified'],changedPaths:['1.guide/design.md','1.guide/tasks.md']}],documents};
|
|
250
|
+
const input={specs:args.specs,stage:'split',feature:'1.guide'};
|
|
251
|
+
// Not the mechanics: an incomplete decision list is refused on another path.
|
|
252
|
+
assert.throws(()=>assertPrdCorrectionRefused({...input,proposal:{...proposal,decisions:[]}}),{code:'prd_correction_recovery_required'});
|
|
253
|
+
const record=path.join(args.specs,'.reviews/prd-guide-task-scope.json');
|
|
254
|
+
fs.chmodSync(record,0o600);fs.writeFileSync(record,'{"damaged":true}',{mode:0o600});
|
|
255
|
+
assert.throws(()=>assertPrdCorrectionRefused({...input,proposal}),{code:'prd_correction_recovery_required'});
|
|
256
|
+
});
|
|
257
|
+
|
|
223
258
|
// F2: a saved correction whose single check fails must still reach the human.
|
|
224
259
|
async function failedCorrectionFixture(t,{mechanical=false,scopeDropped=false}={}){
|
|
225
260
|
const f=fixture(t,{stage:'split',finding:true,scoped:scopeDropped});f.save();let calls=0;
|
|
@@ -317,6 +352,64 @@ for(const rules of [4,3])test(`summary holds a rule-4 save to its session-task c
|
|
|
317
352
|
assert.deepEqual(summary.mechanicalSelfCheck.findings.map(item=>item.code),rules===4?['session_task_multiple']:[]);
|
|
318
353
|
});
|
|
319
354
|
|
|
355
|
+
// 防回归(审查 r1 B1):规则 8 保存的规格经手工修正删掉会话任务的必跑检查时,处置回执绑定所选的复查选项,
|
|
356
|
+
// 失败检查才能按同一选项复验、写成回执交人裁决(之前报 prd_failed_check_binding)。
|
|
357
|
+
test('rule-8 failed correction binds its re-check options so the failed receipt verifies and reaches the human',async t=>{
|
|
358
|
+
const tasks=`${SESSION_TASKS}\n - 必跑检查: \`sh scripts/check-walk.sh\``;
|
|
359
|
+
const f=fixture(t,{stage:'split',finding:true,tasks,rules:8});f.save();
|
|
360
|
+
const correction=await createPrdCorrectionOwner({correct:async({documents})=>({
|
|
361
|
+
documents:documents.map(doc=>({path:doc.path,content:doc.content+(doc.path.endsWith('/design.md')?'\nCorrection':'')})),
|
|
362
|
+
decisions:[{id:'R1',status:'applied',evidence:['Saved original correction'],changedPaths:['1.guide/design.md']}]
|
|
363
|
+
})})({...f.args},new AbortController().signal);
|
|
364
|
+
Object.assign(f.args,structuredClone({decisions:correction.decisions,artifacts:correction.artifacts}));
|
|
365
|
+
const file='1.guide/tasks.md';fs.writeFileSync(path.join(f.args.specs,file),SESSION_TASKS);
|
|
366
|
+
f.args.artifacts.find(a=>a.path===file).sha256=sha(fs.readFileSync(path.join(f.args.specs,file)));
|
|
367
|
+
f.args.decisions[0].changedPaths.push(file);
|
|
368
|
+
const owner=createPrdDispositionOwner({checkContext:async()=>{throw Error('must_not_dispatch');}});
|
|
369
|
+
const result=await owner(f.args,new AbortController().signal);
|
|
370
|
+
assert.equal(result.gate.disposition,'self_check_failed');
|
|
371
|
+
assert.deepEqual(result.mechanicalSelfCheck.findings.map(item=>item.code),['session_task_evidence_missing']);
|
|
372
|
+
const input=JSON.parse(fs.readFileSync(f.receipt)).correction_check.input.draft;
|
|
373
|
+
assert.deepEqual([input.sessionEvidence,input.inapplicableAcceptance,input.sessionEvidenceExempt],[['1.guide'],['1.guide'],undefined]);
|
|
374
|
+
const summary=await humanSummary()(f.args.specs);
|
|
375
|
+
assert.equal(summary.riskCard[0].status,'awaiting_human_ruling');
|
|
376
|
+
assert.match(summary.details.risks,/session_task_evidence_missing/);
|
|
377
|
+
// A receipt whose bound options were dropped no longer verifies as the check that ran.
|
|
378
|
+
const receipt=JSON.parse(fs.readFileSync(f.receipt));delete receipt.correction_check.input.draft.sessionEvidence;
|
|
379
|
+
const {inspectPrdFailedCorrection}=await import('../runtime/js/cm-prd/failed-correction.mjs');
|
|
380
|
+
assert.throws(()=>inspectPrdFailedCorrection({specs:f.args.specs,receipt}),/prd_failed_check_binding/);
|
|
381
|
+
});
|
|
382
|
+
// 防回归(审查 r2 阻断 1、r3 阻断 1):规则 5、6、7 保存的规格,修正检查输入与旧版逐字节相同(不加新字段),
|
|
383
|
+
// 失败回执在「NOT_APPLICABLE 未覆盖 AC + 格式错误任务行 + 无范围任务」时也能复验,交人裁决而不是报 prd_failed_check_binding。
|
|
384
|
+
for(const rules of [5,6,7])test(`a rule-${rules} failed disposition keeps the old check input and its receipt still verifies`,async t=>{
|
|
385
|
+
// Without a 必跑检查 (rules 5, 6), so a later rule-8 record would judge these files differently.
|
|
386
|
+
const tasks=rules===7?`${SESSION_TASKS}\n - 必跑检查: \`sh scripts/check-walk.sh\``:rules===6?`${SCOPED_TASKS}\n - 开发: 会话`:SESSION_TASKS;
|
|
387
|
+
const f=fixture(t,{stage:'split',finding:true,tasks,rules,testCases:true});f.save();
|
|
388
|
+
const correction=await createPrdCorrectionOwner({correct:async({documents})=>({
|
|
389
|
+
documents:documents.map(doc=>({path:doc.path,content:doc.content+(doc.path.endsWith('/design.md')?'\nCorrection':'')})),
|
|
390
|
+
decisions:[{id:'R1',status:'applied',evidence:['Saved original correction'],changedPaths:['1.guide/design.md']}]
|
|
391
|
+
})})({...f.args},new AbortController().signal);
|
|
392
|
+
Object.assign(f.args,structuredClone({decisions:correction.decisions,artifacts:correction.artifacts}));
|
|
393
|
+
for(const [file,content] of [['1.guide/tasks.md',`${tasks}\n- [q] T-008: Invalid marker\n- [ ] T-009: Unscoped`],
|
|
394
|
+
['1.guide/requirements.md','## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Document setup.\n- [ ] [AC-002] NOT_APPLICABLE: 本期不做']]){
|
|
395
|
+
fs.writeFileSync(path.join(f.args.specs,file),content);
|
|
396
|
+
f.args.artifacts.find(a=>a.path===file).sha256=sha(fs.readFileSync(path.join(f.args.specs,file)));
|
|
397
|
+
f.args.decisions[0].changedPaths.push(file);
|
|
398
|
+
}
|
|
399
|
+
const owner=createPrdDispositionOwner({checkContext:async()=>{throw Error('must_not_dispatch');}});
|
|
400
|
+
const result=await owner(f.args,new AbortController().signal);
|
|
401
|
+
assert.equal(result.gate.disposition,'self_check_failed');
|
|
402
|
+
assert.ok(!result.mechanicalSelfCheck.findings.some(item=>item.code==='acceptance_test_coverage_missing'),'the exemption applied');
|
|
403
|
+
const input=JSON.parse(fs.readFileSync(f.receipt)).correction_check.input.draft;
|
|
404
|
+
for(const key of ['inapplicableAcceptance','sessionEvidence','sessionEvidenceExempt'])assert.equal(input[key],undefined,key);
|
|
405
|
+
const summary=await humanSummary()(f.args.specs);
|
|
406
|
+
assert.equal(summary.riskCard[0].status,'awaiting_human_ruling');
|
|
407
|
+
// 审查 r2 第 2 项:之后的保存把范围记录改写成规则 8,旧回执仍按自己的输入复验。
|
|
408
|
+
const {inspectPrdFailedCorrection}=await import('../runtime/js/cm-prd/failed-correction.mjs');
|
|
409
|
+
const record=path.join(f.args.specs,'.reviews/prd-guide-task-scope.json');
|
|
410
|
+
fs.writeFileSync(record,JSON.stringify({...JSON.parse(fs.readFileSync(record,'utf8')),selfCheckRules:8})+'\n',{mode:0o600});
|
|
411
|
+
assert.equal(inspectPrdFailedCorrection({specs:f.args.specs,receipt:JSON.parse(fs.readFileSync(f.receipt))}).status,'failed');
|
|
412
|
+
});
|
|
320
413
|
// Evidence recorded before the scope policy joined the check input (no taskScopes)
|
|
321
414
|
// still verifies, without options or under the record on disk.
|
|
322
415
|
test('F2 legacy failed-check evidence without taskScopes still verifies',async t=>{
|
|
@@ -129,7 +129,11 @@ function loadReceipt(file,args,evidence){
|
|
|
129
129
|
need(!link(file),'PRD review receipt must not be a symlink','prd_review_receipt_invalid',where);
|
|
130
130
|
const value=parseJson(read(file,'prd_review_receipt_invalid',where()),'prd_review_receipt_invalid',where());
|
|
131
131
|
need(keys(value,['schema_version','stage','feature','status','disposition','finding_count','unresolved_count',
|
|
132
|
-
'evidence','evidence_sha256','artifacts','at',...(value?.disposition==='self_check_failed'?['correction_check']:[])
|
|
132
|
+
'evidence','evidence_sha256','artifacts','at',...(value?.disposition==='self_check_failed'?['correction_check']:[]),
|
|
133
|
+
...(Object.hasOwn(value??{},'narrow_user_decision_sha256')?['narrow_user_decision_sha256']:[])]),'PRD review receipt fields do not match the contract','prd_review_receipt_invalid',where);
|
|
134
|
+
// Design only: the user's accept-risks decision this receipt released on (narrow review stop).
|
|
135
|
+
if(Object.hasOwn(value,'narrow_user_decision_sha256'))need(value.stage==='design'&&typeof value.narrow_user_decision_sha256==='string'&&/^[0-9a-f]{64}$/.test(value.narrow_user_decision_sha256),
|
|
136
|
+
'PRD review receipt narrow decision binding is invalid','prd_review_receipt_invalid',where);
|
|
133
137
|
need(value.schema_version===1&&value.stage===args.stage&&value.feature===args.feature&&value.status==='completed'
|
|
134
138
|
&&value.evidence===path.basename(evidence)&&value.evidence_sha256===hash(evidence,'prd_review_evidence_invalid',{evidence:reviewFile(evidence)}),'PRD review receipt does not match current evidence',
|
|
135
139
|
'prd_review_receipt_evidence_mismatch',()=>({receipt,evidence:reviewFile(evidence)}));
|
|
@@ -308,8 +312,10 @@ export function recordPrdReview(args){
|
|
|
308
312
|
}
|
|
309
313
|
const {evidence,receipt}=paths(args),base={stage:args.stage,feature:args.feature};evidenceHeader(evidence);
|
|
310
314
|
if(stat(receipt)){loadReceipt(receipt,args,evidence);return {...base,outcome:'already_recorded'};}
|
|
311
|
-
|
|
312
|
-
findingCount:args.finding_count,unresolvedCount:args.unresolved_count});
|
|
315
|
+
const narrowDecisionSha=args.stage==='design'?assertNarrowReceiptAllowed({specs:resolve(path.dirname(path.dirname(receipt))),slug:args.feature,
|
|
316
|
+
findingCount:args.finding_count,unresolvedCount:args.unresolved_count})??null:null;
|
|
317
|
+
need((args.narrow_user_decision_sha256??null)===null||args.narrow_user_decision_sha256===narrowDecisionSha,
|
|
318
|
+
'narrow decision binding does not match the recorded user decision','prd_narrow_user_decision_binding_mismatch');
|
|
313
319
|
const root=resolve(path.dirname(path.dirname(receipt))),seen=new Set();
|
|
314
320
|
need(Array.isArray(args.artifact)&&args.artifact.length>0,'artifact required','prd_review_artifact_required');
|
|
315
321
|
const artifacts=args.artifact.map(raw=>{
|
|
@@ -321,7 +327,8 @@ export function recordPrdReview(args){
|
|
|
321
327
|
const value={schema_version:1,...base,status:'completed',disposition:args.disposition,finding_count:args.finding_count,
|
|
322
328
|
unresolved_count:args.unresolved_count,evidence:path.basename(evidence),evidence_sha256:hash(evidence,'prd_review_evidence_invalid',{evidence:reviewFile(evidence)}),artifacts,
|
|
323
329
|
at:new Date().toISOString().replace(/\.\d{3}Z$/,'+00:00'),
|
|
324
|
-
...(args.disposition==='self_check_failed'?{correction_check:args.correction_check}:{})
|
|
330
|
+
...(args.disposition==='self_check_failed'?{correction_check:args.correction_check}:{}),
|
|
331
|
+
...(narrowDecisionSha?{narrow_user_decision_sha256:narrowDecisionSha}:{})};
|
|
325
332
|
if(value.disposition==='self_check_failed')inspectPrdFailedCorrection({specs:root,receipt:value});
|
|
326
333
|
const temp=path.join(path.dirname(receipt),`.${path.basename(receipt)}.${randomUUID()}`);let fd;
|
|
327
334
|
try{
|