@pasko70/pibo 1.0.5 → 1.2.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 (429) hide show
  1. package/README.md +106 -250
  2. package/context/codex-base-prompt.md +4 -0
  3. package/context/compute-worker.md +23 -0
  4. package/context/pibo-native-tooling.md +18 -0
  5. package/context/pibo-system-prompt.md +69 -8
  6. package/dist/api/simple-agent-api.js +136 -0
  7. package/dist/app-context.js +4 -0
  8. package/dist/apps/chat/agent-profiles.js +42 -5
  9. package/dist/apps/chat/agent-store.js +113 -16
  10. package/dist/apps/chat/chat-api-routes.js +311 -0
  11. package/dist/apps/chat/chat-capability-routes.js +90 -0
  12. package/dist/apps/chat/chat-files.js +178 -0
  13. package/dist/apps/chat/chat-request-normalizers.js +681 -0
  14. package/dist/apps/chat/chat-settings-routes.js +75 -0
  15. package/dist/apps/chat/chat-trace-helpers.js +94 -0
  16. package/dist/apps/chat/chat-user-skill-routes.js +149 -0
  17. package/dist/apps/chat/cron-api.js +213 -0
  18. package/dist/apps/chat/data/chat-data-mappers.js +74 -0
  19. package/dist/apps/chat/data/event-command-service.js +75 -0
  20. package/dist/apps/chat/data/navigation-query-service.js +11 -0
  21. package/dist/apps/chat/data/project-service.js +844 -0
  22. package/dist/apps/chat/data/read-state-service.js +42 -0
  23. package/dist/apps/chat/data/room-service.js +52 -0
  24. package/dist/apps/chat/data/session-query-service.js +63 -0
  25. package/dist/apps/chat/data/timeline-query-service.js +96 -0
  26. package/dist/apps/chat/event-log.js +1 -307
  27. package/dist/apps/chat/model-catalog.js +47 -0
  28. package/dist/apps/chat/output-compactor.js +126 -0
  29. package/dist/apps/chat/output-event-policy.js +17 -0
  30. package/dist/apps/chat/project-workflow-human-actions.js +347 -0
  31. package/dist/apps/chat/project-workflow-sessions.js +260 -0
  32. package/dist/apps/chat/provider-auth-actions.js +43 -0
  33. package/dist/apps/chat/ralph-api.js +156 -0
  34. package/dist/apps/chat/read-model.js +1 -218
  35. package/dist/apps/chat/rooms.js +1 -321
  36. package/dist/apps/chat/static-assets.js +996 -0
  37. package/dist/apps/chat/stream.js +29 -6
  38. package/dist/apps/chat/trace.js +179 -1003
  39. package/dist/apps/chat/types/event-store.js +1 -0
  40. package/dist/apps/chat/types/read-model.js +1 -0
  41. package/dist/apps/chat/types/rooms.js +36 -0
  42. package/dist/apps/chat/web-app.js +3168 -1811
  43. package/dist/apps/chat/workflow-catalog.js +572 -0
  44. package/dist/apps/chat/workflow-edge-compatibility.js +51 -0
  45. package/dist/apps/chat/workflow-json-schema-validation.js +335 -0
  46. package/dist/apps/chat/workflow-persistence-model.js +140 -0
  47. package/dist/apps/chat/workflow-persistence.js +633 -0
  48. package/dist/apps/chat/workflow-registered-ref-params.js +130 -0
  49. package/dist/apps/chat/workflow-registered-ref-pickers.js +179 -0
  50. package/dist/apps/chat/workflow-registered-ref-validation.js +210 -0
  51. package/dist/apps/chat/workflow-v2-security-validation.js +93 -0
  52. package/dist/apps/chat/workflow-validation-helpers.js +114 -0
  53. package/dist/apps/chat-ui/assets/{dist-CI0Xj2Cp.js → dist-B4lw9z4F.js} +1 -1
  54. package/dist/apps/chat-ui/assets/{dist-aMr2VYOu.js → dist-BbTaHWON.js} +1 -1
  55. package/dist/apps/chat-ui/assets/{dist-u2OzzOTm.js → dist-BcT_c1EJ.js} +1 -1
  56. package/dist/apps/chat-ui/assets/{dist-Di1ScJ22.js → dist-CGINd7XU.js} +1 -1
  57. package/dist/apps/chat-ui/assets/{dist-wiRpAHIv.js → dist-CrBzZkUp.js} +1 -1
  58. package/dist/apps/chat-ui/assets/{dist-CaNOvqMY.js → dist-CyyISotB.js} +1 -1
  59. package/dist/apps/chat-ui/assets/{dist-zgYUl2B-.js → dist-DFbnFNpX.js} +1 -1
  60. package/dist/apps/chat-ui/assets/{dist-CNlhGq5i.js → dist-DGLWQLX8.js} +1 -1
  61. package/dist/apps/chat-ui/assets/{dist-BGxHKHPX.js → dist-DfcIkFSN.js} +1 -1
  62. package/dist/apps/chat-ui/assets/{dist-DrM-H3e1.js → dist-sKDHTwaT.js} +1 -1
  63. package/dist/apps/chat-ui/assets/{dist-DpmEro5R.js → dist-y9D6la48.js} +1 -1
  64. package/dist/apps/chat-ui/assets/index-C25VYnyb.css +1 -0
  65. package/dist/apps/chat-ui/assets/index-CUkuvI3v.js +165 -0
  66. package/dist/apps/chat-ui/assets/pwa-images/android/launchericon-144x144.png +0 -0
  67. package/dist/apps/chat-ui/assets/pwa-images/android/launchericon-192x192.png +0 -0
  68. package/dist/apps/chat-ui/assets/pwa-images/android/launchericon-48x48.png +0 -0
  69. package/dist/apps/chat-ui/assets/pwa-images/android/launchericon-512x512.png +0 -0
  70. package/dist/apps/chat-ui/assets/pwa-images/android/launchericon-72x72.png +0 -0
  71. package/dist/apps/chat-ui/assets/pwa-images/android/launchericon-96x96.png +0 -0
  72. package/dist/apps/chat-ui/assets/pwa-images/ios/100.png +0 -0
  73. package/dist/apps/chat-ui/assets/pwa-images/ios/1024.png +0 -0
  74. package/dist/apps/chat-ui/assets/pwa-images/ios/114.png +0 -0
  75. package/dist/apps/chat-ui/assets/pwa-images/ios/120.png +0 -0
  76. package/dist/apps/chat-ui/assets/pwa-images/ios/128.png +0 -0
  77. package/dist/apps/chat-ui/assets/pwa-images/ios/144.png +0 -0
  78. package/dist/apps/chat-ui/assets/pwa-images/ios/152.png +0 -0
  79. package/dist/apps/chat-ui/assets/pwa-images/ios/16.png +0 -0
  80. package/dist/apps/chat-ui/assets/pwa-images/ios/167.png +0 -0
  81. package/dist/apps/chat-ui/assets/pwa-images/ios/180.png +0 -0
  82. package/dist/apps/chat-ui/assets/pwa-images/ios/192.png +0 -0
  83. package/dist/apps/chat-ui/assets/pwa-images/ios/20.png +0 -0
  84. package/dist/apps/chat-ui/assets/pwa-images/ios/256.png +0 -0
  85. package/dist/apps/chat-ui/assets/pwa-images/ios/29.png +0 -0
  86. package/dist/apps/chat-ui/assets/pwa-images/ios/32.png +0 -0
  87. package/dist/apps/chat-ui/assets/pwa-images/ios/40.png +0 -0
  88. package/dist/apps/chat-ui/assets/pwa-images/ios/50.png +0 -0
  89. package/dist/apps/chat-ui/assets/pwa-images/ios/512.png +0 -0
  90. package/dist/apps/chat-ui/assets/pwa-images/ios/57.png +0 -0
  91. package/dist/apps/chat-ui/assets/pwa-images/ios/58.png +0 -0
  92. package/dist/apps/chat-ui/assets/pwa-images/ios/60.png +0 -0
  93. package/dist/apps/chat-ui/assets/pwa-images/ios/64.png +0 -0
  94. package/dist/apps/chat-ui/assets/pwa-images/ios/72.png +0 -0
  95. package/dist/apps/chat-ui/assets/pwa-images/ios/76.png +0 -0
  96. package/dist/apps/chat-ui/assets/pwa-images/ios/80.png +0 -0
  97. package/dist/apps/chat-ui/assets/pwa-images/ios/87.png +0 -0
  98. package/dist/apps/chat-ui/assets/pwa-images/windows/LargeTile.scale-100.png +0 -0
  99. package/dist/apps/chat-ui/assets/pwa-images/windows/LargeTile.scale-125.png +0 -0
  100. package/dist/apps/chat-ui/assets/pwa-images/windows/LargeTile.scale-150.png +0 -0
  101. package/dist/apps/chat-ui/assets/pwa-images/windows/LargeTile.scale-200.png +0 -0
  102. package/dist/apps/chat-ui/assets/pwa-images/windows/LargeTile.scale-400.png +0 -0
  103. package/dist/apps/chat-ui/assets/pwa-images/windows/SmallTile.scale-100.png +0 -0
  104. package/dist/apps/chat-ui/assets/pwa-images/windows/SmallTile.scale-125.png +0 -0
  105. package/dist/apps/chat-ui/assets/pwa-images/windows/SmallTile.scale-150.png +0 -0
  106. package/dist/apps/chat-ui/assets/pwa-images/windows/SmallTile.scale-200.png +0 -0
  107. package/dist/apps/chat-ui/assets/pwa-images/windows/SmallTile.scale-400.png +0 -0
  108. package/dist/apps/chat-ui/assets/pwa-images/windows/SplashScreen.scale-100.png +0 -0
  109. package/dist/apps/chat-ui/assets/pwa-images/windows/SplashScreen.scale-125.png +0 -0
  110. package/dist/apps/chat-ui/assets/pwa-images/windows/SplashScreen.scale-150.png +0 -0
  111. package/dist/apps/chat-ui/assets/pwa-images/windows/SplashScreen.scale-200.png +0 -0
  112. package/dist/apps/chat-ui/assets/pwa-images/windows/SplashScreen.scale-400.png +0 -0
  113. package/dist/apps/chat-ui/assets/pwa-images/windows/Square150x150Logo.scale-100.png +0 -0
  114. package/dist/apps/chat-ui/assets/pwa-images/windows/Square150x150Logo.scale-125.png +0 -0
  115. package/dist/apps/chat-ui/assets/pwa-images/windows/Square150x150Logo.scale-150.png +0 -0
  116. package/dist/apps/chat-ui/assets/pwa-images/windows/Square150x150Logo.scale-200.png +0 -0
  117. package/dist/apps/chat-ui/assets/pwa-images/windows/Square150x150Logo.scale-400.png +0 -0
  118. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-16.png +0 -0
  119. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-20.png +0 -0
  120. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-24.png +0 -0
  121. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-256.png +0 -0
  122. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-30.png +0 -0
  123. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-32.png +0 -0
  124. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-36.png +0 -0
  125. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-40.png +0 -0
  126. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-44.png +0 -0
  127. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-48.png +0 -0
  128. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-60.png +0 -0
  129. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-64.png +0 -0
  130. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-72.png +0 -0
  131. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-80.png +0 -0
  132. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-96.png +0 -0
  133. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-16.png +0 -0
  134. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-20.png +0 -0
  135. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-24.png +0 -0
  136. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-256.png +0 -0
  137. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-30.png +0 -0
  138. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-32.png +0 -0
  139. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-36.png +0 -0
  140. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-40.png +0 -0
  141. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-44.png +0 -0
  142. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-48.png +0 -0
  143. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-60.png +0 -0
  144. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-64.png +0 -0
  145. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-72.png +0 -0
  146. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-80.png +0 -0
  147. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-96.png +0 -0
  148. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.scale-100.png +0 -0
  149. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.scale-125.png +0 -0
  150. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.scale-150.png +0 -0
  151. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.scale-200.png +0 -0
  152. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.scale-400.png +0 -0
  153. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-16.png +0 -0
  154. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-20.png +0 -0
  155. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-24.png +0 -0
  156. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-256.png +0 -0
  157. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-30.png +0 -0
  158. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-32.png +0 -0
  159. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-36.png +0 -0
  160. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-40.png +0 -0
  161. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-44.png +0 -0
  162. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-48.png +0 -0
  163. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-60.png +0 -0
  164. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-64.png +0 -0
  165. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-72.png +0 -0
  166. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-80.png +0 -0
  167. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-96.png +0 -0
  168. package/dist/apps/chat-ui/assets/pwa-images/windows/StoreLogo.scale-100.png +0 -0
  169. package/dist/apps/chat-ui/assets/pwa-images/windows/StoreLogo.scale-125.png +0 -0
  170. package/dist/apps/chat-ui/assets/pwa-images/windows/StoreLogo.scale-150.png +0 -0
  171. package/dist/apps/chat-ui/assets/pwa-images/windows/StoreLogo.scale-200.png +0 -0
  172. package/dist/apps/chat-ui/assets/pwa-images/windows/StoreLogo.scale-400.png +0 -0
  173. package/dist/apps/chat-ui/assets/pwa-images/windows/Wide310x150Logo.scale-100.png +0 -0
  174. package/dist/apps/chat-ui/assets/pwa-images/windows/Wide310x150Logo.scale-125.png +0 -0
  175. package/dist/apps/chat-ui/assets/pwa-images/windows/Wide310x150Logo.scale-150.png +0 -0
  176. package/dist/apps/chat-ui/assets/pwa-images/windows/Wide310x150Logo.scale-200.png +0 -0
  177. package/dist/apps/chat-ui/assets/pwa-images/windows/Wide310x150Logo.scale-400.png +0 -0
  178. package/dist/apps/chat-ui/index.html +8 -3
  179. package/dist/apps/chat-ui/manifest.webmanifest +25 -0
  180. package/dist/apps/chat-ui/sw.js +41 -0
  181. package/dist/apps/cli-ui/InkSessionApp.js +1218 -0
  182. package/dist/apps/cli-ui/InkTerminalLine.js +53 -0
  183. package/dist/apps/cli-ui/InkTerminalRow.js +304 -0
  184. package/dist/apps/cli-ui/InkTerminalView.js +25 -0
  185. package/dist/apps/cli-ui/cliSessionsCommand.js +232 -0
  186. package/dist/apps/cli-ui/index.js +8 -0
  187. package/dist/apps/cli-ui/inkColors.js +67 -0
  188. package/dist/apps/cli-ui/inkJson.js +244 -0
  189. package/dist/apps/cli-ui/inkMarkdown.js +122 -0
  190. package/dist/apps/context-files-ui/assets/{dist-DFi2YGux.js → dist-BOiGdrG-.js} +1 -1
  191. package/dist/apps/context-files-ui/assets/{dist-DyfSeBMu.js → dist-DK01b7x4.js} +1 -1
  192. package/dist/apps/context-files-ui/assets/{dist-CwbH_3RN.js → dist-DPG9jOQ-.js} +1 -1
  193. package/dist/apps/context-files-ui/assets/{dist-dTBsFYAl.js → dist-Dp5AH00p.js} +1 -1
  194. package/dist/apps/context-files-ui/assets/{dist-CxRLRmMx.js → dist-DqYw0LH7.js} +1 -1
  195. package/dist/apps/context-files-ui/assets/{dist-MyZgX9K2.js → dist-TF5iO5ML.js} +1 -1
  196. package/dist/apps/context-files-ui/assets/{dist-DQXzt2Ng.js → dist-TbjAhles.js} +1 -1
  197. package/dist/apps/context-files-ui/assets/{dist-YwR9dpb-.js → dist-ZsBbt0uY.js} +1 -1
  198. package/dist/apps/context-files-ui/assets/{dist-CKQF1zEu.js → dist-kmsvtHkH.js} +1 -1
  199. package/dist/apps/context-files-ui/assets/{dist-BJW3917N.js → dist-vnd7PMu3.js} +1 -1
  200. package/dist/apps/context-files-ui/assets/{index-BwRDoHMC.css → index-B92tL3Pp.css} +1 -1
  201. package/dist/apps/context-files-ui/assets/{index-GwvjXytt.js → index-BhAWD3dv.js} +2 -2
  202. package/dist/apps/context-files-ui/index.html +2 -2
  203. package/dist/auth/better-auth.js +2 -1
  204. package/dist/auth/login-actions.js +251 -0
  205. package/dist/auth/openai-codex-usage.js +147 -0
  206. package/dist/bin/pibo.js +0 -0
  207. package/dist/bin/rg.js +15 -0
  208. package/dist/cli-session/fakeSessionSource.js +804 -0
  209. package/dist/cli-session/index.js +3 -0
  210. package/dist/cli-session/localSessionSource.js +1144 -0
  211. package/dist/cli-session/sessionSource.js +13 -0
  212. package/dist/cli.js +142 -14
  213. package/dist/compute/cli.js +415 -0
  214. package/dist/compute/docker.js +827 -0
  215. package/dist/compute/resource-health.js +333 -0
  216. package/dist/compute/resource-policy.js +98 -0
  217. package/dist/config/config.js +9 -5
  218. package/dist/core/context-build.js +677 -0
  219. package/dist/core/model-defaults.js +51 -9
  220. package/dist/core/pibo-home.js +8 -0
  221. package/dist/core/profiles.js +48 -0
  222. package/dist/core/provider-telemetry.js +222 -0
  223. package/dist/core/routed-session.js +441 -47
  224. package/dist/core/runtime-telemetry.js +853 -0
  225. package/dist/core/runtime.js +103 -15
  226. package/dist/core/session-errors.js +47 -0
  227. package/dist/core/session-model.js +39 -0
  228. package/dist/core/session-router.js +292 -62
  229. package/dist/core/shared-app.js +17 -0
  230. package/dist/core/skill-expansion.js +43 -0
  231. package/dist/core/system-prompt-template.js +9 -9
  232. package/dist/core/telemetry-staleness.js +128 -0
  233. package/dist/core/test-output-compaction.js +145 -0
  234. package/dist/core/user-settings.js +73 -0
  235. package/dist/cron/channel.js +28 -0
  236. package/dist/cron/cli.js +230 -0
  237. package/dist/cron/plugin.js +11 -0
  238. package/dist/cron/schedule.js +214 -0
  239. package/dist/cron/service.js +177 -0
  240. package/dist/cron/store.js +349 -0
  241. package/dist/cron/types.js +1 -0
  242. package/dist/data/cli.js +184 -0
  243. package/dist/data/event-log.js +106 -0
  244. package/dist/data/final-app-space-cutover-migration.js +728 -0
  245. package/dist/data/ingest-service.js +389 -0
  246. package/dist/data/message-store.js +62 -0
  247. package/dist/data/navigation-store.js +75 -0
  248. package/dist/data/observation-store.js +46 -0
  249. package/dist/data/payload-store.js +144 -0
  250. package/dist/data/pibo-store.js +59 -0
  251. package/dist/data/schema.js +434 -0
  252. package/dist/data/session-store.js +63 -0
  253. package/dist/data/shared-app-migration.js +757 -0
  254. package/dist/data/sqlite-schema.js +12 -0
  255. package/dist/data/telemetry-preview.js +65 -0
  256. package/dist/data/telemetry-queries.js +212 -0
  257. package/dist/data/telemetry-retention.js +50 -0
  258. package/dist/data/telemetry-rows.js +158 -0
  259. package/dist/data/telemetry.js +357 -0
  260. package/dist/debug/delta-compaction.js +99 -0
  261. package/dist/debug/detail-format.js +86 -0
  262. package/dist/debug/events.js +149 -29
  263. package/dist/debug/failures.js +162 -0
  264. package/dist/debug/index.js +655 -30
  265. package/dist/debug/messages.js +185 -0
  266. package/dist/debug/next-commands.js +6 -0
  267. package/dist/debug/payloads.js +123 -0
  268. package/dist/debug/pty.js +924 -0
  269. package/dist/debug/session.js +45 -15
  270. package/dist/debug/sql.js +1 -1
  271. package/dist/debug/stores.js +18 -13
  272. package/dist/debug/summary.js +72 -0
  273. package/dist/debug/telemetry.js +649 -0
  274. package/dist/debug/tools.js +168 -0
  275. package/dist/debug/trace-render-check.js +151 -0
  276. package/dist/debug/trace.js +152 -27
  277. package/dist/debug/web-artifacts.js +63 -0
  278. package/dist/debug/web-options.js +313 -0
  279. package/dist/debug/web-render-analysis.js +310 -0
  280. package/dist/debug/web-snapshot-browser-scripts.js +303 -0
  281. package/dist/debug/web-streaming-benchmark-analysis.js +605 -0
  282. package/dist/debug/web-streaming-browser-library.js +928 -0
  283. package/dist/debug/web-streaming-browser-scripts.js +242 -0
  284. package/dist/debug/web-streaming-provider-telemetry.js +194 -0
  285. package/dist/debug/web-streaming-report.js +493 -0
  286. package/dist/debug/web-streaming-types.js +1 -0
  287. package/dist/debug/web.js +574 -0
  288. package/dist/gateway/backup.js +83 -0
  289. package/dist/gateway/cli.js +511 -0
  290. package/dist/gateway/fallback.js +155 -0
  291. package/dist/gateway/pidfile.js +84 -0
  292. package/dist/gateway/protocol.js +16 -0
  293. package/dist/gateway/server.js +174 -17
  294. package/dist/gateway/tool.js +54 -51
  295. package/dist/gateway/web.js +74 -2
  296. package/dist/index.js +3 -1
  297. package/dist/local/client.js +3 -3
  298. package/dist/local/extension.js +8 -5
  299. package/dist/plugins/builtin.js +252 -49
  300. package/dist/plugins/chat-vscode-web.js +28 -0
  301. package/dist/plugins/codex-compat.js +0 -41
  302. package/dist/plugins/context-files.js +98 -18
  303. package/dist/plugins/dev-auth.js +124 -0
  304. package/dist/plugins/native-tooling.js +15 -0
  305. package/dist/plugins/registry.js +66 -2
  306. package/dist/plugins/web-annotations.js +27 -0
  307. package/dist/providers/minimax.js +70 -0
  308. package/dist/providers/openai-compat.js +48 -0
  309. package/dist/ralph/channel.js +8 -0
  310. package/dist/ralph/cli.js +152 -0
  311. package/dist/ralph/plugin.js +14 -0
  312. package/dist/ralph/service.js +271 -0
  313. package/dist/ralph/stopping.js +151 -0
  314. package/dist/ralph/store.js +450 -0
  315. package/dist/ralph/templates.js +200 -0
  316. package/dist/ralph/types.js +1 -0
  317. package/dist/reliability/store.js +42 -26
  318. package/dist/runs/registry.js +72 -35
  319. package/dist/session-ui/commandCatalog.js +193 -0
  320. package/dist/session-ui/commandResults.js +95 -0
  321. package/dist/session-ui/index.js +7 -0
  322. package/dist/session-ui/ownerViewModel.js +27 -0
  323. package/dist/session-ui/roomSessionViewModel.js +69 -0
  324. package/dist/session-ui/statusViewModel.js +127 -0
  325. package/dist/session-ui/terminalCards.js +210 -0
  326. package/dist/session-ui/terminalRows.js +937 -0
  327. package/dist/session-ui/terminalValue.js +45 -0
  328. package/dist/sessions/pibo-data-store.js +178 -0
  329. package/dist/sessions/sqlite-store.js +78 -12
  330. package/dist/sessions/store.js +11 -4
  331. package/dist/sessions/workflow-session-kind.js +20 -0
  332. package/dist/setup/cli.js +567 -0
  333. package/dist/shared/trace-async-agent-runs.js +127 -0
  334. package/dist/shared/trace-engine.js +96 -0
  335. package/dist/shared/trace-event-projection.js +679 -0
  336. package/dist/shared/trace-live-reducer.js +191 -0
  337. package/dist/shared/trace-nodes.js +76 -0
  338. package/dist/shared/trace-order.js +11 -10
  339. package/dist/shared/trace-patch-nodes.js +83 -0
  340. package/dist/shared/trace-run-notifications.js +69 -0
  341. package/dist/shared/trace-subagent-links.js +46 -0
  342. package/dist/shared/trace-transcript.js +303 -0
  343. package/dist/shared/trace-types.js +1 -0
  344. package/dist/shared-app.js +4 -0
  345. package/dist/signals/aggregate.js +65 -0
  346. package/dist/signals/events.js +1 -0
  347. package/dist/signals/projector.js +158 -0
  348. package/dist/signals/registry.js +513 -0
  349. package/dist/signals/store.js +1 -0
  350. package/dist/signals/types.js +1 -0
  351. package/dist/skills/cli.js +117 -0
  352. package/dist/tools/agent-browser-leases.js +219 -0
  353. package/dist/tools/agent-browser-wrapper.js +99 -0
  354. package/dist/tools/browser-pool.js +623 -0
  355. package/dist/tools/browser-use-cdp.js +56 -4
  356. package/dist/tools/browser-use-leases.js +215 -37
  357. package/dist/tools/browser-use-wrapper.js +508 -65
  358. package/dist/tools/cdp-client.js +189 -0
  359. package/dist/tools/guides.js +203 -4
  360. package/dist/tools/index.js +666 -16
  361. package/dist/tools/npm-runtime.js +136 -0
  362. package/dist/tools/registry.js +107 -8
  363. package/dist/tools/runtime/index.js +3 -0
  364. package/dist/tools/runtime/node-backend.js +225 -0
  365. package/dist/tools/runtime/node-worker-source.js +206 -0
  366. package/dist/tools/runtime/python-backend.js +227 -0
  367. package/dist/tools/runtime/python-worker-source.js +178 -0
  368. package/dist/tools/runtime/registry.js +255 -0
  369. package/dist/tools/runtime/tool.js +168 -0
  370. package/dist/tools/runtime/types.js +1 -0
  371. package/dist/tools/web-search.js +2 -1
  372. package/dist/user-skills/installer.js +214 -0
  373. package/dist/user-skills/manager.js +35 -0
  374. package/dist/user-skills/store.js +267 -0
  375. package/dist/user-skills/types.js +1 -0
  376. package/dist/web/auth.js +5 -1
  377. package/dist/web/channel.js +86 -0
  378. package/dist/web/http.js +79 -14
  379. package/dist/web-annotations/api.js +348 -0
  380. package/dist/web-annotations/attachments.js +201 -0
  381. package/dist/web-annotations/cdp.js +1107 -0
  382. package/dist/web-annotations/index.js +7 -0
  383. package/dist/web-annotations/store.js +407 -0
  384. package/dist/web-annotations/tools.js +350 -0
  385. package/dist/web-annotations/types.js +34 -0
  386. package/dist/web-annotations/validation.js +288 -0
  387. package/docs/README.md +23 -0
  388. package/docs/ops/install-developer-host.md +112 -0
  389. package/docs/ops/install-user-host.md +76 -0
  390. package/docs/ops/upgrade-user-to-developer-host.md +69 -0
  391. package/package.json +24 -10
  392. package/{.codex/skills → skills/builtin}/pi-agent-harness/SKILL.md +24 -24
  393. package/skills/builtin/pibo-docker-system/SKILL.md +170 -0
  394. package/skills/builtin/pibo-spec-writing/SKILL.md +330 -0
  395. package/skills/builtin/prd/SKILL.md +143 -0
  396. package/skills/builtin/ralph-loop/SKILL.md +359 -0
  397. package/skills/builtin/ralph-prd-json/SKILL.md +123 -0
  398. package/skills/builtin/skill-creator/LICENSE.txt +202 -0
  399. package/skills/builtin/skill-creator/SKILL.md +513 -0
  400. package/skills/builtin/skill-creator/agents/analyzer.md +274 -0
  401. package/skills/builtin/skill-creator/agents/comparator.md +202 -0
  402. package/skills/builtin/skill-creator/agents/grader.md +223 -0
  403. package/skills/builtin/skill-creator/assets/eval_review.html +146 -0
  404. package/skills/builtin/skill-creator/eval-viewer/generate_review.py +471 -0
  405. package/skills/builtin/skill-creator/eval-viewer/viewer.html +1325 -0
  406. package/skills/builtin/skill-creator/references/schemas.md +430 -0
  407. package/skills/builtin/skill-creator/scripts/__init__.py +0 -0
  408. package/skills/builtin/skill-creator/scripts/aggregate_benchmark.py +401 -0
  409. package/skills/builtin/skill-creator/scripts/generate_report.py +326 -0
  410. package/skills/builtin/skill-creator/scripts/improve_description.py +247 -0
  411. package/skills/builtin/skill-creator/scripts/package_skill.py +136 -0
  412. package/skills/builtin/skill-creator/scripts/quick_validate.py +103 -0
  413. package/skills/builtin/skill-creator/scripts/run_eval.py +310 -0
  414. package/skills/builtin/skill-creator/scripts/run_loop.py +328 -0
  415. package/skills/builtin/skill-creator/scripts/utils.py +47 -0
  416. package/skills/builtin/web-annotations/SKILL.md +93 -0
  417. package/dist/apps/chat-ui/assets/index-B_E935fP.js +0 -151
  418. package/dist/apps/chat-ui/assets/index-Dk-opWl3.css +0 -1
  419. package/dist/env.js +0 -32
  420. package/dist/plugins/core-tools.js +0 -94
  421. package/dist/plugins/example.js +0 -67
  422. package/dist/plugins/remote-agent.js +0 -9
  423. package/dist/remote/channel.js +0 -176
  424. package/dist/remote/client.js +0 -92
  425. package/dist/remote/examples/tui-controller.js +0 -263
  426. package/dist/remote/protocol.js +0 -55
  427. package/dist/remote/session-client.js +0 -189
  428. package/dist/sessions/bindings.js +0 -41
  429. /package/{.codex/skills → skills/builtin}/pi-agent-harness/agents/openai.yaml +0 -0
