@agent-watch-ai/edge 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. package/CHANGELOG.md +238 -7
  2. package/README.md +308 -8
  3. package/dist/billing/billing-mode.d.ts +37 -5
  4. package/dist/billing/billing-mode.js +28 -19
  5. package/dist/billing/constants/billing.constants.d.ts +0 -2
  6. package/dist/billing/constants/billing.constants.js +0 -2
  7. package/dist/billing/index.d.ts +2 -1
  8. package/dist/billing/index.js +1 -1
  9. package/dist/billing/session-billing.d.ts +3 -2
  10. package/dist/billing/session-billing.js +8 -8
  11. package/dist/billing/types/billing.types.d.ts +7 -0
  12. package/dist/capture/capture-env.d.ts +147 -0
  13. package/dist/capture/capture-env.js +301 -0
  14. package/dist/capture/captured-step.d.ts +88 -0
  15. package/dist/capture/captured-step.js +479 -0
  16. package/dist/capture/constants/capture.constants.d.ts +70 -0
  17. package/dist/capture/constants/capture.constants.js +72 -0
  18. package/dist/capture/launched-runs.d.ts +16 -0
  19. package/dist/capture/launched-runs.js +151 -0
  20. package/dist/capture/node.cjs +697 -0
  21. package/dist/capture/node.d.cts +32 -0
  22. package/dist/capture/python/sitecustomize.py +823 -0
  23. package/dist/capture/schemas/capture.schema.d.ts +35 -0
  24. package/dist/capture/schemas/capture.schema.js +31 -0
  25. package/dist/capture/types/capture.types.d.ts +20 -0
  26. package/dist/cli/constants/cli.constants.d.ts +2 -6
  27. package/dist/cli/constants/cli.constants.js +3 -7
  28. package/dist/cli/context.d.ts +19 -22
  29. package/dist/cli/context.js +23 -54
  30. package/dist/cli/doctor-run-capture.d.ts +13 -0
  31. package/dist/cli/doctor-run-capture.js +19 -0
  32. package/dist/cli/doctor.js +16 -67
  33. package/dist/cli/hook.d.ts +14 -0
  34. package/dist/cli/hook.js +40 -0
  35. package/dist/cli/index.d.ts +1 -1
  36. package/dist/cli/index.js +1 -1
  37. package/dist/cli/misc.js +10 -2
  38. package/dist/cli/replay.d.ts +33 -0
  39. package/dist/cli/replay.js +193 -0
  40. package/dist/cli/setup.d.ts +10 -2
  41. package/dist/cli/setup.js +154 -26
  42. package/dist/cli/status.js +45 -5
  43. package/dist/cli/toggle.js +10 -0
  44. package/dist/cli/types/cli.types.d.ts +15 -1
  45. package/dist/cli/uninstall.js +8 -22
  46. package/dist/cli.js +104 -17
  47. package/dist/config/config.d.ts +0 -2
  48. package/dist/config/config.js +0 -1
  49. package/dist/config/constants/config.constants.js +2 -0
  50. package/dist/config/events-transport.d.ts +15 -0
  51. package/dist/config/events-transport.js +29 -0
  52. package/dist/config/index.d.ts +2 -1
  53. package/dist/config/index.js +1 -0
  54. package/dist/config/root-config.d.ts +12 -0
  55. package/dist/config/root-config.js +24 -0
  56. package/dist/config/schemas/config.schema.d.ts +13 -0
  57. package/dist/config/schemas/config.schema.js +42 -6
  58. package/dist/config/types/config.types.d.ts +7 -0
  59. package/dist/core/index.d.ts +1 -1
  60. package/dist/core/index.js +1 -1
  61. package/dist/core/version.d.ts +9 -0
  62. package/dist/core/version.js +14 -0
  63. package/dist/core/which.d.ts +11 -0
  64. package/dist/core/which.js +18 -0
  65. package/dist/credentials/cloud-claim.d.ts +32 -0
  66. package/dist/credentials/cloud-claim.js +42 -0
  67. package/dist/credentials/constants/credentials.constants.d.ts +8 -1
  68. package/dist/credentials/constants/credentials.constants.js +9 -2
  69. package/dist/credentials/device-api.d.ts +15 -1
  70. package/dist/credentials/device-api.js +12 -1
  71. package/dist/credentials/sign-in.d.ts +27 -0
  72. package/dist/credentials/sign-in.js +31 -1
  73. package/dist/credentials/token-refresher.d.ts +5 -1
  74. package/dist/credentials/token-refresher.js +10 -2
  75. package/dist/events/constants/events.constants.d.ts +8 -2
  76. package/dist/events/constants/events.constants.js +7 -1
  77. package/dist/events/index.d.ts +2 -0
  78. package/dist/events/product-event.d.ts +10 -4
  79. package/dist/events/types/events.types.d.ts +6 -0
  80. package/dist/events/types/replay-progress.types.d.ts +26 -0
  81. package/dist/events/types/replay-progress.types.js +1 -0
  82. package/dist/events/types/repo-snapshot.types.d.ts +1 -4
  83. package/dist/events/types/repo-tree.types.d.ts +25 -0
  84. package/dist/events/types/repo-tree.types.js +1 -0
  85. package/dist/feature/ticket-candidates.d.ts +1 -1
  86. package/dist/git/checkout-root.d.ts +15 -0
  87. package/dist/git/checkout-root.js +18 -0
  88. package/dist/git/code-state.d.ts +2 -16
  89. package/dist/git/code-state.js +11 -12
  90. package/dist/git/constants/git.constants.d.ts +31 -11
  91. package/dist/git/constants/git.constants.js +36 -12
  92. package/dist/git/constants/tree.constants.d.ts +71 -0
  93. package/dist/git/constants/tree.constants.js +92 -0
  94. package/dist/git/fingerprint.d.ts +3 -6
  95. package/dist/git/fingerprint.js +5 -8
  96. package/dist/git/git-context.d.ts +1 -0
  97. package/dist/git/git-context.js +8 -3
  98. package/dist/git/index.d.ts +1 -2
  99. package/dist/git/index.js +1 -1
  100. package/dist/git/repo-snapshot.d.ts +13 -4
  101. package/dist/git/repo-snapshot.js +47 -9
  102. package/dist/git/repo-tree.d.ts +69 -0
  103. package/dist/git/repo-tree.js +130 -0
  104. package/dist/git/types/git.types.d.ts +5 -2
  105. package/dist/git/types/snapshot.types.d.ts +14 -0
  106. package/dist/pipeline/constants/pipeline.constants.d.ts +3 -0
  107. package/dist/pipeline/constants/pipeline.constants.js +3 -0
  108. package/dist/pipeline/hook-pipeline.js +112 -72
  109. package/dist/privacy/product-capture.js +36 -5
  110. package/dist/providers/antigravity/antigravity.capture.d.ts +2 -0
  111. package/dist/providers/antigravity/antigravity.capture.js +5 -0
  112. package/dist/providers/antigravity/antigravity.detect.js +8 -22
  113. package/dist/providers/antigravity/antigravity.provider.js +10 -3
  114. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +1 -0
  115. package/dist/providers/antigravity/constants/antigravity.constants.js +1 -0
  116. package/dist/providers/claude/claude.adapter.js +9 -6
  117. package/dist/providers/claude/claude.detect.js +2 -17
  118. package/dist/providers/claude/claude.otel.d.ts +21 -3
  119. package/dist/providers/claude/claude.otel.js +216 -61
  120. package/dist/providers/claude/claude.provider.js +17 -1
  121. package/dist/providers/claude/claude.version.d.ts +9 -0
  122. package/dist/providers/claude/claude.version.js +28 -0
  123. package/dist/providers/claude/constants/claude.constants.d.ts +27 -0
  124. package/dist/providers/claude/constants/claude.constants.js +27 -0
  125. package/dist/providers/claude/constants/claude.otel.constants.d.ts +27 -0
  126. package/dist/providers/claude/constants/claude.otel.constants.js +45 -5
  127. package/dist/providers/claude/types/claude.types.d.ts +13 -0
  128. package/dist/providers/codex/codex.capture.d.ts +76 -0
  129. package/dist/providers/codex/codex.capture.js +454 -0
  130. package/dist/providers/codex/codex.detect.js +2 -4
  131. package/dist/providers/codex/codex.otel.d.ts +38 -2
  132. package/dist/providers/codex/codex.otel.js +50 -6
  133. package/dist/providers/codex/codex.provider.js +8 -0
  134. package/dist/providers/codex/codex.surface.d.ts +9 -0
  135. package/dist/{turns/codex-originator.js → providers/codex/codex.surface.js} +17 -3
  136. package/dist/providers/codex/codex.titles.d.ts +14 -0
  137. package/dist/providers/codex/codex.titles.js +35 -0
  138. package/dist/providers/codex/constants/codex.constants.d.ts +4 -0
  139. package/dist/providers/codex/constants/codex.constants.js +4 -0
  140. package/dist/providers/cursor/constants/cursor.constants.d.ts +17 -4
  141. package/dist/providers/cursor/constants/cursor.constants.js +25 -5
  142. package/dist/providers/cursor/cursor-mcp-memo.d.ts +34 -0
  143. package/dist/providers/cursor/cursor-mcp-memo.js +94 -0
  144. package/dist/providers/cursor/cursor.adapter.js +20 -82
  145. package/dist/providers/cursor/cursor.capture.d.ts +1 -0
  146. package/dist/providers/cursor/cursor.capture.js +4 -0
  147. package/dist/providers/cursor/cursor.detect.d.ts +5 -1
  148. package/dist/providers/cursor/cursor.detect.js +11 -26
  149. package/dist/providers/cursor/cursor.hooks.js +2 -2
  150. package/dist/providers/cursor/cursor.provider.js +16 -7
  151. package/dist/providers/cursor/cursor.titles.d.ts +14 -0
  152. package/dist/providers/cursor/cursor.titles.js +20 -0
  153. package/dist/providers/cursor/schemas/cursor.schema.d.ts +3 -3
  154. package/dist/providers/cursor/schemas/cursor.schema.js +5 -3
  155. package/dist/providers/gemini/constants/gemini.constants.d.ts +16 -0
  156. package/dist/providers/gemini/constants/gemini.constants.js +17 -0
  157. package/dist/providers/gemini/gemini.capture.d.ts +81 -0
  158. package/dist/providers/gemini/gemini.capture.js +210 -0
  159. package/dist/providers/gemini/gemini.detect.js +57 -24
  160. package/dist/providers/gemini/gemini.otel.d.ts +38 -2
  161. package/dist/providers/gemini/gemini.otel.js +56 -125
  162. package/dist/providers/gemini/gemini.provider.js +5 -0
  163. package/dist/providers/index.d.ts +1 -0
  164. package/dist/providers/index.js +1 -0
  165. package/dist/providers/provider.d.ts +8 -0
  166. package/dist/providers/provider.js +9 -0
  167. package/dist/providers/registry.d.ts +14 -0
  168. package/dist/providers/registry.js +14 -0
  169. package/dist/providers/shared/constants/hook-config.constants.d.ts +2 -0
  170. package/dist/providers/shared/constants/hook-config.constants.js +2 -0
  171. package/dist/providers/shared/constants/terminal-capture.constants.d.ts +6 -0
  172. package/dist/providers/shared/constants/terminal-capture.constants.js +6 -0
  173. package/dist/providers/shared/editor-paths.d.ts +8 -0
  174. package/dist/providers/shared/editor-paths.js +18 -0
  175. package/dist/providers/shared/hook-config.d.ts +5 -0
  176. package/dist/providers/shared/hook-config.js +39 -1
  177. package/dist/providers/shared/hooks-marker.d.ts +14 -0
  178. package/dist/providers/shared/hooks-marker.js +23 -0
  179. package/dist/providers/shared/install-record.d.ts +29 -0
  180. package/dist/providers/shared/install-record.js +52 -0
  181. package/dist/providers/shared/session-title-store.d.ts +23 -0
  182. package/dist/providers/shared/session-title-store.js +50 -0
  183. package/dist/providers/shared/terminal-capture.d.ts +41 -0
  184. package/dist/providers/shared/terminal-capture.js +109 -0
  185. package/dist/providers/shared/tooling.d.ts +21 -0
  186. package/dist/providers/shared/tooling.js +36 -1
  187. package/dist/providers/types/provider.types.d.ts +57 -4
  188. package/dist/replay/checkout-resolver.d.ts +29 -0
  189. package/dist/replay/checkout-resolver.js +69 -0
  190. package/dist/replay/codex-turns.d.ts +24 -0
  191. package/dist/replay/codex-turns.js +221 -0
  192. package/dist/replay/constants/replay.constants.d.ts +99 -0
  193. package/dist/replay/constants/replay.constants.js +102 -0
  194. package/dist/replay/describe.d.ts +10 -0
  195. package/dist/replay/describe.js +31 -0
  196. package/dist/replay/gemini-turns.d.ts +36 -0
  197. package/dist/replay/gemini-turns.js +192 -0
  198. package/dist/replay/machine.d.ts +34 -0
  199. package/dist/replay/machine.js +68 -0
  200. package/dist/replay/progress-event.d.ts +21 -0
  201. package/dist/replay/progress-event.js +45 -0
  202. package/dist/replay/replay-runner.d.ts +58 -0
  203. package/dist/replay/replay-runner.js +529 -0
  204. package/dist/replay/replay-scan.d.ts +83 -0
  205. package/dist/replay/replay-scan.js +170 -0
  206. package/dist/replay/replay-state.d.ts +108 -0
  207. package/dist/replay/replay-state.js +199 -0
  208. package/dist/replay/resume.d.ts +18 -0
  209. package/dist/replay/resume.js +34 -0
  210. package/dist/replay/start.d.ts +23 -0
  211. package/dist/replay/start.js +39 -0
  212. package/dist/replay/throttle.d.ts +35 -0
  213. package/dist/replay/throttle.js +41 -0
  214. package/dist/replay/transcript-turns.d.ts +35 -0
  215. package/dist/replay/transcript-turns.js +215 -0
  216. package/dist/replay/turn-event.d.ts +38 -0
  217. package/dist/replay/turn-event.js +116 -0
  218. package/dist/replay/types/replay.types.d.ts +162 -0
  219. package/dist/replay/types/replay.types.js +1 -0
  220. package/dist/replay/window.d.ts +28 -0
  221. package/dist/replay/window.js +41 -0
  222. package/dist/snapshot/branch-selection.d.ts +40 -23
  223. package/dist/snapshot/branch-selection.js +74 -42
  224. package/dist/snapshot/budget.js +2 -2
  225. package/dist/snapshot/constants/snapshot-stages.constants.d.ts +10 -0
  226. package/dist/snapshot/constants/snapshot-stages.constants.js +10 -0
  227. package/dist/snapshot/constants/snapshot.constants.d.ts +37 -4
  228. package/dist/snapshot/constants/snapshot.constants.js +37 -4
  229. package/dist/snapshot/index.d.ts +6 -1
  230. package/dist/snapshot/index.js +3 -1
  231. package/dist/snapshot/snapshot-event.d.ts +7 -0
  232. package/dist/snapshot/snapshot-event.js +8 -5
  233. package/dist/snapshot/snapshot-pipeline.js +89 -26
  234. package/dist/snapshot/snapshot-state.js +24 -2
  235. package/dist/snapshot/tree-event.d.ts +14 -0
  236. package/dist/snapshot/tree-event.js +91 -0
  237. package/dist/snapshot/tree-pipeline.d.ts +12 -0
  238. package/dist/snapshot/tree-pipeline.js +172 -0
  239. package/dist/snapshot/types/snapshot.types.d.ts +62 -2
  240. package/dist/storage/schemas/storage.schema.d.ts +2 -0
  241. package/dist/storage/schemas/storage.schema.js +6 -0
  242. package/dist/transport/constants/transport.constants.d.ts +5 -0
  243. package/dist/transport/constants/transport.constants.js +5 -0
  244. package/dist/transport/delivery-stats.d.ts +13 -1
  245. package/dist/transport/delivery-stats.js +18 -2
  246. package/dist/transport/delivery.d.ts +4 -3
  247. package/dist/transport/delivery.js +21 -7
  248. package/dist/transport/identity-delivery.d.ts +20 -0
  249. package/dist/transport/identity-delivery.js +41 -0
  250. package/dist/transport/index.d.ts +2 -0
  251. package/dist/transport/index.js +1 -0
  252. package/dist/transport/queue.js +40 -6
  253. package/dist/transport/types/delivery-flow.types.d.ts +7 -0
  254. package/dist/turns/claude-transcript.js +4 -12
  255. package/dist/turns/codex-transcript.d.ts +9 -0
  256. package/dist/turns/codex-transcript.js +27 -19
  257. package/dist/turns/constants/turns.constants.d.ts +13 -12
  258. package/dist/turns/constants/turns.constants.js +15 -19
  259. package/dist/turns/gemini-transcript.d.ts +19 -1
  260. package/dist/turns/gemini-transcript.js +29 -18
  261. package/dist/turns/index.d.ts +3 -4
  262. package/dist/turns/index.js +2 -3
  263. package/dist/turns/run-state.d.ts +71 -0
  264. package/dist/turns/run-state.js +114 -0
  265. package/dist/turns/tool-events.d.ts +11 -1
  266. package/dist/turns/tool-events.js +32 -9
  267. package/dist/turns/transcript.d.ts +15 -14
  268. package/dist/turns/transcript.js +23 -4
  269. package/dist/turns/turn-state.d.ts +49 -7
  270. package/dist/turns/turn-state.js +78 -10
  271. package/dist/turns/turn-summary.js +10 -6
  272. package/dist/turns/turn-tracker.d.ts +9 -16
  273. package/dist/turns/turn-tracker.js +162 -86
  274. package/dist/turns/types/transcript.types.d.ts +11 -1
  275. package/dist/turns/types/turn-provider.types.d.ts +33 -0
  276. package/dist/turns/types/turn-provider.types.js +1 -0
  277. package/dist/turns/types/turn-state.types.d.ts +9 -0
  278. package/dist/turns/types/turn-summary.types.d.ts +20 -6
  279. package/dist/turns/types/turn-tracker.types.d.ts +3 -1
  280. package/dist/turns/work-checkout.js +1 -2
  281. package/docs/AUDIT_PROMPT.md +10 -0
  282. package/docs/DATA_HANDLING.md +269 -32
  283. package/docs/ENTERPRISE_DEPLOYMENT.md +1 -1
  284. package/docs/PERFORMANCE.md +27 -0
  285. package/package.json +3 -2
  286. package/dist/events/canonical-event.d.ts +0 -10
  287. package/dist/events/canonical-event.js +0 -9
  288. package/dist/git/repository-root.d.ts +0 -39
  289. package/dist/git/repository-root.js +0 -131
  290. package/dist/git/types/repository-root.types.d.ts +0 -11
  291. package/dist/transport/transport.d.ts +0 -6
  292. package/dist/turns/codex-originator.d.ts +0 -11
  293. package/dist/turns/cursor-transcript.d.ts +0 -21
  294. package/dist/turns/cursor-transcript.js +0 -66
  295. package/dist/turns/native-session-titles.d.ts +0 -26
  296. package/dist/turns/native-session-titles.js +0 -102
  297. /package/dist/{git/types/repository-root.types.js → billing/types/billing.types.js} +0 -0
  298. /package/dist/{transport/transport.js → capture/types/capture.types.js} +0 -0
