@0xmaxma/claude-gateway 2.0.6 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (429) hide show
  1. package/README.md +15 -1
  2. package/config.template.json +5 -3
  3. package/dist/agent/builtin-commands.js +5 -5
  4. package/dist/agent/builtin-commands.js.map +1 -1
  5. package/dist/agent/command-help.d.ts +9 -0
  6. package/dist/agent/command-help.d.ts.map +1 -0
  7. package/dist/agent/command-help.js +50 -0
  8. package/dist/agent/command-help.js.map +1 -0
  9. package/dist/agent/dreaming/index.d.ts +6 -3
  10. package/dist/agent/dreaming/index.d.ts.map +1 -1
  11. package/dist/agent/dreaming/index.js +21 -1
  12. package/dist/agent/dreaming/index.js.map +1 -1
  13. package/dist/agent/knowledge/reflection.d.ts +7 -4
  14. package/dist/agent/knowledge/reflection.d.ts.map +1 -1
  15. package/dist/agent/knowledge/reflection.js +19 -1
  16. package/dist/agent/knowledge/reflection.js.map +1 -1
  17. package/dist/agent/runner.d.ts +51 -3
  18. package/dist/agent/runner.d.ts.map +1 -1
  19. package/dist/agent/runner.js +244 -66
  20. package/dist/agent/runner.js.map +1 -1
  21. package/dist/agent/session-confirmations.d.ts +12 -0
  22. package/dist/agent/session-confirmations.d.ts.map +1 -0
  23. package/dist/agent/session-confirmations.js +43 -0
  24. package/dist/agent/session-confirmations.js.map +1 -0
  25. package/dist/agent/session-status.d.ts +7 -0
  26. package/dist/agent/session-status.d.ts.map +1 -0
  27. package/dist/agent/session-status.js +16 -0
  28. package/dist/agent/session-status.js.map +1 -0
  29. package/dist/agent/skill-learning/index.d.ts +5 -1
  30. package/dist/agent/skill-learning/index.d.ts.map +1 -1
  31. package/dist/agent/skill-learning/index.js +23 -1
  32. package/dist/agent/skill-learning/index.js.map +1 -1
  33. package/dist/agent/skill-learning/notifier.d.ts +2 -1
  34. package/dist/agent/skill-learning/notifier.d.ts.map +1 -1
  35. package/dist/agent/skill-learning/notifier.js +1 -0
  36. package/dist/agent/skill-learning/notifier.js.map +1 -1
  37. package/dist/api/apps-router.d.ts.map +1 -1
  38. package/dist/api/apps-router.js +1 -3
  39. package/dist/api/apps-router.js.map +1 -1
  40. package/dist/api/cron-router.d.ts +1 -1
  41. package/dist/api/cron-router.d.ts.map +1 -1
  42. package/dist/api/cron-router.js +4 -4
  43. package/dist/api/cron-router.js.map +1 -1
  44. package/dist/api/dashboard-processes.d.ts +86 -0
  45. package/dist/api/dashboard-processes.d.ts.map +1 -0
  46. package/dist/api/dashboard-processes.js +155 -0
  47. package/dist/api/dashboard-processes.js.map +1 -0
  48. package/dist/api/dashboard-sessions.d.ts +15 -0
  49. package/dist/api/dashboard-sessions.d.ts.map +1 -0
  50. package/dist/api/dashboard-sessions.js +66 -0
  51. package/dist/api/dashboard-sessions.js.map +1 -0
  52. package/dist/api/gateway-router.d.ts +3 -4
  53. package/dist/api/gateway-router.d.ts.map +1 -1
  54. package/dist/api/gateway-router.js +77 -56
  55. package/dist/api/gateway-router.js.map +1 -1
  56. package/dist/api/oauth-connectors-router.d.ts +1 -1
  57. package/dist/api/oauth-connectors-router.d.ts.map +1 -1
  58. package/dist/api/oauth-connectors-router.js +11 -21
  59. package/dist/api/oauth-connectors-router.js.map +1 -1
  60. package/dist/api/router.d.ts +1 -1
  61. package/dist/api/router.d.ts.map +1 -1
  62. package/dist/api/router.js +119 -14
  63. package/dist/api/router.js.map +1 -1
  64. package/dist/api/share-router.d.ts +1 -1
  65. package/dist/api/share-router.d.ts.map +1 -1
  66. package/dist/api/share-router.js +1 -1
  67. package/dist/api/share-router.js.map +1 -1
  68. package/dist/api/slack-webhook-router.js +1 -1
  69. package/dist/api/slack-webhook-router.js.map +1 -1
  70. package/dist/api/voice-router.d.ts +1 -0
  71. package/dist/api/voice-router.d.ts.map +1 -1
  72. package/dist/api/voice-router.js +7 -0
  73. package/dist/api/voice-router.js.map +1 -1
  74. package/dist/api/voice-settings-router.d.ts.map +1 -1
  75. package/dist/api/voice-settings-router.js +2 -1
  76. package/dist/api/voice-settings-router.js.map +1 -1
  77. package/dist/apps/agent-container-migration.d.ts +2 -0
  78. package/dist/apps/agent-container-migration.d.ts.map +1 -1
  79. package/dist/apps/agent-container-migration.js +59 -2
  80. package/dist/apps/agent-container-migration.js.map +1 -1
  81. package/dist/apps/agent-manager.d.ts +4 -2
  82. package/dist/apps/agent-manager.d.ts.map +1 -1
  83. package/dist/apps/agent-manager.js +39 -3
  84. package/dist/apps/agent-manager.js.map +1 -1
  85. package/dist/apps/installer.d.ts +4 -3
  86. package/dist/apps/installer.d.ts.map +1 -1
  87. package/dist/apps/installer.js +8 -4
  88. package/dist/apps/installer.js.map +1 -1
  89. package/dist/build-provenance.json +8 -0
  90. package/dist/cli/args.js +1 -1
  91. package/dist/cli/args.js.map +1 -1
  92. package/dist/cli/commands/app.d.ts.map +1 -1
  93. package/dist/cli/commands/app.js +39 -3
  94. package/dist/cli/commands/app.js.map +1 -1
  95. package/dist/cli/commands/doctor.d.ts.map +1 -1
  96. package/dist/cli/commands/doctor.js +6 -2
  97. package/dist/cli/commands/doctor.js.map +1 -1
  98. package/dist/cli/commands/safemode.d.ts +2 -0
  99. package/dist/cli/commands/safemode.d.ts.map +1 -0
  100. package/dist/cli/commands/safemode.js +279 -0
  101. package/dist/cli/commands/safemode.js.map +1 -0
  102. package/dist/cli/dependencies.d.ts +2 -0
  103. package/dist/cli/dependencies.d.ts.map +1 -1
  104. package/dist/cli/dependencies.js +81 -0
  105. package/dist/cli/dependencies.js.map +1 -1
  106. package/dist/cli/index.d.ts.map +1 -1
  107. package/dist/cli/index.js +11 -1
  108. package/dist/cli/index.js.map +1 -1
  109. package/dist/cli/manager.d.ts.map +1 -1
  110. package/dist/cli/manager.js +4 -1
  111. package/dist/cli/manager.js.map +1 -1
  112. package/dist/config/agent-lifecycle.d.ts +26 -0
  113. package/dist/config/agent-lifecycle.d.ts.map +1 -0
  114. package/dist/config/agent-lifecycle.js +63 -0
  115. package/dist/config/agent-lifecycle.js.map +1 -0
  116. package/dist/config/loader.d.ts.map +1 -1
  117. package/dist/config/loader.js +11 -0
  118. package/dist/config/loader.js.map +1 -1
  119. package/dist/config/reload-policy.d.ts +9 -0
  120. package/dist/config/reload-policy.d.ts.map +1 -0
  121. package/dist/config/reload-policy.js +62 -0
  122. package/dist/config/reload-policy.js.map +1 -0
  123. package/dist/config/watcher.d.ts +3 -2
  124. package/dist/config/watcher.d.ts.map +1 -1
  125. package/dist/config/watcher.js +34 -51
  126. package/dist/config/watcher.js.map +1 -1
  127. package/dist/cron/tool-schemas.d.ts +296 -0
  128. package/dist/cron/tool-schemas.d.ts.map +1 -0
  129. package/dist/cron/tool-schemas.js +122 -0
  130. package/dist/cron/tool-schemas.js.map +1 -0
  131. package/dist/history/db.d.ts +4 -0
  132. package/dist/history/db.d.ts.map +1 -1
  133. package/dist/history/db.js +33 -5
  134. package/dist/history/db.js.map +1 -1
  135. package/dist/history/types.d.ts +1 -0
  136. package/dist/history/types.d.ts.map +1 -1
  137. package/dist/index.js +141 -158
  138. package/dist/index.js.map +1 -1
  139. package/dist/orchestration/agent-tool-schemas.js +4 -4
  140. package/dist/orchestration/agent-tool-schemas.js.map +1 -1
  141. package/dist/orchestration/background-work.d.ts +9 -0
  142. package/dist/orchestration/background-work.d.ts.map +1 -0
  143. package/dist/orchestration/background-work.js +49 -0
  144. package/dist/orchestration/background-work.js.map +1 -0
  145. package/dist/orchestration/bridge.d.ts +6 -15
  146. package/dist/orchestration/bridge.d.ts.map +1 -1
  147. package/dist/orchestration/bridge.js +67 -32
  148. package/dist/orchestration/bridge.js.map +1 -1
  149. package/dist/orchestration/capabilities.d.ts.map +1 -1
  150. package/dist/orchestration/capabilities.js +18 -10
  151. package/dist/orchestration/capabilities.js.map +1 -1
  152. package/dist/orchestration/capacity.d.ts +3 -2
  153. package/dist/orchestration/capacity.d.ts.map +1 -1
  154. package/dist/orchestration/capacity.js +7 -0
  155. package/dist/orchestration/capacity.js.map +1 -1
  156. package/dist/orchestration/channel-controls.d.ts.map +1 -1
  157. package/dist/orchestration/channel-controls.js +3 -2
  158. package/dist/orchestration/channel-controls.js.map +1 -1
  159. package/dist/orchestration/channel-speech.d.ts +1 -1
  160. package/dist/orchestration/channel-speech.d.ts.map +1 -1
  161. package/dist/orchestration/channel-speech.js +2 -2
  162. package/dist/orchestration/channel-speech.js.map +1 -1
  163. package/dist/orchestration/cli-skills.d.ts +5 -0
  164. package/dist/orchestration/cli-skills.d.ts.map +1 -1
  165. package/dist/orchestration/config.d.ts +13 -0
  166. package/dist/orchestration/config.d.ts.map +1 -1
  167. package/dist/orchestration/config.js +6 -0
  168. package/dist/orchestration/config.js.map +1 -1
  169. package/dist/orchestration/container-tool-schemas.d.ts +37 -0
  170. package/dist/orchestration/container-tool-schemas.d.ts.map +1 -0
  171. package/dist/orchestration/container-tool-schemas.js +27 -0
  172. package/dist/orchestration/container-tool-schemas.js.map +1 -0
  173. package/dist/orchestration/container.d.ts.map +1 -1
  174. package/dist/orchestration/container.js +7 -0
  175. package/dist/orchestration/container.js.map +1 -1
  176. package/dist/orchestration/dashboard-provider-wait.d.ts +9 -0
  177. package/dist/orchestration/dashboard-provider-wait.d.ts.map +1 -0
  178. package/dist/orchestration/dashboard-provider-wait.js +26 -0
  179. package/dist/orchestration/dashboard-provider-wait.js.map +1 -0
  180. package/dist/orchestration/dashboard-reader-worker.js +18 -11
  181. package/dist/orchestration/dashboard-reader-worker.js.map +1 -1
  182. package/dist/orchestration/decision-context.js +1 -1
  183. package/dist/orchestration/decision-context.js.map +1 -1
  184. package/dist/orchestration/delivery.d.ts +2 -1
  185. package/dist/orchestration/delivery.d.ts.map +1 -1
  186. package/dist/orchestration/delivery.js +39 -5
  187. package/dist/orchestration/delivery.js.map +1 -1
  188. package/dist/orchestration/file-delivery.d.ts +1 -1
  189. package/dist/orchestration/file-delivery.d.ts.map +1 -1
  190. package/dist/orchestration/file-delivery.js +8 -1
  191. package/dist/orchestration/file-delivery.js.map +1 -1
  192. package/dist/orchestration/gateway-config.js +1 -1
  193. package/dist/orchestration/gateway-config.js.map +1 -1
  194. package/dist/orchestration/gateway-tasks/controller.d.ts +29 -0
  195. package/dist/orchestration/gateway-tasks/controller.d.ts.map +1 -0
  196. package/dist/orchestration/gateway-tasks/controller.js +139 -0
  197. package/dist/orchestration/gateway-tasks/controller.js.map +1 -0
  198. package/dist/orchestration/gateway-tasks/safemode.d.ts +19 -0
  199. package/dist/orchestration/gateway-tasks/safemode.d.ts.map +1 -0
  200. package/dist/orchestration/gateway-tasks/safemode.js +128 -0
  201. package/dist/orchestration/gateway-tasks/safemode.js.map +1 -0
  202. package/dist/orchestration/line-quota.d.ts +57 -0
  203. package/dist/orchestration/line-quota.d.ts.map +1 -0
  204. package/dist/orchestration/line-quota.js +191 -0
  205. package/dist/orchestration/line-quota.js.map +1 -0
  206. package/dist/orchestration/process-turn.d.ts +12 -2
  207. package/dist/orchestration/process-turn.d.ts.map +1 -1
  208. package/dist/orchestration/process-turn.js +72 -12
  209. package/dist/orchestration/process-turn.js.map +1 -1
  210. package/dist/orchestration/provider-admission.d.ts +63 -0
  211. package/dist/orchestration/provider-admission.d.ts.map +1 -0
  212. package/dist/orchestration/provider-admission.js +175 -0
  213. package/dist/orchestration/provider-admission.js.map +1 -0
  214. package/dist/orchestration/provider-error-metadata.d.ts +9 -0
  215. package/dist/orchestration/provider-error-metadata.d.ts.map +1 -0
  216. package/dist/orchestration/provider-error-metadata.js +28 -0
  217. package/dist/orchestration/provider-error-metadata.js.map +1 -0
  218. package/dist/orchestration/provider-scope.d.ts +28 -0
  219. package/dist/orchestration/provider-scope.d.ts.map +1 -0
  220. package/dist/orchestration/provider-scope.js +137 -0
  221. package/dist/orchestration/provider-scope.js.map +1 -0
  222. package/dist/orchestration/recovery.d.ts.map +1 -1
  223. package/dist/orchestration/recovery.js +4 -2
  224. package/dist/orchestration/recovery.js.map +1 -1
  225. package/dist/orchestration/runtime.d.ts +23 -0
  226. package/dist/orchestration/runtime.d.ts.map +1 -1
  227. package/dist/orchestration/runtime.js +248 -28
  228. package/dist/orchestration/runtime.js.map +1 -1
  229. package/dist/orchestration/skills.d.ts +2 -0
  230. package/dist/orchestration/skills.d.ts.map +1 -1
  231. package/dist/orchestration/skills.js +4 -3
  232. package/dist/orchestration/skills.js.map +1 -1
  233. package/dist/orchestration/store.d.ts +6 -0
  234. package/dist/orchestration/store.d.ts.map +1 -1
  235. package/dist/orchestration/store.js +51 -10
  236. package/dist/orchestration/store.js.map +1 -1
  237. package/dist/orchestration/task-controls.d.ts +12 -0
  238. package/dist/orchestration/task-controls.d.ts.map +1 -1
  239. package/dist/orchestration/task-controls.js +3 -1
  240. package/dist/orchestration/task-controls.js.map +1 -1
  241. package/dist/orchestration/tasks/driver.d.ts +5 -2
  242. package/dist/orchestration/tasks/driver.d.ts.map +1 -1
  243. package/dist/orchestration/tasks/driver.js +116 -15
  244. package/dist/orchestration/tasks/driver.js.map +1 -1
  245. package/dist/orchestration/tasks/pool.d.ts +2 -0
  246. package/dist/orchestration/tasks/pool.d.ts.map +1 -1
  247. package/dist/orchestration/tasks/pool.js +4 -0
  248. package/dist/orchestration/tasks/pool.js.map +1 -1
  249. package/dist/orchestration/tasks/scheduler.d.ts +12 -2
  250. package/dist/orchestration/tasks/scheduler.d.ts.map +1 -1
  251. package/dist/orchestration/tasks/scheduler.js +81 -7
  252. package/dist/orchestration/tasks/scheduler.js.map +1 -1
  253. package/dist/orchestration/tasks/service.d.ts +5 -1
  254. package/dist/orchestration/tasks/service.d.ts.map +1 -1
  255. package/dist/orchestration/tasks/service.js +49 -10
  256. package/dist/orchestration/tasks/service.js.map +1 -1
  257. package/dist/orchestration/token-ledger.d.ts +1 -0
  258. package/dist/orchestration/token-ledger.d.ts.map +1 -1
  259. package/dist/orchestration/token-ledger.js +6 -2
  260. package/dist/orchestration/token-ledger.js.map +1 -1
  261. package/dist/orchestration/token-usage.d.ts +3 -0
  262. package/dist/orchestration/token-usage.d.ts.map +1 -1
  263. package/dist/orchestration/token-usage.js +12 -3
  264. package/dist/orchestration/token-usage.js.map +1 -1
  265. package/dist/orchestration/types.d.ts +22 -1
  266. package/dist/orchestration/types.d.ts.map +1 -1
  267. package/dist/orchestration/types.js.map +1 -1
  268. package/dist/orchestration/worker-crons.d.ts +5 -0
  269. package/dist/orchestration/worker-crons.d.ts.map +1 -0
  270. package/dist/orchestration/worker-crons.js +84 -0
  271. package/dist/orchestration/worker-crons.js.map +1 -0
  272. package/dist/orchestration/worker-harness.d.ts +15 -0
  273. package/dist/orchestration/worker-harness.d.ts.map +1 -0
  274. package/dist/orchestration/worker-harness.js +72 -0
  275. package/dist/orchestration/worker-harness.js.map +1 -0
  276. package/dist/safemode/config.d.ts +7 -0
  277. package/dist/safemode/config.d.ts.map +1 -0
  278. package/dist/safemode/config.js +67 -0
  279. package/dist/safemode/config.js.map +1 -0
  280. package/dist/safemode/context.d.ts +7 -0
  281. package/dist/safemode/context.d.ts.map +1 -0
  282. package/dist/safemode/context.js +397 -0
  283. package/dist/safemode/context.js.map +1 -0
  284. package/dist/safemode/external-owners.d.ts +19 -0
  285. package/dist/safemode/external-owners.d.ts.map +1 -0
  286. package/dist/safemode/external-owners.js +229 -0
  287. package/dist/safemode/external-owners.js.map +1 -0
  288. package/dist/safemode/native.d.ts +38 -0
  289. package/dist/safemode/native.d.ts.map +1 -0
  290. package/dist/safemode/native.js +220 -0
  291. package/dist/safemode/native.js.map +1 -0
  292. package/dist/safemode/params.d.ts +10 -0
  293. package/dist/safemode/params.d.ts.map +1 -0
  294. package/dist/safemode/params.js +86 -0
  295. package/dist/safemode/params.js.map +1 -0
  296. package/dist/safemode/provenance.d.ts +45 -0
  297. package/dist/safemode/provenance.d.ts.map +1 -0
  298. package/dist/safemode/provenance.js +153 -0
  299. package/dist/safemode/provenance.js.map +1 -0
  300. package/dist/safemode/runner.d.ts +17 -0
  301. package/dist/safemode/runner.d.ts.map +1 -0
  302. package/dist/safemode/runner.js +398 -0
  303. package/dist/safemode/runner.js.map +1 -0
  304. package/dist/safemode/store.d.ts +56 -0
  305. package/dist/safemode/store.d.ts.map +1 -0
  306. package/dist/safemode/store.js +451 -0
  307. package/dist/safemode/store.js.map +1 -0
  308. package/dist/session/codex-auth.d.ts +37 -0
  309. package/dist/session/codex-auth.d.ts.map +1 -0
  310. package/dist/session/codex-auth.js +266 -0
  311. package/dist/session/codex-auth.js.map +1 -0
  312. package/dist/session/codex-container-runtime.d.ts +15 -0
  313. package/dist/session/codex-container-runtime.d.ts.map +1 -0
  314. package/dist/session/codex-container-runtime.js +85 -0
  315. package/dist/session/codex-container-runtime.js.map +1 -0
  316. package/dist/session/codex-context-defaults.json +5 -0
  317. package/dist/session/codex-context.d.ts +13 -0
  318. package/dist/session/codex-context.d.ts.map +1 -0
  319. package/dist/session/codex-context.js +27 -0
  320. package/dist/session/codex-context.js.map +1 -0
  321. package/dist/session/codex-extension-discovery.d.ts +21 -0
  322. package/dist/session/codex-extension-discovery.d.ts.map +1 -0
  323. package/dist/session/codex-extension-discovery.js +132 -0
  324. package/dist/session/codex-extension-discovery.js.map +1 -0
  325. package/dist/session/codex-native-mcp-client.d.ts +37 -0
  326. package/dist/session/codex-native-mcp-client.d.ts.map +1 -0
  327. package/dist/session/codex-native-mcp-client.js +164 -0
  328. package/dist/session/codex-native-mcp-client.js.map +1 -0
  329. package/dist/session/codex-policy.d.ts +6 -0
  330. package/dist/session/codex-policy.d.ts.map +1 -0
  331. package/dist/session/codex-policy.js +17 -0
  332. package/dist/session/codex-policy.js.map +1 -0
  333. package/dist/session/codex-process.d.ts +120 -0
  334. package/dist/session/codex-process.d.ts.map +1 -0
  335. package/dist/session/codex-process.js +817 -0
  336. package/dist/session/codex-process.js.map +1 -0
  337. package/dist/session/codex-runtime.d.ts +20 -0
  338. package/dist/session/codex-runtime.d.ts.map +1 -0
  339. package/dist/session/codex-runtime.js +190 -0
  340. package/dist/session/codex-runtime.js.map +1 -0
  341. package/dist/session/codex-tool-capture.d.ts +35 -0
  342. package/dist/session/codex-tool-capture.d.ts.map +1 -0
  343. package/dist/session/codex-tool-capture.js +178 -0
  344. package/dist/session/codex-tool-capture.js.map +1 -0
  345. package/dist/session/container-connectors.d.ts +10 -0
  346. package/dist/session/container-connectors.d.ts.map +1 -0
  347. package/dist/session/container-connectors.js +41 -0
  348. package/dist/session/container-connectors.js.map +1 -0
  349. package/dist/session/container-extensions.d.ts +4 -0
  350. package/dist/session/container-extensions.d.ts.map +1 -0
  351. package/dist/session/container-extensions.js +45 -0
  352. package/dist/session/container-extensions.js.map +1 -0
  353. package/dist/session/managed-connectors.d.ts +16 -0
  354. package/dist/session/managed-connectors.d.ts.map +1 -0
  355. package/dist/session/managed-connectors.js +25 -0
  356. package/dist/session/managed-connectors.js.map +1 -0
  357. package/dist/session/process-diagnostics.d.ts +14 -0
  358. package/dist/session/process-diagnostics.d.ts.map +1 -0
  359. package/dist/session/process-diagnostics.js +39 -0
  360. package/dist/session/process-diagnostics.js.map +1 -0
  361. package/dist/session/process.d.ts +4 -0
  362. package/dist/session/process.d.ts.map +1 -1
  363. package/dist/session/process.js +21 -16
  364. package/dist/session/process.js.map +1 -1
  365. package/dist/session/request-tool-capture.d.ts +1 -1
  366. package/dist/session/request-tool-capture.d.ts.map +1 -1
  367. package/dist/session/runtime-profile.d.ts +8 -0
  368. package/dist/session/runtime-profile.d.ts.map +1 -1
  369. package/dist/session/runtime-profile.js +3 -2
  370. package/dist/session/runtime-profile.js.map +1 -1
  371. package/dist/session/worker-environment.d.ts +5 -0
  372. package/dist/session/worker-environment.d.ts.map +1 -0
  373. package/dist/session/worker-environment.js +27 -0
  374. package/dist/session/worker-environment.js.map +1 -0
  375. package/dist/session/worker-extensions.d.ts +20 -0
  376. package/dist/session/worker-extensions.d.ts.map +1 -0
  377. package/dist/session/worker-extensions.js +322 -0
  378. package/dist/session/worker-extensions.js.map +1 -0
  379. package/dist/share/share-store.d.ts +5 -11
  380. package/dist/share/share-store.d.ts.map +1 -1
  381. package/dist/share/share-store.js +33 -5
  382. package/dist/share/share-store.js.map +1 -1
  383. package/dist/skills/loader.d.ts +2 -0
  384. package/dist/skills/loader.d.ts.map +1 -1
  385. package/dist/skills/loader.js.map +1 -1
  386. package/dist/types.d.ts +30 -0
  387. package/dist/types.d.ts.map +1 -1
  388. package/dist/ui/codex-context.d.ts +4 -0
  389. package/dist/ui/codex-context.d.ts.map +1 -0
  390. package/dist/ui/codex-context.js +15 -0
  391. package/dist/ui/codex-context.js.map +1 -0
  392. package/dist/ui/dashboard-client.d.ts.map +1 -1
  393. package/dist/ui/dashboard-client.js +17 -13
  394. package/dist/ui/dashboard-client.js.map +1 -1
  395. package/dist/ui/dashboard-presentation.d.ts +3 -1
  396. package/dist/ui/dashboard-presentation.d.ts.map +1 -1
  397. package/dist/ui/dashboard-presentation.js +17 -3
  398. package/dist/ui/dashboard-presentation.js.map +1 -1
  399. package/dist/ui/token-report.d.ts +9 -0
  400. package/dist/ui/token-report.d.ts.map +1 -1
  401. package/dist/ui/token-report.js +23 -11
  402. package/dist/ui/token-report.js.map +1 -1
  403. package/dist/ui/web-ui.d.ts.map +1 -1
  404. package/dist/ui/web-ui.js +53 -132
  405. package/dist/ui/web-ui.js.map +1 -1
  406. package/dist/voice/providers/paxalabs-live-stt.d.ts +29 -0
  407. package/dist/voice/providers/paxalabs-live-stt.d.ts.map +1 -0
  408. package/dist/voice/providers/paxalabs-live-stt.js +137 -0
  409. package/dist/voice/providers/paxalabs-live-stt.js.map +1 -0
  410. package/dist/voice/providers/registry.d.ts.map +1 -1
  411. package/dist/voice/providers/registry.js +2 -1
  412. package/dist/voice/providers/registry.js.map +1 -1
  413. package/mcp/capability-catalog.ts +2 -0
  414. package/mcp/extension-catalog.ts +18 -0
  415. package/mcp/lazy-connector.ts +4 -2
  416. package/mcp/lazy-tools.test.ts +29 -0
  417. package/mcp/modules.ts +1 -0
  418. package/mcp/server.ts +2 -2
  419. package/mcp/tools/cron/module.ts +8 -114
  420. package/mcp/tools/discord/commands.ts +4 -1
  421. package/mcp/tools/safemode/module.test.ts +29 -0
  422. package/mcp/tools/telegram/receiver-server.ts +6 -24
  423. package/mcp/tools/telegram/task-detail.ts +2 -1
  424. package/package.json +3 -2
  425. package/scripts/orchestration/audit-codex-context.cjs +83 -0
  426. package/scripts/orchestration/benchmark-worker-harnesses.cjs +112 -0
  427. package/scripts/orchestration/smoke-codex-extensions.ts +29 -0
  428. package/scripts/orchestration/smoke-codex-worker.cjs +166 -0
  429. package/scripts/orchestration/smoke-safemode-codex.cjs +66 -0
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.AgentRunner = exports.CHANNEL_COALESCE_WINDOW_MS = exports.WHATSAPP_CLOUD_WINDOW_NOTE = exports.DEFAULT_MODELS = exports.MAX_IMAGE_SIZE_BYTES = void 0;
37
37
  exports.toRelMediaFiles = toRelMediaFiles;
