@astrosheep/keiyaku 4.6.32 → 4.6.34

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 (244) hide show
  1. package/README.md +18 -7
  2. package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +18 -11
  3. package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +8 -6
  4. package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +2 -1
  5. package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +2 -1
  6. package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +18 -11
  7. package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +8 -6
  8. package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +2 -1
  9. package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +2 -1
  10. package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +18 -11
  11. package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +8 -6
  12. package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +2 -1
  13. package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +2 -1
  14. package/build/plugins/pi/README.md +55 -97
  15. package/build/plugins/pi/keiyaku.ts +1 -142
  16. package/build/skills/keiyaku-akuma/SKILL.md +18 -11
  17. package/build/skills/keiyaku-babysit/SKILL.md +8 -6
  18. package/build/skills/keiyaku-debt/SKILL.md +2 -1
  19. package/build/skills/keiyaku-workflow/SKILL.md +2 -1
  20. package/build/src/akuma/akuma-instance.d.ts +11 -0
  21. package/build/src/akuma/akuma-instance.js +1 -2
  22. package/build/src/akuma/akuma-observe.d.ts +8 -0
  23. package/build/src/akuma/akuma-observe.js +81 -14
  24. package/build/src/akuma/akuma-owner.d.ts +1 -0
  25. package/build/src/akuma/akuma-owner.js +3 -5
  26. package/build/src/akuma/akuma-selection-execution.d.ts +82 -7
  27. package/build/src/akuma/akuma-selection-execution.js +26 -27
  28. package/build/src/akuma/akuma-wait.d.ts +155 -1
  29. package/build/src/akuma/akuma-wait.js +94 -34
  30. package/build/src/akuma/akuma.d.ts +17 -1
  31. package/build/src/akuma/akuma.js +37 -18
  32. package/build/src/akuma/body.js +13 -18
  33. package/build/src/akuma/call-initial-tell.d.ts +0 -1
  34. package/build/src/akuma/call-initial-tell.js +0 -1
  35. package/build/src/akuma/heart/activity-schema.d.ts +16 -0
  36. package/build/src/akuma/heart/activity-schema.js +7 -0
  37. package/build/src/akuma/heart/facts.d.ts +1 -0
  38. package/build/src/akuma/heart/facts.js +14 -0
  39. package/build/src/akuma/heart/index.d.ts +7 -1
  40. package/build/src/akuma/heart/index.js +35 -9
  41. package/build/src/akuma/heart/rows.d.ts +1 -0
  42. package/build/src/akuma/heart/rows.js +4 -0
  43. package/build/src/akuma/heart/timeline.js +4 -4
  44. package/build/src/akuma/lineage-cache.d.ts +7 -2
  45. package/build/src/akuma/lineage-cache.js +48 -24
  46. package/build/src/akuma/projection-read.d.ts +4 -2
  47. package/build/src/akuma/projection-read.js +25 -23
  48. package/build/src/akuma/projection.d.ts +94 -2
  49. package/build/src/akuma/projection.js +47 -47
  50. package/build/src/akuma/provider.d.ts +2 -2
  51. package/build/src/akuma/provider.js +27 -20
  52. package/build/src/akuma/providers/acp/core.js +2 -5
  53. package/build/src/akuma/providers/opencode-sdk/events.d.ts +2 -1
  54. package/build/src/akuma/providers/opencode-sdk/events.js +31 -1
  55. package/build/src/akuma/publication.js +3 -2
  56. package/build/src/akuma/selection-observation.d.ts +645 -0
  57. package/build/src/akuma/selection-observation.js +22 -7
  58. package/build/src/akuma/status-projection.d.ts +14 -1
  59. package/build/src/akuma/status-projection.js +40 -2
  60. package/build/src/akuma/turn-drive.js +21 -15
  61. package/build/src/body/amend.js +5 -17
  62. package/build/src/body/decode.js +11 -1
  63. package/build/src/body/envelope.d.ts +5 -1
  64. package/build/src/body/envelope.js +4 -2
  65. package/build/src/body/render.js +4 -6
  66. package/build/src/bounded-list.d.ts +8 -0
  67. package/build/src/bounded-list.js +10 -0
  68. package/build/src/cli/commands/akuma-grammar.d.ts +5 -8
  69. package/build/src/cli/commands/akuma-grammar.js +52 -77
  70. package/build/src/cli/commands/akuma.d.ts +1 -2
  71. package/build/src/cli/commands/akuma.js +12 -61
  72. package/build/src/cli/commands/contract-grammar.d.ts +1 -0
  73. package/build/src/cli/commands/contract-grammar.js +39 -42
  74. package/build/src/cli/commands/contract-help.d.ts +6 -5
  75. package/build/src/cli/commands/contract-help.js +21 -13
  76. package/build/src/cli/commands/contract.d.ts +3 -3
  77. package/build/src/cli/commands/contract.js +13 -9
  78. package/build/src/cli/commands/debt-grammar.js +2 -4
  79. package/build/src/cli/parse.d.ts +4 -10
  80. package/build/src/cli/parse.js +2 -5
  81. package/build/src/cli/render/akuma-activity.d.ts +12 -34
  82. package/build/src/cli/render/akuma-activity.js +99 -180
  83. package/build/src/cli/render/akuma.d.ts +5 -11
  84. package/build/src/cli/render/akuma.js +22 -30
  85. package/build/src/cli/render/catalog.js +4 -6
  86. package/build/src/cli/render/contract-history.d.ts +1 -3
  87. package/build/src/cli/render/contract-history.js +70 -49
  88. package/build/src/cli/render/contract-observation.d.ts +2 -1
  89. package/build/src/cli/render/contract-observation.js +25 -1
  90. package/build/src/cli/render/contract-wait.d.ts +2 -2
  91. package/build/src/cli/render/contract-wait.js +21 -17
  92. package/build/src/cli/render/contract.js +12 -9
  93. package/build/src/cli/render/debt.js +1 -2
  94. package/build/src/cli/render/execution-progress.js +1 -3
  95. package/build/src/cli/render/kanshi-akuma.d.ts +4 -3
  96. package/build/src/cli/render/kanshi-akuma.js +27 -23
  97. package/build/src/cli/render/kanshi.js +45 -60
  98. package/build/src/cli/render/receipt.d.ts +1 -1
  99. package/build/src/cli/render/receipt.js +33 -28
  100. package/build/src/cli/render/reconcile.js +2 -5
  101. package/build/src/cli/render/refusal.js +3 -6
  102. package/build/src/cli/render/terminal.d.ts +2 -4
  103. package/build/src/cli/render/terminal.js +10 -17
  104. package/build/src/cli/render/verbs.d.ts +1 -0
  105. package/build/src/cli/render/verbs.js +39 -34
  106. package/build/src/cli/runtime.js +12 -32
  107. package/build/src/core/facts/codec.js +7 -2
  108. package/build/src/core/facts/eligibility.d.ts +4 -4
  109. package/build/src/core/facts/eligibility.js +11 -0
  110. package/build/src/core/facts/fold.js +9 -5
  111. package/build/src/core/facts/gate.d.ts +5 -1
  112. package/build/src/core/facts/gate.js +14 -10
  113. package/build/src/core/facts/types.d.ts +5 -1
  114. package/build/src/core/facts/types.js +7 -0
  115. package/build/src/core/subject.d.ts +4 -1
  116. package/build/src/core/subject.js +10 -2
  117. package/build/src/core/verbs/amend.d.ts +15 -4
  118. package/build/src/core/verbs/amend.js +19 -9
  119. package/build/src/debt/board.d.ts +2 -1
  120. package/build/src/debt/board.js +3 -3
  121. package/build/src/debt/catalog.js +2 -1
  122. package/build/src/debt/document.d.ts +1 -0
  123. package/build/src/debt/document.js +3 -0
  124. package/build/src/debt/index.d.ts +2 -2
  125. package/build/src/debt/index.js +9 -14
  126. package/build/src/debt/input.d.ts +2 -1
  127. package/build/src/debt/input.js +6 -4
  128. package/build/src/debt/operations.d.ts +2 -1
  129. package/build/src/dispatch/index.d.ts +0 -17
  130. package/build/src/dispatch/index.js +1 -10
  131. package/build/src/git/identity.js +16 -45
  132. package/build/src/git/nuke.js +13 -23
  133. package/build/src/git/observe.d.ts +7 -3
  134. package/build/src/git/observe.js +29 -26
  135. package/build/src/git/process.js +11 -18
  136. package/build/src/git/read-observation.d.ts +5 -4
  137. package/build/src/git/repository.d.ts +2 -0
  138. package/build/src/git/repository.js +13 -1
  139. package/build/src/git/scratch.js +2 -14
  140. package/build/src/git/terminal-reconcile.js +1 -13
  141. package/build/src/history.d.ts +26 -0
  142. package/build/src/history.js +43 -0
  143. package/build/src/index.d.ts +6 -3
  144. package/build/src/kanshi/counts.d.ts +15 -1
  145. package/build/src/kanshi/counts.js +14 -3
  146. package/build/src/kanshi/index.d.ts +3 -4
  147. package/build/src/kanshi/index.js +2 -3
  148. package/build/src/kanshi/read.d.ts +21 -0
  149. package/build/src/kanshi/read.js +7 -3
  150. package/build/src/kanshi/report.d.ts +94 -0
  151. package/build/src/library/address.d.ts +12 -5
  152. package/build/src/library/address.js +18 -32
  153. package/build/src/library/akuma-creation.d.ts +39 -0
  154. package/build/src/library/akuma-creation.js +3 -9
  155. package/build/src/library/akumas.d.ts +5 -1
  156. package/build/src/library/akumas.js +11 -5
  157. package/build/src/library/continuation.d.ts +10 -0
  158. package/build/src/library/contract-composition.js +10 -10
  159. package/build/src/library/contract-creation.js +12 -13
  160. package/build/src/library/contract-outcomes.d.ts +72 -1
  161. package/build/src/library/contract-outcomes.js +1 -0
  162. package/build/src/library/contract-types.d.ts +233 -25
  163. package/build/src/library/contract-types.js +32 -12
  164. package/build/src/library/contract-wait.d.ts +212 -0
  165. package/build/src/library/contract-wait.js +65 -49
  166. package/build/src/library/delivery.d.ts +25 -0
  167. package/build/src/library/input.d.ts +8 -26
  168. package/build/src/library/input.js +17 -12
  169. package/build/src/library/kei.js +167 -90
  170. package/build/src/library/keiyaku-attribution.d.ts +1 -1
  171. package/build/src/library/keiyaku-attribution.js +3 -1
  172. package/build/src/library/keiyaku-classify.js +8 -4
  173. package/build/src/library/keiyaku-debt.d.ts +8 -7
  174. package/build/src/library/keiyaku-debt.js +1 -2
  175. package/build/src/library/keiyaku-identity.d.ts +4 -3
  176. package/build/src/library/keiyaku-identity.js +35 -7
  177. package/build/src/library/keiyaku-verbs.d.ts +974 -1409
  178. package/build/src/library/keiyaku-verbs.js +154 -161
  179. package/build/src/library/keiyaku-wait.d.ts +753 -0
  180. package/build/src/library/keiyaku-wait.js +230 -0
  181. package/build/src/library/keiyaku.d.ts +3110 -29
  182. package/build/src/library/keiyaku.js +342 -438
  183. package/build/src/library/model-tools.d.ts +754 -0
  184. package/build/src/library/model-tools.js +362 -0
  185. package/build/src/library/outcome.js +5 -6
  186. package/build/src/library/refusal.d.ts +25 -1
  187. package/build/src/library/refusal.js +4 -5
  188. package/build/src/library/selection.d.ts +18 -5
  189. package/build/src/library/selection.js +11 -5
  190. package/build/src/mcp/adapter.d.ts +0 -6
  191. package/build/src/mcp/adapter.js +11 -160
  192. package/build/src/mcp/description.d.ts +2 -0
  193. package/build/src/mcp/description.js +2 -0
  194. package/build/src/mcp/help.d.ts +1 -1
  195. package/build/src/mcp/help.js +10 -7
  196. package/build/src/pi/index.d.ts +5 -0
  197. package/build/src/pi/index.js +99 -0
  198. package/build/src/pi/status.d.ts +12 -0
  199. package/build/src/pi/status.js +140 -0
  200. package/build/src/protocol/amend.d.ts +14 -3
  201. package/build/src/protocol/amend.js +113 -46
  202. package/build/src/protocol/bind.d.ts +1 -1
  203. package/build/src/protocol/bind.js +5 -16
  204. package/build/src/protocol/completion.d.ts +30 -0
  205. package/build/src/protocol/completion.js +8 -5
  206. package/build/src/protocol/deliver.js +7 -20
  207. package/build/src/protocol/delivery-preview.d.ts +5 -0
  208. package/build/src/protocol/execution-observation.d.ts +8 -0
  209. package/build/src/protocol/intent.d.ts +1 -0
  210. package/build/src/protocol/intent.js +4 -1
  211. package/build/src/protocol/operations.d.ts +56 -16
  212. package/build/src/protocol/operations.js +18 -32
  213. package/build/src/protocol/placement.js +7 -1
  214. package/build/src/protocol/progress.js +0 -6
  215. package/build/src/protocol/read/status.d.ts +52 -4
  216. package/build/src/protocol/read/status.js +26 -22
  217. package/build/src/protocol/reintegrate.js +2 -2
  218. package/build/src/protocol/result-leaves.d.ts +56 -8
  219. package/build/src/protocol/result-leaves.js +11 -2
  220. package/build/src/protocol/run.js +1 -4
  221. package/build/src/protocol/verify.d.ts +10 -0
  222. package/build/src/protocol/verify.js +1 -0
  223. package/build/src/runtime/proc/windows-launch.exe +0 -0
  224. package/build/src/settlement/settle.js +19 -68
  225. package/package.json +7 -3
  226. package/plugins/paseo/plugin/index.server.ts +6 -2
  227. package/plugins/paseo/plugin/server/attach.ts +68 -48
  228. package/plugins/paseo/plugin/server/directory.ts +259 -0
  229. package/plugins/paseo/plugin/server/mirror-identity.ts +3 -32
  230. package/plugins/paseo/plugin/server/reopen.ts +52 -38
  231. package/plugins/pi/README.md +55 -97
  232. package/plugins/pi/keiyaku.ts +1 -142
  233. package/skills/keiyaku-akuma/SKILL.md +18 -11
  234. package/skills/keiyaku-babysit/SKILL.md +8 -6
  235. package/skills/keiyaku-debt/SKILL.md +2 -1
  236. package/skills/keiyaku-workflow/SKILL.md +2 -1
  237. package/build/plugins/pi/akuma-tools.ts +0 -283
  238. package/build/src/body/keys.d.ts +0 -4
  239. package/build/src/body/keys.js +0 -11
  240. package/build/src/kanshi/roster.d.ts +0 -2
  241. package/build/src/kanshi/roster.js +0 -2
  242. package/build/src/mcp/output.d.ts +0 -385
  243. package/build/src/mcp/output.js +0 -193
  244. package/plugins/pi/akuma-tools.ts +0 -283
