@agent-watch-ai/edge 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/CHANGELOG.md +288 -9
  2. package/README.md +307 -5
  3. package/dist/billing/billing-mode.d.ts +37 -5
  4. package/dist/billing/billing-mode.js +28 -19
  5. package/dist/billing/constants/billing.constants.d.ts +0 -2
  6. package/dist/billing/constants/billing.constants.js +0 -2
  7. package/dist/billing/index.d.ts +2 -1
  8. package/dist/billing/index.js +1 -1
  9. package/dist/billing/session-billing.d.ts +7 -3
  10. package/dist/billing/session-billing.js +34 -13
  11. package/dist/billing/types/billing.types.d.ts +7 -0
  12. package/dist/capture/capture-env.d.ts +147 -0
  13. package/dist/capture/capture-env.js +301 -0
  14. package/dist/capture/captured-step.d.ts +88 -0
  15. package/dist/capture/captured-step.js +503 -0
  16. package/dist/capture/constants/capture.constants.d.ts +85 -0
  17. package/dist/capture/constants/capture.constants.js +87 -0
  18. package/dist/capture/launched-runs.d.ts +43 -0
  19. package/dist/capture/launched-runs.js +157 -0
  20. package/dist/capture/node.cjs +697 -0
  21. package/dist/capture/node.d.cts +32 -0
  22. package/dist/capture/python/sitecustomize.py +832 -0
  23. package/dist/capture/schemas/capture.schema.d.ts +35 -0
  24. package/dist/capture/schemas/capture.schema.js +31 -0
  25. package/dist/capture/types/capture.types.d.ts +20 -0
  26. package/dist/capture/venv-loader.d.ts +68 -0
  27. package/dist/capture/venv-loader.js +189 -0
  28. package/dist/cli/constants/cli.constants.d.ts +23 -6
  29. package/dist/cli/constants/cli.constants.js +24 -7
  30. package/dist/cli/context.d.ts +19 -22
  31. package/dist/cli/context.js +23 -54
  32. package/dist/cli/doctor-run-capture.d.ts +21 -0
  33. package/dist/cli/doctor-run-capture.js +33 -0
  34. package/dist/cli/doctor.js +21 -68
  35. package/dist/cli/hook-check.d.ts +7 -2
  36. package/dist/cli/hook-check.js +30 -15
  37. package/dist/cli/hook.d.ts +14 -0
  38. package/dist/cli/hook.js +82 -1
  39. package/dist/cli/index.d.ts +1 -1
  40. package/dist/cli/index.js +1 -1
  41. package/dist/cli/misc.js +10 -2
  42. package/dist/cli/npm-global.d.ts +24 -0
  43. package/dist/cli/npm-global.js +77 -0
  44. package/dist/cli/npx-install.js +22 -6
  45. package/dist/cli/replay.d.ts +33 -0
  46. package/dist/cli/replay.js +228 -0
  47. package/dist/cli/setup.d.ts +10 -2
  48. package/dist/cli/setup.js +200 -31
  49. package/dist/cli/status.js +45 -5
  50. package/dist/cli/toggle.js +10 -0
  51. package/dist/cli/types/cli.types.d.ts +15 -1
  52. package/dist/cli/uninstall.js +42 -23
  53. package/dist/cli/update.js +3 -2
  54. package/dist/cli.js +104 -17
  55. package/dist/config/config-store.d.ts +15 -4
  56. package/dist/config/config-store.js +31 -7
  57. package/dist/config/config.d.ts +0 -2
  58. package/dist/config/config.js +0 -1
  59. package/dist/config/constants/config.constants.d.ts +8 -1
  60. package/dist/config/constants/config.constants.js +10 -1
  61. package/dist/config/events-transport.d.ts +15 -0
  62. package/dist/config/events-transport.js +29 -0
  63. package/dist/config/index.d.ts +2 -1
  64. package/dist/config/index.js +1 -0
  65. package/dist/config/root-config.d.ts +12 -0
  66. package/dist/config/root-config.js +24 -0
  67. package/dist/config/schemas/config.schema.d.ts +15 -2
  68. package/dist/config/schemas/config.schema.js +52 -8
  69. package/dist/config/types/config.types.d.ts +7 -0
  70. package/dist/core/index.d.ts +1 -1
  71. package/dist/core/index.js +1 -1
  72. package/dist/core/version.d.ts +9 -0
  73. package/dist/core/version.js +14 -0
  74. package/dist/core/which.d.ts +11 -0
  75. package/dist/core/which.js +18 -0
  76. package/dist/credentials/cloud-claim.d.ts +34 -0
  77. package/dist/credentials/cloud-claim.js +61 -0
  78. package/dist/credentials/constants/credentials.constants.d.ts +16 -1
  79. package/dist/credentials/constants/credentials.constants.js +17 -2
  80. package/dist/credentials/credential-status.js +1 -1
  81. package/dist/credentials/credentials.d.ts +3 -3
  82. package/dist/credentials/credentials.js +26 -12
  83. package/dist/credentials/device-api.d.ts +15 -1
  84. package/dist/credentials/device-api.js +12 -1
  85. package/dist/credentials/identity.d.ts +2 -2
  86. package/dist/credentials/identity.js +2 -2
  87. package/dist/credentials/install-key.d.ts +31 -0
  88. package/dist/credentials/install-key.js +58 -0
  89. package/dist/credentials/migration.d.ts +9 -7
  90. package/dist/credentials/migration.js +58 -18
  91. package/dist/credentials/secret-store.d.ts +12 -0
  92. package/dist/credentials/secret-store.js +18 -1
  93. package/dist/credentials/sign-in.d.ts +27 -0
  94. package/dist/credentials/sign-in.js +31 -1
  95. package/dist/credentials/token-refresher.d.ts +5 -1
  96. package/dist/credentials/token-refresher.js +10 -2
  97. package/dist/enforcement/enforcement.js +1 -1
  98. package/dist/events/constants/events.constants.d.ts +5 -2
  99. package/dist/events/constants/events.constants.js +4 -1
  100. package/dist/events/enrich.d.ts +14 -0
  101. package/dist/events/enrich.js +1 -1
  102. package/dist/events/index.d.ts +1 -0
  103. package/dist/events/product-event.d.ts +6 -3
  104. package/dist/events/types/events.types.d.ts +6 -0
  105. package/dist/events/types/replay-progress.types.d.ts +26 -0
  106. package/dist/events/types/replay-progress.types.js +1 -0
  107. package/dist/events/types/repo-tree.types.d.ts +2 -1
  108. package/dist/feature/ticket-candidates.d.ts +1 -1
  109. package/dist/git/checkout-root.d.ts +15 -0
  110. package/dist/git/checkout-root.js +18 -0
  111. package/dist/git/code-state.d.ts +2 -16
  112. package/dist/git/code-state.js +11 -12
  113. package/dist/git/constants/git.constants.d.ts +33 -11
  114. package/dist/git/constants/git.constants.js +45 -12
  115. package/dist/git/fingerprint.d.ts +3 -6
  116. package/dist/git/fingerprint.js +5 -8
  117. package/dist/git/git-context.js +5 -1
  118. package/dist/git/index.d.ts +1 -2
  119. package/dist/git/index.js +1 -1
  120. package/dist/git/repo-snapshot.d.ts +13 -4
  121. package/dist/git/repo-snapshot.js +53 -9
  122. package/dist/git/types/snapshot.types.d.ts +6 -0
  123. package/dist/pipeline/constants/pipeline.constants.d.ts +3 -0
  124. package/dist/pipeline/constants/pipeline.constants.js +3 -0
  125. package/dist/pipeline/hook-pipeline.js +82 -57
  126. package/dist/privacy/product-capture.js +2 -0
  127. package/dist/providers/antigravity/antigravity.capture.d.ts +2 -0
  128. package/dist/providers/antigravity/antigravity.capture.js +5 -0
  129. package/dist/providers/antigravity/antigravity.detect.js +8 -22
  130. package/dist/providers/antigravity/antigravity.provider.js +10 -3
  131. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +1 -0
  132. package/dist/providers/antigravity/constants/antigravity.constants.js +1 -0
  133. package/dist/providers/claude/claude.adapter.js +9 -6
  134. package/dist/providers/claude/claude.detect.js +2 -17
  135. package/dist/providers/claude/claude.otel.d.ts +21 -3
  136. package/dist/providers/claude/claude.otel.js +216 -61
  137. package/dist/providers/claude/claude.provider.js +21 -1
  138. package/dist/providers/claude/claude.version.d.ts +9 -0
  139. package/dist/providers/claude/claude.version.js +28 -0
  140. package/dist/providers/claude/constants/claude.constants.d.ts +27 -0
  141. package/dist/providers/claude/constants/claude.constants.js +27 -0
  142. package/dist/providers/claude/constants/claude.otel.constants.d.ts +27 -0
  143. package/dist/providers/claude/constants/claude.otel.constants.js +45 -5
  144. package/dist/providers/claude/types/claude.types.d.ts +13 -0
  145. package/dist/providers/codex/codex.capture.d.ts +76 -0
  146. package/dist/providers/codex/codex.capture.js +454 -0
  147. package/dist/providers/codex/codex.detect.js +2 -4
  148. package/dist/providers/codex/codex.otel.d.ts +38 -2
  149. package/dist/providers/codex/codex.otel.js +50 -6
  150. package/dist/providers/codex/codex.provider.js +8 -0
  151. package/dist/providers/codex/codex.surface.d.ts +9 -0
  152. package/dist/{turns/codex-originator.js → providers/codex/codex.surface.js} +17 -3
  153. package/dist/providers/codex/codex.titles.d.ts +14 -0
  154. package/dist/providers/codex/codex.titles.js +35 -0
  155. package/dist/providers/codex/constants/codex.constants.d.ts +4 -0
  156. package/dist/providers/codex/constants/codex.constants.js +4 -0
  157. package/dist/providers/cursor/constants/cursor.constants.d.ts +17 -4
  158. package/dist/providers/cursor/constants/cursor.constants.js +25 -5
  159. package/dist/providers/cursor/cursor-mcp-memo.d.ts +34 -0
  160. package/dist/providers/cursor/cursor-mcp-memo.js +94 -0
  161. package/dist/providers/cursor/cursor.adapter.js +20 -82
  162. package/dist/providers/cursor/cursor.capture.d.ts +1 -0
  163. package/dist/providers/cursor/cursor.capture.js +4 -0
  164. package/dist/providers/cursor/cursor.detect.d.ts +5 -1
  165. package/dist/providers/cursor/cursor.detect.js +11 -26
  166. package/dist/providers/cursor/cursor.hooks.js +2 -2
  167. package/dist/providers/cursor/cursor.provider.js +16 -7
  168. package/dist/providers/cursor/cursor.titles.d.ts +14 -0
  169. package/dist/providers/cursor/cursor.titles.js +20 -0
  170. package/dist/providers/cursor/schemas/cursor.schema.d.ts +3 -3
  171. package/dist/providers/cursor/schemas/cursor.schema.js +5 -3
  172. package/dist/providers/gemini/constants/gemini.constants.d.ts +16 -0
  173. package/dist/providers/gemini/constants/gemini.constants.js +17 -0
  174. package/dist/providers/gemini/gemini.capture.d.ts +81 -0
  175. package/dist/providers/gemini/gemini.capture.js +210 -0
  176. package/dist/providers/gemini/gemini.detect.js +57 -24
  177. package/dist/providers/gemini/gemini.otel.d.ts +38 -2
  178. package/dist/providers/gemini/gemini.otel.js +56 -125
  179. package/dist/providers/gemini/gemini.provider.js +5 -0
  180. package/dist/providers/index.d.ts +1 -0
  181. package/dist/providers/index.js +1 -0
  182. package/dist/providers/provider.d.ts +8 -0
  183. package/dist/providers/provider.js +9 -0
  184. package/dist/providers/registry.d.ts +14 -0
  185. package/dist/providers/registry.js +14 -0
  186. package/dist/providers/shared/constants/hook-config.constants.d.ts +2 -0
  187. package/dist/providers/shared/constants/hook-config.constants.js +2 -0
  188. package/dist/providers/shared/constants/terminal-capture.constants.d.ts +6 -0
  189. package/dist/providers/shared/constants/terminal-capture.constants.js +6 -0
  190. package/dist/providers/shared/editor-paths.d.ts +8 -0
  191. package/dist/providers/shared/editor-paths.js +18 -0
  192. package/dist/providers/shared/hook-config.d.ts +5 -0
  193. package/dist/providers/shared/hook-config.js +39 -1
  194. package/dist/providers/shared/hooks-marker.d.ts +14 -0
  195. package/dist/providers/shared/hooks-marker.js +23 -0
  196. package/dist/providers/shared/install-record.d.ts +29 -0
  197. package/dist/providers/shared/install-record.js +52 -0
  198. package/dist/providers/shared/session-title-store.d.ts +23 -0
  199. package/dist/providers/shared/session-title-store.js +50 -0
  200. package/dist/providers/shared/terminal-capture.d.ts +41 -0
  201. package/dist/providers/shared/terminal-capture.js +109 -0
  202. package/dist/providers/shared/tooling.d.ts +21 -0
  203. package/dist/providers/shared/tooling.js +36 -1
  204. package/dist/providers/types/provider.types.d.ts +57 -4
  205. package/dist/replay/checkout-resolver.d.ts +56 -0
  206. package/dist/replay/checkout-resolver.js +173 -0
  207. package/dist/replay/codex-turns.d.ts +24 -0
  208. package/dist/replay/codex-turns.js +221 -0
  209. package/dist/replay/constants/replay.constants.d.ts +99 -0
  210. package/dist/replay/constants/replay.constants.js +102 -0
  211. package/dist/replay/describe.d.ts +10 -0
  212. package/dist/replay/describe.js +31 -0
  213. package/dist/replay/gemini-turns.d.ts +36 -0
  214. package/dist/replay/gemini-turns.js +192 -0
  215. package/dist/replay/machine.d.ts +34 -0
  216. package/dist/replay/machine.js +68 -0
  217. package/dist/replay/progress-event.d.ts +21 -0
  218. package/dist/replay/progress-event.js +45 -0
  219. package/dist/replay/replay-runner.d.ts +60 -0
  220. package/dist/replay/replay-runner.js +581 -0
  221. package/dist/replay/replay-scan.d.ts +84 -0
  222. package/dist/replay/replay-scan.js +182 -0
  223. package/dist/replay/replay-state.d.ts +108 -0
  224. package/dist/replay/replay-state.js +199 -0
  225. package/dist/replay/resume.d.ts +18 -0
  226. package/dist/replay/resume.js +34 -0
  227. package/dist/replay/start.d.ts +23 -0
  228. package/dist/replay/start.js +39 -0
  229. package/dist/replay/throttle.d.ts +36 -0
  230. package/dist/replay/throttle.js +44 -0
  231. package/dist/replay/transcript-turns.d.ts +35 -0
  232. package/dist/replay/transcript-turns.js +241 -0
  233. package/dist/replay/turn-event.d.ts +40 -0
  234. package/dist/replay/turn-event.js +127 -0
  235. package/dist/replay/types/replay.types.d.ts +198 -0
  236. package/dist/replay/types/replay.types.js +1 -0
  237. package/dist/replay/window.d.ts +28 -0
  238. package/dist/replay/window.js +41 -0
  239. package/dist/replay/worktree-map.d.ts +42 -0
  240. package/dist/replay/worktree-map.js +134 -0
  241. package/dist/snapshot/branch-selection.d.ts +40 -23
  242. package/dist/snapshot/branch-selection.js +71 -41
  243. package/dist/snapshot/constants/snapshot-stages.constants.d.ts +3 -1
  244. package/dist/snapshot/constants/snapshot-stages.constants.js +3 -1
  245. package/dist/snapshot/constants/snapshot.constants.d.ts +34 -7
  246. package/dist/snapshot/constants/snapshot.constants.js +34 -7
  247. package/dist/snapshot/index.d.ts +2 -2
  248. package/dist/snapshot/index.js +1 -1
  249. package/dist/snapshot/snapshot-pipeline.js +100 -26
  250. package/dist/snapshot/snapshot-state.js +6 -2
  251. package/dist/snapshot/tree-pipeline.d.ts +1 -1
  252. package/dist/snapshot/tree-pipeline.js +34 -15
  253. package/dist/snapshot/types/snapshot.types.d.ts +22 -3
  254. package/dist/storage/schemas/storage.schema.d.ts +2 -0
  255. package/dist/storage/schemas/storage.schema.js +6 -0
  256. package/dist/transport/delivery-stats.d.ts +13 -1
  257. package/dist/transport/delivery-stats.js +18 -2
  258. package/dist/transport/delivery.d.ts +4 -3
  259. package/dist/transport/delivery.js +21 -7
  260. package/dist/transport/identity-delivery.d.ts +20 -0
  261. package/dist/transport/identity-delivery.js +41 -0
  262. package/dist/transport/index.d.ts +2 -0
  263. package/dist/transport/index.js +1 -0
  264. package/dist/transport/types/delivery-flow.types.d.ts +7 -0
  265. package/dist/turns/claude-transcript.js +4 -12
  266. package/dist/turns/codex-transcript.d.ts +9 -0
  267. package/dist/turns/codex-transcript.js +27 -19
  268. package/dist/turns/constants/turns.constants.d.ts +29 -12
  269. package/dist/turns/constants/turns.constants.js +31 -19
  270. package/dist/turns/gemini-transcript.d.ts +19 -1
  271. package/dist/turns/gemini-transcript.js +29 -18
  272. package/dist/turns/index.d.ts +3 -4
  273. package/dist/turns/index.js +2 -3
  274. package/dist/turns/run-state.d.ts +71 -0
  275. package/dist/turns/run-state.js +114 -0
  276. package/dist/turns/tool-events.d.ts +11 -1
  277. package/dist/turns/tool-events.js +32 -9
  278. package/dist/turns/transcript.d.ts +15 -14
  279. package/dist/turns/transcript.js +23 -4
  280. package/dist/turns/turn-state.d.ts +82 -7
  281. package/dist/turns/turn-state.js +157 -10
  282. package/dist/turns/turn-summary.js +7 -2
  283. package/dist/turns/turn-tracker.d.ts +9 -16
  284. package/dist/turns/turn-tracker.js +163 -87
  285. package/dist/turns/types/transcript.types.d.ts +11 -1
  286. package/dist/turns/types/turn-provider.types.d.ts +33 -0
  287. package/dist/turns/types/turn-provider.types.js +1 -0
  288. package/dist/turns/types/turn-state.types.d.ts +9 -0
  289. package/dist/turns/types/turn-summary.types.d.ts +17 -1
  290. package/dist/turns/types/turn-tracker.types.d.ts +3 -1
  291. package/dist/turns/work-checkout.js +1 -2
  292. package/docs/AUDIT_PROMPT.md +10 -0
  293. package/docs/DATA_HANDLING.md +201 -13
  294. package/docs/ENTERPRISE_DEPLOYMENT.md +3 -3
  295. package/docs/PERFORMANCE.md +10 -0
  296. package/package.json +3 -2
  297. package/dist/events/canonical-event.d.ts +0 -10
  298. package/dist/events/canonical-event.js +0 -9
  299. package/dist/git/repository-root.d.ts +0 -39
  300. package/dist/git/repository-root.js +0 -131
  301. package/dist/git/types/repository-root.types.d.ts +0 -11
  302. package/dist/transport/transport.d.ts +0 -6
  303. package/dist/turns/codex-originator.d.ts +0 -11
  304. package/dist/turns/cursor-transcript.d.ts +0 -21
  305. package/dist/turns/cursor-transcript.js +0 -66
  306. package/dist/turns/native-session-titles.d.ts +0 -26
  307. package/dist/turns/native-session-titles.js +0 -102
  308. /package/dist/{git/types/repository-root.types.js → billing/types/billing.types.js} +0 -0
  309. /package/dist/{transport/transport.js → capture/types/capture.types.js} +0 -0
