genaicode 0.0.37 → 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 (312) hide show
  1. package/README.md +3 -1
  2. package/bin/genaicode-dev.js +11 -0
  3. package/bin/genaicode.cjs +15 -1
  4. package/dist/ai-service/ai-studio.d.ts +6 -0
  5. package/dist/ai-service/ai-studio.js +135 -0
  6. package/dist/ai-service/ai-studio.js.map +1 -0
  7. package/dist/ai-service/anthropic.d.ts +6 -0
  8. package/dist/ai-service/anthropic.js +135 -0
  9. package/dist/ai-service/anthropic.js.map +1 -0
  10. package/dist/ai-service/chat-gpt.d.ts +5 -0
  11. package/dist/ai-service/chat-gpt.js +132 -0
  12. package/dist/ai-service/chat-gpt.js.map +1 -0
  13. package/dist/ai-service/common.d.ts +58 -0
  14. package/dist/ai-service/common.js +38 -0
  15. package/dist/ai-service/common.js.map +1 -0
  16. package/dist/ai-service/common.test.d.ts +1 -0
  17. package/dist/ai-service/common.test.js +85 -0
  18. package/dist/ai-service/common.test.js.map +1 -0
  19. package/dist/ai-service/dall-e.d.ts +14 -0
  20. package/dist/ai-service/dall-e.js +48 -0
  21. package/dist/ai-service/dall-e.js.map +1 -0
  22. package/dist/ai-service/vertex-ai-claude.d.ts +5 -0
  23. package/dist/ai-service/vertex-ai-claude.js +94 -0
  24. package/dist/ai-service/vertex-ai-claude.js.map +1 -0
  25. package/dist/ai-service/vertex-ai-imagen.d.ts +14 -0
  26. package/dist/ai-service/vertex-ai-imagen.js +77 -0
  27. package/dist/ai-service/vertex-ai-imagen.js.map +1 -0
  28. package/dist/ai-service/vertex-ai.d.ts +7 -0
  29. package/dist/ai-service/vertex-ai.js +142 -0
  30. package/dist/ai-service/vertex-ai.js.map +1 -0
  31. package/dist/cli/cli-options.d.ts +10 -0
  32. package/dist/cli/cli-options.js +124 -0
  33. package/dist/cli/cli-options.js.map +1 -0
  34. package/dist/cli/cli-options.test.d.ts +1 -0
  35. package/dist/cli/cli-options.test.js +34 -0
  36. package/dist/cli/cli-options.test.js.map +1 -0
  37. package/dist/cli/cli-params.d.ts +30 -0
  38. package/dist/cli/cli-params.js +109 -0
  39. package/dist/cli/cli-params.js.map +1 -0
  40. package/dist/cli/cli-params.test.d.ts +1 -0
  41. package/dist/cli/cli-params.test.js +38 -0
  42. package/dist/cli/cli-params.test.js.map +1 -0
  43. package/dist/cli/service-autodetect.d.ts +2 -0
  44. package/dist/cli/service-autodetect.js +17 -0
  45. package/dist/cli/service-autodetect.js.map +1 -0
  46. package/dist/cli/service-autodetect.test.d.ts +1 -0
  47. package/dist/cli/service-autodetect.test.js +38 -0
  48. package/dist/cli/service-autodetect.test.js.map +1 -0
  49. package/dist/cli/validate-cli-params.d.ts +18 -0
  50. package/dist/cli/validate-cli-params.js +129 -0
  51. package/dist/cli/validate-cli-params.js.map +1 -0
  52. package/dist/cli/validate-cli-params.test.d.ts +1 -0
  53. package/dist/cli/validate-cli-params.test.js +106 -0
  54. package/dist/cli/validate-cli-params.test.js.map +1 -0
  55. package/dist/files/file-utils.d.ts +2 -0
  56. package/dist/files/file-utils.js +7 -0
  57. package/dist/files/file-utils.js.map +1 -0
  58. package/dist/files/file-utils.test.d.ts +1 -0
  59. package/dist/files/file-utils.test.js +18 -0
  60. package/dist/files/file-utils.test.js.map +1 -0
  61. package/dist/files/find-files.d.ts +8 -0
  62. package/dist/files/find-files.js +76 -0
  63. package/dist/files/find-files.js.map +1 -0
  64. package/dist/files/read-files.d.ts +18 -0
  65. package/dist/files/read-files.js +66 -0
  66. package/dist/files/read-files.js.map +1 -0
  67. package/dist/files/read-files.test.d.ts +1 -0
  68. package/dist/files/read-files.test.js +88 -0
  69. package/dist/files/read-files.test.js.map +1 -0
  70. package/dist/files/temp-buffer.d.ts +2 -0
  71. package/dist/files/temp-buffer.js +12 -0
  72. package/dist/files/temp-buffer.js.map +1 -0
  73. package/dist/files/update-files.d.ts +6 -0
  74. package/dist/files/update-files.js +197 -0
  75. package/dist/files/update-files.js.map +1 -0
  76. package/dist/images/ensure-alpha.d.ts +1 -0
  77. package/dist/images/ensure-alpha.js +5 -0
  78. package/dist/images/ensure-alpha.js.map +1 -0
  79. package/dist/images/imgly-remove-background.d.ts +2 -0
  80. package/dist/images/imgly-remove-background.js +21 -0
  81. package/dist/images/imgly-remove-background.js.map +1 -0
  82. package/dist/images/resize-image.d.ts +19 -0
  83. package/dist/images/resize-image.js +22 -0
  84. package/dist/images/resize-image.js.map +1 -0
  85. package/dist/images/split-image.d.ts +18 -0
  86. package/dist/images/split-image.js +25 -0
  87. package/dist/images/split-image.js.map +1 -0
  88. package/dist/main/codegen-interactive-utils.d.ts +8 -0
  89. package/dist/main/codegen-interactive-utils.js +148 -0
  90. package/dist/main/codegen-interactive-utils.js.map +1 -0
  91. package/dist/main/codegen-interactive.d.ts +2 -0
  92. package/dist/main/codegen-interactive.js +68 -0
  93. package/dist/main/codegen-interactive.js.map +1 -0
  94. package/dist/main/codegen-types.d.ts +28 -0
  95. package/dist/main/codegen-types.js +2 -0
  96. package/dist/main/codegen-types.js.map +1 -0
  97. package/dist/main/codegen.d.ts +4 -0
  98. package/dist/main/codegen.js +164 -0
  99. package/dist/main/codegen.js.map +1 -0
  100. package/dist/main/codegen.test.d.ts +2 -0
  101. package/dist/main/codegen.test.js +273 -0
  102. package/dist/main/codegen.test.js.map +1 -0
  103. package/dist/main/config-lib.d.ts +16 -0
  104. package/dist/main/config-lib.js +28 -0
  105. package/dist/main/config-lib.js.map +1 -0
  106. package/dist/main/config-lib.test.d.ts +1 -0
  107. package/dist/main/config-lib.test.js +64 -0
  108. package/dist/main/config-lib.test.js.map +1 -0
  109. package/dist/main/config.d.ts +6 -0
  110. package/{src → dist}/main/config.js +28 -22
  111. package/dist/main/config.js.map +1 -0
  112. package/dist/main/interactive/codegen-interactive.d.ts +2 -0
  113. package/dist/main/interactive/codegen-interactive.js +55 -0
  114. package/dist/main/interactive/codegen-interactive.js.map +1 -0
  115. package/dist/main/interactive/codegen-interactive.test.d.ts +4 -0
  116. package/dist/main/interactive/codegen-interactive.test.js +77 -0
  117. package/dist/main/interactive/codegen-interactive.test.js.map +1 -0
  118. package/dist/main/interactive/codegen-worker.d.ts +3 -0
  119. package/dist/main/interactive/codegen-worker.js +47 -0
  120. package/dist/main/interactive/codegen-worker.js.map +1 -0
  121. package/dist/main/interactive/common.d.ts +5 -0
  122. package/dist/main/interactive/common.js +51 -0
  123. package/dist/main/interactive/common.js.map +1 -0
  124. package/dist/main/interactive/configure.d.ts +2 -0
  125. package/dist/main/interactive/configure.js +99 -0
  126. package/dist/main/interactive/configure.js.map +1 -0
  127. package/dist/main/interactive/error-handling.d.ts +4 -0
  128. package/dist/main/interactive/error-handling.js +49 -0
  129. package/dist/main/interactive/error-handling.js.map +1 -0
  130. package/dist/main/interactive/help.d.ts +1 -0
  131. package/dist/main/interactive/help.js +22 -0
  132. package/dist/main/interactive/help.js.map +1 -0
  133. package/dist/main/interactive/process-comments.d.ts +2 -0
  134. package/dist/main/interactive/process-comments.js +39 -0
  135. package/dist/main/interactive/process-comments.js.map +1 -0
  136. package/dist/main/interactive/select-ai-service.d.ts +2 -0
  137. package/dist/main/interactive/select-ai-service.js +27 -0
  138. package/dist/main/interactive/select-ai-service.js.map +1 -0
  139. package/dist/main/interactive/task-file.d.ts +2 -0
  140. package/dist/main/interactive/task-file.js +28 -0
  141. package/dist/main/interactive/task-file.js.map +1 -0
  142. package/dist/main/interactive/text-prompt.d.ts +2 -0
  143. package/dist/main/interactive/text-prompt.js +18 -0
  144. package/dist/main/interactive/text-prompt.js.map +1 -0
  145. package/dist/main/interactive/user-interrupt.d.ts +1 -0
  146. package/dist/main/interactive/user-interrupt.js +36 -0
  147. package/dist/main/interactive/user-interrupt.js.map +1 -0
  148. package/dist/main/interactive/worker-script.d.ts +1 -0
  149. package/dist/main/interactive/worker-script.js +24 -0
  150. package/dist/main/interactive/worker-script.js.map +1 -0
  151. package/dist/main/interactive/worker.d.ts +2 -0
  152. package/dist/main/interactive/worker.js +55 -0
  153. package/dist/main/interactive/worker.js.map +1 -0
  154. package/dist/prompt/function-calling-validate.d.ts +3 -0
  155. package/dist/prompt/function-calling-validate.js +33 -0
  156. package/dist/prompt/function-calling-validate.js.map +1 -0
  157. package/dist/prompt/function-calling.d.ts +5 -0
  158. package/{src → dist}/prompt/function-calling.js +25 -24
  159. package/dist/prompt/function-calling.js.map +1 -0
  160. package/dist/prompt/function-defs/ask-question.d.ts +65 -0
  161. package/dist/prompt/function-defs/ask-question.js +67 -0
  162. package/dist/prompt/function-defs/ask-question.js.map +1 -0
  163. package/dist/prompt/function-defs/codegen-summary.d.ts +63 -0
  164. package/dist/prompt/function-defs/codegen-summary.js +80 -0
  165. package/dist/prompt/function-defs/codegen-summary.js.map +1 -0
  166. package/dist/prompt/function-defs/create-directory.d.ts +21 -0
  167. package/dist/prompt/function-defs/create-directory.js +22 -0
  168. package/dist/prompt/function-defs/create-directory.js.map +1 -0
  169. package/dist/prompt/function-defs/create-file.d.ts +25 -0
  170. package/dist/prompt/function-defs/create-file.js +26 -0
  171. package/dist/prompt/function-defs/create-file.js.map +1 -0
  172. package/dist/prompt/function-defs/delete-file.d.ts +21 -0
  173. package/dist/prompt/function-defs/delete-file.js +22 -0
  174. package/dist/prompt/function-defs/delete-file.js.map +1 -0
  175. package/dist/prompt/function-defs/download-file.d.ts +25 -0
  176. package/dist/prompt/function-defs/download-file.js +26 -0
  177. package/dist/prompt/function-defs/download-file.js.map +1 -0
  178. package/dist/prompt/function-defs/explanation.d.ts +17 -0
  179. package/dist/prompt/function-defs/explanation.js +18 -0
  180. package/dist/prompt/function-defs/explanation.js.map +1 -0
  181. package/dist/prompt/function-defs/generate-image.d.ts +41 -0
  182. package/dist/prompt/function-defs/generate-image.js +42 -0
  183. package/dist/prompt/function-defs/generate-image.js.map +1 -0
  184. package/dist/prompt/function-defs/get-image-assets.d.ts +20 -0
  185. package/dist/prompt/function-defs/get-image-assets.js +21 -0
  186. package/dist/prompt/function-defs/get-image-assets.js.map +1 -0
  187. package/dist/prompt/function-defs/get-source-code.d.ts +20 -0
  188. package/dist/prompt/function-defs/get-source-code.js +21 -0
  189. package/dist/prompt/function-defs/get-source-code.js.map +1 -0
  190. package/dist/prompt/function-defs/imgly-remove-background.d.ts +25 -0
  191. package/dist/prompt/function-defs/imgly-remove-background.js +26 -0
  192. package/dist/prompt/function-defs/imgly-remove-background.js.map +1 -0
  193. package/dist/prompt/function-defs/move-file.d.ts +25 -0
  194. package/dist/prompt/function-defs/move-file.js +26 -0
  195. package/dist/prompt/function-defs/move-file.js.map +1 -0
  196. package/dist/prompt/function-defs/patch-file.d.ts +25 -0
  197. package/dist/prompt/function-defs/patch-file.js +39 -0
  198. package/dist/prompt/function-defs/patch-file.js.map +1 -0
  199. package/dist/prompt/function-defs/resize-image.d.ts +36 -0
  200. package/dist/prompt/function-defs/resize-image.js +37 -0
  201. package/dist/prompt/function-defs/resize-image.js.map +1 -0
  202. package/dist/prompt/function-defs/split-image.d.ts +57 -0
  203. package/dist/prompt/function-defs/split-image.js +46 -0
  204. package/dist/prompt/function-defs/split-image.js.map +1 -0
  205. package/dist/prompt/function-defs/update-file.d.ts +25 -0
  206. package/dist/prompt/function-defs/update-file.js +26 -0
  207. package/dist/prompt/function-defs/update-file.js.map +1 -0
  208. package/dist/prompt/limits.d.ts +3 -0
  209. package/dist/prompt/limits.js +19 -0
  210. package/dist/prompt/limits.js.map +1 -0
  211. package/dist/prompt/limits.test.d.ts +1 -0
  212. package/dist/prompt/limits.test.js +35 -0
  213. package/dist/prompt/limits.test.js.map +1 -0
  214. package/dist/prompt/prompt-codegen.d.ts +9 -0
  215. package/dist/prompt/prompt-codegen.js +90 -0
  216. package/dist/prompt/prompt-codegen.js.map +1 -0
  217. package/dist/prompt/prompt-codegen.test.d.ts +1 -0
  218. package/dist/prompt/prompt-codegen.test.js +98 -0
  219. package/dist/prompt/prompt-codegen.test.js.map +1 -0
  220. package/dist/prompt/prompt-consts.d.ts +1 -0
  221. package/{src → dist}/prompt/prompt-consts.js +1 -0
  222. package/dist/prompt/prompt-consts.js.map +1 -0
  223. package/dist/prompt/prompt-service-ask-question.test.d.ts +3 -0
  224. package/dist/prompt/prompt-service-ask-question.test.js +142 -0
  225. package/dist/prompt/prompt-service-ask-question.test.js.map +1 -0
  226. package/dist/prompt/prompt-service.d.ts +28 -0
  227. package/dist/prompt/prompt-service.js +163 -0
  228. package/dist/prompt/prompt-service.js.map +1 -0
  229. package/dist/prompt/prompt-service.test.d.ts +1 -0
  230. package/dist/prompt/prompt-service.test.js +531 -0
  231. package/dist/prompt/prompt-service.test.js.map +1 -0
  232. package/dist/prompt/steps/step-ask-question.d.ts +6 -0
  233. package/dist/prompt/steps/step-ask-question.js +82 -0
  234. package/dist/prompt/steps/step-ask-question.js.map +1 -0
  235. package/dist/prompt/steps/step-generate-image.d.ts +2 -0
  236. package/dist/prompt/steps/step-generate-image.js +29 -0
  237. package/dist/prompt/steps/step-generate-image.js.map +1 -0
  238. package/dist/prompt/steps/step-validate-recover.d.ts +13 -0
  239. package/dist/prompt/steps/step-validate-recover.js +51 -0
  240. package/dist/prompt/steps/step-validate-recover.js.map +1 -0
  241. package/dist/prompt/steps/step-verify-patch.d.ts +7 -0
  242. package/dist/prompt/steps/step-verify-patch.js +41 -0
  243. package/dist/prompt/steps/step-verify-patch.js.map +1 -0
  244. package/dist/prompt/steps/steps-types.d.ts +4 -0
  245. package/dist/prompt/steps/steps-types.js +6 -0
  246. package/dist/prompt/steps/steps-types.js.map +1 -0
  247. package/dist/prompt/systemprompt.d.ts +3 -0
  248. package/dist/prompt/systemprompt.js +47 -0
  249. package/dist/prompt/systemprompt.js.map +1 -0
  250. package/dist/prompt/systemprompt.test.d.ts +3 -0
  251. package/dist/prompt/systemprompt.test.js +46 -0
  252. package/dist/prompt/systemprompt.test.js.map +1 -0
  253. package/package.json +15 -5
  254. package/bin/genaicode.js +0 -5
  255. package/bin/vertex-monkey-patch.cjs +0 -33
  256. package/src/ai-service/anthropic.js +0 -126
  257. package/src/ai-service/chat-gpt.js +0 -126
  258. package/src/ai-service/common.js +0 -49
  259. package/src/ai-service/common.test.js +0 -107
  260. package/src/ai-service/dall-e.js +0 -50
  261. package/src/ai-service/vertex-ai-claude.js +0 -99
  262. package/src/ai-service/vertex-ai-imagen.js +0 -78
  263. package/src/ai-service/vertex-ai.js +0 -156
  264. package/src/cli/cli-options.js +0 -132
  265. package/src/cli/cli-options.test.js +0 -50
  266. package/src/cli/cli-params.js +0 -114
  267. package/src/cli/cli-params.test.js +0 -43
  268. package/src/cli/service-autodetect.js +0 -11
  269. package/src/cli/service-autodetect.test.js +0 -43
  270. package/src/cli/validate-cli-params.js +0 -137
  271. package/src/cli/validate-cli-params.test.js +0 -134
  272. package/src/files/file-utils.js +0 -7
  273. package/src/files/file-utils.test.js +0 -21
  274. package/src/files/find-files.js +0 -86
  275. package/src/files/read-files.js +0 -65
  276. package/src/files/read-files.test.js +0 -103
  277. package/src/files/temp-buffer.js +0 -13
  278. package/src/files/update-files.js +0 -205
  279. package/src/images/ensure-alpha.js +0 -5
  280. package/src/images/imgly-remove-background.js +0 -23
  281. package/src/images/resize-image.js +0 -23
  282. package/src/images/split-image.js +0 -26
  283. package/src/main/codegen.js +0 -120
  284. package/src/main/codegen.test.js +0 -335
  285. package/src/main/config-lib.js +0 -33
  286. package/src/main/config-lib.test.js +0 -80
  287. package/src/prompt/function-calling-validate.js +0 -25
  288. package/src/prompt/function-defs/ask-question.js +0 -33
  289. package/src/prompt/function-defs/codegen-summary.js +0 -87
  290. package/src/prompt/function-defs/create-directory.js +0 -21
  291. package/src/prompt/function-defs/create-file.js +0 -26
  292. package/src/prompt/function-defs/delete-file.js +0 -21
  293. package/src/prompt/function-defs/download-file.js +0 -25
  294. package/src/prompt/function-defs/explanation.js +0 -17
  295. package/src/prompt/function-defs/generate-image.js +0 -51
  296. package/src/prompt/function-defs/get-image-assets.js +0 -21
  297. package/src/prompt/function-defs/get-source-code.js +0 -21
  298. package/src/prompt/function-defs/imgly-remove-background.js +0 -25
  299. package/src/prompt/function-defs/move-file.js +0 -25
  300. package/src/prompt/function-defs/patch-file.js +0 -39
  301. package/src/prompt/function-defs/resize-image.js +0 -36
  302. package/src/prompt/function-defs/split-image.js +0 -45
  303. package/src/prompt/function-defs/update-file.js +0 -26
  304. package/src/prompt/limits.js +0 -23
  305. package/src/prompt/limits.test.js +0 -40
  306. package/src/prompt/prompt-codegen.js +0 -106
  307. package/src/prompt/prompt-codegen.test.js +0 -116
  308. package/src/prompt/prompt-service-ask-question.test.js +0 -163
  309. package/src/prompt/prompt-service.js +0 -335
  310. package/src/prompt/prompt-service.test.js +0 -602
  311. package/src/prompt/systemprompt.js +0 -39
  312. package/src/prompt/systemprompt.test.js +0 -64
