@0xmaxma/claude-gateway 1.8.13 → 2.0.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 (594) hide show
  1. package/README.md +28 -1605
  2. package/config.template.json +7 -1
  3. package/dist/agent/runner.d.ts +394 -0
  4. package/dist/agent/runner.d.ts.map +1 -1
  5. package/dist/agent/runner.js +867 -38
  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 +372 -11
  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/api/wechat-access.d.ts +45 -0
  52. package/dist/api/wechat-access.d.ts.map +1 -0
  53. package/dist/api/wechat-access.js +48 -0
  54. package/dist/api/wechat-access.js.map +1 -0
  55. package/dist/apps/agent-container-migration.d.ts +11 -0
  56. package/dist/apps/agent-container-migration.d.ts.map +1 -0
  57. package/dist/apps/agent-container-migration.js +85 -0
  58. package/dist/apps/agent-container-migration.js.map +1 -0
  59. package/dist/apps/installer.d.ts +1 -1
  60. package/dist/apps/installer.d.ts.map +1 -1
  61. package/dist/apps/installer.js +2 -1
  62. package/dist/apps/installer.js.map +1 -1
  63. package/dist/cli/commands/tasks.d.ts +5 -0
  64. package/dist/cli/commands/tasks.d.ts.map +1 -0
  65. package/dist/cli/commands/tasks.js +92 -0
  66. package/dist/cli/commands/tasks.js.map +1 -0
  67. package/dist/cli/http-client.d.ts +2 -0
  68. package/dist/cli/http-client.d.ts.map +1 -1
  69. package/dist/cli/http-client.js +8 -3
  70. package/dist/cli/http-client.js.map +1 -1
  71. package/dist/cli/index.d.ts.map +1 -1
  72. package/dist/cli/index.js +5 -1
  73. package/dist/cli/index.js.map +1 -1
  74. package/dist/config/config-write-lock.d.ts +2 -0
  75. package/dist/config/config-write-lock.d.ts.map +1 -1
  76. package/dist/config/config-write-lock.js +5 -0
  77. package/dist/config/config-write-lock.js.map +1 -1
  78. package/dist/config/loader.d.ts.map +1 -1
  79. package/dist/config/loader.js +87 -2
  80. package/dist/config/loader.js.map +1 -1
  81. package/dist/config/migrator.d.ts.map +1 -1
  82. package/dist/config/migrator.js +12 -1
  83. package/dist/config/migrator.js.map +1 -1
  84. package/dist/config/watcher.d.ts.map +1 -1
  85. package/dist/config/watcher.js +6 -0
  86. package/dist/config/watcher.js.map +1 -1
  87. package/dist/connectors/resolve.d.ts.map +1 -1
  88. package/dist/connectors/resolve.js +3 -1
  89. package/dist/connectors/resolve.js.map +1 -1
  90. package/dist/connectors/types.d.ts +8 -0
  91. package/dist/connectors/types.d.ts.map +1 -1
  92. package/dist/cron/manager.d.ts.map +1 -1
  93. package/dist/cron/manager.js +21 -2
  94. package/dist/cron/manager.js.map +1 -1
  95. package/dist/discord/receiver.d.ts +2 -1
  96. package/dist/discord/receiver.d.ts.map +1 -1
  97. package/dist/discord/receiver.js +5 -1
  98. package/dist/discord/receiver.js.map +1 -1
  99. package/dist/history/db.d.ts +3 -0
  100. package/dist/history/db.d.ts.map +1 -1
  101. package/dist/history/db.js +21 -1
  102. package/dist/history/db.js.map +1 -1
  103. package/dist/history/types.d.ts +12 -1
  104. package/dist/history/types.d.ts.map +1 -1
  105. package/dist/history/types.js +10 -1
  106. package/dist/history/types.js.map +1 -1
  107. package/dist/index.js +48 -9
  108. package/dist/index.js.map +1 -1
  109. package/dist/orchestration/bounded-queue.d.ts +15 -0
  110. package/dist/orchestration/bounded-queue.d.ts.map +1 -0
  111. package/dist/orchestration/bounded-queue.js +58 -0
  112. package/dist/orchestration/bounded-queue.js.map +1 -0
  113. package/dist/orchestration/bridge.d.ts +55 -0
  114. package/dist/orchestration/bridge.d.ts.map +1 -0
  115. package/dist/orchestration/bridge.js +234 -0
  116. package/dist/orchestration/bridge.js.map +1 -0
  117. package/dist/orchestration/browser-routing.d.ts +7 -0
  118. package/dist/orchestration/browser-routing.d.ts.map +1 -0
  119. package/dist/orchestration/browser-routing.js +22 -0
  120. package/dist/orchestration/browser-routing.js.map +1 -0
  121. package/dist/orchestration/capabilities.d.ts +49 -0
  122. package/dist/orchestration/capabilities.d.ts.map +1 -0
  123. package/dist/orchestration/capabilities.js +417 -0
  124. package/dist/orchestration/capabilities.js.map +1 -0
  125. package/dist/orchestration/capacity.d.ts +14 -0
  126. package/dist/orchestration/capacity.d.ts.map +1 -0
  127. package/dist/orchestration/capacity.js +52 -0
  128. package/dist/orchestration/capacity.js.map +1 -0
  129. package/dist/orchestration/channel-activity.d.ts +21 -0
  130. package/dist/orchestration/channel-activity.d.ts.map +1 -0
  131. package/dist/orchestration/channel-activity.js +72 -0
  132. package/dist/orchestration/channel-activity.js.map +1 -0
  133. package/dist/orchestration/channel-controls.d.ts +32 -0
  134. package/dist/orchestration/channel-controls.d.ts.map +1 -0
  135. package/dist/orchestration/channel-controls.js +105 -0
  136. package/dist/orchestration/channel-controls.js.map +1 -0
  137. package/dist/orchestration/channel-input-media.d.ts +11 -0
  138. package/dist/orchestration/channel-input-media.d.ts.map +1 -0
  139. package/dist/orchestration/channel-input-media.js +54 -0
  140. package/dist/orchestration/channel-input-media.js.map +1 -0
  141. package/dist/orchestration/channel-media.d.ts +4 -0
  142. package/dist/orchestration/channel-media.d.ts.map +1 -0
  143. package/dist/orchestration/channel-media.js +70 -0
  144. package/dist/orchestration/channel-media.js.map +1 -0
  145. package/dist/orchestration/channel-speech.d.ts +7 -0
  146. package/dist/orchestration/channel-speech.d.ts.map +1 -0
  147. package/dist/orchestration/channel-speech.js +65 -0
  148. package/dist/orchestration/channel-speech.js.map +1 -0
  149. package/dist/orchestration/cli-skills.d.ts +12 -0
  150. package/dist/orchestration/cli-skills.d.ts.map +1 -0
  151. package/dist/orchestration/cli-skills.js +132 -0
  152. package/dist/orchestration/cli-skills.js.map +1 -0
  153. package/dist/orchestration/config.d.ts +256 -0
  154. package/dist/orchestration/config.d.ts.map +1 -0
  155. package/dist/orchestration/config.js +110 -0
  156. package/dist/orchestration/config.js.map +1 -0
  157. package/dist/orchestration/container.d.ts +21 -0
  158. package/dist/orchestration/container.d.ts.map +1 -0
  159. package/dist/orchestration/container.js +195 -0
  160. package/dist/orchestration/container.js.map +1 -0
  161. package/dist/orchestration/control-delivery.d.ts +5 -0
  162. package/dist/orchestration/control-delivery.d.ts.map +1 -0
  163. package/dist/orchestration/control-delivery.js +50 -0
  164. package/dist/orchestration/control-delivery.js.map +1 -0
  165. package/dist/orchestration/conversation-intake.d.ts +32 -0
  166. package/dist/orchestration/conversation-intake.d.ts.map +1 -0
  167. package/dist/orchestration/conversation-intake.js +92 -0
  168. package/dist/orchestration/conversation-intake.js.map +1 -0
  169. package/dist/orchestration/decisions.d.ts +27 -0
  170. package/dist/orchestration/decisions.d.ts.map +1 -0
  171. package/dist/orchestration/decisions.js +148 -0
  172. package/dist/orchestration/decisions.js.map +1 -0
  173. package/dist/orchestration/delivery.d.ts +30 -0
  174. package/dist/orchestration/delivery.d.ts.map +1 -0
  175. package/dist/orchestration/delivery.js +219 -0
  176. package/dist/orchestration/delivery.js.map +1 -0
  177. package/dist/orchestration/display-stream.d.ts +4 -0
  178. package/dist/orchestration/display-stream.d.ts.map +1 -0
  179. package/dist/orchestration/display-stream.js +77 -0
  180. package/dist/orchestration/display-stream.js.map +1 -0
  181. package/dist/orchestration/events.d.ts +30 -0
  182. package/dist/orchestration/events.d.ts.map +1 -0
  183. package/dist/orchestration/events.js +65 -0
  184. package/dist/orchestration/events.js.map +1 -0
  185. package/dist/orchestration/execution-observation.d.ts +38 -0
  186. package/dist/orchestration/execution-observation.d.ts.map +1 -0
  187. package/dist/orchestration/execution-observation.js +25 -0
  188. package/dist/orchestration/execution-observation.js.map +1 -0
  189. package/dist/orchestration/file-delivery.d.ts +16 -0
  190. package/dist/orchestration/file-delivery.d.ts.map +1 -0
  191. package/dist/orchestration/file-delivery.js +139 -0
  192. package/dist/orchestration/file-delivery.js.map +1 -0
  193. package/dist/orchestration/gateway-config.d.ts +17 -0
  194. package/dist/orchestration/gateway-config.d.ts.map +1 -0
  195. package/dist/orchestration/gateway-config.js +128 -0
  196. package/dist/orchestration/gateway-config.js.map +1 -0
  197. package/dist/orchestration/history.d.ts +13 -0
  198. package/dist/orchestration/history.d.ts.map +1 -0
  199. package/dist/orchestration/history.js +48 -0
  200. package/dist/orchestration/history.js.map +1 -0
  201. package/dist/orchestration/identity.d.ts +6 -0
  202. package/dist/orchestration/identity.d.ts.map +1 -0
  203. package/dist/orchestration/identity.js +13 -0
  204. package/dist/orchestration/identity.js.map +1 -0
  205. package/dist/orchestration/inference-errors.d.ts +3 -0
  206. package/dist/orchestration/inference-errors.d.ts.map +1 -0
  207. package/dist/orchestration/inference-errors.js +16 -0
  208. package/dist/orchestration/inference-errors.js.map +1 -0
  209. package/dist/orchestration/input-images.d.ts +12 -0
  210. package/dist/orchestration/input-images.d.ts.map +1 -0
  211. package/dist/orchestration/input-images.js +66 -0
  212. package/dist/orchestration/input-images.js.map +1 -0
  213. package/dist/orchestration/instance-lock.d.ts +5 -0
  214. package/dist/orchestration/instance-lock.d.ts.map +1 -0
  215. package/dist/orchestration/instance-lock.js +33 -0
  216. package/dist/orchestration/instance-lock.js.map +1 -0
  217. package/dist/orchestration/line-loading.d.ts +21 -0
  218. package/dist/orchestration/line-loading.d.ts.map +1 -0
  219. package/dist/orchestration/line-loading.js +89 -0
  220. package/dist/orchestration/line-loading.js.map +1 -0
  221. package/dist/orchestration/media.d.ts +3 -0
  222. package/dist/orchestration/media.d.ts.map +1 -0
  223. package/dist/orchestration/media.js +46 -0
  224. package/dist/orchestration/media.js.map +1 -0
  225. package/dist/orchestration/migrations/schema.d.ts +3 -0
  226. package/dist/orchestration/migrations/schema.d.ts.map +1 -0
  227. package/dist/orchestration/migrations/schema.js +80 -0
  228. package/dist/orchestration/migrations/schema.js.map +1 -0
  229. package/dist/orchestration/notification-mailbox.d.ts +5 -0
  230. package/dist/orchestration/notification-mailbox.d.ts.map +1 -0
  231. package/dist/orchestration/notification-mailbox.js +29 -0
  232. package/dist/orchestration/notification-mailbox.js.map +1 -0
  233. package/dist/orchestration/process-activity.d.ts +23 -0
  234. package/dist/orchestration/process-activity.d.ts.map +1 -0
  235. package/dist/orchestration/process-activity.js +95 -0
  236. package/dist/orchestration/process-activity.js.map +1 -0
  237. package/dist/orchestration/process-supervisor.d.ts +15 -0
  238. package/dist/orchestration/process-supervisor.d.ts.map +1 -0
  239. package/dist/orchestration/process-supervisor.js +92 -0
  240. package/dist/orchestration/process-supervisor.js.map +1 -0
  241. package/dist/orchestration/process-turn.d.ts +35 -0
  242. package/dist/orchestration/process-turn.d.ts.map +1 -0
  243. package/dist/orchestration/process-turn.js +246 -0
  244. package/dist/orchestration/process-turn.js.map +1 -0
  245. package/dist/orchestration/progress-review.d.ts +28 -0
  246. package/dist/orchestration/progress-review.d.ts.map +1 -0
  247. package/dist/orchestration/progress-review.js +48 -0
  248. package/dist/orchestration/progress-review.js.map +1 -0
  249. package/dist/orchestration/recovery.d.ts +8 -0
  250. package/dist/orchestration/recovery.d.ts.map +1 -0
  251. package/dist/orchestration/recovery.js +35 -0
  252. package/dist/orchestration/recovery.js.map +1 -0
  253. package/dist/orchestration/reply-context.d.ts +7 -0
  254. package/dist/orchestration/reply-context.d.ts.map +1 -0
  255. package/dist/orchestration/reply-context.js +54 -0
  256. package/dist/orchestration/reply-context.js.map +1 -0
  257. package/dist/orchestration/runtime.d.ts +232 -0
  258. package/dist/orchestration/runtime.d.ts.map +1 -0
  259. package/dist/orchestration/runtime.js +962 -0
  260. package/dist/orchestration/runtime.js.map +1 -0
  261. package/dist/orchestration/skills.d.ts +17 -0
  262. package/dist/orchestration/skills.d.ts.map +1 -0
  263. package/dist/orchestration/skills.js +32 -0
  264. package/dist/orchestration/skills.js.map +1 -0
  265. package/dist/orchestration/source-policy.d.ts +6 -0
  266. package/dist/orchestration/source-policy.d.ts.map +1 -0
  267. package/dist/orchestration/source-policy.js +16 -0
  268. package/dist/orchestration/source-policy.js.map +1 -0
  269. package/dist/orchestration/speech.d.ts +24 -0
  270. package/dist/orchestration/speech.d.ts.map +1 -0
  271. package/dist/orchestration/speech.js +61 -0
  272. package/dist/orchestration/speech.js.map +1 -0
  273. package/dist/orchestration/stop-controls.d.ts +30 -0
  274. package/dist/orchestration/stop-controls.d.ts.map +1 -0
  275. package/dist/orchestration/stop-controls.js +79 -0
  276. package/dist/orchestration/stop-controls.js.map +1 -0
  277. package/dist/orchestration/store.d.ts +86 -0
  278. package/dist/orchestration/store.d.ts.map +1 -0
  279. package/dist/orchestration/store.js +275 -0
  280. package/dist/orchestration/store.js.map +1 -0
  281. package/dist/orchestration/task-controls.d.ts +130 -0
  282. package/dist/orchestration/task-controls.d.ts.map +1 -0
  283. package/dist/orchestration/task-controls.js +55 -0
  284. package/dist/orchestration/task-controls.js.map +1 -0
  285. package/dist/orchestration/task-files.d.ts +29 -0
  286. package/dist/orchestration/task-files.d.ts.map +1 -0
  287. package/dist/orchestration/task-files.js +200 -0
  288. package/dist/orchestration/task-files.js.map +1 -0
  289. package/dist/orchestration/task-report.d.ts +7 -0
  290. package/dist/orchestration/task-report.d.ts.map +1 -0
  291. package/dist/orchestration/task-report.js +33 -0
  292. package/dist/orchestration/task-report.js.map +1 -0
  293. package/dist/orchestration/tasks/checkpoint-hook.d.ts +19 -0
  294. package/dist/orchestration/tasks/checkpoint-hook.d.ts.map +1 -0
  295. package/dist/orchestration/tasks/checkpoint-hook.js +49 -0
  296. package/dist/orchestration/tasks/checkpoint-hook.js.map +1 -0
  297. package/dist/orchestration/tasks/cleanup.d.ts +18 -0
  298. package/dist/orchestration/tasks/cleanup.d.ts.map +1 -0
  299. package/dist/orchestration/tasks/cleanup.js +113 -0
  300. package/dist/orchestration/tasks/cleanup.js.map +1 -0
  301. package/dist/orchestration/tasks/driver.d.ts +23 -0
  302. package/dist/orchestration/tasks/driver.d.ts.map +1 -0
  303. package/dist/orchestration/tasks/driver.js +209 -0
  304. package/dist/orchestration/tasks/driver.js.map +1 -0
  305. package/dist/orchestration/tasks/failure.d.ts +5 -0
  306. package/dist/orchestration/tasks/failure.d.ts.map +1 -0
  307. package/dist/orchestration/tasks/failure.js +17 -0
  308. package/dist/orchestration/tasks/failure.js.map +1 -0
  309. package/dist/orchestration/tasks/pool.d.ts +18 -0
  310. package/dist/orchestration/tasks/pool.d.ts.map +1 -0
  311. package/dist/orchestration/tasks/pool.js +73 -0
  312. package/dist/orchestration/tasks/pool.js.map +1 -0
  313. package/dist/orchestration/tasks/scheduler.d.ts +38 -0
  314. package/dist/orchestration/tasks/scheduler.d.ts.map +1 -0
  315. package/dist/orchestration/tasks/scheduler.js +160 -0
  316. package/dist/orchestration/tasks/scheduler.js.map +1 -0
  317. package/dist/orchestration/tasks/service.d.ts +109 -0
  318. package/dist/orchestration/tasks/service.d.ts.map +1 -0
  319. package/dist/orchestration/tasks/service.js +697 -0
  320. package/dist/orchestration/tasks/service.js.map +1 -0
  321. package/dist/orchestration/tasks/shared-workspace.d.ts +25 -0
  322. package/dist/orchestration/tasks/shared-workspace.d.ts.map +1 -0
  323. package/dist/orchestration/tasks/shared-workspace.js +162 -0
  324. package/dist/orchestration/tasks/shared-workspace.js.map +1 -0
  325. package/dist/orchestration/tasks/task-directive.d.ts +6 -0
  326. package/dist/orchestration/tasks/task-directive.d.ts.map +1 -0
  327. package/dist/orchestration/tasks/task-directive.js +41 -0
  328. package/dist/orchestration/tasks/task-directive.js.map +1 -0
  329. package/dist/orchestration/tasks/timing.d.ts +15 -0
  330. package/dist/orchestration/tasks/timing.d.ts.map +1 -0
  331. package/dist/orchestration/tasks/timing.js +48 -0
  332. package/dist/orchestration/tasks/timing.js.map +1 -0
  333. package/dist/orchestration/tasks/tool-repetition.d.ts +3 -0
  334. package/dist/orchestration/tasks/tool-repetition.d.ts.map +1 -0
  335. package/dist/orchestration/tasks/tool-repetition.js +30 -0
  336. package/dist/orchestration/tasks/tool-repetition.js.map +1 -0
  337. package/dist/orchestration/tasks/workspace.d.ts +24 -0
  338. package/dist/orchestration/tasks/workspace.d.ts.map +1 -0
  339. package/dist/orchestration/tasks/workspace.js +147 -0
  340. package/dist/orchestration/tasks/workspace.js.map +1 -0
  341. package/dist/orchestration/telegram-speech.d.ts +17 -0
  342. package/dist/orchestration/telegram-speech.d.ts.map +1 -0
  343. package/dist/orchestration/telegram-speech.js +55 -0
  344. package/dist/orchestration/telegram-speech.js.map +1 -0
  345. package/dist/orchestration/telegram-tool-status.d.ts +23 -0
  346. package/dist/orchestration/telegram-tool-status.d.ts.map +1 -0
  347. package/dist/orchestration/telegram-tool-status.js +207 -0
  348. package/dist/orchestration/telegram-tool-status.js.map +1 -0
  349. package/dist/orchestration/telegram-voices.d.ts +42 -0
  350. package/dist/orchestration/telegram-voices.d.ts.map +1 -0
  351. package/dist/orchestration/telegram-voices.js +70 -0
  352. package/dist/orchestration/telegram-voices.js.map +1 -0
  353. package/dist/orchestration/tool-activity.d.ts +10 -0
  354. package/dist/orchestration/tool-activity.d.ts.map +1 -0
  355. package/dist/orchestration/tool-activity.js +38 -0
  356. package/dist/orchestration/tool-activity.js.map +1 -0
  357. package/dist/orchestration/types.d.ts +177 -0
  358. package/dist/orchestration/types.d.ts.map +1 -0
  359. package/dist/orchestration/types.js +13 -0
  360. package/dist/orchestration/types.js.map +1 -0
  361. package/dist/orchestration/voice-reply-policy.d.ts +8 -0
  362. package/dist/orchestration/voice-reply-policy.d.ts.map +1 -0
  363. package/dist/orchestration/voice-reply-policy.js +46 -0
  364. package/dist/orchestration/voice-reply-policy.js.map +1 -0
  365. package/dist/orchestration/worker-shares.d.ts +8 -0
  366. package/dist/orchestration/worker-shares.d.ts.map +1 -0
  367. package/dist/orchestration/worker-shares.js +59 -0
  368. package/dist/orchestration/worker-shares.js.map +1 -0
  369. package/dist/orchestration/workflow.d.ts +121 -0
  370. package/dist/orchestration/workflow.d.ts.map +1 -0
  371. package/dist/orchestration/workflow.js +69 -0
  372. package/dist/orchestration/workflow.js.map +1 -0
  373. package/dist/session/input-image.d.ts +10 -0
  374. package/dist/session/input-image.d.ts.map +1 -0
  375. package/dist/session/input-image.js +3 -0
  376. package/dist/session/input-image.js.map +1 -0
  377. package/dist/session/process.d.ts +15 -3
  378. package/dist/session/process.d.ts.map +1 -1
  379. package/dist/session/process.js +144 -35
  380. package/dist/session/process.js.map +1 -1
  381. package/dist/session/runtime-profile.d.ts +36 -0
  382. package/dist/session/runtime-profile.d.ts.map +1 -0
  383. package/dist/session/runtime-profile.js +63 -0
  384. package/dist/session/runtime-profile.js.map +1 -0
  385. package/dist/session/store.d.ts.map +1 -1
  386. package/dist/session/store.js +23 -1
  387. package/dist/session/store.js.map +1 -1
  388. package/dist/share/share-store.d.ts +3 -1
  389. package/dist/share/share-store.d.ts.map +1 -1
  390. package/dist/share/share-store.js +13 -2
  391. package/dist/share/share-store.js.map +1 -1
  392. package/dist/shared/line-request-order.d.ts +2 -0
  393. package/dist/shared/line-request-order.d.ts.map +1 -0
  394. package/dist/shared/line-request-order.js +16 -0
  395. package/dist/shared/line-request-order.js.map +1 -0
  396. package/dist/shared/task-elapsed.d.ts +3 -0
  397. package/dist/shared/task-elapsed.d.ts.map +1 -0
  398. package/dist/shared/task-elapsed.js +12 -0
  399. package/dist/shared/task-elapsed.js.map +1 -0
  400. package/dist/shared/task-updated-time.d.ts +3 -0
  401. package/dist/shared/task-updated-time.d.ts.map +1 -0
  402. package/dist/shared/task-updated-time.js +15 -0
  403. package/dist/shared/task-updated-time.js.map +1 -0
  404. package/dist/skills/loader.d.ts +2 -0
  405. package/dist/skills/loader.d.ts.map +1 -1
  406. package/dist/skills/loader.js.map +1 -1
  407. package/dist/telegram/chunks.d.ts +19 -0
  408. package/dist/telegram/chunks.d.ts.map +1 -0
  409. package/dist/telegram/chunks.js +129 -0
  410. package/dist/telegram/chunks.js.map +1 -0
  411. package/dist/telegram/markdown.d.ts.map +1 -1
  412. package/dist/telegram/markdown.js +18 -3
  413. package/dist/telegram/markdown.js.map +1 -1
  414. package/dist/telegram/receiver.d.ts +2 -1
  415. package/dist/telegram/receiver.d.ts.map +1 -1
  416. package/dist/telegram/receiver.js +6 -1
  417. package/dist/telegram/receiver.js.map +1 -1
  418. package/dist/types.d.ts +54 -0
  419. package/dist/types.d.ts.map +1 -1
  420. package/dist/ui/web-ui.d.ts.map +1 -1
  421. package/dist/ui/web-ui.js +31 -5
  422. package/dist/ui/web-ui.js.map +1 -1
  423. package/dist/voice/diagnostics.d.ts +29 -0
  424. package/dist/voice/diagnostics.d.ts.map +1 -0
  425. package/dist/voice/diagnostics.js +37 -0
  426. package/dist/voice/diagnostics.js.map +1 -0
  427. package/dist/voice/errors.d.ts +19 -0
  428. package/dist/voice/errors.d.ts.map +1 -0
  429. package/dist/voice/errors.js +133 -0
  430. package/dist/voice/errors.js.map +1 -0
  431. package/dist/voice/line-audio.d.ts +4 -0
  432. package/dist/voice/line-audio.d.ts.map +1 -0
  433. package/dist/voice/line-audio.js +27 -0
  434. package/dist/voice/line-audio.js.map +1 -0
  435. package/dist/voice/managed-quota.d.ts +5 -0
  436. package/dist/voice/managed-quota.d.ts.map +1 -0
  437. package/dist/voice/managed-quota.js +35 -0
  438. package/dist/voice/managed-quota.js.map +1 -0
  439. package/dist/voice/mp3.d.ts +3 -0
  440. package/dist/voice/mp3.d.ts.map +1 -0
  441. package/dist/voice/mp3.js +30 -0
  442. package/dist/voice/mp3.js.map +1 -0
  443. package/dist/voice/notes.d.ts +9 -0
  444. package/dist/voice/notes.d.ts.map +1 -0
  445. package/dist/voice/notes.js +68 -0
  446. package/dist/voice/notes.js.map +1 -0
  447. package/dist/voice/playback.d.ts +22 -0
  448. package/dist/voice/playback.d.ts.map +1 -0
  449. package/dist/voice/playback.js +52 -0
  450. package/dist/voice/playback.js.map +1 -0
  451. package/dist/voice/preview.d.ts +6 -0
  452. package/dist/voice/preview.d.ts.map +1 -0
  453. package/dist/voice/preview.js +44 -0
  454. package/dist/voice/preview.js.map +1 -0
  455. package/dist/voice/protocol.d.ts +10 -0
  456. package/dist/voice/protocol.d.ts.map +1 -0
  457. package/dist/voice/protocol.js +30 -0
  458. package/dist/voice/protocol.js.map +1 -0
  459. package/dist/voice/providers/cartesia-tts.d.ts +26 -0
  460. package/dist/voice/providers/cartesia-tts.d.ts.map +1 -0
  461. package/dist/voice/providers/cartesia-tts.js +95 -0
  462. package/dist/voice/providers/cartesia-tts.js.map +1 -0
  463. package/dist/voice/providers/deepgram-stt.d.ts +20 -0
  464. package/dist/voice/providers/deepgram-stt.d.ts.map +1 -0
  465. package/dist/voice/providers/deepgram-stt.js +66 -0
  466. package/dist/voice/providers/deepgram-stt.js.map +1 -0
  467. package/dist/voice/providers/elevenlabs-stt.d.ts +20 -0
  468. package/dist/voice/providers/elevenlabs-stt.d.ts.map +1 -0
  469. package/dist/voice/providers/elevenlabs-stt.js +92 -0
  470. package/dist/voice/providers/elevenlabs-stt.js.map +1 -0
  471. package/dist/voice/providers/elevenlabs-tts.d.ts +26 -0
  472. package/dist/voice/providers/elevenlabs-tts.d.ts.map +1 -0
  473. package/dist/voice/providers/elevenlabs-tts.js +82 -0
  474. package/dist/voice/providers/elevenlabs-tts.js.map +1 -0
  475. package/dist/voice/providers/encoded-audio-tts.d.ts +21 -0
  476. package/dist/voice/providers/encoded-audio-tts.d.ts.map +1 -0
  477. package/dist/voice/providers/encoded-audio-tts.js +175 -0
  478. package/dist/voice/providers/encoded-audio-tts.js.map +1 -0
  479. package/dist/voice/providers/fake.d.ts +39 -0
  480. package/dist/voice/providers/fake.d.ts.map +1 -0
  481. package/dist/voice/providers/fake.js +41 -0
  482. package/dist/voice/providers/fake.js.map +1 -0
  483. package/dist/voice/providers/gemini-live-stt.d.ts +21 -0
  484. package/dist/voice/providers/gemini-live-stt.d.ts.map +1 -0
  485. package/dist/voice/providers/gemini-live-stt.js +158 -0
  486. package/dist/voice/providers/gemini-live-stt.js.map +1 -0
  487. package/dist/voice/providers/gemini.d.ts +60 -0
  488. package/dist/voice/providers/gemini.d.ts.map +1 -0
  489. package/dist/voice/providers/gemini.js +124 -0
  490. package/dist/voice/providers/gemini.js.map +1 -0
  491. package/dist/voice/providers/model-ref.d.ts +9 -0
  492. package/dist/voice/providers/model-ref.d.ts.map +1 -0
  493. package/dist/voice/providers/model-ref.js +31 -0
  494. package/dist/voice/providers/model-ref.js.map +1 -0
  495. package/dist/voice/providers/openrouter.d.ts +39 -0
  496. package/dist/voice/providers/openrouter.d.ts.map +1 -0
  497. package/dist/voice/providers/openrouter.js +154 -0
  498. package/dist/voice/providers/openrouter.js.map +1 -0
  499. package/dist/voice/providers/paxalabs-stt.d.ts +12 -0
  500. package/dist/voice/providers/paxalabs-stt.d.ts.map +1 -0
  501. package/dist/voice/providers/paxalabs-stt.js +41 -0
  502. package/dist/voice/providers/paxalabs-stt.js.map +1 -0
  503. package/dist/voice/providers/paxalabs-tts.d.ts +23 -0
  504. package/dist/voice/providers/paxalabs-tts.d.ts.map +1 -0
  505. package/dist/voice/providers/paxalabs-tts.js +80 -0
  506. package/dist/voice/providers/paxalabs-tts.js.map +1 -0
  507. package/dist/voice/providers/recorded-stt.d.ts +34 -0
  508. package/dist/voice/providers/recorded-stt.d.ts.map +1 -0
  509. package/dist/voice/providers/recorded-stt.js +59 -0
  510. package/dist/voice/providers/recorded-stt.js.map +1 -0
  511. package/dist/voice/providers/registry.d.ts +10 -0
  512. package/dist/voice/providers/registry.d.ts.map +1 -0
  513. package/dist/voice/providers/registry.js +77 -0
  514. package/dist/voice/providers/registry.js.map +1 -0
  515. package/dist/voice/providers/socket.d.ts +10 -0
  516. package/dist/voice/providers/socket.d.ts.map +1 -0
  517. package/dist/voice/providers/socket.js +91 -0
  518. package/dist/voice/providers/socket.js.map +1 -0
  519. package/dist/voice/providers/upstream.d.ts +9 -0
  520. package/dist/voice/providers/upstream.d.ts.map +1 -0
  521. package/dist/voice/providers/upstream.js +51 -0
  522. package/dist/voice/providers/upstream.js.map +1 -0
  523. package/dist/voice/providers/voice-catalog.d.ts +17 -0
  524. package/dist/voice/providers/voice-catalog.d.ts.map +1 -0
  525. package/dist/voice/providers/voice-catalog.js +167 -0
  526. package/dist/voice/providers/voice-catalog.js.map +1 -0
  527. package/dist/voice/queue.d.ts +2 -0
  528. package/dist/voice/queue.d.ts.map +1 -0
  529. package/dist/voice/queue.js +6 -0
  530. package/dist/voice/queue.js.map +1 -0
  531. package/dist/voice/session.d.ts +86 -0
  532. package/dist/voice/session.d.ts.map +1 -0
  533. package/dist/voice/session.js +464 -0
  534. package/dist/voice/session.js.map +1 -0
  535. package/dist/voice/turn-manager.d.ts +27 -0
  536. package/dist/voice/turn-manager.d.ts.map +1 -0
  537. package/dist/voice/turn-manager.js +75 -0
  538. package/dist/voice/turn-manager.js.map +1 -0
  539. package/dist/voice/types.d.ts +78 -0
  540. package/dist/voice/types.d.ts.map +1 -0
  541. package/dist/voice/types.js +18 -0
  542. package/dist/voice/types.js.map +1 -0
  543. package/dist/voice/wav.d.ts +2 -0
  544. package/dist/voice/wav.d.ts.map +1 -0
  545. package/dist/voice/wav.js +21 -0
  546. package/dist/voice/wav.js.map +1 -0
  547. package/dist/wechat/ilink-client.d.ts +207 -0
  548. package/dist/wechat/ilink-client.d.ts.map +1 -0
  549. package/dist/wechat/ilink-client.js +660 -0
  550. package/dist/wechat/ilink-client.js.map +1 -0
  551. package/dist/wechat/manager.d.ts +93 -0
  552. package/dist/wechat/manager.d.ts.map +1 -0
  553. package/dist/wechat/manager.js +409 -0
  554. package/dist/wechat/manager.js.map +1 -0
  555. package/dist/whatsapp/manager.d.ts.map +1 -1
  556. package/dist/whatsapp/manager.js +51 -1
  557. package/dist/whatsapp/manager.js.map +1 -1
  558. package/mcp/capability-catalog.ts +206 -0
  559. package/mcp/modules.ts +56 -0
  560. package/mcp/server.ts +18 -35
  561. package/mcp/tools/browser/module.ts +1 -1
  562. package/mcp/tools/browser/skills/open-browser/SKILL.md +5 -3
  563. package/mcp/tools/discord/commands.ts +17 -1
  564. package/mcp/tools/discord/inbound.ts +11 -0
  565. package/mcp/tools/discord/module.ts +42 -2
  566. package/mcp/tools/discord/receiver-server.ts +10 -0
  567. package/mcp/tools/discord/types.ts +4 -1
  568. package/mcp/tools/image/module.ts +3 -1
  569. package/mcp/tools/receiver-spool.test.ts +28 -0
  570. package/mcp/tools/receiver-spool.ts +56 -0
  571. package/mcp/tools/share-file/module.ts +9 -1
  572. package/mcp/tools/shared/share-client.ts +19 -0
  573. package/mcp/tools/tasks/module.ts +35 -0
  574. package/mcp/tools/telegram/media-group.ts +21 -0
  575. package/mcp/tools/telegram/receiver-server.ts +232 -11
  576. package/mcp/tools/telegram/selection-confirmation.ts +20 -0
  577. package/mcp/tools/telegram/task-browser.ts +117 -0
  578. package/mcp/tools/telegram/task-detail.ts +36 -0
  579. package/mcp/tools/telegram/task-elapsed.ts +1 -0
  580. package/mcp/tools/telegram/typing.ts +6 -116
  581. package/mcp/tools/video/module.ts +1 -1
  582. package/mcp/tools/wechat/client.ts +49 -0
  583. package/mcp/tools/wechat/module.ts +88 -0
  584. package/mcp/types.ts +5 -0
  585. package/package.json +2 -1
  586. package/resource/claude_gateway.jpeg +0 -0
  587. package/scripts/orchestration/bench-store.cjs +30 -0
  588. package/scripts/orchestration/inspect.cjs +16 -0
  589. package/scripts/orchestration/probe-profile.cjs +67 -0
  590. package/scripts/orchestration/reconcile.cjs +21 -0
  591. package/scripts/orchestration/smoke-elevenlabs.cjs +90 -0
  592. package/scripts/orchestration/smoke-media.cjs +70 -0
  593. package/scripts/orchestration/smoke-text.cjs +101 -0
  594. package/scripts/orchestration/smoke-vision.cjs +49 -0
