openryoko 2026.10.8 → 2026.10.13

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 (691) hide show
  1. package/dist/bin/jimmy.js +51 -1
  2. package/dist/bin/jimmy.js.map +1 -1
  3. package/dist/package.json +2 -1
  4. package/dist/src/backup/archive.d.ts +65 -0
  5. package/dist/src/backup/archive.d.ts.map +1 -0
  6. package/dist/src/backup/archive.js +214 -0
  7. package/dist/src/backup/archive.js.map +1 -0
  8. package/dist/src/backup/catalog.d.ts +64 -0
  9. package/dist/src/backup/catalog.d.ts.map +1 -0
  10. package/dist/src/backup/catalog.js +252 -0
  11. package/dist/src/backup/catalog.js.map +1 -0
  12. package/dist/src/backup/database-restore.d.ts +63 -0
  13. package/dist/src/backup/database-restore.d.ts.map +1 -0
  14. package/dist/src/backup/database-restore.js +236 -0
  15. package/dist/src/backup/database-restore.js.map +1 -0
  16. package/dist/src/backup/database-source.d.ts +70 -0
  17. package/dist/src/backup/database-source.d.ts.map +1 -0
  18. package/dist/src/backup/database-source.js +70 -0
  19. package/dist/src/backup/database-source.js.map +1 -0
  20. package/dist/src/backup/format.d.ts +4 -0
  21. package/dist/src/backup/format.d.ts.map +1 -0
  22. package/dist/src/backup/format.js +15 -0
  23. package/dist/src/backup/format.js.map +1 -0
  24. package/dist/src/backup/gateway-liveness.d.ts +44 -0
  25. package/dist/src/backup/gateway-liveness.d.ts.map +1 -0
  26. package/dist/src/backup/gateway-liveness.js +120 -0
  27. package/dist/src/backup/gateway-liveness.js.map +1 -0
  28. package/dist/src/backup/inspect.d.ts +45 -0
  29. package/dist/src/backup/inspect.d.ts.map +1 -0
  30. package/dist/src/backup/inspect.js +291 -0
  31. package/dist/src/backup/inspect.js.map +1 -0
  32. package/dist/src/backup/layout.d.ts +11 -0
  33. package/dist/src/backup/layout.d.ts.map +1 -0
  34. package/dist/src/backup/layout.js +16 -0
  35. package/dist/src/backup/layout.js.map +1 -0
  36. package/dist/src/backup/limits.d.ts +54 -0
  37. package/dist/src/backup/limits.d.ts.map +1 -0
  38. package/dist/src/backup/limits.js +59 -0
  39. package/dist/src/backup/limits.js.map +1 -0
  40. package/dist/src/backup/manifest.d.ts +45 -0
  41. package/dist/src/backup/manifest.d.ts.map +1 -0
  42. package/dist/src/backup/manifest.js +77 -0
  43. package/dist/src/backup/manifest.js.map +1 -0
  44. package/dist/src/backup/restore.d.ts +73 -0
  45. package/dist/src/backup/restore.d.ts.map +1 -0
  46. package/dist/src/backup/restore.js +685 -0
  47. package/dist/src/backup/restore.js.map +1 -0
  48. package/dist/src/backup/run.d.ts +76 -0
  49. package/dist/src/backup/run.d.ts.map +1 -0
  50. package/dist/src/backup/run.js +181 -0
  51. package/dist/src/backup/run.js.map +1 -0
  52. package/dist/src/backup/scheduler.d.ts +51 -0
  53. package/dist/src/backup/scheduler.d.ts.map +1 -0
  54. package/dist/src/backup/scheduler.js +198 -0
  55. package/dist/src/backup/scheduler.js.map +1 -0
  56. package/dist/src/backup/settings.d.ts +44 -0
  57. package/dist/src/backup/settings.d.ts.map +1 -0
  58. package/dist/src/backup/settings.js +91 -0
  59. package/dist/src/backup/settings.js.map +1 -0
  60. package/dist/src/backup/space.d.ts +22 -0
  61. package/dist/src/backup/space.d.ts.map +1 -0
  62. package/dist/src/backup/space.js +47 -0
  63. package/dist/src/backup/space.js.map +1 -0
  64. package/dist/src/backup/state.d.ts +46 -0
  65. package/dist/src/backup/state.d.ts.map +1 -0
  66. package/dist/src/backup/state.js +137 -0
  67. package/dist/src/backup/state.js.map +1 -0
  68. package/dist/src/backup/tar.d.ts +64 -0
  69. package/dist/src/backup/tar.d.ts.map +1 -0
  70. package/dist/src/backup/tar.js +274 -0
  71. package/dist/src/backup/tar.js.map +1 -0
  72. package/dist/src/backup/targets.d.ts +85 -0
  73. package/dist/src/backup/targets.d.ts.map +1 -0
  74. package/dist/src/backup/targets.js +104 -0
  75. package/dist/src/backup/targets.js.map +1 -0
  76. package/dist/src/backup/walk.d.ts +42 -0
  77. package/dist/src/backup/walk.d.ts.map +1 -0
  78. package/dist/src/backup/walk.js +324 -0
  79. package/dist/src/backup/walk.js.map +1 -0
  80. package/dist/src/cli/backup.d.ts +45 -0
  81. package/dist/src/cli/backup.d.ts.map +1 -0
  82. package/dist/src/cli/backup.js +344 -0
  83. package/dist/src/cli/backup.js.map +1 -0
  84. package/dist/src/cli/bundled-skills.d.ts +7 -1
  85. package/dist/src/cli/bundled-skills.d.ts.map +1 -1
  86. package/dist/src/cli/bundled-skills.js +12 -2
  87. package/dist/src/cli/bundled-skills.js.map +1 -1
  88. package/dist/src/cli/config-failure.d.ts +18 -0
  89. package/dist/src/cli/config-failure.d.ts.map +1 -0
  90. package/dist/src/cli/config-failure.js +39 -0
  91. package/dist/src/cli/config-failure.js.map +1 -0
  92. package/dist/src/cli/gateway-audit.d.ts +3 -0
  93. package/dist/src/cli/gateway-audit.d.ts.map +1 -1
  94. package/dist/src/cli/gateway-audit.js +61 -14
  95. package/dist/src/cli/gateway-audit.js.map +1 -1
  96. package/dist/src/cli/gateway-url-backup.d.ts +21 -0
  97. package/dist/src/cli/gateway-url-backup.d.ts.map +1 -0
  98. package/dist/src/cli/gateway-url-backup.js +87 -0
  99. package/dist/src/cli/gateway-url-backup.js.map +1 -0
  100. package/dist/src/cli/home-copy.d.ts +37 -0
  101. package/dist/src/cli/home-copy.d.ts.map +1 -0
  102. package/dist/src/cli/home-copy.js +155 -0
  103. package/dist/src/cli/home-copy.js.map +1 -0
  104. package/dist/src/cli/interactive-config.d.ts +5 -0
  105. package/dist/src/cli/interactive-config.d.ts.map +1 -1
  106. package/dist/src/cli/interactive-config.js +16 -7
  107. package/dist/src/cli/interactive-config.js.map +1 -1
  108. package/dist/src/cli/migrate.d.ts +20 -0
  109. package/dist/src/cli/migrate.d.ts.map +1 -1
  110. package/dist/src/cli/migrate.js +365 -68
  111. package/dist/src/cli/migrate.js.map +1 -1
  112. package/dist/src/cli/migration-declarations.d.ts +24 -0
  113. package/dist/src/cli/migration-declarations.d.ts.map +1 -0
  114. package/dist/src/cli/migration-declarations.js +54 -0
  115. package/dist/src/cli/migration-declarations.js.map +1 -0
  116. package/dist/src/cli/start.d.ts.map +1 -1
  117. package/dist/src/cli/start.js +40 -1
  118. package/dist/src/cli/start.js.map +1 -1
  119. package/dist/src/connectors/chunked-send.d.ts +27 -0
  120. package/dist/src/connectors/chunked-send.d.ts.map +1 -0
  121. package/dist/src/connectors/chunked-send.js +40 -0
  122. package/dist/src/connectors/chunked-send.js.map +1 -0
  123. package/dist/src/connectors/cron/index.d.ts +10 -0
  124. package/dist/src/connectors/cron/index.d.ts.map +1 -1
  125. package/dist/src/connectors/cron/index.js +26 -3
  126. package/dist/src/connectors/cron/index.js.map +1 -1
  127. package/dist/src/connectors/discord/attachments.d.ts +25 -0
  128. package/dist/src/connectors/discord/attachments.d.ts.map +1 -0
  129. package/dist/src/connectors/discord/attachments.js +33 -0
  130. package/dist/src/connectors/discord/attachments.js.map +1 -0
  131. package/dist/src/connectors/discord/format.d.ts +17 -1
  132. package/dist/src/connectors/discord/format.d.ts.map +1 -1
  133. package/dist/src/connectors/discord/format.js +36 -6
  134. package/dist/src/connectors/discord/format.js.map +1 -1
  135. package/dist/src/connectors/discord/index.d.ts +12 -0
  136. package/dist/src/connectors/discord/index.d.ts.map +1 -1
  137. package/dist/src/connectors/discord/index.js +47 -40
  138. package/dist/src/connectors/discord/index.js.map +1 -1
  139. package/dist/src/connectors/discord/remote.d.ts +45 -1
  140. package/dist/src/connectors/discord/remote.d.ts.map +1 -1
  141. package/dist/src/connectors/discord/remote.js +147 -22
  142. package/dist/src/connectors/discord/remote.js.map +1 -1
  143. package/dist/src/connectors/slack/attachments.d.ts +25 -0
  144. package/dist/src/connectors/slack/attachments.d.ts.map +1 -0
  145. package/dist/src/connectors/slack/attachments.js +32 -0
  146. package/dist/src/connectors/slack/attachments.js.map +1 -0
  147. package/dist/src/connectors/slack/auth-test-cache.d.ts +22 -0
  148. package/dist/src/connectors/slack/auth-test-cache.d.ts.map +1 -0
  149. package/dist/src/connectors/slack/auth-test-cache.js +34 -0
  150. package/dist/src/connectors/slack/auth-test-cache.js.map +1 -0
  151. package/dist/src/connectors/slack/format.d.ts +6 -1
  152. package/dist/src/connectors/slack/format.d.ts.map +1 -1
  153. package/dist/src/connectors/slack/format.js +65 -13
  154. package/dist/src/connectors/slack/format.js.map +1 -1
  155. package/dist/src/connectors/slack/index.d.ts +4 -0
  156. package/dist/src/connectors/slack/index.d.ts.map +1 -1
  157. package/dist/src/connectors/slack/index.js +64 -52
  158. package/dist/src/connectors/slack/index.js.map +1 -1
  159. package/dist/src/connectors/slack/provider-auth-blocks.d.ts +62 -0
  160. package/dist/src/connectors/slack/provider-auth-blocks.d.ts.map +1 -0
  161. package/dist/src/connectors/slack/provider-auth-blocks.js +204 -0
  162. package/dist/src/connectors/slack/provider-auth-blocks.js.map +1 -0
  163. package/dist/src/connectors/slack/provider-auth.d.ts +126 -0
  164. package/dist/src/connectors/slack/provider-auth.d.ts.map +1 -0
  165. package/dist/src/connectors/slack/provider-auth.js +357 -0
  166. package/dist/src/connectors/slack/provider-auth.js.map +1 -0
  167. package/dist/src/connectors/telegram/index.d.ts +5 -0
  168. package/dist/src/connectors/telegram/index.d.ts.map +1 -1
  169. package/dist/src/connectors/telegram/index.js +14 -22
  170. package/dist/src/connectors/telegram/index.js.map +1 -1
  171. package/dist/src/connectors/whatsapp/index.d.ts +3 -0
  172. package/dist/src/connectors/whatsapp/index.d.ts.map +1 -1
  173. package/dist/src/connectors/whatsapp/index.js +33 -14
  174. package/dist/src/connectors/whatsapp/index.js.map +1 -1
  175. package/dist/src/cron/alert-throttle.d.ts +28 -0
  176. package/dist/src/cron/alert-throttle.d.ts.map +1 -0
  177. package/dist/src/cron/alert-throttle.js +106 -0
  178. package/dist/src/cron/alert-throttle.js.map +1 -0
  179. package/dist/src/cron/jobs.d.ts +8 -0
  180. package/dist/src/cron/jobs.d.ts.map +1 -1
  181. package/dist/src/cron/jobs.js +27 -1
  182. package/dist/src/cron/jobs.js.map +1 -1
  183. package/dist/src/cron/run-outcome.d.ts +28 -0
  184. package/dist/src/cron/run-outcome.d.ts.map +1 -0
  185. package/dist/src/cron/run-outcome.js +66 -0
  186. package/dist/src/cron/run-outcome.js.map +1 -0
  187. package/dist/src/cron/runner.d.ts.map +1 -1
  188. package/dist/src/cron/runner.js +68 -5
  189. package/dist/src/cron/runner.js.map +1 -1
  190. package/dist/src/cron/scheduler.d.ts +8 -1
  191. package/dist/src/cron/scheduler.d.ts.map +1 -1
  192. package/dist/src/cron/scheduler.js +11 -4
  193. package/dist/src/cron/scheduler.js.map +1 -1
  194. package/dist/src/cron/waiting-fires.d.ts +18 -0
  195. package/dist/src/cron/waiting-fires.d.ts.map +1 -0
  196. package/dist/src/cron/waiting-fires.js +49 -0
  197. package/dist/src/cron/waiting-fires.js.map +1 -0
  198. package/dist/src/engines/claude-interactive.d.ts +19 -3
  199. package/dist/src/engines/claude-interactive.d.ts.map +1 -1
  200. package/dist/src/engines/claude-interactive.js +42 -17
  201. package/dist/src/engines/claude-interactive.js.map +1 -1
  202. package/dist/src/engines/claude.d.ts.map +1 -1
  203. package/dist/src/engines/claude.js +38 -5
  204. package/dist/src/engines/claude.js.map +1 -1
  205. package/dist/src/engines/codex.d.ts.map +1 -1
  206. package/dist/src/engines/codex.js +1 -0
  207. package/dist/src/engines/codex.js.map +1 -1
  208. package/dist/src/engines/gemini.d.ts.map +1 -1
  209. package/dist/src/engines/gemini.js +1 -0
  210. package/dist/src/engines/gemini.js.map +1 -1
  211. package/dist/src/gateway/api.d.ts.map +1 -1
  212. package/dist/src/gateway/api.js +184 -160
  213. package/dist/src/gateway/api.js.map +1 -1
  214. package/dist/src/gateway/config-redaction.d.ts +32 -0
  215. package/dist/src/gateway/config-redaction.d.ts.map +1 -0
  216. package/dist/src/gateway/config-redaction.js +139 -0
  217. package/dist/src/gateway/config-redaction.js.map +1 -0
  218. package/dist/src/gateway/config-revision.d.ts +46 -0
  219. package/dist/src/gateway/config-revision.d.ts.map +1 -0
  220. package/dist/src/gateway/config-revision.js +63 -0
  221. package/dist/src/gateway/config-revision.js.map +1 -0
  222. package/dist/src/gateway/connector-config.d.ts +21 -0
  223. package/dist/src/gateway/connector-config.d.ts.map +1 -0
  224. package/dist/src/gateway/connector-config.js +24 -0
  225. package/dist/src/gateway/connector-config.js.map +1 -0
  226. package/dist/src/gateway/daemon-entry.js +5 -0
  227. package/dist/src/gateway/daemon-entry.js.map +1 -1
  228. package/dist/src/gateway/engine-health-monitor.d.ts +67 -0
  229. package/dist/src/gateway/engine-health-monitor.d.ts.map +1 -0
  230. package/dist/src/gateway/engine-health-monitor.js +221 -0
  231. package/dist/src/gateway/engine-health-monitor.js.map +1 -0
  232. package/dist/src/gateway/files.d.ts +7 -1
  233. package/dist/src/gateway/files.d.ts.map +1 -1
  234. package/dist/src/gateway/files.js +110 -217
  235. package/dist/src/gateway/files.js.map +1 -1
  236. package/dist/src/gateway/onboarding-personalize.d.ts +2 -0
  237. package/dist/src/gateway/onboarding-personalize.d.ts.map +1 -1
  238. package/dist/src/gateway/onboarding-personalize.js +17 -1
  239. package/dist/src/gateway/onboarding-personalize.js.map +1 -1
  240. package/dist/src/gateway/portal-config.d.ts +17 -3
  241. package/dist/src/gateway/portal-config.d.ts.map +1 -1
  242. package/dist/src/gateway/portal-config.js +52 -3
  243. package/dist/src/gateway/portal-config.js.map +1 -1
  244. package/dist/src/gateway/request-origin.d.ts +9 -0
  245. package/dist/src/gateway/request-origin.d.ts.map +1 -1
  246. package/dist/src/gateway/request-origin.js +10 -0
  247. package/dist/src/gateway/request-origin.js.map +1 -1
  248. package/dist/src/gateway/server.d.ts.map +1 -1
  249. package/dist/src/gateway/server.js +82 -59
  250. package/dist/src/gateway/server.js.map +1 -1
  251. package/dist/src/gateway/slack-connect-rollback.d.ts +23 -0
  252. package/dist/src/gateway/slack-connect-rollback.d.ts.map +1 -0
  253. package/dist/src/gateway/slack-connect-rollback.js +53 -0
  254. package/dist/src/gateway/slack-connect-rollback.js.map +1 -0
  255. package/dist/src/gateway/status-reconciler.d.ts +25 -7
  256. package/dist/src/gateway/status-reconciler.d.ts.map +1 -1
  257. package/dist/src/gateway/status-reconciler.js +86 -43
  258. package/dist/src/gateway/status-reconciler.js.map +1 -1
  259. package/dist/src/gateway/watcher.d.ts.map +1 -1
  260. package/dist/src/gateway/watcher.js +44 -3
  261. package/dist/src/gateway/watcher.js.map +1 -1
  262. package/dist/src/mcp/gateway-server.js +21 -3
  263. package/dist/src/mcp/gateway-server.js.map +1 -1
  264. package/dist/src/mcp/resolver.d.ts.map +1 -1
  265. package/dist/src/mcp/resolver.js +51 -1
  266. package/dist/src/mcp/resolver.js.map +1 -1
  267. package/dist/src/models/service.d.ts.map +1 -1
  268. package/dist/src/models/service.js +14 -8
  269. package/dist/src/models/service.js.map +1 -1
  270. package/dist/src/provider-auth/discovery.d.ts +16 -0
  271. package/dist/src/provider-auth/discovery.d.ts.map +1 -0
  272. package/dist/src/provider-auth/discovery.js +66 -0
  273. package/dist/src/provider-auth/discovery.js.map +1 -0
  274. package/dist/src/provider-auth/failure-notices.d.ts +29 -0
  275. package/dist/src/provider-auth/failure-notices.d.ts.map +1 -0
  276. package/dist/src/provider-auth/failure-notices.js +48 -0
  277. package/dist/src/provider-auth/failure-notices.js.map +1 -0
  278. package/dist/src/provider-auth/failure-signal.d.ts +22 -0
  279. package/dist/src/provider-auth/failure-signal.d.ts.map +1 -0
  280. package/dist/src/provider-auth/failure-signal.js +79 -0
  281. package/dist/src/provider-auth/failure-signal.js.map +1 -0
  282. package/dist/src/provider-auth/index.d.ts +26 -0
  283. package/dist/src/provider-auth/index.d.ts.map +1 -0
  284. package/dist/src/provider-auth/index.js +51 -0
  285. package/dist/src/provider-auth/index.js.map +1 -0
  286. package/dist/src/provider-auth/input.d.ts +44 -0
  287. package/dist/src/provider-auth/input.d.ts.map +1 -0
  288. package/dist/src/provider-auth/input.js +86 -0
  289. package/dist/src/provider-auth/input.js.map +1 -0
  290. package/dist/src/provider-auth/providers.d.ts +26 -0
  291. package/dist/src/provider-auth/providers.d.ts.map +1 -0
  292. package/dist/src/provider-auth/providers.js +86 -0
  293. package/dist/src/provider-auth/providers.js.map +1 -0
  294. package/dist/src/provider-auth/runtime.d.ts +21 -0
  295. package/dist/src/provider-auth/runtime.d.ts.map +1 -0
  296. package/dist/src/provider-auth/runtime.js +104 -0
  297. package/dist/src/provider-auth/runtime.js.map +1 -0
  298. package/dist/src/provider-auth/service.d.ts +70 -0
  299. package/dist/src/provider-auth/service.d.ts.map +1 -0
  300. package/dist/src/provider-auth/service.js +349 -0
  301. package/dist/src/provider-auth/service.js.map +1 -0
  302. package/dist/src/provider-auth/terminal.d.ts +21 -0
  303. package/dist/src/provider-auth/terminal.d.ts.map +1 -0
  304. package/dist/src/provider-auth/terminal.js +46 -0
  305. package/dist/src/provider-auth/terminal.js.map +1 -0
  306. package/dist/src/provider-auth/types.d.ts +123 -0
  307. package/dist/src/provider-auth/types.d.ts.map +1 -0
  308. package/dist/src/provider-auth/types.js +10 -0
  309. package/dist/src/provider-auth/types.js.map +1 -0
  310. package/dist/src/sessions/accounting.d.ts +3 -0
  311. package/dist/src/sessions/accounting.d.ts.map +1 -1
  312. package/dist/src/sessions/accounting.js +5 -0
  313. package/dist/src/sessions/accounting.js.map +1 -1
  314. package/dist/src/sessions/backup-integrity.d.ts +45 -0
  315. package/dist/src/sessions/backup-integrity.d.ts.map +1 -0
  316. package/dist/src/sessions/backup-integrity.js +122 -0
  317. package/dist/src/sessions/backup-integrity.js.map +1 -0
  318. package/dist/src/sessions/backup.d.ts +40 -2
  319. package/dist/src/sessions/backup.d.ts.map +1 -1
  320. package/dist/src/sessions/backup.js +88 -12
  321. package/dist/src/sessions/backup.js.map +1 -1
  322. package/dist/src/sessions/callbacks.d.ts +9 -0
  323. package/dist/src/sessions/callbacks.d.ts.map +1 -1
  324. package/dist/src/sessions/callbacks.js +55 -10
  325. package/dist/src/sessions/callbacks.js.map +1 -1
  326. package/dist/src/sessions/completion-batching.d.ts +82 -0
  327. package/dist/src/sessions/completion-batching.d.ts.map +1 -0
  328. package/dist/src/sessions/completion-batching.js +126 -0
  329. package/dist/src/sessions/completion-batching.js.map +1 -0
  330. package/dist/src/sessions/connector-command-guard.d.ts +66 -0
  331. package/dist/src/sessions/connector-command-guard.d.ts.map +1 -0
  332. package/dist/src/sessions/connector-command-guard.js +145 -0
  333. package/dist/src/sessions/connector-command-guard.js.map +1 -0
  334. package/dist/src/sessions/context.d.ts.map +1 -1
  335. package/dist/src/sessions/context.js +3 -4
  336. package/dist/src/sessions/context.js.map +1 -1
  337. package/dist/src/sessions/engine-fallback.d.ts +43 -1
  338. package/dist/src/sessions/engine-fallback.d.ts.map +1 -1
  339. package/dist/src/sessions/engine-fallback.js +266 -15
  340. package/dist/src/sessions/engine-fallback.js.map +1 -1
  341. package/dist/src/sessions/engine-health-gate.d.ts +83 -0
  342. package/dist/src/sessions/engine-health-gate.d.ts.map +1 -0
  343. package/dist/src/sessions/engine-health-gate.js +186 -0
  344. package/dist/src/sessions/engine-health-gate.js.map +1 -0
  345. package/dist/src/sessions/engine-login.d.ts +58 -0
  346. package/dist/src/sessions/engine-login.d.ts.map +1 -0
  347. package/dist/src/sessions/engine-login.js +107 -0
  348. package/dist/src/sessions/engine-login.js.map +1 -0
  349. package/dist/src/sessions/fork.d.ts.map +1 -1
  350. package/dist/src/sessions/fork.js +3 -1
  351. package/dist/src/sessions/fork.js.map +1 -1
  352. package/dist/src/sessions/goal-execution.d.ts.map +1 -1
  353. package/dist/src/sessions/goal-execution.js +8 -1
  354. package/dist/src/sessions/goal-execution.js.map +1 -1
  355. package/dist/src/sessions/limit-failure-notice.d.ts +41 -0
  356. package/dist/src/sessions/limit-failure-notice.d.ts.map +1 -0
  357. package/dist/src/sessions/limit-failure-notice.js +87 -0
  358. package/dist/src/sessions/limit-failure-notice.js.map +1 -0
  359. package/dist/src/sessions/lost-turn.d.ts +39 -0
  360. package/dist/src/sessions/lost-turn.d.ts.map +1 -0
  361. package/dist/src/sessions/lost-turn.js +32 -0
  362. package/dist/src/sessions/lost-turn.js.map +1 -0
  363. package/dist/src/sessions/manager.d.ts.map +1 -1
  364. package/dist/src/sessions/manager.js +104 -47
  365. package/dist/src/sessions/manager.js.map +1 -1
  366. package/dist/src/sessions/new-session-engine.d.ts +42 -0
  367. package/dist/src/sessions/new-session-engine.d.ts.map +1 -0
  368. package/dist/src/sessions/new-session-engine.js +100 -0
  369. package/dist/src/sessions/new-session-engine.js.map +1 -0
  370. package/dist/src/sessions/origin-delivery.d.ts +50 -4
  371. package/dist/src/sessions/origin-delivery.d.ts.map +1 -1
  372. package/dist/src/sessions/origin-delivery.js +108 -9
  373. package/dist/src/sessions/origin-delivery.js.map +1 -1
  374. package/dist/src/sessions/queue.d.ts +14 -0
  375. package/dist/src/sessions/queue.d.ts.map +1 -1
  376. package/dist/src/sessions/queue.js +38 -2
  377. package/dist/src/sessions/queue.js.map +1 -1
  378. package/dist/src/sessions/registry.d.ts +4 -2
  379. package/dist/src/sessions/registry.d.ts.map +1 -1
  380. package/dist/src/sessions/registry.js +21 -4
  381. package/dist/src/sessions/registry.js.map +1 -1
  382. package/dist/src/sessions/reply-disposition.d.ts +8 -0
  383. package/dist/src/sessions/reply-disposition.d.ts.map +1 -1
  384. package/dist/src/sessions/reply-disposition.js +8 -0
  385. package/dist/src/sessions/reply-disposition.js.map +1 -1
  386. package/dist/src/sessions/restart-resume.d.ts +234 -0
  387. package/dist/src/sessions/restart-resume.d.ts.map +1 -0
  388. package/dist/src/sessions/restart-resume.js +596 -0
  389. package/dist/src/sessions/restart-resume.js.map +1 -0
  390. package/dist/src/sessions/speaker-prefix.d.ts.map +1 -1
  391. package/dist/src/sessions/speaker-prefix.js +3 -1
  392. package/dist/src/sessions/speaker-prefix.js.map +1 -1
  393. package/dist/src/sessions/turn-delivery.d.ts +26 -0
  394. package/dist/src/sessions/turn-delivery.d.ts.map +1 -0
  395. package/dist/src/sessions/turn-delivery.js +34 -0
  396. package/dist/src/sessions/turn-delivery.js.map +1 -0
  397. package/dist/src/sessions/unrequested-stop.d.ts +26 -0
  398. package/dist/src/sessions/unrequested-stop.d.ts.map +1 -0
  399. package/dist/src/sessions/unrequested-stop.js +19 -0
  400. package/dist/src/sessions/unrequested-stop.js.map +1 -0
  401. package/dist/src/sessions/usage-limit-wait.d.ts +14 -0
  402. package/dist/src/sessions/usage-limit-wait.d.ts.map +1 -0
  403. package/dist/src/sessions/usage-limit-wait.js +9 -0
  404. package/dist/src/sessions/usage-limit-wait.js.map +1 -0
  405. package/dist/src/shared/attachment-download.d.ts +41 -0
  406. package/dist/src/shared/attachment-download.d.ts.map +1 -0
  407. package/dist/src/shared/attachment-download.js +110 -0
  408. package/dist/src/shared/attachment-download.js.map +1 -0
  409. package/dist/src/shared/attachment-notice.d.ts +24 -0
  410. package/dist/src/shared/attachment-notice.d.ts.map +1 -0
  411. package/dist/src/shared/attachment-notice.js +37 -0
  412. package/dist/src/shared/attachment-notice.js.map +1 -0
  413. package/dist/src/shared/attachments.d.ts +65 -0
  414. package/dist/src/shared/attachments.d.ts.map +1 -0
  415. package/dist/src/shared/attachments.js +153 -0
  416. package/dist/src/shared/attachments.js.map +1 -0
  417. package/dist/src/shared/childEnv.d.ts +15 -0
  418. package/dist/src/shared/childEnv.d.ts.map +1 -1
  419. package/dist/src/shared/childEnv.js +15 -0
  420. package/dist/src/shared/childEnv.js.map +1 -1
  421. package/dist/src/shared/claude-auto-memory.d.ts +33 -0
  422. package/dist/src/shared/claude-auto-memory.d.ts.map +1 -0
  423. package/dist/src/shared/claude-auto-memory.js +156 -0
  424. package/dist/src/shared/claude-auto-memory.js.map +1 -0
  425. package/dist/src/shared/claude-limit-reset.d.ts +54 -0
  426. package/dist/src/shared/claude-limit-reset.d.ts.map +1 -0
  427. package/dist/src/shared/claude-limit-reset.js +99 -0
  428. package/dist/src/shared/claude-limit-reset.js.map +1 -0
  429. package/dist/src/shared/config-error.d.ts +21 -0
  430. package/dist/src/shared/config-error.d.ts.map +1 -0
  431. package/dist/src/shared/config-error.js +37 -0
  432. package/dist/src/shared/config-error.js.map +1 -0
  433. package/dist/src/shared/config-file.d.ts +57 -0
  434. package/dist/src/shared/config-file.d.ts.map +1 -0
  435. package/dist/src/shared/config-file.js +217 -0
  436. package/dist/src/shared/config-file.js.map +1 -0
  437. package/dist/src/shared/config-yaml-edit.d.ts +20 -0
  438. package/dist/src/shared/config-yaml-edit.d.ts.map +1 -0
  439. package/dist/src/shared/config-yaml-edit.js +468 -0
  440. package/dist/src/shared/config-yaml-edit.js.map +1 -0
  441. package/dist/src/shared/config.d.ts.map +1 -1
  442. package/dist/src/shared/config.js +12 -4
  443. package/dist/src/shared/config.js.map +1 -1
  444. package/dist/src/shared/engine-fallback.d.ts +22 -0
  445. package/dist/src/shared/engine-fallback.d.ts.map +1 -1
  446. package/dist/src/shared/engine-fallback.js +55 -4
  447. package/dist/src/shared/engine-fallback.js.map +1 -1
  448. package/dist/src/shared/engine-health.d.ts +16 -0
  449. package/dist/src/shared/engine-health.d.ts.map +1 -1
  450. package/dist/src/shared/engine-health.js +42 -0
  451. package/dist/src/shared/engine-health.js.map +1 -1
  452. package/dist/src/shared/list-alignment.d.ts +23 -0
  453. package/dist/src/shared/list-alignment.d.ts.map +1 -0
  454. package/dist/src/shared/list-alignment.js +61 -0
  455. package/dist/src/shared/list-alignment.js.map +1 -0
  456. package/dist/src/shared/logger.d.ts.map +1 -1
  457. package/dist/src/shared/logger.js +104 -33
  458. package/dist/src/shared/logger.js.map +1 -1
  459. package/dist/src/shared/map-limited.d.ts +11 -0
  460. package/dist/src/shared/map-limited.d.ts.map +1 -0
  461. package/dist/src/shared/map-limited.js +30 -0
  462. package/dist/src/shared/map-limited.js.map +1 -0
  463. package/dist/src/shared/oneShotCli.d.ts.map +1 -1
  464. package/dist/src/shared/oneShotCli.js +4 -2
  465. package/dist/src/shared/oneShotCli.js.map +1 -1
  466. package/dist/src/shared/partial-delivery.d.ts +24 -0
  467. package/dist/src/shared/partial-delivery.d.ts.map +1 -0
  468. package/dist/src/shared/partial-delivery.js +46 -0
  469. package/dist/src/shared/partial-delivery.js.map +1 -0
  470. package/dist/src/shared/process-safety-net.d.ts +44 -0
  471. package/dist/src/shared/process-safety-net.d.ts.map +1 -0
  472. package/dist/src/shared/process-safety-net.js +88 -0
  473. package/dist/src/shared/process-safety-net.js.map +1 -0
  474. package/dist/src/shared/rateLimit.d.ts +45 -2
  475. package/dist/src/shared/rateLimit.d.ts.map +1 -1
  476. package/dist/src/shared/rateLimit.js +64 -2
  477. package/dist/src/shared/rateLimit.js.map +1 -1
  478. package/dist/src/shared/redact.d.ts.map +1 -1
  479. package/dist/src/shared/redact.js +11 -1
  480. package/dist/src/shared/redact.js.map +1 -1
  481. package/dist/src/shared/safe-file-name.d.ts +9 -0
  482. package/dist/src/shared/safe-file-name.d.ts.map +1 -0
  483. package/dist/src/shared/safe-file-name.js +16 -0
  484. package/dist/src/shared/safe-file-name.js.map +1 -0
  485. package/dist/src/shared/terminal-safe-text.d.ts +2 -0
  486. package/dist/src/shared/terminal-safe-text.d.ts.map +1 -0
  487. package/dist/src/shared/terminal-safe-text.js +21 -0
  488. package/dist/src/shared/terminal-safe-text.js.map +1 -0
  489. package/dist/src/shared/types.d.ts +75 -4
  490. package/dist/src/shared/types.d.ts.map +1 -1
  491. package/dist/src/skills-sync/apply.d.ts +21 -0
  492. package/dist/src/skills-sync/apply.d.ts.map +1 -0
  493. package/dist/src/skills-sync/apply.js +209 -0
  494. package/dist/src/skills-sync/apply.js.map +1 -0
  495. package/dist/src/skills-sync/backup-run.d.ts +47 -0
  496. package/dist/src/skills-sync/backup-run.d.ts.map +1 -0
  497. package/dist/src/skills-sync/backup-run.js +150 -0
  498. package/dist/src/skills-sync/backup-run.js.map +1 -0
  499. package/dist/src/skills-sync/bounded-read.d.ts +32 -0
  500. package/dist/src/skills-sync/bounded-read.d.ts.map +1 -0
  501. package/dist/src/skills-sync/bounded-read.js +104 -0
  502. package/dist/src/skills-sync/bounded-read.js.map +1 -0
  503. package/dist/src/skills-sync/bundled.d.ts +28 -0
  504. package/dist/src/skills-sync/bundled.d.ts.map +1 -0
  505. package/dist/src/skills-sync/bundled.js +84 -0
  506. package/dist/src/skills-sync/bundled.js.map +1 -0
  507. package/dist/src/skills-sync/fingerprint.d.ts +32 -0
  508. package/dist/src/skills-sync/fingerprint.d.ts.map +1 -0
  509. package/dist/src/skills-sync/fingerprint.js +58 -0
  510. package/dist/src/skills-sync/fingerprint.js.map +1 -0
  511. package/dist/src/skills-sync/history.d.ts +44 -0
  512. package/dist/src/skills-sync/history.d.ts.map +1 -0
  513. package/dist/src/skills-sync/history.js +115 -0
  514. package/dist/src/skills-sync/history.js.map +1 -0
  515. package/dist/src/skills-sync/home-skill.d.ts +28 -0
  516. package/dist/src/skills-sync/home-skill.d.ts.map +1 -0
  517. package/dist/src/skills-sync/home-skill.js +67 -0
  518. package/dist/src/skills-sync/home-skill.js.map +1 -0
  519. package/dist/src/skills-sync/instance.d.ts +26 -0
  520. package/dist/src/skills-sync/instance.d.ts.map +1 -0
  521. package/dist/src/skills-sync/instance.js +128 -0
  522. package/dist/src/skills-sync/instance.js.map +1 -0
  523. package/dist/src/skills-sync/names.d.ts +25 -0
  524. package/dist/src/skills-sync/names.d.ts.map +1 -0
  525. package/dist/src/skills-sync/names.js +56 -0
  526. package/dist/src/skills-sync/names.js.map +1 -0
  527. package/dist/src/skills-sync/plan.d.ts +58 -0
  528. package/dist/src/skills-sync/plan.d.ts.map +1 -0
  529. package/dist/src/skills-sync/plan.js +132 -0
  530. package/dist/src/skills-sync/plan.js.map +1 -0
  531. package/dist/src/skills-sync/receipt.d.ts +61 -0
  532. package/dist/src/skills-sync/receipt.d.ts.map +1 -0
  533. package/dist/src/skills-sync/receipt.js +149 -0
  534. package/dist/src/skills-sync/receipt.js.map +1 -0
  535. package/dist/src/skills-sync/staging.d.ts +21 -0
  536. package/dist/src/skills-sync/staging.d.ts.map +1 -0
  537. package/dist/src/skills-sync/staging.js +81 -0
  538. package/dist/src/skills-sync/staging.js.map +1 -0
  539. package/dist/src/skills-sync/sync.d.ts +37 -0
  540. package/dist/src/skills-sync/sync.d.ts.map +1 -0
  541. package/dist/src/skills-sync/sync.js +201 -0
  542. package/dist/src/skills-sync/sync.js.map +1 -0
  543. package/dist/src/skills-sync/types.d.ts +66 -0
  544. package/dist/src/skills-sync/types.d.ts.map +1 -0
  545. package/dist/src/skills-sync/types.js +2 -0
  546. package/dist/src/skills-sync/types.js.map +1 -0
  547. package/dist/src/stt/config.d.ts +5 -0
  548. package/dist/src/stt/config.d.ts.map +1 -0
  549. package/dist/src/stt/config.js +18 -0
  550. package/dist/src/stt/config.js.map +1 -0
  551. package/dist/src/updates/maintenance.d.ts.map +1 -1
  552. package/dist/src/updates/maintenance.js +24 -4
  553. package/dist/src/updates/maintenance.js.map +1 -1
  554. package/dist/src/workflows/repository-mutex.d.ts +1 -1
  555. package/dist/web/404.html +1 -1
  556. package/dist/web/__next.__PAGE__.txt +11 -11
  557. package/dist/web/__next._full.txt +12 -12
  558. package/dist/web/__next._tree.txt +2 -2
  559. package/dist/web/_next/static/chunks/{0g5c5ppr8zmup.js → 20v6mri7epga5.js} +1 -1
  560. package/dist/web/_next/static/chunks/2u0328ngpt-ek.js +1 -0
  561. package/dist/web/_next/static/chunks/3f9i3f9q6v6_j.css +1 -0
  562. package/dist/web/_next/static/chunks/{08i7uo3uz6_fn.js → 3yy053rafgrzy.js} +1 -1
  563. package/dist/web/_not-found/__next._full.txt +10 -10
  564. package/dist/web/_not-found/__next._not-found.__PAGE__.txt +9 -9
  565. package/dist/web/_not-found/__next._tree.txt +2 -2
  566. package/dist/web/_not-found.html +1 -1
  567. package/dist/web/_not-found.txt +10 -10
  568. package/dist/web/chat/__next._full.txt +12 -12
  569. package/dist/web/chat/__next._tree.txt +2 -2
  570. package/dist/web/chat/__next.chat.__PAGE__.txt +11 -11
  571. package/dist/web/chat.html +1 -1
  572. package/dist/web/chat.txt +12 -12
  573. package/dist/web/cron/__next._full.txt +12 -12
  574. package/dist/web/cron/__next._tree.txt +2 -2
  575. package/dist/web/cron/__next.cron.__PAGE__.txt +11 -11
  576. package/dist/web/cron.html +1 -1
  577. package/dist/web/cron.txt +12 -12
  578. package/dist/web/index.html +1 -1
  579. package/dist/web/index.txt +12 -12
  580. package/dist/web/kanban/__next._full.txt +12 -12
  581. package/dist/web/kanban/__next._tree.txt +2 -2
  582. package/dist/web/kanban/__next.kanban.__PAGE__.txt +11 -11
  583. package/dist/web/kanban.html +1 -1
  584. package/dist/web/kanban.txt +12 -12
  585. package/dist/web/logs/__next._full.txt +12 -12
  586. package/dist/web/logs/__next._tree.txt +2 -2
  587. package/dist/web/logs/__next.logs.__PAGE__.txt +11 -11
  588. package/dist/web/logs.html +1 -1
  589. package/dist/web/logs.txt +12 -12
  590. package/dist/web/models/__next._full.txt +12 -12
  591. package/dist/web/models/__next._tree.txt +2 -2
  592. package/dist/web/models/__next.models.__PAGE__.txt +11 -11
  593. package/dist/web/models.html +1 -1
  594. package/dist/web/models.txt +12 -12
  595. package/dist/web/org/__next._full.txt +12 -12
  596. package/dist/web/org/__next._tree.txt +2 -2
  597. package/dist/web/org/__next.org.__PAGE__.txt +11 -11
  598. package/dist/web/org.html +1 -1
  599. package/dist/web/org.txt +12 -12
  600. package/dist/web/sessions/__next._full.txt +10 -10
  601. package/dist/web/sessions/__next._tree.txt +2 -2
  602. package/dist/web/sessions/__next.sessions.__PAGE__.txt +9 -9
  603. package/dist/web/sessions.html +1 -1
  604. package/dist/web/sessions.txt +10 -10
  605. package/dist/web/settings/__next._full.txt +12 -12
  606. package/dist/web/settings/__next._tree.txt +2 -2
  607. package/dist/web/settings/__next.settings.__PAGE__.txt +11 -11
  608. package/dist/web/settings.html +1 -1
  609. package/dist/web/settings.txt +12 -12
  610. package/dist/web/skills/__next._full.txt +12 -12
  611. package/dist/web/skills/__next._tree.txt +2 -2
  612. package/dist/web/skills/__next.skills.__PAGE__.txt +11 -11
  613. package/dist/web/skills.html +1 -1
  614. package/dist/web/skills.txt +12 -12
  615. package/package.json +2 -1
  616. package/template/AGENTS.md +48 -308
  617. package/template/CLAUDE.md +4 -349
  618. package/template/bundled-skill-history.json +377 -0
  619. package/template/config.default.yaml +52 -3
  620. package/template/docs/architecture.md +41 -3
  621. package/template/docs/backup.md +142 -0
  622. package/template/docs/connectors.md +192 -16
  623. package/template/docs/cron.md +30 -11
  624. package/template/docs/memory.md +47 -0
  625. package/template/docs/overview.md +6 -2
  626. package/template/docs/self-modification.md +11 -10
  627. package/template/docs/skills.md +77 -4
  628. package/template/migrations/0.3.0/MIGRATION.md +6 -0
  629. package/template/migrations/0.7.3/MIGRATION.md +6 -0
  630. package/template/migrations/0.7.5/MIGRATION.md +1 -1
  631. package/template/migrations/0.9.0/MIGRATION.md +6 -0
  632. package/template/migrations/2026.10.13/MIGRATION.md +76 -0
  633. package/template/migrations/2026.10.13/files/docs/architecture.md +112 -0
  634. package/template/migrations/2026.10.13/files/docs/automations.md +110 -0
  635. package/template/migrations/2026.10.13/files/docs/backup.md +142 -0
  636. package/template/migrations/2026.10.13/files/docs/connectors.md +370 -0
  637. package/template/migrations/2026.10.13/files/docs/cron-commands.md +52 -0
  638. package/template/migrations/2026.10.13/files/docs/cron.md +178 -0
  639. package/template/migrations/2026.10.13/files/docs/mcp.md +108 -0
  640. package/template/migrations/2026.10.13/files/docs/memory.md +47 -0
  641. package/template/migrations/2026.10.13/files/docs/org.md +111 -0
  642. package/template/migrations/2026.10.13/files/docs/overview.md +44 -0
  643. package/template/migrations/2026.10.13/files/docs/self-modification.md +71 -0
  644. package/template/migrations/2026.10.13/files/docs/skills.md +140 -0
  645. package/template/migrations/2026.10.13/files/skills/cron-manager/SKILL.md +107 -0
  646. package/template/migrations/2026.10.13/files/skills/management/SKILL.md +227 -0
  647. package/template/migrations/2026.10.13/files/skills/migrate/SKILL.md +194 -0
  648. package/template/migrations/2026.10.13/files/skills/onboarding/SKILL.md +153 -0
  649. package/template/migrations/2026.10.13/files/skills/openryoko-config/SKILL.md +35 -0
  650. package/template/migrations/2026.10.13/files/skills/openryoko-config/references/engine-fallback.md +98 -0
  651. package/template/migrations/2026.10.13/files/skills/openryoko-config/references/jev.md +89 -0
  652. package/template/migrations/2026.10.13/files/skills/openryoko-config/references/maintenance.md +49 -0
  653. package/template/migrations/2026.10.13/files/skills/openryoko-config/references/platform.md +100 -0
  654. package/template/migrations/2026.10.13/files/skills/self-heal/SKILL.md +187 -0
  655. package/template/migrations/2026.10.9/MIGRATION.md +44 -0
  656. package/template/migrations/2026.10.9/files/docs/memory.md +47 -0
  657. package/template/migrations/2026.10.9/files/skills/migrate/SKILL.md +194 -0
  658. package/template/migrations/2026.5.7/MIGRATION.md +6 -0
  659. package/template/migrations/2026.8.28/MIGRATION.md +6 -0
  660. package/template/migrations/2026.9.11/MIGRATION.md +6 -0
  661. package/template/skills/cron-manager/SKILL.md +10 -0
  662. package/template/skills/management/SKILL.md +5 -4
  663. package/template/skills/migrate/SKILL.md +47 -14
  664. package/template/skills/onboarding/SKILL.md +3 -3
  665. package/template/skills/openryoko-config/SKILL.md +1 -1
  666. package/template/skills/openryoko-config/references/engine-fallback.md +16 -5
  667. package/template/skills/openryoko-config/references/platform.md +23 -4
  668. package/template/skills/self-heal/SKILL.md +117 -44
  669. package/dist/src/engines/mock.d.ts +0 -16
  670. package/dist/src/engines/mock.d.ts.map +0 -1
  671. package/dist/src/engines/mock.js +0 -47
  672. package/dist/src/engines/mock.js.map +0 -1
  673. package/dist/src/shared/test-support/posix-mode.d.ts +0 -17
  674. package/dist/src/shared/test-support/posix-mode.d.ts.map +0 -1
  675. package/dist/src/shared/test-support/posix-mode.js +0 -23
  676. package/dist/src/shared/test-support/posix-mode.js.map +0 -1
  677. package/dist/web/_next/static/Oux0UBcCkbX5eOp9-vC4k/_buildManifest.js +0 -11
  678. package/dist/web/_next/static/Oux0UBcCkbX5eOp9-vC4k/_clientMiddlewareManifest.js +0 -1
  679. package/dist/web/_next/static/Oux0UBcCkbX5eOp9-vC4k/_ssgManifest.js +0 -1
  680. package/dist/web/_next/static/chunks/02h65sho8c14h.js +0 -1
  681. package/dist/web/_next/static/chunks/0ic18n-m7ixyw.css +0 -1
  682. package/dist/web/_next/static/chunks/19s8vn2kgy7q1.js +0 -1
  683. package/dist/web/_next/static/chunks/1_jm0szyu2the.js +0 -1
  684. package/dist/web/_next/static/chunks/1omdg4m5w9lgx.js +0 -1
  685. package/dist/web/_next/static/chunks/25nob1new8t4s.js +0 -79
  686. package/dist/web/_next/static/chunks/2iqxlc9wtxzm2.js +0 -1
  687. package/dist/web/_next/static/chunks/3_6klkygi417n.js +0 -1
  688. package/dist/web/_next/static/chunks/3alc-b00c58_3.css +0 -1
  689. /package/dist/web/_next/static/{70PNIyOj8-2kywAG6J41- → ov0mWzyHx0B5oEnTHE_pa}/_buildManifest.js +0 -0
  690. /package/dist/web/_next/static/{70PNIyOj8-2kywAG6J41- → ov0mWzyHx0B5oEnTHE_pa}/_clientMiddlewareManifest.js +0 -0
  691. /package/dist/web/_next/static/{70PNIyOj8-2kywAG6J41- → ov0mWzyHx0B5oEnTHE_pa}/_ssgManifest.js +0 -0
