@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
|
@@ -4,6 +4,7 @@ import fs from 'node:fs';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import {digest,freeze,hex,json,need,shape,text,validIdentity,validTaskLearningInput} from './effect-contract.mjs';
|
|
6
6
|
import {encodeCmAiTaskLearningEvidence,readLearningRetrospectiveContent} from './cm-ai-context-refresh.mjs';
|
|
7
|
+
import {identifyApprovedBootstrapFeature} from './bootstrap-feature.mjs';
|
|
7
8
|
|
|
8
9
|
const LIMIT=256*1024,PREFIX='cm-learning-retrospective-v1:';
|
|
9
10
|
const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
@@ -63,6 +64,19 @@ export function mergeLessons(source,retrospective) {
|
|
|
63
64
|
return `${before}${block}${newline}${after?newline:''}${after}`;
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
// Pure: what a writeback does to this AGENTS.md text, without touching any file.
|
|
68
|
+
function lessonMerge(source,retrospective){
|
|
69
|
+
const next=mergeLessons(source,retrospective);
|
|
70
|
+
if(next===source)return {outcome:'deduplicated',content:source};
|
|
71
|
+
return Buffer.byteLength(next)>LIMIT?{outcome:'writeback_pending',content:source}:{outcome:'written',content:next};
|
|
72
|
+
}
|
|
73
|
+
// The same plan for a task Learning retrospective, for callers that size a
|
|
74
|
+
// delivery before it is written (the driver's journal preflight).
|
|
75
|
+
export function projectLearningWriteback({source,retrospective}){
|
|
76
|
+
const canonical=canonicalRetrospective(retrospective);
|
|
77
|
+
if(canonical.status!=='lesson_candidate')return {outcome:canonical.status,content:source};
|
|
78
|
+
return lessonMerge(source,canonical);
|
|
79
|
+
}
|
|
66
80
|
function result(retrospective,outcome,changed,agentsFile,reason) {
|
|
67
81
|
const body={version:1,workflow:'cm-ai',phase:'task_learning_writeback',feature:retrospective.feature,
|
|
68
82
|
identity:retrospective.identity,learningDigest:retrospective.learningDigest,
|
|
@@ -99,7 +113,7 @@ export function readCmAiProjectLearningWriteback(raw,{learningInput,retrospectiv
|
|
|
99
113
|
return freeze(value);
|
|
100
114
|
}
|
|
101
115
|
|
|
102
|
-
export function writeCmAiProjectLearning(raw,bootstrapAgentsSha256=null) {
|
|
116
|
+
export function writeCmAiProjectLearning(raw,bootstrapAgentsSha256=null,bootstrapFeature=null) {
|
|
103
117
|
const input=json(raw,256*1024);shape(input,['codeProject','learningInput','retrospective']);
|
|
104
118
|
text(input.codeProject);need(path.isAbsolute(input.codeProject)&&path.resolve(input.codeProject)===input.codeProject);
|
|
105
119
|
validTaskLearningInput(input.learningInput,input.learningInput.identity,input.learningInput.feature);
|
|
@@ -109,7 +123,9 @@ export function writeCmAiProjectLearning(raw,bootstrapAgentsSha256=null) {
|
|
|
109
123
|
&&retrospective.learningDigest===input.learningInput.learningDigest,'identity_mismatch');
|
|
110
124
|
// Only the runner supplies a hash from its validated host bootstrap result.
|
|
111
125
|
// The Learning identity/digest still describes the original task-start read.
|
|
112
|
-
if(bootstrapAgentsSha256!==null){need(
|
|
126
|
+
if(bootstrapAgentsSha256!==null){need(bootstrapFeature!==null
|
|
127
|
+
&&bootstrapFeature===identifyApprovedBootstrapFeature([bootstrapFeature])
|
|
128
|
+
&&input.learningInput.feature===bootstrapFeature,'bootstrap_task_required');hex(bootstrapAgentsSha256);}
|
|
113
129
|
const expected=bootstrapAgentsSha256===null
|
|
114
130
|
?input.learningInput.learningFiles.find(file=>file.scope==='project'&&file.path==='AGENTS.md')??null
|
|
115
131
|
:{scope:'project',path:'AGENTS.md',sha256:bootstrapAgentsSha256};
|
|
@@ -147,10 +163,11 @@ function writeLearningContent(codeProject,expected,retrospective,makeResult){
|
|
|
147
163
|
} catch(error) {
|
|
148
164
|
return result(retrospective,'writeback_pending',null,expected,error?.code==='agents_changed'?'agents_changed':'agents_unsafe');
|
|
149
165
|
}
|
|
150
|
-
const source=new TextDecoder('utf-8',{fatal:true,ignoreBOM:true}).decode(before.bytes),
|
|
151
|
-
if(
|
|
166
|
+
const source=new TextDecoder('utf-8',{fatal:true,ignoreBOM:true}).decode(before.bytes),plan=lessonMerge(source,retrospective);
|
|
167
|
+
if(plan.outcome==='deduplicated')return result(retrospective,'deduplicated',false,
|
|
152
168
|
before.exists?{scope:'project',path:'AGENTS.md',sha256:before.sha256}:null,null);
|
|
153
|
-
|
|
169
|
+
if(plan.outcome==='writeback_pending')return result(retrospective,'writeback_pending',null,expected,'agents_too_large');
|
|
170
|
+
const bytes=Buffer.from(plan.content);
|
|
154
171
|
const temporary=path.join(root,`.AGENTS.md.cm-learning.${process.pid}.${randomUUID()}`);let descriptor,renamed=false;
|
|
155
172
|
try {
|
|
156
173
|
descriptor=fs.openSync(temporary,fs.constants.O_WRONLY|fs.constants.O_CREAT|fs.constants.O_EXCL
|
|
@@ -6,8 +6,9 @@ import {fileURLToPath} from 'node:url';
|
|
|
6
6
|
import {digest,hex,id,json,need,shape,text,validIdentity} from './effect-contract.mjs';
|
|
7
7
|
import {readQaAttachment} from './qa-attachment.mjs';
|
|
8
8
|
import {writeCmAiQaStatus} from './cm-ai-run-finalizer.mjs';
|
|
9
|
+
import {scanRows} from './log-rows.mjs';
|
|
9
10
|
import {readExecutionSnapshot} from './execution-snapshot.mjs';
|
|
10
|
-
import {qaRevisionChain,readQaConfigRevision} from './qa-config-revision.mjs';
|
|
11
|
+
import {beforeFirstQaRound,qaRevisionChain,readQaConfigRevision} from './qa-config-revision.mjs';
|
|
11
12
|
|
|
12
13
|
const writer=fileURLToPath(new URL('../../../scripts/cm-log-event.py',import.meta.url));
|
|
13
14
|
const MiB=1024*1024;
|
|
@@ -42,35 +43,39 @@ export function readDecision(raw,identity,packageDigest) {
|
|
|
42
43
|
return json({...decision,at:decision.at.endsWith('Z')?`${decision.at.slice(0,-1)}+00:00`:decision.at});
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
} finally {if(descriptor!==undefined)fs.closeSync(descriptor);}
|
|
46
|
+
export {scanRows} from './log-rows.mjs';
|
|
47
|
+
|
|
48
|
+
// Older hosts recorded a missed qa_assess answer window as a durable
|
|
49
|
+
// blocked/host_request_timeout decision. One explicit recovery may append a
|
|
50
|
+
// superseding decision linked by previous_decision_id; history is never
|
|
51
|
+
// rewritten and every reader consumes the last row of that two-row chain.
|
|
52
|
+
export const timedOutQaDecision=decision=>decision?.status==='blocked'&&decision.reason==='host_request_timeout';
|
|
53
|
+
export function effectiveQaDecisionRow(rows,code){
|
|
54
|
+
if(rows.length===0)return null;
|
|
55
|
+
need(rows.length<=2&&rows[0].previous_decision_id===undefined,code);
|
|
56
|
+
if(rows.length===2)need(timedOutQaDecision(rows[0])&&rows[1].previous_decision_id===rows[0].decision_id
|
|
57
|
+
&&rows[1].decision_id!==rows[0].decision_id,code);
|
|
58
|
+
return rows.at(-1);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
function existingDecision(specsDir,feature,identity,packageDigest,decision) {
|
|
61
|
+
function existingDecision(specsDir,feature,identity,packageDigest,decision,previousDecisionId=null) {
|
|
62
62
|
const log=path.join(path.resolve(specsDir),'运行日志.jsonl');
|
|
63
|
-
if(!fs.existsSync(log))return false;
|
|
63
|
+
if(!fs.existsSync(log)){need(previousDecisionId===null,'qa_decision_conflict');return false;}
|
|
64
64
|
try {
|
|
65
65
|
const matches=[];scanRows(log,row=>{if(row?.schema_version===1&&row.workflow==='cm-ai'&&row.event==='qa'&&row.node==='N6'
|
|
66
66
|
&&row.repository_id===identity.repositoryId&&row.run_id===identity.runId&&row.feature===feature
|
|
67
67
|
&&row.task===identity.taskId&&row.attempt===identity.attempt&&row.package_digest===packageDigest)matches.push(row);});
|
|
68
|
-
if(matches.length===0)return false;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
if(matches.length===0){need(previousDecisionId===null,'qa_decision_conflict');return false;}
|
|
69
|
+
const row=effectiveQaDecisionRow(matches,'qa_decision_conflict');
|
|
70
|
+
if(row.decision_id===decision.decisionId){
|
|
71
|
+
need(row.status===decision.status&&row.reason===decision.reason&&row.score===decision.score&&row.at===decision.at
|
|
72
|
+
&&(row.previous_decision_id??null)===previousDecisionId,'qa_decision_conflict');
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
// Only the single recorded timeout decision can be superseded, and once.
|
|
76
|
+
need(previousDecisionId!==null&&matches.length===1&&row.decision_id===previousDecisionId
|
|
77
|
+
&&timedOutQaDecision(row),'qa_decision_conflict');
|
|
78
|
+
return false;
|
|
74
79
|
} catch(error) {
|
|
75
80
|
if(error?.code==='qa_decision_conflict')throw error;
|
|
76
81
|
need(false,'qa_log_failed');
|
|
@@ -92,15 +97,19 @@ function readResult(stdout,identity,specsDir) {
|
|
|
92
97
|
export function recordCmAiQaDecision(input) {
|
|
93
98
|
const keys=['specsDir','codeProject','feature','identity','packageDigest','decision'];
|
|
94
99
|
if(input&&Object.hasOwn(input,'logHome'))keys.push('logHome');
|
|
100
|
+
if(input&&Object.hasOwn(input,'previousDecisionId'))keys.push('previousDecisionId');
|
|
95
101
|
shape(input,keys);text(input.specsDir);text(input.codeProject);text(input.feature);validIdentity(input.identity);
|
|
96
102
|
hex(input.packageDigest);
|
|
103
|
+
const previousDecisionId=input.previousDecisionId??null;if(previousDecisionId!==null)id(previousDecisionId);
|
|
97
104
|
const decision=readDecision(input.decision,input.identity,input.packageDigest);
|
|
98
|
-
if(existingDecision(input.specsDir,input.feature,input.identity,input.packageDigest,decision))return;
|
|
99
|
-
const detail=decision.status==='triggered'?`触发:${decision.reason}`:
|
|
100
|
-
decision.status==='skipped'?`跳过:评分${decision.score}`:`阻塞:${decision.reason}
|
|
105
|
+
if(existingDecision(input.specsDir,input.feature,input.identity,input.packageDigest,decision,previousDecisionId))return;
|
|
106
|
+
const detail=(decision.status==='triggered'?`触发:${decision.reason}`:
|
|
107
|
+
decision.status==='skipped'?`跳过:评分${decision.score}`:`阻塞:${decision.reason}`)
|
|
108
|
+
+(previousDecisionId===null?'':`(重新评估,替代 ${previousDecisionId})`);
|
|
101
109
|
const data={node:'N6',feature:input.feature,task:input.identity.taskId,attempt:input.identity.attempt,
|
|
102
110
|
repository_id:input.identity.repositoryId,package_digest:input.packageDigest,decision_id:decision.decisionId,
|
|
103
|
-
status:decision.status,reason:decision.reason,score:decision.score
|
|
111
|
+
status:decision.status,reason:decision.reason,score:decision.score,
|
|
112
|
+
...(previousDecisionId===null?{}:{previous_decision_id:previousDecisionId})};
|
|
104
113
|
const args=[writer,'--workflow','cm-ai','--event','qa','--runtime','codex','--project-root',input.codeProject,
|
|
105
114
|
'--specs-dir',input.specsDir,'--run-id',input.identity.runId,'--at',decision.at,'--detail',detail,
|
|
106
115
|
'--data-json',JSON.stringify(data)];
|
|
@@ -137,8 +146,7 @@ function findDecisionRow(input) {
|
|
|
137
146
|
&&row.package_digest===input.packageDigest)matches.push(row);});}
|
|
138
147
|
catch{need(false,'context_not_ready');}
|
|
139
148
|
if(matches.length===0)return null;
|
|
140
|
-
|
|
141
|
-
const row=matches[0];id(row.decision_id);
|
|
149
|
+
const row=effectiveQaDecisionRow(matches,'context_not_ready');id(row.decision_id);
|
|
142
150
|
need(['triggered','skipped','blocked'].includes(row.status),'context_not_ready');
|
|
143
151
|
return row;
|
|
144
152
|
}
|
|
@@ -149,6 +157,12 @@ export function findCmAiQaDecision(input) {
|
|
|
149
157
|
packageDigest:input.packageDigest,reason:row.reason,score:row.score,at:row.at},input.identity,input.packageDigest);
|
|
150
158
|
}
|
|
151
159
|
|
|
160
|
+
// True when the effective decision is the linked replacement of a timed-out
|
|
161
|
+
// decision (the durable effect of one explicit --rerun-blocked-qa recovery).
|
|
162
|
+
export function replacesTimedOutQaDecision(input) {
|
|
163
|
+
return findDecisionRow(input)?.previous_decision_id!==undefined;
|
|
164
|
+
}
|
|
165
|
+
|
|
152
166
|
export function inspectCmAiQaDecision(input) {
|
|
153
167
|
const row=findDecisionRow(input);need(row,'context_not_ready');
|
|
154
168
|
return Object.freeze({status:row.status,decisionId:row.decision_id});
|
|
@@ -180,16 +194,53 @@ function partialPassCases(items,code){
|
|
|
180
194
|
return [...new Set(cases)].sort();
|
|
181
195
|
}
|
|
182
196
|
|
|
197
|
+
// host-check reports a command that produced no exit code as `unavailable`
|
|
198
|
+
// (timeout, kill, spawn or output transport): an environment outcome, not the
|
|
199
|
+
// product's answer. A real non-zero exit stays a product FAIL unless the
|
|
200
|
+
// operator explicitly declares, and the log records, an environment failure.
|
|
201
|
+
const UNAVAILABLE_COMMAND=/^host check: (?:timeout|signal_exit|spawn_failed|output_limit|output_read_failed|output_capture_failed|cleanup_failed)$/;
|
|
202
|
+
const unavailableCommand=row=>row?.kind==='commands'&&row.exitCode===null
|
|
203
|
+
&&Array.isArray(row.evidence)&&UNAVAILABLE_COMMAND.test(row.evidence.at(-1));
|
|
204
|
+
const exitedCommand=row=>row?.kind==='commands'&&Number.isSafeInteger(row.exitCode)&&row.exitCode!==0;
|
|
205
|
+
export const validEnvironmentFailureReason=value=>typeof value==='string'&&value.trim().length>0
|
|
206
|
+
&&Buffer.byteLength(value,'utf8')<=500&&!/[\r\n\0]/.test(value);
|
|
207
|
+
|
|
208
|
+
// The feature's test contract, the same file the executor plans from, is the
|
|
209
|
+
// authority for an unresolved [需确认] expectation; report markers only confirm it.
|
|
210
|
+
function contractCases(specsDir,feature,code){
|
|
211
|
+
need(typeof feature==='string'&&/^\d+\.[A-Za-z0-9._-]+$/.test(feature),code);
|
|
212
|
+
const source=path.join(path.resolve(specsDir),feature,'test-cases.json');
|
|
213
|
+
if(!fs.existsSync(source))return new Map();
|
|
214
|
+
try{
|
|
215
|
+
const stat=fs.lstatSync(source);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.size<=MiB,code);
|
|
216
|
+
const contract=JSON.parse(new TextDecoder('utf-8',{fatal:true}).decode(fs.readFileSync(source)));
|
|
217
|
+
need(Array.isArray(contract?.cases),code);
|
|
218
|
+
return new Map(contract.cases.map(item=>[item.id,item]));
|
|
219
|
+
}catch{need(false,code);}
|
|
220
|
+
}
|
|
221
|
+
// A case missing from the contract counts as unresolved (fail closed).
|
|
222
|
+
const confirmationPending=item=>!Array.isArray(item?.expected)||item.expected.some(value=>String(value).includes('[需确认]'));
|
|
223
|
+
// The eligibility rule of released versions before recovery_rule 2. Superseded
|
|
224
|
+
// rows they wrote (no recovery_rule) are replayed with exactly this predicate.
|
|
225
|
+
// Rows without recovery_rule are exactly the pre-branch released format: the
|
|
226
|
+
// intermediate commits of this change are squash-merged and never reach users.
|
|
227
|
+
const legacyEligible=(row,environment)=>!row.sourceChanged&&(
|
|
228
|
+
row.kind==='logic'&&row.staticVerdict==='INSUFFICIENT_EVIDENCE'
|
|
229
|
+
||row.kind==='browser'&&(typeof row.evidenceProblem==='string'&&row.evidenceProblem.length>0
|
|
230
|
+
||row.cleanup==='failed'||row.hostRequestTimeout===true
|
|
231
|
+
||environment!=null&&row.environment!=null&&digest(row.environment)!==digest(environment)));
|
|
232
|
+
|
|
183
233
|
// Read the executor's existing report format, including pre-recovery reports.
|
|
184
234
|
// Summary counts alone cannot distinguish product failures from host evidence gaps.
|
|
185
|
-
function
|
|
235
|
+
function recoverableCases(items,specsDir,environment,code='qa_rerun_not_blocked_by_evidence',environmentFailure=false,legacyRule=false){
|
|
186
236
|
const completes=items.filter(({row})=>row.phase==='complete');
|
|
187
237
|
need(completes.length===1,code);
|
|
188
238
|
const complete=completes[0].row,start=items[0]?.row;
|
|
189
|
-
need(start?.phase==='start'&&complete.result==='
|
|
239
|
+
need(start?.phase==='start'&&(environmentFailure?complete.result==='FAIL'&&complete.failed>0
|
|
240
|
+
:complete.result==='BLOCKED'&&complete.failed===0&&complete.blocked>0)
|
|
190
241
|
&&complete.mode===start.mode&&complete.case_count===start.case_count
|
|
191
242
|
&&['case_count','passed','failed','blocked'].every(key=>Number.isSafeInteger(complete[key])&&complete[key]>=0)
|
|
192
|
-
&&complete.passed+complete.blocked===start.case_count
|
|
243
|
+
&&complete.passed+complete.failed+complete.blocked===start.case_count
|
|
193
244
|
&&!items.some(({row})=>row.phase==='case_complete'&&row.result!=='PASS'),code);
|
|
194
245
|
let cases;
|
|
195
246
|
try{
|
|
@@ -204,14 +255,35 @@ function blockedEvidenceCases(items,specsDir,environment,code='qa_rerun_not_bloc
|
|
|
204
255
|
}catch{need(false,code);}
|
|
205
256
|
need(cases.length===start.case_count&&new Set(cases.map(row=>row.id)).size===cases.length
|
|
206
257
|
&&cases.filter(row=>row.verdict==='PASS').length===complete.passed
|
|
258
|
+
&&cases.filter(row=>row.verdict==='FAIL').length===complete.failed
|
|
207
259
|
&&cases.filter(row=>row.verdict==='BLOCKED').length===complete.blocked,code);
|
|
208
|
-
const
|
|
260
|
+
const byId=new Map(cases.map(row=>[row.id,row]));
|
|
261
|
+
const mapped=(row,test)=>Array.isArray(row.commandEvidence)&&row.commandEvidence.some(item=>test(byId.get(item)));
|
|
262
|
+
const blocked=cases.filter(row=>row.verdict==='BLOCKED'),failed=cases.filter(row=>row.verdict==='FAIL');
|
|
263
|
+
if(legacyRule){for(const row of blocked)need(legacyEligible(row,environment),code);return {blocked:blocked.map(row=>row.id).sort(),failed:[]};}
|
|
264
|
+
const contract=contractCases(specsDir,start.feature,code);
|
|
265
|
+
// A case may be rerun only if the approved contract has no unresolved
|
|
266
|
+
// [需确认] expectation for it; the report marker must not say otherwise.
|
|
267
|
+
const resolved=row=>!confirmationPending(contract.get(row.id))&&row.needsConfirmation!==true;
|
|
268
|
+
// A host-declared BLOCKED is proven by the durable case_blocked log row the
|
|
269
|
+
// executor appended when the session answered, not by the mutable report.
|
|
270
|
+
const declaredInLog=new Set(items.filter(({row})=>row.phase==='case_blocked'&&row.host_declared_blocked===true)
|
|
271
|
+
.map(({row})=>row.case_id));
|
|
209
272
|
for(const row of blocked)need(!row.sourceChanged&&(
|
|
210
|
-
row.kind==='logic'&&row.staticVerdict==='INSUFFICIENT_EVIDENCE'
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
||
|
|
214
|
-
|
|
273
|
+
row.kind==='logic'&&resolved(row)&&(row.staticVerdict==='INSUFFICIENT_EVIDENCE'
|
|
274
|
+
// Blocked only by a mapped command without exit code, derived from the
|
|
275
|
+
// recorded command rows; the executor's marker has to agree.
|
|
276
|
+
||row.staticVerdict==='SUPPORTED'&&mapped(row,unavailableCommand)&&row.commandUnavailable===true)
|
|
277
|
+
||row.kind==='browser'&&resolved(row)&&(typeof row.evidenceProblem==='string'&&row.evidenceProblem.length>0
|
|
278
|
+
||row.cleanup==='failed'||row.hostRequestTimeout===true||declaredInLog.has(row.id)&&row.hostDeclaredBlocked===true
|
|
279
|
+
||environment!=null&&row.environment!=null&&digest(row.environment)!==digest(environment))
|
|
280
|
+
||unavailableCommand(row)),code);
|
|
281
|
+
// Only declared (otherwise failed is empty): every failure must be a command
|
|
282
|
+
// exit, or a logic case failed by such a mapped command. Browser and
|
|
283
|
+
// CONTRADICTED failures never are.
|
|
284
|
+
for(const row of failed)need(exitedCommand(row)
|
|
285
|
+
||row.kind==='logic'&&row.staticVerdict!=='CONTRADICTED'&&mapped(row,exitedCommand),code);
|
|
286
|
+
return {blocked:blocked.map(row=>row.id).sort(),failed:failed.map(row=>row.id).sort()};
|
|
215
287
|
}
|
|
216
288
|
|
|
217
289
|
// Supersession is authorized by the owner journal, never a self-reported log digest.
|
|
@@ -252,9 +324,14 @@ function validateRunSequence(items,code='qa_round_invalid',specsDir){
|
|
|
252
324
|
need(prior.filter(entry=>entry.row.phase==='complete').length===1,code);
|
|
253
325
|
validateConfigurationSupersession(row,specsDir,code);
|
|
254
326
|
}else{
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
327
|
+
const declared=row.reason==='declared_environment_failure';
|
|
328
|
+
need(declared?validEnvironmentFailureReason(row.environment_failure_reason):row.reason==='host_evidence_problem',code);
|
|
329
|
+
// Rows without recovery_rule were written by released versions before
|
|
330
|
+
// this change (the pre-branch format) under the original rule.
|
|
331
|
+
const legacy=row.recovery_rule===undefined;need(legacy||row.recovery_rule===2,code);
|
|
332
|
+
const cases=recoverableCases(prior,specsDir,row.expected_environment,code,declared,legacy);
|
|
333
|
+
need(JSON.stringify(row.blocked_cases)===JSON.stringify(cases.blocked)
|
|
334
|
+
&&(declared?JSON.stringify(row.failed_cases)===JSON.stringify(cases.failed):row.failed_cases===undefined),code);
|
|
258
335
|
}
|
|
259
336
|
superseded=true;
|
|
260
337
|
}
|
|
@@ -288,7 +365,7 @@ function qaRunRows(input){
|
|
|
288
365
|
|
|
289
366
|
// Only a trusted resumed owner calls this after fresh explicit authorization.
|
|
290
367
|
// Retain unknown for non-PASS results, even if their evidence files vanished.
|
|
291
|
-
export function inspectCmAiQaRecovery(input,{blocked=false,environment=null}={}){
|
|
368
|
+
export function inspectCmAiQaRecovery(input,{blocked=false,environment=null,environmentFailure=null}={}){
|
|
292
369
|
const rows=qaRunRows(input),starts=validateRunSequence(rows,'qa_round_invalid',input.specsDir),start=starts.at(-1).row;
|
|
293
370
|
const runs=rows.filter(item=>item.row.operation_id===start.operation_id);
|
|
294
371
|
// Reject an operation ID reused under another decision, identity or package.
|
|
@@ -297,10 +374,15 @@ export function inspectCmAiQaRecovery(input,{blocked=false,environment=null}={})
|
|
|
297
374
|
need(rows.some(item=>JSON.stringify(item.row)===JSON.stringify(row)),'qa_result_mismatch');
|
|
298
375
|
});
|
|
299
376
|
if(blocked){
|
|
300
|
-
|
|
377
|
+
// After a crash between superseded and start, the recorded row decides
|
|
378
|
+
// whether this was a declared environment failure; the flag is not re-read.
|
|
379
|
+
const recorded=runs.find(({row})=>row.phase==='superseded')?.row;
|
|
380
|
+
const declared=recorded?recorded.reason==='declared_environment_failure':environmentFailure!==null;
|
|
381
|
+
const cases=recoverableCases(runs,input.specsDir,environment,'qa_rerun_not_blocked_by_evidence',declared,
|
|
382
|
+
recorded!==undefined&&recorded.recovery_rule===undefined);
|
|
301
383
|
need(start.attempt<3,'qa_round_invalid');
|
|
302
384
|
return {testRunId:start.operation_id,qaRound:start.attempt,mode:start.mode,caseCount:start.case_count,
|
|
303
|
-
blockedCases,
|
|
385
|
+
blockedCases:cases.blocked,failedCases:cases.failed,superseded:recorded!==undefined};
|
|
304
386
|
}
|
|
305
387
|
const passed=partialPassCases(runs,'qa_execution_unknown');
|
|
306
388
|
const report=path.join(input.specsDir,'.reviews',`${start.operation_id}-execution.md`);
|
|
@@ -345,20 +427,55 @@ export function inspectCmAiQaConfigurationRecovery(input){
|
|
|
345
427
|
return {testRunId:row.operation_id,qaRound:row.attempt,mode:row.mode,caseCount:row.case_count,superseded:true};
|
|
346
428
|
}
|
|
347
429
|
|
|
430
|
+
// Log positions of this run's first N6 test_run row (under any decision,
|
|
431
|
+
// package or attempt: a QA round has started) and of one revision mirror row.
|
|
432
|
+
function preRoundPositions({specsDir,feature,identity},revisionDigest=null){
|
|
433
|
+
text(specsDir);text(feature);validIdentity(identity);
|
|
434
|
+
const log=path.join(path.resolve(specsDir),'运行日志.jsonl');
|
|
435
|
+
let position=0,firstRun=null,mirror=null;
|
|
436
|
+
if(fs.existsSync(log))scanRows(log,row=>{const index=position++;
|
|
437
|
+
if(row?.workflow!=='cm-ai'||row.run_id!==identity.runId||row.repository_id!==identity.repositoryId)return;
|
|
438
|
+
if(firstRun===null&&row.event==='test_run'&&row.node==='N6'&&row.feature===feature&&row.task===identity.taskId)firstRun=index;
|
|
439
|
+
if(mirror===null&&revisionDigest!==null&&row.event==='decision'&&row.phase==='qa_config_revise'
|
|
440
|
+
&&row.qa_revision_digest===revisionDigest)mirror=index;});
|
|
441
|
+
return {firstRun,mirror};
|
|
442
|
+
}
|
|
443
|
+
export const hasCmAiQaRun=input=>preRoundPositions(input).firstRun!==null;
|
|
444
|
+
|
|
445
|
+
// The owner journal authorizes the change; this deterministic row is its audit
|
|
446
|
+
// mirror, written before any QA round. A journal-only crash is repaired only
|
|
447
|
+
// while no round exists, and a mirror after a round fails closed on every open.
|
|
448
|
+
function recordPreRoundRevision(input,record){
|
|
449
|
+
const {specsDir,codeProject,feature,identity}=input,revisionDigest=digest(record);
|
|
450
|
+
const {firstRun,mirror}=preRoundPositions(input,revisionDigest);
|
|
451
|
+
need(firstRun===null||mirror!==null&&mirror<firstRun,'qa_revision_invalid');
|
|
452
|
+
if(mirror!==null)return;
|
|
453
|
+
const data={node:'N6',feature,task:identity.taskId,attempt:identity.attempt,repository_id:identity.repositoryId,
|
|
454
|
+
package_digest:record.packageDigest,qa_revision_digest:revisionDigest,from_fingerprint:record.fromFingerprint,
|
|
455
|
+
to_fingerprint:record.toFingerprint,reason:record.reason};
|
|
456
|
+
const args=[writer,'--workflow','cm-ai','--event','decision','--phase','qa_config_revise','--runtime','codex',
|
|
457
|
+
'--project-root',codeProject,'--specs-dir',specsDir,'--run-id',identity.runId,'--at',record.revisedAt,
|
|
458
|
+
'--detail','首轮 QA 前修订 QA 配置,不消耗轮次','--data-json',JSON.stringify(data)];
|
|
459
|
+
let result;
|
|
460
|
+
try{result=childProcess.spawnSync('python3',args,{timeout:10000,maxBuffer:MiB,killSignal:'SIGKILL',
|
|
461
|
+
...(input.logHome?{env:{...process.env,CM_WORKFLOW_LOG_HOME:input.logHome}}:{})});}
|
|
462
|
+
catch{need(false,'qa_log_failed');}
|
|
463
|
+
need(!result.error&&result.status===0&&result.signal===null&&Buffer.isBuffer(result.stdout),'qa_log_failed');
|
|
464
|
+
return readResult(result.stdout,identity,specsDir);
|
|
465
|
+
}
|
|
466
|
+
|
|
348
467
|
export function recordCmAiQaConfigurationRevision(input,raw){
|
|
349
468
|
const record=readQaConfigRevision(raw),{specsDir,feature,identity,packageDigest}=input;
|
|
469
|
+
if(beforeFirstQaRound(record))return recordPreRoundRevision(input,record);
|
|
350
470
|
const rows=qaRunRows({specsDir,feature,identity,packageDigest});
|
|
351
471
|
const existing=rows.find(({row})=>row.phase==='superseded'&&row.qa_revision_digest===digest(record));
|
|
352
472
|
if(existing){
|
|
353
473
|
validateConfigurationSupersession(existing.row,input.specsDir,'qa_revision_invalid');
|
|
354
|
-
if(rows.at(-1)===existing)writeCmAiQaStatus({specsDir,feature,identity,phase:'configuration_revised'});
|
|
355
474
|
return;
|
|
356
475
|
}
|
|
357
476
|
const target=inspectCmAiQaRevisionTarget(input);
|
|
358
477
|
need(target.testRunId===record.testRunId&&target.qaRound===record.qaRound,'qa_revision_invalid');
|
|
359
|
-
|
|
360
|
-
writeCmAiQaStatus({specsDir,feature,identity,phase:'configuration_revised'});
|
|
361
|
-
return result;
|
|
478
|
+
return recordCmAiQaRun({...input,...target,phase:'superseded',configurationRevision:record});
|
|
362
479
|
}
|
|
363
480
|
|
|
364
481
|
export function recordCmAiQaRun(input) {
|
|
@@ -370,6 +487,7 @@ export function recordCmAiQaRun(input) {
|
|
|
370
487
|
if(Object.hasOwn(input,'deferredCases'))keys.push('deferredCases');
|
|
371
488
|
if(Object.hasOwn(input,'expectedEnvironment'))keys.push('expectedEnvironment');
|
|
372
489
|
if(Object.hasOwn(input,'configurationRevision'))keys.push('configurationRevision');
|
|
490
|
+
if(Object.hasOwn(input,'environmentFailure'))keys.push('environmentFailure');
|
|
373
491
|
shape(input,keys);validIdentity(input.identity);id(input.testRunId);hex(input.packageDigest);
|
|
374
492
|
text(input.specsDir);text(input.codeProject);text(input.feature);
|
|
375
493
|
need(['commands','browser','all'].includes(input.mode));
|
|
@@ -378,15 +496,19 @@ export function recordCmAiQaRun(input) {
|
|
|
378
496
|
const qaRound=input.qaRound??1;
|
|
379
497
|
need(Number.isSafeInteger(qaRound)&&qaRound>=1&&qaRound<=3,'qa_round_invalid');
|
|
380
498
|
const binding={specsDir:input.specsDir,feature:input.feature,identity:input.identity,packageDigest:input.packageDigest};
|
|
381
|
-
let passed=[],blockedCases=[];
|
|
499
|
+
let passed=[],blockedCases=[],failedCases=[],declaredFailure=null;
|
|
500
|
+
if(Object.hasOwn(input,'environmentFailure'))need(input.phase==='superseded'&&!input.configurationRevision
|
|
501
|
+
&&validEnvironmentFailureReason(input.environmentFailure),'qa_recovery_authorization_required');
|
|
382
502
|
if(input.configurationRevision){
|
|
383
503
|
need(input.phase==='superseded','qa_revision_invalid');
|
|
384
504
|
const record=readQaConfigRevision(input.configurationRevision),target=inspectCmAiQaRevisionTarget(binding);
|
|
385
505
|
need(record.taskAttempt===input.identity.attempt&&record.testRunId===input.testRunId&&target.testRunId===input.testRunId&&record.packageDigest===input.packageDigest
|
|
386
506
|
&&target.qaRound===qaRound&&record.qaRound===qaRound&&target.mode===input.mode&&target.caseCount===input.caseCount,'qa_revision_invalid');
|
|
387
507
|
}else if(input.phase==='superseded'){
|
|
388
|
-
const previous=inspectCmAiQaRecovery(binding,{blocked:true,environment:input.expectedEnvironment
|
|
389
|
-
|
|
508
|
+
const previous=inspectCmAiQaRecovery(binding,{blocked:true,environment:input.expectedEnvironment,
|
|
509
|
+
environmentFailure:input.environmentFailure??null});
|
|
510
|
+
blockedCases=previous.blockedCases;failedCases=previous.failedCases;
|
|
511
|
+
declaredFailure=input.environmentFailure??null;
|
|
390
512
|
need(previous.testRunId===input.testRunId&&previous.qaRound===qaRound
|
|
391
513
|
&&previous.mode===input.mode&&previous.caseCount===input.caseCount,'qa_round_invalid');
|
|
392
514
|
if(previous.superseded)return;
|
|
@@ -430,9 +552,11 @@ export function recordCmAiQaRun(input) {
|
|
|
430
552
|
}
|
|
431
553
|
if(input.phase==='abandoned')Object.assign(data,{previous_test_run_id:input.testRunId,reason:'host_terminated',partial_pass_cases:passed});
|
|
432
554
|
if(input.phase==='superseded')Object.assign(data,{previous_test_run_id:input.testRunId,
|
|
433
|
-
reason:'host_evidence_problem',
|
|
555
|
+
reason:declaredFailure===null?'host_evidence_problem':'declared_environment_failure',recovery_rule:2,
|
|
556
|
+
blocked_cases:blockedCases,expected_environment:input.expectedEnvironment??null,
|
|
557
|
+
...(declaredFailure===null?{}:{failed_cases:failedCases,environment_failure_reason:declaredFailure})});
|
|
434
558
|
if(input.configurationRevision){
|
|
435
|
-
delete data.blocked_cases;delete data.expected_environment;
|
|
559
|
+
delete data.blocked_cases;delete data.expected_environment;delete data.recovery_rule;
|
|
436
560
|
Object.assign(data,{reason:'qa_configuration_revision',qa_revision_digest:digest(input.configurationRevision)});
|
|
437
561
|
validateConfigurationSupersession({...data,run_id:input.identity.runId},input.specsDir,'qa_revision_invalid');
|
|
438
562
|
}
|
|
@@ -506,8 +630,8 @@ function inspectQaResult(input,failureSource,historical=false) {
|
|
|
506
630
|
&&row.package_digest===input.packageDigest)decisions.push(item);
|
|
507
631
|
if(row?.schema_version===1&&row.workflow==='cm-ai'&&row.event==='test_run')allRuns.push(item);
|
|
508
632
|
});}catch{need(false,'qa_result_invalid');}
|
|
509
|
-
need(decisions.
|
|
510
|
-
const
|
|
633
|
+
need(effectiveQaDecisionRow(decisions.map(item=>item.row),'qa_not_triggered')?.status==='triggered','qa_not_triggered');
|
|
634
|
+
const decision=decisions.at(-1),decisionId=decision.row.decision_id;id(decisionId);
|
|
511
635
|
const selected=allRuns.filter(item=>item.row.operation_id===input.testRunId);
|
|
512
636
|
need(selected.length>0,'qa_result_incomplete');
|
|
513
637
|
const bound=row=>row.node==='N6'&&row.repository_id===input.identity.repositoryId
|
|
@@ -515,7 +639,7 @@ function inspectQaResult(input,failureSource,historical=false) {
|
|
|
515
639
|
&&row.package_digest===input.packageDigest
|
|
516
640
|
&&row.qa_decision_id===decisionId;
|
|
517
641
|
for(const {row} of selected)need(bound(row),'qa_result_mismatch');
|
|
518
|
-
const candidates=allRuns.filter(item=>item.position>
|
|
642
|
+
const candidates=allRuns.filter(item=>item.position>decision.position&&bound(item.row));
|
|
519
643
|
need(candidates.length>0,'qa_result_invalid');
|
|
520
644
|
for(const {row} of candidates)need(typeof row.operation_id==='string'
|
|
521
645
|
&&/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(row.operation_id)
|
|
@@ -530,7 +654,7 @@ function inspectQaResult(input,failureSource,historical=false) {
|
|
|
530
654
|
need(runs.length>0,'qa_result_invalid');
|
|
531
655
|
const starts=runs.filter(item=>item.row.phase==='start'),completes=runs.filter(item=>item.row.phase==='complete');
|
|
532
656
|
need(starts.length===1&&completes.length===1,'qa_result_incomplete');
|
|
533
|
-
need(
|
|
657
|
+
need(decision.position<starts[0].position&&starts[0].position<completes[0].position,'qa_result_invalid');
|
|
534
658
|
const start=starts[0].row,complete=completes[0].row;
|
|
535
659
|
text(start.mode);text(complete.mode);need(start.mode===complete.mode&&start.attempt===complete.attempt,'qa_result_invalid');
|
|
536
660
|
for(const key of ['case_count','passed','failed','blocked'])
|
|
@@ -1,67 +1,28 @@
|
|
|
1
1
|
// Thin N8 adapter for the JS run_done authority through its platform lock adapter and status file.
|
|
2
2
|
import childProcess from 'node:child_process';
|
|
3
|
-
import {randomUUID} from 'node:crypto';
|
|
4
3
|
import fs from 'node:fs';
|
|
5
4
|
import path from 'node:path';
|
|
6
5
|
import {fileURLToPath} from 'node:url';
|
|
7
6
|
import {hex,id,json,need,shape,text,validIdentity} from './effect-contract.mjs';
|
|
7
|
+
import {validRunId} from '../../../scripts/cm-log-event.mjs';
|
|
8
|
+
import {statusTarget,writeStatusProjection} from './status-projection.mjs';
|
|
8
9
|
|
|
9
10
|
const writer=fileURLToPath(new URL('../../../scripts/cm-log-event.py',import.meta.url));
|
|
10
11
|
const MiB=1024*1024;
|
|
11
12
|
|
|
12
|
-
function statusTarget(specsDir) {
|
|
13
|
-
try {
|
|
14
|
-
const specs=fs.realpathSync(specsDir),stat=fs.lstatSync(specs);
|
|
15
|
-
need(stat.isDirectory()&&!stat.isSymbolicLink(),'status_invalid');
|
|
16
|
-
const target=path.join(specs,'.cm-status.json');
|
|
17
|
-
if(fs.existsSync(target)){
|
|
18
|
-
const targetStat=fs.lstatSync(target);
|
|
19
|
-
need(targetStat.isFile()&&!targetStat.isSymbolicLink(),'status_invalid');
|
|
20
|
-
need(fs.realpathSync(target)===target,'status_invalid');
|
|
21
|
-
}
|
|
22
|
-
return {specs,target};
|
|
23
|
-
} catch(error) {
|
|
24
|
-
if(error?.code==='status_invalid')throw error;
|
|
25
|
-
need(false,'status_invalid');
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function prepareStatus({specs,target},feature,identity,progress=null) {
|
|
30
|
-
const temporary=path.join(specs,`.cm-status.json.tmp.${process.pid}.${randomUUID()}`);
|
|
31
|
-
const value=progress??{node:'N8',feature,task:identity.taskId,detail:'全部任务和文档同步已完成',
|
|
32
|
-
state:'run_done',at:new Date().toTimeString().slice(0,8)};
|
|
33
|
-
let descriptor;
|
|
34
|
-
try {
|
|
35
|
-
descriptor=fs.openSync(temporary,fs.constants.O_WRONLY|fs.constants.O_CREAT|fs.constants.O_EXCL
|
|
36
|
-
|(fs.constants.O_NOFOLLOW??0),0o644);
|
|
37
|
-
fs.writeFileSync(descriptor,`${JSON.stringify(value)}\n`);fs.fsyncSync(descriptor);
|
|
38
|
-
fs.closeSync(descriptor);descriptor=undefined;
|
|
39
|
-
return {temporary,target,specs};
|
|
40
|
-
} catch {
|
|
41
|
-
if(descriptor!==undefined)try{fs.closeSync(descriptor);}catch{}
|
|
42
|
-
try{fs.unlinkSync(temporary);}catch{}
|
|
43
|
-
need(false,'status_write_failed');
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
13
|
// Existing status file is only the current log projection, not a task store.
|
|
48
14
|
export function writeCmAiQaStatus({specsDir,feature,identity,caseId,phase,result}) {
|
|
49
15
|
validIdentity(identity);text(feature);
|
|
50
16
|
need(['case_start','case_complete','case_blocked','complete','configuration_revised'].includes(phase));
|
|
51
17
|
if(phase!=='complete'&&phase!=='configuration_revised')id(caseId);
|
|
52
18
|
if(phase==='complete')need(['PASS','FAIL','BLOCKED'].includes(result?.result),'qa_result_invalid');
|
|
53
|
-
|
|
19
|
+
writeStatusProjection({specsDir,feature,identity,node:'N6',claim:['case_start','configuration_revised'].includes(phase),
|
|
20
|
+
...(phase==='complete'?{allowedNodes:['N3','N5','N6']}:{}),
|
|
21
|
+
...(phase==='case_complete'||phase==='case_blocked'?{caseId,allowedNodes:['N6']}:{}),
|
|
22
|
+
...(phase==='case_start'?{caseId}:{}),
|
|
54
23
|
detail:phase==='configuration_revised'?'QA 配置已修订,旧结果仅作历史,等待下一轮':phase==='complete'?`QA 结果 ${result.result}(通过 ${result.passed} / 失败 ${result.failed} / 阻断 ${result.blocked})`:`QA ${caseId}: ${phase}`,
|
|
55
24
|
state:phase==='configuration_revised'?'qa_pending':phase==='complete'?{PASS:'qa_passed',FAIL:'qa_failed',BLOCKED:'qa_blocked'}[result.result]:'qa_running',
|
|
56
|
-
|
|
57
|
-
try{
|
|
58
|
-
fs.renameSync(prepared.temporary,prepared.target);
|
|
59
|
-
const directory=fs.openSync(prepared.specs,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
|
|
60
|
-
try{fs.fsyncSync(directory);}finally{fs.closeSync(directory);}
|
|
61
|
-
}catch{
|
|
62
|
-
try{fs.unlinkSync(prepared.temporary);}catch{}
|
|
63
|
-
need(false,'status_write_failed');
|
|
64
|
-
}
|
|
25
|
+
});
|
|
65
26
|
}
|
|
66
27
|
|
|
67
28
|
function readResult(stdout,identity,specsDir) {
|
|
@@ -81,8 +42,8 @@ export function recordCmAiRunDone(input) {
|
|
|
81
42
|
if(input&&Object.hasOwn(input,'logHome'))keys.push('logHome');
|
|
82
43
|
shape(input,keys);text(input.specsDir);text(input.codeProject);text(input.feature);validIdentity(input.identity);
|
|
83
44
|
hex(input.packageDigest);hex(input.contextDigest);id(input.documentationSyncId);
|
|
84
|
-
need(
|
|
85
|
-
|
|
45
|
+
need(validRunId(input.identity.runId),'invalid_run_id');
|
|
46
|
+
statusTarget(input.specsDir);
|
|
86
47
|
const data={node:'N8',feature:input.feature,task:input.identity.taskId,package_digest:input.packageDigest,
|
|
87
48
|
context_digest:input.contextDigest,documentation_sync_id:input.documentationSyncId};
|
|
88
49
|
const args=[writer,'--workflow','cm-ai','--event','run_done','--runtime','codex',
|
|
@@ -92,20 +53,16 @@ export function recordCmAiRunDone(input) {
|
|
|
92
53
|
if(Object.hasOwn(input,'logHome')){text(input.logHome);options.env={...process.env,CM_WORKFLOW_LOG_HOME:input.logHome};}
|
|
93
54
|
let result;
|
|
94
55
|
try{result=childProcess.spawnSync('python3',args,options);}
|
|
95
|
-
catch{
|
|
56
|
+
catch{need(false,'run_log_failed');}
|
|
96
57
|
if(result.error||result.status!==0||result.signal!==null||!Buffer.isBuffer(result.stdout)
|
|
97
|
-
||result.stdout.length>MiB)
|
|
58
|
+
||result.stdout.length>MiB)need(false,'run_log_failed');
|
|
98
59
|
let receipt;
|
|
99
60
|
try{receipt=readResult(result.stdout,input.identity,input.specsDir);}
|
|
100
|
-
catch{
|
|
61
|
+
catch{need(false,'run_finalize_unknown');}
|
|
101
62
|
try {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
} catch {
|
|
106
|
-
try{fs.unlinkSync(prepared.temporary);}catch{}
|
|
107
|
-
need(false,'run_finalize_unknown');
|
|
108
|
-
}
|
|
63
|
+
writeStatusProjection({specsDir:input.specsDir,feature:input.feature,identity:input.identity,node:'N8',
|
|
64
|
+
state:'run_done',detail:'全部任务和文档同步已完成'});
|
|
65
|
+
}catch{need(false,'run_finalize_unknown');}
|
|
109
66
|
return Object.freeze({eventId:receipt.event_id,runId:receipt.run_id,
|
|
110
67
|
deduplicated:receipt.deduplicated,degraded:receipt.degraded});
|
|
111
68
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
+
import {externalEffort} from './external-models.mjs';
|
|
5
6
|
|
|
6
7
|
// Native profile, not an outer sandbox. Keep the built-in workspace protections.
|
|
7
8
|
// Reference: https://learn.chatgpt.com/docs/permissions (beta, checked locally).
|
|
@@ -25,7 +26,7 @@ export const disabledFeatures = Object.freeze([
|
|
|
25
26
|
'skill_mcp_dependency_install', 'tool_suggest',
|
|
26
27
|
]);
|
|
27
28
|
|
|
28
|
-
export function commonArgs({ cwd, model, disabledSkills = [] }) {
|
|
29
|
+
export function commonArgs({ cwd, model, effort, disabledSkills = [] }) {
|
|
29
30
|
if (!/^[a-zA-Z0-9._-]+$/.test(model)) throw new Error('invalid model');
|
|
30
31
|
return ['exec', '--ignore-user-config', '--strict-config', '--ephemeral',
|
|
31
32
|
'--sandbox', 'read-only', '--skip-git-repo-check', '--cd', cwd, '--json',
|
|
@@ -33,7 +34,7 @@ export function commonArgs({ cwd, model, disabledSkills = [] }) {
|
|
|
33
34
|
'-c', 'approval_policy="never"', '-c', 'web_search="disabled"',
|
|
34
35
|
'-c', 'project_doc_max_bytes=0', '-c', 'mcp_servers={}',
|
|
35
36
|
'-c', 'check_for_update_on_startup=false', '-c', 'analytics.enabled=false',
|
|
36
|
-
'-c', `model="${model}"`, '-c',
|
|
37
|
+
'-c', `model="${model}"`, '-c', `model_reasoning_effort=${JSON.stringify(externalEffort('codex',effort))}`,
|
|
37
38
|
// Codex 0.153.4 injects a <skills_instructions> catalog built from every skill root
|
|
38
39
|
// (~/.codex/skills, ~/.agents/skills, ...) even with --ignore-user-config, skills.config
|
|
39
40
|
// disables, skip_host_skill_discovery or --ignore-rules. Only this key removes the block.
|