@agent-watch-ai/edge 0.6.0 → 0.7.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 (309) hide show
  1. package/CHANGELOG.md +288 -9
  2. package/README.md +307 -5
  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 +7 -3
  10. package/dist/billing/session-billing.js +34 -13
  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 +503 -0
  16. package/dist/capture/constants/capture.constants.d.ts +85 -0
  17. package/dist/capture/constants/capture.constants.js +87 -0
  18. package/dist/capture/launched-runs.d.ts +43 -0
  19. package/dist/capture/launched-runs.js +157 -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 +832 -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/capture/venv-loader.d.ts +68 -0
  27. package/dist/capture/venv-loader.js +189 -0
  28. package/dist/cli/constants/cli.constants.d.ts +23 -6
  29. package/dist/cli/constants/cli.constants.js +24 -7
  30. package/dist/cli/context.d.ts +19 -22
  31. package/dist/cli/context.js +23 -54
  32. package/dist/cli/doctor-run-capture.d.ts +21 -0
  33. package/dist/cli/doctor-run-capture.js +33 -0
  34. package/dist/cli/doctor.js +21 -68
  35. package/dist/cli/hook-check.d.ts +7 -2
  36. package/dist/cli/hook-check.js +30 -15
  37. package/dist/cli/hook.d.ts +14 -0
  38. package/dist/cli/hook.js +82 -1
  39. package/dist/cli/index.d.ts +1 -1
  40. package/dist/cli/index.js +1 -1
  41. package/dist/cli/misc.js +10 -2
  42. package/dist/cli/npm-global.d.ts +24 -0
  43. package/dist/cli/npm-global.js +77 -0
  44. package/dist/cli/npx-install.js +22 -6
  45. package/dist/cli/replay.d.ts +33 -0
  46. package/dist/cli/replay.js +228 -0
  47. package/dist/cli/setup.d.ts +10 -2
  48. package/dist/cli/setup.js +200 -31
  49. package/dist/cli/status.js +45 -5
  50. package/dist/cli/toggle.js +10 -0
  51. package/dist/cli/types/cli.types.d.ts +15 -1
  52. package/dist/cli/uninstall.js +42 -23
  53. package/dist/cli/update.js +3 -2
  54. package/dist/cli.js +104 -17
  55. package/dist/config/config-store.d.ts +15 -4
  56. package/dist/config/config-store.js +31 -7
  57. package/dist/config/config.d.ts +0 -2
  58. package/dist/config/config.js +0 -1
  59. package/dist/config/constants/config.constants.d.ts +8 -1
  60. package/dist/config/constants/config.constants.js +10 -1
  61. package/dist/config/events-transport.d.ts +15 -0
  62. package/dist/config/events-transport.js +29 -0
  63. package/dist/config/index.d.ts +2 -1
  64. package/dist/config/index.js +1 -0
  65. package/dist/config/root-config.d.ts +12 -0
  66. package/dist/config/root-config.js +24 -0
  67. package/dist/config/schemas/config.schema.d.ts +15 -2
  68. package/dist/config/schemas/config.schema.js +52 -8
  69. package/dist/config/types/config.types.d.ts +7 -0
  70. package/dist/core/index.d.ts +1 -1
  71. package/dist/core/index.js +1 -1
  72. package/dist/core/version.d.ts +9 -0
  73. package/dist/core/version.js +14 -0
  74. package/dist/core/which.d.ts +11 -0
  75. package/dist/core/which.js +18 -0
  76. package/dist/credentials/cloud-claim.d.ts +34 -0
  77. package/dist/credentials/cloud-claim.js +61 -0
  78. package/dist/credentials/constants/credentials.constants.d.ts +16 -1
  79. package/dist/credentials/constants/credentials.constants.js +17 -2
  80. package/dist/credentials/credential-status.js +1 -1
  81. package/dist/credentials/credentials.d.ts +3 -3
  82. package/dist/credentials/credentials.js +26 -12
  83. package/dist/credentials/device-api.d.ts +15 -1
  84. package/dist/credentials/device-api.js +12 -1
  85. package/dist/credentials/identity.d.ts +2 -2
  86. package/dist/credentials/identity.js +2 -2
  87. package/dist/credentials/install-key.d.ts +31 -0
  88. package/dist/credentials/install-key.js +58 -0
  89. package/dist/credentials/migration.d.ts +9 -7
  90. package/dist/credentials/migration.js +58 -18
  91. package/dist/credentials/secret-store.d.ts +12 -0
  92. package/dist/credentials/secret-store.js +18 -1
  93. package/dist/credentials/sign-in.d.ts +27 -0
  94. package/dist/credentials/sign-in.js +31 -1
  95. package/dist/credentials/token-refresher.d.ts +5 -1
  96. package/dist/credentials/token-refresher.js +10 -2
  97. package/dist/enforcement/enforcement.js +1 -1
  98. package/dist/events/constants/events.constants.d.ts +5 -2
  99. package/dist/events/constants/events.constants.js +4 -1
  100. package/dist/events/enrich.d.ts +14 -0
  101. package/dist/events/enrich.js +1 -1
  102. package/dist/events/index.d.ts +1 -0
  103. package/dist/events/product-event.d.ts +6 -3
  104. package/dist/events/types/events.types.d.ts +6 -0
  105. package/dist/events/types/replay-progress.types.d.ts +26 -0
  106. package/dist/events/types/replay-progress.types.js +1 -0
  107. package/dist/events/types/repo-tree.types.d.ts +2 -1
  108. package/dist/feature/ticket-candidates.d.ts +1 -1
  109. package/dist/git/checkout-root.d.ts +15 -0
  110. package/dist/git/checkout-root.js +18 -0
  111. package/dist/git/code-state.d.ts +2 -16
  112. package/dist/git/code-state.js +11 -12
  113. package/dist/git/constants/git.constants.d.ts +33 -11
  114. package/dist/git/constants/git.constants.js +45 -12
  115. package/dist/git/fingerprint.d.ts +3 -6
  116. package/dist/git/fingerprint.js +5 -8
  117. package/dist/git/git-context.js +5 -1
  118. package/dist/git/index.d.ts +1 -2
  119. package/dist/git/index.js +1 -1
  120. package/dist/git/repo-snapshot.d.ts +13 -4
  121. package/dist/git/repo-snapshot.js +53 -9
  122. package/dist/git/types/snapshot.types.d.ts +6 -0
  123. package/dist/pipeline/constants/pipeline.constants.d.ts +3 -0
  124. package/dist/pipeline/constants/pipeline.constants.js +3 -0
  125. package/dist/pipeline/hook-pipeline.js +82 -57
  126. package/dist/privacy/product-capture.js +2 -0
  127. package/dist/providers/antigravity/antigravity.capture.d.ts +2 -0
  128. package/dist/providers/antigravity/antigravity.capture.js +5 -0
  129. package/dist/providers/antigravity/antigravity.detect.js +8 -22
  130. package/dist/providers/antigravity/antigravity.provider.js +10 -3
  131. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +1 -0
  132. package/dist/providers/antigravity/constants/antigravity.constants.js +1 -0
  133. package/dist/providers/claude/claude.adapter.js +9 -6
  134. package/dist/providers/claude/claude.detect.js +2 -17
  135. package/dist/providers/claude/claude.otel.d.ts +21 -3
  136. package/dist/providers/claude/claude.otel.js +216 -61
  137. package/dist/providers/claude/claude.provider.js +21 -1
  138. package/dist/providers/claude/claude.version.d.ts +9 -0
  139. package/dist/providers/claude/claude.version.js +28 -0
  140. package/dist/providers/claude/constants/claude.constants.d.ts +27 -0
  141. package/dist/providers/claude/constants/claude.constants.js +27 -0
  142. package/dist/providers/claude/constants/claude.otel.constants.d.ts +27 -0
  143. package/dist/providers/claude/constants/claude.otel.constants.js +45 -5
  144. package/dist/providers/claude/types/claude.types.d.ts +13 -0
  145. package/dist/providers/codex/codex.capture.d.ts +76 -0
  146. package/dist/providers/codex/codex.capture.js +454 -0
  147. package/dist/providers/codex/codex.detect.js +2 -4
  148. package/dist/providers/codex/codex.otel.d.ts +38 -2
  149. package/dist/providers/codex/codex.otel.js +50 -6
  150. package/dist/providers/codex/codex.provider.js +8 -0
  151. package/dist/providers/codex/codex.surface.d.ts +9 -0
  152. package/dist/{turns/codex-originator.js → providers/codex/codex.surface.js} +17 -3
  153. package/dist/providers/codex/codex.titles.d.ts +14 -0
  154. package/dist/providers/codex/codex.titles.js +35 -0
  155. package/dist/providers/codex/constants/codex.constants.d.ts +4 -0
  156. package/dist/providers/codex/constants/codex.constants.js +4 -0
  157. package/dist/providers/cursor/constants/cursor.constants.d.ts +17 -4
  158. package/dist/providers/cursor/constants/cursor.constants.js +25 -5
  159. package/dist/providers/cursor/cursor-mcp-memo.d.ts +34 -0
  160. package/dist/providers/cursor/cursor-mcp-memo.js +94 -0
  161. package/dist/providers/cursor/cursor.adapter.js +20 -82
  162. package/dist/providers/cursor/cursor.capture.d.ts +1 -0
  163. package/dist/providers/cursor/cursor.capture.js +4 -0
  164. package/dist/providers/cursor/cursor.detect.d.ts +5 -1
  165. package/dist/providers/cursor/cursor.detect.js +11 -26
  166. package/dist/providers/cursor/cursor.hooks.js +2 -2
  167. package/dist/providers/cursor/cursor.provider.js +16 -7
  168. package/dist/providers/cursor/cursor.titles.d.ts +14 -0
  169. package/dist/providers/cursor/cursor.titles.js +20 -0
  170. package/dist/providers/cursor/schemas/cursor.schema.d.ts +3 -3
  171. package/dist/providers/cursor/schemas/cursor.schema.js +5 -3
  172. package/dist/providers/gemini/constants/gemini.constants.d.ts +16 -0
  173. package/dist/providers/gemini/constants/gemini.constants.js +17 -0
  174. package/dist/providers/gemini/gemini.capture.d.ts +81 -0
  175. package/dist/providers/gemini/gemini.capture.js +210 -0
  176. package/dist/providers/gemini/gemini.detect.js +57 -24
  177. package/dist/providers/gemini/gemini.otel.d.ts +38 -2
  178. package/dist/providers/gemini/gemini.otel.js +56 -125
  179. package/dist/providers/gemini/gemini.provider.js +5 -0
  180. package/dist/providers/index.d.ts +1 -0
  181. package/dist/providers/index.js +1 -0
  182. package/dist/providers/provider.d.ts +8 -0
  183. package/dist/providers/provider.js +9 -0
  184. package/dist/providers/registry.d.ts +14 -0
  185. package/dist/providers/registry.js +14 -0
  186. package/dist/providers/shared/constants/hook-config.constants.d.ts +2 -0
  187. package/dist/providers/shared/constants/hook-config.constants.js +2 -0
  188. package/dist/providers/shared/constants/terminal-capture.constants.d.ts +6 -0
  189. package/dist/providers/shared/constants/terminal-capture.constants.js +6 -0
  190. package/dist/providers/shared/editor-paths.d.ts +8 -0
  191. package/dist/providers/shared/editor-paths.js +18 -0
  192. package/dist/providers/shared/hook-config.d.ts +5 -0
  193. package/dist/providers/shared/hook-config.js +39 -1
  194. package/dist/providers/shared/hooks-marker.d.ts +14 -0
  195. package/dist/providers/shared/hooks-marker.js +23 -0
  196. package/dist/providers/shared/install-record.d.ts +29 -0
  197. package/dist/providers/shared/install-record.js +52 -0
  198. package/dist/providers/shared/session-title-store.d.ts +23 -0
  199. package/dist/providers/shared/session-title-store.js +50 -0
  200. package/dist/providers/shared/terminal-capture.d.ts +41 -0
  201. package/dist/providers/shared/terminal-capture.js +109 -0
  202. package/dist/providers/shared/tooling.d.ts +21 -0
  203. package/dist/providers/shared/tooling.js +36 -1
  204. package/dist/providers/types/provider.types.d.ts +57 -4
  205. package/dist/replay/checkout-resolver.d.ts +56 -0
  206. package/dist/replay/checkout-resolver.js +173 -0
  207. package/dist/replay/codex-turns.d.ts +24 -0
  208. package/dist/replay/codex-turns.js +221 -0
  209. package/dist/replay/constants/replay.constants.d.ts +99 -0
  210. package/dist/replay/constants/replay.constants.js +102 -0
  211. package/dist/replay/describe.d.ts +10 -0
  212. package/dist/replay/describe.js +31 -0
  213. package/dist/replay/gemini-turns.d.ts +36 -0
  214. package/dist/replay/gemini-turns.js +192 -0
  215. package/dist/replay/machine.d.ts +34 -0
  216. package/dist/replay/machine.js +68 -0
  217. package/dist/replay/progress-event.d.ts +21 -0
  218. package/dist/replay/progress-event.js +45 -0
  219. package/dist/replay/replay-runner.d.ts +60 -0
  220. package/dist/replay/replay-runner.js +581 -0
  221. package/dist/replay/replay-scan.d.ts +84 -0
  222. package/dist/replay/replay-scan.js +182 -0
  223. package/dist/replay/replay-state.d.ts +108 -0
  224. package/dist/replay/replay-state.js +199 -0
  225. package/dist/replay/resume.d.ts +18 -0
  226. package/dist/replay/resume.js +34 -0
  227. package/dist/replay/start.d.ts +23 -0
  228. package/dist/replay/start.js +39 -0
  229. package/dist/replay/throttle.d.ts +36 -0
  230. package/dist/replay/throttle.js +44 -0
  231. package/dist/replay/transcript-turns.d.ts +35 -0
  232. package/dist/replay/transcript-turns.js +241 -0
  233. package/dist/replay/turn-event.d.ts +40 -0
  234. package/dist/replay/turn-event.js +127 -0
  235. package/dist/replay/types/replay.types.d.ts +198 -0
  236. package/dist/replay/types/replay.types.js +1 -0
  237. package/dist/replay/window.d.ts +28 -0
  238. package/dist/replay/window.js +41 -0
  239. package/dist/replay/worktree-map.d.ts +42 -0
  240. package/dist/replay/worktree-map.js +134 -0
  241. package/dist/snapshot/branch-selection.d.ts +40 -23
  242. package/dist/snapshot/branch-selection.js +71 -41
  243. package/dist/snapshot/constants/snapshot-stages.constants.d.ts +3 -1
  244. package/dist/snapshot/constants/snapshot-stages.constants.js +3 -1
  245. package/dist/snapshot/constants/snapshot.constants.d.ts +34 -7
  246. package/dist/snapshot/constants/snapshot.constants.js +34 -7
  247. package/dist/snapshot/index.d.ts +2 -2
  248. package/dist/snapshot/index.js +1 -1
  249. package/dist/snapshot/snapshot-pipeline.js +100 -26
  250. package/dist/snapshot/snapshot-state.js +6 -2
  251. package/dist/snapshot/tree-pipeline.d.ts +1 -1
  252. package/dist/snapshot/tree-pipeline.js +34 -15
  253. package/dist/snapshot/types/snapshot.types.d.ts +22 -3
  254. package/dist/storage/schemas/storage.schema.d.ts +2 -0
  255. package/dist/storage/schemas/storage.schema.js +6 -0
  256. package/dist/transport/delivery-stats.d.ts +13 -1
  257. package/dist/transport/delivery-stats.js +18 -2
  258. package/dist/transport/delivery.d.ts +4 -3
  259. package/dist/transport/delivery.js +21 -7
  260. package/dist/transport/identity-delivery.d.ts +20 -0
  261. package/dist/transport/identity-delivery.js +41 -0
  262. package/dist/transport/index.d.ts +2 -0
  263. package/dist/transport/index.js +1 -0
  264. package/dist/transport/types/delivery-flow.types.d.ts +7 -0
  265. package/dist/turns/claude-transcript.js +4 -12
  266. package/dist/turns/codex-transcript.d.ts +9 -0
  267. package/dist/turns/codex-transcript.js +27 -19
  268. package/dist/turns/constants/turns.constants.d.ts +29 -12
  269. package/dist/turns/constants/turns.constants.js +31 -19
  270. package/dist/turns/gemini-transcript.d.ts +19 -1
  271. package/dist/turns/gemini-transcript.js +29 -18
  272. package/dist/turns/index.d.ts +3 -4
  273. package/dist/turns/index.js +2 -3
  274. package/dist/turns/run-state.d.ts +71 -0
  275. package/dist/turns/run-state.js +114 -0
  276. package/dist/turns/tool-events.d.ts +11 -1
  277. package/dist/turns/tool-events.js +32 -9
  278. package/dist/turns/transcript.d.ts +15 -14
  279. package/dist/turns/transcript.js +23 -4
  280. package/dist/turns/turn-state.d.ts +82 -7
  281. package/dist/turns/turn-state.js +157 -10
  282. package/dist/turns/turn-summary.js +7 -2
  283. package/dist/turns/turn-tracker.d.ts +9 -16
  284. package/dist/turns/turn-tracker.js +163 -87
  285. package/dist/turns/types/transcript.types.d.ts +11 -1
  286. package/dist/turns/types/turn-provider.types.d.ts +33 -0
  287. package/dist/turns/types/turn-provider.types.js +1 -0
  288. package/dist/turns/types/turn-state.types.d.ts +9 -0
  289. package/dist/turns/types/turn-summary.types.d.ts +17 -1
  290. package/dist/turns/types/turn-tracker.types.d.ts +3 -1
  291. package/dist/turns/work-checkout.js +1 -2
  292. package/docs/AUDIT_PROMPT.md +10 -0
  293. package/docs/DATA_HANDLING.md +201 -13
  294. package/docs/ENTERPRISE_DEPLOYMENT.md +3 -3
  295. package/docs/PERFORMANCE.md +10 -0
  296. package/package.json +3 -2
  297. package/dist/events/canonical-event.d.ts +0 -10
  298. package/dist/events/canonical-event.js +0 -9
  299. package/dist/git/repository-root.d.ts +0 -39
  300. package/dist/git/repository-root.js +0 -131
  301. package/dist/git/types/repository-root.types.d.ts +0 -11
  302. package/dist/transport/transport.d.ts +0 -6
  303. package/dist/turns/codex-originator.d.ts +0 -11
  304. package/dist/turns/cursor-transcript.d.ts +0 -21
  305. package/dist/turns/cursor-transcript.js +0 -66
  306. package/dist/turns/native-session-titles.d.ts +0 -26
  307. package/dist/turns/native-session-titles.js +0 -102
  308. /package/dist/{git/types/repository-root.types.js → billing/types/billing.types.js} +0 -0
  309. /package/dist/{transport/transport.js → capture/types/capture.types.js} +0 -0
