@astrosheep/keiyaku 4.6.26 → 4.6.28

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/README.md +113 -35
  2. package/build/plugins/claude/.claude-plugin/plugin.json +1 -1
  3. package/build/plugins/claude/skills/keiyaku/SKILL.md +14 -26
  4. package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +64 -44
  5. package/build/plugins/claude/skills/keiyaku-akuma/references/automation.md +13 -25
  6. package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +1 -1
  7. package/build/plugins/claude/skills/keiyaku-bind/SKILL.md +42 -29
  8. package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +13 -8
  9. package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +57 -61
  10. package/build/plugins/codex/.codex-plugin/plugin.json +1 -1
  11. package/build/plugins/codex/skills/keiyaku/SKILL.md +14 -26
  12. package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +64 -44
  13. package/build/plugins/codex/skills/keiyaku-akuma/references/automation.md +13 -25
  14. package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +1 -1
  15. package/build/plugins/codex/skills/keiyaku-bind/SKILL.md +42 -29
  16. package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +13 -8
  17. package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +57 -61
  18. package/build/plugins/opencode/package.json +1 -1
  19. package/build/plugins/opencode/skills/keiyaku/SKILL.md +14 -26
  20. package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +64 -44
  21. package/build/plugins/opencode/skills/keiyaku-akuma/references/automation.md +13 -25
  22. package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +1 -1
  23. package/build/plugins/opencode/skills/keiyaku-bind/SKILL.md +42 -29
  24. package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +13 -8
  25. package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +57 -61
  26. package/build/plugins/pi/README.md +7 -12
  27. package/build/plugins/pi/akuma-tools.ts +3 -18
  28. package/build/skills/keiyaku/SKILL.md +14 -26
  29. package/build/skills/keiyaku-akuma/SKILL.md +64 -44
  30. package/build/skills/keiyaku-akuma/references/automation.md +13 -25
  31. package/build/skills/keiyaku-babysit/SKILL.md +1 -1
  32. package/build/skills/keiyaku-bind/SKILL.md +42 -29
  33. package/build/skills/keiyaku-debt/SKILL.md +13 -8
  34. package/build/skills/keiyaku-workflow/SKILL.md +57 -61
  35. package/build/src/akuma/akuma-call.d.ts +15 -18
  36. package/build/src/akuma/akuma-call.js +55 -112
  37. package/build/src/akuma/akuma-errors.d.ts +0 -5
  38. package/build/src/akuma/akuma-errors.js +0 -9
  39. package/build/src/akuma/akuma-instance.d.ts +0 -2
  40. package/build/src/akuma/akuma-instance.js +18 -14
  41. package/build/src/akuma/akuma-observe.js +0 -1
  42. package/build/src/akuma/akuma-owner.js +0 -1
  43. package/build/src/akuma/akuma.d.ts +10 -26
  44. package/build/src/akuma/akuma.js +0 -2
  45. package/build/src/akuma/archetype.d.ts +0 -2
  46. package/build/src/akuma/archetype.js +3 -9
  47. package/build/src/akuma/body-launch.d.ts +12 -4
  48. package/build/src/akuma/body.d.ts +2 -5
  49. package/build/src/akuma/body.js +5 -49
  50. package/build/src/akuma/call-initial-tell.d.ts +39 -147
  51. package/build/src/akuma/call-initial-tell.js +0 -48
  52. package/build/src/akuma/caller.d.ts +0 -4
  53. package/build/src/akuma/custody.js +1 -57
  54. package/build/src/akuma/heart/facts.d.ts +0 -39
  55. package/build/src/akuma/heart/facts.js +0 -1
  56. package/build/src/akuma/heart/index.d.ts +1 -2
  57. package/build/src/akuma/heart/index.js +0 -1
  58. package/build/src/akuma/heart/schema.js +0 -26
  59. package/build/src/akuma/heart/soul.d.ts +2 -2
  60. package/build/src/akuma/heart/soul.js +2 -4
  61. package/build/src/akuma/identity.d.ts +0 -1
  62. package/build/src/akuma/identity.js +0 -2
  63. package/build/src/akuma/in-process-body.d.ts +1 -1
  64. package/build/src/akuma/index.d.ts +0 -2
  65. package/build/src/akuma/index.js +0 -1
  66. package/build/src/akuma/projection.d.ts +23 -23
  67. package/build/src/akuma/provider.d.ts +0 -5
  68. package/build/src/akuma/provider.js +0 -1
  69. package/build/src/akuma/providers/acp/core.js +1 -1
  70. package/build/src/akuma/providers/claude/index.js +1 -2
  71. package/build/src/akuma/providers/codex-app-server/events.d.ts +1 -1
  72. package/build/src/akuma/providers/codex-app-server/events.js +1 -3
  73. package/build/src/akuma/providers/codex-app-server/index.js +1 -1
  74. package/build/src/akuma/providers/execution-environment.d.ts +1 -3
  75. package/build/src/akuma/providers/execution-environment.js +1 -7
  76. package/build/src/akuma/providers/opencode-sdk/index.js +0 -1
  77. package/build/src/akuma/providers/opencode-sdk/session.d.ts +0 -1
  78. package/build/src/akuma/providers/opencode-sdk/session.js +4 -4
  79. package/build/src/akuma/providers/paseo/index.js +2 -9
  80. package/build/src/akuma/providers/pi/index.js +8 -14
  81. package/build/src/akuma/publication.d.ts +24 -59
  82. package/build/src/akuma/publication.js +29 -64
  83. package/build/src/akuma/selection-observation.d.ts +47 -2036
  84. package/build/src/akuma/selection-observation.js +1 -59
  85. package/build/src/akuma/turn-drive.d.ts +0 -8
  86. package/build/src/akuma/turn-drive.js +19 -103
  87. package/build/src/akuma-body.js +3 -6
  88. package/build/src/body-host.d.ts +8 -2
  89. package/build/src/body-host.js +30 -4
  90. package/build/src/cli/commands/akuma-grammar.d.ts +0 -2
  91. package/build/src/cli/commands/akuma-grammar.js +14 -37
  92. package/build/src/cli/commands/akuma.js +31 -49
  93. package/build/src/cli/commands/contract-grammar.d.ts +7 -1
  94. package/build/src/cli/commands/contract-grammar.js +15 -0
  95. package/build/src/cli/commands/contract-help.d.ts +13 -1
  96. package/build/src/cli/commands/contract-help.js +88 -81
  97. package/build/src/cli/commands/contract.js +27 -26
  98. package/build/src/cli/commands/debt-grammar.js +15 -15
  99. package/build/src/cli/commands/debt.js +3 -3
  100. package/build/src/cli/commands/install.d.ts +1 -1
  101. package/build/src/cli/commands/install.js +1 -2
  102. package/build/src/cli/commands/whoami.d.ts +0 -2
  103. package/build/src/cli/commands/whoami.js +0 -5
  104. package/build/src/cli/coordinates.js +15 -0
  105. package/build/src/cli/delivery-identity.d.ts +3 -0
  106. package/build/src/cli/delivery-identity.js +23 -0
  107. package/build/src/cli/parse.js +2 -1
  108. package/build/src/cli/render/akuma-activity.d.ts +0 -1
  109. package/build/src/cli/render/akuma-activity.js +1 -4
  110. package/build/src/cli/render/catalog.js +7 -1
  111. package/build/src/cli/render/contract-history.js +16 -38
  112. package/build/src/cli/render/contract-observation.d.ts +23 -10
  113. package/build/src/cli/render/contract-observation.js +9 -6
  114. package/build/src/cli/render/contract-wait.d.ts +2 -0
  115. package/build/src/cli/render/contract-wait.js +18 -0
  116. package/build/src/cli/render/contract.d.ts +2 -2
  117. package/build/src/cli/render/contract.js +57 -39
  118. package/build/src/cli/render/delivery-preview.js +13 -26
  119. package/build/src/cli/render/execution-progress.js +9 -9
  120. package/build/src/cli/render/kanshi.js +4 -11
  121. package/build/src/cli/render/receipt.d.ts +18 -0
  122. package/build/src/cli/render/receipt.js +34 -10
  123. package/build/src/cli/render/reconcile.js +3 -0
  124. package/build/src/cli/render/refusal.js +28 -6
  125. package/build/src/cli/render/whoami.js +1 -4
  126. package/build/src/cli/runtime.d.ts +0 -2
  127. package/build/src/cli/runtime.js +3 -7
  128. package/build/src/cli/selectors.d.ts +1 -2
  129. package/build/src/cli/selectors.js +2 -5
  130. package/build/src/contract-guidance.js +4 -2
  131. package/build/src/contract-worktree.d.ts +3 -3
  132. package/build/src/core/facts/codec.js +38 -5
  133. package/build/src/core/facts/fold.js +1 -0
  134. package/build/src/core/facts/gate.d.ts +10 -4
  135. package/build/src/core/facts/gate.js +56 -39
  136. package/build/src/core/facts/observation.d.ts +7 -1
  137. package/build/src/core/facts/observation.js +15 -0
  138. package/build/src/core/facts/offer.d.ts +2 -2
  139. package/build/src/core/facts/types.d.ts +17 -1
  140. package/build/src/core/facts/types.js +6 -0
  141. package/build/src/core/verbs/amend.js +8 -0
  142. package/build/src/core/verbs/bind.d.ts +3 -1
  143. package/build/src/core/verbs/bind.js +9 -1
  144. package/build/src/core/verbs/deliver.d.ts +2 -1
  145. package/build/src/core/verbs/deliver.js +4 -1
  146. package/build/src/core/verbs/placement.d.ts +2 -1
  147. package/build/src/core/verbs/placement.js +7 -4
  148. package/build/src/core/verbs/reintegrate.d.ts +2 -1
  149. package/build/src/core/verbs/reintegrate.js +4 -1
  150. package/build/src/debt/board.d.ts +10 -10
  151. package/build/src/debt/created-observation.d.ts +3 -3
  152. package/build/src/debt/document.d.ts +1 -1
  153. package/build/src/debt/index.d.ts +2 -24
  154. package/build/src/debt/index.js +11 -71
  155. package/build/src/debt/operation-types.d.ts +44 -3
  156. package/build/src/git/admission.js +18 -6
  157. package/build/src/git/integration.d.ts +4 -4
  158. package/build/src/git/integration.js +7 -1
  159. package/build/src/git/observe.d.ts +6 -4
  160. package/build/src/git/observe.js +18 -17
  161. package/build/src/git/reconcile.d.ts +20 -8
  162. package/build/src/git/reconcile.js +94 -45
  163. package/build/src/git/repository.d.ts +3 -1
  164. package/build/src/git/repository.js +26 -4
  165. package/build/src/git/scratch.d.ts +1 -1
  166. package/build/src/git/scratch.js +19 -18
  167. package/build/src/git/target-placement.d.ts +33 -7
  168. package/build/src/git/target-placement.js +67 -18
  169. package/build/src/git/target.d.ts +32 -0
  170. package/build/src/git/target.js +84 -0
  171. package/build/src/git/terminal-reconcile.d.ts +1 -1
  172. package/build/src/git/terminal-reconcile.js +34 -6
  173. package/build/src/index.d.ts +9 -7
  174. package/build/src/index.js +1 -1
  175. package/build/src/library/address.d.ts +1 -20
  176. package/build/src/library/address.js +3 -24
  177. package/build/src/library/akuma-creation.d.ts +2 -5
  178. package/build/src/library/akuma-creation.js +60 -44
  179. package/build/src/library/akumas.d.ts +3 -9
  180. package/build/src/library/akumas.js +12 -25
  181. package/build/src/library/bind.d.ts +21 -9
  182. package/build/src/library/bind.js +5 -1
  183. package/build/src/library/continuation.d.ts +130 -155
  184. package/build/src/library/continuation.js +1 -4
  185. package/build/src/library/contract-composition.d.ts +4 -9
  186. package/build/src/library/contract-composition.js +8 -12
  187. package/build/src/library/contract-creation.d.ts +1 -3
  188. package/build/src/library/contract-creation.js +2 -3
  189. package/build/src/library/contract-execution.d.ts +3 -5
  190. package/build/src/library/contract-execution.js +55 -96
  191. package/build/src/library/contract-outcomes.d.ts +2 -1
  192. package/build/src/library/contract-types.d.ts +5 -0
  193. package/build/src/library/contract-wait.d.ts +35 -0
  194. package/build/src/library/contract-wait.js +141 -0
  195. package/build/src/library/delivery.d.ts +13 -525
  196. package/build/src/library/delivery.js +1 -12
  197. package/build/src/library/input.js +2 -1
  198. package/build/src/library/invocation.d.ts +5 -1
  199. package/build/src/library/invocation.js +9 -2
  200. package/build/src/library/keiyaku.d.ts +7 -6
  201. package/build/src/library/keiyaku.js +12 -7
  202. package/build/src/library/outcome.d.ts +461 -12586
  203. package/build/src/library/outcome.js +15 -234
  204. package/build/src/library/reconcile.d.ts +12 -0
  205. package/build/src/library/reconcile.js +1 -0
  206. package/build/src/library/refusal.d.ts +251 -34
  207. package/build/src/library/refusal.js +10 -5
  208. package/build/src/library/selection.d.ts +9 -35
  209. package/build/src/library/selection.js +59 -129
  210. package/build/src/plugin/akuma-signals.d.ts +2 -2
  211. package/build/src/plugin/akuma-signals.js +2 -2
  212. package/build/src/plugin/public.d.ts +0 -7
  213. package/build/src/plugin/runtime.d.ts +2 -2
  214. package/build/src/plugin/runtime.js +4 -3
  215. package/build/src/protocol/attempt.js +7 -3
  216. package/build/src/protocol/bind.d.ts +18 -4
  217. package/build/src/protocol/bind.js +102 -35
  218. package/build/src/protocol/completion.d.ts +18 -331
  219. package/build/src/protocol/completion.js +17 -130
  220. package/build/src/protocol/deliver.d.ts +3 -3
  221. package/build/src/protocol/deliver.js +64 -74
  222. package/build/src/protocol/delivery-preview.d.ts +85 -28
  223. package/build/src/protocol/delivery-preview.js +34 -22
  224. package/build/src/protocol/execution-observation.d.ts +12 -9
  225. package/build/src/protocol/execution-observation.js +0 -1
  226. package/build/src/protocol/intent.d.ts +20 -50
  227. package/build/src/protocol/intent.js +37 -44
  228. package/build/src/protocol/operations.d.ts +299 -19
  229. package/build/src/protocol/operations.js +68 -27
  230. package/build/src/protocol/outcome.d.ts +1 -1
  231. package/build/src/protocol/placement.d.ts +2 -2
  232. package/build/src/protocol/placement.js +4 -3
  233. package/build/src/protocol/progress.d.ts +35 -2
  234. package/build/src/protocol/progress.js +12 -1
  235. package/build/src/protocol/read/observation.js +15 -4
  236. package/build/src/protocol/read/status.d.ts +9 -14
  237. package/build/src/protocol/read/status.js +15 -22
  238. package/build/src/protocol/reintegrate.d.ts +4 -3
  239. package/build/src/protocol/reintegrate.js +21 -5
  240. package/build/src/protocol/review.d.ts +9 -15
  241. package/build/src/protocol/review.js +2 -6
  242. package/build/src/protocol/run.d.ts +1 -1
  243. package/build/src/protocol/verify.d.ts +51 -0
  244. package/build/src/protocol/verify.js +128 -0
  245. package/build/src/runtime/proc/windows-launch.exe +0 -0
  246. package/build/src/verification/declaration.d.ts +5 -1
  247. package/build/src/verification/declaration.js +19 -2
  248. package/build/src/verification/execution.d.ts +5 -2
  249. package/build/src/verification/execution.js +48 -53
  250. package/build/src/verification/observation.d.ts +10 -6
  251. package/build/src/verification/observation.js +5 -2
  252. package/package.json +3 -3
  253. package/plugins/paseo/plugin/index.server.ts +3 -0
  254. package/plugins/paseo/plugin/server/attach.ts +42 -0
  255. package/plugins/paseo/plugin/server/mirror-identity.ts +51 -0
  256. package/plugins/paseo/plugin/server/model.ts +26 -0
  257. package/plugins/paseo/plugin/server/provider.ts +4 -6
  258. package/plugins/paseo/plugin/server/reopen.ts +4 -39
  259. package/plugins/pi/README.md +7 -12
  260. package/plugins/pi/akuma-tools.ts +3 -18
  261. package/skills/keiyaku/SKILL.md +14 -26
  262. package/skills/keiyaku-akuma/SKILL.md +64 -44
  263. package/skills/keiyaku-akuma/references/automation.md +13 -25
  264. package/skills/keiyaku-babysit/SKILL.md +1 -1
  265. package/skills/keiyaku-bind/SKILL.md +42 -29
  266. package/skills/keiyaku-debt/SKILL.md +13 -8
  267. package/skills/keiyaku-workflow/SKILL.md +57 -61
  268. package/build/src/akuma/allowed.d.ts +0 -23
  269. package/build/src/akuma/allowed.js +0 -63
  270. package/build/src/akuma/call-request.d.ts +0 -308
  271. package/build/src/akuma/call-request.js +0 -175
  272. package/build/src/akuma/heart/request-authority.d.ts +0 -16
  273. package/build/src/akuma/heart/request-authority.js +0 -140
  274. package/build/src/akuma/heart/request-rows.d.ts +0 -18
  275. package/build/src/akuma/heart/request-rows.js +0 -107
  276. package/build/src/akuma/request-lifecycle.d.ts +0 -42
  277. package/build/src/akuma/request-lifecycle.js +0 -197
  278. package/build/src/akuma/request-observation.d.ts +0 -45
  279. package/build/src/akuma/request-observation.js +0 -162
  280. package/build/src/akuma/request-rendezvous.d.ts +0 -32
  281. package/build/src/akuma/request-rendezvous.js +0 -189
  282. package/build/src/akuma/request-serve.d.ts +0 -16
  283. package/build/src/akuma/request-serve.js +0 -188
  284. package/build/src/akuma/request-wire.d.ts +0 -143
  285. package/build/src/akuma/request-wire.js +0 -146
  286. package/build/src/akuma/requests.d.ts +0 -20
  287. package/build/src/akuma/requests.js +0 -72
  288. package/build/src/akuma/selection-owner-port.d.ts +0 -14
  289. package/build/src/akuma/selection-owner-port.js +0 -54
  290. package/build/src/akuma/selection-request.d.ts +0 -305
  291. package/build/src/akuma/selection-request.js +0 -307
  292. package/build/src/body-requests.d.ts +0 -13
  293. package/build/src/body-requests.js +0 -131
  294. package/build/src/cli/square-identity.d.ts +0 -10
  295. package/build/src/cli/square-identity.js +0 -130
  296. package/build/src/debt/mutation-result.d.ts +0 -981
  297. package/build/src/debt/mutation-result.js +0 -109
  298. package/build/src/debt/mutation.d.ts +0 -424
  299. package/build/src/debt/mutation.js +0 -223
  300. package/build/src/library/contract-operations.d.ts +0 -382
  301. package/build/src/library/contract-operations.js +0 -300
