@phnx-labs/agents-cli 1.23.33 → 1.23.34

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.34
4
+
5
+ - **A session row says whether its last turn was done, and a finished turn posts a banner.** Live rows on `agents ps --json`, `agents ps watch --json` and `agents feed watch --json` (remote rows too) carry `doneVerdict: { state: 'done'|'open'|'unchecked', gaps, at }` from the Stop hook's verdict in `~/.agents/.cache/state/sessions/<pid>.json`, only when that record belongs to the row's live process. Off by default, an interactive session going from running to idle after at least 2 minutes of work can post one AGI Menu `done` banner: "✓ Done", "Not done" or "Finished" with the row's title, the verdict's gaps in words when it is open or else the first sentence of the agent's last line, and a tap opens the session. One banner per turn; three or more finishes that land together post one summary banner. The `menubar.menu.notifyLow` schedule governs it: its default `["sidebar"]` posts none, and `agents config set menubar.menu.notifyLow '["0m"]'` turns it on (low-urgency asks follow the same key). Source: cli/src/lib/session/hook-sessions.ts, cli/src/lib/session/active.ts, cli/src/lib/daemon/finished-banners.ts, cli/src/lib/daemon/attention-notify-service.ts
6
+
3
7
  ## 1.23.33
4
8
 
5
9
  - **A Codex session that opened several PRs before the upgrade lists them all.** The resumable Codex parse state moves to v5, so a v4 checkpoint (written before the index recorded every PR) re-parses its transcript once instead of resuming with only its first PR, as Claude's v7 already does. Source: cli/src/lib/session/discover.ts
@@ -7,7 +7,7 @@
7
7
  * `interactive.host` unset: this host's asks; this machine: every host's, from
8
8
  * the shared fleet collector; another machine: none. The ledger under
9
9
  * `feed/notified/` (`<key>`, `<key>#r<n>`) makes a restart re-send nothing.
10
- * `done` banners ride the run process's exit (`run-notify.ts`), not this service.
10
+ * Finished interactive turns post `done` banners here too (`finished-banners.ts`, docs/menubar.md).
11
11
  */
12
12
  import { type ActiveSession } from '../session/active.js';
13
13
  import { type AttentionItem, type AttentionUrgency } from '../feed/attention.js';
