@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,404 @@
1
+ /**
2
+ * OTLP/JSON -> llm.call.
3
+ *
4
+ * Exported as `@agent-watch-ai/edge/otlp` for a backend that wants to decode
5
+ * agent telemetry itself. The AgentWatch platform has its own copy of this
6
+ * logic in `@agent-watch/otlp`, and the two have to be changed together:
7
+ * provider detection, the completed-request filter and the usage attribute
8
+ * names are the parts that silently disagree when they drift. All three now
9
+ * live in `constants/otlp.constants.ts`, which is the file to diff.
10
+ */
11
+ import { asArray, asRecord, firstNumber, firstString } from '../core/object.js';
12
+ import { buildLlmCall } from '../events/llm-call.js';
13
+ import { sha256Hex } from '../events/event-id.js';
14
+ import { AGENT_ID_KEYS, AGENT_TYPE_KEYS, BILLING_MODE_KEYS, CACHED_INPUT_TOKEN_KEYS, CACHE_CREATION_TOKEN_KEYS, CANONICAL_PROVIDER_NAMES, CLAUDE_SESSION_KEYS, CODEX_SESSION_KEYS, COST_KEYS, DEFAULT_SURFACE, DERIVED_CALL_ID_HEX_LENGTH, DERIVED_CALL_ID_PREFIX, DURATION_KEYS, ERROR_KEYS, EVENT_NAME_KEYS, EVENT_TYPE_KEYS, GEMINI_SYSTEM_VALUES, GENERIC_SESSION_KEYS, INPUT_TOKEN_KEYS, LOG_RECORDS_KEY, MODEL_KEYS, NANOS_PER_MILLI, OTLP_VALUE_KEYS, OUTPUT_TOKEN_KEYS, PROVIDER_SYSTEM_KEYS, REASONING_TOKEN_KEYS, REQUEST_ID_KEYS, RESOURCE_LOGS_KEY, RE_API_REQUEST, RE_CLAUDE_EVENT, RE_CODEX_COMPLETED, RE_CODEX_EVENT, RE_GEMINI_COMPLETED, RE_GEMINI_EVENT, RE_RESPONSE_COMPLETED, SCOPE_LOGS_KEY, SEQUENCE_KEYS, SPAN_ID_KEYS, THREAD_KEYS, TIMESTAMP_KEYS, TIME_NANO_KEYS, TOTAL_TOKEN_KEYS, TRACE_ID_KEYS, TURN_KEYS, UNSET_TIME_VALUES } from './constants/otlp.constants.js';
15
+ /**
16
+ * Normalize OTLP/JSON logs into the only atomic usage record: llm.call.
17
+ *
18
+ * Duplicate OTLP delivery is safe because call ids and event ids are stable;
19
+ * the backend must upsert on call_id, scoped by provider.
20
+ *
21
+ * @param payload - A decoded OTLP/JSON logs envelope.
22
+ * @param options - Correlation lookup and the batch's ingest time.
23
+ * @returns One llm.call per usable record, in envelope order.
24
+ */
25
+ export function normalizeOtlpLogs(payload, options = {}) {
26
+ const root = asRecord(payload);
27
+ const calls = [];
28
+ for (const resource of asArray(root?.[RESOURCE_LOGS_KEY])) {
29
+ const resourceRecord = asRecord(resource);
30
+ const resourceAttributes = attributes(asRecord(resourceRecord?.['resource'])?.['attributes']);
31
+ for (const scope of asArray(resourceRecord?.[SCOPE_LOGS_KEY])) {
32
+ for (const log of asArray(asRecord(scope)?.[LOG_RECORDS_KEY])) {
33
+ const normalized = normalizeOne(asRecord(log), resourceAttributes, options);
34
+ if (normalized)
35
+ calls.push(normalized);
36
+ }
37
+ }
38
+ }
39
+ return calls;
40
+ }
41
+ /**
42
+ * Normalize one log record, swallowing anything it throws.
43
+ *
44
+ * One malformed record must never abort the batch: every other call's usage and
45
+ * cost would silently vanish from the ledger with it.
46
+ *
47
+ * @param logRecord - The record, or undefined when the entry was not an object.
48
+ * @param resourceAttributes - Attributes inherited from the resource.
49
+ * @param options - Correlation lookup and the batch's ingest time.
50
+ * @returns The call, or undefined.
51
+ */
52
+ function normalizeOne(logRecord, resourceAttributes, options) {
53
+ if (!logRecord)
54
+ return undefined;
55
+ try {
56
+ return normalizeLogRecord(logRecord, { ...resourceAttributes, ...attributes(logRecord['attributes']) }, options);
57
+ }
58
+ catch {
59
+ return undefined;
60
+ }
61
+ }
62
+ /**
63
+ * Turn one recognized, completed provider request into an llm.call.
64
+ *
65
+ * @param log - The raw log record.
66
+ * @param attrs - Its attributes, merged with the resource's.
67
+ * @param options - Correlation lookup and the batch's ingest time.
68
+ * @returns The call, or undefined when the record is not one.
69
+ */
70
+ function normalizeLogRecord(log, attrs, options) {
71
+ const identity = readIdentity(log, attrs, options);
72
+ if (!identity)
73
+ return undefined;
74
+ const correlated = options.correlate?.({
75
+ provider: identity.provider,
76
+ sessionId: identity.sessionId,
77
+ turnId: identity.turnId,
78
+ threadId: identity.threadId,
79
+ agentId: identity.observedAgentId,
80
+ agentType: identity.observedAgentType,
81
+ endedAt: identity.endedAt
82
+ });
83
+ const productSessionId = correlated?.sessionId ?? identity.sessionId;
84
+ const productTurnId = correlated?.turnId ?? identity.turnId;
85
+ const durationMs = firstNumber(attrs, DURATION_KEYS);
86
+ return buildLlmCall({
87
+ provider: CANONICAL_PROVIDER_NAMES[identity.provider] ?? identity.provider,
88
+ surface: correlated?.surface ?? DEFAULT_SURFACE,
89
+ callId: identity.callId,
90
+ providerRequestId: identity.requestId,
91
+ // Only report the native scope when correlation actually replaced it.
92
+ providerSessionId: productSessionId !== identity.sessionId ? identity.sessionId : undefined,
93
+ providerTurnId: productTurnId !== identity.turnId ? identity.turnId : undefined,
94
+ sessionId: productSessionId,
95
+ turnId: productTurnId,
96
+ agentId: correlated?.agentId ?? identity.observedAgentId,
97
+ parentAgentId: correlated?.parentAgentId,
98
+ agentType: correlated?.agentType ?? identity.observedAgentType,
99
+ model: firstString(attrs, MODEL_KEYS),
100
+ billingMode: correlated?.billingMode ?? billingMode(attrs),
101
+ status: firstString(attrs, ERROR_KEYS) ? 'failed' : 'completed',
102
+ correlation: correlationLevel(correlated?.turnId, productTurnId),
103
+ usage: readUsage(attrs),
104
+ costUsd: firstNumber(attrs, COST_KEYS),
105
+ durationMs,
106
+ startedAt: derivedStartedAt(identity.endedAt, durationMs),
107
+ endedAt: identity.endedAt,
108
+ git: correlated?.git,
109
+ featureCandidates: correlated?.featureCandidates
110
+ });
111
+ }
112
+ /**
113
+ * Everything identifying a record, or undefined when it is not a usable one.
114
+ *
115
+ * @param log - The raw log record.
116
+ * @param attrs - Its merged attributes.
117
+ * @param options - Supplies the ingest-time fallback.
118
+ * @returns The identity, or undefined.
119
+ */
120
+ function readIdentity(log, attrs, options) {
121
+ const eventName = firstString(attrs, EVENT_NAME_KEYS) ?? bodyString(log['body']);
122
+ const eventType = firstString(attrs, EVENT_TYPE_KEYS);
123
+ const provider = detectProvider(eventName, eventType, attrs);
124
+ if (!provider || !isCompletedLlmRequest(provider, attrs, eventName, eventType))
125
+ return undefined;
126
+ const endedAt = otlpTimestamp(log) ?? firstString(attrs, TIMESTAMP_KEYS) ?? options.receivedAt;
127
+ if (!endedAt)
128
+ return undefined;
129
+ const sessionId = firstString(attrs, provider === 'claude' ? CLAUDE_SESSION_KEYS : GENERIC_SESSION_KEYS);
130
+ const turnId = firstString(attrs, TURN_KEYS);
131
+ const threadId = firstString(attrs, THREAD_KEYS);
132
+ const requestId = firstString(attrs, REQUEST_ID_KEYS);
133
+ const sequence = firstString(attrs, SEQUENCE_KEYS);
134
+ const traceId = firstString(log, TRACE_ID_KEYS);
135
+ const spanId = firstString(log, SPAN_ID_KEYS);
136
+ return {
137
+ provider,
138
+ endedAt,
139
+ sessionId,
140
+ turnId,
141
+ threadId,
142
+ requestId,
143
+ callId: requestId ?? traceIdAndSpan(traceId, spanId) ?? stableFallback(provider, sessionId, turnId, sequence, endedAt, log, attrs),
144
+ // Codex identifies a child agent by its thread rather than an agent id.
145
+ observedAgentId: firstString(attrs, AGENT_ID_KEYS) ?? (provider === 'codex' ? threadId : undefined),
146
+ observedAgentType: firstString(attrs, AGENT_TYPE_KEYS)
147
+ };
148
+ }
149
+ /**
150
+ * Token counts, under every name an agent gives them.
151
+ *
152
+ * @param attrs - Merged attributes.
153
+ * @returns The usage; every field undefined when nothing was reported.
154
+ */
155
+ function readUsage(attrs) {
156
+ return {
157
+ inputTokens: firstNumber(attrs, INPUT_TOKEN_KEYS),
158
+ cachedInputTokens: firstNumber(attrs, CACHED_INPUT_TOKEN_KEYS),
159
+ cacheCreationInputTokens: firstNumber(attrs, CACHE_CREATION_TOKEN_KEYS),
160
+ outputTokens: firstNumber(attrs, OUTPUT_TOKEN_KEYS),
161
+ reasoningOutputTokens: firstNumber(attrs, REASONING_TOKEN_KEYS),
162
+ totalTokens: firstNumber(attrs, TOTAL_TOKEN_KEYS)
163
+ };
164
+ }
165
+ /**
166
+ * Which agent produced a record.
167
+ *
168
+ * @param eventName - Its event name, when it has one.
169
+ * @param eventType - Its event type, when it has one.
170
+ * @param attrs - Merged attributes.
171
+ * @returns The provider, or undefined when the record is not an agent's.
172
+ */
173
+ function detectProvider(eventName, eventType, attrs) {
174
+ const names = `${eventName ?? ''} ${eventType ?? ''}`;
175
+ if (isGeminiLog(names, attrs))
176
+ return 'gemini';
177
+ // The `codex.` / `codex_` prefix is unambiguous — no other agent produces it —
178
+ // so a conversation or thread id is not needed to claim the record.
179
+ if (RE_CODEX_EVENT.test(names))
180
+ return 'codex';
181
+ // `response.completed` is generic; there a session attribute is what stops
182
+ // another provider's record being misclassified.
183
+ if (RE_RESPONSE_COMPLETED.test(names) && firstString(attrs, CODEX_SESSION_KEYS))
184
+ return 'codex';
185
+ if (RE_CLAUDE_EVENT.test(names) && firstString(attrs, CLAUDE_SESSION_KEYS))
186
+ return 'claude';
187
+ // Older Claude logs may use the bare event name. That generic alias must not
188
+ // steal a provider-qualified Codex record that also carries a compatibility
189
+ // session.id attribute.
190
+ const bareApiRequest = eventName === 'api_request' || eventType === 'api_request';
191
+ if (bareApiRequest && firstString(attrs, CLAUDE_SESSION_KEYS) && !firstString(attrs, CODEX_SESSION_KEYS))
192
+ return 'claude';
193
+ return undefined;
194
+ }
195
+ /**
196
+ * Whether a record is Gemini's.
197
+ *
198
+ * @param names - Event name and type, joined.
199
+ * @param attrs - Merged attributes.
200
+ * @returns True when it is.
201
+ */
202
+ function isGeminiLog(names, attrs) {
203
+ if (RE_GEMINI_EVENT.test(names))
204
+ return true;
205
+ const system = firstString(attrs, PROVIDER_SYSTEM_KEYS);
206
+ return system !== undefined && GEMINI_SYSTEM_VALUES.has(system);
207
+ }
208
+ /**
209
+ * Whether a record represents a request that actually consumed tokens.
210
+ *
211
+ * @param provider - The detected provider.
212
+ * @param attrs - Merged attributes.
213
+ * @param eventName - Its event name, when it has one.
214
+ * @param eventType - Its event type, when it has one.
215
+ * @returns True when the record should become an llm.call.
216
+ */
217
+ function isCompletedLlmRequest(provider, attrs, eventName, eventType) {
218
+ const names = `${eventName ?? ''} ${eventType ?? ''}`;
219
+ if (provider === 'claude')
220
+ return RE_API_REQUEST.test(names);
221
+ if (provider === 'gemini')
222
+ return isCompletedGeminiRequest(names, attrs);
223
+ return RE_CODEX_COMPLETED.test(names);
224
+ }
225
+ /**
226
+ * Whether a Gemini record is the *completion* half of a call.
227
+ *
228
+ * Gemini splits a call across a request record and a response record, and only
229
+ * the response carries token counts, so counting the request too would double
230
+ * every Gemini call. An error is still a call that happened. An unfamiliar name
231
+ * is admitted only when the record actually reports usage.
232
+ *
233
+ * @param names - Event name and type, joined.
234
+ * @param attrs - Merged attributes.
235
+ * @returns True when the record should become an llm.call.
236
+ */
237
+ function isCompletedGeminiRequest(names, attrs) {
238
+ if (RE_API_REQUEST.test(names))
239
+ return false;
240
+ if (RE_GEMINI_COMPLETED.test(names))
241
+ return true;
242
+ return names.trim() === '' || reportsUsage(attrs);
243
+ }
244
+ /**
245
+ * Whether any token count is present.
246
+ *
247
+ * @param attrs - Merged attributes.
248
+ * @returns True when at least one usage field was reported.
249
+ */
250
+ function reportsUsage(attrs) {
251
+ return Object.values(readUsage(attrs)).some((value) => value !== undefined);
252
+ }
253
+ /**
254
+ * Flatten an OTLP attribute list into a keyed record.
255
+ *
256
+ * @param value - The `attributes` array of a resource or record.
257
+ * @returns The flattened attributes.
258
+ */
259
+ function attributes(value) {
260
+ const out = {};
261
+ for (const item of asArray(value)) {
262
+ const record = asRecord(item);
263
+ const key = record?.['key'];
264
+ if (typeof key !== 'string' || key === '')
265
+ continue;
266
+ out[key] = otlpValue(record?.['value']);
267
+ }
268
+ return out;
269
+ }
270
+ /**
271
+ * Unwrap an OTLP AnyValue.
272
+ *
273
+ * @param value - The wrapped value.
274
+ * @returns The primitive, or undefined for an unsupported wrapper.
275
+ */
276
+ function otlpValue(value) {
277
+ const record = asRecord(value);
278
+ if (!record)
279
+ return undefined;
280
+ for (const key of OTLP_VALUE_KEYS) {
281
+ if (record[key] !== undefined)
282
+ return record[key];
283
+ }
284
+ return undefined;
285
+ }
286
+ /**
287
+ * A record's own timestamp, as an ISO string.
288
+ *
289
+ * proto3 JSON encodes an unset uint64 as `"0"`, which is not nullish: it has to
290
+ * fall through to the collector-observed time rather than become 1970 and push
291
+ * the call outside every aggregation window.
292
+ *
293
+ * @param log - The raw log record.
294
+ * @returns The timestamp, or undefined when it has no usable one.
295
+ */
296
+ function otlpTimestamp(log) {
297
+ const raw = TIME_NANO_KEYS.map((key) => log[key]).find((value) => (typeof value === 'string' || typeof value === 'number') && !UNSET_TIME_VALUES.has(value));
298
+ if (raw === undefined)
299
+ return undefined;
300
+ try {
301
+ return new Date(Number(BigInt(raw) / NANOS_PER_MILLI)).toISOString();
302
+ }
303
+ catch {
304
+ return undefined;
305
+ }
306
+ }
307
+ /**
308
+ * The `body.stringValue` of a record, when it has one.
309
+ *
310
+ * @param value - The record's body.
311
+ * @returns The string, or undefined.
312
+ */
313
+ function bodyString(value) {
314
+ const record = asRecord(value);
315
+ return typeof record?.['stringValue'] === 'string' ? record['stringValue'] : undefined;
316
+ }
317
+ /**
318
+ * Billing mode as the agent reported it.
319
+ *
320
+ * @param attrs - Merged attributes.
321
+ * @returns The mode, or undefined when none was reported.
322
+ */
323
+ function billingMode(attrs) {
324
+ const mode = firstString(attrs, BILLING_MODE_KEYS)?.toLowerCase();
325
+ if (!mode)
326
+ return undefined;
327
+ if (mode.includes('api'))
328
+ return 'api';
329
+ if (mode.includes('chatgpt') || mode.includes('subscription'))
330
+ return 'subscription';
331
+ return 'unknown';
332
+ }
333
+ /**
334
+ * How confidently a call was joined to a product turn.
335
+ *
336
+ * @param correlatedTurnId - Turn the backend resolved, when it did.
337
+ * @param productTurnId - Turn the call will carry.
338
+ * @returns The correlation level.
339
+ */
340
+ function correlationLevel(correlatedTurnId, productTurnId) {
341
+ if (correlatedTurnId)
342
+ return 'exact';
343
+ if (productTurnId)
344
+ return 'turn';
345
+ return 'session';
346
+ }
347
+ /**
348
+ * Start time derived from the end time and duration.
349
+ *
350
+ * `endedAt` can be an unparseable attribute string, and NaN arithmetic would
351
+ * make toISOString() throw — so a start is derived only from a real time.
352
+ *
353
+ * @param endedAt - The call's end time.
354
+ * @param durationMs - Its duration, when reported.
355
+ * @returns The start time, or undefined.
356
+ */
357
+ function derivedStartedAt(endedAt, durationMs) {
358
+ if (durationMs === undefined)
359
+ return undefined;
360
+ const ended = Date.parse(endedAt);
361
+ if (!Number.isFinite(ended))
362
+ return undefined;
363
+ return new Date(ended - durationMs).toISOString();
364
+ }
365
+ /**
366
+ * A call id built from the trace context.
367
+ *
368
+ * @param traceId - Trace id, when present.
369
+ * @param spanId - Span id, when present.
370
+ * @returns The composed id, or undefined when there is no trace at all.
371
+ */
372
+ function traceIdAndSpan(traceId, spanId) {
373
+ if (!traceId)
374
+ return undefined;
375
+ return spanId ? `${traceId}:${spanId}` : traceId;
376
+ }
377
+ /**
378
+ * A deterministic call id for a record that carries no identifier at all.
379
+ *
380
+ * The raw nanosecond timestamp and the full canonical record identity both go
381
+ * in: `endedAt` is millisecond precision and is not unique for concurrent
382
+ * calls, so hashing it alone would collapse two real calls into one.
383
+ *
384
+ * @param provider - Detected provider.
385
+ * @param sessionId - Session, when known.
386
+ * @param turnId - Turn, when known.
387
+ * @param sequence - Provider sequence number, when reported.
388
+ * @param endedAt - Resolved end time.
389
+ * @param log - The raw log record.
390
+ * @param attrs - Merged attributes.
391
+ * @returns The derived id.
392
+ */
393
+ function stableFallback(provider, sessionId, turnId, sequence, endedAt, log, attrs) {
394
+ const recordIdentity = {
395
+ timeUnixNano: log['timeUnixNano'],
396
+ observedTimeUnixNano: log['observedTimeUnixNano'],
397
+ severityNumber: log['severityNumber'],
398
+ severityText: log['severityText'],
399
+ body: log['body'],
400
+ attrs: Object.fromEntries(Object.entries(attrs).sort(([a], [b]) => a.localeCompare(b)))
401
+ };
402
+ const digest = sha256Hex(JSON.stringify([provider, sessionId, turnId, sequence, endedAt, recordIdentity]));
403
+ return `${DERIVED_CALL_ID_PREFIX}${digest.slice(0, DERIVED_CALL_ID_HEX_LENGTH)}`;
404
+ }
@@ -0,0 +1,69 @@
1
+ import type { UnknownRecord } from '../../core/types/core.types.js';
2
+ import type { EventGit, FeatureCandidate, UsageBillingMode } from '../../events/types/events.types.js';
3
+ import type { LlmCallUsage } from '../../events/types/llm-call.types.js';
4
+ import type { OTLP_HTTP_SIGNALS } from '../constants/otlp.constants.js';
5
+ /** A flattened OTLP attribute bag. */
6
+ export type Attributes = UnknownRecord;
7
+ /** Providers whose native telemetry the normalizer understands. */
8
+ export type OtlpProvider = 'claude' | 'codex' | 'gemini';
9
+ /** What the backend knows about the scope a call belongs to. */
10
+ export interface OtlpCorrelationContext {
11
+ /** Root product scope resolved from prompt/span/spawn edges. */
12
+ readonly sessionId?: string;
13
+ readonly turnId?: string;
14
+ readonly surface?: string;
15
+ readonly billingMode?: UsageBillingMode;
16
+ readonly agentId?: string;
17
+ readonly parentAgentId?: string;
18
+ readonly agentType?: string;
19
+ readonly git?: Pick<EventGit, 'repository' | 'branch' | 'commit'>;
20
+ readonly featureCandidates?: readonly FeatureCandidate[];
21
+ }
22
+ /** The identity a correlation lookup is given. */
23
+ export interface OtlpCallIdentity {
24
+ readonly provider: OtlpProvider;
25
+ readonly sessionId?: string;
26
+ readonly turnId?: string;
27
+ readonly threadId?: string;
28
+ readonly agentId?: string;
29
+ readonly agentType?: string;
30
+ readonly endedAt: string;
31
+ }
32
+ export interface NormalizeOtlpOptions {
33
+ /**
34
+ * Backend lookup populated from hook summaries and agent lifecycle/spawn
35
+ * telemetry. Intentionally synchronous, so a whole batch can be normalized
36
+ * inside one database transaction.
37
+ */
38
+ readonly correlate?: (identity: OtlpCallIdentity) => OtlpCorrelationContext | undefined;
39
+ /**
40
+ * Ingest time of the batch, used for records that carry no usable timestamp
41
+ * of their own. Epoch 0 is never fabricated — it would push the call outside
42
+ * every aggregation window — so without this fallback such records are
43
+ * skipped.
44
+ */
45
+ readonly receivedAt?: string;
46
+ }
47
+ /** Identity fields read off one log record before correlation. */
48
+ export interface RecordIdentity {
49
+ readonly provider: OtlpProvider;
50
+ readonly endedAt: string;
51
+ readonly sessionId?: string;
52
+ readonly turnId?: string;
53
+ readonly threadId?: string;
54
+ readonly requestId?: string;
55
+ readonly callId: string;
56
+ readonly observedAgentId?: string;
57
+ readonly observedAgentType?: string;
58
+ }
59
+ /** Usage as read from OTLP attributes. */
60
+ export type OtlpUsage = LlmCallUsage;
61
+ /** OTLP/HTTP signal name. */
62
+ export type OtlpHttpSignal = (typeof OTLP_HTTP_SIGNALS)[number];
63
+ /** Outcome of decoding an OTLP/JSON request body. */
64
+ export type DecodedOtlpJson = {
65
+ readonly ok: true;
66
+ readonly payload: UnknownRecord;
67
+ } | {
68
+ readonly ok: false;
69
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { CanonicalEventType } from '../../events/types/events.types.js';
2
+ /** Stage names, used in the flow definition and in its debug trace. */
3
+ export declare const STAGE_RESOLVE_CONTEXT = "resolve-context";
4
+ export declare const STAGE_PARSE_EVENTS = "parse-events";
5
+ export declare const STAGE_ENFORCE = "enforce";
6
+ export declare const STAGE_ENRICH = "enrich";
7
+ export declare const STAGE_TRACK_TURN = "track-turn";
8
+ export declare const STAGE_DELIVER = "deliver";
9
+ export declare const STAGE_SNAPSHOT = "repo-snapshot";
10
+ /** Reasons a stage ends the flow early. */
11
+ export declare const STOP_NO_EVENTS = "provider produced no canonical events";
12
+ export declare const STOP_DRY_RUN = "dry run: nothing delivered";
13
+ export declare const STOP_NO_SNAPSHOT = "no closed turn, or git capture is off";
14
+ /**
15
+ * Canonical event type whose presence makes a payload the turn's gate.
16
+ *
17
+ * Typed as the vocabulary rather than as a bare string: untyped, a typo here
18
+ * type-checks and disables the gate permanently — every allow path is silent by
19
+ * design, so nothing would ever surface it.
20
+ */
21
+ export declare const PROMPT_SUBMITTED_TYPE: CanonicalEventType;
22
+ /** Payload key most agents report their working directory under. */
23
+ export declare const PAYLOAD_CWD_KEY = "cwd";
@@ -0,0 +1,22 @@
1
+ /** Stage names, used in the flow definition and in its debug trace. */
2
+ export const STAGE_RESOLVE_CONTEXT = 'resolve-context';
3
+ export const STAGE_PARSE_EVENTS = 'parse-events';
4
+ export const STAGE_ENFORCE = 'enforce';
5
+ export const STAGE_ENRICH = 'enrich';
6
+ export const STAGE_TRACK_TURN = 'track-turn';
7
+ export const STAGE_DELIVER = 'deliver';
8
+ export const STAGE_SNAPSHOT = 'repo-snapshot';
9
+ /** Reasons a stage ends the flow early. */
10
+ export const STOP_NO_EVENTS = 'provider produced no canonical events';
11
+ export const STOP_DRY_RUN = 'dry run: nothing delivered';
12
+ export const STOP_NO_SNAPSHOT = 'no closed turn, or git capture is off';
13
+ /**
14
+ * Canonical event type whose presence makes a payload the turn's gate.
15
+ *
16
+ * Typed as the vocabulary rather than as a bare string: untyped, a typo here
17
+ * type-checks and disables the gate permanently — every allow path is silent by
18
+ * design, so nothing would ever surface it.
19
+ */
20
+ export const PROMPT_SUBMITTED_TYPE = 'prompt.submitted';
21
+ /** Payload key most agents report their working directory under. */
22
+ export const PAYLOAD_CWD_KEY = 'cwd';
@@ -0,0 +1,14 @@
1
+ import type { FlowResult } from '../core/types/core.types.js';
2
+ import type { HookPipelineInput, HookPipelineState } from './types/pipeline.types.js';
3
+ export type { HookPipelineInput, HookPipelineState } from './types/pipeline.types.js';
4
+ /**
5
+ * Run one hook payload through the flow.
6
+ *
7
+ * Never throws: a stage that fails ends the flow with whatever the last
8
+ * successful stage produced, because the caller is a hook that must answer the
9
+ * coding agent either way.
10
+ *
11
+ * @param input - Provider, environment, payload and dry-run flag.
12
+ * @returns The final state and where the flow stopped.
13
+ */
14
+ export declare function runHookPipeline(input: HookPipelineInput): Promise<FlowResult<HookPipelineState>>;