@agent-watch-ai/edge 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/CHANGELOG.md +219 -9
  2. package/README.md +303 -4
  3. package/dist/billing/billing-mode.d.ts +37 -5
  4. package/dist/billing/billing-mode.js +28 -19
  5. package/dist/billing/constants/billing.constants.d.ts +0 -2
  6. package/dist/billing/constants/billing.constants.js +0 -2
  7. package/dist/billing/index.d.ts +2 -1
  8. package/dist/billing/index.js +1 -1
  9. package/dist/billing/session-billing.d.ts +3 -2
  10. package/dist/billing/session-billing.js +8 -8
  11. package/dist/billing/types/billing.types.d.ts +7 -0
  12. package/dist/capture/capture-env.d.ts +147 -0
  13. package/dist/capture/capture-env.js +301 -0
  14. package/dist/capture/captured-step.d.ts +88 -0
  15. package/dist/capture/captured-step.js +479 -0
  16. package/dist/capture/constants/capture.constants.d.ts +70 -0
  17. package/dist/capture/constants/capture.constants.js +72 -0
  18. package/dist/capture/launched-runs.d.ts +16 -0
  19. package/dist/capture/launched-runs.js +151 -0
  20. package/dist/capture/node.cjs +697 -0
  21. package/dist/capture/node.d.cts +32 -0
  22. package/dist/capture/python/sitecustomize.py +823 -0
  23. package/dist/capture/schemas/capture.schema.d.ts +35 -0
  24. package/dist/capture/schemas/capture.schema.js +31 -0
  25. package/dist/capture/types/capture.types.d.ts +20 -0
  26. package/dist/cli/constants/cli.constants.d.ts +2 -6
  27. package/dist/cli/constants/cli.constants.js +3 -7
  28. package/dist/cli/context.d.ts +19 -22
  29. package/dist/cli/context.js +23 -54
  30. package/dist/cli/doctor-run-capture.d.ts +13 -0
  31. package/dist/cli/doctor-run-capture.js +19 -0
  32. package/dist/cli/doctor.js +16 -67
  33. package/dist/cli/hook.d.ts +14 -0
  34. package/dist/cli/hook.js +40 -0
  35. package/dist/cli/index.d.ts +1 -1
  36. package/dist/cli/index.js +1 -1
  37. package/dist/cli/misc.js +10 -2
  38. package/dist/cli/replay.d.ts +33 -0
  39. package/dist/cli/replay.js +193 -0
  40. package/dist/cli/setup.d.ts +10 -2
  41. package/dist/cli/setup.js +154 -26
  42. package/dist/cli/status.js +45 -5
  43. package/dist/cli/toggle.js +10 -0
  44. package/dist/cli/types/cli.types.d.ts +15 -1
  45. package/dist/cli/uninstall.js +8 -22
  46. package/dist/cli.js +104 -17
  47. package/dist/config/config.d.ts +0 -2
  48. package/dist/config/config.js +0 -1
  49. package/dist/config/constants/config.constants.js +2 -0
  50. package/dist/config/events-transport.d.ts +15 -0
  51. package/dist/config/events-transport.js +29 -0
  52. package/dist/config/index.d.ts +2 -1
  53. package/dist/config/index.js +1 -0
  54. package/dist/config/root-config.d.ts +12 -0
  55. package/dist/config/root-config.js +24 -0
  56. package/dist/config/schemas/config.schema.d.ts +13 -0
  57. package/dist/config/schemas/config.schema.js +42 -6
  58. package/dist/config/types/config.types.d.ts +7 -0
  59. package/dist/core/index.d.ts +1 -1
  60. package/dist/core/index.js +1 -1
  61. package/dist/core/version.d.ts +9 -0
  62. package/dist/core/version.js +14 -0
  63. package/dist/core/which.d.ts +11 -0
  64. package/dist/core/which.js +18 -0
  65. package/dist/credentials/cloud-claim.d.ts +32 -0
  66. package/dist/credentials/cloud-claim.js +42 -0
  67. package/dist/credentials/constants/credentials.constants.d.ts +8 -1
  68. package/dist/credentials/constants/credentials.constants.js +9 -2
  69. package/dist/credentials/device-api.d.ts +15 -1
  70. package/dist/credentials/device-api.js +12 -1
  71. package/dist/credentials/sign-in.d.ts +27 -0
  72. package/dist/credentials/sign-in.js +31 -1
  73. package/dist/credentials/token-refresher.d.ts +5 -1
  74. package/dist/credentials/token-refresher.js +10 -2
  75. package/dist/events/constants/events.constants.d.ts +5 -2
  76. package/dist/events/constants/events.constants.js +4 -1
  77. package/dist/events/index.d.ts +1 -0
  78. package/dist/events/product-event.d.ts +6 -3
  79. package/dist/events/types/events.types.d.ts +6 -0
  80. package/dist/events/types/replay-progress.types.d.ts +26 -0
  81. package/dist/events/types/replay-progress.types.js +1 -0
  82. package/dist/events/types/repo-tree.types.d.ts +2 -1
  83. package/dist/feature/ticket-candidates.d.ts +1 -1
  84. package/dist/git/checkout-root.d.ts +15 -0
  85. package/dist/git/checkout-root.js +18 -0
  86. package/dist/git/code-state.d.ts +2 -16
  87. package/dist/git/code-state.js +11 -12
  88. package/dist/git/constants/git.constants.d.ts +31 -11
  89. package/dist/git/constants/git.constants.js +36 -12
  90. package/dist/git/fingerprint.d.ts +3 -6
  91. package/dist/git/fingerprint.js +5 -8
  92. package/dist/git/git-context.js +5 -1
  93. package/dist/git/index.d.ts +1 -2
  94. package/dist/git/index.js +1 -1
  95. package/dist/git/repo-snapshot.d.ts +13 -4
  96. package/dist/git/repo-snapshot.js +47 -9
  97. package/dist/git/types/snapshot.types.d.ts +2 -0
  98. package/dist/pipeline/constants/pipeline.constants.d.ts +3 -0
  99. package/dist/pipeline/constants/pipeline.constants.js +3 -0
  100. package/dist/pipeline/hook-pipeline.js +81 -57
  101. package/dist/privacy/product-capture.js +2 -0
  102. package/dist/providers/antigravity/antigravity.capture.d.ts +2 -0
  103. package/dist/providers/antigravity/antigravity.capture.js +5 -0
  104. package/dist/providers/antigravity/antigravity.detect.js +8 -22
  105. package/dist/providers/antigravity/antigravity.provider.js +10 -3
  106. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +1 -0
  107. package/dist/providers/antigravity/constants/antigravity.constants.js +1 -0
  108. package/dist/providers/claude/claude.adapter.js +9 -6
  109. package/dist/providers/claude/claude.detect.js +2 -17
  110. package/dist/providers/claude/claude.otel.d.ts +21 -3
  111. package/dist/providers/claude/claude.otel.js +216 -61
  112. package/dist/providers/claude/claude.provider.js +17 -1
  113. package/dist/providers/claude/claude.version.d.ts +9 -0
  114. package/dist/providers/claude/claude.version.js +28 -0
  115. package/dist/providers/claude/constants/claude.constants.d.ts +27 -0
  116. package/dist/providers/claude/constants/claude.constants.js +27 -0
  117. package/dist/providers/claude/constants/claude.otel.constants.d.ts +27 -0
  118. package/dist/providers/claude/constants/claude.otel.constants.js +45 -5
  119. package/dist/providers/claude/types/claude.types.d.ts +13 -0
  120. package/dist/providers/codex/codex.capture.d.ts +76 -0
  121. package/dist/providers/codex/codex.capture.js +454 -0
  122. package/dist/providers/codex/codex.detect.js +2 -4
  123. package/dist/providers/codex/codex.otel.d.ts +38 -2
  124. package/dist/providers/codex/codex.otel.js +50 -6
  125. package/dist/providers/codex/codex.provider.js +8 -0
  126. package/dist/providers/codex/codex.surface.d.ts +9 -0
  127. package/dist/{turns/codex-originator.js → providers/codex/codex.surface.js} +17 -3
  128. package/dist/providers/codex/codex.titles.d.ts +14 -0
  129. package/dist/providers/codex/codex.titles.js +35 -0
  130. package/dist/providers/codex/constants/codex.constants.d.ts +4 -0
  131. package/dist/providers/codex/constants/codex.constants.js +4 -0
  132. package/dist/providers/cursor/constants/cursor.constants.d.ts +17 -4
  133. package/dist/providers/cursor/constants/cursor.constants.js +25 -5
  134. package/dist/providers/cursor/cursor-mcp-memo.d.ts +34 -0
  135. package/dist/providers/cursor/cursor-mcp-memo.js +94 -0
  136. package/dist/providers/cursor/cursor.adapter.js +20 -82
  137. package/dist/providers/cursor/cursor.capture.d.ts +1 -0
  138. package/dist/providers/cursor/cursor.capture.js +4 -0
  139. package/dist/providers/cursor/cursor.detect.d.ts +5 -1
  140. package/dist/providers/cursor/cursor.detect.js +11 -26
  141. package/dist/providers/cursor/cursor.hooks.js +2 -2
  142. package/dist/providers/cursor/cursor.provider.js +16 -7
  143. package/dist/providers/cursor/cursor.titles.d.ts +14 -0
  144. package/dist/providers/cursor/cursor.titles.js +20 -0
  145. package/dist/providers/cursor/schemas/cursor.schema.d.ts +3 -3
  146. package/dist/providers/cursor/schemas/cursor.schema.js +5 -3
  147. package/dist/providers/gemini/constants/gemini.constants.d.ts +16 -0
  148. package/dist/providers/gemini/constants/gemini.constants.js +17 -0
  149. package/dist/providers/gemini/gemini.capture.d.ts +81 -0
  150. package/dist/providers/gemini/gemini.capture.js +210 -0
  151. package/dist/providers/gemini/gemini.detect.js +57 -24
  152. package/dist/providers/gemini/gemini.otel.d.ts +38 -2
  153. package/dist/providers/gemini/gemini.otel.js +56 -125
  154. package/dist/providers/gemini/gemini.provider.js +5 -0
  155. package/dist/providers/index.d.ts +1 -0
  156. package/dist/providers/index.js +1 -0
  157. package/dist/providers/provider.d.ts +8 -0
  158. package/dist/providers/provider.js +9 -0
  159. package/dist/providers/registry.d.ts +14 -0
  160. package/dist/providers/registry.js +14 -0
  161. package/dist/providers/shared/constants/hook-config.constants.d.ts +2 -0
  162. package/dist/providers/shared/constants/hook-config.constants.js +2 -0
  163. package/dist/providers/shared/constants/terminal-capture.constants.d.ts +6 -0
  164. package/dist/providers/shared/constants/terminal-capture.constants.js +6 -0
  165. package/dist/providers/shared/editor-paths.d.ts +8 -0
  166. package/dist/providers/shared/editor-paths.js +18 -0
  167. package/dist/providers/shared/hook-config.d.ts +5 -0
  168. package/dist/providers/shared/hook-config.js +39 -1
  169. package/dist/providers/shared/hooks-marker.d.ts +14 -0
  170. package/dist/providers/shared/hooks-marker.js +23 -0
  171. package/dist/providers/shared/install-record.d.ts +29 -0
  172. package/dist/providers/shared/install-record.js +52 -0
  173. package/dist/providers/shared/session-title-store.d.ts +23 -0
  174. package/dist/providers/shared/session-title-store.js +50 -0
  175. package/dist/providers/shared/terminal-capture.d.ts +41 -0
  176. package/dist/providers/shared/terminal-capture.js +109 -0
  177. package/dist/providers/shared/tooling.d.ts +21 -0
  178. package/dist/providers/shared/tooling.js +36 -1
  179. package/dist/providers/types/provider.types.d.ts +57 -4
  180. package/dist/replay/checkout-resolver.d.ts +29 -0
  181. package/dist/replay/checkout-resolver.js +69 -0
  182. package/dist/replay/codex-turns.d.ts +24 -0
  183. package/dist/replay/codex-turns.js +221 -0
  184. package/dist/replay/constants/replay.constants.d.ts +99 -0
  185. package/dist/replay/constants/replay.constants.js +102 -0
  186. package/dist/replay/describe.d.ts +10 -0
  187. package/dist/replay/describe.js +31 -0
  188. package/dist/replay/gemini-turns.d.ts +36 -0
  189. package/dist/replay/gemini-turns.js +192 -0
  190. package/dist/replay/machine.d.ts +34 -0
  191. package/dist/replay/machine.js +68 -0
  192. package/dist/replay/progress-event.d.ts +21 -0
  193. package/dist/replay/progress-event.js +45 -0
  194. package/dist/replay/replay-runner.d.ts +58 -0
  195. package/dist/replay/replay-runner.js +529 -0
  196. package/dist/replay/replay-scan.d.ts +83 -0
  197. package/dist/replay/replay-scan.js +170 -0
  198. package/dist/replay/replay-state.d.ts +108 -0
  199. package/dist/replay/replay-state.js +199 -0
  200. package/dist/replay/resume.d.ts +18 -0
  201. package/dist/replay/resume.js +34 -0
  202. package/dist/replay/start.d.ts +23 -0
  203. package/dist/replay/start.js +39 -0
  204. package/dist/replay/throttle.d.ts +35 -0
  205. package/dist/replay/throttle.js +41 -0
  206. package/dist/replay/transcript-turns.d.ts +35 -0
  207. package/dist/replay/transcript-turns.js +215 -0
  208. package/dist/replay/turn-event.d.ts +38 -0
  209. package/dist/replay/turn-event.js +116 -0
  210. package/dist/replay/types/replay.types.d.ts +162 -0
  211. package/dist/replay/types/replay.types.js +1 -0
  212. package/dist/replay/window.d.ts +28 -0
  213. package/dist/replay/window.js +41 -0
  214. package/dist/snapshot/branch-selection.d.ts +40 -23
  215. package/dist/snapshot/branch-selection.js +71 -41
  216. package/dist/snapshot/constants/snapshot-stages.constants.d.ts +3 -1
  217. package/dist/snapshot/constants/snapshot-stages.constants.js +3 -1
  218. package/dist/snapshot/constants/snapshot.constants.d.ts +34 -7
  219. package/dist/snapshot/constants/snapshot.constants.js +34 -7
  220. package/dist/snapshot/index.d.ts +2 -2
  221. package/dist/snapshot/index.js +1 -1
  222. package/dist/snapshot/snapshot-pipeline.js +89 -26
  223. package/dist/snapshot/snapshot-state.js +6 -2
  224. package/dist/snapshot/tree-pipeline.d.ts +1 -1
  225. package/dist/snapshot/tree-pipeline.js +34 -15
  226. package/dist/snapshot/types/snapshot.types.d.ts +20 -3
  227. package/dist/storage/schemas/storage.schema.d.ts +2 -0
  228. package/dist/storage/schemas/storage.schema.js +6 -0
  229. package/dist/transport/delivery-stats.d.ts +13 -1
  230. package/dist/transport/delivery-stats.js +18 -2
  231. package/dist/transport/delivery.d.ts +4 -3
  232. package/dist/transport/delivery.js +21 -7
  233. package/dist/transport/identity-delivery.d.ts +20 -0
  234. package/dist/transport/identity-delivery.js +41 -0
  235. package/dist/transport/index.d.ts +2 -0
  236. package/dist/transport/index.js +1 -0
  237. package/dist/transport/types/delivery-flow.types.d.ts +7 -0
  238. package/dist/turns/claude-transcript.js +4 -12
  239. package/dist/turns/codex-transcript.d.ts +9 -0
  240. package/dist/turns/codex-transcript.js +27 -19
  241. package/dist/turns/constants/turns.constants.d.ts +13 -12
  242. package/dist/turns/constants/turns.constants.js +15 -19
  243. package/dist/turns/gemini-transcript.d.ts +19 -1
  244. package/dist/turns/gemini-transcript.js +29 -18
  245. package/dist/turns/index.d.ts +3 -4
  246. package/dist/turns/index.js +2 -3
  247. package/dist/turns/run-state.d.ts +71 -0
  248. package/dist/turns/run-state.js +114 -0
  249. package/dist/turns/tool-events.d.ts +11 -1
  250. package/dist/turns/tool-events.js +32 -9
  251. package/dist/turns/transcript.d.ts +15 -14
  252. package/dist/turns/transcript.js +23 -4
  253. package/dist/turns/turn-state.d.ts +49 -7
  254. package/dist/turns/turn-state.js +78 -10
  255. package/dist/turns/turn-summary.js +7 -2
  256. package/dist/turns/turn-tracker.d.ts +9 -16
  257. package/dist/turns/turn-tracker.js +162 -86
  258. package/dist/turns/types/transcript.types.d.ts +11 -1
  259. package/dist/turns/types/turn-provider.types.d.ts +33 -0
  260. package/dist/turns/types/turn-provider.types.js +1 -0
  261. package/dist/turns/types/turn-state.types.d.ts +9 -0
  262. package/dist/turns/types/turn-summary.types.d.ts +17 -1
  263. package/dist/turns/types/turn-tracker.types.d.ts +3 -1
  264. package/dist/turns/work-checkout.js +1 -2
  265. package/docs/AUDIT_PROMPT.md +10 -0
  266. package/docs/DATA_HANDLING.md +193 -7
  267. package/docs/ENTERPRISE_DEPLOYMENT.md +1 -1
  268. package/docs/PERFORMANCE.md +10 -0
  269. package/package.json +3 -2
  270. package/dist/events/canonical-event.d.ts +0 -10
  271. package/dist/events/canonical-event.js +0 -9
  272. package/dist/git/repository-root.d.ts +0 -39
  273. package/dist/git/repository-root.js +0 -131
  274. package/dist/git/types/repository-root.types.d.ts +0 -11
  275. package/dist/transport/transport.d.ts +0 -6
  276. package/dist/turns/codex-originator.d.ts +0 -11
  277. package/dist/turns/cursor-transcript.d.ts +0 -21
  278. package/dist/turns/cursor-transcript.js +0 -66
  279. package/dist/turns/native-session-titles.d.ts +0 -26
  280. package/dist/turns/native-session-titles.js +0 -102
  281. /package/dist/{git/types/repository-root.types.js → billing/types/billing.types.js} +0 -0
  282. /package/dist/{transport/transport.js → capture/types/capture.types.js} +0 -0
