@phnx-labs/agents-cli 1.23.17 → 1.23.19
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 +239 -0
- package/README.md +140 -165
- package/dist/bootstrap.js +11 -17
- package/dist/cli/command-registry.d.ts +1 -2
- package/dist/cli/command-registry.js +1 -10
- package/dist/commands/accounts.js +7 -7
- package/dist/commands/cloud-transcripts.d.ts +0 -1
- package/dist/commands/cloud-transcripts.js +2 -2
- package/dist/commands/cloud.js +2 -2
- package/dist/commands/config.js +1 -5
- package/dist/commands/cost.js +1 -1
- package/dist/commands/daemon-index.js +0 -1
- package/dist/commands/detach.d.ts +1 -1
- package/dist/commands/detach.js +10 -6
- package/dist/commands/doctor.js +11 -7
- package/dist/commands/exec.d.ts +0 -17
- package/dist/commands/exec.js +26 -72
- package/dist/commands/feed.d.ts +1 -1
- package/dist/commands/feed.js +3 -3
- package/dist/commands/focus.d.ts +11 -6
- package/dist/commands/focus.js +91 -31
- package/dist/commands/fork.d.ts +0 -1
- package/dist/commands/fork.js +7 -16
- package/dist/commands/harness-wizard.js +1 -1
- package/dist/commands/harness.js +1 -1
- package/dist/commands/insights.d.ts +0 -1
- package/dist/commands/insights.js +3 -7
- package/dist/commands/open.js +1 -1
- package/dist/commands/output.js +1 -1
- package/dist/commands/profiles.d.ts +1 -1
- package/dist/commands/profiles.js +2 -2
- package/dist/commands/projects-todo.js +10 -5
- package/dist/commands/projects.js +1 -1
- package/dist/commands/prune.js +1 -1
- package/dist/commands/ps.d.ts +8 -3
- package/dist/commands/ps.js +238 -110
- package/dist/commands/routines.js +1 -1
- package/dist/commands/send.js +1 -1
- package/dist/commands/sessions-backfill.d.ts +0 -1
- package/dist/commands/sessions-backfill.js +3 -6
- package/dist/commands/sessions-browser.d.ts +0 -10
- package/dist/commands/sessions-browser.js +19 -25
- package/dist/commands/sessions-migrate.d.ts +2 -2
- package/dist/commands/sessions-migrate.js +13 -13
- package/dist/commands/sessions-optimize.d.ts +0 -1
- package/dist/commands/sessions-optimize.js +0 -3
- package/dist/commands/sessions-picker.d.ts +0 -7
- package/dist/commands/sessions-picker.js +16 -310
- package/dist/commands/sessions-resume.d.ts +16 -15
- package/dist/commands/sessions-resume.js +101 -269
- package/dist/commands/sessions-stats.d.ts +0 -1
- package/dist/commands/sessions-stats.js +5 -8
- package/dist/commands/sessions-stop.d.ts +1 -1
- package/dist/commands/sessions-stop.js +8 -8
- package/dist/commands/sessions-trace.d.ts +1 -1
- package/dist/commands/sessions-trace.js +40 -17
- package/dist/commands/sessions-watch.js +2 -2
- package/dist/commands/sessions.test-fixture.d.ts +1 -0
- package/dist/commands/sessions.test-fixture.js +14 -0
- package/dist/commands/setup-browser.js +4 -4
- package/dist/commands/setup-computer.js +4 -4
- package/dist/commands/setup-fleet.js +1 -1
- package/dist/commands/setup-preferences.js +1 -1
- package/dist/commands/{sessions-backup-setup.d.ts → setup-session-backup.d.ts} +2 -2
- package/dist/commands/{sessions-backup-setup.js → setup-session-backup.js} +8 -8
- package/dist/commands/setup.js +3 -1
- package/dist/commands/ssh.js +4 -5
- package/dist/commands/sync.js +1 -1
- package/dist/commands/teams.js +2 -2
- package/dist/commands/utils.d.ts +0 -1
- package/dist/commands/utils.js +0 -10
- package/dist/index.js +0 -71
- package/dist/lib/account-registry.d.ts +3 -0
- package/dist/lib/account-registry.js +40 -0
- 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/analytics/mix-commands.js +1 -1
- package/dist/lib/auth-mint.js +2 -2
- package/dist/lib/browser-client.d.ts +0 -1
- package/dist/lib/browser-client.js +0 -3
- package/dist/lib/cloud/antigravity.js +1 -1
- package/dist/lib/cloud/cursor.js +3 -3
- package/dist/lib/cloud/store.d.ts +5 -1
- package/dist/lib/cloud/store.js +10 -3
- package/dist/lib/cloudflare/creds.js +2 -2
- package/dist/lib/computer/context.d.ts +4 -21
- package/dist/lib/computer/context.js +3 -24
- package/dist/lib/computer/policy.d.ts +0 -10
- package/dist/lib/computer/policy.js +0 -28
- package/dist/lib/computer-client.d.ts +0 -44
- package/dist/lib/computer-client.js +17 -121
- package/dist/lib/config-keys.d.ts +2 -2
- package/dist/lib/config-keys.js +1 -3
- package/dist/lib/crabbox/cli.js +1 -1
- 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 +26 -39
- package/dist/lib/devices/connect.d.ts +1 -1
- package/dist/lib/devices/connect.js +3 -6
- package/dist/lib/devices/doctor-findings.d.ts +2 -1
- package/dist/lib/devices/doctor-findings.js +4 -4
- package/dist/lib/devices/health.d.ts +6 -0
- package/dist/lib/devices/health.js +11 -4
- package/dist/lib/exec.js +1 -1
- package/dist/lib/feed/activity.js +1 -1
- package/dist/lib/feed/watch.js +2 -1
- package/dist/lib/fleet/apply.d.ts +1 -1
- package/dist/lib/fleet/apply.js +6 -3
- 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/help.d.ts +0 -1
- package/dist/lib/help.js +2 -10
- package/dist/lib/helper-versions.js +1 -1
- package/dist/lib/hosts/option.js +1 -1
- package/dist/lib/hosts/passthrough.d.ts +0 -1
- package/dist/lib/hosts/passthrough.js +2 -26
- package/dist/lib/hosts/reconnect.js +5 -5
- package/dist/lib/hosts/remote-cmd.d.ts +3 -5
- package/dist/lib/hosts/remote-cmd.js +15 -20
- package/dist/lib/hosts/remote-session-id.js +1 -1
- package/dist/lib/installations/active-check.js +1 -1
- package/dist/lib/installations/migrate.js +4 -15
- package/dist/lib/installations/versions.js +5 -4
- package/dist/lib/launch-log.js +3 -6
- package/dist/lib/owner-notify.d.ts +1 -6
- package/dist/lib/owner-notify.js +0 -2
- package/dist/lib/paths.d.ts +0 -1
- package/dist/lib/paths.js +0 -8
- package/dist/lib/permissions.js +1 -1
- 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/redact.d.ts +0 -1
- package/dist/lib/redact.js +0 -4
- package/dist/lib/remote-agents-json.d.ts +3 -1
- package/dist/lib/remote-agents-json.js +12 -8
- package/dist/lib/reserved-stores.js +1 -1
- package/dist/lib/scheduling/routines.d.ts +0 -1
- package/dist/lib/scheduling/routines.js +1 -1
- package/dist/lib/self-update.d.ts +1 -1
- package/dist/lib/self-update.js +59 -2
- package/dist/lib/session/active.d.ts +1 -1
- package/dist/lib/session/db.js +4 -4
- package/dist/lib/session/detached.d.ts +0 -1
- package/dist/lib/session/detached.js +0 -23
- package/dist/lib/session/discover.d.ts +2 -2
- 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 -7
- package/dist/lib/session/presentation.js +4 -4
- package/dist/lib/session/preview-digest.d.ts +13 -0
- package/dist/lib/session/preview-digest.js +328 -0
- package/dist/lib/session/projection.js +1 -1
- package/dist/lib/session/remote/remote-list.d.ts +5 -2
- package/dist/lib/session/remote/remote-list.js +15 -8
- package/dist/lib/session/remote/watch.d.ts +2 -0
- package/dist/lib/session/remote/watch.js +90 -10
- package/dist/lib/session/remote-active.js +1 -1
- package/dist/lib/session/resume-command.d.ts +0 -1
- package/dist/lib/session/resume-command.js +1 -4
- package/dist/lib/session/resume-owner.d.ts +0 -2
- package/dist/lib/session/resume-owner.js +0 -6
- package/dist/lib/session/selection.d.ts +4 -5
- package/dist/lib/session/selection.js +2 -2
- package/dist/lib/session/sync/config.d.ts +0 -25
- package/dist/lib/session/sync/config.js +0 -62
- package/dist/lib/session/sync/managed-config.d.ts +0 -1
- package/dist/lib/session/sync/managed-config.js +0 -3
- package/dist/lib/session/sync/worker-template.js +1 -1
- package/dist/lib/sessions-client.d.ts +0 -16
- package/dist/lib/sessions-client.js +1 -187
- package/dist/lib/smart-launch.js +6 -1
- package/dist/lib/startup/command-registry.d.ts +2 -0
- package/dist/lib/startup/command-registry.js +36 -3
- package/dist/lib/startup/root-command.d.ts +0 -1
- package/dist/lib/startup/root-command.js +0 -21
- package/dist/lib/sync-umbrella.js +1 -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/resolve.js +1 -1
- package/dist/lib/terminal/run-surface.d.ts +1 -0
- package/dist/lib/terminal/run-surface.js +9 -0
- package/dist/lib/watchdog/rotate.js +1 -1
- package/dist/lib/watchdog/watchdog.d.ts +1 -1
- package/dist/lib/watchdog/watchdog.js +2 -2
- package/package.json +1 -1
- package/dist/commands/browser.d.ts +0 -7
- package/dist/commands/browser.js +0 -139
- package/dist/commands/computer.d.ts +0 -48
- package/dist/commands/computer.js +0 -244
- package/dist/commands/resume.d.ts +0 -23
- package/dist/commands/resume.js +0 -158
- package/dist/commands/secrets-passthrough.d.ts +0 -3
- package/dist/commands/secrets-passthrough.js +0 -52
- package/dist/commands/sessions-bookmark.d.ts +0 -2
- package/dist/commands/sessions-bookmark.js +0 -92
- package/dist/commands/sessions-export.d.ts +0 -31
- package/dist/commands/sessions-export.js +0 -409
- package/dist/commands/sessions-import.d.ts +0 -6
- package/dist/commands/sessions-import.js +0 -343
- package/dist/commands/sessions-inject.d.ts +0 -14
- package/dist/commands/sessions-inject.js +0 -143
- package/dist/commands/sessions-picker-factory.d.ts +0 -24
- package/dist/commands/sessions-picker-factory.js +0 -59
- package/dist/commands/sessions-render.d.ts +0 -11
- package/dist/commands/sessions-render.js +0 -119
- package/dist/commands/sessions-share.d.ts +0 -15
- package/dist/commands/sessions-share.js +0 -171
- package/dist/commands/sessions.d.ts +0 -122
- package/dist/commands/sessions.js +0 -1760
- package/dist/lib/address.d.ts +0 -39
- package/dist/lib/address.js +0 -128
- package/dist/lib/computer/record.d.ts +0 -6
- package/dist/lib/computer/record.js +0 -25
- package/dist/lib/onepassword.d.ts +0 -57
- package/dist/lib/onepassword.js +0 -140
- package/dist/lib/openclaw-keychain.d.ts +0 -43
- package/dist/lib/openclaw-keychain.js +0 -227
- package/dist/lib/session/bundle.d.ts +0 -76
- package/dist/lib/session/bundle.js +0 -146
- package/dist/lib/session/remote/remote-bundle.d.ts +0 -7
- package/dist/lib/session/remote/remote-bundle.js +0 -40
- package/dist/lib/session/remote/remote.d.ts +0 -35
- package/dist/lib/session/remote/remote.js +0 -198
- package/dist/lib/session/remote-bundle.d.ts +0 -1
- package/dist/lib/session/remote-bundle.js +0 -1
- package/dist/lib/session/remote.d.ts +0 -1
- package/dist/lib/session/remote.js +0 -1
- package/dist/lib/session/sync/agents.d.ts +0 -24
- package/dist/lib/session/sync/agents.js +0 -0
- package/dist/lib/session/sync/backend.d.ts +0 -22
- package/dist/lib/session/sync/backend.js +0 -44
- package/dist/lib/session/sync/managed-key.d.ts +0 -5
- package/dist/lib/session/sync/managed-key.js +0 -87
- package/dist/lib/session/sync/net-client.d.ts +0 -29
- package/dist/lib/session/sync/net-client.js +0 -87
- package/dist/lib/session/sync/r2.d.ts +0 -20
- package/dist/lib/session/sync/r2.js +0 -103
- package/dist/lib/session/sync/transcript-crypto.d.ts +0 -41
- package/dist/lib/session/sync/transcript-crypto.js +0 -115
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { changeCounts, classifyFileChanges, detectTestResult, extractArtifacts, extractHooks, extractLinks, extractRepos, extractSkills, extractTodoProgressFromEvents, firstUserMessageFromEvents, harnessTracksBackgroundShells, inferSessionState, isBackgroundShellStart, isSubAgentTool, parseSession, readSessionHead, readSessionTail, sanitizeForTerminal, toolHistogram, WORKTREE_RE, } from '@phnx-labs/sessions-cli/reader';
|
|
4
|
+
import { formatBytes } from '../format.js';
|
|
5
|
+
import { getSessionPlugins, readArchivedSessionPreview, readSessionPreviewCache, writeSessionPreviewCache } from './db.js';
|
|
6
|
+
import { cachedAttachmentImages, materializeInlineImages, mergePreviewImages, previewImagesFromEvents, previewSubAgentsFromEvents, previewSubAgentsFromFiles } from './glance-files.js';
|
|
7
|
+
export const DIRS_TOUCHED_MAX = 5;
|
|
8
|
+
export const CHANGED_FILES_MAX = 200;
|
|
9
|
+
const PREVIEW_DIGEST_MAX_PARSE_BYTES = 4 * 1024 * 1024;
|
|
10
|
+
// Peer metadata is untrusted: bound its shape and strip terminal escapes before rendering.
|
|
11
|
+
export function sanitizeMeta(s) {
|
|
12
|
+
const clean = (v) => (v == null ? v : sanitizeForTerminal(v));
|
|
13
|
+
const todos = s.todos
|
|
14
|
+
? {
|
|
15
|
+
...s.todos,
|
|
16
|
+
activeForm: clean(s.todos.activeForm),
|
|
17
|
+
items: s.todos.items.map((it) => ({
|
|
18
|
+
...it,
|
|
19
|
+
content: sanitizeForTerminal(it.content),
|
|
20
|
+
activeForm: clean(it.activeForm),
|
|
21
|
+
})),
|
|
22
|
+
}
|
|
23
|
+
: s.todos;
|
|
24
|
+
return {
|
|
25
|
+
...s,
|
|
26
|
+
id: sanitizeForTerminal(s.id),
|
|
27
|
+
shortId: sanitizeForTerminal(s.shortId),
|
|
28
|
+
filePath: sanitizeForTerminal(s.filePath),
|
|
29
|
+
cwd: clean(s.cwd),
|
|
30
|
+
project: clean(s.project),
|
|
31
|
+
gitBranch: clean(s.gitBranch),
|
|
32
|
+
version: clean(s.version),
|
|
33
|
+
account: clean(s.account),
|
|
34
|
+
topic: clean(s.topic),
|
|
35
|
+
firstUserMessage: clean(s.firstUserMessage),
|
|
36
|
+
label: clean(s.label),
|
|
37
|
+
generatedTitle: clean(s.generatedTitle),
|
|
38
|
+
ticketId: clean(s.ticketId),
|
|
39
|
+
prUrl: clean(s.prUrl),
|
|
40
|
+
plan: clean(s.plan),
|
|
41
|
+
spawnedTeam: clean(s.spawnedTeam),
|
|
42
|
+
recentDirectoriesTouched: s.recentDirectoriesTouched?.map(sanitizeForTerminal),
|
|
43
|
+
todos,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function readCachedPreviewDigest(session) {
|
|
47
|
+
if (!session.filePath)
|
|
48
|
+
return readArchivedSessionPreview(session.id);
|
|
49
|
+
let stamp;
|
|
50
|
+
try {
|
|
51
|
+
stamp = fs.statSync(session.filePath);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return readArchivedSessionPreview(session.id);
|
|
55
|
+
}
|
|
56
|
+
return readSessionPreviewCache(session.id, { fileMtimeMs: stamp.mtimeMs, fileSize: stamp.size });
|
|
57
|
+
}
|
|
58
|
+
export function loadSessionPreviewDigest(session) {
|
|
59
|
+
if (!session.filePath || !fs.existsSync(session.filePath)) {
|
|
60
|
+
const archived = readArchivedSessionPreview(session.id);
|
|
61
|
+
if (archived) {
|
|
62
|
+
archived.plugins = getSessionPlugins(session.id);
|
|
63
|
+
return { digest: archived, events: [] };
|
|
64
|
+
}
|
|
65
|
+
return { events: [], error: 'no local transcript for this session (metadata-only entry, no archived digest)' };
|
|
66
|
+
}
|
|
67
|
+
const safe = sanitizeMeta(session);
|
|
68
|
+
let events = [];
|
|
69
|
+
let sourceStamp;
|
|
70
|
+
try {
|
|
71
|
+
sourceStamp = fs.statSync(session.filePath);
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
return { events, error: sanitizeForTerminal(err?.message ?? String(err)) };
|
|
75
|
+
}
|
|
76
|
+
let digest = readSessionPreviewCache(session.id, {
|
|
77
|
+
fileMtimeMs: sourceStamp.mtimeMs,
|
|
78
|
+
fileSize: sourceStamp.size,
|
|
79
|
+
});
|
|
80
|
+
if (!digest) {
|
|
81
|
+
// Large uncached transcripts use bounded tail plus bounded head, so a tail follow-up is never mislabeled as the first prompt.
|
|
82
|
+
if (sourceStamp.size > PREVIEW_DIGEST_MAX_PARSE_BYTES) {
|
|
83
|
+
events = readSessionTail(session.filePath, session.agent);
|
|
84
|
+
digest = buildSessionPreviewDigest(events, safe);
|
|
85
|
+
if (session.firstUserMessage) {
|
|
86
|
+
digest.firstUser = session.firstUserMessage;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
digest.firstUser = firstUserMessageFromEvents(readSessionHead(session.filePath, session.agent)) ?? '';
|
|
90
|
+
}
|
|
91
|
+
digest.partial = true;
|
|
92
|
+
digest.partialReason = `transcript is ${formatBytes(sourceStamp.size)}, over the ${formatBytes(PREVIEW_DIGEST_MAX_PARSE_BYTES)} bounded-parse limit for an uncached preview; digest reflects only the last ~128 KiB (tail) of the transcript, not the whole session`;
|
|
93
|
+
writeSessionPreviewCache({
|
|
94
|
+
id: session.id,
|
|
95
|
+
fileMtimeMs: sourceStamp.mtimeMs,
|
|
96
|
+
fileSize: sourceStamp.size,
|
|
97
|
+
preview: digest,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
try {
|
|
102
|
+
events = parseSession(session.filePath, session.agent, { includeInlineImages: true });
|
|
103
|
+
if (session.agent === 'claude')
|
|
104
|
+
materializeInlineImages(events, session.id);
|
|
105
|
+
digest = buildSessionPreviewDigest(events, safe);
|
|
106
|
+
writeSessionPreviewCache({
|
|
107
|
+
id: session.id,
|
|
108
|
+
fileMtimeMs: sourceStamp.mtimeMs,
|
|
109
|
+
fileSize: sourceStamp.size,
|
|
110
|
+
preview: digest,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
return { events, error: sanitizeForTerminal(err?.message ?? String(err)) };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
digest.plugins = getSessionPlugins(session.id);
|
|
119
|
+
applyLiveSessionFiles(digest, session);
|
|
120
|
+
return { digest, events };
|
|
121
|
+
}
|
|
122
|
+
function applyLiveSessionFiles(digest, session) {
|
|
123
|
+
if (session.agent === 'claude' && session.filePath) {
|
|
124
|
+
const children = previewSubAgentsFromFiles(session.filePath, digest.subAgents ?? []);
|
|
125
|
+
if (children) {
|
|
126
|
+
digest.subAgents = children;
|
|
127
|
+
digest.subAgentCount = children.length;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const known = new Set((digest.images ?? []).map(image => image.path));
|
|
131
|
+
const images = mergePreviewImages(digest.images ?? [], cachedAttachmentImages(session.id).filter(image => !known.has(image.path)));
|
|
132
|
+
if (images.length)
|
|
133
|
+
digest.images = images;
|
|
134
|
+
else
|
|
135
|
+
delete digest.images;
|
|
136
|
+
if (!digest.subAgents?.length)
|
|
137
|
+
delete digest.subAgents;
|
|
138
|
+
}
|
|
139
|
+
const SYSTEM_MESSAGE_PATTERNS = [
|
|
140
|
+
/^\s*<environment_context>/i,
|
|
141
|
+
/^\s*<system-reminder>/i,
|
|
142
|
+
/^\s*<permissions\s/i,
|
|
143
|
+
/^\s*<collaboration_mode>/i,
|
|
144
|
+
/^\s*<local-command-caveat>/i,
|
|
145
|
+
/^\s*# AGENTS\.md instructions for\b/i,
|
|
146
|
+
/^\s*<command-(message|name|args)>/i,
|
|
147
|
+
];
|
|
148
|
+
export function buildSessionPreviewDigest(events, session) {
|
|
149
|
+
let firstUser = '';
|
|
150
|
+
let lastAssistant = '';
|
|
151
|
+
const filesRead = new Set();
|
|
152
|
+
const toolCounts = {};
|
|
153
|
+
let toolCalls = 0;
|
|
154
|
+
let planFile = '';
|
|
155
|
+
let subAgentCount = 0;
|
|
156
|
+
let backgroundShellCount = harnessTracksBackgroundShells(session.agent)
|
|
157
|
+
? 0
|
|
158
|
+
: undefined;
|
|
159
|
+
const toolTags = new Set();
|
|
160
|
+
const knownToolUsage = session.usedBrowser !== undefined;
|
|
161
|
+
for (const event of events) {
|
|
162
|
+
if (event.type === 'message') {
|
|
163
|
+
if (event.role === 'user' && !event._synthetic && !firstUser && event.content) {
|
|
164
|
+
if (!SYSTEM_MESSAGE_PATTERNS.some(p => p.test(event.content))) {
|
|
165
|
+
firstUser = event.content;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (event.role === 'assistant' && event.content) {
|
|
169
|
+
lastAssistant = event.content;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else if (event.type === 'tool_use' && !event._local) {
|
|
173
|
+
const tool = event.tool || '';
|
|
174
|
+
const command = event.command || '';
|
|
175
|
+
if (!knownToolUsage) {
|
|
176
|
+
for (const tag of classifySessionTool(tool, command))
|
|
177
|
+
toolTags.add(tag);
|
|
178
|
+
}
|
|
179
|
+
if (isSubAgentTool(tool, command))
|
|
180
|
+
subAgentCount++;
|
|
181
|
+
if (backgroundShellCount !== undefined && isBackgroundShellStart(event))
|
|
182
|
+
backgroundShellCount++;
|
|
183
|
+
const p = event.path || event.args?.file_path || event.args?.path || '';
|
|
184
|
+
if (['Read', 'read_file', 'view_file', 'cat_file', 'get_file'].includes(tool) && p) {
|
|
185
|
+
filesRead.add(p);
|
|
186
|
+
}
|
|
187
|
+
if (!planFile && p && /\/plans\/[^/]+\.md$/.test(p)) {
|
|
188
|
+
planFile = p;
|
|
189
|
+
}
|
|
190
|
+
if (tool)
|
|
191
|
+
toolCounts[tool] = (toolCounts[tool] ?? 0) + 1;
|
|
192
|
+
toolCalls++;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (session.usedBrowser)
|
|
196
|
+
toolTags.add('browser');
|
|
197
|
+
if (session.usedComputer)
|
|
198
|
+
toolTags.add('computer');
|
|
199
|
+
const todos = extractTodoProgressFromEvents(events) ?? session.todos;
|
|
200
|
+
const changes = classifyFileChanges(events);
|
|
201
|
+
const chg = changeCounts(changes);
|
|
202
|
+
const errorEvents = events.filter(e => e.type === 'error');
|
|
203
|
+
const subAgents = previewSubAgentsFromEvents(events, isSubAgentTool);
|
|
204
|
+
const producedArtifacts = inferSessionState(events, { cwd: session.cwd }).artifacts ?? [];
|
|
205
|
+
const images = previewImagesFromEvents(events, changes, session.cwd);
|
|
206
|
+
return {
|
|
207
|
+
schemaVersion: 1,
|
|
208
|
+
firstUser,
|
|
209
|
+
lastAssistant,
|
|
210
|
+
filesRead: filesRead.size,
|
|
211
|
+
toolCalls,
|
|
212
|
+
planFile,
|
|
213
|
+
todos,
|
|
214
|
+
subAgentCount,
|
|
215
|
+
...(subAgents.length ? { subAgents } : {}),
|
|
216
|
+
...(images.length ? { images } : {}),
|
|
217
|
+
backgroundShellCount,
|
|
218
|
+
toolTags: [...toolTags],
|
|
219
|
+
changes: chg,
|
|
220
|
+
changedFiles: changes.slice(0, CHANGED_FILES_MAX),
|
|
221
|
+
dirs: directoriesTouched(session, events, changes),
|
|
222
|
+
repos: extractRepos(events, session.cwd),
|
|
223
|
+
artifacts: extractArtifacts(changes),
|
|
224
|
+
...(producedArtifacts.length ? { producedArtifacts } : {}),
|
|
225
|
+
skills: extractSkills(events),
|
|
226
|
+
plugins: getSessionPlugins(session.id),
|
|
227
|
+
hooks: extractHooks(events),
|
|
228
|
+
links: extractLinks(events),
|
|
229
|
+
errorCount: errorEvents.length,
|
|
230
|
+
firstError: errorEvents[0]?.tool,
|
|
231
|
+
toolHistogram: toolHistogram(toolCounts, 4),
|
|
232
|
+
test: detectTestResult(events),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function classifySessionTool(tool, command) {
|
|
236
|
+
const toolName = tool.toLowerCase();
|
|
237
|
+
const commandUses = (surface) => (new RegExp(`\\b(?:agents|ag)\\b[^\\n;&|]*\\b${surface}\\b`).test(command.toLowerCase()));
|
|
238
|
+
const tags = [];
|
|
239
|
+
if (/browser|webfetch|websearch/.test(toolName) || commandUses('browser'))
|
|
240
|
+
tags.push('browser');
|
|
241
|
+
if (/computer/.test(toolName) || commandUses('computer'))
|
|
242
|
+
tags.push('computer');
|
|
243
|
+
return tags;
|
|
244
|
+
}
|
|
245
|
+
function directoriesTouched(session, events, changes) {
|
|
246
|
+
const fromMeta = session.recentDirectoriesTouched;
|
|
247
|
+
if (Array.isArray(fromMeta) && fromMeta.length > 0) {
|
|
248
|
+
const seen = new Set();
|
|
249
|
+
for (const raw of fromMeta) {
|
|
250
|
+
const dir = relativizeDir(sanitizeForTerminal(String(raw).trim()), session.cwd);
|
|
251
|
+
if (dir)
|
|
252
|
+
seen.add(dir);
|
|
253
|
+
if (seen.size >= DIRS_TOUCHED_MAX)
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
if (seen.size > 0)
|
|
257
|
+
return [...seen];
|
|
258
|
+
}
|
|
259
|
+
const counts = new Map();
|
|
260
|
+
const bump = (raw) => {
|
|
261
|
+
const dir = relativizeDir(raw, session.cwd);
|
|
262
|
+
if (!dir)
|
|
263
|
+
return;
|
|
264
|
+
counts.set(dir, (counts.get(dir) ?? 0) + 1);
|
|
265
|
+
};
|
|
266
|
+
for (const ch of changes)
|
|
267
|
+
bump(ch.path);
|
|
268
|
+
for (const event of events) {
|
|
269
|
+
if (event.type !== 'tool_use' || event._local)
|
|
270
|
+
continue;
|
|
271
|
+
const p = event.path || event.args?.file_path || event.args?.path || '';
|
|
272
|
+
if (p)
|
|
273
|
+
bump(p);
|
|
274
|
+
}
|
|
275
|
+
return [...counts.entries()]
|
|
276
|
+
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
277
|
+
.map(([d]) => d)
|
|
278
|
+
.slice(0, DIRS_TOUCHED_MAX);
|
|
279
|
+
}
|
|
280
|
+
function encodeClaudeSlug(absPath) {
|
|
281
|
+
return absPath.replace(/[/.]/g, '-');
|
|
282
|
+
}
|
|
283
|
+
const SLUG_WORKTREE_RE = /--agents-worktrees-(.+)$/;
|
|
284
|
+
export function relativizeDir(filePath, cwd) {
|
|
285
|
+
const norm = filePath.replace(/\\/g, '/');
|
|
286
|
+
if (!norm || norm.includes('node_modules') || norm.includes('/.git/') || norm.includes('/plans/')) {
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
const normBase = cwd?.replace(/\\/g, '/').replace(/\/$/, '');
|
|
290
|
+
const underCwd = normBase && (norm === normBase || norm.startsWith(normBase + '/'));
|
|
291
|
+
if (!underCwd && (norm.includes('/.agents/.history/') || /\/\.agents\/worktrees(\/[^/]+)?\/?$/.test(norm))) {
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
let dir = path.posix.dirname(norm);
|
|
295
|
+
if (dir.startsWith('-')) {
|
|
296
|
+
const slash = dir.indexOf('/');
|
|
297
|
+
const slug = slash === -1 ? dir : dir.slice(0, slash);
|
|
298
|
+
if (cwd) {
|
|
299
|
+
const cwdSlug = encodeClaudeSlug(cwd.replace(/\\/g, '/').replace(/\/$/, ''));
|
|
300
|
+
if (slug === cwdSlug || slug.startsWith(cwdSlug + '-'))
|
|
301
|
+
return undefined;
|
|
302
|
+
}
|
|
303
|
+
const wtSlug = slug.match(SLUG_WORKTREE_RE);
|
|
304
|
+
if (wtSlug)
|
|
305
|
+
return `⧉ ${wtSlug[1]}`;
|
|
306
|
+
const segs = slug.split('-').filter(Boolean);
|
|
307
|
+
return segs.length ? segs[segs.length - 1] : undefined;
|
|
308
|
+
}
|
|
309
|
+
if (cwd) {
|
|
310
|
+
const base = cwd.replace(/\\/g, '/').replace(/\/$/, '');
|
|
311
|
+
if (dir === base)
|
|
312
|
+
return '.';
|
|
313
|
+
if (dir.startsWith(base + '/'))
|
|
314
|
+
return dir.slice(base.length + 1);
|
|
315
|
+
}
|
|
316
|
+
const wt = dir.match(WORKTREE_RE);
|
|
317
|
+
if (wt) {
|
|
318
|
+
const after = dir.slice(dir.indexOf(wt[0]) + wt[0].length).replace(/^\//, '');
|
|
319
|
+
return after ? `⧉ ${wt[1]}/${after}` : `⧉ ${wt[1]}`;
|
|
320
|
+
}
|
|
321
|
+
const home = (process.env.HOME || '').replace(/\\/g, '/');
|
|
322
|
+
if (home && dir.startsWith(home + '/'))
|
|
323
|
+
dir = '~' + dir.slice(home.length);
|
|
324
|
+
const parts = dir.split('/').filter(Boolean);
|
|
325
|
+
if (parts.length > 3 && dir.startsWith('/'))
|
|
326
|
+
dir = parts.slice(-3).join('/');
|
|
327
|
+
return dir || undefined;
|
|
328
|
+
}
|
|
@@ -88,7 +88,7 @@ export class SessionProjection {
|
|
|
88
88
|
...chosen, rowKey, sourceDevice: owner, machine: owner,
|
|
89
89
|
observerTerminals,
|
|
90
90
|
recovery: chosen.resumable && chosen.sessionId
|
|
91
|
-
? { command: 'agents', args: ['
|
|
91
|
+
? { command: 'agents', args: ['ps', 'focus', chosen.sessionId], ...(chosen.cwd ? { cwd: chosen.cwd } : {}) }
|
|
92
92
|
: null,
|
|
93
93
|
});
|
|
94
94
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type DeviceProfile } from '../../devices/registry.js';
|
|
2
|
+
import type { RemoteToolBin } from '../../hosts/remote-cmd.js';
|
|
2
3
|
import type { SessionMeta } from '@phnx-labs/sessions-cli/reader';
|
|
3
4
|
export declare function remoteListCommand(forwardedArgs: string[], os?: string): string;
|
|
4
5
|
export declare function parseRemoteList(stdout: string, machine: string): SessionMeta[];
|
|
@@ -23,6 +24,7 @@ export declare function isAutomaticSessionPeer(d: DeviceProfile, self: string):
|
|
|
23
24
|
interface GatherRemoteListOptions {
|
|
24
25
|
isDefinitive?: (session: SessionMeta, machine: string) => boolean;
|
|
25
26
|
timeoutMs?: number;
|
|
27
|
+
bin?: RemoteToolBin;
|
|
26
28
|
}
|
|
27
29
|
export declare function gatherRemoteList(forwardedArgs: string[], hosts?: string[], opts?: GatherRemoteListOptions): Promise<RemoteListResult>;
|
|
28
30
|
export declare function resolvePeerTarget(machine: string): Promise<{
|
|
@@ -39,7 +41,8 @@ export type PeerPreviewEnvelopeResult = {
|
|
|
39
41
|
};
|
|
40
42
|
export declare function fetchPeerPreviewEnvelope(sessionId: string, machine: string, timeoutMs?: number): Promise<PeerPreviewEnvelopeResult>;
|
|
41
43
|
export declare function parsePeerPreviewDigest(parsed: unknown): unknown | undefined;
|
|
42
|
-
export
|
|
44
|
+
export type PeerHopOutcome = 'ok' | 'unreachable' | 'failed';
|
|
45
|
+
export declare function peerHopOutcome(code: number | null, hostAnswers: () => boolean, oneShot?: boolean): PeerHopOutcome;
|
|
43
46
|
export declare function peerAnswers(target: string): boolean;
|
|
44
47
|
export declare function peerHopCloseNotice(opts: {
|
|
45
48
|
tty?: boolean;
|
|
@@ -50,7 +53,7 @@ export declare function runOnPeer(args: string[], machine: string, opts?: {
|
|
|
50
53
|
tty?: boolean;
|
|
51
54
|
env?: Record<string, string>;
|
|
52
55
|
sessionId?: string;
|
|
53
|
-
}): Promise<
|
|
56
|
+
}): Promise<PeerHopOutcome | 'no-target'>;
|
|
54
57
|
export declare function hostToken(h: string): string;
|
|
55
58
|
export declare function shouldIncludeLocal(hosts: string[] | undefined, self: string): boolean;
|
|
56
59
|
export declare function remoteHostsToDial(hosts: string[] | undefined, self: string): string[] | undefined;
|
|
@@ -3,6 +3,7 @@ import chalk from 'chalk';
|
|
|
3
3
|
import { SSH_OPTS, controlOpts, sshExec, assertValidSshTarget, shellQuote, SSH_CONN_FAILURE_CODE, REMOTE_STDOUT_MAX_BYTES, RemoteUtf8Accumulator, } from '../../ssh-exec.js';
|
|
4
4
|
import { connectionEndedNotice } from '../../hosts/reconnect.js';
|
|
5
5
|
import { sshTargetFor } from '../../devices/connect.js';
|
|
6
|
+
import { resolveDeviceProfile } from '../../devices/resolve-profile.js';
|
|
6
7
|
import { loadDevices, isDialableDevice } from '../../devices/registry.js';
|
|
7
8
|
import { remoteShellFor, buildWindowsAgentsCommand, stripClixml } from '../../hosts/remote-cmd.js';
|
|
8
9
|
import { gatherRemoteAgentsJson } from '../../remote-agents-json.js';
|
|
@@ -108,12 +109,14 @@ export function isAutomaticSessionPeer(d, self) {
|
|
|
108
109
|
return false;
|
|
109
110
|
if (normalizeHost(d.name) === self)
|
|
110
111
|
return false;
|
|
111
|
-
|
|
112
|
+
const platform = resolveDeviceProfile(d).platform;
|
|
113
|
+
return platform === 'windows' || platform === 'linux' || platform === 'macos';
|
|
112
114
|
}
|
|
113
115
|
export async function gatherRemoteList(forwardedArgs, hosts, opts) {
|
|
114
|
-
const safeResolver = forwardedArgs
|
|
116
|
+
const safeResolver = forwardedArgs[0] === 'ps' && forwardedArgs[1] === 'resolve';
|
|
115
117
|
const result = await gatherRemoteAgentsJson({
|
|
116
118
|
args: forwardedArgs,
|
|
119
|
+
bin: opts?.bin,
|
|
117
120
|
noFanoutEnv: NO_FANOUT_ENV,
|
|
118
121
|
hosts,
|
|
119
122
|
timeoutMs: opts?.timeoutMs,
|
|
@@ -142,7 +145,7 @@ export async function resolvePeerTarget(machine) {
|
|
|
142
145
|
if (normalizeHost(d.name) !== machine)
|
|
143
146
|
continue;
|
|
144
147
|
try {
|
|
145
|
-
return { target: sshTargetFor(d), os: d.platform };
|
|
148
|
+
return { target: sshTargetFor(d), os: resolveDeviceProfile(d).platform };
|
|
146
149
|
}
|
|
147
150
|
catch {
|
|
148
151
|
return undefined;
|
|
@@ -161,7 +164,7 @@ export async function fetchPeerPreviewEnvelope(sessionId, machine, timeoutMs = P
|
|
|
161
164
|
const peer = await resolvePeerTarget(machine);
|
|
162
165
|
if (!peer)
|
|
163
166
|
return { ok: false, reason: 'no-target' };
|
|
164
|
-
const cmd = remoteListCommand(['
|
|
167
|
+
const cmd = remoteListCommand(['ps', 'preview', sessionId, '--local', '--json'], peer.os);
|
|
165
168
|
const capture = await sshCapture(peer.target, cmd, timeoutMs);
|
|
166
169
|
if (capture.code !== 0)
|
|
167
170
|
return { ok: false, reason: 'unreachable' };
|
|
@@ -181,12 +184,16 @@ export function parsePeerPreviewDigest(parsed) {
|
|
|
181
184
|
return preview;
|
|
182
185
|
}
|
|
183
186
|
const PEER_PROBE_TIMEOUT_MS = 15_000;
|
|
184
|
-
export function peerHopOutcome(code, hostAnswers) {
|
|
187
|
+
export function peerHopOutcome(code, hostAnswers, oneShot = false) {
|
|
185
188
|
if (code === null)
|
|
186
189
|
return 'unreachable';
|
|
187
|
-
if (code
|
|
190
|
+
if (code === 0)
|
|
188
191
|
return 'ok';
|
|
189
|
-
|
|
192
|
+
if (code !== SSH_CONN_FAILURE_CODE)
|
|
193
|
+
return oneShot ? 'failed' : 'ok';
|
|
194
|
+
if (!hostAnswers())
|
|
195
|
+
return 'unreachable';
|
|
196
|
+
return oneShot ? 'failed' : 'ok';
|
|
190
197
|
}
|
|
191
198
|
export function peerAnswers(target) {
|
|
192
199
|
return sshExec(target, 'true', { multiplex: false, timeoutMs: PEER_PROBE_TIMEOUT_MS }).code === 0;
|
|
@@ -260,7 +267,7 @@ export async function runOnPeer(args, machine, opts = {}) {
|
|
|
260
267
|
const notice = peerHopCloseNotice(opts, machine, code);
|
|
261
268
|
if (notice)
|
|
262
269
|
process.stderr.write(notice);
|
|
263
|
-
return peerHopOutcome(code, () => peerAnswers(peer.target));
|
|
270
|
+
return peerHopOutcome(code, () => peerAnswers(peer.target), !opts.tty);
|
|
264
271
|
}
|
|
265
272
|
export function hostToken(h) {
|
|
266
273
|
return normalizeHost(h.split('@').pop() || h);
|
|
@@ -82,6 +82,7 @@ export declare class SessionWatchState {
|
|
|
82
82
|
reset(scope: string, sourceRows: ActiveSession[], indexedRows?: SessionMeta[]): SessionWatchEnvelope;
|
|
83
83
|
update(scope: string, sourceRows: ActiveSession[]): SessionWatchEnvelope[];
|
|
84
84
|
patch(scope: string, upserts: ActiveSession[], removes: string[]): SessionWatchEnvelope[];
|
|
85
|
+
refreshPrevious(scope: string, session: SessionMeta, accounts?: import("../../account-registry.js").NativeAccount[]): SessionWatchEnvelope | undefined;
|
|
85
86
|
scope(scope: string, status: SessionWatchScopeStatus, reason?: string): SessionWatchEnvelope;
|
|
86
87
|
heartbeat(scope: string, capturedAt?: number): SessionWatchEnvelope;
|
|
87
88
|
}
|
|
@@ -97,6 +98,7 @@ export interface WatchLocalOptions {
|
|
|
97
98
|
journalPollMs?: number;
|
|
98
99
|
}
|
|
99
100
|
export declare function readPreviousSessionsForWatch(scope: string): SessionMeta[];
|
|
101
|
+
export declare function previewDigestBuildsForTest(): number;
|
|
100
102
|
export declare function watchLocalSessions(options: WatchLocalOptions): Promise<void>;
|
|
101
103
|
interface WatchFleetOptions {
|
|
102
104
|
signal: AbortSignal;
|
|
@@ -4,13 +4,16 @@ import { createHash, randomUUID } from 'node:crypto';
|
|
|
4
4
|
import * as fs from 'node:fs';
|
|
5
5
|
import * as path from 'node:path';
|
|
6
6
|
import { loadDevices, isDialableDevice } from '../../devices/registry.js';
|
|
7
|
+
import { resolveDeviceProfile } from '../../devices/resolve-profile.js';
|
|
7
8
|
import { machineId, normalizeHost } from '../../machine-id.js';
|
|
8
9
|
import { shellQuote } from '../../ssh-exec.js';
|
|
9
10
|
import { streamFromPeer } from './peer-stream.js';
|
|
10
11
|
import { buildWindowsAgentsCommand, remoteShellFor } from '../../hosts/remote-cmd.js';
|
|
11
|
-
import { isReapableOrphan, sessionAccountLabel } from '../active.js';
|
|
12
|
+
import { artifactKind, deriveImportantMessage, deriveSessionRecap, isReapableOrphan, sessionAccountLabel } from '../active.js';
|
|
13
|
+
import { loadSessionPreviewDigest, readCachedPreviewDigest } from '../preview-digest.js';
|
|
14
|
+
import { indexArtifactSidecars, mergeArtifacts } from '@phnx-labs/sessions-cli/reader';
|
|
12
15
|
import { listNativeAccounts } from '../../account-registry.js';
|
|
13
|
-
import { readMeta } from '../../state.js';
|
|
16
|
+
import { getUserAgentsDir, readMeta } from '../../state.js';
|
|
14
17
|
import { querySessions, readSessionSummaryAny, readSessionTimelineAny } from '../db.js';
|
|
15
18
|
import { linearIssueUrl } from '@phnx-labs/sessions-cli/reader';
|
|
16
19
|
import { sessionAgentSupportsResume } from '../recovery.js';
|
|
@@ -43,7 +46,7 @@ export function toSessionWatchRow(scope, row) {
|
|
|
43
46
|
unwatched: !viewingIn,
|
|
44
47
|
viewingIn,
|
|
45
48
|
recovery: resumable
|
|
46
|
-
? { command: 'agents', args: ['
|
|
49
|
+
? { command: 'agents', args: ['ps', 'focus', row.sessionId], ...(row.cwd ? { cwd: row.cwd } : {}) }
|
|
47
50
|
: null,
|
|
48
51
|
};
|
|
49
52
|
}
|
|
@@ -57,6 +60,28 @@ function previousSessionWatchRowKey(scope, sessionId) {
|
|
|
57
60
|
function previousRowTitle(session, foldedHeadline) {
|
|
58
61
|
return session.label || session.generatedTitle || foldedHeadline || session.topic || undefined;
|
|
59
62
|
}
|
|
63
|
+
function previousRowCard(session, request, attachments) {
|
|
64
|
+
const digest = readCachedPreviewDigest(session);
|
|
65
|
+
const recap = deriveSessionRecap({
|
|
66
|
+
...session,
|
|
67
|
+
tail: digest?.lastAssistant ? [digest.lastAssistant] : undefined,
|
|
68
|
+
attachments,
|
|
69
|
+
request,
|
|
70
|
+
});
|
|
71
|
+
const sidecars = indexArtifactSidecars(path.join(getUserAgentsDir(), 'artifacts')).get(session.id) ?? [];
|
|
72
|
+
const artifacts = mergeArtifacts(digest?.producedArtifacts ?? [], sidecars).map((artifact) => ({ ...artifact, kind: artifactKind(artifact.path) }));
|
|
73
|
+
const todos = digest?.todos ?? session.todos;
|
|
74
|
+
const importantMessage = deriveImportantMessage({ status: 'closed', lastAgentLine: recap.lastAgentLine });
|
|
75
|
+
return {
|
|
76
|
+
...(recap.lastAgentLine ? { lastAgentLine: recap.lastAgentLine } : {}),
|
|
77
|
+
...(recap.request ? { request: recap.request } : {}),
|
|
78
|
+
...(recap.userPromptClean ? { userPromptClean: recap.userPromptClean } : {}),
|
|
79
|
+
...(recap.userPromptKind ? { userPromptKind: recap.userPromptKind } : {}),
|
|
80
|
+
...(todos?.total ? { todos } : {}),
|
|
81
|
+
...(artifacts.length ? { artifacts } : {}),
|
|
82
|
+
...(importantMessage ? { importantMessage } : {}),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
60
85
|
export function toPreviousSessionWatchRow(scope, session, accounts = listNativeAccounts(readMeta())) {
|
|
61
86
|
const resumable = sessionAgentSupportsResume(session.agent);
|
|
62
87
|
const sourceDevice = normalizeHost(session.machine ?? scope);
|
|
@@ -76,6 +101,7 @@ export function toPreviousSessionWatchRow(scope, session, accounts = listNativeA
|
|
|
76
101
|
const folded = readSessionTimelineAny(session.id);
|
|
77
102
|
const model = folded?.model ?? session.model;
|
|
78
103
|
const title = previousRowTitle(session, folded?.request?.headline);
|
|
104
|
+
const card = previousRowCard(session, folded?.request, folded?.attachments);
|
|
79
105
|
return {
|
|
80
106
|
context: 'recent',
|
|
81
107
|
kind: session.agent,
|
|
@@ -105,7 +131,7 @@ export function toPreviousSessionWatchRow(scope, session, accounts = listNativeA
|
|
|
105
131
|
...(summary?.checkpoints ? { checkpoints: summary.checkpoints } : {}),
|
|
106
132
|
...(summary?.summaryChecklist ? { summaryChecklist: summary.summaryChecklist } : {}),
|
|
107
133
|
summaryState: resolveStreamSummaryState(summary?.summaryState),
|
|
108
|
-
...
|
|
134
|
+
...card,
|
|
109
135
|
...(folded?.timeline ? { timeline: folded.timeline } : {}),
|
|
110
136
|
...(folded?.files ? { files: folded.files } : {}),
|
|
111
137
|
...(model ? { model } : {}),
|
|
@@ -126,14 +152,13 @@ export function toPreviousSessionWatchRow(scope, session, accounts = listNativeA
|
|
|
126
152
|
unwatched: true,
|
|
127
153
|
viewingIn: null,
|
|
128
154
|
recovery: resumable
|
|
129
|
-
? { command: 'agents', args: ['
|
|
155
|
+
? { command: 'agents', args: ['ps', 'focus', session.id], ...(session.cwd ? { cwd: session.cwd } : {}) }
|
|
130
156
|
: null,
|
|
131
157
|
};
|
|
132
158
|
}
|
|
133
159
|
function demoteWatchRow(scope, row) {
|
|
134
160
|
if (!row.sessionId || row.rowKey === previousSessionWatchRowKey(scope, row.sessionId))
|
|
135
161
|
return null;
|
|
136
|
-
const sourceDevice = row.sourceDevice || scope;
|
|
137
162
|
return {
|
|
138
163
|
...row,
|
|
139
164
|
context: 'recent',
|
|
@@ -145,7 +170,7 @@ function demoteWatchRow(scope, row) {
|
|
|
145
170
|
unwatched: true,
|
|
146
171
|
viewingIn: null,
|
|
147
172
|
recovery: row.resumable
|
|
148
|
-
? { command: 'agents', args: ['
|
|
173
|
+
? { command: 'agents', args: ['ps', 'focus', row.sessionId], ...(row.cwd ? { cwd: row.cwd } : {}) }
|
|
149
174
|
: null,
|
|
150
175
|
};
|
|
151
176
|
}
|
|
@@ -273,6 +298,18 @@ export class SessionWatchState {
|
|
|
273
298
|
this.rows.set(scope, current);
|
|
274
299
|
return events;
|
|
275
300
|
}
|
|
301
|
+
refreshPrevious(scope, session, accounts = listNativeAccounts(readMeta())) {
|
|
302
|
+
const rows = this.rows.get(scope);
|
|
303
|
+
const rowKey = previousSessionWatchRowKey(scope, session.id);
|
|
304
|
+
const current = rows?.get(rowKey);
|
|
305
|
+
if (!rows || !current)
|
|
306
|
+
return undefined;
|
|
307
|
+
const row = toPreviousSessionWatchRow(scope, session, accounts);
|
|
308
|
+
if (sameRow(current, row))
|
|
309
|
+
return undefined;
|
|
310
|
+
rows.set(rowKey, row);
|
|
311
|
+
return { ...this.base('upsert'), scope, rowKey, row };
|
|
312
|
+
}
|
|
276
313
|
scope(scope, status, reason) {
|
|
277
314
|
return { ...this.base('scope'), scope, status, ...(reason ? { reason } : {}) };
|
|
278
315
|
}
|
|
@@ -295,6 +332,47 @@ export function readPreviousSessionsForWatch(scope) {
|
|
|
295
332
|
return [];
|
|
296
333
|
}
|
|
297
334
|
}
|
|
335
|
+
const failedPreviewDigests = new Map();
|
|
336
|
+
let previewDigestBuilds = 0;
|
|
337
|
+
export function previewDigestBuildsForTest() {
|
|
338
|
+
return previewDigestBuilds;
|
|
339
|
+
}
|
|
340
|
+
function transcriptStamp(session) {
|
|
341
|
+
try {
|
|
342
|
+
const stat = fs.statSync(session.filePath);
|
|
343
|
+
return `${stat.mtimeMs}:${stat.size}`;
|
|
344
|
+
}
|
|
345
|
+
catch {
|
|
346
|
+
return 'missing';
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
async function fillPreviousCards(state, options, sessions) {
|
|
350
|
+
const accounts = sessions.length ? listNativeAccounts(readMeta()) : [];
|
|
351
|
+
for (const session of sessions) {
|
|
352
|
+
if (options.signal.aborted)
|
|
353
|
+
return;
|
|
354
|
+
const stamp = transcriptStamp(session);
|
|
355
|
+
if (failedPreviewDigests.get(session.id) === stamp || readCachedPreviewDigest(session))
|
|
356
|
+
continue;
|
|
357
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
358
|
+
if (options.signal.aborted)
|
|
359
|
+
return;
|
|
360
|
+
try {
|
|
361
|
+
previewDigestBuilds++;
|
|
362
|
+
if (!loadSessionPreviewDigest(session).digest) {
|
|
363
|
+
failedPreviewDigests.set(session.id, stamp);
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
failedPreviewDigests.delete(session.id);
|
|
367
|
+
const event = state.refreshPrevious(options.scope, session, accounts);
|
|
368
|
+
if (event)
|
|
369
|
+
options.emit(event);
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
failedPreviewDigests.set(session.id, stamp);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
298
376
|
export async function watchLocalSessions(options) {
|
|
299
377
|
const state = new SessionWatchState();
|
|
300
378
|
const readCache = options.readCache ?? readActiveSessionsCache;
|
|
@@ -307,10 +385,12 @@ export async function watchLocalSessions(options) {
|
|
|
307
385
|
}
|
|
308
386
|
catch { }
|
|
309
387
|
const initial = readCache('local');
|
|
310
|
-
|
|
388
|
+
const previous = readPrevious(options.scope);
|
|
389
|
+
options.emit(state.reset(options.scope, initial?.sessions ?? [], previous));
|
|
311
390
|
options.emit(state.scope(options.scope, initial ? 'available' : 'unavailable', initial ? undefined : 'awaiting publisher'));
|
|
312
391
|
if (options.signal.aborted)
|
|
313
392
|
return;
|
|
393
|
+
void fillPreviousCards(state, options, previous);
|
|
314
394
|
noteActiveSessionsJournalReader();
|
|
315
395
|
await new Promise((resolve) => {
|
|
316
396
|
let partial = '';
|
|
@@ -370,7 +450,7 @@ export async function watchLocalSessions(options) {
|
|
|
370
450
|
});
|
|
371
451
|
}
|
|
372
452
|
function remoteWatchCommand(os) {
|
|
373
|
-
const args = ['
|
|
453
|
+
const args = ['ps', 'watch', '--json', '--local'];
|
|
374
454
|
return remoteShellFor(os) === 'powershell'
|
|
375
455
|
? buildWindowsAgentsCommand({ args })
|
|
376
456
|
: `bash -lc ${shellQuote(`agents ${args.map(shellQuote).join(' ')}`)}`;
|
|
@@ -389,7 +469,7 @@ export async function watchFleetSessions(options) {
|
|
|
389
469
|
return;
|
|
390
470
|
}
|
|
391
471
|
const self = machineId();
|
|
392
|
-
const peers = Object.values(devices).filter((device) => isDialableDevice(device)
|
|
472
|
+
const peers = Object.values(devices).map(resolveDeviceProfile).filter((device) => isDialableDevice(device)
|
|
393
473
|
&& normalizeHost(device.name) !== self
|
|
394
474
|
&& ['windows', 'linux', 'macos'].includes(device.platform));
|
|
395
475
|
const peerTasks = peers.map(async (device) => {
|
|
@@ -27,7 +27,7 @@ export function parseRemoteActive(stdout, machine) {
|
|
|
27
27
|
}
|
|
28
28
|
export async function gatherRemoteActive(hosts, opts) {
|
|
29
29
|
const result = await gatherRemoteAgentsJson({
|
|
30
|
-
args: ['
|
|
30
|
+
args: ['ps', '--local', '--json'],
|
|
31
31
|
noFanoutEnv: NO_FANOUT_ENV,
|
|
32
32
|
hosts,
|
|
33
33
|
parse: parseRemoteActive,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { SessionMeta } from '@phnx-labs/sessions-cli/reader';
|
|
2
|
-
export declare function buildCanonicalResumeCommand(sessionId: string): string[];
|
|
3
2
|
export declare function resumeSessionInPlace(session: SessionMeta): Promise<void>;
|
|
4
3
|
export declare function buildSessionRecoveryCommand(session: Pick<SessionMeta, 'id'>, portable?: boolean): string[];
|
|
5
4
|
export declare function resumeSpawnInvocation(cmd: string[], platform?: NodeJS.Platform): {
|