@astrosheep/keiyaku 4.1.0 → 4.1.2

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 (278) hide show
  1. package/README.md +1 -1
  2. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +3 -0
  3. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +3 -0
  4. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +3 -6
  5. package/build/src/akuma/akuma-errors.d.ts +6 -0
  6. package/build/src/akuma/akuma-errors.js +9 -0
  7. package/build/src/akuma/akuma-handle.d.ts +39 -0
  8. package/build/src/akuma/akuma-handle.js +263 -0
  9. package/build/src/akuma/akuma-observe.d.ts +19 -0
  10. package/build/src/akuma/akuma-observe.js +74 -0
  11. package/build/src/akuma/akuma-product-symbols.d.ts +1 -0
  12. package/build/src/akuma/akuma-product-symbols.js +1 -0
  13. package/build/src/akuma/akuma-product.d.ts +18 -0
  14. package/build/src/akuma/akuma-product.js +154 -0
  15. package/build/src/akuma/akuma.d.ts +37 -81
  16. package/build/src/akuma/akuma.js +39 -447
  17. package/build/src/akuma/allowed.d.ts +1 -0
  18. package/build/src/akuma/allowed.js +6 -0
  19. package/build/src/akuma/archetype.js +8 -5
  20. package/build/src/akuma/body-supervisor.d.ts +26 -0
  21. package/build/src/akuma/body-supervisor.js +89 -0
  22. package/build/src/akuma/body.d.ts +45 -4
  23. package/build/src/akuma/body.js +145 -35
  24. package/build/src/akuma/coordinate.js +17 -7
  25. package/build/src/akuma/heart/facts.js +1 -1
  26. package/build/src/akuma/heart/index.d.ts +1 -1
  27. package/build/src/akuma/heart/index.js +2 -4
  28. package/build/src/akuma/heart/request-authority.js +4 -4
  29. package/build/src/akuma/heart/request-rows.js +27 -16
  30. package/build/src/akuma/heart/rows.js +79 -41
  31. package/build/src/akuma/heart/soul.js +1 -1
  32. package/build/src/akuma/heart/storage.d.ts +1 -0
  33. package/build/src/akuma/heart/storage.js +76 -11
  34. package/build/src/akuma/heart/tells.js +35 -18
  35. package/build/src/akuma/heart/timeline.js +19 -11
  36. package/build/src/akuma/identity.d.ts +1 -0
  37. package/build/src/akuma/identity.js +1 -0
  38. package/build/src/akuma/index.d.ts +3 -3
  39. package/build/src/akuma/index.js +1 -1
  40. package/build/src/akuma/nuke.js +106 -14
  41. package/build/src/akuma/projection-read.d.ts +17 -0
  42. package/build/src/akuma/projection-read.js +135 -0
  43. package/build/src/akuma/projection.d.ts +1 -16
  44. package/build/src/akuma/projection.js +77 -154
  45. package/build/src/akuma/provider-recipe.js +11 -5
  46. package/build/src/akuma/provider.js +105 -62
  47. package/build/src/akuma/providers/acp/config.js +5 -6
  48. package/build/src/akuma/providers/acp/core.js +17 -10
  49. package/build/src/akuma/providers/acp/events.js +38 -29
  50. package/build/src/akuma/providers/acp/index.js +13 -9
  51. package/build/src/akuma/providers/claude/events.js +8 -12
  52. package/build/src/akuma/providers/claude/index.d.ts +1 -0
  53. package/build/src/akuma/providers/claude/index.js +55 -26
  54. package/build/src/akuma/providers/claude/input.js +6 -2
  55. package/build/src/akuma/providers/codex-app-server/events.js +61 -36
  56. package/build/src/akuma/providers/codex-app-server/index.js +25 -13
  57. package/build/src/akuma/providers/grok-build/index.js +22 -25
  58. package/build/src/akuma/providers/index.js +2 -18
  59. package/build/src/akuma/providers/opencode-sdk/events.js +32 -18
  60. package/build/src/akuma/providers/opencode-sdk/index.js +26 -17
  61. package/build/src/akuma/providers/opencode-sdk/session.js +21 -5
  62. package/build/src/akuma/providers/pi/events.js +26 -19
  63. package/build/src/akuma/providers/pi/index.js +58 -40
  64. package/build/src/akuma/publication.js +9 -9
  65. package/build/src/akuma/request-execution.d.ts +6 -0
  66. package/build/src/akuma/request-execution.js +86 -0
  67. package/build/src/akuma/request-serve.d.ts +12 -1
  68. package/build/src/akuma/request-serve.js +19 -122
  69. package/build/src/akuma/request-wire.d.ts +2 -2
  70. package/build/src/akuma/request-wire.js +75 -102
  71. package/build/src/akuma/requests.js +2 -2
  72. package/build/src/akuma/{body-turn.d.ts → turn-drive.d.ts} +2 -25
  73. package/build/src/akuma/{body-turn.js → turn-drive.js} +20 -103
  74. package/build/src/akuma-body.js +6 -5
  75. package/build/src/body/amend.d.ts +4 -1
  76. package/build/src/body/amend.js +14 -6
  77. package/build/src/body/decode.js +2 -4
  78. package/build/src/body/envelope.js +2 -4
  79. package/build/src/body/region.d.ts +1 -2
  80. package/build/src/body/region.js +2 -70
  81. package/build/src/body/render.js +17 -12
  82. package/build/src/body/shape.js +1 -7
  83. package/build/src/cli/accepted.d.ts +1 -1
  84. package/build/src/cli/accepted.js +8 -1
  85. package/build/src/cli/commands/akuma-invoke.js +18 -6
  86. package/build/src/cli/commands/akuma.d.ts +0 -6
  87. package/build/src/cli/commands/akuma.js +11 -24
  88. package/build/src/cli/commands/amend.d.ts +2 -2
  89. package/build/src/cli/commands/amend.js +2 -4
  90. package/build/src/cli/commands/bind.d.ts +4 -4
  91. package/build/src/cli/commands/bind.js +16 -6
  92. package/build/src/cli/commands/contract-invoke.d.ts +25 -0
  93. package/build/src/cli/commands/contract-invoke.js +193 -0
  94. package/build/src/cli/commands/contract.d.ts +109 -10
  95. package/build/src/cli/commands/contract.js +339 -16
  96. package/build/src/cli/commands/install.d.ts +1 -1
  97. package/build/src/cli/commands/install.js +23 -15
  98. package/build/src/cli/commands/task-invoke.js +187 -67
  99. package/build/src/cli/commands/task-query.js +48 -24
  100. package/build/src/cli/commands/task.js +150 -38
  101. package/build/src/cli/coordinates.js +2 -4
  102. package/build/src/cli/invoke.js +92 -208
  103. package/build/src/cli/main.js +4 -2
  104. package/build/src/cli/parse.d.ts +3 -90
  105. package/build/src/cli/parse.js +27 -233
  106. package/build/src/cli/render/akuma-activity.d.ts +38 -0
  107. package/build/src/cli/render/akuma-activity.js +362 -0
  108. package/build/src/cli/render/akuma-tool-command.js +6 -7
  109. package/build/src/cli/render/akuma-tool.js +10 -8
  110. package/build/src/cli/render/akuma.d.ts +1 -1
  111. package/build/src/cli/render/akuma.js +61 -353
  112. package/build/src/cli/render/audit.js +5 -15
  113. package/build/src/cli/render/board.d.ts +1 -0
  114. package/build/src/cli/render/board.js +17 -0
  115. package/build/src/cli/render/catalog.js +81 -8
  116. package/build/src/cli/render/contract-history.d.ts +2 -0
  117. package/build/src/cli/render/contract-history.js +83 -0
  118. package/build/src/cli/render/contract-observation.d.ts +10 -0
  119. package/build/src/cli/render/contract-observation.js +58 -0
  120. package/build/src/cli/render/contract.d.ts +1 -2
  121. package/build/src/cli/render/contract.js +41 -142
  122. package/build/src/cli/render/kanshi.js +239 -215
  123. package/build/src/cli/render/receipt.js +2 -9
  124. package/build/src/cli/render/refusal.js +10 -15
  125. package/build/src/cli/render/region.js +22 -6
  126. package/build/src/cli/render/settings.js +4 -4
  127. package/build/src/cli/render/task.js +34 -14
  128. package/build/src/cli/render/terminal.js +16 -5
  129. package/build/src/cli/result.d.ts +3 -3
  130. package/build/src/cli/runtime.d.ts +6 -1
  131. package/build/src/cli/runtime.js +84 -63
  132. package/build/src/cli/selectors.js +2 -4
  133. package/build/src/cli/usage.js +6 -5
  134. package/build/src/contract-worktree.d.ts +1 -23
  135. package/build/src/contract-worktree.js +79 -155
  136. package/build/src/coordination/durable-file.js +7 -3
  137. package/build/src/coordination/sqlite-transaction-lock.js +29 -12
  138. package/build/src/core/facts/codec.js +7 -3
  139. package/build/src/core/facts/types.d.ts +1 -1
  140. package/build/src/core/subject.js +16 -9
  141. package/build/src/core/verbs/abandon.d.ts +1 -1
  142. package/build/src/core/verbs/abandon.js +1 -1
  143. package/build/src/core/verbs/amend.d.ts +1 -1
  144. package/build/src/core/verbs/amend.js +7 -7
  145. package/build/src/core/verbs/attestation.js +4 -1
  146. package/build/src/core/verbs/bind.d.ts +1 -1
  147. package/build/src/core/verbs/bind.js +1 -1
  148. package/build/src/core/verbs/placement.d.ts +1 -1
  149. package/build/src/core/verbs/placement.js +10 -8
  150. package/build/src/dispatch/index.js +8 -6
  151. package/build/src/duration.js +5 -1
  152. package/build/src/git/admission.js +5 -3
  153. package/build/src/git/hooks.d.ts +8 -0
  154. package/build/src/git/hooks.js +63 -14
  155. package/build/src/git/identity.js +1 -4
  156. package/build/src/git/integration.d.ts +2 -3
  157. package/build/src/git/integration.js +32 -39
  158. package/build/src/git/nuke.d.ts +1 -1
  159. package/build/src/git/nuke.js +110 -57
  160. package/build/src/git/observe.d.ts +13 -1
  161. package/build/src/git/observe.js +51 -44
  162. package/build/src/git/process.js +4 -2
  163. package/build/src/git/read-observation.js +10 -8
  164. package/build/src/git/reconcile.d.ts +22 -2
  165. package/build/src/git/reconcile.js +38 -274
  166. package/build/src/git/repository.d.ts +2 -0
  167. package/build/src/git/repository.js +13 -22
  168. package/build/src/git/scratch.d.ts +8 -5
  169. package/build/src/git/scratch.js +29 -2
  170. package/build/src/git/target-placement.d.ts +9 -10
  171. package/build/src/git/target-placement.js +59 -62
  172. package/build/src/git/tender.js +13 -46
  173. package/build/src/git/terminal-reconcile.d.ts +21 -0
  174. package/build/src/git/terminal-reconcile.js +278 -0
  175. package/build/src/git/terminal-seal.js +15 -12
  176. package/build/src/git/tree.js +5 -2
  177. package/build/src/git/workspace.d.ts +24 -2
  178. package/build/src/git/workspace.js +120 -16
  179. package/build/src/identity/coordinates.js +3 -1
  180. package/build/src/identity/selector.js +6 -3
  181. package/build/src/kanshi/fleet.d.ts +6 -0
  182. package/build/src/kanshi/fleet.js +27 -0
  183. package/build/src/kanshi/index.d.ts +1 -1
  184. package/build/src/kanshi/read.js +60 -48
  185. package/build/src/kanshi/report.d.ts +11 -23
  186. package/build/src/kanshi/select.js +25 -24
  187. package/build/src/library/address.d.ts +2 -1
  188. package/build/src/library/address.js +7 -8
  189. package/build/src/library/akuma-creation.js +20 -12
  190. package/build/src/library/audit.d.ts +0 -1
  191. package/build/src/library/audit.js +1 -2
  192. package/build/src/library/bind.d.ts +53 -5
  193. package/build/src/library/bind.js +98 -22
  194. package/build/src/library/catalog.d.ts +1 -0
  195. package/build/src/library/catalog.js +6 -3
  196. package/build/src/library/configuration.js +3 -1
  197. package/build/src/library/continuation.d.ts +15 -4
  198. package/build/src/library/continuation.js +24 -16
  199. package/build/src/library/contract-bind.d.ts +26 -0
  200. package/build/src/library/contract-bind.js +106 -0
  201. package/build/src/library/contract-operations.d.ts +77 -0
  202. package/build/src/library/contract-operations.js +130 -0
  203. package/build/src/library/contract-types.d.ts +95 -0
  204. package/build/src/library/contract-types.js +1 -0
  205. package/build/src/library/contract.d.ts +19 -154
  206. package/build/src/library/contract.js +46 -261
  207. package/build/src/library/fleet.d.ts +1 -1
  208. package/build/src/library/fleet.js +19 -11
  209. package/build/src/library/input.d.ts +2 -0
  210. package/build/src/library/input.js +14 -0
  211. package/build/src/library/keiyaku.d.ts +8 -7
  212. package/build/src/library/keiyaku.js +3 -3
  213. package/build/src/library/nuke.js +14 -5
  214. package/build/src/library/reconcile.d.ts +9 -4
  215. package/build/src/library/reconcile.js +30 -24
  216. package/build/src/library/refusal.d.ts +13 -5
  217. package/build/src/library/refusal.js +7 -0
  218. package/build/src/library/region.d.ts +8 -7
  219. package/build/src/library/region.js +31 -11
  220. package/build/src/library/repo.js +2 -2
  221. package/build/src/markdown/lex.js +9 -2
  222. package/build/src/markdown/parse.js +11 -7
  223. package/build/src/markdown/query.js +4 -2
  224. package/build/src/protocol/amend.js +3 -1
  225. package/build/src/protocol/attempt.d.ts +7 -3
  226. package/build/src/protocol/attempt.js +9 -5
  227. package/build/src/protocol/audit.d.ts +1 -1
  228. package/build/src/protocol/audit.js +4 -14
  229. package/build/src/protocol/bind.d.ts +19 -6
  230. package/build/src/protocol/bind.js +28 -13
  231. package/build/src/protocol/completion.d.ts +0 -1
  232. package/build/src/protocol/completion.js +1 -3
  233. package/build/src/protocol/deliver.d.ts +1 -3
  234. package/build/src/protocol/deliver.js +15 -39
  235. package/build/src/protocol/intent.d.ts +1 -0
  236. package/build/src/protocol/intent.js +9 -7
  237. package/build/src/protocol/operations.d.ts +3 -7
  238. package/build/src/protocol/operations.js +5 -3
  239. package/build/src/protocol/placement.d.ts +0 -1
  240. package/build/src/protocol/placement.js +6 -6
  241. package/build/src/protocol/read/observation.d.ts +11 -0
  242. package/build/src/protocol/read/observation.js +37 -0
  243. package/build/src/protocol/read/status.d.ts +23 -12
  244. package/build/src/protocol/read/status.js +90 -72
  245. package/build/src/protocol/reconcile.d.ts +1 -0
  246. package/build/src/protocol/reconcile.js +2 -3
  247. package/build/src/protocol/reintegrate.js +1 -1
  248. package/build/src/protocol/review.d.ts +0 -1
  249. package/build/src/protocol/review.js +15 -22
  250. package/build/src/protocol/run.d.ts +1 -0
  251. package/build/src/protocol/run.js +4 -5
  252. package/build/src/runtime/proc/launch.d.ts +33 -0
  253. package/build/src/runtime/proc/launch.js +98 -0
  254. package/build/src/runtime/proc/line-rpc.js +9 -3
  255. package/build/src/runtime/proc/run.d.ts +12 -6
  256. package/build/src/runtime/proc/run.js +78 -21
  257. package/build/src/runtime/proc/stdio.js +7 -10
  258. package/build/src/settings.js +6 -2
  259. package/build/src/settlement/holder.js +13 -10
  260. package/build/src/settlement/settle.js +39 -6
  261. package/build/src/task/board.js +12 -6
  262. package/build/src/task/compose.js +85 -22
  263. package/build/src/task/context.js +21 -8
  264. package/build/src/task/document.js +46 -10
  265. package/build/src/task/identity.js +5 -2
  266. package/build/src/task/index.d.ts +0 -1
  267. package/build/src/task/index.js +119 -34
  268. package/build/src/task/input.js +29 -7
  269. package/build/src/task/mutation.js +61 -19
  270. package/build/src/task/operations.d.ts +6 -1
  271. package/build/src/task/operations.js +83 -29
  272. package/build/src/task/query.js +55 -26
  273. package/build/src/task/store.d.ts +3 -1
  274. package/build/src/task/store.js +81 -17
  275. package/build/src/verification/execution.js +14 -11
  276. package/build/src/workspace-place.js +19 -7
  277. package/build/src/world.js +16 -6
  278. package/package.json +8 -3
