@agent-watch-ai/edge 0.2.5 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. package/CHANGELOG.md +512 -0
  2. package/README.md +217 -96
  3. package/SECURITY.md +69 -0
  4. package/dist/billing/session-billing.d.ts +19 -0
  5. package/dist/billing/session-billing.js +52 -0
  6. package/dist/cli/args.d.ts +10 -0
  7. package/dist/cli/args.js +20 -0
  8. package/dist/cli/constants/cli.constants.d.ts +50 -4
  9. package/dist/cli/constants/cli.constants.js +54 -5
  10. package/dist/cli/context.d.ts +33 -2
  11. package/dist/cli/context.js +84 -14
  12. package/dist/cli/doctor.js +309 -32
  13. package/dist/cli/hook-check.d.ts +23 -0
  14. package/dist/cli/hook-check.js +114 -0
  15. package/dist/cli/hook.js +118 -7
  16. package/dist/cli/index.d.ts +3 -1
  17. package/dist/cli/index.js +3 -1
  18. package/dist/cli/misc.d.ts +11 -0
  19. package/dist/cli/misc.js +80 -4
  20. package/dist/cli/npx-install.d.ts +37 -0
  21. package/dist/cli/npx-install.js +79 -0
  22. package/dist/cli/open-browser.d.ts +39 -0
  23. package/dist/cli/open-browser.js +62 -0
  24. package/dist/cli/setup.d.ts +17 -8
  25. package/dist/cli/setup.js +439 -98
  26. package/dist/cli/status.js +82 -13
  27. package/dist/cli/toggle.d.ts +9 -0
  28. package/dist/cli/toggle.js +113 -0
  29. package/dist/cli/types/cli.types.d.ts +37 -3
  30. package/dist/cli/ui.d.ts +7 -0
  31. package/dist/cli/ui.js +10 -1
  32. package/dist/cli/uninstall.js +39 -2
  33. package/dist/cli/update.d.ts +17 -0
  34. package/dist/cli/update.js +76 -0
  35. package/dist/cli.js +100 -13
  36. package/dist/config/config-store.d.ts +57 -0
  37. package/dist/config/config-store.js +250 -12
  38. package/dist/config/config.d.ts +53 -6
  39. package/dist/config/config.js +66 -6
  40. package/dist/config/constants/config.constants.d.ts +113 -6
  41. package/dist/config/constants/config.constants.js +126 -8
  42. package/dist/config/destination.d.ts +24 -0
  43. package/dist/config/destination.js +33 -0
  44. package/dist/config/index.d.ts +7 -4
  45. package/dist/config/index.js +5 -3
  46. package/dist/config/repo-config.d.ts +11 -7
  47. package/dist/config/repo-config.js +64 -15
  48. package/dist/config/root-config.d.ts +72 -0
  49. package/dist/config/root-config.js +170 -0
  50. package/dist/config/schemas/config.schema.d.ts +721 -84
  51. package/dist/config/schemas/config.schema.js +388 -15
  52. package/dist/config/types/config.types.d.ts +15 -1
  53. package/dist/config/types/destination.types.d.ts +8 -0
  54. package/dist/core/async.d.ts +36 -0
  55. package/dist/core/async.js +68 -0
  56. package/dist/core/index.d.ts +1 -1
  57. package/dist/core/index.js +1 -1
  58. package/dist/core/object.d.ts +5 -0
  59. package/dist/core/object.js +9 -4
  60. package/dist/core/pipe.d.ts +0 -13
  61. package/dist/core/pipe.js +1 -9
  62. package/dist/core/types/core.types.d.ts +9 -0
  63. package/dist/core/types/core.types.js +0 -3
  64. package/dist/core/which.d.ts +14 -0
  65. package/dist/core/which.js +43 -3
  66. package/dist/credentials/budget.d.ts +9 -0
  67. package/dist/credentials/budget.js +16 -0
  68. package/dist/credentials/command-runner.d.ts +16 -0
  69. package/dist/credentials/command-runner.js +37 -0
  70. package/dist/credentials/constants/credentials.constants.d.ts +111 -0
  71. package/dist/credentials/constants/credentials.constants.js +112 -0
  72. package/dist/credentials/credential-status.d.ts +14 -0
  73. package/dist/credentials/credential-status.js +34 -0
  74. package/dist/credentials/credentials.d.ts +72 -0
  75. package/dist/credentials/credentials.js +253 -0
  76. package/dist/credentials/device-api.d.ts +64 -0
  77. package/dist/credentials/device-api.js +150 -0
  78. package/dist/credentials/device-state.d.ts +31 -0
  79. package/dist/credentials/device-state.js +51 -0
  80. package/dist/credentials/identity.d.ts +62 -0
  81. package/dist/credentials/identity.js +90 -0
  82. package/dist/credentials/index.d.ts +7 -0
  83. package/dist/credentials/index.js +5 -0
  84. package/dist/credentials/migration.d.ts +46 -0
  85. package/dist/credentials/migration.js +164 -0
  86. package/dist/credentials/schemas/device-api.schema.d.ts +77 -0
  87. package/dist/credentials/schemas/device-api.schema.js +33 -0
  88. package/dist/credentials/schemas/device-state.schema.d.ts +51 -0
  89. package/dist/credentials/schemas/device-state.schema.js +20 -0
  90. package/dist/credentials/secret-store.d.ts +54 -0
  91. package/dist/credentials/secret-store.js +217 -0
  92. package/dist/credentials/sign-in.d.ts +18 -0
  93. package/dist/credentials/sign-in.js +86 -0
  94. package/dist/credentials/token-refresher.d.ts +39 -0
  95. package/dist/credentials/token-refresher.js +185 -0
  96. package/dist/credentials/types/credentials.types.d.ts +195 -0
  97. package/dist/credentials/types/credentials.types.js +1 -0
  98. package/dist/enforcement/constants/enforcement.constants.d.ts +47 -1
  99. package/dist/enforcement/constants/enforcement.constants.js +56 -0
  100. package/dist/enforcement/decision-cache.d.ts +20 -1
  101. package/dist/enforcement/decision-cache.js +65 -2
  102. package/dist/enforcement/decision-client.d.ts +9 -8
  103. package/dist/enforcement/decision-client.js +62 -16
  104. package/dist/enforcement/enforcement.d.ts +23 -2
  105. package/dist/enforcement/enforcement.js +103 -15
  106. package/dist/enforcement/index.d.ts +4 -3
  107. package/dist/enforcement/index.js +3 -2
  108. package/dist/enforcement/types/enforcement.types.d.ts +64 -0
  109. package/dist/enrollment/constants/enrollment.constants.d.ts +2 -6
  110. package/dist/enrollment/constants/enrollment.constants.js +2 -6
  111. package/dist/enrollment/enrollment.d.ts +16 -0
  112. package/dist/enrollment/enrollment.js +54 -0
  113. package/dist/enrollment/index.d.ts +3 -7
  114. package/dist/enrollment/index.js +1 -1
  115. package/dist/enrollment/types/enrollment.types.d.ts +9 -13
  116. package/dist/events/constants/enrich.constants.d.ts +15 -0
  117. package/dist/events/constants/enrich.constants.js +15 -0
  118. package/dist/events/constants/events.constants.d.ts +6 -2
  119. package/dist/events/constants/events.constants.js +5 -1
  120. package/dist/events/enrich.js +92 -10
  121. package/dist/events/event-id.d.ts +0 -8
  122. package/dist/events/event-id.js +0 -10
  123. package/dist/events/index.d.ts +2 -2
  124. package/dist/events/index.js +1 -1
  125. package/dist/events/product-event.d.ts +9 -6
  126. package/dist/events/types/repo-snapshot.types.d.ts +7 -0
  127. package/dist/events/types/session-billing.types.d.ts +16 -0
  128. package/dist/events/types/session-billing.types.js +1 -0
  129. package/dist/feature/constants/feature.constants.d.ts +7 -0
  130. package/dist/feature/constants/feature.constants.js +7 -0
  131. package/dist/feature/index.d.ts +1 -1
  132. package/dist/feature/index.js +1 -1
  133. package/dist/feature/ticket-candidates.d.ts +14 -0
  134. package/dist/feature/ticket-candidates.js +26 -8
  135. package/dist/git/blob-hash.d.ts +21 -0
  136. package/dist/git/blob-hash.js +69 -0
  137. package/dist/git/checkout-root.d.ts +27 -0
  138. package/dist/git/checkout-root.js +75 -0
  139. package/dist/git/constants/git.constants.d.ts +160 -0
  140. package/dist/git/constants/git.constants.js +181 -0
  141. package/dist/git/fingerprint.d.ts +74 -0
  142. package/dist/git/fingerprint.js +219 -0
  143. package/dist/git/gate-checkout.d.ts +44 -0
  144. package/dist/git/gate-checkout.js +201 -0
  145. package/dist/git/git-context.d.ts +45 -0
  146. package/dist/git/git-context.js +61 -3
  147. package/dist/git/index.d.ts +4 -2
  148. package/dist/git/index.js +2 -1
  149. package/dist/git/manifest-repository.d.ts +13 -0
  150. package/dist/git/manifest-repository.js +92 -0
  151. package/dist/git/repo-snapshot.d.ts +29 -3
  152. package/dist/git/repo-snapshot.js +110 -7
  153. package/dist/git/repository-root.d.ts +39 -0
  154. package/dist/git/repository-root.js +131 -0
  155. package/dist/git/types/git.types.d.ts +55 -0
  156. package/dist/git/types/repository-root.types.d.ts +11 -0
  157. package/dist/git/types/repository-root.types.js +1 -0
  158. package/dist/git/types/snapshot.types.d.ts +9 -0
  159. package/dist/pipeline/constants/pipeline.constants.d.ts +7 -0
  160. package/dist/pipeline/constants/pipeline.constants.js +7 -0
  161. package/dist/pipeline/hook-pipeline.js +360 -32
  162. package/dist/pipeline/types/pipeline.types.d.ts +39 -4
  163. package/dist/privacy/constants/privacy.constants.js +15 -1
  164. package/dist/privacy/index.d.ts +1 -0
  165. package/dist/privacy/index.js +1 -0
  166. package/dist/privacy/product-capture.d.ts +12 -0
  167. package/dist/privacy/product-capture.js +73 -0
  168. package/dist/privacy/sanitizer.d.ts +21 -3
  169. package/dist/privacy/sanitizer.js +52 -8
  170. package/dist/process/ancestors.d.ts +39 -0
  171. package/dist/process/ancestors.js +121 -0
  172. package/dist/process/constants/process.constants.d.ts +34 -0
  173. package/dist/process/constants/process.constants.js +34 -0
  174. package/dist/process/index.d.ts +7 -0
  175. package/dist/process/index.js +2 -0
  176. package/dist/process/types/process.types.d.ts +23 -0
  177. package/dist/process/types/process.types.js +1 -0
  178. package/dist/providers/antigravity/antigravity.adapter.d.ts +12 -1
  179. package/dist/providers/antigravity/antigravity.adapter.js +21 -3
  180. package/dist/providers/antigravity/antigravity.detect.d.ts +0 -9
  181. package/dist/providers/antigravity/antigravity.detect.js +1 -1
  182. package/dist/providers/antigravity/antigravity.provider.js +3 -2
  183. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +2 -0
  184. package/dist/providers/antigravity/constants/antigravity.constants.js +2 -0
  185. package/dist/providers/claude/claude.adapter.d.ts +11 -1
  186. package/dist/providers/claude/claude.adapter.js +26 -5
  187. package/dist/providers/claude/claude.otel.d.ts +32 -18
  188. package/dist/providers/claude/claude.otel.js +81 -6
  189. package/dist/providers/claude/claude.provider.js +5 -2
  190. package/dist/providers/claude/constants/claude.constants.d.ts +2 -0
  191. package/dist/providers/claude/constants/claude.constants.js +2 -0
  192. package/dist/providers/claude/constants/claude.otel.constants.d.ts +4 -0
  193. package/dist/providers/claude/constants/claude.otel.constants.js +8 -0
  194. package/dist/providers/codex/codex.adapter.d.ts +15 -1
  195. package/dist/providers/codex/codex.adapter.js +29 -5
  196. package/dist/providers/codex/codex.otel.d.ts +24 -2
  197. package/dist/providers/codex/codex.otel.js +147 -30
  198. package/dist/providers/codex/codex.provider.js +5 -2
  199. package/dist/providers/codex/constants/codex.constants.d.ts +2 -0
  200. package/dist/providers/codex/constants/codex.constants.js +16 -0
  201. package/dist/providers/codex/constants/codex.otel.constants.d.ts +5 -0
  202. package/dist/providers/codex/constants/codex.otel.constants.js +5 -0
  203. package/dist/providers/constants/provider.constants.d.ts +0 -3
  204. package/dist/providers/constants/provider.constants.js +0 -3
  205. package/dist/providers/cursor/constants/cursor.constants.d.ts +7 -0
  206. package/dist/providers/cursor/constants/cursor.constants.js +7 -0
  207. package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
  208. package/dist/providers/cursor/cursor.adapter.js +52 -3
  209. package/dist/providers/cursor/cursor.detect.d.ts +0 -7
  210. package/dist/providers/cursor/cursor.detect.js +1 -1
  211. package/dist/providers/cursor/cursor.provider.js +5 -2
  212. package/dist/providers/gemini/constants/gemini.constants.d.ts +9 -0
  213. package/dist/providers/gemini/constants/gemini.constants.js +9 -0
  214. package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +3 -1
  215. package/dist/providers/gemini/constants/gemini.otel.constants.js +3 -0
  216. package/dist/providers/gemini/gemini.adapter.d.ts +14 -1
  217. package/dist/providers/gemini/gemini.adapter.js +25 -5
  218. package/dist/providers/gemini/gemini.detect.d.ts +0 -7
  219. package/dist/providers/gemini/gemini.detect.js +1 -1
  220. package/dist/providers/gemini/gemini.otel.d.ts +19 -20
  221. package/dist/providers/gemini/gemini.otel.js +121 -17
  222. package/dist/providers/gemini/gemini.provider.js +2 -1
  223. package/dist/providers/index.d.ts +1 -1
  224. package/dist/providers/index.js +1 -1
  225. package/dist/providers/loaders.d.ts +10 -0
  226. package/dist/providers/loaders.js +40 -0
  227. package/dist/providers/provider.d.ts +11 -0
  228. package/dist/providers/provider.js +1 -1
  229. package/dist/providers/registry.d.ts +11 -8
  230. package/dist/providers/registry.js +11 -15
  231. package/dist/providers/shared/constants/hook-refusal.constants.d.ts +7 -0
  232. package/dist/providers/shared/constants/hook-refusal.constants.js +7 -0
  233. package/dist/providers/shared/constants/shell-directories.constants.d.ts +30 -0
  234. package/dist/providers/shared/constants/shell-directories.constants.js +39 -0
  235. package/dist/providers/shared/constants/tooling.constants.d.ts +18 -2
  236. package/dist/providers/shared/constants/tooling.constants.js +19 -3
  237. package/dist/providers/shared/event-builder.d.ts +12 -14
  238. package/dist/providers/shared/event-builder.js +20 -14
  239. package/dist/providers/shared/exporter-allowlist.d.ts +20 -0
  240. package/dist/providers/shared/exporter-allowlist.js +49 -0
  241. package/dist/providers/shared/hook-config.d.ts +2 -21
  242. package/dist/providers/shared/hook-config.js +5 -4
  243. package/dist/providers/shared/hook-refusal.d.ts +12 -0
  244. package/dist/providers/shared/hook-refusal.js +17 -1
  245. package/dist/providers/shared/install-record.d.ts +12 -2
  246. package/dist/providers/shared/install-record.js +5 -2
  247. package/dist/providers/shared/shell-directories.d.ts +24 -0
  248. package/dist/providers/shared/shell-directories.js +90 -0
  249. package/dist/providers/shared/tooling.d.ts +12 -1
  250. package/dist/providers/shared/tooling.js +18 -0
  251. package/dist/providers/shared/types/adapter.types.d.ts +1 -2
  252. package/dist/providers/types/provider.types.d.ts +57 -1
  253. package/dist/snapshot/constants/snapshot.constants.d.ts +32 -0
  254. package/dist/snapshot/constants/snapshot.constants.js +33 -0
  255. package/dist/snapshot/snapshot-event.js +52 -11
  256. package/dist/snapshot/snapshot-pipeline.js +1 -1
  257. package/dist/snapshot/types/snapshot.types.d.ts +2 -0
  258. package/dist/storage/atomic-file.d.ts +7 -0
  259. package/dist/storage/atomic-file.js +1 -1
  260. package/dist/storage/constants/storage.constants.d.ts +17 -0
  261. package/dist/storage/constants/storage.constants.js +17 -0
  262. package/dist/storage/disabled.d.ts +13 -0
  263. package/dist/storage/disabled.js +24 -0
  264. package/dist/storage/index.d.ts +2 -0
  265. package/dist/storage/index.js +2 -0
  266. package/dist/storage/paths.js +3 -2
  267. package/dist/storage/schemas/storage.schema.d.ts +72 -0
  268. package/dist/storage/schemas/storage.schema.js +6 -0
  269. package/dist/storage/sweep-marker.d.ts +19 -0
  270. package/dist/storage/sweep-marker.js +55 -0
  271. package/dist/storage/types/storage.types.d.ts +2 -0
  272. package/dist/storage/uninstalled.d.ts +58 -0
  273. package/dist/storage/uninstalled.js +107 -0
  274. package/dist/transport/auth-block.d.ts +66 -0
  275. package/dist/transport/auth-block.js +129 -0
  276. package/dist/transport/constants/transport.constants.d.ts +82 -3
  277. package/dist/transport/constants/transport.constants.js +83 -4
  278. package/dist/transport/cooldown.js +8 -1
  279. package/dist/transport/delivery.d.ts +14 -6
  280. package/dist/transport/delivery.js +80 -55
  281. package/dist/transport/http-transport.d.ts +1 -0
  282. package/dist/transport/http-transport.js +52 -10
  283. package/dist/transport/index.d.ts +6 -3
  284. package/dist/transport/index.js +3 -0
  285. package/dist/transport/queue-partition.d.ts +91 -0
  286. package/dist/transport/queue-partition.js +143 -0
  287. package/dist/transport/queue.d.ts +99 -20
  288. package/dist/transport/queue.js +210 -69
  289. package/dist/transport/response-body.d.ts +25 -0
  290. package/dist/transport/response-body.js +64 -0
  291. package/dist/transport/send.d.ts +11 -0
  292. package/dist/transport/send.js +17 -0
  293. package/dist/transport/types/delivery-flow.types.d.ts +19 -0
  294. package/dist/transport/types/delivery-flow.types.js +1 -0
  295. package/dist/transport/types/transport.types.d.ts +45 -0
  296. package/dist/turns/claude-transcript.d.ts +19 -1
  297. package/dist/turns/claude-transcript.js +46 -1
  298. package/dist/turns/codex-originator.d.ts +11 -0
  299. package/dist/turns/codex-originator.js +31 -0
  300. package/dist/turns/codex-transcript.d.ts +30 -0
  301. package/dist/turns/codex-transcript.js +88 -0
  302. package/dist/turns/constants/turns.constants.d.ts +141 -5
  303. package/dist/turns/constants/turns.constants.js +155 -5
  304. package/dist/turns/file-identity.d.ts +27 -0
  305. package/dist/turns/file-identity.js +48 -0
  306. package/dist/turns/gemini-transcript.d.ts +30 -0
  307. package/dist/turns/gemini-transcript.js +96 -0
  308. package/dist/turns/index.d.ts +3 -3
  309. package/dist/turns/index.js +1 -1
  310. package/dist/turns/inherited-checkout.d.ts +54 -0
  311. package/dist/turns/inherited-checkout.js +155 -0
  312. package/dist/turns/native-session-titles.d.ts +26 -0
  313. package/dist/turns/native-session-titles.js +102 -0
  314. package/dist/turns/transcript.d.ts +3 -2
  315. package/dist/turns/transcript.js +5 -1
  316. package/dist/turns/turn-state.d.ts +224 -3
  317. package/dist/turns/turn-state.js +456 -21
  318. package/dist/turns/turn-summary.d.ts +1 -14
  319. package/dist/turns/turn-summary.js +87 -51
  320. package/dist/turns/turn-tracker.d.ts +21 -2
  321. package/dist/turns/turn-tracker.js +379 -56
  322. package/dist/turns/types/transcript.types.d.ts +5 -0
  323. package/dist/turns/types/turn-state.types.d.ts +116 -5
  324. package/dist/turns/types/turn-summary.types.d.ts +64 -14
  325. package/dist/turns/types/turn-tracker.types.d.ts +27 -1
  326. package/dist/turns/work-checkout.d.ts +65 -0
  327. package/dist/turns/work-checkout.js +666 -0
  328. package/dist/untraced/constants/untraced.constants.d.ts +31 -0
  329. package/dist/untraced/constants/untraced.constants.js +63 -0
  330. package/dist/untraced/untraced.d.ts +35 -0
  331. package/dist/untraced/untraced.js +105 -0
  332. package/dist/update/constants/update.constants.d.ts +18 -0
  333. package/dist/update/constants/update.constants.js +20 -0
  334. package/dist/update/update-check.d.ts +52 -0
  335. package/dist/update/update-check.js +113 -0
  336. package/docs/AUDIT_PROMPT.md +129 -0
  337. package/docs/DATA_HANDLING.md +648 -0
  338. package/docs/ENTERPRISE_DEPLOYMENT.md +179 -0
  339. package/docs/PERFORMANCE.md +81 -0
  340. package/package.json +14 -4
  341. package/dist/enrollment/enrollment-provider.d.ts +0 -5
  342. package/dist/enrollment/manual-enrollment.d.ts +0 -32
  343. package/dist/enrollment/manual-enrollment.js +0 -72
  344. package/example/README.md +0 -43
  345. package/example/server.mjs +0 -240
  346. /package/dist/{enrollment/enrollment-provider.js → config/types/destination.types.js} +0 -0