@@ -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,160 @@ 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"][], lightweight?: boolean): {
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
+ lastActivityAt?: string;
29
+ events?: readonly (Readonly<{
30
+ kind: "tell";
31
+ sequence: number;
32
+ at: string;
33
+ tellId: string;
34
+ text: string;
35
+ state: "pending" | "told";
36
+ deliveries: readonly Readonly<{
37
+ deliveredAt: string;
38
+ route: "launch" | "live";
39
+ turnSequence: number;
40
+ }>[];
41
+ }> | Readonly<{
42
+ kind: "report";
43
+ sequence: number;
44
+ bodySequence: number;
45
+ turnSequence: number;
46
+ text: string;
47
+ at: string;
48
+ }> | Readonly<{
49
+ kind: "permission";
50
+ sequence: number;
51
+ turnSequence: number;
52
+ at: string;
53
+ requests: readonly Readonly<{
54
+ id: string;
55
+ action: string;
56
+ resources: readonly string[];
57
+ tool?: string;
58
+ }>[];
59
+ truncated?: true;
60
+ }> | Readonly<{
61
+ kind: "call";
62
+ sequence: number;
63
+ turnSequence: number;
64
+ at: string;
65
+ text: string;
66
+ }> | Readonly<{
67
+ kind: "thought" | "note" | "said";
68
+ sequence: number;
69
+ turnSequence: number;
70
+ at: string;
71
+ text: string;
72
+ truncated?: true;
73
+ }> | Readonly<{
74
+ kind: "turn";
75
+ sequence: number;
76
+ bodySequence: number;
77
+ at: string;
78
+ }> | Readonly<{
79
+ kind: "outcome";
80
+ sequence: number;
81
+ turnSequence: number;
82
+ at: string;
83
+ outcome: Readonly<{
84
+ kind: "answered";
85
+ answer: string;
86
+ foldedSaidSequence?: number;
87
+ }> | Readonly<{
88
+ kind: "failed";
89
+ diagnostic: string;
90
+ }> | Readonly<{
91
+ kind: "canceled";
92
+ }>;
93
+ }> | Readonly<{
94
+ kind: "tool";
95
+ sequence: number;
96
+ turnSequence: number;
97
+ at: string;
98
+ name: string;
99
+ call: Readonly<{
100
+ kind: "run";
101
+ command: string;
102
+ }> | Readonly<{
103
+ kind: "read";
104
+ path: string;
105
+ offset?: number;
106
+ limit?: number;
107
+ }> | Readonly<{
108
+ kind: "search";
109
+ query: string;
110
+ scope?: "content" | "files" | "web";
111
+ path?: string;
112
+ glob?: string;
113
+ }> | Readonly<{
114
+ kind: "fileChange";
115
+ changes: readonly Readonly<{
116
+ op: "add" | "update" | "delete" | "unspecified";
117
+ path: string;
118
+ diffstat?: Readonly<{
119
+ added: number;
120
+ removed: number;
121
+ }>;
122
+ patch?: string;
123
+ }>[];
124
+ }> | Readonly<{
125
+ kind: "other";
126
+ input?: Readonly<{
127
+ json: string;
128
+ truncated?: true;
129
+ }>;
130
+ }>;
131
+ toolId: string;
132
+ state: "active" | "unsettled" | Readonly<{
133
+ status: "error" | "ok";
134
+ message?: string;
135
+ output?: string;
136
+ exitCode?: number;
137
+ }>;
138
+ durationMs?: number;
139
+ truncated?: true;
140
+ }>)[];
141
+ eventsUnavailable?: string;
142
+ pending?: true;
143
+ outcome?: Readonly<{
144
+ kind: "answered";
145
+ historyId: `turn/${number}`;
146
+ answer: string;
147
+ }> | Readonly<{
148
+ kind: "failed";
149
+ historyId: `turn/${number}`;
150
+ diagnostic: string;
151
+ }> | Readonly<{
152
+ kind: "canceled";
153
+ historyId: `turn/${number}`;
154
+ }>;
155
+ strandedReason?: "resume-unsupported";
156
+ }> | Readonly<{
157
+ kind: "unobserved";
158
+ id: import("./identity.js").AkumaId;
159
+ diagnostic: string;
160
+ }> | Readonly<{
161
+ kind: "missing";
162
+ id: import("./identity.js").AkumaId;
163
+ }>>;
164
+ satisfied: (id: AkumaStatus["id"]) => boolean;
165
+ observe: (signal?: AbortSignal, recent?: boolean) => Promise<Readonly<{
166
+ observations: readonly LiveStatusObservation[];
167
+ unobserved: readonly AkumaUnobserved[];
168
+ missing: readonly AkumaStatus["id"][];
169
+ }>>;
170
+ unavailableRecent(message: string): void;
171
+ probe: (completion: "any" | "all", signal?: AbortSignal) => Promise<boolean>;
172
+ notify(observer?: OutcomeObserver): Promise<void>;
173
+ clear: () => void;
174
+ };
21
175
  /** Compact final native evidence, retaining full statuses privately for owner composition. */