@@ -1,29 +1,17 @@
1
1
  import path from 'node:path';
2
+ import { copiedShims, inspectCaptureEnv, installedCaptureEnv, removeCaptureCopy, shimPaths, withoutCaptureEnv } from '../../capture/capture-env.js';
2
3
  import { asRecord, omitKeys } from '../../core/object.js';
3
4
  import { enabledSignalNames, otelEnabled, otlpBaseUrl } from '../../config/config.js';
5
+ import { isAgentWatchEndpoint } from '../../config/schemas/config.schema.js';
4
6
  import { backupFile } from '../../storage/atomic-file.js';
5
7
  import { hasCredential } from '../../credentials/identity.js';
6
8
  import { readJsonFile } from '../../storage/json-file.js';
7
9
  import { writeJsonValidated } from '../shared/hook-config.js';
8
- import { withOtelInstall, withoutOtelInstall } from '../shared/install-record.js';
10
+ import { foldPriorValues, otelPriorValuesOf, parsePriorValue, withOtelInstall, withoutOtelInstall } from '../shared/install-record.js';
9
11
  import { HOOK_COMMAND_MARKER } from '../constants/provider.constants.js';
10
12
  import { claudeSettingsPath } from './claude.detect.js';
11
13
  import { CLAUDE_PROVIDER_ID } from './constants/claude.constants.js';