@@ -1,92 +0,0 @@
1
- import readline from "node:readline/promises";
2
- import { stdin as input, stdout as output } from "node:process";
3
- import { DEFAULT_REMOTE_AGENT_HOST, DEFAULT_REMOTE_AGENT_PORT } from "./protocol.js";
4
- import { RemoteAgentSessionClient } from "./session-client.js";
5
- function isSessionStatus(value) {
6
- if (!value || typeof value !== "object")
7
- return false;
8
- const candidate = value;
9
- return (typeof candidate.sessionKey === "string" &&
10
- typeof candidate.queuedMessages === "number" &&
11
- typeof candidate.processing === "boolean");
12
- }
13
- function printResponse(frame) {
14
- if (frame.ok)
15
- return;
16
- console.error(`\nerror: ${frame.error?.message ?? "request failed"}`);
17
- }
18
- function printExecutionResult(event) {
19
- if (event.action === "status" && isSessionStatus(event.result)) {
20
- console.error(`status: session=${event.result.sessionKey} queued=${event.result.queuedMessages} processing=${event.result.processing} streaming=${event.result.streaming}`);
21
- return;
22
- }
23
- if (event.action === "clear_queue" && event.result && typeof event.result === "object") {
24
- const cleared = event.result.cleared;
25
- console.error(`clear: removed ${typeof cleared === "number" ? cleared : 0} queued message(s)`);
26
- return;
27
- }
28
- console.error(`${event.action}: ${JSON.stringify(event.result)}`);
29
- }
30
- function printEvent(event, state) {
31
- if (event.type === "assistant_delta") {
32
- state.sawAssistantDelta = true;
33
- output.write(event.text);
34
- return;
35
- }
36
- if (event.type === "assistant_message") {
37
- if (!state.sawAssistantDelta) {
38
- output.write(event.text);
39
- }
40
- state.sawAssistantDelta = false;
41
- output.write("\n");
42
- return;
43
- }
44
- if (event.type === "message_started") {
45
- state.sawAssistantDelta = false;
46
- output.write("assistant> ");
47
- return;
48
- }
49
- if (event.type === "session_error") {
50
- console.error(`\nsession error: ${event.error}`);
51
- return;
52
- }
53
- if (event.type === "execution_result") {
54
- printExecutionResult(event);
55
- }
56
- }
57
- export async function runRemoteAgentClient(options = {}) {
58
- const resolvedOptions = {
59
- host: options.host ?? DEFAULT_REMOTE_AGENT_HOST,
60
- port: options.port ?? DEFAULT_REMOTE_AGENT_PORT,
61
- sessionName: options.sessionName ?? "default",
62
- profile: options.profile ?? "pibo-minimal",
63
- };
64
- const client = await RemoteAgentSessionClient.connect(resolvedOptions);
65
- const slashCommands = client.getSlashCommands();
66
- console.error(`connected to pibo remote agent at ${resolvedOptions.host}:${resolvedOptions.port}`);
67
- console.error(`session: ${client.binding.sessionKey}`);
68
- console.error(`profile: ${client.binding.originalProfile}`);
69
- console.error(`commands: ${[...slashCommands.keys(), "/quit"].join(", ")}`);
70
- const renderState = { sawAssistantDelta: false };
71
- client.onEvent((event) => printEvent(event, renderState));
72
- const rl = readline.createInterface({ input, output });
73
- try {
74
- while (true) {
75
- const text = (await rl.question("remote> ")).trim();
76
- if (!text)
77
- continue;
78
- if (text === "/quit" || text === "/exit")
79
- break;
80
- const action = slashCommands.get(text);
81
- if (action) {
82
- client.sendExecution(action).then(printResponse).catch((error) => console.error(`\nerror: ${error.message}`));
83
- continue;
84
- }
85
- client.sendMessage(text).then(printResponse).catch((error) => console.error(`\nerror: ${error.message}`));
86
- }
87
- }
88
- finally {
89
- rl.close();
90
- client.close();
91
- }
92
- }
@@ -1,263 +0,0 @@
1
- import { Box, Container, Spacer, Text } from "@mariozechner/pi-tui";
2
- import { InitialSessionContextBuilder } from "../../core/profiles.js";
3
- import { runPiboTui } from "../../core/runtime.js";
4
- import { DEFAULT_REMOTE_AGENT_HOST, DEFAULT_REMOTE_AGENT_PORT, } from "../protocol.js";
5
- import { createRemoteSlashCommandMap, RemoteAgentSessionClient } from "../session-client.js";
6
- const LOCAL_PI_TUI_COMMANDS = new Set([
7
- "settings",
8
- "model",
9
- "scoped-models",
10
- "export",
11
- "import",
12
- "share",
13
- "copy",
14
- "name",
15
- "session",
16
- "changelog",
17
- "hotkeys",
18
- "fork",
19
- "clone",
20
- "tree",
21
- "login",
22
- "logout",
23
- "new",
24
- "compact",
25
- "reload",
26
- "debug",
27
- "resume",
28
- "quit",
29
- ]);
30
- const REMOTE_MESSAGE_TYPE = "pibo.remote";
31
- function createRemoteControllerProfile() {
32
- return new InitialSessionContextBuilder("pibo-remote-controller")
33
- .withBuiltinTools("disabled")
34
- .createSession();
35
- }
36
- function bg(color, text) {
37
- return `\x1b[48;5;${color}m${text}\x1b[0m`;
38
- }
39
- function fg(color, text) {
40
- return `\x1b[38;5;${color}m${text}\x1b[0m`;
41
- }
42
- function bold(text) {
43
- return `\x1b[1m${text}\x1b[22m`;
44
- }
45
- function getRemoteMessageStyle(role) {
46
- if (role === "user") {
47
- return { label: "you -> remote", bgColor: 24, labelColor: 117 };
48
- }
49
- if (role === "assistant") {
50
- return { label: "remote assistant", bgColor: 22, labelColor: 120 };
51
- }
52
- if (role === "execution") {
53
- return { label: "remote execution", bgColor: 58, labelColor: 229 };
54
- }
55
- if (role === "error") {
56
- return { label: "remote error", bgColor: 52, labelColor: 210 };
57
- }
58
- return { label: "remote session", bgColor: 236, labelColor: 250 };
59
- }
60
- function createRemoteMessageComponent(content, details) {
61
- const style = getRemoteMessageStyle(details.role);
62
- const container = new Container();
63
- const box = new Box(1, 1, (text) => bg(style.bgColor, text));
64
- box.addChild(new Text(bold(fg(style.labelColor, style.label)), 0, 0));
65
- box.addChild(new Spacer(1));
66
- box.addChild(new Text(content, 0, 0));
67
- container.addChild(new Spacer(1));
68
- container.addChild(box);
69
- return container;
70
- }
71
- function createTuiSlashCommandMap(capabilities) {
72
- const commands = createRemoteSlashCommandMap(capabilities);
73
- for (const command of commands.keys()) {
74
- if (LOCAL_PI_TUI_COMMANDS.has(command.slice(1))) {
75
- commands.delete(command);
76
- }
77
- }
78
- return commands;
79
- }
80
- function createRemoteAutocompleteProvider(current, allowedCommands) {
81
- return {
82
- async getSuggestions(lines, cursorLine, cursorCol, options) {
83
- const suggestions = await current.getSuggestions(lines, cursorLine, cursorCol, options);
84
- const beforeCursor = (lines[cursorLine] ?? "").slice(0, cursorCol);
85
- if (!suggestions || !beforeCursor.startsWith("/") || beforeCursor.includes(" ")) {
86
- return suggestions;
87
- }
88
- const items = suggestions.items.filter((item) => allowedCommands.has(item.value));
89
- return items.length > 0 ? { ...suggestions, items } : null;
90
- },
91
- applyCompletion(lines, cursorLine, cursorCol, item, prefix) {
92
- return current.applyCompletion(lines, cursorLine, cursorCol, item, prefix);
93
- },
94
- shouldTriggerFileCompletion: current.shouldTriggerFileCompletion
95
- ? (lines, cursorLine, cursorCol) => current.shouldTriggerFileCompletion(lines, cursorLine, cursorCol)
96
- : undefined,
97
- };
98
- }
99
- function isSessionStatus(value) {
100
- if (!value || typeof value !== "object")
101
- return false;
102
- const candidate = value;
103
- return (typeof candidate.sessionKey === "string" &&
104
- typeof candidate.queuedMessages === "number" &&
105
- typeof candidate.processing === "boolean");
106
- }
107
- function formatExecutionResult(event) {
108
- if (event.action === "status" && isSessionStatus(event.result)) {
109
- return `status: session=${event.result.sessionKey} queued=${event.result.queuedMessages} processing=${event.result.processing} streaming=${event.result.streaming}`;
110
- }
111
- if (event.action === "clear_queue" && event.result && typeof event.result === "object") {
112
- const cleared = event.result.cleared;
113
- return `clear: removed ${typeof cleared === "number" ? cleared : 0} queued message(s)`;
114
- }
115
- return `${event.action}: ${JSON.stringify(event.result)}`;
116
- }
117
- function sendTuiMessage(pi, content, details) {
118
- pi.sendMessage({
119
- customType: REMOTE_MESSAGE_TYPE,
120
- content,
121
- display: true,
122
- details,
123
- });
124
- }
125
- function formatConnectedMessage(client, slashCommands) {
126
- const commands = [...slashCommands.keys()].join(", ") || "none";
127
- return [
128
- `Connected to pibo remote session ${client.binding.sessionKey}.`,
129
- `Profile: ${client.binding.originalProfile}`,
130
- `Remote commands: ${commands}`,
131
- "Pi TUI built-in slash commands stay local.",
132
- ].join("\n");
133
- }
134
- export function createRemoteAgentTuiExtension(options = {}) {
135
- const resolvedOptions = {
136
- host: options.host ?? DEFAULT_REMOTE_AGENT_HOST,
137
- port: options.port ?? DEFAULT_REMOTE_AGENT_PORT,
138
- sessionName: options.sessionName ?? "default",
139
- profile: options.profile ?? "pibo-minimal",
140
- };
141
- return (pi) => {
142
- let client;
143
- let connectPromise;
144
- let slashCommands = new Map();
145
- let context;
146
- let assistantBuffer = "";
147
- let autocompleteRefreshed = false;
148
- const registeredCommands = new Set();
149
- pi.registerMessageRenderer(REMOTE_MESSAGE_TYPE, (message) => {
150
- return createRemoteMessageComponent(String(message.content), message.details ?? { role: "system" });
151
- });
152
- const setStatus = (text) => {
153
- context?.ui.setStatus("pibo.remote", text);
154
- };
155
- const handleRemoteEvent = (event) => {
156
- if (event.type === "message_started") {
157
- assistantBuffer = "";
158
- setStatus("remote running");
159
- return;
160
- }
161
- if (event.type === "assistant_delta") {
162
- assistantBuffer += event.text;
163
- return;
164
- }
165
- if (event.type === "assistant_message") {
166
- sendTuiMessage(pi, event.text || assistantBuffer, { role: "assistant", event });
167
- assistantBuffer = "";
168
- setStatus("remote connected");
169
- return;
170
- }
171
- if (event.type === "execution_result") {
172
- sendTuiMessage(pi, formatExecutionResult(event), { role: "execution", event });
173
- setStatus("remote connected");
174
- return;
175
- }
176
- if (event.type === "session_error") {
177
- sendTuiMessage(pi, `Remote error: ${event.error}`, { role: "error", event });
178
- setStatus("remote error");
179
- }
180
- };
181
- const ensureClient = async (ctx) => {
182
- context = ctx;
183
- if (client)
184
- return client;
185
- if (connectPromise)
186
- return connectPromise;
187
- setStatus("remote connecting");
188
- connectPromise = RemoteAgentSessionClient.connect(resolvedOptions)
189
- .then((connectedClient) => {
190
- client = connectedClient;
191
- slashCommands = createTuiSlashCommandMap(connectedClient.capabilities);
192
- for (const [slashCommand, action] of slashCommands) {
193
- const name = slashCommand.slice(1);
194
- if (registeredCommands.has(name))
195
- continue;
196
- registeredCommands.add(name);
197
- const description = connectedClient.capabilities.actions.find((candidate) => candidate.name === action)?.description ??
198
- `Run remote gateway action "${action}".`;
199
- pi.registerCommand(name, {
200
- description,
201
- async handler() {
202
- sendTuiMessage(pi, slashCommand, { role: "user" });
203
- await connectedClient.sendExecution(action);
204
- },
205
- });
206
- }
207
- if (!autocompleteRefreshed) {
208
- const allowedCommands = new Set([...slashCommands.keys()].map((command) => command.slice(1)));
209
- allowedCommands.add("quit");
210
- ctx.ui.addAutocompleteProvider((current) => createRemoteAutocompleteProvider(current, allowedCommands));
211
- autocompleteRefreshed = true;
212
- }
213
- connectedClient.onEvent(handleRemoteEvent);
214
- setStatus("remote connected");
215
- sendTuiMessage(pi, formatConnectedMessage(connectedClient, slashCommands), { role: "system" });
216
- return connectedClient;
217
- })
218
- .catch((error) => {
219
- connectPromise = undefined;
220
- setStatus("remote offline");
221
- sendTuiMessage(pi, `Remote connection failed: ${error.message}`, { role: "error" });
222
- throw error;
223
- });
224
- return connectPromise;
225
- };
226
- pi.on("session_start", async (_event, ctx) => {
227
- await ensureClient(ctx).catch(() => { });
228
- });
229
- pi.on("session_shutdown", () => {
230
- client?.close();
231
- client = undefined;
232
- connectPromise = undefined;
233
- });
234
- pi.on("input", async (event, ctx) => {
235
- const text = event.text.trim();
236
- if (!text)
237
- return { action: "continue" };
238
- try {
239
- const connectedClient = await ensureClient(ctx);
240
- sendTuiMessage(pi, text, { role: "user" });
241
- const action = slashCommands.get(text);
242
- if (action) {
243
- await connectedClient.sendExecution(action);
244
- }
245
- else {
246
- await connectedClient.sendMessage(event.text);
247
- }
248
- }
249
- catch (error) {
250
- const message = error instanceof Error ? error.message : String(error);
251
- sendTuiMessage(pi, `Remote request failed: ${message}`, { role: "error" });
252
- }
253
- return { action: "handled" };
254
- });
255
- };
256
- }
257
- export async function runRemoteAgentTui(options = {}) {
258
- await runPiboTui({
259
- persistSession: false,
260
- profile: createRemoteControllerProfile(),
261
- extensionFactories: [createRemoteAgentTuiExtension(options)],
262
- });
263
- }
@@ -1,55 +0,0 @@
1
- export const DEFAULT_REMOTE_AGENT_HOST = "127.0.0.1";
2
- export const DEFAULT_REMOTE_AGENT_PORT = 4790;
3
- export const REMOTE_AGENT_CHANNEL_NAME = "remote-agent";
4
- function isJsonValue(value) {
5
- if (value === null ||
6
- typeof value === "string" ||
7
- typeof value === "boolean" ||
8
- (typeof value === "number" && Number.isFinite(value))) {
9
- return true;
10
- }
11
- if (Array.isArray(value)) {
12
- return value.every(isJsonValue);
13
- }
14
- if (typeof value === "object") {
15
- return Object.values(value).every(isJsonValue);
16
- }
17
- return false;
18
- }
19
- export function encodeRemoteAgentFrame(frame) {
20
- return `${JSON.stringify(frame)}\n`;
21
- }
22
- export function remoteAgentErrorResponse(id, error) {
23
- return {
24
- type: "remote_res",
25
- id,
26
- ok: false,
27
- error: { message: error instanceof Error ? error.message : String(error) },
28
- };
29
- }
30
- export function isRemoteAgentRequestFrame(value) {
31
- if (!value || typeof value !== "object")
32
- return false;
33
- const frame = value;
34
- if (typeof frame.id !== "string")
35
- return false;
36
- if (frame.type === "remote_attach") {
37
- return (typeof frame.sessionName === "string" &&
38
- frame.sessionName.length > 0 &&
39
- (frame.profile === undefined || typeof frame.profile === "string"));
40
- }
41
- if (frame.type === "remote_input") {
42
- if (!frame.input || typeof frame.input !== "object")
43
- return false;
44
- const input = frame.input;
45
- if (input.type === "message")
46
- return typeof input.text === "string";
47
- if (input.type === "execution") {
48
- return typeof input.action === "string" && (input.params === undefined || isJsonValue(input.params));
49
- }
50
- }
51
- if (frame.type === "remote_capabilities") {
52
- return true;
53
- }
54
- return false;
55
- }
@@ -1,189 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { connect } from "node:net";
3
- import { DEFAULT_REMOTE_AGENT_HOST, DEFAULT_REMOTE_AGENT_PORT, encodeRemoteAgentFrame, } from "./protocol.js";
4
- function parseJsonLine(line) {
5
- try {
6
- return JSON.parse(line);
7
- }
8
- catch {
9
- return undefined;
10
- }
11
- }
12
- function isBinding(value) {
13
- if (!value || typeof value !== "object")
14
- return false;
15
- const candidate = value;
16
- return typeof candidate.sessionKey === "string" && typeof candidate.originalProfile === "string";
17
- }
18
- function isCapabilities(value) {
19
- if (!value || typeof value !== "object")
20
- return false;
21
- const candidate = value;
22
- return Array.isArray(candidate.actions);
23
- }
24
- export function createRemoteSlashCommandMap(capabilities) {
25
- const commands = new Map();
26
- for (const action of capabilities.actions) {
27
- for (const slashCommand of action.slashCommands) {
28
- commands.set(`/${slashCommand}`, action.name);
29
- }
30
- }
31
- return commands;
32
- }
33
- export class RemoteAgentSessionClient {
34
- socket;
35
- binding;
36
- capabilities;
37
- eventListeners = new Set();
38
- pendingResponses = new Map();
39
- buffer = "";
40
- constructor(socket, attached) {
41
- this.socket = socket;
42
- this.binding = attached.binding;
43
- this.capabilities = attached.capabilities;
44
- this.socket.on("data", (chunk) => this.handleData(String(chunk)));
45
- this.socket.once("close", () => this.rejectPendingResponses(new Error("Remote agent connection closed")));
46
- this.socket.once("error", (error) => this.rejectPendingResponses(error));
47
- }
48
- static async connect(options = {}) {
49
- const resolvedOptions = {
50
- host: options.host ?? DEFAULT_REMOTE_AGENT_HOST,
51
- port: options.port ?? DEFAULT_REMOTE_AGENT_PORT,
52
- sessionName: options.sessionName ?? "default",
53
- profile: options.profile ?? "pibo-minimal",
54
- };
55
- const socket = connect({ host: resolvedOptions.host, port: resolvedOptions.port });
56
- socket.setEncoding("utf-8");
57
- await new Promise((resolve, reject) => {
58
- socket.once("connect", resolve);
59
- socket.once("error", reject);
60
- });
61
- const attached = await attachRemoteAgent(socket, resolvedOptions);
62
- return new RemoteAgentSessionClient(socket, attached);
63
- }
64
- onEvent(listener) {
65
- this.eventListeners.add(listener);
66
- return () => this.eventListeners.delete(listener);
67
- }
68
- getSlashCommands() {
69
- return createRemoteSlashCommandMap(this.capabilities);
70
- }
71
- sendMessage(text) {
72
- return this.sendInput({ type: "message", text });
73
- }
74
- sendExecution(action, params) {
75
- return this.sendInput(params === undefined ? { type: "execution", action } : { type: "execution", action, params });
76
- }
77
- close() {
78
- this.socket.end();
79
- }
80
- sendInput(input) {
81
- return this.sendRequest({ type: "remote_input", id: randomUUID(), input });
82
- }
83
- sendRequest(frame) {
84
- if (this.socket.destroyed) {
85
- return Promise.reject(new Error("Remote agent connection is closed"));
86
- }
87
- return new Promise((resolve, reject) => {
88
- this.pendingResponses.set(frame.id, { resolve, reject });
89
- this.socket.write(encodeRemoteAgentFrame(frame));
90
- });
91
- }
92
- handleData(chunk) {
93
- this.buffer += chunk;
94
- let newlineIndex = this.buffer.indexOf("\n");
95
- while (newlineIndex !== -1) {
96
- const line = this.buffer.slice(0, newlineIndex).trim();
97
- this.buffer = this.buffer.slice(newlineIndex + 1);
98
- this.handleFrame(line ? parseJsonLine(line) : undefined);
99
- newlineIndex = this.buffer.indexOf("\n");
100
- }
101
- }
102
- handleFrame(frame) {
103
- if (!frame)
104
- return;
105
- if (frame.type === "remote_res") {
106
- const pending = this.pendingResponses.get(frame.id);
107
- if (!pending)
108
- return;
109
- this.pendingResponses.delete(frame.id);
110
- if (frame.ok) {
111
- pending.resolve(frame);
112
- }
113
- else {
114
- pending.reject(new Error(frame.error?.message ?? "Remote request failed"));
115
- }
116
- return;
117
- }
118
- if (frame.type === "remote_event") {
119
- for (const listener of this.eventListeners) {
120
- listener(frame.payload);
121
- }
122
- }
123
- }
124
- rejectPendingResponses(error) {
125
- for (const pending of this.pendingResponses.values()) {
126
- pending.reject(error);
127
- }
128
- this.pendingResponses.clear();
129
- }
130
- }
131
- async function attachRemoteAgent(socket, options) {
132
- const id = randomUUID();
133
- return await new Promise((resolve, reject) => {
134
- let buffer = "";
135
- const cleanup = () => {
136
- socket.off("data", onData);
137
- socket.off("error", onError);
138
- socket.off("close", onClose);
139
- };
140
- const onError = (error) => {
141
- cleanup();
142
- reject(error);
143
- };
144
- const onClose = () => {
145
- cleanup();
146
- reject(new Error("Remote agent connection closed before attach completed"));
147
- };
148
- const onData = (chunk) => {
149
- buffer += String(chunk);
150
- let newlineIndex = buffer.indexOf("\n");
151
- while (newlineIndex !== -1) {
152
- const line = buffer.slice(0, newlineIndex).trim();
153
- buffer = buffer.slice(newlineIndex + 1);
154
- const frame = line ? parseJsonLine(line) : undefined;
155
- if (frame?.type === "remote_res" && frame.id === id) {
156
- cleanup();
157
- if (!frame.ok) {
158
- reject(new Error(frame.error?.message ?? "Remote attach failed"));
159
- return;
160
- }
161
- const payload = frame.payload;
162
- if (!isBinding(payload?.binding)) {
163
- reject(new Error("Remote attach response did not include a binding"));
164
- return;
165
- }
166
- if (!isCapabilities(payload.capabilities)) {
167
- reject(new Error("Remote attach response did not include capabilities"));
168
- return;
169
- }
170
- resolve({
171
- binding: payload.binding,
172
- capabilities: payload.capabilities,
173
- });
174
- return;
175
- }
176
- newlineIndex = buffer.indexOf("\n");
177
- }
178
- };
179
- socket.on("data", onData);
180
- socket.once("error", onError);
181
- socket.once("close", onClose);
182
- socket.write(encodeRemoteAgentFrame({
183
- type: "remote_attach",
184
- id,
185
- sessionName: options.sessionName,
186
- profile: options.profile,
187
- }));
188
- });
189
- }
@@ -1,41 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- export function createPiboSessionId() {
3
- return randomUUID();
4
- }
5
- export function createSessionBinding(input, now = new Date().toISOString()) {
6
- return {
7
- sessionKey: input.sessionKey ?? createDefaultSessionKey(input),
8
- sessionId: input.sessionId ?? createPiboSessionId(),
9
- parentSessionKey: input.parentSessionKey,
10
- parentSessionId: input.parentSessionId,
11
- channel: input.channel,
12
- externalId: input.externalId,
13
- originalProfile: input.defaultProfile,
14
- workspace: input.workspace,
15
- createdAt: now,
16
- updatedAt: now,
17
- };
18
- }
19
- export function createDefaultSessionKey(input) {
20
- return `${input.channel}:${input.externalId}`;
21
- }
22
- export class InMemorySessionBindingStore {
23
- bySessionKey = new Map();
24
- byChannelExternalId = new Map();
25
- get(sessionKey) {
26
- return this.bySessionKey.get(sessionKey);
27
- }
28
- list() {
29
- return [...this.bySessionKey.values()];
30
- }
31
- resolve(input) {
32
- const channelExternalId = createDefaultSessionKey(input);
33
- const existing = this.byChannelExternalId.get(channelExternalId);
34
- if (existing)
35
- return existing;
36
- const binding = createSessionBinding(input);
37
- this.bySessionKey.set(binding.sessionKey, binding);
38
- this.byChannelExternalId.set(channelExternalId, binding);
39
- return binding;
40
- }
41
- }