@aviaratech/ai-delivery 0.3.34 → 0.3.36

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 (301) hide show
  1. package/CONTRIBUTING.md +12 -206
  2. package/README.md +57 -506
  3. package/dist/agent.d.ts +0 -2
  4. package/dist/agent.js +76 -16
  5. package/dist/agent.js.map +7 -1
  6. package/dist/agentReadiness.test.js +73 -67
  7. package/dist/agentReadiness.test.js.map +7 -1
  8. package/dist/boardReconcile.test.js +1746 -0
  9. package/dist/boardReconcile.test.js.map +7 -0
  10. package/dist/build.test.js +130 -0
  11. package/dist/build.test.js.map +7 -0
  12. package/dist/callerErrors.test.js +105 -0
  13. package/dist/callerErrors.test.js.map +7 -0
  14. package/dist/cli.js +406 -485
  15. package/dist/cli.js.map +7 -1
  16. package/dist/cliResult.d.ts +2 -2
  17. package/dist/cliResult.js +42 -25
  18. package/dist/cliResult.js.map +7 -1
  19. package/dist/cliResult.test.js +434 -297
  20. package/dist/cliResult.test.js.map +7 -1
  21. package/dist/config/deliveryConfig.d.ts +320 -14
  22. package/dist/config/deliveryConfig.js +472 -385
  23. package/dist/config/deliveryConfig.js.map +7 -1
  24. package/dist/config/deliveryConfig.test.js +775 -584
  25. package/dist/config/deliveryConfig.test.js.map +7 -1
  26. package/dist/contributorChecks.test.js +1694 -916
  27. package/dist/contributorChecks.test.js.map +7 -1
  28. package/dist/currentConsumer.test.js +819 -737
  29. package/dist/currentConsumer.test.js.map +7 -1
  30. package/dist/currentTrackingScenario.test.js +499 -477
  31. package/dist/currentTrackingScenario.test.js.map +7 -1
  32. package/dist/delivery/common.js +160 -172
  33. package/dist/delivery/common.js.map +7 -1
  34. package/dist/delivery/delivery.test.js +509 -431
  35. package/dist/delivery/delivery.test.js.map +7 -1
  36. package/dist/delivery/evidence.d.ts +2 -2
  37. package/dist/delivery/evidence.js +133 -120
  38. package/dist/delivery/evidence.js.map +7 -1
  39. package/dist/delivery/index.js +7 -2
  40. package/dist/delivery/index.js.map +7 -1
  41. package/dist/delivery/legacy.js +65 -5
  42. package/dist/delivery/legacy.js.map +7 -1
  43. package/dist/delivery/policy.d.ts +10 -10
  44. package/dist/delivery/policy.js +211 -238
  45. package/dist/delivery/policy.js.map +7 -1
  46. package/dist/delivery/stage.d.ts +18 -18
  47. package/dist/delivery/stage.js +220 -235
  48. package/dist/delivery/stage.js.map +7 -1
  49. package/dist/deliveryBoard.d.ts +74 -0
  50. package/dist/deliveryBoard.js +644 -0
  51. package/dist/deliveryBoard.js.map +7 -0
  52. package/dist/deliveryBoard.test.d.ts +1 -0
  53. package/dist/deliveryBoard.test.js +649 -0
  54. package/dist/deliveryBoard.test.js.map +7 -0
  55. package/dist/deliveryHealth.test.js +179 -155
  56. package/dist/deliveryHealth.test.js.map +7 -1
  57. package/dist/dependencyCompatibility.test.js +154 -140
  58. package/dist/dependencyCompatibility.test.js.map +7 -1
  59. package/dist/directoryIndependent.test.js +417 -383
  60. package/dist/directoryIndependent.test.js.map +7 -1
  61. package/dist/dispatch.d.ts +17 -12
  62. package/dist/dispatch.js +330 -322
  63. package/dist/dispatch.js.map +7 -1
  64. package/dist/errors.d.ts +16 -3
  65. package/dist/errors.js +104 -82
  66. package/dist/errors.js.map +7 -1
  67. package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
  68. package/dist/fixtures/deliveryBoardReplay.js +617 -0
  69. package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
  70. package/dist/fixtures/discovery.d.ts +59 -19
  71. package/dist/fixtures/discovery.js +96 -90
  72. package/dist/fixtures/discovery.js.map +7 -1
  73. package/dist/fixtures/inertEntrypointChild.js +57 -56
  74. package/dist/fixtures/inertEntrypointChild.js.map +7 -1
  75. package/dist/fixtures/inertEntrypoints.d.ts +1 -1
  76. package/dist/fixtures/inertEntrypoints.js +321 -276
  77. package/dist/fixtures/inertEntrypoints.js.map +7 -1
  78. package/dist/fixtures/inertTarget.d.ts +78 -7
  79. package/dist/fixtures/inertTarget.js +769 -691
  80. package/dist/fixtures/inertTarget.js.map +7 -1
  81. package/dist/fixtures/issue63.d.ts +4 -3
  82. package/dist/fixtures/issue63.js +260 -274
  83. package/dist/fixtures/issue63.js.map +7 -1
  84. package/dist/fixtures/issueProjectItems.d.ts +20 -0
  85. package/dist/fixtures/issueProjectItems.js +15 -0
  86. package/dist/fixtures/issueProjectItems.js.map +7 -0
  87. package/dist/fixtures/readView.d.ts +120 -0
  88. package/dist/fixtures/readView.js +172 -0
  89. package/dist/fixtures/readView.js.map +7 -0
  90. package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
  91. package/dist/fixtures/recordedGitHubFlows.js +109 -0
  92. package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
  93. package/dist/genericCompatibility.test.js +64 -55
  94. package/dist/genericCompatibility.test.js.map +7 -1
  95. package/dist/git.js +73 -67
  96. package/dist/git.js.map +7 -1
  97. package/dist/gitProcess.d.ts +1 -1
  98. package/dist/gitProcess.js +58 -53
  99. package/dist/gitProcess.js.map +7 -1
  100. package/dist/github/client.d.ts +2 -2
  101. package/dist/github/client.js +484 -379
  102. package/dist/github/client.js.map +7 -1
  103. package/dist/github/commandIdentityPolicy.js +44 -51
  104. package/dist/github/commandIdentityPolicy.js.map +7 -1
  105. package/dist/github/discovery.d.ts +3 -0
  106. package/dist/github/discovery.js +197 -201
  107. package/dist/github/discovery.js.map +7 -1
  108. package/dist/github/discovery.test.js +223 -177
  109. package/dist/github/discovery.test.js.map +7 -1
  110. package/dist/github/issueHistory.d.ts +2 -2
  111. package/dist/github/issueHistory.js +117 -125
  112. package/dist/github/issueHistory.js.map +7 -1
  113. package/dist/github/machineAuth.d.ts +1 -1
  114. package/dist/github/machineAuth.js +126 -117
  115. package/dist/github/machineAuth.js.map +7 -1
  116. package/dist/github/machineAuth.test.js +755 -639
  117. package/dist/github/machineAuth.test.js.map +7 -1
  118. package/dist/github/nativeIssueMetadata.js +286 -273
  119. package/dist/github/nativeIssueMetadata.js.map +7 -1
  120. package/dist/github/projectDelivery.d.ts +53 -1
  121. package/dist/github/projectDelivery.js +623 -460
  122. package/dist/github/projectDelivery.js.map +7 -1
  123. package/dist/github/relationships.d.ts +5 -2
  124. package/dist/github/relationships.js +434 -333
  125. package/dist/github/relationships.js.map +7 -1
  126. package/dist/github/repo.d.ts +1 -0
  127. package/dist/github/repo.js +123 -96
  128. package/dist/github/repo.js.map +7 -1
  129. package/dist/index.js +3 -3
  130. package/dist/index.js.map +7 -1
  131. package/dist/issue.d.ts +103 -7
  132. package/dist/issue.js +2104 -1547
  133. package/dist/issue.js.map +7 -1
  134. package/dist/issue63History.test.js +40 -42
  135. package/dist/issue63History.test.js.map +7 -1
  136. package/dist/issue63Routes.test.js +154 -143
  137. package/dist/issue63Routes.test.js.map +7 -1
  138. package/dist/issueBatchUpdate.test.js +1004 -683
  139. package/dist/issueBatchUpdate.test.js.map +7 -1
  140. package/dist/issueBlockerGuard.test.js +262 -226
  141. package/dist/issueBlockerGuard.test.js.map +7 -1
  142. package/dist/issueContract.d.ts +23 -4
  143. package/dist/issueContract.js +416 -395
  144. package/dist/issueContract.js.map +7 -1
  145. package/dist/issueContract.test.d.ts +4 -3
  146. package/dist/issueContract.test.js +358 -321
  147. package/dist/issueContract.test.js.map +7 -1
  148. package/dist/issueDates.test.js +235 -233
  149. package/dist/issueDates.test.js.map +7 -1
  150. package/dist/issueInfoReadback.test.js +304 -190
  151. package/dist/issueInfoReadback.test.js.map +7 -1
  152. package/dist/issueIntake.test.js +1945 -1732
  153. package/dist/issueIntake.test.js.map +7 -1
  154. package/dist/issueJournal.d.ts +40 -19
  155. package/dist/issueJournal.js +229 -138
  156. package/dist/issueJournal.js.map +7 -1
  157. package/dist/issueJournal.test.js +605 -422
  158. package/dist/issueJournal.test.js.map +7 -1
  159. package/dist/issueRollup.test.d.ts +1 -0
  160. package/dist/issueRollup.test.js +476 -0
  161. package/dist/issueRollup.test.js.map +7 -0
  162. package/dist/issueTracking.test.js +1088 -593
  163. package/dist/issueTracking.test.js.map +7 -1
  164. package/dist/issueWriteRecovery.test.d.ts +1 -0
  165. package/dist/issueWriteRecovery.test.js +260 -0
  166. package/dist/issueWriteRecovery.test.js.map +7 -0
  167. package/dist/lifecycle.test.js +112 -441
  168. package/dist/lifecycle.test.js.map +7 -1
  169. package/dist/logger.js +80 -74
  170. package/dist/logger.js.map +7 -1
  171. package/dist/mcp/index.js +116 -90
  172. package/dist/mcp/index.js.map +7 -1
  173. package/dist/mcp/tools.d.ts +790 -220
  174. package/dist/mcp/tools.js +267 -333
  175. package/dist/mcp/tools.js.map +7 -1
  176. package/dist/pluginAuthProbe.js +63 -52
  177. package/dist/pluginAuthProbe.js.map +7 -1
  178. package/dist/pluginAuthProbe.test.js +85 -62
  179. package/dist/pluginAuthProbe.test.js.map +7 -1
  180. package/dist/pluginCredentials.test.js +282 -259
  181. package/dist/pluginCredentials.test.js.map +7 -1
  182. package/dist/pluginDoctor.test.js +653 -588
  183. package/dist/pluginDoctor.test.js.map +7 -1
  184. package/dist/pluginInstaller.d.ts +7 -5
  185. package/dist/pluginInstaller.js +1173 -1231
  186. package/dist/pluginInstaller.js.map +7 -1
  187. package/dist/pluginInstaller.test.js +1822 -1283
  188. package/dist/pluginInstaller.test.js.map +7 -1
  189. package/dist/pluginPackaging.test.js +485 -305
  190. package/dist/pluginPackaging.test.js.map +7 -1
  191. package/dist/pr.d.ts +132 -94
  192. package/dist/pr.js +1521 -1323
  193. package/dist/pr.js.map +7 -1
  194. package/dist/pr.test.js +1678 -632
  195. package/dist/pr.test.js.map +7 -1
  196. package/dist/prAssociation.test.js +2419 -1788
  197. package/dist/prAssociation.test.js.map +7 -1
  198. package/dist/prDispatch.test.js +150 -89
  199. package/dist/prDispatch.test.js.map +7 -1
  200. package/dist/readView.d.ts +183 -0
  201. package/dist/readView.js +217 -0
  202. package/dist/readView.js.map +7 -0
  203. package/dist/readView.test.d.ts +1 -0
  204. package/dist/readView.test.js +119 -0
  205. package/dist/readView.test.js.map +7 -0
  206. package/dist/releaseReconciliation.test.js +267 -288
  207. package/dist/releaseReconciliation.test.js.map +7 -1
  208. package/dist/releaseWorkflow.test.js +2493 -422
  209. package/dist/releaseWorkflow.test.js.map +7 -1
  210. package/dist/review.d.ts +738 -2
  211. package/dist/review.js +601 -348
  212. package/dist/review.js.map +7 -1
  213. package/dist/review.test.js +1218 -812
  214. package/dist/review.test.js.map +7 -1
  215. package/dist/reviewSubmit.test.d.ts +1 -0
  216. package/dist/reviewSubmit.test.js +747 -0
  217. package/dist/reviewSubmit.test.js.map +7 -0
  218. package/dist/services/agentReadinessService.js +42 -37
  219. package/dist/services/agentReadinessService.js.map +7 -1
  220. package/dist/services/blockerGuardService.js +188 -188
  221. package/dist/services/blockerGuardService.js.map +7 -1
  222. package/dist/services/boardReconcileService.d.ts +1204 -0
  223. package/dist/services/boardReconcileService.js +1445 -0
  224. package/dist/services/boardReconcileService.js.map +7 -0
  225. package/dist/services/deliveryAdmission.d.ts +2 -0
  226. package/dist/services/deliveryAdmission.js +129 -152
  227. package/dist/services/deliveryAdmission.js.map +7 -1
  228. package/dist/services/deliveryHealthService.js +197 -199
  229. package/dist/services/deliveryHealthService.js.map +7 -1
  230. package/dist/services/legacyIssueMigration.js +263 -277
  231. package/dist/services/legacyIssueMigration.js.map +7 -1
  232. package/dist/services/worktreeRegistry.d.ts +27 -119
  233. package/dist/services/worktreeRegistry.js +765 -1182
  234. package/dist/services/worktreeRegistry.js.map +7 -1
  235. package/dist/stagedChecks.test.js +396 -194
  236. package/dist/stagedChecks.test.js.map +7 -1
  237. package/dist/start.test.js +99 -95
  238. package/dist/start.test.js.map +7 -1
  239. package/dist/stdoutRegression.test.js +354 -350
  240. package/dist/stdoutRegression.test.js.map +7 -1
  241. package/dist/targetPolicyDiscovery.test.js +141 -143
  242. package/dist/targetPolicyDiscovery.test.js.map +7 -1
  243. package/dist/targetPolicyEntrypoints.test.js +308 -269
  244. package/dist/targetPolicyEntrypoints.test.js.map +7 -1
  245. package/dist/targetPolicyLocal.test.js +580 -1051
  246. package/dist/targetPolicyLocal.test.js.map +7 -1
  247. package/dist/targetPolicyRoutes.test.js +305 -281
  248. package/dist/targetPolicyRoutes.test.js.map +7 -1
  249. package/dist/targetRepositoryExecution.test.d.ts +1 -0
  250. package/dist/targetRepositoryExecution.test.js +463 -0
  251. package/dist/targetRepositoryExecution.test.js.map +7 -0
  252. package/dist/terminalMessages.js +41 -35
  253. package/dist/terminalMessages.js.map +7 -1
  254. package/dist/toolOutput.d.ts +2 -0
  255. package/dist/toolOutput.js +36 -0
  256. package/dist/toolOutput.js.map +7 -0
  257. package/dist/toolOutput.test.d.ts +1 -0
  258. package/dist/toolOutput.test.js +240 -0
  259. package/dist/toolOutput.test.js.map +7 -0
  260. package/dist/utils/atomicJson.js +84 -76
  261. package/dist/utils/atomicJson.js.map +7 -1
  262. package/dist/utils/filesystem.js +15 -18
  263. package/dist/utils/filesystem.js.map +7 -1
  264. package/dist/utils/lockfile.js +68 -71
  265. package/dist/utils/lockfile.js.map +7 -1
  266. package/dist/verification.d.ts +1 -19
  267. package/dist/verification.js +1020 -1929
  268. package/dist/verification.js.map +7 -1
  269. package/dist/verificationGate.test.js +127 -117
  270. package/dist/verificationGate.test.js.map +7 -1
  271. package/dist/version.d.ts +6 -0
  272. package/dist/version.js +24 -10
  273. package/dist/version.js.map +7 -1
  274. package/dist/worktree.d.ts +3 -15
  275. package/dist/worktree.js +97 -177
  276. package/dist/worktree.js.map +7 -1
  277. package/package.json +10 -8
  278. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  279. package/plugins/ai-delivery/README.md +47 -156
  280. package/plugins/ai-delivery/plugin.json +1 -1
  281. package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +261 -43
  282. package/plugins/ai-delivery/runtime/dist/cli.js +369 -125
  283. package/plugins/ai-delivery/runtime/package.json +1 -1
  284. package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
  285. package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
  286. package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
  287. package/dist/investigationCompletion.test.js +0 -728
  288. package/dist/investigationCompletion.test.js.map +0 -1
  289. package/dist/setup.d.ts +0 -60
  290. package/dist/setup.js +0 -585
  291. package/dist/setup.js.map +0 -1
  292. package/dist/setup.test.js +0 -3058
  293. package/dist/setup.test.js.map +0 -1
  294. package/dist/worktreeTransition.d.ts +0 -211
  295. package/dist/worktreeTransition.js +0 -1037
  296. package/dist/worktreeTransition.js.map +0 -1
  297. package/dist/worktreeTransition.test.js +0 -1191
  298. package/dist/worktreeTransition.test.js.map +0 -1
  299. /package/dist/{investigationCompletion.test.d.ts → boardReconcile.test.d.ts} +0 -0
  300. /package/dist/{setup.test.d.ts → build.test.d.ts} +0 -0
  301. /package/dist/{worktreeTransition.test.d.ts → callerErrors.test.d.ts} +0 -0
