@earendil-works/pi-durable 0.99.1 → 0.99.2

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 (172) hide show
  1. package/README.md +435 -46
  2. package/dist/entries.d.ts +20 -2
  3. package/dist/entries.d.ts.map +1 -1
  4. package/dist/entries.js +14 -1
  5. package/dist/entries.js.map +1 -1
  6. package/dist/env/index.d.ts +13 -38
  7. package/dist/env/index.d.ts.map +1 -1
  8. package/dist/env/index.js +2 -0
  9. package/dist/env/index.js.map +1 -1
  10. package/dist/env/node.d.ts.map +1 -1
  11. package/dist/env/node.js +51 -58
  12. package/dist/env/node.js.map +1 -1
  13. package/dist/harness/compaction.d.ts +56 -0
  14. package/dist/harness/compaction.d.ts.map +1 -0
  15. package/dist/harness/compaction.js +385 -0
  16. package/dist/harness/compaction.js.map +1 -0
  17. package/dist/harness/config.d.ts +10 -1
  18. package/dist/harness/config.d.ts.map +1 -1
  19. package/dist/harness/config.js +6 -0
  20. package/dist/harness/config.js.map +1 -1
  21. package/dist/harness/context.d.ts +8 -0
  22. package/dist/harness/context.d.ts.map +1 -1
  23. package/dist/harness/context.js +32 -21
  24. package/dist/harness/context.js.map +1 -1
  25. package/dist/harness/events.d.ts +166 -0
  26. package/dist/harness/events.d.ts.map +1 -0
  27. package/dist/harness/events.js +319 -0
  28. package/dist/harness/events.js.map +1 -0
  29. package/dist/harness/generation.d.ts +37 -6
  30. package/dist/harness/generation.d.ts.map +1 -1
  31. package/dist/harness/generation.js +350 -72
  32. package/dist/harness/generation.js.map +1 -1
  33. package/dist/harness/harness.d.ts.map +1 -1
  34. package/dist/harness/harness.js +124 -3
  35. package/dist/harness/harness.js.map +1 -1
  36. package/dist/harness/inbox.d.ts +57 -0
  37. package/dist/harness/inbox.d.ts.map +1 -0
  38. package/dist/harness/inbox.js +99 -0
  39. package/dist/harness/inbox.js.map +1 -0
  40. package/dist/harness/json.d.ts +10 -0
  41. package/dist/harness/json.d.ts.map +1 -0
  42. package/dist/harness/json.js +33 -0
  43. package/dist/harness/json.js.map +1 -0
  44. package/dist/harness/live.d.ts +66 -7
  45. package/dist/harness/live.d.ts.map +1 -1
  46. package/dist/harness/live.js +71 -7
  47. package/dist/harness/live.js.map +1 -1
  48. package/dist/harness/output.d.ts +62 -0
  49. package/dist/harness/output.d.ts.map +1 -0
  50. package/dist/harness/output.js +261 -0
  51. package/dist/harness/output.js.map +1 -0
  52. package/dist/harness/prompt.d.ts +10 -5
  53. package/dist/harness/prompt.d.ts.map +1 -1
  54. package/dist/harness/prompt.js +66 -13
  55. package/dist/harness/prompt.js.map +1 -1
  56. package/dist/harness/registry.d.ts.map +1 -1
  57. package/dist/harness/registry.js +11 -2
  58. package/dist/harness/registry.js.map +1 -1
  59. package/dist/harness/scheduler.d.ts +37 -12
  60. package/dist/harness/scheduler.d.ts.map +1 -1
  61. package/dist/harness/scheduler.js +632 -72
  62. package/dist/harness/scheduler.js.map +1 -1
  63. package/dist/harness/submissions.d.ts +12 -7
  64. package/dist/harness/submissions.d.ts.map +1 -1
  65. package/dist/harness/submissions.js +72 -33
  66. package/dist/harness/submissions.js.map +1 -1
  67. package/dist/harness/tool.d.ts +36 -0
  68. package/dist/harness/tool.d.ts.map +1 -0
  69. package/dist/harness/tool.js +412 -0
  70. package/dist/harness/tool.js.map +1 -0
  71. package/dist/harness/types.d.ts +185 -11
  72. package/dist/harness/types.d.ts.map +1 -1
  73. package/dist/harness/types.js.map +1 -1
  74. package/dist/harness/usage.d.ts +18 -0
  75. package/dist/harness/usage.d.ts.map +1 -0
  76. package/dist/harness/usage.js +57 -0
  77. package/dist/harness/usage.js.map +1 -0
  78. package/dist/harness/view.d.ts +43 -0
  79. package/dist/harness/view.d.ts.map +1 -0
  80. package/dist/harness/view.js +194 -0
  81. package/dist/harness/view.js.map +1 -0
  82. package/dist/index.d.ts +10 -4
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +6 -1
  85. package/dist/index.js.map +1 -1
  86. package/dist/session/observation.d.ts +18 -11
  87. package/dist/session/observation.d.ts.map +1 -1
  88. package/dist/session/observation.js +24 -13
  89. package/dist/session/observation.js.map +1 -1
  90. package/dist/session/session.d.ts +10 -1
  91. package/dist/session/session.d.ts.map +1 -1
  92. package/dist/session/session.js +18 -4
  93. package/dist/session/session.js.map +1 -1
  94. package/dist/session/transaction.d.ts +10 -1
  95. package/dist/session/transaction.d.ts.map +1 -1
  96. package/dist/session/transaction.js +83 -27
  97. package/dist/session/transaction.js.map +1 -1
  98. package/dist/storage/jsonl/storage.d.ts +22 -2
  99. package/dist/storage/jsonl/storage.d.ts.map +1 -1
  100. package/dist/storage/jsonl/storage.js +1 -1
  101. package/dist/storage/jsonl/storage.js.map +1 -1
  102. package/dist/storage/memory.js +1 -1
  103. package/dist/storage/memory.js.map +1 -1
  104. package/dist/storage/sqlite/migrations.js +1 -1
  105. package/dist/storage/sqlite/migrations.js.map +1 -1
  106. package/dist/testing/storage-benchmark.d.ts.map +1 -1
  107. package/dist/testing/storage-benchmark.js +0 -1
  108. package/dist/testing/storage-benchmark.js.map +1 -1
  109. package/dist/testing/storage-conformance.d.ts.map +1 -1
  110. package/dist/testing/storage-conformance.js +34 -2
  111. package/dist/testing/storage-conformance.js.map +1 -1
  112. package/dist/tools/bash.d.ts +28 -0
  113. package/dist/tools/bash.d.ts.map +1 -0
  114. package/dist/tools/bash.js +69 -0
  115. package/dist/tools/bash.js.map +1 -0
  116. package/dist/tools/edit-diff.d.ts +89 -0
  117. package/dist/tools/edit-diff.d.ts.map +1 -0
  118. package/dist/tools/edit-diff.js +386 -0
  119. package/dist/tools/edit-diff.js.map +1 -0
  120. package/dist/tools/edit.d.ts +18 -0
  121. package/dist/tools/edit.d.ts.map +1 -0
  122. package/dist/tools/edit.js +116 -0
  123. package/dist/tools/edit.js.map +1 -0
  124. package/dist/tools/env.d.ts +5 -0
  125. package/dist/tools/env.d.ts.map +1 -0
  126. package/dist/tools/env.js +7 -0
  127. package/dist/tools/env.js.map +1 -0
  128. package/dist/tools/file-mutation-queue.d.ts +5 -0
  129. package/dist/tools/file-mutation-queue.d.ts.map +1 -0
  130. package/dist/tools/file-mutation-queue.js +46 -0
  131. package/dist/tools/file-mutation-queue.js.map +1 -0
  132. package/dist/tools/image.d.ts +2 -0
  133. package/dist/tools/image.d.ts.map +1 -0
  134. package/dist/tools/image.js +92 -0
  135. package/dist/tools/image.js.map +1 -0
  136. package/dist/tools/index.d.ts +5 -0
  137. package/dist/tools/index.d.ts.map +1 -0
  138. package/dist/tools/index.js +5 -0
  139. package/dist/tools/index.js.map +1 -0
  140. package/dist/tools/path-utils.d.ts +5 -0
  141. package/dist/tools/path-utils.d.ts.map +1 -0
  142. package/dist/tools/path-utils.js +26 -0
  143. package/dist/tools/path-utils.js.map +1 -0
  144. package/dist/tools/read.d.ts +17 -0
  145. package/dist/tools/read.d.ts.map +1 -0
  146. package/dist/tools/read.js +100 -0
  147. package/dist/tools/read.js.map +1 -0
  148. package/dist/tools/write.d.ts +10 -0
  149. package/dist/tools/write.d.ts.map +1 -0
  150. package/dist/tools/write.js +30 -0
  151. package/dist/tools/write.js.map +1 -0
  152. package/dist/{env/utils/truncate.d.ts → truncate.d.ts} +1 -17
  153. package/dist/truncate.d.ts.map +1 -0
  154. package/dist/truncate.js +146 -0
  155. package/dist/truncate.js.map +1 -0
  156. package/dist/types.d.ts +86 -19
  157. package/dist/types.d.ts.map +1 -1
  158. package/dist/types.js.map +1 -1
  159. package/docs/pico-v5-handoff.md +366 -86
  160. package/docs/pico-v5.md +1373 -283
  161. package/package.json +11 -3
  162. package/dist/env/utils/adaptive-publisher.d.ts +0 -24
  163. package/dist/env/utils/adaptive-publisher.d.ts.map +0 -1
  164. package/dist/env/utils/adaptive-publisher.js +0 -79
  165. package/dist/env/utils/adaptive-publisher.js.map +0 -1
  166. package/dist/env/utils/output-capture.d.ts +0 -31
  167. package/dist/env/utils/output-capture.d.ts.map +0 -1
  168. package/dist/env/utils/output-capture.js +0 -238
  169. package/dist/env/utils/output-capture.js.map +0 -1
  170. package/dist/env/utils/truncate.d.ts.map +0 -1
  171. package/dist/env/utils/truncate.js +0 -294
  172. package/dist/env/utils/truncate.js.map +0 -1
@@ -1,6 +1,9 @@
1
- import type { Context, JsonValue } from "@earendil-works/chord";
2
- import type { CacheRetention, Message, Models, ModelThinkingLevel, Tool, ToolResultMessage, Transport, UserMessage } from "@earendil-works/pi-ai";
3
- import type { ConversationId, ConversationOwnership, ConversationRecord, Cursor, DocumentObserver, DocumentReader, EntryDraft, EntryId, EntryQuery, EntryRecord, JsonObject, Page, Session, SubmissionId, SubmissionRecord, Task, TaskId, TaskOptions, TaskRecord, TaskState, Tx } from "../types.ts";
1
+ import type { AttachedReplicatedState, Context, JsonValue } from "@earendil-works/chord";
2
+ import type { AssistantMessage, CacheRetention, Message, Models, ModelThinkingLevel, Tool, ToolCall, ToolResultMessage, Transport, Usage, UserMessage } from "@earendil-works/pi-ai";
3
+ import type { ExecutionEnv } from "../env/index.ts";
4
+ import type { ConversationId, ConversationOwnership, ConversationRecord, Cursor, DocumentObserver, DocumentReader, EntryDraft, EntryId, EntryQuery, EntryRecord, JsonObject, Page, Session, SubmissionId, SubmissionRecord, Task, TaskId, TaskOptions, TaskRecord, TaskState, Tx, WatchHandle } from "../types.ts";
5
+ import type { UsageState } from "./usage.ts";
6
+ import type { ConversationView } from "./view.ts";
4
7
  /** Provider and model ID resolved through pi-ai `Models`. */