@@ -1,300 +0,0 @@
1
- import { isAbsolute, resolve } from "node:path";
2
- import { z } from "zod";
3
- import { AkumaBodyRequestError, requestBodyCommand } from "../akuma/request-rendezvous.js";
4
- import { eraseRequestCommand, } from "../akuma/request-wire.js";
5
- import { deliveryPreviewReportSchema } from "../protocol/delivery-preview.js";
6
- import { materializedConflictSchema } from "../protocol/deliver.js";
7
- import { observationSchema, observeExecution } from "../protocol/execution-observation.js";
8
- import { contractIdSchema } from "../protocol/operations.js";
9
- import { deliveryValueSchema } from "./delivery.js";
10
- import { InvocationAccumulator } from "./invocation.js";
11
- import { decodeFailureWire, encodeFailureWire, KeiyakuError, outcomeSchema, project, reviewSchema } from "./outcome.js";
12
- const absolutePathSchema = z.string().refine((value) => isAbsolute(value) && resolve(value) === value);
13
- const nonblankStringSchema = z.string().refine((value) => value.trim() !== "");
14
- const contractRequestBaseSchema = z.object({ repoRoot: absolutePathSchema, contractId: contractIdSchema }).strict();
15
- const previewRequestSchema = contractRequestBaseSchema
16
- .extend({
17
- includeDirty: z.boolean(),
18
- showDiff: z.boolean(),
19
- })
20
- .transform((request) => ({ action: "contract.preview-delivery", ...request }));
21
- const deliverRequestSchema = contractRequestBaseSchema
22
- .extend({
23
- includeDirty: z.boolean(),
24
- materializeConflict: z.boolean(),
25
- overwrite: z.boolean().optional(),
26
- message: nonblankStringSchema.optional(),
27
- })
28
- .transform((request) => ({ action: "contract.deliver", ...request }));
29
- const reviewRequestSchema = contractRequestBaseSchema
30
- .extend({
31
- verdict: z.enum(["satisfied", "unsatisfied"]),
32
- summary: nonblankStringSchema.optional(),
33
- actor: z.string().optional(),
34
- })
35
- .transform((request) => ({ action: "contract.review", ...request }));
36
- const previewServiceSchema = z
37
- .object({
38
- kind: z.literal("delivery-preview-report"),
39
- repoRoot: absolutePathSchema,
40
- contractId: contractIdSchema,
41
- report: deliveryPreviewReportSchema,
42
- })
43
- .strict();
44
- const deliveryReferenceSchema = z
45
- .object({
46
- kind: z.literal("accepted-reference"),
47
- repoRoot: absolutePathSchema,
48
- contractId: contractIdSchema,
49
- deliveryFactId: nonblankStringSchema,
50
- })
51
- .strict();
52
- const reviewReferenceSchema = z
53
- .object({
54
- kind: z.literal("accepted-reference"),
55
- repoRoot: absolutePathSchema,
56
- contractId: contractIdSchema,
57
- reviewFactId: nonblankStringSchema,
58
- })
59
- .strict();
60
- const materializedHandoffReferenceSchema = materializedConflictSchema;
61
- const materializedHandoffServiceSchema = materializedConflictSchema
62
- .extend({
63
- kind: z.literal("materialized-handoff"),
64
- repoRoot: absolutePathSchema,
65
- contractId: contractIdSchema,
66
- })
67
- .strict();
68
- const contractServiceSchema = z.union([
69
- previewServiceSchema,
70
- deliveryReferenceSchema,
71
- materializedHandoffServiceSchema,
72
- reviewReferenceSchema,
73
- ]);
74
- function decodeContractRequest(action, value) {
75
- const schema = action === "contract.preview-delivery"
76
- ? previewRequestSchema
77
- : action === "contract.deliver"
78
- ? deliverRequestSchema
79
- : reviewRequestSchema;
80
- const parsed = schema.safeParse(value);
81
- return parsed.success ? parsed.data : null;
82
- }
83
- function decodeContractService(action, value) {
84
- const schema = action === "contract.preview-delivery"
85
- ? previewServiceSchema
86
- : action === "contract.deliver"
87
- ? z.union([deliveryReferenceSchema, materializedHandoffServiceSchema])
88
- : reviewReferenceSchema;
89
- const parsed = schema.safeParse(value);
90
- if (!parsed.success)
91
- throw new Error(`malformed stored Contract service evidence for ${action}`);
92
- return parsed.data;
93
- }
94
- function projectContractService(action, service) {
95
- if (action === "contract.deliver" && service.kind === "materialized-handoff") {
96
- const { kind: _kind, repoRoot: _repoRoot, contractId: _contractId, ...handoff } = service;
97
- return { kind: "integration-conflict-materialized", ...handoff };
98
- }
99
- return service;
100
- }
101
- function decodeContractReference(action, value) {
102
- if (action !== "contract.deliver")
103
- return decodeContractService(action, value);
104
- const parsed = z.union([deliveryReferenceSchema, materializedHandoffReferenceSchema]).safeParse(value);
105
- if (!parsed.success)
106
- throw new Error(`malformed stored Contract service evidence for ${action}`);
107
- return parsed.data;
108
- }
109
- function executionObservation(facts) {
110
- if (facts.progress === undefined)
111
- return {};
112
- return { observe: (event) => facts.progress?.(event) };
113
- }
114
- function acceptedDeliveryEvidence(result) {
115
- const leading = result.value.leading;
116
- if (leading === undefined)
117
- throw new Error("accepted delivery is missing its leading admission evidence");
118
- return leading.fact;
119
- }
120
- function acceptedReviewEvidence(result, contractId) {
121
- const review = result.facts.findLast((fact) => fact.contract === contractId && fact.kind === "attestation" && fact.data.gate === "reviewed");
122
- if (review === undefined)
123
- throw new Error("accepted review is missing its addressed journal fact");
124
- return review.entry;
125
- }
126
- async function executeContractRequest(request, facts, port) {
127
- const observation = executionObservation(facts);
128
- if (request.action === "contract.preview-delivery") {
129
- const result = await port.previewDelivery({
130
- ...request,
131
- ...observation,
132
- requester: facts.requester,
133
- signal: facts.signal,
134
- });
135
- if (result.kind !== "accepted")
136
- return { kind: "voided", outcome: result };
137
- return {
138
- kind: "served",
139
- result,
140
- service: {
141
- kind: "delivery-preview-report",
142
- repoRoot: request.repoRoot,
143
- contractId: request.contractId,
144
- report: result.value,
145
- },
146
- };
147
- }
148
- if (request.action === "contract.deliver") {
149
- const result = await port.deliver({
150
- ...request,
151
- ...observation,
152
- overwrite: request.overwrite ?? false,
153
- requester: facts.requester,
154
- signal: facts.signal,
155
- });
156
- if (result.kind === "refused" || result.kind === "retry")
157
- return { kind: "voided", outcome: result };
158
- if (result.kind === "handoff") {
159
- return {
160
- kind: "served",
161
- result,
162
- service: {
163
- kind: "materialized-handoff",
164
- repoRoot: request.repoRoot,
165
- contractId: request.contractId,
166
- targetHead: result.value.targetHead,
167
- handoffBase: result.value.handoffBase,
168
- recovery: result.value.recovery,
169
- conflictPaths: result.value.conflictPaths,
170
- workspace: result.value.workspace,
171
- },
172
- };
173
- }
174
- return {
175
- kind: "served",
176
- result,
177
- service: {
178
- kind: "accepted-reference",
179
- repoRoot: request.repoRoot,
180
- contractId: request.contractId,
181
- deliveryFactId: acceptedDeliveryEvidence(result),
182
- },
183
- };
184
- }
185
- const result = await port.review({
186
- ...request,
187
- ...observation,
188
- requester: facts.requester,
189
- signal: facts.signal,
190
- });
191
- if (result.kind !== "accepted")
192
- return { kind: "voided", outcome: result };
193
- return {
194
- kind: "served",
195
- result,
196
- service: {
197
- kind: "accepted-reference",
198
- repoRoot: request.repoRoot,
199
- contractId: request.contractId,
200
- reviewFactId: acceptedReviewEvidence(result, request.contractId),
201
- },
202
- };
203
- }
204
- function decodedContractResult(action, value) {
205
- const schema = action === "contract.preview-delivery"
206
- ? outcomeSchema("deliver-preview", deliveryPreviewReportSchema)
207
- : action === "contract.deliver"
208
- ? outcomeSchema("deliver", deliveryValueSchema, materializedHandoffReferenceSchema)
209
- : outcomeSchema("review", reviewSchema);
210
- const parsed = schema.safeParse(value);
211
- if (!parsed.success)
212
- throw new Error(`transport integrity: Contract ${action} returned an invalid live result`);
213
- return parsed.data;
214
- }
215
- export function contractRequestProtocol(action) {
216
- return {
217
- action,
218
- supportsCancellation: true,
219
- encodeRequest: (request) => {
220
- const { action: _action, ...payload } = request;
221
- return payload;
222
- },
223
- decodeRequest: (value) => decodeContractRequest(action, value),
224
- encodeResult: (value) => value,
225
- decodeResult: (value) => decodedContractResult(action, value),
226
- encodeFailure: encodeFailureWire,
227
- decodeFailure: (value) => decodeFailureWire(value),
228
- decodeReference: (reference) => decodeContractReference(action, reference),
229
- isPermitted: (allowed) => action === "contract.preview-delivery" || allowed.includes(action),
230
- };
231
- }
232
- export function contractRequestCommand(action, port) {
233
- return {
234
- completion: "service",
235
- protocol: contractRequestProtocol(action),
236
- encodeService: (service) => service,
237
- decodeService: (service) => decodeContractService(action, service),
238
- projectService: (service) => projectContractService(action, service),
239
- execute: async (request, facts) => await executeContractRequest(request, facts, port),
240
- };
241
- }
242
- export function contractRequestCommands(port) {
243
- return {
244
- "contract.preview-delivery": eraseRequestCommand(contractRequestCommand("contract.preview-delivery", port)),
245
- "contract.deliver": eraseRequestCommand(contractRequestCommand("contract.deliver", port)),
246
- "contract.review": eraseRequestCommand(contractRequestCommand("contract.review", port)),
247
- };
248
- }
249
- export async function requestForwardedContractLive(input) {
250
- const command = contractRequestProtocol(input.action);
251
- const response = await requestBodyCommand({
252
- directory: input.directory,
253
- command,
254
- value: input.request,
255
- onProgress: (value) => {
256
- try {
257
- observeExecution(input.observe, observationSchema.parse(value));
258
- }
259
- catch {
260
- observeExecution(input.observe, { kind: "progress-dropped", count: 1 });
261
- }
262
- },
263
- onProgressGap: (count) => observeExecution(input.observe, { kind: "progress-dropped", count }),
264
- ...(input.signal === undefined ? {} : { signal: input.signal }),
265
- }).catch((error) => mapForwardedContractFailure(error, input.request));
266
- if (response.kind === "reference") {
267
- throw new Error(`transport integrity: request ${response.requestId} action ${response.action} returned a durable reference without a live result`);
268
- }
269
- return response.result;
270
- }
271
- /** Map durable request disposition without reconstructing an expired owner answer. */
272
- export function mapForwardedContractFailure(error, request) {
273
- if (error instanceof AkumaBodyRequestError && error.outcome === "voided") {
274
- const operation = request.action === "contract.preview-delivery"
275
- ? "deliver-preview"
276
- : request.action === "contract.review"
277
- ? "review"
278
- : "deliver";
279
- const projected = project(operation, new InvocationAccumulator().snapshot(), {
280
- kind: "retry",
281
- contract: request.contractId,
282
- reason: { kind: "owner-reason-unavailable", diagnostic: error.diagnostic },
283
- });
284
- if (projected.kind === "failed")
285
- throw projected.error;
286
- return { kind: "returned", result: projected.outcome };
287
- }
288
- if (error instanceof AkumaBodyRequestError &&
289
- error.outcome === "unproven" &&
290
- error.cause instanceof Error &&
291
- error.cause instanceof KeiyakuError) {
292
- Object.defineProperties(error.cause, {
293
- requestId: { value: error.requestId, enumerable: false },
294
- action: { value: error.action, enumerable: false },
295
- requestOutcome: { value: error.outcome, enumerable: false },
296
- });
297
- throw error.cause;
298
- }
299
- throw error;
300
- }