@agent-watch-ai/edge 0.2.5 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. package/CHANGELOG.md +512 -0
  2. package/README.md +217 -96
  3. package/SECURITY.md +69 -0
  4. package/dist/billing/session-billing.d.ts +19 -0
  5. package/dist/billing/session-billing.js +52 -0
  6. package/dist/cli/args.d.ts +10 -0
  7. package/dist/cli/args.js +20 -0
  8. package/dist/cli/constants/cli.constants.d.ts +50 -4
  9. package/dist/cli/constants/cli.constants.js +54 -5
  10. package/dist/cli/context.d.ts +33 -2
  11. package/dist/cli/context.js +84 -14
  12. package/dist/cli/doctor.js +309 -32
  13. package/dist/cli/hook-check.d.ts +23 -0
  14. package/dist/cli/hook-check.js +114 -0
  15. package/dist/cli/hook.js +118 -7
  16. package/dist/cli/index.d.ts +3 -1
  17. package/dist/cli/index.js +3 -1
  18. package/dist/cli/misc.d.ts +11 -0
  19. package/dist/cli/misc.js +80 -4
  20. package/dist/cli/npx-install.d.ts +37 -0
  21. package/dist/cli/npx-install.js +79 -0
  22. package/dist/cli/open-browser.d.ts +39 -0
  23. package/dist/cli/open-browser.js +62 -0
  24. package/dist/cli/setup.d.ts +17 -8
  25. package/dist/cli/setup.js +439 -98
  26. package/dist/cli/status.js +82 -13
  27. package/dist/cli/toggle.d.ts +9 -0
  28. package/dist/cli/toggle.js +113 -0
  29. package/dist/cli/types/cli.types.d.ts +37 -3
  30. package/dist/cli/ui.d.ts +7 -0
  31. package/dist/cli/ui.js +10 -1
  32. package/dist/cli/uninstall.js +39 -2
  33. package/dist/cli/update.d.ts +17 -0
  34. package/dist/cli/update.js +76 -0
  35. package/dist/cli.js +100 -13
  36. package/dist/config/config-store.d.ts +57 -0
  37. package/dist/config/config-store.js +250 -12
  38. package/dist/config/config.d.ts +53 -6
  39. package/dist/config/config.js +66 -6
  40. package/dist/config/constants/config.constants.d.ts +113 -6
  41. package/dist/config/constants/config.constants.js +126 -8
  42. package/dist/config/destination.d.ts +24 -0
  43. package/dist/config/destination.js +33 -0
  44. package/dist/config/index.d.ts +7 -4
  45. package/dist/config/index.js +5 -3
  46. package/dist/config/repo-config.d.ts +11 -7
  47. package/dist/config/repo-config.js +64 -15
  48. package/dist/config/root-config.d.ts +72 -0
  49. package/dist/config/root-config.js +170 -0
  50. package/dist/config/schemas/config.schema.d.ts +721 -84
  51. package/dist/config/schemas/config.schema.js +388 -15
  52. package/dist/config/types/config.types.d.ts +15 -1
  53. package/dist/config/types/destination.types.d.ts +8 -0
  54. package/dist/core/async.d.ts +36 -0
  55. package/dist/core/async.js +68 -0
  56. package/dist/core/index.d.ts +1 -1
  57. package/dist/core/index.js +1 -1
  58. package/dist/core/object.d.ts +5 -0
  59. package/dist/core/object.js +9 -4
  60. package/dist/core/pipe.d.ts +0 -13
  61. package/dist/core/pipe.js +1 -9
  62. package/dist/core/types/core.types.d.ts +9 -0
  63. package/dist/core/types/core.types.js +0 -3
  64. package/dist/core/which.d.ts +14 -0
  65. package/dist/core/which.js +43 -3
  66. package/dist/credentials/budget.d.ts +9 -0
  67. package/dist/credentials/budget.js +16 -0
  68. package/dist/credentials/command-runner.d.ts +16 -0
  69. package/dist/credentials/command-runner.js +37 -0
  70. package/dist/credentials/constants/credentials.constants.d.ts +111 -0
  71. package/dist/credentials/constants/credentials.constants.js +112 -0
  72. package/dist/credentials/credential-status.d.ts +14 -0
  73. package/dist/credentials/credential-status.js +34 -0
  74. package/dist/credentials/credentials.d.ts +72 -0
  75. package/dist/credentials/credentials.js +253 -0
  76. package/dist/credentials/device-api.d.ts +64 -0
  77. package/dist/credentials/device-api.js +150 -0
  78. package/dist/credentials/device-state.d.ts +31 -0
  79. package/dist/credentials/device-state.js +51 -0
  80. package/dist/credentials/identity.d.ts +62 -0
  81. package/dist/credentials/identity.js +90 -0
  82. package/dist/credentials/index.d.ts +7 -0
  83. package/dist/credentials/index.js +5 -0
  84. package/dist/credentials/migration.d.ts +46 -0
  85. package/dist/credentials/migration.js +164 -0
  86. package/dist/credentials/schemas/device-api.schema.d.ts +77 -0
  87. package/dist/credentials/schemas/device-api.schema.js +33 -0
  88. package/dist/credentials/schemas/device-state.schema.d.ts +51 -0
  89. package/dist/credentials/schemas/device-state.schema.js +20 -0
  90. package/dist/credentials/secret-store.d.ts +54 -0
  91. package/dist/credentials/secret-store.js +217 -0
  92. package/dist/credentials/sign-in.d.ts +18 -0
  93. package/dist/credentials/sign-in.js +86 -0
  94. package/dist/credentials/token-refresher.d.ts +39 -0
  95. package/dist/credentials/token-refresher.js +185 -0
  96. package/dist/credentials/types/credentials.types.d.ts +195 -0
  97. package/dist/credentials/types/credentials.types.js +1 -0
  98. package/dist/enforcement/constants/enforcement.constants.d.ts +47 -1
  99. package/dist/enforcement/constants/enforcement.constants.js +56 -0
  100. package/dist/enforcement/decision-cache.d.ts +20 -1
  101. package/dist/enforcement/decision-cache.js +65 -2
  102. package/dist/enforcement/decision-client.d.ts +9 -8
  103. package/dist/enforcement/decision-client.js +62 -16
  104. package/dist/enforcement/enforcement.d.ts +23 -2
  105. package/dist/enforcement/enforcement.js +103 -15
  106. package/dist/enforcement/index.d.ts +4 -3
  107. package/dist/enforcement/index.js +3 -2
  108. package/dist/enforcement/types/enforcement.types.d.ts +64 -0
  109. package/dist/enrollment/constants/enrollment.constants.d.ts +2 -6
  110. package/dist/enrollment/constants/enrollment.constants.js +2 -6
  111. package/dist/enrollment/enrollment.d.ts +16 -0
  112. package/dist/enrollment/enrollment.js +54 -0
  113. package/dist/enrollment/index.d.ts +3 -7
  114. package/dist/enrollment/index.js +1 -1
  115. package/dist/enrollment/types/enrollment.types.d.ts +9 -13
  116. package/dist/events/constants/enrich.constants.d.ts +15 -0
  117. package/dist/events/constants/enrich.constants.js +15 -0
  118. package/dist/events/constants/events.constants.d.ts +6 -2
  119. package/dist/events/constants/events.constants.js +5 -1
  120. package/dist/events/enrich.js +92 -10
  121. package/dist/events/event-id.d.ts +0 -8
  122. package/dist/events/event-id.js +0 -10
  123. package/dist/events/index.d.ts +2 -2
  124. package/dist/events/index.js +1 -1
  125. package/dist/events/product-event.d.ts +9 -6
  126. package/dist/events/types/repo-snapshot.types.d.ts +7 -0
  127. package/dist/events/types/session-billing.types.d.ts +16 -0
  128. package/dist/events/types/session-billing.types.js +1 -0
  129. package/dist/feature/constants/feature.constants.d.ts +7 -0
  130. package/dist/feature/constants/feature.constants.js +7 -0
  131. package/dist/feature/index.d.ts +1 -1
  132. package/dist/feature/index.js +1 -1
  133. package/dist/feature/ticket-candidates.d.ts +14 -0
  134. package/dist/feature/ticket-candidates.js +26 -8
  135. package/dist/git/blob-hash.d.ts +21 -0
  136. package/dist/git/blob-hash.js +69 -0
  137. package/dist/git/checkout-root.d.ts +27 -0
  138. package/dist/git/checkout-root.js +75 -0
  139. package/dist/git/constants/git.constants.d.ts +160 -0
  140. package/dist/git/constants/git.constants.js +181 -0
  141. package/dist/git/fingerprint.d.ts +74 -0
  142. package/dist/git/fingerprint.js +219 -0
  143. package/dist/git/gate-checkout.d.ts +44 -0
  144. package/dist/git/gate-checkout.js +201 -0
  145. package/dist/git/git-context.d.ts +45 -0
  146. package/dist/git/git-context.js +61 -3
  147. package/dist/git/index.d.ts +4 -2
  148. package/dist/git/index.js +2 -1
  149. package/dist/git/manifest-repository.d.ts +13 -0
  150. package/dist/git/manifest-repository.js +92 -0
  151. package/dist/git/repo-snapshot.d.ts +29 -3
  152. package/dist/git/repo-snapshot.js +110 -7
  153. package/dist/git/repository-root.d.ts +39 -0
  154. package/dist/git/repository-root.js +131 -0
  155. package/dist/git/types/git.types.d.ts +55 -0
  156. package/dist/git/types/repository-root.types.d.ts +11 -0
  157. package/dist/git/types/repository-root.types.js +1 -0
  158. package/dist/git/types/snapshot.types.d.ts +9 -0
  159. package/dist/pipeline/constants/pipeline.constants.d.ts +7 -0
  160. package/dist/pipeline/constants/pipeline.constants.js +7 -0
  161. package/dist/pipeline/hook-pipeline.js +360 -32
  162. package/dist/pipeline/types/pipeline.types.d.ts +39 -4
  163. package/dist/privacy/constants/privacy.constants.js +15 -1
  164. package/dist/privacy/index.d.ts +1 -0
  165. package/dist/privacy/index.js +1 -0
  166. package/dist/privacy/product-capture.d.ts +12 -0
  167. package/dist/privacy/product-capture.js +73 -0
  168. package/dist/privacy/sanitizer.d.ts +21 -3
  169. package/dist/privacy/sanitizer.js +52 -8
  170. package/dist/process/ancestors.d.ts +39 -0
  171. package/dist/process/ancestors.js +121 -0
  172. package/dist/process/constants/process.constants.d.ts +34 -0
  173. package/dist/process/constants/process.constants.js +34 -0
  174. package/dist/process/index.d.ts +7 -0
  175. package/dist/process/index.js +2 -0
  176. package/dist/process/types/process.types.d.ts +23 -0
  177. package/dist/process/types/process.types.js +1 -0
  178. package/dist/providers/antigravity/antigravity.adapter.d.ts +12 -1
  179. package/dist/providers/antigravity/antigravity.adapter.js +21 -3
  180. package/dist/providers/antigravity/antigravity.detect.d.ts +0 -9
  181. package/dist/providers/antigravity/antigravity.detect.js +1 -1
  182. package/dist/providers/antigravity/antigravity.provider.js +3 -2
  183. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +2 -0
  184. package/dist/providers/antigravity/constants/antigravity.constants.js +2 -0
  185. package/dist/providers/claude/claude.adapter.d.ts +11 -1
  186. package/dist/providers/claude/claude.adapter.js +26 -5
  187. package/dist/providers/claude/claude.otel.d.ts +32 -18
  188. package/dist/providers/claude/claude.otel.js +81 -6
  189. package/dist/providers/claude/claude.provider.js +5 -2
  190. package/dist/providers/claude/constants/claude.constants.d.ts +2 -0
  191. package/dist/providers/claude/constants/claude.constants.js +2 -0
  192. package/dist/providers/claude/constants/claude.otel.constants.d.ts +4 -0
  193. package/dist/providers/claude/constants/claude.otel.constants.js +8 -0
  194. package/dist/providers/codex/codex.adapter.d.ts +15 -1
  195. package/dist/providers/codex/codex.adapter.js +29 -5
  196. package/dist/providers/codex/codex.otel.d.ts +24 -2
  197. package/dist/providers/codex/codex.otel.js +147 -30
  198. package/dist/providers/codex/codex.provider.js +5 -2
  199. package/dist/providers/codex/constants/codex.constants.d.ts +2 -0
  200. package/dist/providers/codex/constants/codex.constants.js +16 -0
  201. package/dist/providers/codex/constants/codex.otel.constants.d.ts +5 -0
  202. package/dist/providers/codex/constants/codex.otel.constants.js +5 -0
  203. package/dist/providers/constants/provider.constants.d.ts +0 -3
  204. package/dist/providers/constants/provider.constants.js +0 -3
  205. package/dist/providers/cursor/constants/cursor.constants.d.ts +7 -0
  206. package/dist/providers/cursor/constants/cursor.constants.js +7 -0
  207. package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
  208. package/dist/providers/cursor/cursor.adapter.js +52 -3
  209. package/dist/providers/cursor/cursor.detect.d.ts +0 -7
  210. package/dist/providers/cursor/cursor.detect.js +1 -1
  211. package/dist/providers/cursor/cursor.provider.js +5 -2
  212. package/dist/providers/gemini/constants/gemini.constants.d.ts +9 -0
  213. package/dist/providers/gemini/constants/gemini.constants.js +9 -0
  214. package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +3 -1
  215. package/dist/providers/gemini/constants/gemini.otel.constants.js +3 -0
  216. package/dist/providers/gemini/gemini.adapter.d.ts +14 -1
  217. package/dist/providers/gemini/gemini.adapter.js +25 -5
  218. package/dist/providers/gemini/gemini.detect.d.ts +0 -7
  219. package/dist/providers/gemini/gemini.detect.js +1 -1
  220. package/dist/providers/gemini/gemini.otel.d.ts +19 -20
  221. package/dist/providers/gemini/gemini.otel.js +121 -17
  222. package/dist/providers/gemini/gemini.provider.js +2 -1
  223. package/dist/providers/index.d.ts +1 -1
  224. package/dist/providers/index.js +1 -1
  225. package/dist/providers/loaders.d.ts +10 -0
  226. package/dist/providers/loaders.js +40 -0
  227. package/dist/providers/provider.d.ts +11 -0
  228. package/dist/providers/provider.js +1 -1
  229. package/dist/providers/registry.d.ts +11 -8
  230. package/dist/providers/registry.js +11 -15
  231. package/dist/providers/shared/constants/hook-refusal.constants.d.ts +7 -0
  232. package/dist/providers/shared/constants/hook-refusal.constants.js +7 -0
  233. package/dist/providers/shared/constants/shell-directories.constants.d.ts +30 -0
  234. package/dist/providers/shared/constants/shell-directories.constants.js +39 -0
  235. package/dist/providers/shared/constants/tooling.constants.d.ts +18 -2
  236. package/dist/providers/shared/constants/tooling.constants.js +19 -3
  237. package/dist/providers/shared/event-builder.d.ts +12 -14
  238. package/dist/providers/shared/event-builder.js +20 -14
  239. package/dist/providers/shared/exporter-allowlist.d.ts +20 -0
  240. package/dist/providers/shared/exporter-allowlist.js +49 -0
  241. package/dist/providers/shared/hook-config.d.ts +2 -21
  242. package/dist/providers/shared/hook-config.js +5 -4
  243. package/dist/providers/shared/hook-refusal.d.ts +12 -0
  244. package/dist/providers/shared/hook-refusal.js +17 -1
  245. package/dist/providers/shared/install-record.d.ts +12 -2
  246. package/dist/providers/shared/install-record.js +5 -2
  247. package/dist/providers/shared/shell-directories.d.ts +24 -0
  248. package/dist/providers/shared/shell-directories.js +90 -0
  249. package/dist/providers/shared/tooling.d.ts +12 -1
  250. package/dist/providers/shared/tooling.js +18 -0
  251. package/dist/providers/shared/types/adapter.types.d.ts +1 -2
  252. package/dist/providers/types/provider.types.d.ts +57 -1
  253. package/dist/snapshot/constants/snapshot.constants.d.ts +32 -0
  254. package/dist/snapshot/constants/snapshot.constants.js +33 -0
  255. package/dist/snapshot/snapshot-event.js +52 -11
  256. package/dist/snapshot/snapshot-pipeline.js +1 -1
  257. package/dist/snapshot/types/snapshot.types.d.ts +2 -0
  258. package/dist/storage/atomic-file.d.ts +7 -0
  259. package/dist/storage/atomic-file.js +1 -1
  260. package/dist/storage/constants/storage.constants.d.ts +17 -0
  261. package/dist/storage/constants/storage.constants.js +17 -0
  262. package/dist/storage/disabled.d.ts +13 -0
  263. package/dist/storage/disabled.js +24 -0
  264. package/dist/storage/index.d.ts +2 -0
  265. package/dist/storage/index.js +2 -0
  266. package/dist/storage/paths.js +3 -2
  267. package/dist/storage/schemas/storage.schema.d.ts +72 -0
  268. package/dist/storage/schemas/storage.schema.js +6 -0
  269. package/dist/storage/sweep-marker.d.ts +19 -0
  270. package/dist/storage/sweep-marker.js +55 -0
  271. package/dist/storage/types/storage.types.d.ts +2 -0
  272. package/dist/storage/uninstalled.d.ts +58 -0
  273. package/dist/storage/uninstalled.js +107 -0
  274. package/dist/transport/auth-block.d.ts +66 -0
  275. package/dist/transport/auth-block.js +129 -0
  276. package/dist/transport/constants/transport.constants.d.ts +82 -3
  277. package/dist/transport/constants/transport.constants.js +83 -4
  278. package/dist/transport/cooldown.js +8 -1
  279. package/dist/transport/delivery.d.ts +14 -6
  280. package/dist/transport/delivery.js +80 -55
  281. package/dist/transport/http-transport.d.ts +1 -0
  282. package/dist/transport/http-transport.js +52 -10
  283. package/dist/transport/index.d.ts +6 -3
  284. package/dist/transport/index.js +3 -0
  285. package/dist/transport/queue-partition.d.ts +91 -0
  286. package/dist/transport/queue-partition.js +143 -0
  287. package/dist/transport/queue.d.ts +99 -20
  288. package/dist/transport/queue.js +210 -69
  289. package/dist/transport/response-body.d.ts +25 -0
  290. package/dist/transport/response-body.js +64 -0
  291. package/dist/transport/send.d.ts +11 -0
  292. package/dist/transport/send.js +17 -0
  293. package/dist/transport/types/delivery-flow.types.d.ts +19 -0
  294. package/dist/transport/types/delivery-flow.types.js +1 -0
  295. package/dist/transport/types/transport.types.d.ts +45 -0
  296. package/dist/turns/claude-transcript.d.ts +19 -1
  297. package/dist/turns/claude-transcript.js +46 -1
  298. package/dist/turns/codex-originator.d.ts +11 -0
  299. package/dist/turns/codex-originator.js +31 -0
  300. package/dist/turns/codex-transcript.d.ts +30 -0
  301. package/dist/turns/codex-transcript.js +88 -0
  302. package/dist/turns/constants/turns.constants.d.ts +141 -5
  303. package/dist/turns/constants/turns.constants.js +155 -5
  304. package/dist/turns/file-identity.d.ts +27 -0
  305. package/dist/turns/file-identity.js +48 -0
  306. package/dist/turns/gemini-transcript.d.ts +30 -0
  307. package/dist/turns/gemini-transcript.js +96 -0
  308. package/dist/turns/index.d.ts +3 -3
  309. package/dist/turns/index.js +1 -1
  310. package/dist/turns/inherited-checkout.d.ts +54 -0
  311. package/dist/turns/inherited-checkout.js +155 -0
  312. package/dist/turns/native-session-titles.d.ts +26 -0
  313. package/dist/turns/native-session-titles.js +102 -0
  314. package/dist/turns/transcript.d.ts +3 -2
  315. package/dist/turns/transcript.js +5 -1
  316. package/dist/turns/turn-state.d.ts +224 -3
  317. package/dist/turns/turn-state.js +456 -21
  318. package/dist/turns/turn-summary.d.ts +1 -14
  319. package/dist/turns/turn-summary.js +87 -51
  320. package/dist/turns/turn-tracker.d.ts +21 -2
  321. package/dist/turns/turn-tracker.js +379 -56
  322. package/dist/turns/types/transcript.types.d.ts +5 -0
  323. package/dist/turns/types/turn-state.types.d.ts +116 -5
  324. package/dist/turns/types/turn-summary.types.d.ts +64 -14
  325. package/dist/turns/types/turn-tracker.types.d.ts +27 -1
  326. package/dist/turns/work-checkout.d.ts +65 -0
  327. package/dist/turns/work-checkout.js +666 -0
  328. package/dist/untraced/constants/untraced.constants.d.ts +31 -0
  329. package/dist/untraced/constants/untraced.constants.js +63 -0
  330. package/dist/untraced/untraced.d.ts +35 -0
  331. package/dist/untraced/untraced.js +105 -0
  332. package/dist/update/constants/update.constants.d.ts +18 -0
  333. package/dist/update/constants/update.constants.js +20 -0
  334. package/dist/update/update-check.d.ts +52 -0
  335. package/dist/update/update-check.js +113 -0
  336. package/docs/AUDIT_PROMPT.md +129 -0
  337. package/docs/DATA_HANDLING.md +648 -0
  338. package/docs/ENTERPRISE_DEPLOYMENT.md +179 -0
  339. package/docs/PERFORMANCE.md +81 -0
  340. package/package.json +14 -4
  341. package/dist/enrollment/enrollment-provider.d.ts +0 -5
  342. package/dist/enrollment/manual-enrollment.d.ts +0 -32
  343. package/dist/enrollment/manual-enrollment.js +0 -72
  344. package/example/README.md +0 -43
  345. package/example/server.mjs +0 -240
  346. /package/dist/{enrollment/enrollment-provider.js → config/types/destination.types.js} +0 -0
