@earendil-works/pi-agent-core 0.85.1 → 0.86.0

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 (198) hide show
  1. package/README.md +16 -6
  2. package/dist/agent-loop.d.ts.map +1 -1
  3. package/dist/agent-loop.js +64 -22
  4. package/dist/agent-loop.js.map +1 -1
  5. package/dist/agent.d.ts +5 -3
  6. package/dist/agent.d.ts.map +1 -1
  7. package/dist/agent.js +15 -6
  8. package/dist/agent.js.map +1 -1
  9. package/dist/harness/config.d.ts +1 -1
  10. package/dist/harness/config.d.ts.map +1 -1
  11. package/dist/harness/config.js +10 -2
  12. package/dist/harness/config.js.map +1 -1
  13. package/dist/harness/env/nodejs.d.ts +2 -1
  14. package/dist/harness/env/nodejs.d.ts.map +1 -1
  15. package/dist/harness/env/nodejs.js +98 -27
  16. package/dist/harness/env/nodejs.js.map +1 -1
  17. package/dist/harness/execution/tools.d.ts +1 -1
  18. package/dist/harness/execution/tools.d.ts.map +1 -1
  19. package/dist/harness/execution/tools.js +0 -2
  20. package/dist/harness/execution/tools.js.map +1 -1
  21. package/dist/harness/messages.d.ts.map +1 -1
  22. package/dist/harness/messages.js +1 -0
  23. package/dist/harness/messages.js.map +1 -1
  24. package/dist/harness/pico3/bash.d.ts +10 -0
  25. package/dist/harness/pico3/bash.d.ts.map +1 -0
  26. package/dist/harness/pico3/bash.js +25 -0
  27. package/dist/harness/pico3/bash.js.map +1 -0
  28. package/dist/harness/pico3/bounded.d.ts +21 -0
  29. package/dist/harness/pico3/bounded.d.ts.map +1 -0
  30. package/dist/harness/pico3/bounded.js +98 -0
  31. package/dist/harness/pico3/bounded.js.map +1 -0
  32. package/dist/harness/pico3/chord.d.ts +41 -0
  33. package/dist/harness/pico3/chord.d.ts.map +1 -0
  34. package/dist/harness/pico3/chord.js +130 -0
  35. package/dist/harness/pico3/chord.js.map +1 -0
  36. package/dist/harness/pico3/context.d.ts +16 -0
  37. package/dist/harness/pico3/context.d.ts.map +1 -0
  38. package/dist/harness/pico3/context.js +88 -0
  39. package/dist/harness/pico3/context.js.map +1 -0
  40. package/dist/harness/pico3/harness.d.ts +197 -0
  41. package/dist/harness/pico3/harness.d.ts.map +1 -0
  42. package/dist/harness/pico3/harness.js +654 -0
  43. package/dist/harness/pico3/harness.js.map +1 -0
  44. package/dist/harness/pico3/hooks.d.ts +10 -0
  45. package/dist/harness/pico3/hooks.d.ts.map +1 -0
  46. package/dist/harness/pico3/hooks.js +33 -0
  47. package/dist/harness/pico3/hooks.js.map +1 -0
  48. package/dist/harness/pico3/index.d.ts +19 -0
  49. package/dist/harness/pico3/index.d.ts.map +1 -0
  50. package/dist/harness/pico3/index.js +15 -0
  51. package/dist/harness/pico3/index.js.map +1 -0
  52. package/dist/harness/pico3/jsonl.d.ts +58 -0
  53. package/dist/harness/pico3/jsonl.d.ts.map +1 -0
  54. package/dist/harness/pico3/jsonl.js +325 -0
  55. package/dist/harness/pico3/jsonl.js.map +1 -0
  56. package/dist/harness/pico3/kinds/collapse.d.ts +49 -0
  57. package/dist/harness/pico3/kinds/collapse.d.ts.map +1 -0
  58. package/dist/harness/pico3/kinds/collapse.js +191 -0
  59. package/dist/harness/pico3/kinds/collapse.js.map +1 -0
  60. package/dist/harness/pico3/kinds/entries.d.ts +78 -0
  61. package/dist/harness/pico3/kinds/entries.d.ts.map +1 -0
  62. package/dist/harness/pico3/kinds/entries.js +13 -0
  63. package/dist/harness/pico3/kinds/entries.js.map +1 -0
  64. package/dist/harness/pico3/kinds/frames.d.ts +9 -0
  65. package/dist/harness/pico3/kinds/frames.d.ts.map +1 -0
  66. package/dist/harness/pico3/kinds/frames.js +75 -0
  67. package/dist/harness/pico3/kinds/frames.js.map +1 -0
  68. package/dist/harness/pico3/kinds/generation.d.ts +94 -0
  69. package/dist/harness/pico3/kinds/generation.d.ts.map +1 -0
  70. package/dist/harness/pico3/kinds/generation.js +504 -0
  71. package/dist/harness/pico3/kinds/generation.js.map +1 -0
  72. package/dist/harness/pico3/kinds/job.d.ts +44 -0
  73. package/dist/harness/pico3/kinds/job.d.ts.map +1 -0
  74. package/dist/harness/pico3/kinds/job.js +143 -0
  75. package/dist/harness/pico3/kinds/job.js.map +1 -0
  76. package/dist/harness/pico3/kinds/plugin.d.ts +15 -0
  77. package/dist/harness/pico3/kinds/plugin.d.ts.map +1 -0
  78. package/dist/harness/pico3/kinds/plugin.js +35 -0
  79. package/dist/harness/pico3/kinds/plugin.js.map +1 -0
  80. package/dist/harness/pico3/kinds/post-tools.d.ts +22 -0
  81. package/dist/harness/pico3/kinds/post-tools.d.ts.map +1 -0
  82. package/dist/harness/pico3/kinds/post-tools.js +145 -0
  83. package/dist/harness/pico3/kinds/post-tools.js.map +1 -0
  84. package/dist/harness/pico3/kinds/task-api.d.ts +3 -0
  85. package/dist/harness/pico3/kinds/task-api.d.ts.map +1 -0
  86. package/dist/harness/pico3/kinds/task-api.js +45 -0
  87. package/dist/harness/pico3/kinds/task-api.js.map +1 -0
  88. package/dist/harness/pico3/kinds/tool.d.ts +43 -0
  89. package/dist/harness/pico3/kinds/tool.d.ts.map +1 -0
  90. package/dist/harness/pico3/kinds/tool.js +373 -0
  91. package/dist/harness/pico3/kinds/tool.js.map +1 -0
  92. package/dist/harness/pico3/membrane.d.ts +23 -0
  93. package/dist/harness/pico3/membrane.d.ts.map +1 -0
  94. package/dist/harness/pico3/membrane.js +141 -0
  95. package/dist/harness/pico3/membrane.js.map +1 -0
  96. package/dist/harness/pico3/memory.d.ts +53 -0
  97. package/dist/harness/pico3/memory.d.ts.map +1 -0
  98. package/dist/harness/pico3/memory.js +264 -0
  99. package/dist/harness/pico3/memory.js.map +1 -0
  100. package/dist/harness/pico3/scheduler.d.ts +46 -0
  101. package/dist/harness/pico3/scheduler.d.ts.map +1 -0
  102. package/dist/harness/pico3/scheduler.js +438 -0
  103. package/dist/harness/pico3/scheduler.js.map +1 -0
  104. package/dist/harness/pico3/session.d.ts +263 -0
  105. package/dist/harness/pico3/session.d.ts.map +1 -0
  106. package/dist/harness/pico3/session.js +1347 -0
  107. package/dist/harness/pico3/session.js.map +1 -0
  108. package/dist/harness/pico3/system.d.ts +126 -0
  109. package/dist/harness/pico3/system.d.ts.map +1 -0
  110. package/dist/harness/pico3/system.js +244 -0
  111. package/dist/harness/pico3/system.js.map +1 -0
  112. package/dist/harness/pico3/types.d.ts +973 -0
  113. package/dist/harness/pico3/types.d.ts.map +1 -0
  114. package/dist/harness/pico3/types.js +96 -0
  115. package/dist/harness/pico3/types.js.map +1 -0
  116. package/dist/harness/pico3/view.d.ts +34 -0
  117. package/dist/harness/pico3/view.d.ts.map +1 -0
  118. package/dist/harness/pico3/view.js +417 -0
  119. package/dist/harness/pico3/view.js.map +1 -0
  120. package/dist/harness/runtime/drive/boundary.d.ts.map +1 -1
  121. package/dist/harness/runtime/drive/boundary.js +6 -3
  122. package/dist/harness/runtime/drive/boundary.js.map +1 -1
  123. package/dist/harness/runtime/drive/response.d.ts.map +1 -1
  124. package/dist/harness/runtime/drive/response.js +4 -4
  125. package/dist/harness/runtime/drive/response.js.map +1 -1
  126. package/dist/harness/runtime/drive/retry.d.ts +2 -2
  127. package/dist/harness/runtime/drive/retry.d.ts.map +1 -1
  128. package/dist/harness/runtime/drive/retry.js +3 -6
  129. package/dist/harness/runtime/drive/retry.js.map +1 -1
  130. package/dist/harness/runtime/drive/structural.d.ts.map +1 -1
  131. package/dist/harness/runtime/drive/structural.js +5 -5
  132. package/dist/harness/runtime/drive/structural.js.map +1 -1
  133. package/dist/harness/runtime/drive/tool-placement.d.ts.map +1 -1
  134. package/dist/harness/runtime/drive/tool-placement.js +2 -27
  135. package/dist/harness/runtime/drive/tool-placement.js.map +1 -1
  136. package/dist/harness/runtime/drive/tools.d.ts.map +1 -1
  137. package/dist/harness/runtime/drive/tools.js.map +1 -1
  138. package/dist/harness/session/fork-policy.d.ts +20 -12
  139. package/dist/harness/session/fork-policy.d.ts.map +1 -1
  140. package/dist/harness/session/fork-policy.js +45 -12
  141. package/dist/harness/session/fork-policy.js.map +1 -1
  142. package/dist/harness/session/fork.d.ts +0 -2
  143. package/dist/harness/session/fork.d.ts.map +1 -1
  144. package/dist/harness/session/fork.js +20 -68
  145. package/dist/harness/session/fork.js.map +1 -1
  146. package/dist/harness/session/in-memory-storage-state.d.ts +5 -5
  147. package/dist/harness/session/in-memory-storage-state.d.ts.map +1 -1
  148. package/dist/harness/session/in-memory-storage-state.js +99 -39
  149. package/dist/harness/session/in-memory-storage-state.js.map +1 -1
  150. package/dist/harness/session/index.d.ts +1 -1
  151. package/dist/harness/session/index.d.ts.map +1 -1
  152. package/dist/harness/session/index.js +1 -1
  153. package/dist/harness/session/index.js.map +1 -1
  154. package/dist/harness/session/jsonl/fork.d.ts +38 -0
  155. package/dist/harness/session/jsonl/fork.d.ts.map +1 -0
  156. package/dist/harness/session/jsonl/fork.js +264 -0
  157. package/dist/harness/session/jsonl/fork.js.map +1 -0
  158. package/dist/harness/session/jsonl/io.d.ts +14 -0
  159. package/dist/harness/session/jsonl/io.d.ts.map +1 -0
  160. package/dist/harness/session/jsonl/io.js +86 -0
  161. package/dist/harness/session/jsonl/io.js.map +1 -0
  162. package/dist/harness/session/jsonl/legacy-v3.d.ts +33 -8
  163. package/dist/harness/session/jsonl/legacy-v3.d.ts.map +1 -1
  164. package/dist/harness/session/jsonl/legacy-v3.js +285 -206
  165. package/dist/harness/session/jsonl/legacy-v3.js.map +1 -1
  166. package/dist/harness/session/jsonl/repo.d.ts +2 -1
  167. package/dist/harness/session/jsonl/repo.d.ts.map +1 -1
  168. package/dist/harness/session/jsonl/repo.js +36 -20
  169. package/dist/harness/session/jsonl/repo.js.map +1 -1
  170. package/dist/harness/session/jsonl/storage.d.ts +4 -5
  171. package/dist/harness/session/jsonl/storage.d.ts.map +1 -1
  172. package/dist/harness/session/jsonl/storage.js +39 -113
  173. package/dist/harness/session/jsonl/storage.js.map +1 -1
  174. package/dist/harness/session/memory.d.ts +3 -5
  175. package/dist/harness/session/memory.d.ts.map +1 -1
  176. package/dist/harness/session/memory.js +9 -14
  177. package/dist/harness/session/memory.js.map +1 -1
  178. package/dist/harness/session/testing/conformance/session-repo.d.ts +2 -0
  179. package/dist/harness/session/testing/conformance/session-repo.d.ts.map +1 -1
  180. package/dist/harness/session/testing/conformance/session-repo.js +220 -1
  181. package/dist/harness/session/testing/conformance/session-repo.js.map +1 -1
  182. package/dist/harness/session/testing/index.d.ts +1 -1
  183. package/dist/harness/session/testing/index.d.ts.map +1 -1
  184. package/dist/harness/session/testing/index.js +1 -1
  185. package/dist/harness/session/testing/index.js.map +1 -1
  186. package/dist/harness/session/types.d.ts +1 -0
  187. package/dist/harness/session/types.d.ts.map +1 -1
  188. package/dist/harness/session/types.js.map +1 -1
  189. package/dist/harness/types.d.ts +14 -0
  190. package/dist/harness/types.d.ts.map +1 -1
  191. package/dist/harness/types.js.map +1 -1
  192. package/dist/proxy.d.ts +2 -2
  193. package/dist/proxy.d.ts.map +1 -1
  194. package/dist/proxy.js.map +1 -1
  195. package/dist/types.d.ts +30 -14
  196. package/dist/types.d.ts.map +1 -1
  197. package/dist/types.js.map +1 -1
  198. package/package.json +10 -6
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/harness/pico3/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,SAAS,IAAI,cAAc,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACtG,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,KAAK,EACX,GAAG,EACH,gBAAgB,EAChB,qBAAqB,EACrB,cAAc,EACd,YAAY,EACZ,OAAO,IAAI,YAAY,EACvB,KAAK,IAAI,OAAO,EAChB,WAAW,EACX,QAAQ,EACR,iBAAiB,EACjB,WAAW,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAA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AAC,EAAE,EAAE,EAAE,CAAC;IAChB,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC;CAC9B,CAAC;AAML,qBAAa,SAAU,SAAQ,KAAK;IACnC,YAAY,IAAI,EAAE,MAAM,EAGvB;CACD;AACD,qBAAa,gBAAiB,SAAQ,KAAK;IAC1C,YAAY,EAAE,EAAE,EAAE,EAGjB;CACD;AACD,qBAAa,oBAAqB,SAAQ,KAAK;IAC9C,YAAY,EAAE,EAAE,EAAE,EAGjB;CACD;AACD,qBAAa,kBAAmB,SAAQ,KAAK;IAC5C,YAAY,EAAE,EAAE,EAAE,EAGjB;CACD;AACD,qBAAa,OAAQ,SAAQ,KAAK;IACjC,YAAY,KAAK,EAAE,OAAO,EAGzB;CACD;AACD,qBAAa,MAAO,SAAQ,KAAK;IAChC,cAGC;CACD;AACD,qBAAa,iBAAkB,SAAQ,KAAK;IAC3C,YAAY,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAGrC;CACD;AAED,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AAC1G,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC","sourcesContent":["/**\n * harness-v3 — records, documents, storage, kinds, transactions, runtime, tools, hooks.\n *\n * Durable model: four tables (conversations, entries, tasks, inputs) and three documents\n * (session, per-conversation rewindable, per-conversation sticky). Every durable position\n * is strict JSON (`JsonValue`); nothing durable is `unknown`.\n *\n * Single process. A storage path has one owning process and one owning Session at a time.\n * Two processes opening the same JSONL directory is unsupported.\n */\nimport type { JsonValue as ChordJsonValue, Context, JsonRepresentation } from \"@earendil-works/chord\";\nimport type { Op } from \"@earendil-works/chord/delta\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tAssistantMessageEvent,\n\tDeferredHandle,\n\tImageContent,\n\tMessage as ModelMessage,\n\tModel as ModelOf,\n\tTextContent,\n\tToolCall,\n\tToolResultMessage,\n\tUserMessage,\n} from \"@earendil-works/pi-ai\";\nimport type { Static, TSchema } from \"typebox\";\nimport type { ThinkingLevel } from \"../../types.ts\";\nimport type { SectionRegistry, SectionSeed, ToolRegistry } from \"./system.ts\";\n\n// ---------------------------------------------------------------------------\n// Strict durable JSON\n// ---------------------------------------------------------------------------\n\nexport type JsonPrimitive = string | number | boolean | null;\nexport type JsonValue = ChordJsonValue;\n/** Optional properties represent absent keys; committed values are normalized through JSON serialization. */\nexport type JsonObject = { [key: string]: JsonValue };\n\n/** Coerce an in-memory value (e.g. a pi-ai message) to its stored representation. */\nexport const toStored = <T>(value: T): Stored<T> => JSON.parse(JSON.stringify(value)) as Stored<T>;\n\n/**\n * The JSON representation of a value: what survives `JSON.parse(JSON.stringify(v))`.\n * Optional keys stay optional; `undefined` values vanish; functions are never durable.\n * Use for imported pi-ai types at durable positions.\n */\nexport type Stored<T> = JsonRepresentation<T>;\n\nexport type Id = number;\nexport type Seq = number;\n\n/** Compile-time assertion helper. */\nexport type Assert<T extends true> = T;\n/** True iff T is strict JSON (structurally). */\nexport type IsJson<T> = [T] extends [JsonValue] ? true : false;\n\n// ---------------------------------------------------------------------------\n// Records\n// ---------------------------------------------------------------------------\n\nexport interface Conversation {\n\treadonly id: Id;\n\treadonly parent?: { readonly conversationId: Id; readonly at: Id };\n\treadonly owner?: Id; // task that created it\n\t/** §8.1 section seed: applied by preparation while the conversation has no local managed entry. Private: not in ConversationView. */\n\treadonly sections?: readonly SectionSeed[];\n}\n\n/**\n * System instructions and the tool loadout ride inside `messages` (pi-ai PR #9116, shimmed\n * here until it lands): a SystemMessage at its historical position.\n */\nexport interface SystemMessage {\n\trole: \"system\";\n\tcontent: string;\n\ttoolsAdded?: { name: string; description: string; parameters: TSchema }[];\n\ttoolsRemoved?: { name: string }[];\n\ttimestamp: number;\n}\nexport type Message = ModelMessage | SystemMessage;\nexport type StoredMessage = Stored<Message>;\nexport type Model = ModelOf<Api>;\n\nexport interface ContextEdit {\n\treadonly target: Id;\n\treadonly action: \"omit\" | \"replace\";\n\treadonly messages?: readonly StoredMessage[];\n}\n\nexport interface Entry {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\treadonly kind: string;\n\treadonly model?: readonly StoredMessage[]; // what the model sees; absent = display/bookkeeping only\n\treadonly data?: JsonObject;\n\treadonly head?: Id; // context starts here (may be a parent's entry). Assigned by the kernel; `self` in NewEntry\n\treadonly edits?: readonly ContextEdit[];\n\treadonly byTaskId?: Id;\n}\nexport type NewEntry = Omit<Entry, \"id\" | \"conversationId\" | \"byTaskId\" | \"head\"> & { readonly head?: Id | \"self\" };\n\n/** A typed witness for an entry kind: `is()` narrows, and typed writes take `EntryInput<E>`. */\nexport interface EntryKind<E extends Entry = Entry> {\n\treadonly kind: string;\n\tis(entry: Entry | undefined): entry is E;\n}\nexport type EntryInput<E extends Entry> = Omit<E, \"id\" | \"conversationId\" | \"kind\" | \"byTaskId\" | \"head\"> &\n\t(E extends { readonly head: Id } ? { readonly head: Id | \"self\" } : { readonly head?: never });\nexport function defineEntry<E extends Entry>(kind: string): EntryKind<E> {\n\tif (kind.startsWith(\"pi.\")) throw new Error(`entry kind names beginning with \"pi.\" are reserved: ${kind}`);\n\treturn Object.freeze({ kind, is: (entry: Entry | undefined): entry is E => entry?.kind === kind });\n}\n\nexport type Checkpoint = JsonObject & { readonly phase: string };\n\nexport type Completion<R extends JsonValue = JsonValue, F extends JsonValue = JsonValue> =\n\t| { readonly status: \"completed\"; readonly result: R }\n\t| { readonly status: \"failed\"; readonly failure: F };\nexport type Outcome<R extends JsonValue = JsonValue, F extends JsonValue = JsonValue, A extends JsonValue = JsonValue> =\n\t| Completion<R, F>\n\t| { readonly status: \"aborted\"; readonly result: A }\n\t| { readonly status: \"orphaned\" }\n\t/** The kind broke its contract (a handler threw or returned an invalid shape). Not one of its declared failures. */\n\t| { readonly status: \"faulted\"; readonly error: string };\n\nexport interface Task<I extends JsonValue = JsonValue, C extends Checkpoint = Checkpoint> {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\treadonly kind: string;\n\treadonly input: I;\n\treadonly status: \"pending\" | \"running\" | \"terminal\";\n\treadonly checkpoint?: C;\n\treadonly abort?: true; // the durable mark\n\treadonly outcome?: Outcome;\n\treadonly after: readonly Id[];\n\treadonly owns: readonly Id[]; // conversations this task created\n\treadonly background?: true; // does not hold the conversation busy; survives conversation abort\n}\nexport type TaskPatch = { readonly id: Id } & Partial<\n\tOmit<Pick<Task, \"status\" | \"checkpoint\" | \"abort\" | \"outcome\" | \"owns\">, \"checkpoint\">\n> & { checkpoint?: Checkpoint | null };\n\nexport interface Input {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\treadonly requestId?: string;\n\treadonly status: \"queued\" | \"placed\" | \"done\" | \"unanswered\";\n\treadonly entry?: Id;\n\treadonly answer?: Id;\n\treadonly reason?: \"aborted\" | \"stale\" | \"terminated\" | \"failed\";\n\treadonly detail?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Documents (Chord-tracked). Mutated in place inside a commit, diffed at the end.\n// ---------------------------------------------------------------------------\n\nexport type ModelRef = { provider: string; modelId: string };\nexport type RetryPolicy = { enabled: boolean; maxRetries: number; baseDelayMs: number; maxAgentDelayMs?: number };\n\n/** One running tool call, at the index of its call in the assistant message. */\nexport type ToolSlot = {\n\tcallId: string;\n\tname: string;\n\targs: JsonValue;\n\tstatus: \"pending\" | \"running\" | \"done\" | \"error\" | \"aborted\";\n\twaitingOn?: string;\n\toutput?: string; // bounded stream as it stands\n\tprogress?: string;\n\tdetails?: JsonValue;\n\tcontinuedBy?: Id; // a background task that took the work over; its live state is `tasks[continuedBy]`\n\tentry?: Id;\n\t/** Private task-lifetime coordination state. Never projected into ConversationView. */\n\tmemos?: { [key: string]: JsonValue };\n};\n/** The current turn, shaped for rendering. Reset when a generation starts; cleared when the turn ends. */\nexport type TurnState = {\n\tmessage?: Stored<AssistantMessage>; // streaming assistant message\n\ttools: ToolSlot[]; // tools of the assistant message being executed, by call index\n};\n\n/** Private durable namespace slices stored in authoritative documents. */\nexport type PluginSlices = { [namespace: string]: JsonObject };\n\n/** Rewound by forks: forks see the state as of their fork point. Core config fields come from the built-in kinds' declarations. */\nexport type RewindableState = {\n\tmodel?: ModelRef;\n\tthinkingLevel: ThinkingLevel;\n\tselectedTools: string[];\n\tprofile: string;\n\tthreshold: number;\n\tkeepRecent: number;\n\tplugins: PluginSlices;\n\t[key: string]: JsonValue | undefined; // ordinary kinds' declared config, keyed by their disjoint names\n};\n/** The present. Never folded historically; truncated to its last base. */\nexport type StickyState = {\n\tretry: RetryPolicy;\n\tsteeringMode: \"all\" | \"one-at-a-time\";\n\tfollowUpMode: \"all\" | \"one-at-a-time\";\n\tinbox: QueuedInput[];\n\tturn: TurnState;\n\ttasks: { [taskId: string]: JsonObject }; // non-turn tasks' live slots; retired by the kernel on terminal\n\tplugins: PluginSlices;\n\t[key: string]: JsonValue | undefined;\n};\nexport type SessionState = { plugins: PluginSlices; [key: string]: JsonValue | undefined };\n\nexport type QueuedInput =\n\t| { id: Id; mode: \"steer\" | \"followUp\"; input: Stored<UserInput> }\n\t| { id: Id; mode: \"write\"; entry: Stored<NewEntry> };\n\nexport type DocRef =\n\t| { doc: \"session\" }\n\t| { doc: \"rewindable\"; conversationId: Id }\n\t| { doc: \"sticky\"; conversationId: Id };\n\nexport type NamespaceDefaults<T extends JsonObject> = {\n\treadonly rewindable?: Partial<T>;\n\treadonly sticky?: Partial<T>;\n\treadonly session?: Partial<T>;\n};\n\n/** Current process authority for one durable namespace string. */\nexport interface Namespace<T extends JsonObject = JsonObject> {\n\treadonly id: string;\n\t/** Type-only invariant marker. */\n\treadonly valueType?: (value: T) => T;\n\tunregister(): void;\n}\n\n/** Internal erased registration paired with the public namespace token. */\nexport interface NamespaceRegistration {\n\treadonly token: object;\n\treadonly defaults: { readonly rewindable: JsonObject; readonly sticky: JsonObject; readonly session: JsonObject };\n\treadonly routes: ReadonlyMap<string, DocRef[\"doc\"]>;\n\treadonly project?: (slice: Readonly<JsonObject>) => JsonValue;\n}\n\n/** First writer wins, including when the stored winner is null. */\nexport function memoOnce<T extends JsonValue>(slot: JsonObject, key: string, candidate: T): T {\n\tif (!Object.hasOwn(slot, \"memos\")) slot.memos = {};\n\tconst memos = slot.memos as { [key: string]: JsonValue };\n\tif (Object.hasOwn(memos, key)) return memos[key] as T;\n\tmemos[key] = candidate;\n\treturn candidate;\n}\n\n// ---------------------------------------------------------------------------\n// Configuration facade: every registered kind's `config` merged flat.\n// ---------------------------------------------------------------------------\n\ntype UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends (x: infer I) => void ? I : never;\n/** A declared slice; the undeclared `ConfigShape` (index signature) counts as no keys. */\ntype Declared<S> = string extends keyof S ? object : S;\ntype RewindableOf<K> = K extends unknown\n\t? ConfigOf<K> extends { readonly rewindable: infer RC }\n\t\t? Declared<RC>\n\t\t: object\n\t: never;\ntype StickyOf<K> = K extends unknown\n\t? ConfigOf<K> extends { readonly sticky: infer SC }\n\t\t? Declared<SC>\n\t\t: object\n\t: never;\nexport type ConfigOfKinds<Ks extends readonly AnyKind[]> = UnionToIntersection<\n\tRewindableOf<Ks[number]> | StickyOf<Ks[number]>\n> extends infer M\n\t? { [K in keyof M]: M[K] }\n\t: never;\ntype KeysOfKind<K> = (keyof RewindableOf<K> | keyof StickyOf<K>) & string;\ntype IsUnion<U, C = U> = U extends unknown ? ([C] extends [U] ? false : true) : never;\n/** The kinds declaring `Key`. */\ntype Owners<Ks extends readonly AnyKind[], Key extends string> = {\n\t[I in keyof Ks]: Key extends KeysOfKind<Ks[I]> ? Ks[I] : never;\n}[number];\ntype AllKeys<Ks extends readonly AnyKind[]> = { [I in keyof Ks]: KeysOfKind<Ks[I]> }[number];\ntype ClashingKeys<Ks extends readonly AnyKind[]> = {\n\t[Key in AllKeys<Ks>]: true extends IsUnion<Owners<Ks, Key>> ? Key : never;\n}[AllKeys<Ks>];\n/** `true` iff no two kinds declare the same config key. Asserted at open at compile time and at runtime. */\nexport type DisjointConfig<Ks extends readonly AnyKind[]> = [ClashingKeys<Ks>] extends [never] ? true : false;\n\nexport interface ConfigFacade<Cfg extends object> {\n\tget(ctx: Context): Promise<Readonly<Cfg>>;\n\t/** One commit, routed to the declaring documents. */\n\tset(patch: { [K in keyof Cfg]?: Cfg[K] }, ctx: Context): Promise<void>;\n\t/** Delete persisted overrides. Declared defaults become visible; `model` becomes absent. */\n\treset(keys: readonly (keyof Cfg)[], ctx: Context): Promise<void>;\n}\n\n// ---------------------------------------------------------------------------\n// Storage: six write types, a handful of reads. One owning Session per instance.\n// ---------------------------------------------------------------------------\n\nexport type Write =\n\t| { type: \"conversation\"; conversation: Conversation }\n\t| { type: \"entry\"; entry: Entry }\n\t| { type: \"task\"; task: Task } // create\n\t| { type: \"task.patch\"; patch: TaskPatch } // `checkpoint: null` clears\n\t| { type: \"input\"; input: Input } // create or replace whole\n\t| { type: \"doc\"; ref: DocRef; ops: Op[] };\n\nexport interface EntryScan {\n\tconversationId: Id;\n\tkind?: string;\n\twithHead?: boolean;\n\tbefore?: Id; // strictly less\n\tlimit: number;\n}\nexport interface TaskScan {\n\tconversationId?: Id;\n\tstatus?: Task[\"status\"][];\n\tkind?: string;\n}\n\nexport interface Storage {\n\t/** Persist one batch atomically: all or nothing. Returns the commit sequence. */\n\tcommit(writes: readonly Write[], ctx: Context): Promise<Seq>;\n\tmintId(): Id;\n\tconversation(id: Id, ctx: Context): Promise<Conversation | undefined>;\n\tconversations(ctx: Context): Promise<Conversation[]>;\n\tentries(ids: readonly Id[], ctx: Context): Promise<Map<Id, Entry>>;\n\t/** Newest-first, fork-aware: this conversation's entries, then the parent's up to the fork point, and so on. */\n\tscanEntries(scan: EntryScan, ctx: Context): Promise<Entry[]>;\n\ttask(id: Id, ctx: Context): Promise<Task | undefined>;\n\tscanTasks(scan: TaskScan, ctx: Context): Promise<Task[]>;\n\tinput(id: Id, ctx: Context): Promise<Input | undefined>;\n\tinputByRequest(conversationId: Id, requestId: string, ctx: Context): Promise<Input | undefined>;\n\tdoc(ref: DocRef, ctx: Context): Promise<JsonObject | undefined>;\n\t/** Rewindable doc as of the atomic commit containing entry `at` (fork inheritance). See \"commit-granular history\". */\n\tdocAsOf(conversationId: Id, at: Id, ctx: Context): Promise<JsonObject | undefined>;\n\t/** Rewrite a doc log from its last base. */\n\ttruncate(ref: DocRef, ctx: Context): Promise<void>;\n\tclose(ctx: Context): Promise<void>;\n}\n\n// ---------------------------------------------------------------------------\n// Kinds\n// ---------------------------------------------------------------------------\n\n/** A hook may synchronously or asynchronously omit its replacement value. */\n// biome-ignore lint/suspicious/noConfusingVoidType: void is the intentional callback no-value result\nexport type HookResult<T> = T | void | Promise<T | void>;\n\nexport interface HookApi {\n\treadonly kind: string;\n\treadonly taskId: Id;\n\treadonly conversationId: Id;\n}\n/** Kept as the concise name used by existing kind hook declarations. */\nexport type HookInfo = HookApi;\nexport interface HookBinding<H extends object> {\n\treadonly handlers: Partial<H>;\n\treadonly namespace: Namespace;\n\treadonly api: HookApi;\n}\nexport interface HookRunner<H extends object> {\n\thandlers(): readonly HookBinding<H>[];\n\t/** Call `fn` on each handler; `onValue` sees non-undefined results and may return true to stop. A throwing handler is reported and skipped. */\n\teach<V>(\n\t\tctx: Context,\n\t\tfn: (handlers: Partial<H>, api: HookApi) => HookResult<V>,\n\t\tonValue?: (v: V) => unknown,\n\t): Promise<void>;\n}\n\n/** What a phase handler returns: advance to a checkpoint, or finish. A builder runs on the line and may terminalize or ask to retry. */\nexport type Step<C extends Checkpoint, R extends JsonValue, F extends JsonValue, Tx extends TaskTx = TaskTx> =\n\t| {\n\t\t\treadonly next:\n\t\t\t\t| C\n\t\t\t\t| ((\n\t\t\t\t\t\ttx: Tx,\n\t\t\t\t\t\tcurrent: Task,\n\t\t\t\t\t\tctx: Context,\n\t\t\t\t ) => C | Completion<R, F> | \"retry\" | Promise<C | Completion<R, F> | \"retry\">);\n\t }\n\t| { readonly done: Closure<R, F, Tx> };\nexport type Closure<R extends JsonValue, F extends JsonValue, Tx extends TaskTx = TaskTx> = (\n\ttx: Tx,\n\tcurrent: Task,\n\tctx: Context,\n) => Completion<R, F> | Promise<Completion<R, F>>;\nexport type AbortClosure<A extends JsonValue, Tx extends TaskTx = TaskTx> = (\n\ttx: Tx,\n\tcurrent: Task,\n\tctx: Context,\n) => A | Promise<A>;\n\nexport type CheckpointAt<C extends Checkpoint, P extends C[\"phase\"]> = Extract<C, { readonly phase: P }>;\nexport type PhaseHandler<\n\tI extends JsonValue,\n\tC extends Checkpoint,\n\tP extends C[\"phase\"],\n\tR extends JsonValue,\n\tF extends JsonValue,\n\tH extends object,\n\tTx extends TaskTx = TaskTx,\n> = (\n\ttask: Task<I, CheckpointAt<C, P>> & { readonly checkpoint: CheckpointAt<C, P> },\n\trt: Runtime<H, Tx>,\n\tctx: Context,\n) => Promise<Step<C, R, F, Tx>>;\n\n/** A config slice: JSON values; a key whose default is `undefined` is optional (only `model` among the built-ins). */\nexport type ConfigShape = { [key: string]: JsonValue | undefined };\n/** Per-kind configuration: defaults, split by document. Keys across all kinds must be disjoint. */\nexport interface KindConfig<RC extends ConfigShape = ConfigShape, SC extends ConfigShape = ConfigShape> {\n\treadonly rewindable?: RC;\n\treadonly sticky?: SC;\n}\n\n/** Phantom carrier so `TaskOf<K>` etc. can read a kind's types back out. Never set at runtime. */\nexport interface KindTypes<\n\tI extends JsonValue,\n\tC extends Checkpoint,\n\tR extends JsonValue,\n\tF extends JsonValue,\n\tA extends JsonValue,\n\tH extends object,\n\tCfg extends KindConfig,\n\tS extends JsonObject,\n> {\n\tinput: I;\n\tcheckpoint: C;\n\tresult: R;\n\tfailure: F;\n\taborted: A;\n\thooks: H;\n\tconfig: Cfg;\n\tslot: S;\n}\n\n/**\n * A task kind. `initial` runs when there is no checkpoint; `phases` is exhaustive over\n * `C[\"phase\"]`. Phases named in `inflight` are written by a handler immediately before an\n * external effect and are entered by the scheduler only after reopen; a `next` transition\n * into one is rejected as a contract fault.\n */\nexport interface Kind<\n\tI extends JsonValue = JsonValue,\n\tC extends Checkpoint = Checkpoint,\n\tR extends JsonValue = JsonValue,\n\tF extends JsonValue = JsonValue,\n\tA extends JsonValue = JsonValue,\n\tH extends object = object,\n\tCfg extends KindConfig = KindConfig,\n\tS extends JsonObject = JsonObject,\n\tTx extends TaskTx = TaskTx,\n> {\n\treadonly types?: KindTypes<I, C, R, F, A, H, Cfg, S>;\n\treadonly name: string;\n\t/** A turn kind makes the conversation busy for admission. */\n\treadonly turn?: boolean;\n\treadonly config?: Cfg;\n\t/** Live slot (`sticky.tasks[id]`) initializer. */\n\treadonly slot?: (input: I) => S;\n\t/** Rendering projection for a non-turn task. Raw checkpoints and slots are never published. */\n\treadonly describe?: (task: Task<I, C> & { readonly slot?: Readonly<S> }) => JsonValue;\n\treadonly inflight?: readonly C[\"phase\"][];\n\tinitial(\n\t\ttask: Task<I, never> & { readonly checkpoint?: undefined },\n\t\trt: Runtime<H, Tx>,\n\t\tctx: Context,\n\t): Promise<Step<C, R, F, Tx>>;\n\treadonly phases: { readonly [P in C[\"phase\"]]: PhaseHandler<I, C, P, R, F, H, Tx> };\n\tabort(task: Task<I, C>, rt: Runtime<H, Tx>, ctx: Context): Promise<AbortClosure<A, Tx>>;\n}\n\n/** Internal kind type for fixed core machinery. */\nexport type CoreKind<\n\tI extends JsonValue,\n\tC extends Checkpoint,\n\tR extends JsonValue,\n\tF extends JsonValue,\n\tA extends JsonValue,\n\tH extends object = object,\n\tCfg extends KindConfig = KindConfig,\n\tS extends JsonObject = JsonObject,\n> = Kind<I, C, R, F, A, H, Cfg, S, CoreTx>;\n\n/** Author an ordinary kind. Names may not begin with `pi.`. */\nexport function defineTask<\n\tI extends JsonValue,\n\tC extends Checkpoint,\n\tR extends JsonValue,\n\tF extends JsonValue,\n\tA extends JsonValue,\n\tH extends object = object,\n\tCfg extends KindConfig = KindConfig,\n\tS extends JsonObject = JsonObject,\n>(definition: Kind<I, C, R, F, A, H, Cfg, S>): Kind<I, C, R, F, A, H, Cfg, S> {\n\tif (definition.name.startsWith(\"pi.\"))\n\t\tthrow new Error(`task kind names beginning with \"pi.\" are reserved: ${definition.name}`);\n\treturn Object.freeze({ ...definition });\n}\n\n/**\n * The erased kind the kernel stores. Handlers are invoked through `KindAdapter`, the one\n * place a concrete `Kind<…>` is narrowed to this and its outputs are validated.\n */\nexport interface AnyKind {\n\treadonly types?: unknown;\n\treadonly name: string;\n\treadonly turn?: boolean;\n\treadonly config?: KindConfig;\n\treadonly slot?: (input: never) => JsonObject;\n\treadonly describe?: unknown;\n\treadonly inflight?: readonly string[];\n\treadonly initial: unknown;\n\treadonly phases: { readonly [phase: string]: unknown };\n\treadonly abort: unknown;\n}\n\nexport interface TaskRef<K extends AnyKind = AnyKind> {\n\treadonly id: Id;\n\treadonly kind: K;\n}\nexport interface EntryRef<E extends Entry = Entry> {\n\treadonly id: Id;\n\treadonly kind: EntryKind<E>;\n}\n\ntype TypesOf<K> = K extends { types?: infer T } ? NonNullable<T> : never;\nexport type TaskOf<K> = TypesOf<K> extends KindTypes<\n\tinfer I,\n\tinfer C,\n\tinfer R,\n\tinfer F,\n\tinfer A,\n\tobject,\n\tKindConfig,\n\tJsonObject\n>\n\t? Omit<Task<I, C>, \"outcome\"> & { readonly outcome?: Outcome<R, F, A> }\n\t: never;\nexport type InputOf<K> = TypesOf<K> extends KindTypes<\n\tinfer I,\n\tCheckpoint,\n\tJsonValue,\n\tJsonValue,\n\tJsonValue,\n\tobject,\n\tKindConfig,\n\tJsonObject\n>\n\t? I\n\t: never;\nexport type HooksOf<K> = TypesOf<K> extends KindTypes<\n\tJsonValue,\n\tCheckpoint,\n\tJsonValue,\n\tJsonValue,\n\tJsonValue,\n\tinfer H,\n\tKindConfig,\n\tJsonObject\n>\n\t? H\n\t: never;\nexport type ConfigOf<K> = TypesOf<K> extends KindTypes<\n\tJsonValue,\n\tCheckpoint,\n\tJsonValue,\n\tJsonValue,\n\tJsonValue,\n\tobject,\n\tinfer Cfg,\n\tJsonObject\n>\n\t? Cfg\n\t: never;\nexport type SlotOf<K> = TypesOf<K> extends KindTypes<\n\tJsonValue,\n\tCheckpoint,\n\tJsonValue,\n\tJsonValue,\n\tJsonValue,\n\tobject,\n\tKindConfig,\n\tinfer S\n>\n\t? S\n\t: never;\n\nexport type TaskSpec = {\n\tkind: string;\n\tconversationId?: Id;\n\tinput: JsonValue;\n\tafter?: Id[];\n\tbackground?: true;\n};\n\n// ---------------------------------------------------------------------------\n// Transactions. One implementation; three views.\n// ---------------------------------------------------------------------------\n\nexport interface ConversationSpec {\n\tparent?: { conversationId: Id; at: Id | \"start\" };\n\trewindable?: Partial<RewindableState>;\n\tsticky?: Partial<StickyState>;\n\tsections?: readonly SectionSeed[];\n}\nexport interface OwnedConversationSpec {\n\tinherit?: boolean;\n\trewindable?: Partial<RewindableState>;\n\tsticky?: Partial<StickyState>;\n}\nexport type UserInput = string | UserMessage[\"content\"];\nexport interface SendInput {\n\tcontent: UserInput;\n\trequestId?: string;\n\twhenBusy?: \"steer\" | \"followUp\" | \"reject\";\n}\nexport type ContextView = { head: Entry | undefined; entries: Entry[]; messages: StoredMessage[] };\n\nexport type GenerationStatus =\n\t| { stage: \"waiting\"; on: \"compaction\" }\n\t| { stage: \"preparing\" }\n\t| { stage: \"requesting\"; attempt: number }\n\t| { stage: \"streaming\"; attempt: number }\n\t| { stage: \"retrying\"; attempt: number; retryAt: number; lastError: string }\n\t| { stage: \"deferred\"; attempt: number; pollAt: number };\n\nexport interface TurnView {\n\tinputs: Id[];\n\tgeneration?: GenerationStatus;\n\tmessage?: Stored<AssistantMessage>;\n\ttools: Omit<ToolSlot, \"memos\">[];\n}\n\nexport interface ConversationView {\n\tconversation: Omit<Conversation, \"sections\">;\n\tentries: Entry[];\n\tconfig: { [key: string]: JsonValue | undefined };\n\tinbox: QueuedInput[];\n\tturn?: TurnView;\n\tcompaction?: {\n\t\ttaskId: Id;\n\t\treason: \"threshold\" | \"manual\" | \"overflow\";\n\t\tstage: \"summarizing\" | \"retrying\";\n\t\tattempt: number;\n\t\tretryAt?: number;\n\t};\n\ttasks: { [taskId: string]: { kind: string; background?: true; marked?: true; status: JsonValue } };\n\tplugins: { [namespace: string]: JsonValue };\n}\n\nexport type ViewEvent =\n\t| { type: \"entry.added\"; entry: Entry }\n\t| { type: \"head.moved\"; entry: Entry }\n\t| { type: \"turn.started\"; inputs: Id[] }\n\t| { type: \"turn.ended\"; inputs: Id[]; status: \"done\"; answer: Id }\n\t| {\n\t\t\ttype: \"turn.ended\";\n\t\t\tinputs: Id[];\n\t\t\tstatus: \"unanswered\";\n\t\t\treason: \"terminated\" | \"aborted\" | \"failed\" | \"stale\";\n\t\t\tdetail?: string;\n\t }\n\t| { type: \"input.queued\"; input: Id; mode: \"steer\" | \"followUp\" | \"write\" }\n\t| { type: \"input.placed\"; input: Id; entry: Id }\n\t| { type: \"input.aborted\"; input: Id }\n\t| { type: \"generation.started\"; taskId: Id; attempt: number }\n\t| { type: \"generation.retrying\"; taskId: Id; attempt: number; retryAt: number; error: string }\n\t| { type: \"generation.deferred\"; taskId: Id; pollAt: number }\n\t| { type: \"generation.completed\"; taskId: Id; entry: Id; toolCalls: number }\n\t| {\n\t\t\ttype: \"generation.failed\";\n\t\t\ttaskId: Id;\n\t\t\treason: \"provider\" | \"overflow\" | \"retries_exhausted\" | \"no_model\";\n\t\t\tdetail: string;\n\t\t\tentry?: Id;\n\t }\n\t| { type: \"tool.waiting\"; taskId: Id; callId: string; on: string }\n\t| { type: \"tool.started\"; taskId: Id; callId: string; name: string }\n\t| { type: \"tool.finished\"; taskId: Id; callId: string; entry: Id; isError: boolean; control?: ToolControl }\n\t| { type: \"tool.aborted\"; taskId: Id; callId: string; entry: Id }\n\t| { type: \"compaction.started\"; taskId: Id; reason: \"threshold\" | \"manual\" | \"overflow\"; through: Id }\n\t| { type: \"compaction.retrying\"; taskId: Id; attempt: number; retryAt: number; error: string }\n\t| { type: \"compaction.finished\"; taskId: Id; summary: Id }\n\t| {\n\t\t\ttype: \"compaction.failed\";\n\t\t\ttaskId: Id;\n\t\t\treason: \"stale\" | \"declined\" | \"provider\" | \"retries_exhausted\" | \"no_model\";\n\t\t\tdetail: string;\n\t }\n\t| { type: \"task.started\"; taskId: Id; kind: string; background?: true }\n\t| {\n\t\t\ttype: \"task.ended\";\n\t\t\ttaskId: Id;\n\t\t\tkind: string;\n\t\t\toutcome: \"completed\" | \"failed\" | \"aborted\" | \"orphaned\" | \"faulted\";\n\t }\n\t| { type: \"config.changed\"; keys: string[] }\n\t| { type: \"warning\"; source: string; message: string }\n\t| { type: `plugin.${string}`; data: JsonValue };\n\nexport interface Envelope {\n\treadonly revision: number;\n\treadonly ops: Op[];\n\treadonly events: ViewEvent[];\n}\n\n/** Reads available to every view. Scans reject after a same-batch write to their domain (`ReadAfterWrite`). */\nexport interface TxReads {\n\tconversation(id: Id): Promise<Conversation | undefined>;\n\tentry(id: Id): Promise<Entry | undefined>;\n\tentry<E extends Entry>(kind: EntryKind<E>, id: Id): Promise<E | undefined>;\n\tentries(ids: readonly Id[]): Promise<Map<Id, Entry>>;\n\tnewestEntry(conversationId: Id, opts?: { kind?: string; withHead?: boolean }): Promise<Entry | undefined>;\n\tnewestEntry<E extends Entry>(conversationId: Id, kind: EntryKind<E>): Promise<E | undefined>;\n\tscanEntries(scan: EntryScan): Promise<Entry[]>;\n\tcontext(conversationId: Id, at?: Id): Promise<ContextView>;\n\ttask(id: Id): Promise<Task | undefined>;\n\ttask<K extends AnyKind>(ref: TaskRef<K>): Promise<TaskOf<K> | undefined>;\n\ttasks(scan: TaskScan): Promise<Task[]>;\n\tinput(id: Id): Promise<Input | undefined>;\n\trewindableAsOf(conversationId: Id, at: Id): Promise<RewindableState | undefined>;\n\t/** Plain copies. Document proxies cannot escape a transaction. */\n\tsnapshot(ref: { doc: \"rewindable\"; conversationId: Id }): RewindableState;\n\tsnapshot(ref: { doc: \"sticky\"; conversationId: Id }): StickyState;\n\tsnapshot(ref: { doc: \"session\" }): SessionState;\n}\n\ninterface SharedTx extends TxReads {\n\tplugins<T extends JsonObject>(namespace: Namespace<T>): T;\n\temit<T extends JsonObject>(namespace: Namespace<T>, name: string, data: JsonValue): void;\n\tconfig(conversationId: Id): { get<K extends string>(key: K): JsonValue | undefined };\n\t/** Passive entry: queued when busy, appended when idle. Returns the input id. */\n\twrite(conversationId: Id, entry: NewEntry): Promise<Id>;\n\twrite<E extends Entry>(conversationId: Id, kind: EntryKind<E>, entry: EntryInput<E>): Promise<Id>;\n\tcreateTask<K extends AnyKind>(\n\t\tkind: K,\n\t\tinput: InputOf<K>,\n\t\topts?: { conversationId?: Id; background?: true; after?: Id[] },\n\t): TaskRef<K>;\n\tcreateConversation(spec: ConversationSpec): Id;\n}\n\n/** What the host gets. */\nexport interface HostTx extends SharedTx {\n\t/** Config through the facade; raw core fields are not exposed to the host tx. */\n\tconfig(conversationId: Id): {\n\t\tget<K extends string>(key: K): JsonValue | undefined;\n\t\tset(key: string, value: JsonValue): void;\n\t\treset(key: string): void;\n\t};\n}\n\n/** What an ordinary task gets: scoped shared operations plus its own checkpoint and slot. */\nexport interface TaskTx extends SharedTx {\n\tcheckpoint<C extends Checkpoint>(value: C): void;\n\tslot<K extends AnyKind>(ref: TaskRef<K>): SlotOf<K>;\n\t/** Create a conversation this task owns. `parent` must be in the task's subtree. */\n\tcreateConversation(spec: ConversationSpec): Id;\n}\n\n/** Internal full authority for the fixed turn machinery. Never handed to ordinary kinds or the host. */\nexport interface CoreTx extends TaskTx {\n\temit<T extends JsonObject>(namespace: Namespace<T>, name: string, data: JsonValue): void;\n\temit(event: ViewEvent): void;\n\trewindable(conversationId: Id): RewindableState;\n\tsticky(conversationId: Id): StickyState;\n\tsession(): SessionState;\n\ttoolSlot(task: { conversationId: Id; input: { index: number } }): ToolSlot;\n\tappendEntry(conversationId: Id, entry: NewEntry): Id;\n\tappendEntry<E extends Entry>(conversationId: Id, kind: EntryKind<E>, entry: EntryInput<E>): EntryRef<E>;\n\tcreateTask(spec: TaskSpec): Id;\n\tcreateTask<K extends AnyKind>(\n\t\tkind: K,\n\t\tinput: InputOf<K>,\n\t\topts?: { conversationId?: Id; background?: true; after?: Id[] },\n\t): TaskRef<K>;\n\tsend(conversationId: Id, input: SendInput): Promise<Id>;\n\tresolveInputs(\n\t\tids: readonly Id[],\n\t\tresolution:\n\t\t\t| { status: \"done\"; answer: Id }\n\t\t\t| { status: \"unanswered\"; reason: NonNullable<Input[\"reason\"]>; detail?: string },\n\t): Promise<void>;\n\t/** Inbox placement at a safe boundary. `headBoundary`: the newest head as the caller knows it (including a same-batch self-head it appended). */\n\tboundary(\n\t\tconversationId: Id,\n\t\tat: \"postTools\" | \"final\",\n\t\theadBoundary: Id | undefined,\n\t): Promise<{ triggers: Id[]; terminated: boolean }>;\n\t/** Internal owned-conversation path. Sanitizes caller overrides while preserving inherited rewindable namespace slices. */\n\tcreateOwnedConversation(ownerTaskId: Id, sourceConversationId: Id, spec: OwnedConversationSpec): Promise<Id>;\n\t/** Internal host-fork path for an already validated historical snapshot. */\n\tcreateForkConversation(spec: ConversationSpec): Id;\n\tmarkTask(id: Id): void;\n}\n\n/** Thrown when a scan-shaped read follows a same-batch write to its domain. Poisons the transaction. */\nexport class ReadAfterWrite extends Error {\n\tconstructor(read: string, write: string) {\n\t\tsuper(`${read} after ${write} in the same transaction: the answer would not include the buffered write`);\n\t\tthis.name = \"ReadAfterWrite\";\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Runtime: what a kind's handlers get. Every commit checks the invocation token.\n// ---------------------------------------------------------------------------\n\nexport interface RequestOptions {\n\tmessages: StoredMessage[];\n\tthinkingLevel: ThinkingLevel;\n}\nexport interface Models {\n\tresolve(ref: ModelRef): Model | undefined;\n\tstream(model: Model, request: RequestOptions, ctx: Context): AsyncIterable<AssistantMessageEvent>;\n\tfetchDeferred(\n\t\tmodel: Model,\n\t\thandle: DeferredHandle,\n\t\tctx: Context,\n\t): Promise<AssistantMessage | { deferred: DeferredHandle }>;\n\tcancelDeferred(model: Model, handle: DeferredHandle, ctx: Context): Promise<void>;\n}\n\nexport interface Runtime<H extends object = object, Tx extends TaskTx = TaskTx> {\n\treadonly taskId: Id;\n\treadonly conversationId: Id;\n\treadonly kind: AnyKind;\n\tcommit<T>(fn: (tx: Tx, current: Task, ctx: Context) => T | Promise<T>, ctx: Context): Promise<T>;\n\treadonly hooks: HookRunner<H>;\n\treadonly models: Models;\n\treadonly tools: ReadonlyMap<string, ToolDeclaration>;\n\treadonly registries: { sections: SectionRegistry; tools: ToolRegistry };\n\treadonly kinds: ReadonlyMap<string, AnyKind>;\n\treadonly processHost: ProcessHost | undefined;\n\treadonly plugins: ReadonlyMap<string, PluginHandler>;\n\tnow(): number;\n\tsleep(untilMs: number, ctx: Context): Promise<void>;\n\twaitForInput(id: Id, ctx: Context): Promise<Input>;\n\twaitForTask(id: Id, ctx: Context): Promise<Task>;\n\tabortTask(id: Id, ctx: Context): Promise<\"marked\" | \"terminal\">;\n\tabortConversation(id: Id, ctx: Context): Promise<void>;\n\tcreateOwnedConversation(spec: OwnedConversationSpec, ctx: Context): Promise<Id>;\n\t/** Admission for a conversation owned by this task; the runtime verifies ownership before invoking the kernel. */\n\tsendOwned(conversationId: Id, input: SendInput, ctx: Context): Promise<Id>;\n\t// off-line reads\n\tcontext(conversationId: Id, at: Id | undefined, ctx: Context): Promise<ContextView>;\n\tnewestEntry(\n\t\tconversationId: Id,\n\t\topts: { kind?: string; withHead?: boolean },\n\t\tctx: Context,\n\t): Promise<Entry | undefined>;\n\trewindable(conversationId: Id, ctx: Context): Promise<RewindableState>;\n\tsticky(conversationId: Id, ctx: Context): Promise<StickyState>;\n\trewindableAsOf(conversationId: Id, at: Id, ctx: Context): Promise<RewindableState | undefined>;\n}\n\n// ---------------------------------------------------------------------------\n// Tools\n// ---------------------------------------------------------------------------\n\nexport type ToolControl = { terminate?: true; handoff?: string; addTools?: string[] };\nexport interface ToolDiagnostic {\n\tseverity: \"info\" | \"warn\" | \"error\";\n\tmessage: string;\n\tcode?: string;\n}\nexport interface ToolResult {\n\t/** Omit when the tool streamed through `api.stream`: the bounded stream is the content. */\n\tcontent?: (TextContent | ImageContent)[];\n\tisError?: boolean;\n\tdetails?: JsonValue;\n\tdiagnostics?: ToolDiagnostic[];\n\tcontrol?: ToolControl;\n}\nexport interface ToolDeclaration<P extends TSchema = TSchema> {\n\treadonly name: string;\n\treadonly description: string;\n\treadonly parameters: P;\n\treadonly replay?: \"safe\" | \"unsafe\"; // default unsafe\n\treadonly output?: { maxBytes?: number; maxLines?: number; retain?: \"head\" | \"tail\" };\n\texecute(args: Static<P>, api: ToolApi, ctx: Context): Promise<ToolResult>;\n}\n/** Erased declaration held by the registry. */\nexport type AnyToolDeclaration = ToolDeclaration<TSchema>;\n\n/** The narrow handle a task gets to a conversation it owns. */\nexport interface OwnedConversation {\n\treadonly id: Id;\n\tsend(\n\t\tinput: SendInput,\n\t\tctx: Context,\n\t): Promise<{ id: Id; wait(ctx: Context): Promise<Input>; result(ctx: Context): Promise<Input | undefined> }>;\n\tabort(ctx: Context): Promise<void>;\n}\n\nexport interface BeforeToolApi extends HookApi {\n\treadonly callId: string;\n\twaiting(ctx: Context): Promise<void>;\n\tmemo<T extends JsonValue>(name: string, candidate: T, ctx: Context): Promise<T>;\n\tmemo<T extends JsonValue>(name: string, ctx: Context): Promise<T | undefined>;\n\temit(name: string, data: JsonValue, ctx: Context): Promise<void>;\n}\n\nexport interface ToolApi {\n\treadonly taskId: Id;\n\treadonly conversationId: Id;\n\treadonly callId: string;\n\t/** Pipe raw output here. The kernel bounds it per the declaration, flushes it on a throttle, and uses it as the result content unless the tool returns its own. Synchronous. */\n\tstream(chunk: string | Uint8Array): void;\n\t/** Mutate the live slot's free fields (`progress`, `details`, `continuedBy`). Identity fields are protected. */\n\tprogress(\n\t\tupdate: (slot: Pick<ToolSlot, \"progress\" | \"details\" | \"continuedBy\">) => void,\n\t\tctx: Context,\n\t): Promise<void>;\n\tmemo<T extends JsonValue>(name: string, candidate: T, ctx: Context): Promise<T>;\n\tmemo<T extends JsonValue>(name: string, ctx: Context): Promise<T | undefined>;\n\tconversation(spec: OwnedConversationSpec, ctx: Context): Promise<OwnedConversation>;\n\ttask<K extends AnyKind>(\n\t\tkind: K,\n\t\tinput: InputOf<K>,\n\t\topts: { background?: true; after?: Id[] },\n\t\tctx: Context,\n\t): Promise<TaskRef<K>>;\n\tgetTask<K extends AnyKind>(ref: TaskRef<K>, ctx: Context): Promise<TaskOf<K> | undefined>;\n\twaitForTask<K extends AnyKind>(ref: TaskRef<K>, ctx: Context): Promise<TaskOf<K>>;\n\t/** Snapshot of another task's live slot (in this task's conversation or subtree). */\n\tslot<K extends AnyKind>(ref: TaskRef<K>, ctx: Context): Promise<SlotOf<K> | undefined>;\n}\n\nexport interface ProcessSpec {\n\tcommand: string;\n\targs: string[];\n\tcwd: string;\n\tenv?: { [key: string]: string };\n}\nexport type ProcessStatus =\n\t| { status: \"running\"; stdout: string; stderr: string; droppedStdout: number; droppedStderr: number }\n\t| {\n\t\t\tstatus: \"exited\";\n\t\t\texitCode: number;\n\t\t\tstdout: string;\n\t\t\tstderr: string;\n\t\t\tdroppedStdout: number;\n\t\t\tdroppedStderr: number;\n\t }\n\t| { status: \"unknown\" };\nexport interface ProcessHost {\n\tstart(key: string, spec: ProcessSpec, ctx: Context): Promise<void>;\n\tstatus(key: string, ctx: Context): Promise<ProcessStatus>;\n\tkill(key: string, signal: \"SIGTERM\" | \"SIGKILL\", ctx: Context): Promise<void>;\n}\n\nexport type PluginHandler = (input: JsonValue, api: ToolApi, ctx: Context) => Promise<JsonValue>;\n\n// ---------------------------------------------------------------------------\n// Invocation tokens and invokers\n// ---------------------------------------------------------------------------\n\n/** An unforgeable capability: only the scheduler creates these, one per invocation. */\nexport class InvocationToken {\n\t#alive = true;\n\treadonly taskId: Id;\n\treadonly mode: \"run\" | \"abort\";\n\tconstructor(taskId: Id, mode: \"run\" | \"abort\") {\n\t\tthis.taskId = taskId;\n\t\tthis.mode = mode;\n\t}\n\tget alive() {\n\t\treturn this.#alive;\n\t}\n\t/** Called by the scheduler when the invocation returns. */\n\trevoke() {\n\t\tthis.#alive = false;\n\t}\n}\n\nexport type Invoker =\n\t| { readonly type: \"host\"; readonly conversationId?: Id }\n\t/** Harness internals acting with core authority (send, reset, abort, retire). Never exported. */\n\t| { readonly type: \"kernel\"; readonly conversationId?: Id }\n\t| {\n\t\t\treadonly type: \"task\";\n\t\t\treadonly token: InvocationToken;\n\t\t\treadonly id: Id;\n\t\t\treadonly conversationId: Id;\n\t\t\treadonly kind: AnyKind;\n\t\t\treadonly core: boolean;\n\t\t\treadonly mode: \"run\" | \"abort\";\n\t };\n\n// ---------------------------------------------------------------------------\n// Errors\n// ---------------------------------------------------------------------------\n\nexport class Forbidden extends Error {\n\tconstructor(what: string) {\n\t\tsuper(`forbidden: ${what}`);\n\t\tthis.name = \"Forbidden\";\n\t}\n}\nexport class ConversationBusy extends Error {\n\tconstructor(id: Id) {\n\t\tsuper(`conversation ${id} is busy`);\n\t\tthis.name = \"ConversationBusy\";\n\t}\n}\nexport class GenerationInProgress extends Error {\n\tconstructor(id: Id) {\n\t\tsuper(`conversation ${id} already has a live generation`);\n\t\tthis.name = \"GenerationInProgress\";\n\t}\n}\nexport class CollapseInProgress extends Error {\n\tconstructor(id: Id) {\n\t\tsuper(`conversation ${id} already has a live collapse`);\n\t\tthis.name = \"CollapseInProgress\";\n\t}\n}\nexport class Faulted extends Error {\n\tconstructor(cause: unknown) {\n\t\tsuper(`Session faulted: ${String(cause)}`);\n\t\tthis.name = \"Faulted\";\n\t}\n}\nexport class Closed extends Error {\n\tconstructor() {\n\t\tsuper(\"Session is closed\");\n\t\tthis.name = \"Closed\";\n\t}\n}\nexport class TaskContractFault extends Error {\n\tconstructor(kind: string, what: string) {\n\t\tsuper(`kind ${kind} broke its contract: ${what}`);\n\t\tthis.name = \"TaskContractFault\";\n\t}\n}\n\nexport type { ToolCall, ToolResultMessage, AssistantMessage, UserMessage, DeferredHandle, ThinkingLevel };\nexport type RequestMessage = StoredMessage;\n"]}
@@ -0,0 +1,96 @@
1
+ /** Coerce an in-memory value (e.g. a pi-ai message) to its stored representation. */
2
+ export const toStored = (value) => JSON.parse(JSON.stringify(value));
3
+ export function defineEntry(kind) {
4
+ if (kind.startsWith("pi."))
5
+ throw new Error(`entry kind names beginning with "pi." are reserved: ${kind}`);
6
+ return Object.freeze({ kind, is: (entry) => entry?.kind === kind });
7
+ }
8
+ /** First writer wins, including when the stored winner is null. */
9
+ export function memoOnce(slot, key, candidate) {
10
+ if (!Object.hasOwn(slot, "memos"))
11
+ slot.memos = {};
12
+ const memos = slot.memos;
13
+ if (Object.hasOwn(memos, key))
14
+ return memos[key];
15
+ memos[key] = candidate;
16
+ return candidate;
17
+ }
18
+ /** Author an ordinary kind. Names may not begin with `pi.`. */
19
+ export function defineTask(definition) {
20
+ if (definition.name.startsWith("pi."))
21
+ throw new Error(`task kind names beginning with "pi." are reserved: ${definition.name}`);
22
+ return Object.freeze({ ...definition });
23
+ }
24
+ /** Thrown when a scan-shaped read follows a same-batch write to its domain. Poisons the transaction. */
25
+ export class ReadAfterWrite extends Error {
26
+ constructor(read, write) {
27
+ super(`${read} after ${write} in the same transaction: the answer would not include the buffered write`);
28
+ this.name = "ReadAfterWrite";
29
+ }
30
+ }
31
+ // ---------------------------------------------------------------------------
32
+ // Invocation tokens and invokers
33
+ // ---------------------------------------------------------------------------
34
+ /** An unforgeable capability: only the scheduler creates these, one per invocation. */
35
+ export class InvocationToken {
36
+ #alive = true;
37
+ taskId;
38
+ mode;
39
+ constructor(taskId, mode) {
40
+ this.taskId = taskId;
41
+ this.mode = mode;
42
+ }
43
+ get alive() {
44
+ return this.#alive;
45
+ }
46
+ /** Called by the scheduler when the invocation returns. */
47
+ revoke() {
48
+ this.#alive = false;
49
+ }
50
+ }
51
+ // ---------------------------------------------------------------------------
52
+ // Errors
53
+ // ---------------------------------------------------------------------------
54
+ export class Forbidden extends Error {
55
+ constructor(what) {
56
+ super(`forbidden: ${what}`);
57
+ this.name = "Forbidden";
58
+ }
59
+ }
60
+ export class ConversationBusy extends Error {
61
+ constructor(id) {
62
+ super(`conversation ${id} is busy`);
63
+ this.name = "ConversationBusy";
64
+ }
65
+ }
66
+ export class GenerationInProgress extends Error {
67
+ constructor(id) {
68
+ super(`conversation ${id} already has a live generation`);
69
+ this.name = "GenerationInProgress";
70
+ }
71
+ }
72
+ export class CollapseInProgress extends Error {
73
+ constructor(id) {
74
+ super(`conversation ${id} already has a live collapse`);
75
+ this.name = "CollapseInProgress";
76
+ }
77
+ }
78
+ export class Faulted extends Error {
79
+ constructor(cause) {
80
+ super(`Session faulted: ${String(cause)}`);
81
+ this.name = "Faulted";
82
+ }
83
+ }
84
+ export class Closed extends Error {
85
+ constructor() {
86
+ super("Session is closed");
87
+ this.name = "Closed";
88
+ }
89
+ }
90
+ export class TaskContractFault extends Error {
91
+ constructor(kind, what) {
92
+ super(`kind ${kind} broke its contract: ${what}`);
93
+ this.name = "TaskContractFault";
94
+ }
95
+ }
96
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/harness/pico3/types.ts"],"names":[],"mappings":"AAsCA,qFAAqF;AACrF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAI,KAAQ,EAAa,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAc,CAAC;AAqEnG,MAAM,UAAU,WAAW,CAAkB,IAAY,EAAgB;IACxE,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,uDAAuD,IAAI,EAAE,CAAC,CAAC;IAC3G,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE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;IAChC,cAAc;QACb,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC;IAAA,CACrB;CACD;AACD,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC3C,YAAY,IAAY,EAAE,IAAY,EAAE;QACvC,KAAK,CAAC,QAAQ,IAAI,wBAAwB,IAAI,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAAA,CAChC;CACD","sourcesContent":["/**\n * harness-v3 — records, documents, storage, kinds, transactions, runtime, tools, hooks.\n *\n * Durable model: four tables (conversations, entries, tasks, inputs) and three documents\n * (session, per-conversation rewindable, per-conversation sticky). Every durable position\n * is strict JSON (`JsonValue`); nothing durable is `unknown`.\n *\n * Single process. A storage path has one owning process and one owning Session at a time.\n * Two processes opening the same JSONL directory is unsupported.\n */\nimport type { JsonValue as ChordJsonValue, Context, JsonRepresentation } from \"@earendil-works/chord\";\nimport type { Op } from \"@earendil-works/chord/delta\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tAssistantMessageEvent,\n\tDeferredHandle,\n\tImageContent,\n\tMessage as ModelMessage,\n\tModel as ModelOf,\n\tTextContent,\n\tToolCall,\n\tToolResultMessage,\n\tUserMessage,\n} from \"@earendil-works/pi-ai\";\nimport type { Static, TSchema } from \"typebox\";\nimport type { ThinkingLevel } from \"../../types.ts\";\nimport type { SectionRegistry, SectionSeed, ToolRegistry } from \"./system.ts\";\n\n// ---------------------------------------------------------------------------\n// Strict durable JSON\n// ---------------------------------------------------------------------------\n\nexport type JsonPrimitive = string | number | boolean | null;\nexport type JsonValue = ChordJsonValue;\n/** Optional properties represent absent keys; committed values are normalized through JSON serialization. */\nexport type JsonObject = { [key: string]: JsonValue };\n\n/** Coerce an in-memory value (e.g. a pi-ai message) to its stored representation. */\nexport const toStored = <T>(value: T): Stored<T> => JSON.parse(JSON.stringify(value)) as Stored<T>;\n\n/**\n * The JSON representation of a value: what survives `JSON.parse(JSON.stringify(v))`.\n * Optional keys stay optional; `undefined` values vanish; functions are never durable.\n * Use for imported pi-ai types at durable positions.\n */\nexport type Stored<T> = JsonRepresentation<T>;\n\nexport type Id = number;\nexport type Seq = number;\n\n/** Compile-time assertion helper. */\nexport type Assert<T extends true> = T;\n/** True iff T is strict JSON (structurally). */\nexport type IsJson<T> = [T] extends [JsonValue] ? true : false;\n\n// ---------------------------------------------------------------------------\n// Records\n// ---------------------------------------------------------------------------\n\nexport interface Conversation {\n\treadonly id: Id;\n\treadonly parent?: { readonly conversationId: Id; readonly at: Id };\n\treadonly owner?: Id; // task that created it\n\t/** §8.1 section seed: applied by preparation while the conversation has no local managed entry. Private: not in ConversationView. */\n\treadonly sections?: readonly SectionSeed[];\n}\n\n/**\n * System instructions and the tool loadout ride inside `messages` (pi-ai PR #9116, shimmed\n * here until it lands): a SystemMessage at its historical position.\n */\nexport interface SystemMessage {\n\trole: \"system\";\n\tcontent: string;\n\ttoolsAdded?: { name: string; description: string; parameters: TSchema }[];\n\ttoolsRemoved?: { name: string }[];\n\ttimestamp: number;\n}\nexport type Message = ModelMessage | SystemMessage;\nexport type StoredMessage = Stored<Message>;\nexport type Model = ModelOf<Api>;\n\nexport interface ContextEdit {\n\treadonly target: Id;\n\treadonly action: \"omit\" | \"replace\";\n\treadonly messages?: readonly StoredMessage[];\n}\n\nexport interface Entry {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\treadonly kind: string;\n\treadonly model?: readonly StoredMessage[]; // what the model sees; absent = display/bookkeeping only\n\treadonly data?: JsonObject;\n\treadonly head?: Id; // context starts here (may be a parent's entry). Assigned by the kernel; `self` in NewEntry\n\treadonly edits?: readonly ContextEdit[];\n\treadonly byTaskId?: Id;\n}\nexport type NewEntry = Omit<Entry, \"id\" | \"conversationId\" | \"byTaskId\" | \"head\"> & { readonly head?: Id | \"self\" };\n\n/** A typed witness for an entry kind: `is()` narrows, and typed writes take `EntryInput<E>`. */\nexport interface EntryKind<E extends Entry = Entry> {\n\treadonly kind: string;\n\tis(entry: Entry | undefined): entry is E;\n}\nexport type EntryInput<E extends Entry> = Omit<E, \"id\" | \"conversationId\" | \"kind\" | \"byTaskId\" | \"head\"> &\n\t(E extends { readonly head: Id } ? { readonly head: Id | \"self\" } : { readonly head?: never });\nexport function defineEntry<E extends Entry>(kind: string): EntryKind<E> {\n\tif (kind.startsWith(\"pi.\")) throw new Error(`entry kind names beginning with \"pi.\" are reserved: ${kind}`);\n\treturn Object.freeze({ kind, is: (entry: Entry | undefined): entry is E => entry?.kind === kind });\n}\n\nexport type Checkpoint = JsonObject & { readonly phase: string };\n\nexport type Completion<R extends JsonValue = JsonValue, F extends JsonValue = JsonValue> =\n\t| { readonly status: \"completed\"; readonly result: R }\n\t| { readonly status: \"failed\"; readonly failure: F };\nexport type Outcome<R extends JsonValue = JsonValue, F extends JsonValue = JsonValue, A extends JsonValue = JsonValue> =\n\t| Completion<R, F>\n\t| { readonly status: \"aborted\"; readonly result: A }\n\t| { readonly status: \"orphaned\" }\n\t/** The kind broke its contract (a handler threw or returned an invalid shape). Not one of its declared failures. */\n\t| { readonly status: \"faulted\"; readonly error: string };\n\nexport interface Task<I extends JsonValue = JsonValue, C extends Checkpoint = Checkpoint> {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\treadonly kind: string;\n\treadonly input: I;\n\treadonly status: \"pending\" | \"running\" | \"terminal\";\n\treadonly checkpoint?: C;\n\treadonly abort?: true; // the durable mark\n\treadonly outcome?: Outcome;\n\treadonly after: readonly Id[];\n\treadonly owns: readonly Id[]; // conversations this task created\n\treadonly background?: true; // does not hold the conversation busy; survives conversation abort\n}\nexport type TaskPatch = { readonly id: Id } & Partial<\n\tOmit<Pick<Task, \"status\" | \"checkpoint\" | \"abort\" | \"outcome\" | \"owns\">, \"checkpoint\">\n> & { checkpoint?: Checkpoint | null };\n\nexport interface Input {\n\treadonly id: Id;\n\treadonly conversationId: Id;\n\treadonly requestId?: string;\n\treadonly status: \"queued\" | \"placed\" | \"done\" | \"unanswered\";\n\treadonly entry?: Id;\n\treadonly answer?: Id;\n\treadonly reason?: \"aborted\" | \"stale\" | \"terminated\" | \"failed\";\n\treadonly detail?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Documents (Chord-tracked). Mutated in place inside a commit, diffed at the end.\n// ---------------------------------------------------------------------------\n\nexport type ModelRef = { provider: string; modelId: string };\nexport type RetryPolicy = { enabled: boolean; maxRetries: number; baseDelayMs: number; maxAgentDelayMs?: number };\n\n/** One running tool call, at the index of its call in the assistant message. */\nexport type ToolSlot = {\n\tcallId: string;\n\tname: string;\n\targs: JsonValue;\n\tstatus: \"pending\" | \"running\" | \"done\" | \"error\" | \"aborted\";\n\twaitingOn?: string;\n\toutput?: string; // bounded stream as it stands\n\tprogress?: string;\n\tdetails?: JsonValue;\n\tcontinuedBy?: Id; // a background task that took the work over; its live state is `tasks[continuedBy]`\n\tentry?: Id;\n\t/** Private task-lifetime coordination state. Never projected into ConversationView. */\n\tmemos?: { [key: string]: JsonValue };\n};\n/** The current turn, shaped for rendering. Reset when a generation starts; cleared when the turn ends. */\nexport type TurnState = {\n\tmessage?: Stored<AssistantMessage>; // streaming assistant message\n\ttools: ToolSlot[]; // tools of the assistant message being executed, by call index\n};\n\n/** Private durable namespace slices stored in authoritative documents. */\nexport type PluginSlices = { [namespace: string]: JsonObject };\n\n/** Rewound by forks: forks see the state as of their fork point. Core config fields come from the built-in kinds' declarations. */\nexport type RewindableState = {\n\tmodel?: ModelRef;\n\tthinkingLevel: ThinkingLevel;\n\tselectedTools: string[];\n\tprofile: string;\n\tthreshold: number;\n\tkeepRecent: number;\n\tplugins: PluginSlices;\n\t[key: string]: JsonValue | undefined; // ordinary kinds' declared config, keyed by their disjoint names\n};\n/** The present. Never folded historically; truncated to its last base. */\nexport type StickyState = {\n\tretry: RetryPolicy;\n\tsteeringMode: \"all\" | \"one-at-a-time\";\n\tfollowUpMode: \"all\" | \"one-at-a-time\";\n\tinbox: QueuedInput[];\n\tturn: TurnState;\n\ttasks: { [taskId: string]: JsonObject }; // non-turn tasks' live slots; retired by the kernel on terminal\n\tplugins: PluginSlices;\n\t[key: string]: JsonValue | undefined;\n};\nexport type SessionState = { plugins: PluginSlices; [key: string]: JsonValue | undefined };\n\nexport type QueuedInput =\n\t| { id: Id; mode: \"steer\" | \"followUp\"; input: Stored<UserInput> }\n\t| { id: Id; mode: \"write\"; entry: Stored<NewEntry> };\n\nexport type DocRef =\n\t| { doc: \"session\" }\n\t| { doc: \"rewindable\"; conversationId: Id }\n\t| { doc: \"sticky\"; conversationId: Id };\n\nexport type NamespaceDefaults<T extends JsonObject> = {\n\treadonly rewindable?: Partial<T>;\n\treadonly sticky?: Partial<T>;\n\treadonly session?: Partial<T>;\n};\n\n/** Current process authority for one durable namespace string. */\nexport interface Namespace<T extends JsonObject = JsonObject> {\n\treadonly id: string;\n\t/** Type-only invariant marker. */\n\treadonly valueType?: (value: T) => T;\n\tunregister(): void;\n}\n\n/** Internal erased registration paired with the public namespace token. */\nexport interface NamespaceRegistration {\n\treadonly token: object;\n\treadonly defaults: { readonly rewindable: JsonObject; readonly sticky: JsonObject; readonly session: JsonObject };\n\treadonly routes: ReadonlyMap<string, DocRef[\"doc\"]>;\n\treadonly project?: (slice: Readonly<JsonObject>) => JsonValue;\n}\n\n/** First writer wins, including when the stored winner is null. */\nexport function memoOnce<T extends JsonValue>(slot: JsonObject, key: string, candidate: T): T {\n\tif (!Object.hasOwn(slot, \"memos\")) slot.memos = {};\n\tconst memos = slot.memos as { [key: string]: JsonValue };\n\tif (Object.hasOwn(memos, key)) return memos[key] as T;\n\tmemos[key] = candidate;\n\treturn candidate;\n}\n\n// ---------------------------------------------------------------------------\n// Configuration facade: every registered kind's `config` merged flat.\n// ---------------------------------------------------------------------------\n\ntype UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends (x: infer I) => void ? I : never;\n/** A declared slice; the undeclared `ConfigShape` (index signature) counts as no keys. */\ntype Declared<S> = string extends keyof S ? object : S;\ntype RewindableOf<K> = K extends unknown\n\t? ConfigOf<K> extends { readonly rewindable: infer RC }\n\t\t? Declared<RC>\n\t\t: object\n\t: never;\ntype StickyOf<K> = K extends unknown\n\t? ConfigOf<K> extends { readonly sticky: infer SC }\n\t\t? Declared<SC>\n\t\t: object\n\t: never;\nexport type ConfigOfKinds<Ks extends readonly AnyKind[]> = UnionToIntersection<\n\tRewindableOf<Ks[number]> | StickyOf<Ks[number]>\n> extends infer M\n\t? { [K in keyof M]: M[K] }\n\t: never;\ntype KeysOfKind<K> = (keyof RewindableOf<K> | keyof StickyOf<K>) & string;\ntype IsUnion<U, C = U> = U extends unknown ? ([C] extends [U] ? false : true) : never;\n/** The kinds declaring `Key`. */\ntype Owners<Ks extends readonly AnyKind[], Key extends string> = {\n\t[I in keyof Ks]: Key extends KeysOfKind<Ks[I]> ? Ks[I] : never;\n}[number];\ntype AllKeys<Ks extends readonly AnyKind[]> = { [I in keyof Ks]: KeysOfKind<Ks[I]> }[number];\ntype ClashingKeys<Ks extends readonly AnyKind[]> = {\n\t[Key in AllKeys<Ks>]: true extends IsUnion<Owners<Ks, Key>> ? Key : never;\n}[AllKeys<Ks>];\n/** `true` iff no two kinds declare the same config key. Asserted at open at compile time and at runtime. */\nexport type DisjointConfig<Ks extends readonly AnyKind[]> = [ClashingKeys<Ks>] extends [never] ? true : false;\n\nexport interface ConfigFacade<Cfg extends object> {\n\tget(ctx: Context): Promise<Readonly<Cfg>>;\n\t/** One commit, routed to the declaring documents. */\n\tset(patch: { [K in keyof Cfg]?: Cfg[K] }, ctx: Context): Promise<void>;\n\t/** Delete persisted overrides. Declared defaults become visible; `model` becomes absent. */\n\treset(keys: readonly (keyof Cfg)[], ctx: Context): Promise<void>;\n}\n\n// ---------------------------------------------------------------------------\n// Storage: six write types, a handful of reads. One owning Session per instance.\n// ---------------------------------------------------------------------------\n\nexport type Write =\n\t| { type: \"conversation\"; conversation: Conversation }\n\t| { type: \"entry\"; entry: Entry }\n\t| { type: \"task\"; task: Task } // create\n\t| { type: \"task.patch\"; patch: TaskPatch } // `checkpoint: null` clears\n\t| { type: \"input\"; input: Input } // create or replace whole\n\t| { type: \"doc\"; ref: DocRef; ops: Op[] };\n\nexport interface EntryScan {\n\tconversationId: Id;\n\tkind?: string;\n\twithHead?: boolean;\n\tbefore?: Id; // strictly less\n\tlimit: number;\n}\nexport interface TaskScan {\n\tconversationId?: Id;\n\tstatus?: Task[\"status\"][];\n\tkind?: string;\n}\n\nexport interface Storage {\n\t/** Persist one batch atomically: all or nothing. Returns the commit sequence. */\n\tcommit(writes: readonly Write[], ctx: Context): Promise<Seq>;\n\tmintId(): Id;\n\tconversation(id: Id, ctx: Context): Promise<Conversation | undefined>;\n\tconversations(ctx: Context): Promise<Conversation[]>;\n\tentries(ids: readonly Id[], ctx: Context): Promise<Map<Id, Entry>>;\n\t/** Newest-first, fork-aware: this conversation's entries, then the parent's up to the fork point, and so on. */\n\tscanEntries(scan: EntryScan, ctx: Context): Promise<Entry[]>;\n\ttask(id: Id, ctx: Context): Promise<Task | undefined>;\n\tscanTasks(scan: TaskScan, ctx: Context): Promise<Task[]>;\n\tinput(id: Id, ctx: Context): Promise<Input | undefined>;\n\tinputByRequest(conversationId: Id, requestId: string, ctx: Context): Promise<Input | undefined>;\n\tdoc(ref: DocRef, ctx: Context): Promise<JsonObject | undefined>;\n\t/** Rewindable doc as of the atomic commit containing entry `at` (fork inheritance). See \"commit-granular history\". */\n\tdocAsOf(conversationId: Id, at: Id, ctx: Context): Promise<JsonObject | undefined>;\n\t/** Rewrite a doc log from its last base. */\n\ttruncate(ref: DocRef, ctx: Context): Promise<void>;\n\tclose(ctx: Context): Promise<void>;\n}\n\n// ---------------------------------------------------------------------------\n// Kinds\n// ---------------------------------------------------------------------------\n\n/** A hook may synchronously or asynchronously omit its replacement value. */\n// biome-ignore lint/suspicious/noConfusingVoidType: void is the intentional callback no-value result\nexport type HookResult<T> = T | void | Promise<T | void>;\n\nexport interface HookApi {\n\treadonly kind: string;\n\treadonly taskId: Id;\n\treadonly conversationId: Id;\n}\n/** Kept as the concise name used by existing kind hook declarations. */\nexport type HookInfo = HookApi;\nexport interface HookBinding<H extends object> {\n\treadonly handlers: Partial<H>;\n\treadonly namespace: Namespace;\n\treadonly api: HookApi;\n}\nexport interface HookRunner<H extends object> {\n\thandlers(): readonly HookBinding<H>[];\n\t/** Call `fn` on each handler; `onValue` sees non-undefined results and may return true to stop. A throwing handler is reported and skipped. */\n\teach<V>(\n\t\tctx: Context,\n\t\tfn: (handlers: Partial<H>, api: HookApi) => HookResult<V>,\n\t\tonValue?: (v: V) => unknown,\n\t): Promise<void>;\n}\n\n/** What a phase handler returns: advance to a checkpoint, or finish. A builder runs on the line and may terminalize or ask to retry. */\nexport type Step<C extends Checkpoint, R extends JsonValue, F extends JsonValue, Tx extends TaskTx = TaskTx> =\n\t| {\n\t\t\treadonly next:\n\t\t\t\t| C\n\t\t\t\t| ((\n\t\t\t\t\t\ttx: Tx,\n\t\t\t\t\t\tcurrent: Task,\n\t\t\t\t\t\tctx: Context,\n\t\t\t\t ) => C | Completion<R, F> | \"retry\" | Promise<C | Completion<R, F> | \"retry\">);\n\t }\n\t| { readonly done: Closure<R, F, Tx> };\nexport type Closure<R extends JsonValue, F extends JsonValue, Tx extends TaskTx = TaskTx> = (\n\ttx: Tx,\n\tcurrent: Task,\n\tctx: Context,\n) => Completion<R, F> | Promise<Completion<R, F>>;\nexport type AbortClosure<A extends JsonValue, Tx extends TaskTx = TaskTx> = (\n\ttx: Tx,\n\tcurrent: Task,\n\tctx: Context,\n) => A | Promise<A>;\n\nexport type CheckpointAt<C extends Checkpoint, P extends C[\"phase\"]> = Extract<C, { readonly phase: P }>;\nexport type PhaseHandler<\n\tI extends JsonValue,\n\tC extends Checkpoint,\n\tP extends C[\"phase\"],\n\tR extends JsonValue,\n\tF extends JsonValue,\n\tH extends object,\n\tTx extends TaskTx = TaskTx,\n> = (\n\ttask: Task<I, CheckpointAt<C, P>> & { readonly checkpoint: CheckpointAt<C, P> },\n\trt: Runtime<H, Tx>,\n\tctx: Context,\n) => Promise<Step<C, R, F, Tx>>;\n\n/** A config slice: JSON values; a key whose default is `undefined` is optional (only `model` among the built-ins). */\nexport type ConfigShape = { [key: string]: JsonValue | undefined };\n/** Per-kind configuration: defaults, split by document. Keys across all kinds must be disjoint. */\nexport interface KindConfig<RC extends ConfigShape = ConfigShape, SC extends ConfigShape = ConfigShape> {\n\treadonly rewindable?: RC;\n\treadonly sticky?: SC;\n}\n\n/** Phantom carrier so `TaskOf<K>` etc. can read a kind's types back out. Never set at runtime. */\nexport interface KindTypes<\n\tI extends JsonValue,\n\tC extends Checkpoint,\n\tR extends JsonValue,\n\tF extends JsonValue,\n\tA extends JsonValue,\n\tH extends object,\n\tCfg extends KindConfig,\n\tS extends JsonObject,\n> {\n\tinput: I;\n\tcheckpoint: C;\n\tresult: R;\n\tfailure: F;\n\taborted: A;\n\thooks: H;\n\tconfig: Cfg;\n\tslot: S;\n}\n\n/**\n * A task kind. `initial` runs when there is no checkpoint; `phases` is exhaustive over\n * `C[\"phase\"]`. Phases named in `inflight` are written by a handler immediately before an\n * external effect and are entered by the scheduler only after reopen; a `next` transition\n * into one is rejected as a contract fault.\n */\nexport interface Kind<\n\tI extends JsonValue = JsonValue,\n\tC extends Checkpoint = Checkpoint,\n\tR extends JsonValue = JsonValue,\n\tF extends JsonValue = JsonValue,\n\tA extends JsonValue = JsonValue,\n\tH extends object = object,\n\tCfg extends KindConfig = KindConfig,\n\tS extends JsonObject = JsonObject,\n\tTx extends TaskTx = TaskTx,\n> {\n\treadonly types?: KindTypes<I, C, R, F, A, H, Cfg, S>;\n\treadonly name: string;\n\t/** A turn kind makes the conversation busy for admission. */\n\treadonly turn?: boolean;\n\treadonly config?: Cfg;\n\t/** Live slot (`sticky.tasks[id]`) initializer. */\n\treadonly slot?: (input: I) => S;\n\t/** Rendering projection for a non-turn task. Raw checkpoints and slots are never published. */\n\treadonly describe?: (task: Task<I, C> & { readonly slot?: Readonly<S> }) => JsonValue;\n\treadonly inflight?: readonly C[\"phase\"][];\n\tinitial(\n\t\ttask: Task<I, never> & { readonly checkpoint?: undefined },\n\t\trt: Runtime<H, Tx>,\n\t\tctx: Context,\n\t): Promise<Step<C, R, F, Tx>>;\n\treadonly phases: { readonly [P in C[\"phase\"]]: PhaseHandler<I, C, P, R, F, H, Tx> };\n\tabort(task: Task<I, C>, rt: Runtime<H, Tx>, ctx: Context): Promise<AbortClosure<A, Tx>>;\n}\n\n/** Internal kind type for fixed core machinery. */\nexport type CoreKind<\n\tI extends JsonValue,\n\tC extends Checkpoint,\n\tR extends JsonValue,\n\tF extends JsonValue,\n\tA extends JsonValue,\n\tH extends object = object,\n\tCfg extends KindConfig = KindConfig,\n\tS extends JsonObject = JsonObject,\n> = Kind<I, C, R, F, A, H, Cfg, S, CoreTx>;\n\n/** Author an ordinary kind. Names may not begin with `pi.`. */\nexport function defineTask<\n\tI extends JsonValue,\n\tC extends Checkpoint,\n\tR extends JsonValue,\n\tF extends JsonValue,\n\tA extends JsonValue,\n\tH extends object = object,\n\tCfg extends KindConfig = KindConfig,\n\tS extends JsonObject = JsonObject,\n>(definition: Kind<I, C, R, F, A, H, Cfg, S>): Kind<I, C, R, F, A, H, Cfg, S> {\n\tif (definition.name.startsWith(\"pi.\"))\n\t\tthrow new Error(`task kind names beginning with \"pi.\" are reserved: ${definition.name}`);\n\treturn Object.freeze({ ...definition });\n}\n\n/**\n * The erased kind the kernel stores. Handlers are invoked through `KindAdapter`, the one\n * place a concrete `Kind<…>` is narrowed to this and its outputs are validated.\n */\nexport interface AnyKind {\n\treadonly types?: unknown;\n\treadonly name: string;\n\treadonly turn?: boolean;\n\treadonly config?: KindConfig;\n\treadonly slot?: (input: never) => JsonObject;\n\treadonly describe?: unknown;\n\treadonly inflight?: readonly string[];\n\treadonly initial: unknown;\n\treadonly phases: { readonly [phase: string]: unknown };\n\treadonly abort: unknown;\n}\n\nexport interface TaskRef<K extends AnyKind = AnyKind> {\n\treadonly id: Id;\n\treadonly kind: K;\n}\nexport interface EntryRef<E extends Entry = Entry> {\n\treadonly id: Id;\n\treadonly kind: EntryKind<E>;\n}\n\ntype TypesOf<K> = K extends { types?: infer T } ? NonNullable<T> : never;\nexport type TaskOf<K> = TypesOf<K> extends KindTypes<\n\tinfer I,\n\tinfer C,\n\tinfer R,\n\tinfer F,\n\tinfer A,\n\tobject,\n\tKindConfig,\n\tJsonObject\n>\n\t? Omit<Task<I, C>, \"outcome\"> & { readonly outcome?: Outcome<R, F, A> }\n\t: never;\nexport type InputOf<K> = TypesOf<K> extends KindTypes<\n\tinfer I,\n\tCheckpoint,\n\tJsonValue,\n\tJsonValue,\n\tJsonValue,\n\tobject,\n\tKindConfig,\n\tJsonObject\n>\n\t? I\n\t: never;\nexport type HooksOf<K> = TypesOf<K> extends KindTypes<\n\tJsonValue,\n\tCheckpoint,\n\tJsonValue,\n\tJsonValue,\n\tJsonValue,\n\tinfer H,\n\tKindConfig,\n\tJsonObject\n>\n\t? H\n\t: never;\nexport type ConfigOf<K> = TypesOf<K> extends KindTypes<\n\tJsonValue,\n\tCheckpoint,\n\tJsonValue,\n\tJsonValue,\n\tJsonValue,\n\tobject,\n\tinfer Cfg,\n\tJsonObject\n>\n\t? Cfg\n\t: never;\nexport type SlotOf<K> = TypesOf<K> extends KindTypes<\n\tJsonValue,\n\tCheckpoint,\n\tJsonValue,\n\tJsonValue,\n\tJsonValue,\n\tobject,\n\tKindConfig,\n\tinfer S\n>\n\t? S\n\t: never;\n\nexport type TaskSpec = {\n\tkind: string;\n\tconversationId?: Id;\n\tinput: JsonValue;\n\tafter?: Id[];\n\tbackground?: true;\n};\n\n// ---------------------------------------------------------------------------\n// Transactions. One implementation; three views.\n// ---------------------------------------------------------------------------\n\nexport interface ConversationSpec {\n\tparent?: { conversationId: Id; at: Id | \"start\" };\n\trewindable?: Partial<RewindableState>;\n\tsticky?: Partial<StickyState>;\n\tsections?: readonly SectionSeed[];\n}\nexport interface OwnedConversationSpec {\n\tinherit?: boolean;\n\trewindable?: Partial<RewindableState>;\n\tsticky?: Partial<StickyState>;\n}\nexport type UserInput = string | UserMessage[\"content\"];\nexport interface SendInput {\n\tcontent: UserInput;\n\trequestId?: string;\n\twhenBusy?: \"steer\" | \"followUp\" | \"reject\";\n}\nexport type ContextView = { head: Entry | undefined; entries: Entry[]; messages: StoredMessage[] };\n\nexport type GenerationStatus =\n\t| { stage: \"waiting\"; on: \"compaction\" }\n\t| { stage: \"preparing\" }\n\t| { stage: \"requesting\"; attempt: number }\n\t| { stage: \"streaming\"; attempt: number }\n\t| { stage: \"retrying\"; attempt: number; retryAt: number; lastError: string }\n\t| { stage: \"deferred\"; attempt: number; pollAt: number };\n\nexport interface TurnView {\n\tinputs: Id[];\n\tgeneration?: GenerationStatus;\n\tmessage?: Stored<AssistantMessage>;\n\ttools: Omit<ToolSlot, \"memos\">[];\n}\n\nexport interface ConversationView {\n\tconversation: Omit<Conversation, \"sections\">;\n\tentries: Entry[];\n\tconfig: { [key: string]: JsonValue | undefined };\n\tinbox: QueuedInput[];\n\tturn?: TurnView;\n\tcompaction?: {\n\t\ttaskId: Id;\n\t\treason: \"threshold\" | \"manual\" | \"overflow\";\n\t\tstage: \"summarizing\" | \"retrying\";\n\t\tattempt: number;\n\t\tretryAt?: number;\n\t};\n\ttasks: { [taskId: string]: { kind: string; background?: true; marked?: true; status: JsonValue } };\n\tplugins: { [namespace: string]: JsonValue };\n}\n\nexport type ViewEvent =\n\t| { type: \"entry.added\"; entry: Entry }\n\t| { type: \"head.moved\"; entry: Entry }\n\t| { type: \"turn.started\"; inputs: Id[] }\n\t| { type: \"turn.ended\"; inputs: Id[]; status: \"done\"; answer: Id }\n\t| {\n\t\t\ttype: \"turn.ended\";\n\t\t\tinputs: Id[];\n\t\t\tstatus: \"unanswered\";\n\t\t\treason: \"terminated\" | \"aborted\" | \"failed\" | \"stale\";\n\t\t\tdetail?: string;\n\t }\n\t| { type: \"input.queued\"; input: Id; mode: \"steer\" | \"followUp\" | \"write\" }\n\t| { type: \"input.placed\"; input: Id; entry: Id }\n\t| { type: \"input.aborted\"; input: Id }\n\t| { type: \"generation.started\"; taskId: Id; attempt: number }\n\t| { type: \"generation.retrying\"; taskId: Id; attempt: number; retryAt: number; error: string }\n\t| { type: \"generation.deferred\"; taskId: Id; pollAt: number }\n\t| { type: \"generation.completed\"; taskId: Id; entry: Id; toolCalls: number }\n\t| {\n\t\t\ttype: \"generation.failed\";\n\t\t\ttaskId: Id;\n\t\t\treason: \"provider\" | \"overflow\" | \"retries_exhausted\" | \"no_model\";\n\t\t\tdetail: string;\n\t\t\tentry?: Id;\n\t }\n\t| { type: \"tool.waiting\"; taskId: Id; callId: string; on: string }\n\t| { type: \"tool.started\"; taskId: Id; callId: string; name: string }\n\t| { type: \"tool.finished\"; taskId: Id; callId: string; entry: Id; isError: boolean; control?: ToolControl }\n\t| { type: \"tool.aborted\"; taskId: Id; callId: string; entry: Id }\n\t| { type: \"compaction.started\"; taskId: Id; reason: \"threshold\" | \"manual\" | \"overflow\"; through: Id }\n\t| { type: \"compaction.retrying\"; taskId: Id; attempt: number; retryAt: number; error: string }\n\t| { type: \"compaction.finished\"; taskId: Id; summary: Id }\n\t| {\n\t\t\ttype: \"compaction.failed\";\n\t\t\ttaskId: Id;\n\t\t\treason: \"stale\" | \"declined\" | \"provider\" | \"retries_exhausted\" | \"no_model\";\n\t\t\tdetail: string;\n\t }\n\t| { type: \"task.started\"; taskId: Id; kind: string; background?: true }\n\t| {\n\t\t\ttype: \"task.ended\";\n\t\t\ttaskId: Id;\n\t\t\tkind: string;\n\t\t\toutcome: \"completed\" | \"failed\" | \"aborted\" | \"orphaned\" | \"faulted\";\n\t }\n\t| { type: \"config.changed\"; keys: string[] }\n\t| { type: \"warning\"; source: string; message: string }\n\t| { type: `plugin.${string}`; data: JsonValue };\n\nexport interface Envelope {\n\treadonly revision: number;\n\treadonly ops: Op[];\n\treadonly events: ViewEvent[];\n}\n\n/** Reads available to every view. Scans reject after a same-batch write to their domain (`ReadAfterWrite`). */\nexport interface TxReads {\n\tconversation(id: Id): Promise<Conversation | undefined>;\n\tentry(id: Id): Promise<Entry | undefined>;\n\tentry<E extends Entry>(kind: EntryKind<E>, id: Id): Promise<E | undefined>;\n\tentries(ids: readonly Id[]): Promise<Map<Id, Entry>>;\n\tnewestEntry(conversationId: Id, opts?: { kind?: string; withHead?: boolean }): Promise<Entry | undefined>;\n\tnewestEntry<E extends Entry>(conversationId: Id, kind: EntryKind<E>): Promise<E | undefined>;\n\tscanEntries(scan: EntryScan): Promise<Entry[]>;\n\tcontext(conversationId: Id, at?: Id): Promise<ContextView>;\n\ttask(id: Id): Promise<Task | undefined>;\n\ttask<K extends AnyKind>(ref: TaskRef<K>): Promise<TaskOf<K> | undefined>;\n\ttasks(scan: TaskScan): Promise<Task[]>;\n\tinput(id: Id): Promise<Input | undefined>;\n\trewindableAsOf(conversationId: Id, at: Id): Promise<RewindableState | undefined>;\n\t/** Plain copies. Document proxies cannot escape a transaction. */\n\tsnapshot(ref: { doc: \"rewindable\"; conversationId: Id }): RewindableState;\n\tsnapshot(ref: { doc: \"sticky\"; conversationId: Id }): StickyState;\n\tsnapshot(ref: { doc: \"session\" }): SessionState;\n}\n\ninterface SharedTx extends TxReads {\n\tplugins<T extends JsonObject>(namespace: Namespace<T>): T;\n\temit<T extends JsonObject>(namespace: Namespace<T>, name: string, data: JsonValue): void;\n\tconfig(conversationId: Id): { get<K extends string>(key: K): JsonValue | undefined };\n\t/** Passive entry: queued when busy, appended when idle. Returns the input id. */\n\twrite(conversationId: Id, entry: NewEntry): Promise<Id>;\n\twrite<E extends Entry>(conversationId: Id, kind: EntryKind<E>, entry: EntryInput<E>): Promise<Id>;\n\tcreateTask<K extends AnyKind>(\n\t\tkind: K,\n\t\tinput: InputOf<K>,\n\t\topts?: { conversationId?: Id; background?: true; after?: Id[] },\n\t): TaskRef<K>;\n\tcreateConversation(spec: ConversationSpec): Id;\n}\n\n/** What the host gets. */\nexport interface HostTx extends SharedTx {\n\t/** Config through the facade; raw core fields are not exposed to the host tx. */\n\tconfig(conversationId: Id): {\n\t\tget<K extends string>(key: K): JsonValue | undefined;\n\t\tset(key: string, value: JsonValue): void;\n\t\treset(key: string): void;\n\t};\n}\n\n/** What an ordinary task gets: scoped shared operations plus its own checkpoint and slot. */\nexport interface TaskTx extends SharedTx {\n\tcheckpoint<C extends Checkpoint>(value: C): void;\n\tslot<K extends AnyKind>(ref: TaskRef<K>): SlotOf<K>;\n\t/** Create a conversation this task owns. `parent` must be in the task's subtree. */\n\tcreateConversation(spec: ConversationSpec): Id;\n}\n\n/** Internal full authority for the fixed turn machinery. Never handed to ordinary kinds or the host. */\nexport interface CoreTx extends TaskTx {\n\temit<T extends JsonObject>(namespace: Namespace<T>, name: string, data: JsonValue): void;\n\temit(event: ViewEvent): void;\n\trewindable(conversationId: Id): RewindableState;\n\tsticky(conversationId: Id): StickyState;\n\tsession(): SessionState;\n\ttoolSlot(task: { conversationId: Id; input: { index: number } }): ToolSlot;\n\tappendEntry(conversationId: Id, entry: NewEntry): Id;\n\tappendEntry<E extends Entry>(conversationId: Id, kind: EntryKind<E>, entry: EntryInput<E>): EntryRef<E>;\n\tcreateTask(spec: TaskSpec): Id;\n\tcreateTask<K extends AnyKind>(\n\t\tkind: K,\n\t\tinput: InputOf<K>,\n\t\topts?: { conversationId?: Id; background?: true; after?: Id[] },\n\t): TaskRef<K>;\n\tsend(conversationId: Id, input: SendInput): Promise<Id>;\n\tresolveInputs(\n\t\tids: readonly Id[],\n\t\tresolution:\n\t\t\t| { status: \"done\"; answer: Id }\n\t\t\t| { status: \"unanswered\"; reason: NonNullable<Input[\"reason\"]>; detail?: string },\n\t): Promise<void>;\n\t/** Inbox placement at a safe boundary. `headBoundary`: the newest head as the caller knows it (including a same-batch self-head it appended). */\n\tboundary(\n\t\tconversationId: Id,\n\t\tat: \"postTools\" | \"final\",\n\t\theadBoundary: Id | undefined,\n\t): Promise<{ triggers: Id[]; terminated: boolean }>;\n\t/** Internal owned-conversation path. Sanitizes caller overrides while preserving inherited rewindable namespace slices. */\n\tcreateOwnedConversation(ownerTaskId: Id, sourceConversationId: Id, spec: OwnedConversationSpec): Promise<Id>;\n\t/** Internal host-fork path for an already validated historical snapshot. */\n\tcreateForkConversation(spec: ConversationSpec): Id;\n\tmarkTask(id: Id): void;\n}\n\n/** Thrown when a scan-shaped read follows a same-batch write to its domain. Poisons the transaction. */\nexport class ReadAfterWrite extends Error {\n\tconstructor(read: string, write: string) {\n\t\tsuper(`${read} after ${write} in the same transaction: the answer would not include the buffered write`);\n\t\tthis.name = \"ReadAfterWrite\";\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Runtime: what a kind's handlers get. Every commit checks the invocation token.\n// ---------------------------------------------------------------------------\n\nexport interface RequestOptions {\n\tmessages: StoredMessage[];\n\tthinkingLevel: ThinkingLevel;\n}\nexport interface Models {\n\tresolve(ref: ModelRef): Model | undefined;\n\tstream(model: Model, request: RequestOptions, ctx: Context): AsyncIterable<AssistantMessageEvent>;\n\tfetchDeferred(\n\t\tmodel: Model,\n\t\thandle: DeferredHandle,\n\t\tctx: Context,\n\t): Promise<AssistantMessage | { deferred: DeferredHandle }>;\n\tcancelDeferred(model: Model, handle: DeferredHandle, ctx: Context): Promise<void>;\n}\n\nexport interface Runtime<H extends object = object, Tx extends TaskTx = TaskTx> {\n\treadonly taskId: Id;\n\treadonly conversationId: Id;\n\treadonly kind: AnyKind;\n\tcommit<T>(fn: (tx: Tx, current: Task, ctx: Context) => T | Promise<T>, ctx: Context): Promise<T>;\n\treadonly hooks: HookRunner<H>;\n\treadonly models: Models;\n\treadonly tools: ReadonlyMap<string, ToolDeclaration>;\n\treadonly registries: { sections: SectionRegistry; tools: ToolRegistry };\n\treadonly kinds: ReadonlyMap<string, AnyKind>;\n\treadonly processHost: ProcessHost | undefined;\n\treadonly plugins: ReadonlyMap<string, PluginHandler>;\n\tnow(): number;\n\tsleep(untilMs: number, ctx: Context): Promise<void>;\n\twaitForInput(id: Id, ctx: Context): Promise<Input>;\n\twaitForTask(id: Id, ctx: Context): Promise<Task>;\n\tabortTask(id: Id, ctx: Context): Promise<\"marked\" | \"terminal\">;\n\tabortConversation(id: Id, ctx: Context): Promise<void>;\n\tcreateOwnedConversation(spec: OwnedConversationSpec, ctx: Context): Promise<Id>;\n\t/** Admission for a conversation owned by this task; the runtime verifies ownership before invoking the kernel. */\n\tsendOwned(conversationId: Id, input: SendInput, ctx: Context): Promise<Id>;\n\t// off-line reads\n\tcontext(conversationId: Id, at: Id | undefined, ctx: Context): Promise<ContextView>;\n\tnewestEntry(\n\t\tconversationId: Id,\n\t\topts: { kind?: string; withHead?: boolean },\n\t\tctx: Context,\n\t): Promise<Entry | undefined>;\n\trewindable(conversationId: Id, ctx: Context): Promise<RewindableState>;\n\tsticky(conversationId: Id, ctx: Context): Promise<StickyState>;\n\trewindableAsOf(conversationId: Id, at: Id, ctx: Context): Promise<RewindableState | undefined>;\n}\n\n// ---------------------------------------------------------------------------\n// Tools\n// ---------------------------------------------------------------------------\n\nexport type ToolControl = { terminate?: true; handoff?: string; addTools?: string[] };\nexport interface ToolDiagnostic {\n\tseverity: \"info\" | \"warn\" | \"error\";\n\tmessage: string;\n\tcode?: string;\n}\nexport interface ToolResult {\n\t/** Omit when the tool streamed through `api.stream`: the bounded stream is the content. */\n\tcontent?: (TextContent | ImageContent)[];\n\tisError?: boolean;\n\tdetails?: JsonValue;\n\tdiagnostics?: ToolDiagnostic[];\n\tcontrol?: ToolControl;\n}\nexport interface ToolDeclaration<P extends TSchema = TSchema> {\n\treadonly name: string;\n\treadonly description: string;\n\treadonly parameters: P;\n\treadonly replay?: \"safe\" | \"unsafe\"; // default unsafe\n\treadonly output?: { maxBytes?: number; maxLines?: number; retain?: \"head\" | \"tail\" };\n\texecute(args: Static<P>, api: ToolApi, ctx: Context): Promise<ToolResult>;\n}\n/** Erased declaration held by the registry. */\nexport type AnyToolDeclaration = ToolDeclaration<TSchema>;\n\n/** The narrow handle a task gets to a conversation it owns. */\nexport interface OwnedConversation {\n\treadonly id: Id;\n\tsend(\n\t\tinput: SendInput,\n\t\tctx: Context,\n\t): Promise<{ id: Id; wait(ctx: Context): Promise<Input>; result(ctx: Context): Promise<Input | undefined> }>;\n\tabort(ctx: Context): Promise<void>;\n}\n\nexport interface BeforeToolApi extends HookApi {\n\treadonly callId: string;\n\twaiting(ctx: Context): Promise<void>;\n\tmemo<T extends JsonValue>(name: string, candidate: T, ctx: Context): Promise<T>;\n\tmemo<T extends JsonValue>(name: string, ctx: Context): Promise<T | undefined>;\n\temit(name: string, data: JsonValue, ctx: Context): Promise<void>;\n}\n\nexport interface ToolApi {\n\treadonly taskId: Id;\n\treadonly conversationId: Id;\n\treadonly callId: string;\n\t/** Pipe raw output here. The kernel bounds it per the declaration, flushes it on a throttle, and uses it as the result content unless the tool returns its own. Synchronous. */\n\tstream(chunk: string | Uint8Array): void;\n\t/** Mutate the live slot's free fields (`progress`, `details`, `continuedBy`). Identity fields are protected. */\n\tprogress(\n\t\tupdate: (slot: Pick<ToolSlot, \"progress\" | \"details\" | \"continuedBy\">) => void,\n\t\tctx: Context,\n\t): Promise<void>;\n\tmemo<T extends JsonValue>(name: string, candidate: T, ctx: Context): Promise<T>;\n\tmemo<T extends JsonValue>(name: string, ctx: Context): Promise<T | undefined>;\n\tconversation(spec: OwnedConversationSpec, ctx: Context): Promise<OwnedConversation>;\n\ttask<K extends AnyKind>(\n\t\tkind: K,\n\t\tinput: InputOf<K>,\n\t\topts: { background?: true; after?: Id[] },\n\t\tctx: Context,\n\t): Promise<TaskRef<K>>;\n\tgetTask<K extends AnyKind>(ref: TaskRef<K>, ctx: Context): Promise<TaskOf<K> | undefined>;\n\twaitForTask<K extends AnyKind>(ref: TaskRef<K>, ctx: Context): Promise<TaskOf<K>>;\n\t/** Snapshot of another task's live slot (in this task's conversation or subtree). */\n\tslot<K extends AnyKind>(ref: TaskRef<K>, ctx: Context): Promise<SlotOf<K> | undefined>;\n}\n\nexport interface ProcessSpec {\n\tcommand: string;\n\targs: string[];\n\tcwd: string;\n\tenv?: { [key: string]: string };\n}\nexport type ProcessStatus =\n\t| { status: \"running\"; stdout: string; stderr: string; droppedStdout: number; droppedStderr: number }\n\t| {\n\t\t\tstatus: \"exited\";\n\t\t\texitCode: number;\n\t\t\tstdout: string;\n\t\t\tstderr: string;\n\t\t\tdroppedStdout: number;\n\t\t\tdroppedStderr: number;\n\t }\n\t| { status: \"unknown\" };\nexport interface ProcessHost {\n\tstart(key: string, spec: ProcessSpec, ctx: Context): Promise<void>;\n\tstatus(key: string, ctx: Context): Promise<ProcessStatus>;\n\tkill(key: string, signal: \"SIGTERM\" | \"SIGKILL\", ctx: Context): Promise<void>;\n}\n\nexport type PluginHandler = (input: JsonValue, api: ToolApi, ctx: Context) => Promise<JsonValue>;\n\n// ---------------------------------------------------------------------------\n// Invocation tokens and invokers\n// ---------------------------------------------------------------------------\n\n/** An unforgeable capability: only the scheduler creates these, one per invocation. */\nexport class InvocationToken {\n\t#alive = true;\n\treadonly taskId: Id;\n\treadonly mode: \"run\" | \"abort\";\n\tconstructor(taskId: Id, mode: \"run\" | \"abort\") {\n\t\tthis.taskId = taskId;\n\t\tthis.mode = mode;\n\t}\n\tget alive() {\n\t\treturn this.#alive;\n\t}\n\t/** Called by the scheduler when the invocation returns. */\n\trevoke() {\n\t\tthis.#alive = false;\n\t}\n}\n\nexport type Invoker =\n\t| { readonly type: \"host\"; readonly conversationId?: Id }\n\t/** Harness internals acting with core authority (send, reset, abort, retire). Never exported. */\n\t| { readonly type: \"kernel\"; readonly conversationId?: Id }\n\t| {\n\t\t\treadonly type: \"task\";\n\t\t\treadonly token: InvocationToken;\n\t\t\treadonly id: Id;\n\t\t\treadonly conversationId: Id;\n\t\t\treadonly kind: AnyKind;\n\t\t\treadonly core: boolean;\n\t\t\treadonly mode: \"run\" | \"abort\";\n\t };\n\n// ---------------------------------------------------------------------------\n// Errors\n// ---------------------------------------------------------------------------\n\nexport class Forbidden extends Error {\n\tconstructor(what: string) {\n\t\tsuper(`forbidden: ${what}`);\n\t\tthis.name = \"Forbidden\";\n\t}\n}\nexport class ConversationBusy extends Error {\n\tconstructor(id: Id) {\n\t\tsuper(`conversation ${id} is busy`);\n\t\tthis.name = \"ConversationBusy\";\n\t}\n}\nexport class GenerationInProgress extends Error {\n\tconstructor(id: Id) {\n\t\tsuper(`conversation ${id} already has a live generation`);\n\t\tthis.name = \"GenerationInProgress\";\n\t}\n}\nexport class CollapseInProgress extends Error {\n\tconstructor(id: Id) {\n\t\tsuper(`conversation ${id} already has a live collapse`);\n\t\tthis.name = \"CollapseInProgress\";\n\t}\n}\nexport class Faulted extends Error {\n\tconstructor(cause: unknown) {\n\t\tsuper(`Session faulted: ${String(cause)}`);\n\t\tthis.name = \"Faulted\";\n\t}\n}\nexport class Closed extends Error {\n\tconstructor() {\n\t\tsuper(\"Session is closed\");\n\t\tthis.name = \"Closed\";\n\t}\n}\nexport class TaskContractFault extends Error {\n\tconstructor(kind: string, what: string) {\n\t\tsuper(`kind ${kind} broke its contract: ${what}`);\n\t\tthis.name = \"TaskContractFault\";\n\t}\n}\n\nexport type { ToolCall, ToolResultMessage, AssistantMessage, UserMessage, DeferredHandle, ThinkingLevel };\nexport type RequestMessage = StoredMessage;\n"]}
@@ -0,0 +1,34 @@
1
+ import type { CommitResult, Session } from "./session.ts";
2
+ import type { Conversation, ConversationView, Envelope } from "./types.ts";
3
+ export declare const WATCH_CAPACITY = 256;
4
+ export interface Watch {
5
+ readonly view: ConversationView;
6
+ readonly revision: number;
7
+ readonly closed: boolean;
8
+ start(listener: (envelope: Envelope) => void): void;
9
+ stop(): void;
10
+ }
11
+ export declare function applyEnvelope(view: ConversationView, envelope: Envelope): ConversationView;
12
+ export declare class ViewManager {
13
+ private readonly records;
14
+ private readonly deliveries;
15
+ private readonly session;
16
+ private readonly onReport;
17
+ constructor(session: Session, onReport: (error: unknown) => void);
18
+ watch(conversation: Conversation, entries: EntryList): Watch;
19
+ /** Runs on the Session line after persistence and in-memory indexes update. */
20
+ update(result: CommitResult<unknown>): void;
21
+ /** Runs after the Session line; listeners are synchronous and ordered. */
22
+ deliver(): void;
23
+ close(): void;
24
+ private build;
25
+ private document;
26
+ private config;
27
+ private turn;
28
+ private compaction;
29
+ private tasks;
30
+ private plugins;
31
+ }
32
+ type EntryList = ConversationView["entries"];
33
+ export {};
34
+ //# sourceMappingURL=view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../../src/harness/pico3/view.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,EAEX,YAAY,EACZ,gBAAgB,EAEhB,QAAQ,EAWR,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC,MAAM,WAAW,KAAK;IACrB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,GAAG,IAAI,CAAC;IACpD,IAAI,IAAI,IAAI,CAAC;CACb;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,GAAG,gBAAgB,CAE1F;AAWD,qBAAa,WAAW;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkB;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA2B;IAEpD,YAAY,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,EAG/D;IAED,KAAK,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,GAAG,KAAK,CAe3D;IAED,+EAA+E;IAC/E,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI,CA4D1C;IAED,0EAA0E;IAC1E,OAAO,IAAI,IAAI,CAId;IAED,KAAK,IAAI,IAAI,CAKZ;IAED,OAAO,CAAC,KAAK;IAiBb,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,MAAM;IAUd,OAAO,CAAC,IAAI;IAmBZ,OAAO,CAAC,UAAU;IAoBlB,OAAO,CAAC,KAAK;IAsBb,OAAO,CAAC,OAAO;CAiBf;AAED,KAAK,SAAS,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC","sourcesContent":["import { applyImmutable, type Op, type Tracker, track } from \"@earendil-works/chord/delta\";\nimport type { CommitResult, Session } from \"./session.ts\";\nimport type {\n\tAnyKind,\n\tConversation,\n\tConversationView,\n\tDocRef,\n\tEnvelope,\n\tGenerationStatus,\n\tId,\n\tJsonObject,\n\tJsonValue,\n\tRewindableState,\n\tStickyState,\n\tTask,\n\tToolSlot,\n\tTurnView,\n\tViewEvent,\n} from \"./types.ts\";\n\nexport const WATCH_CAPACITY = 256;\n\nexport interface Watch {\n\treadonly view: ConversationView;\n\treadonly revision: number;\n\treadonly closed: boolean;\n\tstart(listener: (envelope: Envelope) => void): void;\n\tstop(): void;\n}\n\nexport function applyEnvelope(view: ConversationView, envelope: Envelope): ConversationView {\n\treturn applyImmutable(view, envelope.ops) as ConversationView;\n}\n\ntype Listener = (envelope: Envelope) => void;\ntype ViewRecord = {\n\treadonly conversationId: Id;\n\treadonly tracker: Tracker<ConversationView>;\n\treadonly watchers: Set<WatchImpl>;\n\trevision: number;\n};\ntype Delivery = { envelope: Envelope; watchers: WatchImpl[] };\n\nexport class ViewManager {\n\tprivate readonly records = new Map<Id, ViewRecord>();\n\tprivate readonly deliveries: Delivery[] = [];\n\tprivate readonly session: Session;\n\tprivate readonly onReport: (error: unknown) => void;\n\n\tconstructor(session: Session, onReport: (error: unknown) => void) {\n\t\tthis.session = session;\n\t\tthis.onReport = onReport;\n\t}\n\n\twatch(conversation: Conversation, entries: EntryList): Watch {\n\t\tlet record = this.records.get(conversation.id);\n\t\tif (record === undefined) {\n\t\t\tconst tracker = track(this.build(conversation, entries));\n\t\t\ttracker.flush();\n\t\t\trecord = { conversationId: conversation.id, tracker, watchers: new Set(), revision: 0 };\n\t\t\tthis.records.set(conversation.id, record);\n\t\t}\n\t\tconst watcher = new WatchImpl(structuredClone(record.tracker.target), record.revision, this.onReport, () => {\n\t\t\trecord!.watchers.delete(watcher);\n\t\t\tif (record!.watchers.size === 0 && this.records.get(conversation.id) === record)\n\t\t\t\tthis.records.delete(conversation.id);\n\t\t});\n\t\trecord.watchers.add(watcher);\n\t\treturn watcher;\n\t}\n\n\t/** Runs on the Session line after persistence and in-memory indexes update. */\n\tupdate(result: CommitResult<unknown>): void {\n\t\tfor (const record of [...this.records.values()]) {\n\t\t\tconst conversation = this.session.conversationRecords.get(record.conversationId);\n\t\t\tif (conversation === undefined) continue;\n\t\t\ttry {\n\t\t\t\tconst changes = result.changes;\n\t\t\t\tconst appended = changes.entries.filter((entry) => entry.conversationId === record.conversationId);\n\t\t\t\tconst documentChanges = changes.docs.filter(\n\t\t\t\t\t(change) => change.ref.doc === \"session\" || change.ref.conversationId === record.conversationId,\n\t\t\t\t);\n\t\t\t\tconst taskChanged = changes.tasks.some((task) => task.conversationId === record.conversationId);\n\t\t\t\tconst events = changes.events\n\t\t\t\t\t.filter((scoped) => scoped.conversationId === record.conversationId)\n\t\t\t\t\t.map((scoped) => scoped.event);\n\t\t\t\tif (appended.length === 0 && documentChanges.length === 0 && !taskChanged && events.length === 0) continue;\n\n\t\t\t\tconst entryOps = applyEntries(record.tracker, appended);\n\t\t\t\tconst state = record.tracker.state;\n\t\t\t\tconst rewindableChanged = documentChanges.some(\n\t\t\t\t\t(change) => change.ref.doc === \"rewindable\" && change.ref.conversationId === record.conversationId,\n\t\t\t\t);\n\t\t\t\tconst stickyChanged = documentChanges.some(\n\t\t\t\t\t(change) => change.ref.doc === \"sticky\" && change.ref.conversationId === record.conversationId,\n\t\t\t\t);\n\t\t\t\tconst configChanged = events.some((event) => event.type === \"config.changed\");\n\t\t\t\tconst pluginChanged = documentChanges.some((change) => touchesKey(change.ops, \"plugins\"));\n\t\t\t\tconst rewindable =\n\t\t\t\t\trewindableChanged || configChanged || pluginChanged\n\t\t\t\t\t\t? this.document<RewindableState>({ doc: \"rewindable\", conversationId: record.conversationId })\n\t\t\t\t\t\t: undefined;\n\t\t\t\tconst sticky =\n\t\t\t\t\tstickyChanged || taskChanged || configChanged || pluginChanged\n\t\t\t\t\t\t? this.document<StickyState>({ doc: \"sticky\", conversationId: record.conversationId })\n\t\t\t\t\t\t: undefined;\n\n\t\t\t\tif (configChanged) syncRecord(state.config, this.config(rewindable!, sticky!));\n\t\t\t\tif (stickyChanged) syncArray(state.inbox, structuredClone(sticky!.inbox));\n\t\t\t\tif (stickyChanged || taskChanged) {\n\t\t\t\t\tsyncOptional(state, \"turn\", this.turn(record.conversationId, sticky!).turn);\n\t\t\t\t\tsyncOptional(state, \"compaction\", this.compaction(record.conversationId).compaction);\n\t\t\t\t\tsyncRecord(state.tasks, this.tasks(record.conversationId, sticky!));\n\t\t\t\t}\n\t\t\t\tif (pluginChanged) {\n\t\t\t\t\tconst session = this.document<JsonObject>({ doc: \"session\" });\n\t\t\t\t\tsyncRecord(state.plugins, this.plugins(rewindable!, sticky!, session));\n\t\t\t\t}\n\n\t\t\t\tconst ops = [...entryOps, ...record.tracker.flush()];\n\t\t\t\tif (ops.length === 0 && events.length === 0) continue;\n\t\t\t\tconst envelope = Object.freeze({\n\t\t\t\t\trevision: ++record.revision,\n\t\t\t\t\tops: Object.freeze(ops) as unknown as Op[],\n\t\t\t\t\tevents: Object.freeze(events) as unknown as ViewEvent[],\n\t\t\t\t}) satisfies Envelope;\n\t\t\t\tthis.deliveries.push({ envelope, watchers: [...record.watchers] });\n\t\t\t} catch (error) {\n\t\t\t\tthis.records.delete(record.conversationId);\n\t\t\t\tfor (const watcher of [...record.watchers]) watcher.fail(error);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Runs after the Session line; listeners are synchronous and ordered. */\n\tdeliver(): void {\n\t\tfor (const delivery of this.deliveries.splice(0)) {\n\t\t\tfor (const watcher of delivery.watchers) watcher.accept(delivery.envelope);\n\t\t}\n\t}\n\n\tclose(): void {\n\t\tconst records = [...this.records.values()];\n\t\tthis.records.clear();\n\t\tthis.deliveries.length = 0;\n\t\tfor (const record of records) for (const watcher of [...record.watchers]) watcher.stop();\n\t}\n\n\tprivate build(conversation: Conversation, entries: EntryList): ConversationView {\n\t\tconst rewindable = this.document<RewindableState>({ doc: \"rewindable\", conversationId: conversation.id });\n\t\tconst sticky = this.document<StickyState>({ doc: \"sticky\", conversationId: conversation.id });\n\t\tconst session = this.document<JsonObject>({ doc: \"session\" });\n\t\tconst { sections: _sections, ...publicConversation } = conversation;\n\t\treturn {\n\t\t\tconversation: structuredClone(publicConversation),\n\t\t\tentries: structuredClone(entries),\n\t\t\tconfig: this.config(rewindable, sticky),\n\t\t\tinbox: structuredClone(sticky.inbox),\n\t\t\t...this.turn(conversation.id, sticky),\n\t\t\t...this.compaction(conversation.id),\n\t\t\ttasks: this.tasks(conversation.id, sticky),\n\t\t\tplugins: this.plugins(rewindable, sticky, session),\n\t\t};\n\t}\n\n\tprivate document<T>(ref: DocRef): T {\n\t\tconst value = this.session.loadedDocument(ref);\n\t\tif (value === undefined) throw new Error(`view document ${ref.doc} is not loaded`);\n\t\treturn value as T;\n\t}\n\n\tprivate config(rewindable: RewindableState, sticky: StickyState): ConversationView[\"config\"] {\n\t\tconst out: ConversationView[\"config\"] = {};\n\t\tfor (const [key, doc] of this.session.defaults.route) {\n\t\t\tconst source = doc === \"rewindable\" ? rewindable : sticky;\n\t\t\tconst value = key in source ? source[key] : this.session.defaults[doc][key];\n\t\t\tif (value !== undefined) out[key] = structuredClone(value);\n\t\t}\n\t\treturn out;\n\t}\n\n\tprivate turn(conversationId: Id, sticky: StickyState): { turn?: TurnView } {\n\t\tconst live = [...this.session.liveTasks.values()].filter((task) => task.conversationId === conversationId);\n\t\tconst turnTasks = live.filter((task) => this.session.kinds.get(task.kind)?.turn === true);\n\t\tif (turnTasks.length === 0) return {};\n\t\tconst generation = turnTasks.find((task) => task.kind === \"pi.generation\");\n\t\tconst postTools = turnTasks.find((task) => task.kind === \"pi.post_tools\");\n\t\tconst inputTask = generation ?? postTools;\n\t\tconst inputs = inputTask === undefined ? [] : inputIds(inputTask);\n\t\tconst turn: TurnView = {\n\t\t\tinputs,\n\t\t\t...(generation === undefined\n\t\t\t\t? {}\n\t\t\t\t: { generation: generationStatus(generation, sticky.turn.message !== undefined) }),\n\t\t\t...(sticky.turn.message === undefined ? {} : { message: structuredClone(sticky.turn.message) }),\n\t\t\ttools: sticky.turn.tools.map(stripPrivateToolState),\n\t\t};\n\t\treturn { turn };\n\t}\n\n\tprivate compaction(conversationId: Id): { compaction?: ConversationView[\"compaction\"] } {\n\t\tconst task = [...this.session.liveTasks.values()].find(\n\t\t\t(candidate) => candidate.conversationId === conversationId && candidate.kind === \"pi.collapse\",\n\t\t);\n\t\tif (task === undefined) return {};\n\t\tconst input = task.input as { reason: \"threshold\" | \"manual\" | \"overflow\" };\n\t\tconst checkpoint = task.checkpoint as { phase?: string; attempt?: number; untilMs?: number } | undefined;\n\t\treturn {\n\t\t\tcompaction: {\n\t\t\t\ttaskId: task.id,\n\t\t\t\treason: input.reason,\n\t\t\t\tstage: checkpoint?.phase === \"retrying\" ? \"retrying\" : \"summarizing\",\n\t\t\t\tattempt: checkpoint?.attempt ?? 1,\n\t\t\t\t...(checkpoint?.phase === \"retrying\" && checkpoint.untilMs !== undefined\n\t\t\t\t\t? { retryAt: checkpoint.untilMs }\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate tasks(conversationId: Id, sticky: StickyState): ConversationView[\"tasks\"] {\n\t\tconst out: ConversationView[\"tasks\"] = {};\n\t\tfor (const task of this.session.liveTasks.values()) {\n\t\t\tconst kind = this.session.kinds.get(task.kind);\n\t\t\tif (\n\t\t\t\ttask.conversationId !== conversationId ||\n\t\t\t\tkind === undefined ||\n\t\t\t\tkind.turn === true ||\n\t\t\t\ttask.kind === \"pi.collapse\"\n\t\t\t)\n\t\t\t\tcontinue;\n\t\t\tconst slot = sticky.tasks[task.id];\n\t\t\tout[task.id] = {\n\t\t\t\tkind: task.kind,\n\t\t\t\t...(task.background ? { background: true as const } : {}),\n\t\t\t\t...(task.abort ? { marked: true as const } : {}),\n\t\t\t\tstatus: describe(kind, task, slot),\n\t\t\t};\n\t\t}\n\t\treturn out;\n\t}\n\n\tprivate plugins(rewindable: RewindableState, sticky: StickyState, session: JsonObject): ConversationView[\"plugins\"] {\n\t\tconst out: ConversationView[\"plugins\"] = {};\n\t\tconst sessionPlugins = (session.plugins ?? {}) as { [key: string]: JsonObject };\n\t\tfor (const [id, registration] of this.session.namespaces) {\n\t\t\tif (registration.project === undefined) continue;\n\t\t\tconst merged: JsonObject = {\n\t\t\t\t...registration.defaults.rewindable,\n\t\t\t\t...registration.defaults.sticky,\n\t\t\t\t...registration.defaults.session,\n\t\t\t\t...(rewindable.plugins[id] ?? {}),\n\t\t\t\t...(sticky.plugins[id] ?? {}),\n\t\t\t\t...(sessionPlugins[id] ?? {}),\n\t\t\t};\n\t\t\tout[id] = strictJson(registration.project(structuredClone(merged)), `namespace ${id} view`);\n\t\t}\n\t\treturn out;\n\t}\n}\n\ntype EntryList = ConversationView[\"entries\"];\n\nclass WatchImpl implements Watch {\n\treadonly view: ConversationView;\n\tprivate readonly initialRevision: number;\n\tprivate readonly onReport: (error: unknown) => void;\n\tprivate readonly onStop: () => void;\n\tprivate listener: Listener | undefined;\n\tprivate readonly buffer: Envelope[] = [];\n\tprivate stopped = false;\n\n\tconstructor(view: ConversationView, revision: number, onReport: (error: unknown) => void, onStop: () => void) {\n\t\tthis.view = view;\n\t\tthis.initialRevision = revision;\n\t\tthis.onReport = onReport;\n\t\tthis.onStop = onStop;\n\t}\n\n\tget revision(): number {\n\t\treturn this.initialRevision;\n\t}\n\tget closed(): boolean {\n\t\treturn this.stopped;\n\t}\n\n\tstart(listener: Listener): void {\n\t\tif (this.listener !== undefined || this.stopped) return;\n\t\tthis.listener = listener;\n\t\tfor (const envelope of this.buffer.splice(0)) {\n\t\t\tif (this.stopped) break;\n\t\t\tthis.deliver(envelope);\n\t\t}\n\t}\n\n\tstop(): void {\n\t\tif (this.stopped) return;\n\t\tthis.stopped = true;\n\t\tthis.buffer.length = 0;\n\t\tthis.onStop();\n\t}\n\n\taccept(envelope: Envelope): void {\n\t\tif (this.stopped) return;\n\t\tif (this.listener === undefined) {\n\t\t\tif (this.buffer.length >= WATCH_CAPACITY) {\n\t\t\t\tthis.stop();\n\t\t\t\tthis.report(new Error(`watch capacity ${WATCH_CAPACITY} exceeded before start()`));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.buffer.push(envelope);\n\t\t\treturn;\n\t\t}\n\t\tthis.deliver(envelope);\n\t}\n\n\tprivate deliver(envelope: Envelope): void {\n\t\ttry {\n\t\t\tthis.listener!(envelope);\n\t\t} catch (error) {\n\t\t\tthis.fail(error);\n\t\t}\n\t}\n\n\tfail(error: unknown): void {\n\t\tthis.stop();\n\t\tthis.report(error);\n\t}\n\n\tprivate report(error: unknown): void {\n\t\ttry {\n\t\t\tthis.onReport(error);\n\t\t} catch {}\n\t}\n}\n\nfunction applyEntries(tracker: Tracker<ConversationView>, appended: EntryList): Op[] {\n\tconst ops: Op[] = [];\n\tconst entries = tracker.state.entries;\n\tfor (const entry of appended) {\n\t\tif (entry.head !== undefined) {\n\t\t\tconst retained = entries.findIndex((candidate) => candidate.id >= entry.head!);\n\t\t\tconst remove = retained < 0 ? entries.length : retained;\n\t\t\tif (remove > 0) {\n\t\t\t\tops.push(...tracker.flush());\n\t\t\t\tentries.splice(0, remove);\n\t\t\t\ttracker.flush();\n\t\t\t\tops.push([\"p\", [\"entries\"], 0, remove, []]);\n\t\t\t}\n\t\t}\n\t\tentries.push(structuredClone(entry));\n\t}\n\treturn ops;\n}\n\nfunction inputIds(task: Task): Id[] {\n\tconst inputs = (task.input as { inputs?: JsonValue }).inputs;\n\treturn Array.isArray(inputs) ? inputs.filter((value): value is Id => typeof value === \"number\") : [];\n}\n\nfunction generationStatus(task: Task, streaming: boolean): GenerationStatus {\n\tif (task.status === \"pending\" && task.after.length > 0) return { stage: \"waiting\", on: \"compaction\" };\n\tconst checkpoint = task.checkpoint as\n\t\t| {\n\t\t\t\tphase?: string;\n\t\t\t\tattempt?: number;\n\t\t\t\tuntilMs?: number;\n\t\t\t\tlastError?: string;\n\t\t\t\tpollAt?: number;\n\t\t }\n\t\t| undefined;\n\tif (checkpoint?.phase === \"requesting\")\n\t\treturn { stage: streaming ? \"streaming\" : \"requesting\", attempt: checkpoint.attempt ?? 1 };\n\tif (checkpoint?.phase === \"retrying\")\n\t\treturn {\n\t\t\tstage: \"retrying\",\n\t\t\tattempt: checkpoint.attempt ?? 1,\n\t\t\tretryAt: checkpoint.untilMs ?? 0,\n\t\t\tlastError: checkpoint.lastError ?? \"\",\n\t\t};\n\tif (checkpoint?.phase === \"deferred\")\n\t\treturn { stage: \"deferred\", attempt: checkpoint.attempt ?? 1, pollAt: checkpoint.pollAt ?? 0 };\n\treturn { stage: \"preparing\" };\n}\n\nfunction stripPrivateToolState(slot: ToolSlot): Omit<ToolSlot, \"memos\"> {\n\tconst { memos: _memos, ...view } = structuredClone(slot);\n\treturn view;\n}\n\nfunction describe(kind: AnyKind, task: Task, slot: JsonObject | undefined): JsonValue {\n\tif (typeof kind.describe !== \"function\")\n\t\treturn { phase: task.checkpoint?.phase ?? (task.status === \"pending\" ? \"pending\" : \"running\") };\n\tconst publicSlot = slot === undefined ? undefined : structuredClone(slot);\n\tif (publicSlot !== undefined) delete publicSlot.memos;\n\tconst value = (kind.describe as (task: Task & { readonly slot?: Readonly<JsonObject> }) => JsonValue)({\n\t\t...task,\n\t\t...(publicSlot === undefined ? {} : { slot: publicSlot }),\n\t});\n\treturn strictJson(value, `task kind ${task.kind} describe`);\n}\n\nfunction strictJson(value: JsonValue, what: string): JsonValue {\n\tconst encoded = JSON.stringify(value);\n\tif (encoded === undefined) throw new Error(`${what} returned a non-JSON value`);\n\treturn JSON.parse(encoded) as JsonValue;\n}\n\nfunction touchesKey(ops: readonly Op[], key: string): boolean {\n\treturn ops.some((op) => op[0] === \"r\" || op[1][0] === key);\n}\n\nfunction syncOptional(target: object, key: string, next: unknown): void {\n\tconst record = target as Record<string, unknown>;\n\tif (next === undefined) {\n\t\tdelete record[key];\n\t\treturn;\n\t}\n\tconst current = record[key];\n\tif (same(current, next)) return;\n\tif (isRecord(current) && isRecord(next)) syncRecord(current, next);\n\telse record[key] = structuredClone(next);\n}\n\nfunction syncRecord(target: Record<string, unknown>, next: Record<string, unknown>): void {\n\tfor (const key of Object.keys(target)) if (!(key in next)) delete target[key];\n\tfor (const [key, value] of Object.entries(next)) {\n\t\tconst current = target[key];\n\t\tif (same(current, value)) continue;\n\t\tif (Array.isArray(current) && Array.isArray(value)) {\n\t\t\tsyncArray(current, value);\n\t\t\tcontinue;\n\t\t}\n\t\tif (isRecord(current) && isRecord(value)) {\n\t\t\tsyncRecord(current, value);\n\t\t\tcontinue;\n\t\t}\n\t\ttarget[key] = structuredClone(value);\n\t}\n}\n\nfunction syncArray(target: unknown[], next: unknown[]): void {\n\tlet prefix = 0;\n\twhile (prefix < target.length && prefix < next.length) {\n\t\tif (same(target[prefix], next[prefix])) {\n\t\t\tprefix++;\n\t\t\tcontinue;\n\t\t}\n\t\tconst current = target[prefix];\n\t\tconst replacement = next[prefix];\n\t\tif (!isRecord(current) || !isRecord(replacement) || !sameArrayItem(current, replacement)) break;\n\t\tsyncRecord(current, replacement);\n\t\tprefix++;\n\t}\n\tif (prefix === target.length && prefix === next.length) return;\n\tif (prefix === target.length) {\n\t\ttarget.push(...structuredClone(next.slice(prefix)));\n\t\treturn;\n\t}\n\ttarget.splice(prefix, target.length - prefix, ...structuredClone(next.slice(prefix)));\n}\n\nfunction sameArrayItem(current: Record<string, unknown>, next: Record<string, unknown>): boolean {\n\tif (typeof current.id === \"number\" || typeof next.id === \"number\") return current.id === next.id;\n\tif (typeof current.callId === \"string\" || typeof next.callId === \"string\") return current.callId === next.callId;\n\tif (typeof current.type === \"string\" || typeof next.type === \"string\") return current.type === next.type;\n\treturn false;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction same(a: unknown, b: unknown): boolean {\n\tif (Object.is(a, b)) return true;\n\treturn JSON.stringify(a) === JSON.stringify(b);\n}\n"]}