genaicode 0.6.1 → 0.8.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 (261) hide show
  1. package/README.md +0 -2
  2. package/dist/ai-service/ai-studio.js +7 -1
  3. package/dist/ai-service/ai-studio.js.map +1 -1
  4. package/dist/ai-service/anthropic.js +49 -19
  5. package/dist/ai-service/anthropic.js.map +1 -1
  6. package/dist/ai-service/chat-gpt.js +28 -11
  7. package/dist/ai-service/chat-gpt.js.map +1 -1
  8. package/dist/ai-service/common.d.ts +5 -4
  9. package/dist/ai-service/common.js +3 -4
  10. package/dist/ai-service/common.js.map +1 -1
  11. package/dist/ai-service/common.test.js +1 -1
  12. package/dist/ai-service/vertex-ai-claude.js +1 -1
  13. package/dist/ai-service/vertex-ai-claude.js.map +1 -1
  14. package/dist/ai-service/vertex-ai.js +7 -1
  15. package/dist/ai-service/vertex-ai.js.map +1 -1
  16. package/dist/cli/cli-options.js +0 -12
  17. package/dist/cli/cli-options.js.map +1 -1
  18. package/dist/cli/cli-params.d.ts +1 -4
  19. package/dist/cli/cli-params.js +1 -10
  20. package/dist/cli/cli-params.js.map +1 -1
  21. package/dist/cli/validate-cli-params.js +1 -7
  22. package/dist/cli/validate-cli-params.js.map +1 -1
  23. package/dist/cli/validate-cli-params.test.js +1 -1
  24. package/dist/cli/validate-cli-params.test.js.map +1 -1
  25. package/dist/eval/codegen-summary.test.d.ts +1 -0
  26. package/dist/eval/codegen-summary.test.js +93 -0
  27. package/dist/eval/codegen-summary.test.js.map +1 -0
  28. package/dist/eval/current-prompt-plugin.d.ts +3 -0
  29. package/dist/eval/current-prompt-plugin.js +10 -0
  30. package/dist/eval/current-prompt-plugin.js.map +1 -0
  31. package/dist/eval/data/current-prompt.d.ts +34 -0
  32. package/dist/eval/data/current-prompt.js +59 -0
  33. package/dist/eval/data/current-prompt.js.map +1 -0
  34. package/dist/eval/data/prompt-assistant-image.d.ts +49 -0
  35. package/dist/eval/data/prompt-assistant-image.js +67 -0
  36. package/dist/eval/data/prompt-assistant-image.js.map +1 -0
  37. package/dist/eval/data/prompt3.d.ts +34 -0
  38. package/dist/eval/data/prompt3.js +71 -0
  39. package/dist/eval/data/prompt3.js.map +1 -0
  40. package/dist/eval/prompt-debug.test.d.ts +1 -0
  41. package/dist/eval/prompt-debug.test.js +76 -0
  42. package/dist/eval/prompt-debug.test.js.map +1 -0
  43. package/dist/eval/prompt2.d.ts +34 -0
  44. package/dist/eval/prompt2.js +125 -0
  45. package/dist/eval/prompt2.js.map +1 -0
  46. package/dist/files/read-files.d.ts +29 -6
  47. package/dist/files/read-files.js +31 -10
  48. package/dist/files/read-files.js.map +1 -1
  49. package/dist/files/read-files.test.js +15 -9
  50. package/dist/files/read-files.test.js.map +1 -1
  51. package/dist/files/source-code-tree.d.ts +17 -0
  52. package/dist/files/source-code-tree.js +70 -0
  53. package/dist/files/source-code-tree.js.map +1 -0
  54. package/dist/main/codegen-types.d.ts +8 -5
  55. package/dist/main/codegen.ai-services.test.d.ts +3 -0
  56. package/dist/main/codegen.ai-services.test.js +198 -0
  57. package/dist/main/codegen.ai-services.test.js.map +1 -0
  58. package/dist/main/codegen.cli-options.test.d.ts +3 -0
  59. package/dist/main/codegen.cli-options.test.js +171 -0
  60. package/dist/main/codegen.cli-options.test.js.map +1 -0
  61. package/dist/main/codegen.image-generation.test.d.ts +3 -0
  62. package/dist/main/codegen.image-generation.test.js +187 -0
  63. package/dist/main/codegen.image-generation.test.js.map +1 -0
  64. package/dist/main/codegen.js +2 -5
  65. package/dist/main/codegen.js.map +1 -1
  66. package/dist/main/codegen.test-utils.d.ts +81 -0
  67. package/dist/main/codegen.test-utils.js +88 -0
  68. package/dist/main/codegen.test-utils.js.map +1 -0
  69. package/dist/main/codegen.test.js +47 -28
  70. package/dist/main/codegen.test.js.map +1 -1
  71. package/dist/main/common/content-bus-types.d.ts +6 -0
  72. package/dist/main/common/content-bus.d.ts +2 -2
  73. package/dist/main/common/content-bus.js +3 -1
  74. package/dist/main/common/content-bus.js.map +1 -1
  75. package/dist/main/common/user-actions.d.ts +8 -2
  76. package/dist/main/common/user-actions.js.map +1 -1
  77. package/dist/main/config-lib.js +20 -2
  78. package/dist/main/config-lib.js.map +1 -1
  79. package/dist/main/config.js +4 -28
  80. package/dist/main/config.js.map +1 -1
  81. package/dist/main/interactive/codegen-interactive.js +0 -4
  82. package/dist/main/interactive/codegen-interactive.js.map +1 -1
  83. package/dist/main/interactive/codegen-interactive.test.js +1 -7
  84. package/dist/main/interactive/codegen-interactive.test.js.map +1 -1
  85. package/dist/main/interactive/common.d.ts +1 -1
  86. package/dist/main/interactive/common.js +0 -2
  87. package/dist/main/interactive/common.js.map +1 -1
  88. package/dist/main/interactive/configure.js +0 -2
  89. package/dist/main/interactive/configure.js.map +1 -1
  90. package/dist/main/interactive/help.js +0 -2
  91. package/dist/main/interactive/help.js.map +1 -1
  92. package/dist/main/interactive/task-file.js +1 -1
  93. package/dist/main/interactive/task-file.js.map +1 -1
  94. package/dist/main/interactive/text-prompt.js +1 -1
  95. package/dist/main/interactive/text-prompt.js.map +1 -1
  96. package/dist/main/interactive/user-action-handlers.js +4 -2
  97. package/dist/main/interactive/user-action-handlers.js.map +1 -1
  98. package/dist/main/plugin-loader.d.ts +7 -1
  99. package/dist/main/plugin-loader.js +61 -0
  100. package/dist/main/plugin-loader.js.map +1 -1
  101. package/dist/main/ui/backend/api.js +9 -3
  102. package/dist/main/ui/backend/api.js.map +1 -1
  103. package/dist/main/ui/backend/service.d.ts +2 -1
  104. package/dist/main/ui/backend/service.js +6 -3
  105. package/dist/main/ui/backend/service.js.map +1 -1
  106. package/dist/main/ui/frontend/assets/index-QOcNx5ac.js +812 -0
  107. package/dist/main/ui/frontend/index.html +1 -1
  108. package/dist/main/ui/user-action-handlers.js +1 -1
  109. package/dist/main/ui/user-action-handlers.js.map +1 -1
  110. package/dist/project-profiles/detection.d.ts +40 -0
  111. package/dist/project-profiles/detection.js +131 -0
  112. package/dist/project-profiles/detection.js.map +1 -0
  113. package/dist/project-profiles/index.d.ts +35 -0
  114. package/dist/project-profiles/index.js +72 -0
  115. package/dist/project-profiles/index.js.map +1 -0
  116. package/dist/project-profiles/profiles/golang.d.ts +65 -0
  117. package/dist/project-profiles/profiles/golang.js +208 -0
  118. package/dist/project-profiles/profiles/golang.js.map +1 -0
  119. package/dist/project-profiles/profiles/java-maven.d.ts +80 -0
  120. package/dist/project-profiles/profiles/java-maven.js +165 -0
  121. package/dist/project-profiles/profiles/java-maven.js.map +1 -0
  122. package/dist/project-profiles/profiles/javascript-npm.d.ts +40 -0
  123. package/dist/project-profiles/profiles/javascript-npm.js +118 -0
  124. package/dist/project-profiles/profiles/javascript-npm.js.map +1 -0
  125. package/dist/project-profiles/profiles/javascript-react.d.ts +46 -0
  126. package/dist/project-profiles/profiles/javascript-react.js +147 -0
  127. package/dist/project-profiles/profiles/javascript-react.js.map +1 -0
  128. package/dist/project-profiles/profiles/python-django.d.ts +58 -0
  129. package/dist/project-profiles/profiles/python-django.js +200 -0
  130. package/dist/project-profiles/profiles/python-django.js.map +1 -0
  131. package/dist/project-profiles/types.d.ts +122 -0
  132. package/dist/project-profiles/types.js +77 -0
  133. package/dist/project-profiles/types.js.map +1 -0
  134. package/dist/prompt/function-calling.js +8 -3
  135. package/dist/prompt/function-calling.js.map +1 -1
  136. package/dist/prompt/function-defs/ask-question.d.ts +5 -0
  137. package/dist/prompt/function-defs/ask-question.js +140 -60
  138. package/dist/prompt/function-defs/ask-question.js.map +1 -1
  139. package/dist/prompt/function-defs/codegen-planning.d.ts +8 -0
  140. package/dist/prompt/function-defs/codegen-planning.js +50 -0
  141. package/dist/prompt/function-defs/codegen-planning.js.map +1 -0
  142. package/dist/prompt/function-defs/codegen-summary.js +2 -2
  143. package/dist/prompt/function-defs/codegen-summary.js.map +1 -1
  144. package/dist/prompt/function-defs/get-source-code.js +32 -2
  145. package/dist/prompt/function-defs/get-source-code.js.map +1 -1
  146. package/dist/prompt/function-defs/optimize-context.js +35 -12
  147. package/dist/prompt/function-defs/optimize-context.js.map +1 -1
  148. package/dist/prompt/function-defs/set-summaries.js +20 -1
  149. package/dist/prompt/function-defs/set-summaries.js.map +1 -1
  150. package/dist/prompt/limits.js +2 -2
  151. package/dist/prompt/limits.js.map +1 -1
  152. package/dist/prompt/limits.test.js +3 -3
  153. package/dist/prompt/limits.test.js.map +1 -1
  154. package/dist/prompt/prompt-codegen.js +7 -79
  155. package/dist/prompt/prompt-codegen.js.map +1 -1
  156. package/dist/prompt/prompt-codegen.test.js +8 -14
  157. package/dist/prompt/prompt-codegen.test.js.map +1 -1
  158. package/dist/prompt/prompt-service-ask-question.test.js +27 -80
  159. package/dist/prompt/prompt-service-ask-question.test.js.map +1 -1
  160. package/dist/prompt/prompt-service.ai-services.test.d.ts +1 -0
  161. package/dist/prompt/prompt-service.ai-services.test.js +149 -0
  162. package/dist/prompt/prompt-service.ai-services.test.js.map +1 -0
  163. package/dist/prompt/prompt-service.context-optimization.test.d.ts +1 -0
  164. package/dist/prompt/prompt-service.context-optimization.test.js +212 -0
  165. package/dist/prompt/prompt-service.context-optimization.test.js.map +1 -0
  166. package/dist/prompt/prompt-service.image-handling.test.d.ts +1 -0
  167. package/dist/prompt/prompt-service.image-handling.test.js +212 -0
  168. package/dist/prompt/prompt-service.image-handling.test.js.map +1 -0
  169. package/dist/prompt/prompt-service.js +41 -127
  170. package/dist/prompt/prompt-service.js.map +1 -1
  171. package/dist/prompt/prompt-service.test-utils.d.ts +66 -0
  172. package/dist/prompt/prompt-service.test-utils.js +169 -0
  173. package/dist/prompt/prompt-service.test-utils.js.map +1 -0
  174. package/dist/prompt/prompt-service.test.js +96 -20
  175. package/dist/prompt/prompt-service.test.js.map +1 -1
  176. package/dist/prompt/prompt-service.validation-recovery.test.d.ts +1 -0
  177. package/dist/prompt/prompt-service.validation-recovery.test.js +263 -0
  178. package/dist/prompt/prompt-service.validation-recovery.test.js.map +1 -0
  179. package/dist/prompt/static-prompts.d.ts +16 -0
  180. package/dist/prompt/static-prompts.js +22 -0
  181. package/dist/prompt/static-prompts.js.map +1 -0
  182. package/dist/prompt/steps/step-ask-question/handlers/cancel-code-generation.js +1 -3
  183. package/dist/prompt/steps/step-ask-question/handlers/cancel-code-generation.js.map +1 -1
  184. package/dist/prompt/steps/step-ask-question/handlers/code-generation.d.ts +2 -0
  185. package/dist/prompt/steps/step-ask-question/handlers/code-generation.js +58 -0
  186. package/dist/prompt/steps/step-ask-question/handlers/code-generation.js.map +1 -0
  187. package/dist/prompt/steps/step-ask-question/handlers/confirm-code-generation.d.ts +1 -1
  188. package/dist/prompt/steps/step-ask-question/handlers/confirm-code-generation.js +8 -7
  189. package/dist/prompt/steps/step-ask-question/handlers/confirm-code-generation.js.map +1 -1
  190. package/dist/prompt/steps/step-ask-question/handlers/context-optimization.js +6 -6
  191. package/dist/prompt/steps/step-ask-question/handlers/context-optimization.js.map +1 -1
  192. package/dist/prompt/steps/step-ask-question/handlers/default-action.js +1 -4
  193. package/dist/prompt/steps/step-ask-question/handlers/default-action.js.map +1 -1
  194. package/dist/prompt/steps/step-ask-question/handlers/handle-request-answer-with-image.d.ts +2 -0
  195. package/dist/prompt/steps/step-ask-question/handlers/handle-request-answer-with-image.js +86 -0
  196. package/dist/prompt/steps/step-ask-question/handlers/handle-request-answer-with-image.js.map +1 -0
  197. package/dist/prompt/steps/step-ask-question/handlers/handle-send-message-with-image.d.ts +2 -0
  198. package/dist/prompt/steps/step-ask-question/handlers/handle-send-message-with-image.js +97 -0
  199. package/dist/prompt/steps/step-ask-question/handlers/handle-send-message-with-image.js.map +1 -0
  200. package/dist/prompt/steps/step-ask-question/handlers/handle-send-message.d.ts +2 -0
  201. package/dist/prompt/steps/step-ask-question/handlers/handle-send-message.js +20 -0
  202. package/dist/prompt/steps/step-ask-question/handlers/handle-send-message.js.map +1 -0
  203. package/dist/prompt/steps/step-ask-question/handlers/handler-utils.d.ts +0 -0
  204. package/dist/prompt/steps/step-ask-question/handlers/handler-utils.js +2 -0
  205. package/dist/prompt/steps/step-ask-question/handlers/handler-utils.js.map +1 -0
  206. package/dist/prompt/steps/step-ask-question/handlers/remove-files-from-context.d.ts +1 -1
  207. package/dist/prompt/steps/step-ask-question/handlers/remove-files-from-context.js +57 -15
  208. package/dist/prompt/steps/step-ask-question/handlers/remove-files-from-context.js.map +1 -1
  209. package/dist/prompt/steps/step-ask-question/handlers/request-files-content.d.ts +1 -1
  210. package/dist/prompt/steps/step-ask-question/handlers/request-files-content.js +109 -12
  211. package/dist/prompt/steps/step-ask-question/handlers/request-files-content.js.map +1 -1
  212. package/dist/prompt/steps/step-ask-question/handlers/request-permissions.d.ts +1 -1
  213. package/dist/prompt/steps/step-ask-question/handlers/request-permissions.js +48 -26
  214. package/dist/prompt/steps/step-ask-question/handlers/request-permissions.js.map +1 -1
  215. package/dist/prompt/steps/step-ask-question/handlers/start-code-generation.js +1 -1
  216. package/dist/prompt/steps/step-ask-question/handlers/start-code-generation.js.map +1 -1
  217. package/dist/prompt/steps/step-ask-question/step-ask-question-reflect.js +1 -0
  218. package/dist/prompt/steps/step-ask-question/step-ask-question-reflect.js.map +1 -1
  219. package/dist/prompt/steps/step-ask-question/step-ask-question-types.d.ts +25 -21
  220. package/dist/prompt/steps/step-ask-question/step-ask-question.d.ts +2 -5
  221. package/dist/prompt/steps/step-ask-question/step-ask-question.js +36 -33
  222. package/dist/prompt/steps/step-ask-question/step-ask-question.js.map +1 -1
  223. package/dist/prompt/steps/step-codegen-planning.d.ts +10 -0
  224. package/dist/prompt/steps/step-codegen-planning.js +69 -0
  225. package/dist/prompt/steps/step-codegen-planning.js.map +1 -0
  226. package/dist/prompt/steps/step-codegen-summary.d.ts +7 -0
  227. package/dist/prompt/steps/step-codegen-summary.js +106 -0
  228. package/dist/prompt/steps/step-codegen-summary.js.map +1 -0
  229. package/dist/prompt/steps/step-codegen-summary.test.d.ts +1 -0
  230. package/dist/prompt/steps/step-codegen-summary.test.js +136 -0
  231. package/dist/prompt/steps/step-codegen-summary.test.js.map +1 -0
  232. package/dist/prompt/steps/step-context-optimization.js +243 -126
  233. package/dist/prompt/steps/step-context-optimization.js.map +1 -1
  234. package/dist/prompt/steps/step-context-optimization.test.d.ts +2 -0
  235. package/dist/prompt/steps/step-context-optimization.test.js +475 -0
  236. package/dist/prompt/steps/step-context-optimization.test.js.map +1 -0
  237. package/dist/prompt/steps/step-ensure-context.d.ts +15 -0
  238. package/dist/prompt/steps/step-ensure-context.js +102 -0
  239. package/dist/prompt/steps/step-ensure-context.js.map +1 -0
  240. package/dist/prompt/steps/step-ensure-context.test.d.ts +1 -0
  241. package/dist/prompt/steps/step-ensure-context.test.js +242 -0
  242. package/dist/prompt/steps/step-ensure-context.test.js.map +1 -0
  243. package/dist/prompt/steps/step-generate-image.d.ts +8 -1
  244. package/dist/prompt/steps/step-generate-image.js +1 -0
  245. package/dist/prompt/steps/step-generate-image.js.map +1 -1
  246. package/dist/prompt/steps/step-summarization.d.ts +2 -2
  247. package/dist/prompt/steps/step-summarization.js +45 -9
  248. package/dist/prompt/steps/step-summarization.js.map +1 -1
  249. package/dist/prompt/steps/step-validate-recover.js +24 -15
  250. package/dist/prompt/steps/step-validate-recover.js.map +1 -1
  251. package/dist/prompt/steps/steps-types.d.ts +2 -0
  252. package/dist/prompt/steps/steps-types.js.map +1 -1
  253. package/dist/prompt/systemprompt.d.ts +2 -2
  254. package/dist/prompt/systemprompt.js +74 -176
  255. package/dist/prompt/systemprompt.js.map +1 -1
  256. package/dist/prompt/systemprompt.test.js +4 -5
  257. package/dist/prompt/systemprompt.test.js.map +1 -1
  258. package/dist/vite-genaicode/vite-genaicode-plugin.js +0 -2
  259. package/dist/vite-genaicode/vite-genaicode-plugin.js.map +1 -1
  260. package/package.json +6 -2
  261. package/dist/main/ui/frontend/assets/index-Dk_qaEQg.js +0 -782
