@agent-watch-ai/edge 0.2.5 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (348) hide show
  1. package/CHANGELOG.md +558 -0
  2. package/README.md +222 -97
  3. package/SECURITY.md +72 -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 +52 -4
  9. package/dist/cli/constants/cli.constants.js +56 -5
  10. package/dist/cli/context.d.ts +33 -2
  11. package/dist/cli/context.js +84 -14
  12. package/dist/cli/doctor.js +321 -33
  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 +553 -103
  26. package/dist/cli/status.js +82 -13
  27. package/dist/cli/toggle.d.ts +9 -0
  28. package/dist/cli/toggle.js +117 -0
  29. package/dist/cli/types/cli.types.d.ts +43 -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 +110 -12
  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 +116 -6
  41. package/dist/config/constants/config.constants.js +131 -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 +831 -84
  51. package/dist/config/schemas/config.schema.js +398 -16
  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 +119 -0
  71. package/dist/credentials/constants/credentials.constants.js +120 -0
  72. package/dist/credentials/credential-status.d.ts +14 -0
  73. package/dist/credentials/credential-status.js +38 -0
  74. package/dist/credentials/credentials.d.ts +86 -0
  75. package/dist/credentials/credentials.js +278 -0
  76. package/dist/credentials/device-api.d.ts +73 -0
  77. package/dist/credentials/device-api.js +161 -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 +73 -0
  81. package/dist/credentials/identity.js +101 -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 +31 -0
  93. package/dist/credentials/sign-in.js +105 -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 +206 -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 +64 -17
  104. package/dist/enforcement/enforcement.d.ts +23 -2
  105. package/dist/enforcement/enforcement.js +107 -17
  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 +66 -2
  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 +10 -0
  160. package/dist/pipeline/constants/pipeline.constants.js +10 -0
  161. package/dist/pipeline/hook-pipeline.js +410 -33
  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 +75 -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 +36 -3
  197. package/dist/providers/codex/codex.otel.js +199 -32
  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 +10 -0
  202. package/dist/providers/codex/constants/codex.otel.constants.js +10 -0
  203. package/dist/providers/constants/provider.constants.d.ts +8 -3
  204. package/dist/providers/constants/provider.constants.js +8 -3
  205. package/dist/providers/cursor/constants/cursor.constants.d.ts +9 -0
  206. package/dist/providers/cursor/constants/cursor.constants.js +9 -0
  207. package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
  208. package/dist/providers/cursor/cursor.adapter.js +129 -4
  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 +9 -1
  215. package/dist/providers/gemini/constants/gemini.otel.constants.js +9 -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 +30 -21
  221. package/dist/providers/gemini/gemini.otel.js +166 -22
  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/bearer-rewrite.d.ts +19 -0
  232. package/dist/providers/shared/bearer-rewrite.js +46 -0
  233. package/dist/providers/shared/constants/hook-refusal.constants.d.ts +7 -0
  234. package/dist/providers/shared/constants/hook-refusal.constants.js +7 -0
  235. package/dist/providers/shared/constants/shell-directories.constants.d.ts +30 -0
  236. package/dist/providers/shared/constants/shell-directories.constants.js +39 -0
  237. package/dist/providers/shared/constants/tooling.constants.d.ts +24 -2
  238. package/dist/providers/shared/constants/tooling.constants.js +25 -3
  239. package/dist/providers/shared/event-builder.d.ts +12 -14
  240. package/dist/providers/shared/event-builder.js +20 -14
  241. package/dist/providers/shared/exporter-allowlist.d.ts +20 -0
  242. package/dist/providers/shared/exporter-allowlist.js +49 -0
  243. package/dist/providers/shared/hook-config.d.ts +2 -21
  244. package/dist/providers/shared/hook-config.js +5 -4
  245. package/dist/providers/shared/hook-refusal.d.ts +12 -0
  246. package/dist/providers/shared/hook-refusal.js +17 -1
  247. package/dist/providers/shared/install-record.d.ts +12 -2
  248. package/dist/providers/shared/install-record.js +5 -2
  249. package/dist/providers/shared/shell-directories.d.ts +24 -0
  250. package/dist/providers/shared/shell-directories.js +90 -0
  251. package/dist/providers/shared/tooling.d.ts +40 -1
  252. package/dist/providers/shared/tooling.js +70 -1
  253. package/dist/providers/shared/types/adapter.types.d.ts +1 -2
  254. package/dist/providers/types/provider.types.d.ts +81 -1
  255. package/dist/snapshot/constants/snapshot.constants.d.ts +32 -0
  256. package/dist/snapshot/constants/snapshot.constants.js +33 -0
  257. package/dist/snapshot/snapshot-event.js +52 -11
  258. package/dist/snapshot/snapshot-pipeline.js +1 -1
  259. package/dist/snapshot/types/snapshot.types.d.ts +2 -0
  260. package/dist/storage/atomic-file.d.ts +21 -0
  261. package/dist/storage/atomic-file.js +20 -1
  262. package/dist/storage/constants/storage.constants.d.ts +19 -0
  263. package/dist/storage/constants/storage.constants.js +19 -0
  264. package/dist/storage/disabled.d.ts +13 -0
  265. package/dist/storage/disabled.js +24 -0
  266. package/dist/storage/index.d.ts +2 -0
  267. package/dist/storage/index.js +2 -0
  268. package/dist/storage/paths.js +3 -2
  269. package/dist/storage/schemas/storage.schema.d.ts +72 -0
  270. package/dist/storage/schemas/storage.schema.js +6 -0
  271. package/dist/storage/sweep-marker.d.ts +19 -0
  272. package/dist/storage/sweep-marker.js +55 -0
  273. package/dist/storage/types/storage.types.d.ts +2 -0
  274. package/dist/storage/uninstalled.d.ts +58 -0
  275. package/dist/storage/uninstalled.js +107 -0
  276. package/dist/transport/auth-block.d.ts +66 -0
  277. package/dist/transport/auth-block.js +129 -0
  278. package/dist/transport/constants/transport.constants.d.ts +82 -3
  279. package/dist/transport/constants/transport.constants.js +83 -4
  280. package/dist/transport/cooldown.js +8 -1
  281. package/dist/transport/delivery.d.ts +14 -6
  282. package/dist/transport/delivery.js +80 -55
  283. package/dist/transport/http-transport.d.ts +1 -0
  284. package/dist/transport/http-transport.js +52 -10
  285. package/dist/transport/index.d.ts +6 -3
  286. package/dist/transport/index.js +3 -0
  287. package/dist/transport/queue-partition.d.ts +91 -0
  288. package/dist/transport/queue-partition.js +143 -0
  289. package/dist/transport/queue.d.ts +99 -20
  290. package/dist/transport/queue.js +210 -69
  291. package/dist/transport/response-body.d.ts +25 -0
  292. package/dist/transport/response-body.js +64 -0
  293. package/dist/transport/send.d.ts +11 -0
  294. package/dist/transport/send.js +17 -0
  295. package/dist/transport/types/delivery-flow.types.d.ts +19 -0
  296. package/dist/transport/types/delivery-flow.types.js +1 -0
  297. package/dist/transport/types/transport.types.d.ts +45 -0
  298. package/dist/turns/claude-transcript.d.ts +19 -1
  299. package/dist/turns/claude-transcript.js +46 -1
  300. package/dist/turns/codex-originator.d.ts +11 -0
  301. package/dist/turns/codex-originator.js +31 -0
  302. package/dist/turns/codex-transcript.d.ts +30 -0
  303. package/dist/turns/codex-transcript.js +88 -0
  304. package/dist/turns/constants/turns.constants.d.ts +141 -5
  305. package/dist/turns/constants/turns.constants.js +155 -5
  306. package/dist/turns/file-identity.d.ts +27 -0
  307. package/dist/turns/file-identity.js +48 -0
  308. package/dist/turns/gemini-transcript.d.ts +30 -0
  309. package/dist/turns/gemini-transcript.js +96 -0
  310. package/dist/turns/index.d.ts +3 -3
  311. package/dist/turns/index.js +1 -1
  312. package/dist/turns/inherited-checkout.d.ts +54 -0
  313. package/dist/turns/inherited-checkout.js +155 -0
  314. package/dist/turns/native-session-titles.d.ts +26 -0
  315. package/dist/turns/native-session-titles.js +102 -0
  316. package/dist/turns/transcript.d.ts +3 -2
  317. package/dist/turns/transcript.js +5 -1
  318. package/dist/turns/turn-state.d.ts +224 -3
  319. package/dist/turns/turn-state.js +456 -21
  320. package/dist/turns/turn-summary.d.ts +1 -14
  321. package/dist/turns/turn-summary.js +87 -51
  322. package/dist/turns/turn-tracker.d.ts +21 -2
  323. package/dist/turns/turn-tracker.js +379 -56
  324. package/dist/turns/types/transcript.types.d.ts +5 -0
  325. package/dist/turns/types/turn-state.types.d.ts +116 -5
  326. package/dist/turns/types/turn-summary.types.d.ts +64 -14
  327. package/dist/turns/types/turn-tracker.types.d.ts +27 -1
  328. package/dist/turns/work-checkout.d.ts +67 -0
  329. package/dist/turns/work-checkout.js +700 -0
  330. package/dist/untraced/constants/untraced.constants.d.ts +31 -0
  331. package/dist/untraced/constants/untraced.constants.js +63 -0
  332. package/dist/untraced/untraced.d.ts +35 -0
  333. package/dist/untraced/untraced.js +105 -0
  334. package/dist/update/constants/update.constants.d.ts +18 -0
  335. package/dist/update/constants/update.constants.js +20 -0
  336. package/dist/update/update-check.d.ts +52 -0
  337. package/dist/update/update-check.js +113 -0
  338. package/docs/AUDIT_PROMPT.md +129 -0
  339. package/docs/DATA_HANDLING.md +655 -0
  340. package/docs/ENTERPRISE_DEPLOYMENT.md +194 -0
  341. package/docs/PERFORMANCE.md +81 -0
  342. package/package.json +14 -4
  343. package/dist/enrollment/enrollment-provider.d.ts +0 -5
  344. package/dist/enrollment/manual-enrollment.d.ts +0 -32
  345. package/dist/enrollment/manual-enrollment.js +0 -72
  346. package/example/README.md +0 -43
  347. package/example/server.mjs +0 -240
  348. /package/dist/{enrollment/enrollment-provider.js → config/types/destination.types.js} +0 -0
