@earendil-works/pi-durable 1.4.0 → 1.5.1

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 (270) hide show
  1. package/CHANGELOG.md +204 -0
  2. package/README.md +195 -85
  3. package/dist/codemode/codemode.d.ts +6 -5
  4. package/dist/codemode/codemode.d.ts.map +1 -1
  5. package/dist/codemode/codemode.js +10 -49
  6. package/dist/codemode/codemode.js.map +1 -1
  7. package/dist/codemode/models.d.ts +2 -1
  8. package/dist/codemode/models.d.ts.map +1 -1
  9. package/dist/codemode/models.js +4 -4
  10. package/dist/codemode/models.js.map +1 -1
  11. package/dist/documents.d.ts +1 -1
  12. package/dist/documents.d.ts.map +1 -1
  13. package/dist/documents.js +1 -1
  14. package/dist/documents.js.map +1 -1
  15. package/dist/entries.d.ts +1 -1
  16. package/dist/entries.d.ts.map +1 -1
  17. package/dist/entries.js.map +1 -1
  18. package/dist/env/index.d.ts +13 -11
  19. package/dist/env/index.d.ts.map +1 -1
  20. package/dist/env/index.js.map +1 -1
  21. package/dist/env/node-watch.d.ts +4 -4
  22. package/dist/env/node-watch.d.ts.map +1 -1
  23. package/dist/env/node-watch.js +18 -16
  24. package/dist/env/node-watch.js.map +1 -1
  25. package/dist/env/node.d.ts +3 -3
  26. package/dist/env/node.d.ts.map +1 -1
  27. package/dist/env/node.js +1 -1
  28. package/dist/env/node.js.map +1 -1
  29. package/dist/errors.d.ts +18 -2
  30. package/dist/errors.d.ts.map +1 -1
  31. package/dist/errors.js +26 -3
  32. package/dist/errors.js.map +1 -1
  33. package/dist/harness/agent.d.ts.map +1 -1
  34. package/dist/harness/agent.js +37 -3
  35. package/dist/harness/agent.js.map +1 -1
  36. package/dist/harness/compaction.d.ts +8 -3
  37. package/dist/harness/compaction.d.ts.map +1 -1
  38. package/dist/harness/compaction.js +40 -11
  39. package/dist/harness/compaction.js.map +1 -1
  40. package/dist/harness/context.d.ts +24 -8
  41. package/dist/harness/context.d.ts.map +1 -1
  42. package/dist/harness/context.js +71 -25
  43. package/dist/harness/context.js.map +1 -1
  44. package/dist/harness/define.d.ts +8 -4
  45. package/dist/harness/define.d.ts.map +1 -1
  46. package/dist/harness/define.js +4 -0
  47. package/dist/harness/define.js.map +1 -1
  48. package/dist/harness/generation.d.ts +39 -6
  49. package/dist/harness/generation.d.ts.map +1 -1
  50. package/dist/harness/generation.js +451 -100
  51. package/dist/harness/generation.js.map +1 -1
  52. package/dist/harness/harness.d.ts +3 -1
  53. package/dist/harness/harness.d.ts.map +1 -1
  54. package/dist/harness/harness.js +87 -62
  55. package/dist/harness/harness.js.map +1 -1
  56. package/dist/harness/inbox.d.ts +7 -2
  57. package/dist/harness/inbox.d.ts.map +1 -1
  58. package/dist/harness/inbox.js +5 -2
  59. package/dist/harness/inbox.js.map +1 -1
  60. package/dist/harness/json.d.ts +21 -5
  61. package/dist/harness/json.d.ts.map +1 -1
  62. package/dist/harness/json.js +23 -5
  63. package/dist/harness/json.js.map +1 -1
  64. package/dist/harness/live.d.ts +124 -17
  65. package/dist/harness/live.d.ts.map +1 -1
  66. package/dist/harness/live.js +93 -12
  67. package/dist/harness/live.js.map +1 -1
  68. package/dist/harness/partial-changes.d.ts +54 -0
  69. package/dist/harness/partial-changes.d.ts.map +1 -0
  70. package/dist/harness/partial-changes.js +163 -0
  71. package/dist/harness/partial-changes.js.map +1 -0
  72. package/dist/harness/prompt.d.ts +1 -1
  73. package/dist/harness/prompt.d.ts.map +1 -1
  74. package/dist/harness/prompt.js.map +1 -1
  75. package/dist/harness/provider.d.ts +1 -1
  76. package/dist/harness/provider.d.ts.map +1 -1
  77. package/dist/harness/provider.js.map +1 -1
  78. package/dist/harness/registry-reader.d.ts +11 -0
  79. package/dist/harness/registry-reader.d.ts.map +1 -0
  80. package/dist/harness/registry-reader.js +25 -0
  81. package/dist/harness/registry-reader.js.map +1 -0
  82. package/dist/harness/scheduler.d.ts +48 -20
  83. package/dist/harness/scheduler.d.ts.map +1 -1
  84. package/dist/harness/scheduler.js +1006 -380
  85. package/dist/harness/scheduler.js.map +1 -1
  86. package/dist/harness/submissions.d.ts +18 -11
  87. package/dist/harness/submissions.d.ts.map +1 -1
  88. package/dist/harness/submissions.js +63 -26
  89. package/dist/harness/submissions.js.map +1 -1
  90. package/dist/harness/task-graph.d.ts +14 -9
  91. package/dist/harness/task-graph.d.ts.map +1 -1
  92. package/dist/harness/task-graph.js +38 -28
  93. package/dist/harness/task-graph.js.map +1 -1
  94. package/dist/harness/telemetry.d.ts +11 -11
  95. package/dist/harness/telemetry.d.ts.map +1 -1
  96. package/dist/harness/telemetry.js +7 -7
  97. package/dist/harness/telemetry.js.map +1 -1
  98. package/dist/harness/tool.d.ts +3 -1
  99. package/dist/harness/tool.d.ts.map +1 -1
  100. package/dist/harness/tool.js +172 -56
  101. package/dist/harness/tool.js.map +1 -1
  102. package/dist/harness/transcript.d.ts +72 -0
  103. package/dist/harness/transcript.d.ts.map +1 -0
  104. package/dist/harness/transcript.js +264 -0
  105. package/dist/harness/transcript.js.map +1 -0
  106. package/dist/harness/types.d.ts +237 -61
  107. package/dist/harness/types.d.ts.map +1 -1
  108. package/dist/harness/types.js.map +1 -1
  109. package/dist/harness/usage.d.ts +2 -1
  110. package/dist/harness/usage.d.ts.map +1 -1
  111. package/dist/harness/usage.js +1 -1
  112. package/dist/harness/usage.js.map +1 -1
  113. package/dist/harness/util.d.ts +4 -2
  114. package/dist/harness/util.d.ts.map +1 -1
  115. package/dist/harness/util.js +9 -0
  116. package/dist/harness/util.js.map +1 -1
  117. package/dist/harness/view.d.ts +44 -22
  118. package/dist/harness/view.d.ts.map +1 -1
  119. package/dist/harness/view.js +130 -71
  120. package/dist/harness/view.js.map +1 -1
  121. package/dist/index.d.ts +9 -7
  122. package/dist/index.d.ts.map +1 -1
  123. package/dist/index.js +4 -3
  124. package/dist/index.js.map +1 -1
  125. package/dist/search.d.ts +19 -3
  126. package/dist/search.d.ts.map +1 -1
  127. package/dist/search.js +107 -44
  128. package/dist/search.js.map +1 -1
  129. package/dist/session/cached-storage.d.ts +72 -0
  130. package/dist/session/cached-storage.d.ts.map +1 -0
  131. package/dist/session/cached-storage.js +269 -0
  132. package/dist/session/cached-storage.js.map +1 -0
  133. package/dist/session/conversation-tails.d.ts +33 -0
  134. package/dist/session/conversation-tails.d.ts.map +1 -0
  135. package/dist/session/conversation-tails.js +101 -0
  136. package/dist/session/conversation-tails.js.map +1 -0
  137. package/dist/session/forks.d.ts +1 -1
  138. package/dist/session/forks.d.ts.map +1 -1
  139. package/dist/session/forks.js.map +1 -1
  140. package/dist/session/keys.d.ts +69 -0
  141. package/dist/session/keys.d.ts.map +1 -0
  142. package/dist/session/keys.js +161 -0
  143. package/dist/session/keys.js.map +1 -0
  144. package/dist/session/session.d.ts +169 -26
  145. package/dist/session/session.d.ts.map +1 -1
  146. package/dist/session/session.js +1029 -171
  147. package/dist/session/session.js.map +1 -1
  148. package/dist/session/transaction.d.ts +84 -5
  149. package/dist/session/transaction.d.ts.map +1 -1
  150. package/dist/session/transaction.js +227 -40
  151. package/dist/session/transaction.js.map +1 -1
  152. package/dist/session/writer.d.ts +74 -0
  153. package/dist/session/writer.d.ts.map +1 -0
  154. package/dist/session/writer.js +294 -0
  155. package/dist/session/writer.js.map +1 -0
  156. package/dist/storage/indexeddb.d.ts +12 -3
  157. package/dist/storage/indexeddb.d.ts.map +1 -1
  158. package/dist/storage/indexeddb.js +91 -41
  159. package/dist/storage/indexeddb.js.map +1 -1
  160. package/dist/storage/jsonl/index.d.ts +1 -1
  161. package/dist/storage/jsonl/index.d.ts.map +1 -1
  162. package/dist/storage/jsonl/index.js +1 -1
  163. package/dist/storage/jsonl/index.js.map +1 -1
  164. package/dist/storage/jsonl/node.d.ts +3 -3
  165. package/dist/storage/jsonl/node.d.ts.map +1 -1
  166. package/dist/storage/jsonl/node.js +2 -2
  167. package/dist/storage/jsonl/node.js.map +1 -1
  168. package/dist/storage/jsonl/storage.d.ts +46 -5
  169. package/dist/storage/jsonl/storage.d.ts.map +1 -1
  170. package/dist/storage/jsonl/storage.js +158 -43
  171. package/dist/storage/jsonl/storage.js.map +1 -1
  172. package/dist/storage/memory.d.ts +9 -3
  173. package/dist/storage/memory.d.ts.map +1 -1
  174. package/dist/storage/memory.js +28 -2
  175. package/dist/storage/memory.js.map +1 -1
  176. package/dist/storage/sqlite/commit.d.ts +52 -0
  177. package/dist/storage/sqlite/commit.d.ts.map +1 -0
  178. package/dist/storage/sqlite/commit.js +371 -0
  179. package/dist/storage/sqlite/commit.js.map +1 -0
  180. package/dist/storage/sqlite/rows.d.ts +33 -0
  181. package/dist/storage/sqlite/rows.d.ts.map +1 -0
  182. package/dist/storage/sqlite/rows.js +53 -0
  183. package/dist/storage/sqlite/rows.js.map +1 -0
  184. package/dist/storage/sqlite/statements.d.ts +13 -0
  185. package/dist/storage/sqlite/statements.d.ts.map +1 -0
  186. package/dist/storage/sqlite/statements.js +88 -0
  187. package/dist/storage/sqlite/statements.js.map +1 -0
  188. package/dist/storage/sqlite/storage.d.ts +23 -10
  189. package/dist/storage/sqlite/storage.d.ts.map +1 -1
  190. package/dist/storage/sqlite/storage.js +120 -261
  191. package/dist/storage/sqlite/storage.js.map +1 -1
  192. package/dist/storage/store/commit.d.ts +33 -0
  193. package/dist/storage/store/commit.d.ts.map +1 -0
  194. package/dist/storage/store/commit.js +286 -0
  195. package/dist/storage/store/commit.js.map +1 -0
  196. package/dist/storage/store/documents.d.ts +43 -0
  197. package/dist/storage/store/documents.d.ts.map +1 -0
  198. package/dist/storage/store/documents.js +102 -0
  199. package/dist/storage/store/documents.js.map +1 -0
  200. package/dist/storage/store/index.d.ts +2 -0
  201. package/dist/storage/store/index.d.ts.map +1 -0
  202. package/dist/storage/store/index.js +2 -0
  203. package/dist/storage/store/index.js.map +1 -0
  204. package/dist/storage/store/queries.d.ts +49 -0
  205. package/dist/storage/store/queries.d.ts.map +1 -0
  206. package/dist/storage/store/queries.js +93 -0
  207. package/dist/storage/store/queries.js.map +1 -0
  208. package/dist/storage/store/storage.d.ts +60 -0
  209. package/dist/storage/store/storage.d.ts.map +1 -0
  210. package/dist/storage/store/storage.js +438 -0
  211. package/dist/storage/store/storage.js.map +1 -0
  212. package/dist/storage/store/tables.d.ts +54 -0
  213. package/dist/storage/store/tables.d.ts.map +1 -0
  214. package/dist/storage/store/tables.js +108 -0
  215. package/dist/storage/store/tables.js.map +1 -0
  216. package/dist/testing/commit-writes.d.ts +5 -0
  217. package/dist/testing/commit-writes.d.ts.map +1 -0
  218. package/dist/testing/commit-writes.js +12 -0
  219. package/dist/testing/commit-writes.js.map +1 -0
  220. package/dist/testing/env-conformance.js +7 -7
  221. package/dist/testing/env-conformance.js.map +1 -1
  222. package/dist/testing/index.d.ts +1 -0
  223. package/dist/testing/index.d.ts.map +1 -1
  224. package/dist/testing/index.js +1 -0
  225. package/dist/testing/index.js.map +1 -1
  226. package/dist/testing/storage-benchmark.d.ts.map +1 -1
  227. package/dist/testing/storage-benchmark.js +18 -17
  228. package/dist/testing/storage-benchmark.js.map +1 -1
  229. package/dist/testing/storage-conformance.d.ts.map +1 -1
  230. package/dist/testing/storage-conformance.js +354 -69
  231. package/dist/testing/storage-conformance.js.map +1 -1
  232. package/dist/tool-search/tool-search.d.ts +8 -14
  233. package/dist/tool-search/tool-search.d.ts.map +1 -1
  234. package/dist/tool-search/tool-search.js +25 -13
  235. package/dist/tool-search/tool-search.js.map +1 -1
  236. package/dist/tools/bash.d.ts +13 -13
  237. package/dist/tools/bash.d.ts.map +1 -1
  238. package/dist/tools/bash.js +16 -15
  239. package/dist/tools/bash.js.map +1 -1
  240. package/dist/tools/edit.d.ts +7 -7
  241. package/dist/tools/edit.d.ts.map +1 -1
  242. package/dist/tools/edit.js +9 -9
  243. package/dist/tools/edit.js.map +1 -1
  244. package/dist/tools/file-mutation-queue.d.ts +1 -1
  245. package/dist/tools/file-mutation-queue.d.ts.map +1 -1
  246. package/dist/tools/file-mutation-queue.js.map +1 -1
  247. package/dist/tools/index.d.ts +32 -32
  248. package/dist/tools/path-utils.d.ts +1 -1
  249. package/dist/tools/path-utils.d.ts.map +1 -1
  250. package/dist/tools/path-utils.js.map +1 -1
  251. package/dist/tools/read.d.ts +6 -6
  252. package/dist/tools/read.d.ts.map +1 -1
  253. package/dist/tools/read.js +19 -8
  254. package/dist/tools/read.js.map +1 -1
  255. package/dist/tools/write.d.ts +4 -4
  256. package/dist/tools/write.d.ts.map +1 -1
  257. package/dist/tools/write.js +5 -5
  258. package/dist/tools/write.js.map +1 -1
  259. package/dist/types.d.ts +228 -78
  260. package/dist/types.d.ts.map +1 -1
  261. package/dist/types.js.map +1 -1
  262. package/package.json +19 -12
  263. package/dist/harness/events.d.ts +0 -186
  264. package/dist/harness/events.d.ts.map +0 -1
  265. package/dist/harness/events.js +0 -373
  266. package/dist/harness/events.js.map +0 -1
  267. package/dist/session/observation.d.ts +0 -42
  268. package/dist/session/observation.d.ts.map +0 -1
  269. package/dist/session/observation.js +0 -281
  270. package/dist/session/observation.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/harness/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,QAAQ,EAAuD,MAAM,uBAAuB,CAAC;AACpH,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EACN,WAAW,EACX,YAAY,EAEZ,yBAAyB,EACzB,QAAQ,GAER,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO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,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,CAC7G,CAAC;IACH,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5B,OAAO,CACN,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,CAAE,EAAE,CAAC,CAAC,GAAG,CAAE,CAAC,CAAC,CAClH,CAAC;AACH,CAAC","sourcesContent":["import { type Context, copyJson, type Draft, type JsonRepresentation, type JsonValue } from \"@earendil-works/chord\";\nimport { awaitWithContext } from \"@earendil-works/chord/context\";\nimport { overlap } from \"@earendil-works/chord/delta\";\nimport {\n\tboundOutput,\n\tOutputBuffer,\n\ttype OutputLimits,\n\tPROGRESS_BYTES_PER_SECOND,\n\tProgress,\n\ttype ProgressClock,\n} from \"@earendil-works/chord/output\";\nimport type { ImageContent, TextContent, ToolCall, ToolResultMessage } from \"@earendil-works/pi-ai\";\nimport { validateToolArguments } from \"@earendil-works/pi-ai/utils/validation\";\nimport { Compile } from \"typebox/compile\";\nimport { defineDocFamily } from \"../documents.ts\";\nimport { AssistantEntry, ToolResultEntry } from \"../entries.ts\";\nimport type { ExecutionEnv } from \"../env/index.ts\";\nimport { errorMessage } from \"../errors.ts\";\nimport { defineTask } from \"../tasks.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, utf8ByteLength } from \"../truncate.ts\";\nimport type {\n\tConversationId,\n\tEntryId,\n\tJsonObject,\n\tTask,\n\tTaskId,\n\tTaskOptions,\n\tTaskOutcome,\n\tTaskRuntime,\n\tTx,\n\tTypedEntry,\n} from \"../types.ts\";\nimport { toolExtension } from \"./agent.ts\";\nimport { assignJson } from \"./json.ts\";\nimport {\n\tclearProgress,\n\tfinishSlot,\n\tLiveDoc,\n\ttype NestedToolSlot,\n\ttype NestedToolSummary,\n\tremoveNestedSlots,\n\ttype ToolSlot,\n\ttoolSlot,\n} from \"./live.ts\";\nimport type {\n\tNestedToolExecutionResult,\n\tToolControl,\n\tToolDiagnostic,\n\tToolExecutionApi,\n\tToolExecutionResult,\n\tToolHookCall,\n\tToolHooks,\n\tToolRegistration,\n} from \"./types.ts\";\nimport { recordUsage } from \"./usage.ts\";\nimport { optionalExtension } from \"./util.ts\";\n\n/**\n * A model-issued call, read from its assistant entry, or a nested call a running tool made through `executeTool()`,\n * whose call the input carries because no entry holds it.\n */\nexport type ToolTaskInput =\n\t| { kind: \"model\"; assistant: EntryId; callId: string }\n\t| {\n\t\t\tkind: \"nested\";\n\t\t\tparent: TaskId;\n\t\t\tparentCallId: string;\n\t\t\tkey: string;\n\t\t\tcall: ToolCall;\n\t\t\t/** `false`: commit no running output, details, or diagnostics to the slot; the result still gets them. */\n\t\t\tprogress?: false;\n\t };\n\nexport type ToolTaskCheckpoint =\n\t| { phase: \"call\" }\n\t/** Durable intent: the final arguments and the replay policy recorded before execution. */\n\t| { phase: \"execute\"; arguments: JsonObject; replay: \"safe\" | \"unsafe\" };\n\n/**\n * A model-issued call's result is its transcript entry; a nested call's result is in its caller's\n * `NestedCallDoc`, so the receipt stays small and the result retires with the caller. A version 1 task that was\n * already holding its outcome as `completing` when the Harness upgraded finishes with a version 1 result,\n * `{ entryId, control? }` without `kind`; treat a result without `kind` as a model-issued call's.\n */\nexport type ToolTaskResult = { kind: \"model\"; entryId: EntryId; control?: ToolControl } | { kind: \"nested\" };\n\n/**\n * Memo of a tool task that made a nested call, in any attempt, committed before the first admission of each attempt:\n * only then can `pi.live` hold slots below it, which settling removes. A crash between the two only costs a scan.\n */\nconst MADE_NESTED_CALLS = \"pi.tool.madeNestedCalls\";\n\n/** One nested call of a running tool: its task, and once it ended, its result. */\nexport type NestedCallState = {\n\t/** Absent only inside the commit that creates the call; a creation that fails leaves no member. */\n\ttaskId?: TaskId<ToolTaskResult>;\n\t/** Exactly what `executeTool()` returns; absent while running, and for a call the scheduler faulted or orphaned. */\n\tresult?: JsonRepresentation<NestedToolExecutionResult>;\n};\n\n/**\n * The nested calls of a tool call, a task-scoped family of the calling task keyed by the nested call's key: so a rerun\n * finds the calls it already made, and the caller reads each result. Created with the nested task; the nested call's\n * terminal commit adds its result. One document per call, so no commit rewrites the others. Retires with the caller.\n */\nexport const NestedCallDoc = defineDocFamily<NestedCallState, null>({\n\tkind: \"pi.tool.nested-call\",\n\tversion: 1,\n\tscope: \"task\",\n\tfamily: true,\n\tinitial: () => ({}),\n\t// The document retires with its task.\n\tcheckpointWhen: () => false,\n});\n\ntype Runtime = TaskRuntime<ToolTaskInput, ToolTaskCheckpoint, ToolTaskResult, ToolHooks>;\ntype Content = (TextContent | ImageContent)[];\n\n/**\n * Built-in tool task: resolves the called tool among its phase agent's tools, validates, runs `beforeTool`, records intent,\n * executes, runs `afterTool`, and settles the result, all in one `call` handler so nothing separates resolution from\n * settlement. `execute` is reached only by recovery and applies the replay rule. A model-issued call settles by\n * appending its result entry; a nested call by writing its result to its caller's `NestedCallDoc`.\n */\nexport const ToolTask = defineTask<ToolTaskInput, ToolTaskCheckpoint, ToolTaskResult, ToolHooks>({\n\tname: \"pi.tool\",\n\tversion: 2,\n\tinitial: () => ({ phase: \"call\" }),\n\t// Version 1 had only model-issued calls.\n\tmigrate: (input, checkpoint) => ({\n\t\tinput: { kind: \"model\", ...(input as { assistant: EntryId; callId: string }) },\n\t\tcheckpoint: checkpoint as ToolTaskCheckpoint,\n\t}),\n\tphases: {\n\t\tcall: async (task, runtime, context) => {\n\t\t\tconst call = await readCall(runtime, task.input, context);\n\t\t\tconst tool = await resolveTool(runtime, task.input, call.name, context);\n\t\t\tif (tool === undefined) {\n\t\t\t\tconst error = harnessError(\"tool_unavailable\", `Tool ${call.name} is not available`);\n\t\t\t\treturn settle(runtime, task.input, call, COMPLETED, () => error, context);\n\t\t\t}\n\t\t\tconst prepared = prepare(tool, call.arguments as JsonObject);\n\t\t\tconst checked = \"error\" in prepared ? prepared : validate(tool, call, prepared.args);\n\t\t\tif (\"error\" in checked)\n\t\t\t\treturn settle(runtime, task.input, call, COMPLETED, () => invalid(checked.error), context);\n\t\t\tlet args = checked.args;\n\t\t\tlet block: string | undefined;\n\t\t\tawait runtime.hooks.each(\"beforeTool\", async (hook) => {\n\t\t\t\tif (block !== undefined) return;\n\t\t\t\ttry {\n\t\t\t\t\tconst decision = await hook({ ...call, arguments: args }, runtime, context);\n\t\t\t\t\tif (decision?.block !== undefined) block = decision.block;\n\t\t\t\t\telse if (decision?.arguments !== undefined) args = decision.arguments;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (runtime.signal.aborted) throw error;\n\t\t\t\t\tblock = errorMessage(error);\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (block !== undefined) {\n\t\t\t\tconst blocked = harnessError(\"blocked\", `Tool call blocked: ${block}`);\n\t\t\t\treturn settle(runtime, task.input, call, COMPLETED, () => blocked, context);\n\t\t\t}\n\t\t\tconst validated = validate(tool, call, args);\n\t\t\tif (\"error\" in validated)\n\t\t\t\treturn settle(runtime, task.input, call, COMPLETED, () => invalid(validated.error), context);\n\t\t\t// Strict JSON: repair may set optional properties to undefined, which the slot and checkpoint cannot hold.\n\t\t\tconst final = copyJson(validated.args, { omitUndefinedProperties: true }) as JsonObject;\n\t\t\tawait runtime.commit(async (tx) => {\n\t\t\t\tconst slot = toolSlot(await tx.doc(LiveDoc, runtime.conversationId), runtime.taskId);\n\t\t\t\tif (slot !== undefined) slot.status = \"running\";\n\t\t\t\t// A nested slot shows the arguments the call runs with, which repair, hooks, and coercion may have changed.\n\t\t\t\t// Compared with the input, which the slot got at admission: reading the draft would track every leaf.\n\t\t\t\tconst changed = task.input.kind === \"nested\" && !jsonEqual(task.input.call.arguments as JsonValue, final);\n\t\t\t\tif (changed && slot !== undefined && \"parentTaskId\" in slot) slot.arguments = final;\n\t\t\t\tconst intent = { phase: \"execute\", arguments: final, replay: tool.replay ?? \"unsafe\" } as const;\n\t\t\t\treturn { status: \"running\", checkpoint: intent };\n\t\t\t}, context);\n\t\t\tawait run(runtime, task.input, call, tool, final, context);\n\t\t},\n\t\t/** Recovery after intent: rerun only when the stored and the current policy both say `safe`. */\n\t\texecute: async (task, runtime, context) => {\n\t\t\tconst { arguments: args, replay } = task.state.checkpoint;\n\t\t\tconst call = await readCall(runtime, task.input, context);\n\t\t\tconst tool = await resolveTool(runtime, task.input, call.name, context);\n\t\t\tif (replay === \"safe\" && tool?.replay === \"safe\") {\n\t\t\t\t// The rerun reports from scratch; clear what the interrupted attempt published.\n\t\t\t\tawait runtime.commit(async (tx) => {\n\t\t\t\t\tconst slot = toolSlot(await tx.doc(LiveDoc, runtime.conversationId), runtime.taskId);\n\t\t\t\t\tif (slot !== undefined) clearProgress(slot);\n\t\t\t\t\treturn undefined;\n\t\t\t\t}, context);\n\t\t\t\treturn run(runtime, task.input, call, tool, args, context);\n\t\t\t}\n\t\t\tconst message = `Tool ${call.name} was interrupted and may have partially run`;\n\t\t\t// `failed` records cancellation intent, so the call's owned conversations, left unsupervised, are aborted.\n\t\t\tconst ending = { status: \"failed\", message } as const;\n\t\t\tawait settle(runtime, task.input, call, ending, (slot) => fromSlot(slot, \"interrupted\", message), context);\n\t\t},\n\t},\n\tabort: async (task, runtime, context) => {\n\t\tconst call = await readCall(runtime, task.input, context);\n\t\t// Abandoned after a restart (`TaskOptions.abandonOnRestart`): say whether the call may have run.\n\t\tconst [code, message] =\n\t\t\ttask.abortReason !== \"restart\"\n\t\t\t\t? [\"aborted\", `Tool ${call.name} was aborted`]\n\t\t\t\t: task.state.checkpoint.phase === \"execute\"\n\t\t\t\t\t? [\"interrupted\", `Tool ${call.name} was interrupted by a restart and may have partially run`]\n\t\t\t\t\t: [\"abandoned\", `Tool ${call.name} was not started: its caller ended with a restart`];\n\t\tconst ending = { status: \"aborted\" } as const;\n\t\tawait settle(runtime, task.input, call, ending, (slot) => fromSlot(slot, code, message), context);\n\t},\n});\n\n/** The called tool: among the tools the model is offered for a model-issued call, else among those tools may call. */\nasync function resolveTool(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tname: string,\n\tcontext: Context,\n): Promise<ToolRegistration | undefined> {\n\tconst agent = await runtime.agent(context);\n\treturn (input.kind === \"model\" ? agent.tools : agent.callable).find((tool) => tool.name === name);\n}\n\n/** The call: from the input for a nested call, which hooks see with its parent, else from the assistant entry. */\nasync function readCall(runtime: Runtime, input: ToolTaskInput, context: Context): Promise<ToolHookCall> {\n\tif (input.kind === \"nested\") {\n\t\tcontext.telemetry.setAttributes({\n\t\t\t\"tool.name\": input.call.name,\n\t\t\t\"tool.call_id\": input.call.id,\n\t\t});\n\t\treturn { ...input.call, parent: { taskId: input.parent, callId: input.parentCallId } };\n\t}\n\tconst entry = await runtime.entry(AssistantEntry, input.assistant, context);\n\tconst message = entry?.model?.[0];\n\tconst call =\n\t\tmessage?.role === \"assistant\"\n\t\t\t? message.content.find(\n\t\t\t\t\t(content): content is ToolCall => content.type === \"toolCall\" && content.id === input.callId,\n\t\t\t\t)\n\t\t\t: undefined;\n\tif (call === undefined) throw new Error(`Entry ${input.assistant} has no tool call ${input.callId}`);\n\tcontext.telemetry.setAttributes({\n\t\t\"tool.name\": call.name,\n\t\t\"tool.call_id\": call.id,\n\t});\n\treturn call;\n}\n\n/** Arguments, or why they are invalid. */\ntype Checked = { readonly args: JsonObject } | { readonly error: string };\n\n/** The call's arguments as repaired by the tool; a throwing repair makes them invalid. */\nfunction prepare(tool: ToolRegistration, args: JsonObject): Checked {\n\tif (tool.prepareArguments === undefined) return { args };\n\ttry {\n\t\treturn { args: tool.prepareArguments(args) as JsonObject };\n\t} catch (error) {\n\t\treturn { error: errorMessage(error) };\n\t}\n}\n\n/** Arguments validated and coerced against the implementation's schema. */\nfunction validate(tool: ToolRegistration, call: ToolCall, args: JsonObject): Checked {\n\ttry {\n\t\treturn { args: validateToolArguments(tool, { ...call, arguments: args }) as JsonObject };\n\t} catch (error) {\n\t\treturn { error: errorMessage(error) };\n\t}\n}\n\nfunction invalid(message: string): ToolExecutionResult {\n\treturn harnessError(\"invalid_arguments\", message);\n}\n\n/** What a running tool reported through its api: output, the last details, and diagnostics. */\ntype Reported = {\n\treadonly output: OutputBuffer;\n\treadonly limits: OutputLimits;\n\treadonly diagnostics: ToolDiagnostic[];\n\tdetails: JsonValue | undefined;\n};\n\n/** Execute with the resolved implementation, then settle its result. */\nasync function run(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\ttool: ToolRegistration,\n\targs: JsonObject,\n\tcontext: Context,\n): Promise<void> {\n\tconst limits: OutputLimits = {\n\t\tmaxBytes: tool.outputLimits?.maxBytes ?? DEFAULT_MAX_BYTES,\n\t\tmaxLines: tool.outputLimits?.maxLines ?? DEFAULT_MAX_LINES,\n\t\tretain: tool.outputLimits?.retain ?? \"head\",\n\t};\n\tconst reported: Reported = { output: new OutputBuffer(limits), limits, diagnostics: [], details: undefined };\n\tconst streams = input.kind === \"model\" || input.progress !== false;\n\tconst progress = publishProgress(runtime, reported, streams, context);\n\t/** Nested call admissions this invocation started; cleanup waits for them, so it sees every nested call. */\n\tconst admissions: Promise<unknown>[] = [];\n\t// A caller that can rerun reattaches to its nested calls and child tasks after a restart; any other caller never\n\t// resumes, so they are abandoned (`TaskOptions.abandonOnRestart`).\n\tconst resumes = tool.replay === \"safe\";\n\t/** Default keys: the order of this invocation's calls, so a rerun that calls in the same order reattaches. */\n\tlet sequence = 0;\n\t/** This attempt's commit of the `MADE_NESTED_CALLS` memo. */\n\tlet madeNestedMemo: Promise<unknown> | undefined;\n\tlet ended = false;\n\tconst assertLive = (): void => {\n\t\tif (ended) throw new Error(`Tool call ${call.id} has settled`);\n\t};\n\t/** Built for this call, below, so a rerun after recovery gets the conversation's environment at that time. */\n\tlet env: ExecutionEnv | undefined;\n\tconst api: ToolExecutionApi = {\n\t\ttaskId: runtime.taskId,\n\t\tconversationId: runtime.conversationId,\n\t\tcallId: call.id,\n\t\tregistry: runtime.registry,\n\t\tagent: runtime.agent,\n\t\tget models() {\n\t\t\treturn runtime.models;\n\t\t},\n\t\tget env() {\n\t\t\treturn env;\n\t\t},\n\t\tnow: () => runtime.now(),\n\t\toutput: (chunk, skipped) => {\n\t\t\tassertLive();\n\t\t\tif (reported.output.push(chunk, skipped)) progress.mark();\n\t\t},\n\t\toutputWindow:\n\t\t\tlimits.retain === \"tail\"\n\t\t\t\t? {\n\t\t\t\t\t\tmaxBytes: limits.maxBytes,\n\t\t\t\t\t\tmaxLines: limits.maxLines,\n\t\t\t\t\t\tminIntervalMs: runtime.settings.progress.outputIntervalMs,\n\t\t\t\t\t\tbytesPerSecond: PROGRESS_BYTES_PER_SECOND,\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\tretainedOutput: () => {\n\t\t\tassertLive();\n\t\t\tconst retained = reported.output.snapshot();\n\t\t\treturn { text: retained.text, truncated: retained.droppedBytes > 0 };\n\t\t},\n\t\tdiagnostic: (diagnostic) => {\n\t\t\tassertLive();\n\t\t\treported.diagnostics.push(copyJson(diagnostic, { omitUndefinedProperties: true }) as ToolDiagnostic);\n\t\t\tprogress.mark();\n\t\t},\n\t\tdetails: async (value, detailsContext) => {\n\t\t\tassertLive();\n\t\t\tdetailsContext.abortSignal?.throwIfAborted();\n\t\t\treported.details = copyJson(value, { omitUndefinedProperties: true });\n\t\t\tconst committed = progress.markAndWait();\n\t\t\t// Cancelling the wait leaves the update in place; the commit's own outcome stays observed.\n\t\t\tcommitted.catch(() => {});\n\t\t\treturn awaitWithContext(committed, detailsContext);\n\t\t},\n\t\tcommit: async (change, commitContext) => {\n\t\t\tlet result: Awaited<ReturnType<typeof change>> | undefined;\n\t\t\tawait runtime.commit(async (tx) => {\n\t\t\t\tresult = await change(tx);\n\t\t\t\treturn undefined;\n\t\t\t}, commitContext);\n\t\t\treturn result as Awaited<ReturnType<typeof change>>;\n\t\t},\n\t\tmemo: runtime.memo,\n\t\tcreateTask: async <I, S extends { phase: string }, R, H extends object>(\n\t\t\ttask: Task<I, S, R, H>,\n\t\t\tinput: I,\n\t\t\toptions: Omit<TaskOptions, \"conversationId\">,\n\t\t\ttaskContext: Context,\n\t\t): Promise<TaskId<R>> => {\n\t\t\tconst child = options.ownership.kind === \"task\" && !resumes ? { abandonOnRestart: true, ...options } : options;\n\t\t\tlet id: TaskId<R> | undefined;\n\t\t\tawait runtime.commit(async (tx) => {\n\t\t\t\tid = await tx.createTask(task, input, child);\n\t\t\t\treturn undefined;\n\t\t\t}, taskContext);\n\t\t\treturn id!;\n\t\t},\n\t\tgetTask: runtime.getTask,\n\t\twaitForTask: runtime.waitForTask,\n\t\tconversation: runtime.conversation,\n\t\tsnapshot: runtime.snapshot,\n\t\tsnapshotAsOf: runtime.snapshotAsOf,\n\t\twatchDoc: runtime.watchDoc,\n\t\texecuteTool: async (name, toolArgs, callContext, options = {}) => {\n\t\t\tassertLive();\n\t\t\tconst key = options.key ?? String(++sequence);\n\t\t\tif (options.key !== undefined) checkKey(options.key);\n\t\t\t// The memo first, once per attempt; a failed one is tried again by the next call.\n\t\t\tmadeNestedMemo ??= runtime.memo(MADE_NESTED_CALLS, true, callContext).catch((error: unknown) => {\n\t\t\t\tmadeNestedMemo = undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\t// Registered now, so cleanup waits for it.\n\t\t\tconst admission = madeNestedMemo.then(() =>\n\t\t\t\tstartNestedCall(\n\t\t\t\t\truntime,\n\t\t\t\t\tcall.id,\n\t\t\t\t\tname,\n\t\t\t\t\ttoolArgs,\n\t\t\t\t\t{ key, progress: options.progress, abandonOnRestart: !resumes },\n\t\t\t\t\tcallContext,\n\t\t\t\t),\n\t\t\t);\n\t\t\tadmissions.push(admission);\n\t\t\tconst id = await admission;\n\t\t\tconst settled = await runtime.waitForTask(id, callContext);\n\t\t\tconst stored = (await runtime.snapshot(NestedCallDoc, runtime.taskId, key, callContext))?.result;\n\t\t\t// A copy the tool may change; a nested call the scheduler faulted or orphaned stored none.\n\t\t\treturn stored === undefined\n\t\t\t\t? fallbackResult(id, name, settled.state.outcome)\n\t\t\t\t: (copyJson(stored as unknown as JsonValue) as unknown as NestedToolExecutionResult);\n\t\t},\n\t};\n\n\tlet result: ToolExecutionResult;\n\tlet ending = COMPLETED;\n\t// Execution time of this attempt; a rerun after recovery measures only itself.\n\tlet durationMs: number | undefined;\n\ttry {\n\t\tenv = await runtime.env(context);\n\t\tconst startedAt = performance.now();\n\t\ttry {\n\t\t\tresult = await tool.execute(args, api, context);\n\t\t} finally {\n\t\t\tdurationMs = Math.round(performance.now() - startedAt);\n\t\t}\n\t} catch (error) {\n\t\tif (runtime.signal.aborted) {\n\t\t\tended = true;\n\t\t\tfor (const waiter of await progress.stop()) waiter.reject(error);\n\t\t\tthrow error;\n\t\t}\n\t\tresult = { isError: true, diagnostics: [toolDiagnostic(\"tool_error\", errorMessage(error))] };\n\t\t// A throw, from `execute()` or from building the environment, ends the task `failed`, which cancels what the call\n\t\t// owned; it no longer supervises it. The error text is already in the result.\n\t\tending = { status: \"failed\", message: `Tool ${call.name} threw` };\n\t}\n\tended = true;\n\t// No admission starts after `ended`; let those underway commit, so settlement aborts and lists their calls.\n\tawait Promise.allSettled(admissions);\n\treported.output.end();\n\t// Details still waiting for a progress commit settle with the terminal commit, the final flush.\n\tconst pending = await progress.stop();\n\ttry {\n\t\tconst settled = await finalResult(runtime, input, call, tool, result, reported, context);\n\t\tawait settle(runtime, input, call, ending, () => settled, context, durationMs);\n\t} catch (error) {\n\t\tfor (const waiter of pending) waiter.reject(error);\n\t\tthrow error;\n\t}\n\tfor (const waiter of pending) waiter.resolve();\n}\n\n/**\n * The Harness clock and timers for progress pacing. After the invocation ends nothing more commits, and the clock\n * answers with the last time it read.\n */\nfunction progressClock(runtime: Runtime): ProgressClock {\n\tlet last = 0;\n\treturn {\n\t\tnow: () => {\n\t\t\ttry {\n\t\t\t\tlast = runtime.now();\n\t\t\t} catch {\n\t\t\t\t// The invocation ended.\n\t\t\t}\n\t\t\treturn last;\n\t\t},\n\t\tsetTimer: (callback, delayMs) => runtime.setTimer(callback, delayMs),\n\t};\n}\n\n/**\n * Throttled commits of what the tool reported into its slot, in `pi.live.tools` or `pi.live.nestedTools`, each writing\n * only what changed since the last one; none when `enabled` is false.\n */\nfunction publishProgress(runtime: Runtime, reported: Reported, enabled: boolean, context: Context): Progress {\n\tlet written = { text: \"\", details: undefined as JsonValue | undefined, diagnostics: 0 };\n\treturn new Progress(\n\t\tasync () => {\n\t\t\tif (!enabled) return 0;\n\t\t\t// Capture everything synchronously: the tool keeps reporting while the commit is in flight.\n\t\t\tconst snapshot = reported.output.snapshot();\n\t\t\tconst current = { text: snapshot.text, details: reported.details, diagnostics: reported.diagnostics.length };\n\t\t\tconst added = reported.diagnostics.slice(written.diagnostics, current.diagnostics);\n\t\t\tconst detailsChanged = current.details !== written.details;\n\t\t\t// What the commit writes, as Chord diffs the string: an append, a trim plus an append of what follows the shared\n\t\t\t// part, or the whole window when its bounded overlap search finds nothing.\n\t\t\tlet bytes = 0;\n\t\t\tif (snapshot.text !== written.text) {\n\t\t\t\tconst shared = snapshot.text.startsWith(written.text)\n\t\t\t\t\t? written.text.length\n\t\t\t\t\t: overlap(written.text, snapshot.text, 65_536);\n\t\t\t\tbytes += utf8ByteLength(snapshot.text.slice(shared));\n\t\t\t}\n\t\t\tif (detailsChanged) bytes += utf8ByteLength(JSON.stringify(current.details ?? null));\n\t\t\tif (added.length > 0) bytes += utf8ByteLength(JSON.stringify(added));\n\t\t\tawait runtime.commit(async (tx) => {\n\t\t\t\tconst slot = toolSlot(await tx.doc(LiveDoc, runtime.conversationId), runtime.taskId);\n\t\t\t\tif (slot === undefined) return undefined;\n\t\t\t\t// REMINDER: assign `output` as one string field. Chord then diffs it into an append, or a trim plus an\n\t\t\t\t// append for a sliding tail; replacing the slot object would record the whole window on every commit.\n\t\t\t\tif ((slot.output ?? \"\") !== snapshot.text) slot.output = snapshot.text;\n\t\t\t\tif (snapshot.droppedBytes > 0) slot.droppedBytes = snapshot.droppedBytes;\n\t\t\t\tif (snapshot.droppedLines > 0) slot.droppedLines = snapshot.droppedLines;\n\t\t\t\t// Diff details leaf by leaf and append new diagnostics, so each commit writes only what changed.\n\t\t\t\tif (detailsChanged && current.details !== undefined) {\n\t\t\t\t\tassignJson(slot as unknown as Record<string, JsonValue>, \"details\", current.details);\n\t\t\t\t}\n\t\t\t\tif (added.length > 0) {\n\t\t\t\t\tif (slot.diagnostics === undefined) slot.diagnostics = [];\n\t\t\t\t\tfor (const diagnostic of added) slot.diagnostics.push(diagnostic);\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t}, context);\n\t\t\twritten = current;\n\t\t\treturn bytes;\n\t\t},\n\t\t(error) => {\n\t\t\t// Rejections after an abort mark or close are expected; the committed state stays consistent.\n\t\t\tif (!runtime.signal.aborted) runtime.report(error);\n\t\t},\n\t\truntime.settings.progress.outputIntervalMs,\n\t\tprogressClock(runtime),\n\t);\n}\n\n/**\n * The settled result: the tool's result with the retained output and last details as fallbacks, its diagnostics after\n * those reported through the api, `afterTool` applied, explicit text bounded, and `structuredOutput` checked against the\n * tool's schema, with the Harness's diagnostics last. A nested call whose `structuredOutput` breaks the contract gets an\n * error result without it; a model-issued call only loses it, and the break is reported to the host.\n */\nasync function finalResult(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\ttool: ToolRegistration,\n\tresult: ToolExecutionResult,\n\treported: Reported,\n\tcontext: Context,\n): Promise<ToolExecutionResult> {\n\tconst harness: ToolDiagnostic[] = [];\n\tconst retained = result.output === undefined ? reported.output.snapshot() : undefined;\n\tconst output: Content =\n\t\tretained === undefined ? result.output! : retained.text === \"\" ? [] : [{ type: \"text\", text: retained.text }];\n\tlet final: ToolExecutionResult = {\n\t\t...result,\n\t\toutput,\n\t\tdetails: result.details === undefined ? reported.details : result.details,\n\t\tdiagnostics: [...reported.diagnostics, ...(result.diagnostics ?? [])],\n\t};\n\tawait runtime.hooks.each(\"afterTool\", async (hook) => {\n\t\tfinal = (await hook(call, final, runtime, context)) ?? final;\n\t});\n\t// The retained output's truncation applies only while afterTool kept that output.\n\tif (retained !== undefined && retained.droppedBytes > 0 && final.output === output) {\n\t\tharness.push(truncated(retained, reported.limits.retain));\n\t}\n\tconst bounded = boundContent(final.output ?? [], reported.limits);\n\tif (bounded.droppedBytes > 0) harness.push(truncated(bounded, reported.limits.retain));\n\tconst broken = structuredOutputError(tool, final);\n\tif (broken !== undefined) {\n\t\tconst { structuredOutput: _dropped, ...rest } = final;\n\t\tif (input.kind === \"nested\") {\n\t\t\tfinal = { ...rest, isError: true };\n\t\t\tharness.push(toolDiagnostic(\"invalid_structured_output\", broken));\n\t\t} else {\n\t\t\t// The model never sees structured output, so its call stands; the host learns of the broken tool.\n\t\t\tfinal = rest;\n\t\t\t// Only names the extension: a failed resolution leaves the report without the name.\n\t\t\tconst extension = await runtime.agent(context).then(\n\t\t\t\t(agent) => toolExtension(agent, tool.name),\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\truntime.report(new Error(broken), { type: \"extension\", ...optionalExtension(extension) });\n\t\t}\n\t}\n\t// Programs get the tool's own value: without a schema, its output. The model reads only `output`, so model-issued\n\t// calls skip both.\n\tif (input.kind === \"nested\" && tool.structuredOutputSchema === undefined) {\n\t\tfinal = { ...final, structuredOutput: outputValue(bounded.content) as JsonValue };\n\t}\n\t// A schema tool's error result without structured output has its text only in the output, which programs never\n\t// get: it becomes an error diagnostic, as a thrown error's message does, unless one says what went wrong already.\n\tif (\n\t\tinput.kind === \"nested\" &&\n\t\ttool.structuredOutputSchema !== undefined &&\n\t\tfinal.isError === true &&\n\t\tfinal.structuredOutput === undefined &&\n\t\t![...(final.diagnostics ?? []), ...harness].some((diagnostic) => diagnostic.severity === \"error\")\n\t) {\n\t\tconst text = bounded.content.flatMap((item) => (item.type === \"text\" ? [item.text] : [])).join(\"\\n\");\n\t\tif (text !== \"\") harness.push(toolDiagnostic(\"tool_error\", text));\n\t}\n\treturn { ...final, output: bounded.content, diagnostics: [...(final.diagnostics ?? []), ...harness] };\n}\n\nconst structuredValidators = new WeakMap<object, ReturnType<typeof Compile>>();\n\n/** Why a result's `structuredOutput` breaks the tool's contract, or `undefined` when it keeps it. */\nfunction structuredOutputError(tool: ToolRegistration, result: ToolExecutionResult): string | undefined {\n\tconst schema = tool.structuredOutputSchema;\n\tconst value = result.structuredOutput;\n\tif (schema === undefined) {\n\t\treturn value === undefined\n\t\t\t? undefined\n\t\t\t: `Tool ${tool.name} returned structuredOutput but declares no structuredOutputSchema`;\n\t}\n\tif (value === undefined) {\n\t\treturn result.isError === true ? undefined : `Tool ${tool.name} returned no structuredOutput`;\n\t}\n\tlet validator = structuredValidators.get(schema);\n\tif (validator === undefined) {\n\t\tvalidator = Compile(schema);\n\t\tstructuredValidators.set(schema, validator);\n\t}\n\tif (validator.Check(value)) return undefined;\n\tconst [first] = validator.Errors(value);\n\tconst path = first?.instancePath.replace(/^\\//, \"\").replace(/\\//g, \".\") || \"root\";\n\treturn `Tool ${tool.name} returned structuredOutput that does not match its schema: ${path}: ${first?.message ?? \"invalid\"}`;\n}\n\n/**\n * Commit the tool's terminal state and mark its slot done. A model-issued call appends its result entry and ends with\n * the entry ID; a nested call writes its result to the caller's `NestedCallDoc`, records its usage, and ends with a\n * small receipt. Nested calls this call left running are aborted first, so they report into their slots before the\n * slots below the call leave `pi.live`. `build` receives the slot so interruption and abort can report the durable\n * partial output.\n */\nasync function settle(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\tending: Ending,\n\tbuild: (slot: Readonly<ToolSlot | NestedToolSlot> | undefined) => ToolExecutionResult,\n\tcontext: Context,\n\tdurationMs?: number,\n): Promise<void> {\n\t// A crash in between leaves the call in `execute`: a safe rerun reattaches to the calls, an interruption ends here.\n\t// Every live nested call the task owns, also those an earlier attempt made and this one never called again.\n\tconst nestedIds = (await runtime.ownedTasks(context))\n\t\t.filter((record) => record.kind === ToolTask.definition.name && (record.input as ToolTaskInput).kind === \"nested\")\n\t\t.map((record) => record.id);\n\t// Read before the settling commit: no admission starts after `ended`, and those underway were awaited.\n\tconst madeNested = (await runtime.memo(MADE_NESTED_CALLS, context)) === true;\n\t// Mark them all before waiting for any: one may run until a sibling is cancelled.\n\tawait Promise.all(nestedIds.map((id) => runtime.abortOwned(id, context)));\n\tawait runtime.commit(async (tx) => {\n\t\tconst conversationId = runtime.conversationId;\n\t\tconst live = await tx.doc(LiveDoc, conversationId);\n\t\tconst slot = toolSlot(live, runtime.taskId);\n\t\tconst result = build(slot);\n\t\tlet settled: ToolTaskResult;\n\t\tif (input.kind === \"nested\") {\n\t\t\tconst nested = nestedResult(runtime.taskId, result, durationMs);\n\t\t\tif (nested.usage !== undefined) await recordUsage(tx, conversationId, \"tools\", call.name, nested.usage);\n\t\t\t// The caller is never terminal before its owned nested calls, so its document is open; another task in it is a\n\t\t\t// bug, not a race.\n\t\t\tconst state = await tx.doc(NestedCallDoc, input.parent, input.key, null);\n\t\t\tif (state.taskId !== runtime.taskId) throw new Error(`Nested call ${call.id} is not in its caller's index`);\n\t\t\tstate.result = nested as unknown as Draft<JsonRepresentation<NestedToolExecutionResult>>;\n\t\t\tif (slot !== undefined && \"parentTaskId\" in slot) {\n\t\t\t\tfinishSlot(slot);\n\t\t\t\tslot.summary = summaryOf(nested, result.output ?? []);\n\t\t\t}\n\t\t\tsettled = { kind: \"nested\" };\n\t\t} else {\n\t\t\tconst timing = { timestamp: runtime.now(), durationMs };\n\t\t\tconst entry = await appendToolResult(tx, conversationId, call, result, timing);\n\t\t\tif (slot !== undefined && !(\"parentTaskId\" in slot)) {\n\t\t\t\tfinishSlot(slot);\n\t\t\t\tslot.entry = entry.id;\n\t\t\t}\n\t\t\t// Tools build control objects freely; drop keys set to undefined so the task result is strict JSON.\n\t\t\tconst control =\n\t\t\t\tresult.control === undefined || ending.status !== \"completed\"\n\t\t\t\t\t? {}\n\t\t\t\t\t: { control: copyJson(result.control as JsonValue, { omitUndefinedProperties: true }) as ToolControl };\n\t\t\tsettled = { kind: \"model\", entryId: entry.id, ...control };\n\t\t}\n\t\t// A call that made no nested calls, in any attempt, has no slots below it; skipping the scan keeps many leaves\n\t\t// linear. Committed before the read: no nested call is admitted after `ended`.\n\t\tif (madeNested) removeNestedSlots(live, runtime.taskId);\n\t\tif (ending.status === \"aborted\") return { status: \"terminal\", outcome: { status: \"aborted\", result: settled } };\n\t\tif (ending.status === \"failed\") {\n\t\t\tconst error = { message: ending.message };\n\t\t\treturn { status: \"terminal\", outcome: { status: \"failed\", error, result: settled } };\n\t\t}\n\t\treturn { status: \"terminal\", outcome: { status: \"completed\", result: settled } };\n\t}, context);\n}\n\n/**\n * A nested call's result, as stored and returned: strict JSON, without `output`, which only the model reads, and\n * without `control`, which only model-issued calls apply.\n */\nfunction nestedResult(\n\ttaskId: TaskId,\n\tresult: ToolExecutionResult,\n\tdurationMs: number | undefined,\n): NestedToolExecutionResult {\n\tconst nested = {\n\t\ttaskId,\n\t\tstructuredOutput: result.structuredOutput,\n\t\tisError: result.isError ?? false,\n\t\tdetails: result.details,\n\t\tdiagnostics: result.diagnostics ?? [],\n\t\tusage: result.usage,\n\t\tdurationMs,\n\t};\n\treturn copyJson(nested as unknown as JsonValue, {\n\t\tomitUndefinedProperties: true,\n\t}) as unknown as NestedToolExecutionResult;\n}\n\n/**\n * Create nested call `key` of the call `parentCallId` in one commit: its tool task, owned by the calling task, its slot,\n * and its `NestedCallDoc`. A key already made returns that call's task when it names the same tool and arguments.\n */\nasync function startNestedCall(\n\truntime: Runtime,\n\tparentCallId: string,\n\tname: string,\n\targs: JsonObject,\n\toptions: { readonly key: string; readonly progress: boolean | undefined; readonly abandonOnRestart: boolean },\n\tcontext: Context,\n): Promise<TaskId<ToolTaskResult>> {\n\tconst key = options.key;\n\tconst call: ToolCall = {\n\t\ttype: \"toolCall\",\n\t\tid: `${parentCallId}/${key}`,\n\t\tname,\n\t\targuments: copyJson(args, { omitUndefinedProperties: true }) as JsonObject,\n\t};\n\tlet id: TaskId<ToolTaskResult> | undefined;\n\tlet replayed = false;\n\tawait runtime.commit(async (tx) => {\n\t\t// Opened, or created empty for a key not made yet.\n\t\tconst state = await tx.doc(NestedCallDoc, runtime.taskId, key, null);\n\t\tconst existing = state.taskId;\n\t\tif (existing !== undefined) {\n\t\t\tconst input = (await tx.task(existing))?.input as ToolTaskInput | undefined;\n\t\t\tconst same =\n\t\t\t\tinput?.kind === \"nested\" &&\n\t\t\t\tinput.call.name === name &&\n\t\t\t\tjsonEqual(input.call.arguments as JsonValue, call.arguments as JsonValue);\n\t\t\tif (!same) throw new Error(`Nested call ${call.id} was already made with another tool or other arguments`);\n\t\t\tid = existing as TaskId<ToolTaskResult>;\n\t\t\treplayed = state.result !== undefined;\n\t\t\treturn undefined;\n\t\t}\n\t\tconst input: ToolTaskInput = {\n\t\t\tkind: \"nested\",\n\t\t\tparent: runtime.taskId,\n\t\t\tparentCallId,\n\t\t\tkey,\n\t\t\tcall,\n\t\t\t...(options.progress === false ? { progress: false } : {}),\n\t\t};\n\t\tconst created = await tx.createTask(ToolTask, input, {\n\t\t\townership: { kind: \"task\", taskId: runtime.taskId },\n\t\t\tabandonOnRestart: options.abandonOnRestart,\n\t\t});\n\t\tstate.taskId = created;\n\t\tconst live = await tx.doc(LiveDoc, runtime.conversationId);\n\t\tlive.nestedTools ??= [];\n\t\tconst slot: NestedToolSlot = {\n\t\t\tcallId: call.id,\n\t\t\tparentCallId,\n\t\t\tparentTaskId: runtime.taskId,\n\t\t\tname,\n\t\t\ttaskId: created,\n\t\t\targuments: call.arguments as JsonObject,\n\t\t\tstatus: \"pending\",\n\t\t};\n\t\tlive.nestedTools.push(slot as Draft<NestedToolSlot>);\n\t\tid = created;\n\t\treturn undefined;\n\t}, context);\n\tif (replayed) {\n\t\tcontext.telemetry.addEvent(\"pi.durable.replay\", { \"tool.name\": name });\n\t}\n\treturn id!;\n}\n\n/**\n * What programs get of a tool's output when it declares no schema: one text item as its string, one image as itself,\n * nothing as `\"\"`, and anything else as the content list.\n */\nfunction outputValue(output: Content): string | ImageContent | Content {\n\tif (output.length === 0) return \"\";\n\tif (output.length > 1) return output;\n\tconst [only] = output;\n\treturn only!.type === \"text\" ? only!.text : only!;\n}\n\n/** What the caller gets for a nested call without a stored result: one the scheduler faulted or orphaned. */\nfunction fallbackResult(taskId: TaskId, name: string, outcome: TaskOutcome<ToolTaskResult>): NestedToolExecutionResult {\n\tconst message =\n\t\toutcome.status === \"faulted\"\n\t\t\t? `Tool ${name} failed: ${outcome.error.message}`\n\t\t\t: outcome.status === \"orphaned\"\n\t\t\t\t? `Tool ${name} could not resume: ${outcome.reason}`\n\t\t\t\t: `Tool ${name} ended without a result`;\n\tconst error = harnessError(outcome.status, message);\n\treturn { taskId, isError: true, diagnostics: error.diagnostics ?? [] };\n}\n\n/**\n * How a tool task ends; the result entry is appended either way. `failed` (execution threw or was interrupted)\n * records cancellation intent for the conversations the call owns; a result with `isError` still completes.\n */\ntype Ending = { readonly status: \"completed\" | \"aborted\" } | { readonly status: \"failed\"; readonly message: string };\n\nconst COMPLETED: Ending = { status: \"completed\" };\n\n/** An error result from the slot's durable partial output, details, and diagnostics. */\nfunction fromSlot(\n\tslot: Readonly<ToolSlot | NestedToolSlot> | undefined,\n\tcode: string,\n\tmessage: string,\n): ToolExecutionResult {\n\tconst diagnostics = [...(slot?.diagnostics ?? [])];\n\tconst droppedBytes = slot?.droppedBytes ?? 0;\n\tif (droppedBytes > 0) diagnostics.push(truncated({ droppedBytes, droppedLines: slot?.droppedLines ?? 0 }));\n\tdiagnostics.push(toolDiagnostic(code, message));\n\treturn {\n\t\toutput: slot?.output === undefined || slot.output === \"\" ? [] : [{ type: \"text\", text: slot.output }],\n\t\tisError: true,\n\t\t...(slot?.details === undefined ? {} : { details: slot.details }),\n\t\tdiagnostics,\n\t};\n}\n\n/** An error result the Harness writes itself: no content and one `error` diagnostic with `code`. */\nexport function harnessError(code: string, message: string): ToolExecutionResult {\n\treturn { output: [], isError: true, diagnostics: [toolDiagnostic(code, message)] };\n}\n\nfunction toolDiagnostic(code: string, message: string): ToolDiagnostic {\n\treturn { severity: \"error\", code, message };\n}\n\n/** The Harness's truncation diagnostic; `retain` is unknown when rebuilt from a slot after recovery. */\nfunction truncated(\n\tdropped: { readonly droppedLines: number; readonly droppedBytes: number },\n\tretain?: \"head\" | \"tail\",\n): ToolDiagnostic {\n\tconst kept = retain === undefined ? \"\" : ` to its ${retain === \"head\" ? \"beginning\" : \"end\"}`;\n\treturn {\n\t\tseverity: \"warn\",\n\t\tcode: \"truncated\",\n\t\tmessage: `Output truncated${kept}: ${dropped.droppedLines} lines, ${dropped.droppedBytes} bytes dropped`,\n\t};\n}\n\n/** Error text a nested call's summary keeps. */\nconst MAX_SUMMARY_ERROR_CHARS = 500;\n\n/** How a nested call ended, for its slot: error text, from its diagnostics or else its `output`, bounded. */\nfunction summaryOf(result: NestedToolExecutionResult, output: Content): NestedToolSummary {\n\tconst error = result.isError ? errorTextOf(result, output).slice(0, MAX_SUMMARY_ERROR_CHARS) : \"\";\n\treturn {\n\t\tisError: result.isError,\n\t\t...(result.durationMs === undefined ? {} : { durationMs: result.durationMs }),\n\t\t...(result.usage === undefined ? {} : { usage: result.usage }),\n\t\t...(error === \"\" ? {} : { error }),\n\t};\n}\n\n/** The error messages of a nested result, else the text items of its output, joined with newlines. */\nfunction errorTextOf(result: NestedToolExecutionResult, output: Content): string {\n\tconst errors = result.diagnostics.filter((diagnostic) => diagnostic.severity === \"error\");\n\tif (errors.length > 0) return errors.map((diagnostic) => diagnostic.message).join(\"\\n\");\n\treturn output.flatMap((item) => (item.type === \"text\" ? [item.text] : [])).join(\"\\n\");\n}\n\n/**\n * Append a `pi.tool-result` entry. The content ends with the rendered diagnostics, so the stored message is exactly\n * what the model sees; `data` keeps the structured list. A result's usage is added to `pi.usage` in the same commit.\n */\nexport async function appendToolResult(\n\ttx: Tx,\n\tconversationId: ConversationId,\n\tcall: ToolCall,\n\tresult: ToolExecutionResult,\n\tmeta: { readonly timestamp: number; readonly durationMs?: number },\n): Promise<TypedEntry<{ diagnostics: ToolDiagnostic[] }>> {\n\tconst { timestamp, durationMs } = meta;\n\tconst diagnostics = [...(result.diagnostics ?? [])];\n\tconst content: Content = [...(result.output ?? [])];\n\tif (diagnostics.length > 0) content.push({ type: \"text\", text: renderDiagnostics(diagnostics) });\n\tconst message = {\n\t\trole: \"toolResult\",\n\t\ttoolCallId: call.id,\n\t\ttoolName: call.name,\n\t\tcontent,\n\t\t...(result.details === undefined ? {} : { details: result.details }),\n\t\t...(result.usage === undefined ? {} : { usage: result.usage }),\n\t\tisError: result.isError ?? false,\n\t\t...(durationMs === undefined ? {} : { durationMs }),\n\t\ttimestamp,\n\t} as ToolResultMessage;\n\tif (result.usage !== undefined) await recordUsage(tx, conversationId, \"tools\", call.name, result.usage);\n\treturn tx.appendEntry(ToolResultEntry, conversationId, { model: [message], data: { diagnostics } });\n}\n\nfunction renderDiagnostics(diagnostics: readonly ToolDiagnostic[]): string {\n\treturn `<harness>\\n${diagnostics.map((diagnostic) => `[${diagnostic.severity}] ${diagnostic.message}`).join(\"\\n\")}\\n</harness>`;\n}\n\n/**\n * Bound the text of result content. When the joined text exceeds the limits, the text items are replaced by one bounded\n * item at the position of the first (head) or last (tail) text item; other content is kept.\n */\nfunction boundContent(\n\tcontent: Content,\n\tlimits: OutputLimits,\n): { content: Content; droppedBytes: number; droppedLines: number } {\n\tconst texts = content.filter((item): item is TextContent => item.type === \"text\");\n\tconst bounded = boundOutput(texts.map((item) => item.text).join(\"\"), limits);\n\tif (bounded.droppedBytes === 0) return { content, droppedBytes: 0, droppedLines: 0 };\n\tconst keep = limits.retain === \"head\" ? texts[0] : texts.at(-1);\n\tconst result: Content = [];\n\tfor (const item of content) {\n\t\tif (item.type !== \"text\") result.push(item);\n\t\telse if (item === keep) result.push({ ...item, text: bounded.text });\n\t}\n\treturn { content: result, droppedBytes: bounded.droppedBytes, droppedLines: bounded.droppedLines };\n}\n\n/**\n * Explicit nested call keys are path segments of the call ID, so IDs of different nested calls never collide, and are\n * never plain positive integers, which default keys use. `__proto__` stays reserved, as it was when keys indexed a JSON object.\n */\nfunction checkKey(key: string): void {\n\tif (key === \"\" || key.includes(\"/\") || key === \"__proto__\" || /^[1-9][0-9]*$/.test(key)) {\n\t\tthrow new Error(\n\t\t\t`Nested call key ${JSON.stringify(key)} must be non-empty, without \"/\", not \"__proto__\", and not a positive integer`,\n\t\t);\n\t}\n}\n\n/** Structural JSON equality; object key order does not matter. */\nfunction jsonEqual(a: JsonValue, b: JsonValue): boolean {\n\tif (a === b) return true;\n\tif (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) return false;\n\tif (Array.isArray(a) || Array.isArray(b)) {\n\t\treturn (\n\t\t\tArray.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, i) => jsonEqual(item, b[i]!))\n\t\t);\n\t}\n\tconst keys = Object.keys(a);\n\treturn (\n\t\tkeys.length === Object.keys(b).length && keys.every((key) => Object.hasOwn(b, key) && jsonEqual(a[key]!, b[key]!))\n\t);\n}\n"]}
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/harness/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAgB,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAc,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAA2C,MAAM,4BAA4B,CAAC;AAC/F,OAAO,EACN,WAAW,EACX,YAAY,EAEZ,yBAAyB,EACzB,QAAQ,GAER,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,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AC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC7F,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1C,OAAO,CACN,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,CAC7G,CAAC;IACH,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5B,OAAO,CACN,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,CAAE,EAAE,CAAC,CAAC,GAAG,CAAE,CAAC,CAAC,CAClH,CAAC;AACH,CAAC","sourcesContent":["import { awaitWithContext, type Context } from \"@earendil-works/chord/context\";\nimport { type Draft, overlap, ownedSlice } from \"@earendil-works/chord/delta\";\nimport { copyJson, type JsonRepresentation, type JsonValue } from \"@earendil-works/chord/json\";\nimport {\n\tboundOutput,\n\tOutputBuffer,\n\ttype OutputLimits,\n\tPROGRESS_BYTES_PER_SECOND,\n\tProgress,\n\ttype ProgressClock,\n} from \"@earendil-works/chord/output\";\nimport type { ImageContent, TextContent, ToolCall, ToolResultMessage } from \"@earendil-works/pi-ai\";\nimport { validateToolArguments } from \"@earendil-works/pi-ai/utils/validation\";\nimport { compile, type Validator } from \"@earendil-works/pi-schema\";\nimport { formats } from \"@earendil-works/pi-schema/formats\";\nimport { defineDocFamily } from \"../documents.ts\";\nimport { AssistantEntry, ToolResultEntry } from \"../entries.ts\";\nimport type { ExecutionEnv } from \"../env/index.ts\";\nimport { errorMessage } from \"../errors.ts\";\nimport { defineTask } from \"../tasks.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, utf8ByteLength } from \"../truncate.ts\";\nimport type {\n\tConversationId,\n\tEntryId,\n\tJsonObject,\n\tTask,\n\tTaskId,\n\tTaskOptions,\n\tTaskOutcome,\n\tTaskRuntime,\n\tTx,\n\tTypedEntry,\n} from \"../types.ts\";\nimport { toolExtension } from \"./agent.ts\";\nimport { assignJson } from \"./json.ts\";\nimport {\n\tclearProgress,\n\tcutOffCount,\n\tcutOffTooOften,\n\tfinishSlot,\n\tLiveDoc,\n\ttype NestedToolSlot,\n\ttype NestedToolSummary,\n\tPROGRESS_COMMIT,\n\tremoveNestedSlots,\n\tsalvageable,\n\ttype ToolSlot,\n\ttoolSlot,\n} from \"./live.ts\";\nimport type {\n\tNestedToolExecutionResult,\n\tToolControl,\n\tToolDiagnostic,\n\tToolExecutionApi,\n\tToolExecutionResult,\n\tToolHookCall,\n\tToolHooks,\n\tToolRegistration,\n} from \"./types.ts\";\nimport { recordUsage } from \"./usage.ts\";\nimport { optionalExtension } from \"./util.ts\";\n\n/**\n * A model-issued call, read from its assistant entry, or a nested call a running tool made through `executeTool()`,\n * whose call the input carries because no entry holds it.\n */\nexport type ToolTaskInput =\n\t| {\n\t\t\tkind: \"model\";\n\t\t\tassistant: EntryId;\n\t\t\tcallId: string;\n\t\t\t/** A call to a tool its request did not offer: settles `tool_unavailable` without resolving the name. */\n\t\t\tunoffered?: true;\n\t }\n\t| {\n\t\t\tkind: \"nested\";\n\t\t\tparent: TaskId;\n\t\t\tparentCallId: string;\n\t\t\tkey: string;\n\t\t\tcall: ToolCall;\n\t\t\t/** `false`: commit no running output, details, or diagnostics to the slot; the result still gets them. */\n\t\t\tprogress?: false;\n\t };\n\nexport type ToolTaskCheckpoint =\n\t| { phase: \"call\" }\n\t/** Durable intent: the final arguments and the replay policy recorded before execution. */\n\t| { phase: \"execute\"; arguments: JsonObject; replay: \"safe\" | \"unsafe\" };\n\n/**\n * A model-issued call's result is its transcript entry; a nested call's result is in its caller's\n * `NestedCallDoc`, so the receipt stays small and the result retires with the caller. A version 1 task that was\n * already holding its outcome as `completing` when the Harness upgraded finishes with a version 1 result,\n * `{ entryId, control? }` without `kind`; treat a result without `kind` as a model-issued call's.\n */\nexport type ToolTaskResult = { kind: \"model\"; entryId: EntryId; control?: ToolControl } | { kind: \"nested\" };\n\n/**\n * Memo of a tool task that made a nested call, in any attempt, committed before the first admission of each attempt:\n * only then can `pi.live` hold slots below it, which settling removes. A crash between the two only costs a scan.\n */\nconst MADE_NESTED_CALLS = \"pi.tool.madeNestedCalls\";\n\n/** One nested call of a running tool: its task, and once it ended, its result. */\nexport type NestedCallState = {\n\t/** Absent only inside the commit that creates the call; a creation that fails leaves no member. */\n\ttaskId?: TaskId<ToolTaskResult>;\n\t/** Exactly what `executeTool()` returns; absent while running, and for a call the scheduler faulted or orphaned. */\n\tresult?: JsonRepresentation<NestedToolExecutionResult>;\n};\n\n/**\n * The nested calls of a tool call, a task-scoped family of the calling task keyed by the nested call's key: so a rerun\n * finds the calls it already made, and the caller reads each result. Created with the nested task; the nested call's\n * terminal commit adds its result. One document per call, so no commit rewrites the others. Retires with the caller.\n */\nexport const NestedCallDoc = defineDocFamily<NestedCallState, null>({\n\tkind: \"pi.tool.nested-call\",\n\tversion: 1,\n\tscope: \"task\",\n\tfamily: true,\n\tinitial: () => ({}),\n\t// The document retires with its task.\n\tcheckpointWhen: () => false,\n});\n\ntype Runtime = TaskRuntime<ToolTaskInput, ToolTaskCheckpoint, ToolTaskResult, ToolHooks>;\ntype Content = (TextContent | ImageContent)[];\n\n/**\n * Built-in tool task: resolves the called tool among its phase agent's tools, validates, runs `beforeTool`, records intent,\n * executes, runs `afterTool`, and settles the result, all in one `call` handler so nothing separates resolution from\n * settlement. `execute` is reached only by recovery and applies the replay rule. A model-issued call settles by\n * appending its result entry; a nested call by writing its result to its caller's `NestedCallDoc`.\n */\nexport const ToolTask = defineTask<ToolTaskInput, ToolTaskCheckpoint, ToolTaskResult, ToolHooks>({\n\tname: \"pi.tool\",\n\tversion: 3,\n\tinitial: () => ({ phase: \"call\" }),\n\t// Version 1 had only model-issued calls, without `kind`; version 3 added `unoffered`, absent in version 2 inputs.\n\tmigrate: (input, checkpoint, fromVersion) => ({\n\t\tinput:\n\t\t\tfromVersion === 1\n\t\t\t\t? { kind: \"model\", ...(input as { assistant: EntryId; callId: string }) }\n\t\t\t\t: (input as ToolTaskInput),\n\t\tcheckpoint: checkpoint as ToolTaskCheckpoint,\n\t}),\n\tphases: {\n\t\tcall: async (task, runtime, context) => {\n\t\t\tconst call = await readCall(runtime, task.input, context);\n\t\t\tif (cutOffTooOften(task, runtime)) return endCutOff(runtime, task, call, context);\n\t\t\tconst tool = isUnoffered(task.input) ? undefined : await resolveTool(runtime, task.input, call.name, context);\n\t\t\tif (tool === undefined) {\n\t\t\t\tconst error = harnessError(\"tool_unavailable\", `Tool ${call.name} is not available`);\n\t\t\t\treturn reject(runtime, task.input, call, undefined, error, context);\n\t\t\t}\n\t\t\tconst prepared = prepare(tool, call.arguments as JsonObject);\n\t\t\tconst checked = \"error\" in prepared ? prepared : validate(tool, call, prepared.args);\n\t\t\tif (\"error\" in checked) return reject(runtime, task.input, call, tool, invalid(checked.error), context);\n\t\t\tlet args = checked.args;\n\t\t\tlet block: string | undefined;\n\t\t\tawait runtime.hooks.each(\"beforeTool\", async (hook) => {\n\t\t\t\tif (block !== undefined) return;\n\t\t\t\ttry {\n\t\t\t\t\tconst decision = await hook({ ...call, arguments: args }, runtime, context);\n\t\t\t\t\tif (decision?.block !== undefined) block = decision.block;\n\t\t\t\t\telse if (decision?.arguments !== undefined) args = decision.arguments;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (runtime.signal.aborted) throw error;\n\t\t\t\t\tblock = errorMessage(error);\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (block !== undefined) {\n\t\t\t\tconst blocked = harnessError(\"blocked\", `Tool call blocked: ${block}`);\n\t\t\t\treturn reject(runtime, task.input, call, tool, blocked, context);\n\t\t\t}\n\t\t\tconst validated = validate(tool, call, args);\n\t\t\tif (\"error\" in validated) return reject(runtime, task.input, call, tool, invalid(validated.error), context);\n\t\t\t// Strict JSON: repair may set optional properties to undefined, which the slot and checkpoint cannot hold.\n\t\t\tconst final = copyJson(validated.args, { omitUndefinedProperties: true }) as JsonObject;\n\t\t\t// The slot's status and arguments are presentation, stored like progress (`PROGRESS_COMMIT`); the intent is\n\t\t\t// durable before the tool runs. Parallel calls of one round then share no immediate write to `pi.live`.\n\t\t\tawait runtime.commit(\n\t\t\t\tasync (tx) => {\n\t\t\t\t\tconst slot = toolSlot(await tx.doc(LiveDoc, runtime.conversationId), runtime.taskId);\n\t\t\t\t\tif (slot !== undefined) slot.status = \"running\";\n\t\t\t\t\t// A nested slot shows the arguments the call runs with, which repair, hooks, and coercion may have changed.\n\t\t\t\t\t// Assigned whole: an equal value records no change, and a rerun corrects what an earlier attempt showed.\n\t\t\t\t\tif (slot !== undefined && \"parentTaskId\" in slot) slot.arguments = final;\n\t\t\t\t\treturn undefined;\n\t\t\t\t},\n\t\t\t\tcontext,\n\t\t\t\tPROGRESS_COMMIT,\n\t\t\t);\n\t\t\tawait runtime.commit(() => {\n\t\t\t\tconst intent = { phase: \"execute\", arguments: final, replay: tool.replay ?? \"unsafe\" } as const;\n\t\t\t\treturn { status: \"running\", checkpoint: intent };\n\t\t\t}, context);\n\t\t\tawait run(runtime, task.input, call, tool, final, context);\n\t\t},\n\t\t/** Recovery after intent: rerun only when the stored and the current policy both say `safe`. */\n\t\texecute: async (task, runtime, context) => {\n\t\t\tconst { arguments: args, replay } = task.state.checkpoint;\n\t\t\tconst call = await readCall(runtime, task.input, context);\n\t\t\t// Also before an interruption result: its `afterTool` hooks may be what cut the task off.\n\t\t\tif (cutOffTooOften(task, runtime)) return endCutOff(runtime, task, call, context);\n\t\t\tconst tool = await resolveTool(runtime, task.input, call.name, context);\n\t\t\tif (replay === \"safe\" && tool?.replay === \"safe\") {\n\t\t\t\t// The rerun reports from scratch: clear what the interrupted attempt published, and show the slot running with\n\t\t\t\t// the arguments it runs with again, as the deferred commit that showed them may have been lost with the crash.\n\t\t\t\tawait runtime.commit(async (tx) => {\n\t\t\t\t\tconst slot = toolSlot(await tx.doc(LiveDoc, runtime.conversationId), runtime.taskId);\n\t\t\t\t\tif (slot !== undefined) {\n\t\t\t\t\t\tclearProgress(slot);\n\t\t\t\t\t\tslot.status = \"running\";\n\t\t\t\t\t\tif (\"parentTaskId\" in slot) slot.arguments = args;\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t}, context);\n\t\t\t\treturn run(runtime, task.input, call, tool, args, context);\n\t\t\t}\n\t\t\tconst message = `Tool ${call.name} was interrupted and may have partially run`;\n\t\t\t// `failed` records cancellation intent, so the call's owned conversations, left unsupervised, are aborted.\n\t\t\tconst ending = { status: \"failed\", message } as const;\n\t\t\t// Not cut off too often (checked above), so the hooks run.\n\t\t\tawait settleFromSlot(runtime, task.input, call, { tool }, ending, \"interrupted\", message, context);\n\t\t},\n\t},\n\tabort: async (task, runtime, context) => {\n\t\tconst call = await readCall(runtime, task.input, context);\n\t\t// Abandoned after a restart (`TaskOptions.abandonOnRestart`): say whether the call may have run. An unoffered call\n\t\t// could not run in any case, and its result says so.\n\t\tconst [code, message] = isUnoffered(task.input)\n\t\t\t? [\"tool_unavailable\", `Tool ${call.name} is not available`]\n\t\t\t: task.abortReason !== \"restart\"\n\t\t\t\t? [\"aborted\", `Tool ${call.name} was aborted`]\n\t\t\t\t: task.state.checkpoint.phase === \"execute\"\n\t\t\t\t\t? [\"interrupted\", `Tool ${call.name} was interrupted by a restart and may have partially run`]\n\t\t\t\t\t: [\"abandoned\", `Tool ${call.name} was not started: its caller ended with a restart`];\n\t\t// The scheduler runs an abort handler only while its restarts are below the limit, and faults the task without a\n\t\t// result when the last attempt is cut off. That attempt skips the hooks, which may be what cuts it off.\n\t\tconst hooks =\n\t\t\t(task.restarts ?? 0) < runtime.settings.restartLimit - 1\n\t\t\t\t? { tool: await toolForLimits(runtime, task.input, call.name, context) }\n\t\t\t\t: undefined;\n\t\tawait settleFromSlot(runtime, task.input, call, hooks, { status: \"aborted\" }, code, message, context);\n\t},\n});\n\n/**\n * End a call cut off `settings.restartLimit` times in a row (spec §5.4) with an error result, built from the slot like\n * an interrupted call's, instead of running it again. `failed`, like an interruption, so its owned work is aborted.\n */\nasync function endCutOff(\n\truntime: Runtime,\n\ttask: { readonly restarts?: number; readonly input: ToolTaskInput },\n\tcall: ToolHookCall,\n\tcontext: Context,\n): Promise<void> {\n\tconst message = `Tool ${call.name} was interrupted ${cutOffCount(task)}; it is not run again`;\n\tconst ending = { status: \"failed\", message, reason: \"restart_limit\" } as const;\n\t// Past the limit the hooks may be what keeps cutting the task off (`salvageable`).\n\tconst hooks = salvageable(task, runtime)\n\t\t? { tool: await toolForLimits(runtime, task.input, call.name, context) }\n\t\t: undefined;\n\tawait settleFromSlot(runtime, task.input, call, hooks, ending, \"restart_limit\", message, context);\n}\n\n/**\n * Settle a result the Harness decided in the `call` phase, without running the tool: the tool did not resolve, the\n * arguments are invalid, or `beforeTool` blocked the call. `afterTool` applies as to an executed call's result.\n */\nasync function reject(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\ttool: ToolRegistration | undefined,\n\tresult: ToolExecutionResult,\n\tcontext: Context,\n): Promise<void> {\n\tconst settled = await afterHarnessResult(runtime, input, call, tool, result, undefined, context);\n\tawait settle(runtime, input, call, COMPLETED, settled, context);\n}\n\n/**\n * Settle an error result built from the call's slot (`fromSlot`): an interruption, the restart limit, or an abort.\n * The tool is not running, so the slot read before the commit is still current when it commits. With `hooks`, the\n * result passes `afterTool` and is bounded with the limits of `hooks.tool` (the defaults when it is `undefined`);\n * without, it is settled as built, when the hooks may be what cuts the task off.\n */\nasync function settleFromSlot(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\thooks: { readonly tool: ToolRegistration | undefined } | undefined,\n\tending: Ending,\n\tcode: string,\n\tmessage: string,\n\tcontext: Context,\n): Promise<void> {\n\tconst live = await runtime.snapshot(LiveDoc, runtime.conversationId, context);\n\tconst { result, truncation } = fromSlot(\n\t\tlive === undefined ? undefined : toolSlot(live, runtime.taskId),\n\t\tcode,\n\t\tmessage,\n\t);\n\tconst settled =\n\t\thooks !== undefined\n\t\t\t? await afterHarnessResult(runtime, input, call, hooks.tool, result, truncation, context)\n\t\t\t: truncation === undefined\n\t\t\t\t? result\n\t\t\t\t: { ...result, diagnostics: [...(result.diagnostics ?? []), truncation] };\n\tawait settle(runtime, input, call, ending, settled, context);\n}\n\n/**\n * The tool whose output limits bound a hooks' result: the called tool, or none when it, or the agent, fails to resolve,\n * and for an unoffered call, which never resolves its name.\n */\nasync function toolForLimits(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tname: string,\n\tcontext: Context,\n): Promise<ToolRegistration | undefined> {\n\tif (isUnoffered(input)) return undefined;\n\treturn resolveTool(runtime, input, name, context).catch(() => undefined);\n}\n\n/** A model-issued call to a tool its request did not offer (spec §8.3). */\nfunction isUnoffered(input: ToolTaskInput): boolean {\n\treturn input.kind === \"model\" && input.unoffered === true;\n}\n\n/** The called tool: among the tools the model is offered for a model-issued call, else among those tools may call. */\nasync function resolveTool(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tname: string,\n\tcontext: Context,\n): Promise<ToolRegistration | undefined> {\n\tconst agent = await runtime.agent(context);\n\treturn (input.kind === \"model\" ? agent.tools : agent.callable).find((tool) => tool.name === name);\n}\n\n/** The tool's output limits, the defaults filled in; all defaults when the tool did not resolve. */\nfunction outputLimits(tool: ToolRegistration | undefined): OutputLimits {\n\treturn {\n\t\tmaxBytes: tool?.outputLimits?.maxBytes ?? DEFAULT_MAX_BYTES,\n\t\tmaxLines: tool?.outputLimits?.maxLines ?? DEFAULT_MAX_LINES,\n\t\tretain: tool?.outputLimits?.retain ?? \"head\",\n\t};\n}\n\n/** The call: from the input for a nested call, which hooks see with its parent, else from the assistant entry. */\nasync function readCall(runtime: Runtime, input: ToolTaskInput, context: Context): Promise<ToolHookCall> {\n\tif (input.kind === \"nested\") {\n\t\tcontext.telemetry.setAttributes({\n\t\t\t\"tool.name\": input.call.name,\n\t\t\t\"tool.call_id\": input.call.id,\n\t\t});\n\t\treturn { ...input.call, parent: { taskId: input.parent, callId: input.parentCallId } };\n\t}\n\tconst entry = await runtime.entry(AssistantEntry, input.assistant, context);\n\tconst message = entry?.model?.[0];\n\tconst call =\n\t\tmessage?.role === \"assistant\"\n\t\t\t? message.content.find(\n\t\t\t\t\t(content): content is ToolCall => content.type === \"toolCall\" && content.id === input.callId,\n\t\t\t\t)\n\t\t\t: undefined;\n\tif (call === undefined) throw new Error(`Entry ${input.assistant} has no tool call ${input.callId}`);\n\tcontext.telemetry.setAttributes({\n\t\t\"tool.name\": call.name,\n\t\t\"tool.call_id\": call.id,\n\t});\n\treturn call;\n}\n\n/** Arguments, or why they are invalid. */\ntype Checked = { readonly args: JsonObject } | { readonly error: string };\n\n/** The call's arguments as repaired by the tool; a throwing repair makes them invalid. */\nfunction prepare(tool: ToolRegistration, args: JsonObject): Checked {\n\tif (tool.prepareArguments === undefined) return { args };\n\ttry {\n\t\treturn { args: tool.prepareArguments(args) as JsonObject };\n\t} catch (error) {\n\t\treturn { error: errorMessage(error) };\n\t}\n}\n\n/** Arguments validated and coerced against the implementation's schema. */\nfunction validate(tool: ToolRegistration, call: ToolCall, args: JsonObject): Checked {\n\ttry {\n\t\treturn { args: validateToolArguments(tool, { ...call, arguments: args }) as JsonObject };\n\t} catch (error) {\n\t\treturn { error: errorMessage(error) };\n\t}\n}\n\nfunction invalid(message: string): ToolExecutionResult {\n\treturn harnessError(\"invalid_arguments\", message);\n}\n\n/** What a running tool reported through its api: output, the last details, and diagnostics. */\ntype Reported = {\n\treadonly output: OutputBuffer;\n\treadonly limits: OutputLimits;\n\treadonly diagnostics: ToolDiagnostic[];\n\tdetails: JsonValue | undefined;\n};\n\n/** Execute with the resolved implementation, then settle its result. */\nasync function run(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\ttool: ToolRegistration,\n\targs: JsonObject,\n\tcontext: Context,\n): Promise<void> {\n\tconst limits = outputLimits(tool);\n\tconst reported: Reported = { output: new OutputBuffer(limits), limits, diagnostics: [], details: undefined };\n\tconst streams = input.kind === \"model\" || input.progress !== false;\n\tconst progress = publishProgress(runtime, reported, streams, context);\n\t/** Nested call admissions this invocation started; cleanup waits for them, so it sees every nested call. */\n\tconst admissions: Promise<unknown>[] = [];\n\t// A caller that can rerun reattaches to its nested calls and child tasks after a restart; any other caller never\n\t// resumes, so they are abandoned (`TaskOptions.abandonOnRestart`).\n\tconst resumes = tool.replay === \"safe\";\n\t/** Default keys: the order of this invocation's calls, so a rerun that calls in the same order reattaches. */\n\tlet sequence = 0;\n\t/** This attempt's commit of the `MADE_NESTED_CALLS` memo. */\n\tlet madeNestedMemo: Promise<unknown> | undefined;\n\tlet ended = false;\n\tconst assertLive = (): void => {\n\t\tif (ended) throw new Error(`Tool call ${call.id} has settled`);\n\t};\n\t/** Built for this call, below, so a rerun after recovery gets the conversation's environment at that time. */\n\tlet env: ExecutionEnv | undefined;\n\tconst api: ToolExecutionApi = {\n\t\ttaskId: runtime.taskId,\n\t\tconversationId: runtime.conversationId,\n\t\tcallId: call.id,\n\t\tregistry: runtime.registry,\n\t\tagent: runtime.agent,\n\t\tget models() {\n\t\t\treturn runtime.models;\n\t\t},\n\t\tget env() {\n\t\t\treturn env;\n\t\t},\n\t\tnow: () => runtime.now(),\n\t\toutput: (chunk, skipped) => {\n\t\t\tassertLive();\n\t\t\tif (reported.output.push(chunk, skipped)) progress.mark();\n\t\t},\n\t\toutputWindow:\n\t\t\tlimits.retain === \"tail\"\n\t\t\t\t? {\n\t\t\t\t\t\tmaxBytes: limits.maxBytes,\n\t\t\t\t\t\tmaxLines: limits.maxLines,\n\t\t\t\t\t\tminIntervalMs: runtime.settings.progress.outputIntervalMs,\n\t\t\t\t\t\tbytesPerSecond: PROGRESS_BYTES_PER_SECOND,\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\tretainedOutput: () => {\n\t\t\tassertLive();\n\t\t\tconst retained = reported.output.snapshot();\n\t\t\treturn { text: retained.text, truncated: retained.droppedBytes > 0 };\n\t\t},\n\t\tdiagnostic: (diagnostic) => {\n\t\t\tassertLive();\n\t\t\treported.diagnostics.push(copyJson(diagnostic, { omitUndefinedProperties: true }) as ToolDiagnostic);\n\t\t\tprogress.mark();\n\t\t},\n\t\tdetails: async (value, detailsContext) => {\n\t\t\tassertLive();\n\t\t\tdetailsContext.abortSignal?.throwIfAborted();\n\t\t\treported.details = copyJson(value, { omitUndefinedProperties: true });\n\t\t\tconst committed = progress.markAndWait();\n\t\t\t// Cancelling the wait leaves the update in place; the commit's own outcome stays observed.\n\t\t\tcommitted.catch(() => {});\n\t\t\treturn awaitWithContext(committed, detailsContext);\n\t\t},\n\t\tcommit: async (change, commitContext, options) => {\n\t\t\tlet result: Awaited<ReturnType<typeof change>> | undefined;\n\t\t\tawait runtime.commit(\n\t\t\t\tasync (tx) => {\n\t\t\t\t\tresult = await change(tx);\n\t\t\t\t\treturn undefined;\n\t\t\t\t},\n\t\t\t\tcommitContext,\n\t\t\t\toptions,\n\t\t\t);\n\t\t\treturn result as Awaited<ReturnType<typeof change>>;\n\t\t},\n\t\tmemo: runtime.memo,\n\t\tcreateTask: async <I, S extends { phase: string }, R, H extends object>(\n\t\t\ttask: Task<I, S, R, H>,\n\t\t\tinput: I,\n\t\t\toptions: Omit<TaskOptions, \"conversationId\">,\n\t\t\ttaskContext: Context,\n\t\t): Promise<TaskId<R>> => {\n\t\t\tconst child = options.ownership.kind === \"task\" && !resumes ? { abandonOnRestart: true, ...options } : options;\n\t\t\tlet id: TaskId<R> | undefined;\n\t\t\tawait runtime.commit(async (tx) => {\n\t\t\t\tid = await tx.createTask(task, input, child);\n\t\t\t\treturn undefined;\n\t\t\t}, taskContext);\n\t\t\treturn id!;\n\t\t},\n\t\tgetTask: runtime.getTask,\n\t\twaitForTask: runtime.waitForTask,\n\t\tconversation: runtime.conversation,\n\t\tsnapshot: runtime.snapshot,\n\t\tsnapshotAsOf: runtime.snapshotAsOf,\n\t\twatchDoc: runtime.watchDoc,\n\t\texecuteTool: async (name, toolArgs, callContext, options = {}) => {\n\t\t\tassertLive();\n\t\t\tconst key = options.key ?? String(++sequence);\n\t\t\tif (options.key !== undefined) checkKey(options.key);\n\t\t\t// The memo first, once per attempt; a failed one is tried again by the next call.\n\t\t\tmadeNestedMemo ??= runtime.memo(MADE_NESTED_CALLS, true, callContext).catch((error: unknown) => {\n\t\t\t\tmadeNestedMemo = undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\t// Registered now, so cleanup waits for it.\n\t\t\tconst admission = madeNestedMemo.then(() =>\n\t\t\t\tstartNestedCall(\n\t\t\t\t\truntime,\n\t\t\t\t\tcall.id,\n\t\t\t\t\tname,\n\t\t\t\t\ttoolArgs,\n\t\t\t\t\t{ key, progress: options.progress, abandonOnRestart: !resumes },\n\t\t\t\t\tcallContext,\n\t\t\t\t),\n\t\t\t);\n\t\t\tadmissions.push(admission);\n\t\t\tconst id = await admission;\n\t\t\tconst settled = await runtime.waitForTask(id, callContext);\n\t\t\tconst stored = (await runtime.snapshot(NestedCallDoc, runtime.taskId, key, callContext))?.result;\n\t\t\t// A copy the tool may change; a nested call the scheduler faulted or orphaned stored none.\n\t\t\treturn stored === undefined\n\t\t\t\t? fallbackResult(id, name, settled.state.outcome)\n\t\t\t\t: (copyJson(stored as unknown as JsonValue) as unknown as NestedToolExecutionResult);\n\t\t},\n\t};\n\n\tlet result: ToolExecutionResult;\n\tlet ending = COMPLETED;\n\t// Execution time of this attempt; a rerun after recovery measures only itself.\n\tlet durationMs: number | undefined;\n\ttry {\n\t\tenv = await runtime.env(context);\n\t\tconst startedAt = performance.now();\n\t\ttry {\n\t\t\tresult = await tool.execute(args, api, context);\n\t\t} finally {\n\t\t\tdurationMs = Math.round(performance.now() - startedAt);\n\t\t}\n\t} catch (error) {\n\t\tif (runtime.signal.aborted) {\n\t\t\tended = true;\n\t\t\tfor (const waiter of await progress.stop()) waiter.reject(error);\n\t\t\tthrow error;\n\t\t}\n\t\tresult = { isError: true, diagnostics: [toolDiagnostic(\"tool_error\", errorMessage(error))] };\n\t\t// A throw, from `execute()` or from building the environment, ends the task `failed`, which cancels what the call\n\t\t// owned; it no longer supervises it. The error text is already in the result.\n\t\tending = { status: \"failed\", message: `Tool ${call.name} threw` };\n\t}\n\tended = true;\n\t// No admission starts after `ended`; let those underway commit, so settlement aborts and lists their calls.\n\tawait Promise.allSettled(admissions);\n\treported.output.end();\n\t// Details still waiting for a progress commit settle with the terminal commit, the final flush.\n\tconst pending = await progress.stop();\n\ttry {\n\t\tconst settled = await finalResult(runtime, input, call, tool, result, reported, context);\n\t\tawait settle(runtime, input, call, ending, settled, context, durationMs);\n\t} catch (error) {\n\t\tfor (const waiter of pending) waiter.reject(error);\n\t\tthrow error;\n\t}\n\tfor (const waiter of pending) waiter.resolve();\n}\n\n/**\n * The Harness clock and timers for progress pacing. After the invocation ends nothing more commits, and the clock\n * answers with the last time it read.\n */\nfunction progressClock(runtime: Runtime): ProgressClock {\n\tlet last = 0;\n\treturn {\n\t\tnow: () => {\n\t\t\ttry {\n\t\t\t\tlast = runtime.now();\n\t\t\t} catch {\n\t\t\t\t// The invocation ended.\n\t\t\t}\n\t\t\treturn last;\n\t\t},\n\t\tsetTimer: (callback, delayMs) => runtime.setTimer(callback, delayMs),\n\t};\n}\n\n/**\n * Throttled commits of what the tool reported into its slot, in `pi.live.tools` or `pi.live.nestedTools`, each writing\n * only what changed since the last one, deferred (`PROGRESS_COMMIT`); none when `enabled` is false.\n */\nfunction publishProgress(runtime: Runtime, reported: Reported, enabled: boolean, context: Context): Progress {\n\tlet written = { text: \"\", details: undefined as JsonValue | undefined, diagnostics: 0 };\n\treturn new Progress(\n\t\tasync () => {\n\t\t\tif (!enabled) return 0;\n\t\t\t// Capture everything synchronously: the tool keeps reporting while the commit is in flight.\n\t\t\tconst snapshot = reported.output.snapshot();\n\t\t\tconst current = { text: snapshot.text, details: reported.details, diagnostics: reported.diagnostics.length };\n\t\t\tconst added = reported.diagnostics.slice(written.diagnostics, current.diagnostics);\n\t\t\tconst detailsChanged = current.details !== written.details;\n\t\t\t// What the commit writes, as Chord diffs the string: an append, a trim plus an append of what follows the shared\n\t\t\t// part, or the whole window when its bounded overlap search finds nothing.\n\t\t\tlet bytes = 0;\n\t\t\tif (snapshot.text !== written.text) {\n\t\t\t\tconst shared = snapshot.text.startsWith(written.text)\n\t\t\t\t\t? written.text.length\n\t\t\t\t\t: overlap(written.text, snapshot.text, 65_536);\n\t\t\t\tbytes += utf8ByteLength(snapshot.text.slice(shared));\n\t\t\t}\n\t\t\tif (detailsChanged) bytes += utf8ByteLength(JSON.stringify(current.details ?? null));\n\t\t\tif (added.length > 0) bytes += utf8ByteLength(JSON.stringify(added));\n\t\t\tawait runtime.commit(\n\t\t\t\tasync (tx) => {\n\t\t\t\t\tconst slot = toolSlot(await tx.doc(LiveDoc, runtime.conversationId), runtime.taskId);\n\t\t\t\t\tif (slot === undefined) return undefined;\n\t\t\t\t\t// REMINDER: assign `output` as one string field. Chord then diffs it into an append, or a trim plus an\n\t\t\t\t\t// append for a sliding tail; replacing the slot object would record the whole window on every commit.\n\t\t\t\t\tif ((slot.output ?? \"\") !== snapshot.text) slot.output = snapshot.text;\n\t\t\t\t\tif (snapshot.droppedBytes > 0) slot.droppedBytes = snapshot.droppedBytes;\n\t\t\t\t\tif (snapshot.droppedLines > 0) slot.droppedLines = snapshot.droppedLines;\n\t\t\t\t\t// Diff details leaf by leaf and append new diagnostics, so each commit writes only what changed.\n\t\t\t\t\tif (detailsChanged && current.details !== undefined) {\n\t\t\t\t\t\tassignJson(slot, \"details\", current.details);\n\t\t\t\t\t}\n\t\t\t\t\tif (added.length > 0) {\n\t\t\t\t\t\tif (slot.diagnostics === undefined) slot.diagnostics = [];\n\t\t\t\t\t\tfor (const diagnostic of added) slot.diagnostics.push(diagnostic);\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t},\n\t\t\t\tcontext,\n\t\t\t\tPROGRESS_COMMIT,\n\t\t\t);\n\t\t\twritten = current;\n\t\t\treturn bytes;\n\t\t},\n\t\t(error) => {\n\t\t\t// Rejections after an abort mark or close are expected; the committed state stays consistent.\n\t\t\tif (!runtime.signal.aborted) runtime.report(error);\n\t\t},\n\t\truntime.settings.progress.outputIntervalMs,\n\t\tprogressClock(runtime),\n\t);\n}\n\n/**\n * The settled result: the tool's result with the retained output and last details as fallbacks, its diagnostics after\n * those reported through the api, `afterTool` applied, explicit text bounded, and `structuredOutput` checked against the\n * tool's schema, with the Harness's diagnostics last. A nested call whose `structuredOutput` breaks the contract gets an\n * error result without it; a model-issued call only loses it, and the break is reported to the host.\n */\nasync function finalResult(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\ttool: ToolRegistration,\n\tresult: ToolExecutionResult,\n\treported: Reported,\n\tcontext: Context,\n): Promise<ToolExecutionResult> {\n\tconst harness: ToolDiagnostic[] = [];\n\tconst retained = result.output === undefined ? reported.output.snapshot() : undefined;\n\tconst output: Content =\n\t\tretained === undefined ? result.output! : retained.text === \"\" ? [] : [{ type: \"text\", text: retained.text }];\n\tlet final: ToolExecutionResult = {\n\t\t...result,\n\t\toutput,\n\t\tdetails: result.details === undefined ? reported.details : result.details,\n\t\tdiagnostics: [...reported.diagnostics, ...(result.diagnostics ?? [])],\n\t};\n\tawait runtime.hooks.each(\"afterTool\", async (hook) => {\n\t\tfinal = (await hook(call, final, runtime, context)) ?? final;\n\t});\n\t// The retained output's truncation applies only while afterTool kept that output.\n\tif (retained !== undefined && retained.droppedBytes > 0 && final.output === output) {\n\t\tharness.push(truncated(retained, reported.limits.retain));\n\t}\n\tconst bounded = boundContent(final.output ?? [], reported.limits);\n\tif (bounded.droppedBytes > 0) harness.push(truncated(bounded, reported.limits.retain));\n\tconst broken = structuredOutputError(tool, final);\n\tif (broken !== undefined) {\n\t\tconst { structuredOutput: _dropped, ...rest } = final;\n\t\tif (input.kind === \"nested\") {\n\t\t\tfinal = { ...rest, isError: true };\n\t\t\tharness.push(toolDiagnostic(\"invalid_structured_output\", broken));\n\t\t} else {\n\t\t\t// The model never sees structured output, so its call stands; the host learns of the broken tool.\n\t\t\tfinal = rest;\n\t\t\t// Only names the extension: a failed resolution leaves the report without the name.\n\t\t\tconst extension = await runtime.agent(context).then(\n\t\t\t\t(agent) => toolExtension(agent, tool.name),\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\truntime.report(new Error(broken), { kind: \"extension\", ...optionalExtension(extension) });\n\t\t}\n\t}\n\t// Programs get the tool's own value: without a schema, its output. The model reads only `output`, so model-issued\n\t// calls skip both.\n\tif (input.kind === \"nested\" && tool.structuredOutputSchema === undefined) {\n\t\tfinal = { ...final, structuredOutput: outputValue(bounded.content) as JsonValue };\n\t}\n\t// A schema tool's error result without structured output has its text only in the output, which programs never\n\t// get: it becomes an error diagnostic, as a thrown error's message does, unless one says what went wrong already.\n\tif (\n\t\tinput.kind === \"nested\" &&\n\t\ttool.structuredOutputSchema !== undefined &&\n\t\tfinal.isError === true &&\n\t\tfinal.structuredOutput === undefined &&\n\t\t![...(final.diagnostics ?? []), ...harness].some((diagnostic) => diagnostic.severity === \"error\")\n\t) {\n\t\tconst text = bounded.content.flatMap((item) => (item.type === \"text\" ? [item.text] : [])).join(\"\\n\");\n\t\tif (text !== \"\") harness.push(toolDiagnostic(\"tool_error\", text));\n\t}\n\treturn { ...final, output: bounded.content, diagnostics: [...(final.diagnostics ?? []), ...harness] };\n}\n\n/**\n * A result the Harness wrote itself, without executing the tool, after the `afterTool` chain, normalized like an\n * executed call's: the output bounded with the tool's limits (the defaults when it did not resolve), a truncation\n * diagnostic when that dropped something, and the hooks' `structuredOutput` dropped, since the tool never produced\n * one. A nested call that the hooks turned into a success gets the bounded output as its value, as a schema-less\n * tool's success does, unless the tool declares a schema. `usage` is kept and recorded; `control` applies only when\n * the task completes. `truncation` describes what the result's own output lost before (a slot's retained output); it\n * is kept only while the hooks keep that output.\n */\nasync function afterHarnessResult(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\ttool: ToolRegistration | undefined,\n\tresult: ToolExecutionResult,\n\ttruncation: ToolDiagnostic | undefined,\n\tcontext: Context,\n): Promise<ToolExecutionResult> {\n\tlet final = result;\n\tawait runtime.hooks.each(\"afterTool\", async (hook) => {\n\t\tfinal = (await hook(call, final, runtime, context)) ?? final;\n\t});\n\tconst harness: ToolDiagnostic[] = [];\n\tif (truncation !== undefined && final.output === result.output) harness.push(truncation);\n\tconst limits = outputLimits(tool);\n\tconst bounded = boundContent(final.output ?? [], limits);\n\tif (bounded.droppedBytes > 0) harness.push(truncated(bounded, limits.retain));\n\tconst { structuredOutput: _dropped, ...rest } = final;\n\tconst value =\n\t\tinput.kind === \"nested\" && final.isError !== true && tool?.structuredOutputSchema === undefined\n\t\t\t? { structuredOutput: outputValue(bounded.content) as JsonValue }\n\t\t\t: {};\n\treturn { ...rest, ...value, output: bounded.content, diagnostics: [...(rest.diagnostics ?? []), ...harness] };\n}\n\nconst structuredValidators = new WeakMap<object, Validator>();\n\n/** Why a result's `structuredOutput` breaks the tool's contract, or `undefined` when it keeps it. */\nfunction structuredOutputError(tool: ToolRegistration, result: ToolExecutionResult): string | undefined {\n\tconst schema = tool.structuredOutputSchema;\n\tconst value = result.structuredOutput;\n\tif (schema === undefined) {\n\t\treturn value === undefined\n\t\t\t? undefined\n\t\t\t: `Tool ${tool.name} returned structuredOutput but declares no structuredOutputSchema`;\n\t}\n\tif (value === undefined) {\n\t\treturn result.isError === true ? undefined : `Tool ${tool.name} returned no structuredOutput`;\n\t}\n\tlet validator = structuredValidators.get(schema);\n\tif (validator === undefined) {\n\t\tvalidator = compile(schema, { formats, unresolvedRefs: \"reject\" });\n\t\tstructuredValidators.set(schema, validator);\n\t}\n\tif (validator.check(value)) return undefined;\n\tconst [first] = validator.errors(value);\n\tconst path =\n\t\tfirst?.path\n\t\t\t.slice(1)\n\t\t\t.split(\"/\")\n\t\t\t.map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"))\n\t\t\t.join(\".\") || \"root\";\n\treturn `Tool ${tool.name} returned structuredOutput that does not match its schema: ${path}: ${first?.message ?? \"invalid\"}`;\n}\n\n/**\n * Commit the tool's terminal state and mark its slot done. A model-issued call appends its result entry and ends with\n * the entry ID; a nested call writes its result to the caller's `NestedCallDoc`, records its usage, and ends with a\n * small receipt. Nested calls this call left running are aborted first, so they report into their slots before the\n * slots below the call leave `pi.live`. `control` applies only when the task completes.\n */\nasync function settle(\n\truntime: Runtime,\n\tinput: ToolTaskInput,\n\tcall: ToolHookCall,\n\tending: Ending,\n\tresult: ToolExecutionResult,\n\tcontext: Context,\n\tdurationMs?: number,\n): Promise<void> {\n\t// A crash in between leaves the call in `execute`: a safe rerun reattaches to the calls, an interruption ends here.\n\t// Every live nested call the task owns, also those an earlier attempt made and this one never called again.\n\tconst nestedIds = (await runtime.ownedTasks(context))\n\t\t.filter((record) => record.kind === ToolTask.definition.name && (record.input as ToolTaskInput).kind === \"nested\")\n\t\t.map((record) => record.id);\n\t// Read before the settling commit: no admission starts after `ended`, and those underway were awaited.\n\tconst madeNested = (await runtime.memo(MADE_NESTED_CALLS, context)) === true;\n\t// Mark them all before waiting for any: one may run until a sibling is cancelled.\n\tawait Promise.all(nestedIds.map((id) => runtime.abortOwned(id, context)));\n\tawait runtime.commit(async (tx) => {\n\t\tconst conversationId = runtime.conversationId;\n\t\tconst live = await tx.doc(LiveDoc, conversationId);\n\t\tconst slot = toolSlot(live, runtime.taskId);\n\t\tlet settled: ToolTaskResult;\n\t\tif (input.kind === \"nested\") {\n\t\t\tconst nested = nestedResult(runtime.taskId, result, durationMs);\n\t\t\tif (nested.usage !== undefined) await recordUsage(tx, conversationId, \"tools\", call.name, nested.usage);\n\t\t\t// The caller is never terminal before its owned nested calls, so its document is open; another task in it is a\n\t\t\t// bug, not a race.\n\t\t\tconst state = await tx.doc(NestedCallDoc, input.parent, input.key, null);\n\t\t\tif (state.taskId !== runtime.taskId) throw new Error(`Nested call ${call.id} is not in its caller's index`);\n\t\t\tstate.result = nested as unknown as Draft<JsonRepresentation<NestedToolExecutionResult>>;\n\t\t\tif (slot !== undefined && \"parentTaskId\" in slot) {\n\t\t\t\tfinishSlot(slot);\n\t\t\t\tslot.summary = summaryOf(nested, result.output ?? []);\n\t\t\t}\n\t\t\tsettled = { kind: \"nested\" };\n\t\t} else {\n\t\t\tconst timing = { timestamp: runtime.now(), durationMs };\n\t\t\tconst entry = await appendToolResult(tx, conversationId, call, result, timing);\n\t\t\tif (slot !== undefined && !(\"parentTaskId\" in slot)) {\n\t\t\t\tfinishSlot(slot);\n\t\t\t\tslot.entry = entry.id;\n\t\t\t}\n\t\t\t// Tools build control objects freely; drop keys set to undefined so the task result is strict JSON.\n\t\t\tconst control =\n\t\t\t\tresult.control === undefined || ending.status !== \"completed\"\n\t\t\t\t\t? {}\n\t\t\t\t\t: { control: copyJson(result.control as JsonValue, { omitUndefinedProperties: true }) as ToolControl };\n\t\t\tsettled = { kind: \"model\", entryId: entry.id, ...control };\n\t\t}\n\t\t// A call that made no nested calls, in any attempt, has no slots below it; skipping the scan keeps many leaves\n\t\t// linear. Committed before the read: no nested call is admitted after `ended`.\n\t\tif (madeNested) removeNestedSlots(live, runtime.taskId);\n\t\tif (ending.status === \"aborted\") return { status: \"terminal\", outcome: { status: \"aborted\", result: settled } };\n\t\tif (ending.status === \"failed\") {\n\t\t\tconst error = {\n\t\t\t\tmessage: ending.message,\n\t\t\t\t...(ending.reason === undefined ? {} : { detail: { reason: ending.reason } }),\n\t\t\t};\n\t\t\treturn { status: \"terminal\", outcome: { status: \"failed\", error, result: settled } };\n\t\t}\n\t\treturn { status: \"terminal\", outcome: { status: \"completed\", result: settled } };\n\t}, context);\n}\n\n/**\n * A nested call's result, as stored and returned: strict JSON, without `output`, which only the model reads, and\n * without `control`, which only model-issued calls apply.\n */\nfunction nestedResult(\n\ttaskId: TaskId,\n\tresult: ToolExecutionResult,\n\tdurationMs: number | undefined,\n): NestedToolExecutionResult {\n\tconst nested = {\n\t\ttaskId,\n\t\tstructuredOutput: result.structuredOutput,\n\t\tisError: result.isError ?? false,\n\t\tdetails: result.details,\n\t\tdiagnostics: result.diagnostics ?? [],\n\t\tusage: result.usage,\n\t\tdurationMs,\n\t};\n\treturn copyJson(nested as unknown as JsonValue, {\n\t\tomitUndefinedProperties: true,\n\t}) as unknown as NestedToolExecutionResult;\n}\n\n/**\n * Create nested call `key` of the call `parentCallId` in one commit: its tool task, owned by the calling task, its slot,\n * and its `NestedCallDoc`. A key already made returns that call's task when it names the same tool and arguments.\n */\nasync function startNestedCall(\n\truntime: Runtime,\n\tparentCallId: string,\n\tname: string,\n\targs: JsonObject,\n\toptions: { readonly key: string; readonly progress: boolean | undefined; readonly abandonOnRestart: boolean },\n\tcontext: Context,\n): Promise<TaskId<ToolTaskResult>> {\n\tconst key = options.key;\n\tconst call: ToolCall = {\n\t\ttype: \"toolCall\",\n\t\tid: `${parentCallId}/${key}`,\n\t\tname,\n\t\targuments: copyJson(args, { omitUndefinedProperties: true }) as JsonObject,\n\t};\n\tlet id: TaskId<ToolTaskResult> | undefined;\n\tlet replayed = false;\n\tawait runtime.commit(async (tx) => {\n\t\t// Opened, or created empty for a key not made yet.\n\t\tconst state = await tx.doc(NestedCallDoc, runtime.taskId, key, null);\n\t\tconst existing = state.taskId;\n\t\tif (existing !== undefined) {\n\t\t\tconst input = (await tx.task(existing))?.input as ToolTaskInput | undefined;\n\t\t\tconst same =\n\t\t\t\tinput?.kind === \"nested\" &&\n\t\t\t\tinput.call.name === name &&\n\t\t\t\tjsonEqual(input.call.arguments as JsonValue, call.arguments as JsonValue);\n\t\t\tif (!same) throw new Error(`Nested call ${call.id} was already made with another tool or other arguments`);\n\t\t\tid = existing as TaskId<ToolTaskResult>;\n\t\t\treplayed = state.result !== undefined;\n\t\t\treturn undefined;\n\t\t}\n\t\tconst input: ToolTaskInput = {\n\t\t\tkind: \"nested\",\n\t\t\tparent: runtime.taskId,\n\t\t\tparentCallId,\n\t\t\tkey,\n\t\t\tcall,\n\t\t\t...(options.progress === false ? { progress: false } : {}),\n\t\t};\n\t\tconst created = await tx.createTask(ToolTask, input, {\n\t\t\townership: { kind: \"task\", taskId: runtime.taskId },\n\t\t\tabandonOnRestart: options.abandonOnRestart,\n\t\t});\n\t\tstate.taskId = created;\n\t\tconst live = await tx.doc(LiveDoc, runtime.conversationId);\n\t\tlive.nestedTools ??= [];\n\t\tconst slot: NestedToolSlot = {\n\t\t\tcallId: call.id,\n\t\t\tparentCallId,\n\t\t\tparentTaskId: runtime.taskId,\n\t\t\tname,\n\t\t\ttaskId: created,\n\t\t\targuments: call.arguments as JsonObject,\n\t\t\tstatus: \"pending\",\n\t\t};\n\t\tlive.nestedTools.push(slot as Draft<NestedToolSlot>);\n\t\tid = created;\n\t\treturn undefined;\n\t}, context);\n\tif (replayed) {\n\t\tcontext.telemetry.addEvent(\"pi.durable.replay\", { \"tool.name\": name });\n\t}\n\treturn id!;\n}\n\n/**\n * What programs get of a tool's output when it declares no schema: one text item as its string, one image as itself,\n * nothing as `\"\"`, and anything else as the content list.\n */\nfunction outputValue(output: Content): string | ImageContent | Content {\n\tif (output.length === 0) return \"\";\n\tif (output.length > 1) return output;\n\tconst [only] = output;\n\treturn only!.type === \"text\" ? only!.text : only!;\n}\n\n/** What the caller gets for a nested call without a stored result: one the scheduler faulted or orphaned. */\nfunction fallbackResult(taskId: TaskId, name: string, outcome: TaskOutcome<ToolTaskResult>): NestedToolExecutionResult {\n\tconst message =\n\t\toutcome.status === \"faulted\"\n\t\t\t? `Tool ${name} failed: ${outcome.error.message}`\n\t\t\t: outcome.status === \"orphaned\"\n\t\t\t\t? `Tool ${name} could not resume: ${outcome.reason}`\n\t\t\t\t: `Tool ${name} ended without a result`;\n\tconst error = harnessError(outcome.status, message);\n\treturn { taskId, isError: true, diagnostics: error.diagnostics ?? [] };\n}\n\n/**\n * How a tool task ends; the result entry is appended either way. `failed` (execution threw or was interrupted)\n * records cancellation intent for the conversations the call owns; a result with `isError` still completes.\n */\ntype Ending =\n\t| { readonly status: \"completed\" | \"aborted\" }\n\t| { readonly status: \"failed\"; readonly message: string; readonly reason?: string };\n\nconst COMPLETED: Ending = { status: \"completed\" };\n\n/**\n * An error result from the slot's durable partial output, details, and diagnostics, ending with `code`; and the\n * truncation diagnostic of that output, when its bounds dropped some, which the caller adds after `afterTool`.\n */\nfunction fromSlot(\n\tslot: Readonly<ToolSlot | NestedToolSlot> | undefined,\n\tcode: string,\n\tmessage: string,\n): { readonly result: ToolExecutionResult; readonly truncation?: ToolDiagnostic } {\n\tconst droppedBytes = slot?.droppedBytes ?? 0;\n\tconst result: ToolExecutionResult = {\n\t\toutput: slot?.output === undefined || slot.output === \"\" ? [] : [{ type: \"text\", text: slot.output }],\n\t\tisError: true,\n\t\t...(slot?.details === undefined ? {} : { details: slot.details }),\n\t\tdiagnostics: [...(slot?.diagnostics ?? []), toolDiagnostic(code, message)],\n\t};\n\tif (droppedBytes === 0) return { result };\n\treturn { result, truncation: truncated({ droppedBytes, droppedLines: slot?.droppedLines ?? 0 }) };\n}\n\n/** An error result the Harness writes itself: no content and one `error` diagnostic with `code`. */\nexport function harnessError(code: string, message: string): ToolExecutionResult {\n\treturn { output: [], isError: true, diagnostics: [toolDiagnostic(code, message)] };\n}\n\nfunction toolDiagnostic(code: string, message: string): ToolDiagnostic {\n\treturn { severity: \"error\", code, message };\n}\n\n/** The Harness's truncation diagnostic; `retain` is unknown when rebuilt from a slot after recovery. */\nfunction truncated(\n\tdropped: { readonly droppedLines: number; readonly droppedBytes: number },\n\tretain?: \"head\" | \"tail\",\n): ToolDiagnostic {\n\tconst kept = retain === undefined ? \"\" : ` to its ${retain === \"head\" ? \"beginning\" : \"end\"}`;\n\treturn {\n\t\tseverity: \"warn\",\n\t\tcode: \"truncated\",\n\t\tmessage: `Output truncated${kept}: ${dropped.droppedLines} lines, ${dropped.droppedBytes} bytes dropped`,\n\t};\n}\n\n/** Error text a nested call's summary keeps. */\nconst MAX_SUMMARY_ERROR_CHARS = 500;\n\n/**\n * How a nested call ended, for its slot: error text, from its diagnostics or else its `output`, bounded. The bound is a\n * copy, so the slot never keeps a large output alive through a slice of it.\n */\nfunction summaryOf(result: NestedToolExecutionResult, output: Content): NestedToolSummary {\n\tconst error = result.isError ? ownedSlice(errorTextOf(result, output), 0, MAX_SUMMARY_ERROR_CHARS) : \"\";\n\treturn {\n\t\tisError: result.isError,\n\t\t...(result.durationMs === undefined ? {} : { durationMs: result.durationMs }),\n\t\t...(result.usage === undefined ? {} : { usage: result.usage }),\n\t\t...(error === \"\" ? {} : { error }),\n\t};\n}\n\n/** The error messages of a nested result, else the text items of its output, joined with newlines. */\nfunction errorTextOf(result: NestedToolExecutionResult, output: Content): string {\n\tconst errors = result.diagnostics.filter((diagnostic) => diagnostic.severity === \"error\");\n\tif (errors.length > 0) return errors.map((diagnostic) => diagnostic.message).join(\"\\n\");\n\treturn output.flatMap((item) => (item.type === \"text\" ? [item.text] : [])).join(\"\\n\");\n}\n\n/**\n * Append a `pi.tool-result` entry. The content ends with the rendered diagnostics, so the stored message is exactly\n * what the model sees; `data` keeps the structured list. A result's usage is added to `pi.usage` in the same commit.\n */\nexport async function appendToolResult(\n\ttx: Tx,\n\tconversationId: ConversationId,\n\tcall: ToolCall,\n\tresult: ToolExecutionResult,\n\tmeta: { readonly timestamp: number; readonly durationMs?: number },\n): Promise<TypedEntry<{ diagnostics: ToolDiagnostic[] }>> {\n\tconst { timestamp, durationMs } = meta;\n\tconst diagnostics = [...(result.diagnostics ?? [])];\n\tconst content: Content = [...(result.output ?? [])];\n\tif (diagnostics.length > 0) content.push({ type: \"text\", text: renderDiagnostics(diagnostics) });\n\tconst message = {\n\t\trole: \"toolResult\",\n\t\ttoolCallId: call.id,\n\t\ttoolName: call.name,\n\t\tcontent,\n\t\t...(result.details === undefined ? {} : { details: result.details }),\n\t\t...(result.usage === undefined ? {} : { usage: result.usage }),\n\t\tisError: result.isError ?? false,\n\t\t...(durationMs === undefined ? {} : { durationMs }),\n\t\ttimestamp,\n\t} as ToolResultMessage;\n\tif (result.usage !== undefined) await recordUsage(tx, conversationId, \"tools\", call.name, result.usage);\n\treturn tx.appendEntry(ToolResultEntry, conversationId, { model: [message], data: { diagnostics } });\n}\n\nfunction renderDiagnostics(diagnostics: readonly ToolDiagnostic[]): string {\n\treturn `<harness>\\n${diagnostics.map((diagnostic) => `[${diagnostic.severity}] ${diagnostic.message}`).join(\"\\n\")}\\n</harness>`;\n}\n\n/**\n * Bound the text of result content. When the joined text exceeds the limits, the text items are replaced by one bounded\n * item at the position of the first (head) or last (tail) text item; other content is kept.\n */\nfunction boundContent(\n\tcontent: Content,\n\tlimits: OutputLimits,\n): { content: Content; droppedBytes: number; droppedLines: number } {\n\tconst texts = content.filter((item): item is TextContent => item.type === \"text\");\n\tconst bounded = boundOutput(texts.map((item) => item.text).join(\"\"), limits);\n\tif (bounded.droppedBytes === 0) return { content, droppedBytes: 0, droppedLines: 0 };\n\tconst keep = limits.retain === \"head\" ? texts[0] : texts.at(-1);\n\tconst result: Content = [];\n\tfor (const item of content) {\n\t\tif (item.type !== \"text\") result.push(item);\n\t\telse if (item === keep) result.push({ ...item, text: bounded.text });\n\t}\n\treturn { content: result, droppedBytes: bounded.droppedBytes, droppedLines: bounded.droppedLines };\n}\n\n/**\n * Explicit nested call keys are path segments of the call ID, so IDs of different nested calls never collide, and are\n * never plain positive integers, which default keys use. `__proto__` stays reserved, as it was when keys indexed a JSON object.\n */\nfunction checkKey(key: string): void {\n\tif (key === \"\" || key.includes(\"/\") || key === \"__proto__\" || /^[1-9][0-9]*$/.test(key)) {\n\t\tthrow new Error(\n\t\t\t`Nested call key ${JSON.stringify(key)} must be non-empty, without \"/\", not \"__proto__\", and not a positive integer`,\n\t\t);\n\t}\n}\n\n/** Structural JSON equality; object key order does not matter. */\nfunction jsonEqual(a: JsonValue, b: JsonValue): boolean {\n\tif (a === b) return true;\n\tif (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) return false;\n\tif (Array.isArray(a) || Array.isArray(b)) {\n\t\treturn (\n\t\t\tArray.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, i) => jsonEqual(item, b[i]!))\n\t\t);\n\t}\n\tconst keys = Object.keys(a);\n\treturn (\n\t\tkeys.length === Object.keys(b).length && keys.every((key) => Object.hasOwn(b, key) && jsonEqual(a[key]!, b[key]!))\n\t);\n}\n"]}
@@ -0,0 +1,72 @@
1
+ import type { Context } from "@earendil-works/chord/context";
2
+ import type { Cursor, EntryId, EntryQuery, EntryRecord, Page } from "../types.ts";
3
+ import type { ConversationView, ConversationWindow } from "./view.ts";
4
+ /** One row of a client's transcript. */
5
+ export type TranscriptItem = {
6
+ readonly kind: "entry";
7
+ readonly entry: EntryRecord;
8
+ }
9
+ /** Entries strictly between `after` and `upTo` are missing: render "load more" and call `fillGap()`. */
10
+ | {
11
+ readonly kind: "gap";
12
+ readonly after: EntryId;
13
+ readonly upTo: EntryId;
14
+ }
15
+ /** The transcript continues above: render "load earlier" and call `loadEarlier()`. Always the first item. */
16
+ | {
17
+ readonly kind: "earlier";
18
+ };
19
+ /** The conversation view as a renderer sees it: `items`, the client's whole transcript, instead of the window. */
20
+ export type TranscriptView = Omit<ConversationView, "entries" | "before"> & {
21
+ readonly items: readonly TranscriptItem[];
22
+ };
23
+ /** Pages a conversation's entries, as `Conversation.entries()` does without a cursor. */
24
+ export type EntryLoader = (query: Omit<EntryQuery, "conversationId">, limit: number, context: Context) => Promise<Page<EntryRecord, Cursor>>;
25
+ export type ConversationTranscriptOptions = {
26
+ /** Entries `loadEarlier()` and `fillGap()` load per call; default 50. */
27
+ readonly pageSize?: number;
28
+ };
29
+ type Gap = Extract<TranscriptItem, {
30
+ kind: "gap";
31
+ }>;
32
+ /**
33
+ * What a client has of one conversation: every entry it got from a view or fetched, and the gaps between (spec §9.3).
34
+ * A layer over any `ConversationView`, wherever it comes from: call `merge()` with every value of the view; it returns
35
+ * the view with the client's whole transcript as `items` instead of the window. Entries never change once committed,
36
+ * so the transcript only grows; a window that dropped its oldest entries keeps them here.
37
+ *
38
+ * A window whose `before` lies past the newest entry the client has does not continue it, after a stall, an overflow,
39
+ * or a reconnect: the entries in between become a gap. Nothing counts entries or computes ranges from entry IDs, which
40
+ * have holes; only exclusive bounds are turned into the inclusive bounds of `EntryQuery`. After a drop, a new watch
41
+ * with `resume` as its window continues the transcript.
42
+ *
43
+ * A merge costs O(items) and never re-sorts or re-fetches; a merge, `loadEarlier()`, or `fillGap()` that adds nothing
44
+ * returns the previous `items` array. Concurrent calls of `loadEarlier()`, or of `fillGap()` for the same gap, share one
45
+ * load, so a placeholder that stays visible does not fetch twice.
46
+ */
47
+ export declare class ConversationTranscript {
48
+ #private;
49
+ constructor(load: EntryLoader, options?: ConversationTranscriptOptions);
50
+ /**
51
+ * The ID the transcript reaches: its newest entry, or the `before` of a later window that was empty. Undefined before
52
+ * the first merge and for an empty transcript.
53
+ */
54
+ get newest(): EntryId | undefined;
55
+ /**
56
+ * The window that resumes this transcript after a drop: `{ from }` right after `newest`, so a new watch returns only
57
+ * what was missed when it fits its window, otherwise its newest entries and a gap; `{}` for an empty transcript;
58
+ * undefined before the first merge. `conversation.watch(context, transcript.resume)`.
59
+ */
60
+ get resume(): ConversationWindow | undefined;
61
+ /** Take one value of the view: its window's entries join the transcript. */
62
+ merge(view: ConversationView): TranscriptView;
63
+ /** Load the page before the oldest entry held. Without anything earlier, returns the current view. */
64
+ loadEarlier(context: Context): Promise<TranscriptView>;
65
+ /**
66
+ * Load the next page of `gap`, a gap item of `items`, shrinking it from its start, or removing it once nothing is
67
+ * missing. A gap that has shrunk since loads the gap it became; one that is no longer there returns the current view.
68
+ */
69
+ fillGap(gap: Gap, context: Context): Promise<TranscriptView>;
70
+ }
71
+ export {};
72
+ //# sourceMappingURL=transcript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../../src/harness/transcript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEtE,wCAAwC;AACxC,MAAM,MAAM,cAAc,GACvB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAA;CAAE;AACzD,wGAAwG;GACtG;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE;AAC3E,6GAA6G;GAC3G;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAEhC,kHAAkH;AAClH,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,QAAQ,CAAC,GAAG;IAC3E,QAAQ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