@abelxiaoxing/cadence 1.5.3 → 1.7.0
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/README.md +61 -1
- package/config/plan-draft.example.json +3 -0
- package/config/plan-draft.multiple-tasks.example.json +30 -0
- package/package.json +1 -1
- package/prompts/abel-design.md +33 -3
- package/prompts/abel-implement.md +36 -4
- package/src/apply-transaction.ts +1 -9
- package/src/artifact-store.ts +1 -9
- package/src/change-verification.ts +758 -65
- package/src/contracts.ts +8 -0
- package/src/delivery-compiler.ts +452 -9
- package/src/design-control.ts +2 -2
- package/src/design-diagnostics.ts +6 -4
- package/src/directory-sync.ts +36 -0
- package/src/durable-contracts.ts +19 -3
- package/src/durable-workflow.ts +47 -38
- package/src/implement-continuation.ts +559 -0
- package/src/implement-graph.ts +114 -0
- package/src/implement-plan.ts +2 -0
- package/src/index.ts +179 -1
- package/src/operator-cli.mjs +12 -7
- package/src/package-state.ts +309 -0
- package/src/package-verification.ts +17 -1
- package/src/package-workflow.ts +219 -171
- package/src/phase-execution.ts +7 -1
- package/src/plan-draft-summary.ts +385 -7
- package/src/plan-draft.ts +9 -0
- package/src/run-store.ts +39 -15
- package/src/storage-schema.ts +14 -6
- package/src/subagent-activity.ts +3 -1
- package/src/verification-capability.ts +17 -5
- package/src/verification-environment.ts +20 -2
- package/src/workflow-policy.ts +296 -5
- package/src/workflow-recovery-policy.ts +2 -0
- package/src/workflow-state-machine.ts +400 -131
- package/src/workflow-status.ts +251 -59
- package/src/workspace-io-worker.mjs +48 -42
- package/src/workspace-store.ts +1 -9
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { compareCanonicalStrings } from "./canonical.ts";
|
|
2
|
+
import {
|
|
3
|
+
isValidRelativePath,
|
|
4
|
+
LIMITS,
|
|
5
|
+
verificationInputPaths,
|
|
6
|
+
} from "./contracts.ts";
|
|
7
|
+
import type { ImplementPlan, PlanTaskDraft } from "./implement-plan.ts";
|
|
3
8
|
import { expandSingleTaskDraft } from "./single-task-draft.ts";
|
|
9
|
+
import { declarationPathsConflict, taskConflicts } from "./workflow-policy.ts";
|
|
4
10
|
|
|
5
11
|
/** Review data only: no executable callbacks, evidence cache or approval authority. */
|
|
6
12
|
function record(value: unknown): Record<string, unknown> {
|
|
@@ -8,12 +14,156 @@ function record(value: unknown): Record<string, unknown> {
|
|
|
8
14
|
? (value as Record<string, unknown>)
|
|
9
15
|
: {};
|
|
10
16
|
}
|
|
17
|
+
|
|
18
|
+
type SerializationCause =
|
|
19
|
+
| {
|
|
20
|
+
kind: "producer-output" | "declared-dependency";
|
|
21
|
+
waitingTaskId: string;
|
|
22
|
+
dependencyTaskId: string;
|
|
23
|
+
outputIds: string[];
|
|
24
|
+
}
|
|
25
|
+
| { kind: "declared-task-conflict" }
|
|
26
|
+
| { kind: "declared-resource"; resources: string[] }
|
|
27
|
+
| {
|
|
28
|
+
kind: "shared-writes";
|
|
29
|
+
paths: Array<{ left: string; right: string }>;
|
|
30
|
+
}
|
|
31
|
+
| {
|
|
32
|
+
kind: "shared-write-read";
|
|
33
|
+
paths: Array<{ writer: string; reader: string }>;
|
|
34
|
+
}
|
|
35
|
+
| { kind: "verification-lock"; locks: string[] }
|
|
36
|
+
| { kind: "agents-target"; targets: string[] };
|
|
37
|
+
|
|
38
|
+
function taskAncestors(
|
|
39
|
+
taskId: string,
|
|
40
|
+
tasks: ReadonlyMap<string, PlanTaskDraft>,
|
|
41
|
+
): Set<string> {
|
|
42
|
+
const ancestors = new Set<string>();
|
|
43
|
+
const pending = [...(tasks.get(taskId)?.dependsOn ?? [])];
|
|
44
|
+
while (pending.length > 0) {
|
|
45
|
+
const dependency = pending.pop() as string;
|
|
46
|
+
if (ancestors.has(dependency)) continue;
|
|
47
|
+
ancestors.add(dependency);
|
|
48
|
+
pending.push(...(tasks.get(dependency)?.dependsOn ?? []));
|
|
49
|
+
}
|
|
50
|
+
return ancestors;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function declarations(task: PlanTaskDraft) {
|
|
54
|
+
const reads = new Set<string>();
|
|
55
|
+
const writes = new Set<string>();
|
|
56
|
+
const locks = new Set<string>();
|
|
57
|
+
for (const phase of Object.values(task.phases)) {
|
|
58
|
+
for (const entry of phase.read) reads.add(entry);
|
|
59
|
+
for (const entry of phase.write) writes.add(entry);
|
|
60
|
+
for (const entry of phase.delete) writes.add(entry);
|
|
61
|
+
if (phase.verificationLock) locks.add(phase.verificationLock);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
reads: [...reads].sort(compareCanonicalStrings),
|
|
65
|
+
writes: [...writes].sort(compareCanonicalStrings),
|
|
66
|
+
locks: [...locks].sort(compareCanonicalStrings),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function conflictingPathPairs(
|
|
71
|
+
left: readonly string[],
|
|
72
|
+
right: readonly string[],
|
|
73
|
+
): Array<{ left: string; right: string }> {
|
|
74
|
+
return left.flatMap((leftPath) =>
|
|
75
|
+
right.flatMap((rightPath) =>
|
|
76
|
+
declarationPathsConflict(leftPath, rightPath)
|
|
77
|
+
? [{ left: leftPath, right: rightPath }]
|
|
78
|
+
: [],
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function conflictCauses(
|
|
84
|
+
left: PlanTaskDraft,
|
|
85
|
+
right: PlanTaskDraft,
|
|
86
|
+
truncate: () => void,
|
|
87
|
+
): SerializationCause[] {
|
|
88
|
+
const causes: SerializationCause[] = [];
|
|
89
|
+
if (
|
|
90
|
+
left.scheduling.conflicts.includes(right.taskId) ||
|
|
91
|
+
right.scheduling.conflicts.includes(left.taskId)
|
|
92
|
+
) {
|
|
93
|
+
causes.push({ kind: "declared-task-conflict" });
|
|
94
|
+
}
|
|
95
|
+
const resources = left.scheduling.resources
|
|
96
|
+
.filter((resource) => right.scheduling.resources.includes(resource))
|
|
97
|
+
.sort(compareCanonicalStrings);
|
|
98
|
+
if (resources.length > 8) truncate();
|
|
99
|
+
if (resources.length > 0) {
|
|
100
|
+
causes.push({
|
|
101
|
+
kind: "declared-resource",
|
|
102
|
+
resources: resources.slice(0, 8),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const leftDeclarations = declarations(left);
|
|
107
|
+
const rightDeclarations = declarations(right);
|
|
108
|
+
const sharedWrites = conflictingPathPairs(
|
|
109
|
+
leftDeclarations.writes,
|
|
110
|
+
rightDeclarations.writes,
|
|
111
|
+
);
|
|
112
|
+
const leftWriteReads = conflictingPathPairs(
|
|
113
|
+
leftDeclarations.writes,
|
|
114
|
+
rightDeclarations.reads,
|
|
115
|
+
);
|
|
116
|
+
const rightWriteReads = conflictingPathPairs(
|
|
117
|
+
rightDeclarations.writes,
|
|
118
|
+
leftDeclarations.reads,
|
|
119
|
+
).map(({ left: writer, right: reader }) => ({ writer, reader }));
|
|
120
|
+
if (sharedWrites.length > 8) truncate();
|
|
121
|
+
if (sharedWrites.length > 0) {
|
|
122
|
+
causes.push({ kind: "shared-writes", paths: sharedWrites.slice(0, 8) });
|
|
123
|
+
}
|
|
124
|
+
const writeReads = [
|
|
125
|
+
...leftWriteReads.map(({ left: writer, right: reader }) => ({
|
|
126
|
+
writer,
|
|
127
|
+
reader,
|
|
128
|
+
})),
|
|
129
|
+
...rightWriteReads,
|
|
130
|
+
];
|
|
131
|
+
if (writeReads.length > 8) truncate();
|
|
132
|
+
if (writeReads.length > 0) {
|
|
133
|
+
causes.push({
|
|
134
|
+
kind: "shared-write-read",
|
|
135
|
+
paths: writeReads.slice(0, 8),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (
|
|
139
|
+
left.agents.impact !== "none" &&
|
|
140
|
+
right.agents.impact !== "none" &&
|
|
141
|
+
left.agents.target &&
|
|
142
|
+
left.agents.target === right.agents.target
|
|
143
|
+
) {
|
|
144
|
+
causes.push({ kind: "agents-target", targets: [left.agents.target] });
|
|
145
|
+
}
|
|
146
|
+
const locks = leftDeclarations.locks
|
|
147
|
+
.filter((lock) => rightDeclarations.locks.includes(lock))
|
|
148
|
+
.sort(compareCanonicalStrings);
|
|
149
|
+
if (locks.length > 8) truncate();
|
|
150
|
+
if (locks.length > 0) {
|
|
151
|
+
causes.push({ kind: "verification-lock", locks: locks.slice(0, 8) });
|
|
152
|
+
}
|
|
153
|
+
return causes;
|
|
154
|
+
}
|
|
11
155
|
export function planAuthoringSummary(
|
|
12
156
|
plan: ImplementPlan,
|
|
13
157
|
authoredDraft?: unknown,
|
|
14
158
|
) {
|
|
15
159
|
const quick = record(authoredDraft).singleTask !== undefined;
|
|
16
160
|
const authored = record(expandSingleTaskDraft(authoredDraft));
|
|
161
|
+
const authoredTask = (taskId: string) =>
|
|
162
|
+
record(
|
|
163
|
+
Array.isArray(authored.tasks)
|
|
164
|
+
? authored.tasks.find((item) => record(item).taskId === taskId)
|
|
165
|
+
: undefined,
|
|
166
|
+
);
|
|
17
167
|
const derivations: Array<{ field: string; source: string; taskId?: string }> =
|
|
18
168
|
[];
|
|
19
169
|
let derivationsTruncated = false;
|
|
@@ -30,11 +180,17 @@ export function planAuthoringSummary(
|
|
|
30
180
|
if (plan.changeContract && !Object.hasOwn(authored, "changeContract"))
|
|
31
181
|
derived("changeContract", "approved-gate-a");
|
|
32
182
|
for (const task of plan.tasks) {
|
|
33
|
-
const input =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
)
|
|
183
|
+
const input = authoredTask(task.taskId);
|
|
184
|
+
if (
|
|
185
|
+
task.baselineVerification &&
|
|
186
|
+
!Object.hasOwn(input, "baselineVerification")
|
|
187
|
+
) {
|
|
188
|
+
derived(
|
|
189
|
+
"baselineVerification",
|
|
190
|
+
"affected-safe-original-inputs",
|
|
191
|
+
task.taskId,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
38
194
|
for (const [phase, boundary] of Object.entries(task.phases)) {
|
|
39
195
|
const phaseInput = record(record(input.phases)[phase]);
|
|
40
196
|
if (!Object.hasOwn(phaseInput, "verificationInputs"))
|
|
@@ -112,8 +268,21 @@ export function planAuthoringSummary(
|
|
|
112
268
|
classification: boundary.verification.classification,
|
|
113
269
|
verificationInputs: boundary.verificationInputs.slice(0, 32),
|
|
114
270
|
})),
|
|
271
|
+
baselineVerification: task.baselineVerification?.id ?? null,
|
|
115
272
|
affectedVerification: task.affectedVerification.id,
|
|
116
273
|
repairVerification: task.repairVerification.id,
|
|
274
|
+
verificationSources: {
|
|
275
|
+
baseline:
|
|
276
|
+
authoredDraft === undefined
|
|
277
|
+
? "compiled-plan"
|
|
278
|
+
: Object.hasOwn(authoredTask(task.taskId), "baselineVerification")
|
|
279
|
+
? "author-input"
|
|
280
|
+
: task.baselineVerification
|
|
281
|
+
? "affected-safe-original-inputs"
|
|
282
|
+
: "retained-legacy",
|
|
283
|
+
affected: authoredDraft === undefined ? "compiled-plan" : "author-input",
|
|
284
|
+
repair: authoredDraft === undefined ? "compiled-plan" : "author-input",
|
|
285
|
+
},
|
|
117
286
|
agentsImpact: task.agents.impact,
|
|
118
287
|
}));
|
|
119
288
|
if (
|
|
@@ -126,8 +295,216 @@ export function planAuthoringSummary(
|
|
|
126
295
|
)
|
|
127
296
|
)
|
|
128
297
|
truncated = true;
|
|
298
|
+
|
|
299
|
+
const projectedTasks = [...plan.tasks]
|
|
300
|
+
.sort((left, right) => compareCanonicalStrings(left.taskId, right.taskId))
|
|
301
|
+
.slice(0, 16);
|
|
302
|
+
const tasksById = new Map(plan.tasks.map((task) => [task.taskId, task]));
|
|
303
|
+
const ancestors = new Map(
|
|
304
|
+
plan.tasks.map((task) => [
|
|
305
|
+
task.taskId,
|
|
306
|
+
taskAncestors(task.taskId, tasksById),
|
|
307
|
+
]),
|
|
308
|
+
);
|
|
309
|
+
const outputsById = new Map(
|
|
310
|
+
plan.outputs.map((output) => [output.id, output]),
|
|
311
|
+
);
|
|
312
|
+
const consumedOutputsByTask = new Map<string, string[]>();
|
|
313
|
+
const consumedOutputIds = (task: PlanTaskDraft) => {
|
|
314
|
+
const cached = consumedOutputsByTask.get(task.taskId);
|
|
315
|
+
if (cached) return cached;
|
|
316
|
+
const ids = new Set(
|
|
317
|
+
Object.values(task.phases).flatMap((phase) =>
|
|
318
|
+
phase.verificationInputs.flatMap((binding) =>
|
|
319
|
+
binding.kind === "output" ? [binding.outputId] : [],
|
|
320
|
+
),
|
|
321
|
+
),
|
|
322
|
+
);
|
|
323
|
+
const finalInputs = new Set([
|
|
324
|
+
...verificationInputPaths(task.affectedVerification),
|
|
325
|
+
...verificationInputPaths(task.repairVerification),
|
|
326
|
+
]);
|
|
327
|
+
for (const output of plan.outputs) {
|
|
328
|
+
if (finalInputs.has(output.path)) ids.add(output.id);
|
|
329
|
+
}
|
|
330
|
+
const consumed = [...ids].sort(compareCanonicalStrings);
|
|
331
|
+
consumedOutputsByTask.set(task.taskId, consumed);
|
|
332
|
+
return consumed;
|
|
333
|
+
};
|
|
334
|
+
const dependencyCause = (
|
|
335
|
+
waitingTask: PlanTaskDraft,
|
|
336
|
+
dependencyTaskId: string,
|
|
337
|
+
): Extract<
|
|
338
|
+
SerializationCause,
|
|
339
|
+
{ kind: "producer-output" | "declared-dependency" }
|
|
340
|
+
> => {
|
|
341
|
+
const outputIds = consumedOutputIds(waitingTask).filter(
|
|
342
|
+
(outputId) =>
|
|
343
|
+
outputsById.get(outputId)?.producer.taskId === dependencyTaskId,
|
|
344
|
+
);
|
|
345
|
+
if (outputIds.length > 16) truncated = true;
|
|
346
|
+
return {
|
|
347
|
+
kind: outputIds.length > 0 ? "producer-output" : "declared-dependency",
|
|
348
|
+
waitingTaskId: waitingTask.taskId,
|
|
349
|
+
dependencyTaskId,
|
|
350
|
+
outputIds: outputIds.slice(0, 16),
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
const waiting: Array<{
|
|
354
|
+
taskId: string;
|
|
355
|
+
dependencyTaskId: string;
|
|
356
|
+
reason: "producer-output" | "declared-dependency";
|
|
357
|
+
outputIds: string[];
|
|
358
|
+
}> = [];
|
|
359
|
+
for (const task of projectedTasks) {
|
|
360
|
+
for (const dependencyTaskId of [...task.dependsOn].sort(
|
|
361
|
+
compareCanonicalStrings,
|
|
362
|
+
)) {
|
|
363
|
+
if (waiting.length >= 128) {
|
|
364
|
+
truncated = true;
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
const cause = dependencyCause(task, dependencyTaskId);
|
|
368
|
+
waiting.push({
|
|
369
|
+
taskId: task.taskId,
|
|
370
|
+
dependencyTaskId,
|
|
371
|
+
reason: cause.kind,
|
|
372
|
+
outputIds: cause.outputIds,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
const staticEligiblePairs: Array<{ taskIds: [string, string] }> = [];
|
|
377
|
+
const serializations: Array<{
|
|
378
|
+
taskIds: [string, string];
|
|
379
|
+
causes: SerializationCause[];
|
|
380
|
+
}> = [];
|
|
381
|
+
for (const [index, left] of projectedTasks.entries()) {
|
|
382
|
+
for (const right of projectedTasks.slice(index + 1)) {
|
|
383
|
+
const leftWaits = ancestors.get(left.taskId)?.has(right.taskId) ?? false;
|
|
384
|
+
const rightWaits = ancestors.get(right.taskId)?.has(left.taskId) ?? false;
|
|
385
|
+
const conflict = taskConflicts(left, right);
|
|
386
|
+
if (
|
|
387
|
+
!leftWaits &&
|
|
388
|
+
!rightWaits &&
|
|
389
|
+
!conflict.taskLifetime &&
|
|
390
|
+
!conflict.verification
|
|
391
|
+
) {
|
|
392
|
+
if (staticEligiblePairs.length < 64) {
|
|
393
|
+
staticEligiblePairs.push({ taskIds: [left.taskId, right.taskId] });
|
|
394
|
+
} else {
|
|
395
|
+
truncated = true;
|
|
396
|
+
}
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
const causes: SerializationCause[] = [];
|
|
400
|
+
if (leftWaits) causes.push(dependencyCause(left, right.taskId));
|
|
401
|
+
if (rightWaits) causes.push(dependencyCause(right, left.taskId));
|
|
402
|
+
if (conflict.taskLifetime || conflict.verification) {
|
|
403
|
+
causes.push(...conflictCauses(left, right, () => (truncated = true)));
|
|
404
|
+
}
|
|
405
|
+
if (serializations.length < 64) {
|
|
406
|
+
serializations.push({ taskIds: [left.taskId, right.taskId], causes });
|
|
407
|
+
} else {
|
|
408
|
+
truncated = true;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
const initiallyEligibleTasks = projectedTasks.filter(
|
|
413
|
+
(task) => task.dependsOn.length === 0,
|
|
414
|
+
);
|
|
415
|
+
const initiallyRunnableTasks: PlanTaskDraft[] = [];
|
|
416
|
+
for (const task of initiallyEligibleTasks) {
|
|
417
|
+
if (initiallyRunnableTasks.length >= LIMITS.maxActiveChildSessions) break;
|
|
418
|
+
if (
|
|
419
|
+
initiallyRunnableTasks.some((selected) => {
|
|
420
|
+
const conflict = taskConflicts(task, selected);
|
|
421
|
+
return conflict.taskLifetime || conflict.verification;
|
|
422
|
+
})
|
|
423
|
+
) {
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
initiallyRunnableTasks.push(task);
|
|
427
|
+
}
|
|
428
|
+
const checkpoint = plan.verification.agentsCheckpoint;
|
|
429
|
+
const bounded = (values: readonly string[]) => {
|
|
430
|
+
if (values.length > 32) truncated = true;
|
|
431
|
+
return values.slice(0, 32);
|
|
432
|
+
};
|
|
433
|
+
const contract = plan.changeContract;
|
|
434
|
+
// Review the outer recovery envelope as well as the initial task paths.
|
|
435
|
+
// This projection never grants authority or certifies runtime readiness.
|
|
436
|
+
const implementation = {
|
|
437
|
+
authority: "review-only" as const,
|
|
438
|
+
decisionOwner: "parent" as const,
|
|
439
|
+
userDecisionStage: "abel-design" as const,
|
|
440
|
+
policySource: contract
|
|
441
|
+
? ("structured-change-contract" as const)
|
|
442
|
+
: ("retained-legacy-boundaries" as const),
|
|
443
|
+
acceptanceIds: bounded(contract?.acceptance.map((entry) => entry.id) ?? []),
|
|
444
|
+
constraintIds: bounded(
|
|
445
|
+
contract?.constraints.map((entry) => entry.id) ?? [],
|
|
446
|
+
),
|
|
447
|
+
amendmentPolicy: contract
|
|
448
|
+
? {
|
|
449
|
+
writeRoots: bounded(contract.policy.writeRoots),
|
|
450
|
+
dependencies: bounded(contract.policy.dependencies),
|
|
451
|
+
verificationModes: [...contract.policy.verificationModes],
|
|
452
|
+
}
|
|
453
|
+
: null,
|
|
454
|
+
recovery: {
|
|
455
|
+
strategy: "repair-replan-resume" as const,
|
|
456
|
+
preservesAcceptance: true,
|
|
457
|
+
preservesConsumedBudget: true,
|
|
458
|
+
},
|
|
459
|
+
runtimePrerequisites: "not-assessed" as const,
|
|
460
|
+
};
|
|
129
461
|
return {
|
|
130
462
|
tasks,
|
|
463
|
+
implementation,
|
|
464
|
+
parallelism: {
|
|
465
|
+
assessment: "static-plan" as const,
|
|
466
|
+
authority: "review-only" as const,
|
|
467
|
+
runtimePrerequisites: "not-assessed" as const,
|
|
468
|
+
initiallyEligibleScope: "individual-dependency-free" as const,
|
|
469
|
+
initiallyEligible: initiallyEligibleTasks.map((task) => task.taskId),
|
|
470
|
+
initiallyRunnableGroup: {
|
|
471
|
+
taskIds: initiallyRunnableTasks.map((task) => task.taskId),
|
|
472
|
+
maximumSize: LIMITS.maxActiveChildSessions,
|
|
473
|
+
basis: "dependency-free-task-conflict-policy" as const,
|
|
474
|
+
capacityAssumption: "all-shared-slots-available" as const,
|
|
475
|
+
},
|
|
476
|
+
staticEligiblePairsScope: "eventual-compatibility" as const,
|
|
477
|
+
staticEligiblePairs,
|
|
478
|
+
waiting,
|
|
479
|
+
serializations,
|
|
480
|
+
globalBarriers: [
|
|
481
|
+
{
|
|
482
|
+
kind: "cumulative-verification" as const,
|
|
483
|
+
required: true,
|
|
484
|
+
verificationId: plan.verification.change.fullSuite.id,
|
|
485
|
+
requires: ["all-tasks-verified" as const],
|
|
486
|
+
taskIds: projectedTasks.map((task) => task.taskId),
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
kind: "agents-checkpoint" as const,
|
|
490
|
+
required: checkpoint.required,
|
|
491
|
+
verificationId: checkpoint.verification?.id ?? null,
|
|
492
|
+
requires: ["cumulative-verification" as const],
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
kind: "post-apply-verification" as const,
|
|
496
|
+
required: true,
|
|
497
|
+
verificationId: plan.verification.change.postApply.id,
|
|
498
|
+
requires: [
|
|
499
|
+
"cumulative-verification" as const,
|
|
500
|
+
...(checkpoint.required
|
|
501
|
+
? (["agents-checkpoint" as const] as const)
|
|
502
|
+
: []),
|
|
503
|
+
"transactional-apply" as const,
|
|
504
|
+
],
|
|
505
|
+
},
|
|
506
|
+
],
|
|
507
|
+
},
|
|
131
508
|
recovery: {
|
|
132
509
|
artifactCorrection: plan.verification.artifactCorrection.maxAttempts,
|
|
133
510
|
repair: plan.verification.repair.maxAttempts,
|
|
@@ -141,6 +518,7 @@ export function planAuthoringSummary(
|
|
|
141
518
|
derivationRules: [
|
|
142
519
|
"tracking:task-ids",
|
|
143
520
|
"verificationInputs:contract-and-declared-outputs",
|
|
521
|
+
"baselineVerification:affected-safe-original-inputs",
|
|
144
522
|
"relatedTests:declared-writers",
|
|
145
523
|
"verification-identities:stable-task-and-purpose",
|
|
146
524
|
],
|
package/src/plan-draft.ts
CHANGED
|
@@ -53,6 +53,7 @@ export interface PlanTaskInput
|
|
|
53
53
|
PlanTaskDraft,
|
|
54
54
|
| "phases"
|
|
55
55
|
| "impactClosure"
|
|
56
|
+
| "baselineVerification"
|
|
56
57
|
| "affectedVerification"
|
|
57
58
|
| "repairVerification"
|
|
58
59
|
| "agents"
|
|
@@ -64,6 +65,7 @@ export interface PlanTaskInput
|
|
|
64
65
|
refactor?: PlanPhaseDraft;
|
|
65
66
|
};
|
|
66
67
|
affectedVerification: DraftVerification;
|
|
68
|
+
baselineVerification?: DraftVerification;
|
|
67
69
|
repairVerification: DraftVerification;
|
|
68
70
|
agents: Omit<PlanTaskDraft["agents"], "managedOnly"> & { managedOnly?: true };
|
|
69
71
|
impactClosure: Omit<PlanTaskDraft["impactClosure"], "relatedTests"> & {
|
|
@@ -324,6 +326,13 @@ export function expandPlanDraft(value: unknown): unknown {
|
|
|
324
326
|
}
|
|
325
327
|
for (const field of ["affectedVerification", "repairVerification"])
|
|
326
328
|
task[field] = expand(task[field], field, "expected-green", taskId);
|
|
329
|
+
if (task.baselineVerification !== undefined)
|
|
330
|
+
task.baselineVerification = expand(
|
|
331
|
+
task.baselineVerification,
|
|
332
|
+
"baselineVerification",
|
|
333
|
+
"expected-green",
|
|
334
|
+
taskId,
|
|
335
|
+
);
|
|
327
336
|
}
|
|
328
337
|
if (isRecord(draft.verification)) {
|
|
329
338
|
const verification = draft.verification;
|
package/src/run-store.ts
CHANGED
|
@@ -17,7 +17,10 @@ import {
|
|
|
17
17
|
type ResolvedStateRoot,
|
|
18
18
|
StateRootError,
|
|
19
19
|
} from "./state-root.ts";
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
LEGACY_RUN_SCHEMA_V2,
|
|
22
|
+
RUN_SCHEMA as SCHEMA,
|
|
23
|
+
} from "./storage-schema.ts";
|
|
21
24
|
|
|
22
25
|
export class RunStoreFormatError extends Error {
|
|
23
26
|
readonly code = "run-store-reset-required" as const;
|
|
@@ -115,7 +118,10 @@ function requireIdentifier(value: string, label: string): void {
|
|
|
115
118
|
if (!IDENTIFIER.test(value)) throw new Error(`invalid-${label}`);
|
|
116
119
|
}
|
|
117
120
|
|
|
118
|
-
const
|
|
121
|
+
const LEGACY_SCHEMA_VERSIONS = new Map([
|
|
122
|
+
[2, LEGACY_RUN_SCHEMA_V2],
|
|
123
|
+
[4, SCHEMA],
|
|
124
|
+
]);
|
|
119
125
|
|
|
120
126
|
function applicationTables(database: DatabaseSync): string[] {
|
|
121
127
|
return (
|
|
@@ -153,25 +159,35 @@ function hasCurrentSchema(
|
|
|
153
159
|
);
|
|
154
160
|
}
|
|
155
161
|
|
|
156
|
-
function
|
|
162
|
+
function supportedLegacyVersion(
|
|
157
163
|
database: DatabaseSync,
|
|
158
164
|
tables: readonly string[],
|
|
159
|
-
):
|
|
165
|
+
): number | undefined {
|
|
160
166
|
if (
|
|
161
167
|
!tables.includes("schema_meta") ||
|
|
162
|
-
!hasRequiredCoreSchema(database, tables) ||
|
|
163
168
|
tableColumns(database, "schema_meta").join("\0") !== "version"
|
|
164
169
|
) {
|
|
165
|
-
return
|
|
170
|
+
return undefined;
|
|
166
171
|
}
|
|
167
172
|
const rows = database
|
|
168
173
|
.prepare("SELECT version FROM schema_meta")
|
|
169
174
|
.all() as unknown as Array<{
|
|
170
175
|
version: number;
|
|
171
176
|
}>;
|
|
172
|
-
return
|
|
173
|
-
|
|
174
|
-
);
|
|
177
|
+
if (rows.length !== 1) return undefined;
|
|
178
|
+
const version = rows[0]?.version;
|
|
179
|
+
const schema = LEGACY_SCHEMA_VERSIONS.get(version);
|
|
180
|
+
if (!schema || !matchesSqliteSchema(database, schema)) return undefined;
|
|
181
|
+
// A v2 database cannot already contain any proof fields. Do not repair a
|
|
182
|
+
// partial/ambiguous upgrade or reinterpret malformed fields as authority.
|
|
183
|
+
if (
|
|
184
|
+
version === 2 &&
|
|
185
|
+
tableColumns(database, "delivery_bindings").some((column) =>
|
|
186
|
+
["approval_revision", "contract_hash", "record_hash"].includes(column),
|
|
187
|
+
)
|
|
188
|
+
)
|
|
189
|
+
return undefined;
|
|
190
|
+
return version;
|
|
175
191
|
}
|
|
176
192
|
|
|
177
193
|
function isSqliteLocked(error: unknown): boolean {
|
|
@@ -210,7 +226,7 @@ function ensureCurrentSchema(
|
|
|
210
226
|
const initialTables = applicationTables(database);
|
|
211
227
|
if (hasCurrentSchema(database, initialTables)) return;
|
|
212
228
|
let transactionStarted = false;
|
|
213
|
-
let migrating
|
|
229
|
+
let migrating: number | undefined;
|
|
214
230
|
try {
|
|
215
231
|
database.exec("BEGIN IMMEDIATE");
|
|
216
232
|
transactionStarted = true;
|
|
@@ -219,11 +235,19 @@ function ensureCurrentSchema(
|
|
|
219
235
|
database.exec(SCHEMA);
|
|
220
236
|
} else if (hasCurrentSchema(database, tables)) {
|
|
221
237
|
// Another opener may already have completed the same migration.
|
|
222
|
-
} else if (isSupportedLegacySchema(database, tables)) {
|
|
223
|
-
migrating = true;
|
|
224
|
-
database.exec("DROP TABLE schema_meta");
|
|
225
238
|
} else {
|
|
226
|
-
|
|
239
|
+
migrating = supportedLegacyVersion(database, tables);
|
|
240
|
+
if (migrating === undefined) throw new RunStoreFormatError(databasePath);
|
|
241
|
+
if (migrating === 2) {
|
|
242
|
+
database.exec(`
|
|
243
|
+
ALTER TABLE delivery_bindings ADD COLUMN approval_revision INTEGER;
|
|
244
|
+
ALTER TABLE delivery_bindings ADD COLUMN contract_hash TEXT;
|
|
245
|
+
ALTER TABLE delivery_bindings ADD COLUMN record_hash TEXT;
|
|
246
|
+
`);
|
|
247
|
+
}
|
|
248
|
+
if (!hasRequiredCoreSchema(database, tables))
|
|
249
|
+
throw new RunStoreFormatError(databasePath);
|
|
250
|
+
database.exec("DROP TABLE schema_meta");
|
|
227
251
|
}
|
|
228
252
|
database.exec("COMMIT");
|
|
229
253
|
} catch (error) {
|
|
@@ -242,7 +266,7 @@ function ensureCurrentSchema(
|
|
|
242
266
|
throw error;
|
|
243
267
|
}
|
|
244
268
|
if (migrating) {
|
|
245
|
-
throw new RunStoreMigrationError(
|
|
269
|
+
throw new RunStoreMigrationError(migrating, error);
|
|
246
270
|
}
|
|
247
271
|
throw error;
|
|
248
272
|
}
|
package/src/storage-schema.ts
CHANGED
|
@@ -7,8 +7,14 @@ export const ROUTE_HEALTH_SCHEMA = `
|
|
|
7
7
|
) STRICT;
|
|
8
8
|
`;
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/** v2 predates proof-bound delivery receipts; migration must not invent proof. */
|
|
11
|
+
const DELIVERY_PROOF_COLUMNS = `
|
|
12
|
+
approval_revision INTEGER,
|
|
13
|
+
contract_hash TEXT,
|
|
14
|
+
record_hash TEXT,`;
|
|
15
|
+
|
|
16
|
+
function runSchema(withDeliveryProof: boolean): string {
|
|
17
|
+
return `
|
|
12
18
|
CREATE TABLE IF NOT EXISTS runs (
|
|
13
19
|
run_id TEXT PRIMARY KEY,
|
|
14
20
|
root_hash TEXT NOT NULL,
|
|
@@ -29,10 +35,7 @@ export const RUN_SCHEMA = `
|
|
|
29
35
|
run_id TEXT NOT NULL REFERENCES runs(run_id) ON DELETE CASCADE,
|
|
30
36
|
gate TEXT NOT NULL,
|
|
31
37
|
revision INTEGER NOT NULL,
|
|
32
|
-
receipt_hash TEXT NOT NULL
|
|
33
|
-
approval_revision INTEGER,
|
|
34
|
-
contract_hash TEXT,
|
|
35
|
-
record_hash TEXT,
|
|
38
|
+
receipt_hash TEXT NOT NULL,${withDeliveryProof ? DELIVERY_PROOF_COLUMNS : ""}
|
|
36
39
|
operation_id TEXT NOT NULL,
|
|
37
40
|
PRIMARY KEY (run_id, gate, revision),
|
|
38
41
|
UNIQUE (run_id, operation_id)
|
|
@@ -102,6 +105,11 @@ ${ROUTE_HEALTH_SCHEMA}
|
|
|
102
105
|
facts_json TEXT NOT NULL
|
|
103
106
|
) STRICT;
|
|
104
107
|
`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Owner-private storage contracts. Migrations run atomically before use. */
|
|
111
|
+
export const RUN_SCHEMA = runSchema(true);
|
|
112
|
+
export const LEGACY_RUN_SCHEMA_V2 = runSchema(false);
|
|
105
113
|
|
|
106
114
|
export const DESIGN_SCHEMA = `
|
|
107
115
|
CREATE TABLE IF NOT EXISTS design_facts (
|
package/src/subagent-activity.ts
CHANGED
|
@@ -501,7 +501,9 @@ function hasAutomaticContinuation(result: Record<string, unknown>): boolean {
|
|
|
501
501
|
asRecord(result.pause)?.code !== "operation-cancelled" &&
|
|
502
502
|
continuation?.owner === "parent" &&
|
|
503
503
|
continuation.automatic === true &&
|
|
504
|
-
(continuation.action === "amend" ||
|
|
504
|
+
(continuation.action === "amend" ||
|
|
505
|
+
continuation.command === "resume" ||
|
|
506
|
+
continuation.kind === "inspect-recovery")
|
|
505
507
|
);
|
|
506
508
|
}
|
|
507
509
|
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type StructuredVerificationContract,
|
|
12
12
|
VERIFICATION_CONFIGURATION_PATHS,
|
|
13
13
|
type VerificationAdapterCode,
|
|
14
|
+
type VerificationInputObservation,
|
|
14
15
|
validateVerificationContract,
|
|
15
16
|
verificationBoundInputPaths,
|
|
16
17
|
verificationInputPaths,
|
|
@@ -23,7 +24,7 @@ import {
|
|
|
23
24
|
snapshotFile,
|
|
24
25
|
snapshotFiles,
|
|
25
26
|
} from "./file-snapshot.ts";
|
|
26
|
-
import {
|
|
27
|
+
import { observeSafePath } from "./safe-path.ts";
|
|
27
28
|
import { verificationEnvironmentDigest } from "./verification-identity.ts";
|
|
28
29
|
|
|
29
30
|
export type VerificationCapabilityDiagnostic =
|
|
@@ -38,6 +39,7 @@ export type VerificationCapabilityDiagnostic =
|
|
|
38
39
|
code: VerificationAdapterCode;
|
|
39
40
|
verificationId: string;
|
|
40
41
|
message: string;
|
|
42
|
+
inputObservation?: VerificationInputObservation;
|
|
41
43
|
};
|
|
42
44
|
|
|
43
45
|
export type VerificationCapabilityResult =
|
|
@@ -118,10 +120,17 @@ function adapterFailure(
|
|
|
118
120
|
verificationId: string,
|
|
119
121
|
code: VerificationAdapterCode,
|
|
120
122
|
message: string,
|
|
123
|
+
inputObservation?: VerificationInputObservation,
|
|
121
124
|
): VerificationCapabilityResult {
|
|
122
125
|
return {
|
|
123
126
|
ok: false,
|
|
124
|
-
diagnostic: {
|
|
127
|
+
diagnostic: {
|
|
128
|
+
kind: "verification-adapter",
|
|
129
|
+
code,
|
|
130
|
+
verificationId,
|
|
131
|
+
message,
|
|
132
|
+
...(inputObservation ? { inputObservation } : {}),
|
|
133
|
+
},
|
|
125
134
|
};
|
|
126
135
|
}
|
|
127
136
|
|
|
@@ -1154,11 +1163,14 @@ function validateAcceptedVerificationCapability(
|
|
|
1154
1163
|
): VerificationCapabilityResult {
|
|
1155
1164
|
if (requireInputAvailability) {
|
|
1156
1165
|
for (const input of verificationInputPaths(verification)) {
|
|
1157
|
-
|
|
1166
|
+
const status = fileStatus(root, input);
|
|
1167
|
+
if (status !== "regular") {
|
|
1168
|
+
const inputObservation = { path: input, kind: status } as const;
|
|
1158
1169
|
return adapterFailure(
|
|
1159
1170
|
verification.id,
|
|
1160
|
-
"input-missing",
|
|
1161
|
-
`verification input ${input} is
|
|
1171
|
+
status === "absent" ? "input-missing" : "input-unsafe",
|
|
1172
|
+
`verification input ${input} is ${status}`,
|
|
1173
|
+
inputObservation,
|
|
1162
1174
|
);
|
|
1163
1175
|
}
|
|
1164
1176
|
}
|