@earendil-works/pi-agent-core 0.84.4 → 0.85.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 (343) hide show
  1. package/README.md +4 -0
  2. package/dist/agent-loop.d.ts.map +1 -1
  3. package/dist/agent-loop.js +9 -0
  4. package/dist/agent-loop.js.map +1 -1
  5. package/dist/harness/agent-harness.d.ts +639 -384
  6. package/dist/harness/agent-harness.d.ts.map +1 -1
  7. package/dist/harness/agent-harness.js +5 -251
  8. package/dist/harness/agent-harness.js.map +1 -1
  9. package/dist/harness/compaction/branch-summarization.d.ts +12 -6
  10. package/dist/harness/compaction/branch-summarization.d.ts.map +1 -1
  11. package/dist/harness/compaction/branch-summarization.js +33 -26
  12. package/dist/harness/compaction/branch-summarization.js.map +1 -1
  13. package/dist/harness/compaction/compaction.d.ts +30 -8
  14. package/dist/harness/compaction/compaction.d.ts.map +1 -1
  15. package/dist/harness/compaction/compaction.js +53 -63
  16. package/dist/harness/compaction/compaction.js.map +1 -1
  17. package/dist/harness/config.d.ts +9 -0
  18. package/dist/harness/config.d.ts.map +1 -0
  19. package/dist/harness/config.js +27 -0
  20. package/dist/harness/config.js.map +1 -0
  21. package/dist/harness/context.d.ts +9 -0
  22. package/dist/harness/context.d.ts.map +1 -0
  23. package/dist/harness/context.js +13 -0
  24. package/dist/harness/context.js.map +1 -0
  25. package/dist/harness/env/nodejs.d.ts +24 -28
  26. package/dist/harness/env/nodejs.d.ts.map +1 -1
  27. package/dist/harness/env/nodejs.js +239 -86
  28. package/dist/harness/env/nodejs.js.map +1 -1
  29. package/dist/harness/events.d.ts +20 -38
  30. package/dist/harness/events.d.ts.map +1 -1
  31. package/dist/harness/events.js +240 -55
  32. package/dist/harness/events.js.map +1 -1
  33. package/dist/harness/execution/assistant.d.ts +42 -0
  34. package/dist/harness/execution/assistant.d.ts.map +1 -0
  35. package/dist/harness/execution/assistant.js +82 -0
  36. package/dist/harness/execution/assistant.js.map +1 -0
  37. package/dist/harness/execution/effect-gate.d.ts +22 -0
  38. package/dist/harness/execution/effect-gate.d.ts.map +1 -0
  39. package/dist/harness/execution/effect-gate.js +49 -0
  40. package/dist/harness/execution/effect-gate.js.map +1 -0
  41. package/dist/harness/execution/tools.d.ts +67 -0
  42. package/dist/harness/execution/tools.d.ts.map +1 -0
  43. package/dist/harness/execution/tools.js +121 -0
  44. package/dist/harness/execution/tools.js.map +1 -0
  45. package/dist/harness/hooks.d.ts +38 -0
  46. package/dist/harness/hooks.d.ts.map +1 -0
  47. package/dist/harness/hooks.js +406 -0
  48. package/dist/harness/hooks.js.map +1 -0
  49. package/dist/harness/messages.d.ts +2 -2
  50. package/dist/harness/messages.d.ts.map +1 -1
  51. package/dist/harness/messages.js.map +1 -1
  52. package/dist/harness/prompt-templates.d.ts +3 -2
  53. package/dist/harness/prompt-templates.d.ts.map +1 -1
  54. package/dist/harness/prompt-templates.js +17 -17
  55. package/dist/harness/prompt-templates.js.map +1 -1
  56. package/dist/harness/result.d.ts +93 -0
  57. package/dist/harness/result.d.ts.map +1 -1
  58. package/dist/harness/result.js +40 -0
  59. package/dist/harness/result.js.map +1 -1
  60. package/dist/harness/runtime/drive/boundary.d.ts +28 -0
  61. package/dist/harness/runtime/drive/boundary.d.ts.map +1 -0
  62. package/dist/harness/runtime/drive/boundary.js +170 -0
  63. package/dist/harness/runtime/drive/boundary.js.map +1 -0
  64. package/dist/harness/runtime/drive/checkpoint.d.ts +8 -0
  65. package/dist/harness/runtime/drive/checkpoint.d.ts.map +1 -0
  66. package/dist/harness/runtime/drive/checkpoint.js +133 -0
  67. package/dist/harness/runtime/drive/checkpoint.js.map +1 -0
  68. package/dist/harness/runtime/drive/deferred.d.ts +15 -0
  69. package/dist/harness/runtime/drive/deferred.d.ts.map +1 -0
  70. package/dist/harness/runtime/drive/deferred.js +179 -0
  71. package/dist/harness/runtime/drive/deferred.js.map +1 -0
  72. package/dist/harness/runtime/drive/generation.d.ts +8 -0
  73. package/dist/harness/runtime/drive/generation.d.ts.map +1 -0
  74. package/dist/harness/runtime/drive/generation.js +205 -0
  75. package/dist/harness/runtime/drive/generation.js.map +1 -0
  76. package/dist/harness/runtime/drive/reconcile.d.ts +5 -0
  77. package/dist/harness/runtime/drive/reconcile.d.ts.map +1 -0
  78. package/dist/harness/runtime/drive/reconcile.js +140 -0
  79. package/dist/harness/runtime/drive/reconcile.js.map +1 -0
  80. package/dist/harness/runtime/drive/recovery.d.ts +8 -0
  81. package/dist/harness/runtime/drive/recovery.d.ts.map +1 -0
  82. package/dist/harness/runtime/drive/recovery.js +85 -0
  83. package/dist/harness/runtime/drive/recovery.js.map +1 -0
  84. package/dist/harness/runtime/drive/response.d.ts +23 -0
  85. package/dist/harness/runtime/drive/response.d.ts.map +1 -0
  86. package/dist/harness/runtime/drive/response.js +394 -0
  87. package/dist/harness/runtime/drive/response.js.map +1 -0
  88. package/dist/harness/runtime/drive/retry.d.ts +4 -0
  89. package/dist/harness/runtime/drive/retry.d.ts.map +1 -0
  90. package/dist/harness/runtime/drive/retry.js +37 -0
  91. package/dist/harness/runtime/drive/retry.js.map +1 -0
  92. package/dist/harness/runtime/drive/structural.d.ts +32 -0
  93. package/dist/harness/runtime/drive/structural.d.ts.map +1 -0
  94. package/dist/harness/runtime/drive/structural.js +929 -0
  95. package/dist/harness/runtime/drive/structural.js.map +1 -0
  96. package/dist/harness/runtime/drive/terminal.d.ts +7 -0
  97. package/dist/harness/runtime/drive/terminal.d.ts.map +1 -0
  98. package/dist/harness/runtime/drive/terminal.js +49 -0
  99. package/dist/harness/runtime/drive/terminal.js.map +1 -0
  100. package/dist/harness/runtime/drive/tool-placement.d.ts +14 -0
  101. package/dist/harness/runtime/drive/tool-placement.d.ts.map +1 -0
  102. package/dist/harness/runtime/drive/tool-placement.js +244 -0
  103. package/dist/harness/runtime/drive/tool-placement.js.map +1 -0
  104. package/dist/harness/runtime/drive/tools.d.ts +6 -0
  105. package/dist/harness/runtime/drive/tools.d.ts.map +1 -0
  106. package/dist/harness/runtime/drive/tools.js +449 -0
  107. package/dist/harness/runtime/drive/tools.js.map +1 -0
  108. package/dist/harness/runtime/drive.d.ts +6 -0
  109. package/dist/harness/runtime/drive.d.ts.map +1 -0
  110. package/dist/harness/runtime/drive.js +93 -0
  111. package/dist/harness/runtime/drive.js.map +1 -0
  112. package/dist/harness/runtime/harness.d.ts +59 -0
  113. package/dist/harness/runtime/harness.d.ts.map +1 -0
  114. package/dist/harness/runtime/harness.js +311 -0
  115. package/dist/harness/runtime/harness.js.map +1 -0
  116. package/dist/harness/runtime/index.d.ts +2 -0
  117. package/dist/harness/runtime/index.d.ts.map +1 -0
  118. package/dist/harness/runtime/index.js +2 -0
  119. package/dist/harness/runtime/index.js.map +1 -0
  120. package/dist/harness/runtime/lane.d.ts +101 -0
  121. package/dist/harness/runtime/lane.d.ts.map +1 -0
  122. package/dist/harness/runtime/lane.js +1575 -0
  123. package/dist/harness/runtime/lane.js.map +1 -0
  124. package/dist/harness/runtime/progress.d.ts +15 -0
  125. package/dist/harness/runtime/progress.d.ts.map +1 -0
  126. package/dist/harness/runtime/progress.js +66 -0
  127. package/dist/harness/runtime/progress.js.map +1 -0
  128. package/dist/harness/runtime/reducer.d.ts +5 -0
  129. package/dist/harness/runtime/reducer.d.ts.map +1 -0
  130. package/dist/harness/runtime/reducer.js +240 -0
  131. package/dist/harness/runtime/reducer.js.map +1 -0
  132. package/dist/harness/runtime/restore.d.ts +24 -0
  133. package/dist/harness/runtime/restore.d.ts.map +1 -0
  134. package/dist/harness/runtime/restore.js +117 -0
  135. package/dist/harness/runtime/restore.js.map +1 -0
  136. package/dist/harness/runtime/transcript.d.ts +21 -0
  137. package/dist/harness/runtime/transcript.d.ts.map +1 -0
  138. package/dist/harness/runtime/transcript.js +72 -0
  139. package/dist/harness/runtime/transcript.js.map +1 -0
  140. package/dist/harness/runtime/types.d.ts +105 -0
  141. package/dist/harness/runtime/types.d.ts.map +1 -0
  142. package/dist/harness/runtime/types.js +61 -0
  143. package/dist/harness/runtime/types.js.map +1 -0
  144. package/dist/harness/session/commit.d.ts +53 -0
  145. package/dist/harness/session/commit.d.ts.map +1 -0
  146. package/dist/harness/session/commit.js +57 -0
  147. package/dist/harness/session/commit.js.map +1 -0
  148. package/dist/harness/session/context.d.ts +6 -18
  149. package/dist/harness/session/context.d.ts.map +1 -1
  150. package/dist/harness/session/context.js +31 -49
  151. package/dist/harness/session/context.js.map +1 -1
  152. package/dist/harness/session/fork-policy.d.ts +13 -0
  153. package/dist/harness/session/fork-policy.d.ts.map +1 -0
  154. package/dist/harness/session/fork-policy.js +22 -0
  155. package/dist/harness/session/fork-policy.js.map +1 -0
  156. package/dist/harness/session/fork.d.ts +18 -0
  157. package/dist/harness/session/fork.d.ts.map +1 -0
  158. package/dist/harness/session/fork.js +127 -0
  159. package/dist/harness/session/fork.js.map +1 -0
  160. package/dist/harness/session/in-memory-storage-state.d.ts +39 -0
  161. package/dist/harness/session/in-memory-storage-state.d.ts.map +1 -0
  162. package/dist/harness/session/in-memory-storage-state.js +216 -0
  163. package/dist/harness/session/in-memory-storage-state.js.map +1 -0
  164. package/dist/harness/session/index.d.ts +9 -5
  165. package/dist/harness/session/index.d.ts.map +1 -1
  166. package/dist/harness/session/index.js +7 -4
  167. package/dist/harness/session/index.js.map +1 -1
  168. package/dist/harness/session/jsonl/codec.d.ts +19 -8
  169. package/dist/harness/session/jsonl/codec.d.ts.map +1 -1
  170. package/dist/harness/session/jsonl/codec.js +34 -218
  171. package/dist/harness/session/jsonl/codec.js.map +1 -1
  172. package/dist/harness/session/jsonl/index.d.ts +4 -0
  173. package/dist/harness/session/jsonl/index.d.ts.map +1 -0
  174. package/dist/harness/session/jsonl/index.js +4 -0
  175. package/dist/harness/session/jsonl/index.js.map +1 -0
  176. package/dist/harness/session/jsonl/legacy-v3.d.ts +18 -0
  177. package/dist/harness/session/jsonl/legacy-v3.d.ts.map +1 -0
  178. package/dist/harness/session/jsonl/legacy-v3.js +383 -0
  179. package/dist/harness/session/jsonl/legacy-v3.js.map +1 -0
  180. package/dist/harness/session/jsonl/repo.d.ts +26 -19
  181. package/dist/harness/session/jsonl/repo.d.ts.map +1 -1
  182. package/dist/harness/session/jsonl/repo.js +266 -156
  183. package/dist/harness/session/jsonl/repo.js.map +1 -1
  184. package/dist/harness/session/jsonl/storage.d.ts +39 -41
  185. package/dist/harness/session/jsonl/storage.d.ts.map +1 -1
  186. package/dist/harness/session/jsonl/storage.js +238 -181
  187. package/dist/harness/session/jsonl/storage.js.map +1 -1
  188. package/dist/harness/session/jsonl/types.d.ts +23 -22
  189. package/dist/harness/session/jsonl/types.d.ts.map +1 -1
  190. package/dist/harness/session/jsonl/types.js +2 -1
  191. package/dist/harness/session/jsonl/types.js.map +1 -1
  192. package/dist/harness/session/memory.d.ts +46 -40
  193. package/dist/harness/session/memory.d.ts.map +1 -1
  194. package/dist/harness/session/memory.js +346 -113
  195. package/dist/harness/session/memory.js.map +1 -1
  196. package/dist/harness/session/mutation-line.d.ts +8 -0
  197. package/dist/harness/session/mutation-line.d.ts.map +1 -0
  198. package/dist/harness/session/mutation-line.js +21 -0
  199. package/dist/harness/session/mutation-line.js.map +1 -0
  200. package/dist/harness/session/session.d.ts +78 -46
  201. package/dist/harness/session/session.d.ts.map +1 -1
  202. package/dist/harness/session/session.js +343 -209
  203. package/dist/harness/session/session.js.map +1 -1
  204. package/dist/harness/session/testing/benchmark/datasets.d.ts +12 -0
  205. package/dist/harness/session/testing/benchmark/datasets.d.ts.map +1 -0
  206. package/dist/harness/session/testing/benchmark/datasets.js +24 -0
  207. package/dist/harness/session/testing/benchmark/datasets.js.map +1 -0
  208. package/dist/harness/session/testing/benchmark/session-repo.d.ts +42 -0
  209. package/dist/harness/session/testing/benchmark/session-repo.d.ts.map +1 -0
  210. package/dist/harness/session/testing/benchmark/session-repo.js +127 -0
  211. package/dist/harness/session/testing/benchmark/session-repo.js.map +1 -0
  212. package/dist/harness/session/testing/benchmark/storage.d.ts +25 -0
  213. package/dist/harness/session/testing/benchmark/storage.d.ts.map +1 -0
  214. package/dist/harness/session/testing/benchmark/storage.js +114 -0
  215. package/dist/harness/session/testing/benchmark/storage.js.map +1 -0
  216. package/dist/harness/session/testing/conformance/session-repo.d.ts +21 -0
  217. package/dist/harness/session/testing/conformance/session-repo.d.ts.map +1 -0
  218. package/dist/harness/session/testing/conformance/session-repo.js +590 -0
  219. package/dist/harness/session/testing/conformance/session-repo.js.map +1 -0
  220. package/dist/harness/session/testing/conformance/storage.d.ts +4 -0
  221. package/dist/harness/session/testing/conformance/storage.d.ts.map +1 -0
  222. package/dist/harness/session/testing/conformance/storage.js +600 -0
  223. package/dist/harness/session/testing/conformance/storage.js.map +1 -0
  224. package/dist/harness/session/testing/gating-storage.d.ts +26 -0
  225. package/dist/harness/session/testing/gating-storage.d.ts.map +1 -0
  226. package/dist/harness/session/testing/gating-storage.js +100 -0
  227. package/dist/harness/session/testing/gating-storage.js.map +1 -0
  228. package/dist/harness/session/testing/index.d.ts +9 -2
  229. package/dist/harness/session/testing/index.d.ts.map +1 -1
  230. package/dist/harness/session/testing/index.js +8 -1
  231. package/dist/harness/session/testing/index.js.map +1 -1
  232. package/dist/harness/session/testing/instrumented-storage.d.ts +11 -0
  233. package/dist/harness/session/testing/instrumented-storage.d.ts.map +1 -0
  234. package/dist/harness/session/testing/instrumented-storage.js +16 -0
  235. package/dist/harness/session/testing/instrumented-storage.js.map +1 -0
  236. package/dist/harness/session/testing/storage-decorator.d.ts +20 -0
  237. package/dist/harness/session/testing/storage-decorator.d.ts.map +1 -0
  238. package/dist/harness/session/testing/storage-decorator.js +41 -0
  239. package/dist/harness/session/testing/storage-decorator.js.map +1 -0
  240. package/dist/harness/session/testing/types.d.ts +5 -7
  241. package/dist/harness/session/testing/types.d.ts.map +1 -1
  242. package/dist/harness/session/testing/types.js.map +1 -1
  243. package/dist/harness/session/types.d.ts +424 -259
  244. package/dist/harness/session/types.d.ts.map +1 -1
  245. package/dist/harness/session/types.js +7 -8
  246. package/dist/harness/session/types.js.map +1 -1
  247. package/dist/harness/session/values.d.ts +95 -0
  248. package/dist/harness/session/values.d.ts.map +1 -0
  249. package/dist/harness/session/values.js +81 -0
  250. package/dist/harness/session/values.js.map +1 -0
  251. package/dist/harness/skills.d.ts +3 -2
  252. package/dist/harness/skills.d.ts.map +1 -1
  253. package/dist/harness/skills.js +29 -26
  254. package/dist/harness/skills.js.map +1 -1
  255. package/dist/harness/telemetry.d.ts +64 -43
  256. package/dist/harness/telemetry.d.ts.map +1 -1
  257. package/dist/harness/telemetry.js +45 -26
  258. package/dist/harness/telemetry.js.map +1 -1
  259. package/dist/harness/tools/bash.d.ts +4 -4
  260. package/dist/harness/tools/bash.d.ts.map +1 -1
  261. package/dist/harness/tools/bash.js +66 -93
  262. package/dist/harness/tools/bash.js.map +1 -1
  263. package/dist/harness/tools/edit.d.ts.map +1 -1
  264. package/dist/harness/tools/edit.js +10 -10
  265. package/dist/harness/tools/edit.js.map +1 -1
  266. package/dist/harness/tools/file-mutation-queue.d.ts +2 -1
  267. package/dist/harness/tools/file-mutation-queue.d.ts.map +1 -1
  268. package/dist/harness/tools/file-mutation-queue.js +5 -5
  269. package/dist/harness/tools/file-mutation-queue.js.map +1 -1
  270. package/dist/harness/tools/path-utils.d.ts +3 -2
  271. package/dist/harness/tools/path-utils.d.ts.map +1 -1
  272. package/dist/harness/tools/path-utils.js +5 -5
  273. package/dist/harness/tools/path-utils.js.map +1 -1
  274. package/dist/harness/tools/read.d.ts +2 -1
  275. package/dist/harness/tools/read.d.ts.map +1 -1
  276. package/dist/harness/tools/read.js +4 -6
  277. package/dist/harness/tools/read.js.map +1 -1
  278. package/dist/harness/tools/write.d.ts.map +1 -1
  279. package/dist/harness/tools/write.js +7 -7
  280. package/dist/harness/tools/write.js.map +1 -1
  281. package/dist/harness/types.d.ts +108 -45
  282. package/dist/harness/types.d.ts.map +1 -1
  283. package/dist/harness/types.js.map +1 -1
  284. package/dist/harness/utils/adaptive-publisher.d.ts +24 -0
  285. package/dist/harness/utils/adaptive-publisher.d.ts.map +1 -0
  286. package/dist/harness/utils/adaptive-publisher.js +79 -0
  287. package/dist/harness/utils/adaptive-publisher.js.map +1 -0
  288. package/dist/harness/utils/output-capture.d.ts +31 -0
  289. package/dist/harness/utils/output-capture.d.ts.map +1 -0
  290. package/dist/harness/utils/output-capture.js +217 -0
  291. package/dist/harness/utils/output-capture.js.map +1 -0
  292. package/dist/harness/utils/shell-output.d.ts +12 -5
  293. package/dist/harness/utils/shell-output.d.ts.map +1 -1
  294. package/dist/harness/utils/shell-output.js +64 -174
  295. package/dist/harness/utils/shell-output.js.map +1 -1
  296. package/dist/harness/utils/truncate.d.ts +1 -0
  297. package/dist/harness/utils/truncate.d.ts.map +1 -1
  298. package/dist/harness/utils/truncate.js +1 -1
  299. package/dist/harness/utils/truncate.js.map +1 -1
  300. package/dist/harness/utils/usage.d.ts +4 -0
  301. package/dist/harness/utils/usage.d.ts.map +1 -0
  302. package/dist/harness/utils/usage.js +33 -0
  303. package/dist/harness/utils/usage.js.map +1 -0
  304. package/dist/index.d.ts +4 -1
  305. package/dist/index.d.ts.map +1 -1
  306. package/dist/index.js +3 -6
  307. package/dist/index.js.map +1 -1
  308. package/dist/proxy.d.ts +2 -0
  309. package/dist/proxy.d.ts.map +1 -1
  310. package/dist/proxy.js +40 -10
  311. package/dist/proxy.js.map +1 -1
  312. package/dist/search/index.d.ts +24 -16
  313. package/dist/search/index.d.ts.map +1 -1
  314. package/dist/search/index.js +1 -1
  315. package/dist/search/index.js.map +1 -1
  316. package/dist/types.d.ts +2 -0
  317. package/dist/types.d.ts.map +1 -1
  318. package/dist/types.js.map +1 -1
  319. package/package.json +25 -4
  320. package/dist/harness/reducer.d.ts +0 -100
  321. package/dist/harness/reducer.d.ts.map +0 -1
  322. package/dist/harness/reducer.js +0 -415
  323. package/dist/harness/reducer.js.map +0 -1
  324. package/dist/harness/session/jsonl/errors.d.ts +0 -9
  325. package/dist/harness/session/jsonl/errors.d.ts.map +0 -1
  326. package/dist/harness/session/jsonl/errors.js +0 -19
  327. package/dist/harness/session/jsonl/errors.js.map +0 -1
  328. package/dist/harness/session/jsonl.d.ts +0 -3
  329. package/dist/harness/session/jsonl.d.ts.map +0 -1
  330. package/dist/harness/session/jsonl.js +0 -2
  331. package/dist/harness/session/jsonl.js.map +0 -1
  332. package/dist/harness/session/state.d.ts +0 -65
  333. package/dist/harness/session/state.d.ts.map +0 -1
  334. package/dist/harness/session/state.js +0 -319
  335. package/dist/harness/session/state.js.map +0 -1
  336. package/dist/harness/session/testing/conformance.d.ts +0 -4
  337. package/dist/harness/session/testing/conformance.d.ts.map +0 -1
  338. package/dist/harness/session/testing/conformance.js +0 -762
  339. package/dist/harness/session/testing/conformance.js.map +0 -1
  340. package/dist/search/scanning.d.ts +0 -29
  341. package/dist/search/scanning.d.ts.map +0 -1
  342. package/dist/search/scanning.js +0 -103
  343. package/dist/search/scanning.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../src/harness/telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,wBAAwB,EACxB,mBAAmB,EACnB,gBAAgB,EAEhB,gCAAgC,EAChC,kCAAkC,EAClC,4BAA4B,EAC5B,uBAAuB,EACvB,kCAAkC,EAClC,wBAAwB,EAExB,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EACX,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,UAAU,EACV,4BAA4B,EAC5B,0BAA0B,EAC1B,sBAAsB,EACtB,gBAAgB,EAChB,iCAAiC,EACjC,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,gCAAgC,EAChC,kCAAkC,EAClC,4BAA4B,EAC5B,uBAAuB,EACvB,kCAAkC,EAClC,wBAAwB,EACxB,aAAa,EACb,uBAAuB,EACvB,iCAAiC,EACjC,gBAAgB,GAChB,MAAM,8BAA8B,CAAC;AAEtC,eAAO,MAAM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AAgB,CAC/B,IAAI,SAAS,eAAe,EAC5B,KAAK,CAAC,UAAU,SAAS,0BAA0B,CAAC,IAAI,CAAC,EACzD,MAAM,EAEN,gBAAgB,EAAE,gBAAgB,EAClC,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,wBAAwB,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,EAClF,QAAQ,EAAE,CAAC,IAAI,EAAE,oBAAoB,CAAC,IAAI,CAAC,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GACtE,OAAO,CAAC,MAAM,CAAC,CAIjB","sourcesContent":["import type {\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tTelemetryContext,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n} from \"@earendil-works/pi-telemetry\";\n\nexport type {\n\tAttributeValue,\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tSpanAttributes,\n\tSpanOptions,\n\tSpanStatus,\n\tTelemetryAttributeDefinition,\n\tTelemetryAttributeMetadata,\n\tTelemetryAttributeType,\n\tTelemetryContext,\n\tTelemetryEventAttributeDefinition,\n\tTelemetryEventDefinition,\n\tTelemetryParentDefinition,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n\tTelemetrySpanDefinition,\n\tTelemetryStartAttributeDefinition,\n\tTypedSpanStarter,\n} from \"@earendil-works/pi-telemetry\";\n\nexport const AI_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.ai.request\": {\n\t\t\tdescription: \"One logical request to an AI provider\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.ai.operation\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"stream\", \"fetch_deferred\", \"cancel_deferred\", \"generate_images\"],\n\t\t\t\t\tdescription: \"Logical provider operation\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.provider\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Selected provider id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.model\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested model id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.api\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Provider API id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.streaming\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this operation returns a stream\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.deferred\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Whether the operation requests or participates in deferred execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.ai.response.model\": { type: \"string\", description: \"Concrete response model\" },\n\t\t\t\t\"pi.ai.response.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Provider response id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.response.stop_reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"stop\", \"length\", \"tool_use\", \"error\", \"aborted\", \"deferred\"],\n\t\t\t\t\tdescription: \"Normalized terminal response reason\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.http.status_code\": { type: \"number\", description: \"Final HTTP status\" },\n\t\t\t\t\"pi.ai.usage.input_tokens\": { type: \"number\", description: \"Reported input tokens\" },\n\t\t\t\t\"pi.ai.usage.output_tokens\": { type: \"number\", description: \"Reported output tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_read_tokens\": { type: \"number\", description: \"Reported cache-read tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_write_tokens\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Reported cache-write tokens\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.usage.reasoning_tokens\": { type: \"number\", description: \"Reported reasoning tokens\" },\n\t\t\t\t\"pi.ai.usage.total_tokens\": { type: \"number\", description: \"Reported total tokens\" },\n\t\t\t\t\"pi.ai.usage.cost\": { type: \"number\", description: \"Reported total cost\" },\n\t\t\t\t\"pi.ai.stream.chunk_count\": { type: \"number\", description: \"Streamed update chunk count\" },\n\t\t\t\t\"pi.ai.stream.time_to_first_chunk_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Elapsed milliseconds to first update chunk\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.error.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tdescription: \"Provider or transport error class\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The operation throws or returns an error result\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\nexport type AiSpanName = TelemetrySchemaSpanName<typeof AI_TELEMETRY_SCHEMA>;\nexport type AiSpanStartAttributes<Name extends AiSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanEndAttributes<Name extends AiSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanAttributes<Name extends AiSpanName> = AiSpanStartAttributes<Name> & AiSpanEndAttributes<Name>;\nexport type AiSpanEventName<Name extends AiSpanName> = TelemetrySchemaSpanEventName<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpanEventAttributes<\n\tName extends AiSpanName,\n\tEventName extends AiSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof AI_TELEMETRY_SCHEMA, Name, EventName>;\nexport type AiTelemetrySpan<Name extends AiSpanName> = SchemaTelemetrySpan<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpan = TelemetrySchemaSpanUnion<typeof AI_TELEMETRY_SCHEMA>;\n\nexport function startAiSpan<Name extends AiSpanName, const Attributes extends AiSpanStartAttributes<Name>, Result>(\n\ttelemetryContext: TelemetryContext,\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<AiSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: AiTelemetrySpan<Name>) => Result | Promise<Result>,\n): Promise<Result> {\n\treturn telemetryContext.startSpan({ name, attributes }, (span) => callback(span as AiTelemetrySpan<Name>));\n}\n\nconst HOOK_NAMES = [\n\t\"before_run\",\n\t\"before_resume\",\n\t\"before_run_end\",\n\t\"transform_context\",\n\t\"before_request\",\n\t\"before_payload\",\n\t\"after_response\",\n\t\"before_tool\",\n\t\"after_tool\",\n\t\"before_compaction\",\n\t\"before_navigation\",\n] as const;\n\nconst EVENT_TYPES = [\n\t\"run_start\",\n\t\"run_resume\",\n\t\"run_suspend\",\n\t\"run_abort\",\n\t\"run_end\",\n\t\"fault\",\n\t\"handler_error\",\n\t\"turn_start\",\n\t\"turn_end\",\n\t\"retry_scheduled\",\n\t\"retry_start\",\n\t\"retry_end\",\n\t\"message_start\",\n\t\"message_update\",\n\t\"message_end\",\n\t\"tool_start\",\n\t\"tool_update\",\n\t\"tool_end\",\n\t\"entry_added\",\n\t\"write_pending\",\n\t\"queue_update\",\n\t\"fact_update\",\n\t\"config_update\",\n\t\"compaction_start\",\n\t\"compaction_end\",\n\t\"navigation_start\",\n\t\"navigation_end\",\n\t\"lane_created\",\n\t\"usage\",\n] as const;\n\nconst operationStartAttributes = {\n\t\"pi.session.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Session id\",\n\t},\n\t\"pi.lane.name\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Lane name\",\n\t},\n\t\"pi.operation.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Durable operation id\",\n\t},\n\t\"pi.operation.recovery\": {\n\t\ttype: \"boolean\",\n\t\trequired: true,\n\t\tdescription: \"Whether this invocation resumes durable work\",\n\t},\n} as const;\n\nconst operationErrorAttributes = {\n\t\"pi.error.code\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Stable operation error code\",\n\t},\n\t\"pi.error.type\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Low-cardinality operation error class\",\n\t},\n} as const;\n\nexport const HARNESS_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.harness.run\": {\n\t\t\tdescription: \"One admitted in-process run invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"run\"],\n\t\t\t\t\tdescription: \"Run operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"aborted\", \"failed\", \"suspended\"],\n\t\t\t\t\tdescription: \"Run invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The run fails or throws\" },\n\t\t},\n\t\t\"pi.harness.compaction\": {\n\t\t\tdescription: \"One admitted in-process manual compaction invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"compaction\"],\n\t\t\t\t\tdescription: \"Compaction operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Compaction invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The compaction fails or throws\" },\n\t\t},\n\t\t\"pi.harness.navigation\": {\n\t\t\tdescription: \"One admitted in-process navigation invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"navigation\"],\n\t\t\t\t\tdescription: \"Navigation operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Navigation invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The navigation fails or throws\" },\n\t\t},\n\t\t\"pi.harness.checkpoint\": {\n\t\t\tdescription: \"One run checkpoint\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.checkpoint.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"normal\", \"failure_drain\", \"abort_reconcile\"],\n\t\t\t\t\tdescription: \"Checkpoint purpose\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Checkpoint work throws\" },\n\t\t},\n\t\t\"pi.harness.turn\": {\n\t\t\tdescription: \"One assistant response and its tool batch\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local turn id\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Turn work throws\" },\n\t\t},\n\t\t\"pi.harness.step\": {\n\t\t\tdescription: \"One durable retry attempt\",\n\t\t\tparents: {\n\t\t\t\tkind: \"spans\",\n\t\t\t\tspans: [\"pi.harness.turn\", \"pi.harness.checkpoint\", \"pi.harness.compaction\", \"pi.harness.navigation\"],\n\t\t\t},\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"assistant\", \"compaction\", \"branch_summary\"],\n\t\t\t\t\tdescription: \"Retryable step kind\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.attempt\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"One-based durable attempt number\",\n\t\t\t\t},\n\t\t\t\t\"pi.compaction.reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tvalues: [\"manual\", \"threshold\", \"overflow\"],\n\t\t\t\t\tdescription: \"Compaction trigger\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.step.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"succeeded\", \"retry\", \"failed\", \"aborted\", \"deferred\", \"overflow\"],\n\t\t\t\t\tdescription: \"Attempt outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The attempt retries, fails, or throws\" },\n\t\t},\n\t\t\"pi.harness.tool\": {\n\t\t\tdescription: \"One raw phase-2 tool execution\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.turn\", \"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local live turn id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Tool name\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.call_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Tool call id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.replay\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"never\", \"safe\"],\n\t\t\t\t\tdescription: \"Declared replay policy\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.recovery\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this is recovery execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.tool.is_error\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdescription: \"Whether raw phase-2 execution returned an error\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Raw phase-2 execution returns an error\" },\n\t\t},\n\t\t\"pi.harness.hook\": {\n\t\t\tdescription: \"One registered hook handler invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when accepted\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: HOOK_NAMES,\n\t\t\t\t\tdescription: \"Hook name\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.registration_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Stable hook registration id\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.hook.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"skipped\", \"blocked\", \"failed\"],\n\t\t\t\t\tdescription: \"Handler outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The handler throws\" },\n\t\t},\n\t\t\"pi.harness.sleep\": {\n\t\t\tdescription: \"One retry delay\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.step\", \"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.sleep.delay_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested delay in milliseconds\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.sleep.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"elapsed\", \"aborted\"],\n\t\t\t\t\tdescription: \"Delay outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Sleep work throws\" },\n\t\t},\n\t\t\"pi.harness.event_handler\": {\n\t\t\tdescription: \"One passive event listener invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.event.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tvalues: EVENT_TYPES,\n\t\t\t\t\tdescription: \"Delivered harness event type\",\n\t\t\t\t},\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name for lane-scoped events\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The listener throws\" },\n\t\t},\n\t\t\"pi.session.write\": {\n\t\t\tdescription: \"One committed session mutation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when accepted\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.mutation\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"entry\", \"record\", \"lane\", \"fact\"],\n\t\t\t\t\tdescription: \"Session mutation kind\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.item_type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Entry, record, lane, or fact subtype\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.session.seq\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Committed session sequence when exposed\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Storage rejects the mutation\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\n/** Combined typed span vocabulary for agent-owned AI-request and harness telemetry. */\nexport const AGENT_TELEMETRY_SCHEMAS = [AI_TELEMETRY_SCHEMA, HARNESS_TELEMETRY_SCHEMA] as const;\n\nexport type HarnessSpanName = TelemetrySchemaSpanName<typeof HARNESS_TELEMETRY_SCHEMA>;\nexport type HarnessSpanStartAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEndAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanAttributes<Name extends HarnessSpanName> = HarnessSpanStartAttributes<Name> &\n\tHarnessSpanEndAttributes<Name>;\nexport type HarnessSpanEventName<Name extends HarnessSpanName> = TelemetrySchemaSpanEventName<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEventAttributes<\n\tName extends HarnessSpanName,\n\tEventName extends HarnessSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof HARNESS_TELEMETRY_SCHEMA, Name, EventName>;\nexport type HarnessTelemetrySpan<Name extends HarnessSpanName> = SchemaTelemetrySpan<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpan = TelemetrySchemaSpanUnion<typeof HARNESS_TELEMETRY_SCHEMA>;\n\nexport function startHarnessSpan<\n\tName extends HarnessSpanName,\n\tconst Attributes extends HarnessSpanStartAttributes<Name>,\n\tResult,\n>(\n\ttelemetryContext: TelemetryContext,\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<HarnessSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: HarnessTelemetrySpan<Name>) => Result | Promise<Result>,\n): Promise<Result> {\n\treturn telemetryContext.startSpan({ name, attributes }, (span: TelemetrySpan) =>\n\t\tcallback(span as HarnessTelemetrySpan<Name>),\n\t);\n}\n"]}
