@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
@@ -128,6 +128,15 @@ export async function recordPluginDiagnostic(paths, occurrence, error) {
128
128
  /* plugin diagnostic loss never changes Heart truth */
129
129
  }
130
130
  }
131
+ /** The plugin host bag for one Body occurrence; diagnostics are appended to its log. */
132
+ function pluginHost(launch, world, occurrence) {
133
+ return {
134
+ world,
135
+ reportDiagnostic: (message) => {
136
+ void recordPluginDiagnostic(launch.paths, occurrence, message);
137
+ },
138
+ };
139
+ }
131
140
  async function prepareBodyExecution(launch, leash, runtime, adapter) {
132
141
  runtime.signal?.throwIfAborted();
133
142
  const birth = await bornSoul(launch, leash, runtime.now());
@@ -178,12 +187,7 @@ async function prepareBodyStart(paths, leash) {
178
187
  return true;
179
188
  }
180
189
  async function emitBodyBirth(launch, soul, world, bodySequence) {
181
- await emitPluginSignal({
182
- world,
183
- reportDiagnostic: (message) => {
184
- void recordPluginDiagnostic(launch.paths, "birth", message);
185
- },
186
- }, {
190
+ await emitPluginSignal(pluginHost(launch, world, "birth"), {
187
191
  kind: "akuma.born",
188
192
  akumaId: soul.id,
189
193
  bodySequence,
@@ -193,16 +197,13 @@ async function emitBodyBirth(launch, soul, world, bodySequence) {
193
197
  });
194
198
  }
195
199
  function turnStartedEmitter(launch, soul, world) {
196
- const reportDiagnostic = (message) => {
197
- void recordPluginDiagnostic(launch.paths, "turn started", message);
198
- };
199
200
  return {
200
201
  async emit(turnSequence) {
201
202
  try {
202
203
  const turn = await readTurn(launch.paths, turnSequence);
203
204
  if (turn === null)
204
205
  throw new Error(`Committed Turn ${turnSequence} is missing from Heart`);
205
- await emitPluginSignal({ world, reportDiagnostic }, {
206
+ await emitPluginSignal(pluginHost(launch, world, "turn started"), {
206
207
  kind: "akuma.turn-started",
207
208
  akumaId: soul.id,
208
209
  turnSequence,
@@ -216,9 +217,6 @@ function turnStartedEmitter(launch, soul, world) {
216
217
  };
217
218
  }
218
219
  function turnOutcomeEmitter(launch, soul, world) {
219
- const reportDiagnostic = (message) => {
220
- void recordPluginDiagnostic(launch.paths, "turn outcome", message);
221
- };
222
220
  return {
223
221
  async emit(turnSequence) {
224
222
  try {
@@ -227,7 +225,7 @@ function turnOutcomeEmitter(launch, soul, world) {
227
225
  throw new Error(`Committed Turn ${turnSequence} outcome is missing from Heart`);
228
226
  const outcome = turn.end.outcome;
229
227
  const participants = await readTurnParticipants(launch.paths, turnSequence);
230
- await emitPluginSignal({ world, reportDiagnostic }, {
228
+ await emitPluginSignal(pluginHost(launch, world, "turn outcome"), {
231
229
  kind: "akuma.turn-outcome",
232
230
  akumaId: soul.id,
233
231
  bodySequence: turn.bodySequence,
@@ -250,9 +248,6 @@ function turnOutcomeEmitter(launch, soul, world) {
250
248
  };
251
249
  }
252
250
  function bodyEndEmitter(launch, soul, world) {
253
- const reportDiagnostic = (message) => {
254
- void recordPluginDiagnostic(launch.paths, "body end", message);
255
- };
256
251
  return async (bodySequence, end, diagnostic) => {
257
252
  try {
258
253
  const latestTurn = await readLatestTurnForBody(launch.paths, bodySequence);
@@ -260,7 +255,7 @@ function bodyEndEmitter(launch, soul, world) {
260
255
  const at = latestBody?.sequence === bodySequence ? (latestBody.hung?.at ?? latestBody.endedAt) : undefined;
261
256
  const initiator = latestTurn?.initiator;
262
257
  const participants = latestTurn === null ? [] : await readTurnParticipants(launch.paths, latestTurn.sequence);
263
- await emitPluginSignal({ world, reportDiagnostic }, {
258
+ await emitPluginSignal(pluginHost(launch, world, "body end"), {
264
259
  kind: "akuma.body-ended",
265
260
  akumaId: soul.id,
266
261
  bodySequence,
@@ -6,7 +6,6 @@ export declare const BIRTH_TIMEOUT_MS = 30000;
6
6
  export type CallInitialTell = Readonly<{
7
7
  tellId: string;
8
8
  body: string;
9
- schemaJson?: string;
10
9
  initiator?: string;
11
10
  }>;
12
11
  export type InitialTellAdmissionInput = Readonly<{
@@ -70,7 +70,6 @@ export async function admitCallInitialTell(input) {
70
70
  id: input.initialTell.tellId,
71
71
  body: input.initialTell.body,
72
72
  recordedAt: input.now?.() ?? new Date().toISOString(),
73
- ...(input.initialTell.schemaJson === undefined ? {} : { schemaJson: input.initialTell.schemaJson }),
74
73
  ...(input.initialTell.initiator === undefined ? {} : { initiator: input.initialTell.initiator }),
75
74
  });
76
75
  if (recorded.kind === "not-born")
@@ -184,6 +184,12 @@ declare const toolEventSchema: z.ZodUnion<readonly [z.ZodObject<{
184
184
  }, z.core.$strip>]>;
185
185
  truncated: z.ZodOptional<z.ZodLiteral<true>>;
186
186
  }, z.core.$strip>]>;
187
+ export declare const permissionRequestSchema: z.ZodObject<{
188
+ id: z.ZodString;
189
+ action: z.ZodString;
190
+ resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
191
+ tool: z.ZodOptional<z.ZodString>;
192
+ }, z.core.$strip>;
187
193
  export declare const agentEventSchema: z.ZodUnion<readonly [z.ZodObject<{
188
194
  type: z.ZodLiteral<"session">;
189
195
  coordinate: z.ZodUnion<readonly [z.ZodPipe<z.ZodObject<{
@@ -204,6 +210,15 @@ export declare const agentEventSchema: z.ZodUnion<readonly [z.ZodObject<{
204
210
  }, z.core.$strip>, z.ZodObject<{
205
211
  type: z.ZodLiteral<"model">;
206
212
  model: z.ZodOptional<z.ZodString>;
213
+ }, z.core.$strip>, z.ZodObject<{
214
+ type: z.ZodLiteral<"permission">;
215
+ requests: z.ZodReadonly<z.ZodArray<z.ZodObject<{
216
+ id: z.ZodString;
217
+ action: z.ZodString;
218
+ resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
219
+ tool: z.ZodOptional<z.ZodString>;
220
+ }, z.core.$strip>>>;
221
+ truncated: z.ZodOptional<z.ZodLiteral<true>>;
207
222
  }, z.core.$strip>, z.ZodObject<{
208
223
  type: z.ZodLiteral<"assistant">;
209
224
  text: z.ZodString;
@@ -327,6 +342,7 @@ export declare const agentEventSchema: z.ZodUnion<readonly [z.ZodObject<{
327
342
  kind: z.ZodString;
328
343
  truncated: z.ZodOptional<z.ZodLiteral<true>>;
329
344
  }, z.core.$strip>]>;
345
+ export type PermissionRequest = z.infer<typeof permissionRequestSchema>;
330
346
  export type SearchScope = z.infer<typeof searchScopeSchema>;
331
347
  export type ToolInput = z.infer<typeof toolInputSchema>;
332
348
  export type ToolCall = z.infer<typeof toolCallSchema>;
@@ -42,12 +42,19 @@ const toolEventSchema = z.union([
42
42
  z.object({ ...toolFields, phase: z.literal("started"), result: z.never().optional() }),
43
43
  z.object({ ...toolFields, phase: z.literal("completed"), result: toolResultSchema }),
44
44
  ]);
45
+ export const permissionRequestSchema = z.object({
46
+ id: text,
47
+ action: text,
48
+ resources: z.array(text).readonly(),
49
+ tool: text.optional(),
50
+ });
45
51
  export const agentEventSchema = z.union([
46
52
  z.object({ type: z.literal("session"), coordinate: resumeCoordinateSchema }),
47
53
  // One provider-neutral runtime-model observation in the shared agent-event
48
54
  // vocabulary. Body admits it into the Soul's single current model; it is
49
55
  // never appended to activity, so compaction cannot lose or resurrect it.
50
56
  z.object({ type: z.literal("model"), model: text.optional() }),
57
+ z.object({ type: z.literal("permission"), requests: z.array(permissionRequestSchema).readonly(), truncated }),
51
58
  z.object({ type: z.literal("assistant"), text, truncated }),
52
59
  z.object({ type: z.literal("thought"), text, truncated }),
53
60
  toolEventSchema,
@@ -223,6 +223,7 @@ export type SealFact = Readonly<{
223
223
  }>;
224
224
  export type LeashProbe = "held" | "free";
225
225
  export type AkumaLife = "running" | "asleep" | "stranded" | "hung" | "untidy" | "killed";
226
+ export declare function akumaLifecycle(life: AkumaLife | "unborn" | "stillborn"): "active" | "settled";
226
227
  export type HeartSnapshot = Readonly<{
227
228
  soul: Soul | null;
228
229
  latestBody: BodyFact | null;
@@ -58,6 +58,20 @@ export class BodyControlledError extends Error {
58
58
  this.name = "BodyControlledError";
59
59
  }
60
60
  }
61
+ export function akumaLifecycle(life) {
62
+ switch (life) {
63
+ case "running":
64
+ case "unborn":
65
+ case "stranded":
66
+ case "hung":
67
+ case "untidy":
68
+ return "active";
69
+ case "asleep":
70
+ case "killed":
71
+ case "stillborn":
72
+ return "settled";
73
+ }
74
+ }
61
75
  export function life(input) {
62
76
  if (input.body?.hung !== undefined)
63
77
  return "hung";
@@ -56,6 +56,7 @@ export declare function createTimelineReader(paths: AkumaPaths): Readonly<{
56
56
  /** One observer owns its connection and successful decoded frontier. */
57
57
  export declare function createStatusFactReader(paths: AkumaPaths): {
58
58
  life: (signal?: AbortSignal) => Promise<LifeSnapshot>;
59
+ wait: (recent: boolean, signal?: AbortSignal) => Promise<WaitFacts>;
59
60
  tellOutcome: (id: string, signal?: AbortSignal) => Promise<{
60
61
  tell: Readonly<{
61
62
  kind: "tell";
@@ -80,9 +81,14 @@ export declare function createStatusFactReader(paths: AkumaPaths): {
80
81
  clear(): void;
81
82
  read(input: StatusFactInput, signal?: AbortSignal): Promise<ActivitySlice["rows"]>;
82
83
  };
83
- type LifeSnapshot = Pick<HeartSnapshot, "soul" | "latestBody" | "latestSession" | "latestKill"> & Readonly<{
84
+ type LifeSnapshot = Pick<HeartSnapshot, "soul" | "latestBody" | "latestSession" | "latestKill" | "lastActivityAt"> & Readonly<{
84
85
  hasPendingTell: boolean;
85
86
  }>;
87
+ export type WaitFacts = LifeSnapshot & Readonly<{
88
+ turn: TurnFact | null;
89
+ activity: ActivityFactSlice | undefined;
90
+ activityDiagnostic: string | undefined;
91
+ }>;
86
92
  /** Lifecycle probes do not load narration, Tell bodies, or delivery histories. */
87
93
  export declare function readLifeSnapshot(paths: AkumaPaths, signal?: AbortSignal, read?: HeartRead): Promise<LifeSnapshot>;
88
94
  export type InterruptTellAdmission = Readonly<{
@@ -1,7 +1,7 @@
1
1
  import { parsePublicHistoryId } from "../identity.js";
2
2
  import { decodeRuntimeModel, withoutModel } from "../provider-recipe.js";
3
3
  import { BodyControlledError } from "./facts.js";
4
- import { answeredTurnFact, completeInterruptBarrier as judgeInterruptBarrier, endBodyFact, finishBodyFact, deleteStopControl, insertReportFact, insertActivityFact, insertTurnEndFact, insertTurnStartFact, insertKillFact, insertSessionFact, insertStopControl, killFactForBody, hasBodyHandoffControl, latestBodyFact, insertInterruptBarrier, isTellProtectedByPause, latestKillFact, latestSessionFact, latestTurnFactForBody, lastAnsweredTurnFact, pauseFact, sessionFactForCoordinate, stopFact, turnFact, openTurnsForBody, terminalTurnForTell, } from "./rows.js";
4
+ import { answeredTurnFact, completeInterruptBarrier as judgeInterruptBarrier, endBodyFact, finishBodyFact, deleteStopControl, insertReportFact, insertActivityFact, insertTurnEndFact, insertTurnStartFact, insertKillFact, insertSessionFact, insertStopControl, killFactForBody, hasBodyHandoffControl, latestBodyFact, insertInterruptBarrier, isTellProtectedByPause, latestKillFact, latestSessionFact, latestTurnFactForBody, latestTurnFact, lastAnsweredTurnFact, pauseFact, sessionFactForCoordinate, stopFact, turnFact, openTurnsForBody, terminalTurnForTell, } from "./rows.js";
5
5
  import { insertTellDeliveryFact, dispositionSnapshotProven, insertTellBindingFact, insertTellDispositionSnapshot, insertTellReceiptFact, insertUndeliveredTellReceipts, latestOpenTellDisposition, openBoundTurns, openTellDispositionIds, pendingTellFacts, hasPendingTell, resolveTellDispositionSnapshot, sameTellInput, tellDispositionResolved, tellFact, tellIdsForFence, turnParticipants, } from "./tells.js";
6
6
  import { activityFactSlice, statusFacts, readStatusBatch, decodeTimelineBatch, timelineDataVersion, lastActivityAt as readLastActivityAt, pruneActivityFacts, } from "./timeline.js";
7
7
  import { createHeartReader, isHeartAbsent, readSealFromLeash, recordPendingTell, withHeartTransaction, withReadOnlyHeart, } from "./storage.js";
@@ -132,6 +132,21 @@ export function createStatusFactReader(paths) {
132
132
  let memo;
133
133
  return {
134
134
  life: (signal) => readLifeSnapshot(paths, signal, reader.read),
135
+ wait: (recent, signal) => reader.read((heart) => {
136
+ const snapshot = lifeSnapshot(heart);
137
+ const turn = latestTurnFact(heart);
138
+ let activity;
139
+ let activityDiagnostic;
140
+ if (recent) {
141
+ try {
142
+ activity = activityFactSlice(heart);
143
+ }
144
+ catch (error) {
145
+ activityDiagnostic = error instanceof Error ? error.message : String(error);
146
+ }
147
+ }
148
+ return { ...snapshot, turn, activity, activityDiagnostic };
149
+ }, signal),
135
150
  tellOutcome: (id, signal) => reader.read((heart) => {
136
151
  const tell = tellFact(heart, id);
137
152
  // A pending Tell may be retried by a successor after cancellation. Its
@@ -163,20 +178,31 @@ export function createStatusFactReader(paths) {
163
178
  },
164
179
  };
165
180
  }
181
+ function lifeSnapshot(heart) {
182
+ return {
183
+ soul: soulFact(heart),
184
+ latestBody: latestBodyFact(heart),
185
+ latestSession: latestSessionFact(heart),
186
+ latestKill: latestKillFact(heart),
187
+ hasPendingTell: hasPendingTell(heart),
188
+ lastActivityAt: readLastActivityAt(heart),
189
+ };
190
+ }
166
191
  /** Lifecycle probes do not load narration, Tell bodies, or delivery histories. */
167
192
  export async function readLifeSnapshot(paths, signal, read = (body, signal) => withReadOnlyHeart(paths, body, signal)) {
168
193
  try {
169
- return await read((heart) => ({
170
- soul: soulFact(heart),
171
- latestBody: latestBodyFact(heart),
172
- latestSession: latestSessionFact(heart),
173
- latestKill: latestKillFact(heart),
174
- hasPendingTell: hasPendingTell(heart),
175
- }), signal);
194
+ return await read(lifeSnapshot, signal);
176
195
  }
177
196
  catch (error) {
178
197
  if (isHeartAbsent(error))
179
- return { soul: null, latestBody: null, latestSession: null, latestKill: null, hasPendingTell: false };
198
+ return {
199
+ soul: null,
200
+ latestBody: null,
201
+ latestSession: null,
202
+ latestKill: null,
203
+ hasPendingTell: false,
204
+ lastActivityAt: null,
205
+ };
180
206
  throw error;
181
207
  }
182
208
  }
@@ -189,4 +189,5 @@ export declare function killFactForBody(database: DatabaseSync, bodySequence: nu
189
189
  export declare function lastAnsweredTurnFact(database: DatabaseSync): TurnFact | null;
190
190
  export declare function answeredTurnFact(database: DatabaseSync, turnSequence: number): TurnFact | null;
191
191
  export declare function latestTurnFactForBody(database: DatabaseSync, bodySequence: number): TurnFact | null;
192
+ export declare function latestTurnFact(database: DatabaseSync): TurnFact | null;
192
193
  export declare function turnFact(database: DatabaseSync, turnSequence: number): TurnFact | null;
@@ -428,6 +428,10 @@ export function latestTurnFactForBody(database, bodySequence) {
428
428
  .get(bodySequence);
429
429
  return row === undefined ? null : decodeTurnRow(row);
430
430
  }
431
+ export function latestTurnFact(database) {
432
+ const latest = database.prepare("SELECT sequence FROM turns ORDER BY sequence DESC LIMIT 1").get();
433
+ return latest === undefined ? null : turnFact(database, latest.sequence);
434
+ }
431
435
  export function turnFact(database, turnSequence) {
432
436
  const row = database
433
437
  .prepare(`SELECT sequence, body_sequence, started_at, end_sequence, outcome, history_id,
@@ -3,20 +3,17 @@ import { decodeTellBatch, tellBatchAtSequences, tellStateSql, pendingTellProtect
3
3
  export function lastActivityAt(database) {
4
4
  const row = database
5
5
  .prepare(`SELECT CASE timeline.kind
6
- WHEN 'turn-start' THEN started_turn.started_at
7
6
  WHEN 'call' THEN calls.at
8
7
  WHEN 'activity' THEN activity.at
9
8
  WHEN 'report' THEN reports.at
10
9
  WHEN 'tell' THEN tells.recorded_at
11
- WHEN 'turn-end' THEN ended_turn.completed_at
12
10
  END AS at
13
11
  FROM timeline
14
- LEFT JOIN turns AS started_turn ON timeline.kind = 'turn-start' AND started_turn.sequence = timeline.sequence
15
12
  LEFT JOIN calls ON timeline.kind = 'call' AND calls.sequence = timeline.sequence
16
13
  LEFT JOIN activity ON timeline.kind = 'activity' AND activity.sequence = timeline.sequence
17
14
  LEFT JOIN reports ON timeline.kind = 'report' AND reports.sequence = timeline.sequence
18
15
  LEFT JOIN tells ON timeline.kind = 'tell' AND tells.sequence = timeline.sequence
19
- LEFT JOIN turns AS ended_turn ON timeline.kind = 'turn-end' AND ended_turn.end_sequence = timeline.sequence
16
+ WHERE timeline.kind IN ('call', 'activity', 'report', 'tell')
20
17
  ORDER BY timeline.sequence DESC LIMIT 1`)
21
18
  .get();
22
19
  if (row === undefined || row.at === null)
@@ -48,6 +45,9 @@ export function pruneActivityFacts(database, limit, protectionReleased = false)
48
45
  UNION ${pendingTellProtectionSql}
49
46
  ), protected(sequence) AS (
50
47
  SELECT sequence FROM protected_turns
48
+ UNION SELECT MAX(sequence) FROM activity
49
+ WHERE turn_sequence IN (SELECT sequence FROM turns WHERE end_sequence IS NULL)
50
+ AND json_extract(event_json, '$.type') = 'permission' GROUP BY turn_sequence
51
51
  UNION SELECT sequence FROM calls WHERE turn_sequence IN (SELECT sequence FROM protected_turns)
52
52
  UNION SELECT end_sequence FROM turns WHERE sequence IN (SELECT sequence FROM protected_turns) AND end_sequence IS NOT NULL
53
53
  UNION ${pendingTellSequencesSql}
@@ -7,13 +7,17 @@ import type { WorldRoot } from "../world.js";
7
7
  * rebuilt from Hearts, and an unavailable cache falls back to direct Soul reads.
8
8
  */
9
9
  export type AkumaLineage = ReadonlyMap<AkumaId, AkumaCaller | null>;
10
+ type LineageObservation = Readonly<{
11
+ edges: AkumaLineage;
12
+ skipped: number;
13
+ }>;
10
14
  export type LineageMember = Readonly<{
11
15
  id: AkumaId;
12
16
  paths: AkumaPaths;
13
17
  }>;
14
18
  export declare function akumaLineageCachePath(world: WorldRoot): string;
15
19
  /** Authoritative lineage read: every known born Soul, with no cache consultation. */
16
- export declare function readDirectAkumaLineage(members: readonly LineageMember[]): Promise<AkumaLineage>;
20
+ export declare function readDirectAkumaLineage(members: readonly LineageMember[]): Promise<LineageObservation>;
17
21
  /**
18
22
  * Discard the disposable record when an offered edge disagrees with a born
19
23
  * Soul. The next caller-scoped answer comes from direct Soul evidence and
@@ -36,4 +40,5 @@ export declare function recordAkumaLineage(world: WorldRoot, soul: Readonly<{
36
40
  * Rows whose Akuma directory no longer exists never join this view, and fresh
37
41
  * edges plus that pruning are written back best-effort.
38
42
  */
39
- export declare function readAkumaLineage(world: WorldRoot, members: readonly LineageMember[]): Promise<AkumaLineage>;
43
+ export declare function readAkumaLineage(world: WorldRoot, members: readonly LineageMember[]): Promise<LineageObservation>;
44
+ export {};
@@ -31,14 +31,14 @@ function readCachedEdge(row) {
31
31
  throw new Error("Akuma lineage cache row has an empty caller");
32
32
  return [akumaId, caller];
33
33
  }
34
- /** A readable cache, an empty map for a cache that was never written, or null when unusable. */
35
- async function readLineageCache(path) {
34
+ /** Decode only current members; obsolete and invalid rows are disposable misses. */
35
+ async function readLineageCache(path, known) {
36
36
  try {
37
37
  await lstat(path);
38
38
  }
39
39
  catch (error) {
40
40
  if (error.code === "ENOENT")
41
- return new Map();
41
+ return { edges: new Map(), stale: [] };
42
42
  return null;
43
43
  }
44
44
  let database;
@@ -53,7 +53,24 @@ async function readLineageCache(path) {
53
53
  try {
54
54
  database.exec("PRAGMA busy_timeout=0");
55
55
  const rows = database.prepare("SELECT aku_id, caller_json FROM lineage").all();
56
- return new Map(rows.map(readCachedEdge));
56
+ const edges = new Map();
57
+ const stale = [];
58
+ for (const row of rows) {
59
+ if (typeof row.aku_id !== "string")
60
+ continue;
61
+ if (known.has(row.aku_id)) {
62
+ try {
63
+ const [id, caller] = readCachedEdge(row);
64
+ edges.set(id, caller);
65
+ continue;
66
+ }
67
+ catch {
68
+ // A malformed current edge is a miss, not a reason to discard peers.
69
+ }
70
+ }
71
+ stale.push(row.aku_id);
72
+ }
73
+ return { edges, stale };
57
74
  }
58
75
  catch {
59
76
  return null;
@@ -76,10 +93,10 @@ async function writeLineageCache(path, fresh, stale, replace = false) {
76
93
  try {
77
94
  if (replace)
78
95
  database.exec("DELETE FROM lineage");
79
- for (const [akumaId, caller] of fresh)
80
- insert.run(akumaId, caller === null ? null : JSON.stringify(caller));
81
96
  for (const akumaId of stale)
82
97
  remove.run(akumaId);
98
+ for (const [akumaId, caller] of fresh)
99
+ insert.run(akumaId, caller === null ? null : JSON.stringify(caller));
83
100
  database.exec("COMMIT");
84
101
  }
85
102
  catch (error) {
@@ -98,16 +115,22 @@ async function writeLineageCache(path, fresh, stale, replace = false) {
98
115
  async function directEdge(member) {
99
116
  try {
100
117
  const soul = await readSoul(member.paths);
118
+ if (soul !== null && soul.id !== member.id)
119
+ throw new Error("Akuma soul does not match its coordinate");
101
120
  return soul === null ? null : [member.id, soul.caller ?? null];
102
121
  }
103
122
  catch {
104
- // A hard Heart read failure stays an omitted member, never an empty roster claim.
105
- return null;
123
+ // Unreadability is not authoritative absence and cannot justify a rebuild.
124
+ return undefined;
106
125
  }
107
126
  }
108
127
  /** Authoritative lineage read: every known born Soul, with no cache consultation. */
109
128
  export async function readDirectAkumaLineage(members) {
110
- return new Map((await boundedMap(members, directEdge)).filter((edge) => edge !== null));
129
+ const observed = await boundedMap(members, directEdge);
130
+ return {
131
+ edges: new Map(observed.filter((edge) => edge !== null && edge !== undefined)),
132
+ skipped: observed.filter((edge) => edge === undefined).length,
133
+ };
111
134
  }
112
135
  /**
113
136
  * Discard the disposable record when an offered edge disagrees with a born
@@ -144,19 +167,20 @@ export async function recordAkumaLineage(world, soul) {
144
167
  */
145
168
  export async function readAkumaLineage(world, members) {
146
169
  const path = akumaLineageCachePath(world);
147
- const cached = await readLineageCache(path);
148
- if (cached === null)
149
- return await readDirectAkumaLineage(members);
150
- const known = new Set(members.map((member) => member.id));
151
- const stale = [...cached.keys()].filter((id) => !known.has(id));
152
- const missing = members.filter((member) => !cached.has(member.id));
153
- const fresh = (await boundedMap(missing, directEdge)).filter((edge) => edge !== null);
154
- // A vanished directory never contributes an edge even if its prune write fails.
155
- for (const id of stale)
156
- cached.delete(id);
157
- for (const [akumaId, caller] of fresh)
158
- cached.set(akumaId, caller);
159
- if (fresh.length > 0 || stale.length > 0)
160
- await writeLineageCache(path, fresh, stale);
161
- return cached;
170
+ const cached = await readLineageCache(path, new Set(members.map((member) => member.id)));
171
+ if (cached === null) {
172
+ const direct = await readDirectAkumaLineage(members);
173
+ if (direct.skipped === 0) {
174
+ await invalidateAkumaLineage(world);
175
+ await rebuildAkumaLineage(world, direct.edges);
176
+ }
177
+ return direct;
178
+ }
179
+ const missing = members.filter((member) => !cached.edges.has(member.id));
180
+ const fresh = await readDirectAkumaLineage(missing);
181
+ for (const [akumaId, caller] of fresh.edges)
182
+ cached.edges.set(akumaId, caller);
183
+ if (fresh.edges.size > 0 || cached.stale.length > 0)
184
+ await writeLineageCache(path, [...fresh.edges], cached.stale);
185
+ return { edges: cached.edges, skipped: fresh.skipped };
162
186
  }
@@ -1,8 +1,9 @@
1
- import type { ActivitySnapshot, TurnLedger } from "./projection.js";
1
+ import type { ActivitySnapshot, HistoryCursor, HistoryPage, TurnLedger } from "./projection.js";
2
2
  export declare const DEFAULT_TAIL = 3;
3
3
  /** Present the same snapshot without its reported-change summary. */
4
4
  export declare function withoutReportedChanges(snapshot: ActivitySnapshot): ActivitySnapshot;
5
- import type { HistoryCursor, HistoryPage } from "./projection.js";
5
+ /** Raw reported spellings on the current frontier, before containment partitioning. */
6
+ export declare function reportedChangePaths(ledger: TurnLedger): readonly string[];
6
7
  export declare function selectSnapshot(ledger: TurnLedger, input: Readonly<{
7
8
  aperture: "monitoring" | "receipt";
8
9
  budget?: Readonly<{
@@ -10,6 +11,7 @@ export declare function selectSnapshot(ledger: TurnLedger, input: Readonly<{
10
11
  }>;
11
12
  executionDir?: string;
12
13
  admittedTellId?: string;
14
+ canonicalize?: (absolutePath: string) => string;
13
15
  }>): Readonly<{
14
16
  snapshot: ActivitySnapshot;
15
17
  ordinaryCount: number;
@@ -1,3 +1,4 @@
1
+ import { selectHistoryPage } from "../history.js";
1
2
  import { isAbsolute, relative, resolve, sep } from "node:path";
2
3
  export const DEFAULT_TAIL = 3;
3
4
  const REPORTED_CHANGE_LIMIT = 5;
@@ -74,12 +75,13 @@ function aggregateReportedChanges(changes) {
74
75
  ? { path: group.path, diffstat: { added: group.added, removed: group.removed } }
75
76
  : { path: group.path });
76
77
  }
77
- function summarizeReportedChanges(rows, executionDir) {
78
+ function summarizeReportedChanges(rows, executionDir, canonicalize) {
78
79
  const files = aggregateReportedChanges(flattenReportedChanges(rows));
79
80
  const inside = files.filter((change) => {
80
81
  if (executionDir === undefined)
81
82
  return true;
82
- const path = relative(executionDir, resolve(executionDir, change.path));
83
+ const absolute = resolve(executionDir, change.path);
84
+ const path = relative(executionDir, canonicalize === undefined ? absolute : canonicalize(absolute));
83
85
  return path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path);
84
86
  });
85
87
  const outside = files.length - inside.length;
@@ -89,11 +91,18 @@ function summarizeReportedChanges(rows, executionDir) {
89
91
  ...(outside === 0 ? {} : { reportedChangesOutside: outside }),
90
92
  };
91
93
  }
92
- function frontierReportedChanges(ledger, executionDir) {
94
+ function frontierRows(ledger) {
93
95
  if (ledger.openTurn !== undefined)
94
- return summarizeReportedChanges(ledger.openTurn.rows, executionDir);
96
+ return ledger.openTurn.rows;
95
97
  const closed = ledger.turns.findLast((turn) => turn.kind === "closed");
96
- return closed === undefined ? EMPTY_REPORTED : summarizeReportedChanges(closed.rows, executionDir);
98
+ return closed?.rows ?? [];
99
+ }
100
+ function frontierReportedChanges(ledger, executionDir, canonicalize) {
101
+ return summarizeReportedChanges(frontierRows(ledger), executionDir, canonicalize);
102
+ }
103
+ /** Raw reported spellings on the current frontier, before containment partitioning. */
104
+ export function reportedChangePaths(ledger) {
105
+ return flattenReportedChanges(frontierRows(ledger)).map((change) => change.path);
97
106
  }
98
107
  function isPendingTell(row) {
99
108
  return row.kind === "tell" && row.state === "pending";
@@ -128,22 +137,21 @@ export function selectSnapshot(ledger, input) {
128
137
  const tailCount = Math.min(DEFAULT_TAIL, Math.max(0, input.budget?.tail ?? DEFAULT_TAIL));
129
138
  if (ledger.turns.length === 0 && !ledger.rows.some((row) => row.kind === "tell"))
130
139
  return { snapshot: { kind: "unborn", entries: [], ...EMPTY_REPORTED }, ordinaryCount: 0 };
140
+ const receiptTellId = input.aperture === "receipt" ? input.admittedTellId : undefined;
131
141
  const pending = ledger.rows.filter(isPendingTell);
132
- const admittedTell = input.aperture === "receipt" && input.admittedTellId !== undefined
133
- ? ledger.rows.find((row) => row.kind === "tell" && row.tellId === input.admittedTellId)
134
- : undefined;
135
- const pins = input.aperture === "receipt" && input.admittedTellId !== undefined
136
- ? admittedTell === undefined
137
- ? []
138
- : [admittedTell]
139
- : pending;
140
- const reported = frontierReportedChanges(ledger, input.executionDir);
142
+ const admittedTell = receiptTellId === undefined
143
+ ? undefined
144
+ : ledger.rows.find((row) => row.kind === "tell" && row.tellId === receiptTellId);
145
+ const pins = receiptTellId === undefined ? pending : admittedTell === undefined ? [] : [admittedTell];
146
+ const reported = frontierReportedChanges(ledger, input.executionDir, input.canonicalize);
141
147
  if (ledger.openTurn !== undefined) {
142
148
  const window = currentTurnWindow(ledger);
143
149
  const opening = openingInput(ledger);
144
150
  const latestSaid = window.findLast((row) => row.kind === "said");
151
+ const permission = window.findLast((row) => row.kind === "permission");
145
152
  const pinSet = new Set([
146
153
  ...window.filter(isProtectedTool),
154
+ ...(permission === undefined ? [] : [permission]),
147
155
  ...(latestSaid === undefined ? [] : [latestSaid]),
148
156
  ...pins,
149
157
  ...(opening === undefined ? [] : [opening]),
@@ -173,21 +181,15 @@ export function selectSnapshot(ledger, input) {
173
181
  };
174
182
  }
175
183
  export function selectHistory(ledger, cursor) {
176
- const eligible = ledger.rows.filter((row) => cursor.before !== undefined
177
- ? row.sequence < cursor.before
178
- : cursor.since !== undefined
179
- ? row.sequence > cursor.since
180
- : true);
181
- const rows = cursor.since !== undefined ? eligible.slice(0, cursor.limit) : eligible.slice(-cursor.limit);
182
- const omitted = Math.max(0, eligible.length - rows.length);
184
+ const { rows, omitted } = selectHistoryPage(ledger.rows, (row) => row.sequence, cursor);
183
185
  const historyLost = cursor.since !== undefined
184
186
  ? ledger.rows[0] !== undefined && ledger.rows[0].sequence > cursor.since + 1
185
187
  : ledger.retained.lowestRetained !== null && ledger.retained.lowestRetained > 1 && omitted === 0;
186
188
  return {
187
189
  rows,
188
190
  omitted,
189
- hasEarlier: cursor.since === undefined && eligible.length > rows.length,
190
- hasLater: cursor.since !== undefined && eligible.length > rows.length,
191
+ hasEarlier: cursor.since === undefined && omitted > 0,
192
+ hasLater: cursor.since !== undefined && omitted > 0,
191
193
  historyLost,
192
194
  lowestRetained: ledger.retained.lowestRetained,
193
195
  highest: ledger.retained.highest,