@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,958 @@
1
+ /**
2
+ * Generative application kernel and Telegram installation adapter
3
+ * Zones: generative application state, isolated methods, pi agent tools
4
+ * Owns Generative App identity, installation, invocation, state history, and telegram_bind
5
+ */
6
+
7
+ import { randomUUID } from "node:crypto";
8
+ import {
9
+ appendFile,
10
+ copyFile,
11
+ lstat,
12
+ mkdir,
13
+ readFile,
14
+ rename,
15
+ rm,
16
+ stat,
17
+ writeFile,
18
+ } from "node:fs/promises";
19
+ import { basename, dirname, extname, join, resolve } from "node:path";
20
+ import { Worker } from "node:worker_threads";
21
+
22
+ import { Type } from "@sinclair/typebox";
23
+
24
+ import type { ExtensionAPI } from "./pi.ts";
25
+
26
+ const GENERATIVE_APP_NAME = /^[a-z][a-z0-9-]{0,31}$/u;
27
+ const GENERATIVE_APP_METHOD = /^[a-z][a-z0-9_]{0,31}$/u;
28
+ const GENERATIVE_APP_MAX_MODULE_BYTES = 1024 * 1024;
29
+ const GENERATIVE_APP_MAX_OUTPUT_BYTES = 64 * 1024;
30
+ const GENERATIVE_APP_MAX_STATE_BYTES = 256 * 1024;
31
+ const GENERATIVE_APP_METHOD_TIMEOUT_MS = 10_000;
32
+ const GENERATIVE_APP_LOCK_WAIT_MS = 12_000;
33
+ const GENERATIVE_APP_RUN_MAX_TIMEOUT_MS = 30_000;
34
+ const GENERATIVE_APP_RUN_MAX_ARGS = 64;
35
+ const GENERATIVE_APP_RUN_MAX_STREAM_BYTES = 64 * 1024;
36
+
37
+ export type GenerativeAppJsonValue =
38
+ | null
39
+ | boolean
40
+ | number
41
+ | string
42
+ | GenerativeAppJsonValue[]
43
+ | { [key: string]: GenerativeAppJsonValue };
44
+
45
+ export interface GenerativeAppProcessInput {
46
+ command: string;
47
+ args?: string[];
48
+ cwd: string;
49
+ timeoutMs?: number;
50
+ }
51
+
52
+ export interface GenerativeAppProcessResult {
53
+ code: number;
54
+ killed: boolean;
55
+ stderr: string;
56
+ stdout: string;
57
+ }
58
+
59
+ export interface GenerativeAppMethodContext {
60
+ argument?: GenerativeAppJsonValue;
61
+ revision: number;
62
+ run: (input: GenerativeAppProcessInput) => Promise<GenerativeAppProcessResult>;
63
+ signal: AbortSignal;
64
+ state?: GenerativeAppJsonValue;
65
+ }
66
+
67
+ export interface GenerativeAppMethodResult {
68
+ output: string;
69
+ state?: GenerativeAppJsonValue;
70
+ viewMode?: "new" | "edit";
71
+ }
72
+
73
+ export interface GenerativeAppBoundAction {
74
+ argument?: GenerativeAppJsonValue;
75
+ method: string;
76
+ app: string;
77
+ }
78
+
79
+ export interface GenerativeAppInvocationResult {
80
+ generation: string;
81
+ method: string;
82
+ output: string;
83
+ app: string;
84
+ revision: number;
85
+ stateChanged: boolean;
86
+ viewMode: "new" | "edit";
87
+ }
88
+
89
+ interface GenerativeAppStateEnvelope {
90
+ argument?: GenerativeAppJsonValue;
91
+ method: string;
92
+ revision: number;
93
+ state: GenerativeAppJsonValue;
94
+ }
95
+
96
+ export interface GenerativeAppExecutionFence {
97
+ assertCurrent: () => void;
98
+ signal: AbortSignal;
99
+ }
100
+
101
+ export interface GenerativeAppRuntimeOptions {
102
+ agentDir: string;
103
+ execution?: GenerativeAppExecutionFence;
104
+ methodTimeoutMs?: number;
105
+ }
106
+
107
+ export interface TelegramBindToolRegistrationDeps extends GenerativeAppRuntimeOptions {
108
+ getActiveTurn?: () =>
109
+ | {
110
+ chatId: number;
111
+ replyToMessageId: number;
112
+ target?: { chatId: number; threadId?: number };
113
+ }
114
+ | undefined;
115
+ planOutput?: (
116
+ markdown: string,
117
+ options: { binding: { generation: string; app: string; revision: number } },
118
+ ) => { markdown: string; replyMarkup?: unknown };
119
+ sendMarkdownReply?: (
120
+ chatId: number,
121
+ replyToMessageId: number,
122
+ markdown: string,
123
+ options?: {
124
+ replyMarkup?: unknown;
125
+ target?: { chatId: number; threadId?: number };
126
+ },
127
+ ) => Promise<number | undefined>;
128
+ recordRuntimeEvent?: (
129
+ category: string,
130
+ error: unknown,
131
+ details?: Record<string, unknown>,
132
+ ) => void;
133
+ }
134
+
135
+ function byteLength(value: string): number {
136
+ return Buffer.byteLength(value, "utf8");
137
+ }
138
+
139
+ function wait(ms: number): Promise<void> {
140
+ return new Promise((resolveWait) => setTimeout(resolveWait, ms));
141
+ }
142
+
143
+ function isProcessAlive(pid: number): boolean {
144
+ if (!Number.isInteger(pid) || pid <= 0) return false;
145
+ try {
146
+ process.kill(pid, 0);
147
+ return true;
148
+ } catch (error) {
149
+ return (error as NodeJS.ErrnoException).code === "EPERM";
150
+ }
151
+ }
152
+
153
+ function assertAppName(app: string): void {
154
+ if (!GENERATIVE_APP_NAME.test(app)) {
155
+ throw new Error(
156
+ "Generative App name must match /^[a-z][a-z0-9-]{0,31}$/.",
157
+ );
158
+ }
159
+ }
160
+
161
+ function assertMethod(method: string): void {
162
+ if (!GENERATIVE_APP_METHOD.test(method)) {
163
+ throw new Error(
164
+ "Generative App method must match /^[a-z][a-z0-9_]{0,31}$/.",
165
+ );
166
+ }
167
+ }
168
+
169
+ function assertJsonValue(value: unknown, label: string): GenerativeAppJsonValue {
170
+ let encoded: string;
171
+ try {
172
+ encoded = JSON.stringify(value);
173
+ } catch {
174
+ throw new Error(`${label} must be JSON-serializable.`);
175
+ }
176
+ if (encoded === undefined) throw new Error(`${label} must be a JSON value.`);
177
+ const parsed = JSON.parse(encoded) as GenerativeAppJsonValue;
178
+ if (byteLength(encoded) > GENERATIVE_APP_MAX_STATE_BYTES) {
179
+ throw new Error(`${label} exceeds ${GENERATIVE_APP_MAX_STATE_BYTES} bytes.`);
180
+ }
181
+ return parsed;
182
+ }
183
+
184
+ function getAppsRoot(agentDir: string): string {
185
+ return join(resolve(agentDir), "genapps");
186
+ }
187
+
188
+ async function ensureManagedAppsRoot(
189
+ agentDir: string,
190
+ create: boolean,
191
+ ): Promise<string> {
192
+ const agentRoot = resolve(agentDir);
193
+ if (create) await mkdir(agentRoot, { recursive: true });
194
+ const appsRoot = getAppsRoot(agentDir);
195
+ try {
196
+ const metadata = await lstat(appsRoot);
197
+ if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
198
+ throw new Error("Generative App root must be a managed non-symlink directory.");
199
+ }
200
+ } catch (error) {
201
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT" || !create) throw error;
202
+ await mkdir(appsRoot, { mode: 0o700 });
203
+ const metadata = await lstat(appsRoot);
204
+ if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
205
+ throw new Error("Generative App root must be a managed non-symlink directory.");
206
+ }
207
+ }
208
+ return appsRoot;
209
+ }
210
+
211
+ export function resolveGenerativeAppDir(agentDir: string, app: string): string {
212
+ assertAppName(app);
213
+ return join(getAppsRoot(agentDir), app);
214
+ }
215
+
216
+ export function resolveGenerativeAppModulePath(
217
+ agentDir: string,
218
+ app: string,
219
+ ): string {
220
+ return join(resolveGenerativeAppDir(agentDir, app), `${app}.mjs`);
221
+ }
222
+
223
+ async function writeFileAtomic(path: string, content: string): Promise<void> {
224
+ await mkdir(dirname(path), { recursive: true });
225
+ const temporary = `${path}.${process.pid}.${randomUUID()}.tmp`;
226
+ await writeFile(temporary, content, { encoding: "utf8", mode: 0o600 });
227
+ await rename(temporary, path);
228
+ }
229
+
230
+ async function acquireGenerativeAppTransitionLock(
231
+ appDir: string,
232
+ waitMs = GENERATIVE_APP_LOCK_WAIT_MS,
233
+ ): Promise<() => Promise<void>> {
234
+ const lockDir = `${appDir}.transition.lock`;
235
+ const ownerPath = join(lockDir, "owner.json");
236
+ const token = randomUUID();
237
+ const deadline = Date.now() + waitMs;
238
+ while (true) {
239
+ try {
240
+ await mkdir(lockDir, { mode: 0o700 });
241
+ await writeFile(
242
+ ownerPath,
243
+ `${JSON.stringify({ pid: process.pid, token })}\n`,
244
+ { encoding: "utf8", mode: 0o600 },
245
+ );
246
+ return async () => {
247
+ try {
248
+ const owner = JSON.parse(await readFile(ownerPath, "utf8")) as {
249
+ token?: unknown;
250
+ };
251
+ if (owner.token === token) {
252
+ await rm(lockDir, { recursive: true, force: true });
253
+ }
254
+ } catch {
255
+ // A missing or replaced lock is not owned by this invocation.
256
+ }
257
+ };
258
+ } catch (error) {
259
+ if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
260
+ let ownerPid: number | undefined;
261
+ try {
262
+ const owner = JSON.parse(await readFile(ownerPath, "utf8")) as {
263
+ pid?: unknown;
264
+ };
265
+ if (typeof owner.pid === "number") ownerPid = owner.pid;
266
+ } catch {
267
+ // Lock publication can briefly precede owner publication.
268
+ }
269
+ let ownerlessStale = false;
270
+ if (ownerPid === undefined) {
271
+ try {
272
+ ownerlessStale = Date.now() - (await stat(lockDir)).mtimeMs > 1_000;
273
+ } catch {
274
+ continue;
275
+ }
276
+ }
277
+ if (
278
+ (ownerPid !== undefined && !isProcessAlive(ownerPid)) ||
279
+ ownerlessStale
280
+ ) {
281
+ const reclaimDir = `${appDir}.transition.reclaim`;
282
+ try {
283
+ await mkdir(reclaimDir, { mode: 0o700 });
284
+ } catch (reclaimError) {
285
+ if ((reclaimError as NodeJS.ErrnoException).code !== "EEXIST") {
286
+ throw reclaimError;
287
+ }
288
+ await wait(25);
289
+ continue;
290
+ }
291
+ try {
292
+ let currentOwnerPid: number | undefined;
293
+ try {
294
+ const currentOwner = JSON.parse(
295
+ await readFile(ownerPath, "utf8"),
296
+ ) as { pid?: unknown };
297
+ if (typeof currentOwner.pid === "number") {
298
+ currentOwnerPid = currentOwner.pid;
299
+ }
300
+ } catch {
301
+ // Re-check ownerless staleness below.
302
+ }
303
+ const currentOwnerlessStale = currentOwnerPid === undefined
304
+ ? await stat(lockDir)
305
+ .then((metadata) => Date.now() - metadata.mtimeMs > 1_000)
306
+ .catch(() => false)
307
+ : false;
308
+ if (
309
+ (currentOwnerPid !== undefined && !isProcessAlive(currentOwnerPid)) ||
310
+ currentOwnerlessStale
311
+ ) {
312
+ await rm(lockDir, { recursive: true, force: true });
313
+ }
314
+ } finally {
315
+ await rm(reclaimDir, { recursive: true, force: true });
316
+ }
317
+ continue;
318
+ }
319
+ if (Date.now() >= deadline) {
320
+ throw new Error("Generative App transition is busy in another process.");
321
+ }
322
+ await wait(25);
323
+ }
324
+ }
325
+ }
326
+
327
+ async function assertGenerativeAppModule(path: string): Promise<void> {
328
+ const metadata = await lstat(path);
329
+ if (!metadata.isFile() || metadata.isSymbolicLink()) {
330
+ throw new Error(`Generative App module is not a regular managed file: ${path}`);
331
+ }
332
+ if (metadata.size > GENERATIVE_APP_MAX_MODULE_BYTES) {
333
+ throw new Error(`Generative App module exceeds ${GENERATIVE_APP_MAX_MODULE_BYTES} bytes.`);
334
+ }
335
+ }
336
+
337
+ async function assertManagedAppDir(appDir: string): Promise<void> {
338
+ const metadata = await lstat(appDir);
339
+ if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
340
+ throw new Error("Generative App path must be a managed non-symlink directory.");
341
+ }
342
+ }
343
+
344
+ async function readGenerativeAppGeneration(appDir: string): Promise<string> {
345
+ await assertManagedAppDir(appDir);
346
+ const generation = (await readFile(join(appDir, "generation"), "utf8")).trim();
347
+ if (!/^[0-9a-f]{8}-[0-9a-f-]{27}$/u.test(generation)) {
348
+ throw new Error("Generative App installation generation is invalid.");
349
+ }
350
+ return generation;
351
+ }
352
+
353
+ function normalizeMethodResult(value: unknown): GenerativeAppMethodResult {
354
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
355
+ throw new Error("Generative App method must return an object.");
356
+ }
357
+ const result = value as Record<string, unknown>;
358
+ if (typeof result.output !== "string") {
359
+ throw new Error("Generative App method result.output must be a string.");
360
+ }
361
+ if (byteLength(result.output) > GENERATIVE_APP_MAX_OUTPUT_BYTES) {
362
+ throw new Error(`Generative App output exceeds ${GENERATIVE_APP_MAX_OUTPUT_BYTES} bytes.`);
363
+ }
364
+ const viewMode = result.viewMode ?? "new";
365
+ if (viewMode !== "new" && viewMode !== "edit") {
366
+ throw new Error("Generative App viewMode must be new or edit.");
367
+ }
368
+ return {
369
+ output: result.output,
370
+ ...(Object.hasOwn(result, "state")
371
+ ? { state: assertJsonValue(result.state, "Generative App state") }
372
+ : {}),
373
+ viewMode,
374
+ };
375
+ }
376
+
377
+ async function readStateTimeline(appDir: string): Promise<GenerativeAppStateEnvelope[]> {
378
+ const path = join(appDir, "states.jsonl");
379
+ let content: string;
380
+ try {
381
+ content = await readFile(path, "utf8");
382
+ } catch (error) {
383
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
384
+ throw error;
385
+ }
386
+ const lines = content.split("\n");
387
+ const envelopes: GenerativeAppStateEnvelope[] = [];
388
+ for (let index = 0; index < lines.length; index += 1) {
389
+ const line = lines[index]!.trim();
390
+ if (!line) continue;
391
+ try {
392
+ const parsed = JSON.parse(line) as GenerativeAppStateEnvelope;
393
+ if (
394
+ !parsed ||
395
+ typeof parsed !== "object" ||
396
+ parsed.revision !== envelopes.length ||
397
+ typeof parsed.method !== "string" ||
398
+ !Object.hasOwn(parsed, "state")
399
+ ) throw new Error("invalid envelope");
400
+ parsed.state = assertJsonValue(parsed.state, "Generative App journal state");
401
+ envelopes.push(parsed);
402
+ } catch {
403
+ const hasLaterContent = lines.slice(index + 1).some((entry) => entry.trim());
404
+ if (!hasLaterContent) {
405
+ await writeFileAtomic(
406
+ path,
407
+ envelopes.map((envelope) => JSON.stringify(envelope)).join("\n") +
408
+ (envelopes.length > 0 ? "\n" : ""),
409
+ );
410
+ break;
411
+ }
412
+ throw new Error(`Generative App state journal is corrupt at line ${index + 1}.`);
413
+ }
414
+ }
415
+ return envelopes;
416
+ }
417
+
418
+ async function reconcileCurrentState(
419
+ appDir: string,
420
+ timeline: GenerativeAppStateEnvelope[],
421
+ ): Promise<GenerativeAppJsonValue | undefined> {
422
+ const latest = timeline.at(-1)?.state;
423
+ if (latest === undefined) return undefined;
424
+ const statePath = join(appDir, "state.json");
425
+ let current: GenerativeAppJsonValue | undefined;
426
+ try {
427
+ current = assertJsonValue(
428
+ JSON.parse(await readFile(statePath, "utf8")),
429
+ "Generative App current state",
430
+ );
431
+ } catch {
432
+ current = undefined;
433
+ }
434
+ if (JSON.stringify(current) !== JSON.stringify(latest)) {
435
+ await writeFileAtomic(statePath, `${JSON.stringify(latest, null, 2)}\n`);
436
+ }
437
+ return latest;
438
+ }
439
+
440
+ async function executeGenerativeAppWorker(options: {
441
+ argument?: GenerativeAppJsonValue;
442
+ execution?: GenerativeAppExecutionFence;
443
+ method: string;
444
+ methodTimeoutMs: number;
445
+ modulePath: string;
446
+ app: string;
447
+ revision: number;
448
+ state?: GenerativeAppJsonValue;
449
+ }): Promise<unknown> {
450
+ options.execution?.assertCurrent();
451
+ await assertGenerativeAppModule(options.modulePath);
452
+ return await new Promise((resolveResult, rejectResult) => {
453
+ const worker = new Worker(new URL("./generative-app-worker.mjs", import.meta.url), {
454
+ execArgv: [],
455
+ workerData: {
456
+ argument: options.argument,
457
+ argumentPresent: options.argument !== undefined,
458
+ method: options.method,
459
+ methodTimeoutMs: options.methodTimeoutMs,
460
+ modulePath: options.modulePath,
461
+ app: options.app,
462
+ revision: options.revision,
463
+ runMaxArgs: GENERATIVE_APP_RUN_MAX_ARGS,
464
+ runMaxStreamBytes: GENERATIVE_APP_RUN_MAX_STREAM_BYTES,
465
+ runMaxTimeoutMs: GENERATIVE_APP_RUN_MAX_TIMEOUT_MS,
466
+ state: options.state,
467
+ statePresent: options.state !== undefined,
468
+ },
469
+ });
470
+ let settled = false;
471
+ let terminationError: Error | undefined;
472
+ let terminationStarted = false;
473
+ const finish = (error?: unknown, result?: unknown): void => {
474
+ if (settled) return;
475
+ settled = true;
476
+ clearTimeout(timeout);
477
+ options.execution?.signal.removeEventListener("abort", abort);
478
+ if (error) rejectResult(error);
479
+ else resolveResult(result);
480
+ };
481
+ const terminateAndFinish = (): void => {
482
+ if (terminationStarted || !terminationError) return;
483
+ terminationStarted = true;
484
+ void worker.terminate().then(
485
+ () => finish(terminationError),
486
+ () => finish(terminationError),
487
+ );
488
+ };
489
+ const requestTermination = (error: Error): void => {
490
+ if (settled || terminationError) return;
491
+ terminationError = error;
492
+ worker.postMessage({ type: "abort" });
493
+ const forcedTermination = setTimeout(terminateAndFinish, 250);
494
+ forcedTermination.unref?.();
495
+ };
496
+ const abort = (): void => {
497
+ requestTermination(
498
+ new Error(`Generative App method ${options.method} was cancelled.`),
499
+ );
500
+ };
501
+ const timeout = setTimeout(() => {
502
+ requestTermination(
503
+ new Error(
504
+ `Generative App method timed out after ${options.methodTimeoutMs}ms.`,
505
+ ),
506
+ );
507
+ }, options.methodTimeoutMs);
508
+ timeout.unref?.();
509
+ options.execution?.signal.addEventListener("abort", abort, { once: true });
510
+ worker.on("message", (message: {
511
+ error?: string;
512
+ ok?: boolean;
513
+ result?: unknown;
514
+ type?: string;
515
+ }) => {
516
+ if (terminationError) {
517
+ if (message?.type === "abort-ack") terminateAndFinish();
518
+ } else if (message?.ok === true) {
519
+ finish(undefined, message.result);
520
+ void worker.terminate();
521
+ } else {
522
+ finish(new Error(message?.error || "Generative App worker failed."));
523
+ void worker.terminate();
524
+ }
525
+ });
526
+ worker.once("error", (error) => finish(terminationError ?? error));
527
+ worker.once("exit", (code) => {
528
+ if (terminationError) finish(terminationError);
529
+ else if (!settled && code !== 0) {
530
+ finish(new Error(`Generative App worker exited with code ${code}.`));
531
+ }
532
+ });
533
+ });
534
+ }
535
+
536
+ const invocationQueues = new Map<string, Promise<unknown>>();
537
+
538
+ function serializeInvocation<T>(key: string, operation: () => Promise<T>): Promise<T> {
539
+ const previous = invocationQueues.get(key) ?? Promise.resolve();
540
+ const current = previous.catch(() => undefined).then(operation);
541
+ invocationQueues.set(key, current);
542
+ const cleanup = (): void => {
543
+ if (invocationQueues.get(key) === current) invocationQueues.delete(key);
544
+ };
545
+ void current.then(cleanup, cleanup);
546
+ return current;
547
+ }
548
+
549
+ async function invokeMethod(options: {
550
+ appDir: string;
551
+ argument?: GenerativeAppJsonValue;
552
+ execution?: GenerativeAppExecutionFence;
553
+ expectedGeneration?: string;
554
+ expectedRevision?: number;
555
+ method: string;
556
+ methodTimeoutMs: number;
557
+ modulePath: string;
558
+ app: string;
559
+ }): Promise<GenerativeAppInvocationResult> {
560
+ const generation = await readGenerativeAppGeneration(options.appDir);
561
+ if (
562
+ options.expectedGeneration !== undefined &&
563
+ options.expectedGeneration !== generation
564
+ ) {
565
+ throw new Error(
566
+ `Generative App action is stale: expected generation ${options.expectedGeneration}, current generation ${generation}.`,
567
+ );
568
+ }
569
+ const timeline = await readStateTimeline(options.appDir);
570
+ const state = await reconcileCurrentState(options.appDir, timeline);
571
+ if (options.method !== "init" && state === undefined) {
572
+ throw new Error(`Generative App ${options.app} is not initialized.`);
573
+ }
574
+ const revision = timeline.at(-1)?.revision ?? -1;
575
+ if (
576
+ options.expectedRevision !== undefined &&
577
+ options.expectedRevision !== revision
578
+ ) {
579
+ throw new Error(
580
+ `Generative App action is stale: expected revision ${options.expectedRevision}, current revision ${revision}.`,
581
+ );
582
+ }
583
+ const result = normalizeMethodResult(
584
+ await executeGenerativeAppWorker({
585
+ ...(options.argument !== undefined ? { argument: options.argument } : {}),
586
+ ...(options.execution ? { execution: options.execution } : {}),
587
+ method: options.method,
588
+ methodTimeoutMs: options.methodTimeoutMs,
589
+ modulePath: options.modulePath,
590
+ app: options.app,
591
+ revision,
592
+ ...(state !== undefined ? { state } : {}),
593
+ }),
594
+ );
595
+ if (options.method === "init" && result.state === undefined) {
596
+ throw new Error("Generative App init must return state.");
597
+ }
598
+ let nextRevision = revision;
599
+ if (result.state !== undefined) {
600
+ options.execution?.assertCurrent();
601
+ const envelope: GenerativeAppStateEnvelope = {
602
+ ...(options.argument !== undefined ? { argument: options.argument } : {}),
603
+ method: options.method,
604
+ revision: options.method === "init" ? 0 : revision + 1,
605
+ state: result.state,
606
+ };
607
+ const encodedEnvelope = `${JSON.stringify(envelope)}\n`;
608
+ const encodedState = `${JSON.stringify(result.state, null, 2)}\n`;
609
+ if (options.method === "init") {
610
+ await writeFileAtomic(join(options.appDir, "states.jsonl"), encodedEnvelope);
611
+ } else {
612
+ await appendFile(join(options.appDir, "states.jsonl"), encodedEnvelope, {
613
+ encoding: "utf8",
614
+ mode: 0o600,
615
+ });
616
+ }
617
+ await writeFileAtomic(join(options.appDir, "state.json"), encodedState);
618
+ nextRevision = envelope.revision;
619
+ }
620
+ return {
621
+ generation,
622
+ method: options.method,
623
+ output: result.output,
624
+ app: options.app,
625
+ revision: nextRevision,
626
+ stateChanged: result.state !== undefined,
627
+ viewMode: result.viewMode ?? "new",
628
+ };
629
+ }
630
+
631
+ export async function invokeGenerativeApp(options: GenerativeAppRuntimeOptions & {
632
+ argument?: unknown;
633
+ expectedGeneration?: string;
634
+ expectedRevision?: number;
635
+ method: string;
636
+ app: string;
637
+ }): Promise<GenerativeAppInvocationResult> {
638
+ assertAppName(options.app);
639
+ assertMethod(options.method);
640
+ const argument = options.argument === undefined
641
+ ? undefined
642
+ : assertJsonValue(options.argument, "Generative App argument");
643
+ await ensureManagedAppsRoot(options.agentDir, false);
644
+ const appDir = resolveGenerativeAppDir(options.agentDir, options.app);
645
+ const modulePath = resolveGenerativeAppModulePath(options.agentDir, options.app);
646
+ return await serializeInvocation(appDir, async () => {
647
+ const releaseLock = await acquireGenerativeAppTransitionLock(appDir);
648
+ try {
649
+ return await invokeMethod({
650
+ appDir,
651
+ ...(argument !== undefined ? { argument } : {}),
652
+ ...(options.execution ? { execution: options.execution } : {}),
653
+ ...(options.expectedGeneration !== undefined
654
+ ? { expectedGeneration: options.expectedGeneration }
655
+ : {}),
656
+ ...(options.expectedRevision !== undefined
657
+ ? { expectedRevision: options.expectedRevision }
658
+ : {}),
659
+ method: options.method,
660
+ methodTimeoutMs: options.methodTimeoutMs ?? GENERATIVE_APP_METHOD_TIMEOUT_MS,
661
+ modulePath,
662
+ app: options.app,
663
+ });
664
+ } finally {
665
+ await releaseLock();
666
+ }
667
+ });
668
+ }
669
+
670
+ export async function installGenerativeApp(options: GenerativeAppRuntimeOptions & {
671
+ argument?: unknown;
672
+ app: string;
673
+ replace?: boolean;
674
+ script: string;
675
+ }): Promise<GenerativeAppInvocationResult> {
676
+ assertAppName(options.app);
677
+ const sourcePath = resolve(options.script);
678
+ if (extname(sourcePath) !== ".mjs") {
679
+ throw new Error("Generative App installation requires a .mjs script.");
680
+ }
681
+ if (basename(sourcePath, ".mjs") !== options.app) {
682
+ throw new Error("Generative App script stem must equal its app name.");
683
+ }
684
+ const sourceMetadata = await lstat(sourcePath);
685
+ if (!sourceMetadata.isFile() || sourceMetadata.isSymbolicLink()) {
686
+ throw new Error("Generative App source must be a regular non-symlink file.");
687
+ }
688
+ if (sourceMetadata.size > GENERATIVE_APP_MAX_MODULE_BYTES) {
689
+ throw new Error(`Generative App module exceeds ${GENERATIVE_APP_MAX_MODULE_BYTES} bytes.`);
690
+ }
691
+ const appsRoot = await ensureManagedAppsRoot(options.agentDir, true);
692
+ const appDir = resolveGenerativeAppDir(options.agentDir, options.app);
693
+ return await serializeInvocation(appDir, async () => {
694
+ let installed = false;
695
+ try {
696
+ const metadata = await lstat(appDir);
697
+ if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
698
+ throw new Error(`Generative App ${options.app} path is not a managed directory.`);
699
+ }
700
+ installed = true;
701
+ } catch (error) {
702
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
703
+ }
704
+ if (installed && options.replace !== true) {
705
+ throw new Error(`Generative App ${options.app} is already installed; set replace to true.`);
706
+ }
707
+ if (!installed && options.replace === true) {
708
+ throw new Error(`Generative App ${options.app} is not installed and cannot be replaced.`);
709
+ }
710
+ const releaseLock = installed
711
+ ? await acquireGenerativeAppTransitionLock(appDir)
712
+ : undefined;
713
+ const stagingDir = join(
714
+ appsRoot,
715
+ `.${options.app}.${process.pid}.${randomUUID()}.staging`,
716
+ );
717
+ const stagingModule = join(stagingDir, `${options.app}.mjs`);
718
+ try {
719
+ await mkdir(stagingDir, { recursive: false, mode: 0o700 });
720
+ await copyFile(sourcePath, stagingModule);
721
+ await writeFile(join(stagingDir, "generation"), `${randomUUID()}\n`, {
722
+ encoding: "utf8",
723
+ mode: 0o600,
724
+ });
725
+ const argument = options.argument === undefined
726
+ ? undefined
727
+ : assertJsonValue(options.argument, "Generative App argument");
728
+ const result = await invokeMethod({
729
+ appDir: stagingDir,
730
+ ...(argument !== undefined ? { argument } : {}),
731
+ ...(options.execution ? { execution: options.execution } : {}),
732
+ method: "init",
733
+ methodTimeoutMs: options.methodTimeoutMs ?? GENERATIVE_APP_METHOD_TIMEOUT_MS,
734
+ modulePath: stagingModule,
735
+ app: options.app,
736
+ });
737
+ if (!installed) {
738
+ await rename(stagingDir, appDir);
739
+ return result;
740
+ }
741
+ const backupDir = join(
742
+ appsRoot,
743
+ `.${options.app}.${process.pid}.${randomUUID()}.replaced`,
744
+ );
745
+ await rename(appDir, backupDir);
746
+ try {
747
+ await rename(stagingDir, appDir);
748
+ } catch (error) {
749
+ try {
750
+ await rename(backupDir, appDir);
751
+ } catch (rollbackError) {
752
+ throw new AggregateError(
753
+ [error, rollbackError],
754
+ `Generative App ${options.app} replacement and rollback both failed.`,
755
+ );
756
+ }
757
+ throw error;
758
+ }
759
+ await rm(backupDir, { recursive: true, force: true });
760
+ return result;
761
+ } catch (error) {
762
+ await rm(stagingDir, { recursive: true, force: true });
763
+ throw error;
764
+ } finally {
765
+ await releaseLock?.();
766
+ }
767
+ });
768
+ }
769
+
770
+ export function parseGenerativeAppBoundAction(
771
+ prompt: string,
772
+ ): GenerativeAppBoundAction | undefined {
773
+ if (!prompt.includes("::")) return undefined;
774
+ const match = /^([a-z][a-z0-9-]{0,31})::([a-z][a-z0-9_]{0,31})(?:\(([\s\S]+)\))?$/u.exec(
775
+ prompt,
776
+ );
777
+ if (!match) throw new Error("Malformed Generative App bound action.");
778
+ const [, app, method, encodedArgument] = match;
779
+ if (!app || !method) throw new Error("Malformed Generative App bound action.");
780
+ if (encodedArgument === undefined) return { method, app };
781
+ let argument: unknown;
782
+ try {
783
+ argument = JSON.parse(encodedArgument);
784
+ } catch {
785
+ throw new Error("Generative App bound action argument must be strict JSON.");
786
+ }
787
+ return {
788
+ argument: assertJsonValue(argument, "Generative App bound action argument"),
789
+ method,
790
+ app,
791
+ };
792
+ }
793
+
794
+ export async function invokeGenerativeAppBoundAction(
795
+ options: GenerativeAppRuntimeOptions & {
796
+ expectedGeneration?: string;
797
+ expectedRevision?: number;
798
+ prompt: string;
799
+ },
800
+ ): Promise<GenerativeAppInvocationResult | undefined> {
801
+ const action = parseGenerativeAppBoundAction(options.prompt);
802
+ if (!action) return undefined;
803
+ return await invokeGenerativeApp({
804
+ agentDir: options.agentDir,
805
+ ...(action.argument !== undefined ? { argument: action.argument } : {}),
806
+ ...(options.expectedGeneration !== undefined
807
+ ? { expectedGeneration: options.expectedGeneration }
808
+ : {}),
809
+ ...(options.expectedRevision !== undefined
810
+ ? { expectedRevision: options.expectedRevision }
811
+ : {}),
812
+ method: action.method,
813
+ methodTimeoutMs: options.methodTimeoutMs,
814
+ app: action.app,
815
+ });
816
+ }
817
+
818
+ export async function bindGenerativeApp(options: GenerativeAppRuntimeOptions & {
819
+ argument?: unknown;
820
+ method?: string;
821
+ app: string;
822
+ replace?: boolean;
823
+ script?: string;
824
+ }): Promise<GenerativeAppInvocationResult> {
825
+ const hasScript = typeof options.script === "string";
826
+ const hasMethod = typeof options.method === "string";
827
+ if (hasScript === hasMethod) {
828
+ throw new Error("telegram_bind requires exactly one of script or method.");
829
+ }
830
+ if (!hasScript && options.replace !== undefined) {
831
+ throw new Error("telegram_bind replace is valid only with script.");
832
+ }
833
+ return hasScript
834
+ ? await installGenerativeApp({
835
+ agentDir: options.agentDir,
836
+ ...(options.argument !== undefined ? { argument: options.argument } : {}),
837
+ methodTimeoutMs: options.methodTimeoutMs,
838
+ app: options.app,
839
+ replace: options.replace,
840
+ script: options.script!,
841
+ })
842
+ : await invokeGenerativeApp({
843
+ agentDir: options.agentDir,
844
+ ...(options.argument !== undefined ? { argument: options.argument } : {}),
845
+ method: options.method!,
846
+ methodTimeoutMs: options.methodTimeoutMs,
847
+ app: options.app,
848
+ });
849
+ }
850
+
851
+ export function formatGenerativeAppToolOutput(output: string): string {
852
+ const normalized = output.replace(/^\n+/u, "");
853
+ return `\n${normalized || "(Generative App returned no output)"}`;
854
+ }
855
+
856
+ export function formatDisplayedGenerativeAppToolOutput(): string {
857
+ return "\nGenerative App output was delivered directly to the active Telegram turn. Do not repeat, reformat, summarize, or quote it in the assistant reply.";
858
+ }
859
+
860
+ export function formatGenerativeAppToolError(error: unknown): Error {
861
+ const message = error instanceof Error ? error.message : String(error);
862
+ return new Error(`\n${message.replace(/^\n+/u, "") || "Generative App operation failed."}`);
863
+ }
864
+
865
+ export function registerTelegramBindTool(
866
+ pi: ExtensionAPI,
867
+ deps: TelegramBindToolRegistrationDeps,
868
+ ): void {
869
+ pi.registerTool({
870
+ name: "telegram_bind",
871
+ label: "Telegram Bind",
872
+ description:
873
+ "Install, explicitly replace, or invoke one named method on a managed Generative App; successful output displays directly in the active Telegram turn unless display is false.",
874
+ parameters: Type.Union([
875
+ Type.Object({
876
+ app: Type.String(),
877
+ script: Type.String(),
878
+ replace: Type.Optional(Type.Boolean()),
879
+ display: Type.Optional(Type.Boolean()),
880
+ argument: Type.Optional(Type.Unknown()),
881
+ }, { additionalProperties: false }),
882
+ Type.Object({
883
+ app: Type.String(),
884
+ method: Type.String(),
885
+ display: Type.Optional(Type.Boolean()),
886
+ argument: Type.Optional(Type.Unknown()),
887
+ }, { additionalProperties: false }),
888
+ ]),
889
+ async execute(_toolCallId, params) {
890
+ try {
891
+ const result = await bindGenerativeApp({
892
+ agentDir: deps.agentDir,
893
+ ...(params.argument !== undefined ? { argument: params.argument } : {}),
894
+ ...("method" in params && typeof params.method === "string"
895
+ ? { method: params.method }
896
+ : {}),
897
+ app: params.app,
898
+ ...("replace" in params && typeof params.replace === "boolean"
899
+ ? { replace: params.replace }
900
+ : {}),
901
+ ...("script" in params && typeof params.script === "string"
902
+ ? { script: params.script }
903
+ : {}),
904
+ methodTimeoutMs: deps.methodTimeoutMs,
905
+ });
906
+ const activeTurn = params.display === false
907
+ ? undefined
908
+ : deps.getActiveTurn?.();
909
+ if (activeTurn && deps.planOutput && deps.sendMarkdownReply) {
910
+ try {
911
+ const planned = deps.planOutput(result.output, {
912
+ binding: {
913
+ generation: result.generation,
914
+ app: result.app,
915
+ revision: result.revision,
916
+ },
917
+ });
918
+ const messageId = await deps.sendMarkdownReply(
919
+ activeTurn.chatId,
920
+ activeTurn.replyToMessageId,
921
+ planned.markdown,
922
+ {
923
+ ...(planned.replyMarkup !== undefined
924
+ ? { replyMarkup: planned.replyMarkup }
925
+ : {}),
926
+ ...(activeTurn.target ? { target: activeTurn.target } : {}),
927
+ },
928
+ );
929
+ return {
930
+ content: [{ type: "text", text: formatDisplayedGenerativeAppToolOutput() }],
931
+ details: { ...result, displayed: true, messageId },
932
+ };
933
+ } catch (error) {
934
+ deps.recordRuntimeEvent?.("generative-app", error, {
935
+ phase: "bind-display",
936
+ app: result.app,
937
+ method: result.method,
938
+ });
939
+ return {
940
+ content: [{ type: "text", text: formatGenerativeAppToolOutput(result.output) }],
941
+ details: { ...result, displayed: false, displayFailed: true },
942
+ };
943
+ }
944
+ }
945
+ return {
946
+ content: [{ type: "text", text: formatGenerativeAppToolOutput(result.output) }],
947
+ details: { ...result, displayed: false },
948
+ };
949
+ } catch (error) {
950
+ deps.recordRuntimeEvent?.("generative-app", error, {
951
+ phase: "bind",
952
+ app: params.app,
953
+ });
954
+ throw formatGenerativeAppToolError(error);
955
+ }
956
+ },
957
+ });
958
+ }