@astrosheep/keiyaku 4.5.7 → 4.5.8

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 (234) hide show
  1. package/README.md +10 -0
  2. package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +1 -1
  3. package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +1 -1
  4. package/build/integrations/marketplace/plugins/keiyaku/opencode.js +3 -2
  5. package/build/integrations/marketplace/plugins/keiyaku/package.json +1 -1
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +10 -9
  7. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +22 -1
  8. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-babysit/SKILL.md +35 -96
  9. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +28 -49
  10. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-task/SKILL.md +21 -15
  11. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +148 -89
  12. package/build/src/akuma/abort.d.ts +2 -1
  13. package/build/src/akuma/abort.js +6 -23
  14. package/build/src/akuma/akuma-handle.js +4 -2
  15. package/build/src/akuma/akuma-observe.d.ts +2 -0
  16. package/build/src/akuma/akuma-observe.js +1 -0
  17. package/build/src/akuma/akuma-product.js +9 -7
  18. package/build/src/akuma/akuma.d.ts +372 -9
  19. package/build/src/akuma/akuma.js +31 -1
  20. package/build/src/akuma/allowed.d.ts +1 -1
  21. package/build/src/akuma/allowed.js +1 -0
  22. package/build/src/akuma/body.d.ts +6 -4
  23. package/build/src/akuma/body.js +5 -3
  24. package/build/src/akuma/call-request.d.ts +80 -0
  25. package/build/src/akuma/call-request.js +211 -0
  26. package/build/src/akuma/heart/facts.d.ts +6 -78
  27. package/build/src/akuma/heart/index.d.ts +1 -1
  28. package/build/src/akuma/heart/request-authority.d.ts +5 -4
  29. package/build/src/akuma/heart/request-authority.js +20 -34
  30. package/build/src/akuma/heart/request-rows.js +12 -23
  31. package/build/src/akuma/heart/schema.d.ts +1 -1
  32. package/build/src/akuma/heart/schema.js +5 -13
  33. package/build/src/akuma/index.d.ts +1 -1
  34. package/build/src/akuma/index.js +1 -1
  35. package/build/src/akuma/projection-read.d.ts +1 -0
  36. package/build/src/akuma/projection-read.js +8 -1
  37. package/build/src/akuma/projection.d.ts +856 -137
  38. package/build/src/akuma/projection.js +190 -0
  39. package/build/src/akuma/provider.d.ts +30 -3
  40. package/build/src/akuma/provider.js +104 -0
  41. package/build/src/akuma/providers/acp/core.d.ts +2 -2
  42. package/build/src/akuma/providers/acp/core.js +13 -6
  43. package/build/src/akuma/providers/acp/index.js +5 -4
  44. package/build/src/akuma/providers/claude/index.d.ts +3 -3
  45. package/build/src/akuma/providers/claude/index.js +16 -5
  46. package/build/src/akuma/providers/codex-app-server/events.js +1 -1
  47. package/build/src/akuma/providers/codex-app-server/index.js +18 -6
  48. package/build/src/akuma/providers/grok-build/index.js +5 -4
  49. package/build/src/akuma/providers/opencode-sdk/index.js +66 -25
  50. package/build/src/akuma/providers/opencode-sdk/session.d.ts +3 -2
  51. package/build/src/akuma/providers/opencode-sdk/session.js +28 -11
  52. package/build/src/akuma/providers/pi/index.js +42 -14
  53. package/build/src/akuma/request-lifecycle.d.ts +3 -9
  54. package/build/src/akuma/request-lifecycle.js +4 -4
  55. package/build/src/akuma/request-rendezvous.d.ts +26 -0
  56. package/build/src/akuma/request-rendezvous.js +100 -0
  57. package/build/src/akuma/request-serve.d.ts +5 -65
  58. package/build/src/akuma/request-serve.js +81 -208
  59. package/build/src/akuma/request-wire.d.ts +109 -115
  60. package/build/src/akuma/request-wire.js +63 -318
  61. package/build/src/akuma/requests.d.ts +19 -47
  62. package/build/src/akuma/requests.js +51 -107
  63. package/build/src/akuma/turn-drive.d.ts +5 -3
  64. package/build/src/akuma/turn-drive.js +32 -10
  65. package/build/src/akuma-body.d.ts +7 -2
  66. package/build/src/akuma-body.js +68 -46
  67. package/build/src/cli/accepted.d.ts +1 -1
  68. package/build/src/cli/accepted.js +2 -2
  69. package/build/src/cli/commands/akuma-invoke.d.ts +2 -0
  70. package/build/src/cli/commands/akuma-invoke.js +17 -9
  71. package/build/src/cli/commands/akuma.js +7 -7
  72. package/build/src/cli/commands/contract-invoke.d.ts +3 -2
  73. package/build/src/cli/commands/contract-invoke.js +26 -19
  74. package/build/src/cli/commands/contract.d.ts +13 -13
  75. package/build/src/cli/commands/contract.js +32 -17
  76. package/build/src/cli/commands/install.d.ts +1 -1
  77. package/build/src/cli/commands/install.js +1 -1
  78. package/build/src/cli/commands/task-invoke.d.ts +3 -0
  79. package/build/src/cli/commands/task-invoke.js +23 -140
  80. package/build/src/cli/commands/task.js +54 -20
  81. package/build/src/cli/invoke.js +39 -25
  82. package/build/src/cli/main.js +2 -1
  83. package/build/src/cli/parse.d.ts +2 -2
  84. package/build/src/cli/parse.js +37 -22
  85. package/build/src/cli/render/akuma-activity.d.ts +4 -1
  86. package/build/src/cli/render/akuma-activity.js +45 -30
  87. package/build/src/cli/render/akuma-tool.d.ts +5 -1
  88. package/build/src/cli/render/akuma.js +5 -9
  89. package/build/src/cli/render/audit.js +1 -1
  90. package/build/src/cli/render/catalog.js +80 -21
  91. package/build/src/cli/render/contract-observation.d.ts +2 -0
  92. package/build/src/cli/render/contract-observation.js +11 -0
  93. package/build/src/cli/render/contract.js +25 -65
  94. package/build/src/cli/render/kanshi-akuma.d.ts +8 -0
  95. package/build/src/cli/render/kanshi-akuma.js +111 -0
  96. package/build/src/cli/render/kanshi.js +108 -213
  97. package/build/src/cli/render/receipt.d.ts +1 -2
  98. package/build/src/cli/render/receipt.js +76 -26
  99. package/build/src/cli/render/refusal.js +2 -10
  100. package/build/src/cli/render/region.js +5 -2
  101. package/build/src/cli/render/settings.d.ts +1 -1
  102. package/build/src/cli/render/settings.js +27 -8
  103. package/build/src/cli/render/task.js +22 -5
  104. package/build/src/cli/render/terminal.d.ts +28 -0
  105. package/build/src/cli/render/terminal.js +65 -0
  106. package/build/src/cli/result.d.ts +3 -3
  107. package/build/src/cli/runtime.js +3 -1
  108. package/build/src/cli/selectors.d.ts +2 -1
  109. package/build/src/cli/selectors.js +4 -3
  110. package/build/src/cli/square-edge.js +120 -36
  111. package/build/src/cli/usage.js +2 -1
  112. package/build/src/contract-guidance.d.ts +5 -0
  113. package/build/src/contract-guidance.js +121 -0
  114. package/build/src/contract-worktree.d.ts +0 -1
  115. package/build/src/contract-worktree.js +32 -83
  116. package/build/src/coordination/sqlite-transaction-lock.d.ts +1 -0
  117. package/build/src/coordination/sqlite-transaction-lock.js +5 -0
  118. package/build/src/core/facts/codec.d.ts +2 -0
  119. package/build/src/core/facts/codec.js +4 -0
  120. package/build/src/core/verbs/placement.d.ts +6 -1
  121. package/build/src/core/verbs/placement.js +5 -3
  122. package/build/src/dispatch/index.d.ts +0 -2
  123. package/build/src/dispatch/index.js +54 -55
  124. package/build/src/git/admission.js +2 -2
  125. package/build/src/git/hooks.d.ts +9 -15
  126. package/build/src/git/hooks.js +23 -317
  127. package/build/src/git/nuke.d.ts +2 -1
  128. package/build/src/git/nuke.js +36 -18
  129. package/build/src/git/private-state-seat.d.ts +12 -0
  130. package/build/src/git/private-state-seat.js +39 -0
  131. package/build/src/git/process.d.ts +6 -0
  132. package/build/src/git/process.js +19 -7
  133. package/build/src/git/read-observation.js +29 -20
  134. package/build/src/git/reconcile.d.ts +11 -0
  135. package/build/src/git/reconcile.js +64 -11
  136. package/build/src/git/repository.d.ts +6 -2
  137. package/build/src/git/repository.js +8 -0
  138. package/build/src/git/target-placement.d.ts +1 -0
  139. package/build/src/git/target-placement.js +5 -0
  140. package/build/src/git/tender.d.ts +1 -0
  141. package/build/src/git/terminal-reconcile.d.ts +1 -1
  142. package/build/src/git/terminal-reconcile.js +22 -20
  143. package/build/src/git/workspace.d.ts +14 -0
  144. package/build/src/git/workspace.js +44 -0
  145. package/build/src/kanshi/index.d.ts +1 -1
  146. package/build/src/kanshi/read.js +16 -16
  147. package/build/src/kanshi/report.d.ts +2 -2
  148. package/build/src/library/address.d.ts +9 -3
  149. package/build/src/library/address.js +3 -2
  150. package/build/src/library/akuma-creation.d.ts +4 -3
  151. package/build/src/library/akuma-creation.js +19 -13
  152. package/build/src/library/audit.d.ts +1 -1
  153. package/build/src/library/audit.js +5 -3
  154. package/build/src/library/catalog.d.ts +3 -1
  155. package/build/src/library/catalog.js +20 -6
  156. package/build/src/library/composition.d.ts +371 -0
  157. package/build/src/library/composition.js +28 -0
  158. package/build/src/library/configuration.js +8 -2
  159. package/build/src/library/continuation.js +66 -30
  160. package/build/src/library/contract-bind.js +10 -2
  161. package/build/src/library/contract-forwarding-reconciliation-result.d.ts +96 -0
  162. package/build/src/library/contract-forwarding-reconciliation-result.js +83 -0
  163. package/build/src/library/contract-forwarding-result.d.ts +6723 -0
  164. package/build/src/library/contract-forwarding-result.js +521 -0
  165. package/build/src/library/contract-forwarding.d.ts +72 -0
  166. package/build/src/library/contract-forwarding.js +125 -0
  167. package/build/src/library/contract-handle.d.ts +36 -0
  168. package/build/src/library/contract-handle.js +313 -0
  169. package/build/src/library/contract-operations.d.ts +1044 -67
  170. package/build/src/library/contract-operations.js +190 -118
  171. package/build/src/library/contract.d.ts +11 -32
  172. package/build/src/library/contract.js +16 -289
  173. package/build/src/library/fleet-result.d.ts +1454 -0
  174. package/build/src/library/fleet-result.js +96 -0
  175. package/build/src/library/fleet.d.ts +112 -54
  176. package/build/src/library/fleet.js +211 -71
  177. package/build/src/library/input.d.ts +2 -0
  178. package/build/src/library/input.js +4 -0
  179. package/build/src/library/keiyaku.d.ts +371 -20
  180. package/build/src/library/keiyaku.js +8 -21
  181. package/build/src/library/mutation.d.ts +3 -3
  182. package/build/src/library/mutation.js +5 -9
  183. package/build/src/library/nuke.d.ts +1 -1
  184. package/build/src/library/nuke.js +4 -3
  185. package/build/src/library/reconcile.d.ts +4 -0
  186. package/build/src/library/reconcile.js +2 -0
  187. package/build/src/library/refusal.d.ts +0 -9
  188. package/build/src/library/refusal.js +0 -7
  189. package/build/src/protocol/amend.js +56 -50
  190. package/build/src/protocol/attempt.d.ts +2 -0
  191. package/build/src/protocol/attempt.js +8 -1
  192. package/build/src/protocol/completion.js +7 -0
  193. package/build/src/protocol/deliver.js +6 -2
  194. package/build/src/protocol/operations.d.ts +4 -1
  195. package/build/src/protocol/operations.js +5 -2
  196. package/build/src/protocol/placement.d.ts +1 -0
  197. package/build/src/protocol/placement.js +52 -38
  198. package/build/src/protocol/read/observation.d.ts +1 -4
  199. package/build/src/protocol/read/observation.js +2 -15
  200. package/build/src/protocol/reintegrate.js +62 -58
  201. package/build/src/protocol/review.js +5 -0
  202. package/build/src/protocol/run.js +17 -13
  203. package/build/src/runtime/proc/run.d.ts +8 -0
  204. package/build/src/runtime/proc/run.js +27 -0
  205. package/build/src/runtime/proc/termination.js +26 -22
  206. package/build/src/runtime/proc/windows-launch.exe +0 -0
  207. package/build/src/settlement/holder.d.ts +2 -1
  208. package/build/src/settlement/holder.js +15 -4
  209. package/build/src/settlement/settle.js +99 -33
  210. package/build/src/task/board.d.ts +68 -27
  211. package/build/src/task/board.js +31 -1
  212. package/build/src/task/catalog.d.ts +4 -0
  213. package/build/src/task/catalog.js +23 -0
  214. package/build/src/task/compose-language.js +33 -7
  215. package/build/src/task/compose-parser.d.ts +1 -1
  216. package/build/src/task/compose-parser.js +1 -1
  217. package/build/src/task/compose.js +2 -0
  218. package/build/src/task/index.d.ts +12 -4
  219. package/build/src/task/index.js +97 -16
  220. package/build/src/task/mutation-result.d.ts +923 -0
  221. package/build/src/task/mutation-result.js +140 -0
  222. package/build/src/task/mutation.d.ts +552 -28
  223. package/build/src/task/mutation.js +304 -97
  224. package/build/src/task/operations.d.ts +1 -4
  225. package/build/src/task/operations.js +0 -6
  226. package/build/src/task/public.d.ts +2 -0
  227. package/build/src/task/public.js +1 -0
  228. package/build/src/workspace-place.d.ts +7 -2
  229. package/build/src/workspace-place.js +34 -24
  230. package/build/src/world.d.ts +1 -0
  231. package/build/src/world.js +11 -0
  232. package/package.json +8 -6
  233. package/build/src/akuma/request-execution.d.ts +0 -8
  234. package/build/src/akuma/request-execution.js +0 -98
