@abelxiaoxing/cadence 1.8.3 → 2.0.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.
Files changed (208) hide show
  1. package/README.md +324 -111
  2. package/THIRD_PARTY_NOTICES.md +15 -0
  3. package/agents/design-explorer.md +14 -26
  4. package/agents/diagnosis-worker.md +14 -25
  5. package/agents/implementation-worker.md +16 -35
  6. package/config/.env.example +2 -5
  7. package/config/workflow-task.example.json +7 -0
  8. package/docs/remote-access.md +60 -0
  9. package/docs/reuse-and-distribution.md +44 -0
  10. package/docs/service-management.md +108 -0
  11. package/licenses/bundled-web.txt +6245 -0
  12. package/licenses/pi-web-ui-MIT.txt +21 -0
  13. package/licenses/pi-web-ui-reuse.md +22 -0
  14. package/package.json +94 -21
  15. package/src/index.ts +22 -1807
  16. package/src/native-build.ts +6 -0
  17. package/src/native-client.ts +103 -0
  18. package/src/native-export.ts +58 -0
  19. package/src/native-history.ts +359 -0
  20. package/src/operator-cli.mjs +453 -1937
  21. package/src/plan-proposal.ts +87 -0
  22. package/src/sdk-worker.mjs +549 -0
  23. package/src/service/contracts/active.ts +82 -0
  24. package/src/service/contracts/budget.ts +148 -0
  25. package/src/service/contracts/build.ts +67 -0
  26. package/src/service/contracts/capture.ts +48 -0
  27. package/src/service/contracts/core.ts +33 -0
  28. package/src/service/contracts/current.ts +261 -0
  29. package/src/service/contracts/domain.ts +68 -0
  30. package/src/service/contracts/history.ts +2245 -0
  31. package/src/service/contracts/models.ts +139 -0
  32. package/src/service/coordination.ts +862 -0
  33. package/src/service/private-files.ts +204 -0
  34. package/src/service-cli.mjs +5592 -0
  35. package/src/service-client.ts +747 -0
  36. package/src/service-contract.ts +245 -0
  37. package/src/service-host.mjs +22382 -0
  38. package/src/service-http-client.ts +425 -0
  39. package/src/service-wire.ts +372 -0
  40. package/src/task-shell.ts +1045 -0
  41. package/src/task-store.ts +479 -0
  42. package/src/task-types.ts +184 -0
  43. package/src/verification-diagnostics.ts +29 -72
  44. package/src/worker-capture.mjs +1197 -0
  45. package/src/worker-public.mjs +1753 -0
  46. package/src/worker-redaction.mjs +608 -0
  47. package/src/worker-tools.mjs +202 -0
  48. package/web/dist/assets/KaTeX_AMS-Regular.ttf +0 -0
  49. package/web/dist/assets/KaTeX_AMS-Regular.woff +0 -0
  50. package/web/dist/assets/KaTeX_AMS-Regular.woff2 +0 -0
  51. package/web/dist/assets/KaTeX_Caligraphic-Bold.ttf +0 -0
  52. package/web/dist/assets/KaTeX_Caligraphic-Bold.woff +0 -0
  53. package/web/dist/assets/KaTeX_Caligraphic-Bold.woff2 +0 -0
  54. package/web/dist/assets/KaTeX_Caligraphic-Regular.ttf +0 -0
  55. package/web/dist/assets/KaTeX_Caligraphic-Regular.woff +0 -0
  56. package/web/dist/assets/KaTeX_Caligraphic-Regular.woff2 +0 -0
  57. package/web/dist/assets/KaTeX_Fraktur-Bold.ttf +0 -0
  58. package/web/dist/assets/KaTeX_Fraktur-Bold.woff +0 -0
  59. package/web/dist/assets/KaTeX_Fraktur-Bold.woff2 +0 -0
  60. package/web/dist/assets/KaTeX_Fraktur-Regular.ttf +0 -0
  61. package/web/dist/assets/KaTeX_Fraktur-Regular.woff +0 -0
  62. package/web/dist/assets/KaTeX_Fraktur-Regular.woff2 +0 -0
  63. package/web/dist/assets/KaTeX_Main-Bold.ttf +0 -0
  64. package/web/dist/assets/KaTeX_Main-Bold.woff +0 -0
  65. package/web/dist/assets/KaTeX_Main-Bold.woff2 +0 -0
  66. package/web/dist/assets/KaTeX_Main-BoldItalic.ttf +0 -0
  67. package/web/dist/assets/KaTeX_Main-BoldItalic.woff +0 -0
  68. package/web/dist/assets/KaTeX_Main-BoldItalic.woff2 +0 -0
  69. package/web/dist/assets/KaTeX_Main-Italic.ttf +0 -0
  70. package/web/dist/assets/KaTeX_Main-Italic.woff +0 -0
  71. package/web/dist/assets/KaTeX_Main-Italic.woff2 +0 -0
  72. package/web/dist/assets/KaTeX_Main-Regular.ttf +0 -0
  73. package/web/dist/assets/KaTeX_Main-Regular.woff +0 -0
  74. package/web/dist/assets/KaTeX_Main-Regular.woff2 +0 -0
  75. package/web/dist/assets/KaTeX_Math-BoldItalic.ttf +0 -0
  76. package/web/dist/assets/KaTeX_Math-BoldItalic.woff +0 -0
  77. package/web/dist/assets/KaTeX_Math-BoldItalic.woff2 +0 -0
  78. package/web/dist/assets/KaTeX_Math-Italic.ttf +0 -0
  79. package/web/dist/assets/KaTeX_Math-Italic.woff +0 -0
  80. package/web/dist/assets/KaTeX_Math-Italic.woff2 +0 -0
  81. package/web/dist/assets/KaTeX_SansSerif-Bold.ttf +0 -0
  82. package/web/dist/assets/KaTeX_SansSerif-Bold.woff +0 -0
  83. package/web/dist/assets/KaTeX_SansSerif-Bold.woff2 +0 -0
  84. package/web/dist/assets/KaTeX_SansSerif-Italic.ttf +0 -0
  85. package/web/dist/assets/KaTeX_SansSerif-Italic.woff +0 -0
  86. package/web/dist/assets/KaTeX_SansSerif-Italic.woff2 +0 -0
  87. package/web/dist/assets/KaTeX_SansSerif-Regular.ttf +0 -0
  88. package/web/dist/assets/KaTeX_SansSerif-Regular.woff +0 -0
  89. package/web/dist/assets/KaTeX_SansSerif-Regular.woff2 +0 -0
  90. package/web/dist/assets/KaTeX_Script-Regular.ttf +0 -0
  91. package/web/dist/assets/KaTeX_Script-Regular.woff +0 -0
  92. package/web/dist/assets/KaTeX_Script-Regular.woff2 +0 -0
  93. package/web/dist/assets/KaTeX_Size1-Regular.ttf +0 -0
  94. package/web/dist/assets/KaTeX_Size1-Regular.woff +0 -0
  95. package/web/dist/assets/KaTeX_Size1-Regular.woff2 +0 -0
  96. package/web/dist/assets/KaTeX_Size2-Regular.ttf +0 -0
  97. package/web/dist/assets/KaTeX_Size2-Regular.woff +0 -0
  98. package/web/dist/assets/KaTeX_Size2-Regular.woff2 +0 -0
  99. package/web/dist/assets/KaTeX_Size3-Regular.ttf +0 -0
  100. package/web/dist/assets/KaTeX_Size3-Regular.woff +0 -0
  101. package/web/dist/assets/KaTeX_Size3-Regular.woff2 +0 -0
  102. package/web/dist/assets/KaTeX_Size4-Regular.ttf +0 -0
  103. package/web/dist/assets/KaTeX_Size4-Regular.woff +0 -0
  104. package/web/dist/assets/KaTeX_Size4-Regular.woff2 +0 -0
  105. package/web/dist/assets/KaTeX_Typewriter-Regular.ttf +0 -0
  106. package/web/dist/assets/KaTeX_Typewriter-Regular.woff +0 -0
  107. package/web/dist/assets/KaTeX_Typewriter-Regular.woff2 +0 -0
  108. package/web/dist/assets/cadence.css +2 -0
  109. package/web/dist/assets/cadence.js +7 -0
  110. package/web/dist/assets/markdown.js +296 -0
  111. package/web/dist/assets/react.js +9 -0
  112. package/web/dist/assets/rolldown-runtime.js +1 -0
  113. package/web/dist/assets/timeline-client.js +41 -0
  114. package/web/dist/assets/vis-timeline.css +1274 -0
  115. package/web/dist/assets/vis-timeline.js +32 -0
  116. package/web/dist/index.html +18 -0
  117. package/web/dist/manifest.json +505 -0
  118. package/config/plan-draft.example.json +0 -125
  119. package/config/plan-draft.multiple-tasks.example.json +0 -375
  120. package/config/plan-draft.quick.example.json +0 -78
  121. package/config/routes.example.json +0 -39
  122. package/prompts/abel-design.md +0 -382
  123. package/prompts/abel-diagnose.md +0 -71
  124. package/prompts/abel-implement.md +0 -284
  125. package/prompts/abel-init.md +0 -52
  126. package/src/activation.ts +0 -44
  127. package/src/activity-contracts.ts +0 -82
  128. package/src/agent-registry.ts +0 -53
  129. package/src/apply-transaction.ts +0 -1437
  130. package/src/artifact-store.ts +0 -213
  131. package/src/build-windows-job.mjs +0 -95
  132. package/src/candidate-artifact.ts +0 -143
  133. package/src/candidate-patch.ts +0 -271
  134. package/src/candidate-workspace.ts +0 -80
  135. package/src/canonical.ts +0 -16
  136. package/src/change-contract-schema.ts +0 -191
  137. package/src/change-contract.ts +0 -324
  138. package/src/change-verification.ts +0 -1617
  139. package/src/child-budget.ts +0 -58
  140. package/src/child-model.ts +0 -142
  141. package/src/child-session.ts +0 -640
  142. package/src/contracts.ts +0 -2476
  143. package/src/control-contracts.ts +0 -382
  144. package/src/delivery-compiler.ts +0 -1805
  145. package/src/delivery-revision.ts +0 -42
  146. package/src/design-control.ts +0 -1299
  147. package/src/design-diagnostics.ts +0 -181
  148. package/src/design-journal.ts +0 -1773
  149. package/src/directory-sync.ts +0 -36
  150. package/src/durable-contracts.ts +0 -231
  151. package/src/durable-workflow.ts +0 -978
  152. package/src/evidence-draft.ts +0 -122
  153. package/src/execution-profile.ts +0 -64
  154. package/src/execution-retention.ts +0 -77
  155. package/src/file-snapshot.ts +0 -163
  156. package/src/implement-continuation.ts +0 -559
  157. package/src/implement-graph.ts +0 -690
  158. package/src/implement-plan.ts +0 -72
  159. package/src/install-config.d.mts +0 -6
  160. package/src/isolation-backend.ts +0 -353
  161. package/src/model-source.ts +0 -22
  162. package/src/openspec-cli.ts +0 -494
  163. package/src/operator-cli-entry.mjs +0 -24
  164. package/src/operator-tools.ts +0 -309
  165. package/src/package-candidate.ts +0 -227
  166. package/src/package-delivery.ts +0 -486
  167. package/src/package-state.ts +0 -320
  168. package/src/package-verification.ts +0 -635
  169. package/src/package-workflow.ts +0 -342
  170. package/src/packet-runtime.ts +0 -570
  171. package/src/parent-provider.ts +0 -375
  172. package/src/phase-execution.ts +0 -2259
  173. package/src/pi-adapter.ts +0 -19
  174. package/src/plan-draft-summary.ts +0 -527
  175. package/src/plan-draft.ts +0 -502
  176. package/src/remove-path.ts +0 -32
  177. package/src/route-policy.ts +0 -545
  178. package/src/run-state.ts +0 -420
  179. package/src/run-store.ts +0 -1179
  180. package/src/safe-path.ts +0 -77
  181. package/src/scoped-grep-worker.mjs +0 -23
  182. package/src/scoped-tools.ts +0 -775
  183. package/src/single-task-draft.ts +0 -142
  184. package/src/sqlite-schema.ts +0 -171
  185. package/src/state-root.ts +0 -215
  186. package/src/storage-schema.ts +0 -360
  187. package/src/subagent-activity.ts +0 -1417
  188. package/src/submit-tool.ts +0 -950
  189. package/src/task-ledger.ts +0 -1338
  190. package/src/transport-budget.ts +0 -52
  191. package/src/verification-capability.ts +0 -1191
  192. package/src/verification-environment-io.ts +0 -389
  193. package/src/verification-environment.ts +0 -162
  194. package/src/verification-identity.ts +0 -77
  195. package/src/verification-scan.ts +0 -64
  196. package/src/windows-job-backend.ts +0 -419
  197. package/src/windows-job.c +0 -149
  198. package/src/worker-broker.ts +0 -806
  199. package/src/workflow-engine.ts +0 -28
  200. package/src/workflow-policy.ts +0 -1679
  201. package/src/workflow-recovery-policy.ts +0 -97
  202. package/src/workflow-scheduling.ts +0 -105
  203. package/src/workflow-state-machine.ts +0 -4355
  204. package/src/workflow-status.ts +0 -576
  205. package/src/workspace-io-entry.mjs +0 -76
  206. package/src/workspace-io-worker.mjs +0 -1312
  207. package/src/workspace-io.ts +0 -89
  208. package/src/workspace-store.ts +0 -634
