@aibyzero/cm-workflow 0.16.2 → 0.16.4
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 +4 -0
- package/CHANGELOG.md +147 -0
- package/README.md +44 -3
- package/VERSION +1 -1
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +46 -7
- package/docs/next-steps.md +100 -0
- package/docs/untested-branches.md +24 -18
- package/package.json +1 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +18 -0
- package/runtime/js/cm-ai/claude-tool-preview.mjs +45 -6
- package/runtime/js/cm-ai/cm-ai-admission.mjs +7 -1
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +22 -12
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +70 -5
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +5 -5
- package/runtime/js/cm-ai/drive-core.mjs +68 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +42 -9
- package/runtime/js/cm-ai/effect-contract.mjs +4 -3
- package/runtime/js/cm-ai/execution-snapshot.mjs +40 -0
- package/runtime/js/cm-ai/host-conversation-execution.mjs +8 -5
- package/runtime/js/cm-ai/host-handoff.mjs +9 -14
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +12 -7
- package/runtime/js/cm-ai/host-session.mjs +10 -3
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/qa-config-revision.mjs +85 -0
- package/runtime/js/cm-ai/review-evidence-file.mjs +18 -1
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +144 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +34 -0
- package/runtime/js/cm-ai/task-runner.mjs +41 -8
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-fix/cause-invocation.mjs +9 -5
- package/runtime/js/cm-fix/cause-package.mjs +21 -0
- package/runtime/js/cm-fix/dossier.mjs +40 -1
- package/runtime/js/cm-fix/execution.mjs +360 -83
- package/runtime/js/cm-fix/host.mjs +7 -3
- package/runtime/js/cm-fix/layout.mjs +14 -6
- package/runtime/js/cm-fix/progress.mjs +14 -0
- package/runtime/js/cm-fix/protected-edits.mjs +1 -1
- package/runtime/js/cm-fix/red-test.mjs +7 -6
- package/runtime/js/cm-fix/regression-evidence.mjs +6 -3
- package/runtime/js/cm-fix/regression.mjs +16 -10
- package/runtime/js/cm-fix/repair.mjs +16 -13
- package/runtime/js/cm-fix/test-author.mjs +2 -1
- package/runtime/js/cm-fix/test-extension.mjs +45 -0
- package/runtime/js/cm-prd/accepted-design.mjs +28 -9
- package/runtime/js/cm-prd/analysis.mjs +68 -16
- package/runtime/js/cm-prd/change.mjs +21 -1
- package/runtime/js/cm-prd/draft-save.mjs +96 -2
- package/runtime/js/cm-prd/failed-correction.mjs +51 -0
- package/runtime/js/cm-prd/inputs-replaced.mjs +122 -0
- package/runtime/js/cm-prd/review-correction.mjs +3 -0
- package/runtime/js/cm-prd/review-disposition.mjs +33 -15
- package/runtime/js/cm-prd/review-findings.mjs +2 -2
- package/runtime/js/cm-prd/review-host.mjs +2 -0
- package/runtime/js/cm-prd/review-preparation.mjs +28 -1
- package/runtime/js/cm-prd/review-publication.mjs +4 -2
- package/runtime/js/cm-prd/self-check-revision.mjs +81 -0
- package/runtime/js/cm-prd/session.mjs +5 -5
- package/runtime/js/cm-prd/split-design.mjs +67 -0
- package/runtime/js/cm-prd/summary.mjs +57 -10
- package/runtime/js/cm-refactor/workflow.mjs +100 -19
- package/runtime/js/specs-status.mjs +6 -2
- package/scripts/cm-ai-admission.mjs +2 -0
- package/scripts/cm-ai-batch-drive.mjs +251 -0
- package/scripts/cm-ai-batch-drive.test.mjs +159 -0
- package/scripts/cm-ai-batch-host.mjs +13 -5
- package/scripts/cm-ai-batch-host.test.mjs +25 -0
- package/scripts/cm-ai-contracts.test.mjs +30 -0
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +62 -0
- package/scripts/cm-ai-drive.mjs +335 -0
- package/scripts/cm-ai-drive.test.mjs +258 -0
- package/scripts/cm-ai-fix-integration.test.mjs +1 -1
- package/scripts/cm-ai-host.mjs +48 -20
- package/scripts/cm-ai-host.test.mjs +79 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +328 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +255 -0
- package/scripts/cm-ai-qa-fix-policy.test.mjs +79 -0
- package/scripts/cm-ai-review-timeout.test.mjs +30 -0
- package/scripts/cm-ai-run.mjs +59 -11
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +29 -0
- package/scripts/cm-ai-session-chain.test.mjs +261 -0
- package/scripts/cm-ai-supersede.test.mjs +320 -0
- package/scripts/cm-check-drive.mjs +94 -0
- package/scripts/cm-check-drive.test.mjs +78 -0
- package/scripts/cm-check-entry.mjs +13 -2
- package/scripts/cm-check-host.mjs +2 -2
- package/scripts/cm-check-host.test.mjs +103 -0
- package/scripts/cm-check-runtime.sh +15 -6
- package/scripts/cm-claude-developer-worker.test.mjs +40 -1
- package/scripts/cm-claude-probe.test.mjs +117 -2
- package/scripts/cm-claude-review-stream.test.mjs +43 -0
- package/scripts/cm-fix-abandon.test.mjs +383 -0
- package/scripts/cm-fix-cause-package.test.mjs +31 -1
- package/scripts/cm-fix-cross-session-host.test.mjs +17 -5
- package/scripts/cm-fix-drive.mjs +168 -0
- package/scripts/cm-fix-drive.test.mjs +117 -0
- package/scripts/cm-fix-escalation.test.mjs +214 -0
- package/scripts/cm-fix-execution.test.mjs +26 -0
- package/scripts/cm-fix-host.mjs +4 -2
- package/scripts/cm-fix-observation-dossier.test.mjs +34 -9
- package/scripts/cm-fix-qa-source.test.mjs +3 -3
- package/scripts/cm-fix-session-chain.test.mjs +244 -0
- package/scripts/cm-fix-test-extension.test.mjs +246 -0
- package/scripts/cm-fix-visual-carrier.test.mjs +66 -0
- package/scripts/cm-host-handoff.test.mjs +37 -0
- package/scripts/cm-idea-drive.mjs +99 -0
- package/scripts/cm-idea-drive.test.mjs +50 -0
- package/scripts/cm-init-drive.mjs +191 -0
- package/scripts/cm-init-drive.test.mjs +59 -0
- package/scripts/cm-log-event.mjs +9 -0
- package/scripts/cm-prd-completion.test.mjs +30 -2
- package/scripts/cm-prd-design-phase.test.mjs +355 -15
- package/scripts/cm-prd-drive.mjs +314 -0
- package/scripts/cm-prd-drive.test.mjs +164 -0
- package/scripts/cm-prd-host.mjs +46 -17
- package/scripts/cm-prd-inputs-replaced.test.mjs +237 -0
- package/scripts/cm-prd-review-disposition.test.mjs +133 -7
- package/scripts/cm-prd-review-gate.mjs +23 -4
- package/scripts/cm-prd-self-check-revision.test.mjs +302 -0
- package/scripts/cm-prd-summary.test.mjs +79 -4
- package/scripts/cm-refactor-drive.mjs +237 -0
- package/scripts/cm-refactor-drive.test.mjs +77 -0
- package/scripts/cm-refactor-gaps.test.mjs +276 -0
- package/scripts/cm-refactor-host.test.mjs +1 -48
- package/scripts/cm-refactor-judge-revision.test.mjs +253 -0
- package/scripts/cm-specs-status.test.mjs +19 -0
- package/scripts/cm-test-drive.mjs +132 -0
- package/scripts/cm-test-drive.test.mjs +91 -0
- package/scripts/cm-test-session.test.mjs +117 -0
- package/scripts/correction-check.test.mjs +38 -0
- package/scripts/fixtures/claude-model-marker.mjs +6 -0
- package/scripts/fixtures/claude-review-process.mjs +7 -0
- package/scripts/fixtures/cm-refactor.mjs +56 -0
- package/scripts/test-shell-compat.sh +67 -0
- package/skills/cm-ai/SKILL.md +1 -1
- package/skills/cm-ai/references/N4-review.md +2 -0
- package/skills/cm-ai/references/N8-finish.md +1 -0
- package/skills/cm-ai/references/js-host.md +85 -3
- package/skills/cm-check/SKILL.md +6 -1
- package/skills/cm-check/references/js-host.md +4 -2
- package/skills/cm-fix/SKILL.md +11 -4
- package/skills/cm-fix/references/js-host.md +67 -2
- package/skills/cm-fix/references/test-extension.md +57 -0
- package/skills/cm-idea/references/js-host.md +2 -0
- package/skills/cm-init/references/js-host.md +2 -0
- package/skills/cm-prd/SKILL.md +8 -8
- package/skills/cm-prd/references/js-change-recovery.md +71 -0
- package/skills/cm-prd/references/js-host.md +64 -2
- package/skills/cm-prd/references/spec-self-check.md +14 -2
- package/skills/cm-refactor/SKILL.md +5 -0
- package/skills/cm-refactor/references/js-batch.md +3 -1
- package/skills/cm-refactor/references/js-host.md +49 -0
- package/skills/cm-test/references/js-host.md +5 -0
- package/skills/cm-test/references/unit-coverage.md +2 -2
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Strict V3 payload grammar, shared by live authorization and journal replay.
|
|
2
|
+
import {need,shape,id,hex,json} from './effect-contract.mjs';
|
|
3
|
+
|
|
4
|
+
export function readEvidenceSupersession(raw,expected=null){
|
|
5
|
+
const record=json(raw,1024*1024);
|
|
6
|
+
shape(record,['version','feature','taskId','newRunId','previousRunIds','reason','files','authorizedAt']);
|
|
7
|
+
need(record.version===1,'supersede_record_invalid');
|
|
8
|
+
need(typeof record.authorizedAt==='string'
|
|
9
|
+
&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(record.authorizedAt)
|
|
10
|
+
&&!Number.isNaN(Date.parse(record.authorizedAt)),'supersede_record_invalid');
|
|
11
|
+
for(const key of ['feature','taskId','newRunId'])id(record[key]);
|
|
12
|
+
need(Array.isArray(record.previousRunIds)&&record.previousRunIds.length>0&&record.previousRunIds.length<=128,'supersede_record_invalid');
|
|
13
|
+
const runs=new Set();for(const runId of record.previousRunIds){id(runId);need(!runs.has(runId)&&runId!==record.newRunId,'supersede_record_invalid');runs.add(runId);}
|
|
14
|
+
need(typeof record.reason==='string'&&record.reason.trim()&&Buffer.byteLength(record.reason,'utf8')<=500
|
|
15
|
+
&&!/[\r\n\0]/.test(record.reason),'supersede_reason_required');
|
|
16
|
+
need(Array.isArray(record.files)&&record.files.length>0&&record.files.length<=256,'supersede_record_invalid');
|
|
17
|
+
const names=new Set();for(const file of record.files){
|
|
18
|
+
shape(file,['name','sha256']);
|
|
19
|
+
need(typeof file.name==='string'&&/^[A-Za-z0-9._-]+\.(md|json)$/.test(file.name)
|
|
20
|
+
&&supersedableEvidenceName(file.name,record.feature,record.taskId)
|
|
21
|
+
&&!names.has(file.name),'supersede_record_invalid');
|
|
22
|
+
names.add(file.name);hex(file.sha256);
|
|
23
|
+
}
|
|
24
|
+
if(expected)need(record.feature===expected.feature&&record.taskId===expected.taskId
|
|
25
|
+
&&record.newRunId===expected.newRunId,'supersede_record_invalid');
|
|
26
|
+
return record;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function supersedableEvidenceName(name,feature,taskId){
|
|
30
|
+
const prefix=`${feature.replace(/^\d+\./,'')}-${taskId}-`;
|
|
31
|
+
if(!name.startsWith(prefix))return false;
|
|
32
|
+
const suffix=name.slice(prefix.length);
|
|
33
|
+
return /^(?:a[12]-handoff\.json|r[12]\.md|(?:correction|qa)[A-Za-z0-9._-]*\.(?:md|json))$/.test(suffix);
|
|
34
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {readQaConfigRevision} from './qa-config-revision.mjs';
|
|
1
2
|
import {readQaAttachment} from './qa-attachment.mjs';
|
|
2
3
|
// Trusted synthetic fixture host; explicit V2 supports isolated task-file writes.
|
|
3
4
|
import { randomUUID } from 'node:crypto';
|
|
@@ -11,7 +12,7 @@ import { digest,need,shape,id,text,json,freeze,arrayItems,validIdentity,validTas
|
|
|
11
12
|
import { reviewResult,reviewReceipt } from './review-runner.mjs';
|
|
12
13
|
import { checkCompletion } from './gate-bridge.mjs';
|
|
13
14
|
import { runnerPayload,runnerPayloadV3,readRunnerHistory,attemptBaseline,boundRunnerRecord,
|
|
14
|
-
controlledState,stageAllowed,completedEffectCount,reviewTimeoutTransition,validateReviewDispatchGrant,validateTaskLearningReviewPackage } from './durable-runner-state.mjs';
|
|
15
|
+
MAX_AI_JOINED_HOSTS,controlledState,stageAllowed,completedEffectCount,reviewTimeoutTransition,validateReviewDispatchGrant,validateTaskLearningReviewPackage } from './durable-runner-state.mjs';
|
|
15
16
|
import {commitRunnerFixture} from './task-commit.mjs';
|
|
16
17
|
import {inspectProviderReview,hasProviderReviewResult} from './provider-review-observation.mjs';
|
|
17
18
|
import {attachCmAiTaskLearningApplicationEvidence,attachCmAiTaskLearningEvidence,
|
|
@@ -27,6 +28,7 @@ import {publishHostReview} from './host-review-file.mjs';
|
|
|
27
28
|
import {reviewExclusions} from './effect-contract.mjs';
|
|
28
29
|
import {bootstrapConfiguration,readBootstrapEvidence} from './host-bootstrap.mjs';
|
|
29
30
|
import {validateCodeProjectPaths,assertCodeProjectSelections} from './code-projects.mjs';
|
|
31
|
+
import {readEvidenceSupersession} from './reviewed-evidence-supersession-record.mjs';
|
|
30
32
|
|
|
31
33
|
// Keep default V1 imports free of SQLite initialization/warnings. Native ownership
|
|
32
34
|
// is loaded synchronously only at the explicit V2 boundary (Node24.14+).
|
|
@@ -124,10 +126,14 @@ export function createTaskRunner(options) {
|
|
|
124
126
|
if(invocationMode)id(r.adapterId);
|
|
125
127
|
return {...v,...(invocationMode?{adapterId:r.adapterId}:{}),run};
|
|
126
128
|
});
|
|
127
|
-
let invocationConfig=null,authorize=null;
|
|
129
|
+
let invocationConfig=null,authorize=null,liveHostContextId=null;
|
|
128
130
|
if(invocationMode){
|
|
129
131
|
need(reviewers.length===1&&['codex','claude'].includes(reviewers[0].provider)&&reviewers[0].allowed&&reviewers[0].available,'runner_invocation');
|
|
130
|
-
shape(options.reviewInvocation,['developerThreadId','excludedThreadIds','authorize'
|
|
132
|
+
shape(options.reviewInvocation,['developerThreadId','excludedThreadIds','authorize',
|
|
133
|
+
...(Object.hasOwn(options.reviewInvocation,'hostContextId')?['hostContextId']:[])]);
|
|
134
|
+
liveHostContextId=options.reviewInvocation.hostContextId??null;
|
|
135
|
+
if(liveHostContextId!==null){id(liveHostContextId);
|
|
136
|
+
need(![developer.contextId,...reviewers.flatMap(r=>r.contexts)].includes(liveHostContextId),'not_independent');}
|
|
131
137
|
authorize=options.reviewInvocation.authorize;need(typeof authorize==='function','runner_invocation');
|
|
132
138
|
invocationConfig=json({developerThreadId:options.reviewInvocation.developerThreadId,
|
|
133
139
|
excludedThreadIds:options.reviewInvocation.excludedThreadIds});
|
|
@@ -178,6 +184,11 @@ export function createTaskRunner(options) {
|
|
|
178
184
|
if(options.persistence.mode==='resume')restored=readRunnerHistory(journal,metadata,version);
|
|
179
185
|
else need(journal.length===0,'runner_exists');
|
|
180
186
|
}
|
|
187
|
+
// Transient live identity is deliberately absent from metadata/init bytes.
|
|
188
|
+
const joinedHosts=[...(restored?.joinedHosts??[])];
|
|
189
|
+
if(liveHostContextId!==null)need(!restored?.reviewerThreads.includes(liveHostContextId),'not_independent');
|
|
190
|
+
const liveInvocation=()=>({...invocationConfig,excludedThreadIds:[...new Set([
|
|
191
|
+
...invocationConfig.excludedThreadIds,...joinedHosts,...(liveHostContextId===null?[]:[liveHostContextId])])]});
|
|
181
192
|
const specificationSelection=options.specification??null;
|
|
182
193
|
if(specificationSelection!==null){
|
|
183
194
|
shape(specificationSelection,['specsRoot','feature']);
|
|
@@ -258,7 +269,8 @@ export function createTaskRunner(options) {
|
|
|
258
269
|
kind:{init:'result','effect-intent':'intent','effect-checkpoint':'result',control:'cancel',
|
|
259
270
|
'task-commit-intent':'commit-intent','task-commit-result':'commit-result',
|
|
260
271
|
'review-invocation-registered':'intent','review-invocation-started':'result','review-invocation-result':'result',
|
|
261
|
-
'qa-fix-accepted':'result','qa-attached':'result'
|
|
272
|
+
'host-joined':'result','qa-fix-accepted':'result','qa-attached':'result','qa-config-revised':'result',
|
|
273
|
+
'evidence-superseded':'result'}[type],
|
|
262
274
|
payload:version===3?runnerPayloadV3(type,fields):runnerPayload(type,fields,version)};
|
|
263
275
|
const body={version:1,seq:journal.length+1,...basic,previousDigest:journal.at(-1)?.digest??null};
|
|
264
276
|
const record={...body,digest:digest(body)};boundRunnerRecord(record,body.seq);
|
|
@@ -433,11 +445,17 @@ export function createTaskRunner(options) {
|
|
|
433
445
|
try{registeredAt=safeTime();}catch{halt('unknown','clock_invalid');return;}
|
|
434
446
|
if(registeredAt<authorizationAt){halt('unknown','clock_invalid');return;}
|
|
435
447
|
try{grant=validateReviewDispatchGrant(grant,{request,reviewerId:adapter.id,adapterId:adapter.adapterId,
|
|
436
|
-
packageDigest:reviewPackage.packageDigest,hostContextIds:[invocationConfig.developerThreadId,...
|
|
448
|
+
packageDigest:reviewPackage.packageDigest,hostContextIds:[invocationConfig.developerThreadId,...liveInvocation().excludedThreadIds],
|
|
437
449
|
authorizationAt,registeredAt});}
|
|
438
450
|
catch{halt('unknown','authorization_invalid');return;}
|
|
439
451
|
const registrationFields={effectId,reviewerId:adapter.id,adapterId:adapter.adapterId,requestDigest:request.requestDigest,
|
|
440
452
|
authorizationAt,registeredAt,grant};
|
|
453
|
+
// Validate first, then journal the signer immediately before registration.
|
|
454
|
+
// Durable host lists and prior joiners already have replayable authority.
|
|
455
|
+
if(![invocationConfig.developerThreadId,...invocationConfig.excludedThreadIds,...joinedHosts].includes(grant.hostContextId)){
|
|
456
|
+
need(joinedHosts.length<MAX_AI_JOINED_HOSTS,'host_limit');
|
|
457
|
+
persist('host-joined',{hostContextId:grant.hostContextId});joinedHosts.push(grant.hostContextId);
|
|
458
|
+
}
|
|
441
459
|
persist('review-invocation-registered',registrationFields);
|
|
442
460
|
sequence=nextSequence;
|
|
443
461
|
const registration=json({reviewerId:adapter.id,adapterId:adapter.adapterId,requestDigest:request.requestDigest,
|
|
@@ -459,7 +477,7 @@ export function createTaskRunner(options) {
|
|
|
459
477
|
}
|
|
460
478
|
call.started=true;
|
|
461
479
|
const expectation={request,developerThreadId:invocationConfig.developerThreadId,
|
|
462
|
-
excludedThreadIds:reviewExclusions(
|
|
480
|
+
excludedThreadIds:reviewExclusions(liveInvocation(),calls,developer.contextId)};
|
|
463
481
|
const events=[];let started=null,sealed=false,invalid=false,invalidReject;
|
|
464
482
|
const localController=new AbortController();
|
|
465
483
|
const abort=()=>localController.abort();controller.signal.addEventListener('abort',abort,{once:true});
|
|
@@ -740,7 +758,7 @@ export function createTaskRunner(options) {
|
|
|
740
758
|
busy=true;if(v.kind!=='develop')code=null;
|
|
741
759
|
pending=(async()=>{
|
|
742
760
|
try {await perform(v);}
|
|
743
|
-
catch(error){if(state!=='cancelled')halt(
|
|
761
|
+
catch(error){if(state!=='cancelled'){const code=failureCode(error);halt(code==='spec_drift'?'blocked':'unknown',code);}}
|
|
744
762
|
if(poisoned)return status();
|
|
745
763
|
const result=privateStatus();cache.set(v.id,{effect:v,digest:digest(v),result});
|
|
746
764
|
try{persist('effect-checkpoint',{effectId:v.id,checkpoint:frame()});publication=result;return result;}
|
|
@@ -831,7 +849,22 @@ export function createTaskRunner(options) {
|
|
|
831
849
|
need(state==='fixture_completed','qa_attach_not_completed');
|
|
832
850
|
persist('qa-attached',{record});qaAttachment=record;return json(record);
|
|
833
851
|
};
|
|
834
|
-
const
|
|
852
|
+
const reviseQa=raw=>{
|
|
853
|
+
need(invocationMode&&store&&!busy&&!poisoned,'qa_revision_unavailable');
|
|
854
|
+
const record=readQaConfigRevision(raw),current=status();
|
|
855
|
+
need(current.state==='fixture_completed'&¤t.code===null,'qa_revision_not_completed');
|
|
856
|
+
need(current.packageDigest===record.packageDigest,'package_mismatch');
|
|
857
|
+
persist('qa-config-revised',{record});return json(record);
|
|
858
|
+
};
|
|
859
|
+
const supersedeEvidence=raw=>{
|
|
860
|
+
need(invocationMode&&store&&!busy&&!poisoned,'supersede_unavailable');
|
|
861
|
+
const record=readEvidenceSupersession(raw,{feature:taskLearning.feature,
|
|
862
|
+
taskId:config.identity.taskId,newRunId:config.identity.runId});
|
|
863
|
+
if(restored?.supersession){need(digest(restored.supersession)===digest(record),'supersede_record_invalid');return json(record);}
|
|
864
|
+
need(journal.length===1&&state==='ready','supersede_unavailable');
|
|
865
|
+
persist('evidence-superseded',{record});return json(record);
|
|
866
|
+
};
|
|
867
|
+
const api={reviseQa,supersedeEvidence,executeEffect,status,cancel,run,inspectFixAssociation,acceptCompletedFix,attachQa,verificationBlocks};
|
|
835
868
|
if(bootstrap!==null)api.inspectBootstrapAdmission=()=>bootstrap.inspectAdmission(original);
|
|
836
869
|
if(taskLearning!==null)api.attachLearningEvidence=attachLearningEvidence;
|
|
837
870
|
return Object.freeze(api);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {spawn} from 'node:child_process';
|
|
3
3
|
import {readFileSync} from 'node:fs';
|
|
4
4
|
import {claudeBaseArgs,claudeEnvironment} from './worker-claude.mjs';
|
|
5
|
-
import {reportClaudeRateLimitNotice} from './claude-review-stream.mjs';
|
|
5
|
+
import {reportClaudeDevIntentNotice,reportClaudeRateLimitNotice} from './claude-review-stream.mjs';
|
|
6
6
|
import {need,text,validCallTimeout,json,shape} from './effect-contract.mjs';
|
|
7
7
|
|
|
8
8
|
export function claudeDeveloperArgs(model){
|
|
@@ -54,21 +54,30 @@ export function validateClaudeProposal(raw){
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
function createClaudeDeveloperStream(onNotice=null){
|
|
57
|
-
let session=null,done=false,value,assistant=false,noticeCount=0,thinkingCount=0;
|
|
57
|
+
let session=null,initialized=false,done=false,value,assistant=false,noticeCount=0,thinkingCount=0;
|
|
58
58
|
const tools=new Set();
|
|
59
59
|
return {
|
|
60
60
|
accept(event){
|
|
61
61
|
need(event&&typeof event==='object'&&!Array.isArray(event)&&!done,'invalid_event');
|
|
62
|
-
need(typeof event.session_id==='string'&&event.session_id.
|
|
63
|
-
if(session
|
|
64
|
-
|
|
62
|
+
need(typeof event.session_id==='string'&&event.session_id.trim()&&event.session_id.length<=128,'invalid_session');
|
|
63
|
+
if(session!==null)need(event.session_id===session,'session_mismatch');
|
|
64
|
+
if(!initialized){
|
|
65
|
+
if(event.type==='system'&&event.subtype==='dev_intent'){
|
|
66
|
+
need(noticeCount<32,'unexpected_event');noticeCount++;
|
|
67
|
+
session=event.session_id;reportClaudeDevIntentNotice(onNotice);return;
|
|
68
|
+
}
|
|
69
|
+
need(event.type==='system'&&event.subtype==='init','missing_init');
|
|
70
|
+
session=event.session_id;initialized=true;return;
|
|
65
71
|
}
|
|
66
|
-
need(event.session_id===session,'session_mismatch');
|
|
67
72
|
if(event.type==='rate_limit_event'){
|
|
68
|
-
need(noticeCount<
|
|
73
|
+
need(noticeCount<32,'unexpected_event');noticeCount++;
|
|
69
74
|
reportClaudeRateLimitNotice(event.rate_limit_info,onNotice);return;
|
|
70
75
|
}
|
|
71
76
|
if(event.type==='system'){
|
|
77
|
+
if(event.subtype==='dev_intent'){
|
|
78
|
+
need(noticeCount<32,'unexpected_event');noticeCount++;
|
|
79
|
+
reportClaudeDevIntentNotice(onNotice);return;
|
|
80
|
+
}
|
|
72
81
|
need(event.subtype==='thinking_tokens'&&thinkingCount<64,'unexpected_event');thinkingCount++;return;
|
|
73
82
|
}
|
|
74
83
|
if(event.type==='assistant'){
|
|
@@ -4,18 +4,22 @@ import {inspectProviderCauseReview} from '../cm-ai/provider-review-observation.m
|
|
|
4
4
|
import {digest,id,json,need,shape,text,hex} from '../cm-ai/effect-contract.mjs';
|
|
5
5
|
|
|
6
6
|
// A run outlives the session that created it. Its durable configuration keeps the
|
|
7
|
-
// original hostContextId, so stored records and fingerprints stay byte-identical
|
|
8
|
-
//
|
|
9
|
-
//
|
|
7
|
+
// original hostContextId, so stored records and fingerprints stay byte-identical.
|
|
8
|
+
// Every later session that signs a grant is first written into the run's own
|
|
9
|
+
// history (fix-host-joined-N), and the session running now is added on top. All
|
|
10
|
+
// of them are host identities: a grant may carry any, and the reviewer stays
|
|
11
|
+
// independent of every one. The history is what lets a third session accept a
|
|
12
|
+
// grant the second one signed.
|
|
13
|
+
export const MAX_FIX_JOINED_HOSTS=16;
|
|
10
14
|
export function fixHostContexts(configuration){
|
|
11
15
|
const hosts=configuration.hostContextIds??[configuration.hostContextId];
|
|
12
|
-
need(Array.isArray(hosts)&&hosts.length>=1&&hosts.length<=2&&new Set(hosts).size===hosts.length
|
|
16
|
+
need(Array.isArray(hosts)&&hosts.length>=1&&hosts.length<=MAX_FIX_JOINED_HOSTS+2&&new Set(hosts).size===hosts.length
|
|
13
17
|
&&hosts[0]===configuration.hostContextId,'invalid_host_context');
|
|
14
18
|
hosts.forEach(id);return hosts;
|
|
15
19
|
}
|
|
16
20
|
export function validateCauseReviewer(raw,hostContextId,maxExclusions=32){
|
|
17
21
|
const hosts=Array.isArray(hostContextId)?hostContextId:[hostContextId];
|
|
18
|
-
need(hosts.length>=1&&hosts.length<=2,'invalid_cause_reviewer');hosts.forEach(id);
|
|
22
|
+
need(hosts.length>=1&&hosts.length<=MAX_FIX_JOINED_HOSTS+2,'invalid_cause_reviewer');hosts.forEach(id);
|
|
19
23
|
need([32,33,34].includes(maxExclusions),'invalid_cause_reviewer');
|
|
20
24
|
const value=json(raw);shape(value,['reviewerId','adapterId','provider','requestedModel','contextId','excludedThreadIds',
|
|
21
25
|
...(Object.hasOwn(value,'workerConfigurationDigest')?['workerConfigurationDigest']:[])]);
|
|
@@ -4,6 +4,8 @@ import {digest,id,json,need,shape,text,validIdentity} from '../cm-ai/effect-cont
|
|
|
4
4
|
import {inspectFixLearning} from './learning.mjs';
|
|
5
5
|
import {inspectFixInvestigation} from './investigation.mjs';
|
|
6
6
|
import {inspectFixReproductionAttempts} from './reproduce.mjs';
|
|
7
|
+
import {inspectFixTestAuthor} from './test-author.mjs';
|
|
8
|
+
import {inventory} from './test-extension.mjs';
|
|
7
9
|
import {inspectVisualCarrier} from './visual.mjs';
|
|
8
10
|
|
|
9
11
|
export function createFixCausePackage({codeProject,defect,status}){
|
|
@@ -68,3 +70,22 @@ export function readFixCausePackage(raw){
|
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
export const causeReviewPaths=pkg=>pkg.files.map(file=>file.path);
|
|
73
|
+
|
|
74
|
+
// Validate the original package, then admit only the exact registered test transition.
|
|
75
|
+
export function verifyFixCauseTransition(original,current,authorBaseline,authorResult){
|
|
76
|
+
const reviewed=readFixCausePackage(original),now=readFixCausePackage(current);
|
|
77
|
+
const expected=new Map(reviewed.files.map(file=>[file.path,file]));
|
|
78
|
+
if(authorBaseline&&authorResult){
|
|
79
|
+
const authored=inspectFixTestAuthor(authorResult,authorBaseline);
|
|
80
|
+
need(authored.outcome==='authored','cause_review_drift');
|
|
81
|
+
const before=new Map(authorBaseline.files.map(file=>[file.path,file]));
|
|
82
|
+
for(const file of authored.testFiles){
|
|
83
|
+
if(!expected.has(file.path))continue;
|
|
84
|
+
need(digest(inventory([before.get(file.path)]))===digest(inventory([expected.get(file.path)])),'cause_review_drift');
|
|
85
|
+
expected.set(file.path,file);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
need(digest(inventory(now.files))===digest(inventory([...expected.values()])),'cause_review_drift');
|
|
89
|
+
const {packageDigest,...body}=now;
|
|
90
|
+
need(digest({...body,files:reviewed.files})===reviewed.packageDigest,'cause_review_drift');
|
|
91
|
+
}
|
|
@@ -4,6 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import {createHash,randomUUID} from 'node:crypto';
|
|
5
5
|
import {need,digest} from '../cm-ai/effect-contract.mjs';
|
|
6
6
|
import {writeReviewEvidence} from '../cm-ai/review-evidence-file.mjs';
|
|
7
|
+
import {currentTestFiles,verifyExtensionFiles} from './test-extension.mjs';
|
|
7
8
|
import {verifyFixRedEvidence} from './red-test.mjs';
|
|
8
9
|
import {inspectFixReproduction} from './reproduce.mjs';
|
|
9
10
|
import {readReviewSourceFiles} from '../cm-ai/review-package.mjs';
|
|
@@ -75,13 +76,50 @@ export function publishFixObservationDossier({specsRoot,configuration,status,reg
|
|
|
75
76
|
return {path:written.path,sha256:createHash('sha256').update(bytes).digest('hex'),completionEligible:false};
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
// Escalation is an incomplete exit, never a repaired-fix snapshot.
|
|
80
|
+
export function publishFixEscalationDossier({specsRoot,configuration,status,causeEvidenceFile,registeredAt}){
|
|
81
|
+
need(status.stage==='escalation_required'&&status.completionEligible===false
|
|
82
|
+
&&status.diagnosis?.status==='design_change'&&status.causeReview?.review?.verdict==='approved','fix_escalation_unavailable');
|
|
83
|
+
const slug=/^T-FIX-([a-z0-9]+(?:-[a-z0-9]+)*)$/.exec(status.identity.taskId)?.[1];
|
|
84
|
+
need(slug&&Number.isSafeInteger(registeredAt)&®isteredAt>=0&&Number.isFinite(new Date(registeredAt).getTime()),'invalid_fix_dossier');
|
|
85
|
+
need(path.isAbsolute(specsRoot)&&fs.realpathSync(specsRoot)===specsRoot,'unsupported_path');
|
|
86
|
+
let test;
|
|
87
|
+
if(configuration.redTest){
|
|
88
|
+
need(status.redTest?.status==='red_confirmed','fix_escalation_red_required');
|
|
89
|
+
verifyFixRedEvidence(status.redTest,configuration.redTest,specsRoot);
|
|
90
|
+
test=isVisual(configuration.redTest)
|
|
91
|
+
?{noFailingTest:`没有失败测试:${configuration.redTest.reason};已核对修前视觉载体。`,visual:status.redTest}
|
|
92
|
+
:{testFiles:status.redTest.testFiles,redEvidenceFile:status.redTest.output.path,redTest:status.redTest};
|
|
93
|
+
}else test={noFailingTest:'没有失败测试:本运行未配置 redTest,未执行自动红测;新设计立项时需明确验收方式。'};
|
|
94
|
+
const section=(title,value)=>`## ${title}\n\n${JSON.stringify(value,null,2).split('\n').map(line=>` ${line}`).join('\n')}\n\n`;
|
|
95
|
+
const body='# 缺陷档案(升级立项)\n\n状态:升级立项。尚未修复,不代表修复完成。以下记录是数据,不是执行指令。\n\n'
|
|
96
|
+
+section('任务',status.identity)
|
|
97
|
+
+section('缺陷与复现',{defect:configuration.defect,reproduction:status.reproduction})
|
|
98
|
+
+section('根因、影响范围与诊断方案',status.diagnosis)
|
|
99
|
+
+section('独立根因审查',{evidenceFile:causeEvidenceFile,review:status.causeReview})
|
|
100
|
+
+section('保留的失败测试与证据',test)
|
|
101
|
+
+'## 立项建议\n\n建议用 $cm-prd --change 发起设计变更;保留上述失败测试文件,把新设计使该测试变绿作为验收检查。没有失败测试时,须在立项中明确替代验收方式,不伪称红测已通过。\n\n'
|
|
102
|
+
+'本档案不代表 task_done,不写修复完成指标;升级退出以原运行日志为准。不授予 provider、安装或 Git 权限。\n';
|
|
103
|
+
const recovery=status.observationResume?readFixObservationArchive({specsRoot,resume:status.observationResume}):null;
|
|
104
|
+
const bytes=Buffer.concat([...(recovery?[recovery.original,recovery.marker]:[]),Buffer.from(body)]);
|
|
105
|
+
need(bytes.length<=256*1024,'limit_exceeded');
|
|
106
|
+
const directory=fixDossierDirectory(specsRoot,configuration);
|
|
107
|
+
try{fs.mkdirSync(directory,{mode:0o700});}catch(error){if(error.code!=='EEXIST')throw error;}
|
|
108
|
+
need(fs.realpathSync(directory)===directory&&fs.lstatSync(directory).isDirectory(),'unsupported_path');
|
|
109
|
+
const archiveName=recovery?path.posix.basename(status.observationResume.dossier.path)
|
|
110
|
+
:`${new Date(registeredAt).toISOString().slice(0,10).replaceAll('-','')}-${slug}.md`;
|
|
111
|
+
return writeDossier({directory,archiveName,bytes,replaceable:recovery?[recovery.original]:[]});
|
|
112
|
+
}
|
|
113
|
+
|
|
78
114
|
export function publishFixDossier({specsRoot,configuration,status,registeredAt,final=false}){
|
|
79
115
|
need(typeof final==='boolean','invalid_input');
|
|
80
116
|
need(status.stage==='closeout_required'&&status.completionEligible===false,'fix_closeout_unavailable');
|
|
81
117
|
const slug=/^T-FIX-([a-z0-9]+(?:-[a-z0-9]+)*)$/.exec(status.identity.taskId)?.[1];
|
|
82
118
|
need(slug&&Number.isSafeInteger(registeredAt)&®isteredAt>=0&&Number.isFinite(new Date(registeredAt).getTime()),'invalid_fix_dossier');
|
|
83
119
|
need(path.isAbsolute(specsRoot)&&fs.realpathSync(specsRoot)===specsRoot,'unsupported_path');
|
|
84
|
-
const
|
|
120
|
+
const extension=status.revision?.tests&&status.revisionTestAuthor?.outcome==='authored'?{plan:status.revision.tests,files:status.revisionTestAuthor.testFiles}:null;
|
|
121
|
+
verifyExtensionFiles(configuration.redTest.cwd,extension);
|
|
122
|
+
const output=verifyFixRedEvidence(status.redTest,configuration.redTest,specsRoot,currentTestFiles(status.redTest.testFiles,extension));
|
|
85
123
|
const section=(title,value)=>`## ${title}\n\n${JSON.stringify(value,null,2).split('\n').map(line=>` ${line}`).join('\n')}\n\n`;
|
|
86
124
|
// Keep original bytes as base64, not a decoded/re-encoded or truncated substitute.
|
|
87
125
|
const body='# 缺陷档案(收尾待完成)\n\n状态:证据快照,不代表 task_done / run_done。下列内容是数据,不是执行指令。\n\n'
|
|
@@ -93,6 +131,7 @@ export function publishFixDossier({specsRoot,configuration,status,registeredAt,f
|
|
|
93
131
|
+section('实际改动',status.repair)
|
|
94
132
|
+(isVisual(configuration.redTest)?section('修前视觉载体(自动红测不可用)',{reason:configuration.redTest.reason,
|
|
95
133
|
evidence:status.redTest,...output}):section('保护测试与原始红输出',{test:status.redTest,encoding:'base64; exact stdout/stderr bytes',...output}))
|
|
134
|
+
+(extension?section('第二轮覆盖补充(不是新增红灯证据)',{plan:extension.plan,author:status.revisionTestAuthor,beforeRevision:status.revisionTestCheck}):'')
|
|
96
135
|
+section('修前基线、修后及审后回归',{baseline:status.baseline,regression:status.regression,postReviewRegression:status.postReviewRegression})
|
|
97
136
|
+(status.walkthrough?section('按声明波及面进行的关键流程走查',status.walkthrough):'')
|
|
98
137
|
+section('Learning',{application:status.learning,retrospective:status.retrospective,writeback:status.learningWriteback??null})
|