@astrosheep/keiyaku 4.6.7 → 4.6.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 (165) hide show
  1. package/README.md +6 -2
  2. package/build/plugins/pi/keiyaku.ts +0 -5
  3. package/build/src/akuma/akuma-call.d.ts +2 -0
  4. package/build/src/akuma/akuma-call.js +8 -2
  5. package/build/src/akuma/akuma-instance.d.ts +12 -1
  6. package/build/src/akuma/akuma-instance.js +27 -7
  7. package/build/src/akuma/akuma-observe.js +2 -0
  8. package/build/src/akuma/akuma-owner.d.ts +3 -0
  9. package/build/src/akuma/akuma-owner.js +4 -0
  10. package/build/src/akuma/akuma.d.ts +35 -5
  11. package/build/src/akuma/akuma.js +8 -10
  12. package/build/src/akuma/archetype.d.ts +7 -15
  13. package/build/src/akuma/archetype.js +36 -35
  14. package/build/src/akuma/body.d.ts +5 -3
  15. package/build/src/akuma/body.js +29 -7
  16. package/build/src/akuma/call-request.d.ts +18 -10
  17. package/build/src/akuma/call-request.js +10 -3
  18. package/build/src/akuma/caller.d.ts +39 -0
  19. package/build/src/akuma/caller.js +36 -0
  20. package/build/src/akuma/dispatch-association.d.ts +0 -1
  21. package/build/src/akuma/dispatch-association.js +0 -3
  22. package/build/src/akuma/heart/facts.d.ts +16 -12
  23. package/build/src/akuma/heart/facts.js +8 -0
  24. package/build/src/akuma/heart/index.d.ts +2 -7
  25. package/build/src/akuma/heart/index.js +3 -17
  26. package/build/src/akuma/heart/rows.d.ts +3 -3
  27. package/build/src/akuma/heart/soul.d.ts +1 -1
  28. package/build/src/akuma/heart/soul.js +5 -24
  29. package/build/src/akuma/heart/storage.d.ts +5 -0
  30. package/build/src/akuma/heart/storage.js +7 -3
  31. package/build/src/akuma/identity.d.ts +0 -1
  32. package/build/src/akuma/identity.js +2 -5
  33. package/build/src/akuma/index.d.ts +5 -2
  34. package/build/src/akuma/index.js +1 -0
  35. package/build/src/akuma/nuke.js +6 -28
  36. package/build/src/akuma/projection.d.ts +0 -11
  37. package/build/src/akuma/provider-recipe.d.ts +7 -6
  38. package/build/src/akuma/provider-recipe.js +1 -1
  39. package/build/src/akuma/provider.d.ts +6 -10
  40. package/build/src/akuma/provider.js +6 -7
  41. package/build/src/akuma/providers/acp/events.js +5 -18
  42. package/build/src/akuma/providers/acp/index.js +2 -3
  43. package/build/src/akuma/providers/claude/events.js +35 -60
  44. package/build/src/akuma/providers/claude/index.d.ts +2 -2
  45. package/build/src/akuma/providers/claude/index.js +2 -3
  46. package/build/src/akuma/providers/codex-app-server/index.js +2 -2
  47. package/build/src/akuma/providers/decode.d.ts +25 -0
  48. package/build/src/akuma/providers/decode.js +44 -0
  49. package/build/src/akuma/providers/execution-environment.d.ts +2 -1
  50. package/build/src/akuma/providers/execution-environment.js +3 -0
  51. package/build/src/akuma/providers/grok-build/index.js +6 -22
  52. package/build/src/akuma/providers/index.js +2 -0
  53. package/build/src/akuma/providers/lifecycle.d.ts +9 -0
  54. package/build/src/akuma/providers/lifecycle.js +10 -0
  55. package/build/src/akuma/providers/opencode-sdk/events.js +1 -14
  56. package/build/src/akuma/providers/opencode-sdk/index.js +10 -17
  57. package/build/src/akuma/providers/opencode-sdk/session.js +1 -3
  58. package/build/src/akuma/providers/paseo/events.d.ts +25 -0
  59. package/build/src/akuma/providers/paseo/events.js +157 -0
  60. package/build/src/akuma/providers/paseo/index.d.ts +9 -0
  61. package/build/src/akuma/providers/paseo/index.js +353 -0
  62. package/build/src/akuma/providers/pi/events.js +5 -15
  63. package/build/src/akuma/publication.d.ts +2 -0
  64. package/build/src/akuma/publication.js +5 -0
  65. package/build/src/akuma/request-lifecycle.d.ts +3 -0
  66. package/build/src/akuma/request-lifecycle.js +25 -4
  67. package/build/src/akuma/requests.d.ts +3 -1
  68. package/build/src/akuma/requests.js +32 -0
  69. package/build/src/akuma/selection-observation.d.ts +72 -2
  70. package/build/src/akuma/selection-observation.js +0 -6
  71. package/build/src/akuma/turn-drive.js +2 -5
  72. package/build/src/cli/akuma-caller.d.ts +3 -0
  73. package/build/src/cli/akuma-caller.js +21 -0
  74. package/build/src/cli/commands/akuma-grammar.js +7 -12
  75. package/build/src/cli/commands/akuma.js +12 -4
  76. package/build/src/cli/commands/contract-grammar.d.ts +2 -1
  77. package/build/src/cli/commands/contract-grammar.js +13 -15
  78. package/build/src/cli/commands/contract-help.d.ts +2 -1
  79. package/build/src/cli/commands/contract-help.js +31 -1
  80. package/build/src/cli/commands/contract.js +24 -53
  81. package/build/src/cli/commands/task.js +18 -35
  82. package/build/src/cli/parse.d.ts +2 -2
  83. package/build/src/cli/render/catalog.d.ts +2 -5
  84. package/build/src/cli/render/contract-history.js +3 -6
  85. package/build/src/cli/render/contract.js +15 -50
  86. package/build/src/cli/render/receipt.js +3 -10
  87. package/build/src/cli/render/task.d.ts +4 -6
  88. package/build/src/cli/render/task.js +9 -26
  89. package/build/src/cli/runtime.d.ts +1 -1
  90. package/build/src/cli/runtime.js +11 -17
  91. package/build/src/cli/selectors.d.ts +3 -6
  92. package/build/src/cli/selectors.js +22 -53
  93. package/build/src/dispatch/index.d.ts +3 -3
  94. package/build/src/dispatch/index.js +1 -2
  95. package/build/src/git/observe.d.ts +6 -2
  96. package/build/src/git/observe.js +6 -2
  97. package/build/src/index.d.ts +6 -6
  98. package/build/src/index.js +2 -2
  99. package/build/src/kanshi/index.d.ts +1 -1
  100. package/build/src/kanshi/read.js +21 -6
  101. package/build/src/library/address.js +2 -4
  102. package/build/src/library/akuma-creation.d.ts +5 -1
  103. package/build/src/library/akuma-creation.js +27 -47
  104. package/build/src/library/akumas.d.ts +5 -4
  105. package/build/src/library/akumas.js +13 -9
  106. package/build/src/library/bind.d.ts +14 -14
  107. package/build/src/library/bind.js +11 -7
  108. package/build/src/library/contract-address.d.ts +9 -0
  109. package/build/src/library/contract-address.js +71 -0
  110. package/build/src/library/contract-composition.d.ts +4 -7
  111. package/build/src/library/contract-composition.js +6 -18
  112. package/build/src/library/contract-creation.d.ts +3 -5
  113. package/build/src/library/contract-creation.js +19 -17
  114. package/build/src/library/contract-execution.js +18 -23
  115. package/build/src/library/contract-outcomes.d.ts +2 -14
  116. package/build/src/library/contract-outcomes.js +2 -13
  117. package/build/src/library/contract-types.d.ts +36 -2
  118. package/build/src/library/delivery.d.ts +0 -2
  119. package/build/src/library/delivery.js +2 -5
  120. package/build/src/library/keiyaku.d.ts +0 -5
  121. package/build/src/library/keiyaku.js +6 -12
  122. package/build/src/library/outcome.d.ts +500 -499
  123. package/build/src/library/outcome.js +10 -0
  124. package/build/src/library/reconcile.js +8 -16
  125. package/build/src/library/refusal.d.ts +2 -2
  126. package/build/src/library/repo.d.ts +3 -2
  127. package/build/src/library/repo.js +10 -5
  128. package/build/src/library/selection.d.ts +4 -4
  129. package/build/src/library/selection.js +12 -12
  130. package/build/src/plugin/akuma-signals.d.ts +2 -0
  131. package/build/src/plugin/akuma-signals.js +4 -0
  132. package/build/src/plugin/public.d.ts +27 -2
  133. package/build/src/plugin/runtime.js +2 -2
  134. package/build/src/protocol/amend.js +3 -2
  135. package/build/src/protocol/attempt.js +3 -8
  136. package/build/src/protocol/bind.d.ts +2 -2
  137. package/build/src/protocol/bind.js +1 -1
  138. package/build/src/protocol/deliver.js +3 -3
  139. package/build/src/protocol/operations.d.ts +1 -3
  140. package/build/src/protocol/operations.js +0 -8
  141. package/build/src/protocol/outcome.d.ts +1 -2
  142. package/build/src/protocol/outcome.js +1 -13
  143. package/build/src/protocol/placement.js +3 -10
  144. package/build/src/protocol/read/status.js +31 -70
  145. package/build/src/protocol/reintegrate.js +3 -10
  146. package/build/src/protocol/review.js +3 -3
  147. package/build/src/protocol/run.d.ts +5 -1
  148. package/build/src/protocol/run.js +3 -3
  149. package/build/src/runtime/proc/windows-launch.exe +0 -0
  150. package/package.json +8 -4
  151. package/plugins/pi/keiyaku.ts +57 -0
  152. package/skills/keiyaku/SKILL.md +44 -0
  153. package/skills/keiyaku-akuma/SKILL.md +130 -0
  154. package/skills/keiyaku-akuma/references/automation.md +269 -0
  155. package/skills/keiyaku-babysit/SKILL.md +65 -0
  156. package/skills/keiyaku-bind/SKILL.md +216 -0
  157. package/skills/keiyaku-bind/agents/openai.yaml +4 -0
  158. package/skills/keiyaku-task/SKILL.md +104 -0
  159. package/skills/keiyaku-workflow/SKILL.md +129 -0
  160. package/build/src/cli/commands/amend.d.ts +0 -12
  161. package/build/src/cli/commands/amend.js +0 -10
  162. package/build/src/cli/commands/bind.d.ts +0 -11
  163. package/build/src/cli/commands/bind.js +0 -23
  164. package/build/src/dispatch/association.d.ts +0 -1
  165. package/build/src/dispatch/association.js +0 -1
