@aibyzero/cm-workflow 0.16.4 → 0.16.6
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 +22 -0
- package/CHANGELOG.md +57 -0
- package/README.md +22 -4
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/VERSION +1 -1
- package/docs/architecture.md +43 -0
- package/docs/execution-optimizations.md +33 -0
- package/docs/external-models.md +114 -0
- package/docs/fixes/.reviews/20260929-bootstrap-unchanged-review-r1.md +7 -0
- package/docs/fixes/.reviews/20260930-develop-package-limit-recovery-r4.md +9 -0
- package/docs/fixes/20260929-bootstrap-rule-refresh-conflict.md +22 -0
- package/docs/fixes/20260929-bootstrap-unchanged-review.md +26 -0
- package/docs/fixes/20260930-develop-package-limit-recovery.md +65 -0
- package/docs/human-correction.md +31 -0
- package/docs/installation.md +48 -7
- package/docs/js-workflow-control.md +293 -33
- package/docs/live-evidence-drivers.md +62 -0
- package/docs/next-steps.md +15 -10
- package/docs/runtime-failover.md +1 -1
- package/docs/untested-branches.md +27 -4
- package/docs/user-guide.md +23 -8
- package/install-codex.sh +28 -11
- package/package.json +1 -1
- package/runtime/js/cm-ai/accepted-fix.mjs +23 -5
- package/runtime/js/cm-ai/bootstrap-feature.mjs +15 -0
- package/runtime/js/cm-ai/claude-review-adapter.mjs +7 -4
- package/runtime/js/cm-ai/claude-review-stream.mjs +12 -0
- package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -4
- package/runtime/js/cm-ai/cm-ai-admission.mjs +115 -41
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +208 -34
- package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +22 -5
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +181 -57
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +15 -58
- package/runtime/js/cm-ai/codex-config.mjs +3 -2
- package/runtime/js/cm-ai/codex-review-adapter.mjs +56 -17
- package/runtime/js/cm-ai/committed-rule-basis.mjs +76 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +6 -2
- package/runtime/js/cm-ai/diagnostic-reason.mjs +10 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +315 -0
- package/runtime/js/cm-ai/drive-core.mjs +47 -9
- package/runtime/js/cm-ai/durable-runner-state.mjs +413 -56
- package/runtime/js/cm-ai/effect-abandon-log.mjs +19 -0
- package/runtime/js/cm-ai/effect-contract.mjs +44 -2
- package/runtime/js/cm-ai/execution-policy.mjs +58 -0
- package/runtime/js/cm-ai/execution-store-limits.mjs +18 -0
- package/runtime/js/cm-ai/execution-store.mjs +6 -4
- package/runtime/js/cm-ai/external-group-models.mjs +53 -0
- package/runtime/js/cm-ai/external-model-launch.mjs +23 -0
- package/runtime/js/cm-ai/external-models.mjs +52 -0
- package/runtime/js/cm-ai/external-run-guard.mjs +96 -0
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +126 -29
- package/runtime/js/cm-ai/host-check.mjs +30 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +66 -20
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-progress.mjs +80 -0
- package/runtime/js/cm-ai/host-project-execution.mjs +16 -11
- package/runtime/js/cm-ai/host-qa-executor.mjs +23 -9
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +23 -6
- package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
- package/runtime/js/cm-ai/host-session.mjs +12 -4
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +16 -5
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/knowledge-closeout.mjs +56 -0
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/legacy-model-run-preview.mjs +24 -0
- package/runtime/js/cm-ai/legacy-model-settings.mjs +59 -0
- package/runtime/js/cm-ai/live-evidence.mjs +96 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/model-configuration-file.mjs +63 -0
- package/runtime/js/cm-ai/model_configuration_write.py +214 -0
- package/runtime/js/cm-ai/native-usage-log.mjs +26 -0
- package/runtime/js/cm-ai/operator-guidance.mjs +86 -0
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +22 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +68 -9
- package/runtime/js/cm-ai/provider-usage.mjs +39 -0
- package/runtime/js/cm-ai/qa-config-revision.mjs +44 -10
- package/runtime/js/cm-ai/review-abandon-log.mjs +21 -0
- package/runtime/js/cm-ai/review-package.mjs +438 -31
- package/runtime/js/cm-ai/review-presentation.mjs +45 -0
- package/runtime/js/cm-ai/review-reconciliation.mjs +20 -0
- package/runtime/js/cm-ai/review-runner.mjs +47 -1
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +97 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +104 -10
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +42 -3
- package/runtime/js/cm-ai/specification-material.mjs +154 -12
- package/runtime/js/cm-ai/status-projection.mjs +93 -0
- package/runtime/js/cm-ai/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +658 -75
- package/runtime/js/cm-ai/tool-preview.mjs +8 -4
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-ai/worker-claude.mjs +63 -19
- package/runtime/js/cm-ai/worker-codex-developer.mjs +15 -9
- package/runtime/js/cm-ai/worker-codex.mjs +45 -19
- package/runtime/js/cm-fix/cause-evidence.mjs +5 -3
- package/runtime/js/cm-fix/cause-invocation.mjs +6 -3
- package/runtime/js/cm-fix/cause-package.mjs +10 -1
- package/runtime/js/cm-fix/execution.mjs +279 -52
- package/runtime/js/cm-fix/final-review.mjs +18 -10
- package/runtime/js/cm-fix/host-review.mjs +32 -9
- package/runtime/js/cm-fix/host.mjs +6 -1
- package/runtime/js/cm-fix/layout.mjs +1 -1
- package/runtime/js/cm-fix/progress.mjs +5 -0
- package/runtime/js/cm-fix/protected-edits.mjs +15 -4
- package/runtime/js/cm-fix/qa-source.mjs +6 -4
- package/runtime/js/cm-fix/review-reconciliation.mjs +64 -0
- package/runtime/js/cm-prd/analysis.mjs +2 -1
- package/runtime/js/cm-prd/change.mjs +28 -10
- package/runtime/js/cm-prd/draft.mjs +5 -2
- package/runtime/js/cm-prd/response-recovery.mjs +23 -0
- package/runtime/js/cm-prd/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +27 -15
- package/runtime/js/cm-prd/review-time.mjs +29 -0
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/session.mjs +53 -6
- package/runtime/js/cm-prd/summary.mjs +3 -1
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/cm-security/finalize.mjs +32 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +10 -3
- package/runtime/review.md +5 -0
- package/runtime/task-gates.md +6 -0
- package/runtime/workflow-config.md +10 -1
- package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
- package/scripts/cm-ai-admission.mjs +18 -11
- package/scripts/cm-ai-admission.test.mjs +65 -1
- package/scripts/cm-ai-batch-drive.mjs +135 -34
- package/scripts/cm-ai-batch-drive.test.mjs +209 -3
- package/scripts/cm-ai-batch-host.mjs +63 -24
- package/scripts/cm-ai-batch-host.test.mjs +2 -1
- package/scripts/cm-ai-batch-run.mjs +101 -34
- package/scripts/cm-ai-batch-run.test.mjs +56 -5
- package/scripts/cm-ai-bootstrap-driver-preflight.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap-flow.test.mjs +159 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +162 -0
- package/scripts/cm-ai-bootstrap.test.mjs +174 -89
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +97 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +924 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +468 -0
- package/scripts/cm-ai-drive-timeout.test.mjs +17 -0
- package/scripts/cm-ai-drive.mjs +526 -60
- package/scripts/cm-ai-drive.test.mjs +336 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +142 -43
- package/scripts/cm-ai-host.test.mjs +232 -12
- package/scripts/cm-ai-launch-diagnostics.test.mjs +142 -0
- package/scripts/cm-ai-multi-root.test.mjs +9 -3
- package/scripts/cm-ai-operator-guidance.test.mjs +94 -0
- package/scripts/cm-ai-progress.test.mjs +521 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +187 -15
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +157 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +27 -2
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +400 -0
- package/scripts/cm-ai-review-drift-precedence.test.mjs +90 -0
- package/scripts/cm-ai-review-failure.test.mjs +977 -0
- package/scripts/cm-ai-review-timeout-config.test.mjs +29 -7
- package/scripts/cm-ai-review-timeout.test.mjs +199 -4
- package/scripts/cm-ai-run.mjs +206 -62
- package/scripts/cm-ai-run.test.mjs +6 -4
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +219 -0
- package/scripts/cm-ai-selection-guard.test.mjs +100 -0
- package/scripts/cm-ai-session-chain.test.mjs +7 -3
- package/scripts/cm-ai-spec-rebind.test.mjs +481 -0
- package/scripts/cm-ai-supersede.test.mjs +571 -17
- package/scripts/cm-ai-verification-gate.test.mjs +2 -1
- package/scripts/cm-bootstrap-review-recovery.test.mjs +70 -0
- package/scripts/cm-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.test.mjs +2 -1
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +12 -1
- package/scripts/cm-claude-developer-worker.test.mjs +3 -1
- package/scripts/cm-claude-install-layout.test.mjs +26 -0
- package/scripts/cm-claude-probe.test.mjs +10 -2
- package/scripts/cm-claude-review-stream.test.mjs +25 -0
- package/scripts/cm-claude-worker.test.mjs +11 -4
- package/scripts/cm-codex-developer-worker.test.mjs +4 -2
- package/scripts/cm-codex-plugin-metadata.py +83 -0
- package/scripts/cm-codex-plugin-metadata.test.mjs +55 -0
- package/scripts/cm-efficiency-checks.test.mjs +37 -0
- package/scripts/cm-efficiency-diagnostics.test.mjs +74 -0
- package/scripts/cm-efficiency-offline.mjs +35 -0
- package/scripts/cm-efficiency-policy.test.mjs +48 -0
- package/scripts/cm-efficiency-presentation.test.mjs +35 -0
- package/scripts/cm-efficiency-response.test.mjs +117 -0
- package/scripts/cm-efficiency-usage.test.mjs +148 -0
- package/scripts/cm-external-batch-host.test.mjs +157 -0
- package/scripts/cm-external-fix-host.test.mjs +281 -0
- package/scripts/cm-external-fix-reconciliation.test.mjs +105 -0
- package/scripts/cm-external-group-models.test.mjs +60 -0
- package/scripts/cm-external-model-host.test.mjs +180 -0
- package/scripts/cm-external-model-recovery.test.mjs +108 -0
- package/scripts/cm-external-models.test.mjs +89 -0
- package/scripts/cm-external-process-cleanup.test.mjs +71 -0
- package/scripts/cm-external-qa-fix.test.mjs +170 -0
- package/scripts/cm-external-review-reconciliation.test.mjs +314 -0
- package/scripts/cm-failover.mjs +8 -8
- package/scripts/cm-fix-abandon.test.mjs +123 -5
- package/scripts/cm-fix-cause-package.test.mjs +2 -0
- package/scripts/cm-fix-drive.mjs +70 -23
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-final-review.test.mjs +11 -6
- package/scripts/cm-fix-host.mjs +24 -14
- package/scripts/cm-fix-protected-edits.test.mjs +12 -0
- package/scripts/cm-fix-rediagnosis.test.mjs +168 -0
- package/scripts/cm-fix-review-budget.test.mjs +147 -0
- package/scripts/cm-fixture-process-cleanup.test.mjs +95 -0
- package/scripts/cm-host-check.test.mjs +6 -3
- package/scripts/cm-host-qa-executor.test.mjs +213 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-knowledge-closeout.test.mjs +160 -0
- package/scripts/cm-live-evidence.test.mjs +64 -0
- package/scripts/cm-log-event.mjs +25 -2
- package/scripts/cm-log-event.py +15 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-model-setup.mjs +79 -0
- package/scripts/cm-prd-completion.test.mjs +75 -0
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-drive.mjs +32 -11
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- package/scripts/cm-prd-host.mjs +13 -4
- package/scripts/cm-prd-review-gate.mjs +126 -81
- package/scripts/cm-prd-review-gate.test.mjs +105 -1
- package/scripts/cm-prd-review-preparation.test.mjs +15 -0
- package/scripts/cm-prd-review-publication.test.mjs +6 -0
- package/scripts/cm-prd-self-check.test.mjs +6 -0
- package/scripts/cm-prd-summary.test.mjs +9 -0
- package/scripts/cm-release-smoke.sh +5 -1
- package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- package/scripts/cm-runtime-i18n.mjs +15 -4
- package/scripts/cm-runtime-install.mjs +8 -4
- package/scripts/cm-runtime.mjs +116 -23
- package/scripts/cm-runtime.test.mjs +121 -12
- package/scripts/cm-security.test.mjs +32 -0
- package/scripts/cm-spec-manifest.mjs +28 -10
- package/scripts/cm-spec-manifest.test.mjs +8 -4
- package/scripts/cm-spec-task-line.test.mjs +138 -0
- package/scripts/cm-specs-status.test.mjs +12 -1
- package/scripts/cm-task-gate-correction.test.mjs +117 -0
- package/scripts/cm-task-gate.mjs +164 -20
- package/scripts/cm-task-gate.py +2 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/cm-test-drive.mjs +10 -4
- package/scripts/cm-test-drive.test.mjs +14 -1
- package/scripts/cm-tool-preview-context.test.mjs +12 -0
- package/scripts/cm-usage-report.py +22 -3
- package/scripts/cm-workflow-config.mjs +10 -1
- package/scripts/fixtures/bootstrap-review-runner.mjs +102 -0
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/live-evidence-driver.mjs +35 -0
- package/scripts/fixtures/process-cleanup.mjs +101 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-native-usage.py +62 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-external-model-setup.py +91 -0
- package/scripts/test-model-configuration-write.py +201 -0
- package/scripts/test-npm-install.py +11 -2
- package/scripts/test-scan-public-safety.py +1 -1
- package/scripts/test-spec-manifest.py +16 -8
- package/scripts/test-task-gate.py +2 -2
- package/scripts/test-workflow-config.py +1 -0
- package/scripts/validate-public-repo.py +1 -0
- package/skills/cm-ai/SKILL.md +2 -2
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/N8-finish.md +5 -0
- package/skills/cm-ai/references/js-host.md +270 -43
- package/skills/cm-ai/references/knowledge-closeout.md +90 -0
- package/skills/cm-fix/SKILL.md +1 -1
- package/skills/cm-fix/references/js-host.md +52 -3
- package/skills/cm-prd/references/js-change-recovery.md +1 -1
- package/skills/cm-prd/references/js-host.md +6 -0
- package/skills/cm-runtime/SKILL.md +29 -6
- package/skills/cm-security/SKILL.md +4 -2
- package/skills/cm-security/references/scan-contract.md +1 -0
- package/templates/cm-workflow.yml +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {readExecutionPolicy} from '../cm-ai/execution-policy.mjs';
|
|
2
|
+
import {inspectFixReconciledResult} from './review-reconciliation.mjs';
|
|
1
3
|
// Existing V3 grants and standard implementation-review observations only.
|
|
2
4
|
// The owning execution store registers callbacks; this module issues no receipt.
|
|
3
5
|
import {randomUUID} from 'node:crypto';
|
|
@@ -15,10 +17,10 @@ import {inspectFixRegressionFailure} from './regression-evidence.mjs';
|
|
|
15
17
|
export function fixFinalReviewConfiguration(configuration,causeThread=null){
|
|
16
18
|
const hosts=fixHostContexts(configuration);
|
|
17
19
|
const base=validateCauseReviewer(configuration.causeReview,hosts);
|
|
18
|
-
return {hostContextId:configuration.hostContextId,...(hosts.length>1?{hostContextIds:hosts}:{}),
|
|
20
|
+
return {...(configuration.executionPolicy?{executionPolicy:readExecutionPolicy(configuration.executionPolicy)}:{}),...(configuration.externalModels?{externalModels:configuration.externalModels}:{}),hostContextId:configuration.hostContextId,...(hosts.length>1?{hostContextIds:hosts}:{}),
|
|
19
21
|
reviewer:{...base,reviewerId:'fix-final-reviewer',
|
|
20
22
|
adapterId:`${base.provider}-review-adapter`,contextId:'fix-final-review-context',
|
|
21
|
-
excludedThreadIds:[...new Set([...base.excludedThreadIds,...(causeThread?[causeThread]:[])])]}};
|
|
23
|
+
excludedThreadIds:[...new Set([...base.excludedThreadIds,...(Array.isArray(causeThread)?causeThread:causeThread?[causeThread]:[])])]}};
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
function expectation(request,configuration){
|
|
@@ -46,7 +48,7 @@ function reviewDiagnostic(phase,error,event=null){
|
|
|
46
48
|
}
|
|
47
49
|
export function inspectFixFinalRegistration(raw,configuration){
|
|
48
50
|
const value=json(raw,12*1024*1024);shape(value,['request','authorizationAt','registeredAt','grant']);
|
|
49
|
-
const reviewer=validateCauseReviewer(configuration.reviewer,fixHostContexts(configuration),configuration.reviewFeedback?34
|
|
51
|
+
const reviewer=validateCauseReviewer(configuration.reviewer,fixHostContexts(configuration),configuration.reviewFeedback?35:34),request=value.request;
|
|
50
52
|
need(request.provider===reviewer.provider&&request.requestedModel===reviewer.requestedModel&&request.contextId===reviewer.contextId,'final_registration_mismatch');
|
|
51
53
|
const pkg=readReviewPackage(request.payload.reviewPackage);
|
|
52
54
|
const previous=configuration.reviewFeedback?inspectFixRepairReview(configuration.reviewFeedback,pkg.identity):null;
|
|
@@ -59,10 +61,12 @@ export function inspectFixFinalRegistration(raw,configuration){
|
|
|
59
61
|
return value;
|
|
60
62
|
}
|
|
61
63
|
export function inspectFixFinalResult(raw,registration,configuration,started){
|
|
62
|
-
const value=json(raw,1024*1024);shape(value,['dispatchAt','observation']);
|
|
64
|
+
const value=json(raw,1024*1024);shape(value,['dispatchAt','observation',...(Object.hasOwn(value,'reconciliationReceipt')?['reconciliationReceipt']:[])]);
|
|
63
65
|
need(Number.isSafeInteger(value.dispatchAt)&&value.dispatchAt>=registration.registeredAt
|
|
64
66
|
&&value.dispatchAt<registration.grant.expiresAt,'final_registration_mismatch');
|
|
65
|
-
|
|
67
|
+
need(!value.reconciliationReceipt||(configuration.externalModels||configuration.executionPolicy),'review_reconciliation_unavailable');
|
|
68
|
+
const expected=expectation(registration.request,configuration);
|
|
69
|
+
const checked=value.reconciliationReceipt?inspectFixReconciledResult(value,expected):inspectProviderReview(JSON.stringify(value.observation),JSON.stringify(expected));
|
|
66
70
|
need(checked.providerThreadId===started,'final_registration_mismatch');return checked;
|
|
67
71
|
}
|
|
68
72
|
|
|
@@ -108,16 +112,17 @@ export function fixRevisionReviewConfiguration(feedback,nextIdentity,hostContext
|
|
|
108
112
|
|
|
109
113
|
export function createFixFinalReview({reviewPackage,configuration,timeoutMs},{authorize,run}){
|
|
110
114
|
const pkg=readReviewPackage(reviewPackage);need(pkg.handoff,'final_handoff_required');
|
|
111
|
-
const config=json(configuration,12*1024*1024);shape(config,['hostContextId','reviewer',
|
|
115
|
+
const config=json(configuration,12*1024*1024);shape(config,['hostContextId','reviewer',...(Object.hasOwn(config,'externalModels')?['externalModels']:[]),...(Object.hasOwn(config,'executionPolicy')?['executionPolicy']:[]),
|
|
112
116
|
...(Object.hasOwn(config,'hostContextIds')?['hostContextIds']:[]),
|
|
113
117
|
...(Object.hasOwn(config,'reviewFeedback')?['reviewFeedback']:[])]);
|
|
118
|
+
if(config.executionPolicy)readExecutionPolicy(config.executionPolicy);
|
|
114
119
|
const previous=config.reviewFeedback?inspectFixRepairReview(config.reviewFeedback,pkg.identity):null;
|
|
115
|
-
const reviewer=validateCauseReviewer(config.reviewer,fixHostContexts(config),previous?34
|
|
120
|
+
const reviewer=validateCauseReviewer(config.reviewer,fixHostContexts(config),previous?35:34);
|
|
116
121
|
if(previous)need(reviewer.excludedThreadIds.includes(previous.providerThreadId),'final_context_mismatch');
|
|
117
122
|
need(Number.isInteger(timeoutMs)&&timeoutMs>0&&timeoutMs<=3600000,'invalid_timeout');
|
|
118
123
|
need(typeof authorize==='function'&&typeof run==='function','final_review_unavailable');
|
|
119
124
|
let used=false;
|
|
120
|
-
return async({signal,register,onStarted})=>{
|
|
125
|
+
return async({signal,register,onStarted,onReconciliation})=>{
|
|
121
126
|
need(!used,'final_review_already_attempted');need(!signal.aborted,'cancelled');
|
|
122
127
|
need(typeof register==='function'&&typeof onStarted==='function','final_registration_required');used=true;
|
|
123
128
|
const request=requestFor({invocationId:`fix-final.${randomUUID()}`,identity:pkg.identity,role:'reviewer',provider:reviewer.provider,
|
|
@@ -145,9 +150,11 @@ export function createFixFinalReview({reviewPackage,configuration,timeoutMs},{au
|
|
|
145
150
|
events.push(event);return true;
|
|
146
151
|
}catch(error){diagnostic=reviewDiagnostic(eventPhase,error,event);controller.abort();return false;}
|
|
147
152
|
};
|
|
153
|
+
let transport;
|
|
148
154
|
try{
|
|
149
155
|
timer=setTimeout(()=>{timedOut=true;controller.abort();},timeoutMs);
|
|
150
|
-
|
|
156
|
+
transport=Promise.resolve().then(()=>{need(!controller.signal.aborted,'cancelled');return run(request,{signal:controller.signal,onEvent,...(onReconciliation?{onReconciliation}:{})});});
|
|
157
|
+
const result=await Promise.race([interrupted,transport]);
|
|
151
158
|
need(!controller.signal.aborted,'interrupted');
|
|
152
159
|
const value={dispatchAt,observation:observation(result)};
|
|
153
160
|
phase='result';
|
|
@@ -155,7 +162,8 @@ export function createFixFinalReview({reviewPackage,configuration,timeoutMs},{au
|
|
|
155
162
|
return {outcome:'observed',value,inspection,completionEligible:false};
|
|
156
163
|
}catch(error){
|
|
157
164
|
const reason=timedOut?'timeout':signal.aborted?'cancelled':'transport_incomplete';
|
|
158
|
-
|
|
165
|
+
if(timedOut&&onReconciliation&&transport){let drain;await Promise.race([transport.catch(()=>{}),new Promise(resolve=>{drain=setTimeout(resolve,2500);})]);clearTimeout(drain);}
|
|
166
|
+
return {outcome:'unknown',...((config.externalModels||config.executionPolicy)&&timedOut&&!diagnostic?{value:{dispatchAt,observation:observation({status:'failed',code:'timeout'})}}:{}),reason,diagnostic:diagnostic??(reason==='transport_incomplete'
|
|
159
167
|
?reviewDiagnostic(phase,error):{phase:'transport',code:reason}),completionEligible:false};
|
|
160
168
|
}
|
|
161
169
|
finally{sealed=true;clearTimeout(timer);signal.removeEventListener('abort',cancel);controller.signal.removeEventListener('abort',rejectAbort);controller.abort();}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {selectExternalModels} from '../cm-ai/external-models.mjs';
|
|
2
|
+
import {readExecutionPolicy} from '../cm-ai/execution-policy.mjs';
|
|
3
|
+
import {createNativeUsageLog} from '../cm-ai/native-usage-log.mjs';
|
|
1
4
|
// Shared fix-specific diagnostics, authorities and lazy provider adapters.
|
|
2
5
|
import {fileURLToPath} from 'node:url';
|
|
3
6
|
import {codexWorker,preflightMatches} from '../cm-ai/worker-codex.mjs';
|
|
@@ -8,31 +11,51 @@ import {createHostReviewAuthority} from '../cm-ai/host-review-authority.mjs';
|
|
|
8
11
|
import {fixFinalReviewConfiguration} from './final-review.mjs';
|
|
9
12
|
import {digest,id,json,need} from '../cm-ai/effect-contract.mjs';
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
const DEFAULT_REVIEW_TIMEOUT_MS=900000;
|
|
15
|
+
export function createFixReviewHost({codeProject,hostContextId,runtime='codex',review=null,permissions=[],workerFactory=null,externalModels=null,executionPolicy=null,specsDir=null}){
|
|
12
16
|
id(hostContextId);need(['codex','claude'].includes(runtime),'invalid_runtime');
|
|
17
|
+
const policy=executionPolicy===null?null:readExecutionPolicy(executionPolicy);
|
|
13
18
|
const allowed=new Set(json(permissions)),config=review===null?null:json(review);
|
|
19
|
+
const pair=externalModels?selectExternalModels(externalModels,[runtime]).providers[runtime]:null;
|
|
20
|
+
need(!pair||!config||(config.model===pair.model&&config.effort===pair.effort),'external_model_pair_conflict');
|
|
14
21
|
const matches=runtime==='claude'?claudePreflightMatches:preflightMatches;
|
|
15
22
|
const worker=workerFactory??(runtime==='claude'?claudeWorker:codexWorker);
|
|
16
23
|
need(runtime!=='claude'||!config||config.disabledSkills.length===0,'invalid_review_config');
|
|
17
24
|
const enabled=['--allow-cause-review','--allow-final-review','--allow-test-author','--allow-repair'].some(flag=>allowed.has(flag));
|
|
18
25
|
need(!enabled||config!==null,'review_configuration_required');
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
// Review transport budget from the review configuration (outside its
|
|
27
|
+
// authorized digest), shared by the worker and the owner's review watchdog.
|
|
28
|
+
const timeoutMs=config?.timeoutMs??DEFAULT_REVIEW_TIMEOUT_MS;
|
|
29
|
+
const workerOptions=config?{cwd:codeProject,model:config.model,...(pair?{effort:pair.effort}:{}),disabledSkills:config.disabledSkills,
|
|
30
|
+
promptTransport:'stdin',preflight:config.preflight,timeoutMs,
|
|
21
31
|
schemaPath:fileURLToPath(new URL('../cm-ai/review-result.schema.json',import.meta.url))}:null;
|
|
22
32
|
const assertReviewReady=()=>need(config&&matches(config.preflight,workerOptions),'tool_preflight_missing');
|
|
23
33
|
if(enabled)assertReviewReady();
|
|
24
34
|
const reviewer=config?{reviewerId:'fix-cause-reviewer',adapterId:`${runtime}-cause-review-adapter`,provider:runtime,
|
|
25
35
|
requestedModel:config.model,contextId:'fix-cause-review-context',excludedThreadIds:[],
|
|
26
|
-
workerConfigurationDigest:digest({cwd:codeProject,model:config.model,disabledSkills:config.disabledSkills,
|
|
27
|
-
promptTransport:'stdin',...(runtime==='claude'?{runtime}:{})})}:null;
|
|
36
|
+
workerConfigurationDigest:digest({cwd:codeProject,model:config.model,...(pair?{effort:pair.effort}:{}),disabledSkills:config.disabledSkills,
|
|
37
|
+
promptTransport:'stdin',...(runtime==='claude'?{runtime}:{}),...(policy?{executionPolicy:policy}:{})})}:null;
|
|
28
38
|
const authorityFor=(reviewer,permission)=>createHostReviewAuthority({hostContextId,
|
|
29
39
|
reviewerId:reviewer.reviewerId,adapterId:reviewer.adapterId,
|
|
30
40
|
decide:async()=>allowed.has(permission)?{status:'approved'}:{status:'denied',code:'permission_denied'}});
|
|
31
41
|
const authority=config?authorityFor(reviewer,'--allow-cause-review'):null;
|
|
32
42
|
const finalAuthority=config?authorityFor(fixFinalReviewConfiguration({hostContextId,causeReview:reviewer}).reviewer,'--allow-final-review'):null;
|
|
43
|
+
const runReview=(request,control,cause)=>{
|
|
44
|
+
let log=null,usage={usage_state:'unavailable'},result;
|
|
45
|
+
const native=worker({...workerOptions,...(policy?{onUsage:value=>{usage=value;},onUsageClaim:()=>{
|
|
46
|
+
log??=createNativeUsageLog({definition:{codeProject,specsDir,feature:request.identity.feature??'fix'},request,provider:runtime,role:'reviewer',workflow:'cm-fix'});
|
|
47
|
+
log.claimed();
|
|
48
|
+
}}: {})});
|
|
49
|
+
const complete=()=>log?.complete(usage,control.signal.aborted?'cancelled':result?.status==='succeeded'?'success':'error');
|
|
50
|
+
try{
|
|
51
|
+
const pending=(cause?createCauseReviewRun(native,runtime,policy):(runtime==='claude'?createClaudeReviewRun:createCodexReviewRun)(native,policy))(request,control);
|
|
52
|
+
if(!policy)return pending;
|
|
53
|
+
return Promise.resolve(pending).then(value=>{result=value;return value;}).finally(complete);
|
|
54
|
+
}catch(error){complete();throw error;}
|
|
55
|
+
};
|
|
33
56
|
return {reviewer,authority,finalAuthority,execution:{assertReviewReady,
|
|
34
|
-
...(config?{causeReview:{authorize:authority.authorize,
|
|
35
|
-
run:(request,control)=>
|
|
36
|
-
finalReview:{authorize:finalAuthority.authorize,run:(request,control)=>
|
|
37
|
-
(
|
|
57
|
+
...(config?{causeReview:{authorize:authority.authorize,timeoutMs,
|
|
58
|
+
run:(request,control)=>runReview(request,control,true)},
|
|
59
|
+
finalReview:{authorize:finalAuthority.authorize,timeoutMs,run:(request,control)=>
|
|
60
|
+
runReview(request,control,false)}}:{})}};
|
|
38
61
|
}
|
|
@@ -9,8 +9,9 @@ export function createFixHost({owner,config,runtime='codex',permissions=[],autho
|
|
|
9
9
|
const extra=new Set(permissions);
|
|
10
10
|
const host={async handle(request){
|
|
11
11
|
shape(request,['requestId','operation',...(request.operation==='resume'?['evidenceFiles']:[]),
|
|
12
|
-
...(request.operation
|
|
12
|
+
...(['abandon_step','abandon_review','rediagnose'].includes(request.operation)&&Object.hasOwn(request,'reason')?['reason']:[]),
|
|
13
13
|
...(request.operation==='prepare_revision'&&Object.hasOwn(request,'tests')?['tests']:[]),
|
|
14
|
+
...(request.operation==='reconcile_review'?['invocationId']:[]),
|
|
14
15
|
...(request.operation==='recover_final_review'?['invocationId','packageDigest','previousInvocationStopped','reason']:[])]);
|
|
15
16
|
if(config.qaSource&&!['status','cancel','completion_evidence'].includes(request.operation))
|
|
16
17
|
inspectFixQaSource({specsRoot:config.specsRoot,identity:config.identity,configuration:config});
|
|
@@ -23,10 +24,14 @@ export function createFixHost({owner,config,runtime='codex',permissions=[],autho
|
|
|
23
24
|
return {...status,progress:fixProgress(status,config,{finalReviewAllowed:finalAuthority!==null
|
|
24
25
|
&&extra.has('--allow-final-review')&&recoveryAllowed})};
|
|
25
26
|
}
|
|
27
|
+
if(request.operation==='reconcile_review')return owner.reconcileReview({invocationId:request.invocationId});
|
|
26
28
|
if(request.operation==='recover_final_review')return owner.recoverFinalReview({
|
|
27
29
|
authorized:extra.has('--allow-final-review-recovery'),recoveryInvocationId,invocationId:request.invocationId,
|
|
28
30
|
packageDigest:request.packageDigest,previousInvocationStopped:request.previousInvocationStopped,reason:request.reason});
|
|
29
31
|
if(request.operation==='abandon_step')return owner.abandonStep({authorized:extra.has('--allow-abandon'),reason:request.reason});
|
|
32
|
+
// Reviewer-invocation authority stays separate from local step abandonment.
|
|
33
|
+
if(request.operation==='abandon_review')return owner.abandonReview({authorized:extra.has('--allow-abandon-review'),reason:request.reason});
|
|
34
|
+
if(request.operation==='rediagnose')return owner.rediagnose({authorized:extra.has('--allow-rediagnosis'),reason:request.reason});
|
|
30
35
|
if(request.operation==='completion_evidence')return owner.completionEvidence();
|
|
31
36
|
if(request.operation==='finish')return owner.finish({authorized:extra.has('--allow-finish')});
|
|
32
37
|
if(request.operation==='author_tests')return owner.authorTests({authorized:extra.has('--allow-test-author')});
|
|
@@ -30,7 +30,7 @@ export function fixEvidenceNames(identity,configuration){
|
|
|
30
30
|
// 只列这次配置真的会写的文件,免得拦下根本不会发生的冲突。
|
|
31
31
|
if(configuration.redTest&&configuration.redTest.kind!=='visual')
|
|
32
32
|
names.push(`fix-${slug}-a${identity.attempt}-red-output.md`);
|
|
33
|
-
if(configuration.causeReview)names.push(`fix-${slug}-cause-r1.md`);
|
|
33
|
+
if(configuration.causeReview)names.push(`fix-${slug}-cause-r1.md`,`fix-${slug}-cause-r2.md`);
|
|
34
34
|
return names;
|
|
35
35
|
}
|
|
36
36
|
// 名字被占时分两种:审查结论(-r{n}.md / -cause-r{n}.md)是别人签过字的证据,绝不
|
|
@@ -33,6 +33,10 @@ export function fixProgress(status,config={},authorization={}){
|
|
|
33
33
|
blocker:null,nextAction:null,requiresUser:false,finished:done,
|
|
34
34
|
evidenceScope:'recorded_history_not_fresh_execution',remainingScope:'current_path_not_future_revisions'};
|
|
35
35
|
if(done){result.remaining=[];return result;}
|
|
36
|
+
if(stage==='rediagnosis_required')return {...result,current:'根因审查要求重新诊断',blocker:stage,
|
|
37
|
+
nextAction:'原 run 使用 rediagnose(--allow-rediagnosis、reason);处理原 findings 后重新独立审查,保留 cause-r1。',requiresUser:true};
|
|
38
|
+
if(stage==='rediagnosis_review_limit_reached')return {...result,current:'第二次根因审查仍未通过',blocker:stage,
|
|
39
|
+
nextAction:'保留两次审查和诊断;交用户判断,不继续重派或重建身份。',requiresUser:true};
|
|
36
40
|
if(stage==='escalated')return {...result,current:'已升级立项,修复未完成',remaining:[],nextAction:null};
|
|
37
41
|
if(stage==='cancelled')return {...result,current:'任务已取消',blocker:'cancelled',nextAction:'保留历史,不自动恢复。',requiresUser:true};
|
|
38
42
|
if(status.executionActive===true)return {...result,current:'当前操作正在执行',nextAction:'等待当前操作结果,不重发或申请续审。'};
|
|
@@ -53,6 +57,7 @@ export function fixProgress(status,config={},authorization={}){
|
|
|
53
57
|
remaining:finalPending?['取得有效独立审查结果','保存审查证据','核对完成条件','审后回归',...(config.walkthrough?['走查']:[]),'完成收尾']:null,
|
|
54
58
|
nextAction:finalPending&&invocation.providerThreadId
|
|
55
59
|
?'先确认原调用已停止;核对当前审查包并取得本次一次续审授权,再恢复原任务。'
|
|
60
|
+
:status.reviewAbandonable?'审查没有结论:先确认原审查进程已停止,再用 abandon_review(--allow-abandon-review,原因审查与第二轮最终审查各一次)放弃这次调用,然后重新审查。'
|
|
56
61
|
:'核对原操作与实际结果;不要重跑已完成步骤或推定成功。',requiresUser:true,
|
|
57
62
|
...(finalPending?{recovery:{invocationId:invocation.invocationId,packageDigest:invocation.packageDigest,
|
|
58
63
|
completedRecoveryPreparations:status.finalReviewRecoveryCount??0,
|
|
@@ -22,12 +22,15 @@ function snapshot(cwd,file){
|
|
|
22
22
|
}catch(error){if(error.code==='ENOENT')return null;throw error;}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// Optional mode sets the permission bits of a written file (never of a deletion).
|
|
26
|
+
const EDIT_MODES=new Map([['0644',0o644],['0755',0o755]]);
|
|
25
27
|
export function applyProtectedEdits({cwd,scope,edits}){
|
|
26
28
|
validateDeveloperScope(scope);need(fs.realpathSync(cwd)===cwd,'unsupported_path');
|
|
27
29
|
need(Array.isArray(edits)&&edits.length>0&&edits.length<=scope.length,'protected_edit_invalid');
|
|
28
30
|
const seen=new Set();
|
|
29
31
|
for(const edit of edits){
|
|
30
|
-
shape(edit,['path','beforeSha256','content']);
|
|
32
|
+
shape(edit,['path','beforeSha256','content',...(Object.hasOwn(edit,'mode')?['mode']:[])]);
|
|
33
|
+
need(!Object.hasOwn(edit,'mode')||edit.content!==null&&EDIT_MODES.has(edit.mode),'protected_edit_invalid');
|
|
31
34
|
need(scope.includes(edit.path)&&!seen.has(edit.path),'out_of_scope');seen.add(edit.path);
|
|
32
35
|
need(edit.content===null||typeof edit.content==='string','protected_edit_invalid');
|
|
33
36
|
need(edit.content===null||Buffer.byteLength(edit.content)<=1024*1024,'limit_exceeded');
|
|
@@ -40,9 +43,15 @@ export function applyProtectedEdits({cwd,scope,edits}){
|
|
|
40
43
|
if(edit.content===null)fs.unlinkSync(target);
|
|
41
44
|
else{
|
|
42
45
|
fs.mkdirSync(path.dirname(target),{recursive:true});
|
|
43
|
-
// O_NOFOLLOW avoids silently replacing a last-moment link target.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
// O_NOFOLLOW avoids silently replacing a last-moment link target. A new
|
|
47
|
+
// file is ordinary source (0644); an existing one keeps its mode unless set.
|
|
48
|
+
const created=edit.beforeSha256===null;
|
|
49
|
+
const fd=fs.openSync(target,fs.constants.O_WRONLY|fs.constants.O_CREAT|fs.constants.O_TRUNC|fs.constants.O_NOFOLLOW,0o644);
|
|
50
|
+
try{
|
|
51
|
+
fs.writeFileSync(fd,edit.content);
|
|
52
|
+
if(created||Object.hasOwn(edit,'mode'))fs.fchmodSync(fd,EDIT_MODES.get(edit.mode)??0o644);
|
|
53
|
+
fs.fsyncSync(fd);
|
|
54
|
+
}finally{fs.closeSync(fd);}
|
|
46
55
|
}
|
|
47
56
|
}
|
|
48
57
|
}
|
|
@@ -81,6 +90,8 @@ export function protectedFixBridge({bridge,cwd,specsRoot,timeoutMs}){
|
|
|
81
90
|
shape(result,['outcome','edits']);
|
|
82
91
|
need(['blocked',kind==='fix_repair'?'repaired':'authored'].includes(result.outcome),'protected_edit_invalid');
|
|
83
92
|
need(Array.isArray(result.edits),'protected_edit_invalid');
|
|
93
|
+
// cm-fix keeps its original text-only proposal shape; mode is a cm-ai develop field.
|
|
94
|
+
for(const edit of result.edits)shape(edit,['path','beforeSha256','content']);
|
|
84
95
|
if(result.outcome==='blocked'){need(result.edits.length===0,'protected_edit_invalid');return {outcome:'blocked'};}
|
|
85
96
|
need(result.edits.length>0||kind==='fix_repair'&&payload.allowUnchanged===true,'protected_edit_invalid');
|
|
86
97
|
await commitProtectedEdits({cwd,specsRoot,scope:payload.scope,edits:result.edits,expected,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import {readHostQaFixHandoff,readHostQaFixHistory} from '../cm-ai/host-qa-fix.mjs';
|
|
5
|
-
import {scanRows} from '../cm-ai/cm-ai-qa-log.mjs';
|
|
5
|
+
import {effectiveQaDecisionRow,scanRows} from '../cm-ai/cm-ai-qa-log.mjs';
|
|
6
6
|
import {readReviewSourceFiles} from '../cm-ai/review-package.mjs';
|
|
7
7
|
import {digest,hex,id,json,need,shape,text,validIdentity} from '../cm-ai/effect-contract.mjs';
|
|
8
8
|
|
|
@@ -39,9 +39,11 @@ function inspectSource({specsRoot,identity,configuration},readHandoff){
|
|
|
39
39
|
&&row.task===source.identity.taskId&&row.attempt===source.identity.attempt
|
|
40
40
|
&&row.feature===source.feature&&row.package_digest===source.packageDigest)rows.push(row);
|
|
41
41
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
// A recovered timeout decision appends one linked row; bind the effective one.
|
|
43
|
+
const decision=effectiveQaDecisionRow(rows,'fix_qa_project_mismatch');
|
|
44
|
+
need(decision&&typeof decision.project_path==='string'&&typeof decision.specs_path==='string'
|
|
45
|
+
&&fs.realpathSync(decision.project_path)===fs.realpathSync(configuration.reproduction.cwd)
|
|
46
|
+
&&fs.realpathSync(decision.specs_path)===fs.realpathSync(specsRoot),'fix_qa_project_mismatch');
|
|
45
47
|
need(handoff.handoffDigest===handoffDigest,'fix_qa_source_changed');
|
|
46
48
|
need(handoff.status!=='blocked','fix_qa_source_blocked');
|
|
47
49
|
return handoff;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Owner journal evidence only. Public requests supply invocationId, never receipts.
|
|
2
|
+
import {digest,json,need,shape} from '../cm-ai/effect-contract.mjs';
|
|
3
|
+
import {readReconciliationReceipt} from '../cm-ai/review-reconciliation.mjs';
|
|
4
|
+
import {inspectProviderReview,inspectProviderCauseReview,inspectProviderReviewReconciliation} from '../cm-ai/provider-review-observation.mjs';
|
|
5
|
+
|
|
6
|
+
export function inspectFixReconciledResult(value,expectation,cause=false){
|
|
7
|
+
const receipt=readReconciliationReceipt(value.reconciliationReceipt);
|
|
8
|
+
const original=value.observation;
|
|
9
|
+
const checked=(cause?inspectProviderCauseReview:inspectProviderReview)(JSON.stringify(original),JSON.stringify(expectation));
|
|
10
|
+
need(checked.observationStatus!=='completed'&&Array.isArray(receipt.events)
|
|
11
|
+
&&receipt.events.length<=64&&receipt.events.length>=original.events.length,'review_reconciliation_evidence_required');
|
|
12
|
+
need(digest(original.events)===digest(receipt.events.slice(0,original.events.length)),'review_reconciliation_binding');
|
|
13
|
+
const observation={...original,events:receipt.events,result:receipt.result};
|
|
14
|
+
const result=inspectProviderReviewReconciliation(JSON.stringify(observation),JSON.stringify(expectation),cause);
|
|
15
|
+
// A failed original call has stopped, but cannot become an approving receipt.
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function fixReviewLedger(records,configuration){
|
|
20
|
+
const receipts=new Map(),applied=new Set(),overlays=new Map();
|
|
21
|
+
for(const row of records){
|
|
22
|
+
if(!/^fix-review-(receipt|reconciled)-[0-9a-f]{24}$/.test(row.id))continue;
|
|
23
|
+
need((configuration.externalModels||configuration.executionPolicy)&&row.kind==='result','fix_history_invalid');
|
|
24
|
+
const p=json(row.payload,1024*1024),isReceipt=row.id.startsWith('fix-review-receipt-');
|
|
25
|
+
shape(p,['prefix','invocationId','registeredDigest','startedDigest','resultDigest',...(isReceipt?['receipt']:['receiptDigest'])]);
|
|
26
|
+
need(/^fix-(?:cause(?:-(?:retry|rediagnosis))?|(?:revision-)?final(?:-(?:retry|recovery(?:-[1-9]\d*)?))?)$/.test(p.prefix),'review_reconciliation_binding');
|
|
27
|
+
need(row.id===`fix-review-${isReceipt?'receipt':'reconciled'}-${digest(p.invocationId).slice(0,24)}`,'review_reconciliation_binding');
|
|
28
|
+
const prior=records.filter(r=>r.seq<row.seq);
|
|
29
|
+
const registration=prior.find(r=>r.id===p.prefix+'-registered'),started=prior.find(r=>r.id===p.prefix+'-started'),result=prior.find(r=>r.id===p.prefix+'-result');
|
|
30
|
+
need(registration&&started&&result&®istration.seq<started.seq&&started.seq<result.seq
|
|
31
|
+
&®istration.payload.request.invocationId===p.invocationId
|
|
32
|
+
&&digest(registration)===p.registeredDigest&&digest(started)===p.startedDigest&&digest(result)===p.resultDigest,'review_reconciliation_binding');
|
|
33
|
+
need(prior.filter(r=>r.seq>result.seq).every(r=>/^fix-host-joined-/.test(r.id)||/^fix-review-(?:receipt|reconciled)-/.test(r.id)),
|
|
34
|
+
'review_reconciliation_unavailable');
|
|
35
|
+
const binding={prefix:p.prefix,invocationId:p.invocationId,registeredDigest:p.registeredDigest,startedDigest:p.startedDigest,resultDigest:p.resultDigest};
|
|
36
|
+
if(isReceipt){
|
|
37
|
+
need(!receipts.has(p.invocationId),'review_reconciliation_duplicate');
|
|
38
|
+
const request=registration.payload.request;
|
|
39
|
+
const hosts=[configuration.hostContextId,...prior.filter(r=>/^fix-host-joined-/.test(r.id)).map(r=>r.payload.hostContextId)];
|
|
40
|
+
const excluded=[...hosts,...configuration.causeReview.excludedThreadIds,request.contextId,
|
|
41
|
+
...prior.filter(r=>/-started$/.test(r.id)&&r.id!==started.id&&r.payload.providerThreadId).map(r=>r.payload.providerThreadId)];
|
|
42
|
+
const inspection=inspectFixReconciledResult({...result.payload,reconciliationReceipt:p.receipt},
|
|
43
|
+
{request,developerThreadId:hosts[0],excludedThreadIds:[...new Set(excluded)]},p.prefix.includes('cause'));
|
|
44
|
+
need(inspection.providerThreadId===started.payload.providerThreadId,'review_reconciliation_binding');
|
|
45
|
+
receipts.set(p.invocationId,{...binding,receipt:p.receipt,receiptDigest:digest(row),inspection,resultRecord:result});
|
|
46
|
+
}else{
|
|
47
|
+
const proof=receipts.get(p.invocationId);
|
|
48
|
+
need(proof&&!applied.has(p.invocationId)&&proof.receiptDigest===p.receiptDigest
|
|
49
|
+
&&digest(binding)===digest(Object.fromEntries(Object.keys(binding).map(k=>[k,proof[k]]))),'review_reconciliation_binding');
|
|
50
|
+
applied.add(p.invocationId);
|
|
51
|
+
if(proof.inspection.observationStatus==='completed')overlays.set(result.id,{...result.payload,reconciliationReceipt:proof.receipt});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {receipts,applied,overlays,pending:[...receipts.values()].filter(p=>!applied.has(p.invocationId))};
|
|
55
|
+
}
|
|
56
|
+
export function reconciledFixResultRecord(records,row){
|
|
57
|
+
if(!row||row.payload.reconciliationReceipt)return row;
|
|
58
|
+
const applied=records.find(r=>r.id.startsWith('fix-review-reconciled-')&&r.payload.prefix+'-result'===row.id);
|
|
59
|
+
if(!applied)return row;
|
|
60
|
+
const receipt=records.find(r=>digest(r)===applied.payload.receiptDigest);
|
|
61
|
+
need(receipt&&digest(row)===applied.payload.resultDigest,'review_reconciliation_binding');
|
|
62
|
+
return receipt.payload.receipt.result.status==='succeeded'
|
|
63
|
+
?{...row,payload:{...row.payload,reconciliationReceipt:receipt.payload.receipt}}:row;
|
|
64
|
+
}
|
|
@@ -14,6 +14,7 @@ import {preparePrdReview} from './review-preparation.mjs';
|
|
|
14
14
|
import {inspectAcceptedPrdDesign} from './accepted-design.mjs';
|
|
15
15
|
import {inspectPrdDesignRiskSelection} from './design-risk.mjs';
|
|
16
16
|
import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
17
|
+
import {prdDraftJson} from './validation-reason.mjs';
|
|
17
18
|
|
|
18
19
|
export function createCmPrdAnalysis({input,runtime,analyze,record,processMaterials,generate,checkContext,restored=null,allowInputDrift=false}){
|
|
19
20
|
need(['codex','claude'].includes(runtime)&&typeof analyze==='function'&&typeof record==='function','prd_host_invalid');
|
|
@@ -178,7 +179,7 @@ export function createCmPrdAnalysis({input,runtime,analyze,record,processMateria
|
|
|
178
179
|
await record({event:'degrade',phase:'route',data:{outcome:'planner_adapter_unavailable'}});
|
|
179
180
|
stage='blocked';return this.status();
|
|
180
181
|
}
|
|
181
|
-
const reply=
|
|
182
|
+
const reply=prdDraftJson(await generate({project:admission.project,specs:admission.specs,analysis:result,
|
|
182
183
|
userAnswers:messages.filter(message=>message.role==='user'),messages:next,role:roles.planner,nextIndex,
|
|
183
184
|
phase:designOnly?'design':acceptedDesign!==null?'tasks_after_design':'full_draft',
|
|
184
185
|
acceptedDesign,
|
|
@@ -7,6 +7,7 @@ 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
11
|
import {inspectPrdReview} from '../../../scripts/cm-prd-review-gate.mjs';
|
|
11
12
|
import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
12
13
|
import {writeImmutableWorkflowFile} from '../cm-ai/review-evidence-file.mjs';
|
|
@@ -53,13 +54,27 @@ export function inspectPrdChangeSnapshot(specs){
|
|
|
53
54
|
const status=read(specs,'.cm-specs-status');
|
|
54
55
|
return json({directories,files,trees,reviews,status},4*1024*1024);
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}));}
|
|
57
|
+
// Same declaration grammar as admission and N5 mark-done (spec-task-line.mjs):
|
|
58
|
+
// the approved original is read with the grammar its approval bound, the
|
|
59
|
+
// proposed text (a new approval) with the current grammar.
|
|
60
|
+
function completedLines(source,grammar=TASK_GRAMMAR){return taskDeclarations(source,{grammar}).filter(item=>item.completed).map(item=>item.body);}
|
|
61
|
+
function taskLines(source,grammar=TASK_GRAMMAR){return new Map(taskDeclarations(source,{grammar}).map(item=>[item.id,item.body]));}
|
|
62
|
+
// The grammar the last approval established. cm-prd's own awaiting_review
|
|
63
|
+
// statuses (change invalidation/result, summary publication) only ever carry
|
|
64
|
+
// that value forward, so a chain of changes before re-approval keeps reading
|
|
65
|
+
// the approved originals the same way. The one exception is a first summary
|
|
66
|
+
// publication with no earlier status at all, where nothing was ever approved
|
|
67
|
+
// under another grammar.
|
|
68
|
+
function approvedGrammar(before){
|
|
69
|
+
try{const status=JSON.parse(before.status??'null');
|
|
70
|
+
return ['approved','awaiting_review'].includes(status?.status)&&status.taskGrammar===TASK_GRAMMAR?TASK_GRAMMAR:LEGACY_TASK_GRAMMAR;}
|
|
71
|
+
catch{return LEGACY_TASK_GRAMMAR;}
|
|
72
|
+
}
|
|
73
|
+
function sourceLines(source){return specLines(source).map(line=>line.body);}
|
|
60
74
|
function userCases(files){return Object.entries(files).filter(([file])=>file.endsWith('/test-cases.json'))
|
|
61
75
|
.flatMap(([file,content])=>JSON.parse(content).cases.filter(c=>c.origin==='user').map(c=>({feature:file.split('/')[0],value:c})));}
|
|
62
76
|
export function inspectPrdChangeProposal(before,raw,selected,config){
|
|
77
|
+
const grammar=approvedGrammar(before);
|
|
63
78
|
shape(raw,['status','summary','features','removed']);need(raw.status==='draft'&&text(raw.summary)&&Array.isArray(raw.features)
|
|
64
79
|
&&Array.isArray(raw.removed)&&new Set(raw.removed).size===raw.removed.length,'prd_change_proposal_invalid');
|
|
65
80
|
const files={},features=[],seen=new Set();
|
|
@@ -88,10 +103,10 @@ export function inspectPrdChangeProposal(before,raw,selected,config){
|
|
|
88
103
|
&&new Set(resultDirs.map(dir=>dir.split('.')[0])).size===resultDirs.length,'prd_change_inventory_collision');
|
|
89
104
|
for(const directory of selected){
|
|
90
105
|
const original=before.files[`${directory}/tasks.md`],after=files[`${directory}/tasks.md`]??'';
|
|
91
|
-
for(const line of completedLines(original))need(after
|
|
92
|
-
need(completedLines(after).every(line=>completedLines(original).includes(line)),'prd_completed_task_invented');
|
|
106
|
+
for(const line of completedLines(original,grammar))need(sourceLines(after).includes(line),'prd_completed_task_changed');
|
|
107
|
+
need(completedLines(after).every(line=>completedLines(original,grammar).includes(line)),'prd_completed_task_invented');
|
|
93
108
|
if(raw.removed.includes(directory))continue;
|
|
94
|
-
const prior=taskLines(original),next=taskLines(after);
|
|
109
|
+
const prior=taskLines(original,grammar),next=taskLines(after);
|
|
95
110
|
for(const [id,line] of prior)need(next.has(id)&&(next.get(id)===line||/\[(?:CHANGED|DROPPED)\b/.test(next.get(id))),
|
|
96
111
|
'prd_change_task_history_missing');
|
|
97
112
|
for(const [id,line] of next)if(!prior.has(id))need(/\[NEW\b/.test(line)&&!/\[[xX]\]/.test(line),'prd_change_new_task_invalid');
|
|
@@ -115,7 +130,7 @@ export function inspectPrdChangeProposal(before,raw,selected,config){
|
|
|
115
130
|
return json({...draft,mechanicalSelfCheck:mechanics,removed:raw.removed,files,changedUserCases,
|
|
116
131
|
proposalDigest:digest({before,raw,selected}),counts:{added:resultDirs.filter(dir=>!before.directories.includes(dir)).length,
|
|
117
132
|
removed:raw.removed.length,changed:selected.filter(dir=>seen.has(dir)).length,
|
|
118
|
-
preservedCompletedTasks:selected.reduce((n,dir)=>n+completedLines(before.files[`${dir}/tasks.md`]).length,0)}},4*1024*1024);
|
|
133
|
+
preservedCompletedTasks:selected.reduce((n,dir)=>n+completedLines(before.files[`${dir}/tasks.md`],grammar).length,0)}},4*1024*1024);
|
|
119
134
|
}
|
|
120
135
|
|
|
121
136
|
export function createPrdChange({admission,runtime,call,restored=null,selected=[admission.feature],reason=null}){
|
|
@@ -259,7 +274,9 @@ export function applyPrdChange({specs,before,proposal,selected}){
|
|
|
259
274
|
current();
|
|
260
275
|
// Invalidate approval BEFORE replacing the first byte (also safe after crash).
|
|
261
276
|
const statusFile='.cm-specs-status',invalidated=JSON.stringify({status:'awaiting_review',revisionDigest:proposal.proposalDigest,
|
|
262
|
-
at:new Date().toISOString(),features:newDirs,specFiles:[],testCases:[]
|
|
277
|
+
at:new Date().toISOString(),features:newDirs,specFiles:[],testCases:[],
|
|
278
|
+
// Carry the last approval's tasks.md grammar to the next approval.
|
|
279
|
+
...(approvedGrammar(before)===TASK_GRAMMAR?{taskGrammar:TASK_GRAMMAR}:{})})+'\n';
|
|
263
280
|
if(read(specs,statusFile)===before.status)replaceSessionFile(specs,statusFile,before.status,invalidated);
|
|
264
281
|
for(const [file,content] of Object.entries(expected)){
|
|
265
282
|
if(!selected.includes(file.split('/')[0])&&oldDirs.includes(file.split('/')[0]))continue;
|
|
@@ -281,7 +298,8 @@ export function applyPrdChange({specs,before,proposal,selected}){
|
|
|
281
298
|
current();const specFiles=buildManifest(specs);
|
|
282
299
|
need(digest(fs.readdirSync(specs).filter(dir=>/^\d+\./.test(dir)).sort())===digest(newDirs),'prd_change_inventory_conflict');
|
|
283
300
|
const result={status:'awaiting_review',at:JSON.parse(read(specs,statusFile)).at,revisionDigest:proposal.proposalDigest,
|
|
284
|
-
features:newDirs,specFiles,testCases:specFiles.filter(item=>item.path.endsWith('/test-cases.json'))
|
|
301
|
+
features:newDirs,specFiles,testCases:specFiles.filter(item=>item.path.endsWith('/test-cases.json')),
|
|
302
|
+
...(approvedGrammar(before)===TASK_GRAMMAR?{taskGrammar:TASK_GRAMMAR}:{})};
|
|
285
303
|
replaceSessionFile(specs,statusFile,read(specs,statusFile),JSON.stringify(result)+'\n');
|
|
286
304
|
return json({...result,archive:`.reviews/${name}`,counts:proposal.counts,priorReviews:'retained_as_history_not_current_approval',
|
|
287
305
|
next:'human_review_then_explicit_cm_ai',completionAuthorized:false});
|
|
@@ -2,6 +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
6
|
export function prdFeatureInventory(specs){
|
|
6
7
|
return fs.readdirSync(specs).filter(name=>/^\d+\./.test(name)).sort();
|
|
7
8
|
}
|
|
@@ -37,7 +38,7 @@ export function inspectPrdDesignDraft(raw,{nextIndex}){
|
|
|
37
38
|
writeAuthorized:false,completionAuthorized:false});
|
|
38
39
|
}
|
|
39
40
|
export function inspectPrdDraft(raw,{nextIndex,generateCases,userCasesProvided}){
|
|
40
|
-
const reply=
|
|
41
|
+
const reply=prdDraftJson(raw);shape(reply,['status','summary','features']);
|
|
41
42
|
need(reply.status==='draft'&&typeof reply.summary==='string'&&reply.summary.trim()
|
|
42
43
|
&&Array.isArray(reply.features)&&reply.features.length>0,'prd_draft_invalid');
|
|
43
44
|
const seen=new Set(),features=[];let userCases=0;
|
|
@@ -55,7 +56,9 @@ export function inspectPrdDraft(raw,{nextIndex,generateCases,userCasesProvided})
|
|
|
55
56
|
need(['requirements.md','design.md','tasks.md'].every(file=>files.has(file)),'prd_draft_triad_missing');
|
|
56
57
|
if(files.has('test-cases.json')){
|
|
57
58
|
const cases=JSON.parse(files.get('test-cases.json'));
|
|
58
|
-
|
|
59
|
+
needPrd(feature.testCasesReason===null,'prd_draft_cases_invalid',
|
|
60
|
+
{field:`features[${index}].testCasesReason`,expected:'testCasesReason must be null when test cases are present'});
|
|
61
|
+
need(validateTestCases(cases).length===0&&cases.feature===feature.name,'prd_draft_cases_invalid');
|
|
59
62
|
need(generateCases||cases.cases.every(item=>item.origin!=='generated'),'prd_generated_cases_disabled');
|
|
60
63
|
userCases+=cases.cases.filter(item=>item.origin==='user').length;
|
|
61
64
|
}else need(['no_observable_behavior','generation_disabled'].includes(feature.testCasesReason)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Projection of an already recorded response. No dispatch, verdict edit or retry.
|
|
2
|
+
import {json,digest,need,shape,id} from '../cm-ai/effect-contract.mjs';
|
|
3
|
+
import {inspectPrdReviewResponse} from './review-publication.mjs';
|
|
4
|
+
import {normalizePrdReviewTimestamp} from './review-time.mjs';
|
|
5
|
+
export function readPrdRepairBinding(raw){
|
|
6
|
+
const binding=json(raw,8192);shape(binding,['callId','requestDigest','resultDigest','packageDigest','reason']);
|
|
7
|
+
id(binding.callId);for(const key of ['requestDigest','resultDigest','packageDigest'])
|
|
8
|
+
need(typeof binding[key]==='string'&&/^[a-f0-9]{64}$/.test(binding[key]),'prd_recovery_binding');
|
|
9
|
+
need(typeof binding.reason==='string'&&binding.reason.trim().length>0&&Buffer.byteLength(binding.reason,'utf8')<=1000
|
|
10
|
+
&&!/[\x00-\x1f\u0085\u2028\u2029]/.test(binding.reason),'prd_recovery_evidence_required');
|
|
11
|
+
return binding;
|
|
12
|
+
}
|
|
13
|
+
export function recoverPrdResponse({original,reviewPackage,packageDigest,authorContextId}){
|
|
14
|
+
const response={...json(original,64*1024)},changes=[];
|
|
15
|
+
if(response.reviewer!=='self-degraded'&&Object.hasOwn(response,'degradedReason')&&response.degradedReason===null){
|
|
16
|
+
delete response.degradedReason;changes.push('omit-independent-null-degradedReason');
|
|
17
|
+
}
|
|
18
|
+
const at=normalizePrdReviewTimestamp(response.at);
|
|
19
|
+
if(at!==response.at){response.at=at;changes.push('canonical-exact-timestamp');}
|
|
20
|
+
inspectPrdReviewResponse({reviewPackage,packageDigest,authorContextId,response});
|
|
21
|
+
need(digest(original.result)===digest(response.result),'prd_recovery_verdict_changed');
|
|
22
|
+
return {response,changes};
|
|
23
|
+
}
|
|
@@ -9,6 +9,7 @@ import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
|
9
9
|
import {inspectPrdFindings} from './review-findings.mjs';
|
|
10
10
|
import {inspectPrdSplitDesign} from './split-design.mjs';
|
|
11
11
|
import {need,json,digest} from '../cm-ai/effect-contract.mjs';
|
|
12
|
+
import {needPrd} from './validation-reason.mjs';
|
|
12
13
|
const sha=text=>createHash('sha256').update(text).digest('hex');
|
|
13
14
|
function sections(text,pattern){
|
|
14
15
|
const parts=text.split(/(?=^##\s+)/m);
|
|
@@ -55,12 +56,18 @@ export function preparePrdReview({specs,draft,stage,feature}){
|
|
|
55
56
|
}
|
|
56
57
|
const files=new Map(target.documents.map(document=>[document.path,document.content]));
|
|
57
58
|
const requirements=files.get('requirements.md'),design=files.get('design.md');
|
|
58
|
-
if(stage==='split')
|
|
59
|
-
'prd_review_design_summary_missing'
|
|
59
|
+
if(stage==='split')needPrd(sections(design,/^##\s+(方案摘要|概述|功能模块设计|架构.*|summary|design summary|overview|architecture.*)\s*$/i),
|
|
60
|
+
'prd_review_design_summary_missing',{field:`${feature}/design.md`,
|
|
61
|
+
expected:'Required split summary ## heading: ## 方案摘要, ## 概述, ## 功能模块设计, ## 架构…, ## Summary, ## Design Summary, ## Overview, or ## Architecture…'});
|
|
60
62
|
const content=stage==='design'?{requirements,design}:{
|
|
61
63
|
requirementsFunctions:sections(requirements,/^##\s+(功能需求|Functional requirements)\s*$/i),
|
|
62
64
|
tasks:files.get('tasks.md'),designSummary:sections(design,/^##\s+.*(方案摘要|概述|架构|功能模块|技术|接口|数据|波及|安全|summary|overview|architecture|decision|contract|data|impact|security)/i)};
|
|
63
|
-
|
|
65
|
+
const missing=Object.entries(content).find(([,value])=>typeof value!=='string'||!value.trim());
|
|
66
|
+
const field=missing?.[0]==='requirementsFunctions'?'requirements.md':missing?.[0]==='designSummary'?'design.md':missing?.[0];
|
|
67
|
+
needPrd(!missing,'prd_review_sections_missing',{field:`${feature}/${field}`,
|
|
68
|
+
expected:field==='requirements.md'?'Required ## heading: ## 功能需求 or ## Functional requirements':
|
|
69
|
+
field==='design.md'?'Required ## heading containing 方案摘要, 概述, 架构, 功能模块, 技术, 接口, 数据, 波及, 安全, summary, overview, architecture, decision, contract, data, impact, or security':
|
|
70
|
+
'Non-empty section content'});
|
|
64
71
|
const revision=stage==='split'?readPrdSelfCheckRevision(specs,feature):null;
|
|
65
72
|
const revised=revision?.features.find(f=>f.directory===feature);
|
|
66
73
|
const reviewPackage=json({workflow:'cm-prd',stage,feature,draftDigest:draft.draftDigest,content,
|
|
@@ -6,22 +6,13 @@ import {inspectPrdReview} from '../../../scripts/cm-prd-review-gate.mjs';
|
|
|
6
6
|
import {writeReviewEvidence} from '../cm-ai/review-evidence-file.mjs';
|
|
7
7
|
import {reviewResultForPaths} from '../cm-ai/review-runner.mjs';
|
|
8
8
|
import {need,shape,json,digest,id} from '../cm-ai/effect-contract.mjs';
|
|
9
|
+
import {needPrd} from './validation-reason.mjs';
|
|
9
10
|
|
|
10
|
-
export function
|
|
11
|
-
if(!inspectOnly)assertPrdBatchActive(specs,[reviewPackage.feature]);
|
|
11
|
+
export function inspectPrdReviewResponse({reviewPackage,packageDigest,authorContextId,response}){
|
|
12
12
|
reviewPackage=json(reviewPackage,256*1024);response=json(response,64*1024);id(authorContextId);
|
|
13
13
|
need(digest(reviewPackage)===packageDigest&&reviewPackage.workflow==='cm-prd'
|
|
14
14
|
&&['design','split'].includes(reviewPackage.stage),'prd_review_package_invalid');
|
|
15
|
-
|
|
16
|
-
need(match,'prd_review_feature_invalid');
|
|
17
|
-
need(path.isAbsolute(specs)&&fs.realpathSync(specs)===specs,'prd_review_root_invalid');
|
|
18
|
-
const reviews=path.join(specs,'.reviews');
|
|
19
|
-
need(fs.realpathSync(reviews)===reviews&&fs.lstatSync(reviews).isDirectory(),'prd_review_path_invalid');
|
|
20
|
-
const stage=reviewPackage.stage,feature=match[2],prefix=`prd-${feature}-${stage}`;
|
|
21
|
-
const args={stage,feature,pendingSplit,evidence:path.join(reviews,`${prefix}-r1.md`),receipt:path.join(reviews,`${prefix}-disposition.json`)};
|
|
22
|
-
const gate=inspectPrdReview(args);
|
|
23
|
-
need(gate.package_sha256===packageDigest&&['dispatch_unknown','resume_disposition','completed'].includes(gate.outcome),
|
|
24
|
-
'prd_review_unclaimed');
|
|
15
|
+
need(typeof reviewPackage.feature==='string'&&/^[1-9]\d*\.[a-z0-9]+(?:-[a-z0-9]+)*$/.test(reviewPackage.feature),'prd_review_feature_invalid');
|
|
25
16
|
const degraded=response.reviewer==='self-degraded';
|
|
26
17
|
shape(response,['reviewer','contextId','independent','at','result',...(degraded?['degradedReason']:[])]);
|
|
27
18
|
// Native subagents return canonical context identities, not filesystem paths.
|
|
@@ -36,11 +27,32 @@ export function publishPrdReview({specs,reviewPackage,packageDigest,authorContex
|
|
|
36
27
|
&&!/[\r\n\v\f\x1c-\x1e\x85\u2028\u2029\0]/.test(response.degradedReason):
|
|
37
28
|
['codex-subagent','codex-cli'].includes(response.reviewer)&&response.independent===true&&response.contextId!==authorContextId,
|
|
38
29
|
'prd_review_independence_invalid');
|
|
39
|
-
|
|
40
|
-
&&new Date(response.at).toISOString()===response.at,'prd_review_timestamp_invalid'
|
|
41
|
-
|
|
30
|
+
needPrd(typeof response.at==='string'&&Number.isFinite(Date.parse(response.at))
|
|
31
|
+
&&new Date(response.at).toISOString()===response.at,'prd_review_timestamp_invalid',
|
|
32
|
+
{field:'response.at',expected:'new Date().toISOString() form, e.g. 2026-09-08T00:00:00.000Z'});
|
|
33
|
+
const files=reviewPackage.stage==='design'?['requirements.md','design.md']:['requirements.md','design.md','tasks.md'];
|
|
42
34
|
const examinedPaths=files.map(file=>`${reviewPackage.feature}/${file}`).sort();
|
|
43
35
|
const result=reviewResultForPaths(response.result,{packageDigest},examinedPaths);
|
|
36
|
+
return {response,result,examinedPaths,degraded};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function publishPrdReview({specs,reviewPackage,packageDigest,authorContextId,response,inspectOnly=false,pendingSplit=null}){
|
|
40
|
+
inspectPrdReviewResponse({reviewPackage,packageDigest,authorContextId,response});
|
|
41
|
+
if(!inspectOnly)assertPrdBatchActive(specs,[reviewPackage.feature]);
|
|
42
|
+
reviewPackage=json(reviewPackage,256*1024);response=json(response,64*1024);id(authorContextId);
|
|
43
|
+
need(digest(reviewPackage)===packageDigest&&reviewPackage.workflow==='cm-prd'
|
|
44
|
+
&&['design','split'].includes(reviewPackage.stage),'prd_review_package_invalid');
|
|
45
|
+
const match=typeof reviewPackage.feature==='string'&&reviewPackage.feature.match(/^([1-9]\d*)\.([a-z0-9]+(?:-[a-z0-9]+)*)$/);
|
|
46
|
+
need(match,'prd_review_feature_invalid');
|
|
47
|
+
need(path.isAbsolute(specs)&&fs.realpathSync(specs)===specs,'prd_review_root_invalid');
|
|
48
|
+
const reviews=path.join(specs,'.reviews');
|
|
49
|
+
need(fs.realpathSync(reviews)===reviews&&fs.lstatSync(reviews).isDirectory(),'prd_review_path_invalid');
|
|
50
|
+
const stage=reviewPackage.stage,feature=match[2],prefix=`prd-${feature}-${stage}`;
|
|
51
|
+
const args={stage,feature,pendingSplit,evidence:path.join(reviews,`${prefix}-r1.md`),receipt:path.join(reviews,`${prefix}-disposition.json`)};
|
|
52
|
+
const gate=inspectPrdReview(args);
|
|
53
|
+
need(gate.package_sha256===packageDigest&&['dispatch_unknown','resume_disposition','completed'].includes(gate.outcome),
|
|
54
|
+
'prd_review_unclaimed');
|
|
55
|
+
const {result,examinedPaths,degraded}=inspectPrdReviewResponse({reviewPackage,packageDigest,authorContextId,response});
|
|
44
56
|
const bytes=Buffer.from(['---',`at: ${response.at}`,`reviewer: ${response.reviewer}`,`independent: ${response.independent}`,
|
|
45
57
|
...(degraded?[`degraded_reason: ${JSON.stringify(response.degradedReason)}`]:[]),`package_sha256: ${packageDigest}`,
|
|
46
58
|
`verdict: ${result.verdict}`,'scope:',...examinedPaths.map(file=>` - ${file}`),'---','',
|