@phnx-labs/agents-cli 1.20.93 → 1.21.0

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 (112) hide show
  1. package/CHANGELOG.md +264 -0
  2. package/README.md +3 -0
  3. package/dist/bin/agents +0 -0
  4. package/dist/commands/beta.js +3 -5
  5. package/dist/commands/doctor.js +23 -0
  6. package/dist/commands/exec.js +13 -0
  7. package/dist/commands/mailboxes.js +39 -1
  8. package/dist/commands/message.js +12 -1
  9. package/dist/commands/packages.js +14 -5
  10. package/dist/commands/projects.d.ts +28 -0
  11. package/dist/commands/projects.js +173 -47
  12. package/dist/commands/routines.js +27 -1
  13. package/dist/commands/rules.js +6 -0
  14. package/dist/commands/sessions.d.ts +17 -0
  15. package/dist/commands/sessions.js +16 -8
  16. package/dist/commands/setup-browser.js +5 -1
  17. package/dist/commands/setup-fleet.js +5 -0
  18. package/dist/commands/setup-preferences.d.ts +53 -0
  19. package/dist/commands/setup-preferences.js +142 -0
  20. package/dist/commands/setup.js +8 -9
  21. package/dist/commands/ssh.js +220 -10
  22. package/dist/commands/sync.d.ts +2 -2
  23. package/dist/commands/sync.js +4 -9
  24. package/dist/commands/watchdog.js +26 -3
  25. package/dist/index.js +22 -6
  26. package/dist/lib/activity.d.ts +7 -0
  27. package/dist/lib/activity.js +19 -2
  28. package/dist/lib/auto-dispatch.d.ts +6 -1
  29. package/dist/lib/auto-dispatch.js +7 -2
  30. package/dist/lib/beta.d.ts +1 -1
  31. package/dist/lib/beta.js +1 -1
  32. package/dist/lib/daemon.d.ts +13 -0
  33. package/dist/lib/daemon.js +80 -60
  34. package/dist/lib/device-config.d.ts +82 -0
  35. package/dist/lib/device-config.js +296 -0
  36. package/dist/lib/event-provenance.d.ts +19 -0
  37. package/dist/lib/event-provenance.js +48 -0
  38. package/dist/lib/events.d.ts +2 -2
  39. package/dist/lib/events.js +4 -53
  40. package/dist/lib/feed.d.ts +1 -1
  41. package/dist/lib/feed.js +2 -0
  42. package/dist/lib/git.d.ts +13 -2
  43. package/dist/lib/git.js +38 -6
  44. package/dist/lib/linear-project-counts.d.ts +72 -5
  45. package/dist/lib/linear-project-counts.js +90 -6
  46. package/dist/lib/linear-projects.d.ts +12 -0
  47. package/dist/lib/linear-projects.js +30 -0
  48. package/dist/lib/mailbox-gc.js +30 -7
  49. package/dist/lib/mailbox.d.ts +14 -1
  50. package/dist/lib/mailbox.js +35 -3
  51. package/dist/lib/menubar/MenubarHelper.app/Contents/CodeResources +0 -0
  52. package/dist/lib/menubar/MenubarHelper.app/Contents/MacOS/MenubarHelper +0 -0
  53. package/dist/lib/menubar/install-menubar.d.ts +5 -21
  54. package/dist/lib/menubar/install-menubar.js +35 -44
  55. package/dist/lib/migrate.js +1 -1
  56. package/dist/lib/models.js +21 -11
  57. package/dist/lib/overdue.d.ts +1 -1
  58. package/dist/lib/overdue.js +54 -19
  59. package/dist/lib/project-import.d.ts +96 -0
  60. package/dist/lib/project-import.js +171 -0
  61. package/dist/lib/remote-agents-json.d.ts +14 -1
  62. package/dist/lib/remote-agents-json.js +21 -3
  63. package/dist/lib/routines.d.ts +53 -0
  64. package/dist/lib/routines.js +105 -4
  65. package/dist/lib/rules/run-sync.d.ts +18 -0
  66. package/dist/lib/rules/run-sync.js +92 -0
  67. package/dist/lib/scheduler.js +12 -2
  68. package/dist/lib/secrets/Agents CLI.app/Contents/CodeResources +0 -0
  69. package/dist/lib/secrets/Agents CLI.app/Contents/MacOS/Agents CLI +0 -0
  70. package/dist/lib/secrets/index.d.ts +4 -5
  71. package/dist/lib/secrets/index.js +4 -5
  72. package/dist/lib/session/active.d.ts +16 -2
  73. package/dist/lib/session/active.js +8 -4
  74. package/dist/lib/session/bundle.js +5 -1
  75. package/dist/lib/session/remote-list.d.ts +1 -15
  76. package/dist/lib/session/remote-list.js +22 -111
  77. package/dist/lib/session/sync/config.d.ts +13 -5
  78. package/dist/lib/session/sync/config.js +21 -13
  79. package/dist/lib/startup/command-registry.d.ts +0 -2
  80. package/dist/lib/startup/command-registry.js +1 -5
  81. package/dist/lib/state.d.ts +7 -2
  82. package/dist/lib/state.js +85 -10
  83. package/dist/lib/sync-umbrella.d.ts +11 -23
  84. package/dist/lib/sync-umbrella.js +14 -45
  85. package/dist/lib/teams/agents.d.ts +35 -3
  86. package/dist/lib/teams/agents.js +52 -8
  87. package/dist/lib/teams/scheduler.d.ts +29 -2
  88. package/dist/lib/teams/scheduler.js +60 -16
  89. package/dist/lib/types.d.ts +17 -1
  90. package/package.json +1 -2
  91. package/dist/commands/drive.d.ts +0 -10
  92. package/dist/commands/drive.js +0 -183
  93. package/dist/commands/hq.d.ts +0 -2
  94. package/dist/commands/hq.js +0 -58
  95. package/dist/commands/sessions-sync.d.ts +0 -17
  96. package/dist/commands/sessions-sync.js +0 -135
  97. package/dist/commands/sync-provision.d.ts +0 -23
  98. package/dist/commands/sync-provision.js +0 -107
  99. package/dist/lib/drive-sync.d.ts +0 -45
  100. package/dist/lib/drive-sync.js +0 -238
  101. package/dist/lib/hq/floor.d.ts +0 -87
  102. package/dist/lib/hq/floor.js +0 -243
  103. package/dist/lib/session/sync/crdt.d.ts +0 -44
  104. package/dist/lib/session/sync/crdt.js +0 -119
  105. package/dist/lib/session/sync/manifest.d.ts +0 -62
  106. package/dist/lib/session/sync/manifest.js +0 -100
  107. package/dist/lib/session/sync/provision.d.ts +0 -49
  108. package/dist/lib/session/sync/provision.js +0 -91
  109. package/dist/lib/session/sync/r2.d.ts +0 -32
  110. package/dist/lib/session/sync/r2.js +0 -121
  111. package/dist/lib/session/sync/sync.d.ts +0 -106
  112. package/dist/lib/session/sync/sync.js +0 -374
