@phnx-labs/agents-cli 1.23.36 → 1.23.38
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 +8 -0
- package/dist/lib/lead/brief.d.ts +4 -1
- package/dist/lib/lead/brief.js +18 -8
- package/dist/lib/lead/host.js +1 -1
- package/dist/lib/lead/roster.d.ts +5 -2
- package/dist/lib/lead/roster.js +14 -7
- package/dist/lib/lead/tools.d.ts +11 -0
- package/dist/lib/lead/tools.js +11 -3
- package/dist/lib/session/active.js +2 -2
- package/dist/lib/session/hook-sessions.d.ts +2 -8
- package/dist/lib/session/hook-sessions.js +3 -36
- package/dist/lib/session/pid-registry.d.ts +11 -0
- package/dist/lib/session/pid-registry.js +41 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.23.38
|
|
4
|
+
|
|
5
|
+
- **The Lead can say what moved today (PHNX-4432).** Its tools now print dates. `agents lead tool linear tasks` lists the most recently updated tickets first, each with its age, cut to `--limit` and with a count of older ones (`linear tasks --json` sorts by priority and returns every match, so a done list started with tickets from August). `prs list` and the roster add when each PR was updated, and when each session started and was last active. The brief now keeps the merged and closed PRs among the 40 most recently updated, with their age, under "Merged or closed lately". Before this, "what happened in the last 24 hours" got "none of my tools show history". Source: cli/src/lib/lead/tools.ts, cli/src/lib/lead/brief.ts, cli/src/lib/lead/roster.ts
|
|
6
|
+
|
|
7
|
+
## 1.23.37
|
|
8
|
+
|
|
9
|
+
- **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
|
|
10
|
+
|
|
3
11
|
## 1.23.36
|
|
4
12
|
|
|
5
13
|
- **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
|
package/dist/lib/lead/brief.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ export interface BriefPr {
|
|
|
13
13
|
url: string;
|
|
14
14
|
draft: boolean;
|
|
15
15
|
open: boolean;
|
|
16
|
+
updatedAt?: string;
|
|
17
|
+
mergedAt?: string;
|
|
18
|
+
closedAt?: string;
|
|
16
19
|
}
|
|
17
20
|
export interface BriefInputs {
|
|
18
21
|
project: string;
|
|
@@ -36,7 +39,7 @@ export declare function fetchRecentPrs(repo: string | undefined, cwd: string | u
|
|
|
36
39
|
export declare function linearTeamKey(home: string): string | undefined;
|
|
37
40
|
export declare function quoteNotes(memory: string): string;
|
|
38
41
|
export declare function projectRepo(def: ProjectDef): string | undefined;
|
|
39
|
-
export declare function buildBrief(inputs: BriefInputs): string;
|
|
42
|
+
export declare function buildBrief(inputs: BriefInputs, nowMs?: number): string;
|
|
40
43
|
export declare function briefSummary(inputs: BriefInputs): string[];
|
|
41
44
|
export declare function fleetLine(rows: Array<{
|
|
42
45
|
status: string;
|
package/dist/lib/lead/brief.js
CHANGED
|
@@ -2,16 +2,16 @@ import * as fs from 'node:fs';
|
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { execFile } from 'node:child_process';
|
|
4
4
|
import { createHash } from 'node:crypto';
|
|
5
|
-
import { formatRosterRow } from './roster.js';
|
|
5
|
+
import { ago, formatRosterRow } from './roster.js';
|
|
6
6
|
export const BRIEF_FETCH_TIMEOUT_MS = 8_000;
|
|
7
7
|
const DIGEST_MAX_CHARS = 2_500;
|
|
8
8
|
export const LEAD_RULES = [
|
|
9
9
|
'You are the Lead for this project: one long-lived agent the owner talks or types to. You dispatch and manage coding agents; you never edit files.',
|
|
10
10
|
'Your only tools are these shell commands, each run on its own (no pipes, ;, &&, redirects or $(...); those are denied):',
|
|
11
|
-
' `agents lead tool roster [--project <name>]` lists live sessions from the live feed. It is the only way to see sessions.',
|
|
11
|
+
' `agents lead tool roster [--project <name>]` lists live sessions from the live feed, each with when it started and was last active. It is the only way to see sessions.',
|
|
12
12
|
' `agents lead tool attention` lists every open ask across the fleet (question, choices, its key). It is the only way to see what agents are asking.',
|
|
13
|
-
' `agents lead tool prs list [--repo <owner/repo>]` lists this project\'s open PRs.',
|
|
14
|
-
' `agents lead tool linear tasks [--status open|todo|progress|backlog|done]
|
|
13
|
+
' `agents lead tool prs list [--repo <owner/repo>]` lists this project\'s open PRs, each with when it was last updated.',
|
|
14
|
+
' `agents lead tool linear tasks [--status open|todo|progress|backlog|done] [--limit 1-50]` (most recently updated first, each with its age), `agents lead tool linear view <ID>`, `agents lead tool linear create --title <title> [--description <text>]`.',
|
|
15
15
|
'These queue one action for the owner\'s Confirm and never act themselves:',
|
|
16
16
|
' `agents lead tool answer --key <key> (--choice <id> | --text <answer>)` answers an open ask from the attention tool.',
|
|
17
17
|
' `agents lead tool send --session <id> -- <text>` types a message into a running session of this project (no slash commands).',
|
|
@@ -89,7 +89,12 @@ export async function fetchRecentPrs(repo, cwd) {
|
|
|
89
89
|
if (!repo)
|
|
90
90
|
throw new Error('project has no GitHub repo');
|
|
91
91
|
const raw = JSON.parse(await run('gh', ['api', `repos/${repo}/pulls?state=all&sort=updated&direction=desc&per_page=40`], cwd));
|
|
92
|
-
return raw.map((p) => ({
|
|
92
|
+
return raw.map((p) => ({
|
|
93
|
+
number: p.number, title: p.title, url: p.html_url, draft: p.draft === true, open: p.state === 'open',
|
|
94
|
+
...(p.updated_at ? { updatedAt: p.updated_at } : {}),
|
|
95
|
+
...(p.merged_at ? { mergedAt: p.merged_at } : {}),
|
|
96
|
+
...(p.closed_at ? { closedAt: p.closed_at } : {}),
|
|
97
|
+
}));
|
|
93
98
|
}
|
|
94
99
|
export function linearTeamKey(home) {
|
|
95
100
|
let raw;
|
|
@@ -113,7 +118,7 @@ export function quoteNotes(memory) {
|
|
|
113
118
|
export function projectRepo(def) {
|
|
114
119
|
return def.repo ?? def.repos?.[0]?.slug;
|
|
115
120
|
}
|
|
116
|
-
export function buildBrief(inputs) {
|
|
121
|
+
export function buildBrief(inputs, nowMs = Date.now()) {
|
|
117
122
|
const { def } = inputs;
|
|
118
123
|
const out = [];
|
|
119
124
|
out.push(`# Lead brief: ${inputs.project}`);
|
|
@@ -128,7 +133,7 @@ export function buildBrief(inputs) {
|
|
|
128
133
|
if (inputs.agentsDigest)
|
|
129
134
|
out.push('', '## AGENTS.md digest', inputs.agentsDigest);
|
|
130
135
|
const rows = Object.values(inputs.roster);
|
|
131
|
-
out.push('', `## Live sessions (${rows.length})`, ...(rows.length ? rows.map(formatRosterRow) : ['None.']), inputs.fleet);
|
|
136
|
+
out.push('', `## Live sessions (${rows.length})`, ...(rows.length ? rows.map((r) => formatRosterRow(r, nowMs)) : ['None.']), inputs.fleet);
|
|
132
137
|
out.push('', '## Open tickets');
|
|
133
138
|
if ('error' in inputs.tickets)
|
|
134
139
|
out.push(`Unavailable: ${inputs.tickets.error}`);
|
|
@@ -143,7 +148,12 @@ export function buildBrief(inputs) {
|
|
|
143
148
|
else if (open.length === 0)
|
|
144
149
|
out.push('None.');
|
|
145
150
|
else
|
|
146
|
-
out.push(...open.map((p) => `- #${p.number} ${p.title}${p.draft ? ' (draft)' : ''}`));
|
|
151
|
+
out.push(...open.map((p) => `- #${p.number} ${p.title}${p.draft ? ' (draft)' : ''}${p.updatedAt ? ` · updated ${ago(p.updatedAt, nowMs)}` : ''}`));
|
|
152
|
+
const ended = 'error' in inputs.prs ? [] : inputs.prs.filter((p) => !p.open);
|
|
153
|
+
if (ended.length) {
|
|
154
|
+
out.push('', `## Merged or closed lately (as of ${new Date(nowMs).toISOString()})`);
|
|
155
|
+
out.push(...ended.map((p) => `- #${p.number} ${p.title} · ${p.mergedAt ? `merged ${ago(p.mergedAt, nowMs)}` : `closed without merging ${p.closedAt ? ago(p.closedAt, nowMs) : ''}`.trimEnd()}`));
|
|
156
|
+
}
|
|
147
157
|
out.push('', '## Memory', quoteNotes(inputs.memory));
|
|
148
158
|
return out.join('\n');
|
|
149
159
|
}
|
package/dist/lib/lead/host.js
CHANGED
|
@@ -307,7 +307,7 @@ export class LeadHost {
|
|
|
307
307
|
if (!this.roster.ready)
|
|
308
308
|
throw new Error('The live feed is not connected yet; try again in a few seconds.');
|
|
309
309
|
const rows = Object.values(this.projectRoster(project));
|
|
310
|
-
const lines = rows.length ? rows.map(formatRosterRow) : [`No live sessions for ${project}.`];
|
|
310
|
+
const lines = rows.length ? rows.map((r) => formatRosterRow(r, Date.now())) : [`No live sessions for ${project}.`];
|
|
311
311
|
return { type: 'roster', text: [`Live sessions for ${project} (${rows.length}):`, ...lines, this.fleetSummary()].join('\n') };
|
|
312
312
|
}
|
|
313
313
|
resolveReply(session) {
|
|
@@ -6,6 +6,8 @@ export interface RosterRow {
|
|
|
6
6
|
project?: string;
|
|
7
7
|
cwd?: string;
|
|
8
8
|
ticket?: string;
|
|
9
|
+
startedAtMs?: number;
|
|
10
|
+
lastActivityMs?: number;
|
|
9
11
|
}
|
|
10
12
|
export type RosterSnapshot = Record<string, RosterRow>;
|
|
11
13
|
export interface LeadAttention {
|
|
@@ -38,7 +40,8 @@ export declare class FeedRoster {
|
|
|
38
40
|
private scopeRows;
|
|
39
41
|
}
|
|
40
42
|
export declare function filterProject(snapshot: RosterSnapshot, project: string, projectForCwd: (cwd: string | undefined) => string | undefined, exclude?: ReadonlySet<string>): RosterSnapshot;
|
|
41
|
-
export declare function formatRosterRow(row: RosterRow): string;
|
|
42
|
-
export declare function rosterDelta(prev: RosterSnapshot | null, cur: RosterSnapshot): string[];
|
|
43
|
+
export declare function formatRosterRow(row: RosterRow, nowMs: number): string;
|
|
44
|
+
export declare function rosterDelta(prev: RosterSnapshot | null, cur: RosterSnapshot, nowMs?: number): string[];
|
|
45
|
+
export declare function ago(at: string | number, nowMs: number): string;
|
|
43
46
|
export declare function formatAttention(ask: LeadAttention, row: RosterRow | undefined, nowMs?: number): string;
|
|
44
47
|
export {};
|
package/dist/lib/lead/roster.js
CHANGED
|
@@ -2,6 +2,9 @@ import { sessionHeadline } from '../session/title.js';
|
|
|
2
2
|
function str(v) {
|
|
3
3
|
return typeof v === 'string' && v.length > 0 ? v : undefined;
|
|
4
4
|
}
|
|
5
|
+
function num(v) {
|
|
6
|
+
return typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : undefined;
|
|
7
|
+
}
|
|
5
8
|
export function rosterRowFromFeed(scope, agent) {
|
|
6
9
|
const id = str(agent.sessionId);
|
|
7
10
|
if (!id || agent.previous === true)
|
|
@@ -16,6 +19,8 @@ export function rosterRowFromFeed(scope, agent) {
|
|
|
16
19
|
project: str(agent.confirmedProject),
|
|
17
20
|
cwd: str(agent.cwd),
|
|
18
21
|
ticket: str(agent.ticketId),
|
|
22
|
+
startedAtMs: num(agent.startedAtMs),
|
|
23
|
+
lastActivityMs: num(agent.lastActivityMs),
|
|
19
24
|
};
|
|
20
25
|
}
|
|
21
26
|
export function attentionFromFeed(item) {
|
|
@@ -148,14 +153,16 @@ export function filterProject(snapshot, project, projectForCwd, exclude = new Se
|
|
|
148
153
|
}
|
|
149
154
|
return out;
|
|
150
155
|
}
|
|
151
|
-
export function formatRosterRow(row) {
|
|
156
|
+
export function formatRosterRow(row, nowMs) {
|
|
152
157
|
const ticket = row.ticket ? ` ${row.ticket}` : '';
|
|
153
|
-
|
|
158
|
+
const started = row.startedAtMs ? ` · started ${ago(row.startedAtMs, nowMs)}` : '';
|
|
159
|
+
const active = row.lastActivityMs ? ` · last active ${ago(row.lastActivityMs, nowMs)}` : '';
|
|
160
|
+
return `- ${row.id.slice(0, 8)} “${row.title}” ${row.status} on ${row.host}${ticket}${started}${active}`;
|
|
154
161
|
}
|
|
155
|
-
export function rosterDelta(prev, cur) {
|
|
162
|
+
export function rosterDelta(prev, cur, nowMs = Date.now()) {
|
|
156
163
|
if (!prev) {
|
|
157
164
|
const rows = Object.values(cur);
|
|
158
|
-
return rows.length === 0 ? ['No live sessions for this project.'] : rows.map(formatRosterRow);
|
|
165
|
+
return rows.length === 0 ? ['No live sessions for this project.'] : rows.map((r) => formatRosterRow(r, nowMs));
|
|
159
166
|
}
|
|
160
167
|
const lines = [];
|
|
161
168
|
for (const row of Object.values(cur)) {
|
|
@@ -174,8 +181,8 @@ export function rosterDelta(prev, cur) {
|
|
|
174
181
|
return lines;
|
|
175
182
|
}
|
|
176
183
|
const MAX_QUESTION_CHARS = 240;
|
|
177
|
-
function
|
|
178
|
-
const ms = nowMs - Date.parse(
|
|
184
|
+
export function ago(at, nowMs) {
|
|
185
|
+
const ms = nowMs - (typeof at === 'number' ? at : Date.parse(at));
|
|
179
186
|
if (!Number.isFinite(ms) || ms < 0)
|
|
180
187
|
return 'just now';
|
|
181
188
|
const mins = Math.floor(ms / 60_000);
|
|
@@ -192,5 +199,5 @@ export function formatAttention(ask, row, nowMs = Date.now()) {
|
|
|
192
199
|
const title = row?.title ?? ask.sessionId.slice(0, 8);
|
|
193
200
|
const project = ask.project ?? row?.project;
|
|
194
201
|
const choices = ask.choices.length ? ` Choices: ${ask.choices.map((c) => `${c.id}=${c.label}`).join(', ')}` : ' Free-text answer.';
|
|
195
|
-
return `- ${ask.key} “${title}” on ${ask.host}${project ? ` · ${project}` : ''} · ${
|
|
202
|
+
return `- ${ask.key} “${title}” on ${ask.host}${project ? ` · ${project}` : ''} · ${ago(ask.openedAt, nowMs)}: ${trimmed}${choices}`;
|
|
196
203
|
}
|
package/dist/lib/lead/tools.d.ts
CHANGED
|
@@ -10,6 +10,16 @@ export interface LeadToolContext {
|
|
|
10
10
|
export declare function leadToolContext(env?: NodeJS.ProcessEnv): LeadToolContext;
|
|
11
11
|
export declare function toolRoster(ctx: LeadToolContext, project?: string): Promise<string>;
|
|
12
12
|
export declare function toolAttention(ctx: LeadToolContext): Promise<string>;
|
|
13
|
+
interface LinearIssue {
|
|
14
|
+
identifier: string;
|
|
15
|
+
title: string;
|
|
16
|
+
state?: {
|
|
17
|
+
name?: string;
|
|
18
|
+
};
|
|
19
|
+
url?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
updatedAt?: string;
|
|
22
|
+
}
|
|
13
23
|
export declare function toolDispatch(ctx: LeadToolContext, ticket: string, agent: string): Promise<string>;
|
|
14
24
|
export declare function toolStart(ctx: LeadToolContext, agent: string, task: string): Promise<string>;
|
|
15
25
|
export declare function toolSend(ctx: LeadToolContext, session: string, text: string): Promise<string>;
|
|
@@ -24,6 +34,7 @@ export declare function toolPrAct(ctx: LeadToolContext, verb: PrVerb, opts: {
|
|
|
24
34
|
runId?: string;
|
|
25
35
|
}): Promise<string>;
|
|
26
36
|
export declare function toolLinearTasks(ctx: LeadToolContext, status: string, limit: number): Promise<string>;
|
|
37
|
+
export declare function formatLinearTasks(issues: LinearIssue[], status: string, limit: number, nowMs: number): string;
|
|
27
38
|
export declare function toolLinearView(id: string): Promise<string>;
|
|
28
39
|
export declare function toolLinearCreate(ctx: LeadToolContext, title: string, description?: string): Promise<string>;
|
|
29
40
|
export declare function toolRemember(ctx: LeadToolContext, note: string): string;
|
package/dist/lib/lead/tools.js
CHANGED
|
@@ -2,6 +2,7 @@ import { loadProjectDef } from '../projects.js';
|
|
|
2
2
|
import { atomicWriteFileSync } from '../fs-atomic.js';
|
|
3
3
|
import { connectHost, sendRequest } from './client.js';
|
|
4
4
|
import { runAgents, runLinear } from './act.js';
|
|
5
|
+
import { ago } from './roster.js';
|
|
5
6
|
import { LeadToolError, answerArgv, appendNote, assertAgent, assertPrNumber, assertRepo, assertSessionId, assertTask, assertTicketId, dispatchPrompt, linearCreateArgv, linearPickupArgv, linearTasksArgv, linearViewArgv, prArgv, prFailureArgv, prReadArgv, prsListArgv, runArgv, sendArgv, } from './shapes.js';
|
|
6
7
|
import { ensureLeadDir } from './paths.js';
|
|
7
8
|
import { readMemory } from './store.js';
|
|
@@ -94,7 +95,7 @@ export async function toolPrsList(ctx, repo) {
|
|
|
94
95
|
continue;
|
|
95
96
|
}
|
|
96
97
|
for (const pr of r.pullRequests)
|
|
97
|
-
lines.push(`${r.slug}#${pr.number}${pr.isDraft ? ' [draft]' : ''} ${pr.title}`);
|
|
98
|
+
lines.push(`${r.slug}#${pr.number}${pr.isDraft ? ' [draft]' : ''} ${pr.title}${pr.updatedAt ? ` · updated ${ago(pr.updatedAt, Date.now())}` : ''}`);
|
|
98
99
|
}
|
|
99
100
|
return lines.length ? lines.join('\n') : `No open PRs for ${ctx.project}.`;
|
|
100
101
|
}
|
|
@@ -147,10 +148,17 @@ export async function toolPrAct(ctx, verb, opts) {
|
|
|
147
148
|
}
|
|
148
149
|
export async function toolLinearTasks(ctx, status, limit) {
|
|
149
150
|
const raw = JSON.parse(await runLinear(linearTasksArgv(ctx.def, status, limit)));
|
|
150
|
-
|
|
151
|
+
return formatLinearTasks(raw.issues ?? [], status, limit, Date.now());
|
|
152
|
+
}
|
|
153
|
+
export function formatLinearTasks(issues, status, limit, nowMs) {
|
|
151
154
|
if (issues.length === 0)
|
|
152
155
|
return `No ${status} tickets.`;
|
|
153
|
-
|
|
156
|
+
const when = (i) => (i.updatedAt ? Date.parse(i.updatedAt) || 0 : 0);
|
|
157
|
+
const shown = [...issues].sort((a, b) => when(b) - when(a)).slice(0, limit);
|
|
158
|
+
const lines = shown.map((i) => `${i.identifier} ${i.title}${i.state?.name ? ` (${i.state.name})` : ''}${i.updatedAt ? ` · updated ${ago(i.updatedAt, nowMs)}` : ''}`);
|
|
159
|
+
if (issues.length > shown.length)
|
|
160
|
+
lines.push(`(${issues.length - shown.length} older ${status} tickets not shown)`);
|
|
161
|
+
return lines.join('\n');
|
|
154
162
|
}
|
|
155
163
|
export async function toolLinearView(id) {
|
|
156
164
|
const i = JSON.parse(await runLinear(linearViewArgv(id)));
|
|
@@ -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,
|
|
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
|
|
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 =
|
|
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.
|
|
3
|
+
"version": "1.23.38",
|
|
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",
|