@@ -1,16 +1,48 @@
1
1
  import type { Env } from '../core/types/core.types.js';
2
2
  import type { UsageBillingMode } from '../events/types/events.types.js';
3
+ import type { BillingSource } from './types/billing.types.js';
3
4
  /**
4
- * How the developer pays for this agent.
5
+ * How the developer pays for this agent, as its provider reads it.
5
6
  *
6
7
  * A flat subscription (Claude Pro/Max, a ChatGPT plan) and per-token API billing
7
8
  * price the same turn completely differently, so a summary that guessed would be
8
9
  * worse than one that admits it does not know. Only positively recognized states
9
- * are classified; every read problem, and every value we do not recognize,
10
- * degrades to 'unknown'.
10
+ * are classified; an agent with no reader, every read problem, and every value
11
+ * we do not recognize, degrades to 'unknown'.
11
12
  *
12
- * @param agentId - Internal provider id.
13
+ * @param source - The agent's provider; its `billingMode` reads the local auth state.
13
14
  * @param env - Environment supplying HOME and the relevant variables.
14
15
  * @returns The billing mode.
15
16
  */
16
- export declare function detectBillingMode(agentId: string, env: Env): Promise<UsageBillingMode>;
17
+ export declare function billingModeOf(source: BillingSource | undefined, env: Env): Promise<UsageBillingMode>;
18
+ /**
19
+ * The email of the Claude account signed in here (`oauthAccount.emailAddress`
20
+ * in `~/.claude.json`): who a Claude Code cloud VM claims its device for. The
21
+ * one reader of that field; anything that is not a plain address is none.
22
+ *
23
+ * @param home - The home directory holding `.claude.json`.
24
+ * @returns The email, or undefined.
25
+ */
26
+ export declare function claudeAccountEmail(home: string): Promise<string | undefined>;
27
+ /**
28
+ * Claude Code's billing arrangement. May throw on a read failure; `billingModeOf` catches.
29
+ *
30
+ * @param env - Environment supplying HOME and the relevant variables.
31
+ * @returns The billing mode.
32
+ */
33
+ export declare function claudeBillingMode(env: Env): Promise<UsageBillingMode>;
34
+ /**
35
+ * Codex's billing arrangement. May throw on a read failure; `billingModeOf` catches.
36
+ *
37
+ * @param env - Environment supplying HOME.
38
+ * @returns The billing mode.
39
+ */
40
+ export declare function codexBillingMode(env: Env): Promise<UsageBillingMode>;
41
+ /**
42
+ * The billing arrangement of an agent signed in through the shared Google
43
+ * account state (Gemini CLI, Antigravity). May throw on a read failure; `billingModeOf` catches.
44
+ *
45
+ * @param env - Environment supplying HOME and the relevant variables.
46
+ * @returns The billing mode.
47
+ */
48
+ export declare function googleAccountBillingMode(env: Env): Promise<UsageBillingMode>;
@@ -1,42 +1,51 @@
1
1
  import path from 'node:path';
