@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
@@ -4,7 +4,37 @@ import type { EventBus } from "./event-bus.js";
4
4
  import type { MessageDelivery } from "../adapters/message-hub.js";
5
5
  import type { AgentEnabledCache } from "./agents/loader.js";
6
6
  /**
7
- * Build the cron expression that drives the hourly check.
7
+ * Cadence of the morning self-heal tick. The tick is cheap (three indexed
8
+ * SQLite reads in the common healthy case), and 10 minutes bounds the
9
+ * worst-case detection latency for a swallowed 04:00 cron fire at
10
+ * `MORNING_MISSED_FIRE_GRACE_MINUTES + 10`. Deliberately a dedicated
11
+ * interval rather than a rider on the activity-scan cron: the watchdog
12
+ * historically rode that cron and went silently dead the moment an
13
+ * operator set `activityScanEnabled=false` — exactly the configuration
14
+ * where the morning routine has no other safety net.
15
+ */
16
+ export declare const MORNING_SELF_HEAL_INTERVAL_MS: number;
17
+ /**
18
+ * Per-agent-day cap on hung-run recovery flips. Each flip re-runs the
19
+ * morning pipeline (pre-pass + Stage A — real backend spend), so a
20
+ * deterministically-wedging environment must not be retried every
21
+ * stall-threshold window all day. Past the cap the self-heal degrades to
22
+ * alert-only; the owner DM and a daemon restart are the escape hatches.
23
+ */
24
+ export declare const MAX_SELFHEAL_REQUEUES_PER_AGENT_DAY = 2;
25
+ /**
26
+ * Missed-fire suppression window after process start. Boot catchup owns
27
+ * stale-today.md recovery at startup and runs the morning routine
28
+ * INLINE — no wake row exists for `shouldQueueMissedMorningFire` to
29
+ * dedup against, and its attempt audit row only appears once the
30
+ * fetch-window pre-pass hands over to Stage A. A pathologically slow
31
+ * pre-pass must not read as a missed fire, so the layer stays quiet
32
+ * until the boot path has long since either produced attempt rows or
33
+ * died (in which case the next tick after the window picks it up).
34
+ */
35
+ export declare const MISSED_FIRE_BOOT_SUPPRESSION_MS: number;
36
+ /**
37
+ * Build the cron expression that drives the activity scan.
8
38
  *
9
39
  * Two regimes:
10
40
  *
@@ -17,7 +47,7 @@ import type { AgentEnabledCache } from "./agents/loader.js";
17
47
  * 2. **Arbitrary interval** (anything else, e.g. 7, 45, 90, 120, 720,
18
48
  * 1440): we emit `"* <hourRange> * * *"` (every minute within active
19
49
  * hours). The caller is expected to gate each tick with
20
- * `shouldFireHourlyTickAt(...)`, which anchors the cadence to
50
+ * `shouldFireActivityScanTickAt(...)`, which anchors the cadence to
21
51
  * `activeStartHour` via `((h*60 + m) - activeStartHour*60) %
22
52
  * intervalMinutes`. This anchor matters: a midnight-anchored modulo
23
53
  * plus `activeStartHour > 0` would silently drop intervals where the
@@ -29,9 +59,9 @@ import type { AgentEnabledCache } from "./agents/loader.js";
29
59
  *
30
60
  * The minute-tick cron does fire 60× per hour even when most ticks are
31
61
  * no-ops, but the callback's first action is the modulo check — overhead
32
- * is negligible compared to the actual hourly-check work.
62
+ * is negligible compared to the actual activity-scan work.
33
63
  */
34
- export declare function buildHourlyCronExpr(intervalMinutes: number, startHour: number, endHourExclusive: number): string;
64
+ export declare function buildActivityScanCronExpr(intervalMinutes: number, startHour: number, endHourExclusive: number): string;
35
65
  /**
36
66
  * Returns true when a minute-tick of the hourly cron should actually fire.
37
67
  *
@@ -50,7 +80,7 @@ export declare function buildHourlyCronExpr(intervalMinutes: number, startHour:
50
80
  * so the divisor early-return doesn't change behavior — it's just
51
81
  * explicit about which path the cron expression itself handles.
52
82
  */
