@astrosheep/keiyaku 4.0.4 → 4.0.6

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 (233) hide show
  1. package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +1 -1
  2. package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +1 -1
  3. package/build/integrations/marketplace/plugins/keiyaku/package.json +1 -1
  4. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +4 -4
  5. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +15 -7
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +5 -3
  7. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +24 -4
  8. package/build/src/akuma/akuma.d.ts +2 -1
  9. package/build/src/akuma/akuma.js +27 -9
  10. package/build/src/akuma/allowed.d.ts +1 -1
  11. package/build/src/akuma/allowed.js +3 -10
  12. package/build/src/akuma/archetype.d.ts +3 -1
  13. package/build/src/akuma/archetype.js +11 -6
  14. package/build/src/akuma/body-turn.d.ts +64 -0
  15. package/build/src/akuma/body-turn.js +449 -0
  16. package/build/src/akuma/body.d.ts +4 -5
  17. package/build/src/akuma/body.js +9 -414
  18. package/build/src/akuma/heart/facts.d.ts +37 -9
  19. package/build/src/akuma/heart/facts.js +3 -1
  20. package/build/src/akuma/heart/index.d.ts +4 -13
  21. package/build/src/akuma/heart/index.js +14 -135
  22. package/build/src/akuma/heart/request-authority.d.ts +12 -0
  23. package/build/src/akuma/heart/request-authority.js +119 -0
  24. package/build/src/akuma/heart/request-rows.d.ts +16 -0
  25. package/build/src/akuma/heart/request-rows.js +88 -0
  26. package/build/src/akuma/heart/rows.d.ts +1 -28
  27. package/build/src/akuma/heart/rows.js +4 -138
  28. package/build/src/akuma/heart/schema.d.ts +1 -1
  29. package/build/src/akuma/heart/schema.js +11 -3
  30. package/build/src/akuma/heart/soul.js +0 -36
  31. package/build/src/akuma/heart/timeline.d.ts +1 -0
  32. package/build/src/akuma/heart/timeline.js +19 -0
  33. package/build/src/akuma/index.d.ts +1 -1
  34. package/build/src/akuma/nuke.d.ts +2 -0
  35. package/build/src/akuma/nuke.js +152 -0
  36. package/build/src/akuma/provider-recipe.js +1 -11
  37. package/build/src/akuma/provider.d.ts +4 -7
  38. package/build/src/akuma/providers/acp/config.d.ts +8 -0
  39. package/build/src/akuma/providers/acp/config.js +37 -0
  40. package/build/src/akuma/providers/acp/core.js +12 -2
  41. package/build/src/akuma/providers/acp/index.d.ts +1 -8
  42. package/build/src/akuma/providers/acp/index.js +2 -38
  43. package/build/src/akuma/providers/claude/index.d.ts +0 -4
  44. package/build/src/akuma/providers/claude/index.js +12 -3
  45. package/build/src/akuma/providers/codex-app-server/index.d.ts +2 -27
  46. package/build/src/akuma/providers/codex-app-server/index.js +5 -2
  47. package/build/src/akuma/providers/grok-build/index.js +1 -2
  48. package/build/src/akuma/providers/index.d.ts +3 -2
  49. package/build/src/akuma/providers/index.js +36 -36
  50. package/build/src/akuma/providers/opencode-sdk/index.d.ts +2 -28
  51. package/build/src/akuma/providers/opencode-sdk/index.js +14 -4
  52. package/build/src/akuma/providers/opencode-sdk/session.d.ts +2 -2
  53. package/build/src/akuma/providers/opencode-sdk/session.js +2 -2
  54. package/build/src/akuma/providers/pi/index.d.ts +1 -1
  55. package/build/src/akuma/providers/pi/index.js +29 -6
  56. package/build/src/akuma/request-serve.d.ts +88 -0
  57. package/build/src/akuma/request-serve.js +484 -0
  58. package/build/src/akuma/request-wire.d.ts +125 -0
  59. package/build/src/akuma/request-wire.js +383 -0
  60. package/build/src/akuma/requests.d.ts +28 -94
  61. package/build/src/akuma/requests.js +52 -562
  62. package/build/src/akuma-body.d.ts +7 -0
  63. package/build/src/akuma-body.js +69 -2
  64. package/build/src/alias/index.d.ts +1 -0
  65. package/build/src/alias/index.js +34 -1
  66. package/build/src/body/arc.js +4 -29
  67. package/build/src/body/decode.js +5 -39
  68. package/build/src/body/envelope.d.ts +7 -0
  69. package/build/src/body/envelope.js +37 -0
  70. package/build/src/cli/accepted.js +21 -9
  71. package/build/src/cli/commands/akuma-invoke.js +1 -0
  72. package/build/src/cli/commands/akuma.d.ts +1 -0
  73. package/build/src/cli/commands/akuma.js +13 -10
  74. package/build/src/cli/commands/contract.d.ts +28 -17
  75. package/build/src/cli/commands/contract.js +23 -17
  76. package/build/src/cli/commands/install.d.ts +2 -2
  77. package/build/src/cli/commands/install.js +6 -6
  78. package/build/src/cli/commands/nuke.d.ts +10 -0
  79. package/build/src/cli/commands/nuke.js +20 -0
  80. package/build/src/cli/commands/task-invoke.d.ts +15 -0
  81. package/build/src/cli/commands/task-invoke.js +144 -24
  82. package/build/src/cli/commands/task-query.d.ts +2 -2
  83. package/build/src/cli/commands/task-query.js +1 -2
  84. package/build/src/cli/commands/task.js +22 -22
  85. package/build/src/cli/coordinates.d.ts +6 -2
  86. package/build/src/cli/coordinates.js +12 -56
  87. package/build/src/cli/invoke.d.ts +5 -4
  88. package/build/src/cli/invoke.js +112 -58
  89. package/build/src/cli/main.d.ts +0 -2
  90. package/build/src/cli/main.js +4 -140
  91. package/build/src/cli/parse.d.ts +17 -4
  92. package/build/src/cli/parse.js +93 -15
  93. package/build/src/cli/render/akuma.js +111 -53
  94. package/build/src/cli/render/audit.js +2 -6
  95. package/build/src/cli/render/contract.js +61 -20
  96. package/build/src/cli/render/kanshi.js +15 -5
  97. package/build/src/cli/render/nuke.d.ts +3 -0
  98. package/build/src/cli/render/nuke.js +8 -0
  99. package/build/src/cli/render/receipt.js +28 -1
  100. package/build/src/cli/render/refusal.d.ts +2 -1
  101. package/build/src/cli/render/refusal.js +31 -0
  102. package/build/src/cli/render/terminal.d.ts +0 -2
  103. package/build/src/cli/render/terminal.js +0 -29
  104. package/build/src/cli/render/text.js +6 -1
  105. package/build/src/cli/result.d.ts +36 -9
  106. package/build/src/cli/runtime.d.ts +2 -0
  107. package/build/src/cli/runtime.js +140 -0
  108. package/build/src/cli/usage.d.ts +0 -2
  109. package/build/src/cli/usage.js +0 -4
  110. package/build/src/contract-worktree.d.ts +29 -14
  111. package/build/src/contract-worktree.js +131 -70
  112. package/build/src/core/facts/codec.js +9 -0
  113. package/build/src/core/facts/fold.js +13 -1
  114. package/build/src/core/facts/types.d.ts +8 -1
  115. package/build/src/core/subject.js +4 -3
  116. package/build/src/core/verbs/placement.d.ts +9 -1
  117. package/build/src/core/verbs/placement.js +24 -6
  118. package/build/src/core/verbs/reintegrate.d.ts +13 -0
  119. package/build/src/core/verbs/reintegrate.js +24 -0
  120. package/build/src/dispatch/index.d.ts +1 -1
  121. package/build/src/git/admission.d.ts +2 -1
  122. package/build/src/git/hooks.d.ts +2 -0
  123. package/build/src/git/hooks.js +34 -1
  124. package/build/src/git/integration.d.ts +9 -2
  125. package/build/src/git/integration.js +92 -1
  126. package/build/src/git/nuke.d.ts +2 -0
  127. package/build/src/git/nuke.js +97 -0
  128. package/build/src/git/observe.d.ts +2 -1
  129. package/build/src/git/observe.js +6 -5
  130. package/build/src/git/process.d.ts +28 -0
  131. package/build/src/git/process.js +94 -0
  132. package/build/src/git/read-observation.d.ts +2 -1
  133. package/build/src/git/read-observation.js +3 -2
  134. package/build/src/git/reconcile.d.ts +4 -1
  135. package/build/src/git/reconcile.js +42 -8
  136. package/build/src/git/repository.d.ts +2 -29
  137. package/build/src/git/repository.js +7 -118
  138. package/build/src/git/scratch.d.ts +1 -1
  139. package/build/src/git/scratch.js +1 -1
  140. package/build/src/git/target-placement.d.ts +3 -2
  141. package/build/src/git/target-placement.js +15 -14
  142. package/build/src/git/tender.d.ts +2 -1
  143. package/build/src/git/tender.js +4 -3
  144. package/build/src/git/terminal-seal.d.ts +2 -2
  145. package/build/src/git/terminal-seal.js +3 -6
  146. package/build/src/git/workspace.d.ts +4 -1
  147. package/build/src/git/workspace.js +1 -1
  148. package/build/src/index.d.ts +1 -2
  149. package/build/src/index.js +1 -1
  150. package/build/src/kanshi/read.js +5 -1
  151. package/build/src/library/address.js +7 -1
  152. package/build/src/library/akuma-creation.d.ts +1 -0
  153. package/build/src/library/akuma-creation.js +8 -1
  154. package/build/src/library/audit.d.ts +3 -1
  155. package/build/src/library/audit.js +2 -1
  156. package/build/src/library/bind.d.ts +2 -1
  157. package/build/src/library/bind.js +1 -1
  158. package/build/src/library/configuration.d.ts +1 -1
  159. package/build/src/library/configuration.js +52 -18
  160. package/build/src/library/contract.d.ts +59 -4
  161. package/build/src/library/contract.js +195 -34
  162. package/build/src/library/delivery.d.ts +4 -2
  163. package/build/src/library/fleet.d.ts +27 -7
  164. package/build/src/library/fleet.js +79 -39
  165. package/build/src/library/input.d.ts +0 -1
  166. package/build/src/library/input.js +0 -5
  167. package/build/src/library/keiyaku.d.ts +6 -2
  168. package/build/src/library/keiyaku.js +2 -0
  169. package/build/src/library/mutation.d.ts +3 -1
  170. package/build/src/library/mutation.js +3 -0
  171. package/build/src/library/nuke.d.ts +14 -0
  172. package/build/src/library/nuke.js +54 -0
  173. package/build/src/library/reconcile.d.ts +2 -1
  174. package/build/src/library/reconcile.js +8 -3
  175. package/build/src/library/refusal.d.ts +10 -1
  176. package/build/src/library/region.d.ts +1 -1
  177. package/build/src/library/repo.d.ts +4 -1
  178. package/build/src/library/repo.js +10 -4
  179. package/build/src/protocol/abandon.d.ts +9 -0
  180. package/build/src/protocol/abandon.js +15 -0
  181. package/build/src/protocol/amend.d.ts +16 -0
  182. package/build/src/protocol/amend.js +77 -0
  183. package/build/src/protocol/arc.d.ts +6 -0
  184. package/build/src/protocol/arc.js +12 -0
  185. package/build/src/protocol/attempt.d.ts +2 -1
  186. package/build/src/protocol/audit.d.ts +53 -0
  187. package/build/src/protocol/audit.js +147 -0
  188. package/build/src/protocol/bind.d.ts +1 -1
  189. package/build/src/protocol/completion.d.ts +42 -0
  190. package/build/src/protocol/completion.js +183 -0
  191. package/build/src/protocol/deliver.d.ts +49 -0
  192. package/build/src/protocol/deliver.js +261 -0
  193. package/build/src/protocol/intent.d.ts +2 -1
  194. package/build/src/protocol/intent.js +8 -2
  195. package/build/src/protocol/operations.d.ts +93 -202
  196. package/build/src/protocol/operations.js +23 -642
  197. package/build/src/protocol/placement.d.ts +12 -13
  198. package/build/src/protocol/placement.js +8 -19
  199. package/build/src/protocol/read/status.d.ts +17 -5
  200. package/build/src/protocol/read/status.js +57 -13
  201. package/build/src/protocol/reconcile.d.ts +35 -0
  202. package/build/src/protocol/reconcile.js +41 -0
  203. package/build/src/protocol/reintegrate.d.ts +31 -0
  204. package/build/src/protocol/reintegrate.js +74 -0
  205. package/build/src/protocol/review.d.ts +34 -0
  206. package/build/src/protocol/review.js +156 -0
  207. package/build/src/protocol/run.d.ts +1 -1
  208. package/build/src/runtime/proc/run.js +9 -5
  209. package/build/src/settlement/fence.d.ts +3 -1
  210. package/build/src/settlement/fence.js +24 -0
  211. package/build/src/settlement/holder.d.ts +1 -1
  212. package/build/src/settlement/settle.d.ts +1 -1
  213. package/build/src/settlement/settle.js +1 -2
  214. package/build/src/task/board.d.ts +0 -1
  215. package/build/src/task/board.js +0 -3
  216. package/build/src/task/compose.d.ts +2 -2
  217. package/build/src/task/compose.js +13 -11
  218. package/build/src/task/context.d.ts +14 -2
  219. package/build/src/task/context.js +30 -7
  220. package/build/src/task/index.d.ts +7 -6
  221. package/build/src/task/index.js +17 -145
  222. package/build/src/task/input.d.ts +18 -0
  223. package/build/src/task/input.js +189 -0
  224. package/build/src/task/mutation.d.ts +44 -0
  225. package/build/src/task/mutation.js +93 -0
  226. package/build/src/task/operations.d.ts +14 -6
  227. package/build/src/task/operations.js +57 -57
  228. package/build/src/task/store.d.ts +1 -0
  229. package/build/src/task/store.js +91 -3
  230. package/build/src/verification/execution.d.ts +1 -1
  231. package/build/src/workspace-place.d.ts +3 -4
  232. package/build/src/workspace-place.js +26 -15
  233. package/package.json +3 -3
