@agent-watch-ai/edge 0.2.5 → 0.3.1

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 (346) hide show
  1. package/CHANGELOG.md +512 -0
  2. package/README.md +217 -96
  3. package/SECURITY.md +69 -0
  4. package/dist/billing/session-billing.d.ts +19 -0
  5. package/dist/billing/session-billing.js +52 -0
  6. package/dist/cli/args.d.ts +10 -0
  7. package/dist/cli/args.js +20 -0
  8. package/dist/cli/constants/cli.constants.d.ts +50 -4
  9. package/dist/cli/constants/cli.constants.js +54 -5
  10. package/dist/cli/context.d.ts +33 -2
  11. package/dist/cli/context.js +84 -14
  12. package/dist/cli/doctor.js +309 -32
  13. package/dist/cli/hook-check.d.ts +23 -0
  14. package/dist/cli/hook-check.js +114 -0
  15. package/dist/cli/hook.js +118 -7
  16. package/dist/cli/index.d.ts +3 -1
  17. package/dist/cli/index.js +3 -1
  18. package/dist/cli/misc.d.ts +11 -0
  19. package/dist/cli/misc.js +80 -4
  20. package/dist/cli/npx-install.d.ts +37 -0
  21. package/dist/cli/npx-install.js +79 -0
  22. package/dist/cli/open-browser.d.ts +39 -0
  23. package/dist/cli/open-browser.js +62 -0
  24. package/dist/cli/setup.d.ts +17 -8
  25. package/dist/cli/setup.js +439 -98
  26. package/dist/cli/status.js +82 -13
  27. package/dist/cli/toggle.d.ts +9 -0
  28. package/dist/cli/toggle.js +113 -0
  29. package/dist/cli/types/cli.types.d.ts +37 -3
  30. package/dist/cli/ui.d.ts +7 -0
  31. package/dist/cli/ui.js +10 -1
  32. package/dist/cli/uninstall.js +39 -2
  33. package/dist/cli/update.d.ts +17 -0
  34. package/dist/cli/update.js +76 -0
  35. package/dist/cli.js +100 -13
  36. package/dist/config/config-store.d.ts +57 -0
  37. package/dist/config/config-store.js +250 -12
  38. package/dist/config/config.d.ts +53 -6
  39. package/dist/config/config.js +66 -6
  40. package/dist/config/constants/config.constants.d.ts +113 -6
  41. package/dist/config/constants/config.constants.js +126 -8
  42. package/dist/config/destination.d.ts +24 -0
  43. package/dist/config/destination.js +33 -0
  44. package/dist/config/index.d.ts +7 -4
  45. package/dist/config/index.js +5 -3
  46. package/dist/config/repo-config.d.ts +11 -7
  47. package/dist/config/repo-config.js +64 -15
  48. package/dist/config/root-config.d.ts +72 -0
  49. package/dist/config/root-config.js +170 -0
  50. package/dist/config/schemas/config.schema.d.ts +721 -84
  51. package/dist/config/schemas/config.schema.js +388 -15
  52. package/dist/config/types/config.types.d.ts +15 -1
  53. package/dist/config/types/destination.types.d.ts +8 -0
  54. package/dist/core/async.d.ts +36 -0
  55. package/dist/core/async.js +68 -0
  56. package/dist/core/index.d.ts +1 -1
  57. package/dist/core/index.js +1 -1
  58. package/dist/core/object.d.ts +5 -0
  59. package/dist/core/object.js +9 -4
  60. package/dist/core/pipe.d.ts +0 -13
  61. package/dist/core/pipe.js +1 -9
  62. package/dist/core/types/core.types.d.ts +9 -0
  63. package/dist/core/types/core.types.js +0 -3
  64. package/dist/core/which.d.ts +14 -0
  65. package/dist/core/which.js +43 -3
  66. package/dist/credentials/budget.d.ts +9 -0
  67. package/dist/credentials/budget.js +16 -0
  68. package/dist/credentials/command-runner.d.ts +16 -0
  69. package/dist/credentials/command-runner.js +37 -0
  70. package/dist/credentials/constants/credentials.constants.d.ts +111 -0
  71. package/dist/credentials/constants/credentials.constants.js +112 -0
  72. package/dist/credentials/credential-status.d.ts +14 -0
  73. package/dist/credentials/credential-status.js +34 -0
  74. package/dist/credentials/credentials.d.ts +72 -0
  75. package/dist/credentials/credentials.js +253 -0
  76. package/dist/credentials/device-api.d.ts +64 -0
  77. package/dist/credentials/device-api.js +150 -0
  78. package/dist/credentials/device-state.d.ts +31 -0
  79. package/dist/credentials/device-state.js +51 -0
  80. package/dist/credentials/identity.d.ts +62 -0
  81. package/dist/credentials/identity.js +90 -0
  82. package/dist/credentials/index.d.ts +7 -0
  83. package/dist/credentials/index.js +5 -0
  84. package/dist/credentials/migration.d.ts +46 -0
  85. package/dist/credentials/migration.js +164 -0
  86. package/dist/credentials/schemas/device-api.schema.d.ts +77 -0
  87. package/dist/credentials/schemas/device-api.schema.js +33 -0
  88. package/dist/credentials/schemas/device-state.schema.d.ts +51 -0
  89. package/dist/credentials/schemas/device-state.schema.js +20 -0
  90. package/dist/credentials/secret-store.d.ts +54 -0
  91. package/dist/credentials/secret-store.js +217 -0
  92. package/dist/credentials/sign-in.d.ts +18 -0
  93. package/dist/credentials/sign-in.js +86 -0
  94. package/dist/credentials/token-refresher.d.ts +39 -0
  95. package/dist/credentials/token-refresher.js +185 -0
  96. package/dist/credentials/types/credentials.types.d.ts +195 -0
  97. package/dist/credentials/types/credentials.types.js +1 -0
  98. package/dist/enforcement/constants/enforcement.constants.d.ts +47 -1
  99. package/dist/enforcement/constants/enforcement.constants.js +56 -0
  100. package/dist/enforcement/decision-cache.d.ts +20 -1
  101. package/dist/enforcement/decision-cache.js +65 -2
  102. package/dist/enforcement/decision-client.d.ts +9 -8
  103. package/dist/enforcement/decision-client.js +62 -16
  104. package/dist/enforcement/enforcement.d.ts +23 -2
  105. package/dist/enforcement/enforcement.js +103 -15
  106. package/dist/enforcement/index.d.ts +4 -3
  107. package/dist/enforcement/index.js +3 -2
  108. package/dist/enforcement/types/enforcement.types.d.ts +64 -0
  109. package/dist/enrollment/constants/enrollment.constants.d.ts +2 -6
  110. package/dist/enrollment/constants/enrollment.constants.js +2 -6
  111. package/dist/enrollment/enrollment.d.ts +16 -0
  112. package/dist/enrollment/enrollment.js +54 -0
  113. package/dist/enrollment/index.d.ts +3 -7
  114. package/dist/enrollment/index.js +1 -1
  115. package/dist/enrollment/types/enrollment.types.d.ts +9 -13
  116. package/dist/events/constants/enrich.constants.d.ts +15 -0
  117. package/dist/events/constants/enrich.constants.js +15 -0
  118. package/dist/events/constants/events.constants.d.ts +6 -2
  119. package/dist/events/constants/events.constants.js +5 -1
  120. package/dist/events/enrich.js +92 -10
  121. package/dist/events/event-id.d.ts +0 -8
  122. package/dist/events/event-id.js +0 -10
  123. package/dist/events/index.d.ts +2 -2
  124. package/dist/events/index.js +1 -1
  125. package/dist/events/product-event.d.ts +9 -6
  126. package/dist/events/types/repo-snapshot.types.d.ts +7 -0
  127. package/dist/events/types/session-billing.types.d.ts +16 -0
  128. package/dist/events/types/session-billing.types.js +1 -0
  129. package/dist/feature/constants/feature.constants.d.ts +7 -0
  130. package/dist/feature/constants/feature.constants.js +7 -0
  131. package/dist/feature/index.d.ts +1 -1
  132. package/dist/feature/index.js +1 -1
  133. package/dist/feature/ticket-candidates.d.ts +14 -0
  134. package/dist/feature/ticket-candidates.js +26 -8
  135. package/dist/git/blob-hash.d.ts +21 -0
  136. package/dist/git/blob-hash.js +69 -0
  137. package/dist/git/checkout-root.d.ts +27 -0
  138. package/dist/git/checkout-root.js +75 -0
  139. package/dist/git/constants/git.constants.d.ts +160 -0
  140. package/dist/git/constants/git.constants.js +181 -0
  141. package/dist/git/fingerprint.d.ts +74 -0
  142. package/dist/git/fingerprint.js +219 -0
  143. package/dist/git/gate-checkout.d.ts +44 -0
  144. package/dist/git/gate-checkout.js +201 -0
  145. package/dist/git/git-context.d.ts +45 -0
  146. package/dist/git/git-context.js +61 -3
  147. package/dist/git/index.d.ts +4 -2
  148. package/dist/git/index.js +2 -1
  149. package/dist/git/manifest-repository.d.ts +13 -0
  150. package/dist/git/manifest-repository.js +92 -0
  151. package/dist/git/repo-snapshot.d.ts +29 -3
  152. package/dist/git/repo-snapshot.js +110 -7
  153. package/dist/git/repository-root.d.ts +39 -0
  154. package/dist/git/repository-root.js +131 -0
  155. package/dist/git/types/git.types.d.ts +55 -0
  156. package/dist/git/types/repository-root.types.d.ts +11 -0
  157. package/dist/git/types/repository-root.types.js +1 -0
  158. package/dist/git/types/snapshot.types.d.ts +9 -0
  159. package/dist/pipeline/constants/pipeline.constants.d.ts +7 -0
  160. package/dist/pipeline/constants/pipeline.constants.js +7 -0
  161. package/dist/pipeline/hook-pipeline.js +360 -32
  162. package/dist/pipeline/types/pipeline.types.d.ts +39 -4
  163. package/dist/privacy/constants/privacy.constants.js +15 -1
  164. package/dist/privacy/index.d.ts +1 -0
  165. package/dist/privacy/index.js +1 -0
  166. package/dist/privacy/product-capture.d.ts +12 -0
  167. package/dist/privacy/product-capture.js +73 -0
  168. package/dist/privacy/sanitizer.d.ts +21 -3
  169. package/dist/privacy/sanitizer.js +52 -8
  170. package/dist/process/ancestors.d.ts +39 -0
  171. package/dist/process/ancestors.js +121 -0
  172. package/dist/process/constants/process.constants.d.ts +34 -0
  173. package/dist/process/constants/process.constants.js +34 -0
  174. package/dist/process/index.d.ts +7 -0
  175. package/dist/process/index.js +2 -0
  176. package/dist/process/types/process.types.d.ts +23 -0
  177. package/dist/process/types/process.types.js +1 -0
  178. package/dist/providers/antigravity/antigravity.adapter.d.ts +12 -1
  179. package/dist/providers/antigravity/antigravity.adapter.js +21 -3
  180. package/dist/providers/antigravity/antigravity.detect.d.ts +0 -9
  181. package/dist/providers/antigravity/antigravity.detect.js +1 -1
  182. package/dist/providers/antigravity/antigravity.provider.js +3 -2
  183. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +2 -0
  184. package/dist/providers/antigravity/constants/antigravity.constants.js +2 -0
  185. package/dist/providers/claude/claude.adapter.d.ts +11 -1
  186. package/dist/providers/claude/claude.adapter.js +26 -5
  187. package/dist/providers/claude/claude.otel.d.ts +32 -18
  188. package/dist/providers/claude/claude.otel.js +81 -6
  189. package/dist/providers/claude/claude.provider.js +5 -2
  190. package/dist/providers/claude/constants/claude.constants.d.ts +2 -0
  191. package/dist/providers/claude/constants/claude.constants.js +2 -0
  192. package/dist/providers/claude/constants/claude.otel.constants.d.ts +4 -0
  193. package/dist/providers/claude/constants/claude.otel.constants.js +8 -0
  194. package/dist/providers/codex/codex.adapter.d.ts +15 -1
  195. package/dist/providers/codex/codex.adapter.js +29 -5
  196. package/dist/providers/codex/codex.otel.d.ts +24 -2
  197. package/dist/providers/codex/codex.otel.js +147 -30
  198. package/dist/providers/codex/codex.provider.js +5 -2
  199. package/dist/providers/codex/constants/codex.constants.d.ts +2 -0
  200. package/dist/providers/codex/constants/codex.constants.js +16 -0
  201. package/dist/providers/codex/constants/codex.otel.constants.d.ts +5 -0
  202. package/dist/providers/codex/constants/codex.otel.constants.js +5 -0
  203. package/dist/providers/constants/provider.constants.d.ts +0 -3
  204. package/dist/providers/constants/provider.constants.js +0 -3
  205. package/dist/providers/cursor/constants/cursor.constants.d.ts +7 -0
  206. package/dist/providers/cursor/constants/cursor.constants.js +7 -0
  207. package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
  208. package/dist/providers/cursor/cursor.adapter.js +52 -3
  209. package/dist/providers/cursor/cursor.detect.d.ts +0 -7
  210. package/dist/providers/cursor/cursor.detect.js +1 -1
  211. package/dist/providers/cursor/cursor.provider.js +5 -2
  212. package/dist/providers/gemini/constants/gemini.constants.d.ts +9 -0
  213. package/dist/providers/gemini/constants/gemini.constants.js +9 -0
  214. package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +3 -1
  215. package/dist/providers/gemini/constants/gemini.otel.constants.js +3 -0
  216. package/dist/providers/gemini/gemini.adapter.d.ts +14 -1
  217. package/dist/providers/gemini/gemini.adapter.js +25 -5
  218. package/dist/providers/gemini/gemini.detect.d.ts +0 -7
  219. package/dist/providers/gemini/gemini.detect.js +1 -1
  220. package/dist/providers/gemini/gemini.otel.d.ts +19 -20
  221. package/dist/providers/gemini/gemini.otel.js +121 -17
  222. package/dist/providers/gemini/gemini.provider.js +2 -1
  223. package/dist/providers/index.d.ts +1 -1
  224. package/dist/providers/index.js +1 -1
  225. package/dist/providers/loaders.d.ts +10 -0
  226. package/dist/providers/loaders.js +40 -0
  227. package/dist/providers/provider.d.ts +11 -0
  228. package/dist/providers/provider.js +1 -1
  229. package/dist/providers/registry.d.ts +11 -8
  230. package/dist/providers/registry.js +11 -15
  231. package/dist/providers/shared/constants/hook-refusal.constants.d.ts +7 -0
  232. package/dist/providers/shared/constants/hook-refusal.constants.js +7 -0
  233. package/dist/providers/shared/constants/shell-directories.constants.d.ts +30 -0
  234. package/dist/providers/shared/constants/shell-directories.constants.js +39 -0
  235. package/dist/providers/shared/constants/tooling.constants.d.ts +18 -2
  236. package/dist/providers/shared/constants/tooling.constants.js +19 -3
  237. package/dist/providers/shared/event-builder.d.ts +12 -14
  238. package/dist/providers/shared/event-builder.js +20 -14
  239. package/dist/providers/shared/exporter-allowlist.d.ts +20 -0
  240. package/dist/providers/shared/exporter-allowlist.js +49 -0
  241. package/dist/providers/shared/hook-config.d.ts +2 -21
  242. package/dist/providers/shared/hook-config.js +5 -4
  243. package/dist/providers/shared/hook-refusal.d.ts +12 -0
  244. package/dist/providers/shared/hook-refusal.js +17 -1
  245. package/dist/providers/shared/install-record.d.ts +12 -2
  246. package/dist/providers/shared/install-record.js +5 -2
  247. package/dist/providers/shared/shell-directories.d.ts +24 -0
  248. package/dist/providers/shared/shell-directories.js +90 -0
  249. package/dist/providers/shared/tooling.d.ts +12 -1
  250. package/dist/providers/shared/tooling.js +18 -0
  251. package/dist/providers/shared/types/adapter.types.d.ts +1 -2
  252. package/dist/providers/types/provider.types.d.ts +57 -1
  253. package/dist/snapshot/constants/snapshot.constants.d.ts +32 -0
  254. package/dist/snapshot/constants/snapshot.constants.js +33 -0
  255. package/dist/snapshot/snapshot-event.js +52 -11
  256. package/dist/snapshot/snapshot-pipeline.js +1 -1
  257. package/dist/snapshot/types/snapshot.types.d.ts +2 -0
  258. package/dist/storage/atomic-file.d.ts +7 -0
  259. package/dist/storage/atomic-file.js +1 -1
  260. package/dist/storage/constants/storage.constants.d.ts +17 -0
  261. package/dist/storage/constants/storage.constants.js +17 -0
  262. package/dist/storage/disabled.d.ts +13 -0
  263. package/dist/storage/disabled.js +24 -0
  264. package/dist/storage/index.d.ts +2 -0
  265. package/dist/storage/index.js +2 -0
  266. package/dist/storage/paths.js +3 -2
  267. package/dist/storage/schemas/storage.schema.d.ts +72 -0
  268. package/dist/storage/schemas/storage.schema.js +6 -0
  269. package/dist/storage/sweep-marker.d.ts +19 -0
  270. package/dist/storage/sweep-marker.js +55 -0
  271. package/dist/storage/types/storage.types.d.ts +2 -0
  272. package/dist/storage/uninstalled.d.ts +58 -0
  273. package/dist/storage/uninstalled.js +107 -0
  274. package/dist/transport/auth-block.d.ts +66 -0
  275. package/dist/transport/auth-block.js +129 -0
  276. package/dist/transport/constants/transport.constants.d.ts +82 -3
  277. package/dist/transport/constants/transport.constants.js +83 -4
  278. package/dist/transport/cooldown.js +8 -1
  279. package/dist/transport/delivery.d.ts +14 -6
  280. package/dist/transport/delivery.js +80 -55
  281. package/dist/transport/http-transport.d.ts +1 -0
  282. package/dist/transport/http-transport.js +52 -10
  283. package/dist/transport/index.d.ts +6 -3
  284. package/dist/transport/index.js +3 -0
  285. package/dist/transport/queue-partition.d.ts +91 -0
  286. package/dist/transport/queue-partition.js +143 -0
  287. package/dist/transport/queue.d.ts +99 -20
  288. package/dist/transport/queue.js +210 -69
  289. package/dist/transport/response-body.d.ts +25 -0
  290. package/dist/transport/response-body.js +64 -0
  291. package/dist/transport/send.d.ts +11 -0
  292. package/dist/transport/send.js +17 -0
  293. package/dist/transport/types/delivery-flow.types.d.ts +19 -0
  294. package/dist/transport/types/delivery-flow.types.js +1 -0
  295. package/dist/transport/types/transport.types.d.ts +45 -0
  296. package/dist/turns/claude-transcript.d.ts +19 -1
  297. package/dist/turns/claude-transcript.js +46 -1
  298. package/dist/turns/codex-originator.d.ts +11 -0
  299. package/dist/turns/codex-originator.js +31 -0
  300. package/dist/turns/codex-transcript.d.ts +30 -0
  301. package/dist/turns/codex-transcript.js +88 -0
  302. package/dist/turns/constants/turns.constants.d.ts +141 -5
  303. package/dist/turns/constants/turns.constants.js +155 -5
  304. package/dist/turns/file-identity.d.ts +27 -0
  305. package/dist/turns/file-identity.js +48 -0
  306. package/dist/turns/gemini-transcript.d.ts +30 -0
  307. package/dist/turns/gemini-transcript.js +96 -0
  308. package/dist/turns/index.d.ts +3 -3
  309. package/dist/turns/index.js +1 -1
  310. package/dist/turns/inherited-checkout.d.ts +54 -0
  311. package/dist/turns/inherited-checkout.js +155 -0
  312. package/dist/turns/native-session-titles.d.ts +26 -0
  313. package/dist/turns/native-session-titles.js +102 -0
  314. package/dist/turns/transcript.d.ts +3 -2
  315. package/dist/turns/transcript.js +5 -1
  316. package/dist/turns/turn-state.d.ts +224 -3
  317. package/dist/turns/turn-state.js +456 -21
  318. package/dist/turns/turn-summary.d.ts +1 -14
  319. package/dist/turns/turn-summary.js +87 -51
  320. package/dist/turns/turn-tracker.d.ts +21 -2
  321. package/dist/turns/turn-tracker.js +379 -56
  322. package/dist/turns/types/transcript.types.d.ts +5 -0
  323. package/dist/turns/types/turn-state.types.d.ts +116 -5
  324. package/dist/turns/types/turn-summary.types.d.ts +64 -14
  325. package/dist/turns/types/turn-tracker.types.d.ts +27 -1
  326. package/dist/turns/work-checkout.d.ts +65 -0
  327. package/dist/turns/work-checkout.js +666 -0
  328. package/dist/untraced/constants/untraced.constants.d.ts +31 -0
  329. package/dist/untraced/constants/untraced.constants.js +63 -0
  330. package/dist/untraced/untraced.d.ts +35 -0
  331. package/dist/untraced/untraced.js +105 -0
  332. package/dist/update/constants/update.constants.d.ts +18 -0
  333. package/dist/update/constants/update.constants.js +20 -0
  334. package/dist/update/update-check.d.ts +52 -0
  335. package/dist/update/update-check.js +113 -0
  336. package/docs/AUDIT_PROMPT.md +129 -0
  337. package/docs/DATA_HANDLING.md +648 -0
  338. package/docs/ENTERPRISE_DEPLOYMENT.md +179 -0
  339. package/docs/PERFORMANCE.md +81 -0
  340. package/package.json +14 -4
  341. package/dist/enrollment/enrollment-provider.d.ts +0 -5
  342. package/dist/enrollment/manual-enrollment.d.ts +0 -32
  343. package/dist/enrollment/manual-enrollment.js +0 -72
  344. package/example/README.md +0 -43
  345. package/example/server.mjs +0 -240
  346. /package/dist/{enrollment/enrollment-provider.js → config/types/destination.types.js} +0 -0
