@agent-watch-ai/edge 0.2.5

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 (364) hide show
  1. package/CHANGELOG.md +251 -0
  2. package/LICENSE +21 -0
  3. package/README.md +168 -0
  4. package/dist/billing/billing-mode.d.ts +16 -0
  5. package/dist/billing/billing-mode.js +139 -0
  6. package/dist/billing/constants/billing.constants.d.ts +37 -0
  7. package/dist/billing/constants/billing.constants.js +38 -0
  8. package/dist/billing/index.d.ts +6 -0
  9. package/dist/billing/index.js +6 -0
  10. package/dist/cli/args.d.ts +29 -0
  11. package/dist/cli/args.js +61 -0
  12. package/dist/cli/constants/cli.constants.d.ts +60 -0
  13. package/dist/cli/constants/cli.constants.js +60 -0
  14. package/dist/cli/context.d.ts +51 -0
  15. package/dist/cli/context.js +108 -0
  16. package/dist/cli/doctor.d.ts +15 -0
  17. package/dist/cli/doctor.js +416 -0
  18. package/dist/cli/hook.d.ts +20 -0
  19. package/dist/cli/hook.js +166 -0
  20. package/dist/cli/index.d.ts +13 -0
  21. package/dist/cli/index.js +8 -0
  22. package/dist/cli/misc.d.ts +31 -0
  23. package/dist/cli/misc.js +63 -0
  24. package/dist/cli/setup.d.ts +32 -0
  25. package/dist/cli/setup.js +298 -0
  26. package/dist/cli/status.d.ts +11 -0
  27. package/dist/cli/status.js +174 -0
  28. package/dist/cli/types/cli.types.d.ts +69 -0
  29. package/dist/cli/types/cli.types.js +1 -0
  30. package/dist/cli/ui.d.ts +41 -0
  31. package/dist/cli/ui.js +78 -0
  32. package/dist/cli/uninstall.d.ts +13 -0
  33. package/dist/cli/uninstall.js +83 -0
  34. package/dist/cli.d.ts +2 -0
  35. package/dist/cli.js +124 -0
  36. package/dist/config/config-store.d.ts +29 -0
  37. package/dist/config/config-store.js +75 -0
  38. package/dist/config/config.d.ts +73 -0
  39. package/dist/config/config.js +115 -0
  40. package/dist/config/constants/config.constants.d.ts +62 -0
  41. package/dist/config/constants/config.constants.js +70 -0
  42. package/dist/config/index.d.ts +10 -0
  43. package/dist/config/index.js +5 -0
  44. package/dist/config/repo-config.d.ts +37 -0
  45. package/dist/config/repo-config.js +178 -0
  46. package/dist/config/schemas/config.schema.d.ts +409 -0
  47. package/dist/config/schemas/config.schema.js +97 -0
  48. package/dist/config/types/config.types.d.ts +33 -0
  49. package/dist/config/types/config.types.js +1 -0
  50. package/dist/core/async.d.ts +20 -0
  51. package/dist/core/async.js +32 -0
  52. package/dist/core/constants/core.constants.d.ts +18 -0
  53. package/dist/core/constants/core.constants.js +18 -0
  54. package/dist/core/env.d.ts +12 -0
  55. package/dist/core/env.js +20 -0
  56. package/dist/core/index.d.ts +13 -0
  57. package/dist/core/index.js +8 -0
  58. package/dist/core/logger.d.ts +27 -0
  59. package/dist/core/logger.js +82 -0
  60. package/dist/core/number.d.ts +33 -0
  61. package/dist/core/number.js +47 -0
  62. package/dist/core/object.d.ts +78 -0
  63. package/dist/core/object.js +127 -0
  64. package/dist/core/pipe.d.ts +55 -0
  65. package/dist/core/pipe.js +81 -0
  66. package/dist/core/types/core.types.d.ts +54 -0
  67. package/dist/core/types/core.types.js +4 -0
  68. package/dist/core/version.d.ts +19 -0
  69. package/dist/core/version.js +35 -0
  70. package/dist/core/which.d.ts +13 -0
  71. package/dist/core/which.js +57 -0
  72. package/dist/enforcement/constants/enforcement.constants.d.ts +23 -0
  73. package/dist/enforcement/constants/enforcement.constants.js +22 -0
  74. package/dist/enforcement/decision-cache.d.ts +57 -0
  75. package/dist/enforcement/decision-cache.js +138 -0
  76. package/dist/enforcement/decision-client.d.ts +14 -0
  77. package/dist/enforcement/decision-client.js +84 -0
  78. package/dist/enforcement/enforcement.d.ts +17 -0
  79. package/dist/enforcement/enforcement.js +90 -0
  80. package/dist/enforcement/index.d.ts +11 -0
  81. package/dist/enforcement/index.js +10 -0
  82. package/dist/enforcement/schemas/enforcement.schema.d.ts +30 -0
  83. package/dist/enforcement/schemas/enforcement.schema.js +36 -0
  84. package/dist/enforcement/types/enforcement.types.d.ts +59 -0
  85. package/dist/enforcement/types/enforcement.types.js +1 -0
  86. package/dist/enrollment/constants/enrollment.constants.d.ts +6 -0
  87. package/dist/enrollment/constants/enrollment.constants.js +6 -0
  88. package/dist/enrollment/enrollment-provider.d.ts +5 -0
  89. package/dist/enrollment/enrollment-provider.js +1 -0
  90. package/dist/enrollment/index.d.ts +7 -0
  91. package/dist/enrollment/index.js +1 -0
  92. package/dist/enrollment/manual-enrollment.d.ts +32 -0
  93. package/dist/enrollment/manual-enrollment.js +72 -0
  94. package/dist/enrollment/types/enrollment.types.d.ts +25 -0
  95. package/dist/enrollment/types/enrollment.types.js +1 -0
  96. package/dist/events/canonical-event.d.ts +10 -0
  97. package/dist/events/canonical-event.js +9 -0
  98. package/dist/events/constants/enrich.constants.d.ts +14 -0
  99. package/dist/events/constants/enrich.constants.js +15 -0
  100. package/dist/events/constants/events.constants.d.ts +35 -0
  101. package/dist/events/constants/events.constants.js +57 -0
  102. package/dist/events/enrich.d.ts +16 -0
  103. package/dist/events/enrich.js +226 -0
  104. package/dist/events/event-id.d.ts +32 -0
  105. package/dist/events/event-id.js +49 -0
  106. package/dist/events/index.d.ts +14 -0
  107. package/dist/events/index.js +5 -0
  108. package/dist/events/llm-call.d.ts +14 -0
  109. package/dist/events/llm-call.js +84 -0
  110. package/dist/events/product-event.d.ts +39 -0
  111. package/dist/events/product-event.js +19 -0
  112. package/dist/events/types/enrich.types.d.ts +25 -0
  113. package/dist/events/types/enrich.types.js +1 -0
  114. package/dist/events/types/events.types.d.ts +112 -0
  115. package/dist/events/types/events.types.js +1 -0
  116. package/dist/events/types/llm-call.types.d.ts +79 -0
  117. package/dist/events/types/llm-call.types.js +1 -0
  118. package/dist/events/types/repo-snapshot.types.d.ts +32 -0
  119. package/dist/events/types/repo-snapshot.types.js +1 -0
  120. package/dist/feature/constants/feature.constants.d.ts +10 -0
  121. package/dist/feature/constants/feature.constants.js +10 -0
  122. package/dist/feature/index.d.ts +6 -0
  123. package/dist/feature/index.js +6 -0
  124. package/dist/feature/ticket-candidates.d.ts +13 -0
  125. package/dist/feature/ticket-candidates.js +26 -0
  126. package/dist/git/constants/git.constants.d.ts +84 -0
  127. package/dist/git/constants/git.constants.js +113 -0
  128. package/dist/git/git-context.d.ts +52 -0
  129. package/dist/git/git-context.js +226 -0
  130. package/dist/git/index.d.ts +9 -0
  131. package/dist/git/index.js +3 -0
  132. package/dist/git/remote-sanitize.d.ts +26 -0
  133. package/dist/git/remote-sanitize.js +92 -0
  134. package/dist/git/repo-snapshot.d.ts +40 -0
  135. package/dist/git/repo-snapshot.js +95 -0
  136. package/dist/git/types/git.types.d.ts +36 -0
  137. package/dist/git/types/git.types.js +1 -0
  138. package/dist/git/types/snapshot.types.d.ts +25 -0
  139. package/dist/git/types/snapshot.types.js +1 -0
  140. package/dist/otlp/constants/otlp.constants.d.ts +84 -0
  141. package/dist/otlp/constants/otlp.constants.js +99 -0
  142. package/dist/otlp/http.d.ts +24 -0
  143. package/dist/otlp/http.js +37 -0
  144. package/dist/otlp/index.d.ts +9 -0
  145. package/dist/otlp/index.js +3 -0
  146. package/dist/otlp/normalize.d.ts +14 -0
  147. package/dist/otlp/normalize.js +404 -0
  148. package/dist/otlp/types/otlp.types.d.ts +69 -0
  149. package/dist/otlp/types/otlp.types.js +1 -0
  150. package/dist/pipeline/constants/pipeline.constants.d.ts +23 -0
  151. package/dist/pipeline/constants/pipeline.constants.js +22 -0
  152. package/dist/pipeline/hook-pipeline.d.ts +14 -0
  153. package/dist/pipeline/hook-pipeline.js +297 -0
  154. package/dist/pipeline/index.d.ts +6 -0
  155. package/dist/pipeline/index.js +1 -0
  156. package/dist/pipeline/types/pipeline.types.d.ts +48 -0
  157. package/dist/pipeline/types/pipeline.types.js +1 -0
  158. package/dist/privacy/constants/privacy.constants.d.ts +23 -0
  159. package/dist/privacy/constants/privacy.constants.js +38 -0
  160. package/dist/privacy/index.d.ts +7 -0
  161. package/dist/privacy/index.js +2 -0
  162. package/dist/privacy/sanitizer.d.ts +20 -0
  163. package/dist/privacy/sanitizer.js +52 -0
  164. package/dist/privacy/types/privacy.types.d.ts +13 -0
  165. package/dist/privacy/types/privacy.types.js +1 -0
  166. package/dist/providers/antigravity/antigravity.adapter.d.ts +54 -0
  167. package/dist/providers/antigravity/antigravity.adapter.js +311 -0
  168. package/dist/providers/antigravity/antigravity.detect.d.ts +25 -0
  169. package/dist/providers/antigravity/antigravity.detect.js +64 -0
  170. package/dist/providers/antigravity/antigravity.hooks.d.ts +24 -0
  171. package/dist/providers/antigravity/antigravity.hooks.js +126 -0
  172. package/dist/providers/antigravity/antigravity.provider.d.ts +2 -0
  173. package/dist/providers/antigravity/antigravity.provider.js +22 -0
  174. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +72 -0
  175. package/dist/providers/antigravity/constants/antigravity.constants.js +75 -0
  176. package/dist/providers/antigravity/schemas/antigravity.schema.d.ts +521 -0
  177. package/dist/providers/antigravity/schemas/antigravity.schema.js +64 -0
  178. package/dist/providers/antigravity/types/antigravity.types.d.ts +13 -0
  179. package/dist/providers/antigravity/types/antigravity.types.js +1 -0
  180. package/dist/providers/claude/claude.adapter.d.ts +15 -0
  181. package/dist/providers/claude/claude.adapter.js +141 -0
  182. package/dist/providers/claude/claude.detect.d.ts +20 -0
  183. package/dist/providers/claude/claude.detect.js +57 -0
  184. package/dist/providers/claude/claude.hooks.d.ts +23 -0
  185. package/dist/providers/claude/claude.hooks.js +94 -0
  186. package/dist/providers/claude/claude.otel.d.ts +95 -0
  187. package/dist/providers/claude/claude.otel.js +331 -0
  188. package/dist/providers/claude/claude.provider.d.ts +2 -0
  189. package/dist/providers/claude/claude.provider.js +26 -0
  190. package/dist/providers/claude/constants/claude.constants.d.ts +34 -0
  191. package/dist/providers/claude/constants/claude.constants.js +54 -0
  192. package/dist/providers/claude/constants/claude.otel.constants.d.ts +17 -0
  193. package/dist/providers/claude/constants/claude.otel.constants.js +17 -0
  194. package/dist/providers/claude/schemas/claude.schema.d.ts +72 -0
  195. package/dist/providers/claude/schemas/claude.schema.js +32 -0
  196. package/dist/providers/claude/types/claude.types.d.ts +3 -0
  197. package/dist/providers/claude/types/claude.types.js +1 -0
  198. package/dist/providers/codex/codex.adapter.d.ts +11 -0
  199. package/dist/providers/codex/codex.adapter.js +106 -0
  200. package/dist/providers/codex/codex.detect.d.ts +30 -0
  201. package/dist/providers/codex/codex.detect.js +58 -0
  202. package/dist/providers/codex/codex.hooks.d.ts +27 -0
  203. package/dist/providers/codex/codex.hooks.js +129 -0
  204. package/dist/providers/codex/codex.otel.d.ts +51 -0
  205. package/dist/providers/codex/codex.otel.js +325 -0
  206. package/dist/providers/codex/codex.provider.d.ts +2 -0
  207. package/dist/providers/codex/codex.provider.js +25 -0
  208. package/dist/providers/codex/constants/codex.constants.d.ts +41 -0
  209. package/dist/providers/codex/constants/codex.constants.js +62 -0
  210. package/dist/providers/codex/constants/codex.otel.constants.d.ts +22 -0
  211. package/dist/providers/codex/constants/codex.otel.constants.js +22 -0
  212. package/dist/providers/codex/schemas/codex.schema.d.ts +70 -0
  213. package/dist/providers/codex/schemas/codex.schema.js +32 -0
  214. package/dist/providers/codex/types/codex.types.d.ts +3 -0
  215. package/dist/providers/codex/types/codex.types.js +1 -0
  216. package/dist/providers/constants/provider.constants.d.ts +33 -0
  217. package/dist/providers/constants/provider.constants.js +33 -0
  218. package/dist/providers/cursor/constants/cursor.constants.d.ts +58 -0
  219. package/dist/providers/cursor/constants/cursor.constants.js +95 -0
  220. package/dist/providers/cursor/cursor.adapter.d.ts +11 -0
  221. package/dist/providers/cursor/cursor.adapter.js +331 -0
  222. package/dist/providers/cursor/cursor.detect.d.ts +23 -0
  223. package/dist/providers/cursor/cursor.detect.js +66 -0
  224. package/dist/providers/cursor/cursor.hooks.d.ts +25 -0
  225. package/dist/providers/cursor/cursor.hooks.js +95 -0
  226. package/dist/providers/cursor/cursor.provider.d.ts +2 -0
  227. package/dist/providers/cursor/cursor.provider.js +27 -0
  228. package/dist/providers/cursor/schemas/cursor.schema.d.ts +130 -0
  229. package/dist/providers/cursor/schemas/cursor.schema.js +62 -0
  230. package/dist/providers/cursor/types/cursor.types.d.ts +3 -0
  231. package/dist/providers/cursor/types/cursor.types.js +1 -0
  232. package/dist/providers/gemini/constants/gemini.constants.d.ts +36 -0
  233. package/dist/providers/gemini/constants/gemini.constants.js +58 -0
  234. package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +34 -0
  235. package/dist/providers/gemini/constants/gemini.otel.constants.js +48 -0
  236. package/dist/providers/gemini/gemini.adapter.d.ts +15 -0
  237. package/dist/providers/gemini/gemini.adapter.js +146 -0
  238. package/dist/providers/gemini/gemini.detect.d.ts +23 -0
  239. package/dist/providers/gemini/gemini.detect.js +78 -0
  240. package/dist/providers/gemini/gemini.hooks.d.ts +22 -0
  241. package/dist/providers/gemini/gemini.hooks.js +93 -0
  242. package/dist/providers/gemini/gemini.otel.d.ts +62 -0
  243. package/dist/providers/gemini/gemini.otel.js +274 -0
  244. package/dist/providers/gemini/gemini.provider.d.ts +2 -0
  245. package/dist/providers/gemini/gemini.provider.js +22 -0
  246. package/dist/providers/gemini/schemas/gemini.schema.d.ts +81 -0
  247. package/dist/providers/gemini/schemas/gemini.schema.js +35 -0
  248. package/dist/providers/gemini/types/gemini.types.d.ts +3 -0
  249. package/dist/providers/gemini/types/gemini.types.js +1 -0
  250. package/dist/providers/index.d.ts +14 -0
  251. package/dist/providers/index.js +8 -0
  252. package/dist/providers/provider.d.ts +16 -0
  253. package/dist/providers/provider.js +149 -0
  254. package/dist/providers/registry.d.ts +12 -0
  255. package/dist/providers/registry.js +23 -0
  256. package/dist/providers/shared/constants/hook-refusal.constants.d.ts +6 -0
  257. package/dist/providers/shared/constants/hook-refusal.constants.js +6 -0
  258. package/dist/providers/shared/constants/tooling.constants.d.ts +25 -0
  259. package/dist/providers/shared/constants/tooling.constants.js +25 -0
  260. package/dist/providers/shared/event-builder.d.ts +85 -0
  261. package/dist/providers/shared/event-builder.js +166 -0
  262. package/dist/providers/shared/hook-config.d.ts +80 -0
  263. package/dist/providers/shared/hook-config.js +164 -0
  264. package/dist/providers/shared/hook-refusal.d.ts +16 -0
  265. package/dist/providers/shared/hook-refusal.js +33 -0
  266. package/dist/providers/shared/install-record.d.ts +75 -0
  267. package/dist/providers/shared/install-record.js +113 -0
  268. package/dist/providers/shared/tooling.d.ts +58 -0
  269. package/dist/providers/shared/tooling.js +103 -0
  270. package/dist/providers/shared/types/adapter.types.d.ts +54 -0
  271. package/dist/providers/shared/types/adapter.types.js +1 -0
  272. package/dist/providers/shared/types/hook-config.types.d.ts +32 -0
  273. package/dist/providers/shared/types/hook-config.types.js +1 -0
  274. package/dist/providers/types/provider.types.d.ts +98 -0
  275. package/dist/providers/types/provider.types.js +1 -0
  276. package/dist/snapshot/branch-selection.d.ts +37 -0
  277. package/dist/snapshot/branch-selection.js +69 -0
  278. package/dist/snapshot/budget.d.ts +41 -0
  279. package/dist/snapshot/budget.js +67 -0
  280. package/dist/snapshot/constants/snapshot-stages.constants.d.ts +11 -0
  281. package/dist/snapshot/constants/snapshot-stages.constants.js +11 -0
  282. package/dist/snapshot/constants/snapshot.constants.d.ts +56 -0
  283. package/dist/snapshot/constants/snapshot.constants.js +56 -0
  284. package/dist/snapshot/index.d.ts +16 -0
  285. package/dist/snapshot/index.js +6 -0
  286. package/dist/snapshot/snapshot-event.d.ts +17 -0
  287. package/dist/snapshot/snapshot-event.js +66 -0
  288. package/dist/snapshot/snapshot-pipeline.d.ts +14 -0
  289. package/dist/snapshot/snapshot-pipeline.js +163 -0
  290. package/dist/snapshot/snapshot-state.d.ts +55 -0
  291. package/dist/snapshot/snapshot-state.js +100 -0
  292. package/dist/snapshot/types/snapshot.types.d.ts +86 -0
  293. package/dist/snapshot/types/snapshot.types.js +1 -0
  294. package/dist/storage/atomic-file.d.ts +25 -0
  295. package/dist/storage/atomic-file.js +76 -0
  296. package/dist/storage/constants/storage.constants.d.ts +34 -0
  297. package/dist/storage/constants/storage.constants.js +35 -0
  298. package/dist/storage/index.d.ts +10 -0
  299. package/dist/storage/index.js +5 -0
  300. package/dist/storage/install-state.d.ts +20 -0
  301. package/dist/storage/install-state.js +40 -0
  302. package/dist/storage/json-file.d.ts +13 -0
  303. package/dist/storage/json-file.js +31 -0
  304. package/dist/storage/lock.d.ts +15 -0
  305. package/dist/storage/lock.js +70 -0
  306. package/dist/storage/paths.d.ts +14 -0
  307. package/dist/storage/paths.js +42 -0
  308. package/dist/storage/schemas/storage.schema.d.ts +128 -0
  309. package/dist/storage/schemas/storage.schema.js +27 -0
  310. package/dist/storage/types/storage.types.d.ts +36 -0
  311. package/dist/storage/types/storage.types.js +1 -0
  312. package/dist/transport/constants/transport.constants.d.ts +47 -0
  313. package/dist/transport/constants/transport.constants.js +47 -0
  314. package/dist/transport/cooldown.d.ts +35 -0
  315. package/dist/transport/cooldown.js +62 -0
  316. package/dist/transport/delivery-stats.d.ts +65 -0
  317. package/dist/transport/delivery-stats.js +186 -0
  318. package/dist/transport/delivery.d.ts +26 -0
  319. package/dist/transport/delivery.js +80 -0
  320. package/dist/transport/headers.d.ts +12 -0
  321. package/dist/transport/headers.js +19 -0
  322. package/dist/transport/http-transport.d.ts +39 -0
  323. package/dist/transport/http-transport.js +106 -0
  324. package/dist/transport/index.d.ts +13 -0
  325. package/dist/transport/index.js +7 -0
  326. package/dist/transport/queue.d.ts +177 -0
  327. package/dist/transport/queue.js +474 -0
  328. package/dist/transport/schemas/queue.schema.d.ts +30 -0
  329. package/dist/transport/schemas/queue.schema.js +18 -0
  330. package/dist/transport/transport.d.ts +6 -0
  331. package/dist/transport/transport.js +1 -0
  332. package/dist/transport/types/transport.types.d.ts +102 -0
  333. package/dist/transport/types/transport.types.js +1 -0
  334. package/dist/turns/aggregate-usage.d.ts +20 -0
  335. package/dist/turns/aggregate-usage.js +269 -0
  336. package/dist/turns/claude-transcript.d.ts +18 -0
  337. package/dist/turns/claude-transcript.js +80 -0
  338. package/dist/turns/constants/turns.constants.d.ts +69 -0
  339. package/dist/turns/constants/turns.constants.js +86 -0
  340. package/dist/turns/cursor-transcript.d.ts +21 -0
  341. package/dist/turns/cursor-transcript.js +66 -0
  342. package/dist/turns/index.d.ts +17 -0
  343. package/dist/turns/index.js +7 -0
  344. package/dist/turns/transcript.d.ts +74 -0
  345. package/dist/turns/transcript.js +188 -0
  346. package/dist/turns/turn-state.d.ts +94 -0
  347. package/dist/turns/turn-state.js +234 -0
  348. package/dist/turns/turn-summary.d.ts +27 -0
  349. package/dist/turns/turn-summary.js +164 -0
  350. package/dist/turns/turn-tracker.d.ts +14 -0
  351. package/dist/turns/turn-tracker.js +521 -0
  352. package/dist/turns/types/aggregate-usage.types.d.ts +26 -0
  353. package/dist/turns/types/aggregate-usage.types.js +1 -0
  354. package/dist/turns/types/transcript.types.d.ts +41 -0
  355. package/dist/turns/types/transcript.types.js +1 -0
  356. package/dist/turns/types/turn-state.types.d.ts +37 -0
  357. package/dist/turns/types/turn-state.types.js +1 -0
  358. package/dist/turns/types/turn-summary.types.d.ts +106 -0
  359. package/dist/turns/types/turn-summary.types.js +1 -0
  360. package/dist/turns/types/turn-tracker.types.d.ts +27 -0
  361. package/dist/turns/types/turn-tracker.types.js +1 -0
  362. package/example/README.md +43 -0
  363. package/example/server.mjs +240 -0
  364. package/package.json +89 -0