@@ -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,GA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A,cAAS,EAAC,SAAS,CAAC,CAAC;YAAC,CAAC;QACxH,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,EAAE,qBAAqB,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QACjJ,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACvC,CAAC;CACF;AA/HD,8BA+HC"}
@@ -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"}
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResourceCleanup = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const util_1 = require("util");
6
+ const promises_1 = require("fs/promises");
7
+ const path_1 = require("path");
8
+ const crypto_1 = require("crypto");
9
+ const types_1 = require("../types");
10
+ // Resolve subprocess support only when this feature is invoked.
11
+ const exec = (file, args, options = {}) => (0, util_1.promisify)(child_process_1.execFile)(file, args, { ...options, encoding: 'utf8' });
12
+ /** Conservative retention: archive clean worktrees and private shared-project
13
+ * snapshots. Dirty worktrees remain available for review. Never delete a shared
14
+ * project, uncertain attempt, or path outside the orchestration's resource directory. */
15
+ class ResourceCleanup {
16
+ constructor(store, resourceRoot, archiveRoot, retentionDays) {
17
+ this.store = store;
18
+ this.resourceRoot = resourceRoot;
19
+ this.archiveRoot = archiveRoot;
20
+ this.retentionDays = retentionDays;
21
+ this.controller = new AbortController();
22
+ }
23
+ tick(now = Date.now()) {
24
+ if (this.controller.signal.aborted)
25
+ return Promise.resolve();
26
+ if (this.running)
27
+ return this.running;
28
+ this.running = this.run(now).finally(() => { this.running = undefined; });
29
+ return this.running;
30
+ }
31
+ async settle() { await this.running; }
32
+ stop() { this.controller.abort(); }
33
+ async run(now) {
34
+ const rows = this.store.all(`SELECT r.* FROM task_resources r JOIN tasks t ON r.task_id=t.id WHERE t.active_attempt_id IS NULL AND t.state IN ('completed','failed','cancelled')
35
+ AND r.mode NOT IN ('host','container') AND r.lifecycle_state IN ('active','retained','retained_dirty') AND COALESCE(r.cleanup_after,t.updated_at+?)<=? LIMIT 10`, this.retentionDays * 86400000, now);
36
+ for (const row of rows) {
37
+ if (this.controller.signal.aborted)
38
+ break;
39
+ try {
40
+ if (row.mode === 'host')
41
+ continue; // Operator-owned filesystem is never an expiring task artifact.
42
+ if (!/^[a-f0-9-]{36}$/.test(String(row.id)) || !/^[a-f0-9-]{36}$/.test(String(row.task_id)))
43
+ throw new types_1.OrchestrationError('INVALID_RESOURCE_PATH');
44
+ const directory = row.mode === 'shared-lock' ? (0, path_1.join)(this.resourceRoot, String(row.task_id)) : String(row.worktree_path);
45
+ const [root, location] = await Promise.all([(0, promises_1.realpath)(this.resourceRoot), (0, promises_1.realpath)(directory)]);
46
+ const ref = (0, path_1.relative)(root, location);
47
+ if (!ref || ref.startsWith('..') || (0, path_1.isAbsolute)(ref))
48
+ throw new types_1.OrchestrationError('INVALID_RESOURCE_PATH');
49
+ let main;
50
+ let archivedHead;
51
+ if (row.mode === 'isolated-worktree') {
52
+ const status = await exec('git', ['-C', location, 'status', '--porcelain'], { timeout: 15000, maxBuffer: 1048576 });
53
+ if (status.stdout.trim()) {
54
+ this.store.run("UPDATE task_resources SET lifecycle_state='retained_dirty',cleanup_after=? WHERE id=?", now + 86400000, row.id);
55
+ continue;
56
+ }
57
+ const listed = await exec('git', ['-C', location, 'worktree', 'list', '--porcelain'], { timeout: 15000, maxBuffer: 1048576 });
58
+ if (!listed.stdout.split('\n').includes(`worktree ${location}`))
59
+ throw new types_1.OrchestrationError('RESOURCE_OWNERSHIP_MISMATCH');
60
+ main = listed.stdout.split('\n').find(line => line.startsWith('worktree '))?.slice(9);
61
+ if (!main || main === location)
62
+ throw new types_1.OrchestrationError('RESOURCE_OWNERSHIP_MISMATCH');
63
+ archivedHead = (await exec('git', ['-C', location, 'rev-parse', 'HEAD'], { timeout: 15000 })).stdout.trim();
64
+ }
65
+ else if (row.mode !== 'isolated-directory' && (row.mode !== 'shared-lock' || row.lifecycle_state !== 'retained'))
66
+ continue;
67
+ await (0, promises_1.mkdir)(this.archiveRoot, { recursive: true, mode: 0o700 });
68
+ const archive = (0, path_1.join)(this.archiveRoot, `${row.id}.tar.gz`), temporary = `${archive}.${(0, crypto_1.randomUUID)()}.tmp`;
69
+ this.store.run("UPDATE task_resources SET lifecycle_state='archiving' WHERE id=?", row.id);
70
+ await exec('tar', ['-czf', temporary, '--exclude=.git', '-C', root, '--', ref], { timeout: 60000, maxBuffer: 1048576, signal: this.controller.signal });
71
+ await (0, promises_1.chmod)(temporary, 0o600);
72
+ await exec('tar', ['-tzf', temporary], { timeout: 60000, maxBuffer: 4194304, signal: this.controller.signal });
73
+ if (!(await (0, promises_1.stat)(temporary)).size)
74
+ throw new types_1.OrchestrationError('EMPTY_RESOURCE_ARCHIVE');
75
+ const file = await (0, promises_1.open)(temporary, 'r');
76
+ try {
77
+ await file.sync();
78
+ }
79
+ finally {
80
+ await file.close();
81
+ }
82
+ await (0, promises_1.rename)(temporary, archive);
83
+ const archiveDirectory = await (0, promises_1.open)(this.archiveRoot, 'r');
84
+ try {
85
+ await archiveDirectory.sync();
86
+ }
87
+ finally {
88
+ await archiveDirectory.close();
89
+ }
90
+ // The archive is durable before any owned working files are removed.
91
+ if (main) {
92
+ if ((await exec('git', ['-C', location, 'rev-parse', 'HEAD'], { timeout: 15000 })).stdout.trim() !== archivedHead)
93
+ throw new types_1.OrchestrationError('RESOURCE_CHANGED_DURING_ARCHIVE');
94
+ const clean = await exec('git', ['-C', location, 'status', '--porcelain'], { timeout: 15000, maxBuffer: 1048576 });
95
+ if (clean.stdout.trim()) {
96
+ this.store.run("UPDATE task_resources SET lifecycle_state='retained_dirty',cleanup_after=? WHERE id=?", now + 86400000, row.id);
97
+ continue;
98
+ }
99
+ await exec('git', ['-C', main, 'worktree', 'remove', '--', location], { timeout: 30000, maxBuffer: 1048576 });
100
+ }
101
+ else
102
+ await (0, promises_1.rm)(location, { recursive: true });
103
+ this.store.run("UPDATE task_resources SET lifecycle_state='archived',context_snapshot_ref=?,lock_key=NULL WHERE id=?", archive, row.id);
104
+ }
105
+ catch {
106
+ // No automatic destructive retry after an ambiguous cleanup boundary.
107
+ this.store.run("UPDATE task_resources SET lifecycle_state='cleanup_unknown' WHERE id=?", row.id);
108
+ }
109
+ }
110
+ }
111
+ }
112
+ exports.ResourceCleanup = ResourceCleanup;
113
+ //# sourceMappingURL=cleanup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanup.js","sourceRoot":"","sources":["../../../src/orchestration/tasks/cleanup.ts"],"names":[],"mappings":";;;AAAA,iDAAyC;AACzC,+BAAiC;AACjC,0CAA6E;AAC7E,+BAAkD;AAClD,mCAAoC;AAEpC,oCAA8C;AAE9C,gEAAgE;AAChE,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,IAAc,EAAE,UAAmD,EAAE,EAAE,EAAE,CACnG,IAAA,gBAAS,EAAC,wBAAQ,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAe,EAAE,CAAC,CAAC;AAC7E;;yFAEyF;AACzF,MAAa,eAAe;IAG1B,YAA6B,KAAyB,EAAmB,YAAoB,EAAmB,WAAmB,EAAmB,aAAqB;QAA9I,UAAK,GAAL,KAAK,CAAoB;QAAmB,iBAAY,GAAZ,YAAY,CAAQ;QAAmB,gBAAW,GAAX,WAAW,CAAQ;QAAmB,kBAAa,GAAb,aAAa,CAAQ;QAD1J,eAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IAC0H,CAAC;IAC/K,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;QACnB,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO;YAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;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AAM,CAAC,IAAI,EAAE,KAAK,YAAY;wBAAE,MAAM,IAAI,0BAAkB,CAAC,iCAAiC,CAAC,CAAC;oBACnL,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;oBACnH,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;wBAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,uFAAuF,EAAE,GAAG,GAAG,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;wBAAC,SAAS;oBAAC,CAAC;oBACvK,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;gBAChH,CAAC;;oBAAM,MAAM,IAAA,aAAE,EAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC/C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,sGAAsG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;YAC1I,CAAC;YAAC,MAAM,CAAC;gBACP,sEAAsE;gBACtE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,wEAAwE,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;YACnG,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA3DD,0CA2DC"}
@@ -0,0 +1,23 @@
1
+ import type { AgentConfig, GatewayConfig } from '../../types';
2
+ import { TaskBridge } from '../bridge';
3
+ import { TaskService } from './service';
4
+ import { TaskWorkspaces } from './workspace';
5
+ import { TaskAttempt, TaskSnapshot } from '../types';
6
+ import { WorkerDriver, WorkerHandle } from './scheduler';
7
+ export declare class ClaudeWorkerDriver implements WorkerDriver {
8
+ private readonly agent;
9
+ private readonly gateway;
10
+ private readonly tasks;
11
+ private readonly bridge;
12
+ private readonly workspaces;
13
+ private readonly privateRoot;
14
+ private readonly onManagedTurn?;
15
+ private readonly instanceId;
16
+ constructor(agent: AgentConfig, gateway: GatewayConfig, tasks: TaskService, bridge: TaskBridge, workspaces: TaskWorkspaces, privateRoot: string, onManagedTurn?: ((sessionId: string, text: string, metrics: import("../process-turn").ManagedTurnMetrics, skills?: string[]) => void) | undefined);
17
+ cleanup(attempt: TaskAttempt): Promise<boolean>;
18
+ reserve(taskId: string): (() => void) | undefined;
19
+ available(taskId: string): boolean;
20
+ release(taskId: string): Promise<void>;
21
+ start(task: TaskSnapshot, attempt: TaskAttempt, capacityReserved?: boolean): Promise<WorkerHandle>;
22
+ }
23
+ //# sourceMappingURL=driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../../src/orchestration/tasks/driver.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG9D,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAsB,MAAM,UAAU,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAazD,qBAAa,kBAAmB,YAAW,YAAY;IAEzC,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAe,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAiB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAC9G,OAAO,CAAC,QAAQ,CAAC,MAAM;IAAc,OAAO,CAAC,QAAQ,CAAC,UAAU;IA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