@astrosheep/keiyaku 4.5.16 → 4.5.18

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 (193) hide show
  1. package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +1 -1
  2. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +5 -2
  3. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +4 -2
  4. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-babysit/SKILL.md +3 -1
  5. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +3 -1
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-task/SKILL.md +3 -2
  7. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +13 -1
  8. package/build/src/akuma/akuma-handle.d.ts +18 -7
  9. package/build/src/akuma/akuma-handle.js +89 -112
  10. package/build/src/akuma/akuma-instance.d.ts +19 -4
  11. package/build/src/akuma/akuma-instance.js +102 -38
  12. package/build/src/akuma/akuma-observe.js +40 -22
  13. package/build/src/akuma/akuma-product.d.ts +12 -8
  14. package/build/src/akuma/akuma-product.js +66 -54
  15. package/build/src/akuma/akuma.d.ts +9 -21
  16. package/build/src/akuma/akuma.js +11 -67
  17. package/build/src/akuma/body.js +134 -67
  18. package/build/src/akuma/call-request.d.ts +2 -2
  19. package/build/src/akuma/call-request.js +2 -2
  20. package/build/src/akuma/control.d.ts +8 -0
  21. package/build/src/akuma/control.js +23 -0
  22. package/build/src/akuma/dispatch-association.d.ts +13 -0
  23. package/build/src/akuma/dispatch-association.js +20 -0
  24. package/build/src/akuma/fleet-execution.js +10 -15
  25. package/build/src/akuma/fleet-observation.js +1 -1
  26. package/build/src/akuma/fleet-request.js +9 -2
  27. package/build/src/akuma/heart/facts.d.ts +3 -0
  28. package/build/src/akuma/heart/facts.js +6 -0
  29. package/build/src/akuma/heart/index.d.ts +1 -0
  30. package/build/src/akuma/heart/index.js +5 -8
  31. package/build/src/akuma/heart/rows.d.ts +1 -0
  32. package/build/src/akuma/heart/rows.js +7 -0
  33. package/build/src/akuma/heart/schema.d.ts +1 -1
  34. package/build/src/akuma/heart/schema.js +5 -3
  35. package/build/src/akuma/heart/tells.d.ts +2 -2
  36. package/build/src/akuma/heart/tells.js +16 -11
  37. package/build/src/akuma/index.d.ts +5 -3
  38. package/build/src/akuma/index.js +1 -1
  39. package/build/src/akuma/nuke.js +8 -45
  40. package/build/src/akuma/providers/claude/events.d.ts +1 -1
  41. package/build/src/akuma/providers/claude/events.js +2 -1
  42. package/build/src/akuma/providers/codex-app-server/events.d.ts +2 -2
  43. package/build/src/akuma/providers/codex-app-server/events.js +6 -2
  44. package/build/src/akuma/providers/grok-build/index.js +13 -4
  45. package/build/src/akuma/providers/opencode-sdk/events.d.ts +1 -1
  46. package/build/src/akuma/providers/opencode-sdk/events.js +5 -1
  47. package/build/src/akuma/providers/pi/events.d.ts +4 -0
  48. package/build/src/akuma/providers/pi/events.js +8 -3
  49. package/build/src/akuma/publication.js +2 -11
  50. package/build/src/akuma/request-rendezvous.d.ts +1 -1
  51. package/build/src/akuma/request-rendezvous.js +9 -8
  52. package/build/src/akuma/schema.d.ts +4 -6
  53. package/build/src/akuma/schema.js +35 -31
  54. package/build/src/akuma-body.js +3 -2
  55. package/build/src/cli/accepted.d.ts +1 -2
  56. package/build/src/cli/accepted.js +18 -16
  57. package/build/src/cli/commands/akuma-invoke.d.ts +0 -2
  58. package/build/src/cli/commands/akuma-invoke.js +8 -25
  59. package/build/src/cli/commands/akuma.d.ts +2 -1
  60. package/build/src/cli/commands/akuma.js +6 -6
  61. package/build/src/cli/commands/contract-help.d.ts +2 -1
  62. package/build/src/cli/commands/contract-help.js +27 -13
  63. package/build/src/cli/commands/contract-invoke.js +15 -0
  64. package/build/src/cli/commands/contract.d.ts +1 -0
  65. package/build/src/cli/commands/contract.js +4 -3
  66. package/build/src/cli/commands/install.js +8 -7
  67. package/build/src/cli/commands/task.d.ts +2 -0
  68. package/build/src/cli/commands/task.js +9 -5
  69. package/build/src/cli/invoke.d.ts +0 -1
  70. package/build/src/cli/invoke.js +19 -5
  71. package/build/src/cli/parse.d.ts +3 -0
  72. package/build/src/cli/parse.js +26 -13
  73. package/build/src/cli/render/akuma-activity.js +4 -4
  74. package/build/src/cli/render/akuma.js +7 -9
  75. package/build/src/cli/render/audit.js +28 -24
  76. package/build/src/cli/render/board.js +7 -3
  77. package/build/src/cli/render/catalog.js +16 -23
  78. package/build/src/cli/render/contract-history.js +20 -21
  79. package/build/src/cli/render/contract-observation.d.ts +2 -0
  80. package/build/src/cli/render/contract-observation.js +30 -6
  81. package/build/src/cli/render/contract.js +39 -33
  82. package/build/src/cli/render/kanshi-akuma.js +5 -6
  83. package/build/src/cli/render/kanshi.js +56 -99
  84. package/build/src/cli/render/nuke.js +3 -3
  85. package/build/src/cli/render/receipt.d.ts +15 -5
  86. package/build/src/cli/render/receipt.js +54 -20
  87. package/build/src/cli/render/refusal.d.ts +1 -1
  88. package/build/src/cli/render/refusal.js +55 -45
  89. package/build/src/cli/render/region.js +8 -8
  90. package/build/src/cli/render/settings.js +13 -11
  91. package/build/src/cli/render/status-set.js +13 -8
  92. package/build/src/cli/render/task.d.ts +1 -0
  93. package/build/src/cli/render/task.js +15 -14
  94. package/build/src/cli/render/terminal.d.ts +3 -1
  95. package/build/src/cli/render/terminal.js +33 -21
  96. package/build/src/cli/render/value.d.ts +3 -0
  97. package/build/src/cli/render/value.js +24 -0
  98. package/build/src/cli/result.d.ts +11 -18
  99. package/build/src/cli/runtime.d.ts +0 -1
  100. package/build/src/cli/runtime.js +46 -31
  101. package/build/src/cli/usage.d.ts +15 -2
  102. package/build/src/cli/usage.js +59 -6
  103. package/build/src/contract-guidance.d.ts +1 -0
  104. package/build/src/contract-guidance.js +26 -2
  105. package/build/src/contract-worktree.js +2 -1
  106. package/build/src/core/facts/gate.d.ts +8 -1
  107. package/build/src/core/facts/gate.js +48 -6
  108. package/build/src/core/subject.d.ts +4 -3
  109. package/build/src/core/subject.js +6 -2
  110. package/build/src/dispatch/association.d.ts +1 -13
  111. package/build/src/dispatch/association.js +1 -20
  112. package/build/src/git/hooks.d.ts +1 -1
  113. package/build/src/git/hooks.js +10 -3
  114. package/build/src/git/result-codec.js +4 -1
  115. package/build/src/git/scratch.js +1 -1
  116. package/build/src/git/target-placement.d.ts +2 -2
  117. package/build/src/git/target-placement.js +21 -20
  118. package/build/src/git/terminal-reconcile.js +16 -9
  119. package/build/src/git/workspace.d.ts +18 -3
  120. package/build/src/git/workspace.js +21 -4
  121. package/build/src/index.d.ts +1 -1
  122. package/build/src/kanshi/read.js +3 -3
  123. package/build/src/library/address.js +2 -2
  124. package/build/src/library/akuma-creation.d.ts +6 -3
  125. package/build/src/library/akuma-creation.js +43 -23
  126. package/build/src/library/audit.js +11 -6
  127. package/build/src/library/catalog.js +2 -3
  128. package/build/src/library/composition.d.ts +1 -0
  129. package/build/src/library/continuation.d.ts +23 -31
  130. package/build/src/library/continuation.js +97 -99
  131. package/build/src/library/contract-bind.d.ts +2 -0
  132. package/build/src/library/contract-bind.js +31 -18
  133. package/build/src/library/contract-execution.d.ts +39 -0
  134. package/build/src/library/contract-execution.js +145 -0
  135. package/build/src/library/contract-forwarding.d.ts +9 -29
  136. package/build/src/library/contract-forwarding.js +14 -78
  137. package/build/src/library/contract-handle.js +38 -5
  138. package/build/src/library/contract-operations.d.ts +29 -0
  139. package/build/src/library/contract-operations.js +35 -2
  140. package/build/src/library/contract-types.d.ts +4 -0
  141. package/build/src/library/delivery.d.ts +2 -3
  142. package/build/src/library/delivery.js +3 -5
  143. package/build/src/library/execution-result.d.ts +243 -0
  144. package/build/src/library/execution-result.js +101 -0
  145. package/build/src/library/fleet.d.ts +3 -0
  146. package/build/src/library/fleet.js +6 -5
  147. package/build/src/library/keiyaku.d.ts +5 -4
  148. package/build/src/library/keiyaku.js +1 -0
  149. package/build/src/library/mutation.d.ts +121 -89
  150. package/build/src/library/mutation.js +109 -85
  151. package/build/src/library/reconcile.d.ts +7 -0
  152. package/build/src/library/reconcile.js +13 -0
  153. package/build/src/library/refusal.d.ts +6 -0
  154. package/build/src/library/refusal.js +40 -0
  155. package/build/src/plugin/public.d.ts +8 -0
  156. package/build/src/plugin/runtime.d.ts +2 -2
  157. package/build/src/plugin/runtime.js +31 -23
  158. package/build/src/protocol/attempt.d.ts +3 -1
  159. package/build/src/protocol/attempt.js +13 -5
  160. package/build/src/protocol/audit.d.ts +8 -1
  161. package/build/src/protocol/audit.js +17 -8
  162. package/build/src/protocol/completion.d.ts +20 -16
  163. package/build/src/protocol/completion.js +162 -136
  164. package/build/src/protocol/deliver.d.ts +17 -15
  165. package/build/src/protocol/deliver.js +107 -52
  166. package/build/src/protocol/intent.d.ts +5 -2
  167. package/build/src/protocol/intent.js +9 -2
  168. package/build/src/protocol/operations.d.ts +4 -4
  169. package/build/src/protocol/operations.js +3 -1
  170. package/build/src/protocol/outcome.d.ts +9 -0
  171. package/build/src/protocol/placement.d.ts +3 -1
  172. package/build/src/protocol/placement.js +13 -0
  173. package/build/src/protocol/progress.d.ts +82 -0
  174. package/build/src/protocol/progress.js +142 -0
  175. package/build/src/protocol/read/status.d.ts +27 -3
  176. package/build/src/protocol/read/status.js +40 -9
  177. package/build/src/protocol/reintegrate.d.ts +2 -0
  178. package/build/src/protocol/reintegrate.js +1 -0
  179. package/build/src/protocol/result-codec.d.ts +2 -1
  180. package/build/src/protocol/result-codec.js +79 -49
  181. package/build/src/protocol/review.d.ts +11 -7
  182. package/build/src/protocol/review.js +17 -27
  183. package/build/src/protocol/run.d.ts +2 -0
  184. package/build/src/protocol/run.js +1 -0
  185. package/build/src/runtime/proc/windows-launch.exe +0 -0
  186. package/build/src/settings.js +15 -4
  187. package/build/src/verification/execution.d.ts +2 -2
  188. package/build/src/verification/execution.js +2 -2
  189. package/build/src/workspace-place.d.ts +4 -0
  190. package/build/src/workspace-place.js +15 -7
  191. package/build/src/world.d.ts +2 -2
  192. package/build/src/world.js +20 -51
  193. package/package.json +2 -2
