@phnx-labs/agents-cli 1.22.117 → 1.22.119

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 (271) hide show
  1. package/CHANGELOG.md +301 -0
  2. package/dist/bootstrap.js +4 -11
  3. package/dist/commands/accounts.js +7 -4
  4. package/dist/commands/browser.d.ts +52 -70
  5. package/dist/commands/browser.js +192 -3562
  6. package/dist/commands/daemon.d.ts +39 -2
  7. package/dist/commands/daemon.js +72 -73
  8. package/dist/commands/events.js +1 -1
  9. package/dist/commands/exec.js +53 -1
  10. package/dist/commands/projects.js +92 -7
  11. package/dist/commands/repo.js +13 -49
  12. package/dist/commands/route.js +5 -5
  13. package/dist/commands/routines.js +39 -12
  14. package/dist/commands/sessions-render.d.ts +1 -1
  15. package/dist/commands/sessions-render.js +0 -1
  16. package/dist/commands/sessions.test-fixture.d.ts +0 -1
  17. package/dist/commands/sessions.test-fixture.js +0 -37
  18. package/dist/commands/setup-browser.d.ts +17 -12
  19. package/dist/commands/setup-browser.js +52 -87
  20. package/dist/commands/setup-preferences.d.ts +0 -17
  21. package/dist/commands/setup-preferences.js +18 -49
  22. package/dist/commands/setup.js +9 -9
  23. package/dist/commands/ssh.js +10 -1
  24. package/dist/commands/sync.js +6 -44
  25. package/dist/commands/teams.js +0 -1
  26. package/dist/commands/update.d.ts +19 -0
  27. package/dist/commands/update.js +34 -6
  28. package/dist/commands/view.d.ts +12 -1
  29. package/dist/commands/view.js +47 -2
  30. package/dist/index.js +107 -26
  31. package/dist/lib/account-capabilities.js +0 -2
  32. package/dist/lib/account-catalog.d.ts +38 -0
  33. package/dist/lib/account-catalog.js +110 -26
  34. package/dist/lib/account-provider-registry.js +1 -1
  35. package/dist/lib/account-registry.d.ts +1 -1
  36. package/dist/lib/account-registry.js +36 -2
  37. package/dist/lib/accounting/rotate.js +22 -8
  38. package/dist/lib/accounting/usage-ingest.d.ts +6 -1
  39. package/dist/lib/accounting/usage-ingest.js +115 -45
  40. package/dist/lib/accounting/usage-sync.d.ts +134 -31
  41. package/dist/lib/accounting/usage-sync.js +227 -66
  42. package/dist/lib/accounting/usage.d.ts +16 -3
  43. package/dist/lib/accounting/usage.js +26 -8
  44. package/dist/lib/accounts/add.d.ts +3 -1
  45. package/dist/lib/accounts/add.js +24 -13
  46. package/dist/lib/accounts/slots.d.ts +8 -0
  47. package/dist/lib/accounts/slots.js +17 -0
  48. package/dist/lib/add-dir.js +0 -1
  49. package/dist/lib/agent-cli-commands.js +0 -1
  50. package/dist/lib/agent-spec/agents.d.ts +6 -7
  51. package/dist/lib/agent-spec/agents.js +7 -60
  52. package/dist/lib/auth-health.d.ts +69 -1
  53. package/dist/lib/auth-health.js +133 -4
  54. package/dist/lib/browser/context.d.ts +82 -0
  55. package/dist/lib/browser/context.js +88 -0
  56. package/dist/lib/browser/paths.d.ts +25 -0
  57. package/dist/lib/browser/paths.js +51 -0
  58. package/dist/lib/browser/record.d.ts +38 -0
  59. package/dist/lib/browser/record.js +57 -0
  60. package/dist/lib/browser/sessions-list.js +1 -2
  61. package/dist/lib/browser-client.d.ts +158 -0
  62. package/dist/lib/browser-client.js +234 -0
  63. package/dist/lib/channels/owner-sink.d.ts +1 -18
  64. package/dist/lib/channels/owner-sink.js +29 -82
  65. package/dist/lib/channels/providers/rush.d.ts +7 -7
  66. package/dist/lib/channels/providers/rush.js +127 -57
  67. package/dist/lib/claude-account-token.d.ts +7 -1
  68. package/dist/lib/claude-account-token.js +26 -4
  69. package/dist/lib/claude-statusline.d.ts +1 -1
  70. package/dist/lib/claude-statusline.js +15 -3
  71. package/dist/lib/commands.js +1 -1
  72. package/dist/lib/crabbox/lease.js +1 -1
  73. package/dist/lib/crabbox/runtimes.js +1 -3
  74. package/dist/lib/daemon/account-state-daemon-service.js +1 -0
  75. package/dist/lib/daemon/auth-sync-service.d.ts +21 -18
  76. package/dist/lib/daemon/auth-sync-service.js +37 -43
  77. package/dist/lib/daemon/daemon.d.ts +25 -14
  78. package/dist/lib/daemon/daemon.js +92 -154
  79. package/dist/lib/daemon/runner.d.ts +2 -2
  80. package/dist/lib/daemon/runner.js +32 -9
  81. package/dist/lib/daemon/self-update-service.d.ts +35 -34
  82. package/dist/lib/daemon/self-update-service.js +40 -36
  83. package/dist/lib/daemon/service.d.ts +12 -8
  84. package/dist/lib/daemon/supervisor.d.ts +65 -54
  85. package/dist/lib/daemon/supervisor.js +136 -171
  86. package/dist/lib/daemon/testdata/process-view-start.js +5 -2
  87. package/dist/lib/daemon/usage-sync-service.d.ts +21 -30
  88. package/dist/lib/daemon/usage-sync-service.js +46 -78
  89. package/dist/lib/daemon-health.d.ts +22 -5
  90. package/dist/lib/daemon-health.js +47 -3
  91. package/dist/lib/daemon-services.d.ts +1 -1
  92. package/dist/lib/daemon-services.js +0 -10
  93. package/dist/lib/daemon-ticks.js +4 -2
  94. package/dist/lib/devices/doctor-findings.js +8 -11
  95. package/dist/lib/devices/harness-inventory.js +14 -5
  96. package/dist/lib/exec-account-home.js +5 -0
  97. package/dist/lib/exec.js +10 -13
  98. package/dist/lib/feed/events.js +0 -1
  99. package/dist/lib/feed/tool-activity.js +5 -2
  100. package/dist/lib/fleet-shared-state.d.ts +45 -0
  101. package/dist/lib/fleet-shared-state.js +78 -9
  102. package/dist/lib/fs-atomic.js +25 -0
  103. package/dist/lib/github/pr-mergeable.d.ts +4 -2
  104. package/dist/lib/github/pr-mergeable.js +5 -3
  105. package/dist/lib/github/project-prs.d.ts +58 -3
  106. package/dist/lib/github/project-prs.js +205 -7
  107. package/dist/lib/harness/adapters/cursor.js +14 -4
  108. package/dist/lib/harness-auth-capabilities.d.ts +4 -3
  109. package/dist/lib/harness-auth-capabilities.js +1 -2
  110. package/dist/lib/helper-versions.js +1 -1
  111. package/dist/lib/hooks/cache.d.ts +7 -0
  112. package/dist/lib/hooks/cache.js +27 -2
  113. package/dist/lib/hooks/install.js +7 -1
  114. package/dist/lib/hosts/ready.d.ts +38 -8
  115. package/dist/lib/hosts/ready.js +62 -14
  116. package/dist/lib/installations/active-check.d.ts +27 -0
  117. package/dist/lib/installations/active-check.js +61 -0
  118. package/dist/lib/installations/migrate.js +6 -3
  119. package/dist/lib/installations/shims.d.ts +1 -1
  120. package/dist/lib/installations/shims.js +32 -12
  121. package/dist/lib/installations/store.d.ts +9 -0
  122. package/dist/lib/installations/store.js +24 -0
  123. package/dist/lib/installations/update.js +21 -15
  124. package/dist/lib/installations/versions.js +15 -3
  125. package/dist/lib/manifest.js +1 -1
  126. package/dist/lib/models.js +0 -2
  127. package/dist/lib/open-url.js +28 -54
  128. package/dist/lib/profiles.js +0 -2
  129. package/dist/lib/projects.d.ts +16 -0
  130. package/dist/lib/projects.js +31 -0
  131. package/dist/lib/refresh.js +1 -1
  132. package/dist/lib/routine-readiness.d.ts +35 -0
  133. package/dist/lib/routine-readiness.js +74 -16
  134. package/dist/lib/rules/compile.js +6 -0
  135. package/dist/lib/sandbox.js +0 -2
  136. package/dist/lib/secrets-policy.d.ts +89 -11
  137. package/dist/lib/secrets-policy.js +175 -28
  138. package/dist/lib/session/active.d.ts +17 -6
  139. package/dist/lib/session/active.js +105 -49
  140. package/dist/lib/session/db.d.ts +1 -1
  141. package/dist/lib/session/db.js +65 -18
  142. package/dist/lib/session/discover.js +1 -283
  143. package/dist/lib/session/mirror.d.ts +4 -3
  144. package/dist/lib/session/mirror.js +4 -3
  145. package/dist/lib/session/parse.d.ts +0 -2
  146. package/dist/lib/session/parse.js +1 -138
  147. package/dist/lib/session/pid-registry.d.ts +6 -3
  148. package/dist/lib/session/pid-registry.js +18 -8
  149. package/dist/lib/session/remote/watch.d.ts +1 -1
  150. package/dist/lib/session/remote/watch.js +7 -3
  151. package/dist/lib/session/throughput.d.ts +1 -3
  152. package/dist/lib/session/throughput.js +0 -20
  153. package/dist/lib/session/types.d.ts +2 -2
  154. package/dist/lib/session/types.js +2 -2
  155. package/dist/lib/sessions-client.d.ts +60 -1
  156. package/dist/lib/sessions-client.js +227 -4
  157. package/dist/lib/setup-tool-status.js +5 -10
  158. package/dist/lib/signin-badge.d.ts +3 -2
  159. package/dist/lib/signin-badge.js +6 -3
  160. package/dist/lib/smart-launch.js +4 -1
  161. package/dist/lib/staleness/detectors/commands.d.ts +1 -1
  162. package/dist/lib/staleness/detectors/hooks.d.ts +1 -1
  163. package/dist/lib/staleness/detectors/mcp.d.ts +1 -1
  164. package/dist/lib/staleness/detectors/permissions.d.ts +1 -1
  165. package/dist/lib/staleness/detectors/plugins.d.ts +1 -1
  166. package/dist/lib/staleness/detectors/rules.d.ts +1 -1
  167. package/dist/lib/staleness/detectors/skills.d.ts +1 -1
  168. package/dist/lib/staleness/detectors/subagents.d.ts +1 -1
  169. package/dist/lib/staleness/detectors/workflows.d.ts +1 -1
  170. package/dist/lib/staleness/writers/commands.d.ts +1 -1
  171. package/dist/lib/staleness/writers/hooks.d.ts +1 -1
  172. package/dist/lib/staleness/writers/mcp.d.ts +1 -1
  173. package/dist/lib/staleness/writers/permissions.d.ts +1 -1
  174. package/dist/lib/staleness/writers/plugins.d.ts +1 -1
  175. package/dist/lib/staleness/writers/rules.d.ts +1 -1
  176. package/dist/lib/staleness/writers/skills.d.ts +1 -1
  177. package/dist/lib/staleness/writers/sources.js +5 -0
  178. package/dist/lib/staleness/writers/subagents.d.ts +1 -1
  179. package/dist/lib/staleness/writers/workflows.d.ts +1 -1
  180. package/dist/lib/state.d.ts +6 -4
  181. package/dist/lib/state.js +7 -17
  182. package/dist/lib/teams/parsers.d.ts +1 -1
  183. package/dist/lib/teams/parsers.js +1 -136
  184. package/dist/lib/teams/placement-probe.js +50 -15
  185. package/dist/lib/teams/scheduler.d.ts +7 -0
  186. package/dist/lib/types.d.ts +16 -1
  187. package/dist/lib/types.js +1 -1
  188. package/dist/lib/view-types.d.ts +32 -0
  189. package/dist/lib/watchdog/read.js +0 -1
  190. package/dist/lib/watchdog/rotate.js +1 -2
  191. package/dist/lib/watchdog/runner.js +2 -2
  192. package/dist/lib/watchdog/watchdog.d.ts +1 -1
  193. package/dist/lib/watchdog/watchdogTail.js +0 -31
  194. package/package.json +1 -1
  195. package/scripts/postinstall.js +8 -8
  196. package/dist/browser.d.ts +0 -2
  197. package/dist/browser.js +0 -17
  198. package/dist/commands/browser-picker.d.ts +0 -18
  199. package/dist/commands/browser-picker.js +0 -97
  200. package/dist/lib/browser/arc-discovery.d.ts +0 -52
  201. package/dist/lib/browser/arc-discovery.js +0 -197
  202. package/dist/lib/browser/arc-dom.d.ts +0 -14
  203. package/dist/lib/browser/arc-dom.js +0 -121
  204. package/dist/lib/browser/caller-identity.d.ts +0 -40
  205. package/dist/lib/browser/caller-identity.js +0 -175
  206. package/dist/lib/browser/cdp.d.ts +0 -51
  207. package/dist/lib/browser/cdp.js +0 -254
  208. package/dist/lib/browser/chrome.d.ts +0 -141
  209. package/dist/lib/browser/chrome.js +0 -704
  210. package/dist/lib/browser/chromium-discovery.d.ts +0 -28
  211. package/dist/lib/browser/chromium-discovery.js +0 -96
  212. package/dist/lib/browser/devices.d.ts +0 -34
  213. package/dist/lib/browser/devices.js +0 -61
  214. package/dist/lib/browser/domain-skills.d.ts +0 -71
  215. package/dist/lib/browser/domain-skills.js +0 -195
  216. package/dist/lib/browser/drivers/arc.d.ts +0 -40
  217. package/dist/lib/browser/drivers/arc.js +0 -276
  218. package/dist/lib/browser/drivers/firefox.d.ts +0 -99
  219. package/dist/lib/browser/drivers/firefox.js +0 -377
  220. package/dist/lib/browser/drivers/local.d.ts +0 -55
  221. package/dist/lib/browser/drivers/local.js +0 -266
  222. package/dist/lib/browser/drivers/ssh.d.ts +0 -120
  223. package/dist/lib/browser/drivers/ssh.js +0 -467
  224. package/dist/lib/browser/editor.d.ts +0 -3
  225. package/dist/lib/browser/editor.js +0 -50
  226. package/dist/lib/browser/ffmpeg.d.ts +0 -12
  227. package/dist/lib/browser/ffmpeg.js +0 -184
  228. package/dist/lib/browser/firefox-discovery.d.ts +0 -69
  229. package/dist/lib/browser/firefox-discovery.js +0 -162
  230. package/dist/lib/browser/har.d.ts +0 -85
  231. package/dist/lib/browser/har.js +0 -77
  232. package/dist/lib/browser/hygiene.d.ts +0 -97
  233. package/dist/lib/browser/hygiene.js +0 -153
  234. package/dist/lib/browser/index.d.ts +0 -5
  235. package/dist/lib/browser/index.js +0 -5
  236. package/dist/lib/browser/input.d.ts +0 -7
  237. package/dist/lib/browser/input.js +0 -92
  238. package/dist/lib/browser/ipc.d.ts +0 -204
  239. package/dist/lib/browser/ipc.js +0 -1453
  240. package/dist/lib/browser/login-detection.d.ts +0 -87
  241. package/dist/lib/browser/login-detection.js +0 -274
  242. package/dist/lib/browser/profiles.d.ts +0 -422
  243. package/dist/lib/browser/profiles.js +0 -1157
  244. package/dist/lib/browser/refs.d.ts +0 -89
  245. package/dist/lib/browser/refs.js +0 -191
  246. package/dist/lib/browser/registry.d.ts +0 -70
  247. package/dist/lib/browser/registry.js +0 -252
  248. package/dist/lib/browser/remote-control.d.ts +0 -59
  249. package/dist/lib/browser/remote-control.js +0 -85
  250. package/dist/lib/browser/resolve-target.d.ts +0 -66
  251. package/dist/lib/browser/resolve-target.js +0 -264
  252. package/dist/lib/browser/runtime-state.d.ts +0 -291
  253. package/dist/lib/browser/runtime-state.js +0 -584
  254. package/dist/lib/browser/secret-ref.d.ts +0 -10
  255. package/dist/lib/browser/secret-ref.js +0 -14
  256. package/dist/lib/browser/service.d.ts +0 -812
  257. package/dist/lib/browser/service.js +0 -4693
  258. package/dist/lib/browser/stream.d.ts +0 -17
  259. package/dist/lib/browser/stream.js +0 -72
  260. package/dist/lib/browser/task-index.d.ts +0 -78
  261. package/dist/lib/browser/task-index.js +0 -199
  262. package/dist/lib/browser/types.d.ts +0 -647
  263. package/dist/lib/browser/types.js +0 -61
  264. package/dist/lib/browser/upload.d.ts +0 -29
  265. package/dist/lib/browser/upload.js +0 -298
  266. package/dist/lib/daemon/browser-ipc-service.d.ts +0 -20
  267. package/dist/lib/daemon/browser-ipc-service.js +0 -46
  268. package/dist/lib/daemon/browser-task-reap-service.d.ts +0 -14
  269. package/dist/lib/daemon/browser-task-reap-service.js +0 -26
  270. package/dist/lib/fleet-shared-repo-sync.d.ts +0 -55
  271. package/dist/lib/fleet-shared-repo-sync.js +0 -490