package/dist/cli.js CHANGED
@@ -1,46 +1,66 @@
1
1
  #!/usr/bin/env node
2
2
  import process from 'node:process';
3
+ import { hasAbandonedWork } from './core/async.js';
3
4
  import { realEnv } from './core/env.js';
4
5
  import { setVerbose } from './core/logger.js';
5
6
  // Parsing lives in its own module so tests can import it without executing
6
7
  // main(); command modules stay lazily loaded off the hook critical path.
7
- import { boolFlag, parseArgs, stringFlag } from './cli/args.js';
8
+ import { boolFlag, parseArgs, stringFlag, valuelessFlags } from './cli/args.js';
8
9
  const HELP = `agentwatch — telemetry edge for AI coding agents
9
10
 
10
11
  Usage:
11
- agentwatch setup [enrollment-url] [--endpoint <url>] [--token <token>] [--developer-email <email>] [--otel <signals>] [--yes]
12
+ agentwatch setup [enrollment-url] [--endpoint <url>] [--allow-custom-endpoint] [--no-browser] [--token <token>] [--developer-email <email>] [--developer-name <name>] [--root <path>] [--otel <signals>]
12
13
  agentwatch status
14
+ agentwatch off
15
+ agentwatch on
13
16
  agentwatch doctor [--json]
14
17
  agentwatch uninstall [--agent <id>] [--purge]
18
+ agentwatch update [--check]
15
19
  agentwatch hook --agent <id> [--dry-run] (invoked by agents; reads stdin)
16
20
  agentwatch agents
17
21
  agentwatch config
18
22
  agentwatch otel-headers
19
23
 
20
24
  Flags:
21
- --endpoint <url> backend base URL events are sent to
22
- --token <token> bearer token for the backend
25
+ --endpoint <url> backend base URL events are sent to: an Agent Watch host, or
26
+ loopback for local development (default: https://api.agent-watch.ai)
27
+ --allow-custom-endpoint trust an --endpoint outside the Agent Watch hosts (self-hosted or
28
+ proxied backend). Stored in the config and shown by status and doctor
29
+ --no-browser with an enrollment URL, print the sign-in link without opening a
30
+ browser (never opened anyway under CI, over SSH or without a terminal)
31
+ --token <token> bearer token for the backend; $AGENTWATCH_TOKEN is the private
32
+ channel for an MDM run, where argv is visible to ps
23
33
  --developer-email <email> identity attached to turn summaries and keyed on by per-developer
24
34
  enforcement (default: git config user.email; setup fails when neither
25
35
  names a developer)
36
+ --developer-name <name> what to call this developer in the platform's views (default:
37
+ git config user.name). Never an identity: nothing is keyed on it,
38
+ and leaving it unset keeps whatever name the platform already has
39
+ --root <path> file this tenant's identity under a project root instead of the
40
+ machine default, so one machine can report to two tenants: work
41
+ at or below <path> uses this token, everything else keeps the
42
+ machine's own. Longest matching root wins
26
43
  --otel <signals> native OTLP signals agents export to the backend: comma list of
27
44
  logs,traces,metrics, or "all"/"none" (default: logs — the
28
45
  per-request usage/cost ledger the backend turns into llm.call)
29
- --yes non-interactive: never prompt, fail if required values are missing
30
- (alias: --non-interactive)
31
46
  --agent <id> limit the command to one agent (claude | codex | cursor)
32
47
  --purge uninstall: also delete ~/.agentwatch and queued local data
33
48
  --dry-run hook: print resulting events to stdout instead of sending
34
49
  --json doctor: machine-readable output
50
+ --check update: only say whether a newer release exists
35
51
  --verbose extra diagnostics on stderr
36
52
  --version print version
37
53
 
38
54
  Configuration:
39
55
  global ~/.agentwatch/config.json (written by setup)
40
56
  per repository .agentwatch.json in the repo root — overrides the global
41
- config for work in that repo; "token", "installationId",
42
- "developerEmail", "endpoint", "eventsUrl" and "otlpUrl"
43
- are global-only and ignored there
57
+ config for work in that repo; "token", "device", "installationId",
58
+ "developerEmail", "developerName", "endpoint", "eventsUrl",
59
+ "otlpUrl" and
60
+ "roots" are global-only and ignored there
61
+ per project root "roots" in the global config — absolute path to the identity
62
+ used beneath it (see --root). Identity only: what is captured
63
+ stays machine-wide
44
64
  `;
