@polka-codes/cli 0.10.22 → 0.10.24

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 (350) hide show
  1. package/dist/index.js +3990 -353
  2. package/package.json +4 -4
  3. package/dist/ApiProviderConfig.js +0 -57
  4. package/dist/ApiProviderConfig.js.map +0 -1
  5. package/dist/ApiProviderConfig.test.js +0 -278
  6. package/dist/ApiProviderConfig.test.js.map +0 -1
  7. package/dist/agent/advanced-discovery.js +0 -604
  8. package/dist/agent/advanced-discovery.js.map +0 -1
  9. package/dist/agent/config.js +0 -139
  10. package/dist/agent/config.js.map +0 -1
  11. package/dist/agent/config.test.js +0 -140
  12. package/dist/agent/config.test.js.map +0 -1
  13. package/dist/agent/constants.js +0 -172
  14. package/dist/agent/constants.js.map +0 -1
  15. package/dist/agent/constants.test.js +0 -132
  16. package/dist/agent/constants.test.js.map +0 -1
  17. package/dist/agent/debug-logger.js +0 -281
  18. package/dist/agent/debug-logger.js.map +0 -1
  19. package/dist/agent/debug-logger.test.js +0 -294
  20. package/dist/agent/debug-logger.test.js.map +0 -1
  21. package/dist/agent/error-handling.js +0 -114
  22. package/dist/agent/error-handling.js.map +0 -1
  23. package/dist/agent/error-handling.test.js +0 -191
  24. package/dist/agent/error-handling.test.js.map +0 -1
  25. package/dist/agent/errors.js +0 -301
  26. package/dist/agent/errors.js.map +0 -1
  27. package/dist/agent/executor.js +0 -206
  28. package/dist/agent/executor.js.map +0 -1
  29. package/dist/agent/executor.test.js +0 -228
  30. package/dist/agent/executor.test.js.map +0 -1
  31. package/dist/agent/goal-decomposer.js +0 -281
  32. package/dist/agent/goal-decomposer.js.map +0 -1
  33. package/dist/agent/goal-decomposer.test.js +0 -225
  34. package/dist/agent/goal-decomposer.test.js.map +0 -1
  35. package/dist/agent/health-monitor.js +0 -89
  36. package/dist/agent/health-monitor.js.map +0 -1
  37. package/dist/agent/improvement-loop.js +0 -177
  38. package/dist/agent/improvement-loop.js.map +0 -1
  39. package/dist/agent/index.js +0 -38
  40. package/dist/agent/index.js.map +0 -1
  41. package/dist/agent/metrics.js +0 -158
  42. package/dist/agent/metrics.js.map +0 -1
  43. package/dist/agent/metrics.test.js +0 -311
  44. package/dist/agent/metrics.test.js.map +0 -1
  45. package/dist/agent/orchestrator.js +0 -438
  46. package/dist/agent/orchestrator.js.map +0 -1
  47. package/dist/agent/planner.js +0 -199
  48. package/dist/agent/planner.js.map +0 -1
  49. package/dist/agent/planner.test.js +0 -135
  50. package/dist/agent/planner.test.js.map +0 -1
  51. package/dist/agent/progress.js +0 -298
  52. package/dist/agent/progress.js.map +0 -1
  53. package/dist/agent/progress.test.js +0 -255
  54. package/dist/agent/progress.test.js.map +0 -1
  55. package/dist/agent/resource-monitor.js +0 -114
  56. package/dist/agent/resource-monitor.js.map +0 -1
  57. package/dist/agent/safety/approval.js +0 -178
  58. package/dist/agent/safety/approval.js.map +0 -1
  59. package/dist/agent/safety/approval.test.js +0 -142
  60. package/dist/agent/safety/approval.test.js.map +0 -1
  61. package/dist/agent/safety/checks.js +0 -152
  62. package/dist/agent/safety/checks.js.map +0 -1
  63. package/dist/agent/safety/checks.test.js +0 -89
  64. package/dist/agent/safety/checks.test.js.map +0 -1
  65. package/dist/agent/safety/interrupt.js +0 -92
  66. package/dist/agent/safety/interrupt.js.map +0 -1
  67. package/dist/agent/safety/interrupt.test.js +0 -53
  68. package/dist/agent/safety/interrupt.test.js.map +0 -1
  69. package/dist/agent/session.js +0 -117
  70. package/dist/agent/session.js.map +0 -1
  71. package/dist/agent/session.test.js +0 -213
  72. package/dist/agent/session.test.js.map +0 -1
  73. package/dist/agent/state-manager.js +0 -287
  74. package/dist/agent/state-manager.js.map +0 -1
  75. package/dist/agent/task-discovery.js +0 -433
  76. package/dist/agent/task-discovery.js.map +0 -1
  77. package/dist/agent/task-discovery.test.js +0 -40
  78. package/dist/agent/task-discovery.test.js.map +0 -1
  79. package/dist/agent/task-history.js +0 -128
  80. package/dist/agent/task-history.js.map +0 -1
  81. package/dist/agent/task-prioritizer.js +0 -286
  82. package/dist/agent/task-prioritizer.js.map +0 -1
  83. package/dist/agent/test-fixtures.js +0 -112
  84. package/dist/agent/test-fixtures.js.map +0 -1
  85. package/dist/agent/types.js +0 -15
  86. package/dist/agent/types.js.map +0 -1
  87. package/dist/agent/workflow-adapter.js +0 -219
  88. package/dist/agent/workflow-adapter.js.map +0 -1
  89. package/dist/agent/workflow-adapter.test.js +0 -11
  90. package/dist/agent/workflow-adapter.test.js.map +0 -1
  91. package/dist/agent/working-dir-discovery.js +0 -54
  92. package/dist/agent/working-dir-discovery.js.map +0 -1
  93. package/dist/agent/working-space.js +0 -484
  94. package/dist/agent/working-space.js.map +0 -1
  95. package/dist/agent/working-space.test.js +0 -436
  96. package/dist/agent/working-space.test.js.map +0 -1
  97. package/dist/api.js +0 -279
  98. package/dist/api.js.map +0 -1
  99. package/dist/builtin-commands.js +0 -20
  100. package/dist/builtin-commands.js.map +0 -1
  101. package/dist/chunk-2LRQ2QH6.js +0 -1353
  102. package/dist/chunk-FSNPWI3C.js +0 -128
  103. package/dist/chunk-HB7PTE3H.js +0 -176
  104. package/dist/chunk-LLMPMGV3.js +0 -140
  105. package/dist/chunk-NRDSZGMF.js +0 -675
  106. package/dist/chunk-UEEU3SCC.js +0 -390
  107. package/dist/chunk-YPUL66UK.js +0 -277
  108. package/dist/chunk-ZS4K5RFU.js +0 -176
  109. package/dist/chunk-ZU4UU65A.js +0 -40
  110. package/dist/code.workflow-5TAWK2DE.js +0 -10
  111. package/dist/commandSummarizer.js +0 -96
  112. package/dist/commandSummarizer.js.map +0 -1
  113. package/dist/commands/__tests__/command-detection.integration.test.js +0 -238
  114. package/dist/commands/__tests__/command-detection.integration.test.js.map +0 -1
  115. package/dist/commands/__tests__/script-generator.integration.test.js +0 -271
  116. package/dist/commands/__tests__/script-generator.integration.test.js.map +0 -1
  117. package/dist/commands/agent.js +0 -218
  118. package/dist/commands/agent.js.map +0 -1
  119. package/dist/commands/code.js +0 -102
  120. package/dist/commands/code.js.map +0 -1
  121. package/dist/commands/command.constants.js +0 -13
  122. package/dist/commands/command.constants.js.map +0 -1
  123. package/dist/commands/commit.js +0 -17
  124. package/dist/commands/commit.js.map +0 -1
  125. package/dist/commands/fix.js +0 -17
  126. package/dist/commands/fix.js.map +0 -1
  127. package/dist/commands/init.js +0 -501
  128. package/dist/commands/init.js.map +0 -1
  129. package/dist/commands/mcp-server.js +0 -122
  130. package/dist/commands/mcp-server.js.map +0 -1
  131. package/dist/commands/memory.js +0 -410
  132. package/dist/commands/memory.js.map +0 -1
  133. package/dist/commands/memory.test.js +0 -453
  134. package/dist/commands/memory.test.js.map +0 -1
  135. package/dist/commands/meta.js +0 -142
  136. package/dist/commands/meta.js.map +0 -1
  137. package/dist/commands/plan.js +0 -39
  138. package/dist/commands/plan.js.map +0 -1
  139. package/dist/commands/pr.js +0 -14
  140. package/dist/commands/pr.js.map +0 -1
  141. package/dist/commands/review-json.test.js +0 -33
  142. package/dist/commands/review-json.test.js.map +0 -1
  143. package/dist/commands/review.js +0 -137
  144. package/dist/commands/review.js.map +0 -1
  145. package/dist/commands/review.usage.test.js +0 -41
  146. package/dist/commands/review.usage.test.js.map +0 -1
  147. package/dist/commands/run.js +0 -107
  148. package/dist/commands/run.js.map +0 -1
  149. package/dist/commands/skills.js +0 -175
  150. package/dist/commands/skills.js.map +0 -1
  151. package/dist/commands/task.js +0 -34
  152. package/dist/commands/task.js.map +0 -1
  153. package/dist/commands/workflow.js +0 -117
  154. package/dist/commands/workflow.js.map +0 -1
  155. package/dist/commit.workflow-Z64PNSTS.js +0 -9
  156. package/dist/configPrompt.js +0 -39
  157. package/dist/configPrompt.js.map +0 -1
  158. package/dist/env.js +0 -22
  159. package/dist/env.js.map +0 -1
  160. package/dist/errors.js +0 -132
  161. package/dist/errors.js.map +0 -1
  162. package/dist/errors.test.js +0 -21
  163. package/dist/errors.test.js.map +0 -1
  164. package/dist/file-attachments.js +0 -77
  165. package/dist/file-attachments.js.map +0 -1
  166. package/dist/file-attachments.test.js +0 -214
  167. package/dist/file-attachments.test.js.map +0 -1
  168. package/dist/fix.workflow-KLHJU5Z6.js +0 -7
  169. package/dist/getModel.js +0 -229
  170. package/dist/getModel.js.map +0 -1
  171. package/dist/getModel.test.js +0 -67
  172. package/dist/getModel.test.js.map +0 -1
  173. package/dist/getProviderOptions.js +0 -58
  174. package/dist/getProviderOptions.js.map +0 -1
  175. package/dist/git-operations.js +0 -363
  176. package/dist/git-operations.js.map +0 -1
  177. package/dist/git-operations.test.js +0 -81
  178. package/dist/git-operations.test.js.map +0 -1
  179. package/dist/index.js.map +0 -1
  180. package/dist/logger.js +0 -41
  181. package/dist/logger.js.map +0 -1
  182. package/dist/mcp/client.js +0 -11
  183. package/dist/mcp/client.js.map +0 -1
  184. package/dist/mcp/error-scenarios.test.js +0 -206
  185. package/dist/mcp/error-scenarios.test.js.map +0 -1
  186. package/dist/mcp/errors.js +0 -63
  187. package/dist/mcp/errors.js.map +0 -1
  188. package/dist/mcp/index.js +0 -9
  189. package/dist/mcp/index.js.map +0 -1
  190. package/dist/mcp/manager.js +0 -231
  191. package/dist/mcp/manager.js.map +0 -1
  192. package/dist/mcp/manager.test.js +0 -40
  193. package/dist/mcp/manager.test.js.map +0 -1
  194. package/dist/mcp/sdk-client.js +0 -166
  195. package/dist/mcp/sdk-client.js.map +0 -1
  196. package/dist/mcp/shared-types.js +0 -3
  197. package/dist/mcp/shared-types.js.map +0 -1
  198. package/dist/mcp/tools-integration.test.js +0 -198
  199. package/dist/mcp/tools-integration.test.js.map +0 -1
  200. package/dist/mcp/tools.js +0 -60
  201. package/dist/mcp/tools.js.map +0 -1
  202. package/dist/mcp/transport.js +0 -257
  203. package/dist/mcp/transport.js.map +0 -1
  204. package/dist/mcp/types.js +0 -3
  205. package/dist/mcp/types.js.map +0 -1
  206. package/dist/mcp-server/index.js +0 -5
  207. package/dist/mcp-server/index.js.map +0 -1
  208. package/dist/mcp-server/plan-formatting.test.js +0 -74
  209. package/dist/mcp-server/plan-formatting.test.js.map +0 -1
  210. package/dist/mcp-server/sdk-server.js +0 -102
  211. package/dist/mcp-server/sdk-server.js.map +0 -1
  212. package/dist/mcp-server/sdk-server.test.js +0 -363
  213. package/dist/mcp-server/sdk-server.test.js.map +0 -1
  214. package/dist/mcp-server/tools.js +0 -785
  215. package/dist/mcp-server/tools.js.map +0 -1
  216. package/dist/mcp-server/types.js +0 -3
  217. package/dist/mcp-server/types.js.map +0 -1
  218. package/dist/options.js +0 -85
  219. package/dist/options.js.map +0 -1
  220. package/dist/options.test.js +0 -177
  221. package/dist/options.test.js.map +0 -1
  222. package/dist/plan.workflow-P2Y6W4FA.js +0 -8
  223. package/dist/prices.js +0 -61
  224. package/dist/prices.js.map +0 -1
  225. package/dist/prices.test.js +0 -148
  226. package/dist/prices.test.js.map +0 -1
  227. package/dist/review.workflow-I7RHWKU7.js +0 -8
  228. package/dist/runWorkflow.js +0 -313
  229. package/dist/runWorkflow.js.map +0 -1
  230. package/dist/script/__tests__/execution.integration.test.js +0 -274
  231. package/dist/script/__tests__/execution.integration.test.js.map +0 -1
  232. package/dist/script/__tests__/runner.test.js +0 -176
  233. package/dist/script/__tests__/runner.test.js.map +0 -1
  234. package/dist/script/__tests__/validator.test.js +0 -180
  235. package/dist/script/__tests__/validator.test.js.map +0 -1
  236. package/dist/script/executor.js +0 -127
  237. package/dist/script/executor.js.map +0 -1
  238. package/dist/script/index.js +0 -4
  239. package/dist/script/index.js.map +0 -1
  240. package/dist/script/runner.js +0 -258
  241. package/dist/script/runner.js.map +0 -1
  242. package/dist/sdk-client-KBYJRPEG.js +0 -155
  243. package/dist/skillIntegration.js +0 -46
  244. package/dist/skillIntegration.js.map +0 -1
  245. package/dist/skillIntegration.test.js +0 -128
  246. package/dist/skillIntegration.test.js.map +0 -1
  247. package/dist/test/utils.js +0 -200
  248. package/dist/test/utils.js.map +0 -1
  249. package/dist/test/workflow-fixtures.js +0 -120
  250. package/dist/test/workflow-fixtures.js.map +0 -1
  251. package/dist/tool-implementations.js +0 -521
  252. package/dist/tool-implementations.js.map +0 -1
  253. package/dist/tool-implementations.skill-tools.test.js +0 -106
  254. package/dist/tool-implementations.skill-tools.test.js.map +0 -1
  255. package/dist/tools/getTodoItem.js +0 -33
  256. package/dist/tools/getTodoItem.js.map +0 -1
  257. package/dist/tools/gitDiff.js +0 -108
  258. package/dist/tools/gitDiff.js.map +0 -1
  259. package/dist/tools/index.js +0 -8
  260. package/dist/tools/index.js.map +0 -1
  261. package/dist/tools/listMemoryTopics.js +0 -24
  262. package/dist/tools/listMemoryTopics.js.map +0 -1
  263. package/dist/tools/listTodoItems.js +0 -35
  264. package/dist/tools/listTodoItems.js.map +0 -1
  265. package/dist/tools/listTodoItems.test.js +0 -89
  266. package/dist/tools/listTodoItems.test.js.map +0 -1
  267. package/dist/tools/readMemory.js +0 -33
  268. package/dist/tools/readMemory.js.map +0 -1
  269. package/dist/tools/updateMemory.js +0 -62
  270. package/dist/tools/updateMemory.js.map +0 -1
  271. package/dist/tools/updateMemory.test.js +0 -109
  272. package/dist/tools/updateMemory.test.js.map +0 -1
  273. package/dist/tools/updateTodoItem.js +0 -31
  274. package/dist/tools/updateTodoItem.js.map +0 -1
  275. package/dist/tools/utils/diffLineNumbers.js +0 -178
  276. package/dist/tools/utils/diffLineNumbers.js.map +0 -1
  277. package/dist/utils/cacheControl.js +0 -59
  278. package/dist/utils/cacheControl.js.map +0 -1
  279. package/dist/utils/cacheControl.test.js +0 -128
  280. package/dist/utils/cacheControl.test.js.map +0 -1
  281. package/dist/utils/command.js +0 -50
  282. package/dist/utils/command.js.map +0 -1
  283. package/dist/utils/shell.js +0 -56
  284. package/dist/utils/shell.js.map +0 -1
  285. package/dist/utils/userInput.js +0 -47
  286. package/dist/utils/userInput.js.map +0 -1
  287. package/dist/workflow-tools.js +0 -21
  288. package/dist/workflow-tools.js.map +0 -1
  289. package/dist/workflows/agent-builder.js +0 -90
  290. package/dist/workflows/agent-builder.js.map +0 -1
  291. package/dist/workflows/agent-builder.test.js +0 -115
  292. package/dist/workflows/agent-builder.test.js.map +0 -1
  293. package/dist/workflows/code.workflow.js +0 -145
  294. package/dist/workflows/code.workflow.js.map +0 -1
  295. package/dist/workflows/commit.workflow.js +0 -111
  296. package/dist/workflows/commit.workflow.js.map +0 -1
  297. package/dist/workflows/commit.workflow.test.js +0 -141
  298. package/dist/workflows/commit.workflow.test.js.map +0 -1
  299. package/dist/workflows/fix.workflow.js +0 -172
  300. package/dist/workflows/fix.workflow.js.map +0 -1
  301. package/dist/workflows/fix.workflow.test.js +0 -137
  302. package/dist/workflows/fix.workflow.test.js.map +0 -1
  303. package/dist/workflows/git-file-tools.js +0 -408
  304. package/dist/workflows/git-file-tools.js.map +0 -1
  305. package/dist/workflows/index.js +0 -12
  306. package/dist/workflows/index.js.map +0 -1
  307. package/dist/workflows/init-interactive.workflow.js +0 -198
  308. package/dist/workflows/init-interactive.workflow.js.map +0 -1
  309. package/dist/workflows/init.workflow.js +0 -41
  310. package/dist/workflows/init.workflow.js.map +0 -1
  311. package/dist/workflows/meta.workflow.js +0 -107
  312. package/dist/workflows/meta.workflow.js.map +0 -1
  313. package/dist/workflows/plan.workflow.js +0 -275
  314. package/dist/workflows/plan.workflow.js.map +0 -1
  315. package/dist/workflows/plan.workflow.test.js +0 -419
  316. package/dist/workflows/plan.workflow.test.js.map +0 -1
  317. package/dist/workflows/pr.workflow.js +0 -54
  318. package/dist/workflows/pr.workflow.js.map +0 -1
  319. package/dist/workflows/pr.workflow.test.js +0 -98
  320. package/dist/workflows/pr.workflow.test.js.map +0 -1
  321. package/dist/workflows/prompts/coder.js +0 -85
  322. package/dist/workflows/prompts/coder.js.map +0 -1
  323. package/dist/workflows/prompts/commit.js +0 -16
  324. package/dist/workflows/prompts/commit.js.map +0 -1
  325. package/dist/workflows/prompts/fix.js +0 -44
  326. package/dist/workflows/prompts/fix.js.map +0 -1
  327. package/dist/workflows/prompts/index.js +0 -10
  328. package/dist/workflows/prompts/index.js.map +0 -1
  329. package/dist/workflows/prompts/init.js +0 -48
  330. package/dist/workflows/prompts/init.js.map +0 -1
  331. package/dist/workflows/prompts/meta.js +0 -17
  332. package/dist/workflows/prompts/meta.js.map +0 -1
  333. package/dist/workflows/prompts/plan.js +0 -212
  334. package/dist/workflows/prompts/plan.js.map +0 -1
  335. package/dist/workflows/prompts/pr.js +0 -15
  336. package/dist/workflows/prompts/pr.js.map +0 -1
  337. package/dist/workflows/prompts/review.js +0 -145
  338. package/dist/workflows/prompts/review.js.map +0 -1
  339. package/dist/workflows/prompts/shared.js +0 -93
  340. package/dist/workflows/prompts/shared.js.map +0 -1
  341. package/dist/workflows/review.workflow.js +0 -357
  342. package/dist/workflows/review.workflow.js.map +0 -1
  343. package/dist/workflows/task.workflow.js +0 -47
  344. package/dist/workflows/task.workflow.js.map +0 -1
  345. package/dist/workflows/testing/helper.js +0 -41
  346. package/dist/workflows/testing/helper.js.map +0 -1
  347. package/dist/workflows/workflow.utils.js +0 -351
  348. package/dist/workflows/workflow.utils.js.map +0 -1
  349. package/dist/workflows/workflow.utils.test.js +0 -45
  350. package/dist/workflows/workflow.utils.test.js.map +0 -1
