@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,46 +0,0 @@
1
- export type SecretAuditEvent = 'secrets.get' | 'secrets.unlocked' | 'secrets.create' | 'secrets.import' | 'secrets.export' | 'secrets.view' | 'secrets.lease-denied' | 'secrets.lease-expire';
2
- export interface SecretAuditParams {
3
- /** Which audit event this is — a read (`secrets.get`) or an unlock grant. */
4
- event: SecretAuditEvent;
5
- /** Bundle name (never a value). */
6
- bundle?: string;
7
- /** Raw keychain item/service name for `secrets get <item>` (never a value). */
8
- item?: string;
9
- /** Free-form operation/caller label, e.g. 'export to shell', 'unlock'. */
10
- operation?: string;
11
- /**
12
- * Where the read/grant originated: agent | session | reveal | raw-item |
13
- * remote | sync-push | broker | broker+durable.
14
- */
15
- source?: string;
16
- status?: 'success' | 'error';
17
- /** Env/key NAMES exposed — names only, never values. */
18
- keys?: string[];
19
- keyCount?: number;
20
- /** Subset of `keys` backed by the OS keychain — names only. */
21
- keychainKeys?: string[];
22
- /** Count of resolved values by kind (literal / keychain / env / ...). */
23
- kindCounts?: Record<string, number>;
24
- /**
25
- * Resolving agent/harness identity the access was scoped to (`*` = a global
26
- * grant readable by every harness). Falls back to `$AGENTS_AGENT_NAME`.
27
- */
28
- agent?: string;
29
- /** Remote host the value was pulled from, when applicable. */
30
- host?: string;
31
- /** Grant lifetime in ms (`secrets.unlocked` only). */
32
- ttlMs?: number;
33
- error?: string;
34
- }
35
- /**
36
- * The agent/harness identity to attribute a secret access to. Explicit callers
37
- * (the bundle reader knows the scope it resolved under) win; otherwise fall back
38
- * to the ambient `$AGENTS_AGENT_NAME` set on every agent launch.
39
- */
40
- export declare function resolveAuditAgent(explicit?: string): string | undefined;
41
- /**
42
- * Emit one value-free secret audit event to the raw/operational event stream and
43
- * the persisted audit log. Only ever pass metadata — the secret value must never
44
- * reach this function.
45
- */
46
- export declare function emitSecretAudit(p: SecretAuditParams): void;
@@ -1,101 +0,0 @@
1
- /**
2
- * Canonical audit emitter for every `agents secrets` lifecycle/access event.
3
- *
4
- * This is the ONE write path for secret events. Every path that creates,
5
- * imports, exports, views, reads a VALUE from, or unlocks a bundle funnels its
6
- * audit through here, so the operational event stream — `agents events`, backed
7
- * by the dated append-only `~/.agents/.history/events/` audit log — carries a uniform,
8
- * value-free provenance record: bundle, key NAMES, the resolving agent/harness
9
- * identity, operation, source, status. The ts / host / session / caller fields
10
- * are filled in by `emit()` itself. The secret VALUE is never part of the
11
- * payload; this helper only ever receives metadata, and `emit()`'s
12
- * `sanitizePayload` is a second redaction layer.
13
- *
14
- * The same call also mirrors the event into the per-bundle usage read-model DB
15
- * (`~/.agents/secrets/secrets.db`, lib/secrets/usage-db.ts) so `secrets view` /
16
- * `list` / `activity` can answer "how often / how recently / by whom was this
17
- * bundle used?" without scanning the whole event stream — a DERIVED index fed
18
- * off this chokepoint, not a second write path a caller has to remember.
19
- *
20
- * The event vocabulary, all audit-level and non-milestone (so they surface in
21
- * `agents events` and the persisted audit trail, but are NOT required in the
22
- * curated `agents feed` surface):
23
- * - `secrets.get` — a value was READ (exec inject, export, `view --reveal`,
24
- * raw `get <item>`, remote resolve, sync push,
25
- * `run --secrets`, and every other bundle read).
26
- * - `secrets.unlocked` — a bundle was GRANTED into the secrets broker / durable
27
- * session by `agents secrets unlock`, then readable
28
- * prompt-free for the grant TTL.
29
- * - `secrets.create` — a new bundle was created.
30
- * - `secrets.import` — keys were imported into a bundle (file / ssh / 1password).
31
- * - `secrets.export` — a bundle's values were exported (file / shell / ssh /
32
- * 1password). Exporting also READS the values, so the
33
- * underlying resolve emits its own `secrets.get`.
34
- * - `secrets.view` — a bundle's (masked) metadata was inspected via `view`.
35
- */
36
- import { emit } from '../feed/events.js';
37
- import { recordSecretUsage } from './usage-db.js';
38
- /**
39
- * Map each audit event onto the usage-DB kind it is counted as. `secrets.get` is
40
- * the injection/read access; the rest map 1:1 to their lifecycle kind.
41
- */
42
- const USAGE_KIND = {
43
- 'secrets.get': 'access',
44
- 'secrets.unlocked': 'unlock',
45
- 'secrets.create': 'create',
46
- 'secrets.import': 'import',
47
- 'secrets.export': 'export',
48
- 'secrets.view': 'view',
49
- 'secrets.lease-denied': 'access',
50
- 'secrets.lease-expire': 'access',
51
- };
52
- /**
53
- * The agent/harness identity to attribute a secret access to. Explicit callers
54
- * (the bundle reader knows the scope it resolved under) win; otherwise fall back
55
- * to the ambient `$AGENTS_AGENT_NAME` set on every agent launch.
56
- */
57
- export function resolveAuditAgent(explicit) {
58
- const a = explicit || process.env.AGENTS_AGENT_NAME;
59
- return a && a.length > 0 ? a : undefined;
60
- }
61
- /**
62
- * Emit one value-free secret audit event to the raw/operational event stream and
63
- * the persisted audit log. Only ever pass metadata — the secret value must never
64
- * reach this function.
65
- */
66
- export function emitSecretAudit(p) {
67
- const agent = resolveAuditAgent(p.agent);
68
- emit(p.event, {
69
- module: 'secrets',
70
- ...(p.bundle !== undefined ? { bundle: p.bundle } : {}),
71
- ...(p.item !== undefined ? { item: p.item } : {}),
72
- ...(p.operation !== undefined ? { operation: p.operation } : {}),
73
- ...(p.source !== undefined ? { source: p.source } : {}),
74
- ...(p.status !== undefined ? { status: p.status } : {}),
75
- ...(p.keys !== undefined ? { keys: p.keys } : {}),
76
- ...(p.keyCount !== undefined ? { keyCount: p.keyCount } : {}),
77
- ...(p.keychainKeys !== undefined ? { keychainKeys: p.keychainKeys } : {}),
78
- ...(p.kindCounts !== undefined ? { kindCounts: p.kindCounts } : {}),
79
- ...(agent !== undefined ? { agent } : {}),
80
- ...(p.host !== undefined ? { host: p.host } : {}),
81
- ...(p.ttlMs !== undefined ? { ttlMs: p.ttlMs } : {}),
82
- ...(p.error !== undefined ? { error: p.error } : {}),
83
- });
84
- // Mirror the event into the per-bundle usage read-model so `secrets view` /
85
- // `list` / `activity` can report frequency and recency without scanning the
86
- // whole event stream. Fed off THIS chokepoint alongside the events.jsonl
87
- // write, never a second write path. Per-bundle only — a raw `secrets get
88
- // <item>` has no bundle, so it stays in the events.jsonl audit but is not
89
- // counted as bundle usage. Best-effort inside usage-db (swallows errors).
90
- if (p.bundle) {
91
- recordSecretUsage({
92
- bundle: p.bundle,
93
- event: USAGE_KIND[p.event],
94
- agent,
95
- host: p.host,
96
- source: p.source,
97
- status: p.status,
98
- keyCount: p.keyCount,
99
- });
100
- }
101
- }
@@ -1,290 +0,0 @@
1
- /**
2
- * Secret bundles — named sets of environment variables backed by a secret store.
3
- * Metadata lives under `agents-cli.bundles.<name>`; values under
4
- * `agents-cli.secrets.<bundle>.<key>`. Backends: `keychain` (default),
5
- * `file` (headless/passphrase), and `vault` (age-encrypted, user-synced).
6
- */
7
- import { type BundleValue, type SecretRef } from './index.js';
8
- /** Which store carries a bundle's items. */
9
- export type SecretsBackend = 'keychain' | 'file' | 'vault';
10
- /** Disable the broker-only guard for in-memory keychain tests. */
11
- export declare function setKeychainAgentOnlyBypassForTest(bypass: boolean): void;
12
- /**
13
- * Discover a bundle's backend by location. File store is checked first (a plain
14
- * existence test, no passphrase); absent/locked vault falls back to keychain.
15
- */
16
- export declare function bundleBackend(name: string): SecretsBackend;
17
- /** Allowed values for a secret's `type` metadata field. */
18
- export declare const SECRET_TYPES: readonly ["api-key", "token", "password", "url", "database-url", "ssh-key", "certificate", "webhook", "note"];
19
- export type SecretType = typeof SECRET_TYPES[number];
20
- /** Per-secret metadata; absent fields are omitted at write time. */
21
- export interface VarMeta {
22
- type?: SecretType;
23
- /** Future-dated ISO date ('YYYY-MM-DD'). */
24
- expires?: string;
25
- note?: string;
26
- }
27
- /**
28
- * Bundle prompt policy. `hold` (default): one Touch ID per hold window (~7d),
29
- * then silent via the secrets-agent. `always`: prompt every read. `never`: no
30
- * biometry ACL — least-safe, automation-only. Configurable via `secrets.policy`;
31
- * persisted under the legacy `tier` key for cross-version sync.
32
- */
33
- export type SecretsPolicy = 'always' | 'hold' | 'never';
34
- /** A named set of environment variable definitions backed by secret stores. */
35
- export interface SecretsBundle {
36
- name: string;
37
- description?: string;
38
- allow_exec?: boolean;
39
- /** Absent ⇒ `keychain`. */
40
- backend?: SecretsBackend;
41
- /** Absent ⇒ configured default (`hold`). */
42
- policy?: SecretsPolicy;
43
- created_at?: string;
44
- updated_at?: string;
45
- last_used?: string;
46
- vars: Record<string, BundleValue>;
47
- meta?: Record<string, VarMeta>;
48
- }
49
- export interface LegacyBundleCandidate {
50
- name: string;
51
- file: string;
52
- keys: string[];
53
- }
54
- export declare const BUNDLE_NAME_PATTERN: RegExp;
55
- export declare const ENV_KEY_PATTERN: RegExp;
56
- export declare const BUNDLE_KEY_PATTERN: RegExp;
57
- export declare const BUNDLE_META_PREFIX = "agents-cli.bundles.";
58
- export declare const RESERVED_ENV_NAMES: Set<string>;
59
- /**
60
- * Reserved FILE-BACKED bundle for long-lived setup tokens. Must be file-backed;
61
- * a keychain/vault `auth` bundle is a misconfiguration and is ignored.
62
- */
63
- export declare const AUTH_BUNDLE_NAME = "auth";
64
- export declare const AUTH_BUNDLE_BACKEND: SecretsBackend;
65
- export declare const RESERVED_BUNDLE_NAMES: Set<string>;
66
- export declare function isReservedBundleName(name: string): boolean;
67
- /** Thrown when a reserved bundle is written or resolved on the wrong backend. */
68
- export declare class ReservedBundleWrongBackendError extends Error {
69
- readonly bundle: string;
70
- readonly backend: SecretsBackend;
71
- constructor(bundle: string, backend: SecretsBackend);
72
- }
73
- /** Fail loud when a reserved bundle is on the wrong backend. */
74
- export declare function assertReservedBundleBackend(name: string, backend: SecretsBackend): void;
75
- /**
76
- * Check the reserved `auth` bundle. `ok` is true when absent or file-backed.
77
- *
78
- * Read-only status probe (`agents doctor`, `agents fleet apply`) — unlike the
79
- * destructive-write guards `bundleExists()`/`hasKeychainToken()` document
80
- * themselves as failing loud for, a diagnostic MUST NOT crash the whole
81
- * command because ONE optional finding could not reach the keychain (e.g. the
82
- * macOS Keychain helper source is unavailable — PHNX-3385). Treat an
83
- * unreachable keychain the same as "bundle absent": nothing to warn about.
84
- */
85
- export declare function inspectReservedAuthBundle(): {
86
- exists: boolean;
87
- backend: SecretsBackend | null;
88
- ok: boolean;
89
- };
90
- /**
91
- * After a file-backed import, verify the keys actually decrypt. Import used to
92
- * report success for ciphertext sealed under a forwarded passphrase this process
93
- * does not hold.
94
- */
95
- export declare function assertFileBundleDecryptable(name: string, keys: string[]): void;
96
- export declare function bundleToEnvPrefix(name: string): string;
97
- export declare function isReservedEnvName(key: string): boolean;
98
- export declare function bundleKeyToEnvKey(key: string): string;
99
- export declare function isLoaderOrInterpreterEnv(name: string): boolean;
100
- export declare function sanitizeProcessEnv(env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
101
- /** Validate a bundle name against the allowed pattern. Throws on invalid input. */
102
- export declare function validateBundleName(name: string): void;
103
- export declare function validateEnvKey(key: string): void;
104
- /** Assert that `t` is one of the known SECRET_TYPES. Throws with the allowed list otherwise. */
105
- export declare function validateSecretType(t: string): asserts t is SecretType;
106
- /**
107
- * Validate a future `expires` date. Accepts strict 'YYYY-MM-DD'; end-of-day UTC
108
- * means "today" is past.
109
- */
110
- export declare function validateExpiresFutureDated(iso: string): void;
111
- export declare function bundleExists(name: string): boolean;
112
- /**
113
- * Thrown for file-store ciphertext that will not decrypt (lost/rotated key or
114
- * tampered store). Narrow: temporarily-locked bundles are recoverable and must
115
- * not be collapsed here.
116
- */
117
- export declare class BundleUndecryptableError extends Error {
118
- constructor(message: string);
119
- }
120
- /**
121
- * Read a bundle, returning null only when metadata is present but permanently
122
- * unreadable (`BundleUndecryptableError`). Other failures — including temporary
123
- * lockout — rethrow so a healthy bundle is never deleted by mistake.
124
- */
125
- export declare function readBundleIfDecryptable(name: string): SecretsBundle | null;
126
- export declare function readBundle(name: string): SecretsBundle;
127
- /** Default policy for bundles without an explicit one (`secrets.policy`). */
128
- export declare function secretsDefaultPolicy(): SecretsPolicy;
129
- /** Effective prompt policy of a bundle. */
130
- export declare function bundlePolicy(bundle: SecretsBundle): SecretsPolicy;
131
- /** Options for writeBundle. */
132
- export interface WriteBundleOptions {
133
- /**
134
- * Skip evicting the broker-held copy. Only for no-op writers such as
135
- * stampLastUsed; mutating writes must evict so stale values aren't served.
136
- */
137
- skipBrokerEviction?: boolean;
138
- }
139
- /**
140
- * Whether a bundle write should evict the broker-held copy. Exported for tests.
141
- * Skips when the writer opted out, the broker is disabled, or a test backend is
142
- * active (so tests don't evict the user's real unlocks).
143
- */
144
- export declare function shouldEvictAfterBundleWrite(skipRequested: boolean, noAgentEnv: string | undefined, backendOverridden: boolean): boolean;
145
- export declare function writeBundle(bundle: SecretsBundle, opts?: WriteBundleOptions): void;
146
- export declare function writeBundleWithItems(bundle: SecretsBundle, items: Map<string, string>, opts?: WriteBundleOptions): void;
147
- export declare function deleteBundle(name: string): boolean;
148
- declare function readBundleMetaIndex(): string[] | null;
149
- declare function writeBundleMetaIndex(services: string[]): void;
150
- declare function addBundleToMetaIndex(name: string): void;
151
- declare function removeBundleFromMetaIndex(name: string): void;
152
- /** Test-only accessors for the metadata-name index. Never called in production. */
153
- export declare const __metaIndexForTest: {
154
- read: typeof readBundleMetaIndex;
155
- write: typeof writeBundleMetaIndex;
156
- add: typeof addBundleToMetaIndex;
157
- remove: typeof removeBundleFromMetaIndex;
158
- };
159
- /**
160
- * Re-write keychain metadata items without the biometry ACL. The caller supplies
161
- * the JSON already read, so contents are preserved and no extra read is issued.
162
- * Exported for tests.
163
- */
164
- export declare function healKeychainBundleMetadata(metaJsonByName: Map<string, string>): number;
165
- /**
166
- * One-time driver for healKeychainBundleMetadata. macOS + real keychain only;
167
- * gated by a sentinel. Best-effort: a heal failure never breaks listing.
168
- */
169
- export declare function healKeychainBundleMetadataAclOnce(metaJsonByName: Map<string, string>): void;
170
- export declare function listBundles(): SecretsBundle[];
171
- export interface BundleEntryInfo {
172
- key: string;
173
- kind: 'literal' | 'keychain' | 'env' | 'file' | 'exec';
174
- detail: string;
175
- }
176
- export declare function describeBundle(bundle: SecretsBundle): BundleEntryInfo[];
177
- export declare function stampLastUsed(bundle: SecretsBundle): void;
178
- /** Options for resolveBundleEnv. */
179
- export interface ResolveBundleOptions {
180
- caller?: string;
181
- /** Harness type whose unlock may be reused. */
182
- agent?: string;
183
- /** Duration shown in the Touch ID prompt. */
184
- duration?: string;
185
- /** Allow this call to raise an interactive biometric prompt. */
186
- interactiveUnlock?: boolean;
187
- /** Skip the broker fast-path and read from the keychain directly. */
188
- noAgent?: boolean;
189
- /** Resolve only from an already-unlocked broker snapshot; fail before prompting. */
190
- agentOnly?: boolean;
191
- /** Inject only these keys. Errors if any requested key is absent. */
192
- keys?: string[];
193
- /** Skip the per-key expiry gate. */
194
- allowExpired?: boolean;
195
- /** `process` projects dotted keys to shell-safe env names; `storage` preserves them. */
196
- keyMode?: 'process' | 'storage';
197
- }
198
- export declare function canCacheResolvedEnv(bundle: SecretsBundle, selectedKeys: Set<string>, keyMode: ResolveBundleOptions['keyMode']): boolean;
199
- /**
200
- * Apply --keys and --allow-expired to a broker snapshot so the fast path
201
- * mirrors the slow path's gates. Exported for tests.
202
- */
203
- export declare function filterAgentHitBySubsetAndExpiry(hit: {
204
- bundle: SecretsBundle;
205
- env: Record<string, string>;
206
- }, opts: ResolveBundleOptions): {
207
- bundle: SecretsBundle;
208
- env: Record<string, string>;
209
- };
210
- /**
211
- * Fail loud when remote bundle resolution is asked for flags the SSH resolver
212
- * does not yet thread. Exported so callers share the same error text.
213
- */
214
- export declare function assertRemoteBundleFlagsUnsupported(bundleName: string, host: string, opts: {
215
- keys?: string[];
216
- allowExpired?: boolean;
217
- }, flagLabels: {
218
- keysFlag: string;
219
- allowExpiredFlag: string;
220
- }): void;
221
- export declare function resolveBundleEnv(bundle: SecretsBundle, _opts?: ResolveBundleOptions): Record<string, string>;
222
- /**
223
- * True when the current process is a background / non-interactive context that
224
- * must NEVER raise a Keychain biometry prompt on the interactive user's screen.
225
- * Re-exported from ./headless.js — the detector lives there so the raw-read
226
- * path in index.ts can share it without a bundles↔index import cycle. See that
227
- * module for the full contract.
228
- */
229
- export { isHeadlessSecretsContext, isAgentInvocationContext } from './headless.js';
230
- /**
231
- * Read a bundle's metadata AND resolve its env in a single Touch ID prompt.
232
- * `readBundle` + `resolveBundleEnv` used to issue two LAContext calls (two
233
- * prompts). This collapses them into one batch that includes the metadata item.
234
- */
235
- export declare function readAndResolveBundleEnv(name: string, opts?: ResolveBundleOptions): {
236
- bundle: SecretsBundle;
237
- env: Record<string, string>;
238
- };
239
- export declare function humanUnlockDuration(ms: number): string;
240
- export declare function keychainRef(key: string): string;
241
- /** Options for rotateBundleSecret. */
242
- export interface RotateOptions {
243
- /** New plaintext value to write into keychain (replaces the old one). */
244
- newValue: string;
245
- /** When true, drop existing meta for this key. Mutually exclusive with `meta`. */
246
- clearMeta?: boolean;
247
- /** Patch to merge into existing meta. Undefined fields preserve current values. */
248
- meta?: Partial<VarMeta>;
249
- }
250
- /**
251
- * Rotate a keychain-backed secret. Errors if the key is absent; preserves meta
252
- * unless cleared or patched.
253
- */
254
- export declare function rotateBundleSecret(bundle: SecretsBundle, key: string, opts: RotateOptions): void;
255
- /**
256
- * Reconcile keychain value items to the bundle's current policy. macOS gates
257
- * reads on each item's ACL, not the bundle's declared policy, so a policy change
258
- * alone would leave stale ACLs. hold/always → never strips ACL; never → *
259
- * re-attaches it. Non-keychain backends no-op.
260
- */
261
- export declare function reAclBundleItems(bundle: SecretsBundle): void;
262
- /** Options for renameBundle. */
263
- export interface RenameOptions {
264
- /** Overwrite an existing destination bundle. */
265
- force?: boolean;
266
- }
267
- /**
268
- * Rename a bundle: copy metadata + keychain values to the new name, then delete
269
- * the source. Steps are ordered so a copy-phase failure leaves the source intact.
270
- */
271
- export declare function renameBundle(oldName: string, newName: string, opts?: RenameOptions): void;
272
- /**
273
- * The item store (keychain or encrypted file) for a bundle's per-key secrets.
274
- * Pass the resolved backend (`bundle.backend ?? 'keychain'`).
275
- */
276
- export declare function bundleItemStore(backend: SecretsBackend | undefined, opts?: {
277
- noAcl?: boolean;
278
- }): {
279
- set(item: string, value: string): void;
280
- delete(item: string): boolean;
281
- get(item: string): string;
282
- has(item: string): boolean;
283
- };
284
- export declare function keychainItemsForBundle(bundle: SecretsBundle): Array<{
285
- key: string;
286
- item: string;
287
- }>;
288
- export declare function parseDotenv(content: string): Record<string, string>;
289
- export declare function migrateLegacyBundles(confirmBundle: (candidate: LegacyBundleCandidate) => boolean | Promise<boolean>): Promise<number>;
290
- export type { SecretRef };