@@ -63,11 +63,13 @@ export declare class AttentionNotifyService extends BasePeriodicService {
63
63
  private banners;
64
64
  private fleetHub;
65
65
  private detachFleet;
66
+ private readonly finishes;
66
67
  constructor(opts?: AttentionNotifyServiceOptions);
67
68
  protected onStart(_ctx: DaemonContext): Promise<void>;
68
69
  protected onStop(): Promise<void>;
69
70
  protected onTick(ctx: DaemonContext): Promise<void>;
70
71
  private settings;
72
+ private postFinishes;
71
73
  private localAsks;
72
74
  private fleetAsks;
73
75
  private releaseFleet;
@@ -7,7 +7,7 @@
7
7
  * `interactive.host` unset: this host's asks; this machine: every host's, from
8
8
  * the shared fleet collector; another machine: none. The ledger under
9
9
  * `feed/notified/` (`<key>`, `<key>#r<n>`) makes a restart re-send nothing.
10
- * `done` banners ride the run process's exit (`run-notify.ts`), not this service.
10
+ * Finished interactive turns post `done` banners here too (`finished-banners.ts`, docs/menubar.md).
11
11
  */
12
12
  import * as fs from 'fs';
13
13
  import * as path from 'path';
@@ -25,6 +25,7 @@ import { sharedFleetFeedHub } from '../feed/watch.js';
25
25
  import { DEFAULT_NOTIFY_SCHEDULES, NOTIFY_LEVELS, NOTIFY_LEVEL_KEYS, formatWaited, parseNotifySchedule, } from '../feed/notify-schedule.js';
26
26
  import { notifyDesktop, withdrawDesktop } from '../menubar/notify-desktop.js';
27
27
  import { BasePeriodicService } from './service.js';
28
+ import { TurnFinishTracker, buildBurstNotification, buildFinishNotification, finishKey, FINISH_BURST_MIN } from './finished-banners.js';
28
29
  import { span, spanSync } from './diagnostics.js';
29
30
  const ATTENTION_NOTIFY_TICK_MS = 5_000;
30
31
  const ATTENTION_NOTIFY_DEADLINE_MS = 10_000;
@@ -117,6 +118,7 @@ export class AttentionNotifyService extends BasePeriodicService {
117
118
  banners = null;
118
119
  fleetHub = null;
119
120
  detachFleet = null;
121
+ finishes = new TurnFinishTracker();
120
122
  constructor(opts = {}) {
121
123
  super();
122
124
  this.getSessions = opts.getSessions ?? (() => getActiveSessions());
@@ -143,11 +145,11 @@ export class AttentionNotifyService extends BasePeriodicService {
143
145
  if (scope !== 'fleet')
144
146
  this.releaseFleet();
145
147
  const local = scope === 'local' ? await this.localAsks(nowMs) : undefined;
146
- const { asks, scopes } = local
147
- ? { asks: local.asks, scopes: null }
148
+ const { asks, scopes, rows } = local
149
+ ? { asks: local.asks, scopes: null, rows: local.rows }
148
150
  : scope === 'fleet'
149
151
  ? this.fleetAsks()
150
- : { asks: [], scopes: null };
152
+ : { asks: [], scopes: null, rows: [] };
151
153
  const banners = await this.loadBanners();
152
154
  const toWithdraw = [];
153
155
  const seen = new Set();
@@ -187,8 +189,10 @@ export class AttentionNotifyService extends BasePeriodicService {
187
189
  posted += 1;
188
190
  ctx.log('INFO', `attention-notify: posted ${level} ${item.kind} banner for ${item.key}${stage ? ` (reminder ${stage})` : ''}`, { event: 'attention.posted', kind: item.kind, key: item.key, level, reminder: stage });
189
191
  }
192
+ this.finishes.observe(rows, nowMs);
193
+ posted += await this.postFinishes(ctx, this.finishes.due(nowMs), settings, banners, nowMs);
190
194
  for (const state of banners.values()) {
191
- const resolved = !seen.has(state.key) && (scopes === null || scopes.has(state.key.split('/')[0]));
195
+ const resolved = !state.finished && !seen.has(state.key) && (scopes === null || scopes.has(state.key.split('/')[0]));
192
196
  if (resolved) {
193
197
  if (state.bannerUp)
194
198
  toWithdraw.push(state.key);
@@ -199,6 +203,10 @@ export class AttentionNotifyService extends BasePeriodicService {
199
203
  toWithdraw.push(state.key);
200
204
  state.bannerUp = false;
201
205
  delete state.hideAt;
206
+ if (state.finished) {
207
+ banners.delete(state.key);
208
+ state.resolvedAt = new Date(nowMs).toISOString();
209
+ }
202
210
  await this.writeState(state);
203
211
  }
204
212
  }
@@ -215,6 +223,38 @@ export class AttentionNotifyService extends BasePeriodicService {
215
223
  }
216
224
  return this.settingsCache.value;
217
225
  }
226
+ async postFinishes(ctx, due, settings, banners, nowMs) {
227
+ const schedule = settings.schedules.low;
228
+ if (schedule.sidebar)
229
+ return 0;
230
+ const fresh = [];
231
+ for (const finish of due)
232
+ if (!await this.stageSent(finishKey(finish), 0, banners))
233
+ fresh.push(finish);
234
+ if (fresh.length === 0)
235
+ return 0;
236
+ const notifications = fresh.length >= FINISH_BURST_MIN
237
+ ? [buildBurstNotification(fresh, `${fresh[0].scope}/done-burst-${nowMs}`)]
238
+ : fresh.map(buildFinishNotification);
239
+ for (const n of notifications) {
240
+ if (schedule.sound)
241
+ n.sound = true;
242
+ this.notify(n);
243
+ ctx.log('INFO', `attention-notify: posted done banner ${n.key}`, { event: 'attention.done.posted', key: n.key });
244
+ }
245
+ const bannerKeys = new Set(notifications.map((n) => n.key));
246
+ for (const key of new Set([...bannerKeys, ...fresh.map(finishKey)])) {
247
+ const up = bannerKeys.has(key) && !schedule.stay;
248
+ const state = {
249
+ key, postedAt: new Date(nowMs).toISOString(), level: 'low', stage: 0, bannerUp: up, finished: true,
250
+ ...(up ? { hideAt: nowMs + BANNER_HIDE_AFTER_MS } : { resolvedAt: new Date(nowMs).toISOString() }),
251
+ };
252
+ if (up)
253
+ banners.set(key, state);
254
+ await this.writeState(state);
255
+ }
256
+ return notifications.length;
257
+ }
218
258
  async localAsks(nowMs) {
219
259
  const sessions = await span('attention.sessions', () => this.getSessions(), () => ({}));
220
260
  const host = normalizeHost(this.self());
@@ -234,7 +274,7 @@ export class AttentionNotifyService extends BasePeriodicService {
234
274
  if (item)
235
275
  asks.push({ item, session: projected });
236
276
  }
237
- return { asks, sessions };
277
+ return { asks, sessions, rows: sessions.map((row) => ({ scope: host, row })) };
238
278
  }
239
279
  fleetAsks() {
240
280
  const hub = this.fleetHubOf();
@@ -248,7 +288,7 @@ export class AttentionNotifyService extends BasePeriodicService {
248
288
  item: item.urgency ? item : { ...item, urgency: 'normal' },
249
289
  session: agent ?? {},
250
290
  }));
251
- return { asks, scopes: hub.state.reportingScopes };
291
+ return { asks, scopes: hub.state.reportingScopes, rows: hub.state.liveAgents() };
252
292
  }
253
293
  releaseFleet() {
254
294
  this.detachFleet?.();
@@ -0,0 +1,32 @@
1
+ import type { ActiveSession } from '../session/active.js';
2
+ import type { DesktopNotification } from '../menubar/notify-desktop.js';
3
+ export declare const FINISH_MIN_WORK_MS: number;
4
+ export declare const FINISH_SETTLE_MS = 15000;
5
+ export declare const FINISH_BURST_WINDOW_MS = 60000;
6
+ export declare const FINISH_BURST_MIN = 3;
7
+ export type FinishRow = Partial<Pick<ActiveSession, 'sessionId' | 'status' | 'lead' | 'title' | 'label' | 'lastAgentLine' | 'doneVerdict' | 'userTurns' | 'harness' | 'kind' | 'project' | 'pr'>> & {
8
+ context?: string;
9
+ previous?: boolean;
10
+ };
11
+ export interface ObservedRow {
12
+ scope: string;
13
+ row: FinishRow;
14
+ }
15
+ export interface TurnFinish {
16
+ scope: string;
17
+ sessionId: string;
18
+ turnStartMs: number;
19
+ endedAtMs: number;
20
+ row: FinishRow;
21
+ }
22
+ export declare class TurnFinishTracker {
23
+ private readonly working;
24
+ private readonly idleAt;
25
+ private readonly pending;
26
+ observe(rows: readonly ObservedRow[], nowMs: number): void;
27
+ due(nowMs: number): TurnFinish[];
28
+ }
29
+ export declare function gapsInWords(gaps: readonly string[]): string;
30
+ export declare function finishKey(finish: TurnFinish): string;
31
+ export declare function buildFinishNotification(finish: TurnFinish): DesktopNotification;
32
+ export declare function buildBurstNotification(finishes: readonly TurnFinish[], key: string): DesktopNotification;
@@ -0,0 +1,145 @@
1
+ import { harnessOf } from '../feed/attention.js';
2
+ import { formatWaited } from '../feed/notify-schedule.js';
3
+ export const FINISH_MIN_WORK_MS = 2 * 60_000;
4
+ export const FINISH_SETTLE_MS = 15_000;
5
+ export const FINISH_BURST_WINDOW_MS = 60_000;
6
+ export const FINISH_BURST_MIN = 3;
7
+ const BODY_MAX = 200;
8
+ const VERDICT_SKEW_MS = 5_000;
9
+ const GAP_WORDS = {
10
+ 'open-pr': 'a pull request is still open',
11
+ 'keep-moving': 'it stopped with work left to do',
12
+ delivery: 'the delivery is not verified',
13
+ 'live-team': 'teammates are still running',
14
+ 'self-audit': 'it has not checked its own work',
15
+ };
16
+ function isInteractive(row) {
17
+ return row.context === 'terminal' && !row.lead && !row.previous && !!row.sessionId;
18
+ }
19
+ function lastUserTurnMs(row) {
20
+ const turns = row.userTurns ?? [];
21
+ const at = turns.length ? turns[turns.length - 1].atMs : undefined;
22
+ return typeof at === 'number' && Number.isFinite(at) ? at : undefined;
23
+ }
24
+ export class TurnFinishTracker {
25
+ working = new Map();
26
+ idleAt = new Map();
27
+ pending = new Map();
28
+ observe(rows, nowMs) {
29
+ const present = new Set();
30
+ for (const { scope, row } of rows) {
31
+ if (!isInteractive(row))
32
+ continue;
33
+ const key = `${scope}/${row.sessionId}`;
34
+ present.add(key);
35
+ if (row.status === 'running') {
36
+ const resumed = this.pending.get(key);
37
+ if (resumed) {
38
+ this.pending.delete(key);
39
+ this.working.set(key, resumed.turnStartMs);
40
+ }
41
+ else if (!this.working.has(key)) {
42
+ const asked = lastUserTurnMs(row);
43
+ const idleAt = this.idleAt.get(key);
44
+ this.working.set(key, asked !== undefined && asked <= nowMs && (idleAt === undefined || asked > idleAt) ? asked : nowMs);
45
+ }
46
+ }
47
+ else if (row.status === 'idle') {
48
+ const startMs = this.working.get(key);
49
+ this.working.delete(key);
50
+ this.idleAt.set(key, nowMs);
51
+ const held = this.pending.get(key);
52
+ if (held)
53
+ held.row = row;
54
+ else if (startMs !== undefined && nowMs - startMs >= FINISH_MIN_WORK_MS) {
55
+ this.pending.set(key, { scope, sessionId: row.sessionId, turnStartMs: startMs, endedAtMs: nowMs, row });
56
+ }
57
+ }
58
+ else {
59
+ this.working.delete(key);
60
+ this.pending.delete(key);
61
+ }
62
+ }
63
+ for (const map of [this.working, this.idleAt, this.pending]) {
64
+ for (const key of map.keys())
65
+ if (!present.has(key))
66
+ map.delete(key);
67
+ }
68
+ }
69
+ due(nowMs) {
70
+ if (this.pending.size === 0)
71
+ return [];
72
+ const ends = [...this.pending.values()].map((f) => f.endedAtMs);
73
+ const settled = nowMs - Math.max(...ends) >= FINISH_SETTLE_MS;
74
+ const capped = nowMs - Math.min(...ends) >= FINISH_BURST_WINDOW_MS;
75
+ if (!settled && !capped)
76
+ return [];
77
+ const out = [...this.pending.values()].sort((a, b) => a.endedAtMs - b.endedAtMs);
78
+ this.pending.clear();
79
+ return out;
80
+ }
81
+ }
82
+ function shorten(text, max = BODY_MAX) {
83
+ const flat = text.replace(/\s+/g, ' ').trim();
84
+ return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
85
+ }
86
+ function firstSentence(text) {
87
+ const flat = text.replace(/\s+/g, ' ').trim();
88
+ const end = flat.search(/[.!?](\s|$)/);
89
+ return end >= 0 ? flat.slice(0, end + 1) : flat;
90
+ }
91
+ function turnVerdict(finish) {
92
+ const v = finish.row.doneVerdict;
93
+ if (!v)
94
+ return undefined;
95
+ const at = Date.parse(v.at);
96
+ return Number.isFinite(at) && at >= finish.turnStartMs - VERDICT_SKEW_MS ? v : undefined;
97
+ }
98
+ export function gapsInWords(gaps) {
99
+ const words = gaps.map((g) => GAP_WORDS[g] ?? g.replace(/-/g, ' '));
100
+ const text = words.join('; ');
101
+ return text ? `${text[0].toUpperCase()}${text.slice(1)}.` : '';
102
+ }
103
+ function rowTitle(finish) {
104
+ return finish.row.title?.trim() || finish.row.label?.trim() || finish.sessionId.slice(0, 8);
105
+ }
106
+ function verdictWord(v) {
107
+ return v?.state === 'done' ? '✓ Done' : v?.state === 'open' ? 'Not done' : 'Finished';
108
+ }
109
+ export function finishKey(finish) {
110
+ return `${finish.scope}/${finish.sessionId}/done-${finish.turnStartMs}`;
111
+ }
112
+ export function buildFinishNotification(finish) {
113
+ const verdict = turnVerdict(finish);
114
+ const worked = `worked ${formatWaited(finish.endedAtMs - finish.turnStartMs)}`;
115
+ const gaps = verdict?.state === 'open' ? gapsInWords(verdict.gaps) : '';
116
+ const line = finish.row.lastAgentLine ? firstSentence(finish.row.lastAgentLine) : '';
117
+ const n = {
118
+ title: `${verdictWord(verdict)} · ${rowTitle(finish)}`,
119
+ body: shorten(gaps || line || `The turn ended after it ${worked}.`),
120
+ subtitle: [finish.scope, finish.row.project, worked].filter(Boolean).join(' · '),
121
+ category: 'done',
122
+ key: finishKey(finish),
123
+ sessionId: finish.sessionId,
124
+ };
125
+ const agent = harnessOf(finish.row);
126
+ if (agent)
127
+ n.agent = agent;
128
+ if (finish.row.pr?.url)
129
+ n.action = `url:${finish.row.pr.url}`;
130
+ return n;
131
+ }
132
+ export function buildBurstNotification(finishes, key) {
133
+ const counts = new Map();
134
+ for (const f of finishes) {
135
+ const word = verdictWord(turnVerdict(f)).replace('✓ ', '').toLowerCase();
136
+ counts.set(word, (counts.get(word) ?? 0) + 1);
137
+ }
138
+ return {
139
+ title: `${finishes.length} sessions finished`,
140
+ body: shorten(finishes.map(rowTitle).join(' · ')),
141
+ subtitle: [...counts].map(([word, n]) => `${n} ${word}`).join(' · '),
142
+ category: 'done',
143
+ key,
144
+ };
145
+ }
@@ -11,6 +11,10 @@ export declare class FeedHubState {
11
11
  snapshot(state: FeedWatchState): FeedWatchEnvelope[];
12
12
  get scopeNames(): string[];
13
13
  get reportingScopes(): Set<string>;
14
+ liveAgents(): Array<{
15
+ scope: string;
16
+ row: SessionWatchRow;
17
+ }>;
14
18
  attention(): Array<{
15
19
  scope: string;
16
20
  item: AttentionItem;
@@ -87,6 +87,15 @@ export class FeedHubState {
87
87
  out.add(name);
88
88
  return out;
89
89
  }
90
+ liveAgents() {
91
+ const out = [];
92
+ for (const [scope, state] of this.scopes) {
93
+ for (const row of state.agents.values())
94
+ if (!row.previous)
95
+ out.push({ scope, row });
96
+ }
97
+ return out;
98
+ }
90
99
  attention() {
91
100
  const out = [];
92
101
  for (const [scope, state] of this.scopes) {
@@ -50,7 +50,8 @@ export function validateNotifySchedule(name) {
50
50
  export function notifyScheduleDescription(level) {
51
51
  return (`AGI Menu: when a ${level}-urgency agent ask posts a Mac banner. Times (5m, 1h) are measured from when the ask ` +
52
52
  'opened: the first posts the banner, each later one a reminder. Add stay to keep the banner on screen and sound ' +
53
- `to play a sound, or set just sidebar for no banner. Default ${JSON.stringify(DEFAULT_NOTIFY_SCHEDULES[level])}.`);
53
+ `to play a sound, or set just sidebar for no banner. Default ${JSON.stringify(DEFAULT_NOTIFY_SCHEDULES[level])}.` +
54
+ (level === 'low' ? ' It also schedules the banner a finished session turn posts: sidebar (the default) posts none, any time turns it on.' : ''));
54
55
  }
55
56
  export function formatWaited(ms) {
56
57
  const minutes = Math.round(ms / 60_000);
@@ -1,6 +1,6 @@
1
1
  import type { CloudTaskStatus } from '../cloud/types.js';
2
2
  import { type PidSessionEntry } from './pid-registry.js';
3
- import { type HookSessionIndex } from './hook-sessions.js';
3
+ import { type DoneVerdict, type HookSessionIndex } from './hook-sessions.js';
4
4
  import { type SessionRecap } from './title.js';
5
5
  import type { TouchedPr, TouchedTicket } from './touched.js';
6
6
  import { type UserPromptKind } from '@phnx-labs/sessions-cli/reader';
@@ -172,6 +172,7 @@ export interface ActiveSession {
172
172
  checkpoints?: import('@phnx-labs/sessions-cli/reader').SessionCheckpoint[];
173
173
  summaryChecklist?: import('@phnx-labs/sessions-cli/reader').SessionChecklistItem[];
174
174
  summaryState?: import('@phnx-labs/sessions-cli/reader').SummaryState;
175
+ doneVerdict?: DoneVerdict;
175
176
  }
176
177
  export declare function activeStatusFromCloudStatus(status: CloudTaskStatus): ActiveStatus;
177
178
  interface ActiveQueryOptions {
@@ -282,6 +283,7 @@ export declare function deriveSessionRecap(row: Pick<ActiveSession, 'label' | 'g
282
283
  export declare function deriveImportantMessage(row: Pick<ActiveSession, 'status' | 'activity' | 'awaitingReason' | 'question' | 'preview' | 'lastAgentLine'>): SessionImportantMessage | undefined;
283
284
  export declare function foldRecap(rows: ActiveSession[]): void;
284
285
  export declare function derivePhase(status: ActiveStatus | undefined): SessionPhase;
286
+ export declare function foldDoneVerdict(rows: ActiveSession[]): void;
285
287
  export declare function foldPhase(rows: ActiveSession[]): void;
286
288
  export declare function isReapableOrphan(row: Pick<ActiveSession, 'status' | 'pidAlive'>): boolean;
287
289
  export declare function annotateOrchestratorLabels(sessions: ActiveSession[]): void;
@@ -13,7 +13,7 @@ import { listNativeAccounts } from '../account-registry.js';
13
13
  import { parseNativeIdentityKey } from '../native-accounts.js';
14
14
  import { readLivePidSessionEntry as readPidSessionEntry, listPidSessionEntries, prunePidSessionRegistry, sessionIdFromLivePid, } from './pid-registry.js';
15
15
  import { readSessionActorRecord, writeSessionAliasRecord } from './actor-sidecar.js';
16
- import { loadHookSessionIndex, resolveHookSessionRecord, readStateSessionRecord } from './hook-sessions.js';
16
+ import { loadHookSessionIndex, resolveHookSessionRecord, readStateSessionRecord, 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';
@@ -1334,6 +1334,7 @@ export async function getActiveSessions(opts = {}) {
1334
1334
  annotateOrchestratorLabels(merged);
1335
1335
  foldRecap(merged);
1336
1336
  foldPhase(merged);
1337
+ foldDoneVerdict(merged);
1337
1338
  markLeadSessions(merged);
1338
1339
  }, count(merged));
1339
1340
  return merged;
@@ -1544,6 +1545,17 @@ export function derivePhase(status) {
1544
1545
  return 'idle';
1545
1546
  }
1546
1547
  }
1548
+ export function foldDoneVerdict(rows) {
1549
+ for (const s of rows) {
1550
+ const verdict = s.pid && s.sessionId && s.pidAlive !== false
1551
+ ? readDoneVerdict(s.pid, s.sessionId, s.processStartedAtMs ?? readPidSessionEntry(s.pid)?.startedAtMs)
1552
+ : undefined;
1553
+ if (verdict)
1554
+ s.doneVerdict = verdict;
1555
+ else
1556
+ delete s.doneVerdict;
1557
+ }
1558
+ }
1547
1559
  export function foldPhase(rows) {
1548
1560
  for (const s of rows)
1549
1561
  s.phase = derivePhase(s.status);
@@ -8,6 +8,12 @@ export interface HookSessionRecord {
8
8
  terminal_id?: string;
9
9
  ts?: number;
10
10
  completed?: boolean;
11
+ verdict?: unknown;
12
+ }
13
+ export interface DoneVerdict {
14
+ state: 'done' | 'open' | 'unchecked';
15
+ gaps: string[];
16
+ at: string;
11
17
  }
12
18
  export interface HookSessionIndex {
13
19
  byLaunchId: Map<string, HookSessionRecord>;
@@ -15,6 +21,7 @@ export interface HookSessionIndex {
15
21
  byPid: Map<number, HookSessionRecord>;
16
22
  }
17
23
  export declare function readStateSessionRecord(pid: number, startedAtMs?: number): HookSessionRecord | undefined;
24
+ export declare function readDoneVerdict(pid: number, sessionId: string, processStartedAtMs?: number): DoneVerdict | undefined;
18
25
  export declare function captureLaunchBinding(pid: number | undefined, launchId: string): PidSessionEntry | undefined;
19
26
  export declare function recordCompletedLaunch(binding: PidSessionEntry | undefined): void;
20
27
  export declare function loadHookSessionIndex(): HookSessionIndex;
@@ -6,6 +6,8 @@ import { hostProcessView } from './process-view.js';
6
6
  import path from 'path';
7
7
  import { getTerminalsDir, getRuntimeStateDir } from '../state.js';
8
8
  import { listPidSessionEntries, pidSessionEntryMatchesLiveProcess, readLivePidSessionEntry, readPidSessionEntry } from './pid-registry.js';
9
+ const RECORD_SKEW_MS = 5_000;
10
+ const VERDICT_STATES = new Set(['done', 'open', 'unchecked']);
9
11
  function hookSessionsDir() {
10
12
  return path.join(getTerminalsDir(), 'sessions');
11
13
  }
@@ -25,12 +27,25 @@ export function readStateSessionRecord(pid, startedAtMs) {
25
27
  if (!rec)
26
28
  return undefined;
27
29
  if (startedAtMs !== undefined && typeof rec.ts === 'number') {
28
- const SKEW_MS = 5_000;
29
- if (rec.ts * 1000 < startedAtMs - SKEW_MS)
30
+ if (rec.ts * 1000 < startedAtMs - RECORD_SKEW_MS)
30
31
  return undefined;
31
32
  }
32
33
  return rec;
33
34
  }
35
+ export function readDoneVerdict(pid, sessionId, processStartedAtMs) {
36
+ const rec = readStateSessionRecord(pid, processStartedAtMs);
37
+ if (!rec || rec.pid !== pid || rec.session_id !== sessionId)
38
+ return undefined;
39
+ const v = rec.verdict;
40
+ if (!v || typeof v !== 'object' || typeof v.state !== 'string' || !VERDICT_STATES.has(v.state))
41
+ return undefined;
42
+ if (typeof v.at !== 'number' || !Number.isFinite(v.at))
43
+ return undefined;
44
+ if (processStartedAtMs !== undefined && v.at < processStartedAtMs - RECORD_SKEW_MS)
45
+ return undefined;
46
+ const gaps = Array.isArray(v.gaps) ? v.gaps.filter((g) => typeof g === 'string' && g.length > 0) : [];
47
+ return { state: v.state, gaps, at: new Date(v.at).toISOString() };
48
+ }
34
49
  function parseRecord(raw) {
35
50
  try {
36
51
  const o = JSON.parse(raw);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phnx-labs/agents-cli",
3
- "version": "1.23.33",
3
+ "version": "1.23.34",
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",