@@ -49,8 +49,8 @@ export declare function identityFingerprint(identity: string): string;
49
49
  /**
50
50
  * The device credential that stands for this config's identity, if any.
51
51
  *
52
- * The install key stays beside its device in the config through the migration
53
- * window, to enroll again when the secret expires. A device whose
52
+ * A key and a device side by side are one identity until the exchange moves
53
+ * the key to the store (or an older edge left it there). A device whose
54
54
  * id is not that key's is a leftover from an earlier key and stands for
55
55
  * nothing.
56
56
  *
@@ -63,8 +63,8 @@ export function identityFingerprint(identity) {
63
63
  /**
64
64
  * The device credential that stands for this config's identity, if any.
65
65
  *
66
- * The install key stays beside its device in the config through the migration
67
- * window, to enroll again when the secret expires. A device whose
66
+ * A key and a device side by side are one identity until the exchange moves
67
+ * the key to the store (or an older edge left it there). A device whose
68
68
  * id is not that key's is a leftover from an earlier key and stands for
69
69
  * nothing.
70
70
  *
@@ -0,0 +1,31 @@
1
+ import type { CredentialContext, DeviceCredentialRef } from './types/credentials.types.js';
2
+ /**
3
+ * Move an install key from the config into its device's secret store.
4
+ *
5
+ * The key is needed again only when the device secret expires, so it lives
6
+ * where the secret does, not in plain text in `config.json`. The config entry
7
+ * keeps it until the store has proven it holds the key, so a failed write never
8
+ * loses it. Never throws.
9
+ *
10
+ * @param ctx - Paths, environment, timeout and keychain runner.
11
+ * @param installKey - The key that was exchanged.
12
+ * @param device - The device it was exchanged for.
13
+ * @param waitMs - How long to wait for the config lock.
14
+ * @returns True when the store holds the key and the config was updated.
15
+ */
16
+ export declare function retireInstallKey(ctx: CredentialContext, installKey: string, device: DeviceCredentialRef, waitMs: number): Promise<boolean>;
17
+ /**
18
+ * The install key a device was exchanged for, from its secret store.
19
+ *
20
+ * @param ctx - Paths, environment, timeout and keychain runner.
21
+ * @param device - The device.
22
+ * @returns The key, or undefined (a sign-in device has none).
23
+ */
24
+ export declare function storedInstallKey(ctx: CredentialContext, device: DeviceCredentialRef): Promise<string | undefined>;
25
+ /**
26
+ * Remove the install key kept for a device, if any.
27
+ *
28
+ * @param ctx - Paths, environment, timeout and keychain runner.
29
+ * @param device - The device being forgotten.
30
+ */
31
+ export declare function forgetInstallKey(ctx: CredentialContext, device: DeviceCredentialRef): Promise<void>;
@@ -0,0 +1,58 @@
1
+ import { detachInstallKey } from '../config/config-store.js';
2
+ import { debugLog } from '../core/logger.js';
3
+ import { INSTALL_KEY_ACCOUNT_SUFFIX } from './constants/credentials.constants.js';
4
+ import { secretStoreFor, storeVerified } from './secret-store.js';
5
+ /**
6
+ * The account (or file name) a device's install key is kept under, beside its secret.
7
+ *
8
+ * @param device - The device.
9
+ * @returns The account name.
10
+ */
11
+ function installKeyAccount(device) {
12
+ return device.id + INSTALL_KEY_ACCOUNT_SUFFIX;
13
+ }
14
+ /**
15
+ * Move an install key from the config into its device's secret store.
16
+ *
17
+ * The key is needed again only when the device secret expires, so it lives
18
+ * where the secret does, not in plain text in `config.json`. The config entry
19
+ * keeps it until the store has proven it holds the key, so a failed write never
20
+ * loses it. Never throws.
21
+ *
22
+ * @param ctx - Paths, environment, timeout and keychain runner.
23
+ * @param installKey - The key that was exchanged.
24
+ * @param device - The device it was exchanged for.
25
+ * @param waitMs - How long to wait for the config lock.
26
+ * @returns True when the store holds the key and the config was updated.
27
+ */
28
+ export async function retireInstallKey(ctx, installKey, device, waitMs) {
29
+ try {
30
+ if (!(await storeVerified(ctx, device.store, installKeyAccount(device), installKey)))
31
+ return false;
32
+ return (await detachInstallKey(ctx.paths, installKey, device.id, waitMs)) !== 'busy';
33
+ }
34
+ catch (error) {
35
+ debugLog('credentials: moving the install key out of the config failed; it stays there:', error);
36
+ return false;
37
+ }
38
+ }
39
+ /**
40
+ * The install key a device was exchanged for, from its secret store.
41
+ *
42
+ * @param ctx - Paths, environment, timeout and keychain runner.
43
+ * @param device - The device.
44
+ * @returns The key, or undefined (a sign-in device has none).
45
+ */
46
+ export async function storedInstallKey(ctx, device) {
47
+ // Outside a hook's deadline: a read cut short would look like "no key" and back the re-enrollment off for an hour.
48
+ return secretStoreFor(device.store, { ...ctx, deadline: undefined }).get(installKeyAccount(device)).catch(() => undefined);
49
+ }
50
+ /**
51
+ * Remove the install key kept for a device, if any.
52
+ *
53
+ * @param ctx - Paths, environment, timeout and keychain runner.
54
+ * @param device - The device being forgotten.
55
+ */
56
+ export async function forgetInstallKey(ctx, device) {
57
+ await secretStoreFor(device.store, ctx).remove(installKeyAccount(device));
58
+ }
@@ -8,17 +8,19 @@ import type { CredentialContext, DeviceCredentialRef } from './types/credentials
8
8
  * run — written by an older setup, by `setup --token` or from
