@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
@@ -1,576 +0,0 @@
1
- import {
2
- canonicalJson,
3
- legalControlCommands,
4
- type RunProjection,
5
- } from "./run-state.ts";
6
- import {
7
- approvalRequirement,
8
- type EngineRunRow,
9
- type EngineTaskRow,
10
- hash,
11
- normalizeVerificationPrerequisite,
12
- normalizeWorkflowContextRequest,
13
- normalizeWorkflowVerificationStatus,
14
- parentRecoveryStrategy,
15
- parseDeliveryDiagnostics,
16
- permitsPlanAmendment,
17
- permitsPrerequisiteAmendment,
18
- permitsRecoveryAmendment,
19
- type SafeAttemptDiagnostic,
20
- } from "./workflow-policy.ts";
21
-
22
- export interface WorkflowResourceBudget {
23
- used: number;
24
- maximum: number;
25
- phaseHighWater: number;
26
- hardLimit: number;
27
- }
28
-
29
- export interface WorkflowStatusFacts {
30
- projection: RunProjection;
31
- rows: readonly EngineTaskRow[];
32
- engineRun?: EngineRunRow;
33
- attemptDiagnostics: ReadonlyMap<string, SafeAttemptDiagnostic>;
34
- failureSequences: ReadonlyMap<string, number>;
35
- amendmentUsed: number;
36
- resourceBudget?: WorkflowResourceBudget;
37
- }
38
-
39
- export function firstPausedTask(
40
- rows: readonly EngineTaskRow[],
41
- ): EngineTaskRow | undefined {
42
- return (
43
- rows.find((row) => row.state === "approval-needed") ??
44
- rows.find((row) => ["paused", "retryable"].includes(row.state))
45
- );
46
- }
47
-
48
- /** Project already-read facts; no storage access, callbacks or workflow transitions. */
49
- export function projectWorkflowStatus({
50
- projection,
51
- rows,
52
- engineRun,
53
- attemptDiagnostics,
54
- failureSequences,
55
- amendmentUsed,
56
- resourceBudget,
57
- }: WorkflowStatusFacts): Record<string, unknown> {
58
- const runId = projection.runId;
59
- const queued = rows
60
- .filter((row) => row.state === "queued")
61
- .sort(
62
- (left, right) =>
63
- (left.queue_position ?? Number.MAX_SAFE_INTEGER) -
64
- (right.queue_position ?? Number.MAX_SAFE_INTEGER) ||
65
- left.task_order - right.task_order,
66
- );
67
- const activeRows = rows.filter((row) =>
68
- ["approval-needed", "paused", "retryable"].includes(row.state),
69
- );
70
- const firstPaused = firstPausedTask(rows);
71
- const contextRequest = firstPaused?.context_request_json
72
- ? normalizeWorkflowContextRequest(
73
- JSON.parse(firstPaused.context_request_json) as unknown,
74
- )
75
- : undefined;
76
- const pauseCode =
77
- projection.state === "approval-needed" &&
78
- firstPaused?.state === "approval-needed"
79
- ? (firstPaused.pause_code ?? projection.pauseCode ?? "task-paused")
80
- : (projection.pauseCode ?? firstPaused?.pause_code ?? "task-paused");
81
- const taskPauseSuperseded =
82
- projection.state === "paused" &&
83
- projection.pauseCode !== undefined &&
84
- !activeRows.some((row) => row.pause_code === projection.pauseCode);
85
- const approval =
86
- projection.state === "approval-needed"
87
- ? approvalRequirement(pauseCode, contextRequest)
88
- : undefined;
89
- const attemptDiagnostic = firstPaused
90
- ? attemptDiagnostics.get(firstPaused.task_id)
91
- : undefined;
92
- const recovery = taskPauseSuperseded
93
- ? undefined
94
- : attemptDiagnostic?.recovery;
95
- const recoveryExhausted =
96
- recovery && recovery.failures >= recovery.feedback.maxAttempts;
97
- const selectedPrerequisite = normalizeVerificationPrerequisite(
98
- taskPauseSuperseded ? undefined : attemptDiagnostic?.prerequisite,
99
- );
100
- const selectedRecoveryStrategy = parentRecoveryStrategy(
101
- pauseCode,
102
- taskPauseSuperseded ? undefined : attemptDiagnostic,
103
- );
104
- const selectedPauseActionable =
105
- (projection.state === "approval-needed" && approval !== undefined) ||
106
- (projection.state === "paused" &&
107
- (permitsPlanAmendment(pauseCode) ||
108
- selectedRecoveryStrategy !== undefined ||
109
- permitsPrerequisiteAmendment(selectedPrerequisite)));
110
- const blockers = activeRows.map((row) => {
111
- const context = row.context_request_json
112
- ? normalizeWorkflowContextRequest(JSON.parse(row.context_request_json))
113
- : undefined;
114
- const code = row.pause_code ?? "task-paused";
115
- const diagnostic = attemptDiagnostics.get(row.task_id);
116
- const prerequisite = normalizeVerificationPrerequisite(
117
- diagnostic?.prerequisite,
118
- );
119
- const requirement =
120
- row.state === "approval-needed"
121
- ? approvalRequirement(code, context)
122
- : undefined;
123
- return {
124
- id: hash(runId, row.task_id, code, canonicalJson(context ?? {})),
125
- taskId: row.task_id,
126
- phase: row.phase,
127
- code,
128
- kind: requirement ? "decision" : "execution",
129
- ...(requirement ?? {}),
130
- ...(context ? { contextRequest: context } : {}),
131
- ...(prerequisite
132
- ? {
133
- prerequisite,
134
- scope:
135
- prerequisite.scope === "baseline-full-suite" ? "change" : "task",
136
- minimumRecovery: permitsPrerequisiteAmendment(prerequisite)
137
- ? "Revise the baseline contract to read safe inputs from the retained original revision, then recompile within the existing authority."
138
- : prerequisite.cause === "capability"
139
- ? "Restore the required runner or external capability; a changed environment identity permits a bounded check."
140
- : "Restore trusted verification prerequisites; the retained failure does not authorize plan changes.",
141
- }
142
- : {}),
143
- ...(diagnostic?.recovery
144
- ? {
145
- recovery: {
146
- code: diagnostic.recovery.feedback.code,
147
- attempts: diagnostic.recovery.failures,
148
- maxAttempts: diagnostic.recovery.feedback.maxAttempts,
149
- strategy: diagnostic.recovery.feedback.strategy,
150
- ...(diagnostic.recovery.feedback.failureIdentities
151
- ? {
152
- failureIdentities:
153
- diagnostic.recovery.feedback.failureIdentities,
154
- }
155
- : {}),
156
- },
157
- }
158
- : {}),
159
- };
160
- });
161
- if (
162
- projection.state === "approval-needed" &&
163
- !blockers.some((item) => item.kind === "decision") &&
164
- approval
165
- ) {
166
- blockers.push({
167
- id: hash(runId, pauseCode),
168
- taskId: "change",
169
- phase: "green",
170
- code: pauseCode,
171
- kind: "decision",
172
- ...approval,
173
- });
174
- }
175
- const decisions = blockers.filter((item) => item.kind === "decision");
176
- const amendments = !selectedPauseActionable
177
- ? []
178
- : blockers.filter(
179
- (item) =>
180
- item.kind === "decision" ||
181
- permitsPlanAmendment(item.code) ||
182
- permitsRecoveryAmendment(
183
- item.code,
184
- attemptDiagnostics.get(item.taskId),
185
- ) ||
186
- ("prerequisite" in item &&
187
- permitsPrerequisiteAmendment(item.prerequisite)),
188
- );
189
- if (
190
- projection.state === "paused" &&
191
- permitsPlanAmendment(pauseCode) &&
192
- !amendments.some((item) => item.code === pauseCode)
193
- ) {
194
- const item = {
195
- id: hash(runId, pauseCode, engineRun?.delivery_diagnostics_json ?? ""),
196
- taskId: "change",
197
- phase: "red" as const,
198
- code: pauseCode,
199
- kind: "execution",
200
- };
201
- blockers.push(item);
202
- amendments.push(item);
203
- }
204
- const amendmentBudget = {
205
- used: amendmentUsed,
206
- maximum: 64,
207
- remaining: 64 - amendmentUsed,
208
- exhausted: amendmentUsed >= 64,
209
- };
210
- const budgetCode = [
211
- "change-work-budget-exhausted",
212
- "change-recovery-budget-exhausted",
213
- ].includes(pauseCode)
214
- ? pauseCode
215
- : undefined;
216
- const budgetExhausted = budgetCode !== undefined;
217
- const hasWorkCapacity =
218
- !budgetExhausted &&
219
- (!resourceBudget || resourceBudget.used < resourceBudget.maximum);
220
- const decisionBatch =
221
- amendments.length &&
222
- pauseCode !== "operation-cancelled" &&
223
- ["approval-needed", "paused"].includes(projection.state)
224
- ? {
225
- id: hash(
226
- runId,
227
- String(projection.deliveryRevision ?? 0),
228
- canonicalJson(amendments),
229
- ),
230
- continuation: {
231
- action: "amend",
232
- change: projection.change,
233
- batchId: hash(
234
- runId,
235
- String(projection.deliveryRevision ?? 0),
236
- canonicalJson(amendments),
237
- ),
238
- },
239
- resolution: {
240
- owner: "parent",
241
- strategy: "recommended",
242
- requiresUserInput: false,
243
- },
244
- items: amendments,
245
- requiredGates: [
246
- ...new Set(
247
- amendments.flatMap((item) => item.requiredGates ?? ["gate-b"]),
248
- ),
249
- ].sort(),
250
- }
251
- : undefined;
252
- const guidanceRow = taskPauseSuperseded ? undefined : firstPaused;
253
- const guidanceDiagnostic = taskPauseSuperseded
254
- ? undefined
255
- : attemptDiagnostic;
256
- const guidanceCode = pauseCode;
257
- const guidanceStrategy = selectedRecoveryStrategy;
258
- const failureSequence = recovery
259
- ? failureSequences.get(recovery.key)
260
- : undefined;
261
- const recoveryGrant =
262
- recoveryExhausted &&
263
- guidanceStrategy !== undefined &&
264
- projection.state === "paused" &&
265
- hasWorkCapacity &&
266
- resourceBudget &&
267
- failureSequence !== undefined &&
268
- Number.isSafeInteger(failureSequence) &&
269
- failureSequence > 0
270
- ? {
271
- incidentKey: recovery.key,
272
- failureSequence,
273
- reason: "parent-directed-retry" as const,
274
- }
275
- : undefined;
276
- const recoveryContinuation =
277
- projection.state === "paused" &&
278
- hasWorkCapacity &&
279
- guidanceStrategy &&
280
- (!recoveryExhausted || recoveryGrant)
281
- ? {
282
- owner: "parent" as const,
283
- automatic: true,
284
- kind: "inspect-recovery" as const,
285
- reason: guidanceCode,
286
- stage: projection.stage,
287
- change: projection.change,
288
- metadata: {
289
- ...(guidanceRow
290
- ? { taskId: guidanceRow.task_id, phase: guidanceRow.phase }
291
- : {}),
292
- diagnostic: {
293
- code: guidanceCode,
294
- strategy:
295
- guidanceDiagnostic?.recovery?.feedback.strategy ??
296
- guidanceStrategy,
297
- ...(guidanceDiagnostic?.recovery
298
- ? {
299
- inspection: guidanceStrategy,
300
- attempts: guidanceDiagnostic.recovery.failures,
301
- maxAttempts:
302
- guidanceDiagnostic.recovery.feedback.maxAttempts,
303
- ...(guidanceDiagnostic.recovery.feedback.failureIdentities
304
- ? {
305
- failureIdentities:
306
- guidanceDiagnostic.recovery.feedback
307
- .failureIdentities,
308
- }
309
- : {}),
310
- }
311
- : {}),
312
- ...(guidanceDiagnostic?.prerequisite
313
- ? {
314
- prerequisite: normalizeVerificationPrerequisite(
315
- guidanceDiagnostic.prerequisite,
316
- ),
317
- }
318
- : {}),
319
- ...(guidanceRow?.route_id || engineRun?.route_id
320
- ? {
321
- route: {
322
- routeId:
323
- guidanceRow?.route_id ?? engineRun?.route_id ?? "",
324
- ...((guidanceRow?.route_fingerprint ??
325
- engineRun?.route_fingerprint)
326
- ? {
327
- routeFingerprint:
328
- guidanceRow?.route_fingerprint ??
329
- engineRun?.route_fingerprint,
330
- }
331
- : {}),
332
- },
333
- }
334
- : {}),
335
- },
336
- ...(recoveryGrant
337
- ? {
338
- recommendation: {
339
- kind: "bounded-additional-attempt" as const,
340
- resume: { recovery: recoveryGrant },
341
- },
342
- }
343
- : {}),
344
- },
345
- }
346
- : undefined;
347
- const amendmentContinuation =
348
- decisionBatch && !amendmentBudget.exhausted && hasWorkCapacity
349
- ? {
350
- owner: "parent" as const,
351
- automatic: true,
352
- ...decisionBatch.continuation,
353
- }
354
- : undefined;
355
- const interruptedContinuation =
356
- projection.stage === "abel-implement" &&
357
- projection.change &&
358
- projection.pauseCode === "operation-interrupted" &&
359
- legalControlCommands(projection.state).includes("resume") &&
360
- (projection.state === "recovering" ||
361
- (projection.state === "paused" && hasWorkCapacity))
362
- ? {
363
- owner: "parent" as const,
364
- automatic: true,
365
- command: "resume" as const,
366
- kind:
367
- projection.state === "recovering"
368
- ? ("settle-apply-recovery" as const)
369
- : ("resume-interrupted-operation" as const),
370
- reason: "operation-interrupted" as const,
371
- stage: projection.stage,
372
- change: projection.change,
373
- ...(guidanceRow?.pause_code === "operation-interrupted"
374
- ? {
375
- metadata: {
376
- taskId: guidanceRow.task_id,
377
- phase: guidanceRow.phase,
378
- },
379
- }
380
- : {}),
381
- }
382
- : undefined;
383
- const continuation =
384
- interruptedContinuation ?? recoveryContinuation ?? amendmentContinuation;
385
- const currentRevision = projection.deliveryRevision ?? 0;
386
- return {
387
- runId: projection.runId,
388
- stage: projection.stage,
389
- ...(projection.change ? { change: projection.change } : {}),
390
- state: projection.state,
391
- ...(projection.deliveryRevision === undefined
392
- ? {}
393
- : { deliveryRevision: projection.deliveryRevision }),
394
- ...(projection.deliveryBindings.length > 0
395
- ? { deliveryBindings: structuredClone(projection.deliveryBindings) }
396
- : {}),
397
- completed: projection.state === "completed",
398
- blockers,
399
- ...(resourceBudget
400
- ? {
401
- resourceBudget: {
402
- ...resourceBudget,
403
- remaining: resourceBudget.maximum - resourceBudget.used,
404
- },
405
- }
406
- : {}),
407
- ...(budgetExhausted
408
- ? {
409
- recovery: {
410
- automatic: false,
411
- exhausted: true,
412
- code: budgetCode,
413
- },
414
- }
415
- : {}),
416
- ...(decisionBatch
417
- ? {
418
- decisionBatch,
419
- amendmentBudget,
420
- }
421
- : {}),
422
- ...(recoveryExhausted
423
- ? {
424
- recovery: {
425
- automatic: false,
426
- exhausted: true,
427
- code: recovery.feedback.code,
428
- attempts: recovery.failures,
429
- maxAttempts: recovery.feedback.maxAttempts,
430
- automaticRetryExhausted: true,
431
- ...(recoveryGrant ? { additionalAttempt: recoveryGrant } : {}),
432
- },
433
- }
434
- : {}),
435
- ...(continuation ? { continuation } : {}),
436
- ...(projection.terminal ? { terminal: projection.terminal } : {}),
437
- ...(projection.pauseCode || firstPaused?.pause_code
438
- ? {
439
- pause: {
440
- code: pauseCode,
441
- ...(attemptDiagnostic ? { diagnostic: attemptDiagnostic } : {}),
442
- },
443
- }
444
- : {}),
445
- legalCommands:
446
- projection.state === "approval-needed"
447
- ? ["status", "discard"]
448
- : legalControlCommands(projection.state).filter(
449
- (command) =>
450
- (command !== "rebind" || firstPaused !== undefined) &&
451
- (command !== "resume" ||
452
- (!recoveryExhausted && !budgetExhausted)),
453
- ),
454
- ...(approval && projection.change
455
- ? {
456
- approval: {
457
- category: approval.category,
458
- requiredGates:
459
- decisionBatch?.requiredGates ?? approval.requiredGates,
460
- categories: [
461
- ...new Set(
462
- decisions.flatMap((item) =>
463
- item.category ? [item.category] : [],
464
- ),
465
- ),
466
- ],
467
- refs: [...new Set(decisions.flatMap((item) => item.refs ?? []))],
468
- continuation: decisionBatch?.continuation,
469
- retainedRun: {
470
- runId: projection.runId,
471
- deliveryRevision: currentRevision,
472
- },
473
- receiptPrecondition: {
474
- deliveryRevision: { greaterThan: currentRevision },
475
- receiptHash: "matching-ready-receipt",
476
- },
477
- },
478
- }
479
- : {}),
480
- ...(approval && projection.change
481
- ? {
482
- conditionalCommands: [
483
- {
484
- command: "resume",
485
- stage: "abel-implement",
486
- change: projection.change,
487
- requires: {
488
- deliveryRevision: { greaterThan: currentRevision },
489
- receiptHash: "matching-ready-receipt",
490
- },
491
- },
492
- ],
493
- }
494
- : recoveryGrant && projection.change
495
- ? {
496
- conditionalCommands: [
497
- {
498
- command: "resume",
499
- stage: "abel-implement",
500
- change: projection.change,
501
- requires: { recovery: recoveryGrant },
502
- },
503
- ],
504
- }
505
- : {}),
506
- tasks: rows.map((row) => ({
507
- taskId: row.task_id,
508
- state: row.state,
509
- ...(row.state === "verified" ? {} : { phase: row.phase }),
510
- ...(row.context_request_json
511
- ? {
512
- contextRequest: normalizeWorkflowContextRequest(
513
- JSON.parse(row.context_request_json) as unknown,
514
- ),
515
- }
516
- : {}),
517
- })),
518
- queue: queued.map((row, index) => ({
519
- taskId: row.task_id,
520
- position: index + 1,
521
- reason: row.pause_code === "worker-capacity" ? "capacity" : "conflict",
522
- })),
523
- ...(engineRun?.verification_json
524
- ? {
525
- verification: normalizeWorkflowVerificationStatus(
526
- JSON.parse(engineRun.verification_json) as unknown,
527
- ),
528
- }
529
- : {}),
530
- ...(engineRun?.delivery_diagnostics_json
531
- ? {
532
- delivery: {
533
- code: "delivery-invalid",
534
- diagnostics: parseDeliveryDiagnostics(
535
- engineRun.delivery_diagnostics_json,
536
- ),
537
- },
538
- }
539
- : {}),
540
- ...(engineRun?.route_id
541
- ? {
542
- routeBinding: {
543
- routeId: engineRun.route_id,
544
- ...(engineRun.route_fingerprint
545
- ? { routeFingerprint: engineRun.route_fingerprint }
546
- : {}),
547
- },
548
- }
549
- : {}),
550
- ...(engineRun?.cleanup_state === "retained"
551
- ? {
552
- privateData: {
553
- retained: true,
554
- cleanup: "retained",
555
- ...(engineRun.baseline_workspace_revision
556
- ? {
557
- baselineRevisionId: engineRun.baseline_workspace_revision,
558
- }
559
- : {}),
560
- ...(engineRun.current_workspace_revision
561
- ? {
562
- currentRevisionId: engineRun.current_workspace_revision,
563
- }
564
- : {}),
565
- },
566
- }
567
- : engineRun?.cleanup_state === "complete"
568
- ? {
569
- privateData: {
570
- retained: false,
571
- cleanup: "complete",
572
- },
573
- }
574
- : {}),
575
- };
576
- }
@@ -1,76 +0,0 @@
1
- import { parentPort, workerData } from "node:worker_threads";
2
- import { ArtifactStore } from "./artifact-store.ts";
3
- import { removePathSync } from "./remove-path.ts";
4
- import { prepareVerificationEnvironmentIo } from "./verification-environment-io.ts";
5
- import { verificationEnvironmentDigest } from "./verification-identity.ts";
6
- import { WorkspaceStore } from "./workspace-store.ts";
7
-
8
- const controller = new AbortController();
9
- const flag = new Int32Array(workerData.cancelled);
10
- parentPort.on("message", () => controller.abort(new Error("cancelled")));
11
- const checkCancelled = () => {
12
- if (Atomics.load(flag, 0)) throw new Error("cancelled");
13
- };
14
- try {
15
- if (workerData.operation === "prepareVerification") {
16
- const [root, owner, bindings, profile, environment, scratch] =
17
- workerData.args;
18
- const result = prepareVerificationEnvironmentIo(
19
- root,
20
- owner,
21
- bindings,
22
- profile,
23
- environment,
24
- checkCancelled,
25
- scratch,
26
- );
27
- parentPort.postMessage({ ok: true, result, files: 0, bytes: 0 });
28
- } else if (workerData.operation === "cleanupVerification") {
29
- removePathSync(workerData.args[0], { recursive: true, force: true });
30
- parentPort.postMessage({ ok: true, files: 0, bytes: 0 });
31
- } else if (workerData.operation === "verificationIdentity") {
32
- const result = verificationEnvironmentDigest(
33
- workerData.args[0],
34
- checkCancelled,
35
- );
36
- parentPort.postMessage({ ok: true, result, files: 0, bytes: 0 });
37
- } else {
38
- const artifacts = new ArtifactStore(workerData.artifactRoot);
39
- const store = new WorkspaceStore(workerData.root, artifacts, {
40
- checkCancelled,
41
- });
42
- let result;
43
- let revision;
44
- checkCancelled();
45
- if (workerData.operation === "captureBaseline") {
46
- revision = await store.captureBaselineWithGit(
47
- workerData.args[0],
48
- controller.signal,
49
- );
50
- result = revision;
51
- } else if (workerData.operation === "materialize") {
52
- revision = store.getRevision(workerData.args[0]);
53
- store.materialize(workerData.args[0], workerData.args[1]);
54
- } else {
55
- throw new Error("workspace-io-operation-invalid");
56
- }
57
- const files = Object.values(revision.entries).filter(
58
- (entry) => entry.kind === "file",
59
- );
60
- parentPort.postMessage({
61
- ok: true,
62
- result,
63
- files: files.length,
64
- bytes: files.reduce((sum, entry) => sum + entry.bytes, 0),
65
- });
66
- }
67
- } catch (error) {
68
- parentPort.postMessage({
69
- ok: false,
70
- error: error instanceof Error ? error.message : "workspace-io-failed",
71
- files: 0,
72
- bytes: 0,
73
- });
74
- } finally {
75
- parentPort.close();
76
- }