@@ -53,7 +53,9 @@ export function buildSpeakerPrefix(meta, context) {
53
53
  speakerDiscordId: str(meta.speakerDiscordId),
54
54
  ...context,
55
55
  });
56
- const safeName = name.replace(/[\[\]\r\n]/g, "").slice(0, 60);
56
+ // Brackets would close the line early; control characters (line breaks
57
+ // included) act on the terminal the line is pasted into.
58
+ const safeName = name.replace(/[\[\]\u0000-\u001F\u007F-\u009F]/g, "").slice(0, 60);
57
59
  const operator = context.operatorName?.trim();
58
60
  const tag = operator
59
61
  ? isOp
@@ -1 +1 @@
1
- {"version":3,"file":"speaker-prefix.js","sourceRoot":"","sources":["../../../src/sessions/speaker-prefix.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAevD,0DAA0D;AAC1D,SAAS,GAAG,CAAC,CAAU;IACrB,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3D,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAAuB,EACvB,OAAuE;IAEvE,6CAA6C;IAC7C,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAEjE,MAAM,OAAO,GAAG;QACd,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC;QACrB,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC;QACzB,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC;QAC5B,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC;KACxB,CAAC;IACF,oEAAoE;IACpE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAEvB,uEAAuE;IACvE,wEAAwE;IACxE,2CAA2C;IAC3C,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,uBAAuB,CAAC;QAC1D,YAAY,EAAE,OAAO;QACrB,cAAc,EAAE,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC;QACxC,gBAAgB,EAAE,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC;QAC5C,GAAG,OAAO;KACX,CAAC,CAAC;IACH,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC9D,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC;IAC9C,MAAM,GAAG,GAAG,QAAQ;QAClB,CAAC,CAAC,IAAI;YACJ,CAAC,CAAC,iBAAiB;YACnB,CAAC,CAAC,uDAAuD,QAAQ,GAAG;QACtE,CAAC,CAAC,EAAE,CAAC;IACP,OAAO,aAAa,QAAQ,GAAG,GAAG,GAAG,CAAC;AACxC,CAAC"}
1
+ {"version":3,"file":"speaker-prefix.js","sourceRoot":"","sources":["../../../src/sessions/speaker-prefix.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAevD,0DAA0D;AAC1D,SAAS,GAAG,CAAC,CAAU;IACrB,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3D,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAAuB,EACvB,OAAuE;IAEvE,6CAA6C;IAC7C,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAEjE,MAAM,OAAO,GAAG;QACd,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC;QACrB,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC;QACzB,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC;QAC5B,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC;KACxB,CAAC;IACF,oEAAoE;IACpE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAEvB,uEAAuE;IACvE,wEAAwE;IACxE,2CAA2C;IAC3C,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,uBAAuB,CAAC;QAC1D,YAAY,EAAE,OAAO;QACrB,cAAc,EAAE,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC;QACxC,gBAAgB,EAAE,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC;QAC5C,GAAG,OAAO;KACX,CAAC,CAAC;IACH,uEAAuE;IACvE,yDAAyD;IACzD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACpF,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC;IAC9C,MAAM,GAAG,GAAG,QAAQ;QAClB,CAAC,CAAC,IAAI;YACJ,CAAC,CAAC,iBAAiB;YACnB,CAAC,CAAC,uDAAuD,QAAQ,GAAG;QACtE,CAAC,CAAC,EAAE,CAAC;IACP,OAAO,aAAa,QAAQ,GAAG,GAAG,GAAG,CAAC;AACxC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { Session, Target } from "../shared/types.js";
2
+ import { type PublicAction, type PublicDeliverer } from "./reply-disposition.js";
3
+ export interface TurnDelivery {
4
+ /** True when the turn's last public action was a text reply and it landed. */
5
+ deliveredReply: boolean;
6
+ /** Why a public action did not land. Absent when everything was delivered. */
7
+ failure?: string;
8
+ }
9
+ /**
10
+ * Post a finished turn's public actions in order, and report how that went
11
+ * instead of throwing. By the time this runs the engine has produced its
12
+ * result: a connector that cannot take the reply must not turn a completed
13
+ * turn into a failed one, or keep its state from being saved.
14
+ *
15
+ * Delivery stops at the first action that fails — the ones after it would
16
+ * arrive without the message that leads into them.
17
+ */
18
+ export declare function deliverTurn(connector: PublicDeliverer, target: Target, actions: readonly PublicAction[]): Promise<TurnDelivery>;
19
+ /**
20
+ * The turn is saved, but its reply never reached the conversation. Persist
21
+ * that on the session — the same record an undelivered background reply
22
+ * leaves, with the transport's reason added — and log why. Call it after the
23
+ * turn's own state update: it sets lastError.
24
+ */
25
+ export declare function recordUndeliveredTurn(session: Session, failure: string): void;
26
+ //# sourceMappingURL=turn-delivery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turn-delivery.d.ts","sourceRoot":"","sources":["../../../src/sessions/turn-delivery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,EAAiB,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGhG,MAAM,WAAW,YAAY;IAC3B,8EAA8E;IAC9E,cAAc,EAAE,OAAO,CAAC;IACxB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,SAAS,EAAE,eAAe,EAC1B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,SAAS,YAAY,EAAE,GAC/B,OAAO,CAAC,YAAY,CAAC,CASvB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAK7E"}
@@ -0,0 +1,34 @@
1
+ import { logger } from "../shared/logger.js";
2
+ import { deliverPublic } from "./reply-disposition.js";
3
+ import { recordFailedOriginDelivery } from "./origin-delivery.js";
4
+ /**
5
+ * Post a finished turn's public actions in order, and report how that went
6
+ * instead of throwing. By the time this runs the engine has produced its
7
+ * result: a connector that cannot take the reply must not turn a completed
8
+ * turn into a failed one, or keep its state from being saved.
9
+ *
10
+ * Delivery stops at the first action that fails — the ones after it would
11
+ * arrive without the message that leads into them.
12
+ */
13
+ export async function deliverTurn(connector, target, actions) {
14
+ for (const action of actions) {
15
+ try {
16
+ await deliverPublic(connector, target, action);
17
+ }
18
+ catch (err) {
19
+ return { deliveredReply: false, failure: err instanceof Error ? err.message : String(err) };
20
+ }
21
+ }
22
+ return { deliveredReply: actions.at(-1)?.kind === "reply" };
23
+ }
24
+ /**
25
+ * The turn is saved, but its reply never reached the conversation. Persist
26
+ * that on the session — the same record an undelivered background reply
27
+ * leaves, with the transport's reason added — and log why. Call it after the
28
+ * turn's own state update: it sets lastError.
29
+ */
30
+ export function recordUndeliveredTurn(session, failure) {
31
+ logger.error(`Session ${session.id}: reply was not delivered to ${session.connector ?? session.source} — ${failure}`);
32
+ recordFailedOriginDelivery(session, undefined, failure);
33
+ }
34
+ //# sourceMappingURL=turn-delivery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turn-delivery.js","sourceRoot":"","sources":["../../../src/sessions/turn-delivery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAA2C,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AASlE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,SAA0B,EAC1B,MAAc,EACd,OAAgC;IAEhC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,MAAM,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9F,CAAC;IACH,CAAC;IACD,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,KAAK,OAAO,EAAE,CAAC;AAC9D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAgB,EAAE,OAAe;IACrE,MAAM,CAAC,KAAK,CACV,WAAW,OAAO,CAAC,EAAE,gCAAgC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,MAAM,MAAM,OAAO,EAAE,CACxG,CAAC;IACF,0BAA0B,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The failure of an engine run that stopped without being asked to — how it is
3
+ * worded, and how a session that failed that way is recognised afterwards.
4
+ *
5
+ * settleUnrequestedStop() (engine-fallback.ts) turns such a run into a failed
6
+ * one: the engine's process died, or its own turn deadline ran out. The session
7
+ * ends up in "error" like any other failure, but it is not like the others. A
8
+ * session stopped by a usage limit or a lost login fails again on its next
9
+ * turn; this one has its engine session and its transcript intact, and its next
10
+ * turn simply starts a new process.
11
+ *
12
+ * Whoever has to tell the two apart asks here. This module is the one place
13
+ * that knows the wording, and it depends on nothing, so that anything — the
14
+ * callback that wakes a parent for its children — can ask without pulling in
15
+ * the engine runner.
16
+ */
17
+ import type { Session } from "../shared/types.js";
18
+ /** The error a run that stopped without being asked to is settled with. */
19
+ export declare function unrequestedStopError(engineName: string, detail: string): string;
20
+ /**
21
+ * True while a session is in the error its last turn was settled with because
22
+ * its engine stopped without being asked to. The next turn that settles — or
23
+ * anything else that rewrites lastError — ends it.
24
+ */
25
+ export declare function failedByUnrequestedStop(session: Pick<Session, "status" | "lastError">): boolean;
26
+ //# sourceMappingURL=unrequested-stop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unrequested-stop.d.ts","sourceRoot":"","sources":["../../../src/sessions/unrequested-stop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAMlD,2EAA2E;AAC3E,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE/E;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,WAAW,CAAC,GAAG,OAAO,CAI/F"}
@@ -0,0 +1,19 @@
1
+ const STOPPED_UNEXPECTEDLY = " stopped unexpectedly: ";
2
+ /** What the wording starts with: the engine's name, and nothing before it. */
3
+ const ENGINE_NAME = /^[\w.-]+$/;
4
+ /** The error a run that stopped without being asked to is settled with. */
5
+ export function unrequestedStopError(engineName, detail) {
6
+ return `${engineName}${STOPPED_UNEXPECTEDLY}${detail}`;
7
+ }
8
+ /**
9
+ * True while a session is in the error its last turn was settled with because
10
+ * its engine stopped without being asked to. The next turn that settles — or
11
+ * anything else that rewrites lastError — ends it.
12
+ */
13
+ export function failedByUnrequestedStop(session) {
14
+ if (session.status !== "error" || !session.lastError)
15
+ return false;
16
+ const at = session.lastError.indexOf(STOPPED_UNEXPECTEDLY);
17
+ return at > 0 && ENGINE_NAME.test(session.lastError.slice(0, at));
18
+ }
19
+ //# sourceMappingURL=unrequested-stop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unrequested-stop.js","sourceRoot":"","sources":["../../../src/sessions/unrequested-stop.ts"],"names":[],"mappings":"AAkBA,MAAM,oBAAoB,GAAG,yBAAyB,CAAC;AACvD,8EAA8E;AAC9E,MAAM,WAAW,GAAG,WAAW,CAAC;AAEhC,2EAA2E;AAC3E,MAAM,UAAU,oBAAoB,CAAC,UAAkB,EAAE,MAAc;IACrE,OAAO,GAAG,UAAU,GAAG,oBAAoB,GAAG,MAAM,EAAE,CAAC;AACzD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAA8C;IACpF,IAAI,OAAO,CAAC,MAAM,KAAK,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IACnE,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC3D,OAAO,EAAE,GAAG,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AACpE,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * When a parked turn expects its usage limit to reset.
3
+ *
4
+ * A turn that meets a usage limit with no engine to switch to is parked: its
5
+ * session goes to "waiting", and the runner notes the reset it is waiting for
6
+ * in `lastError`, as an ISO time ("<engine> usage limit — resumes <ISO>").
7
+ * The wait itself is a loop in the gateway process, so that note is all that
8
+ * is left of it on disk. This is the one place that reads it.
9
+ */
10
+ import type { Session } from "../shared/types.js";
11
+ /** The reset (ISO) the usage-limit wait of a "waiting" session expects, when
12
+ * that wait knows it. Undefined for a session that is not waiting. */
13
+ export declare function usageLimitWaitResetsAt(session: Pick<Session, "status" | "lastError">): string | undefined;
14
+ //# sourceMappingURL=usage-limit-wait.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage-limit-wait.d.ts","sourceRoot":"","sources":["../../../src/sessions/usage-limit-wait.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAIlD;uEACuE;AACvE,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,WAAW,CAAC,GAAG,MAAM,GAAG,SAAS,CAGzG"}
@@ -0,0 +1,9 @@
1
+ const ISO_TIME = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z/;
2
+ /** The reset (ISO) the usage-limit wait of a "waiting" session expects, when
3
+ * that wait knows it. Undefined for a session that is not waiting. */
4
+ export function usageLimitWaitResetsAt(session) {
5
+ if (session.status !== "waiting")
6
+ return undefined;
7
+ return session.lastError?.match(ISO_TIME)?.[0];
8
+ }
9
+ //# sourceMappingURL=usage-limit-wait.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage-limit-wait.js","sourceRoot":"","sources":["../../../src/sessions/usage-limit-wait.ts"],"names":[],"mappings":"AAWA,MAAM,QAAQ,GAAG,gDAAgD,CAAC;AAElE;uEACuE;AACvE,MAAM,UAAU,sBAAsB,CAAC,OAA8C;IACnF,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACnD,OAAO,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The largest attachment a connector downloads when its config does not say:
3
+ * `connectors.<name>.maxAttachmentMb`. How large a file is, is up to whoever
4
+ * sent it, so there has to be a limit; it is generous because people do send
5
+ * recordings and videos, and a file over it is not delivered to the session.
6
+ */
7
+ export declare const DEFAULT_MAX_ATTACHMENT_MB = 200;
8
+ /**
9
+ * A connector's attachment limit in bytes, from its `maxAttachmentMb`. The
10
+ * config is hand-edited YAML: anything that is not a positive number means
11
+ * the default, not "no limit" and not "nothing at all".
12
+ */
13
+ export declare function attachmentLimitBytes(maxAttachmentMb: unknown): number;
14
+ /** `bytes` in megabytes, the way the setting is written: "200", "1.5", "0.5". */
15
+ export declare function megabytes(bytes: number): string;
16
+ /** The message says how large is too large, and nothing about the file. */
17
+ export declare class AttachmentTooLargeError extends Error {
18
+ /** The limit that was passed. */
19
+ readonly maxBytes: number;
20
+ constructor(maxBytes: number);
21
+ }
22
+ /**
23
+ * Save what `chunks` yields as the file `destPath`, refusing more than
24
+ * `maxBytes`.
25
+ *
26
+ * Each chunk is written as it arrives, so no more than one chunk is held in
27
+ * memory however large the file, and reading stops at the first chunk that
28
+ * passes the limit — the rest is never asked for. The directory is created
29
+ * once there is something to put in it. When the save fails, for size or for
30
+ * any other reason, nothing is left: neither the partial file nor a directory
31
+ * created for it.
32
+ */
33
+ export declare function saveWithin(chunks: AsyncIterable<Uint8Array>, destination: string, maxBytes: number): Promise<void>;
34
+ /**
35
+ * Save the body of an HTTP response as `destPath`, refusing more than
36
+ * `maxBytes`. A body announced as larger is refused without being read; the
37
+ * announcement is not trusted beyond that, and the body is counted as it is
38
+ * read either way (see {@link saveWithin}).
39
+ */
40
+ export declare function saveResponseWithin(res: Response, destPath: string, maxBytes: number): Promise<void>;
41
+ //# sourceMappingURL=attachment-download.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment-download.d.ts","sourceRoot":"","sources":["../../../src/shared/attachment-download.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAE7C;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,OAAO,GAAG,MAAM,CAIrE;AAED,iFAAiF;AACjF,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,2EAA2E;AAC3E,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,iCAAiC;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBACd,QAAQ,EAAE,MAAM;CAK7B;AAqBD;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBxH;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQzG"}
@@ -0,0 +1,110 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ const BYTES_PER_MB = 1024 * 1024;
4
+ /**
5
+ * The largest attachment a connector downloads when its config does not say:
6
+ * `connectors.<name>.maxAttachmentMb`. How large a file is, is up to whoever
7
+ * sent it, so there has to be a limit; it is generous because people do send
8
+ * recordings and videos, and a file over it is not delivered to the session.
9
+ */
10
+ export const DEFAULT_MAX_ATTACHMENT_MB = 200;
11
+ /**
12
+ * A connector's attachment limit in bytes, from its `maxAttachmentMb`. The
13
+ * config is hand-edited YAML: anything that is not a positive number means
14
+ * the default, not "no limit" and not "nothing at all".
15
+ */
16
+ export function attachmentLimitBytes(maxAttachmentMb) {
17
+ const megabytes = typeof maxAttachmentMb === "number" && Number.isFinite(maxAttachmentMb) && maxAttachmentMb > 0 ? maxAttachmentMb : DEFAULT_MAX_ATTACHMENT_MB;
18
+ return Math.floor(megabytes * BYTES_PER_MB);
19
+ }
20
+ /** `bytes` in megabytes, the way the setting is written: "200", "1.5", "0.5". */
21
+ export function megabytes(bytes) {
22
+ return String(Number((bytes / BYTES_PER_MB).toFixed(2)));
23
+ }
24
+ /** The message says how large is too large, and nothing about the file. */
25
+ export class AttachmentTooLargeError extends Error {
26
+ /** The limit that was passed. */
27
+ maxBytes;
28
+ constructor(maxBytes) {
29
+ super(`Attachment is too large (limit ${maxBytes} bytes)`);
30
+ this.name = "AttachmentTooLargeError";
31
+ this.maxBytes = maxBytes;
32
+ }
33
+ }
34
+ /**
35
+ * Remove a failed save: the partial file, and the directories that were
36
+ * created for it. Deliberately weak tools — unlink removes one file, and a
37
+ * non-recursive rmdir removes a directory only while it is empty — so that
38
+ * whatever path this is handed, it cannot take anything else with it.
39
+ */
40
+ async function discard(destPath, firstCreated) {
41
+ await fs.promises.unlink(destPath).catch(() => { });
42
+ if (firstCreated === undefined)
43
+ return;
44
+ for (let directory = path.dirname(destPath); directory.startsWith(firstCreated); directory = path.dirname(directory)) {
45
+ try {
46
+ await fs.promises.rmdir(directory);
47
+ }
48
+ catch {
49
+ return; // not empty (somebody else's file is in it), or already gone
50
+ }
51
+ if (directory === firstCreated)
52
+ return;
53
+ }
54
+ }
55
+ /**
56
+ * Save what `chunks` yields as the file `destPath`, refusing more than
57
+ * `maxBytes`.
58
+ *
59
+ * Each chunk is written as it arrives, so no more than one chunk is held in
60
+ * memory however large the file, and reading stops at the first chunk that
61
+ * passes the limit — the rest is never asked for. The directory is created
62
+ * once there is something to put in it. When the save fails, for size or for
63
+ * any other reason, nothing is left: neither the partial file nor a directory
64
+ * created for it.
65
+ */
66
+ export async function saveWithin(chunks, destination, maxBytes) {
67
+ const destPath = path.resolve(destination);
68
+ let handle;
69
+ let firstCreated;
70
+ const open = async () => {
71
+ firstCreated = await fs.promises.mkdir(path.dirname(destPath), { recursive: true });
72
+ return fs.promises.open(destPath, "w");
73
+ };
74
+ try {
75
+ let received = 0;
76
+ for await (const chunk of chunks) {
77
+ received += chunk.byteLength;
78
+ if (received > maxBytes)
79
+ throw new AttachmentTooLargeError(maxBytes);
80
+ handle ??= await open();
81
+ await handle.write(chunk);
82
+ }
83
+ handle ??= await open(); // an empty body is an empty file
84
+ await handle.close();
85
+ }
86
+ catch (err) {
87
+ await handle?.close().catch(() => { });
88
+ await discard(destPath, firstCreated);
89
+ throw err;
90
+ }
91
+ }
92
+ /**
93
+ * Save the body of an HTTP response as `destPath`, refusing more than
94
+ * `maxBytes`. A body announced as larger is refused without being read; the
95
+ * announcement is not trusted beyond that, and the body is counted as it is
96
+ * read either way (see {@link saveWithin}).
97
+ */
98
+ export async function saveResponseWithin(res, destPath, maxBytes) {
99
+ const announced = Number(res.headers.get("content-length"));
100
+ if (Number.isFinite(announced) && announced > maxBytes) {
101
+ await res.body?.cancel().catch(() => { });
102
+ throw new AttachmentTooLargeError(maxBytes);
103
+ }
104
+ const body = res.body;
105
+ await saveWithin(body ?? emptyBody(), destPath, maxBytes);
106
+ }
107
+ async function* emptyBody() {
108
+ // nothing to yield
109
+ }
110
+ //# sourceMappingURL=attachment-download.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment-download.js","sourceRoot":"","sources":["../../../src/shared/attachment-download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAE7C;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,eAAwB;IAC3D,MAAM,SAAS,GACb,OAAO,eAAe,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,eAAe,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,yBAAyB,CAAC;IAC/I,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,YAAY,CAAC,CAAC;AAC9C,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,GAAG,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,2EAA2E;AAC3E,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,iCAAiC;IACxB,QAAQ,CAAS;IAC1B,YAAY,QAAgB;QAC1B,KAAK,CAAC,kCAAkC,QAAQ,SAAS,CAAC,CAAC;QAC3D,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED;;;;;GAKG;AACH,KAAK,UAAU,OAAO,CAAC,QAAgB,EAAE,YAAgC;IACvE,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACnD,IAAI,YAAY,KAAK,SAAS;QAAE,OAAO;IACvC,KAAK,IAAI,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACrH,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACrC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,6DAA6D;QACvE,CAAC;QACD,IAAI,SAAS,KAAK,YAAY;YAAE,OAAO;IACzC,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAiC,EAAE,WAAmB,EAAE,QAAgB;IACvG,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC3C,IAAI,MAA0C,CAAC;IAC/C,IAAI,YAAgC,CAAC;IACrC,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE;QACtB,YAAY,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACpF,OAAO,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACzC,CAAC,CAAC;IACF,IAAI,CAAC;QACH,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YACjC,QAAQ,IAAI,KAAK,CAAC,UAAU,CAAC;YAC7B,IAAI,QAAQ,GAAG,QAAQ;gBAAE,MAAM,IAAI,uBAAuB,CAAC,QAAQ,CAAC,CAAC;YACrE,MAAM,KAAK,MAAM,IAAI,EAAE,CAAC;YACxB,MAAM,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;QACD,MAAM,KAAK,MAAM,IAAI,EAAE,CAAC,CAAC,iCAAiC;QAC1D,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACtC,MAAM,OAAO,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QACtC,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,GAAa,EAAE,QAAgB,EAAE,QAAgB;IACxF,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC5D,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,GAAG,QAAQ,EAAE,CAAC;QACvD,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACzC,MAAM,IAAI,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAC9C,CAAC;IACD,MAAM,IAAI,GAAG,GAAG,CAAC,IAAuE,CAAC;IACzF,MAAM,UAAU,CAAC,IAAI,IAAI,SAAS,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC5D,CAAC;AAED,KAAK,SAAS,CAAC,CAAC,SAAS;IACvB,mBAAmB;AACrB,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * How a connector names an attachment it did not retrieve: `what` — a label of
3
+ * the connector's own making, an opaque ID or a position, never the file's
4
+ * name — and the reason, when the reason is the file's size. Any other error
5
+ * is left out: its message may quote a URL or the name.
6
+ */
7
+ export declare function failedAttachment(what: string, err: unknown): string;
8
+ /**
9
+ * What a connector appends to a message whose attachments did not all arrive.
10
+ *
11
+ * Keep attachment failures visible to the engine. Silently dropping a file can
12
+ * make a content-dependent task continue with invented or unrelated input —
13
+ * and with a size limit in force, "silently dropped" is what would happen to
14
+ * every large video. `failed` holds labels from {@link failedAttachment}: the
15
+ * notice is the connector's own text, with nothing of the sender's in it.
16
+ */
17
+ export declare function attachmentFailureNotice(platform: string, failed: readonly string[]): string;
18
+ /**
19
+ * `text` with the notice for `failed` appended. A slash command is passed on
20
+ * exactly as typed — the session manager matches it by its text, and a command
21
+ * reads no attachment anyway — and so is anything that is not text.
22
+ */
23
+ export declare function withAttachmentNotice<T>(text: T, platform: string, failed: readonly string[]): T | string;
24
+ //# sourceMappingURL=attachment-notice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment-notice.d.ts","sourceRoot":"","sources":["../../../src/shared/attachment-notice.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,CAEnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAO3F;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAGxG"}
@@ -0,0 +1,37 @@
1
+ import { AttachmentTooLargeError, megabytes } from "./attachment-download.js";
2
+ /**
3
+ * How a connector names an attachment it did not retrieve: `what` — a label of
4
+ * the connector's own making, an opaque ID or a position, never the file's
5
+ * name — and the reason, when the reason is the file's size. Any other error
6
+ * is left out: its message may quote a URL or the name.
7
+ */
8
+ export function failedAttachment(what, err) {
9
+ return err instanceof AttachmentTooLargeError ? `${what} (larger than the ${megabytes(err.maxBytes)} MB attachment limit)` : what;
10
+ }
11
+ /**
12
+ * What a connector appends to a message whose attachments did not all arrive.
13
+ *
14
+ * Keep attachment failures visible to the engine. Silently dropping a file can
15
+ * make a content-dependent task continue with invented or unrelated input —
16
+ * and with a size limit in force, "silently dropped" is what would happen to
17
+ * every large video. `failed` holds labels from {@link failedAttachment}: the
18
+ * notice is the connector's own text, with nothing of the sender's in it.
19
+ */
20
+ export function attachmentFailureNotice(platform, failed) {
21
+ if (failed.length === 0)
22
+ return "";
23
+ return (`\n\n[System attachment notice: The following ${platform} attachment(s) could not be retrieved: ` +
24
+ `${failed.join(", ")}. Do not infer or substitute their contents. ` +
25
+ "Explain that the attachment could not be read, and why where a reason is given, before doing any content-dependent work.]");
26
+ }
27
+ /**
28
+ * `text` with the notice for `failed` appended. A slash command is passed on
29
+ * exactly as typed — the session manager matches it by its text, and a command
30
+ * reads no attachment anyway — and so is anything that is not text.
31
+ */
32
+ export function withAttachmentNotice(text, platform, failed) {
33
+ if (typeof text !== "string" || text.trimStart().startsWith("/"))
34
+ return text;
35
+ return text + attachmentFailureNotice(platform, failed);
36
+ }
37
+ //# sourceMappingURL=attachment-notice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment-notice.js","sourceRoot":"","sources":["../../../src/shared/attachment-notice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE9E;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,GAAY;IACzD,OAAO,GAAG,YAAY,uBAAuB,CAAC,CAAC,CAAC,GAAG,IAAI,qBAAqB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CAAC,CAAC,IAAI,CAAC;AACpI,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAgB,EAAE,MAAyB;IACjF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACnC,OAAO,CACL,gDAAgD,QAAQ,yCAAyC;QACjG,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,+CAA+C;QACnE,2HAA2H,CAC5H,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAI,IAAO,EAAE,QAAgB,EAAE,MAAyB;IAC1F,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC9E,OAAO,IAAI,GAAG,uBAAuB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Where connectors keep the attachments they download: tmp/attachments/, one
3
+ * directory per incoming message.
4
+ *
5
+ * Not tmp/ itself. An attachment is named by whoever sent it, and tmp/ also
6
+ * holds the gateway's own state (engine-health.json, claude-usage.json): a
7
+ * file with one of those names would replace it, and the end-of-turn cleanup
8
+ * would then delete it. A directory per message also keeps two messages — or
9
+ * two files of one message — with the same file name from overwriting each
10
+ * other while a turn is still reading them.
11
+ *
12
+ * Absolute, always. The home can be given as a relative path (RYOKO_HOME=./home),
13
+ * and the cleanup below refuses every relative path it is handed — it must
14
+ * never guess what one is relative to. Left relative, this directory was
15
+ * refused along with them, and nothing was ever removed or swept. It is
16
+ * resolved here, once, against the directory the gateway was started in.
17
+ */
18
+ export declare const ATTACHMENTS_DIR: string;
19
+ /**
20
+ * A directory for the attachments of one incoming message. Only the name is
21
+ * decided here; whoever saves a file creates the directory, so a message
22
+ * without attachments (or whose downloads all fail) leaves nothing behind.
23
+ */
24
+ export declare function newAttachmentDir(): string;
25
+ /**
26
+ * Where the `slot`-th attachment of a message goes inside that message's
27
+ * directory. One slot each, because one message can carry two files with the
28
+ * same name (Discord calls every pasted screenshot image.png).
29
+ */
30
+ export declare function attachmentSlot(messageDir: string, slot: number): string;
31
+ /**
32
+ * Keep the per-message directories of these attachment files out of the
33
+ * sweep until {@link removeAttachmentDirs} is called for them. A turn can wait
34
+ * far longer than a day before it reads its attachments — behind a long
35
+ * session, or paused on a usage limit — and must still find them.
36
+ */
37
+ export declare function holdAttachmentDirs(filePaths: readonly string[]): void;
38
+ /**
39
+ * Remove the per-message directories the given attachment files were saved
40
+ * in. A path that is not inside tmp/attachments/ is left alone: this is called
41
+ * with whatever a connector put in `localPath`, and must never delete on its
42
+ * say-so anything but an attachment directory.
43
+ */
44
+ export declare function removeAttachmentDirs(filePaths: readonly string[]): void;
45
+ /** How long a message's attachments stay when nothing came to remove them. */
46
+ export declare const STALE_ATTACHMENTS_AFTER_MS: number;
47
+ /**
48
+ * Remove what has been lying in tmp/attachments/ for longer than
49
+ * `olderThanMs`, and return how many entries went.
50
+ *
51
+ * Attachments are saved when a message arrives and removed when its turn
52
+ * ends. A message that never gets a turn — the bot stays silent on it, the
53
+ * gateway is restarted first — left its files for good, so that posting files
54
+ * where the bot reads was enough to fill the disk. Only direct children of
55
+ * tmp/attachments/ are removed (a link is removed as a link), never the
56
+ * directory itself, and never one a turn still holds.
57
+ */
58
+ export declare function sweepStaleAttachmentDirs(now?: number, olderThanMs?: number): number;
59
+ /**
60
+ * Sweep now — what a previous run of the gateway left behind — and then every
61
+ * hour. Returns the function that stops it. The timer never keeps the process
62
+ * alive on its own.
63
+ */
64
+ export declare function startAttachmentSweep(): () => void;
65
+ //# sourceMappingURL=attachments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachments.d.ts","sourceRoot":"","sources":["../../../src/shared/attachments.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,eAAe,QAAuC,CAAC;AAEpE;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvE;AAqBD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAKrE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAcvE;AAED,8EAA8E;AAC9E,eAAO,MAAM,0BAA0B,QAAsB,CAAC;AAG9D;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,GAAE,MAAmB,EAAE,WAAW,GAAE,MAAmC,GAAG,MAAM,CAsB3H;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,IAAI,CASjD"}
@@ -0,0 +1,153 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { logger } from "./logger.js";
5
+ import { TMP_DIR } from "./paths.js";
6
+ /**
7
+ * Where connectors keep the attachments they download: tmp/attachments/, one
8
+ * directory per incoming message.
9
+ *
10
+ * Not tmp/ itself. An attachment is named by whoever sent it, and tmp/ also
11
+ * holds the gateway's own state (engine-health.json, claude-usage.json): a
12
+ * file with one of those names would replace it, and the end-of-turn cleanup
13
+ * would then delete it. A directory per message also keeps two messages — or
14
+ * two files of one message — with the same file name from overwriting each
15
+ * other while a turn is still reading them.
16
+ *
17
+ * Absolute, always. The home can be given as a relative path (RYOKO_HOME=./home),
18
+ * and the cleanup below refuses every relative path it is handed — it must
19
+ * never guess what one is relative to. Left relative, this directory was
20
+ * refused along with them, and nothing was ever removed or swept. It is
21
+ * resolved here, once, against the directory the gateway was started in.
22
+ */
23
+ export const ATTACHMENTS_DIR = path.resolve(TMP_DIR, "attachments");
24
+ /**
25
+ * A directory for the attachments of one incoming message. Only the name is
26
+ * decided here; whoever saves a file creates the directory, so a message
27
+ * without attachments (or whose downloads all fail) leaves nothing behind.
28
+ */
29
+ export function newAttachmentDir() {
30
+ return path.join(ATTACHMENTS_DIR, randomUUID());
31
+ }
32
+ /**
33
+ * Where the `slot`-th attachment of a message goes inside that message's
34
+ * directory. One slot each, because one message can carry two files with the
35
+ * same name (Discord calls every pasted screenshot image.png).
36
+ */
37
+ export function attachmentSlot(messageDir, slot) {
38
+ return path.join(messageDir, String(slot));
39
+ }
40
+ /**
41
+ * The per-message directory under tmp/attachments/ that `filePath` lies in, or
42
+ * null when it lies anywhere else. A path that is not absolute is not
43
+ * resolved, it is refused: what it is relative to is anybody's guess.
44
+ */
45
+ function messageDirOf(filePath) {
46
+ if (typeof filePath !== "string" || !path.isAbsolute(filePath) || !path.isAbsolute(ATTACHMENTS_DIR))
47
+ return null;
48
+ const root = path.normalize(ATTACHMENTS_DIR);
49
+ const relative = path.relative(root, path.normalize(filePath));
50
+ const [messageDir] = relative.split(path.sep);
51
+ if (!messageDir || messageDir === ".." || path.isAbsolute(relative))
52
+ return null;
53
+ const directory = path.join(root, messageDir);
54
+ // Checked once more where it counts: only a direct child of tmp/attachments/.
55
+ return path.dirname(directory) === root ? directory : null;
56
+ }
57
+ /** Directories a queued or running turn still reads from: the sweep leaves them. */
58
+ const heldDirs = new Set();
59
+ /**
60
+ * Keep the per-message directories of these attachment files out of the
61
+ * sweep until {@link removeAttachmentDirs} is called for them. A turn can wait
62
+ * far longer than a day before it reads its attachments — behind a long
63
+ * session, or paused on a usage limit — and must still find them.
64
+ */
65
+ export function holdAttachmentDirs(filePaths) {
66
+ for (const filePath of filePaths) {
67
+ const directory = messageDirOf(filePath);
68
+ if (directory)
69
+ heldDirs.add(directory);
70
+ }
71
+ }
72
+ /**
73
+ * Remove the per-message directories the given attachment files were saved
74
+ * in. A path that is not inside tmp/attachments/ is left alone: this is called
75
+ * with whatever a connector put in `localPath`, and must never delete on its
76
+ * say-so anything but an attachment directory.
77
+ */
78
+ export function removeAttachmentDirs(filePaths) {
79
+ const directories = new Set();
80
+ for (const filePath of filePaths) {
81
+ const directory = messageDirOf(filePath);
82
+ if (directory)
83
+ directories.add(directory);
84
+ }
85
+ for (const directory of directories) {
86
+ heldDirs.delete(directory);
87
+ try {
88
+ fs.rmSync(directory, { recursive: true, force: true });
89
+ }
90
+ catch {
91
+ // Best effort: a leftover temp directory is not worth failing a turn over.
92
+ }
93
+ }
94
+ }
95
+ /** How long a message's attachments stay when nothing came to remove them. */
96
+ export const STALE_ATTACHMENTS_AFTER_MS = 24 * 60 * 60 * 1000;
97
+ const SWEEP_EVERY_MS = 60 * 60 * 1000;
98
+ /**
99
+ * Remove what has been lying in tmp/attachments/ for longer than
100
+ * `olderThanMs`, and return how many entries went.
101
+ *
102
+ * Attachments are saved when a message arrives and removed when its turn
103
+ * ends. A message that never gets a turn — the bot stays silent on it, the
104
+ * gateway is restarted first — left its files for good, so that posting files
105
+ * where the bot reads was enough to fill the disk. Only direct children of
106
+ * tmp/attachments/ are removed (a link is removed as a link), never the
107
+ * directory itself, and never one a turn still holds.
108
+ */
109
+ export function sweepStaleAttachmentDirs(now = Date.now(), olderThanMs = STALE_ATTACHMENTS_AFTER_MS) {
110
+ if (!path.isAbsolute(ATTACHMENTS_DIR))
111
+ return 0;
112
+ const root = path.normalize(ATTACHMENTS_DIR);
113
+ let names;
114
+ try {
115
+ names = fs.readdirSync(root);
116
+ }
117
+ catch {
118
+ return 0; // nothing was ever saved here
119
+ }
120
+ let removed = 0;
121
+ for (const name of names) {
122
+ const entry = path.join(root, name);
123
+ if (path.dirname(entry) !== root || heldDirs.has(entry))
124
+ continue;
125
+ try {
126
+ if (fs.lstatSync(entry).mtimeMs > now - olderThanMs)
127
+ continue;
128
+ fs.rmSync(entry, { recursive: true, force: true });
129
+ removed++;
130
+ }
131
+ catch {
132
+ // Best effort: the next sweep tries again.
133
+ }
134
+ }
135
+ return removed;
136
+ }
137
+ /**
138
+ * Sweep now — what a previous run of the gateway left behind — and then every
139
+ * hour. Returns the function that stops it. The timer never keeps the process
140
+ * alive on its own.
141
+ */
142
+ export function startAttachmentSweep() {
143
+ const sweep = () => {
144
+ const removed = sweepStaleAttachmentDirs();
145
+ if (removed > 0)
146
+ logger.info(`Removed ${removed} leftover attachment director${removed === 1 ? "y" : "ies"} older than a day`);
147
+ };
148
+ sweep();
149
+ const timer = setInterval(sweep, SWEEP_EVERY_MS);
150
+ timer.unref();
151
+ return () => clearInterval(timer);
152
+ }
153
+ //# sourceMappingURL=attachments.js.map