@astrosheep/keiyaku 4.5.6 → 4.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/README.md +10 -0
  2. package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +1 -1
  3. package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +1 -1
  4. package/build/integrations/marketplace/plugins/keiyaku/opencode.js +3 -2
  5. package/build/integrations/marketplace/plugins/keiyaku/package.json +1 -1
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +10 -8
  7. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +22 -1
  8. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-babysit/SKILL.md +53 -0
  9. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +28 -49
  10. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-task/SKILL.md +21 -15
  11. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +148 -89
  12. package/build/src/akuma/abort.d.ts +2 -1
  13. package/build/src/akuma/abort.js +6 -23
  14. package/build/src/akuma/akuma-handle.js +4 -2
  15. package/build/src/akuma/akuma-observe.d.ts +2 -0
  16. package/build/src/akuma/akuma-observe.js +1 -0
  17. package/build/src/akuma/akuma-product.js +9 -7
  18. package/build/src/akuma/akuma.d.ts +372 -9
  19. package/build/src/akuma/akuma.js +31 -1
  20. package/build/src/akuma/allowed.d.ts +1 -1
  21. package/build/src/akuma/allowed.js +1 -0
  22. package/build/src/akuma/body.d.ts +7 -5
  23. package/build/src/akuma/body.js +25 -36
  24. package/build/src/akuma/call-request.d.ts +80 -0
  25. package/build/src/akuma/call-request.js +211 -0
  26. package/build/src/akuma/heart/facts.d.ts +6 -78
  27. package/build/src/akuma/heart/index.d.ts +3 -3
  28. package/build/src/akuma/heart/index.js +2 -2
  29. package/build/src/akuma/heart/request-authority.d.ts +6 -4
  30. package/build/src/akuma/heart/request-authority.js +31 -35
  31. package/build/src/akuma/heart/request-rows.js +12 -23
  32. package/build/src/akuma/heart/schema.d.ts +1 -1
  33. package/build/src/akuma/heart/schema.js +5 -13
  34. package/build/src/akuma/heart/storage.d.ts +0 -1
  35. package/build/src/akuma/heart/storage.js +0 -54
  36. package/build/src/akuma/index.d.ts +1 -1
  37. package/build/src/akuma/index.js +1 -1
  38. package/build/src/akuma/projection-read.d.ts +1 -0
  39. package/build/src/akuma/projection-read.js +8 -1
  40. package/build/src/akuma/projection.d.ts +856 -137
  41. package/build/src/akuma/projection.js +190 -0
  42. package/build/src/akuma/provider.d.ts +30 -3
  43. package/build/src/akuma/provider.js +104 -0
  44. package/build/src/akuma/providers/acp/core.d.ts +2 -2
  45. package/build/src/akuma/providers/acp/core.js +13 -6
  46. package/build/src/akuma/providers/acp/index.js +5 -4
  47. package/build/src/akuma/providers/claude/index.d.ts +3 -3
  48. package/build/src/akuma/providers/claude/index.js +16 -5
  49. package/build/src/akuma/providers/codex-app-server/events.js +1 -1
  50. package/build/src/akuma/providers/codex-app-server/index.js +18 -6
  51. package/build/src/akuma/providers/grok-build/index.js +5 -4
  52. package/build/src/akuma/providers/opencode-sdk/index.js +66 -25
  53. package/build/src/akuma/providers/opencode-sdk/session.d.ts +3 -2
  54. package/build/src/akuma/providers/opencode-sdk/session.js +28 -11
  55. package/build/src/akuma/providers/pi/index.js +42 -14
  56. package/build/src/akuma/publication.js +75 -13
  57. package/build/src/akuma/request-lifecycle.d.ts +3 -9
  58. package/build/src/akuma/request-lifecycle.js +12 -25
  59. package/build/src/akuma/request-rendezvous.d.ts +26 -0
  60. package/build/src/akuma/request-rendezvous.js +100 -0
  61. package/build/src/akuma/request-serve.d.ts +5 -65
  62. package/build/src/akuma/request-serve.js +92 -204
  63. package/build/src/akuma/request-wire.d.ts +109 -115
  64. package/build/src/akuma/request-wire.js +63 -318
  65. package/build/src/akuma/requests.d.ts +19 -47
  66. package/build/src/akuma/requests.js +51 -107
  67. package/build/src/akuma/turn-drive.d.ts +5 -3
  68. package/build/src/akuma/turn-drive.js +32 -10
  69. package/build/src/akuma-body.d.ts +7 -2
  70. package/build/src/akuma-body.js +68 -46
  71. package/build/src/cli/accepted.d.ts +1 -1
  72. package/build/src/cli/accepted.js +2 -2
  73. package/build/src/cli/commands/akuma-invoke.d.ts +2 -0
  74. package/build/src/cli/commands/akuma-invoke.js +17 -9
  75. package/build/src/cli/commands/akuma.js +7 -7
  76. package/build/src/cli/commands/contract-invoke.d.ts +3 -2
  77. package/build/src/cli/commands/contract-invoke.js +26 -19
  78. package/build/src/cli/commands/contract.d.ts +13 -13
  79. package/build/src/cli/commands/contract.js +32 -17
  80. package/build/src/cli/commands/install.d.ts +1 -1
  81. package/build/src/cli/commands/install.js +1 -1
  82. package/build/src/cli/commands/task-invoke.d.ts +7 -2
  83. package/build/src/cli/commands/task-invoke.js +67 -158
  84. package/build/src/cli/commands/task.d.ts +1 -1
  85. package/build/src/cli/commands/task.js +60 -22
  86. package/build/src/cli/coordinates.d.ts +2 -0
  87. package/build/src/cli/coordinates.js +18 -2
  88. package/build/src/cli/invoke.js +39 -25
  89. package/build/src/cli/main.js +2 -1
  90. package/build/src/cli/parse.d.ts +2 -2
  91. package/build/src/cli/parse.js +37 -22
  92. package/build/src/cli/render/akuma-activity.d.ts +4 -1
  93. package/build/src/cli/render/akuma-activity.js +45 -30
  94. package/build/src/cli/render/akuma-tool.d.ts +5 -1
  95. package/build/src/cli/render/akuma.js +5 -9
  96. package/build/src/cli/render/audit.js +1 -1
  97. package/build/src/cli/render/catalog.js +80 -21
  98. package/build/src/cli/render/contract-observation.d.ts +2 -0
  99. package/build/src/cli/render/contract-observation.js +11 -0
  100. package/build/src/cli/render/contract.js +25 -65
  101. package/build/src/cli/render/kanshi-akuma.d.ts +8 -0
  102. package/build/src/cli/render/kanshi-akuma.js +111 -0
  103. package/build/src/cli/render/kanshi.js +108 -213
  104. package/build/src/cli/render/receipt.d.ts +1 -2
  105. package/build/src/cli/render/receipt.js +76 -26
  106. package/build/src/cli/render/refusal.js +2 -10
  107. package/build/src/cli/render/region.js +5 -2
  108. package/build/src/cli/render/settings.d.ts +1 -1
  109. package/build/src/cli/render/settings.js +27 -8
  110. package/build/src/cli/render/task.js +28 -10
  111. package/build/src/cli/render/terminal.d.ts +28 -0
  112. package/build/src/cli/render/terminal.js +65 -0
  113. package/build/src/cli/result.d.ts +3 -3
  114. package/build/src/cli/runtime.js +3 -1
  115. package/build/src/cli/selectors.d.ts +2 -1
  116. package/build/src/cli/selectors.js +4 -3
  117. package/build/src/cli/square-edge.js +120 -36
  118. package/build/src/cli/usage.js +2 -1
  119. package/build/src/contract-guidance.d.ts +5 -0
  120. package/build/src/contract-guidance.js +121 -0
  121. package/build/src/contract-worktree.d.ts +0 -1
  122. package/build/src/contract-worktree.js +32 -83
  123. package/build/src/coordination/sqlite-transaction-lock.d.ts +1 -0
  124. package/build/src/coordination/sqlite-transaction-lock.js +5 -0
  125. package/build/src/core/facts/codec.d.ts +2 -0
  126. package/build/src/core/facts/codec.js +4 -0
  127. package/build/src/core/verbs/placement.d.ts +6 -1
  128. package/build/src/core/verbs/placement.js +5 -3
  129. package/build/src/dispatch/index.d.ts +0 -2
  130. package/build/src/dispatch/index.js +54 -55
  131. package/build/src/git/admission.js +2 -2
  132. package/build/src/git/hooks.d.ts +9 -15
  133. package/build/src/git/hooks.js +23 -317
  134. package/build/src/git/nuke.d.ts +2 -1
  135. package/build/src/git/nuke.js +36 -18
  136. package/build/src/git/private-state-seat.d.ts +12 -0
  137. package/build/src/git/private-state-seat.js +39 -0
  138. package/build/src/git/process.d.ts +6 -0
  139. package/build/src/git/process.js +19 -7
  140. package/build/src/git/read-observation.js +29 -20
  141. package/build/src/git/reconcile.d.ts +11 -0
  142. package/build/src/git/reconcile.js +64 -11
  143. package/build/src/git/repository.d.ts +8 -2
  144. package/build/src/git/repository.js +42 -21
  145. package/build/src/git/target-placement.d.ts +1 -0
  146. package/build/src/git/target-placement.js +5 -6
  147. package/build/src/git/tender.d.ts +1 -0
  148. package/build/src/git/terminal-reconcile.d.ts +1 -1
  149. package/build/src/git/terminal-reconcile.js +22 -20
  150. package/build/src/git/workspace.d.ts +14 -0
  151. package/build/src/git/workspace.js +44 -0
  152. package/build/src/kanshi/index.d.ts +1 -1
  153. package/build/src/kanshi/read.js +16 -16
  154. package/build/src/kanshi/report.d.ts +2 -2
  155. package/build/src/library/address.d.ts +9 -3
  156. package/build/src/library/address.js +3 -2
  157. package/build/src/library/akuma-creation.d.ts +4 -3
  158. package/build/src/library/akuma-creation.js +19 -13
  159. package/build/src/library/audit.d.ts +1 -1
  160. package/build/src/library/audit.js +5 -3
  161. package/build/src/library/catalog.d.ts +3 -1
  162. package/build/src/library/catalog.js +20 -6
  163. package/build/src/library/composition.d.ts +371 -0
  164. package/build/src/library/composition.js +28 -0
  165. package/build/src/library/configuration.js +8 -2
  166. package/build/src/library/continuation.js +66 -30
  167. package/build/src/library/contract-bind.js +10 -2
  168. package/build/src/library/contract-forwarding-reconciliation-result.d.ts +96 -0
  169. package/build/src/library/contract-forwarding-reconciliation-result.js +83 -0
  170. package/build/src/library/contract-forwarding-result.d.ts +6723 -0
  171. package/build/src/library/contract-forwarding-result.js +521 -0
  172. package/build/src/library/contract-forwarding.d.ts +72 -0
  173. package/build/src/library/contract-forwarding.js +125 -0
  174. package/build/src/library/contract-handle.d.ts +36 -0
  175. package/build/src/library/contract-handle.js +313 -0
  176. package/build/src/library/contract-operations.d.ts +1044 -67
  177. package/build/src/library/contract-operations.js +190 -118
  178. package/build/src/library/contract.d.ts +11 -32
  179. package/build/src/library/contract.js +16 -289
  180. package/build/src/library/fleet-result.d.ts +1454 -0
  181. package/build/src/library/fleet-result.js +96 -0
  182. package/build/src/library/fleet.d.ts +112 -54
  183. package/build/src/library/fleet.js +211 -71
  184. package/build/src/library/input.d.ts +2 -0
  185. package/build/src/library/input.js +4 -0
  186. package/build/src/library/keiyaku.d.ts +371 -20
  187. package/build/src/library/keiyaku.js +8 -21
  188. package/build/src/library/mutation.d.ts +3 -3
  189. package/build/src/library/mutation.js +5 -9
  190. package/build/src/library/nuke.d.ts +1 -1
  191. package/build/src/library/nuke.js +4 -3
  192. package/build/src/library/reconcile.d.ts +4 -0
  193. package/build/src/library/reconcile.js +2 -0
  194. package/build/src/library/refusal.d.ts +0 -9
  195. package/build/src/library/refusal.js +0 -7
  196. package/build/src/protocol/amend.js +56 -50
  197. package/build/src/protocol/attempt.d.ts +2 -0
  198. package/build/src/protocol/attempt.js +17 -5
  199. package/build/src/protocol/completion.js +7 -0
  200. package/build/src/protocol/deliver.js +6 -2
  201. package/build/src/protocol/operations.d.ts +4 -1
  202. package/build/src/protocol/operations.js +5 -2
  203. package/build/src/protocol/placement.d.ts +1 -0
  204. package/build/src/protocol/placement.js +52 -38
  205. package/build/src/protocol/read/observation.d.ts +1 -4
  206. package/build/src/protocol/read/observation.js +2 -15
  207. package/build/src/protocol/reintegrate.js +62 -58
  208. package/build/src/protocol/review.js +5 -0
  209. package/build/src/protocol/run.js +17 -13
  210. package/build/src/runtime/proc/run.d.ts +8 -0
  211. package/build/src/runtime/proc/run.js +27 -0
  212. package/build/src/runtime/proc/termination.js +26 -22
  213. package/build/src/runtime/proc/windows-launch.exe +0 -0
  214. package/build/src/settlement/holder.d.ts +2 -1
  215. package/build/src/settlement/holder.js +15 -4
  216. package/build/src/settlement/settle.js +99 -33
  217. package/build/src/task/board.d.ts +68 -27
  218. package/build/src/task/board.js +31 -1
  219. package/build/src/task/catalog.d.ts +4 -0
  220. package/build/src/task/catalog.js +23 -0
  221. package/build/src/task/compose-language.d.ts +4 -0
  222. package/build/src/task/compose-language.js +40 -7
  223. package/build/src/task/compose-parser.d.ts +2 -1
  224. package/build/src/task/compose-parser.js +5 -3
  225. package/build/src/task/compose.d.ts +1 -0
  226. package/build/src/task/compose.js +4 -1
  227. package/build/src/task/context.d.ts +7 -1
  228. package/build/src/task/context.js +25 -6
  229. package/build/src/task/index.d.ts +18 -5
  230. package/build/src/task/index.js +97 -16
  231. package/build/src/task/mutation-result.d.ts +923 -0
  232. package/build/src/task/mutation-result.js +140 -0
  233. package/build/src/task/mutation.d.ts +552 -28
  234. package/build/src/task/mutation.js +304 -97
  235. package/build/src/task/operations.d.ts +1 -4
  236. package/build/src/task/operations.js +0 -6
  237. package/build/src/task/public.d.ts +2 -0
  238. package/build/src/task/public.js +1 -0
  239. package/build/src/workspace-place.d.ts +7 -2
  240. package/build/src/workspace-place.js +34 -24
  241. package/build/src/world.d.ts +1 -0
  242. package/build/src/world.js +11 -0
  243. package/package.json +8 -6
  244. package/build/src/akuma/request-execution.d.ts +0 -8
  245. package/build/src/akuma/request-execution.js +0 -98
