@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,1007 @@
1
+ /**
2
+ * Telegram outbound surface helpers
3
+ * Zones: telegram outbound, command templates, voice delivery
4
+ * Owns configured outbound handler execution, text transforms, public assistant-output reply composition and mutation fencing, voice-file generation/delivery, runtime-event bridge, and compatibility re-exports; assistant markup parsing lives in outbound-markup and button callback actions live in outbound-buttons
5
+ */
6
+
7
+ import { randomUUID } from "node:crypto";
8
+ import { mkdir } from "node:fs/promises";
9
+ import { join } from "node:path";
10
+
11
+ import type { TelegramAssistantSegmentEvent } from "./activity.ts";
12
+ import { resolveTelegramTempDir } from "./paths.ts";
13
+ import * as Replies from "./replies.ts";
14
+ import type {
15
+ TelegramEditMessageTextBody,
16
+ TelegramSendMessageBody,
17
+ TelegramSendRichMessageBody,
18
+ TelegramSentMessage,
19
+ } from "./telegram-api.ts";
20
+
21
+ import {
22
+ planTelegramButtonReply,
23
+ type TelegramButtonActionStore,
24
+ type TelegramOutboundButtonBinding,
25
+ type TelegramOutboundButtonMarkup,
26
+ } from "./outbound-buttons.ts";
27
+ import {
28
+ planTelegramVoiceReply,
29
+ type TelegramVoiceReplyItem,
30
+ } from "./outbound-markup.ts";
31
+ import { createTelegramVoiceReplySender as createTelegramVoiceReplySenderWithPorts } from "./outbound-voice.ts";
32
+ import type { TelegramTarget } from "./target.ts";
33
+
34
+ const OUTBOUND_HANDLER_REGISTRY_KEY = "__piTelegramOutboundHandlers__";
35
+ const VOICE_EVENT_RECORDER_KEY = "__piTelegramVoiceEventRecorder__";
36
+
37
+ import {
38
+ buildCommandTemplateInvocation,
39
+ expandCommandTemplateConfigs,
40
+ substituteCommandTemplateToken,
41
+ type CommandTemplateObjectConfig,
42
+ } from "./command-templates.ts";
43
+ const DEFAULT_VOICE_TIMEOUT_MS = 120_000;
44
+
45
+ // --- Types ---
46
+
47
+ /**
48
+ * Record a runtime event that appears in `/telegram-status`.
49
+ * Voice synthesis provider extensions can call this to surface diagnostics
50
+ * alongside pi-telegram's own events. Events are silently dropped
51
+ * when pi-telegram is not loaded.
52
+ */
53
+ export type TelegramRuntimeEventRecorder = (
54
+ category: string,
55
+ error: unknown,
56
+ details?: Record<string, unknown>,
57
+ ) => void;
58
+
59
+ export function bindTelegramRuntimeEventRecorder(
60
+ recorder: TelegramRuntimeEventRecorder,
61
+ ): void {
62
+ (globalThis as Record<string, unknown>)[VOICE_EVENT_RECORDER_KEY] = recorder;
63
+ }
64
+
65
+ export function recordTelegramRuntimeEvent(
66
+ category: string,
67
+ error: unknown,
68
+ details?: Record<string, unknown>,
69
+ ): void {
70
+ const recorder = (globalThis as Record<string, unknown>)[
71
+ VOICE_EVENT_RECORDER_KEY
72
+ ];
73
+ if (typeof recorder === "function") {
74
+ (recorder as TelegramRuntimeEventRecorder)(category, error, details);
75
+ }
76
+ }
77
+
78
+ export type TelegramOutboundCommandTemplateConfig =
79
+ string | CommandTemplateObjectConfig;
80
+ export interface TelegramOutboundHandlerConfig extends CommandTemplateObjectConfig {
81
+ type?: string;
82
+ match?: string | string[];
83
+ output?: string;
84
+ timeout?: number | string;
85
+ }
86
+
87
+ export {
88
+ normalizeMarkdownAfterVoiceExtraction,
89
+ planTelegramVoiceReply,
90
+ stripTelegramCommentMarkupForDelivery,
91
+ stripTelegramCommentMarkupForPreview,
92
+ stripTelegramVoiceMarkupForPreview,
93
+ type TelegramVoiceReplyItem,
94
+ type TelegramVoiceReplyPlan,
95
+ } from "./outbound-markup.ts";
96
+
97
+ export interface TelegramVoiceExecOptions {
98
+ cwd?: string;
99
+ timeout?: number;
100
+ signal?: AbortSignal;
101
+ stdin?: string;
102
+ retry?: number;
103
+ }
104
+
105
+ export interface TelegramVoiceExecResult {
106
+ stdout: string;
107
+ stderr: string;
108
+ code: number;
109
+ killed: boolean;
110
+ }
111
+
112
+ export interface TelegramVoiceReplyTurnView {
113
+ chatId: number;
114
+ replyToMessageId: number;
115
+ target?: TelegramTarget;
116
+ }
117
+
118
+ export interface TelegramVoiceReplySenderDeps {
119
+ execCommand: (
120
+ command: string,
121
+ args: string[],
122
+ options?: TelegramVoiceExecOptions,
123
+ ) => Promise<TelegramVoiceExecResult>;
124
+ sendMultipart: (
125
+ method: string,
126
+ fields: Record<string, string>,
127
+ fileField: string,
128
+ filePath: string,
129
+ fileName: string,
130
+ ) => Promise<unknown>;
131
+ sendTextReply?: (
132
+ chatId: number,
133
+ replyToMessageId: number | undefined,
134
+ text: string,
135
+ options?: { parseMode?: "HTML" },
136
+ ) => Promise<unknown>;
137
+ sendChatAction?: (chatId: number, action: string) => Promise<unknown>;
138
+ sendRecordVoiceAction?: (chatId: number) => Promise<unknown>;
139
+ getHandlers?: () => TelegramOutboundHandlerConfig[] | undefined;
140
+ cwd?: string;
141
+ tempDir?: string;
142
+ recordRuntimeEvent?: (
143
+ category: string,
144
+ error: unknown,
145
+ details?: Record<string, unknown>,
146
+ ) => void;
147
+ }
148
+
149
+ // --- Programmatic Outbound Handler Registry ---
150
+
151
+ export type TelegramOutboundProgrammaticHandler = (
152
+ text: string,
153
+ options?: { lang?: string; rate?: string },
154
+ ) => Promise<string>;
155
+
156
+ export interface TelegramOutboundHandlerRegistry {
157
+ handlers: Map<string, TelegramOutboundProgrammaticHandler[]>;
158
+ }
159
+
160
+ // --- Programmatic Outbound Handler Registry Runtime ---
161
+
162
+ function getOrCreateOutboundHandlerRegistry(): TelegramOutboundHandlerRegistry {
163
+ const existing = (globalThis as Record<string, unknown>)[
164
+ OUTBOUND_HANDLER_REGISTRY_KEY
165
+ ];
166
+ if (
167
+ existing &&
168
+ typeof existing === "object" &&
169
+ existing !== null &&
170
+ "handlers" in existing &&
171
+ existing.handlers instanceof Map
172
+ ) {
173
+ return existing as TelegramOutboundHandlerRegistry;
174
+ }
175
+ const registry: TelegramOutboundHandlerRegistry = {
176
+ handlers: new Map(),
177
+ };
178
+ (globalThis as Record<string, unknown>)[OUTBOUND_HANDLER_REGISTRY_KEY] =
179
+ registry;
180
+ return registry;
181
+ }
182
+
183
+ export function registerTelegramOutboundHandler(
184
+ kind: string,
185
+ handler: TelegramOutboundProgrammaticHandler,
186
+ ): () => void {
187
+ const registry = getOrCreateOutboundHandlerRegistry();
188
+ const list = registry.handlers.get(kind) ?? [];
189
+ list.push(handler);
190
+ registry.handlers.set(kind, list);
191
+ return () => {
192
+ const updated = registry.handlers.get(kind) ?? [];
193
+ const index = updated.indexOf(handler);
194
+ if (index !== -1) {
195
+ updated.splice(index, 1);
196
+ registry.handlers.set(kind, updated);
197
+ }
198
+ };
199
+ }
200
+
201
+ export function getTelegramOutboundProgrammaticHandlers(
202
+ kind: string,
203
+ ): TelegramOutboundProgrammaticHandler[] {
204
+ const registry = getOrCreateOutboundHandlerRegistry();
205
+ return [...(registry.handlers.get(kind) ?? [])];
206
+ }
207
+
208
+ export interface TelegramOutboundTextReplyRuntimeDeps<TReplyMarkup = unknown> {
209
+ execCommand: TelegramVoiceReplySenderDeps["execCommand"];
210
+ getHandlers?: () => TelegramOutboundHandlerConfig[] | undefined;
211
+ sendTextReply: (
212
+ chatId: number,
213
+ replyToMessageId: number | undefined,
214
+ text: string,
215
+ options?: { parseMode?: "HTML"; target?: TelegramTarget },
216
+ ) => Promise<number | undefined>;
217
+ sendMarkdownReply: (
218
+ chatId: number,
219
+ replyToMessageId: number | undefined,
220
+ markdown: string,
221
+ options?: { replyMarkup?: TReplyMarkup; target?: TelegramTarget },
222
+ ) => Promise<number | undefined>;
223
+ cwd?: string;
224
+ recordRuntimeEvent?: TelegramVoiceReplySenderDeps["recordRuntimeEvent"];
225
+ }
226
+
227
+ export interface TelegramInlineKeyboardLike {
228
+ inline_keyboard: Array<Array<{ text: string; callback_data: string }>>;
229
+ }
230
+
231
+ export interface TelegramOutboundTextTransformOptions<TReplyMarkup = unknown> {
232
+ handlers?: TelegramOutboundHandlerConfig[];
233
+ cwd?: string;
234
+ execCommand: TelegramVoiceReplySenderDeps["execCommand"];
235
+ recordRuntimeEvent?: TelegramVoiceReplySenderDeps["recordRuntimeEvent"];
236
+ replyMarkup?: TReplyMarkup;
237
+ }
238
+
239
+ export interface TelegramOutboundTextTransformResult<TReplyMarkup = unknown> {
240
+ text: string;
241
+ replyMarkup?: TReplyMarkup;
242
+ }
243
+
244
+ export interface TelegramOutboundTextPreviewRuntimeDeps<
245
+ TReplyMarkup = unknown,
246
+ > {
247
+ execCommand: TelegramVoiceReplySenderDeps["execCommand"];
248
+ getHandlers?: () => TelegramOutboundHandlerConfig[] | undefined;
249
+ finalizeMarkdownPreview: (
250
+ chatId: number,
251
+ markdown: string,
252
+ replyToMessageId: number,
253
+ options?: { replyMarkup?: TReplyMarkup },
254
+ ) => Promise<boolean>;
255
+ cwd?: string;
256
+ recordRuntimeEvent?: TelegramVoiceReplySenderDeps["recordRuntimeEvent"];
257
+ }
258
+
259
+ // --- Voice Reply Timeout Helpers ---
260
+
261
+ function resolveOutboundNumericControlField(
262
+ value: number | string | undefined,
263
+ values: Record<string, unknown>,
264
+ label: string,
265
+ ): number | undefined {
266
+ if (value === undefined) return undefined;
267
+ const resolved =
268
+ typeof value === "string"
269
+ ? substituteCommandTemplateToken(value, values, label)
270
+ : value;
271
+ if (resolved === "") return undefined;
272
+ const numeric = Number(resolved);
273
+ if (!Number.isFinite(numeric) || numeric < 0)
274
+ throw new Error(`Command template ${label} must be a non-negative number.`);
275
+ return numeric;
276
+ }
277
+
278
+ function getVoiceReplyConfiguredTimeout(
279
+ config: TelegramOutboundCommandTemplateConfig | undefined,
280
+ ): number | undefined {
281
+ const timeout = typeof config === "string" ? undefined : config?.timeout;
282
+ return resolveOutboundNumericControlField(timeout, {}, "timeout");
283
+ }
284
+
285
+ function getVoiceReplyTimeout(
286
+ config: TelegramOutboundCommandTemplateConfig | undefined,
287
+ ): number {
288
+ return getVoiceReplyConfiguredTimeout(config) ?? DEFAULT_VOICE_TIMEOUT_MS;
289
+ }
290
+
291
+ function getRemainingVoiceReplyTimeout(
292
+ timeout: number,
293
+ startedAt: number,
294
+ ): number {
295
+ return Math.max(1, timeout - (Date.now() - startedAt));
296
+ }
297
+
298
+ function getVoiceReplyCompositionStepTimeout(
299
+ handlerTimeout: number,
300
+ step: TelegramOutboundCommandTemplateConfig,
301
+ startedAt: number,
302
+ ): number {
303
+ const remaining = getRemainingVoiceReplyTimeout(handlerTimeout, startedAt);
304
+ const stepTimeout = getVoiceReplyConfiguredTimeout(step);
305
+ return stepTimeout === undefined
306
+ ? remaining
307
+ : Math.min(stepTimeout, remaining);
308
+ }
309
+
310
+ function formatVoiceReplyExecutionFailure(
311
+ label: string,
312
+ result: TelegramVoiceExecResult,
313
+ ): string {
314
+ const parts = [
315
+ `${label} exited with code ${result.code}${result.killed ? " (killed)" : ""}`,
316
+ ];
317
+ if (result.stderr.trim()) parts.push(`stderr:\n${result.stderr.trimEnd()}`);
318
+ if (result.stdout.trim()) parts.push(`stdout:\n${result.stdout.trimEnd()}`);
319
+ return parts.join("\n\n");
320
+ }
321
+
322
+ async function runVoiceReplyCommand(
323
+ label: string,
324
+ config: TelegramOutboundCommandTemplateConfig,
325
+ values: Record<string, string>,
326
+ options: {
327
+ cwd: string;
328
+ timeout: number;
329
+ execCommand: TelegramVoiceReplySenderDeps["execCommand"];
330
+ stdin?: string;
331
+ },
332
+ ): Promise<TelegramVoiceExecResult> {
333
+ if (!options.execCommand) {
334
+ throw new Error("execCommand is required for command template execution");
335
+ }
336
+ const invocation = buildCommandTemplateInvocation(
337
+ config,
338
+ values,
339
+ options.cwd,
340
+ {
341
+ emptyMessage: "Outbound voice template is empty",
342
+ missingLabel: "outbound voice template",
343
+ },
344
+ );
345
+ const result = await options.execCommand(
346
+ invocation.command,
347
+ invocation.args,
348
+ {
349
+ cwd: options.cwd,
350
+ timeout: options.timeout,
351
+ ...(typeof config === "object" && config.retry !== undefined
352
+ ? {
353
+ retry: resolveOutboundNumericControlField(
354
+ config.retry,
355
+ {},
356
+ "retry",
357
+ ),
358
+ }
359
+ : {}),
360
+ ...(options.stdin !== undefined ? { stdin: options.stdin } : {}),
361
+ },
362
+ );
363
+ if (result.code !== 0)
364
+ throw new Error(formatVoiceReplyExecutionFailure(label, result));
365
+ return result;
366
+ }
367
+
368
+ function normalizeOutboundHandlerStringList(
369
+ value: string | string[] | undefined,
370
+ ): string[] {
371
+ if (Array.isArray(value))
372
+ return value
373
+ .map(String)
374
+ .map((item) => item.trim())
375
+ .filter(Boolean);
376
+ if (typeof value === "string" && value.trim()) return [value.trim()];
377
+ return [];
378
+ }
379
+
380
+ function outboundHandlerMatchesType(
381
+ handler: TelegramOutboundHandlerConfig,
382
+ type: string,
383
+ ): boolean {
384
+ const selectors = [
385
+ ...normalizeOutboundHandlerStringList(handler.type),
386
+ ...normalizeOutboundHandlerStringList(handler.match),
387
+ ];
388
+ if (selectors.length === 0) return false;
389
+ return selectors.includes(type);
390
+ }
391
+
392
+ export function findTelegramOutboundHandlers(
393
+ handlers: TelegramOutboundHandlerConfig[] | undefined,
394
+ type: string,
395
+ ): TelegramOutboundHandlerConfig[] {
396
+ if (!Array.isArray(handlers)) return [];
397
+ return handlers.filter(
398
+ (handler) =>
399
+ !!handler &&
400
+ typeof handler === "object" &&
401
+ outboundHandlerMatchesType(handler, type),
402
+ );
403
+ }
404
+
405
+ function getTelegramVoiceHandlerCompositionSteps(
406
+ handler: TelegramOutboundHandlerConfig,
407
+ ): TelegramOutboundCommandTemplateConfig[] {
408
+ if (Array.isArray(handler.template)) {
409
+ return expandCommandTemplateConfigs(
410
+ handler,
411
+ ) as TelegramOutboundCommandTemplateConfig[];
412
+ }
413
+ return [];
414
+ }
415
+
416
+ function extractVoiceReplyPath(stdout: string): string {
417
+ const path = stdout.trim().split(/\r?\n/).filter(Boolean).at(-1);
418
+ if (!path) throw new Error("Voice generator did not print an output path");
419
+ return path;
420
+ }
421
+
422
+ function getVoiceReplyOutputPath(
423
+ config: TelegramOutboundHandlerConfig,
424
+ values: Record<string, string>,
425
+ stdout: string,
426
+ ): string {
427
+ const output = config.output ?? "stdout";
428
+ if (output === "stdout") return extractVoiceReplyPath(stdout);
429
+ const keyMatch = output.match(/^\{?([A-Za-z_][A-Za-z0-9_-]*)\}?$/);
430
+ if (keyMatch && Object.hasOwn(values, keyMatch[1])) {
431
+ return values[keyMatch[1]] ?? "";
432
+ }
433
+ return output.replace(
434
+ /\{([A-Za-z_][A-Za-z0-9_-]*)\}/g,
435
+ (_match, key: string) => values[key] ?? "",
436
+ );
437
+ }
438
+
439
+ function getVoiceReplyTemplateValues(
440
+ text: string,
441
+ options: { lang?: string; rate?: string; mp3Path: string; oggPath: string },
442
+ ): Record<string, string> {
443
+ return {
444
+ text,
445
+ type: "voice",
446
+ mp3: options.mp3Path,
447
+ ogg: options.oggPath,
448
+ ...(options.lang ? { lang: options.lang } : {}),
449
+ ...(options.rate ? { rate: options.rate } : {}),
450
+ };
451
+ }
452
+
453
+ function getDefaultTelegramVoiceTempDir(): string {
454
+ return resolveTelegramTempDir();
455
+ }
456
+
457
+ async function generateTelegramVoiceReplyFileWithHandler(
458
+ text: string,
459
+ options: {
460
+ lang?: string;
461
+ rate?: string;
462
+ handler: TelegramOutboundHandlerConfig;
463
+ tempDir: string;
464
+ cwd: string;
465
+ timeout: number;
466
+ execCommand: TelegramVoiceReplySenderDeps["execCommand"];
467
+ },
468
+ ): Promise<string> {
469
+ await mkdir(options.tempDir, { recursive: true });
470
+ const artifactId = randomUUID();
471
+ const values = getVoiceReplyTemplateValues(text, {
472
+ lang: options.lang,
473
+ rate: options.rate,
474
+ mp3Path: join(options.tempDir, `${artifactId}-voice.mp3`),
475
+ oggPath: join(options.tempDir, `${artifactId}-voice.ogg`),
476
+ });
477
+ const steps = getTelegramVoiceHandlerCompositionSteps(options.handler);
478
+ if (steps.length > 0) {
479
+ const startedAt = Date.now();
480
+ let stdout = text;
481
+ for (const [index, step] of steps.entries()) {
482
+ try {
483
+ const result = await runVoiceReplyCommand(
484
+ `Outbound voice template step ${index + 1}`,
485
+ step,
486
+ values,
487
+ {
488
+ cwd: options.cwd,
489
+ timeout: getVoiceReplyCompositionStepTimeout(
490
+ options.timeout,
491
+ step,
492
+ startedAt,
493
+ ),
494
+ execCommand: options.execCommand,
495
+ stdin: stdout,
496
+ },
497
+ );
498
+ stdout = result.stdout;
499
+ } catch (error) {
500
+ if (typeof step === "object" && step.failure === "root") throw error;
501
+ stdout = "";
502
+ }
503
+ }
504
+ return getVoiceReplyOutputPath(options.handler, values, stdout);
505
+ }
506
+ const result = await runVoiceReplyCommand(
507
+ "Outbound voice template",
508
+ options.handler,
509
+ values,
510
+ {
511
+ cwd: options.cwd,
512
+ timeout: options.timeout,
513
+ execCommand: options.execCommand,
514
+ stdin: text,
515
+ },
516
+ );
517
+ return getVoiceReplyOutputPath(options.handler, values, result.stdout);
518
+ }
519
+
520
+ export async function generateTelegramVoiceReplyFile(
521
+ text: string,
522
+ options: {
523
+ lang?: string;
524
+ rate?: string;
525
+ handler?: TelegramOutboundHandlerConfig;
526
+ tempDir?: string;
527
+ cwd?: string;
528
+ execCommand: TelegramVoiceReplySenderDeps["execCommand"];
529
+ },
530
+ ): Promise<string | undefined> {
531
+ const handler = options.handler;
532
+ if (!handler?.template) return undefined;
533
+ return generateTelegramVoiceReplyFileWithHandler(text, {
534
+ lang: options.lang,
535
+ rate: options.rate,
536
+ handler,
537
+ tempDir: options.tempDir ?? getDefaultTelegramVoiceTempDir(),
538
+ cwd: options.cwd ?? process.cwd(),
539
+ timeout: getVoiceReplyTimeout(handler),
540
+ execCommand: options.execCommand,
541
+ });
542
+ }
543
+
544
+ function getOutboundTextTemplateValues(text: string): Record<string, string> {
545
+ return { text, type: "text" };
546
+ }
547
+
548
+ async function transformTelegramOutboundTextWithHandler(
549
+ text: string,
550
+ options: {
551
+ handler: TelegramOutboundHandlerConfig;
552
+ cwd: string;
553
+ execCommand: TelegramVoiceReplySenderDeps["execCommand"];
554
+ },
555
+ ): Promise<string> {
556
+ const values = getOutboundTextTemplateValues(text);
557
+ const steps = getTelegramVoiceHandlerCompositionSteps(options.handler);
558
+ if (steps.length > 0) {
559
+ const startedAt = Date.now();
560
+ let stdout = text;
561
+ for (const [index, step] of steps.entries()) {
562
+ try {
563
+ const result = await runVoiceReplyCommand(
564
+ `Outbound text template step ${index + 1}`,
565
+ step,
566
+ values,
567
+ {
568
+ cwd: options.cwd,
569
+ timeout: getVoiceReplyCompositionStepTimeout(
570
+ getVoiceReplyTimeout(options.handler),
571
+ step,
572
+ startedAt,
573
+ ),
574
+ execCommand: options.execCommand,
575
+ stdin: stdout,
576
+ },
577
+ );
578
+ stdout = result.stdout;
579
+ } catch (error) {
580
+ if (typeof step === "object" && step.failure === "root") throw error;
581
+ stdout = "";
582
+ }
583
+ if (!stdout) stdout = text;
584
+ }
585
+ return stdout.trim() || text;
586
+ }
587
+ const result = await runVoiceReplyCommand(
588
+ "Outbound text template",
589
+ options.handler,
590
+ values,
591
+ {
592
+ cwd: options.cwd,
593
+ timeout: getVoiceReplyTimeout(options.handler),
594
+ execCommand: options.execCommand,
595
+ stdin: text,
596
+ },
597
+ );
598
+ return result.stdout.trim() || text;
599
+ }
600
+
601
+ export async function transformTelegramOutboundText(
602
+ text: string,
603
+ options: {
604
+ handlers?: TelegramOutboundHandlerConfig[];
605
+ cwd?: string;
606
+ execCommand: TelegramVoiceReplySenderDeps["execCommand"];
607
+ recordRuntimeEvent?: TelegramVoiceReplySenderDeps["recordRuntimeEvent"];
608
+ },
609
+ ): Promise<string> {
610
+ let transformed = text;
611
+ for (const handler of findTelegramOutboundHandlers(
612
+ options.handlers,
613
+ "text",
614
+ )) {
615
+ try {
616
+ transformed = await transformTelegramOutboundTextWithHandler(
617
+ transformed,
618
+ {
619
+ handler,
620
+ cwd: options.cwd ?? process.cwd(),
621
+ execCommand: options.execCommand,
622
+ },
623
+ );
624
+ } catch (error) {
625
+ options.recordRuntimeEvent?.("outbound-text-handler", error, {
626
+ handler: outboundHandlerMatchesType(handler, "text")
627
+ ? "text"
628
+ : "unknown",
629
+ });
630
+ }
631
+ }
632
+ return transformed;
633
+ }
634
+
635
+ function isTelegramInlineKeyboardLike(
636
+ replyMarkup: unknown,
637
+ ): replyMarkup is TelegramInlineKeyboardLike {
638
+ if (!replyMarkup || typeof replyMarkup !== "object") return false;
639
+ const keyboard = (replyMarkup as { inline_keyboard?: unknown })
640
+ .inline_keyboard;
641
+ return Array.isArray(keyboard);
642
+ }
643
+
644
+ async function transformTelegramOutboundReplyMarkup<TReplyMarkup>(
645
+ replyMarkup: TReplyMarkup | undefined,
646
+ options: Omit<TelegramOutboundTextTransformOptions, "replyMarkup">,
647
+ ): Promise<TReplyMarkup | undefined> {
648
+ if (!isTelegramInlineKeyboardLike(replyMarkup)) return replyMarkup;
649
+ const translatedRows = [];
650
+ for (const row of replyMarkup.inline_keyboard) {
651
+ const translatedRow = [];
652
+ for (const button of row) {
653
+ const text = await transformTelegramOutboundText(button.text, options);
654
+ translatedRow.push({ ...button, text });
655
+ }
656
+ translatedRows.push(translatedRow);
657
+ }
658
+ return { ...replyMarkup, inline_keyboard: translatedRows } as TReplyMarkup;
659
+ }
660
+
661
+ export async function transformTelegramOutboundTextReply<
662
+ TReplyMarkup = unknown,
663
+ >(
664
+ text: string,
665
+ options: TelegramOutboundTextTransformOptions<TReplyMarkup>,
666
+ ): Promise<TelegramOutboundTextTransformResult<TReplyMarkup>> {
667
+ const transformOptions = {
668
+ handlers: options.handlers,
669
+ cwd: options.cwd,
670
+ execCommand: options.execCommand,
671
+ recordRuntimeEvent: options.recordRuntimeEvent,
672
+ };
673
+ const transformedText = await transformTelegramOutboundText(
674
+ text,
675
+ transformOptions,
676
+ );
677
+ const replyMarkup = await transformTelegramOutboundReplyMarkup(
678
+ options.replyMarkup,
679
+ transformOptions,
680
+ );
681
+ return { text: transformedText, ...(replyMarkup ? { replyMarkup } : {}) };
682
+ }
683
+
684
+ export function createTelegramOutboundTextReplyRuntime<TReplyMarkup = unknown>(
685
+ deps: TelegramOutboundTextReplyRuntimeDeps<TReplyMarkup>,
686
+ ): Pick<
687
+ TelegramOutboundTextReplyRuntimeDeps<TReplyMarkup>,
688
+ "sendTextReply" | "sendMarkdownReply"
689
+ > {
690
+ return {
691
+ sendTextReply: async (chatId, replyToMessageId, text, options) => {
692
+ const transformed = await transformTelegramOutboundText(text, {
693
+ handlers: deps.getHandlers?.(),
694
+ cwd: deps.cwd,
695
+ execCommand: deps.execCommand,
696
+ recordRuntimeEvent: deps.recordRuntimeEvent,
697
+ });
698
+ return deps.sendTextReply(chatId, replyToMessageId, transformed, options);
699
+ },
700
+ sendMarkdownReply: async (chatId, replyToMessageId, markdown, options) => {
701
+ const transformed = await transformTelegramOutboundTextReply(markdown, {
702
+ handlers: deps.getHandlers?.(),
703
+ cwd: deps.cwd,
704
+ execCommand: deps.execCommand,
705
+ recordRuntimeEvent: deps.recordRuntimeEvent,
706
+ replyMarkup: options?.replyMarkup,
707
+ });
708
+ return deps.sendMarkdownReply(
709
+ chatId,
710
+ replyToMessageId,
711
+ transformed.text,
712
+ {
713
+ ...options,
714
+ ...(transformed.replyMarkup
715
+ ? { replyMarkup: transformed.replyMarkup }
716
+ : {}),
717
+ },
718
+ );
719
+ },
720
+ };
721
+ }
722
+
723
+ export function createTelegramOutboundTextPreviewRuntime<
724
+ TReplyMarkup = unknown,
725
+ >(
726
+ deps: TelegramOutboundTextPreviewRuntimeDeps<TReplyMarkup>,
727
+ ): Pick<
728
+ TelegramOutboundTextPreviewRuntimeDeps<TReplyMarkup>,
729
+ "finalizeMarkdownPreview"
730
+ > {
731
+ return {
732
+ finalizeMarkdownPreview: async (
733
+ chatId,
734
+ markdown,
735
+ replyToMessageId,
736
+ options,
737
+ ) => {
738
+ const transformed = await transformTelegramOutboundTextReply(markdown, {
739
+ handlers: deps.getHandlers?.(),
740
+ cwd: deps.cwd,
741
+ execCommand: deps.execCommand,
742
+ recordRuntimeEvent: deps.recordRuntimeEvent,
743
+ replyMarkup: options?.replyMarkup,
744
+ });
745
+ return deps.finalizeMarkdownPreview(
746
+ chatId,
747
+ transformed.text,
748
+ replyToMessageId,
749
+ {
750
+ ...options,
751
+ ...(transformed.replyMarkup
752
+ ? { replyMarkup: transformed.replyMarkup }
753
+ : {}),
754
+ },
755
+ );
756
+ },
757
+ };
758
+ }
759
+
760
+ export interface TelegramOutboundReplyPlan<TReplyMarkup = unknown> {
761
+ markdown: string;
762
+ replyMarkup?: TReplyMarkup;
763
+ voiceText?: string;
764
+ voiceReplies?: TelegramVoiceReplyItem[];
765
+ lang?: string;
766
+ rate?: string;
767
+ }
768
+
769
+ // --- Voice Policy Re-Exports ---
770
+ export {
771
+ clearTelegramVoiceSynthesisProviders,
772
+ clearTelegramVoiceTranscriptionProviders,
773
+ computeVoicePromptContribution,
774
+ computeVoiceTurnFlags,
775
+ getTelegramVoiceReplyMode,
776
+ getTelegramVoiceSynthesisProviders,
777
+ getTelegramVoiceTranscriptionProviders,
778
+ hasTelegramVoiceSynthesisProvider,
779
+ hasTelegramVoiceTranscriptionProvider,
780
+ isVoiceTurn,
781
+ registerTelegramVoiceSynthesisProvider,
782
+ registerTelegramVoiceTranscriptionProvider,
783
+ shouldSuppressPreviewForVoice,
784
+ type TelegramVoiceReplyMode,
785
+ type TelegramVoiceSynthesisProvider,
786
+ type TelegramVoiceSynthesisProviderResult,
787
+ type TelegramVoiceTranscriptionFile,
788
+ type TelegramVoiceTranscriptionProvider,
789
+ type TelegramVoiceTranscriptionProviderResult,
790
+ type TelegramVoiceTurnView,
791
+ } from "./voice.ts";
792
+
793
+ export function createTelegramVoiceReplySender(
794
+ deps: TelegramVoiceReplySenderDeps,
795
+ ) {
796
+ return createTelegramVoiceReplySenderWithPorts(deps, {
797
+ findVoiceHandlers: (handlers) =>
798
+ findTelegramOutboundHandlers(
799
+ handlers as TelegramOutboundHandlerConfig[] | undefined,
800
+ "voice",
801
+ ),
802
+ generateVoiceFile: (text, options) =>
803
+ generateTelegramVoiceReplyFile(text, {
804
+ lang: options.lang,
805
+ rate: options.rate,
806
+ handler: options.handler,
807
+ tempDir: options.tempDir,
808
+ cwd: options.cwd,
809
+ execCommand: options.execCommand,
810
+ }),
811
+ getProgrammaticVoiceHandlers: () =>
812
+ getTelegramOutboundProgrammaticHandlers("voice"),
813
+ });
814
+ }
815
+
816
+ export {
817
+ createTelegramButtonActionStore,
818
+ createTelegramButtonPromptTurn,
819
+ createTelegramButtonReplyPlanner,
820
+ handleTelegramButtonCallbackQuery,
821
+ markTelegramButtonSelected,
822
+ planTelegramButtonReply,
823
+ type TelegramButtonActionStore,
824
+ type TelegramButtonCallbackHandlerDeps,
825
+ type TelegramButtonCallbackQuery,
826
+ type TelegramButtonReplyPlan,
827
+ type TelegramOutboundButtonAction,
828
+ type TelegramOutboundButtonBinding,
829
+ type TelegramOutboundButtonMarkup,
830
+ type TelegramOutboundButtonStoredAction,
831
+ } from "./outbound-buttons.ts";
832
+
833
+ export function createTelegramOutboundReplyPlanner(
834
+ store: Pick<TelegramButtonActionStore, "register">,
835
+ ): (
836
+ markdown: string,
837
+ options?: { binding?: TelegramOutboundButtonBinding },
838
+ ) => TelegramOutboundReplyPlan<TelegramOutboundButtonMarkup> {
839
+ return (markdown, options) => {
840
+ const buttonReply = planTelegramButtonReply(markdown, {
841
+ registerAction: store.register,
842
+ ...(options?.binding ? { binding: options.binding } : {}),
843
+ });
844
+
845
+ // Button replies can also contain <!-- telegram_voice --> markup
846
+ const voiceReply = planTelegramVoiceReply(buttonReply.markdown);
847
+
848
+ return {
849
+ markdown: voiceReply.markdown,
850
+ ...(buttonReply.replyMarkup
851
+ ? { replyMarkup: buttonReply.replyMarkup }
852
+ : {}),
853
+ ...(voiceReply.voiceText ? { voiceText: voiceReply.voiceText } : {}),
854
+ ...(voiceReply.voiceReplies
855
+ ? { voiceReplies: voiceReply.voiceReplies }
856
+ : {}),
857
+ ...(voiceReply.lang ? { lang: voiceReply.lang } : {}),
858
+ ...(voiceReply.rate ? { rate: voiceReply.rate } : {}),
859
+ };
860
+ };
861
+ }
862
+
863
+ /**
864
+ * Create an artifact sender that delivers planned voice replies for a turn.
865
+ * Iterates over `voiceReplies` (or a single `voiceText`) and sends each as
866
+ * a Telegram voice message via the voice reply sender. Throws if no voice
867
+ * reply could be delivered.
868
+ */
869
+
870
+ // --- Outbound Reply Artifacts ---
871
+
872
+ export function createTelegramOutboundReplyArtifactSender(
873
+ deps: TelegramVoiceReplySenderDeps,
874
+ ) {
875
+ const sendVoiceReply = createTelegramVoiceReplySender(deps);
876
+ return async (
877
+ turn: TelegramVoiceReplyTurnView,
878
+ plan: Pick<
879
+ TelegramOutboundReplyPlan,
880
+ "voiceText" | "voiceReplies" | "lang" | "rate" | "replyMarkup"
881
+ >,
882
+ options?: { replyToPrompt?: boolean },
883
+ ): Promise<void> => {
884
+ // Normalize voice replies: either use explicit voiceReplies array or fall back to voiceText
885
+ const voiceReplies = plan.voiceReplies?.length
886
+ ? plan.voiceReplies
887
+ : plan.voiceText
888
+ ? [{ text: plan.voiceText, lang: plan.lang, rate: plan.rate }]
889
+ : [];
890
+
891
+ let anyDelivered = false;
892
+
893
+ for (const reply of voiceReplies) {
894
+ try {
895
+ await sendVoiceReply(turn, reply.text, {
896
+ lang: reply.lang ?? plan.lang,
897
+ rate: reply.rate ?? plan.rate,
898
+ // Only attach reply parameters to the first voice message
899
+ replyToPrompt: options?.replyToPrompt === true && !anyDelivered,
900
+ replyMarkup: !anyDelivered ? plan.replyMarkup : undefined,
901
+ });
902
+ anyDelivered = true;
903
+ } catch {
904
+ // sendVoiceReply already recorded the error; continue to next reply
905
+ }
906
+ }
907
+
908
+ if (!anyDelivered) {
909
+ throw new Error(
910
+ "Failed to send voice reply: every voice synthesis provider failed.",
911
+ );
912
+ }
913
+ };
914
+ }
915
+
916
+ // --- Public Assistant Output Delivery ---
917
+
918
+ export interface TelegramAssistantOutputMutationFence {
919
+ run: <TArgs extends unknown[], TResult>(
920
+ mutation: (...args: TArgs) => Promise<TResult>,
921
+ ...args: TArgs
922
+ ) => Promise<TResult>;
923
+ }
924
+
925
+ export interface TelegramAssistantOutputDeliveryAuthority<TTransportStamp> {
926
+ transportStamp: TTransportStamp;
927
+ route: "direct" | "follower" | "none";
928
+ directEpoch?: number | string;
929
+ followerGeneration?: string;
930
+ target?: TelegramTarget;
931
+ }
932
+
933
+ export function createTelegramAssistantOutputMutationFence(
934
+ isAuthorityActive: () => boolean,
935
+ ): TelegramAssistantOutputMutationFence {
936
+ return {
937
+ run(mutation, ...args) {
938
+ if (!isAuthorityActive()) {
939
+ return Promise.reject(
940
+ new Error(
941
+ "Assistant output lost admission authority before transport mutation.",
942
+ ),
943
+ );
944
+ }
945
+ return mutation(...args);
946
+ },
947
+ };
948
+ }
949
+
950
+ export function createTelegramAssistantOutputSender<
951
+ TTransportStamp,
952
+ TReplyMarkup = unknown,
953
+ >(deps: {
954
+ recordOwnership?: Replies.TelegramReplyOwnershipRecorder["record"];
955
+ sendMessage: (body: TelegramSendMessageBody) => Promise<TelegramSentMessage>;
956
+ sendRichMessage: (
957
+ body: TelegramSendRichMessageBody,
958
+ ) => Promise<TelegramSentMessage>;
959
+ editMessage: (body: TelegramEditMessageTextBody) => Promise<unknown>;
960
+ getAssistantRenderingMode: () => "rich" | "html";
961
+ execCommand: TelegramOutboundTextReplyRuntimeDeps<TReplyMarkup>["execCommand"];
962
+ getHandlers?: TelegramOutboundTextReplyRuntimeDeps<TReplyMarkup>["getHandlers"];
963
+ recordRuntimeEvent?: TelegramOutboundTextReplyRuntimeDeps<TReplyMarkup>["recordRuntimeEvent"];
964
+ }): (
965
+ event: TelegramAssistantSegmentEvent,
966
+ authority: TelegramAssistantOutputDeliveryAuthority<TTransportStamp>,
967
+ isAuthorityActive: () => boolean,
968
+ ) => Promise<void> {
969
+ return async function sendAssistantOutput(
970
+ event,
971
+ authority,
972
+ isAuthorityActive,
973
+ ) {
974
+ const target = authority.target;
975
+ if (!target) {
976
+ throw new Error("Assistant output has no authorized Telegram target.");
977
+ }
978
+ const mutationFence =
979
+ createTelegramAssistantOutputMutationFence(isAuthorityActive);
980
+ const replyRuntime = Replies.createTelegramRenderedMessageDeliveryRuntime({
981
+ recordOwnership: deps.recordOwnership,
982
+ sendMessage(body) {
983
+ return mutationFence.run(deps.sendMessage, body);
984
+ },
985
+ sendRichMessage(body) {
986
+ return mutationFence.run(deps.sendRichMessage, body);
987
+ },
988
+ getAssistantRenderingMode: deps.getAssistantRenderingMode,
989
+ editMessage(body) {
990
+ return mutationFence.run(deps.editMessage, body);
991
+ },
992
+ });
993
+ const outboundRuntime = createTelegramOutboundTextReplyRuntime({
994
+ sendTextReply: replyRuntime.sendTextReply,
995
+ sendMarkdownReply: replyRuntime.sendMarkdownReply,
996
+ execCommand: deps.execCommand,
997
+ getHandlers: deps.getHandlers,
998
+ recordRuntimeEvent: deps.recordRuntimeEvent,
999
+ });
1000
+ await outboundRuntime.sendMarkdownReply(
1001
+ target.chatId,
1002
+ undefined,
1003
+ event.text,
1004
+ { target },
1005
+ );
1006
+ };
1007
+ }