2
2
  import { asRecord, firstString } from '../core/object.js';
3
+ import { RE_PLAIN_EMAIL } from '../credentials/constants/credentials.constants.js';
3
4
  import { sha256Hex } from '../events/event-id.js';
4
5
  import { readJsonFile } from '../storage/json-file.js';
5
- import { ANTHROPIC_API_KEY_VAR, API_MARKER, CLAUDE_API_KEY_RESPONSES_FIELD, CLAUDE_APPROVED_FIELD, CLAUDE_BEDROCK_VAR, CLAUDE_BILLING_TYPE_FIELD, CLAUDE_OAUTH_FIELD, CLAUDE_STATE_FILE, CLAUDE_VERTEX_VAR, CODEX_API_KEY_FIELD, CODEX_API_MODE, CODEX_AUTH_FILE, CODEX_AUTH_MODE_FIELD, CODEX_SUBSCRIPTION_MODE, FALSY_ENV_VALUES, GEMINI_API_KEY_FIELDS, GEMINI_API_KEY_VARS, GEMINI_MODE_FIELDS, GEMINI_OAUTH_FILE, GEMINI_SETTINGS_FILE, GOOGLE_ACCOUNT_AGENTS, MIN_APPROVAL_ENTRY_LENGTH, SUBSCRIPTION_MARKER } from './constants/billing.constants.js';
6
+ import { ANTHROPIC_API_KEY_VAR, API_MARKER, CLAUDE_API_KEY_RESPONSES_FIELD, CLAUDE_APPROVED_FIELD, CLAUDE_BEDROCK_VAR, CLAUDE_BILLING_TYPE_FIELD, CLAUDE_OAUTH_FIELD, CLAUDE_STATE_FILE, CLAUDE_VERTEX_VAR, CODEX_API_KEY_FIELD, CODEX_API_MODE, CODEX_AUTH_FILE, CODEX_AUTH_MODE_FIELD, CODEX_SUBSCRIPTION_MODE, FALSY_ENV_VALUES, GEMINI_API_KEY_FIELDS, GEMINI_API_KEY_VARS, GEMINI_MODE_FIELDS, GEMINI_OAUTH_FILE, GEMINI_SETTINGS_FILE, MIN_APPROVAL_ENTRY_LENGTH, SUBSCRIPTION_MARKER } from './constants/billing.constants.js';
6
7
  /**
7
- * How the developer pays for this agent.
8
+ * How the developer pays for this agent, as its provider reads it.
8
9
  *
9
10
  * A flat subscription (Claude Pro/Max, a ChatGPT plan) and per-token API billing
10
11
  * price the same turn completely differently, so a summary that guessed would be
11
12
  * worse than one that admits it does not know. Only positively recognized states
12
- * are classified; every read problem, and every value we do not recognize,
13
- * degrades to 'unknown'.
13
+ * are classified; an agent with no reader, every read problem, and every value
14
+ * we do not recognize, degrades to 'unknown'.
14
15
  *
15
- * @param agentId - Internal provider id.
16
+ * @param source - The agent's provider; its `billingMode` reads the local auth state.
16
17
  * @param env - Environment supplying HOME and the relevant variables.
17
18
  * @returns The billing mode.
18
19
  */
