@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
@@ -0,0 +1,102 @@
1
+ import { CLAUDE_PROVIDER_ID } from '../../providers/claude/constants/claude.constants.js';
2
+ import { CODEX_PROVIDER_ID } from '../../providers/codex/constants/codex.constants.js';
3
+ import { GEMINI_PROVIDER_ID } from '../../providers/gemini/constants/gemini.constants.js';
4
+ /** Days of history a replay reaches back when `--replay-days` names none. */
5
+ export const REPLAY_DEFAULT_DAYS = 30;
6
+ /** The most `--replay-days` accepts; a transcript older than the open charge period is never sent anyway. */
7
+ export const REPLAY_MAX_DAYS = 366;
8
+ /**
9
+ * Days into a month before the previous month's charges settle. A copy of core's
10
+ * `PLACEMENT_FINALIZATION_GRACE_DAYS` (packages/types/src/period-month.ts): the edge
11
+ * cannot import core, and the two must move together.
12
+ */
13
+ export const REPLAY_FINALIZATION_GRACE_DAYS = 5;
14
+ /** Turns in one request. Small on purpose: the gateway budgets a batch at 8 s and the machine is someone's laptop. */
15
+ export const REPLAY_BATCH_TURNS = 20;
16
+ /** Between two requests, so a 1,000 turn history costs the backend under one request per five seconds. */
17
+ export const REPLAY_BATCH_INTERVAL_MS = 5_000;
18
+ /** Between two transcript files, so the disk reads come up for air. */
19
+ export const REPLAY_FILE_PAUSE_MS = 200;
20
+ /** How long a busy machine (load, battery) is left alone before the next look. */
21
+ export const REPLAY_BUSY_PAUSE_MS = 30_000;
22
+ /** The first wait after a failed request; it doubles up to {@link REPLAY_MAX_BACKOFF_MS}. */
23
+ export const REPLAY_BASE_BACKOFF_MS = 10_000;
24
+ /** The longest wait after repeated failures. */
25
+ export const REPLAY_MAX_BACKOFF_MS = 300_000;
26
+ /** Active time one run spends before it stops and waits to be resumed. */
27
+ export const REPLAY_RUN_BUDGET_MS = 20 * 60_000;
28
+ /** A hook closed a turn this recently: an agent is working and replay waits. */
29
+ export const REPLAY_HOOK_QUIET_MS = 60_000;
30
+ /** A progress record goes out every this many batches, besides its start, pauses and end. */
31
+ export const REPLAY_PROGRESS_EVERY_BATCHES = 5;
32
+ /**
33
+ * A turn that ended this recently may still be running; the live hook owns it.
34
+ * Replaying half a turn would hand the backend a smaller one than the hook's.
35
+ */
36
+ export const REPLAY_LIVE_TURN_GRACE_MS = 10 * 60_000;
37
+ /** A run whose state file has not been touched for this long is gone, whatever its pid says. */
38
+ export const REPLAY_HEARTBEAT_STALE_MS = 2 * 60_000;
39
+ /** How often the battery is asked; `pmset` is a process start. */
40
+ export const REPLAY_BATTERY_CHECK_MS = 5 * 60_000;
41
+ /** `nice` 19: the lowest priority the operating system offers. */
42
+ export const REPLAY_NICE = 19;
43
+ /** The 1-minute load average, per core, above which the machine counts as busy. */
44
+ export const REPLAY_BUSY_LOAD_PER_CORE = 0.5;
45
+ /** Where Claude Code keeps its transcripts, under HOME. */
46
+ export const CLAUDE_PROJECTS_SEGMENTS = ['.claude', 'projects'];
47
+ /** The agents replay reads, by provider id: setup starts a replay when any of them is detected. */
48
+ export const REPLAY_AGENTS = new Set([CLAUDE_PROVIDER_ID, CODEX_PROVIDER_ID, GEMINI_PROVIDER_ID]);
49
+ /** Where Codex keeps its rollouts, under `CODEX_HOME`: `sessions/YYYY/MM/DD/rollout-*.jsonl`. */
50
+ export const CODEX_SESSIONS_DIR = 'sessions';
51
+ export const CODEX_ROLLOUT_PREFIX = 'rollout-';
52
+ /** The rollout rows replay reads; every other row (messages, reasoning, tool output) is skipped unparsed. */
53
+ export const RE_CODEX_REPLAY_ROW = /"type":"(?:session_meta|turn_context|task_started|task_complete|token_count)"/;
54
+ /** A prompt row, read only when prompt text is allowed. */
55
+ export const RE_CODEX_PROMPT_ROW = /"type":"user_message"/;
56
+ /** The row that opens a Codex turn, for the cheap count. */
57
+ export const RE_CODEX_TURN_START = /"type":"task_started"/;
58
+ /** Gemini CLI's chat files, under its home: `tmp/<project>/chats/session-*.jsonl`, and the map of project folders. */
59
+ export const GEMINI_TMP_DIR = 'tmp';
60
+ export const GEMINI_CHATS_DIR = 'chats';
61
+ export const GEMINI_SESSION_PREFIX = 'session-';
62
+ export const GEMINI_PROJECTS_FILE = 'projects.json';
63
+ /** A user message, for the cheap count. */
64
+ export const RE_GEMINI_TURN_START = /"type":"user"/;
65
+ /** Directory under the identity state dir holding replay state. */
66
+ export const REPLAY_STATE_FILE_NAME = 'replay.json';
67
+ /** Machine-wide claim that setup has already started or inherited an automatic replay attempt. */
68
+ export const REPLAY_ATTEMPTED_FILE_NAME = 'replay-attempted';
69
+ /** The provider label replay progress reports; each turn carries its own agent's. */
70
+ export const REPLAY_PROVIDER = 'claude';
71
+ /** What a real prompt never starts with: Claude Code's own slash-command and interrupt records. */
72
+ export const RE_NOT_A_PROMPT = /^(?:<command-name>|<command-message>|<local-command-|\[Request interrupted)/;
73
+ /** Claude Code names a detached HEAD "HEAD" in `gitBranch`; the hook path reports no branch for it. */
74
+ export const DETACHED_BRANCH = 'HEAD';
75
+ /** The fields a transcript line is cheaply recognised by before it is parsed. */
76
+ export const RE_USER_OR_ASSISTANT_LINE = /"type":"(?:user|assistant)"/;
77
+ /** Prompt id fallback namespace, so a hash never reads as a Claude id. */
78
+ export const REPLAY_FALLBACK_TURN_PREFIX = 'replay-';
79
+ /** One send's network budget: a batch of twenty turns, to a gateway that budgets eight seconds. */
80
+ export const REPLAY_SEND_TIMEOUT_MS = 15_000;
81
+ /** A repository's snapshot and tree flows share this; the hooks' own is one second. */
82
+ export const REPLAY_SNAPSHOT_BUDGET_MS = 5_000;
83
+ /** Failed requests in a row (10 s doubling to 5 min is about ten minutes) before a run gives up until it is resumed. */
84
+ export const REPLAY_GIVE_UP_FAILURES = 6;
85
+ /** The sibling file that exists only while a replay is unfinished: the hook's one `stat` to know whether to resume it. */
86
+ export const REPLAY_PENDING_FILE_NAME = 'replay-pending';
87
+ /** The provider label progress and snapshot records carry; Claude Code's public name. */
88
+ export const REPLAY_PROVIDER_LABEL = 'claude-code';
89
+ /** A hook starts a stalled replay again at most this often. */
90
+ export const REPLAY_RESUME_INTERVAL_MS = 5 * 60_000;
91
+ /** A nap is cut into pieces this long, each followed by a heartbeat, so a long wait is not mistaken for a dead run. */
92
+ export const REPLAY_HEARTBEAT_MS = 30_000;
93
+ /**
94
+ * Node flags a replay runs under. A replay reads megabytes of JSON per second of
95
+ * wall time and keeps almost none of it, so left alone V8 lets the young
96
+ * generation and the heap grow into hundreds of megabytes of garbage (measured:
97
+ * 460 MB peak over 5,400 transcripts, against about 100 MB with these). They
98
+ * cost nothing in speed.
99
+ */
100
+ export const REPLAY_NODE_FLAGS = ['--max-semi-space-size=1', '--max-old-space-size=256'];
101
+ /** Files the identity pre-pass reads between two heartbeats (and looks for a `--stop`). */
102
+ export const PREPASS_PERSIST_EVERY = 25;
@@ -0,0 +1,10 @@
1
+ import type { ReplayRecord } from './types/replay.types.js';
2
+ /**
3
+ * The one line `agentwatch status` prints about a replay.
4
+ *
5
+ * @param record - The persisted state.
6
+ * @param nowMs - The clock.
7
+ * @param alive - Whether a pid exists; injectable for tests.
8
+ * @returns The line, e.g. "running 412/1,030 turns (40%)".
9
+ */
10
+ export declare function describeReplay(record: ReplayRecord, nowMs: number, alive?: (pid: number) => boolean): string;
@@ -0,0 +1,31 @@
1
+ import { isRunning } from './replay-state.js';
2
+ const PAUSE_REASONS = {
3
+ busy: 'laptop busy',
4
+ battery: 'on battery',
5
+ 'agent-active': 'an agent is working',
6
+ backend: 'waiting for the backend',
7
+ budget: 'resumes with the next agent session'
8
+ };
9
+ /**
10
+ * The one line `agentwatch status` prints about a replay.
11
+ *
12
+ * @param record - The persisted state.
13
+ * @param nowMs - The clock.
14
+ * @param alive - Whether a pid exists; injectable for tests.
15
+ * @returns The line, e.g. "running 412/1,030 turns (40%)".
16
+ */
17
+ export function describeReplay(record, nowMs, alive) {
18
+ const counts = `${record.turnsSent.toLocaleString('en-US')}/${record.turnsTotal.toLocaleString('en-US')} turns`;
19
+ const percent = record.turnsTotal > 0 ? ` (${Math.min(100, Math.floor((record.turnsSent / record.turnsTotal) * 100))}%)` : '';
20
+ if (record.state === 'done')
21
+ return `done: ${record.turnsSent.toLocaleString('en-US')} turns from ${record.sessionsSent.toLocaleString('en-US')} sessions`;
22
+ if (record.state === 'stopped')
23
+ return `stopped at ${counts}`;
24
+ if (!isRunning(record, nowMs, alive))
25
+ return `interrupted at ${counts}${percent}; continues with the next agent session`;
26
+ if (record.state === 'scanning')
27
+ return 'counting earlier sessions';
28
+ if (record.state === 'paused')
29
+ return `paused: ${PAUSE_REASONS[record.pause ?? 'busy']} (${counts}${percent})`;
30
+ return `running ${counts}${percent}`;
31
+ }
@@ -0,0 +1,36 @@
1
+ import type { ReplaySource, ReplayTurn } from './types/replay.types.js';
2
+ /**
3
+ * Gemini CLI's chat files as a replay source.
4
+ *
5
+ * Gemini's chat files do not record the id its live hook sends, so a replayed
6
+ * turn could never meet the live one downstream. Only turns that began before
7
+ * Gemini hooks were first installed on this machine are replayed: the live
8
+ * hooks sent every one after. An install with no first-install time hooked
9
+ * Gemini before that time was recorded, so the hooks already sent its history
10
+ * and nothing is replayed.
11
+ *
12
+ * @param home - Gemini CLI's home (`GEMINI_HOME`, or `~/.gemini`).
13
+ * @param firstInstalledMs - When AgentWatch first installed Gemini hooks here; undefined when unknown.
14
+ * @returns The source.
15
+ */
16
+ export declare function geminiSource(home: string, firstInstalledMs: number | undefined): ReplaySource;
17
+ /**
18
+ * Read a Gemini CLI chat file as the turns its live hook closed.
19
+ *
20
+ * A turn opens at a user message and runs to the next one; its usage is the
21
+ * replies between them that carry `tokens`, each reply once (Gemini rewrites a
22
+ * reply under the same id when its tokens arrive, and a `$set` snapshot
23
+ * repeats earlier messages). A turn whose replies carry no tokens (a file
24
+ * written before gemini-cli 0.46) is not yielded. Reply and thought content is
25
+ * never kept; a prompt's text only when prompt text is allowed.
26
+ *
27
+ * ponytail: the file's messages are kept in memory as metadata (id, time, tokens)
28
+ * before turns are cut, because a `$set` snapshot can repeat any earlier message.
29
+ * A chat file is one session, so that is thousands of small records at most.
30
+ *
31
+ * @param file - A `session-*.jsonl` file.
32
+ * @param promptText - Whether to keep the prompt's text.
33
+ * @param cwd - The directory the file's project folder stands for, if known.
34
+ * @yields Turns, oldest first.
35
+ */
36
+ export declare function readGeminiTurns(file: string, promptText: boolean, cwd: string | undefined): AsyncGenerator<ReplayTurn>;
@@ -0,0 +1,192 @@
1
+ import fs from 'node:fs';
2
+ import fsp from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import readline from 'node:readline';
5
+ import { asRecord, firstStringOf } from '../core/object.js';
6
+ import { sha256Hex } from '../events/event-id.js';
7
+ import { GEMINI_PROVIDER_ID } from '../providers/gemini/constants/gemini.constants.js';
8
+ import { GEMINI_TOKENS } from '../turns/constants/turns.constants.js';
9
+ import { geminiReplyUsage, replyRows } from '../turns/gemini-transcript.js';
10
+ import { accumulateUsage, parseJsonLine } from '../turns/transcript.js';
11
+ import { GEMINI_CHATS_DIR, GEMINI_PROJECTS_FILE, GEMINI_SESSION_PREFIX, GEMINI_TMP_DIR, RE_GEMINI_TURN_START, REPLAY_FALLBACK_TURN_PREFIX } from './constants/replay.constants.js';
12
+ import { estimateTurns, recentFiles } from './replay-scan.js';
13
+ /** The lines worth parsing: the session's metadata row, user messages, replies with tokens, and `$set` snapshots holding them. */
14
+ const RE_GEMINI_REPLAY_ROW = new RegExp(`"sessionId"|"type":"user"|"${GEMINI_TOKENS}"`);
15
+ /**
16
+ * Gemini CLI's chat files as a replay source.
17
+ *
18
+ * Gemini's chat files do not record the id its live hook sends, so a replayed
19
+ * turn could never meet the live one downstream. Only turns that began before
20
+ * Gemini hooks were first installed on this machine are replayed: the live
21
+ * hooks sent every one after. An install with no first-install time hooked
22
+ * Gemini before that time was recorded, so the hooks already sent its history
23
+ * and nothing is replayed.
24
+ *
25
+ * @param home - Gemini CLI's home (`GEMINI_HOME`, or `~/.gemini`).
26
+ * @param firstInstalledMs - When AgentWatch first installed Gemini hooks here; undefined when unknown.
27
+ * @returns The source.
28
+ */
29
+ export function geminiSource(home, firstInstalledMs) {
30
+ let projects;
31
+ return {
32
+ agent: GEMINI_PROVIDER_ID,
33
+ list: async (sinceMs) => (firstInstalledMs === undefined || firstInstalledMs <= sinceMs ? [] : listChats(home, sinceMs)),
34
+ estimate: (file, sinceMs) => estimateTurns(file, sinceMs, RE_GEMINI_TURN_START),
35
+ read: async function* (file, promptText) {
36
+ projects ??= projectFolders(home);
37
+ const cwd = (await projects).get(path.basename(path.dirname(path.dirname(file))));
38
+ // No folder: no way to tell whether it ran under `ignoredRoots` or another root's identity.
39
+ if (!cwd)
40
+ return;
41
+ for await (const turn of readGeminiTurns(file, promptText, cwd))
42
+ if (firstInstalledMs !== undefined && Date.parse(turn.startedAt) < firstInstalledMs)
43
+ yield turn;
44
+ }
45
+ };
46
+ }
47
+ /**
48
+ * The chat files written inside the window, from `tmp/<project>/chats`.
49
+ *
50
+ * @param home - Gemini CLI's home.
51
+ * @param sinceMs - The window's start.
52
+ * @returns The files; empty when Gemini CLI has left none.
53
+ */
54
+ async function listChats(home, sinceMs) {
55
+ const tmp = path.join(home, GEMINI_TMP_DIR);
56
+ const projects = await fsp.readdir(tmp, { withFileTypes: true }).catch(() => []);
57
+ const found = [];
58
+ for (const project of projects) {
59
+ if (project.isDirectory())
60
+ found.push(...(await recentFiles(path.join(tmp, project.name, GEMINI_CHATS_DIR), sinceMs, GEMINI_SESSION_PREFIX)));
61
+ }
62
+ return found;
63
+ }
64
+ /**
65
+ * Which folder each project folder under `tmp/` stands for: `projects.json` (`{projects: {<dir>: <folder>}}`), inverted.
66
+ *
67
+ * @param home - Gemini CLI's home.
68
+ * @returns Project folder name to absolute directory; empty when the file is missing or unreadable.
69
+ */
70
+ async function projectFolders(home) {
71
+ const raw = await fsp.readFile(path.join(home, GEMINI_PROJECTS_FILE), 'utf8').catch(() => '');
72
+ const projects = asRecord(parseJsonLine(raw)?.['projects']) ?? {};
73
+ const folders = new Map();
74
+ for (const [dir, folder] of Object.entries(projects))
75
+ if (typeof folder === 'string' && path.isAbsolute(dir))
76
+ folders.set(folder, dir);
77
+ return folders;
78
+ }
79
+ /**
80
+ * Read a Gemini CLI chat file as the turns its live hook closed.
81
+ *
82
+ * A turn opens at a user message and runs to the next one; its usage is the
83
+ * replies between them that carry `tokens`, each reply once (Gemini rewrites a
84
+ * reply under the same id when its tokens arrive, and a `$set` snapshot
85
+ * repeats earlier messages). A turn whose replies carry no tokens (a file
86
+ * written before gemini-cli 0.46) is not yielded. Reply and thought content is
87
+ * never kept; a prompt's text only when prompt text is allowed.
88
+ *
89
+ * ponytail: the file's messages are kept in memory as metadata (id, time, tokens)
90
+ * before turns are cut, because a `$set` snapshot can repeat any earlier message.
91
+ * A chat file is one session, so that is thousands of small records at most.
92
+ *
93
+ * @param file - A `session-*.jsonl` file.
94
+ * @param promptText - Whether to keep the prompt's text.
95
+ * @param cwd - The directory the file's project folder stands for, if known.
96
+ * @yields Turns, oldest first.
97
+ */
98
+ export async function* readGeminiTurns(file, promptText, cwd) {
99
+ const lines = readline.createInterface({ input: fs.createReadStream(file, { encoding: 'utf8' }), crlfDelay: Infinity });
100
+ const messages = new Map();
101
+ let sessionId;
102
+ try {
103
+ for await (const line of lines) {
104
+ if (!RE_GEMINI_REPLAY_ROW.test(line))
105
+ continue;
106
+ const row = parseJsonLine(line);
107
+ sessionId ??= firstStringOf(row?.['sessionId']);
108
+ for (const record of replyRows(row))
109
+ remember(messages, record, promptText);
110
+ }
111
+ }
112
+ finally {
113
+ lines.close();
114
+ }
115
+ yield* cutTurns(messages, sessionId ?? path.basename(file), cwd);
116
+ }
117
+ /**
118
+ * Keep what replay needs of one message record; a later record with the same id replaces it.
119
+ *
120
+ * @param messages - The file's messages so far, by id.
121
+ * @param record - One message record.
122
+ * @param promptText - Whether to keep a prompt's text.
123
+ */
124
+ function remember(messages, record, promptText) {
125
+ const id = firstStringOf(record['id']);
126
+ if (!id)
127
+ return;
128
+ const at = firstStringOf(record['timestamp']);
129
+ if (record['type'] === 'user') {
130
+ messages.set(id, { user: true, at, text: promptText ? textOf(record['content']) : undefined });
131
+ return;
132
+ }
133
+ const reply = geminiReplyUsage(record);
134
+ // A reply without tokens yet keeps its place; its rewrite with tokens fills it in.
135
+ if (reply || !messages.has(id))
136
+ messages.set(id, { user: false, at, reply });
137
+ }
138
+ /**
139
+ * The turns a session's messages make: one per user message, with the replies up to the next.
140
+ *
141
+ * @param messages - The messages by id, in the order the file first wrote them.
142
+ * @param sessionId - The session.
143
+ * @param cwd - Where it ran, if known.
144
+ * @yields Turns with usage.
145
+ */
146
+ function* cutTurns(messages, sessionId, cwd) {
147
+ let open;
148
+ const close = () => {
149
+ const usage = open && accumulateUsage(open.usage);
150
+ if (!open?.prompt.at || !usage)
151
+ return undefined;
152
+ return {
153
+ provider: GEMINI_PROVIDER_ID,
154
+ sessionId,
155
+ turnId: REPLAY_FALLBACK_TURN_PREFIX + sha256Hex(`${sessionId}${open.id}`).slice(0, 32),
156
+ startedAt: open.prompt.at,
157
+ endedAt: open.endedAt,
158
+ cwd,
159
+ usage,
160
+ tools: [],
161
+ promptText: open.prompt.text?.trim() || undefined
162
+ };
163
+ };
164
+ for (const [id, message] of messages) {
165
+ if (message.user) {
166
+ const closed = close();
167
+ if (closed)
168
+ yield closed;
169
+ open = { id, prompt: message, endedAt: message.at ?? '', usage: new Map() };
170
+ continue;
171
+ }
172
+ if (!open || !message.reply)
173
+ continue;
174
+ open = { ...open, usage: new Map(open.usage).set(id, message.reply), endedAt: message.at && message.at > open.endedAt ? message.at : open.endedAt };
175
+ }
176
+ const last = close();
177
+ if (last)
178
+ yield last;
179
+ }
180
+ /**
181
+ * The text of a user message: a string, or the `text` of its parts.
182
+ *
183
+ * @param content - The message's `content`.
184
+ * @returns The text, or undefined.
185
+ */
186
+ function textOf(content) {
187
+ if (typeof content === 'string')
188
+ return content;
189
+ if (!Array.isArray(content))
190
+ return undefined;
191
+ return content.map((part) => firstStringOf(asRecord(part)?.['text']) ?? '').join('\n');
192
+ }
@@ -0,0 +1,34 @@
1
+ import type { AgentWatchPaths } from '../storage/types/storage.types.js';
2
+ /**
3
+ * Whether the machine is running on its battery.
4
+ *
5
+ * Fails open to "no": a laptop that cannot say is treated as plugged in, since
6
+ * the other reading would silence replay on every machine without `pmset`.
7
+ *
8
+ * @param platform - The OS.
9
+ * @returns True only when the OS says the battery is discharging.
10
+ */
11
+ export declare function readOnBattery(platform: NodeJS.Platform): Promise<boolean>;
12
+ /**
13
+ * Milliseconds since a hook last did work, read from the state it leaves behind.
14
+ *
15
+ * Every closing hook takes and drops a `turn-close-*` lock, and a lock file
16
+ * appearing or going moves its directory's mtime; a new session's state
17
+ * directory moves the turns directory's. One `stat` each: nothing is added to
18
+ * the hook path for this. A prompt hook alone leaves no trace, which is fine:
19
+ * the Stop is where the hook's weight is.
20
+ *
21
+ * @param paths - Where the edge keeps its state.
22
+ * @param nowMs - The clock.
23
+ * @returns The age, or Infinity when neither directory exists.
24
+ */
25
+ export declare function hookAgeMs(paths: AgentWatchPaths, nowMs: number): Promise<number>;
26
+ /**
27
+ * The 1-minute load average and the core count.
28
+ *
29
+ * @returns Both; the load is 0 on Windows, where the OS reports none.
30
+ */
31
+ export declare function readLoad(): {
32
+ readonly load1: number;
33
+ readonly cores: number;
34
+ };
@@ -0,0 +1,68 @@
1
+ import { execFile } from 'node:child_process';
2
+ import fs from 'node:fs/promises';
3
+ import os from 'node:os';
4
+ const POWER_SOURCE_TIMEOUT_MS = 3_000;
5
+ const RE_ON_BATTERY = /Battery Power/;
6
+ const SYS_POWER_SUPPLY = '/sys/class/power_supply';
7
+ /**
8
+ * Whether the machine is running on its battery.
9
+ *
10
+ * Fails open to "no": a laptop that cannot say is treated as plugged in, since
11
+ * the other reading would silence replay on every machine without `pmset`.
12
+ *
13
+ * @param platform - The OS.
14
+ * @returns True only when the OS says the battery is discharging.
15
+ */
16
+ export async function readOnBattery(platform) {
17
+ if (platform === 'darwin')
18
+ return darwinOnBattery();
19
+ if (platform === 'linux')
20
+ return linuxOnBattery();
21
+ return false;
22
+ }
23
+ function darwinOnBattery() {
24
+ return new Promise((resolve) => {
25
+ execFile('pmset', ['-g', 'batt'], { timeout: POWER_SOURCE_TIMEOUT_MS }, (error, stdout) => resolve(!error && RE_ON_BATTERY.test(stdout)));
26
+ });
27
+ }
28
+ async function linuxOnBattery() {
29
+ try {
30
+ for (const name of await fs.readdir(SYS_POWER_SUPPLY)) {
31
+ if (!name.startsWith('BAT'))
32
+ continue;
33
+ const status = await fs.readFile(`${SYS_POWER_SUPPLY}/${name}/status`, 'utf8');
34
+ if (status.trim() === 'Discharging')
35
+ return true;
36
+ }
37
+ }
38
+ catch {
39
+ return false;
40
+ }
41
+ return false;
42
+ }
43
+ /**
44
+ * Milliseconds since a hook last did work, read from the state it leaves behind.
45
+ *
46
+ * Every closing hook takes and drops a `turn-close-*` lock, and a lock file
47
+ * appearing or going moves its directory's mtime; a new session's state
48
+ * directory moves the turns directory's. One `stat` each: nothing is added to
49
+ * the hook path for this. A prompt hook alone leaves no trace, which is fine:
50
+ * the Stop is where the hook's weight is.
51
+ *
52
+ * @param paths - Where the edge keeps its state.
53
+ * @param nowMs - The clock.
54
+ * @returns The age, or Infinity when neither directory exists.
55
+ */
56
+ export async function hookAgeMs(paths, nowMs) {
57
+ const [locks, turns] = await Promise.all([fs.stat(paths.locksDir).catch(() => undefined), fs.stat(paths.turnsDir).catch(() => undefined)]);
58
+ const newest = Math.max(locks?.mtimeMs ?? 0, turns?.mtimeMs ?? 0);
59
+ return newest === 0 ? Number.POSITIVE_INFINITY : Math.max(0, nowMs - newest);
60
+ }
61
+ /**
62
+ * The 1-minute load average and the core count.
63
+ *
64
+ * @returns Both; the load is 0 on Windows, where the OS reports none.
65
+ */
66
+ export function readLoad() {
67
+ return { load1: os.loadavg()[0] ?? 0, cores: os.availableParallelism() };
68
+ }
@@ -0,0 +1,21 @@
1
+ import type { ReplayProgressEvent } from '../events/types/replay-progress.types.js';
2
+ import type { ReplayRecord } from './types/replay.types.js';
3
+ /** Who a progress record speaks for. */
4
+ export interface ReplayProgressIdentity {
5
+ readonly developerId: string;
6
+ readonly installationId?: string;
7
+ readonly surface?: string;
8
+ }
9
+ /**
10
+ * The `replay.progress` record for a replay's state: counts and the window, nothing else.
11
+ *
12
+ * The id is the run, its state, how many turns were sent and when it was
13
+ * written: each report is its own record. An unchanged repeat (a pause that
14
+ * lasts, a run that waits) must not collide with the last one, or the
15
+ * gateway's ten-minute duplicate window would swallow it.
16
+ *
17
+ * @param record - The replay's persisted state.
18
+ * @param who - The developer it is for.
19
+ * @returns The event.
20
+ */
21
+ export declare function buildReplayProgress(record: ReplayRecord, who: ReplayProgressIdentity): ReplayProgressEvent;
@@ -0,0 +1,45 @@
1
+ import { deriveEventId } from '../events/event-id.js';
2
+ import { EVENT_SCHEMA_VERSION } from '../events/constants/events.constants.js';
3
+ import { DEFAULT_SURFACE } from '../turns/constants/turns.constants.js';
4
+ import { compact } from '../core/object.js';
5
+ import { REPLAY_PROVIDER, REPLAY_PROVIDER_LABEL } from './constants/replay.constants.js';
6
+ /**
7
+ * The `replay.progress` record for a replay's state: counts and the window, nothing else.
8
+ *
9
+ * The id is the run, its state, how many turns were sent and when it was
10
+ * written: each report is its own record. An unchanged repeat (a pause that
11
+ * lasts, a run that waits) must not collide with the last one, or the
12
+ * gateway's ten-minute duplicate window would swallow it.
13
+ *
14
+ * @param record - The replay's persisted state.
15
+ * @param who - The developer it is for.
16
+ * @returns The event.
17
+ */
18
+ export function buildReplayProgress(record, who) {
19
+ return compact({
20
+ schemaVersion: EVENT_SCHEMA_VERSION,
21
+ id: deriveEventId({
22
+ provider: REPLAY_PROVIDER,
23
+ providerEventType: 'replay.progress',
24
+ sessionId: `replay:${record.replayId}`,
25
+ payloadFingerprint: `${record.state}:${record.turnsSent}:${record.updatedAt}`
26
+ }),
27
+ timestamp: record.updatedAt,
28
+ event: { type: 'replay.progress', providerEventType: 'replay.progress' },
29
+ agent: { provider: REPLAY_PROVIDER_LABEL, name: REPLAY_PROVIDER_LABEL },
30
+ session: { id: `replay:${record.replayId}`, providerId: `replay:${record.replayId}` },
31
+ developer: who.installationId ? { installationId: who.installationId } : undefined,
32
+ provider: REPLAY_PROVIDER_LABEL,
33
+ surface: who.surface ?? DEFAULT_SURFACE,
34
+ developer_id: who.developerId,
35
+ replay_id: record.replayId,
36
+ state: record.state,
37
+ window_start: record.windowStart,
38
+ window_end: record.windowEnd,
39
+ turns_total: record.state === 'scanning' ? 0 : record.turnsTotal,
40
+ turns_sent: record.turnsSent,
41
+ sessions_total: record.state === 'scanning' ? 0 : record.sessionsTotal,
42
+ sessions_sent: record.sessionsSent,
43
+ started_at: record.startedAt
44
+ });
45
+ }
@@ -0,0 +1,58 @@
1
+ import type { ReplayPorts, ReplayRecord } from './types/replay.types.js';
2
+ /** What a run of `agentwatch replay` ended as. */
3
+ export type ReplayOutcome = 'done' | 'paused' | 'stopped' | 'skipped' | 'failed';
4
+ /** What a dry run counted, in place of sending. */
5
+ export interface ReplayDryCounts {
6
+ readonly files: number;
7
+ /** The cheap pre-count the progress bar's total is made from. */
8
+ readonly estimate: number;
9
+ /** The turns the run built. */
10
+ readonly turns: number;
11
+ readonly repositories: number;
12
+ /** Files and built turns per agent. */
13
+ readonly agents: Readonly<Record<string, {
14
+ readonly files: number;
15
+ readonly turns: number;
16
+ }>>;
17
+ }
18
+ /** The end of a run, and a sentence for the person who started it. */
19
+ export interface ReplayResult {
20
+ readonly outcome: ReplayOutcome;
21
+ readonly message: string;
22
+ readonly record?: ReplayRecord;
23
+ readonly dry?: ReplayDryCounts;
24
+ }
25
+ /** What a run was asked to do. */
26
+ export interface ReplayRequest {
27
+ readonly days: number;
28
+ readonly resume: boolean;
29
+ /** Build every record and count it; send nothing, write nothing. */
30
+ readonly dryRun: boolean;
31
+ /** Setup's start: never repeat an earlier replay attempt for this identity. */
32
+ readonly skipIfExisting: boolean;
33
+ }
34
+ /**
35
+ * Replay a developer's earlier Claude Code, Codex and Gemini CLI sessions to the backend, slowly.
36
+ *
37
+ * In order: decide whether to begin, continue or leave an earlier replay;
38
+ * count the window's transcripts; send their turns newest first in small
39
+ * batches, each preceded by a look at the machine; send one snapshot per
40
+ * repository; end with a final progress record. A crash or a `--stop` leaves a
41
+ * checkpoint per finished file, and every turn is idempotent downstream, so a
42
+ * rerun costs bandwidth, never correctness.
43
+ *
44
+ * @param ports - The machine, the identity and the transport, handed in.
45
+ * @param request - What was asked.
46
+ * @returns How it ended.
47
+ */
48
+ export declare function runReplay(ports: ReplayPorts, request: ReplayRequest): Promise<ReplayResult>;
49
+ /**
50
+ * `agentwatch replay --stop`: end the replay, wherever it is running.
51
+ *
52
+ * A running replay notices the written state at its next write and reports
53
+ * its own end; one that is not running is ended and reported here.
54
+ *
55
+ * @param ports - The machine.
56
+ * @returns What happened.
57
+ */
58
+ export declare function stopReplay(ports: ReplayPorts): Promise<ReplayResult>;