@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
@@ -0,0 +1,26 @@
1
+ import type { AgentWatchEvent } from './events.types.js';
2
+ /** Where a replay stands: counting, sending, waiting for the machine or the backend, or over. */
3
+ export type ReplayProgressState = 'scanning' | 'running' | 'paused' | 'done' | 'stopped';
4
+ /**
5
+ * How far one replay of a developer's earlier sessions has got (contract:
6
+ * core `replayProgressSchema`).
7
+ *
8
+ * Counts and the window only: no path, no text, no session content. One run
9
+ * has one `replay_id`, so a second replay replaces the first one's numbers.
10
+ * `turns_total` is 0 while `scanning`; `turns_sent` is what the edge handed
11
+ * the backend, not what the backend has grouped.
12
+ */
13
+ export interface ReplayProgressEvent extends AgentWatchEvent<'replay.progress'> {
14
+ readonly provider: string;
15
+ readonly surface: string;
16
+ readonly developer_id: string;
17
+ readonly replay_id: string;
18
+ readonly state: ReplayProgressState;
19
+ readonly window_start: string;
20
+ readonly window_end: string;
21
+ readonly turns_total: number;
22
+ readonly turns_sent: number;
23
+ readonly sessions_total: number;
24
+ readonly sessions_sent: number;
25
+ readonly started_at: string;
26
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -9,7 +9,8 @@ export interface RepoTreeFile {
9
9
  *
10
10
  * What a tenant with no GitHub App gets its code feature catalog named from:
11
11
  * paths and declaration names stand in for the source nothing may clone. Sent
12
- * once per repository per install identity; later turns cost one state read.
12
+ * per repository and install identity, and again when the trunk's tree changes
13
+ * (checked hourly); other turns cost one state read.
13
14
  */
14
15
  export interface RepoTreeEvent extends AgentWatchEvent<'repo.tree'> {
15
16
  readonly provider: string;
@@ -1,4 +1,4 @@
1
- import type { FeatureCandidate } from '../events/canonical-event.js';
1
+ import type { FeatureCandidate } from '../events/types/events.types.js';
2
2
  /**
3
3
  * Extract feature-correlation *evidence* (Jira/Linear ticket keys) from a
4
4
  * branch name.
@@ -25,3 +25,18 @@ export declare function checkoutOf(target: string): Promise<{
25
25
  root: string;
26
26
  relative: string;
27
27
  } | undefined>;
28
+ /**
29
+ * Whether a path is a directory or lies inside it.
30
+ *
31
+ * The two answers that disqualify it are a relative path that climbs out and
32
+ * one that stays absolute (a different drive or root). A sibling named
33
+ * `..foo` climbs nowhere, which is why the separator is part of the test.
34
+ *
35
+ * Asked of a repository path read back out of local turn state, which must not
36
+ * be trusted to stay inside the folder the session started in.
37
+ *
38
+ * @param boundary - Folder that bounds the target.
39
+ * @param target - Path to test against it.
40
+ * @returns True when the target is the boundary or beneath it.
41
+ */
42
+ export declare function isBeneath(boundary: string, target: string): boolean;
@@ -73,3 +73,21 @@ async function existingDirectory(target) {
73
73
  }
74
74
  return undefined;
75
75
  }
76
+ /**
77
+ * Whether a path is a directory or lies inside it.
78
+ *
79
+ * The two answers that disqualify it are a relative path that climbs out and
80
+ * one that stays absolute (a different drive or root). A sibling named
81
+ * `..foo` climbs nowhere, which is why the separator is part of the test.
82
+ *
83
+ * Asked of a repository path read back out of local turn state, which must not
84
+ * be trusted to stay inside the folder the session started in.
85
+ *
86
+ * @param boundary - Folder that bounds the target.
87
+ * @param target - Path to test against it.
88
+ * @returns True when the target is the boundary or beneath it.
89
+ */
90
+ export function isBeneath(boundary, target) {
91
+ const relative = path.relative(boundary, target);
92
+ return !path.isAbsolute(relative) && relative !== '..' && !relative.startsWith(`..${path.sep}`);
93
+ }
@@ -1,7 +1,5 @@
1
- import type { CodeState, GitRunner } from './types/git.types.js';
1
+ import type { CodeState } from './types/git.types.js';
2
2
  export type { CodeState } from './types/git.types.js';
3
- /** Hashes what one git command writes to stdout; undefined unless it exits 0. */
4
- export type GitDigester = (args: readonly string[], cwd: string, timeoutMs: number) => Promise<string | undefined>;
5
3
  /**
6
4
  * HEAD and a digest of the uncommitted diff, taken in the completion hook of
7
5
  * a check so a later run of it can be told to cover an earlier one only on
@@ -16,18 +14,6 @@ export type GitDigester = (args: readonly string[], cwd: string, timeoutMs: numb
16
14
  * checkout digests the empty diff. Untracked files are not covered.
17
15
  *
18
16
  * @param cwd - Where the call ran.
19
- * @param run - Git runner; injectable for tests.
20
- * @param digest - Streaming hasher; injectable for tests.
21
- * @param timeoutMs - Budget per git process.
22
17
  * @returns The state, or undefined outside a repository or before its first commit.
23
18
  */
24
- export declare function codeStateAt(cwd: string, run?: GitRunner, digest?: GitDigester, timeoutMs?: number): Promise<CodeState | undefined>;
25
- /**
26
- * sha256 of a git command's stdout, streamed: never buffered, never cut.
27
- *
28
- * @param args - Argument vector.
29
- * @param cwd - Working directory.
30
- * @param timeoutMs - Kill budget.
31
- * @returns The hex digest when git exits 0, else undefined. Never rejects.
32
- */
33
- export declare const digestGitOutput: GitDigester;
19
+ export declare function codeStateAt(cwd: string): Promise<CodeState | undefined>;
@@ -16,13 +16,10 @@ import { runGit } from './git-context.js';
16
16
  * checkout digests the empty diff. Untracked files are not covered.
17
17
  *
18
18
  * @param cwd - Where the call ran.
19
- * @param run - Git runner; injectable for tests.
20
- * @param digest - Streaming hasher; injectable for tests.
21
- * @param timeoutMs - Budget per git process.
22
19
  * @returns The state, or undefined outside a repository or before its first commit.
23
20
  */
24
- export async function codeStateAt(cwd, run = runGit, digest = digestGitOutput, timeoutMs = GIT_TIMEOUT_MS) {
25
- const [commit, diffFp] = await Promise.all([run(['rev-parse', 'HEAD'], cwd, timeoutMs), digest(UNCOMMITTED_DIFF_ARGS, cwd, timeoutMs)]);
21
+ export async function codeStateAt(cwd) {
22
+ const [commit, diffFp] = await Promise.all([runGit(['rev-parse', 'HEAD'], cwd, GIT_TIMEOUT_MS), digestGitOutput(UNCOMMITTED_DIFF_ARGS, cwd, GIT_TIMEOUT_MS)]);
26
23
  if (commit === undefined || !RE_OBJECT_ID.test(commit))
27
24
  return undefined;
28
25
  return { commit, diffFp };
@@ -35,10 +32,12 @@ export async function codeStateAt(cwd, run = runGit, digest = digestGitOutput, t
35
32
  * @param timeoutMs - Kill budget.
36
33
  * @returns The hex digest when git exits 0, else undefined. Never rejects.
37
34
  */
38
- export const digestGitOutput = (args, cwd, timeoutMs) => new Promise((resolve) => {
39
- const hash = crypto.createHash('sha256');
40
- const child = spawn('git', [GIT_NO_OPTIONAL_LOCKS, ...args], { cwd, timeout: timeoutMs, windowsHide: true, stdio: ['ignore', 'pipe', 'ignore'] });
41
- child.stdout.on('data', (chunk) => hash.update(chunk));
42
- child.on('error', () => resolve(undefined));
43
- child.on('close', (code) => resolve(code === 0 ? hash.digest('hex') : undefined));
44
- });
35
+ function digestGitOutput(args, cwd, timeoutMs) {
36
+ return new Promise((resolve) => {
37
+ const hash = crypto.createHash('sha256');
38
+ const child = spawn('git', [GIT_NO_OPTIONAL_LOCKS, ...args], { cwd, timeout: timeoutMs, windowsHide: true, stdio: ['ignore', 'pipe', 'ignore'] });
39
+ child.stdout.on('data', (chunk) => hash.update(chunk));
40
+ child.on('error', () => resolve(undefined));
41
+ child.on('close', (code) => resolve(code === 0 ? hash.digest('hex') : undefined));
42
+ });
43
+ }
@@ -47,7 +47,8 @@ export declare const GIT_FIELD_SEPARATOR = "\u001F";
47
47
  * compared against.
48
48
  *
49
49
  * One process for the whole listing, and it carries the heads — which is what
50
- * lets the cache diff run before any `git log`. On an ordinary closing turn,
50
+ * lets the cache diff run before any `git log` — and whether each upstream is
51
+ * gone, which costs nothing here and a process per branch anywhere else. On an ordinary closing turn,
51
52
  * where nothing moved, that is the difference between two git processes and
52
53
  * twelve.
53
54
  *
@@ -55,6 +56,14 @@ export declare const GIT_FIELD_SEPARATOR = "\u001F";
55
56
  * @returns The argument vector.
56
57
  */
57
58
  export declare function gitRecentBranchesArgs(count: number): readonly string[];
59
+ /** The same branch record as {@link gitRecentBranchesArgs}, restricted to named local branches. */
60
+ export declare function gitNamedBranchesArgs(branches: readonly string[]): readonly string[];
61
+ /**
62
+ * What `%(upstream:track)` prints for a branch whose upstream was deleted on
63
+ * the remote and pruned here: the usual end of a merged or closed pull request.
64
+ * Plumbing prints it untranslated (only `git branch -vv` localizes it).
65
+ */
66
+ export declare const GIT_UPSTREAM_GONE = "[gone]";
58
67
  /**
59
68
  * The commits on a branch that its default branch does not have.
60
69
  *
@@ -68,6 +77,29 @@ export declare function gitRecentBranchesArgs(count: number): readonly string[];
68
77
  * @returns The argument vector.
69
78
  */
70
79
  export declare function gitBranchDeltaArgs(defaultBranch: string, branch: string, count: number): readonly string[];
80
+ /**
81
+ * The tree a merge of `branch` into `base` would produce, without touching the
82
+ * checkout or the index (git >= 2.38; older gits reject the form and the caller
83
+ * reads that as "not merged").
84
+ *
85
+ * Equal to the base's own tree means the branch adds nothing the trunk lacks,
86
+ * however it got there: a squash or rebase merge leaves the branch's commits
87
+ * outside `base..branch` but its changes inside the trunk, and this sees the
88
+ * changes. It writes the merged objects to the object store, unreferenced, for
89
+ * `gc` to prune; it exits non-zero on a conflict.
90
+ *
91
+ * @param base - The trunk the delta was taken against.
92
+ * @param branch - The branch to test.
93
+ * @returns The argument vector.
94
+ */
95
+ export declare function gitMergeTreeArgs(base: string, branch: string): readonly string[];
96
+ /**
97
+ * The tree of a ref, to compare a {@link gitMergeTreeArgs} result against.
98
+ *
99
+ * @param ref - The ref.
100
+ * @returns The argument vector.
101
+ */
102
+ export declare function gitTreeArgs(ref: string): readonly string[];
71
103
  /** One name-status letter: added, copied, deleted, modified, renamed, type-changed, unmerged, unknown. */
72
104
  export declare const RE_NAME_STATUS: RegExp;
73
105
  /** The newline git puts between a commit's header and its first name-status entry. */
@@ -172,16 +204,6 @@ export declare const GATE_REMOTE_MEMO_TTL_MS = 3600000;
172
204
  * remoteless checkout pays one subprocess a minute rather than one per prompt.
173
205
  */
174
206
  export declare const GATE_REMOTE_ABSENT_TTL_MS = 60000;
175
- /**
176
- * The entry that marks a repository root. A *file* of that name counts too:
177
- * that is what a linked worktree and a submodule check out as.
178
- */
179
- export declare const GIT_ENTRY_NAME = ".git";
180
- /**
181
- * The errors that mean "no `.git` here". Anything else — a permission or I/O
182
- * error — means the answer is unknown, not no.
183
- */
184
- export declare const GIT_ENTRY_ABSENT_CODES: ReadonlySet<string>;
185
207
  /**
186
208
  * One fingerprint of a checkout: HEAD, branch and every dirty entry in one
187
209
  * process. NUL-separated so a path is never quoted, split or trimmed; every
@@ -47,7 +47,8 @@ export const GIT_FIELD_SEPARATOR = '';
47
47
  * compared against.
48
48
  *
49
49
  * One process for the whole listing, and it carries the heads — which is what
50
- * lets the cache diff run before any `git log`. On an ordinary closing turn,
50
+ * lets the cache diff run before any `git log` — and whether each upstream is
51
+ * gone, which costs nothing here and a process per branch anywhere else. On an ordinary closing turn,
51
52
  * where nothing moved, that is the difference between two git processes and
52
53
  * twelve.
53
54
  *
@@ -60,9 +61,24 @@ export function gitRecentBranchesArgs(count) {
60
61
  'refs/heads',
61
62
  '--sort=-committerdate',
62
63
  `--count=${String(count)}`,
63
- `--format=%(refname:short)${GIT_FIELD_SEPARATOR}%(objectname)${GIT_FIELD_SEPARATOR}%(committerdate:iso-strict)`
64
+ `--format=%(refname:short)${GIT_FIELD_SEPARATOR}%(objectname)${GIT_FIELD_SEPARATOR}%(committerdate:iso-strict)${GIT_FIELD_SEPARATOR}%(upstream:track)`
64
65
  ];
65
66
  }
67
+ /** The same branch record as {@link gitRecentBranchesArgs}, restricted to named local branches. */
68
+ export function gitNamedBranchesArgs(branches) {
69
+ return [
70
+ 'for-each-ref',
71
+ '--sort=-committerdate',
72
+ `--format=%(refname:short)${GIT_FIELD_SEPARATOR}%(objectname)${GIT_FIELD_SEPARATOR}%(committerdate:iso-strict)${GIT_FIELD_SEPARATOR}%(upstream:track)`,
73
+ ...branches.map((branch) => `refs/heads/${branch}`)
74
+ ];
75
+ }
76
+ /**
77
+ * What `%(upstream:track)` prints for a branch whose upstream was deleted on
78
+ * the remote and pruned here: the usual end of a merged or closed pull request.
79
+ * Plumbing prints it untranslated (only `git branch -vv` localizes it).
80
+ */
81
+ export const GIT_UPSTREAM_GONE = '[gone]';
66
82
  /**
67
83
  * The commits on a branch that its default branch does not have.
68
84
  *
@@ -85,6 +101,33 @@ export function gitBranchDeltaArgs(defaultBranch, branch, count) {
85
101
  '--'
86
102
  ];
87
103
  }
104
+ /**
105
+ * The tree a merge of `branch` into `base` would produce, without touching the
106
+ * checkout or the index (git >= 2.38; older gits reject the form and the caller
107
+ * reads that as "not merged").
108
+ *
109
+ * Equal to the base's own tree means the branch adds nothing the trunk lacks,
110
+ * however it got there: a squash or rebase merge leaves the branch's commits
111
+ * outside `base..branch` but its changes inside the trunk, and this sees the
112
+ * changes. It writes the merged objects to the object store, unreferenced, for
113
+ * `gc` to prune; it exits non-zero on a conflict.
114
+ *
115
+ * @param base - The trunk the delta was taken against.
116
+ * @param branch - The branch to test.
117
+ * @returns The argument vector.
118
+ */
119
+ export function gitMergeTreeArgs(base, branch) {
120
+ return ['merge-tree', '--write-tree', base, branch];
121
+ }
122
+ /**
123
+ * The tree of a ref, to compare a {@link gitMergeTreeArgs} result against.
124
+ *
125
+ * @param ref - The ref.
126
+ * @returns The argument vector.
127
+ */
128
+ export function gitTreeArgs(ref) {
129
+ return ['rev-parse', '--verify', '-q', `${ref}^{tree}`];
130
+ }
88
131
  /** One name-status letter: added, copied, deleted, modified, renamed, type-changed, unmerged, unknown. */
89
132
  export const RE_NAME_STATUS = /^[ACDMRTUX]$/;
90
133
  /** The newline git puts between a commit's header and its first name-status entry. */
@@ -218,16 +261,6 @@ export const GATE_REMOTE_MEMO_TTL_MS = 3_600_000;
218
261
  * remoteless checkout pays one subprocess a minute rather than one per prompt.
219
262
  */
220
263
  export const GATE_REMOTE_ABSENT_TTL_MS = 60_000;
221
- /**
222
- * The entry that marks a repository root. A *file* of that name counts too:
223
- * that is what a linked worktree and a submodule check out as.
224
- */
225
- export const GIT_ENTRY_NAME = '.git';
226
- /**
227
- * The errors that mean "no `.git` here". Anything else — a permission or I/O
228
- * error — means the answer is unknown, not no.
229
- */
230
- export const GIT_ENTRY_ABSENT_CODES = new Set(['ENOENT', 'ENOTDIR']);
231
264
  /**
232
265
  * One fingerprint of a checkout: HEAD, branch and every dirty entry in one
233
266
  * process. NUL-separated so a path is never quoted, split or trimmed; every
@@ -1,4 +1,4 @@
1
- import type { Fingerprint, GitRunner } from './types/git.types.js';
1
+ import type { Fingerprint } from './types/git.types.js';
2
2
  export type { DirtyEntry, Fingerprint } from './types/git.types.js';
3
3
  /**
4
4
  * What a checkout looks like right now: HEAD, branch, and every dirty entry
@@ -14,11 +14,9 @@ export type { DirtyEntry, Fingerprint } from './types/git.types.js';
14
14
  * else.
15
15
  *
16
16
  * @param root - Checkout root.
17
- * @param run - Git runner; injectable for tests.
18
- * @param timeoutMs - Kill budget for the git process.
19
17
  * @returns The fingerprint, or undefined when git could not give one.
20
18
  */
21
- export declare function fingerprint(root: string, run?: GitRunner, timeoutMs?: number): Promise<Fingerprint | undefined>;
19
+ export declare function fingerprint(root: string): Promise<Fingerprint | undefined>;
22
20
  /**
23
21
  * `git status --porcelain=v2 --branch -z`, read.
24
22
  *
@@ -58,10 +56,9 @@ export declare function dirtyDelta(baseline: Fingerprint, closing: Fingerprint):
58
56
  * @param from - Where the turn started; undefined when the branch was unborn.
59
57
  * @param to - Where it ended: an oid, or a branch ref.
60
58
  * @param gitDir - Ask this git dir rather than the one `cwd` would find.
61
- * @param run - Git runner; injectable for tests.
62
59
  * @returns Repository-relative paths; empty when git could not say.
63
60
  */
64
- export declare function commitFiles(cwd: string, from: string | undefined, to: string, gitDir?: string, run?: GitRunner): Promise<string[]>;
61
+ export declare function commitFiles(cwd: string, from: string | undefined, to: string, gitDir?: string): Promise<string[]>;
65
62
  /**
66
63
  * A fingerprint out of turn state, type-checked field by field.
67
64
  *
@@ -18,12 +18,10 @@ import { runGit } from './git-context.js';
18
18
  * else.
19
19
  *
20
20
  * @param root - Checkout root.
21
- * @param run - Git runner; injectable for tests.
22
- * @param timeoutMs - Kill budget for the git process.
23
21
  * @returns The fingerprint, or undefined when git could not give one.
24
22
  */
25
- export async function fingerprint(root, run = runGit, timeoutMs = GIT_TIMEOUT_MS) {
26
- const [status, commonDir] = await Promise.all([run(GIT_FINGERPRINT_ARGS, root, timeoutMs), readCommonDir(root)]);
23
+ export async function fingerprint(root) {
24
+ const [status, commonDir] = await Promise.all([runGit(GIT_FINGERPRINT_ARGS, root, GIT_TIMEOUT_MS), readCommonDir(root)]);
27
25
  if (status === undefined)
28
26
  return undefined;
29
27
  const parsed = parsePorcelainV2(status);
@@ -105,14 +103,13 @@ export function dirtyDelta(baseline, closing) {
105
103
  * @param from - Where the turn started; undefined when the branch was unborn.
106
104
  * @param to - Where it ended: an oid, or a branch ref.
107
105
  * @param gitDir - Ask this git dir rather than the one `cwd` would find.
108
- * @param run - Git runner; injectable for tests.
109
106
  * @returns Repository-relative paths; empty when git could not say.
110
107
  */
111
- export async function commitFiles(cwd, from, to, gitDir, run = runGit) {
108
+ export async function commitFiles(cwd, from, to, gitDir) {
112
109
  const asked = (args) => (gitDir ? ['--git-dir', gitDir, ...args] : args);
113
110
  const [diverged, output] = await Promise.all([
114
- from === undefined ? '' : run(asked(gitNotAncestorArgs(from, to)), cwd, GIT_TIMEOUT_MS),
115
- run(asked(gitOwnCommitFilesArgs(from, to)), cwd, GIT_TIMEOUT_MS)
111
+ from === undefined ? '' : runGit(asked(gitNotAncestorArgs(from, to)), cwd, GIT_TIMEOUT_MS),
112
+ runGit(asked(gitOwnCommitFilesArgs(from, to)), cwd, GIT_TIMEOUT_MS)
116
113
  ]);
117
114
  // `diverged` is undefined when git failed, which is no proof either way.
118
115
  return diverged === '' && output ? [...new Set(output.split('\0').filter(Boolean))] : [];
@@ -251,7 +251,11 @@ function readOctalEscape(inner, start) {
251
251
  * @returns Trailing-trimmed stdout, or undefined.
252
252
  */
253
253
  export const runGit = (args, cwd, timeoutMs, home, maxBufferBytes = GIT_MAX_BUFFER_BYTES) => new Promise((resolve) => {
254
- const env = home ? { ...process.env, HOME: home, XDG_CONFIG_HOME: path.join(home, '.config') } : undefined;
254
+ // `GIT_NO_LAZY_FETCH`: in a partial clone a missing blob would otherwise be
255
+ // fetched from the remote inside the hook (merge-tree reads blobs). Git
256
+ // before 2.44 ignores it, and a call that needed the blob fails as any
257
+ // other git failure does.
258
+ const env = { ...process.env, GIT_NO_LAZY_FETCH: '1', ...(home ? { HOME: home, XDG_CONFIG_HOME: path.join(home, '.config') } : {}) };
255
259
  // `--no-optional-locks`, on every call the edge makes: a hook must never
256
260
  // take `index.lock` from under the agent's own `git commit` in that checkout.
257
261
  execFile('git', [GIT_NO_OPTIONAL_LOCKS, ...args], { cwd, timeout: timeoutMs, maxBuffer: maxBufferBytes, windowsHide: true, env }, (error, stdout) => {
@@ -4,9 +4,8 @@
4
4
  */
5
5
  export type { CodeState, GitContext, GitContextOptions, GitRunner, GitUserEmailOptions, RemoteParts } from './types/git.types.js';
6
6
  export type { BranchCommit, BranchRef, CommitFile, SnapshotBranch } from './types/snapshot.types.js';
7
- export type { RepositoryRootFinder } from './types/repository-root.types.js';
8
7
  export { codeStateAt } from './code-state.js';
9
8
  export { collectGitContext, developerIdentity, gitUserEmail, runGit } from './git-context.js';
10
9
  export { collectBranchCommits, collectBranchRefs, parseCommitFiles, resolveDefaultBranch } from './repo-snapshot.js';
11
10
  export { normalizeRemote, remoteHash, stripRemoteCredentials } from './remote-sanitize.js';
12
- export { isBeneath, repositoryRootFinder } from './repository-root.js';
11
+ export { isBeneath } from './checkout-root.js';
package/dist/git/index.js CHANGED
@@ -2,4 +2,4 @@ export { codeStateAt } from './code-state.js';
2
2
  export { collectGitContext, developerIdentity, gitUserEmail, runGit } from './git-context.js';
3
3
  export { collectBranchCommits, collectBranchRefs, parseCommitFiles, resolveDefaultBranch } from './repo-snapshot.js';
4
4
  export { normalizeRemote, remoteHash, stripRemoteCredentials } from './remote-sanitize.js';
5
- export { isBeneath, repositoryRootFinder } from './repository-root.js';
5
+ export { isBeneath } from './checkout-root.js';
@@ -37,14 +37,23 @@ export declare function resolveDefaultBranch(cwd: string, run: GitRunner): Promi
37
37
  * and taken together that would cost the branch the subjects of every commit
38
38
  * older than it. Apart, the worst a huge commit does is lose some paths.
39
39
  *
40
+ * A branch whose work is already on the trunk is undefined, not empty: one
41
+ * with no delta at all (merged, or created and never committed on), and one
42
+ * whose delta merges into the trunk without changing it (squash- or
43
+ * rebase-merged, where the trunk holds the changes under other shas). Named
44
+ * alone, either becomes a feature for work that is finished. A just-created
45
+ * branch that is checked out still reaches the platform, through the turn that
46
+ * names it (core AWT-419).
47
+ *
40
48
  * @param branch - Branch to describe.
41
49
  * @param options - Where to look, the base branch and the commit cap.
42
50
  * @param run - Git runner.
43
- * @returns The delta commits, newest first. Empty when there is no base to
44
- * subtract, which is the honest answer: the alternative is reporting the
45
- * trunk's commits as this branch's work.
51
+ * @returns The delta commits, newest first, or undefined when the branch's
52
+ * work is already on the trunk. Empty when there is no base to subtract or
53
+ * git failed, which is the honest answer: the alternative is reporting the
54
+ * trunk's commits as this branch's work, and "unknown" is not "merged".
46
55
  */
47
- export declare function collectBranchCommits(branch: string, options: CollectCommitsOptions, run: GitRunner): Promise<BranchCommit[]>;
56
+ export declare function collectBranchCommits(branch: string, options: CollectCommitsOptions, run: GitRunner): Promise<BranchCommit[] | undefined>;
48
57
  /**
49
58
  * The files of each commit in one `log -z --name-status --format=%H` listing.
50
59
  *
@@ -1,4 +1,4 @@
1
- import { ASSUMED_DEFAULT_BRANCHES, GIT_FIELD_SEPARATOR, GIT_ORIGIN_HEAD_ARGS, GIT_TIMEOUT_MS, RE_LEADING_NEWLINE, RE_NAME_STATUS, RE_OBJECT_ID, gitBranchDeltaArgs, gitBranchFilesArgs, gitRecentBranchesArgs, gitVerifyRefArgs } from './constants/git.constants.js';
1
+ import { ASSUMED_DEFAULT_BRANCHES, GIT_FIELD_SEPARATOR, GIT_ORIGIN_HEAD_ARGS, GIT_TIMEOUT_MS, GIT_UPSTREAM_GONE, RE_LEADING_NEWLINE, RE_NAME_STATUS, RE_OBJECT_ID, gitBranchDeltaArgs, gitBranchFilesArgs, gitMergeTreeArgs, gitNamedBranchesArgs, gitRecentBranchesArgs, gitTreeArgs, gitVerifyRefArgs } from './constants/git.constants.js';
2
2
  /** `origin/HEAD` is reported as `origin/main`; the branch is what comes after. */
3
3
  const REMOTE_PREFIX = 'origin/';
4
4
  /**
@@ -16,6 +16,12 @@ export async function collectBranchRefs(options, run) {
16
16
  const output = await run(gitRecentBranchesArgs(options.branchCount), options.cwd, GIT_TIMEOUT_MS);
17
17
  if (!output)
18
18
  return [];
19
+ const recent = parseBranchRefs(output);
20
+ const missing = (options.requiredBranches ?? []).filter((name) => !recent.some((ref) => ref.name === name));
21
+ const required = missing.length === 0 ? [] : parseBranchRefs((await run(gitNamedBranchesArgs(missing), options.cwd, GIT_TIMEOUT_MS)) ?? '');
22
+ return [...required, ...recent];
23
+ }
24
+ function parseBranchRefs(output) {
19
25
  return output
20
26
  .split('\n')
21
27
  .map((line) => parseBranchRef(line))
@@ -54,22 +60,37 @@ export async function resolveDefaultBranch(cwd, run) {
54
60
  * and taken together that would cost the branch the subjects of every commit
55
61
  * older than it. Apart, the worst a huge commit does is lose some paths.
56
62
  *
63
+ * A branch whose work is already on the trunk is undefined, not empty: one
64
+ * with no delta at all (merged, or created and never committed on), and one
65
+ * whose delta merges into the trunk without changing it (squash- or
66
+ * rebase-merged, where the trunk holds the changes under other shas). Named
67
+ * alone, either becomes a feature for work that is finished. A just-created
68
+ * branch that is checked out still reaches the platform, through the turn that
69
+ * names it (core AWT-419).
70
+ *
57
71
  * @param branch - Branch to describe.
58
72
  * @param options - Where to look, the base branch and the commit cap.
59
73
  * @param run - Git runner.
60
- * @returns The delta commits, newest first. Empty when there is no base to
61
- * subtract, which is the honest answer: the alternative is reporting the
62
- * trunk's commits as this branch's work.
74
+ * @returns The delta commits, newest first, or undefined when the branch's
75
+ * work is already on the trunk. Empty when there is no base to subtract or
76
+ * git failed, which is the honest answer: the alternative is reporting the
77
+ * trunk's commits as this branch's work, and "unknown" is not "merged".
63
78
  */
64
79
  export async function collectBranchCommits(branch, options, run) {
65
80
  const delta = await branchDelta(branch, options, run);
66
- if (!delta?.output)
81
+ if (!delta)
67
82
  return [];
83
+ if (delta.output === '')
84
+ return undefined;
68
85
  const commits = delta.output
69
86
  .split('\n')
70
87
  .map((line) => parseCommit(line))
71
88
  .filter((commit) => commit !== undefined);
72
- if (commits.length === 0 || options.withFiles === false)
89
+ if (commits.length === 0)
90
+ return commits;
91
+ if (!options.includeMerged && (await alreadyOnTrunk(delta.base, branch, options.cwd, run)))
92
+ return undefined;
93
+ if (options.withFiles === false)
73
94
  return commits;
74
95
  const listing = await run(gitBranchFilesArgs(delta.base, branch, options.commitCount), options.cwd, GIT_TIMEOUT_MS);
75
96
  // A listing that failed or ran out of budget leaves every commit without
@@ -82,6 +103,29 @@ export async function collectBranchCommits(branch, options, run) {
82
103
  return changed ? { ...commit, files: changed } : commit;
83
104
  });
84
105
  }
106
+ /**
107
+ * Whether merging the branch into its base would leave the base unchanged.
108
+ *
109
+ * Two processes, on branches that have a delta only. Any failure is "no": an
110
+ * old git, a conflict (a squash the trunk has since edited on top of) or a
111
+ * spent budget keeps the branch, which is what every edge before this did.
112
+ *
113
+ * ponytail: the base tree is read once per branch; one read per snapshot would
114
+ * save ~5 ms a branch but needs the delta's base carried out of branchDelta.
115
+ *
116
+ * @param base - The ref the delta was taken against.
117
+ * @param branch - Branch to test.
118
+ * @param cwd - Repository directory.
119
+ * @param run - Git runner.
120
+ * @returns True only when git said so.
121
+ */
122
+ async function alreadyOnTrunk(base, branch, cwd, run) {
123
+ const merged = await run(gitMergeTreeArgs(base, branch), cwd, GIT_TIMEOUT_MS);
124
+ if (!merged)
125
+ return false;
126
+ const tree = await run(gitTreeArgs(base), cwd, GIT_TIMEOUT_MS);
127
+ return tree !== undefined && merged.split('\n', 1)[0] === tree;
128
+ }
85
129
  /**
86
130
  * The delta's log output and the base it was taken against.
87
131
  *
@@ -171,14 +215,14 @@ export function parseCommitFiles(output) {
171
215
  /**
172
216
  * One `for-each-ref` record.
173
217
  *
174
- * @param line - `name<sep>sha<sep>date`.
218
+ * @param line - `name<sep>sha<sep>date<sep>track`.
175
219
  * @returns The branch, or undefined for a line missing a name or a head.
176
220
  */
177
221
  function parseBranchRef(line) {
178
- const [name, headSha, lastCommitAt] = line.split(GIT_FIELD_SEPARATOR);
222
+ const [name, headSha, lastCommitAt, track] = line.split(GIT_FIELD_SEPARATOR);
179
223
  if (!name || !headSha)
180
224
  return undefined;
181
- return { name, headSha, lastCommitAt: lastCommitAt || undefined };
225
+ return { name, headSha, lastCommitAt: lastCommitAt || undefined, ...(track === GIT_UPSTREAM_GONE ? { upstreamGone: true } : {}) };
182
226
  }
183
227
  /**
184
228
  * One `log` record.
@@ -3,6 +3,8 @@ export interface BranchRef {
3
3
  readonly name: string;
4
4
  readonly headSha: string;
5
5
  readonly lastCommitAt?: string;
6
+ /** Its upstream was deleted on the remote and pruned here; absent when it has none or it exists. */
7
+ readonly upstreamGone?: boolean;
6
8
  }
7
9
  /** One file a commit changed: git's name-status letter and the repository-relative path. */
8
10
  export interface CommitFile {
@@ -24,6 +26,8 @@ export interface SnapshotBranch extends BranchRef {
24
26
  export interface CollectRefsOptions {
25
27
  readonly cwd: string;
26
28
  readonly branchCount: number;
29
+ /** Branches that must be returned even when they are older than the recent window. */
30
+ readonly requiredBranches?: readonly string[];
27
31
  }
28
32
  export interface CollectCommitsOptions {
29
33
  readonly cwd: string;
@@ -31,6 +35,8 @@ export interface CollectCommitsOptions {
31
35
  readonly withFiles?: boolean;
32
36
  readonly defaultBranch?: string;
33
37
  readonly commitCount: number;
38
+ /** Historical replay evidence stays useful after a squash/rebase puts the same tree on trunk. */
39
+ readonly includeMerged?: boolean;
34
40
  }
35
41
  /** One source file of a default-branch tree: its path and its top-level declaration names. */
36
42
  export interface TreeFile {
@@ -1,5 +1,6 @@
1
1
  import type { CanonicalEventType } from '../../events/types/events.types.js';
2
2
  /** Stage names, used in the flow definition and in its debug trace. */
3
+ export declare const STAGE_IGNORED_ROOT = "ignored-root";
3
4
  export declare const STAGE_RESOLVE_CONTEXT = "resolve-context";
4
5
  export declare const STAGE_PARSE_EVENTS = "parse-events";
5
6
  export declare const STAGE_AWAIT_SIGN_IN = "await-sign-in";
@@ -8,6 +9,7 @@ export declare const MAX_WORKSPACE_ROOTS = 4;
8
9
  export declare const STAGE_NOMINATE = "nominate";
9
10
  export declare const STAGE_UNTRACED = "untraced";
10
11
  export declare const STAGE_UPDATE = "update";
12
+ export declare const STAGE_REPLAY_RESUME = "replay-resume";
11
13
  /** SessionStart sources that are not a developer starting work: no update notice on them. */
12
14
  export declare const QUIET_SESSION_SOURCES: ReadonlySet<string>;
13
15
  export declare const STAGE_ENFORCE = "enforce";
@@ -17,6 +19,7 @@ export declare const STAGE_DELIVER = "deliver";
17
19
  export declare const STAGE_REWRITE_BEARERS = "rewrite-bearers";
18
20
  export declare const STAGE_SNAPSHOT = "repo-snapshot";
19
21
  /** Reasons a stage ends the flow early. */
22
+ export declare const STOP_IGNORED_ROOT = "working directory is in ignoredRoots: nothing is captured, sent or queued";
20
23
  export declare const STOP_NO_EVENTS = "provider produced no canonical events";
21
24
  export declare const STOP_DRY_RUN = "dry run: nothing delivered";
22
25
  export declare const STOP_NO_SNAPSHOT = "no closed turn, or git capture is off";
@@ -1,4 +1,5 @@
1
1
  /** Stage names, used in the flow definition and in its debug trace. */
2
+ export const STAGE_IGNORED_ROOT = 'ignored-root';
2
3
  export const STAGE_RESOLVE_CONTEXT = 'resolve-context';
3
4
  export const STAGE_PARSE_EVENTS = 'parse-events';
4
5
  export const STAGE_AWAIT_SIGN_IN = 'await-sign-in';
@@ -7,6 +8,7 @@ export const MAX_WORKSPACE_ROOTS = 4;
7
8
  export const STAGE_NOMINATE = 'nominate';
8
9
  export const STAGE_UNTRACED = 'untraced';
9
10
  export const STAGE_UPDATE = 'update';
11
+ export const STAGE_REPLAY_RESUME = 'replay-resume';
10
12
  /** SessionStart sources that are not a developer starting work: no update notice on them. */
11
13
  export const QUIET_SESSION_SOURCES = new Set(['clear', 'compact']);
12
14
  export const STAGE_ENFORCE = 'enforce';
@@ -16,6 +18,7 @@ export const STAGE_DELIVER = 'deliver';
16
18
  export const STAGE_REWRITE_BEARERS = 'rewrite-bearers';
17
19
  export const STAGE_SNAPSHOT = 'repo-snapshot';
18
20
  /** Reasons a stage ends the flow early. */
21
+ export const STOP_IGNORED_ROOT = 'working directory is in ignoredRoots: nothing is captured, sent or queued';
19
22
  export const STOP_NO_EVENTS = 'provider produced no canonical events';
20
23
  export const STOP_DRY_RUN = 'dry run: nothing delivered';
21
24
  export const STOP_NO_SNAPSHOT = 'no closed turn, or git capture is off';