@sentry/warden 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (588) hide show
  1. package/dist/cli/commands/init.d.ts.map +1 -1
  2. package/dist/cli/commands/init.js +3 -1
  3. package/dist/cli/commands/init.js.map +1 -1
  4. package/dist/cli/commands/setup-app/manifest.d.ts.map +1 -1
  5. package/dist/cli/commands/setup-app/manifest.js +3 -1
  6. package/dist/cli/commands/setup-app/manifest.js.map +1 -1
  7. package/dist/cli/commands/setup-app.js +1 -1
  8. package/dist/cli/commands/setup-app.js.map +1 -1
  9. package/dist/cli/files.d.ts +11 -1
  10. package/dist/cli/files.d.ts.map +1 -1
  11. package/dist/cli/files.js +145 -4
  12. package/dist/cli/files.js.map +1 -1
  13. package/dist/cli/git.d.ts.map +1 -1
  14. package/dist/cli/git.js +5 -9
  15. package/dist/cli/git.js.map +1 -1
  16. package/dist/cli/index.js +0 -0
  17. package/dist/cli/output/icons.d.ts +4 -0
  18. package/dist/cli/output/icons.d.ts.map +1 -1
  19. package/dist/cli/output/icons.js +4 -0
  20. package/dist/cli/output/icons.js.map +1 -1
  21. package/dist/cli/output/ink-runner.d.ts +20 -0
  22. package/dist/cli/output/ink-runner.d.ts.map +1 -1
  23. package/dist/cli/output/ink-runner.js +53 -19
  24. package/dist/cli/output/ink-runner.js.map +1 -1
  25. package/dist/cli/output/tasks.d.ts.map +1 -1
  26. package/dist/cli/output/tasks.js +5 -1
  27. package/dist/cli/output/tasks.js.map +1 -1
  28. package/dist/config/schema.d.ts.map +1 -1
  29. package/dist/config/schema.js +15 -1
  30. package/dist/config/schema.js.map +1 -1
  31. package/dist/diff/coalesce.d.ts +32 -2
  32. package/dist/diff/coalesce.d.ts.map +1 -1
  33. package/dist/diff/coalesce.js +174 -2
  34. package/dist/diff/coalesce.js.map +1 -1
  35. package/dist/output/dedup.d.ts.map +1 -1
  36. package/dist/output/dedup.js +8 -3
  37. package/dist/output/dedup.js.map +1 -1
  38. package/dist/output/renderer.d.ts.map +1 -1
  39. package/dist/output/renderer.js +49 -5
  40. package/dist/output/renderer.js.map +1 -1
  41. package/dist/output/stale.d.ts.map +1 -1
  42. package/dist/output/stale.js +7 -0
  43. package/dist/output/stale.js.map +1 -1
  44. package/dist/output/types.d.ts +15 -1
  45. package/dist/output/types.d.ts.map +1 -1
  46. package/dist/sdk/analyze.d.ts +18 -0
  47. package/dist/sdk/analyze.d.ts.map +1 -0
  48. package/dist/sdk/analyze.js +425 -0
  49. package/dist/sdk/analyze.js.map +1 -0
  50. package/dist/sdk/errors.d.ts +23 -0
  51. package/dist/sdk/errors.d.ts.map +1 -0
  52. package/dist/sdk/errors.js +72 -0
  53. package/dist/sdk/errors.js.map +1 -0
  54. package/dist/sdk/extract.d.ts +44 -0
  55. package/dist/sdk/extract.d.ts.map +1 -0
  56. package/dist/sdk/extract.js +224 -0
  57. package/dist/sdk/extract.js.map +1 -0
  58. package/dist/sdk/prepare.d.ts +13 -0
  59. package/dist/sdk/prepare.d.ts.map +1 -0
  60. package/dist/sdk/prepare.js +73 -0
  61. package/dist/sdk/prepare.js.map +1 -0
  62. package/dist/sdk/prompt.d.ts +30 -0
  63. package/dist/sdk/prompt.d.ts.map +1 -0
  64. package/dist/sdk/prompt.js +109 -0
  65. package/dist/sdk/prompt.js.map +1 -0
  66. package/dist/sdk/retry.d.ts +12 -0
  67. package/dist/sdk/retry.d.ts.map +1 -0
  68. package/dist/sdk/retry.js +31 -0
  69. package/dist/sdk/retry.js.map +1 -0
  70. package/dist/sdk/runner.d.ts +22 -199
  71. package/dist/sdk/runner.d.ts.map +1 -1
  72. package/dist/sdk/runner.js +26 -884
  73. package/dist/sdk/runner.js.map +1 -1
  74. package/dist/sdk/types.d.ts +127 -0
  75. package/dist/sdk/types.d.ts.map +1 -0
  76. package/dist/sdk/types.js +5 -0
  77. package/dist/sdk/types.js.map +1 -0
  78. package/dist/sdk/usage.d.ts +20 -0
  79. package/dist/sdk/usage.d.ts.map +1 -0
  80. package/dist/sdk/usage.js +44 -0
  81. package/dist/sdk/usage.js.map +1 -0
  82. package/dist/skills/remote.d.ts.map +1 -1
  83. package/dist/skills/remote.js +3 -7
  84. package/dist/skills/remote.js.map +1 -1
  85. package/dist/types/index.d.ts +1 -0
  86. package/dist/types/index.d.ts.map +1 -1
  87. package/dist/types/index.js +2 -0
  88. package/dist/types/index.js.map +1 -1
  89. package/dist/utils/exec.d.ts +61 -0
  90. package/dist/utils/exec.d.ts.map +1 -0
  91. package/dist/utils/exec.js +111 -0
  92. package/dist/utils/exec.js.map +1 -0
  93. package/dist/utils/index.d.ts +2 -0
  94. package/dist/utils/index.d.ts.map +1 -1
  95. package/dist/utils/index.js +1 -0
  96. package/dist/utils/index.js.map +1 -1
  97. package/package.json +15 -16
  98. package/.agents/skills/find-bugs/SKILL.md +0 -75
  99. package/.agents/skills/vercel-react-best-practices/AGENTS.md +0 -2934
  100. package/.agents/skills/vercel-react-best-practices/SKILL.md +0 -136
  101. package/.agents/skills/vercel-react-best-practices/rules/advanced-event-handler-refs.md +0 -55
  102. package/.agents/skills/vercel-react-best-practices/rules/advanced-init-once.md +0 -42
  103. package/.agents/skills/vercel-react-best-practices/rules/advanced-use-latest.md +0 -39
  104. package/.agents/skills/vercel-react-best-practices/rules/async-api-routes.md +0 -38
  105. package/.agents/skills/vercel-react-best-practices/rules/async-defer-await.md +0 -80
  106. package/.agents/skills/vercel-react-best-practices/rules/async-dependencies.md +0 -51
  107. package/.agents/skills/vercel-react-best-practices/rules/async-parallel.md +0 -28
  108. package/.agents/skills/vercel-react-best-practices/rules/async-suspense-boundaries.md +0 -99
  109. package/.agents/skills/vercel-react-best-practices/rules/bundle-barrel-imports.md +0 -59
  110. package/.agents/skills/vercel-react-best-practices/rules/bundle-conditional.md +0 -31
  111. package/.agents/skills/vercel-react-best-practices/rules/bundle-defer-third-party.md +0 -49
  112. package/.agents/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md +0 -35
  113. package/.agents/skills/vercel-react-best-practices/rules/bundle-preload.md +0 -50
  114. package/.agents/skills/vercel-react-best-practices/rules/client-event-listeners.md +0 -74
  115. package/.agents/skills/vercel-react-best-practices/rules/client-localstorage-schema.md +0 -71
  116. package/.agents/skills/vercel-react-best-practices/rules/client-passive-event-listeners.md +0 -48
  117. package/.agents/skills/vercel-react-best-practices/rules/client-swr-dedup.md +0 -56
  118. package/.agents/skills/vercel-react-best-practices/rules/js-batch-dom-css.md +0 -107
  119. package/.agents/skills/vercel-react-best-practices/rules/js-cache-function-results.md +0 -80
  120. package/.agents/skills/vercel-react-best-practices/rules/js-cache-property-access.md +0 -28
  121. package/.agents/skills/vercel-react-best-practices/rules/js-cache-storage.md +0 -70
  122. package/.agents/skills/vercel-react-best-practices/rules/js-combine-iterations.md +0 -32
  123. package/.agents/skills/vercel-react-best-practices/rules/js-early-exit.md +0 -50
  124. package/.agents/skills/vercel-react-best-practices/rules/js-hoist-regexp.md +0 -45
  125. package/.agents/skills/vercel-react-best-practices/rules/js-index-maps.md +0 -37
  126. package/.agents/skills/vercel-react-best-practices/rules/js-length-check-first.md +0 -49
  127. package/.agents/skills/vercel-react-best-practices/rules/js-min-max-loop.md +0 -82
  128. package/.agents/skills/vercel-react-best-practices/rules/js-set-map-lookups.md +0 -24
  129. package/.agents/skills/vercel-react-best-practices/rules/js-tosorted-immutable.md +0 -57
  130. package/.agents/skills/vercel-react-best-practices/rules/rendering-activity.md +0 -26
  131. package/.agents/skills/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +0 -47
  132. package/.agents/skills/vercel-react-best-practices/rules/rendering-conditional-render.md +0 -40
  133. package/.agents/skills/vercel-react-best-practices/rules/rendering-content-visibility.md +0 -38
  134. package/.agents/skills/vercel-react-best-practices/rules/rendering-hoist-jsx.md +0 -46
  135. package/.agents/skills/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +0 -82
  136. package/.agents/skills/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md +0 -30
  137. package/.agents/skills/vercel-react-best-practices/rules/rendering-svg-precision.md +0 -28
  138. package/.agents/skills/vercel-react-best-practices/rules/rendering-usetransition-loading.md +0 -75
  139. package/.agents/skills/vercel-react-best-practices/rules/rerender-defer-reads.md +0 -39
  140. package/.agents/skills/vercel-react-best-practices/rules/rerender-dependencies.md +0 -45
  141. package/.agents/skills/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md +0 -40
  142. package/.agents/skills/vercel-react-best-practices/rules/rerender-derived-state.md +0 -29
  143. package/.agents/skills/vercel-react-best-practices/rules/rerender-functional-setstate.md +0 -74
  144. package/.agents/skills/vercel-react-best-practices/rules/rerender-lazy-state-init.md +0 -58
  145. package/.agents/skills/vercel-react-best-practices/rules/rerender-memo-with-default-value.md +0 -38
  146. package/.agents/skills/vercel-react-best-practices/rules/rerender-memo.md +0 -44
  147. package/.agents/skills/vercel-react-best-practices/rules/rerender-move-effect-to-event.md +0 -45
  148. package/.agents/skills/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md +0 -35
  149. package/.agents/skills/vercel-react-best-practices/rules/rerender-transitions.md +0 -40
  150. package/.agents/skills/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md +0 -73
  151. package/.agents/skills/vercel-react-best-practices/rules/server-after-nonblocking.md +0 -73
  152. package/.agents/skills/vercel-react-best-practices/rules/server-auth-actions.md +0 -96
  153. package/.agents/skills/vercel-react-best-practices/rules/server-cache-lru.md +0 -41
  154. package/.agents/skills/vercel-react-best-practices/rules/server-cache-react.md +0 -76
  155. package/.agents/skills/vercel-react-best-practices/rules/server-dedup-props.md +0 -65
  156. package/.agents/skills/vercel-react-best-practices/rules/server-parallel-fetching.md +0 -83
  157. package/.agents/skills/vercel-react-best-practices/rules/server-serialization.md +0 -38
  158. package/.claude/settings.json +0 -57
  159. package/.claude/skills/agent-prompt/SKILL.md +0 -54
  160. package/.claude/skills/agent-prompt/references/agentic-patterns.md +0 -94
  161. package/.claude/skills/agent-prompt/references/anti-patterns.md +0 -140
  162. package/.claude/skills/agent-prompt/references/context-design.md +0 -124
  163. package/.claude/skills/agent-prompt/references/core-principles.md +0 -75
  164. package/.claude/skills/agent-prompt/references/model-guidance.md +0 -118
  165. package/.claude/skills/agent-prompt/references/output-formats.md +0 -98
  166. package/.claude/skills/agent-prompt/references/skill-structure.md +0 -115
  167. package/.claude/skills/agent-prompt/references/system-prompts.md +0 -115
  168. package/.claude/skills/notseer/SKILL.md +0 -131
  169. package/.claude/skills/skill-writer/SKILL.md +0 -140
  170. package/.claude/skills/testing-guidelines/SKILL.md +0 -132
  171. package/.claude/skills/warden-skill/SKILL.md +0 -250
  172. package/.claude/skills/warden-skill/references/config-schema.md +0 -133
  173. package/.dex/config.toml +0 -2
  174. package/.github/workflows/ci.yml +0 -33
  175. package/.github/workflows/release.yml +0 -59
  176. package/.github/workflows/warden.yml +0 -40
  177. package/AGENTS.md +0 -89
  178. package/CONTRIBUTING.md +0 -60
  179. package/SPEC.md +0 -263
  180. package/action.yml +0 -87
  181. package/assets/favicon.png +0 -0
  182. package/assets/warden-icon-bw.svg +0 -5
  183. package/assets/warden-icon-purple.png +0 -0
  184. package/assets/warden-icon-purple.svg +0 -5
  185. package/dist/action/159.index.js +0 -523
  186. package/dist/action/159.index.js.map +0 -1
  187. package/dist/action/action/index.d.ts +0 -2
  188. package/dist/action/action/index.d.ts.map +0 -1
  189. package/dist/action/action/main.d.ts +0 -2
  190. package/dist/action/action/main.d.ts.map +0 -1
  191. package/dist/action/cli/args.d.ts +0 -74
  192. package/dist/action/cli/args.d.ts.map +0 -1
  193. package/dist/action/cli/args.test.d.ts +0 -2
  194. package/dist/action/cli/args.test.d.ts.map +0 -1
  195. package/dist/action/cli/commands/add.d.ts +0 -7
  196. package/dist/action/cli/commands/add.d.ts.map +0 -1
  197. package/dist/action/cli/commands/init.d.ts +0 -10
  198. package/dist/action/cli/commands/init.d.ts.map +0 -1
  199. package/dist/action/cli/commands/init.test.d.ts +0 -2
  200. package/dist/action/cli/commands/init.test.d.ts.map +0 -1
  201. package/dist/action/cli/commands/setup-app/browser.d.ts +0 -9
  202. package/dist/action/cli/commands/setup-app/browser.d.ts.map +0 -1
  203. package/dist/action/cli/commands/setup-app/credentials.d.ts +0 -15
  204. package/dist/action/cli/commands/setup-app/credentials.d.ts.map +0 -1
  205. package/dist/action/cli/commands/setup-app/manifest.d.ts +0 -24
  206. package/dist/action/cli/commands/setup-app/manifest.d.ts.map +0 -1
  207. package/dist/action/cli/commands/setup-app/server.d.ts +0 -28
  208. package/dist/action/cli/commands/setup-app/server.d.ts.map +0 -1
  209. package/dist/action/cli/commands/setup-app.d.ts +0 -11
  210. package/dist/action/cli/commands/setup-app.d.ts.map +0 -1
  211. package/dist/action/cli/commands/sync.d.ts +0 -9
  212. package/dist/action/cli/commands/sync.d.ts.map +0 -1
  213. package/dist/action/cli/context.d.ts +0 -27
  214. package/dist/action/cli/context.d.ts.map +0 -1
  215. package/dist/action/cli/files.d.ts +0 -22
  216. package/dist/action/cli/files.d.ts.map +0 -1
  217. package/dist/action/cli/files.test.d.ts +0 -2
  218. package/dist/action/cli/files.test.d.ts.map +0 -1
  219. package/dist/action/cli/fix.d.ts +0 -41
  220. package/dist/action/cli/fix.d.ts.map +0 -1
  221. package/dist/action/cli/fix.test.d.ts +0 -2
  222. package/dist/action/cli/fix.test.d.ts.map +0 -1
  223. package/dist/action/cli/git.d.ts +0 -73
  224. package/dist/action/cli/git.d.ts.map +0 -1
  225. package/dist/action/cli/git.test.d.ts +0 -2
  226. package/dist/action/cli/git.test.d.ts.map +0 -1
  227. package/dist/action/cli/index.d.ts +0 -3
  228. package/dist/action/cli/index.d.ts.map +0 -1
  229. package/dist/action/cli/main.d.ts +0 -7
  230. package/dist/action/cli/main.d.ts.map +0 -1
  231. package/dist/action/cli/output/box.d.ts +0 -75
  232. package/dist/action/cli/output/box.d.ts.map +0 -1
  233. package/dist/action/cli/output/formatters.d.ts +0 -90
  234. package/dist/action/cli/output/formatters.d.ts.map +0 -1
  235. package/dist/action/cli/output/formatters.test.d.ts +0 -2
  236. package/dist/action/cli/output/formatters.test.d.ts.map +0 -1
  237. package/dist/action/cli/output/icons.d.ts +0 -11
  238. package/dist/action/cli/output/icons.d.ts.map +0 -1
  239. package/dist/action/cli/output/index.d.ts +0 -10
  240. package/dist/action/cli/output/index.d.ts.map +0 -1
  241. package/dist/action/cli/output/ink-runner.d.ts +0 -9
  242. package/dist/action/cli/output/ink-runner.d.ts.map +0 -1
  243. package/dist/action/cli/output/jsonl.d.ts +0 -43
  244. package/dist/action/cli/output/jsonl.d.ts.map +0 -1
  245. package/dist/action/cli/output/jsonl.test.d.ts +0 -2
  246. package/dist/action/cli/output/jsonl.test.d.ts.map +0 -1
  247. package/dist/action/cli/output/reporter.d.ts +0 -108
  248. package/dist/action/cli/output/reporter.d.ts.map +0 -1
  249. package/dist/action/cli/output/tasks.d.ts +0 -89
  250. package/dist/action/cli/output/tasks.d.ts.map +0 -1
  251. package/dist/action/cli/output/tty.d.ts +0 -21
  252. package/dist/action/cli/output/tty.d.ts.map +0 -1
  253. package/dist/action/cli/output/tty.test.d.ts +0 -2
  254. package/dist/action/cli/output/tty.test.d.ts.map +0 -1
  255. package/dist/action/cli/output/verbosity.d.ts +0 -20
  256. package/dist/action/cli/output/verbosity.d.ts.map +0 -1
  257. package/dist/action/cli/output/verbosity.test.d.ts +0 -2
  258. package/dist/action/cli/output/verbosity.test.d.ts.map +0 -1
  259. package/dist/action/cli/terminal.d.ts +0 -19
  260. package/dist/action/cli/terminal.d.ts.map +0 -1
  261. package/dist/action/cli/terminal.test.d.ts +0 -2
  262. package/dist/action/cli/terminal.test.d.ts.map +0 -1
  263. package/dist/action/config/index.d.ts +0 -4
  264. package/dist/action/config/index.d.ts.map +0 -1
  265. package/dist/action/config/loader.d.ts +0 -27
  266. package/dist/action/config/loader.d.ts.map +0 -1
  267. package/dist/action/config/loader.test.d.ts +0 -2
  268. package/dist/action/config/loader.test.d.ts.map +0 -1
  269. package/dist/action/config/schema.d.ts +0 -318
  270. package/dist/action/config/schema.d.ts.map +0 -1
  271. package/dist/action/config/writer.d.ts +0 -11
  272. package/dist/action/config/writer.d.ts.map +0 -1
  273. package/dist/action/config/writer.test.d.ts +0 -2
  274. package/dist/action/config/writer.test.d.ts.map +0 -1
  275. package/dist/action/diff/classify.d.ts +0 -29
  276. package/dist/action/diff/classify.d.ts.map +0 -1
  277. package/dist/action/diff/classify.test.d.ts +0 -2
  278. package/dist/action/diff/classify.test.d.ts.map +0 -1
  279. package/dist/action/diff/coalesce.d.ts +0 -42
  280. package/dist/action/diff/coalesce.d.ts.map +0 -1
  281. package/dist/action/diff/coalesce.test.d.ts +0 -2
  282. package/dist/action/diff/coalesce.test.d.ts.map +0 -1
  283. package/dist/action/diff/context.d.ts +0 -30
  284. package/dist/action/diff/context.d.ts.map +0 -1
  285. package/dist/action/diff/context.test.d.ts +0 -2
  286. package/dist/action/diff/context.test.d.ts.map +0 -1
  287. package/dist/action/diff/index.d.ts +0 -5
  288. package/dist/action/diff/index.d.ts.map +0 -1
  289. package/dist/action/diff/parser.d.ts +0 -52
  290. package/dist/action/diff/parser.d.ts.map +0 -1
  291. package/dist/action/diff/parser.test.d.ts +0 -2
  292. package/dist/action/diff/parser.test.d.ts.map +0 -1
  293. package/dist/action/event/context.d.ts +0 -9
  294. package/dist/action/event/context.d.ts.map +0 -1
  295. package/dist/action/event/index.d.ts +0 -3
  296. package/dist/action/event/index.d.ts.map +0 -1
  297. package/dist/action/event/schedule-context.d.ts +0 -30
  298. package/dist/action/event/schedule-context.d.ts.map +0 -1
  299. package/dist/action/examples/examples.integration.test.d.ts +0 -2
  300. package/dist/action/examples/examples.integration.test.d.ts.map +0 -1
  301. package/dist/action/examples/index.d.ts +0 -50
  302. package/dist/action/examples/index.d.ts.map +0 -1
  303. package/dist/action/examples/index.test.d.ts +0 -2
  304. package/dist/action/examples/index.test.d.ts.map +0 -1
  305. package/dist/action/examples/setup.d.ts +0 -2
  306. package/dist/action/examples/setup.d.ts.map +0 -1
  307. package/dist/action/index.d.ts +0 -11
  308. package/dist/action/index.d.ts.map +0 -1
  309. package/dist/action/index.js +0 -38231
  310. package/dist/action/index.js.map +0 -1
  311. package/dist/action/licenses.txt +0 -992
  312. package/dist/action/main.d.ts +0 -2
  313. package/dist/action/main.d.ts.map +0 -1
  314. package/dist/action/main.js +0 -707
  315. package/dist/action/main.js.map +0 -1
  316. package/dist/action/output/dedup.d.ts +0 -153
  317. package/dist/action/output/dedup.d.ts.map +0 -1
  318. package/dist/action/output/dedup.test.d.ts +0 -2
  319. package/dist/action/output/dedup.test.d.ts.map +0 -1
  320. package/dist/action/output/github-checks.d.ts +0 -106
  321. package/dist/action/output/github-checks.d.ts.map +0 -1
  322. package/dist/action/output/github-checks.test.d.ts +0 -2
  323. package/dist/action/output/github-checks.test.d.ts.map +0 -1
  324. package/dist/action/output/github-issues.d.ts +0 -35
  325. package/dist/action/output/github-issues.d.ts.map +0 -1
  326. package/dist/action/output/index.d.ts +0 -6
  327. package/dist/action/output/index.d.ts.map +0 -1
  328. package/dist/action/output/issue-renderer.d.ts +0 -20
  329. package/dist/action/output/issue-renderer.d.ts.map +0 -1
  330. package/dist/action/output/renderer.d.ts +0 -4
  331. package/dist/action/output/renderer.d.ts.map +0 -1
  332. package/dist/action/output/renderer.test.d.ts +0 -2
  333. package/dist/action/output/renderer.test.d.ts.map +0 -1
  334. package/dist/action/output/stale.d.ts +0 -31
  335. package/dist/action/output/stale.d.ts.map +0 -1
  336. package/dist/action/output/stale.test.d.ts +0 -2
  337. package/dist/action/output/stale.test.d.ts.map +0 -1
  338. package/dist/action/output/types.d.ts +0 -31
  339. package/dist/action/output/types.d.ts.map +0 -1
  340. package/dist/action/package.json +0 -3
  341. package/dist/action/sdk/index.d.ts +0 -2
  342. package/dist/action/sdk/index.d.ts.map +0 -1
  343. package/dist/action/sdk/runner.d.ts +0 -202
  344. package/dist/action/sdk/runner.d.ts.map +0 -1
  345. package/dist/action/sdk/runner.test.d.ts +0 -2
  346. package/dist/action/sdk/runner.test.d.ts.map +0 -1
  347. package/dist/action/skills/index.d.ts +0 -5
  348. package/dist/action/skills/index.d.ts.map +0 -1
  349. package/dist/action/skills/loader.d.ts +0 -111
  350. package/dist/action/skills/loader.d.ts.map +0 -1
  351. package/dist/action/skills/loader.test.d.ts +0 -2
  352. package/dist/action/skills/loader.test.d.ts.map +0 -1
  353. package/dist/action/skills/remote.d.ts +0 -117
  354. package/dist/action/skills/remote.d.ts.map +0 -1
  355. package/dist/action/skills/remote.test.d.ts +0 -2
  356. package/dist/action/skills/remote.test.d.ts.map +0 -1
  357. package/dist/action/sourcemap-register.cjs +0 -1
  358. package/dist/action/triggers/matcher.d.ts +0 -30
  359. package/dist/action/triggers/matcher.d.ts.map +0 -1
  360. package/dist/action/triggers/matcher.test.d.ts +0 -2
  361. package/dist/action/triggers/matcher.test.d.ts.map +0 -1
  362. package/dist/action/types/index.d.ts +0 -269
  363. package/dist/action/types/index.d.ts.map +0 -1
  364. package/dist/action/utils/async.d.ts +0 -5
  365. package/dist/action/utils/async.d.ts.map +0 -1
  366. package/dist/action/utils/index.d.ts +0 -16
  367. package/dist/action/utils/index.d.ts.map +0 -1
  368. package/dist/action/utils/index.test.d.ts +0 -2
  369. package/dist/action/utils/index.test.d.ts.map +0 -1
  370. package/dist/action/utils/version.d.ts +0 -3
  371. package/dist/action/utils/version.d.ts.map +0 -1
  372. package/dist/cli/args.test.d.ts +0 -2
  373. package/dist/cli/args.test.d.ts.map +0 -1
  374. package/dist/cli/args.test.js +0 -392
  375. package/dist/cli/args.test.js.map +0 -1
  376. package/dist/cli/commands/init.test.d.ts +0 -2
  377. package/dist/cli/commands/init.test.d.ts.map +0 -1
  378. package/dist/cli/commands/init.test.js +0 -117
  379. package/dist/cli/commands/init.test.js.map +0 -1
  380. package/dist/cli/files.test.d.ts +0 -2
  381. package/dist/cli/files.test.d.ts.map +0 -1
  382. package/dist/cli/files.test.js +0 -117
  383. package/dist/cli/files.test.js.map +0 -1
  384. package/dist/cli/fix.test.d.ts +0 -2
  385. package/dist/cli/fix.test.d.ts.map +0 -1
  386. package/dist/cli/fix.test.js +0 -251
  387. package/dist/cli/fix.test.js.map +0 -1
  388. package/dist/cli/git.test.d.ts +0 -2
  389. package/dist/cli/git.test.d.ts.map +0 -1
  390. package/dist/cli/git.test.js +0 -96
  391. package/dist/cli/git.test.js.map +0 -1
  392. package/dist/cli/output/formatters.test.d.ts +0 -2
  393. package/dist/cli/output/formatters.test.d.ts.map +0 -1
  394. package/dist/cli/output/formatters.test.js +0 -152
  395. package/dist/cli/output/formatters.test.js.map +0 -1
  396. package/dist/cli/output/jsonl.test.d.ts +0 -2
  397. package/dist/cli/output/jsonl.test.d.ts.map +0 -1
  398. package/dist/cli/output/jsonl.test.js +0 -284
  399. package/dist/cli/output/jsonl.test.js.map +0 -1
  400. package/dist/cli/output/tty.test.d.ts +0 -2
  401. package/dist/cli/output/tty.test.d.ts.map +0 -1
  402. package/dist/cli/output/tty.test.js +0 -105
  403. package/dist/cli/output/tty.test.js.map +0 -1
  404. package/dist/cli/output/verbosity.test.d.ts +0 -2
  405. package/dist/cli/output/verbosity.test.d.ts.map +0 -1
  406. package/dist/cli/output/verbosity.test.js +0 -35
  407. package/dist/cli/output/verbosity.test.js.map +0 -1
  408. package/dist/cli/terminal.test.d.ts +0 -2
  409. package/dist/cli/terminal.test.d.ts.map +0 -1
  410. package/dist/cli/terminal.test.js +0 -123
  411. package/dist/cli/terminal.test.js.map +0 -1
  412. package/dist/config/loader.test.d.ts +0 -2
  413. package/dist/config/loader.test.d.ts.map +0 -1
  414. package/dist/config/loader.test.js +0 -263
  415. package/dist/config/loader.test.js.map +0 -1
  416. package/dist/config/writer.test.d.ts +0 -2
  417. package/dist/config/writer.test.d.ts.map +0 -1
  418. package/dist/config/writer.test.js +0 -98
  419. package/dist/config/writer.test.js.map +0 -1
  420. package/dist/diff/classify.test.d.ts +0 -2
  421. package/dist/diff/classify.test.d.ts.map +0 -1
  422. package/dist/diff/classify.test.js +0 -140
  423. package/dist/diff/classify.test.js.map +0 -1
  424. package/dist/diff/coalesce.test.d.ts +0 -2
  425. package/dist/diff/coalesce.test.d.ts.map +0 -1
  426. package/dist/diff/coalesce.test.js +0 -159
  427. package/dist/diff/coalesce.test.js.map +0 -1
  428. package/dist/diff/context.test.d.ts +0 -2
  429. package/dist/diff/context.test.d.ts.map +0 -1
  430. package/dist/diff/context.test.js +0 -190
  431. package/dist/diff/context.test.js.map +0 -1
  432. package/dist/diff/parser.test.d.ts +0 -2
  433. package/dist/diff/parser.test.d.ts.map +0 -1
  434. package/dist/diff/parser.test.js +0 -178
  435. package/dist/diff/parser.test.js.map +0 -1
  436. package/dist/examples/examples.integration.test.d.ts +0 -2
  437. package/dist/examples/examples.integration.test.d.ts.map +0 -1
  438. package/dist/examples/examples.integration.test.js +0 -55
  439. package/dist/examples/examples.integration.test.js.map +0 -1
  440. package/dist/examples/index.test.d.ts +0 -2
  441. package/dist/examples/index.test.d.ts.map +0 -1
  442. package/dist/examples/index.test.js +0 -88
  443. package/dist/examples/index.test.js.map +0 -1
  444. package/dist/output/dedup.test.d.ts +0 -2
  445. package/dist/output/dedup.test.d.ts.map +0 -1
  446. package/dist/output/dedup.test.js +0 -357
  447. package/dist/output/dedup.test.js.map +0 -1
  448. package/dist/output/github-checks.test.d.ts +0 -2
  449. package/dist/output/github-checks.test.d.ts.map +0 -1
  450. package/dist/output/github-checks.test.js +0 -255
  451. package/dist/output/github-checks.test.js.map +0 -1
  452. package/dist/output/renderer.test.d.ts +0 -2
  453. package/dist/output/renderer.test.d.ts.map +0 -1
  454. package/dist/output/renderer.test.js +0 -645
  455. package/dist/output/renderer.test.js.map +0 -1
  456. package/dist/output/stale.test.d.ts +0 -2
  457. package/dist/output/stale.test.d.ts.map +0 -1
  458. package/dist/output/stale.test.js +0 -330
  459. package/dist/output/stale.test.js.map +0 -1
  460. package/dist/sdk/runner.test.d.ts +0 -2
  461. package/dist/sdk/runner.test.d.ts.map +0 -1
  462. package/dist/sdk/runner.test.js +0 -677
  463. package/dist/sdk/runner.test.js.map +0 -1
  464. package/dist/skills/loader.test.d.ts +0 -2
  465. package/dist/skills/loader.test.d.ts.map +0 -1
  466. package/dist/skills/loader.test.js +0 -241
  467. package/dist/skills/loader.test.js.map +0 -1
  468. package/dist/skills/remote.test.d.ts +0 -2
  469. package/dist/skills/remote.test.d.ts.map +0 -1
  470. package/dist/skills/remote.test.js +0 -582
  471. package/dist/skills/remote.test.js.map +0 -1
  472. package/dist/triggers/matcher.test.d.ts +0 -2
  473. package/dist/triggers/matcher.test.d.ts.map +0 -1
  474. package/dist/triggers/matcher.test.js +0 -234
  475. package/dist/triggers/matcher.test.js.map +0 -1
  476. package/dist/utils/index.test.d.ts +0 -2
  477. package/dist/utils/index.test.d.ts.map +0 -1
  478. package/dist/utils/index.test.js +0 -68
  479. package/dist/utils/index.test.js.map +0 -1
  480. package/docs/astro.config.mjs +0 -43
  481. package/docs/package.json +0 -19
  482. package/docs/pnpm-lock.yaml +0 -4000
  483. package/docs/public/favicon.svg +0 -5
  484. package/docs/src/components/Code.astro +0 -141
  485. package/docs/src/components/PackageManagerTabs.astro +0 -183
  486. package/docs/src/components/Terminal.astro +0 -212
  487. package/docs/src/layouts/Base.astro +0 -380
  488. package/docs/src/pages/cli.astro +0 -167
  489. package/docs/src/pages/config.astro +0 -395
  490. package/docs/src/pages/guide.astro +0 -450
  491. package/docs/src/pages/index.astro +0 -490
  492. package/docs/src/styles/global.css +0 -551
  493. package/docs/src/utils/version.ts +0 -6
  494. package/docs/tsconfig.json +0 -3
  495. package/docs/vercel.json +0 -5
  496. package/eslint.config.js +0 -33
  497. package/src/action/index.ts +0 -1
  498. package/src/action/main.ts +0 -868
  499. package/src/cli/args.test.ts +0 -477
  500. package/src/cli/args.ts +0 -414
  501. package/src/cli/commands/add.ts +0 -447
  502. package/src/cli/commands/init.test.ts +0 -137
  503. package/src/cli/commands/init.ts +0 -134
  504. package/src/cli/commands/setup-app/browser.ts +0 -38
  505. package/src/cli/commands/setup-app/credentials.ts +0 -45
  506. package/src/cli/commands/setup-app/manifest.ts +0 -48
  507. package/src/cli/commands/setup-app/server.ts +0 -172
  508. package/src/cli/commands/setup-app.ts +0 -156
  509. package/src/cli/commands/sync.ts +0 -114
  510. package/src/cli/context.ts +0 -131
  511. package/src/cli/files.test.ts +0 -155
  512. package/src/cli/files.ts +0 -89
  513. package/src/cli/fix.test.ts +0 -310
  514. package/src/cli/fix.ts +0 -387
  515. package/src/cli/git.test.ts +0 -119
  516. package/src/cli/git.ts +0 -318
  517. package/src/cli/index.ts +0 -14
  518. package/src/cli/main.ts +0 -672
  519. package/src/cli/output/box.ts +0 -235
  520. package/src/cli/output/formatters.test.ts +0 -187
  521. package/src/cli/output/formatters.ts +0 -269
  522. package/src/cli/output/icons.ts +0 -13
  523. package/src/cli/output/index.ts +0 -44
  524. package/src/cli/output/ink-runner.tsx +0 -337
  525. package/src/cli/output/jsonl.test.ts +0 -347
  526. package/src/cli/output/jsonl.ts +0 -126
  527. package/src/cli/output/reporter.ts +0 -434
  528. package/src/cli/output/tasks.ts +0 -374
  529. package/src/cli/output/tty.test.ts +0 -117
  530. package/src/cli/output/tty.ts +0 -60
  531. package/src/cli/output/verbosity.test.ts +0 -40
  532. package/src/cli/output/verbosity.ts +0 -31
  533. package/src/cli/terminal.test.ts +0 -148
  534. package/src/cli/terminal.ts +0 -301
  535. package/src/config/index.ts +0 -3
  536. package/src/config/loader.test.ts +0 -313
  537. package/src/config/loader.ts +0 -103
  538. package/src/config/schema.ts +0 -168
  539. package/src/config/writer.test.ts +0 -119
  540. package/src/config/writer.ts +0 -84
  541. package/src/diff/classify.test.ts +0 -162
  542. package/src/diff/classify.ts +0 -92
  543. package/src/diff/coalesce.test.ts +0 -208
  544. package/src/diff/coalesce.ts +0 -133
  545. package/src/diff/context.test.ts +0 -226
  546. package/src/diff/context.ts +0 -201
  547. package/src/diff/index.ts +0 -4
  548. package/src/diff/parser.test.ts +0 -212
  549. package/src/diff/parser.ts +0 -149
  550. package/src/event/context.ts +0 -132
  551. package/src/event/index.ts +0 -2
  552. package/src/event/schedule-context.ts +0 -101
  553. package/src/examples/examples.integration.test.ts +0 -66
  554. package/src/examples/index.test.ts +0 -101
  555. package/src/examples/index.ts +0 -122
  556. package/src/examples/setup.ts +0 -25
  557. package/src/index.ts +0 -115
  558. package/src/output/dedup.test.ts +0 -419
  559. package/src/output/dedup.ts +0 -607
  560. package/src/output/github-checks.test.ts +0 -300
  561. package/src/output/github-checks.ts +0 -476
  562. package/src/output/github-issues.ts +0 -329
  563. package/src/output/index.ts +0 -5
  564. package/src/output/issue-renderer.ts +0 -197
  565. package/src/output/renderer.test.ts +0 -727
  566. package/src/output/renderer.ts +0 -217
  567. package/src/output/stale.test.ts +0 -375
  568. package/src/output/stale.ts +0 -155
  569. package/src/output/types.ts +0 -34
  570. package/src/sdk/index.ts +0 -1
  571. package/src/sdk/runner.test.ts +0 -806
  572. package/src/sdk/runner.ts +0 -1232
  573. package/src/skills/index.ts +0 -36
  574. package/src/skills/loader.test.ts +0 -300
  575. package/src/skills/loader.ts +0 -423
  576. package/src/skills/remote.test.ts +0 -704
  577. package/src/skills/remote.ts +0 -604
  578. package/src/triggers/matcher.test.ts +0 -277
  579. package/src/triggers/matcher.ts +0 -152
  580. package/src/types/index.ts +0 -194
  581. package/src/utils/async.ts +0 -18
  582. package/src/utils/index.test.ts +0 -84
  583. package/src/utils/index.ts +0 -51
  584. package/src/utils/version.ts +0 -17
  585. package/tsconfig.json +0 -25
  586. package/vitest.config.ts +0 -8
  587. package/vitest.integration.config.ts +0 -11
  588. package/warden.toml +0 -19