@@ -0,0 +1,49 @@
1
+ import crypto from 'node:crypto';
2
+ import { EVENT_ID_HEX_LENGTH, EVENT_ID_PREFIX } from './constants/events.constants.js';
3
+ /**
4
+ * Deterministic event id, so retries and duplicate hook firings dedupe
5
+ * downstream.
6
+ *
7
+ * The id is a function of the event's identity alone. That is what makes the
8
+ * offline queue idempotent (the filename *is* the id) and what lets the
9
+ * backend upsert instead of counting the same turn twice.
10
+ *
11
+ * @param input - Identity fields; content is passed pre-hashed only.
12
+ * @returns The `evt_`-prefixed id.
13
+ */
14
+ export function deriveEventId(input) {
15
+ const canonical = JSON.stringify([
16
+ input.provider,
17
+ input.providerEventType,
18
+ input.sessionId ?? '',
19
+ input.turnId ?? '',
20
+ input.generationId ?? '',
21
+ input.toolUseId ?? '',
22
+ input.promptId ?? '',
23
+ input.timestamp ?? '',
24
+ input.payloadFingerprint ?? ''
25
+ ]);
26
+ return EVENT_ID_PREFIX + sha256Hex(canonical).slice(0, EVENT_ID_HEX_LENGTH);
27
+ }
28
+ /**
29
+ * Event id built from an id the provider already guarantees to be unique.
30
+ *
31
+ * @param provider - Internal provider id, which scopes the namespace.
32
+ * @param rawId - The provider's own identifier.
33
+ * @returns The namespaced event id.
34
+ */
35
+ export function providerEventId(provider, rawId) {
36
+ return `${EVENT_ID_PREFIX}${provider}_${rawId}`;
37
+ }
38
+ /**
39
+ * SHA-256 of a string, hex encoded.
40
+ *
41
+ * Used both for ids and as the one-way function behind every pseudonymous
42
+ * field (repository hash, content evidence, session directory name).
43
+ *
44
+ * @param text - Text to digest.
45
+ * @returns Lowercase hex digest.
46
+ */
47
+ export function sha256Hex(text) {
48
+ return crypto.createHash('sha256').update(text).digest('hex');
49
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The canonical event model: what a record looks like, how its identity is
3
+ * derived, and how development context is attached before it is sent.
4
+ */
5
+ export type { AgentWatchEvent, CanonicalEventType, ContentEvidence, EventAi, EventGit, EventIdInput, EventPatch, EventSession, EventTool, EventUsage, FeatureCandidate, InternalHookEventType, ProductEventType, UsageBillingMode, UsageSource } from './types/events.types.js';
6
+ export type { BuildLlmCallInput, LlmCallCorrelation, LlmCallEvent, LlmCallStatus, LlmCallUsage } from './types/llm-call.types.js';
7
+ export type { RepoSnapshotBranch, RepoSnapshotCommit, RepoSnapshotEvent } from './types/repo-snapshot.types.js';
8
+ export type { EnrichOptions, PathRewriter, PathRule } from './types/enrich.types.js';
9
+ export type { ProductEvent } from './product-event.js';
10
+ export { CANONICAL_EVENT_TYPES, EVENT_SCHEMA_VERSION, INTERNAL_HOOK_EVENT_TYPES, PRODUCT_EVENT_TYPES, PRODUCT_EVENT_TYPE_SET, TURN_CLOSING_EVENT_TYPE } from './constants/events.constants.js';
11
+ export { deriveEventId, providerEventId, sha256Hex } from './event-id.js';
12
+ export { buildLlmCall } from './llm-call.js';
13
+ export { isProductEvent } from './product-event.js';
14
+ export { enrichEvents } from './enrich.js';
@@ -0,0 +1,5 @@
1
+ export { CANONICAL_EVENT_TYPES, EVENT_SCHEMA_VERSION, INTERNAL_HOOK_EVENT_TYPES, PRODUCT_EVENT_TYPES, PRODUCT_EVENT_TYPE_SET, TURN_CLOSING_EVENT_TYPE } from './constants/events.constants.js';
2
+ export { deriveEventId, providerEventId, sha256Hex } from './event-id.js';
3
+ export { buildLlmCall } from './llm-call.js';
4
+ export { isProductEvent } from './product-event.js';
5
+ export { enrichEvents } from './enrich.js';
@@ -0,0 +1,14 @@
1
+ import type { BuildLlmCallInput, LlmCallEvent } from './types/llm-call.types.js';
2
+ export type { BuildLlmCallInput, LlmCallCorrelation, LlmCallEvent, LlmCallStatus, LlmCallUsage } from './types/llm-call.types.js';
3
+ /**
4
+ * Build the atomic usage record for one provider request.
5
+ *
6
+ * Called by whoever decodes agent telemetry — the edge's own OTLP
7
+ * normalizer, or a backend using `@agent-watch-ai/edge/llm-call` directly.
8
+ * Both the flat `*_tokens` fields and the nested canonical `session` block are
9
+ * populated from the same input, so a consumer can read whichever it models.
10
+ *
11
+ * @param input - Everything known about the call.
12
+ * @returns The llm.call event, with absent fields omitted rather than null.
13
+ */
14
+ export declare function buildLlmCall(input: BuildLlmCallInput): LlmCallEvent;
@@ -0,0 +1,84 @@
1
+ import { compact } from '../core/object.js';
2
+ import { deriveEventId, sha256Hex } from './event-id.js';
3
+ import { EVENT_SCHEMA_VERSION } from './constants/events.constants.js';
4
+ /**
5
+ * Build the atomic usage record for one provider request.
6
+ *
7
+ * Called by whoever decodes agent telemetry — the edge's own OTLP
8
+ * normalizer, or a backend using `@agent-watch-ai/edge/llm-call` directly.
9
+ * Both the flat `*_tokens` fields and the nested canonical `session` block are
10
+ * populated from the same input, so a consumer can read whichever it models.
11
+ *
12
+ * @param input - Everything known about the call.
13
+ * @returns The llm.call event, with absent fields omitted rather than null.
14
+ */
15
+ export function buildLlmCall(input) {
16
+ const jiraIds = ticketValues(input.featureCandidates);
17
+ const providerRequestId = input.providerRequestId ?? input.callId;
18
+ return compact({
19
+ schemaVersion: EVENT_SCHEMA_VERSION,
20
+ id: deriveEventId({
21
+ provider: input.provider,
22
+ providerEventType: 'llm.call',
23
+ sessionId: input.sessionId,
24
+ turnId: input.turnId,
25
+ payloadFingerprint: sha256Hex(providerRequestId)
26
+ }),
27
+ timestamp: input.endedAt,
28
+ event: { type: 'llm.call', providerEventType: 'llm.call' },
29
+ agent: { provider: input.provider, name: input.provider },
30
+ session: {
31
+ id: input.sessionId,
32
+ providerId: input.sessionId,
33
+ turnId: input.turnId,
34
+ generationId: input.callId,
35
+ agentId: input.agentId
36
+ },
37
+ provider: input.provider,
38
+ surface: input.surface,
39
+ call_id: input.callId,
40
+ provider_request_id: input.providerRequestId,
41
+ provider_session_id: input.providerSessionId,
42
+ provider_turn_id: input.providerTurnId,
43
+ session_id: input.sessionId,
44
+ turn_id: input.turnId,
45
+ agent_id: input.agentId,
46
+ parent_agent_id: input.parentAgentId,
47
+ agent_type: input.agentType,
48
+ model: input.model,
49
+ // 'unknown' is the absence of a verdict, not a billing mode; emitting it
50
+ // would make the field look answered.
51
+ billing_mode: input.billingMode && input.billingMode !== 'unknown' ? input.billingMode : undefined,
52
+ status: input.status ?? 'completed',
53
+ correlation: input.correlation,
54
+ input_tokens: input.usage?.inputTokens,
55
+ cached_input_tokens: input.usage?.cachedInputTokens,
56
+ cache_creation_input_tokens: input.usage?.cacheCreationInputTokens,
57
+ output_tokens: input.usage?.outputTokens,
58
+ reasoning_output_tokens: input.usage?.reasoningOutputTokens,
59
+ total_tokens: input.usage?.totalTokens,
60
+ cost_usd: input.costUsd,
61
+ duration_ms: input.durationMs,
62
+ started_at: input.startedAt,
63
+ ended_at: input.endedAt,
64
+ repository: input.git?.repository,
65
+ branch: input.git?.branch,
66
+ commit: input.git?.commit,
67
+ jira_ids: jiraIds.length > 0 ? jiraIds : undefined
68
+ });
69
+ }
70
+ /**
71
+ * Ticket keys out of mixed feature evidence.
72
+ *
73
+ * @param candidates - Evidence collected during enrichment.
74
+ * @returns The ticket values, in order.
75
+ */
76
+ function ticketValues(candidates) {
77
+ const tickets = [];
78
+ for (const candidate of candidates ?? []) {
79
+ if (candidate.type !== 'ticket')
80
+ continue;
81
+ tickets.push(candidate.value);
82
+ }
83
+ return tickets;
84
+ }
@@ -0,0 +1,39 @@
1
+ import type { LlmCallEvent } from './types/llm-call.types.js';
2
+ import type { RepoSnapshotEvent } from './types/repo-snapshot.types.js';
3
+ import type { TurnSummaryEvent } from '../turns/types/turn-summary.types.js';
4
+ export { PRODUCT_EVENT_TYPES } from './constants/events.constants.js';
5
+ export type { ProductEventType } from './types/events.types.js';
6
+ export type { LlmCallEvent, LlmCallCorrelation, LlmCallStatus } from './types/llm-call.types.js';
7
+ export type { RepoSnapshotBranch, RepoSnapshotCommit, RepoSnapshotEvent } from './types/repo-snapshot.types.js';
8
+ export type { AgentUsageSummary, TurnSummaryEvent, TurnUsageStatus } from '../turns/types/turn-summary.types.js';
9
+ /**
10
+ * The complete public AgentWatch domain contract.
11
+ *
12
+ * Three record types, deliberately: `llm.call` is the lossless per-request
13
+ * usage ledger, `turn.summary` is the human unit of work, and `repo.snapshot`
14
+ * is what the working copy says the work *is* when no tracker can be asked. No
15
+ * lifecycle or tool event is public — those exist only to assemble a summary
16
+ * locally.
17
+ */
18
+ export type ProductEvent = LlmCallEvent | TurnSummaryEvent | RepoSnapshotEvent;
19
+ /** The least a value must look like for {@link isProductEvent} to judge it. */
20
+ export interface EventTypeCarrier {
21
+ readonly event?: {
22
+ readonly type?: string;
23
+ };
24
+ }
25
+ /**
26
+ * Whether a record is one the backend accepts.
27
+ *
28
+ * The guard the offline queue uses before draining an entry: a backlog written
29
+ * by an older release can hold internal lifecycle events, and draining one
30
+ * would poison every batch it rides in.
31
+ *
32
+ * One membership test against the declared vocabulary rather than a list of
33
+ * comparisons: the two drifted once, and a record type the queue accepts but
34
+ * this guard does not is a backlog entry that is never drained.
35
+ *
36
+ * @param value - Any record carrying an `event.type`.
37
+ * @returns True when it is one of PRODUCT_EVENT_TYPES.
38
+ */
39
+ export declare function isProductEvent(value: EventTypeCarrier): value is EventTypeCarrier & ProductEvent;
@@ -0,0 +1,19 @@
1
+ import { PRODUCT_EVENT_TYPE_SET } from './constants/events.constants.js';
2
+ export { PRODUCT_EVENT_TYPES } from './constants/events.constants.js';
3
+ /**
4
+ * Whether a record is one the backend accepts.
5
+ *
6
+ * The guard the offline queue uses before draining an entry: a backlog written
7
+ * by an older release can hold internal lifecycle events, and draining one
8
+ * would poison every batch it rides in.
9
+ *
10
+ * One membership test against the declared vocabulary rather than a list of
11
+ * comparisons: the two drifted once, and a record type the queue accepts but
12
+ * this guard does not is a backlog entry that is never drained.
13
+ *
14
+ * @param value - Any record carrying an `event.type`.
15
+ * @returns True when it is one of PRODUCT_EVENT_TYPES.
16
+ */
17
+ export function isProductEvent(value) {
18
+ return value.event?.type !== undefined && PRODUCT_EVENT_TYPE_SET.has(value.event.type);
19
+ }
@@ -0,0 +1,25 @@
1
+ import type { AgentWatchConfig } from '../../config/types/config.types.js';
2
+ export interface EnrichOptions {
3
+ readonly config: AgentWatchConfig;
4
+ /** Working directory reported by the agent's hook payload. */
5
+ readonly cwd: string;
6
+ /** Developer home directory; rewritten to `~` inside captured content. */
7
+ readonly home?: string;
8
+ readonly gitTimeoutMs?: number;
9
+ }
10
+ /** One literal-to-placeholder substitution applied to captured text. */
11
+ export interface PathRule {
12
+ readonly pattern: RegExp;
13
+ readonly replacement: string;
14
+ }
15
+ /**
16
+ * Pre-compiled path substitutions for one enrichment pass.
17
+ *
18
+ * Built once per call and reused for every string of every event: the rules
19
+ * depend only on the repository root and the home directory, and compiling
20
+ * them per string is what made path rewriting the most expensive part of the
21
+ * hook (STYLEGUIDE 3.1).
22
+ */
23
+ export interface PathRewriter {
24
+ readonly rules: readonly PathRule[];
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,112 @@
1
+ /**
2
+ * AgentWatch canonical event schema, version 1.
3
+ *
4
+ * Provider adapters translate native hook payloads into this shape. The schema
5
+ * is deliberately decoupled from OpenTelemetry semantic conventions: native
6
+ * agent OTel flows to the backend separately and is correlated there.
7
+ *
8
+ * Every field is readonly. Events are values: an adapter that needed to
9
+ * "adjust" one after the fact would be mutating something another stage may
10
+ * already be reading, so enrichment and turn tracking build new events
11
+ * instead.
12
+ */
13
+ import type { CANONICAL_EVENT_TYPES, INTERNAL_HOOK_EVENT_TYPES, PRODUCT_EVENT_TYPES } from '../constants/events.constants.js';
14
+ export type CanonicalEventType = (typeof CANONICAL_EVENT_TYPES)[number];
15
+ export type InternalHookEventType = (typeof INTERNAL_HOOK_EVENT_TYPES)[number];
16
+ export type ProductEventType = (typeof PRODUCT_EVENT_TYPES)[number];
17
+ /** Where a usage number came from; decides how much to trust it. */
18
+ export type UsageSource = 'native_otel' | 'hook_payload' | 'transcript' | 'unknown';
19
+ /** How the developer pays for this agent. */
20
+ export type UsageBillingMode = 'api' | 'subscription' | 'unknown';
21
+ /** Evidence linking a turn to a unit of work. Attribution happens in the backend. */
22
+ export interface FeatureCandidate {
23
+ readonly type: 'ticket' | 'branch' | 'other';
24
+ readonly value: string;
25
+ readonly source: string;
26
+ }
27
+ export interface EventSession {
28
+ /** Normalized session identifier (provider session/thread id, verbatim). */
29
+ readonly id?: string;
30
+ /** The provider-native identifier this `id` was taken from, unmodified. */
31
+ readonly providerId?: string;
32
+ readonly turnId?: string;
33
+ readonly generationId?: string;
34
+ readonly agentId?: string;
35
+ }
36
+ export interface EventGit {
37
+ readonly repository?: string;
38
+ readonly repositoryHash?: string;
39
+ readonly remote?: string;
40
+ readonly branch?: string;
41
+ readonly commit?: string;
42
+ readonly workingDirectory?: string;
43
+ readonly changedFiles?: readonly string[];
44
+ }
45
+ export interface EventUsage {
46
+ readonly inputTokens?: number;
47
+ readonly outputTokens?: number;
48
+ readonly cachedInputTokens?: number;
49
+ readonly cacheCreationInputTokens?: number;
50
+ readonly cachedOutputTokens?: number;
51
+ readonly totalTokens?: number;
52
+ readonly source?: UsageSource;
53
+ }
54
+ export interface EventAi {
55
+ readonly provider?: string;
56
+ readonly model?: string;
57
+ readonly billingMode?: UsageBillingMode;
58
+ readonly usage?: EventUsage;
59
+ }
60
+ export interface EventTool {
61
+ readonly name?: string;
62
+ readonly status?: 'started' | 'completed' | 'failed';
63
+ readonly durationMs?: number;
64
+ }
65
+ export interface AgentWatchEvent<TType extends CanonicalEventType = CanonicalEventType> {
66
+ readonly schemaVersion: '1';
67
+ readonly id: string;
68
+ readonly timestamp: string;
69
+ readonly event: {
70
+ readonly type: TType;
71
+ readonly providerEventType: string;
72
+ };
73
+ readonly agent: {
74
+ readonly provider: string;
75
+ readonly name: string;
76
+ readonly version?: string;
77
+ };
78
+ readonly session: EventSession;
79
+ readonly developer?: {
80
+ readonly installationId?: string;
81
+ };
82
+ readonly git?: EventGit;
83
+ readonly feature?: {
84
+ readonly candidates?: readonly FeatureCandidate[];
85
+ };
86
+ readonly ai?: EventAi;
87
+ readonly tool?: EventTool;
88
+ readonly metadata?: Readonly<Record<string, unknown>>;
89
+ }
90
+ /** Everything an adapter may contribute on top of the base event. */
91
+ export type EventPatch = Partial<Omit<AgentWatchEvent, 'schemaVersion' | 'id' | 'timestamp' | 'event' | 'agent'>>;
92
+ /** Length and hash of text we may not be transmitting verbatim. */
93
+ export interface ContentEvidence {
94
+ readonly length: number;
95
+ readonly sha256: string;
96
+ }
97
+ /** Inputs to the deterministic event id. */
98
+ export interface EventIdInput {
99
+ readonly provider: string;
100
+ readonly providerEventType: string;
101
+ readonly sessionId?: string;
102
+ readonly turnId?: string;
103
+ readonly generationId?: string;
104
+ readonly toolUseId?: string;
105
+ readonly promptId?: string;
106
+ readonly timestamp?: string;
107
+ /**
108
+ * Fingerprint of variable payload content (already hashed by the caller).
109
+ * Raw prompt/response/tool text must never be passed here directly.
110
+ */
111
+ readonly payloadFingerprint?: string;
112
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,79 @@
1
+ import type { AgentWatchEvent, EventGit, FeatureCandidate, UsageBillingMode } from './events.types.js';
2
+ export type LlmCallStatus = 'completed' | 'failed';
3
+ /**
4
+ * How confidently a call was joined to a product turn: by an exact turn id,
5
+ * through the turn's time window, or only by session.
6
+ */
7
+ export type LlmCallCorrelation = 'exact' | 'turn' | 'session';
8
+ /**
9
+ * One provider request that can consume tokens. This is the atomic usage
10
+ * ledger record: retries are separate calls when the provider reports them
11
+ * separately, and turn/feature totals must be derived from unique call ids.
12
+ */
13
+ export interface LlmCallEvent extends AgentWatchEvent<'llm.call'> {
14
+ readonly provider: string;
15
+ readonly surface: string;
16
+ readonly call_id: string;
17
+ readonly provider_request_id?: string;
18
+ /** Native scope before a child-agent trace is joined to its root turn. */
19
+ readonly provider_session_id?: string;
20
+ readonly provider_turn_id?: string;
21
+ readonly session_id?: string;
22
+ readonly turn_id?: string;
23
+ /** Concrete child-agent instance when the provider exposes it. */
24
+ readonly agent_id?: string;
25
+ readonly parent_agent_id?: string;
26
+ /** Provider role/name such as Explore, reviewer, or repl_main_thread. */
27
+ readonly agent_type?: string;
28
+ readonly model?: string;
29
+ readonly billing_mode?: UsageBillingMode;
30
+ readonly status: LlmCallStatus;
31
+ readonly correlation: LlmCallCorrelation;
32
+ readonly input_tokens?: number;
33
+ readonly cached_input_tokens?: number;
34
+ readonly cache_creation_input_tokens?: number;
35
+ readonly output_tokens?: number;
36
+ readonly reasoning_output_tokens?: number;
37
+ readonly total_tokens?: number;
38
+ readonly cost_usd?: number;
39
+ readonly duration_ms?: number;
40
+ readonly started_at?: string;
41
+ readonly ended_at: string;
42
+ readonly repository?: string;
43
+ readonly branch?: string;
44
+ readonly commit?: string;
45
+ readonly jira_ids?: readonly string[];
46
+ }
47
+ /** Token counts as the caller measured them, before name flattening. */
48
+ export interface LlmCallUsage {
49
+ readonly inputTokens?: number;
50
+ readonly cachedInputTokens?: number;
51
+ readonly cacheCreationInputTokens?: number;
52
+ readonly outputTokens?: number;
53
+ readonly reasoningOutputTokens?: number;
54
+ readonly totalTokens?: number;
55
+ }
56
+ export interface BuildLlmCallInput {
57
+ readonly provider: string;
58
+ readonly surface: string;
59
+ readonly callId: string;
60
+ readonly providerRequestId?: string;
61
+ readonly providerSessionId?: string;
62
+ readonly providerTurnId?: string;
63
+ readonly sessionId?: string;
64
+ readonly turnId?: string;
65
+ readonly agentId?: string;
66
+ readonly parentAgentId?: string;
67
+ readonly agentType?: string;
68
+ readonly model?: string;
69
+ readonly billingMode?: UsageBillingMode;
70
+ readonly status?: LlmCallStatus;
71
+ readonly correlation: LlmCallCorrelation;
72
+ readonly usage?: LlmCallUsage;
73
+ readonly costUsd?: number;
74
+ readonly durationMs?: number;
75
+ readonly startedAt?: string;
76
+ readonly endedAt: string;
77
+ readonly git?: EventGit;
78
+ readonly featureCandidates?: readonly FeatureCandidate[];
79
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { AgentWatchEvent } from './events.types.js';
2
+ /** One commit of a branch's delta, as the backend receives it. */
3
+ export interface RepoSnapshotCommit {
4
+ readonly sha: string;
5
+ readonly subject: string;
6
+ readonly authored_at?: string;
7
+ }
8
+ /** One branch of a snapshot, with the commits that are its own. */
9
+ export interface RepoSnapshotBranch {
10
+ readonly name: string;
11
+ readonly head_sha: string;
12
+ readonly last_commit_at?: string;
13
+ readonly commits: readonly RepoSnapshotCommit[];
14
+ }
15
+ /**
16
+ * What one repository looked like on this machine at one moment.
17
+ *
18
+ * The third product record, and the only one that is not about spend: it is
19
+ * what lets a backend with no tracker connected know that a piece of work
20
+ * exists at all. Sent only when something changed, so a quiet repository costs
21
+ * nothing.
22
+ */
23
+ export interface RepoSnapshotEvent extends AgentWatchEvent<'repo.snapshot'> {
24
+ readonly provider: string;
25
+ readonly surface: string;
26
+ readonly repository: string;
27
+ readonly developer_id?: string;
28
+ readonly default_branch?: string;
29
+ /** When the working copy was read. The backend orders snapshots by this. */
30
+ readonly captured_at: string;
31
+ readonly branches: readonly RepoSnapshotBranch[];
32
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Jira/Linear-style ticket key inside a branch name.
3
+ *
4
+ * Case-sensitive by design: uppercasing the branch first would turn ordinary
5
+ * words into fabricated ticket ids ("bump-node-20" -> NODE-20) and
6
+ * misattribute the session's work and cost to a ticket that does not exist.
7
+ */
8
+ export declare const RE_TICKET_KEY: RegExp;
9
+ /** Where a candidate was found; carried on the event as provenance. */
10
+ export declare const BRANCH_EVIDENCE_SOURCE = "git.branch";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Jira/Linear-style ticket key inside a branch name.
3
+ *
4
+ * Case-sensitive by design: uppercasing the branch first would turn ordinary
5
+ * words into fabricated ticket ids ("bump-node-20" -> NODE-20) and
6
+ * misattribute the session's work and cost to a ticket that does not exist.
7
+ */
8
+ export const RE_TICKET_KEY = /\b([A-Z][A-Z0-9]{1,9}-\d{1,6})\b/g;
9
+ /** Where a candidate was found; carried on the event as provenance. */
10
+ export const BRANCH_EVIDENCE_SOURCE = 'git.branch';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Feature-correlation evidence: what the working context says about which
3
+ * piece of work a turn belongs to. Attribution itself happens in the backend.
4
+ */
5
+ export { RE_TICKET_KEY } from './constants/feature.constants.js';
6
+ export { featureCandidatesFromBranch } from './ticket-candidates.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Feature-correlation evidence: what the working context says about which
3
+ * piece of work a turn belongs to. Attribution itself happens in the backend.
4
+ */
5
+ export { RE_TICKET_KEY } from './constants/feature.constants.js';
6
+ export { featureCandidatesFromBranch } from './ticket-candidates.js';
@@ -0,0 +1,13 @@
1
+ import type { FeatureCandidate } from '../events/canonical-event.js';
2
+ /**
3
+ * Extract feature-correlation *evidence* (Jira/Linear ticket keys) from a
4
+ * branch name.
5
+ *
6
+ * Evidence, not attribution: this reports what the branch name literally
7
+ * contains and the backend decides what it means. Duplicates collapse, order
8
+ * of first appearance is kept.
9
+ *
10
+ * @param branch - Current branch name, or undefined outside a repository.
11
+ * @returns Ticket candidates, empty when the branch names none.
12
+ */
13
+ export declare function featureCandidatesFromBranch(branch: string | undefined): FeatureCandidate[];
@@ -0,0 +1,26 @@
1
+ import { BRANCH_EVIDENCE_SOURCE, RE_TICKET_KEY } from './constants/feature.constants.js';
2
+ /**
3
+ * Extract feature-correlation *evidence* (Jira/Linear ticket keys) from a
4
+ * branch name.
5
+ *
6
+ * Evidence, not attribution: this reports what the branch name literally
7
+ * contains and the backend decides what it means. Duplicates collapse, order
8
+ * of first appearance is kept.
9
+ *
10
+ * @param branch - Current branch name, or undefined outside a repository.
11
+ * @returns Ticket candidates, empty when the branch names none.
12
+ */
13
+ export function featureCandidatesFromBranch(branch) {
14
+ if (!branch)
15
+ return [];
16
+ const candidates = [];
17
+ const seen = new Set();
18
+ for (const match of branch.matchAll(RE_TICKET_KEY)) {
19
+ const ticket = match[1];
20
+ if (!ticket || seen.has(ticket))
21
+ continue;
22
+ seen.add(ticket);
23
+ candidates.push({ type: 'ticket', value: ticket, source: BRANCH_EVIDENCE_SOURCE });
24
+ }
25
+ return candidates;
26
+ }
@@ -0,0 +1,84 @@
1
+ /** Default budget for one git invocation; hooks run on the critical path. */
2
+ export declare const GIT_TIMEOUT_MS = 1000;
3
+ /** Cap on the changedFiles list; a huge dirty tree must not bloat an event. */
4
+ export declare const MAX_CHANGED_FILES = 50;
5
+ /** stdout ceiling per git process. */
6
+ export declare const GIT_MAX_BUFFER_BYTES: number;
7
+ /**
8
+ * Argument vectors, named so a reader sees intent instead of flags.
9
+ *
10
+ * `symbolic-ref` rather than `branch --show-current`: the latter needs
11
+ * git >= 2.22, and its absence would silently drop branch — and therefore
12
+ * ticket — attribution on older machines. It exits non-zero on a detached
13
+ * HEAD, which is exactly the "no branch" answer we want.
14
+ */
15
+ export declare const GIT_REPO_ROOT_ARGS: readonly ["rev-parse", "--show-toplevel"];
16
+ export declare const GIT_BRANCH_ARGS: readonly ["symbolic-ref", "--short", "-q", "HEAD"];
17
+ export declare const GIT_COMMIT_ARGS: readonly ["rev-parse", "HEAD"];
18
+ export declare const GIT_REMOTE_ARGS: readonly ["config", "--get", "remote.origin.url"];
19
+ export declare const GIT_STATUS_ARGS: readonly ["status", "--porcelain"];
20
+ export declare const GIT_USER_EMAIL_ARGS: readonly ["config", "--get", "user.email"];
21
+ /** Where `origin/HEAD` points: the remote's default branch, when it is known locally. */
22
+ export declare const GIT_ORIGIN_HEAD_ARGS: readonly ["symbolic-ref", "--short", "-q", "refs/remotes/origin/HEAD"];
23
+ /** Field separator inside one `for-each-ref` / `log` record. */
24
+ export declare const GIT_FIELD_SEPARATOR = "\u001F";
25
+ /**
26
+ * The recent branches, newest commit first, with the heads the cache is
27
+ * compared against.
28
+ *
29
+ * One process for the whole listing, and it carries the heads — which is what
30
+ * lets the cache diff run before any `git log`. On an ordinary closing turn,
31
+ * where nothing moved, that is the difference between two git processes and
32
+ * twelve.
33
+ *
34
+ * @param count - How many branches to list, newest commit first.
35
+ * @returns The argument vector.
36
+ */
37
+ export declare function gitRecentBranchesArgs(count: number): readonly string[];
38
+ /**
39
+ * The commits on a branch that its default branch does not have.
40
+ *
41
+ * The delta, never the history: `git log <branch>` would carry the trunk's
42
+ * commits into every branch's evidence, so unrelated work would be described
43
+ * by the same subjects and named as one feature.
44
+ *
45
+ * @param defaultBranch - The trunk to subtract.
46
+ * @param branch - The branch to describe.
47
+ * @param count - Ceiling on the commits returned.
48
+ * @returns The argument vector.
49
+ */
50
+ export declare function gitBranchDeltaArgs(defaultBranch: string, branch: string, count: number): readonly string[];
51
+ /**
52
+ * Whether a ref exists at all, for the local fallback when no `origin/HEAD` does.
53
+ *
54
+ * @param ref - The ref to test.
55
+ * @returns The argument vector, which exits non-zero when the ref is absent.
56
+ */
57
+ export declare function gitVerifyRefArgs(ref: string): readonly string[];
58
+ /** What a repository's trunk is called when neither git nor the platform said. */
59
+ export declare const ASSUMED_DEFAULT_BRANCHES: readonly ["main", "master"];
60
+ /** Node's error code for a child process that overran maxBuffer on stdout. */
61
+ export declare const STDOUT_MAXBUFFER_CODE = "ERR_CHILD_PROCESS_STDOUT_MAXBUFFER";
62
+ /** Length of the "XY " status prefix before the path in porcelain output. */
63
+ export declare const PORCELAIN_PREFIX_LENGTH = 3;
64
+ /** Separator between the old and new path of a rename in porcelain output. */
65
+ export declare const PORCELAIN_RENAME_SEPARATOR = " -> ";
66
+ /** C-style escapes git emits inside a quoted path (core.quotePath). */
67
+ export declare const PORCELAIN_ESCAPES: Readonly<Record<string, string>>;
68
+ /** Trailing whitespace only: porcelain lines carry significant leading spaces. */
69
+ export declare const RE_TRAILING_WHITESPACE: RegExp;
70
+ /** A URL scheme followed by "://". */
71
+ export declare const RE_URL_SCHEME: RegExp;
72
+ /** `scheme://user@` and `scheme://user:password@` prefixes. */
73
+ export declare const RE_URL_USERINFO: RegExp;
74
+ export declare const RE_URL_USERINFO_WITH_PASSWORD: RegExp;
75
+ /** Leading `user@` of an scp-like remote. */
76
+ export declare const RE_SCP_USERINFO: RegExp;
77
+ /**
78
+ * scp-like remote: `host:path`. Two or more characters before the colon keeps
79
+ * Windows drive paths ("C:\\...") out.
80
+ */
81
+ export declare const RE_SCP_REMOTE: RegExp;
82
+ export declare const RE_LEADING_SLASHES: RegExp;
83
+ export declare const RE_TRAILING_SLASHES: RegExp;
84
+ export declare const RE_DOT_GIT_SUFFIX: RegExp;