@agent-watch-ai/edge 0.2.5 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. package/CHANGELOG.md +512 -0
  2. package/README.md +217 -96
  3. package/SECURITY.md +69 -0
  4. package/dist/billing/session-billing.d.ts +19 -0
  5. package/dist/billing/session-billing.js +52 -0
  6. package/dist/cli/args.d.ts +10 -0
  7. package/dist/cli/args.js +20 -0
  8. package/dist/cli/constants/cli.constants.d.ts +50 -4
  9. package/dist/cli/constants/cli.constants.js +54 -5
  10. package/dist/cli/context.d.ts +33 -2
  11. package/dist/cli/context.js +84 -14
  12. package/dist/cli/doctor.js +309 -32
  13. package/dist/cli/hook-check.d.ts +23 -0
  14. package/dist/cli/hook-check.js +114 -0
  15. package/dist/cli/hook.js +118 -7
  16. package/dist/cli/index.d.ts +3 -1
  17. package/dist/cli/index.js +3 -1
  18. package/dist/cli/misc.d.ts +11 -0
  19. package/dist/cli/misc.js +80 -4
  20. package/dist/cli/npx-install.d.ts +37 -0
  21. package/dist/cli/npx-install.js +79 -0
  22. package/dist/cli/open-browser.d.ts +39 -0
  23. package/dist/cli/open-browser.js +62 -0
  24. package/dist/cli/setup.d.ts +17 -8
  25. package/dist/cli/setup.js +439 -98
  26. package/dist/cli/status.js +82 -13
  27. package/dist/cli/toggle.d.ts +9 -0
  28. package/dist/cli/toggle.js +113 -0
  29. package/dist/cli/types/cli.types.d.ts +37 -3
  30. package/dist/cli/ui.d.ts +7 -0
  31. package/dist/cli/ui.js +10 -1
  32. package/dist/cli/uninstall.js +39 -2
  33. package/dist/cli/update.d.ts +17 -0
  34. package/dist/cli/update.js +76 -0
  35. package/dist/cli.js +100 -13
  36. package/dist/config/config-store.d.ts +57 -0
  37. package/dist/config/config-store.js +250 -12
  38. package/dist/config/config.d.ts +53 -6
  39. package/dist/config/config.js +66 -6
  40. package/dist/config/constants/config.constants.d.ts +113 -6
  41. package/dist/config/constants/config.constants.js +126 -8
  42. package/dist/config/destination.d.ts +24 -0
  43. package/dist/config/destination.js +33 -0
  44. package/dist/config/index.d.ts +7 -4
  45. package/dist/config/index.js +5 -3
  46. package/dist/config/repo-config.d.ts +11 -7
  47. package/dist/config/repo-config.js +64 -15
  48. package/dist/config/root-config.d.ts +72 -0
  49. package/dist/config/root-config.js +170 -0
  50. package/dist/config/schemas/config.schema.d.ts +721 -84
  51. package/dist/config/schemas/config.schema.js +388 -15
  52. package/dist/config/types/config.types.d.ts +15 -1
  53. package/dist/config/types/destination.types.d.ts +8 -0
  54. package/dist/core/async.d.ts +36 -0
  55. package/dist/core/async.js +68 -0
  56. package/dist/core/index.d.ts +1 -1
  57. package/dist/core/index.js +1 -1
  58. package/dist/core/object.d.ts +5 -0
  59. package/dist/core/object.js +9 -4
  60. package/dist/core/pipe.d.ts +0 -13
  61. package/dist/core/pipe.js +1 -9
  62. package/dist/core/types/core.types.d.ts +9 -0
  63. package/dist/core/types/core.types.js +0 -3
  64. package/dist/core/which.d.ts +14 -0
  65. package/dist/core/which.js +43 -3
  66. package/dist/credentials/budget.d.ts +9 -0
  67. package/dist/credentials/budget.js +16 -0
  68. package/dist/credentials/command-runner.d.ts +16 -0
  69. package/dist/credentials/command-runner.js +37 -0
  70. package/dist/credentials/constants/credentials.constants.d.ts +111 -0
  71. package/dist/credentials/constants/credentials.constants.js +112 -0
  72. package/dist/credentials/credential-status.d.ts +14 -0
  73. package/dist/credentials/credential-status.js +34 -0
  74. package/dist/credentials/credentials.d.ts +72 -0
  75. package/dist/credentials/credentials.js +253 -0
  76. package/dist/credentials/device-api.d.ts +64 -0
  77. package/dist/credentials/device-api.js +150 -0
  78. package/dist/credentials/device-state.d.ts +31 -0
  79. package/dist/credentials/device-state.js +51 -0
  80. package/dist/credentials/identity.d.ts +62 -0
  81. package/dist/credentials/identity.js +90 -0
  82. package/dist/credentials/index.d.ts +7 -0
  83. package/dist/credentials/index.js +5 -0
  84. package/dist/credentials/migration.d.ts +46 -0
  85. package/dist/credentials/migration.js +164 -0
  86. package/dist/credentials/schemas/device-api.schema.d.ts +77 -0
  87. package/dist/credentials/schemas/device-api.schema.js +33 -0
  88. package/dist/credentials/schemas/device-state.schema.d.ts +51 -0
  89. package/dist/credentials/schemas/device-state.schema.js +20 -0
  90. package/dist/credentials/secret-store.d.ts +54 -0
  91. package/dist/credentials/secret-store.js +217 -0
  92. package/dist/credentials/sign-in.d.ts +18 -0
  93. package/dist/credentials/sign-in.js +86 -0
  94. package/dist/credentials/token-refresher.d.ts +39 -0
  95. package/dist/credentials/token-refresher.js +185 -0
  96. package/dist/credentials/types/credentials.types.d.ts +195 -0
  97. package/dist/credentials/types/credentials.types.js +1 -0
  98. package/dist/enforcement/constants/enforcement.constants.d.ts +47 -1
  99. package/dist/enforcement/constants/enforcement.constants.js +56 -0
  100. package/dist/enforcement/decision-cache.d.ts +20 -1
  101. package/dist/enforcement/decision-cache.js +65 -2
  102. package/dist/enforcement/decision-client.d.ts +9 -8
  103. package/dist/enforcement/decision-client.js +62 -16
  104. package/dist/enforcement/enforcement.d.ts +23 -2
  105. package/dist/enforcement/enforcement.js +103 -15
  106. package/dist/enforcement/index.d.ts +4 -3
  107. package/dist/enforcement/index.js +3 -2
  108. package/dist/enforcement/types/enforcement.types.d.ts +64 -0
  109. package/dist/enrollment/constants/enrollment.constants.d.ts +2 -6
  110. package/dist/enrollment/constants/enrollment.constants.js +2 -6
  111. package/dist/enrollment/enrollment.d.ts +16 -0
  112. package/dist/enrollment/enrollment.js +54 -0
  113. package/dist/enrollment/index.d.ts +3 -7
  114. package/dist/enrollment/index.js +1 -1
  115. package/dist/enrollment/types/enrollment.types.d.ts +9 -13
  116. package/dist/events/constants/enrich.constants.d.ts +15 -0
  117. package/dist/events/constants/enrich.constants.js +15 -0
  118. package/dist/events/constants/events.constants.d.ts +6 -2
  119. package/dist/events/constants/events.constants.js +5 -1
  120. package/dist/events/enrich.js +92 -10
  121. package/dist/events/event-id.d.ts +0 -8
  122. package/dist/events/event-id.js +0 -10
  123. package/dist/events/index.d.ts +2 -2
  124. package/dist/events/index.js +1 -1
  125. package/dist/events/product-event.d.ts +9 -6
  126. package/dist/events/types/repo-snapshot.types.d.ts +7 -0
  127. package/dist/events/types/session-billing.types.d.ts +16 -0
  128. package/dist/events/types/session-billing.types.js +1 -0
  129. package/dist/feature/constants/feature.constants.d.ts +7 -0
  130. package/dist/feature/constants/feature.constants.js +7 -0
  131. package/dist/feature/index.d.ts +1 -1
  132. package/dist/feature/index.js +1 -1
  133. package/dist/feature/ticket-candidates.d.ts +14 -0
  134. package/dist/feature/ticket-candidates.js +26 -8
  135. package/dist/git/blob-hash.d.ts +21 -0
  136. package/dist/git/blob-hash.js +69 -0
  137. package/dist/git/checkout-root.d.ts +27 -0
  138. package/dist/git/checkout-root.js +75 -0
  139. package/dist/git/constants/git.constants.d.ts +160 -0
  140. package/dist/git/constants/git.constants.js +181 -0
  141. package/dist/git/fingerprint.d.ts +74 -0
  142. package/dist/git/fingerprint.js +219 -0
  143. package/dist/git/gate-checkout.d.ts +44 -0
  144. package/dist/git/gate-checkout.js +201 -0
  145. package/dist/git/git-context.d.ts +45 -0
  146. package/dist/git/git-context.js +61 -3
  147. package/dist/git/index.d.ts +4 -2
  148. package/dist/git/index.js +2 -1
  149. package/dist/git/manifest-repository.d.ts +13 -0
  150. package/dist/git/manifest-repository.js +92 -0
  151. package/dist/git/repo-snapshot.d.ts +29 -3
  152. package/dist/git/repo-snapshot.js +110 -7
  153. package/dist/git/repository-root.d.ts +39 -0
  154. package/dist/git/repository-root.js +131 -0
  155. package/dist/git/types/git.types.d.ts +55 -0
  156. package/dist/git/types/repository-root.types.d.ts +11 -0
  157. package/dist/git/types/repository-root.types.js +1 -0
  158. package/dist/git/types/snapshot.types.d.ts +9 -0
  159. package/dist/pipeline/constants/pipeline.constants.d.ts +7 -0
  160. package/dist/pipeline/constants/pipeline.constants.js +7 -0
  161. package/dist/pipeline/hook-pipeline.js +360 -32
  162. package/dist/pipeline/types/pipeline.types.d.ts +39 -4
  163. package/dist/privacy/constants/privacy.constants.js +15 -1
  164. package/dist/privacy/index.d.ts +1 -0
  165. package/dist/privacy/index.js +1 -0
  166. package/dist/privacy/product-capture.d.ts +12 -0
  167. package/dist/privacy/product-capture.js +73 -0
  168. package/dist/privacy/sanitizer.d.ts +21 -3
  169. package/dist/privacy/sanitizer.js +52 -8
  170. package/dist/process/ancestors.d.ts +39 -0
  171. package/dist/process/ancestors.js +121 -0
  172. package/dist/process/constants/process.constants.d.ts +34 -0
  173. package/dist/process/constants/process.constants.js +34 -0
  174. package/dist/process/index.d.ts +7 -0
  175. package/dist/process/index.js +2 -0
  176. package/dist/process/types/process.types.d.ts +23 -0
  177. package/dist/process/types/process.types.js +1 -0
  178. package/dist/providers/antigravity/antigravity.adapter.d.ts +12 -1
  179. package/dist/providers/antigravity/antigravity.adapter.js +21 -3
  180. package/dist/providers/antigravity/antigravity.detect.d.ts +0 -9
  181. package/dist/providers/antigravity/antigravity.detect.js +1 -1
  182. package/dist/providers/antigravity/antigravity.provider.js +3 -2
  183. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +2 -0
  184. package/dist/providers/antigravity/constants/antigravity.constants.js +2 -0
  185. package/dist/providers/claude/claude.adapter.d.ts +11 -1
  186. package/dist/providers/claude/claude.adapter.js +26 -5
  187. package/dist/providers/claude/claude.otel.d.ts +32 -18
  188. package/dist/providers/claude/claude.otel.js +81 -6
  189. package/dist/providers/claude/claude.provider.js +5 -2
  190. package/dist/providers/claude/constants/claude.constants.d.ts +2 -0
  191. package/dist/providers/claude/constants/claude.constants.js +2 -0
  192. package/dist/providers/claude/constants/claude.otel.constants.d.ts +4 -0
  193. package/dist/providers/claude/constants/claude.otel.constants.js +8 -0
  194. package/dist/providers/codex/codex.adapter.d.ts +15 -1
  195. package/dist/providers/codex/codex.adapter.js +29 -5
  196. package/dist/providers/codex/codex.otel.d.ts +24 -2
  197. package/dist/providers/codex/codex.otel.js +147 -30
  198. package/dist/providers/codex/codex.provider.js +5 -2
  199. package/dist/providers/codex/constants/codex.constants.d.ts +2 -0
  200. package/dist/providers/codex/constants/codex.constants.js +16 -0
  201. package/dist/providers/codex/constants/codex.otel.constants.d.ts +5 -0
  202. package/dist/providers/codex/constants/codex.otel.constants.js +5 -0
  203. package/dist/providers/constants/provider.constants.d.ts +0 -3
  204. package/dist/providers/constants/provider.constants.js +0 -3
  205. package/dist/providers/cursor/constants/cursor.constants.d.ts +7 -0
  206. package/dist/providers/cursor/constants/cursor.constants.js +7 -0
  207. package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
  208. package/dist/providers/cursor/cursor.adapter.js +52 -3
  209. package/dist/providers/cursor/cursor.detect.d.ts +0 -7
  210. package/dist/providers/cursor/cursor.detect.js +1 -1
  211. package/dist/providers/cursor/cursor.provider.js +5 -2
  212. package/dist/providers/gemini/constants/gemini.constants.d.ts +9 -0
  213. package/dist/providers/gemini/constants/gemini.constants.js +9 -0
  214. package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +3 -1
  215. package/dist/providers/gemini/constants/gemini.otel.constants.js +3 -0
  216. package/dist/providers/gemini/gemini.adapter.d.ts +14 -1
  217. package/dist/providers/gemini/gemini.adapter.js +25 -5
  218. package/dist/providers/gemini/gemini.detect.d.ts +0 -7
  219. package/dist/providers/gemini/gemini.detect.js +1 -1
  220. package/dist/providers/gemini/gemini.otel.d.ts +19 -20
  221. package/dist/providers/gemini/gemini.otel.js +121 -17
  222. package/dist/providers/gemini/gemini.provider.js +2 -1
  223. package/dist/providers/index.d.ts +1 -1
  224. package/dist/providers/index.js +1 -1
  225. package/dist/providers/loaders.d.ts +10 -0
  226. package/dist/providers/loaders.js +40 -0
  227. package/dist/providers/provider.d.ts +11 -0
  228. package/dist/providers/provider.js +1 -1
  229. package/dist/providers/registry.d.ts +11 -8
  230. package/dist/providers/registry.js +11 -15
  231. package/dist/providers/shared/constants/hook-refusal.constants.d.ts +7 -0
  232. package/dist/providers/shared/constants/hook-refusal.constants.js +7 -0
  233. package/dist/providers/shared/constants/shell-directories.constants.d.ts +30 -0
  234. package/dist/providers/shared/constants/shell-directories.constants.js +39 -0
  235. package/dist/providers/shared/constants/tooling.constants.d.ts +18 -2
  236. package/dist/providers/shared/constants/tooling.constants.js +19 -3
  237. package/dist/providers/shared/event-builder.d.ts +12 -14
  238. package/dist/providers/shared/event-builder.js +20 -14
  239. package/dist/providers/shared/exporter-allowlist.d.ts +20 -0
  240. package/dist/providers/shared/exporter-allowlist.js +49 -0
  241. package/dist/providers/shared/hook-config.d.ts +2 -21
  242. package/dist/providers/shared/hook-config.js +5 -4
  243. package/dist/providers/shared/hook-refusal.d.ts +12 -0
  244. package/dist/providers/shared/hook-refusal.js +17 -1
  245. package/dist/providers/shared/install-record.d.ts +12 -2
  246. package/dist/providers/shared/install-record.js +5 -2
  247. package/dist/providers/shared/shell-directories.d.ts +24 -0
  248. package/dist/providers/shared/shell-directories.js +90 -0
  249. package/dist/providers/shared/tooling.d.ts +12 -1
  250. package/dist/providers/shared/tooling.js +18 -0
  251. package/dist/providers/shared/types/adapter.types.d.ts +1 -2
  252. package/dist/providers/types/provider.types.d.ts +57 -1
  253. package/dist/snapshot/constants/snapshot.constants.d.ts +32 -0
  254. package/dist/snapshot/constants/snapshot.constants.js +33 -0
  255. package/dist/snapshot/snapshot-event.js +52 -11
  256. package/dist/snapshot/snapshot-pipeline.js +1 -1
  257. package/dist/snapshot/types/snapshot.types.d.ts +2 -0
  258. package/dist/storage/atomic-file.d.ts +7 -0
  259. package/dist/storage/atomic-file.js +1 -1
  260. package/dist/storage/constants/storage.constants.d.ts +17 -0
  261. package/dist/storage/constants/storage.constants.js +17 -0
  262. package/dist/storage/disabled.d.ts +13 -0
  263. package/dist/storage/disabled.js +24 -0
  264. package/dist/storage/index.d.ts +2 -0
  265. package/dist/storage/index.js +2 -0
  266. package/dist/storage/paths.js +3 -2
  267. package/dist/storage/schemas/storage.schema.d.ts +72 -0
  268. package/dist/storage/schemas/storage.schema.js +6 -0
  269. package/dist/storage/sweep-marker.d.ts +19 -0
  270. package/dist/storage/sweep-marker.js +55 -0
  271. package/dist/storage/types/storage.types.d.ts +2 -0
  272. package/dist/storage/uninstalled.d.ts +58 -0
  273. package/dist/storage/uninstalled.js +107 -0
  274. package/dist/transport/auth-block.d.ts +66 -0
  275. package/dist/transport/auth-block.js +129 -0
  276. package/dist/transport/constants/transport.constants.d.ts +82 -3
  277. package/dist/transport/constants/transport.constants.js +83 -4
  278. package/dist/transport/cooldown.js +8 -1
  279. package/dist/transport/delivery.d.ts +14 -6
  280. package/dist/transport/delivery.js +80 -55
  281. package/dist/transport/http-transport.d.ts +1 -0
  282. package/dist/transport/http-transport.js +52 -10
  283. package/dist/transport/index.d.ts +6 -3
  284. package/dist/transport/index.js +3 -0
  285. package/dist/transport/queue-partition.d.ts +91 -0
  286. package/dist/transport/queue-partition.js +143 -0
  287. package/dist/transport/queue.d.ts +99 -20
  288. package/dist/transport/queue.js +210 -69
  289. package/dist/transport/response-body.d.ts +25 -0
  290. package/dist/transport/response-body.js +64 -0
  291. package/dist/transport/send.d.ts +11 -0
  292. package/dist/transport/send.js +17 -0
  293. package/dist/transport/types/delivery-flow.types.d.ts +19 -0
  294. package/dist/transport/types/delivery-flow.types.js +1 -0
  295. package/dist/transport/types/transport.types.d.ts +45 -0
  296. package/dist/turns/claude-transcript.d.ts +19 -1
  297. package/dist/turns/claude-transcript.js +46 -1
  298. package/dist/turns/codex-originator.d.ts +11 -0
  299. package/dist/turns/codex-originator.js +31 -0
  300. package/dist/turns/codex-transcript.d.ts +30 -0
  301. package/dist/turns/codex-transcript.js +88 -0
  302. package/dist/turns/constants/turns.constants.d.ts +141 -5
  303. package/dist/turns/constants/turns.constants.js +155 -5
  304. package/dist/turns/file-identity.d.ts +27 -0
  305. package/dist/turns/file-identity.js +48 -0
  306. package/dist/turns/gemini-transcript.d.ts +30 -0
  307. package/dist/turns/gemini-transcript.js +96 -0
  308. package/dist/turns/index.d.ts +3 -3
  309. package/dist/turns/index.js +1 -1
  310. package/dist/turns/inherited-checkout.d.ts +54 -0
  311. package/dist/turns/inherited-checkout.js +155 -0
  312. package/dist/turns/native-session-titles.d.ts +26 -0
  313. package/dist/turns/native-session-titles.js +102 -0
  314. package/dist/turns/transcript.d.ts +3 -2
  315. package/dist/turns/transcript.js +5 -1
  316. package/dist/turns/turn-state.d.ts +224 -3
  317. package/dist/turns/turn-state.js +456 -21
  318. package/dist/turns/turn-summary.d.ts +1 -14
  319. package/dist/turns/turn-summary.js +87 -51
  320. package/dist/turns/turn-tracker.d.ts +21 -2
  321. package/dist/turns/turn-tracker.js +379 -56
  322. package/dist/turns/types/transcript.types.d.ts +5 -0
  323. package/dist/turns/types/turn-state.types.d.ts +116 -5
  324. package/dist/turns/types/turn-summary.types.d.ts +64 -14
  325. package/dist/turns/types/turn-tracker.types.d.ts +27 -1
  326. package/dist/turns/work-checkout.d.ts +65 -0
  327. package/dist/turns/work-checkout.js +666 -0
  328. package/dist/untraced/constants/untraced.constants.d.ts +31 -0
  329. package/dist/untraced/constants/untraced.constants.js +63 -0
  330. package/dist/untraced/untraced.d.ts +35 -0
  331. package/dist/untraced/untraced.js +105 -0
  332. package/dist/update/constants/update.constants.d.ts +18 -0
  333. package/dist/update/constants/update.constants.js +20 -0
  334. package/dist/update/update-check.d.ts +52 -0
  335. package/dist/update/update-check.js +113 -0
  336. package/docs/AUDIT_PROMPT.md +129 -0
  337. package/docs/DATA_HANDLING.md +648 -0
  338. package/docs/ENTERPRISE_DEPLOYMENT.md +179 -0
  339. package/docs/PERFORMANCE.md +81 -0
  340. package/package.json +14 -4
  341. package/dist/enrollment/enrollment-provider.d.ts +0 -5
  342. package/dist/enrollment/manual-enrollment.d.ts +0 -32
  343. package/dist/enrollment/manual-enrollment.js +0 -72
  344. package/example/README.md +0 -43
  345. package/example/server.mjs +0 -240
  346. /package/dist/{enrollment/enrollment-provider.js → config/types/destination.types.js} +0 -0
