taskforce-loop-engineering 0.16.3 → 0.16.5
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/CHANGELOG.md +24 -0
- package/docs/isolated-verification.md +30 -3
- package/lib/context-budget.mjs +9 -1
- package/lib/core.mjs +348 -50
- package/lib/isolated-verification.mjs +14 -1
- package/package.json +2 -2
- package/scripts/async-acceptance-refresh-self-test.mjs +3 -0
- package/scripts/context-budget-self-test.mjs +25 -7
- package/scripts/continuation-regression-self-test.mjs +175 -0
- package/scripts/final-judgement-self-test.mjs +243 -1
- package/scripts/isolated-verification-self-test.mjs +31 -2
- package/scripts/isolated-verify-self-test.py +32 -0
- package/scripts/isolated-verify.py +122 -9
- package/scripts/revision-coverage-self-test.mjs +105 -0
- package/scripts/route-notify-self-test.mjs +12 -1
- package/skills/taskforce-loop-engineering/SKILL.md +18 -1
- package/skills/taskforce-loop-engineering/references/context-budget.md +1 -1
- package/skills/taskforce-loop-engineering/references/scope-task-acceptance.md +11 -1
|
@@ -38,10 +38,23 @@ export async function runIsolatedVerification({ cwd, command, inputs, runtimeFil
|
|
|
38
38
|
...result,
|
|
39
39
|
exitCode: accepted ? 0 : 1,
|
|
40
40
|
isolation: { status: accepted ? 'passed' : 'failed_or_unknown', evidenceDir,
|
|
41
|
-
inputDigest: terminal?.input_digest ?? null, runnerSha256: runnerHash
|
|
41
|
+
inputDigest: terminal?.input_digest ?? null, runnerSha256: runnerHash,
|
|
42
|
+
// Say why, so an operator does not have to open terminal.json.
|
|
43
|
+
...(accepted ? {} : { reason: isolationFailureReason(result, terminal, runnerHash === afterHash) }) }
|
|
42
44
|
};
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
function isolationFailureReason(result, terminal, runnerUnchanged) {
|
|
48
|
+
if (!runnerUnchanged) return 'isolation supervisor changed during verification';
|
|
49
|
+
if (!terminal) return result.timedOut ? 'isolation supervisor timed out before writing a receipt' : `no isolation receipt (supervisor exit ${result.exitCode}): ${String(result.stderr ?? '').trim().slice(-300)}`;
|
|
50
|
+
if (terminal.error) return terminal.error;
|
|
51
|
+
if (terminal.timed_out) return 'verification command timed out';
|
|
52
|
+
if (terminal.read_violations?.length) return `read audit failed: ${terminal.read_violations.slice(0, 3).join('; ')}`;
|
|
53
|
+
if (terminal.exit_code !== 0) return `verification command exited ${terminal.exit_code}`;
|
|
54
|
+
const failed = ['snapshot_unchanged', 'source_unchanged', 'host_tools_unchanged', 'runtime_files_unchanged', 'process_group_gone'].filter((key) => terminal[key] !== true);
|
|
55
|
+
return failed.length ? `receipt check failed: ${failed.join(', ')}` : 'receipt did not match the requested command';
|
|
56
|
+
}
|
|
57
|
+
|
|
45
58
|
export function isolatedEvidenceDir(base, index) {
|
|
46
59
|
return path.join(base, `isolation-${index + 1}-${randomUUID()}`);
|
|
47
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "taskforce-loop-engineering",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "OpenClaw-native loop engineering CLI, templates, and skill for verifiable agent work loops.",
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"check:hermes-install": "node --check scripts/hermes-install.mjs && node --check scripts/hermes-doctor.mjs && node --check scripts/hermes-smoke.mjs && node scripts/hermes-install-self-test.mjs",
|
|
32
32
|
"check:project-gates": "node --check lib/core.mjs && node scripts/project-gate-reconciliation-self-test.mjs && node scripts/project-relay-self-test.mjs",
|
|
33
33
|
"check:human-gates": "node --check lib/human-gate-command.mjs && node --check lib/human-gate-channel-adapter.mjs && node scripts/human-gate-command-self-test.mjs && node scripts/human-gate-final-judgement.mjs",
|
|
34
|
-
"check": "node scripts/context-budget-self-test.mjs && npm run check:project-gates && node scripts/safety-regression-self-test.mjs && npm run check:config-drift && npm run check:openclaw-install && npm run check:hermes-install && node --check bin/loop-engineering.mjs && node --check lib/core.mjs && node --check lib/action-reservations.mjs && node --check lib/todo-control-plane.mjs && node --check lib/quota-runtime-decision.mjs && node --check lib/operator-dashboard.mjs && node scripts/action-reservation-self-test.mjs && node scripts/todo-control-plane-self-test.mjs && node scripts/quota-runtime-decision-self-test.mjs && node scripts/operator-dashboard-self-test.mjs && node scripts/final-judgement-self-test.mjs && node scripts/route-notify-self-test.mjs && node scripts/scheduler-heartbeat-self-test.mjs && node scripts/human-gate-lifecycle-v2-self-test.mjs && node bin/loop-engineering.mjs verify --config templates/workspace-health.json --root . && node bin/loop-engineering.mjs queue-status --queue smoke --root . --json >/dev/null && node bin/loop-engineering.mjs project-intake --root /tmp/loop-engineering-check --name smoke-project --brief \"Build a small website project\" --type auto --check \"npm test\" --json >/dev/null && node bin/loop-engineering.mjs project-plan --root /tmp/loop-engineering-check --project smoke-project --force --json >/dev/null && node bin/loop-engineering.mjs project-status --root /tmp/loop-engineering-check --project smoke-project --json >/dev/null && node bin/loop-engineering.mjs queue-scheduler-tick --queue smoke --root /tmp/loop-engineering-check --plan-only --force-due --json >/dev/null && node bin/loop-engineering.mjs queue-scheduler-tick --queue smoke-progress --root /tmp/loop-engineering-check --plan-only --force-due --progress-report --progress-report-when-not-due --json >/dev/null && node bin/loop-engineering.mjs workflow-metrics --queue smoke --root . --json >/dev/null && node bin/loop-engineering.mjs workflow-tune-plan --queue smoke --root . --json >/dev/null && node bin/loop-engineering.mjs code-queue-init --queue smoke-code --root /tmp/loop-engineering-check --force >/dev/null && node bin/loop-engineering.mjs code-worktree-list --queue smoke-code --root /tmp/loop-engineering-check --json >/dev/null && node bin/loop-engineering.mjs code-task-status --queue smoke-code --root /tmp/loop-engineering-check --json >/dev/null && node bin/loop-engineering.mjs code-task-dashboard --queue smoke-code --root /tmp/loop-engineering-check --json >/dev/null && node bin/loop-engineering.mjs code-worktree-cleanup-plan --queue smoke-code --root /tmp/loop-engineering-check --json >/dev/null && node bin/loop-engineering.mjs code-worktree-cleanup --queue smoke-code --root /tmp/loop-engineering-check --confirm-cleanup --json >/dev/null && node bin/loop-engineering.mjs code-patch-verify --patch README.md --root . --json >/dev/null && node bin/loop-engineering.mjs code-patch-apply-plan --patch README.md --json >/dev/null && node bin/loop-engineering.mjs queue-revision-ci-self-test --queue smoke-ci --root /tmp/loop-engineering-check --json >/dev/null && node bin/loop-engineering.mjs summarize --root . --json >/dev/null && node bin/loop-engineering.mjs dashboard-health --root . --max-age-seconds 999999999 --json >/dev/null && node bin/loop-engineering.mjs doctor --root . --json >/dev/null",
|
|
34
|
+
"check": "node scripts/context-budget-self-test.mjs && npm run check:project-gates && node scripts/safety-regression-self-test.mjs && node scripts/continuation-regression-self-test.mjs && npm run check:config-drift && npm run check:openclaw-install && npm run check:hermes-install && node --check bin/loop-engineering.mjs && node --check lib/core.mjs && node --check lib/action-reservations.mjs && node --check lib/todo-control-plane.mjs && node --check lib/quota-runtime-decision.mjs && node --check lib/operator-dashboard.mjs && node scripts/action-reservation-self-test.mjs && node scripts/todo-control-plane-self-test.mjs && node scripts/quota-runtime-decision-self-test.mjs && node scripts/operator-dashboard-self-test.mjs && node scripts/final-judgement-self-test.mjs && node scripts/revision-coverage-self-test.mjs && node scripts/route-notify-self-test.mjs && node scripts/scheduler-heartbeat-self-test.mjs && node scripts/human-gate-lifecycle-v2-self-test.mjs && node bin/loop-engineering.mjs verify --config templates/workspace-health.json --root . && node bin/loop-engineering.mjs queue-status --queue smoke --root . --json >/dev/null && node bin/loop-engineering.mjs project-intake --root /tmp/loop-engineering-check --name smoke-project --brief \"Build a small website project\" --type auto --check \"npm test\" --json >/dev/null && node bin/loop-engineering.mjs project-plan --root /tmp/loop-engineering-check --project smoke-project --force --json >/dev/null && node bin/loop-engineering.mjs project-status --root /tmp/loop-engineering-check --project smoke-project --json >/dev/null && node bin/loop-engineering.mjs queue-scheduler-tick --queue smoke --root /tmp/loop-engineering-check --plan-only --force-due --json >/dev/null && node bin/loop-engineering.mjs queue-scheduler-tick --queue smoke-progress --root /tmp/loop-engineering-check --plan-only --force-due --progress-report --progress-report-when-not-due --json >/dev/null && node bin/loop-engineering.mjs workflow-metrics --queue smoke --root . --json >/dev/null && node bin/loop-engineering.mjs workflow-tune-plan --queue smoke --root . --json >/dev/null && node bin/loop-engineering.mjs code-queue-init --queue smoke-code --root /tmp/loop-engineering-check --force >/dev/null && node bin/loop-engineering.mjs code-worktree-list --queue smoke-code --root /tmp/loop-engineering-check --json >/dev/null && node bin/loop-engineering.mjs code-task-status --queue smoke-code --root /tmp/loop-engineering-check --json >/dev/null && node bin/loop-engineering.mjs code-task-dashboard --queue smoke-code --root /tmp/loop-engineering-check --json >/dev/null && node bin/loop-engineering.mjs code-worktree-cleanup-plan --queue smoke-code --root /tmp/loop-engineering-check --json >/dev/null && node bin/loop-engineering.mjs code-worktree-cleanup --queue smoke-code --root /tmp/loop-engineering-check --confirm-cleanup --json >/dev/null && node bin/loop-engineering.mjs code-patch-verify --patch README.md --root . --json >/dev/null && node bin/loop-engineering.mjs code-patch-apply-plan --patch README.md --json >/dev/null && node bin/loop-engineering.mjs queue-revision-ci-self-test --queue smoke-ci --root /tmp/loop-engineering-check --json >/dev/null && node bin/loop-engineering.mjs summarize --root . --json >/dev/null && node bin/loop-engineering.mjs dashboard-health --root . --max-age-seconds 999999999 --json >/dev/null && node bin/loop-engineering.mjs doctor --root . --json >/dev/null",
|
|
35
35
|
"pack:dry": "npm pack --dry-run"
|
|
36
36
|
},
|
|
37
37
|
"exports": {
|
|
@@ -27,6 +27,9 @@ try {
|
|
|
27
27
|
status: 'blocked', summary: 'Soak still running.', files_changed: ['soak.json'], verification: ['pending'], blockers: ['pending'], risks: [], project_completion: { status: 'in_progress' }
|
|
28
28
|
});
|
|
29
29
|
await writeJson(path.join(runtimeDir, 'final_judgement.json'), { version: 1, task_id: taskId, outcome: 'blocked' });
|
|
30
|
+
// Legacy judgements without coverage must be rebuilt once, then stay current.
|
|
31
|
+
assert.equal((await refreshTaskAcceptance(root, { queue, taskId })).outcome, 'refreshed');
|
|
32
|
+
assert.equal((await readJson(path.join(runtimeDir, 'final_judgement.json'))).coverage.planned_checkpoints, 1);
|
|
30
33
|
assert.equal((await refreshTaskAcceptance(root, { queue, taskId })).outcome, 'already_current');
|
|
31
34
|
|
|
32
35
|
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
@@ -24,7 +24,7 @@ assert.equal(dispatchFailureClassification({ exitCode: 1, stderr: 'Permission de
|
|
|
24
24
|
|
|
25
25
|
const roots = [];
|
|
26
26
|
try {
|
|
27
|
-
for (const scenario of ['yield', 'stale', 'malformed', 'missing-checkpoint', 'checkpoint-gate', 'pending-action', 'overflow', 'human-error', 'oversized', 'project-soft', 'project-hard', 'project-no-usage', 'terminal', 'pending-action-overflow', 'checkpoint-gate-overflow', 'stale-overflow', 'malformed-overflow', 'yield-overflow', 'yield-human-error', 'pending-action-failure']) {
|
|
27
|
+
for (const scenario of ['yield', 'repeat-yield', 'empty-yield', 'stale', 'malformed', 'missing-checkpoint', 'checkpoint-gate', 'pending-action', 'overflow', 'human-error', 'oversized', 'project-soft', 'project-hard', 'project-no-usage', 'terminal', 'pending-action-overflow', 'checkpoint-gate-overflow', 'stale-overflow', 'malformed-overflow', 'yield-overflow', 'yield-human-error', 'pending-action-failure']) {
|
|
28
28
|
const root = await mkdtemp(path.join(tmpdir(), 'loop-context-'));
|
|
29
29
|
roots.push(root);
|
|
30
30
|
const worker = path.join(root, 'worker.mjs');
|
|
@@ -46,7 +46,7 @@ if (scenario.startsWith('project-') || scenario === 'terminal') {
|
|
|
46
46
|
process.exit(0);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
if (scenario !== 'missing-checkpoint') await writeFile(checkpoint, JSON.stringify({ task_id: e.LOOP_TASK_ID, loop_run_id: e.LOOP_RUN_ID, checkpoint_id: e.LOOP_RUN_ID, status: scenario === 'checkpoint-gate' ? 'needs_human_input' : 'in_progress', summary: 'bounded progress', blockers: scenario === 'checkpoint-gate' ? ['Need approval'] : [], verification: [], risks: [], next_action: 'continue' }));
|
|
49
|
+
if (scenario !== 'missing-checkpoint') await writeFile(checkpoint, JSON.stringify({ task_id: e.LOOP_TASK_ID, loop_run_id: e.LOOP_RUN_ID, checkpoint_id: e.LOOP_RUN_ID, status: scenario === 'checkpoint-gate' ? 'needs_human_input' : 'in_progress', summary: 'bounded progress', blockers: scenario === 'checkpoint-gate' ? ['Need approval'] : [], verification: scenario === 'empty-yield' ? [] : ['verified unit ' + (scenario === 'repeat-yield' ? 'same' : e.LOOP_SESSION_GENERATION)], risks: [], next_action: 'continue' }));
|
|
50
50
|
const handoff = { version: 1, taskId: e.LOOP_TASK_ID, runId: scenario === 'stale' ? 'old-run' : e.LOOP_RUN_ID, generation: Number(e.LOOP_SESSION_GENERATION), attempt: Number(e.LOOP_ATTEMPT), reason: 'context_budget', checkpoint, summary: 'progress', completed: ['read source'], remaining: ['verify changes'], evidence: [checkpoint], nextAction: 'inspect test', authority: 'local only', pendingActions: scenario === 'pending-action' ? ['unknown payment outcome'] : [], blockers: [] };
|
|
51
51
|
await writeFile(e.LOOP_CONTEXT_HANDOFF_FILE, scenario === 'malformed' ? '{' : scenario === 'oversized' ? ' '.repeat(17000) : JSON.stringify(handoff));
|
|
52
52
|
if (original !== scenario) { console.error(original.endsWith('-human-error') ? 'Permission denied; context_length_exceeded' : original.endsWith('-failure') ? 'generic failure' : 'context_length_exceeded'); process.exitCode = 1; }
|
|
@@ -72,16 +72,34 @@ if (original !== scenario) { console.error(original.endsWith('-human-error') ? '
|
|
|
72
72
|
} else if (scenario === 'terminal') {
|
|
73
73
|
assert.equal(first.status, 'completed');
|
|
74
74
|
assert.equal((await runQueueOnce(root, options)).processed, false, 'high token usage cannot replay completed work');
|
|
75
|
-
} else if (['yield', 'overflow', 'yield-overflow'].includes(scenario)) {
|
|
75
|
+
} else if (['yield', 'repeat-yield', 'overflow', 'yield-overflow'].includes(scenario)) {
|
|
76
76
|
assert.equal(first.status, 'runtime_interrupted', scenario);
|
|
77
77
|
const task = JSON.parse(await readFile(path.join(root, first.taskPath), 'utf8'));
|
|
78
78
|
assert.equal(task.runtimeSessionGeneration, 1);
|
|
79
79
|
assert.equal(task.sessionTickCount, 0);
|
|
80
80
|
if (scenario === 'yield') assert.ok(task.contextHandoffFile);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
if (scenario === 'yield') {
|
|
82
|
+
// Normal progress can rotate beyond the exception budget, even with
|
|
83
|
+
// an already exhausted exception counter. It must not reset it either.
|
|
84
|
+
task.runtimeRecoveryCount = 2;
|
|
85
|
+
await writeFile(path.join(root, first.taskPath), JSON.stringify(task));
|
|
86
|
+
for (let tick = 0; tick < 4; tick++) {
|
|
87
|
+
const next = await runQueueOnce(root, options);
|
|
88
|
+
assert.equal(next.status, 'runtime_interrupted');
|
|
89
|
+
const saved = JSON.parse(await readFile(path.join(root, next.taskPath), 'utf8'));
|
|
90
|
+
assert.equal(saved.runtimeRecoveryCount, 2);
|
|
91
|
+
assert.equal(saved.contextHandoffCount, tick + 2);
|
|
92
|
+
assert.equal(saved.runtimeSessionGeneration, tick + 2);
|
|
93
|
+
}
|
|
94
|
+
} else if (scenario === 'repeat-yield') {
|
|
95
|
+
assert.equal((await runQueueOnce(root, options)).status, 'runtime_blocked');
|
|
96
|
+
assert.equal((await runQueueOnce(root, options)).processed, false);
|
|
97
|
+
} else {
|
|
98
|
+
const second = await runQueueOnce(root, options);
|
|
99
|
+
assert.equal(second.status, 'runtime_interrupted');
|
|
100
|
+
const third = await runQueueOnce(root, options);
|
|
101
|
+
assert.equal(third.status, 'runtime_blocked', 'exception recovery is bounded');
|
|
102
|
+
}
|
|
85
103
|
} else if (['pending-action', 'checkpoint-gate', 'human-error', 'pending-action-overflow', 'checkpoint-gate-overflow', 'yield-human-error', 'pending-action-failure'].includes(scenario)) {
|
|
86
104
|
assert.equal(first.status, 'needs_human_input', scenario);
|
|
87
105
|
assert.equal((await runQueueOnce(root, options)).processed, false, 'blocked work cannot auto-replay');
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { mkdir } from 'node:fs/promises';
|
|
6
|
+
import { buildFinalJudgement, enqueueTask, inferTaskScope, notifyTerminalTasks, queueRequeue, runQueueOnce, writeJson } from '../lib/core.mjs';
|
|
7
|
+
|
|
8
|
+
// A worker that follows the dev plan's checkpoint template exactly. `script`
|
|
9
|
+
// receives the tick number and returns { status, exit } decisions.
|
|
10
|
+
async function templateWorker(root, body) {
|
|
11
|
+
const worker = path.join(root, 'worker.mjs');
|
|
12
|
+
await writeFile(worker, `import { readFile, writeFile } from 'node:fs/promises';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
const dir = path.join(process.env.LOOP_CHECKPOINTS_DIR, '..');
|
|
15
|
+
const plan = JSON.parse(await readFile(path.join(dir, 'dev_plan.json'), 'utf8'));
|
|
16
|
+
const schema = plan.checkpoint_schema;
|
|
17
|
+
const marker = ${JSON.stringify(path.join(root, 'tick'))};
|
|
18
|
+
let tick = 0; try { tick = Number(await readFile(marker, 'utf8')); } catch {}
|
|
19
|
+
await writeFile(marker, String(tick + 1));
|
|
20
|
+
const n = Number(schema.checkpoint_id.slice(2));
|
|
21
|
+
const write = (fields) => writeFile(path.join(process.env.LOOP_CHECKPOINTS_DIR, schema.checkpoint_id + '.json'), JSON.stringify({
|
|
22
|
+
task_id: plan.task_id, checkpoint_id: schema.checkpoint_id, milestone_id: schema.milestone_id,
|
|
23
|
+
revises_checkpoint_id: schema.revises_checkpoint_id, sequence: n, created_at: new Date(Date.UTC(2026, 0, n)).toISOString(),
|
|
24
|
+
summary: 'work', files_changed: [], verification: ['npm test passed (' + schema.checkpoint_id + ')'], blockers: [], risks: [], deferred_gates: [], ...fields }));
|
|
25
|
+
${body}`);
|
|
26
|
+
return { queue: 'regress', dispatcher: `node '${worker}'`, checkpointPollMs: 0, progressHeartbeatMs: 0 };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const roots = [];
|
|
30
|
+
try {
|
|
31
|
+
// A bounded task revised once along the template is accepted; before, the
|
|
32
|
+
// revision got a new milestone id and the first review stayed live.
|
|
33
|
+
{
|
|
34
|
+
const root = await mkdtemp(path.join(tmpdir(), 'loop-continuation-revise-')); roots.push(root);
|
|
35
|
+
const { task } = await enqueueTask(root, { queue: 'regress', title: 'fix bug', task: 'Fix the login redirect bug in the auth module.' });
|
|
36
|
+
const options = await templateWorker(root, `await write({ status: tick === 0 ? 'in_progress' : 'ready_for_acceptance' });`);
|
|
37
|
+
const first = await runQueueOnce(root, options);
|
|
38
|
+
assert.equal(first.run.finalJudgement.outcome, 'needs_revision');
|
|
39
|
+
await queueRequeue(root, 'regress', task.id);
|
|
40
|
+
const second = await runQueueOnce(root, options);
|
|
41
|
+
assert.notEqual(second.run.finalJudgement.outcome, 'needs_revision', JSON.stringify(second.run.finalJudgement.reasons));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// A project interrupted after writing an accepted checkpoint continues
|
|
45
|
+
// after recovery instead of failing as "no progress" or "not covered".
|
|
46
|
+
{
|
|
47
|
+
const root = await mkdtemp(path.join(tmpdir(), 'loop-continuation-recover-')); roots.push(root);
|
|
48
|
+
await enqueueTask(root, { queue: 'regress', title: 'project', task: '开发完整项目并完成整体目标' });
|
|
49
|
+
const options = await templateWorker(root, `if (tick === 2) process.exit(0);
|
|
50
|
+
await write({ status: 'ready_for_acceptance', project_completion: { status: 'in_progress' } });
|
|
51
|
+
if (tick === 1) { console.error('gateway is draining for restart'); process.exit(1); }`);
|
|
52
|
+
const statuses = [];
|
|
53
|
+
for (let i = 0; i < 4; i += 1) statuses.push((await runQueueOnce(root, options)).run?.status ?? 'not_processed');
|
|
54
|
+
assert.deepEqual(statuses, ['project_in_progress', 'runtime_interrupted', 'project_in_progress', 'project_in_progress']);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Checkpoints written by the 0.16.1-0.16.4 template carry a new milestone
|
|
58
|
+
// id per revision; an explicit revises_checkpoint_id keeps them one chain,
|
|
59
|
+
// so a resolved historical blocker does not veto the accepted revision.
|
|
60
|
+
{
|
|
61
|
+
const contract = { task_id: 't', task_scope: 'scoped_task', requires_human_gate: false };
|
|
62
|
+
const reviews = { reviews: [
|
|
63
|
+
{ checkpointId: 'cp1', milestoneId: 'cp1', sequence: 1, checkpointCreatedAt: '2026-01-01T00:00:00Z', status: 'blocked' },
|
|
64
|
+
{ checkpointId: 'cp2', milestoneId: 'cp2', revisesCheckpointId: 'cp1', sequence: 2, checkpointCreatedAt: '2026-01-02T00:00:00Z', status: 'accepted', taskTerminal: true }
|
|
65
|
+
] };
|
|
66
|
+
const judgement = buildFinalJudgement(contract, { rubric: [], automation: [] }, { checkpoints: [{ id: 'cp2' }] }, { count: 2 }, reviews, { dispatchStatus: 'completed' });
|
|
67
|
+
assert.equal(judgement.outcome, 'ready_to_apply');
|
|
68
|
+
assert.deepEqual(judgement.coverage.effective_review_ids, ['cp2']);
|
|
69
|
+
// Without the revision link a different milestone's blocker stays live.
|
|
70
|
+
const unlinked = { reviews: [reviews.reviews[0], { ...reviews.reviews[1], revisesCheckpointId: null }] };
|
|
71
|
+
assert.equal(buildFinalJudgement(contract, { rubric: [], automation: [] }, { checkpoints: [{ id: 'cp2' }] }, { count: 2 }, unlinked, { dispatchStatus: 'completed' }).outcome, 'blocked');
|
|
72
|
+
}
|
|
73
|
+
// Context handoffs: capped, blockers surfaced, and never stale.
|
|
74
|
+
{
|
|
75
|
+
const handoffWorker = async (root, extra) => {
|
|
76
|
+
const worker = path.join(root, 'handoff-worker.mjs');
|
|
77
|
+
await writeFile(worker, `import { mkdir, writeFile } from 'node:fs/promises';
|
|
78
|
+
import path from 'node:path';
|
|
79
|
+
const e = process.env;
|
|
80
|
+
await mkdir(e.LOOP_CHECKPOINTS_DIR, { recursive: true });
|
|
81
|
+
const checkpoint = path.join(e.LOOP_CHECKPOINTS_DIR, e.LOOP_RUN_ID + '.json');
|
|
82
|
+
await writeFile(checkpoint, JSON.stringify({ task_id: e.LOOP_TASK_ID, loop_run_id: e.LOOP_RUN_ID, checkpoint_id: e.LOOP_RUN_ID, status: 'in_progress', summary: 'still working', blockers: [], verification: [{ command: 'npm test', outcome: 'failed', log: e.LOOP_WORKER_OUTPUT_PREFIX + '.stdout.log' }], risks: [], next_action: 'continue' }));
|
|
83
|
+
const handoff = { version: 1, taskId: e.LOOP_TASK_ID, runId: e.LOOP_RUN_ID, generation: Number(e.LOOP_SESSION_GENERATION), attempt: Number(e.LOOP_ATTEMPT), reason: 'context_budget', checkpoint, summary: 's', completed: [], remaining: ['fix tests'], evidence: [checkpoint], nextAction: 'fix', authority: 'local', pendingActions: [], blockers: [] };
|
|
84
|
+
${extra}
|
|
85
|
+
await writeFile(e.LOOP_CONTEXT_HANDOFF_FILE, JSON.stringify(handoff));
|
|
86
|
+
`);
|
|
87
|
+
return { queue: 'regress', dispatcher: `node '${worker}'`, retry: { maxAttempts: 1, runtimeRecoveryMaxAttempts: 2, maxContextHandoffs: 3 }, checkpointPollMs: 0, progressHeartbeatMs: 0 };
|
|
88
|
+
};
|
|
89
|
+
// A worker whose evidence differs every turn (a run-specific log path)
|
|
90
|
+
// still stops after maxContextHandoffs instead of looping forever.
|
|
91
|
+
{
|
|
92
|
+
const root = await mkdtemp(path.join(tmpdir(), 'loop-continuation-handoff-loop-')); roots.push(root);
|
|
93
|
+
await enqueueTask(root, { queue: 'regress', title: 't', task: 'Fix the failing test.' });
|
|
94
|
+
const options = await handoffWorker(root, '');
|
|
95
|
+
const statuses = [];
|
|
96
|
+
for (let i = 0; i < 6; i += 1) {
|
|
97
|
+
const result = await runQueueOnce(root, options);
|
|
98
|
+
if (!result.processed) break;
|
|
99
|
+
statuses.push(result.status);
|
|
100
|
+
}
|
|
101
|
+
assert.deepEqual(statuses, ['runtime_interrupted', 'runtime_interrupted', 'runtime_interrupted', 'runtime_blocked']);
|
|
102
|
+
}
|
|
103
|
+
// Handoff blockers and pending external actions reach the human.
|
|
104
|
+
{
|
|
105
|
+
const root = await mkdtemp(path.join(tmpdir(), 'loop-continuation-handoff-blocker-')); roots.push(root);
|
|
106
|
+
await enqueueTask(root, { queue: 'regress', title: 't', task: 'Fix the failing test.', sourceChannel: 'telegram', sourceTarget: '1' });
|
|
107
|
+
const options = await handoffWorker(root, "handoff.blockers = ['NEED_PROD_DB_PASSWORD']; handoff.pendingActions = ['payment request 42'];");
|
|
108
|
+
const result = await runQueueOnce(root, options);
|
|
109
|
+
assert.equal(result.status, 'needs_human_input');
|
|
110
|
+
const judgement = JSON.parse(await readFile(path.join(root, result.run.finalJudgement.path), 'utf8'));
|
|
111
|
+
assert.match(judgement.reasons.join(' '), /NEED_PROD_DB_PASSWORD/);
|
|
112
|
+
assert.match(judgement.next_actions[0], /payment request 42/);
|
|
113
|
+
const notice = await notifyTerminalTasks(root, { queue: 'regress', dryRun: true });
|
|
114
|
+
assert.match(notice.results[0].message, /NEED_PROD_DB_PASSWORD/);
|
|
115
|
+
assert.match(notice.results[0].message, /payment request 42/);
|
|
116
|
+
}
|
|
117
|
+
// A later session is not pointed at an earlier session's handoff.
|
|
118
|
+
{
|
|
119
|
+
const root = await mkdtemp(path.join(tmpdir(), 'loop-continuation-handoff-stale-')); roots.push(root);
|
|
120
|
+
const { task } = await enqueueTask(root, { queue: 'regress', title: 't', task: 'Fix the failing test.' });
|
|
121
|
+
const options = await handoffWorker(root, "if (Number(e.LOOP_SESSION_GENERATION) > 0) { console.error('maximum context length exceeded'); process.exit(1); }");
|
|
122
|
+
await runQueueOnce(root, options);
|
|
123
|
+
await runQueueOnce(root, options);
|
|
124
|
+
const inbox = JSON.parse(await readFile(path.join(root, 'runtime/loops/regress/inbox', `${task.id}.json`), 'utf8'));
|
|
125
|
+
assert.equal(inbox.contextHandoffFile, undefined, 'a run without a handoff clears the previous one');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Scope inference: ordinary words containing 不/别 and temporal "after the
|
|
130
|
+
// first step" are not bounded-scope negations or cues.
|
|
131
|
+
for (const [body, expected] of [
|
|
132
|
+
['继续整体项目,特别要求只处理第 3 项', 'scoped_task'],
|
|
133
|
+
['继续整体项目:在不同模块中只处理第 2 项', 'scoped_task'],
|
|
134
|
+
['Continue the project-level plan: no UI changes needed - only complete backlog item 2', 'scoped_task'],
|
|
135
|
+
['Continue the project-level work. Without network access complete backlog item 2', 'scoped_task'],
|
|
136
|
+
['项目级任务:完成第一步之后不要停,继续完成完整项目', 'project'],
|
|
137
|
+
['继续整体项目,不要只处理第 3 项', 'project'],
|
|
138
|
+
['完成完整项目,不仅是有界里程碑,而且不是仅完成第一步', 'project']
|
|
139
|
+
]) assert.equal(inferTaskScope({ body }), expected, body);
|
|
140
|
+
|
|
141
|
+
// Malformed coverage evidence and id collisions do not crash or overcount.
|
|
142
|
+
{
|
|
143
|
+
const contract = { task_id: 't', task_scope: 'scoped_task', requires_human_gate: false };
|
|
144
|
+
const plan = { checkpoints: [{ id: 'cp1' }, { id: 'cp2' }] };
|
|
145
|
+
const collision = { reviews: [
|
|
146
|
+
{ checkpointId: 'cp1', milestoneId: 'cp1', sequence: 1, checkpointCreatedAt: '2026-01-01T00:00:00Z', status: 'revise' },
|
|
147
|
+
{ checkpointId: 'cp2', milestoneId: 'cp1', revisesCheckpointId: 'cp1', sequence: 2, checkpointCreatedAt: '2026-01-02T00:00:00Z', status: 'accepted' }
|
|
148
|
+
] };
|
|
149
|
+
const judged = buildFinalJudgement(contract, { rubric: [], automation: [] }, plan, { count: 2 }, collision, { dispatchStatus: 'completed' });
|
|
150
|
+
assert.equal(judged.outcome, 'needs_revision', 'one review cannot cover two milestones');
|
|
151
|
+
const malformed = { reviews: [
|
|
152
|
+
{ checkpointId: 'cp1', milestoneId: 'cp1', taskId: 't', sequence: 1, status: 'revise', phaseOnly: true, checkpointDigest: 'a'.repeat(64) },
|
|
153
|
+
{ checkpointId: 'cp2', milestoneId: 'cp1', taskId: 't', sequence: 2, status: 'accepted', verification: { commands: ['npm test'] },
|
|
154
|
+
revisionCoverage: [{ checkpoint_id: 'cp1', checkpoint_sha256: 'a'.repeat(64), resolution: 'fixed', verification: ['npm test'] }] }
|
|
155
|
+
] };
|
|
156
|
+
assert.doesNotThrow(() => buildFinalJudgement(contract, { rubric: [], automation: [] }, { checkpoints: [{ id: 'cp1' }] }, { count: 2 }, malformed, { dispatchStatus: 'completed' }));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// An unreadable gate checkpoint does not stop the queue.
|
|
160
|
+
{
|
|
161
|
+
const root = await mkdtemp(path.join(tmpdir(), 'loop-continuation-gate-')); roots.push(root);
|
|
162
|
+
const gates = path.join(root, 'runtime/loops/regress/human-input/gates');
|
|
163
|
+
await mkdir(gates, { recursive: true });
|
|
164
|
+
await writeJson(path.join(gates, 'broken.json'), { gate_id: 'broken', status: 'waiting_for_human', task_id: 'ghost', checkpoint_id: 'cp1', project_id: 'p' });
|
|
165
|
+
await mkdir(path.join(root, 'runtime/loops/regress/tasks/ghost/checkpoints'), { recursive: true });
|
|
166
|
+
await writeFile(path.join(root, 'runtime/loops/regress/tasks/ghost/checkpoints/cp1.json'), '{"truncated');
|
|
167
|
+
await enqueueTask(root, { queue: 'regress', title: 'healthy', task: 'Fix the login redirect bug.' });
|
|
168
|
+
const result = await runQueueOnce(root, { queue: 'regress', dispatcher: 'true', checkpointPollMs: 0, progressHeartbeatMs: 0 });
|
|
169
|
+
assert.equal(result.processed, true);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
console.log('continuation regression self-test passed');
|
|
173
|
+
} finally {
|
|
174
|
+
for (const root of roots) await rm(root, { recursive: true, force: true });
|
|
175
|
+
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
|
-
import {
|
|
2
|
+
import { mkdtemp, mkdir, readFile, rm, utimes, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { enqueueTask, queueRequeue, runQueueOnce, buildFinalJudgement, dispatchFailureClassification, inferTaskScope, refreshTaskAcceptance, selectEffectiveAcceptanceReviews, writeAcceptancePlan, writeDevPlan, writeTaskContract } from '../lib/core.mjs';
|
|
3
6
|
|
|
4
7
|
const basePlan = { rubric: [], automation: [] };
|
|
5
8
|
const baseContract = { task_id: 't1', risk_level: 'L1', requires_human_gate: false, task_scope: 'scoped_task' };
|
|
6
9
|
|
|
7
10
|
assert.equal(inferTaskScope({ body: '开发完整项目并完成整体目标' }), 'project');
|
|
11
|
+
assert.equal(inferTaskScope({ body: '承接项目并先开始首个批次', taskScope: 'project' }), 'project');
|
|
12
|
+
assert.equal(inferTaskScope({ body: '开发完整项目并完成整体目标', taskScope: 'scoped_task' }), 'scoped_task');
|
|
13
|
+
assert.equal(inferTaskScope({ body: '开发完整项目并完成整体目标', taskScope: 'invalid' }), 'project');
|
|
8
14
|
assert.equal(inferTaskScope({ body: '继续同一整体项目,仅推进 T-01 第 2 项;阶段完成后不能称整体项目完成' }), 'scoped_task');
|
|
9
15
|
assert.equal(inferTaskScope({ body: 'Continue the project, only complete boundary item 2' }), 'scoped_task');
|
|
10
16
|
assert.equal(inferTaskScope({ body: '继续同一整体项目,取消团队功能并从项目完成门槛中移除,其他 backlog 不变' }), 'scoped_task');
|
|
@@ -12,6 +18,113 @@ assert.equal(inferTaskScope({ body: 'Continue the overall project with a product
|
|
|
12
18
|
assert.equal(inferTaskScope({ body: '把外部证据列为项目级 deferred gates。本轮作为有界本地工程里程碑,完成 TECH-01030;不宣称整体项目完成。' }), 'scoped_task');
|
|
13
19
|
assert.equal(inferTaskScope({ body: 'Project-level evidence remains deferred; this round is a bounded local engineering milestone.' }), 'scoped_task');
|
|
14
20
|
|
|
21
|
+
for (const explicitScope of [true, false]) {
|
|
22
|
+
const root = await mkdtemp(path.join(tmpdir(), 'loop-project-plan-'));
|
|
23
|
+
try {
|
|
24
|
+
const task = {
|
|
25
|
+
id: 'project-scope-probe', title: 'First batch',
|
|
26
|
+
body: '开发完整项目并完成整体目标', queue: 'agent-tasks',
|
|
27
|
+
...(explicitScope ? { taskScope: 'project' } : {}), projectId: 'probe', riskAssessment: 'model_assessed'
|
|
28
|
+
};
|
|
29
|
+
const dir = path.join(root, 'runtime/loops/agent-tasks/tasks', task.id);
|
|
30
|
+
await mkdir(path.join(dir, 'checkpoints'), { recursive: true });
|
|
31
|
+
await writeFile(path.join(dir, 'checkpoints/cp1.json'), '{}\n');
|
|
32
|
+
await writeFile(path.join(dir, 'task_contract.json'), JSON.stringify({
|
|
33
|
+
task_id: task.id, task_scope: 'project',
|
|
34
|
+
deliverables: ['preserved-project-deliverable'],
|
|
35
|
+
acceptance_summary: 'preserved-project-acceptance'
|
|
36
|
+
}));
|
|
37
|
+
await writeFile(path.join(dir, 'acceptance_plan.json'), JSON.stringify({
|
|
38
|
+
task_id: task.id,
|
|
39
|
+
generated_by: 'project_scope_worker_revision_after_deterministic_planner_v1',
|
|
40
|
+
functional_checks: ['preserved-project-check'],
|
|
41
|
+
regression_checks: [], negative_tests: [], manual_review: [], automation: [], rubric: []
|
|
42
|
+
}));
|
|
43
|
+
await writeFile(path.join(dir, 'dev_plan.json'), JSON.stringify({
|
|
44
|
+
task_id: task.id,
|
|
45
|
+
generated_by: 'project_scope_worker_revision_after_deterministic_planner_v1',
|
|
46
|
+
approach: 'preserved-project-approach',
|
|
47
|
+
checkpoints: [{ id: 'cp1', goal: 'preserved milestone', output_file: 'checkpoints/cp1.json' }]
|
|
48
|
+
}));
|
|
49
|
+
const contract = await writeTaskContract(root, 'agent-tasks', task, {
|
|
50
|
+
projectAuthorization: { project: 'probe', source: 'test',
|
|
51
|
+
production_authorized: false, paid_action_authorized: false }
|
|
52
|
+
});
|
|
53
|
+
const acceptance = await writeAcceptancePlan(root, 'agent-tasks', task, contract);
|
|
54
|
+
const dev = await writeDevPlan(root, 'agent-tasks', task, contract, acceptance);
|
|
55
|
+
assert.equal(contract.contract.task_scope, 'project');
|
|
56
|
+
assert.deepEqual(contract.contract.deliverables, ['preserved-project-deliverable']);
|
|
57
|
+
assert.deepEqual(acceptance.plan.functional_checks, ['preserved-project-check']);
|
|
58
|
+
assert.deepEqual(dev.plan.checkpoints.map((entry) => entry.id), ['cp1']);
|
|
59
|
+
assert.equal(dev.plan.approach, 'preserved-project-approach');
|
|
60
|
+
assert.equal(dev.plan.checkpoint_schema.checkpoint_id, 'cp2');
|
|
61
|
+
const acceptedReviews = { reviews: [{ checkpointId: 'cp1', sequence: 1, status: 'accepted', projectCompletion: { status: 'in_progress' } }] };
|
|
62
|
+
assert.equal(buildFinalJudgement(contract.contract, acceptance.plan, dev.plan, { count: 1 }, acceptedReviews, { dispatchStatus: 'completed' }).outcome, 'project_in_progress');
|
|
63
|
+
const noProgress = buildFinalJudgement(contract.contract, acceptance.plan, dev.plan, { count: 1 }, acceptedReviews, { dispatchStatus: 'completed', priorCheckpointCount: 1 });
|
|
64
|
+
assert.equal(noProgress.outcome, 'needs_revision');
|
|
65
|
+
assert.equal(noProgress.no_progress_continuation, true);
|
|
66
|
+
assert.match(noProgress.reasons[0], /no new committed and accepted milestone/);
|
|
67
|
+
assert.equal(buildFinalJudgement(contract.contract, acceptance.plan, dev.plan, { count: 1 }, acceptedReviews, { dispatchStatus: 'completed', priorCheckpointCount: 0 }).outcome, 'project_in_progress');
|
|
68
|
+
|
|
69
|
+
const repairedPlan = { checkpoints: [{ id: 'cp1' }, { id: 'cp2' }] };
|
|
70
|
+
const repairedReviews = { reviews: [
|
|
71
|
+
{ checkpointId: 'cp1', sequence: 1, status: 'accepted' },
|
|
72
|
+
{ checkpointId: 'cp2', sequence: 2, status: 'revise' },
|
|
73
|
+
{ checkpointId: 'cp3', milestoneId: 'cp2', sequence: 3, status: 'accepted', projectCompletion: { status: 'in_progress' } }
|
|
74
|
+
] };
|
|
75
|
+
const repairContext = { dispatchStatus: 'completed', priorCheckpointCount: 2, priorPlannedCheckpointCount: 2, priorAcceptedMilestoneIds: ['cp1'] };
|
|
76
|
+
assert.equal(buildFinalJudgement(contract.contract, basePlan, repairedPlan, { count: 3 }, repairedReviews, repairContext).outcome, 'project_in_progress');
|
|
77
|
+
// Re-emitting already accepted work is not progress, even with a new file.
|
|
78
|
+
assert.equal(buildFinalJudgement(contract.contract, basePlan, repairedPlan, { count: 3 }, repairedReviews, { ...repairContext, priorAcceptedMilestoneIds: ['cp1', 'cp2'] }).outcome, 'needs_revision');
|
|
79
|
+
// In-place repair also advances acceptance without increasing file count.
|
|
80
|
+
assert.equal(buildFinalJudgement(contract.contract, basePlan, repairedPlan, { count: 2 }, repairedReviews, repairContext).outcome, 'project_in_progress');
|
|
81
|
+
const completedReviews = { reviews: [{ checkpointId: 'cp1', sequence: 1, status: 'accepted', projectCompletion: { status: 'accepted' } }] };
|
|
82
|
+
assert.notEqual(buildFinalJudgement(contract.contract, acceptance.plan, dev.plan, { count: 1 }, completedReviews, { dispatchStatus: 'completed', priorCheckpointCount: 1 }).outcome, 'needs_revision');
|
|
83
|
+
const committedMissing = { ...dev.plan, checkpoints: [...dev.plan.checkpoints, { id: 'cp2', goal: 'specific committed batch', output_file: 'checkpoints/cp2.json' }] };
|
|
84
|
+
assert.equal(buildFinalJudgement(contract.contract, acceptance.plan, committedMissing, { count: 1 }, acceptedReviews, { dispatchStatus: 'completed' }).outcome, 'needs_revision');
|
|
85
|
+
const accepted170 = Array.from({ length: 170 }, (_, index) => ({ id: `cp${index + 1}`, goal: `bounded batch ${index + 1}` }));
|
|
86
|
+
const reviews170 = { reviews: accepted170.map((entry, index) => ({ checkpointId: entry.id, sequence: index + 1, status: 'accepted', projectCompletion: { status: 'in_progress' } })) };
|
|
87
|
+
const exact170 = { ...dev.plan, checkpoints: accepted170 };
|
|
88
|
+
assert.equal(buildFinalJudgement(contract.contract, acceptance.plan, exact170, { count: 170 }, reviews170, { dispatchStatus: 'completed' }).outcome, 'project_in_progress');
|
|
89
|
+
assert.equal(buildFinalJudgement(contract.contract, acceptance.plan, exact170, { count: 170 }, reviews170, { dispatchStatus: 'completed', priorCheckpointCount: 170 }).outcome, 'needs_revision');
|
|
90
|
+
assert.equal(buildFinalJudgement(contract.contract, acceptance.plan, exact170, { count: 171 }, reviews170, { dispatchStatus: 'completed', priorCheckpointCount: 170, priorPlannedCheckpointCount: 170, priorAcceptedMilestoneIds: accepted170.map(cp => cp.id) }).outcome, 'needs_revision');
|
|
91
|
+
const progressed171 = { ...exact170, checkpoints: [...accepted170, { id: 'cp171', goal: 'selected batch' }] };
|
|
92
|
+
const accepted171 = { reviews: [...reviews170.reviews, { checkpointId: 'cp171', sequence: 171, status: 'accepted', projectCompletion: { status: 'in_progress' } }] };
|
|
93
|
+
assert.equal(buildFinalJudgement(contract.contract, acceptance.plan, progressed171, { count: 171 }, accepted171, { dispatchStatus: 'completed', priorCheckpointCount: 170 }).outcome, 'project_in_progress');
|
|
94
|
+
assert.equal(buildFinalJudgement(contract.contract, acceptance.plan, progressed171, { count: 171 }, accepted171, { dispatchStatus: 'completed', priorCheckpointCount: 170, priorPlannedCheckpointCount: 170 }).outcome, 'project_in_progress');
|
|
95
|
+
assert.equal(buildFinalJudgement(contract.contract, acceptance.plan, progressed171, { count: 171 }, accepted171, { dispatchStatus: 'completed', priorCheckpointCount: 170, priorPlannedCheckpointCount: 171 }).outcome, 'project_in_progress');
|
|
96
|
+
assert.equal(buildFinalJudgement(contract.contract, acceptance.plan, { ...exact170, checkpoints: [...accepted170, { id: 'cp171', goal: 'unexecuted placeholder' }] }, { count: 170 }, reviews170, { dispatchStatus: 'completed' }).outcome, 'needs_revision');
|
|
97
|
+
await writeFile(path.join(dir, 'checkpoints/cp1.json'), JSON.stringify({
|
|
98
|
+
task_id: task.id, checkpoint_id: 'cp1', status: 'ready_for_acceptance', summary: 'Accepted local slice',
|
|
99
|
+
files_changed: [], verification: ['focused test passed'], blockers: [], risks: [],
|
|
100
|
+
project_completion: { status: 'in_progress' }
|
|
101
|
+
}));
|
|
102
|
+
await mkdir(path.join(root, 'runtime/loops/agent-tasks/failed'), { recursive: true });
|
|
103
|
+
await writeFile(path.join(root, 'runtime/loops/agent-tasks/failed', `${task.id}.json`), JSON.stringify({ ...task, status: 'needs_revision' }));
|
|
104
|
+
await writeFile(path.join(dir, 'final_judgement.json'), JSON.stringify(noProgress));
|
|
105
|
+
await writeFile(path.join(dir, 'dev_plan.json'), JSON.stringify(dev.plan));
|
|
106
|
+
const newer = new Date(Date.now() + 2000);
|
|
107
|
+
await utimes(path.join(dir, 'dev_plan.json'), newer, newer);
|
|
108
|
+
const refreshed = await refreshTaskAcceptance(root, { queue: 'agent-tasks', taskId: task.id });
|
|
109
|
+
assert.equal(refreshed.status, 'needs_revision');
|
|
110
|
+
assert.equal(JSON.parse(await readFile(path.join(dir, 'final_judgement.json'), 'utf8')).no_progress_continuation, true);
|
|
111
|
+
await writeFile(path.join(dir, 'checkpoints/cp2.json'), JSON.stringify({
|
|
112
|
+
task_id: task.id, checkpoint_id: 'cp2', status: 'ready_for_acceptance', summary: 'Selected next batch',
|
|
113
|
+
files_changed: [], verification: ['next batch test passed'], blockers: [], risks: [],
|
|
114
|
+
project_completion: { status: 'in_progress' }
|
|
115
|
+
}));
|
|
116
|
+
await writeFile(path.join(dir, 'dev_plan.json'), JSON.stringify({
|
|
117
|
+
...dev.plan, checkpoints: [...dev.plan.checkpoints, { id: 'cp2', goal: 'Selected next batch', output_file: 'checkpoints/cp2.json' }]
|
|
118
|
+
}));
|
|
119
|
+
const latest = new Date(Date.now() + 4000);
|
|
120
|
+
await utimes(path.join(dir, 'dev_plan.json'), latest, latest);
|
|
121
|
+
const resumed = await refreshTaskAcceptance(root, { queue: 'agent-tasks', taskId: task.id });
|
|
122
|
+
assert.equal(resumed.status, 'project_in_progress');
|
|
123
|
+
} finally {
|
|
124
|
+
await rm(root, { recursive: true, force: true });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
15
128
|
{
|
|
16
129
|
const devPlan = { checkpoints: [{ id: 'cp1' }] };
|
|
17
130
|
const reviews = {
|
|
@@ -773,3 +886,132 @@ for (const [body, expected] of [
|
|
|
773
886
|
"project"
|
|
774
887
|
]
|
|
775
888
|
]) assert.equal(inferTaskScope({ body }), expected, body);
|
|
889
|
+
|
|
890
|
+
// Plan labels cannot transfer accepted evidence to a different milestone.
|
|
891
|
+
for (const oldAccepted of [['cp1'], []]) {
|
|
892
|
+
for (const renamedId of ['cp1-renamed', 'cp1-renamed-again', 'cp1-third-name']) {
|
|
893
|
+
const result = buildFinalJudgement(
|
|
894
|
+
{ ...baseContract, task_scope: 'project' }, basePlan,
|
|
895
|
+
{ checkpoints: [{ id: renamedId }] }, { count: 1 },
|
|
896
|
+
{ reviews: [{ checkpointId: 'cp1', milestoneId: 'cp1', sequence: 1, status: 'accepted', projectCompletion: { status: 'in_progress' } }] },
|
|
897
|
+
{ dispatchStatus: 'completed', priorCheckpointCount: 1, priorAcceptedMilestoneIds: oldAccepted }
|
|
898
|
+
);
|
|
899
|
+
assert.equal(result.outcome, 'needs_revision', 'plan-only rename: ' + renamedId);
|
|
900
|
+
assert.equal(result.no_progress_continuation, true);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// A real queue must stop the renaming worker and never replay it on later ticks.
|
|
905
|
+
{
|
|
906
|
+
const root = await mkdtemp(path.join(tmpdir(), 'loop-rename-queue-'));
|
|
907
|
+
try {
|
|
908
|
+
const { task } = await enqueueTask(root, { queue: 'probe', title: 'rename-only', task: '开发完整项目并完成整体目标' });
|
|
909
|
+
const dir = path.join(root, 'runtime/loops/probe/tasks', task.id);
|
|
910
|
+
await mkdir(path.join(dir, 'checkpoints'), { recursive: true });
|
|
911
|
+
const cp = JSON.stringify({ task_id: task.id, checkpoint_id: 'cp1', milestone_id: 'cp1', sequence: 1, status: 'ready_for_acceptance', summary: 'Accepted local work', verification: ['passed'], blockers: [], risks: [], project_completion: { status: 'in_progress' } });
|
|
912
|
+
await writeFile(path.join(dir, 'checkpoints/cp1.json'), cp);
|
|
913
|
+
await writeFile(path.join(dir, 'dev_plan.json'), JSON.stringify({ task_id: task.id, generated_by: 'project_scope_worker_revision_after_deterministic_planner_v1', checkpoints: [{ id: 'cp1' }] }));
|
|
914
|
+
await writeFile(path.join(dir, 'acceptance_plan.json'), JSON.stringify({ task_id: task.id, generated_by: 'project_scope_worker_revision_after_deterministic_planner_v1', functional_checks: [], regression_checks: [], negative_tests: [], edge_cases: [], manual_review: [], automation: [], rubric: [] }));
|
|
915
|
+
const worker = path.join(root, 'worker.mjs');
|
|
916
|
+
await writeFile(worker, `import { readFile, writeFile, appendFile } from 'node:fs/promises';
|
|
917
|
+
const file = ${JSON.stringify(path.join(dir, 'dev_plan.json'))};
|
|
918
|
+
const p = JSON.parse(await readFile(file, 'utf8')); p.checkpoints[0].id += '-renamed';
|
|
919
|
+
await writeFile(file, JSON.stringify(p));
|
|
920
|
+
await appendFile(${JSON.stringify(path.join(root, 'dispatches'))}, 'dispatch\\n');`);
|
|
921
|
+
const options = { queue: 'probe', dispatcher: `node '${worker}'`, checkpointPollMs: 0, progressHeartbeatMs: 0 };
|
|
922
|
+
assert.equal((await runQueueOnce(root, options)).run.finalJudgement.outcome, 'needs_revision');
|
|
923
|
+
for (let tick = 0; tick < 3; tick++) assert.equal((await runQueueOnce(root, options)).processed, false);
|
|
924
|
+
assert.equal(await readFile(path.join(root, 'dispatches'), 'utf8'), 'dispatch\n');
|
|
925
|
+
assert.equal(await readFile(path.join(dir, 'checkpoints/cp1.json'), 'utf8'), cp);
|
|
926
|
+
} finally {
|
|
927
|
+
await rm(root, { recursive: true, force: true });
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// Exercise the dispatch-time baseline through real disposable queue runs.
|
|
932
|
+
for (const plannedCount of [1, 2]) for (const scenario of ['repair', 'in-place', 'duplicate', 'empty', 'blocked']) {
|
|
933
|
+
const root = await mkdtemp(path.join(tmpdir(), 'loop-progress-queue-'));
|
|
934
|
+
try {
|
|
935
|
+
const { task } = await enqueueTask(root, { queue: 'probe', title: scenario, task: '开发完整项目并完成整体目标' });
|
|
936
|
+
const dir = path.join(root, 'runtime/loops/probe/tasks', task.id);
|
|
937
|
+
await mkdir(path.join(dir, 'checkpoints'), { recursive: true });
|
|
938
|
+
const checkpoint = (id, sequence, status) => ({ task_id: task.id, checkpoint_id: id, milestone_id: id, sequence, status, summary: 'Local validation', files_changed: [], verification: ['passed'], blockers: [], risks: [], project_completion: { status: 'in_progress' } });
|
|
939
|
+
if (plannedCount === 2) await writeFile(path.join(dir, 'checkpoints/cp1.json'), JSON.stringify(checkpoint('cp1', 1, 'ready_for_acceptance')));
|
|
940
|
+
await writeFile(path.join(dir, 'checkpoints/cp2.json'), JSON.stringify(checkpoint('cp2', 2, ['repair', 'in-place', 'blocked'].includes(scenario) ? 'in_progress' : 'ready_for_acceptance')));
|
|
941
|
+
await writeFile(path.join(dir, 'dev_plan.json'), JSON.stringify({ task_id: task.id, generated_by: 'project_scope_worker_revision_after_deterministic_planner_v1', checkpoints: plannedCount === 2 ? [{ id: 'cp1' }, { id: 'cp2' }] : [{ id: 'cp2' }] }));
|
|
942
|
+
await writeFile(path.join(dir, 'acceptance_plan.json'), JSON.stringify({ task_id: task.id, generated_by: 'project_scope_worker_revision_after_deterministic_planner_v1', functional_checks: [], regression_checks: [], negative_tests: [], edge_cases: [], manual_review: [], automation: [], rubric: [] }));
|
|
943
|
+
const worker = path.join(root, 'worker.mjs');
|
|
944
|
+
const cp = { ...checkpoint(scenario === 'in-place' ? 'cp2' : 'cp3', 3, scenario === 'blocked' ? 'blocked' : 'ready_for_acceptance'), milestone_id: 'cp2', revises_checkpoint_id: 'cp2', blockers: scenario === 'blocked' ? ['Need human approval'] : [] };
|
|
945
|
+
await writeFile(worker, `import { writeFile } from 'node:fs/promises';
|
|
946
|
+
import path from 'node:path';
|
|
947
|
+
if (${JSON.stringify(scenario)} !== 'empty') await writeFile(path.join(process.env.LOOP_CHECKPOINTS_DIR, ${JSON.stringify(cp.checkpoint_id + '.json')}), ${JSON.stringify(JSON.stringify(cp))});`);
|
|
948
|
+
const options = { queue: 'probe', dispatcher: `node '${worker}'`, checkpointPollMs: 0, progressHeartbeatMs: 0 };
|
|
949
|
+
const result = await runQueueOnce(root, options);
|
|
950
|
+
const expected = ['repair', 'in-place'].includes(scenario) ? 'project_in_progress' : scenario === 'blocked' ? 'blocked' : 'needs_revision';
|
|
951
|
+
assert.equal(result.run.finalJudgement.outcome, expected, scenario + JSON.stringify(result.run.finalJudgement));
|
|
952
|
+
if (expected === 'project_in_progress') {
|
|
953
|
+
const second = await runQueueOnce(root, options);
|
|
954
|
+
assert.equal(second.run.finalJudgement.outcome, 'needs_revision', 'repeated accepted milestone must stop');
|
|
955
|
+
} else {
|
|
956
|
+
assert.equal((await runQueueOnce(root, options)).processed, false, 'no automatic replay');
|
|
957
|
+
}
|
|
958
|
+
} finally {
|
|
959
|
+
await rm(root, { recursive: true, force: true });
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
console.log('project continuation queue regressions passed');
|
|
963
|
+
|
|
964
|
+
// Invalid history is an unknown baseline, not empty accepted coverage. Permit
|
|
965
|
+
// one repairing dispatch, then stop for explicit revision even if it repairs.
|
|
966
|
+
for (const scenario of ['repair', 'unchanged', 'new-terminal', 'blocked', 'invalid-shape', 'shape-unchanged']) {
|
|
967
|
+
const root = await mkdtemp(path.join(tmpdir(), 'loop-invalid-baseline-'));
|
|
968
|
+
try {
|
|
969
|
+
const { task } = await enqueueTask(root, { queue: 'probe', title: scenario, task: '开发完整项目并完成整体目标' });
|
|
970
|
+
const dir = path.join(root, 'runtime/loops/probe/tasks', task.id);
|
|
971
|
+
await mkdir(path.join(dir, 'checkpoints'), { recursive: true });
|
|
972
|
+
await writeFile(path.join(dir, 'checkpoints/cp1.json'), ['invalid-shape', 'shape-unchanged'].includes(scenario) ? 'null' : '{');
|
|
973
|
+
const cp = { task_id: task.id, checkpoint_id: 'cp1', milestone_id: 'cp1', status: scenario === 'blocked' ? 'blocked' : 'ready_for_acceptance', summary: 'Repair', verification: ['passed'], blockers: scenario === 'blocked' ? ['Need human approval'] : [], risks: [], project_completion: { status: 'in_progress' } };
|
|
974
|
+
const worker = path.join(root, 'worker.mjs');
|
|
975
|
+
const marker = path.join(root, 'worker-ran');
|
|
976
|
+
await writeFile(worker, `import { writeFile } from 'node:fs/promises';
|
|
977
|
+
await writeFile(${JSON.stringify(marker)}, 'yes');
|
|
978
|
+
${['repair', 'blocked', 'invalid-shape'].includes(scenario) ? `await writeFile(${JSON.stringify(path.join(dir, 'checkpoints/cp1.json'))}, ${JSON.stringify(JSON.stringify(cp))});` : ''}
|
|
979
|
+
${scenario === 'new-terminal' ? `await writeFile(${JSON.stringify(path.join(dir, 'checkpoints/cp2.json'))}, ${JSON.stringify(JSON.stringify({ ...cp, checkpoint_id: 'cp2', sequence: 99, project_completion: { status: 'accepted' } }))});` : ''}`);
|
|
980
|
+
// A consumed authorization is still not satisfied by unknown history, even
|
|
981
|
+
// with an apparently valid successor beside the corrupt record.
|
|
982
|
+
const gateFile = path.join(root, 'runtime/loops/probe/human-input/gates/consumed.json');
|
|
983
|
+
const gate = { task_id: task.id, checkpoint_id: 'cp1', status: 'consumed', authorization: { state: 'consumed' } };
|
|
984
|
+
await mkdir(path.dirname(gateFile), { recursive: true });
|
|
985
|
+
await writeFile(gateFile, JSON.stringify(gate));
|
|
986
|
+
const preserveGate = ['unchanged', 'new-terminal', 'shape-unchanged'].includes(scenario);
|
|
987
|
+
if (preserveGate) await writeFile(path.join(dir, 'checkpoints/successor.json'), JSON.stringify({ ...cp, checkpoint_id: 'cp-successor', revises_checkpoint_id: 'cp1', sequence: 2 }));
|
|
988
|
+
const options = { queue: 'probe', dispatcher: `node '${worker}'`, checkpointPollMs: 0, progressHeartbeatMs: 0 };
|
|
989
|
+
const result = await runQueueOnce(root, options);
|
|
990
|
+
if (preserveGate) assert.deepEqual(JSON.parse(await readFile(gateFile, 'utf8')), gate, 'corrupt history must preserve consumed gate byte semantics');
|
|
991
|
+
assert.equal(await readFile(marker, 'utf8'), 'yes', scenario + ': repair worker launches');
|
|
992
|
+
if (result.run.finalJudgement.outcome !== (scenario === 'blocked' ? 'blocked' : 'needs_revision')) console.error(JSON.stringify(result.run));
|
|
993
|
+
assert.equal(result.run.finalJudgement.outcome, scenario === 'blocked' ? 'blocked' : 'needs_revision', scenario);
|
|
994
|
+
assert.equal(JSON.parse(await readFile(path.join(dir, 'final_judgement.json'), 'utf8')).invalid_checkpoint_baseline, true, scenario);
|
|
995
|
+
assert.equal((await runQueueOnce(root, options)).processed, false, 'invalid baseline must not replay');
|
|
996
|
+
await refreshTaskAcceptance(root, { queue: 'probe', taskId: task.id });
|
|
997
|
+
const refreshed = JSON.parse(await readFile(path.join(dir, 'final_judgement.json'), 'utf8'));
|
|
998
|
+
assert.equal(refreshed.outcome, scenario === 'blocked' ? 'blocked' : 'needs_revision', 'refresh retains unknown baseline');
|
|
999
|
+
if (preserveGate) assert.deepEqual(JSON.parse(await readFile(gateFile, 'utf8')), gate, 'refresh must preserve consumed gate');
|
|
1000
|
+
if (scenario === 'repair') {
|
|
1001
|
+
// Explicit operator revision only after validated history: do not erase
|
|
1002
|
+
// the marker by refresh or count repairing JSON as new milestone work.
|
|
1003
|
+
await queueRequeue(root, 'probe', task.id, { from: 'failed' });
|
|
1004
|
+
const terminal = { ...cp, checkpoint_id: 'cp2', revises_checkpoint_id: 'cp1', sequence: 2, summary: 'New verified terminal revision', project_completion: { status: 'accepted' } };
|
|
1005
|
+
await writeFile(worker, `import { writeFile } from 'node:fs/promises'; await writeFile(${JSON.stringify(path.join(dir, 'checkpoints/cp2.json'))}, ${JSON.stringify(JSON.stringify(terminal))});`);
|
|
1006
|
+
const revised = await runQueueOnce(root, options);
|
|
1007
|
+
const contract = JSON.parse(await readFile(path.join(dir, 'task_contract.json'), 'utf8'));
|
|
1008
|
+
assert.equal(revised.run.finalJudgement.outcome, contract.requires_human_gate ? 'ready_for_human_review' : 'ready_to_apply', 'explicit revision restores acceptance without bypassing contract gate: ' + JSON.stringify({ judgement: revised.run.finalJudgement, plan: JSON.parse(await readFile(path.join(dir, 'dev_plan.json'), 'utf8')).checkpoints }));
|
|
1009
|
+
assert.equal(JSON.parse(await readFile(path.join(dir, 'final_judgement.json'), 'utf8')).invalid_checkpoint_baseline, false);
|
|
1010
|
+
assert.equal(JSON.parse(await readFile(gateFile, 'utf8')).status, 'satisfied', 'valid successor can satisfy consumed gate after repair');
|
|
1011
|
+
}
|
|
1012
|
+
} finally { await rm(root, { recursive: true, force: true }); }
|
|
1013
|
+
}
|
|
1014
|
+
console.log('invalid baseline controlled repair regressions passed');
|
|
1015
|
+
|
|
1016
|
+
// Durable phase closure protocol and conservative negative cases.
|
|
1017
|
+
await import('./revision-coverage-self-test.mjs');
|