@phnx-labs/agents-cli 1.23.17 → 1.23.19

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 (251) hide show
  1. package/CHANGELOG.md +239 -0
  2. package/README.md +140 -165
  3. package/dist/bootstrap.js +11 -17
  4. package/dist/cli/command-registry.d.ts +1 -2
  5. package/dist/cli/command-registry.js +1 -10
  6. package/dist/commands/accounts.js +7 -7
  7. package/dist/commands/cloud-transcripts.d.ts +0 -1
  8. package/dist/commands/cloud-transcripts.js +2 -2
  9. package/dist/commands/cloud.js +2 -2
  10. package/dist/commands/config.js +1 -5
  11. package/dist/commands/cost.js +1 -1
  12. package/dist/commands/daemon-index.js +0 -1
  13. package/dist/commands/detach.d.ts +1 -1
  14. package/dist/commands/detach.js +10 -6
  15. package/dist/commands/doctor.js +11 -7
  16. package/dist/commands/exec.d.ts +0 -17
  17. package/dist/commands/exec.js +26 -72
  18. package/dist/commands/feed.d.ts +1 -1
  19. package/dist/commands/feed.js +3 -3
  20. package/dist/commands/focus.d.ts +11 -6
  21. package/dist/commands/focus.js +91 -31
  22. package/dist/commands/fork.d.ts +0 -1
  23. package/dist/commands/fork.js +7 -16
  24. package/dist/commands/harness-wizard.js +1 -1
  25. package/dist/commands/harness.js +1 -1
  26. package/dist/commands/insights.d.ts +0 -1
  27. package/dist/commands/insights.js +3 -7
  28. package/dist/commands/open.js +1 -1
  29. package/dist/commands/output.js +1 -1
  30. package/dist/commands/profiles.d.ts +1 -1
  31. package/dist/commands/profiles.js +2 -2
  32. package/dist/commands/projects-todo.js +10 -5
  33. package/dist/commands/projects.js +1 -1
  34. package/dist/commands/prune.js +1 -1
  35. package/dist/commands/ps.d.ts +8 -3
  36. package/dist/commands/ps.js +238 -110
  37. package/dist/commands/routines.js +1 -1
  38. package/dist/commands/send.js +1 -1
  39. package/dist/commands/sessions-backfill.d.ts +0 -1
  40. package/dist/commands/sessions-backfill.js +3 -6
  41. package/dist/commands/sessions-browser.d.ts +0 -10
  42. package/dist/commands/sessions-browser.js +19 -25
  43. package/dist/commands/sessions-migrate.d.ts +2 -2
  44. package/dist/commands/sessions-migrate.js +13 -13
  45. package/dist/commands/sessions-optimize.d.ts +0 -1
  46. package/dist/commands/sessions-optimize.js +0 -3
  47. package/dist/commands/sessions-picker.d.ts +0 -7
  48. package/dist/commands/sessions-picker.js +16 -310
  49. package/dist/commands/sessions-resume.d.ts +16 -15
  50. package/dist/commands/sessions-resume.js +101 -269
  51. package/dist/commands/sessions-stats.d.ts +0 -1
  52. package/dist/commands/sessions-stats.js +5 -8
  53. package/dist/commands/sessions-stop.d.ts +1 -1
  54. package/dist/commands/sessions-stop.js +8 -8
  55. package/dist/commands/sessions-trace.d.ts +1 -1
  56. package/dist/commands/sessions-trace.js +40 -17
  57. package/dist/commands/sessions-watch.js +2 -2
  58. package/dist/commands/sessions.test-fixture.d.ts +1 -0
  59. package/dist/commands/sessions.test-fixture.js +14 -0
  60. package/dist/commands/setup-browser.js +4 -4
  61. package/dist/commands/setup-computer.js +4 -4
  62. package/dist/commands/setup-fleet.js +1 -1
  63. package/dist/commands/setup-preferences.js +1 -1
  64. package/dist/commands/{sessions-backup-setup.d.ts → setup-session-backup.d.ts} +2 -2
  65. package/dist/commands/{sessions-backup-setup.js → setup-session-backup.js} +8 -8
  66. package/dist/commands/setup.js +3 -1
  67. package/dist/commands/ssh.js +4 -5
  68. package/dist/commands/sync.js +1 -1
  69. package/dist/commands/teams.js +2 -2
  70. package/dist/commands/utils.d.ts +0 -1
  71. package/dist/commands/utils.js +0 -10
  72. package/dist/index.js +0 -71
  73. package/dist/lib/account-registry.d.ts +3 -0
  74. package/dist/lib/account-registry.js +40 -0
  75. package/dist/lib/accounting/usage-sync.d.ts +1 -0
  76. package/dist/lib/accounting/usage-sync.js +20 -3
  77. package/dist/lib/accounting/usage.d.ts +4 -1
  78. package/dist/lib/accounting/usage.js +38 -6
  79. package/dist/lib/agent-spec/agents.js +12 -11
  80. package/dist/lib/analytics/mix-commands.js +1 -1
  81. package/dist/lib/auth-mint.js +2 -2
  82. package/dist/lib/browser-client.d.ts +0 -1
  83. package/dist/lib/browser-client.js +0 -3
  84. package/dist/lib/cloud/antigravity.js +1 -1
  85. package/dist/lib/cloud/cursor.js +3 -3
  86. package/dist/lib/cloud/store.d.ts +5 -1
  87. package/dist/lib/cloud/store.js +10 -3
  88. package/dist/lib/cloudflare/creds.js +2 -2
  89. package/dist/lib/computer/context.d.ts +4 -21
  90. package/dist/lib/computer/context.js +3 -24
  91. package/dist/lib/computer/policy.d.ts +0 -10
  92. package/dist/lib/computer/policy.js +0 -28
  93. package/dist/lib/computer-client.d.ts +0 -44
  94. package/dist/lib/computer-client.js +17 -121
  95. package/dist/lib/config-keys.d.ts +2 -2
  96. package/dist/lib/config-keys.js +1 -3
  97. package/dist/lib/crabbox/cli.js +1 -1
  98. package/dist/lib/daemon/account-state-daemon-service.js +9 -2
  99. package/dist/lib/daemon/self-update-service.js +1 -1
  100. package/dist/lib/device-config.d.ts +2 -1
  101. package/dist/lib/device-config.js +26 -39
  102. package/dist/lib/devices/connect.d.ts +1 -1
  103. package/dist/lib/devices/connect.js +3 -6
  104. package/dist/lib/devices/doctor-findings.d.ts +2 -1
  105. package/dist/lib/devices/doctor-findings.js +4 -4
  106. package/dist/lib/devices/health.d.ts +6 -0
  107. package/dist/lib/devices/health.js +11 -4
  108. package/dist/lib/exec.js +1 -1
  109. package/dist/lib/feed/activity.js +1 -1
  110. package/dist/lib/feed/watch.js +2 -1
  111. package/dist/lib/fleet/apply.d.ts +1 -1
  112. package/dist/lib/fleet/apply.js +6 -3
  113. package/dist/lib/fleet-shared-state.d.ts +2 -0
  114. package/dist/lib/fleet-shared-state.js +3 -1
  115. package/dist/lib/github/project-prs.js +14 -1
  116. package/dist/lib/help.d.ts +0 -1
  117. package/dist/lib/help.js +2 -10
  118. package/dist/lib/helper-versions.js +1 -1
  119. package/dist/lib/hosts/option.js +1 -1
  120. package/dist/lib/hosts/passthrough.d.ts +0 -1
  121. package/dist/lib/hosts/passthrough.js +2 -26
  122. package/dist/lib/hosts/reconnect.js +5 -5
  123. package/dist/lib/hosts/remote-cmd.d.ts +3 -5
  124. package/dist/lib/hosts/remote-cmd.js +15 -20
  125. package/dist/lib/hosts/remote-session-id.js +1 -1
  126. package/dist/lib/installations/active-check.js +1 -1
  127. package/dist/lib/installations/migrate.js +4 -15
  128. package/dist/lib/installations/versions.js +5 -4
  129. package/dist/lib/launch-log.js +3 -6
  130. package/dist/lib/owner-notify.d.ts +1 -6
  131. package/dist/lib/owner-notify.js +0 -2
  132. package/dist/lib/paths.d.ts +0 -1
  133. package/dist/lib/paths.js +0 -8
  134. package/dist/lib/permissions.js +1 -1
  135. package/dist/lib/project-root.d.ts +1 -0
  136. package/dist/lib/project-root.js +11 -3
  137. package/dist/lib/projects.js +2 -2
  138. package/dist/lib/quick-todo.d.ts +5 -1
  139. package/dist/lib/quick-todo.js +14 -1
  140. package/dist/lib/redact.d.ts +0 -1
  141. package/dist/lib/redact.js +0 -4
  142. package/dist/lib/remote-agents-json.d.ts +3 -1
  143. package/dist/lib/remote-agents-json.js +12 -8
  144. package/dist/lib/reserved-stores.js +1 -1
  145. package/dist/lib/scheduling/routines.d.ts +0 -1
  146. package/dist/lib/scheduling/routines.js +1 -1
  147. package/dist/lib/self-update.d.ts +1 -1
  148. package/dist/lib/self-update.js +59 -2
  149. package/dist/lib/session/active.d.ts +1 -1
  150. package/dist/lib/session/db.js +4 -4
  151. package/dist/lib/session/detached.d.ts +0 -1
  152. package/dist/lib/session/detached.js +0 -23
  153. package/dist/lib/session/discover.d.ts +2 -2
  154. package/dist/lib/session/glance-files.d.ts +21 -0
  155. package/dist/lib/session/glance-files.js +123 -0
  156. package/dist/lib/session/presentation.d.ts +3 -7
  157. package/dist/lib/session/presentation.js +4 -4
  158. package/dist/lib/session/preview-digest.d.ts +13 -0
  159. package/dist/lib/session/preview-digest.js +328 -0
  160. package/dist/lib/session/projection.js +1 -1
  161. package/dist/lib/session/remote/remote-list.d.ts +5 -2
  162. package/dist/lib/session/remote/remote-list.js +15 -8
  163. package/dist/lib/session/remote/watch.d.ts +2 -0
  164. package/dist/lib/session/remote/watch.js +90 -10
  165. package/dist/lib/session/remote-active.js +1 -1
  166. package/dist/lib/session/resume-command.d.ts +0 -1
  167. package/dist/lib/session/resume-command.js +1 -4
  168. package/dist/lib/session/resume-owner.d.ts +0 -2
  169. package/dist/lib/session/resume-owner.js +0 -6
  170. package/dist/lib/session/selection.d.ts +4 -5
  171. package/dist/lib/session/selection.js +2 -2
  172. package/dist/lib/session/sync/config.d.ts +0 -25
  173. package/dist/lib/session/sync/config.js +0 -62
  174. package/dist/lib/session/sync/managed-config.d.ts +0 -1
  175. package/dist/lib/session/sync/managed-config.js +0 -3
  176. package/dist/lib/session/sync/worker-template.js +1 -1
  177. package/dist/lib/sessions-client.d.ts +0 -16
  178. package/dist/lib/sessions-client.js +1 -187
  179. package/dist/lib/smart-launch.js +6 -1
  180. package/dist/lib/startup/command-registry.d.ts +2 -0
  181. package/dist/lib/startup/command-registry.js +36 -3
  182. package/dist/lib/startup/root-command.d.ts +0 -1
  183. package/dist/lib/startup/root-command.js +0 -21
  184. package/dist/lib/sync-umbrella.js +1 -1
  185. package/dist/lib/teams/placement-probe.d.ts +2 -0
  186. package/dist/lib/teams/placement-probe.js +8 -3
  187. package/dist/lib/terminal/engine.d.ts +2 -0
  188. package/dist/lib/terminal/engine.js +5 -3
  189. package/dist/lib/terminal/index.d.ts +1 -1
  190. package/dist/lib/terminal/index.js +1 -1
  191. package/dist/lib/terminal/resolve.js +1 -1
  192. package/dist/lib/terminal/run-surface.d.ts +1 -0
  193. package/dist/lib/terminal/run-surface.js +9 -0
  194. package/dist/lib/watchdog/rotate.js +1 -1
  195. package/dist/lib/watchdog/watchdog.d.ts +1 -1
  196. package/dist/lib/watchdog/watchdog.js +2 -2
  197. package/package.json +1 -1
  198. package/dist/commands/browser.d.ts +0 -7
  199. package/dist/commands/browser.js +0 -139
  200. package/dist/commands/computer.d.ts +0 -48
  201. package/dist/commands/computer.js +0 -244
  202. package/dist/commands/resume.d.ts +0 -23
  203. package/dist/commands/resume.js +0 -158
  204. package/dist/commands/secrets-passthrough.d.ts +0 -3
  205. package/dist/commands/secrets-passthrough.js +0 -52
  206. package/dist/commands/sessions-bookmark.d.ts +0 -2
  207. package/dist/commands/sessions-bookmark.js +0 -92
  208. package/dist/commands/sessions-export.d.ts +0 -31
  209. package/dist/commands/sessions-export.js +0 -409
  210. package/dist/commands/sessions-import.d.ts +0 -6
  211. package/dist/commands/sessions-import.js +0 -343
  212. package/dist/commands/sessions-inject.d.ts +0 -14
  213. package/dist/commands/sessions-inject.js +0 -143
  214. package/dist/commands/sessions-picker-factory.d.ts +0 -24
  215. package/dist/commands/sessions-picker-factory.js +0 -59
  216. package/dist/commands/sessions-render.d.ts +0 -11
  217. package/dist/commands/sessions-render.js +0 -119
  218. package/dist/commands/sessions-share.d.ts +0 -15
  219. package/dist/commands/sessions-share.js +0 -171
  220. package/dist/commands/sessions.d.ts +0 -122
  221. package/dist/commands/sessions.js +0 -1760
  222. package/dist/lib/address.d.ts +0 -39
  223. package/dist/lib/address.js +0 -128
  224. package/dist/lib/computer/record.d.ts +0 -6
  225. package/dist/lib/computer/record.js +0 -25
  226. package/dist/lib/onepassword.d.ts +0 -57
  227. package/dist/lib/onepassword.js +0 -140
  228. package/dist/lib/openclaw-keychain.d.ts +0 -43
  229. package/dist/lib/openclaw-keychain.js +0 -227
  230. package/dist/lib/session/bundle.d.ts +0 -76
  231. package/dist/lib/session/bundle.js +0 -146
  232. package/dist/lib/session/remote/remote-bundle.d.ts +0 -7
  233. package/dist/lib/session/remote/remote-bundle.js +0 -40
  234. package/dist/lib/session/remote/remote.d.ts +0 -35
  235. package/dist/lib/session/remote/remote.js +0 -198
  236. package/dist/lib/session/remote-bundle.d.ts +0 -1
  237. package/dist/lib/session/remote-bundle.js +0 -1
  238. package/dist/lib/session/remote.d.ts +0 -1
  239. package/dist/lib/session/remote.js +0 -1
  240. package/dist/lib/session/sync/agents.d.ts +0 -24
  241. package/dist/lib/session/sync/agents.js +0 -0
  242. package/dist/lib/session/sync/backend.d.ts +0 -22
  243. package/dist/lib/session/sync/backend.js +0 -44
  244. package/dist/lib/session/sync/managed-key.d.ts +0 -5
  245. package/dist/lib/session/sync/managed-key.js +0 -87
  246. package/dist/lib/session/sync/net-client.d.ts +0 -29
  247. package/dist/lib/session/sync/net-client.js +0 -87
  248. package/dist/lib/session/sync/r2.d.ts +0 -20
  249. package/dist/lib/session/sync/r2.js +0 -103
  250. package/dist/lib/session/sync/transcript-crypto.d.ts +0 -41
  251. package/dist/lib/session/sync/transcript-crypto.js +0 -115
