genaicode 0.0.37 → 0.1.1

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 (244) hide show
  1. package/bin/genaicode-dev.js +11 -0
  2. package/bin/genaicode.cjs +8 -1
  3. package/dist/ai-service/ai-studio.d.ts +5 -0
  4. package/dist/ai-service/ai-studio.js +135 -0
  5. package/dist/ai-service/ai-studio.js.map +1 -0
  6. package/dist/ai-service/anthropic.d.ts +5 -0
  7. package/dist/ai-service/anthropic.js +133 -0
  8. package/dist/ai-service/anthropic.js.map +1 -0
  9. package/dist/ai-service/chat-gpt.d.ts +5 -0
  10. package/dist/ai-service/chat-gpt.js +131 -0
  11. package/dist/ai-service/chat-gpt.js.map +1 -0
  12. package/dist/ai-service/common.d.ts +57 -0
  13. package/dist/ai-service/common.js +38 -0
  14. package/dist/ai-service/common.js.map +1 -0
  15. package/dist/ai-service/common.test.d.ts +1 -0
  16. package/dist/ai-service/common.test.js +85 -0
  17. package/dist/ai-service/common.test.js.map +1 -0
  18. package/dist/ai-service/dall-e.d.ts +14 -0
  19. package/dist/ai-service/dall-e.js +47 -0
  20. package/dist/ai-service/dall-e.js.map +1 -0
  21. package/dist/ai-service/vertex-ai-claude.d.ts +5 -0
  22. package/dist/ai-service/vertex-ai-claude.js +93 -0
  23. package/dist/ai-service/vertex-ai-claude.js.map +1 -0
  24. package/dist/ai-service/vertex-ai-imagen.d.ts +14 -0
  25. package/dist/ai-service/vertex-ai-imagen.js +74 -0
  26. package/dist/ai-service/vertex-ai-imagen.js.map +1 -0
  27. package/dist/ai-service/vertex-ai.d.ts +7 -0
  28. package/dist/ai-service/vertex-ai.js +147 -0
  29. package/dist/ai-service/vertex-ai.js.map +1 -0
  30. package/dist/cli/cli-options.d.ts +10 -0
  31. package/dist/cli/cli-options.js +124 -0
  32. package/dist/cli/cli-options.js.map +1 -0
  33. package/dist/cli/cli-options.test.d.ts +1 -0
  34. package/dist/cli/cli-options.test.js +34 -0
  35. package/dist/cli/cli-options.test.js.map +1 -0
  36. package/dist/cli/cli-params.d.ts +29 -0
  37. package/dist/cli/cli-params.js +103 -0
  38. package/dist/cli/cli-params.js.map +1 -0
  39. package/dist/cli/cli-params.test.d.ts +1 -0
  40. package/dist/cli/cli-params.test.js +38 -0
  41. package/dist/cli/cli-params.test.js.map +1 -0
  42. package/dist/cli/service-autodetect.d.ts +2 -0
  43. package/dist/cli/service-autodetect.js +17 -0
  44. package/dist/cli/service-autodetect.js.map +1 -0
  45. package/dist/cli/service-autodetect.test.d.ts +1 -0
  46. package/dist/cli/service-autodetect.test.js +38 -0
  47. package/dist/cli/service-autodetect.test.js.map +1 -0
  48. package/dist/cli/validate-cli-params.d.ts +18 -0
  49. package/dist/cli/validate-cli-params.js +128 -0
  50. package/dist/cli/validate-cli-params.js.map +1 -0
  51. package/dist/cli/validate-cli-params.test.d.ts +1 -0
  52. package/dist/cli/validate-cli-params.test.js +106 -0
  53. package/dist/cli/validate-cli-params.test.js.map +1 -0
  54. package/dist/files/file-utils.d.ts +2 -0
  55. package/dist/files/file-utils.js +7 -0
  56. package/dist/files/file-utils.js.map +1 -0
  57. package/dist/files/file-utils.test.d.ts +1 -0
  58. package/dist/files/file-utils.test.js +18 -0
  59. package/dist/files/file-utils.test.js.map +1 -0
  60. package/dist/files/find-files.d.ts +8 -0
  61. package/dist/files/find-files.js +76 -0
  62. package/dist/files/find-files.js.map +1 -0
  63. package/dist/files/read-files.d.ts +13 -0
  64. package/dist/files/read-files.js +61 -0
  65. package/dist/files/read-files.js.map +1 -0
  66. package/dist/files/read-files.test.d.ts +1 -0
  67. package/dist/files/read-files.test.js +89 -0
  68. package/dist/files/read-files.test.js.map +1 -0
  69. package/dist/files/temp-buffer.d.ts +2 -0
  70. package/dist/files/temp-buffer.js +12 -0
  71. package/dist/files/temp-buffer.js.map +1 -0
  72. package/dist/files/update-files.d.ts +5 -0
  73. package/dist/files/update-files.js +197 -0
  74. package/dist/files/update-files.js.map +1 -0
  75. package/dist/images/ensure-alpha.d.ts +1 -0
  76. package/dist/images/ensure-alpha.js +5 -0
  77. package/dist/images/ensure-alpha.js.map +1 -0
  78. package/dist/images/imgly-remove-background.d.ts +2 -0
  79. package/dist/images/imgly-remove-background.js +21 -0
  80. package/dist/images/imgly-remove-background.js.map +1 -0
  81. package/dist/images/resize-image.d.ts +19 -0
  82. package/dist/images/resize-image.js +22 -0
  83. package/dist/images/resize-image.js.map +1 -0
  84. package/dist/images/split-image.d.ts +18 -0
  85. package/dist/images/split-image.js +25 -0
  86. package/dist/images/split-image.js.map +1 -0
  87. package/dist/main/codegen.d.ts +2 -0
  88. package/dist/main/codegen.js +101 -0
  89. package/dist/main/codegen.js.map +1 -0
  90. package/dist/main/codegen.test.d.ts +2 -0
  91. package/dist/main/codegen.test.js +259 -0
  92. package/dist/main/codegen.test.js.map +1 -0
  93. package/dist/main/config-lib.d.ts +8 -0
  94. package/dist/main/config-lib.js +28 -0
  95. package/dist/main/config-lib.js.map +1 -0
  96. package/dist/main/config-lib.test.d.ts +1 -0
  97. package/dist/main/config-lib.test.js +64 -0
  98. package/dist/main/config-lib.test.js.map +1 -0
  99. package/dist/main/config.d.ts +5 -0
  100. package/{src → dist}/main/config.js +16 -22
  101. package/dist/main/config.js.map +1 -0
  102. package/dist/prompt/function-calling-validate.d.ts +3 -0
  103. package/dist/prompt/function-calling-validate.js +27 -0
  104. package/dist/prompt/function-calling-validate.js.map +1 -0
  105. package/dist/prompt/function-calling.d.ts +5 -0
  106. package/{src → dist}/prompt/function-calling.js +25 -24
  107. package/dist/prompt/function-calling.js.map +1 -0
  108. package/dist/prompt/function-defs/ask-question.d.ts +31 -0
  109. package/dist/prompt/function-defs/ask-question.js +32 -0
  110. package/dist/prompt/function-defs/ask-question.js.map +1 -0
  111. package/dist/prompt/function-defs/codegen-summary.d.ts +63 -0
  112. package/dist/prompt/function-defs/codegen-summary.js +80 -0
  113. package/dist/prompt/function-defs/codegen-summary.js.map +1 -0
  114. package/dist/prompt/function-defs/create-directory.d.ts +21 -0
  115. package/dist/prompt/function-defs/create-directory.js +22 -0
  116. package/dist/prompt/function-defs/create-directory.js.map +1 -0
  117. package/dist/prompt/function-defs/create-file.d.ts +25 -0
  118. package/dist/prompt/function-defs/create-file.js +26 -0
  119. package/dist/prompt/function-defs/create-file.js.map +1 -0
  120. package/dist/prompt/function-defs/delete-file.d.ts +21 -0
  121. package/dist/prompt/function-defs/delete-file.js +22 -0
  122. package/dist/prompt/function-defs/delete-file.js.map +1 -0
  123. package/dist/prompt/function-defs/download-file.d.ts +25 -0
  124. package/dist/prompt/function-defs/download-file.js +26 -0
  125. package/dist/prompt/function-defs/download-file.js.map +1 -0
  126. package/dist/prompt/function-defs/explanation.d.ts +17 -0
  127. package/dist/prompt/function-defs/explanation.js +18 -0
  128. package/dist/prompt/function-defs/explanation.js.map +1 -0
  129. package/dist/prompt/function-defs/generate-image.d.ts +48 -0
  130. package/dist/prompt/function-defs/generate-image.js +49 -0
  131. package/dist/prompt/function-defs/generate-image.js.map +1 -0
  132. package/dist/prompt/function-defs/get-image-assets.d.ts +20 -0
  133. package/dist/prompt/function-defs/get-image-assets.js +21 -0
  134. package/dist/prompt/function-defs/get-image-assets.js.map +1 -0
  135. package/dist/prompt/function-defs/get-source-code.d.ts +20 -0
  136. package/dist/prompt/function-defs/get-source-code.js +21 -0
  137. package/dist/prompt/function-defs/get-source-code.js.map +1 -0
  138. package/dist/prompt/function-defs/imgly-remove-background.d.ts +25 -0
  139. package/dist/prompt/function-defs/imgly-remove-background.js +26 -0
  140. package/dist/prompt/function-defs/imgly-remove-background.js.map +1 -0
  141. package/dist/prompt/function-defs/move-file.d.ts +25 -0
  142. package/dist/prompt/function-defs/move-file.js +26 -0
  143. package/dist/prompt/function-defs/move-file.js.map +1 -0
  144. package/dist/prompt/function-defs/patch-file.d.ts +25 -0
  145. package/dist/prompt/function-defs/patch-file.js +39 -0
  146. package/dist/prompt/function-defs/patch-file.js.map +1 -0
  147. package/dist/prompt/function-defs/resize-image.d.ts +36 -0
  148. package/dist/prompt/function-defs/resize-image.js +37 -0
  149. package/dist/prompt/function-defs/resize-image.js.map +1 -0
  150. package/dist/prompt/function-defs/split-image.d.ts +57 -0
  151. package/dist/prompt/function-defs/split-image.js +46 -0
  152. package/dist/prompt/function-defs/split-image.js.map +1 -0
  153. package/dist/prompt/function-defs/update-file.d.ts +25 -0
  154. package/dist/prompt/function-defs/update-file.js +26 -0
  155. package/dist/prompt/function-defs/update-file.js.map +1 -0
  156. package/dist/prompt/limits.d.ts +3 -0
  157. package/dist/prompt/limits.js +19 -0
  158. package/dist/prompt/limits.js.map +1 -0
  159. package/dist/prompt/limits.test.d.ts +1 -0
  160. package/dist/prompt/limits.test.js +35 -0
  161. package/dist/prompt/limits.test.js.map +1 -0
  162. package/dist/prompt/prompt-codegen.d.ts +4 -0
  163. package/dist/prompt/prompt-codegen.js +81 -0
  164. package/dist/prompt/prompt-codegen.js.map +1 -0
  165. package/dist/prompt/prompt-codegen.test.d.ts +1 -0
  166. package/dist/prompt/prompt-codegen.test.js +94 -0
  167. package/dist/prompt/prompt-codegen.test.js.map +1 -0
  168. package/dist/prompt/prompt-consts.d.ts +1 -0
  169. package/{src → dist}/prompt/prompt-consts.js +1 -0
  170. package/dist/prompt/prompt-consts.js.map +1 -0
  171. package/dist/prompt/prompt-service-ask-question.test.d.ts +3 -0
  172. package/dist/prompt/prompt-service-ask-question.test.js +146 -0
  173. package/dist/prompt/prompt-service-ask-question.test.js.map +1 -0
  174. package/dist/prompt/prompt-service.d.ts +13 -0
  175. package/dist/prompt/prompt-service.js +278 -0
  176. package/dist/prompt/prompt-service.js.map +1 -0
  177. package/dist/prompt/prompt-service.test.d.ts +1 -0
  178. package/dist/prompt/prompt-service.test.js +511 -0
  179. package/dist/prompt/prompt-service.test.js.map +1 -0
  180. package/dist/prompt/systemprompt.d.ts +2 -0
  181. package/dist/prompt/systemprompt.js +43 -0
  182. package/dist/prompt/systemprompt.js.map +1 -0
  183. package/dist/prompt/systemprompt.test.d.ts +2 -0
  184. package/dist/prompt/systemprompt.test.js +47 -0
  185. package/dist/prompt/systemprompt.test.js.map +1 -0
  186. package/package.json +13 -4
  187. package/bin/genaicode.js +0 -5
  188. package/src/ai-service/anthropic.js +0 -126
  189. package/src/ai-service/chat-gpt.js +0 -126
  190. package/src/ai-service/common.js +0 -49
  191. package/src/ai-service/common.test.js +0 -107
  192. package/src/ai-service/dall-e.js +0 -50
  193. package/src/ai-service/vertex-ai-claude.js +0 -99
  194. package/src/ai-service/vertex-ai-imagen.js +0 -78
  195. package/src/ai-service/vertex-ai.js +0 -156
  196. package/src/cli/cli-options.js +0 -132
  197. package/src/cli/cli-options.test.js +0 -50
  198. package/src/cli/cli-params.js +0 -114
  199. package/src/cli/cli-params.test.js +0 -43
  200. package/src/cli/service-autodetect.js +0 -11
  201. package/src/cli/service-autodetect.test.js +0 -43
  202. package/src/cli/validate-cli-params.js +0 -137
  203. package/src/cli/validate-cli-params.test.js +0 -134
  204. package/src/files/file-utils.js +0 -7
  205. package/src/files/file-utils.test.js +0 -21
  206. package/src/files/find-files.js +0 -86
  207. package/src/files/read-files.js +0 -65
  208. package/src/files/read-files.test.js +0 -103
  209. package/src/files/temp-buffer.js +0 -13
  210. package/src/files/update-files.js +0 -205
  211. package/src/images/ensure-alpha.js +0 -5
  212. package/src/images/imgly-remove-background.js +0 -23
  213. package/src/images/resize-image.js +0 -23
  214. package/src/images/split-image.js +0 -26
  215. package/src/main/codegen.js +0 -120
  216. package/src/main/codegen.test.js +0 -335
  217. package/src/main/config-lib.js +0 -33
  218. package/src/main/config-lib.test.js +0 -80
  219. package/src/prompt/function-calling-validate.js +0 -25
  220. package/src/prompt/function-defs/ask-question.js +0 -33
  221. package/src/prompt/function-defs/codegen-summary.js +0 -87
  222. package/src/prompt/function-defs/create-directory.js +0 -21
  223. package/src/prompt/function-defs/create-file.js +0 -26
  224. package/src/prompt/function-defs/delete-file.js +0 -21
  225. package/src/prompt/function-defs/download-file.js +0 -25
  226. package/src/prompt/function-defs/explanation.js +0 -17
  227. package/src/prompt/function-defs/generate-image.js +0 -51
  228. package/src/prompt/function-defs/get-image-assets.js +0 -21
  229. package/src/prompt/function-defs/get-source-code.js +0 -21
  230. package/src/prompt/function-defs/imgly-remove-background.js +0 -25
  231. package/src/prompt/function-defs/move-file.js +0 -25
  232. package/src/prompt/function-defs/patch-file.js +0 -39
  233. package/src/prompt/function-defs/resize-image.js +0 -36
  234. package/src/prompt/function-defs/split-image.js +0 -45
  235. package/src/prompt/function-defs/update-file.js +0 -26
  236. package/src/prompt/limits.js +0 -23
  237. package/src/prompt/limits.test.js +0 -40
  238. package/src/prompt/prompt-codegen.js +0 -106
  239. package/src/prompt/prompt-codegen.test.js +0 -116
  240. package/src/prompt/prompt-service-ask-question.test.js +0 -163
  241. package/src/prompt/prompt-service.js +0 -335
  242. package/src/prompt/prompt-service.test.js +0 -602
  243. package/src/prompt/systemprompt.js +0 -39
  244. package/src/prompt/systemprompt.test.js +0 -64
