@llblab/pi-kit 0.1.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 (523) hide show
  1. package/AGENTS.md +35 -0
  2. package/BACKLOG.md +3 -0
  3. package/CHANGELOG.md +9 -0
  4. package/LICENSE +21 -0
  5. package/README.md +43 -0
  6. package/node_modules/@llblab/pi-actors/AGENTS.md +150 -0
  7. package/node_modules/@llblab/pi-actors/BACKLOG.md +6 -0
  8. package/node_modules/@llblab/pi-actors/CHANGELOG.md +865 -0
  9. package/node_modules/@llblab/pi-actors/README.md +231 -0
  10. package/node_modules/@llblab/pi-actors/banner.jpg +0 -0
  11. package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/artifact-manifest.json +9 -0
  12. package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/control-endpoint.json +6 -0
  13. package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/control-record.json +9 -0
  14. package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/recipe-summary.json +8 -0
  15. package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/run-state.json +10 -0
  16. package/node_modules/@llblab/pi-actors/dist/fixtures/protocol/trace-event.json +9 -0
  17. package/node_modules/@llblab/pi-actors/dist/index.d.ts +7 -0
  18. package/node_modules/@llblab/pi-actors/dist/index.js +17 -0
  19. package/node_modules/@llblab/pi-actors/dist/lib/async-runs.d.ts +146 -0
  20. package/node_modules/@llblab/pi-actors/dist/lib/async-runs.js +800 -0
  21. package/node_modules/@llblab/pi-actors/dist/lib/automatic-review-runtime.d.ts +20 -0
  22. package/node_modules/@llblab/pi-actors/dist/lib/automatic-review-runtime.js +103 -0
  23. package/node_modules/@llblab/pi-actors/dist/lib/command-templates.d.ts +85 -0
  24. package/node_modules/@llblab/pi-actors/dist/lib/command-templates.js +804 -0
  25. package/node_modules/@llblab/pi-actors/dist/lib/config.d.ts +34 -0
  26. package/node_modules/@llblab/pi-actors/dist/lib/config.js +216 -0
  27. package/node_modules/@llblab/pi-actors/dist/lib/control-projection.d.ts +20 -0
  28. package/node_modules/@llblab/pi-actors/dist/lib/control-projection.js +66 -0
  29. package/node_modules/@llblab/pi-actors/dist/lib/control.d.ts +15 -0
  30. package/node_modules/@llblab/pi-actors/dist/lib/control.js +97 -0
  31. package/node_modules/@llblab/pi-actors/dist/lib/draft-consolidation-transaction.d.ts +65 -0
  32. package/node_modules/@llblab/pi-actors/dist/lib/draft-consolidation-transaction.js +610 -0
  33. package/node_modules/@llblab/pi-actors/dist/lib/draft-consolidation.d.ts +35 -0
  34. package/node_modules/@llblab/pi-actors/dist/lib/draft-consolidation.js +126 -0
  35. package/node_modules/@llblab/pi-actors/dist/lib/draft-review.d.ts +56 -0
  36. package/node_modules/@llblab/pi-actors/dist/lib/draft-review.js +254 -0
  37. package/node_modules/@llblab/pi-actors/dist/lib/draft-sleep.d.ts +65 -0
  38. package/node_modules/@llblab/pi-actors/dist/lib/draft-sleep.js +467 -0
  39. package/node_modules/@llblab/pi-actors/dist/lib/execution-output.d.ts +25 -0
  40. package/node_modules/@llblab/pi-actors/dist/lib/execution-output.js +88 -0
  41. package/node_modules/@llblab/pi-actors/dist/lib/execution-sessions.d.ts +17 -0
  42. package/node_modules/@llblab/pi-actors/dist/lib/execution-sessions.js +85 -0
  43. package/node_modules/@llblab/pi-actors/dist/lib/execution.d.ts +99 -0
  44. package/node_modules/@llblab/pi-actors/dist/lib/execution.js +725 -0
  45. package/node_modules/@llblab/pi-actors/dist/lib/extension-runtime.d.ts +21 -0
  46. package/node_modules/@llblab/pi-actors/dist/lib/extension-runtime.js +141 -0
  47. package/node_modules/@llblab/pi-actors/dist/lib/file-state.d.ts +18 -0
  48. package/node_modules/@llblab/pi-actors/dist/lib/file-state.js +310 -0
  49. package/node_modules/@llblab/pi-actors/dist/lib/identity.d.ts +9 -0
  50. package/node_modules/@llblab/pi-actors/dist/lib/identity.js +27 -0
  51. package/node_modules/@llblab/pi-actors/dist/lib/inspector-actions.d.ts +16 -0
  52. package/node_modules/@llblab/pi-actors/dist/lib/inspector-actions.js +57 -0
  53. package/node_modules/@llblab/pi-actors/dist/lib/inspector-command.d.ts +7 -0
  54. package/node_modules/@llblab/pi-actors/dist/lib/inspector-command.js +37 -0
  55. package/node_modules/@llblab/pi-actors/dist/lib/inspector-overlay.d.ts +100 -0
  56. package/node_modules/@llblab/pi-actors/dist/lib/inspector-overlay.js +824 -0
  57. package/node_modules/@llblab/pi-actors/dist/lib/inspector.d.ts +20 -0
  58. package/node_modules/@llblab/pi-actors/dist/lib/inspector.js +136 -0
  59. package/node_modules/@llblab/pi-actors/dist/lib/limits.d.ts +28 -0
  60. package/node_modules/@llblab/pi-actors/dist/lib/limits.js +28 -0
  61. package/node_modules/@llblab/pi-actors/dist/lib/model-context.d.ts +56 -0
  62. package/node_modules/@llblab/pi-actors/dist/lib/model-context.js +220 -0
  63. package/node_modules/@llblab/pi-actors/dist/lib/observability.d.ts +186 -0
  64. package/node_modules/@llblab/pi-actors/dist/lib/observability.js +951 -0
  65. package/node_modules/@llblab/pi-actors/dist/lib/paths.d.ts +27 -0
  66. package/node_modules/@llblab/pi-actors/dist/lib/paths.js +72 -0
  67. package/node_modules/@llblab/pi-actors/dist/lib/pi.d.ts +19 -0
  68. package/node_modules/@llblab/pi-actors/dist/lib/pi.js +21 -0
  69. package/node_modules/@llblab/pi-actors/dist/lib/preflight-diagnostics.d.ts +27 -0
  70. package/node_modules/@llblab/pi-actors/dist/lib/preflight-diagnostics.js +86 -0
  71. package/node_modules/@llblab/pi-actors/dist/lib/prompts.d.ts +24 -0
  72. package/node_modules/@llblab/pi-actors/dist/lib/prompts.js +49 -0
  73. package/node_modules/@llblab/pi-actors/dist/lib/recipe-control.d.ts +7 -0
  74. package/node_modules/@llblab/pi-actors/dist/lib/recipe-control.js +43 -0
  75. package/node_modules/@llblab/pi-actors/dist/lib/recipes-context.d.ts +36 -0
  76. package/node_modules/@llblab/pi-actors/dist/lib/recipes-context.js +197 -0
  77. package/node_modules/@llblab/pi-actors/dist/lib/recipes-discovery.d.ts +77 -0
  78. package/node_modules/@llblab/pi-actors/dist/lib/recipes-discovery.js +783 -0
  79. package/node_modules/@llblab/pi-actors/dist/lib/recipes-references.d.ts +113 -0
  80. package/node_modules/@llblab/pi-actors/dist/lib/recipes-references.js +1108 -0
  81. package/node_modules/@llblab/pi-actors/dist/lib/recipes-usage.d.ts +21 -0
  82. package/node_modules/@llblab/pi-actors/dist/lib/recipes-usage.js +494 -0
  83. package/node_modules/@llblab/pi-actors/dist/lib/registry.d.ts +67 -0
  84. package/node_modules/@llblab/pi-actors/dist/lib/registry.js +504 -0
  85. package/node_modules/@llblab/pi-actors/dist/lib/review-control.d.ts +14 -0
  86. package/node_modules/@llblab/pi-actors/dist/lib/review-control.js +110 -0
  87. package/node_modules/@llblab/pi-actors/dist/lib/review-diagnostics.d.ts +11 -0
  88. package/node_modules/@llblab/pi-actors/dist/lib/review-diagnostics.js +148 -0
  89. package/node_modules/@llblab/pi-actors/dist/lib/review-projection.d.ts +14 -0
  90. package/node_modules/@llblab/pi-actors/dist/lib/review-projection.js +166 -0
  91. package/node_modules/@llblab/pi-actors/dist/lib/run-evidence-policy.d.ts +95 -0
  92. package/node_modules/@llblab/pi-actors/dist/lib/run-evidence-policy.js +177 -0
  93. package/node_modules/@llblab/pi-actors/dist/lib/run-ui-runtime.d.ts +18 -0
  94. package/node_modules/@llblab/pi-actors/dist/lib/run-ui-runtime.js +125 -0
  95. package/node_modules/@llblab/pi-actors/dist/lib/runs-artifacts.d.ts +21 -0
  96. package/node_modules/@llblab/pi-actors/dist/lib/runs-artifacts.js +68 -0
  97. package/node_modules/@llblab/pi-actors/dist/lib/runs-control-delivery.d.ts +28 -0
  98. package/node_modules/@llblab/pi-actors/dist/lib/runs-control-delivery.js +150 -0
  99. package/node_modules/@llblab/pi-actors/dist/lib/runs-control.d.ts +21 -0
  100. package/node_modules/@llblab/pi-actors/dist/lib/runs-control.js +89 -0
  101. package/node_modules/@llblab/pi-actors/dist/lib/runs-controls.d.ts +39 -0
  102. package/node_modules/@llblab/pi-actors/dist/lib/runs-controls.js +283 -0
  103. package/node_modules/@llblab/pi-actors/dist/lib/runs-identity.d.ts +5 -0
  104. package/node_modules/@llblab/pi-actors/dist/lib/runs-identity.js +11 -0
  105. package/node_modules/@llblab/pi-actors/dist/lib/runs-index.d.ts +27 -0
  106. package/node_modules/@llblab/pi-actors/dist/lib/runs-index.js +142 -0
  107. package/node_modules/@llblab/pi-actors/dist/lib/runs-ownership.d.ts +7 -0
  108. package/node_modules/@llblab/pi-actors/dist/lib/runs-ownership.js +96 -0
  109. package/node_modules/@llblab/pi-actors/dist/lib/runs-parent-teardown.d.ts +51 -0
  110. package/node_modules/@llblab/pi-actors/dist/lib/runs-parent-teardown.js +172 -0
  111. package/node_modules/@llblab/pi-actors/dist/lib/runs-process.d.ts +22 -0
  112. package/node_modules/@llblab/pi-actors/dist/lib/runs-process.js +125 -0
  113. package/node_modules/@llblab/pi-actors/dist/lib/runs-retention.d.ts +18 -0
  114. package/node_modules/@llblab/pi-actors/dist/lib/runs-retention.js +108 -0
  115. package/node_modules/@llblab/pi-actors/dist/lib/runs-start.d.ts +12 -0
  116. package/node_modules/@llblab/pi-actors/dist/lib/runs-start.js +68 -0
  117. package/node_modules/@llblab/pi-actors/dist/lib/runs-status.d.ts +10 -0
  118. package/node_modules/@llblab/pi-actors/dist/lib/runs-status.js +68 -0
  119. package/node_modules/@llblab/pi-actors/dist/lib/runs-trace.d.ts +48 -0
  120. package/node_modules/@llblab/pi-actors/dist/lib/runs-trace.js +491 -0
  121. package/node_modules/@llblab/pi-actors/dist/lib/runtime-identity.d.ts +7 -0
  122. package/node_modules/@llblab/pi-actors/dist/lib/runtime-identity.js +35 -0
  123. package/node_modules/@llblab/pi-actors/dist/lib/runtime-triage.d.ts +29 -0
  124. package/node_modules/@llblab/pi-actors/dist/lib/runtime-triage.js +60 -0
  125. package/node_modules/@llblab/pi-actors/dist/lib/runtime.d.ts +69 -0
  126. package/node_modules/@llblab/pi-actors/dist/lib/runtime.js +339 -0
  127. package/node_modules/@llblab/pi-actors/dist/lib/schema.d.ts +60 -0
  128. package/node_modules/@llblab/pi-actors/dist/lib/schema.js +428 -0
  129. package/node_modules/@llblab/pi-actors/dist/lib/session-evidence.d.ts +45 -0
  130. package/node_modules/@llblab/pi-actors/dist/lib/session-evidence.js +204 -0
  131. package/node_modules/@llblab/pi-actors/dist/lib/state-readers.d.ts +21 -0
  132. package/node_modules/@llblab/pi-actors/dist/lib/state-readers.js +74 -0
  133. package/node_modules/@llblab/pi-actors/dist/lib/temp.d.ts +10 -0
  134. package/node_modules/@llblab/pi-actors/dist/lib/temp.js +90 -0
  135. package/node_modules/@llblab/pi-actors/dist/lib/tool-review-lineage-transaction.d.ts +27 -0
  136. package/node_modules/@llblab/pi-actors/dist/lib/tool-review-lineage-transaction.js +597 -0
  137. package/node_modules/@llblab/pi-actors/dist/lib/tool-review-lineage.d.ts +24 -0
  138. package/node_modules/@llblab/pi-actors/dist/lib/tool-review-lineage.js +98 -0
  139. package/node_modules/@llblab/pi-actors/dist/lib/tool-review-scheduler.d.ts +80 -0
  140. package/node_modules/@llblab/pi-actors/dist/lib/tool-review-scheduler.js +494 -0
  141. package/node_modules/@llblab/pi-actors/dist/lib/tool-review-transaction.d.ts +50 -0
  142. package/node_modules/@llblab/pi-actors/dist/lib/tool-review-transaction.js +362 -0
  143. package/node_modules/@llblab/pi-actors/dist/lib/tool-review.d.ts +56 -0
  144. package/node_modules/@llblab/pi-actors/dist/lib/tool-review.js +197 -0
  145. package/node_modules/@llblab/pi-actors/dist/lib/tools-access.d.ts +19 -0
  146. package/node_modules/@llblab/pi-actors/dist/lib/tools-access.js +44 -0
  147. package/node_modules/@llblab/pi-actors/dist/lib/tools-inspect.d.ts +15 -0
  148. package/node_modules/@llblab/pi-actors/dist/lib/tools-inspect.js +532 -0
  149. package/node_modules/@llblab/pi-actors/dist/lib/tools-local.d.ts +17 -0
  150. package/node_modules/@llblab/pi-actors/dist/lib/tools-local.js +191 -0
  151. package/node_modules/@llblab/pi-actors/dist/lib/tools-message.d.ts +9 -0
  152. package/node_modules/@llblab/pi-actors/dist/lib/tools-message.js +139 -0
  153. package/node_modules/@llblab/pi-actors/dist/lib/tools-register.d.ts +18 -0
  154. package/node_modules/@llblab/pi-actors/dist/lib/tools-register.js +41 -0
  155. package/node_modules/@llblab/pi-actors/dist/lib/tools-response.d.ts +20 -0
  156. package/node_modules/@llblab/pi-actors/dist/lib/tools-response.js +243 -0
  157. package/node_modules/@llblab/pi-actors/dist/lib/tools-spawn.d.ts +15 -0
  158. package/node_modules/@llblab/pi-actors/dist/lib/tools-spawn.js +133 -0
  159. package/node_modules/@llblab/pi-actors/dist/lib/tools.d.ts +28 -0
  160. package/node_modules/@llblab/pi-actors/dist/lib/tools.js +49 -0
  161. package/node_modules/@llblab/pi-actors/dist/lib/trace-projection.d.ts +22 -0
  162. package/node_modules/@llblab/pi-actors/dist/lib/trace-projection.js +231 -0
  163. package/node_modules/@llblab/pi-actors/dist/pi-actors/index.js +1 -0
  164. package/node_modules/@llblab/pi-actors/dist/scripts/async-runner.mjs +555 -0
  165. package/node_modules/@llblab/pi-actors/dist/scripts/build-dist.mjs +60 -0
  166. package/node_modules/@llblab/pi-actors/dist/scripts/conformance.mjs +63 -0
  167. package/node_modules/@llblab/pi-actors/dist/skills/actors/SKILL.md +126 -0
  168. package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/command-validate.json +13 -0
  169. package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/jsonl-tail.json +10 -0
  170. package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/recipe-validate.json +11 -0
  171. package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/resource-locker-snapshot.json +11 -0
  172. package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/resource-locker.json +25 -0
  173. package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/run-ops-snapshot.json +15 -0
  174. package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/run-state-files.json +13 -0
  175. package/node_modules/@llblab/pi-actors/dist/skills/actors/recipes/run-summary.json +9 -0
  176. package/node_modules/@llblab/pi-actors/dist/skills/actors/references/diagnostics.md +44 -0
  177. package/node_modules/@llblab/pi-actors/dist/skills/actors/references/persistent-tools.md +76 -0
  178. package/node_modules/@llblab/pi-actors/dist/skills/actors/references/recipes.md +51 -0
  179. package/node_modules/@llblab/pi-actors/dist/skills/actors/references/runs.md +41 -0
  180. package/node_modules/@llblab/pi-actors/dist/skills/actors/scripts/resource-locker.mjs +425 -0
  181. package/node_modules/@llblab/pi-actors/dist/skills/actors/scripts/run-utils.mjs +164 -0
  182. package/node_modules/@llblab/pi-actors/dist/skills/actors/scripts/validate-recipe.mjs +370 -0
  183. package/node_modules/@llblab/pi-actors/dist/skills/artifacts/SKILL.md +33 -0
  184. package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/bundle.json +77 -0
  185. package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/file-write.json +14 -0
  186. package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/manifest.json +14 -0
  187. package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/report.json +39 -0
  188. package/node_modules/@llblab/pi-actors/dist/skills/artifacts/recipes/write.json +53 -0
  189. package/node_modules/@llblab/pi-actors/dist/skills/artifacts/scripts/artifact-utils.mjs +63 -0
  190. package/node_modules/@llblab/pi-actors/dist/skills/music-player/SKILL.md +57 -0
  191. package/node_modules/@llblab/pi-actors/dist/skills/music-player/genapps/music-player.mjs +360 -0
  192. package/node_modules/@llblab/pi-actors/dist/skills/music-player/recipes/playback.json +29 -0
  193. package/node_modules/@llblab/pi-actors/dist/skills/music-player/scripts/playback-client.mjs +143 -0
  194. package/node_modules/@llblab/pi-actors/dist/skills/music-player/scripts/playback.mjs +1446 -0
  195. package/node_modules/@llblab/pi-actors/dist/skills/project-work/SKILL.md +37 -0
  196. package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/changelog-head.json +11 -0
  197. package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/changelog-section.json +11 -0
  198. package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/docs-maintenance.json +66 -0
  199. package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/git-log.json +11 -0
  200. package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/git-status.json +9 -0
  201. package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/markdown-index.json +14 -0
  202. package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/package-summary.json +9 -0
  203. package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/release-readiness.json +115 -0
  204. package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/release-summary.json +74 -0
  205. package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/repo-health.json +75 -0
  206. package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/run-ops.json +56 -0
  207. package/node_modules/@llblab/pi-actors/dist/skills/project-work/recipes/skill-summary.json +11 -0
  208. package/node_modules/@llblab/pi-actors/dist/skills/project-work/scripts/project-utils.mjs +89 -0
  209. package/node_modules/@llblab/pi-actors/dist/skills/recipe-memory/SKILL.md +36 -0
  210. package/node_modules/@llblab/pi-actors/dist/skills/recipe-memory/recipes/draft-review.json +14 -0
  211. package/node_modules/@llblab/pi-actors/dist/skills/recipe-memory/recipes/tool-review.json +14 -0
  212. package/node_modules/@llblab/pi-actors/dist/skills/swarm/SKILL.md +84 -0
  213. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/architect.json +82 -0
  214. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/checkpoint-continuation.json +51 -0
  215. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/development-tasking.json +67 -0
  216. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/lens-review.json +63 -0
  217. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/quorum-review.json +65 -0
  218. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/research-synthesis.json +81 -0
  219. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/review-readiness.json +59 -0
  220. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-artifact.json +21 -0
  221. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-checkpoint.json +21 -0
  222. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-conflict-report.json +19 -0
  223. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-contradiction-map.json +20 -0
  224. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-critic.json +22 -0
  225. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-evidence-map.json +20 -0
  226. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-followup.json +21 -0
  227. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-judge.json +22 -0
  228. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-merge.json +24 -0
  229. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-normalize.json +20 -0
  230. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-plan.json +20 -0
  231. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-preflight.json +18 -0
  232. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-prompt.json +16 -0
  233. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-prompts.json +39 -0
  234. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-quorum.json +31 -0
  235. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-review-coordinator.json +170 -0
  236. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-review.json +26 -0
  237. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-task-card.json +22 -0
  238. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-tools.json +15 -0
  239. package/node_modules/@llblab/pi-actors/dist/skills/swarm/recipes/subagent-verify.json +23 -0
  240. package/node_modules/@llblab/pi-actors/dist/skills/swarm/references/development-swarm.md +189 -0
  241. package/node_modules/@llblab/pi-actors/dist/skills/swarm/references/review-swarms.md +115 -0
  242. package/node_modules/@llblab/pi-actors/docs/README.md +20 -0
  243. package/node_modules/@llblab/pi-actors/docs/actor-inspector.md +50 -0
  244. package/node_modules/@llblab/pi-actors/docs/async-runs.md +141 -0
  245. package/node_modules/@llblab/pi-actors/docs/command-templates.md +321 -0
  246. package/node_modules/@llblab/pi-actors/docs/recipe-library.md +89 -0
  247. package/node_modules/@llblab/pi-actors/docs/releasing.md +28 -0
  248. package/node_modules/@llblab/pi-actors/docs/template-recipes.md +175 -0
  249. package/node_modules/@llblab/pi-actors/docs/tool-registry.md +90 -0
  250. package/node_modules/@llblab/pi-actors/fixtures/protocol/artifact-manifest.json +9 -0
  251. package/node_modules/@llblab/pi-actors/fixtures/protocol/control-endpoint.json +6 -0
  252. package/node_modules/@llblab/pi-actors/fixtures/protocol/control-record.json +9 -0
  253. package/node_modules/@llblab/pi-actors/fixtures/protocol/recipe-summary.json +8 -0
  254. package/node_modules/@llblab/pi-actors/fixtures/protocol/run-state.json +10 -0
  255. package/node_modules/@llblab/pi-actors/fixtures/protocol/trace-event.json +9 -0
  256. package/node_modules/@llblab/pi-actors/index.ts +30 -0
  257. package/node_modules/@llblab/pi-actors/lib/async-runs.ts +1245 -0
  258. package/node_modules/@llblab/pi-actors/lib/automatic-review-runtime.ts +148 -0
  259. package/node_modules/@llblab/pi-actors/lib/command-templates.ts +1116 -0
  260. package/node_modules/@llblab/pi-actors/lib/config.ts +261 -0
  261. package/node_modules/@llblab/pi-actors/lib/control-projection.ts +105 -0
  262. package/node_modules/@llblab/pi-actors/lib/control.ts +117 -0
  263. package/node_modules/@llblab/pi-actors/lib/draft-consolidation-transaction.ts +821 -0
  264. package/node_modules/@llblab/pi-actors/lib/draft-consolidation.ts +181 -0
  265. package/node_modules/@llblab/pi-actors/lib/draft-review.ts +325 -0
  266. package/node_modules/@llblab/pi-actors/lib/draft-sleep.ts +575 -0
  267. package/node_modules/@llblab/pi-actors/lib/execution-output.ts +123 -0
  268. package/node_modules/@llblab/pi-actors/lib/execution-sessions.ts +111 -0
  269. package/node_modules/@llblab/pi-actors/lib/execution.ts +1153 -0
  270. package/node_modules/@llblab/pi-actors/lib/extension-runtime.ts +181 -0
  271. package/node_modules/@llblab/pi-actors/lib/file-state.ts +306 -0
  272. package/node_modules/@llblab/pi-actors/lib/identity.ts +29 -0
  273. package/node_modules/@llblab/pi-actors/lib/inspector-actions.ts +79 -0
  274. package/node_modules/@llblab/pi-actors/lib/inspector-command.ts +54 -0
  275. package/node_modules/@llblab/pi-actors/lib/inspector-overlay.ts +901 -0
  276. package/node_modules/@llblab/pi-actors/lib/inspector.ts +204 -0
  277. package/node_modules/@llblab/pi-actors/lib/limits.ts +29 -0
  278. package/node_modules/@llblab/pi-actors/lib/model-context.ts +359 -0
  279. package/node_modules/@llblab/pi-actors/lib/observability.ts +1337 -0
  280. package/node_modules/@llblab/pi-actors/lib/paths.ts +111 -0
  281. package/node_modules/@llblab/pi-actors/lib/pi.ts +47 -0
  282. package/node_modules/@llblab/pi-actors/lib/preflight-diagnostics.ts +132 -0
  283. package/node_modules/@llblab/pi-actors/lib/prompts.ts +69 -0
  284. package/node_modules/@llblab/pi-actors/lib/recipe-control.ts +52 -0
  285. package/node_modules/@llblab/pi-actors/lib/recipes-context.ts +268 -0
  286. package/node_modules/@llblab/pi-actors/lib/recipes-discovery.ts +1060 -0
  287. package/node_modules/@llblab/pi-actors/lib/recipes-references.ts +1598 -0
  288. package/node_modules/@llblab/pi-actors/lib/recipes-usage.ts +638 -0
  289. package/node_modules/@llblab/pi-actors/lib/registry.ts +806 -0
  290. package/node_modules/@llblab/pi-actors/lib/review-control.ts +136 -0
  291. package/node_modules/@llblab/pi-actors/lib/review-diagnostics.ts +164 -0
  292. package/node_modules/@llblab/pi-actors/lib/review-projection.ts +196 -0
  293. package/node_modules/@llblab/pi-actors/lib/run-evidence-policy.ts +242 -0
  294. package/node_modules/@llblab/pi-actors/lib/run-ui-runtime.ts +155 -0
  295. package/node_modules/@llblab/pi-actors/lib/runs-artifacts.ts +96 -0
  296. package/node_modules/@llblab/pi-actors/lib/runs-control-delivery.ts +209 -0
  297. package/node_modules/@llblab/pi-actors/lib/runs-control.ts +148 -0
  298. package/node_modules/@llblab/pi-actors/lib/runs-controls.ts +282 -0
  299. package/node_modules/@llblab/pi-actors/lib/runs-identity.ts +14 -0
  300. package/node_modules/@llblab/pi-actors/lib/runs-index.ts +192 -0
  301. package/node_modules/@llblab/pi-actors/lib/runs-ownership.ts +136 -0
  302. package/node_modules/@llblab/pi-actors/lib/runs-parent-teardown.ts +257 -0
  303. package/node_modules/@llblab/pi-actors/lib/runs-process.ts +174 -0
  304. package/node_modules/@llblab/pi-actors/lib/runs-retention.ts +140 -0
  305. package/node_modules/@llblab/pi-actors/lib/runs-start.ts +113 -0
  306. package/node_modules/@llblab/pi-actors/lib/runs-status.ts +101 -0
  307. package/node_modules/@llblab/pi-actors/lib/runs-trace.ts +611 -0
  308. package/node_modules/@llblab/pi-actors/lib/runtime-identity.ts +39 -0
  309. package/node_modules/@llblab/pi-actors/lib/runtime-triage.ts +106 -0
  310. package/node_modules/@llblab/pi-actors/lib/runtime.ts +430 -0
  311. package/node_modules/@llblab/pi-actors/lib/schema.ts +525 -0
  312. package/node_modules/@llblab/pi-actors/lib/session-evidence.ts +302 -0
  313. package/node_modules/@llblab/pi-actors/lib/state-readers.ts +93 -0
  314. package/node_modules/@llblab/pi-actors/lib/temp.ts +99 -0
  315. package/node_modules/@llblab/pi-actors/lib/tool-review-lineage-transaction.ts +881 -0
  316. package/node_modules/@llblab/pi-actors/lib/tool-review-lineage.ts +145 -0
  317. package/node_modules/@llblab/pi-actors/lib/tool-review-scheduler.ts +635 -0
  318. package/node_modules/@llblab/pi-actors/lib/tool-review-transaction.ts +563 -0
  319. package/node_modules/@llblab/pi-actors/lib/tool-review.ts +270 -0
  320. package/node_modules/@llblab/pi-actors/lib/tools-access.ts +68 -0
  321. package/node_modules/@llblab/pi-actors/lib/tools-inspect.ts +673 -0
  322. package/node_modules/@llblab/pi-actors/lib/tools-local.ts +303 -0
  323. package/node_modules/@llblab/pi-actors/lib/tools-message.ts +176 -0
  324. package/node_modules/@llblab/pi-actors/lib/tools-register.ts +63 -0
  325. package/node_modules/@llblab/pi-actors/lib/tools-response.ts +285 -0
  326. package/node_modules/@llblab/pi-actors/lib/tools-spawn.ts +212 -0
  327. package/node_modules/@llblab/pi-actors/lib/tools.ts +88 -0
  328. package/node_modules/@llblab/pi-actors/lib/trace-projection.ts +306 -0
  329. package/node_modules/@llblab/pi-actors/package.json +76 -0
  330. package/node_modules/@llblab/pi-actors/scripts/async-runner.mjs +555 -0
  331. package/node_modules/@llblab/pi-actors/scripts/build-dist.mjs +60 -0
  332. package/node_modules/@llblab/pi-actors/scripts/conformance.mjs +63 -0
  333. package/node_modules/@llblab/pi-actors/skills/actors/SKILL.md +126 -0
  334. package/node_modules/@llblab/pi-actors/skills/actors/recipes/command-validate.json +13 -0
  335. package/node_modules/@llblab/pi-actors/skills/actors/recipes/jsonl-tail.json +10 -0
  336. package/node_modules/@llblab/pi-actors/skills/actors/recipes/recipe-validate.json +11 -0
  337. package/node_modules/@llblab/pi-actors/skills/actors/recipes/resource-locker-snapshot.json +11 -0
  338. package/node_modules/@llblab/pi-actors/skills/actors/recipes/resource-locker.json +25 -0
  339. package/node_modules/@llblab/pi-actors/skills/actors/recipes/run-ops-snapshot.json +15 -0
  340. package/node_modules/@llblab/pi-actors/skills/actors/recipes/run-state-files.json +13 -0
  341. package/node_modules/@llblab/pi-actors/skills/actors/recipes/run-summary.json +9 -0
  342. package/node_modules/@llblab/pi-actors/skills/actors/references/diagnostics.md +44 -0
  343. package/node_modules/@llblab/pi-actors/skills/actors/references/persistent-tools.md +76 -0
  344. package/node_modules/@llblab/pi-actors/skills/actors/references/recipes.md +51 -0
  345. package/node_modules/@llblab/pi-actors/skills/actors/references/runs.md +41 -0
  346. package/node_modules/@llblab/pi-actors/skills/actors/scripts/resource-locker.mjs +425 -0
  347. package/node_modules/@llblab/pi-actors/skills/actors/scripts/run-utils.mjs +164 -0
  348. package/node_modules/@llblab/pi-actors/skills/actors/scripts/validate-recipe.mjs +370 -0
  349. package/node_modules/@llblab/pi-actors/skills/artifacts/SKILL.md +33 -0
  350. package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/bundle.json +77 -0
  351. package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/file-write.json +14 -0
  352. package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/manifest.json +14 -0
  353. package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/report.json +39 -0
  354. package/node_modules/@llblab/pi-actors/skills/artifacts/recipes/write.json +53 -0
  355. package/node_modules/@llblab/pi-actors/skills/artifacts/scripts/artifact-utils.mjs +63 -0
  356. package/node_modules/@llblab/pi-actors/skills/music-player/SKILL.md +57 -0
  357. package/node_modules/@llblab/pi-actors/skills/music-player/genapps/music-player.mjs +360 -0
  358. package/node_modules/@llblab/pi-actors/skills/music-player/recipes/playback.json +29 -0
  359. package/node_modules/@llblab/pi-actors/skills/music-player/scripts/playback-client.mjs +143 -0
  360. package/node_modules/@llblab/pi-actors/skills/music-player/scripts/playback.mjs +1446 -0
  361. package/node_modules/@llblab/pi-actors/skills/project-work/SKILL.md +37 -0
  362. package/node_modules/@llblab/pi-actors/skills/project-work/recipes/changelog-head.json +11 -0
  363. package/node_modules/@llblab/pi-actors/skills/project-work/recipes/changelog-section.json +11 -0
  364. package/node_modules/@llblab/pi-actors/skills/project-work/recipes/docs-maintenance.json +66 -0
  365. package/node_modules/@llblab/pi-actors/skills/project-work/recipes/git-log.json +11 -0
  366. package/node_modules/@llblab/pi-actors/skills/project-work/recipes/git-status.json +9 -0
  367. package/node_modules/@llblab/pi-actors/skills/project-work/recipes/markdown-index.json +14 -0
  368. package/node_modules/@llblab/pi-actors/skills/project-work/recipes/package-summary.json +9 -0
  369. package/node_modules/@llblab/pi-actors/skills/project-work/recipes/release-readiness.json +115 -0
  370. package/node_modules/@llblab/pi-actors/skills/project-work/recipes/release-summary.json +74 -0
  371. package/node_modules/@llblab/pi-actors/skills/project-work/recipes/repo-health.json +75 -0
  372. package/node_modules/@llblab/pi-actors/skills/project-work/recipes/run-ops.json +56 -0
  373. package/node_modules/@llblab/pi-actors/skills/project-work/recipes/skill-summary.json +11 -0
  374. package/node_modules/@llblab/pi-actors/skills/project-work/scripts/project-utils.mjs +89 -0
  375. package/node_modules/@llblab/pi-actors/skills/recipe-memory/SKILL.md +36 -0
  376. package/node_modules/@llblab/pi-actors/skills/recipe-memory/recipes/draft-review.json +14 -0
  377. package/node_modules/@llblab/pi-actors/skills/recipe-memory/recipes/tool-review.json +14 -0
  378. package/node_modules/@llblab/pi-actors/skills/swarm/SKILL.md +84 -0
  379. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/architect.json +82 -0
  380. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/checkpoint-continuation.json +51 -0
  381. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/development-tasking.json +67 -0
  382. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/lens-review.json +63 -0
  383. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/quorum-review.json +65 -0
  384. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/research-synthesis.json +81 -0
  385. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/review-readiness.json +59 -0
  386. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-artifact.json +21 -0
  387. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-checkpoint.json +21 -0
  388. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-conflict-report.json +19 -0
  389. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-contradiction-map.json +20 -0
  390. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-critic.json +22 -0
  391. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-evidence-map.json +20 -0
  392. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-followup.json +21 -0
  393. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-judge.json +22 -0
  394. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-merge.json +24 -0
  395. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-normalize.json +20 -0
  396. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-plan.json +20 -0
  397. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-preflight.json +18 -0
  398. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-prompt.json +16 -0
  399. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-prompts.json +39 -0
  400. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-quorum.json +31 -0
  401. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-review-coordinator.json +170 -0
  402. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-review.json +26 -0
  403. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-task-card.json +22 -0
  404. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-tools.json +15 -0
  405. package/node_modules/@llblab/pi-actors/skills/swarm/recipes/subagent-verify.json +23 -0
  406. package/node_modules/@llblab/pi-actors/skills/swarm/references/development-swarm.md +189 -0
  407. package/node_modules/@llblab/pi-actors/skills/swarm/references/review-swarms.md +115 -0
  408. package/node_modules/@llblab/pi-codex-usage/AGENTS.md +17 -0
  409. package/node_modules/@llblab/pi-codex-usage/BACKLOG.md +8 -0
  410. package/node_modules/@llblab/pi-codex-usage/CHANGELOG.md +80 -0
  411. package/node_modules/@llblab/pi-codex-usage/LICENSE +22 -0
  412. package/node_modules/@llblab/pi-codex-usage/README.md +113 -0
  413. package/node_modules/@llblab/pi-codex-usage/banner.jpg +0 -0
  414. package/node_modules/@llblab/pi-codex-usage/index.ts +1525 -0
  415. package/node_modules/@llblab/pi-codex-usage/package.json +59 -0
  416. package/node_modules/@llblab/pi-grow-loop/AGENTS.md +56 -0
  417. package/node_modules/@llblab/pi-grow-loop/BACKLOG.md +3 -0
  418. package/node_modules/@llblab/pi-grow-loop/CHANGELOG.md +126 -0
  419. package/node_modules/@llblab/pi-grow-loop/README.md +216 -0
  420. package/node_modules/@llblab/pi-grow-loop/banner.jpg +0 -0
  421. package/node_modules/@llblab/pi-grow-loop/index.ts +219 -0
  422. package/node_modules/@llblab/pi-grow-loop/package.json +64 -0
  423. package/node_modules/@llblab/pi-grow-loop/skills/grow-loop/SKILL.md +131 -0
  424. package/node_modules/@llblab/pi-grow-loop/skills/while-true/SKILL.md +233 -0
  425. package/node_modules/@llblab/pi-telegram/AGENTS.md +157 -0
  426. package/node_modules/@llblab/pi-telegram/BACKLOG.md +15 -0
  427. package/node_modules/@llblab/pi-telegram/CHANGELOG.md +886 -0
  428. package/node_modules/@llblab/pi-telegram/README.md +330 -0
  429. package/node_modules/@llblab/pi-telegram/api/activity.ts +15 -0
  430. package/node_modules/@llblab/pi-telegram/api/commands.ts +11 -0
  431. package/node_modules/@llblab/pi-telegram/api/delivery.ts +21 -0
  432. package/node_modules/@llblab/pi-telegram/api/inbound.ts +14 -0
  433. package/node_modules/@llblab/pi-telegram/api/keyboard.ts +11 -0
  434. package/node_modules/@llblab/pi-telegram/api/outbound.ts +11 -0
  435. package/node_modules/@llblab/pi-telegram/api/sections.ts +17 -0
  436. package/node_modules/@llblab/pi-telegram/api/status.ts +12 -0
  437. package/node_modules/@llblab/pi-telegram/api/updates.ts +16 -0
  438. package/node_modules/@llblab/pi-telegram/api/voice.ts +24 -0
  439. package/node_modules/@llblab/pi-telegram/docs/README.md +25 -0
  440. package/node_modules/@llblab/pi-telegram/docs/activity.md +304 -0
  441. package/node_modules/@llblab/pi-telegram/docs/architecture.md +418 -0
  442. package/node_modules/@llblab/pi-telegram/docs/callback-namespaces.md +48 -0
  443. package/node_modules/@llblab/pi-telegram/docs/command-templates.md +365 -0
  444. package/node_modules/@llblab/pi-telegram/docs/compact-matrix-literal.md +176 -0
  445. package/node_modules/@llblab/pi-telegram/docs/delivery.md +225 -0
  446. package/node_modules/@llblab/pi-telegram/docs/generative-apps.md +310 -0
  447. package/node_modules/@llblab/pi-telegram/docs/inbound.md +136 -0
  448. package/node_modules/@llblab/pi-telegram/docs/multi-instance-bus.md +467 -0
  449. package/node_modules/@llblab/pi-telegram/docs/outbound.md +193 -0
  450. package/node_modules/@llblab/pi-telegram/docs/public-api.md +599 -0
  451. package/node_modules/@llblab/pi-telegram/docs/sections.md +452 -0
  452. package/node_modules/@llblab/pi-telegram/docs/ui-style.md +256 -0
  453. package/node_modules/@llblab/pi-telegram/docs/updates.md +171 -0
  454. package/node_modules/@llblab/pi-telegram/docs/voice.md +217 -0
  455. package/node_modules/@llblab/pi-telegram/index.ts +1336 -0
  456. package/node_modules/@llblab/pi-telegram/lib/activity-verbosity.ts +714 -0
  457. package/node_modules/@llblab/pi-telegram/lib/activity.ts +782 -0
  458. package/node_modules/@llblab/pi-telegram/lib/agent-messages.ts +121 -0
  459. package/node_modules/@llblab/pi-telegram/lib/bindings.ts +1129 -0
  460. package/node_modules/@llblab/pi-telegram/lib/bus-api.ts +379 -0
  461. package/node_modules/@llblab/pi-telegram/lib/bus-follower.ts +1941 -0
  462. package/node_modules/@llblab/pi-telegram/lib/bus-leader.ts +2119 -0
  463. package/node_modules/@llblab/pi-telegram/lib/bus-transport.ts +244 -0
  464. package/node_modules/@llblab/pi-telegram/lib/bus.ts +2645 -0
  465. package/node_modules/@llblab/pi-telegram/lib/command-templates.ts +954 -0
  466. package/node_modules/@llblab/pi-telegram/lib/commands.ts +1854 -0
  467. package/node_modules/@llblab/pi-telegram/lib/config.ts +1143 -0
  468. package/node_modules/@llblab/pi-telegram/lib/delivery.ts +891 -0
  469. package/node_modules/@llblab/pi-telegram/lib/generative-app-worker.mjs +104 -0
  470. package/node_modules/@llblab/pi-telegram/lib/generative-apps.ts +958 -0
  471. package/node_modules/@llblab/pi-telegram/lib/inbound.ts +824 -0
  472. package/node_modules/@llblab/pi-telegram/lib/journal.ts +3140 -0
  473. package/node_modules/@llblab/pi-telegram/lib/keyboard.ts +59 -0
  474. package/node_modules/@llblab/pi-telegram/lib/lifecycle.ts +623 -0
  475. package/node_modules/@llblab/pi-telegram/lib/locks.ts +1422 -0
  476. package/node_modules/@llblab/pi-telegram/lib/logs.ts +393 -0
  477. package/node_modules/@llblab/pi-telegram/lib/media.ts +921 -0
  478. package/node_modules/@llblab/pi-telegram/lib/menu-model.ts +1182 -0
  479. package/node_modules/@llblab/pi-telegram/lib/menu-queue.ts +926 -0
  480. package/node_modules/@llblab/pi-telegram/lib/menu-settings.ts +876 -0
  481. package/node_modules/@llblab/pi-telegram/lib/menu-status.ts +274 -0
  482. package/node_modules/@llblab/pi-telegram/lib/menu-thinking.ts +185 -0
  483. package/node_modules/@llblab/pi-telegram/lib/menu.ts +867 -0
  484. package/node_modules/@llblab/pi-telegram/lib/model.ts +672 -0
  485. package/node_modules/@llblab/pi-telegram/lib/outbound-attachments.ts +981 -0
  486. package/node_modules/@llblab/pi-telegram/lib/outbound-buttons.ts +331 -0
  487. package/node_modules/@llblab/pi-telegram/lib/outbound-markup.ts +515 -0
  488. package/node_modules/@llblab/pi-telegram/lib/outbound-voice.ts +285 -0
  489. package/node_modules/@llblab/pi-telegram/lib/outbound.ts +1007 -0
  490. package/node_modules/@llblab/pi-telegram/lib/ownership.ts +298 -0
  491. package/node_modules/@llblab/pi-telegram/lib/paths.ts +127 -0
  492. package/node_modules/@llblab/pi-telegram/lib/pi.ts +197 -0
  493. package/node_modules/@llblab/pi-telegram/lib/polling.ts +1588 -0
  494. package/node_modules/@llblab/pi-telegram/lib/preview.ts +846 -0
  495. package/node_modules/@llblab/pi-telegram/lib/prompt-templates.ts +158 -0
  496. package/node_modules/@llblab/pi-telegram/lib/prompts.ts +218 -0
  497. package/node_modules/@llblab/pi-telegram/lib/queue.ts +3075 -0
  498. package/node_modules/@llblab/pi-telegram/lib/recovery.ts +464 -0
  499. package/node_modules/@llblab/pi-telegram/lib/rendering.ts +1213 -0
  500. package/node_modules/@llblab/pi-telegram/lib/replies.ts +892 -0
  501. package/node_modules/@llblab/pi-telegram/lib/routing.ts +2889 -0
  502. package/node_modules/@llblab/pi-telegram/lib/runtime.ts +628 -0
  503. package/node_modules/@llblab/pi-telegram/lib/sections.ts +710 -0
  504. package/node_modules/@llblab/pi-telegram/lib/setup.ts +220 -0
  505. package/node_modules/@llblab/pi-telegram/lib/skills.ts +21 -0
  506. package/node_modules/@llblab/pi-telegram/lib/status.ts +1550 -0
  507. package/node_modules/@llblab/pi-telegram/lib/sync.ts +883 -0
  508. package/node_modules/@llblab/pi-telegram/lib/target.ts +49 -0
  509. package/node_modules/@llblab/pi-telegram/lib/telegram-api.ts +1747 -0
  510. package/node_modules/@llblab/pi-telegram/lib/text-groups.ts +487 -0
  511. package/node_modules/@llblab/pi-telegram/lib/thread-reconciler.ts +1002 -0
  512. package/node_modules/@llblab/pi-telegram/lib/threads.ts +3183 -0
  513. package/node_modules/@llblab/pi-telegram/lib/time-injection.ts +78 -0
  514. package/node_modules/@llblab/pi-telegram/lib/turns.ts +753 -0
  515. package/node_modules/@llblab/pi-telegram/lib/updates.ts +4950 -0
  516. package/node_modules/@llblab/pi-telegram/lib/voice.ts +340 -0
  517. package/node_modules/@llblab/pi-telegram/package.json +83 -0
  518. package/node_modules/@llblab/pi-telegram/screenshot.png +0 -0
  519. package/node_modules/@llblab/pi-telegram/scripts/check-downgrade.mjs +435 -0
  520. package/node_modules/@llblab/pi-telegram/skills/generated-control-surface/SKILL.md +241 -0
  521. package/node_modules/@llblab/pi-telegram/skills/generative-apps/SKILL.md +114 -0
  522. package/node_modules/@llblab/pi-telegram/skills/telegram-bridge/SKILL.md +149 -0
  523. package/package.json +67 -0