@@ -14,8 +14,34 @@ import { diffTrajectories } from '@phnx-labs/sessions-cli/reader';
14
14
  import { buildLineage } from '@phnx-labs/sessions-cli/reader';
15
15
  import { renderTrajectoryHtml, renderTrajectoryCompareHtml, renderLineageHtml } from '@phnx-labs/sessions-cli/reader';
16
16
  import { renderTrajectoryText, renderTrajectoryCompareText, renderLineageText } from '@phnx-labs/sessions-cli/reader';
17
- import { parseAgentFilter } from '../lib/session/selection.js';
18
- import { selectSessions } from './sessions-export.js';
17
+ import { filterSessionsByQuery, parseAgentFilter } from '../lib/session/selection.js';
18
+ import { looksLikeSessionId, resolveSessionById } from '../lib/session/discover.js';
19
+ import { findSessionsById } from '../lib/session/db.js';
20
+ export function selectSessions(metas, selectors) {
21
+ if (selectors.length === 0)
22
+ return metas;
23
+ const byId = [];
24
+ const unmatched = [];
25
+ for (const sel of selectors) {
26
+ const trimmed = sel.trim();
27
+ const hits = resolveSessionById(metas, trimmed);
28
+ const resolved = hits.length > 0 || !looksLikeSessionId(trimmed) ? hits : findSessionsById(trimmed);
29
+ if (resolved.length > 0)
30
+ byId.push(...resolved);
31
+ else
32
+ unmatched.push(trimmed);
33
+ }
34
+ if (byId.length > 0 && unmatched.length === 0) {
35
+ const seen = new Set();
36
+ return byId.filter(s => (seen.has(s.id) ? false : (seen.add(s.id), true)));
37
+ }
38
+ const missingIds = unmatched.filter(looksLikeSessionId);
39
+ if (missingIds.length > 0) {
40
+ process.stderr.write(chalk.red(`No session with id ${missingIds.join(', ')} on this machine.\n`));
41
+ return [];
42
+ }
43
+ return filterSessionsByQuery(metas, selectors.join(' '));
44
+ }
19
45
  export const SESSIONS_TRACE_SCHEMA_VERSION = 1;