45
65
  /**
46
66
  * Dispatch one CLI invocation.
@@ -55,22 +75,43 @@ async function main() {
55
75
  const parsed = parseArgs(process.argv.slice(2));
56
76
  if (boolFlag(parsed, 'verbose'))
57
77
  setVerbose(true);
78
+ // Before any command runs: `setup --help` used to run setup. A hook's argv is the agent's, not a person's.
79
+ if (boolFlag(parsed, 'help') && parsed.command !== 'hook' && parsed.command !== 'refresh-credential') {
80
+ process.stdout.write(HELP);
81
+ return 0;
82
+ }
58
83
  const env = realEnv();
59
84
  switch (parsed.command) {
85
+ case 'off':
86
+ case 'on': {
87
+ const { runToggle } = await import('./cli/toggle.js');
88
+ return runToggle(env, parsed.command === 'on');
89
+ }
60
90
  case 'hook': {
61
91
  const { runHook } = await import('./cli/hook.js');
62
92
  return runHook(stringFlag(parsed, 'agent') ?? '', { env, dryRun: boolFlag(parsed, 'dry-run') });
63
93
  }
64
94
  case 'setup': {
95
+ const valueless = valuelessFlags(parsed);
96
+ if (valueless.length > 0) {
97
+ process.stderr.write(`agentwatch setup: ${valueless.map((name) => `--${name}`).join(', ')} needs a value\n`);
98
+ return 1;
99
+ }
100
+ const { installGloballyAndHandOff, isNpxRun } = await import('./cli/npx-install.js');
101
+ if (isNpxRun(process.argv[1], process.env))
102
+ return installGloballyAndHandOff(process.argv.slice(2));
65
103
  const { runSetup } = await import('./cli/setup.js');
66
104
  return runSetup({
67
105
  env,
68
106
  setupUrl: parsed.positional[0],
69
107
  endpoint: stringFlag(parsed, 'endpoint'),
108
+ allowCustomEndpoint: boolFlag(parsed, 'allow-custom-endpoint'),
109
+ noBrowser: boolFlag(parsed, 'no-browser'),
70
110
  token: stringFlag(parsed, 'token'),
71
111
  developerEmail: stringFlag(parsed, 'developer-email'),
72
- otel: stringFlag(parsed, 'otel'),
73
- yes: boolFlag(parsed, 'yes') || boolFlag(parsed, 'non-interactive')
112
+ developerName: stringFlag(parsed, 'developer-name'),
113
+ root: stringFlag(parsed, 'root'),
114
+ otel: stringFlag(parsed, 'otel')
74
115
  });
75
116
  }
76
117
  case 'status': {
@@ -85,6 +126,10 @@ async function main() {
85
126
  const { runUninstall } = await import('./cli/uninstall.js');
86
127
  return runUninstall({ env, agent: stringFlag(parsed, 'agent'), purge: boolFlag(parsed, 'purge') });
87
128
  }
129
+ case 'update': {
130
+ const { runUpdate } = await import('./cli/update.js');
131
+ return runUpdate(env, boolFlag(parsed, 'check'));
132
+ }
88
133
  case 'agents': {
89
134
  const { runAgents } = await import('./cli/misc.js');
90
135
  return runAgents(env);
@@ -97,6 +142,11 @@ async function main() {
97
142
  const { runOtelHeaders } = await import('./cli/misc.js');
98
143
  return runOtelHeaders(env);
99
144
  }
145
+ // Started detached by a Windows hook; not listed in the help.
146
+ case 'refresh-credential': {
147
+ const { runRefreshCredential } = await import('./cli/misc.js');
148
+ return runRefreshCredential(env);
149
+ }
100
150
  default:
101
151
  return runFallback(parsed);
102
152
  }
@@ -117,8 +167,45 @@ async function runFallback(parsed) {
117
167
  process.stdout.write(HELP);
118
168
  return parsed.command === undefined || parsed.command === 'help' ? 0 : 1;
119
169
  }
120
- main().then((code) => process.exit(code), (error) => {
170
+ /**
171
+ * Wait for anything still queued on a stream to reach the other end of the pipe.
172
+ *
173
+ * The hook's stdout *is* the agent protocol: a budget refusal travels as a
174
+ * `block` JSON document, and for Antigravity an empty stdout means "no decision
175
+ * at all". On POSIX a write to a pipe is asynchronous and `process.exit` drops
176
+ * whatever is still queued, so the exit waits for the drain instead of racing
177
+ * it. A zero-length write is enough — its callback runs behind every write
178
+ * already in the queue.
179
+ *
180
+ * @param stream - The stream to drain.
181
+ * @returns Resolves once the queue is empty.
182
+ */
183
+ async function drain(stream) {
184
+ if (stream.writableLength === 0)
185
+ return;
186
+ await new Promise((resolve) => stream.write('', () => resolve()));
187
+ }
188
+ /**
189
+ * Exit once the answer has actually been handed to the agent.
190
+ *
191
+ * @param code - The exit code to leave with.
192
+ */
193
+ async function exitAfterFlush(code) {
194
+ await drain(process.stdout);
195
+ await drain(process.stderr);
196
+ // A budgeted read still hung on a stuck mount keeps `process.exit` from
197
+ // returning (Node cannot cancel a read in the thread pool), so the hook would
198
+ // hold the agent until the mount answers. Only then, and only here: main() has
199
+ // returned, so every queue entry is already fsynced, closed and renamed into
200
+ // place, and the answer has drained. The cost is an exit by signal instead of
201
+ // `code`: the agent sees a failed hook, as it would at its own hook timeout,
202
+ // only sooner and with the turn already queued.
203
+ if (hasAbandonedWork())
204
+ process.kill(process.pid, 'SIGKILL');
205
+ return process.exit(code);
206
+ }
207
+ main().then((code) => exitAfterFlush(code), (error) => {
121
208
  process.stderr.write(`[agentwatch] fatal: ${error.stack ?? error}\n`);
122
209
  // A crashing hook must not break the calling agent.
123
- process.exit(process.argv[2] === 'hook' ? 0 : 1);
210
+ return exitAfterFlush(process.argv[2] === 'hook' ? 0 : 1);
124
211
  });
