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,25 +0,0 @@
1
- /**
2
- * Function definition for downloadFile
3
- */
4
- export const downloadFile = {
5
- name: 'downloadFile',
6
- description: 'Download file from url, and save to file',
7
- parameters: {
8
- type: 'object',
9
- properties: {
10
- filePath: {
11
- type: 'string',
12
- description: 'The file path to save the downloaded file.',
13
- },
14
- downloadUrl: {
15
- type: 'string',
16
- description: 'The url of the file that will be used for downloading.',
17
- },
18
- explanation: {
19
- type: 'string',
20
- description: 'The reasoning behind downloading this image.',
21
- },
22
- },
23
- required: ['filePath', 'downloadUrl'],
24
- },
25
- };
@@ -1,17 +0,0 @@
1
- /**
2
- * Function definition for explanation
3
- */
4
- export const explanation = {
5
- name: 'explanation',
6
- description: 'Explain the reasoning behind the suggested code changes or reasoning for lack of code changes',
7
- parameters: {
8
- type: 'object',
9
- properties: {
10
- text: {
11
- type: 'string',
12
- description: 'The explanation text',
13
- },
14
- },
15
- required: ['text'],
16
- },
17
- };
@@ -1,51 +0,0 @@
1
- /**
2
- * Function definition for generateImage
3
- */
4
- export const generateImage = {
5
- name: 'generateImage',
6
- description: 'Generate an image using AI service and save it as a file.',
7
- parameters: {
8
- type: 'object',
9
- properties: {
10
- prompt: {
11
- type: 'string',
12
- description:
13
- 'The prompt that will be used to generate the image. This prompt must be detailed, it will be used by image generation model.',
14
- },
15
- filePath: {
16
- type: 'string',
17
- description: 'The file path to save the generated image.',
18
- },
19
- contextImagePath: {
20
- type: 'string',
21
- description:
22
- 'Path to a image file that will be used as a context for image generation. It is useful if there is a need to edit an image with genAI.',
23
- },
24
- size: {
25
- type: 'object',
26
- properties: {
27
- width: {
28
- type: 'number',
29
- description: 'width of the image',
30
- },
31
- height: {
32
- type: 'number',
33
- description: 'height of the image',
34
- },
35
- },
36
- required: ['width', 'height'],
37
- description: 'The size of the image to generate.',
38
- },
39
- cheap: {
40
- type: 'boolean',
41
- description:
42
- 'true value means that the prompt will be executed with cheaper model, which work faster, but provides lower quality results, so please use it only in situation when lower quality results are acceptable for the prompt.',
43
- },
44
- explanation: {
45
- type: 'string',
46
- description: 'The explanation of the reasoning behind generating this image',
47
- },
48
- },
49
- required: ['prompt', 'filePath', 'size', 'cheap'],
50
- },
51
- };
@@ -1,21 +0,0 @@
1
- /**
2
- * Function definition for getImageAssets
3
- */
4
- export const getImageAssets = {
5
- name: 'getImageAssets',
6
- description:
7
- 'This function returns a map of application image assets. This map contains absolute file path, and basic metadata information. It does not contain contents. Contents must be requested using dedicated tool.',
8
- parameters: {
9
- type: 'object',
10
- properties: {
11
- filePaths: {
12
- type: 'array',
13
- description: 'An array of absolute paths of files that should be used to provided context.',
14
- items: {
15
- type: 'string',
16
- },
17
- },
18
- },
19
- required: [],
20
- },
21
- };
@@ -1,21 +0,0 @@
1
- /**
2
- * Function definition for getSourceCode
3
- */
4
- export const getSourceCode = {
5
- name: 'getSourceCode',
6
- description:
7
- 'This function returns source code of the application in Map format, where absolute file path is the key, and the value is an object, where one of the properties may be the content of the file. Some keys may not provide content. This function can be called only once during the conversation, and only if suggested by the user.',
8
- parameters: {
9
- type: 'object',
10
- properties: {
11
- filePaths: {
12
- type: 'array',
13
- description: 'An array of absolute paths of files that should be used to provided context.',
14
- items: {
15
- type: 'string',
16
- },
17
- },
18
- },
19
- required: [],
20
- },
21
- };
@@ -1,25 +0,0 @@
1
- /**
2
- * Function definition for imglyRemoveBackground
3
- */
4
- export const imglyRemoveBackground = {
5
- name: 'imglyRemoveBackground',
6
- description: 'Removes background from an image using @imgly/background-removal-node',
7
- parameters: {
8
- type: 'object',
9
- properties: {
10
- inputFilePath: {
11
- type: 'string',
12
- description: 'The file path of the input image.',
13
- },
14
- outputFilePath: {
15
- type: 'string',
16
- description: 'The file path to save the output image with removed background.',
17
- },
18
- explanation: {
19
- type: 'string',
20
- description: 'The explanation of the reasoning behind removing the background from this image',
21
- },
22
- },
23
- required: ['inputFilePath', 'outputFilePath'],
24
- },
25
- };
@@ -1,25 +0,0 @@
1
- /**
2
- * Function definition for moveFile
3
- */
4
- export const moveFile = {
5
- name: 'moveFile',
6
- description: 'Move a file from one location to another',
7
- parameters: {
8
- type: 'object',
9
- properties: {
10
- source: {
11
- type: 'string',
12
- description: 'The current file path.',
13
- },
14
- destination: {
15
- type: 'string',
16
- description: 'The new file path.',
17
- },
18
- explanation: {
19
- type: 'string',
20
- description: 'The explanation of the reasoning behind moving this file',
21
- },
22
- },
23
- required: ['source', 'destination'],
24
- },
25
- };
@@ -1,39 +0,0 @@
1
- /**
2
- * Function definition for patchFile
3
- */
4
- export const patchFile = {
5
- name: 'patchFile',
6
- description:
7
- 'Partially update a file content. The file must already exists in the application source code. The function should be called only if there is a need to actually change something.',
8
- parameters: {
9
- type: 'object',
10
- properties: {
11
- filePath: {
12
- type: 'string',
13
- description: 'The file path to patch.',
14
- },
15
- patch: {
16
- type: 'string',
17
- description: `Modification to the file expressed in patch format. Example patch:
18
-
19
- \`\`\`
20
- Index: filename.js
21
- ===================================================================
22
- --- filename.js
23
- +++ filename.js
24
- @@ -1,2 +1,3 @@
25
- line1
26
- +line3
27
- line2
28
- \
29
- \`\`\`
30
- `,
31
- },
32
- explanation: {
33
- type: 'string',
34
- description: 'The explanation of the reasoning behind the suggested code changes for this file',
35
- },
36
- },
37
- required: ['filePath', 'patch'],
38
- },
39
- };
@@ -1,36 +0,0 @@
1
- /**
2
- * Function definition for resizeImage
3
- */
4
- export const resizeImage = {
5
- name: 'resizeImage',
6
- description: 'Resize image to the desired size',
7
- parameters: {
8
- type: 'object',
9
- properties: {
10
- filePath: {
11
- type: 'string',
12
- description: 'The file path of the image.',
13
- },
14
- size: {
15
- type: 'object',
16
- properties: {
17
- width: {
18
- type: 'number',
19
- description: 'width of the image',
20
- },
21
- height: {
22
- type: 'number',
23
- description: 'height of the image',
24
- },
25
- },
26
- required: ['width', 'height'],
27
- description: 'The size of the image to generate.',
28
- },
29
- explanation: {
30
- type: 'string',
31
- description: 'The explanation of the reasoning behind removing the background from this image',
32
- },
33
- },
34
- required: ['filePath', 'size'],
35
- },
36
- };
@@ -1,45 +0,0 @@
1
- /**
2
- * Function definition for splitImage
3
- */
4
- export const splitImage = {
5
- name: 'splitImage',
6
- description: 'Split an image into multiple parts and save them as separate files.',
7
- parameters: {
8
- type: 'object',
9
- properties: {
10
- inputFilePath: {
11
- type: 'string',
12
- description: 'The file path of the input image to be split.',
13
- },
14
- parts: {
15
- type: 'array',
16
- items: {
17
- type: 'object',
18
- properties: {
19
- rect: {
20
- type: 'object',
21
- properties: {
22
- x: { type: 'number', description: 'The x-coordinate of the top-left corner of the rectangle.' },
23
- y: { type: 'number', description: 'The y-coordinate of the top-left corner of the rectangle.' },
24
- width: { type: 'number', description: 'The width of the rectangle.' },
25
- height: { type: 'number', description: 'The height of the rectangle.' },
26
- },
27
- required: ['x', 'y', 'width', 'height'],
28
- },
29
- outputFilePath: {
30
- type: 'string',
31
- description: 'The file path to save the extracted part of the image.',
32
- },
33
- },
34
- required: ['rect', 'outputFilePath'],
35
- },
36
- description: 'An array of parts to extract from the image, each with a rectangle and output file path.',
37
- },
38
- explanation: {
39
- type: 'string',
40
- description: 'The explanation of the reasoning behind splitting this image',
41
- },
42
- },
43
- required: ['inputFilePath', 'parts'],
44
- },
45
- };
@@ -1,26 +0,0 @@
1
- /**
2
- * Function definition for updateFile
3
- */
4
- export const updateFile = {
5
- name: 'updateFile',
6
- description:
7
- 'Update a file with new content. The file must already exists in the application source code. The function should be called only if there is a need to actually change something.',
8
- parameters: {
9
- type: 'object',
10
- properties: {
11
- filePath: {
12
- type: 'string',
13
- description: 'The file path to update.',
14
- },
15
- newContent: {
16
- type: 'string',
17
- description: 'The content to update the file with. Must not be empty.',
18
- },
19
- explanation: {
20
- type: 'string',
21
- description: 'The explanation of the reasoning behind the suggested code changes for this file',
22
- },
23
- },
24
- required: ['filePath', 'newContent'],
25
- },
26
- };
@@ -1,23 +0,0 @@
1
- import assert from 'node:assert';
2
-
3
- const SYSTEM_PROMPT_LIMIT = 200;
4
- const CODEGEN_PROMPT_LIMIT = 500;
5
- const SOURCE_CODE_LIMIT = 20000;
6
-
7
- function verifyPromptLimit(promptType, prompt, limit) {
8
- const tokenCount = prompt.split(/\s+/).length;
9
- console.log(`${promptType} prompt token count: ${tokenCount}`);
10
- assert(tokenCount <= limit, `Token limit exceeded: ${tokenCount} > ${limit}`);
11
- }
12
-
13
- export function verifySystemPromptLimit(systemPrompt) {
14
- verifyPromptLimit('system', systemPrompt, SYSTEM_PROMPT_LIMIT);
15
- }
16
-
17
- export function verifyCodegenPromptLimit(codeGenPrompt) {
18
- verifyPromptLimit('codegen', codeGenPrompt, CODEGEN_PROMPT_LIMIT);
19
- }
20
-
21
- export function verifySourceCodeLimit(sourceCode) {
22
- verifyPromptLimit('sourceCode', sourceCode, SOURCE_CODE_LIMIT);
23
- }
@@ -1,40 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { verifySystemPromptLimit, verifyCodegenPromptLimit, verifySourceCodeLimit } from './limits.js';
3
-
4
- describe('Prompt Limits', () => {
5
- describe('verifySystemPromptLimit', () => {
6
- it('should not throw for a prompt within the limit', () => {
7
- const validPrompt = 'A '.repeat(200 - 1);
8
- expect(() => verifySystemPromptLimit(validPrompt)).not.toThrow();
9
- });
10
-
11
- it('should throw for a prompt exceeding the limit', () => {
12
- const invalidPrompt = 'A '.repeat(201);
13
- expect(() => verifySystemPromptLimit(invalidPrompt)).toThrow('Token limit exceeded: 202 > 200');
14
- });
15
- });
16
-
17
- describe('verifyCodegenPromptLimit', () => {
18
- it('should not throw for a prompt within the limit', () => {
19
- const validPrompt = 'B '.repeat(200 - 1);
20
- expect(() => verifyCodegenPromptLimit(validPrompt)).not.toThrow();
21
- });
22
-
23
- it('should throw for a prompt exceeding the limit', () => {
24
- const invalidPrompt = 'B '.repeat(501);
25
- expect(() => verifyCodegenPromptLimit(invalidPrompt)).toThrow('Token limit exceeded: 502 > 500');
26
- });
27
- });
28
-
29
- describe('verifySourceCodeLimit', () => {
30
- it('should not throw for source code within the limit', () => {
31
- const validSourceCode = 'C '.repeat(20000 - 1);
32
- expect(() => verifySourceCodeLimit(validSourceCode)).not.toThrow();
33
- });
34
-
35
- it('should throw for source code exceeding the limit', () => {
36
- const invalidSourceCode = 'C '.repeat(20001);
37
- expect(() => verifySourceCodeLimit(invalidSourceCode)).toThrow('Token limit exceeded: 20002 > 20000');
38
- });
39
- });
40
- });
@@ -1,106 +0,0 @@
1
- import assert from 'node:assert';
2
- import { getSourceCode } from '../files/read-files.js';
3
- import { CODEGEN_TRIGGER } from './prompt-consts.js';
4
- import {
5
- considerAllFiles,
6
- allowFileCreate,
7
- allowFileDelete,
8
- allowDirectoryCreate,
9
- allowFileMove,
10
- explicitPrompt,
11
- dependencyTree,
12
- verbosePrompt,
13
- vision,
14
- imagen,
15
- } from '../cli/cli-params.js';
16
- import { getDependencyList } from '../files/find-files.js';
17
- import { verifyCodegenPromptLimit } from './limits.js';
18
-
19
- /** Get codegen prompt */
20
- export function getCodeGenPrompt() {
21
- let codeGenFiles;
22
- if (considerAllFiles) {
23
- codeGenFiles = Object.keys(getSourceCode());
24
- } else {
25
- codeGenFiles = Object.entries(getSourceCode())
26
- .filter(([, { content }]) => content?.match(new RegExp("([^'^`]+)" + CODEGEN_TRIGGER)))
27
- .map(([path]) => path);
28
- }
29
-
30
- // Add logic to consider dependency tree
31
- if (dependencyTree) {
32
- assert(codeGenFiles.length > 0, `You must use ${CODEGEN_TRIGGER} together with --dependency-tree`);
33
-
34
- const dependencyTreeFiles = new Set();
35
- codeGenFiles
36
- .map(getDependencyList)
37
- .flat()
38
- .forEach((key) => dependencyTreeFiles.add(key));
39
- codeGenFiles = Array.from(dependencyTreeFiles);
40
- }
41
-
42
- const codeGenPrompt =
43
- (explicitPrompt ? explicitPrompt + '\n\n' : '') +
44
- `${
45
- considerAllFiles
46
- ? codeGenFiles.length > 0
47
- ? `I have marked some files with the ${CODEGEN_TRIGGER} fragments:\n${codeGenFiles.join('\n')}`
48
- : `No files are marked with ${CODEGEN_TRIGGER} fragment, so you can consider doing changes in any file.`
49
- : `Generate updates only for the following files:\n${codeGenFiles.join('\n')}`
50
- }
51
-
52
- ${
53
- considerAllFiles
54
- ? 'You are allowed to modify all files in the application regardless if they contain codegen fragments or not.'
55
- : 'Do not modify files which do not contain the fragments.'
56
- }
57
- ${allowFileCreate ? 'You are allowed to create new files.' : 'Do not create new files.'}
58
- ${
59
- allowFileDelete
60
- ? 'You are allowed to delete files, in such case add empty string as content.'
61
- : 'Do not delete files.'
62
- }
63
- ${allowDirectoryCreate ? 'You are allowed to create new directories.' : 'Do not create new directories.'}
64
- ${allowFileMove ? 'You are allowed to move files.' : 'Do not move files.'}
65
- ${vision ? 'You are allowed to analyze image assets.' : 'Do not analyze image assets.'}
66
- ${imagen ? 'You are allowed to generate images.' : 'You are not allowed to generate images.'}
67
- `;
68
-
69
- if (verbosePrompt) {
70
- console.log('Code gen prompt:');
71
- console.log(codeGenPrompt);
72
- }
73
-
74
- verifyCodegenPromptLimit(codeGenPrompt);
75
-
76
- return codeGenPrompt;
77
- }
78
-
79
- /** Get lint fix prompt */
80
- export function getLintFixPrompt(command, stdout, stderr) {
81
- const lintFixPrompt = `The following lint errors were encountered after the initial code generation:
82
-
83
- Lint command: ${command}
84
- Lint command stdout:
85
-
86
- \`\`\`
87
- ${stdout}
88
- \`\`\`
89
-
90
- Lint command stderr:
91
-
92
- \`\`\`
93
- ${stderr}
94
- \`\`\`
95
-
96
- Please suggest changes to fix these lint errors.`;
97
-
98
- if (verbosePrompt) {
99
- console.log('Lint fix prompt:');
100
- console.log(lintFixPrompt);
101
- }
102
-
103
- verifyCodegenPromptLimit(lintFixPrompt);
104
-
105
- return lintFixPrompt;
106
- }
@@ -1,116 +0,0 @@
1
- /*eslint-disable no-import-assign*/
2
-
3
- import { describe, it, expect, vi, beforeEach } from 'vitest';
4
- import { getCodeGenPrompt, getLintFixPrompt } from './prompt-codegen.js';
5
- import * as findFiles from '../files/find-files.js';
6
- import * as cliParams from '../cli/cli-params.js';
7
- import * as limits from './limits.js';
8
- import '../files/read-files.js';
9
-
10
- vi.mock('../files/find-files.js', () => ({
11
- rcConfig: {},
12
- getSourceFiles: vi.fn(),
13
- }));
14
- vi.mock('../files/read-files.js', () => ({
15
- getSourceCode: () => ({}),
16
- }));
17
- vi.mock('../cli/cli-params.js', () => ({
18
- requireExplanations: false,
19
- considerAllFiles: false,
20
- dependencyTree: false,
21
- explicitPrompt: false,
22
- allowFileCreate: false,
23
- allowFileDelete: false,
24
- allowDirectoryCreate: false,
25
- allowFileMove: false,
26
- verbosePrompt: false,
27
- imagen: false,
28
- vision: false,
29
- }));
30
- vi.mock('./limits.js');
31
-
32
- describe('getCodeGenPrompt', () => {
33
- beforeEach(() => {
34
- vi.resetAllMocks();
35
- });
36
-
37
- it('should generate prompt for all files when considerAllFiles is true', () => {
38
- vi.spyOn(findFiles, 'getSourceFiles').mockReturnValue(['file1.js', 'file2.js']);
39
- cliParams.considerAllFiles = true;
40
- cliParams.explicitPrompt = null;
41
- cliParams.allowFileCreate = false;
42
- cliParams.allowFileDelete = false;
43
- cliParams.allowDirectoryCreate = false;
44
- cliParams.allowFileMove = false;
45
- vi.spyOn(limits, 'verifyCodegenPromptLimit').mockImplementation(() => {});
46
-
47
- const prompt = getCodeGenPrompt();
48
-
49
- expect(prompt).toContain('You are allowed to modify all files in the application');
50
- expect(prompt).toContain('Do not create new files.');
51
- expect(prompt).toContain('Do not delete files.');
52
- expect(prompt).toContain('Do not create new directories.');
53
- expect(prompt).toContain('Do not move files.');
54
- });
55
-
56
- // Add more test cases for getCodeGenPrompt as needed
57
- });
58
-
59
- describe('getLintFixPrompt', () => {
60
- beforeEach(() => {
61
- cliParams.verbosePrompt = false;
62
- vi.spyOn(limits, 'verifyCodegenPromptLimit').mockImplementation(() => {});
63
- });
64
-
65
- it('should generate a lint fix prompt with provided command, stdout, and stderr', () => {
66
- const command = 'eslint --fix';
67
- const stdout = 'Fixed 2 errors';
68
- const stderr = '';
69
-
70
- const prompt = getLintFixPrompt(command, stdout, stderr);
71
-
72
- expect(prompt).toContain('The following lint errors were encountered after the initial code generation:');
73
- expect(prompt).toContain(`Lint command: ${command}`);
74
- expect(prompt).toContain('Lint command stdout:');
75
- expect(prompt).toContain(stdout);
76
- expect(prompt).toContain('Lint command stderr:');
77
- expect(prompt).toContain('Please suggest changes to fix these lint errors.');
78
- });
79
-
80
- it('should include stderr in the prompt when provided', () => {
81
- const command = 'eslint --fix';
82
- const stdout = '';
83
- const stderr = 'Error: Unable to resolve path';
84
-
85
- const prompt = getLintFixPrompt(command, stdout, stderr);
86
-
87
- expect(prompt).toContain('Lint command stderr:');
88
- expect(prompt).toContain(stderr);
89
- });
90
-
91
- it('should call verifyCodegenPromptLimit with the generated prompt', () => {
92
- const command = 'eslint --fix';
93
- const stdout = 'Fixed 1 error';
94
- const stderr = '';
95
-
96
- getLintFixPrompt(command, stdout, stderr);
97
-
98
- expect(limits.verifyCodegenPromptLimit).toHaveBeenCalledWith(expect.any(String));
99
- });
100
-
101
- it('should log the prompt when verbosePrompt is true', () => {
102
- cliParams.verbosePrompt = true;
103
- const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
104
-
105
- const command = 'eslint --fix';
106
- const stdout = 'Fixed 1 error';
107
- const stderr = '';
108
-
109
- getLintFixPrompt(command, stdout, stderr);
110
-
111
- expect(consoleSpy).toHaveBeenCalledWith('Lint fix prompt:');
112
- expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('The following lint errors were encountered'));
113
-
114
- consoleSpy.mockRestore();
115
- });
116
- });