@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,59 @@
1
+ import type { AgentWatchConfig } from '../../config/types/config.types.js';
2
+ import type { AgentWatchPaths } from '../../storage/types/storage.types.js';
3
+ /**
4
+ * These types are hand-written and the validators in `schemas/` are annotated
5
+ * with them — the reverse of the `schemas -> types` direction AGENTS.md states,
6
+ * and deliberately so: the annotation is a compile-time check that the union
7
+ * here and the schema there describe the same thing, which `z.infer` cannot give
8
+ * for `readonly` fields. See the schema file's header before "fixing" it.
9
+ */
10
+ /**
11
+ * What the platform answered, reduced to what the hook path acts on.
12
+ *
13
+ * A union rather than one shape with an optional message, for the reason the
14
+ * platform's own contract gives: a refusal always carries the sentence that
15
+ * explains it, and an allow has nothing to say. Written as optionals, a refusal
16
+ * with nothing to show the developer would type-check.
17
+ */
18
+ export type EnforcementDecision = {
19
+ readonly decision: 'allow';
20
+ } | {
21
+ readonly decision: 'block';
22
+ readonly message: string;
23
+ };
24
+ /**
25
+ * A decision as it arrives, before the caching question is settled.
26
+ *
27
+ * `cache_ttl_ms` is the platform saying how long this particular answer may be
28
+ * reused, which it knows and this side does not: how close the scope came to its
29
+ * cap. Optional because a platform that predates the field simply omits it, and
30
+ * this side then falls back to its own configured TTL.
31
+ */
32
+ export type AnsweredDecision = EnforcementDecision & {
33
+ readonly cacheTtlMs?: number;
34
+ };
35
+ /** One decision as the local cache holds it, with the deadline it expires at. */
36
+ export interface CachedDecision {
37
+ readonly decision: EnforcementDecision;
38
+ readonly expiresAt: number;
39
+ }
40
+ /** One request to the decision endpoint. */
41
+ export interface DecisionRequest {
42
+ readonly url: string;
43
+ readonly token: string;
44
+ /** The same identity `turn.summary.developer_id` carries. */
45
+ readonly developerId: string;
46
+ readonly installationId?: string;
47
+ readonly timeoutMs: number;
48
+ /** Injected by tests; the real fetch otherwise. */
49
+ readonly fetchFn?: typeof fetch;
50
+ }
51
+ /** Everything the check needs to answer without touching ambient state. */
52
+ export interface EnforcementOptions {
53
+ readonly config: AgentWatchConfig;
54
+ readonly paths: AgentWatchPaths;
55
+ /** The identity to ask about, or undefined when this machine has none. */
56
+ readonly developerId?: string;
57
+ readonly now: () => Date;
58
+ readonly fetchFn?: typeof fetch;
59
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ /** Protocols a backend URL may use. */
2
+ export declare const ALLOWED_PROTOCOLS: ReadonlySet<string>;
3
+ /** Prompts the manual provider asks when it has no value yet. */
4
+ export declare const ENDPOINT_PROMPT = "AgentWatch backend URL: ";
5
+ export declare const TOKEN_PROMPT = "API token (optional, press Enter to skip): ";
6
+ export declare const RE_TRAILING_SLASHES: RegExp;
@@ -0,0 +1,6 @@
1
+ /** Protocols a backend URL may use. */
2
+ export const ALLOWED_PROTOCOLS = new Set(['https:', 'http:']);
3
+ /** Prompts the manual provider asks when it has no value yet. */
4
+ export const ENDPOINT_PROMPT = 'AgentWatch backend URL: ';
5
+ export const TOKEN_PROMPT = 'API token (optional, press Enter to skip): ';
6
+ export const RE_TRAILING_SLASHES = /\/+$/;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The enrollment contract. Kept as its own module so `setup` depends on the
3
+ * abstraction rather than on the manual implementation it happens to ship with.
4
+ */
5
+ export type { EnrollmentInput, EnrollmentProvider, EnrollmentResult } from './types/enrollment.types.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Acquiring an endpoint and credentials. The MVP ships the manual provider; the
3
+ * abstraction is what lets a future remote enrollment slot in without touching
4
+ * setup.
5
+ */
6
+ export type { EnrollmentInput, EnrollmentProvider, EnrollmentResult } from './types/enrollment.types.js';
7
+ export { ManualEnrollmentProvider } from './manual-enrollment.js';
@@ -0,0 +1 @@
1
+ export { ManualEnrollmentProvider } from './manual-enrollment.js';
@@ -0,0 +1,32 @@
1
+ import type { EnrollmentInput, EnrollmentProvider, EnrollmentResult } from './types/enrollment.types.js';
2
+ /**
3
+ * Enrollment by asking the developer.
4
+ *
5
+ * Fails loudly rather than guessing: an install pointed at the wrong backend
6
+ * would send this repository's prompts and tool output somewhere the user never
7
+ * chose, so a missing endpoint is an error, not a default.
8
+ */
9
+ export declare class ManualEnrollmentProvider implements EnrollmentProvider {
10
+ /**
11
+ * Resolve the backend endpoint and token.
12
+ *
13
+ * @param input - Flags, existing configuration and the interactive prompt.
14
+ * @returns The endpoint and token to configure.
15
+ * @throws When no usable endpoint can be obtained.
16
+ */
17
+ enroll(input: EnrollmentInput): Promise<EnrollmentResult>;
18
+ /**
19
+ * The endpoint from the flag, the existing config, or the prompt.
20
+ *
21
+ * @param input - Enrollment input.
22
+ * @returns The endpoint, or undefined when there is none.
23
+ */
24
+ private resolveEndpoint;
25
+ /**
26
+ * The token from the flag, the existing config, or the prompt.
27
+ *
28
+ * @param input - Enrollment input.
29
+ * @returns The token, or undefined when the backend needs none.
30
+ */
31
+ private resolveToken;
32
+ }
@@ -0,0 +1,72 @@
1
+ import { ALLOWED_PROTOCOLS, ENDPOINT_PROMPT, RE_TRAILING_SLASHES, TOKEN_PROMPT } from './constants/enrollment.constants.js';
2
+ /**
3
+ * Enrollment by asking the developer.
4
+ *
5
+ * Fails loudly rather than guessing: an install pointed at the wrong backend
6
+ * would send this repository's prompts and tool output somewhere the user never
7
+ * chose, so a missing endpoint is an error, not a default.
8
+ */
9
+ export class ManualEnrollmentProvider {
10
+ /**
11
+ * Resolve the backend endpoint and token.
12
+ *
13
+ * @param input - Flags, existing configuration and the interactive prompt.
14
+ * @returns The endpoint and token to configure.
15
+ * @throws When no usable endpoint can be obtained.
16
+ */
17
+ async enroll(input) {
18
+ if (input.setupUrl) {
19
+ throw new Error('enrollment URLs are not supported yet; pass the backend base URL via --endpoint or the prompt');
20
+ }
21
+ const endpoint = await this.resolveEndpoint(input);
22
+ if (!endpoint) {
23
+ throw new Error('no backend endpoint provided (use --endpoint or run interactively)');
24
+ }
25
+ assertHttpUrl(endpoint);
26
+ return { endpoint: endpoint.replace(RE_TRAILING_SLASHES, ''), token: await this.resolveToken(input) };
27
+ }
28
+ /**
29
+ * The endpoint from the flag, the existing config, or the prompt.
30
+ *
31
+ * @param input - Enrollment input.
32
+ * @returns The endpoint, or undefined when there is none.
33
+ */
34
+ async resolveEndpoint(input) {
35
+ if (input.endpoint)
36
+ return input.endpoint;
37
+ if (!input.ask)
38
+ return undefined;
39
+ return (await input.ask(ENDPOINT_PROMPT)).trim();
40
+ }
41
+ /**
42
+ * The token from the flag, the existing config, or the prompt.
43
+ *
44
+ * @param input - Enrollment input.
45
+ * @returns The token, or undefined when the backend needs none.
46
+ */
47
+ async resolveToken(input) {
48
+ if (input.token !== undefined)
49
+ return input.token;
50
+ if (!input.ask)
51
+ return undefined;
52
+ return (await input.ask(TOKEN_PROMPT)).trim() || undefined;
53
+ }
54
+ }
55
+ /**
56
+ * Reject anything that is not an http(s) URL.
57
+ *
58
+ * @param value - The endpoint as entered.
59
+ * @throws When the value is not a usable http(s) URL.
60
+ */
61
+ function assertHttpUrl(value) {
62
+ let url;
63
+ try {
64
+ url = new URL(value);
65
+ }
66
+ catch {
67
+ throw new Error(`invalid URL: ${value}`);
68
+ }
69
+ if (!ALLOWED_PROTOCOLS.has(url.protocol)) {
70
+ throw new Error(`backend URL must be http(s), got ${url.protocol}`);
71
+ }
72
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Endpoint and credential acquisition.
3
+ *
4
+ * The MVP ships a manual provider — the user types a backend URL — and a future
5
+ * RemoteEnrollmentProvider will implement `agentwatch setup <enrollment-url>`
6
+ * (fetch org config, register the device, receive installation credentials)
7
+ * without setup having to change.
8
+ */
9
+ export interface EnrollmentInput {
10
+ /** URL passed to `agentwatch setup`, when any. */
11
+ readonly setupUrl?: string;
12
+ /** --endpoint flag, or the already-configured endpoint. */
13
+ readonly endpoint?: string;
14
+ /** --token flag, or the already-configured token. */
15
+ readonly token?: string;
16
+ /** Interactive prompt; undefined in non-interactive runs. */
17
+ readonly ask?: (question: string) => Promise<string>;
18
+ }
19
+ export interface EnrollmentResult {
20
+ readonly endpoint: string;
21
+ readonly token?: string;
22
+ }
23
+ export interface EnrollmentProvider {
24
+ enroll(input: EnrollmentInput): Promise<EnrollmentResult>;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The canonical event vocabulary and shape.
3
+ *
4
+ * Kept as the module's stable entry point: the vocabulary lives in
5
+ * `constants/events.constants.ts` and the shape in `types/events.types.ts`, so
6
+ * a reader looking for "what can happen" and a reader looking for "what a
7
+ * record looks like" each land in one file.
8
+ */
9
+ 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';
10
+ export type { AgentWatchEvent, CanonicalEventType, ContentEvidence, EventAi, EventGit, EventIdInput, EventPatch, EventSession, EventTool, EventUsage, FeatureCandidate, InternalHookEventType, ProductEventType, UsageBillingMode, UsageSource } from './types/events.types.js';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The canonical event vocabulary and shape.
3
+ *
4
+ * Kept as the module's stable entry point: the vocabulary lives in
5
+ * `constants/events.constants.ts` and the shape in `types/events.types.ts`, so
6
+ * a reader looking for "what can happen" and a reader looking for "what a
7
+ * record looks like" each land in one file.
8
+ */
9
+ 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';
@@ -0,0 +1,14 @@
1
+ /** Characters that must be escaped to embed a literal path in a pattern. */
2
+ export declare const RE_REGEXP_METACHARACTERS: RegExp;
3
+ /**
4
+ * Lookahead marking the end of a bare directory reference, so `/x/repo` does
5
+ * not fire inside `/x/repository`.
6
+ */
7
+ export declare const PATH_BOUNDARY_LOOKAHEAD = "(?=[\\s\"'`)\\]}>,;:]|$)";
8
+ /** Replacement for the developer's home directory inside captured text. */
9
+ export declare const HOME_PLACEHOLDER = "~";
10
+ export declare const HOME_PLACEHOLDER_PREFIX: string;
11
+ /** Replacement for the repository root itself (as opposed to a path under it). */
12
+ export declare const REPO_ROOT_PLACEHOLDER = ".";
13
+ /** Metadata key adapters use for the single primary file of a tool call. */
14
+ export declare const FILE_PATH_METADATA_KEY = "filePath";
@@ -0,0 +1,15 @@
1
+ import path from 'node:path';
2
+ /** Characters that must be escaped to embed a literal path in a pattern. */
3
+ export const RE_REGEXP_METACHARACTERS = /[.*+?^${}()|[\]\\]/g;
4
+ /**
5
+ * Lookahead marking the end of a bare directory reference, so `/x/repo` does
6
+ * not fire inside `/x/repository`.
7
+ */
8
+ export const PATH_BOUNDARY_LOOKAHEAD = '(?=[\\s"\'`)\\]}>,;:]|$)';
9
+ /** Replacement for the developer's home directory inside captured text. */
10
+ export const HOME_PLACEHOLDER = '~';
11
+ export const HOME_PLACEHOLDER_PREFIX = `~${path.sep}`;
12
+ /** Replacement for the repository root itself (as opposed to a path under it). */
13
+ export const REPO_ROOT_PLACEHOLDER = '.';
14
+ /** Metadata key adapters use for the single primary file of a tool call. */
15
+ export const FILE_PATH_METADATA_KEY = 'filePath';
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The canonical event vocabulary. Provider adapters translate native hook
3
+ * payloads into these types; nothing outside this list is ever emitted.
4
+ */
5
+ /**
6
+ * Hook lifecycle events are an internal assembly format. They are consumed
7
+ * locally to build a turn summary and must never be exposed as product
8
+ * records. The public data model is deliberately limited to
9
+ * PRODUCT_EVENT_TYPES below.
10
+ */
11
+ export declare const INTERNAL_HOOK_EVENT_TYPES: readonly ["session.started", "session.ended", "prompt.submitted", "tool.started", "tool.completed", "tool.failed", "permission.requested", "file.read", "file.edited", "shell.started", "shell.completed", "mcp.started", "mcp.completed", "subagent.started", "subagent.completed", "generation.completed", "compaction.started", "compaction.completed", "agent.error", "agent.other"];
12
+ /**
13
+ * The record types accepted by the AgentWatch product backend.
14
+ *
15
+ * `repo.snapshot` joined the two spend records because the backend's feature
16
+ * layer is an overlay on work items, and a team with no tracker connected has
17
+ * none — the branches on a developer's machine are then the only evidence that
18
+ * a piece of work exists. It carries no usage and is not accounted.
19
+ */
20
+ export declare const PRODUCT_EVENT_TYPES: readonly ["llm.call", "turn.summary", "repo.snapshot"];
21
+ export declare const CANONICAL_EVENT_TYPES: readonly ["session.started", "session.ended", "prompt.submitted", "tool.started", "tool.completed", "tool.failed", "permission.requested", "file.read", "file.edited", "shell.started", "shell.completed", "mcp.started", "mcp.completed", "subagent.started", "subagent.completed", "generation.completed", "compaction.started", "compaction.completed", "agent.error", "agent.other", "llm.call", "turn.summary", "repo.snapshot"];
22
+ /** O(1) membership for the hot path: queue drain checks this per entry. */
23
+ export declare const PRODUCT_EVENT_TYPE_SET: ReadonlySet<string>;
24
+ /** Canonical event types that close a turn. */
25
+ export declare const TURN_CLOSING_EVENT_TYPE = "generation.completed";
26
+ /** Schema version stamped on every canonical event. */
27
+ export declare const EVENT_SCHEMA_VERSION = "1";
28
+ /** Prefix on every derived event id. */
29
+ export declare const EVENT_ID_PREFIX = "evt_";
30
+ /**
31
+ * Hex characters kept from the id digest. 160 bits is collision-free at any
32
+ * volume a single developer machine can produce, and keeps the id short enough
33
+ * to be a queue filename.
34
+ */
35
+ export declare const EVENT_ID_HEX_LENGTH = 40;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The canonical event vocabulary. Provider adapters translate native hook
3
+ * payloads into these types; nothing outside this list is ever emitted.
4
+ */
5
+ /**
6
+ * Hook lifecycle events are an internal assembly format. They are consumed
7
+ * locally to build a turn summary and must never be exposed as product
8
+ * records. The public data model is deliberately limited to
9
+ * PRODUCT_EVENT_TYPES below.
10
+ */
11
+ export const INTERNAL_HOOK_EVENT_TYPES = [
12
+ 'session.started',
13
+ 'session.ended',
14
+ 'prompt.submitted',
15
+ 'tool.started',
16
+ 'tool.completed',
17
+ 'tool.failed',
18
+ 'permission.requested',
19
+ 'file.read',
20
+ 'file.edited',
21
+ 'shell.started',
22
+ 'shell.completed',
23
+ 'mcp.started',
24
+ 'mcp.completed',
25
+ 'subagent.started',
26
+ 'subagent.completed',
27
+ 'generation.completed',
28
+ 'compaction.started',
29
+ 'compaction.completed',
30
+ 'agent.error',
31
+ /** Provider event we don't model yet; preserved as metadata instead of dropped. */
32
+ 'agent.other'
33
+ ];
34
+ /**
35
+ * The record types accepted by the AgentWatch product backend.
36
+ *
37
+ * `repo.snapshot` joined the two spend records because the backend's feature
38
+ * layer is an overlay on work items, and a team with no tracker connected has
39
+ * none — the branches on a developer's machine are then the only evidence that
40
+ * a piece of work exists. It carries no usage and is not accounted.
41
+ */
42
+ export const PRODUCT_EVENT_TYPES = ['llm.call', 'turn.summary', 'repo.snapshot'];
43
+ export const CANONICAL_EVENT_TYPES = [...INTERNAL_HOOK_EVENT_TYPES, ...PRODUCT_EVENT_TYPES];
44
+ /** O(1) membership for the hot path: queue drain checks this per entry. */
45
+ export const PRODUCT_EVENT_TYPE_SET = new Set(PRODUCT_EVENT_TYPES);
46
+ /** Canonical event types that close a turn. */
47
+ export const TURN_CLOSING_EVENT_TYPE = 'generation.completed';
48
+ /** Schema version stamped on every canonical event. */
49
+ export const EVENT_SCHEMA_VERSION = '1';
50
+ /** Prefix on every derived event id. */
51
+ export const EVENT_ID_PREFIX = 'evt_';
52
+ /**
53
+ * Hex characters kept from the id digest. 160 bits is collision-free at any
54
+ * volume a single developer machine can produce, and keeps the id short enough
55
+ * to be a queue filename.
56
+ */
57
+ export const EVENT_ID_HEX_LENGTH = 40;
@@ -0,0 +1,16 @@
1
+ import type { AgentWatchEvent } from './types/events.types.js';
2
+ import type { EnrichOptions } from './types/enrich.types.js';
3
+ export type { EnrichOptions, PathRewriter } from './types/enrich.types.js';
4
+ /**
5
+ * Attach development context to canonical events and scrub them.
6
+ *
7
+ * Four things happen, in this order, and each one is a pure function of the
8
+ * previous: resolve where the work happened (git), derive what it was about
9
+ * (ticket evidence), rewrite machine-specific paths out of captured content,
10
+ * and sanitize. Failures degrade to less context, never to a failed hook.
11
+ *
12
+ * @param events - Canonical events from a provider adapter.
13
+ * @param options - Effective config, working directory and home.
14
+ * @returns Enriched, sanitized events in the same order.
15
+ */
16
+ export declare function enrichEvents(events: readonly AgentWatchEvent[], options: EnrichOptions): Promise<AgentWatchEvent[]>;
@@ -0,0 +1,226 @@
1
+ import path from 'node:path';
2
+ import { isRecord } from '../core/object.js';
3
+ import { collectGitContext } from '../git/git-context.js';
4
+ import { featureCandidatesFromBranch } from '../feature/ticket-candidates.js';
5
+ import { sanitizeValue } from '../privacy/sanitizer.js';
6
+ import { TURN_CLOSING_EVENT_TYPE } from './constants/events.constants.js';
7
+ import { FILE_PATH_METADATA_KEY, HOME_PLACEHOLDER, HOME_PLACEHOLDER_PREFIX, PATH_BOUNDARY_LOOKAHEAD, REPO_ROOT_PLACEHOLDER, RE_REGEXP_METACHARACTERS } from './constants/enrich.constants.js';
8
+ /**
9
+ * Attach development context to canonical events and scrub them.
10
+ *
11
+ * Four things happen, in this order, and each one is a pure function of the
12
+ * previous: resolve where the work happened (git), derive what it was about
13
+ * (ticket evidence), rewrite machine-specific paths out of captured content,
14
+ * and sanitize. Failures degrade to less context, never to a failed hook.
15
+ *
16
+ * @param events - Canonical events from a provider adapter.
17
+ * @param options - Effective config, working directory and home.
18
+ * @returns Enriched, sanitized events in the same order.
19
+ */
20
+ export async function enrichEvents(events, options) {
21
+ if (events.length === 0)
22
+ return [...events];
23
+ const git = await resolveGitContext(events, options);
24
+ const featureCandidates = featureCandidatesFromBranch(git.branch);
25
+ const rewriter = buildPathRewriter(git.repositoryRoot, options.home);
26
+ const enriched = [];
27
+ for (const event of events) {
28
+ enriched.push(sanitizeValue(enrichEvent(event, { git, featureCandidates, rewriter, options })));
29
+ }
30
+ return enriched;
31
+ }
32
+ /**
33
+ * Repository context for this batch, at the cheapest sufficient depth.
34
+ *
35
+ * Full context (branch, commit, remote, status) costs up to five git processes
36
+ * and is only consumed when a turn closes — the summary reads it off the Stop
37
+ * event. Every other hook runs on the agent's critical path, often once per
38
+ * tool call, and needs nothing but the repository root for path rewriting.
39
+ *
40
+ * @param events - The batch being enriched.
41
+ * @param options - Effective config and working directory.
42
+ * @returns The context, or an empty one when git is unavailable or disabled.
43
+ */
44
+ async function resolveGitContext(events, options) {
45
+ if (!options.config.capture.git)
46
+ return {};
47
+ const needsFullGit = events.some((event) => event.event.type === TURN_CLOSING_EVENT_TYPE);
48
+ try {
49
+ return await collectGitContext({
50
+ cwd: options.cwd,
51
+ includeChangedFiles: options.config.capture.files && needsFullGit,
52
+ timeoutMs: options.gitTimeoutMs,
53
+ rootOnly: !needsFullGit
54
+ });
55
+ }
56
+ catch {
57
+ return {};
58
+ }
59
+ }
60
+ /**
61
+ * One event with development context attached.
62
+ *
63
+ * @param event - The event to enrich; left untouched.
64
+ * @param context - Batch-wide resolved context.
65
+ * @returns A new event carrying the context.
66
+ */
67
+ function enrichEvent(event, context) {
68
+ const { git, featureCandidates, options } = context;
69
+ return {
70
+ ...event,
71
+ developer: options.config.installationId
72
+ ? { ...event.developer, installationId: options.config.installationId }
73
+ : event.developer,
74
+ git: git.repositoryRoot
75
+ ? {
76
+ repository: git.repository,
77
+ repositoryHash: git.repositoryHash,
78
+ remote: git.remote,
79
+ branch: git.branch,
80
+ commit: git.commit,
81
+ // Relative to the repo root: absolute paths leak usernames.
82
+ workingDirectory: relativize(git.repositoryRoot, options.cwd),
83
+ changedFiles: git.changedFiles
84
+ }
85
+ : event.git,
86
+ feature: featureCandidates.length > 0 ? { candidates: featureCandidates } : event.feature,
87
+ metadata: enrichMetadata(event.metadata, context)
88
+ };
89
+ }
90
+ /**
91
+ * Metadata with its file path made safe and every path prefix rewritten.
92
+ *
93
+ * @param metadata - Adapter-produced metadata, or undefined.
94
+ * @param context - Batch-wide resolved context.
95
+ * @returns New metadata, or undefined when there was none.
96
+ */
97
+ function enrichMetadata(metadata, context) {
98
+ if (!metadata)
99
+ return undefined;
100
+ const filePath = metadata[FILE_PATH_METADATA_KEY];
101
+ const withSafePath = typeof filePath === 'string'
102
+ ? { ...metadata, [FILE_PATH_METADATA_KEY]: toSafePath(filePath, context.git.repositoryRoot) }
103
+ : metadata;
104
+ return rewritePathsDeep(withSafePath, context.rewriter);
105
+ }
106
+ /**
107
+ * Pre-compile the path substitutions for one enrichment pass.
108
+ *
109
+ * Repo-rooted paths become repo-relative and the home directory becomes `~`,
110
+ * so usernames and machine layout do not leak through captured tool input,
111
+ * output or shell commands. Textual and best-effort by design — an arbitrary
112
+ * string can still embed a path we cannot recognize.
113
+ *
114
+ * @param repositoryRoot - Repository root, when inside one.
115
+ * @param home - Developer home directory, when known.
116
+ * @returns The rewriter; its rule list is empty when there is nothing to hide.
117
+ */
118
+ function buildPathRewriter(repositoryRoot, home) {
119
+ const rules = [];
120
+ // Order matters: the prefixed form is matched first, so `/repo/src/a.ts`
121
+ // becomes `src/a.ts` rather than `./src/a.ts`.
122
+ if (repositoryRoot) {
123
+ rules.push({ pattern: prefixPattern(repositoryRoot + path.sep), replacement: '' });
124
+ rules.push({ pattern: exactPattern(repositoryRoot), replacement: REPO_ROOT_PLACEHOLDER });
125
+ }
126
+ if (home) {
127
+ rules.push({ pattern: prefixPattern(home + path.sep), replacement: HOME_PLACEHOLDER_PREFIX });
128
+ rules.push({ pattern: exactPattern(home), replacement: HOME_PLACEHOLDER });
129
+ }
130
+ return { rules };
131
+ }
132
+ /**
133
+ * Rewrite paths in every string of a value tree.
134
+ *
135
+ * @param value - Node of any shape.
136
+ * @param rewriter - Pre-compiled substitutions.
137
+ * @returns A rewritten copy.
138
+ */
139
+ function rewritePathsDeep(value, rewriter) {
140
+ if (rewriter.rules.length === 0)
141
+ return value;
142
+ if (typeof value === 'string')
143
+ return rewriteText(value, rewriter);
144
+ if (Array.isArray(value))
145
+ return value.map((item) => rewritePathsDeep(item, rewriter));
146
+ if (!isRecord(value))
147
+ return value;
148
+ const out = {};
149
+ for (const [key, entry] of Object.entries(value)) {
150
+ out[key] = rewritePathsDeep(entry, rewriter);
151
+ }
152
+ return out;
153
+ }
154
+ /**
155
+ * Apply every substitution to one string.
156
+ *
157
+ * @param text - Captured text.
158
+ * @param rewriter - Pre-compiled substitutions.
159
+ * @returns The rewritten text.
160
+ */
161
+ function rewriteText(text, rewriter) {
162
+ let out = text;
163
+ for (const rule of rewriter.rules) {
164
+ out = out.replace(rule.pattern, rule.replacement);
165
+ }
166
+ return out;
167
+ }
168
+ /**
169
+ * Pattern for a path prefix. The prefix already ends with a separator, so it
170
+ * is boundary-safe on its own.
171
+ *
172
+ * @param prefix - Literal prefix including the trailing separator.
173
+ * @returns A global pattern matching it.
174
+ */
175
+ function prefixPattern(prefix) {
176
+ return new RegExp(escapeRegExp(prefix), 'g');
177
+ }
178
+ /**
179
+ * Pattern for a bare directory reference: only when it is not the start of a
180
+ * longer path name.
181
+ *
182
+ * @param dir - Literal directory path.
183
+ * @returns A global pattern matching it at a boundary.
184
+ */
185
+ function exactPattern(dir) {
186
+ return new RegExp(escapeRegExp(dir) + PATH_BOUNDARY_LOOKAHEAD, 'g');
187
+ }
188
+ /**
189
+ * Escape a literal for safe use inside a pattern.
190
+ *
191
+ * @param text - Literal text.
192
+ * @returns The escaped form.
193
+ */
194
+ function escapeRegExp(text) {
195
+ return text.replace(RE_REGEXP_METACHARACTERS, '\\$&');
196
+ }
197
+ /**
198
+ * A path relative to the repository root, with the root itself as ".".
199
+ *
200
+ * @param root - Repository root.
201
+ * @param target - Path inside it.
202
+ * @returns The relative path.
203
+ */
204
+ function relativize(root, target) {
205
+ const relative = path.relative(root, target);
206
+ return relative === '' ? REPO_ROOT_PLACEHOLDER : relative;
207
+ }
208
+ /**
209
+ * A file path safe to transmit: repo-relative inside the repository, bare
210
+ * basename outside it.
211
+ *
212
+ * A file the agent touched outside the repository is not the project's
213
+ * business, and its absolute path would leak the machine's layout.
214
+ *
215
+ * @param filePath - Absolute path from a tool payload.
216
+ * @param repositoryRoot - Repository root, when inside one.
217
+ * @returns The safe form.
218
+ */
219
+ function toSafePath(filePath, repositoryRoot) {
220
+ if (!repositoryRoot)
221
+ return path.basename(filePath);
222
+ const relative = path.relative(repositoryRoot, filePath);
223
+ if (relative.startsWith('..') || path.isAbsolute(relative))
224
+ return path.basename(filePath);
225
+ return relative;
226
+ }
@@ -0,0 +1,32 @@
1
+ import type { EventIdInput } from './types/events.types.js';
2
+ export type { EventIdInput } from './types/events.types.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 declare function deriveEventId(input: EventIdInput): string;
15
+ /**
16
+ * Event id built from an id the provider already guarantees to be unique.
17
+ *
18
+ * @param provider - Internal provider id, which scopes the namespace.
19
+ * @param rawId - The provider's own identifier.
20
+ * @returns The namespaced event id.
21
+ */
22
+ export declare function providerEventId(provider: string, rawId: string): string;
23
+ /**
24
+ * SHA-256 of a string, hex encoded.
25
+ *
26
+ * Used both for ids and as the one-way function behind every pseudonymous
27
+ * field (repository hash, content evidence, session directory name).
28
+ *
29
+ * @param text - Text to digest.
30
+ * @returns Lowercase hex digest.
31
+ */
32
+ export declare function sha256Hex(text: string): string;