@abelxiaoxing/cadence 1.8.4 → 2.0.1

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.
Files changed (202) hide show
  1. package/README.md +324 -117
  2. package/THIRD_PARTY_NOTICES.md +15 -0
  3. package/agents/design-explorer.md +14 -18
  4. package/agents/diagnosis-worker.md +14 -14
  5. package/agents/implementation-worker.md +16 -17
  6. package/config/workflow-task.example.json +7 -0
  7. package/docs/remote-access.md +60 -0
  8. package/docs/reuse-and-distribution.md +44 -0
  9. package/docs/service-management.md +108 -0
  10. package/licenses/bundled-web.txt +6245 -0
  11. package/licenses/pi-web-ui-MIT.txt +21 -0
  12. package/licenses/pi-web-ui-reuse.md +22 -0
  13. package/package.json +92 -20
  14. package/src/index.ts +21 -1802
  15. package/src/native-build.ts +6 -0
  16. package/src/native-client.ts +103 -0
  17. package/src/native-export.ts +58 -0
  18. package/src/native-history.ts +359 -0
  19. package/src/operator-cli.mjs +453 -1937
  20. package/src/plan-proposal.ts +87 -0
  21. package/src/sdk-worker.mjs +549 -0
  22. package/src/service/contracts/active.ts +82 -0
  23. package/src/service/contracts/budget.ts +148 -0
  24. package/src/service/contracts/build.ts +67 -0
  25. package/src/service/contracts/capture.ts +48 -0
  26. package/src/service/contracts/core.ts +33 -0
  27. package/src/service/contracts/current.ts +261 -0
  28. package/src/service/contracts/domain.ts +68 -0
  29. package/src/service/contracts/history.ts +2245 -0
  30. package/src/service/contracts/models.ts +139 -0
  31. package/src/service/coordination.ts +862 -0
  32. package/src/service/private-files.ts +204 -0
  33. package/src/service-cli.mjs +5592 -0
  34. package/src/service-client.ts +747 -0
  35. package/src/service-contract.ts +245 -0
  36. package/src/service-host.mjs +22382 -0
  37. package/src/service-http-client.ts +425 -0
  38. package/src/service-wire.ts +372 -0
  39. package/src/task-shell.ts +1045 -0
  40. package/src/task-store.ts +479 -0
  41. package/src/task-types.ts +184 -0
  42. package/src/verification-diagnostics.ts +29 -72
  43. package/src/worker-capture.mjs +1197 -0
  44. package/src/worker-public.mjs +1753 -0
  45. package/src/worker-redaction.mjs +608 -0
  46. package/src/worker-tools.mjs +202 -0
  47. package/web/dist/assets/KaTeX_AMS-Regular.ttf +0 -0
  48. package/web/dist/assets/KaTeX_AMS-Regular.woff +0 -0
  49. package/web/dist/assets/KaTeX_AMS-Regular.woff2 +0 -0
  50. package/web/dist/assets/KaTeX_Caligraphic-Bold.ttf +0 -0
  51. package/web/dist/assets/KaTeX_Caligraphic-Bold.woff +0 -0
  52. package/web/dist/assets/KaTeX_Caligraphic-Bold.woff2 +0 -0
  53. package/web/dist/assets/KaTeX_Caligraphic-Regular.ttf +0 -0
  54. package/web/dist/assets/KaTeX_Caligraphic-Regular.woff +0 -0
  55. package/web/dist/assets/KaTeX_Caligraphic-Regular.woff2 +0 -0
  56. package/web/dist/assets/KaTeX_Fraktur-Bold.ttf +0 -0
  57. package/web/dist/assets/KaTeX_Fraktur-Bold.woff +0 -0
  58. package/web/dist/assets/KaTeX_Fraktur-Bold.woff2 +0 -0
  59. package/web/dist/assets/KaTeX_Fraktur-Regular.ttf +0 -0
  60. package/web/dist/assets/KaTeX_Fraktur-Regular.woff +0 -0
  61. package/web/dist/assets/KaTeX_Fraktur-Regular.woff2 +0 -0
  62. package/web/dist/assets/KaTeX_Main-Bold.ttf +0 -0
  63. package/web/dist/assets/KaTeX_Main-Bold.woff +0 -0
  64. package/web/dist/assets/KaTeX_Main-Bold.woff2 +0 -0
  65. package/web/dist/assets/KaTeX_Main-BoldItalic.ttf +0 -0
  66. package/web/dist/assets/KaTeX_Main-BoldItalic.woff +0 -0
  67. package/web/dist/assets/KaTeX_Main-BoldItalic.woff2 +0 -0
  68. package/web/dist/assets/KaTeX_Main-Italic.ttf +0 -0
  69. package/web/dist/assets/KaTeX_Main-Italic.woff +0 -0
  70. package/web/dist/assets/KaTeX_Main-Italic.woff2 +0 -0
  71. package/web/dist/assets/KaTeX_Main-Regular.ttf +0 -0
  72. package/web/dist/assets/KaTeX_Main-Regular.woff +0 -0
  73. package/web/dist/assets/KaTeX_Main-Regular.woff2 +0 -0
  74. package/web/dist/assets/KaTeX_Math-BoldItalic.ttf +0 -0
  75. package/web/dist/assets/KaTeX_Math-BoldItalic.woff +0 -0
  76. package/web/dist/assets/KaTeX_Math-BoldItalic.woff2 +0 -0
  77. package/web/dist/assets/KaTeX_Math-Italic.ttf +0 -0
  78. package/web/dist/assets/KaTeX_Math-Italic.woff +0 -0
  79. package/web/dist/assets/KaTeX_Math-Italic.woff2 +0 -0
  80. package/web/dist/assets/KaTeX_SansSerif-Bold.ttf +0 -0
  81. package/web/dist/assets/KaTeX_SansSerif-Bold.woff +0 -0
  82. package/web/dist/assets/KaTeX_SansSerif-Bold.woff2 +0 -0
  83. package/web/dist/assets/KaTeX_SansSerif-Italic.ttf +0 -0
  84. package/web/dist/assets/KaTeX_SansSerif-Italic.woff +0 -0
  85. package/web/dist/assets/KaTeX_SansSerif-Italic.woff2 +0 -0
  86. package/web/dist/assets/KaTeX_SansSerif-Regular.ttf +0 -0
  87. package/web/dist/assets/KaTeX_SansSerif-Regular.woff +0 -0
  88. package/web/dist/assets/KaTeX_SansSerif-Regular.woff2 +0 -0
  89. package/web/dist/assets/KaTeX_Script-Regular.ttf +0 -0
  90. package/web/dist/assets/KaTeX_Script-Regular.woff +0 -0
  91. package/web/dist/assets/KaTeX_Script-Regular.woff2 +0 -0
  92. package/web/dist/assets/KaTeX_Size1-Regular.ttf +0 -0
  93. package/web/dist/assets/KaTeX_Size1-Regular.woff +0 -0
  94. package/web/dist/assets/KaTeX_Size1-Regular.woff2 +0 -0
  95. package/web/dist/assets/KaTeX_Size2-Regular.ttf +0 -0
  96. package/web/dist/assets/KaTeX_Size2-Regular.woff +0 -0
  97. package/web/dist/assets/KaTeX_Size2-Regular.woff2 +0 -0
  98. package/web/dist/assets/KaTeX_Size3-Regular.ttf +0 -0
  99. package/web/dist/assets/KaTeX_Size3-Regular.woff +0 -0
  100. package/web/dist/assets/KaTeX_Size3-Regular.woff2 +0 -0
  101. package/web/dist/assets/KaTeX_Size4-Regular.ttf +0 -0
  102. package/web/dist/assets/KaTeX_Size4-Regular.woff +0 -0
  103. package/web/dist/assets/KaTeX_Size4-Regular.woff2 +0 -0
  104. package/web/dist/assets/KaTeX_Typewriter-Regular.ttf +0 -0
  105. package/web/dist/assets/KaTeX_Typewriter-Regular.woff +0 -0
  106. package/web/dist/assets/KaTeX_Typewriter-Regular.woff2 +0 -0
  107. package/web/dist/assets/cadence.css +2 -0
  108. package/web/dist/assets/cadence.js +7 -0
  109. package/web/dist/assets/markdown.js +296 -0
  110. package/web/dist/assets/react.js +9 -0
  111. package/web/dist/assets/rolldown-runtime.js +1 -0
  112. package/web/dist/assets/timeline-client.js +41 -0
  113. package/web/dist/assets/vis-timeline.css +1274 -0
  114. package/web/dist/assets/vis-timeline.js +32 -0
  115. package/web/dist/index.html +18 -0
  116. package/web/dist/manifest.json +505 -0
  117. package/config/plan-draft.example.json +0 -125
  118. package/config/plan-draft.multiple-tasks.example.json +0 -375
  119. package/config/plan-draft.quick.example.json +0 -78
  120. package/prompts/abel-design.md +0 -382
  121. package/prompts/abel-diagnose.md +0 -71
  122. package/prompts/abel-implement.md +0 -284
  123. package/prompts/abel-init.md +0 -52
  124. package/src/activation.ts +0 -44
  125. package/src/activity-contracts.ts +0 -82
  126. package/src/agent-registry.ts +0 -53
  127. package/src/apply-transaction.ts +0 -1437
  128. package/src/artifact-store.ts +0 -213
  129. package/src/build-windows-job.mjs +0 -95
  130. package/src/candidate-artifact.ts +0 -143
  131. package/src/candidate-context.ts +0 -289
  132. package/src/candidate-patch.ts +0 -271
  133. package/src/candidate-workspace.ts +0 -80
  134. package/src/canonical.ts +0 -16
  135. package/src/change-contract-schema.ts +0 -191
  136. package/src/change-contract.ts +0 -324
  137. package/src/change-verification.ts +0 -1617
  138. package/src/contracts.ts +0 -2466
  139. package/src/control-contracts.ts +0 -382
  140. package/src/delivery-compiler.ts +0 -1805
  141. package/src/delivery-revision.ts +0 -42
  142. package/src/design-control.ts +0 -1299
  143. package/src/design-diagnostics.ts +0 -181
  144. package/src/design-journal.ts +0 -1773
  145. package/src/directory-sync.ts +0 -36
  146. package/src/durable-contracts.ts +0 -227
  147. package/src/durable-workflow.ts +0 -822
  148. package/src/evidence-draft.ts +0 -122
  149. package/src/execution-profile.ts +0 -64
  150. package/src/execution-retention.ts +0 -77
  151. package/src/file-snapshot.ts +0 -163
  152. package/src/implement-continuation.ts +0 -559
  153. package/src/implement-graph.ts +0 -690
  154. package/src/implement-plan.ts +0 -72
  155. package/src/install-config.d.mts +0 -6
  156. package/src/isolation-backend.ts +0 -353
  157. package/src/model-source.ts +0 -22
  158. package/src/openspec-cli.ts +0 -494
  159. package/src/operator-cli-entry.mjs +0 -24
  160. package/src/operator-tools.ts +0 -309
  161. package/src/package-candidate-process.ts +0 -206
  162. package/src/package-candidate.ts +0 -24
  163. package/src/package-delivery.ts +0 -486
  164. package/src/package-state.ts +0 -320
  165. package/src/package-verification.ts +0 -635
  166. package/src/package-workflow.ts +0 -305
  167. package/src/packet-runtime.ts +0 -459
  168. package/src/phase-execution.ts +0 -2163
  169. package/src/pi-adapter.ts +0 -19
  170. package/src/plan-draft-summary.ts +0 -527
  171. package/src/plan-draft.ts +0 -502
  172. package/src/remove-path.ts +0 -32
  173. package/src/run-state.ts +0 -420
  174. package/src/run-store.ts +0 -1179
  175. package/src/safe-path.ts +0 -77
  176. package/src/scoped-grep-worker.mjs +0 -23
  177. package/src/scoped-tools.ts +0 -775
  178. package/src/single-task-draft.ts +0 -142
  179. package/src/sqlite-schema.ts +0 -171
  180. package/src/state-root.ts +0 -215
  181. package/src/storage-schema.ts +0 -360
  182. package/src/subagent-activity.ts +0 -1417
  183. package/src/subagent-process.ts +0 -476
  184. package/src/task-ledger.ts +0 -1338
  185. package/src/transport-budget.ts +0 -50
  186. package/src/verification-capability.ts +0 -1191
  187. package/src/verification-environment-io.ts +0 -389
  188. package/src/verification-environment.ts +0 -162
  189. package/src/verification-identity.ts +0 -77
  190. package/src/verification-scan.ts +0 -64
  191. package/src/windows-job-backend.ts +0 -419
  192. package/src/windows-job.c +0 -149
  193. package/src/workflow-engine.ts +0 -28
  194. package/src/workflow-policy.ts +0 -1670
  195. package/src/workflow-recovery-policy.ts +0 -97
  196. package/src/workflow-scheduling.ts +0 -105
  197. package/src/workflow-state-machine.ts +0 -4341
  198. package/src/workflow-status.ts +0 -576
  199. package/src/workspace-io-entry.mjs +0 -76
  200. package/src/workspace-io-worker.mjs +0 -1312
  201. package/src/workspace-io.ts +0 -89
  202. package/src/workspace-store.ts +0 -634