9
9
  * `$AGENTWATCH_TOKEN`. Order matters: the secret is stored and the first token
10
10
  * cached before the config names the device, so a crash in between costs one
11
- * more exchange, never the credential. The install key stays in the config
12
- * beside the device, to enroll again when the secret expires. A failure
13
- * keeps the key in use, and the next try waits an hour.
11
+ * more exchange, never the credential. Once the device is named, the install
12
+ * key moves from the config into the device's secret store, to enroll again
13
+ * when the secret expires (`retireInstallKey`); a config written before that
14
+ * loses its key the next time this runs. A failure keeps the key in the config
15
+ * and in use, and the next try waits an hour.
14
16
  *
15
17
  * A device the gateway refused counts as no device: an expired secret is
16
18
  * enrolled again by any run, a revoked or unknown one only when setup asks
17
19
  * (`ignoreBackoff`), so a hook never undoes an admin's revocation.
18
20
  *
19
- * Never for a scope `uninstall` marked, until setup runs for it again: the key
20
- * stays in the config for a reinstall, not for re-enrolling a device just
21
- * revoked. Asked before the lock, under it, and once more before the device is
21
+ * Never for a scope `uninstall` marked, until setup runs for it again: a key
22
+ * still in the config is there for a reinstall, not for re-enrolling a device
23
+ * just revoked. Asked before the lock, under it, and once more before the device is
22
24
  * attached; a device enrolled while uninstall marked the scope is revoked and
