@phnx-labs/agents-cli 1.22.127 → 1.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/README.md +15 -16
  3. package/dist/bootstrap.js +4 -3
  4. package/dist/commands/browser.js +4 -19
  5. package/dist/commands/cloud-transcripts.js +1 -2
  6. package/dist/commands/computer.d.ts +2 -6
  7. package/dist/commands/computer.js +12 -18
  8. package/dist/commands/daemon.js +70 -11
  9. package/dist/commands/exec.js +1 -1
  10. package/dist/commands/feed.js +1 -2
  11. package/dist/commands/focus.js +4 -1
  12. package/dist/commands/go.js +3 -2
  13. package/dist/commands/logs.js +3 -7
  14. package/dist/commands/menubar.js +55 -3
  15. package/dist/commands/projects.js +103 -40
  16. package/dist/commands/ps-roster.d.ts +0 -11
  17. package/dist/commands/ps-roster.js +3 -116
  18. package/dist/commands/ps.d.ts +10 -0
  19. package/dist/commands/ps.js +182 -1
  20. package/dist/commands/resume.js +1 -1
  21. package/dist/commands/sessions-browser.d.ts +0 -1
  22. package/dist/commands/sessions-browser.js +6 -23
  23. package/dist/commands/sessions-export.js +1 -1
  24. package/dist/commands/sessions-migrate.js +1 -1
  25. package/dist/commands/sessions-picker.d.ts +6 -32
  26. package/dist/commands/sessions-picker.js +81 -8
  27. package/dist/commands/sessions-render.js +1 -1
  28. package/dist/commands/sessions-resume.js +2 -2
  29. package/dist/commands/sessions-share.js +1 -1
  30. package/dist/commands/sessions-trace.js +1 -1
  31. package/dist/commands/sessions.d.ts +2 -176
  32. package/dist/commands/sessions.js +44 -1577
  33. package/dist/index.js +10 -11
  34. package/dist/lib/browser-client.d.ts +0 -21
  35. package/dist/lib/browser-client.js +1 -44
  36. package/dist/lib/computer/record.d.ts +1 -0
  37. package/dist/lib/computer/record.js +2 -16
  38. package/dist/lib/config-keys.d.ts +2 -2
  39. package/dist/lib/config-keys.js +8 -2
  40. package/dist/lib/daemon/account-state-daemon-service.d.ts +2 -2
  41. package/dist/lib/daemon/account-state-daemon-service.js +2 -2
  42. package/dist/lib/daemon/attention-notify-service.js +8 -4
  43. package/dist/lib/daemon/daemon.d.ts +5 -1
  44. package/dist/lib/daemon/daemon.js +54 -14
  45. package/dist/lib/daemon/diagnostics.d.ts +70 -0
  46. package/dist/lib/daemon/diagnostics.js +185 -0
  47. package/dist/lib/daemon/runner.js +3 -2
  48. package/dist/lib/daemon/service.d.ts +1 -1
  49. package/dist/lib/daemon/session-state-service.d.ts +1 -1
  50. package/dist/lib/daemon/session-state-service.js +2 -2
  51. package/dist/lib/daemon/supervisor.d.ts +8 -0
  52. package/dist/lib/daemon/supervisor.js +47 -6
  53. package/dist/lib/daemon-services.d.ts +4 -1
  54. package/dist/lib/daemon-services.js +36 -5
  55. package/dist/lib/daemon-ticks.d.ts +3 -1
  56. package/dist/lib/daemon-ticks.js +18 -12
  57. package/dist/lib/device-config.d.ts +1 -1
  58. package/dist/lib/device-config.js +48 -7
  59. package/dist/lib/feed/tool-activity.d.ts +22 -10
  60. package/dist/lib/feed/tool-activity.js +168 -32
  61. package/dist/lib/feed/tools.d.ts +55 -2
  62. package/dist/lib/feed/tools.js +22 -28
  63. package/dist/lib/feed/watch.js +12 -8
  64. package/dist/lib/github/open-prs.d.ts +41 -0
  65. package/dist/lib/github/open-prs.js +157 -0
  66. package/dist/lib/github/project-prs.d.ts +20 -1
  67. package/dist/lib/github/project-prs.js +8 -7
  68. package/dist/lib/helper-versions.js +1 -1
  69. package/dist/lib/menubar/install-menubar.d.ts +23 -7
  70. package/dist/lib/menubar/install-menubar.js +179 -30
  71. package/dist/lib/menubar/resolve-version.d.ts +1 -0
  72. package/dist/lib/menubar/resolve-version.js +4 -2
  73. package/dist/lib/menubar/snapshot.d.ts +2 -0
  74. package/dist/lib/menubar/snapshot.js +2 -0
  75. package/dist/lib/menubar/update-state.d.ts +15 -0
  76. package/dist/lib/menubar/update-state.js +36 -0
  77. package/dist/lib/owner-notify.d.ts +0 -12
  78. package/dist/lib/owner-notify.js +1 -10
  79. package/dist/lib/self-heal/checks/menubar-helper.js +1 -0
  80. package/dist/lib/session/active.js +18 -14
  81. package/dist/lib/session/cloud.d.ts +0 -1
  82. package/dist/lib/session/cloud.js +0 -5
  83. package/dist/lib/session/db.d.ts +0 -64
  84. package/dist/lib/session/db.js +0 -116
  85. package/dist/lib/session/pid-registry.js +9 -6
  86. package/dist/lib/session/presentation.d.ts +107 -1
  87. package/dist/lib/session/presentation.js +543 -4
  88. package/dist/lib/session/remote/remote-list.d.ts +5 -36
  89. package/dist/lib/session/remote/remote-list.js +16 -320
  90. package/dist/lib/session/resume-command.d.ts +9 -0
  91. package/dist/lib/session/resume-command.js +107 -0
  92. package/dist/lib/session/selection.d.ts +102 -0
  93. package/dist/lib/session/selection.js +443 -0
  94. package/dist/lib/session/tool-index.d.ts +0 -62
  95. package/dist/lib/session/tool-index.js +1 -537
  96. package/dist/lib/sessions-client.d.ts +1 -0
  97. package/dist/lib/sessions-client.js +17 -1
  98. package/dist/lib/standalone-tools.js +2 -2
  99. package/dist/lib/testdata/owner-notify-api.d.ts +0 -13
  100. package/dist/lib/testdata/owner-notify-api.js +3 -23
  101. package/package.json +1 -1
  102. package/dist/commands/browser-sessions-picker.d.ts +0 -9
  103. package/dist/commands/browser-sessions-picker.js +0 -136
  104. package/dist/commands/computer-sessions-picker.d.ts +0 -11
  105. package/dist/commands/computer-sessions-picker.js +0 -90
  106. package/dist/commands/sessions-tail.d.ts +0 -13
  107. package/dist/commands/sessions-tail.js +0 -222
  108. package/dist/lib/browser/native-history.test-fixture.d.ts +0 -12
  109. package/dist/lib/browser/native-history.test-fixture.js +0 -43
  110. package/dist/lib/browser/paths.d.ts +0 -9
  111. package/dist/lib/browser/paths.js +0 -31
  112. package/dist/lib/browser/record.d.ts +0 -4
  113. package/dist/lib/browser/record.js +0 -19
  114. package/dist/lib/browser/sessions-list.d.ts +0 -79
  115. package/dist/lib/browser/sessions-list.js +0 -415
  116. package/dist/lib/computer/sessions-list.d.ts +0 -78
  117. package/dist/lib/computer/sessions-list.js +0 -372
  118. package/dist/lib/daemon/owner-device-delivery-service.d.ts +0 -10
  119. package/dist/lib/daemon/owner-device-delivery-service.js +0 -28