@@ -1,13 +1,29 @@
1
1
  import { asRecord, omitKeys } from '../../core/object.js';
2
- import { enabledSignalNames, otelEnabled, otlpBaseUrl } from '../../config/config.js';
3
- import { backupFile } from '../../storage/atomic-file.js';
2
+ import { enabledSignalNames, otlpBaseUrl, toolContentConsented } from '../../config/config.js';
3
+ import { INSTALLATION_HEADER } from '../../transport/constants/transport.constants.js';
4
+ import { backupFile, currentMode, writeIfUnchanged } from '../../storage/atomic-file.js';
5
+ import { SECRET_FILE_MODE } from '../../storage/constants/storage.constants.js';
4
6
  import { readJsonFile } from '../../storage/json-file.js';
5
- import { HOOK_COMMAND_MARKER } from '../constants/provider.constants.js';
7
+ import { parseJsonLine } from '../../turns/transcript.js';
8
+ import { deviceFor, hasCredential } from '../../credentials/identity.js';
9
+ import { BEARER_PLACEHOLDER, HOOK_COMMAND_MARKER } from '../constants/provider.constants.js';
6
10
  import { writeJsonValidated } from '../shared/hook-config.js';
7
11
  import { withOtelInstall, withoutOtelInstall } from '../shared/install-record.js';
8
12
  import { geminiSettingsPath } from './gemini.detect.js';
9
13
  import { GEMINI_PROVIDER_ID } from './constants/gemini.constants.js';
