@astrosheep/keiyaku 4.6.32 → 4.6.33

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 (199) hide show
  1. package/README.md +8 -6
  2. package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +13 -9
  3. package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +8 -6
  4. package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +2 -1
  5. package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +13 -9
  6. package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +8 -6
  7. package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +2 -1
  8. package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +13 -9
  9. package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +8 -6
  10. package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +2 -1
  11. package/build/plugins/pi/README.md +55 -97
  12. package/build/plugins/pi/keiyaku.ts +2 -9
  13. package/build/skills/keiyaku-akuma/SKILL.md +13 -9
  14. package/build/skills/keiyaku-babysit/SKILL.md +8 -6
  15. package/build/skills/keiyaku-workflow/SKILL.md +2 -1
  16. package/build/src/akuma/akuma-instance.d.ts +11 -0
  17. package/build/src/akuma/akuma-instance.js +1 -2
  18. package/build/src/akuma/akuma-observe.js +73 -14
  19. package/build/src/akuma/akuma-selection-execution.d.ts +82 -7
  20. package/build/src/akuma/akuma-selection-execution.js +26 -27
  21. package/build/src/akuma/akuma-wait.d.ts +40 -1
  22. package/build/src/akuma/akuma-wait.js +58 -29
  23. package/build/src/akuma/akuma.d.ts +11 -0
  24. package/build/src/akuma/body.js +13 -18
  25. package/build/src/akuma/call-initial-tell.d.ts +0 -1
  26. package/build/src/akuma/call-initial-tell.js +0 -1
  27. package/build/src/akuma/heart/activity-schema.d.ts +16 -0
  28. package/build/src/akuma/heart/activity-schema.js +7 -0
  29. package/build/src/akuma/heart/index.d.ts +1 -1
  30. package/build/src/akuma/heart/index.js +9 -1
  31. package/build/src/akuma/heart/timeline.js +4 -4
  32. package/build/src/akuma/projection-read.d.ts +4 -2
  33. package/build/src/akuma/projection-read.js +21 -14
  34. package/build/src/akuma/projection.d.ts +94 -2
  35. package/build/src/akuma/projection.js +47 -47
  36. package/build/src/akuma/provider.d.ts +2 -2
  37. package/build/src/akuma/provider.js +27 -20
  38. package/build/src/akuma/providers/acp/core.js +2 -5
  39. package/build/src/akuma/providers/opencode-sdk/events.d.ts +2 -1
  40. package/build/src/akuma/providers/opencode-sdk/events.js +31 -1
  41. package/build/src/akuma/publication.js +3 -2
  42. package/build/src/akuma/selection-observation.d.ts +23 -0
  43. package/build/src/akuma/selection-observation.js +15 -4
  44. package/build/src/akuma/status-projection.d.ts +14 -1
  45. package/build/src/akuma/status-projection.js +40 -2
  46. package/build/src/akuma/turn-drive.js +21 -15
  47. package/build/src/body/amend.js +5 -17
  48. package/build/src/body/decode.js +11 -1
  49. package/build/src/body/envelope.d.ts +5 -1
  50. package/build/src/body/envelope.js +4 -2
  51. package/build/src/body/render.js +4 -6
  52. package/build/src/cli/commands/akuma-grammar.d.ts +3 -5
  53. package/build/src/cli/commands/akuma-grammar.js +22 -40
  54. package/build/src/cli/commands/akuma.d.ts +1 -2
  55. package/build/src/cli/commands/akuma.js +6 -58
  56. package/build/src/cli/commands/contract-grammar.d.ts +1 -0
  57. package/build/src/cli/commands/contract-grammar.js +7 -11
  58. package/build/src/cli/commands/contract-help.d.ts +3 -2
  59. package/build/src/cli/commands/contract-help.js +11 -5
  60. package/build/src/cli/commands/contract.js +3 -0
  61. package/build/src/cli/commands/debt-grammar.js +2 -4
  62. package/build/src/cli/parse.js +1 -4
  63. package/build/src/cli/render/akuma-activity.d.ts +3 -15
  64. package/build/src/cli/render/akuma-activity.js +19 -73
  65. package/build/src/cli/render/akuma.d.ts +5 -11
  66. package/build/src/cli/render/akuma.js +22 -30
  67. package/build/src/cli/render/catalog.js +1 -4
  68. package/build/src/cli/render/contract-history.js +2 -0
  69. package/build/src/cli/render/contract-observation.d.ts +2 -1
  70. package/build/src/cli/render/contract-observation.js +25 -1
  71. package/build/src/cli/render/contract-wait.d.ts +2 -2
  72. package/build/src/cli/render/contract-wait.js +13 -17
  73. package/build/src/cli/render/contract.js +12 -9
  74. package/build/src/cli/render/debt.js +1 -2
  75. package/build/src/cli/render/execution-progress.js +1 -3
  76. package/build/src/cli/render/kanshi-akuma.js +1 -2
  77. package/build/src/cli/render/kanshi.js +11 -17
  78. package/build/src/cli/render/receipt.d.ts +1 -1
  79. package/build/src/cli/render/receipt.js +33 -28
  80. package/build/src/cli/render/reconcile.js +2 -5
  81. package/build/src/cli/render/refusal.js +3 -6
  82. package/build/src/cli/render/terminal.d.ts +2 -4
  83. package/build/src/cli/render/terminal.js +10 -17
  84. package/build/src/cli/render/verbs.d.ts +1 -0
  85. package/build/src/cli/render/verbs.js +19 -17
  86. package/build/src/cli/runtime.js +3 -9
  87. package/build/src/core/facts/codec.js +7 -2
  88. package/build/src/core/facts/eligibility.d.ts +4 -4
  89. package/build/src/core/facts/eligibility.js +11 -0
  90. package/build/src/core/facts/fold.js +9 -5
  91. package/build/src/core/facts/gate.d.ts +5 -1
  92. package/build/src/core/facts/gate.js +14 -10
  93. package/build/src/core/facts/types.d.ts +5 -1
  94. package/build/src/core/facts/types.js +7 -0
  95. package/build/src/core/subject.d.ts +4 -1
  96. package/build/src/core/subject.js +10 -2
  97. package/build/src/core/verbs/amend.d.ts +15 -4
  98. package/build/src/core/verbs/amend.js +19 -9
  99. package/build/src/debt/index.d.ts +0 -1
  100. package/build/src/debt/index.js +6 -11
  101. package/build/src/debt/input.d.ts +2 -1
  102. package/build/src/debt/input.js +6 -4
  103. package/build/src/dispatch/index.d.ts +0 -17
  104. package/build/src/dispatch/index.js +1 -10
  105. package/build/src/git/identity.js +16 -45
  106. package/build/src/git/nuke.js +13 -23
  107. package/build/src/git/observe.d.ts +3 -0
  108. package/build/src/git/observe.js +25 -23
  109. package/build/src/git/process.js +11 -18
  110. package/build/src/git/read-observation.d.ts +5 -4
  111. package/build/src/git/repository.d.ts +2 -0
  112. package/build/src/git/repository.js +13 -1
  113. package/build/src/git/scratch.js +2 -14
  114. package/build/src/git/terminal-reconcile.js +1 -13
  115. package/build/src/index.d.ts +2 -0
  116. package/build/src/kanshi/index.d.ts +0 -1
  117. package/build/src/kanshi/index.js +0 -1
  118. package/build/src/kanshi/read.d.ts +21 -0
  119. package/build/src/kanshi/read.js +2 -1
  120. package/build/src/kanshi/report.d.ts +94 -0
  121. package/build/src/library/address.d.ts +12 -5
  122. package/build/src/library/address.js +18 -32
  123. package/build/src/library/akuma-creation.d.ts +39 -0
  124. package/build/src/library/akuma-creation.js +3 -9
  125. package/build/src/library/continuation.d.ts +10 -0
  126. package/build/src/library/contract-creation.js +10 -11
  127. package/build/src/library/contract-outcomes.d.ts +72 -1
  128. package/build/src/library/contract-outcomes.js +1 -0
  129. package/build/src/library/contract-types.d.ts +18 -0
  130. package/build/src/library/contract-types.js +2 -0
  131. package/build/src/library/contract-wait.d.ts +7 -0
  132. package/build/src/library/contract-wait.js +53 -49
  133. package/build/src/library/delivery.d.ts +25 -0
  134. package/build/src/library/input.d.ts +5 -23
  135. package/build/src/library/input.js +12 -7
  136. package/build/src/library/kei.js +39 -20
  137. package/build/src/library/keiyaku-classify.js +3 -3
  138. package/build/src/library/keiyaku-debt.js +1 -2
  139. package/build/src/library/keiyaku-identity.d.ts +3 -3
  140. package/build/src/library/keiyaku-identity.js +11 -6
  141. package/build/src/library/keiyaku-verbs.d.ts +456 -1362
  142. package/build/src/library/keiyaku-verbs.js +80 -92
  143. package/build/src/library/keiyaku-wait.d.ts +183 -0
  144. package/build/src/library/keiyaku-wait.js +213 -0
  145. package/build/src/library/keiyaku.d.ts +3 -1
  146. package/build/src/library/keiyaku.js +49 -73
  147. package/build/src/{mcp/output.d.ts → library/model-tools.d.ts} +227 -56
  148. package/build/src/library/model-tools.js +347 -0
  149. package/build/src/library/outcome.js +5 -6
  150. package/build/src/library/refusal.d.ts +25 -1
  151. package/build/src/library/refusal.js +4 -5
  152. package/build/src/library/selection.d.ts +12 -0
  153. package/build/src/library/selection.js +1 -2
  154. package/build/src/mcp/adapter.d.ts +0 -6
  155. package/build/src/mcp/adapter.js +10 -159
  156. package/build/src/mcp/description.d.ts +2 -0
  157. package/build/src/mcp/description.js +2 -0
  158. package/build/src/mcp/help.d.ts +1 -1
  159. package/build/src/mcp/help.js +6 -4
  160. package/build/src/pi/index.d.ts +3 -0
  161. package/build/src/pi/index.js +83 -0
  162. package/build/src/protocol/amend.d.ts +14 -3
  163. package/build/src/protocol/amend.js +113 -46
  164. package/build/src/protocol/bind.d.ts +1 -1
  165. package/build/src/protocol/bind.js +5 -16
  166. package/build/src/protocol/completion.d.ts +30 -0
  167. package/build/src/protocol/completion.js +8 -5
  168. package/build/src/protocol/deliver.js +7 -20
  169. package/build/src/protocol/delivery-preview.d.ts +5 -0
  170. package/build/src/protocol/execution-observation.d.ts +8 -0
  171. package/build/src/protocol/intent.d.ts +1 -0
  172. package/build/src/protocol/intent.js +4 -1
  173. package/build/src/protocol/operations.d.ts +54 -16
  174. package/build/src/protocol/operations.js +17 -31
  175. package/build/src/protocol/placement.js +7 -1
  176. package/build/src/protocol/progress.js +0 -6
  177. package/build/src/protocol/read/status.d.ts +40 -0
  178. package/build/src/protocol/read/status.js +7 -10
  179. package/build/src/protocol/reintegrate.js +2 -2
  180. package/build/src/protocol/result-leaves.d.ts +56 -8
  181. package/build/src/protocol/result-leaves.js +11 -2
  182. package/build/src/protocol/run.js +1 -4
  183. package/build/src/protocol/verify.d.ts +10 -0
  184. package/build/src/protocol/verify.js +1 -0
  185. package/build/src/runtime/proc/windows-launch.exe +0 -0
  186. package/build/src/settlement/settle.js +19 -68
  187. package/package.json +7 -3
  188. package/plugins/pi/README.md +55 -97
  189. package/plugins/pi/keiyaku.ts +2 -9
  190. package/skills/keiyaku-akuma/SKILL.md +13 -9
  191. package/skills/keiyaku-babysit/SKILL.md +8 -6
  192. package/skills/keiyaku-workflow/SKILL.md +2 -1
  193. package/build/plugins/pi/akuma-tools.ts +0 -283
  194. package/build/src/body/keys.d.ts +0 -4
  195. package/build/src/body/keys.js +0 -11
  196. package/build/src/kanshi/roster.d.ts +0 -2
  197. package/build/src/kanshi/roster.js +0 -2
  198. package/build/src/mcp/output.js +0 -193
  199. package/plugins/pi/akuma-tools.ts +0 -283
