@phnx-labs/agents-cli 1.23.36 → 1.23.37

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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.23.37
4
+
5
+ - **A headless run an agent starts no longer takes over that agent's tab.** When a Claude session in an editor tab ran `claude -p` through its shell, the SessionStart hook walked up to the tab agent's `~/.agents/.cache/terminals/by-pid/<pid>.json` and rewrote its session id, so `agents ps`, the feed and the editor showed the tab as the one-second headless run (observed on yosemite-s0 for a zion tab, 2026-10-19). A by-pid entry now yields to the session its own process recorded at SessionStart (`state/sessions/<pid>.json`), which only that process writes, so the tab, its launch id and `agents message` resolve to the real session again, including for entries an older hook already rewrote. Source: cli/src/lib/session/pid-registry.ts, cli/src/lib/session/hook-sessions.ts
6
+
3
7
  ## 1.23.36
4
8
 
5
9
  - **The Lead can act on the fleet, and every action waits for your Confirm.** `agents lead tool attention` lists every open ask across the fleet from the host's live feed, and `answer --key <key> (--choice <id> | --text <answer>)` answers one. `send`, `start` and `dispatch` now queue instead of acting, as `stop` already did, and the new `prs list` reads the project's open PRs while `prs merge|comment|ready|rerun|close` queue one action on a PR. A queued action is a confirm token holding the exact `agents` argv; `agents lead confirm <token>` checks it against its fixed shape and runs it once (a dispatch moves its ticket to In Progress only then). A Lead session briefed before an upgrade that changed its rules starts fresh from the brief on its next turn, so it knows the new tools. The `confirm` event is now `{type, token, action, label, detail?, sessionId?}` with `action` one of `stop`, `answer`, `send`, `start`, `dispatch`, `pr`. Source: cli/src/lib/lead/act.ts, cli/src/lib/lead/tools.ts, cli/src/lib/lead/shapes.ts, cli/src/lib/lead/host.ts
@@ -11,9 +11,9 @@ import { AgentManager } from '../teams/agents.js';
11
11
  import { getTerminalsDir, readMeta } from '../state.js';
12
12
  import { listNativeAccounts } from '../account-registry.js';
13
13
  import { parseNativeIdentityKey } from '../native-accounts.js';
14
- import { readLivePidSessionEntry as readPidSessionEntry, listPidSessionEntries, prunePidSessionRegistry, sessionIdFromLivePid, } from './pid-registry.js';
14
+ import { readLivePidSessionEntry as readPidSessionEntry, listPidSessionEntries, prunePidSessionRegistry, readStateSessionRecord, sessionIdFromLivePid, } from './pid-registry.js';
15
15
  import { readSessionActorRecord, writeSessionAliasRecord } from './actor-sidecar.js';
16
- import { loadHookSessionIndex, resolveHookSessionRecord, readStateSessionRecord, readDoneVerdict } from './hook-sessions.js';
16
+ import { loadHookSessionIndex, resolveHookSessionRecord, readDoneVerdict } from './hook-sessions.js';
17
17
  import { extractClaudeUserText, getAgentSessionDirs, readClaudeLiveNames } from './discover.js';
18
18
  import { buildRunNameMap } from './run-names.js';
19
19
  import { cleanDisplayTitle, isPlaceholderSessionName, resolveSessionName, startedAsFromUserTurn } from './title.js';