@@ -2,11 +2,12 @@
2
2
  * `agents daemon` — runtime, hosted services, and failure visibility for the
3
3
  * always-on daemon (RUSH-2354).
4
4
  *
5
- * The daemon holds the routines scheduler, the browser IPC server, and the
5
+ * The daemon holds the routines scheduler, the session/usage sync, and the
6
6
  * watchdog pass — but until this command group existed it had no user-facing
7
7
  * surface: no way to see it, restart it, or turn it off. The secrets broker
8
8
  * moved out of this daemon entirely with the standalone `secrets` engine
9
- * (PHNX-3989 OWN-1); `agents daemon status` only probes its reachability.
9
+ * (PHNX-3989 OWN-1), and the browser IPC server with the standalone `browser`
10
+ * CLI (PHNX-4101); `agents daemon status` only probes the broker's reachability.
10
11
  * `daemon.ts` (the runtime) has always implemented every mechanism this file
11
12
  * wires up; nothing here is new machinery, only the missing CLI surface.
12
13
  *
@@ -17,6 +18,42 @@
17
18
  * duplicating it.
18
19
  */
19
20
  import type { Command } from 'commander';
21
+ import { type SubsystemHealth } from '../lib/daemon-health.js';
20
22
  /** Elapsed wall-clock seconds since `pid` started, or null if unavailable (best-effort, POSIX only). */