1
+ {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../src/harness/telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,wBAAwB,EACxB,mBAAmB,EAEnB,gCAAgC,EAChC,kCAAkC,EAClC,4BAA4B,EAC5B,uBAAuB,EACvB,kCAAkC,EAClC,wBAAwB,EAExB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,OAAO,EAA6C,MAAM,cAAc,CAAC;AAEvF,YAAY,EACX,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,UAAU,EACV,4BAA4B,EAC5B,0BAA0B,EAC1B,sBAAsB,EACtB,gBAAgB,EAChB,iCAAiC,EACjC,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,gCAAgC,EAChC,kCAAkC,EAClC,4BAA4B,EAC5B,uBAAuB,EACvB,kCAAkC,EAClC,wBAAwB,EACxB,aAAa,EACb,uBAAuB,EACvB,iCAAiC,EACjC,gBAAgB,GAChB,MAAM,8BAA8B,CAAC;AAE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AAwB,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAEpF,wBAAgB,gBAAgB,CAC/B,IAAI,SAAS,eAAe,EAC5B,KAAK,CAAC,UAAU,SAAS,0BAA0B,CAAC,IAAI,CAAC,EACzD,MAAM,EAEN,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,wBAAwB,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,EAClF,QAAQ,EAAE,CAAC,IAAI,EAAE,oBAAoB,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,EAC1F,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,MAAM,CAAC,CAIjB","sourcesContent":["import type {\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n} from \"@earendil-works/pi-telemetry\";\nimport { type Context, getTelemetryContext, withTelemetryContext } from \"./context.ts\";\n\nexport type {\n\tAttributeValue,\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tSpanAttributes,\n\tSpanOptions,\n\tSpanStatus,\n\tTelemetryAttributeDefinition,\n\tTelemetryAttributeMetadata,\n\tTelemetryAttributeType,\n\tTelemetryContext,\n\tTelemetryEventAttributeDefinition,\n\tTelemetryEventDefinition,\n\tTelemetryParentDefinition,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n\tTelemetrySpanDefinition,\n\tTelemetryStartAttributeDefinition,\n\tTypedSpanStarter,\n} from \"@earendil-works/pi-telemetry\";\n\nexport const AI_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.ai.request\": {\n\t\t\tdescription: \"One logical request to an AI provider\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.ai.operation\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"stream\", \"fetch_deferred\", \"cancel_deferred\", \"generate_images\"],\n\t\t\t\t\tdescription: \"Logical provider operation\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.provider\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Selected provider id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.model\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested model id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.api\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Provider API id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.streaming\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this operation returns a stream\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.deferred\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Whether the operation requests or participates in deferred execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.ai.response.model\": { type: \"string\", description: \"Concrete response model\" },\n\t\t\t\t\"pi.ai.response.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Provider response id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.response.stop_reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"stop\", \"length\", \"tool_use\", \"error\", \"aborted\", \"deferred\"],\n\t\t\t\t\tdescription: \"Normalized terminal response reason\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.http.status_code\": { type: \"number\", description: \"Final HTTP status\" },\n\t\t\t\t\"pi.ai.usage.input_tokens\": { type: \"number\", description: \"Reported input tokens\" },\n\t\t\t\t\"pi.ai.usage.output_tokens\": { type: \"number\", description: \"Reported output tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_read_tokens\": { type: \"number\", description: \"Reported cache-read tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_write_tokens\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Reported cache-write tokens\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.usage.reasoning_tokens\": { type: \"number\", description: \"Reported reasoning tokens\" },\n\t\t\t\t\"pi.ai.usage.total_tokens\": { type: \"number\", description: \"Reported total tokens\" },\n\t\t\t\t\"pi.ai.usage.cost\": { type: \"number\", description: \"Reported total cost\" },\n\t\t\t\t\"pi.ai.stream.chunk_count\": { type: \"number\", description: \"Streamed update chunk count\" },\n\t\t\t\t\"pi.ai.stream.time_to_first_chunk_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Elapsed milliseconds to first update chunk\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.error.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tdescription: \"Provider or transport error class\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The operation throws or returns an error result\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\nexport type AiSpanName = TelemetrySchemaSpanName<typeof AI_TELEMETRY_SCHEMA>;\nexport type AiSpanStartAttributes<Name extends AiSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanEndAttributes<Name extends AiSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanAttributes<Name extends AiSpanName> = AiSpanStartAttributes<Name> & AiSpanEndAttributes<Name>;\nexport type AiSpanEventName<Name extends AiSpanName> = TelemetrySchemaSpanEventName<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpanEventAttributes<\n\tName extends AiSpanName,\n\tEventName extends AiSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof AI_TELEMETRY_SCHEMA, Name, EventName>;\nexport type AiTelemetrySpan<Name extends AiSpanName> = SchemaTelemetrySpan<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpan = TelemetrySchemaSpanUnion<typeof AI_TELEMETRY_SCHEMA>;\n\nexport function startAiSpan<Name extends AiSpanName, const Attributes extends AiSpanStartAttributes<Name>, Result>(\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<AiSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: AiTelemetrySpan<Name>, context: Context) => Result | Promise<Result>,\n\tcontext: Context,\n): Promise<Result> {\n\treturn getTelemetryContext(context).startSpan({ name, attributes }, (span) =>\n\t\tcallback(span as AiTelemetrySpan<Name>, withTelemetryContext(span, context)),\n\t);\n}\n\nconst HOOK_NAMES = [\n\t\"before_run\",\n\t\"before_drive\",\n\t\"before_run_end\",\n\t\"transform_context\",\n\t\"before_request\",\n\t\"before_payload\",\n\t\"after_response\",\n\t\"before_tool\",\n\t\"after_tool\",\n\t\"before_compaction\",\n\t\"before_navigation\",\n] as const;\n\nconst EVENT_TYPES = [\n\t\"run_start\",\n\t\"run_resume\",\n\t\"run_suspend\",\n\t\"operation_abort\",\n\t\"run_end\",\n\t\"fault\",\n\t\"handler_error\",\n\t\"turn_start\",\n\t\"turn_end\",\n\t\"retry_scheduled\",\n\t\"retry_start\",\n\t\"retry_end\",\n\t\"message_start\",\n\t\"message_update\",\n\t\"message_end\",\n\t\"tool_start\",\n\t\"tool_update\",\n\t\"tool_end\",\n\t\"entry_added\",\n\t\"queue_update\",\n\t\"value_update\",\n\t\"config_update\",\n\t\"compaction_start\",\n\t\"compaction_end\",\n\t\"navigation_start\",\n\t\"navigation_end\",\n\t\"lane_created\",\n\t\"usage\",\n] as const;\n\nconst operationStartAttributes = {\n\t\"pi.session.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Session id\",\n\t},\n\t\"pi.lane.name\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Lane name\",\n\t},\n\t\"pi.operation.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Durable operation id\",\n\t},\n\t\"pi.operation.recovery\": {\n\t\ttype: \"boolean\",\n\t\trequired: true,\n\t\tdescription: \"Whether this invocation resumes durable work\",\n\t},\n} as const;\n\nconst operationErrorAttributes = {\n\t\"pi.error.code\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Stable operation error code\",\n\t},\n\t\"pi.error.type\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Low-cardinality operation error class\",\n\t},\n} as const;\n\nexport const HARNESS_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.harness.run\": {\n\t\t\tdescription: \"One admitted in-process run invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"run\"],\n\t\t\t\t\tdescription: \"Run operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"aborted\", \"failed\", \"suspended\"],\n\t\t\t\t\tdescription: \"Run invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The run fails or throws\" },\n\t\t},\n\t\t\"pi.harness.compaction\": {\n\t\t\tdescription: \"One admitted in-process manual compaction invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"compaction\"],\n\t\t\t\t\tdescription: \"Compaction operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Compaction invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The compaction fails or throws\" },\n\t\t},\n\t\t\"pi.harness.navigation\": {\n\t\t\tdescription: \"One admitted in-process navigation invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"navigation\"],\n\t\t\t\t\tdescription: \"Navigation operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Navigation invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The navigation fails or throws\" },\n\t\t},\n\t\t\"pi.harness.checkpoint\": {\n\t\t\tdescription: \"One run checkpoint\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.checkpoint.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"normal\", \"abort_reconcile\"],\n\t\t\t\t\tdescription: \"Checkpoint purpose\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Checkpoint work throws\" },\n\t\t},\n\t\t\"pi.harness.turn\": {\n\t\t\tdescription: \"One assistant response and its tool batch\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local turn id\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Turn work throws\" },\n\t\t},\n\t\t\"pi.harness.step\": {\n\t\t\tdescription: \"One durable retry attempt\",\n\t\t\tparents: {\n\t\t\t\tkind: \"spans\",\n\t\t\t\tspans: [\"pi.harness.turn\", \"pi.harness.checkpoint\", \"pi.harness.compaction\", \"pi.harness.navigation\"],\n\t\t\t},\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"assistant\", \"compaction\", \"branch_summary\"],\n\t\t\t\t\tdescription: \"Retryable step kind\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.attempt\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"One-based durable attempt number\",\n\t\t\t\t},\n\t\t\t\t\"pi.compaction.reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tvalues: [\"manual\", \"threshold\", \"overflow\"],\n\t\t\t\t\tdescription: \"Compaction trigger\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.step.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"succeeded\", \"retry\", \"failed\", \"aborted\", \"deferred\", \"overflow\"],\n\t\t\t\t\tdescription: \"Attempt outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The attempt retries, fails, or throws\" },\n\t\t},\n\t\t\"pi.harness.tool\": {\n\t\t\tdescription: \"One raw phase-2 tool execution\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.turn\", \"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local live turn id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Tool name\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.call_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Tool call id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.replay\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"never\", \"safe\"],\n\t\t\t\t\tdescription: \"Declared replay policy\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.recovery\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this is recovery execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.tool.is_error\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdescription: \"Whether raw phase-2 execution returned an error\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Raw phase-2 execution returns an error\" },\n\t\t},\n\t\t\"pi.harness.hook\": {\n\t\t\tdescription: \"One registered hook handler invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when accepted\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: HOOK_NAMES,\n\t\t\t\t\tdescription: \"Hook name\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.registration_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Optional hook registration metadata\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.hook.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"skipped\", \"blocked\", \"failed\"],\n\t\t\t\t\tdescription: \"Handler outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The handler throws\" },\n\t\t},\n\t\t\"pi.harness.sleep\": {\n\t\t\tdescription: \"One retry delay\",\n\t\t\tparents: {\n\t\t\t\tkind: \"spans\",\n\t\t\t\tspans: [\n\t\t\t\t\t\"pi.harness.run\",\n\t\t\t\t\t\"pi.harness.compaction\",\n\t\t\t\t\t\"pi.harness.navigation\",\n\t\t\t\t\t\"pi.harness.turn\",\n\t\t\t\t\t\"pi.harness.checkpoint\",\n\t\t\t\t],\n\t\t\t},\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.sleep.delay_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested delay in milliseconds\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.sleep.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"elapsed\", \"aborted\"],\n\t\t\t\t\tdescription: \"Delay outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Sleep work throws\" },\n\t\t},\n\t\t\"pi.harness.event_handler\": {\n\t\t\tdescription: \"One passive event listener invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.event.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tvalues: EVENT_TYPES,\n\t\t\t\t\tdescription: \"Delivered harness event type\",\n\t\t\t\t},\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name for lane-scoped events\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The listener throws\" },\n\t\t},\n\t\t\"pi.session.write\": {\n\t\t\tdescription: \"One committed session transaction\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.session.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Session id\",\n\t\t\t\t},\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name when supplied by the caller\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when supplied by the caller\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.item_count\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Number of writes in the transaction\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.item_kinds\": {\n\t\t\t\t\ttype: \"string[]\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\telementValues: [\"entry\", \"usage\", \"value\", \"list\"],\n\t\t\t\t\tdescription: \"Distinct write kinds in the transaction\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.session.first_seq\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"First committed sequence in the transaction\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.last_seq\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Last committed sequence in the transaction\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Storage rejects the transaction\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\n/** Combined typed span vocabulary for agent-owned AI-request and harness telemetry. */\nexport const AGENT_TELEMETRY_SCHEMAS = [AI_TELEMETRY_SCHEMA, HARNESS_TELEMETRY_SCHEMA] as const;\n\nexport type HarnessSpanName = TelemetrySchemaSpanName<typeof HARNESS_TELEMETRY_SCHEMA>;\nexport type HarnessSpanStartAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEndAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanAttributes<Name extends HarnessSpanName> = HarnessSpanStartAttributes<Name> &\n\tHarnessSpanEndAttributes<Name>;\nexport type HarnessSpanEventName<Name extends HarnessSpanName> = TelemetrySchemaSpanEventName<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEventAttributes<\n\tName extends HarnessSpanName,\n\tEventName extends HarnessSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof HARNESS_TELEMETRY_SCHEMA, Name, EventName>;\nexport type HarnessTelemetrySpan<Name extends HarnessSpanName> = SchemaTelemetrySpan<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpan = TelemetrySchemaSpanUnion<typeof HARNESS_TELEMETRY_SCHEMA>;\n\nexport function startHarnessSpan<\n\tName extends HarnessSpanName,\n\tconst Attributes extends HarnessSpanStartAttributes<Name>,\n\tResult,\n>(\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<HarnessSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: HarnessTelemetrySpan<Name>, context: Context) => Result | Promise<Result>,\n\tcontext: Context,\n): Promise<Result> {\n\treturn getTelemetryContext(context).startSpan({ name, attributes }, (span: TelemetrySpan) =>\n\t\tcallback(span as HarnessTelemetrySpan<Name>, withTelemetryContext(span, context)),\n\t);\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { getTelemetryContext, withTelemetryContext } from "./context.js";
1
2
  export const AI_TELEMETRY_SCHEMA = {
2
3
  version: 1,
3
4
  spans: {
@@ -75,12 +76,12 @@ export const AI_TELEMETRY_SCHEMA = {
75
76
  },
76
77
  },
77
78
  };
78
- export function startAiSpan(telemetryContext, name, attributes, callback) {
79
- return telemetryContext.startSpan({ name, attributes }, (span) => callback(span));
79
+ export function startAiSpan(name, attributes, callback, context) {
80
+ return getTelemetryContext(context).startSpan({ name, attributes }, (span) => callback(span, withTelemetryContext(span, context)));
80
81
  }
81
82
  const HOOK_NAMES = [
82
83
  "before_run",
83
- "before_resume",
84
+ "before_drive",
84
85
  "before_run_end",
85
86
  "transform_context",
86
87
  "before_request",
@@ -95,7 +96,7 @@ const EVENT_TYPES = [
95
96
  "run_start",
96
97
  "run_resume",
97
98
  "run_suspend",
98
- "run_abort",
99
+ "operation_abort",
99
100
  "run_end",
100
101
  "fault",
101
102
  "handler_error",
@@ -111,9 +112,8 @@ const EVENT_TYPES = [
111
112
  "tool_update",
112
113
  "tool_end",
113
114
  "entry_added",
114
- "write_pending",
115
115
  "queue_update",
116
- "fact_update",
116
+ "value_update",
117
117
  "config_update",
118
118
  "compaction_start",
119
119
  "compaction_end",
@@ -247,7 +247,7 @@ export const HARNESS_TELEMETRY_SCHEMA = {
247
247
  "pi.checkpoint.kind": {
248
248
  type: "string",
249
249
  required: true,
250
- values: ["normal", "failure_drain", "abort_reconcile"],
250
+ values: ["normal", "abort_reconcile"],
251
251
  description: "Checkpoint purpose",
252
252
  },
253
253
  },
@@ -404,7 +404,7 @@ export const HARNESS_TELEMETRY_SCHEMA = {
404
404
  "pi.hook.registration_id": {
405
405
  type: "string",
406
406
  required: false,
407
- description: "Stable hook registration id",
407
+ description: "Optional hook registration metadata",
408
408
  },
409
409
  },
410
410
  endAttributes: {
@@ -418,7 +418,16 @@ export const HARNESS_TELEMETRY_SCHEMA = {
418
418
  },
419
419
  "pi.harness.sleep": {
420
420
  description: "One retry delay",
421
- parents: { kind: "spans", spans: ["pi.harness.step", "pi.harness.run"] },
421
+ parents: {
422
+ kind: "spans",
423
+ spans: [
424
+ "pi.harness.run",
425
+ "pi.harness.compaction",
426
+ "pi.harness.navigation",
427
+ "pi.harness.turn",
428
+ "pi.harness.checkpoint",
429
+ ],
430
+ },
422
431
  startAttributes: {
423
432
  "pi.operation.id": {
424
433
  type: "string",
@@ -463,46 +472,56 @@ export const HARNESS_TELEMETRY_SCHEMA = {
463
472
  status: { default: "ok", errorWhen: "The listener throws" },
464
473
  },
465
474
  "pi.session.write": {
466
- description: "One committed session mutation",
475
+ description: "One committed session transaction",
467
476
  parents: { kind: "any" },
468
477
  startAttributes: {
469
- "pi.lane.name": {
478
+ "pi.session.id": {
470
479
  type: "string",
471
480
  required: true,
472
481
  cardinality: "high",
473
- description: "Lane name",
482
+ description: "Session id",
474
483
  },
475
- "pi.operation.id": {
484
+ "pi.lane.name": {
476
485
  type: "string",
477
486
  required: false,
478
487
  cardinality: "high",
479
- description: "Durable operation id when accepted",
488
+ description: "Lane name when supplied by the caller",
480
489
  },
481
- "pi.session.mutation": {
490
+ "pi.operation.id": {
482
491
  type: "string",
492
+ required: false,
493
+ cardinality: "high",
494
+ description: "Durable operation id when supplied by the caller",
495
+ },
496
+ "pi.session.item_count": {
497
+ type: "number",
483
498
  required: true,
484
- values: ["entry", "record", "lane", "fact"],
485
- description: "Session mutation kind",
499
+ description: "Number of writes in the transaction",
486
500
  },
487
- "pi.session.item_type": {
488
- type: "string",
489
- required: false,
490
- description: "Entry, record, lane, or fact subtype",
501
+ "pi.session.item_kinds": {
502
+ type: "string[]",
503
+ required: true,
504
+ elementValues: ["entry", "usage", "value", "list"],
505
+ description: "Distinct write kinds in the transaction",
491
506
  },
492
507
  },
493
508
  endAttributes: {
494
- "pi.session.seq": {
509
+ "pi.session.first_seq": {
510
+ type: "number",
511
+ description: "First committed sequence in the transaction",
512
+ },
513
+ "pi.session.last_seq": {
495
514
  type: "number",
496
- description: "Committed session sequence when exposed",
515
+ description: "Last committed sequence in the transaction",
497
516
  },
498
517
  },
499
- status: { default: "ok", errorWhen: "Storage rejects the mutation" },
518
+ status: { default: "ok", errorWhen: "Storage rejects the transaction" },
500
519
  },
501
520
  },
502
521
  };
503
522
  /** Combined typed span vocabulary for agent-owned AI-request and harness telemetry. */
504
523
  export const AGENT_TELEMETRY_SCHEMAS = [AI_TELEMETRY_SCHEMA, HARNESS_TELEMETRY_SCHEMA];
505
- export function startHarnessSpan(telemetryContext, name, attributes, callback) {
506
- return telemetryContext.startSpan({ name, attributes }, (span) => callback(span));
524
+ export function startHarnessSpan(name, attributes, callback, context) {
525
+ return getTelemetryContext(context).startSpan({ name, attributes }, (span) => callback(span, withTelemetryContext(span, context)));
507
526
  }
508
527
  //# sourceMappingURL=telemetry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../src/harness/telemetry.ts"],"names":[],"mappings":"AAyCA,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC,OAAO,EAAE,CAAC;IACV,KAAK,EAAE;QACN,eAAe,EAAE;YAChB,WAAW,EAAE,uCAAuC;YACpD,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;YACxB,eAAe,EAAE;gBAChB,iBAAiB,EAAE;oBAClB,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,MAAM,EAAE,CAAC,QAAQ,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,CAAC;oBAC1E,WAAW,EAAE,4BAA4B;iBACzC;gBACD,gBAAgB,EAAE;oBACjB,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,sBAAsB;iBACnC;gBACD,aAAa,EAAE;oBACd,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,oBAAoB;iBACjC;gBACD,WAAW,EAAE;oBACZ,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,iBAAiB;iBAC9B;gBACD,iBAAiB,EAAE;oBAClB,IAA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AAI;oBACd,MAAM,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;oBAC3C,WAAW,EAAE,uBAAuB;iBACpC;gBACD,sBAAsB,EAAE;oBACvB,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,KAAK;oBACf,WAAW,EAAE,sCAAsC;iBACnD;aACD;YACD,aAAa,EAAE;gBACd,gBAAgB,EAAE;oBACjB,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,yCAAyC;iBACtD;aACD;YACD,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,8BAA8B,EAAE;SACpE;KACD;CAC4C,CAAC;AAE/C,uFAAuF;AACvF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,mBAAmB,EAAE,wBAAwB,CAAU,CAAC;AA2BhG,MAAM,UAAU,gBAAgB,CAK/B,gBAAkC,EAClC,IAAU,EACV,UAAkF,EAClF,QAAwE,EACtD;IAClB,OAAO,gBAAgB,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,IAAmB,EAAE,EAAE,CAC/E,QAAQ,CAAC,IAAkC,CAAC,CAC5C,CAAC;AAAA,CACF","sourcesContent":["import type {\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tTelemetryContext,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n} from \"@earendil-works/pi-telemetry\";\n\nexport type {\n\tAttributeValue,\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tSpanAttributes,\n\tSpanOptions,\n\tSpanStatus,\n\tTelemetryAttributeDefinition,\n\tTelemetryAttributeMetadata,\n\tTelemetryAttributeType,\n\tTelemetryContext,\n\tTelemetryEventAttributeDefinition,\n\tTelemetryEventDefinition,\n\tTelemetryParentDefinition,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n\tTelemetrySpanDefinition,\n\tTelemetryStartAttributeDefinition,\n\tTypedSpanStarter,\n} from \"@earendil-works/pi-telemetry\";\n\nexport const AI_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.ai.request\": {\n\t\t\tdescription: \"One logical request to an AI provider\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.ai.operation\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"stream\", \"fetch_deferred\", \"cancel_deferred\", \"generate_images\"],\n\t\t\t\t\tdescription: \"Logical provider operation\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.provider\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Selected provider id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.model\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested model id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.api\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Provider API id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.streaming\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this operation returns a stream\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.deferred\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Whether the operation requests or participates in deferred execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.ai.response.model\": { type: \"string\", description: \"Concrete response model\" },\n\t\t\t\t\"pi.ai.response.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Provider response id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.response.stop_reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"stop\", \"length\", \"tool_use\", \"error\", \"aborted\", \"deferred\"],\n\t\t\t\t\tdescription: \"Normalized terminal response reason\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.http.status_code\": { type: \"number\", description: \"Final HTTP status\" },\n\t\t\t\t\"pi.ai.usage.input_tokens\": { type: \"number\", description: \"Reported input tokens\" },\n\t\t\t\t\"pi.ai.usage.output_tokens\": { type: \"number\", description: \"Reported output tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_read_tokens\": { type: \"number\", description: \"Reported cache-read tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_write_tokens\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Reported cache-write tokens\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.usage.reasoning_tokens\": { type: \"number\", description: \"Reported reasoning tokens\" },\n\t\t\t\t\"pi.ai.usage.total_tokens\": { type: \"number\", description: \"Reported total tokens\" },\n\t\t\t\t\"pi.ai.usage.cost\": { type: \"number\", description: \"Reported total cost\" },\n\t\t\t\t\"pi.ai.stream.chunk_count\": { type: \"number\", description: \"Streamed update chunk count\" },\n\t\t\t\t\"pi.ai.stream.time_to_first_chunk_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Elapsed milliseconds to first update chunk\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.error.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tdescription: \"Provider or transport error class\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The operation throws or returns an error result\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\nexport type AiSpanName = TelemetrySchemaSpanName<typeof AI_TELEMETRY_SCHEMA>;\nexport type AiSpanStartAttributes<Name extends AiSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanEndAttributes<Name extends AiSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanAttributes<Name extends AiSpanName> = AiSpanStartAttributes<Name> & AiSpanEndAttributes<Name>;\nexport type AiSpanEventName<Name extends AiSpanName> = TelemetrySchemaSpanEventName<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpanEventAttributes<\n\tName extends AiSpanName,\n\tEventName extends AiSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof AI_TELEMETRY_SCHEMA, Name, EventName>;\nexport type AiTelemetrySpan<Name extends AiSpanName> = SchemaTelemetrySpan<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpan = TelemetrySchemaSpanUnion<typeof AI_TELEMETRY_SCHEMA>;\n\nexport function startAiSpan<Name extends AiSpanName, const Attributes extends AiSpanStartAttributes<Name>, Result>(\n\ttelemetryContext: TelemetryContext,\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<AiSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: AiTelemetrySpan<Name>) => Result | Promise<Result>,\n): Promise<Result> {\n\treturn telemetryContext.startSpan({ name, attributes }, (span) => callback(span as AiTelemetrySpan<Name>));\n}\n\nconst HOOK_NAMES = [\n\t\"before_run\",\n\t\"before_resume\",\n\t\"before_run_end\",\n\t\"transform_context\",\n\t\"before_request\",\n\t\"before_payload\",\n\t\"after_response\",\n\t\"before_tool\",\n\t\"after_tool\",\n\t\"before_compaction\",\n\t\"before_navigation\",\n] as const;\n\nconst EVENT_TYPES = [\n\t\"run_start\",\n\t\"run_resume\",\n\t\"run_suspend\",\n\t\"run_abort\",\n\t\"run_end\",\n\t\"fault\",\n\t\"handler_error\",\n\t\"turn_start\",\n\t\"turn_end\",\n\t\"retry_scheduled\",\n\t\"retry_start\",\n\t\"retry_end\",\n\t\"message_start\",\n\t\"message_update\",\n\t\"message_end\",\n\t\"tool_start\",\n\t\"tool_update\",\n\t\"tool_end\",\n\t\"entry_added\",\n\t\"write_pending\",\n\t\"queue_update\",\n\t\"fact_update\",\n\t\"config_update\",\n\t\"compaction_start\",\n\t\"compaction_end\",\n\t\"navigation_start\",\n\t\"navigation_end\",\n\t\"lane_created\",\n\t\"usage\",\n] as const;\n\nconst operationStartAttributes = {\n\t\"pi.session.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Session id\",\n\t},\n\t\"pi.lane.name\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Lane name\",\n\t},\n\t\"pi.operation.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Durable operation id\",\n\t},\n\t\"pi.operation.recovery\": {\n\t\ttype: \"boolean\",\n\t\trequired: true,\n\t\tdescription: \"Whether this invocation resumes durable work\",\n\t},\n} as const;\n\nconst operationErrorAttributes = {\n\t\"pi.error.code\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Stable operation error code\",\n\t},\n\t\"pi.error.type\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Low-cardinality operation error class\",\n\t},\n} as const;\n\nexport const HARNESS_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.harness.run\": {\n\t\t\tdescription: \"One admitted in-process run invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"run\"],\n\t\t\t\t\tdescription: \"Run operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"aborted\", \"failed\", \"suspended\"],\n\t\t\t\t\tdescription: \"Run invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The run fails or throws\" },\n\t\t},\n\t\t\"pi.harness.compaction\": {\n\t\t\tdescription: \"One admitted in-process manual compaction invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"compaction\"],\n\t\t\t\t\tdescription: \"Compaction operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Compaction invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The compaction fails or throws\" },\n\t\t},\n\t\t\"pi.harness.navigation\": {\n\t\t\tdescription: \"One admitted in-process navigation invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"navigation\"],\n\t\t\t\t\tdescription: \"Navigation operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Navigation invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The navigation fails or throws\" },\n\t\t},\n\t\t\"pi.harness.checkpoint\": {\n\t\t\tdescription: \"One run checkpoint\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.checkpoint.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"normal\", \"failure_drain\", \"abort_reconcile\"],\n\t\t\t\t\tdescription: \"Checkpoint purpose\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Checkpoint work throws\" },\n\t\t},\n\t\t\"pi.harness.turn\": {\n\t\t\tdescription: \"One assistant response and its tool batch\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local turn id\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Turn work throws\" },\n\t\t},\n\t\t\"pi.harness.step\": {\n\t\t\tdescription: \"One durable retry attempt\",\n\t\t\tparents: {\n\t\t\t\tkind: \"spans\",\n\t\t\t\tspans: [\"pi.harness.turn\", \"pi.harness.checkpoint\", \"pi.harness.compaction\", \"pi.harness.navigation\"],\n\t\t\t},\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"assistant\", \"compaction\", \"branch_summary\"],\n\t\t\t\t\tdescription: \"Retryable step kind\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.attempt\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"One-based durable attempt number\",\n\t\t\t\t},\n\t\t\t\t\"pi.compaction.reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tvalues: [\"manual\", \"threshold\", \"overflow\"],\n\t\t\t\t\tdescription: \"Compaction trigger\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.step.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"succeeded\", \"retry\", \"failed\", \"aborted\", \"deferred\", \"overflow\"],\n\t\t\t\t\tdescription: \"Attempt outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The attempt retries, fails, or throws\" },\n\t\t},\n\t\t\"pi.harness.tool\": {\n\t\t\tdescription: \"One raw phase-2 tool execution\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.turn\", \"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local live turn id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Tool name\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.call_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Tool call id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.replay\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"never\", \"safe\"],\n\t\t\t\t\tdescription: \"Declared replay policy\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.recovery\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this is recovery execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.tool.is_error\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdescription: \"Whether raw phase-2 execution returned an error\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Raw phase-2 execution returns an error\" },\n\t\t},\n\t\t\"pi.harness.hook\": {\n\t\t\tdescription: \"One registered hook handler invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when accepted\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: HOOK_NAMES,\n\t\t\t\t\tdescription: \"Hook name\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.registration_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Stable hook registration id\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.hook.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"skipped\", \"blocked\", \"failed\"],\n\t\t\t\t\tdescription: \"Handler outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The handler throws\" },\n\t\t},\n\t\t\"pi.harness.sleep\": {\n\t\t\tdescription: \"One retry delay\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.step\", \"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.sleep.delay_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested delay in milliseconds\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.sleep.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"elapsed\", \"aborted\"],\n\t\t\t\t\tdescription: \"Delay outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Sleep work throws\" },\n\t\t},\n\t\t\"pi.harness.event_handler\": {\n\t\t\tdescription: \"One passive event listener invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.event.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tvalues: EVENT_TYPES,\n\t\t\t\t\tdescription: \"Delivered harness event type\",\n\t\t\t\t},\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name for lane-scoped events\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The listener throws\" },\n\t\t},\n\t\t\"pi.session.write\": {\n\t\t\tdescription: \"One committed session mutation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when accepted\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.mutation\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"entry\", \"record\", \"lane\", \"fact\"],\n\t\t\t\t\tdescription: \"Session mutation kind\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.item_type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Entry, record, lane, or fact subtype\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.session.seq\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Committed session sequence when exposed\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Storage rejects the mutation\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\n/** Combined typed span vocabulary for agent-owned AI-request and harness telemetry. */\nexport const AGENT_TELEMETRY_SCHEMAS = [AI_TELEMETRY_SCHEMA, HARNESS_TELEMETRY_SCHEMA] as const;\n\nexport type HarnessSpanName = TelemetrySchemaSpanName<typeof HARNESS_TELEMETRY_SCHEMA>;\nexport type HarnessSpanStartAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEndAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanAttributes<Name extends HarnessSpanName> = HarnessSpanStartAttributes<Name> &\n\tHarnessSpanEndAttributes<Name>;\nexport type HarnessSpanEventName<Name extends HarnessSpanName> = TelemetrySchemaSpanEventName<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEventAttributes<\n\tName extends HarnessSpanName,\n\tEventName extends HarnessSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof HARNESS_TELEMETRY_SCHEMA, Name, EventName>;\nexport type HarnessTelemetrySpan<Name extends HarnessSpanName> = SchemaTelemetrySpan<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpan = TelemetrySchemaSpanUnion<typeof HARNESS_TELEMETRY_SCHEMA>;\n\nexport function startHarnessSpan<\n\tName extends HarnessSpanName,\n\tconst Attributes extends HarnessSpanStartAttributes<Name>,\n\tResult,\n>(\n\ttelemetryContext: TelemetryContext,\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<HarnessSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: HarnessTelemetrySpan<Name>) => Result | Promise<Result>,\n): Promise<Result> {\n\treturn telemetryContext.startSpan({ name, attributes }, (span: TelemetrySpan) =>\n\t\tcallback(span as HarnessTelemetrySpan<Name>),\n\t);\n}\n"]}
1
+ {"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../src/harness/telemetry.ts"],"names":[],"mappings":"AAYA,OAAO,EAAgB,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AA6BvF,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC,OAAO,EAAE,CAAC;IACV,KAAK,EAAE;QACN,eAAe,EAAE;YAChB,WAAW,EAAE,uCAAuC;YACpD,OAAO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E,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,iCAAiC,EAAE;SACvE;KACD;CAC4C,CAAC;AAE/C,uFAAuF;AACvF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,mBAAmB,EAAE,wBAAwB,CAAU,CAAC;AA2BhG,MAAM,UAAU,gBAAgB,CAK/B,IAAU,EACV,UAAkF,EAClF,QAA0F,EAC1F,OAAgB,EACE;IAClB,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,IAAmB,EAAE,EAAE,CAC3F,QAAQ,CAAC,IAAkC,EAAE,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CACjF,CAAC;AAAA,CACF","sourcesContent":["import type {\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n} from \"@earendil-works/pi-telemetry\";\nimport { type Context, getTelemetryContext, withTelemetryContext } from \"./context.ts\";\n\nexport type {\n\tAttributeValue,\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tSpanAttributes,\n\tSpanOptions,\n\tSpanStatus,\n\tTelemetryAttributeDefinition,\n\tTelemetryAttributeMetadata,\n\tTelemetryAttributeType,\n\tTelemetryContext,\n\tTelemetryEventAttributeDefinition,\n\tTelemetryEventDefinition,\n\tTelemetryParentDefinition,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n\tTelemetrySpanDefinition,\n\tTelemetryStartAttributeDefinition,\n\tTypedSpanStarter,\n} from \"@earendil-works/pi-telemetry\";\n\nexport const AI_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.ai.request\": {\n\t\t\tdescription: \"One logical request to an AI provider\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.ai.operation\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"stream\", \"fetch_deferred\", \"cancel_deferred\", \"generate_images\"],\n\t\t\t\t\tdescription: \"Logical provider operation\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.provider\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Selected provider id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.model\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested model id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.api\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Provider API id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.streaming\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this operation returns a stream\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.deferred\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Whether the operation requests or participates in deferred execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.ai.response.model\": { type: \"string\", description: \"Concrete response model\" },\n\t\t\t\t\"pi.ai.response.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Provider response id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.response.stop_reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"stop\", \"length\", \"tool_use\", \"error\", \"aborted\", \"deferred\"],\n\t\t\t\t\tdescription: \"Normalized terminal response reason\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.http.status_code\": { type: \"number\", description: \"Final HTTP status\" },\n\t\t\t\t\"pi.ai.usage.input_tokens\": { type: \"number\", description: \"Reported input tokens\" },\n\t\t\t\t\"pi.ai.usage.output_tokens\": { type: \"number\", description: \"Reported output tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_read_tokens\": { type: \"number\", description: \"Reported cache-read tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_write_tokens\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Reported cache-write tokens\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.usage.reasoning_tokens\": { type: \"number\", description: \"Reported reasoning tokens\" },\n\t\t\t\t\"pi.ai.usage.total_tokens\": { type: \"number\", description: \"Reported total tokens\" },\n\t\t\t\t\"pi.ai.usage.cost\": { type: \"number\", description: \"Reported total cost\" },\n\t\t\t\t\"pi.ai.stream.chunk_count\": { type: \"number\", description: \"Streamed update chunk count\" },\n\t\t\t\t\"pi.ai.stream.time_to_first_chunk_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Elapsed milliseconds to first update chunk\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.error.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tdescription: \"Provider or transport error class\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The operation throws or returns an error result\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\nexport type AiSpanName = TelemetrySchemaSpanName<typeof AI_TELEMETRY_SCHEMA>;\nexport type AiSpanStartAttributes<Name extends AiSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanEndAttributes<Name extends AiSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanAttributes<Name extends AiSpanName> = AiSpanStartAttributes<Name> & AiSpanEndAttributes<Name>;\nexport type AiSpanEventName<Name extends AiSpanName> = TelemetrySchemaSpanEventName<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpanEventAttributes<\n\tName extends AiSpanName,\n\tEventName extends AiSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof AI_TELEMETRY_SCHEMA, Name, EventName>;\nexport type AiTelemetrySpan<Name extends AiSpanName> = SchemaTelemetrySpan<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpan = TelemetrySchemaSpanUnion<typeof AI_TELEMETRY_SCHEMA>;\n\nexport function startAiSpan<Name extends AiSpanName, const Attributes extends AiSpanStartAttributes<Name>, Result>(\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<AiSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: AiTelemetrySpan<Name>, context: Context) => Result | Promise<Result>,\n\tcontext: Context,\n): Promise<Result> {\n\treturn getTelemetryContext(context).startSpan({ name, attributes }, (span) =>\n\t\tcallback(span as AiTelemetrySpan<Name>, withTelemetryContext(span, context)),\n\t);\n}\n\nconst HOOK_NAMES = [\n\t\"before_run\",\n\t\"before_drive\",\n\t\"before_run_end\",\n\t\"transform_context\",\n\t\"before_request\",\n\t\"before_payload\",\n\t\"after_response\",\n\t\"before_tool\",\n\t\"after_tool\",\n\t\"before_compaction\",\n\t\"before_navigation\",\n] as const;\n\nconst EVENT_TYPES = [\n\t\"run_start\",\n\t\"run_resume\",\n\t\"run_suspend\",\n\t\"operation_abort\",\n\t\"run_end\",\n\t\"fault\",\n\t\"handler_error\",\n\t\"turn_start\",\n\t\"turn_end\",\n\t\"retry_scheduled\",\n\t\"retry_start\",\n\t\"retry_end\",\n\t\"message_start\",\n\t\"message_update\",\n\t\"message_end\",\n\t\"tool_start\",\n\t\"tool_update\",\n\t\"tool_end\",\n\t\"entry_added\",\n\t\"queue_update\",\n\t\"value_update\",\n\t\"config_update\",\n\t\"compaction_start\",\n\t\"compaction_end\",\n\t\"navigation_start\",\n\t\"navigation_end\",\n\t\"lane_created\",\n\t\"usage\",\n] as const;\n\nconst operationStartAttributes = {\n\t\"pi.session.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Session id\",\n\t},\n\t\"pi.lane.name\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Lane name\",\n\t},\n\t\"pi.operation.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Durable operation id\",\n\t},\n\t\"pi.operation.recovery\": {\n\t\ttype: \"boolean\",\n\t\trequired: true,\n\t\tdescription: \"Whether this invocation resumes durable work\",\n\t},\n} as const;\n\nconst operationErrorAttributes = {\n\t\"pi.error.code\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Stable operation error code\",\n\t},\n\t\"pi.error.type\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Low-cardinality operation error class\",\n\t},\n} as const;\n\nexport const HARNESS_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.harness.run\": {\n\t\t\tdescription: \"One admitted in-process run invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"run\"],\n\t\t\t\t\tdescription: \"Run operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"aborted\", \"failed\", \"suspended\"],\n\t\t\t\t\tdescription: \"Run invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The run fails or throws\" },\n\t\t},\n\t\t\"pi.harness.compaction\": {\n\t\t\tdescription: \"One admitted in-process manual compaction invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"compaction\"],\n\t\t\t\t\tdescription: \"Compaction operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Compaction invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The compaction fails or throws\" },\n\t\t},\n\t\t\"pi.harness.navigation\": {\n\t\t\tdescription: \"One admitted in-process navigation invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"navigation\"],\n\t\t\t\t\tdescription: \"Navigation operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Navigation invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The navigation fails or throws\" },\n\t\t},\n\t\t\"pi.harness.checkpoint\": {\n\t\t\tdescription: \"One run checkpoint\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.checkpoint.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"normal\", \"abort_reconcile\"],\n\t\t\t\t\tdescription: \"Checkpoint purpose\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Checkpoint work throws\" },\n\t\t},\n\t\t\"pi.harness.turn\": {\n\t\t\tdescription: \"One assistant response and its tool batch\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local turn id\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Turn work throws\" },\n\t\t},\n\t\t\"pi.harness.step\": {\n\t\t\tdescription: \"One durable retry attempt\",\n\t\t\tparents: {\n\t\t\t\tkind: \"spans\",\n\t\t\t\tspans: [\"pi.harness.turn\", \"pi.harness.checkpoint\", \"pi.harness.compaction\", \"pi.harness.navigation\"],\n\t\t\t},\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"assistant\", \"compaction\", \"branch_summary\"],\n\t\t\t\t\tdescription: \"Retryable step kind\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.attempt\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"One-based durable attempt number\",\n\t\t\t\t},\n\t\t\t\t\"pi.compaction.reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tvalues: [\"manual\", \"threshold\", \"overflow\"],\n\t\t\t\t\tdescription: \"Compaction trigger\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.step.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"succeeded\", \"retry\", \"failed\", \"aborted\", \"deferred\", \"overflow\"],\n\t\t\t\t\tdescription: \"Attempt outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The attempt retries, fails, or throws\" },\n\t\t},\n\t\t\"pi.harness.tool\": {\n\t\t\tdescription: \"One raw phase-2 tool execution\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.turn\", \"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local live turn id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Tool name\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.call_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Tool call id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.replay\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"never\", \"safe\"],\n\t\t\t\t\tdescription: \"Declared replay policy\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.recovery\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this is recovery execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.tool.is_error\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdescription: \"Whether raw phase-2 execution returned an error\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Raw phase-2 execution returns an error\" },\n\t\t},\n\t\t\"pi.harness.hook\": {\n\t\t\tdescription: \"One registered hook handler invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when accepted\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: HOOK_NAMES,\n\t\t\t\t\tdescription: \"Hook name\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.registration_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Optional hook registration metadata\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.hook.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"skipped\", \"blocked\", \"failed\"],\n\t\t\t\t\tdescription: \"Handler outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The handler throws\" },\n\t\t},\n\t\t\"pi.harness.sleep\": {\n\t\t\tdescription: \"One retry delay\",\n\t\t\tparents: {\n\t\t\t\tkind: \"spans\",\n\t\t\t\tspans: [\n\t\t\t\t\t\"pi.harness.run\",\n\t\t\t\t\t\"pi.harness.compaction\",\n\t\t\t\t\t\"pi.harness.navigation\",\n\t\t\t\t\t\"pi.harness.turn\",\n\t\t\t\t\t\"pi.harness.checkpoint\",\n\t\t\t\t],\n\t\t\t},\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.sleep.delay_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested delay in milliseconds\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.sleep.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"elapsed\", \"aborted\"],\n\t\t\t\t\tdescription: \"Delay outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Sleep work throws\" },\n\t\t},\n\t\t\"pi.harness.event_handler\": {\n\t\t\tdescription: \"One passive event listener invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.event.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tvalues: EVENT_TYPES,\n\t\t\t\t\tdescription: \"Delivered harness event type\",\n\t\t\t\t},\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name for lane-scoped events\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The listener throws\" },\n\t\t},\n\t\t\"pi.session.write\": {\n\t\t\tdescription: \"One committed session transaction\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.session.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Session id\",\n\t\t\t\t},\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name when supplied by the caller\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when supplied by the caller\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.item_count\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Number of writes in the transaction\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.item_kinds\": {\n\t\t\t\t\ttype: \"string[]\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\telementValues: [\"entry\", \"usage\", \"value\", \"list\"],\n\t\t\t\t\tdescription: \"Distinct write kinds in the transaction\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.session.first_seq\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"First committed sequence in the transaction\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.last_seq\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Last committed sequence in the transaction\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Storage rejects the transaction\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\n/** Combined typed span vocabulary for agent-owned AI-request and harness telemetry. */\nexport const AGENT_TELEMETRY_SCHEMAS = [AI_TELEMETRY_SCHEMA, HARNESS_TELEMETRY_SCHEMA] as const;\n\nexport type HarnessSpanName = TelemetrySchemaSpanName<typeof HARNESS_TELEMETRY_SCHEMA>;\nexport type HarnessSpanStartAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEndAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanAttributes<Name extends HarnessSpanName> = HarnessSpanStartAttributes<Name> &\n\tHarnessSpanEndAttributes<Name>;\nexport type HarnessSpanEventName<Name extends HarnessSpanName> = TelemetrySchemaSpanEventName<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEventAttributes<\n\tName extends HarnessSpanName,\n\tEventName extends HarnessSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof HARNESS_TELEMETRY_SCHEMA, Name, EventName>;\nexport type HarnessTelemetrySpan<Name extends HarnessSpanName> = SchemaTelemetrySpan<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpan = TelemetrySchemaSpanUnion<typeof HARNESS_TELEMETRY_SCHEMA>;\n\nexport function startHarnessSpan<\n\tName extends HarnessSpanName,\n\tconst Attributes extends HarnessSpanStartAttributes<Name>,\n\tResult,\n>(\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<HarnessSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: HarnessTelemetrySpan<Name>, context: Context) => Result | Promise<Result>,\n\tcontext: Context,\n): Promise<Result> {\n\treturn getTelemetryContext(context).startSpan({ name, attributes }, (span: TelemetrySpan) =>\n\t\tcallback(span as HarnessTelemetrySpan<Name>, withTelemetryContext(span, context)),\n\t);\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { type Static, Type } from "typebox";
2
- import type { AgentHarnessTool } from "../types.ts";
3
- import { type TruncationResult } from "../utils/truncate.ts";
2
+ import type { Context } from "../context.ts";
3
+ import type { AgentHarnessTool, ShellOutputTruncation } from "../types.ts";
4
4
  import type { ExecutionToolContext } from "./tool-context.ts";
5
5
  declare const bashSchema: Type.TObject<{
6
6
  command: Type.TString;
@@ -8,7 +8,7 @@ declare const bashSchema: Type.TObject<{
8
8
  }>;
9
9
  export type BashToolInput = Static<typeof bashSchema>;
10
10
  export interface BashToolDetails {
11
- truncation?: TruncationResult;
11
+ truncation?: ShellOutputTruncation;
12
12
  fullOutputPath?: string;
13
13
  }
14
14
  export interface BashExecution {
@@ -17,7 +17,7 @@ export interface BashExecution {
17
17
  env: Record<string, string>;
18
18
  inheritEnv: boolean;
19
19
  }
20
- export type BashPrepare<TContext extends ExecutionToolContext = ExecutionToolContext> = (execution: BashExecution, context: TContext, signal?: AbortSignal) => void | Promise<void>;
20
+ export type BashPrepare<TContext extends ExecutionToolContext = ExecutionToolContext> = (execution: BashExecution, toolContext: TContext, context: Context) => void | Promise<void>;
21
21
  export interface BashToolOptions<TContext extends ExecutionToolContext = ExecutionToolContext> {
22
22
  commandPrefix?: string;
23
23
  prepare?: BashPrepare<TContext>;
@@ -1 +1 @@
1
- {"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/harness/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD,OAAO,EAAoD,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC/G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAK9D,QAAA,MAAM,UAAU;;;EAGd,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,oBAAoB,GAAG,oBAAoB,IAAI,CACvF,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,QAAQ,EACjB,MAAM,CAAC,EAAE,WAAW,KAChB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,MAAM,WAAW,eAAe,CAAC,QAAQ,SAAS,oBAAoB,GAAG,oBAAoB;IAC5F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;CAChC;AAYD,wBAAgB,cAAc,CAAC,QAAQ,SAAS,oBAAoB,GAAG,oBAAoB,EAC1F,OAAO,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,GACjC,gBAAgB,CAAC,QAAQ,EAAE,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CA4G5E","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { AgentHarnessTool } from \"../types.ts\";\nimport { getOrThrow } from \"../types.ts\";\nimport { executeShellWithCapture, type ShellCaptureProgress } from \"../utils/shell-output.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult } from \"../utils/truncate.ts\";\nimport type { ExecutionToolContext } from \"./tool-context.ts\";\n\nconst MAX_TIMEOUT_SECONDS = 2_147_483_647 / 1000;\nconst BASH_UPDATE_THROTTLE_MS = 100;\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Bash command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n}\n\nexport interface BashExecution {\n\tcommand: string;\n\tcwd: string;\n\tenv: Record<string, string>;\n\tinheritEnv: boolean;\n}\n\nexport type BashPrepare<TContext extends ExecutionToolContext = ExecutionToolContext> = (\n\texecution: BashExecution,\n\tcontext: TContext,\n\tsignal?: AbortSignal,\n) => void | Promise<void>;\n\nexport interface BashToolOptions<TContext extends ExecutionToolContext = ExecutionToolContext> {\n\tcommandPrefix?: string;\n\tprepare?: BashPrepare<TContext>;\n}\n\nfunction validateTimeout(timeout: number | undefined): void {\n\tif (timeout === undefined) return;\n\tif (!Number.isFinite(timeout) || timeout <= 0) {\n\t\tthrow new Error(\"Invalid timeout: must be a finite number of seconds\");\n\t}\n\tif (timeout > MAX_TIMEOUT_SECONDS) {\n\t\tthrow new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);\n\t}\n}\n\nexport function createBashTool<TContext extends ExecutionToolContext = ExecutionToolContext>(\n\toptions?: BashToolOptions<TContext>,\n): AgentHarnessTool<TContext, typeof bashSchema, BashToolDetails | undefined> {\n\treturn {\n\t\tname: \"bash\",\n\t\tlabel: \"bash\",\n\t\tdescription: `Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tparameters: bashSchema,\n\t\tasync execute(_toolCallId, { command, timeout }, signal, onUpdate, context) {\n\t\t\tvalidateTimeout(timeout);\n\t\t\tconst { env } = context;\n\t\t\tconst execution: BashExecution = {\n\t\t\t\tcommand: options?.commandPrefix ? `${options.commandPrefix}\\n${command}` : command,\n\t\t\t\tcwd: env.cwd,\n\t\t\t\tenv: {},\n\t\t\t\tinheritEnv: true,\n\t\t\t};\n\t\t\tawait options?.prepare?.(execution, context, signal);\n\t\t\tlet getLatestProgress: (() => ShellCaptureProgress) | undefined;\n\t\t\tlet updateTimer: ReturnType<typeof setTimeout> | undefined;\n\t\t\tlet updateDirty = false;\n\t\t\tlet lastUpdateAt = 0;\n\n\t\t\tconst emitOutputUpdate = (): void => {\n\t\t\t\tif (!onUpdate || !updateDirty || !getLatestProgress) return;\n\t\t\t\tupdateDirty = false;\n\t\t\t\tlastUpdateAt = Date.now();\n\t\t\t\tconst progress = getLatestProgress();\n\t\t\t\tonUpdate({\n\t\t\t\t\tcontent: [{ type: \"text\", text: progress.output }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\ttruncation: progress.truncation.truncated ? progress.truncation : undefined,\n\t\t\t\t\t\tfullOutputPath: progress.fullOutputPath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t};\n\t\t\tconst clearUpdateTimer = (): void => {\n\t\t\t\tif (!updateTimer) return;\n\t\t\t\tclearTimeout(updateTimer);\n\t\t\t\tupdateTimer = undefined;\n\t\t\t};\n\t\t\tconst scheduleOutputUpdate = (): void => {\n\t\t\t\tif (!onUpdate) return;\n\t\t\t\tupdateDirty = true;\n\t\t\t\tconst delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);\n\t\t\t\tif (delay <= 0) {\n\t\t\t\t\tclearUpdateTimer();\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tupdateTimer ??= setTimeout(() => {\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t}, delay);\n\t\t\t};\n\n\t\t\tonUpdate?.({ content: [], details: undefined });\n\t\t\ttry {\n\t\t\t\tconst capture = getOrThrow(\n\t\t\t\t\tawait executeShellWithCapture(env, execution.command, {\n\t\t\t\t\t\tcwd: execution.cwd,\n\t\t\t\t\t\tenv: execution.env,\n\t\t\t\t\t\tinheritEnv: execution.inheritEnv,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tabortSignal: signal,\n\t\t\t\t\t\treturnExecutionErrors: true,\n\t\t\t\t\t\tonChunk: (_chunk, getProgress) => {\n\t\t\t\t\t\t\tgetLatestProgress = getProgress;\n\t\t\t\t\t\t\tscheduleOutputUpdate();\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tclearUpdateTimer();\n\t\t\t\tgetLatestProgress = () => capture;\n\t\t\t\tupdateDirty = true;\n\t\t\t\temitOutputUpdate();\n\n\t\t\t\tlet outputText = capture.output;\n\t\t\t\tlet details: BashToolDetails | undefined;\n\t\t\t\tif (capture.truncation.truncated) {\n\t\t\t\t\tdetails = { truncation: capture.truncation, fullOutputPath: capture.fullOutputPath };\n\t\t\t\t\tconst startLine = capture.truncation.totalLines - capture.truncation.outputLines + 1;\n\t\t\t\t\tconst endLine = capture.truncation.totalLines;\n\t\t\t\t\tif (capture.truncation.lastLinePartial) {\n\t\t\t\t\t\tconst lastLineSize = formatSize(capture.lastLineBytes);\n\t\t\t\t\t\toutputText += `\\n\\n[Showing last ${formatSize(capture.truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${capture.fullOutputPath}]`;\n\t\t\t\t\t} else if (capture.truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLine}-${endLine} of ${capture.truncation.totalLines}. Full output: ${capture.fullOutputPath}]`;\n\t\t\t\t\t} else {\n\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLine}-${endLine} of ${capture.truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${capture.fullOutputPath}]`;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst appendStatus = (status: string): string => `${outputText ? `${outputText}\\n\\n` : \"\"}${status}`;\n\t\t\t\tif (capture.cancelled) throw new Error(appendStatus(\"Command aborted\"));\n\t\t\t\tif (capture.executionError?.code === \"timeout\") {\n\t\t\t\t\tthrow new Error(appendStatus(`Command timed out after ${timeout} seconds`), {\n\t\t\t\t\t\tcause: capture.executionError,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (capture.executionError) throw capture.executionError;\n\t\t\t\tif (capture.exitCode !== 0 && capture.exitCode !== undefined) {\n\t\t\t\t\tthrow new Error(appendStatus(`Command exited with code ${capture.exitCode}`));\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputText || \"(no output)\" }], details };\n\t\t\t} finally {\n\t\t\t\tclearUpdateTimer();\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/harness/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAmB,MAAM,aAAa,CAAC;AAG5F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAK9D,QAAA,MAAM,UAAU;;;EAGd,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,qBAAqB,CAAC;IACnC,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,oBAAoB,GAAG,oBAAoB,IAAI,CACvF,SAAS,EAAE,aAAa,EACxB,WAAW,EAAE,QAAQ,EACrB,OAAO,EAAE,OAAO,KACZ,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,MAAM,WAAW,eAAe,CAAC,QAAQ,SAAS,oBAAoB,GAAG,oBAAoB;IAC5F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;CAChC;AAYD,wBAAgB,cAAc,CAAC,QAAQ,SAAS,oBAAoB,GAAG,oBAAoB,EAC1F,OAAO,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,GACjC,gBAAgB,CAAC,QAAQ,EAAE,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CA4F5E","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { Context } from \"../context.ts\";\nimport type { AgentHarnessTool, ShellOutputTruncation, ShellOutputView } from \"../types.ts\";\nimport { applyShellOutputUpdate } from \"../utils/output-capture.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize } from \"../utils/truncate.ts\";\nimport type { ExecutionToolContext } from \"./tool-context.ts\";\n\nconst MAX_TIMEOUT_SECONDS = 2_147_483_647 / 1000;\nconst BASH_CHECKPOINT_INTERVAL_MS = 2_000;\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Bash command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: ShellOutputTruncation;\n\tfullOutputPath?: string;\n}\n\nexport interface BashExecution {\n\tcommand: string;\n\tcwd: string;\n\tenv: Record<string, string>;\n\tinheritEnv: boolean;\n}\n\nexport type BashPrepare<TContext extends ExecutionToolContext = ExecutionToolContext> = (\n\texecution: BashExecution,\n\ttoolContext: TContext,\n\tcontext: Context,\n) => void | Promise<void>;\n\nexport interface BashToolOptions<TContext extends ExecutionToolContext = ExecutionToolContext> {\n\tcommandPrefix?: string;\n\tprepare?: BashPrepare<TContext>;\n}\n\nfunction validateTimeout(timeout: number | undefined): void {\n\tif (timeout === undefined) return;\n\tif (!Number.isFinite(timeout) || timeout <= 0) {\n\t\tthrow new Error(\"Invalid timeout: must be a finite number of seconds\");\n\t}\n\tif (timeout > MAX_TIMEOUT_SECONDS) {\n\t\tthrow new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);\n\t}\n}\n\nexport function createBashTool<TContext extends ExecutionToolContext = ExecutionToolContext>(\n\toptions?: BashToolOptions<TContext>,\n): AgentHarnessTool<TContext, typeof bashSchema, BashToolDetails | undefined> {\n\treturn {\n\t\tname: \"bash\",\n\t\tlabel: \"bash\",\n\t\tdescription: `Execute a bash command in the current working directory. Returns combined stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tparameters: bashSchema,\n\t\tasync execute(_toolCallId, { command, timeout }, onUpdate, toolContext, _invocation, context) {\n\t\t\tvalidateTimeout(timeout);\n\t\t\tconst { env } = toolContext;\n\t\t\tconst execution: BashExecution = {\n\t\t\t\tcommand: options?.commandPrefix ? `${options.commandPrefix}\\n${command}` : command,\n\t\t\t\tcwd: env.cwd,\n\t\t\t\tenv: {},\n\t\t\t\tinheritEnv: true,\n\t\t\t};\n\t\t\tawait options?.prepare?.(execution, toolContext, context);\n\t\t\tlet view: ShellOutputView | undefined;\n\t\t\tlet lastCheckpointAt = Date.now();\n\t\t\tlet lastCheckpoint: string | undefined;\n\t\t\tlet acceptingUpdates = true;\n\n\t\t\tonUpdate({ content: [], details: undefined });\n\t\t\tconst result = await env.exec(\n\t\t\t\texecution.command,\n\t\t\t\t{\n\t\t\t\t\tcwd: execution.cwd,\n\t\t\t\t\tenv: execution.env,\n\t\t\t\t\tinheritEnv: execution.inheritEnv,\n\t\t\t\t\ttimeout,\n\t\t\t\t\tcapture: {\n\t\t\t\t\t\tlimits: { maxBytes: DEFAULT_MAX_BYTES, maxLines: DEFAULT_MAX_LINES, retain: \"tail\" },\n\t\t\t\t\t\tspill: true,\n\t\t\t\t\t},\n\t\t\t\t\tonUpdate: (update) => {\n\t\t\t\t\t\tif (!acceptingUpdates) return;\n\t\t\t\t\t\tview = applyShellOutputUpdate(view, update);\n\t\t\t\t\t\tconst snapshot = {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: view.text }],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\ttruncation: view.truncation.truncated ? view.truncation : undefined,\n\t\t\t\t\t\t\t\tfullOutputPath: view.spillPath,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst now = Date.now();\n\t\t\t\t\t\tconst encoded = JSON.stringify(snapshot);\n\t\t\t\t\t\tconst checkpoint =\n\t\t\t\t\t\t\tnow - lastCheckpointAt >= BASH_CHECKPOINT_INTERVAL_MS && encoded !== lastCheckpoint;\n\t\t\t\t\t\tonUpdate(snapshot, checkpoint ? { checkpoint: true } : undefined);\n\t\t\t\t\t\tif (checkpoint) {\n\t\t\t\t\t\t\tlastCheckpointAt = now;\n\t\t\t\t\t\t\tlastCheckpoint = encoded;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tcontext,\n\t\t\t);\n\t\t\tacceptingUpdates = false;\n\n\t\t\tlet outputText = view?.text ?? \"\";\n\t\t\tconst capture = result.ok ? { text: outputText, ...result.value } : view;\n\t\t\tlet details: BashToolDetails | undefined;\n\t\t\tif (capture?.truncation.truncated) {\n\t\t\t\tdetails = { truncation: capture.truncation, fullOutputPath: capture.spillPath };\n\t\t\t\tconst startLine = capture.truncation.totalLines - capture.truncation.outputLines + 1;\n\t\t\t\tconst endLine = capture.truncation.totalLines;\n\t\t\t\tif (capture.truncation.lastLinePartial) {\n\t\t\t\t\tconst lastLineSize = formatSize(capture.lastLineBytes ?? capture.truncation.outputBytes);\n\t\t\t\t\toutputText += `\\n\\n[Showing last ${formatSize(capture.truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${capture.spillPath}]`;\n\t\t\t\t} else if (capture.truncation.truncatedBy === \"lines\") {\n\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLine}-${endLine} of ${capture.truncation.totalLines}. Full output: ${capture.spillPath}]`;\n\t\t\t\t} else {\n\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLine}-${endLine} of ${capture.truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${capture.spillPath}]`;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!result.ok) {\n\t\t\t\tconst status =\n\t\t\t\t\tresult.error.code === \"timeout\"\n\t\t\t\t\t\t? `Command timed out after ${timeout} seconds`\n\t\t\t\t\t\t: result.error.code === \"aborted\"\n\t\t\t\t\t\t\t? \"Command aborted\"\n\t\t\t\t\t\t\t: result.error.message;\n\t\t\t\tthrow new Error(outputText ? `${outputText}\\n\\n${status}` : status, { cause: result.error });\n\t\t\t}\n\t\t\tif (result.value.exitCode !== 0) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`${outputText ? `${outputText}\\n\\n` : \"\"}Command exited with code ${result.value.exitCode}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn { content: [{ type: \"text\", text: outputText || \"(no output)\" }], details };\n\t\t},\n\t};\n}\n"]}