@agent-watch-ai/edge 0.2.5

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 (364) hide show
  1. package/CHANGELOG.md +251 -0
  2. package/LICENSE +21 -0
  3. package/README.md +168 -0
  4. package/dist/billing/billing-mode.d.ts +16 -0
  5. package/dist/billing/billing-mode.js +139 -0
  6. package/dist/billing/constants/billing.constants.d.ts +37 -0
  7. package/dist/billing/constants/billing.constants.js +38 -0
  8. package/dist/billing/index.d.ts +6 -0
  9. package/dist/billing/index.js +6 -0
  10. package/dist/cli/args.d.ts +29 -0
  11. package/dist/cli/args.js +61 -0
  12. package/dist/cli/constants/cli.constants.d.ts +60 -0
  13. package/dist/cli/constants/cli.constants.js +60 -0
  14. package/dist/cli/context.d.ts +51 -0
  15. package/dist/cli/context.js +108 -0
  16. package/dist/cli/doctor.d.ts +15 -0
  17. package/dist/cli/doctor.js +416 -0
  18. package/dist/cli/hook.d.ts +20 -0
  19. package/dist/cli/hook.js +166 -0
  20. package/dist/cli/index.d.ts +13 -0
  21. package/dist/cli/index.js +8 -0
  22. package/dist/cli/misc.d.ts +31 -0
  23. package/dist/cli/misc.js +63 -0
  24. package/dist/cli/setup.d.ts +32 -0
  25. package/dist/cli/setup.js +298 -0
  26. package/dist/cli/status.d.ts +11 -0
  27. package/dist/cli/status.js +174 -0
  28. package/dist/cli/types/cli.types.d.ts +69 -0
  29. package/dist/cli/types/cli.types.js +1 -0
  30. package/dist/cli/ui.d.ts +41 -0
  31. package/dist/cli/ui.js +78 -0
  32. package/dist/cli/uninstall.d.ts +13 -0
  33. package/dist/cli/uninstall.js +83 -0
  34. package/dist/cli.d.ts +2 -0
  35. package/dist/cli.js +124 -0
  36. package/dist/config/config-store.d.ts +29 -0
  37. package/dist/config/config-store.js +75 -0
  38. package/dist/config/config.d.ts +73 -0
  39. package/dist/config/config.js +115 -0
  40. package/dist/config/constants/config.constants.d.ts +62 -0
  41. package/dist/config/constants/config.constants.js +70 -0
  42. package/dist/config/index.d.ts +10 -0
  43. package/dist/config/index.js +5 -0
  44. package/dist/config/repo-config.d.ts +37 -0
  45. package/dist/config/repo-config.js +178 -0
  46. package/dist/config/schemas/config.schema.d.ts +409 -0
  47. package/dist/config/schemas/config.schema.js +97 -0
  48. package/dist/config/types/config.types.d.ts +33 -0
  49. package/dist/config/types/config.types.js +1 -0
  50. package/dist/core/async.d.ts +20 -0
  51. package/dist/core/async.js +32 -0
  52. package/dist/core/constants/core.constants.d.ts +18 -0
  53. package/dist/core/constants/core.constants.js +18 -0
  54. package/dist/core/env.d.ts +12 -0
  55. package/dist/core/env.js +20 -0
  56. package/dist/core/index.d.ts +13 -0
  57. package/dist/core/index.js +8 -0
  58. package/dist/core/logger.d.ts +27 -0
  59. package/dist/core/logger.js +82 -0
  60. package/dist/core/number.d.ts +33 -0
  61. package/dist/core/number.js +47 -0
  62. package/dist/core/object.d.ts +78 -0
  63. package/dist/core/object.js +127 -0
  64. package/dist/core/pipe.d.ts +55 -0
  65. package/dist/core/pipe.js +81 -0
  66. package/dist/core/types/core.types.d.ts +54 -0
  67. package/dist/core/types/core.types.js +4 -0
  68. package/dist/core/version.d.ts +19 -0
  69. package/dist/core/version.js +35 -0
  70. package/dist/core/which.d.ts +13 -0
  71. package/dist/core/which.js +57 -0
  72. package/dist/enforcement/constants/enforcement.constants.d.ts +23 -0
  73. package/dist/enforcement/constants/enforcement.constants.js +22 -0
  74. package/dist/enforcement/decision-cache.d.ts +57 -0
  75. package/dist/enforcement/decision-cache.js +138 -0
  76. package/dist/enforcement/decision-client.d.ts +14 -0
  77. package/dist/enforcement/decision-client.js +84 -0
  78. package/dist/enforcement/enforcement.d.ts +17 -0
  79. package/dist/enforcement/enforcement.js +90 -0
  80. package/dist/enforcement/index.d.ts +11 -0
  81. package/dist/enforcement/index.js +10 -0
  82. package/dist/enforcement/schemas/enforcement.schema.d.ts +30 -0
  83. package/dist/enforcement/schemas/enforcement.schema.js +36 -0
  84. package/dist/enforcement/types/enforcement.types.d.ts +59 -0
  85. package/dist/enforcement/types/enforcement.types.js +1 -0
  86. package/dist/enrollment/constants/enrollment.constants.d.ts +6 -0
  87. package/dist/enrollment/constants/enrollment.constants.js +6 -0
  88. package/dist/enrollment/enrollment-provider.d.ts +5 -0
  89. package/dist/enrollment/enrollment-provider.js +1 -0
  90. package/dist/enrollment/index.d.ts +7 -0
  91. package/dist/enrollment/index.js +1 -0
  92. package/dist/enrollment/manual-enrollment.d.ts +32 -0
  93. package/dist/enrollment/manual-enrollment.js +72 -0
  94. package/dist/enrollment/types/enrollment.types.d.ts +25 -0
  95. package/dist/enrollment/types/enrollment.types.js +1 -0
  96. package/dist/events/canonical-event.d.ts +10 -0
  97. package/dist/events/canonical-event.js +9 -0
  98. package/dist/events/constants/enrich.constants.d.ts +14 -0
  99. package/dist/events/constants/enrich.constants.js +15 -0
  100. package/dist/events/constants/events.constants.d.ts +35 -0
  101. package/dist/events/constants/events.constants.js +57 -0
  102. package/dist/events/enrich.d.ts +16 -0
  103. package/dist/events/enrich.js +226 -0
  104. package/dist/events/event-id.d.ts +32 -0
  105. package/dist/events/event-id.js +49 -0
  106. package/dist/events/index.d.ts +14 -0
  107. package/dist/events/index.js +5 -0
  108. package/dist/events/llm-call.d.ts +14 -0
  109. package/dist/events/llm-call.js +84 -0
  110. package/dist/events/product-event.d.ts +39 -0
  111. package/dist/events/product-event.js +19 -0
  112. package/dist/events/types/enrich.types.d.ts +25 -0
  113. package/dist/events/types/enrich.types.js +1 -0
  114. package/dist/events/types/events.types.d.ts +112 -0
  115. package/dist/events/types/events.types.js +1 -0
  116. package/dist/events/types/llm-call.types.d.ts +79 -0
  117. package/dist/events/types/llm-call.types.js +1 -0
  118. package/dist/events/types/repo-snapshot.types.d.ts +32 -0
  119. package/dist/events/types/repo-snapshot.types.js +1 -0
  120. package/dist/feature/constants/feature.constants.d.ts +10 -0
  121. package/dist/feature/constants/feature.constants.js +10 -0
  122. package/dist/feature/index.d.ts +6 -0
  123. package/dist/feature/index.js +6 -0
  124. package/dist/feature/ticket-candidates.d.ts +13 -0
  125. package/dist/feature/ticket-candidates.js +26 -0
  126. package/dist/git/constants/git.constants.d.ts +84 -0
  127. package/dist/git/constants/git.constants.js +113 -0
  128. package/dist/git/git-context.d.ts +52 -0
  129. package/dist/git/git-context.js +226 -0
  130. package/dist/git/index.d.ts +9 -0
  131. package/dist/git/index.js +3 -0
  132. package/dist/git/remote-sanitize.d.ts +26 -0
  133. package/dist/git/remote-sanitize.js +92 -0
  134. package/dist/git/repo-snapshot.d.ts +40 -0
  135. package/dist/git/repo-snapshot.js +95 -0
  136. package/dist/git/types/git.types.d.ts +36 -0
  137. package/dist/git/types/git.types.js +1 -0
  138. package/dist/git/types/snapshot.types.d.ts +25 -0
  139. package/dist/git/types/snapshot.types.js +1 -0
  140. package/dist/otlp/constants/otlp.constants.d.ts +84 -0
  141. package/dist/otlp/constants/otlp.constants.js +99 -0
  142. package/dist/otlp/http.d.ts +24 -0
  143. package/dist/otlp/http.js +37 -0
  144. package/dist/otlp/index.d.ts +9 -0
  145. package/dist/otlp/index.js +3 -0
  146. package/dist/otlp/normalize.d.ts +14 -0
  147. package/dist/otlp/normalize.js +404 -0
  148. package/dist/otlp/types/otlp.types.d.ts +69 -0
  149. package/dist/otlp/types/otlp.types.js +1 -0
  150. package/dist/pipeline/constants/pipeline.constants.d.ts +23 -0
  151. package/dist/pipeline/constants/pipeline.constants.js +22 -0
  152. package/dist/pipeline/hook-pipeline.d.ts +14 -0
  153. package/dist/pipeline/hook-pipeline.js +297 -0
  154. package/dist/pipeline/index.d.ts +6 -0
  155. package/dist/pipeline/index.js +1 -0
  156. package/dist/pipeline/types/pipeline.types.d.ts +48 -0
  157. package/dist/pipeline/types/pipeline.types.js +1 -0
  158. package/dist/privacy/constants/privacy.constants.d.ts +23 -0
  159. package/dist/privacy/constants/privacy.constants.js +38 -0
  160. package/dist/privacy/index.d.ts +7 -0
  161. package/dist/privacy/index.js +2 -0
  162. package/dist/privacy/sanitizer.d.ts +20 -0
  163. package/dist/privacy/sanitizer.js +52 -0
  164. package/dist/privacy/types/privacy.types.d.ts +13 -0
  165. package/dist/privacy/types/privacy.types.js +1 -0
  166. package/dist/providers/antigravity/antigravity.adapter.d.ts +54 -0
  167. package/dist/providers/antigravity/antigravity.adapter.js +311 -0
  168. package/dist/providers/antigravity/antigravity.detect.d.ts +25 -0
  169. package/dist/providers/antigravity/antigravity.detect.js +64 -0
  170. package/dist/providers/antigravity/antigravity.hooks.d.ts +24 -0
  171. package/dist/providers/antigravity/antigravity.hooks.js +126 -0
  172. package/dist/providers/antigravity/antigravity.provider.d.ts +2 -0
  173. package/dist/providers/antigravity/antigravity.provider.js +22 -0
  174. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +72 -0
  175. package/dist/providers/antigravity/constants/antigravity.constants.js +75 -0
  176. package/dist/providers/antigravity/schemas/antigravity.schema.d.ts +521 -0
  177. package/dist/providers/antigravity/schemas/antigravity.schema.js +64 -0
  178. package/dist/providers/antigravity/types/antigravity.types.d.ts +13 -0
  179. package/dist/providers/antigravity/types/antigravity.types.js +1 -0
  180. package/dist/providers/claude/claude.adapter.d.ts +15 -0
  181. package/dist/providers/claude/claude.adapter.js +141 -0
  182. package/dist/providers/claude/claude.detect.d.ts +20 -0
  183. package/dist/providers/claude/claude.detect.js +57 -0
  184. package/dist/providers/claude/claude.hooks.d.ts +23 -0
  185. package/dist/providers/claude/claude.hooks.js +94 -0
  186. package/dist/providers/claude/claude.otel.d.ts +95 -0
  187. package/dist/providers/claude/claude.otel.js +331 -0
  188. package/dist/providers/claude/claude.provider.d.ts +2 -0
  189. package/dist/providers/claude/claude.provider.js +26 -0
  190. package/dist/providers/claude/constants/claude.constants.d.ts +34 -0
  191. package/dist/providers/claude/constants/claude.constants.js +54 -0
  192. package/dist/providers/claude/constants/claude.otel.constants.d.ts +17 -0
  193. package/dist/providers/claude/constants/claude.otel.constants.js +17 -0
  194. package/dist/providers/claude/schemas/claude.schema.d.ts +72 -0
  195. package/dist/providers/claude/schemas/claude.schema.js +32 -0
  196. package/dist/providers/claude/types/claude.types.d.ts +3 -0
  197. package/dist/providers/claude/types/claude.types.js +1 -0
  198. package/dist/providers/codex/codex.adapter.d.ts +11 -0
  199. package/dist/providers/codex/codex.adapter.js +106 -0
  200. package/dist/providers/codex/codex.detect.d.ts +30 -0
  201. package/dist/providers/codex/codex.detect.js +58 -0
  202. package/dist/providers/codex/codex.hooks.d.ts +27 -0
  203. package/dist/providers/codex/codex.hooks.js +129 -0
  204. package/dist/providers/codex/codex.otel.d.ts +51 -0
  205. package/dist/providers/codex/codex.otel.js +325 -0
  206. package/dist/providers/codex/codex.provider.d.ts +2 -0
  207. package/dist/providers/codex/codex.provider.js +25 -0
  208. package/dist/providers/codex/constants/codex.constants.d.ts +41 -0
  209. package/dist/providers/codex/constants/codex.constants.js +62 -0
  210. package/dist/providers/codex/constants/codex.otel.constants.d.ts +22 -0
  211. package/dist/providers/codex/constants/codex.otel.constants.js +22 -0
  212. package/dist/providers/codex/schemas/codex.schema.d.ts +70 -0
  213. package/dist/providers/codex/schemas/codex.schema.js +32 -0
  214. package/dist/providers/codex/types/codex.types.d.ts +3 -0
  215. package/dist/providers/codex/types/codex.types.js +1 -0
  216. package/dist/providers/constants/provider.constants.d.ts +33 -0
  217. package/dist/providers/constants/provider.constants.js +33 -0
  218. package/dist/providers/cursor/constants/cursor.constants.d.ts +58 -0
  219. package/dist/providers/cursor/constants/cursor.constants.js +95 -0
  220. package/dist/providers/cursor/cursor.adapter.d.ts +11 -0
  221. package/dist/providers/cursor/cursor.adapter.js +331 -0
  222. package/dist/providers/cursor/cursor.detect.d.ts +23 -0
  223. package/dist/providers/cursor/cursor.detect.js +66 -0
  224. package/dist/providers/cursor/cursor.hooks.d.ts +25 -0
  225. package/dist/providers/cursor/cursor.hooks.js +95 -0
  226. package/dist/providers/cursor/cursor.provider.d.ts +2 -0
  227. package/dist/providers/cursor/cursor.provider.js +27 -0
  228. package/dist/providers/cursor/schemas/cursor.schema.d.ts +130 -0
  229. package/dist/providers/cursor/schemas/cursor.schema.js +62 -0
  230. package/dist/providers/cursor/types/cursor.types.d.ts +3 -0
  231. package/dist/providers/cursor/types/cursor.types.js +1 -0
  232. package/dist/providers/gemini/constants/gemini.constants.d.ts +36 -0
  233. package/dist/providers/gemini/constants/gemini.constants.js +58 -0
  234. package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +34 -0
  235. package/dist/providers/gemini/constants/gemini.otel.constants.js +48 -0
  236. package/dist/providers/gemini/gemini.adapter.d.ts +15 -0
  237. package/dist/providers/gemini/gemini.adapter.js +146 -0
  238. package/dist/providers/gemini/gemini.detect.d.ts +23 -0
  239. package/dist/providers/gemini/gemini.detect.js +78 -0
  240. package/dist/providers/gemini/gemini.hooks.d.ts +22 -0
  241. package/dist/providers/gemini/gemini.hooks.js +93 -0
  242. package/dist/providers/gemini/gemini.otel.d.ts +62 -0
  243. package/dist/providers/gemini/gemini.otel.js +274 -0
  244. package/dist/providers/gemini/gemini.provider.d.ts +2 -0
  245. package/dist/providers/gemini/gemini.provider.js +22 -0
  246. package/dist/providers/gemini/schemas/gemini.schema.d.ts +81 -0
  247. package/dist/providers/gemini/schemas/gemini.schema.js +35 -0
  248. package/dist/providers/gemini/types/gemini.types.d.ts +3 -0
  249. package/dist/providers/gemini/types/gemini.types.js +1 -0
  250. package/dist/providers/index.d.ts +14 -0
  251. package/dist/providers/index.js +8 -0
  252. package/dist/providers/provider.d.ts +16 -0
  253. package/dist/providers/provider.js +149 -0
  254. package/dist/providers/registry.d.ts +12 -0
  255. package/dist/providers/registry.js +23 -0
  256. package/dist/providers/shared/constants/hook-refusal.constants.d.ts +6 -0
  257. package/dist/providers/shared/constants/hook-refusal.constants.js +6 -0
  258. package/dist/providers/shared/constants/tooling.constants.d.ts +25 -0
  259. package/dist/providers/shared/constants/tooling.constants.js +25 -0
  260. package/dist/providers/shared/event-builder.d.ts +85 -0
  261. package/dist/providers/shared/event-builder.js +166 -0
  262. package/dist/providers/shared/hook-config.d.ts +80 -0
  263. package/dist/providers/shared/hook-config.js +164 -0
  264. package/dist/providers/shared/hook-refusal.d.ts +16 -0
  265. package/dist/providers/shared/hook-refusal.js +33 -0
  266. package/dist/providers/shared/install-record.d.ts +75 -0
  267. package/dist/providers/shared/install-record.js +113 -0
  268. package/dist/providers/shared/tooling.d.ts +58 -0
  269. package/dist/providers/shared/tooling.js +103 -0
  270. package/dist/providers/shared/types/adapter.types.d.ts +54 -0
  271. package/dist/providers/shared/types/adapter.types.js +1 -0
  272. package/dist/providers/shared/types/hook-config.types.d.ts +32 -0
  273. package/dist/providers/shared/types/hook-config.types.js +1 -0
  274. package/dist/providers/types/provider.types.d.ts +98 -0
  275. package/dist/providers/types/provider.types.js +1 -0
  276. package/dist/snapshot/branch-selection.d.ts +37 -0
  277. package/dist/snapshot/branch-selection.js +69 -0
  278. package/dist/snapshot/budget.d.ts +41 -0
  279. package/dist/snapshot/budget.js +67 -0
  280. package/dist/snapshot/constants/snapshot-stages.constants.d.ts +11 -0
  281. package/dist/snapshot/constants/snapshot-stages.constants.js +11 -0
  282. package/dist/snapshot/constants/snapshot.constants.d.ts +56 -0
  283. package/dist/snapshot/constants/snapshot.constants.js +56 -0
  284. package/dist/snapshot/index.d.ts +16 -0
  285. package/dist/snapshot/index.js +6 -0
  286. package/dist/snapshot/snapshot-event.d.ts +17 -0
  287. package/dist/snapshot/snapshot-event.js +66 -0
  288. package/dist/snapshot/snapshot-pipeline.d.ts +14 -0
  289. package/dist/snapshot/snapshot-pipeline.js +163 -0
  290. package/dist/snapshot/snapshot-state.d.ts +55 -0
  291. package/dist/snapshot/snapshot-state.js +100 -0
  292. package/dist/snapshot/types/snapshot.types.d.ts +86 -0
  293. package/dist/snapshot/types/snapshot.types.js +1 -0
  294. package/dist/storage/atomic-file.d.ts +25 -0
  295. package/dist/storage/atomic-file.js +76 -0
  296. package/dist/storage/constants/storage.constants.d.ts +34 -0
  297. package/dist/storage/constants/storage.constants.js +35 -0
  298. package/dist/storage/index.d.ts +10 -0
  299. package/dist/storage/index.js +5 -0
  300. package/dist/storage/install-state.d.ts +20 -0
  301. package/dist/storage/install-state.js +40 -0
  302. package/dist/storage/json-file.d.ts +13 -0
  303. package/dist/storage/json-file.js +31 -0
  304. package/dist/storage/lock.d.ts +15 -0
  305. package/dist/storage/lock.js +70 -0
  306. package/dist/storage/paths.d.ts +14 -0
  307. package/dist/storage/paths.js +42 -0
  308. package/dist/storage/schemas/storage.schema.d.ts +128 -0
  309. package/dist/storage/schemas/storage.schema.js +27 -0
  310. package/dist/storage/types/storage.types.d.ts +36 -0
  311. package/dist/storage/types/storage.types.js +1 -0
  312. package/dist/transport/constants/transport.constants.d.ts +47 -0
  313. package/dist/transport/constants/transport.constants.js +47 -0
  314. package/dist/transport/cooldown.d.ts +35 -0
  315. package/dist/transport/cooldown.js +62 -0
  316. package/dist/transport/delivery-stats.d.ts +65 -0
  317. package/dist/transport/delivery-stats.js +186 -0
  318. package/dist/transport/delivery.d.ts +26 -0
  319. package/dist/transport/delivery.js +80 -0
  320. package/dist/transport/headers.d.ts +12 -0
  321. package/dist/transport/headers.js +19 -0
  322. package/dist/transport/http-transport.d.ts +39 -0
  323. package/dist/transport/http-transport.js +106 -0
  324. package/dist/transport/index.d.ts +13 -0
  325. package/dist/transport/index.js +7 -0
  326. package/dist/transport/queue.d.ts +177 -0
  327. package/dist/transport/queue.js +474 -0
  328. package/dist/transport/schemas/queue.schema.d.ts +30 -0
  329. package/dist/transport/schemas/queue.schema.js +18 -0
  330. package/dist/transport/transport.d.ts +6 -0
  331. package/dist/transport/transport.js +1 -0
  332. package/dist/transport/types/transport.types.d.ts +102 -0
  333. package/dist/transport/types/transport.types.js +1 -0
  334. package/dist/turns/aggregate-usage.d.ts +20 -0
  335. package/dist/turns/aggregate-usage.js +269 -0
  336. package/dist/turns/claude-transcript.d.ts +18 -0
  337. package/dist/turns/claude-transcript.js +80 -0
  338. package/dist/turns/constants/turns.constants.d.ts +69 -0
  339. package/dist/turns/constants/turns.constants.js +86 -0
  340. package/dist/turns/cursor-transcript.d.ts +21 -0
  341. package/dist/turns/cursor-transcript.js +66 -0
  342. package/dist/turns/index.d.ts +17 -0
  343. package/dist/turns/index.js +7 -0
  344. package/dist/turns/transcript.d.ts +74 -0
  345. package/dist/turns/transcript.js +188 -0
  346. package/dist/turns/turn-state.d.ts +94 -0
  347. package/dist/turns/turn-state.js +234 -0
  348. package/dist/turns/turn-summary.d.ts +27 -0
  349. package/dist/turns/turn-summary.js +164 -0
  350. package/dist/turns/turn-tracker.d.ts +14 -0
  351. package/dist/turns/turn-tracker.js +521 -0
  352. package/dist/turns/types/aggregate-usage.types.d.ts +26 -0
  353. package/dist/turns/types/aggregate-usage.types.js +1 -0
  354. package/dist/turns/types/transcript.types.d.ts +41 -0
  355. package/dist/turns/types/transcript.types.js +1 -0
  356. package/dist/turns/types/turn-state.types.d.ts +37 -0
  357. package/dist/turns/types/turn-state.types.js +1 -0
  358. package/dist/turns/types/turn-summary.types.d.ts +106 -0
  359. package/dist/turns/types/turn-summary.types.js +1 -0
  360. package/dist/turns/types/turn-tracker.types.d.ts +27 -0
  361. package/dist/turns/types/turn-tracker.types.js +1 -0
  362. package/example/README.md +43 -0
  363. package/example/server.mjs +240 -0
  364. package/package.json +89 -0