21
23
  export declare function uptimeSeconds(pid: number): number | null;
24
+ interface SecretsBrokerHealth {
25
+ reachable: boolean;
26
+ /**
27
+ * True when this box routes `keychain`-backend items to the standalone's
28
+ * encrypted file store (a headless worker with no reachable keyring). The
29
+ * broker exists only to hold an UNLOCKED keychain across reads without a
30
+ * Touch ID prompt — a file-backed box reads every secret one-shot with no
31
+ * broker at all, so an absent broker there is normal, not a fault (PHNX-4116).
32
+ */
33
+ fileBacked: boolean;
34
+ /**
35
+ * Always `null` — the broker's socket now lives entirely inside the
36
+ * standalone `secrets` engine's own process (PHNX-3989 OWN-1); the daemon
37
+ * neither hosts it nor knows its transport details. Kept in the shape for
38
+ * `--json` compatibility.
39
+ */
40
+ socketPath: string | null;
41
+ heldBundles: number | null;
42
+ /**
43
+ * Always `null` — no daemon service writes a health record for the broker
44
+ * anymore (the daemon does not host or supervise it). Kept in the shape for
45
+ * `--json` compatibility.
46
+ */
47
+ record: SubsystemHealth | null;
48
+ }
49
+ /**
50
+ * The `secrets broker` health line. Reachable → healthy. Unreachable is a FAULT
51
+ * (`down`) only when the store is keychain-backed — there the broker is what
52
+ * holds the unlocked keychain across reads. On a file-backed box (every
53
+ * headless worker) no broker is needed: secrets read one-shot, so an absent
54
+ * broker is expected and reads as INFO, not `down` (PHNX-4116). Pure, so the
55
+ * three cases are unit-tested with no live daemon.
56
+ */
57
+ export declare function secretsBrokerHealthLine(secrets: SecretsBrokerHealth): string;
22
58
  export declare function registerDaemonCommand(program: Command): void;
59
+ export {};
@@ -2,11 +2,12 @@
2
2
  * `agents daemon` — runtime, hosted services, and failure visibility for the
3
3
  * always-on daemon (RUSH-2354).
4
4
  *
5
- * The daemon holds the routines scheduler, the browser IPC server, and the
5
+ * The daemon holds the routines scheduler, the session/usage sync, and the
6
6
  * watchdog pass — but until this command group existed it had no user-facing
7
7
  * surface: no way to see it, restart it, or turn it off. The secrets broker
8
8
  * moved out of this daemon entirely with the standalone `secrets` engine
