@aitne/daemon 0.1.10 → 0.1.11

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 (305) hide show
  1. package/dist/adapters/adapter-watchdog.d.ts +70 -0
  2. package/dist/adapters/adapter-watchdog.js +115 -0
  3. package/dist/adapters/discord.d.ts +17 -1
  4. package/dist/adapters/discord.js +33 -0
  5. package/dist/adapters/notification-manager.d.ts +27 -1
  6. package/dist/adapters/notification-manager.js +54 -39
  7. package/dist/adapters/slack-adapter.d.ts +26 -1
  8. package/dist/adapters/slack-adapter.js +41 -0
  9. package/dist/adapters/telegram-adapter.d.ts +18 -1
  10. package/dist/adapters/telegram-adapter.js +41 -2
  11. package/dist/adapters/types.d.ts +20 -0
  12. package/dist/adapters/whatsapp-adapter.d.ts +26 -7
  13. package/dist/adapters/whatsapp-adapter.js +74 -21
  14. package/dist/api/env-writer.js +8 -5
  15. package/dist/api/helpers/agent-errors-registry.d.ts +5 -5
  16. package/dist/api/helpers/agent-errors-registry.js +5 -5
  17. package/dist/api/routes/agent.js +33 -12
  18. package/dist/api/routes/agents/index.js +75 -16
  19. package/dist/api/routes/agents/views.d.ts +37 -2
  20. package/dist/api/routes/agents/views.js +64 -2
  21. package/dist/api/routes/background-task.d.ts +22 -0
  22. package/dist/api/routes/background-task.js +338 -0
  23. package/dist/api/routes/browser-history.js +9 -1
  24. package/dist/api/routes/context/permissions.js +3 -2
  25. package/dist/api/routes/context/snapshots.js +0 -3
  26. package/dist/api/routes/context/write.js +3 -17
  27. package/dist/api/routes/dashboard/config.js +48 -12
  28. package/dist/api/routes/dashboard/cost-approvals.js +66 -0
  29. package/dist/api/routes/dashboard/notifications.js +9 -9
  30. package/dist/api/routes/integrations/crud-patch.js +5 -1
  31. package/dist/api/routes/integrations-reconcile.js +2 -2
  32. package/dist/api/routes/notion.d.ts +1 -1
  33. package/dist/api/routes/observations.js +7 -7
  34. package/dist/api/routes/obsidian.d.ts +1 -1
  35. package/dist/api/routes/receipts.js +5 -1
  36. package/dist/api/routes/setup-migrate.js +1 -1
  37. package/dist/api/routes/setup.js +1 -1
  38. package/dist/api/routes/task-flows.d.ts +1 -1
  39. package/dist/api/routes/task-flows.js +1 -1
  40. package/dist/api/routes/tuning.d.ts +29 -0
  41. package/dist/api/routes/tuning.js +304 -0
  42. package/dist/api/server.d.ts +44 -16
  43. package/dist/api/server.js +9 -0
  44. package/dist/bootstrap/adapters.d.ts +19 -0
  45. package/dist/bootstrap/adapters.js +61 -0
  46. package/dist/bootstrap/api.d.ts +5 -3
  47. package/dist/bootstrap/api.js +45 -13
  48. package/dist/bootstrap/catchup.d.ts +1 -1
  49. package/dist/bootstrap/catchup.js +11 -11
  50. package/dist/bootstrap/event-pipeline.d.ts +11 -0
  51. package/dist/bootstrap/event-pipeline.js +245 -7
  52. package/dist/bootstrap/observers.js +9 -6
  53. package/dist/bootstrap/schedule-helpers.d.ts +104 -6
  54. package/dist/bootstrap/schedule-helpers.js +172 -19
  55. package/dist/config.js +26 -12
  56. package/dist/core/agent-core.d.ts +33 -1
  57. package/dist/core/agent-core.js +36 -1
  58. package/dist/core/agents/activity-scan-cadence.d.ts +103 -0
  59. package/dist/core/agents/activity-scan-cadence.js +127 -0
  60. package/dist/core/agents/agent-route-override.d.ts +53 -0
  61. package/dist/core/agents/agent-route-override.js +69 -0
  62. package/dist/core/agents/builtin-registry.d.ts +51 -14
  63. package/dist/core/agents/builtin-registry.js +92 -15
  64. package/dist/core/agents/config-gate-reconcile.d.ts +38 -0
  65. package/dist/core/agents/config-gate-reconcile.js +51 -0
  66. package/dist/core/agents/cron-substitute.d.ts +1 -1
  67. package/dist/core/agents/cron-substitute.js +1 -1
  68. package/dist/core/agents/custom-routine-migration.d.ts +60 -0
  69. package/dist/core/agents/custom-routine-migration.js +149 -0
  70. package/dist/core/agents/firing-blocked.d.ts +1 -1
  71. package/dist/core/agents/hourly-cadence.d.ts +102 -0
  72. package/dist/core/agents/hourly-cadence.js +126 -0
  73. package/dist/core/agents/loader-boot.js +23 -0
  74. package/dist/core/agents/loader.d.ts +19 -0
  75. package/dist/core/agents/loader.js +34 -2
  76. package/dist/core/agents/override-merge.d.ts +1 -1
  77. package/dist/core/agents/override-merge.js +9 -1
  78. package/dist/core/agents/recurrence-convert.d.ts +1 -1
  79. package/dist/core/agents/recurrence-convert.js +1 -1
  80. package/dist/core/agents/recurring-schedule-adapter.js +8 -0
  81. package/dist/core/alerts.js +6 -6
  82. package/dist/core/backends/auth-health-monitor.d.ts +2 -2
  83. package/dist/core/backends/auth-health-monitor.js +1 -1
  84. package/dist/core/backends/backend-router.d.ts +27 -1
  85. package/dist/core/backends/backend-router.js +165 -1
  86. package/dist/core/backends/claude-code-core.d.ts +71 -31
  87. package/dist/core/backends/claude-code-core.js +282 -54
  88. package/dist/core/backends/cli-quota-guards.d.ts +29 -1
  89. package/dist/core/backends/cli-quota-guards.js +40 -5
  90. package/dist/core/backends/codex-core.d.ts +6 -0
  91. package/dist/core/backends/codex-core.js +22 -6
  92. package/dist/core/backends/failure-spend.d.ts +58 -0
  93. package/dist/core/backends/failure-spend.js +137 -0
  94. package/dist/core/backends/gemini-cli-core.d.ts +6 -0
  95. package/dist/core/backends/gemini-cli-core.js +25 -6
  96. package/dist/core/backends/model-registry.d.ts +1 -1
  97. package/dist/core/backends/model-registry.js +4 -4
  98. package/dist/core/backends/opencode-core.d.ts +1 -1
  99. package/dist/core/backends/opencode-core.js +5 -5
  100. package/dist/core/backends/plan-presets.js +39 -15
  101. package/dist/core/bang-commands/commands-cost.js +3 -1
  102. package/dist/core/bang-commands/commands-report.js +4 -3
  103. package/dist/core/bang-commands/commands-research.js +4 -1
  104. package/dist/core/bang-commands/commands-revert-tuning.d.ts +18 -0
  105. package/dist/core/bang-commands/commands-revert-tuning.js +63 -0
  106. package/dist/core/bang-commands/commands-stop-start.js +3 -3
  107. package/dist/core/bang-commands/commands-task-control.d.ts +19 -0
  108. package/dist/core/bang-commands/commands-task-control.js +147 -0
  109. package/dist/core/bang-commands/commands-wiki.js +5 -5
  110. package/dist/core/bang-commands/index.d.ts +2 -0
  111. package/dist/core/bang-commands/index.js +12 -0
  112. package/dist/core/bang-commands/registry.d.ts +12 -0
  113. package/dist/core/browser-history/research-cluster-fanout.d.ts +28 -14
  114. package/dist/core/browser-history/research-cluster-fanout.js +39 -16
  115. package/dist/core/channel-timeline.d.ts +5 -1
  116. package/dist/core/channel-timeline.js +13 -0
  117. package/dist/core/context/index-reconciler.js +5 -2
  118. package/dist/core/context/policy-index-reconciler.d.ts +6 -4
  119. package/dist/core/context/policy-index-runner.js +25 -6
  120. package/dist/core/context-builder-calendar.js +10 -2
  121. package/dist/core/context-builder-conversation.d.ts +8 -1
  122. package/dist/core/context-builder-conversation.js +41 -7
  123. package/dist/core/context-builder-yesterday.js +4 -3
  124. package/dist/core/context-builder.d.ts +7 -2
  125. package/dist/core/context-builder.js +62 -20
  126. package/dist/core/context-file-serializer.d.ts +1 -1
  127. package/dist/core/context-file-serializer.js +1 -1
  128. package/dist/core/context-health.js +2 -2
  129. package/dist/core/context-paths.d.ts +1 -1
  130. package/dist/core/context-paths.js +1 -1
  131. package/dist/core/context-validation/prepare-write.js +1 -1
  132. package/dist/core/context-validation/routine-rulebook.d.ts +1 -1
  133. package/dist/core/context-vault-aliases.d.ts +0 -13
  134. package/dist/core/context-vault-aliases.js +37 -0
  135. package/dist/core/custom-routines.d.ts +99 -0
  136. package/dist/core/custom-routines.js +187 -0
  137. package/dist/core/daemon-api-cli.js +49 -0
  138. package/dist/core/day-boundary.d.ts +46 -0
  139. package/dist/core/day-boundary.js +40 -0
  140. package/dist/core/dispatcher-activity-scan.d.ts +221 -0
  141. package/dist/core/dispatcher-activity-scan.js +775 -0
  142. package/dist/core/dispatcher-error-handling.d.ts +6 -11
  143. package/dist/core/dispatcher-error-handling.js +38 -62
  144. package/dist/core/dispatcher-hourly-check.js +6 -1
  145. package/dist/core/dispatcher-message-handler.d.ts +10 -0
  146. package/dist/core/dispatcher-message-handler.js +17 -0
  147. package/dist/core/dispatcher-morning-routine.d.ts +6 -6
  148. package/dist/core/dispatcher-morning-routine.js +13 -13
  149. package/dist/core/dispatcher-result-processor.d.ts +33 -0
  150. package/dist/core/dispatcher-result-processor.js +167 -11
  151. package/dist/core/dispatcher-scheduled-background-task.d.ts +42 -0
  152. package/dist/core/dispatcher-scheduled-background-task.js +89 -0
  153. package/dist/core/dispatcher-scheduled-tasks.d.ts +63 -1
  154. package/dist/core/dispatcher-scheduled-tasks.js +213 -6
  155. package/dist/core/dispatcher-task-delivery.d.ts +105 -0
  156. package/dist/core/dispatcher-task-delivery.js +555 -0
  157. package/dist/core/dispatcher-types.d.ts +48 -9
  158. package/dist/core/dispatcher-types.js +3 -3
  159. package/dist/core/dispatcher.d.ts +112 -31
  160. package/dist/core/dispatcher.js +284 -59
  161. package/dist/core/dm-freshness-metrics.d.ts +1 -1
  162. package/dist/core/drift-effects.js +2 -2
  163. package/dist/core/feedback/consolidation-prep.js +17 -5
  164. package/dist/core/feedback/eviction-scorer.js +6 -2
  165. package/dist/core/feedback/lesson-format.js +9 -4
  166. package/dist/core/feedback/lesson-injection.d.ts +1 -1
  167. package/dist/core/feedback/lesson-injection.js +17 -2
  168. package/dist/core/feedback/lesson-store-overview.d.ts +8 -4
  169. package/dist/core/feedback/lesson-store-overview.js +8 -4
  170. package/dist/core/feedback/regeneralization-prep.js +29 -16
  171. package/dist/core/feedback/self-performance-prep.d.ts +186 -0
  172. package/dist/core/feedback/self-performance-prep.js +541 -0
  173. package/dist/core/feedback/tuning-actuator.d.ts +198 -0
  174. package/dist/core/feedback/tuning-actuator.js +432 -0
  175. package/dist/core/feedback/tuning-recommender.d.ts +247 -0
  176. package/dist/core/feedback/tuning-recommender.js +580 -0
  177. package/dist/core/feedback/tuning-revert-monitor.d.ts +90 -0
  178. package/dist/core/feedback/tuning-revert-monitor.js +213 -0
  179. package/dist/core/health-monitor.d.ts +6 -0
  180. package/dist/core/health-monitor.js +1 -1
  181. package/dist/core/injection-policy.d.ts +4 -4
  182. package/dist/core/injection-policy.js +4 -4
  183. package/dist/core/integration-main-backend.js +4 -0
  184. package/dist/core/management-md.d.ts +2 -2
  185. package/dist/core/management-md.js +51 -13
  186. package/dist/core/morning/orchestrator.d.ts +2 -2
  187. package/dist/core/morning/orchestrator.js +2 -2
  188. package/dist/core/notification-gate.d.ts +64 -0
  189. package/dist/core/notification-gate.js +51 -0
  190. package/dist/core/notification-rate-limit.d.ts +40 -0
  191. package/dist/core/notification-rate-limit.js +50 -0
  192. package/dist/core/policy-files.d.ts +1 -1
  193. package/dist/core/policy-files.js +2 -2
  194. package/dist/core/pre-pass-freshness.d.ts +4 -4
  195. package/dist/core/retention.d.ts +5 -0
  196. package/dist/core/retention.js +20 -4
  197. package/dist/core/review-context.d.ts +1 -1
  198. package/dist/core/review-context.js +10 -5
  199. package/dist/core/roadmap-write-lock.d.ts +2 -1
  200. package/dist/core/roadmap-write-lock.js +15 -10
  201. package/dist/core/routine-acquisition-plan.d.ts +47 -1
  202. package/dist/core/routine-acquisition-plan.js +78 -20
  203. package/dist/core/routine-fetch-window-retry.js +7 -4
  204. package/dist/core/routine-fetch-window-runner.d.ts +39 -3
  205. package/dist/core/routine-fetch-window-runner.js +264 -13
  206. package/dist/core/routine-windows.d.ts +2 -2
  207. package/dist/core/routine-windows.js +8 -5
  208. package/dist/core/scheduler.d.ts +175 -16
  209. package/dist/core/scheduler.js +559 -102
  210. package/dist/core/signal-detector.d.ts +12 -0
  211. package/dist/core/signal-detector.js +53 -9
  212. package/dist/core/skills-compiler-denied-tools.js +2 -2
  213. package/dist/core/skills-compiler-skill-index.d.ts +2 -2
  214. package/dist/core/skills-compiler-skill-index.js +2 -2
  215. package/dist/core/skills-compiler-variants.d.ts +1 -1
  216. package/dist/core/skills-compiler-variants.js +8 -0
  217. package/dist/core/skills-compiler.d.ts +29 -26
  218. package/dist/core/skills-compiler.js +117 -81
  219. package/dist/core/skills-manifest.d.ts +37 -0
  220. package/dist/core/skills-manifest.js +73 -2
  221. package/dist/core/sleep-inhibitor.d.ts +79 -0
  222. package/dist/core/sleep-inhibitor.js +132 -0
  223. package/dist/core/slim-system-prompt-loader.d.ts +77 -0
  224. package/dist/core/slim-system-prompt-loader.js +141 -0
  225. package/dist/core/spawn-gates.d.ts +126 -0
  226. package/dist/core/spawn-gates.js +180 -0
  227. package/dist/core/today-direct-writer.d.ts +2 -2
  228. package/dist/core/today-direct-writer.js +1 -1
  229. package/dist/core/today-write-lock.d.ts +4 -2
  230. package/dist/core/today-write-lock.js +30 -20
  231. package/dist/core/wake-detector.d.ts +55 -0
  232. package/dist/core/wake-detector.js +80 -0
  233. package/dist/core/wiki/compile-lock.d.ts +1 -1
  234. package/dist/core/wiki/compile-lock.js +1 -1
  235. package/dist/core/workdir.js +15 -6
  236. package/dist/db/activity-scan-signals.d.ts +77 -0
  237. package/dist/db/activity-scan-signals.js +378 -0
  238. package/dist/db/agents-store.d.ts +28 -0
  239. package/dist/db/agents-store.js +62 -0
  240. package/dist/db/background-task-clarifications-store.d.ts +81 -0
  241. package/dist/db/background-task-clarifications-store.js +152 -0
  242. package/dist/db/background-task-store.d.ts +207 -0
  243. package/dist/db/background-task-store.js +380 -0
  244. package/dist/db/browser-history-store.d.ts +39 -6
  245. package/dist/db/browser-history-store.js +51 -7
  246. package/dist/db/browser-task-clarifications-store.d.ts +12 -0
  247. package/dist/db/browser-task-clarifications-store.js +35 -5
  248. package/dist/db/browser-task-store.d.ts +3 -0
  249. package/dist/db/browser-task-store.js +29 -4
  250. package/dist/db/deferred-dm.d.ts +86 -0
  251. package/dist/db/deferred-dm.js +199 -0
  252. package/dist/db/migrations.js +330 -0
  253. package/dist/db/observations.d.ts +2 -2
  254. package/dist/db/observations.js +3 -3
  255. package/dist/db/schema.js +217 -16
  256. package/dist/db/voice-transcripts-store.d.ts +1 -1
  257. package/dist/index.js +86 -29
  258. package/dist/messaging/browser-task-mcp-notifier.d.ts +12 -70
  259. package/dist/messaging/browser-task-mcp-notifier.js +30 -151
  260. package/dist/messaging/browser-task-screenshot-attachment.d.ts +15 -0
  261. package/dist/messaging/browser-task-screenshot-attachment.js +63 -0
  262. package/dist/observers/delegated-sync-worker.d.ts +6 -6
  263. package/dist/observers/delegated-sync-worker.js +10 -10
  264. package/dist/observers/git-delegated-cron.d.ts +1 -1
  265. package/dist/observers/git-delegated-cron.js +2 -2
  266. package/dist/observers/github-poller-classifier.d.ts +3 -3
  267. package/dist/observers/github-poller-classifier.js +3 -3
  268. package/dist/observers/imminent-event-scheduler.d.ts +1 -1
  269. package/dist/observers/imminent-event-scheduler.js +1 -1
  270. package/dist/observers/mail-poller.d.ts +1 -0
  271. package/dist/observers/mail-poller.js +42 -3
  272. package/dist/observers/observation-summarizer/summarizer-client.d.ts +2 -2
  273. package/dist/observers/observation-summarizer/summarizer-client.js +2 -2
  274. package/dist/observers/observation-summarizer/worker.d.ts +2 -2
  275. package/dist/observers/observation-summarizer/worker.js +4 -4
  276. package/dist/observers/obsidian-watcher.d.ts +1 -1
  277. package/dist/observers/obsidian-watcher.js +1 -1
  278. package/dist/safety/agent-write-tracker.d.ts +4 -4
  279. package/dist/safety/agent-write-tracker.js +4 -4
  280. package/dist/safety/audit.d.ts +43 -5
  281. package/dist/safety/audit.js +86 -18
  282. package/dist/safety/risk-classifier.d.ts +6 -0
  283. package/dist/safety/risk-classifier.js +75 -11
  284. package/dist/scheduler/activity-scan-gate.d.ts +86 -0
  285. package/dist/scheduler/activity-scan-gate.js +132 -0
  286. package/dist/services/background-task/background-task-budget.d.ts +80 -0
  287. package/dist/services/background-task/background-task-budget.js +91 -0
  288. package/dist/services/background-task/background-task-driver.d.ts +105 -0
  289. package/dist/services/background-task/background-task-driver.js +416 -0
  290. package/dist/services/background-task/background-task-runner.d.ts +96 -0
  291. package/dist/services/background-task/background-task-runner.js +673 -0
  292. package/dist/services/background-task/background-task-tools.d.ts +84 -0
  293. package/dist/services/background-task/background-task-tools.js +247 -0
  294. package/dist/services/background-task/background-task-transition-events.d.ts +43 -0
  295. package/dist/services/background-task/background-task-transition-events.js +54 -0
  296. package/dist/services/browser-history/automation/egress-denylist.d.ts +1 -1
  297. package/dist/services/browser-history/automation/egress-denylist.js +16 -6
  298. package/dist/services/browser-history/managed-chromium/sandbox-launcher.js +0 -1
  299. package/dist/services/browser-task/browser-task-runner.js +53 -8
  300. package/dist/services/observations-batch.d.ts +1 -1
  301. package/dist/services/observations-batch.js +2 -2
  302. package/dist/settings/runtime-settings.d.ts +38 -11
  303. package/dist/settings/runtime-settings.js +203 -40
  304. package/dist/settings/settings-store.js +11 -3
  305. package/package.json +4 -4