@@ -1,675 +0,0 @@
1
- import {
2
- annotateDiffWithLineNumbers,
3
- gitDiff_default
4
- } from "./chunk-UEEU3SCC.js";
5
- import {
6
- CODE_REVIEW_SYSTEM_PROMPT,
7
- formatReviewToolInput,
8
- getDefaultContext,
9
- parseGitDiffNameStatus,
10
- parseGitDiffNumStat,
11
- parseGitStatus,
12
- printChangedFiles,
13
- reviewOutputSchema
14
- } from "./chunk-2LRQ2QH6.js";
15
-
16
- // src/workflows/review.workflow.ts
17
- import path from "path";
18
- import { agentWorkflow, listFiles, readBinaryFile, readFile, searchFiles } from "@polka-codes/core";
19
-
20
- // src/workflows/git-file-tools.ts
21
- import { z } from "zod";
22
-
23
- // src/utils/shell.ts
24
- function isWindows() {
25
- return process.platform === "win32";
26
- }
27
- function quoteForShell(str) {
28
- if (isWindows()) {
29
- const escaped = str.replace(/"/g, '""');
30
- return `"${escaped}"`;
31
- } else {
32
- return `'${str.replace(/'/g, "'\\''")}'`;
33
- }
34
- }
35
-
36
- // src/workflows/git-file-tools.ts
37
- function getMediaType(path2) {
38
- const lastDotIndex = path2.lastIndexOf(".");
39
- const ext = lastDotIndex > 0 && lastDotIndex < path2.length - 1 ? path2.slice(lastDotIndex + 1).toLowerCase() : void 0;
40
- const mediaTypes = {
41
- // Images
42
- png: "image/png",
43
- jpg: "image/jpeg",
44
- jpeg: "image/jpeg",
45
- gif: "image/gif",
46
- svg: "image/svg+xml",
47
- webp: "image/webp",
48
- ico: "image/x-icon",
49
- bmp: "image/bmp",
50
- // Fonts
51
- woff: "font/woff",
52
- woff2: "font/woff2",
53
- ttf: "font/ttf",
54
- otf: "font/otf",
55
- eot: "application/vnd.ms-fontobject",
56
- // Documents
57
- pdf: "application/pdf",
58
- // Audio
59
- mp3: "audio/mpeg",
60
- wav: "audio/wav",
61
- ogg: "audio/ogg",
62
- // Video
63
- mp4: "video/mp4",
64
- webm: "video/webm",
65
- avi: "video/x-msvideo"
66
- };
67
- return mediaTypes[ext || ""] || "application/octet-stream";
68
- }
69
- function extractTargetCommit(range, pr) {
70
- if (pr) {
71
- return null;
72
- }
73
- if (!range || range.trim() === "") {
74
- return null;
75
- }
76
- const parts = range.split(/\.\.\.?/);
77
- if (parts.length > 1) {
78
- return parts[1].trim() || null;
79
- }
80
- const trimmed = range.trim();
81
- return trimmed || null;
82
- }
83
- function createGitReadFile(commit) {
84
- const toolInfo = {
85
- name: "readFile",
86
- description: `Read file contents from git commit ${commit}. Use this to examine files at the specific commit being reviewed.`,
87
- parameters: z.object({
88
- path: z.preprocess((val) => {
89
- if (!val) return [];
90
- const values = Array.isArray(val) ? val : [val];
91
- return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
92
- }, z.array(z.string())).describe("The path of the file to read (relative to git root)").meta({ usageValue: "Comma separated paths here" })
93
- }).meta({
94
- examples: [
95
- {
96
- description: "Read the contents of a file at the commit",
97
- input: {
98
- path: "src/main.ts"
99
- }
100
- }
101
- ]
102
- })
103
- };
104
- const handler = async (provider, args) => {
105
- if (!provider.executeCommand) {
106
- return {
107
- success: false,
108
- message: {
109
- type: "error-text",
110
- value: "Not possible to execute command."
111
- }
112
- };
113
- }
114
- const { path: paths } = toolInfo.parameters.parse(args);
115
- const results = [];
116
- for (const filePath of paths) {
117
- const quotedCommit = quoteForShell(commit);
118
- const quotedPath = quoteForShell(filePath);
119
- const result = await provider.executeCommand(`git show ${quotedCommit}:${quotedPath}`, false);
120
- if (result.exitCode === 0) {
121
- results.push(`<read_file_file_content path="${filePath}">${result.stdout}</read_file_file_content>`);
122
- } else {
123
- results.push(`<read_file_file_content path="${filePath}" file_not_found="true"></read_file_file_content>`);
124
- }
125
- }
126
- return {
127
- success: true,
128
- message: {
129
- type: "text",
130
- value: results.join("\n")
131
- }
132
- };
133
- };
134
- return {
135
- ...toolInfo,
136
- handler
137
- };
138
- }
139
- function createGitListFiles(commit) {
140
- const toolInfo = {
141
- name: "listFiles",
142
- description: `List files and directories at git commit ${commit}. Shows the file tree as it existed at that commit.`,
143
- parameters: z.object({
144
- path: z.string().optional().describe("The path of the directory to list (relative to git root). Default is root.").meta({ usageValue: "Directory path here (optional)" }),
145
- maxCount: z.coerce.number().optional().default(2e3).describe("The maximum number of files to list. Default to 2000").meta({ usageValue: "Maximum number of files to list (optional)" })
146
- })
147
- };
148
- const handler = async (provider, args) => {
149
- if (!provider.executeCommand) {
150
- return {
151
- success: false,
152
- message: {
153
- type: "error-text",
154
- value: "Not possible to execute command."
155
- }
156
- };
157
- }
158
- const parsed = toolInfo.parameters.parse(args);
159
- const path2 = parsed.path || ".";
160
- const quotedCommit = quoteForShell(commit);
161
- const quotedPath = quoteForShell(path2);
162
- const result = await provider.executeCommand(`git ls-tree -r --name-only ${quotedCommit} ${quotedPath}`, false);
163
- if (result.exitCode !== 0) {
164
- return {
165
- success: false,
166
- message: {
167
- type: "error-text",
168
- value: `Failed to list files at commit ${commit}: ${result.stderr}`
169
- }
170
- };
171
- }
172
- const files = result.stdout.trim().split("\n").filter((f) => f.length > 0);
173
- const truncated = files.length > parsed.maxCount;
174
- const displayFiles = truncated ? files.slice(0, parsed.maxCount) : files;
175
- return {
176
- success: true,
177
- message: {
178
- type: "text",
179
- value: `<list_files_path>${path2}</list_files_path>
180
- <list_files_files>
181
- ${displayFiles.join("\n")}
182
- </list_files_files>
183
- <list_files_truncated>${truncated}</list_files_truncated>`
184
- }
185
- };
186
- };
187
- return {
188
- ...toolInfo,
189
- handler
190
- };
191
- }
192
- function createGitReadBinaryFile(commit) {
193
- const toolInfo = {
194
- name: "readBinaryFile",
195
- description: `Read binary file contents from git commit ${commit} and return as base64 encoded data. Use for images, fonts, and other binary files.`,
196
- parameters: z.object({
197
- url: z.string().describe("The URL or path of the binary file to read (relative to git root)")
198
- })
199
- };
200
- const handler = async (provider, args) => {
201
- if (!provider.executeCommand) {
202
- return {
203
- success: false,
204
- message: {
205
- type: "error-text",
206
- value: "Not possible to execute command."
207
- }
208
- };
209
- }
210
- const { url } = toolInfo.parameters.parse(args);
211
- const quotedCommit = quoteForShell(commit);
212
- const quotedUrl = quoteForShell(url);
213
- const checkResult = await provider.executeCommand(`git cat-file -e ${quotedCommit}:${quotedUrl}`, false);
214
- if (checkResult.exitCode !== 0) {
215
- return {
216
- success: true,
217
- message: {
218
- type: "text",
219
- value: `<read_binary_file_file_content url="${url}" file_not_found="true"></read_binary_file_file_content>`
220
- }
221
- };
222
- }
223
- const isWindows2 = process.platform === "win32";
224
- const command = isWindows2 ? `cmd /c "git show ${quotedCommit}:${quotedUrl} | base64 -w 0"` : `sh -c "git show ${quotedCommit}:${quotedUrl} | base64"`;
225
- const result = await provider.executeCommand(command, false);
226
- if (result.exitCode === 0) {
227
- const base64Data = result.stdout.replace(/\n/g, "");
228
- return {
229
- success: true,
230
- message: {
231
- type: "content",
232
- value: [
233
- {
234
- type: "media",
235
- url,
236
- data: base64Data,
237
- mediaType: getMediaType(url)
238
- }
239
- ]
240
- }
241
- };
242
- } else {
243
- const isBase64Error = result.stderr.includes("not recognized") || result.stderr.includes("command not found") || result.stderr.includes("base64");
244
- const errorMessage = isBase64Error ? `Failed to read binary file: base64 command not found. On Windows, ensure Git Bash or Unix tools are installed and in PATH.` : `Failed to read binary file: ${result.stderr}`;
245
- return {
246
- success: false,
247
- message: {
248
- type: "error-text",
249
- value: errorMessage
250
- }
251
- };
252
- }
253
- };
254
- return {
255
- ...toolInfo,
256
- handler
257
- };
258
- }
259
- function createGitAwareTools(commit) {
260
- return {
261
- readFile: createGitReadFile(commit),
262
- listFiles: createGitListFiles(commit),
263
- readBinaryFile: createGitReadBinaryFile(commit)
264
- };
265
- }
266
- function createGitAwareDiff(commit) {
267
- const toolInfo = {
268
- name: "git_diff",
269
- description: `Get the git diff for commit ${commit}. Shows the exact changes introduced by this specific commit. Use this to inspect what changed in each file. Always specify a file path.`,
270
- parameters: z.object({
271
- file: z.string().describe("Get the diff for a specific file within the commit. This parameter is required.").meta({ usageValue: "File path here (required)" }),
272
- contextLines: z.coerce.number().int().min(0).optional().default(5).describe("Number of context lines to include around changes.").meta({ usageValue: "Context lines count (optional)" }),
273
- includeLineNumbers: z.preprocess((val) => {
274
- if (typeof val === "string") {
275
- const lower = val.toLowerCase();
276
- if (lower === "false") return false;
277
- if (lower === "true") return true;
278
- }
279
- return val;
280
- }, z.boolean().optional().default(true)).describe("Annotate the diff with line numbers for additions and deletions.").meta({ usageValue: "true or false (optional)" })
281
- })
282
- };
283
- const handler = async (provider, args) => {
284
- if (!provider.executeCommand) {
285
- return {
286
- success: false,
287
- message: {
288
- type: "error-text",
289
- value: "Not possible to execute command."
290
- }
291
- };
292
- }
293
- const { file, contextLines, includeLineNumbers } = toolInfo.parameters.parse(args);
294
- const quotedCommit = quoteForShell(commit);
295
- let command = `git show --no-color --format= -U${contextLines} ${quotedCommit}`;
296
- if (file) {
297
- const quotedFile = quoteForShell(file);
298
- command = `git show --no-color --format= -U${contextLines} ${quotedCommit} -- ${quotedFile}`;
299
- }
300
- try {
301
- const result = await provider.executeCommand(command, false);
302
- if (result.exitCode === 0) {
303
- if (!result.stdout.trim()) {
304
- return {
305
- success: true,
306
- message: {
307
- type: "text",
308
- value: "No diff found."
309
- }
310
- };
311
- }
312
- let diffOutput = result.stdout;
313
- if (includeLineNumbers) {
314
- diffOutput = annotateDiffWithLineNumbers(diffOutput);
315
- }
316
- return {
317
- success: true,
318
- message: {
319
- type: "text",
320
- value: `<diff file="${file ?? "all"}">
321
- ${diffOutput}
322
- </diff>`
323
- }
324
- };
325
- }
326
- return {
327
- success: false,
328
- message: {
329
- type: "error-text",
330
- value: `\`${command}\` exited with code ${result.exitCode}:
331
- ${result.stderr}`
332
- }
333
- };
334
- } catch (error) {
335
- return {
336
- success: false,
337
- message: {
338
- type: "error-text",
339
- value: error instanceof Error ? error.message : String(error)
340
- }
341
- };
342
- }
343
- };
344
- return {
345
- ...toolInfo,
346
- handler
347
- };
348
- }
349
-
350
- // src/workflows/review.workflow.ts
351
- var reviewWorkflow = async (input, context) => {
352
- const { step, tools, logger } = context;
353
- const { pr, range, context: userContext, files } = input;
354
- let changeInfo;
355
- const gitRootResult = await tools.executeCommand({ command: "git", args: ["rev-parse", "--show-toplevel"] });
356
- if (gitRootResult.exitCode !== 0) {
357
- throw new Error("Failed to determine git repository root. Ensure you are in a git repository.");
358
- }
359
- const gitRoot = gitRootResult.stdout.trim();
360
- const normalizeFilePath = (filePath) => {
361
- const absolutePath = path.resolve(process.cwd(), filePath);
362
- const relativePath = path.relative(gitRoot, absolutePath);
363
- return relativePath.split(path.sep).join("/");
364
- };
365
- const normalizedFiles = files?.map(normalizeFilePath);
366
- const filterFiles = (changedFiles) => {
367
- if (!normalizedFiles || normalizedFiles.length === 0) {
368
- return changedFiles;
369
- }
370
- return changedFiles.filter((file) => normalizedFiles.includes(file.path));
371
- };
372
- const filterAndWarn = (changedFiles, source) => {
373
- const filteredFiles = filterFiles(changedFiles);
374
- if (normalizedFiles && normalizedFiles.length > 0) {
375
- const foundFiles = new Set(filteredFiles.map((f) => f.path));
376
- const missingFiles = normalizedFiles.filter((f) => !foundFiles.has(f));
377
- if (missingFiles.length > 0) {
378
- if (filteredFiles.length === 0) {
379
- logger.warn(`Warning: None of the specified files were found in ${source}: ${missingFiles.join(", ")}`);
380
- } else {
381
- logger.warn(`Warning: Some files not found in ${source}: ${missingFiles.join(", ")}`);
382
- }
383
- }
384
- }
385
- return filteredFiles;
386
- };
387
- if (pr) {
388
- const ghCheckResult = await tools.executeCommand({ command: "gh", args: ["--version"] });
389
- if (ghCheckResult.exitCode !== 0) {
390
- throw new Error("Error: GitHub CLI (gh) is not installed. Please install it from https://cli.github.com/");
391
- }
392
- await step(`Checking out PR #${pr}...`, async () => {
393
- const checkoutResult = await tools.executeCommand({
394
- command: "gh",
395
- args: ["pr", "checkout", pr.toString()]
396
- });
397
- if (checkoutResult.exitCode !== 0) {
398
- logger.error(checkoutResult.stderr);
399
- throw new Error(`Error checking out PR #${pr}. Make sure the PR number is correct and you have access to the repository.`);
400
- }
401
- });
402
- const prDetails = await step("Fetching pull request details...", async () => {
403
- const result2 = await tools.executeCommand({
404
- command: "gh",
405
- args: ["pr", "view", pr.toString(), "--json", "title,body,commits,baseRefName,baseRefOid"]
406
- });
407
- try {
408
- return JSON.parse(result2.stdout);
409
- } catch (error) {
410
- throw new Error(`Failed to parse PR details from GitHub CLI: ${error instanceof Error ? error.message : String(error)}`);
411
- }
412
- });
413
- const prCommitRange = `${prDetails.baseRefOid}...HEAD`;
414
- logger.info(`Reviewing PR #${pr} (commit range: ${prCommitRange})`);
415
- const commitMessages = prDetails.commits.map((c) => c.messageBody).join("\n---\n");
416
- const allChangedFiles = await step("Getting file changes...", async () => {
417
- const diffResult = await tools.executeCommand({
418
- command: "git",
419
- args: ["--no-pager", "diff", "--name-status", "--no-color", prCommitRange]
420
- });
421
- if (diffResult.exitCode !== 0) {
422
- logger.warn("Warning: Could not retrieve file changes list");
423
- return [];
424
- }
425
- const files2 = parseGitDiffNameStatus(diffResult.stdout);
426
- const statResult = await tools.executeCommand({
427
- command: "git",
428
- args: ["--no-pager", "diff", "--numstat", "--no-color", prCommitRange]
429
- });
430
- if (statResult.exitCode === 0) {
431
- const stats = parseGitDiffNumStat(statResult.stdout);
432
- for (const file of files2) {
433
- if (stats[file.path]) {
434
- file.insertions = stats[file.path].insertions;
435
- file.deletions = stats[file.path].deletions;
436
- }
437
- }
438
- }
439
- return files2;
440
- });
441
- const changedFiles = filterAndWarn(allChangedFiles, `PR #${pr}`);
442
- printChangedFiles(logger, changedFiles);
443
- if (changedFiles.length === 0) {
444
- return {
445
- overview: normalizedFiles ? `No changes to review. The specified file(s) were not found in PR #${pr}: ${normalizedFiles.join(", ")}` : `No changes to review in PR #${pr}.`,
446
- specificReviews: []
447
- };
448
- }
449
- changeInfo = {
450
- commitRange: prCommitRange,
451
- pullRequestTitle: prDetails.title,
452
- pullRequestDescription: prDetails.body,
453
- commitMessages,
454
- changedFiles,
455
- context: userContext
456
- };
457
- } else if (range) {
458
- await step(`Reviewing git range '${range}'...`, async () => {
459
- });
460
- logger.info(`Reviewing commit range: ${range}`);
461
- const allRangeChangedFiles = await step("Getting file changes...", async () => {
462
- const diffResult = await tools.executeCommand({
463
- command: "git",
464
- args: ["--no-pager", "diff", "--name-status", "--no-color", range]
465
- });
466
- if (diffResult.exitCode !== 0) {
467
- logger.warn("Warning: Could not retrieve file changes list");
468
- return [];
469
- }
470
- const files2 = parseGitDiffNameStatus(diffResult.stdout);
471
- const statResult = await tools.executeCommand({
472
- command: "git",
473
- args: ["--no-pager", "diff", "--numstat", "--no-color", range]
474
- });
475
- if (statResult.exitCode === 0) {
476
- const stats = parseGitDiffNumStat(statResult.stdout);
477
- for (const file of files2) {
478
- if (stats[file.path]) {
479
- file.insertions = stats[file.path].insertions;
480
- file.deletions = stats[file.path].deletions;
481
- }
482
- }
483
- }
484
- return files2;
485
- });
486
- const rangeChangedFiles = filterAndWarn(allRangeChangedFiles, `range '${range}'`);
487
- printChangedFiles(logger, rangeChangedFiles);
488
- if (rangeChangedFiles.length === 0) {
489
- return {
490
- overview: normalizedFiles ? `No changes to review. The specified file(s) were not found in range '${range}': ${normalizedFiles.join(", ")}` : `No changes to review in range '${range}'.`,
491
- specificReviews: []
492
- };
493
- }
494
- const logResult = await tools.executeCommand({
495
- command: "git",
496
- args: ["log", "--format=%B", range]
497
- });
498
- const commitMessages = logResult.exitCode === 0 ? logResult.stdout.trim() : "";
499
- changeInfo = {
500
- commitRange: range,
501
- changedFiles: rangeChangedFiles,
502
- commitMessages,
503
- context: userContext
504
- };
505
- } else {
506
- const statusResult = await tools.executeCommand({ command: "git", args: ["status", "--porcelain=v1"] });
507
- const gitStatus = statusResult.stdout;
508
- const statusLines = gitStatus.split("\n").filter((line) => line);
509
- const hasLocalChanges = statusLines.length > 0;
510
- if (hasLocalChanges) {
511
- const hasStagedChanges = statusLines.some((line) => line[0] !== " " && line[0] !== "?");
512
- const hasUnstagedChanges = statusLines.some((line) => line[1] !== " " && line[1] !== "?");
513
- const hasUntrackedChanges = statusLines.some((line) => line.startsWith("??"));
514
- const reviewTargets = [];
515
- if (hasStagedChanges) {
516
- reviewTargets.push("staged files");
517
- }
518
- if (hasUnstagedChanges) {
519
- reviewTargets.push("unstaged files");
520
- }
521
- if (hasUntrackedChanges) {
522
- reviewTargets.push("untracked files");
523
- }
524
- if (reviewTargets.length > 0) {
525
- logger.info(`Reviewing local changes: ${reviewTargets.join(", ")}.`);
526
- } else {
527
- logger.info("Reviewing local changes.");
528
- }
529
- const allChangedFiles = parseGitStatus(gitStatus);
530
- const unstagedStatResult = await tools.executeCommand({
531
- command: "git",
532
- args: ["diff", "--numstat", "--no-color"]
533
- });
534
- const unstagedStats = unstagedStatResult.exitCode === 0 ? parseGitDiffNumStat(unstagedStatResult.stdout) : {};
535
- const stagedStatResult = await tools.executeCommand({
536
- command: "git",
537
- args: ["diff", "--numstat", "--cached", "--no-color"]
538
- });
539
- const stagedStats = stagedStatResult.exitCode === 0 ? parseGitDiffNumStat(stagedStatResult.stdout) : {};
540
- for (const file of allChangedFiles) {
541
- const unstaged = unstagedStats[file.path] || { insertions: 0, deletions: 0 };
542
- const staged = stagedStats[file.path] || { insertions: 0, deletions: 0 };
543
- if (unstaged.insertions > 0 || unstaged.deletions > 0 || staged.insertions > 0 || staged.deletions > 0) {
544
- file.insertions = unstaged.insertions + staged.insertions;
545
- file.deletions = unstaged.deletions + staged.deletions;
546
- }
547
- }
548
- const changedFiles = filterAndWarn(allChangedFiles, "local changes");
549
- printChangedFiles(logger, changedFiles);
550
- if (changedFiles.length === 0) {
551
- return {
552
- overview: normalizedFiles ? `No changes to review. The specified file(s) were not found in local changes: ${normalizedFiles.join(", ")}` : "No changes to review.",
553
- specificReviews: []
554
- };
555
- }
556
- changeInfo = {
557
- staged: hasStagedChanges,
558
- changedFiles,
559
- context: userContext
560
- };
561
- } else {
562
- await step("No local changes detected. Falling back to branch diff...", async () => {
563
- });
564
- const ghCheckResult = await tools.executeCommand({ command: "gh", args: ["--version"] });
565
- if (ghCheckResult.exitCode !== 0) {
566
- throw new Error(
567
- "Error: GitHub CLI (gh) is not installed, and there are no local changes to review. Please install it from https://cli.github.com/ to review branch changes."
568
- );
569
- }
570
- const defaultBranchResult = await tools.executeCommand({
571
- command: "gh",
572
- args: ["repo", "view", "--json", "defaultBranchRef", "--jq", ".defaultBranchRef.name"]
573
- });
574
- const defaultBranch = defaultBranchResult.stdout.trim();
575
- const currentBranchResult = await tools.executeCommand({ command: "git", args: ["rev-parse", "--abbrev-ref", "HEAD"] });
576
- const currentBranch = currentBranchResult.stdout.trim();
577
- if (currentBranch === defaultBranch) {
578
- await step(`No changes to review. You are on the default branch ('${defaultBranch}').`, async () => {
579
- });
580
- logger.info(`No changes to review. You are on the default branch ('${defaultBranch}').`);
581
- return {
582
- overview: `No changes to review. You are on the default branch ('${defaultBranch}').`,
583
- specificReviews: []
584
- };
585
- }
586
- const branchCommitRange = `${defaultBranch}...${currentBranch}`;
587
- logger.info(`Reviewing branch changes (commit range: ${branchCommitRange})`);
588
- const allBranchChangedFiles = await step("Getting file changes...", async () => {
589
- const diffResult = await tools.executeCommand({
590
- command: "git",
591
- args: ["--no-pager", "diff", "--name-status", "--no-color", branchCommitRange]
592
- });
593
- if (diffResult.exitCode !== 0) {
594
- logger.warn("Warning: Could not retrieve file changes list");
595
- return [];
596
- }
597
- const files2 = parseGitDiffNameStatus(diffResult.stdout);
598
- const statResult = await tools.executeCommand({
599
- command: "git",
600
- args: ["--no-pager", "diff", "--numstat", "--no-color", branchCommitRange]
601
- });
602
- if (statResult.exitCode === 0) {
603
- const stats = parseGitDiffNumStat(statResult.stdout);
604
- for (const file of files2) {
605
- if (stats[file.path]) {
606
- file.insertions = stats[file.path].insertions;
607
- file.deletions = stats[file.path].deletions;
608
- }
609
- }
610
- }
611
- return files2;
612
- });
613
- const branchChangedFiles = filterAndWarn(allBranchChangedFiles, "branch changes");
614
- printChangedFiles(logger, branchChangedFiles);
615
- if (branchChangedFiles.length === 0) {
616
- return {
617
- overview: normalizedFiles ? `No changes to review. The specified file(s) were not found in branch changes: ${normalizedFiles.join(", ")}` : `No changes to review. The current branch has no differences from ${defaultBranch}.`,
618
- specificReviews: []
619
- };
620
- }
621
- changeInfo = {
622
- commitRange: branchCommitRange,
623
- changedFiles: branchChangedFiles,
624
- context: userContext
625
- };
626
- }
627
- }
628
- if (!changeInfo) {
629
- return { overview: "No changes to review.", specificReviews: [] };
630
- }
631
- if (!changeInfo?.changedFiles || changeInfo.changedFiles.length === 0) {
632
- return { overview: "No changes to review.", specificReviews: [] };
633
- }
634
- const targetCommit = extractTargetCommit(range, pr);
635
- const isRange = range?.includes("..");
636
- const finalChangeInfo = targetCommit && !isRange ? { ...changeInfo, targetCommit } : changeInfo;
637
- const fileTools = targetCommit && !isRange ? createGitAwareTools(targetCommit) : { readFile, listFiles, readBinaryFile };
638
- const reviewTools = targetCommit && !isRange ? [fileTools.readFile, fileTools.readBinaryFile, fileTools.listFiles, createGitAwareDiff(targetCommit)] : [readFile, readBinaryFile, searchFiles, listFiles, gitDiff_default];
639
- const result = await step("review", async () => {
640
- const { context: defaultContext } = await getDefaultContext(input.config, "review");
641
- const memoryContext = await tools.getMemoryContext();
642
- const reviewInput = formatReviewToolInput(finalChangeInfo);
643
- const fullContent = `${reviewInput}
644
-
645
- ${defaultContext}
646
- ${memoryContext}`;
647
- return await agentWorkflow(
648
- {
649
- systemPrompt: CODE_REVIEW_SYSTEM_PROMPT,
650
- userMessage: [
651
- {
652
- role: "user",
653
- content: fullContent
654
- }
655
- ],
656
- tools: reviewTools,
657
- outputSchema: reviewOutputSchema
658
- },
659
- context
660
- );
661
- });
662
- if (result.type === "Exit") {
663
- const reviewResult = result.object;
664
- if (!reviewResult) {
665
- return { overview: "AI agent failed to produce a review.", specificReviews: [] };
666
- }
667
- return reviewResult;
668
- }
669
- return { overview: `Agent workflow exited with an unexpected status: ${result.type}`, specificReviews: [] };
670
- };
671
-
672
- export {
673
- quoteForShell,
674
- reviewWorkflow
675
- };