23
25
  * forgotten here, since uninstall can no longer see it.
24
26
  *
@@ -26,7 +28,7 @@ import type { CredentialContext, DeviceCredentialRef } from './types/credentials
26
28
  * fit a hook's budget. Setup makes the exchange there.
27
29
  *
28
30
  * @param ctx - Paths, clock, timeout, fetch and keychain runner.
29
- * @param config - Effective config whose `token` is the install key.
31
+ * @param config - Effective config whose `token` is the install key, or whose device has its key in the store.
30
32
  * @param options - `ignoreBackoff` for setup, where someone asked for it now.
31
33
  * @param options.ignoreBackoff - Try even within an hour of a failed attempt.
32
34
  * @returns The device credential now standing for the key, or undefined.
@@ -7,11 +7,12 @@ import { acquireLock } from '../storage/lock.js';
7
7
  import { isUninstalled } from '../storage/uninstalled.js';
8
8
  import { BackendAuthBlock } from '../transport/auth-block.js';
9
9
  import { identityPaths } from '../transport/queue-partition.js';
10
- import { ENROLL_LOCK_PREFIX, ENROLL_RETRY_MS, REFUSAL_SECRET_EXPIRED } from './constants/credentials.constants.js';
10
+ import { DEVICE_IDENTITY_PREFIX, ENROLL_LOCK_PREFIX, ENROLL_RETRY_MS, REFUSAL_SECRET_EXPIRED } from './constants/credentials.constants.js';
11
11
  import { enrollDevice, revokeDevice } from './device-api.js';
12
12
  import { readDeviceState, writeAccessToken, writeDeviceState } from './device-state.js';
13
13
  import { withinBudget } from './budget.js';
14
- import { credentialId, deviceRefs } from './identity.js';
14
+ import { deviceRefs, identityFingerprint, identityOf } from './identity.js';
15
+ import { forgetInstallKey, retireInstallKey, storedInstallKey } from './install-key.js';
15
16
  import { saveSecret, secretStoreFor } from './secret-store.js';