22
176
  export declare function executeWaitAkuma(input: WaitExecutionInput): Promise<NativeWaitResult>;
23
177
  export {};
@@ -1,8 +1,10 @@
1
1
  import { AkumaNotBornError } from "./akuma-errors.js";
2
- import { createLiveStatusReader, defaultWaitComplete, readWaitComplete, waitForObservation, } from "./akuma-observe.js";
2
+ import { createLiveStatusReader, defaultWaitComplete, executionProgress, readWaitComplete, waitForObservation, } from "./akuma-observe.js";
3
3
  import { pathsForAkumaId } from "./identity.js";
4
+ import { projectTurns } from "./projection.js";
4
5
  const SHARED_ORDINARY_BUDGET = 30;
5
- async function observeWaitRound(ids, readerFor, signal) {
6
+ export const AKUMA_WAIT_POLL_MS = 250;
7
+ async function observeWaitRound(ids, readerFor, signal, witnessed, mode = { lightweight: false, recent: false }) {
6
8
  const read = (id, ordinaryBudget) => readerFor(id).read({ aperture: "monitoring", ...(ordinaryBudget === undefined ? {} : { ordinaryBudget }) }, signal);
7
9
  signal?.throwIfAborted();
8
10
  let remaining = SHARED_ORDINARY_BUDGET;
@@ -12,16 +14,28 @@ async function observeWaitRound(ids, readerFor, signal) {
12
14
  for (const id of ids) {
13
15
  signal?.throwIfAborted();
14
16
  try {
15
- const observed = await read(id, remaining);
16
- observations.push(observed);
17
- remaining -= observed.ordinarySelected;
17
+ if (mode.lightweight) {
18
+ const item = completionSnapshot(await readerFor(id).wait(mode.recent, signal));
19
+ witnessed?.(item);
20
+ }
21
+ else {
22
+ const observed = await read(id, remaining);
23
+ observations.push(observed);
24
+ witnessed?.(completionItem(observed));
25
+ remaining -= observed.ordinarySelected;
26
+ }
18
27
  }
19
28
  catch (error) {
20
29
  signal?.throwIfAborted();
21
- if (error instanceof AkumaNotBornError)
30
+ if (error instanceof AkumaNotBornError) {
22
31
  missing.push(id);
23
- else
24
- unobserved.push({ id, diagnostic: diagnostic(error) });
32
+ witnessed?.({ kind: "missing", id });
33
+ }
34
+ else {
35
+ const item = { id, diagnostic: diagnostic(error) };
36
+ unobserved.push(item);
37
+ witnessed?.({ kind: "unobserved", ...item });
38
+ }
25
39
  }
26
40
  }
27
41
  return { observations, unobserved, missing };
@@ -51,62 +65,108 @@ function completionItem({ status, rows }) {
51
65
  kind: "observed",
52
66
  id: status.id,
53
67
  life: status.life,
68
+ ...(status.lastActivityAt === undefined ? {} : { lastActivityAt: status.lastActivityAt }),
54
69
  ...(pending ? { pending: true } : {}),
55
70
  ...(outcome === undefined ? {} : { outcome: waitOutcome(outcome) }),
56
71
  ...(status.strandedReason === undefined ? {} : { strandedReason: status.strandedReason }),
57
72
  };
58
73
  }
59
- /** Compact final native evidence, retaining full statuses privately for owner composition. */
60
- export async function executeWaitAkuma(input) {
74
+ function completionSnapshot(snapshot) {
75
+ const turn = snapshot.turn;
76
+ const outcome = turn?.end === undefined ? undefined : projectTurns([turn, turn.end]).latestOutcome;
77
+ let events;
78
+ let eventsUnavailable = snapshot.activityDiagnostic;
79
+ if (snapshot.activity !== undefined && snapshot.life === "running") {
80
+ try {
81
+ events = projectTurns(snapshot.activity.rows).rows.slice(-3);
82
+ }
83
+ catch (error) {
84
+ eventsUnavailable = diagnostic(error);
85
+ }
86
+ }
87
+ return {
88
+ kind: "observed",
89
+ id: snapshot.id,
90
+ life: snapshot.life,
91
+ ...(snapshot.lastActivityAt === null ? {} : { lastActivityAt: snapshot.lastActivityAt }),
92
+ ...(snapshot.hasPendingTell ? { pending: true } : {}),
93
+ ...(outcome === undefined ? {} : { outcome: waitOutcome(outcome) }),
94
+ ...(events === undefined ? {} : { events }),
95
+ ...(eventsUnavailable === undefined ? {} : { eventsUnavailable: diagnostic(eventsUnavailable) }),
96
+ };
97
+ }
98
+ /** Private observation custody shared by native and invocation set waits. */
99
+ export function createAkumaWaitObserver(path, ids, lightweight = false) {
61
100
  const readers = new Map();
101
+ const items = new Map();
62
102
  const readerFor = (id) => {
63
103
  let reader = readers.get(id);
64
104
  if (reader === undefined) {
65
- reader = createLiveStatusReader(pathsForAkumaId(input.path, id), id);
105
+ reader = createLiveStatusReader(pathsForAkumaId(path, id), id);
66
106
  readers.set(id, reader);
67
107
  }
68
108
  return reader;
69
109
  };
110
+ return {
111
+ items,
112
+ satisfied: (id) => {
113
+ const item = items.get(id);
114
+ return item?.kind === "observed" && executionProgress(item.life, item.pending === true) !== "advancing";
115
+ },
116
+ observe: (signal, recent = false) => observeWaitRound(ids, readerFor, signal, (item) => items.set(item.id, item), { lightweight, recent }),
117
+ unavailableRecent(message) {
118
+ for (const [id, item] of items) {
119
+ if (item.kind === "observed" && item.life === "running" && item.events === undefined)
120
+ items.set(id, { ...item, eventsUnavailable: diagnostic(message) });
121
+ }
122
+ },
123
+ probe: (completion, signal) => readWaitComplete(path, ids, completion, signal, (id) => readerFor(id)
124
+ .complete(signal)
125
+ .catch((error) => {
126
+ if (error instanceof AkumaNotBornError)
127
+ return true;
128
+ throw error;
129
+ })),
130
+ async notify(observer) {
131
+ for (const item of items.values()) {
132
+ if (item.kind === "observed" && item.outcome !== undefined)
133
+ await observer?.(item.id, [item.outcome.historyId]);
134
+ }
135
+ },
136
+ clear: () => {
137
+ for (const reader of readers.values())
138
+ reader.clear();
139
+ },
140
+ };
141
+ }
142
+ /** Compact final native evidence, retaining full statuses privately for owner composition. */
143
+ export async function executeWaitAkuma(input) {
144
+ const observer = createAkumaWaitObserver(input.path, input.ids);
70
145
  try {
71
146
  const waited = await waitForObservation({
72
- pollMs: 250,
147
+ pollMs: AKUMA_WAIT_POLL_MS,
73
148
  ...(input.timeoutMs === undefined ? {} : { timeoutMs: input.timeoutMs }),
74
149
  ...(input.signal === undefined ? {} : { signal: input.signal }),
75
150
  ...(input.predicate === undefined
76
151
  ? {
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
- })),
152
+ probe: () => observer.probe(input.completion, input.signal),
84
153
  }
85
154
  : {}),
86
- observe: async () => await observeWaitRound(input.ids, readerFor, input.signal),
155
+ observe: () => observer.observe(input.signal),
87
156
  complete: (round) => roundComplete(round, input.completion, input.predicate),
88
157
  });
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 });
158
+ await observer.notify(input.outcomeObserved);
99
159
  return {
100
160
  reason: waited.reason,
101
161
  observations: waited.value.observations.map((observation) => observation.status),
102
- results: input.ids.map((id) => items.get(id)),
162
+ results: input.ids.map((id) => observer.items.get(id)),
103
163
  };
