@phnx-labs/agents-cli 1.22.83 → 1.22.85

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 (291) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/README.md +80 -53
  3. package/dist/bootstrap.d.ts +7 -6
  4. package/dist/bootstrap.js +20 -27
  5. package/dist/cli/command-registry.js +5 -1
  6. package/dist/commands/accounts.d.ts +6 -13
  7. package/dist/commands/accounts.js +330 -143
  8. package/dist/commands/apply.js +1 -1
  9. package/dist/commands/auth-mint.d.ts +7 -3
  10. package/dist/commands/auth-mint.js +21 -9
  11. package/dist/commands/auth.js +2 -3
  12. package/dist/commands/browser.js +10 -10
  13. package/dist/commands/daemon.d.ts +7 -3
  14. package/dist/commands/daemon.js +40 -25
  15. package/dist/commands/doctor.js +28 -2
  16. package/dist/commands/exec.js +87 -39
  17. package/dist/commands/fleet-capture.js +21 -2
  18. package/dist/commands/harness-wizard.js +2 -2
  19. package/dist/commands/lease.js +7 -12
  20. package/dist/commands/profiles.d.ts +2 -2
  21. package/dist/commands/profiles.js +20 -13
  22. package/dist/commands/repo.js +3 -3
  23. package/dist/commands/run-account-picker.d.ts +3 -3
  24. package/dist/commands/run-account-picker.js +29 -30
  25. package/dist/commands/secrets-passthrough.d.ts +20 -0
  26. package/dist/commands/secrets-passthrough.js +43 -0
  27. package/dist/commands/sessions-trace.d.ts +11 -0
  28. package/dist/commands/sessions-trace.js +71 -0
  29. package/dist/commands/setup-accounts.d.ts +3 -2
  30. package/dist/commands/setup-accounts.js +4 -4
  31. package/dist/commands/setup-secrets.d.ts +16 -21
  32. package/dist/commands/setup-secrets.js +43 -224
  33. package/dist/commands/ssh.js +2 -2
  34. package/dist/commands/sync.js +1 -1
  35. package/dist/commands/update.d.ts +10 -0
  36. package/dist/commands/update.js +43 -40
  37. package/dist/commands/versions.d.ts +11 -11
  38. package/dist/commands/versions.js +131 -83
  39. package/dist/commands/view.d.ts +1 -9
  40. package/dist/commands/view.js +41 -55
  41. package/dist/commands/webhook.js +5 -5
  42. package/dist/commands/workflows.js +2 -1
  43. package/dist/index.d.ts +12 -12
  44. package/dist/index.js +13 -42
  45. package/dist/lib/account-capabilities.d.ts +1 -1
  46. package/dist/lib/account-capabilities.js +1 -1
  47. package/dist/lib/account-catalog.d.ts +121 -6
  48. package/dist/lib/account-catalog.js +421 -7
  49. package/dist/lib/account-registry.d.ts +8 -30
  50. package/dist/lib/account-registry.js +36 -79
  51. package/dist/lib/account-schema.d.ts +1 -1
  52. package/dist/lib/account-schema.js +1 -1
  53. package/dist/lib/accounting/account-pool-collect.js +16 -4
  54. package/dist/lib/accounting/rotate.d.ts +20 -7
  55. package/dist/lib/accounting/rotate.js +89 -13
  56. package/dist/lib/accounting/usage.js +11 -16
  57. package/dist/lib/accounts/add.d.ts +138 -0
  58. package/dist/lib/accounts/add.js +651 -0
  59. package/dist/lib/accounts/migrate.d.ts +117 -0
  60. package/dist/lib/accounts/migrate.js +536 -0
  61. package/dist/lib/accounts/slots.d.ts +13 -0
  62. package/dist/lib/accounts/slots.js +100 -0
  63. package/dist/lib/agent-spec/agents.d.ts +16 -0
  64. package/dist/lib/agent-spec/agents.js +32 -4
  65. package/dist/lib/app-bundle-install.js +5 -4
  66. package/dist/lib/auth-health.d.ts +3 -0
  67. package/dist/lib/auth-health.js +11 -0
  68. package/dist/lib/auth-mint.d.ts +52 -16
  69. package/dist/lib/auth-mint.js +117 -39
  70. package/dist/lib/browser/chrome.d.ts +1 -1
  71. package/dist/lib/browser/chrome.js +5 -5
  72. package/dist/lib/byok-usage.js +3 -3
  73. package/dist/lib/claude-account-token.d.ts +47 -3
  74. package/dist/lib/claude-account-token.js +172 -50
  75. package/dist/lib/cloud/antigravity.js +4 -4
  76. package/dist/lib/cloud/cursor.js +4 -4
  77. package/dist/lib/crabbox/cli.d.ts +1 -1
  78. package/dist/lib/crabbox/cli.js +6 -6
  79. package/dist/lib/crabbox/runtimes.d.ts +3 -3
  80. package/dist/lib/crabbox/runtimes.js +5 -5
  81. package/dist/lib/daemon/account-state-daemon-service.d.ts +37 -1
  82. package/dist/lib/daemon/account-state-daemon-service.js +199 -3
  83. package/dist/lib/daemon/auth-sync-service.js +28 -1
  84. package/dist/lib/daemon/daemon.d.ts +6 -16
  85. package/dist/lib/daemon/daemon.js +52 -97
  86. package/dist/lib/daemon/daemon.test-fixture.d.ts +7 -9
  87. package/dist/lib/daemon/daemon.test-fixture.js +22 -40
  88. package/dist/lib/daemon/harness-update-service.d.ts +1 -1
  89. package/dist/lib/daemon/harness-update-service.js +1 -1
  90. package/dist/lib/daemon/runner.d.ts +15 -3
  91. package/dist/lib/daemon/runner.js +49 -24
  92. package/dist/lib/daemon-health.d.ts +1 -2
  93. package/dist/lib/daemon-health.js +7 -6
  94. package/dist/lib/daemon-services.d.ts +1 -1
  95. package/dist/lib/daemon-services.js +1 -11
  96. package/dist/lib/daemon-ticks.js +23 -2
  97. package/dist/lib/daemon-webhooks.d.ts +8 -7
  98. package/dist/lib/daemon-webhooks.js +10 -9
  99. package/dist/lib/device-config.js +1 -1
  100. package/dist/lib/devices/doctor-findings.d.ts +1 -1
  101. package/dist/lib/devices/harness-inventory.d.ts +39 -0
  102. package/dist/lib/devices/harness-inventory.js +126 -4
  103. package/dist/lib/doctor-diff.js +2 -1
  104. package/dist/lib/exec-account-home.d.ts +38 -0
  105. package/dist/lib/exec-account-home.js +164 -0
  106. package/dist/lib/exec.d.ts +30 -0
  107. package/dist/lib/exec.js +101 -31
  108. package/dist/lib/feed/activity-stream.d.ts +60 -0
  109. package/dist/lib/feed/activity-stream.js +271 -0
  110. package/dist/lib/feed/activity.d.ts +7 -0
  111. package/dist/lib/feed/activity.js +10 -4
  112. package/dist/lib/feed/watch.d.ts +9 -3
  113. package/dist/lib/feed/watch.js +72 -36
  114. package/dist/lib/fleet/apply.d.ts +2 -2
  115. package/dist/lib/fleet/apply.js +4 -4
  116. package/dist/lib/fleet/auth-sync.js +4 -3
  117. package/dist/lib/fleet-shared-repo-sync.js +6 -9
  118. package/dist/lib/fleet-shared-state.d.ts +6 -0
  119. package/dist/lib/harness/adapter.d.ts +7 -7
  120. package/dist/lib/harness/adapter.js +10 -6
  121. package/dist/lib/harness/adapters/grok.js +8 -3
  122. package/dist/lib/harness/adapters/muse.js +1 -1
  123. package/dist/lib/harness/adapters/opencode.js +12 -3
  124. package/dist/lib/harness-auth-capabilities.d.ts +61 -0
  125. package/dist/lib/harness-auth-capabilities.js +52 -0
  126. package/dist/lib/helper-versions.d.ts +6 -4
  127. package/dist/lib/helper-versions.js +5 -4
  128. package/dist/lib/hosts/credential-transport.d.ts +10 -0
  129. package/dist/lib/hosts/credential-transport.js +37 -0
  130. package/dist/lib/hosts/dispatch.d.ts +7 -0
  131. package/dist/lib/hosts/dispatch.js +13 -6
  132. package/dist/lib/identity/client.d.ts +3 -3
  133. package/dist/lib/identity/client.js +3 -3
  134. package/dist/lib/installations/index.d.ts +1 -1
  135. package/dist/lib/installations/index.js +1 -1
  136. package/dist/lib/installations/migrate.js +9 -0
  137. package/dist/lib/installations/resolve.js +1 -1
  138. package/dist/lib/installations/shims.d.ts +15 -0
  139. package/dist/lib/installations/shims.js +69 -0
  140. package/dist/lib/installations/store.d.ts +43 -0
  141. package/dist/lib/installations/store.js +75 -7
  142. package/dist/lib/installations/versions.js +1 -1
  143. package/dist/lib/menubar/install-menubar.d.ts +3 -3
  144. package/dist/lib/menubar/install-menubar.js +3 -3
  145. package/dist/lib/native-accounts.d.ts +35 -0
  146. package/dist/lib/native-accounts.js +41 -0
  147. package/dist/lib/net-close.d.ts +11 -0
  148. package/dist/lib/net-close.js +25 -0
  149. package/dist/lib/openclaw-keychain.js +27 -1
  150. package/dist/lib/profiles.js +22 -9
  151. package/dist/lib/project-resources.js +1 -1
  152. package/dist/lib/reserved-stores.d.ts +53 -0
  153. package/dist/lib/reserved-stores.js +120 -0
  154. package/dist/lib/secrets-client.d.ts +191 -0
  155. package/dist/lib/secrets-client.js +710 -0
  156. package/dist/lib/secrets-policy.d.ts +222 -0
  157. package/dist/lib/secrets-policy.js +483 -0
  158. package/dist/lib/secrets-types.d.ts +188 -0
  159. package/dist/lib/secrets-types.js +24 -0
  160. package/dist/lib/service-manifest.js +3 -4
  161. package/dist/lib/session/active.d.ts +38 -4
  162. package/dist/lib/session/active.js +36 -4
  163. package/dist/lib/session/bash-command.js +10 -0
  164. package/dist/lib/session/db.d.ts +65 -2
  165. package/dist/lib/session/db.js +178 -18
  166. package/dist/lib/session/mirror.d.ts +5 -0
  167. package/dist/lib/session/mirror.js +166 -0
  168. package/dist/lib/session/parse.d.ts +49 -0
  169. package/dist/lib/session/parse.js +324 -30
  170. package/dist/lib/session/prompt.d.ts +93 -2
  171. package/dist/lib/session/prompt.js +266 -15
  172. package/dist/lib/session/remote/peer-stream.d.ts +47 -0
  173. package/dist/lib/session/remote/peer-stream.js +142 -0
  174. package/dist/lib/session/remote/watch.d.ts +1 -1
  175. package/dist/lib/session/remote/watch.js +41 -42
  176. package/dist/lib/session/session-cache.d.ts +9 -0
  177. package/dist/lib/session/session-cache.js +40 -2
  178. package/dist/lib/session/sync/config.js +2 -2
  179. package/dist/lib/session/timeline-pass.d.ts +129 -0
  180. package/dist/lib/session/timeline-pass.js +323 -0
  181. package/dist/lib/session/timeline.d.ts +182 -0
  182. package/dist/lib/session/timeline.js +636 -0
  183. package/dist/lib/session/types.d.ts +155 -1
  184. package/dist/lib/sha256-asset.d.ts +11 -16
  185. package/dist/lib/sha256-asset.js +11 -16
  186. package/dist/lib/share/config.js +14 -5
  187. package/dist/lib/signin-badge.d.ts +26 -0
  188. package/dist/lib/signin-badge.js +42 -0
  189. package/dist/lib/staleness/detectors/workflows.js +3 -105
  190. package/dist/lib/staleness/writers/workflows.js +2 -1
  191. package/dist/lib/state.d.ts +7 -4
  192. package/dist/lib/state.js +18 -7
  193. package/dist/lib/summarizer/pass.d.ts +2 -0
  194. package/dist/lib/summarizer/pass.js +14 -1
  195. package/dist/lib/summarizer/summarize.d.ts +7 -0
  196. package/dist/lib/summarizer/summarize.js +3 -0
  197. package/dist/lib/sync-umbrella.js +2 -2
  198. package/dist/lib/teams/agents.js +1 -1
  199. package/dist/lib/types.d.ts +74 -33
  200. package/dist/lib/view-types.d.ts +6 -3
  201. package/dist/lib/workflows-registry.d.ts +71 -0
  202. package/dist/lib/workflows-registry.js +280 -0
  203. package/dist/lib/workflows.d.ts +21 -21
  204. package/dist/lib/workflows.js +12 -327
  205. package/package.json +2 -3
  206. package/scripts/postinstall.js +4 -29
  207. package/dist/commands/secrets-import.d.ts +0 -18
  208. package/dist/commands/secrets-import.js +0 -74
  209. package/dist/commands/secrets-migrate.d.ts +0 -25
  210. package/dist/commands/secrets-migrate.js +0 -334
  211. package/dist/commands/secrets-rotate-passphrase.d.ts +0 -17
  212. package/dist/commands/secrets-rotate-passphrase.js +0 -96
  213. package/dist/commands/secrets-sync.d.ts +0 -11
  214. package/dist/commands/secrets-sync.js +0 -153
  215. package/dist/commands/secrets-vault.d.ts +0 -10
  216. package/dist/commands/secrets-vault.js +0 -130
  217. package/dist/commands/secrets.d.ts +0 -212
  218. package/dist/commands/secrets.js +0 -3030
  219. package/dist/lib/accounts/connect.d.ts +0 -170
  220. package/dist/lib/accounts/connect.js +0 -383
  221. package/dist/lib/daemon/keychain-reap-service.d.ts +0 -17
  222. package/dist/lib/daemon/keychain-reap-service.js +0 -32
  223. package/dist/lib/daemon/secrets-broker-service.d.ts +0 -21
  224. package/dist/lib/daemon/secrets-broker-service.js +0 -51
  225. package/dist/lib/secrets/agent.d.ts +0 -358
  226. package/dist/lib/secrets/agent.js +0 -1291
  227. package/dist/lib/secrets/audit.d.ts +0 -46
  228. package/dist/lib/secrets/audit.js +0 -101
  229. package/dist/lib/secrets/bundles.d.ts +0 -290
  230. package/dist/lib/secrets/bundles.js +0 -1547
  231. package/dist/lib/secrets/download-keychain.d.ts +0 -47
  232. package/dist/lib/secrets/download-keychain.js +0 -70
  233. package/dist/lib/secrets/drivers/rush.d.ts +0 -14
  234. package/dist/lib/secrets/drivers/rush.js +0 -90
  235. package/dist/lib/secrets/fallback.d.ts +0 -48
  236. package/dist/lib/secrets/fallback.js +0 -48
  237. package/dist/lib/secrets/filestore.d.ts +0 -222
  238. package/dist/lib/secrets/filestore.js +0 -1099
  239. package/dist/lib/secrets/headless.d.ts +0 -43
  240. package/dist/lib/secrets/headless.js +0 -56
  241. package/dist/lib/secrets/icloud-import.d.ts +0 -79
  242. package/dist/lib/secrets/icloud-import.js +0 -206
  243. package/dist/lib/secrets/index.d.ts +0 -451
  244. package/dist/lib/secrets/index.js +0 -1568
  245. package/dist/lib/secrets/install-helper.d.ts +0 -72
  246. package/dist/lib/secrets/install-helper.js +0 -245
  247. package/dist/lib/secrets/lease.d.ts +0 -25
  248. package/dist/lib/secrets/lease.js +0 -44
  249. package/dist/lib/secrets/linux.d.ts +0 -77
  250. package/dist/lib/secrets/linux.js +0 -393
  251. package/dist/lib/secrets/list-filter.d.ts +0 -109
  252. package/dist/lib/secrets/list-filter.js +0 -261
  253. package/dist/lib/secrets/mcp.d.ts +0 -93
  254. package/dist/lib/secrets/mcp.js +0 -211
  255. package/dist/lib/secrets/profiles.d.ts +0 -10
  256. package/dist/lib/secrets/profiles.js +0 -13
  257. package/dist/lib/secrets/push.d.ts +0 -133
  258. package/dist/lib/secrets/push.js +0 -273
  259. package/dist/lib/secrets/rc-hygiene.d.ts +0 -63
  260. package/dist/lib/secrets/rc-hygiene.js +0 -143
  261. package/dist/lib/secrets/read-backoff.d.ts +0 -27
  262. package/dist/lib/secrets/read-backoff.js +0 -64
  263. package/dist/lib/secrets/reaper.d.ts +0 -90
  264. package/dist/lib/secrets/reaper.js +0 -243
  265. package/dist/lib/secrets/remote.d.ts +0 -152
  266. package/dist/lib/secrets/remote.js +0 -344
  267. package/dist/lib/secrets/reserved-sync.d.ts +0 -66
  268. package/dist/lib/secrets/reserved-sync.js +0 -147
  269. package/dist/lib/secrets/scope.d.ts +0 -26
  270. package/dist/lib/secrets/scope.js +0 -29
  271. package/dist/lib/secrets/session-store.d.ts +0 -107
  272. package/dist/lib/secrets/session-store.js +0 -342
  273. package/dist/lib/secrets/sync-backend.d.ts +0 -48
  274. package/dist/lib/secrets/sync-backend.js +0 -13
  275. package/dist/lib/secrets/sync-commands.d.ts +0 -21
  276. package/dist/lib/secrets/sync-commands.js +0 -21
  277. package/dist/lib/secrets/sync.d.ts +0 -48
  278. package/dist/lib/secrets/sync.js +0 -237
  279. package/dist/lib/secrets/unlock-hints.d.ts +0 -27
  280. package/dist/lib/secrets/unlock-hints.js +0 -36
  281. package/dist/lib/secrets/usage-db.d.ts +0 -46
  282. package/dist/lib/secrets/usage-db.js +0 -96
  283. package/dist/lib/secrets/vault-age-helper.d.ts +0 -1
  284. package/dist/lib/secrets/vault-age-helper.js +0 -34
  285. package/dist/lib/secrets/vault.d.ts +0 -49
  286. package/dist/lib/secrets/vault.js +0 -399
  287. package/dist/lib/secrets/windows.d.ts +0 -81
  288. package/dist/lib/secrets/windows.js +0 -556
  289. package/scripts/install-helper.js +0 -97
  290. /package/dist/lib/{secrets/sync-passphrase.d.ts → sync-passphrase.d.ts} +0 -0
  291. /package/dist/lib/{secrets/sync-passphrase.js → sync-passphrase.js} +0 -0
