genaicode 0.8.4 → 0.8.6

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 (151) hide show
  1. package/README.md +18 -1
  2. package/dist/ai-service/anthropic.js +1 -1
  3. package/dist/ai-service/anthropic.js.map +1 -1
  4. package/dist/ai-service/common.d.ts +2 -1
  5. package/dist/ai-service/common.js +4 -4
  6. package/dist/ai-service/common.js.map +1 -1
  7. package/dist/ai-service/openai.d.ts +8 -0
  8. package/dist/ai-service/openai.js +182 -0
  9. package/dist/ai-service/openai.js.map +1 -0
  10. package/dist/ai-service/service-configurations.js +9 -3
  11. package/dist/ai-service/service-configurations.js.map +1 -1
  12. package/dist/cli/cli-options.js +1 -1
  13. package/dist/cli/cli-options.js.map +1 -1
  14. package/dist/cli/service-autodetect.js +1 -1
  15. package/dist/cli/service-autodetect.js.map +1 -1
  16. package/dist/cli/validate-cli-params.js +1 -1
  17. package/dist/cli/validate-cli-params.js.map +1 -1
  18. package/dist/files/find-files.js +5 -2
  19. package/dist/files/find-files.js.map +1 -1
  20. package/dist/files/read-files.d.ts +1 -0
  21. package/dist/files/read-files.js +13 -5
  22. package/dist/files/read-files.js.map +1 -1
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +4 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/main/codegen-types.d.ts +56 -4
  27. package/dist/main/codegen-utils.js +1 -1
  28. package/dist/main/codegen-utils.js.map +1 -1
  29. package/dist/main/codegen.js +5 -5
  30. package/dist/main/codegen.js.map +1 -1
  31. package/dist/main/common/content-bus-types.d.ts +1 -1
  32. package/dist/main/config-lib.d.ts +2 -31
  33. package/dist/main/config-lib.js +4 -1
  34. package/dist/main/config-lib.js.map +1 -1
  35. package/dist/main/config-schema.d.ts +14 -0
  36. package/dist/main/config-schema.js +145 -0
  37. package/dist/main/config-schema.js.map +1 -0
  38. package/dist/main/config-types.d.ts +36 -0
  39. package/dist/main/config-types.js +2 -0
  40. package/dist/main/config-types.js.map +1 -0
  41. package/dist/main/config.d.ts +2 -1
  42. package/dist/main/config.js +11 -3
  43. package/dist/main/config.js.map +1 -1
  44. package/dist/main/interactive/select-ai-service.js +1 -1
  45. package/dist/main/interactive/select-ai-service.js.map +1 -1
  46. package/dist/main/plugin-loader.d.ts +19 -4
  47. package/dist/main/plugin-loader.js +155 -48
  48. package/dist/main/plugin-loader.js.map +1 -1
  49. package/dist/main/ui/backend/api-handlers.d.ts +6 -0
  50. package/dist/main/ui/backend/api-handlers.js +5 -0
  51. package/dist/main/ui/backend/api-handlers.js.map +1 -0
  52. package/dist/main/ui/backend/api.d.ts +1 -0
  53. package/dist/main/ui/backend/api.js +6 -313
  54. package/dist/main/ui/backend/api.js.map +1 -1
  55. package/dist/main/ui/backend/endpoints/config-endpoint.d.ts +1 -0
  56. package/dist/main/ui/backend/endpoints/config-endpoint.js +39 -0
  57. package/dist/main/ui/backend/endpoints/config-endpoint.js.map +1 -0
  58. package/dist/main/ui/backend/endpoints/content-endpoint.d.ts +1 -0
  59. package/dist/main/ui/backend/endpoints/content-endpoint.js +14 -0
  60. package/dist/main/ui/backend/endpoints/content-endpoint.js.map +1 -0
  61. package/dist/main/ui/backend/endpoints/edit-message-endpoint.d.ts +1 -0
  62. package/dist/main/ui/backend/endpoints/edit-message-endpoint.js +34 -0
  63. package/dist/main/ui/backend/endpoints/edit-message-endpoint.js.map +1 -0
  64. package/dist/main/ui/backend/endpoints/execute-codegen-endpoint.d.ts +1 -0
  65. package/dist/main/ui/backend/endpoints/execute-codegen-endpoint.js +44 -0
  66. package/dist/main/ui/backend/endpoints/execute-codegen-endpoint.js.map +1 -0
  67. package/dist/main/ui/backend/endpoints/execution-status-endpoint.d.ts +1 -0
  68. package/dist/main/ui/backend/endpoints/execution-status-endpoint.js +37 -0
  69. package/dist/main/ui/backend/endpoints/execution-status-endpoint.js.map +1 -0
  70. package/dist/main/ui/backend/endpoints/generate-content-endpoint.d.ts +1 -0
  71. package/dist/main/ui/backend/endpoints/generate-content-endpoint.js +29 -0
  72. package/dist/main/ui/backend/endpoints/generate-content-endpoint.js.map +1 -0
  73. package/dist/main/ui/backend/endpoints/index.d.ts +11 -0
  74. package/dist/main/ui/backend/endpoints/index.js +12 -0
  75. package/dist/main/ui/backend/endpoints/index.js.map +1 -0
  76. package/dist/main/ui/backend/endpoints/interrupt-execution-endpoint.d.ts +1 -0
  77. package/dist/main/ui/backend/endpoints/interrupt-execution-endpoint.js +14 -0
  78. package/dist/main/ui/backend/endpoints/interrupt-execution-endpoint.js.map +1 -0
  79. package/dist/main/ui/backend/endpoints/iteration-endpoint.d.ts +1 -0
  80. package/dist/main/ui/backend/endpoints/iteration-endpoint.js +16 -0
  81. package/dist/main/ui/backend/endpoints/iteration-endpoint.js.map +1 -0
  82. package/dist/main/ui/backend/endpoints/question-endpoint.d.ts +1 -0
  83. package/dist/main/ui/backend/endpoints/question-endpoint.js +37 -0
  84. package/dist/main/ui/backend/endpoints/question-endpoint.js.map +1 -0
  85. package/dist/main/ui/backend/endpoints/service-configuration-endpoint.d.ts +1 -0
  86. package/dist/main/ui/backend/endpoints/service-configuration-endpoint.js +54 -0
  87. package/dist/main/ui/backend/endpoints/service-configuration-endpoint.js.map +1 -0
  88. package/dist/main/ui/backend/endpoints/usage-endpoint.d.ts +1 -0
  89. package/dist/main/ui/backend/endpoints/usage-endpoint.js +15 -0
  90. package/dist/main/ui/backend/endpoints/usage-endpoint.js.map +1 -0
  91. package/dist/main/ui/backend/service.d.ts +1 -1
  92. package/dist/main/ui/common/api-types.d.ts +5 -1
  93. package/dist/main/ui/frontend/assets/index-BAAQr5b1.js +1747 -0
  94. package/dist/main/ui/frontend/index.html +1 -1
  95. package/dist/prompt/ai-service-fallback.js +10 -3
  96. package/dist/prompt/ai-service-fallback.js.map +1 -1
  97. package/dist/prompt/function-calling-validate.d.ts +1 -1
  98. package/dist/prompt/function-calling-validate.js +13 -5
  99. package/dist/prompt/function-calling-validate.js.map +1 -1
  100. package/dist/prompt/function-calling.js +2 -1
  101. package/dist/prompt/function-calling.js.map +1 -1
  102. package/dist/prompt/function-defs/ask-question.d.ts +1 -0
  103. package/dist/prompt/function-defs/ask-question.js +66 -9
  104. package/dist/prompt/function-defs/ask-question.js.map +1 -1
  105. package/dist/prompt/function-defs/optimize-context.js +2 -2
  106. package/dist/prompt/function-defs/optimize-context.js.map +1 -1
  107. package/dist/prompt/limits.js +2 -2
  108. package/dist/prompt/prompt-service.js +4 -2
  109. package/dist/prompt/prompt-service.js.map +1 -1
  110. package/dist/prompt/prompt-service.test-utils.d.ts +1 -1
  111. package/dist/prompt/prompt-service.test-utils.js +1 -1
  112. package/dist/prompt/prompt-service.test-utils.js.map +1 -1
  113. package/dist/prompt/static-prompts.d.ts +2 -1
  114. package/dist/prompt/static-prompts.js +2 -1
  115. package/dist/prompt/static-prompts.js.map +1 -1
  116. package/dist/prompt/steps/step-ask-question/handlers/code-generation.js +15 -15
  117. package/dist/prompt/steps/step-ask-question/handlers/code-generation.js.map +1 -1
  118. package/dist/prompt/steps/step-ask-question/handlers/default-action.d.ts +1 -1
  119. package/dist/prompt/steps/step-ask-question/handlers/default-action.js +2 -2
  120. package/dist/prompt/steps/step-ask-question/handlers/default-action.js.map +1 -1
  121. package/dist/prompt/steps/step-ask-question/handlers/handle-update-file.d.ts +2 -0
  122. package/dist/prompt/steps/step-ask-question/handlers/handle-update-file.js +136 -0
  123. package/dist/prompt/steps/step-ask-question/handlers/handle-update-file.js.map +1 -0
  124. package/dist/prompt/steps/step-ask-question/handlers/lint.js +23 -3
  125. package/dist/prompt/steps/step-ask-question/handlers/lint.js.map +1 -1
  126. package/dist/prompt/steps/step-ask-question/handlers/request-permissions.js +1 -1
  127. package/dist/prompt/steps/step-ask-question/handlers/request-permissions.js.map +1 -1
  128. package/dist/prompt/steps/step-ask-question/step-ask-question-types.d.ts +1 -1
  129. package/dist/prompt/steps/step-ask-question/step-ask-question.js +9 -5
  130. package/dist/prompt/steps/step-ask-question/step-ask-question.js.map +1 -1
  131. package/dist/prompt/steps/step-codegen-planning.js +63 -3
  132. package/dist/prompt/steps/step-codegen-planning.js.map +1 -1
  133. package/dist/prompt/steps/step-context-optimization.d.ts +3 -0
  134. package/dist/prompt/steps/step-context-optimization.js +63 -49
  135. package/dist/prompt/steps/step-context-optimization.js.map +1 -1
  136. package/dist/prompt/steps/step-generate-codegen-summary.js +3 -5
  137. package/dist/prompt/steps/step-generate-codegen-summary.js.map +1 -1
  138. package/dist/prompt/steps/step-process-file-updates.js +56 -10
  139. package/dist/prompt/steps/step-process-file-updates.js.map +1 -1
  140. package/dist/prompt/steps/step-summarization.js +2 -0
  141. package/dist/prompt/steps/step-summarization.js.map +1 -1
  142. package/dist/prompt/steps/step-validate-recover.js +5 -5
  143. package/dist/prompt/steps/step-validate-recover.js.map +1 -1
  144. package/dist/prompt/systemprompt.d.ts +2 -1
  145. package/dist/prompt/systemprompt.js +16 -4
  146. package/dist/prompt/systemprompt.js.map +1 -1
  147. package/dist/vite-genaicode/vite-genaicode-plugin.d.ts +4 -2
  148. package/dist/vite-genaicode/vite-genaicode-plugin.js +41 -24
  149. package/dist/vite-genaicode/vite-genaicode-plugin.js.map +1 -1
  150. package/package.json +7 -7
  151. package/dist/main/ui/frontend/assets/index-jwSqt8cG.js +0 -1337