19
- export async function detectBillingMode(agentId, env) {
20
+ export async function billingModeOf(source, env) {
20
21
  try {
21
- if (agentId === 'claude')
22
- return await detectClaude(env);
23
- if (agentId === 'codex')
24
- return await detectCodex(env);
25
- if (GOOGLE_ACCOUNT_AGENTS.has(agentId))
26
- return await detectGoogleAccount(env);
22
+ return (await source?.billingMode?.(env)) ?? 'unknown';
27
23
  }
28
24
  catch {
29
25
  // Any read or parse failure: we simply do not know.
26
+ return 'unknown';
30
27
  }
31
- return 'unknown';
32
28
  }
33
29
  /**
34
- * Claude Code's billing arrangement.
30
+ * The email of the Claude account signed in here (`oauthAccount.emailAddress`
31
+ * in `~/.claude.json`): who a Claude Code cloud VM claims its device for. The
32
+ * one reader of that field; anything that is not a plain address is none.
33
+ *
34
+ * @param home - The home directory holding `.claude.json`.
35
+ * @returns The email, or undefined.
36
+ */
37
+ export async function claudeAccountEmail(home) {
38
+ const email = asRecord((await readRecord(path.join(home, CLAUDE_STATE_FILE)))?.[CLAUDE_OAUTH_FIELD])?.['emailAddress'];
39
+ const trimmed = typeof email === 'string' ? email.trim() : undefined;
40
+ return trimmed && RE_PLAIN_EMAIL.test(trimmed) ? trimmed : undefined;
41
+ }
42
+ /**
43
+ * Claude Code's billing arrangement. May throw on a read failure; `billingModeOf` catches.
35
44
  *
36
45
  * @param env - Environment supplying HOME and the relevant variables.
37
46
  * @returns The billing mode.
38
47
  */
39
- async function detectClaude(env) {
48
+ export async function claudeBillingMode(env) {
40
49
  // Bedrock and Vertex sessions always bill per token.
41
50
  if (isSet(env.vars[CLAUDE_BEDROCK_VAR]) || isSet(env.vars[CLAUDE_VERTEX_VAR]))
42
51
  return 'api';
@@ -74,12 +83,12 @@ function envApiKeyUsed(state, apiKey) {
74
83
  return approved.some((entry) => typeof entry === 'string' && entry.length >= MIN_APPROVAL_ENTRY_LENGTH && (hash.startsWith(entry) || apiKey.endsWith(entry)));
75
84
  }
76
85
  /**
77
- * Codex's billing arrangement.
86
+ * Codex's billing arrangement. May throw on a read failure; `billingModeOf` catches.
78
87
  *
79
88
  * @param env - Environment supplying HOME.
80
89
  * @returns The billing mode.
81
90
  */
82
- async function detectCodex(env) {
91
+ export async function codexBillingMode(env) {
83
92
  const auth = await readRecord(path.join(env.home, CODEX_AUTH_FILE));
84
93
  if (!auth)
85
94
  return 'unknown';
@@ -94,12 +103,12 @@ async function detectCodex(env) {
94
103
  }
95
104
  /**
96
105
  * The billing arrangement of an agent signed in through the shared Google
97
- * account state (Gemini CLI, Antigravity).
106
+ * account state (Gemini CLI, Antigravity). May throw on a read failure; `billingModeOf` catches.
98
107
  *
99
108
  * @param env - Environment supplying HOME and the relevant variables.
100
109
  * @returns The billing mode.
101
110
  */
102
- async function detectGoogleAccount(env) {
111
+ export async function googleAccountBillingMode(env) {
103
112
  if (GEMINI_API_KEY_VARS.some((name) => isSet(env.vars[name])))
104
113
  return 'api';
105
114
  const state = (await readRecord(path.join(env.home, GEMINI_SETTINGS_FILE))) ?? (await readRecord(path.join(env.home, GEMINI_OAUTH_FILE)));
@@ -33,5 +33,3 @@ export declare const API_MARKER = "api";
33
33
  export declare const MIN_APPROVAL_ENTRY_LENGTH = 8;
34
34
  /** Environment values that mean "not set", beyond an absent variable. */
35
35
  export declare const FALSY_ENV_VALUES: ReadonlySet<string>;
36
- /** Agent ids that authenticate through the shared ~/.gemini Google account. */
37
- export declare const GOOGLE_ACCOUNT_AGENTS: ReadonlySet<string>;
@@ -34,5 +34,3 @@ export const API_MARKER = 'api';
34
34
  export const MIN_APPROVAL_ENTRY_LENGTH = 8;
35
35
  /** Environment values that mean "not set", beyond an absent variable. */
36
36
  export const FALSY_ENV_VALUES = new Set(['', '0', 'false']);
37
- /** Agent ids that authenticate through the shared ~/.gemini Google account. */
38
- export const GOOGLE_ACCOUNT_AGENTS = new Set(['gemini', 'antigravity']);
@@ -3,4 +3,5 @@
3
3
  * state. A turn priced under the wrong arrangement is worse than one that
4
4
  * admits it does not know, so only positively recognized states are reported.
5
5
  */
6
- export { detectBillingMode } from './billing-mode.js';
6
+ export { billingModeOf } from './billing-mode.js';
7
+ export type { BillingSource } from './types/billing.types.js';
@@ -3,4 +3,4 @@
3
3
  * state. A turn priced under the wrong arrangement is worse than one that
4
4
  * admits it does not know, so only positively recognized states are reported.
5
5
  */
6
- export { detectBillingMode } from './billing-mode.js';
6
+ export { billingModeOf } from './billing-mode.js';
@@ -2,6 +2,7 @@ import type { Env } from '../core/types/core.types.js';
2
2
  import type { AgentWatchEvent } from '../events/types/events.types.js';
3
3
  import type { SessionBillingEvent } from '../events/types/session-billing.types.js';
4
4
  import type { TurnStateStore } from '../turns/turn-state.js';
5
+ import type { TurnProvider } from '../turns/types/turn-provider.types.js';
5
6
  /**
6
7
  * The session's billing fact, the first time it is asked for.
7
8
  *
@@ -10,10 +11,10 @@ import type { TurnStateStore } from '../turns/turn-state.js';
10
11
  *
11
12
  * @param store - Per-session state store; remembers that the fact was taken.
12
13
  * @param events - The hook's canonical events.
13
- * @param agentId - Internal provider id.
14
+ * @param provider - The agent the hook came from, for its billing reader.
14
15
  * @param env - Environment supplying HOME and the relevant variables.
15
16
  * @param surface - Product surface the session runs on.
16
17
  * @returns The event, or undefined when the session already has one, this hook
17
18
  * does not open anything, or the mode cannot be told.
18
19
  */
19
- export declare function sessionBillingFact(store: TurnStateStore, events: readonly AgentWatchEvent[], agentId: string, env: Env, surface: string): Promise<SessionBillingEvent | undefined>;
20
+ export declare function sessionBillingFact(store: TurnStateStore, events: readonly AgentWatchEvent[], provider: TurnProvider, env: Env, surface: string): Promise<SessionBillingEvent | undefined>;
@@ -1,8 +1,8 @@
1
1
  import { compact } from '../core/object.js';
2
2
  import { deriveEventId } from '../events/event-id.js';
3
3
  import { EVENT_SCHEMA_VERSION } from '../events/constants/events.constants.js';
4
- import { PROVIDER_LABELS } from '../turns/constants/turns.constants.js';
5
- import { detectBillingMode } from './billing-mode.js';
4
+ import { CANONICAL_PROVIDER_NAMES } from '../otlp/constants/otlp.constants.js';
5
+ import { billingModeOf } from './billing-mode.js';
6
6
  /** The hooks that open a session or a turn: the earliest a collector hears from it. */
7
7
  const OPENING_TYPES = new Set(['session.started', 'prompt.submitted']);
8
8
  /**
@@ -13,17 +13,17 @@ const OPENING_TYPES = new Set(['session.started', 'prompt.submitted']);
13
13
  *
14
14
  * @param store - Per-session state store; remembers that the fact was taken.
15
15
  * @param events - The hook's canonical events.
16
- * @param agentId - Internal provider id.
16
+ * @param provider - The agent the hook came from, for its billing reader.
17
17
  * @param env - Environment supplying HOME and the relevant variables.
18
18
  * @param surface - Product surface the session runs on.
19
19
  * @returns The event, or undefined when the session already has one, this hook
20
20
  * does not open anything, or the mode cannot be told.
21
21
  */
22
- export async function sessionBillingFact(store, events, agentId, env, surface) {
22
+ export async function sessionBillingFact(store, events, provider, env, surface) {
23
23
  const opening = events.find((event) => OPENING_TYPES.has(event.event.type) && event.session.id);
24
24
  if (!opening?.session.id)
25
25
  return undefined;
26
- const mode = await detectBillingMode(agentId, env);
26
+ const mode = await billingModeOf(provider, env);
27
27
  // Unknown is not a fact, and must not use up the session's one send.
28
28
  if (mode === 'unknown')
29
29
  return undefined;
@@ -36,15 +36,15 @@ export async function sessionBillingFact(store, events, agentId, env, surface) {
36
36
  return undefined;
37
37
  const timestamp = env.now().toISOString();
38
38
  // The public label, as the turn summary and the calls carry it.
39
- const provider = PROVIDER_LABELS[opening.agent.provider] ?? opening.agent.provider;
39
+ const label = CANONICAL_PROVIDER_NAMES[opening.agent.provider] ?? opening.agent.provider;
40
40
  return compact({
41
41
  schemaVersion: EVENT_SCHEMA_VERSION,
42
42
  id: deriveEventId({ provider: opening.agent.provider, providerEventType: 'session.billing', sessionId: opening.session.id }),
43
43
  timestamp,
44
44
  event: { type: 'session.billing', providerEventType: 'session.billing' },
45
- agent: { ...opening.agent, provider },
45
+ agent: { ...opening.agent, provider: label },
46
46
  session: { id: opening.session.id, providerId: opening.session.id },
47
- provider,
47
+ provider: label,
48
48
  surface,
49
49
  session_id: opening.session.id,
50
50
  billing_mode: mode
@@ -0,0 +1,7 @@
1
+ import type { Env } from '../../core/types/core.types.js';
2
+ import type { UsageBillingMode } from '../../events/types/events.types.js';
3
+ /** An agent that can tell how its developer pays; `AgentProvider` is one. */
4
+ export interface BillingSource {
5
+ /** Read the agent's local auth state. May throw; `billingModeOf` turns that into 'unknown'. */
6
+ readonly billingMode?: (env: Env) => Promise<UsageBillingMode>;
7
+ }
@@ -0,0 +1,147 @@
1
+ import type { Env } from '../core/types/core.types.js';
2
+ import type { CredentialFields } from '../credentials/types/credentials.types.js';
3
+ import type { RunCaptureStatus, SetupOutcome } from '../providers/types/provider.types.js';
4
+ type Shims = {
5
+ node: string;
6
+ python: string;
7
+ };
8
+ /**
9
+ * The shim paths inside this package, which the copy under the data dir is made from.
10
+ *
11
+ * @param root - The package root; tests name their own.
12
+ * @returns The file `--require` loads and the folder PYTHONPATH adds.
13
+ */
14
+ export declare function shimPaths(root?: string): Shims;
15
+ /**
16
+ * The two variables that load the shims, each kept beside the developer's own.
17
+ *
18
+ * An agent's env block replaces what the shell set, so a developer's value has to
19
+ * move in with ours or `--max-old-space-size` and their imports quietly vanish:
20
+ * the block's value when it has one, else the ambient one setup was run with.
21
+ *
22
+ * ponytail: the ambient value is copied once, at setup. A later change in the
23
+ * developer's shell is masked for what the agent runs until setup runs again; a
24
+ * `sh -c`-time merge (Claude Code's env file) would lift that, per agent.
25
+ *
26
+ * @param block - The agent's env block as it stands.
27
+ * @param ambient - The environment setup runs in.
28
+ * @param shims - The shim paths to load.
29
+ * @returns The two values; empty on Windows, where no ancestry can be read.
30
+ */
31
+ export declare function captureEnv(block: Record<string, unknown>, ambient: Record<string, string | undefined>, shims?: Shims): Record<string, string>;
32
+ /**
33
+ * Where the shims an agent's environment loads live: a copy under the data dir.
34
+ *
35
+ * A copy because a `--require` naming a missing file stops every Node the agent starts,
36
+ * Edge's own hook included, so nothing can repair it from inside. The package can go
37
+ * from under a path into it (`npm uninstall -g`, a removed nvm version, an upgrade's
38
+ * file swap); this one goes only with `agentwatch uninstall`.
39
+ *
40
+ * @param dataDir - The data dir.
41
+ * @returns The copy's shim paths.
42
+ */
43
+ export declare function copiedShims(dataDir: string): Shims;
44
+ /**
45
+ * Write the copy from this package, overwriting: every setup refreshes it after an update.
46
+ *
47
+ * Atomic per file, and the `--require` target last, so a Node starting meanwhile loads a
48
+ * whole file of one version or the other.
49
+ *
50
+ * @param dataDir - The data dir.
51
+ * @param source - The package's shims.
52
+ * @returns The copy's paths, or undefined when there is nothing to copy (an unbuilt checkout).
53
+ */
54
+ export declare function installCaptureCopy(dataDir: string, source?: Shims): Promise<Shims | undefined>;
55
+ /**
56
+ * Remove the copy, once no agent can still be loading it.
57
+ *
58
+ * Every agent shares the one copy, and a missing `--require` target stops every Node an
59
+ * agent starts, so it stays while either holds. Hooks: `agentwatch off`, the exporter sweep
60
+ * and `otel: none` take the env keys out and leave the hooks, with sessions still running
61
+ * that hold the `--require`; a detection that fails counts as installed. A config naming the
62
+ * copy: a removal that was refused leaves the keys, and a hook file that does not parse
63
+ * reads as no hooks. A copy left behind costs nothing.
64
+ *
65
+ * @param dataDir - The data dir.
66
+ * @param env - Environment supplying where each agent keeps its hooks and config.
67
+ */
68
+ export declare function removeCaptureCopy(dataDir: string, env: Env): Promise<void>;
69
+ /**
70
+ * Refresh the copy, and point an env block at it.
71
+ *
72
+ * @param block - The agent's env block as it stands.
73
+ * @param ambient - The environment setup runs in.
74
+ * @param dataDir - The data dir.
75
+ * @param source - The package's shims.
76
+ * @returns The block with the copy loaded; with no copy to load, the block with any
77
+ * earlier `--require` of ours taken out, since it could stop every Node.
78
+ */
79
+ export declare function installedCaptureEnv(block: Record<string, unknown>, ambient: Record<string, string | undefined>, dataDir: string, source?: Shims): Promise<Record<string, unknown>>;
80
+ /**
81
+ * An env block as setup should leave it.
82
+ *
83
+ * @param block - The agent's env block as it stands.
84
+ * @param ambient - The environment setup runs in.
85
+ * @param installed - Whether the shims are on disk.
86
+ * @param shims - The shim paths to load.
87
+ * @returns The next block.
88
+ */
89
+ export declare function capturedBlock(block: Record<string, unknown>, ambient: Record<string, string | undefined>, installed: boolean, shims?: Shims): Record<string, unknown>;
90
+ /**
91
+ * An env block with only our part of the two variables gone.
92
+ *
93
+ * @param block - The agent's env block.
94
+ * @param shims - This install's shim paths.
95
+ * @returns The block; a variable left empty is removed, a developer's value stays.
96
+ */
97
+ export declare function withoutCaptureEnv(block: Record<string, unknown>, shims?: Shims): Record<string, unknown>;
98
+ /**
99
+ * Whether the config is a link, usually into a dotfiles repository.
100
+ *
101
+ * Capture leaves one alone. Through the link, a machine-specific `--require` would reach
102
+ * every machine sharing the file, and it stops every Node where the copy is missing. In
103
+ * place of the link, the developer's file would quietly stop being the one in use.
104
+ *
105
+ * @param file - The config file.
106
+ * @returns True when it is a symbolic link.
107
+ */
108
+ export declare function isLinkedConfig(file: string): Promise<boolean>;
109
+ /**
110
+ * Why a linked config gets no capture.
111
+ *
112
+ * @param file - The config file.
113
+ * @returns The sentence for setup, status and doctor.
114
+ */
115
+ export declare function linkedConfigReason(file: string): string;
116
+ /**
117
+ * A capture write whose throw (a full disk, a read-only file) is said, not raised, for the
118
+ * reason `withCaptureOutcome` gives.
119
+ *
120
+ * @param step - The write.
121
+ * @returns Its outcome, or one naming what went wrong.
122
+ */
123
+ export declare function skippedOnError(step: Promise<SetupOutcome>): Promise<SetupOutcome>;
124
+ /**
125
+ * An agent's outcome with its run-capture step folded in.
126
+ *
127
+ * A capture step that cannot write says so and stays `ok`: it must not count as a failure
128
+ * of setup or `agentwatch on`, which would roll back every agent over one optional key. Only
129
+ * a removal that leaves our keys behind reports `ok: false`.
130
+ *
131
+ * @param outcome - What the agent's own step reported.
132
+ * @param capture - What the capture step reported.
133
+ * @returns The outcome the command prints.
134
+ */
135
+ export declare function withCaptureOutcome(outcome: SetupOutcome, capture: SetupOutcome): SetupOutcome;
136
+ /**
137
+ * Whether an agent's environment loads the shims, and when not, why.
138
+ *
139
+ * @param block - The env block the agent runs with.
140
+ * @param config - The credential that would deliver what is captured.
141
+ * @param telemetryOn - Whether this machine's config allows the agent's telemetry.
142
+ * @param dataDir - The data dir holding the copy.
143
+ * @param source - The package's shims, which the copy should match.
144
+ * @returns On, or off with the reason; on with a warning when the copy is stale.
145
+ */
146
+ export declare function inspectCaptureEnv(block: Record<string, unknown>, config: CredentialFields, telemetryOn: boolean, dataDir: string, source?: Shims): Promise<RunCaptureStatus>;
147
+ export {};