@@ -1,7 +1,12 @@
1
1
  import path from 'node:path';
2
2
  import { enforcementUrl } from '../config/config.js';
3
+ import { ENFORCEMENT_WINDOW_MS } from '../config/constants/config.constants.js';
3
4
  import { debugLog } from '../core/logger.js';
4
- import { ALLOW, ENFORCEMENT_CACHE_FILE_NAME } from './constants/enforcement.constants.js';
5
+ import { deviceFor, hasCredential, identityOf } from '../credentials/identity.js';
6
+ import { sha256Hex } from '../events/event-id.js';
7
+ import { BackendCooldown } from '../transport/cooldown.js';
8
+ import { identityPaths } from '../transport/queue-partition.js';
9
+ import { ALLOW, DECISION_ALLOW, ENFORCEMENT_CACHE_FILE_NAME, ENFORCEMENT_COOLDOWN_FILE_PREFIX, ENFORCEMENT_COOLDOWN_FILE_SUFFIX, ENFORCEMENT_COOLDOWN_MS, ENFORCEMENT_COOLDOWN_URL_CHARS } from './constants/enforcement.constants.js';
5
10
  import { DecisionCache, decisionKey } from './decision-cache.js';
6
11
  import { requestDecision } from './decision-client.js';
7
12
  /**
@@ -14,6 +19,10 @@ import { requestDecision } from './decision-client.js';
14
19
  * front of every developer's tooling, so a check that failed closed would turn
15
20
  * an alerts-service hiccup into an outage for a whole engineering organization.
16
21
  *
22
+ * An allow that exists only because nothing answered carries the reason, so
23
+ * the turn it lets through can say it ran unchecked. An allow because nothing
24
+ * was asked carries none: there was no check to fail.
25
+ *
17
26
  * Never throws: a caller on the hook path has to answer the agent either way.
18
27
  *
19
28
  * @param options - Effective config, paths, the identity to ask about, clock.
@@ -21,52 +30,130 @@ import { requestDecision } from './decision-client.js';
21
30
  */