package/dist/cli/hook.js CHANGED
@@ -1,10 +1,16 @@
1
+ import path from 'node:path';
1
2
  import process from 'node:process';
2
3
  import { loadConfig } from '../config/config-store.js';
4
+ import { notLongerThan } from '../core/async.js';
3
5
  import { debugLog, warnLog } from '../core/logger.js';
4
6
  import { runHookPipeline } from '../pipeline/hook-pipeline.js';
5
- import { getProvider } from '../providers/registry.js';
7
+ import { loadProvider } from '../providers/loaders.js';
8
+ import { removeRefusedExporters } from '../providers/shared/exporter-allowlist.js';
9
+ import { isDisabled } from '../storage/disabled.js';
10
+ import { loadInstallState, saveInstallState } from '../storage/install-state.js';
6
11
  import { resolvePaths } from '../storage/paths.js';
7
- import { MAX_STDIN_BYTES, STDIN_TIMEOUT_MS } from './constants/cli.constants.js';
12
+ import { claimSweep } from '../storage/sweep-marker.js';
13
+ import { EXPORTER_SWEEP_BUDGET_MS, EXPORTER_SWEEP_INTERVAL_MS, EXPORTER_SWEEP_MARKER_FILE, MAX_STDIN_BYTES, STDIN_TIMEOUT_MS } from './constants/cli.constants.js';
8
14
  /**
9
15
  * The `hook` command: read stdin, run the flow, answer the agent.
10
16
  *
@@ -23,13 +29,29 @@ import { MAX_STDIN_BYTES, STDIN_TIMEOUT_MS } from './constants/cli.constants.js'
23
29
  * @returns The process exit code; always one the agent tolerates.
24
30
  */
