@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.
- 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.js +8 -5
- 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.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/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/context/permissions.js +3 -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 +48 -12
- package/dist/api/routes/dashboard/cost-approvals.js +66 -0
- package/dist/api/routes/dashboard/notifications.js +9 -9
- package/dist/api/routes/integrations/crud-patch.js +5 -1
- package/dist/api/routes/integrations-reconcile.js +2 -2
- 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 +9 -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 +245 -7
- 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 +26 -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 +25 -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 +39 -15
- 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 +62 -20
- 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 +1 -1
- package/dist/core/context-paths.js +1 -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 +49 -0
- 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 +17 -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 +63 -1
- package/dist/core/dispatcher-scheduled-tasks.js +213 -6
- 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 +284 -59
- package/dist/core/dm-freshness-metrics.d.ts +1 -1
- package/dist/core/drift-effects.js +2 -2
- package/dist/core/feedback/consolidation-prep.js +17 -5
- package/dist/core/feedback/eviction-scorer.js +6 -2
- package/dist/core/feedback/lesson-format.js +9 -4
- package/dist/core/feedback/lesson-injection.d.ts +1 -1
- package/dist/core/feedback/lesson-injection.js +17 -2
- package/dist/core/feedback/lesson-store-overview.d.ts +8 -4
- package/dist/core/feedback/lesson-store-overview.js +8 -4
- package/dist/core/feedback/regeneralization-prep.js +29 -16
- 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 +4 -4
- package/dist/core/injection-policy.js +4 -4
- 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 +12 -0
- package/dist/core/signal-detector.js +53 -9
- 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 +2 -2
- package/dist/core/today-direct-writer.js +1 -1
- 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/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/migrations.js +330 -0
- package/dist/db/observations.d.ts +2 -2
- package/dist/db/observations.js +3 -3
- package/dist/db/schema.js +217 -16
- 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/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 +75 -11
- 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 +16 -6
- 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/observations-batch.d.ts +1 -1
- package/dist/services/observations-batch.js +2 -2
- package/dist/settings/runtime-settings.d.ts +38 -11
- package/dist/settings/runtime-settings.js +203 -40
- package/dist/settings/settings-store.js +11 -3
- package/package.json +4 -4
package/dist/core/scheduler.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
* `
|
|
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
|
|
62
|
+
* is negligible compared to the actual activity-scan work.
|
|
33
63
|
*/
|
|
34
|
-
export declare function
|
|
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
|
|
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
|
|
142
|
+
private onActivityScan;
|
|
113
143
|
/**
|
|
114
144
|
* Phase 4 auth probe hook — fired on every hourly cron tick BEFORE
|
|
115
|
-
* `
|
|
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
|
-
*
|
|
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
|
-
* `
|
|
126
|
-
* threshold gate inside `
|
|
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
|
-
|
|
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
|
|
219
|
-
* the probe continues to run even when the
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|