@phnx-labs/agents-cli 1.23.2 → 1.23.4

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,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.23.4
4
+
5
+ - **A live process with no readable transcript is `unknown`, not `running`.** Being alive is not evidence that an agent is working. On 2026-10-10 the fleet stream listed 26 such rows as running: headless `codex` and `rush` processes with no session id, folder or title (11 on one machine). They now report `unknown` (phase `idle`, `◌` in `agents ps`); a dead one is still `closed`. Fleet "running" counts drop by those rows, and such a row whose editor window closed stays `unknown` instead of turning `orphaned`. Spec SES-18 says so. Source: `cli/src/lib/session/active.ts` (`resolveFallbackStatus`).
6
+
7
+ - **A finished Claude session no longer reads as working, and Esc reads as idle.** `@phnx-labs/sessions-cli` 0.8.0: a background task's `<task-notification>` (or a `<system-reminder>`) written after a turn ended no longer counts as "the user spoke last" once the transcript has been quiet past the active window. On 2026-10-10 this was why 5 of 7 "working" Claude sessions on the fleet had been silent 18 to 72 minutes. The Claude live tail is now parsed with interrupts, so a call you stopped with Esc no longer looks in flight. Source: `cli/src/lib/session/active.ts` (`parseLiveTail`).
8
+
9
+ ## 1.23.3
10
+
11
+ - **The daemon stops crash-looping on tool-row linking (PHNX-4225).** Every feed
12
+ reprojection linked each browser and computer row to its agent session with one
13
+ synchronous lookup per row, and rebuilt the launch-id index from every activity log
14
+ on the daemon's event loop. On a busy machine that held the loop for up to 21 s per
15
+ pass, so attention-notify missed its 10 s deadline and the daemon restarted about
16
+ every 20 s. Linking is now incremental and yields:
17
+ - A found session is reused for 60 to 120 s, with staggered expiry.
18
+ - A session-id miss is retried after 10 s.
19
+ - The launch-id index is rebuilt at most once a minute by an async scan that only
20
+ re-reads logs that changed, so a new launch id links within 60 s.
21
+
22
+ Measured on the affected machine: the longest event-loop stall per pass dropped from
23
+ 587 ms to 62 ms cold and 1 ms warm, with identical links.
24
+ Source: `cli/src/lib/feed/tool-activity.ts`.
25
+
3
26
  ## 1.23.2
4
27
 
5
28
  - **AGI Menu 1.15.21: Restart AGI Menu, and Quit no longer turns it off (PHNX-4325).** Settings → AGI Menu has a Restart button and the right-click menu has Restart AGI Menu (⌘R); both run `agents menubar restart`. Quit AGI Menu only quits, and the app returns at the next login. The new Turn off AGI Menu… asks first, then runs `agents menubar disable` as Quit used to. Settings → Tabs names the agents-cli version an unavailable tab needs. Several failing CLI calls finishing at once no longer crash the app. Source: `cli/src/lib/helper-versions.ts`.
@@ -9,12 +9,14 @@ export declare class ToolNotInstalledError extends Error {
9
9
  export declare function readToolJson(tool: StandaloneTool, argv: string[]): Promise<unknown[]>;
10
10
  export declare function readStandaloneBrowserRows(): Promise<BrowserSessionRow[]>;
11
11
  export declare function readStandaloneComputerRows(): Promise<ComputerRunRow[]>;
12
- /** The tools record a session or launch id; only agents-cli's index can say which agent session that was. */
12
+ export declare const TOOL_LINK_TTL_MS = 60000;
13
+ export declare const TOOL_LINK_MISS_TTL_MS = 10000;
14
+ export declare function _resetToolLinkCacheForTest(): void;
13
15
  export declare function linkToolSessions<T extends {
14
16
  sessionId?: string;
15
17
  launchId?: string;
16
18
  linkedSession?: SessionMeta;
17
- }>(rows: T[]): T[];
19
+ }>(rows: T[], nowMs?: number): Promise<T[]>;
18
20
  export interface ToolDiff {
19
21
  upserts: ToolRow[];
20
22
  removes: string[];
@@ -1,9 +1,8 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import * as fs from 'node:fs';
3
3
  import * as path from 'node:path';
4
- import { getBrowserRuntimeDir, getCacheDir } from '../state.js';
4
+ import { getActivityDir, getBrowserRuntimeDir, getCacheDir } from '../state.js';
5
5
  import { getEventsDir } from './events.js';
6
- import { readRecentActivity } from './activity.js';
7
6
  import { span, spanSync } from '../daemon/diagnostics.js';
8
7
  import { invocation as browserInvocation, resolveBrowserBin } from '../browser-client.js';
9
8
  import { invocation as computerInvocation, resolveComputerBin } from '../computer-client.js';
@@ -89,40 +88,155 @@ export async function readStandaloneComputerRows() {
89
88
  return row;
90
89
  });
