@phnx-labs/agents-cli 1.23.18 → 1.23.20
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 +187 -0
- package/README.md +1 -1
- package/dist/bootstrap.js +1 -1
- package/dist/commands/cloud.js +1 -1
- package/dist/commands/config.js +1 -1
- package/dist/commands/detach.js +5 -1
- package/dist/commands/doctor.js +11 -7
- package/dist/commands/exec.d.ts +0 -17
- package/dist/commands/exec.js +17 -51
- package/dist/commands/focus.d.ts +10 -2
- package/dist/commands/focus.js +80 -19
- package/dist/commands/projects-todo.js +10 -5
- package/dist/commands/ps.d.ts +8 -2
- package/dist/commands/ps.js +175 -92
- package/dist/commands/sessions-picker.d.ts +0 -7
- package/dist/commands/sessions-picker.js +5 -299
- package/dist/commands/sessions-stop.js +2 -2
- package/dist/lib/account-registry.d.ts +3 -0
- package/dist/lib/account-registry.js +40 -0
- package/dist/lib/accounting/account-pool-collect.d.ts +2 -2
- package/dist/lib/accounting/account-pool-collect.js +4 -4
- package/dist/lib/accounting/account-pool.d.ts +1 -1
- package/dist/lib/accounting/account-pool.js +3 -1
- package/dist/lib/accounting/usage-sync.d.ts +1 -0
- package/dist/lib/accounting/usage-sync.js +20 -3
- package/dist/lib/accounting/usage.d.ts +4 -1
- package/dist/lib/accounting/usage.js +38 -6
- package/dist/lib/agent-spec/agents.js +12 -11
- package/dist/lib/cloud/store.d.ts +5 -1
- package/dist/lib/cloud/store.js +10 -3
- package/dist/lib/config-keys.d.ts +1 -1
- package/dist/lib/config-keys.js +1 -0
- package/dist/lib/daemon/account-state-daemon-service.js +9 -2
- package/dist/lib/daemon/self-update-service.js +1 -1
- package/dist/lib/device-config.d.ts +2 -1
- package/dist/lib/device-config.js +21 -11
- package/dist/lib/devices/health.d.ts +6 -0
- package/dist/lib/devices/health.js +11 -4
- package/dist/lib/feed/watch.js +2 -1
- package/dist/lib/fleet/apply.d.ts +1 -1
- package/dist/lib/fleet/apply.js +5 -2
- package/dist/lib/fleet-shared-state.d.ts +2 -0
- package/dist/lib/fleet-shared-state.js +3 -1
- package/dist/lib/github/project-prs.js +14 -1
- package/dist/lib/helper-versions.js +1 -1
- package/dist/lib/installations/versions.js +4 -3
- package/dist/lib/project-root.d.ts +1 -0
- package/dist/lib/project-root.js +11 -3
- package/dist/lib/projects.js +2 -2
- package/dist/lib/quick-todo.d.ts +5 -1
- package/dist/lib/quick-todo.js +14 -1
- package/dist/lib/remote-agents-json.js +4 -2
- package/dist/lib/self-update.d.ts +1 -1
- package/dist/lib/self-update.js +59 -2
- package/dist/lib/session/db.js +1 -1
- package/dist/lib/session/glance-files.d.ts +21 -0
- package/dist/lib/session/glance-files.js +123 -0
- package/dist/lib/session/presentation.d.ts +3 -0
- package/dist/lib/session/preview-digest.d.ts +13 -0
- package/dist/lib/session/preview-digest.js +328 -0
- package/dist/lib/session/recovery.d.ts +1 -1
- package/dist/lib/session/recovery.js +1 -1
- package/dist/lib/session/remote/remote-list.d.ts +3 -2
- package/dist/lib/session/remote/remote-list.js +12 -6
- package/dist/lib/session/remote/watch.d.ts +2 -0
- package/dist/lib/session/remote/watch.js +86 -5
- package/dist/lib/smart-launch.js +6 -1
- package/dist/lib/teams/placement-probe.d.ts +2 -0
- package/dist/lib/teams/placement-probe.js +8 -3
- package/dist/lib/terminal/engine.d.ts +2 -0
- package/dist/lib/terminal/engine.js +5 -3
- package/dist/lib/terminal/index.d.ts +1 -1
- package/dist/lib/terminal/index.js +1 -1
- package/dist/lib/terminal/run-surface.d.ts +1 -0
- package/dist/lib/terminal/run-surface.js +9 -0
- package/package.json +1 -1
- package/dist/lib/onepassword.d.ts +0 -57
- package/dist/lib/onepassword.js +0 -140
package/dist/lib/project-root.js
CHANGED
|
@@ -40,13 +40,21 @@ export function homeRemainder(p) {
|
|
|
40
40
|
return p.slice(6);
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
|
-
const FOREIGN_HOME_RE = /^\/(?:home|Users)\/[^/]+(?=\/|$)/;
|
|
43
|
+
const FOREIGN_HOME_RE = /^\/(?:home|Users)\/([^/]+)(?=\/|$)/;
|
|
44
44
|
const WORKTREE_RE = /\/\.agents\/worktrees\/[^/]+(?:\/.*)?$/;
|
|
45
|
+
export function localizeHome(p, home = HOME) {
|
|
46
|
+
if (p === home || p.startsWith(home + '/'))
|
|
47
|
+
return p;
|
|
48
|
+
const foreign = p.match(FOREIGN_HOME_RE);
|
|
49
|
+
const user = path.basename(home);
|
|
50
|
+
if (!foreign || foreign[1] !== user || user === 'Shared')
|
|
51
|
+
return p;
|
|
52
|
+
return home + p.slice(foreign[0].length);
|
|
53
|
+
}
|
|
45
54
|
export function localProjectFolder(cwd, home = HOME) {
|
|
46
55
|
if (!cwd)
|
|
47
56
|
return undefined;
|
|
48
|
-
const
|
|
49
|
-
const folder = local.replace(WORKTREE_RE, '');
|
|
57
|
+
const folder = localizeHome(cwd, home).replace(WORKTREE_RE, '');
|
|
50
58
|
return folder !== home && fs.existsSync(folder) ? folder : undefined;
|
|
51
59
|
}
|
|
52
60
|
export function deriveMirroredCwd(localCwd) {
|
package/dist/lib/projects.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as path from 'path';
|
|
|
3
3
|
import * as yaml from 'yaml';
|
|
4
4
|
import { getProjectsDir } from './state.js';
|
|
5
5
|
import { safeJoin } from './paths.js';
|
|
6
|
-
import { toHomeRelative, expandLocalHome } from './project-root.js';
|
|
6
|
+
import { toHomeRelative, expandLocalHome, localizeHome } from './project-root.js';
|
|
7
7
|
import { resolveProjectKey } from './project-key.js';
|
|
8
8
|
import { atomicWriteFileSync } from './fs-atomic.js';
|
|
9
9
|
export function isSafeProjectName(name) {
|
|
@@ -308,7 +308,7 @@ function isUnder(child, parent) {
|
|
|
308
308
|
export function projectNameForCwd(cwd, defs) {
|
|
309
309
|
if (!cwd)
|
|
310
310
|
return undefined;
|
|
311
|
-
const abs = path.resolve(expandLocalHome(cwd));
|
|
311
|
+
const abs = path.resolve(localizeHome(expandLocalHome(cwd)));
|
|
312
312
|
let best;
|
|
313
313
|
let bestLen = -1;
|
|
314
314
|
let weakBest;
|
package/dist/lib/quick-todo.d.ts
CHANGED
|
@@ -68,7 +68,11 @@ export interface AddOptions {
|
|
|
68
68
|
}
|
|
69
69
|
export declare function addRefusal(title: string, opts: AddOptions): string | null;
|
|
70
70
|
export declare function addQuickTodo(text: string, opts: AddOptions, linear?: LinearExec): Promise<TodoResult>;
|
|
71
|
-
export
|
|
71
|
+
export interface ListOptions {
|
|
72
|
+
project?: string;
|
|
73
|
+
defs?: readonly ProjectDef[];
|
|
74
|
+
}
|
|
75
|
+
export declare function listQuickTodos(now: Date, opts?: ListOptions, linear?: LinearExec): Promise<{
|
|
72
76
|
todos: QuickTodo[];
|
|
73
77
|
total: number;
|
|
74
78
|
}>;
|
package/dist/lib/quick-todo.js
CHANGED
|
@@ -172,7 +172,20 @@ export async function addQuickTodo(text, opts, linear = linearExec) {
|
|
|
172
172
|
return { ok: true, todo, message: `Created ${id}; reading it back failed: ${linearFailure(err)}` };
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
-
export async function listQuickTodos(now, linear = linearExec) {
|
|
175
|
+
export async function listQuickTodos(now, opts = {}, linear = linearExec) {
|
|
176
|
+
if (opts.project) {
|
|
177
|
+
const project = linearProjectFor(opts.project, opts.defs ?? []);
|
|
178
|
+
const parsed = JSON.parse((await linear(['tasks', '--project', project, '--status', 'open', '--all', '--json'])).stdout);
|
|
179
|
+
const all = (parsed.issues ?? []).map(toQuickTodo);
|
|
180
|
+
all.sort((a, b) => {
|
|
181
|
+
if ((a.due === null) !== (b.due === null))
|
|
182
|
+
return a.due !== null ? -1 : 1;
|
|
183
|
+
if (a.due !== null && a.due !== b.due)
|
|
184
|
+
return a.due < b.due ? -1 : 1;
|
|
185
|
+
return b.createdAt.localeCompare(a.createdAt);
|
|
186
|
+
});
|
|
187
|
+
return { todos: all.slice(0, TODO_LIST_LIMIT), total: all.length };
|
|
188
|
+
}
|
|
176
189
|
const parsed = JSON.parse((await linear(['tasks', '--assignee', 'me', '--status', 'open', '--cycle', 'all', '--all', '--json'])).stdout);
|
|
177
190
|
const today = localDay(now);
|
|
178
191
|
const due = (t) => t.due !== null && t.due <= today;
|
|
@@ -3,6 +3,7 @@ import { setMaxListeners } from 'node:events';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import { SSH_OPTS, controlOpts, assertValidSshTarget, shellQuote, REMOTE_STDOUT_MAX_BYTES, RemoteUtf8Accumulator, } from './ssh-exec.js';
|
|
5
5
|
import { deviceIdentityArgs, sshTargetFor } from './devices/connect.js';
|
|
6
|
+
import { resolveDeviceProfile } from './devices/resolve-profile.js';
|
|
6
7
|
import { resolveExplicitTargets } from './devices/resolve-target.js';
|
|
7
8
|
import { loadDevices, isDialableDevice } from './devices/registry.js';
|
|
8
9
|
import { remoteShellFor, buildWindowsAgentsCommand, buildWindowsToolCommand, stripClixml } from './hosts/remote-cmd.js';
|
|
@@ -86,14 +87,15 @@ export async function gatherRemoteAgentsJson(options, deps = {}) {
|
|
|
86
87
|
continue;
|
|
87
88
|
if (normalizeHost(device.name) === self)
|
|
88
89
|
continue;
|
|
89
|
-
|
|
90
|
+
const platform = resolveDeviceProfile(device).platform;
|
|
91
|
+
if (!['windows', 'linux', 'macos'].includes(platform))
|
|
90
92
|
continue;
|
|
91
93
|
try {
|
|
92
94
|
targets.push({
|
|
93
95
|
target: sshTargetFor(device),
|
|
94
96
|
machine: normalizeHost(device.name),
|
|
95
97
|
name: device.name,
|
|
96
|
-
os:
|
|
98
|
+
os: platform,
|
|
97
99
|
extraSshArgs: deviceIdentityArgs(device),
|
|
98
100
|
});
|
|
99
101
|
}
|
|
@@ -35,7 +35,7 @@ export declare function sweepStaleInstallStaging(packageRoot: string): Promise<s
|
|
|
35
35
|
export declare function installPackageIntoPrefix(spec: string, prefix: string, signal?: AbortSignal): Promise<void>;
|
|
36
36
|
export declare const INSTALL_SETTLE_MS = 60000;
|
|
37
37
|
export declare function installLooksSettled(packageRoot: string, settleMs?: number, now?: number): boolean;
|
|
38
|
-
export declare function installPackageWithBun(spec: string, signal?: AbortSignal): Promise<void>;
|
|
38
|
+
export declare function installPackageWithBun(spec: string, globalDir: string, signal?: AbortSignal): Promise<void>;
|
|
39
39
|
export declare function verifyTarballIntegrity(tarball: Buffer, integrity: string): void;
|
|
40
40
|
export declare function downloadVerifiedTarball(tarballUrl: string, integrity: string, timeoutMs?: number, signal?: AbortSignal): Promise<string>;
|
|
41
41
|
export declare function readInstalledVersion(packageRoot: string): Promise<string>;
|
package/dist/lib/self-update.js
CHANGED
|
@@ -7,6 +7,7 @@ import { execFile } from 'child_process';
|
|
|
7
7
|
import { promisify } from 'util';
|
|
8
8
|
const execFileAsync = promisify(execFile);
|
|
9
9
|
import { compareVersions } from './agent-spec/primitives.js';
|
|
10
|
+
import { atomicWriteJsonSync } from './fs-atomic.js';
|
|
10
11
|
import { needsWindowsShell } from './platform/index.js';
|
|
11
12
|
import { PEER_HOP_ENV } from './types.js';
|
|
12
13
|
export const NPM_PACKAGE_NAME = '@phnx-labs/agents-cli';
|
|
@@ -243,11 +244,67 @@ export function installLooksSettled(packageRoot, settleMs = INSTALL_SETTLE_MS, n
|
|
|
243
244
|
return false;
|
|
244
245
|
}
|
|
245
246
|
}
|
|
246
|
-
|
|
247
|
+
function readBunGlobalManifest(globalDir) {
|
|
248
|
+
try {
|
|
249
|
+
const parsed = JSON.parse(fs.readFileSync(path.join(globalDir, 'package.json'), 'utf-8'));
|
|
250
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
251
|
+
? parsed
|
|
252
|
+
: null;
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function setBunGlobalDependency(globalDir, spec) {
|
|
259
|
+
const manifest = readBunGlobalManifest(globalDir);
|
|
260
|
+
if (!manifest)
|
|
261
|
+
return null;
|
|
262
|
+
const deps = manifest.dependencies;
|
|
263
|
+
if (!deps || typeof deps !== 'object' || Array.isArray(deps))
|
|
264
|
+
return null;
|
|
265
|
+
const entries = deps;
|
|
266
|
+
const previous = entries[NPM_PACKAGE_NAME] ?? null;
|
|
267
|
+
if (spec === null) {
|
|
268
|
+
if (!(NPM_PACKAGE_NAME in entries))
|
|
269
|
+
return previous;
|
|
270
|
+
delete entries[NPM_PACKAGE_NAME];
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
if (entries[NPM_PACKAGE_NAME] === spec)
|
|
274
|
+
return previous;
|
|
275
|
+
entries[NPM_PACKAGE_NAME] = spec;
|
|
276
|
+
}
|
|
277
|
+
atomicWriteJsonSync(path.join(globalDir, 'package.json'), manifest);
|
|
278
|
+
return previous;
|
|
279
|
+
}
|
|
280
|
+
function restoreBunGlobalDependency(globalDir, spec) {
|
|
281
|
+
try {
|
|
282
|
+
setBunGlobalDependency(globalDir, spec);
|
|
283
|
+
}
|
|
284
|
+
catch { }
|
|
285
|
+
}
|
|
286
|
+
export async function installPackageWithBun(spec, globalDir, signal) {
|
|
247
287
|
const { execFile } = await import('child_process');
|
|
248
288
|
const { promisify } = await import('util');
|
|
249
289
|
const execFileAsync = promisify(execFile);
|
|
250
|
-
|
|
290
|
+
const previous = setBunGlobalDependency(globalDir, null);
|
|
291
|
+
try {
|
|
292
|
+
await execFileAsync('bun', ['add', '-g', spec, '--ignore-scripts'], {
|
|
293
|
+
shell: needsWindowsShell('bun'),
|
|
294
|
+
signal,
|
|
295
|
+
env: { ...process.env, BUN_INSTALL: path.dirname(path.dirname(globalDir)) },
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
restoreBunGlobalDependency(globalDir, previous);
|
|
300
|
+
throw err;
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
setBunGlobalDependency(globalDir, await readInstalledVersion(path.join(globalDir, 'node_modules', NPM_PACKAGE_NAME)));
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
restoreBunGlobalDependency(globalDir, null);
|
|
307
|
+
}
|
|
251
308
|
}
|
|
252
309
|
// Fail closed on anything except the registry's sha512 bytes before handing a tarball to a package manager.
|
|
253
310
|
export function verifyTarballIntegrity(tarball, integrity) {
|
package/dist/lib/session/db.js
CHANGED
|
@@ -507,7 +507,7 @@ CREATE INDEX IF NOT EXISTS idx_remote_preview_cache_fetched ON session_remote_pr
|
|
|
507
507
|
`;
|
|
508
508
|
export const INSIGHTS_EXTRACTOR_VERSION = 7;
|
|
509
509
|
export const SESSION_TOPIC_EXTRACTOR_VERSION = 2;
|
|
510
|
-
const PREVIEW_EXTRACTOR_VERSION =
|
|
510
|
+
const PREVIEW_EXTRACTOR_VERSION = 5;
|
|
511
511
|
export const SESSION_PHENOTYPE_EXTRACTOR_VERSION = 1;
|
|
512
512
|
export const SESSION_SUMMARY_EXTRACTOR_VERSION = 1;
|
|
513
513
|
let dbInstance = null;
|
|
@@ -18,3 +18,24 @@ export declare function cacheInlineImage(sessionId: string, data: string, mediaT
|
|
|
18
18
|
} | undefined;
|
|
19
19
|
export declare function materializeInlineImages(events: SessionEvent[], sessionId: string, root?: string): void;
|
|
20
20
|
export declare function enrichGlanceFiles(rows: ActiveSession[], nowMs?: number): void;
|
|
21
|
+
export interface PreviewSubAgent {
|
|
22
|
+
id?: string;
|
|
23
|
+
description: string;
|
|
24
|
+
agentType?: string;
|
|
25
|
+
status: 'running' | 'completed' | 'failed';
|
|
26
|
+
startedAt?: string;
|
|
27
|
+
durationMs?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface PreviewImage {
|
|
30
|
+
path: string;
|
|
31
|
+
source: 'attached' | 'produced' | 'read';
|
|
32
|
+
at?: string;
|
|
33
|
+
}
|
|
34
|
+
export declare function previewSubAgentsFromEvents(events: SessionEvent[], isSubAgent: (tool: string, command: string) => boolean): PreviewSubAgent[];
|
|
35
|
+
export declare function previewSubAgentsFromFiles(sessionFile: string, fromEvents: readonly PreviewSubAgent[], nowMs?: number): PreviewSubAgent[] | undefined;
|
|
36
|
+
export declare function previewImagesFromEvents(events: SessionEvent[], changes: ReadonlyArray<{
|
|
37
|
+
path: string;
|
|
38
|
+
op: string;
|
|
39
|
+
}>, cwd?: string): PreviewImage[];
|
|
40
|
+
export declare function cachedAttachmentImages(sessionId: string, root?: string): PreviewImage[];
|
|
41
|
+
export declare function mergePreviewImages(...lists: PreviewImage[][]): PreviewImage[];
|
|
@@ -287,3 +287,126 @@ export function enrichGlanceFiles(rows, nowMs = Date.now()) {
|
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
+
const PREVIEW_SUBAGENTS_MAX = 30;
|
|
291
|
+
const PREVIEW_IMAGES_MAX = 6;
|
|
292
|
+
const IMAGE_PATH_RE = /\.(png|jpe?g|gif|webp|bmp|tiff?|heic|svg)$/i;
|
|
293
|
+
const IMAGE_READ_TOOLS = new Set(['Read', 'read_file', 'view_file', 'view_image', 'cat_file', 'get_file']);
|
|
294
|
+
export function previewSubAgentsFromEvents(events, isSubAgent) {
|
|
295
|
+
const rows = [];
|
|
296
|
+
const byCall = new Map();
|
|
297
|
+
for (const event of events) {
|
|
298
|
+
if (event.type === 'tool_use' && !event._local && isSubAgent(event.tool ?? '', event.command ?? '')) {
|
|
299
|
+
const args = event.args ?? {};
|
|
300
|
+
const text = (value) => typeof value === 'string' && value.trim() ? value.replace(/\s+/g, ' ').trim() : undefined;
|
|
301
|
+
const row = {
|
|
302
|
+
...(event.callId ? { id: event.callId } : {}),
|
|
303
|
+
description: (text(args.description) ?? text(args.prompt) ?? text(event.command) ?? event.tool ?? 'subagent').slice(0, 200),
|
|
304
|
+
...(text(args.subagent_type) ? { agentType: text(args.subagent_type) } : {}),
|
|
305
|
+
status: 'running',
|
|
306
|
+
...(event.timestamp ? { startedAt: event.timestamp } : {}),
|
|
307
|
+
...(args.run_in_background === true ? { background: true } : {}),
|
|
308
|
+
};
|
|
309
|
+
rows.push(row);
|
|
310
|
+
if (event.callId)
|
|
311
|
+
byCall.set(event.callId, row);
|
|
312
|
+
}
|
|
313
|
+
else if ((event.type === 'tool_result' || event.type === 'error') && event.callId) {
|
|
314
|
+
const row = byCall.get(event.callId);
|
|
315
|
+
if (!row)
|
|
316
|
+
continue;
|
|
317
|
+
row.status = event.type === 'error' || event.success === false ? 'failed' : row.background ? 'running' : 'completed';
|
|
318
|
+
const started = row.startedAt ? Date.parse(row.startedAt) : NaN;
|
|
319
|
+
const ended = Date.parse(event.timestamp);
|
|
320
|
+
if (row.status !== 'running' && Number.isFinite(started) && Number.isFinite(ended) && ended >= started)
|
|
321
|
+
row.durationMs = ended - started;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return rows.slice(-PREVIEW_SUBAGENTS_MAX).map(({ background: _background, ...row }) => row);
|
|
325
|
+
}
|
|
326
|
+
export function previewSubAgentsFromFiles(sessionFile, fromEvents, nowMs = Date.now()) {
|
|
327
|
+
const children = readSessionSubagents(sessionFile, true, [], nowMs);
|
|
328
|
+
if (!children?.length)
|
|
329
|
+
return undefined;
|
|
330
|
+
const settled = new Map(fromEvents.filter(row => row.id && row.status !== 'running').map(row => [row.id, row]));
|
|
331
|
+
return children.map((child) => {
|
|
332
|
+
const metaPath = child.transcriptPath.replace(/\.jsonl$/, '.meta.json');
|
|
333
|
+
let toolUseId;
|
|
334
|
+
try {
|
|
335
|
+
toolUseId = JSON.parse(fs.readFileSync(metaPath, 'utf8')).toolUseId;
|
|
336
|
+
}
|
|
337
|
+
catch { }
|
|
338
|
+
const result = toolUseId ? settled.get(toolUseId) : undefined;
|
|
339
|
+
const status = result?.status ?? (child.status === 'failed' ? 'failed' : child.status === 'running' ? 'running' : 'completed');
|
|
340
|
+
let endedAtMs;
|
|
341
|
+
try {
|
|
342
|
+
endedAtMs = fs.statSync(child.transcriptPath).mtimeMs;
|
|
343
|
+
}
|
|
344
|
+
catch { }
|
|
345
|
+
const durationMs = result?.durationMs
|
|
346
|
+
?? (child.startedAtMs !== undefined && endedAtMs !== undefined && endedAtMs >= child.startedAtMs ? Math.round(endedAtMs - child.startedAtMs) : undefined);
|
|
347
|
+
return {
|
|
348
|
+
id: child.id,
|
|
349
|
+
description: child.description,
|
|
350
|
+
...(child.agentType ? { agentType: child.agentType } : {}),
|
|
351
|
+
status,
|
|
352
|
+
...(child.startedAtMs !== undefined ? { startedAt: new Date(child.startedAtMs).toISOString() } : {}),
|
|
353
|
+
...(durationMs !== undefined && status !== 'running' ? { durationMs } : {}),
|
|
354
|
+
};
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
export function previewImagesFromEvents(events, changes, cwd) {
|
|
358
|
+
const resolve = (p) => path.isAbsolute(p) || !cwd ? p : path.resolve(cwd, p);
|
|
359
|
+
const out = [];
|
|
360
|
+
const lastTouch = new Map();
|
|
361
|
+
for (const event of events) {
|
|
362
|
+
if (event.type === 'attachment' && event.path && (event.mediaType ?? '').startsWith('image/')) {
|
|
363
|
+
out.push({ path: resolve(event.path), source: 'attached', ...(event.timestamp ? { at: event.timestamp } : {}) });
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (event.type !== 'tool_use' || event._local)
|
|
367
|
+
continue;
|
|
368
|
+
const raw = event.path || event.args?.file_path || event.args?.path;
|
|
369
|
+
if (typeof raw !== 'string' || !IMAGE_PATH_RE.test(raw))
|
|
370
|
+
continue;
|
|
371
|
+
const abs = resolve(raw);
|
|
372
|
+
if (event.timestamp)
|
|
373
|
+
lastTouch.set(abs, event.timestamp);
|
|
374
|
+
if (IMAGE_READ_TOOLS.has(event.tool ?? ''))
|
|
375
|
+
out.push({ path: abs, source: 'read', ...(event.timestamp ? { at: event.timestamp } : {}) });
|
|
376
|
+
}
|
|
377
|
+
for (const change of changes) {
|
|
378
|
+
if (change.op === 'deleted' || !IMAGE_PATH_RE.test(change.path))
|
|
379
|
+
continue;
|
|
380
|
+
const abs = resolve(change.path);
|
|
381
|
+
const at = lastTouch.get(abs);
|
|
382
|
+
out.push({ path: abs, source: 'produced', ...(at ? { at } : {}) });
|
|
383
|
+
}
|
|
384
|
+
return mergePreviewImages(out.filter(image => fs.existsSync(image.path)));
|
|
385
|
+
}
|
|
386
|
+
export function cachedAttachmentImages(sessionId, root = path.join(getUserAgentsDir(), '.cache', 'attachments')) {
|
|
387
|
+
if (!sessionId || path.basename(sessionId) !== sessionId)
|
|
388
|
+
return [];
|
|
389
|
+
const dir = path.join(root, sessionId);
|
|
390
|
+
try {
|
|
391
|
+
return fs.readdirSync(dir)
|
|
392
|
+
.filter(name => IMAGE_PATH_RE.test(name))
|
|
393
|
+
.map((name) => {
|
|
394
|
+
const file = path.join(dir, name);
|
|
395
|
+
return { path: file, source: 'attached', at: new Date(fs.statSync(file).mtimeMs).toISOString() };
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
catch {
|
|
399
|
+
return [];
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
export function mergePreviewImages(...lists) {
|
|
403
|
+
const byPath = new Map();
|
|
404
|
+
for (const image of lists.flat()) {
|
|
405
|
+
const prior = byPath.get(image.path);
|
|
406
|
+
if (!prior || (image.at ?? '') >= (prior.at ?? ''))
|
|
407
|
+
byPath.set(image.path, prior?.source === 'attached' ? { ...image, source: 'attached' } : image);
|
|
408
|
+
}
|
|
409
|
+
return [...byPath.values()]
|
|
410
|
+
.sort((a, b) => (a.at ?? '').localeCompare(b.at ?? ''))
|
|
411
|
+
.slice(-PREVIEW_IMAGES_MAX);
|
|
412
|
+
}
|
|
@@ -79,6 +79,8 @@ export interface SessionPreviewDigest {
|
|
|
79
79
|
planFile: string;
|
|
80
80
|
todos?: TodoProgress;
|
|
81
81
|
subAgentCount: number;
|
|
82
|
+
subAgents?: import('./glance-files.js').PreviewSubAgent[];
|
|
83
|
+
images?: import('./glance-files.js').PreviewImage[];
|
|
82
84
|
backgroundShellCount?: number;
|
|
83
85
|
toolTags: string[];
|
|
84
86
|
changes: ReturnType<typeof changeCounts>;
|
|
@@ -86,6 +88,7 @@ export interface SessionPreviewDigest {
|
|
|
86
88
|
dirs: string[];
|
|
87
89
|
repos: string[];
|
|
88
90
|
artifacts: ReturnType<typeof extractArtifacts>;
|
|
91
|
+
producedArtifacts?: ReturnType<typeof extractArtifacts>;
|
|
89
92
|
skills: ReturnType<typeof extractSkills>;
|
|
90
93
|
plugins: string[];
|
|
91
94
|
hooks: ReturnType<typeof extractHooks>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SessionEvent, SessionMeta } from '@phnx-labs/sessions-cli/reader';
|
|
2
|
+
import type { SessionPreviewDigest } from './presentation.js';
|
|
3
|
+
export declare const DIRS_TOUCHED_MAX = 5;
|
|
4
|
+
export declare const CHANGED_FILES_MAX = 200;
|
|
5
|
+
export declare function sanitizeMeta(s: SessionMeta): SessionMeta;
|
|
6
|
+
export declare function readCachedPreviewDigest(session: SessionMeta): SessionPreviewDigest | undefined;
|
|
7
|
+
export declare function loadSessionPreviewDigest(session: SessionMeta): {
|
|
8
|
+
digest?: SessionPreviewDigest;
|
|
9
|
+
events: SessionEvent[];
|
|
10
|
+
error?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function buildSessionPreviewDigest(events: SessionEvent[], session: SessionMeta): SessionPreviewDigest;
|
|
13
|
+
export declare function relativizeDir(filePath: string, cwd?: string): string | undefined;
|