@llblab/pi-kit 0.38.3 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (430) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +2 -2
  3. package/node_modules/@llblab/pi-actors/AGENTS.md +108 -20
  4. package/node_modules/@llblab/pi-actors/BACKLOG.md +207 -4
  5. package/node_modules/@llblab/pi-actors/CHANGELOG.md +13 -0
  6. package/node_modules/@llblab/pi-actors/README.md +31 -1
  7. package/node_modules/@llblab/pi-actors/dist/index.js +1 -1
  8. package/node_modules/@llblab/pi-actors/dist/lib/async-runs.d.ts +37 -0
  9. package/node_modules/@llblab/pi-actors/dist/lib/async-runs.js +131 -62
  10. package/node_modules/@llblab/pi-actors/dist/lib/automatic-review-runtime.d.ts +2 -0
  11. package/node_modules/@llblab/pi-actors/dist/lib/automatic-review-runtime.js +3 -2
  12. package/node_modules/@llblab/pi-actors/dist/lib/command-templates.d.ts +37 -0
  13. package/node_modules/@llblab/pi-actors/dist/lib/command-templates.js +263 -129
  14. package/node_modules/@llblab/pi-actors/dist/lib/execution-files.d.ts +32 -0
  15. package/node_modules/@llblab/pi-actors/dist/lib/execution-files.js +128 -0
  16. package/node_modules/@llblab/pi-actors/dist/lib/execution-output.js +5 -4
  17. package/node_modules/@llblab/pi-actors/dist/lib/execution-sessions.d.ts +19 -1
  18. package/node_modules/@llblab/pi-actors/dist/lib/execution-sessions.js +62 -26
  19. package/node_modules/@llblab/pi-actors/dist/lib/execution.d.ts +4 -1
  20. package/node_modules/@llblab/pi-actors/dist/lib/execution.js +6 -1
  21. package/node_modules/@llblab/pi-actors/dist/lib/extension-runtime.d.ts +9 -2
  22. package/node_modules/@llblab/pi-actors/dist/lib/extension-runtime.js +92 -14
  23. package/node_modules/@llblab/pi-actors/dist/lib/file-state.js +21 -2
  24. package/node_modules/@llblab/pi-actors/dist/lib/inspector-command.js +2 -2
  25. package/node_modules/@llblab/pi-actors/dist/lib/inspector-overlay.d.ts +25 -7
  26. package/node_modules/@llblab/pi-actors/dist/lib/inspector-overlay.js +562 -262
  27. package/node_modules/@llblab/pi-actors/dist/lib/inspector.d.ts +20 -10
  28. package/node_modules/@llblab/pi-actors/dist/lib/inspector.js +80 -91
  29. package/node_modules/@llblab/pi-actors/dist/lib/limits.d.ts +1 -0
  30. package/node_modules/@llblab/pi-actors/dist/lib/limits.js +1 -0
  31. package/node_modules/@llblab/pi-actors/dist/lib/observability.d.ts +15 -1
  32. package/node_modules/@llblab/pi-actors/dist/lib/observability.js +216 -99
  33. package/node_modules/@llblab/pi-actors/dist/lib/pi.d.ts +5 -4
  34. package/node_modules/@llblab/pi-actors/dist/lib/pi.js +64 -10
  35. package/node_modules/@llblab/pi-actors/dist/lib/recipe-projection.d.ts +18 -0
  36. package/node_modules/@llblab/pi-actors/dist/lib/recipe-projection.js +220 -0
  37. package/node_modules/@llblab/pi-actors/dist/lib/recipes-context.d.ts +2 -0
  38. package/node_modules/@llblab/pi-actors/dist/lib/recipes-context.js +30 -6
  39. package/node_modules/@llblab/pi-actors/dist/lib/registry.js +270 -36
  40. package/node_modules/@llblab/pi-actors/dist/lib/run-delivery.d.ts +213 -5
  41. package/node_modules/@llblab/pi-actors/dist/lib/run-delivery.js +1909 -40
  42. package/node_modules/@llblab/pi-actors/dist/lib/run-supervision.d.ts +107 -0
  43. package/node_modules/@llblab/pi-actors/dist/lib/run-supervision.js +412 -0
  44. package/node_modules/@llblab/pi-actors/dist/lib/run-ui-runtime.d.ts +9 -2
  45. package/node_modules/@llblab/pi-actors/dist/lib/run-ui-runtime.js +283 -60
  46. package/node_modules/@llblab/pi-actors/dist/lib/runs-artifacts.d.ts +26 -1
  47. package/node_modules/@llblab/pi-actors/dist/lib/runs-artifacts.js +68 -2
  48. package/node_modules/@llblab/pi-actors/dist/lib/runs-context-exports.d.ts +451 -0
  49. package/node_modules/@llblab/pi-actors/dist/lib/runs-context-exports.js +2315 -0
  50. package/node_modules/@llblab/pi-actors/dist/lib/runs-context-index.d.ts +97 -0
  51. package/node_modules/@llblab/pi-actors/dist/lib/runs-context-index.js +368 -0
  52. package/node_modules/@llblab/pi-actors/dist/lib/runs-control-delivery.js +46 -7
  53. package/node_modules/@llblab/pi-actors/dist/lib/runs-control.d.ts +78 -2
  54. package/node_modules/@llblab/pi-actors/dist/lib/runs-control.js +334 -2
  55. package/node_modules/@llblab/pi-actors/dist/lib/runs-controls.js +4 -1
  56. package/node_modules/@llblab/pi-actors/dist/lib/runs-descendant-launches.d.ts +80 -0
  57. package/node_modules/@llblab/pi-actors/dist/lib/runs-descendant-launches.js +287 -0
  58. package/node_modules/@llblab/pi-actors/dist/lib/runs-execution-evidence.d.ts +110 -0
  59. package/node_modules/@llblab/pi-actors/dist/lib/runs-execution-evidence.js +282 -0
  60. package/node_modules/@llblab/pi-actors/dist/lib/runs-index.d.ts +66 -1
  61. package/node_modules/@llblab/pi-actors/dist/lib/runs-index.js +349 -13
  62. package/node_modules/@llblab/pi-actors/dist/lib/runs-native-launches.d.ts +73 -0
  63. package/node_modules/@llblab/pi-actors/dist/lib/runs-native-launches.js +227 -0
  64. package/node_modules/@llblab/pi-actors/dist/lib/runs-outcomes.d.ts +141 -0
  65. package/node_modules/@llblab/pi-actors/dist/lib/runs-outcomes.js +292 -0
  66. package/node_modules/@llblab/pi-actors/dist/lib/runs-ownership.d.ts +10 -1
  67. package/node_modules/@llblab/pi-actors/dist/lib/runs-ownership.js +36 -4
  68. package/node_modules/@llblab/pi-actors/dist/lib/runs-process-windows-mi.d.ts +46 -0
  69. package/node_modules/@llblab/pi-actors/dist/lib/runs-process-windows-mi.js +114 -0
  70. package/node_modules/@llblab/pi-actors/dist/lib/runs-process.d.ts +34 -1
  71. package/node_modules/@llblab/pi-actors/dist/lib/runs-process.js +158 -26
  72. package/node_modules/@llblab/pi-actors/dist/lib/runs-results.d.ts +116 -0
  73. package/node_modules/@llblab/pi-actors/dist/lib/runs-results.js +518 -0
  74. package/node_modules/@llblab/pi-actors/dist/lib/runs-retention.d.ts +15 -2
  75. package/node_modules/@llblab/pi-actors/dist/lib/runs-retention.js +148 -9
  76. package/node_modules/@llblab/pi-actors/dist/lib/runs-session-exports.d.ts +95 -0
  77. package/node_modules/@llblab/pi-actors/dist/lib/runs-session-exports.js +470 -0
  78. package/node_modules/@llblab/pi-actors/dist/lib/runs-snapshot.d.ts +58 -0
  79. package/node_modules/@llblab/pi-actors/dist/lib/runs-snapshot.js +92 -0
  80. package/node_modules/@llblab/pi-actors/dist/lib/runs-start.d.ts +2 -0
  81. package/node_modules/@llblab/pi-actors/dist/lib/runs-start.js +44 -3
  82. package/node_modules/@llblab/pi-actors/dist/lib/runs-status.d.ts +15 -1
  83. package/node_modules/@llblab/pi-actors/dist/lib/runs-status.js +337 -13
  84. package/node_modules/@llblab/pi-actors/dist/lib/runs-supervision.d.ts +105 -0
  85. package/node_modules/@llblab/pi-actors/dist/lib/runs-supervision.js +501 -0
  86. package/node_modules/@llblab/pi-actors/dist/lib/runs-trace.d.ts +1 -0
  87. package/node_modules/@llblab/pi-actors/dist/lib/runs-trace.js +14 -3
  88. package/node_modules/@llblab/pi-actors/dist/lib/runtime.js +22 -3
  89. package/node_modules/@llblab/pi-actors/dist/lib/session-evidence.d.ts +37 -0
  90. package/node_modules/@llblab/pi-actors/dist/lib/session-evidence.js +59 -3
  91. package/node_modules/@llblab/pi-actors/dist/lib/state-readers.d.ts +4 -1
  92. package/node_modules/@llblab/pi-actors/dist/lib/state-readers.js +14 -8
  93. package/node_modules/@llblab/pi-actors/dist/lib/temp.d.ts +2 -4
  94. package/node_modules/@llblab/pi-actors/dist/lib/temp.js +4 -56
  95. package/node_modules/@llblab/pi-actors/dist/lib/tools-access.d.ts +3 -0
  96. package/node_modules/@llblab/pi-actors/dist/lib/tools-access.js +13 -0
  97. package/node_modules/@llblab/pi-actors/dist/lib/tools-inspect.d.ts +1 -0
  98. package/node_modules/@llblab/pi-actors/dist/lib/tools-inspect.js +110 -43
  99. package/node_modules/@llblab/pi-actors/dist/lib/tools-local.d.ts +3 -0
  100. package/node_modules/@llblab/pi-actors/dist/lib/tools-local.js +18 -6
  101. package/node_modules/@llblab/pi-actors/dist/lib/tools-message.d.ts +4 -1
  102. package/node_modules/@llblab/pi-actors/dist/lib/tools-message.js +126 -31
  103. package/node_modules/@llblab/pi-actors/dist/lib/tools-response.d.ts +31 -3
  104. package/node_modules/@llblab/pi-actors/dist/lib/tools-response.js +311 -47
  105. package/node_modules/@llblab/pi-actors/dist/lib/tools-spawn.d.ts +3 -0
  106. package/node_modules/@llblab/pi-actors/dist/lib/tools-spawn.js +29 -7
  107. package/node_modules/@llblab/pi-actors/dist/lib/trace-projection.d.ts +20 -0
  108. package/node_modules/@llblab/pi-actors/dist/lib/trace-projection.js +192 -43
  109. package/node_modules/@llblab/pi-actors/dist/scripts/async-runner.mjs +272 -194
  110. package/node_modules/@llblab/pi-actors/dist/scripts/conformance.mjs +14 -2
  111. package/node_modules/@llblab/pi-actors/dist/skills/actors/SKILL.md +46 -2
  112. package/node_modules/@llblab/pi-actors/dist/skills/actors/references/diagnostics.md +40 -0
  113. package/node_modules/@llblab/pi-actors/dist/skills/actors/references/runs.md +55 -1
  114. package/node_modules/@llblab/pi-actors/docs/README.md +9 -1
  115. package/node_modules/@llblab/pi-actors/docs/actor-inspector.md +84 -15
  116. package/node_modules/@llblab/pi-actors/docs/agent-experience.md +216 -0
  117. package/node_modules/@llblab/pi-actors/docs/async-runs.md +18 -2
  118. package/node_modules/@llblab/pi-actors/docs/composition-transport.md +103 -0
  119. package/node_modules/@llblab/pi-actors/docs/coordinator-delivery.md +204 -4
  120. package/node_modules/@llblab/pi-actors/docs/inspection.md +38 -2
  121. package/node_modules/@llblab/pi-actors/docs/output-projection-map.md +130 -0
  122. package/node_modules/@llblab/pi-actors/docs/releasing.md +19 -2
  123. package/node_modules/@llblab/pi-actors/docs/run-supervision.md +1622 -0
  124. package/node_modules/@llblab/pi-actors/docs/template-recipes.md +4 -0
  125. package/node_modules/@llblab/pi-actors/docs/windows-process-observation.md +248 -0
  126. package/node_modules/@llblab/pi-actors/index.ts +1 -1
  127. package/node_modules/@llblab/pi-actors/lib/async-runs.ts +164 -73
  128. package/node_modules/@llblab/pi-actors/lib/automatic-review-runtime.ts +4 -2
  129. package/node_modules/@llblab/pi-actors/lib/command-templates.ts +287 -138
  130. package/node_modules/@llblab/pi-actors/lib/execution-files.ts +118 -0
  131. package/node_modules/@llblab/pi-actors/lib/execution-output.ts +4 -4
  132. package/node_modules/@llblab/pi-actors/lib/execution-sessions.ts +57 -27
  133. package/node_modules/@llblab/pi-actors/lib/execution.ts +8 -0
  134. package/node_modules/@llblab/pi-actors/lib/extension-runtime.ts +102 -12
  135. package/node_modules/@llblab/pi-actors/lib/file-state.ts +16 -2
  136. package/node_modules/@llblab/pi-actors/lib/inspector-command.ts +2 -2
  137. package/node_modules/@llblab/pi-actors/lib/inspector-overlay.ts +524 -261
  138. package/node_modules/@llblab/pi-actors/lib/inspector.ts +101 -130
  139. package/node_modules/@llblab/pi-actors/lib/limits.ts +1 -0
  140. package/node_modules/@llblab/pi-actors/lib/observability.ts +235 -116
  141. package/node_modules/@llblab/pi-actors/lib/pi.ts +59 -11
  142. package/node_modules/@llblab/pi-actors/lib/recipe-projection.ts +232 -0
  143. package/node_modules/@llblab/pi-actors/lib/recipes-context.ts +27 -6
  144. package/node_modules/@llblab/pi-actors/lib/registry.ts +266 -36
  145. package/node_modules/@llblab/pi-actors/lib/run-delivery.ts +1737 -49
  146. package/node_modules/@llblab/pi-actors/lib/run-supervision.ts +411 -0
  147. package/node_modules/@llblab/pi-actors/lib/run-ui-runtime.ts +237 -73
  148. package/node_modules/@llblab/pi-actors/lib/runs-artifacts.ts +73 -1
  149. package/node_modules/@llblab/pi-actors/lib/runs-context-exports.ts +1871 -0
  150. package/node_modules/@llblab/pi-actors/lib/runs-context-index.ts +372 -0
  151. package/node_modules/@llblab/pi-actors/lib/runs-control-delivery.ts +36 -18
  152. package/node_modules/@llblab/pi-actors/lib/runs-control.ts +297 -1
  153. package/node_modules/@llblab/pi-actors/lib/runs-controls.ts +3 -1
  154. package/node_modules/@llblab/pi-actors/lib/runs-descendant-launches.ts +338 -0
  155. package/node_modules/@llblab/pi-actors/lib/runs-execution-evidence.ts +302 -0
  156. package/node_modules/@llblab/pi-actors/lib/runs-index.ts +345 -17
  157. package/node_modules/@llblab/pi-actors/lib/runs-native-launches.ts +270 -0
  158. package/node_modules/@llblab/pi-actors/lib/runs-outcomes.ts +377 -0
  159. package/node_modules/@llblab/pi-actors/lib/runs-ownership.ts +37 -4
  160. package/node_modules/@llblab/pi-actors/lib/runs-process-windows-mi.ts +113 -0
  161. package/node_modules/@llblab/pi-actors/lib/runs-process.ts +210 -34
  162. package/node_modules/@llblab/pi-actors/lib/runs-results.ts +601 -0
  163. package/node_modules/@llblab/pi-actors/lib/runs-retention.ts +134 -10
  164. package/node_modules/@llblab/pi-actors/lib/runs-session-exports.ts +406 -0
  165. package/node_modules/@llblab/pi-actors/lib/runs-snapshot.ts +143 -0
  166. package/node_modules/@llblab/pi-actors/lib/runs-start.ts +44 -2
  167. package/node_modules/@llblab/pi-actors/lib/runs-status.ts +252 -10
  168. package/node_modules/@llblab/pi-actors/lib/runs-supervision.ts +394 -0
  169. package/node_modules/@llblab/pi-actors/lib/runs-trace.ts +14 -3
  170. package/node_modules/@llblab/pi-actors/lib/runtime.ts +22 -3
  171. package/node_modules/@llblab/pi-actors/lib/session-evidence.ts +76 -4
  172. package/node_modules/@llblab/pi-actors/lib/state-readers.ts +16 -7
  173. package/node_modules/@llblab/pi-actors/lib/temp.ts +3 -56
  174. package/node_modules/@llblab/pi-actors/lib/tools-access.ts +13 -0
  175. package/node_modules/@llblab/pi-actors/lib/tools-inspect.ts +110 -51
  176. package/node_modules/@llblab/pi-actors/lib/tools-local.ts +37 -24
  177. package/node_modules/@llblab/pi-actors/lib/tools-message.ts +120 -37
  178. package/node_modules/@llblab/pi-actors/lib/tools-response.ts +273 -50
  179. package/node_modules/@llblab/pi-actors/lib/tools-spawn.ts +31 -10
  180. package/node_modules/@llblab/pi-actors/lib/trace-projection.ts +165 -42
  181. package/node_modules/@llblab/pi-actors/package.json +10 -6
  182. package/node_modules/@llblab/pi-actors/scripts/async-runner.mjs +272 -194
  183. package/node_modules/@llblab/pi-actors/scripts/conformance.mjs +14 -2
  184. package/node_modules/@llblab/pi-actors/skills/actors/SKILL.md +46 -2
  185. package/node_modules/@llblab/pi-actors/skills/actors/references/diagnostics.md +40 -0
  186. package/node_modules/@llblab/pi-actors/skills/actors/references/runs.md +55 -1
  187. package/node_modules/@llblab/pi-codex-usage/AGENTS.md +2 -2
  188. package/node_modules/@llblab/pi-codex-usage/CHANGELOG.md +6 -0
  189. package/node_modules/@llblab/pi-codex-usage/README.md +9 -5
  190. package/node_modules/@llblab/pi-codex-usage/lib/query.ts +229 -50
  191. package/node_modules/@llblab/pi-codex-usage/lib/usage.ts +9 -1
  192. package/node_modules/@llblab/pi-codex-usage/package.json +1 -1
  193. package/node_modules/yaml/LICENSE +13 -0
  194. package/node_modules/yaml/README.md +172 -0
  195. package/node_modules/yaml/bin.mjs +11 -0
  196. package/node_modules/yaml/browser/dist/compose/compose-collection.js +88 -0
  197. package/node_modules/yaml/browser/dist/compose/compose-doc.js +43 -0
  198. package/node_modules/yaml/browser/dist/compose/compose-node.js +109 -0
  199. package/node_modules/yaml/browser/dist/compose/compose-scalar.js +86 -0
  200. package/node_modules/yaml/browser/dist/compose/composer.js +219 -0
  201. package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +115 -0
  202. package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
  203. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +49 -0
  204. package/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
  205. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +207 -0
  206. package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +225 -0
  207. package/node_modules/yaml/browser/dist/compose/resolve-props.js +146 -0
  208. package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
  209. package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +26 -0
  210. package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
  211. package/node_modules/yaml/browser/dist/compose/util-map-includes.js +13 -0
  212. package/node_modules/yaml/browser/dist/doc/Document.js +335 -0
  213. package/node_modules/yaml/browser/dist/doc/anchors.js +71 -0
  214. package/node_modules/yaml/browser/dist/doc/applyReviver.js +55 -0
  215. package/node_modules/yaml/browser/dist/doc/createNode.js +88 -0
  216. package/node_modules/yaml/browser/dist/doc/directives.js +176 -0
  217. package/node_modules/yaml/browser/dist/errors.js +57 -0
  218. package/node_modules/yaml/browser/dist/index.js +17 -0
  219. package/node_modules/yaml/browser/dist/log.js +11 -0
  220. package/node_modules/yaml/browser/dist/nodes/Alias.js +116 -0
  221. package/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
  222. package/node_modules/yaml/browser/dist/nodes/Node.js +38 -0
  223. package/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
  224. package/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
  225. package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +144 -0
  226. package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
  227. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +63 -0
  228. package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
  229. package/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
  230. package/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
  231. package/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
  232. package/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
  233. package/node_modules/yaml/browser/dist/parse/cst.js +98 -0
  234. package/node_modules/yaml/browser/dist/parse/lexer.js +721 -0
  235. package/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
  236. package/node_modules/yaml/browser/dist/parse/parser.js +975 -0
  237. package/node_modules/yaml/browser/dist/public-api.js +102 -0
  238. package/node_modules/yaml/browser/dist/schema/Schema.js +37 -0
  239. package/node_modules/yaml/browser/dist/schema/common/map.js +17 -0
  240. package/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
  241. package/node_modules/yaml/browser/dist/schema/common/seq.js +17 -0
  242. package/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
  243. package/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
  244. package/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
  245. package/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
  246. package/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
  247. package/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
  248. package/node_modules/yaml/browser/dist/schema/tags.js +96 -0
  249. package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +58 -0
  250. package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
  251. package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
  252. package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
  253. package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +67 -0
  254. package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
  255. package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
  256. package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
  257. package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
  258. package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
  259. package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
  260. package/node_modules/yaml/browser/dist/stringify/stringify.js +129 -0
  261. package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +153 -0
  262. package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
  263. package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
  264. package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +25 -0
  265. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
  266. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +336 -0
  267. package/node_modules/yaml/browser/dist/util.js +11 -0
  268. package/node_modules/yaml/browser/dist/visit.js +233 -0
  269. package/node_modules/yaml/browser/index.js +5 -0
  270. package/node_modules/yaml/browser/package.json +3 -0
  271. package/node_modules/yaml/dist/cli.d.ts +8 -0
  272. package/node_modules/yaml/dist/cli.mjs +201 -0
  273. package/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
  274. package/node_modules/yaml/dist/compose/compose-collection.js +90 -0
  275. package/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
  276. package/node_modules/yaml/dist/compose/compose-doc.js +45 -0
  277. package/node_modules/yaml/dist/compose/compose-node.d.ts +29 -0
  278. package/node_modules/yaml/dist/compose/compose-node.js +112 -0
  279. package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
  280. package/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
  281. package/node_modules/yaml/dist/compose/composer.d.ts +63 -0
  282. package/node_modules/yaml/dist/compose/composer.js +224 -0
  283. package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
  284. package/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
  285. package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
  286. package/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
  287. package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
  288. package/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
  289. package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
  290. package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
  291. package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
  292. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
  293. package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
  294. package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +227 -0
  295. package/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
  296. package/node_modules/yaml/dist/compose/resolve-props.js +148 -0
  297. package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
  298. package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
  299. package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
  300. package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
  301. package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
  302. package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
  303. package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
  304. package/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
  305. package/node_modules/yaml/dist/doc/Document.d.ts +141 -0
  306. package/node_modules/yaml/dist/doc/Document.js +337 -0
  307. package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
  308. package/node_modules/yaml/dist/doc/anchors.js +76 -0
  309. package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
  310. package/node_modules/yaml/dist/doc/applyReviver.js +57 -0
  311. package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
  312. package/node_modules/yaml/dist/doc/createNode.js +90 -0
  313. package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
  314. package/node_modules/yaml/dist/doc/directives.js +178 -0
  315. package/node_modules/yaml/dist/errors.d.ts +21 -0
  316. package/node_modules/yaml/dist/errors.js +62 -0
  317. package/node_modules/yaml/dist/index.d.ts +25 -0
  318. package/node_modules/yaml/dist/index.js +50 -0
  319. package/node_modules/yaml/dist/log.d.ts +3 -0
  320. package/node_modules/yaml/dist/log.js +19 -0
  321. package/node_modules/yaml/dist/nodes/Alias.d.ts +29 -0
  322. package/node_modules/yaml/dist/nodes/Alias.js +118 -0
  323. package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
  324. package/node_modules/yaml/dist/nodes/Collection.js +151 -0
  325. package/node_modules/yaml/dist/nodes/Node.d.ts +53 -0
  326. package/node_modules/yaml/dist/nodes/Node.js +40 -0
  327. package/node_modules/yaml/dist/nodes/Pair.d.ts +22 -0
  328. package/node_modules/yaml/dist/nodes/Pair.js +39 -0
  329. package/node_modules/yaml/dist/nodes/Scalar.d.ts +47 -0
  330. package/node_modules/yaml/dist/nodes/Scalar.js +27 -0
  331. package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
  332. package/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
  333. package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
  334. package/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
  335. package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
  336. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
  337. package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
  338. package/node_modules/yaml/dist/nodes/identity.js +53 -0
  339. package/node_modules/yaml/dist/nodes/toJS.d.ts +29 -0
  340. package/node_modules/yaml/dist/nodes/toJS.js +39 -0
  341. package/node_modules/yaml/dist/options.d.ts +350 -0
  342. package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
  343. package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
  344. package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
  345. package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
  346. package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
  347. package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
  348. package/node_modules/yaml/dist/parse/cst.d.ts +109 -0
  349. package/node_modules/yaml/dist/parse/cst.js +112 -0
  350. package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
  351. package/node_modules/yaml/dist/parse/lexer.js +723 -0
  352. package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
  353. package/node_modules/yaml/dist/parse/line-counter.js +41 -0
  354. package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
  355. package/node_modules/yaml/dist/parse/parser.js +980 -0
  356. package/node_modules/yaml/dist/public-api.d.ts +44 -0
  357. package/node_modules/yaml/dist/public-api.js +107 -0
  358. package/node_modules/yaml/dist/schema/Schema.d.ts +17 -0
  359. package/node_modules/yaml/dist/schema/Schema.js +39 -0
  360. package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
  361. package/node_modules/yaml/dist/schema/common/map.js +19 -0
  362. package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
  363. package/node_modules/yaml/dist/schema/common/null.js +17 -0
  364. package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
  365. package/node_modules/yaml/dist/schema/common/seq.js +19 -0
  366. package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
  367. package/node_modules/yaml/dist/schema/common/string.js +16 -0
  368. package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
  369. package/node_modules/yaml/dist/schema/core/bool.js +21 -0
  370. package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
  371. package/node_modules/yaml/dist/schema/core/float.js +47 -0
  372. package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
  373. package/node_modules/yaml/dist/schema/core/int.js +42 -0
  374. package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
  375. package/node_modules/yaml/dist/schema/core/schema.js +25 -0
  376. package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
  377. package/node_modules/yaml/dist/schema/json/schema.js +64 -0
  378. package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
  379. package/node_modules/yaml/dist/schema/tags.d.ts +48 -0
  380. package/node_modules/yaml/dist/schema/tags.js +99 -0
  381. package/node_modules/yaml/dist/schema/types.d.ts +92 -0
  382. package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
  383. package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
  384. package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
  385. package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
  386. package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
  387. package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
  388. package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
  389. package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
  390. package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
  391. package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +71 -0
  392. package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
  393. package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
  394. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  395. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
  396. package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
  397. package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
  398. package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
  399. package/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
  400. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  401. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
  402. package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
  403. package/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
  404. package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
  405. package/node_modules/yaml/dist/stringify/stringify.js +132 -0
  406. package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
  407. package/node_modules/yaml/dist/stringify/stringifyCollection.js +155 -0
  408. package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
  409. package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
  410. package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
  411. package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
  412. package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
  413. package/node_modules/yaml/dist/stringify/stringifyNumber.js +27 -0
  414. package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
  415. package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
  416. package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
  417. package/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
  418. package/node_modules/yaml/dist/test-events.d.ts +4 -0
  419. package/node_modules/yaml/dist/test-events.js +134 -0
  420. package/node_modules/yaml/dist/util.d.ts +16 -0
  421. package/node_modules/yaml/dist/util.js +28 -0
  422. package/node_modules/yaml/dist/visit.d.ts +102 -0
  423. package/node_modules/yaml/dist/visit.js +236 -0
  424. package/node_modules/yaml/package.json +97 -0
  425. package/node_modules/yaml/util.js +2 -0
  426. package/package.json +3 -3
  427. package/node_modules/@llblab/pi-actors/banner.jpg +0 -0
  428. package/node_modules/@llblab/pi-actors/dist/lib/inspector-actions.d.ts +0 -16
  429. package/node_modules/@llblab/pi-actors/dist/lib/inspector-actions.js +0 -57
  430. package/node_modules/@llblab/pi-actors/lib/inspector-actions.ts +0 -79