38
+ const session_status_1 = require("./session-status");
38
39
  const session_compaction_scheduler_1 = require("./session-compaction-scheduler");
39
40
  const session_compaction_1 = require("../orchestration/session-compaction");
40
41
  const config_1 = require("./dreaming/config");
@@ -76,6 +77,8 @@ const pending_senders_1 = require("../api/pending-senders");
76
77
  const markdown_1 = require("../telegram/markdown");
77
78
  const skills_1 = require("../skills");
78
79
  const builtin_commands_1 = require("./builtin-commands");
80
+ const command_help_1 = require("./command-help");
81
+ const session_confirmations_1 = require("./session-confirmations");
79
82
  const model_catalog_1 = require("./model-catalog");
80
83
  const safe_mode_1 = require("./safe-mode");
81
84
  const config_3 = require("./skill-learning/config");
@@ -125,15 +128,23 @@ exports.MAX_IMAGE_SIZE_BYTES = 10 * 1024 * 1024;
125
128
  // is api.anthropic.com. Behind a proxy the `[1m]` id suffix and the
126
129
  // `context-1m-2025-08-07` beta header are what actually buy the larger window,
127
130
  // which is exactly what the paired rows below encode.
131
+ //
132
+ // Opus 5.5 (`claude-opus-5-5`) follows the same convention on its own family:
133
+ // it takes the bare `opus` alias and Opus 5 is demoted to `opus5`, mirroring
134
+ // the Opus 5 -> Opus 4.8 demotion above and the Fable 5.1 -> Fable 5 one.
135
+ // Selection still stores the resolved id, so an agent already on Opus 5 stays
136
+ // on claude-opus-5 — only `/model opus` from now on resolves to 5.5.
128
137
  exports.DEFAULT_MODELS = [
129
138
  { id: 'claude-fable-5-1[1m]', label: 'Fable 5.1 (1M)', alias: 'fable[1m]', contextWindow: 1000000 },
130
139
  { id: 'claude-fable-5[1m]', label: 'Fable 5 (1M)', alias: 'fable5[1m]', contextWindow: 1000000 },
131
- { id: 'claude-opus-5[1m]', label: 'Opus 5 (1M)', alias: 'opus[1m]', contextWindow: 1000000 },
140
+ { id: 'claude-opus-5-5[1m]', label: 'Opus 5.5 (1M)', alias: 'opus[1m]', contextWindow: 1000000 },
141
+ { id: 'claude-opus-5[1m]', label: 'Opus 5 (1M)', alias: 'opus5[1m]', contextWindow: 1000000 },
132
142
  { id: 'claude-opus-4-8[1m]', label: 'Opus 4.8 (1M)', alias: 'opus48[1m]', contextWindow: 1000000 },
133
143
  { id: 'claude-sonnet-5[1m]', label: 'Sonnet 5 (1M)', alias: 'sonnet[1m]', contextWindow: 1000000 },
134
144
  { id: 'claude-fable-5-1', label: 'Fable 5.1', alias: 'fable', contextWindow: 200000 },
135
145
  { id: 'claude-fable-5', label: 'Fable 5', alias: 'fable5', contextWindow: 200000 },
136
- { id: 'claude-opus-5', label: 'Opus 5', alias: 'opus', contextWindow: 200000 },
146
+ { id: 'claude-opus-5-5', label: 'Opus 5.5', alias: 'opus', contextWindow: 200000 },
147
+ { id: 'claude-opus-5', label: 'Opus 5', alias: 'opus5', contextWindow: 200000 },
137
148
  { id: 'claude-opus-4-8', label: 'Opus 4.8', alias: 'opus48', contextWindow: 200000 },
138
149
  { id: 'claude-opus-4-6', label: 'Opus 4.6', alias: 'opus46', contextWindow: 200000 },
139
150
  { id: 'claude-sonnet-5', label: 'Sonnet 5', alias: 'sonnet', contextWindow: 200000 },
@@ -184,20 +195,27 @@ exports.CHANNEL_COALESCE_WINDOW_MS = 1200;
184
195
  /**
185
196
  * Move UI-uploaded files from staging (ui-upload/) to permanent per-session storage
186
197
  * (media/api-{sessionId}/), matching the same pattern Telegram uses.
187
- * Returns updated relative paths; falls back to original path on error.
198
+ * Queued admission supplies an isolated preparation directory: copy without
199
+ * consuming staging, and fail if preparation cannot read an upload. Legacy
200
+ * callers move files and retain the original-path fallback on error.
188
201
  */
189
- async function promoteUiUploads(agentsBaseDir, agentId, sessionId, mediaFiles, logger) {
202
+ async function promoteUiUploads(agentsBaseDir, agentId, sessionId, mediaFiles, logger, preparationDir) {
190
203
  return Promise.all(mediaFiles.map(async (relPath) => {
191
204
  if (!relPath.startsWith('media/ui-upload/'))
192
205
  return relPath;
193
206
  try {
194
207
  const srcAbs = media_store_1.MediaStore.resolvePath(agentsBaseDir, agentId, relPath);
195
- const newRelPath = media_store_1.MediaStore.copyToMedia(agentsBaseDir, agentId, `api-${sessionId}`, srcAbs);
196
- await fsPromises.unlink(srcAbs).catch(() => { });
208
+ const newRelPath = media_store_1.MediaStore.copyToMedia(agentsBaseDir, agentId, preparationDir ?? `api-${sessionId}`, srcAbs);
209
+ // Admission may reject after preparation. Leave staging available for a
210
+ // retry; the existing staging TTL owns cleanup for this path.
211
+ if (!preparationDir)
212
+ await fsPromises.unlink(srcAbs).catch(() => { });
197
213
  return newRelPath;
198
214
  }
199
215
  catch (err) {
200
216
  logger.warn('Failed to promote ui-upload to session storage', { relPath, err });
217
+ if (preparationDir)
218
+ throw err; // Never admit an unreadable attachment.
201
219
  return relPath;
202
220
  }
203
221
  }));
@@ -241,6 +259,8 @@ class AgentRunner extends events_1.EventEmitter {
241
259
  channelFor(chatId) {
242
260
  return this.channelSourceMap.get(chatId) ?? 'telegram';
243
261
  }
262
+ get idleTimeoutMs() { return (this.agentConfig.session?.idleTimeoutMinutes ?? DEFAULT_IDLE_TIMEOUT_MINUTES) * 60000; }
263
+ get maxConcurrent() { return this.agentConfig.session?.maxConcurrent ?? DEFAULT_MAX_CONCURRENT; }
244
264
  requiresDurableChannelIngress(source) {
245
265
  return Boolean((this.agentConfig.orchestration?.enabled && (this.agentConfig.orchestration.channels ?? ['api']).includes(source)) ||
246
266
  this.orchestration?.ownsChannelIngress(source));
@@ -301,11 +321,27 @@ class AgentRunner extends events_1.EventEmitter {
301
321
  refreshSkills: async () => {
302
322
  try {
303
323
  const { discoverCliSkills } = await Promise.resolve().then(() => __importStar(require('../orchestration/cli-skills')));
304
- this.skillRegistry.cliSkills = await discoverCliSkills(this.agentConfig, undefined, this.gatewayConfig);
324
+ this.skillRegistry.cliSkills = [];
305
325
  delete this.skillRegistry.cliDiscoveryError;
326
+ try {
327
+ this.skillRegistry.cliSkills = await discoverCliSkills(this.agentConfig, undefined, this.gatewayConfig);
328
+ }
329
+ catch {
330
+ this.skillRegistry.cliDiscoveryError = 'CLI_SKILL_DISCOVERY_UNAVAILABLE';
331
+ }
332
+ const { discoverWorkerExtensions } = await Promise.resolve().then(() => __importStar(require('../session/worker-extensions')));
333
+ const extensions = await discoverWorkerExtensions(this.agentConfig, this.gatewayConfig);
334
+ const merged = new Map(this.skillRegistry.cliSkills.map(skill => [skill.name, skill]));
335
+ for (const skill of extensions.skills)
336
+ merged.set(skill.name, { ...merged.get(skill.name), ...skill });
337
+ this.skillRegistry.cliSkills = [...merged.values()];
338
+ this.skillRegistry.extensionServers = Object.keys(extensions.servers);
339
+ this.skillRegistry.extensionNotices = extensions.notices;
306
340
  }
307
341
  catch {
308
342
  this.skillRegistry.cliSkills = [];
343
+ this.skillRegistry.extensionServers = [];
344
+ this.skillRegistry.extensionNotices = [];
309
345
  this.skillRegistry.cliDiscoveryError = 'CLI_SKILL_DISCOVERY_UNAVAILABLE';
310
346
  }
311
347
  },
@@ -424,35 +460,73 @@ class AgentRunner extends events_1.EventEmitter {
424
460
  return task;
425
461
  }
426
462
  stopVoiceResponse(sessionId) { this.orchestration?.stopResponse(sessionId, 'barge-in'); }
463
+ async acceptApiMessage(sessionId, chatId, message, opts) {
464
+ if (!this.orchestrationForApi(sessionId))
465
+ throw Object.assign(new Error('Queued admission requires orchestration'), { code: 'NOT_SUPPORTED' });
466
+ if (!opts.principalId)
467
+ throw new Error('Authenticated principal required');
468
+ await this.authorizeVoiceSession(sessionId, opts.principalId);
469
+ const result = await this.sendOrchestratedApi(sessionId, chatId, message, { ...opts, acceptOnly: true });
470
+ return result.inputId;
471
+ }
427
472
  async sendOrchestratedApi(sessionId, chatId, message, opts, onText, onTool) {
428
473
  const semantic = this.agentConfig.orchestration?.conversation?.semanticIntake === true;
429
- if (!semantic && this.pendingApiSessions.has(sessionId))
474
+ if (!semantic && !opts.acceptOnly && this.pendingApiSessions.has(sessionId))
430
475
  throw Object.assign(new Error('Session already has a pending request'), { code: 'CONFLICT' });
431
476
  if (!opts.principalId)
432
477
  throw new Error('Authenticated principal required for conversation orchestration');
433
478
  const deadline = Date.now() + opts.timeoutMs;
434
- if (!semantic)
479
+ if (!semantic && !opts.acceptOnly)
435
480
  this.pendingApiSessions.add(sessionId); // reserve before the first await
481
+ const preparationDir = opts.acceptOnly ? `api-${sessionId}/admission-${(0, crypto_1.randomUUID)()}` : undefined;
482
+ let keepPreparedMedia = false;
436
483
  try {
437
484
  const orchestration = await this.getOrchestration();
485
+ orchestration.authorizeSession(sessionId, opts.principalId);
486
+ const scope = { agentId: this.agentConfig.id, agentSessionId: sessionId,
487
+ source: 'api', accountId: opts.principalId, chatId, threadKey: '', principalId: opts.principalId };
488
+ const ingressKey = opts.clientMessageId ? `web:${sessionId}:${opts.clientMessageId}` : undefined;
489
+ const requestFingerprint = opts.clientMessageId ? (0, store_1.payloadHash)({ scope, message,
490
+ mediaFiles: opts.mediaFiles ?? [], model: opts.model, imageParams: opts.imageParams,
491
+ videoParams: opts.videoParams, storeUserMessage: !opts.skipUserMessage, allowTools: opts.allowTools ?? false }) : undefined;
492
+ if (opts.acceptOnly && requestFingerprint) {
493
+ const prior = orchestration.store.apiReceipt(scope, ingressKey, requestFingerprint);
494
+ if (prior)
495
+ return { text: '', attachments: [], inputId: prior.inputId };
496
+ }
438
497
  await this.sessionStore.ensureApiSession(this.agentConfig.id, chatId, sessionId);
439
498
  this.apiChatIds.set(sessionId, chatId);
440
- const media = opts.mediaFiles?.length ? await promoteUiUploads(this.agentsBaseDir, this.agentConfig.id, sessionId, opts.mediaFiles, this.logger) : [];
499
+ const media = opts.mediaFiles?.length ? await promoteUiUploads(this.agentsBaseDir, this.agentConfig.id, sessionId, opts.mediaFiles, this.logger, preparationDir) : [];
441
500
  const index = await this.sessionStore.loadIndex(this.agentConfig.id, chatId, 'api');
442
501
  const saved = index?.sessions.find(session => session.id === sessionId)?.imageConfig;
443
502
  const selected = { ...(saved ? AgentRunner.durableImageConfig(saved) : {}), ...opts.imageParams };
444
503
  const imageParams = AgentRunner.remapImageParamsRefs(Object.keys(selected).length ? selected : undefined, opts.mediaFiles, media);
445
504
  const videoParams = AgentRunner.remapVideoParamsRefs(opts.videoParams, opts.mediaFiles, media);
446
- if (videoParams)
447
- await this.sessionStore.updateSessionMeta(this.agentConfig.id, chatId, sessionId, { videoConfig: videoParams }, 'api');
448
505
  const imageConfig = opts.imageParams && imageParams ? AgentRunner.durableImageConfig(imageParams) : undefined;
449
- if (imageConfig)
450
- await this.sessionStore.updateSessionMeta(this.agentConfig.id, chatId, sessionId, { imageConfig }, 'api');
506
+ const saveMediaConfig = async () => {
507
+ if (videoParams)
508
+ await this.sessionStore.updateSessionMeta(this.agentConfig.id, chatId, sessionId, { videoConfig: videoParams }, 'api');
509
+ if (imageConfig)
510
+ await this.sessionStore.updateSessionMeta(this.agentConfig.id, chatId, sessionId, { imageConfig }, 'api');
511
+ };
512
+ if (!opts.acceptOnly)
513
+ await saveMediaConfig();
451
514
  const requestId = opts.requestId ?? (0, crypto_1.randomUUID)();
452
- const scopedInput = { scope: { agentId: this.agentConfig.id, agentSessionId: sessionId, source: 'api', accountId: opts.principalId,
453
- chatId, threadKey: '', principalId: opts.principalId }, text: message || '[Attachment inspection requested]', attachmentIds: media,
454
- requestId, storeUserMessage: !opts.skipUserMessage,
455
- metadata: imageParams || videoParams ? { promptContext: (imageParams ? AgentRunner.buildImageParamsNote(imageParams) : '') + (videoParams ? AgentRunner.buildVideoParamsNote(videoParams) : ''), imageRefs: imageParams?.image_refs } : undefined };
515
+ const scopedInput = { scope, text: message || '[Attachment inspection requested]', attachmentIds: media,
516
+ requestId, ingressKey, requestFingerprint, storeUserMessage: !opts.skipUserMessage,
517
+ metadata: { clientMessageId: opts.clientMessageId, promptContext: (imageParams ? AgentRunner.buildImageParamsNote(imageParams) : '') + (videoParams ? AgentRunner.buildVideoParamsNote(videoParams) : ''), imageRefs: imageParams?.image_refs } };
518
+ if (opts.acceptOnly) {
519
+ const accepted = orchestration.submitInput({ ...scopedInput, model: opts.model }, { execute: opts.allowTools ?? false, writeMemory: false });
520
+ // Concurrent retries can prepare separate copies; only the winning
521
+ // durable input owns its directory. Delete copies belonging to losers.
522
+ const row = orchestration.store.get('SELECT attachment_refs_json,request_id FROM conversation_inputs WHERE id=?', accepted.inputId);
523
+ const admittedMedia = JSON.parse(String(row?.attachment_refs_json ?? '[]'));
524
+ keepPreparedMedia = admittedMedia.some(ref => ref.startsWith(`media/${preparationDir}/`));
525
+ if (row?.request_id === requestId)
526
+ await saveMediaConfig().catch(error => this.logger.warn('Accepted input media settings were not saved', { inputId: accepted.inputId, error: String(error) }));
527
+ await orchestration.flushHistory().catch(error => this.logger.warn("Accepted input history projection pending", { inputId: accepted.inputId, error: String(error) }));
528
+ return { text: '', attachments: [], inputId: accepted.inputId };
529
+ }
456
530
  let text;
457
531
  if (semantic) {
458
532
  const accepted = orchestration.submitInput({ ...scopedInput, model: opts.model }, { execute: opts.allowTools ?? false, writeMemory: false }, onTool);
@@ -480,7 +554,15 @@ class AgentRunner extends events_1.EventEmitter {
480
554
  return { text, attachments: this.popApiAttachments(sessionId) };
481
555
  }
482
556
  finally {
483
- if (!semantic)
557
+ if (preparationDir && !keepPreparedMedia) {
558
+ try {
559
+ fs.rmSync(media_store_1.MediaStore.mediaDir(this.agentsBaseDir, this.agentConfig.id, preparationDir), { recursive: true, force: true });
560
+ }
561
+ catch (error) {
562
+ this.logger.warn('Unused admission media cleanup failed', { error: String(error) });
563
+ }
564
+ }
565
+ if (!semantic && !opts.acceptOnly)
484
566
  this.pendingApiSessions.delete(sessionId);
485
567
  }
486
568
  }
@@ -619,6 +701,7 @@ class AgentRunner extends events_1.EventEmitter {
619
701
  this.skillNotificationOrigins = new Map();
620
702
  // Cancel function for the daily history cleanup timer
621
703
  this.cancelCleanup = null;
704
+ this.sessionConfirmations = new session_confirmations_1.SessionConfirmations();
622
705
  /**
623
706
  * One-shot local `claude -p` triage runner (Phase 3b). Feeds the closed
624
707
  * classification prompt on stdin and returns raw stdout. Hard timeout →
@@ -661,6 +744,10 @@ class AgentRunner extends events_1.EventEmitter {
661
744
  };
662
745
  this.compactingSessions = new Set();
663
746
  this.telegramCommandConfig = '';
747
+ this.configReloadHandlers = [];
748
+ this.shutdownHandlers = [];
749
+ this.receiverReload = Promise.resolve();
750
+ this.channelReloadSnapshot = new Map();
664
751
  this.agentConfig = (0, gateway_config_1.applyGatewayOrchestration)(agentConfig, gatewayConfig);
665
752
  this.gatewayConfig = gatewayConfig;
666
753
  this.logger = logger ?? (0, logger_1.createLogger)(agentConfig.id, gatewayConfig.gateway.logDir);
@@ -674,9 +761,6 @@ class AgentRunner extends events_1.EventEmitter {
674
761
  // config.json lives 3 levels above workspace: <base>/<agentId>/workspace -> <base>/config.json
675
762
  this.configPath = path.resolve(agentConfig.workspace, '..', '..', '..', 'config.json');
676
763
  this.historyDb = db_1.HistoryDB.forDir(this.agentDir, agentConfig.id);
677
- this.idleTimeoutMs =
678
- (agentConfig.session?.idleTimeoutMinutes ?? DEFAULT_IDLE_TIMEOUT_MINUTES) * 60 * 1000;
679
- this.maxConcurrent = agentConfig.session?.maxConcurrent ?? DEFAULT_MAX_CONCURRENT;
680
764
  this.coalesceWindowMs =
681
765
  Number(process.env.CHANNEL_COALESCE_WINDOW_MS) || exports.CHANNEL_COALESCE_WINDOW_MS;
682
766
  }
@@ -827,12 +911,62 @@ class AgentRunner extends events_1.EventEmitter {
827
911
  return;
828
912
  }
829
913
  }
914
+ if (channelSource !== 'telegram' && content.trim() === '/help') {
915
+ await this.sendOrchestrationControl(channelSource, chatId, { text: (0, command_help_1.commandHelp)(channelSource, !!channelOrchestration, this.gatewayConfig.gateway.headless === false), buttons: [] }, meta);
916
+ res.writeHead(200);
917
+ res.end('ok');
918
+ return;
919
+ }
920
+ if (channelSource !== 'telegram' && (/^\/(compact|restart)(?:\s|$)/.test(content.trim()) || this.sessionConfirmations.owns(content.trim()))) {
921
+ const sessionId = await this.sessionStore.getActiveSessionId(this.agentConfig.id, chatId, channelSource);
922
+ const scope = { channel: channelSource, chatId, thread: channelSource === 'whatsapp' && meta.account_id ? `whatsapp-account:${meta.account_id}` : meta.thread_ts ?? meta.message_thread_id ?? '', sessionId, principalId: `${channelSource}:${meta.user_id ?? meta.user ?? chatId}` };
923
+ if (!content.trim().startsWith('/orch ')) {
924
+ const operation = content.trim().startsWith('/compact') ? 'compact' : 'restart';
925
+ await this.sendOrchestrationControl(channelSource, chatId, this.sessionConfirmations.open(scope, operation), meta);
926
+ res.writeHead(200);
927
+ res.end('ok');
928
+ return;
929
+ }
930
+ let operation;
931
+ try {
932
+ operation = this.sessionConfirmations.choose(scope, content.trim());
933
+ }
934
+ catch (error) {
935
+ await this.sendOrchestrationControl(channelSource, chatId, { text: error.message, buttons: [] }, meta);
936
+ res.writeHead(200);
937
+ res.end('ok');
938
+ return;
939
+ }
940
+ // Acknowledge before a potentially long native compaction. Only this consumed action can start it.
941
+ await this.sendOrchestrationControl(channelSource, chatId, { text: operation === 'cancel' ? 'Cancelled.' : operation === 'compact' ? 'Compacting Claude Code context…' : 'Restarting session process…', buttons: [] }, meta);
942
+ res.writeHead(200);
943
+ res.end('ok');
944
+ if (operation !== 'cancel')
945
+ void (async () => {
946
+ let text;
947
+ try {
948
+ if (operation === 'compact')
949
+ await this.compactContext(sessionId);
950
+ else
951
+ await this.restartProcess(chatId, sessionId);
952
+ text = operation === 'compact' ? 'Claude Code context compacted. Chat history is unchanged.' : 'Session process restarted. It starts again with your next message. Chat history is unchanged.';
953
+ }
954
+ catch (error) {
955
+ text = `Command failed: ${error.message}`;
956
+ }
957
+ const deliveryMeta = { ...meta };
958
+ delete deliveryMeta.reply_token;
959
+ delete deliveryMeta.control_message_id;
960
+ await this.sendOrchestrationControl(channelSource, chatId, { text, buttons: [] }, deliveryMeta);
961
+ })().catch(error => this.logger.error('Session control delivery failed', { error: String(error) }));
962
+ return;
963
+ }
830
964
  if (channelSource !== 'telegram' && this.agentConfig.orchestration?.enabled && (this.agentConfig.orchestration.channels ?? ['api']).includes(channelSource) && /^\/sessions?(?:\s|$)/.test(content.trim())) {
831
965
  const index = await this.sessionStore.listSessions(this.agentConfig.id, chatId, channelSource);
832
966
  const current = index.sessions.find(session => session.id === index.activeSessionId);
833
967
  const text = content.trim() === '/sessions'
834
968
  ? `Sessions\n${index.sessions.slice(0, 15).map(session => `${session.id === index.activeSessionId ? '✅ ' : ''}${session.name}\n${session.id}`).join('\n\n')}`
835
- : `Current session: ${current?.name ?? '(unnamed)'}\n${index.activeSessionId}\nMode: Orchestration\nModel: ${this.agentConfig.claude.model}\nMessages: ${current?.messageCount ?? 0}\n\nCommands: /session /sessions /voice /voices /tasks /stop`;
969
+ : (0, session_status_1.formatSessionStatus)(index.activeSessionId, current?.name ?? '(unnamed)', this.agentConfig.claude.model, await this.sessionContextInfo(index.activeSessionId, current), false, channelSource);
836
970
  await this.sendOrchestrationControl(channelSource, chatId, { text, buttons: [] }, meta);
837
971
  res.writeHead(200);
838
972
  res.end('ok');
@@ -1458,18 +1592,7 @@ class AgentRunner extends events_1.EventEmitter {
1458
1592
  return respond({ success: true, sessionId: null, text: 'No active session found.' });
1459
1593
  }
1460
1594
  const context = await this.sessionContextInfo(meta.id, meta);
1461
- const lines = [
1462
- `📌 Current Session: ${meta.name}`,
1463
- `<code>${meta.id}</code>`,
1464
- '',
1465
- `👉 Context: ${context.text}`,
1466
- `🤖 Model: ${String(this.agentConfig.claude.model).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")}`,
1467
- ];
1468
- if (context.contextUsedPct != null && context.contextUsedPct >= 80) {
1469
- lines.push('', '💡 Near limit — consider /compact');
1470
- }
1471
- lines.push('', 'Commands: /sessions /new /rename /clear /compact');
1472
- return respond({ success: true, sessionId: meta.id, text: lines.join('\n'), format: 'html' });
1595
+ return respond({ success: true, sessionId: meta.id, text: (0, session_status_1.formatSessionStatus)(meta.id, meta.name, this.agentConfig.claude.model, context, true), format: 'html' });
1473
1596
  }
1474
1597
  catch {
1475
1598
  return respond({ success: false, text: 'Failed to get session info.' });
@@ -2813,7 +2936,14 @@ class AgentRunner extends events_1.EventEmitter {
2813
2936
  */
2814
2937
  async handleSessionCommand(chatId, content, meta = {}) {
2815
2938
  const agentId = this.agentConfig.id;
2816
- if (content.startsWith('/sessions')) {
2939
+ if (content.trim() === '/help') {
2940
+ this.writeAutoForward(chatId, (0, command_help_1.commandHelp)(this.channelFor(chatId), !!this.agentConfig.orchestration?.enabled, this.gatewayConfig.gateway.headless === false));
2941
+ }
2942
+ else if (/^\/restart(?:\s|$)/.test(content)) {
2943
+ await this.restartProcess(chatId);
2944
+ this.writeAutoForward(chatId, 'Session process restarted. It starts again with your next message.');
2945
+ }
2946
+ else if (content.startsWith('/sessions')) {
2817
2947
  await this.handleCommandSessions(agentId, chatId);
2818
2948
  }
2819
2949
  else if (content.startsWith('/session') && !content.startsWith('/sessions')) {
@@ -2961,19 +3091,7 @@ class AgentRunner extends events_1.EventEmitter {
2961
3091
  return;
2962
3092
  }
2963
3093
  const context = await this.sessionContextInfo(meta.id, meta);
2964
- const lines = [
2965
- `📌 Current Session: ${meta.name}`,
2966
- `<code>${index.activeSessionId}</code>`,
2967
- '',
2968
- `👉 Context: ${context.text}`,
2969
- `🤖 Model: ${String(this.agentConfig.claude.model).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")}`,
2970
- ];
2971
- if (context.contextUsedPct != null && context.contextUsedPct >= 80) {
2972
- lines.push('', '💡 Near limit — consider /compact');
2973
- }
2974
- lines.push('', 'Commands: /sessions /new /rename /clear /compact');
2975
- const info = lines.join('\n');
2976
- this.writeAutoForward(chatId, info, 'html');
3094
+ this.writeAutoForward(chatId, (0, session_status_1.formatSessionStatus)(meta.id, meta.name, this.agentConfig.claude.model, context, true, this.channelFor(chatId)), 'html');
2977
3095
  }
2978
3096
  /**
2979
3097
  * /new [name] — create a new session and switch to it.
@@ -3122,11 +3240,18 @@ class AgentRunner extends events_1.EventEmitter {
3122
3240
  * Restart the process for a given chatId (stop + remove from map).
3123
3241
  * The process will be lazily re-spawned on the next incoming message.
3124
3242
  */
3125
- async restartProcess(chatId) {
3243
+ async restartProcess(chatId, expectedSessionId) {
3126
3244
  const existing = this.sessions.get(chatId);
3245
+ if (existing && expectedSessionId && existing.sessionId !== expectedSessionId)
3246
+ throw new Error('The active session changed. Run /restart again.');
3247
+ // Mark the managed turn as intentionally interrupted before stopping its process.
3248
+ // This also cancels a turn still preparing, before a process has been registered.
3249
+ const sessionId = expectedSessionId ?? existing?.sessionId ?? chatId;
3250
+ this.orchestration?.stopResponse(sessionId);
3127
3251
  if (existing) {
3128
3252
  await existing.stop();
3129
- this.sessions.delete(chatId);
3253
+ if (this.sessions.get(chatId) === existing)
3254
+ this.sessions.delete(chatId);
3130
3255
  }
3131
3256
  // Process will be re-spawned on next incoming message
3132
3257
  }
@@ -3663,6 +3788,8 @@ class AgentRunner extends events_1.EventEmitter {
3663
3788
  this.startIdleCleaner();
3664
3789
  this._startCleanupScheduler();
3665
3790
  this.startSessionCompaction();
3791
+ for (const channel of ['line', 'slack', 'whatsapp_cloud', 'telegram', 'discord'])
3792
+ this.channelReloadSnapshot.set(channel, JSON.stringify(this.agentConfig[channel] ?? null));
3666
3793
  this.logger.info('AgentRunner started', { agentId: this.agentConfig.id });
3667
3794
  }
3668
3795
  /**
@@ -3727,24 +3854,58 @@ class AgentRunner extends events_1.EventEmitter {
3727
3854
  this.startTelegramReceiver();
3728
3855
  });
3729
3856
  }
3857
+ onConfigReload(handler) { this.configReloadHandlers.push(handler); }
3858
+ onShutdown(handler) { this.shutdownHandlers.push(handler); }
3730
3859
  updateAgentConfig(newConfig) {
3731
3860
  newConfig = (0, gateway_config_1.applyGatewayOrchestration)(newConfig, this.gatewayConfig);
3732
3861
  this.orchestration?.updateAgentConfig(newConfig);
3733
3862
  this.agentConfig = newConfig;
3734
3863
  this.sessionCompactionScheduler?.start();
3864
+ if (this.cancelCleanup) {
3865
+ this.cancelCleanup();
3866
+ this._startCleanupScheduler();
3867
+ }
3735
3868
  this.refreshTelegramCommands();
3736
3869
  // Restart LineReplyManager if the LINE config changed so the live instance
3737
3870
  // picks up a new access token, threshold, or labels without a full restart.
3738
- this.stopLineReply();
3739
- this.startLineReply();
3871
+ const changed = (channel) => { const value = JSON.stringify(newConfig[channel] ?? null); const previous = this.channelReloadSnapshot.get(channel); this.channelReloadSnapshot.set(channel, value); return previous !== value; };
3872
+ const telegramChanged = changed('telegram'), discordChanged = changed('discord');
3873
+ if (telegramChanged || discordChanged) {
3874
+ this.receiverReload = this.receiverReload.then(async () => {
3875
+ if (this.stopping)
3876
+ return;
3877
+ if (telegramChanged) {
3878
+ const old = this.receiver;
3879
+ this.receiver = null;
3880
+ await old?.stop();
3881
+ if (!this.stopping)
3882
+ this.startTelegramReceiver();
3883
+ }
3884
+ if (discordChanged) {
3885
+ const old = this.discordReceiver;
3886
+ this.discordReceiver = null;
3887
+ await old?.stop();
3888
+ if (!this.stopping)
3889
+ this.startDiscordReceiver();
3890
+ }
3891
+ }).catch(error => this.logger.error('Channel configuration refresh failed', { error: String(error) }));
3892
+ }
3893
+ if (changed('line')) {
3894
+ this.stopLineReply();
3895
+ this.startLineReply();
3896
+ }
3740
3897
  // Slack token/secret may have changed (or been cleared) — rebuild to pick
3741
3898
  // it up, same reasoning as LineReplyManager above.
3742
- this.stopSlackOutbound();
3743
- this.startSlackOutbound();
3899
+ if (changed('slack')) {
3900
+ this.stopSlackOutbound();
3901
+ this.startSlackOutbound();
3902
+ }
3744
3903
  // WhatsApp Cloud credentials may have changed (or been cleared) — rebuild
3745
3904
  // to pick it up, same reasoning as Slack above.
3746
- this.stopWhatsAppCloudOutbound();
3747
- this.startWhatsAppCloudOutbound();
3905
+ if (changed('whatsapp_cloud')) {
3906
+ this.stopWhatsAppCloudOutbound();
3907
+ this.startWhatsAppCloudOutbound();
3908
+ }
3748
3909
  // WhatsApp has no credential to rebuild on — push the new config
3749
3910
  // (access-control fields) into every already-running manager, and
3750
3911
  // add/remove managers only if the set of configured accounts changed.
@@ -3753,6 +3914,8 @@ class AgentRunner extends events_1.EventEmitter {
3753
3914
  // just hand the manager the fresh config so its access-control reads
3754
3915
  // (dmPolicy/dmAllowlist/pairing) see the latest values.
3755
3916
  this.wechat?.updateAgentConfig(newConfig);
3917
+ for (const handler of this.configReloadHandlers)
3918
+ handler();
3756
3919
  }
3757
3920
  /**
3758
3921
  * Reconcile `this.whatsappAccounts` with `agentConfig.whatsapp.accounts`.
@@ -4115,8 +4278,14 @@ class AgentRunner extends events_1.EventEmitter {
4115
4278
  this.discordReceiver = null;
4116
4279
  this.logger.info('DiscordReceiver stopped', { agentId: this.agentConfig.id });
4117
4280
  }
4118
- async stop() {
4281
+ canRemoveFromConfig() {
4282
+ return !(this.orchestrationStarting && !this.orchestration) && !this.orchestration?.hasPendingWork() && ![...this.sessions.values()].some(s => s.isProcessing);
4283
+ }
4284
+ async stop(preserveConfigurationWatchers = false) {
4119
4285
  this.stopping = true;
4286
+ if (!preserveConfigurationWatchers)
4287
+ for (const handler of this.shutdownHandlers.splice(0))
4288
+ handler();
4120
4289
  this.sessionCompactionScheduler?.stop();
4121
4290
  if (this.orchestrationStarting) {
4122
4291
  const orchestration = await this.orchestrationStarting.catch(() => undefined);
@@ -4199,7 +4368,7 @@ class AgentRunner extends events_1.EventEmitter {
4199
4368
  });
4200
4369
  }
4201
4370
  async restart() {
4202
- await this.stop();
4371
+ await this.stop(true);
4203
4372
  this.stopping = false;
4204
4373
  await this.start();
4205
4374
  }
@@ -4223,6 +4392,13 @@ class AgentRunner extends events_1.EventEmitter {
4223
4392
  const report = this.orchestration?.tokenReport(sessionId);
4224
4393
  return report ? { ...report, backgroundReviews: this.historyDb.listReviewRuns().filter(run => run.sessionId === sessionId) } : undefined;
4225
4394
  }
4395
+ getProcessOwners() {
4396
+ const agents = [...this.sessions.values()].flatMap(p => p.processId ? [{
4397
+ pid: p.processId, group: 'agent', agentId: this.agentConfig.id, sessionId: p.sessionId,
4398
+ model: p.model, harness: 'claude', container: this.agentConfig.container,
4399
+ }] : []);
4400
+ return [...agents, ...(this.orchestration?.processOwners() ?? [])];
4401
+ }
4226
4402
  getOrchestrationSummary() {
4227
4403
  if (!this.agentConfig.orchestration?.enabled && !this.orchestration)
4228
4404
  return undefined;
@@ -5083,7 +5259,7 @@ class AgentRunner extends events_1.EventEmitter {
5083
5259
  const persist = (role, content, force = false) => {
5084
5260
  if ((skipPersist && !force) || !content)
5085
5261
  return;
5086
- this.historyDb.insertMessage({ chatId: dbChatId, sessionId, source: 'api', role, content, ts: Date.now() });
5262
+ this.historyDb.insertMessage({ chatId: dbChatId, sessionId, source: 'api', role, content, ts: Date.now(), ...(role === 'user' && opts?.clientMessageId ? { clientMessageId: opts.clientMessageId } : {}) });
5087
5263
  };
5088
5264
  // Persist the full user command before executing so it appears in history.
5089
5265
  persist('user', opts?.displayCommand ?? command);
@@ -5091,7 +5267,11 @@ class AgentRunner extends events_1.EventEmitter {
5091
5267
  let responseText;
5092
5268
  let forcePersist = false;
5093
5269
  try {
5094
- if (cmd === '/model') {
5270
+ if (cmd === '/help') {
5271
+ responseText = (0, command_help_1.commandHelp)('api', !!this.agentConfig.orchestration?.enabled);
5272
+ result = { text: responseText };
5273
+ }
5274
+ else if (cmd === '/model') {
5095
5275
  const model = this.agentConfig.claude.model;
5096
5276
  const hasArg = command.trim().includes(' ');
5097
5277
  result = { model };
@@ -5137,7 +5317,7 @@ class AgentRunner extends events_1.EventEmitter {
5137
5317
  }
5138
5318
  }
5139
5319
  else if (cmd === '/restart') {
5140
- this.restartProcess(sessionId).catch(() => { });
5320
+ await this.restartProcess(sessionId, sessionId);
5141
5321
  result = { restarting: true };
5142
5322
  responseText = 'Session is restarting.';
5143
5323
  }
@@ -5149,12 +5329,10 @@ class AgentRunner extends events_1.EventEmitter {
5149
5329
  // (the real conversation) directly rather than trusting meta.messageCount.
5150
5330
  const messageCount = (await this.sessionStore.loadSession(agentId, sessionId).catch(() => [])).length;
5151
5331
  const context = await this.sessionContextInfo(sessionId, meta);
5152
- const { text: contextText, ...contextFields } = context;
5332
+ const { text: _contextText, ...contextFields } = context;
5153
5333
  result = { sessionId, sessionName: meta?.name ?? null, messageCount, archivedCount: meta?.archivedCount ?? 0,
5154
5334
  ...contextFields, model: effectiveModel };
5155
- responseText = [`📌 Current Session: ${meta?.name ?? '(unnamed)'}`, sessionId, '', `👉 Context: ${contextText}`, `🤖 Model: ${effectiveModel}`,
5156
- ...(context.contextUsedPct != null && context.contextUsedPct >= 80 ? ['', '💡 Near limit — consider /compact'] : []),
5157
- '', 'Commands: /sessions /new /rename /clear /compact'].join('\n');
5335
+ responseText = (0, session_status_1.formatSessionStatus)(sessionId, meta?.name ?? '(unnamed)', effectiveModel, context, false, 'api');
5158
5336
  }
5159
5337
  else if (cmd === '/sessions') {
5160
5338
  // Advertised for the api channel (BUILTIN_COMMANDS), so handle it here — mirrors the