@aitne/daemon 0.1.9 → 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.
- package/dist/adapters/adapter-watchdog.d.ts +70 -0
- package/dist/adapters/adapter-watchdog.js +115 -0
- package/dist/adapters/discord.d.ts +17 -1
- package/dist/adapters/discord.js +33 -0
- package/dist/adapters/notification-manager.d.ts +27 -1
- package/dist/adapters/notification-manager.js +54 -39
- package/dist/adapters/slack-adapter.d.ts +26 -1
- package/dist/adapters/slack-adapter.js +41 -0
- package/dist/adapters/telegram-adapter.d.ts +18 -1
- package/dist/adapters/telegram-adapter.js +41 -2
- package/dist/adapters/types.d.ts +20 -0
- package/dist/adapters/whatsapp-adapter.d.ts +26 -7
- package/dist/adapters/whatsapp-adapter.js +74 -21
- package/dist/api/env-writer.d.ts +1 -0
- package/dist/api/env-writer.js +17 -7
- package/dist/api/helpers/agent-errors-registry.d.ts +5 -5
- package/dist/api/helpers/agent-errors-registry.js +5 -5
- package/dist/api/routes/agent-schedule.js +5 -1
- package/dist/api/routes/agent.js +33 -12
- package/dist/api/routes/agents/index.js +75 -16
- package/dist/api/routes/agents/views.d.ts +37 -2
- package/dist/api/routes/agents/views.js +64 -2
- package/dist/api/routes/apple-calendar.js +4 -1
- package/dist/api/routes/background-task.d.ts +22 -0
- package/dist/api/routes/background-task.js +338 -0
- package/dist/api/routes/browser-history.js +9 -1
- package/dist/api/routes/calendar.js +12 -2
- package/dist/api/routes/context/path-resolve.js +6 -1
- package/dist/api/routes/context/permissions.js +12 -2
- package/dist/api/routes/context/snapshots.js +0 -3
- package/dist/api/routes/context/write.js +3 -17
- package/dist/api/routes/dashboard/config.js +58 -12
- package/dist/api/routes/dashboard/cost-approvals.js +66 -0
- package/dist/api/routes/dashboard/notifications.js +9 -9
- package/dist/api/routes/dashboard/oauth-google.js +5 -3
- package/dist/api/routes/feedback.d.ts +3 -0
- package/dist/api/routes/feedback.js +349 -0
- package/dist/api/routes/git.js +10 -3
- package/dist/api/routes/github.js +5 -1
- package/dist/api/routes/integrations/crud-patch.js +5 -1
- package/dist/api/routes/integrations-reconcile.js +2 -2
- package/dist/api/routes/mcp.js +65 -13
- package/dist/api/routes/notion.d.ts +1 -1
- package/dist/api/routes/observations.js +7 -7
- package/dist/api/routes/obsidian.d.ts +1 -1
- package/dist/api/routes/receipts.js +5 -1
- package/dist/api/routes/setup-migrate.js +1 -1
- package/dist/api/routes/setup.js +1 -1
- package/dist/api/routes/task-flows.d.ts +1 -1
- package/dist/api/routes/task-flows.js +1 -1
- package/dist/api/routes/tuning.d.ts +29 -0
- package/dist/api/routes/tuning.js +304 -0
- package/dist/api/server.d.ts +44 -16
- package/dist/api/server.js +12 -0
- package/dist/bootstrap/adapters.d.ts +19 -0
- package/dist/bootstrap/adapters.js +61 -0
- package/dist/bootstrap/api.d.ts +5 -3
- package/dist/bootstrap/api.js +45 -13
- package/dist/bootstrap/catchup.d.ts +1 -1
- package/dist/bootstrap/catchup.js +11 -11
- package/dist/bootstrap/event-pipeline.d.ts +11 -0
- package/dist/bootstrap/event-pipeline.js +246 -8
- package/dist/bootstrap/observers.js +9 -6
- package/dist/bootstrap/schedule-helpers.d.ts +104 -6
- package/dist/bootstrap/schedule-helpers.js +172 -19
- package/dist/config.js +32 -12
- package/dist/core/agent-core.d.ts +33 -1
- package/dist/core/agent-core.js +36 -1
- package/dist/core/agents/activity-scan-cadence.d.ts +103 -0
- package/dist/core/agents/activity-scan-cadence.js +127 -0
- package/dist/core/agents/agent-route-override.d.ts +53 -0
- package/dist/core/agents/agent-route-override.js +69 -0
- package/dist/core/agents/builtin-registry.d.ts +51 -14
- package/dist/core/agents/builtin-registry.js +92 -15
- package/dist/core/agents/config-gate-reconcile.d.ts +38 -0
- package/dist/core/agents/config-gate-reconcile.js +51 -0
- package/dist/core/agents/cron-substitute.d.ts +1 -1
- package/dist/core/agents/cron-substitute.js +1 -1
- package/dist/core/agents/custom-routine-migration.d.ts +60 -0
- package/dist/core/agents/custom-routine-migration.js +149 -0
- package/dist/core/agents/firing-blocked.d.ts +1 -1
- package/dist/core/agents/hourly-cadence.d.ts +102 -0
- package/dist/core/agents/hourly-cadence.js +126 -0
- package/dist/core/agents/loader-boot.js +23 -0
- package/dist/core/agents/loader.d.ts +19 -0
- package/dist/core/agents/loader.js +34 -2
- package/dist/core/agents/override-merge.d.ts +1 -1
- package/dist/core/agents/override-merge.js +9 -1
- package/dist/core/agents/recurrence-convert.d.ts +1 -1
- package/dist/core/agents/recurrence-convert.js +1 -1
- package/dist/core/agents/recurring-schedule-adapter.js +8 -0
- package/dist/core/alerts.js +6 -6
- package/dist/core/backends/auth-health-monitor.d.ts +2 -2
- package/dist/core/backends/auth-health-monitor.js +1 -1
- package/dist/core/backends/backend-router.d.ts +27 -1
- package/dist/core/backends/backend-router.js +165 -1
- package/dist/core/backends/claude-code-core.d.ts +71 -31
- package/dist/core/backends/claude-code-core.js +282 -54
- package/dist/core/backends/cli-quota-guards.d.ts +29 -1
- package/dist/core/backends/cli-quota-guards.js +40 -5
- package/dist/core/backends/codex-core.d.ts +6 -0
- package/dist/core/backends/codex-core.js +22 -6
- package/dist/core/backends/failure-spend.d.ts +58 -0
- package/dist/core/backends/failure-spend.js +137 -0
- package/dist/core/backends/gemini-cli-core.d.ts +6 -0
- package/dist/core/backends/gemini-cli-core.js +38 -6
- package/dist/core/backends/model-registry.d.ts +1 -1
- package/dist/core/backends/model-registry.js +4 -4
- package/dist/core/backends/opencode-core.d.ts +1 -1
- package/dist/core/backends/opencode-core.js +5 -5
- package/dist/core/backends/plan-presets.js +47 -18
- package/dist/core/bang-commands/commands-cost.js +3 -1
- package/dist/core/bang-commands/commands-report.js +4 -3
- package/dist/core/bang-commands/commands-research.js +4 -1
- package/dist/core/bang-commands/commands-revert-tuning.d.ts +18 -0
- package/dist/core/bang-commands/commands-revert-tuning.js +63 -0
- package/dist/core/bang-commands/commands-stop-start.js +3 -3
- package/dist/core/bang-commands/commands-task-control.d.ts +19 -0
- package/dist/core/bang-commands/commands-task-control.js +147 -0
- package/dist/core/bang-commands/commands-wiki.js +5 -5
- package/dist/core/bang-commands/index.d.ts +2 -0
- package/dist/core/bang-commands/index.js +12 -0
- package/dist/core/bang-commands/registry.d.ts +12 -0
- package/dist/core/browser-history/research-cluster-fanout.d.ts +28 -14
- package/dist/core/browser-history/research-cluster-fanout.js +39 -16
- package/dist/core/channel-timeline.d.ts +5 -1
- package/dist/core/channel-timeline.js +13 -0
- package/dist/core/context/index-reconciler.js +5 -2
- package/dist/core/context/policy-index-reconciler.d.ts +6 -4
- package/dist/core/context/policy-index-runner.js +25 -6
- package/dist/core/context-builder-calendar.js +10 -2
- package/dist/core/context-builder-conversation.d.ts +8 -1
- package/dist/core/context-builder-conversation.js +41 -7
- package/dist/core/context-builder-yesterday.js +4 -3
- package/dist/core/context-builder.d.ts +7 -2
- package/dist/core/context-builder.js +193 -5
- package/dist/core/context-file-serializer.d.ts +1 -1
- package/dist/core/context-file-serializer.js +1 -1
- package/dist/core/context-health.js +2 -2
- package/dist/core/context-paths.d.ts +11 -1
- package/dist/core/context-paths.js +17 -1
- package/dist/core/context-validation/prepare-write.js +1 -1
- package/dist/core/context-validation/routine-rulebook.d.ts +1 -1
- package/dist/core/context-vault-aliases.d.ts +0 -13
- package/dist/core/context-vault-aliases.js +37 -0
- package/dist/core/custom-routines.d.ts +99 -0
- package/dist/core/custom-routines.js +187 -0
- package/dist/core/daemon-api-cli.js +50 -1
- package/dist/core/day-boundary.d.ts +46 -0
- package/dist/core/day-boundary.js +40 -0
- package/dist/core/dispatcher-activity-scan.d.ts +221 -0
- package/dist/core/dispatcher-activity-scan.js +775 -0
- package/dist/core/dispatcher-error-handling.d.ts +6 -11
- package/dist/core/dispatcher-error-handling.js +38 -62
- package/dist/core/dispatcher-hourly-check.js +6 -1
- package/dist/core/dispatcher-message-handler.d.ts +10 -0
- package/dist/core/dispatcher-message-handler.js +24 -0
- package/dist/core/dispatcher-morning-routine.d.ts +6 -6
- package/dist/core/dispatcher-morning-routine.js +13 -13
- package/dist/core/dispatcher-result-processor.d.ts +33 -0
- package/dist/core/dispatcher-result-processor.js +167 -11
- package/dist/core/dispatcher-scheduled-background-task.d.ts +42 -0
- package/dist/core/dispatcher-scheduled-background-task.js +89 -0
- package/dist/core/dispatcher-scheduled-tasks.d.ts +104 -1
- package/dist/core/dispatcher-scheduled-tasks.js +480 -8
- package/dist/core/dispatcher-task-delivery.d.ts +105 -0
- package/dist/core/dispatcher-task-delivery.js +555 -0
- package/dist/core/dispatcher-types.d.ts +48 -9
- package/dist/core/dispatcher-types.js +3 -3
- package/dist/core/dispatcher.d.ts +112 -31
- package/dist/core/dispatcher.js +297 -60
- package/dist/core/dm-freshness-metrics.d.ts +1 -1
- package/dist/core/drift-effects.js +2 -2
- package/dist/core/feedback/consolidation-prep.d.ts +94 -0
- package/dist/core/feedback/consolidation-prep.js +254 -0
- package/dist/core/feedback/eviction-scorer.d.ts +81 -0
- package/dist/core/feedback/eviction-scorer.js +136 -0
- package/dist/core/feedback/lesson-format.d.ts +79 -0
- package/dist/core/feedback/lesson-format.js +199 -0
- package/dist/core/feedback/lesson-injection.d.ts +98 -0
- package/dist/core/feedback/lesson-injection.js +174 -0
- package/dist/core/feedback/lesson-merge.d.ts +51 -0
- package/dist/core/feedback/lesson-merge.js +88 -0
- package/dist/core/feedback/lesson-store-overview.d.ts +46 -0
- package/dist/core/feedback/lesson-store-overview.js +42 -0
- package/dist/core/feedback/promotion-gate.d.ts +69 -0
- package/dist/core/feedback/promotion-gate.js +117 -0
- package/dist/core/feedback/regeneralization-prep.d.ts +87 -0
- package/dist/core/feedback/regeneralization-prep.js +152 -0
- package/dist/core/feedback/scope-parser.d.ts +86 -0
- package/dist/core/feedback/scope-parser.js +141 -0
- package/dist/core/feedback/self-performance-prep.d.ts +186 -0
- package/dist/core/feedback/self-performance-prep.js +541 -0
- package/dist/core/feedback/tuning-actuator.d.ts +198 -0
- package/dist/core/feedback/tuning-actuator.js +432 -0
- package/dist/core/feedback/tuning-recommender.d.ts +247 -0
- package/dist/core/feedback/tuning-recommender.js +580 -0
- package/dist/core/feedback/tuning-revert-monitor.d.ts +90 -0
- package/dist/core/feedback/tuning-revert-monitor.js +213 -0
- package/dist/core/health-monitor.d.ts +6 -0
- package/dist/core/health-monitor.js +1 -1
- package/dist/core/injection-policy.d.ts +83 -1
- package/dist/core/injection-policy.js +61 -3
- package/dist/core/integration-main-backend.js +4 -0
- package/dist/core/management-md.d.ts +2 -2
- package/dist/core/management-md.js +51 -13
- package/dist/core/morning/orchestrator.d.ts +2 -2
- package/dist/core/morning/orchestrator.js +2 -2
- package/dist/core/notification-gate.d.ts +64 -0
- package/dist/core/notification-gate.js +51 -0
- package/dist/core/notification-rate-limit.d.ts +40 -0
- package/dist/core/notification-rate-limit.js +50 -0
- package/dist/core/policy-files.d.ts +1 -1
- package/dist/core/policy-files.js +2 -2
- package/dist/core/pre-pass-freshness.d.ts +4 -4
- package/dist/core/retention.d.ts +5 -0
- package/dist/core/retention.js +20 -4
- package/dist/core/review-context.d.ts +1 -1
- package/dist/core/review-context.js +10 -5
- package/dist/core/roadmap-write-lock.d.ts +2 -1
- package/dist/core/roadmap-write-lock.js +15 -10
- package/dist/core/routine-acquisition-plan.d.ts +47 -1
- package/dist/core/routine-acquisition-plan.js +78 -20
- package/dist/core/routine-fetch-window-retry.js +7 -4
- package/dist/core/routine-fetch-window-runner.d.ts +39 -3
- package/dist/core/routine-fetch-window-runner.js +264 -13
- package/dist/core/routine-windows.d.ts +2 -2
- package/dist/core/routine-windows.js +8 -5
- package/dist/core/scheduler.d.ts +175 -16
- package/dist/core/scheduler.js +559 -102
- package/dist/core/signal-detector.d.ts +51 -1
- package/dist/core/signal-detector.js +321 -24
- package/dist/core/skills-compiler-denied-tools.js +2 -2
- package/dist/core/skills-compiler-skill-index.d.ts +2 -2
- package/dist/core/skills-compiler-skill-index.js +2 -2
- package/dist/core/skills-compiler-variants.d.ts +1 -1
- package/dist/core/skills-compiler-variants.js +8 -0
- package/dist/core/skills-compiler.d.ts +29 -26
- package/dist/core/skills-compiler.js +117 -81
- package/dist/core/skills-manifest.d.ts +37 -0
- package/dist/core/skills-manifest.js +73 -2
- package/dist/core/sleep-inhibitor.d.ts +79 -0
- package/dist/core/sleep-inhibitor.js +132 -0
- package/dist/core/slim-system-prompt-loader.d.ts +77 -0
- package/dist/core/slim-system-prompt-loader.js +141 -0
- package/dist/core/spawn-gates.d.ts +126 -0
- package/dist/core/spawn-gates.js +180 -0
- package/dist/core/today-direct-writer.d.ts +60 -14
- package/dist/core/today-direct-writer.js +90 -13
- package/dist/core/today-write-lock.d.ts +4 -2
- package/dist/core/today-write-lock.js +30 -20
- package/dist/core/wake-detector.d.ts +55 -0
- package/dist/core/wake-detector.js +80 -0
- package/dist/core/wiki/compile-lock.d.ts +1 -1
- package/dist/core/wiki/compile-lock.js +1 -1
- package/dist/core/wiki/wiki-fts.js +13 -6
- package/dist/core/workdir.js +15 -6
- package/dist/db/activity-scan-signals.d.ts +77 -0
- package/dist/db/activity-scan-signals.js +378 -0
- package/dist/db/agents-store.d.ts +28 -0
- package/dist/db/agents-store.js +62 -0
- package/dist/db/background-task-clarifications-store.d.ts +81 -0
- package/dist/db/background-task-clarifications-store.js +152 -0
- package/dist/db/background-task-store.d.ts +207 -0
- package/dist/db/background-task-store.js +380 -0
- package/dist/db/browser-history-store.d.ts +39 -6
- package/dist/db/browser-history-store.js +51 -7
- package/dist/db/browser-task-clarifications-store.d.ts +12 -0
- package/dist/db/browser-task-clarifications-store.js +35 -5
- package/dist/db/browser-task-store.d.ts +3 -0
- package/dist/db/browser-task-store.js +29 -4
- package/dist/db/deferred-dm.d.ts +86 -0
- package/dist/db/deferred-dm.js +199 -0
- package/dist/db/feedback-signals-store.d.ts +77 -0
- package/dist/db/feedback-signals-store.js +144 -0
- package/dist/db/migrations.js +380 -0
- package/dist/db/observations.d.ts +2 -2
- package/dist/db/observations.js +3 -3
- package/dist/db/schema.js +260 -22
- package/dist/db/voice-transcripts-store.d.ts +1 -1
- package/dist/index.js +86 -29
- package/dist/messaging/browser-task-mcp-notifier.d.ts +12 -70
- package/dist/messaging/browser-task-mcp-notifier.js +30 -151
- package/dist/messaging/browser-task-screenshot-attachment.d.ts +15 -0
- package/dist/messaging/browser-task-screenshot-attachment.js +63 -0
- package/dist/observers/delegated-sync-worker.d.ts +6 -6
- package/dist/observers/delegated-sync-worker.js +10 -10
- package/dist/observers/git-delegated-cron.d.ts +1 -1
- package/dist/observers/git-delegated-cron.js +2 -2
- package/dist/observers/github-poller-classifier.d.ts +3 -3
- package/dist/observers/github-poller-classifier.js +3 -3
- package/dist/observers/imminent-event-scheduler.d.ts +1 -1
- package/dist/observers/imminent-event-scheduler.js +1 -1
- package/dist/observers/mail-poller.d.ts +1 -0
- package/dist/observers/mail-poller.js +42 -3
- package/dist/observers/observation-summarizer/summarizer-client.d.ts +2 -2
- package/dist/observers/observation-summarizer/summarizer-client.js +2 -2
- package/dist/observers/observation-summarizer/worker.d.ts +2 -2
- package/dist/observers/observation-summarizer/worker.js +4 -4
- package/dist/observers/obsidian-watcher.d.ts +1 -1
- package/dist/observers/obsidian-watcher.js +1 -1
- package/dist/safety/agent-write-tracker.d.ts +4 -4
- package/dist/safety/agent-write-tracker.js +4 -4
- package/dist/safety/always-disallowed.d.ts +1 -1
- package/dist/safety/always-disallowed.js +39 -0
- package/dist/safety/audit.d.ts +43 -5
- package/dist/safety/audit.js +86 -18
- package/dist/safety/risk-classifier.d.ts +6 -0
- package/dist/safety/risk-classifier.js +97 -18
- package/dist/scheduler/activity-scan-gate.d.ts +86 -0
- package/dist/scheduler/activity-scan-gate.js +132 -0
- package/dist/services/background-task/background-task-budget.d.ts +80 -0
- package/dist/services/background-task/background-task-budget.js +91 -0
- package/dist/services/background-task/background-task-driver.d.ts +105 -0
- package/dist/services/background-task/background-task-driver.js +416 -0
- package/dist/services/background-task/background-task-runner.d.ts +96 -0
- package/dist/services/background-task/background-task-runner.js +673 -0
- package/dist/services/background-task/background-task-tools.d.ts +84 -0
- package/dist/services/background-task/background-task-tools.js +247 -0
- package/dist/services/background-task/background-task-transition-events.d.ts +43 -0
- package/dist/services/background-task/background-task-transition-events.js +54 -0
- package/dist/services/browser-history/automation/egress-denylist.d.ts +1 -1
- package/dist/services/browser-history/automation/egress-denylist.js +34 -8
- package/dist/services/browser-history/lifecycle/platform.js +44 -2
- package/dist/services/browser-history/managed-chromium/sandbox-launcher.js +0 -1
- package/dist/services/browser-task/browser-task-runner.js +53 -8
- package/dist/services/mcp/probe.js +30 -8
- package/dist/services/observations-batch.d.ts +1 -1
- package/dist/services/observations-batch.js +2 -2
- package/dist/settings/runtime-settings.d.ts +45 -12
- package/dist/settings/runtime-settings.js +215 -40
- package/dist/settings/settings-store.js +11 -3
- package/package.json +4 -4
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ActivityScanCoordinator` — owns the dispatcher's
|
|
3
|
+
* `triggerActivityScan` entry point and the cost-reduction-structural §B
|
|
4
|
+
* three-stage gate that fronts it. The coordinator decides whether a
|
|
5
|
+
* given hourly tick:
|
|
6
|
+
* - skips (autonomous gate / morning routine active / already running
|
|
7
|
+
* / below threshold);
|
|
8
|
+
* - silently consumes observations + records an Agent Log line
|
|
9
|
+
* (Stage 0 deterministic gate or Stage 2 lite-tier `log_only`);
|
|
10
|
+
* - escalates to the existing Stage 3 enqueue (Stage 2 `escalate`
|
|
11
|
+
* verdict or `failed` cautious-escalate path).
|
|
12
|
+
*
|
|
13
|
+
* Extracted from `core/dispatcher.ts` as part of phase D-2 of
|
|
14
|
+
* `docs/design/appendices/file-split-plan.md`. Pattern B (stateful
|
|
15
|
+
* coordinator): the coordinator owns the gate logic but borrows live
|
|
16
|
+
* accessors for state the dispatcher continues to own — the
|
|
17
|
+
* `activityScanInProgress` flag (atomic check-and-set inside the
|
|
18
|
+
* trigger), the `morningRoutineInProgress` flag (read-only), and the
|
|
19
|
+
* lazily-injected delegated-sync refresh callback.
|
|
20
|
+
*
|
|
21
|
+
* Dispatcher entry points served:
|
|
22
|
+
* - `EventDispatcher.triggerActivityScan(source, options)` is now a
|
|
23
|
+
* thin one-liner that delegates to `trigger(source, options)`.
|
|
24
|
+
*
|
|
25
|
+
* Invariants preserved bit-for-bit from
|
|
26
|
+
* `docs/design/02-event-pipeline.md` §2:
|
|
27
|
+
* - skip-if-morning-routine-in-progress;
|
|
28
|
+
* - skip-if-hourly-already-running (atomic flag flip BEFORE any
|
|
29
|
+
* await boundary — the C1 race fix from before the split);
|
|
30
|
+
* - skip-if-pending-observations-below-threshold (legacy
|
|
31
|
+
* min-observations floor honoured only when the gate would have
|
|
32
|
+
* proceeded to Stage 3 anyway);
|
|
33
|
+
* - skip-if-setup-incomplete / vault-degraded / user-paused via
|
|
34
|
+
* `isAutonomousAllowed`.
|
|
35
|
+
*
|
|
36
|
+
* Shared-state references held:
|
|
37
|
+
* - `setActivityScanInProgress` / `isActivityScanInProgress` —
|
|
38
|
+
* getter/setter pair around the dispatcher's flag. The flag is
|
|
39
|
+
* left `true` when an enqueue actually happens (the EventBus
|
|
40
|
+
* consumer's `dispatchSafe` finally clears it on routine
|
|
41
|
+
* completion); it is reset inline when the coordinator owns the
|
|
42
|
+
* turn (silent gate paths) or when the trigger is skipping.
|
|
43
|
+
* - `isMorningRoutineActive` — read-only mirror of the dispatcher
|
|
44
|
+
* method so the gate stays single-sourced.
|
|
45
|
+
* - `isAutonomousAllowed` — same; returns the
|
|
46
|
+
* `TriggerActivityScanSkipReason` the gate should surface.
|
|
47
|
+
* - `getDelegatedSyncRefresh` — accessor; null when no delegated
|
|
48
|
+
* integration is wired, in which case the gate proceeds without
|
|
49
|
+
* a refresh, matching pre-injection behaviour.
|
|
50
|
+
*/
|
|
51
|
+
import type Database from "better-sqlite3";
|
|
52
|
+
import type { IntegrationKey } from "@aitne/shared";
|
|
53
|
+
import type { AgentConfig } from "../config.js";
|
|
54
|
+
import type { EventBus } from "./event-bus.js";
|
|
55
|
+
import type { TodayWriteLockManager } from "./today-write-lock.js";
|
|
56
|
+
import type { IAgentRouter } from "./backends/backend-router.js";
|
|
57
|
+
import type { IAuditLogger, IContextBuilder, TriggerActivityScanOptions, TriggerActivityScanResult, TriggerActivityScanSkipReason } from "./dispatcher-types.js";
|
|
58
|
+
import type { PromptAssembler } from "./dispatcher-prompt.js";
|
|
59
|
+
import type { RoutineFetchWindowRunner } from "./routine-fetch-window-runner.js";
|
|
60
|
+
export interface ActivityScanCoordinatorDeps {
|
|
61
|
+
db: Database.Database;
|
|
62
|
+
config: AgentConfig;
|
|
63
|
+
eventBus: EventBus;
|
|
64
|
+
contextBuilder: IContextBuilder;
|
|
65
|
+
agentRouter: IAgentRouter;
|
|
66
|
+
audit: IAuditLogger;
|
|
67
|
+
todayWriteLock: TodayWriteLockManager | undefined;
|
|
68
|
+
prompt: PromptAssembler;
|
|
69
|
+
/**
|
|
70
|
+
* docs/design/appendices/routine-data-acquisition.md Phase 4 / D3 — pre-pass runner
|
|
71
|
+
* spawned between Stage 2 (lite-tier triage) and Stage 3 (medium-tier
|
|
72
|
+
* main session) on `escalate` / `failed` verdicts. The rendered
|
|
73
|
+
* `<fetch_report>` block rides on the Stage 3 RoutineEvent's
|
|
74
|
+
* `event.data.fetchReportBlock` so ContextBuilder folds it into the
|
|
75
|
+
* Stage 3 prompt.
|
|
76
|
+
*/
|
|
77
|
+
fetchWindowRunner: RoutineFetchWindowRunner;
|
|
78
|
+
/** Accessor for the lazily-injected delegated-sync refresh callback. */
|
|
79
|
+
getDelegatedSyncRefresh: () => (() => Promise<void>) | null;
|
|
80
|
+
/** Setter for the dispatcher's `activityScanInProgress` flag. */
|
|
81
|
+
setActivityScanInProgress: (value: boolean) => void;
|
|
82
|
+
/** Getter for the dispatcher's `activityScanInProgress` flag. */
|
|
83
|
+
isActivityScanInProgress: () => boolean;
|
|
84
|
+
/** Mirrors `EventDispatcher.isMorningRoutineActive`. */
|
|
85
|
+
isMorningRoutineActive: () => boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Mirrors `EventDispatcher.isAutonomousAllowed`. Returns the
|
|
88
|
+
* skip-reason when the gate must abort early (setup incomplete,
|
|
89
|
+
* vault degraded, user paused) or `null` when autonomous work is
|
|
90
|
+
* permitted to proceed.
|
|
91
|
+
*/
|
|
92
|
+
isAutonomousAllowed: () => TriggerActivityScanSkipReason | null;
|
|
93
|
+
/**
|
|
94
|
+
* Accessor for the scheduler's `queueMorningRoutineWake`. Returns the
|
|
95
|
+
* bound function once wiring has completed, or `null` early in startup
|
|
96
|
+
* before the scheduler is constructed. The pre-routine gate calls this
|
|
97
|
+
* when it detects the current agent-day's morning_routine has not run
|
|
98
|
+
* yet (typical cause: Mac slept through the 04:00 cron tick). The
|
|
99
|
+
* wake row carries the dedup guarantee — multiple back-to-back hourly
|
|
100
|
+
* ticks all see the same in-flight row instead of stacking up.
|
|
101
|
+
*/
|
|
102
|
+
getQueueMorningRoutineWake: () => QueueMorningRoutineWake | null;
|
|
103
|
+
}
|
|
104
|
+
/** Signature of `AgentScheduler.queueMorningRoutineWake`, narrowed to the
|
|
105
|
+
* surface the dispatcher gate consumes. Kept structural so we don't pull
|
|
106
|
+
* the scheduler class into this module just for a type reference. */
|
|
107
|
+
export type QueueMorningRoutineWake = (source: string, options?: {
|
|
108
|
+
postCatchupRoutines?: string[];
|
|
109
|
+
postCatchupActivityScan?: boolean;
|
|
110
|
+
}) => {
|
|
111
|
+
inserted: boolean;
|
|
112
|
+
existingId?: number;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* HOURLY_CHECK_GATE_REDESIGN_PLAN.md §3.3 + §7.2 — outcome of the
|
|
116
|
+
* Layer-1 pre-pass harvest that runs at the top of `trigger()` for
|
|
117
|
+
* delegated/native integrations. Surfaced both in the audit row (per-
|
|
118
|
+
* tick observability) and on the Stage 3 event (the rendered
|
|
119
|
+
* `<fetch_report>` block).
|
|
120
|
+
*/
|
|
121
|
+
export interface HarvestResult {
|
|
122
|
+
/** True when at least one integration was eligible and the runner ran. */
|
|
123
|
+
ran: boolean;
|
|
124
|
+
/** Integrations whose sub-session completed successfully or partially. */
|
|
125
|
+
integrations: IntegrationKey[];
|
|
126
|
+
/** Eligible integrations suppressed by the freshness window. */
|
|
127
|
+
skippedIntegrations: IntegrationKey[];
|
|
128
|
+
/** Eligible integrations whose sub-session ended in `failed`. */
|
|
129
|
+
failedIntegrations: IntegrationKey[];
|
|
130
|
+
/** Wall-clock time spent on the harvest (ms). */
|
|
131
|
+
durationMs: number;
|
|
132
|
+
/**
|
|
133
|
+
* True when any eligible integration failed. Triggers §3.5 cautious-
|
|
134
|
+
* escalate: gate decision is forced to `stage3` regardless of the
|
|
135
|
+
* signal verdict so a fetch outage doesn't manifest as silent
|
|
136
|
+
* stage0.
|
|
137
|
+
*/
|
|
138
|
+
failed: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Rendered `<fetch_report>` block from the runner, ready to plumb
|
|
141
|
+
* onto `stage3Event.data.fetchReportBlock`. `null` when the runner
|
|
142
|
+
* was not spawned (no eligible integrations) — in that case the
|
|
143
|
+
* Stage 3 prompt simply omits the block.
|
|
144
|
+
*/
|
|
145
|
+
fetchReportBlock: string | null;
|
|
146
|
+
}
|
|
147
|
+
export declare class ActivityScanCoordinator {
|
|
148
|
+
private readonly db;
|
|
149
|
+
private readonly config;
|
|
150
|
+
private readonly eventBus;
|
|
151
|
+
private readonly contextBuilder;
|
|
152
|
+
private readonly agentRouter;
|
|
153
|
+
private readonly audit;
|
|
154
|
+
private readonly todayWriteLock;
|
|
155
|
+
private readonly prompt;
|
|
156
|
+
private readonly fetchWindowRunner;
|
|
157
|
+
private readonly getDelegatedSyncRefresh;
|
|
158
|
+
private readonly setActivityScanInProgress;
|
|
159
|
+
private readonly isActivityScanInProgress;
|
|
160
|
+
private readonly isMorningRoutineActive;
|
|
161
|
+
private readonly isAutonomousAllowed;
|
|
162
|
+
private readonly getQueueMorningRoutineWake;
|
|
163
|
+
constructor(deps: ActivityScanCoordinatorDeps);
|
|
164
|
+
trigger(source: string, options?: TriggerActivityScanOptions): Promise<TriggerActivityScanResult>;
|
|
165
|
+
/**
|
|
166
|
+
* HOURLY_CHECK_GATE_REDESIGN_PLAN.md §3.3 Layer 1 — pre-pass harvest
|
|
167
|
+
* for active non-direct integrations. Reads the per-integration
|
|
168
|
+
* `pre_pass_last_run:<key>` freshness key; integrations whose last
|
|
169
|
+
* successful run is within `activityScanPrePassFreshnessMinutes` are
|
|
170
|
+
* skipped this tick. Forced runs (`/api/agent/run-now`) bypass the
|
|
171
|
+
* freshness gate.
|
|
172
|
+
*
|
|
173
|
+
* Returns a `HarvestResult` so the caller can:
|
|
174
|
+
* - emit telemetry (which integrations fetched, which skipped on
|
|
175
|
+
* freshness, which failed),
|
|
176
|
+
* - cautious-escalate when any non-direct integration failed
|
|
177
|
+
* (§3.5 — prevents silent stage0 from masking a fetch outage),
|
|
178
|
+
* - plumb the rendered `<fetch_report>` block onto the Stage 3
|
|
179
|
+
* event so ContextBuilder folds it into the prompt.
|
|
180
|
+
*/
|
|
181
|
+
private harvestForGate;
|
|
182
|
+
/**
|
|
183
|
+
* cost-reduction-structural §B — pull a fresh signal snapshot and run
|
|
184
|
+
* the deterministic gate. Helper so the dispatcher's call site stays
|
|
185
|
+
* compact and tests can spy on the boundary.
|
|
186
|
+
*/
|
|
187
|
+
private computeActivityScanGateDecision;
|
|
188
|
+
private readTodayMdSafe;
|
|
189
|
+
/**
|
|
190
|
+
* cost-reduction-structural §B — daemon-direct silent path. Used by
|
|
191
|
+
* Stage 0 and Stage 2 log-only verdicts. Consumes pending user
|
|
192
|
+
* observations + appends a single Agent Log line + records the gate
|
|
193
|
+
* verdict to `agent_actions`. The flag is reset before return.
|
|
194
|
+
*/
|
|
195
|
+
private runSilentActivityScanPath;
|
|
196
|
+
private enqueueStage3ActivityScan;
|
|
197
|
+
private logGateAuditRow;
|
|
198
|
+
/**
|
|
199
|
+
* cost-reduction-structural §B Stage 2 — synchronous lite-tier triage.
|
|
200
|
+
* Builds a `routine.activity_scan.triage` RoutineEvent and runs it
|
|
201
|
+
* inline through the agent router (NOT the EventBus, so the result
|
|
202
|
+
* is available before we decide whether to silence or escalate).
|
|
203
|
+
*
|
|
204
|
+
* The agent contract is JSON-only output (`{ "action": "log_only" |
|
|
205
|
+
* "escalate", "reason": "..." }`); on parse failure we return
|
|
206
|
+
* `'failed'` and the caller treats that as cautious escalate.
|
|
207
|
+
*
|
|
208
|
+
* Tool/turn clamp (defense-in-depth):
|
|
209
|
+
* - `allowedToolsOverride: []` removes every tool from the SDK's
|
|
210
|
+
* allowlist for the spawn. Stage 2 has nothing to do but emit a
|
|
211
|
+
* JSON line; the design's "no write tools" rule is enforced here
|
|
212
|
+
* instead of relying on the prompt alone.
|
|
213
|
+
* - `maxTurns: 1` caps the spawn at a single assistant turn. Even
|
|
214
|
+
* if a future prompt change accidentally invites tool use, the
|
|
215
|
+
* spawn cannot loop. Codex/Gemini have no per-spawn `allowedTools`
|
|
216
|
+
* surface today (acknowledged gap in `agent-core.ts`); the
|
|
217
|
+
* `maxTurns` cap and process_backend_config envelope are the
|
|
218
|
+
* remaining safety floor on those backends.
|
|
219
|
+
*/
|
|
220
|
+
private runStage2Triage;
|
|
221
|
+
}
|