@@ -1,6 +1,14 @@
1
1
  import chalk from 'chalk';
2
2
  import { setHelpSections } from '../lib/help.js';
3
- import { runLiveRoster } from './ps-roster.js';
3
+ import { indexActiveBySessionId, runLiveRoster } from './ps-roster.js';
4
+ import { buildPreview, loadSessionPreviewDigest, transcriptOnPeerOf } from './sessions-picker.js';
5
+ import { isBookmarked } from '../lib/session/bookmarks.js';
6
+ import { discoverSessions, isCompleteSessionId } from '../lib/session/discover.js';
7
+ import { buildSessionDetailBlock, formatLiveStatusHeadline, notFoundByIdMessage, sessionTranscriptStamp } from '../lib/session/presentation.js';
8
+ import { runOnPeer, shouldIncludeLocal } from '../lib/session/remote-list.js';
9
+ import { applyScopeFilters, metadataResolveOutcome, resolveSessionMetadataValue, resolveSessionQuery, selectorAllowsEarlyExit } from '../lib/session/selection.js';
10
+ import { loadLocalActiveSessions } from '../lib/session/session-cache.js';
11
+ import { machineId } from '../lib/session/sync/config.js';
4
12
  import { registerSessionsStopCommand } from './sessions-stop.js';
5
13
  import { registerFocusCommand } from './focus.js';
6
14
  import { registerDetachCommand } from './detach.js';