5
8
  export type ModelRef = {
6
9
  readonly provider: string;
@@ -51,13 +54,27 @@ export type AnyTask = {
51
54
  readonly hooks?: object;
52
55
  };
53
56
  };
57
+ /** Options of `Conversation.abort()`. */
58
+ export type ConversationAbortOptions = {
59
+ /**
60
+ * Cross background boundaries: mark every live task reached ignoring the background flag when the abort is admitted,
61
+ * withdraw the queued inputs of every conversation reached, and wait until those tasks are terminal and the
62
+ * conversation is ordinarily idle. Background work created afterwards is neither marked nor awaited.
63
+ */
64
+ readonly background?: boolean;
65
+ };
54
66
  /** Hook handler map declared by a task definition. */
55
67
  export type HooksOf<K> = K extends Task<infer _I, infer _S, infer _R, infer H> ? H : never;
56
- /** Invocation-bound conversation operations available to tools. */
68
+ /**
69
+ * Invocation-bound conversation operations for tasks and tools. Rejects after the invocation ends; passive entries are
70
+ * written with ordinary transaction writes instead.
71
+ */
57
72
  export interface ConversationHandle {
58
73
  readonly id: ConversationId;
59
74
  submit(submission: InputSubmissionDraft, context: Context): Promise<Submission>;
60
- abort(context: Context): Promise<void>;
75
+ /** `Conversation.abort()`: withdraw queued inputs, abort the ordinary ownership scope, and wait until it is idle. */
76
+ abort(context: Context, options?: ConversationAbortOptions): Promise<void>;
77
+ /** Resolve when the conversation's ordinary ownership scope has no live non-background task. */
61
78
  waitForIdle(context: Context): Promise<void>;
62
79
  }
63
80
  /** Post-tools controls requested by a tool result. */
@@ -66,19 +83,42 @@ export type ToolControl = {
66
83
  readonly terminate?: true;
67
84
  readonly handoff?: string;
68
85
  };
86
+ /** Remark about a call for the model and the UI, such as truncation or a spill path; never part of the tool's data. */
87
+ export type ToolDiagnostic = {
88
+ readonly severity: "info" | "warn" | "error";
89
+ readonly message: string;
90
+ readonly code?: string;
91
+ };
69
92
  export type ToolExecutionResult = {
93
+ /** Omitted: the retained `output()` text becomes the content. */
70
94
  readonly content?: ToolResultMessage["content"];
71
95
  readonly isError?: boolean;
96
+ /** Omitted: the last `details()` value becomes the details. */
72
97
  readonly details?: JsonValue;
98
+ /** Added after those recorded through `api.diagnostic()`. */
99
+ readonly diagnostics?: readonly ToolDiagnostic[];
100
+ /** Spend of the execution itself, such as a model call; stored on the result and in `pi.usage.tools`. */
101
+ readonly usage?: Usage;
73
102
  readonly control?: ToolControl;
74
103
  };
75
- /** Operations available to one tool invocation. */
104
+ /** Whether the tools of one round run at once or one after another in call order. */
105
+ export type ToolExecutionMode = "parallel" | "sequential";
106
+ /** How many queued items of one mode a boundary places: the first, or all of them. */
107
+ export type QueueMode = "all" | "one-at-a-time";
108
+ /**
109
+ * Operations available to one tool invocation. A plain object, so a wrapper can pass `{ ...api, env }` to the tool it
110
+ * wraps. Every operation rejects after the invocation ends.
111
+ */
76
112
  export interface ToolExecutionApi extends DocumentObserver, DocumentReader {
77
113
  readonly taskId: TaskId;
78
114
  readonly conversationId: ConversationId;
79
115
  readonly callId: string;
116
+ /** `HarnessOptions.env` unless a wrapper supplies another environment. */
117
+ readonly env: ExecutionEnv | undefined;
80
118
  /** Append running output; it becomes the result content when the result omits `content`. */
81
119
  output(chunk: string | Uint8Array): void;
120
+ /** Record a model-visible remark about this call. */
121
+ diagnostic(diagnostic: ToolDiagnostic): void;
82
122
  /** Replace running details; the last value becomes the result details when the result omits `details`. */
83
123
  details(value: JsonValue, context: Context): Promise<void>;
84
124
  commit<T>(change: (tx: Tx) => T | Promise<T>, context: Context): Promise<T>;
@@ -89,12 +129,20 @@ export interface ToolExecutionApi extends DocumentObserver, DocumentReader {
89
129
  }, R, H extends object>(task: Task<I, S, R, H>, input: I, options: Omit<TaskOptions, "conversationId">, context: Context): Promise<TaskId<R>>;
90
130
  getTask<R>(id: TaskId<R>, context: Context): Promise<TaskRecord<JsonValue, JsonValue, R> | undefined>;
91
131
  waitForTask<R>(id: TaskId<R>, context: Context): Promise<SettledTask<R>>;
132
+ /** Invocation-bound handle of an existing conversation, such as one this tool created in `commit()`. */
92
133
  conversation(id: ConversationId, context: Context): Promise<ConversationHandle | undefined>;
93
134
  }
94
135
  /** Executable tool registered in a registry. Only pi-ai `Tool` fields enter the transcript. */