22
31
  export async function resolveEnforcement(options) {
23
32
  const url = enforcementUrl(options.config);
24
- const token = options.config.token;
33
+ // A device's install key stays in the file for Codex and Gemini, but this
34
+ // identity sends as the device: only the caller's cached access token will do.
35
+ const token = options.bearer ?? (deviceFor(options.config) ? undefined : options.config.token);
25
36
  const developerId = options.developerId;
26
37
  // Nothing was asked, so nobody said no.
27
- if (!options.config.enforcement.enabled || !url || !token || !developerId)
38
+ if (!enforcementWouldAsk(options.config) || !url || !developerId)
28
39
  return ALLOW;
29
40
  try {
30
41
  return await decideThroughCache(options, url, token, developerId);
31
42
  }
32
43
  catch (error) {
33
44
  debugLog('enforcement: check threw; allowing:', error);
34
- return ALLOW;
45
+ return failOpen('unknown');
35
46
  }
36
47
  }
48
+ /**
49
+ * An allow that stands in for a decision that did not arrive.
50
+ *
51
+ * @param reason - Why it did not.
52
+ * @returns The allow, carrying the reason.
53
+ */
54
+ function failOpen(reason) {
55
+ return { decision: DECISION_ALLOW, failOpenReason: reason };
56
+ }
57
+ /**
58
+ * Whether a decision would be asked for at all, from configuration alone.
59
+ *
60
+ * Exported because the caller has to know before it pays for anything the
61
+ * question needs. Working out where a prompt is happening costs a walk of the
62
+ * working copy and, on a cold checkout, a git process; spending that on a
63
+ * machine that will not ask is the one cost this feature must not add to the
64
+ * gate.
65
+ *
66
+ * Identity is not part of it: resolving that is the caller's own decision, and
67
+ * it is already paid for elsewhere.
68
+ *
69
+ * @param config - Effective configuration.
70
+ * @returns True when a configured, enabled check would reach the platform.
71
+ */
72
+ export function enforcementWouldAsk(config) {
73
+ return config.enforcement.enabled && hasCredential(config) && Boolean(enforcementUrl(config));
74
+ }
37
75
  /**
38
76
  * The decision, from the local cache when it holds a live one.
39
77
  *
40
78
  * A miss asks the platform and stores whatever it answered. A *failure* is not
41
79
  * stored: it is not a decision, and caching it as an allow would extend one
42
- * unreachable moment across the whole TTL.
80
+ * unreachable moment across the whole TTL. It trips the breaker instead, so the
81
+ * turns after it skip the wait rather than each paying the timeout again.
82
+ *
83
+ * The cache is read before the token is needed: it is keyed on the identity,
84
+ * not the bearer, so a block still in force is served even when the prompt
85
+ * path has no valid access token to ask a new question with.
43
86
  *
44
87
  * @param options - As given to {@link resolveEnforcement}.
45
88
  * @param url - The decision endpoint.
46
- * @param token - Edge token.
89
+ * @param token - Edge token, when there is one to ask with.
47
90
  * @param developerId - Identity to ask about.
48
91
  * @returns The decision to act on.
49
92
  */