20
46
  export function buildTraceEnvelope(models) {
21
47
  return {
@@ -159,37 +185,37 @@ function configureTraceCommand(cmd) {
159
185
  .option('-a, --agent <agent>', 'Filter by agent type (e.g. claude, codex)');
160
186
  setHelpSections(cmd, {
161
187
  examples: `# Open one session's trajectory in a browser (a person at a terminal)
162
- agents sessions trace a1b2c3d4
188
+ agents trace a1b2c3d4
163
189
 
164
- # The compact text trajectory an agent reads in-context
165
- agents sessions trace a1b2c3d4 --text
190
+ # The compact text trajectory an agent reads in-context (standalone sessions CLI)
191
+ sessions trace a1b2c3d4
166
192
 
167
193
  # Just the failures and their neighbours — for a triaging agent
168
- agents sessions trace a1b2c3d4 --text --errors-only
194
+ sessions trace a1b2c3d4 --errors-only
169
195
 
170
196
  # What the agent said it was doing, step by step — the sidebar's timeline as text
171
- agents sessions trace a1b2c3d4 --steps
197
+ agents trace a1b2c3d4 --steps
172
198
 
173
199
  # The stable JSON envelope for the AGI EXT Fleet panel or a tool
174
- agents sessions trace a1b2c3d4 --json
200
+ agents trace a1b2c3d4 --json
175
201
 
176
202
  # Write the self-contained HTML to a file without opening it
177
- agents sessions trace a1b2c3d4 --html -o trace.html --no-open
203
+ agents trace a1b2c3d4 --html -o trace.html --no-open
178
204
 
179
205
  # Two selectors — compare where a passing run and a failing one diverge
180
- agents sessions trace a1b2c3d4 e5f6a7b8
206
+ agents trace a1b2c3d4 e5f6a7b8
181
207
 
182
208
  # The compare, as text — for a triaging agent comparing harnesses
183
- agents sessions trace a1b2c3d4 e5f6a7b8 --text
209
+ agents trace a1b2c3d4 e5f6a7b8 --text
184
210
 
185
211
  # The team an orchestrator spawned, as a graph (one selector + --tree)
186
- agents sessions trace a1b2c3d4 --tree
212
+ agents trace a1b2c3d4 --tree
187
213
 
188
214
  # The same lineage as an indented tree an agent can read
189
- agents sessions trace a1b2c3d4 --tree --text`,
215
+ agents trace a1b2c3d4 --tree --text`,
190
216
  notes: `Audience auto-select: with no --html/--text/--json, HTML opens on a TTY (a person) and
191
217
  the compact text trajectory prints when piped or headless (an agent). The HTML is self-contained
192
- (no CDN, no external asset) and redacted by default, as safe to share as an 'agents sessions share' page.
218
+ (no CDN, no external asset) and redacted by default, as safe to share as a 'sessions share' page.
193
219
 
194
220
  One selector renders the single trajectory; exactly two selectors compare them (a shared time axis,
195
221
  the first divergence point, and the step-level diff); one selector with --tree renders its lineage —
@@ -375,9 +401,6 @@ Three or more selectors, and --tree with more than one selector, fail loud.`,
375
401
  });
376
402
  return cmd;
377
403
  }
378
- export function registerSessionsTraceCommand(sessionsCmd) {
379
- configureTraceCommand(sessionsCmd.command('trace <selectors...>'));
380
- }
381
404
  export function registerTraceCommand(program) {
382
405
  configureTraceCommand(program.command('trace <selectors...>'));
383
406
  }
@@ -9,10 +9,10 @@ export function registerSessionsWatchCommand(parent) {
9
9
  setHelpSections(command, {
10
10
  examples: `
11
11
  # Subscribe to session changes for a long-lived UI consumer
12
- agents sessions watch --json
12
+ agents ps watch --json
13
13
 
14
14
  # Subscribe only to this machine
15
- agents sessions watch --json --local
15
+ agents ps watch --json --local
16
16
  `,
17
17
  notes: `
18
18
  - Each line is one versioned reset, upsert, remove, scope, or heartbeat envelope.
@@ -8,6 +8,7 @@ export declare function writeClaudeSession(tempHome: string, projectKey: string,
8
8
  export declare function writeCodexSession(tempHome: string, sessionId: string, cwd: string, prompt: string, timestamp: string): void;
9
9
  export declare function writeOpenClawSetup(tempHome: string, version?: string): string;
10
10
  export declare function runAgents(args: string[], cwd: string, home: string, envOverrides?: Record<string, string>): import("node:child_process").SpawnSyncReturns<string>;
11
+ export declare function indexSessions(cwd: string, home: string): import("node:child_process").SpawnSyncReturns<string>;
11
12
  export declare function outputOf(result: {
12
13
  stdout: string;
13
14
  stderr: string;
@@ -167,6 +167,20 @@ export function runAgents(args, cwd, home, envOverrides = {}) {
167
167
  encoding: 'utf-8',
168
168
  });
169
169
  }
170
+ // The daemon tick's incremental scan, the only writer of the index on a peer.
171
+ export function indexSessions(cwd, home) {
172
+ const script = [
173
+ "const { scanSessionsIncremental } = await import('./src/lib/session/discover.ts');",
174
+ "const { closeDB } = await import('./src/lib/session/db.ts');",
175
+ 'await scanSessionsIncremental();',
176
+ 'closeDB();',
177
+ ].join(' ');
178
+ return spawnSync(process.execPath, ['--import', tsxLoaderUrl, '--input-type=module', '--eval', script], {
179
+ cwd: repoRoot,
180
+ env: { ...process.env, HOME: home, USERPROFILE: home, PWD: cwd },
181
+ encoding: 'utf-8',
182
+ });
183
+ }
170
184
  export function outputOf(result) {
171
185
  return `${result.stdout}${result.stderr}`;
172
186
  }
@@ -39,7 +39,7 @@ export async function runBrowserWizard() {
39
39
  await runBrowserVerb(['use']);
40
40
  const chosen = configuredDefaultProfile();
41
41
  if (!chosen) {
42
- console.log(chalk.dim('No default profile chosen. Run `agents browser use <name>` later to set one.'));
42
+ console.log(chalk.dim('No default profile chosen. Run `browser use <name>` later to set one.'));
43
43
  return false;
44
44
  }
45
45
  printOnboardingNextStep(chosen);
@@ -48,14 +48,14 @@ export async function runBrowserWizard() {
48
48
  function printOnboardingNextStep(name) {
49
49
  console.log(chalk.bold('\nOne manual step left:'));
50
50
  console.log(' ' +
51
- chalk.cyan(`agents browser start --profile ${name}`) +
51
+ chalk.cyan(`browser start --profile ${name}`) +
52
52
  chalk.dim(' # finish the browser first-run + sign in to any sites you want automated'));
53
- console.log(chalk.dim(` Then check it's ready: agents browser profiles doctor ${name}`));
53
+ console.log(chalk.dim(` Then check it's ready: browser profiles doctor ${name}`));
54
54
  }
55
55
  export function registerSetupBrowserCommand(setupCmd) {
56
56
  setupCmd
57
57
  .command('browser')
58
- .description('Set up `agents browser` — install the Browser CLI, seed profiles, and pick this machine\'s default.')
58
+ .description('Set up the standalone `browser` CLI — install it, seed profiles, and pick this machine\'s default.')
59
59
  .option('--install-only', 'Install the standalone Browser CLI without changing profiles or starting a browser')
60
60
  .option('--terminal [backend]', 'Open interactive setup in a detected or selected terminal')
61
61
  .action(async (options) => {
@@ -19,7 +19,7 @@ function openPane(pane) {
19
19
  export async function runComputerWizard() {
20
20
  if (os.platform() !== 'darwin') {
21
21
  console.log(chalk.yellow('`agents setup computer` configures the macOS helper (local control).'));
22
- console.log(chalk.dim('On Windows, provision a remote host from a Mac/Linux box instead: `agents computer setup --device <device>`.'));
22
+ console.log(chalk.dim('On Windows, provision a remote host from a Mac/Linux box instead: `computer setup --device <device>`.'));
23
23
  return false;
24
24
  }
25
25
  try {
@@ -67,7 +67,7 @@ export async function runComputerWizard() {
67
67
  openPane(SCREEN_PANE);
68
68
  if (!trusted) {
69
69
  console.log(chalk.yellow('\nAccessibility not granted yet.'));
70
- console.log(chalk.dim('Finish both grants in System Settings, then run: ') + chalk.cyan('agents computer start'));
70
+ console.log(chalk.dim('Finish both grants in System Settings, then run: ') + chalk.cyan('computer start'));
71
71
  console.log(chalk.dim(' Accessibility: System Settings > Privacy & Security > Accessibility'));
72
72
  console.log(chalk.dim(' Screen Recording: System Settings > Privacy & Security > Screen Recording'));
73
73
  }
@@ -81,7 +81,7 @@ export async function runComputerWizard() {
81
81
  console.log(chalk.dim(' allow:'));
82
82
  console.log(chalk.dim(' - "Computer(com.apple.finder)"'));
83
83
  console.log(chalk.dim(' - "Computer(com.apple.notes)"'));
84
- console.log(chalk.dim(' Then reload: ') + chalk.cyan('agents computer reload'));
84
+ console.log(chalk.dim(' Then reload: ') + chalk.cyan('computer reload'));
85
85
  return trusted;
86
86
  }
87
87
  async function pollForTrust() {
@@ -107,7 +107,7 @@ async function pollForTrust() {
107
107
  export function registerSetupComputerCommand(setupCmd) {
108
108
  setupCmd
109
109
  .command('computer')
110
- .description('Set up `agents computer` (macOS) — install the signed helper and grant control permissions.')
110
+ .description('Set up `computer` (macOS) — install the signed helper and grant control permissions.')
111
111
  .option('--install-only', 'Install the standalone Computer CLI without starting the helper or changing permissions')
112
112
  .option('--terminal [backend]', 'Open interactive setup in a detected or selected terminal')
113
113
  .action(async (options) => {
@@ -73,7 +73,7 @@ async function resolveInteractiveChoices(opts) {
73
73
  default: 'key',
74
74
  choices: [
75
75
  { name: 'key — use your SSH agent / on-disk public keys', value: 'key' },
76
- { name: 'password — read the login password from an agents secrets bundle', value: 'password' },
76
+ { name: 'password — read the login password from an secrets bundle', value: 'password' },
77
77
  ],
78
78
  });
79
79
  return {
@@ -58,7 +58,7 @@ export async function maybePickBrowserProfile(deps = {}) {
58
58
  if (!chosen)
59
59
  return false;
60
60
  console.log(chalk.green(`Browser: '${chosen}'`) +
61
- chalk.dim(' — this machine\'s default (agents browser use to change).'));
61
+ chalk.dim(' — this machine\'s default (browser use to change).'));
62
62
  return true;
63
63
  }
64
64
  export async function runPreferencesStep() {
@@ -7,6 +7,6 @@ interface BackupSetupOptions {
7
7
  token?: string;
8
8
  domain: string;
9
9
  }
10
- export declare function handleSessionsBackupSetup(opts: BackupSetupOptions): Promise<void>;
11
- export declare function registerSessionsBackupSetupCommand(sessionsCmd: Command): void;
10
+ export declare function handleSessionBackupSetup(opts: BackupSetupOptions): Promise<void>;
11
+ export declare function registerSetupSessionBackupCommand(setupCmd: Command): void;
12
12
  export {};
@@ -4,7 +4,7 @@ import { PHOENIX_ID_BASE } from '../lib/identity/client.js';
4
4
  import { provisionSessions } from '../lib/session/sync/provision.js';
5
5
  import { DEFAULT_SESSIONS_BUCKET_NAME, DEFAULT_SESSIONS_DOMAIN, DEFAULT_SESSIONS_WORKER_NAME, } from '../lib/session/sync/managed-config.js';
6
6
  import { setHelpSections } from '../lib/help.js';
7
- export async function handleSessionsBackupSetup(opts) {
7
+ export async function handleSessionBackupSetup(opts) {
8
8
  const { input } = await import('@inquirer/prompts');
9
9
  const { apiToken, accountId: bundledAccountId } = readCloudflareCreds(opts.bundle, {
10
10
  apiToken: opts.token,
@@ -22,18 +22,18 @@ export async function handleSessionsBackupSetup(opts) {
22
22
  phoenixIdBase: PHOENIX_ID_BASE,
23
23
  });
24
24
  console.log(chalk.green(`Managed session-backup endpoint ready → ${chalk.bold(result.baseUrl)}`));
25
- console.log(chalk.dim('Signed-in users now back up with `agents sessions export --to-r2` — no r2.backups bucket.'));
25
+ console.log(chalk.dim('Signed-in users now back up with `sessions export --to-r2` — no r2.backups bucket.'));
26
26
  }
27
27
  const BACKUP_SETUP_EXAMPLES = `
28
- $ agents secrets exec cloudflare -- agents sessions backup-setup
28
+ $ secrets exec cloudflare -- agents setup session-backup
29
29
  Provision the managed session-backup Worker + R2 bucket (creds from the bundle).
30
30
 
31
- $ agents sessions backup-setup --account <id> --domain sessions.example.com
31
+ $ agents setup session-backup --account <id> --domain sessions.example.com
32
32
  Provision against a private account service and custom domain.
33
33
  `.trimStart();
34
- export function registerSessionsBackupSetupCommand(sessionsCmd) {
35
- const cmd = sessionsCmd
36
- .command('backup-setup')
34
+ export function registerSetupSessionBackupCommand(setupCmd) {
35
+ const cmd = setupCmd
36
+ .command('session-backup')
37
37
  .description('(operator) Provision the managed session-backup Worker + R2 bucket — NOT a per-user step; signing in with `agents auth login` backs sessions up with zero setup')
38
38
  .option('--bundle <name>', 'secrets bundle holding the Cloudflare API token', DEFAULT_CF_BUNDLE)
39
39
  .option('--worker <name>', 'Worker name', DEFAULT_SESSIONS_WORKER_NAME)
@@ -43,7 +43,7 @@ export function registerSessionsBackupSetupCommand(sessionsCmd) {
43
43
  .option('--domain <host>', 'custom domain to map', DEFAULT_SESSIONS_DOMAIN)
44
44
  .action(async (opts) => {
45
45
  try {
46
- await handleSessionsBackupSetup(opts);
46
+ await handleSessionBackupSetup(opts);
47
47
  }
48
48
  catch (err) {
49
49
  console.error(chalk.red(err.message));
@@ -21,6 +21,7 @@ import { registerSetupTermCommand, runTermWizard, isTermCliInstalled } from './s
21
21
  import { registerSetupFleetCommand } from './setup-fleet.js';
22
22
  import { registerSetupAccountsCommand, runAccountsSetupWizard } from './setup-accounts.js';
23
23
  import { registerSetupWatchdogCommand, runWatchdogSetupWizard } from './setup-watchdog.js';
24
+ import { registerSetupSessionBackupCommand } from './setup-session-backup.js';
24
25
  import { hasMintedSetupToken } from '../lib/auth-mint.js';
25
26
  import { registerAliasCommand } from './alias.js';
26
27
  import { registerBetaCommands } from './beta.js';
@@ -184,7 +185,7 @@ export async function runSetup(program, options = {}) {
184
185
  .map(i => `${agentLabel(i.agentId)} (${sessionCounts[i.agentId] || 0})`)
185
186
  .join(', ');
186
187
  console.log(chalk.gray(`\n${totalSessions} sessions available across ${breakdown}`));
187
- console.log(chalk.cyan(' agents sessions') + chalk.gray(' # browse them'));
188
+ console.log(chalk.cyan(' sessions') + chalk.gray(' # browse them'));
188
189
  }
189
190
  }
190
191
  }
@@ -332,6 +333,7 @@ export function registerSetupCommand(program) {
332
333
  registerSetupAccountsCommand(setupCmd);
333
334
  registerSetupFleetCommand(setupCmd);
334
335
  registerSetupWatchdogCommand(setupCmd);
336
+ registerSetupSessionBackupCommand(setupCmd);
335
337
  registerAliasCommand(setupCmd);
336
338
  registerBetaCommands(setupCmd);
337
339
  const urlScheme = setupCmd
@@ -23,7 +23,7 @@ import { clearPendingSentinel } from '../lib/devices/pending.js';
23
23
  import { getDeviceDiscoveryStatus, setDeviceDiscoveryStatus } from '../lib/devices/discovery-policy.js';
24
24
  import { isInteractiveTerminal, isPromptCancelled } from './utils.js';
25
25
  import { hostNameFor, renderSshConfig } from '../lib/devices/ssh-config.js';
26
- import { ASKPASS_BUNDLE_ENV, ASKPASS_KEY_ENV, buildSshInvocation, deviceIdentityArgs, fleetDialTarget, isAgentsBrowserDrive, markFleetRemote, writeAskpassShim, } from '../lib/devices/connect.js';
26
+ import { ASKPASS_BUNDLE_ENV, ASKPASS_KEY_ENV, buildSshInvocation, deviceIdentityArgs, fleetDialTarget, isBrowserDrive, markFleetRemote, writeAskpassShim, } from '../lib/devices/connect.js';
27
27
  import { ensureManagedKnownHostsDir, isHostPinned } from '../lib/devices/known-hosts.js';
28
28
  import { shouldSyncTerminfo, syncTerminfoToDevice, terminfoHostKey } from '../lib/devices/terminfo.js';
29
29
  import { fanOutDevices, fleetHealthSkip, planFleetTargets, remoteFleetTargets, runFleet, runOnDevice, runLocalCommand, skipLabel, upgradeCommand, } from '../lib/devices/fleet.js';
@@ -261,7 +261,7 @@ function trySshLeasedBox(name, cmd) {
261
261
  process.exit(res.status ?? 1);
262
262
  }
263
263
  export function leasedBoxRemoteCmd(cmd) {
264
- return isAgentsBrowserDrive(cmd) ? markFleetRemote(cmd, { shell: 'posix' }) : cmd;
264
+ return isBrowserDrive(cmd) ? markFleetRemote(cmd, { shell: 'posix' }) : cmd;
265
265
  }
266
266
  async function mustGetDevice(name) {
267
267
  const d = await getDevice(name);
@@ -2067,9 +2067,8 @@ launched from — 'agents ssh yosemite-s0' from ~/src/app lands in ~/src/app on
2067
2067
  the target when it exists, else the remote home. Same portable-cwd rule as
2068
2068
  'agents run --device'. Passing a command keeps the remote home.
2069
2069
 
2070
- An 'agents browser …', 'ag browser …', or standalone 'browser …' command is
2071
- stamped AGENTS_FLEET_REMOTE so the target's browser.remote-control consent
2072
- gate applies, same as 'agents browser <verb> --device <name>'.
2070
+ A 'browser …' command is stamped AGENTS_FLEET_REMOTE so the target's
2071
+ browser.remote-control consent gate applies, same as 'browser <verb> --device <name>'.
2073
2072
 
2074
2073
  --argv takes a JSON array of strings and delivers each element as exactly ONE
2075
2074
  token on the peer, so a token containing a space, '&', '|', '$' or a quote
@@ -113,7 +113,7 @@ export function addSelectorOptions(cmd) {
113
113
  export function registerSyncCommand(program) {
114
114
  const cmd = addHostOption(program.command('sync [agentSpec] [repo]'))
115
115
  .summary('Make this machine current, or sync resources into one agent')
116
- .description('With an [agentSpec], syncs resources (commands, skills, hooks, rules, MCPs, plugins, etc.) into that installed agent version — previews changes and lets you pick. e.g. "claude", "claude@2.1.142", a selector: @latest / @oldest / @pinned (= @default), or @all for every installed version.\n\nAppend a [repo] (or pass --repo) to scope the sync to a single DotAgent repo — system / user / project / <alias>. e.g. "agents sync claude@all system" reconciles only the system repo\'s resources into every installed Claude.\n\nGive a DotAgent repo name ALONE — "agents sync system" / "agents sync user" / "agents sync <alias>" — to git-sync that one repo: git pull --rebase against origin when the tree is clean; when it is dirty, fast-forward anyway if no incoming path is uncommitted, else refuse and name what collided. The user repo and extra aliases also push local commits up; the system repo is a pull-only mirror.\n\nWith NO agent, runs the umbrella verb: fetch the config repos then reconcile them into every installed agent. Secrets are opt-in — add --secrets to pull secret bundles. Session transcripts are queryable live via "agents sessions --device <machine>", or moved with "agents sessions export/import". Also: --cloud (fetch only), --local (reconcile only).\n\n`agents sync status` reports fleet drift (what is drifted, missing, or behind) and can reconcile it — the former top-level `agents status`.')
116
+ .description('With an [agentSpec], syncs resources (commands, skills, hooks, rules, MCPs, plugins, etc.) into that installed agent version — previews changes and lets you pick. e.g. "claude", "claude@2.1.142", a selector: @latest / @oldest / @pinned (= @default), or @all for every installed version.\n\nAppend a [repo] (or pass --repo) to scope the sync to a single DotAgent repo — system / user / project / <alias>. e.g. "agents sync claude@all system" reconciles only the system repo\'s resources into every installed Claude.\n\nGive a DotAgent repo name ALONE — "agents sync system" / "agents sync user" / "agents sync <alias>" — to git-sync that one repo: git pull --rebase against origin when the tree is clean; when it is dirty, fast-forward anyway if no incoming path is uncommitted, else refuse and name what collided. The user repo and extra aliases also push local commits up; the system repo is a pull-only mirror.\n\nWith NO agent, runs the umbrella verb: fetch the config repos then reconcile them into every installed agent. Secrets are opt-in — add --secrets to pull secret bundles. Session transcripts are queryable live via "sessions --device <machine>", or moved with "sessions export/import". Also: --cloud (fetch only), --local (reconcile only).\n\n`agents sync status` reports fleet drift (what is drifted, missing, or behind) and can reconcile it — the former top-level `agents status`.')
117
117
  .option('--agent <agent>', 'Agent identifier (legacy form; prefer the positional spec)')
118
118
  .option('--agent-version <version>', 'Version to sync into (legacy form; prefer "agent@version" or --version)')
119
119
  .option('--repo <name>', 'Scope the sync to a single DotAgent repo: system / user / project / <alias> (also accepted as a positional)')
@@ -1047,7 +1047,7 @@ export function registerTeamsCommands(program) {
1047
1047
  `,
1048
1048
  notes: `
1049
1049
  A team is a named group of agents working in the background on a shared task.
1050
- Teammate sessions show in 'agents sessions --teams' tagged [team/name · mode].
1050
+ Teammate sessions show in 'sessions --teams' tagged [team/name · mode].
1051
1051
 
1052
1052
  Teammate syntax:
1053
1053
  'claude' the default Claude version on this machine
@@ -1708,7 +1708,7 @@ export function registerTeamsCommands(program) {
1708
1708
  }
1709
1709
  console.log();
1710
1710
  }
1711
- console.log(chalk.gray(`${running.length} teammate${running.length === 1 ? '' : 's'} running. See 'agents sessions --active' for the full cross-context view.`));
1711
+ console.log(chalk.gray(`${running.length} teammate${running.length === 1 ? '' : 's'} running. See 'agents ps' for the full cross-context view.`));
1712
1712
  });
1713
1713
  addHostOption(teams.command('start [team]'))
1714
1714
  .description('Launch ready teammates independently. Failed launch/placement and blocked --after dependencies persist in status; --watch keeps draining viable DAG branches.')
@@ -11,7 +11,6 @@ export interface Surface {
11
11
  interactive: boolean;
12
12
  }
13
13
  export declare function resolveSurface(cmd: Command): Surface;
14
- export declare function normalizeSingleDeviceOption(value: string | string[] | undefined, commandLabel: string): string | undefined;
15
14
  export declare function requireInteractiveSelection(action: string, alternatives: string[]): never;
16
15
  export declare function requireDestructiveArg(opts: {
17
16
  argName: string;
@@ -31,16 +31,6 @@ export function resolveSurface(cmd) {
31
31
  interactive: tty && !json,
32
32
  };
33
33
  }
34
- export function normalizeSingleDeviceOption(value, commandLabel) {
35
- const list = value == null ? [] : Array.isArray(value) ? value : [value];
36
- const hosts = list.map((v) => String(v).trim()).filter((v) => v.length > 0);
37
- if (hosts.length === 0)
38
- return undefined;
39
- if (hosts.length > 1) {
40
- throw new Error(`${commandLabel} targets a single device, but --device named ${hosts.length}: ${hosts.join(', ')}.`);
41
- }
42
- return hosts[0];
43
- }
44
34
  export function requireInteractiveSelection(action, alternatives) {
45
35
  console.error(chalk.red(`${action} requires an interactive terminal.`));
46
36
  if (alternatives.length > 0) {
package/dist/index.js CHANGED
@@ -67,76 +67,5 @@ if (process.argv[2] === '__daemon-run') {
67
67
  }
68
68
  process.exit(process.exitCode ?? 0);
69
69
  }
70
- if (process.argv[2] === 'sessions') {
71
- const forwarded = process.argv.slice(3);
72
- const { isReadQuery, usesFilterFlags, usesHostFlag, sessionsBinSupportsFilters, sessionsBinSupportsHost, planDeviceHostRead, resolveSessionsBin, invocation, SessionsClientError, SESSIONS_INSTALL_HINT, } = await import('./lib/sessions-client.js');
73
- let bin = null;
74
- try {
75
- bin = resolveSessionsBin();
76
- }
77
- catch (err) {
78
- if (!(err instanceof SessionsClientError && err.code === 'SESSIONS_BIN_MISSING'))
79
- throw err;
80
- }
81
- const filters = bin !== null && usesFilterFlags(forwarded) ? sessionsBinSupportsFilters(bin) : false;
82
- const host = bin !== null && usesHostFlag(forwarded) ? sessionsBinSupportsHost(bin) : false;
83
- if (bin !== null) {
84
- const deviceRead = planDeviceHostRead(forwarded, { filters });
85
- if (deviceRead && sessionsBinSupportsHost(bin)) {
86
- let target = null;
87
- try {
88
- const { resolveRemoteDevice } = await import('./lib/ssh-tunnel.js');
89
- target = (await resolveRemoteDevice(deviceRead.device, {})).target;
90
- }
91
- catch {
92
- target = null;
93
- }
94
- if (target !== null) {
95
- const { spawnSync } = await import('node:child_process');
96
- const { command, prefix } = invocation(bin);
97
- const hostArgs = [...deviceRead.readArgs, '--host', `ssh://${target}`];
98
- const childEnv = { ...process.env };
99
- if (process.stdout.isTTY && !hostArgs.includes('--json')) {
100
- if (childEnv.FORCE_COLOR === undefined)
101
- childEnv.FORCE_COLOR = '1';
102
- if (process.stdout.columns)
103
- childEnv.COLUMNS = String(process.stdout.columns);
104
- if (process.stdout.rows)
105
- childEnv.LINES = String(process.stdout.rows);
106
- }
107
- const res = spawnSync(command, [...prefix, ...hostArgs], {
108
- encoding: 'utf8',
109
- env: childEnv,
110
- maxBuffer: 256 * 1024 * 1024,
111
- });
112
- if (res.error) {
113
- process.stderr.write(`Failed to run \`sessions\`: ${res.error.message}\n`);
114
- process.exit(1);
115
- }
116
- if (res.status !== 127) {
117
- if (res.stdout)
118
- process.stdout.write(res.stdout);
119
- if (res.stderr)
120
- process.stderr.write(res.stderr);
121
- process.exit(res.status ?? 1);
122
- }
123
- }
124
- }
125
- }
126
- if (isReadQuery(forwarded, { filters, host })) {
127
- if (!bin) {
128
- process.stderr.write(`agents: the standalone \`sessions\` CLI was not found. Install it with ${SESSIONS_INSTALL_HINT}, or point $SESSIONS_BIN at its executable.\n`);
129
- process.exit(1);
130
- }
131
- const { spawnSync } = await import('node:child_process');
132
- const { command, prefix } = invocation(bin);
133
- const res = spawnSync(command, [...prefix, ...forwarded], { stdio: 'inherit' });
134
- if (res.error) {
135
- process.stderr.write(`Failed to run \`sessions\`: ${res.error.message}\n`);
136
- process.exit(1);
137
- }
138
- process.exit(res.status ?? 1);
139
- }
140
- }
141
70
  await import('./bootstrap.js');
142
71
  export {};
@@ -42,6 +42,9 @@ export declare function parseAccountSelector(input: string): {
42
42
  export declare function assertUnambiguousNativeAccount(meta: Pick<Meta, 'accounts' | 'deviceAccounts'>, name: string, agent?: AgentId): void;
43
43
  export declare function assertNativeAccountNameAvailable(name: string, agent: AgentId): void;
44
44
  export declare function addNativeAccount(name: string, agent: AgentId, identityKey: string, identityLabel: string | undefined, scope: 'version' | 'device'): NativeAccount;
45
+ export declare const PEER_ACCOUNT_ROW_LIMIT = 256;
46
+ export declare function peerAccountRow(record: NativeAccountRecord): NativeAccountRecord;
47
+ export declare function adoptPeerNativeAccounts(records: readonly NativeAccountRecord[]): string[];
45
48
  export declare function labelNativeAccount(agent: AgentId, identityKey: string, identityLabel: string | undefined, label: string | undefined, scope: 'version' | 'device'): NativeAccount;
46
49
  export declare function nativeAccountHome(accountId: string, meta: Pick<Meta, 'deviceAccounts'>): string | null;
47
50
  export declare function setDefaultAccountIfAbsent(agent: AgentId, name: string): boolean;
@@ -213,6 +213,46 @@ export function addNativeAccount(name, agent, identityKey, identityLabel, scope)
213
213
  }
214
214
  return account;
215
215
  }
216
+ export const PEER_ACCOUNT_ROW_LIMIT = 256;
217
+ const PEER_ACCOUNT_ID = /^[a-zA-Z0-9][a-zA-Z0-9-]{0,63}$/;
218
+ export function peerAccountRow(record) {
219
+ const { id, name, agent, identityKey, identityLabel, createdOn } = record;
220
+ return {
221
+ id, name, agent, identityKey, scope: 'version', provisioning: 'per-device',
222
+ ...(identityLabel ? { identityLabel } : {}),
223
+ ...(createdOn ? { createdOn } : {}),
224
+ };
225
+ }
226
+ function missingPeerRows(meta, records) {
227
+ const known = listNativeAccounts(meta);
228
+ const missing = [];
229
+ for (const record of records.slice(0, PEER_ACCOUNT_ROW_LIMIT)) {
230
+ if (record.scope !== 'version' || record.provisioning !== 'per-device' || !PEER_ACCOUNT_ID.test(record.id))
231
+ continue;
232
+ if (Object.hasOwn(meta.accounts?.native ?? {}, record.id))
233
+ continue;
234
+ const taken = [...known, ...missing].some(account => account.id === record.id || account.agent === record.agent
235
+ && (account.identityKey === record.identityKey || account.name === record.name));
236
+ if (!taken)
237
+ missing.push(peerAccountRow(record));
238
+ }
239
+ return missing;
240
+ }
241
+ export function adoptPeerNativeAccounts(records) {
242
+ if (missingPeerRows(readMeta(), records).length === 0)
243
+ return [];
244
+ let adopted = [];
245
+ updateMeta(current => {
246
+ adopted = missingPeerRows(current, records);
247
+ if (adopted.length === 0)
248
+ return current;
249
+ const native = { ...current.accounts?.native };
250
+ for (const row of adopted)
251
+ native[row.id] = row;
252
+ return { ...current, accounts: { ...current.accounts, native } };
253
+ });
254
+ return adopted.map(row => row.id);
255
+ }
216
256
  export function labelNativeAccount(agent, identityKey, identityLabel, label, scope) {
217
257
  const resolvedLabel = label ?? identityLabel;
218
258
  if (!resolvedLabel)
@@ -88,6 +88,7 @@ interface ApplyPeerStateOptions {
88
88
  export interface ApplyPeerStateResult {
89
89
  path: string;
90
90
  merged: number;
91
+ adoptedAccounts: string[];
91
92
  receivedAt: number;
92
93
  }
93
94
  export declare function applyPeerFleetState(state: FleetSharedDeviceState, options?: ApplyPeerStateOptions): Promise<ApplyPeerStateResult>;
@@ -20,10 +20,11 @@
20
20
  * scheduled because a repo was bloated. Git now carries human-authored
21
21
  * resources only; `devices/<device>/daemon-state.json` is untracked.
22
22
  */
23
- import { isHeadedDeviceRole, selfConfiguredDeviceRole } from '../device-config.js';
23
+ import { configuredDeviceRole, isHeadedDeviceRole, selfConfiguredDeviceRole } from '../device-config.js';
24
24
  import { FLEET_SHARED_STATE_VERSION, parseFleetSharedDeviceStateEnvelope, readFleetSharedDeviceStates, readOwnFleetSharedDeviceState, storePeerFleetSharedDeviceState, updateFleetSharedDeviceStateAsync, } from '../fleet-shared-state.js';
25
25
  import { getUserAgentsDir } from '../state.js';
26
26
  import { machineId, normalizeHost } from '../session/sync/config.js';
27
+ import { resolveDeviceProfile } from '../devices/resolve-profile.js';
27
28
  import { exportClaudeUsageCacheRows, ingestPeerClaudeUsageRows, } from './usage.js';
28
29
  export const USAGE_SYNC_INTERVAL_MS = 15 * 60_000;
29
30
  export const USAGE_PUBLISH_HEARTBEAT_MS = 10 * 60_000;
@@ -193,6 +194,21 @@ function stampSyncRows(rows, sender) {
193
194
  }
194
195
  return out;
195
196
  }
197
+ async function adoptHeadedPeerAccounts(state) {
198
+ const native = state.accounts?.native;
199
+ if (!native?.length)
200
+ return [];
201
+ if (!isHeadedDeviceRole(configuredDeviceRole(state.device)))
202
+ return [];
203
+ const { isAgentId } = await import('../types.js');
204
+ const records = native.filter((record) => typeof record?.id === 'string' && typeof record.name === 'string'
205
+ && isAgentId(record.agent) && typeof record.identityKey === 'string' && record.scope === 'version'
206
+ && normalizeHost(record.createdOn ?? '') === normalizeHost(state.device));
207
+ if (records.length === 0)
208
+ return [];
209
+ const { adoptPeerNativeAccounts } = await import('../account-registry.js');
210
+ return adoptPeerNativeAccounts(records);
211
+ }
196
212
  // Peer state is newest-wins and can never overwrite this device's own publisher file.
197
213
  export async function applyPeerFleetState(state, options = {}) {
198
214
  const self = normalizeHost(options.device ?? machineId());
@@ -204,7 +220,8 @@ export async function applyPeerFleetState(state, options = {}) {
204
220
  const merged = state.usage
205
221
  ? await ingestPeerClaudeUsageRows(stampSyncRows(state.usage.rows, state.device), options.cachePath)
206
222
  : 0;
207
- return { path: write.path, merged, receivedAt };
223
+ const adoptedAccounts = await adoptHeadedPeerAccounts(state);
224
+ return { path: write.path, merged, adoptedAccounts, receivedAt };
208
225
  }
209
226
  export async function buildFleetStateExchangeCommand(os) {
210
227
  const { buildRemoteAgentsInvocation, buildWindowsStdinAgentsCommand, remoteShellFor } = await import('../hosts/remote-cmd.js');
@@ -241,7 +258,7 @@ export async function exchangeFleetStateWithPeers(options = {}) {
241
258
  const outcomes = await Promise.all(peers.map(async (peer) => {
242
259
  const outcome = { device: peer.name, delivered: false, receivedAt: null, merged: 0, error: null, peerErrors: [] };
243
260
  try {
244
- const remoteCmd = await buildFleetStateExchangeCommand(peer.shell === 'powershell' ? 'windows' : undefined);
261
+ const remoteCmd = await buildFleetStateExchangeCommand(resolveDeviceProfile(peer).shell === 'powershell' ? 'windows' : undefined);
245
262
  const res = await dial(peer, remoteCmd, input);
246
263
  if (res.timedOut)
247
264
  throw new Error(`timed out after ${Math.round(timeoutMs / 1000)}s`);
@@ -53,6 +53,7 @@ export interface UsageSnapshot {
53
53
  unavailable?: {
54
54
  reason: 'session_limit' | 'out_of_credits';
55
55
  resetsAt?: Date;
56
+ notedAt?: Date;
56
57
  };
57
58
  freshness?: {
58
59
  source: UsageCaptureSource;
@@ -125,6 +126,7 @@ export interface CachedUsageSnapshot {
125
126
  unavailable?: {
126
127
  reason: 'session_limit' | 'out_of_credits';
127
128
  resetsAt?: string;
129
+ notedAt?: string;
128
130
  };
129
131
  modelRefusals?: Record<string, CachedModelRefusal>;
130
132
  freshnessSource?: UsageCaptureSource;
@@ -317,7 +319,8 @@ export declare function writeClaudeUsageCache(usageKey: string, snapshot: UsageS
317
319
  export declare function mergeClaudeUsageCacheWindows(usageKey: string, snapshot: UsageSnapshot, cachePath?: string): void;
318
320
  export declare function exportClaudeUsageCacheRows(cachePath?: string): Record<string, CachedUsageSnapshot>;
319
321
  export declare function ingestPeerClaudeUsageRows(rows: Record<string, CachedUsageSnapshot>, cachePath?: string): Promise<number>;
320
- export declare function noteClaudeOutOfCredits(usageKey: string, cachePath?: string): void;
322
+ export declare const OUT_OF_CREDITS_REPROBE_MS: number;
323
+ export declare function noteClaudeOutOfCredits(usageKey: string, cachePath?: string, now?: Date): void;
321
324
  export declare function clearClaudeAccountRefusal(usageKey: string, cachePath?: string): void;
322
325
  export declare function noteClaudeSessionLimit(usageKey: string, resetsAt: Date, cachePath?: string): void;
323
326
  export declare function claudeModelRefusalKey(accountId?: string | null, home?: string | null): string | undefined;