@phnx-labs/agents-cli 1.22.122 → 1.22.123

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.
Files changed (194) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/README.md +49 -10
  3. package/dist/bootstrap.js +22 -17
  4. package/dist/cli/command-registry.d.ts +0 -1
  5. package/dist/cli/command-registry.js +2 -10
  6. package/dist/commands/auth.js +13 -4
  7. package/dist/commands/browser.js +3 -4
  8. package/dist/commands/cloud-transcripts.d.ts +7 -0
  9. package/dist/commands/cloud-transcripts.js +100 -0
  10. package/dist/commands/cloud.js +5 -0
  11. package/dist/commands/computer.d.ts +0 -12
  12. package/dist/commands/computer.js +14 -124
  13. package/dist/commands/config.js +5 -4
  14. package/dist/commands/daemon-index.d.ts +2 -0
  15. package/dist/commands/daemon-index.js +44 -0
  16. package/dist/commands/daemon.js +6 -0
  17. package/dist/commands/doctor.js +3 -4
  18. package/dist/commands/exec.d.ts +5 -0
  19. package/dist/commands/exec.js +35 -7
  20. package/dist/commands/feed-watch.js +12 -0
  21. package/dist/commands/feed.d.ts +1 -1
  22. package/dist/commands/feed.js +7 -4
  23. package/dist/commands/insights.js +3 -1
  24. package/dist/commands/inspect.js +1 -1
  25. package/dist/commands/logs.js +2 -1
  26. package/dist/commands/models.js +1 -1
  27. package/dist/commands/prune.js +6 -28
  28. package/dist/commands/ps-roster.d.ts +0 -1
  29. package/dist/commands/ps-roster.js +2 -21
  30. package/dist/commands/ps.js +13 -1
  31. package/dist/commands/recordings.d.ts +2 -0
  32. package/dist/commands/recordings.js +117 -0
  33. package/dist/commands/routines.js +1 -1
  34. package/dist/commands/secrets-passthrough.js +3 -3
  35. package/dist/commands/send.js +33 -20
  36. package/dist/commands/sessions-backfill.d.ts +1 -0
  37. package/dist/commands/sessions-backfill.js +48 -13
  38. package/dist/commands/sessions-migrate.d.ts +1 -1
  39. package/dist/commands/sessions-migrate.js +11 -10
  40. package/dist/commands/sessions-optimize.d.ts +1 -0
  41. package/dist/commands/sessions-optimize.js +7 -4
  42. package/dist/commands/sessions-resume.js +8 -1
  43. package/dist/commands/sessions-stats.d.ts +2 -0
  44. package/dist/commands/sessions-stats.js +24 -7
  45. package/dist/commands/sessions.d.ts +5 -11
  46. package/dist/commands/sessions.js +8 -236
  47. package/dist/commands/setup-computer.js +1 -2
  48. package/dist/commands/setup.js +1 -1
  49. package/dist/commands/teams.js +2 -2
  50. package/dist/commands/testdata/feed-hub.d.ts +1 -0
  51. package/dist/commands/testdata/feed-hub.js +11 -0
  52. package/dist/commands/trash.d.ts +0 -1
  53. package/dist/commands/trash.js +74 -10
  54. package/dist/lib/accounting/usage-sync.js +7 -0
  55. package/dist/lib/agent-modes.d.ts +1 -1
  56. package/dist/lib/agent-modes.js +11 -5
  57. package/dist/lib/auth-mint.d.ts +4 -0
  58. package/dist/lib/auth-mint.js +6 -4
  59. package/dist/lib/browser/native-history.test-fixture.d.ts +12 -0
  60. package/dist/lib/browser/native-history.test-fixture.js +43 -0
  61. package/dist/lib/browser/paths.d.ts +5 -0
  62. package/dist/lib/browser/paths.js +7 -1
  63. package/dist/lib/browser/sessions-list.d.ts +28 -1
  64. package/dist/lib/browser/sessions-list.js +137 -25
  65. package/dist/lib/channels/providers/rush.d.ts +2 -1
  66. package/dist/lib/channels/providers/rush.js +2 -2
  67. package/dist/lib/channels/providers/session.d.ts +1 -0
  68. package/dist/lib/channels/providers/session.js +23 -12
  69. package/dist/lib/channels/registry.d.ts +9 -2
  70. package/dist/lib/channels/send.d.ts +5 -10
  71. package/dist/lib/channels/send.js +88 -50
  72. package/dist/lib/cloud/rush.d.ts +6 -0
  73. package/dist/lib/cloud/rush.js +18 -3
  74. package/dist/lib/computer-client.d.ts +19 -0
  75. package/dist/lib/computer-client.js +104 -0
  76. package/dist/lib/config-keys.d.ts +5 -1
  77. package/dist/lib/config-keys.js +14 -11
  78. package/dist/lib/daemon/auth-sync-service.js +13 -0
  79. package/dist/lib/daemon/daemon.js +20 -8
  80. package/dist/lib/daemon/owner-device-delivery-service.d.ts +10 -0
  81. package/dist/lib/daemon/owner-device-delivery-service.js +28 -0
  82. package/dist/lib/daemon-services.d.ts +2 -1
  83. package/dist/lib/daemon-services.js +17 -5
  84. package/dist/lib/device-config.d.ts +4 -1
  85. package/dist/lib/device-config.js +57 -7
  86. package/dist/lib/devices/doctor-findings.d.ts +2 -3
  87. package/dist/lib/devices/doctor-findings.js +10 -19
  88. package/dist/lib/event-provenance.d.ts +1 -0
  89. package/dist/lib/event-provenance.js +2 -0
  90. package/dist/lib/exec.d.ts +1 -0
  91. package/dist/lib/exec.js +20 -15
  92. package/dist/lib/feed/pr-status.d.ts +5 -1
  93. package/dist/lib/feed/pr-status.js +44 -3
  94. package/dist/lib/feed/tool-activity.js +9 -6
  95. package/dist/lib/feed/tools.d.ts +4 -1
  96. package/dist/lib/feed/tools.js +8 -11
  97. package/dist/lib/feed-broadcast.d.ts +5 -3
  98. package/dist/lib/feed-broadcast.js +47 -36
  99. package/dist/lib/fleet-shared-state.d.ts +5 -0
  100. package/dist/lib/fleet-shared-state.js +8 -0
  101. package/dist/lib/github/project-prs.d.ts +4 -1
  102. package/dist/lib/github/project-prs.js +18 -5
  103. package/dist/lib/help.d.ts +1 -0
  104. package/dist/lib/help.js +8 -0
  105. package/dist/lib/helper-versions.js +1 -1
  106. package/dist/lib/hosts/passthrough.js +5 -8
  107. package/dist/lib/hosts/remote-cmd.d.ts +2 -7
  108. package/dist/lib/hosts/remote-cmd.js +14 -22
  109. package/dist/lib/hosts/routing-flag.d.ts +22 -0
  110. package/dist/lib/hosts/routing-flag.js +127 -14
  111. package/dist/lib/identity/index.d.ts +22 -0
  112. package/dist/lib/identity/index.js +3 -0
  113. package/dist/lib/installations/migrate.d.ts +7 -0
  114. package/dist/lib/installations/migrate.js +99 -88
  115. package/dist/lib/installations/versions.js +2 -2
  116. package/dist/lib/launch-identity.d.ts +6 -1
  117. package/dist/lib/launch-identity.js +12 -2
  118. package/dist/lib/menubar/install-menubar.d.ts +1 -0
  119. package/dist/lib/menubar/install-menubar.js +8 -5
  120. package/dist/lib/menubar/snapshot.js +2 -3
  121. package/dist/lib/notify.d.ts +7 -14
  122. package/dist/lib/notify.js +29 -75
  123. package/dist/lib/owner-message.d.ts +4 -6
  124. package/dist/lib/owner-message.js +12 -11
  125. package/dist/lib/owner-notify-tokens.d.ts +49 -0
  126. package/dist/lib/owner-notify-tokens.js +214 -0
  127. package/dist/lib/owner-notify.d.ts +75 -0
  128. package/dist/lib/owner-notify.js +144 -0
  129. package/dist/lib/recordings/config.d.ts +11 -0
  130. package/dist/lib/recordings/config.js +54 -0
  131. package/dist/lib/recordings/identity.d.ts +12 -0
  132. package/dist/lib/recordings/identity.js +57 -0
  133. package/dist/lib/recordings/ledger.d.ts +16 -0
  134. package/dist/lib/recordings/ledger.js +141 -0
  135. package/dist/lib/recordings/model.d.ts +29 -0
  136. package/dist/lib/recordings/model.js +28 -0
  137. package/dist/lib/recordings/pipeline.d.ts +44 -0
  138. package/dist/lib/recordings/pipeline.js +272 -0
  139. package/dist/lib/recordings/process.d.ts +17 -0
  140. package/dist/lib/recordings/process.js +94 -0
  141. package/dist/lib/recordings/service.d.ts +15 -0
  142. package/dist/lib/recordings/service.js +45 -0
  143. package/dist/lib/recordings/settle.d.ts +21 -0
  144. package/dist/lib/recordings/settle.js +92 -0
  145. package/dist/lib/recordings/transcode.d.ts +13 -0
  146. package/dist/lib/recordings/transcode.js +44 -0
  147. package/dist/lib/reminders.d.ts +0 -1
  148. package/dist/lib/reminders.js +1 -1
  149. package/dist/lib/reserved-stores.d.ts +3 -0
  150. package/dist/lib/reserved-stores.js +13 -0
  151. package/dist/lib/routine-notify-owner.d.ts +3 -23
  152. package/dist/lib/routine-notify-owner.js +26 -107
  153. package/dist/lib/rush-api.d.ts +1 -0
  154. package/dist/lib/rush-api.js +1 -0
  155. package/dist/lib/session/active.d.ts +18 -2
  156. package/dist/lib/session/active.js +47 -37
  157. package/dist/lib/session/cloud.js +18 -45
  158. package/dist/lib/session/db.d.ts +2 -0
  159. package/dist/lib/session/db.js +13 -4
  160. package/dist/lib/session/glance-files.d.ts +4 -3
  161. package/dist/lib/session/glance-files.js +31 -0
  162. package/dist/lib/session/inject-target.js +12 -2
  163. package/dist/lib/session/pid-registry.d.ts +2 -0
  164. package/dist/lib/session/pid-registry.js +6 -2
  165. package/dist/lib/session/presentation.d.ts +21 -0
  166. package/dist/lib/session/presentation.js +198 -0
  167. package/dist/lib/session/projection.js +9 -2
  168. package/dist/lib/sqlite.d.ts +3 -1
  169. package/dist/lib/sqlite.js +7 -3
  170. package/dist/lib/standalone-tools.js +1 -1
  171. package/dist/lib/startup/command-registry.js +9 -4
  172. package/dist/lib/state.d.ts +2 -2
  173. package/dist/lib/state.js +3 -5
  174. package/dist/lib/terminal/inject.js +1 -1
  175. package/dist/lib/testdata/owner-notify-api.d.ts +36 -0
  176. package/dist/lib/testdata/owner-notify-api.js +102 -0
  177. package/dist/lib/trash.d.ts +14 -0
  178. package/dist/lib/trash.js +75 -0
  179. package/dist/lib/types.d.ts +0 -34
  180. package/package.json +1 -1
  181. package/dist/commands/feedback.d.ts +0 -2
  182. package/dist/commands/feedback.js +0 -68
  183. package/dist/commands/humans.d.ts +0 -2
  184. package/dist/commands/humans.js +0 -83
  185. package/dist/commands/modes.d.ts +0 -2
  186. package/dist/commands/modes.js +0 -134
  187. package/dist/commands/reminders.d.ts +0 -2
  188. package/dist/commands/reminders.js +0 -49
  189. package/dist/lib/channels/owner-forward.d.ts +0 -25
  190. package/dist/lib/channels/owner-forward.js +0 -78
  191. package/dist/lib/channels/owner-sink.d.ts +0 -10
  192. package/dist/lib/channels/owner-sink.js +0 -26
  193. package/dist/lib/humans.d.ts +0 -12
  194. package/dist/lib/humans.js +0 -64
