@phnx-labs/agents-cli 1.22.127 → 1.23.0

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.
Files changed (77) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +13 -16
  3. package/dist/bootstrap.js +4 -3
  4. package/dist/commands/browser.js +4 -19
  5. package/dist/commands/computer.d.ts +2 -6
  6. package/dist/commands/computer.js +12 -18
  7. package/dist/commands/logs.js +2 -6
  8. package/dist/commands/menubar.js +28 -1
  9. package/dist/commands/projects.js +103 -40
  10. package/dist/commands/sessions.d.ts +0 -11
  11. package/dist/commands/sessions.js +31 -364
  12. package/dist/index.js +10 -11
  13. package/dist/lib/browser-client.d.ts +0 -21
  14. package/dist/lib/browser-client.js +1 -44
  15. package/dist/lib/computer/record.d.ts +1 -0
  16. package/dist/lib/computer/record.js +2 -16
  17. package/dist/lib/config-keys.d.ts +2 -2
  18. package/dist/lib/config-keys.js +8 -2
  19. package/dist/lib/daemon/daemon.js +1 -8
  20. package/dist/lib/daemon/runner.js +3 -2
  21. package/dist/lib/daemon-services.d.ts +1 -1
  22. package/dist/lib/daemon-services.js +0 -5
  23. package/dist/lib/device-config.d.ts +1 -1
  24. package/dist/lib/device-config.js +48 -7
  25. package/dist/lib/feed/tool-activity.d.ts +22 -10
  26. package/dist/lib/feed/tool-activity.js +161 -32
  27. package/dist/lib/feed/tools.d.ts +55 -2
  28. package/dist/lib/feed/tools.js +22 -28
  29. package/dist/lib/feed/watch.js +4 -3
  30. package/dist/lib/github/open-prs.d.ts +41 -0
  31. package/dist/lib/github/open-prs.js +157 -0
  32. package/dist/lib/github/project-prs.d.ts +20 -1
  33. package/dist/lib/github/project-prs.js +8 -7
  34. package/dist/lib/helper-versions.js +1 -1
  35. package/dist/lib/menubar/install-menubar.d.ts +5 -7
  36. package/dist/lib/menubar/install-menubar.js +120 -29
  37. package/dist/lib/menubar/resolve-version.d.ts +1 -0
  38. package/dist/lib/menubar/resolve-version.js +4 -2
  39. package/dist/lib/menubar/snapshot.d.ts +2 -0
  40. package/dist/lib/menubar/snapshot.js +2 -0
  41. package/dist/lib/menubar/update-state.d.ts +15 -0
  42. package/dist/lib/menubar/update-state.js +36 -0
  43. package/dist/lib/owner-notify.d.ts +0 -12
  44. package/dist/lib/owner-notify.js +1 -10
  45. package/dist/lib/self-heal/checks/menubar-helper.js +1 -0
  46. package/dist/lib/session/cloud.d.ts +0 -1
  47. package/dist/lib/session/cloud.js +0 -5
  48. package/dist/lib/session/db.d.ts +0 -64
  49. package/dist/lib/session/db.js +0 -116
  50. package/dist/lib/session/remote/remote-list.d.ts +2 -36
  51. package/dist/lib/session/remote/remote-list.js +3 -320
  52. package/dist/lib/session/tool-index.d.ts +0 -62
  53. package/dist/lib/session/tool-index.js +1 -537
  54. package/dist/lib/sessions-client.d.ts +1 -0
  55. package/dist/lib/sessions-client.js +17 -1
  56. package/dist/lib/standalone-tools.js +2 -2
  57. package/dist/lib/testdata/owner-notify-api.d.ts +0 -13
  58. package/dist/lib/testdata/owner-notify-api.js +3 -23
  59. package/package.json +1 -1
  60. package/dist/commands/browser-sessions-picker.d.ts +0 -9
  61. package/dist/commands/browser-sessions-picker.js +0 -136
  62. package/dist/commands/computer-sessions-picker.d.ts +0 -11
  63. package/dist/commands/computer-sessions-picker.js +0 -90
  64. package/dist/commands/sessions-tail.d.ts +0 -13
  65. package/dist/commands/sessions-tail.js +0 -222
  66. package/dist/lib/browser/native-history.test-fixture.d.ts +0 -12
  67. package/dist/lib/browser/native-history.test-fixture.js +0 -43
  68. package/dist/lib/browser/paths.d.ts +0 -9
  69. package/dist/lib/browser/paths.js +0 -31
  70. package/dist/lib/browser/record.d.ts +0 -4
  71. package/dist/lib/browser/record.js +0 -19
  72. package/dist/lib/browser/sessions-list.d.ts +0 -79
  73. package/dist/lib/browser/sessions-list.js +0 -415
  74. package/dist/lib/computer/sessions-list.d.ts +0 -78
  75. package/dist/lib/computer/sessions-list.js +0 -372
  76. package/dist/lib/daemon/owner-device-delivery-service.d.ts +0 -10
  77. package/dist/lib/daemon/owner-device-delivery-service.js +0 -28