@@ -1,3 +1,4 @@
1
+ import type { DeviceCredentialRef } from '../credentials/types/credentials.types.js';
1
2
  import type { AgentWatchPaths } from '../storage/types/storage.types.js';
2
3
  import type { AgentWatchConfig, ConfigLoadResult } from './types/config.types.js';
3
4
  export type { ConfigLoadResult } from './types/config.types.js';
@@ -20,6 +21,62 @@ export declare function loadConfig(paths: AgentWatchPaths): Promise<ConfigLoadRe
20
21
  * @param config - Config to write.
21
22
  */
22
23
  export declare function saveConfig(paths: AgentWatchPaths, config: AgentWatchConfig): Promise<void>;
24
+ /**
25
+ * Change config.json under the config lock, from what is on disk now.
26
+ *
27
+ * Every writer that can race another takes this path: a hook's exchange,
28
+ * setup, uninstall. The change is computed from the file as read under the
29
+ * lock, never from a copy loaded earlier, so one writer cannot erase what
30
+ * another wrote in between (a device a hook attached while setup was
31
+ * prompting, say).
32
+ *
33
+ * @param paths - Resolved AgentWatch paths.
34
+ * @param change - The new config from the current load, or undefined for no write.
35
+ * @param options - How long to wait for the lock (none by default) and the clock.
36
+ * @param options.waitMs - Wait this long for a lock another process holds.
37
+ * @param options.now - Clock for the lock stamp.
38
+ * @returns `saved`, `unchanged` when `change` declined, or `busy` when the lock stayed taken.
39
+ */
40
+ export declare function updateConfig(paths: AgentWatchPaths, change: (current: ConfigLoadResult) => AgentWatchConfig | undefined, options?: {
41
+ readonly waitMs?: number;
42
+ readonly now?: () => Date;
43
+ }): Promise<'saved' | 'unchanged' | 'busy'>;
44
+ /**
45
+ * Record the device an install key was exchanged for, beside that key,
46
+ * wherever the file holds it: the machine entry and every root sharing it.
47
+ *
48
+ * The key stays: Codex and Gemini still present it (AWT-357 retires it).
49
+ *
50
+ * @param paths - Resolved AgentWatch paths.
51
+ * @param installKey - The key that was exchanged.
52
+ * @param device - Where its device secret now lives.
53
+ * @param waitMs - How long to wait for the config lock.
54
+ * @returns What {@link updateConfig} did.
55
+ */
56
+ export declare function attachDevice(paths: AgentWatchPaths, installKey: string, device: DeviceCredentialRef, waitMs: number): Promise<'saved' | 'unchanged' | 'busy'>;
57
+ /**
58
+ * A config about to be written, with the devices the file on disk already
59
+ * holds for its install keys laid back in.
60
+ *
61
+ * For setup, which computed its config from a load taken before its prompts:
62
+ * a hook may have exchanged the key since. Only a device filed under the
63
+ * entry's own key comes back; a new key starts without one.
64
+ *
65
+ * @param next - What setup is about to write.
66
+ * @param stored - The config on disk now.
67
+ * @returns `next`, with those devices.
68
+ */
69
+ export declare function withStoredDevices(next: AgentWatchConfig, stored: AgentWatchConfig): AgentWatchConfig;
70
+ /**
71
+ * The retired prompt/response flags the file on disk still carries.
72
+ *
73
+ * They collect nothing whatever their value; this exists so `setup` can say once
74
+ * that it is removing them and `doctor` can say they are still written.
75
+ *
76
+ * @param paths - Resolved AgentWatch paths.
77
+ * @returns The retired keys present in `capture`; empty when there are none.
78
+ */
79
+ export declare function storedRetiredCapture(paths: AgentWatchPaths): Promise<string[]>;
23
80
  /**
24
81
  * The config with an installation id, generating one on first use.
25
82
  *
@@ -1,9 +1,14 @@
1
1
  import crypto from 'node:crypto';
2
+ import { pollUntil } from '../core/async.js';
3
+ import { asRecord } from '../core/object.js';
4
+ import { credentialId, deviceRefs } from '../credentials/identity.js';
5
+ import { acquireLock } from '../storage/lock.js';
2
6
  import { readJsonFile } from '../storage/json-file.js';
3
7
  import { writeFileAtomic } from '../storage/atomic-file.js';
4
8
  import { SECRET_FILE_MODE } from '../storage/constants/storage.constants.js';
9
+ import { ALLOWLIST_VERSION, ALLOWLIST_VERSION_KEY, CONFIG_LOCK, CONFIG_LOCK_POLL_MS, CONTENT_CAPTURE_KEYS, CUSTOM_ENDPOINTS_KEY, RETIRED_CAPTURE_KEYS, ROOT_URL_FIELDS, URL_FIELDS } from './constants/config.constants.js';
5
10
  import { defaultConfig } from './config.js';
6
- import { configSchema } from './schemas/config.schema.js';
11
+ import { configSchema, screenConfigUrls } from './schemas/config.schema.js';
7
12
  /**
8
13
  * Read the global config.
9
14
  *
@@ -18,13 +23,52 @@ import { configSchema } from './schemas/config.schema.js';
18
23
  export async function loadConfig(paths) {
19
24
  const result = await readJsonFile(paths.configFile);
20
25
  if (result.state === 'missing')
21
- return { state: 'missing', config: fallbackConfig() };
26
+ return { state: 'missing', config: fallbackConfig(), warnings: [] };
22
27
  if (result.state === 'invalid')
23
- return { state: 'invalid', error: result.error, config: fallbackConfig() };
24
- const parsed = configSchema.safeParse(result.value);
28
+ return { state: 'invalid', error: result.error, config: fallbackConfig(), warnings: [] };
29
+ // A refused URL is nulled rather than failing the whole file — see
30
+ // `screenConfigUrls`. Every caller reports the warnings: the hook path on
31
+ // stderr, `doctor` and `status` by name.
32
+ const record = asRecord(result.value);
33
+ const legacy = record !== undefined && record[ALLOWLIST_VERSION_KEY] === undefined;
34
+ const screened = screenConfigUrls(result.value, legacy);
35
+ const warnings = [...screened.warnings];
36
+ const parsed = configSchema.safeParse(screened.value);
25
37
  if (!parsed.success)
26
- return { state: 'invalid', error: describeIssues(parsed.error.issues), config: fallbackConfig() };
27
- return { state: 'ok', config: parsed.data };
38
+ return { state: 'invalid', error: describeIssues(parsed.error.issues), config: fallbackConfig(), warnings };
39
+ if (screened.grandfathered.length > 0)
40
+ await recordAllowlist(paths, result.value, screened.value);
41
+ return { state: 'ok', config: parsed.data, warnings };
42
+ }
43
+ /**
44
+ * Write the grandfathered trust and the allowlist marker back, once.
45
+ *
46
+ * On disk so the grandfathering happens once: a URL written into the file after
47
+ * this load is judged by the allowlist like any other. Only the two keys change;
48
+ * a refused URL stays as written. A legacy file with nothing to grandfather is
49
+ * not rewritten at all (loading never rewrites a healthy file); the next `setup`
50
+ * stamps it. Best effort and never throws, because the hook
51
+ * path loads the config: a read-only file keeps grandfathering in memory on every
52
+ * load instead. Skipped when the file changed since it was read, so a `setup`
53
+ * that wrote in between is not overwritten.
54
+ *
55
+ * @param paths - Resolved AgentWatch paths.
56
+ * @param raw - The file as it was read.
57
+ * @param screened - The screened value, carrying the grandfathered origins.
58
+ */
59
+ async function recordAllowlist(paths, raw, screened) {
60
+ const record = asRecord(raw);
61
+ const trusted = asRecord(screened)?.[CUSTOM_ENDPOINTS_KEY];
62
+ try {
63
+ const current = await readJsonFile(paths.configFile);
64
+ if (current.state !== 'ok' || JSON.stringify(current.value) !== JSON.stringify(raw))
65
+ return;
66
+ const next = { ...record, ...(trusted === undefined ? {} : { [CUSTOM_ENDPOINTS_KEY]: trusted }), [ALLOWLIST_VERSION_KEY]: ALLOWLIST_VERSION };
67
+ await writeFileAtomic(paths.configFile, JSON.stringify(next, null, 2) + '\n', SECRET_FILE_MODE);
68
+ }
69
+ catch {
70
+ // Unwritable: the next load grandfathers again, in memory.
71
+ }
28
72
  }