@@ -1,8 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import type { RepositoryClassificationReceipt } from './policy.js';
3
3
  export declare const RepositoryStageInputSchema: z.ZodUnion<readonly [z.ZodObject<{
4
- classificationReceiptId: z.ZodString;
5
- schemaVersion: z.ZodLiteral<"ai-delivery.stage-input@1">;
6
4
  definitionHash: z.ZodString;
7
5
  environmentDigest: z.ZodString;
8
6
  inputId: z.ZodString;
@@ -16,14 +14,9 @@ export declare const RepositoryStageInputSchema: z.ZodUnion<readonly [z.ZodObjec
16
14
  receiptId: z.ZodString;
17
15
  stageId: z.ZodString;
18
16
  }, z.core.$strict>>;
17
+ classificationReceiptId: z.ZodString;
18
+ schemaVersion: z.ZodLiteral<"ai-delivery.stage-input@1">;
19
19
  }, z.core.$strict>, z.ZodObject<{
20
- configDigest: z.ZodString;
21
- policyProducer: z.ZodString;
22
- policyArtifacts: z.ZodArray<z.ZodObject<{
23
- digest: z.ZodString;
24
- path: z.ZodString;
25
- }, z.core.$strict>>;
26
- schemaVersion: z.ZodLiteral<"ai-delivery.stage-input@2">;
27
20
  definitionHash: z.ZodString;
28
21
  environmentDigest: z.ZodString;
29
22
  inputId: z.ZodString;
@@ -37,6 +30,13 @@ export declare const RepositoryStageInputSchema: z.ZodUnion<readonly [z.ZodObjec
37
30
  receiptId: z.ZodString;
38
31
  stageId: z.ZodString;
39
32
  }, z.core.$strict>>;
33
+ configDigest: z.ZodString;
34
+ policyProducer: z.ZodString;
35
+ policyArtifacts: z.ZodArray<z.ZodObject<{
36
+ digest: z.ZodString;
37
+ path: z.ZodString;
38
+ }, z.core.$strict>>;
39
+ schemaVersion: z.ZodLiteral<"ai-delivery.stage-input@2">;
40
40
  }, z.core.$strict>]>;