@@ -1,21 +0,0 @@
1
- import { vi, describe, beforeEach, it, expect } from 'vitest';
2
- import { isAncestorDirectory } from './file-utils.js';
3
-
4
- // Test for isAncestorDirectory
5
- describe('isAncestorDirectory', () => {
6
- beforeEach(() => {
7
- vi.resetAllMocks();
8
- });
9
-
10
- it('should return true if directories are the same', () => {
11
- expect(isAncestorDirectory('/project', '/project')).toBe(true);
12
- });
13
-
14
- it('should return true if parent is ancestor of dir', () => {
15
- expect(isAncestorDirectory('/project', '/project/src')).toBe(true);
16
- });
17
-
18
- it('should return false if parent is not ancestor of dir', () => {
19
- expect(isAncestorDirectory('/project', '/other')).toBe(false);
20
- });
21
- });
@@ -1,86 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { rcConfig, sourceExtensions, IMAGE_ASSET_EXTENSIONS, ignorePaths } from '../main/config.js';
4
-
5
- // List of possible extensions for dependency resolution
6
- const POSSIBLE_DEPENDENCY_EXTENSIONS = ['.ts', '.js', '.tsx', '.jsx'];
7
-
8
- function findFiles(dir, recursive, extensions) {
9
- const files = [];
10
- const items = fs.readdirSync(dir);
11
- for (const item of items) {
12
- const fullPath = path.join(dir, item);
13
-
14
- if (ignorePaths.some((ignorePath) => fullPath.endsWith(ignorePath))) {
15
- continue;
16
- }
17
-
18
- if (fs.statSync(fullPath).isDirectory()) {
19
- if (recursive) {
20
- files.push(...findFiles(fullPath, true, extensions));
21
- }
22
- } else if (extensions.includes(path.extname(fullPath))) {
23
- files.push(fullPath);
24
- }
25
- }
26
- return files;
27
- }
28
-
29
- function getDependencies(filePath) {
30
- const content = fs.readFileSync(filePath, 'utf-8');
31
- const dependencyRegex = /import\s+.+?\s+from\s+['"](.+?\/?[^'"]+)['"]/g;
32
- const dependencies = [];
33
- let match;
34
- while ((match = dependencyRegex.exec(content)) !== null) {
35
- const dependencyPath = match[1];
36
- // Resolve relative paths from the file's directory
37
- let resolvedPath = path.resolve(path.dirname(filePath), dependencyPath);
38
-
39
- // Only add the dependency if it's a local file and not a module
40
- if (fs.existsSync(resolvedPath)) {
41
- dependencies.push(resolvedPath);
42
- } else {
43
- const possibleExtensions = POSSIBLE_DEPENDENCY_EXTENSIONS;
44
- for (const ext of possibleExtensions) {
45
- const extendedPath = resolvedPath + ext;
46
- if (fs.existsSync(extendedPath)) {
47
- dependencies.push(extendedPath);
48
- }
49
- }
50
- }
51
- }
52
- return dependencies;
53
- }
54
-
55
- /** Generates a dependency list for given file */
56
- export function getDependencyList(entryFile) {
57
- const visitedFiles = new Set();
58
- const result = new Set();
59
-
60
- function traverse(file) {
61
- if (visitedFiles.has(file)) return;
62
- visitedFiles.add(file);
63
- const dependencies = getDependencies(file);
64
- dependencies.forEach((dependency) => result.add(dependency));
65
- dependencies.forEach(traverse);
66
- }
67
-
68
- result.add(path.resolve(entryFile));
69
- traverse(entryFile);
70
-
71
- return Array.from(result);
72
- }
73
-
74
- const sourceFiles = findFiles(rcConfig.rootDir, true, sourceExtensions);
75
-
76
- /** Get source files of the application */
77
- export function getSourceFiles() {
78
- return [...sourceFiles];
79
- }
80
-
81
- const imageAssetFiles = findFiles(rcConfig.rootDir, true, IMAGE_ASSET_EXTENSIONS);
82
-
83
- /** Get source files of the application */
84
- export function getImageAssetFiles() {
85
- return [...imageAssetFiles];
86
- }
@@ -1,65 +0,0 @@
1
- import fs from 'fs';
2
- import mime from 'mime-types';
3
- import sizeOf from 'image-size';
4
- import path from 'path';
5
- import globRegex from 'glob-regex';
6
-
7
- import { getSourceFiles, getImageAssetFiles } from './find-files.js';
8
- import { rcConfig } from '../main/config.js';
9
- import { verifySourceCodeLimit } from '../prompt/limits.js';
10
- import { taskFile, contentMask, ignorePatterns } from '../cli/cli-params.js';
11
-
12
- /**
13
- * Read contents of source files and create a map with file path as key and file content as value
14
- */
15
- function readSourceFiles(filterPaths) {
16
- const sourceCode = {};
17
- for (const file of getSourceFiles()) {
18
- if (!filterPaths || filterPaths.includes(file)) {
19
- // Apply content mask filter if it's set
20
- if (!filterPaths && contentMask) {
21
- const relativePath = path.relative(rcConfig.rootDir, file);
22
- if (!relativePath.startsWith(contentMask)) {
23
- sourceCode[file] = { content: null }; // Include the file path but set content to null
24
- continue;
25
- }
26
- }
27
- if (ignorePatterns.some((pattern) => globRegex(pattern).test(file))) {
28
- sourceCode[file] = { content: null };
29
- } else {
30
- const content = fs.readFileSync(file, 'utf-8');
31
- sourceCode[file] = { content };
32
- }
33
- }
34
- }
35
- return sourceCode;
36
- }
37
-
38
- /** Print source code of all source files */
39
- export function getSourceCode(filterPaths) {
40
- const sourceCode = readSourceFiles(filterPaths);
41
-
42
- if (taskFile && !sourceCode[taskFile]) {
43
- sourceCode[taskFile] = {
44
- content: fs.readFileSync(taskFile, 'utf-8'),
45
- };
46
- }
47
-
48
- verifySourceCodeLimit(JSON.stringify(sourceCode));
49
- return sourceCode;
50
- }
51
-
52
- /** Get image asset files summary */
53
- export function getImageAssets() {
54
- const imageAssets = {};
55
- for (const file of getImageAssetFiles()) {
56
- const dimensions = sizeOf(file);
57
- imageAssets[file] = {
58
- mimeType: mime.lookup(file),
59
- width: dimensions.width,
60
- height: dimensions.height,
61
- };
62
- }
63
- verifySourceCodeLimit(JSON.stringify(imageAssets));
64
- return imageAssets;
65
- }
@@ -1,103 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
- import fs from 'fs';
3
- import mime from 'mime-types';
4
- import sizeOf from 'image-size';
5
- import { getSourceCode, getImageAssets } from './read-files.js';
6
- import { getSourceFiles, getImageAssetFiles } from './find-files.js';
7
- import { verifySourceCodeLimit } from '../prompt/limits.js';
8
- import * as cliParams from '../cli/cli-params.js';
9
- import { rcConfig } from '../main/config.js';
10
-
11
- vi.mock('fs');
12
- vi.mock('mime-types');
13
- vi.mock('image-size');
14
- vi.mock('./find-files.js', () => ({
15
- getImageAssetFiles: vi.fn(),
16
- getSourceFiles: vi.fn(),
17
- }));
18
- vi.mock('../prompt/limits.js');
19
- vi.mock('../cli/cli-params.js', () => ({
20
- taskFile: null,
21
- contentMask: null,
22
- ignorePatterns: [],
23
- }));
24
- vi.mock('../main/config.js', () => ({
25
- rcConfig: { rootDir: '/home/project' },
26
- }));
27
-
28
- describe('read-files', () => {
29
- beforeEach(() => {
30
- vi.resetAllMocks();
31
- vi.mocked(cliParams).contentMask = undefined;
32
- });
33
-
34
- afterEach(() => {
35
- vi.clearAllMocks();
36
- });
37
-
38
- describe('getSourceCode', () => {
39
- it('should return source code for all files', () => {
40
- const mockFiles = ['/home/project/file1.js', '/home/project/file2.js'];
41
- getSourceFiles.mockReturnValue(mockFiles);
42
- fs.readFileSync.mockImplementation((file) => `Content of ${file}`);
43
- rcConfig.rootDir = '/home/project';
44
-
45
- const result = getSourceCode();
46
-
47
- expect(result).toEqual({
48
- '/home/project/file1.js': { content: 'Content of /home/project/file1.js' },
49
- '/home/project/file2.js': { content: 'Content of /home/project/file2.js' },
50
- });
51
- expect(verifySourceCodeLimit).toHaveBeenCalled();
52
- });
53
-
54
- it('should apply content mask when specified', () => {
55
- const mockFiles = ['/home/project/file1.js', '/home/project/subfolder/file2.js'];
56
- getSourceFiles.mockReturnValue(mockFiles);
57
- fs.readFileSync.mockImplementation((file) => `Content of ${file}`);
58
- rcConfig.rootDir = '/home/project';
59
- vi.mocked(cliParams).contentMask = 'subfolder';
60
-
61
- const result = getSourceCode();
62
-
63
- expect(result).toEqual({
64
- '/home/project/file1.js': { content: null },
65
- '/home/project/subfolder/file2.js': {
66
- content: 'Content of /home/project/subfolder/file2.js',
67
- },
68
- });
69
- });
70
-
71
- it('should include task file when specified', () => {
72
- const mockFiles = ['/home/project/file1.js'];
73
- getSourceFiles.mockReturnValue(mockFiles);
74
- fs.readFileSync.mockImplementation((file) => `Content of ${file}`);
75
- rcConfig.rootDir = '/home/project';
76
- vi.mocked(cliParams).taskFile = '/home/project/task.md';
77
-
78
- const result = getSourceCode();
79
-
80
- expect(result).toEqual({
81
- '/home/project/file1.js': { content: 'Content of /home/project/file1.js' },
82
- '/home/project/task.md': { content: 'Content of /home/project/task.md' },
83
- });
84
- });
85
- });
86
-
87
- describe('getImageAssets', () => {
88
- it('should return image assets information', () => {
89
- const mockImageFiles = ['/home/project/image1.png', '/home/project/image2.jpg'];
90
- getImageAssetFiles.mockReturnValue(mockImageFiles);
91
- mime.lookup.mockImplementation((file) => (file.endsWith('.png') ? 'image/png' : 'image/jpeg'));
92
- sizeOf.mockImplementation(() => ({ width: 100, height: 200 }));
93
-
94
- const result = getImageAssets();
95
-
96
- expect(result).toEqual({
97
- '/home/project/image1.png': { mimeType: 'image/png', width: 100, height: 200 },
98
- '/home/project/image2.jpg': { mimeType: 'image/jpeg', width: 100, height: 200 },
99
- });
100
- expect(verifySourceCodeLimit).toHaveBeenCalled();
101
- });
102
- });
103
- });
@@ -1,13 +0,0 @@
1
- /** Temporary storage */
2
- let tempId = 1;
3
- const temp = {};
4
-
5
- export function getTempBuffer(url) {
6
- return temp[url];
7
- }
8
-
9
- export function setTempBuffer(buffer) {
10
- const imageUrl = 'temp://' + tempId++;
11
- temp[imageUrl] = buffer;
12
- return imageUrl;
13
- }
@@ -1,205 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import assert from 'node:assert';
4
- import * as diff from 'diff';
5
-
6
- import { getSourceFiles } from './find-files.js';
7
- import { isAncestorDirectory } from './file-utils.js';
8
- import { rcConfig } from '../main/config.js';
9
- import {
10
- allowDirectoryCreate,
11
- allowFileCreate,
12
- allowFileDelete,
13
- allowFileMove,
14
- anthropic,
15
- chatGpt,
16
- vertexAiClaude,
17
- } from '../cli/cli-params.js';
18
- import { getTempBuffer } from './temp-buffer.js';
19
- import { imglyRemoveBackground } from '../images/imgly-remove-background.js';
20
- import { splitImage } from '../images/split-image.js';
21
- import { resizeImageFile } from '../images/resize-image.js';
22
-
23
- /**
24
- * @param functionCalls Result of the code generation, a map of file paths to new content
25
- */
26
- export async function updateFiles(functionCalls) {
27
- for (const { name, args } of functionCalls) {
28
- let {
29
- filePath,
30
- newContent,
31
- source,
32
- destination,
33
- patch,
34
- inputFilePath,
35
- outputFilePath,
36
- backgroundColor,
37
- parts,
38
- size,
39
- } = args;
40
-
41
- // Check if filePath is absolute, if not use rootDir as baseline
42
- if (name !== 'moveFile' && name !== 'imglyRemoveBackground' && name !== 'splitImage') {
43
- filePath = path.isAbsolute(filePath) ? filePath : path.join(rcConfig.rootDir, filePath);
44
- } else if (name === 'moveFile') {
45
- source = path.isAbsolute(source) ? source : path.join(rcConfig.rootDir, source);
46
- destination = path.isAbsolute(destination) ? destination : path.join(rcConfig.rootDir, destination);
47
- } else if (name === 'imglyRemoveBackground' || name === 'splitImage') {
48
- inputFilePath = path.isAbsolute(inputFilePath) ? inputFilePath : path.join(rcConfig.rootDir, inputFilePath);
49
- if (name === 'imglyRemoveBackground') {
50
- outputFilePath = path.isAbsolute(outputFilePath) ? outputFilePath : path.join(rcConfig.rootDir, outputFilePath);
51
- } else if (name === 'splitImage') {
52
- parts.forEach(
53
- (part) =>
54
- (part.outputFilePath = path.isAbsolute(part.outputFilePath)
55
- ? part.outputFilePath
56
- : path.join(rcConfig.rootDir, part.outputFilePath)),
57
- );
58
- }
59
- }
60
-
61
- // ignore files which are not located inside project directory (sourceFiles)
62
- if (
63
- (name !== 'moveFile' && name !== 'imglyRemoveBackground' && name !== 'splitImage' && !isProjectPath(filePath)) ||
64
- (name === 'moveFile' && (!isProjectPath(source) || !isProjectPath(destination))) ||
65
- (name === 'imglyRemoveBackground' && (!isProjectPath(inputFilePath) || !isProjectPath(outputFilePath))) ||
66
- (name === 'splitImage' &&
67
- (!isProjectPath(inputFilePath) || parts.some((part) => !isProjectPath(part.outputFilePath))))
68
- ) {
69
- console.log(`Skipping file: ${filePath || source || inputFilePath}`);
70
- throw new Error(
71
- `File ${filePath || source || inputFilePath} is not located inside project directory, something is wrong?`,
72
- );
73
- }
74
-
75
- if (name === 'deleteFile') {
76
- assert(allowFileDelete, 'File delete option was not enabled');
77
- console.log(`Removing file: ${filePath}`);
78
- fs.unlinkSync(filePath);
79
- } else if (name === 'createDirectory') {
80
- assert(allowDirectoryCreate, 'Directory create option was not enabled');
81
- console.log(`Creating directory: ${filePath}`);
82
- fs.mkdirSync(filePath, { recursive: true });
83
- } else if (name === 'updateFile' || name === 'createFile' || name === 'patchFile') {
84
- if (name === 'patchFile') {
85
- console.log(`Applying a patch: ${filePath} content`);
86
- newContent = diff.applyPatch(fs.readFileSync(filePath, 'utf-8'), patch);
87
- assert(!!newContent, 'Patch was not successful');
88
- }
89
-
90
- assert(!!newContent, 'newContent must not be empty');
91
- if (name === 'createFile') {
92
- console.log(`Creating file: ${filePath}`);
93
- assert(allowFileCreate, 'File create option was not enabled');
94
- assert(!fs.existsSync(filePath), 'File already exists');
95
- if (allowDirectoryCreate) {
96
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
97
- }
98
- } else {
99
- console.log(`Updating file: ${filePath}`);
100
- assert(fs.existsSync(filePath), 'File does not exist');
101
- }
102
- fs.writeFileSync(
103
- filePath,
104
- chatGpt || anthropic || vertexAiClaude
105
- ? newContent
106
- : // Fixing a problem caused by vertex function calling. Possibly not a good fix
107
- newContent.replace(/\\n/g, '\n').replace(/\\'/g, "'"),
108
- 'utf-8',
109
- );
110
- } else if (name === 'moveFile') {
111
- console.log(`Moving file from ${source} to ${destination}`);
112
- assert(fs.existsSync(source), 'Source file does not exist');
113
- assert(!fs.existsSync(destination), 'Destination file already exists');
114
- assert(allowFileMove, 'File move option was not enabled');
115
- if (allowDirectoryCreate) {
116
- fs.mkdirSync(path.dirname(destination), { recursive: true });
117
- }
118
- fs.renameSync(source, destination);
119
- } else if (name === 'downloadFile') {
120
- console.log(`Downloading image: ${filePath}`);
121
- assert(fs.existsSync(filePath) || allowFileCreate, 'File create option was not enabled and file does not exist');
122
- if (allowDirectoryCreate) {
123
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
124
- }
125
- try {
126
- assert(args.downloadUrl, 'image url is not empty');
127
- if (args.downloadUrl.startsWith('temp://')) {
128
- assert(getTempBuffer(args.downloadUrl), 'Temp buffer not present but expected');
129
- fs.writeFileSync(filePath, getTempBuffer(args.downloadUrl));
130
- } else {
131
- const imageResponse = await fetch(args.downloadUrl);
132
- const arrayBuffer = await imageResponse.arrayBuffer();
133
- const buffer = Buffer.from(arrayBuffer);
134
- fs.writeFileSync(filePath, buffer);
135
- }
136
- console.log(`Image download and saved to: ${filePath}`);
137
- } catch (error) {
138
- console.error(`Failed to download image: ${error.message}`);
139
- throw error;
140
- }
141
- } else if (name === 'imglyRemoveBackground') {
142
- console.log(`Removing background from image: ${inputFilePath}`);
143
- assert(fs.existsSync(inputFilePath), 'Input file does not exist');
144
- assert(
145
- allowFileCreate || fs.existsSync(outputFilePath),
146
- 'File create option was not enabled and output file does not exist',
147
- );
148
- if (allowDirectoryCreate) {
149
- fs.mkdirSync(path.dirname(outputFilePath), { recursive: true });
150
- }
151
- try {
152
- await imglyRemoveBackground(inputFilePath, outputFilePath, backgroundColor);
153
- console.log(`Background removed and image saved to: ${outputFilePath}`);
154
- } catch (error) {
155
- console.error(`Failed to remove background: ${error.message}`);
156
- throw error;
157
- }
158
- } else if (name === 'splitImage') {
159
- console.log(`Splitting image: ${inputFilePath}`, parts);
160
- assert(fs.existsSync(inputFilePath), 'Input file does not exist');
161
- assert(Array.isArray(parts) && parts.length > 0, 'Parts array must not be empty');
162
- for (const part of parts) {
163
- assert(
164
- allowFileCreate || fs.existsSync(part.outputFilePath),
165
- 'File create option was not enabled and output file does not exist',
166
- );
167
- if (allowDirectoryCreate) {
168
- fs.mkdirSync(path.dirname(part.outputFilePath), { recursive: true });
169
- }
170
- }
171
- try {
172
- await splitImage(inputFilePath, parts);
173
- console.log(`Image split successfully`);
174
- } catch (error) {
175
- console.error(`Failed to split image: ${error.message}`);
176
- throw error;
177
- }
178
- } else if (name === 'resizeImage') {
179
- console.log(`Resizing image: ${filePath}`, size);
180
- assert(fs.existsSync(filePath), 'Input file does not exist');
181
-
182
- try {
183
- await resizeImageFile(filePath, size);
184
- console.log(`Image resized successfully`);
185
- } catch (error) {
186
- console.error(`Failed to resize image: ${error.message}`);
187
- throw error;
188
- }
189
- }
190
- }
191
- }
192
-
193
- function isProjectPath(filePath) {
194
- const sourceFiles = getSourceFiles();
195
-
196
- return (
197
- isAncestorDirectory(rcConfig.rootDir, filePath) ||
198
- sourceFiles.includes(filePath) ||
199
- !sourceFiles.some(
200
- (sourceFile) =>
201
- path.dirname(filePath) === path.dirname(sourceFile) ||
202
- isAncestorDirectory(path.dirname(sourceFile), path.dirname(filePath)),
203
- )
204
- );
205
- }
@@ -1,5 +0,0 @@
1
- import sharp from 'sharp';
2
-
3
- export async function ensureAlpha(image) {
4
- return sharp(image).ensureAlpha().toBuffer();
5
- }
@@ -1,23 +0,0 @@
1
- import fs from 'fs';
2
- import { createRequire } from 'node:module';
3
-
4
- import { removeBackground } from '@imgly/background-removal-node';
5
-
6
- /** Converts white color to transparency on a image and saves to destination path */
7
- export async function imglyRemoveBackground(inputFilePath, outputFilePath) {
8
- try {
9
- console.log(`Removing background for image: ${inputFilePath}`);
10
-
11
- const publicPath = 'file://' + createRequire(import.meta.url).resolve('@imgly/background-removal-node');
12
- const blob = await removeBackground(inputFilePath, {
13
- publicPath,
14
- });
15
- fs.writeFileSync(outputFilePath, Buffer.from(await blob.arrayBuffer()));
16
-
17
- console.log(`Background removed successfully. Saved to: ${outputFilePath}`);
18
- return outputFilePath;
19
- } catch (error) {
20
- console.error('Error removing background:', error);
21
- throw error;
22
- }
23
- }
@@ -1,23 +0,0 @@
1
- import sharp from 'sharp';
2
- import fs from 'fs';
3
-
4
- /**
5
- *
6
- * @param {Buffer} input
7
- * @param {{width: number, height: number}} size
8
- * @returns {Buffer}
9
- */
10
- export async function resizeImageBuffer(input, size) {
11
- return await sharp(input).resize(size.width, size.height).toBuffer();
12
- }
13
-
14
- /**
15
- *
16
- * @param {string} filePath
17
- * @param {{width: number, height: number}} size
18
- * @returns {Buffer}
19
- */
20
- export async function resizeImageFile(filePath, size) {
21
- const buffer = await resizeImageBuffer(filePath, size);
22
- fs.writeFileSync(filePath, buffer);
23
- }
@@ -1,26 +0,0 @@
1
- import sharp from 'sharp';
2
-
3
- /**
4
- * This function opens the input file, and splits its into parts, extracting parts of the input image, and saving to outputFilePaths
5
- *
6
- * @param {string} inputFilePath
7
- * @param {Array<{rect: {x: number, y: number, width: number, height: number}, outputFilePath: string}>} parts
8
- */
9
- export async function splitImage(inputFilePath, parts) {
10
- try {
11
- // Process each part
12
- for (const part of parts) {
13
- const { rect, outputFilePath } = part;
14
- const { x, y, width, height } = rect;
15
-
16
- // Extract the specified rectangle from the input image
17
- console.log('Extracting', rect, outputFilePath);
18
- await sharp(inputFilePath).extract({ left: x, top: y, width, height }).toFile(outputFilePath);
19
- }
20
-
21
- console.log('Image splitting completed successfully.');
22
- } catch (error) {
23
- console.error('Error splitting image:', error);
24
- throw error;
25
- }
26
- }