@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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {needPrd} from './validation-reason.mjs';
|
|
2
|
+
|
|
3
|
+
export function assertPrdReviewTimestamp(value){
|
|
4
|
+
needPrd(typeof value==='string'&&Number.isFinite(Date.parse(value))
|
|
5
|
+
&&new Date(value).toISOString()===value,'prd_review_timestamp_invalid',
|
|
6
|
+
{field:'response.at',expected:'new Date().toISOString() form, e.g. 2026-09-08T00:00:00.000Z'});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Recovery only: explicit timezone, exact calendar, no Date.parse rollover.
|
|
10
|
+
// Only exact millisecond instants are recoverable; never truncate precision or use now.
|
|
11
|
+
export function normalizePrdReviewTimestamp(value){
|
|
12
|
+
const match=typeof value==='string'&&value.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?(Z|([+-])(\d{2}):(\d{2}))$/);
|
|
13
|
+
const valid=ok=>needPrd(ok,'prd_review_timestamp_invalid',
|
|
14
|
+
{field:'response.at',expected:'Valid ISO calendar timestamp with explicit Z or +/-HH:mm timezone; 1-9 fractional digits'});
|
|
15
|
+
valid(match);
|
|
16
|
+
valid(match[8]!=='-00:00');
|
|
17
|
+
const [year,month,day,hour,minute,second]=match.slice(1,7).map(Number);
|
|
18
|
+
const offsetHour=Number(match[10]??0),offsetMinute=Number(match[11]??0);
|
|
19
|
+
valid(month>=1&&month<=12&&day>=1&&day<=31&&hour<=23&&minute<=59&&second<=59
|
|
20
|
+
&&offsetHour<=23&&offsetMinute<=59);
|
|
21
|
+
const date=new Date(0);date.setUTCFullYear(year,month-1,day);date.setUTCHours(hour,minute,second,0);
|
|
22
|
+
valid(date.getUTCFullYear()===year&&date.getUTCMonth()===month-1&&date.getUTCDate()===day);
|
|
23
|
+
valid(!(match[7]??'').slice(3).match(/[1-9]/));
|
|
24
|
+
const milliseconds=Number((match[7]??'').padEnd(3,'0').slice(0,3));
|
|
25
|
+
const offset=(offsetHour*60+offsetMinute)*60000*(match[9]==='-'?-1:1);
|
|
26
|
+
const utc=new Date(date.getTime()+milliseconds-offset);
|
|
27
|
+
valid(utc.getUTCFullYear()>=0&&utc.getUTCFullYear()<=9999);
|
|
28
|
+
const canonical=utc.toISOString();assertPrdReviewTimestamp(canonical);return canonical;
|
|
29
|
+
}
|
|
@@ -26,7 +26,8 @@ export function inspectPrdContextCheck(raw,draft){
|
|
|
26
26
|
return json({...report,status:failed?'failed':'host_reported_passed',independentReview:false,completionAuthorized:false});
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
// Examples are not declarations.
|
|
29
|
+
// Examples are not declarations. Task lines go through the shared grammar,
|
|
30
|
+
// which already skips fences; this blanks fenced acceptance examples.
|
|
30
31
|
function outsideFences(source){
|
|
31
32
|
let fence=null;return source.split(/\r?\n/).map(line=>{
|
|
32
33
|
const match=line.match(/^\s*(`{3,}|~{3,})/);
|
|
@@ -42,8 +43,10 @@ export function checkPrdDraftMechanics(draft,{change=false}={}){
|
|
|
42
43
|
const findings=[],features=[];
|
|
43
44
|
for(const feature of draft.features){
|
|
44
45
|
const files=new Map(feature.documents.map(document=>[document.path,document.content]));
|
|
45
|
-
const add=code=>findings.push({feature:feature.directory,code
|
|
46
|
-
|
|
46
|
+
const add=code=>findings.push({feature:feature.directory,code,
|
|
47
|
+
...(code==='dependencies_invalid'?{reason:{field:`${feature.directory}/tasks.md`,
|
|
48
|
+
expected:'One line per task; comma-separated prerequisites, e.g. - T-003 依赖 T-001, T-002'}}:{})});
|
|
49
|
+
const parsed=parseFeatureTaskText(files.get('tasks.md'));
|
|
47
50
|
const acIds=declaredAcceptanceIds(outsideFences(files.get('requirements.md')));
|
|
48
51
|
if(acIds.size===0)add('acceptance_missing');
|
|
49
52
|
let taskIds=new Set();
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// PRD-local checkpoint and call journal. It never owns review/task approval.
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import {randomUUID} from 'node:crypto';
|
|
5
|
-
import {need,json,digest} from '../cm-ai/effect-contract.mjs';
|
|
4
|
+
import {randomUUID,createHash} from 'node:crypto';
|
|
5
|
+
import {need,json,digest,shape} from '../cm-ai/effect-contract.mjs';
|
|
6
|
+
import {readExecutionPolicy} from '../cm-ai/execution-policy.mjs';
|
|
7
|
+
import {recoverPrdResponse,readPrdRepairBinding} from './response-recovery.mjs';
|
|
6
8
|
import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
7
9
|
|
|
8
10
|
export function readPrdSessionFile(root,relative){
|
|
@@ -25,7 +27,7 @@ export function replaceSessionFile(root,relative,before,after){
|
|
|
25
27
|
const d=fs.openSync(dir,'r');try{fs.fsyncSync(d);}finally{fs.closeSync(d);}
|
|
26
28
|
}finally{if(fd!==undefined)fs.closeSync(fd);try{fs.unlinkSync(tmp);}catch(e){if(e.code!=='ENOENT')throw e;}}
|
|
27
29
|
}
|
|
28
|
-
export function openPrdSession({specs,sessionId,identity}){
|
|
30
|
+
export function openPrdSession({specs,sessionId,identity,executionPolicy=null}){
|
|
29
31
|
need(/^prd-[a-zA-Z0-9-]{1,80}$/.test(sessionId),'prd_session_id_invalid');
|
|
30
32
|
for(const relative of ['.reviews','.reviews/prd-sessions',`.reviews/prd-sessions/${sessionId}`]){
|
|
31
33
|
const dir=path.join(specs,relative);try{fs.mkdirSync(dir,{mode:0o700});}catch(e){if(e.code!=='EEXIST')throw e;}
|
|
@@ -41,13 +43,58 @@ export function openPrdSession({specs,sessionId,identity}){
|
|
|
41
43
|
}
|
|
42
44
|
const lockBytes=JSON.stringify({pid:process.pid,nonce:randomUUID()});
|
|
43
45
|
const fd=fs.openSync(lock,'wx',0o600);try{fs.writeFileSync(fd,lockBytes);fs.fsyncSync(fd);}finally{fs.closeSync(fd);}
|
|
44
|
-
let bytes=read(),state=bytes===null?{version:1,identity,checkpoint:null,active:null,segments:{}
|
|
45
|
-
|
|
46
|
+
let bytes=read(),state=bytes===null?{version:executionPolicy===null?1:2,identity,checkpoint:null,active:null,segments:{},
|
|
47
|
+
...(executionPolicy===null?{}:{executionPolicy:readExecutionPolicy(executionPolicy),responseRepairs:[]})}:JSON.parse(bytes);
|
|
48
|
+
try{need([1,2].includes(state.version)&&digest(state.identity)===digest(identity),'prd_session_identity_changed');
|
|
49
|
+
if(state.version===2){readExecutionPolicy(state.executionPolicy);need(Array.isArray(state.responseRepairs),'prd_recovery_binding');}
|
|
50
|
+
else need(executionPolicy===null,'execution_policy_legacy_run');}
|
|
46
51
|
catch(e){fs.unlinkSync(lock);throw e;}
|
|
47
52
|
let cursor=0;
|
|
48
53
|
const save=()=>{const next=JSON.stringify(state);replaceSessionFile(directory,'state.json',bytes,next);bytes=next;};
|
|
54
|
+
const projected=call=>{
|
|
55
|
+
if(!call.responseRepair)return call.result;
|
|
56
|
+
need(state.version===2&&call.kind==='prd_review'&&digest({kind:call.kind,payload:call.payload})===call.requestDigest,'prd_recovery_binding');
|
|
57
|
+
const record=call.responseRepair;
|
|
58
|
+
shape(record,['version','callId','requestDigest','originalDigest','originalBase64','response','changes','reason']);
|
|
59
|
+
need(record.version===1&&record.callId===call.callId&&record.requestDigest===call.requestDigest
|
|
60
|
+
&&record.originalDigest===digest(call.result)&&record.originalBase64===Buffer.from(JSON.stringify(call.result)).toString('base64'),'prd_recovery_binding');
|
|
61
|
+
const {packageDigest,...reviewPackage}=call.payload.package;
|
|
62
|
+
const expected=recoverPrdResponse({original:call.result,reviewPackage,packageDigest,authorContextId:call.payload.authorContextId});
|
|
63
|
+
need(digest(expected.response)===digest(record.response)&&digest(expected.changes)===digest(record.changes),'prd_recovery_binding');
|
|
64
|
+
return expected.response;
|
|
65
|
+
};
|
|
49
66
|
return {
|
|
50
67
|
get state(){return json(state,12*1024*1024);},
|
|
68
|
+
reviewResponse(call){return projected(call);},
|
|
69
|
+
repairReviewResponse(binding){
|
|
70
|
+
need(state.version===2&&state.executionPolicy.responseRecovery==='mechanical-v1','execution_policy_required');
|
|
71
|
+
binding=readPrdRepairBinding(binding);
|
|
72
|
+
const saved=state.responseRepairs.find(item=>item.originalCall.callId===binding.callId);
|
|
73
|
+
if(saved){
|
|
74
|
+
need(saved.originalOperation.operation==='final_review'&&/^[a-f0-9]{64}$/.test(saved.originalStateSha256),'prd_recovery_binding');
|
|
75
|
+
need(saved.originalCall.requestDigest===binding.requestDigest&&digest(saved.originalCall.result)===binding.resultDigest
|
|
76
|
+
&&saved.originalCall.payload.package.packageDigest===binding.packageDigest,'prd_recovery_binding');
|
|
77
|
+
const response=projected({...saved.originalCall,responseRepair:saved.repair});
|
|
78
|
+
need(saved.originalOperation.mode==='self-degraded'?response.reviewer==='self-degraded':response.reviewer!=='self-degraded','prd_review_mode_changed');
|
|
79
|
+
return json(saved.repair);
|
|
80
|
+
}
|
|
81
|
+
const active=state.active,call=active?.calls.find(c=>c.callId===binding.callId);
|
|
82
|
+
need(active?.request.operation==='final_review'&&active.calls.length===1&&call?.kind==='prd_review'
|
|
83
|
+
&&Object.hasOwn(call,'result')&&call.requestDigest===binding.requestDigest
|
|
84
|
+
&&digest(call.result)===binding.resultDigest&&call.payload.package.packageDigest===binding.packageDigest,'prd_recovery_binding');
|
|
85
|
+
if(call.responseRepair){projected(call);return json(call.responseRepair);}
|
|
86
|
+
const {packageDigest,...reviewPackage}=call.payload.package;
|
|
87
|
+
const recovered=recoverPrdResponse({original:call.result,reviewPackage,packageDigest,authorContextId:call.payload.authorContextId});
|
|
88
|
+
need(active.request.mode==='self-degraded'?recovered.response.reviewer==='self-degraded':recovered.response.reviewer!=='self-degraded','prd_review_mode_changed');
|
|
89
|
+
need(recovered.changes.length>0,'prd_response_already_canonical');
|
|
90
|
+
const originalCall=json(call,1024*1024);
|
|
91
|
+
call.responseRepair={version:1,callId:call.callId,requestDigest:call.requestDigest,originalDigest:digest(call.result),
|
|
92
|
+
originalBase64:Buffer.from(JSON.stringify(call.result)).toString('base64'),...recovered,reason:binding.reason};
|
|
93
|
+
need(state.responseRepairs.length<64,'prd_write_limit');
|
|
94
|
+
state.responseRepairs.push({originalCall,originalOperation:active.request,
|
|
95
|
+
originalStateSha256:createHash('sha256').update(bytes).digest('hex'),repair:call.responseRepair});
|
|
96
|
+
save();return json(call.responseRepair);
|
|
97
|
+
},
|
|
51
98
|
begin(request,before){need(state.active===null,'prd_operation_recovery_required');state.active={request,before,calls:[]};cursor=0;save();},
|
|
52
99
|
replay(){need(state.active!==null,'prd_nothing_to_resume');cursor=0;return json(state.active,12*1024*1024);},
|
|
53
100
|
commit(checkpoint){state.checkpoint=checkpoint;state.active=null;save();},
|
|
@@ -69,7 +116,7 @@ export function openPrdSession({specs,sessionId,identity}){
|
|
|
69
116
|
const active=state.active;
|
|
70
117
|
const previous=state.active.calls[index];
|
|
71
118
|
if(previous){need(previous.requestDigest===digest(input),'prd_replay_inputs_changed');
|
|
72
|
-
need(Object.hasOwn(previous,'result'),'prd_host_result_unknown');return previous
|
|
119
|
+
need(Object.hasOwn(previous,'result'),'prd_host_result_unknown');return projected(previous);}
|
|
73
120
|
need(!state.active.calls.some(call=>!Object.hasOwn(call,'result')),'prd_host_result_unknown');
|
|
74
121
|
const call={callId:randomUUID(),requestDigest:digest(input),...input};state.active.calls.push(call);save();
|
|
75
122
|
const response=await perform({...payload,recovery:{sessionId,callId:call.callId,requestDigest:call.requestDigest}},signal);
|
|
@@ -128,7 +128,9 @@ export function publishPrdAwaitingReview({specs,summary,writeEnabled,recover=fal
|
|
|
128
128
|
const prior=readSpecsStatus(specs);
|
|
129
129
|
const status={status:'awaiting_review',summaryDigest:summary.summaryDigest,at:new Date().toISOString(),features:before.features.map(item=>item.directory),
|
|
130
130
|
specFiles:before.specFiles,testCases:before.specFiles.filter(item=>item.path.endsWith('/test-cases.json')),approval:null,
|
|
131
|
-
...(prior.kind==='valid'&&Object.hasOwn(prior.value,'revisionDigest')?{revisionDigest:prior.value.revisionDigest}:{})
|
|
131
|
+
...(prior.kind==='valid'&&Object.hasOwn(prior.value,'revisionDigest')?{revisionDigest:prior.value.revisionDigest}:{}),
|
|
132
|
+
// A first publication has no earlier approval to reinterpret: bind grammar 2.
|
|
133
|
+
...(prior.kind==='missing'||prior.kind==='valid'&&prior.value.taskGrammar===2?{taskGrammar:2}:{})};
|
|
132
134
|
const bytes=Buffer.from(JSON.stringify(status)+'\n'),target=path.join(specs,'.cm-specs-status');
|
|
133
135
|
try{
|
|
134
136
|
writeSpecsStatus(specs,status,{beforeRename:()=>{
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Add operator guidance to existing fail-closed codes without changing the gate.
|
|
2
|
+
import {need,json} from '../cm-ai/effect-contract.mjs';
|
|
3
|
+
import {tagDiagnosticReason} from '../cm-ai/diagnostic-reason.mjs';
|
|
4
|
+
|
|
5
|
+
export function needPrd(ok,code,reason){
|
|
6
|
+
try{need(ok,code);}catch(error){throw tagDiagnosticReason(error,reason);}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function prdDraftJson(raw){
|
|
10
|
+
try{return json(raw,64*1024);}catch(error){
|
|
11
|
+
if(error.code==='limit_exceeded'){
|
|
12
|
+
// The input is a parsed host reply. Do not include its contents in diagnostics.
|
|
13
|
+
let actualBytes=null;
|
|
14
|
+
try{actualBytes=Buffer.byteLength(JSON.stringify(raw));}catch{/* original error wins */}
|
|
15
|
+
tagDiagnosticReason(error,{field:'draft',expected:'one submission must be <= 65536 bytes (64 KiB)',
|
|
16
|
+
limitBytes:65536,actualBytes});
|
|
17
|
+
}
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -127,6 +127,37 @@ function validateReview(review,scan){
|
|
|
127
127
|
return {version:1,scanDigest:review.scanDigest,paths};
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
// Presentation is derived from validated metadata, never raw scanner messages.
|
|
131
|
+
function checkSummary(tools){
|
|
132
|
+
const names={gitleaks:'凭证泄露检查',semgrep:'本地规则代码检查',osv:'离线依赖漏洞检查'};
|
|
133
|
+
const details={
|
|
134
|
+
no_scannable_files:['所选范围没有可扫描文件。','核对所选范围与文件缺口;没有可扫描文件不代表安全检查通过。'],
|
|
135
|
+
tool_missing:['项目外可信工具不可用,检查未运行。','由用户确认项目外可信工具可用后,在同一范围重新检查。'],
|
|
136
|
+
local_rules_required:['未指定已审查的外部本地规则,检查未运行。','准备已审查的外部本地规则文件,并用 --semgrep-rules 显式指定后重跑。'],
|
|
137
|
+
no_supported_lockfile_selected:['所选范围没有支持的依赖锁文件,检查未运行。','确认依赖锁文件是否在所选范围内;无锁文件不能推断无依赖漏洞。'],
|
|
138
|
+
offline_database_required:['未提供外部离线数据库缓存目录,检查未运行。','由用户准备外部离线数据库缓存,并用 --osv-db 显式指定后重跑。'],
|
|
139
|
+
timeout:['检查已尝试,但超时,未得到完整结果。','排查本地工具耗时与执行条件,再在原范围重跑;保留本次超时记录。'],
|
|
140
|
+
execution_failed:['检查已尝试,但执行失败,未得到完整结果。','核对本地工具版本与执行条件,处理失败原因后重跑。'],
|
|
141
|
+
invalid_or_incomplete_report:['检查已尝试,但输出无法验证或不完整。','核对本地工具兼容性和输出完整性,取得可验证结果后重跑。'],
|
|
142
|
+
unscanned_files:['工具已执行,但部分文件未扫描。','核对工具的 unscanned 路径,补齐对应语言或规则覆盖,或逐项人工复核。'],
|
|
143
|
+
offline_database_freshness_and_ecosystem_coverage_unverified:['离线扫描已执行;数据库新旧仍未知,生态覆盖未核验。','人工核验离线数据库新旧和生态覆盖;未核验前保留该缺口,不自动下载数据库。'],
|
|
144
|
+
};
|
|
145
|
+
const attempted=[],notRun=[],nextSteps=[];
|
|
146
|
+
for(const row of tools){
|
|
147
|
+
const execution=row.status==='NOT_RUN'?'未运行':row.status==='ERROR'?'已尝试,未完成':'已完成';
|
|
148
|
+
const fallback=row.status==='NOT_RUN'?['检查未运行,具体原因未记录。','核对该工具的配置和执行条件后重跑。']
|
|
149
|
+
:row.status==='ERROR'?['检查已尝试但未完成,具体原因未记录。','核对该工具的执行条件,取得完整结果后重跑。']
|
|
150
|
+
:row.status==='FINDINGS'?['本轮检查已完成,发现候选问题。','结合相关代码逐项复核候选问题。']
|
|
151
|
+
:['本轮检查已完成,未报告候选问题。',null];
|
|
152
|
+
const [description,action]=details[row.reason]??fallback;
|
|
153
|
+
const item={tool:row.tool,check:names[row.tool],status:row.status,execution,
|
|
154
|
+
version:row.version??'unknown',reason:row.reason,description};
|
|
155
|
+
(row.status==='NOT_RUN'?notRun:attempted).push(item);
|
|
156
|
+
if(action)nextSteps.push({tool:row.tool,action});
|
|
157
|
+
}
|
|
158
|
+
return {attempted,notRun,nextSteps};
|
|
159
|
+
}
|
|
160
|
+
|
|
130
161
|
export function finalize(project,{scanFile,reviewFile}={}){
|
|
131
162
|
project=fs.realpathSync(project);
|
|
132
163
|
const scan=validateScan(readExternal(project,scanFile));
|
|
@@ -152,6 +183,7 @@ export function finalize(project,{scanFile,reviewFile}={}){
|
|
|
152
183
|
const result=scan.result==='BLOCKED'||!unchanged?'BLOCKED':findingsCount?'FINDINGS':!scan.selected.length?'NO_CHANGES':'REVIEWED_PARTIAL';
|
|
153
184
|
const sourceUnchanged=scan.sourceUnchanged&&unchanged;
|
|
154
185
|
const report={...scan,review,gaps,coverage,result,aiReview:'completed',findingsCount,sourceUnchanged,
|
|
186
|
+
checkSummary:checkSummary(scan.tools),
|
|
155
187
|
sourceWindows:{scan:{sourceUnchanged:scan.sourceUnchanged},review:{sourceUnchanged:unchanged,digest:current.digest}}};
|
|
156
188
|
// Resolve/check TMPDIR before creating anything: the output must remain external.
|
|
157
189
|
const tempRoot=fs.realpathSync(os.tmpdir());need(!inside(project,tempRoot),'external_temp_directory_required');
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// The one tasks.md declaration grammar. Admission, the cm-prd checks, N5
|
|
2
|
+
// mark-done and the approval manifest's runtime-mark normalization all read
|
|
3
|
+
// task lines through this file, so a task one of them accepts is a task for all.
|
|
4
|
+
//
|
|
5
|
+
// A declaration is a list item with a checkbox at any indentation, an optional
|
|
6
|
+
// `~~` strike, a T-id and then an ASCII colon, a full-width colon or whitespace:
|
|
7
|
+
// - [ ] T-003: 描述 - [x] T-003 描述 - [ ] T-003:描述 ····- [ ] T-003 - 描述
|
|
8
|
+
// The full-width colon is accepted rather than rejected: Chinese input methods
|
|
9
|
+
// produce it, cm-failover already accepted it, and rejecting it would force a
|
|
10
|
+
// spec revision for punctuation alone. Lines inside ``` / ~~~ fences (the
|
|
11
|
+
// manifest's original fence rule) are examples, never declarations.
|
|
12
|
+
//
|
|
13
|
+
// The grammar is versioned by the approval that bound the bytes: approvals
|
|
14
|
+
// written by this version record taskGrammar 2 in .cm-specs-status. Approvals
|
|
15
|
+
// recorded earlier keep the exact pre-grammar parse (grammar 1) so an existing
|
|
16
|
+
// approved tasks.md never changes meaning, e.g. an unfenced `- [ ] T-001:例`
|
|
17
|
+
// beside the real `- [ ] T-001:` stays prose instead of becoming a duplicate.
|
|
18
|
+
// cm-prd drafts and new approvals always use grammar 2.
|
|
19
|
+
import fs from 'node:fs';
|
|
20
|
+
import path from 'node:path';
|
|
21
|
+
export const TASK_GRAMMAR=2;
|
|
22
|
+
export const LEGACY_TASK_GRAMMAR=1;
|
|
23
|
+
const LEGACY_DECLARATION=/^((\s*-\s*)\[([ xX])\]\s+(?:~~)?(T-[A-Za-z0-9][A-Za-z0-9._-]*))(?=[:\s])[:\s]*(.*)$/;
|
|
24
|
+
const DECLARATION=/^(\s*-\s*)\[([ xX])\]\s+(?:~~)?(T-[A-Za-z0-9][A-Za-z0-9._-]*)(?=[::\s])/u;
|
|
25
|
+
const FENCE=/^[ ]{0,3}(`{3,}|~{3,})/;
|
|
26
|
+
|
|
27
|
+
export function matchTaskDeclaration(line){
|
|
28
|
+
const match=DECLARATION.exec(line);
|
|
29
|
+
if(!match)return null;
|
|
30
|
+
return {id:match[3],completed:match[2]!==' ',markOffset:match[1].length+1,
|
|
31
|
+
rest:line.slice(match[0].length)};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Physical lines (\r\n, \r or \n) with their character offsets. Fenced lines are
|
|
35
|
+
// reported but flagged, so callers keep exact line numbers for diagnostics.
|
|
36
|
+
export function specLines(text){
|
|
37
|
+
const lines=[],parts=text.split(/(\r\n|\r|\n)/);let fence=null,width=0,start=0;
|
|
38
|
+
for(let index=0;index*2<parts.length;index++){
|
|
39
|
+
const body=parts[index*2],opener=FENCE.exec(body);let fenced=true;
|
|
40
|
+
if(fence!==null){
|
|
41
|
+
if(opener&&opener[1][0]===fence&&opener[1].length>=width&&/^[\t\n\v\f\r ]*$/.test(body.slice(opener[0].length))){fence=null;width=0;}
|
|
42
|
+
}else if(opener){fence=opener[1][0];width=opener[1].length;}
|
|
43
|
+
else fenced=false;
|
|
44
|
+
lines.push({index,start,body,fenced});
|
|
45
|
+
start+=body.length+(parts[index*2+1]??'').length;
|
|
46
|
+
}
|
|
47
|
+
return lines;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Lines of tasks.md with their declaration (or null) under the given grammar.
|
|
51
|
+
// `description` is the text after the id with the grammar's own separator stripped.
|
|
52
|
+
export function taskLines(text,{grammar=TASK_GRAMMAR}={}){
|
|
53
|
+
if(grammar===TASK_GRAMMAR)return specLines(text).map(line=>{
|
|
54
|
+
const declaration=line.fenced?null:matchTaskDeclaration(line.body);
|
|
55
|
+
return {...line,declaration:declaration&&{...declaration,description:declaration.rest.replace(/^[::\s]+/u,'')}};
|
|
56
|
+
});
|
|
57
|
+
if(grammar!==LEGACY_TASK_GRAMMAR)throw Object.assign(new Error('task_grammar_invalid'),{code:'task_grammar_invalid'});
|
|
58
|
+
// Exactly the pre-grammar admission parser: \r?\n lines, no fence handling.
|
|
59
|
+
const lines=[],parts=text.split(/(\r?\n)/);let start=0;
|
|
60
|
+
for(let index=0;index*2<parts.length;index++){
|
|
61
|
+
const body=parts[index*2],match=LEGACY_DECLARATION.exec(body);
|
|
62
|
+
lines.push({index,start,body,fenced:false,declaration:match&&{id:match[4],completed:match[3]!==' ',
|
|
63
|
+
markOffset:match[2].length+1,rest:body.slice(match[1].length),description:match[5]}});
|
|
64
|
+
start+=body.length+(parts[index*2+1]??'').length;
|
|
65
|
+
}
|
|
66
|
+
return lines;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function taskDeclarations(text,{grammar=TASK_GRAMMAR}={}){
|
|
70
|
+
return taskLines(text,{grammar}).flatMap(line=>line.declaration?[{...line,...line.declaration}]:[]);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// The grammar the current approval bound; anything but an approval written with
|
|
74
|
+
// taskGrammar 2 (older approvals, awaiting review, missing or unreadable status)
|
|
75
|
+
// is read with the pre-grammar parser, which is what approved those bytes.
|
|
76
|
+
export function approvedTaskGrammar(specsDir){
|
|
77
|
+
try{
|
|
78
|
+
const status=JSON.parse(fs.readFileSync(path.join(specsDir,'.cm-specs-status'),'utf8'));
|
|
79
|
+
return status?.status==='approved'&&status.taskGrammar===TASK_GRAMMAR?TASK_GRAMMAR:LEGACY_TASK_GRAMMAR;
|
|
80
|
+
}catch{return LEGACY_TASK_GRAMMAR;}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Runtime completion marks are the only task-line bytes that change after approval.
|
|
84
|
+
export function resetTaskMarks(text){
|
|
85
|
+
let result='',cursor=0;
|
|
86
|
+
for(const item of taskDeclarations(text)){
|
|
87
|
+
if(!item.completed)continue;
|
|
88
|
+
const offset=item.start+item.markOffset;
|
|
89
|
+
result+=text.slice(cursor,offset)+' ';cursor=offset+1;
|
|
90
|
+
}
|
|
91
|
+
return result+text.slice(cursor);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Byte-level twin of resetTaskMarks for approval digests. Invalid UTF-8 stays
|
|
95
|
+
// byte-exact: each line is decoded only to find the ASCII checkbox position.
|
|
96
|
+
export function resetTaskMarkBytes(bytes){
|
|
97
|
+
const out=Buffer.from(bytes),decoder=new TextDecoder('utf-8',{ignoreBOM:true});
|
|
98
|
+
let fence=null,width=0;
|
|
99
|
+
for(let start=0;start<bytes.length;){
|
|
100
|
+
let end=start;while(end<bytes.length&&bytes[end]!==0x0a&&bytes[end]!==0x0d)end++;
|
|
101
|
+
const line=decoder.decode(bytes.subarray(start,end));
|
|
102
|
+
const opener=FENCE.exec(line);
|
|
103
|
+
if(fence!==null){
|
|
104
|
+
if(opener&&opener[1][0]===fence&&opener[1].length>=width&&/^[\t\n\v\f\r ]*$/.test(line.slice(opener[0].length))){fence=null;width=0;}
|
|
105
|
+
}else if(opener){fence=opener[1][0];width=opener[1].length;}
|
|
106
|
+
else{
|
|
107
|
+
const declaration=matchTaskDeclaration(line);
|
|
108
|
+
if(declaration?.completed){
|
|
109
|
+
const offset=start+Buffer.byteLength(line.slice(0,declaration.markOffset));
|
|
110
|
+
if(out[offset-1]!==0x5b||(out[offset]|0x20)!==0x78)throw new Error('task checkbox byte offset mismatch');
|
|
111
|
+
out[offset]=0x20;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
start=end+(bytes[end]===0x0d&&bytes[end+1]===0x0a?2:1);
|
|
115
|
+
}
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
@@ -3,7 +3,7 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import {randomUUID} from 'node:crypto';
|
|
5
5
|
|
|
6
|
-
const fields=['status','summaryDigest','at','features','specFiles','testCases','approval','revisionDigest'];
|
|
6
|
+
const fields=['status','summaryDigest','at','features','specFiles','testCases','approval','revisionDigest','taskGrammar'];
|
|
7
7
|
const record=value=>value!==null&&typeof value==='object'&&!Array.isArray(value);
|
|
8
8
|
const hex=value=>typeof value==='string'&&/^[a-fA-F0-9]{64}$/.test(value);
|
|
9
9
|
const revisionHex=value=>typeof value==='string'&&/^[a-f0-9]{64}$/.test(value);
|
|
@@ -35,6 +35,9 @@ export function writeSpecsStatus(specsDir,value,{beforeRename=()=>{}}={}){
|
|
|
35
35
|
const summaryDigest=value.summaryDigest===undefined?null:value.summaryDigest;
|
|
36
36
|
need(summaryDigest===null||hex(summaryDigest));
|
|
37
37
|
if(Object.hasOwn(value,'revisionDigest'))need(revisionHex(value.revisionDigest));
|
|
38
|
+
// The grammar the last approval bound (spec-task-line.mjs). An awaiting_review
|
|
39
|
+
// status only carries it forward; parsing honours it only once approved.
|
|
40
|
+
if(Object.hasOwn(value,'taskGrammar'))need(value.taskGrammar===2);
|
|
38
41
|
need(iso(value.at)&&Array.isArray(value.features)&&value.features.length>0
|
|
39
42
|
&&value.features.every(name=>typeof name==='string'&&/^\d+\.[^/\\]+$/.test(name))
|
|
40
43
|
&&new Set(value.features).size===value.features.length);
|
|
@@ -53,14 +56,18 @@ export function writeSpecsStatus(specsDir,value,{beforeRename=()=>{}}={}){
|
|
|
53
56
|
const canonical={status:value.status,summaryDigest,at:value.at,features:[...value.features],
|
|
54
57
|
specFiles:manifest(value.specFiles),testCases:manifest(value.testCases),
|
|
55
58
|
approval:approval===null?null:{response:approval.response,at:approval.at},
|
|
56
|
-
...(Object.hasOwn(value,'revisionDigest')?{revisionDigest:value.revisionDigest}:{})
|
|
59
|
+
...(Object.hasOwn(value,'revisionDigest')?{revisionDigest:value.revisionDigest}:{}),
|
|
60
|
+
...(Object.hasOwn(value,'taskGrammar')?{taskGrammar:value.taskGrammar}:{})};
|
|
57
61
|
const bytes=Buffer.from(JSON.stringify(canonical)+'\n'),target=path.join(specsDir,'.cm-specs-status');
|
|
58
62
|
const temporary=path.join(specsDir,`.cm-specs-status-${randomUUID()}`);let fd;
|
|
59
63
|
try{
|
|
60
64
|
fd=fs.openSync(temporary,'wx',0o600);fs.writeFileSync(fd,bytes);fs.fsyncSync(fd);fs.closeSync(fd);fd=undefined;
|
|
61
65
|
beforeRename();
|
|
62
66
|
fs.renameSync(temporary,target);
|
|
63
|
-
|
|
67
|
+
// Windows does not support fsync on directory handles. The file was synced above.
|
|
68
|
+
if(process.platform!=='win32'){
|
|
69
|
+
const dir=fs.openSync(specsDir,'r');try{fs.fsyncSync(dir);}finally{fs.closeSync(dir);}
|
|
70
|
+
}
|
|
64
71
|
need(fs.readFileSync(target).equals(bytes));
|
|
65
72
|
return canonical;
|
|
66
73
|
}finally{
|
package/runtime/review.md
CHANGED
|
@@ -105,6 +105,11 @@ PRD artifact 回执先比对原始字节,仅 Markdown 中 `tasks.md` 的任务
|
|
|
105
105
|
proceed only when the reviewer records `approved` and the disagreement is
|
|
106
106
|
preserved in `LESSONS.md`.
|
|
107
107
|
|
|
108
|
+
A concrete human-approved local correction after blocked round two may use the
|
|
109
|
+
one-shot task-gate entrance in `docs/human-correction.md`. It preserves the original
|
|
110
|
+
reports, seals a fresh independent correction review, and does not reopen a host
|
|
111
|
+
journal or reset ordinary attempts. Without explicit human authorization, stop.
|
|
112
|
+
|
|
108
113
|
At any stage, changing reviewed code, tests, or execution instructions invalidates
|
|
109
114
|
approval for the changed content. N5 may record improvement suggestions, not make
|
|
110
115
|
new implementation changes while writing lessons. After mark-done, preserve the
|
package/runtime/task-gates.md
CHANGED
|
@@ -84,6 +84,12 @@ entry and the body must contain findings or an explicit zero-findings result.
|
|
|
84
84
|
implementation files. Round 2 cannot create attempt 3: another blocking result
|
|
85
85
|
becomes `blocked` and requires human resolution under `runtime/review.md`.
|
|
86
86
|
|
|
87
|
+
For an explicitly human-authorized correction after round-two blocked, see
|
|
88
|
+
`docs/human-correction.md`: `prepare-human-correction` and
|
|
89
|
+
`publish-human-correction-review` keep the original four records and bind a separate
|
|
90
|
+
one-shot correction. N4/N5 and locked completion accept its fixed `--correction`
|
|
91
|
+
record; legacy-unbound flags do not weaken correction checks.
|
|
92
|
+
|
|
87
93
|
N5 must let the JavaScript gate validate and update the exact task checkbox while
|
|
88
94
|
the compatibility entry holds the existing platform ownership lock:
|
|
89
95
|
|
|
@@ -30,7 +30,7 @@ CM 支持一个可选的项目根配置文件:`.cm-workflow.yml`、`.cm-workfl
|
|
|
30
30
|
## 运行时声明
|
|
31
31
|
|
|
32
32
|
`runtimes.available` 记录用户自报的可用运行时:`codex`、`claude` 或 `both`。缺省为
|
|
33
|
-
`unknown
|
|
33
|
+
`unknown`(两级均未声明,不做交叉检查)。安装器可选写用户默认,`cm-init` 优先继承且不再询问;`cm-runtime` 默认查看并保留,主动选择后才修改。
|
|
34
34
|
|
|
35
35
|
| 预设 | `runtimes.available` | `roles.coder.adapter` | `roles.reviewer.adapter` |
|
|
36
36
|
| --- | --- | --- | --- |
|
|
@@ -150,6 +150,15 @@ preset: codex-codes
|
|
|
150
150
|
|
|
151
151
|
`cm-runtime show [--project PATH]` 只读;`set <preset> [--project PATH]` 原子改项目;
|
|
152
152
|
`set --user <preset>` 改用户默认;`unset --user` 删除用户默认但不删除项目声明。
|
|
153
|
+
无参数先显示有效配置、来源与模型,默认保留;高级模型入口只提供说明和现有校验方法。
|
|
154
|
+
终端/会话向导和安装器的最终确认均为 `[y/N]`,回车不写;无效配置保留并报告错误。
|
|
155
|
+
`preview <preset> [--project PATH | --user] [--json]` 只读生成候选,复用同一合并和校验逻辑,
|
|
156
|
+
展示范围、目标、字段前后值、项目覆盖和保留模型。`set ... --expect-preview <preview_sha256>`
|
|
157
|
+
核对项目、范围、预设、候选内容及相关输入快照;漂移后必须重新预览确认。两次调用保持相同
|
|
158
|
+
工作目录、语言和运行时环境。用户范围在代码项目目录执行,以核对该项目;不扫描所有项目。
|
|
159
|
+
摘要是配置一致性检查,不是授权凭证;原有显式 `set` 仍按原合同执行。
|
|
160
|
+
模型别名保留不表示更换适配器后仍可用;结构校验不证明 provider 兼容、调用成功或配额。
|
|
161
|
+
`unset --user` 不是通用重置,项目声明仍优先;高级入口不提供任意模型编辑器。
|
|
153
162
|
新建项目配置使用模板,已有配置只改五个字段,其余原文保留。已创建的 run 绑定原配置,切换不改 run。
|
|
154
163
|
`set` 通过 cm-log-event.mjs 的 Python 锁适配器写独立的 `decision/route` 全局日志,
|
|
155
164
|
仅附 preset、source、项目路径;没有 specs 指针或业务任务状态写入。日志失败明确报告配置已保存。
|