41
41
  export type RepositoryStageInput = z.infer<typeof RepositoryStageInputSchema>;
42
42
  export declare const RepositoryStageReceiptSchema: z.ZodObject<{
@@ -51,8 +51,6 @@ export declare const RepositoryStageReceiptSchema: z.ZodObject<{
51
51
  }, z.core.$strict>>;
52
52
  completedAt: z.ZodISODateTime;
53
53
  input: z.ZodUnion<readonly [z.ZodObject<{
54
- classificationReceiptId: z.ZodString;
55
- schemaVersion: z.ZodLiteral<"ai-delivery.stage-input@1">;
56
54
  definitionHash: z.ZodString;
57
55
  environmentDigest: z.ZodString;
58
56
  inputId: z.ZodString;
@@ -66,14 +64,9 @@ export declare const RepositoryStageReceiptSchema: z.ZodObject<{
66
64
  receiptId: z.ZodString;
67
65
  stageId: z.ZodString;
68
66
  }, z.core.$strict>>;
67
+ classificationReceiptId: z.ZodString;
68
+ schemaVersion: z.ZodLiteral<"ai-delivery.stage-input@1">;
69
69
  }, z.core.$strict>, z.ZodObject<{
70
- configDigest: z.ZodString;
71
- policyProducer: z.ZodString;
72
- policyArtifacts: z.ZodArray<z.ZodObject<{
73
- digest: z.ZodString;
74
- path: z.ZodString;
75
- }, z.core.$strict>>;
76
- schemaVersion: z.ZodLiteral<"ai-delivery.stage-input@2">;
77
70
  definitionHash: z.ZodString;
78
71
  environmentDigest: z.ZodString;
79
72
  inputId: z.ZodString;
@@ -87,6 +80,13 @@ export declare const RepositoryStageReceiptSchema: z.ZodObject<{
87
80
  receiptId: z.ZodString;
88
81
  stageId: z.ZodString;
89
82
  }, z.core.$strict>>;
83
+ configDigest: z.ZodString;
84
+ policyProducer: z.ZodString;
85
+ policyArtifacts: z.ZodArray<z.ZodObject<{
86
+ digest: z.ZodString;
87
+ path: z.ZodString;
88
+ }, z.core.$strict>>;
89
+ schemaVersion: z.ZodLiteral<"ai-delivery.stage-input@2">;
90
90
  }, z.core.$strict>]>;
91
91
  receiptId: z.ZodString;
92
92
  result: z.ZodLiteral<"passed">;
@@ -1,257 +1,242 @@
1
- import { join } from 'node:path';
2
- import { z } from 'zod';
3
- import { assertArtifact, assertPrivateFile, DigestSchema, digestBytes, digestValue, isUniqueSorted, stableJson, StageIdSchema, writeCreateOnly, } from './common.js';
4
- import { assertRepositoryClassificationCurrent, RepositoryClassificationReceiptSchema } from './policy.js';
1
+ import { join } from "node:path";
2
+ import { z } from "zod";
3
+ import {
4
+ assertArtifact,
5
+ assertPrivateFile,
6
+ DigestSchema,
7
+ digestBytes,
8
+ digestValue,
9
+ isUniqueSorted,
10
+ stableJson,
11
+ StageIdSchema,
12
+ writeCreateOnly
13
+ } from "./common.js";
14
+ import { assertRepositoryClassificationCurrent, RepositoryClassificationReceiptSchema } from "./policy.js";
5
15
  const SemanticInputSchema = z.object({ digest: DigestSchema, key: z.string().min(1) }).strict();
6
16
  const UpstreamSchema = z.object({ receiptId: DigestSchema, stageId: StageIdSchema }).strict();
7
- const compareText = (left, right) => (left < right ? -1 : left > right ? 1 : 0);
17
+ const compareText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
8
18
  const StageInputFields = {
9
- definitionHash: DigestSchema,
10
- environmentDigest: DigestSchema,
11
- inputId: DigestSchema,
12
- policyDigest: DigestSchema,
13
- semanticInputs: z.array(SemanticInputSchema).min(1),
14
- stageId: StageIdSchema,
15
- upstream: z.array(UpstreamSchema),
19
+ definitionHash: DigestSchema,
20
+ environmentDigest: DigestSchema,
21
+ inputId: DigestSchema,
22
+ policyDigest: DigestSchema,
23
+ semanticInputs: z.array(SemanticInputSchema).min(1),
24
+ stageId: StageIdSchema,
25
+ upstream: z.array(UpstreamSchema)
16
26
  };
17
- export const RepositoryStageInputSchema = z
18
- .union([
19
- z.strictObject({
20
- ...StageInputFields,
21
- classificationReceiptId: DigestSchema,
22
- schemaVersion: z.literal('ai-delivery.stage-input@1'),
23
- }),
24
- z.strictObject({
25
- ...StageInputFields,
26
- configDigest: DigestSchema,
27
- policyProducer: z.string().min(1),
28
- policyArtifacts: z.array(z.strictObject({ digest: DigestSchema, path: z.string().min(1) })),
29
- schemaVersion: z.literal('ai-delivery.stage-input@2'),
30
- }),
31
- ])
32
- .superRefine((value, ctx) => {
33
- const { inputId, ...content } = value;
34
- if (inputId !== digestValue(content) ||
35
- !isUniqueSorted(value.semanticInputs.map((x) => x.key)) ||
36
- !isUniqueSorted(value.upstream.map((x) => x.stageId)) ||
37
- (value.schemaVersion === 'ai-delivery.stage-input@2' && !isUniqueSorted(value.policyArtifacts.map((x) => x.path))))
38
- ctx.addIssue({ code: 'custom', message: 'Stage input identity or inventory is invalid.' });
27
+ const RepositoryStageInputSchema = z.union([
28
+ z.strictObject({
29
+ ...StageInputFields,
30
+ classificationReceiptId: DigestSchema,
31
+ schemaVersion: z.literal("ai-delivery.stage-input@1")
32
+ }),
33
+ z.strictObject({
34
+ ...StageInputFields,
35
+ configDigest: DigestSchema,
36
+ policyProducer: z.string().min(1),
37
+ policyArtifacts: z.array(z.strictObject({ digest: DigestSchema, path: z.string().min(1) })),
38
+ schemaVersion: z.literal("ai-delivery.stage-input@2")
39
+ })
40
+ ]).superRefine((value, ctx) => {
41
+ const { inputId, ...content } = value;
42
+ if (inputId !== digestValue(content) || !isUniqueSorted(value.semanticInputs.map((x) => x.key)) || !isUniqueSorted(value.upstream.map((x) => x.stageId)) || value.schemaVersion === "ai-delivery.stage-input@2" && !isUniqueSorted(value.policyArtifacts.map((x) => x.path)))
43
+ ctx.addIssue({ code: "custom", message: "Stage input identity or inventory is invalid." });
39
44
  });
40
- export const RepositoryStageReceiptSchema = z
41
- .object({
42
- artifacts: z.array(z.object({ digest: DigestSchema, path: z.string().min(1) }).strict()),
43
- commands: z.array(z
44
- .object({ exitCode: z.number().int().nonnegative(), label: z.string().min(1), outputDigest: DigestSchema })
45
- .strict()),
46
- completedAt: z.iso.datetime(),
47
- input: RepositoryStageInputSchema,
48
- receiptId: DigestSchema,
49
- result: z.literal('passed'),
50
- schemaVersion: z.enum(['ai-delivery.stage-receipt@1', 'ai-delivery.stage-receipt@2']),
51
- startedAt: z.iso.datetime(),
52
- })
53
- .strict()
54
- .superRefine((value, ctx) => {
55
- const { receiptId, ...content } = value;
56
- if (receiptId !== digestValue(content) ||
57
- (value.schemaVersion === 'ai-delivery.stage-receipt@2') !==
58
- (value.input.schemaVersion === 'ai-delivery.stage-input@2') ||
59
- Date.parse(value.completedAt) < Date.parse(value.startedAt) ||
60
- value.commands.some((command) => command.exitCode !== 0) ||
61
- !isUniqueSorted(value.artifacts.map((a) => a.path)))
62
- ctx.addIssue({ code: 'custom', message: 'Stage receipt has incomplete or corrupt proof.' });
45
+ const RepositoryStageReceiptSchema = z.object({
46
+ artifacts: z.array(z.object({ digest: DigestSchema, path: z.string().min(1) }).strict()),
47
+ commands: z.array(
48
+ z.object({ exitCode: z.number().int().nonnegative(), label: z.string().min(1), outputDigest: DigestSchema }).strict()
49
+ ),
50
+ completedAt: z.iso.datetime(),
51
+ input: RepositoryStageInputSchema,
52
+ receiptId: DigestSchema,
53
+ result: z.literal("passed"),
54
+ schemaVersion: z.enum(["ai-delivery.stage-receipt@1", "ai-delivery.stage-receipt@2"]),
55
+ startedAt: z.iso.datetime()
56
+ }).strict().superRefine((value, ctx) => {
57
+ const { receiptId, ...content } = value;
58
+ if (receiptId !== digestValue(content) || value.schemaVersion === "ai-delivery.stage-receipt@2" !== (value.input.schemaVersion === "ai-delivery.stage-input@2") || Date.parse(value.completedAt) < Date.parse(value.startedAt) || value.commands.some((command) => command.exitCode !== 0) || !isUniqueSorted(value.artifacts.map((a) => a.path)))
59
+ ctx.addIssue({ code: "custom", message: "Stage receipt has incomplete or corrupt proof." });
63
60
  });
64
- export const RepositoryStageAggregateSchema = z
65
- .object({
66
- aggregateId: DigestSchema,
67
- classificationReceiptId: DigestSchema,
68
- policyDigest: DigestSchema,
69
- result: z.literal('passed'),
70
- schemaVersion: z.enum(['ai-delivery.stage-aggregate@1', 'ai-delivery.stage-aggregate@2']),
71
- stages: z
72
- .array(z.object({ inputId: DigestSchema, receiptId: DigestSchema, stageId: StageIdSchema }).strict())
73
- .min(1),
74
- })
75
- .strict()
76
- .superRefine((value, ctx) => {
77
- const { aggregateId, ...content } = value;
78
- if (aggregateId !== digestValue(content) ||
79
- new Set(value.stages.map((x) => x.stageId)).size !== value.stages.length)
80
- ctx.addIssue({ code: 'custom', message: 'Stage aggregate identity or inventory is invalid.' });
61
+ const RepositoryStageAggregateSchema = z.object({
62
+ aggregateId: DigestSchema,
63
+ classificationReceiptId: DigestSchema,
64
+ policyDigest: DigestSchema,
65
+ result: z.literal("passed"),
66
+ schemaVersion: z.enum(["ai-delivery.stage-aggregate@1", "ai-delivery.stage-aggregate@2"]),
67
+ stages: z.array(z.object({ inputId: DigestSchema, receiptId: DigestSchema, stageId: StageIdSchema }).strict()).min(1)
68
+ }).strict().superRefine((value, ctx) => {
69
+ const { aggregateId, ...content } = value;
70
+ if (aggregateId !== digestValue(content) || new Set(value.stages.map((x) => x.stageId)).size !== value.stages.length)
71
+ ctx.addIssue({ code: "custom", message: "Stage aggregate identity or inventory is invalid." });
81
72
  });
82
- export function createRepositoryStageInput(input) {
83
- const classification = RepositoryClassificationReceiptSchema.parse(input.classification);
84
- const definition = classification.requiredStages.find((stage) => stage.id === input.stageId);
85
- if (definition === undefined)
86
- throw new Error('Stage is absent from selected policy.');
87
- const semanticInputs = [...input.semanticInputs]
88
- .sort((a, b) => compareText(a.key, b.key))
89
- .map((x) => SemanticInputSchema.parse(x));
90
- const upstream = [...input.upstream]
91
- .sort((a, b) => compareText(a.stageId, b.stageId))
92
- .map((x) => UpstreamSchema.parse(x));
93
- if (stableJson(semanticInputs.map((x) => x.key)) !== stableJson(definition.semanticInputKeys) ||
94
- (classification.schemaVersion === 'ai-delivery.classification@2' &&
95
- stableJson(semanticInputs) !== stableJson(definition.semanticInputs)) ||
96
- stableJson(upstream.map((x) => x.stageId)) !== stableJson([...definition.dependsOn].sort()))
97
- throw new Error('Stage input lacks required semantic or upstream proof.');
98
- const content = {
99
- ...(classification.schemaVersion === 'ai-delivery.classification@1'
100
- ? { classificationReceiptId: classification.receiptId, schemaVersion: 'ai-delivery.stage-input@1' }
101
- : {
102
- configDigest: classification.configDigest,
103
- policyProducer: classification.policyEvidence.producer,
104
- schemaVersion: 'ai-delivery.stage-input@2',
105
- policyArtifacts: classification.policyEvidence.artifacts
106
- .filter((artifact) => artifact.path === definition.attestationKey)
107
- .map(({ digest, path }) => ({ digest, path })),
108
- }),
109
- definitionHash: digestValue(definition),
110
- environmentDigest: DigestSchema.parse(input.environmentDigest),
111
- policyDigest: classification.policyDigest,
112
- semanticInputs,
113
- stageId: definition.id,
114
- upstream,
115
- };
116
- return RepositoryStageInputSchema.parse({ ...content, inputId: digestValue(content) });
73
+ function createRepositoryStageInput(input) {
74
+ const classification = RepositoryClassificationReceiptSchema.parse(input.classification);
75
+ const definition = classification.requiredStages.find((stage) => stage.id === input.stageId);
76
+ if (definition === void 0) throw new Error("Stage is absent from selected policy.");
77
+ const semanticInputs = [...input.semanticInputs].sort((a, b) => compareText(a.key, b.key)).map((x) => SemanticInputSchema.parse(x));
78
+ const upstream = [...input.upstream].sort((a, b) => compareText(a.stageId, b.stageId)).map((x) => UpstreamSchema.parse(x));
79
+ if (stableJson(semanticInputs.map((x) => x.key)) !== stableJson(definition.semanticInputKeys) || classification.schemaVersion === "ai-delivery.classification@2" && stableJson(semanticInputs) !== stableJson(definition.semanticInputs) || stableJson(upstream.map((x) => x.stageId)) !== stableJson([...definition.dependsOn].sort()))
80
+ throw new Error("Stage input lacks required semantic or upstream proof.");
81
+ const content = {
82
+ ...classification.schemaVersion === "ai-delivery.classification@1" ? { classificationReceiptId: classification.receiptId, schemaVersion: "ai-delivery.stage-input@1" } : {
83
+ configDigest: classification.configDigest,
84
+ policyProducer: classification.policyEvidence.producer,
85
+ schemaVersion: "ai-delivery.stage-input@2",
86
+ policyArtifacts: classification.policyEvidence.artifacts.filter((artifact) => artifact.path === definition.attestationKey).map(({ digest, path }) => ({ digest, path }))
87
+ },
88
+ definitionHash: digestValue(definition),
89
+ environmentDigest: DigestSchema.parse(input.environmentDigest),
90
+ policyDigest: classification.policyDigest,
91
+ semanticInputs,
92
+ stageId: definition.id,
93
+ upstream
94
+ };
95
+ return RepositoryStageInputSchema.parse({ ...content, inputId: digestValue(content) });
117
96
  }
118
- export function createRepositoryStageReceipt(input) {
119
- const classification = RepositoryClassificationReceiptSchema.parse(input.classification);
120
- const stageInput = RepositoryStageInputSchema.parse(input.stageInput);
121
- const definition = classification.requiredStages.find((stage) => stage.id === stageInput.stageId);
122
- if (definition === undefined ||
123
- createRepositoryStageInput({
124
- classification,
125
- stageId: stageInput.stageId,
126
- environmentDigest: stageInput.environmentDigest,
127
- semanticInputs: stageInput.semanticInputs,
128
- upstream: stageInput.upstream,
129
- }).inputId !== stageInput.inputId ||
130
- (stageInput.schemaVersion === 'ai-delivery.stage-input@2' &&
131
- stableJson(input.artifacts) !== stableJson(stageInput.policyArtifacts)) ||
132
- input.commands.length !== definition.commands.length ||
133
- input.commands.some((command, index) => command.label !== definition.commands[index]?.label || command.exitCode !== 0) ||
134
- (definition.attestationKey !== undefined && input.artifacts.length === 0))
135
- throw new Error('Stage receipt does not prove selected definition.');
136
- const content = {
137
- artifacts: [...input.artifacts].sort((a, b) => compareText(a.path, b.path)),
138
- commands: input.commands.map((x) => ({ ...x })),
139
- completedAt: input.completedAt,
140
- input: stageInput,
141
- result: 'passed',
142
- schemaVersion: stageInput.schemaVersion === 'ai-delivery.stage-input@2'
143
- ? 'ai-delivery.stage-receipt@2'
144
- : 'ai-delivery.stage-receipt@1',
145
- startedAt: input.startedAt,
146
- };
147
- return RepositoryStageReceiptSchema.parse({ ...content, receiptId: digestValue(content) });
97
+ function createRepositoryStageReceipt(input) {
98
+ const classification = RepositoryClassificationReceiptSchema.parse(input.classification);
99
+ const stageInput = RepositoryStageInputSchema.parse(input.stageInput);
100
+ const definition = classification.requiredStages.find((stage) => stage.id === stageInput.stageId);
101
+ if (definition === void 0 || createRepositoryStageInput({
102
+ classification,
103
+ stageId: stageInput.stageId,
104
+ environmentDigest: stageInput.environmentDigest,
105
+ semanticInputs: stageInput.semanticInputs,
106
+ upstream: stageInput.upstream
107
+ }).inputId !== stageInput.inputId || stageInput.schemaVersion === "ai-delivery.stage-input@2" && stableJson(input.artifacts) !== stableJson(stageInput.policyArtifacts) || input.commands.length !== definition.commands.length || input.commands.some(
108
+ (command, index) => command.label !== definition.commands[index]?.label || command.exitCode !== 0
109
+ ) || definition.attestationKey !== void 0 && input.artifacts.length === 0)
110
+ throw new Error("Stage receipt does not prove selected definition.");
111
+ const content = {
112
+ artifacts: [...input.artifacts].sort((a, b) => compareText(a.path, b.path)),
113
+ commands: input.commands.map((x) => ({ ...x })),
114
+ completedAt: input.completedAt,
115
+ input: stageInput,
116
+ result: "passed",
117
+ schemaVersion: stageInput.schemaVersion === "ai-delivery.stage-input@2" ? "ai-delivery.stage-receipt@2" : "ai-delivery.stage-receipt@1",
118
+ startedAt: input.startedAt
119
+ };
120
+ return RepositoryStageReceiptSchema.parse({ ...content, receiptId: digestValue(content) });
148
121
  }
149
- export function createRepositoryStageAggregate(input) {
150
- const classification = RepositoryClassificationReceiptSchema.parse(input.classification);
151
- if (input.receipts.length !== classification.requiredStages.length)
152
- throw new Error('Aggregate requires every selected stage.');
153
- const receipts = input.receipts.map((receipt) => RepositoryStageReceiptSchema.parse(receipt));
154
- const byStage = new Map(receipts.map((receipt) => [receipt.input.stageId, receipt]));
155
- if (byStage.size !== receipts.length)
156
- throw new Error('Aggregate contains duplicate stages.');
157
- for (const definition of classification.requiredStages) {
158
- const receipt = byStage.get(definition.id);
159
- if (receipt === undefined ||
160
- stableJson(receipt.input.upstream) !==
161
- stableJson(definition.dependsOn
162
- .map((stageId) => ({ stageId, receiptId: byStage.get(stageId)?.receiptId }))
163
- .sort((a, b) => compareText(a.stageId, b.stageId))) ||
164
- createRepositoryStageReceipt({
165
- artifacts: receipt.artifacts,
166
- classification,
167
- commands: receipt.commands,
168
- completedAt: receipt.completedAt,
169
- stageInput: receipt.input,
170
- startedAt: receipt.startedAt,
171
- }).receiptId !== receipt.receiptId)
172
- throw new Error('Aggregate contains missing, foreign or stale stage proof.');
173
- }
174
- const content = {
175
- classificationReceiptId: classification.receiptId,
176
- policyDigest: classification.policyDigest,
177
- result: 'passed',
178
- schemaVersion: classification.schemaVersion === 'ai-delivery.classification@2'
179
- ? 'ai-delivery.stage-aggregate@2'
180
- : 'ai-delivery.stage-aggregate@1',
181
- stages: classification.requiredStages.map((stage) => {
182
- const receipt = byStage.get(stage.id);
183
- return { inputId: receipt.input.inputId, receiptId: receipt.receiptId, stageId: stage.id };
184
- }),
185
- };
186
- return RepositoryStageAggregateSchema.parse({ ...content, aggregateId: digestValue(content) });
122
+ function createRepositoryStageAggregate(input) {
123
+ const classification = RepositoryClassificationReceiptSchema.parse(input.classification);
124
+ if (input.receipts.length !== classification.requiredStages.length)
125
+ throw new Error("Aggregate requires every selected stage.");
126
+ const receipts = input.receipts.map((receipt) => RepositoryStageReceiptSchema.parse(receipt));
127
+ const byStage = new Map(receipts.map((receipt) => [receipt.input.stageId, receipt]));
128
+ if (byStage.size !== receipts.length) throw new Error("Aggregate contains duplicate stages.");
129
+ for (const definition of classification.requiredStages) {
130
+ const receipt = byStage.get(definition.id);
131
+ if (receipt === void 0 || stableJson(receipt.input.upstream) !== stableJson(
132
+ definition.dependsOn.map((stageId) => ({ stageId, receiptId: byStage.get(stageId)?.receiptId })).sort((a, b) => compareText(a.stageId, b.stageId))
133
+ ) || createRepositoryStageReceipt({
134
+ artifacts: receipt.artifacts,
135
+ classification,
136
+ commands: receipt.commands,
137
+ completedAt: receipt.completedAt,
138
+ stageInput: receipt.input,
139
+ startedAt: receipt.startedAt
140
+ }).receiptId !== receipt.receiptId)
141
+ throw new Error("Aggregate contains missing, foreign or stale stage proof.");
142
+ }
143
+ const content = {
144
+ classificationReceiptId: classification.receiptId,
145
+ policyDigest: classification.policyDigest,
146
+ result: "passed",
147
+ schemaVersion: classification.schemaVersion === "ai-delivery.classification@2" ? "ai-delivery.stage-aggregate@2" : "ai-delivery.stage-aggregate@1",
148
+ stages: classification.requiredStages.map((stage) => {
149
+ const receipt = byStage.get(stage.id);
150
+ return { inputId: receipt.input.inputId, receiptId: receipt.receiptId, stageId: stage.id };
151
+ })
152
+ };
153
+ return RepositoryStageAggregateSchema.parse({ ...content, aggregateId: digestValue(content) });
187
154
  }
188
155
  function storeRoot(gitCommonDir, version = 1) {
189
- return join(gitCommonDir, 'ai-delivery', `verification@${String(version)}`);
156
+ return join(gitCommonDir, "ai-delivery", `verification@${String(version)}`);
190
157
  }
191
158
  function outputPath(gitCommonDir, digest) {
192
- return join(storeRoot(gitCommonDir), 'command-output', `${DigestSchema.parse(digest).slice(7)}.bin`);
159
+ return join(storeRoot(gitCommonDir), "command-output", `${DigestSchema.parse(digest).slice(7)}.bin`);
193
160
  }
194
161
  function checkpointPath(gitCommonDir, stageInput) {
195
- return join(storeRoot(gitCommonDir, stageInput.schemaVersion === 'ai-delivery.stage-input@2' ? 2 : 1), 'stages', stageInput.stageId, `${stageInput.inputId.slice(7)}.json`);
162
+ return join(
163
+ storeRoot(gitCommonDir, stageInput.schemaVersion === "ai-delivery.stage-input@2" ? 2 : 1),
164
+ "stages",
165
+ stageInput.stageId,
166
+ `${stageInput.inputId.slice(7)}.json`
167
+ );
196
168
  }
197
- export function writeRepositoryCommandOutput(input) {
198
- if (input.bytes.length > 8 * 1024 * 1024)
199
- throw new Error('Command output exceeds bounded evidence limit.');
200
- const digest = digestBytes(input.bytes);
201
- writeCreateOnly(outputPath(input.gitCommonDir, digest), input.bytes, digest);
202
- return digest;
169
+ function writeRepositoryCommandOutput(input) {
170
+ if (input.bytes.length > 8 * 1024 * 1024) throw new Error("Command output exceeds bounded evidence limit.");
171
+ const digest = digestBytes(input.bytes);
172
+ writeCreateOnly(outputPath(input.gitCommonDir, digest), input.bytes, digest);
173
+ return digest;
203
174
  }
204
- /** @internal Read immutable command evidence through its existing storage owner. */
205
- export function readRepositoryCommandOutput(input) {
206
- const bytes = assertPrivateFile(outputPath(input.gitCommonDir, input.digest), {
207
- maxBytes: 8 * 1024 ** 2,
208
- ...(input.expectedBytes === undefined ? {} : { expectedBytes: input.expectedBytes }),
209
- });
210
- if (digestBytes(bytes) !== input.digest)
211
- throw new Error('Command output bytes are corrupt.');
212
- return bytes;
175
+ function readRepositoryCommandOutput(input) {
176
+ const bytes = assertPrivateFile(outputPath(input.gitCommonDir, input.digest), {
177
+ maxBytes: 8 * 1024 ** 2,
178
+ ...input.expectedBytes === void 0 ? {} : { expectedBytes: input.expectedBytes }
179
+ });
180
+ if (digestBytes(bytes) !== input.digest) throw new Error("Command output bytes are corrupt.");
181
+ return bytes;
213
182
  }
214
- export function assertRepositoryStageProof(input) {
215
- const receipt = RepositoryStageReceiptSchema.parse(input.receipt);
216
- for (const artifact of receipt.artifacts)
217
- assertArtifact(input.repoRoot, artifact);
218
- for (const command of receipt.commands)
219
- readRepositoryCommandOutput({ gitCommonDir: input.gitCommonDir, digest: command.outputDigest });
183
+ function assertRepositoryStageProof(input) {
184
+ const receipt = RepositoryStageReceiptSchema.parse(input.receipt);
185
+ for (const artifact of receipt.artifacts) assertArtifact(input.repoRoot, artifact);
186
+ for (const command of receipt.commands)
187
+ readRepositoryCommandOutput({ gitCommonDir: input.gitCommonDir, digest: command.outputDigest });
220
188
  }
221
- export function writeRepositoryStageCheckpoint(input) {
222
- const receipt = RepositoryStageReceiptSchema.parse(input.receipt);
223
- assertRepositoryStageProof({ ...input, receipt });
224
- return writeCreateOnly(checkpointPath(input.gitCommonDir, receipt.input), Buffer.from(stableJson(receipt), 'utf8'));
189
+ function writeRepositoryStageCheckpoint(input) {
190
+ const receipt = RepositoryStageReceiptSchema.parse(input.receipt);
191
+ assertRepositoryStageProof({ ...input, receipt });
192
+ return writeCreateOnly(checkpointPath(input.gitCommonDir, receipt.input), Buffer.from(stableJson(receipt), "utf8"));
225
193
  }
226
- export function loadRepositoryStageCheckpoint(input) {
227
- const stageInput = RepositoryStageInputSchema.parse(input.stageInput);
228
- assertRepositoryClassificationCurrent(input);
229
- let bytes;
230
- try {
231
- bytes = assertPrivateFile(checkpointPath(input.gitCommonDir, stageInput));
232
- }
233
- catch (error) {
234
- if (error.code === 'ENOENT')
235
- return undefined;
236
- throw error;
237
- }
238
- const receipt = RepositoryStageReceiptSchema.parse(JSON.parse(bytes.toString('utf8')));
239
- if (!bytes.equals(Buffer.from(stableJson(receipt), 'utf8')) ||
240
- receipt.input.inputId !== stageInput.inputId ||
241
- createRepositoryStageReceipt({
242
- artifacts: receipt.artifacts,
243
- classification: input.classification,
244
- commands: receipt.commands,
245
- completedAt: receipt.completedAt,
246
- stageInput,
247
- startedAt: receipt.startedAt,
248
- }).receiptId !== receipt.receiptId)
249
- throw new Error('Stage checkpoint is corrupt or belongs to another input.');
250
- assertRepositoryStageProof({ gitCommonDir: input.gitCommonDir, receipt, repoRoot: input.repoRoot });
251
- return receipt;
194
+ function loadRepositoryStageCheckpoint(input) {
195
+ const stageInput = RepositoryStageInputSchema.parse(input.stageInput);
196
+ assertRepositoryClassificationCurrent(input);
197
+ let bytes;
198
+ try {
199
+ bytes = assertPrivateFile(checkpointPath(input.gitCommonDir, stageInput));
200
+ } catch (error) {
201
+ if (error.code === "ENOENT") return void 0;
202
+ throw error;
203
+ }
204
+ const receipt = RepositoryStageReceiptSchema.parse(JSON.parse(bytes.toString("utf8")));
205
+ if (!bytes.equals(Buffer.from(stableJson(receipt), "utf8")) || receipt.input.inputId !== stageInput.inputId || createRepositoryStageReceipt({
206
+ artifacts: receipt.artifacts,
207
+ classification: input.classification,
208
+ commands: receipt.commands,
209
+ completedAt: receipt.completedAt,
210
+ stageInput,
211
+ startedAt: receipt.startedAt
212
+ }).receiptId !== receipt.receiptId)
213
+ throw new Error("Stage checkpoint is corrupt or belongs to another input.");
214
+ assertRepositoryStageProof({ gitCommonDir: input.gitCommonDir, receipt, repoRoot: input.repoRoot });
215
+ return receipt;
252
216
  }
253
- export function writeRepositoryStageAggregate(input) {
254
- const aggregate = RepositoryStageAggregateSchema.parse(input.aggregate);
255
- return writeCreateOnly(join(storeRoot(input.gitCommonDir, aggregate.schemaVersion === 'ai-delivery.stage-aggregate@2' ? 2 : 1), 'aggregates', `${aggregate.aggregateId.slice(7)}.json`), Buffer.from(stableJson(aggregate), 'utf8'));
217
+ function writeRepositoryStageAggregate(input) {
218
+ const aggregate = RepositoryStageAggregateSchema.parse(input.aggregate);
219
+ return writeCreateOnly(
220
+ join(
221
+ storeRoot(input.gitCommonDir, aggregate.schemaVersion === "ai-delivery.stage-aggregate@2" ? 2 : 1),
222
+ "aggregates",
223
+ `${aggregate.aggregateId.slice(7)}.json`
224
+ ),
225
+ Buffer.from(stableJson(aggregate), "utf8")
226
+ );
256
227
  }
257
- //# sourceMappingURL=stage.js.map
228
+ export {
229
+ RepositoryStageAggregateSchema,
230
+ RepositoryStageInputSchema,
231
+ RepositoryStageReceiptSchema,
232
+ assertRepositoryStageProof,
233
+ createRepositoryStageAggregate,
234
+ createRepositoryStageInput,
235
+ createRepositoryStageReceipt,
236
+ loadRepositoryStageCheckpoint,
237
+ readRepositoryCommandOutput,
238
+ writeRepositoryCommandOutput,
239
+ writeRepositoryStageAggregate,
240
+ writeRepositoryStageCheckpoint
241
+ };
242
+ //# sourceMappingURL=stage.js.map