@@ -1,76 +1,16 @@
1
- import { type KillEvidence, type RequestFact } from "./heart/index.js";
2
- import { type AkuId } from "./identity.js";
3
- import { type StructuralRequestClaim } from "./request-wire.js";
4
- import { type TaskMutationRequest } from "../task/mutation.js";
5
- import { BodyRequestPump as LifecycleBodyRequestPump, type RequestChildLaunch as LifecycleRequestChildLaunch, type PumpInput as LifecyclePumpInput } from "./request-lifecycle.js";
1
+ import { type ErasedRequestCommand, type RequestEnvelope } from "./request-wire.js";
2
+ import { BodyRequestPump as LifecycleBodyRequestPump, type PumpInput as LifecyclePumpInput } from "./request-lifecycle.js";
6
3
  export { clearBodyRequestTransport, settleBodyRequests } from "./request-lifecycle.js";
7
- export type RequestChildLaunch = LifecycleRequestChildLaunch;
8
- type UpstreamCall = Readonly<{
9
- signal: AbortSignal;
10
- }>;
11
- type RequesterCall = UpstreamCall & Readonly<{
12
- requester: AkuId;
13
- }>;
14
- type ContractCall = RequesterCall & Readonly<{
15
- repoRoot: string;
16
- contractId: string;
17
- }>;
18
- export type UpstreamExecutionPort = Readonly<{
19
- wait(input: UpstreamCall & Readonly<{
20
- targets: readonly AkuId[];
21
- completion: "any" | "all";
22
- timeoutMs?: number;
23
- }>): Promise<unknown>;
24
- tell(input: UpstreamCall & Readonly<{
25
- target: AkuId;
26
- body: string;
27
- tellId: string;
28
- recordedAt: string;
29
- }>): Promise<unknown>;
30
- kill(input: Readonly<{
31
- targets: readonly AkuId[];
32
- signal: AbortSignal;
33
- }>): Promise<Readonly<{
34
- result: unknown;
35
- service: readonly Readonly<{
36
- id: AkuId;
37
- evidence: KillEvidence;
38
- }>[];
39
- }>>;
40
- deliver(input: ContractCall & Readonly<{
41
- message?: string;
42
- includeDirty: boolean;
43
- materializeConflict: boolean;
44
- }>): Promise<Readonly<{
45
- result: unknown;
46
- deliveryFactId?: string;
47
- }>>;
48
- review(input: ContractCall & Readonly<{
49
- verdict: "satisfied" | "unsatisfied";
50
- summary?: string;
51
- }>): Promise<Readonly<{
52
- result: unknown;
53
- reviewFactId?: string;
54
- }>>;
55
- task(input: RequesterCall & Readonly<{
56
- world: string;
57
- request: TaskMutationRequest;
58
- }>): Promise<unknown>;
59
- }>;
60
4
  type PumpInput = Omit<LifecyclePumpInput, "upstream"> & Readonly<{
61
- upstream?: UpstreamExecutionPort;
5
+ upstream?: unknown;
6
+ commands: Readonly<Record<string, ErasedRequestCommand>>;
62
7
  }>;