@@ -1,13 +1,14 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import { parse as parseToml } from 'smol-toml';
3
3
  import { asRecord } from '../../core/object.js';
4
- import { joinUrl, otlpBaseUrl } from '../../config/config.js';
5
- import { backupFile, writeFileAtomic } from '../../storage/atomic-file.js';
4
+ import { joinUrl, otlpBaseUrl, toolContentConsented } from '../../config/config.js';
5
+ import { backupFile, currentMode, writeFileAtomic } from '../../storage/atomic-file.js';
6
6
  import { SECRET_FILE_MODE } from '../../storage/constants/storage.constants.js';
7
7
  import { withOtelInstall, withoutOtelInstall } from '../shared/install-record.js';
8
+ import { INSTALLATION_HEADER } from '../../transport/constants/transport.constants.js';
8
9
  import { codexConfigTomlPath } from './codex.detect.js';
9
10
  import { CODEX_PROVIDER_ID } from './constants/codex.constants.js';
10
- import { BLOCK_END, BLOCK_START, CODEX_OTEL_SIGNALS, LOGS_PATH, OTEL_TABLE_KEY, RE_LEADING_NEWLINE, RE_TOML_BACKSLASH, RE_TOML_QUOTE, RE_TRAILING_NEWLINES, TRACES_PATH } from './constants/codex.otel.constants.js';
11
+ import { BLOCK_END, BLOCK_START, CODEX_EXPORTER_KEYS, CODEX_OTEL_SIGNALS, LOGS_PATH, OTEL_TABLE_KEY, OTLP_HTTP_KEY, RE_LEADING_NEWLINE, RE_TOML_BACKSLASH, RE_TOML_QUOTE, RE_TOML_TABLE_HEADER, RE_TRAILING_NEWLINES, TRACES_PATH } from './constants/codex.otel.constants.js';
11
12
  /**
12
13
  * Configures Codex's own OTLP export.
13
14
  *
@@ -40,8 +41,10 @@ export class CodexOtelConfigurator {
40
41
  return { supported: true, configured: false, detail: 'no config.toml' };
41
42
  }
42
43
  const hasBlock = raw.includes(BLOCK_START);
43
- if (disabled)
44
- return inspectDisabled(hasBlock);
44
+ if (disabled) {
45
+ const detail = context.config.otel.logs || context.config.otel.traces ? 'disabled by content consent' : 'disabled in config (otel)';
46
+ return inspectDisabled(hasBlock, detail);
47
+ }
45
48
  if (hasBlock)
46
49
  return inspectManagedBlock(raw, context.config);
47
50
  const parsed = tryParseToml(raw);
@@ -67,7 +70,7 @@ export class CodexOtelConfigurator {
67
70
  return { ok: false, changed: false, messages: ['no backend endpoint configured'] };
68
71
  const configPath = codexConfigTomlPath(context.env);
69
72
  const raw = (await readFileOrUndefined(configPath)) ?? '';
70
- const block = renderBlock(otlpBase, context.config.token, context.config.otel);
73
+ const block = renderBlock(otlpBase, context.config.token, context.config.otel, context.config.installationId);
71
74
  const next = raw.includes(BLOCK_START) ? replaceBlock(raw, block) : appendBlock(raw, block);
72
75
  if (typeof next !== 'string')
73
76
  return { ok: false, changed: false, messages: [next.error(configPath)] };
@@ -79,7 +82,10 @@ export class CodexOtelConfigurator {
79
82
  return { ok: false, changed: false, messages: ['internal error: generated config.toml would not parse; nothing written'] };
80
83
  }
81
84
  await backupFile(configPath, context.paths.backupsDir, context.env.now());
82
- // The managed block may carry the bearer token, so the file becomes private.
85
+ // The managed block may carry the bearer token, so the file becomes private
86
+ // — but this file is Codex's, not ours, so the mode it had first is
87
+ // recorded and uninstall puts it back.
88
+ const priorMode = context.config.token ? await currentMode(configPath) : undefined;
83
89
  await writeFileAtomic(configPath, next, context.config.token ? SECRET_FILE_MODE : undefined);
84
90
  return {
85
91
  ok: true,
@@ -88,15 +94,18 @@ export class CodexOtelConfigurator {
88
94
  installState: withOtelInstall(context.installState, CODEX_PROVIDER_ID, {
89
95
  configPath,
90
96
  ownedKeys: [OTEL_TABLE_KEY],
91
- configuredAt: context.env.now()
97
+ configuredAt: context.env.now(),
98
+ ...(priorMode !== undefined && priorMode !== SECRET_FILE_MODE ? { priorMode } : {})
92
99
  })
93
100
  };
94
101
  }
95
102
  /**
96
103
  * Remove the managed block from Codex's config.toml.
97
104
  *
98
- * Only the marker-delimited region goes; everything the developer wrote
99
- * around it — comments included — is preserved byte for byte.
105
+ * Only our own `[otel]` table goes. Everything the developer wrote around the
106
+ * markers — comments included — is preserved byte for byte, and so is
107
+ * anything the agent wrote *inside* them: Codex parks its `[hooks.state]`
108
+ * trust hashes there when it re-serializes the file.
100
109
  *
101
110
  * @param context - Environment, paths and install state.
102
111
  * @returns Whether the file changed, what to tell the user, and the next
@@ -111,8 +120,17 @@ export class CodexOtelConfigurator {
111
120
  const next = replaceBlock(raw, undefined);
112
121
  if (typeof next !== 'string')
113
122
  return { ok: false, changed: false, messages: [next.error(configPath)] };
123
+ // Removal now lifts the agent's own tables back out of the span, so it can
124
+ // reorder the file. A config that parsed before must still parse after; one
125
+ // that never parsed is not ours to refuse over.
126
+ if (tryParseToml(raw) !== undefined && tryParseToml(next) === undefined) {
127
+ return { ok: false, changed: false, messages: [`removing the AgentWatch block from ${configPath} would leave it unparseable; nothing written`] };
128
+ }
114
129
  await backupFile(configPath, context.paths.backupsDir, context.env.now());
115
- await writeFileAtomic(configPath, next);
130
+ // Restore the mode the file carried before AgentWatch tightened it:
131
+ // `writeFileAtomic` with no mode preserves the target's current one, which
132
+ // is our 0600 on a file that no longer holds a token.
133
+ await writeFileAtomic(configPath, next, context.installState.agents[CODEX_PROVIDER_ID]?.otelPriorMode);
116
134
  return {
117
135
  ok: true,
118
136
  changed: true,
@@ -120,6 +138,40 @@ export class CodexOtelConfigurator {
120
138
  installState: withoutOtelInstall(context.installState, CODEX_PROVIDER_ID)
121
139
  };
122
140
  }
141
+ /**
142
+ * Where the managed block's exporters send. The block is AgentWatch's whole,
143
+ * so every endpoint in it is.
144
+ *
145
+ * @param context - Environment.
146
+ * @returns The endpoints; none when there is no block or it does not parse.
147
+ */
148
+ async exporterEndpoints(context) {
149
+ const raw = await readFileOrUndefined(codexConfigTomlPath(context.env));
150
+ const block = raw?.includes(BLOCK_START) ? extractBlock(raw) : undefined;
151
+ const otel = asRecord((block === undefined ? undefined : tryParseToml(block))?.[OTEL_TABLE_KEY]);
152
+ const endpoints = [];
153
+ for (const key of CODEX_EXPORTER_KEYS) {
154
+ const endpoint = asRecord(asRecord(otel?.[key])?.[OTLP_HTTP_KEY])?.['endpoint'];
155
+ if (typeof endpoint === 'string')
156
+ endpoints.push(endpoint);
157
+ }
158
+ return endpoints;
159
+ }
160
+ /**
161
+ * Signals Codex was asked for but will not be given under current consent.
162
+ *
163
+ * Codex's usage logs and traces both carry tool arguments and results with no
164
+ * per-field filter, so the two of them stand or fall together on
165
+ * `toolContentConsented`.
166
+ *
167
+ * @param config - Effective configuration.
168
+ * @returns The requested signals that are held back; empty when none are.
169
+ */
170
+ withheldSignals(config) {
171
+ if (codexOtelEnabled(config))
172
+ return [];
173
+ return CODEX_OTEL_SIGNALS.filter((name) => config.otel[name]);
174
+ }
123
175
  /**
124
176
  * Handle `configure` when Codex telemetry is deliberately off.
125
177
  *
@@ -135,8 +187,8 @@ export class CodexOtelConfigurator {
135
187
  changed: removed.changed,
136
188
  messages: [
137
189
  removed.changed
138
- ? 'native OpenTelemetry disabled in config; previous configuration removed'
139
- : 'native OpenTelemetry disabled in config (otel: none)'
190
+ ? 'native OpenTelemetry disabled by config or content consent; previous configuration removed'
191
+ : 'native OpenTelemetry disabled by config or content consent'
140
192
  ],
141
193
  installState: removed.installState
142
194
  };
@@ -151,6 +203,8 @@ export class CodexOtelConfigurator {
151
203
  * @returns True when logs or traces are on.
152
204
  */
