@phnx-labs/agents-cli 1.22.127 → 1.23.1
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/CHANGELOG.md +108 -0
- package/README.md +15 -16
- package/dist/bootstrap.js +4 -3
- package/dist/commands/browser.js +4 -19
- package/dist/commands/cloud-transcripts.js +1 -2
- package/dist/commands/computer.d.ts +2 -6
- package/dist/commands/computer.js +12 -18
- package/dist/commands/daemon.js +70 -11
- package/dist/commands/exec.js +1 -1
- package/dist/commands/feed.js +1 -2
- package/dist/commands/focus.js +4 -1
- package/dist/commands/go.js +3 -2
- package/dist/commands/logs.js +3 -7
- package/dist/commands/menubar.js +55 -3
- package/dist/commands/projects.js +103 -40
- package/dist/commands/ps-roster.d.ts +0 -11
- package/dist/commands/ps-roster.js +3 -116
- package/dist/commands/ps.d.ts +10 -0
- package/dist/commands/ps.js +182 -1
- package/dist/commands/resume.js +1 -1
- package/dist/commands/sessions-browser.d.ts +0 -1
- package/dist/commands/sessions-browser.js +6 -23
- package/dist/commands/sessions-export.js +1 -1
- package/dist/commands/sessions-migrate.js +1 -1
- package/dist/commands/sessions-picker.d.ts +6 -32
- package/dist/commands/sessions-picker.js +81 -8
- package/dist/commands/sessions-render.js +1 -1
- package/dist/commands/sessions-resume.js +2 -2
- package/dist/commands/sessions-share.js +1 -1
- package/dist/commands/sessions-trace.js +1 -1
- package/dist/commands/sessions.d.ts +2 -176
- package/dist/commands/sessions.js +44 -1577
- package/dist/index.js +10 -11
- package/dist/lib/browser-client.d.ts +0 -21
- package/dist/lib/browser-client.js +1 -44
- package/dist/lib/computer/record.d.ts +1 -0
- package/dist/lib/computer/record.js +2 -16
- package/dist/lib/config-keys.d.ts +2 -2
- package/dist/lib/config-keys.js +8 -2
- package/dist/lib/daemon/account-state-daemon-service.d.ts +2 -2
- package/dist/lib/daemon/account-state-daemon-service.js +2 -2
- package/dist/lib/daemon/attention-notify-service.js +8 -4
- package/dist/lib/daemon/daemon.d.ts +5 -1
- package/dist/lib/daemon/daemon.js +54 -14
- package/dist/lib/daemon/diagnostics.d.ts +70 -0
- package/dist/lib/daemon/diagnostics.js +185 -0
- package/dist/lib/daemon/runner.js +3 -2
- package/dist/lib/daemon/service.d.ts +1 -1
- package/dist/lib/daemon/session-state-service.d.ts +1 -1
- package/dist/lib/daemon/session-state-service.js +2 -2
- package/dist/lib/daemon/supervisor.d.ts +8 -0
- package/dist/lib/daemon/supervisor.js +47 -6
- package/dist/lib/daemon-services.d.ts +4 -1
- package/dist/lib/daemon-services.js +36 -5
- package/dist/lib/daemon-ticks.d.ts +3 -1
- package/dist/lib/daemon-ticks.js +18 -12
- package/dist/lib/device-config.d.ts +1 -1
- package/dist/lib/device-config.js +48 -7
- package/dist/lib/feed/tool-activity.d.ts +22 -10
- package/dist/lib/feed/tool-activity.js +168 -32
- package/dist/lib/feed/tools.d.ts +55 -2
- package/dist/lib/feed/tools.js +22 -28
- package/dist/lib/feed/watch.js +12 -8
- package/dist/lib/github/open-prs.d.ts +41 -0
- package/dist/lib/github/open-prs.js +157 -0
- package/dist/lib/github/project-prs.d.ts +20 -1
- package/dist/lib/github/project-prs.js +8 -7
- package/dist/lib/helper-versions.js +1 -1
- package/dist/lib/menubar/install-menubar.d.ts +23 -7
- package/dist/lib/menubar/install-menubar.js +179 -30
- package/dist/lib/menubar/resolve-version.d.ts +1 -0
- package/dist/lib/menubar/resolve-version.js +4 -2
- package/dist/lib/menubar/snapshot.d.ts +2 -0
- package/dist/lib/menubar/snapshot.js +2 -0
- package/dist/lib/menubar/update-state.d.ts +15 -0
- package/dist/lib/menubar/update-state.js +36 -0
- package/dist/lib/owner-notify.d.ts +0 -12
- package/dist/lib/owner-notify.js +1 -10
- package/dist/lib/self-heal/checks/menubar-helper.js +1 -0
- package/dist/lib/session/active.js +18 -14
- package/dist/lib/session/cloud.d.ts +0 -1
- package/dist/lib/session/cloud.js +0 -5
- package/dist/lib/session/db.d.ts +0 -64
- package/dist/lib/session/db.js +0 -116
- package/dist/lib/session/pid-registry.js +9 -6
- package/dist/lib/session/presentation.d.ts +107 -1
- package/dist/lib/session/presentation.js +543 -4
- package/dist/lib/session/remote/remote-list.d.ts +5 -36
- package/dist/lib/session/remote/remote-list.js +16 -320
- package/dist/lib/session/resume-command.d.ts +9 -0
- package/dist/lib/session/resume-command.js +107 -0
- package/dist/lib/session/selection.d.ts +102 -0
- package/dist/lib/session/selection.js +443 -0
- package/dist/lib/session/tool-index.d.ts +0 -62
- package/dist/lib/session/tool-index.js +1 -537
- package/dist/lib/sessions-client.d.ts +1 -0
- package/dist/lib/sessions-client.js +17 -1
- package/dist/lib/standalone-tools.js +2 -2
- package/dist/lib/testdata/owner-notify-api.d.ts +0 -13
- package/dist/lib/testdata/owner-notify-api.js +3 -23
- package/package.json +1 -1
- package/dist/commands/browser-sessions-picker.d.ts +0 -9
- package/dist/commands/browser-sessions-picker.js +0 -136
- package/dist/commands/computer-sessions-picker.d.ts +0 -11
- package/dist/commands/computer-sessions-picker.js +0 -90
- package/dist/commands/sessions-tail.d.ts +0 -13
- package/dist/commands/sessions-tail.js +0 -222
- package/dist/lib/browser/native-history.test-fixture.d.ts +0 -12
- package/dist/lib/browser/native-history.test-fixture.js +0 -43
- package/dist/lib/browser/paths.d.ts +0 -9
- package/dist/lib/browser/paths.js +0 -31
- package/dist/lib/browser/record.d.ts +0 -4
- package/dist/lib/browser/record.js +0 -19
- package/dist/lib/browser/sessions-list.d.ts +0 -79
- package/dist/lib/browser/sessions-list.js +0 -415
- package/dist/lib/computer/sessions-list.d.ts +0 -78
- package/dist/lib/computer/sessions-list.js +0 -372
- package/dist/lib/daemon/owner-device-delivery-service.d.ts +0 -10
- package/dist/lib/daemon/owner-device-delivery-service.js +0 -28
package/dist/index.js
CHANGED
|
@@ -124,19 +124,18 @@ if (process.argv[2] === 'sessions') {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
if (isReadQuery(forwarded, { filters, host })) {
|
|
127
|
-
if (bin) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const res = spawnSync(command, [...prefix, ...forwarded], { stdio: 'inherit' });
|
|
131
|
-
if (res.error) {
|
|
132
|
-
process.stderr.write(`Failed to run \`sessions\`: ${res.error.message}\n`);
|
|
133
|
-
process.exit(1);
|
|
134
|
-
}
|
|
135
|
-
process.exit(res.status ?? 1);
|
|
127
|
+
if (!bin) {
|
|
128
|
+
process.stderr.write(`agents: the standalone \`sessions\` CLI was not found. Install it with ${SESSIONS_INSTALL_HINT}, or point $SESSIONS_BIN at its executable.\n`);
|
|
129
|
+
process.exit(1);
|
|
136
130
|
}
|
|
137
|
-
|
|
138
|
-
|
|
131
|
+
const { spawnSync } = await import('node:child_process');
|
|
132
|
+
const { command, prefix } = invocation(bin);
|
|
133
|
+
const res = spawnSync(command, [...prefix, ...forwarded], { stdio: 'inherit' });
|
|
134
|
+
if (res.error) {
|
|
135
|
+
process.stderr.write(`Failed to run \`sessions\`: ${res.error.message}\n`);
|
|
136
|
+
process.exit(1);
|
|
139
137
|
}
|
|
138
|
+
process.exit(res.status ?? 1);
|
|
140
139
|
}
|
|
141
140
|
}
|
|
142
141
|
await import('./bootstrap.js');
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare const BROWSER_CONTEXT_FD = 3;
|
|
2
|
-
export declare const BROWSER_EVENTS_FD = 4;
|
|
3
2
|
export declare class BrowserClientError extends Error {
|
|
4
3
|
code: string;
|
|
5
4
|
constructor(code: string, message: string);
|
|
@@ -12,29 +11,9 @@ export declare function invocation(bin: string): {
|
|
|
12
11
|
command: string;
|
|
13
12
|
prefix: string[];
|
|
14
13
|
};
|
|
15
|
-
export interface BrowserActionEvent {
|
|
16
|
-
event?: string;
|
|
17
|
-
ts?: string;
|
|
18
|
-
command: string;
|
|
19
|
-
invocationId?: string;
|
|
20
|
-
pid?: number;
|
|
21
|
-
task?: string;
|
|
22
|
-
profile?: string;
|
|
23
|
-
url?: string;
|
|
24
|
-
host?: string;
|
|
25
|
-
sessionId?: string;
|
|
26
|
-
launchId?: string;
|
|
27
|
-
actor?: string;
|
|
28
|
-
[key: string]: unknown;
|
|
29
|
-
}
|
|
30
|
-
export declare function parseEventLines(buffer: string): {
|
|
31
|
-
events: BrowserActionEvent[];
|
|
32
|
-
rest: string;
|
|
33
|
-
};
|
|
34
14
|
interface RunBrowserOptions {
|
|
35
15
|
argv: string[];
|
|
36
16
|
context: unknown;
|
|
37
|
-
onEvent?: (event: BrowserActionEvent) => void;
|
|
38
17
|
capture?: boolean;
|
|
39
18
|
}
|
|
40
19
|
interface RunBrowserResult {
|
|
@@ -4,7 +4,6 @@ import * as path from 'node:path';
|
|
|
4
4
|
import { findInPath } from './agent-spec/agents.js';
|
|
5
5
|
const INSTALL_HINT = 'npm i -g @phnx-labs/browser-cli';
|
|
6
6
|
export const BROWSER_CONTEXT_FD = 3;
|
|
7
|
-
export const BROWSER_EVENTS_FD = 4;
|
|
8
7
|
export class BrowserClientError extends Error {
|
|
9
8
|
code;
|
|
10
9
|
constructor(code, message) {
|
|
@@ -58,38 +57,17 @@ export function invocation(bin) {
|
|
|
58
57
|
return { command: process.execPath, prefix: [bin] };
|
|
59
58
|
return { command: bin, prefix: [] };
|
|
60
59
|
}
|
|
61
|
-
export function parseEventLines(buffer) {
|
|
62
|
-
const events = [];
|
|
63
|
-
const parts = buffer.split('\n');
|
|
64
|
-
const rest = parts.pop() ?? '';
|
|
65
|
-
for (const line of parts) {
|
|
66
|
-
const trimmed = line.trim();
|
|
67
|
-
if (!trimmed)
|
|
68
|
-
continue;
|
|
69
|
-
try {
|
|
70
|
-
const parsed = JSON.parse(trimmed);
|
|
71
|
-
if (parsed && typeof parsed === 'object' && typeof parsed.command === 'string') {
|
|
72
|
-
events.push(parsed);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return { events, rest };
|
|
79
|
-
}
|
|
80
60
|
export async function runBrowser(opts) {
|
|
81
61
|
const bin = resolveBrowserBin();
|
|
82
62
|
const { command, prefix } = invocation(bin);
|
|
83
63
|
const child = spawn(command, [...prefix, ...opts.argv], {
|
|
84
|
-
stdio: ['inherit', opts.capture ? 'pipe' : 'inherit', 'inherit', 'pipe'
|
|
64
|
+
stdio: ['inherit', opts.capture ? 'pipe' : 'inherit', 'inherit', 'pipe'],
|
|
85
65
|
env: {
|
|
86
66
|
...process.env,
|
|
87
67
|
BROWSER_CONTEXT_FD: String(BROWSER_CONTEXT_FD),
|
|
88
|
-
BROWSER_EVENTS_FD: String(BROWSER_EVENTS_FD),
|
|
89
68
|
},
|
|
90
69
|
});
|
|
91
70
|
const contextPipe = child.stdio[BROWSER_CONTEXT_FD];
|
|
92
|
-
const eventsPipe = child.stdio[BROWSER_EVENTS_FD];
|
|
93
71
|
if (contextPipe) {
|
|
94
72
|
contextPipe.on('error', () => { });
|
|
95
73
|
contextPipe.end(JSON.stringify(opts.context) + '\n');
|
|
@@ -101,26 +79,6 @@ export async function runBrowser(opts) {
|
|
|
101
79
|
stdout += chunk;
|
|
102
80
|
});
|
|
103
81
|
}
|
|
104
|
-
let pending = '';
|
|
105
|
-
const drained = new Promise((resolve) => {
|
|
106
|
-
if (!eventsPipe)
|
|
107
|
-
return resolve();
|
|
108
|
-
eventsPipe.setEncoding('utf-8');
|
|
109
|
-
eventsPipe.on('data', (chunk) => {
|
|
110
|
-
const { events, rest } = parseEventLines(pending + chunk);
|
|
111
|
-
pending = rest;
|
|
112
|
-
for (const event of events)
|
|
113
|
-
opts.onEvent?.(event);
|
|
114
|
-
});
|
|
115
|
-
eventsPipe.on('error', () => resolve());
|
|
116
|
-
eventsPipe.on('end', () => {
|
|
117
|
-
const { events } = parseEventLines(pending.endsWith('\n') ? pending : pending + '\n');
|
|
118
|
-
pending = '';
|
|
119
|
-
for (const event of events)
|
|
120
|
-
opts.onEvent?.(event);
|
|
121
|
-
resolve();
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
82
|
const exitCode = await new Promise((resolve, reject) => {
|
|
125
83
|
child.on('error', (err) => {
|
|
126
84
|
reject(new BrowserClientError('BROWSER_SPAWN_FAILED', `Could not run \`${bin}\`: ${err.message}`));
|
|
@@ -131,7 +89,6 @@ export async function runBrowser(opts) {
|
|
|
131
89
|
resolve(code);
|
|
132
90
|
});
|
|
133
91
|
});
|
|
134
|
-
await drained;
|
|
135
92
|
return { exitCode, stdout };
|
|
136
93
|
}
|
|
137
94
|
function osSignalNumber(signal) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ComputerActionEvent } from '../computer-client.js';
|
|
2
|
+
export declare const TASK_PREVIEW_MAX_CHARS = 200;
|
|
2
3
|
export declare const COMPUTER_INVOCATION_ID: `${string}-${string}-${string}-${string}-${string}`;
|
|
3
4
|
export declare function recordComputerAction(event: ComputerActionEvent, opts?: {
|
|
4
5
|
device?: string;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { emit as emitEvent } from '../feed/events.js';
|
|
3
|
-
import { recordComputerSession } from '../session/db.js';
|
|
4
|
-
import { resolveActor } from '../actor.js';
|
|
5
3
|
import { truncate } from '../feed/events.js';
|
|
6
|
-
|
|
4
|
+
export const TASK_PREVIEW_MAX_CHARS = 200;
|
|
7
5
|
export const COMPUTER_INVOCATION_ID = randomUUID();
|
|
8
6
|
export function recordComputerAction(event, opts = {}) {
|
|
9
|
-
const { event: _kind, command, invocationId, pid: _enginePid, host, sessionId, launchId, actor, ...rest } = event;
|
|
7
|
+
const { event: _kind, command, invocationId, pid: _enginePid, host, sessionId, launchId, actor: _actor, ...rest } = event;
|
|
10
8
|
const runId = invocationId || COMPUTER_INVOCATION_ID;
|
|
11
9
|
const drivenHost = host ?? opts.device;
|
|
12
10
|
const extra = typeof rest.task === 'string'
|
|
@@ -24,16 +22,4 @@ export function recordComputerAction(event, opts = {}) {
|
|
|
24
22
|
}
|
|
25
23
|
catch {
|
|
26
24
|
}
|
|
27
|
-
try {
|
|
28
|
-
recordComputerSession({
|
|
29
|
-
invocationId: runId,
|
|
30
|
-
sessionId: sessionId ?? process.env.AGENT_SESSION_ID ?? process.env.AGENTS_SESSION_ID,
|
|
31
|
-
launchId: launchId ?? process.env.AGENT_LAUNCH_ID,
|
|
32
|
-
actor: actor ?? resolveActor().id,
|
|
33
|
-
actionCount: 1,
|
|
34
|
-
taskPreview: typeof extra.task === 'string' ? extra.task : undefined,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
}
|
|
39
25
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AgentId } from './types.js';
|
|
2
2
|
import { type ModelTier } from './model-tiers.js';
|
|
3
3
|
export type ConfigScope = 'run' | 'interactive' | 'auto' | 'browser' | 'project' | 'device' | 'summarizer' | 'updates' | 'menubar';
|
|
4
|
-
export declare const MENUBAR_MENU_PROPERTIES: readonly ["defaultProject", "workingRowsShown", "showPreviews", "projectPriorityFilter", "hideCompletedMilestones", "bannerWhenNeedsYou", "includeOtherDeviceRequests", "groupBy", "thenBy", "projectScope", "projectSort", "ticketSort", "showPullRequests", "sessionUpdates", "deviceSort", "headlessAgent", "headlessFallbackAgent", "headlessPlacement", "pinnedProjects", "tabOrder", "hiddenTabs", "groupTicketsByMilestone", "prGroupOpen", "prGroupMerged", "homeGoals"];
|
|
4
|
+
export declare const MENUBAR_MENU_PROPERTIES: readonly ["defaultProject", "workingRowsShown", "showPreviews", "projectPriorityFilter", "hideCompletedMilestones", "bannerWhenNeedsYou", "includeOtherDeviceRequests", "groupBy", "thenBy", "projectScope", "projectSort", "ticketSort", "showPullRequests", "sessionUpdates", "deviceSort", "headlessAgent", "headlessFallbackAgent", "headlessPlacement", "pinnedProjects", "tabOrder", "hiddenTabs", "groupTicketsByMilestone", "prGroupOpen", "prGroupMerged", "homeGoals", "githubHidden", "githubDrafts", "githubBots"];
|
|
5
5
|
export declare const MENUBAR_STATUSBAR_PROPERTIES: readonly ["goalCountdown"];
|
|
6
6
|
export type MenubarSection = 'menu' | 'statusbar';
|
|
7
7
|
export declare const MENUBAR_CONFIG_KEYS: readonly string[];
|
|
@@ -45,7 +45,7 @@ export interface ParsedUpdatesConfigKey {
|
|
|
45
45
|
}
|
|
46
46
|
export interface ParsedMenubarConfigKey {
|
|
47
47
|
scope: 'menubar';
|
|
48
|
-
section
|
|
48
|
+
section?: MenubarSection;
|
|
49
49
|
property: string;
|
|
50
50
|
}
|
|
51
51
|
export type ParsedConfigKey = ParsedRunConfigKey | ParsedInteractiveConfigKey | ParsedAutoConfigKey | ParsedBrowserConfigKey | ParsedProjectConfigKey | ParsedDeviceConfigKey | ParsedSummarizerConfigKey | ParsedUpdatesConfigKey | ParsedMenubarConfigKey;
|
package/dist/lib/config-keys.js
CHANGED
|
@@ -27,9 +27,13 @@ export const MENUBAR_MENU_PROPERTIES = [
|
|
|
27
27
|
'prGroupOpen',
|
|
28
28
|
'prGroupMerged',
|
|
29
29
|
'homeGoals',
|
|
30
|
+
'githubHidden',
|
|
31
|
+
'githubDrafts',
|
|
32
|
+
'githubBots',
|
|
30
33
|
];
|
|
31
34
|
export const MENUBAR_STATUSBAR_PROPERTIES = ['goalCountdown'];
|
|
32
35
|
export const MENUBAR_CONFIG_KEYS = [
|
|
36
|
+
'menubar.autoUpdate',
|
|
33
37
|
...MENUBAR_MENU_PROPERTIES.map((p) => `menubar.menu.${p}`),
|
|
34
38
|
...MENUBAR_STATUSBAR_PROPERTIES.map((p) => `menubar.statusbar.${p}`),
|
|
35
39
|
];
|
|
@@ -99,6 +103,8 @@ export function parseConfigKey(key) {
|
|
|
99
103
|
if (summarizerMatch) {
|
|
100
104
|
return { scope: 'summarizer', property: summarizerMatch[1] };
|
|
101
105
|
}
|
|
106
|
+
if (raw === 'menubar.autoUpdate')
|
|
107
|
+
return { scope: 'menubar', property: 'autoUpdate' };
|
|
102
108
|
const menubarMatch = raw.match(/^menubar\.(menu|statusbar)\.(.+)$/);
|
|
103
109
|
if (menubarMatch) {
|
|
104
110
|
if (!MENUBAR_CONFIG_KEYS.includes(raw)) {
|
|
@@ -178,7 +184,7 @@ export function formatConfigKey(parsed) {
|
|
|
178
184
|
case 'updates':
|
|
179
185
|
return parsed.agent ? `updates.${parsed.agent}.auto` : 'updates.auto';
|
|
180
186
|
case 'menubar':
|
|
181
|
-
return `menubar.${parsed.section}.${parsed.property}`;
|
|
187
|
+
return parsed.section ? `menubar.${parsed.section}.${parsed.property}` : `menubar.${parsed.property}`;
|
|
182
188
|
}
|
|
183
189
|
}
|
|
184
190
|
export function listKnownConfigKeys() {
|
|
@@ -259,6 +265,6 @@ export function configKeyStorageHint(parsed) {
|
|
|
259
265
|
? `config.updatesAgentAuto.${parsed.agent} (central agents.yaml; syncs fleet-wide)`
|
|
260
266
|
: 'config.updatesAuto (central agents.yaml; syncs fleet-wide)';
|
|
261
267
|
case 'menubar':
|
|
262
|
-
return `config.menubar${parsed.section === 'menu' ? 'Menu' : 'Statusbar'}${parsed.property.charAt(0).toUpperCase()}${parsed.property.slice(1)} (central agents.yaml; syncs fleet-wide)`;
|
|
268
|
+
return `config.menubar${parsed.section === 'menu' ? 'Menu' : parsed.section === 'statusbar' ? 'Statusbar' : ''}${parsed.property.charAt(0).toUpperCase()}${parsed.property.slice(1)} (central agents.yaml; syncs fleet-wide)`;
|
|
263
269
|
}
|
|
264
270
|
}
|
|
@@ -19,10 +19,10 @@ export declare class AccountUsageService extends BasePeriodicService {
|
|
|
19
19
|
readonly intervalMs = 60000;
|
|
20
20
|
readonly deadlineMs: number;
|
|
21
21
|
private readonly refresh;
|
|
22
|
-
constructor(refresh?: (signal: AbortSignal) => Promise<void>);
|
|
22
|
+
constructor(refresh?: (signal: AbortSignal, log: DaemonContext['log']) => Promise<void>);
|
|
23
23
|
protected onStart(): Promise<void>;
|
|
24
24
|
protected onStop(): Promise<void>;
|
|
25
|
-
protected onTick(
|
|
25
|
+
protected onTick(ctx: DaemonContext, signal: AbortSignal): Promise<void>;
|
|
26
26
|
}
|
|
27
27
|
export declare class AccountAuthService extends BasePeriodicService {
|
|
28
28
|
readonly id: DaemonServiceId;
|
|
@@ -36,9 +36,9 @@ export class AccountUsageService extends BasePeriodicService {
|
|
|
36
36
|
}
|
|
37
37
|
async onStart() { }
|
|
38
38
|
async onStop() { }
|
|
39
|
-
async onTick(
|
|
39
|
+
async onTick(ctx, signal) {
|
|
40
40
|
await Promise.race([
|
|
41
|
-
this.refresh(signal),
|
|
41
|
+
this.refresh(signal, ctx.log),
|
|
42
42
|
abortRejection(signal, 'usage refresh aborted at deadline'),
|
|
43
43
|
]);
|
|
44
44
|
}
|
|
@@ -33,6 +33,7 @@ import { blockIdForSession, readBlock, readResolution } from '../feed/feed.js';
|
|
|
33
33
|
import { reconcileAttention, harnessOf } from '../feed/attention.js';
|
|
34
34
|
import { notifyDesktop } from '../menubar/notify-desktop.js';
|
|
35
35
|
import { BasePeriodicService } from './service.js';
|
|
36
|
+
import { span, spanSync } from './diagnostics.js';
|
|
36
37
|
const ATTENTION_NOTIFY_TICK_MS = 5_000;
|
|
37
38
|
const ATTENTION_NOTIFY_DEADLINE_MS = 10_000;
|
|
38
39
|
const LEDGER_RETENTION_MS = 14 * 24 * 60 * 60 * 1000;
|
|
@@ -101,19 +102,20 @@ export class AttentionNotifyService extends BasePeriodicService {
|
|
|
101
102
|
async onStop() {
|
|
102
103
|
}
|
|
103
104
|
async onTick(ctx) {
|
|
104
|
-
const sessions = await this.getSessions();
|
|
105
|
+
const sessions = await span('attention.sessions', () => this.getSessions(), () => ({}));
|
|
105
106
|
const host = machineId();
|
|
107
|
+
let posted = 0;
|
|
106
108
|
for (const session of sessions) {
|
|
107
109
|
if (!session.sessionId)
|
|
108
110
|
continue;
|
|
109
111
|
const projected = { ...session, host };
|
|
110
112
|
const blockId = blockIdForSession(session.sessionId);
|
|
111
|
-
const item = reconcileAttention({
|
|
113
|
+
const item = spanSync('attention.reconcile', () => reconcileAttention({
|
|
112
114
|
block: readBlock(blockId, this.feedRoot),
|
|
113
115
|
session: projected,
|
|
114
116
|
resolution: readResolution(blockId, this.feedRoot),
|
|
115
117
|
nowMs: this.now(),
|
|
116
|
-
});
|
|
118
|
+
}));
|
|
117
119
|
if (!item || !BANNER_KINDS[item.kind])
|
|
118
120
|
continue;
|
|
119
121
|
if (await this.hasNotified(item.key))
|
|
@@ -123,9 +125,11 @@ export class AttentionNotifyService extends BasePeriodicService {
|
|
|
123
125
|
continue;
|
|
124
126
|
this.notify(notification);
|
|
125
127
|
await this.markNotified(item.key);
|
|
126
|
-
|
|
128
|
+
posted += 1;
|
|
129
|
+
ctx.log('INFO', `attention-notify: posted ${item.kind} banner for ${item.key}`, { event: 'attention.posted', kind: item.kind, key: item.key });
|
|
127
130
|
}
|
|
128
131
|
await this.pruneLedger();
|
|
132
|
+
ctx.log('DEBUG', `attention-notify: ${sessions.length} session(s) reconciled, ${posted} banner(s) posted`, { event: 'attention.tick', sessions: sessions.length, posted });
|
|
129
133
|
}
|
|
130
134
|
ledgerPath(key) {
|
|
131
135
|
return path.join(this.ledgerDir, encodeURIComponent(key));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isolatedHomeSuffix } from '../service-manifest.js';
|
|
2
2
|
import { getAgentsBinPath } from '../cli-entry.js';
|
|
3
3
|
import type { ServiceHealth } from './service.js';
|
|
4
|
+
import { type LogFields, type LogLevel } from './diagnostics.js';
|
|
4
5
|
export declare function getServiceSupervisorHealth(): Record<string, ServiceHealth> | null;
|
|
5
6
|
export declare function productionDaemonServiceNames(): {
|
|
6
7
|
systemdUnit: string;
|
|
@@ -33,7 +34,10 @@ export declare function reapStrayDaemons(keepPid?: number): {
|
|
|
33
34
|
details: string[];
|
|
34
35
|
};
|
|
35
36
|
export declare function isLiveDaemon(pid: number): boolean;
|
|
36
|
-
export declare function
|
|
37
|
+
export declare function setDaemonLogLevel(level: LogLevel): void;
|
|
38
|
+
export declare function getDaemonLogLevel(): LogLevel;
|
|
39
|
+
export declare function applyConfiguredLogLevel(): void;
|
|
40
|
+
export declare function log(level: string, message: string, fields?: LogFields): void;
|
|
37
41
|
export declare function guardSignalHandler(handler: () => void, onError: (err: unknown) => void): () => void;
|
|
38
42
|
export declare function anchorDaemonCwd(): string | null;
|
|
39
43
|
export declare function warnEphemeralDaemonRoot(resolveBin?: () => string): string | null;
|
|
@@ -22,8 +22,9 @@ import { isSchedulerEnabled, assertSchedulerEnabled, isDaemonEnabled } from '../
|
|
|
22
22
|
import { recordSubsystemOk, recordSubsystemError, recordSubsystemErrorReason, readSubsystemHealth, readRecentDaemonRestarts, SUBSYSTEM_DAEMON_START } from '../daemon-health.js';
|
|
23
23
|
import { ServiceSupervisor } from './supervisor.js';
|
|
24
24
|
import { emit, emitAsync, emitRoutineEnd } from '../feed/events.js';
|
|
25
|
-
import { readDaemonServicesConfig, drainDaemonServiceRestartQueue } from '../daemon-services.js';
|
|
25
|
+
import { readDaemonServicesConfig, readDaemonLogLevel, drainDaemonServiceRestartQueue } from '../daemon-services.js';
|
|
26
26
|
import { sleepSync } from '../fs-atomic.js';
|
|
27
|
+
import { DaemonVitals, installSpanLog, levelEnabled, topSpansSinceReport } from './diagnostics.js';
|
|
27
28
|
let activeServiceSupervisor = null;
|
|
28
29
|
export function getServiceSupervisorHealth() {
|
|
29
30
|
return activeServiceSupervisor?.health() ?? null;
|
|
@@ -428,17 +429,52 @@ function rotateLogsIfNeeded(logPath) {
|
|
|
428
429
|
}
|
|
429
430
|
catch { }
|
|
430
431
|
}
|
|
431
|
-
|
|
432
|
+
let logThreshold = 'INFO';
|
|
433
|
+
export function setDaemonLogLevel(level) {
|
|
434
|
+
logThreshold = level;
|
|
435
|
+
}
|
|
436
|
+
export function getDaemonLogLevel() {
|
|
437
|
+
return logThreshold;
|
|
438
|
+
}
|
|
439
|
+
function redactFields(value) {
|
|
440
|
+
if (typeof value === 'string')
|
|
441
|
+
return redactSecrets(value);
|
|
442
|
+
if (Array.isArray(value))
|
|
443
|
+
return value.map(redactFields);
|
|
444
|
+
if (value && typeof value === 'object') {
|
|
445
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, redactFields(v)]));
|
|
446
|
+
}
|
|
447
|
+
return value;
|
|
448
|
+
}
|
|
449
|
+
export function applyConfiguredLogLevel() {
|
|
450
|
+
const before = logThreshold;
|
|
451
|
+
try {
|
|
452
|
+
logThreshold = readDaemonLogLevel();
|
|
453
|
+
}
|
|
454
|
+
catch (err) {
|
|
455
|
+
log('WARN', `daemon log level unchanged (${before.toLowerCase()}): ${err.message}`);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (logThreshold !== before)
|
|
459
|
+
log('INFO', `daemon log level ${before.toLowerCase()} -> ${logThreshold.toLowerCase()}`, { event: 'log.level', from: before, to: logThreshold });
|
|
460
|
+
}
|
|
461
|
+
export function log(level, message, fields) {
|
|
462
|
+
if (!levelEnabled(level, logThreshold))
|
|
463
|
+
return;
|
|
432
464
|
const logPath = getDaemonLogPath();
|
|
433
465
|
rotateLogsIfNeeded(logPath);
|
|
434
|
-
const
|
|
466
|
+
const lvl = level.toUpperCase();
|
|
467
|
+
const entry = { ts: new Date().toISOString(), level: lvl, message: redactSecrets(message) };
|
|
468
|
+
if (fields && Object.keys(fields).length > 0)
|
|
469
|
+
entry.data = redactFields(fields);
|
|
435
470
|
fs.appendFileSync(logPath, JSON.stringify(entry) + '\n', 'utf-8');
|
|
436
471
|
try {
|
|
437
472
|
fs.chmodSync(logPath, 0o600);
|
|
438
473
|
}
|
|
439
474
|
catch { }
|
|
475
|
+
if (lvl === 'DEBUG')
|
|
476
|
+
return;
|
|
440
477
|
try {
|
|
441
|
-
const lvl = level.toUpperCase();
|
|
442
478
|
const event = lvl === 'ERROR' || lvl === 'FATAL' ? 'daemon.error'
|
|
443
479
|
: lvl === 'START' || /starting|started/i.test(message) ? 'daemon.start'
|
|
444
480
|
: lvl === 'STOP' || /stopping|stopped|shutting down/i.test(message) ? 'daemon.stop'
|
|
@@ -504,7 +540,7 @@ export function assertTestDaemonHome(daemonDir = getDaemonDir(), testHome = proc
|
|
|
504
540
|
}
|
|
505
541
|
export async function runDaemon() {
|
|
506
542
|
assertTestDaemonHome();
|
|
507
|
-
const [{ SessionIndexService }, { SessionSummarizerService }, { SessionTitleService }, { AccountUsageService, AccountAuthService }, { CatchupService }, { WatchdogService }, { DeviceProbeService }, { SelfHealService }, { SelfUpdateService }, { HarnessUpdateService }, { AuthSyncService }, { UsageSyncService }, { StateDirCheckService }, { SessionStateService }, { FeedStreamService }, { AttentionNotifyService }, {
|
|
543
|
+
const [{ SessionIndexService }, { SessionSummarizerService }, { SessionTitleService }, { AccountUsageService, AccountAuthService }, { CatchupService }, { WatchdogService }, { DeviceProbeService }, { SelfHealService }, { SelfUpdateService }, { HarnessUpdateService }, { AuthSyncService }, { UsageSyncService }, { StateDirCheckService }, { SessionStateService }, { FeedStreamService }, { AttentionNotifyService }, { RecordingsService }, { WebhookReceiverService }, { HeartbeatService }, { TmuxReapService },] = await Promise.all([
|
|
508
544
|
import('./session-index-service.js'),
|
|
509
545
|
import('./session-summarizer-service.js'),
|
|
510
546
|
import('./session-title-service.js'),
|
|
@@ -521,7 +557,6 @@ export async function runDaemon() {
|
|
|
521
557
|
import('./session-state-service.js'),
|
|
522
558
|
import('./feed-stream-service.js'),
|
|
523
559
|
import('./attention-notify-service.js'),
|
|
524
|
-
import('./owner-device-delivery-service.js'),
|
|
525
560
|
import('../recordings/service.js'),
|
|
526
561
|
import('./webhook-receiver-service.js'),
|
|
527
562
|
import('./heartbeat-service.js'),
|
|
@@ -554,7 +589,10 @@ export async function runDaemon() {
|
|
|
554
589
|
const lifetimePath = path.join(getDaemonDir(), LIFETIME_FILE);
|
|
555
590
|
const lifetimeToken = `${process.pid}:${Date.now()}`;
|
|
556
591
|
fs.writeFileSync(lifetimePath, lifetimeToken, 'utf-8');
|
|
557
|
-
|
|
592
|
+
applyConfiguredLogLevel();
|
|
593
|
+
log('INFO', `Daemon started (PID: ${process.pid})`, {
|
|
594
|
+
event: 'daemon.start', pid: process.pid, node: process.version, logLevel: getDaemonLogLevel().toLowerCase(),
|
|
595
|
+
});
|
|
558
596
|
anchorDaemonCwd();
|
|
559
597
|
warnEphemeralDaemonRoot();
|
|
560
598
|
try {
|
|
@@ -590,7 +628,12 @@ export async function runDaemon() {
|
|
|
590
628
|
catch (err) {
|
|
591
629
|
log('ERROR', `Stray daemon reaper failed: ${err.message}`);
|
|
592
630
|
}
|
|
593
|
-
|
|
631
|
+
let supervisorRef = null;
|
|
632
|
+
const vitals = new DaemonVitals({ log, extra: () => ({ inFlight: supervisorRef?.inFlightTicks() ?? [] }) });
|
|
633
|
+
installSpanLog(log);
|
|
634
|
+
vitals.start();
|
|
635
|
+
const supervisor = new ServiceSupervisor({ diagnostics: () => ({ vitals: vitals.snapshot(), topSpansSinceReport: topSpansSinceReport(8) }) });
|
|
636
|
+
supervisorRef = supervisor;
|
|
594
637
|
if (isEnabled('session-state')) {
|
|
595
638
|
supervisor.register(new SessionStateService(() => supervisor.runNow('session-state')));
|
|
596
639
|
}
|
|
@@ -632,12 +675,6 @@ export async function runDaemon() {
|
|
|
632
675
|
supervisor.register(new AttentionNotifyService());
|
|
633
676
|
else
|
|
634
677
|
log('INFO', 'Attention-notify service disabled');
|
|
635
|
-
if (process.platform === 'darwin') {
|
|
636
|
-
if (isEnabled('owner-device-delivery'))
|
|
637
|
-
supervisor.register(new OwnerDeviceDeliveryService());
|
|
638
|
-
else
|
|
639
|
-
log('INFO', 'Owner device-delivery service disabled');
|
|
640
|
-
}
|
|
641
678
|
if (isEnabled('session-title'))
|
|
642
679
|
supervisor.register(new SessionTitleService());
|
|
643
680
|
else
|
|
@@ -820,6 +857,7 @@ export async function runDaemon() {
|
|
|
820
857
|
recordSubsystemOk(SUBSYSTEM_DAEMON_START);
|
|
821
858
|
const handleReload = () => {
|
|
822
859
|
log('INFO', 'Reloading jobs (SIGHUP)');
|
|
860
|
+
applyConfiguredLogLevel();
|
|
823
861
|
const reloadedConfig = readDaemonServicesConfig();
|
|
824
862
|
const reloadedEnabled = (id) => reloadedConfig.services[id] !== false;
|
|
825
863
|
for (const id of Object.keys(servicesConfig.services)) {
|
|
@@ -880,6 +918,8 @@ export async function runDaemon() {
|
|
|
880
918
|
// Cleanup removes lifetime, pid, heartbeat, and registry state only when each still belongs to this instance.
|
|
881
919
|
const handleShutdown = singleShot(async () => {
|
|
882
920
|
log('INFO', 'Daemon shutting down');
|
|
921
|
+
vitals.report();
|
|
922
|
+
vitals.stop();
|
|
883
923
|
await supervisor.stopAll();
|
|
884
924
|
activeServiceSupervisor = null;
|
|
885
925
|
stopScheduler();
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export declare const LOG_LEVELS: readonly ["DEBUG", "INFO", "WARN", "ERROR"];
|
|
2
|
+
export type LogLevel = (typeof LOG_LEVELS)[number];
|
|
3
|
+
export type LogFields = Record<string, unknown>;
|
|
4
|
+
export type DiagnosticLog = (level: LogLevel, message: string, fields?: LogFields) => void;
|
|
5
|
+
export declare function parseLogLevel(raw: unknown): LogLevel | undefined;
|
|
6
|
+
export declare function levelRank(level: string): number;
|
|
7
|
+
export declare function levelEnabled(level: string, threshold: LogLevel): boolean;
|
|
8
|
+
export interface SpanRecord {
|
|
9
|
+
name: string;
|
|
10
|
+
kind: 'sync' | 'async';
|
|
11
|
+
startMs: number;
|
|
12
|
+
durMs: number;
|
|
13
|
+
fields?: LogFields;
|
|
14
|
+
}
|
|
15
|
+
export interface SpanAggregate {
|
|
16
|
+
name: string;
|
|
17
|
+
kind: 'sync' | 'async';
|
|
18
|
+
count: number;
|
|
19
|
+
totalMs: number;
|
|
20
|
+
maxMs: number;
|
|
21
|
+
}
|
|
22
|
+
export declare function installSpanLog(log: DiagnosticLog | null, opts?: {
|
|
23
|
+
slowSyncMs?: number;
|
|
24
|
+
}): void;
|
|
25
|
+
export declare function spanSync<T>(name: string, fn: () => T, fields?: () => LogFields | undefined): T;
|
|
26
|
+
export declare function span<T>(name: string, fn: () => Promise<T>, fields?: () => LogFields | undefined): Promise<T>;
|
|
27
|
+
export declare function syncSpansBetween(fromMs: number, toMs: number): SpanRecord[];
|
|
28
|
+
export declare function topSpansSinceReport(limit: number): SpanAggregate[];
|
|
29
|
+
export interface VitalsSnapshot {
|
|
30
|
+
uptimeS: number;
|
|
31
|
+
loop: {
|
|
32
|
+
p50Ms: number;
|
|
33
|
+
p99Ms: number;
|
|
34
|
+
maxMs: number;
|
|
35
|
+
};
|
|
36
|
+
cpuPct: number;
|
|
37
|
+
rssMb: number;
|
|
38
|
+
heapUsedMb: number;
|
|
39
|
+
load1: number;
|
|
40
|
+
cores: number;
|
|
41
|
+
}
|
|
42
|
+
interface VitalsOptions {
|
|
43
|
+
log: DiagnosticLog;
|
|
44
|
+
reportMs?: number;
|
|
45
|
+
probeMs?: number;
|
|
46
|
+
stallMs?: number;
|
|
47
|
+
extra?: () => LogFields;
|
|
48
|
+
}
|
|
49
|
+
export declare class DaemonVitals {
|
|
50
|
+
private readonly log;
|
|
51
|
+
private readonly reportMs;
|
|
52
|
+
private readonly probeMs;
|
|
53
|
+
private readonly stallMs;
|
|
54
|
+
private readonly extra?;
|
|
55
|
+
private histogram;
|
|
56
|
+
private probeTimer?;
|
|
57
|
+
private reportTimer?;
|
|
58
|
+
private lastProbe;
|
|
59
|
+
private lastCpu;
|
|
60
|
+
private lastCpuAt;
|
|
61
|
+
private readonly startedAt;
|
|
62
|
+
constructor(opts: VitalsOptions);
|
|
63
|
+
start(): void;
|
|
64
|
+
stop(): void;
|
|
65
|
+
snapshot(): VitalsSnapshot;
|
|
66
|
+
private safe;
|
|
67
|
+
private probe;
|
|
68
|
+
report(): void;
|
|
69
|
+
}
|
|
70
|
+
export {};
|