29
73
  /**
30
74
  * Persist the global config atomically.
@@ -33,8 +77,202 @@ export async function loadConfig(paths) {
33
77
  * @param config - Config to write.
34
78
  */
35
79
  export async function saveConfig(paths, config) {
36
- // 0600: the file may contain a backend token.
37
- await writeFileAtomic(paths.configFile, JSON.stringify(config, null, 2) + '\n', SECRET_FILE_MODE);
80
+ // Write the flags the user chose, not the flags the consent gate computed.
81
+ // `loadConfig` re-applies the gate on every read, so persisting the gated
82
+ // shape would change nothing at runtime and would quietly erase the choice:
83
+ // a machine that later adds `contentCaptureConsent: true` would find every
84
+ // content flag already false and no record that it had ever set them.
85
+ // Retired prompt/response flags are not carried over, so this write removes them.
86
+ const capture = { ...config.capture, ...(await storedCapture(paths)) };
87
+ const refused = await storedRefusedUrls(paths, config);
88
+ // 0600: the file may contain a backend token. Stamped: this release wrote it.
89
+ await writeFileAtomic(paths.configFile, JSON.stringify({ ...config, ...refused, capture, [ALLOWLIST_VERSION_KEY]: ALLOWLIST_VERSION }, null, 2) + '\n', SECRET_FILE_MODE);
90
+ }
91
+ /**
92
+ * Change config.json under the config lock, from what is on disk now.
93
+ *
94
+ * Every writer that can race another takes this path: a hook's exchange,
95
+ * setup, uninstall. The change is computed from the file as read under the
96
+ * lock, never from a copy loaded earlier, so one writer cannot erase what
97
+ * another wrote in between (a device a hook attached while setup was
98
+ * prompting, say).
99
+ *
100
+ * @param paths - Resolved AgentWatch paths.
101
+ * @param change - The new config from the current load, or undefined for no write.
102
+ * @param options - How long to wait for the lock (none by default) and the clock.
103
+ * @param options.waitMs - Wait this long for a lock another process holds.
104
+ * @param options.now - Clock for the lock stamp.
105
+ * @returns `saved`, `unchanged` when `change` declined, or `busy` when the lock stayed taken.
106
+ */
107
+ export async function updateConfig(paths, change, options = {}) {
108
+ const take = () => acquireLock(paths.locksDir, CONFIG_LOCK, options.now);
109
+ const release = options.waitMs ? await pollUntil(take, options.waitMs, CONFIG_LOCK_POLL_MS) : await take();
110
+ if (!release)
111
+ return 'busy';
112
+ try {
113
+ const next = change(await loadConfig(paths));
114
+ if (!next)
115
+ return 'unchanged';
116
+ await saveConfig(paths, next);
117
+ return 'saved';
118
+ }
119
+ finally {
120
+ await release();
121
+ }
122
+ }
123
+ /**
124
+ * Record the device an install key was exchanged for, beside that key,
125
+ * wherever the file holds it: the machine entry and every root sharing it.
126
+ *
127
+ * The key stays: Codex and Gemini still present it (AWT-357 retires it).
128
+ *
129
+ * @param paths - Resolved AgentWatch paths.
130
+ * @param installKey - The key that was exchanged.
131
+ * @param device - Where its device secret now lives.
132
+ * @param waitMs - How long to wait for the config lock.
133
+ * @returns What {@link updateConfig} did.
134
+ */
135
+ export async function attachDevice(paths, installKey, device, waitMs) {
136
+ return updateConfig(paths, (loaded) => {
137
+ if (loaded.state !== 'ok')
138
+ return undefined;
139
+ const attach = (entry) => (entry.token === installKey ? { ...entry, device } : entry);
140
+ const roots = loaded.config.roots ? Object.fromEntries(Object.entries(loaded.config.roots).map(([key, root]) => [key, attach(root)])) : undefined;
141
+ const next = { ...attach(loaded.config), ...(roots ? { roots } : {}) };
142
+ return JSON.stringify(next) === JSON.stringify(loaded.config) ? undefined : next;
143
+ }, { waitMs });
144
+ }
145
+ /**
146
+ * A config about to be written, with the devices the file on disk already
147
+ * holds for its install keys laid back in.
148
+ *
149
+ * For setup, which computed its config from a load taken before its prompts:
150
+ * a hook may have exchanged the key since. Only a device filed under the
151
+ * entry's own key comes back; a new key starts without one.
152
+ *
153
+ * @param next - What setup is about to write.
154
+ * @param stored - The config on disk now.
155
+ * @returns `next`, with those devices.
156
+ */
157
+ export function withStoredDevices(next, stored) {
158
+ const known = deviceRefs(stored);
159
+ const carry = (entry) => {
160
+ if (!entry.token || entry.device)
161
+ return entry;
162
+ const id = credentialId(entry.token);
163
+ const device = known.find((ref) => ref.id === id);
164
+ return device ? { ...entry, device } : entry;
165
+ };
166
+ const roots = next.roots ? Object.fromEntries(Object.entries(next.roots).map(([key, root]) => [key, carry(root)])) : undefined;
167
+ return { ...carry(next), ...(roots ? { roots } : {}) };
168
+ }
169
+ /**
170
+ * The URL fields this write would otherwise overwrite with `null`, as they are
171
+ * written on disk right now.
172
+ *
173
+ * Same reason as `storedCapture`, and the same mechanism: the parsed config has
174
+ * already lost the value, so the raw file is asked. A refused URL parses to
175
+ * `null` — "a URL was written here and refused" — and writing that back deletes
176
+ * what the developer typed. That is data loss on its own, and it also deletes
177
+ * the report: `screenConfigUrls` reads the raw file, so a `roots[]` URL
178
+ * one unrelated `agentwatch setup` erased stops being named by `doctor` and
179
+ * `status` while that root goes on receiving nothing.
180
+ *
181
+ * Only a `null` is carried over, so this never fights a repair: `setup
182
+ * --endpoint https://…` parses to a string, and the string wins. It is also
183
+ * what lets one tenant's typo stop blocking every other tenant's install —
184
+ * `setup --root /work/clientB` leaves `roots["/work/clientA"]` alone rather
185
+ * than having to refuse the whole run to avoid trampling it.
186
+ *
187
+ * @param paths - Resolved AgentWatch paths.
188
+ * @param config - Config about to be written.
189
+ * @returns The fields to lay back over it; empty when there are none.
190
+ */
191
+ async function storedRefusedUrls(paths, config) {
192
+ const result = await readJsonFile(paths.configFile);
193
+ const raw = result.state === 'ok' ? asRecord(result.value) : undefined;
194
+ if (!raw)
195
+ return {};
196
+ const kept = refusedFrom(raw, config, URL_FIELDS);
197
+ const rawRoots = asRecord(raw['roots']);
198
+ if (!rawRoots || !config.roots)
199
+ return kept;
200
+ const roots = { ...config.roots };
201
+ let changed = false;
202
+ for (const [path, override] of Object.entries(config.roots)) {
203
+ const rawRoot = asRecord(rawRoots[path]);
204
+ const keptHere = rawRoot ? refusedFrom(rawRoot, override, ROOT_URL_FIELDS) : {};
205
+ if (Object.keys(keptHere).length === 0)
206
+ continue;
207
+ roots[path] = { ...override, ...keptHere };
208
+ changed = true;
209
+ }
210
+ return changed ? { ...kept, roots } : kept;
211
+ }
212
+ /**
213
+ * The raw values of one object's refused URL fields.
214
+ *
215
+ * @param raw - The object as it sits on disk.
216
+ * @param parsed - The same object as the schema read it.
217
+ * @param fields - The URL fields that object may carry.
218
+ * @returns The raw value of every field the parse refused.
219
+ */
220
+ function refusedFrom(raw, parsed, fields) {
221
+ const out = {};
222
+ for (const field of fields) {
223
+ if (parsed[field] === null && raw[field] !== undefined)
224
+ out[field] = raw[field];
225
+ }
226
+ return out;
227
+ }
228
+ /**
229
+ * The raw `capture` block on disk, when the file has one.
230
+ *
231
+ * Read raw rather than through the schema: the schema is where the gate lives
232
+ * and where retired keys are stripped, so a parsed value has already lost what
233
+ * the callers here need to see.
234
+ *
235
+ * @param paths - Resolved AgentWatch paths.
236
+ * @returns The stored block, or undefined.
237
+ */
238
+ async function rawCapture(paths) {
239
+ const result = await readJsonFile(paths.configFile);
240
+ return result.state === 'ok' ? asRecord(asRecord(result.value)?.['capture']) : undefined;
241
+ }
242
+ /**
243
+ * The content flags as they are written on disk right now.
244
+ *
245
+ * Only the tool content flags are carried over — a metadata flag the caller
246
+ * changed is a change the caller meant.
247
+ *
248
+ * @param paths - Resolved AgentWatch paths.
249
+ * @returns The stored content flags; empty when the file has none.
250
+ */
251
+ async function storedCapture(paths) {
252
+ const capture = await rawCapture(paths);
253
+ if (!capture)
254
+ return {};
255
+ const out = {};
256
+ for (const key of CONTENT_CAPTURE_KEYS) {
257
+ if (typeof capture[key] === 'boolean')
258
+ out[key] = capture[key];
259
+ }
260
+ return out;
261
+ }
262
+ /**
263
+ * The retired prompt/response flags the file on disk still carries.
264
+ *
265
+ * They collect nothing whatever their value; this exists so `setup` can say once
266
+ * that it is removing them and `doctor` can say they are still written.
267
+ *
268
+ * @param paths - Resolved AgentWatch paths.
269
+ * @returns The retired keys present in `capture`; empty when there are none.
270
+ */
271
+ export async function storedRetiredCapture(paths) {
272
+ const capture = await rawCapture(paths);
273
+ if (!capture)
274
+ return [];
275
+ return RETIRED_CAPTURE_KEYS.filter((key) => key in capture);
38
276
  }