104
164
  }
105
165
  finally {
106
- for (const reader of readers.values())
107
- reader.clear();
166
+ observer.clear();
108
167
  }
109
168
  }
110
169
  function diagnostic(error) {
111
- return error instanceof Error ? error.message : String(error);
170
+ const message = error instanceof Error ? error.message : String(error);
171
+ return message.length <= 500 ? message : `${message.slice(0, 500)}...`;
112
172
  }
@@ -1,5 +1,6 @@
1
1
  import { type AkumaCaller } from "./caller.js";
2
2
  import { z } from "zod";
3
+ import { type LifecycleSelection } from "../bounded-list.js";
3
4
  import type { WorldRoot } from "../world.js";
4
5
  import { type AkumaId, type AkumaPaths } from "./identity.js";
5
6
  import type { ActivitySnapshot } from "./projection.js";
@@ -33,6 +34,7 @@ export type AkumaCompleteList = Readonly<{
33
34
  export type AkumaRosterInput = Readonly<{
34
35
  akumaName?: string;
35
36
  caller?: AkumaCaller;
37
+ selection?: LifecycleSelection;
36
38
  limit?: number;
37
39
  }>;
38
40
  export declare const akumaStatusSchema: z.ZodReadonly<z.ZodObject<{
@@ -84,6 +86,17 @@ export declare const akumaStatusSchema: z.ZodReadonly<z.ZodObject<{
84
86
  toolId: z.ZodString;
85
87
  }, z.core.$strict>>>>>;
86
88
  latestActivity: z.ZodExactOptional<z.ZodNumber>;
89
+ awaiting: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
90
+ kind: z.ZodLiteral<"permission">;
91
+ id: z.ZodNumber;
92
+ requests: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
93
+ id: z.ZodString;
94
+ action: z.ZodString;
95
+ resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
96
+ tool: z.ZodExactOptional<z.ZodString>;
97
+ }, z.core.$strict>>>>;
98
+ clipped: z.ZodExactOptional<z.ZodLiteral<true>>;
99
+ }, z.core.$strict>>>;
87
100
  pending: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