@@ -27,7 +27,18 @@ export interface SessionEvidenceToolCall {
27
27
  resultError?: boolean;
28
28
  }
29
29
 
30
+ // Non-JSON provenance data. The enumerable Symbol survives turn copies; it grants no source/lifecycle authority.
31
+ export const SESSION_TURN_IDENTITY = Symbol("session-turn-identity");
32
+ interface SessionTurnIdentity {
33
+ basis: "entry" | "record";
34
+ entryId?: string;
35
+ sessionId?: string;
36
+ role: "assistant" | "user";
37
+ ordinal?: number;
38
+ }
39
+
30
40
  export interface SessionEvidenceTurn {
41
+ [SESSION_TURN_IDENTITY]?: Readonly<SessionTurnIdentity>;
31
42
  assistantEntryId?: string;
32
43
  assistantText?: string;
33
44
  error?: string;
@@ -44,7 +55,20 @@ export interface SessionEvidenceTurn {
44
55
  userText?: string;
45
56
  }
46
57
 
58
+ export const SESSION_EVIDENCE_CHRONOLOGY = Symbol("session-evidence-chronology");
59
+ export interface SessionChronologyEntry {
60
+ ordinal: number;
61
+ timestamp: string;
62
+ identity: Readonly<SessionTurnIdentity>;
63
+ }
64
+ export type SessionChronologyReason = "source_unavailable" | "identity_unavailable" | "timestamp_unavailable" | "metadata_too_large";
65
+ export type SessionChronology = Readonly<{
66
+ basis: "recorded_branch_metadata";
67
+ entries: readonly Readonly<SessionChronologyEntry>[];
68
+ } & ({ state: "available" } | { state: "unavailable"; reason: SessionChronologyReason })>;
69
+
47
70
  export interface SessionEvidence {
71
+ [SESSION_EVIDENCE_CHRONOLOGY]?: SessionChronology;
48
72
  activeLeafId?: string;
49
73
  diagnostics: StateReadDiagnostic[];
50
74
  path: string;
@@ -289,7 +313,8 @@ function contentText(
289
313
  return boundedText(text, maxChars);
290
314
  }
291
315
 
292
- function activeBranch(
316
+ /** Physical last-leaf ancestry, not current model context or a claim about a live SessionManager leaf. */
317
+ export function selectLastRecordedSessionBranch(
293
318
  entries: SessionEntry[],
294
319
  path: string,
295
320
  diagnostics: StateReadDiagnostic[],
@@ -345,6 +370,28 @@ function toolCalls(
345
370
  }));
346
371
  }
347
372
 
373
+ function sessionChronology(turns: readonly SessionEvidenceTurn[], sourceAvailable: boolean): SessionChronology {
374
+ const basis = "recorded_branch_metadata" as const;
375
+ const unavailable = (reason: SessionChronologyReason): SessionChronology => Object.freeze({
376
+ state: "unavailable", basis, reason, entries: Object.freeze([]),
377
+ });
378
+ if (!sourceAvailable) return unavailable("source_unavailable");
379
+ const entries: Readonly<SessionChronologyEntry>[] = [];
380
+ let bytes = Buffer.byteLength(JSON.stringify({ state: "available", basis, entries: [] }));
381
+ for (const turn of turns) {
382
+ const identity = turn[SESSION_TURN_IDENTITY];
383
+ if (identity?.basis !== "entry") return unavailable("identity_unavailable");
384
+ const timestamp = turn.timestamp;
385
+ if (typeof timestamp !== "string" || timestamp.length !== 24 || !Number.isFinite(Date.parse(timestamp)) ||
386
+ new Date(timestamp).toISOString() !== timestamp || redactSessionEvidenceValue(timestamp) !== timestamp) return unavailable("timestamp_unavailable");
387
+ const entry = Object.freeze({ ordinal: turn.index, timestamp, identity });
388
+ bytes += Buffer.byteLength(JSON.stringify(entry)) + Number(entries.length > 0);
389
+ if (bytes > Limits.SESSION_EVIDENCE_MAX_BYTES) return unavailable("metadata_too_large");
390
+ entries.push(entry);
391
+ }
392
+ return Object.freeze({ state: "available", basis, entries: Object.freeze(entries) });
393
+ }
394
+
348
395
  export function readSessionEvidence(
349
396
  path: string,
350
397
  options: SessionEvidenceReadOptions = {},
@@ -368,9 +415,27 @@ export function readSessionEvidence(
368
415
  const read = readJsonlFileResilient<SessionEntry>(path, { maxBytes });
369
416
  const diagnostics = [...read.diagnostics];
370
417
  const header = read.records.find((entry) => entry.type === "session");
371
- const branch = activeBranch(read.records, path, diagnostics);
418
+ const branch = selectLastRecordedSessionBranch(read.records, path, diagnostics);
419
+ const ordinals = new Map<SessionEntry, number>(branch.map(entry => [entry, 0]));
420
+ const idCounts = new Map(branch.map(entry => [String(entry.id), 0]));
421
+ let sessionHeaders = 0;
422
+ for (const [index, entry] of read.records.entries()) {
423
+ if (entry.type === "session") sessionHeaders++;
424
+ if (ordinals.has(entry)) ordinals.set(entry, index + 1);
425
+ if (entry.type !== "session" && typeof entry.id === "string" && idCounts.has(entry.id)) {
426
+ idCounts.set(entry.id, idCounts.get(entry.id)! + 1);
427
+ }
428
+ }
429
+ const sessionId = sessionHeaders === 1 && typeof header?.id === "string" && header.id &&
430
+ redactSessionEvidenceValue(header.id, maxTextChars) === header.id ? header.id : undefined;
431
+ const identity = (entry: SessionEntry, role: "assistant" | "user"): Readonly<SessionTurnIdentity> => {
432
+ const entryId = typeof entry.id === "string" ? entry.id : "";
433
+ const basis = sessionId && entryId && idCounts.get(entryId) === 1 && diagnostics.length === 0 &&
434
+ redactSessionEvidenceValue(entryId, maxTextChars) === entryId ? "entry" : "record";
435
+ return Object.freeze({ basis, role, ...(basis === "entry" ? { sessionId, entryId } : { ordinal: ordinals.get(entry)! }) });
436
+ };
372
437
  const turns: SessionEvidenceTurn[] = [];
373
- let pendingUser: { id: string; text?: string } | undefined;
438
+ let pendingUser: { id: string; text?: string; identity: Readonly<SessionTurnIdentity> } | undefined;
374
439
  let currentTurn: SessionEvidenceTurn | undefined;
375
440
  for (const entry of branch) {
376
441
  if (entry.type !== "message") continue;
@@ -379,6 +444,7 @@ export function readSessionEvidence(
379
444
  if (role === "user") {
380
445
  pendingUser = {
381
446
  id: String(entry.id),
447
+ identity: identity(entry, "user"),
382
448
  text: contentText(message, "text", maxTextChars),
383
449
  };
384
450
  currentTurn = undefined;
@@ -386,6 +452,7 @@ export function readSessionEvidence(
386
452
  }
387
453
  if (role === "assistant") {
388
454
  currentTurn = {
455
+ [SESSION_TURN_IDENTITY]: identity(entry, "assistant"),
389
456
  ...(typeof entry.id === "string" ? { assistantEntryId: entry.id } : {}),
390
457
  ...(contentText(message, "text", maxTextChars)
391
458
  ? { assistantText: contentText(message, "text", maxTextChars) }
@@ -440,6 +507,7 @@ export function readSessionEvidence(
440
507
  toolCalls: [],
441
508
  unmatchedToolResults: 0,
442
509
  userEntryId: pendingUser.id,
510
+ [SESSION_TURN_IDENTITY]: pendingUser.identity,
443
511
  ...(pendingUser.text ? { userText: pendingUser.text } : {}),
444
512
  });
445
513
  }
@@ -448,7 +516,7 @@ export function readSessionEvidence(
448
516
  ...turn,
449
517
  index: firstVisibleIndex + index + 1,
450
518
  }));
451
- return {
519
+ const evidence: SessionEvidence = {
452
520
  ...(branch.at(-1)?.id ? { activeLeafId: String(branch.at(-1)?.id) } : {}),
453
521
  diagnostics,
454
522
  path,
@@ -457,4 +525,8 @@ export function readSessionEvidence(
457
525
  truncated: read.truncated === true || turns.length > visibleTurns.length,
458
526
  turns: visibleTurns,
459
527
  };
528
+ Object.defineProperty(evidence, SESSION_EVIDENCE_CHRONOLOGY, {
529
+ value: sessionChronology(turns, sessionId !== undefined && read.truncated !== true && diagnostics.length === 0),
530
+ });
531
+ return evidence;
460
532
  }
@@ -6,6 +6,7 @@
6
6
 
7
7
  import {
8
8
  closeSync,
9
+ constants,
9
10
  fstatSync,
10
11
  openSync,
11
12
  readFileSync,
@@ -41,12 +42,14 @@ function diagnosticMessage(error: unknown): string {
41
42
  return error instanceof Error ? error.message : String(error);
42
43
  }
43
44
 
44
- function readTextFileCapped(path: string, maxBytes: number | undefined): string {
45
- if (maxBytes === undefined) return readFileSync(path, "utf8");
45
+ function readTextFileCapped(path: string, maxBytes: number | undefined, strictUtf8 = false): string {
46
+ if (maxBytes === undefined) return strictUtf8 ? new TextDecoder("utf-8", { fatal: true }).decode(readFileSync(path)) : readFileSync(path, "utf8");
46
47
  const limit = Math.max(0, Math.floor(maxBytes));
47
- const fd = openSync(path, "r");
48
+ const fd = openSync(path, strictUtf8 ? constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0) : "r");
48
49
  try {
49
- const size = fstatSync(fd).size;
50
+ const opened = fstatSync(fd);
51
+ if (strictUtf8 && !opened.isFile()) throw new Error("bounded strict read requires a regular file");
52
+ const size = opened.size;
50
53
  if (size > limit) {
51
54
  throw Object.assign(
52
55
  new Error(`file exceeds bounded read limit (${size} > ${limit} bytes)`),
@@ -60,17 +63,23 @@ function readTextFileCapped(path: string, maxBytes: number | undefined): string
60
63
  if (bytesRead === 0) break;
61
64
  offset += bytesRead;
62
65
  }
63
- return content.subarray(0, offset).toString("utf8");
66
+ if (strictUtf8 && offset !== size) throw new Error("file ended before its bounded strict read completed");
67
+ const observed = content.subarray(0, offset);
68
+ return strictUtf8 ? new TextDecoder("utf-8", { fatal: true }).decode(observed) : observed.toString("utf8");
64
69
  } finally {
65
70
  closeSync(fd);
66
71
  }
67
72
  }
68
73
 
69
- export function readJsonFileResilient<T>(path: string, fallback: T): JsonReadResult<T> {
74
+ export function readJsonFileResilient<T>(
75
+ path: string,
76
+ fallback: T,
77
+ options: { maxBytes?: number; strictUtf8?: boolean } = {},
78
+ ): JsonReadResult<T> {
70
79
  try {
71
80
  return {
72
81
  diagnostics: [],
73
- value: JSON.parse(readFileSync(path, "utf8")) as T,
82
+ value: JSON.parse(readTextFileCapped(path, options.maxBytes, options.strictUtf8)) as T,
74
83
  };
75
84
  } catch (error) {
76
85
  if (isEnoent(error)) return { diagnostics: [], value: fallback };
@@ -1,14 +1,13 @@
1
1
  /**
2
2
  * Extension temp-directory helpers
3
3
  * Zones: temp directory, cleanup, runtime files
4
- * Owns pi-agent tmp directory preparation and stale-entry cleanup
4
+ * Owns ordinary pi-agent tmp directory preparation and stale-entry cleanup; Run retirement is separate.
5
5
  */
6
6
 
7
- import { mkdir, readdir, readFile, rm, stat } from "node:fs/promises";
7
+ import { mkdir, readdir, rm, stat } from "node:fs/promises";
8
8
  import { join } from "node:path";
9
9
 
10
10
  export const DEFAULT_TEMP_MAX_AGE_MS = 24 * 60 * 60 * 1000;
11
- export const DEFAULT_RUN_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
12
11
 
13
12
  export async function cleanupStaleTempEntries(
14
13
  tempDir: string,
@@ -38,62 +37,10 @@ export async function cleanupStaleTempEntries(
38
37
  return removed;
39
38
  }
40
39
 
41
- function isPidAlive(pid: number): boolean {
42
- try {
43
- process.kill(pid, 0);
44
- return true;
45
- } catch {
46
- return false;
47
- }
48
- }
49
-
50
- async function isRunEntryAlive(path: string): Promise<boolean> {
51
- try {
52
- const raw = await readFile(join(path, "run.json"), "utf8");
53
- const meta = JSON.parse(raw) as Record<string, unknown>;
54
- const pid = Number(meta.pid || 0);
55
- return pid > 0 && isPidAlive(pid);
56
- } catch {
57
- return false;
58
- }
59
- }
60
-
61
- export async function cleanupStaleRunEntries(
62
- runsDir: string,
63
- maxAgeMs = DEFAULT_RUN_MAX_AGE_MS,
64
- now = Date.now(),
65
- ): Promise<number> {
66
- let entries: Array<{ name: string; isDirectory(): boolean }>;
67
- let removed = 0;
68
- try {
69
- entries = await readdir(runsDir, { withFileTypes: true });
70
- } catch {
71
- return 0;
72
- }
73
- for (const entry of entries) {
74
- if (!entry.isDirectory()) continue;
75
- const path = join(runsDir, entry.name);
76
- try {
77
- const info = await stat(path);
78
- const timestamp = Math.min(info.birthtimeMs || info.mtimeMs, info.mtimeMs);
79
- if (now - timestamp <= maxAgeMs) continue;
80
- if (await isRunEntryAlive(path)) continue;
81
- await rm(path, { force: true, recursive: true });
82
- removed += 1;
83
- } catch {
84
- // Ignore temp cleanup races.
85
- }
86
- }
87
- return removed;
88
- }
89
-
90
40
  export async function prepareExtensionTempDir(
91
41
  tempDir: string,
92
42
  maxAgeMs = DEFAULT_TEMP_MAX_AGE_MS,
93
- runMaxAgeMs = DEFAULT_RUN_MAX_AGE_MS,
94
43
  ): Promise<number> {
95
44
  await mkdir(tempDir, { recursive: true });
96
- const removedTemp = await cleanupStaleTempEntries(tempDir, maxAgeMs);
97
- const removedRuns = await cleanupStaleRunEntries(join(tempDir, "runs"), runMaxAgeMs);
98
- return removedTemp + removedRuns;
45
+ return cleanupStaleTempEntries(tempDir, maxAgeMs);
99
46
  }
@@ -5,6 +5,7 @@
5
5
  */
6
6
 
7
7
  import * as AsyncRuns from "./async-runs.ts";
8
+ import * as RunIndex from "./runs-index.ts";
8
9
 
9
10
  export interface SessionContext {
10
11
  sessionManager?: { getSessionId?: () => string };
@@ -14,6 +15,18 @@ export function getContextSessionId(ctx: unknown): string | undefined {
14
15
  return (ctx as SessionContext | undefined)?.sessionManager?.getSessionId?.();
15
16
  }
16
17
 
18
+ /** Optional post-launch navigation never fails or rolls back work already admitted by the launch owner. */
19
+ export function readRunFileNavigationForContext(status: object, ctx: unknown): Readonly<RunIndex.RunDirectoryNavigation> {
20
+ try {
21
+ const sessionId = getContextSessionId(ctx);
22
+ const directory = Object.getOwnPropertyDescriptor(status, "state_dir");
23
+ const navigation = RunIndex.readRunDirectoryNavigation(typeof directory?.value === "string" ? directory.value : "", status, sessionId);
24
+ return getContextSessionId(ctx) === sessionId ? navigation : Object.freeze({ state: "unavailable", reason: "session_changed" });
25
+ } catch {
26
+ return Object.freeze({ state: "unavailable", reason: "navigation_unavailable" });
27
+ }
28
+ }
29
+
17
30
  export function requireContextSessionId(ctx: unknown, actor: string): string {
18
31
  const sessionId = getContextSessionId(ctx);
19
32
  if (!sessionId) {
@@ -18,6 +18,7 @@ import * as RecipesDiscovery from "./recipes-discovery.ts";
18
18
  import * as RecipesReferences from "./recipes-references.ts";
19
19
  import * as ReviewDiagnostics from "./review-diagnostics.ts";
20
20
  import * as RunsControls from "./runs-controls.ts";
21
+ import { readRunSessionNavigation, type RunNavigationPriority } from "./runs-index.ts";
21
22
  import * as RunControlDelivery from "./runs-control-delivery.ts";
22
23
  import * as RunsTrace from "./runs-trace.ts";
23
24
  import * as Runtime from "./runtime.ts";
@@ -37,6 +38,7 @@ export interface InspectToolDeps<TContext = unknown> {
37
38
  getToolStatus?: (name: string) => Record<string, unknown> | undefined;
38
39
  listRuns?: () => Array<Record<string, any>>;
39
40
  recipeRoot?: string;
41
+ runStateRoot?: string;
40
42
  registryStatus?: () => Runtime.RecipeRegistryStatus;
41
43
  }
42
44
 
@@ -53,23 +55,36 @@ function runtimeRuns(
53
55
  ctx: unknown,
54
56
  deps: InspectToolDeps,
55
57
  status: string | undefined,
58
+ includeNavigation = false,
56
59
  ): Record<string, unknown> {
57
60
  const session = ToolsAccess.requireContextSessionId(ctx, "runtime Run inventory");
58
61
  const listed = deps.listRuns
59
62
  ? deps.listRuns()
60
63
  : AsyncRuns.listRuns(undefined, status);
64
+ const observedFailures: RunNavigationPriority["failed"][number][] = [];
61
65
  const runs = listed
62
66
  .map((run) => {
63
67
  try {
64
- return deps.getRunStatus
68
+ const observed = deps.getRunStatus
65
69
  ? deps.getRunStatus(String(run.state_dir ?? run.run))
66
70
  : AsyncRuns.getRunStatus(String(run.state_dir ?? run.run));
71
+ if (includeNavigation && observed.status === "failed" && typeof observed.run === "string" && typeof observed.run_instance_id === "string" &&
72
+ typeof observed.state_dir === "string" && observed.ownerId === session) {
73
+ observedFailures.push({ run: observed.run, run_instance_id: observed.run_instance_id, state_dir: observed.state_dir, ownerId: session });
74
+ }
75
+ return observed;
67
76
  } catch {
68
77
  return run;
69
78
  }
70
79
  })
71
80
  .filter((run) => run.ownerId === session);
72
- return { owner_session: session, runs };
81
+ const navigation = includeNavigation ? readRunSessionNavigation(deps.runStateRoot ?? Paths.getRunStateRoot(), session, {
82
+ root_order: status === "failed" ? "failed_subtrees_first" : "latest_registration",
83
+ failed: observedFailures,
84
+ }) : undefined;
85
+ const current = ToolsAccess.requireContextSessionId(ctx, "runtime Run inventory");
86
+ if (current !== session) throw ToolsAccess.sessionMismatchError({ currentSession: current, expectedSession: session, target: "runtime" });
87
+ return { owner_session: session, runs, ...(navigation ? { navigation } : {}) };
73
88
  }
74
89
 
75
90
  function runtimeTriage(
@@ -171,13 +186,44 @@ function runtimeTriage(
171
186
  }
172
187
 
173
188
  function compactRuntime(view: string, details: Record<string, unknown>): string {
174
- if (view === "runs") {
175
- return `\nruntime runs=${(details.runs as unknown[] | undefined)?.length ?? 0}`;
176
- }
177
- if (view === "triage") {
178
- return `\nruntime failed=${(details.failed_runs as unknown[] | undefined)?.length ?? 0} pending_controls=${Number(details.pending_control_count ?? 0)} stale_controls=${Number(details.stale_control_count ?? 0)} backpressured=${Number(details.backpressured_run_count ?? 0)} incomplete_trace=${Number(details.trace_diagnostic_count ?? 0)} attention=${(details.attention_events as unknown[] | undefined)?.length ?? 0}`;
179
- }
180
- return `\nruntime version=${String(details.version)} state_schema=${String(details.state_schema)} automatic_review=${String(details.automatic_review)}`;
189
+ const fields = view === "runs" ? { runs: (details.runs as unknown[] | undefined)?.length ?? 0 }
190
+ : view === "triage" ? {
191
+ failed: (details.failed_runs as unknown[] | undefined)?.length ?? 0,
192
+ pending_controls: Number(details.pending_control_count ?? 0), stale_controls: Number(details.stale_control_count ?? 0),
193
+ backpressured: Number(details.backpressured_run_count ?? 0), incomplete_trace: Number(details.trace_diagnostic_count ?? 0),
194
+ attention: (details.attention_events as unknown[] | undefined)?.length ?? 0,
195
+ } : { version: String(details.version), state_schema: String(details.state_schema), automatic_review: String(details.automatic_review) };
196
+ return "\n" + [ToolsResponse.formatMarkdownField("runtime", view),
197
+ ...Object.entries(fields).map(([key, value]) => ToolsResponse.formatMarkdownField(key, String(value)))].join("\n");
198
+ }
199
+
200
+ // Projects local refusals only; does not intercept other throws or change existing catches.
201
+ function formatInspectFailure(
202
+ fields: readonly (readonly [key: string, value: string | readonly string[], omittable?: true])[],
203
+ next?: readonly [target: string, view: string],
204
+ ): string {
205
+ // The unchanged public adapter adds exactly one leading LF to these Error messages.
206
+ const budget = Limits.RUN_DELIVERY_MODEL_MAX_BYTES - 1;
207
+ const omitted = (key: string) => `- ${key}:\n - state: omitted\n - reason: response_too_large\n - shown: 0\n - omitted: 1\n - total: 1`;
208
+ const field = ([key, value]: (typeof fields)[number]) => typeof value === "string"
209
+ ? ToolsResponse.formatMarkdownField(key, value)
210
+ : `- ${key}:\n${value.map(item => ` - ${item}`).join("\n")}`;
211
+ // Unmarked fields are bounded compiler literals/lists. Short values seed full so admission only grows.
212
+ const formatted = fields.map(field);
213
+ const projected = fields.map((item, index) => {
214
+ const full = formatted[index]!, fallback = omitted(item[0]);
215
+ return item[2] && Buffer.byteLength(full, "utf8") > Buffer.byteLength(fallback, "utf8") ? fallback : full;
216
+ });
217
+ let action = next ? ToolsResponse.formatInspectNextAction(next[0], next[1]) : "";
218
+ const text = () => [...projected, ...(action ? [action] : [])].join("\n");
219
+ if (next && Buffer.byteLength(text(), "utf8") > budget) action = omitted("next_action");
220
+ fields.forEach((item, index) => {
221
+ if (!item[2]) return;
222
+ const fallback = projected[index]!;
223
+ projected[index] = formatted[index]!;
224
+ if (Buffer.byteLength(text(), "utf8") > budget) projected[index] = fallback;
225
+ });
226
+ return text();
181
227
  }
182
228
 
183
229
  function inspectRuntime(
@@ -192,10 +238,13 @@ function inspectRuntime(
192
238
  ctx,
193
239
  deps,
194
240
  typeof input.status === "string" ? input.status : undefined,
241
+ input.verbose === true,
195
242
  );
196
243
  }
197
244
  if (view === "triage") return runtimeTriage(ctx, deps);
198
- throw new Error("inspect runtime supports view=status, view=runs, or view=triage.");
245
+ throw new Error(formatInspectFailure([
246
+ ["target_kind", "runtime"], ["result", "unsupported view"], ["supported_views", ["status", "runs", "triage"]],
247
+ ]));
199
248
  }
200
249
 
201
250
  function portableSkillRecipePath(
@@ -350,9 +399,10 @@ function inspectRecipes(
350
399
  view !== "imports" &&
351
400
  view !== "reviews"
352
401
  ) {
353
- throw new Error(
354
- "inspect recipes supports view=status, view=summary, view=doctor, view=imports, or view=reviews.",
355
- );
402
+ throw new Error(formatInspectFailure([
403
+ ["target_kind", "recipes"], ["result", "unsupported view"],
404
+ ["supported_views", ["status", "summary", "doctor", "imports", "reviews"]],
405
+ ]));
356
406
  }
357
407
  const recipeRoot = deps.recipeRoot ?? Paths.getRecipeRoot();
358
408
  if (view === "reviews") {
@@ -379,7 +429,7 @@ function inspectRecipes(
379
429
  const identity =
380
430
  typeof input.identity === "string" ? input.identity.trim() : "";
381
431
  if (identity && view !== "doctor") {
382
- throw new Error("inspect recipes identity is supported only with view=doctor.");
432
+ throw new Error(formatInspectFailure([["target_kind", "recipes"], ["result", "identity requires view=doctor"]]));
383
433
  }
384
434
  if (view === "doctor" && identity) {
385
435
  return inspectRecipeIdentity(
@@ -463,7 +513,9 @@ function inspectRun(
463
513
  deps: InspectToolDeps,
464
514
  ): Record<string, unknown> {
465
515
  if (view !== "recipe" && view !== "trace" && view !== "control") {
466
- throw new Error("inspect run:<id> supports view=recipe, view=trace, or view=control.");
516
+ throw new Error(formatInspectFailure([
517
+ ["target_kind", "run"], ["result", "unsupported view"], ["supported_views", ["recipe", "trace", "control"]],
518
+ ]));
467
519
  }
468
520
  const status = deps.getRunStatus
469
521
  ? ToolsAccess.assertRunStatusAccessibleToContext(
@@ -487,7 +539,10 @@ function inspectRun(
487
539
  source !== "artifact" &&
488
540
  source !== "runtime"
489
541
  ) {
490
- throw new Error(`unsupported Trace source: ${source}`);
542
+ throw new Error(formatInspectFailure([
543
+ ["target_kind", "run"], ["source", source, true], ["result", "unsupported Trace source"],
544
+ ["supported_sources", ["all", "lifecycle", "control", "process", "agent", "artifact", "runtime"]],
545
+ ]));
491
546
  }
492
547
  return {
493
548
  run, source,
@@ -545,22 +600,26 @@ function inspectTool(
545
600
  deps: InspectToolDeps,
546
601
  ): Record<string, unknown> {
547
602
  if (!name || !/^[A-Za-z0-9_.-]+$/.test(name)) {
548
- throw new Error(`invalid tool target: tool:${name}`);
603
+ throw new Error(formatInspectFailure([["target", `tool:${name}`, true], ["result", "invalid tool target"]]));
549
604
  }
550
605
  if (view !== "status" && view !== "schema") {
551
- throw new Error("inspect tool:<name> supports view=status or view=schema.");
606
+ throw new Error(formatInspectFailure([
607
+ ["target_kind", "tool"], ["result", "unsupported view"], ["supported_views", ["status", "schema"]],
608
+ ]));
552
609
  }
553
610
  const tool = deps.getTool?.(name);
554
611
  const status = deps.getToolStatus?.(name);
555
612
  if (!tool && !status) {
556
- throw new Error(
557
- `Registered tool not found: ${name}. Next: inspect target=recipes view=doctor; do not substitute spawn for tool invocation.`,
558
- );
613
+ throw new Error(formatInspectFailure([
614
+ ["tool", name, true], ["result", "registered tool not found"], ["safety", "Do not substitute spawn for tool invocation."],
615
+ ], ["recipes", "doctor"]));
559
616
  }
560
617
  if (view === "schema" && !tool) {
561
- throw new Error(
562
- `Tool "${name}" is registered but its callable schema is unavailable; callable_now=${String(status?.callable_now ?? false)}, activation_boundary=${String(status?.activation_boundary ?? "host_registration")}. Next: inspect target=tool:${name} view=status.`,
563
- );
618
+ throw new Error(formatInspectFailure([
619
+ ["tool", name, true], ["result", "registered; callable schema unavailable"],
620
+ ["callable_now", String(status?.callable_now ?? false), true],
621
+ ["activation_boundary", String(status?.activation_boundary ?? "host_registration"), true],
622
+ ], [`tool:${name}`, "status"]));
564
623
  }
565
624
  return {
566
625
  name,
@@ -578,38 +637,37 @@ function inspectTool(
578
637
  function compactResult(target: string, view: string, details: Record<string, unknown>): string {
579
638
  if (target === "runtime") return compactRuntime(view, details);
580
639
  if (target === "recipes" && typeof details.identity === "string") {
581
- const lines = [
582
- `recipes doctor identity=${details.identity} skill_active=${String(details.skill_active)} resolvable=${String(details.resolvable)} catalog_partial=${String(details.catalog_partial)} component_status=${String(details.component_status)}`,
583
- ...(details.source_location
584
- ? [`source=${String(details.source_location)}`]
585
- : []),
586
- `resolution_generation=${String(details.resolution_generation)}`,
587
- ...(details.rejected_reason
588
- ? [`rejected_reason=${String(details.rejected_reason)}`]
589
- : []),
590
- ...((details.next_actions as unknown[] | undefined) ?? []).map(
591
- (action) => `next=${String(action)}`,
592
- ),
593
- ];
594
- return `\n${lines.join("\n")}`;
640
+ const fields = [ToolsResponse.formatMarkdownField("recipes", "doctor"),
641
+ ...["identity", "skill_active", "resolvable", "catalog_partial", "component_status"]
642
+ .map(key => ToolsResponse.formatMarkdownField(key, String(details[key]))),
643
+ ...(details.source_location ? [ToolsResponse.formatMarkdownField("source_location", ToolsResponse.formatLiteralBlock(String(details.source_location)))] : []),
644
+ ToolsResponse.formatMarkdownField("resolution_generation", String(details.resolution_generation)),
645
+ ...(details.rejected_reason ? [ToolsResponse.formatMarkdownField("rejected_reason", String(details.rejected_reason))] : [])];
646
+ const actions = details.next_actions as unknown[] | undefined;
647
+ if (actions?.length) fields.push(ToolsResponse.formatInspectionHint(String(actions[0])));
648
+ return "\n" + fields.join("\n");
595
649
  }
596
650
  if (target === "recipes") return ToolsResponse.compactRecipeRegistry(details);
597
651
  if (target.startsWith("tool:") && view === "status") {
598
- const required = Array.isArray(details.required_args)
599
- ? details.required_args.map(String).join(",") || "none"
600
- : "unknown";
601
- const optional = Array.isArray(details.optional_args)
602
- ? details.optional_args.map(String).join(",") || "none"
603
- : "unknown";
652
+ const argumentsField = (key: string, value: unknown): string => Array.isArray(value) && value.length
653
+ ? "- " + key + ":\n" + value.map(item => " - " + String(item).replace(/\r\n|\r|\n/gu, match => match + " ")).join("\n")
654
+ : ToolsResponse.formatMarkdownField(key, Array.isArray(value) ? "none" : "unknown");
604
655
  const next = Array.isArray(details.next_actions) && details.next_actions.length > 0
605
656
  ? String(details.next_actions[0])
606
657
  : details.callable_now === true
607
658
  ? `call tool ${target.slice(5)}`
608
659
  : `register_tool name=${target.slice(5)} update=true`;
609
- return `\ntool=${target.slice(5)} source=${String(details.source ?? "unknown")} callable_now=${String(details.callable_now ?? false)} activation_boundary=${String(details.activation_boundary ?? "unknown")} required=${required} optional=${optional} launch_kind=${String(details.launch_kind ?? "none")} spawn_calls=${Number(details.spawn_calls ?? 0)} tool_calls=${Number(details.tool_calls ?? 0)} next=${next}`;
660
+ return "\n" + [ToolsResponse.formatMarkdownField("tool", target.slice(5)),
661
+ ToolsResponse.formatMarkdownField("source", String(details.source ?? "unknown")),
662
+ ToolsResponse.formatMarkdownField("callable_now", String(details.callable_now ?? false)),
663
+ ToolsResponse.formatMarkdownField("activation_boundary", String(details.activation_boundary ?? "unknown")),
664
+ argumentsField("required_args", details.required_args), argumentsField("optional_args", details.optional_args),
665
+ ToolsResponse.formatMarkdownField("launch_kind", String(details.launch_kind ?? "none")),
666
+ ToolsResponse.formatMarkdownField("spawn_calls", String(Number(details.spawn_calls ?? 0))),
667
+ ToolsResponse.formatMarkdownField("tool_calls", String(Number(details.tool_calls ?? 0))), ToolsResponse.formatInspectionHint(next)].join("\n");
610
668
  }
611
- if (target.startsWith("tool:")) return `\ntool=${target.slice(5)} view=${view}`;
612
- return `\nrun=${target.slice(4)} view=${view}`;
669
+ if (target.startsWith("tool:")) return "\n" + ToolsResponse.formatMarkdownField("tool", target.slice(5)) + "\n" + ToolsResponse.formatMarkdownField("view", view);
670
+ return "\n" + ToolsResponse.formatMarkdownField("run", target.slice(4)) + "\n" + ToolsResponse.formatMarkdownField("view", view);
613
671
  }
614
672
 
615
673
  export function createInspectToolDefinition<TContext = unknown>(
@@ -629,7 +687,7 @@ export function createInspectToolDefinition<TContext = unknown>(
629
687
  source: Schema.stringSchema(
630
688
  "Optional Trace source: all, lifecycle, control, process, agent, artifact, or runtime.",
631
689
  ),
632
- status: Schema.stringSchema("Optional runtime Run status filter."),
690
+ status: Schema.stringSchema("Optional runtime Run status filter. With verbose runs, failed prioritizes observed failed subtrees without filtering the navigation map."),
633
691
  target: Schema.stringSchema("Target: run:<id>, runtime, recipes, or tool:<name>."),
634
692
  verbose: Schema.booleanSchema("Return full JSON instead of compact text."),
635
693
  view: Schema.stringSchema(
@@ -659,9 +717,10 @@ export function createInspectToolDefinition<TContext = unknown>(
659
717
  else if (target.startsWith("tool:")) {
660
718
  details = inspectTool(target.slice(5), view, deps);
661
719
  } else {
662
- throw new Error(
663
- `unsupported inspect target: ${target}; use run:<id>, runtime, recipes, or tool:<name>`,
664
- );
720
+ throw new Error(formatInspectFailure([
721
+ ["target", target, true], ["result", "unsupported inspect target"],
722
+ ["supported_targets", ["run:<id>", "runtime", "recipes", "tool:<name>"]],
723
+ ]));
665
724
  }
666
725
  }
667
726
  return {