39
277
  /**
40
278
  * The config with an installation id, generating one on first use.
@@ -51,9 +289,9 @@ export function ensureInstallationId(config) {
51
289
  * Fail-safe runtime config for a missing or corrupt file.
52
290
  *
53
291
  * Hooks keep running, but content capture is OFF: an accidental config wipe
54
- * must not silently start collecting prompts and tool I/O. Deliberately
55
- * different from `defaultConfig()`, which is what setup writes when the user
56
- * asked for an install.
292
+ * must not silently start collecting prompts or tool I/O. The schema defaults are already
293
+ * off, so this now only pins the guarantee — deliberately, so that a future
294
+ * default cannot quietly widen what a *broken* config collects.
57
295
  *
58
296
  * @returns A metadata-only config.
59
297
  */
@@ -61,7 +299,7 @@ function fallbackConfig() {
61
299
  const config = defaultConfig();
62
300
  return {
63
301
  ...config,
64
- capture: { ...config.capture, prompts: false, responses: false, toolInput: false, toolOutput: false }
302
+ capture: { ...config.capture, promptText: false, toolInput: false, toolOutput: false, sessionTitle: false }
65
303
  };
66
304
  }
67
305
  /**
@@ -2,10 +2,7 @@ import type { AgentWatchConfig, OtelConfig, OtelSignalName } from './types/confi
2
2
  export { captureSchema, configSchema, deliverySchema, emitSchema, enforcementSchema, otelSchema } from './schemas/config.schema.js';
3
3
  export type { AgentWatchConfig, CaptureConfig, EnforcementConfig, OtelConfig, OtelSignalName } from './types/config.types.js';
4
4
  /**
5
- * The configuration a deliberate `agentwatch setup` writes: full capture.
6
- *
7
- * Distinct from the runtime fallback in config-store, which is what a
8
- * *missing* config degrades to.
5
+ * The configuration a deliberate `agentwatch setup` writes: metadata only.
9
6
  *
10
7
  * @returns A config with every default applied.
11
8
  */