12
- import { ENV_BLOCK_KEY, HEADERS_HELPER_KEY, OTEL_EXPORTER_NONE, OTEL_EXPORTER_OTLP, OTLP_ENDPOINT_KEY, OTLP_PROTOCOL, OTLP_SIGNAL_ENDPOINT_KEYS, RE_HOOK_SUFFIX } from './constants/claude.otel.constants.js';
13
- /**
14
- * Claude's own content-logging switches, forced off.
15
- *
16
- * Never treated as a foreign key: a user who set `OTEL_LOG_USER_PROMPTS=1`
17
- * before installing is exactly the case this exists to override, and refusing
18
- * to configure them would leave prompt logging on *and* drop the llm.call
19
- * ledger. Overriding a switch that only ever reduces what leaves the machine
20
- * is not the redirection the conflict check protects against.
21
- */
22
- const CONTENT_LOG_OFF = {
23
- OTEL_LOG_USER_PROMPTS: '0',
24
- OTEL_LOG_TOOL_DETAILS: '0',
25
- OTEL_LOG_TOOL_CONTENT: '0'
26
- };
14
+ import { AGENTWATCH_ENV_VALUES, CONTENT_LOG_OFF, ENV_BLOCK_KEY, HEADERS_HELPER_KEY, OTEL_EXPORTER_NONE, OTEL_EXPORTER_OTLP, OTLP_ENDPOINT_KEY, OTLP_PROTOCOL, OTEL_SHARED_KEYS, OTLP_SIGNAL_ENDPOINT_KEYS, OTLP_SIGNAL_EXPORTER_KEYS, KEPT_REASON_MESSAGES, RE_HOOK_SUFFIX, SIGNAL_EXPORTER_EXTRA_KEYS, TRACES_BETA_KEY } from './constants/claude.otel.constants.js';
27
15
  /**
28
16
  * The telemetry environment AgentWatch wants in Claude Code's settings.
29
17
  *
@@ -53,7 +41,7 @@ function desiredClaudeOtelEnv(context) {
53
41
  OTEL_EXPORTER_OTLP_PROTOCOL: OTLP_PROTOCOL,
54
42
  [OTLP_ENDPOINT_KEY]: otlpBase,
55
43
  // The beta flag only adds the llm_request spans; it stays tied to traces.
56
- ...(signals.traces ? { CLAUDE_CODE_ENHANCED_TELEMETRY_BETA: '1' } : {})
44
+ ...(signals.traces ? { [TRACES_BETA_KEY]: '1' } : {})
57
45
  };
58
46
  }
59
47
  /**
@@ -119,6 +107,24 @@ function headersHelperCommand(hookCommand) {
119
107
  * ledger comes from.
120
108
  */