88
101
  id: z.ZodNumber;
89
102
  tellId: z.ZodString;
@@ -118,18 +131,21 @@ export declare function knownAkuma(path: WorldRoot, selected?: string): Promise<
118
131
  }>>;
119
132
  /** Exact running count requires every recognized coordinate to be readable. */
120
133
  export declare function countRunningAkuma(path: WorldRoot): Promise<number>;
134
+ /** Readable running subset of the same frozen caller tree used by listing. */
135
+ export declare function countCallerRunningAkuma(path: WorldRoot, caller: AkumaCaller): Promise<number>;
121
136
  export declare function rosterInput(input: AkumaRosterInput | Readonly<{
122
137
  akumaName?: string;
123
138
  }>, allowLimit: boolean): Readonly<{
124
139
  akumaName?: string;
125
140
  caller?: AkumaCaller;
141
+ selection?: LifecycleSelection;
126
142
  }>;
127
143
  /**
128
144
  * The bounded recent-activity roster: native membership, semantic order and
129
145
  * observed extent. A caller-scoped roster filters its World-local closure before
130
146
  * this same activity order and bound; World Alias context is attached above.
131
147
  */
132
- export declare function observeAkumaRoster(path: WorldRoot, limit: number, selected?: string, caller?: AkumaCaller): Promise<AkumaRosterPage>;
148
+ export declare function observeAkumaRoster(path: WorldRoot, limit: number, selected?: string, caller?: AkumaCaller, selection?: LifecycleSelection): Promise<AkumaRosterPage>;
133
149
  /** The complete native roster for callers whose semantics require a frozen set. */