16
17
  /**
17
18
  * Exchange the install key this config holds for a device credential, once.
@@ -21,17 +22,19 @@ import { saveSecret, secretStoreFor } from './secret-store.js';
21
22
  * run — written by an older setup, by `setup --token` or from
22
23
  * `$AGENTWATCH_TOKEN`. Order matters: the secret is stored and the first token
23
24
  * cached before the config names the device, so a crash in between costs one
24
- * more exchange, never the credential. The install key stays in the config
25
- * beside the device, to enroll again when the secret expires. A failure
26
- * keeps the key in use, and the next try waits an hour.
25
+ * more exchange, never the credential. Once the device is named, the install
26
+ * key moves from the config into the device's secret store, to enroll again
27
+ * when the secret expires (`retireInstallKey`); a config written before that
28
+ * loses its key the next time this runs. A failure keeps the key in the config
29
+ * and in use, and the next try waits an hour.
27
30
  *
28
31
  * A device the gateway refused counts as no device: an expired secret is
29
32
  * enrolled again by any run, a revoked or unknown one only when setup asks
30
33
  * (`ignoreBackoff`), so a hook never undoes an admin's revocation.
31
34
  *
32
- * Never for a scope `uninstall` marked, until setup runs for it again: the key
33
- * stays in the config for a reinstall, not for re-enrolling a device just
34
- * revoked. Asked before the lock, under it, and once more before the device is
35
+ * Never for a scope `uninstall` marked, until setup runs for it again: a key
36
+ * still in the config is there for a reinstall, not for re-enrolling a device
37
+ * just revoked. Asked before the lock, under it, and once more before the device is
35
38
  * attached; a device enrolled while uninstall marked the scope is revoked and
36
39
  * forgotten here, since uninstall can no longer see it.
37
40
  *
@@ -39,14 +42,15 @@ import { saveSecret, secretStoreFor } from './secret-store.js';
39
42
  * fit a hook's budget. Setup makes the exchange there.
40
43
  *
41
44
  * @param ctx - Paths, clock, timeout, fetch and keychain runner.
42
- * @param config - Effective config whose `token` is the install key.
45
+ * @param config - Effective config whose `token` is the install key, or whose device has its key in the store.
43
46
  * @param options - `ignoreBackoff` for setup, where someone asked for it now.
44
47
  * @param options.ignoreBackoff - Try even within an hour of a failed attempt.
45
48
  * @returns The device credential now standing for the key, or undefined.
46
49
  */