@@ -1,51 +0,0 @@
1
- /**
2
- * Secrets-broker lifecycle as a `DaemonService` (RUSH-3193 P2).
3
- *
4
- * Wraps the daemon's secrets-broker hosting under the `ServiceSupervisor`
5
- * contract so the supervisor owns start/stop and reports health through the
6
- * uniform `daemon-health.ts` path. The broker self-heal (RUSH-1817) is
7
- * encapsulated here: a background interval re-probes the socket and takes
8
- * over hosting whenever the daemon is NOT already hosting AND no healthy
9
- * standalone broker answers a ping.
10
- */
11
- import { BasePeriodicService } from './service.js';
12
- /** Matches the constant previously in daemon.ts. */
13
- const BROKER_SELF_HEAL_TICK_MS = 60_000;
14
- const BROKER_SELF_HEAL_DEADLINE_MS = 30_000;
15
- /** Take over only when we are not already hosting AND no broker is reachable. */
16
- function shouldTakeOver(isHosting, brokerReachable) {
17
- return !isHosting && !brokerReachable;
18
- }
19
- export class SecretsBrokerService extends BasePeriodicService {
20
- id = 'secrets-broker';
21
- intervalMs = BROKER_SELF_HEAL_TICK_MS;
22
- deadlineMs = BROKER_SELF_HEAL_DEADLINE_MS;
23
- hostedBroker = null;
24
- async onStart(ctx) {
25
- const { agentPing, startHostedBroker } = await import('../secrets/agent.js');
26
- if ((await agentPing()).reachable) {
27
- ctx.log('INFO', 'Secrets broker already running (standalone); daemon not hosting it');
28
- }
29
- else {
30
- this.hostedBroker = await startHostedBroker();
31
- if (this.hostedBroker)
32
- ctx.log('INFO', 'Secrets broker hosted in daemon (socket-first)');
33
- }
34
- }
35
- async onStop() {
36
- this.hostedBroker?.close();
37
- this.hostedBroker = null;
38
- }
39
- async onTick(ctx) {
40
- // RUSH-1817: if the standalone the daemon deferred to at start later dies,
41
- // take over hosting on the next supervisor-owned self-heal probe.
42
- const { agentPing, startHostedBroker } = await import('../secrets/agent.js');
43
- const reachable = (await agentPing()).reachable;
44
- if (!shouldTakeOver(this.hostedBroker != null, reachable))
45
- return;
46
- this.hostedBroker = await startHostedBroker();
47
- if (this.hostedBroker) {
48
- ctx.log('WARN', 'Secrets broker was unreachable; daemon took over hosting (self-heal)');
49
- }
50
- }
51
- }
@@ -1,358 +0,0 @@
1
- /**
2
- * The secrets-agent: an in-memory broker that holds resolved bundle env after one
3
- * Touch ID unlock, so concurrent agents don't each prompt.
4
- *
5
- * Security model: while unlocked, any same-user process reaching the socket can
6
- * read it silently — the same trust boundary the keychain already concedes. We
7
- * bound it with per-bundle opt-in, a TTL (~7d), auto-wipe on sleep/logout, and
8
- * explicit lock. Nothing touches disk. Off-darwin the broker is unused.
9
- */
10
- import * as net from 'net';
11
- import type { SecretsBundle } from './bundles.js';
12
- import { GLOBAL_HARNESS, bundleScopeChain } from './scope.js';
13
- import { type SecretLease } from './lease.js';
14
- export { GLOBAL_HARNESS, bundleScopeChain };
15
- /** Default lifetime of an unlocked bundle when `--ttl` is not given. */
16
- export declare const DEFAULT_TTL_MS: number;
17
- /**
18
- * Whether the secrets broker service is enabled in daemon service config.
19
- */
20
- export declare function isSecretsBrokerEnabled(): boolean;
21
- /**
22
- * Reserved store-key prefix for the `secrets list` metadata snapshot cache.
23
- * Keyed by a hash of the keychain name-set; adding/removing/renaming a bundle
24
- * changes the key and invalidates passively. The '!' sentinel cannot collide
25
- * with a real bundle name and is safe as argv.
26
- */
27
- export declare const META_CACHE_PREFIX = "!meta:";
28
- export { SYNC_GET_CMD, SYNC_PING_CMD, SYNC_LOCK_CMD } from './sync-commands.js';
29
- /**
30
- * Decide whether a persistent broker should exit so launchd relaunches it on
31
- * freshly-installed code. Only when the store is empty: exiting with held
32
- * bundles would force a re-prompt. Deferring protects against rapid upgrades
33
- * wiping the hot cache (#435).
34
- */
35
- export declare function shouldSelfHealForUpgrade(persistent: boolean, storeSize: number, runningVersion: string, onDiskVersion: string): boolean;
36
- /**
37
- * Client-side twin: may only tear down a version-skewed broker when it holds
38
- * no real unlocks, otherwise every held bundle re-prompts (#435).
39
- */
40
- export declare function shouldTeardownVersionSkewedBroker(realHeldBundles: number): boolean;
41
- /**
42
- * Whether a client may evict a version-skewed broker. A daemon-hosted broker
43
- * must never be client-evicted: the daemon owns the socket via ownerPath(), so
44
- * unlinking it would orphan the broker until daemon restart (#435).
45
- */
46
- export declare function shouldClientEvictSkewedBroker(daemonRunning: boolean, realHeldBundles: number): boolean;
47
- export interface StoredBundle {
48
- bundle: SecretsBundle;
49
- env: Record<string, string>;
50
- /** epoch ms; the entry is gone once Date.now() passes this. */
51
- expiresAt: number;
52
- harness: string;
53
- lease?: SecretLease;
54
- }
55
- /** One unlocked bundle as reported by `status`. */
56
- export interface AgentStatusEntry {
57
- name: string;
58
- expiresAt: number;
59
- keyCount: number;
60
- harness: string;
61
- leaseId?: string;
62
- keys?: string[];
63
- }
64
- /** Public accessor for the broker's socket path — `agents daemon status`/`services` reads it for display. */
65
- export declare function secretsBrokerSocketPath(): string;
66
- /**
67
- * Read the current broker capability token. A restart mints a new token, so a
68
- * stale read fails soft and the caller falls back to a direct keychain read.
69
- */
70
- export declare function readAgentToken(): string | null;
71
- /** True if a legacy standalone-broker launchd plist is still installed. */
72
- export declare function secretsAgentServiceInstalled(): boolean;
73
- /**
74
- * Retire the legacy standalone launchd service so the daemon owns the socket.
75
- * Idempotent; does not wipe held bundles.
76
- */
77
- export declare function retireLegacySecretsAgentService(): void;
78
- /**
79
- * Stop the persistent broker for `agents secrets stop`: wipe held bundles, then
80
- * retire any legacy standalone service. The daemon-hosted broker itself is left
81
- * running because it backs unrelated background work.
82
- */
83
- export declare function uninstallSecretsAgentService(): Promise<void>;
84
- export type Request = {
85
- cmd: 'ping';
86
- } | {
87
- cmd: 'get';
88
- name: string;
89
- harness?: string;
90
- token?: string;
91
- } | {
92
- cmd: 'load';
93
- name: string;
94
- harness?: string;
95
- bundle: SecretsBundle;
96
- env: Record<string, string>;
97
- ttlMs: number;
98
- lease?: SecretLease;
99
- token?: string;
100
- snapshotAt?: number;
101
- } | {
102
- cmd: 'lock';
103
- name?: string;
104
- token?: string;
105
- } | {
106
- cmd: 'revoke';
107
- leaseId: string;
108
- token?: string;
109
- } | {
110
- cmd: 'status';
111
- token?: string;
112
- };
113
- export type Response = {
114
- ok: true;
115
- cmd: 'ping';
116
- version: number;
117
- cliVersion: string;
118
- } | {
119
- ok: true;
120
- cmd: 'get';
121
- hit: false;
122
- } | {
123
- ok: true;
124
- cmd: 'get';
125
- hit: true;
126
- bundle: SecretsBundle;
127
- env: Record<string, string>;
128
- lease?: SecretLease;
129
- } | {
130
- ok: true;
131
- cmd: 'load';
132
- } | {
133
- ok: true;
134
- cmd: 'lock';
135
- wiped: number;
136
- } | {
137
- ok: true;
138
- cmd: 'revoke';
139
- wiped: number;
140
- } | {
141
- ok: true;
142
- cmd: 'status';
143
- entries: AgentStatusEntry[];
144
- } | {
145
- ok: false;
146
- error: string;
147
- };
148
- /**
149
- * Count of real unlocked bundles, excluding the internal `secrets list` metadata
150
- * cache. A metadata-only store must read as empty so it doesn't block upgrade
151
- * self-heal or idle-exit (#435). Exported for tests.
152
- */
153
- export declare function realBundleCount(store: Map<string, StoredBundle>): number;
154
- export declare function scopedBundleKey(name: string, harness: string): string;
155
- /** Pure request handler over the in-memory store. Exported for tests. */
156
- export declare function handleAgentRequest(store: Map<string, StoredBundle>, req: Request, now?: number, evictedAt?: Map<string, number>): Response;
157
- /**
158
- * Wipe the in-memory store only on SLEEP, not screen-lock (already gated by the
159
- * login password). Exported for regression coverage of the LOCK-survives /
160
- * SLEEP-wipes contract.
161
- */
162
- export declare function shouldWipeOnWatchEvent(chunk: string): boolean;
163
- /**
164
- * Authorization gate: every request except `ping` must carry the per-broker
165
- * capability token from the 0600 token file. `ping` stays unauthenticated so
166
- * clients can probe reachability before reading the token. Fail closed. Exported
167
- * for tests.
168
- */
169
- export declare function isRequestAuthorized(req: Request, expectedToken: string | null): boolean;
170
- type BrokerConnectionHandler = (conn: net.Socket) => void;
171
- /**
172
- * Build the socket `connection` handler shared by standalone and daemon-hosted
173
- * brokers. Newline-framed JSON in, one response line out, with per-request token
174
- * lookup so rotation on restart is picked up.
175
- */
176
- export declare function makeConnectionHandler(handle: (req: Request) => Response, token: () => string | null): BrokerConnectionHandler;
177
- /**
178
- * Whether a live process still owns the broker pid file. A single missed ping
179
- * isn't proof of death: the single-threaded broker can blow the ping budget
180
- * while healthy. The pid file is the second liveness signal that makes reclaim
181
- * safe.
182
- */
183
- /** Drop our ownership record only if it is still ours. */
184
- export declare function releaseBrokerPid(): void;
185
- export declare function brokerPidAlive(): boolean;
186
- /**
187
- * Run the standalone broker in the foreground. Spawned by ensureAgentRunning via
188
- * `agents secrets _agent-run`. Serves the socket, sweeps expired entries, wipes
189
- * on sleep, and self-exits when idle.
190
- */
191
- export declare function runSecretsAgent(opts?: {
192
- service?: boolean;
193
- }): Promise<{
194
- close(): void | Promise<void>;
195
- } | null>;
196
- /**
197
- * Host the secrets broker inside the always-on daemon (#416). Serves the same
198
- * socket/protocol as the standalone broker, but daemon-safe: no pid-file guard,
199
- * no process.exit/SIG handlers, no self-heal/idle-exit (the daemon owns the
200
- * lifecycle). Returns null off-darwin.
201
- */
202
- export declare function startHostedBroker(): Promise<{
203
- close(): void | Promise<void>;
204
- } | null>;
205
- /**
206
- * Wait for net.Server.close()'s 'close' event (or a bounded timeout) so a
207
- * successor bind doesn't race a half-closed socket (RUSH-2421).
208
- */
209
- export declare function closeServerBounded(server: net.Server, timeoutMs?: number): Promise<void>;
210
- /** Cheap socket-existence check so the never-unlocked path stays a single stat. */
211
- export declare function agentSocketExists(): boolean;
212
- /**
213
- * Spawn one of the `__secrets-*` sync clients via `getCliLaunch`. The old
214
- * `process.execPath -e` pattern broke on the bun-compiled Mach-O binary
215
- * (1.20.53); routing through getCliLaunch fixes both install shapes. The
216
- * subcommands are intercepted in index.ts before commander/startup so a cache
217
- * hit doesn't fork detached syncs or run update checks.
218
- */
219
- export declare function syncClientLaunch(sub: string[], agentsBin?: string): {
220
- command: string;
221
- args: string[];
222
- };
223
- /**
224
- * Synchronous read for the hot path. Returns null on any failure so the caller
225
- * falls through to the real keychain. macOS only.
226
- */
227
- export declare function agentGetSync(name: string, harness?: string): {
228
- bundle: SecretsBundle;
229
- env: Record<string, string>;
230
- lease?: SecretLease;
231
- } | null;
232
- /**
233
- * Last non-empty line of a child's stdout — the payload line. Anchors on the
234
- * terminator so any future CLI startup chatter on stdout doesn't break JSON.parse
235
- * and silently turn cache hits into misses.
236
- */
237
- export declare function lastLine(stdout: string): string;
238
- /**
239
- * Synchronous liveness check: is a broker actually listening? Gates the
240
- * synchronous warm path so a stale socket doesn't drag a foreground read
241
- * through a cold-start. macOS only.
242
- */
243
- export declare function agentReachableSync(): boolean;
244
- /**
245
- * Synchronously evict one bundle after a mutating write so the broker doesn't
246
- * serve a stale snapshot for the hold window. Best-effort silent no-op. macOS only.
247
- */
248
- export declare function agentEvictSync(name: string): void;
249
- /** Body of `__secrets-get <name>`. Exit 0 = hit, 3 = miss/down. */
250
- export declare function runAgentGetSync(name: string, harness?: string): Promise<number>;
251
- /** Body of `__secrets-ping`. Exit 0 = listening broker, 3 = nothing there.
252
- * Does not gate on PROTOCOL_VERSION so version-skewed brokers still answer reads. */
253
- export declare function runAgentPingSync(): Promise<number>;
254
- /** Body of `__secrets-lock <name>`. Best-effort evict; exit 0 even when no
255
- * broker answers. An empty name is refused to avoid accidentally locking ALL
256
- * bundles. */
257
- export declare function runAgentLockSync(name: string): Promise<number>;
258
- /**
259
- * Read the cached `secrets list` metadata snapshot for a keychain name-set hash.
260
- * Reuses agentGetSync. The name-set hash is the cache key, so add/remove/rename
261
- * yields a clean miss.
262
- */
263
- export declare function agentGetMetaSync(nameSetHash: string): SecretsBundle[] | null;
264
- /**
265
- * Fire-and-forget: populate the broker with a metadata snapshot so the next
266
- * `secrets list` within the hold window is prompt-free. Stored under a reserved
267
- * META_CACHE_PREFIX key; snapshot travels over stdin. macOS only.
268
- */
269
- export declare function agentAutoLoadMetaSync(nameSetHash: string, bundles: SecretsBundle[], ttlMs: number): void;
270
- /** True unless `secrets.agent.auto` is explicitly disabled in agents.yaml. The
271
- * broker is the mechanism that delivers the `daily` default policy (one Touch ID
272
- * per ~7d), so auto-caching is ON by default; opt out with
273
- * `secrets.agent.auto: false`. Best-effort; an unreadable meta reads as on. */
274
- export declare function secretsAgentAutoEnabled(): boolean;
275
- /** Default `sleepPersist` for a new unlock when `--durable` is not passed. OFF by
276
- * default (the secure split default: survive restart, re-lock on sleep); set
277
- * `secrets.agent.durable: true` in agents.yaml to make every unlock sleep-durable.
278
- * Best-effort; an unreadable meta reads as off. */
279
- export declare function secretsAgentDurable(): boolean;
280
- /** Minimum / maximum bounds for the configurable hold window. A too-small value
281
- * would defeat the broker (constant re-prompts); a too-large one pins secrets in
282
- * memory far longer than intended. */
283
- export declare const MIN_HOLD_MS: number;
284
- export declare const MAX_HOLD_MS: number;
285
- /**
286
- * How long an unlocked / auto-cached bundle is held before the next read
287
- * re-prompts. Defaults to DEFAULT_TTL_MS (7d); override with
288
- * `secrets.agent.holdMs` (milliseconds) in agents.yaml — e.g. 86400000 for a 24h
289
- * cap. Clamped to [MIN_HOLD_MS, MAX_HOLD_MS] so a typo can neither disable the
290
- * hold nor pin a secret in memory indefinitely. Best-effort: an unreadable or
291
- * non-numeric value falls back to the 7d default. Pure except for the meta read.
292
- */
293
- export declare function secretsHoldMs(): number;
294
- /** Pure clamp for a configured `holdMs`: a positive finite number is bounded to
295
- * [MIN_HOLD_MS, MAX_HOLD_MS]; anything else (absent, 0, negative, NaN, non-number)
296
- * falls back to the 7d default. Exported for direct unit testing. */
297
- export declare function clampHoldMs(v: unknown): number;
298
- /**
299
- * Fire-and-forget: populate the broker with a freshly-resolved bundle so the
300
- * NEXT process reads it without a prompt. Used by the auto-cache path after a
301
- * real keychain read of a `daily`-policy bundle, so the NEXT concurrent read is
302
- * silent. Env travels over stdin, never argv.
303
- *
304
- * Reliability (this is what makes `daily` actually "stick"): when a broker is
305
- * ALREADY listening, warm it SYNCHRONOUSLY with a bounded wait so the bundle is
306
- * held by the time this process exits. The old detached-only path lost the race
307
- * under load — a short-lived reader (`agents secrets export`, a release-script
308
- * loop) exited before the unref'd worker connected, so the cache silently never
309
- * populated and every read re-prompted despite the `daily` policy. Only when the
310
- * broker must COLD-START (no socket yet) do we fall back to the detached worker,
311
- * so a first-ever read never blocks on a multi-second broker boot.
312
- *
313
- * The worker reuses the robust `ensureAgentRunning` path (spawn-then-ping) rather
314
- * than a tight inline retry loop. Best-effort; never throws. macOS only.
315
- */
316
- export declare function agentAutoLoadSync(name: string, bundle: SecretsBundle, env: Record<string, string>, ttlMs: number, harness?: string, lease?: SecretLease, snapshotAt?: number): void;
317
- /**
318
- * Body of the hidden `secrets _agent-load` worker. Reads one `{name, bundle,
319
- * env, ttlMs}` payload from stdin, ensures the broker is up (robust, generous
320
- * budget), and loads the bundle into it.
321
- *
322
- * Exit code is load-truthful: 0 ONLY when the bundle was actually loaded into a
323
- * reachable broker; non-zero on any failure (malformed payload, broker couldn't
324
- * be brought up, or the load transport failed). The synchronous caller
325
- * (agentAutoLoadSync) relies on this to decide whether to skip the detached
326
- * fallback — a bare "process exited 0" would otherwise be a false-positive
327
- * success that silently reintroduces the very re-prompt storm this path fixes.
328
- */
329
- export declare function runAgentLoadFromStdin(): Promise<void>;
330
- /** Store a resolved bundle in the broker. Returns false on transport failure. */
331
- export declare function agentLoad(name: string, bundle: SecretsBundle, env: Record<string, string>, ttlMs: number, harness?: string, lease?: SecretLease, snapshotAt?: number): Promise<boolean>;
332
- /** Wipe one bundle (or all if name omitted) from the broker. Returns the count
333
- * wiped, or 0 when no broker is running. */
334
- export declare function agentLock(name?: string): Promise<number>;
335
- /** List currently-unlocked bundles, or [] when no broker is running. The
336
- * internal `secrets list` metadata-cache entry is filtered out here as well as
337
- * server-side: during a rollout a NEW client can talk to an OLD broker that
338
- * predates the server-side exclusion, so this keeps the internal entry from
339
- * surfacing in `agents secrets status` in that skew window. */
340
- export declare function agentStatus(): Promise<AgentStatusEntry[]>;
341
- /** Ping result: whether a broker is reachable + speaking our protocol, and the
342
- * version of the code it's running (for staleness detection). */
343
- export declare function agentPing(): Promise<{
344
- reachable: boolean;
345
- cliVersion?: string;
346
- }>;
347
- /**
348
- * Ensure a broker is running and reachable. Returns true once the socket answers
349
- * a ping. macOS only.
350
- *
351
- * Prefers the always-on daemon, which hosts the broker socket (#416): retire any
352
- * legacy standalone launchd service so the daemon owns the socket, then bring the
353
- * daemon up (Path 0) — one supervised backbone that survives the whole login
354
- * session, so subsequent reads never cold-start. Only when the daemon can't be
355
- * used do we fall back to a one-off detached broker (Path 1) — the model that
356
- * gets starved under heavy load, so it's last.
357
- */
358
- export declare function ensureAgentRunning(timeoutMs?: number): Promise<boolean>;