@agent-watch-ai/edge 0.5.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 (298) hide show
  1. package/CHANGELOG.md +238 -7
  2. package/README.md +308 -8
  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 +8 -2
  76. package/dist/events/constants/events.constants.js +7 -1
  77. package/dist/events/index.d.ts +2 -0
  78. package/dist/events/product-event.d.ts +10 -4
  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-snapshot.types.d.ts +1 -4
  83. package/dist/events/types/repo-tree.types.d.ts +25 -0
  84. package/dist/events/types/repo-tree.types.js +1 -0
  85. package/dist/feature/ticket-candidates.d.ts +1 -1
  86. package/dist/git/checkout-root.d.ts +15 -0
  87. package/dist/git/checkout-root.js +18 -0
  88. package/dist/git/code-state.d.ts +2 -16
  89. package/dist/git/code-state.js +11 -12
  90. package/dist/git/constants/git.constants.d.ts +31 -11
  91. package/dist/git/constants/git.constants.js +36 -12
  92. package/dist/git/constants/tree.constants.d.ts +71 -0
  93. package/dist/git/constants/tree.constants.js +92 -0
  94. package/dist/git/fingerprint.d.ts +3 -6
  95. package/dist/git/fingerprint.js +5 -8
  96. package/dist/git/git-context.d.ts +1 -0
  97. package/dist/git/git-context.js +8 -3
  98. package/dist/git/index.d.ts +1 -2
  99. package/dist/git/index.js +1 -1
  100. package/dist/git/repo-snapshot.d.ts +13 -4
  101. package/dist/git/repo-snapshot.js +47 -9
  102. package/dist/git/repo-tree.d.ts +69 -0
  103. package/dist/git/repo-tree.js +130 -0
  104. package/dist/git/types/git.types.d.ts +5 -2
  105. package/dist/git/types/snapshot.types.d.ts +14 -0
  106. package/dist/pipeline/constants/pipeline.constants.d.ts +3 -0
  107. package/dist/pipeline/constants/pipeline.constants.js +3 -0
  108. package/dist/pipeline/hook-pipeline.js +112 -72
  109. package/dist/privacy/product-capture.js +36 -5
  110. package/dist/providers/antigravity/antigravity.capture.d.ts +2 -0
  111. package/dist/providers/antigravity/antigravity.capture.js +5 -0
  112. package/dist/providers/antigravity/antigravity.detect.js +8 -22
  113. package/dist/providers/antigravity/antigravity.provider.js +10 -3
  114. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +1 -0
  115. package/dist/providers/antigravity/constants/antigravity.constants.js +1 -0
  116. package/dist/providers/claude/claude.adapter.js +9 -6
  117. package/dist/providers/claude/claude.detect.js +2 -17
  118. package/dist/providers/claude/claude.otel.d.ts +21 -3
  119. package/dist/providers/claude/claude.otel.js +216 -61
  120. package/dist/providers/claude/claude.provider.js +17 -1
  121. package/dist/providers/claude/claude.version.d.ts +9 -0
  122. package/dist/providers/claude/claude.version.js +28 -0
  123. package/dist/providers/claude/constants/claude.constants.d.ts +27 -0
  124. package/dist/providers/claude/constants/claude.constants.js +27 -0
  125. package/dist/providers/claude/constants/claude.otel.constants.d.ts +27 -0
  126. package/dist/providers/claude/constants/claude.otel.constants.js +45 -5
  127. package/dist/providers/claude/types/claude.types.d.ts +13 -0
  128. package/dist/providers/codex/codex.capture.d.ts +76 -0
  129. package/dist/providers/codex/codex.capture.js +454 -0
  130. package/dist/providers/codex/codex.detect.js +2 -4
  131. package/dist/providers/codex/codex.otel.d.ts +38 -2
  132. package/dist/providers/codex/codex.otel.js +50 -6
  133. package/dist/providers/codex/codex.provider.js +8 -0
  134. package/dist/providers/codex/codex.surface.d.ts +9 -0
  135. package/dist/{turns/codex-originator.js → providers/codex/codex.surface.js} +17 -3
  136. package/dist/providers/codex/codex.titles.d.ts +14 -0
  137. package/dist/providers/codex/codex.titles.js +35 -0
  138. package/dist/providers/codex/constants/codex.constants.d.ts +4 -0
  139. package/dist/providers/codex/constants/codex.constants.js +4 -0
  140. package/dist/providers/cursor/constants/cursor.constants.d.ts +17 -4
  141. package/dist/providers/cursor/constants/cursor.constants.js +25 -5
  142. package/dist/providers/cursor/cursor-mcp-memo.d.ts +34 -0
  143. package/dist/providers/cursor/cursor-mcp-memo.js +94 -0
  144. package/dist/providers/cursor/cursor.adapter.js +20 -82
  145. package/dist/providers/cursor/cursor.capture.d.ts +1 -0
  146. package/dist/providers/cursor/cursor.capture.js +4 -0
  147. package/dist/providers/cursor/cursor.detect.d.ts +5 -1
  148. package/dist/providers/cursor/cursor.detect.js +11 -26
  149. package/dist/providers/cursor/cursor.hooks.js +2 -2
  150. package/dist/providers/cursor/cursor.provider.js +16 -7
  151. package/dist/providers/cursor/cursor.titles.d.ts +14 -0
  152. package/dist/providers/cursor/cursor.titles.js +20 -0
  153. package/dist/providers/cursor/schemas/cursor.schema.d.ts +3 -3
  154. package/dist/providers/cursor/schemas/cursor.schema.js +5 -3
  155. package/dist/providers/gemini/constants/gemini.constants.d.ts +16 -0
  156. package/dist/providers/gemini/constants/gemini.constants.js +17 -0
  157. package/dist/providers/gemini/gemini.capture.d.ts +81 -0
  158. package/dist/providers/gemini/gemini.capture.js +210 -0
  159. package/dist/providers/gemini/gemini.detect.js +57 -24
  160. package/dist/providers/gemini/gemini.otel.d.ts +38 -2
  161. package/dist/providers/gemini/gemini.otel.js +56 -125
  162. package/dist/providers/gemini/gemini.provider.js +5 -0
  163. package/dist/providers/index.d.ts +1 -0
  164. package/dist/providers/index.js +1 -0
  165. package/dist/providers/provider.d.ts +8 -0
  166. package/dist/providers/provider.js +9 -0
  167. package/dist/providers/registry.d.ts +14 -0
  168. package/dist/providers/registry.js +14 -0
  169. package/dist/providers/shared/constants/hook-config.constants.d.ts +2 -0
  170. package/dist/providers/shared/constants/hook-config.constants.js +2 -0
  171. package/dist/providers/shared/constants/terminal-capture.constants.d.ts +6 -0
  172. package/dist/providers/shared/constants/terminal-capture.constants.js +6 -0
  173. package/dist/providers/shared/editor-paths.d.ts +8 -0
  174. package/dist/providers/shared/editor-paths.js +18 -0
  175. package/dist/providers/shared/hook-config.d.ts +5 -0
  176. package/dist/providers/shared/hook-config.js +39 -1
  177. package/dist/providers/shared/hooks-marker.d.ts +14 -0
  178. package/dist/providers/shared/hooks-marker.js +23 -0
  179. package/dist/providers/shared/install-record.d.ts +29 -0
  180. package/dist/providers/shared/install-record.js +52 -0
  181. package/dist/providers/shared/session-title-store.d.ts +23 -0
  182. package/dist/providers/shared/session-title-store.js +50 -0
  183. package/dist/providers/shared/terminal-capture.d.ts +41 -0
  184. package/dist/providers/shared/terminal-capture.js +109 -0
  185. package/dist/providers/shared/tooling.d.ts +21 -0
  186. package/dist/providers/shared/tooling.js +36 -1
  187. package/dist/providers/types/provider.types.d.ts +57 -4
  188. package/dist/replay/checkout-resolver.d.ts +29 -0
  189. package/dist/replay/checkout-resolver.js +69 -0
  190. package/dist/replay/codex-turns.d.ts +24 -0
  191. package/dist/replay/codex-turns.js +221 -0
  192. package/dist/replay/constants/replay.constants.d.ts +99 -0
  193. package/dist/replay/constants/replay.constants.js +102 -0
  194. package/dist/replay/describe.d.ts +10 -0
  195. package/dist/replay/describe.js +31 -0
  196. package/dist/replay/gemini-turns.d.ts +36 -0
  197. package/dist/replay/gemini-turns.js +192 -0
  198. package/dist/replay/machine.d.ts +34 -0
  199. package/dist/replay/machine.js +68 -0
  200. package/dist/replay/progress-event.d.ts +21 -0
  201. package/dist/replay/progress-event.js +45 -0
  202. package/dist/replay/replay-runner.d.ts +58 -0
  203. package/dist/replay/replay-runner.js +529 -0
  204. package/dist/replay/replay-scan.d.ts +83 -0
  205. package/dist/replay/replay-scan.js +170 -0
  206. package/dist/replay/replay-state.d.ts +108 -0
  207. package/dist/replay/replay-state.js +199 -0
  208. package/dist/replay/resume.d.ts +18 -0
  209. package/dist/replay/resume.js +34 -0
  210. package/dist/replay/start.d.ts +23 -0
  211. package/dist/replay/start.js +39 -0
  212. package/dist/replay/throttle.d.ts +35 -0
  213. package/dist/replay/throttle.js +41 -0
  214. package/dist/replay/transcript-turns.d.ts +35 -0
  215. package/dist/replay/transcript-turns.js +215 -0
  216. package/dist/replay/turn-event.d.ts +38 -0
  217. package/dist/replay/turn-event.js +116 -0
  218. package/dist/replay/types/replay.types.d.ts +162 -0
  219. package/dist/replay/types/replay.types.js +1 -0
  220. package/dist/replay/window.d.ts +28 -0
  221. package/dist/replay/window.js +41 -0
  222. package/dist/snapshot/branch-selection.d.ts +40 -23
  223. package/dist/snapshot/branch-selection.js +74 -42
  224. package/dist/snapshot/budget.js +2 -2
  225. package/dist/snapshot/constants/snapshot-stages.constants.d.ts +10 -0
  226. package/dist/snapshot/constants/snapshot-stages.constants.js +10 -0
  227. package/dist/snapshot/constants/snapshot.constants.d.ts +37 -4
  228. package/dist/snapshot/constants/snapshot.constants.js +37 -4
  229. package/dist/snapshot/index.d.ts +6 -1
  230. package/dist/snapshot/index.js +3 -1
  231. package/dist/snapshot/snapshot-event.d.ts +7 -0
  232. package/dist/snapshot/snapshot-event.js +8 -5
  233. package/dist/snapshot/snapshot-pipeline.js +89 -26
  234. package/dist/snapshot/snapshot-state.js +24 -2
  235. package/dist/snapshot/tree-event.d.ts +14 -0
  236. package/dist/snapshot/tree-event.js +91 -0
  237. package/dist/snapshot/tree-pipeline.d.ts +12 -0
  238. package/dist/snapshot/tree-pipeline.js +172 -0
  239. package/dist/snapshot/types/snapshot.types.d.ts +62 -2
  240. package/dist/storage/schemas/storage.schema.d.ts +2 -0
  241. package/dist/storage/schemas/storage.schema.js +6 -0
  242. package/dist/transport/constants/transport.constants.d.ts +5 -0
  243. package/dist/transport/constants/transport.constants.js +5 -0
  244. package/dist/transport/delivery-stats.d.ts +13 -1
  245. package/dist/transport/delivery-stats.js +18 -2
  246. package/dist/transport/delivery.d.ts +4 -3
  247. package/dist/transport/delivery.js +21 -7
  248. package/dist/transport/identity-delivery.d.ts +20 -0
  249. package/dist/transport/identity-delivery.js +41 -0
  250. package/dist/transport/index.d.ts +2 -0
  251. package/dist/transport/index.js +1 -0
  252. package/dist/transport/queue.js +40 -6
  253. package/dist/transport/types/delivery-flow.types.d.ts +7 -0
  254. package/dist/turns/claude-transcript.js +4 -12
  255. package/dist/turns/codex-transcript.d.ts +9 -0
  256. package/dist/turns/codex-transcript.js +27 -19
  257. package/dist/turns/constants/turns.constants.d.ts +13 -12
  258. package/dist/turns/constants/turns.constants.js +15 -19
  259. package/dist/turns/gemini-transcript.d.ts +19 -1
  260. package/dist/turns/gemini-transcript.js +29 -18
  261. package/dist/turns/index.d.ts +3 -4
  262. package/dist/turns/index.js +2 -3
  263. package/dist/turns/run-state.d.ts +71 -0
  264. package/dist/turns/run-state.js +114 -0
  265. package/dist/turns/tool-events.d.ts +11 -1
  266. package/dist/turns/tool-events.js +32 -9
  267. package/dist/turns/transcript.d.ts +15 -14
  268. package/dist/turns/transcript.js +23 -4
  269. package/dist/turns/turn-state.d.ts +49 -7
  270. package/dist/turns/turn-state.js +78 -10
  271. package/dist/turns/turn-summary.js +10 -6
  272. package/dist/turns/turn-tracker.d.ts +9 -16
  273. package/dist/turns/turn-tracker.js +162 -86
  274. package/dist/turns/types/transcript.types.d.ts +11 -1
  275. package/dist/turns/types/turn-provider.types.d.ts +33 -0
  276. package/dist/turns/types/turn-provider.types.js +1 -0
  277. package/dist/turns/types/turn-state.types.d.ts +9 -0
  278. package/dist/turns/types/turn-summary.types.d.ts +20 -6
  279. package/dist/turns/types/turn-tracker.types.d.ts +3 -1
  280. package/dist/turns/work-checkout.js +1 -2
  281. package/docs/AUDIT_PROMPT.md +10 -0
  282. package/docs/DATA_HANDLING.md +269 -32
  283. package/docs/ENTERPRISE_DEPLOYMENT.md +1 -1
  284. package/docs/PERFORMANCE.md +27 -0
  285. package/package.json +3 -2
  286. package/dist/events/canonical-event.d.ts +0 -10
  287. package/dist/events/canonical-event.js +0 -9
  288. package/dist/git/repository-root.d.ts +0 -39
  289. package/dist/git/repository-root.js +0 -131
  290. package/dist/git/types/repository-root.types.d.ts +0 -11
  291. package/dist/transport/transport.d.ts +0 -6
  292. package/dist/turns/codex-originator.d.ts +0 -11
  293. package/dist/turns/cursor-transcript.d.ts +0 -21
  294. package/dist/turns/cursor-transcript.js +0 -66
  295. package/dist/turns/native-session-titles.d.ts +0 -26
  296. package/dist/turns/native-session-titles.js +0 -102
  297. /package/dist/{git/types/repository-root.types.js → billing/types/billing.types.js} +0 -0
  298. /package/dist/{transport/transport.js → capture/types/capture.types.js} +0 -0