@@ -1,11 +1,15 @@
1
- import { realpath } from "node:fs/promises";
1
+ import { realpath } from "node:fs";
2
+ import { basename, dirname, join, resolve } from "node:path";
3
+ import { promisify } from "node:util";
2
4
  import { projectAkumaBirth } from "./caller.js";
3
5
  import { createStatusFactReader, readLifeSnapshot, HeldAkumaLeash, heartExists, isHeartAbsent, life, lifeAt, probeLeash, readHeart, readSeal, } from "./heart/index.js";
4
6
  import { pathsForAkumaId } from "./identity.js";
5
- import { DEFAULT_TAIL, projectTurns, selectHistory, selectSnapshot, } from "./projection.js";
7
+ import { DEFAULT_TAIL, projectTurns, reportedChangePaths, selectHistory, selectSnapshot, } from "./projection.js";
6
8
  import { resolveProviderExecution } from "./providers/index.js";
7
9
  import { abortableDelay } from "./abort.js";
8
10
  import { AkumaNotBornError } from "./akuma-errors.js";
11
+ /** Native resolution answers on-disk case as well as symlinks; the portable form keeps the caller's spelling. */
12
+ const realpathNative = promisify(realpath.native);
9
13
  export async function rosterListRow(paths, expected) {
10
14
  const snapshot = await readHeart(paths);
11
15
  if (snapshot.soul !== null) {
@@ -79,22 +83,79 @@ export async function observeStatusOutcome(status, observer) {
79
83
  if (snapshot.kind === "idle" && snapshot.outcome !== undefined)
80
84
  await observer?.(status.id, [`turn/${snapshot.outcome.turnSequence}`]);
81
85
  }
82
- function snapshotSelection(input, executionDir) {
86
+ function snapshotSelection(input, executionDir, canonicalize) {
83
87
  if (input.ordinaryBudget !== undefined && (!Number.isSafeInteger(input.ordinaryBudget) || input.ordinaryBudget < 0))
84
88
  throw new TypeError("ordinary budget must be a nonnegative safe integer");
85
89
  return {
86
90
  aperture: input.aperture,
87
91
  budget: { tail: Math.min(DEFAULT_TAIL, input.ordinaryBudget ?? DEFAULT_TAIL) },
88
92
  ...(executionDir === undefined ? {} : { executionDir }),
93
+ ...(canonicalize === undefined ? {} : { canonicalize }),
89
94
  ...(input.admittedTellId === undefined ? {} : { admittedTellId: input.admittedTellId }),
90
95
  };
91
96
  }
97
+ /** Canonical resolutions of reported-change anchors, so projection itself stays synchronous. */
98
+ function createCanonicalAnchors() {
99
+ const resolved = new Map();
100
+ let changed = 0;
101
+ return {
102
+ changed: () => changed,
103
+ clear: () => {
104
+ resolved.clear();
105
+ changed = 0;
106
+ },
107
+ /** Answer from what is already resolved; an unresolved directory stays lexical. */
108
+ canonicalize(absolutePath) {
109
+ const hit = resolved.get(absolutePath);
110
+ if (hit !== undefined)
111
+ return hit;
112
+ const dir = resolved.get(dirname(absolutePath));
113
+ return dir === undefined ? absolutePath : join(dir, basename(absolutePath));
114
+ },
115
+ async resolve(absolutePaths) {
116
+ for (const absolutePath of new Set(absolutePaths)) {
117
+ if (resolved.has(absolutePath))
118
+ continue;
119
+ try {
120
+ resolved.set(absolutePath, await realpathNative(absolutePath));
121
+ changed += 1;
122
+ continue;
123
+ }
124
+ catch {
125
+ // A deleted or not-yet-existing leaf still belongs to its canonical directory.
126
+ }
127
+ const dir = dirname(absolutePath);
128
+ if (resolved.has(dir))
129
+ continue;
130
+ try {
131
+ resolved.set(dir, await realpathNative(dir));
132
+ changed += 1;
133
+ }
134
+ catch {
135
+ // An unresolvable directory stays lexical without caching the transient error.
136
+ }
137
+ }
138
+ },
139
+ };
140
+ }
141
+ function reusableSelection(memo, ledger, options, anchorsChanged) {
142
+ if (memo === undefined || memo.ledger !== ledger || memo.anchorsChanged !== anchorsChanged)
143
+ return undefined;
144
+ if (memo.options.aperture !== options.aperture ||
145
+ memo.options.admittedTellId !== options.admittedTellId ||
146
+ memo.options.budget.tail !== options.budget.tail ||
147
+ memo.options.executionDir !== options.executionDir)
148
+ return undefined;
149
+ return memo.selected;
150
+ }
92
151
  /** Private to a live wait: retain only this member's current frontier and last selection. */
93
152
  export function createLiveStatusReader(paths, expected) {
94
153
  const reader = createStatusFactReader(paths);
154
+ const anchors = createCanonicalAnchors();
95
155
  let memo;
96
156
  const clear = () => {
97
157
  reader.clear();
158
+ anchors.clear();
98
159
  memo = undefined;
99
160
  };
100
161
  return {
@@ -121,16 +182,14 @@ export function createLiveStatusReader(paths, expected) {
121
182
  (await resolveProviderExecution(soul.provider)).adapter.resume === undefined;
122
183
  const facts = await reader.read(input, signal);
123
184
  const ledger = memo?.facts === facts ? memo.ledger : projectTurns(facts);
124
- const options = snapshotSelection(input, await realpath(soul.cwd).catch(() => undefined));
125
- const selected = memo?.ledger === ledger &&
126
- memo.options.aperture === options.aperture &&
127
- memo.options.admittedTellId === options.admittedTellId &&
128
- memo.options.budget.tail === options.budget.tail &&
129
- memo.options.executionDir === options.executionDir
130
- ? memo.selected
131
- : selectSnapshot(ledger, options);
132
- memo = { facts, ledger, options, selected };
133
- const lastActivityAt = ledger.rows.findLast((row) => row.kind !== "turn")?.at;
185
+ const executionDir = await realpathNative(soul.cwd).catch(() => undefined);
186
+ if (executionDir !== undefined)
187
+ await anchors.resolve(reportedChangePaths(ledger).map((reported) => resolve(executionDir, reported)));
188
+ const options = snapshotSelection(input, executionDir, executionDir === undefined ? undefined : anchors.canonicalize);
189
+ const anchorsChanged = anchors.changed();
190
+ const selected = reusableSelection(memo, ledger, options, anchorsChanged) ?? selectSnapshot(ledger, options);
191
+ memo = { facts, ledger, options, selected, anchorsChanged };
192
+ const lastActivityAt = snapshot.lastActivityAt;
134
193
  return {
135
194
  status: {
136
195
  id: soul.id,
@@ -144,7 +203,7 @@ export function createLiveStatusReader(paths, expected) {
144
203
  ...(soul.options.model === undefined ? {} : { model: soul.options.model }),
145
204
  ...(resumeUnsupported ? { strandedReason: "resume-unsupported" } : {}),
146
205
  timeline: selected.snapshot,
147
- ...(lastActivityAt === undefined ? {} : { lastActivityAt }),
206
+ ...(lastActivityAt === null ? {} : { lastActivityAt }),
148
207
  },
149
208
  ordinarySelected: selected.ordinaryCount,
150
209
  rows: ledger.rows,
@@ -76,6 +76,18 @@ export declare const liveStatusObservationSchema: z.ZodReadonly<z.ZodObject<{
76
76
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
77
77
  kind: z.ZodLiteral<"row">;
78
78
  row: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
79
+ kind: z.ZodLiteral<"permission">;
80
+ sequence: z.ZodNumber;
81
+ turnSequence: z.ZodNumber;
82
+ at: z.ZodString;
83
+ requests: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
84
+ id: z.ZodString;
85
+ action: z.ZodString;
86
+ resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
87
+ tool: z.ZodExactOptional<z.ZodString>;
88
+ }, z.core.$strict>>>>;
89
+ truncated: z.ZodExactOptional<z.ZodLiteral<true>>;
90
+ }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
79
91
  kind: z.ZodLiteral<"report">;
80
92
  sequence: z.ZodNumber;
81
93
  bodySequence: z.ZodNumber;
@@ -222,6 +234,18 @@ export declare const liveStatusObservationSchema: z.ZodReadonly<z.ZodObject<{
222
234
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
223
235
  kind: z.ZodLiteral<"row">;
224
236
  row: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
237
+ kind: z.ZodLiteral<"permission">;
238
+ sequence: z.ZodNumber;
239
+ turnSequence: z.ZodNumber;
240
+ at: z.ZodString;
241
+ requests: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
242
+ id: z.ZodString;
243
+ action: z.ZodString;
244
+ resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
245
+ tool: z.ZodExactOptional<z.ZodString>;
246
+ }, z.core.$strict>>>>;
247
+ truncated: z.ZodExactOptional<z.ZodLiteral<true>>;
248
+ }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
225
249
  kind: z.ZodLiteral<"report">;
226
250
  sequence: z.ZodNumber;
227
251
  bodySequence: z.ZodNumber;
@@ -338,6 +362,18 @@ export declare const liveStatusObservationSchema: z.ZodReadonly<z.ZodObject<{
338
362
  }, z.core.$strict>>;
339
363
  ordinarySelected: z.ZodNumber;
340
364
  rows: z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
365
+ kind: z.ZodLiteral<"permission">;
366
+ sequence: z.ZodNumber;
367
+ turnSequence: z.ZodNumber;
368
+ at: z.ZodString;
369
+ requests: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
370
+ id: z.ZodString;
371
+ action: z.ZodString;
372
+ resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
373
+ tool: z.ZodExactOptional<z.ZodString>;
374
+ }, z.core.$strict>>>>;
375
+ truncated: z.ZodExactOptional<z.ZodLiteral<true>>;
376
+ }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
341
377
  kind: z.ZodLiteral<"turn">;
342
378
  sequence: z.ZodNumber;
343
379
  bodySequence: z.ZodNumber;
@@ -588,6 +624,18 @@ export declare const askProgressSchema: z.ZodUnion<readonly [z.ZodReadonly<z.Zod
588
624
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
589
625
  kind: z.ZodLiteral<"row">;
590
626
  row: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
627
+ kind: z.ZodLiteral<"permission">;
628
+ sequence: z.ZodNumber;
629
+ turnSequence: z.ZodNumber;
630
+ at: z.ZodString;
631
+ requests: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
632
+ id: z.ZodString;
633
+ action: z.ZodString;
634
+ resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
635
+ tool: z.ZodExactOptional<z.ZodString>;
636
+ }, z.core.$strict>>>>;
637
+ truncated: z.ZodExactOptional<z.ZodLiteral<true>>;
638
+ }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
591
639
  kind: z.ZodLiteral<"report">;
592
640
  sequence: z.ZodNumber;
593
641
  bodySequence: z.ZodNumber;
@@ -734,6 +782,18 @@ export declare const askProgressSchema: z.ZodUnion<readonly [z.ZodReadonly<z.Zod
734
782
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
735
783
  kind: z.ZodLiteral<"row">;
736
784
  row: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
785
+ kind: z.ZodLiteral<"permission">;
786
+ sequence: z.ZodNumber;
787
+ turnSequence: z.ZodNumber;
788
+ at: z.ZodString;
789
+ requests: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
790
+ id: z.ZodString;
791
+ action: z.ZodString;
792
+ resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
793
+ tool: z.ZodExactOptional<z.ZodString>;
794
+ }, z.core.$strict>>>>;
795
+ truncated: z.ZodExactOptional<z.ZodLiteral<true>>;
796
+ }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
737
797
  kind: z.ZodLiteral<"report">;
738
798
  sequence: z.ZodNumber;
739
799
  bodySequence: z.ZodNumber;
@@ -850,6 +910,18 @@ export declare const askProgressSchema: z.ZodUnion<readonly [z.ZodReadonly<z.Zod
850
910
  }, z.core.$strict>>;
851
911
  ordinarySelected: z.ZodNumber;
852
912
  rows: z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
913
+ kind: z.ZodLiteral<"permission">;
914
+ sequence: z.ZodNumber;
915
+ turnSequence: z.ZodNumber;
916
+ at: z.ZodString;
917
+ requests: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
918
+ id: z.ZodString;
919
+ action: z.ZodString;
920
+ resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
921
+ tool: z.ZodExactOptional<z.ZodString>;
922
+ }, z.core.$strict>>>>;
923
+ truncated: z.ZodExactOptional<z.ZodLiteral<true>>;
924
+ }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
853
925
  kind: z.ZodLiteral<"turn">;
