@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
@@ -4,9 +4,33 @@
4
4
  * Owns portable command-template parsing, expansion, risk checks, retries, timeouts, and direct execution.
5
5
  */
6
6
  import { spawn, spawnSync } from "node:child_process";
7
- import { accessSync, appendFileSync, constants, mkdirSync, mkdtempSync, statSync, writeFileSync } from "node:fs";
7
+ import { createHash } from "node:crypto";
8
+ import { accessSync, appendFileSync, constants, lstatSync, mkdirSync, mkdtempSync, statSync, writeFileSync } from "node:fs";
8
9
  import { homedir, tmpdir } from "node:os";
9
10
  import { basename, delimiter, extname, isAbsolute, join, resolve as resolvePath } from "node:path";
11
+ let pendingSpawnAdmission;
12
+ const freshManagedAttempts = new WeakMap();
13
+ /** Available only before this synchronous admission invokes its factory; never retroactively adopt a born process. */
14
+ export function readPendingCommandSpawnAdmission() {
15
+ return pendingSpawnAdmission;
16
+ }
17
+ /** Kernel-only launch observation capability; copies and references retained past the callback are not authority. */
18
+ export function requireFreshManagedCommandAttempt(context, admission) {
19
+ const actual = freshManagedAttempts.get(context);
20
+ if (!actual || (admission !== undefined && actual.admission !== admission) || context.process !== actual.process || actual.process.pid !== actual.pid) {
21
+ throw new Error("Native process observation requires a fresh managed attempt from this runtime.");
22
+ }
23
+ return context;
24
+ }
25
+ const nativeCloseReceipts = new WeakMap();
26
+ /** Exact retained process close during its synchronous receipt callback, never a serialized terminal claim. */
27
+ export function requireNativeCommandAttemptClose(receipt, admission, child) {
28
+ const actual = nativeCloseReceipts.get(receipt);
29
+ if (!actual || actual.admission !== admission || actual.process !== child || child.pid !== actual.close.pid) {
30
+ throw new Error("Native settlement requires its exact runtime-local process-close receipt.");
31
+ }
32
+ return actual.close;
33
+ }
10
34
  const DEFAULT_COMMAND_CAPTURE_LIMIT_BYTES = 1024 * 1024;