91
90
  }
92
- function buildLaunchSessionIndex() {
93
- return spanSync('feed.tools.launch-index', buildLaunchSessionIndexNow);
91
+ export const TOOL_LINK_TTL_MS = 60_000;
92
+ export const TOOL_LINK_MISS_TTL_MS = 10_000;
93
+ const LINK_YIELD_EVERY = 64;
94
+ const ACTIVITY_LAUNCH_TAIL_BYTES = 64 * 1024;
95
+ const linkCache = { metas: new Map(), launches: new Map(), indexBuiltAt: -Infinity, activity: new Map() };
96
+ export function _resetToolLinkCacheForTest() {
97
+ linkCache.metas.clear();
98
+ linkCache.launches = new Map();
99
+ linkCache.activity.clear();
100
+ linkCache.indexBuiltAt = -Infinity;
94
101
  }
95
- function buildLaunchSessionIndexNow() {
96
- const byLaunchId = new Map();
97
- for (const event of readRecentActivity({ maxBytesPerSession: 64 * 1024 })) {
98
- if (event.launchId && event.sessionId)
99
- byLaunchId.set(event.launchId, event.sessionId);
102
+ const yieldToLoop = () => new Promise((resolve) => setImmediate(resolve));
103
+ function expiryJitterMs(id) {
104
+ let hash = 0;
105
+ for (let i = 0; i < id.length; i++)
106
+ hash = (hash * 31 + id.charCodeAt(i)) >>> 0;
107
+ return hash % TOOL_LINK_TTL_MS;
108
+ }
109
+ function keepEarliest(into, launchId, sessionId, atMs) {
110
+ const prior = into.get(launchId);
111
+ if (!prior || atMs < prior.atMs)
112
+ into.set(launchId, { sessionId, atMs });
113
+ }
114
+ async function readLaunchPairs(file) {
115
+ const handle = await fs.promises.open(file, 'r');
116
+ try {
117
+ const { size } = await handle.stat();
118
+ const start = Math.max(0, size - ACTIVITY_LAUNCH_TAIL_BYTES);
119
+ const buf = Buffer.alloc(size - start);
120
+ await handle.read(buf, 0, buf.length, start);
121
+ const pairs = new Map();
122
+ for (const line of buf.toString('utf8').split('\n')) {
123
+ if (!line.includes('"launchId"'))
124
+ continue;
125
+ let event;
126
+ try {
127
+ event = JSON.parse(line);
128
+ }
129
+ catch {
130
+ continue;
131
+ }
132
+ if (typeof event.launchId !== 'string' || !event.launchId || typeof event.sessionId !== 'string' || !event.sessionId)
133
+ continue;
134
+ if (!event.event || typeof event.ts !== 'string')
135
+ continue;
136
+ const atMs = Date.parse(event.ts);
137
+ if (Number.isFinite(atMs))
138
+ keepEarliest(pairs, event.launchId, event.sessionId, atMs);
139
+ }
140
+ return pairs;
141
+ }
142
+ finally {
143
+ await handle.close();
100
144
  }
101
- for (const [launchId, record] of loadHookSessionIndex().byLaunchId) {
102
- if (record.session_id)
103
- byLaunchId.set(launchId, record.session_id);
145
+ }
146
+ async function refreshLaunchIndex(nowMs) {
147
+ const dir = getActivityDir();
148
+ let names;
149
+ try {
150
+ names = (await fs.promises.readdir(dir)).filter((name) => name.endsWith('.jsonl'));
151
+ }
152
+ catch (error) {
153
+ if (error.code !== 'ENOENT')
154
+ throw error;
155
+ names = [];
156
+ }
157
+ const present = new Set(names);
158
+ for (const name of linkCache.activity.keys())
159
+ if (!present.has(name))
160
+ linkCache.activity.delete(name);
161
+ for (const name of names) {
162
+ const file = path.join(dir, name);
163
+ let stat;
164
+ try {
165
+ stat = await fs.promises.stat(file);
166
+ }
167
+ catch {
168
+ linkCache.activity.delete(name);
169
+ continue;
170
+ }
171
+ const stamp = `${stat.size}:${stat.mtimeMs}`;
172
+ if (linkCache.activity.get(name)?.stamp === stamp)
173
+ continue;
174
+ let pairs;
175
+ try {
176
+ pairs = await readLaunchPairs(file);
177
+ }
178
+ catch (error) {
179
+ if (error.code !== 'ENOENT')
180
+ throw error;
181
+ linkCache.activity.delete(name);
182
+ continue;
183
+ }
184
+ linkCache.activity.set(name, { stamp, pairs });
104
185
  }
105
- for (const entry of listPidSessionEntries()) {
106
- if (entry.launchId && entry.sessionId)
107
- byLaunchId.set(entry.launchId, entry.sessionId);
186
+ const earliest = new Map();
187
+ for (const { pairs } of linkCache.activity.values()) {
188
+ for (const [launchId, { sessionId, atMs }] of pairs)
189
+ keepEarliest(earliest, launchId, sessionId, atMs);
108
190
  }
109
- return byLaunchId;
191
+ const next = new Map();
192
+ for (const [launchId, { sessionId }] of earliest)
193
+ next.set(launchId, sessionId);
194
+ spanSync('feed.tools.launch-index.local', () => {
195
+ for (const [launchId, record] of loadHookSessionIndex().byLaunchId) {
196
+ if (record.session_id)
197
+ next.set(launchId, record.session_id);
198
+ }
199
+ for (const entry of listPidSessionEntries()) {
200
+ if (entry.launchId && entry.sessionId)
201
+ next.set(entry.launchId, entry.sessionId);
202
+ }
203
+ });
204
+ linkCache.launches = next;
205
+ linkCache.indexBuiltAt = nowMs;
110
206
  }
111
- /** The tools record a session or launch id; only agents-cli's index can say which agent session that was. */
112
- export function linkToolSessions(rows) {
113
- return spanSync('feed.tools.link-sessions', () => linkToolSessionsNow(rows), () => ({ rows: rows.length }));
207
+ export function linkToolSessions(rows, nowMs = Date.now()) {
208
+ return span('feed.tools.link-sessions', () => linkToolSessionsNow(rows, nowMs), () => ({ rows: rows.length }));
114
209
  }
115
- function linkToolSessionsNow(rows) {
116
- let byLaunchId;
117
- return rows.map((row) => {
118
- let linked = row.sessionId ? getSessionById(row.sessionId) : null;
210
+ async function linkToolSessionsNow(rows, nowMs) {
211
+ for (const [id, entry] of linkCache.metas)
212
+ if (entry.expiresAt <= nowMs)
213
+ linkCache.metas.delete(id);
214
+ if (rows.some((row) => row.launchId) && nowMs - linkCache.indexBuiltAt >= TOOL_LINK_TTL_MS) {
215
+ linkCache.refreshing ??= span('feed.tools.launch-index', () => refreshLaunchIndex(nowMs))
216
+ .finally(() => { linkCache.refreshing = undefined; });
217
+ await linkCache.refreshing;
218
+ }
219
+ let lookups = 0;
220
+ const sessionFor = async (id) => {
221
+ const hit = linkCache.metas.get(id);
222
+ if (hit)
223
+ return hit.meta;
224
+ if (++lookups % LINK_YIELD_EVERY === 0)
225
+ await yieldToLoop();
226
+ const meta = getSessionById(id);
227
+ linkCache.metas.set(id, { meta, expiresAt: nowMs + (meta ? TOOL_LINK_TTL_MS + expiryJitterMs(id) : TOOL_LINK_MISS_TTL_MS) });
228
+ return meta;
229
+ };
230
+ const out = [];
231
+ for (const row of rows) {
232
+ let linked = row.sessionId ? await sessionFor(row.sessionId) : null;
119
233
  if (!linked && row.launchId) {
120
- byLaunchId ??= buildLaunchSessionIndex();
121
- const sessionId = byLaunchId.get(row.launchId);
122
- linked = sessionId ? getSessionById(sessionId) : null;
234
+ const sessionId = linkCache.launches.get(row.launchId);
235
+ linked = sessionId ? await sessionFor(sessionId) : null;
123
236
  }
124
- return linked ? { ...row, linkedSession: linked } : row;
125
- });
237
+ out.push(linked ? { ...row, linkedSession: linked } : row);
238
+ }
239
+ return out;
126
240
  }
127
241
  export async function collectToolRows(scope, sources = {}) {
128
242
  const incomplete = new Set();
@@ -476,7 +476,7 @@ export function lifecycleStatus(pidAlive, mtimeMs, nowMs = Date.now()) {
476
476
  }
477
477
  export function resolveFallbackStatus(sessionFile, pidAlive, nowMs = Date.now()) {
478
478
  const { mtimeMs } = sessionFileTimes(sessionFile);
479
- return lifecycleStatus(pidAlive, mtimeMs, nowMs) ?? 'running';
479
+ return lifecycleStatus(pidAlive, mtimeMs, nowMs) ?? 'unknown';
480
480
  }
481
481
  export function findSessionFileForKind(kind, cwd, sessionId) {
482
482
  if (!cwd)
@@ -521,7 +521,7 @@ export function clearLiveSignalsCacheForTest() {
521
521
  }
522
522
  function parseLiveTail(kind, sessionFile, mtimeMs) {
523
523
  if (kind === 'claude' || kind === 'codex') {
524
- const { events, content } = readSessionTailWithRaw(sessionFile, kind);
524
+ const { events, content } = readSessionTailWithRaw(sessionFile, kind, undefined, undefined, { includeInterrupts: true });
525
525
  const tokPerSec = events.length > 0 ? computeTokPerSec(content, kind) : 0;
526
526
  return { mtimeMs, events, tokPerSec: tokPerSec > 0 ? tokPerSec : undefined };
527
527
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phnx-labs/agents-cli",
3
- "version": "1.23.2",
3
+ "version": "1.23.4",
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",
@@ -87,7 +87,7 @@
87
87
  "@fontsource/inter": "^5.3.0",
88
88
  "@fontsource/jetbrains-mono": "^5.3.0",
89
89
  "@inquirer/prompts": "8.5.2",
90
- "@phnx-labs/sessions-cli": "0.7.0",
90
+ "@phnx-labs/sessions-cli": "0.8.0",
91
91
  "@resvg/resvg-wasm": "^2.6.2",
92
92
  "@types/proper-lockfile": "4.1.4",
93
93
  "@zed-industries/agent-client-protocol": "0.4.5",
@@ -1,5 +0,0 @@
1
- export interface PrInfo {
2
- state: string;
3
- mergedAt: string | null;
4
- }
5
- export declare function shouldCloseIssue(pr: PrInfo): boolean;
@@ -1,3 +0,0 @@
1
- export function shouldCloseIssue(pr) {
2
- return pr.state === 'MERGED' && pr.mergedAt !== null;
3
- }
@@ -1,5 +0,0 @@
1
- export declare function resolveTemplate(tmpl: string, artifact: Record<string, string>, preflight: Record<string, string | string[] | unknown>): string;
2
- export declare function extractTemplateVariables(tmpl: string): {
3
- artifact: string[];
4
- preflight: string[];
5
- };
@@ -1,36 +0,0 @@
1
- export function resolveTemplate(tmpl, artifact, preflight) {
2
- let result = tmpl;
3
- result = result.replace(/\{\{artifact\.(\w+)\}\}/g, (_, key) => {
4
- return artifact[key] ?? '';
5
- });
6
- result = result.replace(/\{\{preflight\.(\w+)\}\}/g, (_, key) => {
7
- const val = preflight[key];
8
- if (val === undefined || val === null) {
9
- return '';
10
- }
11
- if (typeof val === 'string') {
12
- return val;
13
- }
14
- if (Array.isArray(val)) {
15
- return val.join(',');
16
- }
17
- return '';
18
- });
19
- return result;
20
- }
21
- export function extractTemplateVariables(tmpl) {
22
- const artifact = [];
23
- const preflight = [];
24
- const re = /\{\{(\w+)\.(\w+)\}\}/g;
25
- let match;
26
- while ((match = re.exec(tmpl)) !== null) {
27
- const [, prefix, key] = match;
28
- if (prefix === 'artifact' && !artifact.includes(key)) {
29
- artifact.push(key);
30
- }
31
- else if (prefix === 'preflight' && !preflight.includes(key)) {
32
- preflight.push(key);
33
- }
34
- }
35
- return { artifact, preflight };
36
- }
@@ -1,14 +0,0 @@
1
- import { type AccountInfo } from './agents.js';
2
- import type { AgentId } from './types.js';
3
- export interface VersionAccountEntry {
4
- version: string;
5
- info: AccountInfo;
6
- }
7
- interface NewerDuplicateVersion {
8
- version: string;
9
- email: string | null;
10
- plan: string | null;
11
- }
12
- export declare function findNewerDuplicateVersions(entries: VersionAccountEntry[], selectedVersion: string): NewerDuplicateVersion[];
13
- export declare function formatNewerDuplicateNotice(agentId: AgentId, selectedVersion: string, duplicates: NewerDuplicateVersion[], selectedLabel?: string): string;
14
- export {};
@@ -1,54 +0,0 @@
1
- import chalk from 'chalk';
2
- import { agentLabel } from './agents.js';
3
- import { compareVersions } from './installations/versions.js';
4
- import { getUsageLookupKey } from './accounting/usage.js';
5
- function duplicateIdentity(info) {
6
- if (!info)
7
- return null;
8
- const usageKey = getUsageLookupKey(info);
9
- if (usageKey)
10
- return usageKey;
11
- return info.email ? `email:${info.email.toLowerCase()}` : null;
12
- }
13
- export function findNewerDuplicateVersions(entries, selectedVersion) {
14
- const selected = entries.find((entry) => entry.version === selectedVersion);
15
- const selectedIdentity = duplicateIdentity(selected?.info);
16
- if (!selectedIdentity)
17
- return [];
18
- return entries
19
- .filter((entry) => entry.version !== selectedVersion &&
20
- compareVersions(entry.version, selectedVersion) > 0 &&
21
- duplicateIdentity(entry.info) === selectedIdentity)
22
- .sort((a, b) => compareVersions(b.version, a.version))
23
- .map((entry) => ({
24
- version: entry.version,
25
- email: entry.info.email,
26
- plan: entry.info.plan,
27
- }));
28
- }
29
- export function formatNewerDuplicateNotice(agentId, selectedVersion, duplicates, selectedLabel = '') {
30
- if (duplicates.length === 0)
31
- return '';
32
- const versionLabel = selectedLabel
33
- ? `${selectedLabel} ${agentLabel(agentId)}@${selectedVersion}`
34
- : `${agentLabel(agentId)}@${selectedVersion}`;
35
- const plural = duplicates.length === 1 ? 'duplicate' : 'duplicates';
36
- const maxVersion = Math.max(...duplicates.map((duplicate) => duplicate.version.length));
37
- const maxEmail = Math.max(0, ...duplicates.map((duplicate) => duplicate.email?.length ?? 0));
38
- const lines = [
39
- `Found ${duplicates.length} newer ${plural} for ${versionLabel}:`,
40
- ];
41
- for (const duplicate of duplicates) {
42
- const parts = [` ${duplicate.version.padEnd(maxVersion)}`];
43
- if (maxEmail > 0) {
44
- parts.push(duplicate.email ? chalk.cyan(duplicate.email.padEnd(maxEmail)) : ''.padEnd(maxEmail));
45
- }
46
- if (duplicate.plan) {
47
- parts.push(duplicate.plan);
48
- }
49
- lines.push(parts.join(' '));
50
- }
51
- lines.push('');
52
- lines.push(`Run: agents use ${agentId}@${duplicates[0].version}`);
53
- return lines.join('\n');
54
- }