854
926
  sequence: z.ZodNumber;
855
927
  bodySequence: z.ZodNumber;
@@ -1011,7 +1083,14 @@ type AskExecutionInput = TellExecutionInput & Readonly<{
1011
1083
  schemaJson?: string;
1012
1084
  }>;
1013
1085
  export declare function executeTellAkuma(input: TellExecutionInput): Promise<AkumaTellResult>;
1014
- export declare function observeAdmittedAskAkuma(input: Readonly<{
1086
+ type TextAskResult = Exclude<AkumaAskResult, {
1087
+ kind: "answered";
1088
+ }> | (Omit<Extract<AkumaAskResult, {
1089
+ kind: "answered";
1090
+ }>, "answer"> & Readonly<{
1091
+ answer: string;
1092
+ }>);
1093
+ export declare function observeAdmittedTellAkuma(input: Readonly<{
1015
1094
  path: WorldRoot;
1016
1095
  id: AkumaStatus["id"];
1017
1096
  tellId: string;
@@ -1028,12 +1107,8 @@ export declare function observeAdmittedAskAkuma(input: Readonly<{
1028
1107
  receipt?: TellResult;
1029
1108
  onObserve?: AskObserver;
1030
1109
  outcomeObserved?: OutcomeObserver;
1031
- }>): Promise<AkumaAskResult & {
1032
- answer?: string;
1033
- }>;
1034
- export declare function executeAskAkuma(input: AskExecutionInput): Promise<AkumaAskResult & {
1035
- answer?: string;
1036
- }>;
1110
+ }>): Promise<TextAskResult>;
1111
+ export declare function executeAskAkuma(input: AskExecutionInput): Promise<AkumaAskResult>;
1037
1112
  type KillExecutionInput = Readonly<{
1038
1113
  spawn: BodyLauncher;
1039
1114
  path: WorldRoot;
@@ -18,11 +18,7 @@ export const askProgressSchema = z.union([
18
18
  z.strictObject({ kind: z.literal("admitted"), tell: tellResultSchema, id: akumaIdSchema }).readonly(),
19
19
  z.strictObject({ kind: z.literal("live"), observation: liveStatusObservationSchema }).readonly(),
20
20
  ]);
21
- export async function executeTellAkuma(input) {
22
- if (input.wait === true) {
23
- const { akumaId, tellId, wake, interrupt, ...observation } = await executeAskAkuma(input);
24
- return completeTell({ akumaId, tellId, ...(wake === undefined ? {} : { wake }), ...(interrupt === undefined ? {} : { interrupt }) }, observation.kind === "invalid-output" ? { kind: "failed", diagnostic: observation.diagnostic } : observation);
25
- }
21
+ async function admitExecutionTell(input) {
26
22
  input.signal?.throwIfAborted();
27
23
  const owner = new AkumaOwner(input.id, input.path);
28
24
  const admission = input.interrupt === true
@@ -32,12 +28,21 @@ export async function executeTellAkuma(input) {
32
28
  throw new AkumaNotBornError(input.id);
33
29
  if (admission.kind === "unavailable")
34
30
  throw new AkumaProviderError(`Tell interrupt unavailable: ${admission.evidence}`);
35
- let tell = {
31
+ const receipt = {
36
32
  ...pendingTellReceipt(admission.tell),
37
33
  ...("barrier" in admission && admission.barrier !== undefined
38
34
  ? { interruption: { kind: "pending", bodySequence: admission.barrier.bodySequence } }
39
35
  : {}),
40
36
  };
37
+ return { owner, admission, receipt };
38
+ }
39
+ export async function executeTellAkuma(input) {
40
+ if (input.wait === true) {
41
+ const { akumaId, tellId, wake, interrupt, ...observation } = await executeObservedTellAkuma(input);
42
+ return completeTell({ akumaId, tellId, ...(wake === undefined ? {} : { wake }), ...(interrupt === undefined ? {} : { interrupt }) }, observation.kind === "invalid-output" ? { kind: "failed", diagnostic: observation.diagnostic } : observation);
43
+ }
44
+ const { owner, admission, receipt } = await admitExecutionTell(input);
45
+ let tell = receipt;
41
46
  try {
42
47
  tell = await ("wake" in admission
43
48
  ? admission.wake
@@ -49,22 +54,24 @@ export async function executeTellAkuma(input) {
49
54
  throw withTellFailureReceipt(error, completeTell(tellAdmissionEvidence(input.id, tell)), input.signal);
50
55
  }
51
56
  }
52
- function askObservation(observed) {
57
+ function tellObservation(observed) {
53
58
  if (observed.outcome === null)
54
59
  return observed.reason === "deadline" ? { kind: "deadline" } : { kind: "unanswered" };
55
60
  if (observed.outcome.kind === "canceled")
56
61
  return { kind: "unanswered" };
62
+ const completedAt = observed.completedAt === null ? {} : { completedAt: observed.completedAt };
57
63
  if (observed.outcome.kind === "answered")
58
- return { kind: "answered", answer: observed.outcome.answerJson ?? observed.outcome.answer };
64
+ return { kind: "answered", answer: observed.outcome.answerJson ?? observed.outcome.answer, ...completedAt };
59
65
  if (observed.outcome.kind === "failed")
60
- return { kind: "failed", diagnostic: observed.outcome.diagnostic };
66
+ return { kind: "failed", diagnostic: observed.outcome.diagnostic, ...completedAt };
61
67
  return {
62
68
  kind: "invalid-output",
63
69
  diagnostic: observed.outcome.diagnostic,
64
70
  answer: observed.outcome.answer,
71
+ ...completedAt,
65
72
  };
66
73
  }
67
- export async function observeAdmittedAskAkuma(input) {
74
+ export async function observeAdmittedTellAkuma(input) {
68
75
  const owner = new AkumaOwner(input.id, input.path, input.outcomeObserved);
69
76
  const tell = input.receipt ?? (await owner.admittedReceipt(input.tellId));
70
77
  await input.onObserve?.admitted?.(tell, input.id);
@@ -102,35 +109,27 @@ export async function observeAdmittedAskAkuma(input) {
102
109
  throw withTellFailureReceipt(error, completeTell(tellAdmissionEvidence(input.id, settled ?? tell)), input.signal);
103
110
  }
104
111
  const receipt = tellAdmissionEvidence(input.id, settled ?? tell);
105
- const observation = askObservation(observed);
112
+ const observation = tellObservation(observed);
106
113
  const { wake, ...subject } = receipt;
107
114
  return observation.kind === "unanswered" || observation.kind === "deadline"
108
115
  ? { ...subject, ...(wake === undefined ? {} : { wake }), ...observation }
109
116
  : { ...subject, ...(wake?.kind === "failed" ? { wake } : {}), ...observation };
110
117
  }
111
118
  export async function executeAskAkuma(input) {
112
- input.signal?.throwIfAborted();
113
- const owner = new AkumaOwner(input.id, input.path);
114
- const admission = input.interrupt === true
115
- ? await owner.admitInterrupt(input.body, input)
116
- : await owner.admitTell(input.body, input.tellId, input.recordedAt, tellWakeRuntime(input.spawn), input);
117
- if (admission.kind === "not-born")
118
- throw new AkumaNotBornError(input.id);
119
- if (admission.kind === "unavailable")
120
- throw new AkumaProviderError(`Tell interrupt unavailable: ${admission.evidence}`);
119
+ const result = await executeObservedTellAkuma(input);
120
+ return result.kind === "answered" && input.schemaJson !== undefined
121
+ ? { ...result, answer: JSON.parse(result.answer) }
122
+ : result;
123
+ }
124
+ async function executeObservedTellAkuma(input) {
125
+ const { owner, admission, receipt } = await admitExecutionTell(input);
121
126
  const observing = new AbortController();
122
127
  const signal = input.signal === undefined ? observing.signal : AbortSignal.any([input.signal, observing.signal]);
123
128
  const wake = "wake" in admission
124
129
  ? admission.wake
125
130
  : owner.completeInterruptAdmission(admission, tellWakeRuntime(input.spawn), signal);
126
- const receipt = {
127
- ...pendingTellReceipt(admission.tell),
128
- ...("barrier" in admission && admission.barrier !== undefined
129
- ? { interruption: { kind: "pending", bodySequence: admission.barrier.bodySequence } }
130
- : {}),
131
- };
132
131
  try {
133
- return await observeAdmittedAskAkuma({
132
+ return await observeAdmittedTellAkuma({
134
133
  ...input,
135
134
  tellId: admission.tell.id,
136
135
  receipt,
@@ -1,7 +1,7 @@
1
1
  import type { WorldRoot } from "../world.js";
2
2
  import { type LiveStatusObservation, type WaitReason, type OutcomeObserver } from "./akuma-observe.js";
3
3
  import type { AkumaStatus } from "./akuma.js";
4
- import type { AkumaWaitItem } from "./selection-observation.js";
4
+ import type { AkumaUnobserved, AkumaWaitItem } from "./selection-observation.js";
5
5
  type WaitExecutionInput = Readonly<{
6
6
  path: WorldRoot;
7
7
  ids: readonly AkumaStatus["id"][];
@@ -18,6 +18,45 @@ export type NativeWaitResult = Readonly<{
18
18
  observations: readonly LiveStatusObservation["status"][];
19
19
  results: readonly AkumaWaitItem[];
20
20
  }>;
21
+ export declare const AKUMA_WAIT_POLL_MS = 250;
22
+ /** Private observation custody shared by native and invocation set waits. */
23
+ export declare function createAkumaWaitObserver(path: WorldRoot, ids: readonly AkumaStatus["id"][]): {
24
+ items: Map<import("./identity.js").AkumaId, Readonly<{
25
+ kind: "observed";
26
+ id: import("./identity.js").AkumaId;
27
+ life: "hung" | "untidy" | "killed" | "running" | "asleep" | "stranded";
28
+ pending?: true;
29
+ outcome?: Readonly<{
30
+ kind: "answered";
31
+ historyId: `turn/${number}`;
32
+ answer: string;
33
+ }> | Readonly<{
34
+ kind: "failed";
35
+ historyId: `turn/${number}`;
36
+ diagnostic: string;
37
+ }> | Readonly<{
38
+ kind: "canceled";
39
+ historyId: `turn/${number}`;
40
+ }>;
41
+ strandedReason?: "resume-unsupported";
42
+ }> | Readonly<{
43
+ kind: "unobserved";
44
+ id: import("./identity.js").AkumaId;
45
+ diagnostic: string;
46
+ }> | Readonly<{
47
+ kind: "missing";
48
+ id: import("./identity.js").AkumaId;
49
+ }>>;
50
+ satisfied: (id: AkumaStatus["id"]) => boolean;
51
+ observe: (signal?: AbortSignal) => Promise<Readonly<{
52
+ observations: readonly LiveStatusObservation[];
53
+ unobserved: readonly AkumaUnobserved[];
54
+ missing: readonly AkumaStatus["id"][];
55
+ }>>;
56
+ probe: (completion: "any" | "all", signal?: AbortSignal) => Promise<boolean>;
57
+ notify(observer?: OutcomeObserver): Promise<void>;
58
+ clear: () => void;
59
+ };
21
60
  /** Compact final native evidence, retaining full statuses privately for owner composition. */
22
61
  export declare function executeWaitAkuma(input: WaitExecutionInput): Promise<NativeWaitResult>;
23
62
  export {};
@@ -2,7 +2,8 @@ import { AkumaNotBornError } from "./akuma-errors.js";
2
2
  import { createLiveStatusReader, defaultWaitComplete, readWaitComplete, waitForObservation, } from "./akuma-observe.js";
3
3
  import { pathsForAkumaId } from "./identity.js";
4
4
  const SHARED_ORDINARY_BUDGET = 30;
5
- async function observeWaitRound(ids, readerFor, signal) {
5
+ export const AKUMA_WAIT_POLL_MS = 250;
6
+ async function observeWaitRound(ids, readerFor, signal, witnessed) {
6
7
  const read = (id, ordinaryBudget) => readerFor(id).read({ aperture: "monitoring", ...(ordinaryBudget === undefined ? {} : { ordinaryBudget }) }, signal);
7
8
  signal?.throwIfAborted();
8
9
  let remaining = SHARED_ORDINARY_BUDGET;
@@ -14,14 +15,20 @@ async function observeWaitRound(ids, readerFor, signal) {
14
15
  try {
15
16
  const observed = await read(id, remaining);
16
17
  observations.push(observed);
18
+ witnessed?.(completionItem(observed), observed);
17
19
  remaining -= observed.ordinarySelected;
18
20
  }
19
21
  catch (error) {
20
22
  signal?.throwIfAborted();
21
- if (error instanceof AkumaNotBornError)
23
+ if (error instanceof AkumaNotBornError) {
22
24
  missing.push(id);
23
- else
24
- unobserved.push({ id, diagnostic: diagnostic(error) });
25
+ witnessed?.({ kind: "missing", id });
26
+ }
27
+ else {
28
+ const item = { id, diagnostic: diagnostic(error) };
29
+ unobserved.push(item);
30
+ witnessed?.({ kind: "unobserved", ...item });
31
+ }
25
32
  }
26
33
  }
27
34
  return { observations, unobserved, missing };
@@ -56,55 +63,77 @@ function completionItem({ status, rows }) {
56
63
  ...(status.strandedReason === undefined ? {} : { strandedReason: status.strandedReason }),
57
64
  };
58
65
  }
59
- /** Compact final native evidence, retaining full statuses privately for owner composition. */
60
- export async function executeWaitAkuma(input) {
66
+ /** Private observation custody shared by native and invocation set waits. */
67
+ export function createAkumaWaitObserver(path, ids) {
61
68
  const readers = new Map();
69
+ const items = new Map();
70
+ const observations = new Map();
62
71
  const readerFor = (id) => {
63
72
  let reader = readers.get(id);
64
73
  if (reader === undefined) {
65
- reader = createLiveStatusReader(pathsForAkumaId(input.path, id), id);
74
+ reader = createLiveStatusReader(pathsForAkumaId(path, id), id);
66
75
  readers.set(id, reader);
67
76
  }
68
77
  return reader;
69
78
  };
79
+ return {
80
+ items,
81
+ satisfied: (id) => {
82
+ const observation = observations.get(id);
83
+ return items.get(id)?.kind === "observed" && observation !== undefined && defaultWaitComplete(observation.status);
84
+ },
85
+ observe: (signal) => observeWaitRound(ids, readerFor, signal, (item, observation) => {
86
+ items.set(item.id, item);
87
+ if (observation === undefined)
88
+ observations.delete(item.id);
89
+ else
90
+ observations.set(item.id, observation);
91
+ }),
92
+ probe: (completion, signal) => readWaitComplete(path, ids, completion, signal, (id) => readerFor(id)
93
+ .complete(signal)
94
+ .catch((error) => {
95
+ if (error instanceof AkumaNotBornError)
96
+ return true;
97
+ throw error;
98
+ })),
99
+ async notify(observer) {
100
+ for (const { status, rows } of observations.values()) {
101
+ const outcome = rows.findLast((row) => row.kind === "outcome");
102
+ if (outcome !== undefined)
103
+ await observer?.(status.id, [`turn/${outcome.turnSequence}`]);
104
+ }
105
+ },
106
+ clear: () => {
107
+ for (const reader of readers.values())
108
+ reader.clear();
109
+ },
110
+ };
111
+ }
112
+ /** Compact final native evidence, retaining full statuses privately for owner composition. */
113
+ export async function executeWaitAkuma(input) {
114
+ const observer = createAkumaWaitObserver(input.path, input.ids);
70
115
  try {
71
116
  const waited = await waitForObservation({
72
- pollMs: 250,
117
+ pollMs: AKUMA_WAIT_POLL_MS,
73
118
  ...(input.timeoutMs === undefined ? {} : { timeoutMs: input.timeoutMs }),
74
119
  ...(input.signal === undefined ? {} : { signal: input.signal }),
75
120
  ...(input.predicate === undefined
76
121
  ? {
77
- probe: async () => await readWaitComplete(input.path, input.ids, input.completion, input.signal, (id) => readerFor(id)
78
- .complete(input.signal)
79
- .catch((error) => {
80
- if (error instanceof AkumaNotBornError)
81
- return true;
82
- throw error;
83
- })),
122
+ probe: () => observer.probe(input.completion, input.signal),
84
123
  }
85
124
  : {}),
86
- observe: async () => await observeWaitRound(input.ids, readerFor, input.signal),
125
+ observe: () => observer.observe(input.signal),
87
126
  complete: (round) => roundComplete(round, input.completion, input.predicate),
88
127
  });
89
- for (const { status, rows } of waited.value.observations) {
90
- const outcome = rows.findLast((row) => row.kind === "outcome");
91
- if (outcome !== undefined)
92
- await input.outcomeObserved?.(status.id, [`turn/${outcome.turnSequence}`]);
93
- }
94
- const items = new Map(waited.value.observations.map((observation) => [observation.status.id, completionItem(observation)]));
95
- for (const item of waited.value.unobserved)
96
- items.set(item.id, { kind: "unobserved", ...item });
97
- for (const id of waited.value.missing)
98
- items.set(id, { kind: "missing", id });
128
+ await observer.notify(input.outcomeObserved);
99
129
  return {
100
130
  reason: waited.reason,
101
131
  observations: waited.value.observations.map((observation) => observation.status),
102
- results: input.ids.map((id) => items.get(id)),
132
+ results: input.ids.map((id) => observer.items.get(id)),
103
133
  };
104
134
  }
105
135
  finally {
106
- for (const reader of readers.values())
107
- reader.clear();
136
+ observer.clear();
108
137
  }
109
138
  }
110
139
  function diagnostic(error) {
@@ -84,6 +84,17 @@ export declare const akumaStatusSchema: z.ZodReadonly<z.ZodObject<{
84
84
  toolId: z.ZodString;
85
85
  }, z.core.$strict>>>>>;
86
86
  latestActivity: z.ZodExactOptional<z.ZodNumber>;
87
+ awaiting: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
88
+ kind: z.ZodLiteral<"permission">;
89
+ id: z.ZodNumber;
90
+ requests: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
91
+ id: z.ZodString;
92
+ action: z.ZodString;
93
+ resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
94
+ tool: z.ZodExactOptional<z.ZodString>;
95
+ }, z.core.$strict>>>>;
96
+ clipped: z.ZodExactOptional<z.ZodLiteral<true>>;
97
+ }, z.core.$strict>>>;
87
98
  pending: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
88
99
  id: z.ZodNumber;
89
100
  tellId: z.ZodString;