@@ -0,0 +1,475 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { executeStepContextOptimization } from './step-context-optimization';
3
+ import { getSourceCode } from '../../files/read-files';
4
+ import { StepResult } from './steps-types';
5
+ import { putSystemMessage } from '../../main/common/content-bus';
6
+ import '../../main/config.js';
7
+ import '../../files/find-files.js';
8
+ // Mock dependencies
9
+ vi.mock('../../files/read-files');
10
+ vi.mock('../../files/find-files.js', () => ({
11
+ getSourceFiles: () => [],
12
+ getImageAssetFiles: () => [],
13
+ refreshFiles: () => null,
14
+ }));
15
+ vi.mock('../../main/common/content-bus');
16
+ vi.mock('../token-estimator', () => ({
17
+ estimateTokenCount: vi.fn((content) => {
18
+ // Simple mock implementation that returns length of content as token count
19
+ return content ? content.length : 0;
20
+ }),
21
+ }));
22
+ vi.mock('./step-summarization', () => ({
23
+ getSummary: vi.fn().mockReturnValue({ summary: 'Test summary', dependencies: [{ path: 'test-dep', type: 'local' }] }),
24
+ }));
25
+ vi.mock('../../main/config.js', () => ({
26
+ rootDir: '/test',
27
+ rcConfig: {
28
+ rootDir: '/test',
29
+ extensions: ['.js', '.ts', '.tsx', '.jsx'],
30
+ },
31
+ importantContext: {},
32
+ sourceExtensions: ['.ts'],
33
+ }));
34
+ describe('executeStepContextOptimization', () => {
35
+ const mockGenerateContentFn = vi.fn();
36
+ const mockOptions = {
37
+ aiService: 'vertex-ai',
38
+ askQuestion: false,
39
+ };
40
+ beforeEach(() => {
41
+ vi.clearAllMocks();
42
+ mockGenerateContentFn.mockReset();
43
+ });
44
+ describe('Source code tree transformation', () => {
45
+ it('should correctly transform source code between flat and tree structures', async () => {
46
+ // Mock source code data
47
+ const mockSourceCode = {
48
+ '/test/file1.ts': { content: 'content1' + Array.from(Array(10000).keys()).join(',') },
49
+ '/test/file2.ts': { content: 'content2' },
50
+ };
51
+ const mockSourceCodeTree = {
52
+ '/test': {
53
+ 'file1.ts': { content: 'content1' + Array.from(Array(10000).keys()).join(',') },
54
+ 'file2.ts': { content: 'content2' },
55
+ },
56
+ };
57
+ vi.mocked(getSourceCode).mockReturnValue(mockSourceCode);
58
+ // Mock optimization response with high relevance scores
59
+ mockGenerateContentFn.mockResolvedValueOnce([
60
+ {
61
+ name: 'optimizeContext',
62
+ args: {
63
+ userPrompt: 'test prompt',
64
+ optimizedContext: [
65
+ { filePath: '/test/file1.ts', relevance: 0.9 },
66
+ { filePath: '/test/file2.ts', relevance: 0.8 },
67
+ ],
68
+ },
69
+ },
70
+ ]);
71
+ const result = await executeStepContextOptimization(mockGenerateContentFn, [
72
+ {
73
+ type: 'user',
74
+ functionResponses: [
75
+ {
76
+ name: 'getSourceCode',
77
+ content: JSON.stringify(mockSourceCodeTree),
78
+ },
79
+ ],
80
+ },
81
+ ], mockOptions);
82
+ expect(result).toBe(StepResult.CONTINUE);
83
+ expect(putSystemMessage).toHaveBeenCalledWith('Context optimization in progress.', expect.arrayContaining([
84
+ ['/test/file1.ts', 0.9],
85
+ ['/test/file2.ts', 0.8],
86
+ ]));
87
+ });
88
+ it('should handle empty source code tree', async () => {
89
+ const emptySourceCode = {};
90
+ const emptySourceCodeTree = {};
91
+ vi.mocked(getSourceCode).mockReturnValue(emptySourceCode);
92
+ mockGenerateContentFn.mockResolvedValueOnce([
93
+ {
94
+ name: 'optimizeContext',
95
+ args: {
96
+ userPrompt: 'test prompt',
97
+ optimizedContext: [],
98
+ },
99
+ },
100
+ ]);
101
+ const result = await executeStepContextOptimization(mockGenerateContentFn, [
102
+ {
103
+ type: 'user',
104
+ functionResponses: [
105
+ {
106
+ name: 'getSourceCode',
107
+ content: JSON.stringify(emptySourceCodeTree),
108
+ },
109
+ ],
110
+ },
111
+ ], mockOptions);
112
+ expect(result).toBe(StepResult.CONTINUE);
113
+ expect(putSystemMessage).toHaveBeenCalledWith('Context optimization is not needed, because the code base is small.');
114
+ });
115
+ });
116
+ describe('Multiple getSourceCode responses handling', () => {
117
+ // This test verifies that when clearing previous getSourceCode responses:
118
+ // 1. Directory structure is preserved
119
+ // 2. File content is set to null
120
+ // 3. The overall structure of the conversation remains intact
121
+ it('should clear previous getSourceCode responses while preserving structure', async () => {
122
+ const mockSourceCode = {
123
+ '/test/file1.ts': { content: 'content1' + Array.from(Array(10000).keys()).join(',') },
124
+ };
125
+ const mockSourceCodeTree = {
126
+ '/test': {
127
+ 'file1.ts': { content: 'content1' + Array.from(Array(10000).keys()).join(',') },
128
+ },
129
+ };
130
+ vi.mocked(getSourceCode).mockReturnValue(mockSourceCode);
131
+ mockGenerateContentFn.mockResolvedValueOnce([
132
+ {
133
+ name: 'optimizeContext',
134
+ args: {
135
+ userPrompt: 'test prompt',
136
+ optimizedContext: [{ filePath: '/test/file1.ts', relevance: 0.9 }],
137
+ },
138
+ },
139
+ ]);
140
+ const prompt = [
141
+ {
142
+ type: 'user',
143
+ functionResponses: [
144
+ {
145
+ name: 'getSourceCode',
146
+ content: JSON.stringify({ '/test': { 'old-file.ts': { content: 'old content' } } }),
147
+ },
148
+ ],
149
+ },
150
+ {
151
+ type: 'assistant',
152
+ text: 'Some response',
153
+ },
154
+ {
155
+ type: 'user',
156
+ functionResponses: [
157
+ {
158
+ name: 'getSourceCode',
159
+ content: JSON.stringify(mockSourceCodeTree),
160
+ },
161
+ ],
162
+ },
163
+ ];
164
+ const result = await executeStepContextOptimization(mockGenerateContentFn, prompt, mockOptions);
165
+ expect(result).toBe(StepResult.CONTINUE);
166
+ // Verify that previous responses maintain structure but clear content
167
+ const expectedStructure = {
168
+ '/test': {
169
+ 'old-file.ts': { content: null },
170
+ },
171
+ };
172
+ expect(JSON.parse(prompt[0].functionResponses[0].content)).toEqual(expectedStructure);
173
+ // Verify that structure was preserved
174
+ expect(prompt[0].type).toBe('user');
175
+ expect(prompt[0].functionResponses[0].name).toBe('getSourceCode');
176
+ // Verify that non-getSourceCode items were preserved
177
+ expect(prompt[1].type).toBe('assistant');
178
+ expect(prompt[1].text).toBe('Some response');
179
+ });
180
+ // This test verifies that when handling multiple responses:
181
+ // 1. Each response maintains its directory structure
182
+ // 2. Content is cleared (set to null) for all previous responses
183
+ // 3. The latest response remains unchanged
184
+ it('should handle multiple responses with different content', async () => {
185
+ const mockSourceCode = {
186
+ '/test/file1.ts': { content: 'content1' + Array.from(Array(10000).keys()).join(',') },
187
+ '/test/file2.ts': { content: 'content2' },
188
+ };
189
+ const mockSourceCodeTree = {
190
+ '/test': {
191
+ 'file1.ts': { content: 'content1' + Array.from(Array(10000).keys()).join(',') },
192
+ 'file2.ts': { content: 'content2' },
193
+ },
194
+ };
195
+ vi.mocked(getSourceCode).mockReturnValue(mockSourceCode);
196
+ mockGenerateContentFn.mockResolvedValueOnce([
197
+ {
198
+ name: 'optimizeContext',
199
+ args: {
200
+ userPrompt: 'test prompt',
201
+ optimizedContext: [
202
+ { filePath: '/test/file1.ts', relevance: 0.9 },
203
+ { filePath: '/test/file2.ts', relevance: 0.8 },
204
+ ],
205
+ },
206
+ },
207
+ ]);
208
+ const prompt = [
209
+ {
210
+ type: 'user',
211
+ functionResponses: [
212
+ {
213
+ name: 'getSourceCode',
214
+ content: JSON.stringify({ '/test': { 'file1.ts': { content: 'old content 1' } } }),
215
+ },
216
+ ],
217
+ },
218
+ {
219
+ type: 'user',
220
+ functionResponses: [
221
+ {
222
+ name: 'getSourceCode',
223
+ content: JSON.stringify({ '/test': { 'file2.ts': { content: 'old content 2' } } }),
224
+ },
225
+ ],
226
+ },
227
+ {
228
+ type: 'user',
229
+ functionResponses: [
230
+ {
231
+ name: 'getSourceCode',
232
+ content: JSON.stringify(mockSourceCodeTree),
233
+ },
234
+ ],
235
+ },
236
+ ];
237
+ const result = await executeStepContextOptimization(mockGenerateContentFn, prompt, mockOptions);
238
+ expect(result).toBe(StepResult.CONTINUE);
239
+ // Verify that previous responses maintain structure but clear content
240
+ prompt.slice(0, -1).forEach((item) => {
241
+ if (item.type === 'user' && item.functionResponses) {
242
+ const response = item.functionResponses.find((r) => r.name === 'getSourceCode');
243
+ const parsedContent = JSON.parse(response.content);
244
+ // Check that structure is preserved but content is null
245
+ expect(parsedContent).toHaveProperty('/test');
246
+ Object.values(parsedContent['/test']).forEach((file) => {
247
+ expect(file.content).toBe(null);
248
+ });
249
+ }
250
+ });
251
+ });
252
+ it('should handle edge case with no getSourceCode responses', async () => {
253
+ const mockSourceCode = {
254
+ '/test/file1.ts': { content: 'content1' + Array.from(Array(10000).keys()).join(',') },
255
+ };
256
+ vi.mocked(getSourceCode).mockReturnValue(mockSourceCode);
257
+ const prompt = [
258
+ {
259
+ type: 'user',
260
+ text: 'Some user message',
261
+ },
262
+ {
263
+ type: 'assistant',
264
+ text: 'Some assistant response',
265
+ },
266
+ ];
267
+ const result = await executeStepContextOptimization(mockGenerateContentFn, prompt, mockOptions);
268
+ expect(result).toBe(StepResult.CONTINUE);
269
+ // Verify that the prompt structure remains unchanged
270
+ expect(prompt).toHaveLength(2);
271
+ expect(prompt[0].type).toBe('user');
272
+ expect(prompt[0].text).toBe('Some user message');
273
+ expect(prompt[1].type).toBe('assistant');
274
+ expect(prompt[1].text).toBe('Some assistant response');
275
+ });
276
+ it('should handle edge case with empty functionResponses', async () => {
277
+ const mockSourceCode = {
278
+ '/test/file1.ts': { content: 'content1' + Array.from(Array(10000).keys()).join(',') },
279
+ };
280
+ vi.mocked(getSourceCode).mockReturnValue(mockSourceCode);
281
+ const prompt = [
282
+ {
283
+ type: 'user',
284
+ functionResponses: [],
285
+ },
286
+ {
287
+ type: 'user',
288
+ functionResponses: undefined,
289
+ },
290
+ ];
291
+ const result = await executeStepContextOptimization(mockGenerateContentFn, prompt, mockOptions);
292
+ expect(result).toBe(StepResult.CONTINUE);
293
+ // Verify that the prompt structure remains unchanged
294
+ expect(prompt).toHaveLength(2);
295
+ expect(prompt[0].type).toBe('user');
296
+ expect(prompt[0].functionResponses).toEqual([]);
297
+ expect(prompt[1].type).toBe('user');
298
+ expect(prompt[1].functionResponses).toBeUndefined();
299
+ });
300
+ });
301
+ describe('Context optimization process', () => {
302
+ it('should optimize context based on relevance scores', async () => {
303
+ const mockSourceCode = {
304
+ '/test/high-relevance.ts': { content: 'important content' + Array.from(Array(10000).keys()).join(',') },
305
+ '/test/medium-relevance.ts': { content: 'somewhat important' },
306
+ '/test/low-relevance.ts': { content: 'not important' },
307
+ };
308
+ const mockSourceCodeTree = {
309
+ '/test': {
310
+ 'high-relevance.ts': { content: 'important content' },
311
+ 'medium-relevance.ts': { content: 'somewhat important' },
312
+ 'low-relevance.ts': { content: 'not important' },
313
+ },
314
+ };
315
+ vi.mocked(getSourceCode).mockReturnValue(mockSourceCode);
316
+ mockGenerateContentFn.mockResolvedValueOnce([
317
+ {
318
+ name: 'optimizeContext',
319
+ args: {
320
+ userPrompt: 'test prompt',
321
+ optimizedContext: [
322
+ { filePath: '/test/high-relevance.ts', relevance: 0.9 },
323
+ { filePath: '/test/medium-relevance.ts', relevance: 0.6 },
324
+ { filePath: '/test/low-relevance.ts', relevance: 0.2 },
325
+ ],
326
+ },
327
+ },
328
+ ]);
329
+ const result = await executeStepContextOptimization(mockGenerateContentFn, [
330
+ {
331
+ type: 'user',
332
+ functionResponses: [
333
+ {
334
+ name: 'getSourceCode',
335
+ content: JSON.stringify(mockSourceCodeTree),
336
+ },
337
+ ],
338
+ },
339
+ ], mockOptions);
340
+ expect(result).toBe(StepResult.CONTINUE);
341
+ expect(putSystemMessage).toHaveBeenCalledWith('Context optimization in progress.', expect.arrayContaining([
342
+ ['/test/high-relevance.ts', 0.9],
343
+ ['/test/medium-relevance.ts', 0.6],
344
+ ]));
345
+ // Low relevance file should not be included
346
+ expect(putSystemMessage).not.toHaveBeenCalledWith('Context optimization in progress.', expect.arrayContaining(['/test/low-relevance.ts', 0.2]));
347
+ });
348
+ it('should handle optimization failure gracefully', async () => {
349
+ const mockSourceCode = {
350
+ '/test/file.ts': { content: 'test content'.repeat(1000) }, // Make it large enough to trigger optimization
351
+ };
352
+ const mockSourceCodeTree = {
353
+ '/test': {
354
+ 'file.ts': { content: 'test content'.repeat(1000) },
355
+ },
356
+ };
357
+ vi.mocked(getSourceCode).mockReturnValue(mockSourceCode);
358
+ mockGenerateContentFn.mockResolvedValueOnce([
359
+ {
360
+ name: 'optimizeContext',
361
+ args: {
362
+ userPrompt: 'test prompt',
363
+ optimizedContext: [], // Empty context indicates optimization failure
364
+ },
365
+ },
366
+ ]);
367
+ const result = await executeStepContextOptimization(mockGenerateContentFn, [
368
+ {
369
+ type: 'user',
370
+ functionResponses: [
371
+ {
372
+ name: 'getSourceCode',
373
+ content: JSON.stringify(mockSourceCodeTree),
374
+ },
375
+ ],
376
+ },
377
+ ], mockOptions);
378
+ expect(result).toBe(StepResult.CONTINUE);
379
+ expect(putSystemMessage).toHaveBeenCalledWith('Warning: Context optimization failed to produce useful summaries for all batches. Proceeding with current context.');
380
+ });
381
+ });
382
+ describe('Edge cases and error handling', () => {
383
+ beforeEach(() => {
384
+ const mockSourceCode = {
385
+ '/test/file1.ts': { content: 'content1' + Array.from(Array(10000).keys()).join(',') },
386
+ };
387
+ vi.mocked(getSourceCode).mockReturnValue(mockSourceCode);
388
+ });
389
+ it('should handle missing source code response', async () => {
390
+ const result = await executeStepContextOptimization(mockGenerateContentFn, [], // Empty prompt array
391
+ mockOptions);
392
+ expect(result).toBe(StepResult.CONTINUE);
393
+ expect(putSystemMessage).not.toHaveBeenCalledWith('Context optimization in progress.');
394
+ });
395
+ it('should handle invalid JSON in source code response', async () => {
396
+ await expect(executeStepContextOptimization(mockGenerateContentFn, [
397
+ {
398
+ type: 'user',
399
+ functionResponses: [
400
+ {
401
+ name: 'getSourceCode',
402
+ content: 'invalid json',
403
+ },
404
+ ],
405
+ },
406
+ ], mockOptions)).rejects.toThrow('Unexpected token');
407
+ });
408
+ it('should handle errors during optimization process', async () => {
409
+ vi.mocked(getSourceCode).mockImplementation(() => {
410
+ throw new Error('Unexpected error');
411
+ });
412
+ await expect(executeStepContextOptimization(mockGenerateContentFn, [
413
+ {
414
+ type: 'user',
415
+ functionResponses: [
416
+ {
417
+ name: 'getSourceCode',
418
+ content: '{}',
419
+ },
420
+ ],
421
+ },
422
+ ], mockOptions)).rejects.toThrow('Unexpected error');
423
+ });
424
+ });
425
+ describe('Token count handling', () => {
426
+ it('should respect MAX_TOTAL_TOKENS limit', async () => {
427
+ // Create source code that exceeds token limit
428
+ const largeContent = 'a'.repeat(12000); // Exceeds MAX_TOTAL_TOKENS (10000)
429
+ const smallContent = 'b'.repeat(3000);
430
+ const mockSourceCode = {
431
+ '/test/large-file.ts': { content: largeContent },
432
+ '/test/small-file.ts': { content: smallContent },
433
+ };
434
+ const mockSourceCodeTree = {
435
+ '/test': {
436
+ 'large-file.ts': { content: largeContent },
437
+ 'small-file.ts': { content: smallContent },
438
+ },
439
+ };
440
+ vi.mocked(getSourceCode).mockReturnValue(mockSourceCode);
441
+ mockGenerateContentFn.mockResolvedValueOnce([
442
+ {
443
+ name: 'optimizeContext',
444
+ args: {
445
+ userPrompt: 'test prompt',
446
+ optimizedContext: [
447
+ { filePath: '/test/large-file.ts', relevance: 0.9 },
448
+ { filePath: '/test/small-file.ts', relevance: 0.8 },
449
+ ],
450
+ },
451
+ },
452
+ ]);
453
+ const result = await executeStepContextOptimization(mockGenerateContentFn, [
454
+ {
455
+ type: 'user',
456
+ functionResponses: [
457
+ {
458
+ name: 'getSourceCode',
459
+ content: JSON.stringify(mockSourceCodeTree),
460
+ },
461
+ ],
462
+ },
463
+ ], mockOptions);
464
+ expect(result).toBe(StepResult.CONTINUE);
465
+ expect(putSystemMessage).toHaveBeenCalledWith('Context optimization completed successfully.', expect.objectContaining({
466
+ tokensBefore: expect.any(Number),
467
+ tokensAfter: expect.any(Number),
468
+ contentTokenCount: expect.any(Number),
469
+ summaryTokenCount: expect.any(Number),
470
+ percentageReduced: expect.stringContaining('%'),
471
+ }));
472
+ });
473
+ });
474
+ });
475
+ //# sourceMappingURL=step-context-optimization.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-context-optimization.test.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-context-optimization.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,E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C,GAAG,CAAC,MAAM,CAAC;gBAChC,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;gBAC/B,iBAAiB,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;gBACrC,iBAAiB,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;gBACrC,iBAAiB,EAAE,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC;aAChD,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { FunctionCall } from '../../ai-service/common.js';
2
+ import { CodegenOptions } from '../../main/codegen-types.js';
3
+ import { StepResult } from './steps-types.js';
4
+ /**
5
+ * Executes the context completeness check step.
6
+ * Ensures all necessary files are included in the conversation context.
7
+ */
8
+ export declare function executeStepEnsureContext(prompt: {
9
+ type: string;
10
+ functionResponses?: {
11
+ name: string;
12
+ content?: string;
13
+ }[];
14
+ functionCalls?: FunctionCall[];
15
+ }[], codegenSummaryCall: FunctionCall, options: CodegenOptions): Promise<StepResult>;
@@ -0,0 +1,102 @@
1
+ import { importantContext } from '../../main/config.js';
2
+ import { getSourceCode } from '../../files/read-files.js';
3
+ import { putSystemMessage } from '../../main/common/content-bus.js';
4
+ import { StepResult } from './steps-types.js';
5
+ import { getSourceCodeTree } from '../../files/source-code-tree.js';
6
+ /**
7
+ * Executes the context completeness check step.
8
+ * Ensures all necessary files are included in the conversation context.
9
+ */
10
+ export async function executeStepEnsureContext(prompt, codegenSummaryCall, options) {
11
+ try {
12
+ // Extract all required paths
13
+ const requiredPaths = extractRequiredPaths(codegenSummaryCall);
14
+ if (requiredPaths.length === 0) {
15
+ putSystemMessage('No paths to ensure in context.');
16
+ return StepResult.CONTINUE;
17
+ }
18
+ // Get paths that are already in context
19
+ const existingPaths = getExistingContextPaths(prompt);
20
+ // Find paths that are missing from context
21
+ const missingPaths = requiredPaths.filter((path) => !existingPaths.has(path));
22
+ if (missingPaths.length === 0) {
23
+ putSystemMessage('All required paths are already in context.');
24
+ return StepResult.CONTINUE;
25
+ }
26
+ // Get source code for missing paths
27
+ putSystemMessage(`Ensuring context completeness. Adding ${missingPaths.length} missing files.`, { missingPaths });
28
+ const sourceCode = getSourceCode({ filterPaths: missingPaths }, options);
29
+ // Append getSourceCode function call/response to the prompt
30
+ prompt.push({
31
+ type: 'assistant',
32
+ functionCalls: [
33
+ {
34
+ name: 'getSourceCode',
35
+ args: {
36
+ filePaths: missingPaths,
37
+ },
38
+ },
39
+ ],
40
+ }, {
41
+ type: 'user',
42
+ functionResponses: [
43
+ {
44
+ name: 'getSourceCode',
45
+ content: JSON.stringify(getSourceCodeTree(sourceCode)),
46
+ },
47
+ ],
48
+ });
49
+ putSystemMessage('Context completeness check completed successfully.');
50
+ return StepResult.CONTINUE;
51
+ }
52
+ catch (error) {
53
+ putSystemMessage('Error: Context completeness check failed. This is unexpected.');
54
+ console.error('Context completeness check error:', error);
55
+ return StepResult.BREAK;
56
+ }
57
+ }
58
+ /**
59
+ * Extract all required file paths from codegenSummary function call
60
+ */
61
+ function extractRequiredPaths(codegenSummaryCall) {
62
+ if (!codegenSummaryCall.args?.fileUpdates || !codegenSummaryCall.args?.contextPaths) {
63
+ throw new Error('Invalid codegenSummary call: missing fileUpdates or contextPaths');
64
+ }
65
+ // Ensure fileUpdates is an array and has the correct type
66
+ const fileUpdatePaths = Array.isArray(codegenSummaryCall.args.fileUpdates)
67
+ ? codegenSummaryCall.args.fileUpdates.map((update) => update.filePath)
68
+ : [];
69
+ const contextPaths = codegenSummaryCall.args.contextPaths;
70
+ const importantPaths = importantContext.files ?? [];
71
+ // Use Set to deduplicate paths
72
+ return Array.from(new Set([...fileUpdatePaths, ...contextPaths, ...importantPaths]));
73
+ }
74
+ /**
75
+ * Get paths that are already present in the conversation context
76
+ */
77
+ function getExistingContextPaths(prompt) {
78
+ const existingPaths = new Set();
79
+ for (const item of prompt) {
80
+ if (!item.functionResponses)
81
+ continue;
82
+ const sourceCodeResponse = item.functionResponses.find((response) => response.name === 'getSourceCode');
83
+ if (!sourceCodeResponse?.content)
84
+ continue;
85
+ try {
86
+ const sourceCode = JSON.parse(sourceCodeResponse.content);
87
+ for (const [dirPath, files] of Object.entries(sourceCode)) {
88
+ for (const [fileName, fileInfo] of Object.entries(files)) {
89
+ const fullPath = `${dirPath}/${fileName}`;
90
+ if (fileInfo && typeof fileInfo === 'object' && 'content' in fileInfo && fileInfo.content !== null) {
91
+ existingPaths.add(fullPath);
92
+ }
93
+ }
94
+ }
95
+ }
96
+ catch (error) {
97
+ console.warn('Failed to parse getSourceCode response:', error);
98
+ }
99
+ }
100
+ return existingPaths;
101
+ }
102
+ //# sourceMappingURL=step-ensure-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-ensure-context.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-ensure-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAEpE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,MAAoH,EACpH,kBAAgC,EAChC,OAAuB;IAEvB,IAAI,CAAC;QACH,6BAA6B;QAC7B,MAAM,aAAa,GAAG,oBAAoB,CAAC,kBAAkB,CAAC,CAAC;QAC/D,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,gBAAgB,CAAC,gCAAgC,CAAC,CAAC;YACnD,OAAO,UAAU,CAAC,QAAQ,CAAC;QAC7B,CAAC;QAED,wCAAwC;QACxC,MAAM,aAAa,GAAG,uBAAuB,CAAC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