@@ -1,4 +1,4 @@
1
- import { activitySlice, isHeartAbsent, life, lifeAt, probeLeash, readHeart, readSeal, readSoul, } from "./heart/index.js";
1
+ import { activitySlice, HeldAkumaLeash, isHeartAbsent, life, lifeAt, probeLeash, readHeart, readSeal, readSoul, } from "./heart/index.js";
2
2
  import { pathsForAkuId } from "./identity.js";
3
3
  import { ordinarySnapshotBudget, projectTurns, selectHistory, selectSnapshot, } from "./projection.js";
4
4
  import { resolveProviderExecution } from "./providers/index.js";
@@ -6,7 +6,7 @@ import { AkumaNotBornError } from "./akuma-errors.js";
6
6
  export async function fleetListRow(paths, expected) {
7
7
  const snapshot = await readHeart(paths);
8
8
  if (snapshot.soul !== null)
9
- return await bornListRow(paths, expected, snapshot);
9
+ return (await bornObservation(paths, expected, snapshot)).row;
10
10
  try {
11
11
  if ((await probeLeash(paths)) === "held")
12
12
  return { id: expected, life: "unborn" };
@@ -19,33 +19,51 @@ export async function fleetListRow(paths, expected) {
19
19
  throw error;
20
20
  }
21
21
  }
22
- async function bornListRow(paths, expected, snapshot) {
22
+ async function bornObservation(paths, expected, snapshot) {
23
23
  snapshot ??= await readHeart(paths);
24
24
  if (snapshot.soul === null)
25
25
  throw new AkumaNotBornError(expected);
26
- if (snapshot.soul.id !== expected)
27
- throw new Error("Akuma soul does not match its coordinate");
28
- const currentLife = life({ leash: await probeLeash(paths), body: snapshot.latestBody, kill: snapshot.latestKill });
29
- return {
30
- id: snapshot.soul.id,
31
- archetype: snapshot.soul.archetype,
32
- ...(snapshot.soul.description === undefined ? {} : { description: snapshot.soul.description }),
33
- life: currentLife,
34
- lifeAt: lifeAt(currentLife, snapshot.latestBody, snapshot.latestKill, snapshot.soul.createdAt),
35
- lastActivityAt: snapshot.lastActivityAt,
36
- pending: snapshot.pending.map((tell) => tell.id),
37
- };
26
+ const claim = await HeldAkumaLeash.try(paths);
27
+ try {
28
+ // A Body may finish after the first read. Refresh under the free seat so
29
+ // neither its release nor a successor can manufacture an untidy observation.
30
+ if (claim !== null)
31
+ snapshot = await readHeart(paths);
32
+ const soul = snapshot.soul;
33
+ if (soul === null)
34
+ throw new AkumaNotBornError(expected);
35
+ if (soul.id !== expected)
36
+ throw new Error("Akuma soul does not match its coordinate");
37
+ const currentLife = life({
38
+ leash: claim === null ? "held" : "free",
39
+ body: snapshot.latestBody,
40
+ kill: snapshot.latestKill,
41
+ });
42
+ return {
43
+ snapshot,
44
+ soul,
45
+ row: {
46
+ id: soul.id,
47
+ archetype: soul.archetype,
48
+ ...(soul.description === undefined ? {} : { description: soul.description }),
49
+ life: currentLife,
50
+ lifeAt: lifeAt(currentLife, snapshot.latestBody, snapshot.latestKill, soul.createdAt),
51
+ lastActivityAt: snapshot.lastActivityAt,
52
+ pending: snapshot.pending.map((tell) => tell.id),
53
+ },
54
+ };
55
+ }
56
+ finally {
57
+ claim?.release();
58
+ }
38
59
  }
39
60
  export async function bornStatus(paths, expected, input) {
40
61
  if (input.ordinaryBudget !== undefined && (!Number.isSafeInteger(input.ordinaryBudget) || input.ordinaryBudget < 0))
41
62
  throw new TypeError("ordinary budget must be a nonnegative safe integer");
42
- const snapshot = await readHeart(paths);
43
- if (snapshot.soul === null)
44
- throw new AkumaNotBornError(expected);
45
- const current = await bornListRow(paths, expected, snapshot);
63
+ const { snapshot, soul, row: current } = await bornObservation(paths, expected);
46
64
  const resumeUnsupported = current.life === "stranded" &&
47
- snapshot.latestSession?.provider === snapshot.soul.provider.name &&
48
- (await resolveProviderExecution(snapshot.soul.provider)).adapter.resume === undefined;
65
+ snapshot.latestSession?.provider === soul.provider.name &&
66
+ (await resolveProviderExecution(soul.provider)).adapter.resume === undefined;
49
67
  const slice = await activitySlice(paths);
50
68
  const selected = selectSnapshot(projectTurns(slice.rows), {
51
69
  aperture: input.aperture,
@@ -56,7 +74,7 @@ export async function bornStatus(paths, expected, input) {
56
74
  status: {
57
75
  id: current.id,
58
76
  life: current.life,
59
- ...(snapshot.soul.readonly === undefined ? {} : { readonly: snapshot.soul.readonly }),
77
+ ...(soul.readonly === undefined ? {} : { readonly: soul.readonly }),
60
78
  ...(resumeUnsupported ? { strandedReason: "resume-unsupported" } : {}),
61
79
  timeline: selected.snapshot,
62
80
  },
@@ -20,7 +20,7 @@ export type BornAkumaCall = Readonly<{
20
20
  kind: "direct";
21
21
  };
22
22
  }>;
23
- initialBody: string;
23
+ initialBody?: string;
24
24
  initialSchemaJson?: string;
25
25
  execution: BornExecution;
26
26
  }>;
@@ -31,21 +31,23 @@ export type RequestedAkumaCall = Readonly<{
31
31
  execution: BornExecution;
32
32
  }>;
33
33
  export type AkumaBornCall = BornAkumaCall | RequestedAkumaCall;
34
- type AkumaCallLaunchInput = AkumaCallInput;
34
+ type AkumaCallLaunchInput = Omit<AkumaCallInput, "body"> & Readonly<{
35
+ body?: string;
36
+ }>;
35
37
  export declare const PAGE_POOL_SIZE = 16;
36
38
  export declare function boundedMap<Value, Result>(values: readonly Value[], mapper: (value: Value) => Promise<Result>): Promise<readonly Result[]>;
37
- export declare class Akuma {
39
+ declare class AkumaProduct {
38
40
  private readonly path;
39
41
  private readonly configuration;
40
42
  private constructor();
41
- static of(root: WorldRoot, input?: AkumaConfiguration): Akuma;
42
- of(input: Readonly<{
43
+ static create(root: WorldRoot, input?: AkumaConfiguration): AkumaProduct;
44
+ selectHandle(input: Readonly<{
43
45
  id: string;
44
46
  }>): AkumaHandle;
45
47
  listArchetypes(): Promise<readonly string[]>;
46
- call(input: AkumaCallLaunchInput): Promise<AkumaHandle>;
47
- beginCall(input: AkumaCallLaunchInput, context: AkumaCallContext): Promise<AkumaBornCall>;
48
- finishCall(born: AkumaBornCall, completion?: Readonly<{
48
+ invoke(input: AkumaCallLaunchInput): Promise<AkumaHandle>;
49
+ admit(input: AkumaCallLaunchInput, context: AkumaCallContext): Promise<AkumaBornCall>;
50
+ publish(born: AkumaBornCall, completion?: Readonly<{
49
51
  contractId?: string;
50
52
  }>): Promise<AkumaHandle>;
51
53
  [CALL_WITH_CONTEXT](input: AkumaCallLaunchInput, context: AkumaCallContext): Promise<AkumaHandle>;
@@ -54,4 +56,6 @@ export declare class Akuma {
54
56
  }>): Promise<AkumaCompleteList>;
55
57
  list(input?: AkumaListInput): Promise<AkumaList>;
56
58
  }
59
+ /** Internal composition product; the package exposes the smaller Akuma instance instead. */
60
+ export declare function createAkumaProduct(root: WorldRoot, input?: AkumaConfiguration): AkumaProduct;
57
61
  export {};
@@ -13,6 +13,55 @@ import { requestForwardedAkumaCall } from "./call-request.js";
13
13
  import { executionChannel } from "./requests.js";
14
14
  import { decodeAllowedActions, unionAllowedActions } from "./allowed.js";
15
15
  import { settings as readSettings } from "../settings.js";
16
+ import { schemaJsonText } from "./schema.js";
17
+ async function admitBodyRequest(input) {
18
+ const cwd = input.call.cwd === undefined
19
+ ? undefined
20
+ : input.context.cwdCanonical === true
21
+ ? input.call.cwd
22
+ : await canonicalBirthCwd(input.call.cwd);
23
+ const child = await requestForwardedAkumaCall({
24
+ directory: input.execution.directory,
25
+ id: randomUUID(),
26
+ world: input.path,
27
+ archetype: input.name,
28
+ ...(input.call.body === undefined ? {} : { body: input.call.body }),
29
+ ...(cwd === undefined ? {} : { cwd }),
30
+ recipe: input.recipe,
31
+ });
32
+ const bornCwd = await readAkumaBirthCwd(input.path, child);
33
+ return {
34
+ kind: "requested",
35
+ id: child,
36
+ cwd: bornCwd,
37
+ execution: { cwd: bornCwd, source: cwd === undefined ? "caller" : "input" },
38
+ };
39
+ }
40
+ async function admitDirect(input) {
41
+ const initiatorCwd = input.context.initiatorCwd;
42
+ const selectedCwd = input.call.cwd ?? initiatorCwd ?? input.path;
43
+ const cwd = input.call.cwd !== undefined && input.context.cwdCanonical === true
44
+ ? input.call.cwd
45
+ : await canonicalBirthCwd(selectedCwd);
46
+ const allocated = await birthAkuma({ worldPath: input.path, archetype: input.archetype.name });
47
+ return {
48
+ kind: "born",
49
+ allocated,
50
+ seed: {
51
+ id: allocated.id,
52
+ archetype: allocated.archetype,
53
+ ...input.recipe,
54
+ cwd,
55
+ origin: { kind: "direct" },
56
+ },
57
+ ...(input.call.body === undefined ? {} : { initialBody: input.call.body }),
58
+ ...(input.call.schema === undefined ? {} : { initialSchemaJson: schemaJsonText(input.call.schema) }),
59
+ execution: {
60
+ cwd,
61
+ source: input.call.cwd !== undefined ? "input" : initiatorCwd === undefined ? "world" : "process",
62
+ },
63
+ };
64
+ }
16
65
  export const PAGE_POOL_SIZE = 16;
17
66
  function activityAt(row) {
18
67
  if (!("lifeAt" in row))
@@ -106,19 +155,19 @@ async function readableRows(rows) {
106
155
  });
107
156
  return [...loaded].filter((row) => row !== null);
108
157
  }
109
- export class Akuma {
158
+ class AkumaProduct {
110
159
  path;
111
160
  configuration;
112
161
  constructor(path, configuration) {
113
162
  this.path = path;
114
163
  this.configuration = configuration;
115
164
  }
116
- static of(root, input = {}) {
165
+ static create(root, input = {}) {
117
166
  if (typeof root !== "string")
118
- throw new TypeError("Akuma.of root must be a WorldRoot");
119
- return new Akuma(root, input);
167
+ throw new TypeError("Akuma product root must be a WorldRoot");
168
+ return new AkumaProduct(root, input);
120
169
  }
121
- of(input) {
170
+ selectHandle(input) {
122
171
  return new AkumaHandle(parseAkuId(input.id).id, this.path);
123
172
  }
124
173
  async listArchetypes() {
@@ -127,10 +176,10 @@ export class Akuma {
127
176
  ...(this.configuration.home === undefined ? {} : { home: this.configuration.home }),
128
177
  });
129
178
  }
130
- async call(input) {
179
+ async invoke(input) {
131
180
  return await this[CALL_WITH_CONTEXT](input, { initiatorCwd: process.cwd() });
132
181
  }
133
- async beginCall(input, context) {
182
+ async admit(input, context) {
134
183
  const readonly = callReadonly(input.readonly);
135
184
  const name = archetypeName(input.archetype);
136
185
  const home = this.configuration.home === undefined ? {} : { home: this.configuration.home };
@@ -147,52 +196,11 @@ export class Akuma {
147
196
  ...(archetype.readonly === undefined ? {} : { readonly: archetype.readonly }),
148
197
  allowed,
149
198
  });
150
- if (execution.kind === "body-request") {
151
- const cwd = input.cwd === undefined
152
- ? undefined
153
- : context?.cwdCanonical === true
154
- ? input.cwd
155
- : await canonicalBirthCwd(input.cwd);
156
- const child = await requestForwardedAkumaCall({
157
- directory: execution.directory,
158
- id: randomUUID(),
159
- world: this.path,
160
- archetype: name,
161
- body: input.body,
162
- ...(cwd === undefined ? {} : { cwd }),
163
- recipe: requestRecipe,
164
- });
165
- const bornCwd = await readAkumaBirthCwd(this.path, child);
166
- return {
167
- kind: "requested",
168
- id: child,
169
- cwd: bornCwd,
170
- execution: { cwd: bornCwd, source: cwd === undefined ? "caller" : "input" },
171
- };
172
- }
173
- const initiatorCwd = context.initiatorCwd;
174
- const selectedCwd = input.cwd ?? initiatorCwd ?? this.path;
175
- const cwd = input.cwd !== undefined && context?.cwdCanonical === true ? input.cwd : await canonicalBirthCwd(selectedCwd);
176
- const allocated = await birthAkuma({ worldPath: this.path, archetype: archetype.name });
177
- return {
178
- kind: "born",
179
- allocated,
180
- seed: {
181
- id: allocated.id,
182
- archetype: allocated.archetype,
183
- ...requestRecipe,
184
- cwd,
185
- origin: { kind: "direct" },
186
- },
187
- initialBody: input.body,
188
- ...(input.schema === undefined ? {} : { initialSchemaJson: input.schema.jsonText }),
189
- execution: {
190
- cwd,
191
- source: input.cwd !== undefined ? "input" : initiatorCwd === undefined ? "world" : "process",
192
- },
193
- };
199
+ if (execution.kind === "body-request")
200
+ return await admitBodyRequest({ call: input, context, path: this.path, name, recipe: requestRecipe, execution });
201
+ return await admitDirect({ call: input, context, path: this.path, archetype, recipe: requestRecipe });
194
202
  }
195
- async finishCall(born, completion = {}) {
203
+ async publish(born, completion = {}) {
196
204
  if (born.kind === "requested") {
197
205
  return new AkumaHandle(born.id, this.path, { cwd: born.cwd, source: born.execution.source });
198
206
  }
@@ -201,7 +209,7 @@ export class Akuma {
201
209
  launch: async (allocated) => await spawnAkumaBody({
202
210
  paths: allocated.paths,
203
211
  seed: born.seed,
204
- initialBody: born.initialBody,
212
+ ...(born.initialBody === undefined ? {} : { initialBody: born.initialBody }),
205
213
  ...(born.initialSchemaJson === undefined ? {} : { initialSchemaJson: born.initialSchemaJson }),
206
214
  ...(Object.keys(completion).length === 0 ? {} : { completion }),
207
215
  }),
@@ -212,7 +220,7 @@ export class Akuma {
212
220
  });
213
221
  }
214
222
  async [CALL_WITH_CONTEXT](input, context) {
215
- return await this.finishCall(await this.beginCall(input, context));
223
+ return await this.publish(await this.admit(input, context));
216
224
  }
217
225
  async listComplete(input = {}) {
218
226
  if (typeof input !== "object" || input === null || Array.isArray(input))
@@ -270,3 +278,7 @@ export class Akuma {
270
278
  };
271
279
  }
272
280
  }
281
+ /** Internal composition product; the package exposes the smaller Akuma instance instead. */
282
+ export function createAkumaProduct(root, input = {}) {
283
+ return AkumaProduct.create(root, input);
284
+ }
@@ -1,7 +1,6 @@
1
- import { type TellResult, type TellWakeRuntime } from "./body.js";
2
- import { HeldAkumaLeash, type AkumaLife, type KillEvidence, type ResumeCoordinate } from "./heart/index.js";
1
+ import { type AkumaLife, type KillEvidence, type ResumeCoordinate } from "./heart/index.js";
3
2
  export type { KillEvidence };
4
- import { type AkuId, type AkumaPaths } from "./identity.js";
3
+ import { type AkuId } from "./identity.js";
5
4
  import type { Settings } from "../settings.js";
6
5
  import type { WorldRoot } from "../world.js";
7
6
  import type { AllowedAction } from "./allowed.js";
@@ -9,6 +8,9 @@ import type { ExecutionContext } from "./requests.js";
9
8
  import { z } from "zod";
10
9
  import type { BoundedList } from "../bounded-list.js";
11
10
  import type { Schema } from "./schema.js";
11
+ import { killAkumaWithRecovery } from "./akuma-handle.js";
12
+ import type { TellResult } from "./body.js";
13
+ export { killAkumaWithRecovery };
12
14
  export declare const POLL_MS = 100;
13
15
  export type AkumaListRow = Readonly<{
14
16
  id: AkuId;
@@ -431,7 +433,6 @@ export type AkumaCallExecution = Readonly<{
431
433
  cwd: string;
432
434
  source: "input" | "caller" | "process" | "world";
433
435
  }>;
434
- export { CALL_WITH_CONTEXT } from "./akuma-product-symbols.js";
435
436
  export type AkumaCallInput = Readonly<{
436
437
  archetype: string;
437
438
  body: string;
@@ -472,27 +473,14 @@ export type ForkReceipt = Readonly<{
472
473
  }>;
473
474
  export { AkumaNotBornError } from "./akuma-errors.js";
474
475
  export declare function wait(milliseconds: number): Promise<void>;
475
- export declare function takeLeashUntil(paths: AkumaPaths, deadline: number): Promise<HeldAkumaLeash | null>;
476
- export declare function recordTellBody(paths: AkumaPaths, akuma: AkuId, body: string, id?: string, recordedAt?: string): Promise<Readonly<{
477
- kind: "recorded";
478
- tellId: string;
479
- }>>;
480
- export declare function tellAkumaWithId(input: Readonly<{
481
- worldPath: WorldRoot;
482
- id: AkuId;
483
- body: string;
484
- tellId: string;
485
- recordedAt?: string;
486
- runtime?: TellWakeRuntime;
487
- }>): Promise<TellResult>;
488
- export declare function diagnostic(error: unknown): string;
489
- export declare function killAkumaWithRecovery(paths: AkumaPaths, recover?: (paths: AkumaPaths) => Promise<void>): Promise<KillEvidence>;
490
476
  export { bornStatus, fleetListRow, readAkumaBirthCwd, readBudgetedStatus, type BudgetedStatusObservation, } from "./akuma-observe.js";
491
477
  export type AkumaConfiguration = Readonly<{
492
478
  home?: string;
493
479
  settings?: Settings;
494
480
  execution?: ExecutionContext;
495
481
  }>;
496
- export { AkumaHandle, akumaCallExecution, type LastAnswer } from "./akuma-handle.js";
497
- export { Akuma } from "./akuma-product.js";
482
+ /** Internal catalog observation for composition owners. */
483
+ export declare function readAkumaCatalog(path: WorldRoot, input?: AkumaListInput): Promise<AkumaList>;
484
+ /** Internal timeline observation for composition owners. */
485
+ export declare function readAkumaTimeline(path: WorldRoot, id: AkuId): Promise<AkumaStatus["timeline"]>;
498
486
  export { AkumaBusyError, AkumaDecodeError, AkumaProviderError } from "./akuma-errors.js";
@@ -1,9 +1,9 @@
1
- import { randomUUID } from "node:crypto";
2
- import { CONTROL_RESPONSE_MS, handoffPendingTells, wakeRecordedTell, } from "./body.js";
3
- import { HeldAkumaLeash, readHeart, readKill, recordTell, requestStop, } from "./heart/index.js";
4
- import { parseAkuId, pathsForAkuId } from "./identity.js";
1
+ import { parseAkuId } from "./identity.js";
5
2
  import { activitySnapshotSchema } from "./projection.js";
6
3
  import { z } from "zod";
4
+ import { createAkumaProduct } from "./akuma-product.js";
5
+ import { killAkumaWithRecovery } from "./akuma-handle.js";
6
+ export { killAkumaWithRecovery };
7
7
  export const POLL_MS = 100;
8
8
  export const akumaIdSchema = z.string().transform((value, context) => {
9
9
  try {
@@ -38,73 +38,17 @@ export function defaultWaitComplete(status) {
38
38
  return (status.life !== "running" &&
39
39
  !status.timeline.entries.some((entry) => entry.kind === "row" && entry.row.kind === "tell" && entry.row.state === "pending"));
40
40
  }
41
- export { CALL_WITH_CONTEXT } from "./akuma-product-symbols.js";
42
41
  export { AkumaNotBornError } from "./akuma-errors.js";
43
- import { AkumaNotBornError } from "./akuma-errors.js";
44
42
  export function wait(milliseconds) {
45
43
  return new Promise((resolve) => setTimeout(resolve, milliseconds));
46
44
  }
47
- export async function takeLeashUntil(paths, deadline) {
48
- for (;;) {
49
- const leash = await HeldAkumaLeash.try(paths);
50
- if (leash !== null)
51
- return leash;
52
- if (performance.now() >= deadline)
53
- return null;
54
- await wait(Math.min(POLL_MS, Math.max(0, deadline - performance.now())));
55
- }
56
- }
57
- export async function recordTellBody(paths, akuma, body, id = randomUUID(), recordedAt = new Date().toISOString()) {
58
- const admitted = await recordTell(paths, { kind: "tell", id, body, recordedAt });
59
- if (admitted.kind === "not-born")
60
- throw new AkumaNotBornError(akuma);
61
- return { kind: "recorded", tellId: admitted.tell.id };
62
- }
63
- export async function tellAkumaWithId(input) {
64
- const paths = pathsForAkuId(input.worldPath, input.id);
65
- const recorded = await recordTellBody(paths, input.id, input.body, input.tellId, input.recordedAt);
66
- return await wakeRecordedTell(paths, recorded.tellId, input.runtime);
45
+ export { bornStatus, fleetListRow, readAkumaBirthCwd, readBudgetedStatus, } from "./akuma-observe.js";
46
+ /** Internal catalog observation for composition owners. */
47
+ export async function readAkumaCatalog(path, input = {}) {
48
+ return await createAkumaProduct(path).list(input);
67
49
  }
68
- export function diagnostic(error) {
69
- return error instanceof Error ? error.message : String(error);
50
+ /** Internal timeline observation for composition owners. */
51
+ export async function readAkumaTimeline(path, id) {
52
+ return (await createAkumaProduct(path).selectHandle({ id }).status()).timeline;
70
53
  }
71
- export async function killAkumaWithRecovery(paths, recover = handoffPendingTells) {
72
- try {
73
- const request = await requestStop(paths, new Date().toISOString());
74
- if (request.kind !== "requested")
75
- return request.kind;
76
- const target = request.body;
77
- const leash = await takeLeashUntil(paths, performance.now() + CONTROL_RESPONSE_MS);
78
- if ((await readKill(paths, target.sequence)) !== null) {
79
- leash?.release();
80
- return "killed";
81
- }
82
- if (leash === null) {
83
- if ((await readKill(paths, target.sequence)) !== null)
84
- return "killed";
85
- const body = (await readHeart(paths)).latestBody;
86
- return body?.sequence === target.sequence && body.hung !== undefined ? "hung" : "unavailable";
87
- }
88
- try {
89
- const settledBody = (await readHeart(paths)).latestBody;
90
- if (settledBody?.sequence !== target.sequence)
91
- return (await readKill(paths, target.sequence)) === null ? "unavailable" : "killed";
92
- if (settledBody.end !== "put-down") {
93
- await leash.clearStop(paths);
94
- return "untidy";
95
- }
96
- const settled = await leash.settleStop(paths, target.sequence);
97
- return settled === null ? "unavailable" : "killed";
98
- }
99
- finally {
100
- leash.release();
101
- }
102
- }
103
- finally {
104
- void recover(paths).catch(() => undefined);
105
- }
106
- }
107
- export { bornStatus, fleetListRow, readAkumaBirthCwd, readBudgetedStatus, } from "./akuma-observe.js";
108
- export { AkumaHandle, akumaCallExecution } from "./akuma-handle.js";
109
- export { Akuma } from "./akuma-product.js";
110
54
  export { AkumaBusyError, AkumaDecodeError, AkumaProviderError } from "./akuma-errors.js";