53
- export declare function shouldFireHourlyTickAt(localHour: number, localMinute: number, intervalMinutes: number, activeStartHour: number): boolean;
83
+ export declare function shouldFireActivityScanTickAt(localHour: number, localMinute: number, intervalMinutes: number, activeStartHour: number): boolean;
54
84
  /**
55
85
  * Cron expression for the morning user-profile sweep: 10 min before the
56
86
  * day boundary, wrapping backward across midnight. For the default
@@ -109,12 +139,12 @@ export declare class AgentScheduler {
109
139
  private noFutureTasksWarned;
110
140
  private onDayBoundary;
111
141
  private sendDm;
112
- private onHourlyCheck;
142
+ private onActivityScan;
113
143
  /**
114
144
  * Phase 4 auth probe hook — fired on every hourly cron tick BEFORE
115
- * `onHourlyCheck` so the probe gets a chance to refresh DB cache +
145
+ * `onActivityScan` so the probe gets a chance to refresh DB cache +
116
146
  * emit DMs even when the observation-threshold gate would skip the
117
- * hourly check itself. The AuthHealthMonitor.checkAll() method owns
147
+ * activity scan itself. The AuthHealthMonitor.checkAll() method owns
118
148
  * its own kill-switch and morning-routine skip; the scheduler only
119
149
  * applies the same `autonomousGate` short-circuit that protects the
120
150
  * other cron callbacks.
@@ -122,10 +152,24 @@ export declare class AgentScheduler {
122
152
  * See `docs/design/09-safety-cost.md` §9.5.4 for the gate
123
153
  * ordering: morning-routine → hourly-already-running → auth probe
124
154
  * → observation-threshold. Steps 1 + 2 are handled inside
125
- * `triggerHourlyCheck`; step 3 is this callback; step 4 is the
126
- * threshold gate inside `triggerHourlyCheck`.
155
+ * `triggerActivityScan`; step 3 is this callback; step 4 is the
156
+ * threshold gate inside `triggerActivityScan`.
127
157
  */
128
158
  private onAuthProbe;
159
+ /**
160
+ * SELF_TUNING_REVIEW_CYCLE_DESIGN.md §3.4 Phase 3 — auto-revert monitor.
161
+ * Piggybacks the hourly cron tick (P2 — zero new scheduled sessions),
162
+ * fired AHEAD of the per-agent enabled gate and the autonomous setup
163
+ * gate so rollback safety survives the owner disabling the activity-scan
164
+ * Agent or a setup-gated daemon; the callback owns its own 1/day
165
+ * throttle, per-entry isolation, and DM emission. Remaining coupling:
166
+ * with `activityScanEnabled=false` this cron is never registered and
167
+ * applied changes stay unverified until the check is re-enabled —
168
+ * acceptable because R1/R3 govern the (now-idle) hourly pipeline
169
+ * itself; an applied R5 (`feedbackLessonMaxBytesGlobal`) change would
170
+ * sit unverified, with `!revert tuning` as the manual escape hatch.
171
+ */
172
+ private onSelfTuningRevertMonitor;
129
173
  /**
130
174
  * B-004 Phase 2a — nightly context-index reconciler callback (§4.1).
131
175
  * Fires at 03:45 local (dayBoundaryHour - 15 min) via an internal cron
@@ -201,6 +245,25 @@ export declare class AgentScheduler {
201
245
  private nudgeSeq;
202
246
  private observedSeq;
203
247
  private sleepWaiter;
248
+ /**
249
+ * Detects machine sleep / forward clock jumps and replays the cron
250
+ * triggers the sleep swallowed (node-cron never fires missed ticks).
251
+ * See {@link runWakeCatchup}.
252
+ */
253
+ private readonly wakeDetector;
254
+ /**
255
+ * Independent self-heal tick for the morning routine (alert + recover +
256
+ * missed-fire re-queue). See {@link runMorningSelfHeal}. Kept off the
257
+ * activity-scan cron on purpose — that cron is operator-disableable.
258
+ */
259
+ private morningSelfHealTimer;
260
+ /**
261
+ * Wall-clock instant this scheduler instance was constructed (one
262
+ * instance per daemon process). Drives the missed-fire boot
263
+ * suppression; tests override via cast to simulate a long-lived
264
+ * process.
265
+ */
266
+ private startedAtMs;
204
267
  constructor(eventBus: EventBus, db: Database.Database, config: AgentConfig);
205
268
  /**
206
269
  * Register a callback that runs at the day boundary (4 AM) BEFORE
@@ -212,14 +275,21 @@ export declare class AgentScheduler {
212
275
  * When a task_type='dm' row is due, the message is sent directly without an agent.
213
276
  */