@@ -0,0 +1,136 @@
1
+ import { executor as executeUpdateFile } from '../../../../operations/update-file/update-file-executor.js';
2
+ import { getSourceCode } from '../../../../files/read-files.js';
3
+ import { getFunctionDefs } from '../../../function-calling.js';
4
+ import { askUserForConfirmationWithAnswer } from '../../../../main/common/user-actions.js';
5
+ import { putSystemMessage } from '../../../../main/common/content-bus.js';
6
+ import { refreshFiles } from '../../../../files/find-files.js';
7
+ export const handleUpdateFile = async ({ askQuestionCall, options, prompt, generateContentFn, }) => {
8
+ putSystemMessage('File update requested, new content generation started.', askQuestionCall);
9
+ const [updateFileCall] = (await generateContentFn([
10
+ ...prompt,
11
+ {
12
+ type: 'assistant',
13
+ text: askQuestionCall.args?.message ?? '',
14
+ },
15
+ {
16
+ type: 'user',
17
+ text: 'Ok, please provide the update using `updateFile` function. Please remember to use absolute file path.',
18
+ },
19
+ ], getFunctionDefs(), 'updateFile', options.temperature ?? 0.7, false, options));
20
+ if (!updateFileCall || !updateFileCall.args) {
21
+ return {
22
+ breakLoop: true,
23
+ items: [],
24
+ };
25
+ }
26
+ const { filePath } = updateFileCall.args;
27
+ const file = getSourceCode({ filterPaths: [filePath], forceAll: true }, options)[filePath];
28
+ if (!file || !('content' in file) || !file.content) {
29
+ // TODO: In this corner case we should probably retry the operation but prefix it with getSourceCode
30
+ return {
31
+ breakLoop: false,
32
+ items: [
33
+ {
34
+ assistant: {
35
+ type: 'assistant',
36
+ text: askQuestionCall.args.message,
37
+ },
38
+ user: {
39
+ type: 'user',
40
+ text: 'The file does not exist or is empty or its content is not present in the context.',
41
+ },
42
+ },
43
+ ],
44
+ };
45
+ }
46
+ putSystemMessage(`The assistant suggests updating the file ${filePath}.`, {
47
+ name: updateFileCall.name,
48
+ args: {
49
+ ...updateFileCall.args,
50
+ oldContent: file.content,
51
+ },
52
+ });
53
+ const userConfirmation = await askUserForConfirmationWithAnswer('The assistant suggests updating the file. Do you want to proceed?', 'Accept file update', 'Reject file update', false);
54
+ if (!userConfirmation.confirmed) {
55
+ return {
56
+ breakLoop: false,
57
+ items: [
58
+ {
59
+ assistant: {
60
+ type: 'assistant',
61
+ text: askQuestionCall.args.message,
62
+ functionCalls: [updateFileCall],
63
+ },
64
+ user: {
65
+ type: 'user',
66
+ text: 'Rejecting file update.' + (userConfirmation.answer ? ` ${userConfirmation.answer}` : ''),
67
+ functionResponses: [
68
+ {
69
+ name: 'updateFile',
70
+ call_id: updateFileCall.id,
71
+ content: '',
72
+ },
73
+ ],
74
+ },
75
+ },
76
+ ],
77
+ };
78
+ }
79
+ else {
80
+ try {
81
+ await executeUpdateFile(updateFileCall.args);
82
+ refreshFiles();
83
+ return {
84
+ breakLoop: false,
85
+ items: [
86
+ {
87
+ assistant: {
88
+ type: 'assistant',
89
+ text: askQuestionCall.args.message,
90
+ functionCalls: [updateFileCall],
91
+ },
92
+ user: {
93
+ type: 'user',
94
+ text: 'Accepting file update.' + (userConfirmation.answer ? ` ${userConfirmation.answer}` : ''),
95
+ functionResponses: [
96
+ {
97
+ name: 'updateFile',
98
+ call_id: updateFileCall.id,
99
+ content: '',
100
+ },
101
+ ],
102
+ },
103
+ },
104
+ ],
105
+ };
106
+ }
107
+ catch {
108
+ return {
109
+ breakLoop: false,
110
+ items: [
111
+ {
112
+ assistant: {
113
+ type: 'assistant',
114
+ text: askQuestionCall.args.message,
115
+ functionCalls: [updateFileCall],
116
+ },
117
+ user: {
118
+ type: 'user',
119
+ text: 'Accepting file update.' +
120
+ (userConfirmation.answer ? ` ${userConfirmation.answer}` : '') +
121
+ ' Unfortunately, the file update failed, the new content was not saved.',
122
+ functionResponses: [
123
+ {
124
+ name: 'updateFile',
125
+ call_id: updateFileCall.id,
126
+ content: '',
127
+ },
128
+ ],
129
+ },
130
+ },
131
+ ],
132
+ };
133
+ }
134
+ }
135
+ };
136
+ //# sourceMappingURL=handle-update-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-update-file.js","sourceRoot":"","sources":["../../../../../src/prompt/steps/step-ask-question/handlers/handle-update-file.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,4DAA4D,CAAC;AAE3G,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,gCAAgC,EAAE,MAAM,yCAAyC,CAAC;AAC3F,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,MAAM,CAAC,MAAM,gBAAgB,GAAkB,KAAK,EAAE,EACpD,eAAe,EACf,OAAO,EACP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,wBAAwB,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;4BAC/F,iBAAiB,EAAE;gCACjB;oCACE,IAAI,EAAE,YAAY;oCAClB,OAAO,EAAE,cAAc,CAAC,EAAE;oCAC1B,OAAO,EAAE,EAAE;iCACZ;6BACF;yBACF;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO;gBACL,SAAS,EAAE,KAAK;gBAChB,KAAK,EAAE;oBACL;wBACE,SAAS,EAAE;4BACT,IAAI,EAAE,WAAW;4BACjB,IAAI,EAAE,eAAe,CAAC,IAAK,CAAC,OAAO;4BACnC,aAAa,EAAE,CAAC,cAAc,CAAC;yBAChC;wBACD,IAAI,EAAE;4BACJ,IAAI,EAAE,MAAM;4BACZ,IAAI,EACF,wBAAwB;gCACxB,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gCAC9D,wEAAwE;4BAC1E,iBAAiB,EAAE;gCACjB;oCACE,IAAI,EAAE,YAAY;oCAClB,OAAO,EAAE,cAAc,CAAC,EAAE;oCAC1B,OAAO,EAAE,EAAE;iCACZ;6BACF;yBACF;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC,CAAC"}
@@ -16,10 +16,18 @@ export async function handleLint({ askQuestionCall }) {
16
16
  assistant: {
17
17
  type: 'assistant',
18
18
  text: askQuestionCall.args?.message ?? '',
19
+ functionCalls: [{ name: 'lint', id: askQuestionCall.id + '_lint' }],
19
20
  },
20
21
  user: {
21
22
  type: 'user',
22
23
  text: 'Lint command not configured. Skipping lint check.',
24
+ functionResponses: [
25
+ {
26
+ name: 'lint',
27
+ call_id: askQuestionCall.id + '_lint',
28
+ content: JSON.stringify({ error: 'Lint command not configured' }),
29
+ },
30
+ ],
23
31
  },
24
32
  },