25
31
  export async function runHook(agentId, options) {
26
- const provider = getProvider(agentId);
32
+ const provider = await loadProvider(agentId);
27
33
  if (!provider) {
28
34
  warnLog(`unknown agent "${agentId}"; passing through`);
29
35
  return 0;
30
36
  }
37
+ const disabled = await isDisabled(resolvePaths(options.env));
31
38
  const payload = await readPayload(options);
32
39
  try {
40
+ // Disabled: answer the agent and do nothing else. The payload is read but
41
+ // never parsed, enriched, queued or sent — it is read because the answer
42
+ // depends on which hook fired. Antigravity's Stop wants `stop`, its PreToolUse
43
+ // wants `allow`, and its post-tool hooks want silence; the payload-less
44
+ // fallback would send `allow` to all three.
45
+ //
46
+ // Inside the try with everything else: a provider that throws here would
47
+ // exit 0 through cli.ts having written nothing, and an Antigravity hook
48
+ // reads that empty stdout as no decision at all.
49
+ if (disabled) {
50
+ const idle = provider.getHookResponse(payload);
51
+ if (idle.stdout)
52
+ writeStdout(options, idle.stdout);
53
+ return idle.exitCode;
54
+ }
33
55
  const result = payload === undefined ? undefined : await processPayload(provider, payload, options);
34
56
  const response = respondToDecision(provider, payload, result);
35
57
  if (response.stdout)
@@ -37,8 +59,31 @@ export async function runHook(agentId, options) {
37
59
  return response.exitCode;
38
60
  }
39
61
  catch (error) {
40
- // Telemetry must never break the coding agent.
62
+ // Telemetry must never break the coding agent — but exit 0 alone is not an
63
+ // answer. Antigravity's PreToolUse and Stop hooks read stdout for the
64
+ // decision, and silence is not the passive one; try the provider's safe
65
+ // response before giving up on saying anything at all.
41
66
  debugLog('hook processing failed:', error);
67
+ return answerSafely(provider, payload, options);
68
+ }
69
+ }
70
+ /**
71
+ * Last-resort answer after something in the flow threw.
72
+ *
73
+ * @param provider - The agent's provider.
74
+ * @param payload - Decoded hook payload.
75
+ * @param options - Environment and the stdout sink.
76
+ * @returns The provider's passive exit code, or 0 when even that cannot be built.
77
+ */
78
+ function answerSafely(provider, payload, options) {
79
+ try {
80
+ const response = provider.getHookResponse(payload);
81
+ if (response.stdout)
82
+ writeStdout(options, response.stdout);
83
+ return response.exitCode;
84
+ }
85
+ catch (error) {
86
+ debugLog('hook fallback response failed:', error);
42
87
  return 0;
43
88
  }
44
89
  }
@@ -57,8 +102,10 @@ export async function runHook(agentId, options) {
57
102
  */
58
103
  function respondToDecision(provider, payload, result) {
59
104
  const message = result?.blockMessage;
60
- if (message === undefined)
61
- return provider.getHookResponse(payload);
105
+ if (message === undefined) {
106
+ const notice = result?.notice === undefined ? undefined : provider.getNoticeResponse?.(payload, result.notice);
107
+ return notice ?? provider.getHookResponse(payload);
108
+ }
62
109
  const refusal = provider.getBlockResponse?.(payload, message);
63
110
  if (!refusal)
64
111
  return provider.getHookResponse(payload);
@@ -79,18 +126,82 @@ function respondToDecision(provider, payload, result) {
79
126
  async function processPayload(provider, payload, options) {
80
127
  const paths = resolvePaths(options.env);
81
128
  const loaded = await loadConfig(paths);
129
+ // On stderr, on every hook, because this is the only place a developer ever
130
+ // sees it. A config the schema refuses degrades the runtime to `fallbackConfig`
131
+ // — no endpoint, no token — and nothing else on this path says a word, so an
132
+ // install that stopped delivering the moment someone hand-edited the file
133
+ // looked healthy until somebody thought to run `status`. `missing` is not
134
+ // warned: that is a machine before `setup`, which is not a fault.
135
+ if (loaded.state === 'invalid')
136
+ warnLog(`config ${paths.configFile} is invalid (${loaded.error}); running metadata-only with nothing configured`);
137
+ for (const warning of loaded.warnings)
138
+ warnLog(`config ${paths.configFile}: ${warning}`);
82
139
  const result = await runHookPipeline({
83
140
  provider,
84
141
  env: options.env,
85
142
  paths,
86
- globalConfig: loaded.config,
143
+ globalConfig: loaded,
87
144
  payload,
88
145
  dryRun: options.dryRun === true
89
146
  });
90
147
  if (options.dryRun)
91
148
  writeStdout(options, JSON.stringify({ events: result.state.outbound }, null, 2) + '\n');
149
+ // Only on a config that loaded: a missing or invalid one runs on
150
+ // `fallbackConfig`, which trusts no custom origin, so every trusted
151
+ // self-hosted exporter would read as refused and be deleted for good.
152
+ if (!options.dryRun && loaded.state === 'ok')
153
+ await sweepRefusedExporters(options.env, paths, loaded.config);
92
154
  return result.state;
93
155
  }
156
+ /**
157
+ * Remove AgentWatch-owned native exporters that send outside the allowlist, at
158
+ * most once a day per machine.
159
+ *
160
+ * Here because a machine whose config refused a host may never see `setup` or
161
+ * `doctor` again, while its agents' exporters keep sending to that host with
162
+ * the bearer setup wrote. Bounded by a budget and never throws: the agent's
163
+ * turn is worth more than this check, which the next day retries. Past the
164
+ * budget it is left to die with the process, not counted as abandoned work:
165
+ * that would make the CLI exit by SIGKILL, a failed hook, over housekeeping.
166
+ * Stopping it at any point is safe: each file is replaced atomically, and an
167
+ * exporter removed before the install state is saved is simply not found again.
168
+ *
169
+ * @param env - Ambient environment.
170
+ * @param paths - Resolved AgentWatch paths.
171
+ * @param config - The machine config whose trust applies.
172
+ */
173
+ async function sweepRefusedExporters(env, paths, config) {
174
+ try {
175
+ if (!(await claimSweep(path.join(paths.dataDir, EXPORTER_SWEEP_MARKER_FILE), EXPORTER_SWEEP_INTERVAL_MS, Date.now())))
176
+ return;
177
+ await notLongerThan(sweepAllExporters(env, paths, config), EXPORTER_SWEEP_BUDGET_MS);
178
+ }
179
+ catch (error) {
180
+ debugLog('native exporter allowlist check failed:', error);
181
+ }
182
+ }
183
+ /**
184
+ * One pass over every agent, persisting the install state it changed.
185
+ *
186
+ * @param env - Ambient environment.
187
+ * @param paths - Resolved AgentWatch paths.
188
+ * @param config - The machine config.
189
+ */
190
+ async function sweepAllExporters(env, paths, config) {
191
+ try {
192
+ // Loaded here, not at the top: the hook path loads only its own provider.
193
+ const { providers } = await import('../providers/registry.js');
194
+ const installState = await loadInstallState(paths);
195
+ const swept = await removeRefusedExporters({ env, paths, config, hookCommand: '', installState }, providers);
196
+ for (const refused of swept.refused)
197
+ warnLog(refused.message);
198
+ if (swept.installState !== installState)
199
+ await saveInstallState(paths, swept.installState);
200
+ }
201
+ catch (error) {
202
+ debugLog('native exporter allowlist check failed:', error);
203
+ }
204
+ }
94
205
  /**
95
206
  * Decode the hook payload.
96
207
  *
@@ -4,10 +4,12 @@
4
4
  */
5
5
  export type { Check, CheckLevel, CliContext, HookRunOptions, ParsedArgs, SetupOptions, UninstallOptions } from './types/cli.types.js';
6
6
  export { boolFlag, parseArgs, stringFlag } from './args.js';
7
- export { buildCliContext, buildDeliveryStats, buildHookCommand, buildQueue, buildTransport } from './context.js';
7
+ export { buildCliContext, buildDeliveryStats, buildHookCommand, buildQueue, buildTransport, openIdentityQueue } from './context.js';
8
8
  export { runHook } from './hook.js';
9
9
  export { runSetup } from './setup.js';
10
10
  export { runStatus } from './status.js';
11
11
  export { runDoctor } from './doctor.js';
12
+ export { runToggle } from './toggle.js';
13
+ export { checkHookCommand, installedHookChecks } from './hook-check.js';
12
14
  export { runUninstall } from './uninstall.js';
13
15
  export { runAgents, runConfig, runOtelHeaders } from './misc.js';
package/dist/cli/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  export { boolFlag, parseArgs, stringFlag } from './args.js';
2
- export { buildCliContext, buildDeliveryStats, buildHookCommand, buildQueue, buildTransport } from './context.js';
2
+ export { buildCliContext, buildDeliveryStats, buildHookCommand, buildQueue, buildTransport, openIdentityQueue } from './context.js';
3
3
  export { runHook } from './hook.js';
4
4
  export { runSetup } from './setup.js';
5
5
  export { runStatus } from './status.js';
6
6
  export { runDoctor } from './doctor.js';
7
+ export { runToggle } from './toggle.js';
8
+ export { checkHookCommand, installedHookChecks } from './hook-check.js';
7
9
  export { runUninstall } from './uninstall.js';
8
10
  export { runAgents, runConfig, runOtelHeaders } from './misc.js';
@@ -29,3 +29,14 @@ export declare function runConfig(env: Env): Promise<number>;
29
29
  * @returns Exit code 0.
30
30
  */
31
31
  export declare function runOtelHeaders(env: Env): Promise<number>;
32
+ /**
33
+ * `agentwatch refresh-credential` — started detached by a Windows hook whose
34
+ * DPAPI-held device token is due. Not for people: it prints nothing.
35
+ *
36
+ * Refreshes (or exchanges) this directory's credential the way any CLI run
37
+ * does, PowerShell included, under the same token lock as every other refresher.
38
+ *
39
+ * @param env - Ambient environment.
40
+ * @returns Exit code 0, whatever happened: the next hook reads the result from the cache.
41
+ */
42
+ export declare function runRefreshCredential(env: Env): Promise<number>;
package/dist/cli/misc.js CHANGED
@@ -1,8 +1,14 @@
1
1
  import process from 'node:process';
2
+ import { eventsUrl, otlpBaseUrl, sharesOtlpCollector } from '../config/config.js';
2
3
  import { loadEffectiveConfig } from '../config/repo-config.js';
4
+ import { applyRootOverride, credentialScope } from '../config/root-config.js';
5
+ import { isAllowedHost } from '../config/schemas/config.schema.js';
6
+ import { resolveBearer } from '../credentials/credentials.js';
7
+ import { claudeExporterTargets, claudeOverrideTargets } from '../providers/claude/claude.otel.js';
3
8
  import { providers } from '../providers/registry.js';
4
- import { buildCliContext } from './context.js';
5
- import { REDACTED_TOKEN } from './constants/cli.constants.js';
9
+ import { INSTALLATION_HEADER } from '../transport/constants/transport.constants.js';
10
+ import { buildCliContext, resolveContextBearer } from './context.js';
11
+ import { OTEL_HEADERS_MIN_TOKEN_LIFE_MS, REDACTED_TOKEN } from './constants/cli.constants.js';
6
12
  import { bold, dim, println, symbols } from './ui.js';
7
13
  /**
8
14
  * `agentwatch agents` — detection details for debugging.
@@ -37,14 +43,36 @@ export async function runAgents(env) {
37
43
  export async function runConfig(env) {
38
44
  const context = await buildCliContext(env);
39
45
  println(dim(`# global: ${context.paths.configFile} (${context.configState})`));
46
+ println(`# AgentWatch ${context.disabled ? 'DISABLED' : 'enabled'}`);
40
47
  const effective = await loadEffectiveConfig(context.paths, env.cwd);
48
+ if (effective.rootPath)
49
+ println(dim(`# project root: ${effective.rootPath}`));
41
50
  if (effective.repoConfigFile)
42
51
  println(dim(`# repo overrides: ${effective.repoConfigFile}`));
43
- for (const warning of effective.warnings)
52
+ if (effective.rootPath && !eventsUrl(effective.config))
53
+ println(dim('# warning: this project root has no usable events route; events stay queued — configure its endpoint/eventsUrl or fix the refused URL'));
54
+ if (effective.rootPath && !otlpBaseUrl(effective.config))
55
+ println(dim('# warning: this project root has no usable OTLP route; the machine collector is not inherited'));
56
+ for (const warning of [...context.configWarnings, ...effective.warnings])
44
57
  println(dim(`# warning: ${warning}`));
45
58
  println(JSON.stringify({ ...effective.config, token: effective.config.token ? REDACTED_TOKEN : undefined }, null, 2));
46
59
  return context.configState === 'invalid' ? 1 : 0;
47
60
  }
61
+ /**
62
+ * Whether Claude Code's exporters send to the machine's OTLP base and nowhere
63
+ * the allowlist would refuse.
64
+ *
65
+ * @param env - Ambient environment.
66
+ * @param config - The machine config.
67
+ * @returns True when the bearer may go to the exporter.
68
+ */
69
+ async function exportsWhereConfigured(env, config) {
70
+ const targets = await claudeExporterTargets(env);
71
+ const trusted = new Set(config.customEndpoints);
72
+ if (targets.base === undefined || targets.base !== otlpBaseUrl(config))
73
+ return false;
74
+ return [targets.base, ...targets.signals, ...(await claudeOverrideTargets(env))].every((url) => isAllowedHost(url, trusted));
75
+ }
48
76
  /**
49
77
  * `agentwatch otel-headers` — Claude Code's otelHeadersHelper contract.
50
78
  *
@@ -57,7 +85,55 @@ export async function runConfig(env) {
57
85
  */
58
86
  export async function runOtelHeaders(env) {
59
87
  const context = await buildCliContext(env);
60
- const headers = context.config.token ? { Authorization: `Bearer ${context.config.token}` } : {};
88
+ // Per directory, not machine-wide: with two tenants on one machine the token
89
+ // that signs this export is decided by where the agent is running. Roots are
90
+ // all that can move identity (a repo file cannot), so the global config
91
+ // already in hand is enough. But the agent exports to the machine-wide
92
+ // collector, so a root enrolled against a different backend gets no bearer
93
+ // at all rather than presenting its credential to the other tenant's collector.
94
+ //
95
+ // And only when the exporter sends where the config says, to a host the edge
96
+ // itself would send to: the endpoint lives in Claude's settings file, which
97
+ // is not ours and can be edited to point anywhere.
98
+ const { config: rooted, root } = applyRootOverride(context.config, env.cwd);
99
+ // The current access token, refreshed here whenever it would not outlast
100
+ // Claude Code's debounce on this helper: what it prints is reused until then.
101
+ // An install key still in the config is exchanged first.
102
+ const shared = !context.disabled && sharesOtlpCollector(context.config, rooted) && (await exportsWhereConfigured(env, context.config));
103
+ const token = shared ? await resolveBearer({ env, paths: context.paths, timeoutMs: rooted.delivery.timeoutMs, scope: credentialScope(root), minRemainingMs: OTEL_HEADERS_MIN_TOKEN_LIFE_MS }, rooted) : undefined;
104
+ // The installation id rides with the bearer and on the same condition: an
105
+ // export that carries no credential names no machine either. It is what lets
106
+ // measured per-call usage be traced back to a sender at all — the exporter is
107
+ // the agent's own, so this header is the only thing on that route we set.
108
+ //
109
+ // Not `edgeHeaders()`, though the header list belongs there: that builder also
110
+ // sets User-Agent, and what it would override here is the exporting agent's
111
+ // own, not ours to replace.
112
+ const headers = token
113
+ ? {
114
+ // Spelled out, not `AUTHORIZATION_HEADER`: that constant is lower
115
+ // case for the transport's own requests, and this map is handed to
116
+ // Claude Code rather than to fetch. Its output is what the exporter
117
+ // sends, so the spelling stays the one that has always gone out.
118
+ Authorization: `Bearer ${token}`,
119
+ ...(rooted.installationId ? { [INSTALLATION_HEADER]: rooted.installationId } : {})
120
+ }
121
+ : {};
61
122
  process.stdout.write(JSON.stringify(headers));
62
123
  return 0;
63
124
  }
125
+ /**
126
+ * `agentwatch refresh-credential` — started detached by a Windows hook whose
127
+ * DPAPI-held device token is due. Not for people: it prints nothing.
128
+ *
129
+ * Refreshes (or exchanges) this directory's credential the way any CLI run
130
+ * does, PowerShell included, under the same token lock as every other refresher.
131
+ *
132
+ * @param env - Ambient environment.
133
+ * @returns Exit code 0, whatever happened: the next hook reads the result from the cache.
134
+ */
135
+ export async function runRefreshCredential(env) {
136
+ const context = await buildCliContext(env);
137
+ await resolveContextBearer(context, context.identityConfig.delivery.timeoutMs);
138
+ return 0;
139
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Whether this process runs from npx's download cache, and has not already
3
+ * been handed off once.
4
+ *
5
+ * That cache is temporary: npm may clear it at any time, so hooks registered
6
+ * against it would point at a file that later disappears. The handoff marker
7
+ * stops a global install that happens to live under an `_npx` directory from
8
+ * handing off to itself forever.
9
+ *
10
+ * @param scriptPath - The running script, `process.argv[1]`.
11
+ * @param vars - The environment.
12
+ * @returns True when the script lives under an `_npx` directory.
13
+ */
14
+ export declare function isNpxRun(scriptPath: string | undefined, vars: NodeJS.ProcessEnv): boolean;
15
+ /**
16
+ * PATH for the handed-off setup: the global install's bin first, npx's cache
17
+ * directories gone.
18
+ *
19
+ * First, because setup registers whichever `agentwatch` PATH resolves to, and
20
+ * an older global or a project's `node_modules/.bin` must not win over the copy
21
+ * just installed.
22
+ *
23
+ * @param pathVar - The PATH value.
24
+ * @param globalBin - Directory holding the global `agentwatch`.
25
+ * @returns The PATH to hand off with.
26
+ */
27
+ export declare function handoffPath(pathVar: string, globalBin: string): string;
28
+ /**
29
+ * Install this exact version globally, then run setup again from there.
30
+ *
31
+ * Lets the whole install be `npx -y @agent-watch-ai/edge setup --token …`:
32
+ * one line, and the hooks it registers point at the permanent install.
33
+ *
34
+ * @param setupArgs - Arguments after `agentwatch`, starting with `setup`.
35
+ * @returns The handed-off setup's exit code.
36
+ */
37
+ export declare function installGloballyAndHandOff(setupArgs: readonly string[]): number;
@@ -0,0 +1,79 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { createRequire } from 'node:module';
3
+ import path from 'node:path';
4
+ import { NPX_CACHE_SEGMENT, NPX_HANDOFF_VAR } from './constants/cli.constants.js';
5
+ import { printErrln, symbols } from './ui.js';
6
+ /**
7
+ * Whether this process runs from npx's download cache, and has not already
8
+ * been handed off once.
9
+ *
10
+ * That cache is temporary: npm may clear it at any time, so hooks registered
11
+ * against it would point at a file that later disappears. The handoff marker
12
+ * stops a global install that happens to live under an `_npx` directory from
13
+ * handing off to itself forever.
14
+ *
15
+ * @param scriptPath - The running script, `process.argv[1]`.
16
+ * @param vars - The environment.
17
+ * @returns True when the script lives under an `_npx` directory.
18
+ */
19
+ export function isNpxRun(scriptPath, vars) {
20
+ if (vars[NPX_HANDOFF_VAR])
21
+ return false;
22
+ return scriptPath !== undefined && scriptPath.split(path.sep).includes(NPX_CACHE_SEGMENT);
23
+ }
24
+ /**
25
+ * PATH for the handed-off setup: the global install's bin first, npx's cache
26
+ * directories gone.
27
+ *
28
+ * First, because setup registers whichever `agentwatch` PATH resolves to, and
29
+ * an older global or a project's `node_modules/.bin` must not win over the copy
30
+ * just installed.
31
+ *
32
+ * @param pathVar - The PATH value.
33
+ * @param globalBin - Directory holding the global `agentwatch`.
34
+ * @returns The PATH to hand off with.
35
+ */
36
+ export function handoffPath(pathVar, globalBin) {
37
+ const kept = pathVar.split(path.delimiter).filter((dir) => dir && dir !== globalBin && !dir.split(path.sep).includes(NPX_CACHE_SEGMENT));
38
+ return [globalBin, ...kept].join(path.delimiter);
39
+ }
40
+ /**
41
+ * Install this exact version globally, then run setup again from there.
42
+ *
43
+ * Lets the whole install be `npx -y @agent-watch-ai/edge setup --token …`:
44
+ * one line, and the hooks it registers point at the permanent install.
45
+ *
46
+ * @param setupArgs - Arguments after `agentwatch`, starting with `setup`.
47
+ * @returns The handed-off setup's exit code.
48
+ */
49
+ export function installGloballyAndHandOff(setupArgs) {
50
+ const pkg = createRequire(import.meta.url)('../../package.json');
51
+ const spec = `${pkg.name}@${pkg.version}`;
52
+ // Not the arguments: they carry the token.
53
+ const manual = `run \`npm install -g ${spec}\` yourself, then your setup command again with \`agentwatch\` in place of \`npx -y ${pkg.name}\``;
54
+ // npm is `npm.cmd` on Windows, which only a shell resolves.
55
+ const shell = process.platform === 'win32';
56
+ const install = spawnSync('npm', ['install', '-g', spec], { stdio: 'inherit', shell });
57
+ if (install.status !== 0) {
58
+ printErrln(`${symbols.fail} could not install ${spec} globally; ${manual}`);
59
+ return 1;
60
+ }
61
+ const prefix = spawnSync('npm', ['prefix', '-g'], { encoding: 'utf8', shell }).stdout?.trim();
62
+ const root = spawnSync('npm', ['root', '-g'], { encoding: 'utf8', shell }).stdout?.trim();
63
+ if (!prefix || !root || !path.isAbsolute(prefix) || !path.isAbsolute(root)) {
64
+ printErrln(`${symbols.fail} could not find npm's global folder; ${manual}`);
65
+ return 1;
66
+ }
67
+ // Windows puts the global shims in the prefix itself; everything else in prefix/bin.
68
+ const globalBin = shell ? prefix : path.join(prefix, 'bin');
69
+ const env = { ...process.env, PATH: handoffPath(process.env['PATH'] ?? '', globalBin), [NPX_HANDOFF_VAR]: '1' };
70
+ // The installed entry point under node, never a shim through a shell: the
71
+ // arguments carry the token, and cmd.exe would interpret them.
72
+ const cli = path.join(root, pkg.name, 'dist', 'cli.js');
73
+ const setup = spawnSync(process.execPath, [cli, ...setupArgs], { stdio: 'inherit', env });
74
+ if (setup.error || setup.status === null) {
75
+ printErrln(`${symbols.fail} installed ${spec} but could not start it; ${manual}`);
76
+ return 1;
77
+ }
78
+ return setup.status;
79
+ }
@@ -0,0 +1,39 @@
1
+ import type { SetupOptions } from './types/cli.types.js';
2
+ /**
3
+ * Whether setup should open the sign-in link itself. Only for a developer at
4
+ * an interactive terminal on this machine: under CI, or over SSH (where the
5
+ * browser would open on the far side, if anywhere), the printed link is the way.
6
+ *
7
+ * @param vars - The process environment.
8
+ * @param isTTY - Whether stdout is a terminal.
9
+ * @returns True when a browser may be opened.
10
+ */
11
+ export declare function canOpenBrowser(vars: Record<string, string | undefined>, isTTY: boolean): boolean;
12
+ /**
13
+ * How setup opens the sign-in link: the test seam, the real browser, or not at all.
14
+ *
15
+ * @param options - `--no-browser`, the test seam and the environment.
16
+ * @param options.noBrowser - `--no-browser`.
17
+ * @param options.openUrl - The test seam.
18
+ * @param options.env - Where the vars and platform come from.
19
+ * @param isTTY - Whether stdout is a terminal.
20
+ * @returns The opener, or undefined to only print the link.
21
+ */
22
+ export declare function signInOpener(options: Pick<SetupOptions, 'noBrowser' | 'openUrl' | 'env'>, isTTY: boolean): ((url: string) => void) | undefined;
23
+ /**
24
+ * Whether a link may be handed to a browser opener: http(s) only, since the
25
+ * gateway chose it and a `file:` or custom-scheme link would run something local.
26
+ *
27
+ * @param url - The link from the gateway.
28
+ * @returns True for a parseable http(s) link.
29
+ */
30
+ export declare function isOpenableUrl(url: string): boolean;
31
+ /**
32
+ * Open a link in the default browser, fire-and-forget. Any failure is ignored:
33
+ * the link is printed beside it. No shell is involved, and only an http(s)
34
+ * link is opened, since the gateway chose it.
35
+ *
36
+ * @param url - The link to open.
37
+ * @param platform - Which opener to use.
38
+ */
39
+ export declare function openBrowser(url: string, platform: NodeJS.Platform): void;
@@ -0,0 +1,62 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { BROWSER_OPENERS, DEFAULT_BROWSER_OPENER, OPENABLE_PROTOCOLS } from './constants/cli.constants.js';
3
+ /**
4
+ * Whether setup should open the sign-in link itself. Only for a developer at
5
+ * an interactive terminal on this machine: under CI, or over SSH (where the
6
+ * browser would open on the far side, if anywhere), the printed link is the way.
7
+ *
8
+ * @param vars - The process environment.
9
+ * @param isTTY - Whether stdout is a terminal.
10
+ * @returns True when a browser may be opened.
11
+ */
12
+ export function canOpenBrowser(vars, isTTY) {
13
+ return isTTY && !vars['CI'] && !vars['SSH_CONNECTION'] && !vars['SSH_TTY'];
14
+ }
15
+ /**
16
+ * How setup opens the sign-in link: the test seam, the real browser, or not at all.
17
+ *
18
+ * @param options - `--no-browser`, the test seam and the environment.
19
+ * @param options.noBrowser - `--no-browser`.
20
+ * @param options.openUrl - The test seam.
21
+ * @param options.env - Where the vars and platform come from.
22
+ * @param isTTY - Whether stdout is a terminal.
23
+ * @returns The opener, or undefined to only print the link.
24
+ */
25
+ export function signInOpener(options, isTTY) {
26
+ if (options.noBrowser)
27
+ return undefined;
28
+ if (options.openUrl)
29
+ return options.openUrl;
30
+ return canOpenBrowser(options.env.vars, isTTY) ? (url) => openBrowser(url, options.env.platform) : undefined;
31
+ }
32
+ /**
33
+ * Whether a link may be handed to a browser opener: http(s) only, since the
34
+ * gateway chose it and a `file:` or custom-scheme link would run something local.
35
+ *
36
+ * @param url - The link from the gateway.
37
+ * @returns True for a parseable http(s) link.
38
+ */
39
+ export function isOpenableUrl(url) {
40
+ return URL.canParse(url) && OPENABLE_PROTOCOLS.has(new URL(url).protocol);
41
+ }
42
+ /**
43
+ * Open a link in the default browser, fire-and-forget. Any failure is ignored:
44
+ * the link is printed beside it. No shell is involved, and only an http(s)
45
+ * link is opened, since the gateway chose it.
46
+ *
47
+ * @param url - The link to open.
48
+ * @param platform - Which opener to use.
49
+ */
50
+ export function openBrowser(url, platform) {
51
+ if (!isOpenableUrl(url))
52
+ return;
53
+ const [file, ...args] = [...(BROWSER_OPENERS[platform] ?? DEFAULT_BROWSER_OPENER), url];
54
+ try {
55
+ const child = spawn(file, args, { detached: true, stdio: 'ignore' });
56
+ child.on('error', () => undefined);
57
+ child.unref();
58
+ }
59
+ catch {
60
+ // The printed link still works.
61
+ }
62
+ }
@@ -6,13 +6,26 @@ export type { SetupOptions } from './types/cli.types.js';
6
6
  * telemetry in every detected agent.
7
7
  *
8
8
  * Ordered so nothing is written until everything that can be validated has
9
- * been: a `--otel` typo, an unparseable existing config or a missing endpoint
10
- * fails the run before the first file is touched.
9
+ * been: a `--otel` typo, an unparseable existing config, a refused endpoint or
10
+ * a missing token fails the run before the first file is touched. No endpoint
11
+ * at all means the production Agent Watch backend.
11
12
  *
12
- * @param options - Environment, flags and the interactive prompt.
13
+ * @param options - Environment and flags.
13
14
  * @returns 0 when every step succeeded, else 1.
14
15
  */
15
16
  export declare function runSetup(options: SetupOptions): Promise<number>;
17
+ /**
18
+ * What to call this developer: the flag, then the config, then `git config
19
+ * user.name`.
20
+ *
21
+ * An install whose developer cannot be named is still a working install — the
22
+ * platform falls back to the address.
23
+ *
24
+ * @param options - Setup options, including the flag and injected git runner.
25
+ * @param baseConfig - Config the run starts from.
26
+ * @returns The name, or undefined when nothing knows one.
27
+ */
28
+ export declare function resolveDeveloperName(options: SetupOptions, baseConfig: AgentWatchConfig): Promise<string | undefined>;
16
29
  /**
17
30
  * The developer identity this install will be attributed to.
18
31
  *
@@ -21,12 +34,8 @@ export declare function runSetup(options: SetupOptions): Promise<number>;
21
34
  * the gate will later ask the platform about. The flag is the only override,
22
35
  * for a machine whose git identity is someone else's.
23
36
  *
24
- * Nothing is asked when the identity is already known: the prompt exists for
25
- * the machine that has no answer, not to re-confirm one we already trust.
26
- *
27
37
  * @param options - Flags, environment and the git runner override.
28
38
  * @param baseConfig - Config the run starts from.
29
- * @param ask - The prompt, when the run is interactive.
30
39
  * @returns The identity, or undefined when nothing names the developer.
31
40
  */
32
- export declare function resolveDeveloperEmail(options: SetupOptions, baseConfig: AgentWatchConfig, ask: ((question: string) => Promise<string>) | undefined): Promise<string | undefined>;
41
+ export declare function resolveDeveloperEmail(options: SetupOptions, baseConfig: AgentWatchConfig): Promise<string | undefined>;