@@ -2,18 +2,17 @@
2
2
  * Umbrella `agents sync` orchestration — "make this machine current".
3
3
  *
4
4
  * Bare `agents sync` fetches the config repos then reconciles them into every
5
- * installed agent's version home. Secrets and sessions are opt-in stages
6
- * (`--secrets` / `--sessions`) — see `planUmbrellaStages` for why they're off by
7
- * default. Each stage is an existing exported library function; this module only
8
- * sequences them and decides — from the flags — which stages run. The planner is
9
- * pure so the flag matrix is unit-tested without any I/O.
5
+ * installed agent's version home. Secrets are an opt-in stage (`--secrets`) —
6
+ * see `planUmbrellaStages` for why it's off by default. Each stage is an
7
+ * existing exported library function; this module only sequences them and
8
+ * decides — from the flags — which stages run. The planner is pure so the
9
+ * flag matrix is unit-tested without any I/O.
10
10
  *
11
11
  * Stage backends:
12
12
  * repos -> git pull of ~/.agents + enabled ~/.agents-* extras (pullRepo)
13
13
  * secrets -> listRemoteBundles + pullBundle (needs a passphrase; skipped
14
14
  * cleanly when none is available — tokenized non-interactive auth
15
15
  * arrives with `agents login`, #366/#367)
16
- * sessions -> syncSessions(), gated by the session-sync beta opt-in + isSyncConfigured(), like the daemon
17
16
  * reconcile-> refresh({ skipPrompts }) — re-materialize resources into homes
18
17
  */
19
18
  import { pullRepo } from './git.js';
@@ -24,34 +23,31 @@ import { listRemoteBundles, pullBundle } from './secrets/sync.js';
24
23
  * bare (no flags) fetch repos, then reconcile
25
24
  * --local reconcile only, no fetch
26
25
  * --cloud fetch repos (or the selected subset), skip reconcile
27
- * --repos/--secrets/... fetch only the selected types, then reconcile
26
+ * --repos/--secrets fetch only the selected types, then reconcile
28
27
  * `--local` wins over everything; `--cloud` suppresses reconcile.
29
28
  *
30
- * Secrets and sessions are NOT part of the bare default — they are opt-in via
31
- * `--secrets` / `--sessions`. Pulling every secret bundle onto the machine on a
32
- * bare `agents sync` is more blast radius than the verb should carry by
33
- * default, and session transcripts are queryable on demand (`agents sessions
34
- * --host <machine>`) so they don't need eager mirroring.
29
+ * Secrets are NOT part of the bare default — they are opt-in via `--secrets`.
30
+ * Pulling every secret bundle onto the machine on a bare `agents sync` is more
31
+ * blast radius than the verb should carry by default.
35
32
  */
36
33
  export function planUmbrellaStages(f) {
37
34
  if (f.local) {
38
- return { fetchRepos: false, fetchSecrets: false, fetchSessions: false, reconcile: true };
35
+ return { fetchRepos: false, fetchSecrets: false, reconcile: true };
39
36
  }
40
- const anySelector = !!(f.repos || f.secrets || f.sessions);
37
+ const anySelector = !!(f.repos || f.secrets);
41
38
  if (anySelector) {
42
39
  return {
43
40
  fetchRepos: !!f.repos,
44
41
  fetchSecrets: !!f.secrets,
45
- fetchSessions: !!f.sessions,
46
42
  reconcile: !f.cloud,
47
43
  };
48
44
  }
49
45
  // No per-type selector: bare = repos + reconcile; --cloud = repos, no
50
- // reconcile. Secrets/sessions stay off unless explicitly selected above.
51
- return { fetchRepos: true, fetchSecrets: false, fetchSessions: false, reconcile: !f.cloud };
46
+ // reconcile. Secrets stay off unless explicitly selected above.
47
+ return { fetchRepos: true, fetchSecrets: false, reconcile: !f.cloud };
52
48
  }
53
49
  /**
54
- * Execute the planned stages in order: repos -> secrets -> sessions -> reconcile.
50
+ * Execute the planned stages in order: repos -> secrets -> reconcile.
55
51
  * A failure in one fetch stage is recorded and does not abort the others or the
56
52
  * reconcile — `agents sync` should make as much current as it can in one pass.
57
53
  */
@@ -110,33 +106,6 @@ export async function runUmbrellaSync(args) {
110
106
  result.secrets = { pulled, skipped: false, errors };
111
107
  }
112
108
  }