@@ -1,37 +1,54 @@
1
1
  import type { BranchRef } from '../git/types/snapshot.types.js';
2
- import type { SelectionInput, SnapshotState } from './types/snapshot.types.js';
2
+ import type { SelectionInput, SnapshotCandidate, SnapshotState } from './types/snapshot.types.js';
3
3
  /**
4
- * Which branches are worth describing again.
4
+ * The branches the snapshot walks, newest commit first, and which of them are due.
5
5
  *
6
- * Four reasons, and each one is a bug if it is missing:
6
+ * A branch already found on the trunk, at the same head and against the same
7
+ * base, is left out without a git process: merged stays merged, and that is
8
+ * what lets the walk pass the dozens of finished branches a busy repository
9
+ * keeps to reach the live ones behind them. Every other branch is a candidate,
10
+ * due when one of these holds — and each one is a bug if it is missing:
7
11
  *
8
- * - the branch is new — nothing has ever been reported about it;
9
- * - its head moved — the obvious one;
10
- * - the default branch changed since the last send, because every delta was
11
- * computed against the wrong base and no head has to move for that to be
12
- * true;
13
- * - the entry is older than the heartbeat, which is the only thing that ever
14
- * re-offers a finished branch to a tracker connected after the fact.
12
+ * - the branch is new — nothing has ever been checked about it;
13
+ * - its head moved — the obvious one, and how a merged branch with new work
14
+ * comes back;
15
+ * - the default branch changed since it was checked, because its delta and its
16
+ * verdict were computed against the wrong base and no head has to move for
17
+ * that to be true;
18
+ * - it was last sent longer ago than the heartbeat, which is the only thing
19
+ * that ever re-offers a finished branch to a tracker connected after the fact.
15
20
  *
16
- * @param input - The refs git reported and what was last sent.
17
- * @returns The branches to describe. Empty means send nothing at all.
21
+ * @param input - The refs git reported and what was last recorded.
22
+ * @returns The candidates in walk order.
18
23
  */