@@ -1,7 +1,10 @@
1
1
  import fs from 'node:fs/promises';
2
- import { providerIds, providers } from '../providers/registry.js';
2
+ import path from 'node:path';
3
+ import { VENV_LOADER_FILE, VENV_RECORDS_DIR } from '../capture/constants/capture.constants.js';
4
+ import { providers } from '../providers/registry.js';
3
5
  import { saveInstallState } from '../storage/install-state.js';
4
6
  import { uninstalledFile } from '../storage/uninstalled.js';
7
+ import { removeVenvLoaders } from '../capture/venv-loader.js';
5
8
  import { forgetDeviceCredentials } from '../credentials/credentials.js';
6
9
  import { buildCliContext, buildHookCommand } from './context.js';
7
10
  import { SETUP_EXCHANGE_TIMEOUT_MS } from './constants/cli.constants.js';
@@ -20,14 +23,14 @@ export async function runUninstall(options) {
20
23
  const context = await buildCliContext(options.env);
21
24
  println(bold('AgentWatch Uninstall'));
22
25
  println();
23
- const targets = resolveTargets(options.agent);
24
- if (!targets) {
25
- println(`${symbols.fail} unknown agent "${options.agent}" (known: ${providerIds.join(', ')})`);
26
+ const wholeInstall = options.agents === undefined;
27
+ if (options.purge && !wholeInstall) {
28
+ println(`${symbols.fail} --purge removes every agent and the local data; run it without --agent. Nothing was removed`);
26
29
  return 1;
27
30
  }
28
31
  let installState = context.installState;
29
32
  let failures = 0;
30
- for (const provider of targets) {
33
+ for (const provider of options.agents ?? providers) {
31
34
  println(bold(provider.displayName));
32
35
  const setupContext = {
33
36
  env: options.env,
@@ -49,12 +52,25 @@ export async function runUninstall(options) {
49
52
  println();
50
53
  }
51
54
  await saveInstallState(context.paths, installState);
55
+ // The loaders `python -I` runs come in through: harmless once the hooks are gone, but not ours to leave.
56
+ let loadersLeft = 0;
57
+ if (wholeInstall) {
58
+ const loaders = await removeVenvLoaders(context.paths.dataDir);
59
+ loadersLeft = loaders.left.length;
60
+ for (const folder of loaders.removed) {
61
+ println(`${symbols.ok} run capture loader removed from ${folder}`);
62
+ }
63
+ for (const folder of loaders.left) {
64
+ println(`${symbols.fail} could not remove ${path.join(folder, VENV_LOADER_FILE)}; delete it by hand`);
65
+ failures++;
66
+ }
67
+ }
52
68
  // The whole install, not one agent: the device is switched off on the
53
69
  // platform and its secret goes with it, so a reinstall enrolls again rather
54
70
  // than finding a credential nobody chose to keep. The network never fails
55
71
  // uninstall; a credential left live is said, with who can switch it off. A
56
72
  // config that could not be updated is a failure: nothing was revoked.
57
- if (!options.agent) {
73
+ if (wholeInstall) {
58
74
  const forgotten = await forgetDeviceCredentials({ env: options.env, paths: context.paths, timeoutMs: SETUP_EXCHANGE_TIMEOUT_MS });
59
75
  if (!forgotten.marked)
60
76
  println(`${symbols.warn} could not record the uninstall in ${uninstalledFile(context.paths)}; a later run may enroll this machine again`);
@@ -66,30 +82,18 @@ export async function runUninstall(options) {
66
82
  println(revocationLine(revocation));
67
83
  }
68
84
  }
69
- if (options.purge && !options.agent) {
70
- await fs.rm(context.paths.dataDir, { recursive: true, force: true });
85
+ if (options.purge) {
86
+ await purgeDataDir(context.paths.dataDir, loadersLeft > 0);
71
87
  await fs.rm(context.paths.configDir, { recursive: true, force: true });
72
88
  println(`${symbols.ok} local configuration and queued data removed`);
89
+ if (loadersLeft > 0)
90
+ println(`run capture records kept in ${path.join(context.paths.dataDir, VENV_RECORDS_DIR)}, so a re-run can remove those loaders`);
73
91
  }
74
- if (!options.purge || options.agent) {
92
+ if (!options.purge) {
75
93
  println(`local config kept at ${context.paths.configFile} (use --purge to remove)`);
76
94
  }
77
95
  return failures === 0 ? 0 : 1;
78
96
  }
79
- /**
80
- * Which providers this run touches.
81
- *
82
- * @param agent - Value of `--agent`, when given.
83
- * @returns The providers, or undefined when the named agent is unknown.
84
- */
85
- function resolveTargets(agent) {
86
- if (!agent)
87
- return providers;
88
- // This command already holds the eager list, so it names the one it wants
89
- // rather than loading a sixth copy of it.
90
- const provider = providers.find((candidate) => candidate.id === agent);
91
- return provider ? [provider] : undefined;
92
- }
93
97
  /**
94
98
  * Print an outcome and carry its install state forward.
95
99
  *
@@ -118,3 +122,18 @@ function revocationLine(revocation) {
118
122
  const where = revocation.removed ? 'removed from this machine but still active on the platform' : 'still active on the platform and still on this machine';
119
123
  return `${symbols.warn} device credential ${where} (${revocation.reason}); an admin can revoke this machine in Settings → Install${leftover}`;
120
124
  }
125
+ /**
126
+ * Remove the data dir, all of it or all but the venv loader records: those are how a
127
+ * re-run finds the loaders this one could not remove.
128
+ *
129
+ * @param dataDir - The data dir.
130
+ * @param keepRecords - Whether a loader was left behind.
131
+ */
132
+ async function purgeDataDir(dataDir, keepRecords) {
133
+ if (!keepRecords) {
134
+ await fs.rm(dataDir, { recursive: true, force: true });
135
+ return;
136
+ }
137
+ const names = await fs.readdir(dataDir).catch(() => []);
138
+ await Promise.all(names.filter((name) => name !== VENV_RECORDS_DIR).map((name) => fs.rm(path.join(dataDir, name), { recursive: true, force: true })));
139
+ }
@@ -5,6 +5,7 @@ import process from 'node:process';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  import { resolvePaths } from '../storage/paths.js';
7
7
  import { installedPackage, isNewer, refreshLatest } from '../update/update-check.js';
8
+ import { npmGlobalRoot } from './npm-global.js';
8
9
  import { printErrln, println, symbols } from './ui.js';
9
10
  /**
10
11
  * `agentwatch update [--check]` — install the latest release from npm.
@@ -64,8 +65,8 @@ export async function runUpdate(env, checkOnly) {
64
65
  * @returns The real path, or undefined when npm has none or cannot say.
65
66
  */
66
67
  function npmGlobalCopy(name, shell) {
67
- const globalRoot = spawnSync('npm', ['root', '-g'], { encoding: 'utf8', shell }).stdout?.trim();
68
- if (!globalRoot || !path.isAbsolute(globalRoot))
68
+ const globalRoot = npmGlobalRoot(process.env, shell);
69
+ if (!globalRoot)
69
70
  return undefined;
70
71
  try {
71
72
  return realpathSync(path.join(globalRoot, name));
package/dist/cli.js CHANGED
@@ -6,11 +6,15 @@ import { setVerbose } from './core/logger.js';
6
6
  // Parsing lives in its own module so tests can import it without executing
7
7
  // main(); command modules stay lazily loaded off the hook critical path.
8
8
  import { boolFlag, parseArgs, stringFlag, valuelessFlags } from './cli/args.js';
9
+ import { AGENT_COMMANDS } from './cli/constants/cli.constants.js';
10
+ import { providerIds } from './providers/loaders.js';
9
11
  const HELP = `agentwatch — telemetry edge for AI coding agents
10
12
 
11
13
  Usage:
12
- agentwatch setup [enrollment-url] [--endpoint <url>] [--allow-custom-endpoint] [--no-browser] [--enrollment-code -] [--token <token>] [--developer-email <email>] [--developer-name <name>] [--root <path>] [--otel <signals>]
14
+ agentwatch setup [enrollment-url] [--endpoint <url>] [--allow-custom-endpoint] [--no-browser] [--enrollment-code -] [--token <token>] [--developer-email <email>] [--developer-name <name>] [--root <path>] [--otel <signals>] [--replay-days <n>] [--no-replay] [--agent <id>]
15
+ agentwatch setup --cloud (a Claude Code cloud session's managed SessionStart hook)
13
16
  agentwatch status
17
+ agentwatch replay [--machine | --root <path>] [--replay-days <n>] [--resume | --stop] [--dry-run]
14
18
  agentwatch off
15
19
  agentwatch on
16
20
  agentwatch doctor [--json]
@@ -40,10 +44,11 @@ Flags:
40
44
  --developer-name <name> what to call this developer in the platform's views (default:
41
45
  git config user.name). Never an identity: nothing is keyed on it,
42
46
  and leaving it unset keeps whatever name the platform already has
43
- --root <path> file this tenant's identity under a project root instead of the
44
- machine default, so one machine can report to two tenants: work
47
+ --root <path> with setup or replay, use the identity under this project root;
48
+ setup can file a second tenant instead of the machine default: work
45
49
  at or below <path> uses this token, everything else keeps the
46
50
  machine's own. Longest matching root wins
51
+ --machine with replay, use the machine identity regardless of this directory
47
52
  --otel <signals> native OTLP signals agents export to the backend: comma list of
48
53
  logs,traces,metrics, or "all"/"none" (default: logs — the
49
54
  per-request usage/cost ledger the backend turns into llm.call)
@@ -52,7 +57,17 @@ Flags:
52
57
  developer runs \`agentwatch setup\` and signs in as themselves.
53
58
  A machine with no device and an enrollment code redeems the
54
59
  code now instead
55
- --agent <id> limit the command to one agent (claude | codex | cursor)
60
+ --cloud setup, in a Claude Code cloud session ($CLAUDE_CODE_REMOTE=true) with no
61
+ credential: claim a device with the organization's managed settings
62
+ ($AGENTWATCH_CLOUD_ORGANIZATION, $AGENTWATCH_CLOUD_KEY) for the Claude
63
+ account's email. Does nothing anywhere else; always exits 0
64
+ --replay-days <n> setup, replay: how many days of earlier Claude Code sessions to send in the
65
+ background (default 30, never before the open charge period). Metadata only:
66
+ what the hooks send for a turn. See docs/DATA_HANDLING.md
67
+ --no-replay setup: do not replay earlier Claude Code sessions
68
+ --resume, --stop replay: carry on an unfinished replay, or end it
69
+ --agent <id> ${[...AGENT_COMMANDS].join(', ')}: limit the command to one agent
70
+ (${providerIds.join(' | ')})
56
71
  --purge uninstall: also delete ~/.agentwatch and queued local data
57
72
  --dry-run hook: print resulting events to stdout instead of sending
58
73
  --json doctor: machine-readable output
@@ -89,6 +104,26 @@ async function main() {
89
104
  process.stdout.write(HELP);
90
105
  return 0;
91
106
  }
107
+ // No command, or `help`, prints the help; a hook's argv is the agent's.
108
+ const checksFlags = parsed.command !== undefined && parsed.command !== 'help' && parsed.command !== 'hook' && parsed.command !== 'refresh-credential';
109
+ // A cloud session's SessionStart hook: every path exits 0, so Agent Watch never fails the session.
110
+ const cloud = parsed.command === 'setup' && boolFlag(parsed, 'cloud');
111
+ const valueless = valuelessFlags(parsed);
112
+ // Status always exits 0, so scripts can rely on it: a flag it does not take is named and ignored.
113
+ const lenient = parsed.command === 'status';
114
+ const ignored = lenient ? '; ignored' : '';
115
+ // `--endpoint --token KEY` would read the endpoint as absent, and a bare `--agent` as every agent.
116
+ if (checksFlags && valueless.length > 0) {
117
+ process.stderr.write(`agentwatch ${parsed.command}: ${valueless.map((name) => `--${name}`).join(', ')} needs a value${ignored}\n`);
118
+ if (!lenient)
119
+ return cloud ? 0 : 1;
120
+ }
121
+ // `off --agent cursor` used to switch every agent off: a flag a command does not take is refused, never ignored.
122
+ if (checksFlags && parsed.flags['agent'] !== undefined && !AGENT_COMMANDS.has(parsed.command ?? '')) {
123
+ process.stderr.write(`agentwatch ${parsed.command}: --agent is not supported here; only ${[...AGENT_COMMANDS].join(', ')} take it${ignored}\n`);
124
+ if (!lenient)
125
+ return 1;
126
+ }
92
127
  const env = realEnv();
93
128
  switch (parsed.command) {
94
129
  case 'off':
@@ -97,21 +132,31 @@ async function main() {
97
132
  return runToggle(env, parsed.command === 'on');
98
133
  }
99
134
  case 'hook': {
100
- const { runHook } = await import('./cli/hook.js');
101
- return runHook(stringFlag(parsed, 'agent') ?? '', { env, dryRun: boolFlag(parsed, 'dry-run') });
135
+ const { handOffDetached, runHook } = await import('./cli/hook.js');
136
+ // `--attached` is the detached child a turn close was handed to; it processes in place.
137
+ const handOff = boolFlag(parsed, 'attached') || boolFlag(parsed, 'dry-run') ? undefined : handOffDetached;
138
+ return runHook(stringFlag(parsed, 'agent') ?? '', { env, dryRun: boolFlag(parsed, 'dry-run'), handOff });
102
139
  }
103
140
  case 'setup': {
104
- const valueless = valuelessFlags(parsed);
105
- if (valueless.length > 0) {
106
- process.stderr.write(`agentwatch setup: ${valueless.map((name) => `--${name}`).join(', ')} needs a value\n`);
107
- return 1;
108
- }
141
+ // Before the npx hand-off, so an unknown id installs nothing globally either.
142
+ const selected = await selectedAgents(parsed);
143
+ if (!selected)
144
+ return cloud ? 0 : 1;
109
145
  const { installGloballyAndHandOff, isNpxRun } = await import('./cli/npx-install.js');
110
- if (isNpxRun(process.argv[1], process.env))
111
- return installGloballyAndHandOff(process.argv.slice(2));
146
+ if (isNpxRun(process.argv[1], process.env)) {
147
+ // The managed hook runs `npx … setup --cloud` on every start and resume: a VM that already has its device skips the global install.
148
+ if (cloud) {
149
+ const [{ loadConfig }, { resolvePaths }, { hasCredential }] = await Promise.all([import('./config/config-store.js'), import('./storage/paths.js'), import('./credentials/identity.js')]);
150
+ if (hasCredential((await loadConfig(resolvePaths(env))).config))
151
+ return 0;
152
+ }
153
+ const handedOff = await installGloballyAndHandOff(process.argv.slice(2));
154
+ return cloud ? 0 : handedOff;
155
+ }
112
156
  const { runSetup } = await import('./cli/setup.js');
113
157
  return runSetup({
114
158
  env,
159
+ cloud,
115
160
  setupUrl: parsed.positional[0],
116
161
  endpoint: stringFlag(parsed, 'endpoint'),
117
162
  allowCustomEndpoint: boolFlag(parsed, 'allow-custom-endpoint'),
@@ -122,20 +167,44 @@ async function main() {
122
167
  developerName: stringFlag(parsed, 'developer-name'),
123
168
  root: stringFlag(parsed, 'root'),
124
169
  otel: stringFlag(parsed, 'otel'),
125
- deferSignIn: boolFlag(parsed, 'defer-sign-in')
170
+ agents: selected.agents,
171
+ deferSignIn: boolFlag(parsed, 'defer-sign-in'),
172
+ replayDays: stringFlag(parsed, 'replay-days'),
173
+ noReplay: boolFlag(parsed, 'no-replay')
126
174
  });
127
175
  }
128
176
  case 'status': {
129
177
  const { runStatus } = await import('./cli/status.js');
130
178
  return runStatus(env);
131
179
  }
180
+ case 'replay': {
181
+ const { runWithSmallHeap } = await import('./replay/start.js');
182
+ const rerun = runWithSmallHeap(process.argv.slice(2));
183
+ if (rerun !== undefined)
184
+ return rerun;
185
+ const { runReplayCommand } = await import('./cli/replay.js');
186
+ return runReplayCommand({
187
+ env,
188
+ machine: boolFlag(parsed, 'machine'),
189
+ root: stringFlag(parsed, 'root'),
190
+ days: stringFlag(parsed, 'replay-days'),
191
+ resume: boolFlag(parsed, 'resume'),
192
+ stop: boolFlag(parsed, 'stop'),
193
+ dryRun: boolFlag(parsed, 'dry-run'),
194
+ claimAutomatic: boolFlag(parsed, 'claim-automatic'),
195
+ skipIfExisting: boolFlag(parsed, 'skip-if-existing')
196
+ });
197
+ }
132
198
  case 'doctor': {
133
199
  const { runDoctor } = await import('./cli/doctor.js');
134
200
  return runDoctor(env, { json: boolFlag(parsed, 'json') });
135
201
  }
136
202
  case 'uninstall': {
203
+ const selected = await selectedAgents(parsed);
204
+ if (!selected)
205
+ return 1;
137
206
  const { runUninstall } = await import('./cli/uninstall.js');
138
- return runUninstall({ env, agent: stringFlag(parsed, 'agent'), purge: boolFlag(parsed, 'purge') });
207
+ return runUninstall({ env, agents: selected.agents, purge: boolFlag(parsed, 'purge') });
139
208
  }
140
209
  case 'update': {
141
210
  const { runUpdate } = await import('./cli/update.js');
@@ -162,6 +231,24 @@ async function main() {
162
231
  return runFallback(parsed);
163
232
  }
164
233
  }
234
+ /**
235
+ * The agents `--agent` selects for setup or uninstall, refused on stderr when it names none.
236
+ *
237
+ * @param parsed - Parsed arguments; a bare `--agent` was already refused as valueless.
238
+ * @returns The selected providers (none without the flag), or undefined once the refusal is printed.
239
+ */
240
+ async function selectedAgents(parsed) {
241
+ const agent = stringFlag(parsed, 'agent');
242
+ if (agent === undefined)
243
+ return {};
244
+ const { selectProviders } = await import('./providers/registry.js');
245
+ const selected = selectProviders(agent);
246
+ if ('error' in selected) {
247
+ process.stderr.write(`agentwatch ${parsed.command}: ${selected.error}\n`);
248
+ return undefined;
249
+ }
250
+ return { agents: selected.providers };
251
+ }
165
252
  /**
166
253
  * Handle `--version`, `help`, and an unrecognized command.
167
254
  *
@@ -217,6 +304,6 @@ async function exitAfterFlush(code) {
217
304
  }
218
305
  main().then((code) => exitAfterFlush(code), (error) => {
219
306
  process.stderr.write(`[agentwatch] fatal: ${error.stack ?? error}\n`);
220
- // A crashing hook must not break the calling agent.
221
- return exitAfterFlush(process.argv[2] === 'hook' ? 0 : 1);
307
+ // A crashing hook, or a cloud session's setup, must not break the calling agent.
308
+ return exitAfterFlush(process.argv[2] === 'hook' || (process.argv[2] === 'setup' && process.argv.includes('--cloud')) ? 0 : 1);
222
309
  });
@@ -42,10 +42,9 @@ export declare function updateConfig(paths: AgentWatchPaths, change: (current: C
42
42
  readonly now?: () => Date;
43
43
  }): Promise<'saved' | 'unchanged' | 'busy'>;
44
44
  /**
45
- * Record the device an install key was exchanged for, beside that key,
46
- * wherever the file holds it: the machine entry and every root sharing it.
47
- *
48
- * The key stays, to enroll again when the device secret expires.
45
+ * Record the device an install key was exchanged for wherever the file holds
46
+ * that key, or a device of the same id whose key already left the file (an
47
+ * expired secret enrolled again): the machine entry and every root sharing it.
49
48
  *
50
49
  * @param paths - Resolved AgentWatch paths.
51
50
  * @param installKey - The key that was exchanged.
@@ -54,6 +53,18 @@ export declare function updateConfig(paths: AgentWatchPaths, change: (current: C
54
53
  * @returns What {@link updateConfig} did.
55
54
  */
56
55
  export declare function attachDevice(paths: AgentWatchPaths, installKey: string, device: DeviceCredentialRef, waitMs: number): Promise<'saved' | 'unchanged' | 'busy'>;
56
+ /**
57
+ * Take an install key out of every entry that already names the device it was
58
+ * exchanged for. The caller has put the key in that device's secret store
59
+ * first, so it is still there to enroll again when the secret expires.
60
+ *
61
+ * @param paths - Resolved AgentWatch paths.
62
+ * @param installKey - The key to remove.
63
+ * @param deviceId - The device it was exchanged for.
64
+ * @param waitMs - How long to wait for the config lock.
65
+ * @returns What {@link updateConfig} did.
66
+ */
67
+ export declare function detachInstallKey(paths: AgentWatchPaths, installKey: string, deviceId: string, waitMs: number): Promise<'saved' | 'unchanged' | 'busy'>;
57
68
  /**
58
69
  * A config about to be written, with the devices the file on disk already
59
70
  * holds for its install keys laid back in.
@@ -121,10 +121,9 @@ export async function updateConfig(paths, change, options = {}) {
121
121
  }
122
122
  }
123
123
  /**
124
- * Record the device an install key was exchanged for, beside that key,
125
- * wherever the file holds it: the machine entry and every root sharing it.
126
- *
127
- * The key stays, to enroll again when the device secret expires.
124
+ * Record the device an install key was exchanged for wherever the file holds
125
+ * that key, or a device of the same id whose key already left the file (an
126
+ * expired secret enrolled again): the machine entry and every root sharing it.
128
127
  *
129
128
  * @param paths - Resolved AgentWatch paths.
130
129
  * @param installKey - The key that was exchanged.
@@ -133,12 +132,37 @@ export async function updateConfig(paths, change, options = {}) {
133
132
  * @returns What {@link updateConfig} did.
134
133
  */
135
134
  export async function attachDevice(paths, installKey, device, waitMs) {
135
+ const holdsKey = (entry) => entry.token === installKey || (entry.token === undefined && entry.device?.id === device.id);
136
+ return updateEntries(paths, (entry) => (holdsKey(entry) ? { ...entry, device } : entry), waitMs);
137
+ }
138
+ /**
139
+ * Take an install key out of every entry that already names the device it was
140
+ * exchanged for. The caller has put the key in that device's secret store
141
+ * first, so it is still there to enroll again when the secret expires.
142
+ *
143
+ * @param paths - Resolved AgentWatch paths.
144
+ * @param installKey - The key to remove.
145
+ * @param deviceId - The device it was exchanged for.
146
+ * @param waitMs - How long to wait for the config lock.
147
+ * @returns What {@link updateConfig} did.
148
+ */
149
+ export async function detachInstallKey(paths, installKey, deviceId, waitMs) {
150
+ return updateEntries(paths, (entry) => (entry.token === installKey && entry.device?.id === deviceId ? { ...entry, token: undefined } : entry), waitMs);
151
+ }
152
+ /**
153
+ * Apply one change to the machine entry and to every root, under the config lock.
154
+ *
155
+ * @param paths - Resolved AgentWatch paths.
156
+ * @param change - What to do to one entry's credential fields.
157
+ * @param waitMs - How long to wait for the config lock.
158
+ * @returns What {@link updateConfig} did.
159
+ */
160
+ async function updateEntries(paths, change, waitMs) {
136
161
  return updateConfig(paths, (loaded) => {
137
162
  if (loaded.state !== 'ok')
138
163
  return undefined;
139
- const attach = (entry) => (entry.token === installKey ? { ...entry, device } : entry);
140
- const roots = loaded.config.roots ? Object.fromEntries(Object.entries(loaded.config.roots).map(([key, root]) => [key, attach(root)])) : undefined;
141
- const next = { ...attach(loaded.config), ...(roots ? { roots } : {}) };
164
+ const roots = loaded.config.roots ? Object.fromEntries(Object.entries(loaded.config.roots).map(([key, root]) => [key, change(root)])) : undefined;
165
+ const next = { ...change(loaded.config), ...(roots ? { roots } : {}) };
142
166
  return JSON.stringify(next) === JSON.stringify(loaded.config) ? undefined : next;
143
167
  }, { waitMs });
144
168
  }
@@ -1,6 +1,4 @@
1
1
  import type { AgentWatchConfig, OtelConfig, OtelSignalName } from './types/config.types.js';
2
- export { captureSchema, configSchema, deliverySchema, emitSchema, enforcementSchema, otelSchema } from './schemas/config.schema.js';
3
- export type { AgentWatchConfig, CaptureConfig, EnforcementConfig, OtelConfig, OtelSignalName } from './types/config.types.js';
4
2
  /**
5
3
  * The configuration a deliberate `agentwatch setup` writes: metadata only.
6
4
  *
@@ -1,6 +1,5 @@
1
1
  import { ENFORCEMENT_PATH, EVENTS_PATH, OTEL_ALL, OTEL_NONE, OTEL_SIGNAL_NAMES, OTEL_SIGNAL_NAME_SET, OTLP_BASE_PATH, RE_TRAILING_SLASHES } from './constants/config.constants.js';
2
2
  import { configSchema } from './schemas/config.schema.js';
3
- export { captureSchema, configSchema, deliverySchema, emitSchema, enforcementSchema, otelSchema } from './schemas/config.schema.js';
4
3
  /**
5
4
  * The configuration a deliberate `agentwatch setup` writes: metadata only.
6
5
  *
@@ -14,7 +14,14 @@ export declare const DEFAULT_MAX_EVENT_AGE_DAYS = 7;
14
14
  * `cache_ttl_ms` and the ceiling on any advice it does give, so it is the one
15
15
  * number on the path no platform change can shorten.
16
16
  */
17
- export declare const DEFAULT_ENFORCEMENT_TIMEOUT_MS = 300;
17
+ export declare const DEFAULT_ENFORCEMENT_TIMEOUT_MS = 500;
18
+ /**
19
+ * The default before 500, still written into every config saved by an earlier
20
+ * version: setup saves the parsed config, defaults included. 300 ms is about the
21
+ * whole round trip from outside the US (~190 ms to reach the gateway, ~105 ms
22
+ * inside it), so roughly half the asks failed open (2026-11-14).
23
+ */
24
+ export declare const LEGACY_ENFORCEMENT_TIMEOUT_MS = 300;
18
25
  export declare const DEFAULT_ENFORCEMENT_CACHE_TTL_MS = 5000;
19
26
  /**
20
27
  * The window the product promises between a cap being crossed and the next
@@ -14,7 +14,14 @@ export const DEFAULT_MAX_EVENT_AGE_DAYS = 7;
14
14
  * `cache_ttl_ms` and the ceiling on any advice it does give, so it is the one
15
15
  * number on the path no platform change can shorten.
16
16
  */
17
- export const DEFAULT_ENFORCEMENT_TIMEOUT_MS = 300;
17
+ export const DEFAULT_ENFORCEMENT_TIMEOUT_MS = 500;
18
+ /**
19
+ * The default before 500, still written into every config saved by an earlier
20
+ * version: setup saves the parsed config, defaults included. 300 ms is about the
21
+ * whole round trip from outside the US (~190 ms to reach the gateway, ~105 ms
22
+ * inside it), so roughly half the asks failed open (2026-11-14).
23
+ */
24
+ export const LEGACY_ENFORCEMENT_TIMEOUT_MS = 300;
18
25
  export const DEFAULT_ENFORCEMENT_CACHE_TTL_MS = 5_000;
19
26
  /**
20
27
  * The window the product promises between a cap being crossed and the next
@@ -123,6 +130,8 @@ export const GLOBAL_ONLY_KEYS = new Set([
123
130
  'developerName',
124
131
  'untracedNotices',
125
132
  'updateNotices',
133
+ // Silences usage telemetry and budget caps: a developer's own choice, never a repository's.
134
+ 'ignoredRoots',
126
135
  'endpoint',
127
136
  'eventsUrl',
128
137
  'otlpUrl',
@@ -0,0 +1,15 @@
1
+ import type { EventTransport } from '../transport/types/transport.types.js';
2
+ import type { AgentWatchConfig, TransportLimits } from './types/config.types.js';
3
+ /**
4
+ * The transport for one config, when a backend is configured.
5
+ *
6
+ * Here, not in `src/transport`, because choosing the destination and reading
7
+ * the credential state are config decisions; transport sends to whatever URL
8
+ * it is given.
9
+ *
10
+ * @param config - The config whose destination, capture and installation id are sent.
11
+ * @param bearer - What to authenticate with; see `resolveBearer`.
12
+ * @param limits - Request and whole-send ceilings.
13
+ * @returns The transport, or undefined before setup has run.
14
+ */
15
+ export declare function transportFor(config: AgentWatchConfig, bearer: string | undefined, limits?: TransportLimits): EventTransport | undefined;
@@ -0,0 +1,29 @@
1
+ import { hasCredential } from '../credentials/identity.js';
2
+ import { HttpTransport } from '../transport/http-transport.js';
3
+ import { eventsUrl } from './config.js';
4
+ /**
5
+ * The transport for one config, when a backend is configured.
6
+ *
7
+ * Here, not in `src/transport`, because choosing the destination and reading
8
+ * the credential state are config decisions; transport sends to whatever URL
9
+ * it is given.
10
+ *
11
+ * @param config - The config whose destination, capture and installation id are sent.
12
+ * @param bearer - What to authenticate with; see `resolveBearer`.
13
+ * @param limits - Request and whole-send ceilings.
14
+ * @returns The transport, or undefined before setup has run.
15
+ */
16
+ export function transportFor(config, bearer, limits = {}) {
17
+ const url = eventsUrl(config);
18
+ if (!url)
19
+ return undefined;
20
+ return new HttpTransport({
21
+ eventsUrl: url,
22
+ capture: config.capture,
23
+ token: bearer,
24
+ credentialPending: hasCredential(config) && !bearer,
25
+ installationId: config.installationId,
26
+ timeoutMs: limits.timeoutMs ?? config.delivery.timeoutMs,
27
+ budgetMs: limits.budgetMs
28
+ });
29
+ }
@@ -2,7 +2,7 @@
2
2
  * What the edge is configured to do: the global file, the repository overlay
3
3
  * on top of it, and the routes derived from the endpoint.
4
4
  */
5
- export type { AgentWatchConfig, CaptureConfig, ConfigLoadResult, EffectiveConfig, MergedConfig, OtelConfig, OtelSignalName, RootedConfig, RootOverride } from './types/config.types.js';
5
+ export type { AgentWatchConfig, CaptureConfig, ConfigLoadResult, EffectiveConfig, MergedConfig, OtelConfig, OtelSignalName, RootedConfig, RootOverride, TransportLimits } from './types/config.types.js';
6
6
  export { CONTENT_CAPTURE_KEYS, OTEL_SIGNAL_NAMES, REPO_CONFIG_NAME, ROOTS_KEY } from './constants/config.constants.js';
7
7
  export { captureSchema, configSchema, deliverySchema, emitSchema, otelSchema } from './schemas/config.schema.js';
8
8
  export { defaultConfig, enabledSignalNames, eventsUrl, joinUrl, otelEnabled, otlpBaseUrl, parseOtelSignals, sharesOtlpCollector } from './config.js';
@@ -10,4 +10,5 @@ export { attachDevice, ensureInstallationId, loadConfig, saveConfig, updateConfi
10
10
  export { findRepoConfigFile, loadEffectiveConfig, mergeRepoConfig } from './repo-config.js';
11
11
  export { applyRootOverride, canonicalRoot, selectRoot, servesMultipleIdentities } from './root-config.js';
12
12
  export { normalizeEndpoint, sameEndpoint, transitionDestination } from './destination.js';
13
+ export { transportFor } from './events-transport.js';
13
14
  export type { Destination, DestinationTransition } from './types/destination.types.js';
@@ -5,3 +5,4 @@ export { attachDevice, ensureInstallationId, loadConfig, saveConfig, updateConfi
5
5
  export { findRepoConfigFile, loadEffectiveConfig, mergeRepoConfig } from './repo-config.js';
6
6
  export { applyRootOverride, canonicalRoot, selectRoot, servesMultipleIdentities } from './root-config.js';
7
7
  export { normalizeEndpoint, sameEndpoint, transitionDestination } from './destination.js';
8
+ export { transportFor } from './events-transport.js';
@@ -14,6 +14,18 @@ import type { AgentWatchConfig, RootedConfig, RootOverride } from './types/confi
14
14
  * @returns The winning root path and its overrides, or undefined.
15
15
  */
16
16
  export declare function selectRoot(roots: Readonly<Record<string, RootOverride>> | undefined, cwd: string): RootedConfig['root'];
17
+ /**
18
+ * Whether a working directory is one the developer told this machine to ignore.
19
+ *
20
+ * An entry names one directory exactly; `<dir>/**` names it and everything
21
+ * beneath it. Exact is the default because the directory people most want
22
+ * ignored is usually home, and a subtree match there would ignore every repo.
23
+ *
24
+ * @param ignored - `ignoredRoots` from the global config.
25
+ * @param cwd - Where the payload happened.
26
+ * @returns True when nothing from this directory may be captured.
27
+ */
28
+ export declare function isIgnoredRoot(ignored: readonly string[], cwd: string): boolean;
17
29
  /**
18
30
  * Whether this machine sends as more than one identity.
19
31
  *
@@ -40,6 +40,30 @@ export function selectRoot(roots, cwd) {
40
40
  // Named as configured, so `agentwatch config` shows the root the user wrote.
41
41
  return { path: path.resolve(bestKey), override: roots[bestKey] };
42
42
  }
43
+ /**
44
+ * Whether a working directory is one the developer told this machine to ignore.
45
+ *
46
+ * An entry names one directory exactly; `<dir>/**` names it and everything
47
+ * beneath it. Exact is the default because the directory people most want
48
+ * ignored is usually home, and a subtree match there would ignore every repo.
49
+ *
50
+ * @param ignored - `ignoredRoots` from the global config.
51
+ * @param cwd - Where the payload happened.
52
+ * @returns True when nothing from this directory may be captured.
53
+ */
54
+ export function isIgnoredRoot(ignored, cwd) {
55
+ const target = canonicalRoot(cwd);
56
+ return ignored.some((entry) => {
57
+ // `/**` on Windows too: people write config paths with forward slashes.
58
+ const subtree = entry.endsWith('/**') || entry.endsWith(`${path.sep}**`);
59
+ const dir = subtree ? entry.slice(0, -3) : entry;
60
+ // Relative for the same reason as `selectRoot`: nobody can predict it.
61
+ if (!path.isAbsolute(dir))
62
+ return false;
63
+ const root = canonicalRoot(dir);
64
+ return subtree ? contains(root, target) : root === target;
65
+ });
66
+ }
43
67
  /**
44
68
  * Whether this machine sends as more than one identity.
45
69
  *