@phnx-labs/agents-cli 1.23.50 → 1.23.52
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/commands/sessions-backfill.d.ts +3 -0
- package/dist/commands/sessions-backfill.js +9 -6
- package/dist/lib/daemon/session-title-service.js +3 -3
- package/dist/lib/fleet-shared-state.d.ts +1 -0
- package/dist/lib/session/active.d.ts +1 -0
- package/dist/lib/session/active.js +2 -0
- package/dist/lib/session/db.d.ts +9 -2
- package/dist/lib/session/db.js +40 -13
- package/dist/lib/session/mirror.js +2 -0
- package/dist/lib/session/remote/watch.js +3 -1
- package/dist/lib/session/title.d.ts +29 -9
- package/dist/lib/session/title.js +153 -42
- package/dist/lib/startup/command-registry.js +18 -1
- package/dist/lib/startup/shadowing-alias.d.ts +8 -0
- package/dist/lib/startup/shadowing-alias.js +66 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.23.52
|
|
4
|
+
|
|
5
|
+
- **`agents browser` (and `computer`, `secrets`, `sessions`) now explain the alias that sent you there (PHNX-4641).** With `alias browser="agents browser"` in `~/.zshrc`, every `browser` call hit the removed-group error, and its advice, `browser --help`, looped straight back into it. The error now names the standalone binary by absolute path (`/opt/homebrew/bin/browser doctor`), says a shell alias or function is the likely cause (`type browser` shows it), and, when it finds one in `~/.zshrc`, `~/.zshenv`, `~/.zprofile`, `~/.bashrc`, `~/.bash_aliases`, `~/.bash_profile`, `~/.profile` or `~/.config/fish/config.fish`, names the file and line with the fix: delete it, then `unalias browser`. The scan is read-only and never edits an rc file. Source: `cli/src/lib/startup/command-registry.ts`, `cli/src/lib/startup/shadowing-alias.ts`.
|
|
6
|
+
|
|
7
|
+
## 1.23.51
|
|
8
|
+
|
|
9
|
+
- **Every session gets a workstream, and titles come in one batched call.** The `session-title` daemon service now names up to 12 sessions per tick in ONE cheap-model call instead of one call per session, and each reply carries a `workstream` beside the title: 1 to 3 words naming the larger effort ("Rush Mac", "Ahrefs SEO"). The call is shown the workstreams this box already uses, so related sessions share one name. A session keeps its workstream until its first message changes, and a `/rename`d session keeps its name and only gets a workstream. The field rides `agents ps --json`, `ps watch --json`, `feed watch --json`, history rows and the fleet session mirror, so AGI EXT can group sessions by what they are about. Schema v55 adds `sessions.workstream`. Source: `cli/src/lib/session/title.ts`, `cli/src/lib/session/db.ts`, `cli/src/lib/session/active.ts`, `cli/src/lib/session/remote/watch.ts`, `cli/src/lib/session/mirror.ts`.
|
|
10
|
+
|
|
3
11
|
## 1.23.50
|
|
4
12
|
|
|
5
13
|
- **A launch killed in its first second no longer locks the harness for ten minutes (PHNX-4610).** `withFileLockAsync` took its lock through proper-lockfile's async `lock()`, which registers the exit cleanup only after `mkdir` and two more fs callbacks, and its async `unlock()` drops that registration before the `rmdir`. A SIGTERM or SIGHUP landing in either gap left `<target>.lock` behind, and every later caller read it as held until it went stale. For the installation lock that is ten minutes, longer than the three minutes `agents __launch-lease` waits, so the next launch of that harness failed with `Could not acquire lock … Lock file is already being held` and `could not safely coordinate this launch with a possibly in-progress update`. Rush Cloud hit it when Stop landed during the shim's launch: the follow-up waited six minutes and failed. The async variant now takes and releases the lock through the same sync API `withFileLock` uses, so registration and removal never straddle an event-loop turn; the retry wait between attempts stays asynchronous. Measured with 12 children cycling the lock and killed mid-cycle: 8 of 12 left the lock before, 0 of 12 after. A SIGKILL still leaves it, as before. Source: `cli/src/lib/fs-atomic.ts`, `cli/src/lib/fs-atomic.test.ts`.
|
|
@@ -44,10 +44,13 @@ export interface TitleBackfillEnvelope {
|
|
|
44
44
|
scanned: number;
|
|
45
45
|
cached: number;
|
|
46
46
|
generated: number;
|
|
47
|
+
grouped: number;
|
|
47
48
|
failed: number;
|
|
49
|
+
errors: string[];
|
|
48
50
|
titles: Array<{
|
|
49
51
|
id: string;
|
|
50
52
|
title: string;
|
|
53
|
+
workstream?: string;
|
|
51
54
|
}>;
|
|
52
55
|
}
|
|
53
56
|
export declare function runTitlesBackfill(options: TitleBackfillOptions): Promise<TitleBackfillEnvelope>;
|
|
@@ -310,14 +310,14 @@ export function registerBackfillCommand(parent, invocation) {
|
|
|
310
310
|
});
|
|
311
311
|
const titles = backfill
|
|
312
312
|
.command('titles')
|
|
313
|
-
.description('Generate the session-row headline (a short technical title) now, instead of waiting for the daemon.')
|
|
313
|
+
.description('Generate the session-row headline (a short technical title) and its workstream now, instead of waiting for the daemon.')
|
|
314
314
|
.option('--session <id>', 'Title one session (full or short id), even if it is old or already titled')
|
|
315
315
|
.option('--limit <n>', 'Maximum titles to generate in this run')
|
|
316
316
|
.option('--refresh', 'Regenerate even when the stored title still matches the session\'s first user message')
|
|
317
317
|
.option('--json', 'Emit the machine-readable result');
|
|
318
318
|
setHelpSections(titles, {
|
|
319
319
|
examples: `
|
|
320
|
-
# Catch this machine up now (the daemon otherwise does
|
|
320
|
+
# Catch this machine up now (the daemon otherwise does up to 12 every 2 min, in one call)
|
|
321
321
|
${invocation} titles
|
|
322
322
|
|
|
323
323
|
# Re-title one session after correcting its first message
|
|
@@ -328,7 +328,8 @@ export function registerBackfillCommand(parent, invocation) {
|
|
|
328
328
|
`,
|
|
329
329
|
notes: `
|
|
330
330
|
- The headline ladder is: \`/rename\` label > this generated title > the user's first message. It is never the agent's latest turn.
|
|
331
|
-
- One cheap-model call per
|
|
331
|
+
- One cheap-model call per batch of up to 12 sessions (\`--model cheap\`, read-only plan mode) returns each session's title and workstream, generated ONCE and persisted; a session whose first message has not changed is a pure cache hit.
|
|
332
|
+
- The workstream is 1 to 3 words naming the larger effort (e.g. "Rush Mac"); the call is shown this box's existing workstreams so related sessions share one name. A \`/rename\`d session keeps its name and only gets a workstream.
|
|
332
333
|
- Local-only: each box titles its own sessions and publishes them to the fleet via the session mirror, so a peer's rows already carry their titles.
|
|
333
334
|
- Best-effort. With no signed-in harness nothing is generated and rows keep showing the user's own words.
|
|
334
335
|
`,
|
|
@@ -342,10 +343,12 @@ export function registerBackfillCommand(parent, invocation) {
|
|
|
342
343
|
else {
|
|
343
344
|
console.log(`${envelope.machine}: generated ${envelope.generated.toLocaleString()} title${envelope.generated === 1 ? '' : 's'}; ` +
|
|
344
345
|
`${envelope.cached.toLocaleString()} already current, ${envelope.scanned.toLocaleString()} scanned.`);
|
|
345
|
-
for (const { id, title } of envelope.titles)
|
|
346
|
-
console.log(` ${chalk.cyan(id.slice(0, 8))} ${title}`);
|
|
346
|
+
for (const { id, title, workstream } of envelope.titles)
|
|
347
|
+
console.log(` ${chalk.cyan(id.slice(0, 8))} ${title}${workstream ? chalk.gray(` · ${workstream}`) : ''}`);
|
|
348
|
+
if (envelope.grouped > 0)
|
|
349
|
+
console.log(`${envelope.grouped.toLocaleString()} session${envelope.grouped === 1 ? '' : 's'} got a workstream.`);
|
|
347
350
|
if (envelope.failed > 0) {
|
|
348
|
-
console.log(chalk.yellow(`${envelope.failed.toLocaleString()} session${envelope.failed === 1 ? '' : 's'}
|
|
351
|
+
console.log(chalk.yellow(`${envelope.failed.toLocaleString()} session${envelope.failed === 1 ? '' : 's'} got no usable title or workstream${envelope.errors.length ? ` (${envelope.errors.join('; ')})` : ''}; rerun to retry.`));
|
|
349
352
|
}
|
|
350
353
|
}
|
|
351
354
|
}
|
|
@@ -28,9 +28,9 @@ export class SessionTitleService extends BasePeriodicService {
|
|
|
28
28
|
signal,
|
|
29
29
|
...(this.run ? { run: this.run } : {}),
|
|
30
30
|
});
|
|
31
|
-
if (result.generated > 0) {
|
|
31
|
+
if (result.generated > 0 || result.grouped > 0) {
|
|
32
32
|
this.backoff = 0;
|
|
33
|
-
ctx.log('INFO', `session-title: generated ${result.generated} title(s) (${result.cached} already current)`);
|
|
33
|
+
ctx.log('INFO', `session-title: generated ${result.generated} title(s), ${result.grouped} workstream(s) (${result.cached} already current)`);
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
if (result.failed > 0) {
|
|
@@ -38,7 +38,7 @@ export class SessionTitleService extends BasePeriodicService {
|
|
|
38
38
|
? SESSION_TITLE_BACKOFF_START
|
|
39
39
|
: Math.min(this.backoff * 2, SESSION_TITLE_BACKOFF_MAX);
|
|
40
40
|
this.skipTicks = this.backoff;
|
|
41
|
-
ctx.log('WARN', `session-title: ${result.failed}
|
|
41
|
+
ctx.log('WARN', `session-title: ${result.failed} session(s) got no title or workstream${result.errors.length ? ` (${result.errors.join('; ')})` : ''}; backing off ${this.backoff} tick(s)`);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -164,6 +164,8 @@ export function applySessionNames(sessions) {
|
|
|
164
164
|
s.touchedPrs = stored.touchedPrs;
|
|
165
165
|
if (stored?.touchedTickets)
|
|
166
166
|
s.touchedTickets = stored.touchedTickets;
|
|
167
|
+
if (stored?.workstream)
|
|
168
|
+
s.workstream = stored.workstream;
|
|
167
169
|
}
|
|
168
170
|
}
|
|
169
171
|
export function sessionAccountLabel(kind, session, accounts = listNativeAccounts(readMeta())) {
|
package/dist/lib/session/db.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { TouchedPr, TouchedTicket } from './touched.js';
|
|
|
5
5
|
import { type IndexedToolCall } from '@phnx-labs/sessions-cli/reader';
|
|
6
6
|
import { type ToolScanResumePoint } from './tool-store.js';
|
|
7
7
|
import { type TimelineState } from '@phnx-labs/sessions-cli/reader';
|
|
8
|
-
export declare const SCHEMA_VERSION =
|
|
8
|
+
export declare const SCHEMA_VERSION = 55;
|
|
9
9
|
export declare const CONTENT_INDEX_VERSION = 8;
|
|
10
10
|
export declare const INSIGHTS_EXTRACTOR_VERSION = 7;
|
|
11
11
|
export declare const SESSION_SUMMARY_EXTRACTOR_VERSION = 1;
|
|
@@ -97,6 +97,7 @@ export interface IndexedSessionNames {
|
|
|
97
97
|
recap?: SessionRecap;
|
|
98
98
|
touchedPrs?: TouchedPr[];
|
|
99
99
|
touchedTickets?: TouchedTicket[];
|
|
100
|
+
workstream?: string;
|
|
100
101
|
}
|
|
101
102
|
export declare function getIndexedSessionNames(rows: Array<{
|
|
102
103
|
id: string;
|
|
@@ -221,6 +222,7 @@ export interface LocalMirrorSource {
|
|
|
221
222
|
firstUserMessage: string | null;
|
|
222
223
|
label: string | null;
|
|
223
224
|
generatedTitle: string | null;
|
|
225
|
+
workstream: string | null;
|
|
224
226
|
lastActivity: string | null;
|
|
225
227
|
timestamp: string;
|
|
226
228
|
ticketId: string | null;
|
|
@@ -240,6 +242,7 @@ export interface MirrorSessionUpsert {
|
|
|
240
242
|
firstUser?: string | null;
|
|
241
243
|
label?: string | null;
|
|
242
244
|
generatedTitle?: string | null;
|
|
245
|
+
workstream?: string | null;
|
|
243
246
|
lastActivity?: string | null;
|
|
244
247
|
timestamp: string;
|
|
245
248
|
ticketId?: string | null;
|
|
@@ -260,12 +263,16 @@ export interface SessionTitleCandidateRow {
|
|
|
260
263
|
gitBranch: string | null;
|
|
261
264
|
generatedTitle: string | null;
|
|
262
265
|
generatedTitleKey: string | null;
|
|
266
|
+
workstream: string | null;
|
|
263
267
|
}
|
|
264
268
|
export declare function querySessionTitleCandidates(limit: number, opts?: {
|
|
265
269
|
sinceMs?: number;
|
|
266
270
|
id?: string;
|
|
267
271
|
}): SessionTitleCandidateRow[];
|
|
268
|
-
export declare function setSessionGeneratedTitle(id: string, title: string, sourceKey: string, now?: number): boolean;
|
|
272
|
+
export declare function setSessionGeneratedTitle(id: string, title: string, sourceKey: string, now?: number, workstream?: string): boolean;
|
|
273
|
+
export declare function setSessionWorkstream(id: string, workstream: string): boolean;
|
|
274
|
+
export declare function getSessionWorkstream(id: string): string | undefined;
|
|
275
|
+
export declare function listRecentWorkstreams(sinceMs: number, limit: number): string[];
|
|
269
276
|
export declare function pruneMirrorSessions(cutoffMs: number): number;
|
|
270
277
|
export declare function getSessionPlugins(id: string): string[];
|
|
271
278
|
export type UsageRollupGroup = 'agent' | 'project' | 'day' | 'model' | 'account';
|
package/dist/lib/session/db.js
CHANGED
|
@@ -18,7 +18,7 @@ import { firstUserMessageFromEvents, lastUserMessageFromEvents } from '@phnx-lab
|
|
|
18
18
|
import { emptyTimelineState, TIMELINE_EXTRACTOR_VERSION } from '@phnx-labs/sessions-cli/reader';
|
|
19
19
|
const SESSIONS_DIR = getSessionsDir();
|
|
20
20
|
const DB_PATH = getSessionsDbPath();
|
|
21
|
-
export const SCHEMA_VERSION =
|
|
21
|
+
export const SCHEMA_VERSION = 55;
|
|
22
22
|
export const CONTENT_INDEX_VERSION = 8;
|
|
23
23
|
const RESOURCE_INDEX_VERSION = 2;
|
|
24
24
|
function canonicalLedgerKey(filePath) {
|
|
@@ -115,7 +115,8 @@ CREATE TABLE IF NOT EXISTS sessions (
|
|
|
115
115
|
-- is when it was produced.
|
|
116
116
|
generated_title TEXT,
|
|
117
117
|
generated_title_key TEXT,
|
|
118
|
-
generated_title_at INTEGER
|
|
118
|
+
generated_title_at INTEGER,
|
|
119
|
+
workstream TEXT
|
|
119
120
|
);
|
|
120
121
|
CREATE INDEX IF NOT EXISTS idx_sessions_timestamp ON sessions(timestamp DESC);
|
|
121
122
|
CREATE INDEX IF NOT EXISTS idx_sessions_cwd ON sessions(cwd);
|
|
@@ -1039,6 +1040,11 @@ function migrateSchema(db, fromVersion) {
|
|
|
1039
1040
|
}
|
|
1040
1041
|
if (fromVersion < 54)
|
|
1041
1042
|
reparseSessionsWithPr(db);
|
|
1043
|
+
if (fromVersion < 55) {
|
|
1044
|
+
const cols = db.prepare(`PRAGMA table_info(sessions)`).all();
|
|
1045
|
+
if (!cols.some(c => c.name === 'workstream'))
|
|
1046
|
+
db.exec(`ALTER TABLE sessions ADD COLUMN workstream TEXT`);
|
|
1047
|
+
}
|
|
1042
1048
|
}
|
|
1043
1049
|
function reparseSessionsWithPr(db) {
|
|
1044
1050
|
const withPr = db.prepare(`SELECT file_path FROM sessions WHERE pr_url IS NOT NULL AND file_path IS NOT NULL AND mirror_synced_at IS NULL`).all();
|
|
@@ -2022,10 +2028,10 @@ export function getIndexedSessionNames(rows) {
|
|
|
2022
2028
|
for (let i = 0; i < ids.length; i += CHUNK) {
|
|
2023
2029
|
const chunk = ids.slice(i, i + CHUNK);
|
|
2024
2030
|
const indexed = db
|
|
2025
|
-
.prepare(`SELECT id, label, file_path FROM sessions WHERE id IN (${chunk.map(() => '?').join(',')})`)
|
|
2031
|
+
.prepare(`SELECT id, label, file_path, workstream FROM sessions WHERE id IN (${chunk.map(() => '?').join(',')})`)
|
|
2026
2032
|
.all(...chunk);
|
|
2027
2033
|
for (const row of indexed) {
|
|
2028
|
-
out.set(row.id, { label: row.label ?? undefined });
|
|
2034
|
+
out.set(row.id, { label: row.label ?? undefined, ...(row.workstream ? { workstream: row.workstream } : {}) });
|
|
2029
2035
|
filePathById.set(row.id, filePathById.get(row.id) ?? row.file_path ?? undefined);
|
|
2030
2036
|
}
|
|
2031
2037
|
}
|
|
@@ -2789,7 +2795,7 @@ export function writeSessionTimeline(entry) {
|
|
|
2789
2795
|
export function queryLocalOriginSessionsForMirror(self, limit) {
|
|
2790
2796
|
const rows = getDB().prepare(`
|
|
2791
2797
|
SELECT id, short_id, agent, version, machine, cwd, topic, first_user_message,
|
|
2792
|
-
label, generated_title, last_activity, timestamp, ticket_id, pr_url
|
|
2798
|
+
label, generated_title, workstream, last_activity, timestamp, ticket_id, pr_url
|
|
2793
2799
|
FROM sessions
|
|
2794
2800
|
WHERE mirror_synced_at IS NULL
|
|
2795
2801
|
AND file_path IS NOT NULL AND file_path <> ''
|
|
@@ -2802,7 +2808,7 @@ export function queryLocalOriginSessionsForMirror(self, limit) {
|
|
|
2802
2808
|
return rows.map((r) => ({
|
|
2803
2809
|
id: r.id, shortId: r.short_id, agent: r.agent, version: r.version, machine: r.machine,
|
|
2804
2810
|
cwd: r.cwd, topic: r.topic, firstUserMessage: r.first_user_message, label: r.label,
|
|
2805
|
-
generatedTitle: r.generated_title,
|
|
2811
|
+
generatedTitle: r.generated_title, workstream: r.workstream,
|
|
2806
2812
|
lastActivity: r.last_activity, timestamp: r.timestamp, ticketId: r.ticket_id, prUrl: r.pr_url,
|
|
2807
2813
|
summary: readSessionSummaryAny(r.id) ?? null,
|
|
2808
2814
|
timeline: readSessionTimelineAny(r.id) ?? null,
|
|
@@ -2814,11 +2820,11 @@ export function upsertMirrorSession(row, source, syncedAt) {
|
|
|
2814
2820
|
const result = db.prepare(`
|
|
2815
2821
|
INSERT INTO sessions (
|
|
2816
2822
|
id, short_id, agent, origin, version, timestamp, last_activity, cwd,
|
|
2817
|
-
topic, first_user_message, label, generated_title, message_count, file_path, scanned_at,
|
|
2823
|
+
topic, first_user_message, label, generated_title, workstream, message_count, file_path, scanned_at,
|
|
2818
2824
|
is_team_origin, ticket_id, pr_url, machine, mirror_synced_at, mirror_source
|
|
2819
2825
|
) VALUES (
|
|
2820
2826
|
@id, @short_id, @agent, 'cli', @version, @timestamp, @last_activity, @cwd,
|
|
2821
|
-
@topic, @first_user, @label, @generated_title, NULL, '', @scanned_at,
|
|
2827
|
+
@topic, @first_user, @label, @generated_title, @workstream, NULL, '', @scanned_at,
|
|
2822
2828
|
0, @ticket_id, @pr_url, @machine, @synced_at, @source
|
|
2823
2829
|
)
|
|
2824
2830
|
ON CONFLICT(id) DO UPDATE SET
|
|
@@ -2842,6 +2848,7 @@ export function upsertMirrorSession(row, source, syncedAt) {
|
|
|
2842
2848
|
-- session yet clears it (the ladder then falls back to the synced first
|
|
2843
2849
|
-- user message, never to an agent line).
|
|
2844
2850
|
generated_title = excluded.generated_title,
|
|
2851
|
+
workstream = excluded.workstream,
|
|
2845
2852
|
ticket_id = COALESCE(excluded.ticket_id, sessions.ticket_id),
|
|
2846
2853
|
pr_url = COALESCE(excluded.pr_url, sessions.pr_url),
|
|
2847
2854
|
machine = excluded.machine,
|
|
@@ -2860,6 +2867,7 @@ export function upsertMirrorSession(row, source, syncedAt) {
|
|
|
2860
2867
|
first_user: row.firstUser ?? null,
|
|
2861
2868
|
label: row.label ?? null,
|
|
2862
2869
|
generated_title: row.generatedTitle ?? null,
|
|
2870
|
+
workstream: row.workstream ?? null,
|
|
2863
2871
|
ticket_id: row.ticketId ?? null,
|
|
2864
2872
|
pr_url: row.prUrl ?? null,
|
|
2865
2873
|
machine: row.machine,
|
|
@@ -2898,7 +2906,7 @@ export function querySessionTitleCandidates(limit, opts = {}) {
|
|
|
2898
2906
|
params.push(opts.id, opts.id);
|
|
2899
2907
|
}
|
|
2900
2908
|
else {
|
|
2901
|
-
clauses.push(`(label IS NULL OR trim(label) = '')`);
|
|
2909
|
+
clauses.push(`((label IS NULL OR trim(label) = '') OR workstream IS NULL)`);
|
|
2902
2910
|
if (opts.sinceMs != null) {
|
|
2903
2911
|
clauses.push(`COALESCE(last_activity, timestamp) >= ?`);
|
|
2904
2912
|
params.push(new Date(opts.sinceMs).toISOString());
|
|
@@ -2906,7 +2914,7 @@ export function querySessionTitleCandidates(limit, opts = {}) {
|
|
|
2906
2914
|
}
|
|
2907
2915
|
const rows = getDB().prepare(`
|
|
2908
2916
|
SELECT id, agent, cwd, project, topic, first_user_message, label, ticket_id,
|
|
2909
|
-
git_branch, generated_title, generated_title_key
|
|
2917
|
+
git_branch, generated_title, generated_title_key, workstream
|
|
2910
2918
|
FROM sessions
|
|
2911
2919
|
WHERE ${clauses.join(' AND ')}
|
|
2912
2920
|
ORDER BY COALESCE(last_activity, timestamp) DESC
|
|
@@ -2924,16 +2932,35 @@ export function querySessionTitleCandidates(limit, opts = {}) {
|
|
|
2924
2932
|
gitBranch: r.git_branch,
|
|
2925
2933
|
generatedTitle: r.generated_title,
|
|
2926
2934
|
generatedTitleKey: r.generated_title_key,
|
|
2935
|
+
workstream: r.workstream,
|
|
2927
2936
|
}));
|
|
2928
2937
|
}
|
|
2929
|
-
export function setSessionGeneratedTitle(id, title, sourceKey, now = Date.now()) {
|
|
2938
|
+
export function setSessionGeneratedTitle(id, title, sourceKey, now = Date.now(), workstream) {
|
|
2930
2939
|
const result = getDB().prepare(`
|
|
2931
2940
|
UPDATE sessions
|
|
2932
|
-
SET generated_title = ?, generated_title_key = ?, generated_title_at =
|
|
2941
|
+
SET generated_title = ?, generated_title_key = ?, generated_title_at = ?,
|
|
2942
|
+
workstream = COALESCE(?, workstream)
|
|
2933
2943
|
WHERE id = ? AND mirror_synced_at IS NULL
|
|
2934
|
-
`).run(title, sourceKey, now, id);
|
|
2944
|
+
`).run(title, sourceKey, now, workstream ?? null, id);
|
|
2935
2945
|
return result.changes > 0;
|
|
2936
2946
|
}
|
|
2947
|
+
export function setSessionWorkstream(id, workstream) {
|
|
2948
|
+
return getDB().prepare(`UPDATE sessions SET workstream = ? WHERE id = ? AND mirror_synced_at IS NULL`).run(workstream, id).changes > 0;
|
|
2949
|
+
}
|
|
2950
|
+
export function getSessionWorkstream(id) {
|
|
2951
|
+
const row = getDB().prepare(`SELECT workstream FROM sessions WHERE id = ?`).get(id);
|
|
2952
|
+
return row?.workstream ?? undefined;
|
|
2953
|
+
}
|
|
2954
|
+
export function listRecentWorkstreams(sinceMs, limit) {
|
|
2955
|
+
const rows = getDB().prepare(`
|
|
2956
|
+
SELECT workstream, COUNT(*) AS n FROM sessions
|
|
2957
|
+
WHERE workstream IS NOT NULL AND trim(workstream) <> ''
|
|
2958
|
+
AND COALESCE(last_activity, timestamp) >= ?
|
|
2959
|
+
GROUP BY workstream ORDER BY n DESC, MAX(COALESCE(last_activity, timestamp)) DESC
|
|
2960
|
+
LIMIT ?
|
|
2961
|
+
`).all(new Date(sinceMs).toISOString(), limit);
|
|
2962
|
+
return rows.map((r) => r.workstream);
|
|
2963
|
+
}
|
|
2937
2964
|
export function pruneMirrorSessions(cutoffMs) {
|
|
2938
2965
|
const db = getDB();
|
|
2939
2966
|
const stale = db.prepare(`SELECT id FROM sessions WHERE mirror_synced_at IS NOT NULL AND mirror_synced_at < ?`).all(cutoffMs);
|
|
@@ -66,6 +66,7 @@ export async function publishSessionMirrorToSharedStore(options = {}) {
|
|
|
66
66
|
...(snippet(s.topic, 200) ? { topic: snippet(s.topic, 200) } : {}),
|
|
67
67
|
...(s.label ? { label: s.label } : {}),
|
|
68
68
|
...(snippet(s.generatedTitle, 200) ? { title: snippet(s.generatedTitle, 200) } : {}),
|
|
69
|
+
...(snippet(s.workstream, 64) ? { workstream: snippet(s.workstream, 64) } : {}),
|
|
69
70
|
...(snippet(s.firstUserMessage) ? { firstUser: snippet(s.firstUserMessage) } : {}),
|
|
70
71
|
...(s.lastActivity ? { lastActivity: s.lastActivity } : {}),
|
|
71
72
|
timestamp: s.timestamp,
|
|
@@ -129,6 +130,7 @@ function toUpsert(raw) {
|
|
|
129
130
|
firstUser: cap(r.firstUser, SESSION_MIRROR_SNIPPET_MAX),
|
|
130
131
|
label: cap(r.label, 400),
|
|
131
132
|
generatedTitle: cap(r.title, 200),
|
|
133
|
+
workstream: cap(r.workstream, 64),
|
|
132
134
|
lastActivity: isString(r.lastActivity) ? r.lastActivity : undefined,
|
|
133
135
|
timestamp,
|
|
134
136
|
ticketId: cap(r.ticketId, 64),
|
|
@@ -15,7 +15,7 @@ import { loadSessionPreviewDigest, readCachedPreviewDigest } from '../preview-di
|
|
|
15
15
|
import { indexArtifactSidecars, mergeArtifacts } from '@phnx-labs/sessions-cli/reader';
|
|
16
16
|
import { listNativeAccounts } from '../../account-registry.js';
|
|
17
17
|
import { readMeta } from '../../state.js';
|
|
18
|
-
import { querySessions, readSessionSummaryAny, readSessionTimelineAny } from '../db.js';
|
|
18
|
+
import { getSessionWorkstream, querySessions, readSessionSummaryAny, readSessionTimelineAny } from '../db.js';
|
|
19
19
|
import { linearIssueUrl } from '@phnx-labs/sessions-cli/reader';
|
|
20
20
|
import { sessionAgentSupportsResume } from '../recovery.js';
|
|
21
21
|
import { SESSION_AGENTS } from '@phnx-labs/sessions-cli/reader';
|
|
@@ -114,6 +114,7 @@ export function toPreviousSessionWatchRow(scope, session, accounts = listNativeA
|
|
|
114
114
|
}
|
|
115
115
|
: readSessionSummaryAny(session.id);
|
|
116
116
|
const folded = readSessionTimelineAny(session.id);
|
|
117
|
+
const workstream = getSessionWorkstream(session.id);
|
|
117
118
|
const model = folded?.model ?? session.model;
|
|
118
119
|
const card = previousRowCard(session, folded?.request, folded?.attachments);
|
|
119
120
|
return {
|
|
@@ -127,6 +128,7 @@ export function toPreviousSessionWatchRow(scope, session, accounts = listNativeA
|
|
|
127
128
|
confirmedProject: confirmedProjectForCwd(session.cwd) ?? null,
|
|
128
129
|
...(session.label ? { label: session.label } : {}),
|
|
129
130
|
...(session.generatedTitle ? { generatedTitle: session.generatedTitle } : {}),
|
|
131
|
+
...(workstream ? { workstream } : {}),
|
|
130
132
|
...(session.topic ? { topic: session.topic } : {}),
|
|
131
133
|
...(session.firstUserMessage ? { firstUserMessage: session.firstUserMessage } : {}),
|
|
132
134
|
...(session.version ? { version: session.version } : {}),
|
|
@@ -3,10 +3,15 @@ export declare const SESSION_TITLE_PROMPT_MARKER = "Generate a concise session h
|
|
|
3
3
|
export declare const SESSION_TITLE_MAX_CHARS = 60;
|
|
4
4
|
export declare const SESSION_TITLE_MAX_WORDS = 8;
|
|
5
5
|
export declare const SESSION_TITLE_INPUT_MAX_CHARS = 2000;
|
|
6
|
-
export declare const SESSION_TITLE_MAX_PER_TICK =
|
|
6
|
+
export declare const SESSION_TITLE_MAX_PER_TICK = 12;
|
|
7
|
+
export declare const SESSION_TITLE_BATCH_SIZE = 12;
|
|
8
|
+
export declare const SESSION_TITLE_BATCH_INPUT_MAX_CHARS = 600;
|
|
9
|
+
export declare const SESSION_WORKSTREAM_MAX_CHARS = 32;
|
|
10
|
+
export declare const SESSION_WORKSTREAM_MAX_WORDS = 4;
|
|
11
|
+
export declare const SESSION_WORKSTREAMS_OFFERED = 30;
|
|
7
12
|
export declare const SESSION_TITLE_CANDIDATE_SCAN = 200;
|
|
8
13
|
export declare const SESSION_TITLE_MAX_AGE_MS: number;
|
|
9
|
-
export declare const SESSION_TITLE_TIMEOUT_MS =
|
|
14
|
+
export declare const SESSION_TITLE_TIMEOUT_MS = 90000;
|
|
10
15
|
export declare const SESSION_TITLE_AGENTS: readonly ["claude", "codex", "grok", "kimi", "opencode"];
|
|
11
16
|
export interface SessionTitleInput {
|
|
12
17
|
firstUserMessage?: string | null;
|
|
@@ -18,7 +23,17 @@ export interface SessionTitleInput {
|
|
|
18
23
|
export declare function sessionTitleSourceText(input: SessionTitleInput): string;
|
|
19
24
|
export declare function sessionTitleSourceKey(input: SessionTitleInput): string | null;
|
|
20
25
|
export declare function isSessionTitlePrompt(...values: Array<string | null | undefined>): boolean;
|
|
21
|
-
export
|
|
26
|
+
export interface SessionTitleBatchItem {
|
|
27
|
+
ref: string;
|
|
28
|
+
input: SessionTitleInput;
|
|
29
|
+
currentTitle?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function renderSessionTitleBatchPrompt(items: SessionTitleBatchItem[], workstreams: string[]): string;
|
|
32
|
+
export declare function sanitizeWorkstream(raw: unknown): string | undefined;
|
|
33
|
+
export declare function parseSessionTitleBatch(raw: string): Map<string, {
|
|
34
|
+
title?: string;
|
|
35
|
+
workstream?: string;
|
|
36
|
+
}>;
|
|
22
37
|
export declare function sanitizeGeneratedTitle(raw: string | null | undefined): string | undefined;
|
|
23
38
|
type CarriesTitleRung<T> = 'generatedTitle' extends keyof T ? T : never;
|
|
24
39
|
export declare function sessionHeadline<T extends {
|
|
@@ -58,13 +73,13 @@ export declare function resolveSessionTitleAgent(): Promise<string | null>;
|
|
|
58
73
|
export declare function defaultSessionTitleRunner(prompt: string, signal?: AbortSignal): Promise<string>;
|
|
59
74
|
export interface SessionTitleProvider {
|
|
60
75
|
readonly name: string;
|
|
61
|
-
|
|
76
|
+
generateBatch(items: SessionTitleBatchItem[], workstreams: string[], signal?: AbortSignal): Promise<string>;
|
|
62
77
|
}
|
|
63
78
|
export declare class CloudSessionTitleProvider implements SessionTitleProvider {
|
|
64
79
|
private readonly runner;
|
|
65
80
|
readonly name = "cloud";
|
|
66
81
|
constructor(runner?: SessionTitleRunner);
|
|
67
|
-
|
|
82
|
+
generateBatch(items: SessionTitleBatchItem[], workstreams: string[], signal?: AbortSignal): Promise<string>;
|
|
68
83
|
}
|
|
69
84
|
export declare function defaultSessionTitleProvider(): SessionTitleProvider;
|
|
70
85
|
export interface SessionTitleTickOptions {
|
|
@@ -81,20 +96,25 @@ export interface SessionTitleTickResult {
|
|
|
81
96
|
scanned: number;
|
|
82
97
|
cached: number;
|
|
83
98
|
generated: number;
|
|
99
|
+
grouped: number;
|
|
84
100
|
failed: number;
|
|
101
|
+
errors: string[];
|
|
85
102
|
titles: Array<{
|
|
86
103
|
id: string;
|
|
87
104
|
title: string;
|
|
105
|
+
workstream?: string;
|
|
88
106
|
}>;
|
|
89
107
|
}
|
|
108
|
+
export interface PendingSessionTitle {
|
|
109
|
+
row: SessionTitleCandidateRow;
|
|
110
|
+
sourceKey: string;
|
|
111
|
+
needsTitle: boolean;
|
|
112
|
+
}
|
|
90
113
|
export declare function selectSessionsNeedingTitle(rows: SessionTitleCandidateRow[], opts?: {
|
|
91
114
|
limit: number;
|
|
92
115
|
force?: boolean;
|
|
93
116
|
}): {
|
|
94
|
-
pending:
|
|
95
|
-
row: SessionTitleCandidateRow;
|
|
96
|
-
sourceKey: string;
|
|
97
|
-
}>;
|
|
117
|
+
pending: PendingSessionTitle[];
|
|
98
118
|
cached: number;
|
|
99
119
|
};
|
|
100
120
|
export declare function runSessionTitleTick(options?: SessionTitleTickOptions): Promise<SessionTitleTickResult>;
|
|
@@ -4,10 +4,15 @@ export const SESSION_TITLE_PROMPT_MARKER = 'Generate a concise session headline'
|
|
|
4
4
|
export const SESSION_TITLE_MAX_CHARS = 60;
|
|
5
5
|
export const SESSION_TITLE_MAX_WORDS = 8;
|
|
6
6
|
export const SESSION_TITLE_INPUT_MAX_CHARS = 2000;
|
|
7
|
-
export const SESSION_TITLE_MAX_PER_TICK =
|
|
7
|
+
export const SESSION_TITLE_MAX_PER_TICK = 12;
|
|
8
|
+
export const SESSION_TITLE_BATCH_SIZE = 12;
|
|
9
|
+
export const SESSION_TITLE_BATCH_INPUT_MAX_CHARS = 600;
|
|
10
|
+
export const SESSION_WORKSTREAM_MAX_CHARS = 32;
|
|
11
|
+
export const SESSION_WORKSTREAM_MAX_WORDS = 4;
|
|
12
|
+
export const SESSION_WORKSTREAMS_OFFERED = 30;
|
|
8
13
|
export const SESSION_TITLE_CANDIDATE_SCAN = 200;
|
|
9
14
|
export const SESSION_TITLE_MAX_AGE_MS = 14 * 24 * 60 * 60_000;
|
|
10
|
-
export const SESSION_TITLE_TIMEOUT_MS =
|
|
15
|
+
export const SESSION_TITLE_TIMEOUT_MS = 90_000;
|
|
11
16
|
export const SESSION_TITLE_AGENTS = ['claude', 'codex', 'grok', 'kimi', 'opencode'];
|
|
12
17
|
export function sessionTitleSourceText(input) {
|
|
13
18
|
const raw = (input.firstUserMessage || input.topic || '').replace(/\s+/g, ' ').trim();
|
|
@@ -22,29 +27,81 @@ export function sessionTitleSourceKey(input) {
|
|
|
22
27
|
export function isSessionTitlePrompt(...values) {
|
|
23
28
|
return values.some((v) => typeof v === 'string' && v.includes(SESSION_TITLE_PROMPT_MARKER));
|
|
24
29
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
function promptLine(raw, max) {
|
|
31
|
+
return (raw ?? '').replace(/\s+/g, ' ').trim().slice(0, max);
|
|
32
|
+
}
|
|
33
|
+
export function renderSessionTitleBatchPrompt(items, workstreams) {
|
|
34
|
+
const sessions = items.flatMap(({ ref, input, currentTitle: named }) => {
|
|
35
|
+
const text = sessionTitleSourceText(input).slice(0, SESSION_TITLE_BATCH_INPUT_MAX_CHARS);
|
|
36
|
+
const context = [
|
|
37
|
+
input.project ? `repository ${promptLine(input.project, 80)}` : null,
|
|
38
|
+
input.ticketId ? `ticket ${promptLine(input.ticketId, 80)}` : null,
|
|
39
|
+
input.gitBranch ? `branch ${promptLine(input.gitBranch, 80)}` : null,
|
|
40
|
+
].filter(Boolean).join(', ');
|
|
41
|
+
const currentTitle = promptLine(named, 120);
|
|
42
|
+
return [
|
|
43
|
+
`[${ref}]${context ? ` (${context})` : ''}`,
|
|
44
|
+
...(currentTitle ? [`Current title: ${currentTitle}`] : []),
|
|
45
|
+
`Request: ${text}`,
|
|
46
|
+
'',
|
|
47
|
+
];
|
|
48
|
+
});
|
|
32
49
|
return [
|
|
33
|
-
`${SESSION_TITLE_PROMPT_MARKER}
|
|
34
|
-
'
|
|
50
|
+
`${SESSION_TITLE_PROMPT_MARKER} and a workstream for each coding session below.`,
|
|
51
|
+
'title: an ACTION + OBJECT headline of 4 to 8 words naming the concrete task,',
|
|
35
52
|
'e.g. "Triage the AGI board" or "Rename browser profile — default confusion".',
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
|
|
40
|
-
|
|
53
|
+
'Not a single noun, not a full sentence, not the person, not the pleasantries.',
|
|
54
|
+
'workstream: 1 to 3 words naming the larger effort the session belongs to, the same name for',
|
|
55
|
+
'every session about that effort, e.g. "Rush Mac", "Ahrefs SEO", "Fundraising".',
|
|
56
|
+
workstreams.length
|
|
57
|
+
? `Reuse one of these existing workstreams whenever it fits; coin a new one only when none does: ${workstreams.map((w) => promptLine(w, SESSION_WORKSTREAM_MAX_CHARS)).join(' | ')}`
|
|
58
|
+
: 'Name workstreams so that related sessions share one.',
|
|
59
|
+
'Respond IMMEDIATELY with only a JSON array, one object per session, in this exact shape:',
|
|
60
|
+
'[{"ref": "1", "title": "...", "workstream": "..."}]',
|
|
61
|
+
'Do NOT investigate, do NOT read files, do NOT use any tools. No prose, no code fences.',
|
|
41
62
|
'',
|
|
42
|
-
|
|
43
|
-
'---',
|
|
44
|
-
text,
|
|
45
|
-
'---',
|
|
63
|
+
...sessions,
|
|
46
64
|
].join('\n');
|
|
47
65
|
}
|
|
66
|
+
export function sanitizeWorkstream(raw) {
|
|
67
|
+
if (typeof raw !== 'string')
|
|
68
|
+
return undefined;
|
|
69
|
+
let name = raw.replace(/["'`*_]/g, '').replace(/[.!?,;:]+$/, '').replace(/\s+/g, ' ').trim();
|
|
70
|
+
const words = name.split(' ');
|
|
71
|
+
if (words.length > SESSION_WORKSTREAM_MAX_WORDS)
|
|
72
|
+
name = words.slice(0, SESSION_WORKSTREAM_MAX_WORDS).join(' ');
|
|
73
|
+
if (name.length > SESSION_WORKSTREAM_MAX_CHARS)
|
|
74
|
+
name = name.slice(0, SESSION_WORKSTREAM_MAX_CHARS).trimEnd();
|
|
75
|
+
return name || undefined;
|
|
76
|
+
}
|
|
77
|
+
export function parseSessionTitleBatch(raw) {
|
|
78
|
+
const out = new Map();
|
|
79
|
+
const open = raw.indexOf('[');
|
|
80
|
+
const close = raw.lastIndexOf(']');
|
|
81
|
+
if (open < 0 || close <= open)
|
|
82
|
+
return out;
|
|
83
|
+
let parsed;
|
|
84
|
+
try {
|
|
85
|
+
parsed = JSON.parse(raw.slice(open, close + 1));
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
if (!Array.isArray(parsed))
|
|
91
|
+
return out;
|
|
92
|
+
for (const entry of parsed) {
|
|
93
|
+
if (!entry || typeof entry !== 'object')
|
|
94
|
+
continue;
|
|
95
|
+
const { ref, title, workstream } = entry;
|
|
96
|
+
if (typeof ref !== 'string' && typeof ref !== 'number')
|
|
97
|
+
continue;
|
|
98
|
+
out.set(String(ref), {
|
|
99
|
+
title: typeof title === 'string' ? sanitizeGeneratedTitle(title) : undefined,
|
|
100
|
+
workstream: sanitizeWorkstream(workstream),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
48
105
|
export function sanitizeGeneratedTitle(raw) {
|
|
49
106
|
if (!raw)
|
|
50
107
|
return undefined;
|
|
@@ -178,8 +235,8 @@ export class CloudSessionTitleProvider {
|
|
|
178
235
|
constructor(runner = defaultSessionTitleRunner) {
|
|
179
236
|
this.runner = runner;
|
|
180
237
|
}
|
|
181
|
-
|
|
182
|
-
return this.runner(
|
|
238
|
+
generateBatch(items, workstreams, signal) {
|
|
239
|
+
return this.runner(renderSessionTitleBatchPrompt(items, workstreams), signal);
|
|
183
240
|
}
|
|
184
241
|
}
|
|
185
242
|
export function defaultSessionTitleProvider() {
|
|
@@ -194,23 +251,25 @@ export function selectSessionsNeedingTitle(rows, opts = { limit: SESSION_TITLE_M
|
|
|
194
251
|
const sourceKey = sessionTitleSourceKey(row);
|
|
195
252
|
if (!sourceKey)
|
|
196
253
|
continue;
|
|
197
|
-
|
|
254
|
+
const named = Boolean(row.label?.trim());
|
|
255
|
+
const titleCurrent = named || (!opts.force && Boolean(row.generatedTitle) && row.generatedTitleKey === sourceKey);
|
|
256
|
+
const needsTitle = !titleCurrent;
|
|
257
|
+
if (!needsTitle && row.workstream) {
|
|
198
258
|
cached++;
|
|
199
259
|
continue;
|
|
200
260
|
}
|
|
201
261
|
if (pending.length < opts.limit)
|
|
202
|
-
pending.push({ row, sourceKey });
|
|
262
|
+
pending.push({ row, sourceKey, needsTitle });
|
|
203
263
|
}
|
|
204
264
|
return { pending, cached };
|
|
205
265
|
}
|
|
206
266
|
export async function runSessionTitleTick(options = {}) {
|
|
207
267
|
const limit = options.limit ?? SESSION_TITLE_MAX_PER_TICK;
|
|
208
268
|
const now = options.nowMs ?? Date.now();
|
|
209
|
-
const
|
|
210
|
-
const {
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
: { sinceMs: now - (options.maxAgeMs ?? SESSION_TITLE_MAX_AGE_MS) });
|
|
269
|
+
const maxAgeMs = options.maxAgeMs ?? SESSION_TITLE_MAX_AGE_MS;
|
|
270
|
+
const result = { scanned: 0, cached: 0, generated: 0, grouped: 0, failed: 0, errors: [], titles: [] };
|
|
271
|
+
const { querySessionTitleCandidates, setSessionGeneratedTitle, setSessionWorkstream, listRecentWorkstreams } = await import('./db.js');
|
|
272
|
+
const rows = querySessionTitleCandidates(options.id ? 1 : SESSION_TITLE_CANDIDATE_SCAN, options.id ? { id: options.id } : { sinceMs: now - maxAgeMs });
|
|
214
273
|
result.scanned = rows.length;
|
|
215
274
|
if (options.id && rows.length === 0) {
|
|
216
275
|
throw new Error(`no indexed session matches "${options.id}" on this machine — ` +
|
|
@@ -222,24 +281,76 @@ export async function runSessionTitleTick(options = {}) {
|
|
|
222
281
|
if (pending.length === 0)
|
|
223
282
|
return result;
|
|
224
283
|
const provider = options.provider ?? new CloudSessionTitleProvider(options.run);
|
|
225
|
-
|
|
284
|
+
const known = listRecentWorkstreams(now - maxAgeMs, SESSION_WORKSTREAMS_OFFERED);
|
|
285
|
+
const canonical = (name) => {
|
|
286
|
+
if (!name)
|
|
287
|
+
return undefined;
|
|
288
|
+
const hit = known.find((k) => k.toLowerCase() === name.toLowerCase());
|
|
289
|
+
if (hit)
|
|
290
|
+
return hit;
|
|
291
|
+
known.push(name);
|
|
292
|
+
return name;
|
|
293
|
+
};
|
|
294
|
+
const apply = (batch, reply) => {
|
|
295
|
+
batch.forEach(({ row, sourceKey, needsTitle }, n) => {
|
|
296
|
+
const answer = reply.get(String(n + 1));
|
|
297
|
+
const workstream = canonical(answer?.workstream);
|
|
298
|
+
if (needsTitle) {
|
|
299
|
+
const title = answer?.title;
|
|
300
|
+
if (!title) {
|
|
301
|
+
result.failed++;
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (setSessionGeneratedTitle(row.id, title, sourceKey, now, workstream)) {
|
|
305
|
+
result.generated++;
|
|
306
|
+
if (workstream)
|
|
307
|
+
result.grouped++;
|
|
308
|
+
result.titles.push({ id: row.id, title, ...(workstream ? { workstream } : {}) });
|
|
309
|
+
}
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (!workstream) {
|
|
313
|
+
result.failed++;
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (setSessionWorkstream(row.id, workstream))
|
|
317
|
+
result.grouped++;
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
const run = async (batch, split = false) => {
|
|
226
321
|
if (options.signal?.aborted)
|
|
227
|
-
|
|
228
|
-
|
|
322
|
+
return;
|
|
323
|
+
const items = batch.map(({ row, needsTitle }, n) => ({
|
|
324
|
+
ref: String(n + 1),
|
|
325
|
+
input: row,
|
|
326
|
+
...(needsTitle ? {} : { currentTitle: (row.label?.trim() || row.generatedTitle) ?? undefined }),
|
|
327
|
+
}));
|
|
328
|
+
let raw;
|
|
229
329
|
try {
|
|
230
|
-
|
|
330
|
+
raw = await provider.generateBatch(items, known, options.signal);
|
|
231
331
|
}
|
|
232
|
-
catch {
|
|
233
|
-
|
|
332
|
+
catch (error) {
|
|
333
|
+
if (options.signal?.aborted)
|
|
334
|
+
return;
|
|
335
|
+
const message = error instanceof Error ? error.message.split('\n')[0] : String(error);
|
|
336
|
+
if (!result.errors.includes(message))
|
|
337
|
+
result.errors.push(message);
|
|
338
|
+
result.failed += batch.length;
|
|
339
|
+
return;
|
|
234
340
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
result.titles.push({ id: row.id, title });
|
|
341
|
+
const reply = parseSessionTitleBatch(raw);
|
|
342
|
+
if (reply.size === 0 && batch.length > 1 && !split) {
|
|
343
|
+
const half = Math.ceil(batch.length / 2);
|
|
344
|
+
await run(batch.slice(0, half), true);
|
|
345
|
+
await run(batch.slice(half), true);
|
|
346
|
+
return;
|
|
242
347
|
}
|
|
348
|
+
apply(batch, reply);
|
|
349
|
+
};
|
|
350
|
+
for (let i = 0; i < pending.length; i += SESSION_TITLE_BATCH_SIZE) {
|
|
351
|
+
if (options.signal?.aborted)
|
|
352
|
+
break;
|
|
353
|
+
await run(pending.slice(i, i + SESSION_TITLE_BATCH_SIZE));
|
|
243
354
|
}
|
|
244
355
|
return result;
|
|
245
356
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import * as os from 'os';
|
|
2
|
+
import { findExecutable } from '../platform/exec.js';
|
|
3
|
+
import { findShadowingDefinition, shadowFixCommand } from './shadowing-alias.js';
|
|
1
4
|
const LOADED_COMMAND_NAMES = [
|
|
2
5
|
'accounts', 'auth', 'view', 'inspect', 'commands', 'hooks', 'skills', 'rules', 'memory',
|
|
3
6
|
'permissions', 'mcp', 'clis', 'subagents', 'plugins', 'workflows', 'add', 'use',
|
|
@@ -105,7 +108,21 @@ export function removedToolGroupMessage(group, rest) {
|
|
|
105
108
|
? `error: 'agents sessions --roots' was removed; use 'agents daemon index roots'.`
|
|
106
109
|
: `error: 'agents sessions --active' was removed; use 'agents ps'.`;
|
|
107
110
|
}
|
|
108
|
-
return
|
|
111
|
+
return standaloneGroupMessage(group);
|
|
112
|
+
}
|
|
113
|
+
const STANDALONE_CHECK_VERB = { browser: 'doctor' };
|
|
114
|
+
function standaloneGroupMessage(group) {
|
|
115
|
+
const binary = findExecutable(group);
|
|
116
|
+
const next = binary ? `(${binary} ${STANDALONE_CHECK_VERB[group] ?? '--help'})` : `(none is on PATH)`;
|
|
117
|
+
const shadow = findShadowingDefinition(group, os.homedir());
|
|
118
|
+
const fix = shadow
|
|
119
|
+
? `~/${shadow.file}:${shadow.line} defines it: delete that ${shadow.kind === 'alias' ? 'line' : 'function'}, then run '${shadowFixCommand(group, shadow)}'.`
|
|
120
|
+
: `If so, remove it from your shell rc file, then run 'unalias ${group}' (or 'unset -f ${group}' for a function).`;
|
|
121
|
+
return [
|
|
122
|
+
`error: 'agents ${group}' was removed; use the standalone '${group}' CLI ${next}.`,
|
|
123
|
+
`If you typed '${group}', a shell alias or function sends it here; 'type ${group}' shows it.`,
|
|
124
|
+
fix,
|
|
125
|
+
].join('\n');
|
|
109
126
|
}
|
|
110
127
|
export function isKnownTopLevelCommand(name) {
|
|
111
128
|
return KNOWN_TOP_LEVEL_COMMANDS.has(name);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ShadowingDefinition {
|
|
2
|
+
kind: 'alias' | 'function';
|
|
3
|
+
file: string;
|
|
4
|
+
line: number;
|
|
5
|
+
fish: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function findShadowingDefinition(group: string, home: string): ShadowingDefinition | undefined;
|
|
8
|
+
export declare function shadowFixCommand(group: string, def: ShadowingDefinition): string;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
const RC_FILES = [
|
|
4
|
+
'.zshrc', '.zshenv', '.zprofile', '.bashrc', '.bash_aliases', '.bash_profile', '.profile',
|
|
5
|
+
'.config/fish/config.fish',
|
|
6
|
+
];
|
|
7
|
+
const MAX_RC_BYTES = 1024 * 1024;
|
|
8
|
+
const MAX_FUNCTION_LINES = 20;
|
|
9
|
+
function escapeRegExp(value) {
|
|
10
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
11
|
+
}
|
|
12
|
+
export function findShadowingDefinition(group, home) {
|
|
13
|
+
const name = `${escapeRegExp(group)}(?![\\w-])`;
|
|
14
|
+
const callsAgents = new RegExp(`(?:^|[\\s'"/;&|({])(?:agents|ag)\\s+${name}`);
|
|
15
|
+
const alias = new RegExp(`^\\s*alias\\s+(?:-\\w+\\s+)*(?:--\\s+)?${name}(?:=|\\s+)(.*)$`);
|
|
16
|
+
const fn = new RegExp(`^\\s*(?:function\\s+${name}|${name}\\s*\\(\\s*\\))(.*)$`);
|
|
17
|
+
const comment = /^\s*#/;
|
|
18
|
+
for (const file of RC_FILES) {
|
|
19
|
+
const full = path.join(home, file);
|
|
20
|
+
let text;
|
|
21
|
+
try {
|
|
22
|
+
const stat = fs.statSync(full);
|
|
23
|
+
if (!stat.isFile() || stat.size > MAX_RC_BYTES)
|
|
24
|
+
continue;
|
|
25
|
+
text = fs.readFileSync(full, 'utf-8');
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const fish = file.endsWith('.fish');
|
|
31
|
+
const lines = text.split(/\r?\n/);
|
|
32
|
+
for (let i = 0; i < lines.length; i++) {
|
|
33
|
+
const aliasMatch = alias.exec(lines[i]);
|
|
34
|
+
if (aliasMatch && callsAgents.test(aliasMatch[1])) {
|
|
35
|
+
return { kind: 'alias', file, line: i + 1, fish };
|
|
36
|
+
}
|
|
37
|
+
const fnMatch = fn.exec(lines[i]);
|
|
38
|
+
if (!fnMatch)
|
|
39
|
+
continue;
|
|
40
|
+
const header = fnMatch[1];
|
|
41
|
+
if (callsAgents.test(header))
|
|
42
|
+
return { kind: 'function', file, line: i + 1, fish };
|
|
43
|
+
if (/\}\s*;?\s*$/.test(header))
|
|
44
|
+
continue;
|
|
45
|
+
let depth = 0;
|
|
46
|
+
const end = Math.min(lines.length, i + MAX_FUNCTION_LINES);
|
|
47
|
+
for (let j = i + 1; j < end; j++) {
|
|
48
|
+
const body = lines[j];
|
|
49
|
+
if (comment.test(body))
|
|
50
|
+
continue;
|
|
51
|
+
if (callsAgents.test(body))
|
|
52
|
+
return { kind: 'function', file, line: i + 1, fish };
|
|
53
|
+
if (fish && /^\s*(?:if|for|while|switch|begin|function)\b/.test(body))
|
|
54
|
+
depth++;
|
|
55
|
+
if (/^\s*(?:\}|end\b)/.test(body) && depth-- === 0)
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
export function shadowFixCommand(group, def) {
|
|
63
|
+
if (def.fish)
|
|
64
|
+
return `functions --erase ${group}`;
|
|
65
|
+
return def.kind === 'alias' ? `unalias ${group}` : `unset -f ${group}`;
|
|
66
|
+
}
|
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.52",
|
|
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",
|