@phnx-labs/agents-cli 1.23.40 → 1.23.42

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.23.42
4
+
5
+ - **A session that reconnects after an ssh drop keeps its editor tab.** `agents run --device` exports `AGENT_TERMINAL_ID`, `AGENTS_ORIGIN_TERMINAL_ID` and `AGENTS_ORIGIN_DEVICE` so the remote session's row links back to the tab it was launched from. The automatic reattach after a dropped connection (`agents ps focus --reconnect-reattach`) ran without them, so the reattached session had no tab. The extension then saw a running session with no tab here, resumed it, and started a second Claude on the same conversation (owner video, 2026-10-19). The reattach now runs behind the same `remoteRunShellPrelude` as the launch. Source: `cli/src/lib/hosts/reconnect.ts`, `cli/src/commands/exec.ts`.
6
+
7
+ - **A turn the Stop judge could not read no longer hides the agent's question.** An `unjudged` `turnVerdict` (model error, the account's usage limit, every judge slot busy) also switched off the last-line question read, so a session whose judge failed showed no ask at all. `currentTurnVerdict` now treats `unjudged` as no verdict. Source: `cli/src/lib/feed/attention.ts`.
8
+
9
+ ## 1.23.41
10
+
11
+ - **The daemon no longer scans the whole search index after every indexing pass.** The check that decides whether the session search index needs compacting counted every row of FTS5's `_data` table, which is one row per index page, not one per segment. On one Mac that was 809,183 rows in 3 GB against 14 real segments, so the 512-segment threshold was always crossed: each pass ran two full scans of that table (1 to 2 s each with the machine idle, far longer under load) plus a `merge`, all on the daemon's main thread. A `sample` of the daemon showed 71% of its main thread in that count, its event loop was stalled 36 to 56 minutes of every hour, and the watchdog restarted it 57 times in a day. The count now reads the segment total FTS5 keeps in its structure record: 0.03 ms on the same index, and no merge while it is healthy. `agents daemon index optimize` reports the same real segment counts. Source: `cli/src/lib/session/db.ts`
12
+
13
+ - **The daemon no longer restarts every few minutes on a Mac with many screen recordings.** Every 2 seconds the `recordings` watcher looked up a session for each recording since `watchedSince`, one full live-session scan per file and all at once, and repeated it on every tick for any file with no single matching session. On a laptop with 77 recordings that meant 77 parallel scans every tick (`ps`, `lsof` and `tmux` per live session), event-loop stalls of 25 to 68 s, and 57 daemon restarts in a day as `attention-notify` ran past its hang limit. A scan now reads live sessions at most once, only when it finds a new file, and a file's lookup is never repeated, including when it matched no session. Source: `cli/src/lib/recordings/settle.ts`.
14
+
3
15
  ## 1.23.40
4
16
 
5
17
  - **The stall watchdog is gone (PHNX-4439).** `agents watchdog`, `agents setup watchdog`, the
@@ -1426,7 +1426,7 @@ ${formatModeSupportTable().split('\n').map((line) => ` ${line}`).join('\n
1426
1426
  hostName: host.name,
1427
1427
  target: reconnectTarget,
1428
1428
  initialExit: exitCode,
1429
- reattach: () => reattachRemoteSession(host, reconnectTarget),
1429
+ reattach: () => reattachRemoteSession(host, reconnectTarget, runAgent),
1430
1430
  }));
1431
1431
  }
1432
1432
  if (next.notice)
@@ -153,7 +153,7 @@ function attentionFromBlock(block, session, nowMs) {
153
153
  }