63
8
  export type ServeInput = Omit<PumpInput, "bodySequence"> & Readonly<{
64
9
  directory: string;
65
10
  transportId: string;
66
- claim: StructuralRequestClaim;
11
+ claim: RequestEnvelope;
67
12
  admissionOpen(): boolean;
68
13
  }>;
69
- export type UpstreamFact = Exclude<Extract<RequestFact, {
70
- state: "admitted";
71
- }>, Extract<RequestFact, {
72
- action: "akuma.call";
73
- }>>;
74
14
  export declare function serveRequest(input: ServeInput): Promise<void>;
75
15
  export declare class BodyRequestPump extends LifecycleBodyRequestPump {
76
16
  static open(input: PumpInput): Promise<BodyRequestPump>;
@@ -1,251 +1,139 @@
1
- import { admitRequest, readRequest, refuseRequest, reserveRequest, serveRequest as serveChildRequest, serveUpstreamRequest, voidRequest, } from "./heart/index.js";
2
- import { worldRootForAkumaPaths } from "./identity.js";
3
- import { publishAkuma } from "./publication.js";
4
- import { atomicJson, canonicalAkuId, decodeRecipe, receiptPath, } from "./request-wire.js";
5
- import { isTaskMutationAction } from "../task/mutation.js";
6
- import { executeRequest } from "./request-execution.js";
1
+ import { admitRequest, isRequestInputConflict, readRequest, serveRequest as serveChildRequest, serveUpstreamRequest, voidRequest, } from "./heart/index.js";
2
+ import { atomicJson, receiptPath, } from "./request-wire.js";
7
3
  import { BodyRequestPump as LifecycleBodyRequestPump, } from "./request-lifecycle.js";
8
4
  export { clearBodyRequestTransport, settleBodyRequests } from "./request-lifecycle.js";
9
- function diagnostic(error) {
10
- return error instanceof Error ? error.message : String(error);
11
- }
12
- function isTask(value) {
13
- return isTaskMutationAction(value.action);
14
- }
15
- function refusalRecipe(value) {
16
- if (value !== null && typeof value === "object" && !Array.isArray(value)) {
17
- const recipe = value;
18
- if (Array.isArray(recipe.allowed))
19
- return recipe;
20
- return { ...recipe, allowed: [] };
21
- }
22
- return { allowed: [] };
23
- }
24
- function acceptedReceipt(fact, service) {
25
- return {
26
- id: fact.id,
27
- action: fact.action,
28
- state: fact.state,
29
- reference: service.action === "contract.deliver"
5
+ async function projectCommandReceipt(input, fact, command, outcome, failure) {
6
+ const receipt = fact.state === "refused"
7
+ ? { id: fact.id, action: fact.action, state: "refused", diagnostic: fact.diagnostic }
8
+ : fact.state === "voided"
30
9
  ? {
31
- kind: "accepted-reference",
32
- repoRoot: service.repoRoot,
33
- contractId: service.contractId,
34
- deliveryFactId: service.deliveryFactId,
10
+ id: fact.id,
11
+ action: fact.action,
12
+ state: "voided",
13
+ evidence: fact.evidence,
14
+ ...(failure === undefined ? {} : { failure }),
35
15
  }
36
- : {
37
- kind: "accepted-reference",
38
- repoRoot: service.repoRoot,
39
- contractId: service.contractId,
40
- reviewFactId: service.reviewFactId,
41
- },
42
- };
43
- }
44
- function receiptFor(fact) {
45
- if (fact.state === "refused") {
46
- return { id: fact.id, action: fact.action, state: fact.state, diagnostic: fact.diagnostic };
47
- }
48
- if (fact.state === "voided") {
49
- return { id: fact.id, action: fact.action, state: fact.state, evidence: fact.evidence };
50
- }
51
- if (fact.action === "akuma.call" && fact.state === "served") {
52
- return { id: fact.id, action: fact.action, state: fact.state, child: fact.child };
53
- }
54
- if (fact.state !== "served")
55
- return null;
56
- if (fact.action === "contract.deliver") {
57
- return acceptedReceipt(fact, fact.service);
58
- }
59
- if (fact.action === "contract.review") {
60
- return acceptedReceipt(fact, fact.service);
61
- }
62
- if (isTask(fact)) {
63
- return {
64
- id: fact.id,
65
- action: fact.action,
66
- state: fact.state,
67
- reference: { kind: "served-reference", action: fact.action },
68
- };
69
- }
70
- return null;
71
- }
72
- async function projectReceipt(directory, transportId, fact, outcome) {
73
- const receipt = outcome === undefined
74
- ? receiptFor(fact)
75
- : fact.action === "akuma.call"
76
- ? null
77
- : { id: fact.id, action: fact.action, state: "served", outcome };
16
+ : outcome === undefined
17
+ ? "serviceJson" in fact
18
+ ? {
19
+ id: fact.id,
20
+ action: fact.action,
21
+ state: "served",
22
+ reference: command.projectServiceJson(fact.serviceJson),
23
+ }
24
+ : "child" in fact
25
+ ? {
26
+ id: fact.id,
27
+ action: fact.action,
28
+ state: "served",
29
+ reference: command.projectChild(fact.child),
30
+ }
31
+ : null
32
+ : { id: fact.id, action: fact.action, state: "served", outcome };
78
33
  if (receipt === null)
79
34
  return;
80
35
  try {
81
- await atomicJson(receiptPath(directory, transportId), receipt);
36
+ await atomicJson(receiptPath(input.directory, input.transportId), receipt);
82
37
  }
83
38
  catch (error) {
84
39
  if (error.code !== "ENOENT")
85
40
  throw error;
86
41
  }
87
42
  }
88
- async function refuseInvalidCall(input) {
43
+ async function serveCommand(input, command) {
44
+ const request = command.resolve(input.claim.payload);
45
+ if (request === null)
46
+ return false;
89
47
  let fact = await admitRequest(input.paths, {
90
- ...input.claim,
91
- recipe: refusalRecipe(input.claim.recipe),
48
+ id: input.claim.id,
49
+ action: input.claim.action,
50
+ payloadJson: request.payloadJson,
92
51
  admittedAt: input.now(),
52
+ permitted: request.isPermitted(input.parent.allowed),
93
53
  });
94
- const existing = receiptFor(fact);
95
- if (existing !== null) {
96
- await projectReceipt(input.directory, input.transportId, fact);
97
- return;
98
- }
99
- fact = await refuseRequest(input.paths, input.claim.id, "invalid akuma.call recipe");
100
- await projectReceipt(input.directory, input.transportId, fact);
101
- }
102
- async function serveCall(input) {
103
- input.signal.throwIfAborted();
104
- if (!input.admissionOpen())
105
- return;
106
- const recipe = decodeRecipe(input.claim.recipe);
107
- if (recipe === null) {
108
- await refuseInvalidCall(input);
109
- return;
110
- }
111
- let fact = await admitRequest(input.paths, { ...input.claim, recipe, admittedAt: input.now() });
112
- const existing = receiptFor(fact);
113
- if (existing !== null) {
114
- await projectReceipt(input.directory, input.transportId, fact);
115
- return;
54
+ if (fact.state !== "admitted") {
55
+ await projectCommandReceipt(input, fact, request);
56
+ return true;
116
57
  }
117
58
  if (!input.admissionOpen()) {
118
- fact = await voidRequest(input.paths, input.claim.id, "body closed request admission");
119
- await projectReceipt(input.directory, input.transportId, fact);
120
- return;
121
- }
122
- if (fact.action !== "akuma.call" || fact.state !== "admitted") {
123
- throw new Error(`Akuma request ${fact.id} cannot be replayed from ${fact.state}`);
124
- }
125
- const request = fact;
126
- const world = worldRootForAkumaPaths(input.paths);
127
- if (request.world !== world) {
128
- fact = await refuseRequest(input.paths, request.id, `request world ${request.world} does not match ${world}`);
129
- await projectReceipt(input.directory, input.transportId, fact);
130
- return;
59
+ fact = await voidRequest(input.paths, fact.id, "body closed request admission");
60
+ await projectCommandReceipt(input, fact, request);
61
+ return true;
131
62
  }
132
63
  try {
133
- const published = await publishAkuma({
134
- worldPath: world,
135
- archetype: request.archetype,
64
+ const served = await request.execute({
65
+ id: fact.id,
66
+ admittedAt: fact.admittedAt,
67
+ requester: fact.requester,
136
68
  signal: input.signal,
137
- launch: async (allocated) => {
138
- if (!input.admissionOpen())
139
- throw new Error("body closed request admission");
140
- fact = await reserveRequest(input.paths, request.id, allocated.id);
141
- return await input.spawn({
142
- paths: allocated.paths,
143
- seed: {
144
- id: allocated.id,
145
- archetype: allocated.archetype,
146
- ...(request.recipe.description === undefined ? {} : { description: request.recipe.description }),
147
- provider: request.recipe.provider,
148
- options: request.recipe.options,
149
- ...(request.recipe.readonly === undefined ? {} : { readonly: request.recipe.readonly }),
150
- allowed: request.recipe.allowed,
151
- cwd: request.cwd ?? input.parent.cwd,
152
- origin: {
153
- kind: "request",
154
- parent: input.parent.id,
155
- requestId: request.id,
156
- },
157
- },
158
- initialBody: request.body,
159
- });
160
- },
69
+ upstream: input.upstream,
70
+ paths: input.paths,
71
+ parent: input.parent,
72
+ spawn: input.spawn,
73
+ admissionOpen: input.admissionOpen,
161
74
  });
162
- fact = await serveChildRequest(input.paths, request.id, published.id);
75
+ fact =
76
+ "child" in served
77
+ ? await serveChildRequest(input.paths, fact.id, served.child)
78
+ : await serveUpstreamRequest(input.paths, fact.id, served.serviceJson);
79
+ await projectCommandReceipt(input, fact, request, { kind: "returned", result: served.result });
163
80
  }
164
81
  catch (error) {
165
- const current = await readRequest(input.paths, request.id);
82
+ const failure = encodedFailure(request, error);
83
+ const current = await readRequest(input.paths, fact.id);
166
84
  if (current === null)
167
85
  throw error;
168
86
  fact =
169
87
  current.state === "admitted" || current.state === "reserved"
170
- ? await voidRequest(input.paths, request.id, diagnostic(error))
88
+ ? await voidRequest(input.paths, fact.id, diagnostic(error))
171
89
  : current;
90
+ await projectCommandReceipt(input, fact, request, undefined, failure);
172
91
  }
173
- await projectReceipt(input.directory, input.transportId, fact);
92
+ return true;
174
93
  }
175
- function failure(error) {
176
- const value = error !== null && typeof error === "object" ? error : null;
177
- if (value?.kind === "akuma-not-born") {
178
- const id = canonicalAkuId(value.id);
179
- if (id !== null)
180
- return { kind: "akuma-not-born", id };
181
- }
182
- return { kind: "failed", diagnostic: diagnostic(error) };
94
+ function diagnostic(error) {
95
+ return error instanceof Error ? error.message : String(error);
183
96
  }
184
- function pendingService(request) {
185
- if (request.action === "akuma.wait")
186
- return { action: request.action };
187
- if (request.action === "akuma.tell") {
188
- return { action: request.action, target: request.target, tellId: request.id };
97
+ function encodedFailure(request, error) {
98
+ try {
99
+ const failure = request.encodeFailure(error);
100
+ return failure === null ? undefined : failure;
189
101
  }
190
- return request.action === "akuma.kill" ? { action: request.action, results: [] } : undefined;
191
- }
192
- async function serveUpstream(input) {
193
- input.signal.throwIfAborted();
194
- let fact = await admitRequest(input.paths, {
195
- ...input.claim,
196
- admittedAt: input.now(),
197
- });
198
- const existing = receiptFor(fact);
199
- if (existing !== null) {
200
- await projectReceipt(input.directory, input.transportId, fact);
201
- return;
102
+ catch {
103
+ return undefined;
202
104
  }
203
- if (fact.state === "served") {
204
- await projectReceipt(input.directory, input.transportId, fact, {
205
- kind: "failed",
206
- failure: {
207
- kind: "failed",
208
- diagnostic: "served request receipt is no longer available",
209
- },
105
+ }
106
+ export async function serveRequest(input) {
107
+ const command = input.commands[input.claim.action];
108
+ if (command === undefined) {
109
+ await atomicJson(receiptPath(input.directory, input.transportId), {
110
+ id: input.claim.id,
111
+ action: input.claim.action,
112
+ state: "refused",
113
+ diagnostic: `request action ${input.claim.action} is not registered`,
210
114
  });
211
115
  return;
212
116
  }
213
- if (!input.admissionOpen()) {
214
- fact = await voidRequest(input.paths, input.claim.id, "body closed request admission");
215
- await projectReceipt(input.directory, input.transportId, fact);
117
+ if (await serveCommand(input, command))
216
118
  return;
217
- }
218
- if (fact.state !== "admitted" || fact.action === "akuma.call") {
219
- throw new Error(`Akuma request ${fact.id} cannot be served from ${fact.state}`);
220
- }
221
- const request = fact;
222
- let outcome;
223
- let service = pendingService(request);
119
+ }
120
+ async function serveTransportClaim(input) {
224
121
  try {
225
- const served = await executeRequest(input, request);
226
- outcome = { kind: "returned", result: served.result };
227
- if (served.service !== undefined)
228
- service = served.service;
122
+ await serveRequest(input);
229
123
  }
230
124
  catch (error) {
231
- outcome = { kind: "failed", failure: failure(error) };
232
- fact = await voidRequest(input.paths, request.id, "body failed before serving the request");
233
- await projectReceipt(input.directory, input.transportId, fact);
234
- return;
125
+ if (!isRequestInputConflict(error))
126
+ throw error;
127
+ await atomicJson(receiptPath(input.directory, input.transportId), {
128
+ id: input.claim.id,
129
+ action: input.claim.action,
130
+ state: "refused",
131
+ diagnostic: error.message,
132
+ });
235
133
  }
236
- fact =
237
- service === undefined
238
- ? await voidRequest(input.paths, request.id, "body completed without a durable Contract fact reference")
239
- : await serveUpstreamRequest(input.paths, request.id, service);
240
- await projectReceipt(input.directory, input.transportId, fact, outcome);
241
- }
242
- export async function serveRequest(input) {
243
- return input.claim.action === "akuma.call"
244
- ? await serveCall({ ...input, claim: input.claim })
245
- : await serveUpstream({ ...input, claim: input.claim });
246
134
  }
247
135
  export class BodyRequestPump extends LifecycleBodyRequestPump {
248
136
  static async open(input) {
249
- return (await LifecycleBodyRequestPump.openWithService(input, async (claim) => await serveRequest(claim)));
137
+ return (await LifecycleBodyRequestPump.openWithService(input, async (claim) => await serveTransportClaim({ ...claim, commands: input.commands })));
250
138
  }
251
139
  }
@@ -1,124 +1,118 @@
1
- import { type AkuId } from "./identity.js";
2
- import { decodeProviderOptions, type ReadonlyRestraint } from "./provider-recipe.js";
3
- import { decodeProviderExecution } from "./providers/index.js";
4
- import { type TaskMutationAction, type TaskMutationRequest } from "../task/mutation.js";
5
- export type RequestRecipe = Readonly<{
6
- description?: string;
7
- allowed: readonly string[];
8
- provider: ReturnType<typeof decodeProviderExecution>;
9
- options: ReturnType<typeof decodeProviderOptions>;
10
- readonly?: ReadonlyRestraint;
1
+ import { z } from "zod";
2
+ declare const requestEnvelopeSchema: z.ZodObject<{
3
+ id: z.ZodString;
4
+ action: z.ZodString;
5
+ payload: z.ZodUnknown;
6
+ }, z.core.$strict>;
7
+ declare const upstreamRequestFailureSchema: z.ZodUnion<readonly [z.ZodObject<{
8
+ kind: z.ZodLiteral<"akuma-not-born">;
9
+ id: z.ZodString;
10
+ }, z.core.$strict>, z.ZodObject<{
11
+ kind: z.ZodLiteral<"failed">;
12
+ diagnostic: z.ZodString;
13
+ }, z.core.$strict>]>;
14
+ declare const returnedEnvelopeSchema: z.ZodUnion<readonly [z.ZodObject<{
15
+ kind: z.ZodLiteral<"returned">;
16
+ result: z.ZodUnknown;
17
+ }, z.core.$strict>, z.ZodObject<{
18
+ kind: z.ZodLiteral<"failed">;
19
+ failure: z.ZodUnion<readonly [z.ZodObject<{
20
+ kind: z.ZodLiteral<"akuma-not-born">;
21
+ id: z.ZodString;
22
+ }, z.core.$strict>, z.ZodObject<{
23
+ kind: z.ZodLiteral<"failed">;
24
+ diagnostic: z.ZodString;
25
+ }, z.core.$strict>]>;
26
+ }, z.core.$strict>]>;
27
+ declare const receiptEnvelopeSchema: z.ZodUnion<readonly [z.ZodObject<{
28
+ id: z.ZodString;
29
+ action: z.ZodString;
30
+ state: z.ZodLiteral<"served">;
31
+ outcome: z.ZodUnion<readonly [z.ZodObject<{
32
+ kind: z.ZodLiteral<"returned">;
33
+ result: z.ZodUnknown;
34
+ }, z.core.$strict>, z.ZodObject<{
35
+ kind: z.ZodLiteral<"failed">;
36
+ failure: z.ZodUnion<readonly [z.ZodObject<{
37
+ kind: z.ZodLiteral<"akuma-not-born">;
38
+ id: z.ZodString;
39
+ }, z.core.$strict>, z.ZodObject<{
40
+ kind: z.ZodLiteral<"failed">;
41
+ diagnostic: z.ZodString;
42
+ }, z.core.$strict>]>;
43
+ }, z.core.$strict>]>;
44
+ }, z.core.$strict>, z.ZodObject<{
45
+ id: z.ZodString;
46
+ action: z.ZodString;
47
+ state: z.ZodLiteral<"served">;
48
+ reference: z.ZodUnknown;
49
+ }, z.core.$strict>, z.ZodObject<{
50
+ id: z.ZodString;
51
+ action: z.ZodString;
52
+ state: z.ZodLiteral<"refused">;
53
+ diagnostic: z.ZodString;
54
+ }, z.core.$strict>, z.ZodObject<{
55
+ id: z.ZodString;
56
+ action: z.ZodString;
57
+ state: z.ZodLiteral<"voided">;
58
+ evidence: z.ZodString;
59
+ failure: z.ZodOptional<z.ZodUnknown>;
60
+ }, z.core.$strict>]>;
61
+ export type RequestEnvelope = z.infer<typeof requestEnvelopeSchema>;
62
+ /**
63
+ * A Body Request operation is owned by the verb that defines its public
64
+ * values. Transport only carries the opaque values produced here.
65
+ */
66
+ export type RequestCommand<Input, Output, Service, Reference = Service, Context = unknown> = Readonly<{
67
+ action: string;
68
+ encodeRequest(input: Input): unknown;
69
+ decodeRequest(payload: unknown): Input | null;
70
+ encodeResult(result: Output): unknown;
71
+ decodeResult(result: unknown): Output;
72
+ encodeFailure?(error: unknown): unknown | null;
73
+ decodeFailure?(failure: unknown): Error | null;
74
+ encodeService(service: Service): unknown;
75
+ decodeService(service: unknown): Service;
76
+ projectService(service: Service): Reference;
77
+ projectChild?(child: string): Reference;
78
+ decodeReference(reference: unknown): Reference;
79
+ /** The operation owner proves the Body-owned execution capability before use. */
80
+ decodeExecutionContext(value: unknown): Context;
81
+ isPermitted(allowed: readonly string[]): boolean;
82
+ execute(input: Input, context: Context): Promise<Readonly<{
83
+ result: Output;
84
+ }> & (Readonly<{
85
+ service: Service;
86
+ }> | Readonly<{
87
+ child: string;
88
+ }>)>;
11
89
  }>;
12
- export type CallRequestClaim = Readonly<{
13
- id: string;
14
- action: "akuma.call";
15
- world: string;
16
- archetype: string;
17
- body: string;
18
- cwd?: string;
19
- recipe: RequestRecipe;
90
+ export type ErasedRequestCommand = Readonly<{
91
+ action: string;
92
+ resolve(payload: unknown): ErasedRequest | null;
20
93
  }>;
21
- export type WaitRequestClaim = Readonly<{
22
- id: string;
23
- action: "akuma.wait";
24
- targets: readonly AkuId[];
25
- completion: "any" | "all";
26
- timeoutMs?: number;
94
+ export type ErasedRequest = Readonly<{
95
+ payloadJson: string;
96
+ isPermitted(allowed: readonly string[]): boolean;
97
+ execute(context: unknown): Promise<ErasedRequestExecution>;
98
+ encodeFailure(error: unknown): unknown | null;
99
+ projectServiceJson(serviceJson: string): unknown;
100
+ projectChild(child: string): unknown;
27
101
  }>;
28
- export type TellRequestClaim = Readonly<{
29
- id: string;
30
- action: "akuma.tell";
31
- target: AkuId;
32
- body: string;
33
- }>;
34
- export type KillRequestClaim = Readonly<{
35
- id: string;
36
- action: "akuma.kill";
37
- targets: readonly AkuId[];
38
- }>;
39
- export type DeliverRequestClaim = Readonly<{
40
- id: string;
41
- action: "contract.deliver";
42
- repoRoot: string;
43
- contractId: string;
44
- message?: string;
45
- includeDirty: boolean;
46
- materializeConflict: boolean;
47
- }>;
48
- export type ReviewRequestClaim = Readonly<{
49
- id: string;
50
- action: "contract.review";
51
- repoRoot: string;
52
- contractId: string;
53
- verdict: "satisfied" | "unsatisfied";
54
- summary?: string;
55
- }>;
56
- export type TaskRequestClaim = Readonly<{
57
- id: string;
58
- action: TaskMutationAction;
59
- world: string;
60
- request: TaskMutationRequest;
61
- }>;
62
- export type RequestClaim = CallRequestClaim | WaitRequestClaim | TellRequestClaim | KillRequestClaim | DeliverRequestClaim | ReviewRequestClaim | TaskRequestClaim;
63
- export type StructuralRequestClaim = (Omit<CallRequestClaim, "recipe"> & Readonly<{
64
- recipe: unknown;
65
- }>) | Exclude<RequestClaim, CallRequestClaim>;
66
- export type UpstreamRequestFailure = Readonly<{
67
- kind: "akuma-not-born";
68
- id: AkuId;
69
- }> | Readonly<{
70
- kind: "failed";
71
- diagnostic: string;
72
- }>;
73
- export type UpstreamRequestOutcome = Readonly<{
74
- kind: "returned";
102
+ export type ErasedRequestExecution = Readonly<{
75
103
  result: unknown;
104
+ serviceJson: string;
76
105
  }> | Readonly<{
77
- kind: "failed";
78
- failure: UpstreamRequestFailure;
79
- }>;
80
- export type ForwardedDeliveryReference = Readonly<{
81
- kind: "accepted-reference";
82
- repoRoot: string;
83
- contractId: string;
84
- deliveryFactId: string;
85
- }>;
86
- export type ForwardedReviewReference = Readonly<{
87
- kind: "accepted-reference";
88
- repoRoot: string;
89
- contractId: string;
90
- reviewFactId: string;
91
- }>;
92
- export type ForwardedTaskReference = Readonly<{
93
- kind: "served-reference";
94
- action: TaskMutationAction;
95
- }>;
96
- type ReceiptBase<A extends RequestClaim["action"], S extends string> = Readonly<{
97
- id: string;
98
- action: A;
99
- state: S;
106
+ result: unknown;
107
+ child: string;
100
108
  }>;
101
- export type RequestReceipt = (ReceiptBase<"akuma.call", "served"> & Readonly<{
102
- child: AkuId;
103
- }>) | (ReceiptBase<"contract.deliver", "served"> & Readonly<{
104
- reference: ForwardedDeliveryReference;
105
- }>) | (ReceiptBase<"contract.review", "served"> & Readonly<{
106
- reference: ForwardedReviewReference;
107
- }>) | (ReceiptBase<TaskMutationAction, "served"> & Readonly<{
108
- reference: ForwardedTaskReference;
109
- }>) | (ReceiptBase<Exclude<RequestClaim["action"], "akuma.call">, "served"> & Readonly<{
110
- outcome: UpstreamRequestOutcome;
111
- }>) | (ReceiptBase<RequestClaim["action"], "refused"> & Readonly<{
112
- diagnostic: string;
113
- }>) | (ReceiptBase<RequestClaim["action"], "voided"> & Readonly<{
114
- evidence: string;
115
- }>);
116
- export declare function absolute(value: unknown): value is string;
117
- export declare function canonicalAkuId(value: unknown): AkuId | null;
118
- export declare function decodeRecipe(value: unknown): RequestRecipe | null;
119
- export declare function decodeClaim(bytes: string, fileId: string): StructuralRequestClaim | null;
120
- export declare function decodeReceipt(bytes: string, id: string, action: RequestClaim["action"]): RequestReceipt | null;
121
- export declare function requestPayload(claim: RequestClaim): unknown;
109
+ /** Erases only static TypeScript parameters; each operation codec remains captured by its owner descriptor. */
110
+ export declare function eraseRequestCommand<Input, Output, Service, Reference, Context>(command: RequestCommand<Input, Output, Service, Reference, Context>): ErasedRequestCommand;
111
+ export type UpstreamRequestFailure = z.infer<typeof upstreamRequestFailureSchema>;
112
+ export type ReturnedEnvelope = z.infer<typeof returnedEnvelopeSchema>;
113
+ export type ReceiptEnvelope = z.infer<typeof receiptEnvelopeSchema>;
114
+ export declare function decodeEnvelope(bytes: string, fileId: string): RequestEnvelope | null;
115
+ export declare function decodeReceiptEnvelope(bytes: string, id: string, action: string): ReceiptEnvelope | null;
122
116
  export declare function requestPath(directory: string, id: string): string;
123
117
  export declare function receiptPath(directory: string, id: string): string;
124
118
  export declare function atomicJson(path: string, value: unknown): Promise<void>;