@@ -1,137 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import globRegex from 'glob-regex';
4
- import { rcConfig } from '../main/config.js';
5
-
6
- // List of allowed CLI parameters
7
- const allowedParameters = [
8
- '--dry-run',
9
- '--consider-all-files',
10
- '--allow-file-create',
11
- '--allow-file-delete',
12
- '--allow-directory-create',
13
- '--allow-file-move',
14
- '--chat-gpt',
15
- '--vertex-ai',
16
- '--vertex-ai-claude',
17
- '--anthropic',
18
- '--explicit-prompt=',
19
- '--task-file=',
20
- '--dependency-tree',
21
- '--verbose-prompt',
22
- '--require-explanations',
23
- '--disable-context-optimization',
24
- '--gemini-block-none',
25
- '--disable-initial-lint',
26
- '--temperature=',
27
- '--vision',
28
- '--imagen=',
29
- '--cheap',
30
- '--ask-question',
31
- '--help',
32
- '--content-mask=',
33
- '--disable-cache',
34
- '--ignore-pattern=',
35
- ];
36
-
37
- /**
38
- * Validate CLI parameters according to those mentioned in README.md
39
- * Fail the process if not valid, or if an unknown parameter is passed
40
- * @throws {Error} If an invalid parameter is provided
41
- */
42
- export function validateCliParams() {
43
- const providedParameters = process.argv.slice(2);
44
-
45
- // Check if --help is present
46
- const helpRequested = providedParameters.includes('--help');
47
-
48
- if (helpRequested) {
49
- // If --help is present, no other parameters should be allowed
50
- if (providedParameters.length > 1) {
51
- console.error('The --help option cannot be used with other parameters.');
52
- process.exit(1);
53
- }
54
- return; // Exit the function early as no further validation is needed
55
- }
56
-
57
- providedParameters.forEach((param) => {
58
- if (!param.startsWith('--')) {
59
- console.error(`Invalid parameter: ${param}, all parameters must start with --`);
60
- process.exit(1);
61
- }
62
- if (!allowedParameters.some((p) => (p.endsWith('=') && param.startsWith(p)) || param === p)) {
63
- console.error(`Invalid parameter: ${param}, allowed parameters are: ${allowedParameters.join(', ')}`);
64
- process.exit(1);
65
- }
66
- });
67
-
68
- // Validate temperature parameter, it must be a number between 0.0 and 2.0
69
- const temperatureParam = providedParameters.find((param) => param.startsWith('--temperature='));
70
- if (temperatureParam) {
71
- const temperatureValue = parseFloat(temperatureParam.split('=')[1]);
72
- if (isNaN(temperatureValue) || temperatureValue < 0.0 || temperatureValue > 2.0) {
73
- console.error('Invalid temperature value. It must be a number between 0.0 and 2.0.');
74
- process.exit(1);
75
- }
76
- }
77
-
78
- // Validate --imagen parameter
79
- const imagenParam = providedParameters.find((param) => param.startsWith('--imagen='));
80
- if (imagenParam) {
81
- const imagenValue = imagenParam.split('=')[1];
82
- if (imagenValue !== 'vertex-ai' && imagenValue !== 'dall-e') {
83
- throw new Error('Invalid --imagen value. It must be either "vertex-ai" or "dall-e".');
84
- }
85
- }
86
-
87
- if (providedParameters.includes('--vision') && providedParameters.includes('--vertex-ai')) {
88
- throw new Error('--vision and --vertex-ai are currently not supported together.');
89
- }
90
-
91
- // Validate content mask parameter
92
- const contentMaskParam = providedParameters.find((param) => param.startsWith('--content-mask='));
93
- if (contentMaskParam) {
94
- const contentMaskValue = contentMaskParam.split('=')[1];
95
- const fullPath = path.join(rcConfig.rootDir, contentMaskValue);
96
- if (!fs.existsSync(fullPath) || !fs.statSync(fullPath).isDirectory()) {
97
- throw new Error(
98
- `Invalid --content-mask value. The path "${contentMaskValue}" does not exist or is not a directory within the project.`,
99
- );
100
- }
101
- }
102
-
103
- // Validate ignore pattern parameter
104
- const ignorePatternParams = providedParameters.filter((param) => param.startsWith('--ignore-pattern='));
105
- if (ignorePatternParams.length > 0) {
106
- for (const ignorePatternParam of ignorePatternParams) {
107
- const ignorePatternValue = ignorePatternParam.split('=')[1];
108
- if (!ignorePatternValue) {
109
- throw new Error('Invalid --ignore-pattern value. The pattern cannot be empty.');
110
- }
111
- try {
112
- globRegex(ignorePatternValue);
113
- } catch (e) {
114
- throw new Error(`Invalid --ignore-pattern value. The pattern "${ignorePatternValue}" is not valid.`, e);
115
- }
116
- }
117
- }
118
- }
119
-
120
- /**
121
- * Get the value of a CLI parameter
122
- * @param {string} paramName - The name of the parameter to get the value for
123
- * @returns {string|null} The value of the parameter, or null if not found
124
- */
125
- export function getCliParamValue(paramName) {
126
- const param = process.argv.find((arg) => arg.startsWith(`${paramName}=`));
127
- return param ? param.split('=')[1] : null;
128
- }
129
-
130
- /**
131
- * Check if a CLI parameter is present
132
- * @param {string} paramName - The name of the parameter to check
133
- * @returns {boolean} True if the parameter is present, false otherwise
134
- */
135
- export function hasCliParam(paramName) {
136
- return process.argv.includes(paramName) || !!getCliParamValue(paramName);
137
- }
@@ -1,134 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
- import { validateCliParams, getCliParamValue, hasCliParam } from './validate-cli-params.js';
3
-
4
- describe('validateCliParams', () => {
5
- const originalArgv = process.argv;
6
-
7
- beforeEach(() => {
8
- process.argv = ['node', 'script.js'];
9
- });
10
-
11
- afterEach(() => {
12
- process.argv = originalArgv;
13
- });
14
-
15
- it('should not throw for valid parameters', () => {
16
- process.argv.push('--dry-run', '--consider-all-files');
17
- expect(() => validateCliParams()).not.toThrow();
18
- });
19
-
20
- it('should throw for invalid parameters', () => {
21
- process.argv.push('--invalid-param');
22
- expect(() => validateCliParams()).toThrow();
23
- });
24
-
25
- it('should throw for parameters without --', () => {
26
- process.argv.push('invalid-param');
27
- expect(() => validateCliParams()).toThrow();
28
- });
29
-
30
- it('should not throw for valid --temperature parameter', () => {
31
- process.argv.push('--temperature=0.5');
32
- expect(() => validateCliParams()).not.toThrow();
33
- });
34
-
35
- it('should throw for invalid --temperature parameter', () => {
36
- process.argv.push('--temperature=invalid');
37
- expect(() => validateCliParams()).toThrow();
38
- });
39
-
40
- it('should throw an error when both vision and vertexAi flags are true', () => {
41
- process.argv.push('--vision');
42
- process.argv.push('--vertex-ai');
43
-
44
- expect(() => validateCliParams()).toThrow('--vision and --vertex-ai are currently not supported together.');
45
- });
46
-
47
- // New tests for --imagen parameter
48
- it('should not throw for valid --imagen parameter with vertex-ai', () => {
49
- process.argv.push('--imagen=vertex-ai');
50
- expect(() => validateCliParams()).not.toThrow();
51
- });
52
-
53
- it('should not throw for valid --imagen parameter with dall-e', () => {
54
- process.argv.push('--imagen=dall-e');
55
- expect(() => validateCliParams()).not.toThrow();
56
- });
57
-
58
- it('should throw for invalid --imagen parameter value', () => {
59
- process.argv.push('--imagen=invalid-service');
60
- expect(() => validateCliParams()).toThrow('Invalid --imagen value. It must be either "vertex-ai" or "dall-e".');
61
- });
62
-
63
- it('should throw for --imagen parameter without value', () => {
64
- process.argv.push('--imagen=');
65
- expect(() => validateCliParams()).toThrow('Invalid --imagen value. It must be either "vertex-ai" or "dall-e".');
66
- });
67
- });
68
-
69
- describe('getCliParamValue', () => {
70
- const originalArgv = process.argv;
71
-
72
- beforeEach(() => {
73
- process.argv = ['node', 'script.js'];
74
- });
75
-
76
- afterEach(() => {
77
- process.argv = originalArgv;
78
- });
79
-
80
- it('should return the value for a parameter with a value', () => {
81
- process.argv.push('--explicit-prompt=Test prompt');
82
- expect(getCliParamValue('--explicit-prompt')).toBe('Test prompt');
83
- });
84
-
85
- it('should return null for a parameter without a value', () => {
86
- process.argv.push('--dry-run');
87
- expect(getCliParamValue('--dry-run')).toBeNull();
88
- });
89
-
90
- it('should return null for a non-existent parameter', () => {
91
- expect(getCliParamValue('--non-existent')).toBeNull();
92
- });
93
-
94
- it('should return the value for --temperature parameter', () => {
95
- process.argv.push('--temperature=0.5');
96
- expect(getCliParamValue('--temperature')).toBe('0.5');
97
- });
98
-
99
- it('should return the value for --imagen parameter', () => {
100
- process.argv.push('--imagen=vertex-ai');
101
- expect(getCliParamValue('--imagen')).toBe('vertex-ai');
102
- });
103
- });
104
-
105
- describe('hasCliParam', () => {
106
- const originalArgv = process.argv;
107
-
108
- beforeEach(() => {
109
- process.argv = ['node', 'script.js'];
110
- });
111
-
112
- afterEach(() => {
113
- process.argv = originalArgv;
114
- });
115
-
116
- it('should return true for an existing parameter', () => {
117
- process.argv.push('--dry-run');
118
- expect(hasCliParam('--dry-run')).toBe(true);
119
- });
120
-
121
- it('should return false for a non-existent parameter', () => {
122
- expect(hasCliParam('--non-existent')).toBe(false);
123
- });
124
-
125
- it('should return true for --temperature parameter', () => {
126
- process.argv.push('--temperature=0.5');
127
- expect(hasCliParam('--temperature')).toBe(true);
128
- });
129
-
130
- it('should return true for --imagen parameter', () => {
131
- process.argv.push('--imagen=dall-e');
132
- expect(hasCliParam('--imagen')).toBe(true);
133
- });
134
- });
@@ -1,7 +0,0 @@
1
- import path from 'path';
2
-
3
- /** Check if directory is ancestor of given directory */
4
- export function isAncestorDirectory(parent, dir) {
5
- const relative = path.relative(parent, dir);
6
- return parent === dir || (relative && !relative.startsWith('..') && !path.isAbsolute(relative));
7
- }
@@ -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
- }