154
154
  export function currentTurnVerdict(session) {
155
155
  const v = session.turnVerdict;
156
- if (!v || session.activity === 'working')
156
+ if (!v || v.kind === 'unjudged' || session.activity === 'working')
157
157
  return undefined;
158
158
  if (session.lastEventMs != null && session.lastEventMs > v.atMs)
159
159
  return undefined;
@@ -66,8 +66,8 @@ interface ReconnectTargetInputs {
66
66
  launchId?: string;
67
67
  }
68
68
  export declare function pickReconnectTarget(inputs: ReconnectTargetInputs): ReconnectTarget | undefined;
69
- export declare function reattachRemoteCommand(target: ReconnectTarget): string;
70
- export declare function reattachRemoteSession(host: Host, target: ReconnectTarget): ReconnectOutcome;
69
+ export declare function reattachRemoteCommand(target: ReconnectTarget, agent: string): string;
70
+ export declare function reattachRemoteSession(host: Host, target: ReconnectTarget, agent: string): ReconnectOutcome;
71
71
  interface ReconnectLoopOpts {
72
72
  hostName: string;
73
73
  target: ReconnectTarget;
@@ -1,6 +1,7 @@
1
1
  import { sshExec, sshStream, shellQuote, SSH_CONN_FAILURE_CODE } from '../ssh-exec.js';
2
2
  import { hostIdentityArgs, sshTargetFor } from './types.js';
3
3
  import { RUN_AUTO_KEYWORD } from '../types.js';
4
+ import { remoteRunShellPrelude } from './dispatch.js';
4
5
  export const SSH_CONN_FAILURE = SSH_CONN_FAILURE_CODE;
5
6
  export const REMOTE_EXIT_255_REMAPPED = 254;
6
7
  export const RECONNECT_WINDOW_MS = 15 * 60_000;
@@ -108,23 +109,23 @@ export function pickReconnectTarget(inputs) {
108
109
  return { kind: 'session', id };
109
110
  return launchId ? { kind: 'launch', id: launchId } : undefined;
110
111
  }
111
- export function reattachRemoteCommand(target) {
112
+ export function reattachRemoteCommand(target, agent) {
112
113
  const selector = target.kind === 'launch'
113
114
  ? ['--launch-id', target.id]
114
115
  : [target.id];
115
116
  const inner = ['agents', 'ps', 'focus', ...selector, '--local', '--reconnect-reattach']
116
117
  .map(shellQuote)
117
118
  .join(' ');
118
- return wrapRemoteExitCode(inner);
119
+ return wrapRemoteExitCode(`${remoteRunShellPrelude(agent)}${inner}`);
119
120
  }
120
- export function reattachRemoteSession(host, target) {
121
+ export function reattachRemoteSession(host, target, agent) {
121
122
  const sshTarget = sshTargetFor(host);
122
123
  const extraSshArgs = hostIdentityArgs(host);
123
124
  const probe = sshExec(sshTarget, 'true', { multiplex: false, extraSshArgs });
124
125
  if (probe.code !== 0)
125
126
  return { code: SSH_CONN_FAILURE, connected: false, heldMs: 0 };
126
127
  const startedAt = Date.now();
127
- const code = sshStream(sshTarget, reattachRemoteCommand(target), { tty: true, extraSshArgs });
128
+ const code = sshStream(sshTarget, reattachRemoteCommand(target, agent), { tty: true, extraSshArgs });
128
129
  return { code, connected: true, heldMs: Date.now() - startedAt };
129
130
  }
130
131
  async function waitOrInterrupt(ms) {
@@ -1,3 +1,4 @@
1
+ import { type ActiveSession } from '../session/active.js';
1
2
  import { type RecordingCandidate } from './model.js';
2
3
  export interface RecordingScan {
3
4
  latest: RecordingCandidate[];
@@ -6,16 +7,18 @@ export interface RecordingScan {
6
7
  export interface RecordingSettlerOptions {
7
8
  settleMs?: number;
8
9
  now?: () => number;
9
- sessionsAt?: (recordedAtMs: number) => Promise<string | undefined>;
10
+ liveSessions?: () => Promise<LiveSession[]>;
10
11
  }
12
+ type LiveSession = Pick<ActiveSession, 'sessionId' | 'startedAtMs'>;
11
13
  export declare class RecordingSettler {
12
14
  private readonly observations;
13
15
  private readonly settleMs;
14
16
  private readonly now;
15
- private readonly sessionsAt;
17
+ private readonly liveSessions;
16
18
  constructor(options?: RecordingSettlerOptions);
17
19
  scan(directory: string, options?: {
18
20
  notBeforeMs?: number;
19
21
  }): Promise<RecordingScan>;
20
22
  }
21
23
  export declare function candidateForFile(filePath: string): Promise<RecordingCandidate>;
24
+ export {};
@@ -2,8 +2,8 @@ import * as fs from 'node:fs/promises';
2
2
  import * as path from 'node:path';
3
3
  import { getActiveSessions } from '../session/active.js';
4
4
  import { cleanShotStem, isNewerRecording, isRecordingFile, slugifyRecordingStem, } from './model.js';
5
- async function sessionAtRecordingTime(recordedAtMs) {
6
- const sessions = await getActiveSessions({ localOnly: true });
5
+ const localLiveSessions = () => getActiveSessions({ localOnly: true });
6
+ function sessionAt(sessions, recordedAtMs) {
7
7
  const matching = sessions.filter((session) => session.sessionId && (session.startedAtMs ?? Number.POSITIVE_INFINITY) <= recordedAtMs);
8
8
  return matching.length === 1 ? matching[0].sessionId : undefined;
9
9
  }
@@ -11,17 +11,19 @@ export class RecordingSettler {
11
11
  observations = new Map();
12
12
  settleMs;
13
13
  now;
14
- sessionsAt;
14
+ liveSessions;
15
15
  constructor(options = {}) {
16
16
  this.settleMs = options.settleMs ?? 10_000;
17
17
  this.now = options.now ?? Date.now;
18
- this.sessionsAt = options.sessionsAt ?? sessionAtRecordingTime;
18
+ this.liveSessions = options.liveSessions ?? localLiveSessions;
19
19
  }
20
20
  async scan(directory, options = {}) {
21
21
  const names = await fs.readdir(directory);
22
22
  const now = this.now();
23
23
  const seen = new Set();
24
24
  const candidates = [];
25
+ let sessions;
26
+ const sessionFor = async (recordedAtMs) => sessionAt(await (sessions ??= this.liveSessions()), recordedAtMs);
25
27
  await Promise.all(names.map(async (name) => {
26
28
  const filePath = path.join(directory, name);
27
29
  if (!isRecordingFile(filePath))
@@ -41,7 +43,7 @@ export class RecordingSettler {
41
43
  size: stat.size,
42
44
  mtimeMs: stat.mtimeMs,
43
45
  recordedAt: new Date(recordedAtMs).toISOString(),
44
- sessionId: previous?.candidate.sessionId ?? await this.sessionsAt(recordedAtMs),
46
+ sessionId: previous ? previous.candidate.sessionId : await sessionFor(recordedAtMs),
45
47
  };
46
48
  const unchangedSinceMs = previous && previous.candidate.size === candidate.size
47
49
  ? previous.unchangedSinceMs
@@ -87,6 +89,6 @@ export async function candidateForFile(filePath) {
87
89
  size: stat.size,
88
90
  mtimeMs: stat.mtimeMs,
89
91
  recordedAt: new Date(recordedAtMs).toISOString(),
90
- sessionId: await sessionAtRecordingTime(recordedAtMs),
92
+ sessionId: sessionAt(await localLiveSessions(), recordedAtMs),
91
93
  };
92
94
  }
@@ -1190,14 +1190,33 @@ export function closeDB() {
1190
1190
  cachedStmts = {};
1191
1191
  }
1192
1192
  }
1193
+ const FTS5_STRUCTURE_ROWID = 10;
1194
+ const FTS5_STRUCTURE_V2 = [0xff, 0x00, 0x00, 0x01];
1195
+ function ftsSegmentCount(db, table) {
1196
+ const row = db.prepare(`SELECT block FROM ${table}_data WHERE id = ?`).get(FTS5_STRUCTURE_ROWID);
1197
+ if (!row)
1198
+ return 0;
1199
+ const block = row.block;
1200
+ let at = FTS5_STRUCTURE_V2.every((byte, i) => block[4 + i] === byte) ? 8 : 4;
1201
+ const varint = () => {
1202
+ let value = 0;
1203
+ for (;;) {
1204
+ const byte = block[at++];
1205
+ value = value * 128 + (byte & 0x7f);
1206
+ if (!(byte & 0x80))
1207
+ return value;
1208
+ }
1209
+ };
1210
+ varint();
1211
+ return varint();
1212
+ }
1193
1213
  export function optimizeSessionSearchIndex() {
1194
1214
  const db = getDB();
1195
1215
  const tables = ['tool_call_text', 'session_text'];
1196
- const segments = (table) => db.prepare(`SELECT count(*) AS n FROM ${table}_data`).get().n;
1197
1216
  return tables.map((table) => {
1198
- const segmentsBefore = segments(table);
1217
+ const segmentsBefore = ftsSegmentCount(db, table);
1199
1218
  db.prepare(`INSERT INTO ${table}(${table}) VALUES('optimize')`).run();
1200
- return { table, segmentsBefore, segmentsAfter: segments(table) };
1219
+ return { table, segmentsBefore, segmentsAfter: ftsSegmentCount(db, table) };
1201
1220
  });
1202
1221
  }
1203
1222
  const FTS_MAINTENANCE_SEGMENT_THRESHOLD = 512;
@@ -1206,14 +1225,13 @@ export function maintainSessionSearchIndex(db = getDB(), options = {}) {
1206
1225
  const threshold = options.segmentThreshold ?? FTS_MAINTENANCE_SEGMENT_THRESHOLD;
1207
1226
  const pages = options.mergePages ?? FTS_MAINTENANCE_MERGE_PAGES;
1208
1227
  const tables = ['tool_call_text', 'session_text'];
1209
- const segments = (table) => db.prepare(`SELECT count(*) AS n FROM ${table}_data`).get().n;
1210
1228
  const results = [];
1211
1229
  for (const table of tables) {
1212
- const segmentsBefore = segments(table);
1230
+ const segmentsBefore = ftsSegmentCount(db, table);
1213
1231
  if (segmentsBefore < threshold)
1214
1232
  continue;
1215
1233
  db.prepare(`INSERT INTO ${table}(${table}, rank) VALUES('merge', ?)`).run(pages);
1216
- results.push({ table, segmentsBefore, segmentsAfter: segments(table) });
1234
+ results.push({ table, segmentsBefore, segmentsAfter: ftsSegmentCount(db, table) });
1217
1235
  }
1218
1236
  return results;
1219
1237
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phnx-labs/agents-cli",
3
- "version": "1.23.40",
3
+ "version": "1.23.42",
4
4
  "description": "One CLI for all your AI coding agents - versions, config, cloud dispatch, sessions, and teams (now with first-class Grok Build CLI support)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",