@@ -5,12 +5,12 @@
5
5
  * the daemon — adapter / service interfaces (`IDashboardStream`,
6
6
  * `INotificationManager`, `ISessionManager`, `IMessageRecorder`,
7
7
  * `IContextBuilder`, `IAuditLogger`), the `GetTaskFlow` callback, and the
8
- * value types used at API boundaries (`TriggerHourlyCheckOptions`,
9
- * `TriggerHourlyCheckResult`, `InFlightExecutionInfo`, `SetupMode`,
8
+ * value types used at API boundaries (`TriggerActivityScanOptions`,
9
+ * `TriggerActivityScanResult`, `InFlightExecutionInfo`, `SetupMode`,
10
10
  * `BangCommandDetail`, `ReplyActivityHandle`). It also hosts two pure
11
11
  * helpers that have no dependence on dispatcher instance state:
12
12
  * `buildLogErrorContext` (recovers backend/quota failure metadata from a
13
- * thrown error) and `parseStage2Verdict` (extracts the Stage 2 hourly-check
13
+ * thrown error) and `parseStage2Verdict` (extracts the Stage 2 activity-scan
14
14
  * triage JSON verdict from an LLM response).
15
15
  *
16
16
  * The dispatcher re-exports the public-surface members of this file so that
@@ -1,23 +1,26 @@
1
1
  import type Database from "better-sqlite3";
2
2
  import type { Event } from "@aitne/shared";
3
+ import { type TaskDeliveryAsset } from "@aitne/shared";
3
4
  import type { AgentConfig } from "../config.js";
4
5
  import type { DocsCitationLookup } from "./docs/citation-validator.js";
5
6
  import type { SignalDetector } from "./signal-detector.js";
6
7
  import type { ServiceRegistry } from "../services/service-registry.js";
7
8
  import { EventBus } from "./event-bus.js";
9
+ import { SessionGateRegistry } from "./session-gate.js";
8
10
  import type { IAgentRouter } from "./backends/backend-router.js";
9
11
  import type { TodayWriteLockManager } from "./today-write-lock.js";
10
12
  import type { RoadmapWriteLockManager } from "./roadmap-write-lock.js";
11
13
  import type { AgentWriteTracker } from "../safety/agent-write-tracker.js";
12
14
  import type { AttachmentStore } from "../services/attachments/store.js";
15
+ import type { OutboundAttachmentRef } from "../adapters/types.js";
13
16
  import type { VoiceTranscriber } from "../services/voice/transcriber.js";
14
17
  import type { AgentExecutionTracker } from "./agents/agent-execution-tracker.js";
15
18
  export type { IAgentCore, StreamCallbacks } from "./agent-core.js";
16
19
  export type { IAgentRouter } from "./backends/backend-router.js";
17
- import { parseStage2Verdict, type ReplyActivityHandle, type IDashboardStream, type IContextBuilder, type GetTaskFlow, type INotificationManager, type ISessionManager, type IMessageRecorder, type IAuditLogger, type BangCommandDetail, type DailyWriteAuditDetail, type TriggerHourlyCheckSkipReason, type SetupMode, type TriggerHourlyCheckOptions, type TriggerHourlyCheckResult, type InFlightExecutionInfo } from "./dispatcher-types.js";
20
+ import { parseStage2Verdict, type ReplyActivityHandle, type IDashboardStream, type IContextBuilder, type GetTaskFlow, type INotificationManager, type ISessionManager, type IMessageRecorder, type IAuditLogger, type BangCommandDetail, type DailyWriteAuditDetail, type TriggerActivityScanSkipReason, type SetupMode, type TriggerActivityScanOptions, type TriggerActivityScanResult, type InFlightExecutionInfo } from "./dispatcher-types.js";
18
21
  export { parseStage2Verdict, };
19
- export type { ReplyActivityHandle, IDashboardStream, IContextBuilder, GetTaskFlow, INotificationManager, ISessionManager, IMessageRecorder, IAuditLogger, BangCommandDetail, DailyWriteAuditDetail, TriggerHourlyCheckSkipReason, SetupMode, TriggerHourlyCheckOptions, TriggerHourlyCheckResult, InFlightExecutionInfo, };
20
- import type { QueueMorningRoutineWake } from "./dispatcher-hourly-check.js";
22
+ export type { ReplyActivityHandle, IDashboardStream, IContextBuilder, GetTaskFlow, INotificationManager, ISessionManager, IMessageRecorder, IAuditLogger, BangCommandDetail, DailyWriteAuditDetail, TriggerActivityScanSkipReason, SetupMode, TriggerActivityScanOptions, TriggerActivityScanResult, InFlightExecutionInfo, };
23
+ import type { QueueMorningRoutineWake } from "./dispatcher-activity-scan.js";
21
24
  import { SKILL_CURATION_OPTIMIZER_ALLOWED_TOOLS } from "./dispatcher-scheduled-tasks.js";
22
25
  export { SKILL_CURATION_OPTIMIZER_ALLOWED_TOOLS };
23
26
  export declare class EventDispatcher {
@@ -101,6 +104,14 @@ export declare class EventDispatcher {
101
104
  * instead of leaving the row silently flipped to `failed` in the DB.
102
105
  */
103
106
  private browserTaskTerminalNotifier;
107
+ /**
108
+ * BACKGROUND_TASK_RUNNER_DESIGN.md §4.2 — the dispatcher routes
109
+ * `scheduled.background_task` events to this runner. Wired at startup
110
+ * from `bootstrap/event-pipeline.ts` via `setBackgroundTaskRunner`.
111
+ * Null when the runner factory has not landed — the dispatch branch
112
+ * flips the row to `failed (runner_unavailable)` so it doesn't park.
113
+ */
114
+ private backgroundTaskRunner;
104
115
  /**
105
116
  * Current setup mode — scope-agnostic flag that survives internal
106
117
  * direct-message session refresh (day boundary, stale flag, etc). Previously this
@@ -130,38 +141,38 @@ export declare class EventDispatcher {
130
141
  /** Dedup guard: timestamp of the last roadmap_refresh emission */
131
142
  private lastRoadmapRefreshEmitMs;
132
143
  private morningRoutineInProgress;
133
- private hourlyCheckInProgress;
144
+ private activityScanInProgress;
134
145
  /**
135
146
  * Wall-clock timestamp (ms since epoch) of the most recent flip of
136
- * `hourlyCheckInProgress` to `true`, or `null` when the flag is false.
147
+ * `activityScanInProgress` to `true`, or `null` when the flag is false.
137
148
  *
138
- * Paired with `HOURLY_CHECK_FLAG_MAX_AGE_MS` to break the silent-stall
149
+ * Paired with `ACTIVITY_SCAN_FLAG_MAX_AGE_MS` to break the silent-stall
139
150
  * pattern where the flag is set true at enqueue time but the matching
140
151
  * `dispatchSafe` finally never runs — currently possible when the
141
152
  * EventBus evicts/drops the queued routine event under `put()` pressure
142
153
  * (heap-js drops the lowest-priority entry silently when `heap.size() >=
143
154
  * maxSize=1000`). Without the timestamp the flag stays `true` until
144
155
  * process restart and every subsequent hourly tick short-circuits with
145
- * `hourly_check_in_progress`.
156
+ * `activity_scan_in_progress`.
146
157
  *
147
- * Read side (`isHourlyCheckInProgress` callback below) checks the age
158
+ * Read side (`isActivityScanInProgress` callback below) checks the age
148
159
  * and auto-clears when it exceeds the bound, surfacing the recovery via
149
160
  * a warn log so the operator sees the EventBus pressure event.
150
161
  */
151
- private hourlyCheckInProgressAt;
162
+ private activityScanInProgressAt;
152
163
  /**
153
- * Upper bound for how long `hourlyCheckInProgress=true` can plausibly
164
+ * Upper bound for how long `activityScanInProgress=true` can plausibly
154
165
  * be valid before we treat it as stuck and force-clear.
155
166
  *
156
- * Sized generously above the realistic Stage-3 hourly_check ceiling
157
- * (fetch_window pre-pass ~30–60 s + Sonnet hourly_check session
167
+ * Sized generously above the realistic Stage-3 activity_scan ceiling
168
+ * (fetch_window pre-pass ~30–60 s + Sonnet activity_scan session
158
169
  * ~1–3 min) so a slow but normal run is never falsely cleared. Sized
159
170
  * well below an entire agent-day so a stuck flag recovers within a
160
171
  * single hourly cron cycle's worst case (default cadence 60 min).
161
172
  * The 30-minute window is comfortably outside any plausible "still
162
173
  * running" interpretation and inside one full hourly slot.
163
174
  */
164
- private static readonly HOURLY_CHECK_FLAG_MAX_AGE_MS;
175
+ private static readonly ACTIVITY_SCAN_FLAG_MAX_AGE_MS;
165
176
  /**
166
177
  * P22 §3.4 — wired by `index.ts` after the daemon's data dir + skills root
167
178
  * are known. Returns a `{runId, runToken, workdirPath, targetSkills}` tuple
@@ -194,12 +205,19 @@ export declare class EventDispatcher {
194
205
  * and older code paths that don't wire the store. When null, the
195
206
  * dispatcher skips attachment staging + outbound collection. */
196
207
  private attachmentStore;
208
+ /** Injected lazily via `setTaskDeliveryAssetResolver` — optional.
209
+ * Resolves a task's deliverable assets (browser-task screenshots +
210
+ * worker-written files) to outbound attachments for the `task.delivery`
211
+ * idle + active branches (the ingest hook is constructed after this
212
+ * dispatcher, so it is wired post-construction like the attachment
213
+ * store). When null, task-delivery DMs are text-only. */
214
+ private taskDeliveryAssetResolver;
197
215
  /** Injected lazily via `setDelegatedSyncRefresh` — optional. When null,
198
- * hourly check fires without first refreshing delegated-mode snapshots,
216
+ * activity scan fires without first refreshing delegated-mode snapshots,
199
217
  * matching the pre-Phase-9 behaviour. Wired in production when at
200
218
  * least one integration is in delegated mode. See
201
219
  * `docs/design/appendices/delegated-sync-opt-in.md` and the worker's
202
- * `runDisabledCadencesForHourlyCheck` method. */
220
+ * `runDisabledCadencesForActivityScan` method. */
203
221
  private delegatedSyncRefresh;
204
222
  /**
205
223
  * Injected lazily via `setQueueMorningRoutineWake` (wired in `index.ts`
@@ -218,7 +236,7 @@ export declare class EventDispatcher {
218
236
  * Injected lazily via `setEventBroadcaster` — optional. When wired, the
219
237
  * dispatcher emits `routine_started` / `routine_completed` SSE events at
220
238
  * the `dispatchSafe` chokepoint so the dashboard can render real-time
221
- * progress for autonomous routines (morning_routine, hourly_check,
239
+ * progress for autonomous routines (morning_routine, activity_scan,
222
240
  * roadmap_refresh, evening/weekly/monthly reviews, etc.).
223
241
  *
224
242
  * Failure to broadcast is non-fatal: the throw is swallowed and logged
@@ -295,21 +313,38 @@ export declare class EventDispatcher {
295
313
  */
296
314
  private readonly resultProcessor;
297
315
  /**
298
- * Phase D-2 coordinator: owns `triggerHourlyCheck` and the
316
+ * Phase D-2 coordinator: owns `triggerActivityScan` and the
299
317
  * cost-reduction-structural §B three-stage gate. Borrows live
300
- * accessors for the dispatcher's `hourlyCheckInProgress` flag so the
318
+ * accessors for the dispatcher's `activityScanInProgress` flag so the
301
319
  * pre-existing C1 atomic check-and-set semantics survive the split.
302
320
  */
303
321
  /**
304
322
  * docs/design/appendices/routine-data-acquisition.md Phase 4 / D1 — shared pre-pass
305
- * runner for `routine.fetch_window`. Injected into HourlyCheckCoordinator
323
+ * runner for `routine.fetch_window`. Injected into ActivityScanCoordinator
306
324
  * (D3), MorningRoutineRunner (D2), and ScheduledTaskRunner (D4) so
307
325
  * every routine that has rows in `ROUTINE_WINDOWS` gets the same
308
326
  * fetcher session ahead of its parent dispatch. Pure helper, no
309
327
  * mutable state of its own.
310
328
  */
311
329
  private readonly fetchWindowRunner;
312
- private readonly hourlyCheck;
330
+ /**
331
+ * PREPASS_COST_REDUCTION_PLAN.md N2 — offline (backend-API-host DNS) +
332
+ * cached-auth spawn gate for autonomous sessions. Shared with the
333
+ * pre-pass fan-out runner so both layers reuse one DNS verdict cache.
334
+ */
335
+ private readonly spawnGate;
336
+ /**
337
+ * Last spawn-gate skip *audit write* per (schedule-or-type, reason) —
338
+ * ms epoch. A released schedule row is re-claimed by the
339
+ * ScheduleWatcher every poll tick (default 5s), so an hours-long
340
+ * offline window would otherwise INSERT thousands of identical
341
+ * `result='skipped'` rows. The DB row release/claim churn is bounded
342
+ * (UPDATEs to one row); the audit INSERT is what must be throttled.
343
+ * In-memory on purpose: worst case after a restart is one extra row.
344
+ */
345
+ private readonly spawnGateSkipAuditAt;
346
+ private static readonly SPAWN_GATE_SKIP_AUDIT_THROTTLE_MS;
347
+ private readonly activityScan;
313
348
  /**
314
349
  * Phase D-2 coordinator: owns morning-routine execution end-to-end
315
350
  * (lock acquisition, prompt-variant selection, retry chain, today.md
@@ -341,7 +376,7 @@ export declare class EventDispatcher {
341
376
  * thin shims that forward into this handler.
342
377
  */
343
378
  private readonly messageHandler;
344
- constructor(eventBus: EventBus, agentRouter: IAgentRouter, contextBuilder: IContextBuilder, getTaskFlow: GetTaskFlow, notificationMgr: INotificationManager, sessionMgr: ISessionManager, messageRecorder: IMessageRecorder, audit: IAuditLogger, db: Database.Database, config: AgentConfig, todayWriteLock?: TodayWriteLockManager | undefined, services?: ServiceRegistry | undefined, roadmapWriteLock?: RoadmapWriteLockManager | undefined, writeTracker?: AgentWriteTracker | undefined);
379
+ constructor(eventBus: EventBus, agentRouter: IAgentRouter, contextBuilder: IContextBuilder, getTaskFlow: GetTaskFlow, notificationMgr: INotificationManager, sessionMgr: ISessionManager, messageRecorder: IMessageRecorder, audit: IAuditLogger, db: Database.Database, config: AgentConfig, todayWriteLock?: TodayWriteLockManager | undefined, services?: ServiceRegistry | undefined, roadmapWriteLock?: RoadmapWriteLockManager | undefined, writeTracker?: AgentWriteTracker | undefined, sessionGates?: SessionGateRegistry);
345
380
  private loadPersistedSetupMode;
346
381
  /** Set the SignalDetector for implicit feedback collection from user messages. */
347
382
  setSignalDetector(detector: SignalDetector): void;
@@ -373,6 +408,13 @@ export declare class EventDispatcher {
373
408
  */
374
409
  setBrowserTaskRunner(runner: import("../services/browser-task/browser-task-runner.js").BrowserTaskRunner | null): void;
375
410
  getBrowserTaskRunner(): import("../services/browser-task/browser-task-runner.js").BrowserTaskRunner | null;
411
+ /**
412
+ * BACKGROUND_TASK_RUNNER_DESIGN.md §4.2 — wire the generic
413
+ * background-task runner so the `scheduled.background_task` dispatch
414
+ * branch can hand fire-time events to it. Pairs with the
415
+ * `event-pipeline.ts` `createBackgroundTaskRunner` factory call.
416
+ */
417
+ setBackgroundTaskRunner(runner: import("../services/background-task/background-task-runner.js").BackgroundTaskRunner | null): void;
376
418
  /**
377
419
  * BROWSER_TASK_REDESIGN_PLAN.md §7 — wire the terminal-state DM
378
420
  * emitter used by the `scheduled.browser_task` failure paths (see
@@ -394,13 +436,19 @@ export declare class EventDispatcher {
394
436
  setDocsCitationLookup(lookup: DocsCitationLookup): void;
395
437
  /** Chat-attachments Phase 1 — inject the shared AttachmentStore. */
396
438
  setAttachmentStore(store: AttachmentStore): void;
439
+ /** BACKGROUND_TASK_RUNNER_DESIGN.md Phase 1 (delivery assets) — inject the
440
+ * asset resolver used by the `task.delivery` idle + active branches to
441
+ * attach a task's deliverable files (screenshots, PDF/PPTX/PNG/docs)
442
+ * inline. Wired post-construction because the underlying
443
+ * dashboard-ingest hook is built after this dispatcher. */
444
+ setTaskDeliveryAssetResolver(resolver: (platform: string, assets: readonly TaskDeliveryAsset[]) => Promise<readonly OutboundAttachmentRef[]>): void;
397
445
  /** Inject the local-Whisper voice transcriber. Optional — when unset,
398
446
  * inbound audio attachments are passed to the backend with a path-only
399
447
  * reference (the pre-feature behaviour). */
400
448
  setVoiceTranscriber(transcriber: VoiceTranscriber): void;
401
449
  /**
402
450
  * Inject the delegated-sync refresh callback. Called from
403
- * `triggerHourlyCheck` before the gate decision so any cadence the
451
+ * `triggerActivityScan` before the gate decision so any cadence the
404
452
  * operator left opted-OUT (post-Phase-9 default) populates fresh
405
453
  * Gmail / Notion observations the agent can then consume.
406
454
  *
@@ -410,13 +458,13 @@ export declare class EventDispatcher {
410
458
  * dispatcher holding a stale reference.
411
459
  *
412
460
  * Pass `null` to detach (e.g. when no delegated integration exists).
413
- * The hourly check then proceeds without a refresh — equivalent to the
461
+ * The activity scan then proceeds without a refresh — equivalent to the
414
462
  * pre-injection behaviour.
415
463
  */
416
464
  setDelegatedSyncRefresh(fn: (() => Promise<void>) | null): void;
417
465
  /**
418
466
  * Wire the scheduler's `queueMorningRoutineWake` so the pre-routine
419
- * gate (hourly_check + evening/weekly/monthly review) can self-recover
467
+ * gate (activity_scan + evening/weekly/monthly review) can self-recover
420
468
  * after a missed 04:00 cron fire. Wired once in `index.ts` after both
421
469
  * the dispatcher and scheduler are constructed; passing `null` detaches.
422
470
  * When unset, the gate logs a warning and still skips the dependent
@@ -439,6 +487,14 @@ export declare class EventDispatcher {
439
487
  * behaves exactly as before. Set once at boot from the event-pipeline factory.
440
488
  */
441
489
  setAgentExecutionTracker(tracker: AgentExecutionTracker): void;
490
+ /**
491
+ * Resolve the user-Agent slug owning an in-flight firing, for stamping
492
+ * `agent_id` into quiet-hours-deferred DM rows (QUIET_HOURS_HARDENING_PLAN
493
+ * Phase 1 — the `/api/notify` gate coalesces per Agent so an hourly Agent
494
+ * firing five times overnight yields one combined DM). `null` when no
495
+ * tracker is wired or no execution is active for the correlation id.
496
+ */
497
+ agentIdForCorrelation(correlationId: string): string | null;
442
498
  /**
443
499
  * Open an execution row for an agent-resolvable firing (§8.1), called from
444
500
  * `dispatchSafe` after the setup / cost gates pass so a skipped firing never
@@ -507,7 +563,7 @@ export declare class EventDispatcher {
507
563
  /**
508
564
  * Enter setup mode. Called from `POST /setup/start` so the warm gate
509
565
  * engages the moment the user opens the dashboard setup flow — before any
510
- * agent turn runs — so concurrent hourly_check / morning routine / scheduled
566
+ * agent turn runs — so concurrent activity_scan / morning routine / scheduled
511
567
  * wake work cannot race with the setup conversation. Persisted to
512
568
  * `runtime_state` so the flag survives daemon restart.
513
569
  */
@@ -526,7 +582,7 @@ export declare class EventDispatcher {
526
582
  */
527
583
  getInFlightExecutions(): InFlightExecutionInfo[];
528
584
  /**
529
- * Gate for autonomous background work (cron routines, hourly_check,
585
+ * Gate for autonomous background work (cron routines, activity_scan,
530
586
  * scheduled wake tasks, startup catchup, calendar-poller reactive events).
531
587
  *
532
588
  * Two layers:
@@ -558,21 +614,29 @@ export declare class EventDispatcher {
558
614
  /**
559
615
  * Check whether this autonomous event should be skipped because the daily
560
616
  * autonomous cost cap has been exceeded. Uses priority-based degradation:
561
- * hourly_check (lowest priority, skipped first) → roadmap_refresh →
617
+ * activity_scan (lowest priority, skipped first) → roadmap_refresh →
562
618
  * evening_review → morning_routine (highest, last to be cut).
563
619
  *
564
620
  * Lower-priority events are skipped at 100% of cap; higher-priority events
565
621
  * only at 150%+, giving headroom for the morning briefing.
566
622
  */
567
623
  private shouldSkipForCostCap;
624
+ /**
625
+ * Resolve the candidate backends for an autonomous event and run the
626
+ * N2 spawn gates against them. Fail-open on every internal error
627
+ * (binding resolution included) — the gate exists to save sessions
628
+ * that would deterministically fail, never to block live ones.
629
+ * Returns `null` when the gate could not be evaluated.
630
+ */
631
+ private evaluateAutonomousSpawnGate;
568
632
  private handleEvent;
569
633
  private handleEventInner;
570
634
  /**
571
- * Public entry point. Delegates to the HourlyCheckCoordinator.
635
+ * Public entry point. Delegates to the ActivityScanCoordinator.
572
636
  * The dispatcher keeps the wrapper because tests + the cron entry
573
- * call `dispatcher.triggerHourlyCheck(source, opts)` directly.
637
+ * call `dispatcher.triggerActivityScan(source, opts)` directly.
574
638
  */
575
- triggerHourlyCheck(source: string, options?: TriggerHourlyCheckOptions): Promise<TriggerHourlyCheckResult>;
639
+ triggerActivityScan(source: string, options?: TriggerActivityScanOptions): Promise<TriggerActivityScanResult>;
576
640
  /**
577
641
  * Advisory check: is a morning routine execution or retry currently in
578
642
  * progress? Synchronous (no async) so callers can atomically gate other
@@ -586,7 +650,7 @@ export declare class EventDispatcher {
586
650
  *
587
651
  * Public (not private) because Phase 4's `AuthHealthMonitor.checkAll()`
588
652
  * shares the same skip-while-morning-routine-active invariant as the
589
- * hourly check, and injects this method as an option so a probe tick
653
+ * activity scan, and injects this method as an option so a probe tick
590
654
  * running concurrently with morning routine can no-op cleanly. See
591
655
  * `docs/design/09-safety-cost.md` §9.5.4.
592
656
  */
@@ -608,8 +672,25 @@ export declare class EventDispatcher {
608
672
  * non-scheduled events or already-terminal rows.
609
673
  */
610
674
  private releaseClaimedSchedule;
675
+ /**
676
+ * Throttle for spawn-gate skip audit rows. A released schedule row is
677
+ * due immediately, so the watcher re-claims it every poll tick (5s
678
+ * default) for the whole outage — without this, one offline day per
679
+ * pending row writes ~17k identical agent_actions rows. Keyed by
680
+ * (schedule id | event type) × reason so distinct routines and
681
+ * distinct reasons each still get their own first row, and a reason
682
+ * flip (offline → auth_unhealthy) is recorded promptly.
683
+ */
684
+ private shouldWriteSpawnGateSkipAudit;
611
685
  private dispatchSafe;
612
686
  private dispatch;
687
+ /**
688
+ * BACKGROUND_TASK_RUNNER_DESIGN.md §4.2 — dispatch branch for
689
+ * `scheduled.background_task`. Defers to `handleScheduledBackgroundTask`
690
+ * (validation + row creation + runner handoff) and translates the
691
+ * outcome into the `agent_schedule.status` write.
692
+ */
693
+ private handleScheduledBackgroundTaskDispatch;
613
694
  /**
614
695
  * BROWSER_TASK_REDESIGN_PLAN.md §6.2 + §7 — dispatch branch for
615
696
  * `scheduled.browser_task`. Defers the heavy lifting to