@@ -38,8 +35,23 @@ export declare function parseOtelSignals(value: string): OtelConfig | undefined;
38
35
  /**
39
36
  * Where product events are POSTed.
40
37
  *
38
+ * `null` is checked before truthiness, and that is not a formality: `null` is
39
+ * how `deliverableUrl` records "a URL was written here and refused", and it
40
+ * means something a *missing* field does not. Read by truthiness the two are
41
+ * the same value, so a refused `roots[].eventsUrl` fell through to the
42
+ * machine-global `endpoint` — the root's own destination being unusable is
43
+ * exactly when it must not inherit the other tenant's. A consultant whose
44
+ * `roots["/work/clientA"]` points `eventsUrl` at an internal `http:` collector
45
+ * would have had every prompt, response and branch name under that directory
46
+ * POSTed to their corporate backend under clientA's bearer.
47
+ *
48
+ * So a refusal is sticky where an absence is derivable. `otlpBaseUrl` holds the
49
+ * same rule for the same reason; `enforcementUrl` deliberately does not, and
50
+ * says why.
51
+ *
41
52
  * @param config - Effective configuration.
42
- * @returns The events URL, or undefined when no backend is configured.
53
+ * @returns The events URL, or undefined when no backend is configured or the
54
+ * one configured here was refused.
43
55
  */
