@0xmaxma/claude-gateway 1.8.14 → 2.0.1

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 (586) hide show
  1. package/README.md +28 -1613
  2. package/config.template.json +7 -1
  3. package/dist/agent/runner.d.ts +419 -0
  4. package/dist/agent/runner.d.ts.map +1 -1
  5. package/dist/agent/runner.js +736 -24
  6. package/dist/agent/runner.js.map +1 -1
  7. package/dist/agent/skill-learning/index.d.ts +6 -4
  8. package/dist/agent/skill-learning/index.d.ts.map +1 -1
  9. package/dist/agent/skill-learning/index.js +3 -3
  10. package/dist/agent/skill-learning/index.js.map +1 -1
  11. package/dist/agent/skill-learning/notifier.d.ts +3 -4
  12. package/dist/agent/skill-learning/notifier.d.ts.map +1 -1
  13. package/dist/agent/skill-learning/notifier.js +15 -13
  14. package/dist/agent/skill-learning/notifier.js.map +1 -1
  15. package/dist/agent/skill-learning/reviewer.d.ts.map +1 -1
  16. package/dist/agent/skill-learning/reviewer.js +3 -1
  17. package/dist/agent/skill-learning/reviewer.js.map +1 -1
  18. package/dist/api/connectors-router.d.ts.map +1 -1
  19. package/dist/api/connectors-router.js +110 -4
  20. package/dist/api/connectors-router.js.map +1 -1
  21. package/dist/api/gateway-router.d.ts +1 -0
  22. package/dist/api/gateway-router.d.ts.map +1 -1
  23. package/dist/api/gateway-router.js +13 -1
  24. package/dist/api/gateway-router.js.map +1 -1
  25. package/dist/api/line-webhook-router.d.ts +2 -2
  26. package/dist/api/line-webhook-router.d.ts.map +1 -1
  27. package/dist/api/line-webhook-router.js +264 -230
  28. package/dist/api/line-webhook-router.js.map +1 -1
  29. package/dist/api/router.d.ts.map +1 -1
  30. package/dist/api/router.js +162 -10
  31. package/dist/api/router.js.map +1 -1
  32. package/dist/api/share-router.d.ts.map +1 -1
  33. package/dist/api/share-router.js +29 -10
  34. package/dist/api/share-router.js.map +1 -1
  35. package/dist/api/slack-client.d.ts +2 -0
  36. package/dist/api/slack-client.d.ts.map +1 -1
  37. package/dist/api/slack-client.js +6 -2
  38. package/dist/api/slack-client.js.map +1 -1
  39. package/dist/api/slack-webhook-router.d.ts +3 -0
  40. package/dist/api/slack-webhook-router.d.ts.map +1 -1
  41. package/dist/api/slack-webhook-router.js +226 -131
  42. package/dist/api/slack-webhook-router.js.map +1 -1
  43. package/dist/api/voice-router.d.ts +21 -0
  44. package/dist/api/voice-router.d.ts.map +1 -0
  45. package/dist/api/voice-router.js +372 -0
  46. package/dist/api/voice-router.js.map +1 -0
  47. package/dist/api/voice-settings-router.d.ts +5 -0
  48. package/dist/api/voice-settings-router.d.ts.map +1 -0
  49. package/dist/api/voice-settings-router.js +318 -0
  50. package/dist/api/voice-settings-router.js.map +1 -0
  51. package/dist/apps/agent-container-migration.d.ts +11 -0
  52. package/dist/apps/agent-container-migration.d.ts.map +1 -0
  53. package/dist/apps/agent-container-migration.js +85 -0
  54. package/dist/apps/agent-container-migration.js.map +1 -0
  55. package/dist/apps/installer.d.ts +1 -1
  56. package/dist/apps/installer.d.ts.map +1 -1
  57. package/dist/apps/installer.js +2 -1
  58. package/dist/apps/installer.js.map +1 -1
  59. package/dist/cli/commands/tasks.d.ts +5 -0
  60. package/dist/cli/commands/tasks.d.ts.map +1 -0
  61. package/dist/cli/commands/tasks.js +92 -0
  62. package/dist/cli/commands/tasks.js.map +1 -0
  63. package/dist/cli/http-client.d.ts +2 -0
  64. package/dist/cli/http-client.d.ts.map +1 -1
  65. package/dist/cli/http-client.js +8 -3
  66. package/dist/cli/http-client.js.map +1 -1
  67. package/dist/cli/index.d.ts.map +1 -1
  68. package/dist/cli/index.js +5 -1
  69. package/dist/cli/index.js.map +1 -1
  70. package/dist/config/config-write-lock.d.ts +2 -0
  71. package/dist/config/config-write-lock.d.ts.map +1 -1
  72. package/dist/config/config-write-lock.js +5 -0
  73. package/dist/config/config-write-lock.js.map +1 -1
  74. package/dist/config/loader.d.ts.map +1 -1
  75. package/dist/config/loader.js +87 -2
  76. package/dist/config/loader.js.map +1 -1
  77. package/dist/config/migrator.d.ts.map +1 -1
  78. package/dist/config/migrator.js +12 -1
  79. package/dist/config/migrator.js.map +1 -1
  80. package/dist/config/watcher.d.ts.map +1 -1
  81. package/dist/config/watcher.js +6 -0
  82. package/dist/config/watcher.js.map +1 -1
  83. package/dist/connectors/resolve.d.ts.map +1 -1
  84. package/dist/connectors/resolve.js +3 -1
  85. package/dist/connectors/resolve.js.map +1 -1
  86. package/dist/connectors/types.d.ts +8 -0
  87. package/dist/connectors/types.d.ts.map +1 -1
  88. package/dist/cron/manager.d.ts.map +1 -1
  89. package/dist/cron/manager.js +21 -2
  90. package/dist/cron/manager.js.map +1 -1
  91. package/dist/discord/receiver.d.ts +2 -1
  92. package/dist/discord/receiver.d.ts.map +1 -1
  93. package/dist/discord/receiver.js +5 -1
  94. package/dist/discord/receiver.js.map +1 -1
  95. package/dist/history/db.d.ts +3 -0
  96. package/dist/history/db.d.ts.map +1 -1
  97. package/dist/history/db.js +21 -1
  98. package/dist/history/db.js.map +1 -1
  99. package/dist/history/types.d.ts +2 -0
  100. package/dist/history/types.d.ts.map +1 -1
  101. package/dist/index.js +48 -9
  102. package/dist/index.js.map +1 -1
  103. package/dist/orchestration/bounded-queue.d.ts +15 -0
  104. package/dist/orchestration/bounded-queue.d.ts.map +1 -0
  105. package/dist/orchestration/bounded-queue.js +58 -0
  106. package/dist/orchestration/bounded-queue.js.map +1 -0
  107. package/dist/orchestration/bridge.d.ts +55 -0
  108. package/dist/orchestration/bridge.d.ts.map +1 -0
  109. package/dist/orchestration/bridge.js +234 -0
  110. package/dist/orchestration/bridge.js.map +1 -0
  111. package/dist/orchestration/browser-routing.d.ts +7 -0
  112. package/dist/orchestration/browser-routing.d.ts.map +1 -0
  113. package/dist/orchestration/browser-routing.js +22 -0
  114. package/dist/orchestration/browser-routing.js.map +1 -0
  115. package/dist/orchestration/capabilities.d.ts +49 -0
  116. package/dist/orchestration/capabilities.d.ts.map +1 -0
  117. package/dist/orchestration/capabilities.js +417 -0
  118. package/dist/orchestration/capabilities.js.map +1 -0
  119. package/dist/orchestration/capacity.d.ts +14 -0
  120. package/dist/orchestration/capacity.d.ts.map +1 -0
  121. package/dist/orchestration/capacity.js +52 -0
  122. package/dist/orchestration/capacity.js.map +1 -0
  123. package/dist/orchestration/channel-activity.d.ts +21 -0
  124. package/dist/orchestration/channel-activity.d.ts.map +1 -0
  125. package/dist/orchestration/channel-activity.js +72 -0
  126. package/dist/orchestration/channel-activity.js.map +1 -0
  127. package/dist/orchestration/channel-controls.d.ts +32 -0
  128. package/dist/orchestration/channel-controls.d.ts.map +1 -0
  129. package/dist/orchestration/channel-controls.js +105 -0
  130. package/dist/orchestration/channel-controls.js.map +1 -0
  131. package/dist/orchestration/channel-input-media.d.ts +11 -0
  132. package/dist/orchestration/channel-input-media.d.ts.map +1 -0
  133. package/dist/orchestration/channel-input-media.js +54 -0
  134. package/dist/orchestration/channel-input-media.js.map +1 -0
  135. package/dist/orchestration/channel-media.d.ts +4 -0
  136. package/dist/orchestration/channel-media.d.ts.map +1 -0
  137. package/dist/orchestration/channel-media.js +70 -0
  138. package/dist/orchestration/channel-media.js.map +1 -0
  139. package/dist/orchestration/channel-speech.d.ts +7 -0
  140. package/dist/orchestration/channel-speech.d.ts.map +1 -0
  141. package/dist/orchestration/channel-speech.js +65 -0
  142. package/dist/orchestration/channel-speech.js.map +1 -0
  143. package/dist/orchestration/cli-skills.d.ts +12 -0
  144. package/dist/orchestration/cli-skills.d.ts.map +1 -0
  145. package/dist/orchestration/cli-skills.js +132 -0
  146. package/dist/orchestration/cli-skills.js.map +1 -0
  147. package/dist/orchestration/config.d.ts +260 -0
  148. package/dist/orchestration/config.d.ts.map +1 -0
  149. package/dist/orchestration/config.js +110 -0
  150. package/dist/orchestration/config.js.map +1 -0
  151. package/dist/orchestration/container.d.ts +21 -0
  152. package/dist/orchestration/container.d.ts.map +1 -0
  153. package/dist/orchestration/container.js +195 -0
  154. package/dist/orchestration/container.js.map +1 -0
  155. package/dist/orchestration/control-delivery.d.ts +5 -0
  156. package/dist/orchestration/control-delivery.d.ts.map +1 -0
  157. package/dist/orchestration/control-delivery.js +50 -0
  158. package/dist/orchestration/control-delivery.js.map +1 -0
  159. package/dist/orchestration/conversation-intake.d.ts +32 -0
  160. package/dist/orchestration/conversation-intake.d.ts.map +1 -0
  161. package/dist/orchestration/conversation-intake.js +92 -0
  162. package/dist/orchestration/conversation-intake.js.map +1 -0
  163. package/dist/orchestration/decisions.d.ts +27 -0
  164. package/dist/orchestration/decisions.d.ts.map +1 -0
  165. package/dist/orchestration/decisions.js +151 -0
  166. package/dist/orchestration/decisions.js.map +1 -0
  167. package/dist/orchestration/delivery.d.ts +34 -0
  168. package/dist/orchestration/delivery.d.ts.map +1 -0
  169. package/dist/orchestration/delivery.js +235 -0
  170. package/dist/orchestration/delivery.js.map +1 -0
  171. package/dist/orchestration/display-stream.d.ts +4 -0
  172. package/dist/orchestration/display-stream.d.ts.map +1 -0
  173. package/dist/orchestration/display-stream.js +77 -0
  174. package/dist/orchestration/display-stream.js.map +1 -0
  175. package/dist/orchestration/events.d.ts +30 -0
  176. package/dist/orchestration/events.d.ts.map +1 -0
  177. package/dist/orchestration/events.js +65 -0
  178. package/dist/orchestration/events.js.map +1 -0
  179. package/dist/orchestration/execution-observation.d.ts +38 -0
  180. package/dist/orchestration/execution-observation.d.ts.map +1 -0
  181. package/dist/orchestration/execution-observation.js +25 -0
  182. package/dist/orchestration/execution-observation.js.map +1 -0
  183. package/dist/orchestration/file-delivery.d.ts +16 -0
  184. package/dist/orchestration/file-delivery.d.ts.map +1 -0
  185. package/dist/orchestration/file-delivery.js +139 -0
  186. package/dist/orchestration/file-delivery.js.map +1 -0
  187. package/dist/orchestration/gateway-config.d.ts +17 -0
  188. package/dist/orchestration/gateway-config.d.ts.map +1 -0
  189. package/dist/orchestration/gateway-config.js +128 -0
  190. package/dist/orchestration/gateway-config.js.map +1 -0
  191. package/dist/orchestration/history.d.ts +13 -0
  192. package/dist/orchestration/history.d.ts.map +1 -0
  193. package/dist/orchestration/history.js +48 -0
  194. package/dist/orchestration/history.js.map +1 -0
  195. package/dist/orchestration/identity.d.ts +6 -0
  196. package/dist/orchestration/identity.d.ts.map +1 -0
  197. package/dist/orchestration/identity.js +13 -0
  198. package/dist/orchestration/identity.js.map +1 -0
  199. package/dist/orchestration/inference-errors.d.ts +3 -0
  200. package/dist/orchestration/inference-errors.d.ts.map +1 -0
  201. package/dist/orchestration/inference-errors.js +16 -0
  202. package/dist/orchestration/inference-errors.js.map +1 -0
  203. package/dist/orchestration/input-images.d.ts +12 -0
  204. package/dist/orchestration/input-images.d.ts.map +1 -0
  205. package/dist/orchestration/input-images.js +66 -0
  206. package/dist/orchestration/input-images.js.map +1 -0
  207. package/dist/orchestration/instance-lock.d.ts +5 -0
  208. package/dist/orchestration/instance-lock.d.ts.map +1 -0
  209. package/dist/orchestration/instance-lock.js +33 -0
  210. package/dist/orchestration/instance-lock.js.map +1 -0
  211. package/dist/orchestration/line-loading.d.ts +21 -0
  212. package/dist/orchestration/line-loading.d.ts.map +1 -0
  213. package/dist/orchestration/line-loading.js +89 -0
  214. package/dist/orchestration/line-loading.js.map +1 -0
  215. package/dist/orchestration/media.d.ts +3 -0
  216. package/dist/orchestration/media.d.ts.map +1 -0
  217. package/dist/orchestration/media.js +46 -0
  218. package/dist/orchestration/media.js.map +1 -0
  219. package/dist/orchestration/migrations/schema.d.ts +3 -0
  220. package/dist/orchestration/migrations/schema.d.ts.map +1 -0
  221. package/dist/orchestration/migrations/schema.js +80 -0
  222. package/dist/orchestration/migrations/schema.js.map +1 -0
  223. package/dist/orchestration/notification-mailbox.d.ts +5 -0
  224. package/dist/orchestration/notification-mailbox.d.ts.map +1 -0
  225. package/dist/orchestration/notification-mailbox.js +29 -0
  226. package/dist/orchestration/notification-mailbox.js.map +1 -0
  227. package/dist/orchestration/process-activity.d.ts +23 -0
  228. package/dist/orchestration/process-activity.d.ts.map +1 -0
  229. package/dist/orchestration/process-activity.js +95 -0
  230. package/dist/orchestration/process-activity.js.map +1 -0
  231. package/dist/orchestration/process-supervisor.d.ts +15 -0
  232. package/dist/orchestration/process-supervisor.d.ts.map +1 -0
  233. package/dist/orchestration/process-supervisor.js +92 -0
  234. package/dist/orchestration/process-supervisor.js.map +1 -0
  235. package/dist/orchestration/process-turn.d.ts +35 -0
  236. package/dist/orchestration/process-turn.d.ts.map +1 -0
  237. package/dist/orchestration/process-turn.js +246 -0
  238. package/dist/orchestration/process-turn.js.map +1 -0
  239. package/dist/orchestration/progress-review.d.ts +28 -0
  240. package/dist/orchestration/progress-review.d.ts.map +1 -0
  241. package/dist/orchestration/progress-review.js +48 -0
  242. package/dist/orchestration/progress-review.js.map +1 -0
  243. package/dist/orchestration/recovery.d.ts +8 -0
  244. package/dist/orchestration/recovery.d.ts.map +1 -0
  245. package/dist/orchestration/recovery.js +35 -0
  246. package/dist/orchestration/recovery.js.map +1 -0
  247. package/dist/orchestration/reply-context.d.ts +7 -0
  248. package/dist/orchestration/reply-context.d.ts.map +1 -0
  249. package/dist/orchestration/reply-context.js +54 -0
  250. package/dist/orchestration/reply-context.js.map +1 -0
  251. package/dist/orchestration/runtime.d.ts +237 -0
  252. package/dist/orchestration/runtime.d.ts.map +1 -0
  253. package/dist/orchestration/runtime.js +1031 -0
  254. package/dist/orchestration/runtime.js.map +1 -0
  255. package/dist/orchestration/skills.d.ts +17 -0
  256. package/dist/orchestration/skills.d.ts.map +1 -0
  257. package/dist/orchestration/skills.js +32 -0
  258. package/dist/orchestration/skills.js.map +1 -0
  259. package/dist/orchestration/source-policy.d.ts +6 -0
  260. package/dist/orchestration/source-policy.d.ts.map +1 -0
  261. package/dist/orchestration/source-policy.js +16 -0
  262. package/dist/orchestration/source-policy.js.map +1 -0
  263. package/dist/orchestration/speech.d.ts +24 -0
  264. package/dist/orchestration/speech.d.ts.map +1 -0
  265. package/dist/orchestration/speech.js +61 -0
  266. package/dist/orchestration/speech.js.map +1 -0
  267. package/dist/orchestration/stop-controls.d.ts +30 -0
  268. package/dist/orchestration/stop-controls.d.ts.map +1 -0
  269. package/dist/orchestration/stop-controls.js +79 -0
  270. package/dist/orchestration/stop-controls.js.map +1 -0
  271. package/dist/orchestration/store.d.ts +92 -0
  272. package/dist/orchestration/store.d.ts.map +1 -0
  273. package/dist/orchestration/store.js +326 -0
  274. package/dist/orchestration/store.js.map +1 -0
  275. package/dist/orchestration/task-controls.d.ts +172 -0
  276. package/dist/orchestration/task-controls.d.ts.map +1 -0
  277. package/dist/orchestration/task-controls.js +59 -0
  278. package/dist/orchestration/task-controls.js.map +1 -0
  279. package/dist/orchestration/task-files.d.ts +29 -0
  280. package/dist/orchestration/task-files.d.ts.map +1 -0
  281. package/dist/orchestration/task-files.js +200 -0
  282. package/dist/orchestration/task-files.js.map +1 -0
  283. package/dist/orchestration/task-questions.d.ts +26 -0
  284. package/dist/orchestration/task-questions.d.ts.map +1 -0
  285. package/dist/orchestration/task-questions.js +160 -0
  286. package/dist/orchestration/task-questions.js.map +1 -0
  287. package/dist/orchestration/task-report.d.ts +7 -0
  288. package/dist/orchestration/task-report.d.ts.map +1 -0
  289. package/dist/orchestration/task-report.js +33 -0
  290. package/dist/orchestration/task-report.js.map +1 -0
  291. package/dist/orchestration/tasks/checkpoint-hook.d.ts +19 -0
  292. package/dist/orchestration/tasks/checkpoint-hook.d.ts.map +1 -0
  293. package/dist/orchestration/tasks/checkpoint-hook.js +49 -0
  294. package/dist/orchestration/tasks/checkpoint-hook.js.map +1 -0
  295. package/dist/orchestration/tasks/cleanup.d.ts +18 -0
  296. package/dist/orchestration/tasks/cleanup.d.ts.map +1 -0
  297. package/dist/orchestration/tasks/cleanup.js +113 -0
  298. package/dist/orchestration/tasks/cleanup.js.map +1 -0
  299. package/dist/orchestration/tasks/driver.d.ts +23 -0
  300. package/dist/orchestration/tasks/driver.d.ts.map +1 -0
  301. package/dist/orchestration/tasks/driver.js +209 -0
  302. package/dist/orchestration/tasks/driver.js.map +1 -0
  303. package/dist/orchestration/tasks/failure.d.ts +5 -0
  304. package/dist/orchestration/tasks/failure.d.ts.map +1 -0
  305. package/dist/orchestration/tasks/failure.js +17 -0
  306. package/dist/orchestration/tasks/failure.js.map +1 -0
  307. package/dist/orchestration/tasks/pool.d.ts +18 -0
  308. package/dist/orchestration/tasks/pool.d.ts.map +1 -0
  309. package/dist/orchestration/tasks/pool.js +73 -0
  310. package/dist/orchestration/tasks/pool.js.map +1 -0
  311. package/dist/orchestration/tasks/scheduler.d.ts +38 -0
  312. package/dist/orchestration/tasks/scheduler.d.ts.map +1 -0
  313. package/dist/orchestration/tasks/scheduler.js +160 -0
  314. package/dist/orchestration/tasks/scheduler.js.map +1 -0
  315. package/dist/orchestration/tasks/service.d.ts +114 -0
  316. package/dist/orchestration/tasks/service.d.ts.map +1 -0
  317. package/dist/orchestration/tasks/service.js +760 -0
  318. package/dist/orchestration/tasks/service.js.map +1 -0
  319. package/dist/orchestration/tasks/shared-workspace.d.ts +25 -0
  320. package/dist/orchestration/tasks/shared-workspace.d.ts.map +1 -0
  321. package/dist/orchestration/tasks/shared-workspace.js +162 -0
  322. package/dist/orchestration/tasks/shared-workspace.js.map +1 -0
  323. package/dist/orchestration/tasks/task-directive.d.ts +6 -0
  324. package/dist/orchestration/tasks/task-directive.d.ts.map +1 -0
  325. package/dist/orchestration/tasks/task-directive.js +41 -0
  326. package/dist/orchestration/tasks/task-directive.js.map +1 -0
  327. package/dist/orchestration/tasks/timing.d.ts +15 -0
  328. package/dist/orchestration/tasks/timing.d.ts.map +1 -0
  329. package/dist/orchestration/tasks/timing.js +48 -0
  330. package/dist/orchestration/tasks/timing.js.map +1 -0
  331. package/dist/orchestration/tasks/tool-repetition.d.ts +3 -0
  332. package/dist/orchestration/tasks/tool-repetition.d.ts.map +1 -0
  333. package/dist/orchestration/tasks/tool-repetition.js +30 -0
  334. package/dist/orchestration/tasks/tool-repetition.js.map +1 -0
  335. package/dist/orchestration/tasks/workspace.d.ts +24 -0
  336. package/dist/orchestration/tasks/workspace.d.ts.map +1 -0
  337. package/dist/orchestration/tasks/workspace.js +147 -0
  338. package/dist/orchestration/tasks/workspace.js.map +1 -0
  339. package/dist/orchestration/telegram-speech.d.ts +17 -0
  340. package/dist/orchestration/telegram-speech.d.ts.map +1 -0
  341. package/dist/orchestration/telegram-speech.js +55 -0
  342. package/dist/orchestration/telegram-speech.js.map +1 -0
  343. package/dist/orchestration/telegram-tool-status.d.ts +23 -0
  344. package/dist/orchestration/telegram-tool-status.d.ts.map +1 -0
  345. package/dist/orchestration/telegram-tool-status.js +207 -0
  346. package/dist/orchestration/telegram-tool-status.js.map +1 -0
  347. package/dist/orchestration/telegram-voices.d.ts +42 -0
  348. package/dist/orchestration/telegram-voices.d.ts.map +1 -0
  349. package/dist/orchestration/telegram-voices.js +70 -0
  350. package/dist/orchestration/telegram-voices.js.map +1 -0
  351. package/dist/orchestration/tool-activity.d.ts +10 -0
  352. package/dist/orchestration/tool-activity.d.ts.map +1 -0
  353. package/dist/orchestration/tool-activity.js +38 -0
  354. package/dist/orchestration/tool-activity.js.map +1 -0
  355. package/dist/orchestration/types.d.ts +177 -0
  356. package/dist/orchestration/types.d.ts.map +1 -0
  357. package/dist/orchestration/types.js +13 -0
  358. package/dist/orchestration/types.js.map +1 -0
  359. package/dist/orchestration/voice-reply-policy.d.ts +8 -0
  360. package/dist/orchestration/voice-reply-policy.d.ts.map +1 -0
  361. package/dist/orchestration/voice-reply-policy.js +46 -0
  362. package/dist/orchestration/voice-reply-policy.js.map +1 -0
  363. package/dist/orchestration/worker-shares.d.ts +8 -0
  364. package/dist/orchestration/worker-shares.d.ts.map +1 -0
  365. package/dist/orchestration/worker-shares.js +59 -0
  366. package/dist/orchestration/worker-shares.js.map +1 -0
  367. package/dist/orchestration/workflow.d.ts +121 -0
  368. package/dist/orchestration/workflow.d.ts.map +1 -0
  369. package/dist/orchestration/workflow.js +69 -0
  370. package/dist/orchestration/workflow.js.map +1 -0
  371. package/dist/session/input-image.d.ts +10 -0
  372. package/dist/session/input-image.d.ts.map +1 -0
  373. package/dist/session/input-image.js +3 -0
  374. package/dist/session/input-image.js.map +1 -0
  375. package/dist/session/process.d.ts +15 -3
  376. package/dist/session/process.d.ts.map +1 -1
  377. package/dist/session/process.js +143 -35
  378. package/dist/session/process.js.map +1 -1
  379. package/dist/session/runtime-profile.d.ts +36 -0
  380. package/dist/session/runtime-profile.d.ts.map +1 -0
  381. package/dist/session/runtime-profile.js +63 -0
  382. package/dist/session/runtime-profile.js.map +1 -0
  383. package/dist/session/store.d.ts.map +1 -1
  384. package/dist/session/store.js +23 -1
  385. package/dist/session/store.js.map +1 -1
  386. package/dist/share/share-store.d.ts +3 -1
  387. package/dist/share/share-store.d.ts.map +1 -1
  388. package/dist/share/share-store.js +13 -2
  389. package/dist/share/share-store.js.map +1 -1
  390. package/dist/shared/line-request-order.d.ts +2 -0
  391. package/dist/shared/line-request-order.d.ts.map +1 -0
  392. package/dist/shared/line-request-order.js +16 -0
  393. package/dist/shared/line-request-order.js.map +1 -0
  394. package/dist/shared/task-elapsed.d.ts +3 -0
  395. package/dist/shared/task-elapsed.d.ts.map +1 -0
  396. package/dist/shared/task-elapsed.js +12 -0
  397. package/dist/shared/task-elapsed.js.map +1 -0
  398. package/dist/shared/task-updated-time.d.ts +3 -0
  399. package/dist/shared/task-updated-time.d.ts.map +1 -0
  400. package/dist/shared/task-updated-time.js +15 -0
  401. package/dist/shared/task-updated-time.js.map +1 -0
  402. package/dist/skills/loader.d.ts +2 -0
  403. package/dist/skills/loader.d.ts.map +1 -1
  404. package/dist/skills/loader.js.map +1 -1
  405. package/dist/telegram/chunks.d.ts +19 -0
  406. package/dist/telegram/chunks.d.ts.map +1 -0
  407. package/dist/telegram/chunks.js +129 -0
  408. package/dist/telegram/chunks.js.map +1 -0
  409. package/dist/telegram/markdown.d.ts.map +1 -1
  410. package/dist/telegram/markdown.js +18 -3
  411. package/dist/telegram/markdown.js.map +1 -1
  412. package/dist/telegram/receiver.d.ts +2 -1
  413. package/dist/telegram/receiver.d.ts.map +1 -1
  414. package/dist/telegram/receiver.js +6 -1
  415. package/dist/telegram/receiver.js.map +1 -1
  416. package/dist/types.d.ts +14 -0
  417. package/dist/types.d.ts.map +1 -1
  418. package/dist/ui/web-ui.d.ts.map +1 -1
  419. package/dist/ui/web-ui.js +31 -5
  420. package/dist/ui/web-ui.js.map +1 -1
  421. package/dist/voice/diagnostics.d.ts +29 -0
  422. package/dist/voice/diagnostics.d.ts.map +1 -0
  423. package/dist/voice/diagnostics.js +37 -0
  424. package/dist/voice/diagnostics.js.map +1 -0
  425. package/dist/voice/errors.d.ts +19 -0
  426. package/dist/voice/errors.d.ts.map +1 -0
  427. package/dist/voice/errors.js +133 -0
  428. package/dist/voice/errors.js.map +1 -0
  429. package/dist/voice/line-audio.d.ts +4 -0
  430. package/dist/voice/line-audio.d.ts.map +1 -0
  431. package/dist/voice/line-audio.js +27 -0
  432. package/dist/voice/line-audio.js.map +1 -0
  433. package/dist/voice/managed-quota.d.ts +5 -0
  434. package/dist/voice/managed-quota.d.ts.map +1 -0
  435. package/dist/voice/managed-quota.js +35 -0
  436. package/dist/voice/managed-quota.js.map +1 -0
  437. package/dist/voice/mp3.d.ts +3 -0
  438. package/dist/voice/mp3.d.ts.map +1 -0
  439. package/dist/voice/mp3.js +30 -0
  440. package/dist/voice/mp3.js.map +1 -0
  441. package/dist/voice/notes.d.ts +9 -0
  442. package/dist/voice/notes.d.ts.map +1 -0
  443. package/dist/voice/notes.js +68 -0
  444. package/dist/voice/notes.js.map +1 -0
  445. package/dist/voice/playback.d.ts +22 -0
  446. package/dist/voice/playback.d.ts.map +1 -0
  447. package/dist/voice/playback.js +52 -0
  448. package/dist/voice/playback.js.map +1 -0
  449. package/dist/voice/preview.d.ts +6 -0
  450. package/dist/voice/preview.d.ts.map +1 -0
  451. package/dist/voice/preview.js +44 -0
  452. package/dist/voice/preview.js.map +1 -0
  453. package/dist/voice/protocol.d.ts +10 -0
  454. package/dist/voice/protocol.d.ts.map +1 -0
  455. package/dist/voice/protocol.js +30 -0
  456. package/dist/voice/protocol.js.map +1 -0
  457. package/dist/voice/providers/cartesia-tts.d.ts +26 -0
  458. package/dist/voice/providers/cartesia-tts.d.ts.map +1 -0
  459. package/dist/voice/providers/cartesia-tts.js +95 -0
  460. package/dist/voice/providers/cartesia-tts.js.map +1 -0
  461. package/dist/voice/providers/deepgram-stt.d.ts +20 -0
  462. package/dist/voice/providers/deepgram-stt.d.ts.map +1 -0
  463. package/dist/voice/providers/deepgram-stt.js +66 -0
  464. package/dist/voice/providers/deepgram-stt.js.map +1 -0
  465. package/dist/voice/providers/elevenlabs-stt.d.ts +20 -0
  466. package/dist/voice/providers/elevenlabs-stt.d.ts.map +1 -0
  467. package/dist/voice/providers/elevenlabs-stt.js +92 -0
  468. package/dist/voice/providers/elevenlabs-stt.js.map +1 -0
  469. package/dist/voice/providers/elevenlabs-tts.d.ts +26 -0
  470. package/dist/voice/providers/elevenlabs-tts.d.ts.map +1 -0
  471. package/dist/voice/providers/elevenlabs-tts.js +82 -0
  472. package/dist/voice/providers/elevenlabs-tts.js.map +1 -0
  473. package/dist/voice/providers/encoded-audio-tts.d.ts +21 -0
  474. package/dist/voice/providers/encoded-audio-tts.d.ts.map +1 -0
  475. package/dist/voice/providers/encoded-audio-tts.js +175 -0
  476. package/dist/voice/providers/encoded-audio-tts.js.map +1 -0
  477. package/dist/voice/providers/fake.d.ts +39 -0
  478. package/dist/voice/providers/fake.d.ts.map +1 -0
  479. package/dist/voice/providers/fake.js +41 -0
  480. package/dist/voice/providers/fake.js.map +1 -0
  481. package/dist/voice/providers/gemini-live-stt.d.ts +21 -0
  482. package/dist/voice/providers/gemini-live-stt.d.ts.map +1 -0
  483. package/dist/voice/providers/gemini-live-stt.js +158 -0
  484. package/dist/voice/providers/gemini-live-stt.js.map +1 -0
  485. package/dist/voice/providers/gemini.d.ts +60 -0
  486. package/dist/voice/providers/gemini.d.ts.map +1 -0
  487. package/dist/voice/providers/gemini.js +124 -0
  488. package/dist/voice/providers/gemini.js.map +1 -0
  489. package/dist/voice/providers/model-ref.d.ts +9 -0
  490. package/dist/voice/providers/model-ref.d.ts.map +1 -0
  491. package/dist/voice/providers/model-ref.js +31 -0
  492. package/dist/voice/providers/model-ref.js.map +1 -0
  493. package/dist/voice/providers/openrouter.d.ts +39 -0
  494. package/dist/voice/providers/openrouter.d.ts.map +1 -0
  495. package/dist/voice/providers/openrouter.js +154 -0
  496. package/dist/voice/providers/openrouter.js.map +1 -0
  497. package/dist/voice/providers/paxalabs-stt.d.ts +12 -0
  498. package/dist/voice/providers/paxalabs-stt.d.ts.map +1 -0
  499. package/dist/voice/providers/paxalabs-stt.js +41 -0
  500. package/dist/voice/providers/paxalabs-stt.js.map +1 -0
  501. package/dist/voice/providers/paxalabs-tts.d.ts +23 -0
  502. package/dist/voice/providers/paxalabs-tts.d.ts.map +1 -0
  503. package/dist/voice/providers/paxalabs-tts.js +80 -0
  504. package/dist/voice/providers/paxalabs-tts.js.map +1 -0
  505. package/dist/voice/providers/recorded-stt.d.ts +34 -0
  506. package/dist/voice/providers/recorded-stt.d.ts.map +1 -0
  507. package/dist/voice/providers/recorded-stt.js +59 -0
  508. package/dist/voice/providers/recorded-stt.js.map +1 -0
  509. package/dist/voice/providers/registry.d.ts +10 -0
  510. package/dist/voice/providers/registry.d.ts.map +1 -0
  511. package/dist/voice/providers/registry.js +77 -0
  512. package/dist/voice/providers/registry.js.map +1 -0
  513. package/dist/voice/providers/socket.d.ts +10 -0
  514. package/dist/voice/providers/socket.d.ts.map +1 -0
  515. package/dist/voice/providers/socket.js +91 -0
  516. package/dist/voice/providers/socket.js.map +1 -0
  517. package/dist/voice/providers/upstream.d.ts +9 -0
  518. package/dist/voice/providers/upstream.d.ts.map +1 -0
  519. package/dist/voice/providers/upstream.js +51 -0
  520. package/dist/voice/providers/upstream.js.map +1 -0
  521. package/dist/voice/providers/voice-catalog.d.ts +17 -0
  522. package/dist/voice/providers/voice-catalog.d.ts.map +1 -0
  523. package/dist/voice/providers/voice-catalog.js +167 -0
  524. package/dist/voice/providers/voice-catalog.js.map +1 -0
  525. package/dist/voice/queue.d.ts +2 -0
  526. package/dist/voice/queue.d.ts.map +1 -0
  527. package/dist/voice/queue.js +6 -0
  528. package/dist/voice/queue.js.map +1 -0
  529. package/dist/voice/session.d.ts +86 -0
  530. package/dist/voice/session.d.ts.map +1 -0
  531. package/dist/voice/session.js +464 -0
  532. package/dist/voice/session.js.map +1 -0
  533. package/dist/voice/turn-manager.d.ts +27 -0
  534. package/dist/voice/turn-manager.d.ts.map +1 -0
  535. package/dist/voice/turn-manager.js +75 -0
  536. package/dist/voice/turn-manager.js.map +1 -0
  537. package/dist/voice/types.d.ts +78 -0
  538. package/dist/voice/types.d.ts.map +1 -0
  539. package/dist/voice/types.js +18 -0
  540. package/dist/voice/types.js.map +1 -0
  541. package/dist/voice/wav.d.ts +2 -0
  542. package/dist/voice/wav.d.ts.map +1 -0
  543. package/dist/voice/wav.js +21 -0
  544. package/dist/voice/wav.js.map +1 -0
  545. package/dist/wechat/ilink-client.d.ts +13 -0
  546. package/dist/wechat/ilink-client.d.ts.map +1 -1
  547. package/dist/wechat/ilink-client.js +19 -0
  548. package/dist/wechat/ilink-client.js.map +1 -1
  549. package/dist/whatsapp/manager.d.ts.map +1 -1
  550. package/dist/whatsapp/manager.js +51 -1
  551. package/dist/whatsapp/manager.js.map +1 -1
  552. package/mcp/capability-catalog.ts +206 -0
  553. package/mcp/modules.ts +56 -0
  554. package/mcp/server.ts +18 -37
  555. package/mcp/tools/browser/module.ts +1 -1
  556. package/mcp/tools/browser/skills/open-browser/SKILL.md +5 -3
  557. package/mcp/tools/discord/commands.ts +17 -1
  558. package/mcp/tools/discord/inbound.ts +11 -0
  559. package/mcp/tools/discord/module.ts +42 -2
  560. package/mcp/tools/discord/receiver-server.ts +10 -0
  561. package/mcp/tools/discord/types.ts +4 -1
  562. package/mcp/tools/image/module.ts +3 -1
  563. package/mcp/tools/receiver-spool.test.ts +28 -0
  564. package/mcp/tools/receiver-spool.ts +56 -0
  565. package/mcp/tools/share-file/module.ts +9 -1
  566. package/mcp/tools/shared/share-client.ts +19 -0
  567. package/mcp/tools/tasks/module.ts +35 -0
  568. package/mcp/tools/telegram/media-group.ts +21 -0
  569. package/mcp/tools/telegram/receiver-server.ts +246 -11
  570. package/mcp/tools/telegram/selection-confirmation.ts +20 -0
  571. package/mcp/tools/telegram/task-browser.ts +117 -0
  572. package/mcp/tools/telegram/task-detail.ts +36 -0
  573. package/mcp/tools/telegram/task-elapsed.ts +1 -0
  574. package/mcp/tools/telegram/typing.ts +6 -116
  575. package/mcp/tools/video/module.ts +1 -1
  576. package/mcp/types.ts +5 -0
  577. package/package.json +2 -1
  578. package/resource/claude_gateway.jpeg +0 -0
  579. package/scripts/orchestration/bench-store.cjs +30 -0
  580. package/scripts/orchestration/inspect.cjs +16 -0
  581. package/scripts/orchestration/probe-profile.cjs +67 -0
  582. package/scripts/orchestration/reconcile.cjs +21 -0
  583. package/scripts/orchestration/smoke-elevenlabs.cjs +90 -0
  584. package/scripts/orchestration/smoke-media.cjs +70 -0
  585. package/scripts/orchestration/smoke-text.cjs +101 -0
  586. package/scripts/orchestration/smoke-vision.cjs +49 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-files.d.ts","sourceRoot":"","sources":["../../src/orchestration/task-files.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAA4B,MAAM,SAAS,CAAC;AAMvE,qBAAa,SAAS;IACR,QAAQ,CAAC,KAAK,EAAE,kBAAkB;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM;IAAE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAAU,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAA5H,KAAK,EAAE,kBAAkB,EAAW,UAAU,EAAE,MAAM,EAAmB,cAAc,CAAC,EAAE,MAAM,YAAA,EAAmB,SAAS,SAA+C;IAChM,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA0C;IACzE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAkC;IAEpE,oFAAoF;IACpF,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAiCxE,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAOxC,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;;;;;IAU3C,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM;IAsB9E,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;IA2B5F,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;CAsBhG"}
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaskFiles = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const crypto_1 = require("crypto");
7
+ const store_1 = require("./store");
8
+ const types_1 = require("./types");
9
+ const media_1 = require("./media");
10
+ const media_store_1 = require("../history/media-store");
11
+ const share_store_1 = require("../share/share-store");
12
+ class TaskFiles {
13
+ constructor(store, agentsRoot, containerSpool, workspace = (0, path_1.join)(agentsRoot, store.agentId, 'workspace')) {
14
+ this.store = store;
15
+ this.agentsRoot = agentsRoot;
16
+ this.containerSpool = containerSpool;
17
+ this.workspace = workspace;
18
+ this.capturedImages = new Map();
19
+ this.pendingImageTools = new Map();
20
+ }
21
+ /** Capture actual MCP image bytes, never model-authored paths or assistant text. */
22
+ captureOutput(attemptId, generation, line) {
23
+ if (this.containerSpool)
24
+ return; // Container output must use the container import boundary.
25
+ let event;
26
+ try {
27
+ event = JSON.parse(line);
28
+ }
29
+ catch {
30
+ return;
31
+ }
32
+ const blocks = event.message?.content;
33
+ if (!Array.isArray(blocks))
34
+ return;
35
+ const pending = this.pendingImageTools.get(attemptId) ?? new Set();
36
+ this.pendingImageTools.set(attemptId, pending);
37
+ for (const block of blocks) {
38
+ if (event.type === 'assistant' && block.type === 'tool_use' && typeof block.name === 'string' && block.name.startsWith('mcp__') && typeof block.id === 'string')
39
+ pending.add(block.id);
40
+ if (event.type !== 'user' || block.type !== 'tool_result' || !pending.delete(block.tool_use_id) || block.is_error || !Array.isArray(block.content))
41
+ continue;
42
+ const image = block.content.find((item) => item.type === 'image');
43
+ const data = image?.source?.type === 'base64' ? image.source.data : image?.data;
44
+ if (typeof data !== 'string' || data.length > 28 * 1024 * 1024 || !/^[A-Za-z0-9+/]*={0,2}$/.test(data))
45
+ continue;
46
+ const bytes = Buffer.from(data, 'base64');
47
+ const mime = (0, share_store_1.detectImageMime)(bytes.subarray(0, 12));
48
+ if (!mime || !bytes.length || bytes.length > 20 * 1024 * 1024)
49
+ continue;
50
+ const { mediaDir } = this.scope(attemptId, generation);
51
+ const images = this.capturedImages.get(attemptId) ?? new Map();
52
+ if (images.has(block.tool_use_id))
53
+ continue;
54
+ if (images.size >= 20) {
55
+ const oldest = images.entries().next().value;
56
+ try {
57
+ (0, fs_1.unlinkSync)(oldest[1]);
58
+ }
59
+ catch { /* already removed */ }
60
+ images.delete(oldest[0]);
61
+ }
62
+ (0, fs_1.mkdirSync)(mediaDir, { recursive: true, mode: 0o700 });
63
+ const suffix = mime === 'image/png' ? '.png' : mime === 'image/jpeg' ? '.jpg' : mime === 'image/webp' ? '.webp' : '.gif';
64
+ const file = (0, path_1.join)(mediaDir, `mcp-image-${(0, crypto_1.randomUUID)()}${suffix}`);
65
+ (0, fs_1.writeFileSync)(file, bytes, { flag: 'wx', mode: 0o600 });
66
+ images.set(block.tool_use_id, file);
67
+ this.capturedImages.set(attemptId, images);
68
+ }
69
+ }
70
+ releaseCaptured(attemptId) {
71
+ this.pendingImageTools.delete(attemptId);
72
+ for (const path of this.capturedImages.get(attemptId)?.values() ?? []) {
73
+ try {
74
+ (0, fs_1.unlinkSync)(path);
75
+ }
76
+ catch { /* staged bytes live independently in content-addressed media */ }
77
+ }
78
+ this.capturedImages.delete(attemptId);
79
+ }
80
+ scope(attemptId, generation) {
81
+ const attempt = this.store.get('SELECT * FROM task_attempts WHERE id=?', attemptId);
82
+ const task = attempt && this.store.task(String(attempt.task_id));
83
+ // The serialized attempt is authoritative; never borrow a later generation.
84
+ const snapshot = attempt && JSON.parse(String(attempt.payload_json));
85
+ if (!task || task.activeAttemptId !== attemptId || snapshot.generation !== generation || !['starting', 'running'].includes(task.state))
86
+ throw new types_1.OrchestrationError('STALE_ATTEMPT');
87
+ const conversation = this.store.get('SELECT * FROM conversations WHERE id=?', task.conversationId);
88
+ const mediaDir = (0, path_1.join)(this.agentsRoot, this.store.agentId, 'media', `api-${task.agentSessionId}`);
89
+ return { task, conversation, mediaDir };
90
+ }
91
+ allowedPath(attemptId, generation, candidate) {
92
+ const { task, mediaDir } = this.scope(attemptId, generation);
93
+ const value = (0, store_1.boundedText)(candidate, 4096);
94
+ const path = (0, fs_1.realpathSync)(value.startsWith('media/') ? media_store_1.MediaStore.resolvePath(this.agentsRoot, this.store.agentId, value) : value);
95
+ const under = (root) => { const ref = (0, path_1.relative)((0, fs_1.realpathSync)(root), path); return !!ref && !ref.startsWith('..') && !(0, path_1.isAbsolute)(ref); };
96
+ if (this.containerSpool) {
97
+ if (!under((0, path_1.join)(this.containerSpool, attemptId)) || !(0, fs_1.statSync)(path).isFile())
98
+ throw new types_1.OrchestrationError('ARTIFACT_PATH_DENIED');
99
+ return path;
100
+ }
101
+ let permitted = false;
102
+ try {
103
+ permitted = under(mediaDir);
104
+ }
105
+ catch { /* not created yet */ }
106
+ for (const row of this.store.all("SELECT worktree_path FROM task_resources WHERE task_id=? AND lifecycle_state='active'", task.taskId)) {
107
+ try {
108
+ permitted || (permitted = under(String(row.worktree_path)));
109
+ }
110
+ catch { /* unavailable resource */ }
111
+ }
112
+ for (const row of this.store.all('SELECT attachment_refs_json FROM conversation_inputs WHERE conversation_id=?', task.conversationId)) {
113
+ for (const ref of JSON.parse(String(row.attachment_refs_json))) {
114
+ try {
115
+ permitted || (permitted = (0, fs_1.realpathSync)(media_store_1.MediaStore.resolvePath(this.agentsRoot, this.store.agentId, ref)) === path);
116
+ }
117
+ catch { /* expired attachment */ }
118
+ }
119
+ }
120
+ if (!permitted || !(0, fs_1.statSync)(path).isFile())
121
+ throw new types_1.OrchestrationError('ARTIFACT_PATH_DENIED', 'ARTIFACT_PATH_DENIED: File is outside this task scope. Use the original file’s absolute path in the active task workspace, a supplied input attachment, or this session’s media directory. Do not copy it to the agent-wide media root. The gateway stages authorized files automatically.');
122
+ return path;
123
+ }
124
+ stage(attemptId, generation, actionId, args) {
125
+ const { task } = this.scope(attemptId, generation);
126
+ (0, store_1.boundedText)(actionId, 256);
127
+ const old = this.store.get('SELECT * FROM task_files WHERE attempt_id=? AND action_id=?', attemptId, actionId);
128
+ if (old) {
129
+ if (old.args_hash !== (0, store_1.payloadHash)(args))
130
+ throw new types_1.OrchestrationError('IDEMPOTENCY_CONFLICT');
131
+ return { artifactId: String(old.id), path: String(old.path), staged: true };
132
+ }
133
+ if (Number(this.store.get('SELECT COUNT(*) n FROM task_files WHERE attempt_id=?', attemptId).n) >= 10)
134
+ throw new types_1.OrchestrationError('TOO_MANY_ARTIFACTS');
135
+ if (args.path !== undefined && args.source_tool_call_id !== undefined)
136
+ throw new types_1.OrchestrationError('INVALID_INPUT', 'Choose path OR source_tool_call_id, not both.');
137
+ const images = this.capturedImages.get(attemptId);
138
+ const captured = args.source_tool_call_id === undefined ? [...(images?.values() ?? [])].at(-1) : images?.get((0, store_1.boundedText)(args.source_tool_call_id, 256));
139
+ if (args.path === undefined && !captured)
140
+ throw new types_1.OrchestrationError('MCP_IMAGE_NOT_CAPTURED', 'No captured MCP image for this attempt. Capture an image first, or supply an existing local file path.');
141
+ let source;
142
+ try {
143
+ source = this.allowedPath(attemptId, generation, args.path ?? captured);
144
+ }
145
+ catch (error) {
146
+ if (['ENOENT', 'INVALID_REQUEST'].includes(String(error.code)))
147
+ throw new types_1.OrchestrationError('ARTIFACT_FILE_NOT_FOUND', 'The supplied path is not a saved file. For an MCP screenshot, omit path to stage its captured image, or use source_tool_call_id. Do not invent a filename.');
148
+ throw error;
149
+ }
150
+ const caption = args.caption === undefined ? '' : (0, store_1.boundedText)(args.caption, 1024);
151
+ if ((0, fs_1.statSync)(source).size > 50 * 1024 * 1024)
152
+ throw new types_1.OrchestrationError('ATTACHMENT_TOO_LARGE');
153
+ const path = (0, media_1.ingestOrchestrationMedia)(this.agentsRoot, this.store.agentId, `api-${task.agentSessionId}`, source);
154
+ const kind = (0, share_store_1.detectImageMime)((0, fs_1.readFileSync)(source).subarray(0, 12)) ? 'image' : 'file';
155
+ const id = (0, crypto_1.randomUUID)();
156
+ this.store.run('INSERT INTO task_files VALUES(?,?,?,?,?,?,?,?,?,?,?)', id, task.taskId, attemptId, actionId, path, (0, path_1.basename)(source).replace(/[\r\n]/g, '_').slice(0, 200), kind, caption, null, Date.now(), (0, store_1.payloadHash)(args));
157
+ return { artifactId: id, path, staged: true };
158
+ }
159
+ remember(attemptId, generation, actionId, args) {
160
+ const { task, conversation } = this.scope(attemptId, generation);
161
+ if (!task.capabilities.writeMemory || conversation.source === 'api')
162
+ throw new types_1.OrchestrationError('MEMORY_WRITE_DENIED');
163
+ const note = (0, store_1.boundedText)(args.note, 8192), name = args.path === undefined ? `memory/${new Date().toISOString().slice(0, 10)}.md` : (0, store_1.boundedText)(args.path, 256);
164
+ if (!/^(?:MEMORY\.md|USER\.md|memory\/[A-Za-z0-9_-]+\.md)$/.test(name))
165
+ throw new types_1.OrchestrationError('MEMORY_PATH_DENIED');
166
+ const workspace = this.workspace, destination = (0, path_1.join)(workspace, name);
167
+ (0, fs_1.mkdirSync)((0, path_1.dirname)(destination), { recursive: true });
168
+ if ((0, fs_1.realpathSync)((0, path_1.dirname)(destination)) !== (0, path_1.join)((0, fs_1.realpathSync)(workspace), name.startsWith('memory/') ? 'memory' : '') || ((0, fs_1.existsSync)(destination) && (0, fs_1.lstatSync)(destination).isSymbolicLink()))
169
+ throw new types_1.OrchestrationError('MEMORY_PATH_DENIED');
170
+ if ((0, fs_1.existsSync)(destination) && (0, fs_1.statSync)(destination).size > 1048576)
171
+ throw new types_1.OrchestrationError('MEMORY_TOO_LARGE');
172
+ const old = (0, fs_1.existsSync)(destination) ? (0, fs_1.readFileSync)(destination, 'utf8') : '';
173
+ const operation = (0, crypto_1.createHash)('sha256').update(`${attemptId}:${actionId}`).digest('hex');
174
+ const marker = `<!-- orchestration-memory:${operation}:${(0, crypto_1.createHash)('sha256').update(name + '\0' + note).digest('hex')} -->`;
175
+ if (old.includes(`<!-- orchestration-memory:${operation}:`) && !old.includes(marker))
176
+ throw new types_1.OrchestrationError('IDEMPOTENCY_CONFLICT');
177
+ if (!old.includes(marker)) {
178
+ const temporary = `${destination}.${(0, crypto_1.randomUUID)()}.tmp`, fd = (0, fs_1.openSync)(temporary, 'wx', 0o600);
179
+ try {
180
+ (0, fs_1.writeFileSync)(fd, `${old}\n${marker}\n${note}\n`);
181
+ (0, fs_1.fsyncSync)(fd);
182
+ }
183
+ finally {
184
+ (0, fs_1.closeSync)(fd);
185
+ }
186
+ (0, fs_1.renameSync)(temporary, destination);
187
+ const directory = (0, fs_1.openSync)((0, path_1.dirname)(destination), 'r');
188
+ try {
189
+ (0, fs_1.fsyncSync)(directory);
190
+ }
191
+ finally {
192
+ (0, fs_1.closeSync)(directory);
193
+ }
194
+ }
195
+ this.store.transaction(() => this.store.appendEvent(task.conversationId, 'task.memory_updated', { taskId: task.taskId, path: name, operation }));
196
+ return { updated: true, path: name };
197
+ }
198
+ }
199
+ exports.TaskFiles = TaskFiles;
200
+ //# sourceMappingURL=task-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-files.js","sourceRoot":"","sources":["../../src/orchestration/task-files.ts"],"names":[],"mappings":";;;AAAA,2BAAmK;AACnK,+BAAqE;AACrE,mCAAgD;AAChD,mCAAuE;AACvE,mCAA6C;AAC7C,mCAAmD;AACnD,wDAAoD;AACpD,sDAAuD;AAEvD,MAAa,SAAS;IACpB,YAAqB,KAAyB,EAAW,UAAkB,EAAmB,cAAuB,EAAmB,YAAY,IAAA,WAAI,EAAC,UAAU,EAAE,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC;QAA3K,UAAK,GAAL,KAAK,CAAoB;QAAW,eAAU,GAAV,UAAU,CAAQ;QAAmB,mBAAc,GAAd,cAAc,CAAS;QAAmB,cAAS,GAAT,SAAS,CAA+C;QAC/K,mBAAc,GAAG,IAAI,GAAG,EAA+B,CAAC;QACxD,sBAAiB,GAAG,IAAI,GAAG,EAAuB,CAAC;IAF+H,CAAC;IAIpM,oFAAoF;IACpF,aAAa,CAAC,SAAiB,EAAE,UAAkB,EAAE,IAAY;QAC/D,IAAI,IAAI,CAAC,cAAc;YAAE,OAAO,CAAC,2DAA2D;QAC5F,IAAI,KAAU,CAAC;QACf,IAAI,CAAC;YAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC;YAAC,OAAO;QAAC,CAAC;QACnD,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC;QACtC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YAAE,OAAO;QACnC,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,GAAG,EAAU,CAAC;QAC3E,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC/C,K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AAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACvC,CAAC;CACF;AA/HD,8BA+HC"}
@@ -0,0 +1,26 @@
1
+ import { ControlMenu, ControlScope } from './channel-controls';
2
+ import { DecisionService } from './decisions';
3
+ import { DeliveryControl } from './delivery';
4
+ import { AcceptInput, OrchestrationStore } from './store';
5
+ import { TaskService } from './tasks/service';
6
+ /** Questions are durable user controls, not ordinary model-generated progress reports. */
7
+ export declare class TaskQuestions {
8
+ private store;
9
+ private tasks;
10
+ private decisions;
11
+ private deliver;
12
+ private publish;
13
+ private reminderMs;
14
+ constructor(store: OrchestrationStore, tasks: TaskService, decisions: DecisionService, deliver: (responseId: string, bindingId: string, text: string, controls: DeliveryControl[]) => void, publish: (sessionId: string, responseId: string, text: string) => void, reminderMs: () => number);
15
+ tick(now?: number): void;
16
+ private suppressQuestionReports;
17
+ private owned;
18
+ handle(scope: ControlScope, text: string, inputId?: string): ControlMenu | undefined;
19
+ private apply;
20
+ /** Only a platform reply to a persisted question message is an unambiguous answer. */
21
+ answerReply(input: AcceptInput, inputId: string): ControlMenu | undefined;
22
+ normalizeReply(input: AcceptInput): AcceptInput;
23
+ matches(input: AcceptInput): boolean;
24
+ private replyQuestion;
25
+ }
26
+ //# sourceMappingURL=task-questions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-questions.d.ts","sourceRoot":"","sources":["../../src/orchestration/task-questions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAoB,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9C,0FAA0F;AAC1F,qBAAa,aAAa;IACZ,OAAO,CAAC,KAAK;IAAsB,OAAO,CAAC,KAAK;IAAe,OAAO,CAAC,SAAS;IAC1F,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,UAAU;gBAHA,KAAK,EAAE,kBAAkB,EAAU,KAAK,EAAE,WAAW,EAAU,SAAS,EAAE,eAAe,EACnG,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,KAAK,IAAI,EACnG,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,EACtE,UAAU,EAAE,MAAM,MAAM;IAElC,IAAI,CAAC,GAAG,SAAa,GAAG,IAAI;IAmD5B,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,KAAK;IAYb,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAGpF,OAAO,CAAC,KAAK;IAmBb,sFAAsF;IACtF,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAQzE,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW;IAW/C,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;IAcpC,OAAO,CAAC,aAAa;CAOtB"}
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaskQuestions = void 0;
4
+ const store_1 = require("./store");
5
+ const types_1 = require("./types");
6
+ const UUID = '[a-f0-9-]{36}';
7
+ /** Questions are durable user controls, not ordinary model-generated progress reports. */
8
+ class TaskQuestions {
9
+ constructor(store, tasks, decisions, deliver, publish, reminderMs) {
10
+ this.store = store;
11
+ this.tasks = tasks;
12
+ this.decisions = decisions;
13
+ this.deliver = deliver;
14
+ this.publish = publish;
15
+ this.reminderMs = reminderMs;
16
+ }
17
+ tick(now = Date.now()) {
18
+ const published = [];
19
+ this.store.compose(() => {
20
+ // A pending message must not ask for an already answered or replaced question.
21
+ for (const row of this.store.all(`SELECT q.* FROM task_questions q JOIN tasks t ON t.id=q.task_id
22
+ WHERE (q.closed=0 OR EXISTS(SELECT 1 FROM deliveries d JOIN task_question_messages m ON m.response_id=d.response_id WHERE m.question_id=q.question_id AND d.state='pending')) AND (t.state!='waiting_input' OR COALESCE(json_extract(t.snapshot_json,'$.pendingQuestion.questionId'),'')!=q.question_id)`)) {
23
+ this.store.run('UPDATE task_questions SET closed=1 WHERE question_id=?', row.question_id);
24
+ this.suppressQuestionReports(String(row.question_id));
25
+ this.store.cancelQuestionDeliveries(String(row.question_id));
26
+ }
27
+ for (const row of this.store.all(`SELECT t.*,c.agent_session_id FROM tasks t JOIN conversations c ON c.id=t.conversation_id
28
+ WHERE t.state='waiting_input' AND c.status='active'`)) {
29
+ const task = this.store.task(String(row.id)), question = task.pendingQuestion;
30
+ if (!question || question.revision !== task.revision)
31
+ continue;
32
+ let saved = this.store.get('SELECT * FROM task_questions WHERE question_id=?', question.questionId);
33
+ if (!saved) {
34
+ // Preserve the originating channel/thread, never pick an arbitrary linked channel.
35
+ const binding = this.store.get('SELECT binding_id FROM conversation_inputs WHERE id=?', task.initiatingInputId);
36
+ if (!binding)
37
+ continue;
38
+ this.store.run('INSERT INTO task_questions(question_id,task_id,revision,state_version,binding_id,next_reminder_at) VALUES(?,?,?,?,?,?)', question.questionId, task.taskId, question.revision, task.stateVersion, binding.binding_id, now);
39
+ saved = this.store.get('SELECT * FROM task_questions WHERE question_id=?', question.questionId);
40
+ }
41
+ if (!saved.closed && !saved.muted && Number(saved.next_reminder_at) <= now) {
42
+ const pending = this.store.get(`SELECT d.id FROM deliveries d JOIN task_question_messages m ON m.response_id=d.response_id
43
+ WHERE m.question_id=? AND d.state IN ('pending','sending') LIMIT 1`, question.questionId);
44
+ if (!pending) {
45
+ const prefix = Number(saved.reminder_count) ? 'Reminder · Waiting for your answer' : 'Waiting for your answer';
46
+ const command = `/task_question ${question.questionId}`;
47
+ const channel = this.store.get('SELECT channel FROM conversation_bindings WHERE id=?', saved.binding_id).channel;
48
+ const fallback = ['telegram', 'discord', 'slack', 'line'].includes(String(channel)) ? '' : `\n\n${command} snooze\n${command} mute`;
49
+ const text = `${prefix}\n${task.title}\n\n${question.text}\n\nReply to this message with your answer, or use:\n${command} answer <your answer>${fallback}`;
50
+ const responseId = this.decisions.notice(task.conversationId, text, false);
51
+ this.store.run('INSERT INTO task_question_messages VALUES(?,?)', responseId, question.questionId);
52
+ this.deliver(responseId, String(saved.binding_id), text, [
53
+ { label: 'Remind in 1 hour', data: `orch:q:${question.questionId}:snooze` },
54
+ { label: 'Mute reminders', data: `orch:q:${question.questionId}:mute` },
55
+ ]);
56
+ const count = Number(saved.reminder_count) + 1;
57
+ this.store.run('UPDATE task_questions SET reminder_count=?,next_reminder_at=? WHERE question_id=?', count, now + this.reminderMs() * (count === 1 ? 1 : count === 2 ? 3 : 6), question.questionId);
58
+ published.push([String(row.agent_session_id), responseId, text]);
59
+ }
60
+ }
61
+ if (Number(saved.state_version) !== task.stateVersion)
62
+ this.store.run('UPDATE task_questions SET state_version=? WHERE question_id=?', task.stateVersion, question.questionId);
63
+ this.suppressQuestionReports(question.questionId);
64
+ }
65
+ });
66
+ for (const item of published)
67
+ this.publish(...item);
68
+ }
69
+ suppressQuestionReports(questionId) {
70
+ // Earlier pending progress for this task is superseded by its current question.
71
+ // The durable version fence excludes later terminal results or replacement questions.
72
+ const question = this.store.get('SELECT task_id,state_version FROM task_questions WHERE question_id=?', questionId);
73
+ this.store.run("UPDATE notifications SET status='handled' WHERE task_id=? AND task_state_version<=? AND status='pending'", question.task_id, question.state_version);
74
+ this.store.run(`UPDATE outbox SET state='completed' WHERE kind='notification' AND state='pending' AND json_extract(payload_json,'$.notificationId') IN
75
+ (SELECT id FROM notifications WHERE task_id=? AND task_state_version<=? AND status='handled')`, question.task_id, question.state_version);
76
+ }
77
+ owned(scope, questionId) {
78
+ const row = this.store.get(`SELECT q.*,t.conversation_id,c.agent_session_id FROM task_questions q JOIN tasks t ON t.id=q.task_id
79
+ JOIN conversations c ON c.id=t.conversation_id JOIN conversation_bindings b ON b.id=q.binding_id
80
+ WHERE q.question_id=? AND c.agent_session_id=? AND b.channel=? AND b.chat_id=? AND (b.thread_key=? OR (b.channel='slack' AND b.thread_key='' AND EXISTS(
81
+ SELECT 1 FROM task_question_messages m JOIN deliveries d ON d.response_id=m.response_id
82
+ WHERE m.question_id=q.question_id AND d.binding_id=b.id AND d.state='delivered' AND d.provider_message_id=?)))`, questionId, scope.sessionId, scope.channel, scope.chatId, scope.thread, scope.thread);
83
+ if (!row)
84
+ throw new types_1.OrchestrationError('QUESTION_NOT_FOUND');
85
+ this.store.assertMember(String(row.conversation_id), scope.principalId);
86
+ return row;
87
+ }
88
+ handle(scope, text, inputId) {
89
+ return this.store.compose(() => this.apply(scope, text, inputId));
90
+ }
91
+ apply(scope, text, inputId) {
92
+ const command = new RegExp(`^/task_question (${UUID}) (answer|snooze|mute)(?:\\s+([\\s\\S]+))?$`).exec(text.trim());
93
+ const callback = new RegExp(`^/orch q:(${UUID}):(snooze|mute)$`).exec(text.trim());
94
+ if (!command && !callback)
95
+ return undefined;
96
+ const [, questionId, action] = (command ?? callback);
97
+ const row = this.owned(scope, questionId);
98
+ if (action === 'answer') {
99
+ const task = this.tasks.answerByUser(String(row.conversation_id), scope.principalId, String(row.task_id), questionId, command?.[3] ?? '', inputId);
100
+ this.store.run('UPDATE task_questions SET closed=1 WHERE question_id=?', questionId);
101
+ this.suppressQuestionReports(questionId);
102
+ return { text: `Answer received · ${task.title}\nThe answer is saved. Current task status: ${task.state}.`, buttons: [] };
103
+ }
104
+ const task = this.store.task(String(row.task_id));
105
+ if (row.closed || task?.state !== 'waiting_input' || task.pendingQuestion?.questionId !== questionId)
106
+ throw new types_1.OrchestrationError('STALE_QUESTION');
107
+ this.store.cancelQuestionDeliveries(questionId);
108
+ this.store.run('UPDATE task_questions SET muted=?,next_reminder_at=? WHERE question_id=?', action === 'mute' ? 1 : 0, Date.now() + 3600000, questionId);
109
+ return { text: `${action === 'mute' ? 'Reminders muted' : 'Reminder snoozed for 1 hour'} · ${task.title}\nThe task is still waiting for your answer.`, buttons: [] };
110
+ }
111
+ /** Only a platform reply to a persisted question message is an unambiguous answer. */
112
+ answerReply(input, inputId) {
113
+ if (!input.text.trim() || input.attachmentIds?.length || !input.metadata?.repliedMessageId || input.text.trim().startsWith('/'))
114
+ return undefined;
115
+ const row = this.replyQuestion(input);
116
+ if (!row)
117
+ return undefined;
118
+ const scope = { channel: input.scope.source, chatId: input.scope.chatId, thread: input.scope.threadKey, sessionId: input.scope.agentSessionId, principalId: input.scope.principalId };
119
+ return this.handle(scope, `/task_question ${row.question_id} answer ${input.text}`, inputId);
120
+ }
121
+ normalizeReply(input) {
122
+ if (input.scope.source !== 'slack' || !input.scope.threadKey || input.metadata?.repliedMessageId !== input.scope.threadKey)
123
+ return input;
124
+ const row = this.store.get(`SELECT b.conversation_id FROM task_question_messages m JOIN deliveries d ON d.response_id=m.response_id
125
+ JOIN conversation_bindings b ON b.id=d.binding_id JOIN conversations c ON c.id=b.conversation_id
126
+ WHERE d.provider_message_id=? AND d.state='delivered' AND b.channel='slack' AND b.chat_id=? AND b.account_id=?
127
+ AND b.thread_key='' AND c.agent_session_id=?`, input.scope.threadKey, input.scope.chatId, input.scope.accountId, input.scope.agentSessionId);
128
+ if (!row)
129
+ return input;
130
+ this.store.assertMember(String(row.conversation_id), input.scope.principalId);
131
+ return { ...input, scope: { ...input.scope, threadKey: '' } };
132
+ }
133
+ matches(input) {
134
+ if (/^\/task_question(?:\s|$)/.test(input.text.trim()))
135
+ return true;
136
+ if (!input.text.trim() || input.text.trim().startsWith('/') || input.attachmentIds?.length || !input.metadata?.repliedMessageId)
137
+ return false;
138
+ const question = this.replyQuestion(input);
139
+ if (!question)
140
+ return false;
141
+ if (input.scope.source !== 'slack' || !question.closed)
142
+ return true;
143
+ // Slack repeats the root message as reply metadata for every later thread message.
144
+ // Once answered, only an actual retry of the saved receipt is a question control.
145
+ if (!input.ingressKey)
146
+ return false;
147
+ const s = input.scope;
148
+ const key = (0, store_1.payloadHash)([this.store.agentId, s.source, s.accountId, s.chatId, s.threadKey, s.principalId, input.ingressKey]);
149
+ return Boolean(this.store.get(`SELECT i.input_id FROM ingress_receipts i JOIN conversation_decisions d
150
+ ON d.kind='notice' AND EXISTS(SELECT 1 FROM json_each(d.input_ids_json) WHERE value=i.input_id) WHERE i.ingress_key=?`, key));
151
+ }
152
+ replyQuestion(input) {
153
+ const scope = { channel: input.scope.source, chatId: input.scope.chatId, thread: input.scope.threadKey, sessionId: input.scope.agentSessionId };
154
+ return this.store.get(`SELECT DISTINCT m.question_id,q.closed FROM task_question_messages m JOIN task_questions q ON q.question_id=m.question_id JOIN deliveries d ON d.response_id=m.response_id
155
+ JOIN conversation_bindings b ON b.id=d.binding_id JOIN conversations c ON c.id=b.conversation_id
156
+ WHERE d.provider_message_id=? AND d.state='delivered' AND b.channel=? AND b.chat_id=? AND b.thread_key=? AND c.agent_session_id=?`, input.metadata.repliedMessageId, scope.channel, scope.chatId, scope.thread, scope.sessionId);
157
+ }
158
+ }
159
+ exports.TaskQuestions = TaskQuestions;
160
+ //# sourceMappingURL=task-questions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-questions.js","sourceRoot":"","sources":["../../src/orchestration/task-questions.ts"],"names":[],"mappings":";;;AAGA,mCAA4E;AAE5E,mCAA6C;AAE7C,MAAM,IAAI,GAAG,eAAe,CAAC;AAC7B,0FAA0F;AAC1F,MAAa,aAAa;IACxB,YAAoB,KAAyB,EAAU,KAAkB,EAAU,SAA0B,EACnG,OAAmG,EACnG,OAAsE,EACtE,UAAwB;QAHd,UAAK,GAAL,K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AAK,CAAC,QAAS,CAAC,gBAAiB,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IACnG,CAAC;CACF;AA7ID,sCA6IC"}
@@ -0,0 +1,7 @@
1
+ import { OrchestrationStore } from './store';
2
+ /** Scheduled callers need the report of their own work, not the queue acknowledgement. */
3
+ export declare function taskReport(store: OrchestrationStore, inputId: string): {
4
+ pending: boolean;
5
+ text?: string;
6
+ };
7
+ //# sourceMappingURL=task-report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-report.d.ts","sourceRoot":"","sources":["../../src/orchestration/task-report.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAG7C,0FAA0F;AAC1F,wBAAgB,UAAU,CAAC,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAoB1G"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.taskReport = taskReport;
4
+ const types_1 = require("./types");
5
+ /** Scheduled callers need the report of their own work, not the queue acknowledgement. */
6
+ function taskReport(store, inputId) {
7
+ const tasks = store.all(`SELECT DISTINCT t.snapshot_json FROM task_commands tc
8
+ JOIN conversation_decisions d ON d.id=tc.decision_id JOIN tasks t ON t.id=tc.task_id
9
+ WHERE EXISTS (SELECT 1 FROM json_each(d.input_ids_json) WHERE value=?)`, inputId)
10
+ .map(row => JSON.parse(String(row.snapshot_json)));
11
+ if (!tasks.length)
12
+ return { pending: false };
13
+ const reports = new Map();
14
+ let pending = false;
15
+ for (const task of tasks) {
16
+ if (['failed', 'cancelled', 'needs_reconciliation', 'waiting_input'].includes(task.state)) {
17
+ throw new types_1.OrchestrationError('SCHEDULED_TASK_INCOMPLETE', `Task ${task.taskId} ${task.state}: ${task.failure?.code ?? task.state} ${task.failure?.message ?? ''}`.trim());
18
+ }
19
+ if (task.state !== 'completed') {
20
+ pending = true;
21
+ continue;
22
+ }
23
+ const report = store.get(`SELECT r.id,r.generated_text FROM notifications n
24
+ JOIN assistant_responses r ON r.decision_id=n.decision_id
25
+ WHERE n.task_id=? AND n.task_state_version=? AND n.status='handled' AND r.state='completed'`, task.taskId, task.stateVersion);
26
+ if (!report?.generated_text)
27
+ pending = true;
28
+ else
29
+ reports.set(String(report.id), String(report.generated_text));
30
+ }
31
+ return pending ? { pending: true } : { pending: false, text: [...reports.values()].join('\n\n') };
32
+ }
33
+ //# sourceMappingURL=task-report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-report.js","sourceRoot":"","sources":["../../src/orchestration/task-report.ts"],"names":[],"mappings":";;AAIA,gCAoBC;AAvBD,mCAA2D;AAE3D,0FAA0F;AAC1F,SAAgB,UAAU,CAAC,KAAyB,EAAE,OAAe;IACnE,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC;;2EAEiD,EAAE,OAAO,CAAC;SAChF,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAiB,CAAC,CAAC;IACrE,IAAI,CAAC,KAAK,CAAC,MAAM;QAAE,OAAO,EAAC,OAAO,EAAC,KAAK,EAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAC;IACzC,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,QAAQ,EAAC,WAAW,EAAC,sBAAsB,EAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACvF,MAAM,IAAI,0BAAkB,CAAC,2BAA2B,EAAE,QAAQ,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,OAAO,EAAE,IAAI,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5K,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;YAAC,OAAO,GAAG,IAAI,CAAC;YAAC,SAAS;QAAC,CAAC;QAC7D,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC;;kGAEqE,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAChI,IAAI,CAAC,MAAM,EAAE,cAAc;YAAE,OAAO,GAAG,IAAI,CAAC;;YACvC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,OAAO,CAAC,CAAC,CAAC,EAAC,OAAO,EAAC,IAAI,EAAC,CAAC,CAAC,CAAC,EAAC,OAAO,EAAC,KAAK,EAAC,IAAI,EAAC,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAC,CAAC;AAC5F,CAAC"}
@@ -0,0 +1,19 @@
1
+ /** Installed into the attempt directory; never invokes a shell with task/tool data.
2
+ * Claude Code PostToolUse/Failure supplies context before its next model call.
3
+ * Stop handles an update arriving after the last tool. Empty checkpoints are silent.
4
+ */
5
+ export declare const CHECKPOINT_HOOK: string;
6
+ export declare function checkpointSettings(command: string): {
7
+ disableAllHooks: boolean;
8
+ hooks: {
9
+ [k: string]: {
10
+ matcher: string;
11
+ hooks: {
12
+ type: string;
13
+ command: string;
14
+ timeout: number;
15
+ }[];
16
+ }[];
17
+ };
18
+ };
19
+ //# sourceMappingURL=checkpoint-hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkpoint-hook.d.ts","sourceRoot":"","sources":["../../../src/orchestration/tasks/checkpoint-hook.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,eAAe,QAoC3B,CAAC;AACF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM;;;;;;;;;;;;EAEjD"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CHECKPOINT_HOOK = void 0;
4
+ exports.checkpointSettings = checkpointSettings;
5
+ /** Installed into the attempt directory; never invokes a shell with task/tool data.
6
+ * Claude Code PostToolUse/Failure supplies context before its next model call.
7
+ * Stop handles an update arriving after the last tool. Empty checkpoints are silent.
8
+ */
9
+ exports.CHECKPOINT_HOOK = String.raw `
10
+ const fs = require('fs'), http = require('http');
11
+ let input = ''; process.stdin.setEncoding('utf8');
12
+ process.stdin.on('data', chunk => { input += chunk; if (input.length > 8*1024*1024) process.exit(0); });
13
+ process.stdin.on('end', async () => {
14
+ try {
15
+ const event = JSON.parse(input);
16
+ if (event.agent_id || !['PostToolUse','PostToolUseFailure','Stop'].includes(event.hook_event_name)) return;
17
+ const ticket = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
18
+ const call = args => new Promise((resolve,reject) => {
19
+ const url = ticket.socket ? null : new URL(ticket.url);
20
+ const options = ticket.socket ? { socketPath: ticket.socket, path: '/call' } : { hostname:url.hostname, port:url.port, path:url.pathname };
21
+ const request = http.request({...options, method: 'POST', headers: { Authorization: 'Bearer '+ticket.token, 'Content-Type': 'application/json' } }, response => {
22
+ let body = ''; response.setEncoding('utf8');
23
+ response.on('data', chunk => { body += chunk; if(body.length > 2*1024*1024) response.destroy(); });
24
+ response.on('error', reject);
25
+ response.on('end', () => { try { if(response.statusCode !== 200) return reject(Error('checkpoint')); resolve(JSON.parse(body)); } catch(error) { reject(error); } });
26
+ });
27
+ request.on('error',reject); request.setTimeout(2000,()=>request.destroy(Error('timeout')));
28
+ request.end(JSON.stringify({tool:'task_checkpoint', action_id:'hook', args:{sessionId:event.session_id,...args}}));
29
+ });
30
+ const next = await call({});
31
+ const context = [next.directive ? 'Task revision '+next.revision+' received at a tool boundary. Continue this same task; do not redo completed actions.\n'+next.directive : '', next.feedback?.message].filter(Boolean).join('\n\n');
32
+ if (!context) return;
33
+ // Monitoring advice cannot keep a completed worker alive. Explicit task
34
+ // amendments still block Stop so new user work cannot be silently dropped.
35
+ if (event.hook_event_name === 'Stop' && next.directiveKind === 'advice') {
36
+ await call({ackRevision:next.revision,ackFeedback:next.feedback?.id}); return;
37
+ }
38
+ // Stop blocks only for a new revision, never because monitoring wants more work.
39
+ if (event.hook_event_name === 'Stop' && !next.directive) return;
40
+ const output = event.hook_event_name === 'Stop' ? {decision:'block',reason:context} : {hookSpecificOutput:{hookEventName:event.hook_event_name,additionalContext:context}};
41
+ await new Promise(resolve => process.stdout.write(JSON.stringify(output)+'\n',resolve));
42
+ await call({ackRevision:next.revision,ackFeedback:next.feedback?.id});
43
+ } catch { /* A bridge failure cannot kill or authorize a task; its revision stays pending. */ }
44
+ });
45
+ `;
46
+ function checkpointSettings(command) {
47
+ return { disableAllHooks: false, hooks: Object.fromEntries(['PostToolUse', 'PostToolUseFailure', 'Stop'].map(event => [event, [{ matcher: '*', hooks: [{ type: 'command', command, timeout: 5 }] }]])) };
48
+ }
49
+ //# sourceMappingURL=checkpoint-hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkpoint-hook.js","sourceRoot":"","sources":["../../../src/orchestration/tasks/checkpoint-hook.ts"],"names":[],"mappings":";;;AAyCA,gDAEC;AA3CD;;;GAGG;AACU,QAAA,eAAe,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCxC,CAAC;AACF,SAAgB,kBAAkB,CAAC,OAAe;IAChD,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,aAAa,EAAC,oBAAoB,EAAC,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACzM,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { OrchestrationStore } from '../store';
2
+ /** Conservative retention: archive clean worktrees and private shared-project
3
+ * snapshots. Dirty worktrees remain available for review. Never delete a shared
4
+ * project, uncertain attempt, or path outside the orchestration's resource directory. */
5
+ export declare class ResourceCleanup {
6
+ private readonly store;
7
+ private readonly resourceRoot;
8
+ private readonly archiveRoot;
9
+ private readonly retentionDays;
10
+ private running?;
11
+ private readonly controller;
12
+ constructor(store: OrchestrationStore, resourceRoot: string, archiveRoot: string, retentionDays: number);
13
+ tick(now?: number): Promise<void>;
14
+ settle(): Promise<void>;
15
+ stop(): void;
16
+ private run;
17
+ }
18
+ //# sourceMappingURL=cleanup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanup.d.ts","sourceRoot":"","sources":["../../../src/orchestration/tasks/cleanup.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAM9C;;yFAEyF;AACzF,qBAAa,eAAe;IAGd,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAsB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAAU,OAAO,CAAC,QAAQ,CAAC,WAAW;IAAU,OAAO,CAAC,QAAQ,CAAC,aAAa;IAFnK,OAAO,CAAC,OAAO,CAAC,CAAgB;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;gBACvB,KAAK,EAAE,kBAAkB,EAAmB,YAAY,EAAE,MAAM,EAAmB,WAAW,EAAE,MAAM,EAAmB,aAAa,EAAE,MAAM;IAC3K,IAAI,CAAC,GAAG,SAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAM/B,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAC7B,IAAI,IAAI,IAAI;YACE,GAAG;CA+ClB"}