@@ -2,11 +2,12 @@ import { access, mkdir, readFile, readdir, rm } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { abortableDelay } from "./abort.js";
4
4
  import { HeldAkumaLeash, admitRequest, readNonterminalRequests, readRequest, readSoul, refuseRequest, reserveRequest, serveRequest, serveUpstreamRequest, voidRequest, } from "./heart/index.js";
5
- import { pathsForAkuId, worldRootForAkumaPaths, } from "./identity.js";
5
+ import { pathsForAkuId, worldRootForAkumaPaths } from "./identity.js";
6
6
  import { BIRTH_TIMEOUT_MS, publishAkuma } from "./publication.js";
7
7
  import { atomicJson, canonicalAkuId, decodeClaim, decodeRecipe, receiptPath, } from "./request-wire.js";
8
8
  import { isTaskMutationAction } from "../task/mutation.js";
9
- const POLL_MS = 25;
9
+ import { executeRequest } from "./request-execution.js";
10
+ const POLL_MS = 100;
10
11
  function diagnostic(error) {
11
12
  return error instanceof Error ? error.message : String(error);
12
13
  }
@@ -123,14 +124,10 @@ async function serveCall(input) {
123
124
  seed: {
124
125
  id: allocated.id,
125
126
  archetype: allocated.archetype,
126
- ...(request.recipe.description === undefined
127
- ? {}
128
- : { description: request.recipe.description }),
127
+ ...(request.recipe.description === undefined ? {} : { description: request.recipe.description }),
129
128
  provider: request.recipe.provider,
130
129
  options: request.recipe.options,
131
- ...(request.recipe.readonly === undefined
132
- ? {}
133
- : { readonly: request.recipe.readonly }),
130
+ ...(request.recipe.readonly === undefined ? {} : { readonly: request.recipe.readonly }),
134
131
  allowed: request.recipe.allowed,
135
132
  cwd: request.cwd ?? input.parent.cwd,
136
133
  origin: {
@@ -149,9 +146,10 @@ async function serveCall(input) {
149
146
  const current = await readRequest(input.paths, request.id);
150
147
  if (current === null)
151
148
  throw error;
152
- fact = current.state === "admitted" || current.state === "reserved"
153
- ? await voidRequest(input.paths, request.id, diagnostic(error))
154
- : current;
149
+ fact =
150
+ current.state === "admitted" || current.state === "reserved"
151
+ ? await voidRequest(input.paths, request.id, diagnostic(error))
152
+ : current;
155
153
  }
156
154
  await projectReceipt(input.directory, fact);
157
155
  }
@@ -164,103 +162,6 @@ function failure(error) {
164
162
  }
165
163
  return { kind: "failed", diagnostic: diagnostic(error) };
166
164
  }
167
- async function execute(input, request) {
168
- if (input.upstream === undefined)
169
- throw new Error("upstream execution port is unavailable");
170
- if (request.action === "akuma.wait") {
171
- const result = await input.upstream.wait({
172
- targets: request.targets,
173
- completion: request.completion,
174
- ...(request.timeoutMs === undefined ? {} : { timeoutMs: request.timeoutMs }),
175
- signal: input.signal,
176
- });
177
- return { result, service: { action: request.action } };
178
- }
179
- if (request.action === "akuma.tell") {
180
- const result = await input.upstream.tell({
181
- target: request.target,
182
- body: request.body,
183
- tellId: request.id,
184
- recordedAt: request.admittedAt,
185
- signal: input.signal,
186
- });
187
- return {
188
- result,
189
- service: { action: request.action, target: request.target, tellId: request.id },
190
- };
191
- }
192
- if (request.action === "akuma.kill") {
193
- const served = await input.upstream.kill({
194
- targets: request.targets,
195
- signal: input.signal,
196
- });
197
- return {
198
- result: served.result,
199
- service: { action: request.action, results: served.service },
200
- };
201
- }
202
- if (request.action === "contract.deliver") {
203
- return await executeDeliver(input, request);
204
- }
205
- if (request.action === "contract.review") {
206
- return await executeReview(input, request);
207
- }
208
- const task = request;
209
- const result = await input.upstream.task({
210
- world: task.world,
211
- request: task.request,
212
- requester: task.requester,
213
- signal: input.signal,
214
- });
215
- return { result, service: { action: task.action } };
216
- }
217
- async function executeDeliver(input, request) {
218
- if (input.upstream === undefined)
219
- throw new Error("upstream execution port is unavailable");
220
- const served = await input.upstream.deliver({
221
- repoRoot: request.repoRoot,
222
- contractId: request.contractId,
223
- ...(request.message === undefined ? {} : { message: request.message }),
224
- includeDirty: request.includeDirty,
225
- materializeConflict: request.materializeConflict,
226
- requester: request.requester,
227
- signal: input.signal,
228
- });
229
- return {
230
- result: served.result,
231
- ...(served.deliveryFactId === undefined ? {} : {
232
- service: {
233
- action: request.action,
234
- repoRoot: request.repoRoot,
235
- contractId: request.contractId,
236
- deliveryFactId: served.deliveryFactId,
237
- },
238
- }),
239
- };
240
- }
241
- async function executeReview(input, request) {
242
- if (input.upstream === undefined)
243
- throw new Error("upstream execution port is unavailable");
244
- const served = await input.upstream.review({
245
- repoRoot: request.repoRoot,
246
- contractId: request.contractId,
247
- verdict: request.verdict,
248
- ...(request.summary === undefined ? {} : { summary: request.summary }),
249
- requester: request.requester,
250
- signal: input.signal,
251
- });
252
- return {
253
- result: served.result,
254
- ...(served.reviewFactId === undefined ? {} : {
255
- service: {
256
- action: request.action,
257
- repoRoot: request.repoRoot,
258
- contractId: request.contractId,
259
- reviewFactId: served.reviewFactId,
260
- },
261
- }),
262
- };
263
- }
264
165
  function pendingService(request) {
265
166
  if (request.action === "akuma.wait")
266
167
  return { action: request.action };
@@ -302,7 +203,7 @@ async function serveUpstream(input) {
302
203
  let outcome;
303
204
  let service = pendingService(request);
304
205
  try {
305
- const served = await execute(input, request);
206
+ const served = await executeRequest(input, request);
306
207
  outcome = { kind: "returned", result: served.result };
307
208
  if (served.service !== undefined)
308
209
  service = served.service;
@@ -313,9 +214,10 @@ async function serveUpstream(input) {
313
214
  await projectReceipt(input.directory, fact);
314
215
  return;
315
216
  }
316
- fact = service === undefined
317
- ? await voidRequest(input.paths, request.id, "body completed without a durable Contract fact reference")
318
- : await serveUpstreamRequest(input.paths, request.id, service);
217
+ fact =
218
+ service === undefined
219
+ ? await voidRequest(input.paths, request.id, "body completed without a durable Contract fact reference")
220
+ : await serveUpstreamRequest(input.paths, request.id, service);
319
221
  await projectReceipt(input.directory, fact, outcome);
320
222
  }
321
223
  async function serve(input) {
@@ -325,9 +227,7 @@ async function serve(input) {
325
227
  }
326
228
  async function requestFiles(directory) {
327
229
  try {
328
- return (await readdir(directory))
329
- .filter((name) => name.endsWith(".request.json"))
330
- .sort();
230
+ return (await readdir(directory)).filter((name) => name.endsWith(".request.json")).sort();
331
231
  }
332
232
  catch (error) {
333
233
  if (error.code === "ENOENT")
@@ -421,9 +321,7 @@ export async function clearBodyRequestTransport(paths) {
421
321
  await rm(join(paths.directory, "requests"), { recursive: true, force: true });
422
322
  }
423
323
  function matchingRequestOrigin(soul, parent, id) {
424
- return soul.origin.kind === "request"
425
- && soul.origin.parent === parent
426
- && soul.origin.requestId === id;
324
+ return soul.origin.kind === "request" && soul.origin.parent === parent && soul.origin.requestId === id;
427
325
  }
428
326
  async function settleReservedSoul(paths, parent, request, soul) {
429
327
  await (matchingRequestOrigin(soul, parent.id, request.id)
@@ -435,7 +333,7 @@ async function settleReserved(paths, parent, request, now, signal) {
435
333
  const deadline = performance.now() + BIRTH_TIMEOUT_MS;
436
334
  for (;;) {
437
335
  signal?.throwIfAborted();
438
- if (!await access(childPaths.directory).then(() => true, () => false)) {
336
+ if (!(await access(childPaths.directory).then(() => true, () => false))) {
439
337
  await voidRequest(paths, request.id, "reserved child directory is absent");
440
338
  return true;
441
339
  }
@@ -466,7 +364,7 @@ async function settleReserved(paths, parent, request, now, signal) {
466
364
  }
467
365
  if (performance.now() >= deadline)
468
366
  return false;
469
- await abortableDelay(POLL_MS, signal);
367
+ await abortableDelay(Math.min(POLL_MS, Math.max(0, deadline - performance.now())), signal);
470
368
  }
471
369
  }
472
370
  export async function settleBodyRequests(paths, parent, now, signal) {
@@ -476,8 +374,7 @@ export async function settleBodyRequests(paths, parent, now, signal) {
476
374
  if (request.state === "admitted") {
477
375
  await voidRequest(paths, request.id, "body died before serving the request");
478
376
  }
479
- else if (request.state === "reserved"
480
- && !await settleReserved(paths, parent, request, now, signal))
377
+ else if (request.state === "reserved" && !(await settleReserved(paths, parent, request, now, signal)))
481
378
  pending = true;
482
379
  }
483
380
  return pending ? "pending" : "settled";
@@ -60,9 +60,9 @@ export type TaskRequestClaim = Readonly<{
60
60
  request: TaskMutationRequest;
61
61
  }>;
62
62
  export type RequestClaim = CallRequestClaim | WaitRequestClaim | TellRequestClaim | KillRequestClaim | DeliverRequestClaim | ReviewRequestClaim | TaskRequestClaim;
63
- export type StructuralRequestClaim = Omit<CallRequestClaim, "recipe"> & Readonly<{
63
+ export type StructuralRequestClaim = (Omit<CallRequestClaim, "recipe"> & Readonly<{
64
64
  recipe: unknown;
65
- }> | Exclude<RequestClaim, CallRequestClaim>;
65
+ }>) | Exclude<RequestClaim, CallRequestClaim>;
66
66
  export type UpstreamRequestFailure = Readonly<{
67
67
  kind: "akuma-not-born";
68
68
  id: AkuId;
@@ -3,7 +3,7 @@ import { rename, rm, writeFile } from "node:fs/promises";
3
3
  import { isAbsolute, join, resolve } from "node:path";
4
4
  import { decodeAllowedActions } from "./allowed.js";
5
5
  import { archetypeName, parseAkuId } from "./identity.js";
6
- import { decodeProviderOptions, decodeReadonlyRestraint, } from "./provider-recipe.js";
6
+ import { decodeProviderOptions, decodeReadonlyRestraint } from "./provider-recipe.js";
7
7
  import { decodeProviderExecution } from "./providers/index.js";
8
8
  import { decodeTaskMutationRequest, isTaskMutationAction, } from "../task/mutation.js";
9
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;
@@ -37,9 +37,7 @@ function canonicalTargets(value) {
37
37
  const ids = [];
38
38
  for (const item of value) {
39
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))
40
+ if (id === null || (ids.length > 0 && Buffer.compare(Buffer.from(ids.at(-1)), Buffer.from(id)) >= 0))
43
41
  return null;
44
42
  ids.push(id);
45
43
  }
@@ -56,10 +54,9 @@ export function decodeRecipe(value) {
56
54
  ...(recipe.description === undefined ? [] : ["description"]),
57
55
  ...(recipe.readonly === undefined ? [] : ["readonly"]),
58
56
  ];
59
- if (!exactKeys(recipe, expected)
60
- || (recipe.description !== undefined
61
- && (typeof recipe.description !== "string"
62
- || recipe.description.trim().length === 0)))
57
+ if (!exactKeys(recipe, expected) ||
58
+ (recipe.description !== undefined &&
59
+ (typeof recipe.description !== "string" || recipe.description.trim().length === 0)))
63
60
  return null;
64
61
  try {
65
62
  const options = decodeProviderOptions(recipe.options);
@@ -82,17 +79,11 @@ function contractId(value) {
82
79
  return typeof value === "string" && /^kei\/[^/\s]+$/u.test(value) ? value : null;
83
80
  }
84
81
  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)))
82
+ const expected = ["archetype", "body", "recipe", "world", ...(payload.cwd === undefined ? [] : ["cwd"])];
83
+ if (!exactKeys(payload, expected) ||
84
+ typeof payload.body !== "string" ||
85
+ !absolute(payload.world) ||
86
+ (payload.cwd !== undefined && !absolute(payload.cwd)))
96
87
  return null;
97
88
  try {
98
89
  archetypeName(payload.archetype);
@@ -112,42 +103,29 @@ function decodeCall(id, payload) {
112
103
  }
113
104
  function decodeWait(id, payload) {
114
105
  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)))
106
+ const expected = ["completion", "targets", ...(payload.timeoutMs === undefined ? [] : ["timeoutMs"])];
107
+ if (!exactKeys(payload, expected) ||
108
+ targets === null ||
109
+ (payload.completion !== "any" && payload.completion !== "all") ||
110
+ (payload.timeoutMs !== undefined && (!Number.isSafeInteger(payload.timeoutMs) || payload.timeoutMs < 0)))
126
111
  return null;
127
112
  return {
128
113
  id,
129
114
  action: "akuma.wait",
130
115
  targets,
131
116
  completion: payload.completion,
132
- ...(payload.timeoutMs === undefined
133
- ? {}
134
- : { timeoutMs: payload.timeoutMs }),
117
+ ...(payload.timeoutMs === undefined ? {} : { timeoutMs: payload.timeoutMs }),
135
118
  };
136
119
  }
137
120
  function decodeTell(id, payload) {
138
121
  const target = canonicalAkuId(payload.target);
139
- return exactKeys(payload, ["body", "target"])
140
- && target !== null
141
- && typeof payload.body === "string"
122
+ return exactKeys(payload, ["body", "target"]) && target !== null && typeof payload.body === "string"
142
123
  ? { id, action: "akuma.tell", target, body: payload.body }
143
124
  : null;
144
125
  }
145
126
  function decodeKill(id, payload) {
146
127
  const targets = canonicalTargets(payload.targets);
147
- return exactKeys(payload, ["targets"])
148
- && targets !== null
149
- ? { id, action: "akuma.kill", targets }
150
- : null;
128
+ return exactKeys(payload, ["targets"]) && targets !== null ? { id, action: "akuma.kill", targets } : null;
151
129
  }
152
130
  function decodeDeliver(id, payload) {
153
131
  const valid = exactKeys(payload, [
@@ -158,14 +136,12 @@ function decodeDeliver(id, payload) {
158
136
  ...(payload.message === undefined ? [] : ["message"]),
159
137
  ]);
160
138
  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))
139
+ return valid &&
140
+ selected !== null &&
141
+ absolute(payload.repoRoot) &&
142
+ typeof payload.includeDirty === "boolean" &&
143
+ typeof payload.materializeConflict === "boolean" &&
144
+ (payload.message === undefined || (typeof payload.message === "string" && payload.message.trim().length > 0))
169
145
  ? {
170
146
  id,
171
147
  action: "contract.deliver",
@@ -173,9 +149,7 @@ function decodeDeliver(id, payload) {
173
149
  contractId: selected,
174
150
  includeDirty: payload.includeDirty,
175
151
  materializeConflict: payload.materializeConflict,
176
- ...(payload.message === undefined
177
- ? {}
178
- : { message: payload.message }),
152
+ ...(payload.message === undefined ? {} : { message: payload.message }),
179
153
  }
180
154
  : null;
181
155
  }
@@ -187,29 +161,23 @@ function decodeReview(id, payload) {
187
161
  ...(payload.summary === undefined ? [] : ["summary"]),
188
162
  ]);
189
163
  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))
164
+ return valid &&
165
+ selected !== null &&
166
+ absolute(payload.repoRoot) &&
167
+ (payload.verdict === "satisfied" || payload.verdict === "unsatisfied") &&
168
+ (payload.summary === undefined || (typeof payload.summary === "string" && payload.summary.trim().length > 0))
197
169
  ? {
198
170
  id,
199
171
  action: "contract.review",
200
172
  repoRoot: payload.repoRoot,
201
173
  contractId: selected,
202
174
  verdict: payload.verdict,
203
- ...(payload.summary === undefined
204
- ? {}
205
- : { summary: payload.summary }),
175
+ ...(payload.summary === undefined ? {} : { summary: payload.summary }),
206
176
  }
207
177
  : null;
208
178
  }
209
179
  function decodeTask(id, action, payload) {
210
- if (!isTaskMutationAction(action)
211
- || !exactKeys(payload, ["request", "world"])
212
- || !absolute(payload.world))
180
+ if (!isTaskMutationAction(action) || !exactKeys(payload, ["request", "world"]) || !absolute(payload.world))
213
181
  return null;
214
182
  try {
215
183
  return {
@@ -240,11 +208,11 @@ export function decodeClaim(bytes, fileId) {
240
208
  return null;
241
209
  }
242
210
  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))
211
+ if (value === null ||
212
+ !exactKeys(value, ["action", "id", "payload"]) ||
213
+ value.id !== fileId ||
214
+ typeof value.id !== "string" ||
215
+ !UUID.test(value.id))
248
216
  return null;
249
217
  const payload = object(value.payload);
250
218
  if (payload === null || typeof value.action !== "string")
@@ -258,54 +226,59 @@ function outcome(value) {
258
226
  return { kind: input.kind, result: input.result };
259
227
  }
260
228
  const failure = object(input?.failure);
261
- if (input?.kind !== "failed"
262
- || !exactKeys(input, ["failure", "kind"])
263
- || failure === null)
229
+ if (input?.kind !== "failed" || !exactKeys(input, ["failure", "kind"]) || failure === null)
264
230
  return null;
265
231
  if (failure.kind === "akuma-not-born" && exactKeys(failure, ["id", "kind"])) {
266
232
  const id = canonicalAkuId(failure.id);
267
- return id === null
268
- ? null
269
- : { kind: input.kind, failure: { kind: failure.kind, id } };
233
+ return id === null ? null : { kind: input.kind, failure: { kind: failure.kind, id } };
270
234
  }
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;
235
+ return failure.kind === "failed" &&
236
+ exactKeys(failure, ["diagnostic", "kind"]) &&
237
+ typeof failure.diagnostic === "string"
238
+ ? { kind: input.kind, failure: { kind: failure.kind, diagnostic: failure.diagnostic } }
239
+ : null;
273
240
  }
274
241
  function envelope(value, id, action) {
275
- if (value.state === "refused"
276
- && exactKeys(value, ["action", "diagnostic", "id", "state"])
277
- && typeof value.diagnostic === "string") {
242
+ if (value.state === "refused" &&
243
+ exactKeys(value, ["action", "diagnostic", "id", "state"]) &&
244
+ typeof value.diagnostic === "string") {
278
245
  return { id, action, state: value.state, diagnostic: value.diagnostic };
279
246
  }
280
- if (value.state === "voided"
281
- && exactKeys(value, ["action", "evidence", "id", "state"])
282
- && typeof value.evidence === "string") {
247
+ if (value.state === "voided" &&
248
+ exactKeys(value, ["action", "evidence", "id", "state"]) &&
249
+ typeof value.evidence === "string") {
283
250
  return { id, action, state: value.state, evidence: value.evidence };
284
251
  }
285
- if (action !== "akuma.call"
286
- && value.state === "served"
287
- && exactKeys(value, ["action", "id", "outcome", "state"])) {
252
+ if (action !== "akuma.call" && value.state === "served" && exactKeys(value, ["action", "id", "outcome", "state"])) {
288
253
  const decoded = outcome(value.outcome);
289
- return decoded === null
290
- ? null
291
- : { id, action, state: value.state, outcome: decoded };
254
+ return decoded === null ? null : { id, action, state: value.state, outcome: decoded };
292
255
  }
293
256
  return null;
294
257
  }
295
258
  function reference(value, action) {
296
259
  const input = object(value);
297
260
  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)
261
+ if (input === null ||
262
+ !exactKeys(input, ["contractId", field, "kind", "repoRoot"]) ||
263
+ input.kind !== "accepted-reference" ||
264
+ !absolute(input.repoRoot) ||
265
+ contractId(input.contractId) === null ||
266
+ typeof input[field] !== "string" ||
267
+ input[field].trim().length === 0)
305
268
  return null;
306
269
  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 };
270
+ ? {
271
+ kind: input.kind,
272
+ repoRoot: input.repoRoot,
273
+ contractId: input.contractId,
274
+ deliveryFactId: input.deliveryFactId,
275
+ }
276
+ : {
277
+ kind: input.kind,
278
+ repoRoot: input.repoRoot,
279
+ contractId: input.contractId,
280
+ reviewFactId: input.reviewFactId,
281
+ };
309
282
  }
310
283
  function decodeCallReceipt(value, id) {
311
284
  if (value.state !== "served" || !exactKeys(value, ["action", "child", "id", "state"]))
@@ -327,10 +300,10 @@ function decodeTaskReceipt(value, id, action) {
327
300
  if (value.state !== "served" || !exactKeys(value, ["action", "id", "reference", "state"]))
328
301
  return null;
329
302
  const selected = object(value.reference);
330
- if (selected === null
331
- || !exactKeys(selected, ["action", "kind"])
332
- || selected.kind !== "served-reference"
333
- || selected.action !== action)
303
+ if (selected === null ||
304
+ !exactKeys(selected, ["action", "kind"]) ||
305
+ selected.kind !== "served-reference" ||
306
+ selected.action !== action)
334
307
  return null;
335
308
  return { id, action, state: value.state, reference: { kind: selected.kind, action } };
336
309
  }
@@ -4,7 +4,7 @@ import { abortableDelay } from "./abort.js";
4
4
  import { AKUMA_REQUESTS_ENV } from "./provider.js";
5
5
  import { absolute, atomicJson, decodeReceipt, receiptPath, requestPath, requestPayload, } from "./request-wire.js";
6
6
  import { isTaskMutationAction } from "../task/mutation.js";
7
- const POLL_MS = 25;
7
+ const POLL_MS = 100;
8
8
  export class AkumaBodyRequestError extends Error {
9
9
  outcome;
10
10
  diagnostic;
@@ -47,7 +47,7 @@ async function requestBody(input) {
47
47
  if (error.code !== "ENOENT")
48
48
  throw error;
49
49
  }
50
- if (!await access(input.directory).then(() => true, () => false)) {
50
+ if (!(await access(input.directory).then(() => true, () => false))) {
51
51
  throw new AkumaBodyRequestError("voided", "parent request channel closed before a receipt");
52
52
  }
53
53
  await abortableDelay(POLL_MS, input.signal);
@@ -1,31 +1,8 @@
1
- import { type HeartSnapshot, type HeldAkumaLeash, type ResumeCoordinate, type Soul, type TellFact } from "./heart/index.js";
1
+ import { type ResumeCoordinate, type Soul, type TellFact } from "./heart/index.js";
2
2
  import type { AkumaPaths } from "./identity.js";
3
3
  import { type ProviderAdapter, type TurnResult } from "./provider.js";
4
4
  import { type RequestChildLaunch, type UpstreamExecutionPort } from "./request-serve.js";
5
- export declare const CONTROL_RESPONSE_MS = 1000;
6
- export declare class BodySupervisor {
7
- private readonly paths;
8
- private readonly bodySequence;
9
- private readonly leash;
10
- readonly signal: AbortSignal;
11
- private readonly controller;
12
- private readonly finished;
13
- private readonly observer;
14
- private waiter;
15
- private observation;
16
- private stopping?;
17
- private constructor();
18
- static open(paths: AkumaPaths, bodySequence: number, leash: HeldAkumaLeash): Promise<BodySupervisor>;
19
- get reason(): "control" | "heart-gone" | undefined;
20
- current(): HeartSnapshot;
21
- recordHung(diagnostic: string, at: string): Promise<void>;
22
- refresh(): Promise<HeartSnapshot>;
23
- next(after: HeartSnapshot): Promise<HeartSnapshot>;
24
- cancel(reason: "control" | "heart-gone"): void;
25
- close(): Promise<void>;
26
- private publish;
27
- private observe;
28
- }
5
+ import { BodySupervisor } from "./body-supervisor.js";
29
6
  export declare function turnRecipe(paths: AkumaPaths, soul: Soul): Promise<Readonly<{
30
7
  cwd: string;
31
8
  options: Soul["options"];