@@ -0,0 +1,521 @@
1
+ /* eslint-disable max-lines -- Contract owns one coherent forwarded result boundary. */
2
+ import { decodeJournalEntry } from "../core/facts/codec.js";
3
+ import { changeId, contractHead, contractId, entryUlid, gate, snapshotId } from "../core/facts/types.js";
4
+ import { formatTaskId, parseTaskId } from "../task/identity.js";
5
+ import { KeiyakuRefused, KeiyakuRetry } from "./refusal.js";
6
+ import { reconciliationLagSchema } from "./contract-forwarding-reconciliation-result.js";
7
+ import { z } from "zod";
8
+ function canonical(decode, message) {
9
+ return z.string().transform((value, context) => {
10
+ try {
11
+ return decode(value);
12
+ }
13
+ catch {
14
+ context.addIssue({ code: "custom", message });
15
+ return z.NEVER;
16
+ }
17
+ });
18
+ }
19
+ const nonblankStringSchema = z.string().refine((value) => value.trim() !== "");
20
+ const contractIdSchema = canonical(contractId, "expected ContractId");
21
+ const contractHeadSchema = canonical(contractHead, "expected ContractHead");
22
+ const snapshotIdSchema = canonical(snapshotId, "expected SnapshotId");
23
+ const changeIdSchema = canonical(changeId, "expected ChangeId");
24
+ const taskIdSchema = z.string().transform((value, context) => {
25
+ try {
26
+ const id = formatTaskId(parseTaskId(value));
27
+ if (id !== value)
28
+ throw new Error("not canonical");
29
+ return id;
30
+ }
31
+ catch {
32
+ context.addIssue({ code: "custom", message: "expected canonical TaskId" });
33
+ return z.NEVER;
34
+ }
35
+ });
36
+ const journalFactSchema = z.unknown().transform((value, context) => {
37
+ try {
38
+ return decodeJournalEntry(value);
39
+ }
40
+ catch {
41
+ context.addIssue({ code: "custom", message: "expected journal entry" });
42
+ return z.NEVER;
43
+ }
44
+ });
45
+ const settlementLagSchema = z
46
+ .object({
47
+ kind: z.literal("settlement-failed"),
48
+ surface: z.enum(["task-holder", "task", "namespace-context"]),
49
+ contractId: contractIdSchema,
50
+ taskId: taskIdSchema.optional(),
51
+ path: nonblankStringSchema.optional(),
52
+ diagnostic: nonblankStringSchema,
53
+ })
54
+ .strict()
55
+ .transform(({ taskId, path, ...lag }) => ({
56
+ ...lag,
57
+ ...(taskId === undefined ? {} : { taskId }),
58
+ ...(path === undefined ? {} : { path }),
59
+ }));
60
+ const completionSchema = z
61
+ .object({
62
+ integration: snapshotIdSchema,
63
+ verification: z
64
+ .object({ mode: z.enum(["ran", "reused"]), verdict: z.enum(["satisfied", "unsatisfied"]) })
65
+ .strict()
66
+ .optional(),
67
+ })
68
+ .strict()
69
+ .transform(({ verification, ...completion }) => verification === undefined ? completion : { ...completion, verification });
70
+ const integrationSchema = z
71
+ .object({ predecessor: snapshotIdSchema, snapshot: snapshotIdSchema, changeId: changeIdSchema })
72
+ .strict();
73
+ const policySchema = z.object({ requireBranchesToBeUpToDate: z.boolean() }).strict();
74
+ const gateSchema = canonical(gate, "expected Gate");
75
+ const contractIdentityRefusalSchema = z
76
+ .object({
77
+ kind: z.enum([
78
+ "terminal",
79
+ "terms-moved",
80
+ "unknown-prerequisite",
81
+ "cyclic-prerequisite",
82
+ "document-moved",
83
+ "contract-exists",
84
+ "invalid-after",
85
+ "fork-source-moved",
86
+ "worktree-missing",
87
+ "target-missing",
88
+ "delivery-missing",
89
+ ]),
90
+ contractId: contractIdSchema,
91
+ })
92
+ .strict();
93
+ const contractMissingRefusalSchema = z
94
+ .object({ kind: z.literal("contract-missing"), contractId: contractIdSchema })
95
+ .strict();
96
+ const targetInputRefusalSchema = z.union([
97
+ z.object({ kind: z.literal("invalid-target") }).strict(),
98
+ z.object({ kind: z.literal("target-missing") }).strict(),
99
+ z.object({ kind: z.literal("unborn-head") }).strict(),
100
+ ]);
101
+ const verificationDeclarationRefusalSchema = z
102
+ .object({ kind: z.literal("verification-declaration-invalid"), contractId: contractIdSchema.optional() })
103
+ .strict()
104
+ .transform(({ contractId, ...refusal }) => (contractId === undefined ? refusal : { ...refusal, contractId }));
105
+ const workspaceSchema = z.object({ kind: z.literal("worktree"), path: nonblankStringSchema }).strict();
106
+ const mergeStateRefusalSchema = z
107
+ .object({ kind: z.literal("merge-state-present"), contractId: contractIdSchema, workspace: workspaceSchema })
108
+ .strict();
109
+ const unmergedPathsRefusalSchema = z
110
+ .object({ kind: z.literal("unmerged-paths"), contractId: contractIdSchema, paths: z.array(nonblankStringSchema) })
111
+ .strict();
112
+ const dirtyWorkspaceRefusalSchema = z
113
+ .object({
114
+ kind: z.literal("dirty-workspace"),
115
+ contractId: contractIdSchema,
116
+ staged: z.array(nonblankStringSchema),
117
+ unstaged: z.array(nonblankStringSchema),
118
+ untracked: z.array(nonblankStringSchema),
119
+ submodules: z.array(nonblankStringSchema),
120
+ shortStat: z
121
+ .object({
122
+ filesChanged: z.number().int().nonnegative(),
123
+ insertions: z.number().int().nonnegative(),
124
+ deletions: z.number().int().nonnegative(),
125
+ })
126
+ .strict(),
127
+ })
128
+ .strict();
129
+ const integrationFailureSchema = z
130
+ .object({
131
+ kind: z.literal("integration-failed"),
132
+ contractId: contractIdSchema,
133
+ reason: z.enum(["not-based-on-target", "unrelated-histories", "conflict"]),
134
+ targetHead: snapshotIdSchema,
135
+ conflictPaths: z.array(nonblankStringSchema).optional(),
136
+ })
137
+ .strict()
138
+ .transform(({ conflictPaths, ...failure }) => conflictPaths === undefined ? failure : { ...failure, conflictPaths });
139
+ const integrationPreparationRefusalSchema = z.union([
140
+ integrationFailureSchema,
141
+ z
142
+ .object({
143
+ kind: z.literal("integration-unsupported"),
144
+ contractId: contractIdSchema,
145
+ requiredGit: z.literal("2.38"),
146
+ })
147
+ .strict(),
148
+ ]);
149
+ const integrationRefusalSchema = z.union([
150
+ integrationPreparationRefusalSchema,
151
+ z
152
+ .object({
153
+ kind: z.literal("integration-failed"),
154
+ contractId: contractIdSchema,
155
+ reason: z.literal("conflict"),
156
+ targetHead: snapshotIdSchema,
157
+ conflictPaths: z.array(nonblankStringSchema),
158
+ recovery: z
159
+ .object({
160
+ materialize: z.literal("deliver --materialize-conflict"),
161
+ continue: z.literal("deliver --include-dirty"),
162
+ })
163
+ .strict(),
164
+ })
165
+ .strict(),
166
+ ]);
167
+ const checkoutRefusalSchema = z
168
+ .object({
169
+ kind: z.literal("checkout-not-followable"),
170
+ contractId: contractIdSchema,
171
+ target: nonblankStringSchema,
172
+ path: nonblankStringSchema,
173
+ reason: z.enum(["staged", "conflict", "untracked"]),
174
+ paths: z.array(nonblankStringSchema),
175
+ })
176
+ .strict();
177
+ const gateCurrentSchema = z.union([
178
+ z
179
+ .object({
180
+ kind: z.literal("attested"),
181
+ verdict: z.enum(["satisfied", "unsatisfied"]),
182
+ summary: z.string().optional(),
183
+ at: z.string(),
184
+ })
185
+ .strict()
186
+ .transform(({ summary, ...current }) => (summary === undefined ? current : { ...current, summary })),
187
+ z.object({ kind: z.literal("stale"), priorVerdict: z.enum(["satisfied", "unsatisfied"]) }).strict(),
188
+ z.object({ kind: z.literal("missing") }).strict(),
189
+ ]);
190
+ const placementRefusalSchema = z.union([
191
+ z
192
+ .object({
193
+ kind: z.literal("gates-unsatisfied"),
194
+ contractId: contractIdSchema,
195
+ unmet: z.array(z.object({ gate: gateSchema, current: gateCurrentSchema }).strict()),
196
+ })
197
+ .strict(),
198
+ z
199
+ .object({
200
+ kind: z.literal("prerequisites-unsatisfied"),
201
+ contractId: contractIdSchema,
202
+ unmet: z.array(z.object({ contractId: contractIdSchema, state: z.enum(["missing", "active", "abandoned"]) }).strict()),
203
+ })
204
+ .strict(),
205
+ ]);
206
+ const nukeRefusalSchema = z.union([
207
+ z.object({ kind: z.literal("nuke-confirmation-required"), world: nonblankStringSchema }).strict(),
208
+ z
209
+ .object({ kind: z.literal("nuke-confirmation-mismatch"), world: nonblankStringSchema, confirmation: z.string() })
210
+ .strict(),
211
+ ]);
212
+ const forkSourceRefusalSchema = z
213
+ .object({
214
+ kind: z.enum(["fork-source-missing", "fork-source-unavailable", "fork-source-invalid", "fork-source-moved"]),
215
+ contractId: contractIdSchema,
216
+ })
217
+ .strict();
218
+ const refusalSchema = z.union([
219
+ contractMissingRefusalSchema,
220
+ contractIdentityRefusalSchema,
221
+ targetInputRefusalSchema,
222
+ verificationDeclarationRefusalSchema,
223
+ mergeStateRefusalSchema,
224
+ unmergedPathsRefusalSchema,
225
+ dirtyWorkspaceRefusalSchema,
226
+ integrationRefusalSchema,
227
+ checkoutRefusalSchema,
228
+ placementRefusalSchema,
229
+ nukeRefusalSchema,
230
+ forkSourceRefusalSchema,
231
+ ]);
232
+ const retrySchema = z.union([
233
+ z.object({ kind: z.literal("exhausted") }).strict(),
234
+ z.object({ kind: z.literal("collision") }).strict(),
235
+ z.object({ kind: z.literal("publication-failed"), diagnostic: z.string() }).strict(),
236
+ ]);
237
+ const materializedConflictSchema = z
238
+ .object({
239
+ kind: z.literal("integration-conflict-materialized"),
240
+ targetHead: snapshotIdSchema,
241
+ conflictPaths: z.array(nonblankStringSchema),
242
+ workspace: z.object({ kind: z.literal("worktree"), path: nonblankStringSchema }).strict(),
243
+ })
244
+ .strict();
245
+ const hookFailureSchema = z.union([
246
+ z
247
+ .object({
248
+ kind: z.literal("exit"),
249
+ code: z.number().int(),
250
+ stdout: z.string(),
251
+ stderr: z.string(),
252
+ truncated: z.boolean(),
253
+ })
254
+ .strict(),
255
+ z.object({ kind: z.literal("timeout") }).strict(),
256
+ z.object({ kind: z.literal("spawn-error"), diagnostic: z.string() }).strict(),
257
+ z.object({ kind: z.literal("unknown-exit") }).strict(),
258
+ ]);
259
+ const attestationRefusalSchema = z
260
+ .object({ kind: z.enum(["contract-missing", "terminal"]), contractId: contractIdSchema })
261
+ .strict();
262
+ const verificationStopSchema = z.union([
263
+ z.object({ refusal: z.union([attestationRefusalSchema, verificationDeclarationRefusalSchema]) }).strict(),
264
+ z.object({ retry: retrySchema }).strict(),
265
+ z.object({ failure: z.enum(["unknown-exit", "cancelled"]) }).strict(),
266
+ z.object({ failure: z.enum(["candidate-unavailable", "spawn-error"]), diagnostic: z.string() }).strict(),
267
+ z.object({ failure: z.literal("environment-failure"), diagnostic: z.string() }).strict(),
268
+ z
269
+ .object({ failure: z.literal("environment-failure"), command: z.number().int(), detail: hookFailureSchema })
270
+ .strict(),
271
+ ]);
272
+ const verificationReuseSchema = z
273
+ .object({
274
+ entry: canonical(entryUlid, "expected EntryUlid"),
275
+ verdict: z.enum(["satisfied", "unsatisfied"]),
276
+ summary: z.string().optional(),
277
+ })
278
+ .strict()
279
+ .transform(({ summary, ...reuse }) => (summary === undefined ? reuse : { ...reuse, summary }));
280
+ const placementStepRefusalSchema = z.union([
281
+ z
282
+ .object({ kind: z.enum(["contract-missing", "delivery-missing", "terminal"]), contractId: contractIdSchema })
283
+ .strict(),
284
+ placementRefusalSchema,
285
+ checkoutRefusalSchema,
286
+ integrationFailureSchema,
287
+ z
288
+ .object({
289
+ kind: z.literal("integration-unsupported"),
290
+ contractId: contractIdSchema,
291
+ requiredGit: z.literal("2.38"),
292
+ })
293
+ .strict(),
294
+ z.object({ kind: z.literal("target-missing"), contractId: contractIdSchema }).strict(),
295
+ ]);
296
+ const placementStopSchema = z.union([
297
+ z.object({ refusal: placementStepRefusalSchema }).strict(),
298
+ z.object({ retry: retrySchema }).strict(),
299
+ z
300
+ .object({
301
+ failure: z.literal("target-moved"),
302
+ contractId: contractIdSchema,
303
+ target: nonblankStringSchema,
304
+ expected: snapshotIdSchema,
305
+ observed: snapshotIdSchema.nullable(),
306
+ observedTreeEqualsCandidate: z.boolean(),
307
+ })
308
+ .strict(),
309
+ z
310
+ .object({
311
+ failure: z.literal("target-moved"),
312
+ contractId: contractIdSchema,
313
+ target: nonblankStringSchema,
314
+ integratedAt: snapshotIdSchema,
315
+ observed: snapshotIdSchema.nullable(),
316
+ attempts: z.number().int(),
317
+ observedTreeEqualsCandidate: z.boolean(),
318
+ })
319
+ .strict(),
320
+ z.object({ failure: z.literal("target-placement-failed"), diagnostic: z.string() }).strict(),
321
+ ]);
322
+ const cleanupSchema = z
323
+ .object({ phase: z.literal("destroy"), command: z.number().int(), detail: hookFailureSchema })
324
+ .strict();
325
+ const leakSchema = z.object({ path: z.string(), diagnostic: z.string() }).strict();
326
+ const continuationSchema = z
327
+ .object({
328
+ claimed: z.array(contractIdSchema),
329
+ stopped: z.array(z
330
+ .object({
331
+ contractId: contractIdSchema,
332
+ stop: z.union([placementStopSchema, z.object({ kind: z.literal("already-terminal") }).strict()]),
333
+ })
334
+ .strict()),
335
+ })
336
+ .strict();
337
+ const workspaceDeltaSchema = z
338
+ .object({
339
+ staged: z.array(z.string()),
340
+ unstaged: z.array(z.string()),
341
+ untracked: z.array(z.string()),
342
+ shortStat: z
343
+ .object({ filesChanged: z.number().int(), insertions: z.number().int(), deletions: z.number().int() })
344
+ .strict(),
345
+ })
346
+ .strict();
347
+ const deliveryValueSchema = z
348
+ .object({
349
+ tenderSnapshot: snapshotIdSchema,
350
+ integration: integrationSchema,
351
+ method: z.literal("squash"),
352
+ policy: policySchema,
353
+ completion: completionSchema.optional(),
354
+ verification: verificationStopSchema.optional(),
355
+ verificationReuse: verificationReuseSchema.optional(),
356
+ verificationSummary: nonblankStringSchema.optional(),
357
+ placement: placementStopSchema.optional(),
358
+ cleanup: cleanupSchema.optional(),
359
+ leak: leakSchema.optional(),
360
+ continuation: continuationSchema.optional(),
361
+ })
362
+ .strict()
363
+ .transform(({ completion, verification, verificationReuse, verificationSummary, placement, cleanup, leak, continuation, ...value }) => ({
364
+ ...value,
365
+ ...(completion === undefined ? {} : { completion }),
366
+ ...(verification === undefined ? {} : { verification }),
367
+ ...(verificationReuse === undefined ? {} : { verificationReuse }),
368
+ ...(verificationSummary === undefined ? {} : { verificationSummary }),
369
+ ...(placement === undefined ? {} : { placement }),
370
+ ...(cleanup === undefined ? {} : { cleanup }),
371
+ ...(leak === undefined ? {} : { leak }),
372
+ ...(continuation === undefined ? {} : { continuation }),
373
+ }));
374
+ const reviewValueSchema = z
375
+ .object({
376
+ completion: completionSchema.optional(),
377
+ verification: verificationStopSchema.optional(),
378
+ verificationReuse: verificationReuseSchema.optional(),
379
+ verificationSummary: nonblankStringSchema.optional(),
380
+ placement: placementStopSchema.optional(),
381
+ cleanup: cleanupSchema.optional(),
382
+ leak: leakSchema.optional(),
383
+ continuation: continuationSchema.optional(),
384
+ workspace: workspaceDeltaSchema.optional(),
385
+ })
386
+ .strict()
387
+ .transform(({ completion, verification, verificationReuse, verificationSummary, placement, cleanup, leak, continuation, workspace, }) => ({
388
+ ...(completion === undefined ? {} : { completion }),
389
+ ...(verification === undefined ? {} : { verification }),
390
+ ...(verificationReuse === undefined ? {} : { verificationReuse }),
391
+ ...(verificationSummary === undefined ? {} : { verificationSummary }),
392
+ ...(placement === undefined ? {} : { placement }),
393
+ ...(cleanup === undefined ? {} : { cleanup }),
394
+ ...(leak === undefined ? {} : { leak }),
395
+ ...(continuation === undefined ? {} : { continuation }),
396
+ ...(workspace === undefined ? {} : { workspace }),
397
+ }));
398
+ const deliveryPreparationRefusalSchema = z.union([
399
+ z.object({ kind: z.enum(["target-missing", "worktree-missing"]), contractId: contractIdSchema }).strict(),
400
+ dirtyWorkspaceRefusalSchema,
401
+ unmergedPathsRefusalSchema,
402
+ integrationPreparationRefusalSchema,
403
+ mergeStateRefusalSchema,
404
+ checkoutRefusalSchema,
405
+ ]);
406
+ const auditReadyCandidateSchema = z
407
+ .object({
408
+ kind: z.literal("ready"),
409
+ workspace: z.object({ kind: z.literal("worktree"), path: nonblankStringSchema }).strict(),
410
+ identity: z
411
+ .object({
412
+ tenderSnapshot: snapshotIdSchema,
413
+ integration: integrationSchema,
414
+ method: z.literal("squash"),
415
+ policy: policySchema,
416
+ })
417
+ .strict(),
418
+ scope: z
419
+ .object({
420
+ filesChanged: z.number().int(),
421
+ insertions: z.number().int(),
422
+ deletions: z.number().int(),
423
+ paths: z.array(z.string()).optional(),
424
+ })
425
+ .strict()
426
+ .transform(({ paths, ...scope }) => (paths === undefined ? scope : { ...scope, paths })),
427
+ diff: z.string().optional(),
428
+ })
429
+ .strict()
430
+ .transform(({ diff, ...candidate }) => (diff === undefined ? candidate : { ...candidate, diff }));
431
+ const auditCandidateSchema = z.union([
432
+ z.object({ kind: z.literal("blocked"), refusal: deliveryPreparationRefusalSchema }).strict(),
433
+ auditReadyCandidateSchema,
434
+ ]);
435
+ const auditVerificationSchema = z.union([
436
+ z.object({ kind: z.literal("not-run") }).strict(),
437
+ z.object({ kind: z.literal("stopped"), stop: verificationStopSchema }).strict(),
438
+ z
439
+ .object({
440
+ kind: z.enum(["satisfied", "unsatisfied"]),
441
+ passed: z.number(),
442
+ total: z.number(),
443
+ summary: z.string().optional(),
444
+ })
445
+ .strict()
446
+ .transform(({ summary, ...verification }) => (summary === undefined ? verification : { ...verification, summary })),
447
+ ]);
448
+ const auditTargetSchema = z.union([
449
+ z.object({ kind: z.literal("not-observed") }).strict(),
450
+ z.object({ kind: z.literal("placeable"), ref: z.string(), head: snapshotIdSchema }).strict(),
451
+ z
452
+ .object({
453
+ kind: z.literal("moved"),
454
+ ref: z.string(),
455
+ expected: snapshotIdSchema,
456
+ observed: snapshotIdSchema.nullable(),
457
+ })
458
+ .strict(),
459
+ z.object({ kind: z.literal("refused"), refusal: checkoutRefusalSchema }).strict(),
460
+ z.object({ kind: z.literal("failed"), diagnostic: z.string() }).strict(),
461
+ ]);
462
+ export const auditReportSchema = z
463
+ .object({
464
+ candidate: auditCandidateSchema,
465
+ verification: auditVerificationSchema,
466
+ target: auditTargetSchema,
467
+ delivery: z
468
+ .object({ changeId: changeIdSchema, relation: z.enum(["identical", "differs"]) })
469
+ .strict()
470
+ .optional(),
471
+ })
472
+ .strict()
473
+ .transform(({ delivery, ...report }) => delivery === undefined ? report : { ...report, delivery });
474
+ const mutationResultSchema = (value) => z
475
+ .object({
476
+ facts: z.array(journalFactSchema),
477
+ head: contractHeadSchema,
478
+ value,
479
+ lags: z.array(reconciliationLagSchema),
480
+ settlementLags: z.array(settlementLagSchema),
481
+ recoverySnapshot: snapshotIdSchema.optional(),
482
+ cleanup: cleanupSchema.optional(),
483
+ leak: leakSchema.optional(),
484
+ })
485
+ .strict()
486
+ .transform(({ recoverySnapshot, cleanup, leak, ...result }) => ({
487
+ ...result,
488
+ ...(recoverySnapshot === undefined ? {} : { recoverySnapshot }),
489
+ ...(cleanup === undefined ? {} : { cleanup }),
490
+ ...(leak === undefined ? {} : { leak }),
491
+ }));
492
+ const deliveryMutationResultSchema = mutationResultSchema(deliveryValueSchema);
493
+ const reviewMutationResultSchema = mutationResultSchema(reviewValueSchema);
494
+ const auditMutationResultSchema = mutationResultSchema(auditReportSchema);
495
+ export const deliveryResultSchema = z.union([
496
+ deliveryMutationResultSchema,
497
+ materializedConflictSchema,
498
+ ]);
499
+ export const reviewResultSchema = reviewMutationResultSchema;
500
+ export const auditResultSchema = auditMutationResultSchema;
501
+ const contractLiveFailureSchema = z.union([
502
+ z.object({ kind: z.literal("refused"), refusal: refusalSchema }).strict(),
503
+ z.object({ kind: z.literal("retry"), reason: retrySchema }).strict(),
504
+ ]);
505
+ export function encodeContractLiveFailure(error) {
506
+ if (error instanceof KeiyakuRefused) {
507
+ return contractLiveFailureSchema.parse({ kind: "refused", refusal: error.refusal });
508
+ }
509
+ if (error instanceof KeiyakuRetry) {
510
+ return contractLiveFailureSchema.parse({ kind: "retry", reason: error.reason });
511
+ }
512
+ return null;
513
+ }
514
+ export function decodeContractLiveFailure(value) {
515
+ const parsed = contractLiveFailureSchema.safeParse(value);
516
+ if (!parsed.success)
517
+ return null;
518
+ return parsed.data.kind === "refused"
519
+ ? new KeiyakuRefused(parsed.data.refusal)
520
+ : new KeiyakuRetry(parsed.data.reason);
521
+ }
@@ -0,0 +1,72 @@
1
+ import { type ContractId } from "../core/facts/types.js";
2
+ import { type IntegrationConflictMaterialized } from "../protocol/deliver.js";
3
+ import type { RepositoryScope } from "../protocol/operations.js";
4
+ import { type AuditInput } from "./audit.js";
5
+ import type { AuditReport } from "../protocol/audit.js";
6
+ import type { WorktreeHooks } from "./configuration.js";
7
+ import type { DeliveryValue } from "./delivery.js";
8
+ import { actorOption } from "./input.js";
9
+ import { type MutationResult } from "./mutation.js";
10
+ import { type Review } from "./contract-forwarding-result.js";
11
+ export type { Review } from "./contract-forwarding-result.js";
12
+ import { Repo } from "./repo.js";
13
+ export type DeliveryExecutionInput = Readonly<{
14
+ scope: RepositoryScope;
15
+ contractId: ContractId;
16
+ actor?: ReturnType<typeof actorOption>["actor"];
17
+ message?: string;
18
+ requireBranchesToBeUpToDate: boolean;
19
+ includeDirty: boolean;
20
+ materializeConflict: boolean;
21
+ signal?: AbortSignal;
22
+ hooks: WorktreeHooks;
23
+ }>;
24
+ export type AttestationVerdict = "satisfied" | "unsatisfied";
25
+ export type ReviewExecutionInput = Readonly<{
26
+ scope: RepositoryScope;
27
+ contractId: ContractId;
28
+ actor?: ReturnType<typeof actorOption>["actor"];
29
+ verdict: AttestationVerdict;
30
+ summary?: string;
31
+ hooks: WorktreeHooks;
32
+ }>;
33
+ export declare function executeLocalDelivery(input: DeliveryExecutionInput): Promise<MutationResult<DeliveryValue> | IntegrationConflictMaterialized>;
34
+ export declare function executeLocalReview(input: ReviewExecutionInput): Promise<MutationResult<Review>>;
35
+ export declare function executeForwardedDeliver(input: Readonly<{
36
+ repo: Repo;
37
+ contractId: string;
38
+ requester: string;
39
+ message?: string;
40
+ includeDirty: boolean;
41
+ materializeConflict: boolean;
42
+ requireBranchesToBeUpToDate: boolean;
43
+ hooks: Parameters<typeof executeLocalDelivery>[0]["hooks"];
44
+ signal?: AbortSignal;
45
+ }>): Promise<Readonly<{
46
+ result: MutationResult<DeliveryValue> | IntegrationConflictMaterialized;
47
+ deliveryFactId?: string;
48
+ }>>;
49
+ export declare function executeForwardedReview(input: Readonly<{
50
+ repo: Repo;
51
+ contractId: string;
52
+ requester: string;
53
+ verdict: AttestationVerdict;
54
+ summary?: string;
55
+ hooks: Parameters<typeof executeLocalReview>[0]["hooks"];
56
+ }>): Promise<Readonly<{
57
+ result: MutationResult<Review>;
58
+ reviewFactId?: string;
59
+ }>>;
60
+ export declare function executeForwardedAudit(input: Readonly<{
61
+ repo: Repo;
62
+ contractId: string;
63
+ requester: string;
64
+ includeDirty: boolean;
65
+ showDiff: boolean;
66
+ requireBranchesToBeUpToDate: boolean;
67
+ hooks: AuditInput["hooks"];
68
+ signal?: AbortSignal;
69
+ }>): Promise<Readonly<{
70
+ result: MutationResult<AuditReport>;
71
+ auditReport?: AuditReport;
72
+ }>>;