19
- export declare function selectChangedBranches(input: SelectionInput): readonly BranchRef[];
24
+ export declare function snapshotCandidates(input: SelectionInput): readonly SnapshotCandidate[];
25
+ /**
26
+ * Whether the walk would reach a due branch before the window is full.
27
+ *
28
+ * The cheap exit on an ordinary closing turn: the first ten live branches are
29
+ * all as they were sent, so no git process runs and nothing is queued.
30
+ *
31
+ * @param candidates - The walk, from {@link snapshotCandidates}.
32
+ * @returns True when something has to be checked.
33
+ */
34
+ export declare function anyDue(candidates: readonly SnapshotCandidate[]): boolean;
20
35
  /**
21
36
  * The state to store once a snapshot has been queued.
22
37
  *
23
- * A branch is recorded as reported only if it was actually described. The
24
- * cache is a record of what the platform has been told, not of what git said:
25
- * a branch whose head moved and which then fell outside the budget must keep
26
- * its *old* head here, or the next turn compares the new head against the new
27
- * head, finds them equal, and the work disappears until the heartbeat six hours
28
- * later.
38
+ * A branch is recorded only if it was actually checked. The cache is a record
39
+ * of what the platform has been told, not of what git said: a branch whose head
40
+ * moved and which then fell outside the budget must keep its *old* head here,
41
+ * or the next turn compares the new head against the new head, finds them
42
+ * equal, and the work disappears until the heartbeat six hours later.
29
43
  *
30
- * A branch that was listed but never sent is therefore left exactly as it was —
31
- * and one that has never been sent at all is left out, so it stays new.
44
+ * A branch found on the trunk is recorded as merged: the platform has been told
45
+ * all there is, and the verdict is what keeps every later turn from checking it
46
+ * again. Each entry carries the base it was checked against, so a trunk change
47
+ * re-checks branch by branch and a budget cut part-way loses nothing.
32
48
  *
33
49
  * @param input - Refs, previous state and the send's own clock.
34
- * @param sent - The branches this snapshot actually described.
50
+ * @param sent - The live branches this snapshot described.
51
+ * @param merged - The branches it found already on the trunk.
35
52
  * @returns The state to write.
36
53
  */
