@phnx-labs/agents-cli 1.23.21 → 1.23.22
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 +111 -0
- package/README.md +17 -0
- package/dist/bootstrap.js +5 -4
- package/dist/cli/command-registry.js +2 -0
- package/dist/commands/config.js +16 -0
- package/dist/commands/daemon.js +3 -3
- package/dist/commands/doctor.js +10 -19
- package/dist/commands/events.js +1 -14
- package/dist/commands/feed-watch.js +5 -2
- package/dist/commands/go.js +2 -2
- package/dist/commands/lead.d.ts +3 -0
- package/dist/commands/lead.js +280 -0
- package/dist/commands/projects.js +3 -2
- package/dist/commands/ps-roster.d.ts +2 -12
- package/dist/commands/ps-roster.js +5 -87
- package/dist/commands/ps.js +3 -1
- package/dist/commands/repo.js +12 -12
- package/dist/commands/resource-view.js +5 -5
- package/dist/commands/sessions-browser.js +2 -2
- package/dist/commands/sessions-watch.js +5 -2
- package/dist/commands/setup-secrets.d.ts +3 -4
- package/dist/commands/setup-secrets.js +15 -46
- package/dist/commands/setup-session-backup.js +1 -1
- package/dist/commands/ssh.d.ts +0 -4
- package/dist/commands/ssh.js +14 -81
- package/dist/commands/teams-picker.js +1 -12
- package/dist/commands/teams.js +1 -13
- package/dist/commands/view.d.ts +1 -40
- package/dist/commands/view.js +9 -330
- package/dist/commands/watchdog.js +4 -4
- package/dist/index.js +4 -0
- package/dist/lib/accounting/usage.d.ts +0 -1
- package/dist/lib/accounting/usage.js +1 -112
- package/dist/lib/accounts/add.js +1 -1
- package/dist/lib/accounts/migrate.js +1 -1
- package/dist/lib/auto-pull-worker.js +2 -16
- package/dist/lib/auto-pull.d.ts +1 -0
- package/dist/lib/auto-pull.js +27 -0
- package/dist/lib/browser-client.js +2 -11
- package/dist/lib/cloud/codex.js +3 -0
- package/dist/lib/commands.d.ts +0 -6
- package/dist/lib/commands.js +3 -116
- package/dist/lib/comms-render.d.ts +1 -7
- package/dist/lib/comms-render.js +0 -19
- package/dist/lib/computer-client.js +2 -11
- package/dist/lib/config-keys.d.ts +7 -3
- package/dist/lib/config-keys.js +15 -2
- package/dist/lib/crabbox/runtimes.d.ts +0 -14
- package/dist/lib/crabbox/runtimes.js +0 -80
- package/dist/lib/daemon/attention-notify-service.d.ts +51 -28
- package/dist/lib/daemon/attention-notify-service.js +219 -53
- package/dist/lib/daemon/daemon.js +1 -2
- package/dist/lib/daemon/feed-stream-service.js +2 -4
- package/dist/lib/device-config.d.ts +0 -5
- package/dist/lib/device-config.js +20 -27
- package/dist/lib/devices/doctor-findings.d.ts +2 -1
- package/dist/lib/devices/doctor-findings.js +12 -1
- package/dist/lib/devices/fleet.d.ts +6 -0
- package/dist/lib/devices/fleet.js +15 -0
- package/dist/lib/devices/harness-inventory.d.ts +9 -0
- package/dist/lib/devices/harness-inventory.js +66 -0
- package/dist/lib/exec.js +1 -3
- package/dist/lib/feed/attention.d.ts +16 -1
- package/dist/lib/feed/attention.js +63 -1
- package/dist/lib/feed/feed.d.ts +1 -1
- package/dist/lib/feed/feed.js +12 -2
- package/dist/lib/feed/hub.d.ts +9 -0
- package/dist/lib/feed/hub.js +27 -1
- package/dist/lib/feed/notify-schedule.d.ts +16 -0
- package/dist/lib/feed/notify-schedule.js +62 -0
- package/dist/lib/feed/ticket-priority.d.ts +4 -0
- package/dist/lib/feed/ticket-priority.js +30 -0
- package/dist/lib/feed/watch.d.ts +1 -0
- package/dist/lib/feed/watch.js +27 -3
- package/dist/lib/feed-ranking.d.ts +1 -0
- package/dist/lib/feed-ranking.js +3 -1
- package/dist/lib/format.d.ts +0 -2
- package/dist/lib/format.js +0 -8
- package/dist/lib/helper-versions.js +1 -1
- package/dist/lib/hooks/cache.d.ts +1 -0
- package/dist/lib/hooks/cache.js +12 -1
- package/dist/lib/installations/duplicate-prune.d.ts +37 -0
- package/dist/lib/installations/duplicate-prune.js +85 -0
- package/dist/lib/installations/inventory-json.d.ts +20 -0
- package/dist/lib/installations/inventory-json.js +252 -0
- package/dist/lib/installations/shims.d.ts +0 -18
- package/dist/lib/installations/shims.js +1 -257
- package/dist/lib/lead/brief.d.ts +49 -0
- package/dist/lib/lead/brief.js +173 -0
- package/dist/lib/lead/client.d.ts +21 -0
- package/dist/lib/lead/client.js +167 -0
- package/dist/lib/lead/confirm.d.ts +22 -0
- package/dist/lib/lead/confirm.js +73 -0
- package/dist/lib/lead/events.d.ts +106 -0
- package/dist/lib/lead/events.js +188 -0
- package/dist/lib/lead/harness.d.ts +29 -0
- package/dist/lib/lead/harness.js +107 -0
- package/dist/lib/lead/host.d.ts +132 -0
- package/dist/lib/lead/host.js +675 -0
- package/dist/lib/lead/paths.d.ts +22 -0
- package/dist/lib/lead/paths.js +69 -0
- package/dist/lib/lead/refs.d.ts +17 -0
- package/dist/lib/lead/refs.js +75 -0
- package/dist/lib/lead/roster.d.ts +26 -0
- package/dist/lib/lead/roster.js +121 -0
- package/dist/lib/lead/shapes.d.ts +23 -0
- package/dist/lib/lead/shapes.js +95 -0
- package/dist/lib/lead/store.d.ts +46 -0
- package/dist/lib/lead/store.js +77 -0
- package/dist/lib/lead/tools.d.ts +18 -0
- package/dist/lib/lead/tools.js +106 -0
- package/dist/lib/lead/visibility.d.ts +16 -0
- package/dist/lib/lead/visibility.js +77 -0
- package/dist/lib/mailbox.d.ts +0 -18
- package/dist/lib/mailbox.js +0 -170
- package/dist/lib/menubar/notify-desktop.d.ts +5 -0
- package/dist/lib/menubar/notify-desktop.js +24 -0
- package/dist/lib/models.js +1 -19
- package/dist/lib/permissions.d.ts +0 -6
- package/dist/lib/permissions.js +0 -140
- package/dist/lib/platform/process.d.ts +1 -0
- package/dist/lib/platform/process.js +5 -0
- package/dist/lib/probe.js +13 -1
- package/dist/lib/project-status.js +4 -3
- package/dist/lib/projects.d.ts +9 -0
- package/dist/lib/projects.js +61 -3
- package/dist/lib/scheduling/routines.d.ts +1 -13
- package/dist/lib/scheduling/routines.js +1 -37
- package/dist/lib/secrets-cli.d.ts +3 -3
- package/dist/lib/secrets-cli.js +1 -1
- package/dist/lib/secrets-client.d.ts +4 -37
- package/dist/lib/secrets-client.js +19 -265
- package/dist/lib/session/active.d.ts +18 -8
- package/dist/lib/session/active.js +94 -18
- package/dist/lib/session/db.d.ts +0 -16
- package/dist/lib/session/db.js +1 -134
- package/dist/lib/session/detached.d.ts +0 -1
- package/dist/lib/session/detached.js +0 -18
- package/dist/lib/session/pending-work.d.ts +21 -0
- package/dist/lib/session/pending-work.js +284 -0
- package/dist/lib/session/remote/remote-list.d.ts +0 -3
- package/dist/lib/session/remote/remote-list.js +1 -23
- package/dist/lib/session/remote/watch.d.ts +5 -0
- package/dist/lib/session/remote/watch.js +19 -2
- package/dist/lib/session/session-cache.d.ts +1 -1
- package/dist/lib/session/session-cache.js +12 -5
- package/dist/lib/session/sync/provision.js +1 -2
- package/dist/lib/smart-launch.js +7 -2
- package/dist/lib/snapshot.js +3 -4
- package/dist/lib/ssh-exec.d.ts +0 -40
- package/dist/lib/ssh-exec.js +0 -108
- package/dist/lib/ssh-tunnel.d.ts +0 -6
- package/dist/lib/ssh-tunnel.js +0 -42
- package/dist/lib/standalone-tools.js +12 -1
- package/dist/lib/startup/command-registry.js +1 -1
- package/dist/lib/startup/spellcheck.d.ts +0 -1
- package/dist/lib/startup/spellcheck.js +1 -20
- package/dist/lib/state.d.ts +0 -6
- package/dist/lib/state.js +1 -14
- package/dist/lib/teams/delivery.d.ts +1 -0
- package/dist/lib/teams/delivery.js +13 -0
- package/dist/lib/types.d.ts +0 -37
- package/dist/lib/types.js +0 -9
- package/dist/lib/watchdog/log.d.ts +1 -1
- package/dist/lib/watchdog/log.js +6 -4
- package/package.json +2 -1
- package/dist/lib/artifact-actions.d.ts +0 -7
- package/dist/lib/artifact-actions.js +0 -39
- package/dist/lib/session/sync/managed-config.d.ts +0 -3
- package/dist/lib/session/sync/managed-config.js +0 -3
- package/dist/lib/session/sync/worker-template.d.ts +0 -1
- package/dist/lib/session/sync/worker-template.js +0 -807
- package/dist/lib/storage/selection.d.ts +0 -8
- package/dist/lib/storage/selection.js +0 -10
- package/dist/lib/watchdog/index.d.ts +0 -3
- package/dist/lib/watchdog/index.js +0 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { writerProcessView } from './process-view.js';
|
|
2
|
+
import { markLeadSessions } from '../lead/visibility.js';
|
|
2
3
|
import { span, spanSync } from '../daemon/diagnostics.js';
|
|
3
4
|
import * as fs from 'fs';
|
|
4
5
|
import * as path from 'path';
|
|
@@ -10,7 +11,7 @@ import { AgentManager } from '../teams/agents.js';
|
|
|
10
11
|
import { getTerminalsDir, readMeta } from '../state.js';
|
|
11
12
|
import { listNativeAccounts } from '../account-registry.js';
|
|
12
13
|
import { parseNativeIdentityKey } from '../native-accounts.js';
|
|
13
|
-
import { readLivePidSessionEntry as readPidSessionEntry, listPidSessionEntries, prunePidSessionRegistry, sessionIdFromLivePid,
|
|
14
|
+
import { readLivePidSessionEntry as readPidSessionEntry, listPidSessionEntries, prunePidSessionRegistry, sessionIdFromLivePid, } from './pid-registry.js';
|
|
14
15
|
import { readSessionActorRecord, writeSessionAliasRecord } from './actor-sidecar.js';
|
|
15
16
|
import { loadHookSessionIndex, resolveHookSessionRecord, readStateSessionRecord } from './hook-sessions.js';
|
|
16
17
|
import { buildClaudeLabelMap, getAgentSessionDirs } from './discover.js';
|
|
@@ -23,7 +24,7 @@ import { computeTokPerSec } from './throughput.js';
|
|
|
23
24
|
import { inferSessionState } from '@phnx-labs/sessions-cli/reader';
|
|
24
25
|
import { isSessionTrackedAgent, SESSION_AGENTS, AG_TMUX_NAME_RE } from '@phnx-labs/sessions-cli/reader';
|
|
25
26
|
import { AGENTS } from '../agents.js';
|
|
26
|
-
import { confirmedProjectForCwd, listProjectDefsCached } from '../projects.js';
|
|
27
|
+
import { canonicalProjectName, confirmedProjectForCwd, listProjectDefsCached } from '../projects.js';
|
|
27
28
|
import { detectProvenance } from './provenance.js';
|
|
28
29
|
import { loadDevices } from '../devices/registry.js';
|
|
29
30
|
import { machineId, normalizeHost } from '../machine-id.js';
|
|
@@ -33,6 +34,8 @@ import { mapBounded } from '../concurrency.js';
|
|
|
33
34
|
import { linearIssueUrl } from '@phnx-labs/sessions-cli/reader';
|
|
34
35
|
import { viewingInLabel } from './viewing-in.js';
|
|
35
36
|
import { claudeProjectDirName } from '../project-key.js';
|
|
37
|
+
import { gatherRemoteActive, NO_FANOUT_ENV } from './remote-active.js';
|
|
38
|
+
import { hostToken, remoteHostsToDial, shouldIncludeLocal } from './remote-list.js';
|
|
36
39
|
const execFileAsync = promisify(execFile);
|
|
37
40
|
export function resolveOwner(pidActor, sessionId) {
|
|
38
41
|
return pidActor ?? (sessionId ? readSessionActorRecord(sessionId)?.actor : undefined) ?? undefined;
|
|
@@ -178,9 +181,9 @@ export function isRunningLiveSession(s) {
|
|
|
178
181
|
// Unknown liveness from an older peer is not enough for bare --active.
|
|
179
182
|
return Boolean(s.machine) && typeof s.pid === 'number' && s.pid > 0 && s.pidAlive === true;
|
|
180
183
|
}
|
|
181
|
-
export function activeSessionProjectKey(s) {
|
|
184
|
+
export function activeSessionProjectKey(s, defs = listProjectDefsCached()) {
|
|
182
185
|
if (s.cwd)
|
|
183
|
-
return path.basename(s.cwd);
|
|
186
|
+
return canonicalProjectName(path.basename(s.cwd), defs);
|
|
184
187
|
return s.context === 'cloud' ? 'cloud' : 'other';
|
|
185
188
|
}
|
|
186
189
|
const ARTIFACT_KINDS = [
|
|
@@ -198,7 +201,7 @@ export function serializeActiveSessionsForJson(sessions) {
|
|
|
198
201
|
return sessions.map((s) => ({
|
|
199
202
|
...s,
|
|
200
203
|
ticketId: s.ticket?.id ?? null,
|
|
201
|
-
project: activeSessionProjectKey(s),
|
|
204
|
+
project: activeSessionProjectKey(s, defs),
|
|
202
205
|
confirmedProject: confirmedProjectForCwd(s.cwd, defs) ?? null,
|
|
203
206
|
prLink: s.pr?.url ?? null,
|
|
204
207
|
viewingIn: viewingInLabel(s) ?? null,
|
|
@@ -1308,6 +1311,7 @@ export async function getActiveSessions(opts = {}) {
|
|
|
1308
1311
|
annotateOrchestratorLabels(merged);
|
|
1309
1312
|
foldRecap(merged);
|
|
1310
1313
|
foldPhase(merged);
|
|
1314
|
+
markLeadSessions(merged);
|
|
1311
1315
|
}, count(merged));
|
|
1312
1316
|
return merged;
|
|
1313
1317
|
}
|
|
@@ -1322,19 +1326,6 @@ export async function describeActiveDiscoveryHealth() {
|
|
|
1322
1326
|
}
|
|
1323
1327
|
return { degradedSources };
|
|
1324
1328
|
}
|
|
1325
|
-
export async function isSessionIdLiveOnProcessTable(sessionId, deps = {}) {
|
|
1326
|
-
if (!isSessionIdShape(sessionId))
|
|
1327
|
-
return false;
|
|
1328
|
-
const readTable = deps.readTable ?? (async () => readProcessTable());
|
|
1329
|
-
const sessionIdOf = deps.sessionIdOf ?? sessionIdFromLivePid;
|
|
1330
|
-
for (const row of await readTable()) {
|
|
1331
|
-
if (!row.kind)
|
|
1332
|
-
continue;
|
|
1333
|
-
if (sessionIdOf(row.pid) === sessionId)
|
|
1334
|
-
return true;
|
|
1335
|
-
}
|
|
1336
|
-
return false;
|
|
1337
|
-
}
|
|
1338
1329
|
export async function foldTmuxClients(rows) {
|
|
1339
1330
|
const tmuxRows = rows.filter((s) => s.provenance?.mux?.kind === 'tmux' && s.provenance.mux.pane);
|
|
1340
1331
|
if (tmuxRows.length === 0)
|
|
@@ -1626,3 +1617,88 @@ export function dedupeBySession(sessions) {
|
|
|
1626
1617
|
}
|
|
1627
1618
|
return out;
|
|
1628
1619
|
}
|
|
1620
|
+
export function dedupeByMachineSession(sessions, answered) {
|
|
1621
|
+
const heard = new Set(answered.map(normalizeHost));
|
|
1622
|
+
const seen = new Map();
|
|
1623
|
+
const out = [];
|
|
1624
|
+
for (const s of sessions) {
|
|
1625
|
+
if (!s.sessionId) {
|
|
1626
|
+
out.push(s);
|
|
1627
|
+
continue;
|
|
1628
|
+
}
|
|
1629
|
+
const key = `${s.machine ?? ''}:${s.sessionId}`;
|
|
1630
|
+
const at = seen.get(key);
|
|
1631
|
+
if (at === undefined) {
|
|
1632
|
+
seen.set(key, out.length);
|
|
1633
|
+
out.push(s);
|
|
1634
|
+
continue;
|
|
1635
|
+
}
|
|
1636
|
+
if (out[at].offloadedFrom && !s.offloadedFrom)
|
|
1637
|
+
out[at] = s;
|
|
1638
|
+
}
|
|
1639
|
+
return out.filter(s => !(s.sessionId && s.offloadedFrom && s.context !== 'teams' && s.machine && heard.has(normalizeHost(s.machine))));
|
|
1640
|
+
}
|
|
1641
|
+
export function filterActiveSessionsByHostScope(sessions, hosts, self) {
|
|
1642
|
+
if (!hosts || hosts.length === 0)
|
|
1643
|
+
return sessions;
|
|
1644
|
+
const wanted = new Set(hosts.map(hostToken));
|
|
1645
|
+
return sessions.filter((s) => wanted.has(s.machine ?? self));
|
|
1646
|
+
}
|
|
1647
|
+
export async function gatherActiveSessions(opts = {}) {
|
|
1648
|
+
const forceRefresh = opts.forceRefresh === true
|
|
1649
|
+
|| process.env.AGENTS_SESSIONS_FORCE_REFRESH === '1'
|
|
1650
|
+
|| process.env[NO_FANOUT_ENV] === '1';
|
|
1651
|
+
const scoped = (opts.hosts?.length ?? 0) > 0;
|
|
1652
|
+
if (opts.local && !scoped) {
|
|
1653
|
+
const { loadLocalActiveSessions } = await import('./session-cache.js');
|
|
1654
|
+
const loaded = await loadLocalActiveSessions({ forceRefresh });
|
|
1655
|
+
const self = machineId();
|
|
1656
|
+
for (const s of loaded.sessions)
|
|
1657
|
+
if (!s.machine)
|
|
1658
|
+
s.machine = self;
|
|
1659
|
+
return { sessions: loaded.sessions, remoteDeviceCount: 0 };
|
|
1660
|
+
}
|
|
1661
|
+
if (!opts.local && !scoped) {
|
|
1662
|
+
const { loadFleetActiveSessions } = await import('./session-cache.js');
|
|
1663
|
+
const loaded = await loadFleetActiveSessions({
|
|
1664
|
+
forceRefresh,
|
|
1665
|
+
gather: () => gatherActiveSessionsLive({ local: false }),
|
|
1666
|
+
});
|
|
1667
|
+
return {
|
|
1668
|
+
sessions: loaded.sessions,
|
|
1669
|
+
remoteDeviceCount: loaded.remoteDeviceCount,
|
|
1670
|
+
remoteSkipped: loaded.remoteSkipped,
|
|
1671
|
+
remoteDiscoveryFailed: loaded.remoteDiscoveryFailed,
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
return gatherActiveSessionsLive(opts);
|
|
1675
|
+
}
|
|
1676
|
+
async function gatherActiveSessionsLive(opts = {}) {
|
|
1677
|
+
const self = machineId();
|
|
1678
|
+
const local = shouldIncludeLocal(opts.hosts, self)
|
|
1679
|
+
? await getActiveSessions({ localOnly: opts.local })
|
|
1680
|
+
: [];
|
|
1681
|
+
for (const s of local)
|
|
1682
|
+
if (!s.machine)
|
|
1683
|
+
s.machine = self;
|
|
1684
|
+
let remoteDeviceCount = 0;
|
|
1685
|
+
let remoteSkipped = [];
|
|
1686
|
+
let remoteDiscoveryFailed = false;
|
|
1687
|
+
let merged = local;
|
|
1688
|
+
if (!opts.local) {
|
|
1689
|
+
const remoteHosts = remoteHostsToDial(opts.hosts, self);
|
|
1690
|
+
if (!opts.hosts?.length || (remoteHosts && remoteHosts.length > 0)) {
|
|
1691
|
+
const remote = await gatherRemoteActive(remoteHosts);
|
|
1692
|
+
remoteDeviceCount = remote.deviceCount;
|
|
1693
|
+
remoteSkipped = remote.skipped;
|
|
1694
|
+
remoteDiscoveryFailed = remote.discoveryFailed;
|
|
1695
|
+
merged = dedupeByMachineSession([...local, ...remote.sessions], remote.answered);
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
return {
|
|
1699
|
+
sessions: filterActiveSessionsByHostScope(merged, opts.hosts, self),
|
|
1700
|
+
remoteDeviceCount,
|
|
1701
|
+
remoteSkipped,
|
|
1702
|
+
remoteDiscoveryFailed,
|
|
1703
|
+
};
|
|
1704
|
+
}
|
package/dist/lib/session/db.d.ts
CHANGED
|
@@ -6,8 +6,6 @@ import { type TimelineState } from '@phnx-labs/sessions-cli/reader';
|
|
|
6
6
|
export declare const SCHEMA_VERSION = 52;
|
|
7
7
|
export declare const CONTENT_INDEX_VERSION = 7;
|
|
8
8
|
export declare const INSIGHTS_EXTRACTOR_VERSION = 7;
|
|
9
|
-
export declare const SESSION_TOPIC_EXTRACTOR_VERSION = 2;
|
|
10
|
-
export declare const SESSION_PHENOTYPE_EXTRACTOR_VERSION = 1;
|
|
11
9
|
export declare const SESSION_SUMMARY_EXTRACTOR_VERSION = 1;
|
|
12
10
|
export interface ScanStamp {
|
|
13
11
|
fileMtimeMs: number;
|
|
@@ -133,20 +131,6 @@ export declare function writeSessionInsights<T>(entries: Array<{
|
|
|
133
131
|
facets: T;
|
|
134
132
|
}>): void;
|
|
135
133
|
export declare function clearSessionInsights(): void;
|
|
136
|
-
export declare function readSessionTopics<T>(ids: string[]): Map<string, T>;
|
|
137
|
-
export declare function writeSessionTopics<T>(entries: Array<{
|
|
138
|
-
id: string;
|
|
139
|
-
fileMtimeMs: number | null;
|
|
140
|
-
fileSize: number | null;
|
|
141
|
-
topic: T;
|
|
142
|
-
}>): void;
|
|
143
|
-
export declare function readSessionPhenotypes<T>(ids: string[]): Map<string, T>;
|
|
144
|
-
export declare function writeSessionPhenotypes<T>(entries: Array<{
|
|
145
|
-
id: string;
|
|
146
|
-
fileMtimeMs: number | null;
|
|
147
|
-
fileSize: number | null;
|
|
148
|
-
phenotype: T;
|
|
149
|
-
}>): void;
|
|
150
134
|
export declare function readSessionPreviewCache<T>(id: string, sourceStamp: {
|
|
151
135
|
fileMtimeMs: number | null;
|
|
152
136
|
fileSize: number | null;
|
package/dist/lib/session/db.js
CHANGED
|
@@ -329,37 +329,6 @@ CREATE TABLE IF NOT EXISTS session_insights (
|
|
|
329
329
|
facets TEXT NOT NULL
|
|
330
330
|
);
|
|
331
331
|
|
|
332
|
-
-- Derived topic classification for traces sync. Like session_insights, this is
|
|
333
|
-
-- a lazy, stamp-validated cache and is intentionally independent of SCHEMA_VERSION.
|
|
334
|
-
CREATE TABLE IF NOT EXISTS session_topics (
|
|
335
|
-
session_id TEXT PRIMARY KEY,
|
|
336
|
-
file_mtime_ms INTEGER,
|
|
337
|
-
file_size INTEGER,
|
|
338
|
-
extractor_version INTEGER NOT NULL,
|
|
339
|
-
computed_at INTEGER NOT NULL,
|
|
340
|
-
topic_json TEXT NOT NULL
|
|
341
|
-
);
|
|
342
|
-
|
|
343
|
-
-- Derived failure phenotype for traces sync (PHNX-3327). Like session_topics /
|
|
344
|
-
-- session_insights, this is a lazy, stamp-validated cache keyed on
|
|
345
|
-
-- (file_mtime_ms, file_size) and intentionally independent of SCHEMA_VERSION.
|
|
346
|
-
-- Classifying a phenotype needs the full derived SessionTrajectory (ordered
|
|
347
|
-
-- steps, gaps), which buildIndexShard does NOT have from flat tool_calls rows —
|
|
348
|
-
-- so it is computed per-session ONCE (parse -> trajectory -> classify) and cached
|
|
349
|
-
-- here, then read for the WHOLE corpus on every sync. That is what lets the
|
|
350
|
-
-- phenotype grouping dimension fold two identically-signatured sessions into one
|
|
351
|
-
-- cluster regardless of which incremental batch each was first synced in, without
|
|
352
|
-
-- re-parsing transcripts at 10k+ session scale. phenotype_json holds
|
|
353
|
-
-- { phenotype: FailurePhenotype | null } (null = no failure phenotype matched).
|
|
354
|
-
CREATE TABLE IF NOT EXISTS session_phenotypes (
|
|
355
|
-
session_id TEXT PRIMARY KEY,
|
|
356
|
-
file_mtime_ms INTEGER,
|
|
357
|
-
file_size INTEGER,
|
|
358
|
-
extractor_version INTEGER NOT NULL,
|
|
359
|
-
computed_at INTEGER NOT NULL,
|
|
360
|
-
phenotype_json TEXT NOT NULL
|
|
361
|
-
);
|
|
362
|
-
|
|
363
332
|
-- Normalized data behind sessions preview. Like session_insights this is a
|
|
364
333
|
-- lazy, stamp-validated cache: opening one session parses only that transcript,
|
|
365
334
|
-- while subsequent processes reuse the derived preview until its bytes change.
|
|
@@ -506,9 +475,7 @@ CREATE TABLE IF NOT EXISTS session_remote_preview_cache (
|
|
|
506
475
|
CREATE INDEX IF NOT EXISTS idx_remote_preview_cache_fetched ON session_remote_preview_cache(fetched_at DESC);
|
|
507
476
|
`;
|
|
508
477
|
export const INSIGHTS_EXTRACTOR_VERSION = 7;
|
|
509
|
-
export const SESSION_TOPIC_EXTRACTOR_VERSION = 2;
|
|
510
478
|
const PREVIEW_EXTRACTOR_VERSION = 5;
|
|
511
|
-
export const SESSION_PHENOTYPE_EXTRACTOR_VERSION = 1;
|
|
512
479
|
export const SESSION_SUMMARY_EXTRACTOR_VERSION = 1;
|
|
513
480
|
let dbInstance = null;
|
|
514
481
|
function migrateSchema(db, fromVersion) {
|
|
@@ -1818,7 +1785,7 @@ function reconcileCodexFileOwners(db, metas) {
|
|
|
1818
1785
|
continue;
|
|
1819
1786
|
db.prepare(`DELETE FROM session_text WHERE rowid = ${SESSION_TEXT_ROWID}`).run(row.id);
|
|
1820
1787
|
db.prepare('DELETE FROM sessions WHERE id = ?').run(row.id);
|
|
1821
|
-
for (const table of ['session_preview_cache', 'session_summaries', 'session_insights', '
|
|
1788
|
+
for (const table of ['session_preview_cache', 'session_summaries', 'session_insights', 'session_resource_usage', 'resource_scan_ledger']) {
|
|
1822
1789
|
db.prepare(`DELETE FROM ${table} WHERE session_id = ?`).run(row.id);
|
|
1823
1790
|
}
|
|
1824
1791
|
purgeToolCalls(db, row.id);
|
|
@@ -2500,106 +2467,6 @@ export function writeSessionInsights(entries) {
|
|
|
2500
2467
|
export function clearSessionInsights() {
|
|
2501
2468
|
getDB().exec(`DELETE FROM session_insights`);
|
|
2502
2469
|
}
|
|
2503
|
-
export function readSessionTopics(ids) {
|
|
2504
|
-
const db = getDB();
|
|
2505
|
-
const out = new Map();
|
|
2506
|
-
if (ids.length === 0)
|
|
2507
|
-
return out;
|
|
2508
|
-
const CHUNK = 400;
|
|
2509
|
-
for (let i = 0; i < ids.length; i += CHUNK) {
|
|
2510
|
-
const chunk = ids.slice(i, i + CHUNK);
|
|
2511
|
-
const placeholders = chunk.map(() => '?').join(',');
|
|
2512
|
-
const rows = db.prepare(`
|
|
2513
|
-
SELECT st.session_id AS id, st.topic_json AS topicJson
|
|
2514
|
-
FROM session_topics st
|
|
2515
|
-
JOIN sessions s ON s.id = st.session_id
|
|
2516
|
-
WHERE st.session_id IN (${placeholders})
|
|
2517
|
-
AND st.extractor_version = ?
|
|
2518
|
-
AND st.file_mtime_ms IS s.file_mtime_ms
|
|
2519
|
-
AND st.file_size IS s.file_size
|
|
2520
|
-
`).all(...chunk, SESSION_TOPIC_EXTRACTOR_VERSION);
|
|
2521
|
-
for (const row of rows) {
|
|
2522
|
-
try {
|
|
2523
|
-
out.set(row.id, JSON.parse(row.topicJson));
|
|
2524
|
-
}
|
|
2525
|
-
catch {
|
|
2526
|
-
}
|
|
2527
|
-
}
|
|
2528
|
-
}
|
|
2529
|
-
return out;
|
|
2530
|
-
}
|
|
2531
|
-
export function writeSessionTopics(entries) {
|
|
2532
|
-
if (entries.length === 0)
|
|
2533
|
-
return;
|
|
2534
|
-
const db = getDB();
|
|
2535
|
-
const stmt = db.prepare(`
|
|
2536
|
-
INSERT INTO session_topics
|
|
2537
|
-
(session_id, file_mtime_ms, file_size, extractor_version, computed_at, topic_json)
|
|
2538
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
2539
|
-
ON CONFLICT(session_id) DO UPDATE SET
|
|
2540
|
-
file_mtime_ms = excluded.file_mtime_ms,
|
|
2541
|
-
file_size = excluded.file_size,
|
|
2542
|
-
extractor_version = excluded.extractor_version,
|
|
2543
|
-
computed_at = excluded.computed_at,
|
|
2544
|
-
topic_json = excluded.topic_json
|
|
2545
|
-
`);
|
|
2546
|
-
const now = Date.now();
|
|
2547
|
-
db.transaction(() => {
|
|
2548
|
-
for (const entry of entries) {
|
|
2549
|
-
stmt.run(entry.id, entry.fileMtimeMs, entry.fileSize, SESSION_TOPIC_EXTRACTOR_VERSION, now, JSON.stringify(entry.topic));
|
|
2550
|
-
}
|
|
2551
|
-
})();
|
|
2552
|
-
}
|
|
2553
|
-
export function readSessionPhenotypes(ids) {
|
|
2554
|
-
const db = getDB();
|
|
2555
|
-
const out = new Map();
|
|
2556
|
-
if (ids.length === 0)
|
|
2557
|
-
return out;
|
|
2558
|
-
const CHUNK = 400;
|
|
2559
|
-
for (let i = 0; i < ids.length; i += CHUNK) {
|
|
2560
|
-
const chunk = ids.slice(i, i + CHUNK);
|
|
2561
|
-
const placeholders = chunk.map(() => '?').join(',');
|
|
2562
|
-
const rows = db.prepare(`
|
|
2563
|
-
SELECT sp.session_id AS id, sp.phenotype_json AS phenotypeJson
|
|
2564
|
-
FROM session_phenotypes sp
|
|
2565
|
-
JOIN sessions s ON s.id = sp.session_id
|
|
2566
|
-
WHERE sp.session_id IN (${placeholders})
|
|
2567
|
-
AND sp.extractor_version = ?
|
|
2568
|
-
AND sp.file_mtime_ms IS s.file_mtime_ms
|
|
2569
|
-
AND sp.file_size IS s.file_size
|
|
2570
|
-
`).all(...chunk, SESSION_PHENOTYPE_EXTRACTOR_VERSION);
|
|
2571
|
-
for (const row of rows) {
|
|
2572
|
-
try {
|
|
2573
|
-
out.set(row.id, JSON.parse(row.phenotypeJson));
|
|
2574
|
-
}
|
|
2575
|
-
catch {
|
|
2576
|
-
}
|
|
2577
|
-
}
|
|
2578
|
-
}
|
|
2579
|
-
return out;
|
|
2580
|
-
}
|
|
2581
|
-
export function writeSessionPhenotypes(entries) {
|
|
2582
|
-
if (entries.length === 0)
|
|
2583
|
-
return;
|
|
2584
|
-
const db = getDB();
|
|
2585
|
-
const stmt = db.prepare(`
|
|
2586
|
-
INSERT INTO session_phenotypes
|
|
2587
|
-
(session_id, file_mtime_ms, file_size, extractor_version, computed_at, phenotype_json)
|
|
2588
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
2589
|
-
ON CONFLICT(session_id) DO UPDATE SET
|
|
2590
|
-
file_mtime_ms = excluded.file_mtime_ms,
|
|
2591
|
-
file_size = excluded.file_size,
|
|
2592
|
-
extractor_version = excluded.extractor_version,
|
|
2593
|
-
computed_at = excluded.computed_at,
|
|
2594
|
-
phenotype_json = excluded.phenotype_json
|
|
2595
|
-
`);
|
|
2596
|
-
const now = Date.now();
|
|
2597
|
-
db.transaction(() => {
|
|
2598
|
-
for (const entry of entries) {
|
|
2599
|
-
stmt.run(entry.id, entry.fileMtimeMs, entry.fileSize, SESSION_PHENOTYPE_EXTRACTOR_VERSION, now, JSON.stringify(entry.phenotype));
|
|
2600
|
-
}
|
|
2601
|
-
})();
|
|
2602
|
-
}
|
|
2603
2470
|
export function readSessionPreviewCache(id, sourceStamp) {
|
|
2604
2471
|
const row = getDB().prepare(`
|
|
2605
2472
|
SELECT pc.preview_json AS previewJson
|
|
@@ -10,7 +10,6 @@ interface DetachRecord {
|
|
|
10
10
|
export declare function writeDetachRecord(rec: DetachRecord): void;
|
|
11
11
|
export declare function readDetachRecord(sessionId: string): DetachRecord | undefined;
|
|
12
12
|
export declare function clearDetachRecord(sessionId: string): void;
|
|
13
|
-
export declare function listDetachRecords(): DetachRecord[];
|
|
14
13
|
export declare function isHeadlessAlive(rec: DetachRecord): boolean;
|
|
15
14
|
export declare function presenceFromStore(sessionId: string): Presence | undefined;
|
|
16
15
|
export {};
|
|
@@ -27,24 +27,6 @@ export function clearDetachRecord(sessionId) {
|
|
|
27
27
|
catch {
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
export function listDetachRecords() {
|
|
31
|
-
let names;
|
|
32
|
-
try {
|
|
33
|
-
names = fs.readdirSync(detachedDir());
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
return [];
|
|
37
|
-
}
|
|
38
|
-
const out = [];
|
|
39
|
-
for (const name of names) {
|
|
40
|
-
if (!name.endsWith('.json'))
|
|
41
|
-
continue;
|
|
42
|
-
const rec = readDetachRecord(name.slice(0, -'.json'.length));
|
|
43
|
-
if (rec)
|
|
44
|
-
out.push(rec);
|
|
45
|
-
}
|
|
46
|
-
return out;
|
|
47
|
-
}
|
|
48
30
|
export function isHeadlessAlive(rec) {
|
|
49
31
|
if (!rec.headlessPid || rec.headlessPid <= 0)
|
|
50
32
|
return false;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ActiveSession } from './active.js';
|
|
2
|
+
export interface PendingWorkItem {
|
|
3
|
+
id: string;
|
|
4
|
+
description: string;
|
|
5
|
+
startedAtMs?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SessionPendingWork {
|
|
8
|
+
subagents: PendingWorkItem[];
|
|
9
|
+
shells: PendingWorkItem[];
|
|
10
|
+
monitors: PendingWorkItem[];
|
|
11
|
+
}
|
|
12
|
+
export type SessionEffort = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
13
|
+
export declare const PENDING_COLD_TAIL_BYTES: number;
|
|
14
|
+
export interface SessionLiveWork {
|
|
15
|
+
pending?: SessionPendingWork;
|
|
16
|
+
effort?: SessionEffort;
|
|
17
|
+
fast?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function readSessionLiveWork(row: Pick<ActiveSession, 'kind' | 'sessionFile' | 'pidAlive' | 'subagents' | 'processStartedAtMs'>, nowMs?: number): SessionLiveWork;
|
|
20
|
+
export declare function enrichLiveWork(rows: ActiveSession[], nowMs?: number): void;
|
|
21
|
+
export declare function resetPendingWorkFolds(): void;
|