@@ -18,12 +18,20 @@ function parseAgent(value) {
18
18
  throw new Error(`Unknown session agent: ${name}`);
19
19
  return { agent: name, version: separator < 0 ? undefined : value.slice(separator + 1) || undefined };
20
20
  }
21
+ function assertTimeFilters(options) {
22
+ for (const [flag, value] of [['--since', options.since], ['--until', options.until]]) {
23
+ if (value !== undefined && parseTimeFilter(value) === 0) {
24
+ throw new Error(`${flag} must be a duration like 7d or an ISO date (got "${value}")`);
25
+ }
26
+ }
27
+ }
21
28
  function mergeHosts(options) {
22
29
  const values = [options.host, options.device].flatMap((value) => value === undefined ? [] : Array.isArray(value) ? value : [value]);
23
30
  return [...new Set(values)];
24
31
  }
25
32
  export async function backfillToolsLocal(options, oneBatch = false) {
26
33
  const { agent, version } = parseAgent(options.agent);
34
+ assertTimeFilters(options);
27
35
  const sessions = await discoverSessions({
28
36
  agent,
29
37
  version,
@@ -91,6 +99,8 @@ function peerArgs(options) {
91
99
  return args;
92
100
  }
93
101
  export async function runToolsBackfill(options) {
102
+ parseAgent(options.agent);
103
+ assertTimeFilters(options);
94
104
  const hosts = mergeHosts(options);
95
105
  const includeLocal = options.local === true || hosts.length === 0;
96
106
  const fanOut = options.local !== true && (options.fleet === true || hosts.length > 0);
@@ -142,6 +152,7 @@ export async function runToolsBackfill(options) {
142
152
  }
143
153
  async function runResourceBackfill(options) {
144
154
  const { agent, version } = parseAgent(options.agent);
155
+ assertTimeFilters(options);
145
156
  await discoverSessions({
146
157
  agent,
147
158
  version,
@@ -193,23 +204,39 @@ export async function runTitlesBackfill(options) {
193
204
  };
194
205
  }
195
206
  export function registerSessionsBackfillCommand(sessionsCmd) {
196
- const backfill = sessionsCmd.command('backfill').description('Populate derived session data explicitly.');
197
- const tools = backfill.command('tools').description('Parse historical tool calls once into the local SQLite index.');
207
+ registerBackfillCommand(sessionsCmd, 'agents sessions backfill');
208
+ }
209
+ export function registerBackfillCommand(parent, invocation) {
210
+ const backfill = parent.command('backfill').description('Populate derived session data explicitly.');
211
+ const tools = backfill
212
+ .command('tools')
213
+ .description('Parse historical tool calls once into the local SQLite index.')
214
+ .option('-a, --agent <agent>', 'Only this agent, optionally pinned to a version (e.g. codex, claude@2.1.45)')
215
+ .option('-p, --project <name>', 'Only sessions from this project')
216
+ .option('--since <time>', 'Only sessions newer than this (e.g. 2h, 7d, 4w, or an ISO date)')
217
+ .option('--until <time>', 'Only sessions older than this (ISO timestamp)')
218
+ .option('--unmanaged', 'Include sessions from your own ~/.<agent> installs')
219
+ .option('--team, --teams', 'Include team-spawned sessions')
220
+ .option('--local', 'Only this machine')
221
+ .option('--fleet', 'Every registered online compute device, each keeping its own index')
222
+ .option('-D, --device <target...>', 'Only these devices (repeatable); cannot be combined with --local')
223
+ .option('--json', 'Emit the machine-readable result');
198
224
  setHelpSections(tools, {
199
225
  examples: `
200
226
  # Backfill this machine once; reruns resume and skip completed transcripts
201
- agents sessions backfill tools
227
+ ${invocation} tools
202
228
 
203
229
  # Backfill every online compute device, keeping each index local
204
- agents sessions backfill tools --fleet --json
230
+ ${invocation} tools --fleet --json
205
231
 
206
232
  # Narrow the historical work
207
- agents sessions backfill tools --agent codex --since 7d
233
+ ${invocation} tools --agent codex --since 7d
208
234
  `,
209
235
  notes: `
210
236
  - This command is the only historical transcript parse for tool indexing. Tool queries never trigger it.
211
237
  - New and changed sessions are indexed during their normal incremental scan.
212
238
  - No embeddings, vector database, network model, or semantic processing is used.
239
+ - Peers are driven with \`agents sessions backfill tools --local\`, which every released CLI understands.
213
240
  `,
214
241
  });
215
242
  tools.action(async (_options, command) => {
@@ -237,21 +264,29 @@ export function registerSessionsBackfillCommand(sessionsCmd) {
237
264
  process.exitCode = 1;
238
265
  }
239
266
  });
240
- const resources = backfill.command('resources').description('Derive historical skill/slash-command usage once into the local SQLite index.');
267
+ const resources = backfill
268
+ .command('resources')
269
+ .description('Derive historical skill/slash-command usage once into the local SQLite index.')
270
+ .option('-a, --agent <agent>', 'Only this agent, optionally pinned to a version (e.g. claude, codex@0.116.0)')
271
+ .option('-p, --project <name>', 'Only sessions from this project')
272
+ .option('--since <time>', 'Only sessions newer than this (e.g. 2h, 7d, 4w, or an ISO date)')
273
+ .option('--until <time>', 'Only sessions older than this (ISO timestamp)')
274
+ .option('--team, --teams', 'Include team-spawned sessions')
275
+ .option('--json', 'Emit the machine-readable result');
241
276
  setHelpSections(resources, {
242
277
  examples: `
243
278
  # Fold every historical session on this machine into the usage index
244
- agents sessions backfill resources
279
+ ${invocation} resources
245
280
 
246
281
  # Narrow the historical work
247
- agents sessions backfill resources --agent claude --since 30d
282
+ ${invocation} resources --agent claude --since 30d
248
283
 
249
284
  # Machine-readable summary
250
- agents sessions backfill resources --json
285
+ ${invocation} resources --json
251
286
  `,
252
287
  notes: `
253
288
  - Populates session_resource_usage for sessions indexed before the usage signal shipped. New/changed sessions are recorded on their normal scan; this is the one-shot catch-up read by \`agents sessions stats\`.
254
- - Local-only: the signal is derived per machine from its own transcripts. Run it on each box (or over \`agents ssh <host> agents sessions backfill resources\`).
289
+ - Local-only: the signal is derived per machine from its own transcripts. Run it on each box (or over \`agents ssh <host> ${invocation} resources\`).
255
290
  - Reruns skip transcripts already current (resource_scan_ledger); bump the extractor version to force a full re-derive.
256
291
  - Only slash commands and \`Skill\` tool calls are recorded — auto-triggered skills emit no signal.
257
292
  `,
@@ -286,13 +321,13 @@ export function registerSessionsBackfillCommand(sessionsCmd) {
286
321
  setHelpSections(titles, {
287
322
  examples: `
288
323
  # Catch this machine up now (the daemon otherwise does a couple every 2 min)
289
- agents sessions backfill titles
324
+ ${invocation} titles
290
325
 
291
326
  # Re-title one session after correcting its first message
292
- agents sessions backfill titles --session 6fc1db18 --refresh
327
+ ${invocation} titles --session 6fc1db18 --refresh
293
328
 
294
329
  # Machine-readable
295
- agents sessions backfill titles --limit 20 --json
330
+ ${invocation} titles --limit 20 --json
296
331
  `,
297
332
  notes: `
298
333
  - The headline ladder is: \`/rename\` label > this generated title > the user's first message. It is never the agent's latest turn.
@@ -17,5 +17,5 @@ export declare function buildMigrateResumeCommands(opts: {
17
17
  socketFlag: string;
18
18
  };
19
19
  export declare function rehydrateCommand(source: SessionMeta): string[];
20
- export declare function registerSessionsMigrationsCommand(sessionsCmd: Command): void;
20
+ export declare function registerSessionsMigrationsCommand(sessionsCmd: Command, group?: 'sessions' | 'ps'): void;
21
21
  export {};
@@ -58,11 +58,11 @@ export function registerSessionsMigrateCommand(sessionsCmd, group = 'sessions')
58
58
  - --mode resume attempts a native '<agent> --resume' on the target — faithful, but best-effort:
59
59
  the target agent must have the session registered, so migrate falls back to rehydrate when it can't.
60
60
  - The source is stopped only AFTER the target's session is confirmed live; --keep skips the stop (copy).
61
- - Every migrate appends to the ledger — see 'agents sessions migrations' for where each session went.
61
+ - Every migrate appends to the ledger — see 'agents ${group} migrations' for where each session went.
62
62
  `,
63
63
  });
64
64
  cmd.action(async (sessionId, options) => {
65
- await sessionsMigrateAction(sessionId, options);
65
+ await sessionsMigrateAction(sessionId, options, group);
66
66
  });
67
67
  }
68
68
  function fail(message) {
@@ -375,7 +375,7 @@ export function rehydrateCommand(source) {
375
375
  ].join(' ');
376
376
  return [cli, prompt];
377
377
  }
378
- async function sessionsMigrateAction(sessionId, options) {
378
+ async function sessionsMigrateAction(sessionId, options, group) {
379
379
  if (options.mode && options.mode !== 'resume' && options.mode !== 'rehydrate') {
380
380
  fail(`--mode must be 'resume' or 'rehydrate' (got "${options.mode}").`);
381
381
  }
@@ -411,7 +411,7 @@ async function sessionsMigrateAction(sessionId, options) {
411
411
  }
412
412
  recordMigration({ ...base, status: 'completed' });
413
413
  console.log(chalk.green(`\nMigrated ${source.shortId} to ${target.name}${options.keep ? ' (copy)' : ''}.`) +
414
- chalk.gray(" Tracked in 'agents sessions migrations'."));
414
+ chalk.gray(` Tracked in 'agents ${group} migrations'.`));
415
415
  }
416
416
  async function stopSource(source, active) {
417
417
  const mux = active?.provenance?.mux;
@@ -432,22 +432,23 @@ async function stopSource(source, active) {
432
432
  else
433
433
  console.log(chalk.yellow(` Source tmux session ${name} was already gone.`));
434
434
  }
435
- export function registerSessionsMigrationsCommand(sessionsCmd) {
436
- sessionsCmd
435
+ export function registerSessionsMigrationsCommand(sessionsCmd, group = 'sessions') {
436
+ const cmd = sessionsCmd
437
437
  .command('migrations')
438
438
  .description('Show the migration ledger — sessions handed off to/from other machines.')
439
439
  .option('--json', 'Output the raw ledger as JSON')
440
- .option('--session <id>', 'Only rows whose session id starts with this fragment')
441
- .action((options) => {
440
+ .option('--session <id>', 'Only rows whose session id starts with this fragment');
441
+ cmd.action((options) => {
442
+ const json = cmd.optsWithGlobals().json === true;
442
443
  let recs = readMigrations();
443
444
  if (options.session)
444
445
  recs = recs.filter((r) => r.sessionId.startsWith(options.session) || r.shortId.startsWith(options.session));
445
- if (options.json) {
446
+ if (json) {
446
447
  console.log(JSON.stringify(recs, null, 2));
447
448
  return;
448
449
  }
449
450
  if (recs.length === 0) {
450
- console.log(chalk.gray('No migrations recorded yet. Move one: agents sessions migrate --auto'));
451
+ console.log(chalk.gray(`No migrations recorded yet. Move one: agents ${group} migrate --auto`));
451
452
  return;
452
453
  }
453
454
  recs.reverse();
@@ -1,2 +1,3 @@
1
1
  import type { Command } from 'commander';
2
2
  export declare function registerSessionsOptimizeCommand(sessionsCmd: Command): void;
3
+ export declare function registerOptimizeCommand(parent: Command, invocation: string): void;
@@ -2,7 +2,10 @@ import chalk from 'chalk';
2
2
  import { optimizeSessionSearchIndex } from '../lib/session/db.js';
3
3
  import { setHelpSections } from '../lib/help.js';
4
4
  export function registerSessionsOptimizeCommand(sessionsCmd) {
5
- const cmd = sessionsCmd
5
+ registerOptimizeCommand(sessionsCmd, 'agents sessions optimize');
6
+ }
7
+ export function registerOptimizeCommand(parent, invocation) {
8
+ const cmd = parent
6
9
  .command('optimize')
7
10
  .description('Compact the session search index (FTS5), reclaiming bloat from repeated re-indexing')
8
11
  .option('--json', 'Emit machine-readable JSON')
@@ -23,14 +26,14 @@ export function registerSessionsOptimizeCommand(sessionsCmd) {
23
26
  setHelpSections(cmd, {
24
27
  examples: `
25
28
  # Compact the session/tool search index once it has grown fragmented
26
- agents sessions optimize
29
+ ${invocation}
27
30
 
28
31
  # Machine-readable segment counts
29
- agents sessions optimize --json
32
+ ${invocation} --json
30
33
 
31
34
  # Wire it to a weekly routine so the index never re-bloats
32
35
  agents routines add sessions-optimize --schedule "0 4 * * 0" --agent claude \\
33
- --prompt "Run: agents sessions optimize"
36
+ --prompt "Run: ${invocation}"
34
37
  `,
35
38
  notes: `
36
39
  - FTS5 appends a segment on every insert and tombstones every delete; the scanner delete+inserts a session's docs on each rescan and never self-merges, so \`tool_call_text_data\` / \`session_text_data\` bloat with unmerged segments — GBs of index for tens of MB of content, and queries slow down.
@@ -20,6 +20,7 @@ import { buildResumeRemoteArgs, runStrictResume, wantsStrictResume } from './res
20
20
  import { toRemotePortable } from '../lib/project-root.js';
21
21
  import { attachLocalLiveSelector } from '../lib/session/local-tmux-attach.js';
22
22
  import { sessionHeadline } from '../lib/session/title.js';
23
+ import { stripRoutingFlags } from '../lib/hosts/remote-cmd.js';
23
24
  export const CONFIRM_THRESHOLD = 5;
24
25
  export function registerSessionsResumeCommand(sessionsCmd) {
25
26
  const cmd = sessionsCmd
@@ -290,9 +291,15 @@ export async function sessionsResumeAction(query, prompt, options) {
290
291
  if (opened !== items.length)
291
292
  process.exitCode = 1;
292
293
  }
294
+ const RUN_RESUME_PICKER_SPECS = [
295
+ { long: 'all', takesValue: false },
296
+ { long: 'teams', takesValue: false },
297
+ { long: 'since', takesValue: true },
298
+ { long: 'limit', short: 'n', takesValue: true },
299
+ ];
293
300
  export function buildSelectedResumeArgs(id, prompt, options) {
294
301
  if (options.runArgs) {
295
- const args = [...options.runArgs];
302
+ const args = stripRoutingFlags(options.runArgs, RUN_RESUME_PICKER_SPECS);
296
303
  const boundary = args.indexOf('--');
297
304
  const index = args.findIndex((arg, i) => (boundary < 0 || i < boundary) && (arg === '--resume' || arg === '--resume='));
298
305
  if (index < 0)
@@ -10,4 +10,6 @@ export declare function diffZeroInvoked(installed: InstalledResource[], invoked:
10
10
  name: string;
11
11
  }>): InstalledResource[];
12
12
  export declare function registerSessionsStatsCommand(sessionsCmd: Command): void;
13
+ export declare function registerInsightsResourcesCommand(insightsCmd: Command): void;
14
+ export declare function resolveStatsAgent(values: unknown[]): string | undefined;
13
15
  export {};
@@ -38,8 +38,13 @@ function installedResources(kindFilter, pluginFilter, cwd) {
38
38
  return [...byKey.values()];
39
39
  }
40
40
  export function registerSessionsStatsCommand(sessionsCmd) {
41
- const stats = sessionsCmd
42
- .command('stats')
41
+ configureStatsCommand(sessionsCmd.command('stats'), 'agents sessions stats');
42
+ }
43
+ export function registerInsightsResourcesCommand(insightsCmd) {
44
+ configureStatsCommand(insightsCmd.command('resources'), 'agents insights resources');
45
+ }
46
+ function configureStatsCommand(stats, spelling) {
47
+ stats
43
48
  .description('Which skills/commands you actually invoke, and which installed ones are dead weight.')
44
49
  .option('--kind <kind>', 'Limit to one kind: skill or command')
45
50
  .option('--plugin <name>', "Only this plugin's resources (r.plugin), not every resource a plugin-touching session used")
@@ -57,16 +62,16 @@ export function registerSessionsStatsCommand(sessionsCmd) {
57
62
  setHelpSections(stats, {
58
63
  examples: `
59
64
  # Most-invoked skills and commands, plus the installed ones you never invoke
60
- agents sessions stats
65
+ ${spelling}
61
66
 
62
67
  # Just the dead weight — installed but never explicitly invoked
63
- agents sessions stats --zero
68
+ ${spelling} --zero
64
69
 
65
70
  # Skills only, last 30 days, machine-readable
66
- agents sessions stats --kind skill --since 30d --json
71
+ ${spelling} --kind skill --since 30d --json
67
72
 
68
73
  # One plugin's resources, least-used first
69
- agents sessions stats --plugin rush --bottom
74
+ ${spelling} --plugin rush --bottom
70
75
 
71
76
  # Backfill historical sessions first if coverage is low
72
77
  agents sessions backfill resources
@@ -76,11 +81,23 @@ export function registerSessionsStatsCommand(sessionsCmd) {
76
81
  - Skill invocations are recorded for Claude and Kimi; slash-commands for Claude only. Other harnesses contribute nothing to these counts.
77
82
  - Counts come from the SQLite index. New/changed sessions are recorded on their normal scan; run \`agents sessions backfill resources\` once to fold in historical sessions (a low coverage line means it hasn't run).
78
83
  - --plugin filters the resource rows (this plugin's skills/commands), distinct from the top-level \`agents sessions --plugin\` which filters SESSIONS.
84
+ - The window is all time unless --since narrows it. \`agents insights resources\` and \`agents sessions stats\` are the same report; --json keeps \`kind: "sessions-stats"\` under either spelling.
79
85
  `,
80
86
  });
81
87
  }
88
+ export function resolveStatsAgent(values) {
89
+ const agents = [...new Set(values.flatMap(v => (Array.isArray(v) ? v : v === undefined ? [] : [v])).map(String))];
90
+ if (agents.length > 1) {
91
+ console.error(chalk.red(`error: resource usage filters on one --agent; got ${agents.join(', ')}`));
92
+ process.exit(1);
93
+ }
94
+ return agents[0];
95
+ }
82
96
  async function statsAction(cmd) {
83
- const opts = cmd.optsWithGlobals();
97
+ const agentValues = [];
98
+ for (let c = cmd; c; c = c.parent)
99
+ agentValues.push(c.opts().agent);
100
+ const opts = { ...cmd.optsWithGlobals(), agent: resolveStatsAgent(agentValues) };
84
101
  const kind = normalizeKind(opts.kind);
85
102
  const sinceMs = opts.since ? parseTimeFilter(opts.since) : undefined;
86
103
  const top = resolveTop(opts.top);
@@ -1,6 +1,6 @@
1
1
  import { type Command } from 'commander';
2
2
  import { type ProjectDef } from '../lib/projects.js';
3
- import type { SessionAgentId, SessionEvent, SessionMeta, ViewMode } from '@phnx-labs/sessions-cli/reader';
3
+ import type { SessionAgentId, SessionEvent, SessionMeta } from '@phnx-labs/sessions-cli/reader';
4
4
  import { type ActiveSession } from '../lib/session/active.js';
5
5
  export { activeSessionProjectKey, backfillActiveRowsFromIndex, backfillActiveRowsFromMeta, isRunningLiveSession, serializeActiveSessionsForJson, serializeSessionsJson, type BackfillMeta } from '../lib/session/active.js';
6
6
  import { loadLocalActiveSessions } from '../lib/session/session-cache.js';
@@ -8,6 +8,8 @@ import { gatherRemoteList, runOnPeer } from '../lib/session/remote-list.js';
8
8
  import { type RemoteAgentsJsonParseResult } from '../lib/remote-agents-json.js';
9
9
  import { type RunMeta } from '../lib/scheduling/routines.js';
10
10
  import { type PickedSession, type SessionPreviewDigest } from './sessions-picker.js';
11
+ import { type TranscriptRenderOptions } from '../lib/session/presentation.js';
12
+ export { buildFilterOptions, renderSession, renderSessionLog, renderSessionLogJson, resolveViewMode, type TranscriptRenderOptions, } from '../lib/session/presentation.js';
11
13
  import { type ComputerRunRow } from '../lib/computer/sessions-list.js';
12
14
  import { type ToolSearchEnvelope, type ToolProgramCountEnvelope } from '../lib/session/tool-index.js';
13
15
  interface SessionFilterOptions {
@@ -22,7 +24,7 @@ interface SessionFilterOptions {
22
24
  since?: string;
23
25
  until?: string;
24
26
  }
25
- interface SessionsOptions extends SessionFilterOptions {
27
+ interface SessionsOptions extends SessionFilterOptions, TranscriptRenderOptions {
26
28
  unmanaged?: boolean;
27
29
  query?: string[];
28
30
  resolve?: string;
@@ -30,13 +32,6 @@ interface SessionsOptions extends SessionFilterOptions {
30
32
  resolveLaunchId?: string;
31
33
  limit?: string;
32
34
  sort?: string;
33
- json?: boolean;
34
- markdown?: boolean;
35
- redact?: boolean;
36
- include?: string;
37
- exclude?: string;
38
- first?: string;
39
- last?: string;
40
35
  artifacts?: boolean;
41
36
  artifact?: string;
42
37
  active?: boolean;
@@ -180,8 +175,7 @@ export declare function buildOverviewGroups(pool: SessionMeta[], perProjectCap:
180
175
  groups: OverviewGroup[];
181
176
  projectCount: number;
182
177
  };
183
- export declare function renderSessionLog(session: SessionMeta, mode?: ViewMode): Promise<void>;
184
- export declare function renderSessionLogJson(session: SessionMeta): Promise<void>;
178
+ export declare function printSessionTable(sessions: SessionMeta[], hiddenCount?: number, tree?: boolean, liveIndex?: Map<string, ActiveSession>): void;
185
179
  export interface SshOriginTag {
186
180
  device?: string;
187
181
  }