95
136
  export type ToolRegistration = Tool & {
96
137
  /** Whether an interrupted execution may rerun on recovery. Default `unsafe`. */
97
138
  readonly replay?: "safe" | "unsafe";
139
+ /** Default: the conversation's `toolExecution`. One sequential call makes its whole round sequential. */
140
+ readonly executionMode?: ToolExecutionMode;
141
+ /**
142
+ * Repair arguments models commonly get wrong before validation, such as a JSON string where an array belongs. Must be
143
+ * pure and must not mutate `args`: it runs again when a call is retried before its intent is recorded.
144
+ */
145
+ prepareArguments?(args: JsonValue): JsonValue;
98
146
  readonly outputLimits?: {
99
147
  readonly maxBytes?: number;
100
148
  readonly maxLines?: number;
@@ -246,10 +294,33 @@ export type ConversationRetryPolicy = {
246
294
  baseDelayMs: number;
247
295
  maxAgentDelayMs?: number;
248
296
  };
297
+ /** Automatic compaction thresholds (spec §8.7); manual compaction ignores `enabled`. */
298
+ export type CompactionPolicy = {
299
+ /** Threshold and overflow compaction. */
300
+ enabled: boolean;
301
+ /** Room kept free for the answer: generation blocks to compact above `contextWindow - reserveTokens`. */
302
+ reserveTokens: number;
303
+ /** Approximate size of the recent context a summary keeps verbatim. */
304
+ keepRecentTokens: number;
305
+ /** Background compaction starts `backgroundTokens` below the blocking threshold; `0` disables it. */
306
+ backgroundTokens: number;
307
+ };
308
+ /** Why a compaction runs: `compact()`, a threshold in generation preparation, or a context overflow. */
309
+ export type CompactionReason = "manual" | "threshold" | "overflow";
310
+ /**
311
+ * `entryId` of a blocking compaction's summary, or the `submissionId` of a conversation-owned compaction's summary
312
+ * write; both absent when nothing was compacted.
313
+ */
314
+ export type CompactionResult = {
315
+ entryId?: EntryId;
316
+ submissionId?: SubmissionId;
317
+ };
249
318
  export type HarnessOptions<Tool extends ToolRegistration = ToolRegistration> = {
250
319
  /** pi-ai model access used by generation. */
251
320
  readonly models: Models;
252
321
  readonly registry: RegistryReader<Tool>;
322
+ /** Default execution environment offered to tools as `api.env`. */
323
+ readonly env?: ExecutionEnv;
253
324
  readonly now?: () => number;
254
325
  /** Receives extension failures that do not fail the calling operation. Must not throw. */
255
326
  readonly onReport?: (error: unknown) => void;
@@ -265,11 +336,18 @@ export type TaskInspection = {
265
336
  readonly kind: "ready";
266
337
  readonly migrates: boolean;
267
338
  }
268
- /** Pending until these tasks are terminal. */
339
+ /**
340
+ * Waits for these live tasks: the live part of its `on`, or, when abort-marked, its live ordinary owned work, which
341
+ * must end before its abort handler starts.
342
+ */
269
343
  | {
270
344
  readonly kind: "waiting";
271
345
  readonly on: readonly TaskId[];
272
346
  }
347
+ /** Outcome held until its ordinary owned work drains. */
348
+ | {
349
+ readonly kind: "completing";
350
+ }
273
351
  /** No registered definition can take it; aborting it settles it as `orphaned`. */
274
352
  | {
275
353
  readonly kind: "blocked";
@@ -292,6 +370,8 @@ export type ContextView = {
292
370
  readonly head: EntryRecord | undefined;
293
371
  /** Raw active entries: the head marker followed by non-head entries from its head through the tail. */
294
372
  readonly entries: readonly EntryRecord[];
373
+ /** Per entry of `entries`, its model messages after edits and excluded stop reasons, before tool result ordering. */
374
+ readonly contributions: readonly (readonly Message[])[];
295
375
  /** Model context for the next provider request. */
296
376
  readonly messages: readonly Message[];
297
377
  };
@@ -311,19 +391,57 @@ export interface Conversation {
311
391
  getRetryPolicy(context: Context): Promise<ConversationRetryPolicy>;
312
392
  /** `undefined` removes the configured policy. */
313
393
  setRetryPolicy(policy: ConversationRetryPolicy | undefined, context: Context): Promise<void>;
394
+ /** `parallel` when unset. */
395
+ getToolExecution(context: Context): Promise<ToolExecutionMode>;
396
+ /** `undefined` removes the configured mode. */
397
+ setToolExecution(mode: ToolExecutionMode | undefined, context: Context): Promise<void>;
398
+ /** `one-at-a-time` when unset. */
399
+ getSteeringMode(context: Context): Promise<QueueMode>;
400
+ /** `undefined` removes the configured mode. */
401
+ setSteeringMode(mode: QueueMode | undefined, context: Context): Promise<void>;
402
+ /** `one-at-a-time` when unset. */
403
+ getFollowUpMode(context: Context): Promise<QueueMode>;
404
+ /** `undefined` removes the configured mode. */
405
+ setFollowUpMode(mode: QueueMode | undefined, context: Context): Promise<void>;
406
+ /** `DEFAULT_COMPACTION_POLICY` when unset. */
407
+ getCompaction(context: Context): Promise<CompactionPolicy>;
408
+ /** `undefined` removes the configured policy. */
409
+ setCompaction(policy: CompactionPolicy | undefined, context: Context): Promise<void>;
314
410
  /**
315
- * Durably admit user input or a passive entry write. Until the inbox exists, a busy conversation rejects every
316
- * submission with `ConversationBusy`.
411
+ * Durably admit user input or a passive entry write. A busy conversation, or one with queued items, queues it in
412
+ * `pi.inbox`; `whenBusy: "reject"` rejects with `ConversationBusy` instead and writes nothing.
317
413
  */
318
414
  submit(submission: SubmissionDraft, context: Context): Promise<Submission>;
415
+ /**
416
+ * Admit a write of a `pi.reset` entry that starts a new context, carrying `handoff` as a user message when given.
417
+ * Resolves after admission; while busy, it is placed at the next boundary.
418
+ */
419
+ reset(handoff: string | undefined, context: Context): Promise<void>;
420
+ /**
421
+ * Admit a manual compaction task and return its ID. It summarizes while the conversation keeps working and places its
422
+ * summary through a write submission: at once when idle, otherwise at the next boundary (spec §8.7).
423
+ */
424
+ compact(instructions: string | undefined, context: Context): Promise<TaskId<CompactionResult>>;
319
425
  /** Session commit whose `tx.createTask()` defaults to this conversation. */
320
426
  commit<T>(change: (tx: Tx) => T | Promise<T>, context: Context): Promise<T>;
321
427
  context(context: Context): Promise<ContextView>;
322
428
  /** Newest-first fork-aware history of this conversation. */
323
429
  entries(query: Omit<EntryQuery, "conversationId">, limit: number, cursor: Cursor | undefined, context: Context): Promise<Page<EntryRecord, Cursor>>;
324
430
  fork(at: EntryId, options: ConversationCreateOptions, context: Context): Promise<Conversation>;
325
- /** Resolve when no live non-background task belongs to this conversation. */
431
+ /**
432
+ * Withdraw queued inputs (queued writes stay), mark every live non-background task of the ordinary ownership scope,
433
+ * signal them, and resolve once the scope is idle. Background subtrees survive unless `background` is set.
434
+ */
435
+ abort(context: Context, options?: ConversationAbortOptions): Promise<void>;
436
+ /**
437
+ * Resolve when the ordinary ownership scope has no live non-background task: this conversation and the conversations
438
+ * owned, transitively, by its non-background tasks.
439
+ */
326
440
  waitForIdle(context: Context): Promise<void>;
441
+ /** The structural view (spec §9.3) as a disposable read-only Chord state. */
442
+ viewState(context: Context): Promise<AttachedReplicatedState<ConversationView>>;
443
+ /** The structural view as a serialized exact-frame watch with bounded pending frames. */
444
+ watch(context: Context): Promise<WatchHandle<ConversationView>>;
327
445
  }
328
446
  /** Durable agent harness over one Session. */
329
447
  export interface Harness extends Session {
@@ -352,7 +470,63 @@ export interface Harness extends Session {
352
470
  abortTask(id: TaskId, context: Context): Promise<"marked" | "terminal">;
353
471
  /** Resolve with the terminal receipt; cancelling `context` cancels only this wait. */
354
472
  waitForTask<R>(id: TaskId<R>, context: Context): Promise<SettledTask<R>>;
355
- /** Resolve when no live non-background task exists. */
473
+ /** Resolve when the ordinary ownership scope of every ownerless conversation has no live non-background task. */
356
474
  waitForIdle(context: Context): Promise<void>;
475
+ /** Session total: every conversation's `pi.usage` summed. */
476
+ usage(context: Context): Promise<UsageState>;
477
+ }
478
+ /** What a hook may use: committed reads and the asking task's memos, which hooks and the task share. */
479
+ export interface HookApi extends DocumentReader {
480
+ readonly taskId: TaskId;
481
+ readonly conversationId: ConversationId;
482
+ memo<T extends JsonValue>(name: string, context: Context): Promise<T | undefined>;
483
+ memo<T extends JsonValue>(name: string, candidate: T, context: Context): Promise<T>;
484
+ }
485
+ export type HookResult<T> = T | undefined | Promise<T | undefined>;
486
+ /** Hooks of the built-in generation task. */
487
+ export interface GenerationHooks {
488
+ /** Before every request attempt, including recovery; the result is used for that request only. */
489
+ beforeRequest(request: {
490
+ readonly messages: readonly Message[];
491
+ }, api: HookApi, context: Context): HookResult<{
492
+ readonly messages: readonly Message[];
493
+ }>;
494
+ /** Every terminal provider message, before classification. */
495
+ afterResponse(message: AssistantMessage, api: HookApi, context: Context): void | Promise<void>;
496
+ /** A final answer; the first `continue` appends a user message and continues the run. */
497
+ onYield(answer: AssistantMessage, api: HookApi, context: Context): HookResult<{
498
+ readonly continue: UserInput;
499
+ }>;
500
+ /** After every tool of the round is terminal; `results` are the round's result entries in call order. */
501
+ afterTools(assistant: EntryId, results: readonly EntryId[], api: HookApi, context: Context): void | Promise<void>;
502
+ }
503
+ /** Hooks of the built-in tool task. */
504
+ export interface ToolHooks {
505
+ /** Before intent; the first `block` wins, otherwise `arguments` replace the call's arguments. A throw blocks. */
506
+ beforeTool(call: ToolCall, api: HookApi, context: Context): HookResult<{
507
+ readonly arguments?: JsonObject;
508
+ readonly block?: string;
509
+ }>;
510
+ /** After execution, before the result entry; replaces the result. */
511
+ afterTool(call: ToolCall, result: ToolExecutionResult, api: HookApi, context: Context): HookResult<ToolExecutionResult>;
512
+ }
513
+ /** Hooks of the built-in compaction task. */
514
+ export interface CompactionHooks {
515
+ /**
516
+ * After range selection, before summarizing; the first decision wins. `entries` are the active entries the summary
517
+ * replaces, the head marker first, and `messages` their model context, the summarizer's source; `firstKept` is the
518
+ * first entry kept verbatim.
519
+ */
520
+ beforeCompact(compaction: {
521
+ readonly reason: CompactionReason;
522
+ readonly entries: readonly EntryRecord[];
523
+ readonly messages: readonly Message[];
524
+ readonly firstKept: EntryId;
525
+ readonly instructions?: string;
526
+ }, api: HookApi, context: Context): HookResult<{
527
+ readonly decline: true;
528
+ } | {
529
+ readonly summary: string;
530
+ }>;
357
531
  }
358
532
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/harness/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EACX,cAAc,EACd,OAAO,EACP,MAAM,EACN,kBAAkB,EAClB,IAAI,EACJ,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACX,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EAClB,MAAM,EACN,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,OAAO,EACP,UAAU,EACV,WAAW,EACX,UAAU,EACV,IAAI,EACJ,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,IAAI,EACJ,MAAM,EACN,WAAW,EACX,UAAU,EACV,SAAS,EACT,EAAE,EACF,MAAM,aAAa,CAAC;AAErB,6DAA6D;AAC7D,MAAM,MAAM,QAAQ,GAAG;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAA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CAAC;KAC/B,EACD,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,OAAO,GACd,UAAU,CAAC;QAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAA;KAAE,GAAG;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACzE"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/harness/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Context, JsonValue } from \"@earendil-works/chord\";\nimport type {\n\tCacheRetention,\n\tMessage,\n\tModels,\n\tModelThinkingLevel,\n\tTool,\n\tToolResultMessage,\n\tTransport,\n\tUserMessage,\n} from \"@earendil-works/pi-ai\";\nimport type {\n\tConversationId,\n\tConversationOwnership,\n\tConversationRecord,\n\tCursor,\n\tDocumentObserver,\n\tDocumentReader,\n\tEntryDraft,\n\tEntryId,\n\tEntryQuery,\n\tEntryRecord,\n\tJsonObject,\n\tPage,\n\tSession,\n\tSubmissionId,\n\tSubmissionRecord,\n\tTask,\n\tTaskId,\n\tTaskOptions,\n\tTaskRecord,\n\tTaskState,\n\tTx,\n} from \"../types.ts\";\n\n/** Provider and model ID resolved through pi-ai `Models`. */\nexport type ModelRef = {\n\treadonly provider: string;\n\treadonly modelId: string;\n};\n\nexport type UserInput = UserMessage[\"content\"];\n\n/** Host submission: user input that may start a run, or a passive entry write. */\nexport type SubmissionDraft = {\n\treadonly requestId?: string;\n} & (\n\t| {\n\t\t\treadonly type: \"input\";\n\t\t\treadonly content: UserInput;\n\t\t\treadonly whenBusy?: \"steer\" | \"followUp\" | \"reject\";\n\t\t\treadonly entry?: never;\n\t }\n\t| {\n\t\t\treadonly type: \"write\";\n\t\t\treadonly entry: EntryDraft;\n\t\t\treadonly content?: never;\n\t\t\treadonly whenBusy?: never;\n\t }\n);\n\nexport type InputSubmissionDraft = Extract<SubmissionDraft, { readonly type: \"input\" }>;\n\nexport type SettledSubmissionRecord = SubmissionRecord & {\n\treadonly status: \"done\" | \"unanswered\";\n};\n\n/** Awaitable host object for one durably admitted submission. */\nexport interface Submission {\n\treadonly id: SubmissionId;\n\tstatus(context: Context): Promise<SubmissionRecord>;\n\twait(context: Context): Promise<SettledSubmissionRecord>;\n\tabort(context: Context): Promise<\"aborted\" | \"already_placed\" | \"settled\">;\n}\n\nexport type SettledTask<R> = TaskRecord<JsonValue, JsonValue, R> & {\n\treadonly state: Extract<TaskState<JsonValue, R>, { readonly status: \"terminal\" }>;\n};\n\n/** Erased executable task definition stored in the registry. */\nexport type AnyTask = {\n\treadonly definition: {\n\t\treadonly name: string;\n\t\treadonly version: number;\n\t\treadonly initial: unknown;\n\t\treadonly phases: Readonly<Record<string, unknown>>;\n\t\treadonly abort: unknown;\n\t\treadonly migrate?: unknown;\n\t\treadonly hooks?: object;\n\t};\n};\n\n/** Hook handler map declared by a task definition. */\nexport type HooksOf<K> = K extends Task<infer _I, infer _S, infer _R, infer H> ? H : never;\n\n/** Invocation-bound conversation operations available to tools. */\nexport interface ConversationHandle {\n\treadonly id: ConversationId;\n\tsubmit(submission: InputSubmissionDraft, context: Context): Promise<Submission>;\n\tabort(context: Context): Promise<void>;\n\twaitForIdle(context: Context): Promise<void>;\n}\n\n/** Post-tools controls requested by a tool result. */\nexport type ToolControl = {\n\treadonly addTools?: readonly string[];\n\treadonly terminate?: true;\n\treadonly handoff?: string;\n};\n\nexport type ToolExecutionResult = {\n\treadonly content?: ToolResultMessage[\"content\"];\n\treadonly isError?: boolean;\n\treadonly details?: JsonValue;\n\treadonly control?: ToolControl;\n};\n\n/** Operations available to one tool invocation. */\nexport interface ToolExecutionApi extends DocumentObserver, DocumentReader {\n\treadonly taskId: TaskId;\n\treadonly conversationId: ConversationId;\n\treadonly callId: string;\n\t/** Append running output; it becomes the result content when the result omits `content`. */\n\toutput(chunk: string | Uint8Array): void;\n\t/** Replace running details; the last value becomes the result details when the result omits `details`. */\n\tdetails(value: JsonValue, context: Context): Promise<void>;\n\tcommit<T>(change: (tx: Tx) => T | Promise<T>, context: Context): Promise<T>;\n\tmemo<T extends JsonValue>(name: string, context: Context): Promise<T | undefined>;\n\tmemo<T extends JsonValue>(name: string, candidate: T, context: Context): Promise<T>;\n\tcreateTask<I, S extends { phase: string }, R, H extends object>(\n\t\ttask: Task<I, S, R, H>,\n\t\tinput: I,\n\t\toptions: Omit<TaskOptions, \"conversationId\">,\n\t\tcontext: Context,\n\t): Promise<TaskId<R>>;\n\tgetTask<R>(id: TaskId<R>, context: Context): Promise<TaskRecord<JsonValue, JsonValue, R> | undefined>;\n\twaitForTask<R>(id: TaskId<R>, context: Context): Promise<SettledTask<R>>;\n\tconversation(id: ConversationId, context: Context): Promise<ConversationHandle | undefined>;\n}\n\n/** Executable tool registered in a registry. Only pi-ai `Tool` fields enter the transcript. */\nexport type ToolRegistration = Tool & {\n\t/** Whether an interrupted execution may rerun on recovery. Default `unsafe`. */\n\treadonly replay?: \"safe\" | \"unsafe\";\n\treadonly outputLimits?: {\n\t\treadonly maxBytes?: number;\n\t\treadonly maxLines?: number;\n\t\treadonly retain?: \"head\" | \"tail\";\n\t};\n\texecute(args: JsonValue, api: ToolExecutionApi, context: Context): Promise<ToolExecutionResult>;\n};\n\n/** Token for removing registrations. Work already running keeps using what it started with. */\nexport interface Registration {\n\t/** Idempotent; removes exactly the registrations this token covers. */\n\tdispose(): void;\n}\n\n/** Pure decorator; returns a new tool with the same name and never mutates its input. */\nexport type ToolWrapper<Tool extends ToolRegistration> = (tool: Tool) => Tool;\n\n/** Conversation selection for a scoped hook registration. */\nexport type HookScope = {\n\treadonly conversationId: ConversationId;\n\t/** Also match conversations owned, transitively, by tasks of this conversation. */\n\treadonly subtree?: boolean;\n};\n\n/** Input to system prompt section rendering for one request preparation. */\nexport type PromptInput<Tool extends ToolRegistration> = {\n\treadonly conversationId: ConversationId;\n\t/** Active and registered tools in configured order, as offered in this request. */\n\treadonly tools: readonly Tool[];\n\t/** Sections already in effect after replaying the active transcript. */\n\treadonly shown: Readonly<Record<string, string>>;\n\treadonly model?: ModelRef;\n\treadonly thinkingLevel: ModelThinkingLevel;\n\t/** Committed document reads. */\n\treadonly read: DocumentReader;\n};\n\n/** One registered system prompt section; sections render in registry order before each request. */\nexport type PromptSection<Tool extends ToolRegistration> = {\n\treadonly key: string;\n\trender(input: PromptInput<Tool>, context: Context): string | undefined | Promise<string | undefined>;\n\t/** Default true: wrap the text as `<key>\\n...\\n</key>`. */\n\treadonly tag?: boolean;\n};\n\n/** Pure decorator; returns a new section with the same key and never mutates its input. */\nexport type PromptSectionWrapper<Tool extends ToolRegistration> = (section: PromptSection<Tool>) => PromptSection<Tool>;\n\n/** One registered hook handler map for task `K`. */\nexport type HookRegistration<K extends AnyTask> = {\n\treadonly handlers: Partial<HooksOf<K>>;\n\treadonly scope?: HookScope;\n};\n\n/** Wrapper composition failure found while building a snapshot. */\nexport type RegistryFailure = {\n\treadonly kind: \"tool\" | \"section\";\n\t/** Tool name or section key. */\n\treadonly name: string;\n\treadonly error: unknown;\n};\n\n/** Immutable view of one published registry state. */\nexport interface RegistrySnapshot<Tool extends ToolRegistration = ToolRegistration> {\n\t/** Composed tools in registry order; a tool whose wrapper failed is absent. */\n\ttools(): readonly Tool[];\n\ttool(name: string): Tool | undefined;\n\t/** Base tool names in registry order, including tools whose wrappers fail. */\n\ttoolNames(): readonly string[];\n\ttask(name: string): AnyTask | undefined;\n\t/** Hooks registered for tasks with `task`'s name, in registry order. */\n\thooks<K extends AnyTask>(task: K): readonly HookRegistration<K>[];\n\t/** Composed sections in registry order; a section whose wrapper failed is absent. */\n\tsections(): readonly PromptSection<Tool>[];\n\t/** Wrapper failures of this state. */\n\tfailures(): readonly RegistryFailure[];\n\t/** Conversation setups in registry order, the built-in `pi` setup first. */\n\tconversationSetups(): readonly { readonly key: string; readonly setup: ConversationSetup }[];\n}\n\n/** Read side of a registry consumed by a Harness. */\nexport interface RegistryReader<Tool extends ToolRegistration = ToolRegistration> {\n\t/** Immutable view of the whole current registry. */\n\tsnapshot(): RegistrySnapshot<Tool>;\n\t/** Called synchronously after every publication; wakes the scheduler to reconsider blocked tasks. */\n\tsubscribe(listener: () => void): () => void;\n}\n\n/** Application-owned registry of tools, hooks, tasks, and the system prompt. */\nexport interface Registry<Tool extends ToolRegistration = ToolRegistration> extends RegistryReader<Tool> {\n\treadonly tools: {\n\t\tadd(tool: Tool): Registration;\n\t\t/** `key` identifies the wrapper: it orders wrappers of one tool and keeps its position on re-registration. */\n\t\twrap(name: string, key: string, wrapper: ToolWrapper<Tool>): Registration;\n\t\t/** Composed tools of the current state. */\n\t\tlist(): readonly Tool[];\n\t};\n\treadonly hooks: {\n\t\tadd<K extends AnyTask>(\n\t\t\ttask: K,\n\t\t\thandlers: Partial<HooksOf<K>>,\n\t\t\toptions?: { readonly scope?: HookScope; readonly key?: string },\n\t\t): Registration;\n\t};\n\treadonly tasks: {\n\t\tadd(task: AnyTask): Registration;\n\t\tlist(): readonly AnyTask[];\n\t};\n\treadonly conversations: {\n\t\t/** `key` orders setups and keeps its position on re-registration. */\n\t\tsetup(key: string, setup: ConversationSetup): Registration;\n\t};\n\treadonly systemPrompt: {\n\t\tsection(key: string, render: PromptSection<Tool>[\"render\"], options?: { readonly tag?: boolean }): Registration;\n\t\twrap(key: string, wrapperKey: string, wrapper: PromptSectionWrapper<Tool>): Registration;\n\t\t/** Composed sections of the current state. */\n\t\tsections(): readonly PromptSection<Tool>[];\n\t};\n\t/** Stage registrations and disposals made synchronously by `register`, then publish them at once. Cannot nest. */\n\tbatch(register: () => void): Registration;\n}\n\n/**\n * Stages the documents every new conversation gets. Runs inside every Harness commit that creates or forks a\n * conversation, including raw `Tx` creation, after fork copies and before host `init`. Table reads throw, since the\n * conversation write came first; a fork (`conversation.parent`) already holds its copied documents. A throw fails the\n * creating commit.\n */\nexport type ConversationSetup = (\n\ttx: Tx,\n\tconversation: ConversationRecord,\n\tregistry: RegistrySnapshot,\n) => void | Promise<void>;\n\n/**\n * Runs inside the creating commit, after the conversation and its configuration exist. The conversation creation is\n * already a table write, so table reads here throw `ReadAfterWrite`; document access remains available.\n */\nexport type ConversationInit = (tx: Tx, conversationId: ConversationId) => void | Promise<void>;\n\nexport type ConversationCreateOptions = {\n\treadonly ownership: ConversationOwnership;\n\treadonly init?: ConversationInit;\n};\n\n/** Curated pi-ai request options; absent fields use pi-ai defaults. */\nexport type ConversationStreamOptions = {\n\ttransport?: Transport;\n\ttimeoutMs?: number;\n\t/** Provider/SDK retries inside one request attempt. */\n\tmaxRetries?: number;\n\tmaxRetryDelayMs?: number;\n\theaders?: Record<string, string>;\n\tmetadata?: JsonObject;\n\tcacheRetention?: CacheRetention;\n\tdeferred?: boolean | { window?: \"15m\" | \"1h\" | \"24h\" };\n};\n\n/** Durable generation attempt retries; the JSON shape of pi-ai `RetryPolicy`. */\nexport type ConversationRetryPolicy = {\n\tenabled: boolean;\n\tmaxRetries: number;\n\tbaseDelayMs: number;\n\tmaxAgentDelayMs?: number;\n};\n\nexport type HarnessOptions<Tool extends ToolRegistration = ToolRegistration> = {\n\t/** pi-ai model access used by generation. */\n\treadonly models: Models;\n\treadonly registry: RegistryReader<Tool>;\n\treadonly now?: () => number;\n\t/** Receives extension failures that do not fail the calling operation. Must not throw. */\n\treadonly onReport?: (error: unknown) => void;\n};\n\n/** Live task and what the scheduler would do with it under the current registry. */\nexport type TaskInspection = {\n\treadonly record: TaskRecord<JsonValue, JsonValue, JsonValue>;\n\treadonly state: /** An invocation is active. */\n\t\t| { readonly kind: \"running\" }\n\t\t/** The next scheduling pass reserves it; `migrates` when its definition is newer and has `migrate`. */\n\t\t| { readonly kind: \"ready\"; readonly migrates: boolean }\n\t\t/** Pending until these tasks are terminal. */\n\t\t| { readonly kind: \"waiting\"; readonly on: readonly TaskId[] }\n\t\t/** No registered definition can take it; aborting it settles it as `orphaned`. */\n\t\t| {\n\t\t\t\treadonly kind: \"blocked\";\n\t\t\t\treadonly reason: \"missing_task\" | \"task_too_old\" | \"migration_failed\";\n\t\t\t\treadonly error?: unknown;\n\t\t };\n};\n\n/** Point-in-time view of live work: unfinished tasks and submissions, read on the Session line. */\nexport type HarnessInspection = {\n\treadonly scheduling: \"paused\" | \"running\" | \"closing\";\n\treadonly tasks: readonly TaskInspection[];\n\t/** Queued and placed submissions, in ID order. */\n\treadonly submissions: readonly SubmissionRecord[];\n\t/** Wrapper failures of the current registry snapshot. */\n\treadonly registry: readonly RegistryFailure[];\n};\n\n/** Raw active transcript and derived model context. */\nexport type ContextView = {\n\t/** Newest applicable head marker, if any. */\n\treadonly head: EntryRecord | undefined;\n\t/** Raw active entries: the head marker followed by non-head entries from its head through the tail. */\n\treadonly entries: readonly EntryRecord[];\n\t/** Model context for the next provider request. */\n\treadonly messages: readonly Message[];\n};\n\n/** Stateless handle for one conversation, bound to the Harness that returned it. Compare handles by `id`. */\nexport interface Conversation {\n\treadonly id: ConversationId;\n\n\tgetModel(context: Context): Promise<ModelRef | undefined>;\n\tsetModel(model: ModelRef | undefined, context: Context): Promise<void>;\n\tgetThinkingLevel(context: Context): Promise<ModelThinkingLevel>;\n\tsetThinkingLevel(level: ModelThinkingLevel, context: Context): Promise<void>;\n\tgetActiveTools(context: Context): Promise<readonly string[]>;\n\tsetActiveTools(names: readonly string[], context: Context): Promise<void>;\n\t/** `{}` when unset. */\n\tgetStreamOptions(context: Context): Promise<ConversationStreamOptions>;\n\tsetStreamOptions(options: ConversationStreamOptions, context: Context): Promise<void>;\n\t/** The default policy when unset. */\n\tgetRetryPolicy(context: Context): Promise<ConversationRetryPolicy>;\n\t/** `undefined` removes the configured policy. */\n\tsetRetryPolicy(policy: ConversationRetryPolicy | undefined, context: Context): Promise<void>;\n\n\t/**\n\t * Durably admit user input or a passive entry write. Until the inbox exists, a busy conversation rejects every\n\t * submission with `ConversationBusy`.\n\t */\n\tsubmit(submission: SubmissionDraft, context: Context): Promise<Submission>;\n\n\t/** Session commit whose `tx.createTask()` defaults to this conversation. */\n\tcommit<T>(change: (tx: Tx) => T | Promise<T>, context: Context): Promise<T>;\n\tcontext(context: Context): Promise<ContextView>;\n\t/** Newest-first fork-aware history of this conversation. */\n\tentries(\n\t\tquery: Omit<EntryQuery, \"conversationId\">,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<EntryRecord, Cursor>>;\n\tfork(at: EntryId, options: ConversationCreateOptions, context: Context): Promise<Conversation>;\n\t/** Resolve when no live non-background task belongs to this conversation. */\n\twaitForIdle(context: Context): Promise<void>;\n}\n\n// TODO: decide how Harness exposes subscribeCommits() and subscribeClose(). Their listeners run on the Session line\n// and must not throw or call Session APIs, and Harness close will also join task invocations.\n/** Durable agent harness over one Session. */\nexport interface Harness extends Session {\n\t/**\n\t * Enable task scheduling. Idempotent; throws after close. Calls that wait for progress (`Conversation.submit()`,\n\t * `Submission.wait()`, `waitForTask()`, `waitForIdle()`) enable it too.\n\t */\n\tresume(): void;\n\n\t/** Return the reserved root conversation, creating it with `init` in one commit when absent. */\n\troot(context: Context, options?: { readonly init?: ConversationInit }): Promise<Conversation>;\n\t// Conversation activity (active/idle notifications) is specified with run control in Package 17.\n\tconversation(id: ConversationId, context: Context): Promise<Conversation | undefined>;\n\tcreateConversation(options: ConversationCreateOptions, context: Context): Promise<Conversation>;\n\n\tgetTask<R>(id: TaskId<R>, context: Context): Promise<TaskRecord<JsonValue, JsonValue, R> | undefined>;\n\t/** Live tasks, unsettled submissions, and registry failures. Writes nothing and runs no task code. */\n\tinspect(context: Context): Promise<HarnessInspection>;\n\t/** Reacquire a submission, for example after reopen. */\n\tsubmission(id: SubmissionId, context: Context): Promise<Submission | undefined>;\n\t/** `not_found` for an unknown submission or one of another conversation than `conversationId`. */\n\tabortSubmission(\n\t\tid: SubmissionId,\n\t\tcontext: Context,\n\t\tconversationId?: ConversationId,\n\t): Promise<\"aborted\" | \"already_placed\" | \"settled\" | \"not_found\">;\n\t/**\n\t * Commit the abort mark, signal and join an active run invocation, and schedule the abort invocation. A task whose\n\t * definition cannot take it settles as `orphaned` instead.\n\t */\n\tabortTask(id: TaskId, context: Context): Promise<\"marked\" | \"terminal\">;\n\t/** Resolve with the terminal receipt; cancelling `context` cancels only this wait. */\n\twaitForTask<R>(id: TaskId<R>, context: Context): Promise<SettledTask<R>>;\n\t/** Resolve when no live non-background task exists. */\n\twaitForIdle(context: Context): Promise<void>;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/harness/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AttachedReplicatedState, Context, JsonValue } from \"@earendil-works/chord\";\nimport type {\n\tAssistantMessage,\n\tCacheRetention,\n\tMessage,\n\tModels,\n\tModelThinkingLevel,\n\tTool,\n\tToolCall,\n\tToolResultMessage,\n\tTransport,\n\tUsage,\n\tUserMessage,\n} from \"@earendil-works/pi-ai\";\nimport type { ExecutionEnv } from \"../env/index.ts\";\nimport type {\n\tConversationId,\n\tConversationOwnership,\n\tConversationRecord,\n\tCursor,\n\tDocumentObserver,\n\tDocumentReader,\n\tEntryDraft,\n\tEntryId,\n\tEntryQuery,\n\tEntryRecord,\n\tJsonObject,\n\tPage,\n\tSession,\n\tSubmissionId,\n\tSubmissionRecord,\n\tTask,\n\tTaskId,\n\tTaskOptions,\n\tTaskRecord,\n\tTaskState,\n\tTx,\n\tWatchHandle,\n} from \"../types.ts\";\nimport type { UsageState } from \"./usage.ts\";\nimport type { ConversationView } from \"./view.ts\";\n\n/** Provider and model ID resolved through pi-ai `Models`. */\nexport type ModelRef = {\n\treadonly provider: string;\n\treadonly modelId: string;\n};\n\nexport type UserInput = UserMessage[\"content\"];\n\n/** Host submission: user input that may start a run, or a passive entry write. */\nexport type SubmissionDraft = {\n\treadonly requestId?: string;\n} & (\n\t| {\n\t\t\treadonly type: \"input\";\n\t\t\treadonly content: UserInput;\n\t\t\treadonly whenBusy?: \"steer\" | \"followUp\" | \"reject\";\n\t\t\treadonly entry?: never;\n\t }\n\t| {\n\t\t\treadonly type: \"write\";\n\t\t\treadonly entry: EntryDraft;\n\t\t\treadonly content?: never;\n\t\t\treadonly whenBusy?: never;\n\t }\n);\n\nexport type InputSubmissionDraft = Extract<SubmissionDraft, { readonly type: \"input\" }>;\n\nexport type SettledSubmissionRecord = SubmissionRecord & {\n\treadonly status: \"done\" | \"unanswered\";\n};\n\n/** Awaitable host object for one durably admitted submission. */\nexport interface Submission {\n\treadonly id: SubmissionId;\n\tstatus(context: Context): Promise<SubmissionRecord>;\n\twait(context: Context): Promise<SettledSubmissionRecord>;\n\tabort(context: Context): Promise<\"aborted\" | \"already_placed\" | \"settled\">;\n}\n\nexport type SettledTask<R> = TaskRecord<JsonValue, JsonValue, R> & {\n\treadonly state: Extract<TaskState<JsonValue, R>, { readonly status: \"terminal\" }>;\n};\n\n/** Erased executable task definition stored in the registry. */\nexport type AnyTask = {\n\treadonly definition: {\n\t\treadonly name: string;\n\t\treadonly version: number;\n\t\treadonly initial: unknown;\n\t\treadonly phases: Readonly<Record<string, unknown>>;\n\t\treadonly abort: unknown;\n\t\treadonly migrate?: unknown;\n\t\treadonly hooks?: object;\n\t};\n};\n\n/** Options of `Conversation.abort()`. */\nexport type ConversationAbortOptions = {\n\t/**\n\t * Cross background boundaries: mark every live task reached ignoring the background flag when the abort is admitted,\n\t * withdraw the queued inputs of every conversation reached, and wait until those tasks are terminal and the\n\t * conversation is ordinarily idle. Background work created afterwards is neither marked nor awaited.\n\t */\n\treadonly background?: boolean;\n};\n\n/** Hook handler map declared by a task definition. */\nexport type HooksOf<K> = K extends Task<infer _I, infer _S, infer _R, infer H> ? H : never;\n\n/**\n * Invocation-bound conversation operations for tasks and tools. Rejects after the invocation ends; passive entries are\n * written with ordinary transaction writes instead.\n */\nexport interface ConversationHandle {\n\treadonly id: ConversationId;\n\tsubmit(submission: InputSubmissionDraft, context: Context): Promise<Submission>;\n\t/** `Conversation.abort()`: withdraw queued inputs, abort the ordinary ownership scope, and wait until it is idle. */\n\tabort(context: Context, options?: ConversationAbortOptions): Promise<void>;\n\t/** Resolve when the conversation's ordinary ownership scope has no live non-background task. */\n\twaitForIdle(context: Context): Promise<void>;\n}\n\n/** Post-tools controls requested by a tool result. */\nexport type ToolControl = {\n\treadonly addTools?: readonly string[];\n\treadonly terminate?: true;\n\treadonly handoff?: string;\n};\n\n/** Remark about a call for the model and the UI, such as truncation or a spill path; never part of the tool's data. */\nexport type ToolDiagnostic = {\n\treadonly severity: \"info\" | \"warn\" | \"error\";\n\treadonly message: string;\n\treadonly code?: string;\n};\n\nexport type ToolExecutionResult = {\n\t/** Omitted: the retained `output()` text becomes the content. */\n\treadonly content?: ToolResultMessage[\"content\"];\n\treadonly isError?: boolean;\n\t/** Omitted: the last `details()` value becomes the details. */\n\treadonly details?: JsonValue;\n\t/** Added after those recorded through `api.diagnostic()`. */\n\treadonly diagnostics?: readonly ToolDiagnostic[];\n\t/** Spend of the execution itself, such as a model call; stored on the result and in `pi.usage.tools`. */\n\treadonly usage?: Usage;\n\treadonly control?: ToolControl;\n};\n\n/** Whether the tools of one round run at once or one after another in call order. */\nexport type ToolExecutionMode = \"parallel\" | \"sequential\";\n\n/** How many queued items of one mode a boundary places: the first, or all of them. */\nexport type QueueMode = \"all\" | \"one-at-a-time\";\n\n/**\n * Operations available to one tool invocation. A plain object, so a wrapper can pass `{ ...api, env }` to the tool it\n * wraps. Every operation rejects after the invocation ends.\n */\nexport interface ToolExecutionApi extends DocumentObserver, DocumentReader {\n\treadonly taskId: TaskId;\n\treadonly conversationId: ConversationId;\n\treadonly callId: string;\n\t/** `HarnessOptions.env` unless a wrapper supplies another environment. */\n\treadonly env: ExecutionEnv | undefined;\n\t/** Append running output; it becomes the result content when the result omits `content`. */\n\toutput(chunk: string | Uint8Array): void;\n\t/** Record a model-visible remark about this call. */\n\tdiagnostic(diagnostic: ToolDiagnostic): void;\n\t/** Replace running details; the last value becomes the result details when the result omits `details`. */\n\tdetails(value: JsonValue, context: Context): Promise<void>;\n\tcommit<T>(change: (tx: Tx) => T | Promise<T>, context: Context): Promise<T>;\n\tmemo<T extends JsonValue>(name: string, context: Context): Promise<T | undefined>;\n\tmemo<T extends JsonValue>(name: string, candidate: T, context: Context): Promise<T>;\n\tcreateTask<I, S extends { phase: string }, R, H extends object>(\n\t\ttask: Task<I, S, R, H>,\n\t\tinput: I,\n\t\toptions: Omit<TaskOptions, \"conversationId\">,\n\t\tcontext: Context,\n\t): Promise<TaskId<R>>;\n\tgetTask<R>(id: TaskId<R>, context: Context): Promise<TaskRecord<JsonValue, JsonValue, R> | undefined>;\n\twaitForTask<R>(id: TaskId<R>, context: Context): Promise<SettledTask<R>>;\n\t/** Invocation-bound handle of an existing conversation, such as one this tool created in `commit()`. */\n\tconversation(id: ConversationId, context: Context): Promise<ConversationHandle | undefined>;\n}\n\n/** Executable tool registered in a registry. Only pi-ai `Tool` fields enter the transcript. */\nexport type ToolRegistration = Tool & {\n\t/** Whether an interrupted execution may rerun on recovery. Default `unsafe`. */\n\treadonly replay?: \"safe\" | \"unsafe\";\n\t/** Default: the conversation's `toolExecution`. One sequential call makes its whole round sequential. */\n\treadonly executionMode?: ToolExecutionMode;\n\t/**\n\t * Repair arguments models commonly get wrong before validation, such as a JSON string where an array belongs. Must be\n\t * pure and must not mutate `args`: it runs again when a call is retried before its intent is recorded.\n\t */\n\tprepareArguments?(args: JsonValue): JsonValue;\n\treadonly outputLimits?: {\n\t\treadonly maxBytes?: number;\n\t\treadonly maxLines?: number;\n\t\treadonly retain?: \"head\" | \"tail\";\n\t};\n\texecute(args: JsonValue, api: ToolExecutionApi, context: Context): Promise<ToolExecutionResult>;\n};\n\n/** Token for removing registrations. Work already running keeps using what it started with. */\nexport interface Registration {\n\t/** Idempotent; removes exactly the registrations this token covers. */\n\tdispose(): void;\n}\n\n/** Pure decorator; returns a new tool with the same name and never mutates its input. */\nexport type ToolWrapper<Tool extends ToolRegistration> = (tool: Tool) => Tool;\n\n/** Conversation selection for a scoped hook registration. */\nexport type HookScope = {\n\treadonly conversationId: ConversationId;\n\t/** Also match conversations owned, transitively, by tasks of this conversation. */\n\treadonly subtree?: boolean;\n};\n\n/** Input to system prompt section rendering for one request preparation. */\nexport type PromptInput<Tool extends ToolRegistration> = {\n\treadonly conversationId: ConversationId;\n\t/** Active and registered tools in configured order, as offered in this request. */\n\treadonly tools: readonly Tool[];\n\t/** Sections already in effect after replaying the active transcript. */\n\treadonly shown: Readonly<Record<string, string>>;\n\treadonly model?: ModelRef;\n\treadonly thinkingLevel: ModelThinkingLevel;\n\t/** Committed document reads. */\n\treadonly read: DocumentReader;\n};\n\n/** One registered system prompt section; sections render in registry order before each request. */\nexport type PromptSection<Tool extends ToolRegistration> = {\n\treadonly key: string;\n\trender(input: PromptInput<Tool>, context: Context): string | undefined | Promise<string | undefined>;\n\t/** Default true: wrap the text as `<key>\\n...\\n</key>`. */\n\treadonly tag?: boolean;\n};\n\n/** Pure decorator; returns a new section with the same key and never mutates its input. */\nexport type PromptSectionWrapper<Tool extends ToolRegistration> = (section: PromptSection<Tool>) => PromptSection<Tool>;\n\n/** One registered hook handler map for task `K`. */\nexport type HookRegistration<K extends AnyTask> = {\n\treadonly handlers: Partial<HooksOf<K>>;\n\treadonly scope?: HookScope;\n};\n\n/** Wrapper composition failure found while building a snapshot. */\nexport type RegistryFailure = {\n\treadonly kind: \"tool\" | \"section\";\n\t/** Tool name or section key. */\n\treadonly name: string;\n\treadonly error: unknown;\n};\n\n/** Immutable view of one published registry state. */\nexport interface RegistrySnapshot<Tool extends ToolRegistration = ToolRegistration> {\n\t/** Composed tools in registry order; a tool whose wrapper failed is absent. */\n\ttools(): readonly Tool[];\n\ttool(name: string): Tool | undefined;\n\t/** Base tool names in registry order, including tools whose wrappers fail. */\n\ttoolNames(): readonly string[];\n\ttask(name: string): AnyTask | undefined;\n\t/** Hooks registered for tasks with `task`'s name, in registry order. */\n\thooks<K extends AnyTask>(task: K): readonly HookRegistration<K>[];\n\t/** Composed sections in registry order; a section whose wrapper failed is absent. */\n\tsections(): readonly PromptSection<Tool>[];\n\t/** Wrapper failures of this state. */\n\tfailures(): readonly RegistryFailure[];\n\t/** Conversation setups in registry order, the built-in `pi` setup first. */\n\tconversationSetups(): readonly { readonly key: string; readonly setup: ConversationSetup }[];\n}\n\n/** Read side of a registry consumed by a Harness. */\nexport interface RegistryReader<Tool extends ToolRegistration = ToolRegistration> {\n\t/** Immutable view of the whole current registry. */\n\tsnapshot(): RegistrySnapshot<Tool>;\n\t/** Called synchronously after every publication; wakes the scheduler to reconsider blocked tasks. */\n\tsubscribe(listener: () => void): () => void;\n}\n\n/** Application-owned registry of tools, hooks, tasks, and the system prompt. */\nexport interface Registry<Tool extends ToolRegistration = ToolRegistration> extends RegistryReader<Tool> {\n\treadonly tools: {\n\t\tadd(tool: Tool): Registration;\n\t\t/** `key` identifies the wrapper: it orders wrappers of one tool and keeps its position on re-registration. */\n\t\twrap(name: string, key: string, wrapper: ToolWrapper<Tool>): Registration;\n\t\t/** Composed tools of the current state. */\n\t\tlist(): readonly Tool[];\n\t};\n\treadonly hooks: {\n\t\tadd<K extends AnyTask>(\n\t\t\ttask: K,\n\t\t\thandlers: Partial<HooksOf<K>>,\n\t\t\toptions?: { readonly scope?: HookScope; readonly key?: string },\n\t\t): Registration;\n\t};\n\treadonly tasks: {\n\t\tadd(task: AnyTask): Registration;\n\t\tlist(): readonly AnyTask[];\n\t};\n\treadonly conversations: {\n\t\t/** `key` orders setups and keeps its position on re-registration. */\n\t\tsetup(key: string, setup: ConversationSetup): Registration;\n\t};\n\treadonly systemPrompt: {\n\t\tsection(key: string, render: PromptSection<Tool>[\"render\"], options?: { readonly tag?: boolean }): Registration;\n\t\twrap(key: string, wrapperKey: string, wrapper: PromptSectionWrapper<Tool>): Registration;\n\t\t/** Composed sections of the current state. */\n\t\tsections(): readonly PromptSection<Tool>[];\n\t};\n\t/** Stage registrations and disposals made synchronously by `register`, then publish them at once. Cannot nest. */\n\tbatch(register: () => void): Registration;\n}\n\n/**\n * Stages the documents every new conversation gets. Runs inside every Harness commit that creates or forks a\n * conversation, including raw `Tx` creation, after fork copies and before host `init`. Table reads throw, since the\n * conversation write came first; a fork (`conversation.parent`) already holds its copied documents. A throw fails the\n * creating commit.\n */\nexport type ConversationSetup = (\n\ttx: Tx,\n\tconversation: ConversationRecord,\n\tregistry: RegistrySnapshot,\n) => void | Promise<void>;\n\n/**\n * Runs inside the creating commit, after the conversation and its configuration exist. The conversation creation is\n * already a table write, so table reads here throw `ReadAfterWrite`; document access remains available.\n */\nexport type ConversationInit = (tx: Tx, conversationId: ConversationId) => void | Promise<void>;\n\nexport type ConversationCreateOptions = {\n\treadonly ownership: ConversationOwnership;\n\treadonly init?: ConversationInit;\n};\n\n/** Curated pi-ai request options; absent fields use pi-ai defaults. */\nexport type ConversationStreamOptions = {\n\ttransport?: Transport;\n\ttimeoutMs?: number;\n\t/** Provider/SDK retries inside one request attempt. */\n\tmaxRetries?: number;\n\tmaxRetryDelayMs?: number;\n\theaders?: Record<string, string>;\n\tmetadata?: JsonObject;\n\tcacheRetention?: CacheRetention;\n\tdeferred?: boolean | { window?: \"15m\" | \"1h\" | \"24h\" };\n};\n\n/** Durable generation attempt retries; the JSON shape of pi-ai `RetryPolicy`. */\nexport type ConversationRetryPolicy = {\n\tenabled: boolean;\n\tmaxRetries: number;\n\tbaseDelayMs: number;\n\tmaxAgentDelayMs?: number;\n};\n\n/** Automatic compaction thresholds (spec §8.7); manual compaction ignores `enabled`. */\nexport type CompactionPolicy = {\n\t/** Threshold and overflow compaction. */\n\tenabled: boolean;\n\t/** Room kept free for the answer: generation blocks to compact above `contextWindow - reserveTokens`. */\n\treserveTokens: number;\n\t/** Approximate size of the recent context a summary keeps verbatim. */\n\tkeepRecentTokens: number;\n\t/** Background compaction starts `backgroundTokens` below the blocking threshold; `0` disables it. */\n\tbackgroundTokens: number;\n};\n\n/** Why a compaction runs: `compact()`, a threshold in generation preparation, or a context overflow. */\nexport type CompactionReason = \"manual\" | \"threshold\" | \"overflow\";\n\n/**\n * `entryId` of a blocking compaction's summary, or the `submissionId` of a conversation-owned compaction's summary\n * write; both absent when nothing was compacted.\n */\nexport type CompactionResult = { entryId?: EntryId; submissionId?: SubmissionId };\n\nexport type HarnessOptions<Tool extends ToolRegistration = ToolRegistration> = {\n\t/** pi-ai model access used by generation. */\n\treadonly models: Models;\n\treadonly registry: RegistryReader<Tool>;\n\t/** Default execution environment offered to tools as `api.env`. */\n\treadonly env?: ExecutionEnv;\n\treadonly now?: () => number;\n\t/** Receives extension failures that do not fail the calling operation. Must not throw. */\n\treadonly onReport?: (error: unknown) => void;\n};\n\n/** Live task and what the scheduler would do with it under the current registry. */\nexport type TaskInspection = {\n\treadonly record: TaskRecord<JsonValue, JsonValue, JsonValue>;\n\treadonly state: /** An invocation is active. */\n\t\t| { readonly kind: \"running\" }\n\t\t/** The next scheduling pass reserves it; `migrates` when its definition is newer and has `migrate`. */\n\t\t| { readonly kind: \"ready\"; readonly migrates: boolean }\n\t\t/**\n\t\t * Waits for these live tasks: the live part of its `on`, or, when abort-marked, its live ordinary owned work, which\n\t\t * must end before its abort handler starts.\n\t\t */\n\t\t| { readonly kind: \"waiting\"; readonly on: readonly TaskId[] }\n\t\t/** Outcome held until its ordinary owned work drains. */\n\t\t| { readonly kind: \"completing\" }\n\t\t/** No registered definition can take it; aborting it settles it as `orphaned`. */\n\t\t| {\n\t\t\t\treadonly kind: \"blocked\";\n\t\t\t\treadonly reason: \"missing_task\" | \"task_too_old\" | \"migration_failed\";\n\t\t\t\treadonly error?: unknown;\n\t\t };\n};\n\n/** Point-in-time view of live work: unfinished tasks and submissions, read on the Session line. */\nexport type HarnessInspection = {\n\treadonly scheduling: \"paused\" | \"running\" | \"closing\";\n\treadonly tasks: readonly TaskInspection[];\n\t/** Queued and placed submissions, in ID order. */\n\treadonly submissions: readonly SubmissionRecord[];\n\t/** Wrapper failures of the current registry snapshot. */\n\treadonly registry: readonly RegistryFailure[];\n};\n\n/** Raw active transcript and derived model context. */\nexport type ContextView = {\n\t/** Newest applicable head marker, if any. */\n\treadonly head: EntryRecord | undefined;\n\t/** Raw active entries: the head marker followed by non-head entries from its head through the tail. */\n\treadonly entries: readonly EntryRecord[];\n\t/** Per entry of `entries`, its model messages after edits and excluded stop reasons, before tool result ordering. */\n\treadonly contributions: readonly (readonly Message[])[];\n\t/** Model context for the next provider request. */\n\treadonly messages: readonly Message[];\n};\n\n/** Stateless handle for one conversation, bound to the Harness that returned it. Compare handles by `id`. */\nexport interface Conversation {\n\treadonly id: ConversationId;\n\n\tgetModel(context: Context): Promise<ModelRef | undefined>;\n\tsetModel(model: ModelRef | undefined, context: Context): Promise<void>;\n\tgetThinkingLevel(context: Context): Promise<ModelThinkingLevel>;\n\tsetThinkingLevel(level: ModelThinkingLevel, context: Context): Promise<void>;\n\tgetActiveTools(context: Context): Promise<readonly string[]>;\n\tsetActiveTools(names: readonly string[], context: Context): Promise<void>;\n\t/** `{}` when unset. */\n\tgetStreamOptions(context: Context): Promise<ConversationStreamOptions>;\n\tsetStreamOptions(options: ConversationStreamOptions, context: Context): Promise<void>;\n\t/** The default policy when unset. */\n\tgetRetryPolicy(context: Context): Promise<ConversationRetryPolicy>;\n\t/** `undefined` removes the configured policy. */\n\tsetRetryPolicy(policy: ConversationRetryPolicy | undefined, context: Context): Promise<void>;\n\t/** `parallel` when unset. */\n\tgetToolExecution(context: Context): Promise<ToolExecutionMode>;\n\t/** `undefined` removes the configured mode. */\n\tsetToolExecution(mode: ToolExecutionMode | undefined, context: Context): Promise<void>;\n\t/** `one-at-a-time` when unset. */\n\tgetSteeringMode(context: Context): Promise<QueueMode>;\n\t/** `undefined` removes the configured mode. */\n\tsetSteeringMode(mode: QueueMode | undefined, context: Context): Promise<void>;\n\t/** `one-at-a-time` when unset. */\n\tgetFollowUpMode(context: Context): Promise<QueueMode>;\n\t/** `undefined` removes the configured mode. */\n\tsetFollowUpMode(mode: QueueMode | undefined, context: Context): Promise<void>;\n\t/** `DEFAULT_COMPACTION_POLICY` when unset. */\n\tgetCompaction(context: Context): Promise<CompactionPolicy>;\n\t/** `undefined` removes the configured policy. */\n\tsetCompaction(policy: CompactionPolicy | undefined, context: Context): Promise<void>;\n\n\t/**\n\t * Durably admit user input or a passive entry write. A busy conversation, or one with queued items, queues it in\n\t * `pi.inbox`; `whenBusy: \"reject\"` rejects with `ConversationBusy` instead and writes nothing.\n\t */\n\tsubmit(submission: SubmissionDraft, context: Context): Promise<Submission>;\n\t/**\n\t * Admit a write of a `pi.reset` entry that starts a new context, carrying `handoff` as a user message when given.\n\t * Resolves after admission; while busy, it is placed at the next boundary.\n\t */\n\treset(handoff: string | undefined, context: Context): Promise<void>;\n\t/**\n\t * Admit a manual compaction task and return its ID. It summarizes while the conversation keeps working and places its\n\t * summary through a write submission: at once when idle, otherwise at the next boundary (spec §8.7).\n\t */\n\tcompact(instructions: string | undefined, context: Context): Promise<TaskId<CompactionResult>>;\n\n\t/** Session commit whose `tx.createTask()` defaults to this conversation. */\n\tcommit<T>(change: (tx: Tx) => T | Promise<T>, context: Context): Promise<T>;\n\tcontext(context: Context): Promise<ContextView>;\n\t/** Newest-first fork-aware history of this conversation. */\n\tentries(\n\t\tquery: Omit<EntryQuery, \"conversationId\">,\n\t\tlimit: number,\n\t\tcursor: Cursor | undefined,\n\t\tcontext: Context,\n\t): Promise<Page<EntryRecord, Cursor>>;\n\tfork(at: EntryId, options: ConversationCreateOptions, context: Context): Promise<Conversation>;\n\t/**\n\t * Withdraw queued inputs (queued writes stay), mark every live non-background task of the ordinary ownership scope,\n\t * signal them, and resolve once the scope is idle. Background subtrees survive unless `background` is set.\n\t */\n\tabort(context: Context, options?: ConversationAbortOptions): Promise<void>;\n\t/**\n\t * Resolve when the ordinary ownership scope has no live non-background task: this conversation and the conversations\n\t * owned, transitively, by its non-background tasks.\n\t */\n\twaitForIdle(context: Context): Promise<void>;\n\t/** The structural view (spec §9.3) as a disposable read-only Chord state. */\n\tviewState(context: Context): Promise<AttachedReplicatedState<ConversationView>>;\n\t/** The structural view as a serialized exact-frame watch with bounded pending frames. */\n\twatch(context: Context): Promise<WatchHandle<ConversationView>>;\n}\n\n// TODO: decide how Harness exposes subscribeCommits() and subscribeClose(). Their listeners run on the Session line\n// and must not throw or call Session APIs, and Harness close will also join task invocations.\n/** Durable agent harness over one Session. */\nexport interface Harness extends Session {\n\t/**\n\t * Enable task scheduling. Idempotent; throws after close. Calls that wait for progress (`Conversation.submit()`,\n\t * `Submission.wait()`, `waitForTask()`, `waitForIdle()`) enable it too.\n\t */\n\tresume(): void;\n\n\t/** Return the reserved root conversation, creating it with `init` in one commit when absent. */\n\troot(context: Context, options?: { readonly init?: ConversationInit }): Promise<Conversation>;\n\tconversation(id: ConversationId, context: Context): Promise<Conversation | undefined>;\n\tcreateConversation(options: ConversationCreateOptions, context: Context): Promise<Conversation>;\n\n\tgetTask<R>(id: TaskId<R>, context: Context): Promise<TaskRecord<JsonValue, JsonValue, R> | undefined>;\n\t/** Live tasks, unsettled submissions, and registry failures. Writes nothing and runs no task code. */\n\tinspect(context: Context): Promise<HarnessInspection>;\n\t/** Reacquire a submission, for example after reopen. */\n\tsubmission(id: SubmissionId, context: Context): Promise<Submission | undefined>;\n\t/** `not_found` for an unknown submission or one of another conversation than `conversationId`. */\n\tabortSubmission(\n\t\tid: SubmissionId,\n\t\tcontext: Context,\n\t\tconversationId?: ConversationId,\n\t): Promise<\"aborted\" | \"already_placed\" | \"settled\" | \"not_found\">;\n\t/**\n\t * Commit the abort mark, signal and join an active run invocation, and schedule the abort invocation. A task whose\n\t * definition cannot take it settles as `orphaned` instead.\n\t */\n\tabortTask(id: TaskId, context: Context): Promise<\"marked\" | \"terminal\">;\n\t/** Resolve with the terminal receipt; cancelling `context` cancels only this wait. */\n\twaitForTask<R>(id: TaskId<R>, context: Context): Promise<SettledTask<R>>;\n\t/** Resolve when the ordinary ownership scope of every ownerless conversation has no live non-background task. */\n\twaitForIdle(context: Context): Promise<void>;\n\t/** Session total: every conversation's `pi.usage` summed. */\n\tusage(context: Context): Promise<UsageState>;\n}\n\n/** What a hook may use: committed reads and the asking task's memos, which hooks and the task share. */\nexport interface HookApi extends DocumentReader {\n\treadonly taskId: TaskId;\n\treadonly conversationId: ConversationId;\n\tmemo<T extends JsonValue>(name: string, context: Context): Promise<T | undefined>;\n\tmemo<T extends JsonValue>(name: string, candidate: T, context: Context): Promise<T>;\n}\n\nexport type HookResult<T> = T | undefined | Promise<T | undefined>;\n\n/** Hooks of the built-in generation task. */\nexport interface GenerationHooks {\n\t/** Before every request attempt, including recovery; the result is used for that request only. */\n\tbeforeRequest(\n\t\trequest: { readonly messages: readonly Message[] },\n\t\tapi: HookApi,\n\t\tcontext: Context,\n\t): HookResult<{ readonly messages: readonly Message[] }>;\n\t/** Every terminal provider message, before classification. */\n\tafterResponse(message: AssistantMessage, api: HookApi, context: Context): void | Promise<void>;\n\t/** A final answer; the first `continue` appends a user message and continues the run. */\n\tonYield(answer: AssistantMessage, api: HookApi, context: Context): HookResult<{ readonly continue: UserInput }>;\n\t/** After every tool of the round is terminal; `results` are the round's result entries in call order. */\n\tafterTools(assistant: EntryId, results: readonly EntryId[], api: HookApi, context: Context): void | Promise<void>;\n}\n\n/** Hooks of the built-in tool task. */\nexport interface ToolHooks {\n\t/** Before intent; the first `block` wins, otherwise `arguments` replace the call's arguments. A throw blocks. */\n\tbeforeTool(\n\t\tcall: ToolCall,\n\t\tapi: HookApi,\n\t\tcontext: Context,\n\t): HookResult<{ readonly arguments?: JsonObject; readonly block?: string }>;\n\t/** After execution, before the result entry; replaces the result. */\n\tafterTool(\n\t\tcall: ToolCall,\n\t\tresult: ToolExecutionResult,\n\t\tapi: HookApi,\n\t\tcontext: Context,\n\t): HookResult<ToolExecutionResult>;\n}\n\n/** Hooks of the built-in compaction task. */\nexport interface CompactionHooks {\n\t/**\n\t * After range selection, before summarizing; the first decision wins. `entries` are the active entries the summary\n\t * replaces, the head marker first, and `messages` their model context, the summarizer's source; `firstKept` is the\n\t * first entry kept verbatim.\n\t */\n\tbeforeCompact(\n\t\tcompaction: {\n\t\t\treadonly reason: CompactionReason;\n\t\t\treadonly entries: readonly EntryRecord[];\n\t\t\treadonly messages: readonly Message[];\n\t\t\treadonly firstKept: EntryId;\n\t\t\treadonly instructions?: string;\n\t\t},\n\t\tapi: HookApi,\n\t\tcontext: Context,\n\t): HookResult<{ readonly decline: true } | { readonly summary: string }>;\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import { type Draft, type JsonRepresentation } from "@earendil-works/chord";
2
+ import type { Usage } from "@earendil-works/pi-ai";
3
+ import type { ConversationId, Tx } from "../types.ts";
4
+ /** Ledger of one conversation's own spend: its entries, and compaction summarization attempts, which have none. */
5
+ export type UsageState = {
6
+ /** Assistant entries and summarization attempts, keyed `provider/modelId`. */
7
+ models: Record<string, JsonRepresentation<Usage>>;
8
+ /** Tool results, keyed by tool name; their usage has no model identity. */
9
+ tools: Record<string, JsonRepresentation<Usage>>;
10
+ };
11
+ export declare const UsageDoc: import("../types.ts").ConversationDocToken<UsageState>;
12
+ /** Add `usage` to one bucket of the conversation's `pi.usage`, in the commit that records the response. */
13
+ export declare function recordUsage(tx: Tx, conversationId: ConversationId, bucket: keyof UsageState, key: string, usage: Usage): Promise<void>;
14
+ /** Add every counter of `usage` to `total`; optional counters are added once either side reports them. */
15
+ export declare function addUsage(total: Draft<Usage> | Usage, usage: Usage): void;
16
+ /** Add every bucket of `state` into `sum`. */
17
+ export declare function addUsageState(sum: UsageState, state: Readonly<UsageState>): void;
18
+ //# sourceMappingURL=usage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/harness/usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,KAAK,EAAE,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEtD,mHAAmH;AACnH,MAAM,MAAM,UAAU,GAAG;IACxB,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;IAClD,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;CACjD,CAAC;AAEF,eAAO,MAAM,QAAQ,wDAQnB,CAAC;AAEH,2GAA2G;AAC3G,wBAAsB,WAAW,CAChC,EAAE,EAAE,EAAE,EACN,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,MAAM,UAAU,EACxB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,KAAK,GACV,OAAO,CAAC,IAAI,CAAC,CAQf;AAED,0GAA0G;AAC1G,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAaxE;AAED,8CAA8C;AAC9C,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,IAAI,CAchF"}
@@ -0,0 +1,57 @@
1
+ import { copyJson } from "@earendil-works/chord";
2
+ import { defineDoc } from "../documents.js";
3
+ export const UsageDoc = defineDoc({
4
+ kind: "pi.usage",
5
+ version: 1,
6
+ scope: "conversation",
7
+ history: "latest",
8
+ fork: "initial",
9
+ initial: () => ({ models: {}, tools: {} }),
10
+ checkpointWhen: () => true,
11
+ });
12
+ /** Add `usage` to one bucket of the conversation's `pi.usage`, in the commit that records the response. */
13
+ export async function recordUsage(tx, conversationId, bucket, key, usage) {
14
+ const totals = (await tx.doc(UsageDoc, conversationId))[bucket];
15
+ // Own keys only: a tool may be called `toString`.
16
+ const total = Object.hasOwn(totals, key) ? totals[key] : undefined;
17
+ // Providers may leave optional counters `undefined`; drafts take strict JSON.
18
+ if (total === undefined)
19
+ totals[key] = copyJson(usage, { omitUndefinedProperties: true });
20
+ else
21
+ addUsage(total, usage);
22
+ }
23
+ /** Add every counter of `usage` to `total`; optional counters are added once either side reports them. */
24
+ export function addUsage(total, usage) {
25
+ total.input += usage.input;
26
+ total.output += usage.output;
27
+ total.cacheRead += usage.cacheRead;
28
+ total.cacheWrite += usage.cacheWrite;
29
+ total.totalTokens += usage.totalTokens;
30
+ if (usage.cacheWrite1h !== undefined)
31
+ total.cacheWrite1h = (total.cacheWrite1h ?? 0) + usage.cacheWrite1h;
32
+ if (usage.reasoning !== undefined)
33
+ total.reasoning = (total.reasoning ?? 0) + usage.reasoning;
34
+ total.cost.input += usage.cost.input;
35
+ total.cost.output += usage.cost.output;
36
+ total.cost.cacheRead += usage.cost.cacheRead;
37
+ total.cost.cacheWrite += usage.cost.cacheWrite;
38
+ total.cost.total += usage.cost.total;
39
+ }
40
+ /** Add every bucket of `state` into `sum`. */
41
+ export function addUsageState(sum, state) {
42
+ for (const bucket of ["models", "tools"]) {
43
+ for (const [key, usage] of Object.entries(state[bucket])) {
44
+ const total = Object.hasOwn(sum[bucket], key) ? sum[bucket][key] : undefined;
45
+ // Define rather than assign: assigning a tool named `__proto__` would set the prototype.
46
+ if (total !== undefined)
47
+ addUsage(total, usage);
48
+ else
49
+ Object.defineProperty(sum[bucket], key, {
50
+ value: structuredClone(usage),
51
+ enumerable: true,
52
+ writable: true,
53
+ });
54
+ }
55
+ }
56
+ }
57
+ //# sourceMappingURL=usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/harness/usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAuC,MAAM,uBAAuB,CAAC;AAEtF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAW5C,MAAM,CAAC,MAAM,QAAQ,GAAG,SAAS,CAAa;IAC7C,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,cAAc;IACrB,OAAO,EAAE,QAAQ;IACjB,IAAI,EAAE,SAA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AC7B,UAAU,EAAE,IAAI;oBAChB,QAAQ,EAAE,IAAI;iBACd,CAAC,CAAC;QACL,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { copyJson, type Draft, type JsonRepresentation } from \"@earendil-works/chord\";\nimport type { Usage } from \"@earendil-works/pi-ai\";\nimport { defineDoc } from \"../documents.ts\";\nimport type { ConversationId, Tx } from \"../types.ts\";\n\n/** Ledger of one conversation's own spend: its entries, and compaction summarization attempts, which have none. */\nexport type UsageState = {\n\t/** Assistant entries and summarization attempts, keyed `provider/modelId`. */\n\tmodels: Record<string, JsonRepresentation<Usage>>;\n\t/** Tool results, keyed by tool name; their usage has no model identity. */\n\ttools: Record<string, JsonRepresentation<Usage>>;\n};\n\nexport const UsageDoc = defineDoc<UsageState>({\n\tkind: \"pi.usage\",\n\tversion: 1,\n\tscope: \"conversation\",\n\thistory: \"latest\",\n\tfork: \"initial\",\n\tinitial: () => ({ models: {}, tools: {} }),\n\tcheckpointWhen: () => true,\n});\n\n/** Add `usage` to one bucket of the conversation's `pi.usage`, in the commit that records the response. */\nexport async function recordUsage(\n\ttx: Tx,\n\tconversationId: ConversationId,\n\tbucket: keyof UsageState,\n\tkey: string,\n\tusage: Usage,\n): Promise<void> {\n\tconst totals = (await tx.doc(UsageDoc, conversationId))[bucket];\n\t// Own keys only: a tool may be called `toString`.\n\tconst total = Object.hasOwn(totals, key) ? totals[key] : undefined;\n\t// Providers may leave optional counters `undefined`; drafts take strict JSON.\n\tif (total === undefined)\n\t\ttotals[key] = copyJson(usage, { omitUndefinedProperties: true }) as JsonRepresentation<Usage>;\n\telse addUsage(total, usage);\n}\n\n/** Add every counter of `usage` to `total`; optional counters are added once either side reports them. */\nexport function addUsage(total: Draft<Usage> | Usage, usage: Usage): void {\n\ttotal.input += usage.input;\n\ttotal.output += usage.output;\n\ttotal.cacheRead += usage.cacheRead;\n\ttotal.cacheWrite += usage.cacheWrite;\n\ttotal.totalTokens += usage.totalTokens;\n\tif (usage.cacheWrite1h !== undefined) total.cacheWrite1h = (total.cacheWrite1h ?? 0) + usage.cacheWrite1h;\n\tif (usage.reasoning !== undefined) total.reasoning = (total.reasoning ?? 0) + usage.reasoning;\n\ttotal.cost.input += usage.cost.input;\n\ttotal.cost.output += usage.cost.output;\n\ttotal.cost.cacheRead += usage.cost.cacheRead;\n\ttotal.cost.cacheWrite += usage.cost.cacheWrite;\n\ttotal.cost.total += usage.cost.total;\n}\n\n/** Add every bucket of `state` into `sum`. */\nexport function addUsageState(sum: UsageState, state: Readonly<UsageState>): void {\n\tfor (const bucket of [\"models\", \"tools\"] as const) {\n\t\tfor (const [key, usage] of Object.entries(state[bucket])) {\n\t\t\tconst total = Object.hasOwn(sum[bucket], key) ? sum[bucket][key] : undefined;\n\t\t\t// Define rather than assign: assigning a tool named `__proto__` would set the prototype.\n\t\t\tif (total !== undefined) addUsage(total, usage);\n\t\t\telse\n\t\t\t\tObject.defineProperty(sum[bucket], key, {\n\t\t\t\t\tvalue: structuredClone(usage),\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\twritable: true,\n\t\t\t\t});\n\t\t}\n\t}\n}\n"]}