10
- import { ENV_BLOCK_KEY, GEMINI_LEGACY_OWNED_KEYS, GEMINI_OTLP_PROTOCOL, GEMINI_TELEMETRY_TARGET_LOCAL, LEGACY_HELPER_KEY, OTEL_EXPORTER_NONE, OTEL_EXPORTER_OTLP, OTLP_HEADERS_KEY, STANDARD_OTLP_PROTOCOL } from './constants/gemini.otel.constants.js';
14
+ import { ENV_BLOCK_KEY, GEMINI_ENDPOINT_KEYS, GEMINI_LEGACY_OWNED_KEYS, GEMINI_OTLP_PROTOCOL, GEMINI_TELEMETRY_TARGET_LOCAL, LEGACY_HELPER_KEY, OTEL_EXPORTER_NONE, OTEL_EXPORTER_OTLP, OTLP_HEADERS_KEY, RE_BEARER_PAIR, STANDARD_OTLP_PROTOCOL } from './constants/gemini.otel.constants.js';
15
+ /**
16
+ * Gemini's own prompt-logging switch, forced off.
17
+ *
18
+ * Never treated as a foreign key: a user who set it to `true` before installing
19
+ * is exactly the case this exists to override, and refusing to configure it
20
+ * would leave prompt logging on *and* drop the llm.call ledger. Overriding a
21
+ * switch that only ever reduces what leaves the machine is not the redirection
22
+ * the conflict check protects against. Mirrors `CONTENT_LOG_OFF` in claude.otel.
23
+ */
24
+ const CONTENT_LOG_OFF = {
25
+ GEMINI_TELEMETRY_LOG_PROMPTS: 'false'
26
+ };
11
27
  /**
12
28
  * The environment Gemini CLI actually reads.
13
29
  *
@@ -24,16 +40,18 @@ import { ENV_BLOCK_KEY, GEMINI_LEGACY_OWNED_KEYS, GEMINI_OTLP_PROTOCOL, GEMINI_T
24
40
  * which is fail-closed, answered 401 to every batch.
25
41
  *
26
42
  * @param context - Environment, paths and effective config.
43
+ * @param bearer - What to authenticate with; see `SetupContext.bearer`.
27
44
  * @returns The desired variables, or undefined when telemetry is off or no
28
45
  * backend is configured.
29
46
  */
