@phnx-labs/agents-cli 1.23.32 → 1.23.33

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,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.23.33
4
+
5
+ - **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
6
+
7
+ - **A live Claude row lists the PRs and tickets the session acted on.** `touchedPrs` (`[{ url, number, repo, action }]`, action `merged`, `reviewed`, `commented`, `checked out`, `edited` or `closed`) comes from `gh pr merge|review|comment|checkout|edit|close` and `agents projects prs merge|review|comment`; `touchedTickets` (`[{ id, action }]`) from `linear update`. Only calls that ran and succeeded count, newest first with the last action per item, leaving out what the session created itself (`prs`, `createdTickets`). Upgrading re-parses a Claude transcript from the start the next time it changes. Source: cli/src/lib/session/touched.ts, cli/src/lib/session/discover.ts, cli/src/lib/session/active.ts
8
+
3
9
  ## 1.23.32
4
10
 
5
11
  - **A session row lists every PR the session opened (#3989).** The session index records each PR a Claude or Codex session created (`pr_urls`, schema v53), not only the first, and live and ended rows read it as `prs`, so a long session whose PR creations scrolled out of its transcript tail still lists them all. Upgrading re-parses only the transcripts of sessions that already have a PR. Source: cli/src/lib/session/discover.ts, cli/src/lib/session/db.ts, cli/src/lib/session/active.ts
@@ -2,6 +2,7 @@ import type { CloudTaskStatus } from '../cloud/types.js';
2
2
  import { type PidSessionEntry } from './pid-registry.js';
3
3
  import { type HookSessionIndex } from './hook-sessions.js';
4
4
  import { type SessionRecap } from './title.js';
5
+ import type { TouchedPr, TouchedTicket } from './touched.js';
5
6
  import { type UserPromptKind } from '@phnx-labs/sessions-cli/reader';
6
7
  import { type SessionState, type SessionActivity, type AwaitingReason, type StructuredQuestion, type TodoProgress, type DetectedPr, type DetectedWorktree, type DetectedTicket } from '@phnx-labs/sessions-cli/reader';
7
8
  import { type SessionAgentId, type SessionAttachment, type SessionFiles, type SessionMeta, type SessionRequest, type SessionTimeline } from '@phnx-labs/sessions-cli/reader';
@@ -108,6 +109,8 @@ export interface ActiveSession {
108
109
  ticket?: DetectedTicket;
109
110
  rateLimited?: boolean;
110
111
  createdTickets?: string[];
112
+ touchedPrs?: TouchedPr[];
113
+ touchedTickets?: TouchedTicket[];
111
114
  spawnedTeam?: string;
112
115
  attachments?: SessionAttachment[];
113
116
  request?: SessionRequest;
@@ -158,6 +158,10 @@ export function applySessionNames(sessions) {
158
158
  }) ?? s.label;
159
159
  if (stored?.recap)
160
160
  s.recap = stored.recap;
161
+ if (stored?.touchedPrs)
162
+ s.touchedPrs = stored.touchedPrs;
163
+ if (stored?.touchedTickets)
164
+ s.touchedTickets = stored.touchedTickets;
161
165
  }
162
166
  }