package/src/pi-adapter.ts DELETED
@@ -1,19 +0,0 @@
1
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import type { PackageContext } from "./model-source.ts";
3
-
4
- /** Project only the model capabilities used by the control services. */
5
- export function packageContext(
6
- context: Pick<ExtensionContext, "cwd" | "model" | "modelRegistry">,
7
- ): PackageContext {
8
- return {
9
- cwd: context.cwd,
10
- get model() {
11
- return context.model;
12
- },
13
- modelRegistry: {
14
- getProvider: (id) => context.modelRegistry.getProvider(id),
15
- getApiKeyAndHeaders: (model) =>
16
- context.modelRegistry.getApiKeyAndHeaders(model),
17
- },
18
- };
19
- }
@@ -1,527 +0,0 @@
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";
8
- import { expandSingleTaskDraft } from "./single-task-draft.ts";
9
- import { declarationPathsConflict, taskConflicts } from "./workflow-policy.ts";
10
-
11
- /** Review data only: no executable callbacks, evidence cache or approval authority. */
12
- function record(value: unknown): Record<string, unknown> {
13
- return value && typeof value === "object" && !Array.isArray(value)
14
- ? (value as Record<string, unknown>)
15
- : {};
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
- }
155
- export function planAuthoringSummary(
156
- plan: ImplementPlan,
157
- authoredDraft?: unknown,
158
- ) {
159
- const quick = record(authoredDraft).singleTask !== undefined;
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
- );
167
- const derivations: Array<{ field: string; source: string; taskId?: string }> =
168
- [];
169
- let derivationsTruncated = false;
170
- const derived = (field: string, source: string, taskId?: string) => {
171
- if (derivations.length >= 128) {
172
- derivationsTruncated = true;
173
- return;
174
- }
175
- derivations.push({ field, source, ...(taskId ? { taskId } : {}) });
176
- };
177
- if (quick) derived("singleTask", "single-task-author-input");
178
- if (authoredDraft !== undefined) {
179
- if (!Object.hasOwn(authored, "tracking")) derived("tracking", "task-ids");
180
- if (plan.changeContract && !Object.hasOwn(authored, "changeContract"))
181
- derived("changeContract", "approved-gate-a");
182
- for (const task of plan.tasks) {
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
- }
194
- for (const [phase, boundary] of Object.entries(task.phases)) {
195
- const phaseInput = record(record(input.phases)[phase]);
196
- if (!Object.hasOwn(phaseInput, "verificationInputs"))
197
- derived(
198
- `phases.${phase}.verificationInputs`,
199
- "contract-and-declared-outputs",
200
- task.taskId,
201
- );
202
- if (Object.hasOwn(input, "read"))
203
- derived(
204
- `phases.${phase}.read`,
205
- "common-and-phase-reads",
206
- task.taskId,
207
- );
208
- const verification = record(phaseInput.verification);
209
- if (typeof verification.use === "string")
210
- derived(
211
- `phases.${phase}.verification`,
212
- `definition:${verification.use}`,
213
- task.taskId,
214
- );
215
- if (!Object.hasOwn(verification, "id"))
216
- derived(
217
- `phases.${phase}.verification.id`,
218
- "stable-task-purpose-command",
219
- task.taskId,
220
- );
221
- if (!Object.hasOwn(verification, "classification"))
222
- derived(
223
- `phases.${phase}.verification.classification`,
224
- boundary.verification.classification,
225
- task.taskId,
226
- );
227
- }
228
- const tests = record(input.impactClosure).relatedTests;
229
- if (
230
- Array.isArray(tests) &&
231
- tests.some((test) => !Object.hasOwn(record(test), "disposition"))
232
- )
233
- derived("impactClosure.relatedTests", "declared-writers", task.taskId);
234
- if (!Object.hasOwn(record(input.agents), "managedOnly"))
235
- derived("agents.managedOnly", "parent-managed-boundary", task.taskId);
236
- }
237
- const verification = record(authored.verification);
238
- for (const [group, keys] of [
239
- ["baseline", ["target", "affected", "failureIdentity"]],
240
- ["change", ["affected"]],
241
- [
242
- "repair",
243
- ["inBoundaryOnly", "approvalOnBoundaryExpansion", "attribution"],
244
- ],
245
- ] as const) {
246
- for (const key of keys)
247
- if (!Object.hasOwn(record(verification[group]), key))
248
- derived(`verification.${group}.${key}`, "fixed-execution-contract");
249
- }
250
- if (!Object.hasOwn(verification, "agentsCheckpoint"))
251
- derived("verification.agentsCheckpoint", "explicit-none-impacts");
252
- }
253
- let truncated = plan.tasks.length > 16;
254
- const paths = (values: readonly string[]) => {
255
- const safe = values.filter(isValidRelativePath);
256
- if (safe.length !== values.length || safe.length > 32) truncated = true;
257
- return safe.slice(0, 32);
258
- };
259
- const tasks = plan.tasks.slice(0, 16).map((task) => ({
260
- taskId: task.taskId,
261
- dependsOn: task.dependsOn.slice(0, 16),
262
- phases: Object.entries(task.phases).map(([phase, boundary]) => ({
263
- phase,
264
- read: paths(boundary.read),
265
- write: paths(boundary.write),
266
- delete: paths(boundary.delete),
267
- verificationId: boundary.verification.id,
268
- classification: boundary.verification.classification,
269
- verificationInputs: boundary.verificationInputs.slice(0, 32),
270
- })),
271
- baselineVerification: task.baselineVerification?.id ?? null,
272
- affectedVerification: task.affectedVerification.id,
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
- },
286
- agentsImpact: task.agents.impact,
287
- }));
288
- if (
289
- plan.tasks.some(
290
- (task) =>
291
- task.dependsOn.length > 16 ||
292
- Object.values(task.phases).some(
293
- (phase) => phase.verificationInputs.length > 32,
294
- ),
295
- )
296
- )
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
- };
461
- return {
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
- },
508
- recovery: {
509
- artifactCorrection: plan.verification.artifactCorrection.maxAttempts,
510
- repair: plan.verification.repair.maxAttempts,
511
- },
512
- verifications: {
513
- baseline: plan.verification.baseline.fullSuite.id,
514
- fullSuite: plan.verification.change.fullSuite.id,
515
- postApply: plan.verification.change.postApply.id,
516
- },
517
- derivations,
518
- derivationRules: [
519
- "tracking:task-ids",
520
- "verificationInputs:contract-and-declared-outputs",
521
- "baselineVerification:affected-safe-original-inputs",
522
- "relatedTests:declared-writers",
523
- "verification-identities:stable-task-and-purpose",
524
- ],
525
- truncated: truncated || derivationsTruncated,
526
- };
527
- }