@@ -107,4 +115,177 @@ export function registerPsCommand(program) {
107
115
  registerDetachCommand(ps, 'ps');
108
116
  registerSessionsMigrateCommand(ps, 'ps');
109
117
  registerSessionsMigrationsCommand(ps, 'ps');
118
+ registerSessionPreviewCommand(ps, 'ps');
119
+ }
120
+ export function registerSessionPreviewCommand(parent, group) {
121
+ const previewCmd = parent
122
+ .command('preview')
123
+ .argument('<id>', 'Full session ID or displayed 8-character short ID')
124
+ .description('Show one rich session card without rendering the full transcript')
125
+ .option('-a, --agent <agent>', 'Narrow the ID to one agent type/version')
126
+ .option('-p, --project <name>', 'Narrow the ID to one project')
127
+ .option('--local', 'Only this machine; do not resolve the ID across the fleet')
128
+ .option('-D, --device <target...>', 'Resolve only on the named device(s)')
129
+ .option('--json', 'Output the session preview as JSON')
130
+ .option('--refresh', 'Bypass the durable remote-preview cache and negative backoff for one bounded fetch (full ID + single --device only)')
131
+ .option('--revision <cursor>', 'Opaque caller-owned activity cursor (any stable value YOU track, e.g. your own feed\'s lastActivityMs) -- passing the SAME value as your last call confirms nothing changed and serves the cache with zero SSH indefinitely; a different value fetches once, still subject to backoff unless --refresh is also set (full ID + single --device only)');
132
+ setHelpSections(previewCmd, {
133
+ examples: `
134
+ # Preview by the 8-character ID shown in agents ${group}
135
+ agents ${group} preview 407b8dd5
136
+
137
+ # A full UUID resolves on the first device that owns it
138
+ agents ${group} preview c70ecdea-6210-4039-9845-246a3a7a9942
139
+
140
+ # Stay on this machine or restrict the authoritative lookup to one peer
141
+ agents ${group} preview 407b8dd5 --local
142
+ agents ${group} preview 407b8dd5 --device zion
143
+
144
+ # Full ID + one --device: durable-cached fast path (PHNX-3999); force a fresh fetch
145
+ agents ${group} preview c70ecdea-6210-4039-9845-246a3a7a9942 --device zion --json --refresh
146
+ `,
147
+ notes: `
148
+ - Full UUIDs are globally unique and may stop the fleet lookup at the first exact hit.
149
+ - Short IDs wait for every selected device so ambiguity is never hidden.
150
+ - Active status is refreshed through the bounded live-state TTL; transcript-derived details use the durable session index.
151
+ - A full UUID with exactly one --device and --json is served from a local durable cache (~45s fresh window); the JSON envelope's "cache" field reports fresh/stale/offline state. --refresh forces one bounded re-fetch.${group === 'ps' ? "\n - Put -D after the verb: 'ps -D box preview <id>' reads 'preview' as a device." : ''}
152
+ `,
153
+ });
154
+ previewCmd.action(async (id) => {
155
+ const options = previewCmd.optsWithGlobals();
156
+ const hosts = [...(options.host ?? []), ...(options.device ?? [])];
157
+ await renderSessionPreview(id, {
158
+ agent: options.agent,
159
+ project: options.project,
160
+ local: options.local,
161
+ hosts: hosts.length > 0 ? hosts : undefined,
162
+ json: options.json,
163
+ refresh: options.refresh,
164
+ revision: options.revision,
165
+ });
166
+ });
167
+ }
168
+ export async function renderSessionPreview(query, scope) {
169
+ if (scope.json && !scope.local && scope.hosts?.length === 1
170
+ && scope.hosts[0] !== machineId() && isCompleteSessionId(query.trim())) {
171
+ const { getRemoteSessionPreview } = await import('../lib/session/remote-preview-cache.js');
172
+ const result = await getRemoteSessionPreview(query.trim(), scope.hosts[0], {
173
+ refresh: scope.refresh,
174
+ revision: scope.revision,
175
+ });
176
+ const envelope = result.envelope;
177
+ console.log(JSON.stringify({
178
+ schemaVersion: 1,
179
+ session: envelope?.session ?? null,
180
+ active: result.cache.source === 'live' ? (envelope?.active ?? null) : null,
181
+ preview: envelope?.preview ?? null,
182
+ error: envelope?.error ?? (envelope ? null : result.cache.reason),
183
+ details: envelope?.details ?? null,
184
+ cache: result.cache,
185
+ }));
186
+ return;
187
+ }
188
+ let outcome = await resolveSessionMetadataValue(query, scope);
189
+ if (outcome.kind !== 'resolved'
190
+ && (!scope.hosts?.length || shouldIncludeLocal(scope.hosts, machineId()))) {
191
+ const discovered = applyScopeFilters(await discoverSessions({ all: true, cwd: process.cwd(), limit: 5000, waitForScan: true }), scope);
192
+ const localMatches = resolveSessionQuery(discovered, query, { indexFallback: false, scope }).matches
193
+ .map(session => ({ ...session, machine: session.machine || machineId() }));
194
+ const exact = localMatches.find(session => selectorAllowsEarlyExit(query)
195
+ && session.id.toLowerCase() === query.trim().toLowerCase());
196
+ if (exact)
197
+ outcome = { kind: 'resolved', session: exact };
198
+ else if (outcome.kind === 'not-found' && localMatches.length > 0) {
199
+ outcome = metadataResolveOutcome(localMatches, { sessions: [], unreachable: [] }, query);
200
+ }
201
+ }
202
+ if (outcome.kind === 'partial') {
203
+ const offline = outcome.failedPeers;
204
+ console.error(chalk.yellow(`Warning: ${offline.length} device(s) unreachable, not checked: ${offline.join(', ')}`));
205
+ console.error(chalk.red(`No session matching "${query}" on any reachable device (${offline.length} unreachable, not checked).`));
206
+ console.error(chalk.gray(' If it lives on an offline box, wake it (agents devices) or run there: agents ssh <device>'));
207
+ process.exitCode = 1;
208
+ return;
209
+ }
210
+ if (outcome.kind === 'not-found') {
211
+ notFoundByIdMessage(query).forEach(l => console.error(l));
212
+ process.exitCode = 1;
213
+ return;
214
+ }
215
+ if (outcome.kind === 'ambiguous') {
216
+ console.error(chalk.red(`Multiple sessions match "${query}" across the fleet:`));
217
+ for (const candidate of outcome.candidates) {
218
+ const match = candidate.hits[0].session;
219
+ const machines = candidate.hits.map(hit => hit.machine).join(', ');
220
+ console.error(chalk.cyan(` ${match.shortId} ${match.id}`) + chalk.gray(` ${machines} ${match.agent}${match.version ? ` ${match.version}` : ''}`));
221
+ }
222
+ console.error(chalk.gray('Pass the full session ID to narrow it down.'));
223
+ process.exitCode = 1;
224
+ return;
225
+ }
226
+ const session = outcome.session;
227
+ const transcriptPeer = transcriptOnPeerOf(session);
228
+ if (transcriptPeer) {
229
+ const args = ['sessions', 'preview', session.id, '--local'];
230
+ if (scope.json)
231
+ args.push('--json');
232
+ const rendered = await runOnPeer(args, transcriptPeer);
233
+ if (rendered === 'no-target') {
234
+ console.error(chalk.red(`Session ${session.id} is on ${transcriptPeer}, but that device is not reachable.`));
235
+ process.exitCode = 1;
236
+ }
237
+ return;
238
+ }
239
+ let live;
240
+ try {
241
+ const loaded = await loadLocalActiveSessions();
242
+ live = indexActiveBySessionId(loaded.sessions).get(session.id);
243
+ }
244
+ catch { }
245
+ if (scope.json) {
246
+ const sourceStamp = sessionTranscriptStamp(session);
247
+ const { digest, error, events } = loadSessionPreviewDigest(session);
248
+ console.log(JSON.stringify({
249
+ schemaVersion: 1,
250
+ session: {
251
+ id: session.id,
252
+ shortId: session.shortId,
253
+ agent: session.agent,
254
+ version: session.version,
255
+ model: session.model,
256
+ account: session.account,
257
+ machine: session.machine ?? machineId(),
258
+ cwd: session.cwd,
259
+ project: session.project,
260
+ gitBranch: session.gitBranch,
261
+ createdAt: session.timestamp,
262
+ lastActivity: session.lastActivity,
263
+ durationMs: session.durationMs,
264
+ messageCount: session.messageCount,
265
+ tokenCount: session.tokenCount,
266
+ costUsd: session.costUsd,
267
+ label: session.label,
268
+ topic: session.topic,
269
+ ticketId: session.ticketId,
270
+ prUrl: session.prUrl,
271
+ },
272
+ active: live ? {
273
+ status: live.status,
274
+ activity: live.activity,
275
+ awaitingReason: live.awaitingReason,
276
+ lastActivityMs: live.lastActivityMs,
277
+ startedAtMs: live.startedAtMs,
278
+ pid: live.pid,
279
+ host: live.host,
280
+ } : null,
281
+ preview: digest ?? null,
282
+ error: error ?? null,
283
+ details: buildSessionDetailBlock(session, digest, events, sourceStamp),
284
+ }));
285
+ return;
286
+ }
287
+ const headline = formatLiveStatusHeadline(live, isBookmarked(session.id));
288
+ if (headline)
289
+ console.log(headline);
290
+ console.log(buildPreview(session));
110
291
  }