9
- * (PHNX-3989 OWN-1); `agents daemon status` only probes its reachability.
9
+ * (PHNX-3989 OWN-1), and the browser IPC server with the standalone `browser`
10
+ * CLI (PHNX-4101); `agents daemon status` only probes the broker's reachability.
10
11
  * `daemon.ts` (the runtime) has always implemented every mechanism this file
11
12
  * wires up; nothing here is new machinery, only the missing CLI surface.
12
13
  *
@@ -21,10 +22,10 @@ import { execFileSync } from 'child_process';
21
22
  import * as fs from 'fs';
22
23
  import * as path from 'path';
23
24
  import { setHelpSections } from '../lib/help.js';
24
- import { getDaemonStatus, isDaemonRunning, isDaemonWedged, readDaemonLog, startDaemon, stopDaemon, signalDaemonReload, findSurvivingStateDirDaemons, getDaemonLogPath, isDaemonAutostartCircuitOpen, RedirectedHomeDaemonError, } from '../lib/daemon/daemon.js';
25
+ import { getDaemonStatus, isDaemonRunning, readDaemonLog, startDaemon, stopDaemon, signalDaemonReload, findSurvivingStateDirDaemons, getDaemonLogPath, isDaemonAutostartCircuitOpen, RedirectedHomeDaemonError, } from '../lib/daemon/daemon.js';
25
26
  import { listDaemonRunProcesses } from '../lib/daemon/leaked-daemons.js';
26
27
  import { getConfigValue, setConfigValue, isDaemonEnabled } from '../lib/device-config.js';
27
- import { readSubsystemHealth, readAllSubsystemHealth, SUBSYSTEM_BROWSER_IPC, SUBSYSTEM_DAEMON_START, } from '../lib/daemon-health.js';
28
+ import { readSubsystemHealth, readAllSubsystemHealth, SUBSYSTEM_DAEMON_START, } from '../lib/daemon-health.js';
28
29
  import { DAEMON_SERVICE_IDS, listDaemonServiceStates, setDaemonServiceEnabled, getDaemonServicesConfigPath, queueDaemonServiceRestart, } from '../lib/daemon-services.js';
29
30
  import { listJobs, getLatestRun } from '../lib/scheduling/routines.js';
30
31
  import { JobScheduler } from '../lib/scheduler.js';
@@ -293,25 +294,24 @@ function humanDuration(seconds) {
293
294
  }
294
295
  /** Reachability probe only — the daemon does not host, supervise, or take over the broker (OWN-1). */