@@ -0,0 +1,1245 @@
1
+ /**
2
+ * Command-template async run lifecycle facade.
3
+ * Owns: launch, state observation, listing, message/control facade methods, and retention while runs-* subdomains own narrower run internals.
4
+ */
5
+
6
+ import { spawn } from "node:child_process";
7
+ import { randomUUID } from "node:crypto";
8
+ import {
9
+ closeSync,
10
+ existsSync,
11
+ mkdirSync,
12
+ openSync,
13
+ readFileSync,
14
+ readdirSync,
15
+ rmSync,
16
+ statSync,
17
+ writeFileSync,
18
+ } from "node:fs";
19
+ import { basename, dirname, extname, isAbsolute, join, relative, resolve } from "node:path";
20
+ import { fileURLToPath } from "node:url";
21
+ import { isDeepStrictEqual } from "node:util";
22
+
23
+ import type {
24
+ CommandTemplateFailureScope,
25
+ CommandTemplateValue,
26
+ } from "./command-templates.ts";
27
+ import { writeJsonAtomic } from "./file-state.ts";
28
+ import {
29
+ CURRENT_MODEL_VALUE_KEY,
30
+ CURRENT_THINKING_VALUE_KEY,
31
+ describeCurrentPolicyProvenance,
32
+ type CurrentPolicyProvenance,
33
+ } from "./model-context.ts";
34
+ import * as Paths from "./paths.ts";
35
+ import * as RecipesReferences from "./recipes-references.ts";
36
+ import * as RecipesUsage from "./recipes-usage.ts";
37
+ import * as Schema from "./schema.ts";
38
+ import {
39
+ resolveArtifactManifest,
40
+ resolveArtifactPaths,
41
+ type RunArtifactDeclaration,
42
+ type RunArtifactManifestEntry,
43
+ } from "./runs-artifacts.ts";
44
+ import { safeRunId } from "./runs-identity.ts";
45
+ import {
46
+ buildTerminalProgress,
47
+ getRunProcessSignalPlan,
48
+ markTerminalHandled,
49
+ signalOwnedRunProcess,
50
+ type RunProcessSignalPlan,
51
+ } from "./runs-control.ts";
52
+ import { claimRunStateDirectory } from "./runs-ownership.ts";
53
+ import {
54
+ appendRunRetentionEvidence,
55
+ archiveTerminalRun,
56
+ pruneTerminalRun,
57
+ type RunRetentionAction,
58
+ } from "./runs-retention.ts";
59
+ import {
60
+ captureRunProcessIdentity,
61
+ verifyRunProcessIdentity,
62
+ type RunProcessIdentity,
63
+ } from "./runs-process.ts";
64
+ import * as RuntimeIdentity from "./runtime-identity.ts";
65
+ import * as RunsStart from "./runs-start.ts";
66
+ import { appendRunTraceEvent } from "./runs-trace.ts";
67
+ import * as RunsIndex from "./runs-index.ts";
68
+ import * as RunsParentTeardown from "./runs-parent-teardown.ts";
69
+ import {
70
+ deliverRunControl,
71
+ type DeliverRunControlOptions,
72
+ type DeliverRunControlRequest,
73
+ } from "./runs-control-delivery.ts";
74
+ import {
75
+ buildRunStatus,
76
+ tailFile,
77
+ type AsyncRunStatus,
78
+ } from "./runs-status.ts";
79
+ import { readJsonFileResilient } from "./state-readers.ts";
80
+
81
+ const RUNNER_IDENTITY_GRACE_MS = 5000;
82
+
83
+ export type AsyncRunLaunchSource = "spawn" | "tool";
84
+
85
+ export interface AsyncRunControlEndpoint {
86
+ path: string;
87
+ type: "fifo" | "named-pipe";
88
+ }
89
+
90
+ export function normalizeRunTransportContext(
91
+ value: unknown,
92
+ ): Record<string, string | number | boolean> | undefined {
93
+ if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
94
+ const normalized: Record<string, string | number | boolean> = {};
95
+ for (const [key, item] of Object.entries(
96
+ value as Record<string, unknown>,
97
+ ).slice(0, 16)) {
98
+ const safeKey = key.trim().slice(0, 64);
99
+ if (!safeKey) continue;
100
+ if (typeof item === "string") {
101
+ normalized[safeKey] = item.trim().slice(0, 256);
102
+ continue;
103
+ }
104
+ if (typeof item === "number" && Number.isFinite(item)) {
105
+ normalized[safeKey] = item;
106
+ continue;
107
+ }
108
+ if (typeof item === "boolean") normalized[safeKey] = item;
109
+ }
110
+ return Object.keys(normalized).length ? normalized : undefined;
111
+ }
112
+
113
+ export interface AsyncRunStartParams {
114
+ async?: boolean;
115
+ control_endpoint?: AsyncRunControlEndpoint;
116
+ file?: string;
117
+ launch_source?: AsyncRunLaunchSource;
118
+ lifecycleHooks?: {
119
+ onLockContention?(): void;
120
+ };
121
+ launch_correlation?: {
122
+ correlation_id?: string;
123
+ tool_call_id?: string;
124
+ };
125
+ name?: string;
126
+ ownerId?: string;
127
+ run_id?: string;
128
+ singleton?: boolean;
129
+ singleton_run_id?: string;
130
+ singleton_recipe_id?: string;
131
+ state_dir?: string;
132
+ tool?: string;
133
+ template?: CommandTemplateValue;
134
+ args?: string[];
135
+ defaults?: Record<string, unknown>;
136
+ recipe_dir?: string;
137
+ skill_dir?: string;
138
+ parallel?: boolean;
139
+ concurrency?: number | string;
140
+ min_successful?: number | string;
141
+ label?: string;
142
+ when?: boolean | string;
143
+ timeout?: number | string;
144
+ delay?: number | string;
145
+ accept_output?: "review_evidence";
146
+ output?: string;
147
+ artifacts?: Record<string, RunArtifactDeclaration>;
148
+ control?: string[];
149
+ notification_policy?: "normal" | "silent";
150
+ retire_when?: "children_terminal";
151
+ retry?: number | string;
152
+ failure?: CommandTemplateFailureScope;
153
+ recover?: CommandTemplateValue;
154
+ transport_context?: Record<string, unknown>;
155
+ repeat?: number;
156
+ values?: Record<string, unknown>;
157
+ policy_values?: Record<string, unknown>;
158
+ actor_context?: boolean | string;
159
+ cwd?: string;
160
+ }
161
+
162
+ export type { AsyncRunStatus } from "./runs-status.ts";
163
+
164
+ export interface AsyncRunMeta {
165
+ argv: string[];
166
+ createdAt: string;
167
+ cwd: string;
168
+ launch_kind?: AsyncRunLaunchSource;
169
+ launch_source?: AsyncRunLaunchSource;
170
+ launch_correlation?: {
171
+ correlation_id?: string;
172
+ tool_call_id?: string;
173
+ };
174
+ ownerId?: string;
175
+ pid: number;
176
+ recipe?: string;
177
+ recipe_file?: string;
178
+ run: string;
179
+ run_instance_id: string;
180
+ state_dir: string;
181
+ state_schema: typeof RuntimeIdentity.RUN_STATE_SCHEMA;
182
+ status: AsyncRunStatus;
183
+ tool?: string;
184
+ template: CommandTemplateValue;
185
+ values: Record<string, unknown>;
186
+ artifacts?: Record<string, RunArtifactDeclaration>;
187
+ control?: string[];
188
+ control_endpoint?: AsyncRunControlEndpoint;
189
+ model_policy?: CurrentPolicyProvenance;
190
+ notification_policy?: "normal" | "silent";
191
+ process_identity?: RunProcessIdentity;
192
+ recipe_context_records?: RecipesReferences.TemplateRecipeContextRecord[];
193
+ retire_when?: "children_terminal";
194
+ reused?: boolean;
195
+ singleton?: boolean;
196
+ singleton_recipe_id?: string;
197
+ singleton_values?: Record<string, unknown>;
198
+ transport_context?: Record<string, unknown>;
199
+ }
200
+
201
+ const DEFAULT_STATE_ROOT = Paths.getRunStateRoot();
202
+ const DEFAULT_RECIPE_ROOT = Paths.getRecipeRoot();
203
+
204
+ function packageRoot(): string {
205
+ const moduleDir = dirname(fileURLToPath(import.meta.url));
206
+ if (
207
+ basename(moduleDir) === "lib" &&
208
+ basename(dirname(moduleDir)) === "dist"
209
+ ) {
210
+ return dirname(dirname(moduleDir));
211
+ }
212
+ return dirname(moduleDir);
213
+ }
214
+
215
+ const PACKAGE_ROOT = packageRoot();
216
+ const RUNNER_PATH = join(PACKAGE_ROOT, "scripts", "async-runner.mjs");
217
+
218
+ function asyncRunnerArgv(stateDir: string): string[] {
219
+ return existsSync(join(PACKAGE_ROOT, "dist", "lib", "execution.js"))
220
+ ? [RUNNER_PATH, stateDir]
221
+ : ["--experimental-strip-types", RUNNER_PATH, stateDir];
222
+ }
223
+
224
+ export { safeRunId } from "./runs-identity.ts";
225
+
226
+ export { resolveArtifactManifest } from "./runs-artifacts.ts";
227
+ export type {
228
+ RunArtifactDeclaration,
229
+ RunArtifactManifestEntry,
230
+ } from "./runs-artifacts.ts";
231
+
232
+ function resolveRunTemplate(params: AsyncRunStartParams): {
233
+ template: CommandTemplateValue;
234
+ } {
235
+ if (!params.template) throw new Error("spawn requires file or template.");
236
+ const envelope: Record<string, unknown> = {};
237
+ for (const key of [
238
+ "args",
239
+ "defaults",
240
+ "parallel",
241
+ "concurrency",
242
+ "min_successful",
243
+ "label",
244
+ "when",
245
+ "timeout",
246
+ "delay",
247
+ "accept_output",
248
+ "output",
249
+ "retry",
250
+ "failure",
251
+ "recover",
252
+ "repeat",
253
+ ] as const) {
254
+ if (params[key] !== undefined) envelope[key] = params[key];
255
+ }
256
+ if (Object.keys(envelope).length === 0) return { template: params.template };
257
+ if (typeof params.template === "object" && !Array.isArray(params.template)) {
258
+ return { template: { ...envelope, ...params.template } };
259
+ }
260
+ return { template: { ...envelope, template: params.template } };
261
+ }
262
+
263
+ function resolveStateDir(params: AsyncRunStartParams, run: string): string {
264
+ return resolve(params.state_dir || join(DEFAULT_STATE_ROOT, run));
265
+ }
266
+
267
+ function assertNoActiveRunState(stateDir: string): void {
268
+ RunsStart.assertNoActiveRunState(stateDir, readJson, RUNNER_PATH);
269
+ }
270
+
271
+ function reuseCompatibleSingletonRun(
272
+ stateDir: string,
273
+ startParams: AsyncRunStartParams,
274
+ singletonValues: Record<string, unknown>,
275
+ ): AsyncRunMeta | undefined {
276
+ const existing = RunsStart.readActiveOwnedRunState(
277
+ stateDir,
278
+ readJson,
279
+ RUNNER_PATH,
280
+ );
281
+ if (!existing) return undefined;
282
+ const compatible =
283
+ existing.singleton === true &&
284
+ existing.singleton_recipe_id === startParams.singleton_recipe_id &&
285
+ existing.ownerId === startParams.ownerId &&
286
+ isDeepStrictEqual(existing.singleton_values ?? {}, singletonValues) &&
287
+ isDeepStrictEqual(existing.control ?? [], startParams.control ?? []);
288
+ if (!compatible) {
289
+ throw new Error(
290
+ `Active singleton Run ${String(existing.run ?? stateDir)} has incompatible Recipe identity, owner, startup values, or Control contract. Stop it before changing singleton configuration.`,
291
+ );
292
+ }
293
+ return {
294
+ ...(existing as unknown as AsyncRunMeta),
295
+ ...(startParams.launch_source
296
+ ? {
297
+ launch_kind: startParams.launch_source,
298
+ launch_source: startParams.launch_source,
299
+ }
300
+ : {}),
301
+ ...(startParams.launch_correlation
302
+ ? { launch_correlation: startParams.launch_correlation }
303
+ : {}),
304
+ reused: true,
305
+ };
306
+ }
307
+
308
+ export interface AsyncRunStartOptions {
309
+ skillContext?: RecipesReferences.ActiveSkillRecipeContext;
310
+ }
311
+
312
+ function resolveRecipeFile(
313
+ file: string,
314
+ cwd: string,
315
+ options: AsyncRunStartOptions,
316
+ ): string {
317
+ const path = RecipesReferences.resolveRecipeReferencePath(
318
+ file,
319
+ cwd,
320
+ options.skillContext,
321
+ );
322
+ if (path) return path;
323
+ throw new Error(
324
+ `Recipe reference not found. Use <skill>/<recipe> or an explicit .json/.md file path: ${file}`,
325
+ );
326
+ }
327
+
328
+ function isMutableUsageRecipeFile(file: string): boolean {
329
+ const userRoot = resolve(DEFAULT_RECIPE_ROOT);
330
+ const resolved = resolve(file);
331
+ const relation = relative(userRoot, resolved);
332
+ return relation !== "" && !relation.startsWith("..") && !isAbsolute(relation);
333
+ }
334
+
335
+ function readRecipeFile(
336
+ file: string,
337
+ cwd: string,
338
+ options: AsyncRunStartOptions,
339
+ ): AsyncRunStartParams {
340
+ const path = resolveRecipeFile(file, cwd, options);
341
+ const raw = RecipesReferences.readRawRecipeConfig(path);
342
+ const includeActorRecipeContext =
343
+ raw?.actor_context !== false && raw?.actor_context !== "off";
344
+ const config = RecipesReferences.readResolvedRecipeConfig(path, [], {
345
+ includeActorRecipeContext,
346
+ skillContext: options.skillContext,
347
+ });
348
+ if (!config) {
349
+ throw new Error(`Template recipe must define template: ${path}`);
350
+ }
351
+ if (config.disabled === true) {
352
+ throw new Error(`Template recipe is disabled: ${path}`);
353
+ }
354
+ return {
355
+ ...(config as AsyncRunStartParams),
356
+ file: path,
357
+ ...(includeActorRecipeContext ? {} : { actor_context: false }),
358
+ };
359
+ }
360
+
361
+ function getRunIdFromFile(file: string | undefined): string | undefined {
362
+ if (!file) return undefined;
363
+ const name = basename(file, extname(file));
364
+ return name || undefined;
365
+ }
366
+
367
+ function resolveStartParams(
368
+ params: AsyncRunStartParams,
369
+ cwd: string,
370
+ options: AsyncRunStartOptions,
371
+ ): AsyncRunStartParams {
372
+ if (!params.file) return params;
373
+ const fileParams = readRecipeFile(params.file, cwd, options);
374
+ const singleton = fileParams.singleton === true;
375
+ if (singleton && fileParams.async !== true) {
376
+ throw new Error("singleton Recipes must declare async: true");
377
+ }
378
+ if (singleton && (!fileParams.singleton_run_id || !fileParams.singleton_recipe_id)) {
379
+ throw new Error("singleton Recipes must resolve one active Skill-owned singleton identity");
380
+ }
381
+ const singletonRun = singleton ? fileParams.singleton_run_id : undefined;
382
+ if (singletonRun && params.run_id && params.run_id !== singletonRun) {
383
+ throw new Error(
384
+ `singleton Recipe run identity is run:${singletonRun}; received run:${params.run_id}`,
385
+ );
386
+ }
387
+ return {
388
+ ...fileParams,
389
+ ...params,
390
+ ...(singleton ? { singleton: true } : {}),
391
+ run_id:
392
+ singletonRun ||
393
+ params.run_id ||
394
+ fileParams.run_id ||
395
+ fileParams.name ||
396
+ getRunIdFromFile(fileParams.file),
397
+ values: {
398
+ ...(fileParams.values ?? {}),
399
+ ...(params.values ?? {}),
400
+ ...(fileParams.recipe_dir
401
+ ? { recipe_dir: fileParams.recipe_dir }
402
+ : {}),
403
+ ...(fileParams.skill_dir ? { skill_dir: fileParams.skill_dir } : {}),
404
+ },
405
+ };
406
+ }
407
+
408
+ function readJson(path: string): Record<string, unknown> | undefined {
409
+ return readJsonFileResilient<Record<string, unknown> | undefined>(
410
+ path,
411
+ undefined,
412
+ ).value;
413
+ }
414
+
415
+ function isRecord(value: unknown): value is Record<string, unknown> {
416
+ return Boolean(value && typeof value === "object" && !Array.isArray(value));
417
+ }
418
+
419
+ function isFalsyValue(value: unknown): boolean {
420
+ if (value === undefined || value === null || value === false) return true;
421
+ const normalized = String(value).trim().toLowerCase();
422
+ return (
423
+ normalized === "" ||
424
+ normalized === "0" ||
425
+ normalized === "false" ||
426
+ normalized === "no"
427
+ );
428
+ }
429
+
430
+ function stringReferencesPlaceholder(
431
+ value: string,
432
+ placeholder: string,
433
+ ): boolean {
434
+ return new RegExp(`\\{\\s*${placeholder}\\s*\\}`).test(value);
435
+ }
436
+
437
+ function collectUnresolvedCurrentPlaceholderReferences(
438
+ value: unknown,
439
+ values: Record<string, unknown>,
440
+ placeholder: string,
441
+ valueKey: string,
442
+ path = "template",
443
+ refs: string[] = [],
444
+ ): string[] {
445
+ if (typeof value === "string") {
446
+ if (
447
+ stringReferencesPlaceholder(value, placeholder) &&
448
+ isFalsyValue(values[valueKey])
449
+ ) {
450
+ refs.push(path);
451
+ }
452
+ return refs;
453
+ }
454
+ if (Array.isArray(value)) {
455
+ value.forEach((item, index) =>
456
+ collectUnresolvedCurrentPlaceholderReferences(
457
+ item,
458
+ values,
459
+ placeholder,
460
+ valueKey,
461
+ `${path}[${index}]`,
462
+ refs,
463
+ ),
464
+ );
465
+ return refs;
466
+ }
467
+ if (!isRecord(value)) return refs;
468
+ for (const [key, child] of Object.entries(value)) {
469
+ if (key === "defaults" && isRecord(child)) {
470
+ for (const [defaultKey, defaultValue] of Object.entries(child)) {
471
+ if (
472
+ typeof defaultValue === "string" &&
473
+ stringReferencesPlaceholder(defaultValue, placeholder) &&
474
+ isFalsyValue(values[defaultKey]) &&
475
+ isFalsyValue(values[valueKey])
476
+ ) {
477
+ refs.push(`${path}.defaults.${defaultKey}`);
478
+ }
479
+ }
480
+ continue;
481
+ }
482
+ collectUnresolvedCurrentPlaceholderReferences(
483
+ child,
484
+ values,
485
+ placeholder,
486
+ valueKey,
487
+ `${path}.${key}`,
488
+ refs,
489
+ );
490
+ }
491
+ return refs;
492
+ }
493
+
494
+ function assertCurrentPlaceholderReferencesResolved(
495
+ template: CommandTemplateValue,
496
+ defaults: Record<string, unknown> | undefined,
497
+ values: Record<string, unknown>,
498
+ modelPolicy: CurrentPolicyProvenance,
499
+ ): void {
500
+ const checks = [
501
+ {
502
+ label: "model",
503
+ placeholder: "current_model",
504
+ valueKey: CURRENT_MODEL_VALUE_KEY,
505
+ },
506
+ {
507
+ label: "thinking level",
508
+ placeholder: "current_thinking",
509
+ valueKey: CURRENT_THINKING_VALUE_KEY,
510
+ },
511
+ ];
512
+ for (const check of checks) {
513
+ const refs = collectUnresolvedCurrentPlaceholderReferences(
514
+ template,
515
+ values,
516
+ check.placeholder,
517
+ check.valueKey,
518
+ );
519
+ if (defaults) {
520
+ collectUnresolvedCurrentPlaceholderReferences(
521
+ { defaults },
522
+ values,
523
+ check.placeholder,
524
+ check.valueKey,
525
+ "recipe",
526
+ refs,
527
+ );
528
+ }
529
+ if (refs.length === 0) continue;
530
+ throw Object.assign(
531
+ new Error(
532
+ `Template recipe requires the current Pi ${check.label} for inheritance, but no current ${check.label} was available. Pass explicit values or launch from a Pi session with a selected ${check.label}. unresolved=${refs.slice(0, 4).join(",")}`,
533
+ ),
534
+ { model_policy: modelPolicy },
535
+ );
536
+ }
537
+ }
538
+
539
+ function acquireStateStartLock(
540
+ stateDir: string,
541
+ options: import("./file-state.ts").FileMutationLockOptions = {},
542
+ ): () => void {
543
+ return RunsStart.acquireStateStartLock(stateDir, options);
544
+ }
545
+
546
+ function prepareStateDirForStart(stateDir: string): void {
547
+ RunsStart.prepareStateDirForStart(stateDir, readJson, RUNNER_PATH);
548
+ }
549
+
550
+ export function startRun(
551
+ params: AsyncRunStartParams,
552
+ cwd: string,
553
+ options: AsyncRunStartOptions = {},
554
+ ): AsyncRunMeta {
555
+ const startParams = resolveStartParams(params, cwd, options);
556
+ const resolved = resolveRunTemplate(startParams);
557
+ const run = safeRunId(startParams.run_id);
558
+ const stateDir = resolveStateDir(startParams, run);
559
+ const recipeFile = startParams.file
560
+ ? resolveRecipeFile(startParams.file, cwd, options)
561
+ : undefined;
562
+ const argSpec = Schema.parseToolArgDeclarationList(startParams.args ?? []);
563
+ if (argSpec.error) throw new Error(argSpec.error);
564
+ const declaredArgs = new Set(argSpec.args);
565
+ for (const key of Object.keys(startParams.defaults ?? {})) {
566
+ if (declaredArgs.size > 0 && !declaredArgs.has(key))
567
+ throw new Error(`Unknown Recipe default argument: ${key}`);
568
+ }
569
+ const values = Schema.normalizeRuntimeValues(
570
+ {
571
+ ...argSpec.defaults,
572
+ ...(startParams.defaults || {}),
573
+ ...(startParams.values || {}),
574
+ run_id: run,
575
+ state_dir: stateDir,
576
+ trace_file: join(stateDir, "trace.jsonl"),
577
+ },
578
+ argSpec.argTypes,
579
+ );
580
+ const runtimeTemplate =
581
+ resolved.template &&
582
+ typeof resolved.template === "object" &&
583
+ !Array.isArray(resolved.template)
584
+ ? {
585
+ ...resolved.template,
586
+ defaults: {
587
+ ...(resolved.template.defaults ?? {}),
588
+ ...values,
589
+ },
590
+ }
591
+ : resolved.template;
592
+ const modelPolicy = describeCurrentPolicyProvenance({
593
+ defaults: startParams.defaults,
594
+ template: resolved.template,
595
+ values: startParams.policy_values ?? startParams.values ?? {},
596
+ });
597
+ assertCurrentPlaceholderReferencesResolved(
598
+ resolved.template,
599
+ startParams.defaults,
600
+ values,
601
+ modelPolicy,
602
+ );
603
+ const singletonValues = Object.fromEntries(
604
+ [...declaredArgs].map((key) => [key, values[key]]),
605
+ );
606
+ if (startParams.singleton !== true) assertNoActiveRunState(stateDir);
607
+ mkdirSync(stateDir, { recursive: true });
608
+ const releaseStartLock = acquireStateStartLock(stateDir, {
609
+ onContention: startParams.lifecycleHooks?.onLockContention,
610
+ });
611
+ try {
612
+ claimRunStateDirectory(stateDir, run);
613
+ if (
614
+ recipeFile &&
615
+ isMutableUsageRecipeFile(recipeFile) &&
616
+ !RecipesUsage.recordRecipeLaunch(
617
+ recipeFile,
618
+ new Date(),
619
+ startParams.launch_source === "tool" ? "tool" : "spawn",
620
+ )
621
+ ) {
622
+ throw new Error(
623
+ `Recipe launch rejected because its source changed during activation: ${recipeFile}. Reload recipe tools and retry.`,
624
+ );
625
+ }
626
+ if (startParams.singleton === true) {
627
+ const existing = reuseCompatibleSingletonRun(
628
+ stateDir,
629
+ startParams,
630
+ singletonValues,
631
+ );
632
+ if (existing) return existing;
633
+ } else assertNoActiveRunState(stateDir);
634
+ prepareStateDirForStart(stateDir);
635
+ const stdout = join(stateDir, "stdout.log");
636
+ const stderr = join(stateDir, "stderr.log");
637
+ const recipe = startParams.name || getRunIdFromFile(recipeFile);
638
+ const includeActorRecipeContext =
639
+ startParams.actor_context !== false &&
640
+ startParams.actor_context !== "off";
641
+ const recipeContextRecords =
642
+ recipeFile && includeActorRecipeContext
643
+ ? RecipesReferences.buildRecipeContextRecords(
644
+ recipeFile,
645
+ options.skillContext,
646
+ ).map((record, index) =>
647
+ index === 0 &&
648
+ startParams.launch_source === "tool" &&
649
+ record.source_kind === "explicit_file_recipe"
650
+ ? {
651
+ ...record,
652
+ logical_reference: record.name,
653
+ source_kind: "user_registry_capability" as const,
654
+ }
655
+ : record,
656
+ )
657
+ : undefined;
658
+ const outFd = openSync(stdout, "a");
659
+ const errFd = openSync(stderr, "a");
660
+ const argv = asyncRunnerArgv(stateDir);
661
+ const outputValues = {
662
+ ...(startParams.defaults || {}),
663
+ ...values,
664
+ };
665
+ const transportContext = normalizeRunTransportContext(
666
+ startParams.transport_context,
667
+ );
668
+ const artifacts = resolveArtifactPaths(startParams.artifacts, outputValues);
669
+ const meta: AsyncRunMeta = {
670
+ argv: [process.execPath, ...argv],
671
+ createdAt: new Date().toISOString(),
672
+ cwd,
673
+ ...(startParams.launch_source
674
+ ? {
675
+ launch_kind: startParams.launch_source,
676
+ launch_source: startParams.launch_source,
677
+ }
678
+ : {}),
679
+ ...(startParams.launch_correlation
680
+ ? { launch_correlation: startParams.launch_correlation } : {}),
681
+ ...(startParams.ownerId ? { ownerId: startParams.ownerId } : {}),
682
+ pid: 0,
683
+ ...(recipe ? { recipe } : {}),
684
+ ...(recipeFile ? { recipe_file: recipeFile } : {}),
685
+ run,
686
+ run_instance_id: randomUUID(),
687
+ state_dir: stateDir,
688
+ state_schema: RuntimeIdentity.RUN_STATE_SCHEMA,
689
+ status: "running",
690
+ ...(startParams.tool ? { tool: startParams.tool } : {}),
691
+ template: runtimeTemplate,
692
+ values,
693
+ model_policy: modelPolicy,
694
+ ...(artifacts ? { artifacts } : {}),
695
+ ...(startParams.control ? { control: startParams.control } : {}),
696
+ ...(startParams.control_endpoint
697
+ ? { control_endpoint: startParams.control_endpoint }
698
+ : {}),
699
+ ...(startParams.notification_policy === "silent"
700
+ ? { notification_policy: "silent" as const }
701
+ : {}),
702
+ ...(recipeContextRecords && recipeContextRecords.length > 0
703
+ ? { recipe_context_records: recipeContextRecords }
704
+ : {}),
705
+ ...(startParams.retire_when === "children_terminal"
706
+ ? { retire_when: "children_terminal" as const }
707
+ : {}),
708
+ ...(startParams.singleton === true
709
+ ? {
710
+ singleton: true,
711
+ singleton_recipe_id: startParams.singleton_recipe_id,
712
+ singleton_values: singletonValues,
713
+ }
714
+ : {}),
715
+ ...(transportContext
716
+ ? { transport_context: transportContext } : {}),
717
+ };
718
+ writeJsonAtomic(join(stateDir, "run.json"), meta);
719
+ writeJsonAtomic(join(stateDir, "progress.json"), {
720
+ completed: 0,
721
+ failures: [],
722
+ model_policy: modelPolicy,
723
+ phase: "starting",
724
+ updatedAt: new Date().toISOString(),
725
+ });
726
+ const child = spawn(process.execPath, argv, {
727
+ cwd,
728
+ detached: true,
729
+ stdio: ["ignore", outFd, errFd],
730
+ });
731
+ closeSync(outFd);
732
+ closeSync(errFd);
733
+ meta.pid = child.pid ?? 0;
734
+ const processIdentity = captureRunProcessIdentity(
735
+ meta.pid,
736
+ cwd,
737
+ stateDir,
738
+ RUNNER_PATH,
739
+ );
740
+ if (processIdentity) meta.process_identity = processIdentity;
741
+ writeJsonAtomic(join(stateDir, "run.json"), meta);
742
+ appendRunTraceEvent(stateDir, {
743
+ kind: "run.start",
744
+ summary: `Run ${run} started`,
745
+ data: {
746
+ pid: meta.pid,
747
+ run_instance_id: meta.run_instance_id,
748
+ },
749
+ });
750
+ child.unref();
751
+ return meta;
752
+ } finally {
753
+ releaseStartLock();
754
+ }
755
+ }
756
+
757
+ function resolveRunStateDir(runOrDir: string): string {
758
+ return resolve(
759
+ /[\\/]/u.test(runOrDir)
760
+ ? runOrDir
761
+ : join(DEFAULT_STATE_ROOT, safeRunId(runOrDir)),
762
+ );
763
+ }
764
+
765
+ export function getRunStatus(runOrDir: string): Record<string, unknown> {
766
+ const stateDir = resolveRunStateDir(runOrDir);
767
+ const meta = readJson(join(stateDir, "run.json"));
768
+ if (!meta) throw new Error(`Run not found: ${runOrDir}`);
769
+ return buildRunStatus(
770
+ stateDir,
771
+ runOrDir,
772
+ meta,
773
+ readJson,
774
+ RUNNER_PATH,
775
+ RUNNER_IDENTITY_GRACE_MS,
776
+ );
777
+ }
778
+
779
+ export type { RunStateIndexEntry } from "./runs-index.ts";
780
+
781
+ export function listRunStateDirs(
782
+ stateRoot = DEFAULT_STATE_ROOT,
783
+ ): string[] {
784
+ return RunsIndex.listRunStateDirs(stateRoot);
785
+ }
786
+
787
+ export function rebuildRunStateIndex(
788
+ stateRoot = DEFAULT_STATE_ROOT,
789
+ ): RunsIndex.RunStateIndexEntry[] {
790
+ return RunsIndex.rebuildRunStateIndex(stateRoot, getRunStatus);
791
+ }
792
+
793
+ export function readRunStateIndex(
794
+ stateRoot = DEFAULT_STATE_ROOT,
795
+ ): RunsIndex.RunStateIndexEntry[] | undefined {
796
+ return RunsIndex.readRunStateIndex(stateRoot, readJson);
797
+ }
798
+
799
+ export function listRuns(
800
+ stateRoot = DEFAULT_STATE_ROOT,
801
+ statusFilter?: string,
802
+ ): Array<Record<string, unknown>> {
803
+ return RunsIndex.listRuns(stateRoot, getRunStatus, readJson, statusFilter);
804
+ }
805
+
806
+ export type {
807
+ ParentRunTeardownAttempt,
808
+ ParentRunTeardownDiscoveryFailure,
809
+ ParentRunTeardownResult,
810
+ } from "./runs-parent-teardown.ts";
811
+
812
+ export interface ParentRunsTeardownSummaryResult
813
+ extends RunsParentTeardown.ParentRunTeardownResult {
814
+ summaryPath?: string;
815
+ }
816
+
817
+ export function teardownRunsOwnedByParent(
818
+ ownerId: string | undefined,
819
+ stateRoot = DEFAULT_STATE_ROOT,
820
+ options: { trigger?: string } = {},
821
+ ): ParentRunsTeardownSummaryResult {
822
+ const result = RunsParentTeardown.teardownParentRuns(ownerId, {
823
+ getRunStatus,
824
+ killRun,
825
+ listRunStatuses: () => {
826
+ const discovered = RunsIndex.discoverRunStateDirs(
827
+ stateRoot,
828
+ Number.POSITIVE_INFINITY,
829
+ );
830
+ const failures: RunsParentTeardown.ParentRunTeardownDiscoveryFailure[] =
831
+ discovered.issues.map((issue) => ({
832
+ path: issue.path,
833
+ reason: issue.reason.replaceAll("_", " "),
834
+ }));
835
+ const statuses = discovered.stateDirs.flatMap((stateDir) => {
836
+ try {
837
+ return [getRunStatus(stateDir)];
838
+ } catch (error) {
839
+ failures.push({
840
+ path: stateDir,
841
+ reason: error instanceof Error ? error.message : String(error),
842
+ });
843
+ return [];
844
+ }
845
+ });
846
+ return { failures, statuses };
847
+ },
848
+ recordAttempt: (attempt) => {
849
+ const current = getRunStatus(attempt.stateDir);
850
+ if (
851
+ !attempt.runInstanceId ||
852
+ current.run_instance_id !== attempt.runInstanceId
853
+ ) {
854
+ throw new Error("run generation changed before teardown evidence");
855
+ }
856
+ appendRunTraceEvent(attempt.stateDir, {
857
+ kind: "run.parent_teardown",
858
+ summary: `Parent teardown ${attempt.outcome}`,
859
+ data: {
860
+ outcome: attempt.outcome,
861
+ owner_id: attempt.ownerId,
862
+ reason: attempt.reason,
863
+ run: attempt.run,
864
+ run_instance_id: attempt.runInstanceId,
865
+ trigger: options.trigger ?? "parent_shutdown",
866
+ },
867
+ ...(attempt.outcome === "failed" ? { level: "error" as const } : {}),
868
+ });
869
+ },
870
+ });
871
+ const summaryPath = join(
872
+ stateRoot,
873
+ "teardown",
874
+ `${Date.now()}-${randomUUID()}.json`,
875
+ );
876
+ try {
877
+ writeJsonAtomic(
878
+ summaryPath,
879
+ RunsParentTeardown.buildBoundedParentTeardownSummary(
880
+ result,
881
+ ownerId ?? "unknown",
882
+ options.trigger ?? "parent_shutdown",
883
+ new Date().toISOString(),
884
+ ),
885
+ );
886
+ return { ...result, summaryPath };
887
+ } catch (error) {
888
+ const failure = {
889
+ path: summaryPath,
890
+ reason: `summary: ${error instanceof Error ? error.message : String(error)}`,
891
+ };
892
+ return {
893
+ ...result,
894
+ discoveryFailed: result.discoveryFailed + 1,
895
+ discoveryFailures: [...result.discoveryFailures, failure],
896
+ failed: result.failed + 1,
897
+ };
898
+ }
899
+ }
900
+
901
+ export function tailRun(runOrDir: string, lines = 40): string {
902
+ const status = getRunStatus(runOrDir);
903
+ const stateDir = String(status.state_dir);
904
+ const trace = tailFile(join(stateDir, "trace.jsonl"), lines);
905
+ if (trace) return trace;
906
+ return (
907
+ tailFile(join(stateDir, "stdout.log"), lines) ||
908
+ tailFile(join(stateDir, "stderr.log"), lines)
909
+ );
910
+ }
911
+
912
+ export type {
913
+ DeliverRunControlOptions,
914
+ DeliverRunControlRequest,
915
+ } from "./runs-control-delivery.ts";
916
+
917
+ export interface SendRunControlOptions extends DeliverRunControlOptions {
918
+ ownerId?: string;
919
+ }
920
+
921
+ export async function sendRunControl(
922
+ runOrDir: string,
923
+ request: DeliverRunControlRequest,
924
+ options: SendRunControlOptions = {},
925
+ ): Promise<Record<string, unknown>> {
926
+ const stateDir = resolveRunStateDir(runOrDir);
927
+ const releaseControlLock = RunsStart.acquireStateStartLock(stateDir);
928
+ try {
929
+ const status = getRunStatus(stateDir);
930
+ const run = String(status.run ?? runOrDir);
931
+ if (options.ownerId !== undefined && status.ownerId !== options.ownerId) {
932
+ throw Object.assign(new Error(`Run ownership changed: ${run}`), {
933
+ reason: "owner_mismatch",
934
+ });
935
+ }
936
+ if (status.run_instance_id !== request.run_instance_id) {
937
+ throw Object.assign(new Error(`Run generation changed: ${run}`), {
938
+ reason: "generation_mismatch",
939
+ });
940
+ }
941
+ if (status.status !== "running") {
942
+ throw Object.assign(new Error(`Run is not running: ${run}`), {
943
+ reason: "terminal_state",
944
+ });
945
+ }
946
+ const pid = Number(status.pid || 0);
947
+ const identity = verifyRunProcessIdentity(
948
+ pid,
949
+ status.process_identity as RunProcessIdentity | undefined,
950
+ );
951
+ if (!identity.valid) {
952
+ throw Object.assign(
953
+ new Error(`Run process identity ${identity.status}: ${run}`),
954
+ { reason: `process_identity_${identity.status}` },
955
+ );
956
+ }
957
+ return await deliverRunControl(run, stateDir, request, options);
958
+ } finally {
959
+ releaseControlLock();
960
+ }
961
+ }
962
+
963
+ export { getRunProcessSignalPlan } from "./runs-control.ts";
964
+ export type { RunProcessSignalPlan } from "./runs-control.ts";
965
+
966
+ function markTerminalProgress(
967
+ stateDir: string,
968
+ phase: "cancelled" | "killed",
969
+ ): void {
970
+ const existing = readJson(join(stateDir, "progress.json"));
971
+ const progress =
972
+ existing && typeof existing === "object" && !Array.isArray(existing)
973
+ ? (existing as Record<string, unknown>)
974
+ : undefined;
975
+ writeJsonAtomic(
976
+ join(stateDir, "progress.json"),
977
+ buildTerminalProgress(progress, phase),
978
+ );
979
+ }
980
+
981
+ function finalizeInterruptedExecution(
982
+ stateDir: string,
983
+ phase: "cancelled" | "killed",
984
+ signal: NodeJS.Signals,
985
+ ): void {
986
+ const executionPath = join(stateDir, "execution.json");
987
+ const manifest = readJson(executionPath);
988
+ if (!manifest || typeof manifest !== "object" || Array.isArray(manifest)) return;
989
+ const record = manifest as Record<string, unknown>;
990
+ if (!Array.isArray(record.commands)) return;
991
+ const completedAt = new Date().toISOString();
992
+ const effectiveExitCode = signal === "SIGKILL" ? 137 : 143;
993
+ const commands = record.commands.map((command) => {
994
+ if (!command || typeof command !== "object" || Array.isArray(command)) {
995
+ return command;
996
+ }
997
+ const entry = command as Record<string, unknown>;
998
+ if (entry.status !== "running" || typeof entry.id !== "string") return entry;
999
+ const captureDir = join(stateDir, "captures", entry.id);
1000
+ const attempts = existsSync(captureDir)
1001
+ ? readdirSync(captureDir)
1002
+ .filter((name) => /^attempt-\d+$/.test(name))
1003
+ .sort()
1004
+ .map((name, index) => {
1005
+ const attemptDir = join(captureDir, name);
1006
+ const stdoutFile = join(attemptDir, "stdout.log");
1007
+ const stderrFile = join(attemptDir, "stderr.log");
1008
+ return {
1009
+ attempt: index + 1,
1010
+ stdout: {
1011
+ path: relative(stateDir, stdoutFile).replaceAll("\\", "/"),
1012
+ bytes: existsSync(stdoutFile) ? statSync(stdoutFile).size : 0,
1013
+ },
1014
+ stderr: {
1015
+ path: relative(stateDir, stderrFile).replaceAll("\\", "/"),
1016
+ bytes: existsSync(stderrFile) ? statSync(stderrFile).size : 0,
1017
+ },
1018
+ };
1019
+ })
1020
+ : [];
1021
+ return {
1022
+ ...entry,
1023
+ status: phase,
1024
+ completed_at: completedAt,
1025
+ attempts,
1026
+ effective_exit_code: effectiveExitCode,
1027
+ killed: true,
1028
+ ...(entry.semantic_acceptance === "pending"
1029
+ ? { semantic_acceptance: "interrupted" }
1030
+ : {}),
1031
+ };
1032
+ });
1033
+ writeJsonAtomic(executionPath, {
1034
+ ...record,
1035
+ status: phase,
1036
+ commands,
1037
+ updated_at: completedAt,
1038
+ });
1039
+ }
1040
+
1041
+ export interface RunControlExpectation {
1042
+ onLocked?(): void;
1043
+ ownerId?: string;
1044
+ runInstanceId?: string;
1045
+ }
1046
+
1047
+ function stopRun(
1048
+ runOrDir: string,
1049
+ signal: NodeJS.Signals,
1050
+ event: string,
1051
+ expected: RunControlExpectation = {},
1052
+ ): Record<string, unknown> {
1053
+ const stateDir = resolveRunStateDir(runOrDir);
1054
+ const releaseControlLock = RunsStart.acquireStateStartLock(stateDir);
1055
+ try {
1056
+ expected.onLocked?.();
1057
+ const status = getRunStatus(stateDir);
1058
+ if (
1059
+ expected.ownerId !== undefined &&
1060
+ status.ownerId !== expected.ownerId
1061
+ ) {
1062
+ return { stopped: false, reason: "ownership changed", status };
1063
+ }
1064
+ if (
1065
+ expected.runInstanceId !== undefined &&
1066
+ status.run_instance_id !== expected.runInstanceId
1067
+ ) {
1068
+ return { stopped: false, reason: "run generation changed", status };
1069
+ }
1070
+ const pid = Number(status.pid || 0);
1071
+ if (status.status !== "running" && status.status !== "exited") {
1072
+ return { stopped: false, reason: "not running", status };
1073
+ }
1074
+ const identity = verifyRunProcessIdentity(
1075
+ pid,
1076
+ status.process_identity as RunProcessIdentity | undefined,
1077
+ );
1078
+ if (status.status === "exited") {
1079
+ if (
1080
+ identity.status === "owner_mismatch" ||
1081
+ identity.status === "unsupported_proof"
1082
+ ) {
1083
+ return {
1084
+ stopped: false,
1085
+ reason: identity.status.replaceAll("_", " "),
1086
+ process_identity_status: identity.status,
1087
+ status,
1088
+ };
1089
+ }
1090
+ return { stopped: false, reason: "not running", status };
1091
+ }
1092
+ if (!identity.valid) {
1093
+ return {
1094
+ stopped: false,
1095
+ reason: identity.status.replaceAll("_", " "),
1096
+ process_identity_status: identity.status,
1097
+ status,
1098
+ };
1099
+ }
1100
+ let signalResult: RunProcessSignalPlan;
1101
+ try {
1102
+ signalResult = signalOwnedRunProcess(
1103
+ pid,
1104
+ signal,
1105
+ status.process_identity as RunProcessIdentity,
1106
+ );
1107
+ } catch (error) {
1108
+ throw error;
1109
+ }
1110
+ appendRunTraceEvent(stateDir, {
1111
+ kind: event,
1112
+ summary: `${event === "run.kill" ? "Killed" : "Cancelled"} Run process`,
1113
+ data: { pid, signal, ...signalResult },
1114
+ });
1115
+ markTerminalHandled(stateDir, { event, signal });
1116
+ if (event === "run.kill") {
1117
+ finalizeInterruptedExecution(stateDir, "killed", signal);
1118
+ markTerminalProgress(stateDir, "killed");
1119
+ }
1120
+ if (event === "run.cancel") {
1121
+ finalizeInterruptedExecution(stateDir, "cancelled", signal);
1122
+ markTerminalProgress(stateDir, "cancelled");
1123
+ }
1124
+ return {
1125
+ stopped: true,
1126
+ pid,
1127
+ signal,
1128
+ ...signalResult,
1129
+ state_dir: stateDir,
1130
+ };
1131
+ } finally {
1132
+ releaseControlLock();
1133
+ }
1134
+ }
1135
+
1136
+ export function markRunTerminalNotificationHandled(
1137
+ stateDir: string,
1138
+ status: string,
1139
+ ): void {
1140
+ markTerminalHandled(stateDir, {
1141
+ event: "run.notification",
1142
+ status,
1143
+ });
1144
+ }
1145
+
1146
+ export function recordRunTerminalDeliveryFailure(
1147
+ stateDir: string,
1148
+ status: string,
1149
+ error: unknown,
1150
+ ): void {
1151
+ const path = join(stateDir, "terminal-delivery-failure.json");
1152
+ const previous = readJson(path);
1153
+ const message = (error instanceof Error ? error.message : String(error))
1154
+ .replaceAll(/\s+/g, " ")
1155
+ .trim()
1156
+ .slice(0, 500);
1157
+ writeJsonAtomic(path, {
1158
+ attempts: Math.max(0, Number(previous?.attempts ?? 0)) + 1,
1159
+ error: message || "unknown delivery failure",
1160
+ status,
1161
+ ts: new Date().toISOString(),
1162
+ });
1163
+ }
1164
+
1165
+ export function cancelRun(
1166
+ runOrDir: string,
1167
+ expected: RunControlExpectation = {},
1168
+ ): Record<string, unknown> {
1169
+ const result = stopRun(runOrDir, "SIGTERM", "run.cancel", expected);
1170
+ return Object.hasOwn(result, "stopped")
1171
+ ? { cancelled: result.stopped, ...result }
1172
+ : result;
1173
+ }
1174
+
1175
+ function retainRun(
1176
+ runOrDir: string,
1177
+ action: RunRetentionAction,
1178
+ expected: RunControlExpectation,
1179
+ options: { preserveArtifacts?: boolean } = {},
1180
+ ): Record<string, unknown> {
1181
+ const stateDir = resolveRunStateDir(runOrDir);
1182
+ const releaseControlLock = RunsStart.acquireStateStartLock(stateDir);
1183
+ let status: Record<string, unknown> | undefined;
1184
+ let evidenceId: string | undefined;
1185
+ try {
1186
+ expected.onLocked?.();
1187
+ status = getRunStatus(stateDir);
1188
+ if (expected.ownerId !== undefined && status.ownerId !== expected.ownerId) {
1189
+ return { [`${action}d`]: false, reason: "ownership changed", status };
1190
+ }
1191
+ if (
1192
+ expected.runInstanceId !== undefined &&
1193
+ status.run_instance_id !== expected.runInstanceId
1194
+ ) {
1195
+ return { [`${action}d`]: false, reason: "run generation changed", status };
1196
+ }
1197
+ if (status.status === "running") {
1198
+ throw new Error("Only terminal runs can be archived or pruned.");
1199
+ }
1200
+ evidenceId = appendRunRetentionEvidence(status, action, "queued");
1201
+ const result = action === "archive"
1202
+ ? archiveTerminalRun(status)
1203
+ : pruneTerminalRun(status, options);
1204
+ appendRunRetentionEvidence(status, action, "handled", {
1205
+ id: evidenceId,
1206
+ result,
1207
+ });
1208
+ return { ...result, retention_id: evidenceId };
1209
+ } catch (error) {
1210
+ if (status && evidenceId) {
1211
+ appendRunRetentionEvidence(status, action, "failed", {
1212
+ error: error instanceof Error ? error.message : String(error),
1213
+ id: evidenceId,
1214
+ });
1215
+ }
1216
+ throw error;
1217
+ } finally {
1218
+ releaseControlLock();
1219
+ }
1220
+ }
1221
+
1222
+ export function archiveRun(
1223
+ runOrDir: string,
1224
+ expected: RunControlExpectation = {},
1225
+ ): Record<string, unknown> {
1226
+ return retainRun(runOrDir, "archive", expected);
1227
+ }
1228
+
1229
+ export function pruneRun(
1230
+ runOrDir: string,
1231
+ options: { preserveArtifacts?: boolean } = {},
1232
+ expected: RunControlExpectation = {},
1233
+ ): Record<string, unknown> {
1234
+ return retainRun(runOrDir, "prune", expected, options);
1235
+ }
1236
+
1237
+ export function killRun(
1238
+ runOrDir: string,
1239
+ expected: RunControlExpectation = {},
1240
+ ): Record<string, unknown> {
1241
+ const result = stopRun(runOrDir, "SIGKILL", "run.kill", expected);
1242
+ return Object.hasOwn(result, "stopped")
1243
+ ? { killed: result.stopped, ...result }
1244
+ : result;
1245
+ }