214
277
  setSendDmCallback(fn: (message: string, platforms?: string[]) => Promise<MessageDelivery[]>): void;
215
- setHourlyCheckCallback(fn: (source: string) => Promise<unknown>): void;
278
+ setActivityScanCallback(fn: (source: string) => Promise<unknown>): void;
216
279
  /**
217
280
  * Register the Phase 4 auth probe callback. Called on each hourly
218
- * cron tick BEFORE the hourly-check observation threshold gate so
219
- * the probe continues to run even when the hourly check itself
281
+ * cron tick BEFORE the activity-scan observation threshold gate so
282
+ * the probe continues to run even when the activity scan itself
220
283
  * would be skipped for lack of pending observations.
221
284
  */
222
285
  setAuthProbeCallback(fn: () => Promise<unknown>): void;
286
+ /**
287
+ * Register the Phase 3 self-tuning auto-revert monitor. Called on each
288
+ * hourly cron tick alongside the auth probe; the monitor throttles
289
+ * itself to one pass per day and is a no-op until the actuator has
290
+ * written ledger entries.
291
+ */
292
+ setSelfTuningRevertMonitorCallback(fn: () => Promise<unknown>): void;
223
293
  /**
224
294
  * Register the context-index reconciler cron callback. Called every
225
295
  * night at 03:45 local; the callback is expected to be fire-and-forget
@@ -284,9 +354,9 @@ export declare class AgentScheduler {
284
354
  * (CLAUDE.md "morning_routine wake stall"). When the morning routine
285
355
  * never writes an `agent_actions.result='success'` row, the dedup
286
356
  * inside `queueMorningRoutineWake` keeps the stuck wake row pinned in
287
- * `pending`/`running` and the hourly-check pre-routine gate silently
357
+ * `pending`/`running` and the activity-scan pre-routine gate silently
288
358
  * skips every subsequent autonomous tick. The user gets no morning
289
- * brief, no evening review, no hourly check, and no error — the
359
+ * brief, no evening review, no activity scan, and no error — the
290
360
  * system is functionally dead until the wake row clears.
291
361
  *
292
362
  * Detection: oldest `task_type='wake'` row tied to
@@ -307,6 +377,75 @@ export declare class AgentScheduler {
307
377
  * cron-callback exception.
308
378
  */
309
379
  private checkMorningRoutineStall;