@@ -0,0 +1,383 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { rename, rm, writeFile } from "node:fs/promises";
3
+ import { isAbsolute, join, resolve } from "node:path";
4
+ import { decodeAllowedActions } from "./allowed.js";
5
+ import { archetypeName, parseAkuId } from "./identity.js";
6
+ import { decodeProviderOptions, decodeReadonlyRestraint, } from "./provider-recipe.js";
7
+ import { decodeProviderExecution } from "./providers/index.js";
8
+ import { decodeTaskMutationRequest, isTaskMutationAction, } from "../task/mutation.js";
9
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
10
+ function object(value) {
11
+ return value !== null && typeof value === "object" && !Array.isArray(value)
12
+ ? value
13
+ : null;
14
+ }
15
+ function exactKeys(value, expected) {
16
+ const actual = Object.keys(value).sort();
17
+ const sorted = [...expected].sort();
18
+ return actual.length === sorted.length && actual.every((key, index) => key === sorted[index]);
19
+ }
20
+ export function absolute(value) {
21
+ return typeof value === "string" && isAbsolute(value) && resolve(value) === value;
22
+ }
23
+ export function canonicalAkuId(value) {
24
+ if (typeof value !== "string")
25
+ return null;
26
+ try {
27
+ const id = parseAkuId(value).id;
28
+ return id === value ? id : null;
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ }
34
+ function canonicalTargets(value) {
35
+ if (!Array.isArray(value) || value.length === 0)
36
+ return null;
37
+ const ids = [];
38
+ for (const item of value) {
39
+ const id = canonicalAkuId(item);
40
+ if (id === null
41
+ || (ids.length > 0
42
+ && Buffer.compare(Buffer.from(ids.at(-1)), Buffer.from(id)) >= 0))
43
+ return null;
44
+ ids.push(id);
45
+ }
46
+ return ids;
47
+ }
48
+ export function decodeRecipe(value) {
49
+ const recipe = object(value);
50
+ if (recipe === null)
51
+ return null;
52
+ const expected = [
53
+ "allowed",
54
+ "options",
55
+ "provider",
56
+ ...(recipe.description === undefined ? [] : ["description"]),
57
+ ...(recipe.readonly === undefined ? [] : ["readonly"]),
58
+ ];
59
+ if (!exactKeys(recipe, expected)
60
+ || (recipe.description !== undefined
61
+ && (typeof recipe.description !== "string"
62
+ || recipe.description.trim().length === 0)))
63
+ return null;
64
+ try {
65
+ const options = decodeProviderOptions(recipe.options);
66
+ const readonly = recipe.readonly === undefined ? undefined : decodeReadonlyRestraint(recipe.readonly);
67
+ if ((options.readonly === true) !== (readonly !== undefined))
68
+ return null;
69
+ return Object.freeze({
70
+ ...(recipe.description === undefined ? {} : { description: recipe.description }),
71
+ allowed: decodeAllowedActions(recipe.allowed),
72
+ provider: decodeProviderExecution(recipe.provider),
73
+ options,
74
+ ...(readonly === undefined ? {} : { readonly }),
75
+ });
76
+ }
77
+ catch {
78
+ return null;
79
+ }
80
+ }
81
+ function contractId(value) {
82
+ return typeof value === "string" && /^kei\/[^/\s]+$/u.test(value) ? value : null;
83
+ }
84
+ function decodeCall(id, payload) {
85
+ const expected = [
86
+ "archetype",
87
+ "body",
88
+ "recipe",
89
+ "world",
90
+ ...(payload.cwd === undefined ? [] : ["cwd"]),
91
+ ];
92
+ if (!exactKeys(payload, expected)
93
+ || typeof payload.body !== "string"
94
+ || !absolute(payload.world)
95
+ || (payload.cwd !== undefined && !absolute(payload.cwd)))
96
+ return null;
97
+ try {
98
+ archetypeName(payload.archetype);
99
+ }
100
+ catch {
101
+ return null;
102
+ }
103
+ return {
104
+ id,
105
+ action: "akuma.call",
106
+ world: payload.world,
107
+ archetype: payload.archetype,
108
+ body: payload.body,
109
+ recipe: payload.recipe,
110
+ ...(payload.cwd === undefined ? {} : { cwd: payload.cwd }),
111
+ };
112
+ }
113
+ function decodeWait(id, payload) {
114
+ const targets = canonicalTargets(payload.targets);
115
+ const expected = [
116
+ "completion",
117
+ "targets",
118
+ ...(payload.timeoutMs === undefined ? [] : ["timeoutMs"]),
119
+ ];
120
+ if (!exactKeys(payload, expected)
121
+ || targets === null
122
+ || (payload.completion !== "any" && payload.completion !== "all")
123
+ || (payload.timeoutMs !== undefined
124
+ && (!Number.isSafeInteger(payload.timeoutMs)
125
+ || payload.timeoutMs < 0)))
126
+ return null;
127
+ return {
128
+ id,
129
+ action: "akuma.wait",
130
+ targets,
131
+ completion: payload.completion,
132
+ ...(payload.timeoutMs === undefined
133
+ ? {}
134
+ : { timeoutMs: payload.timeoutMs }),
135
+ };
136
+ }
137
+ function decodeTell(id, payload) {
138
+ const target = canonicalAkuId(payload.target);
139
+ return exactKeys(payload, ["body", "target"])
140
+ && target !== null
141
+ && typeof payload.body === "string"
142
+ ? { id, action: "akuma.tell", target, body: payload.body }
143
+ : null;
144
+ }
145
+ function decodeKill(id, payload) {
146
+ const targets = canonicalTargets(payload.targets);
147
+ return exactKeys(payload, ["targets"])
148
+ && targets !== null
149
+ ? { id, action: "akuma.kill", targets }
150
+ : null;
151
+ }
152
+ function decodeDeliver(id, payload) {
153
+ const valid = exactKeys(payload, [
154
+ "contractId",
155
+ "includeDirty",
156
+ "materializeConflict",
157
+ "repoRoot",
158
+ ...(payload.message === undefined ? [] : ["message"]),
159
+ ]);
160
+ const selected = contractId(payload.contractId);
161
+ return valid
162
+ && selected !== null
163
+ && absolute(payload.repoRoot)
164
+ && typeof payload.includeDirty === "boolean"
165
+ && typeof payload.materializeConflict === "boolean"
166
+ && (payload.message === undefined
167
+ || (typeof payload.message === "string"
168
+ && payload.message.trim().length > 0))
169
+ ? {
170
+ id,
171
+ action: "contract.deliver",
172
+ repoRoot: payload.repoRoot,
173
+ contractId: selected,
174
+ includeDirty: payload.includeDirty,
175
+ materializeConflict: payload.materializeConflict,
176
+ ...(payload.message === undefined
177
+ ? {}
178
+ : { message: payload.message }),
179
+ }
180
+ : null;
181
+ }
182
+ function decodeReview(id, payload) {
183
+ const valid = exactKeys(payload, [
184
+ "contractId",
185
+ "repoRoot",
186
+ "verdict",
187
+ ...(payload.summary === undefined ? [] : ["summary"]),
188
+ ]);
189
+ const selected = contractId(payload.contractId);
190
+ return valid
191
+ && selected !== null
192
+ && absolute(payload.repoRoot)
193
+ && (payload.verdict === "satisfied" || payload.verdict === "unsatisfied")
194
+ && (payload.summary === undefined
195
+ || (typeof payload.summary === "string"
196
+ && payload.summary.trim().length > 0))
197
+ ? {
198
+ id,
199
+ action: "contract.review",
200
+ repoRoot: payload.repoRoot,
201
+ contractId: selected,
202
+ verdict: payload.verdict,
203
+ ...(payload.summary === undefined
204
+ ? {}
205
+ : { summary: payload.summary }),
206
+ }
207
+ : null;
208
+ }
209
+ function decodeTask(id, action, payload) {
210
+ if (!isTaskMutationAction(action)
211
+ || !exactKeys(payload, ["request", "world"])
212
+ || !absolute(payload.world))
213
+ return null;
214
+ try {
215
+ return {
216
+ id,
217
+ action,
218
+ world: payload.world,
219
+ request: decodeTaskMutationRequest(action, payload.request),
220
+ };
221
+ }
222
+ catch {
223
+ return null;
224
+ }
225
+ }
226
+ const CLAIM_DECODERS = {
227
+ "akuma.call": decodeCall,
228
+ "akuma.wait": decodeWait,
229
+ "akuma.tell": decodeTell,
230
+ "akuma.kill": decodeKill,
231
+ "contract.deliver": decodeDeliver,
232
+ "contract.review": decodeReview,
233
+ };
234
+ export function decodeClaim(bytes, fileId) {
235
+ let decoded;
236
+ try {
237
+ decoded = JSON.parse(bytes);
238
+ }
239
+ catch {
240
+ return null;
241
+ }
242
+ const value = object(decoded);
243
+ if (value === null
244
+ || !exactKeys(value, ["action", "id", "payload"])
245
+ || value.id !== fileId
246
+ || typeof value.id !== "string"
247
+ || !UUID.test(value.id))
248
+ return null;
249
+ const payload = object(value.payload);
250
+ if (payload === null || typeof value.action !== "string")
251
+ return null;
252
+ const decoder = CLAIM_DECODERS[value.action];
253
+ return decoder === undefined ? decodeTask(value.id, value.action, payload) : decoder(value.id, payload);
254
+ }
255
+ function outcome(value) {
256
+ const input = object(value);
257
+ if (input?.kind === "returned" && exactKeys(input, ["kind", "result"])) {
258
+ return { kind: input.kind, result: input.result };
259
+ }
260
+ const failure = object(input?.failure);
261
+ if (input?.kind !== "failed"
262
+ || !exactKeys(input, ["failure", "kind"])
263
+ || failure === null)
264
+ return null;
265
+ if (failure.kind === "akuma-not-born" && exactKeys(failure, ["id", "kind"])) {
266
+ const id = canonicalAkuId(failure.id);
267
+ return id === null
268
+ ? null
269
+ : { kind: input.kind, failure: { kind: failure.kind, id } };
270
+ }
271
+ return failure.kind === "failed" && exactKeys(failure, ["diagnostic", "kind"]) && typeof failure.diagnostic === "string"
272
+ ? { kind: input.kind, failure: { kind: failure.kind, diagnostic: failure.diagnostic } } : null;
273
+ }
274
+ function envelope(value, id, action) {
275
+ if (value.state === "refused"
276
+ && exactKeys(value, ["action", "diagnostic", "id", "state"])
277
+ && typeof value.diagnostic === "string") {
278
+ return { id, action, state: value.state, diagnostic: value.diagnostic };
279
+ }
280
+ if (value.state === "voided"
281
+ && exactKeys(value, ["action", "evidence", "id", "state"])
282
+ && typeof value.evidence === "string") {
283
+ return { id, action, state: value.state, evidence: value.evidence };
284
+ }
285
+ if (action !== "akuma.call"
286
+ && value.state === "served"
287
+ && exactKeys(value, ["action", "id", "outcome", "state"])) {
288
+ const decoded = outcome(value.outcome);
289
+ return decoded === null
290
+ ? null
291
+ : { id, action, state: value.state, outcome: decoded };
292
+ }
293
+ return null;
294
+ }
295
+ function reference(value, action) {
296
+ const input = object(value);
297
+ const field = action === "contract.deliver" ? "deliveryFactId" : "reviewFactId";
298
+ if (input === null
299
+ || !exactKeys(input, ["contractId", field, "kind", "repoRoot"])
300
+ || input.kind !== "accepted-reference"
301
+ || !absolute(input.repoRoot)
302
+ || contractId(input.contractId) === null
303
+ || typeof input[field] !== "string"
304
+ || input[field].trim().length === 0)
305
+ return null;
306
+ return action === "contract.deliver"
307
+ ? { kind: input.kind, repoRoot: input.repoRoot, contractId: input.contractId, deliveryFactId: input.deliveryFactId }
308
+ : { kind: input.kind, repoRoot: input.repoRoot, contractId: input.contractId, reviewFactId: input.reviewFactId };
309
+ }
310
+ function decodeCallReceipt(value, id) {
311
+ if (value.state !== "served" || !exactKeys(value, ["action", "child", "id", "state"]))
312
+ return null;
313
+ const child = canonicalAkuId(value.child);
314
+ return child === null ? null : { id, action: "akuma.call", state: value.state, child };
315
+ }
316
+ function decodeContractReceipt(value, id, action) {
317
+ if (value.state !== "served" || !exactKeys(value, ["action", "id", "reference", "state"]))
318
+ return null;
319
+ const selected = reference(value.reference, action);
320
+ if (selected === null)
321
+ return null;
322
+ return action === "contract.deliver"
323
+ ? { id, action, state: value.state, reference: selected }
324
+ : { id, action, state: value.state, reference: selected };
325
+ }
326
+ function decodeTaskReceipt(value, id, action) {
327
+ if (value.state !== "served" || !exactKeys(value, ["action", "id", "reference", "state"]))
328
+ return null;
329
+ const selected = object(value.reference);
330
+ if (selected === null
331
+ || !exactKeys(selected, ["action", "kind"])
332
+ || selected.kind !== "served-reference"
333
+ || selected.action !== action)
334
+ return null;
335
+ return { id, action, state: value.state, reference: { kind: selected.kind, action } };
336
+ }
337
+ export function decodeReceipt(bytes, id, action) {
338
+ let decoded;
339
+ try {
340
+ decoded = JSON.parse(bytes);
341
+ }
342
+ catch {
343
+ return null;
344
+ }
345
+ const value = object(decoded);
346
+ if (value === null || value.id !== id || value.action !== action)
347
+ return null;
348
+ const shared = envelope(value, id, action);
349
+ if (shared !== null)
350
+ return shared;
351
+ if (action === "akuma.call")
352
+ return decodeCallReceipt(value, id);
353
+ if (action === "contract.deliver" || action === "contract.review")
354
+ return decodeContractReceipt(value, id, action);
355
+ if (isTaskMutationAction(action))
356
+ return decodeTaskReceipt(value, id, action);
357
+ return null;
358
+ }
359
+ export function requestPayload(claim) {
360
+ if (isTaskMutationAction(claim.action)) {
361
+ const task = claim;
362
+ const { action: _action, ...request } = task.request;
363
+ return { world: task.world, request };
364
+ }
365
+ const { id: _id, action: _action, ...payload } = claim;
366
+ return payload;
367
+ }
368
+ export function requestPath(directory, id) {
369
+ return join(directory, `${id}.request.json`);
370
+ }
371
+ export function receiptPath(directory, id) {
372
+ return join(directory, `${id}.receipt.json`);
373
+ }
374
+ export async function atomicJson(path, value) {
375
+ const temporary = `${path}.${randomUUID()}.tmp`;
376
+ try {
377
+ await writeFile(temporary, `${JSON.stringify(value)}\n`, { flag: "wx" });
378
+ await rename(temporary, path);
379
+ }
380
+ finally {
381
+ await rm(temporary, { force: true });
382
+ }
383
+ }
@@ -1,71 +1,6 @@
1
- import { type KillEvidence, type RequestRecipe, type Soul } from "./heart/index.js";
2
- import { type AkuId, type AkumaPaths } from "./identity.js";
3
- type RequestClaimRecipe = Omit<RequestRecipe, "confinement">;
4
- type CallRequestClaim = Readonly<{
5
- id: string;
6
- action: "akuma.call";
7
- world: string;
8
- archetype: string;
9
- body: string;
10
- cwd?: string;
11
- recipe: RequestClaimRecipe;
12
- }>;
13
- type WaitRequestClaim = Readonly<{
14
- id: string;
15
- action: "akuma.wait";
16
- targets: readonly AkuId[];
17
- completion: "any" | "all";
18
- timeoutMs?: number;
19
- }>;
20
- type TellRequestClaim = Readonly<{
21
- id: string;
22
- action: "akuma.tell";
23
- target: AkuId;
24
- body: string;
25
- }>;
26
- type KillRequestClaim = Readonly<{
27
- id: string;
28
- action: "akuma.kill";
29
- targets: readonly AkuId[];
30
- }>;
31
- type UpstreamRequestFailure = Readonly<{
32
- kind: "akuma-not-born";
33
- id: AkuId;
34
- }> | Readonly<{
35
- kind: "failed";
36
- diagnostic: string;
37
- }>;
38
- export type UpstreamRequestOutcome = Readonly<{
39
- kind: "returned";
40
- result: unknown;
41
- }> | Readonly<{
42
- kind: "failed";
43
- failure: UpstreamRequestFailure;
44
- }>;
45
- export type UpstreamExecutionPort = Readonly<{
46
- wait(input: Omit<WaitRequestClaim, "id" | "action"> & Readonly<{
47
- signal: AbortSignal;
48
- }>): Promise<unknown>;
49
- tell(input: Omit<TellRequestClaim, "id" | "action"> & Readonly<{
50
- tellId: string;
51
- recordedAt: string;
52
- signal: AbortSignal;
53
- }>): Promise<unknown>;
54
- kill(input: Omit<KillRequestClaim, "id" | "action"> & Readonly<{
55
- signal: AbortSignal;
56
- }>): Promise<Readonly<{
57
- result: unknown;
58
- service: readonly Readonly<{
59
- id: AkuId;
60
- evidence: KillEvidence;
61
- }>[];
62
- }>>;
63
- }>;
64
- export type RequestChildLaunch = Readonly<{
65
- paths: AkumaPaths;
66
- seed: Omit<Soul, "createdAt">;
67
- initialBody: string;
68
- }>;
1
+ import { type CallRequestClaim, type DeliverRequestClaim, type ForwardedDeliveryReference, type ForwardedReviewReference, type KillRequestClaim, type ReviewRequestClaim, type TellRequestClaim, type UpstreamRequestOutcome, type WaitRequestClaim } from "./request-wire.js";
2
+ import { type TaskMutationRequest } from "../task/mutation.js";
3
+ export type { UpstreamRequestOutcome } from "./request-wire.js";
69
4
  export declare class AkumaBodyRequestError extends Error {
70
5
  readonly outcome: "refused" | "voided";
71
6
  readonly diagnostic: string;
@@ -75,7 +10,13 @@ export declare class AkumaBodyRequestError extends Error {
75
10
  export declare function injectedBodyRequests(): string | null;
76
11
  export declare function requestBodyCall(input: Omit<CallRequestClaim, "action"> & Readonly<{
77
12
  directory: string;
78
- }>): Promise<AkuId>;
13
+ }>): Promise<import("./identity.js").AkuId>;
14
+ export declare function requestBodyTask(input: Readonly<{
15
+ directory: string;
16
+ world: string;
17
+ request: TaskMutationRequest;
18
+ id?: string;
19
+ }>): Promise<unknown>;
79
20
  export declare function requestBodyWait(input: Omit<WaitRequestClaim, "action" | "id"> & Readonly<{
80
21
  directory: string;
81
22
  id?: string;
@@ -88,28 +29,21 @@ export declare function requestBodyKill(input: Omit<KillRequestClaim, "action" |
88
29
  directory: string;
89
30
  id?: string;
90
31
  }>): Promise<UpstreamRequestOutcome>;
91
- export declare class BodyRequestPump {
92
- private readonly input;
93
- readonly directory: string;
94
- readonly failure: Promise<never>;
95
- private readonly closeSignal;
96
- private readonly handled;
97
- private readonly running;
98
- private readonly cancelAdmission;
99
- private constructor();
100
- static open(input: Readonly<{
101
- paths: AkumaPaths;
102
- parent: Soul;
103
- bodySequence: number;
104
- now(): string;
105
- spawn(launch: RequestChildLaunch): Promise<void>;
106
- upstream?: UpstreamExecutionPort;
107
- signal: AbortSignal;
108
- }>): Promise<BodyRequestPump>;
109
- private run;
110
- close(): Promise<void>;
111
- stopAdmission(): void;
112
- }
113
- export declare function clearBodyRequestTransport(paths: AkumaPaths): Promise<void>;
114
- export declare function settleBodyRequests(paths: AkumaPaths, parent: Soul, now: () => string, signal?: AbortSignal): Promise<"settled" | "pending">;
115
- export {};
32
+ type ContractRequestInput<T extends DeliverRequestClaim | ReviewRequestClaim> = Omit<T, "action" | "id"> & Readonly<{
33
+ directory: string;
34
+ signal?: AbortSignal;
35
+ }>;
36
+ type BodyDeliverInput = ContractRequestInput<DeliverRequestClaim>;
37
+ export declare function requestBodyDeliver(input: BodyDeliverInput & Readonly<{
38
+ id?: never;
39
+ }>): Promise<UpstreamRequestOutcome>;
40
+ export declare function requestBodyDeliver(input: BodyDeliverInput & Readonly<{
41
+ id: string;
42
+ }>): Promise<UpstreamRequestOutcome | ForwardedDeliveryReference>;
43
+ type BodyReviewInput = ContractRequestInput<ReviewRequestClaim>;
44
+ export declare function requestBodyReview(input: BodyReviewInput & Readonly<{
45
+ id?: never;
46
+ }>): Promise<UpstreamRequestOutcome>;
47
+ export declare function requestBodyReview(input: BodyReviewInput & Readonly<{
48
+ id: string;
49
+ }>): Promise<UpstreamRequestOutcome | ForwardedReviewReference>;