121
109
  export class ClaudeOtelConfigurator {
110
+ captureSource;
111
+ /**
112
+ * Bind to the shims setup copies.
113
+ *
114
+ * @param captureSource - The package's shims; tests name their own.
115
+ */
116
+ constructor(captureSource = shimPaths()) {
117
+ this.captureSource = captureSource;
118
+ }
119
+ /** Run capture rides in the same env block, and comes and goes with the exporters. */
120
+ runCapture = {
121
+ configPath: claudeSettingsPath,
122
+ inspect: async (context) => {
123
+ const read = await readJsonFile(claudeSettingsPath(context.env));
124
+ const block = asRecord(read.state === 'ok' ? asRecord(read.value)?.[ENV_BLOCK_KEY] : undefined) ?? {};
125
+ return inspectCaptureEnv(block, context.config, otelEnabled(context.config), context.paths.dataDir, this.captureSource);
126
+ }
127
+ };
122
128
  /**
123
129
  * Whether this agent can export native telemetry at all.
124
130
  *
@@ -154,7 +160,7 @@ export class ClaudeOtelConfigurator {
154
160
  if (Object.entries(desired).every(([key, value]) => envBlock[key] === value)) {
155
161
  return { supported: true, configured: true };
156
162
  }
157
- const conflicting = foreignKeys(envBlock, desired, ownedKeys);
163
+ const conflicting = foreignKeys(envBlock, desired, ownedKeys, context);
158
164
  if (conflicting.length > 0) {
159
165
  return { supported: true, configured: false, conflict: `existing telemetry env vars: ${conflicting.join(', ')}` };
160
166
  }
@@ -187,21 +193,25 @@ export class ClaudeOtelConfigurator {
187
193
  const settings = (read.state === 'ok' ? asRecord(read.value) : undefined) ?? {};
188
194
  const envBlock = asRecord(settings[ENV_BLOCK_KEY]) ?? {};
189
195
  const ownedKeys = this.ownedKeys(context);
190
- const conflicting = foreignKeys(envBlock, desired, ownedKeys);
196
+ const conflicting = foreignKeys(envBlock, desired, ownedKeys, context);
191
197
  if (conflicting.length > 0) {
192
198
  return {
193
199
  ok: false,
194
200
  changed: false,
201
+ conflict: true,
195
202
  messages: [`skipping native OpenTelemetry: ${conflicting.join(', ')} already set in ${settingsPath} (not AgentWatch-owned)`]
196
203
  };
197
204
  }
198
205
  // Signals disabled since the previous run leave stale AgentWatch-owned keys
199
- // behind — the enhanced-telemetry flag, once traces go off.
206
+ // behind — the enhanced-telemetry flag, once traces go off. A value the
207
+ // developer had there before goes back.
208
+ const previous = otelPriorValuesOf(context.installState, CLAUDE_PROVIDER_ID);
200
209
  const stale = new Set(ownedKeys.filter((key) => key !== HEADERS_HELPER_KEY && desired[key] === undefined));
201
- const withEnv = { ...settings, [ENV_BLOCK_KEY]: { ...omitKeys(envBlock, stale), ...desired } };
210
+ // Merged, never recorded as owned: uninstall takes our part of these two, not the keys.
211
+ const withEnv = { ...settings, [ENV_BLOCK_KEY]: { ...withRestored(await installedCaptureEnv(envBlock, context.env.vars, context.paths.dataDir, this.captureSource), stale, restoredEnv(previous, stale)), ...desired } };
202
212
  const helper = this.applyHeadersHelper(withEnv, context);
203
213
  if ('conflict' in helper) {
204
- return { ok: false, changed: false, messages: [helper.conflict] };
214
+ return { ok: false, changed: false, conflict: true, messages: [helper.conflict] };
205
215
  }
206
216
  const changed = JSON.stringify(helper.settings) !== JSON.stringify(settings);
207
217
  if (changed) {
@@ -217,6 +227,7 @@ export class ClaudeOtelConfigurator {
217
227
  installState: withOtelInstall(context.installState, CLAUDE_PROVIDER_ID, {
218
228
  configPath: settingsPath,
219
229
  ownedKeys: [...Object.keys(desired), ...helper.ownedExtra],
230
+ priorValues: priorEnvValues(envBlock, desired, ownedKeys, previous, context),
220
231
  configuredAt: context.env.now()
221
232
  })
222
233
  };
@@ -224,9 +235,11 @@ export class ClaudeOtelConfigurator {
224
235
  /**
225
236
  * Remove the telemetry configuration AgentWatch wrote.
226
237
  *
227
- * Only our own keys go. Without a recorded key list we fall back to the
228
- * well-known ones, and then only when their values are the ones we would have
229
- * written — user-owned telemetry config is never removed.
238
+ * Only our own keys go, and a key the developer had before setup gets its
239
+ * value back. Without a recorded key list, keys holding values AgentWatch
240
+ * writes go only while the base endpoint is an Agent Watch one, and a signal
241
+ * the developer sends to their own collector keeps what it needs. Whatever is
242
+ * left in place for want of proof is named, never dropped silently.
230
243
  *
231
244
  * @param context - Environment, paths, config and install state.
232
245
  * @returns Whether the file changed, what to tell the user, and the next
@@ -235,25 +248,28 @@ export class ClaudeOtelConfigurator {
235
248
  async uninstall(context) {
236
249
  const settingsPath = claudeSettingsPath(context.env);
237
250
  const read = await readJsonFile(settingsPath);
238
- if (read.state === 'missing')
251
+ if (read.state === 'missing') {
252
+ await removeCaptureCopy(context.paths.dataDir, context.env);
239
253
  return { ok: true, changed: false, messages: ['no Claude settings file'] };
254
+ }
240
255
  const settings = read.state === 'ok' ? asRecord(read.value) : undefined;
241
256
  if (!settings)
242
257
  return { ok: false, changed: false, messages: [`cannot parse ${settingsPath}; not modified`] };
243
- const desired = desiredClaudeOtelEnv(context) ?? {};
244
- const recorded = this.ownedKeys(context);
245
258
  const envBlock = asRecord(settings[ENV_BLOCK_KEY]);
246
- const removable = removableEnvKeys(envBlock, recorded, desired);
247
- const helperRemoved = isOurHelper(settings[HEADERS_HELPER_KEY]);
248
- const changed = removable.size > 0 || helperRemoved;
259
+ const { removable, kept, reason } = removableEnvKeys(envBlock ?? {}, this.ownedKeys(context), context);
260
+ const restored = restoredEnv(otelPriorValuesOf(context.installState, CLAUDE_PROVIDER_ID), removable);
261
+ const next = strippedSettings(settings, envBlock && withoutCaptureEnv(envBlock, copiedShims(context.paths.dataDir)), restored, removable, isOurHelper(settings[HEADERS_HELPER_KEY]));
262
+ const changed = JSON.stringify(next) !== JSON.stringify(settings);
263
+ const left = keptMessages(kept, reason, settingsPath);
249
264
  if (changed) {
250
265
  await backupFile(settingsPath, context.paths.backupsDir, context.env.now());
251
- await writeJsonValidated(settingsPath, strippedSettings(settings, envBlock, removable, helperRemoved));
266
+ await writeJsonValidated(settingsPath, next);
252
267
  }
268
+ await removeCaptureCopy(context.paths.dataDir, context.env);
253
269
  return {
254
270
  ok: true,
255
271
  changed,
256
- messages: changed ? ['native OpenTelemetry configuration removed'] : ['no AgentWatch telemetry configuration found'],
272
+ messages: [changed ? 'native OpenTelemetry configuration removed' : 'no AgentWatch telemetry configuration found', ...left],
257
273
  installState: withoutOtelInstall(context.installState, CLAUDE_PROVIDER_ID)
258
274
  };
259
275
  }
@@ -290,7 +306,9 @@ export class ClaudeOtelConfigurator {
290
306
  messages: [
291
307
  removed.changed
292
308
  ? 'native OpenTelemetry disabled in config; previous configuration removed'
293
- : 'native OpenTelemetry disabled in config (otel: none)'
309
+ : 'native OpenTelemetry disabled in config (otel: none)',
310
+ // Past uninstall's own headline: the keys it left and why.
311
+ ...removed.messages.slice(1)
294
312
  ],
295
313
  installState: removed.installState
296
314
  };
@@ -346,55 +364,192 @@ function inspectDisabled(settings, envBlock, ownedKeys) {
346
364
  * @param envBlock - Current env block.
347
365
  * @param desired - What we want to write.
348
366
  * @param ownedKeys - Keys a previous setup recorded as ours.
367
+ * @param context - Config, for which endpoints are ours.
349
368
  * @returns The conflicting key names.
350
369
  */
351
- function foreignKeys(envBlock, desired, ownedKeys) {
370
+ function foreignKeys(envBlock, desired, ownedKeys, context) {
352
371
  const owned = new Set([...ownedKeys, ...Object.keys(CONTENT_LOG_OFF)]);
353
- return Object.keys(desired).filter((key) => envBlock[key] !== undefined && envBlock[key] !== desired[key] && !owned.has(key));
372
+ // An endpoint uninstall would call ours is ours here too, so the two never disagree.
373
+ return Object.keys(desired).filter((key) => envBlock[key] !== undefined && envBlock[key] !== desired[key] && !owned.has(key) && !(key === OTLP_ENDPOINT_KEY && isOurEndpoint(envBlock[key], context)));
354
374
  }
355
375
  /**
356
376
  * Env keys uninstall is allowed to remove.
357
377
  *
358
- * @param envBlock - Current env block, when there is one.
378
+ * Recorded keys go whatever their value (absent ones too, so their prior value
379
+ * comes back). Without a record we are guessing: a key counts as ours only when
380
+ * it holds a value AgentWatch writes and the base endpoint is an Agent Watch
381
+ * one. A signal sent to the developer's own per-signal endpoint keeps its
382
+ * exporter and the switches every signal needs.
383
+ *
384
+ * @param envBlock - Current env block.
359
385
  * @param recorded - Keys a previous setup recorded as ours.
360
- * @param desired - What this config would write, for the value check.
361
- * @returns The keys to drop.
386
+ * @param context - Config, for which endpoints are ours.
387
+ * @returns The keys to drop and the AgentWatch-looking keys left in place.
362
388
  */
363
- function removableEnvKeys(envBlock, recorded, desired) {
364
- const removable = new Set();
365
- if (!envBlock)
366
- return removable;
367
- const candidates = recorded.length > 0 ? recorded : Object.keys(desired);
368
- for (const key of candidates) {
369
- if (key === HEADERS_HELPER_KEY || envBlock[key] === undefined)
370
- continue;
371
- // Without a recorded list we are guessing, so a value we would not have
372
- // written belongs to the user and stays.
373
- if (recorded.length === 0 && desired[key] !== undefined && envBlock[key] !== desired[key])
374
- continue;
375
- removable.add(key);
376
- }
377
- return removable;
389
+ function removableEnvKeys(envBlock, recorded, context) {
390
+ if (recorded.length > 0)
391
+ return { removable: new Set(recorded.filter((key) => key !== HEADERS_HELPER_KEY)), kept: [] };
392
+ const ownEndpoint = isOurEndpoint(envBlock[OTLP_ENDPOINT_KEY], context);
393
+ const ours = Object.keys(envBlock).filter((key) => isAgentWatchValue(key, envBlock[key], context));
394
+ if (!ownEndpoint)
395
+ return { removable: new Set(), kept: ours, reason: isNamedEndpoint(envBlock[OTLP_ENDPOINT_KEY]) ? 'foreignEndpoint' : 'noEndpoint' };
396
+ const developers = developerSignalKeys(envBlock, context);
397
+ return { removable: new Set(ours.filter((key) => !developers.has(key))), kept: ours.filter((key) => developers.has(key)), reason: 'ownSignal' };
398
+ }
399
+ /**
400
+ * Whether a key holds a value some AgentWatch setup writes; for the endpoint,
401
+ * one of ours.
402
+ *
403
+ * @param key - Env key.
404
+ * @param value - Its value.
405
+ * @param context - Config, for which endpoints are ours.
406
+ * @returns True for one of our values.
407
+ */
408
+ function isAgentWatchValue(key, value, context) {
409
+ if (key === OTLP_ENDPOINT_KEY)
410
+ return isOurEndpoint(value, context);
411
+ return AGENTWATCH_ENV_VALUES.get(key)?.has(value) === true;
412
+ }
413
+ /**
414
+ * Keys a signal needs while it exports to the developer's own per-signal
415
+ * endpoint: its exporter switch and what that exporter needs (the traces beta
416
+ * flag), plus the switches every signal shares. An empty or Agent Watch
417
+ * endpoint is not the developer's.
418
+ *
419
+ * @param envBlock - Current env block.
420
+ * @param context - Config, for which endpoints are ours.
421
+ * @returns The keys to leave in place.
422
+ */
423
+ function developerSignalKeys(envBlock, context) {
424
+ // Only an exporter switched to `otlp` sends there; `none` or no switch sends nothing, so it is not kept.
425
+ const exporters = [...OTLP_SIGNAL_EXPORTER_KEYS].flatMap(([endpoint, exporter]) => !isDeveloperEndpoint(envBlock[endpoint], context) || envBlock[exporter] !== OTEL_EXPORTER_OTLP
426
+ ? []
427
+ : [exporter, ...(SIGNAL_EXPORTER_EXTRA_KEYS.get(exporter) ?? [])]);
428
+ return new Set(exporters.length === 0 ? [] : [...exporters, ...OTEL_SHARED_KEYS]);
429
+ }
430
+ /**
431
+ * Whether a per-signal endpoint is the developer's own collector.
432
+ *
433
+ * @param value - The endpoint as the settings hold it.
434
+ * @param context - Config, for which endpoints are ours.
435
+ * @returns True for a non-empty endpoint that is not ours.
436
+ */
437
+ function isDeveloperEndpoint(value, context) {
438
+ return isNamedEndpoint(value) && !isOurEndpoint(value, context);
439
+ }
440
+ /**
441
+ * Whether an endpoint value names anywhere at all.
442
+ *
443
+ * @param value - The endpoint as the settings hold it.
444
+ * @returns True for a non-empty string.
445
+ */
446
+ function isNamedEndpoint(value) {
447
+ return typeof value === 'string' && value.trim() !== '';
448
+ }
449
+ /**
450
+ * Whether an endpoint is one AgentWatch sends to: the one this config names,
451
+ * an Agent Watch host, or an origin this machine trusts. A changed config URL
452
+ * must not turn an exporter setup wrote into the developer's.
453
+ *
454
+ * @param value - The endpoint as the settings hold it.
455
+ * @param context - Config, for its endpoint and trusted origins.
456
+ * @returns True when the endpoint is ours.
457
+ */
458
+ function isOurEndpoint(value, context) {
459
+ if (typeof value !== 'string')
460
+ return false;
461
+ return value === otlpBaseUrl(context.config) || isAgentWatchEndpoint(value, new Set(context.config.customEndpoints));
462
+ }
463
+ /**
464
+ * What each desired key held before AgentWatch took it, as JSON text so
465
+ * uninstall puts back the same value and type. With no record, a file already
466
+ * sending to our endpoint was written by an AgentWatch setup whose record is
467
+ * gone, so nothing in it is the developer's.
468
+ *
469
+ * @param envBlock - Current env block.
470
+ * @param desired - What we are about to write.
471
+ * @param ownedKeys - Keys a previous setup recorded as ours.
472
+ * @param previous - Prior values that setup recorded.
473
+ * @param context - Config, for which endpoints are ours.
474
+ * @returns Prior values by key.
475
+ */
476
+ function priorEnvValues(envBlock, desired, ownedKeys, previous, context) {
477
+ const leftover = ownedKeys.length === 0 && isOurEndpoint(envBlock[OTLP_ENDPOINT_KEY], context);
478
+ // Even in a leftover file, a value AgentWatch never writes, or a key a
479
+ // developer's own per-signal export needs, is the developer's.
480
+ const developers = leftover ? developerSignalKeys(envBlock, context) : new Set();
481
+ const keys = Object.keys(desired);
482
+ const before = Object.fromEntries(keys.flatMap((key) => {
483
+ const value = envBlock[key];
484
+ const theirs = !leftover || developers.has(key) || !isAgentWatchValue(key, value, context);
485
+ return value === undefined || !theirs ? [] : [[key, JSON.stringify(value)]];
486
+ }));
487
+ return foldPriorValues(keys, ownedKeys, previous, before);
488
+ }
489
+ /**
490
+ * The recorded prior values of the given keys, decoded.
491
+ *
492
+ * @param priors - Prior values by key, as JSON text.
493
+ * @param keys - Keys being dropped.
494
+ * @returns The values to put back.
495
+ */
496
+ function restoredEnv(priors, keys) {
497
+ return Object.fromEntries([...keys].flatMap((key) => {
498
+ const value = parsePriorValue(priors[key]);
499
+ return value === undefined ? [] : [[key, value]];
500
+ }));
501
+ }
502
+ /**
503
+ * An env block with keys dropped and prior values put back.
504
+ *
505
+ * A restored key keeps its place, so a restore that changes nothing rewrites
506
+ * nothing.
507
+ *
508
+ * @param envBlock - Current env block.
509
+ * @param dropped - Keys we give up.
510
+ * @param restored - The developer's own values among them.
511
+ * @returns The next env block.
512
+ */
513
+ function withRestored(envBlock, dropped, restored) {
514
+ return { ...omitKeys(envBlock, new Set([...dropped].filter((key) => !Object.hasOwn(restored, key)))), ...restored };
378
515
  }
379
516
  /**
380
517
  * Settings with our telemetry keys removed.
381
518
  *
382
519
  * @param settings - The whole settings object.
383
- * @param envBlock - Its env block, when there is one.
520
+ * @param withoutCapture - The env block with our part of the capture variables gone.
521
+ * @param restored - The developer's own values to put back.
384
522
  * @param removable - Env keys to drop.
385
523
  * @param helperRemoved - Whether the header helper is ours to drop.
386
524
  * @returns The next settings object.
387
525
  */
388
- function strippedSettings(settings, envBlock, removable, helperRemoved) {
526
+ function strippedSettings(settings, withoutCapture, restored, removable, helperRemoved) {
389
527
  const withoutHelper = helperRemoved ? omitKeys(settings, new Set([HEADERS_HELPER_KEY])) : settings;
390
- if (!envBlock)
528
+ const envBlock = asRecord(settings[ENV_BLOCK_KEY]);
529
+ // An env value that is not an object is not ours to replace.
530
+ if (!envBlock && settings[ENV_BLOCK_KEY] !== undefined)
391
531
  return withoutHelper;
392
- const nextEnv = omitKeys(envBlock, removable);
393
- // An emptied env block is dropped rather than left as `"env": {}`.
394
- if (Object.keys(nextEnv).length === 0)
395
- return omitKeys(withoutHelper, new Set([ENV_BLOCK_KEY]));
532
+ const nextEnv = withRestored(withoutCapture ?? {}, removable, restored);
533
+ // A block this run emptied is dropped rather than left as `"env": {}`; one
534
+ // that was already empty is the developer's and stays.
535
+ if (Object.keys(nextEnv).length === 0) {
536
+ return Object.keys(envBlock ?? {}).length > 0 ? omitKeys(withoutHelper, new Set([ENV_BLOCK_KEY])) : withoutHelper;
537
+ }
396
538
  return { ...withoutHelper, [ENV_BLOCK_KEY]: nextEnv };
397
539
  }
540
+ /**
541
+ * What uninstall says about keys it left for want of an install record.
542
+ *
543
+ * @param kept - The keys left in place.
544
+ * @param reason - Why they were left.
545
+ * @param settingsPath - The settings file, to name.
546
+ * @returns The messages; none when nothing was left.
547
+ */
548
+ function keptMessages(kept, reason, settingsPath) {
549
+ if (kept.length === 0 || !reason)
550
+ return [];
551
+ return [`left ${kept.join(', ')} in ${settingsPath}: ${KEPT_REASON_MESSAGES[reason]}`];
552
+ }
398
553
  /**
399
554
  * Whether the configured header helper is one we wrote.
400
555
  *
@@ -1,5 +1,8 @@
1
+ import { claudeBillingMode } from '../../billing/billing-mode.js';
2
+ import { asRecord } from '../../core/object.js';
1
3
  import { hookNotice, hookRefusal } from '../shared/hook-refusal.js';
2
- import { CLAUDE_PROMPT_SUBMIT_EVENTS } from './constants/claude.constants.js';
4
+ import { readClaudeSessionTitles, readTurnUsage } from '../../turns/claude-transcript.js';
5
+ import { CLAUDE_DETACHED_EVENTS, CLAUDE_ENTRYPOINT_VAR, CLAUDE_INTERACTIVE_ENTRYPOINTS, CLAUDE_PROMPT_SUBMIT_EVENTS } from './constants/claude.constants.js';
3
6
  import { detectClaude } from './claude.detect.js';
4
7
  import { installClaudeHooks, uninstallClaudeHooks } from './claude.hooks.js';
5
8
  import { claudeShellCall, parseClaudeHookEvent } from './claude.adapter.js';
@@ -7,6 +10,8 @@ import { ClaudeOtelConfigurator } from './claude.otel.js';
7
10
  export const claudeProvider = {
8
11
  id: 'claude',
9
12
  displayName: 'Claude Code',
13
+ /** Doctor only, so the hook path never loads the version probe. */
14
+ checks: async (env) => (await import('./claude.version.js')).claudeVersionChecks(env),
10
15
  detect: detectClaude,
11
16
  installHooks: installClaudeHooks,
12
17
  uninstallHooks: uninstallClaudeHooks,
@@ -24,6 +29,17 @@ export const claudeProvider = {
24
29
  getBlockResponse: (payload, message) => hookRefusal(payload, CLAUDE_PROMPT_SUBMIT_EVENTS, { decision: 'block', reason: message }),
25
30
  /** A line for the developer after a shell run, as `systemMessage`; never plain stdout. */
26
31
  getNoticeResponse: (payload, message) => hookNotice(payload, message),
32
+ /**
33
+ * Stop and SubagentStop of a terminal session; anywhere else the session may end at once and its `SessionEnd` would race the close.
34
+ * ponytail: an interactive `/exit` or `/clear` within the ~0.3 s the detached close takes can still race
35
+ * its `SessionEnd`; upgrade path is a pending-close marker that `SessionEnd` waits on.
36
+ */
37
+ runsDetached: (payload, env) => CLAUDE_DETACHED_EVENTS.has(String(asRecord(payload)?.['hook_event_name'])) && CLAUDE_INTERACTIVE_ENTRYPOINTS.has(env.vars[CLAUDE_ENTRYPOINT_VAR] ?? ''),
27
38
  shellCall: claudeShellCall,
39
+ readTurnUsage,
40
+ billingMode: claudeBillingMode,
41
+ readTranscriptTitles: readClaudeSessionTitles,
42
+ /** Claude Code names its own entrypoint (`cli`, `claude-vscode`, `sdk-ts`, ...). */
43
+ surface: async (env) => env.vars[CLAUDE_ENTRYPOINT_VAR] || undefined,
28
44
  nativeTelemetry: new ClaudeOtelConfigurator()
29
45
  };
@@ -0,0 +1,9 @@
1
+ import type { Env } from '../../core/types/core.types.js';
2
+ import type { ProviderCheck } from '../types/provider.types.js';
3
+ /**
4
+ * Whether Claude Code is new enough for prompt-id turn correlation.
5
+ *
6
+ * @param env - Ambient environment.
7
+ * @returns The one check, for doctor.
8
+ */
9
+ export declare function claudeVersionChecks(env: Env): Promise<readonly ProviderCheck[]>;
@@ -0,0 +1,28 @@
1
+ import { execVersion, meetsMinVersion, parseVersion } from '../../core/version.js';
2
+ import { findExecutable } from '../../core/which.js';
3
+ import { CLAUDE_MIN_VERSION_FOR_PROMPT_ID, CLAUDE_VERSION_TIMEOUT_MS } from './constants/claude.constants.js';
4
+ /**
5
+ * Whether Claude Code is new enough for prompt-id turn correlation.
6
+ *
7
+ * @param env - Ambient environment.
8
+ * @returns The one check, for doctor.
9
+ */
10
+ export async function claudeVersionChecks(env) {
11
+ const name = 'Claude Code version';
12
+ const bin = findExecutable(env, 'claude');
13
+ if (!bin) {
14
+ return [{ name, level: 'warn', detail: `claude not on PATH; cannot verify >= ${CLAUDE_MIN_VERSION_FOR_PROMPT_ID} (needed for turn correlation)` }];
15
+ }
16
+ const output = await execVersion(bin, ['--version'], CLAUDE_VERSION_TIMEOUT_MS);
17
+ const version = output ? parseVersion(output) : undefined;
18
+ if (!version) {
19
+ return [{ name, level: 'warn', detail: `could not determine version (need >= ${CLAUDE_MIN_VERSION_FOR_PROMPT_ID} for turn correlation)` }];
20
+ }
21
+ if (meetsMinVersion(version, CLAUDE_MIN_VERSION_FOR_PROMPT_ID))
22
+ return [{ name, level: 'ok', detail: version }];
23
+ return [{
24
+ name,
25
+ level: 'warn',
26
+ detail: `${version} — prompt_id turn correlation needs >= ${CLAUDE_MIN_VERSION_FOR_PROMPT_ID}; turn_id will be empty`
27
+ }];
28
+ }
@@ -14,10 +14,30 @@ export declare const CLAUDE_EXECUTABLE = "claude";
14
14
  export declare const CLAUDE_HOOK_EVENTS: readonly ["SessionStart", "SessionEnd", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PostToolUseFailure", "PermissionRequest", "Stop", "SubagentStart", "SubagentStop"];
15
15
  /** Tool-scoped events take a tool-name matcher; "*" observes every tool. */
16
16
  export declare const CLAUDE_MATCHED_EVENTS: ReadonlySet<string>;
17
+ /**
18
+ * Hooks whose work a detached `agentwatch hook` does, so the end of a turn does
19
+ * not wait on the send (p50 1 s, p99 6 s, measured 2026-11; the hand-off takes
20
+ * about 0.1 s). Not `async: true` in settings: under `claude -p` Claude kills an
21
+ * async hook within milliseconds of its Stop, before Node has even started.
22
+ * Only hooks that answer nothing qualify: `UserPromptSubmit` carries the budget
23
+ * refusal, and `SessionEnd` clears the session's state.
24
+ */
25
+ export declare const CLAUDE_DETACHED_EVENTS: ReadonlySet<string>;
26
+ /**
27
+ * `CLAUDE_CODE_ENTRYPOINT` values of a session a person keeps open (`cli`, the
28
+ * terminal; verified 2026-11). Only these hand a Stop off. Any other entrypoint
29
+ * (`sdk-cli` for `claude -p`, the SDKs, the GitHub Action, or none at all) may end
30
+ * the session right after its last Stop, and that `SessionEnd` clears the turn
31
+ * state a detached close still has to read, so those Stops run in place.
32
+ */
33
+ export declare const CLAUDE_ENTRYPOINT_VAR = "CLAUDE_CODE_ENTRYPOINT";
34
+ export declare const CLAUDE_INTERACTIVE_ENTRYPOINTS: ReadonlySet<string>;
17
35
  /** Claude Code reads this field as seconds. */
18
36
  export declare const CLAUDE_HOOK_TIMEOUT_SECONDS = 30;
19
37
  /** Provider hook name to canonical event type, where the mapping is direct. */
20
38
  export declare const CLAUDE_EVENT_TYPE_MAP: Readonly<Record<string, CanonicalEventType>>;
39
+ /** The tool that runs a skill; its input names it as `skill` (AWT-711). */
40
+ export declare const CLAUDE_SKILL_TOOL = "Skill";
21
41
  /** Hooks whose canonical type depends on which tool ran. */
22
42
  export declare const CLAUDE_TOOL_EVENTS: ReadonlySet<string>;
23
43
  /** Hooks that report a tool call as starting rather than finishing. */
@@ -40,3 +60,10 @@ export declare const CLAUDE_UNKNOWN_EVENT = "unknown";
40
60
  * the error is read for the number in memory, never kept.
41
61
  */
42
62
  export declare const RE_CLAUDE_EXIT_CODE: RegExp;
63
+ /**
64
+ * prompt_id (== OTel prompt.id) appeared in this Claude Code release; older
65
+ * versions fall back to session-scoped turn tracking with an empty turn_id.
66
+ */
67
+ export declare const CLAUDE_MIN_VERSION_FOR_PROMPT_ID = "2.1.196";
68
+ /** How long doctor waits for `claude --version`. */
69
+ export declare const CLAUDE_VERSION_TIMEOUT_MS = 5000;
@@ -24,6 +24,24 @@ export const CLAUDE_HOOK_EVENTS = [
24
24
  ];
25
25
  /** Tool-scoped events take a tool-name matcher; "*" observes every tool. */
26
26
  export const CLAUDE_MATCHED_EVENTS = new Set(['PreToolUse', 'PostToolUse', 'PostToolUseFailure', 'PermissionRequest']);
27
+ /**
28
+ * Hooks whose work a detached `agentwatch hook` does, so the end of a turn does
29
+ * not wait on the send (p50 1 s, p99 6 s, measured 2026-11; the hand-off takes
30
+ * about 0.1 s). Not `async: true` in settings: under `claude -p` Claude kills an
31
+ * async hook within milliseconds of its Stop, before Node has even started.
32
+ * Only hooks that answer nothing qualify: `UserPromptSubmit` carries the budget
33
+ * refusal, and `SessionEnd` clears the session's state.
34
+ */
35
+ export const CLAUDE_DETACHED_EVENTS = new Set(['Stop', 'SubagentStop']);
36
+ /**
37
+ * `CLAUDE_CODE_ENTRYPOINT` values of a session a person keeps open (`cli`, the
38
+ * terminal; verified 2026-11). Only these hand a Stop off. Any other entrypoint
39
+ * (`sdk-cli` for `claude -p`, the SDKs, the GitHub Action, or none at all) may end
40
+ * the session right after its last Stop, and that `SessionEnd` clears the turn
41
+ * state a detached close still has to read, so those Stops run in place.
42
+ */
43
+ export const CLAUDE_ENTRYPOINT_VAR = 'CLAUDE_CODE_ENTRYPOINT';
44
+ export const CLAUDE_INTERACTIVE_ENTRYPOINTS = new Set(['cli']);
27
45
  /** Claude Code reads this field as seconds. */
28
46
  export const CLAUDE_HOOK_TIMEOUT_SECONDS = 30;
29
47
  /** Provider hook name to canonical event type, where the mapping is direct. */
@@ -38,6 +56,8 @@ export const CLAUDE_EVENT_TYPE_MAP = {
38
56
  PreCompact: 'compaction.started',
39
57
  PostCompact: 'compaction.completed'
40
58
  };
59
+ /** The tool that runs a skill; its input names it as `skill` (AWT-711). */
60
+ export const CLAUDE_SKILL_TOOL = 'Skill';
41
61
  /** Hooks whose canonical type depends on which tool ran. */
42
62
  export const CLAUDE_TOOL_EVENTS = new Set(['PreToolUse', 'PostToolUse', 'PostToolUseFailure', 'PermissionRequest']);
43
63
  /** Hooks that report a tool call as starting rather than finishing. */
@@ -60,3 +80,10 @@ export const CLAUDE_UNKNOWN_EVENT = 'unknown';
60
80
  * the error is read for the number in memory, never kept.
61
81
  */
62
82
  export const RE_CLAUDE_EXIT_CODE = /\bexit code (-?\d+)\b/i;
83
+ /**
84
+ * prompt_id (== OTel prompt.id) appeared in this Claude Code release; older
85
+ * versions fall back to session-scoped turn tracking with an empty turn_id.
86
+ */
87
+ export const CLAUDE_MIN_VERSION_FOR_PROMPT_ID = '2.1.196';
88
+ /** How long doctor waits for `claude --version`. */
89
+ export const CLAUDE_VERSION_TIMEOUT_MS = 5_000;
@@ -1,3 +1,4 @@
1
+ import type { KeptReason } from '../types/claude.types.js';
1
2
  /** Settings key Claude Code reads the OTLP header helper command from. */
2
3
  export declare const HEADERS_HELPER_KEY = "otelHeadersHelper";
3
4
  /** Settings key holding the environment block telemetry is configured through. */
@@ -17,5 +18,31 @@ export declare const OTLP_PROTOCOL = "http/json";
17
18
  export declare const RE_HOOK_SUFFIX: RegExp;
18
19
  /** Where Claude Code's exporters send: the OTLP base every signal derives from. */
19
20
  export declare const OTLP_ENDPOINT_KEY = "OTEL_EXPORTER_OTLP_ENDPOINT";
21
+ /** Each signal's own endpoint key, mapped to the exporter switch that signal reads. */
22
+ export declare const OTLP_SIGNAL_EXPORTER_KEYS: ReadonlyMap<string, string>;
20
23
  /** Per-signal endpoints, which override the base for that one signal. */
21
24
  export declare const OTLP_SIGNAL_ENDPOINT_KEYS: readonly string[];
25
+ /** Claude's enhanced-traces beta switch, which only adds the llm_request spans. */
26
+ export declare const TRACES_BETA_KEY = "CLAUDE_CODE_ENHANCED_TELEMETRY_BETA";
27
+ /** Keys a signal's exporter needs beside itself, by exporter switch. */
28
+ export declare const SIGNAL_EXPORTER_EXTRA_KEYS: ReadonlyMap<string, readonly string[]>;
29
+ /** Keys every exporting signal needs, whoever's collector it sends to. */
30
+ export declare const OTEL_SHARED_KEYS: readonly string[];
31
+ /**
32
+ * Claude's own content-logging switches, forced off.
33
+ *
34
+ * Never treated as a foreign key: a user who set `OTEL_LOG_USER_PROMPTS=1`
35
+ * before installing is exactly the case this exists to override, and refusing
36
+ * to configure them would leave prompt logging on *and* drop the llm.call
37
+ * ledger. Overriding a switch that only ever reduces what leaves the machine
38
+ * is not the redirection the conflict check protects against.
39
+ */
40
+ export declare const CONTENT_LOG_OFF: Readonly<Record<string, string>>;
41
+ /**
42
+ * Every value any AgentWatch setup writes for an env key, whatever the signals
43
+ * were then. Without an install record, a key counts as ours only when it holds
44
+ * one of these. The endpoint is judged on its own (an Agent Watch host).
45
+ */
46
+ export declare const AGENTWATCH_ENV_VALUES: ReadonlyMap<string, ReadonlySet<unknown>>;
47
+ /** What uninstall says about keys it left, by why it left them. */
48
+ export declare const KEPT_REASON_MESSAGES: Readonly<Record<KeptReason, string>>;