50
93
  async function decideThroughCache(options, url, token, developerId) {
51
94
  const cache = new DecisionCache(path.join(options.paths.dataDir, ENFORCEMENT_CACHE_FILE_NAME), options.now);
52
- const key = decisionKey(url, token, developerId);
95
+ // `enforcementWouldAsk` already required a credential, so there is an identity.
96
+ const key = decisionKey(url, identityOf(options.config) ?? '', developerId, options.checkout, options.model);
53
97
  const cached = await cache.read(key);
54
98
  if (cached)
55
99
  return cached;
56
- const answered = await requestDecision({
100
+ // A question would have to be asked, and the device has no valid token to ask
101
+ // it with (the prompt path never refreshes): the turn runs unchecked, and says why.
102
+ if (!token)
103
+ return failOpen('token_unavailable');
104
+ const cooldown = new BackendCooldown(enforcementCooldownFile(options, url), options.now);
105
+ // Skipping is the only thing the breaker does: the turn gets the same allow a
106
+ // timeout would have given it, without the wait.
107
+ if (await cooldown.active()) {
108
+ debugLog('enforcement: breaker open; allowing without asking');
109
+ return failOpen('circuit_open');
110
+ }
111
+ const outcome = await requestDecision({
57
112
  url,
58
113
  token,
59
114
  developerId,
115
+ checkout: options.checkout,
116
+ model: options.model,
60
117
  installationId: options.config.installationId,
61
118
  timeoutMs: options.config.enforcement.timeoutMs,
62
119
  fetchFn: options.fetchFn
63
120
  });
64
- if (!answered)
65
- return ALLOW;
66
- const { cacheTtlMs, ...decision } = answered;
67
- await cache.write(key, decision, effectiveTtlMs(cacheTtlMs, options.config.enforcement.cacheTtlMs));
121
+ if ('failOpenReason' in outcome) {
122
+ await cooldown.trip(ENFORCEMENT_COOLDOWN_MS);
123
+ return failOpen(outcome.failOpenReason);
124
+ }
125
+ await cooldown.clear();
126
+ const { cacheTtlMs, ...decision } = outcome.answered;
127
+ const ttlMs = effectiveTtlMs(cacheTtlMs, options.config.enforcement.cacheTtlMs);
128
+ // Zero is the platform saying "do not keep this", which it says to every tenant
129
+ // that has a feature cap: which feature a branch belongs to is a fact about one
130
+ // checkout, and this cache is keyed on the developer. Written anyway the entry
131
+ // would already be expired — but it would still be a file write per gated
132
+ // prompt for something nothing can ever read.
133
+ if (ttlMs > 0) {
134
+ await cache.write(key, decision, ttlMs);
135
+ return decision;
136
+ }
137
+ // Writing is also what prunes, so an answer that must not be kept still has to
138
+ // sweep what an earlier one left behind.
139
+ await cache.prune();
68
140
  return decision;
69
141
  }
142
+ /**
143
+ * The enforcement breaker's file for this identity and endpoint.
144
+ *
145
+ * Per identity for the reason delivery's is: one tenant's unreachable platform
146
+ * or revoked token must not skip another tenant's checks. Per endpoint because
147
+ * one identity reaching two platforms must not let one's outage skip the other.
148
+ *
149
+ * @param options - As given to {@link resolveEnforcement}.
150
+ * @param url - The decision endpoint.
151
+ * @returns Absolute path of the state file.
152
+ */
153
+ function enforcementCooldownFile(options, url) {
154
+ const name = ENFORCEMENT_COOLDOWN_FILE_PREFIX + sha256Hex(url).slice(0, ENFORCEMENT_COOLDOWN_URL_CHARS) + ENFORCEMENT_COOLDOWN_FILE_SUFFIX;
155
+ return path.join(path.dirname(identityPaths(options.paths, identityOf(options.config)).cooldownFile), name);
156
+ }
70
157
  /**
71
158
  * How long this answer may be reused.
72
159
  *
@@ -77,14 +164,15 @@ async function decideThroughCache(options, url, token, developerId) {
77
164
  * configured ceiling, which is what keeps the setting meaningful.
78
165
  *
79
166
  * No advice means the configured value, which is what a platform that predates
80
- * the field produces.
167
+ * the field produces. Neither may exceed the promised window.
81
168
  *
82
169
  * @param asked - What the platform asked for, if anything.
83
170
  * @param configured - This machine's own TTL, and its ceiling.
84
171
  * @returns The TTL to store the entry with.
85
172
  */
86
173
  function effectiveTtlMs(asked, configured) {
174
+ const ceiling = Math.min(configured, ENFORCEMENT_WINDOW_MS);
87
175
  if (asked === undefined)
88
- return configured;
89
- return Math.min(asked, configured);
176
+ return ceiling;
177
+ return Math.min(asked, ceiling);
90
178
  }
@@ -2,10 +2,11 @@
2
2
  * The pre-turn budget check: one question to the platform before a developer's
3
3
  * agent starts a turn, and a refusal only when the platform explicitly says so.
4
4
  *
5
- * `resolveEnforcement` is the whole contract. The client, the cache and the
5
+ * `resolveEnforcement` is the whole contract, and `enforcementWouldAsk` is the
6
+ * question a caller asks before paying for anything the check needs. The client, the cache and the
6
7
  * validators are how it keeps that contract, not part of it; tests reach for
7
8
  * them directly.
8
9
  */
9
- export { resolveEnforcement } from './enforcement.js';
10
+ export { enforcementWouldAsk, resolveEnforcement } from './enforcement.js';
10
11
  export { DECISION_BLOCK, ENFORCEMENT_CACHE_FILE_NAME } from './constants/enforcement.constants.js';
11
- export type { EnforcementDecision, EnforcementOptions } from './types/enforcement.types.js';
12
+ export type { EnforcementDecision, EnforcementOptions, FailOpenReason, GateDecision } from './types/enforcement.types.js';
@@ -2,9 +2,10 @@
2
2
  * The pre-turn budget check: one question to the platform before a developer's
3
3
  * agent starts a turn, and a refusal only when the platform explicitly says so.
4
4
  *
5
- * `resolveEnforcement` is the whole contract. The client, the cache and the
5
+ * `resolveEnforcement` is the whole contract, and `enforcementWouldAsk` is the
6
+ * question a caller asks before paying for anything the check needs. The client, the cache and the
6
7
  * validators are how it keeps that contract, not part of it; tests reach for
7
8
  * them directly.
8
9
  */
9
- export { resolveEnforcement } from './enforcement.js';
10
+ export { enforcementWouldAsk, resolveEnforcement } from './enforcement.js';
10
11
  export { DECISION_BLOCK, ENFORCEMENT_CACHE_FILE_NAME } from './constants/enforcement.constants.js';
@@ -32,6 +32,39 @@ export type EnforcementDecision = {
32
32
  export type AnsweredDecision = EnforcementDecision & {
33
33
  readonly cacheTtlMs?: number;
34
34
  };
35
+ /**
36
+ * Why a turn ran without a decision, in the platform's closed vocabulary.
37
+ *
38
+ * A category and never a detail: no status code, no error message, no body.
39
+ * The body of a failed answer can name a person and what they spent, and a
40
+ * status code says nothing the platform's own logs do not already say better.
41
+ */
42
+ export type FailOpenReason = 'timeout' | 'http_error' | 'network_error' | 'unreadable_response' | 'circuit_open' | 'token_unavailable' | 'unknown';
43
+ /**
44
+ * What asking the platform produced: an answer, or the reason there was none.
45
+ *
46
+ * A union rather than `AnsweredDecision | undefined` so a failure keeps what
47
+ * kind of failure it was, which is what the turn summary reports.
48
+ */
49
+ export type DecisionOutcome = {
50
+ readonly answered: AnsweredDecision;
51
+ } | {
52
+ readonly failOpenReason: FailOpenReason;
53
+ };
54
+ /**
55
+ * What the hook acts on: the decision, and — only when the turn is allowed
56
+ * because nothing answered — why.
57
+ *
58
+ * An allow with no reason is a real answer (or nothing was asked at all); an
59
+ * allow with one is a turn that ran unchecked.
60
+ */
61
+ export type GateDecision = {
62
+ readonly decision: 'allow';
63
+ readonly failOpenReason?: FailOpenReason;
64
+ } | {
65
+ readonly decision: 'block';
66
+ readonly message: string;
67
+ };
35
68
  /** One decision as the local cache holds it, with the deadline it expires at. */
36
69
  export interface CachedDecision {
37
70
  readonly decision: EnforcementDecision;
@@ -39,21 +72,52 @@ export interface CachedDecision {
39
72
  }
40
73
  /** One request to the decision endpoint. */
41
74
  export interface DecisionRequest {
75
+ readonly checkout?: EnforcementCheckout;
42
76
  readonly url: string;
43
77
  readonly token: string;
44
78
  /** The same identity `turn.summary.developer_id` carries. */
45
79
  readonly developerId: string;
46
80
  readonly installationId?: string;
81
+ /** The model this session is on, when the collector learned one. */
82
+ readonly model?: string;
47
83
  readonly timeoutMs: number;
48
84
  /** Injected by tests; the real fetch otherwise. */
49
85
  readonly fetchFn?: typeof fetch;
50
86
  }
51
87
  /** Everything the check needs to answer without touching ambient state. */
88
+ /** Where the turn is happening, when the working copy could say. */
89
+ interface EnforcementCheckout {
90
+ readonly repository: string;
91
+ readonly branch: string;
92
+ }
52
93
  export interface EnforcementOptions {
53
94
  readonly config: AgentWatchConfig;
54
95
  readonly paths: AgentWatchPaths;
55
96
  /** The identity to ask about, or undefined when this machine has none. */
56
97
  readonly developerId?: string;
98
+ /**
99
+ * Where the turn is happening, when the working copy could say.
100
+ *
101
+ * Both halves or neither: a branch alone identifies nothing, because every
102
+ * repository has a `main`, and the platform drops a half-stated pair anyway.
103
+ */
104
+ readonly checkout?: EnforcementCheckout;
105
+ /**
106
+ * The model the turn is about, when the collector knows it.
107
+ *
108
+ * Absent is a supported answer, not a degraded one: an agent that never names
109
+ * its model is judged on the developer and the checkout alone, exactly as
110
+ * every collector was before this field existed.
111
+ */
112
+ readonly model?: string;
113
+ /**
114
+ * What to present as the bearer: the install key or a cached access token,
115
+ * resolved by the caller without network work. Absent, the config's install
116
+ * key is used unless the identity sends as a device; a device with no cached
117
+ * token asks nothing and fails open as `token_unavailable`.
118
+ */
119
+ readonly bearer?: string;
57
120
  readonly now: () => Date;
58
121
  readonly fetchFn?: typeof fetch;
59
122
  }
123
+ export {};
@@ -1,6 +1,2 @@
1
- /** Protocols a backend URL may use. */
2
- export declare const ALLOWED_PROTOCOLS: ReadonlySet<string>;
3
- /** Prompts the manual provider asks when it has no value yet. */
4
- export declare const ENDPOINT_PROMPT = "AgentWatch backend URL: ";
5
- export declare const TOKEN_PROMPT = "API token (optional, press Enter to skip): ";
6
- export declare const RE_TRAILING_SLASHES: RegExp;
1
+ /** The organization id in an enrollment URL: a UUID, as the gateway's start route requires. */
2
+ export declare const RE_ORGANIZATION_ID: RegExp;
@@ -1,6 +1,2 @@
1
- /** Protocols a backend URL may use. */
2
- export const ALLOWED_PROTOCOLS = new Set(['https:', 'http:']);
3
- /** Prompts the manual provider asks when it has no value yet. */
4
- export const ENDPOINT_PROMPT = 'AgentWatch backend URL: ';
5
- export const TOKEN_PROMPT = 'API token (optional, press Enter to skip): ';
6
- export const RE_TRAILING_SLASHES = /\/+$/;
1
+ /** The organization id in an enrollment URL: a UUID, as the gateway's start route requires. */
2
+ export const RE_ORGANIZATION_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -0,0 +1,16 @@
1
+ import type { EnrollmentInput, EnrollmentResult } from './types/enrollment.types.js';
2
+ /**
3
+ * Acquire the backend endpoint and token. Never prompts.
4
+ *
5
+ * No endpoint means the production Agent Watch backend. A host outside the
6
+ * Agent Watch allowlist needs an origin this machine already trusts, or the
7
+ * flag on this run. The URL is checked
8
+ * against the same rule the config schema applies on every later read, so a
9
+ * bearer can never be configured onto a destination the schema would then
10
+ * refuse to load.
11
+ *
12
+ * @param input - Flags and existing configuration.
13
+ * @returns The endpoint and token to configure.
14
+ * @throws When the endpoint is not usable.
15
+ */
16
+ export declare function resolveEnrollment(input: EnrollmentInput): EnrollmentResult;
@@ -0,0 +1,54 @@
1
+ import { deliverableOrigin, isAllowedHost } from '../config/schemas/config.schema.js';
2
+ import { DEFAULT_ENDPOINT, DELIVERABLE_URL_MESSAGE } from '../config/constants/config.constants.js';
3
+ import { normalizeEndpoint } from '../config/destination.js';
4
+ import { RE_ORGANIZATION_ID } from './constants/enrollment.constants.js';
5
+ /**
6
+ * Acquire the backend endpoint and token. Never prompts.
7
+ *
8
+ * No endpoint means the production Agent Watch backend. A host outside the
9
+ * Agent Watch allowlist needs an origin this machine already trusts, or the
10
+ * flag on this run. The URL is checked
11
+ * against the same rule the config schema applies on every later read, so a
12
+ * bearer can never be configured onto a destination the schema would then
13
+ * refuse to load.
14
+ *
15
+ * @param input - Flags and existing configuration.
16
+ * @returns The endpoint and token to configure.
17
+ * @throws When the endpoint is not usable.
18
+ */
19
+ export function resolveEnrollment(input) {
20
+ const link = input.setupUrl ? parseEnrollmentUrl(input.setupUrl) : undefined;
21
+ if (link && input.token)
22
+ throw new Error('an enrollment URL signs in through the browser and takes no install key; drop --token / $AGENTWATCH_TOKEN');
23
+ if (link && input.endpoint)
24
+ throw new Error('an enrollment URL names its own backend; drop --endpoint');
25
+ const endpoint = link?.endpoint ?? input.endpoint ?? DEFAULT_ENDPOINT;
26
+ const trimmed = normalizeEndpoint(endpoint);
27
+ const origin = deliverableOrigin(trimmed);
28
+ if (!origin) {
29
+ throw new Error(`backend URL ${DELIVERABLE_URL_MESSAGE}, got ${endpoint}`);
30
+ }
31
+ // Before anything is written: a forged setup line must fail here, while the
32
+ // machine is still pointed where it was.
33
+ if (input.allowCustomEndpoint !== true && !isAllowedHost(trimmed, new Set(input.trustedOrigins))) {
34
+ throw new Error(`${origin} is not an Agent Watch host; nothing was written. If you trust it, re-run setup with --allow-custom-endpoint`);
35
+ }
36
+ return link ? { endpoint: trimmed, signIn: { organizationId: link.organizationId } } : { endpoint: trimmed, token: input.token };
37
+ }
38
+ /**
39
+ * Split an enrollment URL, `<backend>?organization=<uuid>`, into the backend and
40
+ * the organization's public id. The id is the only thing the link carries, so
41
+ * it is safe to share (SPEC R1).
42
+ *
43
+ * @param link - The URL given to `agentwatch setup`.
44
+ * @returns The backend origin and organization id.
45
+ * @throws When the link is not a URL or names no organization.
46
+ */
47
+ function parseEnrollmentUrl(link) {
48
+ const url = URL.canParse(link) ? new URL(link) : undefined;
49
+ const organizationId = url?.searchParams.get('organization') ?? '';
50
+ if (!url || !RE_ORGANIZATION_ID.test(organizationId))
51
+ throw new Error('enrollment URL must look like https://<backend>?organization=<organization id>');
52
+ // A backend under a path prefix keeps it, as `--endpoint` does.
53
+ return { endpoint: url.origin + url.pathname.replace(/\/+$/, ''), organizationId };
54
+ }
@@ -1,7 +1,3 @@
1
- /**
2
- * Acquiring an endpoint and credentials. The MVP ships the manual provider; the
3
- * abstraction is what lets a future remote enrollment slot in without touching
4
- * setup.
5
- */
6
- export type { EnrollmentInput, EnrollmentProvider, EnrollmentResult } from './types/enrollment.types.js';
7
- export { ManualEnrollmentProvider } from './manual-enrollment.js';
1
+ /** Acquiring an endpoint and credentials. */
2
+ export type { EnrollmentInput, EnrollmentResult } from './types/enrollment.types.js';
3
+ export { resolveEnrollment } from './enrollment.js';
@@ -1 +1 @@
1
- export { ManualEnrollmentProvider } from './manual-enrollment.js';
1
+ export { resolveEnrollment } from './enrollment.js';
@@ -1,25 +1,21 @@
1
- /**
2
- * Endpoint and credential acquisition.
3
- *
4
- * The MVP ships a manual provider — the user types a backend URL — and a future
5
- * RemoteEnrollmentProvider will implement `agentwatch setup <enrollment-url>`
6
- * (fetch org config, register the device, receive installation credentials)
7
- * without setup having to change.
8
- */
1
+ /** What `setup` has to work out before it can write a configuration. */
9
2
  export interface EnrollmentInput {
10
3
  /** URL passed to `agentwatch setup`, when any. */
11
4
  readonly setupUrl?: string;
12
5
  /** --endpoint flag, or the already-configured endpoint. */
13
6
  readonly endpoint?: string;
7
+ /** `--allow-custom-endpoint`: the endpoint may be outside the Agent Watch hosts. */
8
+ readonly allowCustomEndpoint?: boolean;
9
+ /** Origins this machine already trusts (`customEndpoints`); enough without the flag. */
10
+ readonly trustedOrigins?: readonly string[];
14
11
  /** --token flag, or the already-configured token. */
15
12
  readonly token?: string;
16
- /** Interactive prompt; undefined in non-interactive runs. */
17
- readonly ask?: (question: string) => Promise<string>;
18
13
  }
19
14
  export interface EnrollmentResult {
20
15
  readonly endpoint: string;
21
16
  readonly token?: string;
22
- }
23
- export interface EnrollmentProvider {
24
- enroll(input: EnrollmentInput): Promise<EnrollmentResult>;
17
+ /** Set when `setup` was given an enrollment URL: the machine signs in instead of using a key. */
18
+ readonly signIn?: {
19
+ readonly organizationId: string;
20
+ };
25
21
  }
@@ -12,3 +12,18 @@ export declare const HOME_PLACEHOLDER_PREFIX: string;
12
12
  export declare const REPO_ROOT_PLACEHOLDER = ".";
13
13
  /** Metadata key adapters use for the single primary file of a tool call. */
14
14
  export declare const FILE_PATH_METADATA_KEY = "filePath";
15
+ /**
16
+ * A tool call's file outside every checkout, home-relative (`~/Documents/a.xlsx`).
17
+ * Its own key so `filePath` keeps meaning repo-relative.
18
+ */
19
+ export declare const EXTERNAL_PATH_METADATA_KEY = "externalPath";
20
+ /**
21
+ * Metadata key naming the repository a tool call's file belongs to, relative
22
+ * to the cwd of the hook that resolved it.
23
+ *
24
+ * Local assembly state only: the turn tracker reads it to decide which
25
+ * repository a turn worked in, and it never reaches a product record.
26
+ */
27
+ export declare const REPOSITORY_PATH_METADATA_KEY = "repositoryPath";
28
+ /** Shared empty answer for a batch with no per-file repository to resolve. */
29
+ export declare const EMPTY_REPOSITORIES: ReadonlyMap<string, never>;
@@ -13,3 +13,18 @@ export const HOME_PLACEHOLDER_PREFIX = `~${path.sep}`;
13
13
  export const REPO_ROOT_PLACEHOLDER = '.';
14
14
  /** Metadata key adapters use for the single primary file of a tool call. */
15
15
  export const FILE_PATH_METADATA_KEY = 'filePath';
16
+ /**
17
+ * A tool call's file outside every checkout, home-relative (`~/Documents/a.xlsx`).
18
+ * Its own key so `filePath` keeps meaning repo-relative.
19
+ */
20
+ export const EXTERNAL_PATH_METADATA_KEY = 'externalPath';
21
+ /**
22
+ * Metadata key naming the repository a tool call's file belongs to, relative
23
+ * to the cwd of the hook that resolved it.
24
+ *
25
+ * Local assembly state only: the turn tracker reads it to decide which
26
+ * repository a turn worked in, and it never reaches a product record.
27
+ */
28
+ export const REPOSITORY_PATH_METADATA_KEY = 'repositoryPath';
29
+ /** Shared empty answer for a batch with no per-file repository to resolve. */
30
+ export const EMPTY_REPOSITORIES = new Map();
@@ -16,9 +16,13 @@ export declare const INTERNAL_HOOK_EVENT_TYPES: readonly ["session.started", "se
16
16
  * layer is an overlay on work items, and a team with no tracker connected has
17
17
  * none — the branches on a developer's machine are then the only evidence that
18
18
  * a piece of work exists. It carries no usage and is not accounted.
19
+ *
20
+ * `session.billing` states how the session's developer pays, once, when the
21
+ * session opens: a turn that never reaches its Stop hook has no summary to
22
+ * carry that fact, and its calls would be priced as metered spend (AWT-476).
19
23
  */
20
- export declare const PRODUCT_EVENT_TYPES: readonly ["llm.call", "turn.summary", "repo.snapshot"];
21
- export declare const CANONICAL_EVENT_TYPES: readonly ["session.started", "session.ended", "prompt.submitted", "tool.started", "tool.completed", "tool.failed", "permission.requested", "file.read", "file.edited", "shell.started", "shell.completed", "mcp.started", "mcp.completed", "subagent.started", "subagent.completed", "generation.completed", "compaction.started", "compaction.completed", "agent.error", "agent.other", "llm.call", "turn.summary", "repo.snapshot"];
24
+ export declare const PRODUCT_EVENT_TYPES: readonly ["llm.call", "turn.summary", "repo.snapshot", "session.billing"];
25
+ export declare const CANONICAL_EVENT_TYPES: readonly ["session.started", "session.ended", "prompt.submitted", "tool.started", "tool.completed", "tool.failed", "permission.requested", "file.read", "file.edited", "shell.started", "shell.completed", "mcp.started", "mcp.completed", "subagent.started", "subagent.completed", "generation.completed", "compaction.started", "compaction.completed", "agent.error", "agent.other", "llm.call", "turn.summary", "repo.snapshot", "session.billing"];
22
26
  /** O(1) membership for the hot path: queue drain checks this per entry. */
23
27
  export declare const PRODUCT_EVENT_TYPE_SET: ReadonlySet<string>;
24
28
  /** Canonical event types that close a turn. */
@@ -38,8 +38,12 @@ export const INTERNAL_HOOK_EVENT_TYPES = [
38
38
  * layer is an overlay on work items, and a team with no tracker connected has
39
39
  * none — the branches on a developer's machine are then the only evidence that
40
40
  * a piece of work exists. It carries no usage and is not accounted.
41
+ *
42
+ * `session.billing` states how the session's developer pays, once, when the
43
+ * session opens: a turn that never reaches its Stop hook has no summary to
44
+ * carry that fact, and its calls would be priced as metered spend (AWT-476).
41
45
  */
42
- export const PRODUCT_EVENT_TYPES = ['llm.call', 'turn.summary', 'repo.snapshot'];
46
+ export const PRODUCT_EVENT_TYPES = ['llm.call', 'turn.summary', 'repo.snapshot', 'session.billing'];
43
47
  export const CANONICAL_EVENT_TYPES = [...INTERNAL_HOOK_EVENT_TYPES, ...PRODUCT_EVENT_TYPES];
44
48
  /** O(1) membership for the hot path: queue drain checks this per entry. */
45
49
  export const PRODUCT_EVENT_TYPE_SET = new Set(PRODUCT_EVENT_TYPES);