@@ -1,6 +1,6 @@
1
1
  import { spawn } from 'child_process';
2
2
  import chalk from 'chalk';
3
- import { resolveSessionMetadataValue } from './sessions.js';
3
+ import { resolveSessionMetadataValue } from '../lib/session/selection.js';
4
4
  import { sessionOwnerDevice, consumeResumePinned, RESUME_PINNED_ENV } from '../lib/session/resume-owner.js';
5
5
  import { machineId } from '../lib/machine-id.js';
6
6
  import { takeOverDetachedSession } from '../lib/session/detached.js';
@@ -23,7 +23,6 @@ export interface BrowserFilter {
23
23
  export declare function buildInitialFilter(initial: Partial<BrowserFilter>): BrowserFilter;
24
24
  export declare function cycle(current: string | undefined, options: string[]): string | undefined;
25
25
  export declare function cycleWindow(current: string | undefined): string | undefined;
26
- export declare function sessionMatchesQuery(s: SessionMeta, query: string): boolean;
27
26
  export declare function browserFilterToArgv(f: BrowserFilter, query?: string): string[];
28
27
  export declare function normalizeDeviceSeed(host: string | undefined): string | undefined;
29
28
  export declare function activeBrowserSeed(opts: {
@@ -4,15 +4,17 @@ import chalk from 'chalk';
4
4
  import { dynamicPicker } from '../lib/picker.js';
5
5
  import { isSessionTrackedAgent } from '@phnx-labs/sessions-cli/reader';
6
6
  import { discoverSessions } from '../lib/session/discover.js';
7
- import { gatherRemoteList } from '../lib/session/remote-list.js';
7
+ import { gatherRemoteList, remoteHostsToDial, shouldIncludeLocal } from '../lib/session/remote-list.js';
8
8
  import { resolveVersionAliasLoose } from '../lib/installations/versions.js';
9
9
  import { AGENTS } from '../lib/agents.js';
10
10
  import { enrichTeamOrigins, safeTeamText, shouldShowTeamSessions } from '@phnx-labs/sessions-cli/reader';
11
11
  import { listBookmarks, toggleBookmark } from '../lib/session/bookmarks.js';
12
12
  import { machineId, normalizeHost } from '../lib/session/sync/config.js';
13
- import { buildPreview, setRemotePreviewRepaint } from './sessions-picker.js';
14
- import { formatPickerLabel, pickerColumnsFor, ticketLabel, mergeLocalFirst, liveHostLabel, LIVE_ROW_PREFIX, handlePickedSession, matchesTeam, formatLiveStatusHeadline, isRunningLiveSession, parseAgentFilter } from './sessions.js';
15
- import { gatherActiveSessions, cleanPreview, shouldIncludeLocal, remoteHostsToDial, matchesLiveStatus, resolveRoutineName } from './ps-roster.js';
13
+ import { buildPreview, setRemotePreviewRepaint, LIVE_ROW_PREFIX, handlePickedSession } from './sessions-picker.js';
14
+ import { isRunningLiveSession } from '../lib/session/active.js';
15
+ import { cleanPreview, formatPickerLabel, pickerColumnsFor, liveHostLabel, formatLiveStatusHeadline } from '../lib/session/presentation.js';
16
+ import { matchesTeam, mergeLocalFirst, parseAgentFilter, sessionMatchesQuery } from '../lib/session/selection.js';
17
+ import { gatherActiveSessions, matchesLiveStatus, resolveRoutineName } from './ps-roster.js';
16
18
  export function buildInitialFilter(initial) {
17
19
  return {
18
20
  running: initial.running ?? false,
@@ -56,25 +58,6 @@ export function cycleWindow(current) {
56
58
  function distinct(values) {
57
59
  return [...new Set(values.filter((v) => !!v))].sort();
58
60
  }
59
- export function sessionMatchesQuery(s, query) {
60
- const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
61
- if (terms.length === 0)
62
- return true;
63
- const hay = [
64
- s.shortId,
65
- s.agent,
66
- s.project,
67
- s.cwd,
68
- s.topic,
69
- s.label,
70
- ticketLabel(s),
71
- s.machine,
72
- ]
73
- .filter(Boolean)
74
- .join(' ')
75
- .toLowerCase();
76
- return terms.every((t) => hay.includes(t));
77
- }
78
61
  export function browserFilterToArgv(f, query = '') {
79
62
  const a = ['sessions'];
80
63
  if (f.statuses.length === 0 && f.running)
@@ -22,7 +22,7 @@ import * as path from 'path';
22
22
  import chalk from 'chalk';
23
23
  import { discoverSessions, resolveSessionById, looksLikeSessionId } from '../lib/session/discover.js';
24
24
  import { findSessionsById } from '../lib/session/db.js';
25
- import { filterSessionsByQuery, parseAgentFilter } from './sessions.js';
25
+ import { filterSessionsByQuery, parseAgentFilter } from '../lib/session/selection.js';
26
26
  import { listLocalTranscripts, objectKey, SYNC_AGENTS } from '../lib/session/sync/agents.js';
27
27
  import { machineId } from '../lib/machine-id.js';
28
28
  import { getHistoryDir } from '../lib/state.js';
@@ -7,7 +7,7 @@ import { spawnSync } from 'child_process';
7
7
  import { AGENTS } from '../lib/agents.js';
8
8
  import { getActiveSessions } from '../lib/session/active.js';
9
9
  import { discoverSessions, resolveSessionById } from '../lib/session/discover.js';
10
- import { buildResumeCommand } from './sessions.js';
10
+ import { buildResumeCommand } from '../lib/session/resume-command.js';
11
11
  import { injectTargetFromReplyRail } from '../lib/session/inject.js';
12
12
  import { injectIntoTerminal, iLoginShell, shellQuote as quoteArg } from '../lib/terminal/index.js';
13
13
  import { killSession } from '../lib/tmux/session.js';
@@ -1,10 +1,8 @@
1
- import type { SessionEvent, SessionMeta, TodoProgress } from '@phnx-labs/sessions-cli/reader';
1
+ import type { SessionEvent, SessionMeta } from '@phnx-labs/sessions-cli/reader';
2
2
  import { fetchPeerPreviewDigest } from '../lib/session/remote-list.js';
3
- import { changeCounts, toolHistogram, detectTestResult } from '@phnx-labs/sessions-cli/reader';
4
- import type { FileChange } from '@phnx-labs/sessions-cli/reader';
5
- import { extractArtifacts, extractHooks, extractLinks, extractSkills } from '@phnx-labs/sessions-cli/reader';
3
+ import { type SessionSearchScope } from '../lib/session/selection.js';
4
+ import { type SessionPreviewDigest } from '../lib/session/presentation.js';
6
5
  export declare function transcriptOnPeerOf(session: SessionMeta): string | undefined;
7
- export declare function formatTodoCompact(todos?: Pick<TodoProgress, 'done' | 'total' | 'activeForm'> | null): string;
8
6
  export declare function githubRepoUrlFromCwd(cwd?: string): string | undefined;
9
7
  export interface PickedSession {
10
8
  session: SessionMeta;
@@ -42,35 +40,11 @@ export declare function extractTiming(session: Pick<SessionMeta, 'timestamp' | '
42
40
  lastActiveAgo?: string;
43
41
  duration?: string;
44
42
  };
45
- export interface SessionPreviewDigest {
46
- schemaVersion: 1;
47
- firstUser: string;
48
- lastAssistant: string;
49
- filesRead: number;
50
- toolCalls: number;
51
- planFile: string;
52
- todos?: TodoProgress;
53
- subAgentCount: number;
54
- backgroundShellCount?: number;
55
- toolTags: string[];
56
- changes: ReturnType<typeof changeCounts>;
57
- changedFiles: FileChange[];
58
- dirs: string[];
59
- repos: string[];
60
- artifacts: ReturnType<typeof extractArtifacts>;
61
- skills: ReturnType<typeof extractSkills>;
62
- plugins: string[];
63
- hooks: ReturnType<typeof extractHooks>;
64
- links: ReturnType<typeof extractLinks>;
65
- errorCount: number;
66
- firstError?: string;
67
- toolHistogram: ReturnType<typeof toolHistogram>;
68
- test: ReturnType<typeof detectTestResult>;
69
- partial?: boolean;
70
- partialReason?: string;
71
- }
72
43
  export declare function buildSessionPreviewDigest(events: SessionEvent[], session: SessionMeta): SessionPreviewDigest;
73
44
  export declare function relativizeDir(filePath: string, cwd?: string): string | undefined;
74
45
  export declare function renderLastResponse(content: string, maxLines?: number, width?: number): string[];
75
46
  export declare function sessionPicker(config: SessionPickerConfig): Promise<PickedSession | null>;
47
+ export declare function pickSessionInteractive(sessions: SessionMeta[], message?: string, initialSearch?: string, hiddenCount?: number, enterHint?: string, scope?: SessionSearchScope): Promise<PickedSession | null>;
48
+ export declare const LIVE_ROW_PREFIX = "live:";
49
+ export declare function handlePickedSession(picked: PickedSession): Promise<void>;
76
50
  export {};
@@ -20,6 +20,12 @@ import { classifyFileChanges, changeCounts, toolHistogram, detectTestResult } fr
20
20
  import { extractArtifacts, extractHooks, extractLinks, extractRepos, extractSkills, harnessTracksBackgroundShells, isBackgroundShellStart, isSubAgentTool, } from '@phnx-labs/sessions-cli/reader';
21
21
  import { getSessionPlugins, readSessionPreviewCache, writeSessionPreviewCache, readSessionContent, readArchivedSessionPreview } from '../lib/session/db.js';
22
22
  import { machineId } from '../lib/session/sync/config.js';
23
+ import { isPromptCancelled } from '../lib/format.js';
24
+ import { runOnPeer } from '../lib/session/remote-list.js';
25
+ import { RESUME_PINNED_ENV, sessionOwnerDevice } from '../lib/session/resume-owner.js';
26
+ import { resumeSessionInPlace } from '../lib/session/resume-command.js';
27
+ import { filterSessionsByQuery } from '../lib/session/selection.js';
28
+ import { formatPickerLabel, formatPickerTip, formatTeamHiddenFooter, formatTodoCompact, pickerColumnsFor, renderSession, } from '../lib/session/presentation.js';
23
29
  export function transcriptOnPeerOf(session) {
24
30
  if (session._remote)
25
31
  return session.machine;
@@ -30,14 +36,6 @@ export function transcriptOnPeerOf(session) {
30
36
  }
31
37
  return undefined;
32
38
  }
33
- export function formatTodoCompact(todos) {
34
- if (!todos || !Number.isFinite(todos.total) || todos.total < 1)
35
- return '';
36
- const done = Number.isFinite(todos.done) ? Math.max(0, todos.done) : 0;
37
- const tally = `✓${done}/${todos.total}`;
38
- const step = todos.activeForm?.replace(/\s+/g, ' ').trim();
39
- return step ? `${tally} · ${step}` : tally;
40
- }
41
39
  export function githubRepoUrlFromCwd(cwd) {
42
40
  if (!cwd)
43
41
  return undefined;
@@ -946,3 +944,78 @@ export async function sessionPicker(config) {
946
944
  return null;
947
945
  return { session: picked.item, action: 'resume' };
948
946
  }
947
+ const PICKER_RECENT_COUNT = 15;
948
+ export async function pickSessionInteractive(sessions, message = 'Search sessions:', initialSearch, hiddenCount = 0, enterHint, scope) {
949
+ let linesAbovePrompt = 0;
950
+ if (hiddenCount > 0) {
951
+ console.log(chalk.gray(formatTeamHiddenFooter(hiddenCount)));
952
+ linesAbovePrompt += 1;
953
+ }
954
+ const cols = pickerColumnsFor(sessions);
955
+ try {
956
+ return await sessionPicker({
957
+ message,
958
+ subtitle: formatPickerTip(sessions),
959
+ sessions,
960
+ filter: (query) => {
961
+ if (!query.trim())
962
+ return sessions;
963
+ return filterSessionsByQuery(sessions, query, scope);
964
+ },
965
+ labelFor: (s, query) => formatPickerLabel(s, query, cols),
966
+ pageSize: PICKER_RECENT_COUNT,
967
+ initialSearch,
968
+ enterHint,
969
+ linesAbovePrompt,
970
+ });
971
+ }
972
+ catch (err) {
973
+ if (isPromptCancelled(err))
974
+ return null;
975
+ throw err;
976
+ }
977
+ }
978
+ function warnNoPeerTarget(machine, session) {
979
+ console.log(chalk.yellow(`Session ${session.shortId} lives on ${machine}, which isn't a reachable device right now.`));
980
+ console.log(chalk.gray(`Register/wake it (ag devices), or run there: agents ssh ${machine}`));
981
+ }
982
+ export const LIVE_ROW_PREFIX = 'live:';
983
+ function isIdlessLiveRow(s) {
984
+ return s.id.startsWith(LIVE_ROW_PREFIX);
985
+ }
986
+ export async function handlePickedSession(picked) {
987
+ if (isIdlessLiveRow(picked.session)) {
988
+ const where = picked.session.machine ? ` on ${picked.session.machine}` : '';
989
+ 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 sessions --active${picked.session.machine ? ` --device ${picked.session.machine}` : ''}`));
991
+ return;
992
+ }
993
+ if (picked.action === 'view') {
994
+ const readFrom = transcriptOnPeerOf(picked.session);
995
+ if (readFrom) {
996
+ const rc = await runOnPeer(['sessions', picked.session.shortId, '--markdown'], readFrom);
997
+ if (rc === 'no-target')
998
+ warnNoPeerTarget(readFrom, picked.session);
999
+ return;
1000
+ }
1001
+ await renderSession(picked.session, 'summary', {});
1002
+ return;
1003
+ }
1004
+ if (await resumeOnOwnerIfRemote(picked.session))
1005
+ return;
1006
+ await resumeSessionInPlace(picked.session);
1007
+ }
1008
+ async function resumeOnOwnerIfRemote(session) {
1009
+ const owner = sessionOwnerDevice(session);
1010
+ if (!owner)
1011
+ return false;
1012
+ console.log(chalk.gray(`Resuming ${session.shortId} on ${owner} over SSH...`));
1013
+ const rc = await runOnPeer(['sessions', 'resume', session.id], owner, {
1014
+ tty: true,
1015
+ env: { [RESUME_PINNED_ENV]: '1' },
1016
+ sessionId: session.id,
1017
+ });
1018
+ if (rc === 'no-target')
1019
+ warnNoPeerTarget(owner, session);
1020
+ return true;
1021
+ }
@@ -8,7 +8,7 @@ import { parseSession } from '@phnx-labs/sessions-cli/reader';
8
8
  import { extractSessionTopic, isSyntheticUserMessage } from '@phnx-labs/sessions-cli/reader';
9
9
  import { renderConversationMarkdown } from '@phnx-labs/sessions-cli/reader';
10
10
  import { buildPreview } from './sessions-picker.js';
11
- import { parseAgentFilter } from './sessions.js';
11
+ import { parseAgentFilter } from '../lib/session/selection.js';
12
12
  import { selectSessions } from './sessions-export.js';
13
13
  export const MARKDOWN_RENDER_AGENTS = [
14
14
  'claude',
@@ -6,8 +6,8 @@ import { discoverSessions } from '../lib/session/discover.js';
6
6
  import { filterTeamSessions } from '@phnx-labs/sessions-cli/reader';
7
7
  import { multiItemPicker, itemPicker } from '../lib/picker.js';
8
8
  import { buildPreview } from './sessions-picker.js';
9
- import { formatPickerLabel, pickerColumnsFor, resolveSessionMetadataValue, parseAgentFilter, } from './sessions.js';
10
- import { sessionMatchesQuery } from './sessions-browser.js';
9
+ import { formatPickerLabel, pickerColumnsFor } from '../lib/session/presentation.js';
10
+ import { parseAgentFilter, resolveSessionMetadataValue, sessionMatchesQuery } from '../lib/session/selection.js';
11
11
  import { openSurfaces, availableBackends, detectCurrentBackend, currentContext, shellQuote, } from '../lib/terminal/index.js';
12
12
  import { isInteractiveTerminal, isPromptCancelled, normalizeSingleDeviceOption } from './utils.js';
13
13
  import { setHelpSections } from '../lib/help.js';
@@ -10,7 +10,7 @@ import { renderSessionHtmlDocument } from '@phnx-labs/sessions-cli/reader';
10
10
  import { resolveArtifactsBin, invocation, ArtifactsClientError } from '../lib/artifacts-client.js';
11
11
  import { renderSessionMarkdownDocument } from './sessions-render.js';
12
12
  import { selectSessions } from './sessions-export.js';
13
- import { parseAgentFilter } from './sessions.js';
13
+ import { parseAgentFilter } from '../lib/session/selection.js';
14
14
  function parseReasoning(value) {
15
15
  if (value === 'omit' || value === 'fold' || value === 'include')
16
16
  return value;
@@ -14,7 +14,7 @@ import { diffTrajectories } from '@phnx-labs/sessions-cli/reader';
14
14
  import { buildLineage } from '@phnx-labs/sessions-cli/reader';
15
15
  import { renderTrajectoryHtml, renderTrajectoryCompareHtml, renderLineageHtml } from '@phnx-labs/sessions-cli/reader';
16
16
  import { renderTrajectoryText, renderTrajectoryCompareText, renderLineageText } from '@phnx-labs/sessions-cli/reader';
17
- import { parseAgentFilter } from './sessions.js';
17
+ import { parseAgentFilter } from '../lib/session/selection.js';
18
18
  import { selectSessions } from './sessions-export.js';
19
19
  export const SESSIONS_TRACE_SCHEMA_VERSION = 1;
20
20
  export function buildTraceEnvelope(models) {