153
205
  function codexOtelEnabled(config) {
206
+ if (!toolContentConsented(config))
207
+ return false;
154
208
  return config.otel.logs || config.otel.traces;
155
209
  }
156
210
  /**
@@ -166,15 +220,16 @@ function codexSignalNames(signals) {
166
220
  * Status when Codex telemetry is deliberately off.
167
221
  *
168
222
  * @param hasBlock - Whether our managed block is still in the file.
223
+ * @param detail - Why native telemetry should be absent.
169
224
  * @returns Configured, unless our leftovers are still there.
170
225
  */
171
- function inspectDisabled(hasBlock) {
226
+ function inspectDisabled(hasBlock, detail) {
172
227
  if (!hasBlock)
173
- return { supported: true, configured: true, detail: 'disabled in config (otel)' };
228
+ return { supported: true, configured: true, detail };
174
229
  return {
175
230
  supported: true,
176
231
  configured: false,
177
- detail: 'disabled in config, but the AgentWatch [otel] block remains — run `agentwatch setup`'
232
+ detail: `${detail}, but the AgentWatch [otel] block remains — run \`agentwatch setup\``
178
233
  };
179
234
  }
180
235
  /**
@@ -189,7 +244,7 @@ function inspectManagedBlock(raw, config) {
189
244
  if (!otlpBase)
190
245
  return { supported: true, configured: false, detail: 'no backend endpoint configured' };
191
246
  const actual = extractBlock(raw);
192
- const expected = renderBlock(otlpBase, config.token, config.otel).trim();
247
+ const expected = renderBlock(otlpBase, config.token, config.otel, config.installationId).trim();
193
248
  if (actual === expected)
194
249
  return { supported: true, configured: true };
195
250
  return { supported: true, configured: false, detail: 'AgentWatch [otel] block is incomplete or stale — run `agentwatch setup`' };
@@ -205,11 +260,18 @@ function inspectManagedBlock(raw, config) {
205
260
  * @param signals - The signal selection.
206
261
  * @returns The block text, newline-terminated.
207
262
  */
208
- function renderBlock(otlpBase, token, signals) {
209
- const headers = token ? `, headers = { "Authorization" = "Bearer ${escapeTomlString(token)}" }` : '';
263
+ function renderBlock(otlpBase, token, signals, installationId) {
264
+ // Codex has no header helper, so this map is written once at install and is
265
+ // whatever the exporter sends until setup runs again. The installation id is
266
+ // fixed for the life of the config, so that suits it; a developer identity
267
+ // would not, which is why one is never put here.
268
+ const headers = token
269
+ ? `, headers = { ${tomlHeaders(token, installationId)} }`
270
+ : '';
210
271
  return [
211
272
  BLOCK_START,
212
273
  `[${OTEL_TABLE_KEY}]`,
274
+ 'log_user_prompt = false',
213
275
  signals.logs
214
276
  ? `exporter = { otlp-http = { endpoint = "${escapeTomlString(joinUrl(otlpBase, LOGS_PATH))}", protocol = "json"${headers} } }`
215
277
  : 'exporter = "none"',
@@ -222,22 +284,54 @@ function renderBlock(otlpBase, token, signals) {
222
284
  ''
223
285
  ].join('\n');
224
286
  }
287
+ /**
288
+ * The `key = "value"` pairs of a Codex exporter's header map.
289
+ *
290
+ * Bearer first, so a reader of the config sees the credential where the other
291
+ * agents put it. The installation id is omitted rather than written empty: an
292
+ * absent header and a header naming nothing are different claims, and only the
293
+ * first is true before an install has an id.
294
+ */
295
+ function tomlHeaders(token, installationId) {
296
+ const pairs = [`"Authorization" = "Bearer ${escapeTomlString(token)}"`];
297
+ if (installationId) {
298
+ pairs.push(`"${INSTALLATION_HEADER}" = "${escapeTomlString(installationId)}"`);
299
+ }
300
+ return pairs.join(', ');
301
+ }
225
302
  /**
226
303
  * Replace, or remove, the marker-delimited block.
227
304
  *
305
+ * Only our own `[otel]` table goes. Codex re-serializes config.toml as it runs
306
+ * and writes its own tables — the `[hooks.state]` trust hashes among them —
307
+ * after `[otel]` but before our end marker, which puts them inside the span.
308
+ * Deleting the span whole took those with it, so every `off`/`on` cost the
309
+ * developer another `codex` → `/hooks` → trust round.
310
+ *
228
311
  * @param raw - The whole config.toml.
229
312
  * @param block - The new block, or undefined to remove it.
230
313
  * @returns The next contents, or a failure when the markers are malformed.
231
314
  */
232
315
  function replaceBlock(raw, block) {
233
- const bounds = blockBounds(raw);
234
- if (!bounds)
316
+ const span = managedSpan(raw);
317
+ if (!span)
235
318
  return malformedMarkers;
236
- const head = raw.slice(0, bounds.start);
237
- const tail = raw.slice(bounds.end).replace(RE_LEADING_NEWLINE, '');
238
- if (block === undefined)
239
- return head.replace(RE_TRAILING_NEWLINES, '\n') + tail;
240
- return head + block + tail;
319
+ const head = raw.slice(0, span.start);
320
+ const tail = raw.slice(span.end).replace(RE_LEADING_NEWLINE, '');
321
+ const kept = block === undefined ? head.replace(RE_TRAILING_NEWLINES, '\n') : head + block;
322
+ return withForeign(kept, span.foreign) + tail;
323
+ }
324
+ /**
325
+ * Put back the TOML the agent wrote inside our markers.
326
+ *
327
+ * @param base - Everything up to and including our block, when it stays.
328
+ * @param foreign - The lifted tables, without surrounding blank lines.
329
+ * @returns The two, separated by a blank line.
330
+ */
331
+ function withForeign(base, foreign) {
332
+ if (foreign === '')
333
+ return base;
334
+ return base === '' ? `${foreign}\n` : `${base}\n${foreign}\n`;
241
335
  }
242
336
  /**
243
337
  * Append the managed block to a config that has none.
@@ -270,16 +364,39 @@ function blockBounds(raw) {
270
364
  return { start, end: endMarker + BLOCK_END.length };
271
365
  }
272
366
  /**
273
- * The managed block as it currently stands in the file.
367
+ * Split the marker span at the first table header that is not ours.
368
+ *
369
+ * Everything from our `[otel]` header to the next `[table]` is the block; the
370
+ * rest of the span belongs to whoever wrote it and has to survive.
274
371
  *
275
372
  * @param raw - The whole config.toml.
276
- * @returns The block text, or undefined when the markers are broken.
373
+ * @returns The split span, or undefined when the markers are broken.
277
374
  */
278
- function extractBlock(raw) {
375
+ function managedSpan(raw) {
279
376
  const bounds = blockBounds(raw);
280
377
  if (!bounds)
281
378
  return undefined;
282
- return raw.slice(bounds.start, bounds.end).trim();
379
+ const span = raw.slice(bounds.start, bounds.end);
380
+ const inner = span.slice(BLOCK_START.length, span.length - BLOCK_END.length);
381
+ const lines = inner.split('\n');
382
+ const ours = lines.findIndex((line) => line.trimStart().startsWith(`[${OTEL_TABLE_KEY}]`));
383
+ const next = lines.findIndex((line, index) => index > ours && RE_TOML_TABLE_HEADER.test(line));
384
+ if (ours === -1 || next === -1)
385
+ return { ...bounds, managed: span, foreign: '' };
386
+ return {
387
+ ...bounds,
388
+ managed: BLOCK_START + lines.slice(0, next).join('\n') + BLOCK_END,
389
+ foreign: lines.slice(next).join('\n').trim()
390
+ };
391
+ }
392
+ /**
393
+ * The managed block as it currently stands in the file, foreign tables excluded.
394
+ *
395
+ * @param raw - The whole config.toml.
396
+ * @returns The block text, or undefined when the markers are broken.
397
+ */
398
+ function extractBlock(raw) {
399
+ return managedSpan(raw)?.managed.trim();
283
400
  }
284
401
  /**
285
402
  * Escape a string for a TOML basic-string literal.
@@ -1,8 +1,8 @@
1
- import { hookRefusal } from '../shared/hook-refusal.js';
1
+ import { hookNotice, hookRefusal } from '../shared/hook-refusal.js';
2
2
  import { CODEX_PROMPT_SUBMIT_EVENTS } from './constants/codex.constants.js';
3
3
  import { detectCodex } from './codex.detect.js';
4
4
  import { installCodexHooks, uninstallCodexHooks } from './codex.hooks.js';
5
- import { parseCodexHookEvent } from './codex.adapter.js';
5
+ import { codexShellCall, parseCodexHookEvent } from './codex.adapter.js';
6
6
  import { CodexOtelConfigurator } from './codex.otel.js';
7
7
  export const codexProvider = {
8
8
  id: 'codex',
@@ -21,5 +21,8 @@ export const codexProvider = {
21
21
  * parser accepts.
22
22
  */
23
23
  getBlockResponse: (payload, message) => hookRefusal(payload, CODEX_PROMPT_SUBMIT_EVENTS, { continue: false, stopReason: message, systemMessage: message }),
24
+ /** A line for the developer after a shell run, as `systemMessage`; never plain stdout. */
25
+ getNoticeResponse: (payload, message) => hookNotice(payload, message),
26
+ shellCall: codexShellCall,
24
27
  nativeTelemetry: new CodexOtelConfigurator()
25
28
  };
@@ -28,6 +28,8 @@ export declare const CODEX_HOOKS_DISABLED_WARNING = "warning: [features] hooks =
28
28
  export declare const CODEX_EVENT_TYPE_MAP: Readonly<Record<string, CanonicalEventType>>;
29
29
  /** Hooks whose canonical type depends on which tool ran. */
30
30
  export declare const CODEX_TOOL_EVENTS: ReadonlySet<string>;
31
+ /** The hooks a shell call is read on: once before it runs, once after (same `tool_input`). */
32
+ export declare const CODEX_SHELL_CALL_EVENTS: ReadonlySet<string>;
31
33
  /**
32
34
  * The one hook a budget refusal may travel on.
33
35
  *
@@ -49,6 +49,8 @@ export const CODEX_EVENT_TYPE_MAP = {
49
49
  };
50
50
  /** Hooks whose canonical type depends on which tool ran. */
51
51
  export const CODEX_TOOL_EVENTS = new Set(['PreToolUse', 'PostToolUse', 'PermissionRequest']);
52
+ /** The hooks a shell call is read on: once before it runs, once after (same `tool_input`). */
53
+ export const CODEX_SHELL_CALL_EVENTS = new Set(['PreToolUse', 'PostToolUse']);
52
54
  /**
53
55
  * The one hook a budget refusal may travel on.
54
56
  *
@@ -59,4 +61,18 @@ export const CODEX_TOOL_EVENTS = new Set(['PreToolUse', 'PostToolUse', 'Permissi
59
61
  * because the developer and the transcript both need it.
60
62
  */
61
63
  export const CODEX_PROMPT_SUBMIT_EVENTS = new Set(['UserPromptSubmit']);
64
+ /*
65
+ * The untraced-run notice (AWT-310) travels on `PostToolUse` as
66
+ * `{"systemMessage": …}`. Verified against openai/codex
67
+ * `codex-rs/hooks/src/schema.rs`, 2026-10-07: `PostToolUseCommandOutputWire`
68
+ * flattens `HookUniversalOutputWire` (`continue`, `stopReason`,
69
+ * `suppressOutput`, `systemMessage`), so the key survives `deny_unknown_fields`.
70
+ *
71
+ * Shown only in the interactive TUI ("PostToolUse (completed) says: …", seen
72
+ * live on codex-cli 0.150.0, 2026-10-08). `codex exec` prints no hook's
73
+ * `systemMessage` on any event (`exec/src/event_processor_with_human_output.rs`
74
+ * logs only the event name and status; JSON mode drops hooks; still so in
75
+ * 0.160.1), so a pending notice replayed at `UserPromptSubmit` would be dropped
76
+ * the same way. Accepted: exec runs are headless, with nobody to read it.
77
+ */
62
78
  export const CODEX_UNKNOWN_EVENT = 'unknown';
@@ -11,6 +11,9 @@ export declare const BLOCK_START = "# >>> agentwatch managed block \u2014 do not
11
11
  export declare const BLOCK_END = "# <<< agentwatch managed block <<<";
12
12
  /** The one config key the managed block owns. */
13
13
  export declare const OTEL_TABLE_KEY = "otel";
14
+ /** The `[otel]` keys that hold an exporter, and the table naming its OTLP/HTTP target. */
15
+ export declare const CODEX_EXPORTER_KEYS: readonly string[];
16
+ export declare const OTLP_HTTP_KEY = "otlp-http";
14
17
  /** Signals Codex actually exports; `metrics` has no effect there. */
15
18
  export declare const CODEX_OTEL_SIGNALS: readonly ["logs", "traces"];
16
19
  /** OTLP/HTTP signal routes; Codex needs full endpoints, not a base. */
@@ -20,3 +23,5 @@ export declare const RE_LEADING_NEWLINE: RegExp;
20
23
  export declare const RE_TRAILING_NEWLINES: RegExp;
21
24
  export declare const RE_TOML_BACKSLASH: RegExp;
22
25
  export declare const RE_TOML_QUOTE: RegExp;
26
+ /** Start of any TOML table header, used to find where our block stops being ours. */
27
+ export declare const RE_TOML_TABLE_HEADER: RegExp;
@@ -11,6 +11,9 @@ export const BLOCK_START = '# >>> agentwatch managed block — do not edit; `age
11
11
  export const BLOCK_END = '# <<< agentwatch managed block <<<';
12
12
  /** The one config key the managed block owns. */
13
13
  export const OTEL_TABLE_KEY = 'otel';
14
+ /** The `[otel]` keys that hold an exporter, and the table naming its OTLP/HTTP target. */
15
+ export const CODEX_EXPORTER_KEYS = ['exporter', 'trace_exporter'];
16
+ export const OTLP_HTTP_KEY = 'otlp-http';
14
17
  /** Signals Codex actually exports; `metrics` has no effect there. */
15
18
  export const CODEX_OTEL_SIGNALS = ['logs', 'traces'];
16
19
  /** OTLP/HTTP signal routes; Codex needs full endpoints, not a base. */
@@ -20,3 +23,5 @@ export const RE_LEADING_NEWLINE = /^\n/;
20
23
  export const RE_TRAILING_NEWLINES = /\n+$/;
21
24
  export const RE_TOML_BACKSLASH = /\\/g;
22
25
  export const RE_TOML_QUOTE = /"/g;
26
+ /** Start of any TOML table header, used to find where our block stops being ours. */
27
+ export const RE_TOML_TABLE_HEADER = /^\s*\[/;
@@ -28,6 +28,3 @@ export declare const RE_SHELL_CONTROL: RegExp;
28
28
  /** Characters a double quote still escapes inside a quoted argument. */
29
29
  export declare const RE_DOUBLE_QUOTE_ESCAPABLE: RegExp;
30
30
  export declare const RE_WHITESPACE: RegExp;
31
- /** Argument shape that forces quoting when a hook command is generated. */
32
- export declare const RE_NEEDS_QUOTING: RegExp;
33
- export declare const RE_QUOTE_ESCAPE: RegExp;
@@ -28,6 +28,3 @@ export const RE_SHELL_CONTROL = /[|&;<>\r\n]/;
28
28
  /** Characters a double quote still escapes inside a quoted argument. */
29
29
  export const RE_DOUBLE_QUOTE_ESCAPABLE = /["\\$`]/;
30
30
  export const RE_WHITESPACE = /\s/;
31
- /** Argument shape that forces quoting when a hook command is generated. */
32
- export const RE_NEEDS_QUOTING = /[\s"'\\$`]/;
33
- export const RE_QUOTE_ESCAPE = /(["\\$`])/g;
@@ -44,6 +44,13 @@ export declare const CURSOR_TOOL_KINDS: Readonly<Record<string, ToolKind>>;
44
44
  export declare const CURSOR_READ_TOOL_NAME = "Read";
45
45
  export declare const CURSOR_EDIT_TOOL_NAME = "Edit";
46
46
  export declare const CURSOR_SHELL_TOOL_NAME = "Shell";
47
+ /** The dedicated shell hooks, with `command` (and, before the call, `cwd`) at the top level. */
48
+ export declare const CURSOR_SHELL_EVENTS: ReadonlySet<string>;
49
+ /** The generic hook that fires before any tool call, the shell's included. */
50
+ export declare const CURSOR_GENERIC_TOOL_START_EVENT = "preToolUse";
51
+ /** Where `preToolUse` for `Shell` puts the command and its directory in `tool_input`. */
52
+ export declare const CURSOR_SHELL_COMMAND_KEY = "command";
53
+ export declare const CURSOR_SHELL_WORKDIR_KEY = "working_directory";
47
54
  /** Attachment field carrying a file path. */
48
55
  export declare const ATTACHMENT_FILE_PATH_KEY = "file_path";
49
56
  /**
@@ -81,6 +81,13 @@ export const CURSOR_TOOL_KINDS = {
81
81
  export const CURSOR_READ_TOOL_NAME = 'Read';
82
82
  export const CURSOR_EDIT_TOOL_NAME = 'Edit';
83
83
  export const CURSOR_SHELL_TOOL_NAME = 'Shell';
84
+ /** The dedicated shell hooks, with `command` (and, before the call, `cwd`) at the top level. */
85
+ export const CURSOR_SHELL_EVENTS = new Set(['beforeShellExecution', 'afterShellExecution']);
86
+ /** The generic hook that fires before any tool call, the shell's included. */
87
+ export const CURSOR_GENERIC_TOOL_START_EVENT = 'preToolUse';
88
+ /** Where `preToolUse` for `Shell` puts the command and its directory in `tool_input`. */
89
+ export const CURSOR_SHELL_COMMAND_KEY = 'command';
90
+ export const CURSOR_SHELL_WORKDIR_KEY = 'working_directory';
84
91
  /** Attachment field carrying a file path. */
85
92
  export const ATTACHMENT_FILE_PATH_KEY = 'file_path';
86
93
  /**
@@ -1,5 +1,5 @@
1
1
  import type { AgentWatchEvent } from '../../events/types/events.types.js';
2
- import type { HookContext } from '../types/provider.types.js';
2
+ import type { HookContext, ShellCall } from '../types/provider.types.js';
3
3
  export type { CursorPayload } from './types/cursor.types.js';
4
4
  /**
5
5
  * Translate one Cursor hook payload into canonical events.
@@ -9,3 +9,35 @@ export type { CursorPayload } from './types/cursor.types.js';
9
9
  * @returns The canonical events, or an empty list for an unusable payload.
10
10
  */
11
11
  export declare function parseCursorHookEvent(rawPayload: unknown, context: HookContext): AgentWatchEvent[];
12
+ /**
13
+ * The command a shell call is about to run, and the directory it runs in.
14
+ *
15
+ * Cursor announces one call twice (cursor.com/docs/hooks): `beforeShellExecution`
16
+ * with `command` and `cwd` at the top level, and the generic `preToolUse` for
17
+ * `Shell` with `tool_input.command` and `tool_input.working_directory`. Both are
18
+ * read, so both name the same checkout; a hook left unread would instead vote
19
+ * for the cwd it sits in. `afterShellExecution` is read too: a command can
20
+ * create the worktree it works in.
21
+ *
22
+ * @param rawPayload - Raw JSON from the hook's stdin.
23
+ * @returns The call, or undefined for any other payload.
24
+ */
25
+ export declare function cursorShellCall(rawPayload: unknown): ShellCall | undefined;
26
+ /**
27
+ * The folders the Cursor window has open, absolute paths only.
28
+ *
29
+ * @param rawPayload - Raw JSON from the hook's stdin.
30
+ * @returns The roots; empty when the payload names none.
31
+ */
32
+ export declare function cursorWorkspaceRoots(rawPayload: unknown): string[];
33
+ /**
34
+ * Where a payload that reports no `cwd` happened: the first workspace root.
35
+ *
36
+ * Cursor puts `cwd` on its shell and tool hooks only; the prompt, file-edit and
37
+ * stop hooks would otherwise resolve against the directory the hook process
38
+ * started in, which Cursor does not promise is the workspace.
39
+ *
40
+ * @param rawPayload - Raw JSON from the hook's stdin.
41
+ * @returns The first workspace root, or undefined.
42
+ */
43
+ export declare function cursorCwd(rawPayload: unknown): string | undefined;
@@ -1,8 +1,9 @@
1
+ import path from 'node:path';
1
2
  import { asRecord, compact } from '../../core/object.js';
2
3
  import { sha256Hex } from '../../events/event-id.js';
3
4
  import { baseEvent, filePathPatch, promptPatch, responsePatch, toolPatch, withPatch } from '../shared/event-builder.js';
4
- import { classifyTool, contentEvidence, parseMcpToolName, toolCompleteType, toolStartType } from '../shared/tooling.js';
5
- import { ATTACHMENT_FILE_PATH_KEY, CURSOR_DEDICATED_COMPLETION_KINDS, CURSOR_DISPLAY_NAME, CURSOR_EDIT_TOOL_NAME, CURSOR_EVENT_TYPE_MAP, CURSOR_PROVIDER_ID, CURSOR_READ_TOOL_NAME, CURSOR_SHELL_TOOL_NAME, CURSOR_TOOL_KINDS, CURSOR_UNKNOWN_EVENT } from './constants/cursor.constants.js';
5
+ import { classifyTool, contentEvidence, parseMcpToolName, shellCallOf, toolCompleteType, toolStartType } from '../shared/tooling.js';
6
+ import { ATTACHMENT_FILE_PATH_KEY, CURSOR_DEDICATED_COMPLETION_KINDS, CURSOR_DISPLAY_NAME, CURSOR_EDIT_TOOL_NAME, CURSOR_EVENT_TYPE_MAP, CURSOR_PROVIDER_ID, CURSOR_READ_TOOL_NAME, CURSOR_GENERIC_TOOL_START_EVENT, CURSOR_SHELL_COMMAND_KEY, CURSOR_SHELL_EVENTS, CURSOR_SHELL_WORKDIR_KEY, CURSOR_SHELL_TOOL_NAME, CURSOR_TOOL_KINDS, CURSOR_UNKNOWN_EVENT } from './constants/cursor.constants.js';
6
7
  import { cursorPayloadSchema } from './schemas/cursor.schema.js';
7
8
  /**
8
9
  * Translate one Cursor hook payload into canonical events.
@@ -19,6 +20,54 @@ export function parseCursorHookEvent(rawPayload, context) {
19
20
  const providerEventType = payload.hook_event_name ?? CURSOR_UNKNOWN_EVENT;
20
21
  return [withPatch(cursorBaseEvent(payload, providerEventType), hookPatch(payload, providerEventType, context))];
21
22
  }
23
+ /**
24
+ * The command a shell call is about to run, and the directory it runs in.
25
+ *
26
+ * Cursor announces one call twice (cursor.com/docs/hooks): `beforeShellExecution`
27
+ * with `command` and `cwd` at the top level, and the generic `preToolUse` for
28
+ * `Shell` with `tool_input.command` and `tool_input.working_directory`. Both are
29
+ * read, so both name the same checkout; a hook left unread would instead vote
30
+ * for the cwd it sits in. `afterShellExecution` is read too: a command can
31
+ * create the worktree it works in.
32
+ *
33
+ * @param rawPayload - Raw JSON from the hook's stdin.
34
+ * @returns The call, or undefined for any other payload.
35
+ */
36
+ export function cursorShellCall(rawPayload) {
37
+ const parsed = cursorPayloadSchema.safeParse(rawPayload);
38
+ if (!parsed.success)
39
+ return undefined;
40
+ const payload = parsed.data;
41
+ if (CURSOR_SHELL_EVENTS.has(payload.hook_event_name ?? ''))
42
+ return shellCallOf(payload.command, payload.cwd);
43
+ if (payload.hook_event_name !== CURSOR_GENERIC_TOOL_START_EVENT || cursorToolKind(payload.tool_name) !== 'shell')
44
+ return undefined;
45
+ const input = asRecord(payload.tool_input);
46
+ return shellCallOf(input?.[CURSOR_SHELL_COMMAND_KEY], input?.[CURSOR_SHELL_WORKDIR_KEY]);
47
+ }
48
+ /**
49
+ * The folders the Cursor window has open, absolute paths only.
50
+ *
51
+ * @param rawPayload - Raw JSON from the hook's stdin.
52
+ * @returns The roots; empty when the payload names none.
53
+ */
54
+ export function cursorWorkspaceRoots(rawPayload) {
55
+ const parsed = cursorPayloadSchema.safeParse(rawPayload);
56
+ return parsed.success ? (parsed.data.workspace_roots ?? []).filter((root) => path.isAbsolute(root)) : [];
57
+ }
58
+ /**
59
+ * Where a payload that reports no `cwd` happened: the first workspace root.
60
+ *
61
+ * Cursor puts `cwd` on its shell and tool hooks only; the prompt, file-edit and
62
+ * stop hooks would otherwise resolve against the directory the hook process
63
+ * started in, which Cursor does not promise is the workspace.
64
+ *
65
+ * @param rawPayload - Raw JSON from the hook's stdin.
66
+ * @returns The first workspace root, or undefined.
67
+ */
68
+ export function cursorCwd(rawPayload) {
69
+ return cursorWorkspaceRoots(rawPayload)[0];
70
+ }
22
71
  /**
23
72
  * The provider-independent part of the event.
24
73
  *
@@ -96,7 +145,7 @@ function hookPatch(payload, providerEventType, context) {
96
145
  return { metadata: { compactionTrigger: payload.trigger, contextUsagePercent: payload.context_usage_percent } };
97
146
  }
98
147
  if (providerEventType === 'afterAgentResponse')
99
- return responsePatch(payload.text ?? '', capture);
148
+ return responsePatch(payload.text ?? '');
100
149
  if (providerEventType === 'stop')
101
150
  return { metadata: { stopStatus: payload.status } };
102
151
  return {};
@@ -1,12 +1,5 @@
1
1
  import type { Env } from '../../core/types/core.types.js';
2
2
  import type { DetectionResult } from '../types/provider.types.js';
3
- /**
4
- * Cursor's configuration root.
5
- *
6
- * @param env - Environment supplying HOME.
7
- * @returns Absolute path of `~/.cursor`.
8
- */
9
- export declare function cursorHome(env: Env): string;
10
3
  /**
11
4
  * Where Cursor reads user-level hook registrations from.
12
5
  *
@@ -10,7 +10,7 @@ import { CURSOR_EXECUTABLES, CURSOR_HOME_DIR, CURSOR_HOOKS_FILE } from './consta
10
10
  * @param env - Environment supplying HOME.
11
11
  * @returns Absolute path of `~/.cursor`.
12
12
  */
13
- export function cursorHome(env) {
13
+ function cursorHome(env) {
14
14
  return path.join(env.home, CURSOR_HOME_DIR);
15
15
  }
16
16
  /**
@@ -2,7 +2,7 @@ import { hookRefusal } from '../shared/hook-refusal.js';
2
2
  import { CURSOR_PROMPT_SUBMIT_EVENTS } from './constants/cursor.constants.js';
3
3
  import { detectCursor } from './cursor.detect.js';
4
4
  import { installCursorHooks, uninstallCursorHooks } from './cursor.hooks.js';
5
- import { parseCursorHookEvent } from './cursor.adapter.js';
5
+ import { cursorCwd, cursorShellCall, cursorWorkspaceRoots, parseCursorHookEvent } from './cursor.adapter.js';
6
6
  export const cursorProvider = {
7
7
  id: 'cursor',
8
8
  displayName: 'Cursor',
@@ -20,7 +20,10 @@ export const cursorProvider = {
20
20
  * A budget refusal on `beforeSubmitPrompt`: the prompt is not submitted and
21
21
  * `user_message` explains why.
22
22
  */
23
- getBlockResponse: (payload, message) => hookRefusal(payload, CURSOR_PROMPT_SUBMIT_EVENTS, { continue: false, user_message: message })
23
+ getBlockResponse: (payload, message) => hookRefusal(payload, CURSOR_PROMPT_SUBMIT_EVENTS, { continue: false, user_message: message }),
24
+ resolveCwd: cursorCwd,
25
+ shellCall: cursorShellCall,
26
+ workspaceRoots: cursorWorkspaceRoots
24
27
  // No nativeTelemetry: Cursor has no OTel export, so there is no llm.call
25
28
  // ledger source. Turn summaries stay usage_status=pending until Cursor
26
29
  // enriches its transcripts with usage (see cursor-transcript.ts).
@@ -33,4 +33,13 @@ export declare const GEMINI_TOOL_EVENTS: ReadonlySet<string>;
33
33
  export declare const GEMINI_TOOL_START_EVENTS: ReadonlySet<string>;
34
34
  /** Tool hooks that report a completion. */
35
35
  export declare const GEMINI_TOOL_COMPLETE_EVENTS: ReadonlySet<string>;
36
+ /**
37
+ * Tool hooks a shell call is read on: the ones that fire once before it runs,
38
+ * and once after it ran (a command can create the worktree it works in), across
39
+ * both namings. `PermissionRequest` also counts as a start, but only for calls
40
+ * that ask, and reading it too would count those calls twice.
41
+ */
42
+ export declare const GEMINI_SHELL_CALL_EVENTS: ReadonlySet<string>;
43
+ /** `run_shell_command`'s working-directory argument. */
44
+ export declare const GEMINI_SHELL_DIR_KEY = "dir_path";
36
45
  export declare const GEMINI_UNKNOWN_EVENT = "unknown";
@@ -55,4 +55,13 @@ export const GEMINI_TOOL_EVENTS = new Set([
55
55
  export const GEMINI_TOOL_START_EVENTS = new Set(['BeforeTool', 'PreToolUse', 'PermissionRequest']);
56
56
  /** Tool hooks that report a completion. */
57
57
  export const GEMINI_TOOL_COMPLETE_EVENTS = new Set(['AfterTool', 'PostToolUse', 'PostToolUseFailure']);
58
+ /**
59
+ * Tool hooks a shell call is read on: the ones that fire once before it runs,
60
+ * and once after it ran (a command can create the worktree it works in), across
61
+ * both namings. `PermissionRequest` also counts as a start, but only for calls
62
+ * that ask, and reading it too would count those calls twice.
63
+ */
64
+ export const GEMINI_SHELL_CALL_EVENTS = new Set(['BeforeTool', 'PreToolUse', 'AfterTool', 'PostToolUse']);
65
+ /** `run_shell_command`'s working-directory argument. */
66
+ export const GEMINI_SHELL_DIR_KEY = 'dir_path';
58
67
  export const GEMINI_UNKNOWN_EVENT = 'unknown';