11
35
  const COMMAND_TEMPLATE_RISK_LABEL_ORDER = [
12
36
  "risk.shell",
@@ -634,7 +658,7 @@ export async function execCommandTemplate(command, args, options = {}) {
634
658
  captureDir: join(options.captureDir, `attempt-${String(attempt).padStart(3, "0")}`),
635
659
  }
636
660
  : options;
637
- const result = await execCommandTemplateOnce(command, args, attemptOptions);
661
+ const result = await execCommandTemplateOnce(command, args, attemptOptions, attempt);
638
662
  if (result.code === 0)
639
663
  return result;
640
664
  lastResult = result;
@@ -649,8 +673,9 @@ function trimCaptureTail(value, limit) {
649
673
  start += 1;
650
674
  return value.subarray(start);
651
675
  }
652
- function createBoundedCommandCapture(stream, limit, getCaptureDir, persistCompleteStream) {
676
+ function createBoundedCommandCapture(stream, limit, getCaptureDir, persistCompleteStream, onFailure) {
653
677
  let bytes = 0;
678
+ const digest = stream === "stdout" && persistCompleteStream ? createHash("sha256") : undefined;
654
679
  let content = Buffer.alloc(0);
655
680
  let file = persistCompleteStream
656
681
  ? join(getCaptureDir(), `${stream}.log`)
@@ -658,163 +683,272 @@ function createBoundedCommandCapture(stream, limit, getCaptureDir, persistComple
658
683
  if (file)
659
684
  writeFileSync(file, Buffer.alloc(0));
660
685
  let truncated = false;
686
+ let incomplete = false;
661
687
  return {
662
688
  append(value) {
663
689
  const chunk = Buffer.isBuffer(value) ? value : Buffer.from(value);
664
690
  bytes += chunk.length;
691
+ digest?.update(chunk);
665
692
  if (bytes > limit)
666
693
  truncated = true;
667
- if (!file && bytes <= limit) {
668
- content = Buffer.concat([content, chunk]);
694
+ const previous = content;
695
+ content = trimCaptureTail(Buffer.concat([content, chunk]), limit);
696
+ if (!file && bytes <= limit)
697
+ return;
698
+ if (incomplete)
669
699
  return;
700
+ try {
701
+ if (!file) {
702
+ file = join(getCaptureDir(), `${stream}.log`);
703
+ writeFileSync(file, previous);
704
+ }
705
+ appendFileSync(file, chunk);
670
706
  }
671
- if (!file) {
672
- file = join(getCaptureDir(), `${stream}.log`);
673
- writeFileSync(file, content);
707
+ catch (error) {
708
+ incomplete = true;
709
+ onFailure(error);
674
710
  }
675
- appendFileSync(file, chunk);
676
- content = trimCaptureTail(Buffer.concat([content, chunk]), limit);
677
711
  },
678
712
  result() {
679
- if (!file && persistCompleteStream) {
680
- file = join(getCaptureDir(), `${stream}.log`);
681
- writeFileSync(file, content);
713
+ let retainedFile = file;
714
+ let fileBytes;
715
+ if (incomplete && file) {
716
+ try {
717
+ const stat = lstatSync(file);
718
+ if (stat.isFile())
719
+ fileBytes = stat.size;
720
+ else
721
+ retainedFile = undefined;
722
+ }
723
+ catch {
724
+ retainedFile = undefined;
725
+ }
682
726
  }
683
727
  return {
684
728
  bytes,
685
729
  content: content.toString("utf8"),
686
- ...(file ? { file } : {}),
730
+ ...(retainedFile ? { file: retainedFile } : {}),
731
+ ...(digest && !incomplete && retainedFile ? { sha256: digest.digest("hex") } : {}),
732
+ ...(incomplete ? { incomplete: true, ...(fileBytes === undefined ? {} : { fileBytes }) } : {}),
687
733
  truncated,
688
734
  };
689
735
  },
690
736
  };
691
737
  }
692
- function execCommandTemplateOnce(command, args, options = {}) {
693
- return new Promise((resolve) => {
694
- const proc = spawn(command, args, {
695
- cwd: options.cwd,
696
- shell: false,
697
- stdio: [options.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"],
698
- });
699
- const captureLimit = Math.max(1, options.captureLimitBytes ?? DEFAULT_COMMAND_CAPTURE_LIMIT_BYTES);
700
- let captureDir;
701
- const getCaptureDir = () => {
702
- if (captureDir)
738
+ function execCommandTemplateOnce(command, args, options, attempt) {
739
+ return new Promise((resolve, reject) => {
740
+ let failure;
741
+ let managed;
742
+ let invoked = false;
743
+ let admissionOpen = true;
744
+ const spawnAdmission = Object.freeze({ attempt });
745
+ const rememberFailure = (error) => { failure ??= { error }; };
746
+ const start = () => {
747
+ if (!admissionOpen)
748
+ throw new Error("Native spawn admission window is closed.");
749
+ if (invoked)
750
+ throw new Error("Native spawn factory may be invoked only once per attempt.");
751
+ invoked = true;
752
+ pendingSpawnAdmission = undefined;
753
+ const captureLimit = Math.max(1, options.captureLimitBytes ?? DEFAULT_COMMAND_CAPTURE_LIMIT_BYTES);
754
+ let captureDir;
755
+ const getCaptureDir = () => {
756
+ if (captureDir)
757
+ return captureDir;
758
+ captureDir = options.captureDir
759
+ ? resolvePath(options.captureDir)
760
+ : mkdtempSync(join(tmpdir(), "pi-actors-command-"));
761
+ mkdirSync(captureDir, { recursive: true });
703
762
  return captureDir;
704
- captureDir = options.captureDir
705
- ? resolvePath(options.captureDir)
706
- : mkdtempSync(join(tmpdir(), "pi-actors-command-"));
707
- mkdirSync(captureDir, { recursive: true });
708
- return captureDir;
709
- };
710
- const persistCompleteStreams = options.captureDir !== undefined;
711
- const stdoutCapture = createBoundedCommandCapture("stdout", captureLimit, getCaptureDir, persistCompleteStreams);
712
- const stderrCapture = createBoundedCommandCapture("stderr", captureLimit, getCaptureDir, persistCompleteStreams);
713
- let killed = false;
714
- let settled = false;
715
- let timeoutId;
716
- let killTimeoutId;
717
- const signalProcessTree = (signal) => {
718
- if (proc.pid === undefined)
719
- return;
720
- if (process.platform === "win32") {
721
- spawnSync("taskkill", [
722
- "/PID",
723
- String(proc.pid),
724
- "/T",
725
- ...(signal === "SIGKILL" ? ["/F"] : []),
726
- ]);
727
- return;
728
- }
729
- const snapshot = spawnSync("ps", ["-eo", "pid=,ppid="], { encoding: "utf8" });
730
- const children = new Map();
731
- for (const line of snapshot.stdout?.split(/\r?\n/u) ?? []) {
732
- const [pidText, parentText] = line.trim().split(/\s+/u);
733
- const pid = Number(pidText);
734
- const parent = Number(parentText);
735
- if (!Number.isSafeInteger(pid) || !Number.isSafeInteger(parent))
736
- continue;
737
- const siblings = children.get(parent) ?? [];
738
- siblings.push(pid);
739
- children.set(parent, siblings);
740
- }
741
- const descendants = [];
742
- const collect = (parent) => {
743
- for (const child of children.get(parent) ?? []) {
744
- collect(child);
745
- descendants.push(child);
763
+ };
764
+ const persistCompleteStreams = options.captureDir !== undefined;
765
+ const stdoutCapture = createBoundedCommandCapture("stdout", captureLimit, getCaptureDir, persistCompleteStreams, rememberFailure);
766
+ const stderrCapture = createBoundedCommandCapture("stderr", captureLimit, getCaptureDir, persistCompleteStreams, rememberFailure);
767
+ let killed = false;
768
+ let settled = false;
769
+ let timeoutId;
770
+ let killTimeoutId;
771
+ const signalProcessTree = (signal) => {
772
+ if (proc.pid === undefined)
773
+ return;
774
+ if (process.platform === "win32") {
775
+ spawnSync("taskkill", [
776
+ "/PID",
777
+ String(proc.pid),
778
+ "/T",
779
+ ...(signal === "SIGKILL" ? ["/F"] : []),
780
+ ]);
781
+ return;
782
+ }
783
+ const snapshot = spawnSync("ps", ["-eo", "pid=,ppid="], { encoding: "utf8" });
784
+ const children = new Map();
785
+ for (const line of snapshot.stdout?.split(/\r?\n/u) ?? []) {
786
+ const [pidText, parentText] = line.trim().split(/\s+/u);
787
+ const pid = Number(pidText);
788
+ const parent = Number(parentText);
789
+ if (!Number.isSafeInteger(pid) || !Number.isSafeInteger(parent))
790
+ continue;
791
+ const siblings = children.get(parent) ?? [];
792
+ siblings.push(pid);
793
+ children.set(parent, siblings);
746
794
  }
795
+ const descendants = [];
796
+ const collect = (parent) => {
797
+ for (const child of children.get(parent) ?? []) {
798
+ collect(child);
799
+ descendants.push(child);
800
+ }
801
+ };
802
+ collect(proc.pid);
803
+ for (const pid of [...descendants, proc.pid]) {
804
+ try {
805
+ process.kill(pid, signal);
806
+ }
807
+ catch (error) {
808
+ if (error.code !== "ESRCH")
809
+ throw error;
810
+ }
811
+ }
812
+ };
813
+ const killProcess = () => {
814
+ if (killed)
815
+ return;
816
+ killed = true;
817
+ signalProcessTree("SIGTERM");
818
+ killTimeoutId = setTimeout(() => {
819
+ if (!settled)
820
+ signalProcessTree("SIGKILL");
821
+ }, options.killGrace ?? 5000);
747
822
  };
748
- collect(proc.pid);
749
- for (const pid of [...descendants, proc.pid]) {
823
+ const settle = (code, nativeExitCode, nativeSignal) => {
824
+ if (settled)
825
+ return;
826
+ settled = true;
827
+ if (timeoutId)
828
+ clearTimeout(timeoutId);
829
+ if (killTimeoutId)
830
+ clearTimeout(killTimeoutId);
831
+ if (options.signal)
832
+ options.signal.removeEventListener("abort", killProcess);
833
+ const stdout = stdoutCapture.result();
834
+ const stderr = stderrCapture.result();
835
+ const result = {
836
+ stdout: stdout.content,
837
+ stderr: stderr.content,
838
+ code,
839
+ killed,
840
+ stdoutBytes: stdout.bytes,
841
+ stderrBytes: stderr.bytes,
842
+ ...(stdout.file ? { stdoutFile: stdout.file } : {}),
843
+ ...(stderr.file ? { stderrFile: stderr.file } : {}),
844
+ ...(stdout.truncated ? { stdoutTruncated: true } : {}),
845
+ ...(stderr.truncated ? { stderrTruncated: true } : {}),
846
+ ...(stdout.incomplete ? { stdoutCaptureIncomplete: true, ...(stdout.fileBytes === undefined ? {} : { stdoutFileBytes: stdout.fileBytes }) } : {}),
847
+ ...(stderr.incomplete ? { stderrCaptureIncomplete: true, ...(stderr.fileBytes === undefined ? {} : { stderrFileBytes: stderr.fileBytes }) } : {}),
848
+ };
750
849
  try {
751
- process.kill(pid, signal);
850
+ if (options.onAttemptComplete) {
851
+ const receipt = Object.freeze({
852
+ attempt, result: Object.freeze({ ...result }),
853
+ ...(stdout.sha256 ? { stdoutSha256: stdout.sha256 } : {}),
854
+ ...(nativeExitCode !== undefined ? { nativeExitCode } : {}),
855
+ ...(nativeSignal !== undefined ? { nativeSignal } : {}),
856
+ });
857
+ const exitObserved = (Number.isSafeInteger(nativeExitCode) && nativeSignal === null) ||
858
+ (nativeExitCode === null && typeof nativeSignal === "string" && /^SIG[A-Z0-9]+$/.exec(nativeSignal)?.[0] === nativeSignal);
859
+ if (exitObserved && Number.isSafeInteger(proc.pid) && Number(proc.pid) > 0 &&
860
+ proc.exitCode === nativeExitCode && proc.signalCode === nativeSignal) {
861
+ nativeCloseReceipts.set(receipt, {
862
+ admission: spawnAdmission, process: proc,
863
+ close: Object.freeze({ pid: proc.pid, nativeExitCode: nativeExitCode, nativeSignal: nativeSignal }),
864
+ });
865
+ }
866
+ try {
867
+ options.onAttemptComplete(receipt);
868
+ }
869
+ finally {
870
+ nativeCloseReceipts.delete(receipt);
871
+ }
872
+ }
752
873
  }
753
874
  catch (error) {
754
- if (error.code !== "ESRCH")
755
- throw error;
875
+ rememberFailure(error);
756
876
  }
757
- }
758
- };
759
- const killProcess = () => {
760
- if (killed)
761
- return;
762
- killed = true;
763
- signalProcessTree("SIGTERM");
764
- killTimeoutId = setTimeout(() => {
765
- if (!settled)
766
- signalProcessTree("SIGKILL");
767
- }, options.killGrace ?? 5000);
768
- };
769
- const settle = (code) => {
770
- if (settled)
771
- return;
772
- settled = true;
773
- if (timeoutId)
774
- clearTimeout(timeoutId);
775
- if (killTimeoutId)
776
- clearTimeout(killTimeoutId);
777
- if (options.signal)
778
- options.signal.removeEventListener("abort", killProcess);
779
- const stdout = stdoutCapture.result();
780
- const stderr = stderrCapture.result();
781
- resolve({
782
- stdout: stdout.content,
783
- stderr: stderr.content,
784
- code,
785
- killed,
786
- stdoutBytes: stdout.bytes,
787
- stderrBytes: stderr.bytes,
788
- ...(stdout.file ? { stdoutFile: stdout.file } : {}),
789
- ...(stderr.file ? { stderrFile: stderr.file } : {}),
790
- ...(stdout.truncated ? { stdoutTruncated: true } : {}),
791
- ...(stderr.truncated ? { stderrTruncated: true } : {}),
877
+ if (failure)
878
+ reject(failure.error);
879
+ else
880
+ resolve(result);
881
+ };
882
+ const proc = spawn(command, args, {
883
+ cwd: options.cwd,
884
+ shell: false,
885
+ stdio: [options.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"],
886
+ });
887
+ proc.stdout?.on("data", (data) => {
888
+ stdoutCapture.append(data);
889
+ });
890
+ proc.stderr?.on("data", (data) => {
891
+ stderrCapture.append(data);
792
892
  });
893
+ proc.stdin?.on("error", () => { });
894
+ proc.on("error", (error) => {
895
+ const liveHandle = Number.isSafeInteger(proc.pid) && Number(proc.pid) > 0;
896
+ if (liveHandle)
897
+ rememberFailure(error);
898
+ stderrCapture.append(error instanceof Error ? error.message : String(error));
899
+ if (!liveHandle)
900
+ settle(1);
901
+ });
902
+ proc.on("close", (code, signal) => {
903
+ settle(code ?? 1, code, signal);
904
+ });
905
+ managed = proc;
906
+ try {
907
+ if (options.signal) {
908
+ if (options.signal.aborted)
909
+ killProcess();
910
+ else
911
+ options.signal.addEventListener("abort", killProcess, { once: true });
912
+ }
913
+ if (options.timeout !== undefined && options.timeout > 0)
914
+ timeoutId = setTimeout(killProcess, options.timeout);
915
+ if (options.stdin !== undefined)
916
+ proc.stdin?.end(options.stdin);
917
+ if (options.onAttemptManaged) {
918
+ const context = Object.freeze({ attempt, process: proc });
919
+ freshManagedAttempts.set(context, { process: proc, pid: proc.pid, admission: spawnAdmission });
920
+ try {
921
+ options.onAttemptManaged(context);
922
+ }
923
+ finally {
924
+ freshManagedAttempts.delete(context);
925
+ }
926
+ }
927
+ }
928
+ catch (error) {
929
+ rememberFailure(error);
930
+ }
931
+ return proc;
793
932
  };
794
- if (options.signal) {
795
- if (options.signal.aborted)
796
- killProcess();
933
+ const parentAdmission = pendingSpawnAdmission;
934
+ try {
935
+ pendingSpawnAdmission = spawnAdmission;
936
+ const proc = options.admitSpawn ? options.admitSpawn(start) : start();
937
+ if (!managed)
938
+ throw new Error("Native spawn admission must invoke its managed factory.");
939
+ if (proc !== managed)
940
+ throw new Error("Native spawn admission must return its managed process.");
941
+ }
942
+ catch (error) {
943
+ if (managed)
944
+ rememberFailure(error);
797
945
  else
798
- options.signal.addEventListener("abort", killProcess, { once: true });
946
+ reject(error);
947
+ }
948
+ finally {
949
+ admissionOpen = false;
950
+ pendingSpawnAdmission = parentAdmission;
799
951
  }
800
- if (options.timeout !== undefined && options.timeout > 0)
801
- timeoutId = setTimeout(killProcess, options.timeout);
802
- proc.stdout?.on("data", (data) => {
803
- stdoutCapture.append(data);
804
- });
805
- proc.stderr?.on("data", (data) => {
806
- stderrCapture.append(data);
807
- });
808
- proc.stdin?.on("error", () => { });
809
- if (options.stdin !== undefined)
810
- proc.stdin?.end(options.stdin);
811
- proc.on("error", (error) => {
812
- stderrCapture.append(error instanceof Error ? error.message : String(error));
813
- settle(1);
814
- });
815
- proc.on("close", (code) => {
816
- settle(code ?? (killed ? 1 : 0));
817
- });
818
952
  });
819
953
  }
820
954
  export function buildCommandTemplateInvocation(config, values, cwd, options = {}) {
@@ -0,0 +1,32 @@
1
+ export type ExecutionFileReferenceReading = {
2
+ readonly availability: "available";
3
+ readonly path: string;
4
+ readonly local_path: string;
5
+ readonly bytes_total: number;
6
+ readonly mutable: true;
7
+ readonly unchanged: () => boolean;
8
+ } | {
9
+ readonly availability: "unavailable";
10
+ readonly reason: "invalid_reference" | "reference_missing" | "reference_unavailable" | "reference_changed" | "reference_size_unrepresentable";
11
+ };
12
+ export declare const RUN_STREAM_SOURCE_MAX_BYTES: number;
13
+ export type ExecutionTextReading = {
14
+ readonly availability: "available";
15
+ readonly reference: Extract<ExecutionFileReferenceReading, {
16
+ availability: "available";
17
+ }>;
18
+ readonly text: string;
19
+ } | {
20
+ readonly availability: "unavailable";
21
+ readonly reason: Extract<ExecutionFileReferenceReading, {
22
+ availability: "unavailable";
23
+ }>["reason"] | "reference_too_large" | "reference_invalid_text";
24
+ };
25
+ /** Metadata-only: never reads body bytes, regardless of file size. */
26
+ export declare function observeExecutionFileReference(stateDir: string, request: unknown): Readonly<ExecutionFileReferenceReading>;
27
+ /** Raw text is kernel-local input to an authorized projection, never a tool/model result. */
28
+ export declare function readExecutionSessionText(stateDir: string, path: string): Readonly<ExecutionTextReading>;
29
+ /** Explicit command capture input only; neither this read nor its path authorizes publication. */
30
+ export declare function readExecutionCaptureText(stateDir: string, path: string): Readonly<ExecutionTextReading>;
31
+ /** Canonical runner text is kernel-local input, not complete command capture or a model-visible privacy projection. */
32
+ export declare function readExecutionRunnerStreamText(stateDir: string, stream: unknown): Readonly<ExecutionTextReading>;
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Execution-file layout and metadata observation beneath a caller-admitted Run state root.
3
+ * Owns: capture/session/canonical-runner stream layout, metadata and bounded strict text inputs through a checked descriptor.
4
+ * Excludes: Run/generation admission, unrestricted body exposure, discovery, privacy projection, historical-content or native authority.
5
+ */
6
+ import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, realpathSync } from "node:fs";
7
+ import { isAbsolute, join, resolve, win32 } from "node:path";
8
+ import { SESSION_EVIDENCE_MAX_BYTES } from "./limits.js";
9
+ export const RUN_STREAM_SOURCE_MAX_BYTES = 4 * 1024 * 1024;
10
+ function unavailable(reason) { return Object.freeze({ availability: "unavailable", reason }); }
11
+ function sameObject(left, right) { return left.dev === right.dev && left.ino === right.ino; }
12
+ function sameFile(left, right) {
13
+ return right.isFile() && sameObject(left, right) && left.size === right.size && left.mtimeNs === right.mtimeNs && left.ctimeNs === right.ctimeNs;
14
+ }
15
+ function referencePath(request) {
16
+ if (!request || typeof request !== "object" || Array.isArray(request))
17
+ return undefined;
18
+ const kind = Object.getOwnPropertyDescriptor(request, "kind")?.value;
19
+ const path = Object.getOwnPropertyDescriptor(request, "path")?.value;
20
+ if ((kind !== "session" && kind !== "capture" && kind !== "runner_stream") || typeof path !== "string" || !path || isAbsolute(path) || win32.isAbsolute(path) ||
21
+ /[\\\u0000-\u001f\u007f]/u.test(path) || (process.platform === "win32" && path.includes(":")))
22
+ return undefined;
23
+ const parts = path.split("/");
24
+ if (parts.some(part => !part || part === "." || part === ".."))
25
+ return undefined;
26
+ if (kind === "runner_stream")
27
+ return path === "stdout.log" || path === "stderr.log" ? path : undefined;
28
+ if (kind === "session")
29
+ return parts[0] === "sessions" && parts.length >= 2 && parts.at(-1).endsWith(".jsonl") ? path : undefined;
30
+ const capture = /^captures\/command-([0-9]{3,})\/attempt-([0-9]{3,})\/(stdout|stderr)\.log$/u.exec(path);
31
+ return capture && capture.slice(1, 3).every(number => Number.isSafeInteger(Number(number)) && Number(number) > 0) ? path : undefined;
32
+ }
33
+ function inspectExecutionFile(stateDir, request, maxTextBytes) {
34
+ const relative = referencePath(request);
35
+ if (!relative)
36
+ return unavailable("invalid_reference");
37
+ try {
38
+ const requestedRoot = resolve(stateDir);
39
+ const root = lstatSync(requestedRoot, { bigint: true });
40
+ if (!root.isDirectory() || root.isSymbolicLink())
41
+ return unavailable("reference_unavailable");
42
+ const canonicalRoot = realpathSync(requestedRoot);
43
+ const canonical = lstatSync(canonicalRoot, { bigint: true });
44
+ if (!canonical.isDirectory() || !sameObject(root, canonical))
45
+ return unavailable("reference_changed");
46
+ const directories = [{ path: requestedRoot, stamp: root }, { path: canonicalRoot, stamp: canonical }];
47
+ const parts = relative.split("/");
48
+ let directory = canonicalRoot;
49
+ for (const part of parts.slice(0, -1)) {
50
+ directory = join(directory, part);
51
+ const stamp = lstatSync(directory, { bigint: true });
52
+ if (!stamp.isDirectory() || stamp.isSymbolicLink())
53
+ return unavailable("reference_unavailable");
54
+ directories.push({ path: directory, stamp });
55
+ }
56
+ const path = join(canonicalRoot, ...parts);
57
+ const before = lstatSync(path, { bigint: true });
58
+ if (!before.isFile())
59
+ return unavailable("reference_unavailable");
60
+ if (before.size < 0n || before.size > BigInt(Number.MAX_SAFE_INTEGER))
61
+ return unavailable("reference_size_unrepresentable");
62
+ if (maxTextBytes !== undefined && before.size > BigInt(maxTextBytes))
63
+ return Object.freeze({ availability: "unavailable", reason: "reference_too_large" });
64
+ // Nonblocking/nofollow flags avoid waiting on a leaf replaced with a FIFO or following a leaf alias when supported.
65
+ const fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
66
+ try {
67
+ const opened = fstatSync(fd, { bigint: true });
68
+ if (!sameFile(before, opened))
69
+ return unavailable("reference_changed");
70
+ const unchanged = () => {
71
+ try {
72
+ return directories.every(directory => {
73
+ const current = lstatSync(directory.path, { bigint: true });
74
+ return current.isDirectory() && sameObject(directory.stamp, current);
75
+ }) && sameFile(opened, lstatSync(path, { bigint: true }));
76
+ }
77
+ catch {
78
+ return false;
79
+ }
80
+ };
81
+ let text;
82
+ if (maxTextBytes !== undefined) {
83
+ const bytes = Buffer.alloc(Number(opened.size));
84
+ let offset = 0;
85
+ while (offset < bytes.length) {
86
+ const count = readSync(fd, bytes, offset, bytes.length - offset, offset);
87
+ if (!count)
88
+ return unavailable("reference_changed");
89
+ offset += count;
90
+ }
91
+ try {
92
+ text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: !relative.startsWith("sessions/") }).decode(bytes);
93
+ }
94
+ catch {
95
+ return Object.freeze({ availability: "unavailable", reason: "reference_invalid_text" });
96
+ }
97
+ }
98
+ if (!sameFile(opened, fstatSync(fd, { bigint: true })) || !unchanged())
99
+ return unavailable("reference_changed");
100
+ const reference = Object.freeze({ availability: "available", path: relative, local_path: path, bytes_total: Number(opened.size), mutable: true, unchanged });
101
+ return text === undefined ? reference : Object.freeze({ availability: "available", reference, text });
102
+ }
103
+ finally {
104
+ closeSync(fd);
105
+ }
106
+ }
107
+ catch (error) {
108
+ return unavailable(error.code === "ENOENT" ? "reference_missing" : "reference_unavailable");
109
+ }
110
+ }
111
+ /** Metadata-only: never reads body bytes, regardless of file size. */
112
+ export function observeExecutionFileReference(stateDir, request) {
113
+ return inspectExecutionFile(stateDir, request);
114
+ }
115
+ /** Raw text is kernel-local input to an authorized projection, never a tool/model result. */
116
+ export function readExecutionSessionText(stateDir, path) {
117
+ return inspectExecutionFile(stateDir, { kind: "session", path }, SESSION_EVIDENCE_MAX_BYTES);
118
+ }
119
+ /** Explicit command capture input only; neither this read nor its path authorizes publication. */
120
+ export function readExecutionCaptureText(stateDir, path) {
121
+ return inspectExecutionFile(stateDir, { kind: "capture", path }, RUN_STREAM_SOURCE_MAX_BYTES);
122
+ }
123
+ /** Canonical runner text is kernel-local input, not complete command capture or a model-visible privacy projection. */
124
+ export function readExecutionRunnerStreamText(stateDir, stream) {
125
+ if (stream !== "stdout" && stream !== "stderr")
126
+ return unavailable("invalid_reference");
127
+ return inspectExecutionFile(stateDir, { kind: "runner_stream", path: `${stream}.log` }, RUN_STREAM_SOURCE_MAX_BYTES);
128
+ }
@@ -35,10 +35,11 @@ export function trimToTailBytes(value, maxBytes) {
35
35
  const buffer = Buffer.from(value, "utf8");
36
36
  if (buffer.length <= maxBytes)
37
37
  return value;
38
- return buffer
39
- .subarray(buffer.length - maxBytes)
40
- .toString("utf8")
41
- .replace(/^\uFFFD+/, "");
38
+ let start = Math.ceil(buffer.length - maxBytes);
39
+ // Skip only the cut code point's continuation bytes, not genuine U+FFFD text.
40
+ while (start < buffer.length && (buffer[start] & 0xc0) === 0x80)
41
+ start++;
42
+ return buffer.subarray(start).toString("utf8");
42
43
  }
43
44
  export function truncateTailContent(content) {
44
45
  const totalBytes = byteLength(content);
@@ -14,4 +14,22 @@ export interface ExecutionTurnItem extends SessionEvidence.SessionEvidenceTurn {
14
14
  sessionTruncated: boolean;
15
15
  stage?: string;
16
16
  }
17
- export declare function readExecutionTurns(stateDir: string): ExecutionTurnItem[];
17
+ export declare const EXECUTION_CHRONOLOGY: unique symbol;
18
+ export interface ExecutionChronologyEntry extends SessionEvidence.SessionChronologyEntry {
19
+ commandId: string;
20
+ sessionFile: string;
21
+ sessionOrdinal: number;
22
+ }
23
+ export type ExecutionChronology = Readonly<{
24
+ basis: "recorded_execution_metadata";
25
+ entries: readonly Readonly<ExecutionChronologyEntry>[];
26
+ } & ({
27
+ state: "available";
28
+ } | {
29
+ state: "unavailable";
30
+ reason: SessionEvidence.SessionChronologyReason | "source_changed" | "namespace_unavailable";
31
+ })>;
32
+ export type ExecutionTurnCollection = ExecutionTurnItem[] & {
33
+ readonly [EXECUTION_CHRONOLOGY]?: ExecutionChronology;
34
+ };
35
+ export declare function readExecutionTurns(stateDir: string): ExecutionTurnCollection;