@songsid/agend 2.4.0-beta.16 → 2.4.0-beta.17
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/auth-api.js +2 -0
- package/dist/auth-api.js.map +1 -1
- package/dist/backend/claude-code.d.ts +10 -1
- package/dist/backend/claude-code.js +1 -0
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/types.d.ts +6 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/claude-credential-launch.d.ts +1 -0
- package/dist/claude-credential-launch.js +13 -2
- package/dist/claude-credential-launch.js.map +1 -1
- package/dist/claude-credential-vault.d.ts +7 -1
- package/dist/claude-credential-vault.js +26 -1
- package/dist/claude-credential-vault.js.map +1 -1
- package/dist/claude-request-observation.d.ts +7 -0
- package/dist/claude-request-observation.js +26 -0
- package/dist/claude-request-observation.js.map +1 -0
- package/dist/cli-audited.js +8 -6
- package/dist/cli-audited.js.map +1 -1
- package/dist/daemon.js +6 -0
- package/dist/daemon.js.map +1 -1
- package/dist/fleet-manager.d.ts +14 -0
- package/dist/fleet-manager.js +128 -3
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +9 -3
- package/dist/host-monitoring-config.d.ts +2 -1
- package/dist/host-monitoring-config.js +8 -3
- package/dist/host-monitoring-config.js.map +1 -1
- package/dist/host-monitoring-history-files.d.ts +2 -0
- package/dist/host-monitoring-history-files.js +16 -0
- package/dist/host-monitoring-history-files.js.map +1 -0
- package/dist/host-monitoring-history-policy.d.ts +55 -0
- package/dist/host-monitoring-history-policy.js +93 -0
- package/dist/host-monitoring-history-policy.js.map +1 -0
- package/dist/host-monitoring-history-store.d.ts +52 -0
- package/dist/host-monitoring-history-store.js +176 -0
- package/dist/host-monitoring-history-store.js.map +1 -0
- package/dist/host-monitoring-history-worker.d.ts +1 -0
- package/dist/host-monitoring-history-worker.js +50 -0
- package/dist/host-monitoring-history-worker.js.map +1 -0
- package/dist/host-monitoring-history.d.ts +71 -0
- package/dist/host-monitoring-history.js +265 -0
- package/dist/host-monitoring-history.js.map +1 -0
- package/dist/host-monitoring-platform.d.ts +73 -0
- package/dist/host-monitoring-platform.js +273 -0
- package/dist/host-monitoring-platform.js.map +1 -0
- package/dist/host-monitoring-runtime.d.ts +34 -0
- package/dist/host-monitoring-runtime.js +80 -0
- package/dist/host-monitoring-runtime.js.map +1 -0
- package/dist/host-monitoring-settings-store.d.ts +5 -0
- package/dist/host-monitoring-settings-store.js +49 -0
- package/dist/host-monitoring-settings-store.js.map +1 -0
- package/dist/host-monitoring.d.ts +106 -0
- package/dist/host-monitoring.js +157 -0
- package/dist/host-monitoring.js.map +1 -0
- package/dist/public-web-gateway.js +4 -0
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/runtime-cli-install.js +17 -16
- package/dist/runtime-cli-install.js.map +1 -1
- package/dist/settings-api.d.ts +3 -0
- package/dist/settings-api.js +14 -7
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-baseline.d.ts +1 -0
- package/dist/settings-baseline.js +5 -4
- package/dist/settings-baseline.js.map +1 -1
- package/dist/settings-change.js +8 -0
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-effect.d.ts +2 -0
- package/dist/settings-effect.js +5 -3
- package/dist/settings-effect.js.map +1 -1
- package/dist/transcript-monitor.d.ts +1 -0
- package/dist/transcript-monitor.js +18 -0
- package/dist/transcript-monitor.js.map +1 -1
- package/dist/ui/accounts-view.js +7 -5
- package/dist/ui/claude-credentials.js +12 -1
- package/dist/ui/fleet-office-pack.js +2 -2
- package/dist/ui/fleet-office-play.js +142 -3
- package/dist/ui/fleet-office-skin.js +67 -2
- package/dist/ui/fleet-office-store.js +41 -0
- package/dist/ui/fleet-office-zones.js +15 -8
- package/dist/ui/fleet-office.js +126 -21
- package/dist/ui/host-health-model.js +42 -0
- package/dist/ui/host-health.js +74 -0
- package/dist/ui/panel-chat.js +99 -43
- package/dist/ui/panel-fleet.js +24 -11
- package/dist/ui/panel-hub.js +5 -1
- package/dist/ui/panel-settings.js +3 -3
- package/dist/ui/search-dialog.js +8 -1
- package/dist/ui/settings-capabilities.js +2 -0
- package/dist/ui/settings-host-monitoring.js +31 -13
- package/dist/ui/settings-registry.js +4 -1
- package/dist/ui/shared/accounts.css +8 -4
- package/dist/ui/shared/agent-sheet.js +5 -2
- package/dist/ui/shared/app-route.js +1 -1
- package/dist/ui/shared/app.css +37 -0
- package/dist/ui/shared/app.js +1 -0
- package/dist/ui/shared/chat-strings.js +2 -2
- package/dist/ui/shared/chat-thread.js +42 -10
- package/dist/ui/shared/instance-nav.js +47 -5
- package/dist/ui/shared/jump-idle.js +36 -0
- package/dist/ui/shared/theme.js +6 -2
- package/dist/ui/shared/ui-menu.js +17 -11
- package/dist/web-api.d.ts +2 -0
- package/dist/web-api.js +54 -0
- package/dist/web-api.js.map +1 -1
- package/dist/web-chat-history.d.ts +7 -1
- package/dist/web-chat-history.js +19 -3
- package/dist/web-chat-history.js.map +1 -1
- package/dist/web-shell-routes.d.ts +1 -1
- package/dist/web-shell-routes.js +1 -1
- package/dist/web-shell-routes.js.map +1 -1
- package/package.json +1 -1
|
@@ -443,7 +443,7 @@ the rest. **Show** picks a team or the Lobby and **People** pins chosen instance
|
|
|
443
443
|
in each (Everyone, Picked: whole teams or single instances, or #2752 Nobody: its style's NPCs only; none picked = everyone) and its style,
|
|
444
444
|
#4104 **Idle people stay in their own area** (per office, off by default: idle strolls stay in the seat's area, no visits),
|
|
445
445
|
#4119 **Drag and pat** in the Office bar (per device, on by default, off with reduced motion; never on a share link): drag
|
|
446
|
-
someone and
|
|
446
|
+
someone onto another valid seat in their area (#4266) to seat them there immediately (persisted per device/office/style, swapping cleanly and respecting reserved seats and `stayInArea`) or drop on empty floor to walk back; while held they play a `dragged` pose (#4267: optional `characters.<set>.dragged` / `default.dragged` strip or built-in lifted dangle, returning to their prior pose on drop); their card's Pat/Feed show hearts and words; nothing reaches the agent unless that card's
|
|
447
447
|
**Tell <agent> (with their next message)** is ticked (per agent, off) — then one `[Office] … patted your head ×N` line rides
|
|
448
448
|
its next real message's `[Recent reactions: …]` (never a wake; capped); a pack's `bubbles.<lang>.pat` / `.feed` give the words; (#4255) packs with optional `snacks` (1–12 items, `sprite`, optional `eat` overlay, `radius`) and `characters.<set>.eat` show a floating snack tray (bottom-left; above zone pills on phone) for drag-to-feed, tap-to-arm, and placed snacks (up to 6 on floor, 30 s TTL, up to 4 nearest idle racers honoring `stayInArea`, first eats and others scatter; packs without `snacks` stay unchanged), and upload or delete **skin packs** (an
|
|
449
449
|
artist's pictures: `manifest.json` plus PNGs, format v1, kept in `web-office-skins/` in the AgEnD home; the host
|
|
@@ -543,6 +543,8 @@ every 5 s.
|
|
|
543
543
|
|
|
544
544
|
## Finding an instance
|
|
545
545
|
|
|
546
|
+
Right-click an Agent row in the left sidebar to open that Agent's chat actions without first changing chats. On touch, hold the row; with the row focused, press Shift+F10 or the context-menu key. The same shared menu/sheet and applicable actions are used as the chat header's **⋯**, with a Favorite toggle using the sidebar's existing saved favorites and limit. Split chat opens the selected Agent beside the current chat wherever the workspace is available. Existing row favorite/split controls remain available. Its Card tile opens that selected Agent's card in a dialog without changing the current chat's card preference. Escape or an outside press closes it. Moving or scrolling cancels a touch hold. Guests and read-only viewers do not gain these chat controls; the row's existing favorites/workspace **⋯** remains separate.
|
|
547
|
+
|
|
546
548
|
**The sidebar list.** Grouped by team (an instance in `teams.<name>.members` under its first team, whatever its tags), else by
|
|
547
549
|
its first tag ("#" before the heading), ClassicBot rooms under Classic, the rest under Other; Settings → Agents the same (#2172).
|
|
548
550
|
Settings → Preferences → **Sidebar agent list** chooses **Detailed** or **Compact**, one for a phone's drawer and one for a
|
|
@@ -747,7 +749,7 @@ runs now. If the npm copy is still there, **Remove the npm copy** is a separate
|
|
|
747
749
|
runs `npm -g uninstall @anthropic-ai/claude-code` in that npm folder; the card offers it whenever Claude Code runs from the native
|
|
748
750
|
install and an npm copy is still on the computer (also after a restart). This offer is only on AI accounts, not in Needs you.
|
|
749
751
|
|
|
750
|
-
**Managed Claude credentials (M-3419)** — Accounts → Connect (also Needs you → Connect account) offers the existing subscription login, a token obtained with setup-token, or an Anthropic API key. Pasting, replacing and removing saved credentials requires the local dashboard and a current verified administrator, even though ordinary subscription login can run over a public link. Never put a key/token in chat, an agent tool call or a proposal. Values are encrypted; Save makes no model request and reports saved-unverified. Source-class checks are not provider validation. Managed profiles do not show an old subscription identity, meters or keep-alive. Used-profile changes list affected users, require idle local panes and positive old-pane retirement before commit; busy/paused/unknown consumers refuse, and failed restarts are listed. Removing the saved value leaves the profile disconnected; explicitly choosing Subscription switches back to its native login. Profile/conversation assignments stay. A managed secret must be removed before deleting its profile. Removing AgEnD's copy does not revoke it at Anthropic. The launcher clears ambient credentials and uses a private API-key helper or child-only setup-token environment. Organization-managed Claude settings are unsupported. Same-OS-user agents are not isolated from runtime secrets.
|
|
752
|
+
**Managed Claude credentials (M-3419)** — Accounts → Connect (also Needs you → Connect account) offers the existing subscription login, a token obtained with setup-token, or an Anthropic API key. Pasting, replacing and removing saved credentials requires the local dashboard and a current verified administrator, even though ordinary subscription login can run over a public link. Never put a key/token in chat, an agent tool call or a proposal. Values are encrypted; Save makes no model request and reports saved-unverified. Source-class checks are not provider validation. A fresh normal successful request bound to the current launch/profile/credential revision marks it Verified with a timestamp. A 401/403 shows Needs replacement; network/unconfirmed errors stay Unknown and do not mean the credential is invalid. No extra model request is sent. Replacing, removing or changing source clears the stamp. Managed profiles do not show an old subscription identity, meters or keep-alive. Used-profile changes list affected users, require idle local panes and positive old-pane retirement before commit; busy/paused/unknown consumers refuse, and failed restarts are listed. Removing the saved value leaves the profile disconnected; explicitly choosing Subscription switches back to its native login. Profile/conversation assignments stay. A managed secret must be removed before deleting its profile. Removing AgEnD's copy does not revoke it at Anthropic. The launcher clears ambient credentials and uses a private API-key helper or child-only setup-token environment. Organization-managed Claude settings are unsupported. Same-OS-user agents are not isolated from runtime secrets.
|
|
751
753
|
|
|
752
754
|
For the token method, **Get a token for me** opens a private browser sign-in on the local host. It uses the same verified-admin gate, a 10-minute Connect-account deadline and an owned cleanup; only safe sign-in controls reach the page, and the printed token goes directly to encrypted storage after cleanup. Paste remains available. Cancel or expiry never changes the selected source; if saving is uncertain, read account status before retrying. No model request is made by this flow.
|
|
753
755
|
|
|
@@ -819,7 +821,11 @@ other Windows PCs to pair** (`runtimes.remote_runtime`), **Agents at once on eac
|
|
|
819
821
|
under **Manual options**, a pairing code. Each computer: its CLIs (**Install a CLI**, **Update to *version***, only while
|
|
820
822
|
that PC's owner allowed it there), its accounts, and its update status. See docs/remote-runtime.md.
|
|
821
823
|
|
|
822
|
-
**Notifications → Host monitoring** (
|
|
824
|
+
**Notifications → Host monitoring** (「主機監測」): **Monitor this computer** and **Include agent footprint** are off by default; off is explicitly saved as false. On a supported computer, **View host health** opens Fleet → Host health. Sampling runs every 30–60 seconds; local history is capped at 64 MiB. Memory/write overhead is still being measured, rather than a promised budget. Agent footprint stays disabled until the version supports it. Turning monitoring off asks before deleting its history, then waits for physical close and cleanup; a failed cleanup is not a clean Off state. Off starts no monitoring collector, timer, worker or history file.
|
|
825
|
+
|
|
826
|
+
**Fleet → Host health** (「主機狀態」, administrator only) shows current CPU, memory/pressure and relevant disks, with 1h / 24h / 7d / 30d recorded trends. Refresh reads caches/history; it does not start a new probe or turn monitoring on. Missing data stays unavailable, stale values keep their last-success time, and chart gaps are not zero. New history says **Collecting history…** until enough recorded buckets exist for a trend. WSL CPU/memory are WSL's figures; the Windows drive holding its virtual disk is separate. If that drive is unknown, choose it in Monitoring settings. The drive choice is kept in a private local sidecar, separate from fleet.yaml, so this choice does not prevent an older release from starting; missing or invalid sidecar data uses automatic detection. macOS APFS volumes can share free space: never add those values together; available memory is an estimate and unknown pressure is not Normal. Unsupported computers say so instead of offering a misleading enable link.
|
|
827
|
+
|
|
828
|
+
History retains up to 24 hours of raw data and 30 days of five-minute rollups, subject to the shared cap. Below 2 GiB free on state storage or the verified WSL backing drive, history pauses and current samples remain in memory. Recovery needs both above 4 GiB for ten minutes. Automated threshold alerts and agent footprint are not available in this page's initial version; the independent existing disk watcher is unchanged.
|
|
823
829
|
|
|
824
830
|
**Notifications** — **Quota notices** (「用量提醒」, #3302): one reminder per account at the **Remaining percentages**
|
|
825
831
|
and **Periods** you choose, shared by its agents, **Send to** General.
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
export interface HostMonitoringConfig {
|
|
3
3
|
enabled: boolean;
|
|
4
4
|
agent_footprint: boolean;
|
|
5
|
+
wsl_drive?: string;
|
|
5
6
|
}
|
|
6
|
-
export declare const
|
|
7
|
+
export declare const HOST_MONITORING_PAGE_AVAILABLE = true;
|
|
7
8
|
export declare const HOST_MONITORING_KEYS: readonly ['enabled', 'agent_footprint'];
|
|
8
9
|
export declare function monitoringProblem(value: unknown): string | null;
|
|
9
10
|
export declare function monitoringConfig(value?: unknown): HostMonitoringConfig;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
export const HOST_MONITORING_COLLECTOR_AVAILABLE = false;
|
|
1
|
+
// S-207 changes this only when the actual Host health page is available.
|
|
2
|
+
export const HOST_MONITORING_PAGE_AVAILABLE = true;
|
|
4
3
|
export const HOST_MONITORING_KEYS = ['enabled', 'agent_footprint'];
|
|
5
4
|
export function monitoringProblem(value) {
|
|
6
5
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
7
6
|
return 'must be a mapping';
|
|
8
7
|
for (const [key, setting] of Object.entries(value)) {
|
|
8
|
+
if (key === 'wsl_drive') {
|
|
9
|
+
if (typeof setting !== 'string' || !/^(?:[A-Z])?$/.test(setting))
|
|
10
|
+
return 'wsl_drive must be an uppercase drive letter or empty for automatic';
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
9
13
|
if (!HOST_MONITORING_KEYS.includes(key))
|
|
10
14
|
return `unknown key: ${key}`;
|
|
11
15
|
if (typeof setting !== 'boolean')
|
|
@@ -20,6 +24,7 @@ export function monitoringConfig(value) {
|
|
|
20
24
|
throw new Error(`monitoring: ${problem}`);
|
|
21
25
|
}
|
|
22
26
|
const v = value;
|
|
27
|
+
// Persist only the beta.16-compatible booleans. wsl_drive is accepted solely for legacy migration / Settings input.
|
|
23
28
|
// Explicit literals, never a changeable default or an environment override.
|
|
24
29
|
return { enabled: v?.enabled === true, agent_footprint: v?.agent_footprint === true };
|
|
25
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-monitoring-config.js","sourceRoot":"","sources":["../src/host-monitoring-config.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"host-monitoring-config.js","sourceRoot":"","sources":["../src/host-monitoring-config.ts"],"names":[],"mappings":"AAEA,yEAAyE;AACzE,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AACnD,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,SAAS,EAAE,iBAAiB,CAAU,CAAC;AAC5E,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,mBAAmB,CAAC;IAC5F,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACnD,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;YAAC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC;gBAAE,OAAO,oEAAoE,CAAC;YAAC,SAAS;QAAC,CAAC;QACrL,IAAI,CAAE,oBAA0C,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,OAAO,gBAAgB,GAAG,EAAE,CAAC;QAC7F,IAAI,OAAO,OAAO,KAAK,SAAS;YAAE,OAAO,GAAG,GAAG,oBAAoB,CAAC;IACtE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AACD,MAAM,UAAU,gBAAgB,CAAC,KAAe;IAC9C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAAC,MAAM,OAAO,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAAC,IAAI,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,eAAe,OAAO,EAAE,CAAC,CAAC;IAAC,CAAC;IAC9H,MAAM,CAAC,GAAG,KAAkD,CAAC;IAC7D,oHAAoH;IACpH,4EAA4E;IAC5E,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,KAAK,IAAI,EAAE,eAAe,EAAE,CAAC,EAAE,eAAe,KAAK,IAAI,EAAE,CAAC;AACxF,CAAC;AACD,MAAM,UAAU,uBAAuB,CAAC,IAAa;IACnD,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAc,CAAC,CAAC,MAAM;QAAE,OAAO,EAAE,KAAK,EAAE,6BAA6B,EAAE,CAAC;IACpH,OAAO,EAAE,KAAK,EAAE,EAAE,GAAG,IAAqC,EAAE,EAAE,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { unlink } from 'node:fs/promises';
|
|
2
|
+
export const historyFiles = (path) => ['', '-wal', '-shm', '-journal', '.incidents', '.incidents.tmp'].map(s => path + s);
|
|
3
|
+
export async function cleanupHistory(path, remove = unlink) {
|
|
4
|
+
let failed = false;
|
|
5
|
+
for (const name of historyFiles(path))
|
|
6
|
+
try {
|
|
7
|
+
await remove(name);
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
if (error.code !== 'ENOENT')
|
|
11
|
+
failed = true;
|
|
12
|
+
}
|
|
13
|
+
if (failed)
|
|
14
|
+
throw Error('history_cleanup_failed');
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=host-monitoring-history-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-monitoring-history-files.js","sourceRoot":"","sources":["../src/host-monitoring-history-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAW,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA,EAAE,CAAA,IAAI,GAAC,CAAC,CAAC,CAAC;AAC7H,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAW,EAAC,MAAM,GAA8B,MAAM;IACzF,IAAI,MAAM,GAAC,KAAK,CAAC;IACjB,KAAI,MAAM,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC;QAAE,IAAI,CAAC;YAAA,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;QAAA,CAAC;QAAC,OAAM,KAAK,EAAE,CAAC;YAAA,IAAI,KAA+B,CAAC,IAAI,KAAG,QAAQ;gBAAC,MAAM,GAAC,IAAI,CAAC;QAAA,CAAC;IAC/I,IAAG,MAAM;QAAC,MAAM,KAAK,CAAC,wBAAwB,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { HostHealthSnapshot } from './host-monitoring.js';
|
|
2
|
+
export declare const HISTORY_BYTES: number;
|
|
3
|
+
export declare const HISTORY_PAGE_BYTES = 4096;
|
|
4
|
+
export declare const HISTORY_SHM_BUDGET: number;
|
|
5
|
+
export declare const HISTORY_RAW_MS: number;
|
|
6
|
+
export declare const HISTORY_ROLLUP_MS: number;
|
|
7
|
+
export declare const HISTORY_BUCKET_MS: number;
|
|
8
|
+
export declare const HISTORY_MAX_BUCKETS = 240;
|
|
9
|
+
/** Leave room for one worst-case WAL and later bounded incident files, not just the database. */
|
|
10
|
+
export declare function historyBudget(maxBytes?: number): {
|
|
11
|
+
maxBytes: number;
|
|
12
|
+
softBytes: number;
|
|
13
|
+
lowBytes: number;
|
|
14
|
+
reserveBytes: number;
|
|
15
|
+
maxPages: number;
|
|
16
|
+
dbBytes: number;
|
|
17
|
+
walBytes: number;
|
|
18
|
+
worstBytes: number;
|
|
19
|
+
};
|
|
20
|
+
export type HistoryPause = 'disk_unavailable' | 'backing_drive_unknown' | 'low_space' | 'recovering_space';
|
|
21
|
+
export declare class HistoryWatermark {
|
|
22
|
+
private low;
|
|
23
|
+
private recoveringAt;
|
|
24
|
+
/** Monotonic time controls recovery; wall-clock adjustments cannot finish it early. */
|
|
25
|
+
permit(snapshot: HostHealthSnapshot, monotonicNow: number): {
|
|
26
|
+
ok: true;
|
|
27
|
+
} | {
|
|
28
|
+
ok: false;
|
|
29
|
+
reason: HistoryPause;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface HistoryPoint {
|
|
33
|
+
series: string;
|
|
34
|
+
at: number;
|
|
35
|
+
sourceAt: number;
|
|
36
|
+
value: number;
|
|
37
|
+
}
|
|
38
|
+
export declare const historySeries: (value: unknown) => value is string;
|
|
39
|
+
/** Only numerical telemetry and opaque volume ids cross into history. No paths/names/native text. */
|
|
40
|
+
export declare function hostHistoryPoints(snapshot: HostHealthSnapshot, at: number): HistoryPoint[];
|
|
41
|
+
export declare const HISTORY_RANGES: {
|
|
42
|
+
readonly '1h': number;
|
|
43
|
+
readonly '24h': number;
|
|
44
|
+
readonly '7d': number;
|
|
45
|
+
readonly '30d': number;
|
|
46
|
+
};
|
|
47
|
+
export type HistoryRange = keyof typeof HISTORY_RANGES;
|
|
48
|
+
export declare function historyQuery(range: unknown, series: unknown, now: number): {
|
|
49
|
+
series: string[];
|
|
50
|
+
start: number;
|
|
51
|
+
end: number;
|
|
52
|
+
resolution: number;
|
|
53
|
+
step: number;
|
|
54
|
+
buckets: number;
|
|
55
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export const HISTORY_BYTES = 64 * 1024 ** 2;
|
|
2
|
+
export const HISTORY_PAGE_BYTES = 4096;
|
|
3
|
+
export const HISTORY_SHM_BUDGET = 128 * 1024;
|
|
4
|
+
export const HISTORY_RAW_MS = 24 * 60 * 60 * 1000;
|
|
5
|
+
export const HISTORY_ROLLUP_MS = 30 * HISTORY_RAW_MS;
|
|
6
|
+
export const HISTORY_BUCKET_MS = 5 * 60 * 1000;
|
|
7
|
+
export const HISTORY_MAX_BUCKETS = 240;
|
|
8
|
+
const GiB = 1024 ** 3;
|
|
9
|
+
/** Leave room for one worst-case WAL and later bounded incident files, not just the database. */
|
|
10
|
+
export function historyBudget(maxBytes = HISTORY_BYTES) {
|
|
11
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1024 ** 2 || maxBytes > HISTORY_BYTES)
|
|
12
|
+
throw Error('invalid_history_budget');
|
|
13
|
+
const reserveBytes = Math.min(4 * 1024 ** 2, Math.floor(maxBytes / 4));
|
|
14
|
+
const maxPages = Math.floor((maxBytes - reserveBytes - HISTORY_SHM_BUDGET - 32) / (2 * HISTORY_PAGE_BYTES + 24));
|
|
15
|
+
const dbBytes = maxPages * HISTORY_PAGE_BYTES, walBytes = 32 + maxPages * (HISTORY_PAGE_BYTES + 24);
|
|
16
|
+
return { maxBytes, softBytes: Math.floor(maxBytes * 7 / 8), lowBytes: Math.floor(maxBytes * 3 / 4), reserveBytes, maxPages, dbBytes, walBytes,
|
|
17
|
+
worstBytes: dbBytes + walBytes + HISTORY_SHM_BUDGET + reserveBytes };
|
|
18
|
+
}
|
|
19
|
+
export class HistoryWatermark {
|
|
20
|
+
low = false;
|
|
21
|
+
recoveringAt = null;
|
|
22
|
+
/** Monotonic time controls recovery; wall-clock adjustments cannot finish it early. */
|
|
23
|
+
permit(snapshot, monotonicNow) {
|
|
24
|
+
const unavailable = (reason) => { this.recoveringAt = null; return { ok: false, reason }; };
|
|
25
|
+
if (snapshot.disks.status !== 'ok' || !snapshot.disks.value)
|
|
26
|
+
return unavailable('disk_unavailable');
|
|
27
|
+
const volumes = snapshot.disks.value.volumes;
|
|
28
|
+
const state = volumes.find(v => v.roles.includes('state'));
|
|
29
|
+
const valid = (n) => typeof n === 'number' && Number.isSafeInteger(n) && n >= 0;
|
|
30
|
+
if (!state || !valid(state.availableBytes))
|
|
31
|
+
return unavailable('disk_unavailable');
|
|
32
|
+
const free = [state.availableBytes];
|
|
33
|
+
if (snapshot.platform === 'wsl') {
|
|
34
|
+
const backing = volumes.find(v => v.roles.includes('wsl-backing'));
|
|
35
|
+
if (snapshot.disks.value.backingDrive !== 'identified' || !backing || !valid(backing.availableBytes))
|
|
36
|
+
return unavailable('backing_drive_unknown');
|
|
37
|
+
free.push(backing.availableBytes);
|
|
38
|
+
}
|
|
39
|
+
if (free.some(n => n < 2 * GiB)) {
|
|
40
|
+
this.low = true;
|
|
41
|
+
return unavailable('low_space');
|
|
42
|
+
}
|
|
43
|
+
if (!this.low)
|
|
44
|
+
return { ok: true };
|
|
45
|
+
if (free.some(n => n <= 4 * GiB))
|
|
46
|
+
return unavailable('recovering_space');
|
|
47
|
+
if (this.recoveringAt === null || monotonicNow < this.recoveringAt)
|
|
48
|
+
this.recoveringAt = monotonicNow;
|
|
49
|
+
if (monotonicNow - this.recoveringAt < 10 * 60 * 1000)
|
|
50
|
+
return { ok: false, reason: 'recovering_space' };
|
|
51
|
+
this.low = false;
|
|
52
|
+
this.recoveringAt = null;
|
|
53
|
+
return { ok: true };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export const historySeries = (value) => typeof value === 'string' &&
|
|
57
|
+
/^(?:cpu\.used|memory\.(?:available|pressure)|swap\.free|disk\.[a-f0-9]{16}\.(?:available|used))$/.test(value);
|
|
58
|
+
/** Only numerical telemetry and opaque volume ids cross into history. No paths/names/native text. */
|
|
59
|
+
export function hostHistoryPoints(snapshot, at) {
|
|
60
|
+
if (!snapshot.enabled || snapshot.state !== 'sampling' || !Number.isSafeInteger(at) || at < 0)
|
|
61
|
+
return [];
|
|
62
|
+
const points = [];
|
|
63
|
+
const add = (series, value, sourceAt, max = Number.MAX_SAFE_INTEGER) => {
|
|
64
|
+
if (typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= max && sourceAt !== null && Number.isSafeInteger(sourceAt) && sourceAt >= 0)
|
|
65
|
+
points.push({ series, at, sourceAt, value });
|
|
66
|
+
};
|
|
67
|
+
if (snapshot.cpu.status === 'ok')
|
|
68
|
+
add('cpu.used', snapshot.cpu.value?.usedPercent, snapshot.cpu.sampledAt, 100);
|
|
69
|
+
if (snapshot.memory.status === 'ok' && snapshot.memory.value) {
|
|
70
|
+
const memory = snapshot.memory.value;
|
|
71
|
+
add('memory.available', memory.availableBytes, snapshot.memory.sampledAt);
|
|
72
|
+
add('swap.free', memory.swapFreeBytes, snapshot.memory.sampledAt);
|
|
73
|
+
add('memory.pressure', { normal: 1, elevated: 2, critical: 3 }[memory.pressure], snapshot.memory.sampledAt, 3);
|
|
74
|
+
}
|
|
75
|
+
if (snapshot.disks.status === 'ok')
|
|
76
|
+
for (const disk of snapshot.disks.value?.volumes.slice(0, 8) ?? []) {
|
|
77
|
+
if (!/^[a-f0-9]{16}$/.test(disk.id))
|
|
78
|
+
continue;
|
|
79
|
+
add(`disk.${disk.id}.available`, disk.availableBytes, disk.sampledAt);
|
|
80
|
+
add(`disk.${disk.id}.used`, disk.usedPercent, disk.sampledAt, 100);
|
|
81
|
+
}
|
|
82
|
+
return points;
|
|
83
|
+
}
|
|
84
|
+
export const HISTORY_RANGES = { '1h': 60 * 60 * 1000, '24h': HISTORY_RAW_MS, '7d': 7 * HISTORY_RAW_MS, '30d': HISTORY_ROLLUP_MS };
|
|
85
|
+
export function historyQuery(range, series, now) {
|
|
86
|
+
if (typeof range !== 'string' || !Object.hasOwn(HISTORY_RANGES, range) || !Array.isArray(series) || series.length < 1 || series.length > 24 || !series.every(historySeries) || new Set(series).size !== series.length || !Number.isSafeInteger(now) || now < 0)
|
|
87
|
+
throw Error('invalid_history_query');
|
|
88
|
+
const duration = HISTORY_RANGES[range], resolution = range === '1h' ? 30_000 : HISTORY_BUCKET_MS;
|
|
89
|
+
const step = Math.max(resolution, Math.ceil(duration / HISTORY_MAX_BUCKETS / resolution) * resolution);
|
|
90
|
+
const start = Math.max(0, now - duration);
|
|
91
|
+
return { series: [...series], start, end: now, resolution, step, buckets: Math.max(1, Math.ceil((now - start) / step)) };
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=host-monitoring-history-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-monitoring-history-policy.js","sourceRoot":"","sources":["../src/host-monitoring-history-policy.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC;AAC5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AACvC,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,GAAG,IAAI,CAAC;AAC7C,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAClD,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,GAAG,cAAc,CAAC;AACrD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAC/C,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AACvC,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,CAAC;AAEtB,iGAAiG;AACjG,MAAM,UAAU,aAAa,CAAC,QAAQ,GAAG,aAAa;IACpD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,QAAQ,GAAG,aAAa;QAAE,MAAM,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC/H,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GA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,CAAC,GAAC,UAAU,CAAC,CAAC;IAC9F,MAAM,KAAK,GAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAC,GAAG,GAAC,QAAQ,CAAC,CAAC;IACrC,OAAO,EAAC,MAAM,EAAC,CAAC,GAAG,MAAM,CAAa,EAAC,KAAK,EAAC,GAAG,EAAC,GAAG,EAAC,UAAU,EAAC,IAAI,EAAC,OAAO,EAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,GAAC,KAAK,CAAC,GAAC,IAAI,CAAC,CAAC,EAAC,CAAC;AACxH,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type HistoryPoint } from './host-monitoring-history-policy.js';
|
|
2
|
+
export { historyFiles, cleanupHistory } from './host-monitoring-history-files.js';
|
|
3
|
+
export interface HistoryStats {
|
|
4
|
+
bytes: number;
|
|
5
|
+
rows: number;
|
|
6
|
+
maxBytes: number;
|
|
7
|
+
dbBudget: number;
|
|
8
|
+
trimmed: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface HistoryBucket {
|
|
11
|
+
at: number;
|
|
12
|
+
min: number | null;
|
|
13
|
+
max: number | null;
|
|
14
|
+
average: number | null;
|
|
15
|
+
count: number;
|
|
16
|
+
sourceAt: number | null;
|
|
17
|
+
}
|
|
18
|
+
export interface HistoryAnswer {
|
|
19
|
+
start: number;
|
|
20
|
+
end: number;
|
|
21
|
+
step: number;
|
|
22
|
+
series: Array<{
|
|
23
|
+
id: string;
|
|
24
|
+
buckets: HistoryBucket[];
|
|
25
|
+
}>;
|
|
26
|
+
stats: HistoryStats;
|
|
27
|
+
}
|
|
28
|
+
interface Options {
|
|
29
|
+
maxBytes?: number;
|
|
30
|
+
maxRows?: number;
|
|
31
|
+
}
|
|
32
|
+
/** A hard DB quota reserves an entire non-spilling transaction WAL, SHM and incident headroom. */
|
|
33
|
+
export declare class HostHistoryStore {
|
|
34
|
+
private readonly path;
|
|
35
|
+
private db;
|
|
36
|
+
private readonly budget;
|
|
37
|
+
private readonly maxRows;
|
|
38
|
+
private trimmed;
|
|
39
|
+
constructor(path: string, options?: Options);
|
|
40
|
+
/** Exact names only; rejects foreign/symlinked/oversized files before opening SQLite. */
|
|
41
|
+
private files;
|
|
42
|
+
private checkpoint;
|
|
43
|
+
stats(): HistoryStats;
|
|
44
|
+
private removeOldest;
|
|
45
|
+
append(points: HistoryPoint[], now: number): {
|
|
46
|
+
written: number;
|
|
47
|
+
paused: boolean;
|
|
48
|
+
stats: HistoryStats;
|
|
49
|
+
};
|
|
50
|
+
query(range: unknown, series: unknown, now: number): HistoryAnswer;
|
|
51
|
+
close(): void;
|
|
52
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// SQLite is synchronous: production imports this only inside the dedicated history worker.
|
|
2
|
+
import Database from 'better-sqlite3';
|
|
3
|
+
import { closeSync, lstatSync, openSync } from 'node:fs';
|
|
4
|
+
import { historyBudget, historyQuery, historySeries, HISTORY_BUCKET_MS, HISTORY_PAGE_BYTES, HISTORY_RAW_MS, HISTORY_ROLLUP_MS, HISTORY_SHM_BUDGET } from './host-monitoring-history-policy.js';
|
|
5
|
+
export { historyFiles, cleanupHistory } from './host-monitoring-history-files.js';
|
|
6
|
+
import { historyFiles } from './host-monitoring-history-files.js';
|
|
7
|
+
/** A hard DB quota reserves an entire non-spilling transaction WAL, SHM and incident headroom. */
|
|
8
|
+
export class HostHistoryStore {
|
|
9
|
+
path;
|
|
10
|
+
db;
|
|
11
|
+
budget;
|
|
12
|
+
maxRows;
|
|
13
|
+
trimmed = false;
|
|
14
|
+
constructor(path, options = {}) {
|
|
15
|
+
this.path = path;
|
|
16
|
+
this.budget = historyBudget(options.maxBytes);
|
|
17
|
+
this.maxRows = options.maxRows ?? 100_000;
|
|
18
|
+
if (!Number.isSafeInteger(this.maxRows) || this.maxRows < 16 || this.maxRows > 100_000)
|
|
19
|
+
throw Error('history_invalid_rows');
|
|
20
|
+
this.files(true);
|
|
21
|
+
this.db = new Database(path, { fileMustExist: true, timeout: 0 });
|
|
22
|
+
try {
|
|
23
|
+
this.db.pragma(`page_size = ${HISTORY_PAGE_BYTES}`);
|
|
24
|
+
if (this.db.pragma('page_size', { simple: true }) !== HISTORY_PAGE_BYTES)
|
|
25
|
+
throw Error('history_page_size');
|
|
26
|
+
this.db.pragma('busy_timeout = 0');
|
|
27
|
+
this.db.pragma('temp_store = MEMORY');
|
|
28
|
+
this.db.pragma('cache_size = -1024');
|
|
29
|
+
// Without dirty-page spill, one transaction emits at most one frame per DB page.
|
|
30
|
+
this.db.pragma('cache_spill = OFF');
|
|
31
|
+
this.db.pragma('journal_mode = WAL');
|
|
32
|
+
this.db.pragma('wal_autocheckpoint = 0');
|
|
33
|
+
this.db.pragma('synchronous = NORMAL');
|
|
34
|
+
if (Number(this.db.pragma(`max_page_count = ${this.budget.maxPages}`, { simple: true })) > this.budget.maxPages)
|
|
35
|
+
throw Error('history_cap');
|
|
36
|
+
const version = Number(this.db.pragma('user_version', { simple: true }));
|
|
37
|
+
if (version !== 0 && version !== 1)
|
|
38
|
+
throw Error('history_version');
|
|
39
|
+
this.db.exec(`CREATE TABLE IF NOT EXISTS monitoring_points (
|
|
40
|
+
resolution INTEGER NOT NULL, series TEXT NOT NULL, at INTEGER NOT NULL,
|
|
41
|
+
lo REAL NOT NULL, hi REAL NOT NULL, total REAL NOT NULL, n INTEGER NOT NULL, source_at INTEGER NOT NULL,
|
|
42
|
+
PRIMARY KEY (resolution,series,at)
|
|
43
|
+
) WITHOUT ROWID;
|
|
44
|
+
CREATE INDEX IF NOT EXISTS monitoring_points_time ON monitoring_points(resolution,at);
|
|
45
|
+
PRAGMA user_version = 1;`);
|
|
46
|
+
if (!this.checkpoint())
|
|
47
|
+
throw Error('history_busy');
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
this.db.close();
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Exact names only; rejects foreign/symlinked/oversized files before opening SQLite. */
|
|
55
|
+
files(create = false) {
|
|
56
|
+
let bytes = 0, wal = 0, reserved = 0;
|
|
57
|
+
for (const [i, name] of historyFiles(this.path).entries()) {
|
|
58
|
+
let info;
|
|
59
|
+
try {
|
|
60
|
+
info = lstatSync(name);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error.code === 'ENOENT')
|
|
64
|
+
continue;
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
if (!info.isFile() || info.nlink !== 1 || (process.getuid && (info.uid !== process.getuid() || (info.mode & 0o077) !== 0)))
|
|
68
|
+
throw Error('history_private_file_required');
|
|
69
|
+
bytes += info.size;
|
|
70
|
+
if (i >= 4)
|
|
71
|
+
reserved += info.size;
|
|
72
|
+
if (i === 0 && info.size > this.budget.dbBytes)
|
|
73
|
+
throw Error('history_cap');
|
|
74
|
+
if (i === 1) {
|
|
75
|
+
wal = info.size;
|
|
76
|
+
if (wal > this.budget.walBytes)
|
|
77
|
+
throw Error('history_cap');
|
|
78
|
+
}
|
|
79
|
+
if (i === 2 && info.size > HISTORY_SHM_BUDGET)
|
|
80
|
+
throw Error('history_cap');
|
|
81
|
+
if (i === 3 && info.size)
|
|
82
|
+
throw Error('history_unexpected_journal');
|
|
83
|
+
}
|
|
84
|
+
if (bytes > this.budget.maxBytes || reserved > this.budget.reserveBytes)
|
|
85
|
+
throw Error('history_cap');
|
|
86
|
+
if (create) {
|
|
87
|
+
try {
|
|
88
|
+
closeSync(openSync(this.path, 'wx', 0o600));
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (error.code !== 'EEXIST')
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { bytes, wal };
|
|
96
|
+
}
|
|
97
|
+
checkpoint() {
|
|
98
|
+
this.files();
|
|
99
|
+
const result = this.db.pragma('wal_checkpoint(TRUNCATE)');
|
|
100
|
+
return result[0]?.busy === 0 && this.files().wal === 0;
|
|
101
|
+
}
|
|
102
|
+
stats() {
|
|
103
|
+
return { bytes: this.files().bytes, rows: Number(this.db.prepare('SELECT count(*) n FROM monitoring_points').get().n), maxBytes: this.budget.maxBytes, dbBudget: this.budget.dbBytes, trimmed: this.trimmed };
|
|
104
|
+
}
|
|
105
|
+
removeOldest(limit) {
|
|
106
|
+
const removed = this.db.prepare(`DELETE FROM monitoring_points WHERE (resolution,series,at) IN
|
|
107
|
+
(SELECT resolution,series,at FROM monitoring_points ORDER BY at,resolution LIMIT ?)`).run(limit).changes;
|
|
108
|
+
if (removed)
|
|
109
|
+
this.trimmed = true;
|
|
110
|
+
return removed;
|
|
111
|
+
}
|
|
112
|
+
append(points, now) {
|
|
113
|
+
if (points.length > 64 || !Number.isSafeInteger(now) || now < 0 || points.some(p => !historySeries(p.series) || !Number.isSafeInteger(p.at) || p.at < 0 || p.at > now || !Number.isSafeInteger(p.sourceAt) || p.sourceAt < 0 || !Number.isFinite(p.value) || p.value < 0 || p.value > Number.MAX_SAFE_INTEGER))
|
|
114
|
+
throw Error('history_invalid_points');
|
|
115
|
+
// A pinned WAL must close before another write. Never accumulate a second transaction behind it.
|
|
116
|
+
const pressure = this.files().bytes >= this.budget.softBytes;
|
|
117
|
+
if (!this.checkpoint())
|
|
118
|
+
return { written: 0, paused: true, stats: this.stats() };
|
|
119
|
+
const prune = this.db.transaction(() => {
|
|
120
|
+
// The entire DB and row population are capped; expiry completes in this worker transaction.
|
|
121
|
+
for (const [resolution, cutoff] of [[30_000, now - HISTORY_RAW_MS], [HISTORY_BUCKET_MS, now - HISTORY_ROLLUP_MS]])
|
|
122
|
+
this.db.prepare('DELETE FROM monitoring_points WHERE resolution=? AND at<?').run(resolution, cutoff);
|
|
123
|
+
// At the soft mark prune oldest history, then release WAL below the low mark.
|
|
124
|
+
// DB+reserve+SHM alone is deliberately smaller than that low mark.
|
|
125
|
+
if (pressure)
|
|
126
|
+
this.removeOldest(2000);
|
|
127
|
+
const count = this.stats().rows;
|
|
128
|
+
if (count + points.length * 2 > this.maxRows)
|
|
129
|
+
this.removeOldest(Math.min(2000, Math.max(points.length * 2, count - Math.floor(this.maxRows * .9))));
|
|
130
|
+
const pages = Number(this.db.pragma('page_count', { simple: true })), free = Number(this.db.pragma('freelist_count', { simple: true }));
|
|
131
|
+
const growthPages = Math.min(128, Math.max(8, Math.floor(this.budget.maxPages / 8)));
|
|
132
|
+
if (this.budget.maxPages - pages + free < growthPages)
|
|
133
|
+
this.removeOldest(2000);
|
|
134
|
+
});
|
|
135
|
+
prune();
|
|
136
|
+
if (!this.checkpoint())
|
|
137
|
+
return { written: 0, paused: true, stats: this.stats() };
|
|
138
|
+
const current = this.stats();
|
|
139
|
+
if (current.rows + points.length * 2 > this.maxRows)
|
|
140
|
+
return { written: 0, paused: true, stats: current };
|
|
141
|
+
const put = this.db.prepare(`INSERT INTO monitoring_points VALUES(?,?,?,?,?,?,?,?) ON CONFLICT(resolution,series,at)
|
|
142
|
+
DO UPDATE SET lo=excluded.lo,hi=excluded.hi,total=excluded.total,n=excluded.n,source_at=excluded.source_at`);
|
|
143
|
+
const aggregate = this.db.prepare(`SELECT min(lo) lo,max(hi) hi,sum(total) total,sum(n) n,max(source_at) source_at
|
|
144
|
+
FROM monitoring_points WHERE resolution=30000 AND series=? AND at>=? AND at<?`);
|
|
145
|
+
this.db.transaction(() => {
|
|
146
|
+
const changed = new Map();
|
|
147
|
+
for (const p of points) {
|
|
148
|
+
const at = Math.floor(p.at / 30_000) * 30_000;
|
|
149
|
+
put.run(30_000, p.series, at, p.value, p.value, p.value, 1, p.sourceAt);
|
|
150
|
+
const roll = Math.floor(at / HISTORY_BUCKET_MS) * HISTORY_BUCKET_MS;
|
|
151
|
+
changed.set(`${p.series}:${roll}`, { series: p.series, at: roll });
|
|
152
|
+
}
|
|
153
|
+
for (const p of changed.values()) {
|
|
154
|
+
const a = aggregate.get(p.series, p.at, p.at + HISTORY_BUCKET_MS);
|
|
155
|
+
put.run(HISTORY_BUCKET_MS, p.series, p.at, a.lo, a.hi, a.total, a.n, a.source_at);
|
|
156
|
+
}
|
|
157
|
+
})();
|
|
158
|
+
const truncated = this.checkpoint(), stats = this.stats();
|
|
159
|
+
// Checkpointing releases journal bytes first; history retention/row pruning reuses allocated DB pages.
|
|
160
|
+
if (stats.bytes > this.budget.maxBytes || (pressure && truncated && stats.bytes > this.budget.lowBytes))
|
|
161
|
+
throw Error('history_cap');
|
|
162
|
+
return { written: points.length, paused: !truncated, stats };
|
|
163
|
+
}
|
|
164
|
+
query(range, series, now) {
|
|
165
|
+
const q = historyQuery(range, series, now);
|
|
166
|
+
const select = this.db.prepare(`SELECT CAST((at-?)/? AS INTEGER) bucket,min(lo) lo,max(hi) hi,sum(total) total,sum(n) n,max(source_at) source_at
|
|
167
|
+
FROM monitoring_points WHERE resolution=? AND series=? AND at>=? AND at<? GROUP BY bucket ORDER BY bucket LIMIT 241`);
|
|
168
|
+
return { start: q.start, end: q.end, step: q.step, series: q.series.map(id => {
|
|
169
|
+
const rows = select.all(q.start, q.step, q.resolution, id, q.start, q.end);
|
|
170
|
+
const byBucket = new Map(rows.map(r => [r.bucket, r]));
|
|
171
|
+
return { id, buckets: Array.from({ length: q.buckets }, (_, i) => { const r = byBucket.get(i); return { at: q.start + i * q.step, min: r?.lo ?? null, max: r?.hi ?? null, average: r && r.n ? r.total / r.n : null, count: r?.n ?? 0, sourceAt: r?.source_at ?? null }; }) };
|
|
172
|
+
}), stats: this.stats() };
|
|
173
|
+
}
|
|
174
|
+
close() { this.db.close(); }
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=host-monitoring-history-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-monitoring-history-store.js","sourceRoot":"","sources":["../src/host-monitoring-history-store.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,SA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AC,CAAA,IAAI,EAAC,KAAK,EAAC,CAAC,EAAE,CAAC,IAAE,CAAC,EAAC,QAAQ,EAAC,CAAC,EAAE,SAAS,IAAE,IAAI,EAAC,CAAC,CAAA,CAAC,CAAC,EAAC,CAAC;YAC9N,CAAC,CAAC,EAAC,KAAK,EAAC,IAAI,CAAC,KAAK,EAAE,EAAC,CAAC;IACzB,CAAC;IACD,KAAK,KAAS,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAA,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
2
|
+
import { HostHistoryStore } from './host-monitoring-history-store.js';
|
|
3
|
+
const data = workerData;
|
|
4
|
+
const enabled = new Int32Array(data.control), port = parentPort;
|
|
5
|
+
let store = null;
|
|
6
|
+
function reason(error) { const text = error?.message; return typeof text === 'string' && /^history_[a-z_]+$/.test(text) ? text : 'history_io_failed'; }
|
|
7
|
+
function close() { try {
|
|
8
|
+
store?.close();
|
|
9
|
+
}
|
|
10
|
+
finally {
|
|
11
|
+
store = null;
|
|
12
|
+
port.close();
|
|
13
|
+
} }
|
|
14
|
+
if (Atomics.load(enabled, 0) !== 1)
|
|
15
|
+
port.close();
|
|
16
|
+
else
|
|
17
|
+
try {
|
|
18
|
+
port.on('message', message => {
|
|
19
|
+
if (message?.op === 'close' || Atomics.load(enabled, 0) !== 1) {
|
|
20
|
+
close();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!Number.isSafeInteger(message?.id))
|
|
24
|
+
return;
|
|
25
|
+
try {
|
|
26
|
+
// Recheck the shared permission at execution, not only when the parent enqueued it.
|
|
27
|
+
if (message.op === 'append' && Atomics.load(enabled, 1) !== 1) {
|
|
28
|
+
port.postMessage({ id: message.id, ok: false, reason: 'history_low_space' });
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (message.op === 'append')
|
|
32
|
+
store ??= new HostHistoryStore(data.path);
|
|
33
|
+
if (!store) {
|
|
34
|
+
port.postMessage({ id: message.id, ok: false, reason: 'history_unavailable' });
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const value = message.op === 'append' ? store.append(message.points, message.now) : message.op === 'query' ? store.query(message.range, message.series, message.now) : null;
|
|
38
|
+
port.postMessage({ id: message.id, ok: value !== null, value });
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
port.postMessage({ id: message.id, ok: false, reason: reason(error) });
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
port.postMessage({ op: 'ready' });
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
port.postMessage({ op: 'failed', reason: reason(error) });
|
|
48
|
+
close();
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=host-monitoring-history-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-monitoring-history-worker.js","sourceRoot":"","sources":["../src/host-monitoring-history-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,UAAU,EAAC,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAC,gBAAgB,EAAC,MAAM,oCAAoC,CAAC;AACpE,MAAM,IAAI,GAAC,UAAqD,CAAC;AACjE,MAAM,OAAO,GAAC,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAC,IAAI,GAAC,UAAW,CAAC;AAC5D,IAAI,KAAK,GAAuB,IAAI,CAAC;AACrC,SAAS,MAAM,CAAC,KAAa,IAAU,MAAM,IAAI,GAAE,KAAe,EAAE,OAAO,CAAC,CAAA,OAAO,OAAO,IAAI,KAAG,QAAQ,IAAE,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,CAAC,CAAA,IAAI,CAAA,CAAC,CAAA,mBAAmB,CAAC,CAAA,CAAC;AACpK,SAAS,KAAK,KAAG,IAAG,CAAC;IAA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