@@ -0,0 +1,274 @@
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';
4
+ import { readJsonFile } from '../../storage/json-file.js';
5
+ import { HOOK_COMMAND_MARKER } from '../constants/provider.constants.js';
6
+ import { writeJsonValidated } from '../shared/hook-config.js';
7
+ import { withOtelInstall, withoutOtelInstall } from '../shared/install-record.js';
8
+ import { geminiSettingsPath } from './gemini.detect.js';
9
+ 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';
11
+ /**
12
+ * The environment Gemini CLI actually reads.
13
+ *
14
+ * Every name here was verified against the installed `@google/gemini-cli`
15
+ * bundle (`resolveTelemetrySettings`), because the previous set was written
16
+ * from Claude Code's vocabulary and Gemini reads none of it:
17
+ *
18
+ * - `GEMINI_TELEMETRY_ENABLED`, not `GEMINI_ENABLE_TELEMETRY`. The latter
19
+ * appears nowhere in the CLI, and `initializeTelemetry()` returns immediately
20
+ * unless the former is set, so no exporter was ever created.
21
+ * - Auth travels in `OTEL_EXPORTER_OTLP_HEADERS`. Gemini has no
22
+ * `otelHeadersHelper` — that is a Claude Code setting — so with the helper
23
+ * alone the exporter posted without an Authorization header and the gateway,
24
+ * which is fail-closed, answered 401 to every batch.
25
+ *
26
+ * @param context - Environment, paths and effective config.
27
+ * @returns The desired variables, or undefined when telemetry is off or no
28
+ * backend is configured.
29
+ */
30
+ export function desiredGeminiOtelEnv(context) {
31
+ const otlpBase = otlpBaseUrl(context.config);
32
+ if (!otlpBase || !otelEnabled(context.config))
33
+ return undefined;
34
+ const signals = context.config.otel;
35
+ return {
36
+ GEMINI_TELEMETRY_ENABLED: 'true',
37
+ GEMINI_TELEMETRY_TARGET: GEMINI_TELEMETRY_TARGET_LOCAL,
38
+ GEMINI_TELEMETRY_OTLP_ENDPOINT: otlpBase,
39
+ GEMINI_TELEMETRY_OTLP_PROTOCOL: GEMINI_OTLP_PROTOCOL,
40
+ GEMINI_TELEMETRY_TRACES_ENABLED: signals.traces ? 'true' : 'false',
41
+ OTEL_METRICS_EXPORTER: signals.metrics ? OTEL_EXPORTER_OTLP : OTEL_EXPORTER_NONE,
42
+ OTEL_LOGS_EXPORTER: signals.logs ? OTEL_EXPORTER_OTLP : OTEL_EXPORTER_NONE,
43
+ OTEL_TRACES_EXPORTER: signals.traces ? OTEL_EXPORTER_OTLP : OTEL_EXPORTER_NONE,
44
+ OTEL_EXPORTER_OTLP_PROTOCOL: STANDARD_OTLP_PROTOCOL,
45
+ OTEL_EXPORTER_OTLP_ENDPOINT: otlpBase,
46
+ ...(context.config.token ? { [OTLP_HEADERS_KEY]: `Authorization=Bearer ${context.config.token}` } : {})
47
+ };
48
+ }
49
+ /** Configures Gemini CLI's own OTLP export. */
50
+ export class GeminiOtelConfigurator {
51
+ /**
52
+ * Whether this agent can export native telemetry at all.
53
+ *
54
+ * @param _env - Unused; Gemini CLI always supports it.
55
+ * @returns Always true.
56
+ */
57
+ async supported(_env) {
58
+ return true;
59
+ }
60
+ /**
61
+ * Report whether the machine's telemetry configuration matches what we want.
62
+ *
63
+ * @param context - Environment, paths, config and install state.
64
+ * @returns The status, naming any foreign configuration in the way.
65
+ */
66
+ async inspect(context) {
67
+ const disabled = !otelEnabled(context.config);
68
+ const read = await readJsonFile(geminiSettingsPath(context.env));
69
+ const settings = read.state === 'ok' ? asRecord(read.value) : undefined;
70
+ if (!settings) {
71
+ if (disabled && read.state === 'missing')
72
+ return { supported: true, configured: true, detail: 'disabled in config (otel)' };
73
+ return { supported: true, configured: false, detail: read.state === 'invalid' ? 'settings unparseable' : 'no settings file' };
74
+ }
75
+ const envBlock = asRecord(settings[ENV_BLOCK_KEY]) ?? {};
76
+ const ownedKeys = ownedKeysOf(context);
77
+ if (disabled)
78
+ return inspectDisabled(settings, envBlock, ownedKeys);
79
+ const desired = desiredGeminiOtelEnv(context);
80
+ if (!desired)
81
+ return { supported: true, configured: false, detail: 'no backend endpoint configured' };
82
+ const matches = Object.entries(desired).every(([key, value]) => envBlock[key] === value);
83
+ // A helper entry left by an older version is dead weight Gemini ignores;
84
+ // reporting "configured" would hide that setup still has work to do. A
85
+ // helper belonging to another tool is none of our business.
86
+ if (matches && !hasOurLegacyHelper(settings))
87
+ return { supported: true, configured: true };
88
+ if (matches)
89
+ return { supported: true, configured: false, detail: 'stale otelHeadersHelper entry — run `agentwatch setup`' };
90
+ const conflicting = foreignKeys(envBlock, desired, ownedKeys);
91
+ if (conflicting.length > 0) {
92
+ return { supported: true, configured: false, conflict: `existing telemetry env vars: ${conflicting.join(', ')}` };
93
+ }
94
+ return { supported: true, configured: false };
95
+ }
96
+ /**
97
+ * Write the telemetry configuration into Gemini CLI's settings.
98
+ *
99
+ * @param context - Environment, paths, config and install state.
100
+ * @returns Whether the file changed, what to tell the user, and the next
101
+ * install state.
102
+ */
103
+ async configure(context) {
104
+ const desired = desiredGeminiOtelEnv(context);
105
+ if (!desired)
106
+ return this.configureDisabled(context);
107
+ const settingsPath = geminiSettingsPath(context.env);
108
+ const read = await readJsonFile(settingsPath);
109
+ if (read.state === 'invalid') {
110
+ return { ok: false, changed: false, messages: [`refusing to modify unparseable ${settingsPath} (${read.error})`] };
111
+ }
112
+ if (read.state === 'ok' && !asRecord(read.value)) {
113
+ return { ok: false, changed: false, messages: [`refusing to modify ${settingsPath}: top level is not an object`] };
114
+ }
115
+ const settings = (read.state === 'ok' ? asRecord(read.value) : undefined) ?? {};
116
+ const envBlock = asRecord(settings[ENV_BLOCK_KEY]) ?? {};
117
+ const ownedKeys = ownedKeysOf(context);
118
+ const conflicting = foreignKeys(envBlock, desired, ownedKeys);
119
+ if (conflicting.length > 0) {
120
+ return {
121
+ ok: false,
122
+ changed: false,
123
+ messages: [`skipping native OpenTelemetry: ${conflicting.join(', ')} already set in ${settingsPath} (not AgentWatch-owned)`]
124
+ };
125
+ }
126
+ // Keys we own that this configuration no longer wants (a signal turned off
127
+ // since the last run) would otherwise linger.
128
+ const stale = new Set(ownedKeys.filter((key) => key !== LEGACY_HELPER_KEY && desired[key] === undefined));
129
+ const withEnv = { ...settings, [ENV_BLOCK_KEY]: { ...omitKeys(envBlock, stale), ...desired } };
130
+ // Gemini never read this; leaving it behind only confuses the next reader.
131
+ const nextSettings = hasOurLegacyHelper(withEnv) ? omitKeys(withEnv, new Set([LEGACY_HELPER_KEY])) : withEnv;
132
+ const changed = JSON.stringify(nextSettings) !== JSON.stringify(settings);
133
+ if (changed) {
134
+ await backupFile(settingsPath, context.paths.backupsDir, context.env.now());
135
+ await writeJsonValidated(settingsPath, nextSettings);
136
+ }
137
+ return {
138
+ ok: true,
139
+ changed,
140
+ messages: changed
141
+ ? [`native OpenTelemetry configured (signals: ${enabledSignalNames(context.config.otel).join(', ')})`, 'restart running Gemini CLI sessions to pick it up']
142
+ : ['native OpenTelemetry already up to date'],
143
+ installState: withOtelInstall(context.installState, GEMINI_PROVIDER_ID, {
144
+ configPath: settingsPath,
145
+ ownedKeys: Object.keys(desired),
146
+ configuredAt: context.env.now()
147
+ })
148
+ };
149
+ }
150
+ /**
151
+ * Remove the telemetry configuration AgentWatch wrote.
152
+ *
153
+ * @param context - Environment, paths, config and install state.
154
+ * @returns Whether the file changed, what to tell the user, and the next
155
+ * install state.
156
+ */
157
+ async uninstall(context) {
158
+ const settingsPath = geminiSettingsPath(context.env);
159
+ const read = await readJsonFile(settingsPath);
160
+ if (read.state === 'missing')
161
+ return { ok: true, changed: false, messages: ['no Gemini settings file'] };
162
+ if (read.state === 'invalid') {
163
+ return { ok: false, changed: false, messages: [`refusing to modify unparseable ${settingsPath} (${read.error})`] };
164
+ }
165
+ const settings = asRecord(read.value);
166
+ if (!settings) {
167
+ return { ok: false, changed: false, messages: [`refusing to modify ${settingsPath}: top level is not an object`] };
168
+ }
169
+ const removable = new Set((context.installState.agents[GEMINI_PROVIDER_ID]?.otelOwnedKeys ?? GEMINI_LEGACY_OWNED_KEYS).filter((key) => key !== LEGACY_HELPER_KEY));
170
+ const nextSettings = strippedSettings(settings, removable);
171
+ const changed = JSON.stringify(nextSettings) !== JSON.stringify(settings);
172
+ if (changed) {
173
+ await backupFile(settingsPath, context.paths.backupsDir, context.env.now());
174
+ await writeJsonValidated(settingsPath, nextSettings);
175
+ }
176
+ return {
177
+ ok: true,
178
+ changed,
179
+ messages: changed ? ['native OpenTelemetry configuration removed'] : ['no AgentWatch OpenTelemetry configuration found'],
180
+ installState: withoutOtelInstall(context.installState, GEMINI_PROVIDER_ID)
181
+ };
182
+ }
183
+ /**
184
+ * Handle `configure` when telemetry is off or unconfigurable.
185
+ *
186
+ * @param context - Environment, paths, config and install state.
187
+ * @returns The outcome.
188
+ */
189
+ async configureDisabled(context) {
190
+ if (otelEnabled(context.config))
191
+ return { ok: false, changed: false, messages: ['no backend endpoint configured'] };
192
+ const removed = await this.uninstall(context);
193
+ if (!removed.ok)
194
+ return removed;
195
+ return {
196
+ ok: true,
197
+ changed: removed.changed,
198
+ messages: [
199
+ removed.changed
200
+ ? 'native OpenTelemetry disabled in config; previous configuration removed'
201
+ : 'native OpenTelemetry disabled in config (otel: none)'
202
+ ],
203
+ installState: removed.installState
204
+ };
205
+ }
206
+ }
207
+ /**
208
+ * Settings keys a previous AgentWatch setup recorded as its own.
209
+ *
210
+ * @param context - Install state carrier.
211
+ * @returns The recorded keys.
212
+ */
213
+ function ownedKeysOf(context) {
214
+ return context.installState.agents[GEMINI_PROVIDER_ID]?.otelOwnedKeys ?? [];
215
+ }
216
+ /**
217
+ * Status when telemetry is deliberately off.
218
+ *
219
+ * @param settings - The whole settings object.
220
+ * @param envBlock - Its env block.
221
+ * @param ownedKeys - Keys a previous setup recorded.
222
+ * @returns Configured, unless our own leftovers are still in place.
223
+ */
224
+ function inspectDisabled(settings, envBlock, ownedKeys) {
225
+ const leftover = ownedKeys.some((key) => (key === LEGACY_HELPER_KEY ? settings[key] !== undefined : envBlock[key] !== undefined)) || hasOurLegacyHelper(settings);
226
+ if (!leftover)
227
+ return { supported: true, configured: true, detail: 'disabled in config (otel)' };
228
+ return {
229
+ supported: true,
230
+ configured: false,
231
+ detail: 'disabled in config, but previous telemetry env vars remain — run `agentwatch setup`'
232
+ };
233
+ }
234
+ /**
235
+ * Desired keys already set to a value we did not write.
236
+ *
237
+ * @param envBlock - Current env block.
238
+ * @param desired - What we want to write.
239
+ * @param ownedKeys - Keys a previous setup recorded as ours.
240
+ * @returns The conflicting key names.
241
+ */
242
+ function foreignKeys(envBlock, desired, ownedKeys) {
243
+ const owned = new Set(ownedKeys);
244
+ return Object.keys(desired).filter((key) => envBlock[key] !== undefined && envBlock[key] !== desired[key] && !owned.has(key));
245
+ }
246
+ /**
247
+ * Settings with our telemetry keys and legacy helper removed.
248
+ *
249
+ * @param settings - The whole settings object.
250
+ * @param removable - Env keys to drop.
251
+ * @returns The next settings object.
252
+ */
253
+ function strippedSettings(settings, removable) {
254
+ const withoutHelper = hasOurLegacyHelper(settings) ? omitKeys(settings, new Set([LEGACY_HELPER_KEY])) : settings;
255
+ const envBlock = asRecord(withoutHelper[ENV_BLOCK_KEY]);
256
+ if (!envBlock)
257
+ return withoutHelper;
258
+ const nextEnv = omitKeys(envBlock, removable);
259
+ // An emptied env block is dropped rather than left as `"env": {}`.
260
+ if (Object.keys(nextEnv).length === 0)
261
+ return omitKeys(withoutHelper, new Set([ENV_BLOCK_KEY]));
262
+ return { ...withoutHelper, [ENV_BLOCK_KEY]: nextEnv };
263
+ }
264
+ /**
265
+ * Whether the settings carry an `otelHeadersHelper` this tool wrote, as
266
+ * opposed to somebody else's.
267
+ *
268
+ * @param settings - The whole settings object.
269
+ * @returns True when the entry is ours.
270
+ */
271
+ function hasOurLegacyHelper(settings) {
272
+ const value = settings[LEGACY_HELPER_KEY];
273
+ return typeof value === 'string' && value.includes(HOOK_COMMAND_MARKER);
274
+ }
@@ -0,0 +1,2 @@
1
+ import type { AgentProvider } from '../provider.js';
2
+ export declare const geminiProvider: AgentProvider;
@@ -0,0 +1,22 @@
1
+ import { hookRefusal } from '../shared/hook-refusal.js';
2
+ import { GEMINI_PROMPT_EVENTS } from './constants/gemini.constants.js';
3
+ import { detectGemini } from './gemini.detect.js';
4
+ import { installGeminiHooks, uninstallGeminiHooks } from './gemini.hooks.js';
5
+ import { parseGeminiHookEvent } from './gemini.adapter.js';
6
+ import { GeminiOtelConfigurator } from './gemini.otel.js';
7
+ export const geminiProvider = {
8
+ id: 'gemini',
9
+ displayName: 'Gemini CLI',
10
+ detect: detectGemini,
11
+ installHooks: installGeminiHooks,
12
+ uninstallHooks: uninstallGeminiHooks,
13
+ parseHookEvent: async (payload, context) => parseGeminiHookEvent(payload, context),
14
+ getHookResponse: (_payload) => ({ exitCode: 0 }),
15
+ /**
16
+ * A budget refusal on the prompt hook: `decision: "deny"` makes Gemini CLI
17
+ * discard the user's message and show the reason. The gate is the prompt-hook
18
+ * set across both namings — exactly the hooks a refusal may travel on.
19
+ */
20
+ getBlockResponse: (payload, message) => hookRefusal(payload, GEMINI_PROMPT_EVENTS, { decision: 'deny', reason: message }),
21
+ nativeTelemetry: new GeminiOtelConfigurator()
22
+ };
@@ -0,0 +1,81 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Gemini CLI hook payload.
4
+ *
5
+ * Optional and passthrough throughout: the field names have changed across
6
+ * releases (BeforeAgent/AfterAgent replaced UserPromptSubmit/Stop) and an
7
+ * installation registered by an older version still sends the old shape.
8
+ */
9
+ export declare const geminiPayloadSchema: z.ZodObject<{
10
+ hook_event_name: z.ZodOptional<z.ZodString>;
11
+ session_id: z.ZodOptional<z.ZodString>;
12
+ thread_id: z.ZodOptional<z.ZodString>;
13
+ turn_id: z.ZodOptional<z.ZodString>;
14
+ prompt_id: z.ZodOptional<z.ZodString>;
15
+ transcript_path: z.ZodOptional<z.ZodString>;
16
+ cwd: z.ZodOptional<z.ZodString>;
17
+ permission_mode: z.ZodOptional<z.ZodString>;
18
+ agent_id: z.ZodOptional<z.ZodString>;
19
+ agent_type: z.ZodOptional<z.ZodString>;
20
+ tool_name: z.ZodOptional<z.ZodString>;
21
+ tool_use_id: z.ZodOptional<z.ZodString>;
22
+ tool_input: z.ZodOptional<z.ZodUnknown>;
23
+ tool_response: z.ZodOptional<z.ZodUnknown>;
24
+ tool_error: z.ZodOptional<z.ZodUnknown>;
25
+ prompt: z.ZodOptional<z.ZodString>;
26
+ prompt_response: z.ZodOptional<z.ZodString>;
27
+ source: z.ZodOptional<z.ZodString>;
28
+ model: z.ZodOptional<z.ZodString>;
29
+ reason: z.ZodOptional<z.ZodString>;
30
+ last_assistant_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
31
+ stop_hook_active: z.ZodOptional<z.ZodBoolean>;
32
+ denialReason: z.ZodOptional<z.ZodString>;
33
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
34
+ hook_event_name: z.ZodOptional<z.ZodString>;
35
+ session_id: z.ZodOptional<z.ZodString>;
36
+ thread_id: z.ZodOptional<z.ZodString>;
37
+ turn_id: z.ZodOptional<z.ZodString>;
38
+ prompt_id: z.ZodOptional<z.ZodString>;
39
+ transcript_path: z.ZodOptional<z.ZodString>;
40
+ cwd: z.ZodOptional<z.ZodString>;
41
+ permission_mode: z.ZodOptional<z.ZodString>;
42
+ agent_id: z.ZodOptional<z.ZodString>;
43
+ agent_type: z.ZodOptional<z.ZodString>;
44
+ tool_name: z.ZodOptional<z.ZodString>;
45
+ tool_use_id: z.ZodOptional<z.ZodString>;
46
+ tool_input: z.ZodOptional<z.ZodUnknown>;
47
+ tool_response: z.ZodOptional<z.ZodUnknown>;
48
+ tool_error: z.ZodOptional<z.ZodUnknown>;
49
+ prompt: z.ZodOptional<z.ZodString>;
50
+ prompt_response: z.ZodOptional<z.ZodString>;
51
+ source: z.ZodOptional<z.ZodString>;
52
+ model: z.ZodOptional<z.ZodString>;
53
+ reason: z.ZodOptional<z.ZodString>;
54
+ last_assistant_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
55
+ stop_hook_active: z.ZodOptional<z.ZodBoolean>;
56
+ denialReason: z.ZodOptional<z.ZodString>;
57
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
58
+ hook_event_name: z.ZodOptional<z.ZodString>;
59
+ session_id: z.ZodOptional<z.ZodString>;
60
+ thread_id: z.ZodOptional<z.ZodString>;
61
+ turn_id: z.ZodOptional<z.ZodString>;
62
+ prompt_id: z.ZodOptional<z.ZodString>;
63
+ transcript_path: z.ZodOptional<z.ZodString>;
64
+ cwd: z.ZodOptional<z.ZodString>;
65
+ permission_mode: z.ZodOptional<z.ZodString>;
66
+ agent_id: z.ZodOptional<z.ZodString>;
67
+ agent_type: z.ZodOptional<z.ZodString>;
68
+ tool_name: z.ZodOptional<z.ZodString>;
69
+ tool_use_id: z.ZodOptional<z.ZodString>;
70
+ tool_input: z.ZodOptional<z.ZodUnknown>;
71
+ tool_response: z.ZodOptional<z.ZodUnknown>;
72
+ tool_error: z.ZodOptional<z.ZodUnknown>;
73
+ prompt: z.ZodOptional<z.ZodString>;
74
+ prompt_response: z.ZodOptional<z.ZodString>;
75
+ source: z.ZodOptional<z.ZodString>;
76
+ model: z.ZodOptional<z.ZodString>;
77
+ reason: z.ZodOptional<z.ZodString>;
78
+ last_assistant_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
79
+ stop_hook_active: z.ZodOptional<z.ZodBoolean>;
80
+ denialReason: z.ZodOptional<z.ZodString>;
81
+ }, z.ZodTypeAny, "passthrough">>;
@@ -0,0 +1,35 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Gemini CLI hook payload.
4
+ *
5
+ * Optional and passthrough throughout: the field names have changed across
6
+ * releases (BeforeAgent/AfterAgent replaced UserPromptSubmit/Stop) and an
7
+ * installation registered by an older version still sends the old shape.
8
+ */
9
+ export const geminiPayloadSchema = z
10
+ .object({
11
+ hook_event_name: z.string().optional(),
12
+ session_id: z.string().optional(),
13
+ thread_id: z.string().optional(),
14
+ turn_id: z.string().optional(),
15
+ prompt_id: z.string().optional(),
16
+ transcript_path: z.string().optional(),
17
+ cwd: z.string().optional(),
18
+ permission_mode: z.string().optional(),
19
+ agent_id: z.string().optional(),
20
+ agent_type: z.string().optional(),
21
+ tool_name: z.string().optional(),
22
+ tool_use_id: z.string().optional(),
23
+ tool_input: z.unknown().optional(),
24
+ tool_response: z.unknown().optional(),
25
+ tool_error: z.unknown().optional(),
26
+ prompt: z.string().optional(),
27
+ prompt_response: z.string().optional(),
28
+ source: z.string().optional(),
29
+ model: z.string().optional(),
30
+ reason: z.string().optional(),
31
+ last_assistant_message: z.string().nullable().optional(),
32
+ stop_hook_active: z.boolean().optional(),
33
+ denialReason: z.string().optional()
34
+ })
35
+ .passthrough();
@@ -0,0 +1,3 @@
1
+ import type { z } from 'zod';
2
+ import type { geminiPayloadSchema } from '../schemas/gemini.schema.js';
3
+ export type GeminiPayload = z.infer<typeof geminiPayloadSchema>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * One AgentProvider per coding agent: how to detect it, how to register hooks
3
+ * and native telemetry in its own config, and how to translate its hook
4
+ * payloads into canonical events.
5
+ */
6
+ export type { AgentProvider, DetectionResult, HookContext, McpToolName, NativeTelemetryConfigurator, NativeTelemetryStatus, ProviderHookResponse, SetupContext, SetupOutcome, ToolKind, ToolStatus } from './types/provider.types.js';
7
+ export { HOOK_COMMAND_MARKER, KNOWN_AGENT_IDS } from './constants/provider.constants.js';
8
+ export { isAgentWatchHookCommand } from './provider.js';
9
+ export { getProvider, providerIds, providers } from './registry.js';
10
+ export { classifyTool, contentEvidence, extractCommand, extractFilePath, parseMcpToolName, toolCompleteType, toolStartType } from './shared/tooling.js';
11
+ export { baseEvent, filePathPatch, promptPatch, providerPatch, responsePatch, toolPatch, withPatch } from './shared/event-builder.js';
12
+ export { registerOurHandlers, stripOurHandlers, sweepUnregisteredEvents, withHooksBlock, writeJsonValidated } from './shared/hook-config.js';
13
+ export { hookRefusal } from './shared/hook-refusal.js';
14
+ export { withHookInstall, withOtelInstall, withoutAgent, withoutHookInstall, withoutOtelInstall } from './shared/install-record.js';
@@ -0,0 +1,8 @@
1
+ export { HOOK_COMMAND_MARKER, KNOWN_AGENT_IDS } from './constants/provider.constants.js';
2
+ export { isAgentWatchHookCommand } from './provider.js';
3
+ export { getProvider, providerIds, providers } from './registry.js';
4
+ export { classifyTool, contentEvidence, extractCommand, extractFilePath, parseMcpToolName, toolCompleteType, toolStartType } from './shared/tooling.js';
5
+ export { baseEvent, filePathPatch, promptPatch, providerPatch, responsePatch, toolPatch, withPatch } from './shared/event-builder.js';
6
+ export { registerOurHandlers, stripOurHandlers, sweepUnregisteredEvents, withHooksBlock, writeJsonValidated } from './shared/hook-config.js';
7
+ export { hookRefusal } from './shared/hook-refusal.js';
8
+ export { withHookInstall, withOtelInstall, withoutAgent, withoutHookInstall, withoutOtelInstall } from './shared/install-record.js';
@@ -0,0 +1,16 @@
1
+ export { HOOK_COMMAND_MARKER } from './constants/provider.constants.js';
2
+ export type { AgentProvider, DetectionResult, HookContext, McpToolName, NativeTelemetryConfigurator, NativeTelemetryStatus, ProviderHookResponse, SetupContext, SetupOutcome, ToolKind, ToolStatus } from './types/provider.types.js';
3
+ /**
4
+ * Whether a hook command registered in an agent's config is ours.
5
+ *
6
+ * Ownership decides what uninstall is allowed to delete, so the test is
7
+ * deliberately narrow: the executable invoked before `hook --agent` must
8
+ * actually be the agentwatch CLI — a binary named `agentwatch`, or the
9
+ * generated `dist/cli.js` run via node — the agent id must be one we support,
10
+ * and nothing may follow. A user's `my-agentwatch-notifier hook --agent x`, or
11
+ * a compound `echo agentwatch && my-tool hook --agent x`, must never be claimed.
12
+ *
13
+ * @param command - The command line found in the agent's config.
14
+ * @returns True only when AgentWatch wrote it.
15
+ */
16
+ export declare function isAgentWatchHookCommand(command: string): boolean;
@@ -0,0 +1,149 @@
1
+ import { HOOK_COMMAND_MARKER, KNOWN_AGENT_IDS, RE_AGENTWATCH_BINARY, RE_CLI_SCRIPT, RE_DOUBLE_QUOTE_ESCAPABLE, RE_NODE_BINARY, RE_PATH_SEPARATOR, RE_SHELL_CONTROL, RE_WHITESPACE } from './constants/provider.constants.js';
2
+ export { HOOK_COMMAND_MARKER } from './constants/provider.constants.js';
3
+ /**
4
+ * Whether a hook command registered in an agent's config is ours.
5
+ *
6
+ * Ownership decides what uninstall is allowed to delete, so the test is
7
+ * deliberately narrow: the executable invoked before `hook --agent` must
8
+ * actually be the agentwatch CLI — a binary named `agentwatch`, or the
9
+ * generated `dist/cli.js` run via node — the agent id must be one we support,
10
+ * and nothing may follow. A user's `my-agentwatch-notifier hook --agent x`, or
11
+ * a compound `echo agentwatch && my-tool hook --agent x`, must never be claimed.
12
+ *
13
+ * @param command - The command line found in the agent's config.
14
+ * @returns True only when AgentWatch wrote it.
15
+ */
16
+ export function isAgentWatchHookCommand(command) {
17
+ const tokens = tokenizeHookCommand(command);
18
+ if (!tokens)
19
+ return false;
20
+ const hookIndex = tokens.indexOf('hook');
21
+ if (hookIndex < 1 || tokens[hookIndex + 1] !== '--agent')
22
+ return false;
23
+ if (!KNOWN_AGENT_IDS.has(tokens[hookIndex + 2] ?? ''))
24
+ return false;
25
+ // Installed commands carry no trailing shell fragments or extra argv.
26
+ if (hookIndex + 3 !== tokens.length)
27
+ return false;
28
+ return isOurExecutable(tokens.slice(0, hookIndex));
29
+ }
30
+ /**
31
+ * Whether the tokens before `hook` name the agentwatch CLI.
32
+ *
33
+ * @param prefix - Tokens preceding the subcommand.
34
+ * @returns True for `agentwatch` or `<node> <cli script>`.
35
+ */
36
+ function isOurExecutable(prefix) {
37
+ if (prefix.length === 1)
38
+ return isAgentWatchBinary(prefix[0]);
39
+ if (prefix.length === 2)
40
+ return isNodeBinary(prefix[0]) && isAgentWatchCliScript(prefix[1]);
41
+ return false;
42
+ }
43
+ /**
44
+ * Whether a path names the installed agentwatch binary.
45
+ *
46
+ * @param value - Executable path or bare name.
47
+ * @returns True when its basename is ours.
48
+ */
49
+ function isAgentWatchBinary(value) {
50
+ return RE_AGENTWATCH_BINARY.test(pathBase(value).toLowerCase());
51
+ }
52
+ /**
53
+ * Whether a path names a Node-compatible runtime.
54
+ *
55
+ * @param value - Executable path or bare name.
56
+ * @returns True when it is one we may have embedded.
57
+ */
58
+ function isNodeBinary(value) {
59
+ return RE_NODE_BINARY.test(pathBase(value));
60
+ }
61
+ /**
62
+ * Whether a path is the agentwatch CLI entry script.
63
+ *
64
+ * `dist/cli.js` is accepted on its own — that exact suffix is what
65
+ * buildHookCommand emits, and the parent directory need not carry the package
66
+ * name (a renamed checkout). A dev install running the TypeScript entry point
67
+ * directly must additionally have the package name somewhere in its path, so a
68
+ * foreign tool's `cli.ts` is never claimed as ours.
69
+ *
70
+ * @param value - Script path.
71
+ * @returns True when it is our entry point.
72
+ */
73
+ function isAgentWatchCliScript(value) {
74
+ const segments = value.split(RE_PATH_SEPARATOR).filter(Boolean);
75
+ if (segments.length < 2)
76
+ return false;
77
+ const lower = segments.map((segment) => segment.toLowerCase());
78
+ const basename = lower.at(-1);
79
+ if (basename === 'cli.js' && lower.at(-2) === 'dist')
80
+ return true;
81
+ return RE_CLI_SCRIPT.test(basename) && lower.some((segment) => segment.includes(HOOK_COMMAND_MARKER));
82
+ }
83
+ /**
84
+ * Last path segment of a path using either platform's separator.
85
+ *
86
+ * @param value - The path.
87
+ * @returns Its basename.
88
+ */
89
+ function pathBase(value) {
90
+ return value.split(RE_PATH_SEPARATOR).pop() ?? '';
91
+ }
92
+ /**
93
+ * Minimal tokenizer for the exact commands buildHookCommand emits.
94
+ *
95
+ * Supports quoted paths and their escaped quote/backslash forms, and rejects
96
+ * any command containing a shell control operator — a command we cannot fully
97
+ * understand is one we must not claim ownership of.
98
+ *
99
+ * @param command - The command line.
100
+ * @returns Its tokens, or undefined when the command is not one we emit.
101
+ */
102
+ function tokenizeHookCommand(command) {
103
+ const tokens = [];
104
+ let token = '';
105
+ let started = false;
106
+ let quote;
107
+ for (let index = 0; index < command.length; index++) {
108
+ const char = command[index];
109
+ if (quote) {
110
+ if (char === quote) {
111
+ quote = undefined;
112
+ continue;
113
+ }
114
+ // Inside double quotes a backslash still escapes the shell's own
115
+ // specials; inside single quotes it is a literal character.
116
+ if (quote === '"' && char === '\\' && index + 1 < command.length && RE_DOUBLE_QUOTE_ESCAPABLE.test(command[index + 1])) {
117
+ token += command[++index];
118
+ started = true;
119
+ continue;
120
+ }
121
+ token += char;
122
+ started = true;
123
+ continue;
124
+ }
125
+ if (char === '"' || char === "'") {
126
+ quote = char;
127
+ started = true;
128
+ continue;
129
+ }
130
+ if (RE_WHITESPACE.test(char)) {
131
+ if (started)
132
+ tokens.push(token);
133
+ token = '';
134
+ started = false;
135
+ continue;
136
+ }
137
+ // A command we cannot fully understand is one we must not claim.
138
+ if (RE_SHELL_CONTROL.test(char))
139
+ return undefined;
140
+ token += char;
141
+ started = true;
142
+ }
143
+ // An unterminated quote means the command is not one we wrote.
144
+ if (quote)
145
+ return undefined;
146
+ if (started)
147
+ tokens.push(token);
148
+ return tokens;
149
+ }
@@ -0,0 +1,12 @@
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[];
4
+ /**
5
+ * The provider for an agent id.
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 getProvider(id: string): AgentProvider | undefined;
11
+ /** Every agent id the CLI accepts, for help and error messages. */
12
+ export declare const providerIds: readonly string[];
@@ -0,0 +1,23 @@
1
+ import { antigravityProvider } from './antigravity/antigravity.provider.js';
2
+ import { claudeProvider } from './claude/claude.provider.js';
3
+ import { codexProvider } from './codex/codex.provider.js';
4
+ import { cursorProvider } from './cursor/cursor.provider.js';
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]));
13
+ /**
14
+ * The provider for an agent id.
15
+ *
16
+ * @param id - Agent id as passed to `agentwatch hook --agent <id>`.
17
+ * @returns The provider, or undefined for an unknown agent.
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);
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Keys of the hook protocols themselves, as opposed to the payload fields the
3
+ * adapters read.
4
+ */
5
+ /** Every JSON hook protocol AgentWatch registers names its event under this key. */
6
+ export declare const PAYLOAD_HOOK_EVENT_KEY = "hook_event_name";