295
296
  async function probeSecretsBroker() {
297
+ const { agentPing, agentStatus, keychainUsesFileFallback } = await import('../lib/secrets-client.js');
296
298
  try {
297
- const { agentPing, agentStatus } = await import('../lib/secrets-client.js');
298
299
  const ping = await agentPing();
299
- if (!ping.reachable)
300
- return { reachable: false, socketPath: null, heldBundles: null, record: null };
301
- const entries = await agentStatus();
302
- return { reachable: true, socketPath: null, heldBundles: entries.length, record: null };
300
+ if (ping.reachable) {
301
+ const entries = await agentStatus();
302
+ return { reachable: true, fileBacked: false, socketPath: null, heldBundles: entries.length, record: null };
303
+ }
303
304
  }
304
- catch {
305
- return { reachable: false, socketPath: null, heldBundles: null, record: null };
305
+ catch { /* fall through to the unreachable classification below */ }
306
+ // Unreachable: distinguish "broker needed and absent" (a keychain-backed box)
307
+ // from "no broker needed" (a file-backed worker reads secrets one-shot). An
308
+ // unknown store defaults to broker-needed, the louder verdict.
309
+ let fileBacked = false;
310
+ try {
311
+ fileBacked = await keychainUsesFileFallback();
306
312
  }
307
- }
308
- async function probeBrowserIPC() {
309
- const record = readSubsystemHealth(SUBSYSTEM_BROWSER_IPC);
310
- const { isBrowserServiceReachable, getSocketPath } = await import('../lib/browser/ipc.js');
311
- const { listAllProfileSnapshots } = await import('../lib/browser/runtime-state.js');
312
- const bound = await isBrowserServiceReachable();
313
- const sessionCount = listAllProfileSnapshots().filter((s) => s.pidAlive && s.daemonAlive).length;
314
- return { bound, socketPath: getSocketPath(), sessionCount, record };
313
+ catch { /* unknown → not file-backed */ }
314
+ return { reachable: false, fileBacked, socketPath: null, heldBundles: null, record: null };
315
315
  }
316
316
  function schedulerSummary() {
317
317
  const jobs = listJobs();
@@ -357,6 +357,23 @@ function healthLine(label, live, record) {
357
357
  : '';
358
358
  return ` ${chalk.red('down')} ${label} ${detail}`;
359
359
  }
360
+ /**
361
+ * The `secrets broker` health line. Reachable → healthy. Unreachable is a FAULT
362
+ * (`down`) only when the store is keychain-backed — there the broker is what
363
+ * holds the unlocked keychain across reads. On a file-backed box (every
364
+ * headless worker) no broker is needed: secrets read one-shot, so an absent
365
+ * broker is expected and reads as INFO, not `down` (PHNX-4116). Pure, so the
366
+ * three cases are unit-tested with no live daemon.
367
+ */
368
+ export function secretsBrokerHealthLine(secrets) {
369
+ if (secrets.reachable) {
370
+ return healthLine(`secrets broker (${secrets.socketPath}, ${secrets.heldBundles} bundle(s) held)`, true, secrets.record);
371
+ }
372
+ if (secrets.fileBacked) {
373
+ return ` ${chalk.cyan('info')} secrets agent not running (file-backed stores)`;
374
+ }
375
+ return healthLine('secrets broker (unreachable)', false, secrets.record);
376
+ }
360
377
  async function runStatus(opts) {
361
378
  const status = getDaemonStatus();
362
379
  const enabled = isDaemonEnabled();
@@ -378,7 +395,7 @@ async function runStatus(opts) {
378
395
  const staleTiers = staleDaemons(processes, pid ?? null, registeredPids);
379
396
  const stale = staleTiers.visible;
380
397
  const ownerEntryGone = owner ? entryIsGone(owner) : false;
381
- const [secrets, browserIpc] = await Promise.all([probeSecretsBroker(), probeBrowserIPC()]);
398
+ const secrets = await probeSecretsBroker();
382
399
  const scheduler = schedulerSummary();
383
400
  if (opts.json) {
384
401
  console.log(JSON.stringify({
@@ -386,6 +403,9 @@ async function runStatus(opts) {
386
403
  pid,
387
404
  uptimeSeconds: uptime,
388
405
  heartbeatAgeMs,
406
+ restarts24h: status.restarts24h,
407
+ lastRestartCause: status.lastRestartCause,
408
+ lastRestartAt: status.lastRestartAt,
389
409
  logPath: status.logPath,
390
410
  binaryPath: owner?.entry ?? status.binaryPath,
391
411
  binaryVersion: owner?.version ?? null,
@@ -409,12 +429,6 @@ async function runStatus(opts) {
409
429
  heldBundles: secrets.heldBundles,
410
430
  health: secrets.record,
411
431
  },
412
- browserIpc: {
413
- bound: browserIpc.bound,
414
- socketPath: browserIpc.socketPath,
415
- sessionCount: browserIpc.sessionCount,
416
- health: browserIpc.record,
417
- },
418
432
  },
419
433
  scheduler: {
420
434
  enabled: getConfigValue('scheduler.enabled').value !== false,
@@ -427,9 +441,8 @@ async function runStatus(opts) {
427
441
  return;
428
442
  }
429
443
  const stateLabel = state === 'running' ? chalk.green('running')
430
- : state === 'wedged' ? chalk.red('wedged')
431
- : state === 'disabled' ? chalk.yellow('disabled')
432
- : chalk.gray('stopped');
444
+ : state === 'disabled' ? chalk.yellow('disabled')
445
+ : chalk.gray('stopped');
433
446
  console.log(chalk.bold('Identity\n'));
434
447
  console.log(` State: ${stateLabel}`);
435
448
  if (pid)
@@ -438,6 +451,12 @@ async function runStatus(opts) {
438
451
  console.log(` Uptime: ${humanDuration(uptime)}`);
439
452
  if (heartbeatAgeMs !== null)
440
453
  console.log(` Heartbeat: ${Math.round(heartbeatAgeMs / 1000)}s ago`);
454
+ if (status.restarts24h > 0) {
455
+ const when = status.lastRestartAt ? ` (last ${new Date(status.lastRestartAt).toLocaleString()})` : '';
456
+ console.log(` Restarts: ${status.restarts24h} in the last 24h${when}`);
457
+ if (status.lastRestartCause)
458
+ console.log(` Last cause: ${chalk.gray(status.lastRestartCause)}`);
459
+ }
441
460
  const binaryLabel = owner?.entry ?? status.binaryPath ?? 'unknown';
442
461
  console.log(` Binary: ${ownerEntryGone ? chalk.red(`${binaryLabel} (MISSING from disk)`) : chalk.gray(binaryLabel)}`);
443
462
  console.log(` Version: ${chalk.gray(owner?.version ?? 'unknown')}`);
@@ -476,17 +495,13 @@ async function runStatus(opts) {
476
495
  console.log(chalk.gray('\n Only one install should own the daemon. Stop the stray(s): kill <pid>'));
477
496
  }
478
497
  console.log(chalk.bold('\nHealth\n'));
479
- console.log(healthLine(`secrets broker ${secrets.reachable ? `(${secrets.socketPath}, ${secrets.heldBundles} bundle(s) held)` : '(unreachable)'}`, secrets.reachable, secrets.record));
480
- console.log(healthLine(`browser IPC ${browserIpc.bound ? `(${browserIpc.socketPath}, ${browserIpc.sessionCount} session(s))` : '(unbound)'}`, browserIpc.bound, browserIpc.record));
498
+ console.log(secretsBrokerHealthLine(secrets));
481
499
  const schedulerEnabled = getConfigValue('scheduler.enabled').value !== false;
482
500
  console.log(` ${schedulerEnabled ? chalk.green('enabled') : chalk.yellow('disabled')} scheduler — ${scheduler.enabledCount}/${scheduler.routineCount} routine(s) enabled` +
483
501
  (scheduler.nextFire ? `, next ${scheduler.nextFire.toLocaleString()}` : ''));
484
502
  if (scheduler.failingCount > 0) {
485
503
  console.log(chalk.red(` ${scheduler.failingCount} routine(s) failing their last run — see: agents routines stats`));
486
504
  }
487
- if (state === 'wedged') {
488
- console.log(chalk.red('\nThe daemon is wedged (heartbeat stale). Restart: agents daemon restart'));
489
- }
490
505
  }
491
506
  /**
492
507
  * Combine the persisted enable/disable toggles with whatever health the
@@ -503,8 +518,8 @@ function buildServiceRows(daemonRunning) {
503
518
  // A persisted supervisor state (health.json) is only trustworthy while the
504
519
  // daemon is actually up. If it is not running (crash / kill -9 / never
505
520
  // started), every service is stopped no matter what the last-written record
506
- // says — trusting a stale 'running'/'parked'/'idle' here would print a
507
- // report that contradicts the live-probed socket rows below (RUSH-2368).
521
+ // says — trusting a stale 'running'/'idle' here would print a report that
522
+ // contradicts the live-probed socket rows below (RUSH-2368).
508
523
  const state = daemonRunning
509
524
  ? (h?.state ?? (s.enabled ? 'running (unsupervised)' : 'stopped'))
510
525
  : 'stopped';
@@ -524,8 +539,6 @@ function buildServiceRows(daemonRunning) {
524
539
  function serviceStateLabel(state) {
525
540
  if (state === 'running')
526
541
  return chalk.green('running');
527
- if (state === 'parked')
528
- return chalk.red('parked');
529
542
  if (state === 'stopped')
530
543
  return chalk.gray('stopped');
531
544
  if (state === 'idle')
@@ -533,13 +546,12 @@ function serviceStateLabel(state) {
533
546
  return chalk.yellow(state); // 'running (unsupervised)' or any future label
534
547
  }
535
548
  async function runServices(opts) {
536
- const [secrets, browserIpc] = await Promise.all([probeSecretsBroker(), probeBrowserIPC()]);
549
+ const secrets = await probeSecretsBroker();
537
550
  const rows = buildServiceRows(isDaemonRunning());
538
551
  if (opts.json) {
539
552
  console.log(JSON.stringify({
540
553
  // Existing fields — unchanged shape, agents/CI consume these directly.
541
554
  secretsBroker: { reachable: secrets.reachable, socketPath: secrets.socketPath, heldBundles: secrets.heldBundles, health: secrets.record },
542
- browserIpc: { bound: browserIpc.bound, socketPath: browserIpc.socketPath, sessionCount: browserIpc.sessionCount, health: browserIpc.record },
543
555
  // Additive: every registered service, supervised or legacy.
544
556
  services: rows,
545
557
  }, null, 2));
@@ -554,8 +566,7 @@ async function runServices(opts) {
554
566
  console.log(chalk.gray(` last-error: ${row.lastError}`));
555
567
  }
556
568
  console.log(chalk.bold('\nHosted sockets\n'));
557
- console.log(healthLine(`secrets broker ${secrets.reachable ? `(${secrets.socketPath}, ${secrets.heldBundles} bundle(s) held)` : '(unreachable)'}`, secrets.reachable, secrets.record));
558
- console.log(healthLine(`browser IPC ${browserIpc.bound ? `(${browserIpc.socketPath}, ${browserIpc.sessionCount} session(s))` : '(unbound)'}`, browserIpc.bound, browserIpc.record));
569
+ console.log(secretsBrokerHealthLine(secrets));
559
570
  console.log(chalk.gray('\nScheduled routines run through `agents routines` — see: agents routines stats'));
560
571
  console.log(chalk.gray('agents daemon services enable|disable|restart <id> apply live for supervised services.'));
561
572
  }
@@ -633,8 +644,6 @@ async function runDoctor(opts) {
633
644
  const problems = [];
634
645
  if (!status.running && enabled)
635
646
  problems.push('Daemon is not running. Start it: agents daemon start');
636
- if (status.running && isDaemonWedged())
637
- problems.push('Daemon is wedged (heartbeat stale). Restart: agents daemon restart');
638
647
  // RUSH-2418: an open auto-start circuit breaker is the FIRST thing to report
639
648
  // for a stopped daemon — otherwise the only advice is "agents daemon start",
640
649
  // which is the exact action the breaker just refused, with no hint that a
@@ -672,12 +681,6 @@ async function runDoctor(opts) {
672
681
  if (secrets.record && secrets.record.consecutiveFailures > 0) {
673
682
  problems.push(`Secrets broker has ${secrets.record.consecutiveFailures} consecutive failure(s): ${secrets.record.lastError}`);
674
683
  }
675
- const browserIpc = await probeBrowserIPC();
676
- if (!browserIpc.bound)
677
- problems.push('Browser IPC is unbound.');
678
- if (browserIpc.record && browserIpc.record.consecutiveFailures > 0) {
679
- problems.push(`Browser IPC has ${browserIpc.record.consecutiveFailures} consecutive failure(s): ${browserIpc.record.lastError}`);
680
- }
681
684
  const scheduler = schedulerSummary();
682
685
  if (scheduler.failingCount > 0) {
683
686
  problems.push(`${scheduler.failingCount} routine(s) failing their last run. See: agents routines stats`);
@@ -841,7 +844,7 @@ function runWebhooksList(json) {
841
844
  export function registerDaemonCommand(program) {
842
845
  const cmd = program
843
846
  .command('daemon')
844
- .description('The always-on daemon: browser IPC, watchdog, and the routines scheduler. Bare `agents daemon` shows status.')
847
+ .description('The always-on daemon: watchdog, session/usage sync, and the routines scheduler. Bare `agents daemon` shows status.')
845
848
  .option('--json', 'Emit as JSON')
846
849
  .action(async (opts, command) => {
847
850
  await runStatus({ json: command.optsWithGlobals().json === true });
@@ -870,12 +873,12 @@ export function registerDaemonCommand(program) {
870
873
  agents daemon services
871
874
 
872
875
  # Toggle or restart a service live — applies without a daemon restart
873
- # for supervisor-managed services (browser-ipc, account-state,
874
- # session-index, monitors' off-transition, watchdog, device-probe,
875
- # self-heal, state-dir-check)
876
- agents daemon services disable browser-ipc
877
- agents daemon services enable browser-ipc
878
- agents daemon services restart browser-ipc
876
+ # for supervisor-managed services (account-state, session-index,
877
+ # monitors' off-transition, watchdog, device-probe, self-heal,
878
+ # state-dir-check)
879
+ agents daemon services disable account-state
880
+ agents daemon services enable account-state
881
+ agents daemon services restart account-state
879
882
 
880
883
  # Host a signed webhook receiver here, supervised and restarted on crash
881
884
  agents daemon webhooks add --secrets-bundle linear-webhook
@@ -912,12 +915,10 @@ export function registerDaemonCommand(program) {
912
915
 
913
916
  'agents daemon services enable|disable|restart <id>' applies live (no
914
917
  daemon restart) for supervisor-managed services that were registered at
915
- boot. browser-ipc is also registered while disabled, specifically so a
916
- browser client can enable it live. The inline scheduler re-evaluates its
917
- toggle on every reload as well. A boot-disabled service other than
918
- browser-ipc, the monitor on-transition, and webhook-receiver still need an
919
- operator 'agents daemon restart'. 'agents daemon services' names which
920
- case you're in per row.
918
+ boot. The inline scheduler re-evaluates its toggle on every reload as
919
+ well. A boot-disabled service other than the monitor on-transition and
920
+ webhook-receiver still needs an operator 'agents daemon restart'. 'agents
921
+ daemon services' names which case you're in per row.
921
922
  `,
922
923
  });
923
924
  cmd.command('status')
@@ -1033,16 +1034,15 @@ export function registerDaemonCommand(program) {
1033
1034
  agents daemon services list
1034
1035
 
1035
1036
  # Toggle or restart live — no daemon restart for a supervisor-managed
1036
- # service (browser-ipc, account-state, session-index)
1037
- agents daemon services disable browser-ipc
1038
- agents daemon services enable browser-ipc
1039
- agents daemon services restart browser-ipc
1037
+ # service (account-state, session-index)
1038
+ agents daemon services disable account-state
1039
+ agents daemon services enable account-state
1040
+ agents daemon services restart account-state
1040
1041
  `,
1041
1042
  notes: `
1042
1043
  A service disabled at daemon boot is normally not registered on the
1043
- supervisor, so enabling it needs an operator restart. browser-ipc is the
1044
- exception: it is registered stopped and can be enabled live. The inline
1045
- scheduler also applies enable/disable on reload; webhook-receiver and the
1044
+ supervisor, so enabling it needs an operator restart. The inline
1045
+ scheduler applies enable/disable on reload; webhook-receiver and the
1046
1046
  monitor on-transition still require 'agents daemon restart'. Each row in
1047
1047
  the plain-text view names which case it is; 'supervised: true/false' does
1048
1048
  the same in --json.
@@ -1077,9 +1077,8 @@ export function registerDaemonCommand(program) {
1077
1077
  * Apply an enable/disable toggle live (RUSH-3193 P4): persist it, then signal
1078
1078
  * the running daemon to reload — its handler diffs the toggle and drives
1079
1079
  * `supervisor.start/stop(id)` for a supervised service, so no restart is
1080
- * needed for supervisor-managed services registered at boot. browser-ipc is
1081
- * registered even when disabled so it can be enabled live; the inline
1082
- * scheduler also re-evaluates its toggle on reload. webhook-receiver,
1080
+ * needed for supervisor-managed services registered at boot. The inline
1081
+ * scheduler re-evaluates its toggle on reload. webhook-receiver,
1083
1082
  * monitors' on-transition, and other boot-disabled services still need a
1084
1083
  * deliberate operator restart — the daemon's own reload log says so.
1085
1084
  */
@@ -203,7 +203,7 @@ export function addEventsReadOptions(command) {
203
203
  .option('--command <path>', 'Only this command path — prefix match (e.g. "teams create")')
204
204
  .option('--event <type>', 'Only this typed event (repeatable, e.g. secrets.get, run.dispatched, pr.opened)', collect, [])
205
205
  .option('--agent <name>', 'Only events tagged with this agent')
206
- .option('--caller <kind>', 'Only this caller kind (claude-code, codex, gemini, cursor, terminal, script)')
206
+ .option('--caller <kind>', 'Only this caller kind (claude-code, codex, cursor, terminal, script)')
207
207
  .option('--level <level>', 'Only this level: audit, warn, info, debug')
208
208
  .option('--session <id>', 'Only events from this session (the provenance sessionId) — e.g. trace which session read a secret')
209
209
  .option('--bundle <name>', 'Only events carrying this bundle in their payload — e.g. `--module secrets --bundle share` for every read of the share bundle')
@@ -17,6 +17,7 @@ import { parseLoopInterval } from '../lib/loop.js';
17
17
  import { AGENTS, resolveAgentName, isAgentHardDeprecated, hardDeprecationError } from '../lib/agents.js';
18
18
  import { parseAgentVersionSpec } from '../lib/agent-spec/agents.js';
19
19
  import { recordDispatchedRun } from '../lib/audit/log.js';
20
+ import { recordRunAuthOutcome } from '../lib/auth-health.js';
20
21
  import { maybeShowStarNudge } from '../lib/star-nudge.js';
21
22
  import { warnUnpushedWork, shouldWarnUnpushed } from '../lib/warn-unpushed.js';
22
23
  import { warnOrphanedOpenPr } from '../lib/pr-land-detach.js';
@@ -2681,6 +2682,37 @@ agents run auto --device yosemite-s0 "fix the flaky test" # pin the device
2681
2682
  // the only `continue` is the preflight exhaustion handoff below, which
2682
2683
  // consumes one entry of the `--fallback` spec before retrying as that
2683
2684
  // alternate. The spec is finite, so this terminates (PHNX-3999 F19).
2685
+ // A balanced pick or the no-fresh-usage picker returns a CANDIDATE. Since
2686
+ // PHNX-3940 a native candidate is a registered account SLOT, not the
2687
+ // version home the executable lives in, so the spawn must resolve that
2688
+ // slot (home + durable env) through the canonical local launch resolver.
2689
+ // Without this the run launched the version home and whichever login it
2690
+ // held: on yosemite-m0 (2026-09-23) the picker chose trp and Claude
2691
+ // started as a different account in its first-run wizard. A remote run
2692
+ // re-resolves on the peer, which runs this same code locally.
2693
+ const applyPickedCandidate = async (candidate) => {
2694
+ if (!candidate.nativeAccount || options.host || options.device)
2695
+ return;
2696
+ const { resolveLocalAccountLaunch } = await import('../lib/accounting/account-launch.js');
2697
+ try {
2698
+ launchAccount = await resolveLocalAccountLaunch({
2699
+ agent,
2700
+ executableVersion: version ?? candidate.version,
2701
+ candidate,
2702
+ useDefault: false,
2703
+ });
2704
+ }
2705
+ catch (err) {
2706
+ console.error(chalk.red(err.message));
2707
+ process.exit(1);
2708
+ }
2709
+ if (launchAccount.execHome)
2710
+ execHome = launchAccount.execHome;
2711
+ if (launchAccount.configVersion)
2712
+ accountConfigVersion = launchAccount.configVersion;
2713
+ if (Object.keys(launchAccount.env).length > 0)
2714
+ accountEnv = { ...accountEnv, ...launchAccount.env };
2715
+ };
2684
2716
  preflight: for (;;) {
2685
2717
  if (!accountPickerRequested && !configuredAccount && (!version || strategy !== 'pinned' || options.balanced || explicitStrategy)) {
2686
2718
  if (version) {
@@ -2818,6 +2850,7 @@ agents run auto --device yosemite-s0 "fix the flaky test" # pin the device
2818
2850
  // Keep the rotation so mid-run failover can still cascade across
2819
2851
  // the other (stale) healthy accounts after a real rejection.
2820
2852
  rotationResult = resolved.rotation;
2853
+ await applyPickedCandidate(selected);
2821
2854
  if (!options.quiet) {
2822
2855
  const identity = selected.accountLabel || 'signed-in account';
2823
2856
  process.stderr.write(chalk.gray(`[agents] no fresh usage for any ${agent} account — you picked ${identity} · ${agent}@${selected.version}\n`));
@@ -2836,12 +2869,13 @@ agents run auto --device yosemite-s0 "fix the flaky test" # pin the device
2836
2869
  if (resolved.rotation) {
2837
2870
  launchSignedIn = resolved.rotation.picked.signedIn;
2838
2871
  launchEmail = resolved.rotation.picked.email;
2872
+ await applyPickedCandidate(resolved.rotation.picked);
2839
2873
  }
2840
2874
  // A balanced/available pick of a PROVIDER account (setup-token /
2841
2875
  // API-key) carries `providerAccount`. Resolve its env through the
2842
2876
  // same `resolveSpawnAccount` path an explicit `--account` uses, so
2843
2877
  // exec injects the credential; a native pick has no providerAccount
2844
- // and runs from its own version home unchanged (RUSH-3182).
2878
+ // and resolved its slot home in applyPickedCandidate above.
2845
2879
  const pickedProviderAccount = resolved.rotation?.picked.providerAccount;
2846
2880
  if (pickedProviderAccount) {
2847
2881
  try {
@@ -3561,6 +3595,24 @@ agents run auto --device yosemite-s0 "fix the flaky test" # pin the device
3561
3595
  // Governance chokepoint (#347): every dispatched run finalizes here.
3562
3596
  // ONE tamper-evident audit record per run — non-fatal by contract.
3563
3597
  recordDispatchedRun({ agent: ranAgent, version: ranVersion ?? 'unknown', mode, cwd, exitCode });
3598
+ // A clean headless exit is real auth evidence — the account authenticated
3599
+ // and produced a result. Record it as the per-account FACT `agents view`
3600
+ // renders (`last used ok`), keyed to the slot the run used so it lands on
3601
+ // the right row and clears any stale failure fact (PHNX-4116). A non-zero
3602
+ // exit is NOT recorded as an auth failure: the exit code alone does not
3603
+ // prove the token was rejected (a task can fail for a hundred reasons), and
3604
+ // a lying "auth failure" fact is worse than none. Real auth failures are
3605
+ // recorded where they are actually detected (the routine runner's
3606
+ // isAuthFailureFromLog sites) and by the daemon probe.
3607
+ if (exitCode === 0) {
3608
+ recordRunAuthOutcome({
3609
+ agent: ranAgent,
3610
+ accountId: execOptions.accountId ?? null,
3611
+ version: ranVersion ?? null,
3612
+ home: execHome ?? null,
3613
+ outcome: { ok: true },
3614
+ });
3615
+ }
3564
3616
  // First-successful-run star nudge (one-time, non-nagging). Only on a
3565
3617
  // clean run, and never when output is machine-readable/quiet.
3566
3618
  if (exitCode === 0)
@@ -30,7 +30,8 @@ import { checkRepoSlug } from '../lib/project-doctor.js';
30
30
  import { formatFocusAreas, readFocusAreas } from '../lib/project-focus.js';
31
31
  import { formatVerdict, scheduleVerdict } from '../lib/project-schedule.js';
32
32
  import { buildLinearImportCandidates, validateImportOpts, } from '../lib/project-import.js';
33
- import { buildProjectPrs } from '../lib/github/project-prs.js';
33
+ import { buildProjectPrs, mergeProjectPr, resolveTargetSlugs, MERGE_METHODS } from '../lib/github/project-prs.js';
34
+ import { ghExec } from '../lib/github/pr-mergeable.js';
34
35
  /** Recursion guard: a peer answering a probe fan-out never re-fans-out itself. */
35
36
  const PROJECTS_NO_FANOUT_ENV = 'AGENTS_PROJECTS_LOCAL';
36
37
  /** Max peers named in the skipped note before the rest collapse to `+N`. */
@@ -820,9 +821,14 @@ export function registerProjectsCommands(program) {
820
821
  await runProjectCard(name, opts, mode);
821
822
  });
822
823
  // ---- prs ----
824
+ // `list` is the default so `prs <name>` keeps its shape; a bare parent with
825
+ // no options of its own is what lets `prs merge` own --repo/--number/--json.
823
826
  const prsCmd = projects
824
- .command('prs <name>')
825
- .description('Every OPEN pull request across a project\'s attached repos (drafts included, no author filter).')
827
+ .command('prs')
828
+ .description('A project\'s open pull requests: list them (default), or merge one.');
829
+ const prsListCmd = prsCmd
830
+ .command('list <name>', { isDefault: true })
831
+ .description('Every OPEN pull request across a project\'s attached repos (drafts included, no author filter), scoped to this project\'s paths in a shared repo.')
826
832
  .option('--json', 'Machine-readable output (the AGI Menu contract shape)')
827
833
  .option('--repo <owner/repo>', 'Restrict to one of the project\'s attached repos')
828
834
  .option('--number <n>', 'Lazy detail: enrich exactly this PR with checks + reviewDecision (requires --repo)')
@@ -849,7 +855,7 @@ export function registerProjectsCommands(program) {
849
855
  }
850
856
  let envelope;
851
857
  try {
852
- envelope = await buildProjectPrs(def, { repo: opts.repo, number }, undefined);
858
+ envelope = await buildProjectPrs(def, { repo: opts.repo, number }, undefined, listProjectDefs());
853
859
  }
854
860
  catch (e) {
855
861
  // A restriction error (repo not attached) is a hard, up-front failure —
@@ -875,7 +881,8 @@ export function registerProjectsCommands(program) {
875
881
  console.log(`${chalk.bold(r.slug)} ${chalk.dim(`${r.pullRequests.length} open`)}`);
876
882
  for (const pr of r.pullRequests) {
877
883
  const draft = pr.isDraft ? chalk.gray(' [draft]') : '';
878
- console.log(` #${pr.number}${draft} ${pr.title} ${chalk.gray(`@${pr.author.login} · ${pr.headRefName}`)}`);
884
+ const wide = pr.scope === 'repo-wide' ? chalk.gray(' [repo-wide]') : '';
885
+ console.log(` #${pr.number}${draft}${wide} ${pr.title} ${chalk.gray(`@${pr.author.login} · ${pr.headRefName}`)}`);
879
886
  }
880
887
  }
881
888
  if (envelope.partial) {
@@ -886,11 +893,81 @@ export function registerProjectsCommands(program) {
886
893
  if (envelope.partial)
887
894
  process.exit(1);
888
895
  });
896
+ const mergeCmd = prsCmd
897
+ .command('merge <name>')
898
+ .description('Merge one open PR of a project, pinned to the head SHA you reviewed.')
899
+ .requiredOption('--repo <owner/repo>', 'One of the project\'s attached repos')
900
+ .requiredOption('--number <n>', 'The PR number')
901
+ .requiredOption('--sha <head-sha>', 'The head SHA you reviewed; GitHub refuses if the branch moved since')
902
+ .option('--method <method>', `${MERGE_METHODS.join(' | ')} (default: the first the repo allows, in that order)`)
903
+ .option('--json', 'Machine-readable result')
904
+ .action(async (name, opts) => {
905
+ const def = loadProjectDef(name);
906
+ if (!def) {
907
+ console.error(chalk.red(`No project named "${name}". List them: agents projects list`));
908
+ process.exit(1);
909
+ }
910
+ const raw = opts.number.trim();
911
+ const number = /^\d+$/.test(raw) ? Number.parseInt(raw, 10) : NaN;
912
+ if (!Number.isSafeInteger(number) || number <= 0) {
913
+ console.error(chalk.red(`--number expects a positive integer, got "${opts.number}".`));
914
+ process.exit(1);
915
+ }
916
+ if (!/^[0-9a-f]{7,40}$/i.test(opts.sha.trim())) {
917
+ console.error(chalk.red(`--sha expects a commit SHA, got "${opts.sha}".`));
918
+ process.exit(1);
919
+ }
920
+ if (opts.method !== undefined && !MERGE_METHODS.includes(opts.method)) {
921
+ console.error(chalk.red(`--method expects one of ${MERGE_METHODS.join(', ')}, got "${opts.method}".`));
922
+ process.exit(1);
923
+ }
924
+ let repo;
925
+ try {
926
+ [repo] = await resolveTargetSlugs(def, opts.repo, ghExec);
927
+ }
928
+ catch (e) {
929
+ console.error(chalk.red(e instanceof Error ? e.message : String(e)));
930
+ process.exit(1);
931
+ }
932
+ const result = await mergeProjectPr(repo, number, opts.sha.trim(), opts.method);
933
+ if (opts.json) {
934
+ console.log(JSON.stringify(result, null, 2));
935
+ }
936
+ else if (result.merged) {
937
+ console.log(`${chalk.green('Merged')} ${repo}#${number} (${result.method}) ${chalk.gray(result.sha ?? '')}`);
938
+ }
939
+ else {
940
+ console.error(chalk.red(`Not merged: ${repo}#${number}: ${result.message}`));
941
+ }
942
+ if (!result.merged)
943
+ process.exit(1);
944
+ });
945
+ setHelpSections(mergeCmd, {
946
+ examples: `
947
+ agents projects prs rush --json --repo phnx-labs/agi-cli --number 3646 # read headSha + mergeableState
948
+ agents projects prs merge rush --repo phnx-labs/agi-cli --number 3646 --sha <headSha>
949
+ agents projects prs merge rush --repo phnx-labs/agi-cli --number 3646 --sha <headSha> --method squash --json
950
+ `,
951
+ notes: `
952
+ The merge is a single REST call pinned to --sha: if anything was pushed after
953
+ you read the PR, GitHub refuses and nothing merges. Branch protection, required
954
+ checks and reviews stay GitHub's to enforce; a refusal exits 1 with GitHub's
955
+ message (merged: false in --json).
956
+ `,
957
+ });
889
958
  setHelpSections(prsCmd, {
890
959
  examples: `
960
+ agents projects prs rush --json # every open PR across rush's repos (= prs list rush)
961
+ agents projects prs rush --json --repo phnx-labs/agi-cli --number 3646 # one PR, with checks + mergeability
962
+ agents projects prs merge rush --repo phnx-labs/agi-cli --number 3646 --sha <headSha>
963
+ `,
964
+ });
965
+ setHelpSections(prsListCmd, {
966
+ examples: `
891
967
  agents projects prs rush --json # every open PR across rush's repos
892
968
  agents projects prs rush --json --repo phnx-labs/agi-cli
893
- agents projects prs rush --json --repo phnx-labs/agi-cli --number 3646 # one PR, with checks + review
969
+ agents projects prs rush --json --repo phnx-labs/agi-cli --number 3646 # one PR, with checks + review + mergeability
970
+ agents projects prs merge rush --repo phnx-labs/agi-cli --number 3646 --sha <headSha>
894
971
  `,
895
972
  notes: `
896
973
  Repos come from the project definition's attached repos only (repo + repos[].slug);
@@ -898,7 +975,15 @@ export function registerProjectsCommands(program) {
898
975
 
899
976
  The list is read from GitHub over REST and paginated in full, drafts included,
900
977
  with no author filter. checks and reviewDecision are null in the list; --number
901
- enriches exactly that one PR against its live head SHA.
978
+ enriches exactly that one PR against its live head SHA, with mergeable and
979
+ mergeableState.
980
+
981
+ A repository attached to several projects (a monorepo) is scoped by the paths
982
+ each project claims, the same rule that attributes a session's cwd: a
983
+ defaultPath narrowed under root, or a repos[] subpath. A PR is listed when it
984
+ touches this project's paths (scope: project) or no sharing project's paths
985
+ (scope: repo-wide). Changed files are cached per head SHA, so only a new push
986
+ costs a read.
902
987
 
903
988
  A repository whose fetch fails is reported with an error and marks the result
904
989
  partial (JSON reports errors per repository; text mode exits non-zero).