@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,390 +0,0 @@
1
- // src/tools/gitDiff.ts
2
- import { z } from "zod";
3
-
4
- // src/tools/utils/diffLineNumbers.ts
5
- function parseHunkHeader(header) {
6
- const match = header.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
7
- if (!match) return null;
8
- return {
9
- oldStart: parseInt(match[1], 10),
10
- oldCount: match[2] ? parseInt(match[2], 10) : 1,
11
- newStart: parseInt(match[3], 10),
12
- newCount: match[4] ? parseInt(match[4], 10) : 1,
13
- header
14
- };
15
- }
16
- function annotateDiffWithLineNumbers(diff) {
17
- const lines = diff.split("\n");
18
- const annotatedLines = [];
19
- let currentNewLine = 0;
20
- let currentOldLine = 0;
21
- let inHunk = false;
22
- for (const line of lines) {
23
- if (line.startsWith("@@")) {
24
- const hunk = parseHunkHeader(line);
25
- if (hunk) {
26
- currentOldLine = hunk.oldStart;
27
- currentNewLine = hunk.newStart;
28
- inHunk = true;
29
- }
30
- annotatedLines.push(line);
31
- continue;
32
- }
33
- if (line.startsWith("diff --git") || line.startsWith("index ") || line.startsWith("---") || line.startsWith("+++")) {
34
- annotatedLines.push(line);
35
- inHunk = false;
36
- continue;
37
- }
38
- if (!inHunk) {
39
- annotatedLines.push(line);
40
- continue;
41
- }
42
- if (line.startsWith("+") && !line.startsWith("+++")) {
43
- annotatedLines.push(`${line} [Line ${currentNewLine}]`);
44
- currentNewLine++;
45
- } else if (line.startsWith("-") && !line.startsWith("---")) {
46
- annotatedLines.push(`${line} [Line ${currentOldLine} removed]`);
47
- currentOldLine++;
48
- } else if (line.startsWith(" ")) {
49
- annotatedLines.push(line);
50
- currentOldLine++;
51
- currentNewLine++;
52
- } else {
53
- annotatedLines.push(line);
54
- }
55
- }
56
- return annotatedLines.join("\n");
57
- }
58
-
59
- // src/tools/gitDiff.ts
60
- var toolInfo = {
61
- name: "git_diff",
62
- description: "Get the git diff for the current repository. Can be used to get staged changes, unstaged changes, or changes between commits. By default, it returns unstaged changes.",
63
- parameters: z.object({
64
- staged: z.preprocess((val) => {
65
- if (typeof val === "string") {
66
- const lower = val.toLowerCase();
67
- if (lower === "false") return false;
68
- if (lower === "true") return true;
69
- }
70
- return val;
71
- }, z.boolean().optional().default(false)).describe("Get staged changes instead of unstaged changes."),
72
- commitRange: z.string().optional().describe('The commit range to get the diff for (e.g., "main...HEAD").'),
73
- file: z.string().describe("Get the diff for a specific file."),
74
- contextLines: z.coerce.number().optional().default(5).describe("Number of context lines to include around changes."),
75
- includeLineNumbers: z.preprocess((val) => {
76
- if (typeof val === "string") {
77
- const lower = val.toLowerCase();
78
- if (lower === "false") return false;
79
- if (lower === "true") return true;
80
- }
81
- return val;
82
- }, z.boolean().optional().default(true)).describe("Annotate the diff with line numbers for additions and deletions.")
83
- })
84
- };
85
- var handler = async (provider, args) => {
86
- if (!provider.executeCommand) {
87
- return {
88
- success: false,
89
- message: {
90
- type: "error-text",
91
- value: "Not possible to execute command. Abort."
92
- }
93
- };
94
- }
95
- const { staged, file, commitRange, contextLines, includeLineNumbers } = toolInfo.parameters.parse(args);
96
- const commandParts = ["git", "diff", "--no-color", `-U${contextLines}`];
97
- if (staged) {
98
- commandParts.push("--staged");
99
- }
100
- if (commitRange) {
101
- commandParts.push(commitRange);
102
- }
103
- if (file) {
104
- const escapedFile = file.replace(/'/g, "'\\''");
105
- commandParts.push("--", `'${escapedFile}'`);
106
- }
107
- const command = commandParts.join(" ");
108
- try {
109
- const result = await provider.executeCommand(command, false);
110
- if (result.exitCode === 0) {
111
- if (!result.stdout.trim()) {
112
- return {
113
- success: true,
114
- message: {
115
- type: "text",
116
- value: "No diff found."
117
- }
118
- };
119
- }
120
- let diffOutput = result.stdout;
121
- if (includeLineNumbers) {
122
- diffOutput = annotateDiffWithLineNumbers(diffOutput);
123
- }
124
- return {
125
- success: true,
126
- message: {
127
- type: "text",
128
- value: `<diff file="${file ?? "all"}">
129
- ${diffOutput}
130
- </diff>`
131
- }
132
- };
133
- }
134
- return {
135
- success: false,
136
- message: {
137
- type: "error-text",
138
- value: `\`${command}\` exited with code ${result.exitCode}:
139
- ${result.stderr}`
140
- }
141
- };
142
- } catch (error) {
143
- return {
144
- success: false,
145
- message: {
146
- type: "error-text",
147
- value: error instanceof Error ? error.message : String(error)
148
- }
149
- };
150
- }
151
- };
152
- var gitDiff_default = {
153
- ...toolInfo,
154
- handler
155
- };
156
-
157
- // src/tools/getTodoItem.ts
158
- import { z as z2 } from "zod";
159
- var toolInfo2 = {
160
- name: "getTodoItem",
161
- description: "Get a to-do item by its ID.",
162
- parameters: z2.object({
163
- id: z2.string().describe("The ID of the to-do item.")
164
- })
165
- };
166
- var handler2 = async (provider, args) => {
167
- if (!provider.getTodoItem) {
168
- return {
169
- success: false,
170
- message: {
171
- type: "error-text",
172
- value: "Not possible to get a to-do item."
173
- }
174
- };
175
- }
176
- const { id } = toolInfo2.parameters.parse(args);
177
- const item = await provider.getTodoItem(id);
178
- return {
179
- success: true,
180
- message: {
181
- type: "json",
182
- value: item ?? null
183
- }
184
- };
185
- };
186
- var getTodoItem_default = {
187
- ...toolInfo2,
188
- handler: handler2
189
- };
190
-
191
- // src/tools/listMemoryTopics.ts
192
- import { z as z3 } from "zod";
193
- var toolInfo3 = {
194
- name: "listMemoryTopics",
195
- description: "Lists all topics in memory. Use this to see what information has been stored and which topics are available to read from.",
196
- parameters: z3.object({})
197
- };
198
- var handler3 = async (provider, _args) => {
199
- const topics = await provider.listMemoryTopics();
200
- if (!topics.length) {
201
- return { success: true, message: { type: "text", value: "No topics found." } };
202
- }
203
- return {
204
- success: true,
205
- message: {
206
- type: "text",
207
- value: `Memory topics:
208
- ${topics.join("\n")}`
209
- }
210
- };
211
- };
212
- var listMemoryTopics_default = {
213
- ...toolInfo3,
214
- handler: handler3
215
- };
216
-
217
- // src/tools/listTodoItems.ts
218
- import { TodoStatus } from "@polka-codes/core";
219
- import { z as z4 } from "zod";
220
- var toolInfo4 = {
221
- name: "listTodoItems",
222
- description: "List all to-do items, sorted by id. If an id is provided, it lists all sub-items for that id. Can be filtered by status.",
223
- parameters: z4.object({
224
- id: z4.string().nullish(),
225
- status: TodoStatus.nullish()
226
- })
227
- };
228
- var handler4 = async (provider, args) => {
229
- if (!provider.listTodoItems) {
230
- return {
231
- success: false,
232
- message: {
233
- type: "error-text",
234
- value: "Not possible to list to-do items."
235
- }
236
- };
237
- }
238
- const { id, status } = toolInfo4.parameters.parse(args);
239
- const items = await provider.listTodoItems(id, status);
240
- return {
241
- success: true,
242
- message: {
243
- type: "json",
244
- value: items
245
- }
246
- };
247
- };
248
- var listTodoItems_default = {
249
- ...toolInfo4,
250
- handler: handler4
251
- };
252
-
253
- // src/tools/readMemory.ts
254
- import { z as z5 } from "zod";
255
- var toolInfo5 = {
256
- name: "readMemory",
257
- description: "Reads content from a memory topic. Use this to retrieve information stored in previous steps. If no topic is specified, reads from the default topic.",
258
- parameters: z5.object({
259
- topic: z5.string().nullish().describe('The topic to read from memory. Defaults to ":default:".')
260
- })
261
- };
262
- var handler5 = async (provider, args) => {
263
- const { topic } = toolInfo5.parameters.parse(args);
264
- const content = await provider.readMemory(topic ?? void 0);
265
- if (content) {
266
- return {
267
- success: true,
268
- message: {
269
- type: "text",
270
- value: `<memory${topic ? ` topic="${topic}"` : ""}>
271
- ${content}
272
- </memory>`
273
- }
274
- };
275
- }
276
- return {
277
- success: true,
278
- message: {
279
- type: "text",
280
- value: `<memory ${topic ? `topic="${topic}"` : ""} isEmpty="true" />`
281
- }
282
- };
283
- };
284
- var readMemory_default = {
285
- ...toolInfo5,
286
- handler: handler5
287
- };
288
-
289
- // src/tools/updateMemory.ts
290
- import { z as z6 } from "zod";
291
- var toolInfo6 = {
292
- name: "updateMemory",
293
- description: 'Appends, replaces, or removes content from a memory topic. Use "append" to add to existing content, "replace" to overwrite entirely, or "remove" to delete a topic. Memory persists across tool calls within a workflow.',
294
- parameters: z6.object({
295
- operation: z6.enum(["append", "replace", "remove"]).describe("The operation to perform."),
296
- topic: z6.string().nullish().describe('The topic to update in memory. Defaults to ":default:".'),
297
- content: z6.string().nullish().describe("The content for append or replace operations. Must be omitted for remove operation.")
298
- }).superRefine((data, ctx) => {
299
- if (data.operation === "append" || data.operation === "replace") {
300
- if (data.content === void 0) {
301
- ctx.addIssue({
302
- code: "custom",
303
- message: 'Content is required for "append" and "replace" operations.',
304
- path: ["content"]
305
- });
306
- }
307
- } else if (data.operation === "remove") {
308
- if (data.content !== void 0) {
309
- ctx.addIssue({
310
- code: "custom",
311
- message: 'Content must not be provided for "remove" operation.',
312
- path: ["content"]
313
- });
314
- }
315
- }
316
- })
317
- };
318
- var handler6 = async (provider, args) => {
319
- if (!provider.updateMemory) {
320
- return {
321
- success: false,
322
- message: {
323
- type: "error-text",
324
- value: "Memory operations are not supported by the current provider."
325
- }
326
- };
327
- }
328
- const params = toolInfo6.parameters.parse(args);
329
- await provider.updateMemory(params.operation, params.topic ?? void 0, params.content ?? void 0);
330
- const topic = params.topic || ":default:";
331
- const messages = {
332
- append: `Content appended to memory topic '${topic}'`,
333
- replace: `Memory topic '${topic}' replaced`,
334
- remove: `Memory topic '${topic}' removed`
335
- };
336
- return {
337
- success: true,
338
- message: {
339
- type: "text",
340
- value: messages[params.operation]
341
- }
342
- };
343
- };
344
- var updateMemory_default = {
345
- ...toolInfo6,
346
- handler: handler6
347
- };
348
-
349
- // src/tools/updateTodoItem.ts
350
- import { UpdateTodoItemInputSchema } from "@polka-codes/core";
351
- var toolInfo7 = {
352
- name: "updateTodoItem",
353
- description: "Add or update a to-do item.",
354
- parameters: UpdateTodoItemInputSchema
355
- };
356
- var handler7 = async (provider, args) => {
357
- if (!provider.updateTodoItem) {
358
- return {
359
- success: false,
360
- message: {
361
- type: "error-text",
362
- value: "Not possible to update a to-do item."
363
- }
364
- };
365
- }
366
- const input = toolInfo7.parameters.parse(args);
367
- const result = await provider.updateTodoItem(input);
368
- return {
369
- success: true,
370
- message: {
371
- type: "json",
372
- value: result
373
- }
374
- };
375
- };
376
- var updateTodoItem_default = {
377
- ...toolInfo7,
378
- handler: handler7
379
- };
380
-
381
- export {
382
- getTodoItem_default,
383
- annotateDiffWithLineNumbers,
384
- gitDiff_default,
385
- listMemoryTopics_default,
386
- listTodoItems_default,
387
- readMemory_default,
388
- updateMemory_default,
389
- updateTodoItem_default
390
- };
@@ -1,277 +0,0 @@
1
- import {
2
- UserCancelledError
3
- } from "./chunk-LLMPMGV3.js";
4
- import {
5
- PlanSchema,
6
- getDefaultContext,
7
- getPlanPrompt,
8
- getPlannerSystemPrompt
9
- } from "./chunk-2LRQ2QH6.js";
10
-
11
- // src/workflows/plan.workflow.ts
12
- import {
13
- agentWorkflow,
14
- askFollowupQuestion,
15
- fetchUrl,
16
- listFiles,
17
- readBinaryFile,
18
- readFile,
19
- searchFiles
20
- } from "@polka-codes/core";
21
- async function createPlan(input, context) {
22
- const { tools, step } = context;
23
- const { task, files, plan: inputPlan, userFeedback, interactive, messages, additionalTools } = input;
24
- const getMessages = async () => {
25
- if (messages) {
26
- return {
27
- messages,
28
- userMessage: [{ role: "user", content: userFeedback ?? task }]
29
- };
30
- } else {
31
- const { context: defaultContext, loadRules } = await getDefaultContext(input.config, "plan");
32
- const memoryContext = await tools.getMemoryContext();
33
- const prompt = `${memoryContext}
34
- ${getPlanPrompt(task, inputPlan)}
35
-
36
- ${defaultContext}`;
37
- const userContent = [{ type: "text", text: prompt }];
38
- if (files) {
39
- for (const file of files) {
40
- if (file.type === "file") {
41
- userContent.push({
42
- type: "file",
43
- mediaType: file.mediaType,
44
- filename: file.filename,
45
- data: { type: "base64", value: file.data }
46
- });
47
- } else if (file.type === "image") {
48
- userContent.push({
49
- type: "image",
50
- mediaType: file.mediaType,
51
- image: { type: "base64", value: file.image }
52
- });
53
- }
54
- }
55
- }
56
- return {
57
- systemPrompt: getPlannerSystemPrompt(loadRules),
58
- userMessage: [{ role: "user", content: userContent }]
59
- };
60
- }
61
- };
62
- const agentTools = [readFile, listFiles, searchFiles, readBinaryFile, fetchUrl];
63
- if (additionalTools?.search) {
64
- agentTools.push(additionalTools.search);
65
- }
66
- if (additionalTools?.mcpTools) {
67
- agentTools.push(...additionalTools.mcpTools);
68
- }
69
- if (interactive) {
70
- agentTools.push(askFollowupQuestion);
71
- }
72
- const inputMessages = await getMessages();
73
- const result = await step("plan", async () => {
74
- return await agentWorkflow(
75
- {
76
- ...inputMessages,
77
- tools: agentTools,
78
- outputSchema: PlanSchema
79
- },
80
- context
81
- );
82
- });
83
- if (result.type === "Exit" && result.object) {
84
- const { plan, question, reason, files: filePaths } = result.object;
85
- if (reason) {
86
- return { reason, messages: result.messages };
87
- }
88
- if (question) {
89
- return { plan: plan || inputPlan, question, messages: result.messages };
90
- }
91
- const outputFiles = [];
92
- if (filePaths) {
93
- for (const path of filePaths) {
94
- const content = await tools.readFile({ path });
95
- if (content) {
96
- outputFiles.push({ path, content });
97
- }
98
- }
99
- }
100
- if (plan) {
101
- try {
102
- const taskSummary = task.split("\n")[0].substring(0, 100);
103
- const topic = `plan:${taskSummary.replace(/[^a-zA-Z0-9_-]+/g, "-").toLowerCase()}`;
104
- const keywords = task.toLowerCase().match(/(?:implement|create|add|fix|refactor|update|improve|optimize|test|document)(?:\s+(\w+))?/g);
105
- const _tags = keywords ? keywords.map((k) => {
106
- const parts = k.split(" ");
107
- if (parts.length > 1) {
108
- return parts.join("-");
109
- }
110
- return k;
111
- }).join(",") : void 0;
112
- await tools.updateMemory({
113
- operation: "replace",
114
- topic,
115
- content: plan
116
- });
117
- context.logger.info(`Plan saved to memory as: ${topic}`);
118
- } catch (error) {
119
- context.logger.warn("Failed to save plan to memory:", error);
120
- }
121
- }
122
- return { plan: plan || void 0, files: outputFiles, messages: result.messages };
123
- }
124
- context.logger.warn("Failed to generate plan.", result);
125
- throw new Error("Failed to generate plan.");
126
- }
127
- var planWorkflow = async (input, context) => {
128
- const { tools, logger, step } = context;
129
- const { fileContent, filePath, mode: inputMode, interactive, additionalTools } = input;
130
- const mode = interactive === false ? "noninteractive" : inputMode ?? "interactive";
131
- let currentTask = input.task;
132
- let plan = fileContent || "";
133
- let files = [];
134
- let userFeedback;
135
- let messages;
136
- let state = "Generating";
137
- let count = 0;
138
- while (state !== "Done") {
139
- state = await step(`plan-iteration-${count++}`, async () => {
140
- switch (state) {
141
- case "Generating": {
142
- if (!currentTask) {
143
- const message = plan ? "How would you like to improve the plan?" : "What is the task you want to plan?";
144
- const defaultTask = plan ? "Review and improve the plan" : void 0;
145
- try {
146
- currentTask = await tools.input({
147
- message,
148
- default: defaultTask
149
- });
150
- } catch (_error) {
151
- return "Done";
152
- }
153
- }
154
- const planResult = await createPlan(
155
- {
156
- task: currentTask,
157
- plan,
158
- userFeedback,
159
- files: input.files,
160
- interactive: mode === "interactive" || mode === "confirm",
161
- messages,
162
- additionalTools,
163
- config: input.config
164
- },
165
- context
166
- );
167
- messages = planResult.messages;
168
- if (planResult.reason) {
169
- logger.info(planResult.reason);
170
- return "Done";
171
- }
172
- if (planResult.question) {
173
- try {
174
- userFeedback = await tools.input({
175
- message: planResult.question.question,
176
- default: planResult.question.defaultAnswer || void 0
177
- });
178
- plan = planResult.plan || plan;
179
- return "Generating";
180
- } catch (error) {
181
- if (error instanceof UserCancelledError) {
182
- throw error;
183
- }
184
- return "Done";
185
- }
186
- }
187
- plan = planResult.plan || "";
188
- files = planResult.files || [];
189
- userFeedback = "";
190
- return "Reviewing";
191
- }
192
- case "Reviewing": {
193
- logger.info("\nGenerated Plan:\n");
194
- logger.info(plan);
195
- if (files?.length > 0) {
196
- logger.info("\nFiles:");
197
- for (const file of files) {
198
- logger.info(`- ${file.path}`);
199
- }
200
- }
201
- if (mode === "noninteractive") {
202
- return "Done";
203
- }
204
- if (mode === "confirm") {
205
- try {
206
- userFeedback = await tools.input({
207
- message: "Do you approve this plan and want to proceed with implementation? (leave blank to approve, or enter feedback)"
208
- });
209
- if (userFeedback === "") {
210
- return "Done";
211
- } else {
212
- return "Generating";
213
- }
214
- } catch (error) {
215
- if (error instanceof UserCancelledError) {
216
- throw error;
217
- }
218
- userFeedback = "";
219
- return "Reviewing";
220
- }
221
- }
222
- const choices = [
223
- { name: "Save Plan", value: "save" },
224
- { name: "Provide Feedback", value: "feedback" },
225
- { name: "Regenerate Plan", value: "regenerate" },
226
- { name: "Exit", value: "exit" }
227
- ];
228
- const choice = await tools.select({
229
- message: "What do you want to do?",
230
- choices
231
- });
232
- switch (choice) {
233
- case "save": {
234
- const defaultPath = `.plans/plan-${(/* @__PURE__ */ new Date()).toISOString().replace(/:/g, "-")}.md`;
235
- const savePath = filePath || await tools.input({
236
- message: "Where do you want to save the plan?",
237
- default: defaultPath
238
- });
239
- await tools.writeToFile({ path: savePath, content: plan });
240
- logger.info(`Plan saved to ${savePath}`);
241
- return "Done";
242
- }
243
- case "feedback": {
244
- try {
245
- userFeedback = await tools.input({
246
- message: "What changes do you want to make?"
247
- });
248
- return "Generating";
249
- } catch (_error) {
250
- userFeedback = "";
251
- return "Reviewing";
252
- }
253
- }
254
- case "regenerate": {
255
- plan = "";
256
- userFeedback = "";
257
- messages = void 0;
258
- return "Generating";
259
- }
260
- case "exit": {
261
- return "Done";
262
- }
263
- default:
264
- throw new Error(`Invalid mode: ${mode}`);
265
- }
266
- }
267
- default:
268
- throw new Error(`Invalid state: ${state}`);
269
- }
270
- });
271
- }
272
- return { plan, files };
273
- };
274
-
275
- export {
276
- planWorkflow
277
- };