380
+ /**
381
+ * Self-heal tick for the morning routine. Three layers:
382
+ *
383
+ * 1. **Recover** — a wake row stuck in `running` whose claim
384
+ * (`task_context.claimedAt`) is ≥ stall-threshold minutes old with
385
+ * no success today (machine slept mid-run, the backend stream died)
386
+ * is flipped back to `pending` so the ScheduleWatcher re-claims it.
387
+ * Without this, `queueMorningRoutineWake` dedups into the corpse
388
+ * forever and the day stays frozen until a daemon restart. Runs
389
+ * BEFORE the alert so a stall the self-heal is about to fix doesn't
390
+ * burn the once-per-day DM budget on a misleading "restart the
391
+ * daemon" message; if the re-run wedges too, the next tick still
392
+ * alerts (the row's created_at age keeps growing). Capped at
393
+ * {@link MAX_SELFHEAL_REQUEUES_PER_AGENT_DAY} re-runs per agent-day
394
+ * so a deterministic hang cannot burn backend spend every
395
+ * threshold-window all day. Worst case if the original execution is
396
+ * alive after all: one duplicate morning run, serialized by the
397
+ * today-write-lock.
398
+ * 2. **Alert** — the stall watchdog ({@link checkMorningRoutineStall}).
399
+ * Previously this only ran on activity-scan cron ticks, so
400
+ * `activityScanEnabled=false` silently disabled it; this timer is the
401
+ * guaranteed host now (the cron-tick invocation remains, made safe
402
+ * by the watchdog's mutex + per-day DM dedup).
403
+ * 3. **Missed fire** — no attempt, no wake row, agent-day older than the
404
+ * grace window: the boundary cron tick was swallowed (sleep shorter
405
+ * than the WakeDetector's gap threshold straddling 04:00, or a
406
+ * detector failure) — open the day exactly the way the cron and the
407
+ * wake catch-up do (day-boundary callback → daily cleanup → wake row
408
+ * with due reviews riding the post-catchup context). Never resurrects
409
+ * an exhausted retry chain: failed attempts leave audit rows, which
410
+ * `shouldQueueMissedMorningFire` treats as "attempted". Suppressed
411
+ * during the first {@link MISSED_FIRE_BOOT_SUPPRESSION_MS} of process
412
+ * life: that window belongs to the boot catchup, whose INLINE morning
413
+ * run leaves no wake row for the predicate to dedup against (a slow
414
+ * pre-pass there must not look like a missed fire).
415
+ *
416
+ * Fire-and-forget; each layer owns its own error containment.
417
+ */
418
+ private runMorningSelfHeal;
419
+ /**
420
+ * Number of self-heal re-queues already performed this agent-day,
421
+ * counted from the `morning_routine.selfheal_requeued` audit rows the
422
+ * recovery layer writes. Throws propagate to the recovery layer's
423
+ * catch (fail-closed: an unreadable counter must not unlock unlimited
424
+ * re-runs).
425
+ */
426
+ private countSelfHealRequeuesToday;
427
+ /**
428
+ * Replay cron triggers swallowed by a machine sleep (or forward clock
429
+ * jump). node-cron does not fire ticks whose time passed while the
430
+ * process was suspended, so without this a daemon that sleeps through
431
+ * 04:00 / 18:00 / a Friday 19:00 recovers those routines only on the
432
+ * next daemon RESTART (`bootstrap/catchup.ts`) — possibly days later.
433
+ *
434
+ * Reuses the boot-time catchup's decision predicates so the two paths
435
+ * cannot drift: `getDueCatchupRoutines` dedups against `agent_actions`,
436
+ * `shouldCatchUpActivityScan` replays at most the current slot, and the
437
+ * morning routine goes through `queueMorningRoutineWake`'s DB-backed
438
+ * dedup. Downstream dispatch-time gates (autonomous setup gate,
439
+ * morning-pending review gate) still apply.
440
+ *
441
+ * Ordering: when the morning routine has not completed for the current
442
+ * agent-day, the review routines and the activity scan ride along on the
443
+ * wake row's `postCatchupRoutines` / `postCatchupActivityScan` context
444
+ * (same replay mechanism the boot catchup uses) so they run AFTER the
445
+ * day is opened instead of being skipped by the dispatcher's
446
+ * pre-routine gate.
447
+ */
448
+ private runWakeCatchup;
310
449
  start(): void;
311
450
  stop(): void;
312
451
  /**
@@ -347,7 +486,7 @@ export declare class AgentScheduler {
347
486
  */
348
487
  queueMorningRoutineWake(source: string, options?: {
349
488
  postCatchupRoutines?: string[];
350
- postCatchupHourlyCheck?: boolean;
489
+ postCatchupActivityScan?: boolean;
351
490
  }): {
352
491
  inserted: boolean;
353
492
  existingId?: number;
@@ -360,6 +499,26 @@ export declare class AgentScheduler {
360
499
  * UPDATE ... SET status='running' WHERE status='pending' succeeds.
361
500
  */
362
501
  private startScheduleWatcher;
502
+ /**
503
+ * Quiet-hours deferral for a claimed `agent_schedule` row (shared by the
504
+ * `browser_task` always-on-by-config path and the `agent.task` per-row
505
+ * opt-in, QUIET_HOURS_HARDENING_PLAN.md §6). When the current wall-clock
506
+ * instant falls inside the configured quiet-hours window, the row is pushed
507
+ * forward to the next quiet-hours-end boundary (status reverted to
508
+ * `pending` so the next ScheduleWatcher tick re-evaluates), one
509
+ * `agent_actions` audit row is written per deferral so the user can see the
510
+ * delay, and `true` is returned. Returns `false` when outside the window —
511
+ * or when `nextQuietHoursEndMs` cannot resolve a boundary, which inside a
512
+ * quiet-hours predicate that just returned true would mean a 24-hour
513
+ * window; the runtime-settings schema disallows this (equal start/end
514
+ * short-circuits the predicate), so it cannot occur in normal operation.
515
+ * Falling through to dispatch beats re-deferring forever.
516
+ *
517
+ * `agentId` (the owning user Agent's slug from `task_context.agent_id`)
518
+ * stamps the audit row's `agent_id` column so the deferral is attributable
519
+ * per Agent; the browser_task path has no owning Agent and passes none.
520
+ */
521
+ private deferClaimedRowForQuietHours;
363
522
  /**
364
523
  * Sleep for `ms` milliseconds, but resolve early when `stop()` or
365
524
  * `nudgeWatcher()` fire. Used by the ScheduleWatcher between polls so