@aitne/daemon 0.1.3 → 0.1.6

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 (421) hide show
  1. package/dist/adapters/notification-manager.d.ts +12 -0
  2. package/dist/adapters/notification-manager.d.ts.map +1 -1
  3. package/dist/adapters/notification-manager.js +39 -1
  4. package/dist/adapters/notification-manager.js.map +1 -1
  5. package/dist/adapters/whatsapp-adapter.d.ts.map +1 -1
  6. package/dist/adapters/whatsapp-adapter.js +0 -1
  7. package/dist/adapters/whatsapp-adapter.js.map +1 -1
  8. package/dist/api/integration-route-gate.d.ts +15 -11
  9. package/dist/api/integration-route-gate.d.ts.map +1 -1
  10. package/dist/api/integration-route-gate.js +60 -23
  11. package/dist/api/integration-route-gate.js.map +1 -1
  12. package/dist/api/json-body.d.ts +22 -7
  13. package/dist/api/json-body.d.ts.map +1 -1
  14. package/dist/api/json-body.js +27 -8
  15. package/dist/api/json-body.js.map +1 -1
  16. package/dist/api/routes/agent.d.ts.map +1 -1
  17. package/dist/api/routes/agent.js +25 -0
  18. package/dist/api/routes/agent.js.map +1 -1
  19. package/dist/api/routes/backends.d.ts.map +1 -1
  20. package/dist/api/routes/backends.js +96 -1
  21. package/dist/api/routes/backends.js.map +1 -1
  22. package/dist/api/routes/books.js +1 -1
  23. package/dist/api/routes/books.js.map +1 -1
  24. package/dist/api/routes/commands.d.ts.map +1 -1
  25. package/dist/api/routes/commands.js +16 -13
  26. package/dist/api/routes/commands.js.map +1 -1
  27. package/dist/api/routes/context.d.ts.map +1 -1
  28. package/dist/api/routes/context.js +26 -3
  29. package/dist/api/routes/context.js.map +1 -1
  30. package/dist/api/routes/dashboard.d.ts.map +1 -1
  31. package/dist/api/routes/dashboard.js +103 -5
  32. package/dist/api/routes/dashboard.js.map +1 -1
  33. package/dist/api/routes/fs.d.ts +23 -0
  34. package/dist/api/routes/fs.d.ts.map +1 -0
  35. package/dist/api/routes/fs.js +156 -0
  36. package/dist/api/routes/fs.js.map +1 -0
  37. package/dist/api/routes/fs.logic.d.ts +62 -0
  38. package/dist/api/routes/fs.logic.d.ts.map +1 -0
  39. package/dist/api/routes/fs.logic.js +137 -0
  40. package/dist/api/routes/fs.logic.js.map +1 -0
  41. package/dist/api/routes/github.d.ts.map +1 -1
  42. package/dist/api/routes/github.js +38 -5
  43. package/dist/api/routes/github.js.map +1 -1
  44. package/dist/api/routes/health.d.ts.map +1 -1
  45. package/dist/api/routes/health.js +4 -2
  46. package/dist/api/routes/health.js.map +1 -1
  47. package/dist/api/routes/integrations.d.ts +35 -6
  48. package/dist/api/routes/integrations.d.ts.map +1 -1
  49. package/dist/api/routes/integrations.js +192 -15
  50. package/dist/api/routes/integrations.js.map +1 -1
  51. package/dist/api/routes/mail.d.ts.map +1 -1
  52. package/dist/api/routes/mail.js +112 -46
  53. package/dist/api/routes/mail.js.map +1 -1
  54. package/dist/api/routes/metrics.d.ts +1 -0
  55. package/dist/api/routes/metrics.d.ts.map +1 -1
  56. package/dist/api/routes/metrics.js +24 -0
  57. package/dist/api/routes/metrics.js.map +1 -1
  58. package/dist/api/routes/observations.d.ts.map +1 -1
  59. package/dist/api/routes/observations.js +696 -30
  60. package/dist/api/routes/observations.js.map +1 -1
  61. package/dist/api/routes/setup-migrate.d.ts +9 -1
  62. package/dist/api/routes/setup-migrate.d.ts.map +1 -1
  63. package/dist/api/routes/setup-migrate.js +4 -2
  64. package/dist/api/routes/setup-migrate.js.map +1 -1
  65. package/dist/api/routes/skills.d.ts +9 -1
  66. package/dist/api/routes/skills.d.ts.map +1 -1
  67. package/dist/api/routes/skills.js +77 -17
  68. package/dist/api/routes/skills.js.map +1 -1
  69. package/dist/api/routes/voice.d.ts.map +1 -1
  70. package/dist/api/routes/voice.js +62 -4
  71. package/dist/api/routes/voice.js.map +1 -1
  72. package/dist/api/routes/wiki.d.ts +4 -0
  73. package/dist/api/routes/wiki.d.ts.map +1 -0
  74. package/dist/api/routes/wiki.js +1075 -0
  75. package/dist/api/routes/wiki.js.map +1 -0
  76. package/dist/api/server.d.ts +13 -0
  77. package/dist/api/server.d.ts.map +1 -1
  78. package/dist/api/server.js +27 -1
  79. package/dist/api/server.js.map +1 -1
  80. package/dist/bootstrap/adapters.d.ts +109 -0
  81. package/dist/bootstrap/adapters.d.ts.map +1 -0
  82. package/dist/bootstrap/adapters.js +237 -0
  83. package/dist/bootstrap/adapters.js.map +1 -0
  84. package/dist/bootstrap/catchup.d.ts +23 -0
  85. package/dist/bootstrap/catchup.d.ts.map +1 -0
  86. package/dist/bootstrap/catchup.js +124 -0
  87. package/dist/bootstrap/catchup.js.map +1 -0
  88. package/dist/bootstrap/schedule-helpers.d.ts +18 -0
  89. package/dist/bootstrap/schedule-helpers.d.ts.map +1 -0
  90. package/dist/bootstrap/schedule-helpers.js +96 -0
  91. package/dist/bootstrap/schedule-helpers.js.map +1 -0
  92. package/dist/bootstrap/services.d.ts +60 -0
  93. package/dist/bootstrap/services.d.ts.map +1 -0
  94. package/dist/bootstrap/services.js +209 -0
  95. package/dist/bootstrap/services.js.map +1 -0
  96. package/dist/config.d.ts.map +1 -1
  97. package/dist/config.js +26 -0
  98. package/dist/config.js.map +1 -1
  99. package/dist/core/agent-core.d.ts +25 -0
  100. package/dist/core/agent-core.d.ts.map +1 -1
  101. package/dist/core/agent-core.js.map +1 -1
  102. package/dist/core/backends/backend-router.d.ts +28 -1
  103. package/dist/core/backends/backend-router.d.ts.map +1 -1
  104. package/dist/core/backends/backend-router.js +58 -4
  105. package/dist/core/backends/backend-router.js.map +1 -1
  106. package/dist/core/backends/claude-auth.d.ts +70 -0
  107. package/dist/core/backends/claude-auth.d.ts.map +1 -0
  108. package/dist/core/backends/claude-auth.js +198 -0
  109. package/dist/core/backends/claude-auth.js.map +1 -0
  110. package/dist/core/backends/claude-code-core.d.ts +47 -119
  111. package/dist/core/backends/claude-code-core.d.ts.map +1 -1
  112. package/dist/core/backends/claude-code-core.js +166 -1561
  113. package/dist/core/backends/claude-code-core.js.map +1 -1
  114. package/dist/core/backends/claude-delegated.d.ts +86 -0
  115. package/dist/core/backends/claude-delegated.d.ts.map +1 -0
  116. package/dist/core/backends/claude-delegated.js +801 -0
  117. package/dist/core/backends/claude-delegated.js.map +1 -0
  118. package/dist/core/backends/claude-errors.d.ts +39 -0
  119. package/dist/core/backends/claude-errors.d.ts.map +1 -0
  120. package/dist/core/backends/claude-errors.js +71 -0
  121. package/dist/core/backends/claude-errors.js.map +1 -0
  122. package/dist/core/backends/claude-probe.d.ts +103 -0
  123. package/dist/core/backends/claude-probe.d.ts.map +1 -0
  124. package/dist/core/backends/claude-probe.js +336 -0
  125. package/dist/core/backends/claude-probe.js.map +1 -0
  126. package/dist/core/backends/claude-tool-collection.d.ts +135 -0
  127. package/dist/core/backends/claude-tool-collection.d.ts.map +1 -0
  128. package/dist/core/backends/claude-tool-collection.js +1093 -0
  129. package/dist/core/backends/claude-tool-collection.js.map +1 -0
  130. package/dist/core/backends/codex-core.d.ts.map +1 -1
  131. package/dist/core/backends/codex-core.js +36 -0
  132. package/dist/core/backends/codex-core.js.map +1 -1
  133. package/dist/core/backends/gemini-cli-core.d.ts +45 -5
  134. package/dist/core/backends/gemini-cli-core.d.ts.map +1 -1
  135. package/dist/core/backends/gemini-cli-core.js +146 -36
  136. package/dist/core/backends/gemini-cli-core.js.map +1 -1
  137. package/dist/core/backends/plan-presets.d.ts +3 -1
  138. package/dist/core/backends/plan-presets.d.ts.map +1 -1
  139. package/dist/core/backends/plan-presets.js +42 -2
  140. package/dist/core/backends/plan-presets.js.map +1 -1
  141. package/dist/core/backends/prompt-utils.d.ts +1 -0
  142. package/dist/core/backends/prompt-utils.d.ts.map +1 -1
  143. package/dist/core/backends/prompt-utils.js +60 -3
  144. package/dist/core/backends/prompt-utils.js.map +1 -1
  145. package/dist/core/bang-commands/commands-help.d.ts +5 -0
  146. package/dist/core/bang-commands/commands-help.d.ts.map +1 -0
  147. package/dist/core/bang-commands/commands-help.js +69 -0
  148. package/dist/core/bang-commands/commands-help.js.map +1 -0
  149. package/dist/core/bang-commands/commands-wiki.d.ts +75 -0
  150. package/dist/core/bang-commands/commands-wiki.d.ts.map +1 -0
  151. package/dist/core/bang-commands/commands-wiki.js +574 -0
  152. package/dist/core/bang-commands/commands-wiki.js.map +1 -0
  153. package/dist/core/bang-commands/index.d.ts +4 -2
  154. package/dist/core/bang-commands/index.d.ts.map +1 -1
  155. package/dist/core/bang-commands/index.js +15 -1
  156. package/dist/core/bang-commands/index.js.map +1 -1
  157. package/dist/core/bang-commands/registry.d.ts +47 -4
  158. package/dist/core/bang-commands/registry.d.ts.map +1 -1
  159. package/dist/core/bang-commands/registry.js +85 -15
  160. package/dist/core/bang-commands/registry.js.map +1 -1
  161. package/dist/core/context-builder.d.ts +53 -12
  162. package/dist/core/context-builder.d.ts.map +1 -1
  163. package/dist/core/context-builder.js +240 -92
  164. package/dist/core/context-builder.js.map +1 -1
  165. package/dist/core/daemon-api-cli.d.ts.map +1 -1
  166. package/dist/core/daemon-api-cli.js +50 -2
  167. package/dist/core/daemon-api-cli.js.map +1 -1
  168. package/dist/core/dispatcher-date-utils.d.ts +49 -0
  169. package/dist/core/dispatcher-date-utils.d.ts.map +1 -0
  170. package/dist/core/dispatcher-date-utils.js +132 -0
  171. package/dist/core/dispatcher-date-utils.js.map +1 -0
  172. package/dist/core/dispatcher-error-handling.d.ts +159 -0
  173. package/dist/core/dispatcher-error-handling.d.ts.map +1 -0
  174. package/dist/core/dispatcher-error-handling.js +393 -0
  175. package/dist/core/dispatcher-error-handling.js.map +1 -0
  176. package/dist/core/dispatcher-hourly-check.d.ts +150 -0
  177. package/dist/core/dispatcher-hourly-check.d.ts.map +1 -0
  178. package/dist/core/dispatcher-hourly-check.js +665 -0
  179. package/dist/core/dispatcher-hourly-check.js.map +1 -0
  180. package/dist/core/dispatcher-message-handler.d.ts +170 -0
  181. package/dist/core/dispatcher-message-handler.d.ts.map +1 -0
  182. package/dist/core/dispatcher-message-handler.js +1064 -0
  183. package/dist/core/dispatcher-message-handler.js.map +1 -0
  184. package/dist/core/dispatcher-morning-routine.d.ts +169 -0
  185. package/dist/core/dispatcher-morning-routine.d.ts.map +1 -0
  186. package/dist/core/dispatcher-morning-routine.js +449 -0
  187. package/dist/core/dispatcher-morning-routine.js.map +1 -0
  188. package/dist/core/dispatcher-prompt.d.ts +107 -0
  189. package/dist/core/dispatcher-prompt.d.ts.map +1 -0
  190. package/dist/core/dispatcher-prompt.js +227 -0
  191. package/dist/core/dispatcher-prompt.js.map +1 -0
  192. package/dist/core/dispatcher-repository-helpers.d.ts +39 -0
  193. package/dist/core/dispatcher-repository-helpers.d.ts.map +1 -0
  194. package/dist/core/dispatcher-repository-helpers.js +86 -0
  195. package/dist/core/dispatcher-repository-helpers.js.map +1 -0
  196. package/dist/core/dispatcher-result-processor.d.ts +168 -0
  197. package/dist/core/dispatcher-result-processor.d.ts.map +1 -0
  198. package/dist/core/dispatcher-result-processor.js +533 -0
  199. package/dist/core/dispatcher-result-processor.js.map +1 -0
  200. package/dist/core/dispatcher-scheduled-tasks.d.ts +406 -0
  201. package/dist/core/dispatcher-scheduled-tasks.d.ts.map +1 -0
  202. package/dist/core/dispatcher-scheduled-tasks.js +1032 -0
  203. package/dist/core/dispatcher-scheduled-tasks.js.map +1 -0
  204. package/dist/core/dispatcher-types.d.ts +411 -0
  205. package/dist/core/dispatcher-types.d.ts.map +1 -0
  206. package/dist/core/dispatcher-types.js +106 -0
  207. package/dist/core/dispatcher-types.js.map +1 -0
  208. package/dist/core/dispatcher.d.ts +122 -610
  209. package/dist/core/dispatcher.d.ts.map +1 -1
  210. package/dist/core/dispatcher.js +365 -3521
  211. package/dist/core/dispatcher.js.map +1 -1
  212. package/dist/core/integration-health.d.ts +18 -10
  213. package/dist/core/integration-health.d.ts.map +1 -1
  214. package/dist/core/integration-health.js +31 -1
  215. package/dist/core/integration-health.js.map +1 -1
  216. package/dist/core/integration-lifecycle.d.ts +65 -0
  217. package/dist/core/integration-lifecycle.d.ts.map +1 -1
  218. package/dist/core/integration-lifecycle.js +163 -14
  219. package/dist/core/integration-lifecycle.js.map +1 -1
  220. package/dist/core/integration-main-backend.d.ts +40 -0
  221. package/dist/core/integration-main-backend.d.ts.map +1 -1
  222. package/dist/core/integration-main-backend.js +89 -2
  223. package/dist/core/integration-main-backend.js.map +1 -1
  224. package/dist/core/management-md.d.ts +51 -17
  225. package/dist/core/management-md.d.ts.map +1 -1
  226. package/dist/core/management-md.js +233 -56
  227. package/dist/core/management-md.js.map +1 -1
  228. package/dist/core/metrics.d.ts +127 -0
  229. package/dist/core/metrics.d.ts.map +1 -1
  230. package/dist/core/metrics.js +256 -1
  231. package/dist/core/metrics.js.map +1 -1
  232. package/dist/core/output-language-policy.d.ts +74 -0
  233. package/dist/core/output-language-policy.d.ts.map +1 -0
  234. package/dist/core/output-language-policy.js +194 -0
  235. package/dist/core/output-language-policy.js.map +1 -0
  236. package/dist/core/prompts.d.ts +3 -1
  237. package/dist/core/prompts.d.ts.map +1 -1
  238. package/dist/core/prompts.js +161 -3
  239. package/dist/core/prompts.js.map +1 -1
  240. package/dist/core/repository-management-docs.d.ts +24 -0
  241. package/dist/core/repository-management-docs.d.ts.map +1 -1
  242. package/dist/core/repository-management-docs.js +210 -26
  243. package/dist/core/repository-management-docs.js.map +1 -1
  244. package/dist/core/roadmap-validate.js +13 -1
  245. package/dist/core/roadmap-validate.js.map +1 -1
  246. package/dist/core/routine-acquisition-plan.d.ts +182 -0
  247. package/dist/core/routine-acquisition-plan.d.ts.map +1 -0
  248. package/dist/core/routine-acquisition-plan.js +367 -0
  249. package/dist/core/routine-acquisition-plan.js.map +1 -0
  250. package/dist/core/routine-fetch-window-retry.d.ts +109 -0
  251. package/dist/core/routine-fetch-window-retry.d.ts.map +1 -0
  252. package/dist/core/routine-fetch-window-retry.js +210 -0
  253. package/dist/core/routine-fetch-window-retry.js.map +1 -0
  254. package/dist/core/routine-fetch-window-runner.d.ts +427 -0
  255. package/dist/core/routine-fetch-window-runner.d.ts.map +1 -0
  256. package/dist/core/routine-fetch-window-runner.js +1591 -0
  257. package/dist/core/routine-fetch-window-runner.js.map +1 -0
  258. package/dist/core/routine-windows.d.ts +171 -0
  259. package/dist/core/routine-windows.d.ts.map +1 -0
  260. package/dist/core/routine-windows.js +377 -0
  261. package/dist/core/routine-windows.js.map +1 -0
  262. package/dist/core/scheduler.d.ts +50 -2
  263. package/dist/core/scheduler.d.ts.map +1 -1
  264. package/dist/core/scheduler.js +88 -7
  265. package/dist/core/scheduler.js.map +1 -1
  266. package/dist/core/skill-curation/declarations.d.ts.map +1 -1
  267. package/dist/core/skill-curation/declarations.js +11 -12
  268. package/dist/core/skill-curation/declarations.js.map +1 -1
  269. package/dist/core/skill-source-paths.d.ts +14 -0
  270. package/dist/core/skill-source-paths.d.ts.map +1 -0
  271. package/dist/core/skill-source-paths.js +82 -0
  272. package/dist/core/skill-source-paths.js.map +1 -0
  273. package/dist/core/skills-compiler.d.ts +29 -0
  274. package/dist/core/skills-compiler.d.ts.map +1 -1
  275. package/dist/core/skills-compiler.js +166 -30
  276. package/dist/core/skills-compiler.js.map +1 -1
  277. package/dist/core/skills-manifest.d.ts.map +1 -1
  278. package/dist/core/skills-manifest.js +72 -0
  279. package/dist/core/skills-manifest.js.map +1 -1
  280. package/dist/core/system-reset.d.ts +25 -0
  281. package/dist/core/system-reset.d.ts.map +1 -1
  282. package/dist/core/system-reset.js +72 -2
  283. package/dist/core/system-reset.js.map +1 -1
  284. package/dist/core/wiki/approval-queue.d.ts +31 -0
  285. package/dist/core/wiki/approval-queue.d.ts.map +1 -0
  286. package/dist/core/wiki/approval-queue.js +44 -0
  287. package/dist/core/wiki/approval-queue.js.map +1 -0
  288. package/dist/core/wiki/bridge.d.ts +74 -0
  289. package/dist/core/wiki/bridge.d.ts.map +1 -0
  290. package/dist/core/wiki/bridge.js +405 -0
  291. package/dist/core/wiki/bridge.js.map +1 -0
  292. package/dist/core/wiki/compile-lock.d.ts +42 -0
  293. package/dist/core/wiki/compile-lock.d.ts.map +1 -0
  294. package/dist/core/wiki/compile-lock.js +55 -0
  295. package/dist/core/wiki/compile-lock.js.map +1 -0
  296. package/dist/core/wiki/compile-preview.d.ts +8 -0
  297. package/dist/core/wiki/compile-preview.d.ts.map +1 -0
  298. package/dist/core/wiki/compile-preview.js +200 -0
  299. package/dist/core/wiki/compile-preview.js.map +1 -0
  300. package/dist/core/wiki/cost-estimate.d.ts +30 -0
  301. package/dist/core/wiki/cost-estimate.d.ts.map +1 -0
  302. package/dist/core/wiki/cost-estimate.js +243 -0
  303. package/dist/core/wiki/cost-estimate.js.map +1 -0
  304. package/dist/core/wiki/dispatcher.d.ts +48 -0
  305. package/dist/core/wiki/dispatcher.d.ts.map +1 -0
  306. package/dist/core/wiki/dispatcher.js +92 -0
  307. package/dist/core/wiki/dispatcher.js.map +1 -0
  308. package/dist/core/wiki/git-precompile.d.ts +86 -0
  309. package/dist/core/wiki/git-precompile.d.ts.map +1 -0
  310. package/dist/core/wiki/git-precompile.js +96 -0
  311. package/dist/core/wiki/git-precompile.js.map +1 -0
  312. package/dist/core/wiki/import-migrate.d.ts +38 -0
  313. package/dist/core/wiki/import-migrate.d.ts.map +1 -0
  314. package/dist/core/wiki/import-migrate.js +310 -0
  315. package/dist/core/wiki/import-migrate.js.map +1 -0
  316. package/dist/core/wiki/import-probe.d.ts +76 -0
  317. package/dist/core/wiki/import-probe.d.ts.map +1 -0
  318. package/dist/core/wiki/import-probe.js +245 -0
  319. package/dist/core/wiki/import-probe.js.map +1 -0
  320. package/dist/core/wiki/index-cache.d.ts +39 -0
  321. package/dist/core/wiki/index-cache.d.ts.map +1 -0
  322. package/dist/core/wiki/index-cache.js +152 -0
  323. package/dist/core/wiki/index-cache.js.map +1 -0
  324. package/dist/core/wiki/multi-url-dispatch.d.ts +52 -0
  325. package/dist/core/wiki/multi-url-dispatch.d.ts.map +1 -0
  326. package/dist/core/wiki/multi-url-dispatch.js +72 -0
  327. package/dist/core/wiki/multi-url-dispatch.js.map +1 -0
  328. package/dist/core/wiki/wiki-fts.d.ts +75 -0
  329. package/dist/core/wiki/wiki-fts.d.ts.map +1 -0
  330. package/dist/core/wiki/wiki-fts.js +265 -0
  331. package/dist/core/wiki/wiki-fts.js.map +1 -0
  332. package/dist/core/wiki/workspaces.d.ts +101 -0
  333. package/dist/core/wiki/workspaces.d.ts.map +1 -0
  334. package/dist/core/wiki/workspaces.js +352 -0
  335. package/dist/core/wiki/workspaces.js.map +1 -0
  336. package/dist/core/wiki/write-strategy.d.ts +70 -0
  337. package/dist/core/wiki/write-strategy.d.ts.map +1 -0
  338. package/dist/core/wiki/write-strategy.js +112 -0
  339. package/dist/core/wiki/write-strategy.js.map +1 -0
  340. package/dist/core/workdir.d.ts +8 -1
  341. package/dist/core/workdir.d.ts.map +1 -1
  342. package/dist/core/workdir.js +4 -1
  343. package/dist/core/workdir.js.map +1 -1
  344. package/dist/db/observations.d.ts +45 -2
  345. package/dist/db/observations.d.ts.map +1 -1
  346. package/dist/db/observations.js +112 -14
  347. package/dist/db/observations.js.map +1 -1
  348. package/dist/db/schema.d.ts.map +1 -1
  349. package/dist/db/schema.js +135 -25
  350. package/dist/db/schema.js.map +1 -1
  351. package/dist/db/wiki-store.d.ts +3 -0
  352. package/dist/db/wiki-store.d.ts.map +1 -0
  353. package/dist/db/wiki-store.js +7 -0
  354. package/dist/db/wiki-store.js.map +1 -0
  355. package/dist/index.js +159 -610
  356. package/dist/index.js.map +1 -1
  357. package/dist/messaging/url-extract.d.ts +8 -0
  358. package/dist/messaging/url-extract.d.ts.map +1 -0
  359. package/dist/messaging/url-extract.js +41 -0
  360. package/dist/messaging/url-extract.js.map +1 -0
  361. package/dist/observers/delegated-sync-worker.d.ts +52 -1
  362. package/dist/observers/delegated-sync-worker.d.ts.map +1 -1
  363. package/dist/observers/delegated-sync-worker.js +75 -18
  364. package/dist/observers/delegated-sync-worker.js.map +1 -1
  365. package/dist/observers/imminent-event-scheduler.d.ts +20 -7
  366. package/dist/observers/imminent-event-scheduler.d.ts.map +1 -1
  367. package/dist/observers/imminent-event-scheduler.js +134 -29
  368. package/dist/observers/imminent-event-scheduler.js.map +1 -1
  369. package/dist/observers/mail-poller.d.ts +12 -5
  370. package/dist/observers/mail-poller.d.ts.map +1 -1
  371. package/dist/observers/mail-poller.js +36 -14
  372. package/dist/observers/mail-poller.js.map +1 -1
  373. package/dist/observers/manager.d.ts +37 -5
  374. package/dist/observers/manager.d.ts.map +1 -1
  375. package/dist/observers/manager.js +28 -10
  376. package/dist/observers/manager.js.map +1 -1
  377. package/dist/safety/always-disallowed.d.ts +65 -0
  378. package/dist/safety/always-disallowed.d.ts.map +1 -1
  379. package/dist/safety/always-disallowed.js +106 -10
  380. package/dist/safety/always-disallowed.js.map +1 -1
  381. package/dist/safety/audit.d.ts +46 -1
  382. package/dist/safety/audit.d.ts.map +1 -1
  383. package/dist/safety/audit.js +79 -16
  384. package/dist/safety/audit.js.map +1 -1
  385. package/dist/safety/risk-classifier.d.ts.map +1 -1
  386. package/dist/safety/risk-classifier.js +29 -0
  387. package/dist/safety/risk-classifier.js.map +1 -1
  388. package/dist/services/delegated-backend-invoker.d.ts +1 -51
  389. package/dist/services/delegated-backend-invoker.d.ts.map +1 -1
  390. package/dist/services/delegated-backend-invoker.js +41 -480
  391. package/dist/services/delegated-backend-invoker.js.map +1 -1
  392. package/dist/services/delegated-invoker-audit.d.ts +94 -0
  393. package/dist/services/delegated-invoker-audit.d.ts.map +1 -0
  394. package/dist/services/delegated-invoker-audit.js +238 -0
  395. package/dist/services/delegated-invoker-audit.js.map +1 -0
  396. package/dist/services/delegated-invoker-cache-hits.d.ts +34 -0
  397. package/dist/services/delegated-invoker-cache-hits.d.ts.map +1 -0
  398. package/dist/services/delegated-invoker-cache-hits.js +104 -0
  399. package/dist/services/delegated-invoker-cache-hits.js.map +1 -0
  400. package/dist/services/delegated-invoker-janitors.d.ts +28 -0
  401. package/dist/services/delegated-invoker-janitors.d.ts.map +1 -0
  402. package/dist/services/delegated-invoker-janitors.js +104 -0
  403. package/dist/services/delegated-invoker-janitors.js.map +1 -0
  404. package/dist/services/delegated-invoker-utils.d.ts +42 -0
  405. package/dist/services/delegated-invoker-utils.d.ts.map +1 -0
  406. package/dist/services/delegated-invoker-utils.js +100 -0
  407. package/dist/services/delegated-invoker-utils.js.map +1 -0
  408. package/dist/services/delegated-task-runtime.d.ts +1 -1
  409. package/dist/services/delegated-task-runtime.js +1 -1
  410. package/dist/services/integrations/snapshot-partitions.d.ts +5 -0
  411. package/dist/services/integrations/snapshot-partitions.d.ts.map +1 -1
  412. package/dist/services/integrations/snapshot-partitions.js +12 -0
  413. package/dist/services/integrations/snapshot-partitions.js.map +1 -1
  414. package/dist/services/voice/transcriber-impl.d.ts.map +1 -1
  415. package/dist/services/voice/transcriber-impl.js +7 -8
  416. package/dist/services/voice/transcriber-impl.js.map +1 -1
  417. package/dist/settings/runtime-settings.d.ts +12 -1
  418. package/dist/settings/runtime-settings.d.ts.map +1 -1
  419. package/dist/settings/runtime-settings.js +59 -1
  420. package/dist/settings/runtime-settings.js.map +1 -1
  421. package/package.json +2 -2
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Retry-policy helpers for the pre-pass fan-out coordinator.
3
+ *
4
+ * PRE_PASS_FAN_OUT_DESIGN.md §4.4 — the coordinator spawns a fresh Haiku
5
+ * sub-session per attempt and consults `defaultRetryDecision` (or any
6
+ * `RetryDecisionFn`) between attempts to choose whether to spawn the
7
+ * next one. Keeping the policy as pure data (decision matrix in
8
+ * TypeScript, not in agent prose) makes the loop deterministic,
9
+ * testable, and free of per-model variance.
10
+ *
11
+ * Phase 0 ships these helpers + their unit tests. The fan-out
12
+ * coordinator that consumes them lands in Phase 1.
13
+ */
14
+ // ── Decision matrix (PRE_PASS_FAN_OUT_DESIGN.md §4.4) ─────────────────────
15
+ /**
16
+ * Stable reason identifiers. Centralised so the dashboard / audit feed
17
+ * can render them consistently and so test assertions don't drift from
18
+ * runtime values.
19
+ */
20
+ export const RETRY_REASONS = {
21
+ MAX_ATTEMPTS: "max-attempts-reached",
22
+ BUDGET_CAP: "per-integration-budget-cap",
23
+ FLIP_LOCKED: "flip-locked",
24
+ BUDGET_EXHAUSTED: "budget-exhausted",
25
+ AUTH_FAILED: "auth-failed",
26
+ FAILED_STATUS: "failed-status",
27
+ UPSTREAM_5XX: "upstream-5xx",
28
+ PARTIAL_NO_POST: "partial-no-post",
29
+ SUCCESS: "success",
30
+ PARTIAL_WITH_POST: "partial-with-progress",
31
+ SKIPPED: "skipped",
32
+ NO_PROGRESS: "no-progress",
33
+ };
34
+ /**
35
+ * Sum the cost across `priorAttempts` + the current `report`. Pure;
36
+ * exported for unit testing the budget-cap branch in isolation.
37
+ */
38
+ export function cumulativeAttemptCost(report, priorAttempts) {
39
+ let total = report.costUsd;
40
+ for (const att of priorAttempts)
41
+ total += att.costUsd;
42
+ return total;
43
+ }
44
+ function isFetchFailedWithStatus(err, predicate) {
45
+ if (err.type !== "fetch-failed")
46
+ return false;
47
+ // `status` may arrive as number or string — MCP transports stringify
48
+ // upstream HTTP codes inconsistently.
49
+ const raw = err.status;
50
+ const status = typeof raw === "number"
51
+ ? raw
52
+ : typeof raw === "string" && /^\d+$/.test(raw)
53
+ ? Number.parseInt(raw, 10)
54
+ : NaN;
55
+ if (Number.isNaN(status))
56
+ return false;
57
+ return predicate(status);
58
+ }
59
+ /**
60
+ * Default retry policy from §4.4. Pure: decision is fully determined by
61
+ * the inputs, no side effects, no shared state. Decision order:
62
+ *
63
+ * 1. Attempts cap (no retry, reason `max-attempts-reached`).
64
+ * 2. Per-integration cumulative budget cap.
65
+ * 3. Terminal error classes — flip-lock, budget-exhausted, auth (401/403).
66
+ * 4. Retry-worthy outcomes — failed status, upstream 5xx, partial-no-post.
67
+ * 5. Non-retry-by-default — success, partial-with-progress, skipped, no-progress.
68
+ *
69
+ * The motivating §1.1 failure ("Unknown name "limit"") lands
70
+ * as `status="partial"` with `fetched > 0`, `posted === 0` and a
71
+ * `fetch-failed` error — rule (4)'s `partial-no-post` branch catches it.
72
+ */
73
+ export const defaultRetryDecision = (report, attempt, policy, priorAttempts) => {
74
+ // (1) Attempts cap — the loop body checks this before spawning attempt N+1.
75
+ if (attempt >= policy.maxAttempts) {
76
+ return { retry: false, reason: RETRY_REASONS.MAX_ATTEMPTS };
77
+ }
78
+ // (2) Cumulative cost cap. Compare against the cost AFTER recording
79
+ // this attempt; if it's already at/over the cap, no point retrying.
80
+ const cumulative = cumulativeAttemptCost(report, priorAttempts);
81
+ if (cumulative >= policy.perIntegrationBudgetUsd) {
82
+ return { retry: false, reason: RETRY_REASONS.BUDGET_CAP };
83
+ }
84
+ // (3) Terminal error classes — first match wins.
85
+ for (const err of report.errors) {
86
+ if (err.type === "flip-locked") {
87
+ return { retry: false, reason: RETRY_REASONS.FLIP_LOCKED };
88
+ }
89
+ if (err.type === "budget-exhausted") {
90
+ return { retry: false, reason: RETRY_REASONS.BUDGET_EXHAUSTED };
91
+ }
92
+ if (isFetchFailedWithStatus(err, (s) => s === 401 || s === 403)) {
93
+ return { retry: false, reason: RETRY_REASONS.AUTH_FAILED };
94
+ }
95
+ }
96
+ // (4) Retry-worthy.
97
+ if (report.status === "failed") {
98
+ return { retry: true, reason: RETRY_REASONS.FAILED_STATUS };
99
+ }
100
+ for (const err of report.errors) {
101
+ if (isFetchFailedWithStatus(err, (s) => s >= 500 && s < 600)) {
102
+ return { retry: true, reason: RETRY_REASONS.UPSTREAM_5XX };
103
+ }
104
+ }
105
+ if (policy.retryOnPartial !== false
106
+ &&
107
+ report.status === "partial"
108
+ && report.posted === 0
109
+ && report.fetched > 0) {
110
+ return { retry: true, reason: RETRY_REASONS.PARTIAL_NO_POST };
111
+ }
112
+ // (5) Non-retry-by-default outcomes.
113
+ if (report.status === "success") {
114
+ return { retry: false, reason: RETRY_REASONS.SUCCESS };
115
+ }
116
+ if (report.status === "partial" && report.posted > 0) {
117
+ return { retry: false, reason: RETRY_REASONS.PARTIAL_WITH_POST };
118
+ }
119
+ if (report.status === "skipped") {
120
+ return { retry: false, reason: RETRY_REASONS.SKIPPED };
121
+ }
122
+ // Partial with fetched=0 and posted=0 — every fetch errored before
123
+ // returning items. The spec's matrix doesn't list this case; default
124
+ // to no-retry to keep the policy conservative (the §1.1 motivating
125
+ // failure is partial-no-post WITH fetched>0, which is already caught
126
+ // above). Operators who see this case in telemetry can override via
127
+ // `RetryPolicy.retryOn`.
128
+ return { retry: false, reason: RETRY_REASONS.NO_PROGRESS };
129
+ };
130
+ // ── Prior-attempt hint rendering (PRE_PASS_FAN_OUT_DESIGN.md §4.4) ────────
131
+ function xmlAttr(value) {
132
+ return value
133
+ .replace(/&/g, "&amp;")
134
+ .replace(/"/g, "&quot;")
135
+ .replace(/</g, "&lt;")
136
+ .replace(/>/g, "&gt;");
137
+ }
138
+ function xmlText(value) {
139
+ return value
140
+ .replace(/&/g, "&amp;")
141
+ .replace(/</g, "&lt;")
142
+ .replace(/>/g, "&gt;");
143
+ }
144
+ /**
145
+ * Generic MVP hint prose. §4.4 calls out the OQ-3 upgrade path
146
+ * (schema-aware classifier that promotes the hint to a specific
147
+ * substitution, e.g. `limit` → `maxResults`); the MVP stays generic so
148
+ * the hint-builder is not coupled to upstream argument-name schemas
149
+ * that drift independently.
150
+ */
151
+ const GENERIC_HINT_PROSE = "The previous attempt's call returned the error above. Re-read the partial body and try a different argument shape — the partial is the source of truth for tool argument names, not your memory of prior calls.";
152
+ function pickFirstError(errors) {
153
+ return errors.length > 0 ? errors[0] : undefined;
154
+ }
155
+ function renderErrorChild(err) {
156
+ const type = typeof err.type === "string" ? err.type : "unknown";
157
+ // Surface every string/number attribute (other than `type`) so the
158
+ // motivating §1.1 case carries `status="400"` and `message="…"`
159
+ // verbatim into the next attempt's prompt.
160
+ const attrEntries = Object.entries(err).filter(([k, v]) => k !== "type" && (typeof v === "string" || typeof v === "number"));
161
+ const attrs = attrEntries
162
+ .map(([k, v]) => `${xmlAttr(k)}="${xmlAttr(String(v))}"`)
163
+ .join(" ");
164
+ const tagName = xmlAttr(type.replace(/-/g, "_"));
165
+ return `<${tagName}${attrs ? " " + attrs : ""} />`;
166
+ }
167
+ function renderOnePriorAttempt(record, integrationKey) {
168
+ const openParts = [`attempt="${record.attempt}"`];
169
+ if (integrationKey !== undefined) {
170
+ openParts.push(`integration="${xmlAttr(integrationKey)}"`);
171
+ }
172
+ const lines = [`<prior_attempt_error ${openParts.join(" ")}>`];
173
+ const firstErr = pickFirstError(record.errors);
174
+ if (firstErr) {
175
+ lines.push(` ${renderErrorChild(firstErr)}`);
176
+ }
177
+ else if (record.parseError) {
178
+ lines.push(` <parse_failed reason="${xmlAttr(record.parseError)}" />`);
179
+ }
180
+ else {
181
+ // The attempt was retried but carried neither an explicit error nor
182
+ // a parseError — likely a coordinator-side timeout or quota error
183
+ // logged as a generic failed-status. Surface that explicitly so the
184
+ // model knows *something* went wrong, not just that retry was
185
+ // selected silently.
186
+ lines.push(` <failed status="${xmlAttr(record.status)}" />`);
187
+ }
188
+ lines.push(` <hint>${xmlText(GENERIC_HINT_PROSE)}</hint>`);
189
+ lines.push("</prior_attempt_error>");
190
+ return lines.join("\n");
191
+ }
192
+ /**
193
+ * Render the `<prior_attempt_error>` block sequence injected into a
194
+ * sub-session's prompt on attempt > 1. Returns the empty string when
195
+ * `attempts` is empty so callers can unconditionally concatenate the
196
+ * result.
197
+ *
198
+ * **Ordering.** Newest first — attempt N (most recent) appears before
199
+ * attempt N-1, etc. The model reads the most-recent failure top of
200
+ * page; deeper history is context-only.
201
+ */
202
+ export function buildPriorAttemptHintBlock(attempts, integrationKey) {
203
+ if (attempts.length === 0)
204
+ return "";
205
+ const newestFirst = [...attempts].reverse();
206
+ return newestFirst
207
+ .map((att) => renderOnePriorAttempt(att, integrationKey))
208
+ .join("\n");
209
+ }
210
+ //# sourceMappingURL=routine-fetch-window-retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routine-fetch-window-retry.js","sourceRoot":"","sources":["../../src/core/routine-fetch-window-retry.ts"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B,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAChE,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,WAAW,OAAO,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC5D,KAAK,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IACrC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,0BAA0B,CACxC,QAAqC,EACrC,cAA+B;IAE/B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,MAAM,WAAW,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;IAC5C,OAAO,WAAW;SACf,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,qBAAqB,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;SACxD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
@@ -0,0 +1,427 @@
1
+ /**
2
+ * `RoutineFetchWindowRunner` — pre-pass fan-out coordinator.
3
+ *
4
+ * ROUTINE_DATA_ACQUISITION_DESIGN.md §6.1.1 + PRE_PASS_FAN_OUT_DESIGN.md
5
+ * — every routine dispatcher (morning_routine, today_refresh,
6
+ * hourly_check, evening / weekly / monthly review) calls this runner
7
+ * immediately before dispatching the parent session. The runner:
8
+ *
9
+ * 1. Reads the per-routine plan from `ROUTINE_WINDOWS` and the current
10
+ * integration state, fans rows out per-account where applicable,
11
+ * resolves each row's predicate (`direct` / `delegated-same` /
12
+ * `delegated-cross` / `native` / skip), and partitions the plan
13
+ * by `IntegrationKey` via `splitAcquisitionPlanByIntegration`.
14
+ * 2. Spawns one lite-tier `routine.fetch_window` sub-session per
15
+ * integration in parallel (bounded by `prePassFanOutConcurrency`).
16
+ * Each sub-session sees exactly one partial — the
17
+ * `{integration_partial}` placeholder in the
18
+ * `routine.fetch_window` task-flow is replaced with the body of
19
+ * `_partials/<integration prePassPartial>` so the lite-tier model
20
+ * never has to disambiguate cross-API argument names. Each
21
+ * sub-session runs through an independent retry loop bounded by
22
+ * `prePassMaxAttemptsPerIntegration`, `prePassBackoffMs`, and the
23
+ * per-integration / per-routine USD budget caps.
24
+ * 3. Merges the sub-reports into a single `FetchReport` (additive
25
+ * `<integration>` children on the `<fetch_report>` XML block) and
26
+ * returns it plus the rendered block.
27
+ * 4. The caller grafts the block into the **parent** routine event's
28
+ * `event.data.fetchReportBlock`. ContextBuilder injects it verbatim
29
+ * into the parent session's prompt (mirrors the `<gate_decision>`
30
+ * pattern used by hourly_check Stage 3).
31
+ *
32
+ * Failure-mode contract (PRE_PASS_FAN_OUT_DESIGN.md §5):
33
+ *
34
+ * - **No applicable rows** (routine has no windows in `ROUTINE_WINDOWS`,
35
+ * every integration is disabled, every account list is empty) — the
36
+ * runner returns an empty `<fetch_report>` with `status="skipped"` and
37
+ * `fetched=posted=duplicates=0`. The parent routine still runs; the
38
+ * block is informational only.
39
+ * - **Pre-pass session errors** (binding resolve fails, agent throws,
40
+ * JSON parse fails) — recorded per-attempt; the retry loop fires up
41
+ * to `maxAttempts` before giving up. Final per-integration status
42
+ * surfaces in `<integration status="failed">`. Pre-pass cost gains
43
+ * are forfeit for that integration; siblings are unaffected.
44
+ * Throwing here would otherwise propagate up and abort the parent
45
+ * routine — the opposite of P3 ("Lite for Fetch, Medium for Decide").
46
+ * - **Partial success** — the report's `errors` array carries per-row
47
+ * failures (`no-surface`, `fetch-failed`, `budget-exhausted`,
48
+ * `budget-cap`, `global-budget-cap`). The block surfaces them so the
49
+ * parent prompt can decide whether to treat its observations view as
50
+ * complete.
51
+ */
52
+ import type Database from "better-sqlite3";
53
+ import type { BackendId, Event, IntegrationKey, IntegrationState } from "@aitne/shared";
54
+ import type { AgentConfig } from "../config.js";
55
+ import type { MailAccount } from "../services/mail/provider.js";
56
+ import type { IAgentRouter } from "./backends/backend-router.js";
57
+ import type { IAuditLogger, IContextBuilder } from "./dispatcher-types.js";
58
+ import type { PromptAssembler } from "./dispatcher-prompt.js";
59
+ import { type RoutineWindowKey } from "./routine-windows.js";
60
+ /**
61
+ * Structured form of the agent's single-line JSON output. Matches the
62
+ * contract in `agent-profiles/routine-fetch-window.md`:
63
+ *
64
+ * ```json
65
+ * {"fetched": <int>, "posted": <int>, "duplicates": <int>, "errors": [...]}
66
+ * ```
67
+ *
68
+ * `status` is the runner's classification of the run — `success` /
69
+ * `partial` (any errors) / `failed` (parse / agent / dispatch failure) /
70
+ * `skipped` (no applicable rows). Persisted in the `<fetch_report>`
71
+ * block so the parent routine can branch deterministically without
72
+ * re-counting the errors array.
73
+ */
74
+ export interface FetchReport {
75
+ status: "success" | "partial" | "failed" | "skipped";
76
+ fetched: number;
77
+ posted: number;
78
+ duplicates: number;
79
+ errors: ReadonlyArray<Record<string, unknown>>;
80
+ /** True when the runner skipped dispatching a session entirely. */
81
+ skipped: boolean;
82
+ /** Set when status === "failed" — the message captured in the audit row. */
83
+ failureReason?: string;
84
+ /** Stable ID for telemetry tie-back; mirrors the fetcher event's correlationId. */
85
+ fetcherCorrelationId?: string;
86
+ /**
87
+ * PRE_PASS_FAN_OUT_DESIGN.md §4.5 — per-integration breakdown. Top-level
88
+ * counts above already aggregate the children; the breakdown lets
89
+ * downstream consumers (parent task-flow prose, dashboard renderers)
90
+ * branch per integration. Absent on the `skipped` / `failed` paths
91
+ * that short-circuit before fan-out (no-routine-key, no-windows,
92
+ * empty plan, plan-assembly-failed).
93
+ */
94
+ perIntegration?: ReadonlyArray<SubReport>;
95
+ }
96
+ /**
97
+ * PRE_PASS_FAN_OUT_DESIGN.md §4.3 — one attempt of one integration's
98
+ * sub-session. The fan-out coordinator records one of these per
99
+ * `agentRouter.execute` invocation; `defaultRetryDecision` consumes
100
+ * the latest record to decide whether to spawn another attempt.
101
+ */
102
+ export interface SubAttemptRecord {
103
+ /** 1-indexed. */
104
+ attempt: number;
105
+ status: FetchReport["status"];
106
+ fetched: number;
107
+ posted: number;
108
+ duplicates: number;
109
+ errors: ReadonlyArray<Record<string, unknown>>;
110
+ /** Set when the agent's output failed strict-JSON parse. */
111
+ parseError?: string;
112
+ fetcherCorrelationId: string;
113
+ /** ISO 8601 UTC. */
114
+ startedAt: string;
115
+ /** ISO 8601 UTC. */
116
+ endedAt: string;
117
+ costUsd: number;
118
+ numTurns: number;
119
+ }
120
+ /**
121
+ * PRE_PASS_FAN_OUT_DESIGN.md §4.3 — final per-integration verdict the
122
+ * coordinator emits after its retry loop terminates. Mirrors the
123
+ * fields of the last `SubAttemptRecord` (the final attempt's outcome
124
+ * is the integration's effective outcome) plus the integration key
125
+ * and the full attempt history.
126
+ */
127
+ export interface SubReport extends SubAttemptRecord {
128
+ integrationKey: IntegrationKey;
129
+ /** Full attempt history; `attempts[attempts.length - 1]` matches the inherited fields. */
130
+ attempts: ReadonlyArray<SubAttemptRecord>;
131
+ /**
132
+ * True iff the loop exhausted `maxAttempts` (or a budget/global cap
133
+ * tripped) without reaching a non-retryable success state.
134
+ */
135
+ retriesExhausted: boolean;
136
+ }
137
+ export interface RoutineFetchWindowResult {
138
+ report: FetchReport;
139
+ /** XML block to graft into the parent routine event's `event.data.fetchReportBlock`. */
140
+ block: string;
141
+ }
142
+ export interface RoutineFetchWindowRunnerDeps {
143
+ db: Database.Database;
144
+ config: AgentConfig;
145
+ contextBuilder: IContextBuilder;
146
+ agentRouter: IAgentRouter;
147
+ audit: IAuditLogger;
148
+ prompt: PromptAssembler;
149
+ /**
150
+ * Returns the active mail account list — used to fan rows out per
151
+ * account when `RoutineWindowSpec.perAccount === true`. Threads the
152
+ * dispatcher's existing `getActiveMailAccounts` closure so the runner
153
+ * doesn't need to depend on the registry directly.
154
+ */
155
+ getActiveMailAccounts: () => readonly MailAccount[];
156
+ /**
157
+ * Lazy accessor for the dashboard SSE event broadcaster (A2 / B2
158
+ * observability extension). When set, the runner emits
159
+ * `kind: "prepass_started"` / `"prepass_completed"` payloads to the
160
+ * default `event` SSE channel so the setup wizard can render the
161
+ * "Fetching your mail and Notion data…" sub-step distinctly from
162
+ * the parent routine's `routine_started` / `routine_completed`
163
+ * envelope. Returns `null` when the dispatcher has not wired a
164
+ * broadcaster yet (test paths, headless installs); the runner
165
+ * treats every call as fire-and-forget and never propagates a
166
+ * broadcaster failure into the parent dispatch.
167
+ *
168
+ * Optional — when undefined the runner runs exactly as it did
169
+ * pre-A2, including the empty-plan short-circuit.
170
+ */
171
+ getEventBroadcaster?: () => {
172
+ broadcastEvent: (data: unknown) => void;
173
+ } | null;
174
+ }
175
+ /**
176
+ * Compose the per-execute `allowedToolsOverride` for the pre-pass. The
177
+ * override REPLACES the SDK's default allowlist (no union per
178
+ * claude-code-core.ts:437) so the list must be exhaustive for every
179
+ * surface the partials use under any (integration, mode) cell. Mode
180
+ * coverage:
181
+ *
182
+ * - `direct`: daemon REST → curl prefix.
183
+ * - `delegated-same`: session backend MCP → integration tool name.
184
+ * - `delegated-cross`: daemon delegation proxy → curl prefix
185
+ * (`/api/integrations/<key>/exec`).
186
+ * - `native` (descriptor-bound): session backend MCP → integration
187
+ * tool name.
188
+ * - `native` (user-managed) / no-surface: nothing in the override —
189
+ * the partial records `no-surface` and the runner's report carries
190
+ * the gap forward to the parent routine.
191
+ *
192
+ * `ToolSearch` is appended for Claude sessions whenever at least one
193
+ * descriptor-bound MCP tool is present. Claude Code 2.1+ defers large
194
+ * MCP tool manifests (`mcp__claude_ai_Gmail__*`,
195
+ * `mcp__claude_ai_Google_Calendar__*`, `mcp__claude_ai_Notion__*`, …)
196
+ * behind `ToolSearch`, so the model must call `ToolSearch` to load a
197
+ * deferred tool's schema before it can be invoked. Without `ToolSearch`
198
+ * allowed, the Haiku fetcher emits a denied ToolSearch call on its
199
+ * first turn, gives up, and returns text with no JSON — the parent
200
+ * routine then sees `<fetch_report status="failed" reason="no-json-object">`.
201
+ * Mirrors the same workaround in `claude-delegated.ts` (delegated proxy
202
+ * `allowedTools: [toolName, "ToolSearch"]`). Codex / Gemini have no
203
+ * per-spawn allowedTools surface today and ignore the override entirely
204
+ * (CLAUDE.md acknowledges the gap), so the `ToolSearch` widening is
205
+ * gated on `sessionBackend === "claude"` to keep the list minimal for
206
+ * other backends.
207
+ *
208
+ * Exported for unit testing — the runner consumes it via
209
+ * `composePrePassAllowedTools` at dispatch time.
210
+ */
211
+ export declare function composePrePassAllowedTools(apiPort: number, integrations: Partial<Record<IntegrationKey, IntegrationState>>, sessionBackend: BackendId): readonly string[];
212
+ /**
213
+ * Derive the canonical `RoutineWindowKey` from a routine event. The
214
+ * caller's intent is conveyed by `event.type` (always `routine.<name>`),
215
+ * with `RoutineEvent.routine` carrying the same suffix without the
216
+ * `routine.` prefix. Returns null for routines outside the catalog so
217
+ * the caller can short-circuit before touching plan assembly.
218
+ */
219
+ export declare function routineWindowKeyFromEvent(event: Event): RoutineWindowKey | null;
220
+ /**
221
+ * Walk `text` and return every balanced `{...}` slice (top-level objects
222
+ * only; nested braces are honoured). Strings are tracked so brace
223
+ * characters inside `"..."` literals don't unbalance the scan. Used by
224
+ * `parseFetchWindowOutput` to pick the LAST top-level object on stdout —
225
+ * agents occasionally emit a think-aloud line carrying a JSON snippet
226
+ * before the verdict, and the fetcher's contract is "the last
227
+ * top-level JSON object wins."
228
+ *
229
+ * Exported for direct unit testing; the runner consumes it via
230
+ * `parseFetchWindowOutput`.
231
+ */
232
+ export declare function extractBalancedJsonObjects(text: string): string[];
233
+ /** Strict-JSON parse of the fetcher's single-line output. */
234
+ export declare function parseFetchWindowOutput(output: string): FetchReport | {
235
+ parseError: string;
236
+ };
237
+ /**
238
+ * Render the `<fetch_report>` XML block injected into the parent
239
+ * routine's prompt. Keep the schema narrow — every additional attribute
240
+ * costs prompt tokens on the cache-warm parent session.
241
+ *
242
+ * `meta.routine` accepts any string so the no-routine-key skip path can
243
+ * render the parent event's actual type (e.g. `routine.skill_curation`)
244
+ * instead of borrowing a catalog entry as a placeholder. The renderer
245
+ * strips the `routine.` prefix verbatim — callers may pass either the
246
+ * fully-qualified ProcessKey or a bare suffix.
247
+ */
248
+ export declare function renderFetchReportBlock(report: FetchReport, meta: {
249
+ routine: RoutineWindowKey | string;
250
+ agentDay: string;
251
+ }): string;
252
+ /**
253
+ * Resolve the aggregate `<fetch_report>` status from a set of
254
+ * sub-reports' final statuses, per §4.5:
255
+ *
256
+ * - `success` iff every non-skipped sub-report is `success`. Skipped
257
+ * sub-reports do not count against success.
258
+ * - `failed` iff every non-skipped sub-report is `failed`.
259
+ * - `partial` for any other mix (incl. one success + one failed).
260
+ * - `skipped` only when the input is empty (the caller handles
261
+ * "every sub-report skipped" separately — the runner short-circuits
262
+ * before fan-out when no integrations are active).
263
+ *
264
+ * Exported for unit testing the status-resolution branch in isolation.
265
+ */
266
+ export declare function aggregateFanOutStatus(subReports: readonly SubReport[]): FetchReport["status"];
267
+ /** Headline numbers for one integration's full retry chain. */
268
+ export interface IntegrationSummary {
269
+ key: IntegrationKey;
270
+ status: FetchReport["status"];
271
+ attempts: number;
272
+ fetched: number;
273
+ posted: number;
274
+ duplicates: number;
275
+ costUsd: number;
276
+ durationMs: number;
277
+ /** Set only when status === "failed"; first error message of final attempt. */
278
+ finalError?: string;
279
+ }
280
+ /** Headline numbers for the whole fan-out routine. */
281
+ export interface AggregateSummary {
282
+ status: FetchReport["status"];
283
+ fetched: number;
284
+ posted: number;
285
+ duplicates: number;
286
+ costUsd: number;
287
+ }
288
+ export declare function summarizeIntegrationReport(sub: SubReport): IntegrationSummary;
289
+ export declare function summarizeFetchReport(report: FetchReport): AggregateSummary;
290
+ /**
291
+ * Merge fan-out sub-reports into a single `FetchReport` + the rendered
292
+ * `<fetch_report>` XML block the parent routine sees. §4.5.
293
+ *
294
+ * - Counts (`fetched`, `posted`, `duplicates`): arithmetic sum.
295
+ * - `errors`: concatenation, each error tagged with
296
+ * `integration: <key>` (and the per-attempt rows already carry
297
+ * `attempt: <n>` via the runner's per-attempt error-recording —
298
+ * `mergeSubReports` does not invent annotations beyond `integration`).
299
+ * - `status`: `aggregateFanOutStatus`.
300
+ * - `failureReason`: only when aggregate is `failed`; one-line summary
301
+ * listing the failed integrations and their attempt counts.
302
+ * - `perIntegration`: sorted by `INTEGRATION_KEYS` order regardless of
303
+ * completion order (deterministic — §4.6).
304
+ *
305
+ * Pure function: no side effects, no DB / clock dependencies.
306
+ */
307
+ export declare function mergeSubReports(subReports: readonly SubReport[], routine: RoutineWindowKey | string, agentDay: string): {
308
+ report: FetchReport;
309
+ block: string;
310
+ };
311
+ export declare class RoutineFetchWindowRunner {
312
+ private readonly db;
313
+ private readonly config;
314
+ private readonly contextBuilder;
315
+ private readonly agentRouter;
316
+ private readonly audit;
317
+ private readonly prompt;
318
+ private readonly getActiveMailAccounts;
319
+ private readonly getEventBroadcaster;
320
+ constructor(deps: RoutineFetchWindowRunnerDeps);
321
+ /**
322
+ * Broadcast a single pre-pass progress event to the dashboard SSE
323
+ * channel. Failure is contained — the broadcaster contract is
324
+ * fire-and-forget and a misbehaving writer must not affect the
325
+ * runner's return value or the parent routine's dispatch.
326
+ *
327
+ * Schema (default `event` SSE channel, matches existing
328
+ * `kind: "main_backend_changed"` / `"routine_started"` pattern):
329
+ * { kind, routine, source, correlationId, timestamp, status? }
330
+ * `status` is set on `prepass_completed` only and reflects the
331
+ * FetchReport.status field (success / partial / failed / skipped).
332
+ */
333
+ private broadcastPrepassProgress;
334
+ /**
335
+ * Execute the pre-pass for `parentEvent`. Returns the fetch report
336
+ * and rendered `<fetch_report>` block; callers graft the block into
337
+ * the parent event's `event.data.fetchReportBlock` so ContextBuilder
338
+ * injects it into the parent prompt.
339
+ *
340
+ * `routineKey` overrides the auto-derived window key — used by
341
+ * morning_routine to opt into `routine.morning_routine_initial`'s
342
+ * plan when `yesterday.md` is absent (their plans currently coincide,
343
+ * but the seam exists for future divergence).
344
+ */
345
+ run(parentEvent: Event, routineKey?: RoutineWindowKey): Promise<RoutineFetchWindowResult>;
346
+ private runImpl;
347
+ private buildFanOutPlanContext;
348
+ /**
349
+ * §5 BackendQuotaError row + §4.4 retryEscalationTier — re-derive the
350
+ * per-integration sub-plan against the CURRENT attempt's binding so a
351
+ * cross-backend swap (escalation tier flips main backend, or
352
+ * `prePassRetryEscalationTier` swaps the per-attempt tier) keeps the
353
+ * plan's `<fetch mode="…">` attribute aligned with the partial body's
354
+ * remaining mode-branch (the partial is filtered for the new backend
355
+ * via `renderPartialForFanOut`). Returns null only when the
356
+ * integration becomes unreachable on the new backend (e.g. native
357
+ * mode bound to A but the attempt re-resolves to B); the runner
358
+ * passes the call through to record the original sub-plan and let
359
+ * the agent emit `no-surface` errors organically.
360
+ *
361
+ * Pure: snapshot inputs (`integrationsSnapshot`, `accounts`,
362
+ * `timestamps`) are frozen at run() entry; only `sessionBackend`
363
+ * varies across attempts. Re-derivation is cheap —
364
+ * `splitAcquisitionPlanByIntegration` walks `ROUTINE_WINDOWS[routine]`
365
+ * (a small constant) without I/O.
366
+ */
367
+ private rebuildSubPlanForBackend;
368
+ private buildRetryPolicy;
369
+ private fanOutConcurrency;
370
+ private retryEscalationTier;
371
+ private runFanOut;
372
+ private runOneIntegrationWithRetry;
373
+ /**
374
+ * Emit `prepass_subsession_started` for an attempt that is about to run.
375
+ * Called at the TOP of every loop iteration so the started/completed
376
+ * pair is symmetric across all paths — including binding-resolve-failed
377
+ * and budget-cap short-circuits, which previously emitted neither.
378
+ */
379
+ private emitSubSessionStarted;
380
+ /**
381
+ * Emit `prepass_subsession_completed` for an attempt that has just
382
+ * recorded its outcome. Mirror of `emitSubSessionStarted` — invoked
383
+ * once per iteration after every code path that pushes a record
384
+ * (success, parse error, agent throw, binding-resolve-failed,
385
+ * global-budget-cap, per-integration-budget-cap).
386
+ */
387
+ private emitSubSessionCompleted;
388
+ private createFanOutFetcherEvent;
389
+ private sliceIntegrationSnapshot;
390
+ private attemptRecordFromResult;
391
+ private failedAttemptRecord;
392
+ private budgetCapAttemptRecord;
393
+ private didExhaustRetries;
394
+ private backoffForAttempt;
395
+ /**
396
+ * Unified audit-row companion for every fan-out failure mode —
397
+ * binding-resolve-failed, global-budget-cap, budget-cap (per-integration),
398
+ * context-build-failed, and agent-execute-failed. Routes through
399
+ * `audit.logError` (writes `result='failed'`) with a `prePass` payload
400
+ * so `MetricsCollector.collectPrePassMetrics` can see every failure
401
+ * mode without a parallel `result='success'` row. Before this helper
402
+ * existed, the four pre-execute branches wrote nothing at all and the
403
+ * agent-execute path wrote a `failureKind`-only row that the aggregator
404
+ * silently skipped (it filters on `detail.prePass` being a non-null
405
+ * object). Cost / tokens are intentionally NOT supplied — pre-execute
406
+ * paths have zero cost, the agent-execute throw path has no usable
407
+ * AgentResult, so any figure here would be a guess; the aggregator
408
+ * coalesces missing `cost_usd` to 0.
409
+ */
410
+ private logFanOutFailure;
411
+ private logFanOutAttempt;
412
+ /**
413
+ * Helper for the failure paths — renders a `<fetch_report status="failed">`
414
+ * block and logs the underlying error. Never throws so the caller can
415
+ * always continue with the parent routine dispatch.
416
+ */
417
+ private fail;
418
+ /**
419
+ * Translate the mail registry's active-account list into the
420
+ * `AcquisitionAccount[]` shape `buildAcquisitionPlan` expects. Only
421
+ * accounts whose integration is currently non-disabled survive — a
422
+ * disabled gmail integration with five accounts produces zero rows,
423
+ * matching the partial's `<!-- mode:disabled:gmail -->` no-op.
424
+ */
425
+ private collectAccounts;
426
+ }
427
+ //# sourceMappingURL=routine-fetch-window-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routine-fetch-window-runner.d.ts","sourceRoot":"","sources":["../../src/core/routine-fetch-window-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAEV,SAAS,EACT,KAAK,EACL,cAAc,EACd,gBAAgB,EAIjB,MAAM,eAAe,CAAC;AASvB,OAAO,KAAK,EAAE,WAAW,EAA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