47
50
  export async function migrateInstallKey(ctx, config, options = {}) {
48
- const installKey = config.token;
49
- if (!installKey || !config.endpoint)
51
+ const identity = identityOf(config);
52
+ const id = identity === undefined ? undefined : identityFingerprint(identity);
53
+ if (!id || !config.endpoint)
50
54
  return undefined;
51
55
  if (ctx.hookPath && ctx.env.platform === 'win32')
52
56
  return undefined;
@@ -54,22 +58,36 @@ export async function migrateInstallKey(ctx, config, options = {}) {
54
58
  // enroll: only setup, which lifts the marker first, may.
55
59
  if (await isUninstalled(ctx.paths, ctx.scope))
56
60
  return undefined;
57
- const id = credentialId(installKey);
58
- const files = identityPaths(ctx.paths, installKey);
61
+ const files = identityPaths(ctx.paths, DEVICE_IDENTITY_PREFIX + id);
62
+ const waitMs = ctx.hookPath ? CONFIG_LOCK_HOOK_WAIT_MS : CONFIG_LOCK_WAIT_MS;
59
63
  // Cheap checks first, so a backed-off key costs a hook no lock; both are
60
64
  // asked again under the lock, where the answer can no longer change.
61
65
  const settled = await settledExchange(ctx, id, files.deviceStateFile, options);
62
- if (settled.done)
66
+ // A config written before the key left it (an older edge) still holds it beside its device.
67
+ // Only the entry that names the device beside it, which is what `detachInstallKey` clears.
68
+ const leftKey = settled.done && settled.device !== undefined && config.token !== undefined && config.device?.id === id;
69
+ if (settled.done && !leftKey)
63
70
  return settled.device;
64
71
  const release = await acquireLock(ctx.paths.locksDir, ENROLL_LOCK_PREFIX + id, ctx.env.now).catch(() => undefined);
72
+ // The device stands either way; moving the key waits for the next run.
65
73
  if (!release)
66
- return undefined;
74
+ return leftKey ? settled.device : undefined;
67
75
  try {
68
76
  const recheck = await settledExchange(ctx, id, files.deviceStateFile, options);
69
- if (recheck.done)
70
- return recheck.device;
77
+ // Under the lock, so uninstall (which takes it) cannot remove the key from the store in between.
71
78
  if (await isUninstalled(ctx.paths, ctx.scope))
72
79
  return undefined;
80
+ if (recheck.done) {
81
+ if (recheck.device && config.token && config.device?.id === id)
82
+ await retireInstallKey(ctx, config.token, recheck.device, waitMs);
83
+ return recheck.device;
84
+ }
85
+ const installKey = config.token ?? (config.device ? await storedInstallKey(ctx, config.device) : undefined);
86
+ // A device signed in through the browser has no key: back off, so a hook does not ask the keychain every turn.
87
+ if (!installKey) {
88
+ await writeDeviceState(files.deviceStateFile, { ...recheck.state, enrollAttemptAt: ctx.env.now().toISOString() });
89
+ return undefined;
90
+ }
73
91
  const now = ctx.env.now();
74
92
  const budget = withinBudget(ctx);
75
93
  if (!budget)
@@ -93,17 +111,38 @@ export async function migrateInstallKey(ctx, config, options = {}) {
93
111
  await abandonDevice(ctx, device, result.value.deviceSecret, files.accessTokenFile);
94
112
  return undefined;
95
113
  }
96
- const attached = await attachDevice(ctx.paths, installKey, device, ctx.hookPath ? CONFIG_LOCK_HOOK_WAIT_MS : CONFIG_LOCK_WAIT_MS);
114
+ const attached = await attachDevice(ctx.paths, installKey, device, waitMs);
97
115
  // Unnamed in the config (the lock was busy), the device is invisible to the
98
116
  // next run: keep the backoff, or every hook would enroll yet another one.
99
117
  await writeDeviceState(files.deviceStateFile, (await namesDevice(ctx, attached, device)) ? {} : { enrollAttemptAt: now.toISOString() });
100
118
  await new BackendAuthBlock(files.authBlockFile, ctx.env.now).clear();
119
+ // Uninstall may have overtaken the exchange since the last look: it removes the key, so it must not come back.
120
+ if (await isUninstalled(ctx.paths, ctx.scope))
121
+ return device;
122
+ await keepInstallKey(ctx, installKey, config.token === undefined ? config.device : undefined, device, waitMs);
101
123
  return device;
102
124
  }
103
125
  finally {
104
126
  await release();
105
127
  }
106
128
  }
129
+ /**
130
+ * After an exchange, keep the key in the new device's store only. A key read
131
+ * from the store is written again only when the secret moved to another store
132
+ * (a keychain that works now), and the old copy goes once the new one is proven.
133
+ *
134
+ * @param ctx - Paths, environment, timeout and keychain runner.
135
+ * @param installKey - The key just exchanged.
136
+ * @param previous - The device whose store the key was read from, when it was.
137
+ * @param device - The device it was exchanged for.
138
+ * @param waitMs - How long to wait for the config lock.
139
+ */
140
+ async function keepInstallKey(ctx, installKey, previous, device, waitMs) {
141
+ if (previous?.store === device.store)
142
+ return;
143
+ if ((await retireInstallKey(ctx, installKey, device, waitMs)) && previous)
144
+ await forgetInstallKey(ctx, previous).catch(() => undefined);
145
+ }
107
146
  /**
108
147
  * Undo an exchange uninstall overtook: revoke the device on the platform and
109
148
  * forget it here, best effort. Its secret is in hand, so no keychain read.
@@ -120,6 +159,7 @@ export async function abandonDevice(ctx, device, secret, tokenFile) {
120
159
  if (!revoked)
121
160
  warnLog('a device that was enrolled but not kept (uninstall overtook it, or setup could not save it) could not be revoked; it may still be active on the platform. An admin can revoke this machine in Settings → Install.');
122
161
  await secretStoreFor(device.store, ctx).remove(device.id).catch(() => undefined);
162
+ await forgetInstallKey(ctx, device).catch(() => undefined);
123
163
  await fs.rm(tokenFile, { force: true }).catch(() => undefined);
124
164
  debugLog('device enrollment overtaken by uninstall; revoked and forgotten');
125
165
  }
@@ -19,6 +19,18 @@ export type { SecretStore, StoreDeps } from './types/credentials.types.js';
19
19
  * @returns The store that holds it now.
20
20
  */
21
21
  export declare function saveSecret(deps: StoreDeps, id: string, secret: string): Promise<CredentialStoreKind>;
22
+ /**
23
+ * Write a value to one store and read it back, outside a hook's credential
24
+ * deadline (see `saveSecret`). `security -i` exits 0 whatever happened, so only
25
+ * the read proves the write.
26
+ *
27
+ * @param deps - Environment, paths, timeout and runner.
28
+ * @param kind - The store to write to.
29
+ * @param id - The account name.
30
+ * @param value - What to keep.
31
+ * @returns True when the store gives the value back.
32
+ */
33
+ export declare function storeVerified(deps: StoreDeps, kind: CredentialStoreKind, id: string, value: string): Promise<boolean>;
22
34
  /**
23
35
  * The OS keychain this machine offers, or the private file when it offers none.
24
36
  *
@@ -28,11 +28,28 @@ import { CREDENTIALS_DIR_NAME, DBUS_SESSION_VAR, DPAPI_FILE_SUFFIX, DPAPI_PROTEC
28
28
  export async function saveSecret(deps, id, secret) {
29
29
  const unhurried = { ...deps, deadline: undefined };
30
30
  const preferred = preferredStore(unhurried);
31
- if (preferred.kind !== 'file' && (await preferred.set(id, secret)) && (await preferred.get(id)) === secret)
31
+ if (preferred.kind !== 'file' && (await setVerified(preferred, id, secret)))
32
32
  return preferred.kind;
33
33
  await fileStore(unhurried).set(id, secret);
34
34
  return 'file';
35
35
  }
36
+ /**
37
+ * Write a value to one store and read it back, outside a hook's credential
38
+ * deadline (see `saveSecret`). `security -i` exits 0 whatever happened, so only
39
+ * the read proves the write.
40
+ *
41
+ * @param deps - Environment, paths, timeout and runner.
42
+ * @param kind - The store to write to.
43
+ * @param id - The account name.
44
+ * @param value - What to keep.
45
+ * @returns True when the store gives the value back.
46
+ */
47
+ export async function storeVerified(deps, kind, id, value) {
48
+ return setVerified(secretStoreFor(kind, { ...deps, deadline: undefined }), id, value);
49
+ }
50
+ async function setVerified(store, id, value) {
51
+ return (await store.set(id, value)) && (await store.get(id)) === value;
52
+ }
36
53
  /**
37
54
  * The OS keychain this machine offers, or the private file when it offers none.
38
55
  *
@@ -1,3 +1,4 @@
1
+ import { type CloudIdentity } from './cloud-claim.js';
1
2
  import type { CredentialContext, RedeemCodeInput, SignedIn, SignInInput } from './types/credentials.types.js';
2
3
  /**
3
4
  * Enroll this machine through the browser: show the verification code, wait
@@ -29,3 +30,29 @@ export declare function signInDevice(ctx: CredentialContext, input: SignInInput)
29
30
  export declare function enrollWithCode(ctx: CredentialContext, input: Omit<RedeemCodeInput, 'timeoutMs' | 'fetchFn'>): Promise<SignedIn | {
30
31
  readonly error: string;
31
32
  }>;
33
+ /**
34
+ * Enroll a Claude Code cloud VM with a claim signed by its organization's
35
+ * cloud session key. No install key, no prompt, no code: the signature names
36
+ * the organization and the claim the developer. The credential is kept
37
+ * exactly as a sign-in's is. Never prints the key or the signature.
38
+ *
39
+ * ponytail: the device is stored with no `source` (like a sign-in's), because
40
+ * the config schema only knows `batch-code`; recording `cloud` there is a
41
+ * config.schema.ts change.
42
+ *
43
+ * @param ctx - Paths, environment, timeout, fetch and keychain runner.
44
+ * @param input - Gateway, the managed-settings identity, installation and label.
45
+ * @param input.endpoint - The gateway to claim from.
46
+ * @param input.identity - Organization, key and Claude account email.
47
+ * @param input.installationId - This VM's own installation.
48
+ * @param input.name - The machine label.
49
+ * @returns The device to name in the config and its secret, or the reason there is none.
50
+ */
51
+ export declare function enrollWithCloudClaim(ctx: CredentialContext, input: {
52
+ readonly endpoint: string;
53
+ readonly identity: CloudIdentity;
54
+ readonly installationId: string;
55
+ readonly name: string;
56
+ }): Promise<SignedIn | {
57
+ readonly error: string;
58
+ }>;
@@ -1,7 +1,8 @@
1
1
  import { sleep } from '../core/async.js';
2
2
  import { identityPaths } from '../transport/queue-partition.js';
3
3
  import { DEVICE_SOURCE_BATCH_CODE, POLL_DENIED, POLL_EXPIRED, POLL_PENDING, POLL_SLOW_DOWN, RE_PLAIN_EMAIL, SLOW_DOWN_STEP_MS } from './constants/credentials.constants.js';
4
- import { pollEnrollmentSession, redeemEnrollmentCode, revokeDevice, startEnrollmentSession } from './device-api.js';
4
+ import { signCloudClaim } from './cloud-claim.js';
5
+ import { claimCloudDevice, pollEnrollmentSession, redeemEnrollmentCode, revokeDevice, startEnrollmentSession } from './device-api.js';
5
6
  import { writeAccessToken } from './device-state.js';
6
7
  import { credentialId } from './identity.js';
7
8
  import { saveSecret } from './secret-store.js';
@@ -79,6 +80,35 @@ export async function enrollWithCode(ctx, input) {
79
80
  return { error: `the enrollment code was refused (${redeemed.refusal}): it is unknown, used, expired or revoked; ask your admin for a new one. Nothing was written` };
80
81
  return { error: `could not redeem the enrollment code with ${input.endpoint} (${redeemed.status ?? 'no response'}); nothing was written` };
81
82
  }
83
+ /**
84
+ * Enroll a Claude Code cloud VM with a claim signed by its organization's
85
+ * cloud session key. No install key, no prompt, no code: the signature names
86
+ * the organization and the claim the developer. The credential is kept
87
+ * exactly as a sign-in's is. Never prints the key or the signature.
88
+ *
89
+ * ponytail: the device is stored with no `source` (like a sign-in's), because
90
+ * the config schema only knows `batch-code`; recording `cloud` there is a
91
+ * config.schema.ts change.
92
+ *
93
+ * @param ctx - Paths, environment, timeout, fetch and keychain runner.
94
+ * @param input - Gateway, the managed-settings identity, installation and label.
95
+ * @param input.endpoint - The gateway to claim from.
96
+ * @param input.identity - Organization, key and Claude account email.
97
+ * @param input.installationId - This VM's own installation.
98
+ * @param input.name - The machine label.
99
+ * @returns The device to name in the config and its secret, or the reason there is none.
100
+ */
101
+ export async function enrollWithCloudClaim(ctx, input) {
102
+ const signed = signCloudClaim(input.identity, ctx.env.now());
103
+ if (!signed)
104
+ return { error: 'AGENTWATCH_CLOUD_KEY is not an Ed25519 private key (base64url PKCS8 DER); copy the block from Settings again. Nothing was written' };
105
+ const claimed = await claimCloudDevice({ endpoint: input.endpoint, ...signed, installationId: input.installationId, name: input.name, timeoutMs: ctx.timeoutMs, fetchFn: ctx.fetchFn });
106
+ if (claimed.ok)
107
+ return keep(ctx, input.endpoint, claimed.value);
108
+ if (claimed.status === 401)
109
+ return { error: 'the cloud claim was refused: check the organization id and key in the managed settings, and that the Claude account email is at the organization\'s verified domain. Nothing was written' };
110
+ return { error: `could not claim a cloud device from ${input.endpoint} (${claimed.status ?? 'no response'}); nothing was written, the next session start tries again` };
111
+ }
82
112
  /**
83
113
  * Store an approved credential. The gateway has issued it by now, so a store
84
114
  * that fails is undone on the platform too: nothing would name the device, and
@@ -34,6 +34,10 @@ export declare function cachedAccessToken(ctx: CredentialContext, config: AgentW
34
34
  *
35
35
  * @param ctx - Paths, clock, timeout, deadline, fetch and keychain runner.
36
36
  * @param config - Effective config holding a device credential.
37
+ * @param options - Refresh options.
38
+ * @param options.force - Refresh whatever the cache holds (after a plain 401).
37
39
  * @returns The token, or undefined when there is none to send.
38
40
  */
39
- export declare function currentAccessToken(ctx: CredentialContext, config: AgentWatchConfig): Promise<string | undefined>;
41
+ export declare function currentAccessToken(ctx: CredentialContext, config: AgentWatchConfig, options?: {
42
+ readonly force?: boolean;
43
+ }): Promise<string | undefined>;
@@ -58,9 +58,11 @@ export async function cachedAccessToken(ctx, config) {
58
58
  *
59
59
  * @param ctx - Paths, clock, timeout, deadline, fetch and keychain runner.
60
60
  * @param config - Effective config holding a device credential.
61
+ * @param options - Refresh options.
62
+ * @param options.force - Refresh whatever the cache holds (after a plain 401).
61
63
  * @returns The token, or undefined when there is none to send.
62
64
  */
63
- export async function currentAccessToken(ctx, config) {
65
+ export async function currentAccessToken(ctx, config, options = {}) {
64
66
  const device = config.device;
65
67
  if (!device)
66
68
  return undefined;
@@ -70,7 +72,8 @@ export async function currentAccessToken(ctx, config) {
70
72
  destination ? new BackendAuthBlock(files.authBlockFile, ctx.env.now).active(destination) : undefined,
71
73
  readAccessToken(files.accessTokenFile)
72
74
  ]);
73
- const expired = block?.reason === REFUSAL_TOKEN_EXPIRED;
75
+ // `force` (a plain 401) is handled as an expired token: same lock, cooldown and refusal rules.
76
+ const expired = options.force === true || block?.reason === REFUSAL_TOKEN_EXPIRED;
74
77
  if (cached && !expired && !needsRefresh(cached, ctx.env.now(), ctx.minRemainingMs))
75
78
  return cached.accessToken;
76
79
  const fallback = expired ? undefined : usable(cached, ctx.env.now());
@@ -83,6 +86,11 @@ export async function currentAccessToken(ctx, config) {
83
86
  // `agentwatch refresh-credential` refreshes under the same lock, and this
84
87
  // hook sends what it has (or queues).
85
88
  if (ctx.hookPath && device.store === 'windows-dpapi') {
89
+ // The refresher only refreshes what is due, so a forced refresh drops the
90
+ // cache to make it due. This hook cannot resend: the next send after the
91
+ // block's re-probe goes on the new token.
92
+ if (options.force === true)
93
+ await fs.promises.rm(files.accessTokenFile, { force: true }).catch(() => undefined);
86
94
  await startBackgroundRefresh(ctx, files.deviceStateFile);
87
95
  return fallback;
88
96
  }
@@ -31,7 +31,7 @@ import { requestDecision } from './decision-client.js';
31
31
  */
32
32
  export async function resolveEnforcement(options) {
33
33
  const url = enforcementUrl(options.config);
34
- // A device's install key stays in the file to enroll again, but this
34
+ // An install key an older edge left beside its device is not sent: this
35
35
  // identity sends as the device: only the caller's cached access token will do.
36
36
  const token = options.bearer ?? (deviceFor(options.config) ? undefined : options.config.token);
37
37
  const developerId = options.developerId;
@@ -23,9 +23,12 @@ export declare const INTERNAL_HOOK_EVENT_TYPES: readonly ["session.started", "se
23
23
  *
24
24
  * `repo.tree` is the default branch's source paths and declaration names, once
25
25
  * per repository and identity: what a tenant with no GitHub App gets its feature catalog named from.
26
+ *
27
+ * `replay.progress` counts how far a replay of the developer's earlier sessions
28
+ * has got, so the platform can say a history is still arriving. Counts only.
26
29
  */
27
- export declare const PRODUCT_EVENT_TYPES: readonly ["llm.call", "turn.summary", "repo.snapshot", "session.billing", "repo.tree"];
28
- 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", "repo.tree"];
30
+ export declare const PRODUCT_EVENT_TYPES: readonly ["llm.call", "turn.summary", "repo.snapshot", "session.billing", "repo.tree", "replay.progress"];
31
+ 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", "repo.tree", "replay.progress"];
29
32
  /** O(1) membership for the hot path: queue drain checks this per entry. */
30
33
  export declare const PRODUCT_EVENT_TYPE_SET: ReadonlySet<string>;
31
34
  /** Canonical event types that close a turn. */
@@ -45,8 +45,11 @@ export const INTERNAL_HOOK_EVENT_TYPES = [
45
45
  *
46
46
  * `repo.tree` is the default branch's source paths and declaration names, once
47
47
  * per repository and identity: what a tenant with no GitHub App gets its feature catalog named from.
48
+ *
49
+ * `replay.progress` counts how far a replay of the developer's earlier sessions
50
+ * has got, so the platform can say a history is still arriving. Counts only.
48
51
  */
49
- export const PRODUCT_EVENT_TYPES = ['llm.call', 'turn.summary', 'repo.snapshot', 'session.billing', 'repo.tree'];
52
+ export const PRODUCT_EVENT_TYPES = ['llm.call', 'turn.summary', 'repo.snapshot', 'session.billing', 'repo.tree', 'replay.progress'];
50
53
  export const CANONICAL_EVENT_TYPES = [...INTERNAL_HOOK_EVENT_TYPES, ...PRODUCT_EVENT_TYPES];
51
54
  /** O(1) membership for the hot path: queue drain checks this per entry. */
52
55
  export const PRODUCT_EVENT_TYPE_SET = new Set(PRODUCT_EVENT_TYPES);
@@ -14,3 +14,17 @@ export type { EnrichOptions, PathRewriter } from './types/enrich.types.js';
14
14
  * @returns Enriched, sanitized events in the same order.
15
15
  */
16
16
  export declare function enrichEvents(events: readonly AgentWatchEvent[], options: EnrichOptions): Promise<AgentWatchEvent[]>;
17
+ /**
18
+ * Where a file outside every checkout lies, without the home directory's name.
19
+ *
20
+ * A spreadsheet in `~/Documents` is the target of a session with no repository,
21
+ * so it is kept — but as `~/Documents/a.xlsx`: the home directory names the
22
+ * person. A path outside home is kept as it is; with no home to compare against
23
+ * nothing is kept, since the path could be the home itself.
24
+ *
25
+ * @param filePath - Path from a tool payload.
26
+ * @param repositoryRoot - The hook's repository root, when inside one.
27
+ * @param home - Developer home directory, when known.
28
+ * @returns The path to send, or undefined when the file is in the repository or unplaceable.
29
+ */
30
+ export declare function externalPath(filePath: string, repositoryRoot: string | undefined, home: string | undefined): string | undefined;
@@ -278,7 +278,7 @@ function relativize(root, target) {
278
278
  * @param home - Developer home directory, when known.
279
279
  * @returns The path to send, or undefined when the file is in the repository or unplaceable.
280
280
  */
281
- function externalPath(filePath, repositoryRoot, home) {
281
+ export function externalPath(filePath, repositoryRoot, home) {
282
282
  if (!home || !path.isAbsolute(filePath) || (repositoryRoot && isInside(repositoryRoot, filePath)))
283
283
  return undefined;
284
284
  return isInside(home, filePath) ? HOME_PLACEHOLDER_PREFIX + path.relative(home, filePath) : filePath;
@@ -6,6 +6,7 @@ export type { AgentWatchEvent, CanonicalEventType, ContentEvidence, EventAi, Eve
6
6
  export type { BuildLlmCallInput, LlmCallCorrelation, LlmCallEvent, LlmCallStatus, LlmCallUsage } from './types/llm-call.types.js';
7
7
  export type { RepoSnapshotBranch, RepoSnapshotCommit, RepoSnapshotCommitFile, RepoSnapshotEvent } from './types/repo-snapshot.types.js';
8
8
  export type { RepoTreeEvent, RepoTreeFile } from './types/repo-tree.types.js';
9
+ export type { ReplayProgressEvent, ReplayProgressState } from './types/replay-progress.types.js';
9
10
  export type { EnrichOptions, PathRewriter, PathRule } from './types/enrich.types.js';
10
11
  export type { ProductEvent } from './product-event.js';
11
12
  export { CANONICAL_EVENT_TYPES, EVENT_SCHEMA_VERSION, INTERNAL_HOOK_EVENT_TYPES, PRODUCT_EVENT_TYPES, PRODUCT_EVENT_TYPE_SET, TURN_CLOSING_EVENT_TYPE } from './constants/events.constants.js';
@@ -2,26 +2,29 @@ import type { TurnSummaryEvent } from '../turns/types/turn-summary.types.js';
2
2
  import type { LlmCallEvent } from './types/llm-call.types.js';
3
3
  import type { RepoSnapshotEvent } from './types/repo-snapshot.types.js';
4
4
  import type { RepoTreeEvent } from './types/repo-tree.types.js';
5
+ import type { ReplayProgressEvent, ReplayProgressState } from './types/replay-progress.types.js';
5
6
  import type { SessionBillingEvent } from './types/session-billing.types.js';
6
7
  export { PRODUCT_EVENT_TYPES } from './constants/events.constants.js';
7
8
  export type { ProductEventType } from './types/events.types.js';
8
9
  export type { LlmCallEvent, LlmCallCorrelation, LlmCallStatus } from './types/llm-call.types.js';
9
10
  export type { RepoSnapshotBranch, RepoSnapshotCommit, RepoSnapshotCommitFile, RepoSnapshotEvent } from './types/repo-snapshot.types.js';
10
11
  export type { RepoTreeEvent, RepoTreeFile } from './types/repo-tree.types.js';
12
+ export type { ReplayProgressEvent, ReplayProgressState };
11
13
  export type { SessionBillingEvent } from './types/session-billing.types.js';
12
14
  export type { AgentUsageSummary, TurnSummaryEvent, TurnUsageStatus } from '../turns/types/turn-summary.types.js';
13
15
  /**
14
16
  * The complete public AgentWatch domain contract.
15
17
  *
16
- * Five record types, deliberately: `llm.call` is the lossless per-request
18
+ * Six record types, deliberately: `llm.call` is the lossless per-request
17
19
  * usage ledger, `turn.summary` is the human unit of work, `repo.snapshot`
18
20
  * is what the working copy says the work *is* when no tracker can be asked,
19
21
  * `session.billing` is how the session's developer pays, and `repo.tree` is
20
- * what the trunk's code is called when nothing can clone it. No
22
+ * what the trunk's code is called when nothing can clone it, and `replay.progress`
23
+ * counts how far a replay of earlier sessions has got. No
21
24
  * lifecycle or tool event is public — those exist only to assemble a summary
22
25
  * locally.
23
26
  */
24
- export type ProductEvent = LlmCallEvent | TurnSummaryEvent | RepoSnapshotEvent | SessionBillingEvent | RepoTreeEvent;
27
+ export type ProductEvent = LlmCallEvent | TurnSummaryEvent | RepoSnapshotEvent | SessionBillingEvent | RepoTreeEvent | ReplayProgressEvent;
25
28
  /** The least a value must look like for {@link isProductEvent} to judge it. */
26
29
  export interface EventTypeCarrier {
27
30
  readonly event?: {
@@ -32,6 +32,10 @@ export interface EventSession {
32
32
  readonly turnId?: string;
33
33
  readonly generationId?: string;
34
34
  readonly agentId?: string;
35
+ /** The agent's mode when the session started, where its start hook names one (Cursor `composer_mode`). */
36
+ readonly mode?: string;
37
+ /** Whether the agent runs the session in the vendor's cloud (Cursor `is_background_agent`). */
38
+ readonly isCloudAgent?: boolean;
35
39
  }
36
40
  export interface EventGit {
37
41
  readonly repository?: string;
@@ -78,6 +82,8 @@ export interface AgentWatchEvent<TType extends CanonicalEventType = CanonicalEve
78
82
  readonly session: EventSession;
79
83
  readonly developer?: {
80
84
  readonly installationId?: string;
85
+ /** The email the agent's own account is signed in as, where its hook names one (Cursor `user_email`). */
86
+ readonly accountEmail?: string;
81
87
  };
82
88
  readonly git?: EventGit;
83
89
  readonly feature?: {