@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
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import type
|
|
4
|
-
import { type ToolRow } from './tools.js';
|
|
1
|
+
import type { SessionMeta } from '@phnx-labs/sessions-cli/reader';
|
|
2
|
+
import type { BrowserSessionRow, ComputerRunRow, LiveBrowserTask } from './tools.js';
|
|
3
|
+
import { type ToolKind, type ToolRow } from './tools.js';
|
|
5
4
|
export declare const TOOL_SWEEP_MS = 5000;
|
|
5
|
+
type StandaloneTool = 'browser' | 'computer';
|
|
6
|
+
export declare class ToolNotInstalledError extends Error {
|
|
7
|
+
}
|
|
8
|
+
/** Runs a standalone tool's `--json` listing; any failure rejects so the snapshot is reported incomplete. */
|
|
9
|
+
export declare function readToolJson(tool: StandaloneTool, argv: string[]): Promise<unknown[]>;
|
|
10
|
+
export declare function readStandaloneBrowserRows(): Promise<BrowserSessionRow[]>;
|
|
11
|
+
export declare function readStandaloneComputerRows(): Promise<ComputerRunRow[]>;
|
|
12
|
+
/** The tools record a session or launch id; only agents-cli's index can say which agent session that was. */
|
|
13
|
+
export declare function linkToolSessions<T extends {
|
|
14
|
+
sessionId?: string;
|
|
15
|
+
launchId?: string;
|
|
16
|
+
linkedSession?: SessionMeta;
|
|
17
|
+
}>(rows: T[]): T[];
|
|
6
18
|
export interface ToolDiff {
|
|
7
19
|
upserts: ToolRow[];
|
|
8
20
|
removes: string[];
|
|
9
21
|
}
|
|
10
22
|
interface ToolSources {
|
|
11
|
-
browserRows?: () => BrowserSessionRow[]
|
|
12
|
-
computerRows?: () => ComputerRunRow[]
|
|
23
|
+
browserRows?: () => BrowserSessionRow[] | Promise<BrowserSessionRow[]>;
|
|
24
|
+
computerRows?: () => ComputerRunRow[] | Promise<ComputerRunRow[]>;
|
|
13
25
|
bindings?: () => Array<{
|
|
14
26
|
name: string;
|
|
15
27
|
device?: string;
|
|
@@ -23,12 +35,13 @@ interface ToolSources {
|
|
|
23
35
|
}
|
|
24
36
|
export interface ToolSnapshot {
|
|
25
37
|
rows: ToolRow[];
|
|
26
|
-
|
|
38
|
+
incomplete: ToolKind[];
|
|
39
|
+
retry: boolean;
|
|
27
40
|
}
|
|
28
|
-
export declare function collectToolRows(scope: string, sources?: ToolSources): ToolSnapshot
|
|
41
|
+
export declare function collectToolRows(scope: string, sources?: ToolSources): Promise<ToolSnapshot>;
|
|
29
42
|
export declare class ToolRowSet {
|
|
30
43
|
private readonly rows;
|
|
31
|
-
diff(next: ToolRow[]): ToolDiff;
|
|
44
|
+
diff(next: ToolRow[], unreadKinds?: readonly ToolKind[]): ToolDiff;
|
|
32
45
|
reset(rows: ToolRow[]): void;
|
|
33
46
|
}
|
|
34
47
|
interface ToolWatchOptions {
|
|
@@ -40,7 +53,6 @@ interface ToolWatchOptions {
|
|
|
40
53
|
sources?: ToolSources;
|
|
41
54
|
initial?: ToolRow[];
|
|
42
55
|
}
|
|
43
|
-
export declare function toolWatchRoots(): string[];
|
|
44
56
|
export declare function readLiveBrowserTasks(root?: string): LiveBrowserTask[];
|
|
45
57
|
export declare function watchToolActivity(options: ToolWatchOptions): {
|
|
46
58
|
armed: () => boolean;
|
|
@@ -1,31 +1,156 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
1
2
|
import * as fs from 'node:fs';
|
|
2
3
|
import * as path from 'node:path';
|
|
3
|
-
import { getBrowserRuntimeDir,
|
|
4
|
+
import { getBrowserRuntimeDir, getCacheDir } from '../state.js';
|
|
4
5
|
import { getEventsDir } from './events.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
6
|
+
import { readRecentActivity } from './activity.js';
|
|
7
|
+
import { span, spanSync } from '../daemon/diagnostics.js';
|
|
8
|
+
import { invocation as browserInvocation, resolveBrowserBin } from '../browser-client.js';
|
|
9
|
+
import { invocation as computerInvocation, resolveComputerBin } from '../computer-client.js';
|
|
10
|
+
import { getSessionById } from '../session/db.js';
|
|
11
|
+
import { loadHookSessionIndex } from '../session/hook-sessions.js';
|
|
12
|
+
import { listPidSessionEntries } from '../session/pid-registry.js';
|
|
7
13
|
import { boundBrowserRow, projectBrowserToolRow, projectComputerToolRow, sortToolRows } from './tools.js';
|
|
8
14
|
export const TOOL_SWEEP_MS = 5_000;
|
|
9
15
|
const TOOL_COMPUTER_LIMIT = 500;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
const TOOL_JSON_MAX_BYTES = 64 * 1024 * 1024;
|
|
17
|
+
const TOOL_JSON_TIMEOUT_MS = 30_000;
|
|
18
|
+
export class ToolNotInstalledError extends Error {
|
|
19
|
+
}
|
|
20
|
+
function resolveTool(tool) {
|
|
21
|
+
let bin;
|
|
22
|
+
try {
|
|
23
|
+
bin = tool === 'browser' ? resolveBrowserBin() : resolveComputerBin();
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
throw new ToolNotInstalledError(`${error.message}\nRun \`agents setup tools\` to install the pinned \`${tool}\` CLI.`);
|
|
27
|
+
}
|
|
28
|
+
return tool === 'browser' ? browserInvocation(bin) : computerInvocation(bin);
|
|
29
|
+
}
|
|
30
|
+
/** Runs a standalone tool's `--json` listing; any failure rejects so the snapshot is reported incomplete. */
|
|
31
|
+
export async function readToolJson(tool, argv) {
|
|
32
|
+
const { command, prefix } = resolveTool(tool);
|
|
33
|
+
const label = `\`${tool} ${argv.join(' ')}\``;
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const child = spawn(command, [...prefix, ...argv], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
36
|
+
const stdout = [];
|
|
37
|
+
let stdoutBytes = 0;
|
|
38
|
+
let stderr = '';
|
|
39
|
+
let failure;
|
|
40
|
+
const fail = (error) => { failure ??= error; child.kill('SIGKILL'); };
|
|
41
|
+
const timer = setTimeout(() => fail(new Error(`${label} did not finish within ${TOOL_JSON_TIMEOUT_MS / 1000}s`)), TOOL_JSON_TIMEOUT_MS);
|
|
42
|
+
child.stdout.on('data', (chunk) => {
|
|
43
|
+
stdoutBytes += chunk.length;
|
|
44
|
+
if (stdoutBytes > TOOL_JSON_MAX_BYTES)
|
|
45
|
+
fail(new Error(`${label} printed more than ${TOOL_JSON_MAX_BYTES} bytes`));
|
|
46
|
+
else
|
|
47
|
+
stdout.push(chunk);
|
|
48
|
+
});
|
|
49
|
+
child.stderr.on('data', (chunk) => { if (stderr.length < 4096)
|
|
50
|
+
stderr += chunk.toString('utf8'); });
|
|
51
|
+
child.on('error', (error) => fail(new Error(`${label} failed: ${error.message}`)));
|
|
52
|
+
child.on('close', (code, signal) => {
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
if (failure)
|
|
55
|
+
return reject(failure);
|
|
56
|
+
if (code !== 0)
|
|
57
|
+
return reject(new Error(`${label} exited ${code ?? signal}: ${stderr.trim().slice(0, 500)}`));
|
|
58
|
+
let value;
|
|
59
|
+
try {
|
|
60
|
+
value = JSON.parse(Buffer.concat(stdout).toString('utf8'));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
return reject(new Error(`${label} printed unparseable JSON: ${error.message}`));
|
|
64
|
+
}
|
|
65
|
+
if (!Array.isArray(value))
|
|
66
|
+
return reject(new Error(`${label} printed ${typeof value}, expected an array of rows`));
|
|
67
|
+
resolve(value);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function isRecord(value) {
|
|
72
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
73
|
+
}
|
|
74
|
+
export async function readStandaloneBrowserRows() {
|
|
75
|
+
return (await readToolJson('browser', ['sessions', '--tasks', '--json', '--no-interactive'])).map((row, index) => {
|
|
76
|
+
if (!isRecord(row) || typeof row.profile !== 'string' || !Array.isArray(row.artifacts)
|
|
77
|
+
|| !isRecord(row.counts) || typeof row.latestMtimeMs !== 'number') {
|
|
78
|
+
throw new Error(`\`browser sessions --json\` row ${index} lacks profile, artifacts, counts or latestMtimeMs`);
|
|
79
|
+
}
|
|
80
|
+
return row;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
export async function readStandaloneComputerRows() {
|
|
84
|
+
return (await readToolJson('computer', ['sessions', '--json', '--no-interactive', '--limit', String(TOOL_COMPUTER_LIMIT)])).map((row, index) => {
|
|
85
|
+
if (!isRecord(row) || typeof row.machine !== 'string' || !Array.isArray(row.actions)
|
|
86
|
+
|| !isRecord(row.counts) || typeof row.startMs !== 'number' || typeof row.endMs !== 'number') {
|
|
87
|
+
throw new Error(`\`computer sessions --json\` row ${index} lacks machine, actions, counts or startMs/endMs`);
|
|
88
|
+
}
|
|
89
|
+
return row;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function buildLaunchSessionIndex() {
|
|
93
|
+
return spanSync('feed.tools.launch-index', buildLaunchSessionIndexNow);
|
|
94
|
+
}
|
|
95
|
+
function buildLaunchSessionIndexNow() {
|
|
96
|
+
const byLaunchId = new Map();
|
|
97
|
+
for (const event of readRecentActivity({ maxBytesPerSession: 64 * 1024 })) {
|
|
98
|
+
if (event.launchId && event.sessionId)
|
|
99
|
+
byLaunchId.set(event.launchId, event.sessionId);
|
|
100
|
+
}
|
|
101
|
+
for (const [launchId, record] of loadHookSessionIndex().byLaunchId) {
|
|
102
|
+
if (record.session_id)
|
|
103
|
+
byLaunchId.set(launchId, record.session_id);
|
|
104
|
+
}
|
|
105
|
+
for (const entry of listPidSessionEntries()) {
|
|
106
|
+
if (entry.launchId && entry.sessionId)
|
|
107
|
+
byLaunchId.set(entry.launchId, entry.sessionId);
|
|
108
|
+
}
|
|
109
|
+
return byLaunchId;
|
|
110
|
+
}
|
|
111
|
+
/** The tools record a session or launch id; only agents-cli's index can say which agent session that was. */
|
|
112
|
+
export function linkToolSessions(rows) {
|
|
113
|
+
return spanSync('feed.tools.link-sessions', () => linkToolSessionsNow(rows), () => ({ rows: rows.length }));
|
|
114
|
+
}
|
|
115
|
+
function linkToolSessionsNow(rows) {
|
|
116
|
+
let byLaunchId;
|
|
117
|
+
return rows.map((row) => {
|
|
118
|
+
let linked = row.sessionId ? getSessionById(row.sessionId) : null;
|
|
119
|
+
if (!linked && row.launchId) {
|
|
120
|
+
byLaunchId ??= buildLaunchSessionIndex();
|
|
121
|
+
const sessionId = byLaunchId.get(row.launchId);
|
|
122
|
+
linked = sessionId ? getSessionById(sessionId) : null;
|
|
123
|
+
}
|
|
124
|
+
return linked ? { ...row, linkedSession: linked } : row;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
export async function collectToolRows(scope, sources = {}) {
|
|
128
|
+
const incomplete = new Set();
|
|
129
|
+
let retry = false;
|
|
130
|
+
const read = async (kind, source, empty) => {
|
|
13
131
|
try {
|
|
14
|
-
return source();
|
|
132
|
+
return await source();
|
|
15
133
|
}
|
|
16
|
-
catch {
|
|
17
|
-
|
|
134
|
+
catch (error) {
|
|
135
|
+
incomplete.add(kind);
|
|
136
|
+
if (!(error instanceof ToolNotInstalledError))
|
|
137
|
+
retry = true;
|
|
18
138
|
return empty;
|
|
19
139
|
}
|
|
20
140
|
};
|
|
141
|
+
const [bindingList, liveTaskList, browserRows, computerRows] = await Promise.all([
|
|
142
|
+
read('browser', sources.bindings ?? (() => []), []),
|
|
143
|
+
read('browser', sources.liveTasks ?? (() => spanSync('feed.tools.live-tasks', () => readLiveBrowserTasks())), []),
|
|
144
|
+
read('browser', sources.browserRows ?? (async () => linkToolSessions(await readStandaloneBrowserRows())), []),
|
|
145
|
+
read('computer', sources.computerRows ?? (async () => linkToolSessions(await readStandaloneComputerRows())), []),
|
|
146
|
+
]);
|
|
21
147
|
const bindings = new Map();
|
|
22
|
-
for (const binding of
|
|
148
|
+
for (const binding of bindingList)
|
|
23
149
|
bindings.set(binding.name, binding);
|
|
24
150
|
const liveTasks = new Map();
|
|
25
|
-
for (const task of
|
|
151
|
+
for (const task of liveTaskList)
|
|
26
152
|
liveTasks.set(task.task, task);
|
|
27
153
|
const rows = [];
|
|
28
|
-
const browserRows = read(sources.browserRows ?? (() => readBrowserSessionRows()), []);
|
|
29
154
|
const captured = new Set();
|
|
30
155
|
for (const row of browserRows) {
|
|
31
156
|
if (row.task)
|
|
@@ -39,27 +164,27 @@ export function collectToolRows(scope, sources = {}) {
|
|
|
39
164
|
const live = liveTasks.get(task);
|
|
40
165
|
rows.push(projectBrowserToolRow(scope, boundBrowserRow(task, live ?? binding ?? {}), binding, live));
|
|
41
166
|
}
|
|
42
|
-
const computerRows = read(sources.computerRows ?? (() => buildComputerSessionRows({ limit: TOOL_COMPUTER_LIMIT, observer: scope })), []);
|
|
43
167
|
for (const row of computerRows)
|
|
44
168
|
rows.push(projectComputerToolRow(scope, row));
|
|
45
|
-
return { rows: sortToolRows(rows),
|
|
169
|
+
return { rows: sortToolRows(rows.filter((row) => !incomplete.has(row.kind))), incomplete: [...incomplete], retry };
|
|
46
170
|
}
|
|
47
171
|
export class ToolRowSet {
|
|
48
172
|
rows = new Map();
|
|
49
|
-
|
|
173
|
+
// A kind whose read failed keeps the rows it last published: a failed read is not "every task closed".
|
|
174
|
+
diff(next, unreadKinds = []) {
|
|
50
175
|
const upserts = [];
|
|
51
176
|
const seen = new Set();
|
|
52
177
|
for (const row of next) {
|
|
53
178
|
seen.add(row.rowKey);
|
|
54
179
|
const serialized = JSON.stringify(row);
|
|
55
|
-
if (this.rows.get(row.rowKey) === serialized)
|
|
180
|
+
if (this.rows.get(row.rowKey)?.serialized === serialized)
|
|
56
181
|
continue;
|
|
57
|
-
this.rows.set(row.rowKey, serialized);
|
|
182
|
+
this.rows.set(row.rowKey, { kind: row.kind, serialized });
|
|
58
183
|
upserts.push(row);
|
|
59
184
|
}
|
|
60
185
|
const removes = [];
|
|
61
|
-
for (const key of [...this.rows
|
|
62
|
-
if (seen.has(key))
|
|
186
|
+
for (const [key, { kind }] of [...this.rows]) {
|
|
187
|
+
if (seen.has(key) || unreadKinds.includes(kind))
|
|
63
188
|
continue;
|
|
64
189
|
this.rows.delete(key);
|
|
65
190
|
removes.push(key);
|
|
@@ -69,11 +194,13 @@ export class ToolRowSet {
|
|
|
69
194
|
reset(rows) {
|
|
70
195
|
this.rows.clear();
|
|
71
196
|
for (const row of rows)
|
|
72
|
-
this.rows.set(row.rowKey, JSON.stringify(row));
|
|
197
|
+
this.rows.set(row.rowKey, { kind: row.kind, serialized: JSON.stringify(row) });
|
|
73
198
|
}
|
|
74
199
|
}
|
|
75
|
-
|
|
76
|
-
|
|
200
|
+
// Only roots the tools append to while they act: their history databases are
|
|
201
|
+
// written by the very listings this watcher runs, so watching those would loop.
|
|
202
|
+
function toolWatchRoots() {
|
|
203
|
+
return [getBrowserRuntimeDir(), getEventsDir(), path.join(getCacheDir(), 'computer', 'actions')];
|
|
77
204
|
}
|
|
78
205
|
function readLiveTasksFor(profileDir) {
|
|
79
206
|
const file = path.join(profileDir, 'tasks.json');
|
|
@@ -171,24 +298,33 @@ export function watchToolActivity(options) {
|
|
|
171
298
|
for (const root of roots)
|
|
172
299
|
armRoot(root);
|
|
173
300
|
const armed = () => [...watchers.values()].every((watcher) => watcher !== undefined);
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
301
|
+
let projecting = false;
|
|
302
|
+
const reproject = async () => {
|
|
303
|
+
projecting = true;
|
|
304
|
+
try {
|
|
305
|
+
const snapshot = await span('feed.tools.collect', () => collectToolRows(options.scope, options.sources));
|
|
306
|
+
if (stopped)
|
|
307
|
+
return;
|
|
308
|
+
if (snapshot.retry)
|
|
309
|
+
dirty = true;
|
|
310
|
+
const diff = spanSync('feed.tools.diff', () => set.diff(snapshot.rows, snapshot.incomplete), () => ({ rows: snapshot.rows.length }));
|
|
311
|
+
if (diff.upserts.length > 0 || diff.removes.length > 0)
|
|
312
|
+
options.onDiff(diff);
|
|
313
|
+
}
|
|
314
|
+
finally {
|
|
315
|
+
projecting = false;
|
|
179
316
|
}
|
|
180
|
-
const diff = set.diff(snapshot.rows);
|
|
181
|
-
if (diff.upserts.length > 0 || diff.removes.length > 0)
|
|
182
|
-
options.onDiff(diff);
|
|
183
317
|
};
|
|
184
318
|
const timer = setInterval(() => {
|
|
185
319
|
for (const root of roots)
|
|
186
320
|
armRoot(root);
|
|
187
|
-
if (armed() && !dirty)
|
|
321
|
+
if (projecting || (armed() && !dirty))
|
|
188
322
|
return;
|
|
189
323
|
dirty = false;
|
|
190
|
-
reproject();
|
|
324
|
+
void reproject();
|
|
191
325
|
}, options.sweepMs ?? TOOL_SWEEP_MS);
|
|
326
|
+
if (!options.initial)
|
|
327
|
+
void reproject();
|
|
192
328
|
const stop = () => {
|
|
193
329
|
stopped = true;
|
|
194
330
|
clearInterval(timer);
|
package/dist/lib/feed/tools.d.ts
CHANGED
|
@@ -1,5 +1,58 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { SessionMeta } from '@phnx-labs/sessions-cli/reader';
|
|
2
|
+
export type ArtifactKind = 'screenshot' | 'pdf' | 'recording' | 'download';
|
|
3
|
+
export interface BrowserArtifact {
|
|
4
|
+
kind: ArtifactKind;
|
|
5
|
+
task?: string;
|
|
6
|
+
name: string;
|
|
7
|
+
path: string;
|
|
8
|
+
bytes: number;
|
|
9
|
+
mtimeMs: number;
|
|
10
|
+
}
|
|
11
|
+
export interface BrowserSessionRow {
|
|
12
|
+
kind: 'task' | 'downloads';
|
|
13
|
+
profile: string;
|
|
14
|
+
task?: string;
|
|
15
|
+
launchId?: string;
|
|
16
|
+
sessionId?: string;
|
|
17
|
+
linkedSession?: SessionMeta;
|
|
18
|
+
artifacts: BrowserArtifact[];
|
|
19
|
+
counts: Record<ArtifactKind, number>;
|
|
20
|
+
latestMtimeMs: number;
|
|
21
|
+
startedAt?: number;
|
|
22
|
+
machine?: string;
|
|
23
|
+
captureDir?: string;
|
|
24
|
+
capturesRemote?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ComputerAction {
|
|
27
|
+
verb: string;
|
|
28
|
+
tsMs: number;
|
|
29
|
+
host?: string;
|
|
30
|
+
bundle?: string;
|
|
31
|
+
capture?: {
|
|
32
|
+
kind: 'screenshot';
|
|
33
|
+
path: string;
|
|
34
|
+
name: string;
|
|
35
|
+
bytes?: number;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export interface ComputerRunRow {
|
|
39
|
+
pid?: number;
|
|
40
|
+
invocationId?: string;
|
|
41
|
+
task?: string;
|
|
42
|
+
machine: string;
|
|
43
|
+
remoteHost?: string;
|
|
44
|
+
bundle?: string;
|
|
45
|
+
sessionId?: string;
|
|
46
|
+
launchId?: string;
|
|
47
|
+
linkedSession?: SessionMeta;
|
|
48
|
+
actions: ComputerAction[];
|
|
49
|
+
counts: Record<string, number>;
|
|
50
|
+
recoveredActionCount?: number;
|
|
51
|
+
captures?: ComputerAction[];
|
|
52
|
+
captureCount?: number;
|
|
53
|
+
startMs: number;
|
|
54
|
+
endMs: number;
|
|
55
|
+
}
|
|
3
56
|
export declare const TOOL_CAPTURE_LIMIT = 20;
|
|
4
57
|
export declare const TOOL_ACTION_LIMIT = 50;
|
|
5
58
|
export type ToolKind = 'browser' | 'computer';
|
package/dist/lib/feed/tools.js
CHANGED
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
* projected into one row contract, alongside the agent and attention rows.
|
|
4
4
|
*
|
|
5
5
|
* WHY A PROJECTION AND NOT A NEW STORE. Both sources already exist and already
|
|
6
|
-
* have an owner: `
|
|
7
|
-
* task-first rows
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* tool
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
6
|
+
* have an owner: the standalone `browser sessions --tasks --json` groups a
|
|
7
|
+
* profile's captures into task-first rows, and the standalone
|
|
8
|
+
* `computer sessions --json` groups its action ledger into run rows. A menu-bar
|
|
9
|
+
* or Fleet view that wanted the same information had only one way to get it:
|
|
10
|
+
* shell out to those two commands, per tool, per device, on a timer. That is the
|
|
11
|
+
* per-tool polling this module removes — the rows ride the ONE stream
|
|
12
|
+
* `agents feed watch --json` already holds open, so a consumer switching its
|
|
13
|
+
* All/Agents/Browser/Computer filter spawns zero commands. {@link BrowserSessionRow}
|
|
14
|
+
* and {@link ComputerRunRow} are those commands' JSON rows, plus the agent session
|
|
15
|
+
* agents-cli resolved for them from its own index.
|
|
15
16
|
*
|
|
16
17
|
* WHAT IS DELIBERATELY DIFFERENT BETWEEN THE TWO KINDS. A browser task is a
|
|
17
18
|
* LIVE resource: it is bound in the task index while it exists, it can be
|
|
@@ -70,12 +71,12 @@ function ownerOf(sessionId, linkedSession, scope) {
|
|
|
70
71
|
};
|
|
71
72
|
}
|
|
72
73
|
function knownMachine(machine) {
|
|
73
|
-
return machine
|
|
74
|
+
return machine !== 'local' ? machine : undefined;
|
|
74
75
|
}
|
|
75
76
|
export function boundBrowserRow(task, binding) {
|
|
76
77
|
return {
|
|
77
78
|
kind: 'task', task, profile: binding.profile ?? '',
|
|
78
|
-
|
|
79
|
+
artifacts: [],
|
|
79
80
|
counts: { screenshot: 0, pdf: 0, recording: 0, download: 0 },
|
|
80
81
|
latestMtimeMs: 0,
|
|
81
82
|
};
|
|
@@ -125,22 +126,15 @@ export function projectBrowserToolRow(scope, row, binding, live) {
|
|
|
125
126
|
export function projectComputerToolRow(scope, row) {
|
|
126
127
|
const host = normalizeHost(scope);
|
|
127
128
|
const owner = ownerOf(row.sessionId, row.linkedSession, host);
|
|
128
|
-
const agent = row.
|
|
129
|
-
const
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
captures.push({
|
|
138
|
-
kind: action.capture.kind, name: action.capture.name, path: action.capture.path,
|
|
139
|
-
host,
|
|
140
|
-
...(action.capture.bytes !== undefined ? { bytes: action.capture.bytes } : {}),
|
|
141
|
-
atMs: action.tsMs,
|
|
142
|
-
});
|
|
143
|
-
}
|
|
129
|
+
const agent = row.linkedSession?.agent;
|
|
130
|
+
const captured = (row.captures ?? row.actions).flatMap((action) => action.capture ? [{ ...action.capture, atMs: action.tsMs }] : []);
|
|
131
|
+
const captures = captured.slice(0, TOOL_CAPTURE_LIMIT).map((capture) => ({
|
|
132
|
+
kind: capture.kind, name: capture.name, path: capture.path, host,
|
|
133
|
+
...(capture.bytes !== undefined ? { bytes: capture.bytes } : {}),
|
|
134
|
+
atMs: capture.atMs,
|
|
135
|
+
}));
|
|
136
|
+
const captureTotal = row.captureCount ?? captured.length;
|
|
137
|
+
const captureCounts = captureTotal > 0 ? { screenshot: captureTotal } : {};
|
|
144
138
|
const actions = row.actions.slice(0, TOOL_ACTION_LIMIT).map((action) => ({
|
|
145
139
|
verb: action.verb, atMs: action.tsMs,
|
|
146
140
|
...(action.host ? { host: action.host } : {}),
|
|
@@ -157,7 +151,7 @@ export function projectComputerToolRow(scope, row) {
|
|
|
157
151
|
...(row.launchId ? { launchId: row.launchId } : {}),
|
|
158
152
|
...(agent ? { agent } : {}),
|
|
159
153
|
...(owner ? { owner } : {}),
|
|
160
|
-
linkStatus: row.
|
|
154
|
+
linkStatus: row.linkedSession ? 'linked' : (row.sessionId || row.launchId) ? 'unresolved' : 'unlinked',
|
|
161
155
|
startedAtMs: row.startMs,
|
|
162
156
|
updatedAtMs: row.endMs,
|
|
163
157
|
captures,
|
package/dist/lib/feed/watch.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SessionProjection } from '../session/projection.js';
|
|
2
|
+
import { span, spanSync } from '../daemon/diagnostics.js';
|
|
2
3
|
import * as fs from 'node:fs';
|
|
3
4
|
import * as path from 'node:path';
|
|
4
5
|
import { loadDevices, isDialableDevice } from '../devices/registry.js';
|
|
@@ -11,7 +12,7 @@ import { watchLocalSessions } from '../session/watch.js';
|
|
|
11
12
|
import { readBlock, readResolution, blockIdForSession } from './feed.js';
|
|
12
13
|
import { reconcileAttention } from './attention.js';
|
|
13
14
|
import { ActivityStream } from './activity-stream.js';
|
|
14
|
-
import {
|
|
15
|
+
import { watchToolActivity } from './tool-activity.js';
|
|
15
16
|
import { FeedWatchState } from './envelope.js';
|
|
16
17
|
import { FeedHub } from './hub.js';
|
|
17
18
|
import { getCachedToolSetup, subscribeToolSetup } from '../setup-tool-status.js';
|
|
@@ -182,7 +183,8 @@ export async function watchLocalFeed(options) {
|
|
|
182
183
|
const state = new FeedWatchState();
|
|
183
184
|
const activity = new ActivityStream();
|
|
184
185
|
let activityCursor = Date.now();
|
|
185
|
-
|
|
186
|
+
// The tool listings spawn processes; the first projection runs on the tool watcher so it never delays sessions or attention.
|
|
187
|
+
let toolRows = [];
|
|
186
188
|
const readSetup = options.setup?.read ?? getCachedToolSetup;
|
|
187
189
|
let setupRows = (() => {
|
|
188
190
|
try {
|
|
@@ -221,7 +223,7 @@ export async function watchLocalFeed(options) {
|
|
|
221
223
|
const activityTimer = setInterval(() => {
|
|
222
224
|
pending = pending.then(async () => {
|
|
223
225
|
const nowMs = Date.now();
|
|
224
|
-
const events = activity.read(activityCursor + 1, nowMs).reverse();
|
|
226
|
+
const events = spanSync('feed.activity.read', () => activity.read(activityCursor + 1, nowMs).reverse());
|
|
225
227
|
for (const event of events) {
|
|
226
228
|
activityCursor = Math.max(activityCursor, Date.parse(event.ts));
|
|
227
229
|
options.emit(state.emit({ type: 'activity.append', scope: options.scope, event }));
|
|
@@ -230,11 +232,11 @@ export async function watchLocalFeed(options) {
|
|
|
230
232
|
return;
|
|
231
233
|
attentionDirty = false;
|
|
232
234
|
lastReconcileMs = nowMs;
|
|
233
|
-
await reconcileRows();
|
|
235
|
+
await span('feed.attention.reconcile', reconcileRows, () => ({ rows: agents.size }));
|
|
234
236
|
});
|
|
235
237
|
}, options.activityPollMs ?? 500);
|
|
236
238
|
const toolWatch = watchToolActivity({
|
|
237
|
-
...options.tools, scope: options.scope, signal: options.signal,
|
|
239
|
+
...options.tools, scope: options.scope, signal: options.signal,
|
|
238
240
|
onDiff: (diff) => {
|
|
239
241
|
for (const tool of diff.upserts) {
|
|
240
242
|
toolRows = [...toolRows.filter((row) => row.rowKey !== tool.rowKey), tool];
|
|
@@ -269,7 +271,7 @@ export async function watchLocalFeed(options) {
|
|
|
269
271
|
attention.delete(event.rowKey);
|
|
270
272
|
prStatus.delete(event.rowKey);
|
|
271
273
|
}
|
|
272
|
-
pending = pending.then(() => projectSessionEnvelope(event, state, options.gh, toolRows, setupRows)).then((events) => {
|
|
274
|
+
pending = pending.then(() => span('feed.sessions.project', () => projectSessionEnvelope(event, state, options.gh, toolRows, setupRows), () => ({ type: event.type }))).then((events) => {
|
|
273
275
|
for (const projected of events) {
|
|
274
276
|
if (projected.type === 'reset') {
|
|
275
277
|
attention.clear();
|
|
@@ -344,8 +346,10 @@ export async function watchFleetFeed(options) {
|
|
|
344
346
|
const coordinator = new FeedWatchState();
|
|
345
347
|
const projection = new FeedSessionProjection(coordinator);
|
|
346
348
|
const forward = (event) => {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
+
spanSync('feed.fleet.apply', () => {
|
|
350
|
+
for (const projected of projection.apply(event))
|
|
351
|
+
options.emit(projected);
|
|
352
|
+
}, () => ({ type: event.type, scope: 'scope' in event ? event.scope : undefined }));
|
|
349
353
|
};
|
|
350
354
|
const local = subscribeSharedLocalFeed({ signal: options.signal, emit: forward });
|
|
351
355
|
let devices;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type GhExec } from './pr-mergeable.js';
|
|
2
|
+
import { type ProjectPr, type RepoMergeAbility } from './project-prs.js';
|
|
3
|
+
import type { ProjectDef } from '../projects.js';
|
|
4
|
+
export type NeedsMe = 'review' | 'failing' | 'conflicts';
|
|
5
|
+
export interface OpenPr extends ProjectPr {
|
|
6
|
+
reviewRequested: boolean;
|
|
7
|
+
needsMe: NeedsMe | null;
|
|
8
|
+
}
|
|
9
|
+
export interface OpenPrRepo {
|
|
10
|
+
slug: string;
|
|
11
|
+
projects: string[];
|
|
12
|
+
merge: RepoMergeAbility | null;
|
|
13
|
+
pullRequests: OpenPr[];
|
|
14
|
+
ciError: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface OpenPrOwner {
|
|
17
|
+
login: string;
|
|
18
|
+
open: number;
|
|
19
|
+
truncated: boolean;
|
|
20
|
+
error: string | null;
|
|
21
|
+
}
|
|
22
|
+
export interface OpenPrsEnvelope {
|
|
23
|
+
viewer: string | null;
|
|
24
|
+
owners: OpenPrOwner[];
|
|
25
|
+
reviewRequestedError: string | null;
|
|
26
|
+
repositories: OpenPrRepo[];
|
|
27
|
+
partial: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface OpenPrsOptions {
|
|
30
|
+
owners?: string[];
|
|
31
|
+
repo?: string;
|
|
32
|
+
number?: number;
|
|
33
|
+
cacheDir?: string;
|
|
34
|
+
nowMs?: number;
|
|
35
|
+
}
|
|
36
|
+
export declare const SEARCH_RESULT_CAP = 1000;
|
|
37
|
+
export declare function listViewerOwners(viewer: string | null, gh?: GhExec): Promise<string[]>;
|
|
38
|
+
export declare function needsMeFor(pr: ProjectPr, viewer: string | null, reviewRequested: boolean): NeedsMe | null;
|
|
39
|
+
export declare function compareOpenPrs(a: OpenPr, b: OpenPr): number;
|
|
40
|
+
export declare const OWNER_LOGIN: RegExp;
|
|
41
|
+
export declare function buildOpenPrs(defs: readonly ProjectDef[], opts?: OpenPrsOptions, gh?: GhExec): Promise<OpenPrsEnvelope>;
|