134
150
  export declare function readAkumaCompleteRoster(path: WorldRoot, input?: Readonly<{
135
151
  akumaName?: string;
@@ -2,8 +2,9 @@ import { KeiyakuError } from "../errors.js";
2
2
  import { akumaBirthSchema, akumaCallerKey, decodeAkumaCaller } from "./caller.js";
3
3
  import { readdir, stat } from "node:fs/promises";
4
4
  import { z } from "zod";
5
- import { projectBoundedList } from "../bounded-list.js";
6
- import { rosterListRow } from "./akuma-observe.js";
5
+ import { projectBoundedList, lifecycleSelection } from "../bounded-list.js";
6
+ import { akumaLifecycle } from "./heart/facts.js";
7
+ import { readBornLife, rosterListRow } from "./akuma-observe.js";
7
8
  import { AkumaOwner } from "./akuma-owner.js";
8
9
  import { readSoul } from "./heart/index.js";
9
10
  import { akumaIdFromDirectoryName, akumaIdSchema, akumaPaths, akumaRunRoot, parseAkumaId, pathsForAkumaId, } from "./identity.js";
@@ -125,10 +126,26 @@ export async function countRunningAkuma(path) {
125
126
  throw new Error("Cannot classify every recognized Akuma", { cause: observed.failure });
126
127
  return observed.rows.filter((row) => row.life === "running").length;
127
128
  }
129
+ /** Readable running subset of the same frozen caller tree used by listing. */
130
+ export async function countCallerRunningAkuma(path, caller) {
131
+ const known = await knownAkuma(path);
132
+ const { edges } = await readDirectAkumaLineage(known.rows);
133
+ const members = callerClosure(edges, caller, path);
134
+ const running = await boundedMap(known.rows.filter(({ id }) => members.has(id)), async ({ id, paths }) => {
135
+ try {
136
+ return (await readBornLife(paths, id)) === "running" ? 1 : 0;
137
+ }
138
+ catch {
139
+ // Failed life does not erase the already proven Soul edge for descendants.
140
+ return 0;
141
+ }
142
+ });
143
+ return running.reduce((count, value) => count + value, 0);
144
+ }
128
145
  export function rosterInput(input, allowLimit) {
129
146
  if (typeof input !== "object" || input === null || Array.isArray(input))
130
147
  throw new KeiyakuError("invalid-input", "Akuma list input must be an object");
131
- const allowed = allowLimit ? ["akumaName", "caller", "limit"] : ["akumaName", "caller"];
148
+ const allowed = allowLimit ? ["akumaName", "caller", "selection", "limit"] : ["akumaName", "caller"];
132
149
  const unknown = Object.keys(input).find((key) => !allowed.includes(key));
133
150
  if (unknown !== undefined)
134
151
  throw new KeiyakuError("invalid-input", `Akuma list input has unknown field: ${unknown}`);
@@ -136,6 +153,7 @@ export function rosterInput(input, allowLimit) {
136
153
  return {
137
154
  ...(input.akumaName === undefined ? {} : { akumaName: validateAkumaName(input.akumaName) }),
138
155
  ...(caller === undefined ? {} : { caller }),
156
+ ...(allowLimit ? { selection: lifecycleSelection(input.selection) } : {}),
139
157
  };
140
158
  }
141
159
  /**
@@ -160,8 +178,8 @@ function callerClosure(lineage, root, world) {
160
178
  const included = new Set();
161
179
  const visited = new Set();
162
180
  const queue = [root];
163
- while (queue.length > 0) {
164
- const caller = queue.shift();
181
+ for (let cursor = 0; cursor < queue.length; cursor += 1) {
182
+ const caller = queue[cursor];
165
183
  const key = akumaCallerKey(caller);
166
184
  if (visited.has(key))
167
185
  continue;
@@ -248,7 +266,7 @@ async function verifyCallerMember(verification, id, observedCaller) {
248
266
  * closure's own born Soul edges are the proof. Unprovable members are skipped
249
267
  * honestly instead of reported as no more.
250
268
  */
251
- async function pageCallerRows(candidates, limit, admit) {
269
+ async function pageCallerRows(candidates, limit, admit, selection = "all") {
252
270
  const rows = [];
253
271
  let skipped = 0;
254
272
  let cursor = 0;
@@ -261,7 +279,7 @@ async function pageCallerRows(candidates, limit, admit) {
261
279
  const verdict = admit === undefined ? "included" : await admit(row);
262
280
  if (verdict === "invalid-cache")
263
281
  return { rows, skipped, invalid: true };
264
- if (verdict === "included")
282
+ if (verdict === "included" && (selection === "all" || akumaLifecycle(row.life) === selection))
265
283
  rows.push(row);
266
284
  else if (verdict === "unknown")
267
285
  skipped += 1;
@@ -294,21 +312,22 @@ async function callerCandidates(rows, lineage, root, world, selected) {
294
312
  * re-proven against its born Soul chain, and one disagreement discards the
295
313
  * record and answers from direct Soul evidence instead of an empty success.
296
314
  */
297
- async function readCallerPage(path, limit, selected, caller) {
315
+ async function readCallerPage(path, limit, selected, caller, selection = "all") {
298
316
  const known = await knownAkuma(path);
299
317
  const cached = await readAkumaLineage(path, known.rows);
300
- const verification = { world: path, root: caller, lineage: cached, souls: new Map() };
301
- const attempted = await pageCallerRows(await callerCandidates(known.rows, cached, caller, path, selected), limit,
318
+ const verification = { world: path, root: caller, lineage: cached.edges, souls: new Map() };
319
+ const attempted = await pageCallerRows(await callerCandidates(known.rows, cached.edges, caller, path, selected), limit,
302
320
  // A cache-proposed identity without a born Soul cannot justify inclusion.
303
- async (row) => (row.kind === "born" ? await verifyCallerMember(verification, row.id, row.caller) : "invalid-cache"));
321
+ async (row) => (row.kind === "born" ? await verifyCallerMember(verification, row.id, row.caller) : "invalid-cache"), selection);
304
322
  if (!attempted.invalid)
305
- return attempted;
323
+ return { ...attempted, skipped: attempted.skipped + cached.skipped };
306
324
  // One wrong edge makes the whole disposable record untrustworthy.
307
325
  await invalidateAkumaLineage(path);
308
326
  const direct = await readDirectAkumaLineage(known.rows);
309
- const repaired = await pageCallerRows(await callerCandidates(known.rows, direct, caller, path, selected), limit);
310
- await rebuildAkumaLineage(path, direct);
311
- return repaired;
327
+ const repaired = await pageCallerRows(await callerCandidates(known.rows, direct.edges, caller, path, selected), limit, undefined, selection);
328
+ if (direct.skipped === 0)
329
+ await rebuildAkumaLineage(path, direct.edges);
330
+ return { ...repaired, skipped: repaired.skipped + direct.skipped };
312
331
  }
313
332
  /** One roster answer: empty rows and known completeness are both omissions. */
314
333
  function rosterResult(observedAt, rows, more) {
@@ -323,15 +342,15 @@ function rosterResult(observedAt, rows, more) {
323
342
  * observed extent. A caller-scoped roster filters its World-local closure before
324
343
  * this same activity order and bound; World Alias context is attached above.
325
344
  */
326
- export async function observeAkumaRoster(path, limit, selected, caller) {
345
+ export async function observeAkumaRoster(path, limit, selected, caller, selection = "all") {
327
346
  const observedAt = new Date().toISOString();
328
347
  if (caller !== undefined) {
329
- const page = await readCallerPage(path, limit, selected, caller);
348
+ const page = await readCallerPage(path, limit, selected, caller, selection);
330
349
  const bounded = projectBoundedList(page.rows, limit);
331
350
  return rosterResult(observedAt, bounded.rows, bounded.hasMore || page.skipped > 0);
332
351
  }
333
352
  const known = await knownAkuma(path, selected);
334
- const ranked = await pageCallerRows(await freshnessOrdered(known.rows), limit);
353
+ const ranked = await pageCallerRows(await freshnessOrdered(known.rows), limit, undefined, selection);
335
354
  const bounded = projectBoundedList(ranked.rows, limit);
336
355
  return rosterResult(observedAt, bounded.rows, bounded.hasMore);
337
356
  }