37
- export declare function nextSnapshotState(input: SelectionInput, sent: readonly BranchRef[]): SnapshotState;
54
+ export declare function nextSnapshotState(input: SelectionInput, sent: readonly BranchRef[], merged?: readonly BranchRef[]): SnapshotState;
@@ -1,69 +1,101 @@
1
- import { SNAPSHOT_REFRESH_MS } from './constants/snapshot.constants.js';
1
+ import { SNAPSHOT_BRANCH_COUNT, SNAPSHOT_REFRESH_MS } from './constants/snapshot.constants.js';
2
2
  /**
3
- * Which branches are worth describing again.
3
+ * The branches the snapshot walks, newest commit first, and which of them are due.
4
4
  *
5
- * Four reasons, and each one is a bug if it is missing:
5
+ * A branch already found on the trunk, at the same head and against the same
6
+ * base, is left out without a git process: merged stays merged, and that is
7
+ * what lets the walk pass the dozens of finished branches a busy repository
8
+ * keeps to reach the live ones behind them. Every other branch is a candidate,
9
+ * due when one of these holds — and each one is a bug if it is missing:
6
10
  *
7
- * - the branch is new — nothing has ever been reported about it;
8
- * - its head moved — the obvious one;
9
- * - the default branch changed since the last send, because every delta was
10
- * computed against the wrong base and no head has to move for that to be
11
- * true;
12
- * - the entry is older than the heartbeat, which is the only thing that ever
13
- * re-offers a finished branch to a tracker connected after the fact.
11
+ * - the branch is new — nothing has ever been checked about it;
12
+ * - its head moved — the obvious one, and how a merged branch with new work
13
+ * comes back;
14
+ * - the default branch changed since it was checked, because its delta and its
15
+ * verdict were computed against the wrong base and no head has to move for
16
+ * that to be true;
17
+ * - it was last sent longer ago than the heartbeat, which is the only thing
18
+ * that ever re-offers a finished branch to a tracker connected after the fact.
14
19
  *
15
- * @param input - The refs git reported and what was last sent.
16
- * @returns The branches to describe. Empty means send nothing at all.
20
+ * @param input - The refs git reported and what was last recorded.
21
+ * @returns The candidates in walk order.
17
22
  */