@@ -1,9 +0,0 @@
1
- interface BrowserSessionsCommandOpts {
2
- profile?: string;
3
- open?: string | boolean;
4
- json?: boolean;
5
- interactive?: boolean;
6
- }
7
- export declare function shouldOpenInteractiveBrowserSessions(opts: BrowserSessionsCommandOpts, isTTY: boolean): boolean;
8
- export declare function runBrowserSessionsCommand(opts: BrowserSessionsCommandOpts): Promise<void>;
9
- export {};
@@ -1,136 +0,0 @@
1
- import { showFile } from '../lib/open-url.js';
2
- import chalk from 'chalk';
3
- import { itemPicker } from '../lib/picker.js';
4
- import { isPromptCancelled } from './utils.js';
5
- import { buildPreview } from './sessions-picker.js';
6
- import { createSessionsPickerCommand } from './sessions-picker-factory.js';
7
- import { runBrowserSessions, buildBrowserSessionRows, matchesBrowserSessionRow, formatBytes, } from '../lib/browser/sessions-list.js';
8
- import { formatRelativeTime } from '../lib/session/relative-time.js';
9
- import { sessionHeadline } from '../lib/session/title.js';
10
- const KIND_LABEL = {
11
- screenshot: 'shots',
12
- pdf: 'pdf',
13
- recording: 'rec',
14
- download: 'dl',
15
- };
16
- function formatCounts(counts) {
17
- const parts = [];
18
- for (const kind of Object.keys(KIND_LABEL)) {
19
- if (counts[kind] > 0)
20
- parts.push(`${KIND_LABEL[kind]} ${counts[kind]}`);
21
- }
22
- return parts.join(' · ') || '-';
23
- }
24
- function rowLinkSummary(row) {
25
- if (row.kind === 'downloads')
26
- return '';
27
- if (row.linkStatus === 'linked' && row.linkedSession) {
28
- const s = row.linkedSession;
29
- return chalk.cyan(s.agent) + ' — ' + (sessionHeadline(s) || s.shortId);
30
- }
31
- if (row.linkStatus === 'unresolved') {
32
- return chalk.yellow(`owner ${row.owner ?? 'unknown'} (session not indexed here)`);
33
- }
34
- return chalk.gray('unlinked');
35
- }
36
- function formatRowLabel(row) {
37
- const name = (row.kind === 'downloads' ? '[downloads]' : (row.task ?? '')).padEnd(30);
38
- const coloredName = row.kind === 'downloads' ? chalk.gray(name) : name;
39
- const age = formatRelativeTime(new Date(row.latestMtimeMs).toISOString());
40
- const counts = formatCounts(row.counts);
41
- return [
42
- coloredName,
43
- row.profile.padEnd(26),
44
- age.padEnd(11),
45
- counts.padEnd(18),
46
- rowLinkSummary(row),
47
- ].join(' ');
48
- }
49
- const PREVIEW_ARTIFACT_LIMIT = 12;
50
- function buildRowPreview(row) {
51
- const parts = [];
52
- if (row.kind === 'downloads') {
53
- parts.push(chalk.bold(`${row.profile} — downloads`));
54
- }
55
- else if (row.linkStatus === 'linked' && row.linkedSession) {
56
- parts.push(buildPreview(row.linkedSession));
57
- }
58
- else if (row.linkStatus === 'unresolved') {
59
- parts.push(chalk.yellow(`owner ${row.owner ?? 'unknown'} — launch ${row.launchId} has no indexed session on this machine.`));
60
- }
61
- else {
62
- parts.push(chalk.gray(`Unlinked — no owning agent session is known for this task`
63
- + (row.owner ? ` (last known owner: ${row.owner}).` : '.')));
64
- }
65
- parts.push('');
66
- parts.push(chalk.bold(`Captures (${row.artifacts.length})`));
67
- for (const a of row.artifacts.slice(0, PREVIEW_ARTIFACT_LIMIT)) {
68
- const age = formatRelativeTime(new Date(a.mtimeMs).toISOString());
69
- parts.push(` ${age.padEnd(11)} ${a.name.padEnd(30)} ${formatBytes(a.bytes).padStart(8)}`);
70
- }
71
- const more = row.artifacts.length - PREVIEW_ARTIFACT_LIMIT;
72
- if (more > 0)
73
- parts.push(chalk.gray(` … (${more} more)`));
74
- return parts.join('\n');
75
- }
76
- function formatArtifactLabel(a) {
77
- const age = formatRelativeTime(new Date(a.mtimeMs).toISOString());
78
- return `${age.padEnd(11)} ${a.name.padEnd(34)} ${formatBytes(a.bytes).padStart(8)}`;
79
- }
80
- async function openAndReport(a) {
81
- console.log(a.path);
82
- if ((await showFile(a.path)).via === 'none')
83
- console.error(`Could not open ${a.path}`);
84
- }
85
- async function pickArtifact(row) {
86
- try {
87
- const picked = await itemPicker({
88
- message: `Captures — ${row.task ?? 'downloads'} (${row.profile}):`,
89
- items: row.artifacts,
90
- filter: (query) => {
91
- const q = query.trim().toLowerCase();
92
- return q ? row.artifacts.filter((a) => a.name.toLowerCase().includes(q)) : row.artifacts;
93
- },
94
- labelFor: (a) => formatArtifactLabel(a),
95
- emptyMessage: 'No captures.',
96
- enterHint: 'open',
97
- });
98
- return picked?.item ?? null;
99
- }
100
- catch (err) {
101
- if (isPromptCancelled(err))
102
- return null;
103
- throw err;
104
- }
105
- }
106
- const browserSessionsPicker = createSessionsPickerCommand({
107
- requireOpenUndefined: true,
108
- runFlat: (opts) => runBrowserSessions({ profile: opts.profile, open: opts.open, json: opts.json }),
109
- buildRows: (opts) => buildBrowserSessionRows(opts.profile),
110
- emptyMessage: (opts) => `No browser captures found${opts.profile ? ` for profile "${opts.profile}"` : ''}.`,
111
- message: 'Browser sessions:',
112
- matches: matchesBrowserSessionRow,
113
- labelFor: formatRowLabel,
114
- buildPreview: buildRowPreview,
115
- emptyFilterMessage: 'No browser sessions match.',
116
- enterHint: 'open capture',
117
- onOpen: async (row) => {
118
- if (row.artifacts.length === 0) {
119
- console.log('No captures in this task yet.');
120
- return;
121
- }
122
- if (row.artifacts.length === 1) {
123
- await openAndReport(row.artifacts[0]);
124
- return;
125
- }
126
- const artifact = await pickArtifact(row);
127
- if (artifact)
128
- await openAndReport(artifact);
129
- },
130
- });
131
- export function shouldOpenInteractiveBrowserSessions(opts, isTTY) {
132
- return browserSessionsPicker.shouldOpen(opts, isTTY);
133
- }
134
- export async function runBrowserSessionsCommand(opts) {
135
- await browserSessionsPicker.run(opts);
136
- }
@@ -1,11 +0,0 @@
1
- import { type ComputerRunRow } from '../lib/computer/sessions-list.js';
2
- interface ComputerSessionsCommandOpts {
3
- machine?: string;
4
- limit?: number;
5
- json?: boolean;
6
- interactive?: boolean;
7
- rows?: ComputerRunRow[];
8
- }
9
- export declare function shouldOpenInteractiveComputerSessions(opts: ComputerSessionsCommandOpts, isTTY: boolean): boolean;
10
- export declare function runComputerSessionsCommand(opts: ComputerSessionsCommandOpts): Promise<void>;
11
- export {};
@@ -1,90 +0,0 @@
1
- import chalk from 'chalk';
2
- import { buildPreview } from './sessions-picker.js';
3
- import { createSessionsPickerCommand } from './sessions-picker-factory.js';
4
- import { runComputerSessions, printComputerSessionRows, buildComputerSessionRows, matchesComputerSessionRow, formatRowActions, } from '../lib/computer/sessions-list.js';
5
- import { formatRelativeTime } from '../lib/session/relative-time.js';
6
- import { sessionHeadline } from '../lib/session/title.js';
7
- function rowLinkSummary(row) {
8
- if (row.linkStatus === 'linked' && row.linkedSession) {
9
- const s = row.linkedSession;
10
- return chalk.cyan(s.agent) + ' — ' + (sessionHeadline(s) || s.shortId);
11
- }
12
- if (row.linkStatus === 'unresolved') {
13
- return chalk.yellow(`owner ${row.agent ?? 'unknown'} (session not indexed here)`);
14
- }
15
- return chalk.gray('unlinked');
16
- }
17
- function formatRowLabel(row) {
18
- const rawName = row.task ?? row.bundle ?? (row.pid ? `pid ${row.pid}` : 'recovered run');
19
- const name = rawName.slice(0, 40).padEnd(40);
20
- const coloredName = row.task ? name : chalk.gray(name);
21
- const where = (row.remoteHost ? `${row.machine} -> ${row.remoteHost}` : row.machine).padEnd(24);
22
- const age = formatRelativeTime(new Date(row.endMs).toISOString());
23
- const counts = formatRowActions(row);
24
- return [coloredName, where, age.padEnd(11), counts.padEnd(24), rowLinkSummary(row)].join(' ');
25
- }
26
- const PREVIEW_ACTION_LIMIT = 12;
27
- function buildRowPreview(row) {
28
- const parts = [];
29
- if (row.linkStatus === 'linked' && row.linkedSession) {
30
- parts.push(buildPreview(row.linkedSession));
31
- }
32
- else if (row.linkStatus === 'unresolved') {
33
- parts.push(chalk.yellow(`owner ${row.agent ?? 'unknown'} — session ${row.sessionId ?? row.launchId} has no indexed session on this machine.`));
34
- }
35
- else {
36
- parts.push(chalk.gray('Unlinked — no owning agent session is known for this run (no session/launch identity recorded).'));
37
- }
38
- if (row.task) {
39
- parts.push('');
40
- parts.push(chalk.bold('Task:') + ` ${row.task}`);
41
- }
42
- parts.push('');
43
- parts.push(chalk.bold(`Actions (${row.recoveredActionCount ?? row.actions.length})`) + ` ${formatRowActions(row)}`);
44
- for (const a of row.actions.slice(0, PREVIEW_ACTION_LIMIT)) {
45
- parts.push(` ${formatActionLabel(a)}`);
46
- }
47
- const more = row.actions.length - PREVIEW_ACTION_LIMIT;
48
- if (more > 0)
49
- parts.push(chalk.gray(` … (${more} more)`));
50
- return parts.join('\n');
51
- }
52
- function formatActionLabel(a) {
53
- const age = formatRelativeTime(new Date(a.tsMs).toISOString());
54
- const target = a.bundle ?? (a.targetPid != null ? `pid ${a.targetPid}` : '-');
55
- return `${age.padEnd(11)} ${a.verb.padEnd(14)} ${target}`;
56
- }
57
- function printRunDetail(row) {
58
- console.log('');
59
- console.log(chalk.bold(row.task ?? row.bundle ?? `pid ${row.pid}`));
60
- console.log(row.remoteHost ? `${row.machine} -> ${row.remoteHost}` : row.machine);
61
- console.log('');
62
- for (const a of row.actions)
63
- console.log(formatActionLabel(a));
64
- if (row.actions.length === 0)
65
- console.log('(no driving actions recorded)');
66
- console.log('');
67
- }
68
- const computerSessionsPicker = createSessionsPickerCommand({
69
- runFlat: (opts) => {
70
- if (opts.rows)
71
- printComputerSessionRows(opts.rows, { limit: opts.limit, json: opts.json });
72
- else
73
- runComputerSessions({ machine: opts.machine, limit: opts.limit, json: opts.json });
74
- },
75
- buildRows: (opts) => opts.rows ?? buildComputerSessionRows({ machine: opts.machine }),
76
- emptyMessage: (opts) => `No computer actions recorded${opts.machine ? ` for machine "${opts.machine}"` : ''}.`,
77
- message: 'Computer sessions:',
78
- matches: matchesComputerSessionRow,
79
- labelFor: formatRowLabel,
80
- buildPreview: buildRowPreview,
81
- emptyFilterMessage: 'No computer sessions match.',
82
- enterHint: 'view actions',
83
- onOpen: printRunDetail,
84
- });
85
- export function shouldOpenInteractiveComputerSessions(opts, isTTY) {
86
- return computerSessionsPicker.shouldOpen(opts, isTTY);
87
- }
88
- export async function runComputerSessionsCommand(opts) {
89
- await computerSessionsPicker.run(opts);
90
- }
@@ -1,13 +0,0 @@
1
- import type { Command } from 'commander';
2
- import type { SessionMeta, SessionAgentId } from '@phnx-labs/sessions-cli/reader';
3
- export declare function isTailable(agent: SessionAgentId): boolean;
4
- interface TailFileOptions {
5
- fromStart?: boolean;
6
- }
7
- export declare function tailFile(filePath: string, onLine: (line: string) => void, ac: AbortController, opts?: TailFileOptions): Promise<void>;
8
- export declare function streamSessionTail(session: SessionMeta, options?: {
9
- fromStart?: boolean;
10
- raw?: boolean;
11
- }): Promise<void>;
12
- export declare function registerSessionsTailCommand(sessionsCmd: Command): void;
13
- export {};
@@ -1,222 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as fsp from 'fs/promises';
3
- import * as path from 'path';
4
- import chalk from 'chalk';
5
- import { discoverSessions, resolveSessionById } from '../lib/session/discover.js';
6
- import { setHelpSections } from '../lib/help.js';
7
- import { makeStreamRenderer } from '@phnx-labs/sessions-cli/reader';
8
- const TAIL_SUPPORTED = ['claude', 'codex'];
9
- export function isTailable(agent) {
10
- return TAIL_SUPPORTED.includes(agent);
11
- }
12
- export async function tailFile(filePath, onLine, ac, opts = {}) {
13
- const dir = path.dirname(filePath);
14
- const base = path.basename(filePath);
15
- let fd = null;
16
- let offset = 0;
17
- let partial = '';
18
- let reading = false;
19
- let dirty = false;
20
- const openIfPossible = async (initial) => {
21
- try {
22
- fd = await fsp.open(filePath, 'r');
23
- }
24
- catch {
25
- return false;
26
- }
27
- if (initial) {
28
- const st = await fd.stat();
29
- offset = opts.fromStart ? 0 : st.size;
30
- }
31
- else {
32
- offset = 0;
33
- partial = '';
34
- }
35
- return true;
36
- };
37
- const closeFd = async () => {
38
- const h = fd;
39
- fd = null;
40
- if (h) {
41
- try {
42
- await h.close();
43
- }
44
- catch { }
45
- }
46
- };
47
- const drain = async () => {
48
- if (reading) {
49
- dirty = true;
50
- return;
51
- }
52
- reading = true;
53
- try {
54
- while (!ac.signal.aborted) {
55
- if (!fd) {
56
- const ok = await openIfPossible(false);
57
- if (!ok)
58
- return;
59
- }
60
- const st = await fd.stat();
61
- if (st.size < offset) {
62
- offset = 0;
63
- partial = '';
64
- }
65
- if (st.size === offset) {
66
- if (dirty) {
67
- dirty = false;
68
- continue;
69
- }
70
- return;
71
- }
72
- const len = st.size - offset;
73
- const buf = Buffer.alloc(len);
74
- await fd.read(buf, 0, len, offset);
75
- offset = st.size;
76
- const text = partial + buf.toString('utf-8');
77
- const lines = text.split('\n');
78
- partial = lines.pop() ?? '';
79
- for (const line of lines) {
80
- if (ac.signal.aborted)
81
- return;
82
- if (line.length > 0)
83
- onLine(line);
84
- }
85
- if (!dirty)
86
- return;
87
- dirty = false;
88
- }
89
- }
90
- finally {
91
- reading = false;
92
- }
93
- };
94
- if (fs.existsSync(filePath)) {
95
- await openIfPossible(true);
96
- }
97
- const watcher = fs.watch(dir, { recursive: false }, (_event, filename) => {
98
- if (ac.signal.aborted)
99
- return;
100
- if (filename !== null && filename !== base)
101
- return;
102
- void drain();
103
- });
104
- await drain();
105
- await new Promise((resolve) => {
106
- const onAbort = () => {
107
- ac.signal.removeEventListener('abort', onAbort);
108
- try {
109
- watcher.close();
110
- }
111
- catch { }
112
- void closeFd().then(() => resolve());
113
- };
114
- if (ac.signal.aborted)
115
- onAbort();
116
- else
117
- ac.signal.addEventListener('abort', onAbort);
118
- });
119
- }
120
- async function findLatestTailable() {
121
- const sessions = await discoverSessions({ all: true, limit: 100 });
122
- const eligible = sessions.filter(s => TAIL_SUPPORTED.includes(s.agent));
123
- if (eligible.length === 0)
124
- return undefined;
125
- eligible.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
126
- return eligible[0];
127
- }
128
- async function resolveTailable(sessionId) {
129
- const sessions = await discoverSessions({ all: true, limit: 5000 });
130
- const matches = resolveSessionById(sessions, sessionId);
131
- if (matches.length === 0)
132
- return undefined;
133
- const supported = matches.find(s => TAIL_SUPPORTED.includes(s.agent));
134
- if (supported)
135
- return supported;
136
- return 'unsupported';
137
- }
138
- async function runTail(sessionId, options) {
139
- let session;
140
- if (options.latest) {
141
- session = await findLatestTailable();
142
- if (!session) {
143
- console.log(chalk.gray('No tailable sessions found (claude or codex).'));
144
- return;
145
- }
146
- }
147
- else {
148
- if (!sessionId) {
149
- console.error(chalk.red('Missing session ID. Pass an ID or use --latest.'));
150
- process.exit(2);
151
- }
152
- const resolved = await resolveTailable(sessionId);
153
- if (resolved === 'unsupported') {
154
- console.error(chalk.red(`Tailing is supported for append-only JSONL agents only (claude, codex).`));
155
- process.exit(2);
156
- }
157
- if (!resolved) {
158
- console.error(chalk.red(`No session found matching: ${sessionId}`));
159
- process.exit(1);
160
- }
161
- session = resolved;
162
- }
163
- await streamSessionTail(session, { fromStart: options.fromStart, raw: options.json });
164
- }
165
- export async function streamSessionTail(session, options = {}) {
166
- const filePath = session.filePath.split('#')[0];
167
- const render = options.raw ? undefined : makeStreamRenderer(session.agent, session.cwd);
168
- if (process.stderr.isTTY) {
169
- process.stderr.write(chalk.gray(`Tailing ${session.agent} ${session.shortId} — ${filePath}\n`) +
170
- chalk.gray('Ctrl+C to stop.\n'));
171
- }
172
- const ac = new AbortController();
173
- const onSig = () => { ac.abort(); };
174
- process.on('SIGINT', onSig);
175
- process.on('SIGTERM', onSig);
176
- try {
177
- await tailFile(filePath, (line) => {
178
- if (!render) {
179
- process.stdout.write(line + '\n');
180
- return;
181
- }
182
- const out = render(line);
183
- if (out)
184
- process.stdout.write(out + '\n');
185
- }, ac, { fromStart: options.fromStart });
186
- }
187
- finally {
188
- process.off('SIGINT', onSig);
189
- process.off('SIGTERM', onSig);
190
- }
191
- }
192
- export function registerSessionsTailCommand(sessionsCmd) {
193
- const tailCmd = sessionsCmd
194
- .command('tail [sessionId]')
195
- .description('Stream compact live lines from a session file as events are written. Long-running: Ctrl+C to stop. Claude and Codex only.')
196
- .option('--latest', 'Tail the most recent tailable session (claude or codex)')
197
- .option('--from-start', 'Emit the full file first, then follow (default: start at EOF)')
198
- .option('--json', 'Emit raw JSONL events instead of compact live lines');
199
- setHelpSections(tailCmd, {
200
- examples: `
201
- # Follow the most recent active Claude or Codex session
202
- agents sessions tail --latest
203
-
204
- # Follow a specific session by short or full ID
205
- agents sessions tail a1b2c3d4
206
-
207
- # Replay from the beginning, then follow
208
- agents sessions tail a1b2c3d4 --from-start
209
-
210
- # Pipe raw events through jq to extract just user messages
211
- agents sessions tail --latest --json | jq 'select(.type == "user")'
212
- `,
213
- notes: `
214
- - Only Claude and Codex sessions are tailable — they append JSONL one event per line.
215
- - Live tail is compact by default; pass --json for the raw JSONL stream.
216
- - Gemini, OpenCode, and OpenClaw use formats that rewrite the file or store state elsewhere.
217
- `,
218
- });
219
- tailCmd.action(async (sessionId, _options, command) => {
220
- await runTail(sessionId, command.optsWithGlobals());
221
- });
222
- }
@@ -1,12 +0,0 @@
1
- import type { BrowserTaskSummary } from './sessions-list.js';
2
- export declare class NativeHistoryWriter {
3
- readonly file: string;
4
- private readonly db;
5
- constructor(file: string);
6
- put(record: Omit<BrowserTaskSummary, 'counts'> & {
7
- counts?: BrowserTaskSummary['counts'];
8
- }): void;
9
- putMany(records: Parameters<NativeHistoryWriter['put']>[0][]): void;
10
- rawRecord(profile: string, task: string, record: string, lastActivity: number): void;
11
- close(): void;
12
- }
@@ -1,43 +0,0 @@
1
- import * as fs from 'node:fs';
2
- import * as path from 'node:path';
3
- import Database from '../sqlite.js';
4
- export class NativeHistoryWriter {
5
- file;
6
- db;
7
- constructor(file) {
8
- this.file = file;
9
- fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
10
- this.db = new Database(file);
11
- this.db.exec(`PRAGMA busy_timeout=5000;
12
- PRAGMA journal_mode=WAL;
13
- PRAGMA wal_autocheckpoint=0;
14
- CREATE TABLE IF NOT EXISTS tasks (
15
- profile TEXT NOT NULL, task TEXT NOT NULL, last_activity INTEGER NOT NULL,
16
- record TEXT NOT NULL, native INTEGER NOT NULL DEFAULT 1, PRIMARY KEY(profile, task));
17
- CREATE INDEX IF NOT EXISTS tasks_activity ON tasks(last_activity DESC);
18
- CREATE TABLE IF NOT EXISTS migrations (name TEXT PRIMARY KEY);`);
19
- this.db.exec('PRAGMA user_version=1');
20
- }
21
- put(record) {
22
- this.db.prepare(`INSERT INTO tasks(profile,task,last_activity,record,native) VALUES(?,?,?,?,1)
23
- ON CONFLICT(profile,task) DO UPDATE SET
24
- last_activity=MAX(tasks.last_activity,excluded.last_activity), native=excluded.native,
25
- record=json_set(
26
- CASE WHEN excluded.last_activity >= tasks.last_activity
27
- THEN json_patch(tasks.record,excluded.record)
28
- ELSE json_patch(excluded.record,tasks.record) END,
29
- '$.lastActivity', MAX(tasks.last_activity,excluded.last_activity),
30
- '$.startedAt', MIN(json_extract(tasks.record,'$.startedAt'),json_extract(excluded.record,'$.startedAt')))`).run(record.profile, record.task, record.lastActivity, JSON.stringify(record));
31
- }
32
- putMany(records) {
33
- this.db.transaction(() => { for (const record of records)
34
- this.put(record); })();
35
- }
36
- rawRecord(profile, task, record, lastActivity) {
37
- this.db.prepare('INSERT OR REPLACE INTO tasks(profile,task,last_activity,record,native) VALUES(?,?,?,?,1)')
38
- .run(profile, task, lastActivity, record);
39
- }
40
- close() {
41
- this.db.close();
42
- }
43
- }
@@ -1,9 +0,0 @@
1
- export { getBrowserDurableDir } from '../state.js';
2
- export declare function getBrowserRuntimeDir(): string;
3
- export declare function getProfileRuntimeDir(name: string): string;
4
- export declare function profileOfCacheKey(key: string): string;
5
- export declare function profileScopeSql(column: string, profile: string): {
6
- sql: string;
7
- params: string[];
8
- };
9
- export declare function listProfileCacheDirs(profileName: string): string[];
@@ -1,31 +0,0 @@
1
- import * as path from 'node:path';
2
- import * as fs from 'node:fs';
3
- import { getBrowserRuntimeDir as getBrowserRuntimeDirRoot } from '../state.js';
4
- export { getBrowserDurableDir } from '../state.js';
5
- export function getBrowserRuntimeDir() {
6
- return getBrowserRuntimeDirRoot();
7
- }
8
- export function getProfileRuntimeDir(name) {
9
- return path.join(getBrowserRuntimeDir(), name);
10
- }
11
- export function profileOfCacheKey(key) {
12
- const at = key.lastIndexOf('@');
13
- return at === -1 ? key : key.slice(0, at);
14
- }
15
- export function profileScopeSql(column, profile) {
16
- return {
17
- sql: `(${column} = ? OR (substr(${column}, 1, length(?) + 1) = ? || '@' AND instr(substr(${column}, length(?) + 2), '@') = 0))`,
18
- params: [profile, profile, profile, profile],
19
- };
20
- }
21
- export function listProfileCacheDirs(profileName) {
22
- const root = getBrowserRuntimeDir();
23
- if (!fs.existsSync(root))
24
- return [];
25
- const matches = [];
26
- for (const entry of fs.readdirSync(root)) {
27
- if (profileOfCacheKey(entry) === profileName)
28
- matches.push(path.join(root, entry));
29
- }
30
- return matches;
31
- }
@@ -1,4 +0,0 @@
1
- import type { BrowserActionEvent } from '../browser-client.js';
2
- export declare function recordBrowserAction(event: BrowserActionEvent, opts?: {
3
- device?: string;
4
- }): void;
@@ -1,19 +0,0 @@
1
- import { recordBrowserSession } from '../session/db.js';
2
- import { resolveActor } from '../actor.js';
3
- export function recordBrowserAction(event, opts = {}) {
4
- if (typeof event.task !== 'string' || typeof event.profile !== 'string')
5
- return;
6
- const machine = event.host ?? opts.device;
7
- try {
8
- recordBrowserSession({
9
- task: event.task,
10
- profile: event.profile,
11
- sessionId: event.sessionId ?? process.env.AGENT_SESSION_ID ?? process.env.AGENTS_SESSION_ID,
12
- launchId: event.launchId ?? process.env.AGENT_LAUNCH_ID,
13
- actor: event.actor ?? resolveActor().id,
14
- ...(machine ? { machine } : {}),
15
- });
16
- }
17
- catch {
18
- }
19
- }