@phnx-labs/agents-cli 1.22.122 → 1.22.124
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 +288 -0
- package/README.md +49 -10
- package/dist/bootstrap.js +22 -17
- package/dist/cli/command-registry.d.ts +0 -1
- package/dist/cli/command-registry.js +2 -10
- package/dist/commands/auth.js +13 -4
- package/dist/commands/browser.js +3 -4
- package/dist/commands/cloud-transcripts.d.ts +7 -0
- package/dist/commands/cloud-transcripts.js +100 -0
- package/dist/commands/cloud.js +5 -0
- package/dist/commands/computer.d.ts +0 -12
- package/dist/commands/computer.js +14 -124
- package/dist/commands/config.js +5 -4
- package/dist/commands/daemon-index.d.ts +2 -0
- package/dist/commands/daemon-index.js +44 -0
- package/dist/commands/daemon.js +6 -0
- package/dist/commands/doctor.js +3 -4
- package/dist/commands/exec.d.ts +5 -0
- package/dist/commands/exec.js +35 -7
- package/dist/commands/feed-watch.js +12 -0
- package/dist/commands/feed.d.ts +1 -1
- package/dist/commands/feed.js +7 -4
- package/dist/commands/insights.js +3 -1
- package/dist/commands/inspect.js +1 -1
- package/dist/commands/logs.js +2 -1
- package/dist/commands/models.js +1 -1
- package/dist/commands/prune.js +6 -28
- package/dist/commands/ps-roster.d.ts +0 -1
- package/dist/commands/ps-roster.js +2 -21
- package/dist/commands/ps.js +13 -1
- package/dist/commands/recordings.d.ts +2 -0
- package/dist/commands/recordings.js +117 -0
- package/dist/commands/routines.js +1 -1
- package/dist/commands/secrets-passthrough.js +3 -3
- package/dist/commands/send.js +33 -20
- package/dist/commands/sessions-backfill.d.ts +1 -0
- package/dist/commands/sessions-backfill.js +48 -13
- package/dist/commands/sessions-migrate.d.ts +1 -1
- package/dist/commands/sessions-migrate.js +11 -10
- package/dist/commands/sessions-optimize.d.ts +1 -0
- package/dist/commands/sessions-optimize.js +7 -4
- package/dist/commands/sessions-resume.js +8 -1
- package/dist/commands/sessions-stats.d.ts +2 -0
- package/dist/commands/sessions-stats.js +24 -7
- package/dist/commands/sessions.d.ts +5 -11
- package/dist/commands/sessions.js +8 -236
- package/dist/commands/setup-computer.js +1 -2
- package/dist/commands/setup.js +1 -1
- package/dist/commands/teams.js +2 -2
- package/dist/commands/testdata/feed-hub.d.ts +1 -0
- package/dist/commands/testdata/feed-hub.js +11 -0
- package/dist/commands/trash.d.ts +0 -1
- package/dist/commands/trash.js +74 -10
- package/dist/lib/accounting/usage-sync.js +7 -0
- package/dist/lib/agent-modes.d.ts +1 -1
- package/dist/lib/agent-modes.js +11 -5
- package/dist/lib/auth-mint.d.ts +4 -0
- package/dist/lib/auth-mint.js +6 -4
- package/dist/lib/browser/native-history.test-fixture.d.ts +12 -0
- package/dist/lib/browser/native-history.test-fixture.js +43 -0
- package/dist/lib/browser/paths.d.ts +5 -0
- package/dist/lib/browser/paths.js +7 -1
- package/dist/lib/browser/sessions-list.d.ts +28 -1
- package/dist/lib/browser/sessions-list.js +137 -25
- package/dist/lib/channels/providers/rush.d.ts +2 -1
- package/dist/lib/channels/providers/rush.js +2 -2
- package/dist/lib/channels/providers/session.d.ts +1 -0
- package/dist/lib/channels/providers/session.js +23 -12
- package/dist/lib/channels/registry.d.ts +9 -2
- package/dist/lib/channels/send.d.ts +5 -10
- package/dist/lib/channels/send.js +88 -50
- package/dist/lib/cloud/rush.d.ts +6 -0
- package/dist/lib/cloud/rush.js +18 -3
- package/dist/lib/computer-client.d.ts +19 -0
- package/dist/lib/computer-client.js +104 -0
- package/dist/lib/config-keys.d.ts +5 -1
- package/dist/lib/config-keys.js +14 -11
- package/dist/lib/daemon/auth-sync-service.js +13 -0
- package/dist/lib/daemon/daemon.js +20 -8
- package/dist/lib/daemon/owner-device-delivery-service.d.ts +10 -0
- package/dist/lib/daemon/owner-device-delivery-service.js +28 -0
- package/dist/lib/daemon-services.d.ts +2 -1
- package/dist/lib/daemon-services.js +17 -5
- package/dist/lib/device-config.d.ts +4 -1
- package/dist/lib/device-config.js +57 -7
- package/dist/lib/devices/doctor-findings.d.ts +2 -3
- package/dist/lib/devices/doctor-findings.js +10 -19
- package/dist/lib/event-provenance.d.ts +1 -0
- package/dist/lib/event-provenance.js +2 -0
- package/dist/lib/exec.d.ts +1 -0
- package/dist/lib/exec.js +20 -15
- package/dist/lib/feed/pr-status.d.ts +5 -1
- package/dist/lib/feed/pr-status.js +44 -3
- package/dist/lib/feed/tool-activity.js +9 -6
- package/dist/lib/feed/tools.d.ts +4 -1
- package/dist/lib/feed/tools.js +8 -11
- package/dist/lib/feed-broadcast.d.ts +5 -3
- package/dist/lib/feed-broadcast.js +47 -36
- package/dist/lib/fleet-shared-state.d.ts +5 -0
- package/dist/lib/fleet-shared-state.js +8 -0
- package/dist/lib/github/project-prs.d.ts +4 -1
- package/dist/lib/github/project-prs.js +18 -5
- package/dist/lib/help.d.ts +1 -0
- package/dist/lib/help.js +8 -0
- package/dist/lib/helper-versions.js +1 -1
- package/dist/lib/hosts/passthrough.js +5 -8
- package/dist/lib/hosts/remote-cmd.d.ts +2 -7
- package/dist/lib/hosts/remote-cmd.js +14 -22
- package/dist/lib/hosts/routing-flag.d.ts +22 -0
- package/dist/lib/hosts/routing-flag.js +127 -14
- package/dist/lib/identity/index.d.ts +22 -0
- package/dist/lib/identity/index.js +3 -0
- package/dist/lib/installations/migrate.d.ts +7 -0
- package/dist/lib/installations/migrate.js +101 -88
- package/dist/lib/installations/versions.js +2 -2
- package/dist/lib/launch-identity.d.ts +6 -1
- package/dist/lib/launch-identity.js +12 -2
- package/dist/lib/menubar/install-menubar.d.ts +1 -0
- package/dist/lib/menubar/install-menubar.js +8 -5
- package/dist/lib/menubar/snapshot.js +2 -3
- package/dist/lib/notify.d.ts +7 -14
- package/dist/lib/notify.js +29 -75
- package/dist/lib/owner-message.d.ts +4 -6
- package/dist/lib/owner-message.js +12 -11
- package/dist/lib/owner-notify-tokens.d.ts +49 -0
- package/dist/lib/owner-notify-tokens.js +214 -0
- package/dist/lib/owner-notify.d.ts +75 -0
- package/dist/lib/owner-notify.js +144 -0
- package/dist/lib/recordings/config.d.ts +11 -0
- package/dist/lib/recordings/config.js +54 -0
- package/dist/lib/recordings/identity.d.ts +12 -0
- package/dist/lib/recordings/identity.js +57 -0
- package/dist/lib/recordings/ledger.d.ts +16 -0
- package/dist/lib/recordings/ledger.js +141 -0
- package/dist/lib/recordings/model.d.ts +29 -0
- package/dist/lib/recordings/model.js +28 -0
- package/dist/lib/recordings/pipeline.d.ts +44 -0
- package/dist/lib/recordings/pipeline.js +272 -0
- package/dist/lib/recordings/process.d.ts +17 -0
- package/dist/lib/recordings/process.js +94 -0
- package/dist/lib/recordings/service.d.ts +15 -0
- package/dist/lib/recordings/service.js +45 -0
- package/dist/lib/recordings/settle.d.ts +21 -0
- package/dist/lib/recordings/settle.js +92 -0
- package/dist/lib/recordings/transcode.d.ts +13 -0
- package/dist/lib/recordings/transcode.js +44 -0
- package/dist/lib/reminders.d.ts +0 -1
- package/dist/lib/reminders.js +1 -1
- package/dist/lib/reserved-stores.d.ts +3 -0
- package/dist/lib/reserved-stores.js +13 -0
- package/dist/lib/routine-notify-owner.d.ts +3 -23
- package/dist/lib/routine-notify-owner.js +26 -107
- package/dist/lib/rush-api.d.ts +1 -0
- package/dist/lib/rush-api.js +1 -0
- package/dist/lib/session/active.d.ts +18 -2
- package/dist/lib/session/active.js +47 -37
- package/dist/lib/session/cloud.js +18 -45
- package/dist/lib/session/db.d.ts +2 -0
- package/dist/lib/session/db.js +13 -4
- package/dist/lib/session/glance-files.d.ts +4 -3
- package/dist/lib/session/glance-files.js +31 -0
- package/dist/lib/session/inject-target.js +12 -2
- package/dist/lib/session/pid-registry.d.ts +2 -0
- package/dist/lib/session/pid-registry.js +6 -2
- package/dist/lib/session/presentation.d.ts +21 -0
- package/dist/lib/session/presentation.js +198 -0
- package/dist/lib/session/projection.js +9 -2
- package/dist/lib/sqlite.d.ts +3 -1
- package/dist/lib/sqlite.js +7 -3
- package/dist/lib/standalone-tools.js +1 -1
- package/dist/lib/startup/command-registry.js +9 -4
- package/dist/lib/state.d.ts +2 -2
- package/dist/lib/state.js +3 -5
- package/dist/lib/terminal/inject.js +1 -1
- package/dist/lib/testdata/owner-notify-api.d.ts +36 -0
- package/dist/lib/testdata/owner-notify-api.js +102 -0
- package/dist/lib/trash.d.ts +14 -0
- package/dist/lib/trash.js +75 -0
- package/dist/lib/types.d.ts +0 -34
- package/package.json +2 -2
- package/dist/commands/feedback.d.ts +0 -2
- package/dist/commands/feedback.js +0 -68
- package/dist/commands/humans.d.ts +0 -2
- package/dist/commands/humans.js +0 -83
- package/dist/commands/modes.d.ts +0 -2
- package/dist/commands/modes.js +0 -134
- package/dist/commands/reminders.d.ts +0 -2
- package/dist/commands/reminders.js +0 -49
- package/dist/lib/channels/owner-forward.d.ts +0 -25
- package/dist/lib/channels/owner-forward.js +0 -78
- package/dist/lib/channels/owner-sink.d.ts +0 -10
- package/dist/lib/channels/owner-sink.js +0 -26
- package/dist/lib/humans.d.ts +0 -12
- package/dist/lib/humans.js +0 -64
|
@@ -14,7 +14,7 @@ import { readSessionActorRecord, writeSessionAliasRecord } from './actor-sidecar
|
|
|
14
14
|
import { loadHookSessionIndex, resolveHookSessionRecord, readStateSessionRecord } from './hook-sessions.js';
|
|
15
15
|
import { buildClaudeLabelMap, getAgentSessionDirs } from './discover.js';
|
|
16
16
|
import { buildRunNameMap } from './run-names.js';
|
|
17
|
-
import { latestSessionFileForCwd, findSessionsByShortIds, findSessionMachinesByIds, getSessionById } from './db.js';
|
|
17
|
+
import { latestSessionFileForCwd, indexedSessionIdForFile, findSessionsByShortIds, findSessionMachinesByIds, getSessionById } from './db.js';
|
|
18
18
|
import { extractSessionTopic, classifyUserPrompt, tidyRequest } from '@phnx-labs/sessions-cli/reader';
|
|
19
19
|
import { readSessionTailWithRaw } from '@phnx-labs/sessions-cli/reader';
|
|
20
20
|
import { parseSession } from '@phnx-labs/sessions-cli/reader';
|
|
@@ -344,16 +344,17 @@ function readLiveTerminals() {
|
|
|
344
344
|
const windowHeartbeatMs = Number.isFinite(at) ? at : undefined;
|
|
345
345
|
const windowGone = windowHeartbeatMs !== undefined && now - windowHeartbeatMs >= HOST_HEARTBEAT_STALE_MS;
|
|
346
346
|
for (const e of (slice?.entries ?? [])) {
|
|
347
|
-
|
|
347
|
+
const key = e?.sessionId || (e?.terminalId ? `terminal\0${e.terminalId}` : undefined);
|
|
348
|
+
if (!key)
|
|
348
349
|
continue;
|
|
349
350
|
const alive = isPidAlive(e.pid, e.startedAtMs);
|
|
350
351
|
if (!alive && !windowGone)
|
|
351
352
|
continue;
|
|
352
|
-
const entry = { ...e, windowId, windowHeartbeatMs, pidDead: !alive };
|
|
353
|
-
const prev = merged.get(
|
|
353
|
+
const entry = { ...e, sessionId: e.sessionId || undefined, windowId, windowHeartbeatMs, pidDead: !alive };
|
|
354
|
+
const prev = merged.get(key);
|
|
354
355
|
if (prev && !prev.pidDead && !alive)
|
|
355
356
|
continue;
|
|
356
|
-
merged.set(
|
|
357
|
+
merged.set(key, entry);
|
|
357
358
|
}
|
|
358
359
|
}
|
|
359
360
|
return Array.from(merged.values());
|
|
@@ -465,10 +466,12 @@ function indexedSessionFileForId(kind, sessionId) {
|
|
|
465
466
|
return row.filePath || undefined;
|
|
466
467
|
}
|
|
467
468
|
const UUID_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
|
|
468
|
-
function sessionIdFromFile(file) {
|
|
469
|
+
export function sessionIdFromFile(kind, file) {
|
|
469
470
|
if (!file)
|
|
470
471
|
return undefined;
|
|
471
|
-
|
|
472
|
+
if (kind === 'claude')
|
|
473
|
+
return path.basename(file).match(UUID_RE)?.[0];
|
|
474
|
+
return indexedSessionIdForFile(kind, file);
|
|
472
475
|
}
|
|
473
476
|
const LIVE_STATE_MAX_EVENTS = 80;
|
|
474
477
|
function parseTailEventsForKind(agent, sessionFile) {
|
|
@@ -639,7 +642,7 @@ export async function listTeamsActive(opts = {}) {
|
|
|
639
642
|
const topic = sessionFile ? quickExtractTopic(sessionFile) : undefined;
|
|
640
643
|
const pidAlive = a.pid ? isPidAlive(a.pid) : true;
|
|
641
644
|
const { state, tokPerSec } = computeLiveSignals(a.agentType, sessionFile, a.cwd ?? undefined, pidAlive);
|
|
642
|
-
const resolvedId = ownSessionId ?? sessionIdFromFile(sessionFile);
|
|
645
|
+
const resolvedId = ownSessionId ?? sessionIdFromFile(a.agentType, sessionFile);
|
|
643
646
|
const execHost = a.hostName ? normalizeHost(a.hostName) : undefined;
|
|
644
647
|
const offloaded = execHost !== undefined && execHost !== self;
|
|
645
648
|
return applyState({
|
|
@@ -675,7 +678,7 @@ export async function listTerminalsActive() {
|
|
|
675
678
|
const children = childrenByParent(new Map([...procByPid.values()].map(r => [r.pid, r.ppid])));
|
|
676
679
|
const labelMap = buildClaudeLabelMap();
|
|
677
680
|
const runNameMap = buildRunNameMap();
|
|
678
|
-
return entries.
|
|
681
|
+
return entries.flatMap((t) => {
|
|
679
682
|
const directEntry = readPidSessionEntry(t.pid, procByPid.get(t.pid)?.startTime);
|
|
680
683
|
const candidate = directEntry?.sessionId ? directEntry
|
|
681
684
|
: (!t.pidDead ? terminalDescendantEntry(t.pid, procByPid, children) : undefined) ?? directEntry;
|
|
@@ -683,35 +686,38 @@ export async function listTerminalsActive() {
|
|
|
683
686
|
const resolvedId = pidEntry?.sessionId ?? t.sessionId;
|
|
684
687
|
const cwd = pidEntry?.cwd ?? t.cwd ?? undefined;
|
|
685
688
|
const sessionKind = pidEntry?.agent ?? t.kind;
|
|
686
|
-
|
|
689
|
+
if (!resolvedId && !isSessionTrackedAgent(sessionKind))
|
|
690
|
+
return [];
|
|
691
|
+
const sessionFile = resolvedId ? findSessionFileForKind(sessionKind, cwd, resolvedId) : undefined;
|
|
687
692
|
const label = t.label ?? (resolvedId ? labelMap.get(resolvedId) : undefined) ?? undefined;
|
|
688
693
|
const name = resolvedId ? runNameMap.get(resolvedId) ?? undefined : undefined;
|
|
689
694
|
const topic = sessionFile ? quickExtractTopic(sessionFile) : undefined;
|
|
690
695
|
const pidAlive = isPidAlive(t.pid, t.startedAtMs);
|
|
691
696
|
const { state, tokPerSec } = computeLiveSignals(sessionKind, sessionFile, cwd, pidAlive);
|
|
692
|
-
return applyState({
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
697
|
+
return [applyState({
|
|
698
|
+
context: 'terminal',
|
|
699
|
+
kind: sessionKind,
|
|
700
|
+
harness: pidEntry?.harness,
|
|
701
|
+
host: detectHost(t.pid, procByPid),
|
|
702
|
+
tty: procByPid.get(t.pid)?.tty,
|
|
703
|
+
pid: t.pid,
|
|
704
|
+
sessionId: resolvedId ?? sessionIdFromFile(sessionKind, sessionFile),
|
|
705
|
+
launchId: pidEntry?.launchId,
|
|
706
|
+
terminalId: pidEntry?.terminalId ?? t.terminalId,
|
|
707
|
+
originTerminal: pidEntry?.originTerminal,
|
|
708
|
+
tabIndex: t.tabIndex,
|
|
709
|
+
cwd,
|
|
710
|
+
label,
|
|
711
|
+
name,
|
|
712
|
+
topic,
|
|
713
|
+
tokPerSec,
|
|
714
|
+
sessionFile,
|
|
715
|
+
startedAtMs: pidEntry?.startedAtMs ?? t.startedAtMs,
|
|
716
|
+
lastActivityMs: sessionFileTimes(sessionFile).mtimeMs,
|
|
717
|
+
windowId: t.windowId,
|
|
718
|
+
windowHeartbeatMs: t.windowHeartbeatMs,
|
|
719
|
+
owner: resolveOwner(pidEntry?.actor, resolvedId),
|
|
720
|
+
}, state, sessionFile, pidAlive)];
|
|
715
721
|
});
|
|
716
722
|
}
|
|
717
723
|
function listCloudActive() {
|
|
@@ -871,6 +877,8 @@ export function resolveCwds(pids, probe = getCwdForPid) {
|
|
|
871
877
|
async function getCwdForPid(pid) {
|
|
872
878
|
if (process.platform === 'win32')
|
|
873
879
|
return undefined;
|
|
880
|
+
if (process.platform === 'linux')
|
|
881
|
+
return fs.promises.readlink(`/proc/${pid}/cwd`).catch(() => undefined);
|
|
874
882
|
let out;
|
|
875
883
|
try {
|
|
876
884
|
const res = await execFileAsync('lsof', ['-a', '-p', String(pid), '-d', 'cwd', '-Fn'], {
|
|
@@ -1052,7 +1060,7 @@ async function listUnattributedActiveLive(attributed) {
|
|
|
1052
1060
|
const context = host && UI_HOSTS.has(host) ? 'terminal' : 'headless';
|
|
1053
1061
|
const { state, tokPerSec } = computeLiveSignals(kind, sessionFile, cwd, true);
|
|
1054
1062
|
const { birthtimeMs, mtimeMs } = sessionFileTimes(sessionFile);
|
|
1055
|
-
const resolvedId = exactId ?? sessionIdFromFile(sessionFile);
|
|
1063
|
+
const resolvedId = exactId ?? sessionIdFromFile(kind, sessionFile);
|
|
1056
1064
|
const name = resolvedId ? runNameMap.get(resolvedId) ?? undefined : undefined;
|
|
1057
1065
|
const label = name;
|
|
1058
1066
|
out.push(applyState({
|
|
@@ -1075,6 +1083,7 @@ async function listUnattributedActiveLive(attributed) {
|
|
|
1075
1083
|
owner: resolveOwner(entry?.actor, resolvedId),
|
|
1076
1084
|
launchId: entry?.launchId ?? hookRec?.launch_id,
|
|
1077
1085
|
terminalId: entry?.terminalId ?? hookRec?.terminal_id,
|
|
1086
|
+
originTerminal: entry?.originTerminal,
|
|
1078
1087
|
}, state, sessionFile, true));
|
|
1079
1088
|
}
|
|
1080
1089
|
prunePidSessionRegistry(isPidAlive);
|
|
@@ -1187,7 +1196,7 @@ export async function listTmuxAgentSessions() {
|
|
|
1187
1196
|
harness: id.harness,
|
|
1188
1197
|
host: 'tmux',
|
|
1189
1198
|
pid,
|
|
1190
|
-
sessionId: id.sessionId ?? sessionIdFromFile(sessionFile),
|
|
1199
|
+
sessionId: id.sessionId ?? sessionIdFromFile(id.agent, sessionFile),
|
|
1191
1200
|
cwd,
|
|
1192
1201
|
topic,
|
|
1193
1202
|
tokPerSec,
|
|
@@ -1195,10 +1204,11 @@ export async function listTmuxAgentSessions() {
|
|
|
1195
1204
|
startedAtMs: liveEntry?.startedAtMs ?? birthtimeMs,
|
|
1196
1205
|
lastActivityMs: mtimeMs,
|
|
1197
1206
|
provenance,
|
|
1198
|
-
owner: resolveOwner(liveEntry?.actor, id.sessionId ?? sessionIdFromFile(sessionFile)),
|
|
1207
|
+
owner: resolveOwner(liveEntry?.actor, id.sessionId ?? sessionIdFromFile(id.agent, sessionFile)),
|
|
1199
1208
|
launchId: liveEntry?.launchId,
|
|
1200
1209
|
terminalId: liveEntry?.terminalId,
|
|
1201
|
-
|
|
1210
|
+
originTerminal: liveEntry?.originTerminal,
|
|
1211
|
+
paneId: id.sessionId ?? sessionIdFromFile(id.agent, sessionFile) ? undefined : pane,
|
|
1202
1212
|
tmuxName: sessName,
|
|
1203
1213
|
}, state, sessionFile, pidAlive));
|
|
1204
1214
|
}
|
|
@@ -1,48 +1,19 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
-
import * as os from 'os';
|
|
4
|
-
import * as yaml from 'yaml';
|
|
5
3
|
import { deriveShortId } from '../text/short-id.js';
|
|
6
4
|
import { getCacheDir } from '../state.js';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
const USER_YAML = path.join(os.homedir(), '.rush', 'user.yaml');
|
|
5
|
+
import { readToken, rushOrgHandle } from '../cloud/rush.js';
|
|
6
|
+
import { RUSH_API_BASE } from '../rush-api.js';
|
|
10
7
|
const CLOUD_CACHE_DIR = path.join(getCacheDir(), 'cloud-runs');
|
|
11
8
|
const CLOUD_EXECUTION_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
const raw = fs.readFileSync(USER_YAML, 'utf-8');
|
|
17
|
-
const data = yaml.parse(raw);
|
|
18
|
-
const token = data?.session?.access_token;
|
|
19
|
-
if (!token) {
|
|
20
|
-
throw new Error('No session token in ~/.rush/user.yaml. Run `rush login` first.');
|
|
21
|
-
}
|
|
22
|
-
const expiresAt = data.session?.expires_at;
|
|
23
|
-
if (isRushSessionExpired(expiresAt)) {
|
|
24
|
-
const expiredAt = new Date(expiresAt).toISOString();
|
|
25
|
-
throw new Error(`Rush session expired at ${expiredAt}. Run \`rush login\` to refresh.`);
|
|
26
|
-
}
|
|
27
|
-
return token;
|
|
28
|
-
}
|
|
29
|
-
async function api(method, endpoint, token) {
|
|
30
|
-
return fetch(`${PROXY_BASE}${endpoint}`, {
|
|
31
|
-
method,
|
|
32
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
9
|
+
async function api(endpoint, token, accept) {
|
|
10
|
+
return fetch(`${RUSH_API_BASE}${endpoint}`, {
|
|
11
|
+
headers: { Authorization: `Bearer ${token}`, ...(accept ? { Accept: accept } : {}) },
|
|
33
12
|
});
|
|
34
13
|
}
|
|
35
|
-
function
|
|
36
|
-
if (
|
|
37
|
-
return
|
|
38
|
-
if (agent === 'codex')
|
|
39
|
-
return 'codex';
|
|
40
|
-
if (agent === 'rush')
|
|
41
|
-
return 'rush';
|
|
42
|
-
if (agent === 'droid')
|
|
43
|
-
return 'droid';
|
|
44
|
-
if (agent === 'opencode')
|
|
45
|
-
return 'opencode';
|
|
14
|
+
function harnessToFormat(harness) {
|
|
15
|
+
if (harness === 'claude' || harness === 'codex' || harness === 'opencode')
|
|
16
|
+
return harness;
|
|
46
17
|
return null;
|
|
47
18
|
}
|
|
48
19
|
function assertContained(candidate, rootDir) {
|
|
@@ -65,21 +36,22 @@ function cachePathForExecution(executionId, agent) {
|
|
|
65
36
|
}
|
|
66
37
|
export async function discoverCloudSessions(options) {
|
|
67
38
|
const token = readToken();
|
|
39
|
+
const org = await rushOrgHandle(token);
|
|
68
40
|
const limit = options?.limit ?? 50;
|
|
69
|
-
const res = await api(
|
|
41
|
+
const res = await api(`/o/${encodeURIComponent(org)}/sessions?limit=${limit}`, token);
|
|
70
42
|
if (!res.ok) {
|
|
71
|
-
throw new Error(`cloud
|
|
43
|
+
throw new Error(`cloud sessions list failed (${res.status})`);
|
|
72
44
|
}
|
|
73
45
|
const data = (await res.json());
|
|
74
|
-
const rows = data.
|
|
46
|
+
const rows = data.sessions ?? [];
|
|
75
47
|
const out = [];
|
|
76
48
|
for (const row of rows) {
|
|
77
|
-
const agent =
|
|
49
|
+
const agent = harnessToFormat(row.harness);
|
|
78
50
|
if (!agent)
|
|
79
51
|
continue;
|
|
80
|
-
const id = validateCloudExecutionId(row.
|
|
52
|
+
const id = validateCloudExecutionId(row.id);
|
|
81
53
|
const timestamp = row.updated_at || row.created_at || new Date().toISOString();
|
|
82
|
-
const project = row.
|
|
54
|
+
const project = row.project ?? undefined;
|
|
83
55
|
const filePath = cachePathForExecution(id, agent);
|
|
84
56
|
out.push({
|
|
85
57
|
id,
|
|
@@ -88,7 +60,7 @@ export async function discoverCloudSessions(options) {
|
|
|
88
60
|
timestamp,
|
|
89
61
|
project,
|
|
90
62
|
filePath,
|
|
91
|
-
topic: row.prompt?.split('\n')[0]?.slice(0, 120),
|
|
63
|
+
topic: (row.title || row.prompt)?.split('\n')[0]?.slice(0, 120),
|
|
92
64
|
label: `[cloud/${row.status}]${row.branch ? ` ${row.branch}` : ''}`,
|
|
93
65
|
});
|
|
94
66
|
}
|
|
@@ -99,7 +71,8 @@ export async function ensureCloudSessionCached(executionId, destPath) {
|
|
|
99
71
|
const id = validateCloudExecutionId(executionId);
|
|
100
72
|
const callerPath = destPath ? assertContained(destPath, CLOUD_CACHE_DIR) : undefined;
|
|
101
73
|
const token = readToken();
|
|
102
|
-
const
|
|
74
|
+
const org = await rushOrgHandle(token);
|
|
75
|
+
const res = await api(`/o/${encodeURIComponent(org)}/p/_/sessions/${encodeURIComponent(id)}/trajectory`, token, 'application/x-ndjson');
|
|
103
76
|
if (!res.ok) {
|
|
104
77
|
const body = await res.text().catch(() => '');
|
|
105
78
|
throw new Error(`session.jsonl fetch ${res.status}: ${body.slice(0, 200)}`);
|
package/dist/lib/session/db.d.ts
CHANGED
|
@@ -105,6 +105,7 @@ export declare function latestSessionFileForCwd(agent: SessionAgentId, cwd: stri
|
|
|
105
105
|
maxAgeMs?: number;
|
|
106
106
|
nowMs?: number;
|
|
107
107
|
}): string | undefined;
|
|
108
|
+
export declare function indexedSessionIdForFile(agent: string, filePath: string): string | undefined;
|
|
108
109
|
export declare function getSessionExistenceCacheStats(): {
|
|
109
110
|
sweeps: number;
|
|
110
111
|
};
|
|
@@ -400,6 +401,7 @@ interface StoredBrowserSession extends Required<Pick<BrowserSessionRecord, 'task
|
|
|
400
401
|
}
|
|
401
402
|
export declare function listBrowserSessionRecords(profile?: string, opts?: {
|
|
402
403
|
limit?: number;
|
|
404
|
+
deviceKeys?: boolean;
|
|
403
405
|
}): StoredBrowserSession[];
|
|
404
406
|
export declare function getBrowserSessionRecord(profile: string, task: string): StoredBrowserSession | null;
|
|
405
407
|
interface StoredComputerSession {
|
package/dist/lib/session/db.js
CHANGED
|
@@ -17,6 +17,7 @@ import { discoverPlugins } from '../plugins/plugins.js';
|
|
|
17
17
|
import { machineId } from '../machine-id.js';
|
|
18
18
|
import { firstUserMessageFromEvents, lastUserMessageFromEvents } from '@phnx-labs/sessions-cli/reader';
|
|
19
19
|
import { emptyTimelineState, TIMELINE_EXTRACTOR_VERSION } from '@phnx-labs/sessions-cli/reader';
|
|
20
|
+
import { profileScopeSql } from '../browser/paths.js';
|
|
20
21
|
const SESSIONS_DIR = getSessionsDir();
|
|
21
22
|
const DB_PATH = getSessionsDbPath();
|
|
22
23
|
export const SCHEMA_VERSION = 52;
|
|
@@ -2229,6 +2230,14 @@ export function latestSessionFileForCwd(agent, cwd, options) {
|
|
|
2229
2230
|
}
|
|
2230
2231
|
return row.file_path;
|
|
2231
2232
|
}
|
|
2233
|
+
export function indexedSessionIdForFile(agent, filePath) {
|
|
2234
|
+
if (!filePath)
|
|
2235
|
+
return undefined;
|
|
2236
|
+
const row = getDB()
|
|
2237
|
+
.prepare(`SELECT id FROM sessions WHERE file_path = ? AND agent = ? LIMIT 1`)
|
|
2238
|
+
.get(filePath, agent);
|
|
2239
|
+
return row?.id;
|
|
2240
|
+
}
|
|
2232
2241
|
function buildSessionWhere(options) {
|
|
2233
2242
|
const where = [];
|
|
2234
2243
|
const params = [];
|
|
@@ -3569,10 +3578,10 @@ function toStoredBrowserSession(row) {
|
|
|
3569
3578
|
}
|
|
3570
3579
|
export function listBrowserSessionRecords(profile, opts = {}) {
|
|
3571
3580
|
const db = getDB();
|
|
3572
|
-
const
|
|
3573
|
-
?
|
|
3574
|
-
|
|
3575
|
-
|
|
3581
|
+
const where = !profile ? undefined
|
|
3582
|
+
: opts.deviceKeys ? profileScopeSql('profile', profile) : { sql: 'profile = ?', params: [profile] };
|
|
3583
|
+
const limit = profile ? opts.limit : opts.limit ?? TOOL_SESSION_LIST_LIMIT;
|
|
3584
|
+
const rows = db.prepare(`SELECT * FROM browser_sessions${where ? ` WHERE ${where.sql}` : ''} ORDER BY started_at DESC${limit === undefined ? '' : ' LIMIT ?'}`).all(...(where?.params ?? []), ...(limit === undefined ? [] : [limit]));
|
|
3576
3585
|
return rows.map(toStoredBrowserSession);
|
|
3577
3586
|
}
|
|
3578
3587
|
export function getBrowserSessionRecord(profile, task) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { SessionEvent
|
|
2
|
-
import type { ActiveSession } from './active.js';
|
|
1
|
+
import type { SessionEvent } from '@phnx-labs/sessions-cli/reader';
|
|
2
|
+
import type { ActiveSession, WatchSubagent } from './active.js';
|
|
3
|
+
export declare const SUBAGENT_PROMPT_MAX_CHARS = 400;
|
|
3
4
|
export declare function resolvedSubAgentCount(children: readonly string[] | undefined, toolCount: number): number;
|
|
4
5
|
export declare function claudeSubagentFiles(sessionFile: string): string[] | undefined;
|
|
5
|
-
export declare function readSessionSubagents(sessionFile: string, parentLive: boolean, failedCalls?: readonly string[], nowMs?: number):
|
|
6
|
+
export declare function readSessionSubagents(sessionFile: string, parentLive: boolean, failedCalls?: readonly string[], nowMs?: number): WatchSubagent[] | undefined;
|
|
6
7
|
export declare function hasOpenInlineImage(sessionId: string): boolean;
|
|
7
8
|
export declare function dropOpenInlineImage(sessionId: string): void;
|
|
8
9
|
export declare function appendInlineImage(sessionId: string, chunk: string, mediaType: string): void;
|
|
@@ -3,6 +3,7 @@ import * as path from 'node:path';
|
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
4
|
import { getUserAgentsDir } from '../state.js';
|
|
5
5
|
import { indexArtifactSidecars, mergeArtifacts, parseClaudeContent, sanitizeEvents } from '@phnx-labs/sessions-cli/reader';
|
|
6
|
+
export const SUBAGENT_PROMPT_MAX_CHARS = 400;
|
|
6
7
|
const directoryCache = new Map();
|
|
7
8
|
const childFolds = new Map();
|
|
8
9
|
const MAX_CHILD_BYTES_PER_READ = 256 * 1024;
|
|
@@ -39,11 +40,31 @@ function foldChildEvents(fold, events) {
|
|
|
39
40
|
}
|
|
40
41
|
if (event.type === 'tool_use' && !event._local)
|
|
41
42
|
fold.toolCount++;
|
|
43
|
+
if (event.role === 'assistant' && event.model && (event.type === 'message' || event.type === 'usage'))
|
|
44
|
+
fold.model = event.model;
|
|
42
45
|
if (event.type === 'message' && event.role === 'assistant' && event.content) {
|
|
43
46
|
fold.resultExcerpt = event.content.slice(0, 200);
|
|
44
47
|
}
|
|
48
|
+
if (event.type === 'message' && event.role === 'user' && !fold.promptDone)
|
|
49
|
+
foldPrompt(fold, event);
|
|
45
50
|
}
|
|
46
51
|
}
|
|
52
|
+
function foldPrompt(fold, event) {
|
|
53
|
+
if (fold.prompt !== undefined && event._turnId !== fold.promptTurnId) {
|
|
54
|
+
fold.promptDone = true;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (event._synthetic || event._meta)
|
|
58
|
+
return;
|
|
59
|
+
const text = (event.content ?? '').replace(/\s+/g, ' ').trim();
|
|
60
|
+
if (!text)
|
|
61
|
+
return;
|
|
62
|
+
const joined = fold.prompt ? `${fold.prompt} ${text}` : text;
|
|
63
|
+
fold.prompt = joined.length > SUBAGENT_PROMPT_MAX_CHARS ? joined.slice(0, SUBAGENT_PROMPT_MAX_CHARS) : joined;
|
|
64
|
+
fold.promptTurnId = event._turnId;
|
|
65
|
+
if (event._turnId === undefined || joined.length >= SUBAGENT_PROMPT_MAX_CHARS)
|
|
66
|
+
fold.promptDone = true;
|
|
67
|
+
}
|
|
47
68
|
function advanceChild(file, fold, size) {
|
|
48
69
|
if (size < fold.offset) {
|
|
49
70
|
fold.offset = 0;
|
|
@@ -52,6 +73,10 @@ function advanceChild(file, fold, size) {
|
|
|
52
73
|
fold.startedAtMs = undefined;
|
|
53
74
|
fold.endedAtMs = undefined;
|
|
54
75
|
fold.resultExcerpt = undefined;
|
|
76
|
+
fold.model = undefined;
|
|
77
|
+
fold.prompt = undefined;
|
|
78
|
+
fold.promptTurnId = undefined;
|
|
79
|
+
fold.promptDone = undefined;
|
|
55
80
|
}
|
|
56
81
|
const end = Math.min(size, fold.offset + MAX_CHILD_BYTES_PER_READ);
|
|
57
82
|
if (end <= fold.offset)
|
|
@@ -111,6 +136,10 @@ export function readSessionSubagents(sessionFile, parentLive, failedCalls = [],
|
|
|
111
136
|
startedAtMs: fold?.startedAtMs,
|
|
112
137
|
endedAtMs: fold?.endedAtMs,
|
|
113
138
|
resultExcerpt: fold?.resultExcerpt,
|
|
139
|
+
model: fold?.model,
|
|
140
|
+
prompt: fold?.prompt,
|
|
141
|
+
promptTurnId: fold?.promptTurnId,
|
|
142
|
+
promptDone: fold?.promptDone,
|
|
114
143
|
agentType: typeof meta.agentType === 'string' ? meta.agentType : '',
|
|
115
144
|
description: typeof meta.description === 'string' ? meta.description : '',
|
|
116
145
|
toolUseId: typeof meta.toolUseId === 'string' ? meta.toolUseId : undefined,
|
|
@@ -135,6 +164,8 @@ export function readSessionSubagents(sessionFile, parentLive, failedCalls = [],
|
|
|
135
164
|
...(fold.startedAtMs !== undefined ? { startedAtMs: fold.startedAtMs, endedAtMs: fold.endedAtMs } : {}),
|
|
136
165
|
toolCount: fold.toolCount,
|
|
137
166
|
...(fold.resultExcerpt ? { resultExcerpt: fold.resultExcerpt } : {}),
|
|
167
|
+
...(fold.model ? { model: fold.model } : {}),
|
|
168
|
+
...(fold.prompt ? { prompt: fold.prompt } : {}),
|
|
138
169
|
transcriptPath: file,
|
|
139
170
|
});
|
|
140
171
|
}
|
|
@@ -17,9 +17,19 @@ export function matchInjectSelector(session, token) {
|
|
|
17
17
|
}
|
|
18
18
|
export async function resolveLiveInjectTarget(selector) {
|
|
19
19
|
const sessions = await getActiveSessions();
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
20
|
+
const matches = sessions.filter((s) => matchInjectSelector(s, selector));
|
|
21
|
+
if (matches.length === 0)
|
|
22
22
|
return { target: null, reason: `No active session matches "${selector}".` };
|
|
23
|
+
const exact = matches.filter((s) => [s.sessionId, s.tmuxName, s.paneId, s.tmuxName && shortIdFromName(s.tmuxName)].includes(selector));
|
|
24
|
+
const candidates = exact.length > 0 ? exact : matches;
|
|
25
|
+
if (candidates.length > 1) {
|
|
26
|
+
const names = candidates.map((s) => s.tmuxName ?? s.sessionId ?? s.paneId).join(', ');
|
|
27
|
+
return {
|
|
28
|
+
target: null,
|
|
29
|
+
reason: `"${selector}" matches ${candidates.length} live sessions (${names}); pass a longer id.`,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const [match] = candidates;
|
|
23
33
|
const resolution = resolveInjectTargetForSession(match);
|
|
24
34
|
if (!resolution.addressable) {
|
|
25
35
|
return {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LaunchOrigin } from '../launch-identity.js';
|
|
1
2
|
export interface PidSessionEntry {
|
|
2
3
|
pid: number;
|
|
3
4
|
agent: string;
|
|
@@ -8,6 +9,7 @@ export interface PidSessionEntry {
|
|
|
8
9
|
initiatedBy?: 'human' | 'agent';
|
|
9
10
|
launchId?: string;
|
|
10
11
|
terminalId?: string;
|
|
12
|
+
originTerminal?: LaunchOrigin;
|
|
11
13
|
tmuxPane?: string;
|
|
12
14
|
startedAtMs: number;
|
|
13
15
|
processIdentity?: {
|
|
@@ -139,12 +139,16 @@ function persistOwnership(entry) {
|
|
|
139
139
|
atomicWriteFileSync(ownershipPath(entry.pid), JSON.stringify(entry), 'utf8');
|
|
140
140
|
}
|
|
141
141
|
function restoreOwnership(entry) {
|
|
142
|
-
if (entry.processIdentity)
|
|
142
|
+
if (entry.processIdentity && (entry.originTerminal || !entry.terminalId || !entry.launchId))
|
|
143
143
|
return entry;
|
|
144
144
|
try {
|
|
145
145
|
const owner = JSON.parse(fs.readFileSync(ownershipPath(entry.pid), 'utf8'));
|
|
146
146
|
if (owner.pid === entry.pid && owner.launchId === entry.launchId && owner.startedAtMs === entry.startedAtMs) {
|
|
147
|
-
return {
|
|
147
|
+
return {
|
|
148
|
+
...entry,
|
|
149
|
+
processIdentity: entry.processIdentity ?? owner.processIdentity,
|
|
150
|
+
...(entry.originTerminal ?? owner.originTerminal ? { originTerminal: entry.originTerminal ?? owner.originTerminal } : {}),
|
|
151
|
+
};
|
|
148
152
|
}
|
|
149
153
|
}
|
|
150
154
|
catch { }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type FilterOptions, type SessionMeta, type ViewMode } from '@phnx-labs/sessions-cli/reader';
|
|
2
|
+
import type { ActiveSession } from './active.js';
|
|
3
|
+
export declare function signalBadges(s: Pick<ActiveSession, 'awaitingReason' | 'pr' | 'worktree' | 'ticket'>): string;
|
|
4
|
+
export interface TranscriptRenderOptions {
|
|
5
|
+
json?: boolean;
|
|
6
|
+
markdown?: boolean;
|
|
7
|
+
redact?: boolean;
|
|
8
|
+
include?: string;
|
|
9
|
+
exclude?: string;
|
|
10
|
+
first?: string;
|
|
11
|
+
last?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function metaSignals(s: SessionMeta): Parameters<typeof signalBadges>[0];
|
|
14
|
+
export declare function buildFilterOptions(options: TranscriptRenderOptions): FilterOptions;
|
|
15
|
+
export declare function hasAnyFilter(opts: FilterOptions): boolean;
|
|
16
|
+
export declare function resolveViewMode(options: TranscriptRenderOptions, filters: FilterOptions): ViewMode;
|
|
17
|
+
export declare function renderSessionLog(session: SessionMeta, mode?: ViewMode): Promise<void>;
|
|
18
|
+
export declare function renderSessionLogJson(session: SessionMeta): Promise<void>;
|
|
19
|
+
export declare function renderSession(session: SessionMeta, mode: ViewMode, filters: FilterOptions, options?: {
|
|
20
|
+
redact?: boolean;
|
|
21
|
+
}): Promise<void>;
|