package/src/sdk/runner.ts DELETED
@@ -1,1232 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { query, type SDKResultMessage } from '@anthropic-ai/claude-agent-sdk';
4
- import Anthropic from '@anthropic-ai/sdk';
5
- import type { SkillDefinition, ChunkingConfig } from '../config/schema.js';
6
- import { FindingSchema } from '../types/index.js';
7
- import type { EventContext, SkillReport, Finding, UsageStats, SkippedFile, RetryConfig } from '../types/index.js';
8
- import {
9
- APIError,
10
- RateLimitError,
11
- InternalServerError,
12
- APIConnectionError,
13
- APIConnectionTimeoutError,
14
- } from '@anthropic-ai/sdk';
15
- import {
16
- parseFileDiff,
17
- expandDiffContext,
18
- formatHunkForAnalysis,
19
- classifyFile,
20
- coalesceHunks,
21
- type HunkWithContext,
22
- } from '../diff/index.js';
23
-
24
- export class SkillRunnerError extends Error {
25
- constructor(message: string, options?: { cause?: unknown }) {
26
- super(message, options);
27
- this.name = 'SkillRunnerError';
28
- }
29
- }
30
-
31
- /** Default concurrency for file-level parallel processing */
32
- const DEFAULT_FILE_CONCURRENCY = 5;
33
-
34
- /** Pattern to match the start of findings JSON (allows whitespace after brace) */
35
- const FINDINGS_JSON_START = /\{\s*"findings"/;
36
-
37
- /** Threshold in characters above which to warn about large prompts (~25k tokens) */
38
- const LARGE_PROMPT_THRESHOLD_CHARS = 100000;
39
-
40
- /**
41
- * Estimate token count from character count.
42
- * Uses chars/4 as a rough approximation for English text.
43
- */
44
- export function estimateTokens(chars: number): number {
45
- return Math.ceil(chars / 4);
46
- }
47
-
48
- /** Result from analyzing a single hunk */
49
- interface HunkAnalysisResult {
50
- findings: Finding[];
51
- usage: UsageStats;
52
- /** Whether the hunk analysis failed (SDK error, API error, etc.) */
53
- failed: boolean;
54
- }
55
-
56
- /**
57
- * Extract usage stats from an SDK result message.
58
- */
59
- function extractUsage(result: SDKResultMessage): UsageStats {
60
- return {
61
- inputTokens: result.usage['input_tokens'],
62
- outputTokens: result.usage['output_tokens'],
63
- cacheReadInputTokens: result.usage['cache_read_input_tokens'] ?? 0,
64
- cacheCreationInputTokens: result.usage['cache_creation_input_tokens'] ?? 0,
65
- costUSD: result.total_cost_usd,
66
- };
67
- }
68
-
69
- /**
70
- * Create empty usage stats.
71
- */
72
- function emptyUsage(): UsageStats {
73
- return {
74
- inputTokens: 0,
75
- outputTokens: 0,
76
- cacheReadInputTokens: 0,
77
- cacheCreationInputTokens: 0,
78
- costUSD: 0,
79
- };
80
- }
81
-
82
- /**
83
- * Aggregate multiple usage stats into one.
84
- */
85
- export function aggregateUsage(usages: UsageStats[]): UsageStats {
86
- return usages.reduce(
87
- (acc, u) => ({
88
- inputTokens: acc.inputTokens + u.inputTokens,
89
- outputTokens: acc.outputTokens + u.outputTokens,
90
- cacheReadInputTokens: (acc.cacheReadInputTokens ?? 0) + (u.cacheReadInputTokens ?? 0),
91
- cacheCreationInputTokens: (acc.cacheCreationInputTokens ?? 0) + (u.cacheCreationInputTokens ?? 0),
92
- costUSD: acc.costUSD + u.costUSD,
93
- }),
94
- emptyUsage()
95
- );
96
- }
97
-
98
- /** Default retry configuration */
99
- const DEFAULT_RETRY_CONFIG: Required<RetryConfig> = {
100
- maxRetries: 3,
101
- initialDelayMs: 1000,
102
- backoffMultiplier: 2,
103
- maxDelayMs: 30000,
104
- };
105
-
106
- /**
107
- * Check if an error is retryable.
108
- * Retries on: rate limits (429), server errors (5xx), connection errors, timeouts.
109
- */
110
- export function isRetryableError(error: unknown): boolean {
111
- if (error instanceof RateLimitError) return true;
112
- if (error instanceof InternalServerError) return true;
113
- if (error instanceof APIConnectionError) return true;
114
- if (error instanceof APIConnectionTimeoutError) return true;
115
-
116
- // Check for generic APIError with retryable status codes
117
- if (error instanceof APIError) {
118
- const status = error.status;
119
- if (status === 429) return true;
120
- if (status !== undefined && status >= 500 && status < 600) return true;
121
- }
122
-
123
- return false;
124
- }
125
-
126
- /**
127
- * Check if an error is an authentication failure.
128
- * These require user action (login or API key) and should not be retried.
129
- */
130
- export function isAuthenticationError(error: unknown): boolean {
131
- if (error instanceof APIError && error.status === 401) {
132
- return true;
133
- }
134
-
135
- // Check error message for common auth failure patterns
136
- const message = error instanceof Error ? error.message : String(error);
137
- const authPatterns = [
138
- 'authentication',
139
- 'unauthorized',
140
- 'invalid.*api.*key',
141
- 'not.*logged.*in',
142
- 'login.*required',
143
- ];
144
- return authPatterns.some((pattern) => new RegExp(pattern, 'i').test(message));
145
- }
146
-
147
- /** User-friendly error message for authentication failures */
148
- const AUTH_ERROR_MESSAGE = `Authentication required.
149
-
150
- claude login # Use Claude Code subscription
151
- export WARDEN_ANTHROPIC_API_KEY=sk-... # Or use API key
152
-
153
- https://console.anthropic.com/ for API keys`;
154
-
155
- export class WardenAuthenticationError extends Error {
156
- constructor() {
157
- super(AUTH_ERROR_MESSAGE);
158
- this.name = 'WardenAuthenticationError';
159
- }
160
- }
161
-
162
- /**
163
- * Calculate delay for a retry attempt using exponential backoff.
164
- */
165
- export function calculateRetryDelay(
166
- attempt: number,
167
- config: Required<RetryConfig>
168
- ): number {
169
- const delay = config.initialDelayMs * Math.pow(config.backoffMultiplier, attempt);
170
- return Math.min(delay, config.maxDelayMs);
171
- }
172
-
173
- /**
174
- * Sleep for a specified duration, respecting abort signal.
175
- */
176
- async function sleep(ms: number, abortSignal?: AbortSignal): Promise<void> {
177
- return new Promise((resolve, reject) => {
178
- if (abortSignal?.aborted) {
179
- reject(new Error('Aborted'));
180
- return;
181
- }
182
-
183
- const timeout = setTimeout(resolve, ms);
184
-
185
- abortSignal?.addEventListener('abort', () => {
186
- clearTimeout(timeout);
187
- reject(new Error('Aborted'));
188
- }, { once: true });
189
- });
190
- }
191
-
192
- /**
193
- * Callbacks for progress reporting during skill execution.
194
- */
195
- export interface SkillRunnerCallbacks {
196
- /** Start time of the skill execution (for elapsed time calculations) */
197
- skillStartTime?: number;
198
- onFileStart?: (file: string, index: number, total: number) => void;
199
- onHunkStart?: (file: string, hunkNum: number, totalHunks: number, lineRange: string) => void;
200
- onHunkComplete?: (file: string, hunkNum: number, findings: Finding[]) => void;
201
- onFileComplete?: (file: string, index: number, total: number) => void;
202
- /** Called when a prompt exceeds the large prompt threshold */
203
- onLargePrompt?: (file: string, lineRange: string, chars: number, estimatedTokens: number) => void;
204
- /** Called with prompt size info in debug mode */
205
- onPromptSize?: (file: string, lineRange: string, systemChars: number, userChars: number, totalChars: number, estimatedTokens: number) => void;
206
- /** Called when a retry attempt is made (verbose mode) */
207
- onRetry?: (file: string, lineRange: string, attempt: number, maxRetries: number, error: string, delayMs: number) => void;
208
- }
209
-
210
- export interface SkillRunnerOptions {
211
- apiKey?: string;
212
- maxTurns?: number;
213
- /** Lines of context to include around each hunk */
214
- contextLines?: number;
215
- /** Process files in parallel (default: true) */
216
- parallel?: boolean;
217
- /** Max concurrent file analyses when parallel=true (default: 5) */
218
- concurrency?: number;
219
- /** Delay in milliseconds between batch starts when parallel=true (default: 0) */
220
- batchDelayMs?: number;
221
- /** Model to use for analysis (e.g., 'claude-sonnet-4-20250514'). Uses SDK default if not specified. */
222
- model?: string;
223
- /** Progress callbacks */
224
- callbacks?: SkillRunnerCallbacks;
225
- /** Abort controller for cancellation on SIGINT */
226
- abortController?: AbortController;
227
- /** Path to Claude Code CLI executable. Required in CI environments. */
228
- pathToClaudeCodeExecutable?: string;
229
- /** Retry configuration for transient API failures */
230
- retry?: RetryConfig;
231
- /** Enable verbose logging for retry attempts */
232
- verbose?: boolean;
233
- }
234
-
235
- /**
236
- * Builds the system prompt for hunk-based analysis.
237
- *
238
- * Future enhancement: Could have the agent output a structured `contextAssessment`
239
- * (applicationType, trustBoundaries, filesChecked) to cache across hunks, allow
240
- * user overrides, or build analytics. Not implemented since we don't consume it yet.
241
- */
242
- function buildHunkSystemPrompt(skill: SkillDefinition): string {
243
- const sections = [
244
- `<role>
245
- You are a code analysis agent for Warden. You evaluate code changes against specific skill criteria and report findings ONLY when the code violates or conflicts with those criteria. You do not perform general code review or report issues outside the skill's scope.
246
- </role>`,
247
-
248
- `<tools>
249
- You have access to these tools to gather context:
250
- - **Read**: Check related files to understand context
251
- - **Grep**: Search for patterns to trace data flow or find related code
252
- </tools>`,
253
-
254
- `<skill_instructions>
255
- The following defines the ONLY criteria you should evaluate. Do not report findings outside this scope:
256
-
257
- ${skill.prompt}
258
- </skill_instructions>`,
259
-
260
- `<output_format>
261
- IMPORTANT: Your response must be ONLY a valid JSON object. No markdown, no explanation, no code fences.
262
-
263
- Example response format:
264
- {"findings": [{"id": "example-1", "severity": "medium", "confidence": "high", "title": "Issue title", "description": "Description", "location": {"path": "file.ts", "startLine": 10}}]}
265
-
266
- Full schema:
267
- {
268
- "findings": [
269
- {
270
- "id": "unique-identifier",
271
- "severity": "critical|high|medium|low|info",
272
- "confidence": "high|medium|low",
273
- "title": "Short descriptive title",
274
- "description": "Detailed explanation of the issue",
275
- "location": {
276
- "path": "path/to/file.ts",
277
- "startLine": 10,
278
- "endLine": 15
279
- },
280
- "suggestedFix": {
281
- "description": "How to fix this issue",
282
- "diff": "unified diff format"
283
- }
284
- }
285
- ]
286
- }
287
-
288
- Requirements:
289
- - Return ONLY valid JSON starting with {"findings":
290
- - "findings" array can be empty if no issues found
291
- - "location.path" is auto-filled from context - just provide startLine (and optionally endLine). Omit location entirely for general findings not about a specific line.
292
- - "confidence" reflects how certain you are this is a real issue given the codebase context
293
- - "suggestedFix" is optional - only include when you can provide a complete, correct fix **to the file being analyzed**. Omit suggestedFix if:
294
- - The fix would be incomplete or you're uncertain about the correct solution
295
- - The fix requires changes to a different file or a new file (describe the fix in the description field instead)
296
- - Keep descriptions SHORT (1-2 sentences max) - avoid lengthy explanations
297
- - Be concise - focus only on the changes shown
298
- </output_format>`,
299
- ];
300
-
301
- const { rootDir } = skill;
302
- if (rootDir) {
303
- const resourceDirs = ['scripts', 'references', 'assets'].filter((dir) =>
304
- existsSync(join(rootDir, dir))
305
- );
306
- if (resourceDirs.length > 0) {
307
- const dirList = resourceDirs.map((d) => `${d}/`).join(', ');
308
- sections.push(`<skill_resources>
309
- This skill is located at: ${rootDir}
310
- You can read files from ${dirList} subdirectories using the Read tool with the full path.
311
- </skill_resources>`);
312
- }
313
- }
314
-
315
- return sections.join('\n\n');
316
- }
317
-
318
- /**
319
- * Context about the PR being analyzed, for inclusion in prompts.
320
- *
321
- * The title and body (like a commit message) help explain the _intent_ of the
322
- * changes to the agent, enabling it to better understand what the author was
323
- * trying to accomplish and identify issues that conflict with that intent.
324
- */
325
- export interface PRPromptContext {
326
- /** All files being changed in the PR */
327
- changedFiles: string[];
328
- /** PR title - explains what the change does */
329
- title?: string;
330
- /** PR description/body - explains why and provides additional context */
331
- body?: string | null;
332
- }
333
-
334
- /**
335
- * Builds the user prompt for a single hunk.
336
- */
337
- function buildHunkUserPrompt(
338
- skill: SkillDefinition,
339
- hunkCtx: HunkWithContext,
340
- prContext?: PRPromptContext
341
- ): string {
342
- const sections: string[] = [];
343
-
344
- sections.push(`Analyze this code change according to the "${skill.name}" skill criteria.`);
345
-
346
- // Include PR title and description for context on intent
347
- if (prContext?.title) {
348
- let prSection = `## Pull Request Context\n**Title:** ${prContext.title}`;
349
- if (prContext.body) {
350
- // Truncate very long PR descriptions to avoid bloating prompts
351
- const maxBodyLength = 1000;
352
- const body = prContext.body.length > maxBodyLength
353
- ? prContext.body.slice(0, maxBodyLength) + '...'
354
- : prContext.body;
355
- prSection += `\n\n**Description:**\n${body}`;
356
- }
357
- sections.push(prSection);
358
- }
359
-
360
- // Include list of other files being changed in the PR for context
361
- const otherFiles = prContext?.changedFiles.filter((f) => f !== hunkCtx.filename) ?? [];
362
- if (otherFiles.length > 0) {
363
- sections.push(`## Other Files in This PR
364
- The following files are also being changed in this PR (may provide useful context):
365
- ${otherFiles.map((f) => `- ${f}`).join('\n')}`);
366
- }
367
-
368
- sections.push(formatHunkForAnalysis(hunkCtx));
369
-
370
- sections.push(
371
- `IMPORTANT: Only report findings that are explicitly covered by the skill instructions. Do not report general code quality issues, bugs, or improvements unless the skill specifically asks for them. Return an empty findings array if no issues match the skill's criteria.`
372
- );
373
-
374
- return sections.join('\n\n');
375
- }
376
-
377
- /**
378
- * Result from extracting findings JSON from text.
379
- */
380
- export type ExtractFindingsResult =
381
- | { success: true; findings: unknown[] }
382
- | { success: false; error: string; preview: string };
383
-
384
- /**
385
- * Extract JSON object from text, handling nested braces correctly.
386
- * Starts from the given position and returns the balanced JSON object.
387
- */
388
- export function extractBalancedJson(text: string, startIndex: number): string | null {
389
- let depth = 0;
390
- let inString = false;
391
- let escape = false;
392
-
393
- for (let i = startIndex; i < text.length; i++) {
394
- const char = text[i];
395
-
396
- if (escape) {
397
- escape = false;
398
- continue;
399
- }
400
-
401
- if (char === '\\' && inString) {
402
- escape = true;
403
- continue;
404
- }
405
-
406
- if (char === '"') {
407
- inString = !inString;
408
- continue;
409
- }
410
-
411
- if (inString) continue;
412
-
413
- if (char === '{') depth++;
414
- if (char === '}') {
415
- depth--;
416
- if (depth === 0) {
417
- return text.slice(startIndex, i + 1);
418
- }
419
- }
420
- }
421
-
422
- return null;
423
- }
424
-
425
- /**
426
- * Extract findings JSON from model output text.
427
- * Handles markdown code fences, prose before JSON, and nested objects.
428
- */
429
- export function extractFindingsJson(rawText: string): ExtractFindingsResult {
430
- let text = rawText.trim();
431
-
432
- // Strip markdown code fences if present (handles any language tag: ```json, ```typescript, ```c++, etc.)
433
- const codeBlockMatch = text.match(/```[\w+#-]*\s*([\s\S]*?)```/);
434
- if (codeBlockMatch?.[1]) {
435
- text = codeBlockMatch[1].trim();
436
- }
437
-
438
- // Find the start of the findings JSON object
439
- const findingsMatch = text.match(FINDINGS_JSON_START);
440
- if (!findingsMatch || findingsMatch.index === undefined) {
441
- return {
442
- success: false,
443
- error: 'no_findings_json',
444
- preview: text.slice(0, 200),
445
- };
446
- }
447
- const findingsStart = findingsMatch.index;
448
-
449
- // Extract the balanced JSON object
450
- const jsonStr = extractBalancedJson(text, findingsStart);
451
- if (!jsonStr) {
452
- return {
453
- success: false,
454
- error: 'unbalanced_json',
455
- preview: text.slice(findingsStart, findingsStart + 200),
456
- };
457
- }
458
-
459
- // Parse the JSON
460
- let parsed: unknown;
461
- try {
462
- parsed = JSON.parse(jsonStr);
463
- } catch {
464
- return {
465
- success: false,
466
- error: 'invalid_json',
467
- preview: jsonStr.slice(0, 200),
468
- };
469
- }
470
-
471
- // Validate structure
472
- if (typeof parsed !== 'object' || parsed === null || !('findings' in parsed)) {
473
- return {
474
- success: false,
475
- error: 'missing_findings_key',
476
- preview: jsonStr.slice(0, 200),
477
- };
478
- }
479
-
480
- const findings = (parsed as { findings: unknown }).findings;
481
- if (!Array.isArray(findings)) {
482
- return {
483
- success: false,
484
- error: 'findings_not_array',
485
- preview: jsonStr.slice(0, 200),
486
- };
487
- }
488
-
489
- return { success: true, findings };
490
- }
491
-
492
- /** Max characters to send to LLM fallback (roughly ~8k tokens) */
493
- const LLM_FALLBACK_MAX_CHARS = 32000;
494
-
495
- /** Timeout for LLM fallback API calls in milliseconds */
496
- const LLM_FALLBACK_TIMEOUT_MS = 30000;
497
-
498
- /**
499
- * Truncate text for LLM fallback while preserving the findings JSON.
500
- *
501
- * Caller must ensure findings JSON exists in the text before calling.
502
- */
503
- export function truncateForLLMFallback(rawText: string, maxChars: number): string {
504
- if (rawText.length <= maxChars) {
505
- return rawText;
506
- }
507
-
508
- const findingsIndex = rawText.match(FINDINGS_JSON_START)?.index ?? -1;
509
-
510
- // If findings starts within our budget, simple truncation from start preserves it
511
- if (findingsIndex < maxChars - 20) {
512
- return rawText.slice(0, maxChars) + '\n[... truncated]';
513
- }
514
-
515
- // Findings is beyond our budget - skip to just before it
516
- // Keep minimal context (10% of budget or 200 chars, whichever is smaller)
517
- const markerOverhead = 40;
518
- const usableBudget = maxChars - markerOverhead;
519
- const contextBefore = Math.min(200, Math.floor(usableBudget * 0.1), findingsIndex);
520
- const startIndex = findingsIndex - contextBefore;
521
- const endIndex = startIndex + usableBudget;
522
-
523
- const truncatedContent = rawText.slice(startIndex, endIndex);
524
- const suffix = endIndex < rawText.length ? '\n[... truncated]' : '';
525
-
526
- return '[... truncated ...]\n' + truncatedContent + suffix;
527
- }
528
-
529
- /**
530
- * Extract findings from malformed output using LLM as a fallback.
531
- * Uses claude-haiku-4-5 for lightweight, fast extraction.
532
- */
533
- export async function extractFindingsWithLLM(
534
- rawText: string,
535
- apiKey?: string
536
- ): Promise<ExtractFindingsResult> {
537
- if (!apiKey) {
538
- return {
539
- success: false,
540
- error: 'no_api_key_for_fallback',
541
- preview: rawText.slice(0, 200),
542
- };
543
- }
544
-
545
- // If no findings anchor exists, there's nothing to extract
546
- if (!FINDINGS_JSON_START.test(rawText)) {
547
- return {
548
- success: false,
549
- error: 'no_findings_to_extract',
550
- preview: rawText.slice(0, 200),
551
- };
552
- }
553
-
554
- // Truncate input while preserving JSON boundaries
555
- const truncatedText = truncateForLLMFallback(rawText, LLM_FALLBACK_MAX_CHARS);
556
-
557
- try {
558
- const client = new Anthropic({ apiKey, timeout: LLM_FALLBACK_TIMEOUT_MS });
559
- const response = await client.messages.create({
560
- model: 'claude-haiku-4-5',
561
- max_tokens: 4096,
562
- messages: [
563
- {
564
- role: 'user',
565
- content: `Extract the findings JSON from this model output.
566
- Return ONLY valid JSON in format: {"findings": [...]}
567
- If no findings exist, return: {"findings": []}
568
-
569
- Model output:
570
- ${truncatedText}`,
571
- },
572
- ],
573
- });
574
-
575
- const content = response.content[0];
576
- if (!content || content.type !== 'text') {
577
- return {
578
- success: false,
579
- error: 'llm_unexpected_response',
580
- preview: rawText.slice(0, 200),
581
- };
582
- }
583
-
584
- // Parse the LLM response as JSON
585
- return extractFindingsJson(content.text);
586
- } catch (error) {
587
- const errorMessage = error instanceof Error ? error.message : String(error);
588
- return {
589
- success: false,
590
- error: `llm_extraction_failed: ${errorMessage}`,
591
- preview: rawText.slice(0, 200),
592
- };
593
- }
594
- }
595
-
596
- /**
597
- * Validate and normalize findings from extracted JSON.
598
- */
599
- function validateFindings(findings: unknown[], filename: string): Finding[] {
600
- const validated: Finding[] = [];
601
-
602
- for (const f of findings) {
603
- // Normalize location path before validation
604
- if (typeof f === 'object' && f !== null && 'location' in f) {
605
- const loc = (f as Record<string, unknown>)['location'];
606
- if (loc && typeof loc === 'object') {
607
- (loc as Record<string, unknown>)['path'] = filename;
608
- }
609
- }
610
-
611
- const result = FindingSchema.safeParse(f);
612
- if (result.success) {
613
- validated.push({
614
- ...result.data,
615
- location: result.data.location ? { ...result.data.location, path: filename } : undefined,
616
- });
617
- }
618
- }
619
-
620
- return validated;
621
- }
622
-
623
- /**
624
- * Parse findings from a hunk analysis result.
625
- * Uses a two-tier extraction strategy:
626
- * 1. Regex-based extraction (fast, handles well-formed output)
627
- * 2. LLM fallback using haiku (handles malformed output gracefully)
628
- */
629
- async function parseHunkOutput(
630
- result: SDKResultMessage,
631
- filename: string,
632
- apiKey?: string
633
- ): Promise<Finding[]> {
634
- if (result.subtype !== 'success') {
635
- // Silently return empty - the SDK already handles error reporting
636
- return [];
637
- }
638
-
639
- // Tier 1: Try regex-based extraction first (fast)
640
- const extracted = extractFindingsJson(result.result);
641
-
642
- if (extracted.success) {
643
- return validateFindings(extracted.findings, filename);
644
- }
645
-
646
- // Tier 2: Try LLM fallback for malformed output
647
- const fallback = await extractFindingsWithLLM(result.result, apiKey);
648
-
649
- if (fallback.success) {
650
- return validateFindings(fallback.findings, filename);
651
- }
652
-
653
- // Both tiers failed - return empty findings silently
654
- return [];
655
- }
656
-
657
- /**
658
- * Callbacks for prompt size reporting during hunk analysis.
659
- */
660
- interface HunkAnalysisCallbacks {
661
- lineRange: string;
662
- onLargePrompt?: (lineRange: string, chars: number, estimatedTokens: number) => void;
663
- onPromptSize?: (lineRange: string, systemChars: number, userChars: number, totalChars: number, estimatedTokens: number) => void;
664
- onRetry?: (lineRange: string, attempt: number, maxRetries: number, error: string, delayMs: number) => void;
665
- }
666
-
667
- /**
668
- * Execute a single SDK query attempt.
669
- */
670
- async function executeQuery(
671
- systemPrompt: string,
672
- userPrompt: string,
673
- repoPath: string,
674
- options: SkillRunnerOptions
675
- ): Promise<SDKResultMessage | undefined> {
676
- const { maxTurns = 50, model, abortController, pathToClaudeCodeExecutable } = options;
677
-
678
- const stream = query({
679
- prompt: userPrompt,
680
- options: {
681
- maxTurns,
682
- cwd: repoPath,
683
- systemPrompt,
684
- // Only allow read-only tools - context is already provided in the prompt
685
- allowedTools: ['Read', 'Grep'],
686
- // Explicitly block modification/side-effect tools as defense-in-depth
687
- disallowedTools: ['Write', 'Edit', 'Bash', 'WebFetch', 'WebSearch', 'Task', 'TodoWrite'],
688
- permissionMode: 'bypassPermissions',
689
- model,
690
- abortController,
691
- pathToClaudeCodeExecutable,
692
- },
693
- });
694
-
695
- let resultMessage: SDKResultMessage | undefined;
696
-
697
- for await (const message of stream) {
698
- if (message.type === 'result') {
699
- resultMessage = message;
700
- }
701
- }
702
-
703
- return resultMessage;
704
- }
705
-
706
- /**
707
- * Analyze a single hunk with retry logic for transient failures.
708
- */
709
- async function analyzeHunk(
710
- skill: SkillDefinition,
711
- hunkCtx: HunkWithContext,
712
- repoPath: string,
713
- options: SkillRunnerOptions,
714
- callbacks?: HunkAnalysisCallbacks,
715
- prContext?: PRPromptContext
716
- ): Promise<HunkAnalysisResult> {
717
- const { apiKey, abortController, retry } = options;
718
-
719
- const systemPrompt = buildHunkSystemPrompt(skill);
720
- const userPrompt = buildHunkUserPrompt(skill, hunkCtx, prContext);
721
-
722
- // Report prompt size information
723
- const systemChars = systemPrompt.length;
724
- const userChars = userPrompt.length;
725
- const totalChars = systemChars + userChars;
726
- const estimatedTokens = estimateTokens(totalChars);
727
-
728
- // Always call onPromptSize if provided (for debug mode)
729
- callbacks?.onPromptSize?.(callbacks.lineRange, systemChars, userChars, totalChars, estimatedTokens);
730
-
731
- // Warn about large prompts
732
- if (totalChars > LARGE_PROMPT_THRESHOLD_CHARS) {
733
- callbacks?.onLargePrompt?.(callbacks.lineRange, totalChars, estimatedTokens);
734
- }
735
-
736
- // Merge retry config with defaults
737
- const retryConfig: Required<RetryConfig> = {
738
- ...DEFAULT_RETRY_CONFIG,
739
- ...retry,
740
- };
741
-
742
- let lastError: unknown;
743
- // Track accumulated usage across retry attempts for accurate cost reporting
744
- const accumulatedUsage: UsageStats[] = [];
745
-
746
- for (let attempt = 0; attempt <= retryConfig.maxRetries; attempt++) {
747
- // Check for abort before each attempt
748
- if (abortController?.signal.aborted) {
749
- return { findings: [], usage: aggregateUsage(accumulatedUsage), failed: true };
750
- }
751
-
752
- try {
753
- const resultMessage = await executeQuery(systemPrompt, userPrompt, repoPath, options);
754
-
755
- if (!resultMessage) {
756
- return { findings: [], usage: aggregateUsage(accumulatedUsage), failed: true };
757
- }
758
-
759
- // Extract usage from the result, regardless of success/error status
760
- const usage = extractUsage(resultMessage);
761
- accumulatedUsage.push(usage);
762
-
763
- // Check if the SDK returned an error result (e.g., max turns, budget exceeded)
764
- const isError = resultMessage.is_error || resultMessage.subtype !== 'success';
765
-
766
- if (isError) {
767
- // SDK error - we have usage but no valid findings
768
- return {
769
- findings: [],
770
- usage: aggregateUsage(accumulatedUsage),
771
- failed: true,
772
- };
773
- }
774
-
775
- return {
776
- findings: await parseHunkOutput(resultMessage, hunkCtx.filename, apiKey),
777
- usage: aggregateUsage(accumulatedUsage),
778
- failed: false,
779
- };
780
- } catch (error) {
781
- lastError = error;
782
-
783
- // Authentication errors should surface immediately with helpful guidance
784
- if (isAuthenticationError(error)) {
785
- throw new WardenAuthenticationError();
786
- }
787
-
788
- // Don't retry if not a retryable error or we've exhausted retries
789
- if (!isRetryableError(error) || attempt >= retryConfig.maxRetries) {
790
- break;
791
- }
792
-
793
- // Calculate delay and wait before retry
794
- const delayMs = calculateRetryDelay(attempt, retryConfig);
795
- const errorMessage = error instanceof Error ? error.message : String(error);
796
-
797
- // Notify about retry in verbose mode
798
- callbacks?.onRetry?.(
799
- callbacks.lineRange,
800
- attempt + 1,
801
- retryConfig.maxRetries,
802
- errorMessage,
803
- delayMs
804
- );
805
-
806
- try {
807
- await sleep(delayMs, abortController?.signal);
808
- } catch {
809
- // Aborted during sleep
810
- return { findings: [], usage: aggregateUsage(accumulatedUsage), failed: true };
811
- }
812
- }
813
- }
814
-
815
- // All attempts failed - return failure with any accumulated usage
816
- // Log the final error for debugging if verbose
817
- if (options.verbose && lastError) {
818
- const errorMessage = lastError instanceof Error ? lastError.message : String(lastError);
819
- callbacks?.onRetry?.(
820
- callbacks.lineRange,
821
- retryConfig.maxRetries + 1,
822
- retryConfig.maxRetries,
823
- `Final failure: ${errorMessage}`,
824
- 0
825
- );
826
- }
827
-
828
- return { findings: [], usage: aggregateUsage(accumulatedUsage), failed: true };
829
- }
830
-
831
- /**
832
- * Deduplicate findings by id and location.
833
- */
834
- export function deduplicateFindings(findings: Finding[]): Finding[] {
835
- const seen = new Set<string>();
836
- return findings.filter((f) => {
837
- const key = `${f.id}:${f.location?.path}:${f.location?.startLine}`;
838
- if (seen.has(key)) return false;
839
- seen.add(key);
840
- return true;
841
- });
842
- }
843
-
844
- /**
845
- * A file prepared for analysis with its hunks.
846
- */
847
- export interface PreparedFile {
848
- filename: string;
849
- hunks: HunkWithContext[];
850
- }
851
-
852
- function groupHunksByFile(hunks: HunkWithContext[]): PreparedFile[] {
853
- const fileMap = new Map<string, HunkWithContext[]>();
854
-
855
- for (const hunk of hunks) {
856
- const existing = fileMap.get(hunk.filename);
857
- if (existing) {
858
- existing.push(hunk);
859
- } else {
860
- fileMap.set(hunk.filename, [hunk]);
861
- }
862
- }
863
-
864
- return Array.from(fileMap, ([filename, fileHunks]) => ({ filename, hunks: fileHunks }));
865
- }
866
-
867
- /**
868
- * Get line range string for a hunk.
869
- */
870
- function getHunkLineRange(hunk: HunkWithContext): string {
871
- const start = hunk.hunk.newStart;
872
- const end = start + hunk.hunk.newCount - 1;
873
- return start === end ? `${start}` : `${start}-${end}`;
874
- }
875
-
876
- /**
877
- * Attach elapsed time to findings if skill start time is available.
878
- */
879
- function attachElapsedTime(findings: Finding[], skillStartTime: number | undefined): void {
880
- if (skillStartTime === undefined) return;
881
- const elapsedMs = Date.now() - skillStartTime;
882
- for (const finding of findings) {
883
- finding.elapsedMs = elapsedMs;
884
- }
885
- }
886
-
887
- /**
888
- * Options for preparing files for analysis.
889
- */
890
- export interface PrepareFilesOptions {
891
- /** Lines of context to include around each hunk */
892
- contextLines?: number;
893
- /** Chunking configuration for file patterns and coalescing */
894
- chunking?: ChunkingConfig;
895
- }
896
-
897
- /**
898
- * Result from preparing files for analysis.
899
- */
900
- export interface PrepareFilesResult {
901
- /** Files prepared for analysis */
902
- files: PreparedFile[];
903
- /** Files that were skipped due to chunking patterns */
904
- skippedFiles: SkippedFile[];
905
- }
906
-
907
- /**
908
- * Prepare files for analysis by parsing patches into hunks with context.
909
- * Returns files that have changes to analyze and files that were skipped.
910
- */
911
- export function prepareFiles(
912
- context: EventContext,
913
- options: PrepareFilesOptions = {}
914
- ): PrepareFilesResult {
915
- const { contextLines = 20, chunking } = options;
916
-
917
- if (!context.pullRequest) {
918
- return { files: [], skippedFiles: [] };
919
- }
920
-
921
- const pr = context.pullRequest;
922
- const allHunks: HunkWithContext[] = [];
923
- const skippedFiles: SkippedFile[] = [];
924
-
925
- for (const file of pr.files) {
926
- if (!file.patch) continue;
927
-
928
- // Check if this file should be skipped based on chunking patterns
929
- const mode = classifyFile(file.filename, chunking?.filePatterns);
930
- if (mode === 'skip') {
931
- skippedFiles.push({
932
- filename: file.filename,
933
- reason: 'builtin', // Could be enhanced to track which pattern matched
934
- });
935
- continue;
936
- }
937
-
938
- const statusMap: Record<string, 'added' | 'removed' | 'modified' | 'renamed'> = {
939
- added: 'added',
940
- removed: 'removed',
941
- modified: 'modified',
942
- renamed: 'renamed',
943
- copied: 'added',
944
- changed: 'modified',
945
- unchanged: 'modified',
946
- };
947
- const status = statusMap[file.status] ?? 'modified';
948
-
949
- const diff = parseFileDiff(file.filename, file.patch, status);
950
-
951
- // Apply hunk coalescing if enabled (default: enabled)
952
- const coalesceEnabled = chunking?.coalesce?.enabled !== false;
953
- const hunks = coalesceEnabled
954
- ? coalesceHunks(diff.hunks, {
955
- maxGapLines: chunking?.coalesce?.maxGapLines,
956
- maxChunkSize: chunking?.coalesce?.maxChunkSize,
957
- })
958
- : diff.hunks;
959
-
960
- const hunksWithContext = expandDiffContext(context.repoPath, { ...diff, hunks }, contextLines);
961
- allHunks.push(...hunksWithContext);
962
- }
963
-
964
- return {
965
- files: groupHunksByFile(allHunks),
966
- skippedFiles,
967
- };
968
- }
969
-
970
- /**
971
- * Callbacks for per-file analysis progress.
972
- */
973
- export interface FileAnalysisCallbacks {
974
- skillStartTime?: number;
975
- onHunkStart?: (hunkNum: number, totalHunks: number, lineRange: string) => void;
976
- onHunkComplete?: (hunkNum: number, findings: Finding[]) => void;
977
- /** Called when a prompt exceeds the large prompt threshold */
978
- onLargePrompt?: (lineRange: string, chars: number, estimatedTokens: number) => void;
979
- /** Called with prompt size info in debug mode */
980
- onPromptSize?: (lineRange: string, systemChars: number, userChars: number, totalChars: number, estimatedTokens: number) => void;
981
- /** Called when a retry attempt is made (verbose mode) */
982
- onRetry?: (lineRange: string, attempt: number, maxRetries: number, error: string, delayMs: number) => void;
983
- }
984
-
985
- /**
986
- * Result from analyzing a single file.
987
- */
988
- export interface FileAnalysisResult {
989
- filename: string;
990
- findings: Finding[];
991
- usage: UsageStats;
992
- /** Number of hunks that failed to analyze */
993
- failedHunks: number;
994
- }
995
-
996
- /**
997
- * Analyze a single prepared file's hunks.
998
- */
999
- export async function analyzeFile(
1000
- skill: SkillDefinition,
1001
- file: PreparedFile,
1002
- repoPath: string,
1003
- options: SkillRunnerOptions = {},
1004
- callbacks?: FileAnalysisCallbacks,
1005
- prContext?: PRPromptContext
1006
- ): Promise<FileAnalysisResult> {
1007
- const { abortController } = options;
1008
- const fileFindings: Finding[] = [];
1009
- const fileUsage: UsageStats[] = [];
1010
- let failedHunks = 0;
1011
-
1012
- for (const [hunkIndex, hunk] of file.hunks.entries()) {
1013
- if (abortController?.signal.aborted) break;
1014
-
1015
- const lineRange = getHunkLineRange(hunk);
1016
- callbacks?.onHunkStart?.(hunkIndex + 1, file.hunks.length, lineRange);
1017
-
1018
- const hunkCallbacks: HunkAnalysisCallbacks | undefined = callbacks
1019
- ? {
1020
- lineRange,
1021
- onLargePrompt: callbacks.onLargePrompt,
1022
- onPromptSize: callbacks.onPromptSize,
1023
- onRetry: callbacks.onRetry,
1024
- }
1025
- : undefined;
1026
-
1027
- const result = await analyzeHunk(skill, hunk, repoPath, options, hunkCallbacks, prContext);
1028
-
1029
- if (result.failed) {
1030
- failedHunks++;
1031
- }
1032
-
1033
- attachElapsedTime(result.findings, callbacks?.skillStartTime);
1034
- callbacks?.onHunkComplete?.(hunkIndex + 1, result.findings);
1035
-
1036
- fileFindings.push(...result.findings);
1037
- fileUsage.push(result.usage);
1038
- }
1039
-
1040
- return {
1041
- filename: file.filename,
1042
- findings: fileFindings,
1043
- usage: aggregateUsage(fileUsage),
1044
- failedHunks,
1045
- };
1046
- }
1047
-
1048
- /**
1049
- * Run a skill on a PR, analyzing each hunk separately.
1050
- */
1051
- export async function runSkill(
1052
- skill: SkillDefinition,
1053
- context: EventContext,
1054
- options: SkillRunnerOptions = {}
1055
- ): Promise<SkillReport> {
1056
- const { parallel = true, callbacks, abortController } = options;
1057
- const startTime = Date.now();
1058
-
1059
- if (!context.pullRequest) {
1060
- throw new SkillRunnerError('Pull request context required for skill execution');
1061
- }
1062
-
1063
- const { files: fileHunks, skippedFiles } = prepareFiles(context, {
1064
- contextLines: options.contextLines,
1065
- // Note: chunking config should come from the caller (e.g., from warden.toml defaults)
1066
- // For now, we use built-in defaults. The caller can pass explicit chunking config.
1067
- });
1068
-
1069
- if (fileHunks.length === 0) {
1070
- const report: SkillReport = {
1071
- skill: skill.name,
1072
- summary: 'No code changes to analyze',
1073
- findings: [],
1074
- usage: emptyUsage(),
1075
- durationMs: Date.now() - startTime,
1076
- };
1077
- if (skippedFiles.length > 0) {
1078
- report.skippedFiles = skippedFiles;
1079
- }
1080
- return report;
1081
- }
1082
-
1083
- const totalFiles = fileHunks.length;
1084
- const allFindings: Finding[] = [];
1085
-
1086
- // Track all usage stats for aggregation
1087
- const allUsage: UsageStats[] = [];
1088
-
1089
- // Track failed hunks across all files
1090
- let totalFailedHunks = 0;
1091
-
1092
- // Build PR context for inclusion in prompts (helps LLM understand the full scope of changes)
1093
- const prContext: PRPromptContext = {
1094
- changedFiles: context.pullRequest.files.map((f) => f.filename),
1095
- title: context.pullRequest.title,
1096
- body: context.pullRequest.body,
1097
- };
1098
-
1099
- /**
1100
- * Process all hunks for a single file sequentially.
1101
- * Wraps analyzeFile with progress callbacks.
1102
- */
1103
- async function processFile(
1104
- fileHunkEntry: PreparedFile,
1105
- fileIndex: number
1106
- ): Promise<FileAnalysisResult> {
1107
- const { filename } = fileHunkEntry;
1108
-
1109
- callbacks?.onFileStart?.(filename, fileIndex, totalFiles);
1110
-
1111
- const fileCallbacks: FileAnalysisCallbacks = {
1112
- skillStartTime: callbacks?.skillStartTime,
1113
- onHunkStart: (hunkNum, totalHunks, lineRange) => {
1114
- callbacks?.onHunkStart?.(filename, hunkNum, totalHunks, lineRange);
1115
- },
1116
- onHunkComplete: (hunkNum, findings) => {
1117
- callbacks?.onHunkComplete?.(filename, hunkNum, findings);
1118
- },
1119
- onLargePrompt: callbacks?.onLargePrompt
1120
- ? (lineRange, chars, estimatedTokens) => {
1121
- callbacks.onLargePrompt?.(filename, lineRange, chars, estimatedTokens);
1122
- }
1123
- : undefined,
1124
- onPromptSize: callbacks?.onPromptSize
1125
- ? (lineRange, systemChars, userChars, totalChars, estimatedTokens) => {
1126
- callbacks.onPromptSize?.(filename, lineRange, systemChars, userChars, totalChars, estimatedTokens);
1127
- }
1128
- : undefined,
1129
- onRetry: callbacks?.onRetry
1130
- ? (lineRange, attempt, maxRetries, error, delayMs) => {
1131
- callbacks.onRetry?.(filename, lineRange, attempt, maxRetries, error, delayMs);
1132
- }
1133
- : undefined,
1134
- };
1135
-
1136
- const result = await analyzeFile(skill, fileHunkEntry, context.repoPath, options, fileCallbacks, prContext);
1137
-
1138
- callbacks?.onFileComplete?.(filename, fileIndex, totalFiles);
1139
-
1140
- return result;
1141
- }
1142
-
1143
- // Process files - parallel or sequential based on options
1144
- if (parallel) {
1145
- // Process files in parallel with concurrency limit
1146
- const fileConcurrency = options.concurrency ?? DEFAULT_FILE_CONCURRENCY;
1147
- const batchDelayMs = options.batchDelayMs ?? 0;
1148
-
1149
- for (let i = 0; i < fileHunks.length; i += fileConcurrency) {
1150
- // Check for abort before starting new batch
1151
- if (abortController?.signal.aborted) break;
1152
-
1153
- // Apply rate limiting delay between batches (not before the first batch)
1154
- if (i > 0 && batchDelayMs > 0) {
1155
- await new Promise((resolve) => setTimeout(resolve, batchDelayMs));
1156
- }
1157
-
1158
- const batch = fileHunks.slice(i, i + fileConcurrency);
1159
- const batchPromises = batch.map((fileHunkEntry, batchIndex) =>
1160
- processFile(fileHunkEntry, i + batchIndex)
1161
- );
1162
-
1163
- const batchResults = await Promise.all(batchPromises);
1164
- for (const result of batchResults) {
1165
- allFindings.push(...result.findings);
1166
- allUsage.push(result.usage);
1167
- totalFailedHunks += result.failedHunks;
1168
- }
1169
- }
1170
- } else {
1171
- // Process files sequentially
1172
- for (const [fileIndex, fileHunkEntry] of fileHunks.entries()) {
1173
- // Check for abort before starting new file
1174
- if (abortController?.signal.aborted) break;
1175
-
1176
- const result = await processFile(fileHunkEntry, fileIndex);
1177
- allFindings.push(...result.findings);
1178
- allUsage.push(result.usage);
1179
- totalFailedHunks += result.failedHunks;
1180
- }
1181
- }
1182
-
1183
- // Deduplicate findings
1184
- const uniqueFindings = deduplicateFindings(allFindings);
1185
-
1186
- // Generate summary
1187
- const summary = generateSummary(skill.name, uniqueFindings);
1188
-
1189
- // Aggregate usage across all hunks
1190
- const totalUsage = aggregateUsage(allUsage);
1191
-
1192
- const report: SkillReport = {
1193
- skill: skill.name,
1194
- summary,
1195
- findings: uniqueFindings,
1196
- usage: totalUsage,
1197
- durationMs: Date.now() - startTime,
1198
- };
1199
- if (skippedFiles.length > 0) {
1200
- report.skippedFiles = skippedFiles;
1201
- }
1202
- if (totalFailedHunks > 0) {
1203
- report.failedHunks = totalFailedHunks;
1204
- }
1205
- return report;
1206
- }
1207
-
1208
- /**
1209
- * Generate a summary of findings.
1210
- */
1211
- export function generateSummary(skillName: string, findings: Finding[]): string {
1212
- if (findings.length === 0) {
1213
- return `${skillName}: No issues found`;
1214
- }
1215
-
1216
- const counts: Record<string, number> = {};
1217
- for (const f of findings) {
1218
- counts[f.severity] = (counts[f.severity] ?? 0) + 1;
1219
- }
1220
-
1221
- const parts: string[] = [];
1222
- if (counts['critical']) parts.push(`${counts['critical']} critical`);
1223
- if (counts['high']) parts.push(`${counts['high']} high`);
1224
- if (counts['medium']) parts.push(`${counts['medium']} medium`);
1225
- if (counts['low']) parts.push(`${counts['low']} low`);
1226
- if (counts['info']) parts.push(`${counts['info']} info`);
1227
-
1228
- return `${skillName}: Found ${findings.length} issue${findings.length === 1 ? '' : 's'} (${parts.join(', ')})`;
1229
- }
1230
-
1231
- // Legacy export for backwards compatibility
1232
- export { buildHunkSystemPrompt as buildSystemPrompt };