@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,131 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
- import { GIT_ENTRY_ABSENT_CODES, GIT_ENTRY_NAME } from './constants/git.constants.js';
4
- /**
5
- * A finder for the repository each file belongs to, when the session's own
6
- * folder is not one.
7
- *
8
- * Bounded by `boundary` — the folder the session started in — for two reasons:
9
- * a repository outside it is another project's, possibly another tenant's, and
10
- * a bounded walk is a handful of `stat` calls rather than an unbounded climb to
11
- * the filesystem root.
12
- *
13
- * ponytail: presence of a `.git` entry is the whole test, and the answer is the
14
- * *nearest* ancestor that has one — so a file inside a submodule or a vendored
15
- * checkout belongs to that inner repository, which is also what git itself
16
- * would answer from that directory. It does not understand `GIT_DIR`, a bare
17
- * repository, or a `.git` file pointing outside the tree. The upgrade path is
18
- * `git rev-parse --show-toplevel` behind this same cache — deliberately not the
19
- * implementation: a subprocess per tool call would sit on the coding agent's
20
- * critical path.
21
- *
22
- * @param boundary - Folder the walk stops at, inclusive.
23
- * @returns A finder whose answers are memoized per directory.
24
- */
25
- export function repositoryRootFinder(boundary) {
26
- // Directory → its repository root, or undefined for "none, and asked".
27
- // One turn touches the same handful of directories over and over.
28
- const cache = new Map();
29
- return { find: (filePath) => rootFor(path.dirname(filePath), boundary, cache) };
30
- }
31
- /**
32
- * The repository root at or above one directory, memoizing every level.
33
- *
34
- * @param dir - Directory to resolve.
35
- * @param boundary - Folder the walk stops at, inclusive.
36
- * @param cache - Directory answers resolved so far.
37
- * @returns The root, or undefined when there is none inside the boundary.
38
- */
39
- async function rootFor(dir, boundary, cache) {
40
- if (cache.has(dir))
41
- return cache.get(dir);
42
- // A file outside the start folder contributes no repository at all: its
43
- // repository is not the session's business and could be another tenant's.
44
- if (!isBeneath(boundary, dir))
45
- return undefined;
46
- const root = await walkUp(dir, boundary, cache);
47
- cache.set(dir, root);
48
- return root;
49
- }
50
- /**
51
- * One rung of the walk: this directory, else its parent.
52
- *
53
- * @param dir - Directory to test.
54
- * @param boundary - Folder the walk stops at, inclusive.
55
- * @param cache - Directory answers resolved so far.
56
- * @returns The root, or undefined once the boundary is passed.
57
- */
58
- async function walkUp(dir, boundary, cache) {
59
- const entry = await gitEntry(dir);
60
- if (entry === 'present')
61
- return (await isReallyBeneath(boundary, dir)) ? dir : undefined;
62
- // A `.git` that could not be checked may well be there: climbing past it
63
- // would hand the file to an enclosing repository — the wrong branch, the
64
- // wrong config. No repository is the answer this walk gives when unsure.
65
- if (entry === 'unknown')
66
- return undefined;
67
- const parent = path.dirname(dir);
68
- // `dir === boundary` ends the walk; `parent === dir` is the filesystem root,
69
- // which only happens when the boundary is not an ancestor at all.
70
- if (dir === boundary || parent === dir)
71
- return undefined;
72
- return rootFor(parent, boundary, cache);
73
- }
74
- /**
75
- * `isBeneath`, asked of where the two really are.
76
- *
77
- * A symlink inside the start folder can point at a checkout anywhere on the
78
- * machine, and `.git` is found through it: lexically beneath, on disk another
79
- * project's. Asked only once a root is found, so the walk itself stays `stat`s.
80
- * A refused root ends the walk rather than climbing past it — the file belongs
81
- * to that repository, whoever's it is. A path that cannot be resolved — a link
82
- * removed or retargeted since the `.git` check — is refused too: its real
83
- * location was never proven to be inside.
84
- *
85
- * @param boundary - Folder that bounds the walk.
86
- * @param dir - Directory a `.git` entry was found in.
87
- * @returns True when the directory really lies within the boundary.
88
- */
89
- async function isReallyBeneath(boundary, dir) {
90
- try {
91
- const [realBoundary, realDir] = await Promise.all([fs.realpath(boundary), fs.realpath(dir)]);
92
- return isBeneath(realBoundary, realDir);
93
- }
94
- catch {
95
- return false;
96
- }
97
- }
98
- /**
99
- * Whether a `.git` entry sits directly in a directory.
100
- *
101
- * @param dir - Directory to test.
102
- * @returns `present`, `absent`, or `unknown` when the check itself failed.
103
- */
104
- async function gitEntry(dir) {
105
- try {
106
- await fs.access(path.join(dir, GIT_ENTRY_NAME));
107
- return 'present';
108
- }
109
- catch (error) {
110
- const code = error.code;
111
- return code !== undefined && GIT_ENTRY_ABSENT_CODES.has(code) ? 'absent' : 'unknown';
112
- }
113
- }
114
- /**
115
- * Whether a path is a directory or lies inside it.
116
- *
117
- * The two answers that disqualify it are a relative path that climbs out and
118
- * one that stays absolute (a different drive or root). A sibling named
119
- * `..foo` climbs nowhere, which is why the separator is part of the test.
120
- *
121
- * Exported because the same question is asked of a repository path read back
122
- * out of local turn state: one answer, not two that could disagree.
123
- *
124
- * @param boundary - Folder that bounds the walk.
125
- * @param target - Path to test against it.
126
- * @returns True when the target is the boundary or beneath it.
127
- */
128
- export function isBeneath(boundary, target) {
129
- const relative = path.relative(boundary, target);
130
- return !path.isAbsolute(relative) && relative !== '..' && !relative.startsWith(`..${path.sep}`);
131
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Finds the repository a file belongs to, bounded by one directory and
3
- * memoized for the life of the finder.
4
- */
5
- export interface RepositoryRootFinder {
6
- /**
7
- * The root of the repository containing `filePath`, or undefined when none
8
- * lies between the file and the boundary.
9
- */
10
- find(filePath: string): Promise<string | undefined>;
11
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * The contract between delivery and whatever actually moves bytes. Kept
3
- * separate from the HTTP implementation so the queue, the cooldown and the
4
- * whole test suite can substitute their own.
5
- */
6
- export type { DeliveryCounters, DeliveryResult, EventTransport, HttpTransportOptions } from './types/transport.types.js';
@@ -1,11 +0,0 @@
1
- /**
2
- * Whether a Codex transcript belongs to a headless `codex exec` run.
3
- *
4
- * The hook payload does not say how Codex was started; the transcript's first
5
- * line (`session_meta`) does. Any failure answers false, so an unreadable
6
- * transcript reports the default surface rather than failing the hook.
7
- *
8
- * @param transcriptPath - Path Codex reported in the hook payload.
9
- * @returns True only when the originator is `codex_exec`.
10
- */
11
- export declare function isCodexExecTranscript(transcriptPath: string): Promise<boolean>;
@@ -1,21 +0,0 @@
1
- import type { ReadTurnUsageRetry, TurnUsage } from './types/transcript.types.js';
2
- /**
3
- * Forward-compatible token usage from Cursor's transcript JSONL.
4
- *
5
- * Today (verified 2026-08) Cursor transcript rows carry only role/message with
6
- * tool_use blocks — no usage, no timestamps, no message ids — so this reader
7
- * returns undefined and Cursor turn summaries stay usage_status=pending. Cursor
8
- * has logged the enrichment request; the parser already accepts `usage` and
9
- * `message.usage` objects with Anthropic-style token fields, so tokens will
10
- * appear here without a code change once the format grows them.
11
- *
12
- * Rows have no timestamps, so unlike the Claude reader there is no time window:
13
- * a turn claims every not-yet-claimed usage row, and exactly-once attribution
14
- * rests entirely on the persisted message-id ledger.
15
- *
16
- * @param transcriptPath - Path Cursor reported in the hook payload.
17
- * @param retry - How long to wait for the transcript flush to settle.
18
- * @param excludeMessageIds - Rows another turn already claimed.
19
- * @returns The turn's usage, or undefined while the format carries none.
20
- */
21
- export declare function readCursorTurnUsage(transcriptPath: string, retry?: ReadTurnUsageRetry, excludeMessageIds?: ReadonlySet<string>): Promise<TurnUsage | undefined>;
@@ -1,66 +0,0 @@
1
- import { asRecord, firstStringOf } from '../core/object.js';
2
- import { accumulateUsage, messageIdFor, parseJsonLine, readTranscriptTail, readUntilSettled } from './transcript.js';
3
- /**
4
- * Forward-compatible token usage from Cursor's transcript JSONL.
5
- *
6
- * Today (verified 2026-08) Cursor transcript rows carry only role/message with
7
- * tool_use blocks — no usage, no timestamps, no message ids — so this reader
8
- * returns undefined and Cursor turn summaries stay usage_status=pending. Cursor
9
- * has logged the enrichment request; the parser already accepts `usage` and
10
- * `message.usage` objects with Anthropic-style token fields, so tokens will
11
- * appear here without a code change once the format grows them.
12
- *
13
- * Rows have no timestamps, so unlike the Claude reader there is no time window:
14
- * a turn claims every not-yet-claimed usage row, and exactly-once attribution
15
- * rests entirely on the persisted message-id ledger.
16
- *
17
- * @param transcriptPath - Path Cursor reported in the hook payload.
18
- * @param retry - How long to wait for the transcript flush to settle.
19
- * @param excludeMessageIds - Rows another turn already claimed.
20
- * @returns The turn's usage, or undefined while the format carries none.
21
- */
22
- export async function readCursorTurnUsage(transcriptPath, retry, excludeMessageIds) {
23
- return readUntilSettled(() => readOnce(transcriptPath, excludeMessageIds), retry, { bailOnFirstEmpty: true });
24
- }
25
- /**
26
- * One pass over the transcript tail.
27
- *
28
- * @param transcriptPath - Transcript file.
29
- * @param excludeMessageIds - Rows another turn already claimed.
30
- * @returns The usage found in this pass.
31
- */
32
- async function readOnce(transcriptPath, excludeMessageIds) {
33
- const raw = await readTranscriptTail(transcriptPath);
34
- if (raw === undefined)
35
- return undefined;
36
- const byMessageId = new Map();
37
- for (const line of raw.split('\n')) {
38
- if (!line.trim())
39
- continue;
40
- const entry = usageRow(line, excludeMessageIds);
41
- if (entry)
42
- byMessageId.set(entry.id, entry.value);
43
- }
44
- return accumulateUsage(byMessageId);
45
- }
46
- /**
47
- * The usage of one transcript row, when it reports any and no other turn has
48
- * claimed it.
49
- *
50
- * @param line - Verbatim JSONL line.
51
- * @param excludeMessageIds - Rows another turn already claimed.
52
- * @returns The entry, or undefined when the row carries no usage.
53
- */
54
- function usageRow(line, excludeMessageIds) {
55
- const entry = parseJsonLine(line);
56
- if (!entry)
57
- return undefined;
58
- const message = asRecord(entry['message']);
59
- const usage = asRecord(entry['usage']) ?? asRecord(message?.['usage']);
60
- if (!usage)
61
- return undefined;
62
- const id = messageIdFor(firstStringOf(message?.['id'], entry['id'], entry['message_id']), line);
63
- if (excludeMessageIds?.has(id))
64
- return undefined;
65
- return { id, value: { model: firstStringOf(message?.['model'], entry['model']), usage } };
66
- }
@@ -1,26 +0,0 @@
1
- import type { Env } from '../core/types/core.types.js';
2
- import type { SessionTitles } from './types/transcript.types.js';
3
- /**
4
- * Read the name and generated title Codex keeps for one thread.
5
- *
6
- * Codex does not put either value in its hook payload or rollout. Its own
7
- * read-model database is therefore the source, opened read-only and queried by
8
- * the hook's session id.
9
- *
10
- * @param env - Environment locating `$CODEX_HOME` or `~/.codex`.
11
- * @param sessionId - Codex thread id from the hook payload.
12
- * @returns Codex's latest name and generated title, or neither when unavailable.
13
- */
14
- export declare function readCodexSessionTitles(env: Env, sessionId: string): Promise<SessionTitles>;
15
- /**
16
- * Read Cursor's generated conversation title from its local search index.
17
- *
18
- * Cursor exposes no title in hooks or transcripts. The desktop app's search
19
- * index keys the same conversation id the hook sends; Cursor keeps custom and
20
- * generated titles in one display field, so it maps to `session_title`.
21
- *
22
- * @param env - Environment locating Cursor's platform data directory.
23
- * @param sessionId - Cursor conversation id from the hook payload.
24
- * @returns Cursor's display title, or neither when unavailable.
25
- */
26
- export declare function readCursorSessionTitles(env: Env, sessionId: string): Promise<SessionTitles>;
@@ -1,102 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import { createRequire } from 'node:module';
3
- import path from 'node:path';
4
- import { asRecord, compact } from '../core/object.js';
5
- import { codexHome } from '../providers/codex/codex.detect.js';
6
- const CODEX_STATE_DATABASE = /^state_(\d+)\.sqlite$/;
7
- const require = createRequire(import.meta.url);
8
- /**
9
- * Read the name and generated title Codex keeps for one thread.
10
- *
11
- * Codex does not put either value in its hook payload or rollout. Its own
12
- * read-model database is therefore the source, opened read-only and queried by
13
- * the hook's session id.
14
- *
15
- * @param env - Environment locating `$CODEX_HOME` or `~/.codex`.
16
- * @param sessionId - Codex thread id from the hook payload.
17
- * @returns Codex's latest name and generated title, or neither when unavailable.
18
- */
19
- export async function readCodexSessionTitles(env, sessionId) {
20
- const sqlite = sqliteModule();
21
- if (!sqlite)
22
- return {};
23
- const home = codexHome(env);
24
- const entries = await fs.readdir(home, { withFileTypes: true });
25
- const databases = entries
26
- .flatMap((entry) => {
27
- const match = entry.isFile() && CODEX_STATE_DATABASE.exec(entry.name);
28
- return match ? [{ path: path.join(home, entry.name), version: Number(match[1]) }] : [];
29
- })
30
- .sort((left, right) => right.version - left.version);
31
- for (const database of databases) {
32
- const titles = readTitles(sqlite, database.path, 'SELECT title, name FROM threads WHERE id = ?', sessionId);
33
- if (titles.custom || titles.generated)
34
- return titles;
35
- }
36
- return {};
37
- }
38
- /**
39
- * Read Cursor's generated conversation title from its local search index.
40
- *
41
- * Cursor exposes no title in hooks or transcripts. The desktop app's search
42
- * index keys the same conversation id the hook sends; Cursor keeps custom and
43
- * generated titles in one display field, so it maps to `session_title`.
44
- *
45
- * @param env - Environment locating Cursor's platform data directory.
46
- * @param sessionId - Cursor conversation id from the hook payload.
47
- * @returns Cursor's display title, or neither when unavailable.
48
- */
49
- export async function readCursorSessionTitles(env, sessionId) {
50
- const sqlite = sqliteModule();
51
- const database = cursorSearchDatabase(env);
52
- if (!sqlite || !database)
53
- return {};
54
- return readTitles(sqlite, database, "SELECT title FROM conversations WHERE source = 'local' AND scope = '' AND id = ?", sessionId);
55
- }
56
- /**
57
- * Open one provider-owned read model and return only its title fields.
58
- *
59
- * ponytail: the synchronous stdlib query can briefly block one Stop hook; it is
60
- * one indexed local lookup. Move it to a worker if measured hook latency makes
61
- * that visible.
62
- */
63
- function readTitles(sqlite, databasePath, query, sessionId) {
64
- let database;
65
- try {
66
- database = new sqlite.DatabaseSync(databasePath, { readOnly: true });
67
- const row = asRecord(database.prepare(query).get(sessionId));
68
- return compact({
69
- custom: typeof row?.['name'] === 'string' ? row['name'] : undefined,
70
- generated: typeof row?.['title'] === 'string' ? row['title'] : undefined
71
- });
72
- }
73
- catch {
74
- return {};
75
- }
76
- finally {
77
- database?.close();
78
- }
79
- }
80
- /** Node added enforced read-only SQLite opens in 22.12. */
81
- function sqliteModule() {
82
- const [major = 0, minor = 0] = process.versions.node.split('.').map(Number);
83
- if (major < 22 || (major === 22 && minor < 12))
84
- return undefined;
85
- try {
86
- return require('node:sqlite');
87
- }
88
- catch {
89
- return undefined;
90
- }
91
- }
92
- /** Cursor's search index path on each supported desktop platform. */
93
- function cursorSearchDatabase(env) {
94
- const suffix = ['Cursor', 'User', 'globalStorage', 'conversation-search.db'];
95
- if (env.platform === 'darwin')
96
- return path.join(env.home, 'Library', 'Application Support', ...suffix);
97
- if (env.platform === 'linux')
98
- return path.join(env.vars['XDG_CONFIG_HOME'] ?? path.join(env.home, '.config'), ...suffix);
99
- if (env.platform === 'win32' && env.vars['APPDATA'])
100
- return path.join(env.vars['APPDATA'], ...suffix);
101
- return undefined;
102
- }