@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
|
@@ -2,29 +2,48 @@
|
|
|
2
2
|
import {inspectCmAiAdmission,matchesCmAiTaskSelection} from './cm-ai-admission.mjs';
|
|
3
3
|
import {inspectCmAiContextRefresh,inspectCmAiTaskLearningInput} from './cm-ai-context-refresh.mjs';
|
|
4
4
|
import {findCmAiQaDecision,inspectCmAiQaDecision,inspectCmAiQaResult,recordCmAiQaDecision,
|
|
5
|
-
latestCmAiQaRun,recordCmAiQaRun,inspectCmAiQaRecovery,inspectCmAiQaConfigurationRecovery
|
|
5
|
+
latestCmAiQaRun,recordCmAiQaRun,inspectCmAiQaRecovery,inspectCmAiQaConfigurationRecovery,timedOutQaDecision,
|
|
6
|
+
replacesTimedOutQaDecision,validEnvironmentFailureReason} from './cm-ai-qa-log.mjs';
|
|
6
7
|
import {recordCmAiRunDone} from './cm-ai-run-finalizer.mjs';
|
|
8
|
+
import {projectHostResult} from './host-progress.mjs';
|
|
9
|
+
import {operatorGuidance} from './operator-guidance.mjs';
|
|
10
|
+
import {outstandingFeatureQa,describeOutstandingQa} from './project-qa-gate.mjs';
|
|
7
11
|
import {REVIEWED_HANDOFF_HINT} from './host-handoff.mjs';
|
|
8
12
|
import {readHostQaFixHandoff} from './host-qa-fix.mjs';
|
|
13
|
+
import {readCloseoutPolicy,readCloseoutReport,closeoutSummary} from './knowledge-closeout.mjs';
|
|
9
14
|
import {digest,freeze,hex,id,json,need,shape,text,validIdentity} from './effect-contract.mjs';
|
|
10
15
|
|
|
11
16
|
const sameIdentity=(left,right)=>['repositoryId','runId','taskId','attempt'].every(key=>left[key]===right[key]);
|
|
12
17
|
const sameTask=(left,right)=>['repositoryId','runId','taskId'].every(key=>left[key]===right[key]);
|
|
13
18
|
const boundStatus=(status,identity)=>{validIdentity(status?.identity);
|
|
14
19
|
need(sameIdentity(status.identity,identity),'identity_mismatch');return status;};
|
|
15
|
-
|
|
20
|
+
// A no-result timeout, an explicit abandonment, a reviewer failure with no
|
|
21
|
+
// verdict and a verdict that broke the written contract share one redispatch
|
|
22
|
+
// per attempt. Exported for the batch driver, like developmentRetryable.
|
|
23
|
+
export const reviewRetryable=status=>status.state==='pending_review'
|
|
24
|
+
&&['review_transport_timeout','review_abandoned','review_provider_failed','review_verdict_invalid'].includes(status.code);
|
|
25
|
+
const retryReview=reviewRetryable;
|
|
16
26
|
// Both mean the delivery itself must be redone: an invalid developer result, or
|
|
17
27
|
// one that does not satisfy the task's own written verification. Exported so the
|
|
18
28
|
// batch driver decides retryability from the same predicate instead of keeping a
|
|
19
29
|
// second copy of the code list that silently drifts.
|
|
20
30
|
export const developmentRetryable=status=>status.state==='blocked'
|
|
21
|
-
&&['developer_result_invalid','verification_precheck_failed'].includes(status.code);
|
|
31
|
+
&&['developer_result_invalid','verification_precheck_failed','check_output_out_of_scope','develop_checks_not_passed','develop_unchanged_after_review','develop_empty_changes','develop_requirement_missing','develop_package_too_large','bootstrap_verification_failed'].includes(status.code);
|
|
22
32
|
const retryDeveloper=developmentRetryable;
|
|
33
|
+
export const completionRetryable=status=>status.state==='blocked'
|
|
34
|
+
&&['completion_checks_changed','completion_package_changed'].includes(status.code)
|
|
35
|
+
&&status.retryReady!==false;
|
|
23
36
|
const pendingAction=status=>status.state==='awaiting_spec_approval'?'spec_approval':
|
|
37
|
+
// The runner reports spec_drift over any state whose next effect would be refused.
|
|
38
|
+
status.code==='spec_drift'?(status.specificationRebind==='available'?'spec_rebind':'none'):
|
|
39
|
+
status.bootstrapReviewRecovery===true?'bootstrap_review_recover':
|
|
40
|
+
status.reviewReconciliation?.available?'reconcile_review':
|
|
24
41
|
status.state==='changes_requested'||retryDeveloper(status)||retryReview(status)?'resume':
|
|
25
|
-
status.state==='awaiting_review'?'decision':status.state==='unknown'
|
|
42
|
+
status.state==='awaiting_review'?'decision':status.state==='unknown'
|
|
43
|
+
?(status.pendingEffectKind?'abandon_effect':
|
|
44
|
+
status.pendingReviewInvocation||status.abandonableReviewResult?'abandon_review':'reconcile'):
|
|
26
45
|
status.state==='pending_review'&&status.code==='provider_review_observed'?'review_evidence':
|
|
27
|
-
status.state==='pending_review'?'decision':status.state==='approved'?'complete':
|
|
46
|
+
status.state==='pending_review'?'decision':status.state==='approved'||completionRetryable(status)?'complete':
|
|
28
47
|
status.state==='fixture_completed'&&status.code==='qa_triggered'?'qa_execution':
|
|
29
48
|
status.state==='fixture_completed'&&status.code==='qa_skipped'?'context_refresh':
|
|
30
49
|
status.state==='fixture_completed'&&status.code==='qa_passed'?'context_refresh':
|
|
@@ -32,6 +51,7 @@ const pendingAction=status=>status.state==='awaiting_spec_approval'?'spec_approv
|
|
|
32
51
|
status.state==='fixture_completed'&&status.code==='documentation_sync_required'?'documentation_sync':
|
|
33
52
|
status.state==='fixture_completed'&&status.code==='documentation_synced'?'run_finalize':
|
|
34
53
|
status.state==='fixture_completed'&&status.code==='documentation_sync_blocked'?'none':
|
|
54
|
+
status.state==='fixture_completed'&&status.code==='project_qa_not_passed'?'none':
|
|
35
55
|
status.state==='fixture_completed'&&status.code==='qa_blocked'?'none':
|
|
36
56
|
status.state==='fixture_completed'&&status.code==='qa_execution_unknown'?'reconcile':
|
|
37
57
|
status.state==='fixture_completed'&&['qa_failed','qa_result_blocked'].includes(status.code)?'none':
|
|
@@ -39,20 +59,45 @@ const pendingAction=status=>status.state==='awaiting_spec_approval'?'spec_approv
|
|
|
39
59
|
const summary=(operation,status,outcome)=>freeze({version:1,workflow:'cm-ai',operation:operation.operation,
|
|
40
60
|
requestDigest:digest(operation),identity:status.identity,outcome,state:status.state,code:status.code??null,
|
|
41
61
|
packageDigest:status.packageDigest??null,pendingAction:pendingAction(status),
|
|
62
|
+
...(status.reviewReconciliation?{reviewReconciliation:status.reviewReconciliation}:{}),
|
|
63
|
+
...(typeof status.reason==='string'?{reason:status.reason}:{}),
|
|
42
64
|
...(status.code==='handoff_exists'?{reason:REVIEWED_HANDOFF_HINT}:{}),
|
|
43
65
|
...(status.state==='blocked'&&status.calls?.at(-1)?.blockedReason!==undefined
|
|
44
66
|
?{blockedReason:status.calls.at(-1).blockedReason}:{})});
|
|
45
67
|
const correctionSummary=(operation,status)=>status.code==='correction_review_required'
|
|
46
68
|
?summary(operation,status,'blocked'):null;
|
|
69
|
+
// run_done is a project claim: every approved feature's latest mandatory QA must
|
|
70
|
+
// have passed, not only this final run's own. Read with the strict owner validator.
|
|
71
|
+
function projectQaSummary(operation,status,options){
|
|
72
|
+
const admission=inspectCmAiAdmission({specsDir:options.specsDir,codeProject:options.codeProject});
|
|
73
|
+
const outstanding=outstandingFeatureQa({specsDir:options.specsDir,features:admission.features.map(({name,pending})=>({name,pending})),
|
|
74
|
+
currentRunId:status.identity.runId,inspect:latestCmAiQaRun});
|
|
75
|
+
if(!outstanding.length)return null;
|
|
76
|
+
return freeze({...summary(operation,{...status,code:'project_qa_not_passed',
|
|
77
|
+
reason:`以下 feature 的最新一轮 QA 未通过:${outstanding.map(describeOutstandingQa).join(';')}。先恢复对应运行让 QA 通过,再重新推进本运行收尾。`},'blocked'),
|
|
78
|
+
outstandingQa:outstanding});
|
|
79
|
+
}
|
|
47
80
|
|
|
48
81
|
function readOperation(raw) {
|
|
49
82
|
const operation=json(raw),keys=['version','operation','requestId','identity'];
|
|
50
83
|
if(['decision','complete','qa','qa_result','context_refresh','finish','run_finalize'].includes(operation?.operation))keys.push('packageDigest');
|
|
51
84
|
if(['qa_result','context_refresh','finish','run_finalize'].includes(operation?.operation))keys.push('testRunId');
|
|
85
|
+
if(['abandon_review','abandon_effect','bootstrap_review_recover'].includes(operation?.operation))keys.push('reason');
|
|
86
|
+
if(operation?.operation==='reconcile_review')keys.push('invocationId');
|
|
52
87
|
shape(operation,keys);
|
|
53
|
-
|
|
88
|
+
if(operation?.operation==='reconcile_review')id(operation.invocationId);
|
|
89
|
+
need(operation.version===1&&['advance','start','status','decision','complete','qa','qa_result','context_refresh','finish','run_finalize','cancel','resume','reconcile_review','abandon_review','abandon_effect','bootstrap_review_recover']
|
|
54
90
|
.includes(operation.operation));
|
|
55
91
|
id(operation.requestId);validIdentity(operation.identity);
|
|
92
|
+
if(operation.operation==='abandon_review')need(typeof operation.reason==='string'
|
|
93
|
+
&&operation.reason.trim().length>0&&Buffer.byteLength(operation.reason,'utf8')<=500
|
|
94
|
+
&&!/[\r\n\0]/.test(operation.reason),'review_abandon_reason_required');
|
|
95
|
+
if(operation.operation==='abandon_effect')need(typeof operation.reason==='string'
|
|
96
|
+
&&operation.reason.trim().length>0&&Buffer.byteLength(operation.reason,'utf8')<=500
|
|
97
|
+
&&!/[\r\n\0]/.test(operation.reason),'effect_abandon_reason_required');
|
|
98
|
+
if(operation.operation==='bootstrap_review_recover')need(typeof operation.reason==='string'
|
|
99
|
+
&&operation.reason.trim().length>0&&Buffer.byteLength(operation.reason,'utf8')<=500
|
|
100
|
+
&&!/[\r\n\0]/.test(operation.reason),'bootstrap_review_recovery_reason_required');
|
|
56
101
|
if(['decision','complete','qa','qa_result','context_refresh','finish','run_finalize'].includes(operation.operation))hex(operation.packageDigest);
|
|
57
102
|
if(operation.operation==='qa_result')id(operation.testRunId);
|
|
58
103
|
if(['context_refresh','finish','run_finalize'].includes(operation.operation)){
|
|
@@ -82,9 +127,9 @@ function validateHostDecision(decision,status) {
|
|
|
82
127
|
|
|
83
128
|
function effectSummary(operation,result,runner,identity) {
|
|
84
129
|
if(result?.outcome==='rejected'){
|
|
85
|
-
const rejection=json(result);shape(rejection,['outcome','code']);id(rejection.code);
|
|
130
|
+
const rejection=json(result);shape(rejection,['outcome','code',...(Object.hasOwn(rejection,'reason')?['reason']:[])]);id(rejection.code);
|
|
86
131
|
const current=boundStatus(runner.status(),identity);
|
|
87
|
-
return summary(operation,{...current,code:rejection.code},'rejected');
|
|
132
|
+
return summary(operation,{...current,code:rejection.code,...(rejection.reason?{reason:rejection.reason}:{})},'rejected');
|
|
88
133
|
}
|
|
89
134
|
if(operation.operation==='decision'&&identity.attempt===1&&result?.state==='changes_requested'){
|
|
90
135
|
const next={...identity,attempt:2};
|
|
@@ -114,8 +159,10 @@ const contextSummary=(operation,status,refresh)=>freeze({version:1,workflow:'cm-
|
|
|
114
159
|
pendingAction:refresh.state==='complete'?'finish':'start_next_task',nextTask:refresh.nextTask,
|
|
115
160
|
contextDigest:refresh.contextDigest,contextFiles:refresh.contextFiles});
|
|
116
161
|
|
|
117
|
-
function validateDocumentationResult(result,status,refresh) {
|
|
118
|
-
shape(result,['syncId','identity','packageDigest','contextDigest','status','reason','at'
|
|
162
|
+
function validateDocumentationResult(result,status,refresh,policy=null) {
|
|
163
|
+
shape(result,['syncId','identity','packageDigest','contextDigest','status','reason','at',
|
|
164
|
+
...(policy?.enabled&&Object.hasOwn(result,'closeout')?['closeout']:[])]);
|
|
165
|
+
if(Object.hasOwn(result,'closeout'))readCloseoutReport(result.closeout);
|
|
119
166
|
id(result.syncId);validIdentity(result.identity);hex(result.packageDigest);hex(result.contextDigest);
|
|
120
167
|
need(sameIdentity(result.identity,status.identity),'identity_mismatch');
|
|
121
168
|
need(result.packageDigest===status.packageDigest&&result.contextDigest===refresh.contextDigest,'stale_documentation');
|
|
@@ -137,33 +184,58 @@ export function createCmAiConversationEntry(options) {
|
|
|
137
184
|
if(options&&Object.hasOwn(options,'qaExecutor'))optionKeys.push('qaExecutor');
|
|
138
185
|
if(options&&Object.hasOwn(options,'rerunUnknownQa'))optionKeys.push('rerunUnknownQa');
|
|
139
186
|
if(options&&Object.hasOwn(options,'rerunBlockedQa'))optionKeys.push('rerunBlockedQa');
|
|
187
|
+
if(options&&Object.hasOwn(options,'qaEnvironmentFailure'))optionKeys.push('qaEnvironmentFailure');
|
|
140
188
|
if(options&&Object.hasOwn(options,'qaLogHome'))optionKeys.push('qaLogHome');
|
|
141
189
|
if(options&&Object.hasOwn(options,'applicableAgentFiles'))optionKeys.push('applicableAgentFiles');
|
|
142
190
|
if(options&&Object.hasOwn(options,'documentationResult'))optionKeys.push('documentationResult');
|
|
143
191
|
if(options&&Object.hasOwn(options,'documentationProvider'))optionKeys.push('documentationProvider');
|
|
192
|
+
if(options&&Object.hasOwn(options,'knowledgeCloseout'))optionKeys.push('knowledgeCloseout');
|
|
193
|
+
if(options&&Object.hasOwn(options,'codeProjects'))optionKeys.push('codeProjects');
|
|
144
194
|
if(options&&Object.hasOwn(options,'parallelSelection'))optionKeys.push('parallelSelection');
|
|
195
|
+
if(options&&Object.hasOwn(options,'allowAbandonReview'))optionKeys.push('allowAbandonReview');
|
|
196
|
+
if(options&&Object.hasOwn(options,'allowAbandonEffect'))optionKeys.push('allowAbandonEffect');
|
|
197
|
+
if(options&&Object.hasOwn(options,'allowBootstrapReviewRecovery'))optionKeys.push('allowBootstrapReviewRecovery');
|
|
198
|
+
if(options&&Object.hasOwn(options,'holdRevision'))optionKeys.push('holdRevision');
|
|
145
199
|
shape(options,optionKeys);
|
|
200
|
+
need(!Object.hasOwn(options,'holdRevision')||options.holdRevision===true,'invalid_input');
|
|
146
201
|
if(Object.hasOwn(options,'developmentAttempt'))need([1,2].includes(options.developmentAttempt),'invalid_development_attempt');
|
|
147
202
|
text(options.specsDir);text(options.codeProject);text(options.feature);
|
|
148
203
|
const ownerIdentity=json(options.identity);validIdentity(ownerIdentity);
|
|
149
204
|
const runner=options.runner;
|
|
150
205
|
const runnerKeys=['executeEffect','status','cancel','run'];
|
|
151
206
|
if(runner&&Object.hasOwn(runner,'verificationBlocks'))runnerKeys.push('verificationBlocks');
|
|
207
|
+
if(runner&&Object.hasOwn(runner,'completionBlocks'))runnerKeys.push('completionBlocks');
|
|
152
208
|
if(runner&&Object.hasOwn(runner,'attachLearningEvidence'))runnerKeys.push('attachLearningEvidence');
|
|
153
209
|
if(runner&&Object.hasOwn(runner,'inspectFixAssociation'))runnerKeys.push('inspectFixAssociation');
|
|
154
210
|
if(runner&&Object.hasOwn(runner,'acceptCompletedFix'))runnerKeys.push('acceptCompletedFix');
|
|
155
211
|
if(runner&&Object.hasOwn(runner,'attachQa'))runnerKeys.push('attachQa');
|
|
156
212
|
if(runner&&Object.hasOwn(runner,'reviseQa'))runnerKeys.push('reviseQa');
|
|
157
213
|
if(runner&&Object.hasOwn(runner,'supersedeEvidence'))runnerKeys.push('supersedeEvidence');
|
|
214
|
+
if(runner&&Object.hasOwn(runner,'rebindSpecification'))runnerKeys.push('rebindSpecification');
|
|
215
|
+
if(runner&&Object.hasOwn(runner,'abandonReview'))runnerKeys.push('abandonReview');
|
|
216
|
+
if(runner&&Object.hasOwn(runner,'reconcileReview'))runnerKeys.push('reconcileReview');
|
|
217
|
+
if(runner&&Object.hasOwn(runner,'abandonEffect'))runnerKeys.push('abandonEffect');
|
|
218
|
+
if(runner&&Object.hasOwn(runner,'recoverBootstrapReview'))runnerKeys.push('recoverBootstrapReview');
|
|
158
219
|
if(runner&&Object.hasOwn(runner,'inspectBootstrapAdmission'))runnerKeys.push('inspectBootstrapAdmission');
|
|
159
220
|
shape(runner,runnerKeys);
|
|
160
221
|
for(const name of ['executeEffect','status','cancel','run'])need(typeof runner[name]==='function');
|
|
222
|
+
if(Object.hasOwn(runner,'completionBlocks'))need(typeof runner.completionBlocks==='function');
|
|
161
223
|
if(Object.hasOwn(runner,'attachLearningEvidence'))need(typeof runner.attachLearningEvidence==='function');
|
|
162
224
|
if(Object.hasOwn(runner,'inspectFixAssociation'))need(typeof runner.inspectFixAssociation==='function');
|
|
163
225
|
if(Object.hasOwn(runner,'acceptCompletedFix'))need(typeof runner.acceptCompletedFix==='function');
|
|
164
226
|
if(Object.hasOwn(runner,'attachQa'))need(typeof runner.attachQa==='function');
|
|
165
227
|
if(Object.hasOwn(runner,'reviseQa'))need(typeof runner.reviseQa==='function');
|
|
228
|
+
if(Object.hasOwn(runner,'abandonReview'))need(typeof runner.abandonReview==='function');
|
|
229
|
+
if(Object.hasOwn(runner,'reconcileReview'))need(typeof runner.reconcileReview==='function');
|
|
230
|
+
if(Object.hasOwn(runner,'abandonEffect'))need(typeof runner.abandonEffect==='function');
|
|
231
|
+
if(Object.hasOwn(runner,'recoverBootstrapReview'))need(typeof runner.recoverBootstrapReview==='function');
|
|
166
232
|
if(Object.hasOwn(runner,'inspectBootstrapAdmission'))need(typeof runner.inspectBootstrapAdmission==='function');
|
|
233
|
+
need(options.allowAbandonReview===undefined||typeof options.allowAbandonReview==='boolean','invalid_input');
|
|
234
|
+
let abandonPermission=options.allowAbandonReview===true;
|
|
235
|
+
need(options.allowAbandonEffect===undefined||typeof options.allowAbandonEffect==='boolean','invalid_input');
|
|
236
|
+
let abandonEffectPermission=options.allowAbandonEffect===true;
|
|
237
|
+
need(options.allowBootstrapReviewRecovery===undefined||typeof options.allowBootstrapReviewRecovery==='boolean','invalid_input');
|
|
238
|
+
let bootstrapReviewRecoveryPermission=options.allowBootstrapReviewRecovery===true;
|
|
167
239
|
|
|
168
240
|
const hostDecision=Object.hasOwn(options,'hostDecision')?json(options.hostDecision):null;
|
|
169
241
|
let hostDecisionProvider=null,pendingReviewDecision=null;
|
|
@@ -184,9 +256,14 @@ export function createCmAiConversationEntry(options) {
|
|
|
184
256
|
const decideQa=qaProvider?.decide,qaTimeout=qaProvider?.timeoutMs;
|
|
185
257
|
let pendingQa=null;
|
|
186
258
|
let qaExecutor=null,pendingExecution=null,cancellationEpoch=0;
|
|
259
|
+
const inFlightHandles=new Set();
|
|
187
260
|
let rerunUnknownQa=options.rerunUnknownQa??false;need(typeof rerunUnknownQa==='boolean');
|
|
188
261
|
let rerunBlockedQa=options.rerunBlockedQa??false;need(typeof rerunBlockedQa==='boolean');
|
|
189
262
|
need(!(rerunUnknownQa&&rerunBlockedQa),'qa_recovery_authorization_required');
|
|
263
|
+
// Operator declaration that the latest FAIL came from the environment; only
|
|
264
|
+
// meaningful with the one-shot rerun authorization and consumed with it.
|
|
265
|
+
const qaEnvironmentFailure=options.qaEnvironmentFailure??null;
|
|
266
|
+
need(qaEnvironmentFailure===null||rerunBlockedQa&&validEnvironmentFailureReason(qaEnvironmentFailure),'qa_recovery_authorization_required');
|
|
190
267
|
if(Object.hasOwn(options,'qaExecutor')){
|
|
191
268
|
shape(options.qaExecutor,['mode','caseCount','timeoutMs','run',
|
|
192
269
|
...(Object.hasOwn(options.qaExecutor,'configuration')?['configuration']:[]),
|
|
@@ -199,6 +276,9 @@ export function createCmAiConversationEntry(options) {
|
|
|
199
276
|
}
|
|
200
277
|
const applicableAgentFiles=Object.hasOwn(options,'applicableAgentFiles')?json(options.applicableAgentFiles):null;
|
|
201
278
|
const documentationResult=Object.hasOwn(options,'documentationResult')?json(options.documentationResult):null;
|
|
279
|
+
const knowledgeCloseout=Object.hasOwn(options,'knowledgeCloseout')?readCloseoutPolicy(options.knowledgeCloseout):null;
|
|
280
|
+
if(Object.hasOwn(options,'codeProjects'))need(knowledgeCloseout!==null&&Array.isArray(options.codeProjects)
|
|
281
|
+
&&options.codeProjects.length>0&&options.codeProjects.every(value=>typeof value==='string'),'invalid_input');
|
|
202
282
|
let documentationProvider=null,pendingDocumentation=null,inspectedDocumentation=null;
|
|
203
283
|
if(Object.hasOwn(options,'documentationProvider')){
|
|
204
284
|
shape(options.documentationProvider,['inspect','timeoutMs']);
|
|
@@ -211,7 +291,9 @@ export function createCmAiConversationEntry(options) {
|
|
|
211
291
|
async function documentationFor(status,refresh){
|
|
212
292
|
if(documentationProvider===null)return documentationResult;
|
|
213
293
|
const binding=json({specsDir:options.specsDir,codeProject:options.codeProject,feature:options.feature,
|
|
214
|
-
identity:status.identity,packageDigest:status.packageDigest,contextDigest:refresh.contextDigest
|
|
294
|
+
identity:status.identity,packageDigest:status.packageDigest,contextDigest:refresh.contextDigest,
|
|
295
|
+
...(knowledgeCloseout===null?{}:{closeout:knowledgeCloseout,
|
|
296
|
+
...(options.codeProjects?{codeProjects:options.codeProjects}:{})})});
|
|
215
297
|
const syncId=`docs-${digest(binding).slice(0,48)}`;
|
|
216
298
|
if(inspectedDocumentation?.syncId===syncId)return inspectedDocumentation;
|
|
217
299
|
need(pendingDocumentation===null,'documentation_pending');
|
|
@@ -234,12 +316,15 @@ export function createCmAiConversationEntry(options) {
|
|
|
234
316
|
const reread=inspectCmAiContextRefresh({specsDir:options.specsDir,codeProject:options.codeProject,
|
|
235
317
|
feature:options.feature,applicableAgentFiles});
|
|
236
318
|
need(reread.state==='complete'&&reread.contextDigest===refresh.contextDigest,'stale_documentation');
|
|
237
|
-
validateDocumentationResult(result,current,reread);
|
|
319
|
+
validateDocumentationResult(result,current,reread,knowledgeCloseout);
|
|
238
320
|
if(result.status==='completed')inspectedDocumentation=result;
|
|
239
321
|
return result;
|
|
240
322
|
}finally{clearTimeout(timer);pendingDocumentation=null;}
|
|
241
323
|
}
|
|
242
324
|
|
|
325
|
+
// Admission summaries do not describe a runner transition. Track their
|
|
326
|
+
// origin privately; other awaiting results still need progress projection.
|
|
327
|
+
const admissionReports=new WeakSet();
|
|
243
328
|
async function route(raw) {
|
|
244
329
|
const operation=readOperation(raw);
|
|
245
330
|
need(sameTask(operation.identity,ownerIdentity),'identity_mismatch');
|
|
@@ -251,15 +336,16 @@ export function createCmAiConversationEntry(options) {
|
|
|
251
336
|
// a newer attempt must bind it to the runner before we report its block.
|
|
252
337
|
const blockedIdentity=sameIdentity(operation.identity,ownerIdentity)?ownerIdentity:
|
|
253
338
|
boundStatus(runner.status(),operation.identity).identity;
|
|
254
|
-
|
|
339
|
+
const report=summary(operation,{state:admission.state,code:admission.reason,
|
|
255
340
|
identity:blockedIdentity,packageDigest:null},'awaiting');
|
|
341
|
+
admissionReports.add(report);return report;
|
|
256
342
|
}
|
|
257
343
|
const initialStatus=runner.status();
|
|
258
344
|
const identity=json(initialStatus.identity);validIdentity(identity);
|
|
259
345
|
need(sameTask(identity,ownerIdentity)&&identity.attempt>=ownerIdentity.attempt,'identity_mismatch');
|
|
260
346
|
// Stable run-definition identity can query/control or resume the current
|
|
261
347
|
// attempt. Package-bound mutations must name the current attempt exactly.
|
|
262
|
-
const stableControl=['status','cancel','advance','resume'].includes(operation.operation)
|
|
348
|
+
const stableControl=['status','cancel','advance','resume','reconcile_review','abandon_review','abandon_effect','bootstrap_review_recover'].includes(operation.operation)
|
|
263
349
|
&&sameIdentity(operation.identity,ownerIdentity);
|
|
264
350
|
need(sameIdentity(operation.identity,identity)||stableControl,'identity_mismatch');
|
|
265
351
|
if(operation.operation==='advance'){
|
|
@@ -277,7 +363,8 @@ export function createCmAiConversationEntry(options) {
|
|
|
277
363
|
result=await call('decision',result.packageDigest);
|
|
278
364
|
if(result.outcome==='advanced'&&result.code===null&&result.state==='changes_requested'
|
|
279
365
|
&&result.identity.attempt===round+1)continue;
|
|
280
|
-
if(['reported','advanced'].includes(result.outcome)
|
|
366
|
+
if(['reported','advanced'].includes(result.outcome)
|
|
367
|
+
&&(result.code===null&&result.state==='approved'||completionRetryable(result)))
|
|
281
368
|
result=await call('complete',result.packageDigest);
|
|
282
369
|
break;
|
|
283
370
|
}
|
|
@@ -313,13 +400,20 @@ export function createCmAiConversationEntry(options) {
|
|
|
313
400
|
previous=null;
|
|
314
401
|
}
|
|
315
402
|
}
|
|
403
|
+
// The authorization's durable effect is a replacement of a timed-out
|
|
404
|
+
// decision with no QA run under it yet (just written, or written
|
|
405
|
+
// before an interruption): run the ordinary first round, not a rerun.
|
|
406
|
+
if(rerunBlockedQa&&previous===null&&replacesTimedOutQaDecision(binding))rerunBlockedQa=false;
|
|
316
407
|
if(rerunBlockedQa){
|
|
317
408
|
need(previous!==null,'qa_rerun_not_blocked_by_evidence');
|
|
318
|
-
recovery=inspectCmAiQaRecovery(binding,{blocked:true,environment:qaExecutor.configuration?.environment
|
|
409
|
+
recovery=inspectCmAiQaRecovery(binding,{blocked:true,environment:qaExecutor.configuration?.environment,
|
|
410
|
+
environmentFailure:qaEnvironmentFailure});
|
|
319
411
|
}
|
|
320
412
|
let testRunId=previous?.testRunId;
|
|
321
413
|
const accepted=runner.status().acceptedQaFix;
|
|
322
414
|
const repaired=previous?.status==='failed'&&accepted?.testRunId===previous.testRunId;
|
|
415
|
+
// An accepted repair already owns the next round of that FAIL.
|
|
416
|
+
need(!(rerunBlockedQa&&repaired),'qa_rerun_not_blocked_by_evidence');
|
|
323
417
|
if(previous===null||repaired||rerunBlockedQa){
|
|
324
418
|
// Later rounds require an accepted completed repair or explicit
|
|
325
419
|
// evidence recovery/configuration revision. Unknown execution stops.
|
|
@@ -334,7 +428,8 @@ export function createCmAiConversationEntry(options) {
|
|
|
334
428
|
if(recovery&&!configurationRecovery){
|
|
335
429
|
recordCmAiQaRun({...logInput,testRunId:recovery.testRunId,mode:recovery.mode,
|
|
336
430
|
caseCount:recovery.caseCount,qaRound:recovery.qaRound,phase:rerunBlockedQa?'superseded':'abandoned',
|
|
337
|
-
...(rerunBlockedQa?{expectedEnvironment:qaExecutor.configuration?.environment??null}:{})
|
|
431
|
+
...(rerunBlockedQa?{expectedEnvironment:qaExecutor.configuration?.environment??null}:{}),
|
|
432
|
+
...(rerunBlockedQa&&qaEnvironmentFailure!==null?{environmentFailure:qaEnvironmentFailure}:{})});
|
|
338
433
|
rerunUnknownQa=false;rerunBlockedQa=false;
|
|
339
434
|
}
|
|
340
435
|
recordCmAiQaRun({...logInput,phase:'start',
|
|
@@ -379,24 +474,64 @@ export function createCmAiConversationEntry(options) {
|
|
|
379
474
|
}
|
|
380
475
|
// Next-task execution and QA execution still need their host adapters;
|
|
381
476
|
// a refreshed nextTask is not permission to dispatch it or claim run_done.
|
|
382
|
-
|
|
477
|
+
const advanced=freeze({...result,operation:'advance',requestDigest:digest(operation)});
|
|
478
|
+
if(admissionReports.has(result))admissionReports.add(advanced);
|
|
479
|
+
return advanced;
|
|
383
480
|
}
|
|
384
481
|
if(operation.operation==='status'){
|
|
385
482
|
const status=boundStatus(initialStatus,identity);
|
|
386
483
|
return summary(operation,status,'reported');
|
|
387
484
|
}
|
|
388
485
|
if(operation.operation==='cancel'){
|
|
486
|
+
const interrupted=inFlightHandles.size>0||pendingReviewDecision!==null||pendingQa!==null
|
|
487
|
+
||pendingExecution!==null||pendingDocumentation!==null;
|
|
389
488
|
cancellationEpoch++;
|
|
390
489
|
pendingReviewDecision?.abort();
|
|
391
490
|
pendingQa?.abort();
|
|
392
491
|
pendingExecution?.abort();
|
|
393
492
|
pendingDocumentation?.abort();
|
|
394
493
|
const status=boundStatus(runner.cancel(),identity);
|
|
395
|
-
return summary(operation,status,'cancelled');
|
|
494
|
+
return summary(operation,status,status.state==='cancelled'||interrupted?'cancelled':'reported');
|
|
495
|
+
}
|
|
496
|
+
if(operation.operation==='reconcile_review'){
|
|
497
|
+
const result=runner.reconcileReview?.({invocationId:operation.invocationId})
|
|
498
|
+
??{outcome:'rejected',code:'review_reconciliation_unavailable'};
|
|
499
|
+
return result.outcome==='rejected'?summary(operation,{...runner.status(),code:result.code},'rejected')
|
|
500
|
+
:summary(operation,result,'reconciled');
|
|
501
|
+
}
|
|
502
|
+
if(operation.operation==='abandon_review'){
|
|
503
|
+
if(!abandonPermission)return summary(operation,{...runner.status(),
|
|
504
|
+
code:'review_abandon_authorization_required'},'rejected');
|
|
505
|
+
abandonPermission=false;
|
|
506
|
+
const result=runner.abandonReview?.({allowed:true,reason:operation.reason})
|
|
507
|
+
??{outcome:'rejected',code:'review_abandon_unavailable'};
|
|
508
|
+
if(result.outcome==='rejected')return summary(operation,{...runner.status(),code:result.code},'rejected');
|
|
509
|
+
return summary(operation,boundStatus(result,identity),'abandoned');
|
|
510
|
+
}
|
|
511
|
+
if(operation.operation==='abandon_effect'){
|
|
512
|
+
if(!abandonEffectPermission)return summary(operation,{...runner.status(),
|
|
513
|
+
code:'effect_abandon_authorization_required'},'rejected');
|
|
514
|
+
abandonEffectPermission=false;
|
|
515
|
+
const result=runner.abandonEffect?.({allowed:true,reason:operation.reason})
|
|
516
|
+
??{outcome:'rejected',code:'effect_abandon_unavailable'};
|
|
517
|
+
if(result.outcome==='rejected')return summary(operation,{...runner.status(),code:result.code,
|
|
518
|
+
...(result.reason?{reason:result.reason}:{})},'rejected');
|
|
519
|
+
return summary(operation,boundStatus(result,identity),'abandoned');
|
|
520
|
+
}
|
|
521
|
+
if(operation.operation==='bootstrap_review_recover'){
|
|
522
|
+
if(!bootstrapReviewRecoveryPermission)return summary(operation,{...runner.status(),
|
|
523
|
+
code:'bootstrap_review_recovery_authorization_required'},'rejected');
|
|
524
|
+
bootstrapReviewRecoveryPermission=false;
|
|
525
|
+
const result=runner.recoverBootstrapReview?.({allowed:true,reason:operation.reason})
|
|
526
|
+
??{outcome:'rejected',code:'bootstrap_review_recovery_unavailable'};
|
|
527
|
+
if(result.outcome==='rejected')return summary(operation,{...runner.status(),code:result.code,
|
|
528
|
+
...(result.reason?{reason:result.reason}:{})},'rejected');
|
|
529
|
+
return summary(operation,boundStatus(result,identity),'advanced');
|
|
396
530
|
}
|
|
397
531
|
if(operation.operation==='decision'){
|
|
398
532
|
const status=boundStatus(runner.status(),identity);
|
|
399
533
|
need(status.packageDigest===operation.packageDigest,'stale_decision');
|
|
534
|
+
if(status.code==='review_package_changed')return summary(operation,status,'rejected');
|
|
400
535
|
let decision=hostDecision;
|
|
401
536
|
if(hostDecisionProvider!==null){
|
|
402
537
|
// A historical terminal or outstanding invocation is owned by the runner;
|
|
@@ -428,7 +563,8 @@ export function createCmAiConversationEntry(options) {
|
|
|
428
563
|
if(validateHostDecision(decision,status)==='denied')
|
|
429
564
|
return summary(operation,{...status,code:'permission_denied'},'denied');
|
|
430
565
|
const retries=retryReview(status)?status.calls.filter(call=>call.channel==='host-authorized'
|
|
431
|
-
&&
|
|
566
|
+
&&['failed','abandoned'].includes(call.terminal)
|
|
567
|
+
&&call.contextId===status.reviewInvocation.registration.grant.logicalContextId).length:0;
|
|
432
568
|
const effectId=`review-${identity.attempt}${retries?`-retry-${retries}`:''}`;
|
|
433
569
|
const result=await runner.executeEffect({version:1,id:effectId,identity,kind:'review'});
|
|
434
570
|
return effectSummary(operation,result,runner,identity);
|
|
@@ -436,9 +572,13 @@ export function createCmAiConversationEntry(options) {
|
|
|
436
572
|
if(operation.operation==='complete'){
|
|
437
573
|
const status=boundStatus(runner.status(),identity);
|
|
438
574
|
need(status.packageDigest===operation.packageDigest,'stale_completion');
|
|
575
|
+
if(status.code==='review_package_changed')return summary(operation,status,'rejected');
|
|
576
|
+
if(status.code==='completion_package_changed'&&status.retryReady===false)return summary(operation,status,'rejected');
|
|
439
577
|
const correction=correctionSummary(operation,status);if(correction)return correction;
|
|
440
|
-
need(['approved','fixture_completed'].includes(status.state),'completion_not_ready');
|
|
441
|
-
const
|
|
578
|
+
need(['approved','fixture_completed'].includes(status.state)||completionRetryable(status),'completion_not_ready');
|
|
579
|
+
const retries=runner.completionBlocks?.()??0;
|
|
580
|
+
const effectId=`complete-${identity.attempt}${retries?`-retry-${retries}`:''}`;
|
|
581
|
+
const result=await runner.executeEffect({version:1,id:effectId,identity,kind:'complete'});
|
|
442
582
|
return effectSummary(operation,result,runner,identity);
|
|
443
583
|
}
|
|
444
584
|
if(operation.operation==='qa'){
|
|
@@ -446,14 +586,19 @@ export function createCmAiConversationEntry(options) {
|
|
|
446
586
|
need(status.packageDigest===operation.packageDigest,'stale_qa');
|
|
447
587
|
const correction=correctionSummary(operation,status);if(correction)return correction;
|
|
448
588
|
need(status.state==='fixture_completed','qa_not_ready');
|
|
449
|
-
let decision=qaDecision;
|
|
589
|
+
let decision=qaDecision,previousDecisionId=null;
|
|
450
590
|
if(qaProvider!==null){
|
|
451
591
|
need(pendingQa===null,'qa_decision_pending');
|
|
452
592
|
const binding={specsDir:options.specsDir,feature:options.feature,identity,packageDigest:operation.packageDigest};
|
|
453
593
|
decision=findCmAiQaDecision(binding);
|
|
594
|
+
// An older host recorded a missed qa_assess window as this durable
|
|
595
|
+
// block. Only the explicit one-shot rerun authorization asks again; the
|
|
596
|
+
// new decision is appended with a link, the old row stays history.
|
|
597
|
+
if(rerunBlockedQa&&timedOutQaDecision(decision)){previousDecisionId=decision.decisionId;decision=null;}
|
|
454
598
|
// A bound historical decision is evidence, not a fresh proposal. Keep
|
|
455
599
|
// the existing downstream compatibility path; do not rewrite its log.
|
|
456
|
-
if(decision!==null)return summary(operation,{...status,code:`qa_${decision.status}
|
|
600
|
+
if(decision!==null)return summary(operation,{...status,code:`qa_${decision.status}`,
|
|
601
|
+
...(decision.status==='blocked'?{reason:decision.reason}:{})},'recorded');
|
|
457
602
|
if(decision===null){
|
|
458
603
|
const controller=new AbortController();pendingQa=controller;
|
|
459
604
|
let timer,timedOut=false;
|
|
@@ -461,13 +606,14 @@ export function createCmAiConversationEntry(options) {
|
|
|
461
606
|
const interrupted=new Promise((_,reject)=>{
|
|
462
607
|
controller.signal.addEventListener('abort',()=>reject(Object.assign(new Error('QA decision interrupted'),
|
|
463
608
|
{code:timedOut?'qa_decision_timeout':'cancelled'})),{once:true});
|
|
464
|
-
//
|
|
465
|
-
//
|
|
609
|
+
// The request watchdog normally settles first with the same
|
|
610
|
+
// retryable qa_decision_timeout; this is the outer backstop.
|
|
466
611
|
timer=setTimeout(()=>{timedOut=true;controller.abort();},qaTimeout+1000);
|
|
467
612
|
});
|
|
468
613
|
decision=json(await Promise.race([
|
|
469
614
|
Promise.resolve().then(()=>{need(!controller.signal.aborted,'cancelled');
|
|
470
|
-
return decideQa(freeze({...binding,codeProject:options.codeProject
|
|
615
|
+
return decideQa(freeze({...binding,codeProject:options.codeProject,
|
|
616
|
+
...(previousDecisionId===null?{}:{previousDecisionId})}),controller.signal);}),interrupted]));
|
|
471
617
|
need(!controller.signal.aborted,'cancelled');
|
|
472
618
|
const current=boundStatus(runner.status(),identity);
|
|
473
619
|
need(current.state==='fixture_completed'&¤t.code==null&¤t.packageDigest===operation.packageDigest,'stale_qa');
|
|
@@ -488,6 +634,7 @@ export function createCmAiConversationEntry(options) {
|
|
|
488
634
|
const input={specsDir:options.specsDir,codeProject:options.codeProject,feature:options.feature,identity,
|
|
489
635
|
packageDigest:operation.packageDigest,decision};
|
|
490
636
|
if(Object.hasOwn(options,'qaLogHome'))input.logHome=options.qaLogHome;
|
|
637
|
+
if(previousDecisionId!==null)input.previousDecisionId=previousDecisionId;
|
|
491
638
|
recordCmAiQaDecision(input);
|
|
492
639
|
return summary(operation,{...status,code:`qa_${decision.status}`},'recorded');
|
|
493
640
|
}
|
|
@@ -532,6 +679,7 @@ export function createCmAiConversationEntry(options) {
|
|
|
532
679
|
const refresh=inspectCmAiContextRefresh({specsDir:options.specsDir,codeProject:options.codeProject,
|
|
533
680
|
feature:options.feature,applicableAgentFiles});
|
|
534
681
|
need(refresh.state==='complete','run_not_ready');
|
|
682
|
+
const projectQa=projectQaSummary(operation,status,options);if(projectQa)return projectQa;
|
|
535
683
|
const documentationEpoch=cancellationEpoch;
|
|
536
684
|
const documentation=await documentationFor(status,refresh);
|
|
537
685
|
need(documentationEpoch===cancellationEpoch,'cancelled');
|
|
@@ -540,10 +688,11 @@ export function createCmAiConversationEntry(options) {
|
|
|
540
688
|
need(current.state==='fixture_completed'&¤t.code==null&¤t.packageDigest===status.packageDigest,'stale_documentation');
|
|
541
689
|
if(documentation===null)
|
|
542
690
|
return summary(operation,{...status,code:'documentation_sync_required'},'awaiting');
|
|
543
|
-
const result=validateDocumentationResult(documentation,status,refresh);
|
|
544
|
-
if(result==='blocked')return summary(operation,{...status,code:'documentation_sync_blocked'},'blocked')
|
|
691
|
+
const result=validateDocumentationResult(documentation,status,refresh,knowledgeCloseout);
|
|
692
|
+
if(result==='blocked')return freeze({...summary(operation,{...status,code:'documentation_sync_blocked'},'blocked'),
|
|
693
|
+
...closeoutSummary(knowledgeCloseout,documentation)});
|
|
545
694
|
return freeze({...summary(operation,{...status,code:'documentation_synced'},'verified'),
|
|
546
|
-
contextDigest:refresh.contextDigest});
|
|
695
|
+
contextDigest:refresh.contextDigest,...closeoutSummary(knowledgeCloseout,documentation)});
|
|
547
696
|
}
|
|
548
697
|
if(operation.operation==='run_finalize'){
|
|
549
698
|
const status=boundStatus(runner.status(),identity);
|
|
@@ -555,6 +704,7 @@ export function createCmAiConversationEntry(options) {
|
|
|
555
704
|
const refresh=inspectCmAiContextRefresh({specsDir:options.specsDir,codeProject:options.codeProject,
|
|
556
705
|
feature:options.feature,applicableAgentFiles});
|
|
557
706
|
need(refresh.state==='complete','run_not_ready');
|
|
707
|
+
const projectQa=projectQaSummary(operation,status,options);if(projectQa)return projectQa;
|
|
558
708
|
const documentationEpoch=cancellationEpoch;
|
|
559
709
|
const documentation=await documentationFor(status,refresh);need(documentation!==null,'run_not_ready');
|
|
560
710
|
need(documentationEpoch===cancellationEpoch,'cancelled');
|
|
@@ -565,9 +715,11 @@ export function createCmAiConversationEntry(options) {
|
|
|
565
715
|
const finalContext=inspectCmAiContextRefresh({specsDir:options.specsDir,codeProject:options.codeProject,
|
|
566
716
|
feature:options.feature,applicableAgentFiles});
|
|
567
717
|
need(finalContext.state==='complete'&&finalContext.contextDigest===refresh.contextDigest,'stale_documentation');
|
|
568
|
-
const documentationStatus=validateDocumentationResult(documentation,status,refresh);
|
|
718
|
+
const documentationStatus=validateDocumentationResult(documentation,status,refresh,knowledgeCloseout);
|
|
569
719
|
if(documentationStatus==='blocked')
|
|
570
|
-
return summary(operation,{...status,code:'documentation_sync_blocked'},'blocked')
|
|
720
|
+
return freeze({...summary(operation,{...status,code:'documentation_sync_blocked'},'blocked'),
|
|
721
|
+
...closeoutSummary(knowledgeCloseout,documentation)});
|
|
722
|
+
const finalQa=projectQaSummary(operation,status,options);if(finalQa)return finalQa;
|
|
571
723
|
const input={specsDir:options.specsDir,codeProject:options.codeProject,feature:options.feature,identity,
|
|
572
724
|
packageDigest:operation.packageDigest,contextDigest:refresh.contextDigest,
|
|
573
725
|
documentationSyncId:documentation.syncId};
|
|
@@ -576,7 +728,8 @@ export function createCmAiConversationEntry(options) {
|
|
|
576
728
|
return freeze({version:1,workflow:'cm-ai',operation:operation.operation,requestDigest:digest(operation),identity,
|
|
577
729
|
outcome:'finalized',state:'run_done',code:result.degraded?'run_done_degraded':'run_done',
|
|
578
730
|
packageDigest:operation.packageDigest,pendingAction:'none',contextDigest:refresh.contextDigest,
|
|
579
|
-
deduplicated:result.deduplicated,degraded:result.degraded
|
|
731
|
+
deduplicated:result.deduplicated,degraded:result.degraded,
|
|
732
|
+
...closeoutSummary(knowledgeCloseout,documentation)});
|
|
580
733
|
}
|
|
581
734
|
need(['start','resume'].includes(operation.operation),'invalid_input');
|
|
582
735
|
need(matchesCmAiTaskSelection(admission,options.feature,identity.taskId,options.parallelSelection??null),'task_mismatch');
|
|
@@ -589,6 +742,10 @@ export function createCmAiConversationEntry(options) {
|
|
|
589
742
|
// An unapproved next attempt is waiting, not a dispatched effect of unknown outcome.
|
|
590
743
|
if(developable&&Object.hasOwn(options,'developmentAttempt')&&options.developmentAttempt!==identity.attempt)
|
|
591
744
|
return summary(operation,{...status,code:'provider_development_authorization_required'},'awaiting');
|
|
745
|
+
// Transient launch option: the caller has no revision answer yet. Stop after
|
|
746
|
+
// the review that asked for it, before any develop intent, and say so.
|
|
747
|
+
if(options.holdRevision===true&&status.state==='changes_requested')
|
|
748
|
+
return summary(operation,{...status,code:'revision_answer_required'},'awaiting');
|
|
592
749
|
const learningInput=inspectCmAiTaskLearningInput({specsDir:options.specsDir,codeProject:options.codeProject,
|
|
593
750
|
feature:options.feature,identity,applicableAgentFiles:applicableAgentFiles??[]},
|
|
594
751
|
{admission:runner.inspectBootstrapAdmission?.()??null,parallelSelection:options.parallelSelection??null});
|
|
@@ -603,6 +760,23 @@ export function createCmAiConversationEntry(options) {
|
|
|
603
760
|
const result=await runner.executeEffect({version:1,id:effectId,identity,kind:'develop',learningInput});
|
|
604
761
|
return effectSummary(operation,result,runner,identity);
|
|
605
762
|
}
|
|
606
|
-
const handle=async raw=>{
|
|
763
|
+
const handle=async raw=>{
|
|
764
|
+
let token=null,operation=null;const epoch=cancellationEpoch;
|
|
765
|
+
try{
|
|
766
|
+
operation=readOperation(raw);
|
|
767
|
+
if(!['status','cancel','reconcile_review','abandon_review','abandon_effect','bootstrap_review_recover'].includes(operation.operation)){
|
|
768
|
+
token=Symbol(operation.operation);inFlightHandles.add(token);
|
|
769
|
+
}
|
|
770
|
+
const routed=await route(operation);
|
|
771
|
+
const guidance=operatorGuidance(routed,{executionActive:inFlightHandles.size>(token===null?0:1)});
|
|
772
|
+
const result=guidance?freeze({...routed,guidance}):routed;
|
|
773
|
+
if(!admissionReports.has(routed)&&(epoch===cancellationEpoch||operation.operation==='cancel'))projectHostResult({specsDir:options.specsDir,
|
|
774
|
+
feature:options.feature,result,readCurrent:()=>runner.status()});
|
|
775
|
+
return result;
|
|
776
|
+
}catch(error){return freeze({...rejected(ownerIdentity,error),
|
|
777
|
+
...(['finish','run_finalize'].includes(operation?.operation)
|
|
778
|
+
?closeoutSummary(knowledgeCloseout,null,error.code??'inspection_failed'): {})});}
|
|
779
|
+
finally{if(token!==null)inFlightHandles.delete(token);}
|
|
780
|
+
};
|
|
607
781
|
return Object.freeze({handle});
|
|
608
782
|
}
|
|
@@ -38,6 +38,15 @@ function validateHandoff(target,identity) {
|
|
|
38
38
|
&&result.stdout.length<=MiB,'handoff_invalid');
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
// Pure: the handoff bytes once Learning evidence is attached, exactly as written.
|
|
42
|
+
export function taskLearningHandoffBytes({handoff,feature,identity,learningInput,application,retrospective,includeAgents}){
|
|
43
|
+
const applied=attachCmAiTaskLearningApplicationEvidence({handoff,feature,identity,learningInput,application});
|
|
44
|
+
const attached=attachCmAiTaskLearningEvidence({handoff:applied,feature,identity,learningInput,retrospective});
|
|
45
|
+
const changedFiles=arrayItems(attached.changed_files);for(const item of changedFiles)text(item);
|
|
46
|
+
const next={...attached,changed_files:includeAgents&&!changedFiles.includes('AGENTS.md')
|
|
47
|
+
?[...changedFiles,'AGENTS.md']:changedFiles};
|
|
48
|
+
return Buffer.from(`${JSON.stringify(next,null,2)}\n`);
|
|
49
|
+
}
|
|
41
50
|
export function writeCmAiTaskLearningHandoff(raw) {
|
|
42
51
|
const input=json(raw,512*1024);
|
|
43
52
|
shape(input,['handoffPath','feature','identity','learningInput','application','retrospective','writeback']);
|
|
@@ -55,15 +64,8 @@ export function writeCmAiTaskLearningHandoff(raw) {
|
|
|
55
64
|
need(sameSnapshot(before,readHandoff(input.handoffPath)),'handoff_changed');
|
|
56
65
|
let handoff;
|
|
57
66
|
try {handoff=JSON.parse(before.source);}catch{need(false,'handoff_invalid');}
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
const attached=attachCmAiTaskLearningEvidence({handoff:applied,feature:input.feature,identity:input.identity,
|
|
61
|
-
learningInput:input.learningInput,retrospective:input.retrospective});
|
|
62
|
-
const changedFiles=arrayItems(attached.changed_files);for(const item of changedFiles)text(item);
|
|
63
|
-
const includeAgents=writeback.outcome==='written';
|
|
64
|
-
const next={...attached,changed_files:includeAgents&&!changedFiles.includes('AGENTS.md')
|
|
65
|
-
?[...changedFiles,'AGENTS.md']:changedFiles};
|
|
66
|
-
const bytes=Buffer.from(`${JSON.stringify(next,null,2)}\n`);
|
|
67
|
+
const bytes=taskLearningHandoffBytes({handoff,feature:input.feature,identity:input.identity,learningInput:input.learningInput,
|
|
68
|
+
application:input.application,retrospective:input.retrospective,includeAgents:writeback.outcome==='written'});
|
|
67
69
|
need(bytes.length<=LIMIT,'limit_exceeded');
|
|
68
70
|
if(bytes.equals(before.bytes))return freeze({outcome:'unchanged',handoffSha256:before.sha256});
|
|
69
71
|
|