163
167
  export function sessionAccountLabel(kind, session, accounts = listNativeAccounts(readMeta())) {
@@ -1,6 +1,7 @@
1
1
  import Database from '../sqlite.js';
2
2
  import type { SessionAgentId, SessionCheckpoint, SessionChecklistItem, SessionEvent, SessionFiles, SessionGlance, SessionMeta, SessionRequest, SessionSubagent, SessionTimeline, SummaryState } from '@phnx-labs/sessions-cli/reader';
3
3
  import type { SessionRecap } from './title.js';
4
+ import type { TouchedPr, TouchedTicket } from './touched.js';
4
5
  import { type IndexedToolCall } from '@phnx-labs/sessions-cli/reader';
5
6
  import { type ToolScanResumePoint } from './tool-store.js';
6
7
  import { type TimelineState } from '@phnx-labs/sessions-cli/reader';
@@ -94,6 +95,8 @@ export interface IndexedSessionNames {
94
95
  label?: string;
95
96
  customTitle?: string;
96
97
  recap?: SessionRecap;
98
+ touchedPrs?: TouchedPr[];
99
+ touchedTickets?: TouchedTicket[];
97
100
  }
98
101
  export declare function getIndexedSessionNames(rows: Array<{
99
102
  id: string;
@@ -1984,6 +1984,10 @@ export function upsertSessionsBatch(entries) {
1984
1984
  }
1985
1985
  maintainSessionSearchIndex(db);
1986
1986
  }
1987
+ function nonEmptyJsonArray(raw) {
1988
+ const list = raw ? JSON.parse(raw) : undefined;
1989
+ return list && list.length > 0 ? list : undefined;
1990
+ }
1987
1991
  export function getIndexedSessionNames(rows) {
1988
1992
  const out = new Map();
1989
1993
  if (rows.length === 0)
@@ -2010,14 +2014,16 @@ export function getIndexedSessionNames(rows) {
2010
2014
  for (let i = 0; i < keys.length; i += CHUNK) {
2011
2015
  const chunk = keys.slice(i, i + CHUNK);
2012
2016
  const fromState = db
2013
- .prepare(`SELECT file_path, json_extract(parser_state, '$.customTitle') AS custom_title, json_extract(parser_state, '$.recap') AS recap FROM scan_ledger WHERE file_path IN (${chunk.map(() => '?').join(',')}) AND json_valid(parser_state)`)
2017
+ .prepare(`SELECT file_path, json_extract(parser_state, '$.customTitle') AS custom_title, json_extract(parser_state, '$.recap') AS recap, json_extract(parser_state, '$.touchedPrs') AS touched_prs, json_extract(parser_state, '$.touchedTickets') AS touched_tickets FROM scan_ledger WHERE file_path IN (${chunk.map(() => '?').join(',')}) AND json_valid(parser_state)`)
2014
2018
  .all(...chunk);
2015
2019
  for (const row of fromState) {
2016
2020
  const id = idByLedgerKey.get(row.file_path);
2017
2021
  const customTitle = typeof row.custom_title === 'string' && row.custom_title ? row.custom_title : undefined;
2018
2022
  const recap = row.recap ? JSON.parse(row.recap) : undefined;
2019
- if (customTitle || recap)
2020
- out.set(id, { ...out.get(id), customTitle, recap });
2023
+ const touchedPrs = nonEmptyJsonArray(row.touched_prs);
2024
+ const touchedTickets = nonEmptyJsonArray(row.touched_tickets);
2025
+ if (customTitle || recap || touchedPrs || touchedTickets)
2026
+ out.set(id, { ...out.get(id), customTitle, recap, touchedPrs, touchedTickets });
2021
2027
  }
2022
2028
  }
2023
2029
  return out;
@@ -1,6 +1,7 @@
1
1
  import type { SessionAgentId, SessionEvent, SessionMeta, TodoProgress } from '@phnx-labs/sessions-cli/reader';
2
2
  export { machineForSessionFile } from './origin-machine.js';
3
3
  import { type ScanStamp } from './db.js';
4
+ import { type CommandTouches, type TouchedPr, type TouchedTicket } from './touched.js';
4
5
  import { type LiveSessionName, type SessionRecap } from './title.js';
5
6
  import { ToolCallCollector, type IndexedToolCall, type ToolCallCollectorSnapshot } from '@phnx-labs/sessions-cli/reader';
6
7
  interface DiscoverOptions {
@@ -209,6 +210,9 @@ interface ClaudeParseState {
209
210
  prUrls: string[];
210
211
  createdTickets: Set<string>;
211
212
  pendingTicketTools: Set<string>;
213
+ touchedPrs: TouchedPr[];
214
+ touchedTickets: TouchedTicket[];
215
+ pendingTouches: Map<string, CommandTouches>;
212
216
  spawnedTeam?: string;
213
217
  plan?: string;
214
218
  checklistEvents: SessionEvent[];
@@ -224,7 +228,7 @@ export declare function applyClaudeLine(state: ClaudeParseState, parsed: any): v
224
228
  export declare function finalizeClaudeScan(state: ClaudeParseState, sessionFile?: string): ClaudeSessionScan;
225
229
  export declare function scanClaudeSession(filePath: string): Promise<ClaudeSessionScan>;
226
230
  export interface ClaudeParserState {
227
- v: 6;
231
+ v: 7;
228
232
  subAgents: number;
229
233
  backgroundShells: number | undefined;
230
234
  offset: number;
@@ -259,9 +263,12 @@ export interface ClaudeParserState {
259
263
  pendingPrCreates?: string[];
260
264
  prUrl?: string;
261
265
  prNumber?: number;
262
- prUrls?: string[];
266
+ prUrls: string[];
263
267
  pendingTicketTools: string[];
264
268
  createdTickets: string[];
269
+ touchedPrs: TouchedPr[];
270
+ touchedTickets: TouchedTicket[];
271
+ pendingTouches: Array<[string, CommandTouches]>;
265
272
  spawnedTeam?: string;
266
273
  ticketId?: string;
267
274
  contentText?: string;
@@ -325,7 +332,7 @@ export declare function initCodexParseState(): CodexParseState;
325
332
  export declare function applyCodexLine(state: CodexParseState, parsed: any): void;
326
333
  export declare function finalizeCodexScan(state: CodexParseState): CodexSessionScan;
327
334
  export interface CodexParserState {
328
- v: 4;
335
+ v: 5;
329
336
  offset: number;
330
337
  jsonlDroppingOversizedLine?: boolean;
331
338
  sessionId?: string;
@@ -344,7 +351,7 @@ export interface CodexParserState {
344
351
  pendingPrCreates?: string[];
345
352
  prUrl?: string;
346
353
  prNumber?: number;
347
- prUrls?: string[];
354
+ prUrls: string[];
348
355
  pendingTicketTools: string[];
349
356
  createdTickets: string[];
350
357
  spawnedTeam?: string;
@@ -30,6 +30,7 @@ export { machineForSessionFile } from './origin-machine.js';
30
30
  import { mapBounded } from '../concurrency.js';
31
31
  import { getDB, getScanStampByPath, getScanStampsForPaths, getParserStatesForPaths, getDirLedgerForPaths, recordDirScans, recordScans, seedLabelsFromNames, syncTopics, upsertSessionsBatch, querySessions, countSessions, ftsSearch, getSessionById, tryClaimScan, releaseScan, scanInProgressByLivePid, cacheLinearProject, CONTENT_INDEX_VERSION, } from './db.js';
32
32
  import { buildRunNameMap } from './run-names.js';
33
+ import { recordTouches, touchesFromCommand, trackPendingTouches } from './touched.js';
33
34
  import { claudeRecapFromLine, resolveSessionName } from './title.js';
34
35
  import { resolveLinearApiKey } from '../linear-cache.js';
35
36
  import { ToolCallCollector, collectClaudeToolCalls, collectCodexToolCalls, } from '@phnx-labs/sessions-cli/reader';
@@ -2155,6 +2156,9 @@ export function initClaudeParseState() {
2155
2156
  prUrls: [],
2156
2157
  createdTickets: new Set(),
2157
2158
  pendingTicketTools: new Set(),
2159
+ touchedPrs: [],
2160
+ touchedTickets: [],
2161
+ pendingTouches: new Map(),
2158
2162
  spawnedTeam: undefined,
2159
2163
  plan: undefined,
2160
2164
  checklistEvents: [],
@@ -2212,6 +2216,9 @@ export function applyClaudeLine(state, parsed) {
2212
2216
  if (typeof b?.id === 'string' && isTicketCreateTool(b?.name, b?.input?.command)) {
2213
2217
  state.pendingTicketTools.add(b.id);
2214
2218
  }
2219
+ if (typeof b?.id === 'string' && b?.name === 'Bash' && typeof b?.input?.command === 'string' && b.input.run_in_background !== true) {
2220
+ trackPendingTouches(state.pendingTouches, b.id, touchesFromCommand(b.input.command, typeof parsed.cwd === 'string' ? parsed.cwd : state.cwd));
2221
+ }
2215
2222
  if (b?.name === 'ExitPlanMode' && typeof b?.input?.plan === 'string') {
2216
2223
  const p = b.input.plan.trim();
2217
2224
  if (p)
@@ -2255,6 +2262,22 @@ export function applyClaudeLine(state, parsed) {
2255
2262
  recordCreatedPr(state, extractPrUrl(text));
2256
2263
  }
2257
2264
  }
2265
+ if (state.pendingTouches.size > 0 && parsed.type === 'user' && Array.isArray(parsed.message?.content)) {
2266
+ for (const b of parsed.message.content) {
2267
+ if (b?.type !== 'tool_result' || typeof b?.tool_use_id !== 'string')
2268
+ continue;
2269
+ const touches = state.pendingTouches.get(b.tool_use_id);
2270
+ if (!touches)
2271
+ continue;
2272
+ state.pendingTouches.delete(b.tool_use_id);
2273
+ if (b.is_error === true)
2274
+ continue;
2275
+ const output = typeof b.content === 'string'
2276
+ ? b.content
2277
+ : Array.isArray(b.content) ? b.content.map((c) => c?.text || '').join('\n') : '';
2278
+ recordTouches(state, touches, output, { prUrls: state.prUrls, tickets: state.createdTickets });
2279
+ }
2280
+ }
2258
2281
  if (typeof parsed.timestamp === 'string') {
2259
2282
  const ms = new Date(parsed.timestamp).getTime();
2260
2283
  if (!Number.isNaN(ms)) {
@@ -2433,7 +2456,7 @@ export function serializeClaudeParserState(state, offset, jsonlDroppingOversized
2433
2456
  : allIds;
2434
2457
  const ticket = detectTicket(state.userTexts.join('\n') || undefined, state.gitBranch);
2435
2458
  return {
2436
- v: 6,
2459
+ v: 7,
2437
2460
  subAgents: state.subAgents,
2438
2461
  backgroundShells: state.backgroundShells,
2439
2462
  offset,
@@ -2471,6 +2494,9 @@ export function serializeClaudeParserState(state, offset, jsonlDroppingOversized
2471
2494
  prUrls: state.prUrls,
2472
2495
  pendingTicketTools: [...state.pendingTicketTools],
2473
2496
  createdTickets: [...state.createdTickets],
2497
+ touchedPrs: state.touchedPrs,
2498
+ touchedTickets: state.touchedTickets,
2499
+ pendingTouches: [...state.pendingTouches],
2474
2500
  spawnedTeam: state.spawnedTeam,
2475
2501
  ticketId: ticket?.id,
2476
2502
  contentText: state.userTexts.length > 0 ? state.userTexts.join('\n') : undefined,
@@ -2523,8 +2549,11 @@ export function hydrateClaudeParseState(prior) {
2523
2549
  pendingPrCreates: new Set(prior.pendingPrCreates),
2524
2550
  prUrl: prior.prUrl,
2525
2551
  prNumber: prior.prNumber,
2526
- prUrls: prior.prUrls ?? (prior.prUrl ? [prior.prUrl] : []),
2552
+ prUrls: prior.prUrls,
2527
2553
  createdTickets: new Set(prior.createdTickets),
2554
+ touchedPrs: prior.touchedPrs,
2555
+ touchedTickets: prior.touchedTickets,
2556
+ pendingTouches: new Map(prior.pendingTouches),
2528
2557
  pendingTicketTools: new Set(prior.pendingTicketTools),
2529
2558
  spawnedTeam: prior.spawnedTeam,
2530
2559
  plan: prior.plan,
@@ -2609,7 +2638,7 @@ function parsePriorClaudeState(row) {
2609
2638
  return null;
2610
2639
  try {
2611
2640
  const parsed = JSON.parse(row.parserState);
2612
- if (parsed?.v !== 6 || typeof parsed.offset !== 'number' || parsed.toolCalls?.v !== 1)
2641
+ if (parsed?.v !== 7 || typeof parsed.offset !== 'number' || parsed.toolCalls?.v !== 1)
2613
2642
  return null;
2614
2643
  return parsed;
2615
2644
  }
@@ -2849,7 +2878,7 @@ async function scanCodexSession(filePath) {
2849
2878
  export function serializeCodexParserState(state, offset, jsonlDroppingOversizedLine = false) {
2850
2879
  const ticket = detectTicket(state.userTexts.join('\n') || undefined, state.gitBranch);
2851
2880
  return {
2852
- v: 4,
2881
+ v: 5,
2853
2882
  offset,
2854
2883
  jsonlDroppingOversizedLine: jsonlDroppingOversizedLine || undefined,
2855
2884
  sessionId: state.sessionId,
@@ -2902,7 +2931,7 @@ export function hydrateCodexParseState(prior) {
2902
2931
  pendingPrCreates: new Set(prior.pendingPrCreates),
2903
2932
  prUrl: prior.prUrl,
2904
2933
  prNumber: prior.prNumber,
2905
- prUrls: prior.prUrls ?? (prior.prUrl ? [prior.prUrl] : []),
2934
+ prUrls: prior.prUrls,
2906
2935
  createdTickets: new Set(prior.createdTickets),
2907
2936
  pendingTicketTools: new Set(prior.pendingTicketTools),
2908
2937
  spawnedTeam: prior.spawnedTeam,
@@ -2977,7 +3006,7 @@ function parsePriorCodexState(row) {
2977
3006
  return null;
2978
3007
  try {
2979
3008
  const parsed = JSON.parse(row.parserState);
2980
- if (parsed?.v !== 4 || typeof parsed.offset !== 'number' || parsed.toolCalls?.v !== 1)
3009
+ if (parsed?.v !== 5 || typeof parsed.offset !== 'number' || parsed.toolCalls?.v !== 1)
2981
3010
  return null;
2982
3011
  return parsed;
2983
3012
  }
@@ -0,0 +1,30 @@
1
+ export type TouchedPrAction = 'merged' | 'reviewed' | 'commented' | 'checked out' | 'edited' | 'closed';
2
+ export interface TouchedPr {
3
+ url: string;
4
+ number: number;
5
+ repo: string;
6
+ action: TouchedPrAction;
7
+ }
8
+ export interface TouchedTicket {
9
+ id: string;
10
+ action: string;
11
+ }
12
+ export interface CommandTouches {
13
+ prs: Array<TouchedPr & {
14
+ masked?: true;
15
+ }>;
16
+ tickets: Array<TouchedTicket & {
17
+ masked?: true;
18
+ }>;
19
+ }
20
+ export declare function touchesFromCommand(command: string, cwd: string | undefined, repoForDir?: (dir: string) => string | undefined): CommandTouches;
21
+ interface TouchedLedger {
22
+ touchedPrs: TouchedPr[];
23
+ touchedTickets: TouchedTicket[];
24
+ }
25
+ export declare function trackPendingTouches(pending: Map<string, CommandTouches>, id: string, touches: CommandTouches): void;
26
+ export declare function recordTouches(ledger: TouchedLedger, touches: CommandTouches, output: string, created: {
27
+ prUrls: string[];
28
+ tickets: Iterable<string>;
29
+ }): void;
30
+ export {};
@@ -0,0 +1,297 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { linearIssueKeys, tokenizeBash } from '@phnx-labs/sessions-cli/reader';
6
+ import { repoFromRemote } from '../github/gh-overload.js';
7
+ const TOUCHED_MAX = 50;
8
+ const PENDING_MAX = 64;
9
+ const GH_BODY_FLAGS = ['-b', '--body', '-F', '--body-file'];
10
+ const GH_PR_VERBS = {
11
+ merge: { action: 'merged', valueFlags: new Set([...GH_BODY_FLAGS, '-t', '--subject', '--match-head-commit', '-A', '--author-email']) },
12
+ review: { action: 'reviewed', valueFlags: new Set(GH_BODY_FLAGS) },
13
+ comment: { action: 'commented', valueFlags: new Set(GH_BODY_FLAGS) },
14
+ checkout: { action: 'checked out', valueFlags: new Set(['-b', '--branch']) },
15
+ edit: {
16
+ action: 'edited',
17
+ valueFlags: new Set([...GH_BODY_FLAGS, '-t', '--title', '-B', '--base', '-m', '--milestone',
18
+ '--add-assignee', '--remove-assignee', '--add-label', '--remove-label', '--add-reviewer',
19
+ '--remove-reviewer', '--add-project', '--remove-project']),
20
+ },
21
+ close: { action: 'closed', valueFlags: new Set(['-c', '--comment']) },
22
+ };
23
+ const AGENTS_PRS_ACTIONS = {
24
+ merge: 'merged',
25
+ review: 'reviewed',
26
+ comment: 'commented',
27
+ };
28
+ const LINEAR_UPDATE_VALUE_FLAGS = new Set([
29
+ '--status', '--comment', '--proof', '--label', '--unlabel', '--priority', '--assign', '--delegate',
30
+ '--parent', '--project', '--milestone', '--title', '--description', '--description-file',
31
+ '--due-date', '--remind-at', '--cycle', '--blocks', '--blocked-by', '--relates', '--team',
32
+ ]);
33
+ const MERGED_EVIDENCE_RE = /"merged":\s*true|\bmerged pull request\b/i;
34
+ const PR_URL_RE = /^https?:\/\/github\.com\/([^/\s]+)\/([^/\s]+)\/pull\/(\d+)(?:[/?#]\S*)?$/;
35
+ function heredocDelimiter(cmd, at) {
36
+ const m = cmd.slice(at).match(/^<<(-?)\s*(['"]?)([A-Za-z_][\w-]*)\2/);
37
+ return m ? { word: m[3], strip: m[1] === '-' } : undefined;
38
+ }
39
+ function splitTopLevel(cmd) {
40
+ const out = [];
41
+ const heredocs = [];
42
+ let start = 0;
43
+ let depth = 0;
44
+ let quote;
45
+ const cut = (end, op, next) => {
46
+ const text = cmd.slice(start, end).trim();
47
+ if (text)
48
+ out.push({ text, op });
49
+ else if (out.length > 0 && op)
50
+ out[out.length - 1].op = op;
51
+ start = next;
52
+ return next - 1;
53
+ };
54
+ for (let i = 0; i < cmd.length; i++) {
55
+ const c = cmd[i];
56
+ if (quote) {
57
+ if (c === '\\' && quote !== "'")
58
+ i++;
59
+ else if (c === quote)
60
+ quote = undefined;
61
+ continue;
62
+ }
63
+ if (c === '\\') {
64
+ i++;
65
+ continue;
66
+ }
67
+ if (c === "'" || c === '"' || c === '`') {
68
+ quote = c;
69
+ continue;
70
+ }
71
+ if (c === '(') {
72
+ depth++;
73
+ continue;
74
+ }
75
+ if (c === ')') {
76
+ depth = Math.max(0, depth - 1);
77
+ continue;
78
+ }
79
+ if (depth > 0)
80
+ continue;
81
+ if (c === '<' && cmd[i + 1] === '<' && cmd[i + 2] !== '<') {
82
+ const h = heredocDelimiter(cmd, i);
83
+ if (h)
84
+ heredocs.push(h);
85
+ i++;
86
+ continue;
87
+ }
88
+ if (c === '\n') {
89
+ let next = i + 1;
90
+ for (const h of heredocs.splice(0)) {
91
+ while (next < cmd.length) {
92
+ const eol = cmd.indexOf('\n', next);
93
+ const line = cmd.slice(next, eol < 0 ? cmd.length : eol);
94
+ next = eol < 0 ? cmd.length : eol + 1;
95
+ if ((h.strip ? line.replace(/^\t+/, '') : line) === h.word)
96
+ break;
97
+ }
98
+ }
99
+ i = cut(i, ';', next);
100
+ continue;
101
+ }
102
+ if (c === ';') {
103
+ i = cut(i, ';', i + 1);
104
+ continue;
105
+ }
106
+ if (c === '&' && cmd[i + 1] === '&') {
107
+ i = cut(i, '&&', i + 2);
108
+ continue;
109
+ }
110
+ if (c === '|' && cmd[i + 1] === '|') {
111
+ i = cut(i, '||', i + 2);
112
+ continue;
113
+ }
114
+ if (c === '|') {
115
+ i = cut(i, '|', cmd[i + 1] === '&' ? i + 2 : i + 1);
116
+ continue;
117
+ }
118
+ if (c === '&' && cmd[i - 1] !== '>' && cmd[i + 1] !== '>') {
119
+ i = cut(i, '&', i + 1);
120
+ continue;
121
+ }
122
+ }
123
+ cut(cmd.length, '', cmd.length);
124
+ return out;
125
+ }
126
+ function flagValue(tokens, names) {
127
+ for (let i = 0; i < tokens.length; i++) {
128
+ const t = tokens[i];
129
+ for (const name of names) {
130
+ if (t === name)
131
+ return tokens[i + 1];
132
+ if (name.startsWith('--') && t.startsWith(`${name}=`))
133
+ return t.slice(name.length + 1);
134
+ }
135
+ }
136
+ return undefined;
137
+ }
138
+ function positionals(tokens, valueFlags) {
139
+ const out = [];
140
+ for (let i = 0; i < tokens.length; i++) {
141
+ const t = tokens[i];
142
+ if (t === '--') {
143
+ out.push(...tokens.slice(i + 1));
144
+ break;
145
+ }
146
+ if (t.startsWith('-')) {
147
+ if (valueFlags.has(t))
148
+ i++;
149
+ continue;
150
+ }
151
+ out.push(t);
152
+ }
153
+ return out;
154
+ }
155
+ function normalizeRepo(value) {
156
+ if (!value)
157
+ return undefined;
158
+ const m = value.replace(/^https?:\/\//, '').replace(/^github\.com\//, '').replace(/\.git$/, '').match(/^([\w.-]+)\/([\w.-]+)$/);
159
+ return m ? `${m[1]}/${m[2]}` : undefined;
160
+ }
161
+ function prTouch(repo, number, action) {
162
+ return { url: `https://github.com/${repo}/pull/${number}`, number, repo, action };
163
+ }
164
+ function withoutEnvPrefix(tokens) {
165
+ let i = 0;
166
+ while (i < tokens.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(tokens[i]))
167
+ i++;
168
+ return tokens.slice(i);
169
+ }
170
+ function ghPrTouch(tokens, inferRepo) {
171
+ const verb = GH_PR_VERBS[tokens[2] ?? ''];
172
+ if (!verb)
173
+ return undefined;
174
+ const args = tokens.slice(3);
175
+ if (verb.action === 'merged' && (args.includes('--auto') || args.includes('--disable-auto')))
176
+ return undefined;
177
+ const target = positionals(args, new Set(['-R', '--repo', ...verb.valueFlags]))[0];
178
+ if (!target)
179
+ return undefined;
180
+ const url = target.match(PR_URL_RE);
181
+ if (url)
182
+ return prTouch(`${url[1]}/${url[2]}`, Number(url[3]), verb.action);
183
+ if (!/^\d+$/.test(target))
184
+ return undefined;
185
+ const repo = normalizeRepo(flagValue(args, ['-R', '--repo'])) ?? inferRepo();
186
+ return repo ? prTouch(repo, Number(target), verb.action) : undefined;
187
+ }
188
+ function agentsPrsTouch(tokens) {
189
+ const action = AGENTS_PRS_ACTIONS[tokens[3] ?? ''];
190
+ if (!action)
191
+ return undefined;
192
+ const args = tokens.slice(4);
193
+ const repo = normalizeRepo(flagValue(args, ['--repo']));
194
+ const number = flagValue(args, ['--number']);
195
+ return repo && number && /^\d+$/.test(number) ? prTouch(repo, Number(number), action) : undefined;
196
+ }
197
+ function linearUpdateTouches(tokens) {
198
+ const args = tokens.slice(2);
199
+ const status = args.includes('--done') ? 'done'
200
+ : args.includes('--pickup') ? 'started'
201
+ : args.includes('--todo') ? 'moved to Todo'
202
+ : flagValue(args, ['--status']) ? `moved to ${flagValue(args, ['--status'])}`
203
+ : undefined;
204
+ const action = status
205
+ ?? (flagValue(args, ['--comment', '--proof']) !== undefined ? 'commented' : 'updated');
206
+ const ids = positionals(args, LINEAR_UPDATE_VALUE_FLAGS).flatMap(t => linearIssueKeys(t).filter(k => k === t.toUpperCase()));
207
+ return [...new Set(ids)].map(id => ({ id, action }));
208
+ }
209
+ function exitStatusCounts(segments, index) {
210
+ return segments.slice(index, -1).every(s => s.op === '&&');
211
+ }
212
+ export function touchesFromCommand(command, cwd, repoForDir = githubRepoForDir) {
213
+ const prs = [];
214
+ const tickets = [];
215
+ const segments = splitTopLevel(command);
216
+ let dir = cwd;
217
+ segments.forEach((segment, index) => {
218
+ const tokens = withoutEnvPrefix(tokenizeBash(segment.text)[0] ?? []);
219
+ const bin = path.basename(tokens[0] ?? '');
220
+ if (bin === 'cd') {
221
+ dir = resolveCommandDir(dir, tokens[1]);
222
+ return;
223
+ }
224
+ const mark = exitStatusCounts(segments, index) ? {} : { masked: true };
225
+ if (bin === 'gh' && tokens[1] === 'pr') {
226
+ const pr = ghPrTouch(tokens, () => (dir ? repoForDir(dir) : undefined));
227
+ if (pr)
228
+ prs.push({ ...pr, ...mark });
229
+ }
230
+ else if ((bin === 'agents' || bin === 'ag') && tokens[1] === 'projects' && tokens[2] === 'prs') {
231
+ const pr = agentsPrsTouch(tokens);
232
+ if (pr)
233
+ prs.push({ ...pr, ...mark });
234
+ }
235
+ else if (bin === 'linear' && tokens[1] === 'update') {
236
+ tickets.push(...linearUpdateTouches(tokens).map(t => ({ ...t, ...mark })));
237
+ }
238
+ });
239
+ return { prs, tickets };
240
+ }
241
+ const REPO_CACHE_MAX = 1024;
242
+ const repoByDir = new Map();
243
+ function githubRepoForDir(dir) {
244
+ const cached = repoByDir.get(dir);
245
+ if (cached !== undefined)
246
+ return cached ?? undefined;
247
+ let repo = null;
248
+ try {
249
+ if (fs.statSync(dir).isDirectory()) {
250
+ const url = execFileSync('git', ['-C', dir, 'config', '--get', 'remote.origin.url'], {
251
+ encoding: 'utf-8',
252
+ stdio: ['ignore', 'pipe', 'ignore'],
253
+ timeout: 2_000,
254
+ });
255
+ repo = repoFromRemote(url);
256
+ }
257
+ }
258
+ catch { }
259
+ if (repoByDir.size >= REPO_CACHE_MAX)
260
+ repoByDir.delete(repoByDir.keys().next().value);
261
+ repoByDir.set(dir, repo);
262
+ return repo ?? undefined;
263
+ }
264
+ function resolveCommandDir(cwd, cdTarget) {
265
+ if (!cdTarget || cdTarget === '~')
266
+ return os.homedir();
267
+ const expanded = cdTarget.startsWith('~/') ? path.join(os.homedir(), cdTarget.slice(2)) : cdTarget;
268
+ if (path.isAbsolute(expanded))
269
+ return expanded;
270
+ return cwd ? path.resolve(cwd, expanded) : undefined;
271
+ }
272
+ export function trackPendingTouches(pending, id, touches) {
273
+ if (touches.prs.length === 0 && touches.tickets.length === 0)
274
+ return;
275
+ if (pending.size >= PENDING_MAX)
276
+ pending.delete(pending.keys().next().value);
277
+ pending.set(id, touches);
278
+ }
279
+ export function recordTouches(ledger, touches, output, created) {
280
+ const createdPrs = new Set(created.prUrls.map(u => u.toLowerCase()));
281
+ const createdTickets = new Set([...created.tickets].map(t => t.toUpperCase()));
282
+ for (const { masked, ...pr } of touches.prs) {
283
+ if (masked && !(pr.action === 'merged' && MERGED_EVIDENCE_RE.test(output)))
284
+ continue;
285
+ const key = pr.url.toLowerCase();
286
+ if (createdPrs.has(key))
287
+ continue;
288
+ ledger.touchedPrs = [pr, ...ledger.touchedPrs.filter(p => p.url.toLowerCase() !== key)].slice(0, TOUCHED_MAX);
289
+ }
290
+ for (const { masked, ...ticket } of touches.tickets) {
291
+ if (masked)
292
+ continue;
293
+ if (createdTickets.has(ticket.id))
294
+ continue;
295
+ ledger.touchedTickets = [ticket, ...ledger.touchedTickets.filter(t => t.id !== ticket.id)].slice(0, TOUCHED_MAX);
296
+ }
297
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phnx-labs/agents-cli",
3
- "version": "1.23.32",
3
+ "version": "1.23.33",
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",