44
56
  export declare function eventsUrl(config: AgentWatchConfig): string | undefined;
45
57
  /**
@@ -49,9 +61,18 @@ export declare function eventsUrl(config: AgentWatchConfig): string | undefined;
49
61
  * this base themselves, so it must stay a base and not a signal route.
50
62
  *
51
63
  * @param config - Effective configuration.
52
- * @returns The OTLP base URL, or undefined when no backend is configured.
64
+ * @returns The OTLP base URL, or undefined when no backend is configured or the
65
+ * one configured here was refused.
53
66
  */
54
67
  export declare function otlpBaseUrl(config: AgentWatchConfig): string | undefined;
68
+ /**
69
+ * Use the same collector check for exporter credentials and setup diagnostics.
70
+ * Missing collectors cannot establish permission to expose a root's bearer.
71
+ * @param machine - Configuration used by the machine-wide exporter.
72
+ * @param identity - Effective configuration for the selected directory.
73
+ * @returns Whether the exporter can use this identity's credential.
74
+ */
75
+ export declare function sharesOtlpCollector(machine: AgentWatchConfig, identity: AgentWatchConfig): boolean;
55
76
  /**
56
77
  * Where the pre-turn budget check asks its question.
57
78
  *
@@ -59,6 +80,21 @@ export declare function otlpBaseUrl(config: AgentWatchConfig): string | undefine
59
80
  * endpoint; the override exists for the same reason the other two do — a
60
81
  * deployment that does not put every route behind one host.
61
82
  *
83
+ * The one accessor that does *not* hold `eventsUrl`'s rule, and deliberately.
84
+ * There, refusing to derive is fail-safe: nothing leaves. Here it is fail-open
85
+ * — `resolveEnforcement` answers `ALLOW` when there is no URL to ask, and
86
+ * `enforcementWouldAsk` stops the caller even paying for the identity lookup —
87
+ * so one `http:` line in a field nobody uses would switch every `block` cap on
88
+ * the machine off silently. The security argument does not carry either: the
89
+ * derived URL is a path on an `endpoint` already validated as `https:`, so
90
+ * deriving sends the bearer nowhere it was not already going. `doctor` reports
91
+ * the refused field as `configuration: fail` regardless.
92
+ *
93
+ * Root resolution retains this route only for the shared backend. A root with
94
+ * a different base derives its decision route there; a route-only root still
95
+ * uses machine enforcement, so setting endpoint is required for a separate
96
+ * enforcement backend.
97
+ *
62
98
  * @param config - Effective configuration.
63
99
  * @returns The decision URL, or undefined when no backend is configured.
64
100
  */
@@ -71,3 +107,14 @@ export declare function enforcementUrl(config: AgentWatchConfig): string | undef
71
107
  * @returns The joined URL.
72
108
  */
73
109
  export declare function joinUrl(base: string, suffix: string): string;
110
+ /**
111
+ * Whether the machine has consented to tool arguments and results leaving it.
112
+ *
113
+ * Native provider logs carry both with no per-field filter, so this one answer
114
+ * decides whether a Codex or Gemini exporter may be configured at all — and
115
+ * `doctor` needs the same answer to explain why one was not.
116
+ *
117
+ * @param config - Effective configuration.
118
+ * @returns True when global consent and both tool flags are on.
119
+ */
120
+ export declare function toolContentConsented(config: AgentWatchConfig): boolean;