25
33
  ],
@@ -40,10 +48,18 @@ export async function handleLint({ askQuestionCall }) {
40
48
  assistant: {
41
49
  type: 'assistant',
42
50
  text: askQuestionCall.args?.message ?? '',
51
+ functionCalls: [{ name: 'lint', id: askQuestionCall.id + '_lint' }],
43
52
  },
44
53
  user: {
45
54
  type: 'user',
46
55
  text: 'Lint command executed successfully, no issues found.',
56
+ functionResponses: [
57
+ {
58
+ name: 'lint',
59
+ call_id: askQuestionCall.id + '_lint',
60
+ content: JSON.stringify(lintResult),
61
+ },
62
+ ],
47
63
  },
48
64
  },
49
65
  ],
@@ -65,14 +81,18 @@ export async function handleLint({ askQuestionCall }) {
65
81
  assistant: {
66
82
  type: 'assistant',
67
83
  text: askQuestionCall.args?.message ?? '',
68
- functionCalls: [askQuestionCall],
84
+ functionCalls: [{ name: 'lint', id: askQuestionCall.id + '_lint' }],
69
85
  },
70
86
  user: {
71
87
  type: 'user',
72
- text: 'Lint command failed',
88
+ text: 'Lint command failed, please analyze the output.',
73
89
  data: { stdout, stderr },
74
90
  functionResponses: [
75
- { name: 'askQuestion', call_id: askQuestionCall.id, content: JSON.stringify({ stdout, stderr }) },
91
+ {
92
+ name: 'lint',
93
+ call_id: askQuestionCall.id + '_lint',
94
+ content: JSON.stringify(lintResult),
95
+ },
76
96
  ],
77
97
  },
78
98
  },