@@ -1,14 +1,9 @@
1
- import { type PidSessionEntry } from './pid-registry.js';
2
- export interface HookSessionRecord {
3
- session_id: string;
1
+ import { type PidSessionEntry, type SessionStartRecord } from './pid-registry.js';
2
+ export interface HookSessionRecord extends SessionStartRecord {
4
3
  agent?: string;
5
- cwd?: string;
6
- pid: number;
7
4
  launch_id?: string;
8
5
  terminal_id?: string;
9
- ts?: number;
10
6
  completed?: boolean;
11
- verdict?: unknown;
12
7
  }
13
8
  export interface DoneVerdict {
14
9
  state: 'done' | 'open' | 'unchecked';
@@ -20,7 +15,6 @@ export interface HookSessionIndex {
20
15
  byTerminalId: Map<string, HookSessionRecord>;
21
16
  byPid: Map<number, HookSessionRecord>;
22
17
  }
23
- export declare function readStateSessionRecord(pid: number, startedAtMs?: number): HookSessionRecord | undefined;
24
18
  export declare function readDoneVerdict(pid: number, sessionId: string, processStartedAtMs?: number): DoneVerdict | undefined;
25
19
  export declare function captureLaunchBinding(pid: number | undefined, launchId: string): PidSessionEntry | undefined;
26
20
  export declare function recordCompletedLaunch(binding: PidSessionEntry | undefined): void;
@@ -4,34 +4,12 @@ import { execFileSync } from 'node:child_process';
4
4
  import { atomicWriteFileSync } from '../fs-atomic.js';
5
5
  import { hostProcessView } from './process-view.js';
6
6
  import path from 'path';
7
- import { getTerminalsDir, getRuntimeStateDir } from '../state.js';
8
- import { listPidSessionEntries, pidSessionEntryMatchesLiveProcess, readLivePidSessionEntry, readPidSessionEntry } from './pid-registry.js';
9
- const RECORD_SKEW_MS = 5_000;
7
+ import { getTerminalsDir } from '../state.js';
8
+ import { listPidSessionEntries, parseSessionRecord, pidSessionEntryMatchesLiveProcess, readLivePidSessionEntry, readPidSessionEntry, readStateSessionRecord, RECORD_SKEW_MS, stateSessionRecordPath, } from './pid-registry.js';
10
9
  const VERDICT_STATES = new Set(['done', 'open', 'unchecked']);
11
10
  function hookSessionsDir() {
12
11
  return path.join(getTerminalsDir(), 'sessions');
13
12
  }
14
- function stateSessionRecordPath(pid) {
15
- return path.join(getRuntimeStateDir(), 'sessions', `${pid}.json`);
16
- }
17
- export function readStateSessionRecord(pid, startedAtMs) {
18
- if (!pid || pid < 1)
19
- return undefined;
20
- let rec;
21
- try {
22
- rec = parseRecord(fs.readFileSync(stateSessionRecordPath(pid), 'utf8'));
23
- }
24
- catch {
25
- return undefined;
26
- }
27
- if (!rec)
28
- return undefined;
29
- if (startedAtMs !== undefined && typeof rec.ts === 'number') {
30
- if (rec.ts * 1000 < startedAtMs - RECORD_SKEW_MS)
31
- return undefined;
32
- }
33
- return rec;
34
- }
35
13
  export function readDoneVerdict(pid, sessionId, processStartedAtMs) {
36
14
  const rec = readStateSessionRecord(pid, processStartedAtMs);
37
15
  if (!rec || rec.pid !== pid || rec.session_id !== sessionId)
@@ -46,17 +24,6 @@ export function readDoneVerdict(pid, sessionId, processStartedAtMs) {
46
24
  const gaps = Array.isArray(v.gaps) ? v.gaps.filter((g) => typeof g === 'string' && g.length > 0) : [];
47
25
  return { state: v.state, gaps, at: new Date(v.at).toISOString() };
48
26
  }
49
- function parseRecord(raw) {
50
- try {
51
- const o = JSON.parse(raw);
52
- if (o && typeof o === 'object' && typeof o.session_id === 'string' && o.session_id) {
53
- return o;
54
- }
55
- }
56
- catch {
57
- }
58
- return undefined;
59
- }
60
27
  function keepNewest(map, key, rec) {
61
28
  const prev = map.get(key);
62
29
  if (!prev || (rec.ts ?? 0) > (prev.ts ?? 0))
@@ -158,7 +125,7 @@ export function loadHookSessionIndex() {
158
125
  for (const f of files) {
159
126
  let rec;
160
127
  try {
161
- rec = parseRecord(fs.readFileSync(path.join(hookSessionsDir(), f), 'utf8'));
128
+ rec = parseSessionRecord(fs.readFileSync(path.join(hookSessionsDir(), f), 'utf8'));
162
129
  }
163
130
  catch {
164
131
  }
@@ -21,6 +21,17 @@ export interface PidSessionEntry {
21
21
  startTime?: string;
22
22
  };
23
23
  }
24
+ export interface SessionStartRecord {
25
+ session_id: string;
26
+ pid: number;
27
+ cwd?: string;
28
+ ts?: number;
29
+ verdict?: unknown;
30
+ }
31
+ export declare const RECORD_SKEW_MS = 5000;
32
+ export declare function parseSessionRecord<T extends SessionStartRecord = SessionStartRecord>(raw: string): T | undefined;
33
+ export declare function stateSessionRecordPath(pid: number): string;
34
+ export declare function readStateSessionRecord<T extends SessionStartRecord = SessionStartRecord>(pid: number, startedAtMs?: number): T | undefined;
24
35
  export declare function processStartTimesMatch(recorded: string | undefined, observed: string | undefined): boolean | undefined;
25
36
  export declare function pidSessionEntryMatchesLiveProcess(entry: PidSessionEntry, startTime?: string): boolean | undefined;
26
37
  export declare function isSessionIdShape(value: string): boolean;
@@ -3,8 +3,46 @@ import { spanSync } from '../daemon/diagnostics.js';
3
3
  import path from 'path';
4
4
  import { execFileSync } from 'child_process';
5
5
  import { hostProcessView, writerProcessView } from './process-view.js';
6
- import { getTerminalsDir } from '../state.js';
6
+ import { getTerminalsDir, getRuntimeStateDir } from '../state.js';
7
7
  import { atomicWriteFileSync, withFileLock } from '../fs-atomic.js';
8
+ export const RECORD_SKEW_MS = 5_000;
9
+ export function parseSessionRecord(raw) {
10
+ try {
11
+ const o = JSON.parse(raw);
12
+ if (o && typeof o === 'object' && typeof o.session_id === 'string' && o.session_id)
13
+ return o;
14
+ }
15
+ catch {
16
+ }
17
+ return undefined;
18
+ }
19
+ export function stateSessionRecordPath(pid) {
20
+ return path.join(getRuntimeStateDir(), 'sessions', `${pid}.json`);
21
+ }
22
+ export function readStateSessionRecord(pid, startedAtMs) {
23
+ if (!pid || pid < 1)
24
+ return undefined;
25
+ let rec;
26
+ try {
27
+ rec = parseSessionRecord(fs.readFileSync(stateSessionRecordPath(pid), 'utf8'));
28
+ }
29
+ catch {
30
+ return undefined;
31
+ }
32
+ if (!rec)
33
+ return undefined;
34
+ if (startedAtMs !== undefined && typeof rec.ts === 'number') {
35
+ if (rec.ts * 1000 < startedAtMs - RECORD_SKEW_MS)
36
+ return undefined;
37
+ }
38
+ return rec;
39
+ }
40
+ function ownSession(entry) {
41
+ const own = readStateSessionRecord(entry.pid, entry.startedAtMs);
42
+ return own && own.pid === entry.pid && entry.sessionId && own.session_id !== entry.sessionId
43
+ ? { ...entry, sessionId: own.session_id }
44
+ : entry;
45
+ }
8
46
  function linuxStartTicks(pid) {
9
47
  try {
10
48
  const stat = fs.readFileSync(`/proc/${pid}/stat`, 'utf8');
@@ -188,7 +226,7 @@ export function readPidSessionEntry(pid) {
188
226
  try {
189
227
  const parsed = JSON.parse(raw);
190
228
  if (parsed && typeof parsed === 'object' && parsed.pid === pid) {
191
- return restoreOwnership(parsed);
229
+ return ownSession(restoreOwnership(parsed));
192
230
  }
193
231
  }
194
232
  catch {
@@ -230,7 +268,7 @@ export function listPidSessionEntries() {
230
268
  try {
231
269
  const parsed = JSON.parse(fs.readFileSync(path.join(pidRegistryDir(), f), 'utf8'));
232
270
  if (parsed && typeof parsed === 'object' && typeof parsed.pid === 'number') {
233
- out.push(restoreOwnership(parsed));
271
+ out.push(ownSession(restoreOwnership(parsed)));
234
272
  }
235
273
  }
236
274
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phnx-labs/agents-cli",
3
- "version": "1.23.36",
3
+ "version": "1.23.37",
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",