30
- export function desiredGeminiOtelEnv(context) {
47
+ function desiredGeminiOtelEnv(context, bearer) {
31
48
  const otlpBase = otlpBaseUrl(context.config);
32
- if (!otlpBase || !otelEnabled(context.config))
49
+ const signals = safeGeminiSignals(context.config);
50
+ if (!otlpBase || !anySignal(signals))
33
51
  return undefined;
34
- const signals = context.config.otel;
35
52
  return {
36
53
  GEMINI_TELEMETRY_ENABLED: 'true',
54
+ ...CONTENT_LOG_OFF,
37
55
  GEMINI_TELEMETRY_TARGET: GEMINI_TELEMETRY_TARGET_LOCAL,
38
56
  GEMINI_TELEMETRY_OTLP_ENDPOINT: otlpBase,
39
57
  GEMINI_TELEMETRY_OTLP_PROTOCOL: GEMINI_OTLP_PROTOCOL,
@@ -43,9 +61,30 @@ export function desiredGeminiOtelEnv(context) {
43
61
  OTEL_TRACES_EXPORTER: signals.traces ? OTEL_EXPORTER_OTLP : OTEL_EXPORTER_NONE,
44
62
  OTEL_EXPORTER_OTLP_PROTOCOL: STANDARD_OTLP_PROTOCOL,
45
63
  OTEL_EXPORTER_OTLP_ENDPOINT: otlpBase,
46
- ...(context.config.token ? { [OTLP_HEADERS_KEY]: `Authorization=Bearer ${context.config.token}` } : {})
64
+ ...(bearer ? { [OTLP_HEADERS_KEY]: otlpHeaders(bearer, context.config.installationId) } : {})
47
65
  };
48
66
  }
67
+ /**
68
+ * The `OTEL_EXPORTER_OTLP_HEADERS` value: comma-separated `key=value` pairs.
69
+ *
70
+ * Carries the installation id beside the bearer so a Gemini call that no turn
71
+ * summary claimed can still be traced to the machine that made it. Only the id
72
+ * — a locally generated UUID — travels here; no developer identity does.
73
+ *
74
+ * Takes the token rather than the config it came from, like `tomlHeaders` does
75
+ * for Codex: a header builder that reads a config can be handed one with no
76
+ * token and quietly emit `Bearer ` rather than refusing to be called.
77
+ *
78
+ * @param token - The access token; the caller has already checked there is one.
79
+ * @param installationId - This installation's id, when one exists.
80
+ * @returns The header list for the exporter.
81
+ */
82
+ function otlpHeaders(token, installationId) {
83
+ const pairs = [`Authorization=Bearer ${token}`];
84
+ if (installationId)
85
+ pairs.push(`${INSTALLATION_HEADER}=${installationId}`);
86
+ return pairs.join(',');
87
+ }
49
88
  /** Configures Gemini CLI's own OTLP export. */
50
89
  export class GeminiOtelConfigurator {
51
90
  /**
@@ -64,7 +103,7 @@ export class GeminiOtelConfigurator {
64
103
  * @returns The status, naming any foreign configuration in the way.
65
104
  */
66
105
  async inspect(context) {
67
- const disabled = !otelEnabled(context.config);
106
+ const disabled = !anySignal(safeGeminiSignals(context.config));
68
107
  const read = await readJsonFile(geminiSettingsPath(context.env));
69
108
  const settings = read.state === 'ok' ? asRecord(read.value) : undefined;
70
109
  if (!settings) {
@@ -76,10 +115,19 @@ export class GeminiOtelConfigurator {
76
115
  const ownedKeys = ownedKeysOf(context);
77
116
  if (disabled)
78
117
  return inspectDisabled(settings, envBlock, ownedKeys);
79
- const desired = desiredGeminiOtelEnv(context);
118
+ // The bearer's value is not compared: it is the access token, which the hook
119
+ // path rotates. Only whether a header is there, when there is a credential.
120
+ const device = deviceFor(context.config);
121
+ const desired = desiredGeminiOtelEnv(context, hasCredential(context.config) ? BEARER_PLACEHOLDER : undefined);
80
122
  if (!desired)
81
123
  return { supported: true, configured: false, detail: 'no backend endpoint configured' };
82
- const matches = Object.entries(desired).every(([key, value]) => envBlock[key] === value);
124
+ const headers = envBlock[OTLP_HEADERS_KEY];
125
+ // An install key still in the header list once a device exists is stale.
126
+ if (device && context.config.token && typeof headers === 'string' && headers.includes(context.config.token)) {
127
+ return { supported: true, configured: false, detail: 'telemetry headers still hold the install key — run `agentwatch setup`' };
128
+ }
129
+ const actual = typeof headers === 'string' ? { ...envBlock, [OTLP_HEADERS_KEY]: headers.replace(RE_BEARER_PAIR, `$1${BEARER_PLACEHOLDER}`) } : envBlock;
130
+ const matches = Object.entries(desired).every(([key, value]) => actual[key] === value);
83
131
  // A helper entry left by an older version is dead weight Gemini ignores;
84
132
  // reporting "configured" would hide that setup still has work to do. A
85
133
  // helper belonging to another tool is none of our business.
@@ -87,7 +135,7 @@ export class GeminiOtelConfigurator {
87
135
  return { supported: true, configured: true };
88
136
  if (matches)
89
137
  return { supported: true, configured: false, detail: 'stale otelHeadersHelper entry — run `agentwatch setup`' };
90
- const conflicting = foreignKeys(envBlock, desired, ownedKeys);
138
+ const conflicting = foreignKeys(actual, desired, ownedKeys);
91
139
  if (conflicting.length > 0) {
92
140
  return { supported: true, configured: false, conflict: `existing telemetry env vars: ${conflicting.join(', ')}` };
93
141
  }
@@ -101,7 +149,7 @@ export class GeminiOtelConfigurator {
101
149
  * install state.
102
150
  */
103
151
  async configure(context) {
104
- const desired = desiredGeminiOtelEnv(context);
152
+ const desired = desiredGeminiOtelEnv(context, context.bearer);
105
153
  if (!desired)
106
154
  return this.configureDisabled(context);
107
155
  const settingsPath = geminiSettingsPath(context.env);
@@ -130,20 +178,27 @@ export class GeminiOtelConfigurator {
130
178
  // Gemini never read this; leaving it behind only confuses the next reader.
131
179
  const nextSettings = hasOurLegacyHelper(withEnv) ? omitKeys(withEnv, new Set([LEGACY_HELPER_KEY])) : withEnv;
132
180
  const changed = JSON.stringify(nextSettings) !== JSON.stringify(settings);
181
+ // Only when the block actually carries the bearer. This file is Gemini's,
182
+ // not ours, and `writeFileAtomic` preserves the target's mode by design —
183
+ // so tightening it unconditionally changed another tool's permissions on a
184
+ // shared workstation for no reason, and could never be undone.
185
+ const carriesCredential = desired[OTLP_HEADERS_KEY] !== undefined;
186
+ const priorMode = carriesCredential ? await currentMode(settingsPath) : undefined;
133
187
  if (changed) {
134
188
  await backupFile(settingsPath, context.paths.backupsDir, context.env.now());
135
- await writeJsonValidated(settingsPath, nextSettings);
189
+ await writeJsonValidated(settingsPath, nextSettings, carriesCredential ? SECRET_FILE_MODE : undefined);
136
190
  }
137
191
  return {
138
192
  ok: true,
139
193
  changed,
140
194
  messages: changed
141
- ? [`native OpenTelemetry configured (signals: ${enabledSignalNames(context.config.otel).join(', ')})`, 'restart running Gemini CLI sessions to pick it up']
195
+ ? [`native OpenTelemetry configured (signals: ${enabledSignalNames(safeGeminiSignals(context.config)).join(', ')})`, 'restart running Gemini CLI sessions to pick it up']
142
196
  : ['native OpenTelemetry already up to date'],
143
197
  installState: withOtelInstall(context.installState, GEMINI_PROVIDER_ID, {
144
198
  configPath: settingsPath,
145
199
  ownedKeys: Object.keys(desired),
146
- configuredAt: context.env.now()
200
+ configuredAt: context.env.now(),
201
+ ...(changed && priorMode !== undefined && priorMode !== SECRET_FILE_MODE ? { priorMode } : {})
147
202
  })
148
203
  };
149
204
  }
@@ -171,7 +226,10 @@ export class GeminiOtelConfigurator {
171
226
  const changed = JSON.stringify(nextSettings) !== JSON.stringify(settings);
172
227
  if (changed) {
173
228
  await backupFile(settingsPath, context.paths.backupsDir, context.env.now());
174
- await writeJsonValidated(settingsPath, nextSettings);
229
+ // The mode the file had before AgentWatch tightened it, when it was
230
+ // tightened. `writeJsonValidated` with no mode would otherwise keep our
231
+ // 0600 on a file that no longer holds a token.
232
+ await writeJsonValidated(settingsPath, nextSettings, context.installState.agents[GEMINI_PROVIDER_ID]?.otelPriorMode);
175
233
  }
176
234
  return {
177
235
  ok: true,
@@ -180,6 +238,26 @@ export class GeminiOtelConfigurator {
180
238
  installState: withoutOtelInstall(context.installState, GEMINI_PROVIDER_ID)
181
239
  };
182
240
  }
241
+ /**
242
+ * Where the exporter keys `uninstall` would remove send.
243
+ *
244
+ * @param context - Environment and install state.
245
+ * @returns The owned endpoints.
246
+ */
247
+ async exporterEndpoints(context) {
248
+ const read = await readJsonFile(geminiSettingsPath(context.env));
249
+ const envBlock = asRecord(read.state === 'ok' ? asRecord(read.value)?.[ENV_BLOCK_KEY] : undefined);
250
+ // No record owns nothing: unlike an explicit `uninstall`, the sweep runs
251
+ // unasked, and Gemini installed after setup holds only the developer's keys.
252
+ const owned = new Set(context.installState.agents[GEMINI_PROVIDER_ID]?.otelOwnedKeys ?? []);
253
+ const endpoints = [];
254
+ for (const key of GEMINI_ENDPOINT_KEYS) {
255
+ const value = envBlock?.[key];
256
+ if (owned.has(key) && typeof value === 'string')
257
+ endpoints.push(value);
258
+ }
259
+ return endpoints;
260
+ }
183
261
  /**
184
262
  * Handle `configure` when telemetry is off or unconfigurable.
185
263
  *
@@ -187,7 +265,7 @@ export class GeminiOtelConfigurator {
187
265
  * @returns The outcome.
188
266
  */
189
267
  async configureDisabled(context) {
190
- if (otelEnabled(context.config))
268
+ if (anySignal(safeGeminiSignals(context.config)))
191
269
  return { ok: false, changed: false, messages: ['no backend endpoint configured'] };
192
270
  const removed = await this.uninstall(context);
193
271
  if (!removed.ok)
@@ -197,12 +275,78 @@ export class GeminiOtelConfigurator {
197
275
  changed: removed.changed,
198
276
  messages: [
199
277
  removed.changed
200
- ? 'native OpenTelemetry disabled in config; previous configuration removed'
201
- : 'native OpenTelemetry disabled in config (otel: none)'
278
+ ? 'native OpenTelemetry disabled by config or content consent; previous configuration removed'
279
+ : 'native OpenTelemetry disabled by config or content consent'
202
280
  ],
203
281
  installState: removed.installState
204
282
  };
205
283
  }
284
+ /**
285
+ * Swap the bearer in our `OTEL_EXPORTER_OTLP_HEADERS` for the current one.
286
+ *
287
+ * Only when a setup recorded the key as ours, and only the bearer in it
288
+ * changes. No backup: one per rotation would collect copies of every token.
289
+ *
290
+ * @param context - The recorded file, its contents as read, install state and the current bearer.
291
+ * @returns True when the file was rewritten.
292
+ */
293
+ async rewriteBearer(context) {
294
+ if (!context.installState.agents[GEMINI_PROVIDER_ID]?.otelOwnedKeys.includes(OTLP_HEADERS_KEY))
295
+ return false;
296
+ const settings = parseJsonLine(context.raw);
297
+ const envBlock = asRecord(settings?.[ENV_BLOCK_KEY]);
298
+ const headers = envBlock?.[OTLP_HEADERS_KEY];
299
+ if (!envBlock || typeof headers !== 'string')
300
+ return false;
301
+ const next = headers.replace(RE_BEARER_PAIR, (_match, head) => head + context.bearer);
302
+ if (next === headers)
303
+ return false;
304
+ // In place when the value appears once as written, so the developer's
305
+ // formatting survives every rotation; re-serialized only when it does not.
306
+ const written = JSON.stringify(headers);
307
+ const at = context.raw.indexOf(written);
308
+ const inPlace = at !== -1 && at === context.raw.lastIndexOf(written) ? context.raw.slice(0, at) + JSON.stringify(next) + context.raw.slice(at + written.length) : '';
309
+ const contents = asRecord(parseJsonLine(inPlace)?.[ENV_BLOCK_KEY])?.[OTLP_HEADERS_KEY] === next
310
+ ? inPlace
311
+ : `${JSON.stringify({ ...settings, [ENV_BLOCK_KEY]: { ...envBlock, [OTLP_HEADERS_KEY]: next } }, null, 2)}\n`;
312
+ return writeIfUnchanged(context.configPath, context.raw, contents, SECRET_FILE_MODE);
313
+ }
314
+ /**
315
+ * Signals Gemini was asked for but will not be given under current consent.
316
+ *
317
+ * Its usage logs always carry function arguments, and its detailed traces can
318
+ * carry prompts — so logs wait on tool-content consent and traces are never
319
+ * given, which is why the answer is per signal rather than all-or-nothing.
320
+ *
321
+ * @param config - Effective configuration.
322
+ * @returns The requested signals that are held back; empty when none are.
323
+ */
324
+ withheldSignals(config) {
325
+ const safe = safeGeminiSignals(config);
326
+ return enabledSignalNames(config.otel).filter((name) => !safe[name]);
327
+ }
328
+ }
329
+ /**
330
+ * Gemini logs always carry function arguments, so they need tool-content
331
+ * consent. Detailed traces can carry prompts unbounded and unscrubbed, outside
332
+ * the summary's `promptText` path, so no configuration makes them safe.
333
+ * @param config - Global, consent-gated configuration.
334
+ * @returns The signals safe to materialize in Gemini settings.
335
+ */
336
+ function safeGeminiSignals(config) {
337
+ return {
338
+ logs: config.otel.logs && toolContentConsented(config),
339
+ traces: false,
340
+ metrics: config.otel.metrics
341
+ };
342
+ }
343
+ /**
344
+ * Whether Gemini has at least one safe signal to export.
345
+ * @param signals - Consent-filtered signal selection.
346
+ * @returns True when one signal remains.
347
+ */
348
+ function anySignal(signals) {
349
+ return signals.logs || signals.traces || signals.metrics;
206
350
  }
207
351
  /**
208
352
  * Settings keys a previous AgentWatch setup recorded as its own.
@@ -224,7 +368,7 @@ function ownedKeysOf(context) {
224
368
  function inspectDisabled(settings, envBlock, ownedKeys) {
225
369
  const leftover = ownedKeys.some((key) => (key === LEGACY_HELPER_KEY ? settings[key] !== undefined : envBlock[key] !== undefined)) || hasOurLegacyHelper(settings);
226
370
  if (!leftover)
227
- return { supported: true, configured: true, detail: 'disabled in config (otel)' };
371
+ return { supported: true, configured: true, detail: 'disabled by config or content consent' };
228
372
  return {
229
373
  supported: true,
230
374
  configured: false,
@@ -240,7 +384,7 @@ function inspectDisabled(settings, envBlock, ownedKeys) {
240
384
  * @returns The conflicting key names.
241
385
  */
242
386
  function foreignKeys(envBlock, desired, ownedKeys) {
243
- const owned = new Set(ownedKeys);
387
+ const owned = new Set([...ownedKeys, ...Object.keys(CONTENT_LOG_OFF)]);
244
388
  return Object.keys(desired).filter((key) => envBlock[key] !== undefined && envBlock[key] !== desired[key] && !owned.has(key));
245
389
  }
246
390
  /**
@@ -2,7 +2,7 @@ import { hookRefusal } from '../shared/hook-refusal.js';
2
2
  import { GEMINI_PROMPT_EVENTS } from './constants/gemini.constants.js';
3
3
  import { detectGemini } from './gemini.detect.js';
4
4
  import { installGeminiHooks, uninstallGeminiHooks } from './gemini.hooks.js';
5
- import { parseGeminiHookEvent } from './gemini.adapter.js';
5
+ import { geminiShellCall, parseGeminiHookEvent } from './gemini.adapter.js';
6
6
  import { GeminiOtelConfigurator } from './gemini.otel.js';
7
7
  export const geminiProvider = {
8
8
  id: 'gemini',
@@ -18,5 +18,6 @@ export const geminiProvider = {
18
18
  * set across both namings — exactly the hooks a refusal may travel on.
19
19
  */
20
20
  getBlockResponse: (payload, message) => hookRefusal(payload, GEMINI_PROMPT_EVENTS, { decision: 'deny', reason: message }),
21
+ shellCall: geminiShellCall,
21
22
  nativeTelemetry: new GeminiOtelConfigurator()
22
23
  };
@@ -6,7 +6,7 @@
6
6
  export type { AgentProvider, DetectionResult, HookContext, McpToolName, NativeTelemetryConfigurator, NativeTelemetryStatus, ProviderHookResponse, SetupContext, SetupOutcome, ToolKind, ToolStatus } from './types/provider.types.js';
7
7
  export { HOOK_COMMAND_MARKER, KNOWN_AGENT_IDS } from './constants/provider.constants.js';
8
8
  export { isAgentWatchHookCommand } from './provider.js';
9
- export { getProvider, providerIds, providers } from './registry.js';
9
+ export { loadProvider, providerIds, providers } from './registry.js';
10
10
  export { classifyTool, contentEvidence, extractCommand, extractFilePath, parseMcpToolName, toolCompleteType, toolStartType } from './shared/tooling.js';
11
11
  export { baseEvent, filePathPatch, promptPatch, providerPatch, responsePatch, toolPatch, withPatch } from './shared/event-builder.js';
12
12
  export { registerOurHandlers, stripOurHandlers, sweepUnregisteredEvents, withHooksBlock, writeJsonValidated } from './shared/hook-config.js';
@@ -1,6 +1,6 @@
1
1
  export { HOOK_COMMAND_MARKER, KNOWN_AGENT_IDS } from './constants/provider.constants.js';
2
2
  export { isAgentWatchHookCommand } from './provider.js';
3
- export { getProvider, providerIds, providers } from './registry.js';
3
+ export { loadProvider, providerIds, providers } from './registry.js';
4
4
  export { classifyTool, contentEvidence, extractCommand, extractFilePath, parseMcpToolName, toolCompleteType, toolStartType } from './shared/tooling.js';
5
5
  export { baseEvent, filePathPatch, promptPatch, providerPatch, responsePatch, toolPatch, withPatch } from './shared/event-builder.js';
6
6
  export { registerOurHandlers, stripOurHandlers, sweepUnregisteredEvents, withHooksBlock, writeJsonValidated } from './shared/hook-config.js';
@@ -0,0 +1,10 @@
1
+ import type { AgentProvider } from './types/provider.types.js';
2
+ /** Every agent id the CLI accepts, for help and error messages. */
3
+ export declare const providerIds: readonly string[];
4
+ /**
5
+ * The provider for an agent id, loading only that agent's code.
6
+ *
7
+ * @param id - Agent id as passed to `agentwatch hook --agent <id>`.
8
+ * @returns The provider, or undefined for an unknown agent.
9
+ */
10
+ export declare function loadProvider(id: string): Promise<AgentProvider | undefined>;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * One dynamic import per agent, so a hook loads the agent it was invoked for
3
+ * and no other.
4
+ *
5
+ * The hook path resolves exactly one provider per invocation, and importing the
6
+ * eager registry pulled in all five with their adapters, schemas and constants
7
+ * — measurably the largest single cost in the hook's own import graph, paid ten
8
+ * to fifteen times per turn on every developer's machine. `cli.ts` already goes
9
+ * to trouble to lazy-import command modules "so the hook path does not pay
10
+ * their startup"; this is the same argument applied to the agents.
11
+ *
12
+ * This literal and `registry.providers` are two hand-maintained lists of the
13
+ * same five agents, and they cannot be derived from one another: the eager list
14
+ * holds the provider objects, and having these loaders produce it would import
15
+ * every agent, which is the cost this file exists to avoid. `tests/providers.test.ts`
16
+ * asserts the two agree, so a sixth agent registered in only one of them fails
17
+ * the suite rather than installing hooks whose every invocation resolves no
18
+ * provider and drops the agent's telemetry in silence.
19
+ */
20
+ const PROVIDER_LOADERS = {
21
+ claude: async () => (await import('./claude/claude.provider.js')).claudeProvider,
22
+ codex: async () => (await import('./codex/codex.provider.js')).codexProvider,
23
+ cursor: async () => (await import('./cursor/cursor.provider.js')).cursorProvider,
24
+ gemini: async () => (await import('./gemini/gemini.provider.js')).geminiProvider,
25
+ antigravity: async () => (await import('./antigravity/antigravity.provider.js')).antigravityProvider
26
+ };
27
+ /** Every agent id the CLI accepts, for help and error messages. */
28
+ export const providerIds = Object.keys(PROVIDER_LOADERS);
29
+ /**
30
+ * The provider for an agent id, loading only that agent's code.
31
+ *
32
+ * @param id - Agent id as passed to `agentwatch hook --agent <id>`.
33
+ * @returns The provider, or undefined for an unknown agent.
34
+ */
35
+ export async function loadProvider(id) {
36
+ const load = PROVIDER_LOADERS[id];
37
+ if (!load)
38
+ return undefined;
39
+ return load();
40
+ }
@@ -14,3 +14,14 @@ export type { AgentProvider, DetectionResult, HookContext, McpToolName, NativeTe
14
14
  * @returns True only when AgentWatch wrote it.
15
15
  */
16
16
  export declare function isAgentWatchHookCommand(command: string): boolean;
17
+ /**
18
+ * Minimal tokenizer for the exact commands buildHookCommand emits.
19
+ *
20
+ * Supports quoted paths and their escaped quote/backslash forms, and rejects
21
+ * any command containing a shell control operator — a command we cannot fully
22
+ * understand is one we must not claim ownership of.
23
+ *
24
+ * @param command - The command line.
25
+ * @returns Its tokens, or undefined when the command is not one we emit.
26
+ */
27
+ export declare function tokenizeHookCommand(command: string): string[] | undefined;
@@ -99,7 +99,7 @@ function pathBase(value) {
99
99
  * @param command - The command line.
100
100
  * @returns Its tokens, or undefined when the command is not one we emit.
101
101
  */
102
- function tokenizeHookCommand(command) {
102
+ export function tokenizeHookCommand(command) {
103
103
  const tokens = [];
104
104
  let token = '';
105
105
  let started = false;
@@ -1,12 +1,15 @@
1
1
  import type { AgentProvider } from './types/provider.types.js';
2
- /** Adding an agent = implementing AgentProvider and registering it here. */
3
- export declare const providers: readonly AgentProvider[];
2
+ export { loadProvider, providerIds } from './loaders.js';
4
3
  /**
5
- * The provider for an agent id.
4
+ * Every provider, eagerly.
5
+ *
6
+ * For the commands that genuinely need all five — `setup`, `status`, `doctor`,
7
+ * `uninstall`, `toggle` — each of which asks every agent about itself. The hook
8
+ * path must not import this module: it needs one agent, and `loadProvider` in
9
+ * `loaders.js` is how it gets exactly that one.
6
10
  *
7
- * @param id - Agent id as passed to `agentwatch hook --agent <id>`.
8
- * @returns The provider, or undefined for an unknown agent.
11
+ * Adding an agent = implementing AgentProvider, registering it here, and adding
12
+ * its loader in `loaders.js`. Both, or `tests/providers.test.ts` fails: an agent
13
+ * present here and missing there installs hooks that resolve no provider.
9
14
  */
10
- export declare function getProvider(id: string): AgentProvider | undefined;
11
- /** Every agent id the CLI accepts, for help and error messages. */
12
- export declare const providerIds: readonly string[];
15
+ export declare const providers: readonly AgentProvider[];
@@ -3,21 +3,17 @@ import { claudeProvider } from './claude/claude.provider.js';
3
3
  import { codexProvider } from './codex/codex.provider.js';
4
4
  import { cursorProvider } from './cursor/cursor.provider.js';
5
5
  import { geminiProvider } from './gemini/gemini.provider.js';
6
- /** Adding an agent = implementing AgentProvider and registering it here. */
7
- export const providers = [claudeProvider, codexProvider, cursorProvider, geminiProvider, antigravityProvider];
8
- /**
9
- * Index built once at module load: the hook path resolves a provider on every
10
- * single invocation, and a linear scan there is pure waste (STYLEGUIDE 3.2).
11
- */
12
- const byId = new Map(providers.map((provider) => [provider.id, provider]));
6
+ export { loadProvider, providerIds } from './loaders.js';
13
7
  /**
14
- * The provider for an agent id.
8
+ * Every provider, eagerly.
15
9
  *
16
- * @param id - Agent id as passed to `agentwatch hook --agent <id>`.
17
- * @returns The provider, or undefined for an unknown agent.
10
+ * For the commands that genuinely need all five — `setup`, `status`, `doctor`,
11
+ * `uninstall`, `toggle` — each of which asks every agent about itself. The hook
12
+ * path must not import this module: it needs one agent, and `loadProvider` in
13
+ * `loaders.js` is how it gets exactly that one.
14
+ *
15
+ * Adding an agent = implementing AgentProvider, registering it here, and adding
16
+ * its loader in `loaders.js`. Both, or `tests/providers.test.ts` fails: an agent
17
+ * present here and missing there installs hooks that resolve no provider.
18
18
  */
19
- export function getProvider(id) {
20
- return byId.get(id);
21
- }
22
- /** Every agent id the CLI accepts, for help and error messages. */
23
- export const providerIds = providers.map((provider) => provider.id);
19
+ export const providers = [claudeProvider, codexProvider, cursorProvider, geminiProvider, antigravityProvider];
@@ -0,0 +1,19 @@
1
+ import type { AgentWatchPaths } from '../../storage/types/storage.types.js';
2
+ /**
3
+ * Put the machine's current access token into every agent config that holds
4
+ * a literal OTLP bearer (Codex, Gemini).
5
+ *
6
+ * They read that header once, when a session starts
7
+ * (docs/NATIVE_OTLP_TOKENS.md), so the hook keeps the file on the live token
8
+ * for the next session. An agent is loaded only when its file holds a bearer
9
+ * that is not this one, so the usual hook pays one small read per agent and no
10
+ * import. Each agent changes nothing but its own bearer.
11
+ *
12
+ * Never throws: a file that cannot be read or written is left as it is, and
13
+ * the next hook tries again.
14
+ *
15
+ * @param paths - Resolved AgentWatch paths, for the install state.
16
+ * @param bearer - The machine's current access token.
17
+ * @returns How many files were rewritten.
18
+ */
19
+ export declare function rewriteNativeBearers(paths: AgentWatchPaths, bearer: string): Promise<number>;
@@ -0,0 +1,46 @@
1
+ import fs from 'node:fs/promises';
2
+ import { debugLog } from '../../core/logger.js';
3
+ import { loadInstallState } from '../../storage/install-state.js';
4
+ import { BEARER_PREFIX } from '../constants/provider.constants.js';
5
+ import { loadProvider } from '../loaders.js';
6
+ /**
7
+ * Put the machine's current access token into every agent config that holds
8
+ * a literal OTLP bearer (Codex, Gemini).
9
+ *
10
+ * They read that header once, when a session starts
11
+ * (docs/NATIVE_OTLP_TOKENS.md), so the hook keeps the file on the live token
12
+ * for the next session. An agent is loaded only when its file holds a bearer
13
+ * that is not this one, so the usual hook pays one small read per agent and no
14
+ * import. Each agent changes nothing but its own bearer.
15
+ *
16
+ * Never throws: a file that cannot be read or written is left as it is, and
17
+ * the next hook tries again.
18
+ *
19
+ * @param paths - Resolved AgentWatch paths, for the install state.
20
+ * @param bearer - The machine's current access token.
21
+ * @returns How many files were rewritten.
22
+ */
23
+ export async function rewriteNativeBearers(paths, bearer) {
24
+ let rewritten = 0;
25
+ try {
26
+ const installState = await loadInstallState(paths);
27
+ for (const [id, agent] of Object.entries(installState.agents)) {
28
+ const configPath = agent.otelConfigPath;
29
+ const raw = configPath ? await fs.readFile(configPath, 'utf8').catch(() => '') : '';
30
+ if (!configPath || !raw.includes(BEARER_PREFIX) || raw.includes(BEARER_PREFIX + bearer))
31
+ continue;
32
+ try {
33
+ const configurator = (await loadProvider(id))?.nativeTelemetry;
34
+ if (await configurator?.rewriteBearer?.({ configPath, installState, bearer, raw }))
35
+ rewritten++;
36
+ }
37
+ catch (error) {
38
+ debugLog(`${id}: rewriting the native exporter bearer failed:`, error);
39
+ }
40
+ }
41
+ }
42
+ catch (error) {
43
+ debugLog('rewriting native exporter bearers failed:', error);
44
+ }
45
+ return rewritten;
46
+ }
@@ -4,3 +4,10 @@
4
4
  */
5
5
  /** Every JSON hook protocol AgentWatch registers names its event under this key. */
6
6
  export declare const PAYLOAD_HOOK_EVENT_KEY = "hook_event_name";
7
+ /**
8
+ * The hooks a notice travels on, in both Claude Code and Codex: the untraced
9
+ * notice after a run, the update notice as a session starts. Both protocols
10
+ * take `systemMessage` on each (Codex: `SessionStartCommandOutputWire` flattens
11
+ * `HookUniversalOutputWire`, checked 2026-10-13).
12
+ */
13
+ export declare const NOTICE_EVENTS: ReadonlySet<string>;
@@ -4,3 +4,10 @@
4
4
  */
5
5
  /** Every JSON hook protocol AgentWatch registers names its event under this key. */
6
6
  export const PAYLOAD_HOOK_EVENT_KEY = 'hook_event_name';
7
+ /**
8
+ * The hooks a notice travels on, in both Claude Code and Codex: the untraced
9
+ * notice after a run, the update notice as a session starts. Both protocols
10
+ * take `systemMessage` on each (Codex: `SessionStartCommandOutputWire` flattens
11
+ * `HookUniversalOutputWire`, checked 2026-10-13).
12
+ */
13
+ export const NOTICE_EVENTS = new Set(['PostToolUse', 'SessionStart']);
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Patterns the shell-directory reader uses. Every one of them is applied to a
3
+ * command held in memory inside one pipeline stage; see `shell-directories.ts`.
4
+ */
5
+ /** A heredoc and its body: file content, not the command. */
6
+ export declare const RE_HEREDOC: RegExp;
7
+ /** What a heredoc is replaced with, so the command around it still reads. */
8
+ export declare const HEREDOC_PLACEHOLDER = "<<HEREDOC";
9
+ /** Command separators: each piece is read on its own, in order. */
10
+ export declare const RE_SHELL_SEPARATORS: RegExp;
11
+ /** `cd X` / `pushd X`: X is a directory, and later relative paths resolve against it. */
12
+ export declare const RE_CHANGE_DIRECTORY: RegExp;
13
+ /** Arguments that name a directory outright, relative or not. */
14
+ export declare const RE_DIRECTORY_ARGUMENTS: readonly RegExp[];
15
+ /** A quoted absolute or home-relative path anywhere in the command. */
16
+ export declare const RE_QUOTED_ABSOLUTE: RegExp;
17
+ /** A bare absolute or home-relative path, not glued to a longer word. */
18
+ export declare const RE_BARE_ABSOLUTE: RegExp;
19
+ /** A bare `./` or `../` path. */
20
+ export declare const RE_DOT_RELATIVE: RegExp;
21
+ /** `./x` or `../x`: relative on purpose, so resolved even outside a directory argument. */
22
+ export declare const RE_DOT_PREFIX: RegExp;
23
+ /** Home spelled the three ways a command spells it. */
24
+ export declare const RE_HOME_PREFIX: RegExp;
25
+ /** Anything the shell would still expand: not a path this reader can know. */
26
+ export declare const RE_UNEXPANDED: RegExp;
27
+ /** Surrounding quotes of one argument. */
28
+ export declare const RE_SURROUNDING_QUOTES: RegExp;
29
+ /** Directories one command may name before the rest are ignored: each one costs a walk of `stat`s. */
30
+ export declare const MAX_SHELL_DIRECTORIES = 32;