@@ -1,486 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { lstatSync, readFileSync } from "node:fs";
3
- import path from "node:path";
4
- import { isValidRelativePath } from "./contracts.ts";
5
- import {
6
- assessDeliveryTraceability,
7
- compileImplementPlan,
8
- DeliveryValidationError,
9
- type GateApprovalProof,
10
- parseGateAReceipt,
11
- parseImplementPlan,
12
- parseReadyReceipt,
13
- } from "./delivery-compiler.ts";
14
- import { canonicalJson, hashCanonicalValue } from "./implement-graph.ts";
15
- import {
16
- inspectOpenSpecDelivery,
17
- type OpenSpecCliOptions,
18
- type OpenSpecDeliveryInspection,
19
- } from "./openspec-cli.ts";
20
- import { observeSafePath } from "./safe-path.ts";
21
- import type {
22
- WorkflowAvailableDelivery,
23
- WorkflowDeliverySource,
24
- } from "./workflow-engine.ts";
25
-
26
- function sha256(value: Uint8Array | string): string {
27
- return createHash("sha256").update(value).digest("hex");
28
- }
29
-
30
- export interface PackageDeliverySourceOptions {
31
- inspectOpenSpec?: (
32
- consumerRoot: string,
33
- change: string,
34
- options?: OpenSpecCliOptions,
35
- ) => Promise<OpenSpecDeliveryInspection>;
36
- verifyGateProof?: (input: {
37
- change: string;
38
- gate: "gate-a" | "gate-b";
39
- proof: GateApprovalProof;
40
- }) => boolean;
41
- verifyFinalizedDelivery?: (input: {
42
- change: string;
43
- deliveryRevision: number;
44
- receiptHash: string;
45
- gateA: GateApprovalProof;
46
- gateB: GateApprovalProof;
47
- planCanonicalHash: string;
48
- }) => boolean;
49
- }
50
-
51
- export interface PackageWorkflowDeliverySource extends WorkflowDeliverySource {
52
- discoverLatest(input: {
53
- stage: "abel-implement";
54
- change: string;
55
- }): Promise<WorkflowAvailableDelivery | undefined>;
56
- }
57
-
58
- function proofVerified(verify: () => boolean): boolean {
59
- try {
60
- return verify() === true;
61
- } catch {
62
- return false;
63
- }
64
- }
65
-
66
- function normalizedTrackingArtifact(
67
- bytes: Uint8Array,
68
- taskIds: readonly string[],
69
- ): Buffer | undefined {
70
- let text: string;
71
- try {
72
- text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
73
- } catch {
74
- return undefined;
75
- }
76
- const identities = taskIds.map((taskId) => ({
77
- taskId,
78
- pattern: new RegExp(
79
- `(?:^|[^A-Za-z0-9._:-])${taskId.replace(
80
- /[.*+?^${}()|[\]\\]/gu,
81
- "\\$&",
82
- )}(?![A-Za-z0-9._:-])`,
83
- "u",
84
- ),
85
- matches: 0,
86
- }));
87
- const normalized = text
88
- .split(/(?<=\n)/u)
89
- .map((segment) => {
90
- const line = segment.endsWith("\n") ? segment.slice(0, -1) : segment;
91
- if (!/^\s*-\s+\[[ xX]\]/u.test(line)) return segment;
92
- const matching = identities.filter(({ pattern }) => pattern.test(line));
93
- if (matching.length !== 1) return segment;
94
- matching[0].matches += 1;
95
- return segment.replace(/^(\s*-\s+)\[[xX]\]/u, "$1[ ]");
96
- })
97
- .join("");
98
- if (identities.some(({ matches }) => matches !== 1)) return undefined;
99
- return Buffer.from(normalized, "utf8");
100
- }
101
-
102
- function readPackageDeliveryFile(
103
- root: string,
104
- relative: string,
105
- maximumBytes = PACKAGE_DELIVERY_MAX_BYTES,
106
- ): Buffer {
107
- const observation = observeSafePath(root, relative);
108
- if (observation.kind !== "file") {
109
- throw new Error("delivery-file-unavailable");
110
- }
111
- const target = path.join(root, ...relative.split("/"));
112
- const stat = lstatSync(target);
113
- if (stat.size < 1 || stat.size > maximumBytes) {
114
- throw new Error("delivery-file-size-invalid");
115
- }
116
- return readFileSync(target);
117
- }
118
-
119
- export function packageDeliverySource(
120
- consumerRoot: string,
121
- options: PackageDeliverySourceOptions = {},
122
- ): PackageWorkflowDeliverySource {
123
- const inspect = options.inspectOpenSpec ?? inspectOpenSpecDelivery;
124
- const verifyGateProof = options.verifyGateProof;
125
- const verifyFinalizedDelivery = options.verifyFinalizedDelivery;
126
- return {
127
- async discoverLatest(input) {
128
- if (
129
- input.stage !== "abel-implement" ||
130
- !verifyGateProof ||
131
- !verifyFinalizedDelivery
132
- ) {
133
- return undefined;
134
- }
135
- try {
136
- const changeRoot = `openspec/changes/${input.change}`;
137
- const receiptBytes = readPackageDeliveryFile(
138
- consumerRoot,
139
- `${changeRoot}/ready.yaml`,
140
- 4 * 1024 * 1024,
141
- );
142
- const receipt = parseReadyReceipt(receiptBytes, {
143
- allowLegacyOrder: true,
144
- });
145
- if (receipt.change !== input.change) return undefined;
146
- const gateABytes = readPackageDeliveryFile(
147
- consumerRoot,
148
- `${changeRoot}/${receipt.approvals.gateA.path}`,
149
- 4 * 1024 * 1024,
150
- );
151
- if (sha256(gateABytes) !== receipt.approvals.gateA.rawSha256) {
152
- return undefined;
153
- }
154
- const gateA = parseGateAReceipt(gateABytes, { allowLegacyOrder: true });
155
- if (
156
- gateA.change !== receipt.change ||
157
- gateA.schema !== receipt.schema ||
158
- !proofVerified(() =>
159
- verifyGateProof({
160
- change: input.change,
161
- gate: "gate-a",
162
- proof: gateA.approval,
163
- }),
164
- ) ||
165
- !proofVerified(() =>
166
- verifyGateProof({
167
- change: input.change,
168
- gate: "gate-b",
169
- proof: receipt.approvals.gateB,
170
- }),
171
- )
172
- ) {
173
- return undefined;
174
- }
175
- const receiptHash = sha256(receiptBytes);
176
- if (
177
- !proofVerified(() =>
178
- verifyFinalizedDelivery({
179
- change: input.change,
180
- deliveryRevision: receipt.deliveryRevision,
181
- receiptHash,
182
- gateA: gateA.approval,
183
- gateB: receipt.approvals.gateB,
184
- planCanonicalHash: receipt.plan.canonicalHash,
185
- }),
186
- )
187
- ) {
188
- return undefined;
189
- }
190
- return {
191
- deliveryRevision: receipt.deliveryRevision,
192
- receiptHash,
193
- };
194
- } catch {
195
- return undefined;
196
- }
197
- },
198
- async load(input) {
199
- if (input.stage !== "abel-implement") {
200
- throw new DeliveryValidationError(["delivery-stage-invalid"]);
201
- }
202
- const changeRoot = `openspec/changes/${input.change}`;
203
- const receiptRelative = `${changeRoot}/ready.yaml`;
204
- const planRelative = `${changeRoot}/implement-plan.json`;
205
- let receiptBytes: Buffer;
206
- try {
207
- receiptBytes = readPackageDeliveryFile(
208
- consumerRoot,
209
- receiptRelative,
210
- 4 * 1024 * 1024,
211
- );
212
- } catch {
213
- throw new DeliveryValidationError(["delivery-receipt-unavailable"]);
214
- }
215
- let receipt: ReturnType<typeof parseReadyReceipt>;
216
- try {
217
- receipt = parseReadyReceipt(receiptBytes, { allowLegacyOrder: true });
218
- } catch {
219
- throw new DeliveryValidationError([
220
- "delivery-receipt-invalid",
221
- "delivery-recompile-required",
222
- ]);
223
- }
224
- const diagnostics = new Set<string>();
225
- if (receipt.change !== input.change) {
226
- diagnostics.add("delivery-change-mismatch");
227
- }
228
- const receiptHash = sha256(receiptBytes);
229
- if (
230
- (input.deliveryRevision !== undefined &&
231
- input.deliveryRevision !== receipt.deliveryRevision) ||
232
- (input.receiptHash !== undefined && input.receiptHash !== receiptHash)
233
- ) {
234
- diagnostics.add("delivery-revision-mismatch");
235
- }
236
-
237
- let inspection: OpenSpecDeliveryInspection | undefined;
238
- try {
239
- inspection = await inspect(consumerRoot, input.change, {
240
- signal: input.signal,
241
- });
242
- } catch {
243
- diagnostics.add("delivery-openspec-unavailable");
244
- }
245
- input.signal?.throwIfAborted();
246
- if (inspection) {
247
- if (!inspection.strictValid) {
248
- diagnostics.add("delivery-openspec-strict-invalid");
249
- }
250
- if (!inspection.planningComplete) {
251
- diagnostics.add("delivery-openspec-incomplete");
252
- }
253
- if (inspection.schema !== receipt.schema) {
254
- diagnostics.add("delivery-schema-mismatch");
255
- }
256
- }
257
-
258
- let gateABytes: Buffer | undefined;
259
- let gateA: ReturnType<typeof parseGateAReceipt> | undefined;
260
- try {
261
- gateABytes = readPackageDeliveryFile(
262
- consumerRoot,
263
- `${changeRoot}/${receipt.approvals.gateA.path}`,
264
- 4 * 1024 * 1024,
265
- );
266
- if (sha256(gateABytes) !== receipt.approvals.gateA.rawSha256) {
267
- diagnostics.add("delivery-gate-a-hash-mismatch");
268
- }
269
- gateA = parseGateAReceipt(gateABytes, { allowLegacyOrder: true });
270
- if (
271
- gateA.change !== receipt.change ||
272
- gateA.schema !== receipt.schema
273
- ) {
274
- diagnostics.add("delivery-gate-a-binding-mismatch");
275
- }
276
- } catch {
277
- diagnostics.add("delivery-gate-a-invalid");
278
- }
279
-
280
- const artifactBytes = new Map<string, Buffer>();
281
- const artifactHashes = new Map(
282
- receipt.artifacts.map((artifact) => [
283
- artifact.path,
284
- artifact.rawSha256,
285
- ]),
286
- );
287
- for (const artifact of receipt.artifacts) {
288
- try {
289
- const bytes = readPackageDeliveryFile(
290
- consumerRoot,
291
- `${changeRoot}/${artifact.path}`,
292
- );
293
- artifactBytes.set(artifact.path, bytes);
294
- if (
295
- artifact.path !== receipt.traceability.taskPath &&
296
- sha256(bytes) !== artifact.rawSha256
297
- ) {
298
- diagnostics.add(`delivery-artifact-hash-mismatch:${artifact.path}`);
299
- }
300
- } catch {
301
- diagnostics.add(`delivery-artifact-unavailable:${artifact.path}`);
302
- }
303
- }
304
- if (inspection) {
305
- const covered = new Set(receipt.artifacts.map((entry) => entry.path));
306
- const expected = new Set(inspection.artifactPaths);
307
- for (const relative of expected) {
308
- if (!isValidRelativePath(relative) || !covered.has(relative)) {
309
- diagnostics.add(`delivery-artifact-unbound:${relative}`);
310
- }
311
- }
312
- for (const relative of covered) {
313
- if (!expected.has(relative)) {
314
- diagnostics.add(`delivery-artifact-not-in-openspec:${relative}`);
315
- }
316
- }
317
- }
318
- if (gateA) {
319
- if (!verifyGateProof) {
320
- diagnostics.add("delivery-gate-proof-verifier-unavailable");
321
- } else if (
322
- !proofVerified(() =>
323
- verifyGateProof({
324
- change: input.change,
325
- gate: "gate-a",
326
- proof: gateA.approval,
327
- }),
328
- )
329
- ) {
330
- diagnostics.add("delivery-gate-a-proof-invalid");
331
- }
332
- for (const artifact of gateA.artifacts) {
333
- if (artifactHashes.get(artifact.path) !== artifact.rawSha256) {
334
- diagnostics.add(
335
- `delivery-gate-a-artifact-mismatch:${artifact.path}`,
336
- );
337
- }
338
- }
339
- }
340
- if (
341
- verifyGateProof &&
342
- !proofVerified(() =>
343
- verifyGateProof({
344
- change: input.change,
345
- gate: "gate-b",
346
- proof: receipt.approvals.gateB,
347
- }),
348
- )
349
- ) {
350
- diagnostics.add("delivery-gate-b-proof-invalid");
351
- }
352
- if (gateA) {
353
- if (!verifyFinalizedDelivery) {
354
- diagnostics.add("delivery-finalization-verifier-unavailable");
355
- } else if (
356
- !proofVerified(() =>
357
- verifyFinalizedDelivery({
358
- change: input.change,
359
- deliveryRevision: receipt.deliveryRevision,
360
- receiptHash,
361
- gateA: gateA.approval,
362
- gateB: receipt.approvals.gateB,
363
- planCanonicalHash: receipt.plan.canonicalHash,
364
- }),
365
- )
366
- ) {
367
- diagnostics.add("delivery-finalization-proof-invalid");
368
- }
369
- }
370
-
371
- let plan: ReturnType<typeof parseImplementPlan> | undefined;
372
- let planBytes: Buffer | undefined;
373
- try {
374
- planBytes = readPackageDeliveryFile(consumerRoot, planRelative);
375
- plan = parseImplementPlan(planBytes, { allowLegacyOrder: true });
376
- } catch {
377
- diagnostics.add("delivery-plan-invalid");
378
- }
379
- if (plan && planBytes) {
380
- if (plan.changeId !== input.change) {
381
- diagnostics.add("delivery-plan-change-mismatch");
382
- }
383
- let compiled: ReturnType<typeof compileImplementPlan> | undefined;
384
- try {
385
- compiled = compileImplementPlan(plan, { consumerRoot });
386
- } catch {
387
- diagnostics.add("delivery-verification-closure-invalid");
388
- }
389
- if (
390
- receipt.plan.path !== "implement-plan.json" ||
391
- receipt.plan.rawSha256 !== sha256(planBytes) ||
392
- receipt.plan.canonicalHash !== hashCanonicalValue(plan)
393
- ) {
394
- diagnostics.add("delivery-plan-binding-invalid");
395
- }
396
- if (
397
- compiled &&
398
- canonicalJson(compiled.closure) !==
399
- canonicalJson(receipt.verificationClosure)
400
- ) {
401
- diagnostics.add("delivery-verification-closure-mismatch");
402
- }
403
- }
404
-
405
- if (plan) {
406
- const tasksBytes = artifactBytes.get(receipt.traceability.taskPath);
407
- const expectedTasksHash = artifactHashes.get(
408
- receipt.traceability.taskPath,
409
- );
410
- if (
411
- tasksBytes &&
412
- expectedTasksHash &&
413
- sha256(tasksBytes) !== expectedTasksHash
414
- ) {
415
- const normalized = normalizedTrackingArtifact(
416
- tasksBytes,
417
- plan.tracking.taskIds,
418
- );
419
- if (!normalized || sha256(normalized) !== expectedTasksHash) {
420
- diagnostics.add(
421
- `delivery-artifact-hash-mismatch:${receipt.traceability.taskPath}`,
422
- );
423
- }
424
- }
425
- const specs = [...artifactBytes]
426
- .filter(
427
- ([relative]) =>
428
- relative.startsWith("specs/") && relative.endsWith("/spec.md"),
429
- )
430
- .flatMap(([relative, bytes]) => {
431
- try {
432
- return [
433
- {
434
- path: relative,
435
- text: new TextDecoder("utf-8", { fatal: true }).decode(bytes),
436
- },
437
- ];
438
- } catch {
439
- diagnostics.add(`delivery-artifact-encoding-invalid:${relative}`);
440
- return [];
441
- }
442
- });
443
- if (!tasksBytes || specs.length === 0) {
444
- diagnostics.add("delivery-traceability-input-unavailable");
445
- } else {
446
- try {
447
- const traceability = assessDeliveryTraceability({
448
- tasksMarkdown: new TextDecoder("utf-8", { fatal: true }).decode(
449
- tasksBytes,
450
- ),
451
- specs,
452
- plan,
453
- });
454
- if (!traceability.ok) {
455
- for (const diagnostic of traceability.diagnostics) {
456
- diagnostics.add(diagnostic);
457
- }
458
- } else if (
459
- canonicalJson(traceability.value) !==
460
- canonicalJson(receipt.traceability)
461
- ) {
462
- diagnostics.add("delivery-traceability-binding-mismatch");
463
- }
464
- } catch {
465
- diagnostics.add("delivery-traceability-invalid");
466
- }
467
- }
468
- }
469
- if (!plan || !gateA || diagnostics.size > 0) {
470
- throw new DeliveryValidationError([...diagnostics]);
471
- }
472
- return {
473
- gate: "gate-b",
474
- revision: receipt.deliveryRevision,
475
- receiptHash,
476
- plan,
477
- approvalProofs: {
478
- gateA: structuredClone(gateA.approval),
479
- gateB: structuredClone(receipt.approvals.gateB),
480
- },
481
- };
482
- },
483
- };
484
- }
485
-
486
- const PACKAGE_DELIVERY_MAX_BYTES = 16 * 1024 * 1024;