18
- export function selectChangedBranches(input) {
19
- const rebased = input.stored.defaultBranch !== input.defaultBranch;
20
- return input.refs.filter((ref) => {
21
- if (rebased)
22
- return true;
23
+ export function snapshotCandidates(input) {
24
+ const candidates = [];
25
+ for (const ref of input.refs) {
23
26
  const entry = input.stored.branches[ref.name];
24
- if (!entry)
25
- return true;
26
- if (entry.headSha !== ref.headSha)
27
- return true;
28
- return input.now - entry.lastSentAt >= SNAPSHOT_REFRESH_MS;
29
- });
27
+ const current = entry !== undefined && entry.headSha === ref.headSha && entryBase(entry, input.stored) === input.defaultBranch;
28
+ if (current && entry.merged)
29
+ continue;
30
+ candidates.push({ ref, due: !current || input.now - entry.lastSentAt >= SNAPSHOT_REFRESH_MS });
31
+ }
32
+ return candidates;
33
+ }
34
+ /**
35
+ * Whether the walk would reach a due branch before the window is full.
36
+ *
37
+ * The cheap exit on an ordinary closing turn: the first ten live branches are
38
+ * all as they were sent, so no git process runs and nothing is queued.
39
+ *
40
+ * @param candidates - The walk, from {@link snapshotCandidates}.
41
+ * @returns True when something has to be checked.
42
+ */
43
+ export function anyDue(candidates) {
44
+ const reached = candidates.slice(0, SNAPSHOT_BRANCH_COUNT);
45
+ return reached.some((candidate) => candidate.due);
30
46
  }
31
47
  /**
32
48
  * The state to store once a snapshot has been queued.
33
49
  *
34
- * A branch is recorded as reported only if it was actually described. The
35
- * cache is a record of what the platform has been told, not of what git said:
36
- * a branch whose head moved and which then fell outside the budget must keep
37
- * its *old* head here, or the next turn compares the new head against the new
38
- * head, finds them equal, and the work disappears until the heartbeat six hours
39
- * later.
50
+ * A branch is recorded only if it was actually checked. The cache is a record
51
+ * of what the platform has been told, not of what git said: a branch whose head
52
+ * moved and which then fell outside the budget must keep its *old* head here,
53
+ * or the next turn compares the new head against the new head, finds them
54
+ * equal, and the work disappears until the heartbeat six hours later.
40
55
  *
41
- * A branch that was listed but never sent is therefore left exactly as it was —
42
- * and one that has never been sent at all is left out, so it stays new.
56
+ * A branch found on the trunk is recorded as merged: the platform has been told
57
+ * all there is, and the verdict is what keeps every later turn from checking it
58
+ * again. Each entry carries the base it was checked against, so a trunk change
59
+ * re-checks branch by branch and a budget cut part-way loses nothing.
43
60
  *
44
61
  * @param input - Refs, previous state and the send's own clock.
45
- * @param sent - The branches this snapshot actually described.
62
+ * @param sent - The live branches this snapshot described.
63
+ * @param merged - The branches it found already on the trunk.
46
64
  * @returns The state to write.
47
65
  */
48
- export function nextSnapshotState(input, sent) {
66
+ export function nextSnapshotState(input, sent, merged = []) {
49
67
  const sentNames = new Set(sent.map((ref) => ref.name));
68
+ const mergedNames = new Set(merged.map((ref) => ref.name));
50
69
  const branches = {};
51
70
  for (const ref of input.refs) {
52
71
  if (sentNames.has(ref.name)) {
53
- branches[ref.name] = { headSha: ref.headSha, lastSentAt: input.now };
72
+ branches[ref.name] = { headSha: ref.headSha, lastSentAt: input.now, base: input.defaultBranch };
73
+ continue;
74
+ }
75
+ if (mergedNames.has(ref.name)) {
76
+ branches[ref.name] = { headSha: ref.headSha, lastSentAt: input.now, base: input.defaultBranch, merged: true };
54
77
  continue;
55
78
  }
56
79
  const previous = input.stored.branches[ref.name];
80
+ // An entry from before bases were per branch takes the repository's, so
81
+ // the recorded default branch below can move without re-dating it.
57
82
  if (previous)
58
- branches[ref.name] = previous;
83
+ branches[ref.name] = { ...previous, base: entryBase(previous, input.stored) };
59
84
  }
60
- // The recorded base only moves once every branch has been described against
61
- // it. Recording it early would end the `rebased` selection for branches whose
62
- // deltas were never recomputed, and they would sit on the wrong base until
63
- // their heads happened to move.
64
- const described = input.refs.every((ref) => sentNames.has(ref.name));
85
+ // The tree is the tree flow's to write; a branch send carries it over untouched.
65
86
  return {
66
- defaultBranch: described ? input.defaultBranch : input.stored.defaultBranch,
67
- branches
87
+ defaultBranch: input.defaultBranch,
88
+ branches,
89
+ ...(input.stored.tree ? { tree: input.stored.tree } : {})
68
90
  };
69
91
  }
92
+ /**
93
+ * The base an entry was checked against.
94
+ *
95
+ * @param entry - One stored branch.
96
+ * @param stored - Its state, whose default branch an older entry inherits.
97
+ * @returns The base name, or undefined when there was none.
98
+ */
99
+ function entryBase(entry, stored) {
100
+ return entry.base ?? stored.defaultBranch;
101
+ }
@@ -27,11 +27,11 @@ export function remainingMs(deadline, now = Date.now) {
27
27
  * @returns A runner whose timeout is whatever is left, capped at the git default.
28
28
  */
29
29
  export function budgetedRunner(run, deadline, now = Date.now) {
30
- return async (args, cwd, timeoutMs, home) => {
30
+ return async (args, cwd, timeoutMs, home, maxBufferBytes) => {
31
31
  const left = remainingMs(deadline, now);
32
32
  if (left === 0)
33
33
  return undefined;
34
- return run(args, cwd, Math.min(timeoutMs || GIT_TIMEOUT_MS, left), home);
34
+ return run(args, cwd, Math.min(timeoutMs || GIT_TIMEOUT_MS, left), home, maxBufferBytes);
35
35
  };
36
36
  }
37
37
  /**
@@ -7,5 +7,15 @@ export declare const STAGE_ENQUEUE = "enqueue";
7
7
  /** Reasons a stage ends the flow early. */
8
8
  export declare const STOP_NOT_A_REPOSITORY = "no branches: not a repository, or it has none";
9
9
  export declare const STOP_NOTHING_CHANGED = "no branch moved and none is due a refresh";
10
+ export declare const STOP_ALL_ON_TRUNK = "every checked branch is already on the trunk";
10
11
  export declare const STOP_BUDGET_SPENT = "snapshot budget spent";
11
12
  export declare const STOP_NO_EVENT = "no snapshot event was built";
13
+ /** The tree flow's stages and stops. */
14
+ export declare const STAGE_TREE_DUE = "tree-due";
15
+ export declare const STAGE_TREE_RESOLVE = "tree-resolve";
16
+ export declare const STAGE_TREE_CHANGED = "tree-changed";
17
+ export declare const STAGE_TREE_COLLECT = "tree-collect";
18
+ export declare const STOP_TREE_SENT = "trunk tree already sent for this repository and identity";
19
+ export declare const STOP_TREE_NOT_DUE = "tree attempt failed within the last hour";
20
+ export declare const STOP_TREE_NO_TRUNK = "no default branch tree to list";
21
+ export declare const STOP_TREE_UNLISTED = "tree could not be listed";
@@ -7,5 +7,15 @@ export const STAGE_ENQUEUE = 'enqueue';
7
7
  /** Reasons a stage ends the flow early. */
8
8
  export const STOP_NOT_A_REPOSITORY = 'no branches: not a repository, or it has none';
9
9
  export const STOP_NOTHING_CHANGED = 'no branch moved and none is due a refresh';
10
+ export const STOP_ALL_ON_TRUNK = 'every checked branch is already on the trunk';
10
11
  export const STOP_BUDGET_SPENT = 'snapshot budget spent';
11
12
  export const STOP_NO_EVENT = 'no snapshot event was built';
13
+ /** The tree flow's stages and stops. */
14
+ export const STAGE_TREE_DUE = 'tree-due';
15
+ export const STAGE_TREE_RESOLVE = 'tree-resolve';
16
+ export const STAGE_TREE_CHANGED = 'tree-changed';
17
+ export const STAGE_TREE_COLLECT = 'tree-collect';
18
+ export const STOP_TREE_SENT = 'trunk tree already sent for this repository and identity';
19
+ export const STOP_TREE_NOT_DUE = 'tree attempt failed within the last hour';
20
+ export const STOP_TREE_NO_TRUNK = 'no default branch tree to list';
21
+ export const STOP_TREE_UNLISTED = 'tree could not be listed';
@@ -1,11 +1,37 @@
1
1
  /**
2
- * How many branches one snapshot describes.
2
+ * How many live branches one snapshot describes.
3
3
  *
4
- * The ten most recently committed: enough to cover what anyone is actually
5
- * working on, few enough that the listing is one cheap git process and the
6
- * backend's per-branch transaction count stays bounded.
4
+ * The ten most recently committed that are not already on the trunk: enough to
5
+ * cover what anyone is actually working on, few enough that the backend's
6
+ * per-branch transaction count stays bounded.
7
7
  */
8
8
  export declare const SNAPSHOT_BRANCH_COUNT = 10;
9
+ /**
10
+ * How many branches the listing reads, newest commit first, to find those ten.
11
+ *
12
+ * Merged branches are passed over, so the ten live ones can sit deep: 46 down
13
+ * on agent-watch-core (294 local branches, October 2026). Still one process —
14
+ * all 294 list in ~40 ms — and the bound keeps the state file small.
15
+ */
16
+ export declare const SNAPSHOT_SCAN_COUNT = 100;
17
+ /**
18
+ * How many branches one snapshot may check with git.
19
+ *
20
+ * A check is the delta log plus, when it has commits, a merge-tree and a tree
21
+ * read: ~70 ms on agent-watch-core. Finding its ten live branches from an empty
22
+ * cache took 18 checks (27 more were passed for a gone upstream at no cost); the
23
+ * budget usually ends a first snapshot before this does, and verdicts are
24
+ * remembered, so the next turn continues where it stopped.
25
+ */
26
+ export declare const SNAPSHOT_MAX_CHECKS = 20;
27
+ /**
28
+ * Budget the checks leave for queueing the event and writing the state.
29
+ *
30
+ * Without it a walk that ran to the deadline would queue nothing and record
31
+ * nothing, and on a repository that always needs more than the budget no turn
32
+ * would ever make progress.
33
+ */
34
+ export declare const SNAPSHOT_WRITE_RESERVE_MS = 100;
9
35
  /**
10
36
  * How many of a branch's own commits travel with it.
11
37
  *
@@ -86,3 +112,10 @@ export declare const SNAPSHOT_MAX_PATH_LENGTH = 1024;
86
112
  export declare const SNAPSHOT_RE_CONTROL_CHARACTER: RegExp;
87
113
  /** Hex characters kept from the repository digest that names a state file. */
88
114
  export declare const SNAPSHOT_STATE_HASH_LENGTH = 32;
115
+ /**
116
+ * How long a repository waits between `repo.tree` checks: after a failed
117
+ * attempt (no trunk, listing failed, budget spent), and between comparisons of
118
+ * the trunk's tree oid with the one already sent. Bounds the git cost to one
119
+ * oid lookup an hour per repository.
120
+ */
121
+ export declare const TREE_RETRY_INTERVAL_MS: number;
@@ -1,11 +1,37 @@
1
1
  /**
2
- * How many branches one snapshot describes.
2
+ * How many live branches one snapshot describes.
3
3
  *
4
- * The ten most recently committed: enough to cover what anyone is actually
5
- * working on, few enough that the listing is one cheap git process and the
6
- * backend's per-branch transaction count stays bounded.
4
+ * The ten most recently committed that are not already on the trunk: enough to
5
+ * cover what anyone is actually working on, few enough that the backend's
6
+ * per-branch transaction count stays bounded.
7
7
  */
8
8
  export const SNAPSHOT_BRANCH_COUNT = 10;
9
+ /**
10
+ * How many branches the listing reads, newest commit first, to find those ten.
11
+ *
12
+ * Merged branches are passed over, so the ten live ones can sit deep: 46 down
13
+ * on agent-watch-core (294 local branches, October 2026). Still one process —
14
+ * all 294 list in ~40 ms — and the bound keeps the state file small.
15
+ */
16
+ export const SNAPSHOT_SCAN_COUNT = 100;
17
+ /**
18
+ * How many branches one snapshot may check with git.
19
+ *
20
+ * A check is the delta log plus, when it has commits, a merge-tree and a tree
21
+ * read: ~70 ms on agent-watch-core. Finding its ten live branches from an empty
22
+ * cache took 18 checks (27 more were passed for a gone upstream at no cost); the
23
+ * budget usually ends a first snapshot before this does, and verdicts are
24
+ * remembered, so the next turn continues where it stopped.
25
+ */
26
+ export const SNAPSHOT_MAX_CHECKS = 20;
27
+ /**
28
+ * Budget the checks leave for queueing the event and writing the state.
29
+ *
30
+ * Without it a walk that ran to the deadline would queue nothing and record
31
+ * nothing, and on a repository that always needs more than the budget no turn
32
+ * would ever make progress.
33
+ */
34
+ export const SNAPSHOT_WRITE_RESERVE_MS = 100;
9
35
  /**
10
36
  * How many of a branch's own commits travel with it.
11
37
  *
@@ -87,3 +113,10 @@ export const SNAPSHOT_MAX_PATH_LENGTH = 1024;
87
113
  export const SNAPSHOT_RE_CONTROL_CHARACTER = /[\x00-\x1f\x7f]/;
88
114
  /** Hex characters kept from the repository digest that names a state file. */
89
115
  export const SNAPSHOT_STATE_HASH_LENGTH = 32;
116
+ /**
117
+ * How long a repository waits between `repo.tree` checks: after a failed
118
+ * attempt (no trunk, listing failed, budget spent), and between comparisons of
119
+ * the trunk's tree oid with the one already sent. Bounds the git cost to one
120
+ * oid lookup an hour per repository.
121
+ */
122
+ export const TREE_RETRY_INTERVAL_MS = 60 * 60 * 1000;
@@ -6,11 +6,16 @@
6
6
  * layer is an overlay on work items, and a team with no tracker connected has
7
7
  * none — the branches on this machine are then the only evidence that a piece
8
8
  * of work exists at all.
9
+ *
10
+ * The tree flow beside it sends the trunk's source paths and declaration names
11
+ * (`repo.tree`) per repository and identity, again when the trunk's tree changes, for a tenant whose code nothing may clone.
9
12
  */
10
13
  export type { BuildSnapshotInput, SelectionInput, SnapshotFlowInput, SnapshotFlowState, SnapshotIdentity, SnapshotPipelineInput, SnapshotQueue, SnapshotState, SnapshotStateEntry, SnapshotStateReader } from './types/snapshot.types.js';
11
14
  export { SNAPSHOT_BRANCH_COUNT, SNAPSHOT_BUDGET_MS, SNAPSHOT_COMMITS_PER_BRANCH, SNAPSHOT_REFRESH_MS } from './constants/snapshot.constants.js';
12
- export { nextSnapshotState, selectChangedBranches } from './branch-selection.js';
15
+ export { anyDue, nextSnapshotState, snapshotCandidates } from './branch-selection.js';
13
16
  export { budgetedRunner, remainingMs, withinBudget } from './budget.js';
14
17
  export { buildRepoSnapshot } from './snapshot-event.js';
15
18
  export { runSnapshotPipeline } from './snapshot-pipeline.js';
19
+ export { buildRepoTree } from './tree-event.js';
20
+ export { runTreePipeline } from './tree-pipeline.js';
16
21
  export { SnapshotStateStore, emptyState } from './snapshot-state.js';
@@ -1,6 +1,8 @@
1
1
  export { SNAPSHOT_BRANCH_COUNT, SNAPSHOT_BUDGET_MS, SNAPSHOT_COMMITS_PER_BRANCH, SNAPSHOT_REFRESH_MS } from './constants/snapshot.constants.js';
2
- export { nextSnapshotState, selectChangedBranches } from './branch-selection.js';
2
+ export { anyDue, nextSnapshotState, snapshotCandidates } from './branch-selection.js';
3
3
  export { budgetedRunner, remainingMs, withinBudget } from './budget.js';
4
4
  export { buildRepoSnapshot } from './snapshot-event.js';
5
5
  export { runSnapshotPipeline } from './snapshot-pipeline.js';
6
+ export { buildRepoTree } from './tree-event.js';
7
+ export { runTreePipeline } from './tree-pipeline.js';
6
8
  export { SnapshotStateStore, emptyState } from './snapshot-state.js';
@@ -15,3 +15,10 @@ import type { BuildSnapshotInput } from './types/snapshot.types.js';
15
15
  * @returns The snapshot event.
16
16
  */
17
17
  export declare function buildRepoSnapshot(input: BuildSnapshotInput): RepoSnapshotEvent;
18
+ /**
19
+ * Whether a path may be named at all: not over-long, no control characters, not a credential file.
20
+ *
21
+ * @param filePath - Repository-relative path.
22
+ * @returns True when the path may be sent.
23
+ */
24
+ export declare function sendable(filePath: string): boolean;
@@ -49,11 +49,9 @@ export function buildRepoSnapshot(input) {
49
49
  return compact({
50
50
  name: branch.name,
51
51
  head_sha: branch.headSha,
52
- last_commit_at: branch.lastCommitAt,
53
52
  commits: branch.commits.map((commit, index) => compact({
54
53
  sha: commit.sha,
55
54
  subject: commit.subject.slice(0, SNAPSHOT_MAX_SUBJECT_LENGTH),
56
- authored_at: commit.authoredAt,
57
55
  files: files[index]
58
56
  }))
59
57
  });
@@ -84,15 +82,20 @@ function branchFiles(commits) {
84
82
  continue;
85
83
  files -= 1;
86
84
  bytes -= size;
87
- kept.push(file);
85
+ kept.push({ path: file.path });
88
86
  }
89
87
  // Empty only when git listed nothing: a commit whose every file was withheld
90
88
  // or capped did change something, and an empty list would say it had not.
91
89
  return kept.length > 0 || commit.files?.length === 0 ? kept : undefined;
92
90
  });
93
91
  }
94
- /** Whether a path may be named at all: not over-long, no control characters, not a credential file. */
95
- function sendable(filePath) {
92
+ /**
93
+ * Whether a path may be named at all: not over-long, no control characters, not a credential file.
94
+ *
95
+ * @param filePath - Repository-relative path.
96
+ * @returns True when the path may be sent.
97
+ */
98
+ export function sendable(filePath) {
96
99
  return filePath.length <= SNAPSHOT_MAX_PATH_LENGTH && !SNAPSHOT_RE_CONTROL_CHARACTER.test(filePath) && !RE_SECRET_FILE.test(path.posix.basename(filePath));
97
100
  }
98
101
  /**