@@ -1,3 +1,4 @@
1
+ import { projectAkumaBirth } from "./caller.js";
1
2
  import { z } from "zod";
2
3
  import { decodeSoulSeed } from "./heart/soul.js";
3
4
  import { sessionAdmissionSchema } from "./heart/rows.js";
@@ -35,6 +36,7 @@ export const bodyLaunchSchema = z
35
36
  birthSession: sessionAdmissionSchema.optional(),
36
37
  initialBody: z.string().optional(),
37
38
  initiator: z.string().optional(),
39
+ birthInitiator: z.string().optional(),
38
40
  initialSchemaJson: z.string().optional(),
39
41
  refuseIfHeld: z.boolean().optional(),
40
42
  completion: z.object({ contractId: z.string().optional() }).strict().optional(),
@@ -74,17 +76,18 @@ async function takeLeash(paths, refuseIfHeld = false) {
74
76
  async function bornSoul(launch, leash, now) {
75
77
  const before = await readHeart(launch.paths);
76
78
  if (before.soul !== null)
77
- return before.soul;
79
+ return { soul: before.soul, created: false };
78
80
  if (launch.seed === undefined)
79
81
  throw new Error("Akuma wake has no born soul");
80
82
  const candidate = { ...launch.seed, createdAt: now };
81
- if ((await leash.birth(launch.paths, candidate, launch.birthSession)) === "sealed")
83
+ const result = await leash.birth(launch.paths, candidate, launch.birthSession);
84
+ if (result === "sealed")
82
85
  return null;
83
86
  const born = (await readHeart(launch.paths)).soul;
84
87
  if (born === null || born.id !== candidate.id) {
85
88
  throw new Error("Akuma birth identity does not match its directory");
86
89
  }
87
- return born;
90
+ return { soul: born, created: result === "born" };
88
91
  }
89
92
  async function launchCwd(launch) {
90
93
  if (launch.seed !== undefined)
@@ -233,14 +236,18 @@ export async function bodyProcessInput(launch, bodyModuleUrl = import.meta.url)
233
236
  return {
234
237
  argv: source ? [executable, "--import", import.meta.resolve("tsx"), entry, encoded] : [executable, entry, encoded],
235
238
  cwd: await launchCwd(launch),
236
- env: akumaExecutionEnvironment(process.env, { KEIYAKU_ACTOR_ID: actorId }),
239
+ env: akumaExecutionEnvironment(process.env, {
240
+ KEIYAKU_ACTOR_ID: actorId,
241
+ KEIYAKU_ACTOR_WORLD: worldRootForAkumaPaths(launch.paths),
242
+ }),
237
243
  log: launch.paths.log,
238
244
  };
239
245
  }
240
246
  async function prepareBodyExecution(launch, leash, runtime, adapter) {
241
- const soul = await bornSoul(launch, leash, runtime.now());
242
- if (soul === null)
247
+ const birth = await bornSoul(launch, leash, runtime.now());
248
+ if (birth === null)
243
249
  return null;
250
+ const { soul } = birth;
244
251
  if (launch.seed === undefined && launch.initialBody === undefined) {
245
252
  const [heart, requests] = await Promise.all([readHeart(launch.paths), readNonterminalRequests(launch.paths)]);
246
253
  if (heart.pending.length === 0 && requests.length === 0)
@@ -249,7 +256,7 @@ async function prepareBodyExecution(launch, leash, runtime, adapter) {
249
256
  const selected = adapter ?? (await resolveProviderExecution(soul.provider)).adapter;
250
257
  if (!(await prepareBodyStart(launch.paths, leash)))
251
258
  return null;
252
- return { soul, adapter: selected };
259
+ return { ...birth, adapter: selected };
253
260
  }
254
261
  async function runPreparedBody(input) {
255
262
  let pendingTellDisposition;
@@ -568,6 +575,21 @@ export async function driveAkumaBody(launch, adapter, runtimeInput = {}) {
568
575
  emitTurnOutcome = turnOutcomeEmitter(launch, prepared.soul, world);
569
576
  const body = await leash.recordBody(launch.paths, { leashTakenAt: runtime.now() });
570
577
  bodySequence = body.sequence;
578
+ if (prepared.created) {
579
+ await emitPluginSignal({
580
+ world,
581
+ reportDiagnostic: (message) => {
582
+ void recordPluginDiagnostic(launch.paths, "birth", message);
583
+ },
584
+ }, {
585
+ kind: "akuma.born",
586
+ akumaId: prepared.soul.id,
587
+ bodySequence: body.sequence,
588
+ ...projectAkumaBirth(prepared.soul),
589
+ ...(launch.birthInitiator === undefined ? {} : { initiator: launch.birthInitiator }),
590
+ ...(launch.completion?.contractId === undefined ? {} : { contractId: launch.completion.contractId }),
591
+ });
592
+ }
571
593
  const supervisor = await BodySupervisor.open(launch.paths, body.sequence, leash);
572
594
  pendingTellDisposition = await runPreparedBody({
573
595
  launch,
@@ -33,6 +33,7 @@ declare const akumaCallRecipeSchema: z.ZodObject<{
33
33
  "codex-app-server": "codex-app-server";
34
34
  "grok-build": "grok-build";
35
35
  "opencode-sdk": "opencode-sdk";
36
+ paseo: "paseo";
36
37
  pi: "pi";
37
38
  }>;
38
39
  executable: z.ZodOptional<z.ZodString>;
@@ -43,10 +44,10 @@ declare const akumaCallRecipeSchema: z.ZodObject<{
43
44
  config?: Readonly<Record<string, unknown>>;
44
45
  executable?: string;
45
46
  name: string;
46
- kind: "acp" | "claude-agent-sdk" | "codex-app-server" | "grok-build" | "opencode-sdk" | "pi";
47
+ kind: "acp" | "claude-agent-sdk" | "codex-app-server" | "grok-build" | "opencode-sdk" | "paseo" | "pi";
47
48
  }>, {
48
49
  name: string;
49
- kind: "acp" | "claude-agent-sdk" | "codex-app-server" | "grok-build" | "opencode-sdk" | "pi";
50
+ kind: "acp" | "claude-agent-sdk" | "codex-app-server" | "grok-build" | "opencode-sdk" | "paseo" | "pi";
50
51
  executable?: string | undefined;
51
52
  config?: Record<string, unknown> | undefined;
52
53
  env?: Record<string, string> | undefined;
@@ -60,11 +61,11 @@ declare const akumaCallRecipeSchema: z.ZodObject<{
60
61
  }>>;
61
62
  systemPrompt: z.ZodOptional<z.ZodString>;
62
63
  systemPromptMode: z.ZodOptional<z.ZodEnum<{
63
- append: "append";
64
64
  replace: "replace";
65
+ append: "append";
65
66
  }>>;
66
67
  }, z.core.$strip>, z.ZodTransform<Readonly<{
67
- systemPromptMode?: "append" | "replace";
68
+ systemPromptMode?: "replace" | "append";
68
69
  systemPrompt?: string;
69
70
  network?: "disabled" | "enabled";
70
71
  effort?: string;
@@ -74,7 +75,7 @@ declare const akumaCallRecipeSchema: z.ZodObject<{
74
75
  effort?: string | undefined;
75
76
  network?: "disabled" | "enabled" | undefined;
76
77
  systemPrompt?: string | undefined;
77
- systemPromptMode?: "append" | "replace" | undefined;
78
+ systemPromptMode?: "replace" | "append" | undefined;
78
79
  }>>;
79
80
  }, z.core.$strict>;
80
81
  declare const akumaCallPayloadSchema: z.ZodObject<{
@@ -86,6 +87,8 @@ declare const akumaCallPayloadSchema: z.ZodObject<{
86
87
  schemaJson: z.ZodOptional<z.ZodString>;
87
88
  initiator: z.ZodOptional<z.ZodString>;
88
89
  }, z.core.$strict>>;
90
+ birthInitiator: z.ZodOptional<z.ZodString>;
91
+ contractId: z.ZodOptional<z.ZodString>;
89
92
  cwd: z.ZodOptional<z.ZodString>;
90
93
  recipe: z.ZodObject<{
91
94
  description: z.ZodOptional<z.ZodString>;
@@ -115,6 +118,7 @@ declare const akumaCallPayloadSchema: z.ZodObject<{
115
118
  "codex-app-server": "codex-app-server";
116
119
  "grok-build": "grok-build";
117
120
  "opencode-sdk": "opencode-sdk";
121
+ paseo: "paseo";
118
122
  pi: "pi";
119
123
  }>;
120
124
  executable: z.ZodOptional<z.ZodString>;
@@ -125,10 +129,10 @@ declare const akumaCallPayloadSchema: z.ZodObject<{
125
129
  config?: Readonly<Record<string, unknown>>;
126
130
  executable?: string;
127
131
  name: string;
128
- kind: "acp" | "claude-agent-sdk" | "codex-app-server" | "grok-build" | "opencode-sdk" | "pi";
132
+ kind: "acp" | "claude-agent-sdk" | "codex-app-server" | "grok-build" | "opencode-sdk" | "paseo" | "pi";
129
133
  }>, {
130
134
  name: string;
131
- kind: "acp" | "claude-agent-sdk" | "codex-app-server" | "grok-build" | "opencode-sdk" | "pi";
135
+ kind: "acp" | "claude-agent-sdk" | "codex-app-server" | "grok-build" | "opencode-sdk" | "paseo" | "pi";
132
136
  executable?: string | undefined;
133
137
  config?: Record<string, unknown> | undefined;
134
138
  env?: Record<string, string> | undefined;
@@ -142,11 +146,11 @@ declare const akumaCallPayloadSchema: z.ZodObject<{
142
146
  }>>;
143
147
  systemPrompt: z.ZodOptional<z.ZodString>;
144
148
  systemPromptMode: z.ZodOptional<z.ZodEnum<{
145
- append: "append";
146
149
  replace: "replace";
150
+ append: "append";
147
151
  }>>;
148
152
  }, z.core.$strip>, z.ZodTransform<Readonly<{
149
- systemPromptMode?: "append" | "replace";
153
+ systemPromptMode?: "replace" | "append";
150
154
  systemPrompt?: string;
151
155
  network?: "disabled" | "enabled";
152
156
  effort?: string;
@@ -156,7 +160,7 @@ declare const akumaCallPayloadSchema: z.ZodObject<{
156
160
  effort?: string | undefined;
157
161
  network?: "disabled" | "enabled" | undefined;
158
162
  systemPrompt?: string | undefined;
159
- systemPromptMode?: "append" | "replace" | undefined;
163
+ systemPromptMode?: "replace" | "append" | undefined;
160
164
  }>>;
161
165
  }, z.core.$strict>;
162
166
  }, z.core.$strict>;
@@ -167,6 +171,10 @@ export type AkumaCallRequest = z.infer<typeof akumaCallPayloadSchema> & Readonly
167
171
  export type AkumaCallRequestChildLaunch = Readonly<{
168
172
  paths: AkumaPaths;
169
173
  seed: Omit<Soul, "createdAt">;
174
+ birthInitiator?: string;
175
+ completion?: Readonly<{
176
+ contractId?: string;
177
+ }>;
170
178
  }>;
171
179
  export type InitialTellAdmissionRequest = Readonly<{
172
180
  id: AkuId;
@@ -1,7 +1,8 @@
1
1
  import { isAbsolute, resolve } from "node:path";
2
2
  import { allowedActionsSchema } from "./allowed.js";
3
3
  import { refuseRequest, reserveRequest } from "./heart/index.js";
4
- import { archetypeName, akumaIdSchema } from "./identity.js";
4
+ import { validateAkumaName } from "../identity/normalize.js";
5
+ import { akumaIdSchema } from "./identity.js";
5
6
  import { callDiagnostic, executePreparedCall } from "./publication.js";
6
7
  import { tellResultSchema } from "./call-initial-tell.js";
7
8
  import { providerOptionsSchema, providerRecipeSchema } from "./provider-recipe.js";
@@ -11,7 +12,7 @@ import { z } from "zod";
11
12
  const absolutePathSchema = z.string().refine((value) => isAbsolute(value) && resolve(value) === value);
12
13
  const archetypeSchema = z.string().transform((value, context) => {
13
14
  try {
14
- return archetypeName(value);
15
+ return validateAkumaName(value);
15
16
  }
16
17
  catch {
17
18
  context.addIssue({ code: "custom", message: "expected Akuma name" });
@@ -39,6 +40,8 @@ const akumaCallPayloadSchema = z
39
40
  world: absolutePathSchema,
40
41
  archetype: archetypeSchema,
41
42
  initialTell: initialTellSchema.optional(),
43
+ birthInitiator: z.string().optional(),
44
+ contractId: z.string().optional(),
42
45
  cwd: absolutePathSchema.optional(),
43
46
  recipe: akumaCallRecipeSchema,
44
47
  })
@@ -95,7 +98,11 @@ async function executeAkumaCall(request, facts, capabilities) {
95
98
  refuse: async (diagnostic) => {
96
99
  await refuseRequest(paths, facts.id, diagnostic);
97
100
  },
98
- spawn,
101
+ spawn: async (launch) => await spawn({
102
+ ...launch,
103
+ ...(request.birthInitiator === undefined ? {} : { birthInitiator: request.birthInitiator }),
104
+ ...(request.contractId === undefined ? {} : { completion: { contractId: request.contractId } }),
105
+ }),
99
106
  admitInitialTell,
100
107
  },
101
108
  });
@@ -0,0 +1,39 @@
1
+ import { z } from "zod";
2
+ import type { WorldRoot } from "../world.js";
3
+ import { type Soul } from "./heart/facts.js";
4
+ export declare const akumaCallerSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
5
+ kind: z.ZodLiteral<"akuma">;
6
+ world: z.ZodCustom<WorldRoot, WorldRoot>;
7
+ akuId: z.ZodPipe<z.ZodString, z.ZodTransform<import("./identity.js").AkuId, string>>;
8
+ }, z.core.$strict>, z.ZodObject<{
9
+ kind: z.ZodLiteral<"external">;
10
+ integration: z.ZodString;
11
+ id: z.ZodString;
12
+ }, z.core.$strict>], "kind">;
13
+ export type AkumaCaller = z.infer<typeof akumaCallerSchema>;
14
+ export declare const akumaBirthSchema: z.ZodObject<{
15
+ origin: z.ZodDiscriminatedUnion<[z.ZodObject<{
16
+ kind: z.ZodLiteral<"direct">;
17
+ }, z.core.$strip>, z.ZodObject<{
18
+ kind: z.ZodLiteral<"request">;
19
+ parent: z.ZodPipe<z.ZodString, z.ZodTransform<import("./identity.js").AkuId, string>>;
20
+ requestId: z.ZodString;
21
+ }, z.core.$strip>, z.ZodObject<{
22
+ kind: z.ZodLiteral<"fork">;
23
+ parent: z.ZodPipe<z.ZodString, z.ZodTransform<import("./identity.js").AkuId, string>>;
24
+ at: z.ZodString;
25
+ }, z.core.$strip>], "kind">;
26
+ caller: z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
27
+ kind: z.ZodLiteral<"akuma">;
28
+ world: z.ZodCustom<WorldRoot, WorldRoot>;
29
+ akuId: z.ZodPipe<z.ZodString, z.ZodTransform<import("./identity.js").AkuId, string>>;
30
+ }, z.core.$strict>, z.ZodObject<{
31
+ kind: z.ZodLiteral<"external">;
32
+ integration: z.ZodString;
33
+ id: z.ZodString;
34
+ }, z.core.$strict>], "kind">, z.ZodObject<{
35
+ kind: z.ZodLiteral<"unknown">;
36
+ }, z.core.$strict>]>;
37
+ }, z.core.$strict>;
38
+ export declare function projectAkumaBirth(soul: Soul): z.infer<typeof akumaBirthSchema>;
39
+ export declare function decodeAkumaCaller(value: unknown): AkumaCaller | undefined;
@@ -0,0 +1,36 @@
1
+ import { isAbsolute, resolve } from "node:path";
2
+ import { z } from "zod";
3
+ import { akumaIdSchema } from "./identity.js";
4
+ import { akumaOriginSchema } from "./heart/facts.js";
5
+ // Stored attribution is a coordinate, not a live World capability or lookup.
6
+ const callerWorldSchema = z.custom((value) => typeof value === "string" && isAbsolute(value) && resolve(value) === value, "caller world must be an absolute normalized path");
7
+ export const akumaCallerSchema = z.discriminatedUnion("kind", [
8
+ z.object({ kind: z.literal("akuma"), world: callerWorldSchema, akuId: akumaIdSchema }).strict(),
9
+ z
10
+ .object({
11
+ kind: z.literal("external"),
12
+ integration: z.string().regex(/^[a-z][a-z0-9._-]{0,63}$/u),
13
+ id: z
14
+ .string()
15
+ .max(512)
16
+ .refine((value) => value.trim().length > 0 && !/[\u0000-\u001f\u007f-\u009f]/u.test(value), "external caller id must be nonblank and contain no control characters"),
17
+ })
18
+ .strict(),
19
+ ]);
20
+ export const akumaBirthSchema = z
21
+ .object({
22
+ origin: akumaOriginSchema,
23
+ caller: z.union([akumaCallerSchema, z.object({ kind: z.literal("unknown") }).strict()]),
24
+ })
25
+ .strict();
26
+ export function projectAkumaBirth(soul) {
27
+ return { origin: soul.origin, caller: soul.caller ?? { kind: "unknown" } };
28
+ }
29
+ export function decodeAkumaCaller(value) {
30
+ if (value === undefined)
31
+ return undefined;
32
+ const parsed = akumaCallerSchema.safeParse(value);
33
+ if (!parsed.success)
34
+ throw new TypeError(`Invalid Akuma caller: ${parsed.error.message}`);
35
+ return parsed.data;
36
+ }
@@ -10,4 +10,3 @@ export declare const dispatchAssociationSchema: z.ZodUnion<readonly [z.ZodObject
10
10
  }, z.core.$strict>]>;
11
11
  export type DispatchAssociation = z.infer<typeof dispatchAssociationSchema>;
12
12
  export declare const NO_DISPATCH_ASSOCIATION: DispatchAssociation;
13
- export declare function parseDispatchAssociation(value: unknown): DispatchAssociation;
@@ -6,6 +6,3 @@ export const dispatchAssociationSchema = z.union([
6
6
  z.object({ kind: z.literal("failed"), diagnostic: z.string() }).strict(),
7
7
  ]);
8
8
  export const NO_DISPATCH_ASSOCIATION = { kind: "none" };
9
- export function parseDispatchAssociation(value) {
10
- return dispatchAssociationSchema.parse(value);
11
- }
@@ -1,4 +1,6 @@
1
- import type { AkuId } from "../identity.js";
1
+ import type { AkumaCaller } from "../caller.js";
2
+ import { z } from "zod";
3
+ import { type AkuId } from "../identity.js";
2
4
  import type { ResumeCoordinate } from "../coordinate.js";
3
5
  import type { ProviderExecution, ProviderOptions } from "../provider-recipe.js";
4
6
  import type { AllowedActions } from "../allowed.js";
@@ -6,17 +8,18 @@ export type { ResumeCoordinate } from "../coordinate.js";
6
8
  export declare class HeartAuthorityCorruptionError extends Error {
7
9
  constructor(message: string, options?: ErrorOptions);
8
10
  }
9
- export type AkumaOrigin = Readonly<{
10
- kind: "direct";
11
- }> | Readonly<{
12
- kind: "request";
13
- parent: AkuId;
14
- requestId: string;
15
- }> | Readonly<{
16
- kind: "fork";
17
- parent: AkuId;
18
- at: string;
19
- }>;
11
+ export declare const akumaOriginSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
12
+ kind: z.ZodLiteral<"direct">;
13
+ }, z.core.$strip>, z.ZodObject<{
14
+ kind: z.ZodLiteral<"request">;
15
+ parent: z.ZodPipe<z.ZodString, z.ZodTransform<AkuId, string>>;
16
+ requestId: z.ZodString;
17
+ }, z.core.$strip>, z.ZodObject<{
18
+ kind: z.ZodLiteral<"fork">;
19
+ parent: z.ZodPipe<z.ZodString, z.ZodTransform<AkuId, string>>;
20
+ at: z.ZodString;
21
+ }, z.core.$strip>], "kind">;
22
+ export type AkumaOrigin = z.infer<typeof akumaOriginSchema>;
20
23
  export type Soul = Readonly<{
21
24
  id: AkuId;
22
25
  archetype: string;
@@ -25,6 +28,7 @@ export type Soul = Readonly<{
25
28
  options: ProviderOptions;
26
29
  cwd: string;
27
30
  origin: AkumaOrigin;
31
+ caller?: AkumaCaller;
28
32
  allowed: AllowedActions;
29
33
  createdAt: string;
30
34
  }>;
@@ -1,9 +1,17 @@
1
+ import { z } from "zod";
2
+ import { akumaIdSchema } from "../identity.js";
1
3
  export class HeartAuthorityCorruptionError extends Error {
2
4
  constructor(message, options) {
3
5
  super(message, options);
4
6
  this.name = "HeartAuthorityCorruptionError";
5
7
  }
6
8
  }
9
+ const originText = z.string().refine((value) => value.trim().length > 0);
10
+ export const akumaOriginSchema = z.discriminatedUnion("kind", [
11
+ z.object({ kind: z.literal("direct") }),
12
+ z.object({ kind: z.literal("request"), parent: akumaIdSchema, requestId: originText }),
13
+ z.object({ kind: z.literal("fork"), parent: akumaIdSchema, at: originText }),
14
+ ]);
7
15
  export function projectTell(fact) {
8
16
  return {
9
17
  kind: "tell",
@@ -1,14 +1,12 @@
1
1
  import type { AkumaPaths } from "../identity.js";
2
2
  import type { BodyEnd, BodyFact, ForkPoint, HeartSnapshot, KillFact, SealFact, SessionFact, Soul, TellDeliveryInput, TellFact, TellReceiptInput, TurnEndFact, TurnFact, TurnOutcome, TurnStartFact } from "./facts.js";
3
- export type { CallFact } from "./facts.js";
4
- import type { ActivityFact } from "./rows.js";
5
3
  import type { AgentEvent } from "./activity-schema.js";
6
4
  import { type StatusFactInput, type ActivityFactSlice } from "./timeline.js";
7
5
  export { HeartAbsentError, HeldAkumaLeash, classifyHeartSchema, initializeHeart, isHeartAbsent, probeLeash, } from "./storage.js";
8
6
  export { admitRequest, beginRequest, isRequestInputConflict, readNonterminalRequests, readRequest, refuseRequest, reserveRequest, serveRequest, serveUpstreamRequest, unproveRequest, voidRequest, } from "./request-authority.js";
9
7
  export { AkumaBusyError, life, lifeAt, projectTell } from "./facts.js";
10
8
  export { drainPendingTells } from "./tells.js";
11
- export type { AkumaLife, AkumaOrigin, BodyEnd, BodyFact, HeartSnapshot, ForkPoint, KillEvidence, KillFact, LeashProbe, PauseFact, RequestFact, RequestInput, RequestRecipe, SealFact, SessionFact, Soul, StopFact, TellBinding, TellFact, TellRow, TellDelivery, TellDeliveryInput, TellReceiptInput, TurnEndFact, TurnFact, TurnOutcome, TurnStartFact, } from "./facts.js";
9
+ export type { AkumaLife, AkumaOrigin, BodyEnd, HeartSnapshot, KillEvidence, RequestFact, SessionFact, Soul, TellFact, TurnEndFact, TurnOutcome, } from "./facts.js";
12
10
  export type { ResumeCoordinate } from "../coordinate.js";
13
11
  export declare function readSoul(paths: AkumaPaths): Promise<Soul | null>;
14
12
  export declare function heartExists(paths: AkumaPaths): Promise<boolean>;
@@ -19,8 +17,7 @@ export declare function appendActivity(paths: AkumaPaths, input: Readonly<{
19
17
  event: AgentEvent;
20
18
  at: string;
21
19
  }>): Promise<number>;
22
- export type ActivitySlice = ActivityFactSlice;
23
- export type { ActivityFact };
20
+ type ActivitySlice = ActivityFactSlice;
24
21
  export type { TimelineFact } from "./timeline.js";
25
22
  export declare function activitySlice(paths: AkumaPaths): Promise<ActivitySlice>;
26
23
  export declare function readStatusFacts(paths: AkumaPaths, input: StatusFactInput, signal?: AbortSignal): Promise<ActivitySlice["rows"]>;
@@ -74,8 +71,6 @@ export declare function requestPause(paths: AkumaPaths, at: string, signal?: Abo
74
71
  kind: "requested";
75
72
  body: BodyFact;
76
73
  }>>;
77
- export declare function stopRequested(paths: AkumaPaths, bodySequence?: number): Promise<boolean>;
78
- export declare function pauseRequested(paths: AkumaPaths, bodySequence?: number): Promise<boolean>;
79
74
  export declare function breakBody(paths: AkumaPaths, input: Readonly<{
80
75
  sequence: number;
81
76
  end: Exclude<BodyEnd, "exited">;
@@ -1,8 +1,8 @@
1
1
  import { parsePublicHistoryId } from "../identity.js";
2
2
  import { answeredTurnFact, endBodyFact, finishBodyFact, deleteStopControl, insertActivityFact, insertTurnEndFact, insertTurnStartFact, insertPauseControl, insertKillFact, insertSessionFact, insertStopControl, killFactForBody, latestBodyFact, latestKillFact, latestSessionFact, latestTurnFactForBody, lastAnsweredTurnFact, pauseFact, sessionFactForCoordinate, stopFact, turnFact, } from "./rows.js";
3
- import { insertTellDeliveryFact, dispositionSnapshotProven, insertTellBindingFact, insertTellDispositionSnapshot, insertTellFact, insertTellReceiptFact, insertUndeliveredTellReceipts, latestOpenTellDisposition, openBoundTurns, openTellDispositionIds, pendingTellFacts, hasPendingTell, resolveTellDispositionSnapshot, tellDispositionResolved, tellFact, tellIdsForFence, turnParticipants, } from "./tells.js";
3
+ import { insertTellDeliveryFact, dispositionSnapshotProven, insertTellBindingFact, insertTellDispositionSnapshot, insertTellReceiptFact, insertUndeliveredTellReceipts, latestOpenTellDisposition, openBoundTurns, openTellDispositionIds, pendingTellFacts, hasPendingTell, resolveTellDispositionSnapshot, tellDispositionResolved, tellFact, tellIdsForFence, turnParticipants, } from "./tells.js";
4
4
  import { activityFactSlice, statusFacts, readStatusBatch, decodeTimelineBatch, lastActivityAt as readLastActivityAt, pruneActivityFacts, } from "./timeline.js";
5
- import { isHeartAbsent, readSealFromLeash, withHeartTransaction, withReadOnlyHeart } from "./storage.js";
5
+ import { isHeartAbsent, readSealFromLeash, recordPendingTell, withHeartTransaction, withReadOnlyHeart, } from "./storage.js";
6
6
  import { soulFact } from "./soul.js";
7
7
  import { AkumaBusyError, HeartAuthorityCorruptionError } from "./facts.js";
8
8
  export { HeartAbsentError, HeldAkumaLeash, classifyHeartSchema, initializeHeart, isHeartAbsent, probeLeash, } from "./storage.js";
@@ -138,9 +138,7 @@ export async function recordTell(paths, tell, options = {}) {
138
138
  const running = body !== null && body.end === undefined && body.hung === undefined;
139
139
  if (tell.schemaJson !== undefined && running && options.interrupt !== true)
140
140
  throw new AkumaBusyError();
141
- const sequence = insertTellFact(heart, tell);
142
- pruneActivityFacts(heart, ACTIVITY_LIMIT);
143
- return { kind: "recorded", tell: { sequence, ...tell, state: "pending", deliveries: [] } };
141
+ return recordPendingTell(heart, tell);
144
142
  });
145
143
  }
146
144
  export async function readTell(paths, id) {
@@ -256,18 +254,6 @@ export async function requestPause(paths, at, signal) {
256
254
  return { kind: "requested", body };
257
255
  }, signal);
258
256
  }
259
- export async function stopRequested(paths, bodySequence) {
260
- return await withReadOnlyHeart(paths, (heart) => {
261
- const target = stopFact(heart);
262
- return target !== null && (bodySequence === undefined || target.bodySequence === bodySequence);
263
- });
264
- }
265
- export async function pauseRequested(paths, bodySequence) {
266
- return await withReadOnlyHeart(paths, (heart) => {
267
- const target = pauseFact(heart);
268
- return target !== null && (bodySequence === undefined || target.bodySequence === bodySequence);
269
- });
270
- }
271
257
  export async function breakBody(paths, input) {
272
258
  await withHeartTransaction(paths, (heart) => endBodyFact(heart, input));
273
259
  }
@@ -41,11 +41,11 @@ export declare const sessionAdmissionSchema: z.ZodObject<{
41
41
  }>>;
42
42
  systemPrompt: z.ZodOptional<z.ZodString>;
43
43
  systemPromptMode: z.ZodOptional<z.ZodEnum<{
44
- append: "append";
45
44
  replace: "replace";
45
+ append: "append";
46
46
  }>>;
47
47
  }, z.core.$strip>, z.ZodTransform<Readonly<{
48
- systemPromptMode?: "append" | "replace";
48
+ systemPromptMode?: "replace" | "append";
49
49
  systemPrompt?: string;
50
50
  network?: "disabled" | "enabled";
51
51
  effort?: string;
@@ -55,7 +55,7 @@ export declare const sessionAdmissionSchema: z.ZodObject<{
55
55
  effort?: string | undefined;
56
56
  network?: "disabled" | "enabled" | undefined;
57
57
  systemPrompt?: string | undefined;
58
- systemPromptMode?: "append" | "replace" | undefined;
58
+ systemPromptMode?: "replace" | "append" | undefined;
59
59
  }>>;
60
60
  admittedAt: z.ZodString;
61
61
  }, z.core.$strict>;
@@ -1,5 +1,5 @@
1
1
  import type { DatabaseSync } from "node:sqlite";
2
- import type { Soul, SoulRow } from "./facts.js";
2
+ import { type Soul, type SoulRow } from "./facts.js";
3
3
  export declare function decodeSoulSeed(value: unknown): Omit<Soul, "createdAt">;
4
4
  export declare function decodeSoul(value: unknown): Soul;
5
5
  export declare function encodeSoul(soul: Soul): string;
@@ -1,5 +1,7 @@
1
+ import { decodeAkumaCaller } from "../caller.js";
1
2
  import { parseAkuId } from "../identity.js";
2
3
  import { decodeProviderOptions, decodeProviderRecipe } from "../provider-recipe.js";
4
+ import { akumaOriginSchema } from "./facts.js";
3
5
  import { historicalAllowedActions } from "../allowed.js";
4
6
  function record(value) {
5
7
  return value !== null && typeof value === "object" && !Array.isArray(value)
@@ -20,29 +22,6 @@ function soulAkuIdentity(value, what) {
20
22
  throw new Error(`Akuma soul ${what} is not an Akuma identity coordinate`, { cause: error });
21
23
  }
22
24
  }
23
- function decodeOrigin(value) {
24
- const origin = record(value);
25
- if (origin === null)
26
- throw new Error("Akuma soul origin must be an object");
27
- if (origin.kind === "direct") {
28
- return { kind: "direct" };
29
- }
30
- if (origin.kind === "request") {
31
- return {
32
- kind: "request",
33
- parent: soulAkuIdentity(origin.parent, "request parent").id,
34
- requestId: nonblank(origin.requestId, "request requestId"),
35
- };
36
- }
37
- if (origin.kind === "fork") {
38
- return {
39
- kind: "fork",
40
- parent: soulAkuIdentity(origin.parent, "fork parent").id,
41
- at: nonblank(origin.at, "fork at"),
42
- };
43
- }
44
- throw new Error("Akuma soul origin must be direct, request, or fork");
45
- }
46
25
  export function decodeSoulSeed(value) {
47
26
  const soul = record(value);
48
27
  if (soul === null)
@@ -55,6 +34,7 @@ export function decodeSoulSeed(value) {
55
34
  const description = soul.description === undefined ? undefined : nonblank(soul.description, "description");
56
35
  const provider = decodeProviderRecipe(soul.provider);
57
36
  const options = decodeProviderOptions(soul.options);
37
+ const caller = decodeAkumaCaller(soul.caller);
58
38
  return {
59
39
  id,
60
40
  archetype,
@@ -62,7 +42,8 @@ export function decodeSoulSeed(value) {
62
42
  provider,
63
43
  options,
64
44
  cwd: nonblank(soul.cwd, "cwd"),
65
- origin: decodeOrigin(soul.origin),
45
+ origin: akumaOriginSchema.parse(soul.origin),
46
+ ...(caller === undefined ? {} : { caller }),
66
47
  allowed: historicalAllowedActions(soul.allowed),
67
48
  };
68
49
  }
@@ -10,6 +10,11 @@ export declare function isHeartAbsent(error: unknown): error is HeartAbsentError
10
10
  export declare function classifyHeartSchema(paths: AkumaPaths): Promise<"current" | "unsupported">;
11
11
  export declare function withReadOnlyHeart<T>(paths: AkumaPaths, body: (database: DatabaseSync) => T, signal?: AbortSignal): Promise<T>;
12
12
  export declare function withHeartTransaction<T>(paths: AkumaPaths, body: (database: DatabaseSync) => T, signal?: AbortSignal): Promise<T>;
13
+ /** Insert one already-admitted pending Tell into an already-open Heart transaction. */
14
+ export declare function recordPendingTell(heart: DatabaseSync, tell: Omit<TellFact, "sequence" | "state" | "deliveries" | "binding">): Readonly<{
15
+ kind: "recorded";
16
+ tell: TellFact;
17
+ }>;
13
18
  export declare function initializeHeart(paths: AkumaPaths): Promise<void>;
14
19
  export declare class HeldAkumaLeash {
15
20
  private readonly database;
@@ -142,6 +142,12 @@ function finishTransaction(database, body) {
142
142
  throw error;
143
143
  }
144
144
  }
145
+ /** Insert one already-admitted pending Tell into an already-open Heart transaction. */
146
+ export function recordPendingTell(heart, tell) {
147
+ const sequence = insertTellFact(heart, tell);
148
+ pruneActivityFacts(heart, ACTIVITY_LIMIT);
149
+ return { kind: "recorded", tell: { sequence, ...tell, state: "pending", deliveries: [] } };
150
+ }
145
151
  export async function initializeHeart(paths) {
146
152
  const heart = new DatabaseSync(paths.heart);
147
153
  try {
@@ -258,9 +264,7 @@ export class HeldAkumaLeash {
258
264
  deletePauseControl(heart);
259
265
  if (soulFact(heart) === null)
260
266
  return { kind: "not-born" };
261
- const sequence = insertTellFact(heart, tell);
262
- pruneActivityFacts(heart, ACTIVITY_LIMIT);
263
- return { kind: "recorded", tell: { sequence, ...tell, state: "pending", deliveries: [] } };
267
+ return recordPendingTell(heart, tell);
264
268
  });
265
269
  }
266
270
  release() {
@@ -18,7 +18,6 @@ export type AllocatedAkuma = Readonly<{
18
18
  suffix: string;
19
19
  paths: AkumaPaths;
20
20
  }>;
21
- export declare function archetypeName(value: string): string;
22
21
  export declare function akuId(input: Readonly<{
23
22
  archetype: string;
24
23
  suffix: string;
@@ -22,9 +22,6 @@ export const akumaPathsSchema = z
22
22
  requests: pathText,
23
23
  })
24
24
  .strict();
25
- export function archetypeName(value) {
26
- return validateAkumaName(value);
27
- }
28
25
  function suffixSegment(value) {
29
26
  if (!HEX8.test(value))
30
27
  throw new TypeError("Akuma suffix must be lower hex8");
@@ -33,7 +30,7 @@ function suffixSegment(value) {
33
30
  export function akuId(input) {
34
31
  return identityCoordinate({
35
32
  family: "aku",
36
- segments: [archetypeName(input.archetype), suffixSegment(input.suffix)],
33
+ segments: [validateAkumaName(input.archetype), suffixSegment(input.suffix)],
37
34
  });
38
35
  }
39
36
  export function parseAkuId(value) {
@@ -94,7 +91,7 @@ export async function ensureAkumaRunRoot(worldRoot) {
94
91
  return runRoot;
95
92
  }
96
93
  export async function allocateAkumaDirectory(input) {
97
- const archetype = archetypeName(input.archetype);
94
+ const archetype = validateAkumaName(input.archetype);
98
95
  const runRoot = await ensureAkumaRunRoot(input.worldRoot);
99
96
  for (;;) {
100
97
  const suffix = suffixSegment(input.draw?.() ?? randomBytes(4).toString("hex"));
@@ -1,7 +1,10 @@
1
- export type { WorldRoot } from "../world.js";
1
+ export type { AkumaCaller } from "./caller.js";
2
+ export type { AkumaOrigin } from "./heart/index.js";
3
+ export { AkumaArchetypeError, listArchetypeDefinitions } from "./archetype.js";
4
+ export type { ArchetypeCatalog, ArchetypeCatalogInput, ArchetypeCatalogRow } from "./archetype.js";
2
5
  export { AkumaBusyError, AkumaDecodeError, AkumaNotBornError, AkumaProviderError } from "./akuma-errors.js";
3
6
  export { Akuma } from "./akuma-instance.js";
4
- export type { AkumaAskOptions, AkumaBirthInput, AkumaHistoryOptions, AkumaIdleOptions, AkumaIdleResult, AkumaSignalOptions, AkumaTellOptions, } from "./akuma-instance.js";
7
+ export type { AkumaAskOptions, AkumaBirthInput, AkumaHistoryOptions, AkumaHostOptions, AkumaIdleOptions, AkumaIdleResult, AkumaSignalOptions, AkumaTellOptions, } from "./akuma-instance.js";
5
8
  export type { InterruptReceipt } from "./akuma-owner.js";
6
9
  export type { AkumaStatus } from "./akuma.js";
7
10
  export { ALLOWED_ACTIONS } from "./allowed.js";
@@ -1,3 +1,4 @@
1
+ export { AkumaArchetypeError, listArchetypeDefinitions } from "./archetype.js";
1
2
  export { AkumaBusyError, AkumaDecodeError, AkumaNotBornError, AkumaProviderError } from "./akuma-errors.js";
2
3
  export { Akuma } from "./akuma-instance.js";
3
4
  export { ALLOWED_ACTIONS } from "./allowed.js";