113
- if (plan.fetchSessions) {
114
- // Gate exactly like the daemon: without the `session-sync` beta opt-in (or
115
- // with a missing r2.backups bundle) this is a clean no-op, not an error that
116
- // fails the whole sync.
117
- const { isBetaEnabled } = await import('./beta.js');
118
- const { isSyncConfigured } = await import('./session/sync/config.js');
119
- if (isBetaEnabled('session-sync') && isSyncConfigured()) {
120
- const { syncSessions } = await import('./session/sync/sync.js');
121
- // Record a failure here instead of letting it throw: like the fetchSecrets
122
- // block above, a failure in one fetch stage must not abort the others or
123
- // the reconcile below (see this function's doc comment). Without this,
124
- // syncSessions() throwing — e.g. via the C1 containment reject on a
125
- // malicious peer manifest — would skip `plan.reconcile` entirely.
126
- try {
127
- const r = await syncSessions();
128
- result.sessions = { ran: true, pushed: r.pushed, pulled: r.pulled, merged: r.merged };
129
- log(`sessions: pushed ${r.pushed}, pulled ${r.pulled}, merged ${r.merged}`);
130
- }
131
- catch (err) {
132
- result.sessions = { ran: false, pushed: 0, pulled: 0, merged: 0, error: err.message };
133
- log(`sessions: failed — ${err.message}`);
134
- }
135
- }
136
- else {
137
- result.sessions = { ran: false, pushed: 0, pulled: 0, merged: 0 };
138
- }
139
- }
140
109
  if (plan.reconcile) {
141
110
  const { refresh } = await import('./refresh.js');
142
111
  await refresh({ skipPrompts: yes });
@@ -218,13 +218,30 @@ export declare class AgentProcess {
218
218
  * Uses a per-wave batched snapshot (remotePollSnapshot) when the supervisor's
219
219
  * one-ssh-per-host pre-pass populated it; otherwise falls back to its own
220
220
  * round-trips so a bare `teams status`/`teams logs` is still correct.
221
+ *
222
+ * Only polls a teammate that is plausibly still RUNNING (RUSH-2118). Once a
223
+ * remote teammate reaches a terminal status, the poll that resolved it already
224
+ * mirrored the final log bytes and read the `.exit` sentinel in this SAME
225
+ * function (delta pulled before the exit check below) — the underlying process
226
+ * is gone and can never write more, so there is nothing left to fetch. Without
227
+ * this guard every finished remote teammate still cost one ssh round-trip on
228
+ * EVERY `--active`/`listAll` poll forever, which is what made `agents sessions
229
+ * --active --local` take ~4.3s on a box with 30 completed teammates.
221
230
  */
222
231
  private syncRemoteMirror;
223
232
  /** Reset the local stdout cursor for a newly truncated resume log. */
224
233
  resetLogReadPosition(): number;
225
234
  /** Restore the cursor when a resume transaction puts the prior log back. */
226
235
  restoreLogReadPosition(position: number): void;
227
- readNewEvents(): Promise<void>;
236
+ /**
237
+ * @param opts.skipRemote A `--local` caller (RUSH-2118): never dial a
238
+ * remote-host teammate, not even a still-RUNNING one — report its
239
+ * last-persisted meta.json state as-is. A local-only query is by definition
240
+ * this-machine-only, so it must not issue an ssh round-trip at all.
241
+ */
242
+ readNewEvents(opts?: {
243
+ skipRemote?: boolean;
244
+ }): Promise<void>;
228
245
  /**
229
246
  * Truncate the local mirror to its trailing REMOTE_MIRROR_MAX_BYTES and reset
230
247
  * lastReadPos to the new (smaller) size so the parser doesn't re-read the kept
@@ -244,7 +261,14 @@ export declare class AgentProcess {
244
261
  saveMeta(): Promise<void>;
245
262
  static loadFromDisk(agentId: string, baseDir?: string | null): Promise<AgentProcess | null>;
246
263
  isProcessAlive(): boolean;
247
- updateStatusFromProcess(): Promise<void>;
264
+ /**
265
+ * @param opts.skipRemote A `--local` caller (RUSH-2118): a distributed
266
+ * teammate is never dialed — its in-memory state (already loaded from
267
+ * meta.json) stands as-is, no ssh, no re-save.
268
+ */
269
+ updateStatusFromProcess(opts?: {
270
+ skipRemote?: boolean;
271
+ }): Promise<void>;
248
272
  /**
249
273
  * Recover the teammate's exit status after its process is gone.
250
274
  *
@@ -298,8 +322,16 @@ export declare class AgentManager {
298
322
  private defaultMode;
299
323
  private initPromise;
300
324
  private cloudDispatcher;
325
+ /**
326
+ * A `--local` caller (RUSH-2118): every poll this manager issues skips the
327
+ * ssh round-trip for a distributed (remote-host) teammate, reporting its
328
+ * last-persisted meta.json state instead. Set once at construction so the
329
+ * INITIAL load in doInitialize()/loadExistingAgents() — which polls every
330
+ * teammate before listRunning()/listAll() ever run — honors it too.
331
+ */
332
+ private localOnly;
301
333
  private constructorAgentsDir;
302
- constructor(maxAgents?: number, agentsDir?: string | null, defaultMode?: Mode | null, filterByCwd?: string | null, cleanupAgeDays?: number);
334
+ constructor(maxAgents?: number, agentsDir?: string | null, defaultMode?: Mode | null, filterByCwd?: string | null, cleanupAgeDays?: number, localOnly?: boolean);
303
335
  private initialize;
304
336
  private doInitialize;
305
337
  getDefaultMode(): Mode;
@@ -34,7 +34,9 @@ import { resolveRemoteOsSync } from '../hosts/remote-os.js';
34
34
  import { pullRemoteLogDelta, REMOTE_MIRROR_MAX_BYTES } from '../hosts/progress.js';
35
35
  import { createRemoteWorktree, ensureRemoteRepo } from './remoteWorktree.js';
36
36
  import { getTeam } from './registry.js';
37
- import { resolvePlacement } from './scheduler.js';
37
+ import { resolvePlacement, cappedDevices } from './scheduler.js';
38
+ import { readMaxConcurrentCaps } from '../device-config.js';
39
+ import chalk from 'chalk';
38
40
  let lastMemoryWarnAt = 0;
39
41
  // On macOS, os.freemem() returns only the truly-free pool and ignores the
40
42
  // large inactive+purgeable cache the kernel will reclaim under pressure, so
@@ -669,10 +671,21 @@ export class AgentProcess {
669
671
  * Uses a per-wave batched snapshot (remotePollSnapshot) when the supervisor's
670
672
  * one-ssh-per-host pre-pass populated it; otherwise falls back to its own
671
673
  * round-trips so a bare `teams status`/`teams logs` is still correct.
674
+ *
675
+ * Only polls a teammate that is plausibly still RUNNING (RUSH-2118). Once a
676
+ * remote teammate reaches a terminal status, the poll that resolved it already
677
+ * mirrored the final log bytes and read the `.exit` sentinel in this SAME
678
+ * function (delta pulled before the exit check below) — the underlying process
679
+ * is gone and can never write more, so there is nothing left to fetch. Without
680
+ * this guard every finished remote teammate still cost one ssh round-trip on
681
+ * EVERY `--active`/`listAll` poll forever, which is what made `agents sessions
682
+ * --active --local` take ~4.3s on a box with 30 completed teammates.
672
683
  */
673
684
  async syncRemoteMirror() {
674
685
  if (!this.hostName || !this.hostTarget || !this.remoteLog)
675
686
  return;
687
+ if (this.status !== AgentStatus.RUNNING)
688
+ return;
676
689
  // Pull the new remote bytes and append them to the local mirror the parser
677
690
  // reads. One offset-tail round-trip; nothing to write when the log is quiet.
678
691
  const delta = pullRemoteLogDelta(this.hostTarget, {
@@ -729,7 +742,15 @@ export class AgentProcess {
729
742
  restoreLogReadPosition(position) {
730
743
  this.lastReadPos = position;
731
744
  }
732
- async readNewEvents() {
745
+ /**
746
+ * @param opts.skipRemote A `--local` caller (RUSH-2118): never dial a
747
+ * remote-host teammate, not even a still-RUNNING one — report its
748
+ * last-persisted meta.json state as-is. A local-only query is by definition
749
+ * this-machine-only, so it must not issue an ssh round-trip at all.
750
+ */
751
+ async readNewEvents(opts = {}) {
752
+ if (this.hostName && opts.skipRemote)
753
+ return;
733
754
  // Distributed teammate: mirror the host's new log bytes locally first, then
734
755
  // fall through to the identical local read+parse below.
735
756
  if (this.hostName) {
@@ -984,7 +1005,12 @@ export class AgentProcess {
984
1005
  }
985
1006
  return true;
986
1007
  }
987
- async updateStatusFromProcess() {
1008
+ /**
1009
+ * @param opts.skipRemote A `--local` caller (RUSH-2118): a distributed
1010
+ * teammate is never dialed — its in-memory state (already loaded from
1011
+ * meta.json) stands as-is, no ssh, no re-save.
1012
+ */
1013
+ async updateStatusFromProcess(opts = {}) {
988
1014
  if (!this.pid) {
989
1015
  // Distributed (remote-host) teammates have no local PID by design; their
990
1016
  // lifecycle lives on the host. readNewEvents() mirrors the remote log and
@@ -992,6 +1018,8 @@ export class AgentProcess {
992
1018
  // syncRemoteMirror), so we just persist and return — never the local
993
1019
  // "RUNNING without a PID is impossible" fail path below.
994
1020
  if (this.hostName) {
1021
+ if (opts.skipRemote)
1022
+ return;
995
1023
  await this.readNewEvents();
996
1024
  if (this.status !== AgentStatus.RUNNING && !this.completedAt) {
997
1025
  this.completedAt = this.getLatestEventTime() || this.startedAt || new Date();
@@ -1160,12 +1188,21 @@ export class AgentManager {
1160
1188
  defaultMode;
1161
1189
  initPromise = null;
1162
1190
  cloudDispatcher = null;
1191
+ /**
1192
+ * A `--local` caller (RUSH-2118): every poll this manager issues skips the
1193
+ * ssh round-trip for a distributed (remote-host) teammate, reporting its
1194
+ * last-persisted meta.json state instead. Set once at construction so the
1195
+ * INITIAL load in doInitialize()/loadExistingAgents() — which polls every
1196
+ * teammate before listRunning()/listAll() ever run — honors it too.
1197
+ */
1198
+ localOnly;
1163
1199
  constructorAgentsDir = null;
1164
- constructor(maxAgents = 50, agentsDir = null, defaultMode = null, filterByCwd = null, cleanupAgeDays = 7) {
1200
+ constructor(maxAgents = 50, agentsDir = null, defaultMode = null, filterByCwd = null, cleanupAgeDays = 7, localOnly = false) {
1165
1201
  this.maxAgents = maxAgents;
1166
1202
  this.constructorAgentsDir = agentsDir;
1167
1203
  this.filterByCwd = filterByCwd;
1168
1204
  this.cleanupAgeDays = cleanupAgeDays;
1205
+ this.localOnly = localOnly;
1169
1206
  const resolvedDefaultMode = defaultMode ? normalizeModeValue(defaultMode) : defaultModeFromEnv();
1170
1207
  if (!resolvedDefaultMode) {
1171
1208
  throw new Error(`Invalid default_mode '${defaultMode}'. Use plan, edit, auto, or skip.`);
@@ -1272,7 +1309,7 @@ export class AgentManager {
1272
1309
  continue;
1273
1310
  }
1274
1311
  }
1275
- await agent.updateStatusFromProcess();
1312
+ await agent.updateStatusFromProcess({ skipRemote: this.localOnly });
1276
1313
  this.agents.set(agentId, agent);
1277
1314
  loadedCount++;
1278
1315
  }
@@ -1726,7 +1763,14 @@ export class AgentManager {
1726
1763
  if (!teamMeta)
1727
1764
  return;
1728
1765
  const roster = await this.listByTask(taskName);
1729
- const { device } = resolvePlacement(teamMeta, null, roster);
1766
+ const pool = teamMeta.devices ?? [];
1767
+ const maxConcurrent = pool.length > 1 ? readMaxConcurrentCaps(pool) : undefined;
1768
+ if (maxConcurrent) {
1769
+ for (const c of cappedDevices(pool, roster, maxConcurrent)) {
1770
+ console.error(chalk.dim(`[placement] '${c.device}' excluded from auto-pick — at its agents.max-concurrent cap (${c.running}/${c.cap} running)`));
1771
+ }
1772
+ }
1773
+ const { device } = resolvePlacement(teamMeta, null, roster, { maxConcurrent });
1730
1774
  if (device)
1731
1775
  await this.resolveScheduledPlacement(agent, device, taskName);
1732
1776
  }
@@ -1990,8 +2034,8 @@ export class AgentManager {
1990
2034
  await this.initialize();
1991
2035
  const agents = Array.from(this.agents.values());
1992
2036
  for (const agent of agents) {
1993
- await agent.readNewEvents();
1994
- await agent.updateStatusFromProcess();
2037
+ await agent.readNewEvents({ skipRemote: this.localOnly });
2038
+ await agent.updateStatusFromProcess({ skipRemote: this.localOnly });
1995
2039
  }
1996
2040
  return agents;
1997
2041
  }
@@ -2,6 +2,19 @@
2
2
  export interface PlacementTeam {
3
3
  devices?: string[];
4
4
  }
5
+ /**
6
+ * Optional placement inputs beyond the team + roster. `maxConcurrent` maps a
7
+ * device name to its `agents.max-concurrent` cap (from the device doc — read
8
+ * locally via `readMaxConcurrentCaps`, never probed over SSH). Teams counts
9
+ * the team's OWN roster against the cap (device-global counting would need an
10
+ * SSH probe per candidate — out of the hot path; Factory auto-launch is the
11
+ * device-wide counter). Only the least-loaded AUTO-PICK (cascade step 3)
12
+ * honors caps: an explicit pin or a pool of one is the user's own choice and
13
+ * is never second-guessed.
14
+ */
15
+ export interface PlacementOptions {
16
+ maxConcurrent?: Record<string, number>;
17
+ }
5
18
  /**
6
19
  * A roster entry the load counter reads — the shape any teammate satisfies
7
20
  * (AgentProcess included). `status` is compared against `'running'` (the
@@ -11,19 +24,33 @@ export interface RosterEntry {
11
24
  hostName: string | null;
12
25
  status: string;
13
26
  }
27
+ /**
28
+ * Pool devices excluded from auto-pick because they are at (or over) their
29
+ * `agents.max-concurrent` cap. Returned with the live counts so the caller can
30
+ * state the reason to the user instead of the device silently never winning.
31
+ */
32
+ export declare function cappedDevices(devices: string[], roster: RosterEntry[], maxConcurrent: Record<string, number>): Array<{
33
+ device: string;
34
+ running: number;
35
+ cap: number;
36
+ }>;
14
37
  /**
15
38
  * Pick the least-loaded device from the pool — the one with the fewest RUNNING
16
39
  * teammates currently assigned to it. Ties break by pool order (first wins), so
17
40
  * an empty pool fills round-robin-ish as teammates launch. Pure: counts the
18
41
  * roster, no I/O.
42
+ *
43
+ * With `maxConcurrent`, devices at their cap are excluded; if EVERY device is
44
+ * capped this throws naming each cap and the fix — a loud failure beats a
45
+ * teammate silently landing on a machine its operator capped.
19
46
  */
20
- export declare function pickLeastLoaded(devices: string[], roster: RosterEntry[]): string;
47
+ export declare function pickLeastLoaded(devices: string[], roster: RosterEntry[], maxConcurrent?: Record<string, number>): string;
21
48
  /**
22
49
  * Resolve where a teammate runs. Returns `{ device: null }` for a local run
23
50
  * (no pin, no pool, or the chosen device is the local machine) and
24
51
  * `{ device: <name> }` for a remote placement. See the cascade in the module
25
52
  * header.
26
53
  */
27
- export declare function resolvePlacement(team: PlacementTeam, explicitDevice: string | null, roster: RosterEntry[]): {
54
+ export declare function resolvePlacement(team: PlacementTeam, explicitDevice: string | null, roster: RosterEntry[], opts?: PlacementOptions): {
28
55
  device: string | null;
29
56
  };
@@ -11,6 +11,11 @@
11
11
  * 3. else the team pool has many devices → least-loaded pick
12
12
  * 4. else (no pin, no pool) → null == run local
13
13
  *
14
+ * Step 3 is cap-aware: a device at its `agents.max-concurrent` cap (from the
15
+ * device doc, passed in via PlacementOptions) is excluded from the auto-pick,
16
+ * and an all-capped pool fails loud. Pins and pools of one are the user's own
17
+ * choice and are never second-guessed.
18
+ *
14
19
  * A device whose name equals the local machine id is treated as "local" — it
15
20
  * resolves to a null placement so the existing local spawn path runs unchanged,
16
21
  * letting the local machine participate in a pool as just another member.
@@ -20,31 +25,70 @@ import { machineId } from '../session/sync/config.js';
20
25
  function isLocalDevice(device) {
21
26
  return device.toLowerCase() === machineId();
22
27
  }
28
+ /** Count RUNNING teammates per pool device. Pure. A null/empty hostName is a
29
+ * LOCAL teammate — it counts against the pool member that is this machine,
30
+ * otherwise a cap on the local device could never engage. */
31
+ function loadByDevice(devices, roster) {
32
+ const load = new Map();
33
+ for (const d of devices)
34
+ load.set(d, 0);
35
+ for (const r of roster) {
36
+ if (r.status !== 'running')
37
+ continue;
38
+ const host = r.hostName ? r.hostName : devices.find((d) => isLocalDevice(d));
39
+ if (!host)
40
+ continue; // local teammate but this machine is not in the pool
41
+ if (load.has(host))
42
+ load.set(host, (load.get(host) ?? 0) + 1);
43
+ }
44
+ return load;
45
+ }
46
+ /**
47
+ * Pool devices excluded from auto-pick because they are at (or over) their
48
+ * `agents.max-concurrent` cap. Returned with the live counts so the caller can
49
+ * state the reason to the user instead of the device silently never winning.
50
+ */
51
+ export function cappedDevices(devices, roster, maxConcurrent) {
52
+ const load = loadByDevice(devices, roster);
53
+ const capped = [];
54
+ for (const d of devices) {
55
+ const cap = maxConcurrent[d];
56
+ if (cap === undefined)
57
+ continue;
58
+ const running = load.get(d) ?? 0;
59
+ if (running >= cap)
60
+ capped.push({ device: d, running, cap });
61
+ }
62
+ return capped;
63
+ }
23
64
  /**
24
65
  * Pick the least-loaded device from the pool — the one with the fewest RUNNING
25
66
  * teammates currently assigned to it. Ties break by pool order (first wins), so
26
67
  * an empty pool fills round-robin-ish as teammates launch. Pure: counts the
27
68
  * roster, no I/O.
69
+ *
70
+ * With `maxConcurrent`, devices at their cap are excluded; if EVERY device is
71
+ * capped this throws naming each cap and the fix — a loud failure beats a
72
+ * teammate silently landing on a machine its operator capped.
28
73
  */
29
- export function pickLeastLoaded(devices, roster) {
74
+ export function pickLeastLoaded(devices, roster, maxConcurrent) {
30
75
  if (devices.length === 0) {
31
76
  throw new Error('pickLeastLoaded called with an empty device pool');
32
77
  }
33
- const load = new Map();
34
- for (const d of devices)
35
- load.set(d, 0);
36
- for (const r of roster) {
37
- if (!r.hostName)
38
- continue;
39
- if (r.status !== 'running')
40
- continue;
41
- if (load.has(r.hostName))
42
- load.set(r.hostName, (load.get(r.hostName) ?? 0) + 1);
78
+ const load = loadByDevice(devices, roster);
79
+ const capped = new Set(maxConcurrent ? cappedDevices(devices, roster, maxConcurrent).map((c) => c.device) : []);
80
+ const eligible = devices.filter((d) => !capped.has(d));
81
+ if (eligible.length === 0) {
82
+ const detail = devices
83
+ .map((d) => `${d} (${load.get(d) ?? 0}/${maxConcurrent[d]})`)
84
+ .join(', ');
85
+ throw new Error(`Every device in the pool is at its agents.max-concurrent cap: ${detail}. ` +
86
+ `Raise a cap with 'agents devices configure <name> --max-agents N' or add a device to the pool.`);
43
87
  }
44
88
  // Iterate the pool in declared order so the first device wins ties.
45
- let best = devices[0];
89
+ let best = eligible[0];
46
90
  let bestLoad = load.get(best) ?? 0;
47
- for (const d of devices) {
91
+ for (const d of eligible) {
48
92
  const l = load.get(d) ?? 0;
49
93
  if (l < bestLoad) {
50
94
  best = d;
@@ -59,7 +103,7 @@ export function pickLeastLoaded(devices, roster) {
59
103
  * `{ device: <name> }` for a remote placement. See the cascade in the module
60
104
  * header.
61
105
  */
62
- export function resolvePlacement(team, explicitDevice, roster) {
106
+ export function resolvePlacement(team, explicitDevice, roster, opts) {
63
107
  // 1. Explicit pin wins — even without a pool.
64
108
  if (explicitDevice) {
65
109
  return { device: isLocalDevice(explicitDevice) ? null : explicitDevice };
@@ -72,7 +116,7 @@ export function resolvePlacement(team, explicitDevice, roster) {
72
116
  if (pool.length === 1) {
73
117
  return { device: isLocalDevice(pool[0]) ? null : pool[0] };
74
118
  }
75
- // 3. Many → least-loaded across the pool.
76
- const picked = pickLeastLoaded(pool, roster);
119
+ // 3. Many → least-loaded across the pool (cap-aware when caps are provided).
120
+ const picked = pickLeastLoaded(pool, roster, opts?.maxConcurrent);
77
121
  return { device: isLocalDevice(picked) ? null : picked };
78
122
  }
@@ -62,7 +62,7 @@ export interface BudgetConfig {
62
62
  require_confirm_over?: number;
63
63
  }
64
64
  /** Preview features that users can opt into via `agents beta`. */
65
- export type BetaFeatureName = 'drive' | 'factory' | 'session-sync' | 'projects';
65
+ export type BetaFeatureName = 'factory' | 'projects';
66
66
  /** Subset of chalk color names used for agent-specific terminal output. */
67
67
  export type ChalkColor = 'magenta' | 'green' | 'blue' | 'cyan' | 'yellowBright' | 'redBright' | 'whiteBright' | 'blueBright' | 'greenBright' | 'magentaBright' | 'cyanBright';
68
68
  /** Static configuration for a single agent -- paths, capabilities, and format conventions. */
@@ -845,6 +845,22 @@ export interface Meta {
845
845
  * `agents browser profiles set-default <name>`.
846
846
  */
847
847
  defaultBrowserProfile?: string;
848
+ /**
849
+ * User-scope config block (`config:` in central agents.yaml). Holds the
850
+ * user-scope keys from the device-config registry (`lib/device-config.ts`) —
851
+ * today just `interactiveHost`. Syncs fleet-wide via `agents repo push/pull`.
852
+ * Device-scope keys live in {@link Meta.deviceConfig} instead.
853
+ */
854
+ config?: Record<string, unknown>;
855
+ /**
856
+ * Device-scope config block, carried in memory under a distinct field so it
857
+ * can never leak into the central (synced) agents.yaml: `writeMetaUnlocked`
858
+ * routes it to `~/.agents/devices/<machine>/agents.yaml` under the `config:`
859
+ * key (mirroring how `defaultBrowserProfile` is routed), and
860
+ * `overlayMachineLocal` reads it back. Holds the device-scope keys from the
861
+ * device-config registry (`maxAgents`, `schedulerEnabled`, `notes`). Per-machine by design — unset = today's behavior.
862
+ */
863
+ deviceConfig?: Record<string, unknown>;
848
864
  /**
849
865
  * Agent-host registry keyed by host name (`agents hosts`). Portable user
850
866
  * config synced with `agents repo push/pull`. For `ssh-config` hosts this is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phnx-labs/agents-cli",
3
- "version": "1.20.93",
3
+ "version": "1.21.0",
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",
@@ -90,7 +90,6 @@
90
90
  "@xterm/headless": "6.0.0",
91
91
  "@zed-industries/agent-client-protocol": "0.4.5",
92
92
  "age-encryption": "0.3.0",
93
- "aws4fetch": "1.0.20",
94
93
  "chalk": "5.6.2",
95
94
  "commander": "15.0.0",
96
95
  "croner": "10.0.1",
@@ -1,10 +0,0 @@
1
- /**
2
- * Drive sync commands.
3
- *
4
- * Registers the `agents drive` command tree for syncing agent session
5
- * history across machines via rsync. Supports pull, push, attach
6
- * (redirect agent homes to drive), and detach operations.
7
- */
8
- import type { Command } from 'commander';
9
- /** Register the `agents drive` command tree. */
10
- export declare function registerDriveCommands(program: Command): void;