@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
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
2
|
import chalk from 'chalk';
|
|
4
|
-
import { truncate, humanDuration
|
|
3
|
+
import { truncate, humanDuration } from '../lib/format.js';
|
|
5
4
|
import { sessionDisplayAgent } from '@phnx-labs/sessions-cli/reader';
|
|
6
|
-
import { fetchPeerPreviewDigest } from '../lib/session/remote-list.js';
|
|
7
|
-
import {
|
|
8
|
-
import { readSessionTail, readSessionHead } from '@phnx-labs/sessions-cli/reader';
|
|
5
|
+
import { fetchPeerPreviewDigest, resolvePeerTarget, runOnPeer } from '../lib/session/remote-list.js';
|
|
6
|
+
import { sanitizeForTerminal } from '@phnx-labs/sessions-cli/reader';
|
|
9
7
|
import { safeTeamText } from '@phnx-labs/sessions-cli/reader';
|
|
10
|
-
import { cleanSessionPrompt, extractSessionTopic, isSyntheticUserMessage
|
|
8
|
+
import { cleanSessionPrompt, extractSessionTopic, isSyntheticUserMessage } from '@phnx-labs/sessions-cli/reader';
|
|
11
9
|
import { linkPath, linkUrl, relativeToCwd, shortenModel } from '@phnx-labs/sessions-cli/reader';
|
|
12
10
|
import { linearIssueUrl } from '@phnx-labs/sessions-cli/reader';
|
|
13
|
-
import { extractTodoProgress, WORKTREE_RE } from '@phnx-labs/sessions-cli/reader';
|
|
14
11
|
import { renderMarkdown } from '../lib/markdown.js';
|
|
15
12
|
import { wrapToWidth } from '../lib/wrap.js';
|
|
16
13
|
import { terminalWidth, stringWidth } from '../lib/session/width.js';
|
|
17
14
|
import { itemPicker } from '../lib/picker.js';
|
|
18
15
|
import { createMemoryCache } from '../lib/memory-cache.js';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { getSessionPlugins, readSessionPreviewCache, writeSessionPreviewCache, readSessionContent, readArchivedSessionPreview } from '../lib/session/db.js';
|
|
16
|
+
import { readSessionContent } from '../lib/session/db.js';
|
|
17
|
+
import { CHANGED_FILES_MAX, DIRS_TOUCHED_MAX, loadSessionPreviewDigest, sanitizeMeta } from '../lib/session/preview-digest.js';
|
|
22
18
|
import { machineId } from '../lib/session/sync/config.js';
|
|
23
19
|
import { isPromptCancelled } from '../lib/format.js';
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
20
|
+
import { sessionOwnerDevice } from '../lib/session/resume-owner.js';
|
|
21
|
+
import { sessionRecoveryRunArgs } from '../lib/session/recovery.js';
|
|
26
22
|
import { resumeSessionInPlace } from '../lib/session/resume-command.js';
|
|
27
23
|
import { filterSessionsByQuery } from '../lib/session/selection.js';
|
|
28
24
|
import { formatPickerLabel, formatPickerTip, formatTeamHiddenFooter, formatTodoCompact, pickerColumnsFor, renderSession, } from '../lib/session/presentation.js';
|
|
@@ -43,42 +39,6 @@ export function githubRepoUrlFromCwd(cwd) {
|
|
|
43
39
|
const m = norm.match(/\/github\.com\/([^/]+\/[^/]+)/);
|
|
44
40
|
return m ? `https://github.com/${m[1]}` : undefined;
|
|
45
41
|
}
|
|
46
|
-
// Peer metadata is untrusted: bound its shape and strip terminal escapes before rendering.
|
|
47
|
-
function sanitizeMeta(s) {
|
|
48
|
-
const clean = (v) => (v == null ? v : sanitizeForTerminal(v));
|
|
49
|
-
const todos = s.todos
|
|
50
|
-
? {
|
|
51
|
-
...s.todos,
|
|
52
|
-
activeForm: clean(s.todos.activeForm),
|
|
53
|
-
items: s.todos.items.map((it) => ({
|
|
54
|
-
...it,
|
|
55
|
-
content: sanitizeForTerminal(it.content),
|
|
56
|
-
activeForm: clean(it.activeForm),
|
|
57
|
-
})),
|
|
58
|
-
}
|
|
59
|
-
: s.todos;
|
|
60
|
-
return {
|
|
61
|
-
...s,
|
|
62
|
-
id: sanitizeForTerminal(s.id),
|
|
63
|
-
shortId: sanitizeForTerminal(s.shortId),
|
|
64
|
-
filePath: sanitizeForTerminal(s.filePath),
|
|
65
|
-
cwd: clean(s.cwd),
|
|
66
|
-
project: clean(s.project),
|
|
67
|
-
gitBranch: clean(s.gitBranch),
|
|
68
|
-
version: clean(s.version),
|
|
69
|
-
account: clean(s.account),
|
|
70
|
-
topic: clean(s.topic),
|
|
71
|
-
firstUserMessage: clean(s.firstUserMessage),
|
|
72
|
-
label: clean(s.label),
|
|
73
|
-
generatedTitle: clean(s.generatedTitle),
|
|
74
|
-
ticketId: clean(s.ticketId),
|
|
75
|
-
prUrl: clean(s.prUrl),
|
|
76
|
-
plan: clean(s.plan),
|
|
77
|
-
spawnedTeam: clean(s.spawnedTeam),
|
|
78
|
-
recentDirectoriesTouched: s.recentDirectoriesTouched?.map(sanitizeForTerminal),
|
|
79
|
-
todos,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
42
|
const previewCache = createMemoryCache({
|
|
83
43
|
max: 256,
|
|
84
44
|
ttlMs: 5 * 60_000,
|
|
@@ -242,67 +202,6 @@ function previewCacheKey(session, remote) {
|
|
|
242
202
|
export function clearPreviewMemoryCacheForTest() {
|
|
243
203
|
previewCache.clear();
|
|
244
204
|
}
|
|
245
|
-
export function loadSessionPreviewDigest(session) {
|
|
246
|
-
if (!session.filePath || !fs.existsSync(session.filePath)) {
|
|
247
|
-
const archived = readArchivedSessionPreview(session.id);
|
|
248
|
-
if (archived) {
|
|
249
|
-
archived.plugins = getSessionPlugins(session.id);
|
|
250
|
-
return { digest: archived, events: [] };
|
|
251
|
-
}
|
|
252
|
-
return { events: [], error: 'no local transcript for this session (metadata-only entry, no archived digest)' };
|
|
253
|
-
}
|
|
254
|
-
const safe = sanitizeMeta(session);
|
|
255
|
-
let events = [];
|
|
256
|
-
let sourceStamp;
|
|
257
|
-
try {
|
|
258
|
-
sourceStamp = fs.statSync(session.filePath);
|
|
259
|
-
}
|
|
260
|
-
catch (err) {
|
|
261
|
-
return { events, error: sanitizeForTerminal(err?.message ?? String(err)) };
|
|
262
|
-
}
|
|
263
|
-
let digest = readSessionPreviewCache(session.id, {
|
|
264
|
-
fileMtimeMs: sourceStamp.mtimeMs,
|
|
265
|
-
fileSize: sourceStamp.size,
|
|
266
|
-
});
|
|
267
|
-
if (!digest) {
|
|
268
|
-
// Large uncached transcripts use bounded tail plus bounded head, so a tail follow-up is never mislabeled as the first prompt.
|
|
269
|
-
if (sourceStamp.size > PREVIEW_DIGEST_MAX_PARSE_BYTES) {
|
|
270
|
-
events = readSessionTail(session.filePath, session.agent);
|
|
271
|
-
digest = buildSessionPreviewDigest(events, safe);
|
|
272
|
-
if (session.firstUserMessage) {
|
|
273
|
-
digest.firstUser = session.firstUserMessage;
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
digest.firstUser = firstUserMessageFromEvents(readSessionHead(session.filePath, session.agent)) ?? '';
|
|
277
|
-
}
|
|
278
|
-
digest.partial = true;
|
|
279
|
-
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`;
|
|
280
|
-
writeSessionPreviewCache({
|
|
281
|
-
id: session.id,
|
|
282
|
-
fileMtimeMs: sourceStamp.mtimeMs,
|
|
283
|
-
fileSize: sourceStamp.size,
|
|
284
|
-
preview: digest,
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
try {
|
|
289
|
-
events = parseSession(session.filePath, session.agent);
|
|
290
|
-
digest = buildSessionPreviewDigest(events, safe);
|
|
291
|
-
writeSessionPreviewCache({
|
|
292
|
-
id: session.id,
|
|
293
|
-
fileMtimeMs: sourceStamp.mtimeMs,
|
|
294
|
-
fileSize: sourceStamp.size,
|
|
295
|
-
preview: digest,
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
catch (err) {
|
|
299
|
-
return { events, error: sanitizeForTerminal(err?.message ?? String(err)) };
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
digest.plugins = getSessionPlugins(session.id);
|
|
304
|
-
return { digest, events };
|
|
305
|
-
}
|
|
306
205
|
export function buildPreview(session) {
|
|
307
206
|
const remote = transcriptOnPeerOf(session);
|
|
308
207
|
const cacheKey = previewCacheKey(session, remote);
|
|
@@ -540,15 +439,6 @@ function formatTokens(n) {
|
|
|
540
439
|
const v = n / 1_000_000;
|
|
541
440
|
return (v >= 100 ? Math.round(v).toString() : v.toFixed(1).replace(/\.0$/, '')) + 'm';
|
|
542
441
|
}
|
|
543
|
-
const SYSTEM_MESSAGE_PATTERNS = [
|
|
544
|
-
/^\s*<environment_context>/i,
|
|
545
|
-
/^\s*<system-reminder>/i,
|
|
546
|
-
/^\s*<permissions\s/i,
|
|
547
|
-
/^\s*<collaboration_mode>/i,
|
|
548
|
-
/^\s*<local-command-caveat>/i,
|
|
549
|
-
/^\s*# AGENTS\.md instructions for\b/i,
|
|
550
|
-
/^\s*<command-(message|name|args)>/i,
|
|
551
|
-
];
|
|
552
442
|
function stripTags(text) {
|
|
553
443
|
let cleaned = text.replace(/<(system-reminder|environment_context|permissions[^>]*)>[\s\S]*?<\/\1>/gi, '');
|
|
554
444
|
cleaned = cleaned.replace(/<\/?[a-z_-]+[^>]*>/gi, '');
|
|
@@ -557,96 +447,6 @@ function stripTags(text) {
|
|
|
557
447
|
const LAST_RESPONSE_MAX_LINES = 15;
|
|
558
448
|
const LAST_RESPONSE_MAX_LINES_WITH_TODOS = 8;
|
|
559
449
|
const TODOS_MAX_ITEMS = 5;
|
|
560
|
-
const DIRS_TOUCHED_MAX = 5;
|
|
561
|
-
const CHANGED_FILES_MAX = 200;
|
|
562
|
-
const PREVIEW_DIGEST_MAX_PARSE_BYTES = 4 * 1024 * 1024;
|
|
563
|
-
export function buildSessionPreviewDigest(events, session) {
|
|
564
|
-
let firstUser = '';
|
|
565
|
-
let lastAssistant = '';
|
|
566
|
-
const filesRead = new Set();
|
|
567
|
-
const toolCounts = {};
|
|
568
|
-
let toolCalls = 0;
|
|
569
|
-
let planFile = '';
|
|
570
|
-
let latestTodos;
|
|
571
|
-
let subAgentCount = 0;
|
|
572
|
-
let backgroundShellCount = harnessTracksBackgroundShells(session.agent)
|
|
573
|
-
? 0
|
|
574
|
-
: undefined;
|
|
575
|
-
const toolTags = new Set();
|
|
576
|
-
const knownToolUsage = session.usedBrowser !== undefined;
|
|
577
|
-
for (const event of events) {
|
|
578
|
-
if (event.type === 'message') {
|
|
579
|
-
if (event.role === 'user' && !event._synthetic && !firstUser && event.content) {
|
|
580
|
-
if (!SYSTEM_MESSAGE_PATTERNS.some(p => p.test(event.content))) {
|
|
581
|
-
firstUser = event.content;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
if (event.role === 'assistant' && event.content) {
|
|
585
|
-
lastAssistant = event.content;
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
else if (event.type === 'tool_use' && !event._local) {
|
|
589
|
-
const tool = event.tool || '';
|
|
590
|
-
const command = event.command || '';
|
|
591
|
-
if (!knownToolUsage) {
|
|
592
|
-
for (const tag of classifySessionTool(tool, command))
|
|
593
|
-
toolTags.add(tag);
|
|
594
|
-
}
|
|
595
|
-
if (isSubAgentTool(tool, command))
|
|
596
|
-
subAgentCount++;
|
|
597
|
-
if (backgroundShellCount !== undefined && isBackgroundShellStart(event))
|
|
598
|
-
backgroundShellCount++;
|
|
599
|
-
const p = event.path || event.args?.file_path || event.args?.path || '';
|
|
600
|
-
if (['Read', 'read_file', 'view_file', 'cat_file', 'get_file'].includes(tool) && p) {
|
|
601
|
-
filesRead.add(p);
|
|
602
|
-
}
|
|
603
|
-
if (!planFile && p && /\/plans\/[^/]+\.md$/.test(p)) {
|
|
604
|
-
planFile = p;
|
|
605
|
-
}
|
|
606
|
-
if (SNAPSHOT_TODO_TOOLS.has(tool)) {
|
|
607
|
-
const progress = extractTodoProgress(event.args);
|
|
608
|
-
if (progress)
|
|
609
|
-
latestTodos = progress;
|
|
610
|
-
}
|
|
611
|
-
if (tool)
|
|
612
|
-
toolCounts[tool] = (toolCounts[tool] ?? 0) + 1;
|
|
613
|
-
toolCalls++;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
if (session.usedBrowser)
|
|
617
|
-
toolTags.add('browser');
|
|
618
|
-
if (session.usedComputer)
|
|
619
|
-
toolTags.add('computer');
|
|
620
|
-
const todos = latestTodos ?? session.todos;
|
|
621
|
-
const changes = classifyFileChanges(events);
|
|
622
|
-
const chg = changeCounts(changes);
|
|
623
|
-
const errorEvents = events.filter(e => e.type === 'error');
|
|
624
|
-
return {
|
|
625
|
-
schemaVersion: 1,
|
|
626
|
-
firstUser,
|
|
627
|
-
lastAssistant,
|
|
628
|
-
filesRead: filesRead.size,
|
|
629
|
-
toolCalls,
|
|
630
|
-
planFile,
|
|
631
|
-
todos,
|
|
632
|
-
subAgentCount,
|
|
633
|
-
backgroundShellCount,
|
|
634
|
-
toolTags: [...toolTags],
|
|
635
|
-
changes: chg,
|
|
636
|
-
changedFiles: changes.slice(0, CHANGED_FILES_MAX),
|
|
637
|
-
dirs: directoriesTouched(session, events, changes),
|
|
638
|
-
repos: extractRepos(events, session.cwd),
|
|
639
|
-
artifacts: extractArtifacts(changes),
|
|
640
|
-
skills: extractSkills(events),
|
|
641
|
-
plugins: getSessionPlugins(session.id),
|
|
642
|
-
hooks: extractHooks(events),
|
|
643
|
-
links: extractLinks(events),
|
|
644
|
-
errorCount: errorEvents.length,
|
|
645
|
-
firstError: errorEvents[0]?.tool,
|
|
646
|
-
toolHistogram: toolHistogram(toolCounts, 4),
|
|
647
|
-
test: detectTestResult(events),
|
|
648
|
-
};
|
|
649
|
-
}
|
|
650
450
|
const VERB_GUTTER = 9;
|
|
651
451
|
function verbLabel(v) {
|
|
652
452
|
return chalk.cyan(v.padEnd(VERB_GUTTER)) + ' ';
|
|
@@ -756,55 +556,6 @@ function formatCompactPreview(digest, session, events) {
|
|
|
756
556
|
lines.push(verbLabel('Details ▸') + joinWidthCapped(details, valueWidth));
|
|
757
557
|
return lines.map(l => ' ' + l).join('\n');
|
|
758
558
|
}
|
|
759
|
-
function classifySessionTool(tool, command) {
|
|
760
|
-
const toolName = tool.toLowerCase();
|
|
761
|
-
const commandUses = (surface) => (new RegExp(`\\b(?:agents|ag)\\b[^\\n;&|]*\\b${surface}\\b`).test(command.toLowerCase()));
|
|
762
|
-
const tags = [];
|
|
763
|
-
if (/browser|webfetch|websearch/.test(toolName) || commandUses('browser'))
|
|
764
|
-
tags.push('browser');
|
|
765
|
-
if (/computer/.test(toolName) || commandUses('computer'))
|
|
766
|
-
tags.push('computer');
|
|
767
|
-
return tags;
|
|
768
|
-
}
|
|
769
|
-
function directoriesTouched(session, events, changes) {
|
|
770
|
-
const fromMeta = session.recentDirectoriesTouched;
|
|
771
|
-
if (Array.isArray(fromMeta) && fromMeta.length > 0) {
|
|
772
|
-
const seen = new Set();
|
|
773
|
-
for (const raw of fromMeta) {
|
|
774
|
-
const dir = relativizeDir(sanitizeForTerminal(String(raw).trim()), session.cwd);
|
|
775
|
-
if (dir)
|
|
776
|
-
seen.add(dir);
|
|
777
|
-
if (seen.size >= DIRS_TOUCHED_MAX)
|
|
778
|
-
break;
|
|
779
|
-
}
|
|
780
|
-
if (seen.size > 0)
|
|
781
|
-
return [...seen];
|
|
782
|
-
}
|
|
783
|
-
const counts = new Map();
|
|
784
|
-
const bump = (raw) => {
|
|
785
|
-
const dir = relativizeDir(raw, session.cwd);
|
|
786
|
-
if (!dir)
|
|
787
|
-
return;
|
|
788
|
-
counts.set(dir, (counts.get(dir) ?? 0) + 1);
|
|
789
|
-
};
|
|
790
|
-
for (const ch of changes)
|
|
791
|
-
bump(ch.path);
|
|
792
|
-
for (const event of events) {
|
|
793
|
-
if (event.type !== 'tool_use' || event._local)
|
|
794
|
-
continue;
|
|
795
|
-
const p = event.path || event.args?.file_path || event.args?.path || '';
|
|
796
|
-
if (p)
|
|
797
|
-
bump(p);
|
|
798
|
-
}
|
|
799
|
-
return [...counts.entries()]
|
|
800
|
-
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
801
|
-
.map(([d]) => d)
|
|
802
|
-
.slice(0, DIRS_TOUCHED_MAX);
|
|
803
|
-
}
|
|
804
|
-
function encodeClaudeSlug(absPath) {
|
|
805
|
-
return absPath.replace(/[/.]/g, '-');
|
|
806
|
-
}
|
|
807
|
-
const SLUG_WORKTREE_RE = /--agents-worktrees-(.+)$/;
|
|
808
559
|
function joinWidthCapped(items, maxWidth) {
|
|
809
560
|
let out = '';
|
|
810
561
|
let width = 0;
|
|
@@ -821,51 +572,6 @@ function joinWidthCapped(items, maxWidth) {
|
|
|
821
572
|
const remaining = items.length - shown;
|
|
822
573
|
return out + (remaining > 0 ? chalk.gray(` … +${remaining} more`) : '');
|
|
823
574
|
}
|
|
824
|
-
export function relativizeDir(filePath, cwd) {
|
|
825
|
-
const norm = filePath.replace(/\\/g, '/');
|
|
826
|
-
if (!norm || norm.includes('node_modules') || norm.includes('/.git/') || norm.includes('/plans/')) {
|
|
827
|
-
return undefined;
|
|
828
|
-
}
|
|
829
|
-
const normBase = cwd?.replace(/\\/g, '/').replace(/\/$/, '');
|
|
830
|
-
const underCwd = normBase && (norm === normBase || norm.startsWith(normBase + '/'));
|
|
831
|
-
if (!underCwd && (norm.includes('/.agents/.history/') || /\/\.agents\/worktrees(\/[^/]+)?\/?$/.test(norm))) {
|
|
832
|
-
return undefined;
|
|
833
|
-
}
|
|
834
|
-
let dir = path.posix.dirname(norm);
|
|
835
|
-
if (dir.startsWith('-')) {
|
|
836
|
-
const slash = dir.indexOf('/');
|
|
837
|
-
const slug = slash === -1 ? dir : dir.slice(0, slash);
|
|
838
|
-
if (cwd) {
|
|
839
|
-
const cwdSlug = encodeClaudeSlug(cwd.replace(/\\/g, '/').replace(/\/$/, ''));
|
|
840
|
-
if (slug === cwdSlug || slug.startsWith(cwdSlug + '-'))
|
|
841
|
-
return undefined;
|
|
842
|
-
}
|
|
843
|
-
const wtSlug = slug.match(SLUG_WORKTREE_RE);
|
|
844
|
-
if (wtSlug)
|
|
845
|
-
return `⧉ ${wtSlug[1]}`;
|
|
846
|
-
const segs = slug.split('-').filter(Boolean);
|
|
847
|
-
return segs.length ? segs[segs.length - 1] : undefined;
|
|
848
|
-
}
|
|
849
|
-
if (cwd) {
|
|
850
|
-
const base = cwd.replace(/\\/g, '/').replace(/\/$/, '');
|
|
851
|
-
if (dir === base)
|
|
852
|
-
return '.';
|
|
853
|
-
if (dir.startsWith(base + '/'))
|
|
854
|
-
return dir.slice(base.length + 1);
|
|
855
|
-
}
|
|
856
|
-
const wt = dir.match(WORKTREE_RE);
|
|
857
|
-
if (wt) {
|
|
858
|
-
const after = dir.slice(dir.indexOf(wt[0]) + wt[0].length).replace(/^\//, '');
|
|
859
|
-
return after ? `⧉ ${wt[1]}/${after}` : `⧉ ${wt[1]}`;
|
|
860
|
-
}
|
|
861
|
-
const home = (process.env.HOME || '').replace(/\\/g, '/');
|
|
862
|
-
if (home && dir.startsWith(home + '/'))
|
|
863
|
-
dir = '~' + dir.slice(home.length);
|
|
864
|
-
const parts = dir.split('/').filter(Boolean);
|
|
865
|
-
if (parts.length > 3 && dir.startsWith('/'))
|
|
866
|
-
dir = parts.slice(-3).join('/');
|
|
867
|
-
return dir || undefined;
|
|
868
|
-
}
|
|
869
575
|
export function renderLastResponse(content, maxLines = LAST_RESPONSE_MAX_LINES, width = terminalWidth()) {
|
|
870
576
|
const cleaned = stripTags(content).trim();
|
|
871
577
|
if (!cleaned)
|
|
@@ -987,15 +693,19 @@ export async function handlePickedSession(picked) {
|
|
|
987
693
|
if (isIdlessLiveRow(picked.session)) {
|
|
988
694
|
const where = picked.session.machine ? ` on ${picked.session.machine}` : '';
|
|
989
695
|
console.log(chalk.yellow(`This session hasn't reported a session id yet — nothing to open${where}.`));
|
|
990
|
-
console.log(chalk.gray(`Watch for it with: agents
|
|
696
|
+
console.log(chalk.gray(`Watch for it with: agents ps${picked.session.machine ? ` --device ${picked.session.machine}` : ''}`));
|
|
991
697
|
return;
|
|
992
698
|
}
|
|
993
699
|
if (picked.action === 'view') {
|
|
994
700
|
const readFrom = transcriptOnPeerOf(picked.session);
|
|
995
701
|
if (readFrom) {
|
|
996
|
-
const
|
|
997
|
-
if (
|
|
702
|
+
const peer = await resolvePeerTarget(readFrom);
|
|
703
|
+
if (!peer) {
|
|
998
704
|
warnNoPeerTarget(readFrom, picked.session);
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
const { runSessions } = await import('../lib/sessions-client.js');
|
|
708
|
+
process.exitCode = await runSessions([picked.session.id, '--markdown', '--host', `ssh://${peer.target}`]);
|
|
999
709
|
return;
|
|
1000
710
|
}
|
|
1001
711
|
await renderSession(picked.session, 'summary', {});
|
|
@@ -1010,11 +720,7 @@ async function resumeOnOwnerIfRemote(session) {
|
|
|
1010
720
|
if (!owner)
|
|
1011
721
|
return false;
|
|
1012
722
|
console.log(chalk.gray(`Resuming ${session.shortId} on ${owner} over SSH...`));
|
|
1013
|
-
const rc = await runOnPeer(
|
|
1014
|
-
tty: true,
|
|
1015
|
-
env: { [RESUME_PINNED_ENV]: '1' },
|
|
1016
|
-
sessionId: session.id,
|
|
1017
|
-
});
|
|
723
|
+
const rc = await runOnPeer(sessionRecoveryRunArgs(session), owner, { tty: true, sessionId: session.id });
|
|
1018
724
|
if (rc === 'no-target')
|
|
1019
725
|
warnNoPeerTarget(owner, session);
|
|
1020
726
|
return true;
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type SessionMeta } from '@phnx-labs/sessions-cli/reader';
|
|
1
|
+
import type { SessionMeta } from '@phnx-labs/sessions-cli/reader';
|
|
3
2
|
import { type Backend, type SurfaceItem, type EngineContext, type Packing } from '../lib/terminal/index.js';
|
|
4
|
-
import { type StrictResumeOptions } from './resume.js';
|
|
5
3
|
export declare const CONFIRM_THRESHOLD = 5;
|
|
6
|
-
|
|
4
|
+
export declare function stillRunningNotice(shortId: string, pid: number, host: string): string;
|
|
5
|
+
interface ResumeOptions {
|
|
7
6
|
agent?: string;
|
|
7
|
+
account?: string;
|
|
8
|
+
model?: string;
|
|
9
|
+
mode?: string;
|
|
10
|
+
interactive?: boolean;
|
|
11
|
+
headless?: boolean;
|
|
12
|
+
cwd?: string;
|
|
13
|
+
quiet?: boolean;
|
|
14
|
+
here?: boolean;
|
|
8
15
|
all?: boolean;
|
|
9
16
|
teams?: boolean;
|
|
10
17
|
since?: string;
|
|
@@ -16,26 +23,20 @@ interface ResumeOptions extends StrictResumeOptions {
|
|
|
16
23
|
vscodium?: boolean;
|
|
17
24
|
terminalApp?: boolean;
|
|
18
25
|
splits?: boolean;
|
|
19
|
-
|
|
20
|
-
local?: boolean;
|
|
21
|
-
runArgs?: string[];
|
|
26
|
+
runArgs: string[];
|
|
22
27
|
}
|
|
23
|
-
export declare function
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function sessionsResumeAction(query: string | undefined, prompt: string | undefined, options: ResumeOptions): Promise<void>;
|
|
26
|
-
export declare function buildSelectedResumeArgs(id: string, prompt: string | undefined, options: ResumeOptions): string[];
|
|
27
|
-
export declare function isDirectResumeSelector(query: string): boolean;
|
|
28
|
+
export declare function sessionsResumeAction(options: ResumeOptions): Promise<void>;
|
|
29
|
+
export declare function buildSelectedResumeArgs(id: string, options: ResumeOptions): string[];
|
|
28
30
|
export declare function partitionResumableSelections(chosen: SessionMeta[], options?: Pick<ResumeOptions, 'here' | 'device'>): {
|
|
29
31
|
resumable: SessionMeta[];
|
|
30
32
|
skipped: SessionMeta[];
|
|
31
33
|
};
|
|
32
|
-
export declare function resumeUsesLifecycleDispatch(query: string | undefined, prompt: string | undefined, options: Pick<ResumeOptions, 'attachOnly' | 'local' | 'mode' | 'interactive' | 'headless' | 'here'>): boolean;
|
|
33
34
|
export declare function dispatchSessionLifecycleInPlace(selector: string, hosts?: string[], attachOnly?: boolean, local?: boolean): Promise<void>;
|
|
34
35
|
export declare function buildSessionLifecycleArgs(selector: string, hosts?: string[], attachOnly?: boolean, local?: boolean): string[];
|
|
35
36
|
export declare function resolveResumePacking(options: Pick<ResumeOptions, 'splits'>): Packing;
|
|
36
|
-
export declare function buildSelectedResumeSurface(session: SessionMeta,
|
|
37
|
+
export declare function buildSelectedResumeSurface(session: SessionMeta, options: ResumeOptions): SurfaceItem & {
|
|
37
38
|
session: SessionMeta;
|
|
38
39
|
};
|
|
39
40
|
export declare function resumeHostMismatch(session: Pick<SessionMeta, 'shortId' | 'machine'>, requestedHost: string, self?: string): string | null;
|
|
40
|
-
export declare function resolveBackend(options: ResumeOptions, ctx: EngineContext, count: number): Promise<Backend | 'inplace' | 'cancel'>;
|
|
41
|
+
export declare function resolveBackend(options: Pick<ResumeOptions, 'iterm' | 'ghostty' | 'tmux' | 'vscodium' | 'terminalApp' | 'device'>, ctx: EngineContext, count: number): Promise<Backend | 'inplace' | 'cancel'>;
|
|
41
42
|
export {};
|