@@ -1 +1 @@
1
- {"version":3,"file":"lint.js","sourceRoot":"","sources":["../../../../../src/prompt/steps/step-ask-question/handlers/lint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAGtD,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAEpC;;;GAGG;AACH,MA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,UAAU,GAAG;YACX,OAAO,EAAE,KAAK;YACd,MAAM;YACN,MAAM;SACP,CAAC;QAEF,iDAAiD;QACjD,OAAO;YACL,SAAS,EAAE,KAAK;YAChB,UAAU;YACV,KAAK,EAAE;gBACL;oBACE,SAAS,EAAE;wBACT,IAAI,EAAE,WAAW;wBACjB,IAAI,EAAE,eAAe,CAAC,IAAI,EAAE,OAAO,IAAI,EAAE;wBACzC,aAAa,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,eAAe,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC;qBACpE;oBACD,IAAI,EAAE;wBACJ,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,iDAAiD;wBACvD,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;wBACxB,iBAAiB,EAAE;4BACjB;gCACE,IAAI,EAAE,MAAM;gCACZ,OAAO,EAAE,eAAe,CAAC,EAAE,GAAG,OAAO;gCACrC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;6BACpC;yBACF;qBACF;iBACF;aACF;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -51,7 +51,7 @@ function updatePermissions(requestPermissionsCall, options) {
51
51
  const permissions = requestPermissionsCall.args;
52
52
  if (permissions) {
53
53
  if ('enableImagen' in permissions && permissions.enableImagen) {
54
- options.imagen = options.aiService === 'chat-gpt' ? 'dall-e' : 'vertex-ai';
54
+ options.imagen = options.aiService === 'openai' ? 'dall-e' : 'vertex-ai';
55
55
  }
56
56
  if ('enableVision' in permissions && permissions.enableVision)
57
57
  options.vision = true;
@@ -1 +1 @@
1
- {"version":3,"file":"request-permissions.js","sourceRoot":"","sources":["../../../../../src/prompt/steps/step-ask-question/handlers/request-permissions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAG/D,MAAM,C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EAAE,CAAC,sBAAsB,CAAC;iBACxC;gBACD,IAAI;aACL;SACF;KACF,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,sBAA4D,EAAE,OAAuB;IAC9G,MAAM,WAAW,GAAG,sBAAsB,CAAC,IAAI,CAAC;IAChD,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,cAAc,IAAI,WAAW,IAAI,WAAW,CAAC,YAAY,EAAE,CAAC;YAC9D,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC;QAC7E,CAAC;QACD,IAAI,cAAc,IAAI,WAAW,IAAI,WAAW,CAAC,YAAY;YAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;QACrF,IAAI,sBAAsB,IAAI,WAAW,IAAI,WAAW,CAAC,oBAAoB;YAAE,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;QACnH,IAAI,iBAAiB,IAAI,WAAW,IAAI,WAAW,CAAC,eAAe;YAAE,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;QACpG,IAAI,iBAAiB,IAAI,WAAW,IAAI,WAAW,CAAC,eAAe;YAAE,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;QACpG,IAAI,eAAe,IAAI,WAAW,IAAI,WAAW,CAAC,aAAa;YAAE,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAChG,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"request-permissions.js","sourceRoot":"","sources":["../../../../../src/prompt/steps/step-ask-question/handlers/request-permissions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAG/D,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,EAC7C,eAAe,EACf,OAAO,EACP,MAAM,EACN,iBAAiB,GACE;IACnB,MAAM,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,CAAC,sBAA4D,EAAE,OAAuB;IAC9G,MAAM,WAAW,GAAG,sBAAsB,CAAC,IAAI,CAAC;IAChD,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,cAAc,IAAI,WAAW,IAAI,WAAW,CAAC,YAAY,EAAE,CAAC;YAC9D,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC;QAC3E,CAAC;QACD,IAAI,cAAc,IAAI,WAAW,IAAI,WAAW,CAAC,YAAY;YAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;QACrF,IAAI,sBAAsB,IAAI,WAAW,IAAI,WAAW,CAAC,oBAAoB;YAAE,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;QACnH,IAAI,iBAAiB,IAAI,WAAW,IAAI,WAAW,CAAC,eAAe;YAAE,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;QACpG,IAAI,iBAAiB,IAAI,WAAW,IAAI,WAAW,CAAC,eAAe;YAAE,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;QACpG,IAAI,eAAe,IAAI,WAAW,IAAI,WAAW,CAAC,aAAa;YAAE,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAChG,CAAC;AACH,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { FunctionCall, GenerateContentFunction, GenerateImageFunction, PromptItem, PromptItemImage } from '../../../ai-service/common.js';
2
2
  import { CodegenOptions } from '../../../main/codegen-types.js';
3
3
  import { PluginActionType } from '../../../main/codegen-types.js';
4
- export type ActionType = 'codeGeneration' | 'sendMessage' | 'sendMessageWithImage' | 'requestPermissions' | 'requestFilesContent' | 'removeFilesFromContext' | 'confirmCodeGeneration' | 'cancelCodeGeneration' | 'contextOptimization' | 'searchCode' | 'lint' | PluginActionType;
4
+ export type ActionType = 'codeGeneration' | 'sendMessage' | 'sendMessageWithImage' | 'requestPermissions' | 'requestFilesContent' | 'removeFilesFromContext' | 'confirmCodeGeneration' | 'cancelCodeGeneration' | 'contextOptimization' | 'searchCode' | 'lint' | 'updateFile' | PluginActionType;
5
5
  type AskQuestionArgs = {
6
6
  actionType: ActionType;
7
7
  message: string;
@@ -5,7 +5,6 @@ import { handleRequestFilesContent } from './handlers/request-files-content.js';
5
5
  import { handleContextOptimization } from './handlers/context-optimization.js';
6
6
  import { handleRemoveFilesFromContext } from './handlers/remove-files-from-context.js';
7
7
  import { handleRequestPermissions } from './handlers/request-permissions.js';
8
- import { handleDefaultAction } from './handlers/default-action.js';
9
8
  import { handleSendMessage } from './handlers/handle-send-message.js';
10
9
  import { handleSendMessageWithImage } from './handlers/handle-send-message-with-image.js';
11
10
  import { handleConfirmCodeGeneration } from './handlers/confirm-code-generation.js';
@@ -14,6 +13,7 @@ import { handleLint } from './handlers/lint.js';
14
13
  import { getRegisteredActionHandlers } from '../../../main/plugin-loader.js';
15
14
  import { handleCodeGeneration } from './handlers/code-generation.js';
16
15
  import { handleSearchCode } from './handlers/handle-search-code.js';
16
+ import { handleUpdateFile } from './handlers/handle-update-file.js';
17
17
  export async function executeStepAskQuestion(generateContentFn, generateImageFn, prompt, functionDefs, waitIfPaused, temperature, options) {
18
18
  console.log('Allowing the assistant to ask a question...');
19
19
  while (!abortController?.signal.aborted) {
@@ -22,7 +22,6 @@ export async function executeStepAskQuestion(generateContentFn, generateImageFn,
22
22
  if (!askQuestionCall) {
23
23
  break;
24
24
  }
25
- console.log('Assistant asks:', askQuestionCall.args);
26
25
  if (askQuestionCall.args?.message) {
27
26
  // TODO: PromptItem should be included here, but a small refactor is needed to achieve this
28
27
  putAssistantMessage(askQuestionCall.args.message, askQuestionCall.args);
@@ -40,7 +39,9 @@ export async function executeStepAskQuestion(generateContentFn, generateImageFn,
40
39
  });
41
40
  // This is important to display the content to the user interface (ui or interactive cli)
42
41
  let lastItem = result.items.slice(-1)[0];
43
- putUserMessage(lastItem.user.text, lastItem.user.data, undefined, undefined, lastItem.user);
42
+ if (lastItem) {
43
+ putUserMessage(lastItem.user.text, lastItem.user.data, undefined, undefined, lastItem.user);
44
+ }
44
45
  prompt.push(...result.items.map(({ assistant, user }) => [assistant, user]).flat());
45
46
  if (result.executeCodegen) {
46
47
  result = await getActionHandler('codeGeneration')({
@@ -52,7 +53,9 @@ export async function executeStepAskQuestion(generateContentFn, generateImageFn,
52
53
  waitIfPaused,
53
54
  });
54
55
  lastItem = result.items.slice(-1)[0];
55
- putUserMessage(lastItem.user.text, undefined, undefined, undefined, lastItem.user);
56
+ if (lastItem) {
57
+ putUserMessage(lastItem.user.text, undefined, undefined, undefined, lastItem.user);
58
+ }
56
59
  prompt.push(...result.items.map(({ assistant, user }) => [assistant, user]).flat());
57
60
  }
58
61
  if (result.breakLoop) {
@@ -99,7 +102,8 @@ function getActionHandler(actionType) {
99
102
  searchCode: handleSearchCode,
100
103
  lint: handleLint,
101
104
  contextOptimization: handleContextOptimization,
105
+ updateFile: handleUpdateFile,
102
106
  };
103
- return handlers[actionType] || handleDefaultAction;
107
+ return handlers[actionType] || handleSendMessage;
104
108
  }
105
109
  //# sourceMappingURL=step-ask-question.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"step-ask-question.js","sourceRoot":"","sources":["../../../../src/prompt/steps/step-ask-question/step-ask-question.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC5G,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAE7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AACvF,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,E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EAAyE;IACzE,MAAM,aAAa,GAAG,2BAA2B,EAAE,CAAC,GAAG,CAAC,UAAgC,CAAC,CAAC;IAC1F,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,2DAA2D;IAC3D,MAAM,QAAQ,GAAsC;QAClD,cAAc,EAAE,oBAAoB;QACpC,oBAAoB,EAAE,0BAA0B;QAChD,qBAAqB,EAAE,2BAA2B;QAClD,mBAAmB,EAAE,yBAAyB;QAC9C,kBAAkB,EAAE,wBAAwB;QAC5C,sBAAsB,EAAE,4BAA4B;QACpD,WAAW,EAAE,iBAAiB;QAC9B,oBAAoB,EAAE,0BAA0B;QAChD,UAAU,EAAE,gBAAgB;QAC5B,IAAI,EAAE,UAAU;QAChB,mBAAmB,EAAE,yBAAyB;KAC/C,CAAC;IAEF,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,mBAAmB,CAAC;AACrD,CAAC"}
1
+ {"version":3,"file":"step-ask-question.js","sourceRoot":"","sources":["../../../../src/prompt/steps/step-ask-question/step-ask-question.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC5G,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAE7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AACvF,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AAC1F,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAu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AAa,CAAC;IACvB,CAAC;IAED,2DAA2D;IAC3D,MAAM,QAAQ,GAAsC;QAClD,cAAc,EAAE,oBAAoB;QACpC,oBAAoB,EAAE,0BAA0B;QAChD,qBAAqB,EAAE,2BAA2B;QAClD,mBAAmB,EAAE,yBAAyB;QAC9C,kBAAkB,EAAE,wBAAwB;QAC5C,sBAAsB,EAAE,4BAA4B;QACpD,WAAW,EAAE,iBAAiB;QAC9B,oBAAoB,EAAE,0BAA0B;QAChD,UAAU,EAAE,gBAAgB;QAC5B,IAAI,EAAE,UAAU;QAChB,mBAAmB,EAAE,yBAAyB;QAC9C,UAAU,EAAE,gBAAgB;KAC7B,CAAC;IAEF,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,iBAAiB,CAAC;AACnD,CAAC"}
@@ -3,6 +3,7 @@ import { putSystemMessage } from '../../main/common/content-bus.js';
3
3
  import { validateAndRecoverSingleResult } from './step-validate-recover.js';
4
4
  import { StepResult } from './steps-types.js';
5
5
  import { executeStepEnsureContext } from './step-ensure-context.js';
6
+ import { getRegisteredPlanningPreHooks, getRegisteredPlanningPostHooks } from '../../main/plugin-loader.js';
6
7
  export const PLANNING_PROMPT = `Please analyze the conversation so far and help plan the implementation:
7
8
 
8
9
  1. Review the conversation history and requirements
@@ -25,12 +26,14 @@ Output the plan using \`codegenPlanning\` function provding all the required fie
25
26
  */
26
27
  export async function executeStepCodegenPlanning(generateContentFn, prompt, options) {
27
28
  putSystemMessage('Starting codegen planning phase...');
29
+ // Execute pre-hooks to potentially modify the planning prompt
30
+ const modifiedPlanningPrompt = await executePlanningPreHooks(PLANNING_PROMPT, options);
28
31
  // Add the planning prompt to the conversation
29
32
  if (prompt.slice(-1)[0].type === 'user') {
30
- prompt.slice(-1)[0].text += '\n\\n' + PLANNING_PROMPT;
33
+ prompt.slice(-1)[0].text += '\\n\\n' + modifiedPlanningPrompt;
31
34
  }
32
35
  else {
33
- prompt.push({ type: 'user', text: PLANNING_PROMPT });
36
+ prompt.push({ type: 'user', text: modifiedPlanningPrompt });
34
37
  }
35
38
  const planningRequest = [
36
39
  prompt,
@@ -43,8 +46,10 @@ export async function executeStepCodegenPlanning(generateContentFn, prompt, opti
43
46
  try {
44
47
  let planningResult = await generateContentFn(...planningRequest);
45
48
  planningResult = await validateAndRecoverSingleResult(planningRequest, planningResult, generateContentFn);
46
- const codegenPlanningRequest = planningResult.find((call) => call.name === 'codegenPlanning');
49
+ let codegenPlanningRequest = planningResult.find((call) => call.name === 'codegenPlanning');
47
50
  if (codegenPlanningRequest) {
51
+ // Execute post-hooks to potentially modify the planning result
52
+ codegenPlanningRequest = await executePlanningPostHooks(codegenPlanningRequest, modifiedPlanningPrompt, options);
48
53
  putSystemMessage('Planning phase completed, ensuring context completeness...');
49
54
  // Ensure all necessary files are in context
50
55
  const contextResult = await executeStepEnsureContext(prompt, codegenPlanningRequest, options);
@@ -72,4 +77,59 @@ export async function executeStepCodegenPlanning(generateContentFn, prompt, opti
72
77
  return StepResult.BREAK;
73
78
  }
74
79
  }
80
+ /**
81
+ * Execute registered planning pre-hooks
82
+ * Returns modified prompt if any hook provides one, otherwise returns the original prompt
83
+ */
84
+ async function executePlanningPreHooks(originalPrompt, options) {
85
+ let modifiedPrompt = originalPrompt;
86
+ const preHooks = getRegisteredPlanningPreHooks();
87
+ if (preHooks.length > 0) {
88
+ putSystemMessage(`Executing ${preHooks.length} planning pre-hooks...`);
89
+ for (const hook of preHooks) {
90
+ try {
91
+ const result = await hook({
92
+ prompt: modifiedPrompt,
93
+ options,
94
+ });
95
+ if (result) {
96
+ modifiedPrompt = result;
97
+ }
98
+ }
99
+ catch (error) {
100
+ putSystemMessage(`Error in planning pre-hook: ${error.message}`);
101
+ console.error('Planning pre-hook error:', error);
102
+ }
103
+ }
104
+ }
105
+ return modifiedPrompt;
106
+ }
107
+ /**
108
+ * Execute registered planning post-hooks
109
+ * Returns modified result if any hook provides one, otherwise returns the original result
110
+ */
111
+ async function executePlanningPostHooks(originalResult, originalPrompt, options) {
112
+ let modifiedResult = originalResult;
113
+ const postHooks = getRegisteredPlanningPostHooks();
114
+ if (postHooks.length > 0) {
115
+ putSystemMessage(`Executing ${postHooks.length} planning post-hooks...`);
116
+ for (const hook of postHooks) {
117
+ try {
118
+ const result = await hook({
119
+ prompt: originalPrompt,
120
+ options,
121
+ result: modifiedResult,
122
+ });
123
+ if (result) {
124
+ modifiedResult = result;
125
+ }
126
+ }
127
+ catch (error) {
128
+ putSystemMessage(`Error in planning post-hook: ${error.message}`);
129
+ console.error('Planning post-hook error:', error);
130
+ }
131
+ }
132
+ }
133
+ return modifiedResult;
134
+ }
75
135
  //# sourceMappingURL=step-codegen-planning.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"step-codegen-planning.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-codegen-planning.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;qFAcsD,CAAC;AAEtF;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,iBAA0C,EAC1C,MAAoB,EACpB,OAAuB;IAEvB,gBAAgB,CAAC,oCAAoC,CAAC,CAAC;IAEvD,8CAA8C;IAC9C,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACxC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,OAAO,GAAG,eAAe,CAAC;IACxD,CAAC;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C,OAAO,KAAK,EAAE,CAAC;gBACf,gBAAgB,CAAC,+BAAgC,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;gBAC5E,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,wBAAwB,CACrC,cAAiD,EACjD,cAAsB,EACtB,OAAuB;IAEvB,IAAI,cAAc,GAAG,cAAc,CAAC;IACpC,MAAM,SAAS,GAAG,8BAA8B,EAAE,CAAC;IAEnD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,gBAAgB,CAAC,aAAa,SAAS,CAAC,MAAM,yBAAyB,CAAC,CAAC;QAEzE,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;YAC7B,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC;oBACxB,MAAM,EAAE,cAAc;oBACtB,OAAO;oBACP,MAAM,EAAE,cAAc;iBACvB,CAAC,CAAC;gBACH,IAAI,MAAM,EAAE,CAAC;oBACX,cAAc,GAAG,MAAM,CAAC;gBAC1B,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,gBAAgB,CAAC,gCAAiC,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;gBAC7E,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC"}
@@ -1,4 +1,7 @@
1
1
  import { GenerateContentFunction, PromptItem } from '../../ai-service/common.js';
2
2
  import { CodegenOptions } from '../../main/codegen-types.js';
3
3
  import { StepResult } from './steps-types.js';
4
+ export declare const OPTIMIZATION_PROMPT = "You need to analyze the provided source code files and determine their relevance to the user's prompt. You will then call the `optimizeContext` function with the results.\n\n**Crucially, only include files in the `optimizedContext` array of the `optimizeContext` function call if their calculated relevance score is 0.5 or greater.**\n\nHere are the detailed steps:\n\n1. **Relevance Assessment (Scores from 0.0 to 1.0):**\n - Evaluate the relevance of each file to the user's prompt based on the following scale:\n - 0.0 \u2013 0.3: Not Relevant\n - 0.3 \u2013 0.7: Somewhat Relevant\n - 0.7 \u2013 0.9: Moderately Relevant\n - 0.9 \u2013 1.0: Highly Relevant\n - Consider:\n - Directly implements the core logic required to address the prompt's features.\n - Role in dependency chains of relevant files.\n - Keyword matches with the prompt.\n - Importance as a dependency.\n\n2. **Dependency Consideration:**\n - Understand how files depend on each other.\n - Prioritize files that are directly relevant or are dependencies of highly relevant files.\n - When evaluating a file, consider its position within dependency chains, but **do not include a file in the `optimizedContext` if its individual relevance score is below 0.5, even if it's part of a dependency chain of a relevant file.**\n\n3. **Token Awareness:**\n - Be mindful of token usage, but **relevance (specifically a score of 0.5 or higher) is the primary criterion for inclusion in `optimizedContext`.**\n\n4. **Function Call - `optimizeContext`:**\n - Call the `optimizeContext` function with the following arguments:\n - `\"userPrompt\"`: The original user prompt.\n - `\"reasoning\"`: A detailed, step-by-step explanation of the thought process used to determine the optimized context.\n - `\"optimizedContext\"`: **An array containing ONLY files with a relevance score of 0.5 or higher.** Each object in the array should have:\n - `\"reasoning\"`: Specific reasoning for why *this particular file* is relevant and has a score of 0.5 or higher.\n - `\"filePath\"`: Absolute file path.\n - `\"relevance\"`: The calculated relevance score (0.5 to 1.0).\n\n**Important Guidelines:**\n\n- **Strict Filtering:** **Only files with a relevance score of 0.5 or more should be included in the `optimizedContext` array.**\n- **No Guessing:** Only use files provided in the `getSourceCode` response.\n- **Evaluate Individually and in Chains:** Consider both individual relevance and dependencies, but the 0.5 threshold is paramount for inclusion.\n- **Proper JSON:** Ensure the `optimizeContext` call is valid JSON.\n- **Full Paths:** Use absolute file paths.\n- **Focus on 0.5+:** The `optimizedContext` array should be exclusively populated with files meeting the relevance criteria.\n- **Handling Codebase-Wide Operations:**\n - If the user prompt indicates a codebase-wide operation, choose one of the following `optimizeContext` strategies:\n - **Empty Context:** For operations applying to all files simultaneously, call `optimizeContext` with an empty `optimizedContext` and explain in the `reasoning`.\n - **Main Entry Points:** For operations starting with key files, identify main entry points and call `optimizeContext` with these files (relevance=1.0), explaining in the `reasoning`.\n- **Data Flow Consideration**: Consider the entire lifecycle of the data involved in the user's request, from the user interface to the database and back. Include files involved in handling, storing, and transmitting this data.\n- **Intent and Contribution Analysis:** For each file, evaluate its purpose and how it contributes to fulfilling the user's prompt. Consider the flow of logic and data. Which files are essential for the requested outcome, not just tangentially related?\n- **Functional Web Analysis:** Think of the codebase as a web of interconnected functionalities. Identify the key functional areas involved in the user's prompt and trace the connections between files within these areas.\n- **Core Responsibility Assessment:** Identify the files that are primarily responsible for managing the lifecycle, data, or logic of the entities involved in the `userPrompt`. These files are likely to be highly relevant.\n- **Data Flow Mapping:** Trace the flow of data related to the user's request. Identify the files involved in creating, storing, transforming, and retrieving this data.\n\nNow, analyze the source code and call the `optimizeContext` function accordingly.";
5
+ export declare const OPTIMIZATION_TRIGGER_PROMPT = "Thank you for describing the task, I have noticed you have provided a very large context for your question. The amount of source code is very big in particular. Can we do something about it?";
6
+ export declare const CONTEXT_OPTIMIZATION_TEMPERATURE = 0.2;
4
7
  export declare function executeStepContextOptimization(generateContentFn: GenerateContentFunction, prompt: PromptItem[], options: CodegenOptions): Promise<StepResult>;
@@ -8,57 +8,62 @@ import { validateAndRecoverSingleResult } from './step-validate-recover.js';
8
8
  import { getSourceCodeResponse } from './steps-utils.js';
9
9
  import { getSourceCodeTree, parseSourceCodeTree } from '../../files/source-code-tree.js';
10
10
  import { importantContext } from '../../main/config.js';
11
- const OPTIMIZATION_PROMPT = `You're correct, we need to optimize the context for code generation. Please perform the following tasks and respond by calling the \`optimizeContext\` function with the appropriate arguments:
11
+ export const OPTIMIZATION_PROMPT = `You need to analyze the provided source code files and determine their relevance to the user's prompt. You will then call the \`optimizeContext\` function with the results.
12
12
 
13
- 1. **Relevance and Dependency Analysis**:
14
- - Rate the **relevance** of each file to the user's prompt on a scale from **0 to 1**, using the following guidelines:
15
- - **0.0 – 0.3 (Not Relevant)**: The file has no apparent connection to the user's prompt.
16
- - **0.3 – 0.7 (Somewhat Relevant)**: The file has minor or indirect relevance to the prompt.
17
- - **0.7 – 0.9 (Moderately Relevant)**: The file is related and could contribute to addressing the prompt.
18
- - **0.9 – 1.0 (Highly Relevant)**: The file is directly related and is important for addressing the prompt.
19
-
20
- - **Evaluation Criteria**:
21
- - **Direct Relevance**: Does the file directly implement features mentioned in the prompt?
22
- - **Dependency Chain**: Is the file part of a dependency chain of relevant files?
23
- - **Keyword Matching**: Does the file contain keywords or topics from the prompt?
24
- - **Dependency Importance**: Is the file a critical dependency for other relevant files?
13
+ **Crucially, only include files in the \`optimizedContext\` array of the \`optimizeContext\` function call if their calculated relevance score is 0.5 or greater.**
25
14
 
26
- 2. **Dependency-Aware Optimization**:
27
- - Consider both direct and indirect dependencies
28
- - Prioritize files that are:
29
- - Directly relevant to the prompt
30
- - Dependencies of highly relevant files
31
- - Part of important dependency chains
32
- - Handle dependency chains intelligently:
33
- - Include critical dependencies even if they seem less relevant
34
- - Consider the full dependency tree when evaluating relevance
35
- - Avoid breaking dependency chains of important files
15
+ Here are the detailed steps:
36
16
 
37
- 3. **Token-Aware Optimization**:
38
- - Balance relevance against token usage
39
- - Consider the combined token cost of dependency chains
40
- - Prioritize files where the relevance justifies the token usage
41
- - Consider the token cost of including entire dependency chains
17
+ 1. **Relevance Assessment (Scores from 0.0 to 1.0):**
18
+ - Evaluate the relevance of each file to the user's prompt based on the following scale:
19
+ - 0.0 – 0.3: Not Relevant
20
+ - 0.3 – 0.7: Somewhat Relevant
21
+ - 0.7 – 0.9: Moderately Relevant
22
+ - 0.9 – 1.0: Highly Relevant
23
+ - Consider:
24
+ - Directly implements the core logic required to address the prompt's features.
25
+ - Role in dependency chains of relevant files.
26
+ - Keyword matches with the prompt.
27
+ - Importance as a dependency.
42
28
 
43
- 4. **Function Call Response**:
44
- - Call the \`optimizeContext\` function with:
45
- - \`"userPrompt"\`: The original prompt
46
- - \`"optimizedContext"\`: Array of objects containing:
47
- - \`"filePath"\`: Absolute file path
48
- - \`"relevance"\`: Calculated relevance score (0 to 1)
29
+ 2. **Dependency Consideration:**
30
+ - Understand how files depend on each other.
31
+ - Prioritize files that are directly relevant or are dependencies of highly relevant files.
32
+ - When evaluating a file, consider its position within dependency chains, but **do not include a file in the \`optimizedContext\` if its individual relevance score is below 0.5, even if it's part of a dependency chain of a relevant file.**
49
33
 
50
- **Important Guidelines**:
51
- - **Only include files from \`getSourceCode\` response**
52
- - **Do not guess or infer additional files**
53
- - **Evaluate each file individually and as part of dependency chains**
54
- - **Consider both direct and indirect dependencies**
55
- - **Ensure proper JSON formatting**
56
- - **Include full file paths**
57
- - **Filter out low-relevance files (< 0.5)**
58
- - **Maintain dependency chain integrity**
34
+ 3. **Token Awareness:**
35
+ - Be mindful of token usage, but **relevance (specifically a score of 0.5 or higher) is the primary criterion for inclusion in \`optimizedContext\`.**
59
36
 
60
- Now could you please analyze the source code and return me the optimized context?
61
- `;
37
+ 4. **Function Call - \`optimizeContext\`:**
38
+ - Call the \`optimizeContext\` function with the following arguments:
39
+ - \`"userPrompt"\`: The original user prompt.
40
+ - \`"reasoning"\`: A detailed, step-by-step explanation of the thought process used to determine the optimized context.
41
+ - \`"optimizedContext"\`: **An array containing ONLY files with a relevance score of 0.5 or higher.** Each object in the array should have:
42
+ - \`"reasoning"\`: Specific reasoning for why *this particular file* is relevant and has a score of 0.5 or higher.
43
+ - \`"filePath"\`: Absolute file path.
44
+ - \`"relevance"\`: The calculated relevance score (0.5 to 1.0).
45
+
46
+ **Important Guidelines:**
47
+
48
+ - **Strict Filtering:** **Only files with a relevance score of 0.5 or more should be included in the \`optimizedContext\` array.**
49
+ - **No Guessing:** Only use files provided in the \`getSourceCode\` response.
50
+ - **Evaluate Individually and in Chains:** Consider both individual relevance and dependencies, but the 0.5 threshold is paramount for inclusion.
51
+ - **Proper JSON:** Ensure the \`optimizeContext\` call is valid JSON.
52
+ - **Full Paths:** Use absolute file paths.
53
+ - **Focus on 0.5+:** The \`optimizedContext\` array should be exclusively populated with files meeting the relevance criteria.
54
+ - **Handling Codebase-Wide Operations:**
55
+ - If the user prompt indicates a codebase-wide operation, choose one of the following \`optimizeContext\` strategies:
56
+ - **Empty Context:** For operations applying to all files simultaneously, call \`optimizeContext\` with an empty \`optimizedContext\` and explain in the \`reasoning\`.
57
+ - **Main Entry Points:** For operations starting with key files, identify main entry points and call \`optimizeContext\` with these files (relevance=1.0), explaining in the \`reasoning\`.
58
+ - **Data Flow Consideration**: Consider the entire lifecycle of the data involved in the user's request, from the user interface to the database and back. Include files involved in handling, storing, and transmitting this data.
59
+ - **Intent and Contribution Analysis:** For each file, evaluate its purpose and how it contributes to fulfilling the user's prompt. Consider the flow of logic and data. Which files are essential for the requested outcome, not just tangentially related?
60
+ - **Functional Web Analysis:** Think of the codebase as a web of interconnected functionalities. Identify the key functional areas involved in the user's prompt and trace the connections between files within these areas.
61
+ - **Core Responsibility Assessment:** Identify the files that are primarily responsible for managing the lifecycle, data, or logic of the entities involved in the \`userPrompt\`. These files are likely to be highly relevant.
62
+ - **Data Flow Mapping:** Trace the flow of data related to the user's request. Identify the files involved in creating, storing, transforming, and retrieving this data.
63
+
64
+ Now, analyze the source code and call the \`optimizeContext\` function accordingly.`;
65
+ export const OPTIMIZATION_TRIGGER_PROMPT = 'Thank you for describing the task, I have noticed you have provided a very large context for your question. The amount of source code is very big in particular. Can we do something about it?';
66
+ export const CONTEXT_OPTIMIZATION_TEMPERATURE = 0.2;
62
67
  const MAX_TOTAL_TOKENS = 10000;
63
68
  export async function executeStepContextOptimization(generateContentFn, prompt, options) {
64
69
  const fullSourceCode = getSourceCode({ forceAll: true }, options);
@@ -80,14 +85,21 @@ export async function executeStepContextOptimization(generateContentFn, prompt,
80
85
  ...prompt,
81
86
  {
82
87
  type: 'assistant',
83
- text: 'Thank you for describing the task, I have noticed you have provided a very large context for your question. The amount of source code is very big in particular. Can we do something about it?',
88
+ text: OPTIMIZATION_TRIGGER_PROMPT,
84
89
  },
85
90
  {
86
91
  type: 'user',
87
92
  text: OPTIMIZATION_PROMPT,
88
93
  },
89
94
  ];
90
- const request = [optimizationPrompt, getFunctionDefs(), 'optimizeContext', 0.2, true, options];
95
+ const request = [
96
+ optimizationPrompt,
97
+ getFunctionDefs(),
98
+ 'optimizeContext',
99
+ CONTEXT_OPTIMIZATION_TEMPERATURE,
100
+ true,
101
+ options,
102
+ ];
91
103
  let result = await generateContentFn(...request);
92
104
  result = await validateAndRecoverSingleResult(request, result, generateContentFn);
93
105
  const [optimizedContext, irrelevantFiles] = parseOptimizationResult(fullSourceCode, result);
@@ -96,7 +108,7 @@ export async function executeStepContextOptimization(generateContentFn, prompt,
96
108
  return StepResult.BREAK;
97
109
  }
98
110
  if (optimizedContext.length === 0) {
99
- putSystemMessage('Warning: Context optimization failed to produce useful summaries for all batches. Proceeding with current context.');
111
+ putSystemMessage('Context optimization did not generate changes to current context.');
100
112
  return StepResult.CONTINUE;
101
113
  }
102
114
  putSystemMessage('Context optimization in progress.', Array.from(optimizedContext));
@@ -224,7 +236,9 @@ function optimizeSourceCode(sourceCode, fullSourceCode, optimizedContext, irrele
224
236
  const summary = getSummary(path);
225
237
  const content = (fullSourceCode[path] && 'content' in fullSourceCode[path] ? fullSourceCode[path]?.content : undefined) ?? null;
226
238
  const dependencies = fullSourceCode[path] && 'dependencies' in fullSourceCode[path] ? fullSourceCode[path]?.dependencies : undefined;
227
- if (isRequired && content && !(sourceCode[path] && 'content' in sourceCode[path])) {
239
+ if (isRequired &&
240
+ content &&
241
+ !(sourceCode[path] && 'content' in sourceCode[path] && sourceCode[path].content !== null)) {
228
242
  contentTokenCount += estimateTokenCount(content);
229
243
  optimizedSourceCode[path] = {
230
244
  content,