genaicode 0.11.1 → 0.12.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 (210) hide show
  1. package/README.md +3 -9
  2. package/dist/ai-service/ai-studio.d.ts +18 -1
  3. package/dist/ai-service/ai-studio.js +92 -21
  4. package/dist/ai-service/ai-studio.js.map +1 -1
  5. package/dist/ai-service/anthropic.js +59 -25
  6. package/dist/ai-service/anthropic.js.map +1 -1
  7. package/dist/ai-service/common-types.d.ts +8 -3
  8. package/dist/ai-service/common.d.ts +5 -1
  9. package/dist/ai-service/common.js +9 -0
  10. package/dist/ai-service/common.js.map +1 -1
  11. package/dist/ai-service/dall-e.js +1 -0
  12. package/dist/ai-service/dall-e.js.map +1 -1
  13. package/dist/ai-service/github-models.d.ts +13 -0
  14. package/dist/ai-service/github-models.js +51 -0
  15. package/dist/ai-service/github-models.js.map +1 -0
  16. package/dist/ai-service/local-llm.js +2 -1
  17. package/dist/ai-service/local-llm.js.map +1 -1
  18. package/dist/ai-service/openai-responses.d.ts +9 -0
  19. package/dist/ai-service/openai-responses.js +286 -0
  20. package/dist/ai-service/openai-responses.js.map +1 -0
  21. package/dist/ai-service/openai.js +22 -10
  22. package/dist/ai-service/openai.js.map +1 -1
  23. package/dist/ai-service/service-configurations-types.d.ts +7 -7
  24. package/dist/ai-service/service-configurations.d.ts +1 -0
  25. package/dist/ai-service/service-configurations.js +41 -36
  26. package/dist/ai-service/service-configurations.js.map +1 -1
  27. package/dist/ai-service/vertex-ai-claude.js +2 -2
  28. package/dist/ai-service/vertex-ai-claude.js.map +1 -1
  29. package/dist/ai-service/vertex-ai.d.ts +1 -0
  30. package/dist/ai-service/vertex-ai.js +4 -332
  31. package/dist/ai-service/vertex-ai.js.map +1 -1
  32. package/dist/cli/cli-options.js +1 -1
  33. package/dist/cli/cli-options.js.map +1 -1
  34. package/dist/cli/validate-cli-params.js +1 -1
  35. package/dist/cli/validate-cli-params.js.map +1 -1
  36. package/dist/files/cache-file.d.ts +4 -0
  37. package/dist/files/cache-file.js +21 -0
  38. package/dist/files/cache-file.js.map +1 -1
  39. package/dist/files/find-files.d.ts +1 -0
  40. package/dist/files/find-files.js +4 -1
  41. package/dist/files/find-files.js.map +1 -1
  42. package/dist/files/source-code-utils.js +1 -1
  43. package/dist/files/summary-cache.d.ts +1 -1
  44. package/dist/files/summary-cache.js +1 -1
  45. package/dist/files/summary-cache.js.map +1 -1
  46. package/dist/main/codegen-utils.d.ts +6 -1
  47. package/dist/main/codegen-utils.js +21 -2
  48. package/dist/main/codegen-utils.js.map +1 -1
  49. package/dist/main/codegen.js +2 -2
  50. package/dist/main/codegen.js.map +1 -1
  51. package/dist/main/common/content-bus-types.d.ts +17 -1
  52. package/dist/main/common/content-bus.d.ts +3 -1
  53. package/dist/main/common/content-bus.js +23 -1
  54. package/dist/main/common/content-bus.js.map +1 -1
  55. package/dist/main/common/user-actions.d.ts +3 -0
  56. package/dist/main/common/user-actions.js +10 -0
  57. package/dist/main/common/user-actions.js.map +1 -1
  58. package/dist/main/config-lib.js +3 -2
  59. package/dist/main/config-lib.js.map +1 -1
  60. package/dist/main/config-types.d.ts +4 -0
  61. package/dist/main/config.js +4 -0
  62. package/dist/main/config.js.map +1 -1
  63. package/dist/main/interactive/select-ai-service.js +0 -1
  64. package/dist/main/interactive/select-ai-service.js.map +1 -1
  65. package/dist/main/interactive/user-action-handlers.js +7 -2
  66. package/dist/main/interactive/user-action-handlers.js.map +1 -1
  67. package/dist/main/knowledge/knowledge-store.d.ts +6 -0
  68. package/dist/main/knowledge/knowledge-store.js +128 -0
  69. package/dist/main/knowledge/knowledge-store.js.map +1 -0
  70. package/dist/main/knowledge/types.d.ts +20 -0
  71. package/dist/main/knowledge/types.js +2 -0
  72. package/dist/main/knowledge/types.js.map +1 -0
  73. package/dist/main/ui/backend/endpoints/interrupt-execution-endpoint.js +17 -3
  74. package/dist/main/ui/backend/endpoints/interrupt-execution-endpoint.js.map +1 -1
  75. package/dist/main/ui/common/api-types.d.ts +67 -4
  76. package/dist/main/ui/common/api-types.js +12 -1
  77. package/dist/main/ui/common/api-types.js.map +1 -1
  78. package/dist/main/ui/frontend/assets/index-j9Oi9iiP.js +2635 -0
  79. package/dist/main/ui/frontend/index.html +1 -1
  80. package/dist/main/ui/user-action-handlers.js +7 -1
  81. package/dist/main/ui/user-action-handlers.js.map +1 -1
  82. package/dist/project-profiles/types.d.ts +4 -4
  83. package/dist/project-profiles/types.js +4 -4
  84. package/dist/project-profiles/types.js.map +1 -1
  85. package/dist/prompt/function-calling-validate.js +2 -1
  86. package/dist/prompt/function-calling-validate.js.map +1 -1
  87. package/dist/prompt/function-calling.js +4 -0
  88. package/dist/prompt/function-calling.js.map +1 -1
  89. package/dist/prompt/function-defs/ask-question.js +4 -0
  90. package/dist/prompt/function-defs/ask-question.js.map +1 -1
  91. package/dist/prompt/function-defs/container-task-commands.d.ts +10 -0
  92. package/dist/prompt/function-defs/container-task-commands.js +185 -0
  93. package/dist/prompt/function-defs/container-task-commands.js.map +1 -0
  94. package/dist/prompt/function-defs/run-container-task.d.ts +11 -0
  95. package/dist/prompt/function-defs/run-container-task.js +41 -0
  96. package/dist/prompt/function-defs/run-container-task.js.map +1 -0
  97. package/dist/prompt/function-defs/web-search.d.ts +9 -0
  98. package/dist/prompt/function-defs/web-search.js +16 -0
  99. package/dist/prompt/function-defs/web-search.js.map +1 -0
  100. package/dist/prompt/limits.js +1 -1
  101. package/dist/prompt/steps/step-ask-question/handlers/container-task/command-execution-loop.d.ts +7 -0
  102. package/dist/prompt/steps/step-ask-question/handlers/container-task/command-execution-loop.js +301 -0
  103. package/dist/prompt/steps/step-ask-question/handlers/container-task/command-execution-loop.js.map +1 -0
  104. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/check-context.d.ts +12 -0
  105. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/check-context.js +41 -0
  106. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/check-context.js.map +1 -0
  107. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/complete-task.d.ts +4 -0
  108. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/complete-task.js +49 -0
  109. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/complete-task.js.map +1 -0
  110. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/copy-from-container.d.ts +4 -0
  111. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/copy-from-container.js +190 -0
  112. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/copy-from-container.js.map +1 -0
  113. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/copy-to-container.d.ts +4 -0
  114. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/copy-to-container.js +139 -0
  115. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/copy-to-container.js.map +1 -0
  116. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/edit-file.d.ts +10 -0
  117. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/edit-file.js +93 -0
  118. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/edit-file.js.map +1 -0
  119. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/fail-task.d.ts +4 -0
  120. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/fail-task.js +72 -0
  121. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/fail-task.js.map +1 -0
  122. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/gain-knowledge.d.ts +10 -0
  123. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/gain-knowledge.js +125 -0
  124. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/gain-knowledge.js.map +1 -0
  125. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/interrupt-controller.d.ts +19 -0
  126. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/interrupt-controller.js +33 -0
  127. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/interrupt-controller.js.map +1 -0
  128. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/query-knowledge.d.ts +8 -0
  129. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/query-knowledge.js +85 -0
  130. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/query-knowledge.js.map +1 -0
  131. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/request-secret.d.ts +6 -0
  132. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/request-secret.js +122 -0
  133. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/request-secret.js.map +1 -0
  134. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/run-command.d.ts +7 -0
  135. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/run-command.js +146 -0
  136. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/run-command.js.map +1 -0
  137. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/send-message.d.ts +4 -0
  138. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/send-message.js +56 -0
  139. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/send-message.js.map +1 -0
  140. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/set-execution-plan.d.ts +4 -0
  141. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/set-execution-plan.js +56 -0
  142. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/set-execution-plan.js.map +1 -0
  143. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/update-execution-plan.d.ts +4 -0
  144. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/update-execution-plan.js +39 -0
  145. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/update-execution-plan.js.map +1 -0
  146. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/view-file.d.ts +10 -0
  147. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/view-file.js +95 -0
  148. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/view-file.js.map +1 -0
  149. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/web-search.d.ts +2 -0
  150. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/web-search.js +96 -0
  151. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/web-search.js.map +1 -0
  152. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/wrap-context.d.ts +4 -0
  153. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/wrap-context.js +123 -0
  154. package/dist/prompt/steps/step-ask-question/handlers/container-task/commands/wrap-context.js.map +1 -0
  155. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-command-handlers.d.ts +34 -0
  156. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-command-handlers.js +332 -0
  157. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-command-handlers.js.map +1 -0
  158. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-registry.d.ts +11 -0
  159. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-registry.js +50 -0
  160. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-registry.js.map +1 -0
  161. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-types.d.ts +28 -0
  162. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-types.js +2 -0
  163. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-commands-types.js.map +1 -0
  164. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-task-orchestrator.d.ts +2 -0
  165. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-task-orchestrator.js +202 -0
  166. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-task-orchestrator.js.map +1 -0
  167. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-task-types.d.ts +52 -0
  168. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-task-types.js +2 -0
  169. package/dist/prompt/steps/step-ask-question/handlers/container-task/container-task-types.js.map +1 -0
  170. package/dist/prompt/steps/step-ask-question/handlers/container-task/utils/docker-check.d.ts +4 -0
  171. package/dist/prompt/steps/step-ask-question/handlers/container-task/utils/docker-check.js +15 -0
  172. package/dist/prompt/steps/step-ask-question/handlers/container-task/utils/docker-check.js.map +1 -0
  173. package/dist/prompt/steps/step-ask-question/handlers/container-task/utils/docker-utils.d.ts +50 -0
  174. package/dist/prompt/steps/step-ask-question/handlers/container-task/utils/docker-utils.js +358 -0
  175. package/dist/prompt/steps/step-ask-question/handlers/container-task/utils/docker-utils.js.map +1 -0
  176. package/dist/prompt/steps/step-ask-question/handlers/handle-compound-action.js +2 -2
  177. package/dist/prompt/steps/step-ask-question/handlers/handle-compound-action.js.map +1 -1
  178. package/dist/prompt/steps/step-ask-question/handlers/handle-explore-external-directories.js +1 -1
  179. package/dist/prompt/steps/step-ask-question/handlers/handle-explore-external-directories.js.map +1 -1
  180. package/dist/prompt/steps/step-ask-question/handlers/handle-genaicode-help.js +1 -1
  181. package/dist/prompt/steps/step-ask-question/handlers/handle-genaicode-help.js.map +1 -1
  182. package/dist/prompt/steps/step-ask-question/handlers/handle-generate-image.js +2 -2
  183. package/dist/prompt/steps/step-ask-question/handlers/handle-generate-image.js.map +1 -1
  184. package/dist/prompt/steps/step-ask-question/handlers/handle-perform-analysis.js +1 -1
  185. package/dist/prompt/steps/step-ask-question/handlers/handle-perform-analysis.js.map +1 -1
  186. package/dist/prompt/steps/step-ask-question/handlers/handle-run-container-task.d.ts +2 -0
  187. package/dist/prompt/steps/step-ask-question/handlers/handle-run-container-task.js +7 -0
  188. package/dist/prompt/steps/step-ask-question/handlers/handle-run-container-task.js.map +1 -0
  189. package/dist/prompt/steps/step-ask-question/handlers/handle-send-message.js +1 -1
  190. package/dist/prompt/steps/step-ask-question/handlers/handle-send-message.js.map +1 -1
  191. package/dist/prompt/steps/step-ask-question/handlers/handle-web-search.d.ts +1 -0
  192. package/dist/prompt/steps/step-ask-question/handlers/handle-web-search.js +85 -0
  193. package/dist/prompt/steps/step-ask-question/handlers/handle-web-search.js.map +1 -0
  194. package/dist/prompt/steps/step-ask-question/step-ask-question-types.d.ts +1 -1
  195. package/dist/prompt/steps/step-ask-question/step-ask-question.d.ts +2 -0
  196. package/dist/prompt/steps/step-ask-question/step-ask-question.js +11 -1
  197. package/dist/prompt/steps/step-ask-question/step-ask-question.js.map +1 -1
  198. package/dist/prompt/steps/step-codegen-planning.js +1 -1
  199. package/dist/prompt/steps/step-codegen-planning.js.map +1 -1
  200. package/dist/prompt/steps/step-summarization.js +17 -10
  201. package/dist/prompt/steps/step-summarization.js.map +1 -1
  202. package/dist/prompt/systemprompt.js +3 -0
  203. package/dist/prompt/systemprompt.js.map +1 -1
  204. package/dist/utils/docker-utils.d.ts +37 -0
  205. package/dist/utils/docker-utils.js +258 -0
  206. package/dist/utils/docker-utils.js.map +1 -0
  207. package/dist/vite-genaicode/vite-genaicode-plugin.js +8 -1
  208. package/dist/vite-genaicode/vite-genaicode-plugin.js.map +1 -1
  209. package/package.json +13 -5
  210. package/dist/main/ui/frontend/assets/index-DylPpHEw.js +0 -2256
@@ -0,0 +1,301 @@
1
+ import { ModelType, } from '../../../../../ai-service/common-types.js';
2
+ import { putAssistantMessage, putContainerLog, putSystemMessage, putUserMessage, } from '../../../../../main/common/content-bus.js';
3
+ import { abortController } from '../../../../../main/common/abort-controller.js';
4
+ import { getContainerCommandDefs, getContainerCommandHandler } from './container-commands-registry.js';
5
+ import { rcConfig } from '../../../../../main/config.js';
6
+ import { clearInterruption, isInterrupted } from './commands/interrupt-controller.js';
7
+ import { askUserForInput } from '../../../../../main/common/user-actions.js';
8
+ import { sanitizePrompt } from './commands/request-secret.js';
9
+ import { maybeQueryKnowledge } from './commands/query-knowledge.js';
10
+ import { maybeGainKnowledge } from './commands/gain-knowledge.js';
11
+ import { maybeWrapContext } from './commands/wrap-context.js';
12
+ const MAX_CONTEXT_ITEMS = 50;
13
+ const MAX_CONTEXT_SIZE = 2048;
14
+ const MAX_OUTPUT_LENGTH = 2048;
15
+ export async function commandExecutionLoop(args, container, taskDescription, unsanitizedGenerateContentFn, options, waitIfPaused) {
16
+ let success = false;
17
+ let summary = '';
18
+ const maxCommands = 200;
19
+ const taskExecutionPrompt = [];
20
+ const isAborted = () => abortController?.signal.aborted === true;
21
+ const generateContentFn = (prompt, ...args) => unsanitizedGenerateContentFn(sanitizePrompt(prompt), ...args);
22
+ const systemPrompt = {
23
+ type: 'systemPrompt',
24
+ systemPrompt: `You are Genaicode, an expert system operator inside a Docker container. Your task is to complete the objective by executing shell commands. You help the user achieve their goals given the superpower of running bash in secure Docker container environment, which allows you to do anything you want or what is needed. Starting from running basic commands, through creating new files and directories, to installing software and configuring the environment.
25
+
26
+ Best Practices:
27
+ - Be efficient: Plan your approach and minimize unnecessary commands. Write down your plan, keep it up to date.
28
+ - Be incremental: Check results after each command before proceeding
29
+ - Be concise: Keep command outputs focused on the task
30
+ - Be mindful: Avoid generating excessive output that could overflow context
31
+ - Be adaptive: Adjust your strategy based on command results, including failures.
32
+ - Be meticulous: Pay attention to detail and ensure accuracy in all commands and responses.
33
+ - Don't give up: If a command fails, analyze the output and try to find a solution.
34
+ - Use reasoning: Provide clear reasoning for each command you execute.
35
+ - FFS! Communicate! It means you should keep the user informed about what you are doing and why, and adjust your approach based on their feedback.
36
+ - Don't be passive aggressive, it doesn't help anyone. Help the user achieve their goals, even if you encounter obstacles.
37
+ - Let the user have a life, outside of this task, and avoid unnecessary interruptions, or bothering them with irrelevant details, especially if you can find a solution without involving them.
38
+ - SFTU! You have the possibility to search the web for solutions or information.
39
+ - Be careful about secrets and sensitive information, never expose them in your commands or outputs.
40
+ - Reuse existing knowledge and solutions from the knowledge base to avoid reinventing the wheel.
41
+ - Every corrected mistake, fixed problem, or learned lesson - no matter how small - may be worth documenting in the knowledge base.
42
+
43
+ You have access to the following functions:
44
+ - runCommand: Execute a shell command in the container, and wait for the result. Execute only non-interactive commands, otherwise you will wait indefinitely!
45
+ - completeTask: Mark the task as successfully completed with a summary
46
+ - failTask: Mark the task as failed with a reason
47
+ - setExecutionPlan: Record a brief plan to follow.
48
+ - updateExecutionPlan: Update plan progress and next steps.
49
+ - copyToContainer: Copy a file or directory from the host to the container. The hostPath must be absolute path container within project root.
50
+ - copyFromContainer: Copy a file or directory from the container to the host. The hostPath must be absolute path container within project root.
51
+ - sendMessage: Use it to communicate with the user, either to inform them about something, or ask them a question, or answer their question. Think if asking user about something is really necessary before doing it (maybe you can find the answer yourself?)
52
+ - webSearch: Perform a web search given an exhaustive prompt. Return a concise, grounded answer and a list of source URLs used. The answer is not displayed to the user. It should be used to inform following actions.
53
+ - requestSecret: Ask the user to provide a secret value (e.g. API key) and write it to a specified file path in the container. The file path must be absolute path within the container.
54
+ - gainKnowledge: Persist a new knowledge entry in the knowledge base capturing a prompt, its answer/insight, and optional metadata. Use this to record successful operations, solutions to problems, or any other valuable information that could help in future tasks. Avoid storing secrets.
55
+ - queryKnowledge: Query the knowledge base with a natural language prompt to find relevant information from past tasks. Use this to check for existing solutions before attempting a complex step.
56
+
57
+ You may also provide reasoning text before function calls to explain your approach or analyze the current situation.
58
+
59
+ The container starts fresh with a clean state and no prior context. You need to setup the container to perform the task described in the user prompt.
60
+ If the task requires current project source code(located in ${rcConfig.rootDir}) then you may need to copy it from host to the container.
61
+ Outcomes of your work can be provided in two ways back to the current project:
62
+ - Provide comprehensive description of the outcome in completeTask function call.
63
+ - Copy the relevant files or directories from the container to the host using copyFromContainer function call.
64
+ `,
65
+ };
66
+ const taskPrompt = {
67
+ type: 'user',
68
+ text: `Overall Task:
69
+ ${taskDescription}
70
+
71
+ Environment:
72
+ - Docker CLI is not available in the environment.
73
+ - Docker image used in the contianer: ${args.image}
74
+ - Working directory: ${args.workingDir}
75
+
76
+ Begin by analyzing the task and formulating your approach. Then start executing commands to complete it.`,
77
+ };
78
+ await maybeQueryKnowledge({
79
+ actionResult: { name: 'queryKnowledge' }, // Placeholder, ignored by maybeQueryKnowledge
80
+ taskExecutionPrompt,
81
+ systemPrompt,
82
+ taskPrompt,
83
+ generateContentFn,
84
+ container,
85
+ options,
86
+ maxContextItems: MAX_CONTEXT_ITEMS,
87
+ maxContextSize: MAX_CONTEXT_SIZE,
88
+ maxOutputLength: MAX_OUTPUT_LENGTH,
89
+ });
90
+ let commandsExecuted = 0;
91
+ let periodicQueryPromise = null;
92
+ for (let i = 0; i < maxCommands; i++) {
93
+ try {
94
+ if (periodicQueryPromise) {
95
+ await periodicQueryPromise;
96
+ periodicQueryPromise = null;
97
+ }
98
+ if (isAborted()) {
99
+ putContainerLog('warn', 'Task cancelled by user. Exiting command loop.');
100
+ summary = 'Task cancelled by user';
101
+ break;
102
+ }
103
+ await waitIfPaused();
104
+ if (isInterrupted()) {
105
+ clearInterruption();
106
+ putSystemMessage('Task interrupted, waiting for user input');
107
+ putAssistantMessage('What would you like to do?');
108
+ const response = await askUserForInput('Your answer', '', options);
109
+ const item = {
110
+ type: 'user',
111
+ text: response.answer,
112
+ images: response.images,
113
+ };
114
+ putUserMessage(response.answer ?? '', undefined, undefined, response.images, item);
115
+ taskExecutionPrompt.push(item);
116
+ }
117
+ if (i > 0 &&
118
+ i % 10 === 0 &&
119
+ !taskExecutionPrompt.find((item) => item.functionCalls?.some((fc) => fc.name === 'queryKnowledge'))) {
120
+ periodicQueryPromise = maybeQueryKnowledge({
121
+ actionResult: { name: 'queryKnowledge' }, // Placeholder
122
+ taskExecutionPrompt,
123
+ systemPrompt,
124
+ taskPrompt,
125
+ generateContentFn,
126
+ container,
127
+ options,
128
+ maxContextItems: MAX_CONTEXT_ITEMS,
129
+ maxContextSize: MAX_CONTEXT_SIZE,
130
+ maxOutputLength: MAX_OUTPUT_LENGTH,
131
+ }).catch((err) => {
132
+ putContainerLog('error', 'Periodic knowledge query failed in background', {
133
+ error: err instanceof Error ? err.message : String(err),
134
+ });
135
+ });
136
+ }
137
+ if (i === maxCommands - 10) {
138
+ taskExecutionPrompt.push({
139
+ type: 'user',
140
+ text: `[context] nearing command limit of ${maxCommands}! 10 commands remaining! Start finishing up.`,
141
+ });
142
+ }
143
+ await maybeWrapContext(systemPrompt, taskPrompt, taskExecutionPrompt, generateContentFn, container, options);
144
+ if (isAborted()) {
145
+ putContainerLog('warn', 'Task cancelled by user before model call.');
146
+ summary = 'Task cancelled by user';
147
+ break;
148
+ }
149
+ const modelResponse = await generateContentFn([systemPrompt, taskPrompt, ...taskExecutionPrompt], {
150
+ functionDefs: getContainerCommandDefs(),
151
+ temperature: 0.7,
152
+ modelType: taskExecutionPrompt.length <= 2
153
+ ? ModelType.DEFAULT
154
+ : taskExecutionPrompt.length <= 5
155
+ ? ModelType.CHEAP
156
+ : ModelType.LITE,
157
+ expectedResponseType: {
158
+ text: false,
159
+ functionCall: true,
160
+ media: false,
161
+ },
162
+ }, options);
163
+ if (isAborted()) {
164
+ putContainerLog('warn', 'Task cancelled by user after model call.');
165
+ summary = 'Task cancelled by user';
166
+ break;
167
+ }
168
+ const actionResults = modelResponse
169
+ .filter((item) => item.type === 'functionCall')
170
+ .map((item) => item.functionCall);
171
+ if (!actionResults || actionResults.length === 0) {
172
+ putContainerLog('error', 'Internal LLM failed to produce a valid function call.');
173
+ taskExecutionPrompt.push({
174
+ type: 'assistant',
175
+ text: 'I could not determine a valid action to take.',
176
+ }, {
177
+ type: 'user',
178
+ text: 'Please try again.',
179
+ });
180
+ continue;
181
+ }
182
+ let shouldBreakOuter = false;
183
+ for (const actionResult of actionResults) {
184
+ if (actionResult.name === 'runCommand' && commandsExecuted >= maxCommands) {
185
+ putContainerLog('warn', 'Reached maximum command limit.');
186
+ putSystemMessage('⚠️ Task incomplete: Reached maximum command limit');
187
+ summary = 'Task incomplete: Reached maximum command limit';
188
+ shouldBreakOuter = true;
189
+ break;
190
+ }
191
+ const handler = getContainerCommandHandler(actionResult.name);
192
+ if (!handler) {
193
+ putContainerLog('warn', `Unknown function call received: ${actionResult.name}`);
194
+ taskExecutionPrompt.push({
195
+ type: 'user',
196
+ functionResponses: [
197
+ {
198
+ name: actionResult.name,
199
+ call_id: actionResult.id || undefined,
200
+ content: `Unknown function call: ${actionResult.name}`,
201
+ },
202
+ ],
203
+ });
204
+ continue;
205
+ }
206
+ const handlerProps = {
207
+ actionResult,
208
+ systemPrompt,
209
+ taskPrompt,
210
+ taskExecutionPrompt,
211
+ container,
212
+ options,
213
+ generateContentFn,
214
+ maxContextItems: MAX_CONTEXT_ITEMS,
215
+ maxContextSize: MAX_CONTEXT_SIZE,
216
+ maxOutputLength: MAX_OUTPUT_LENGTH,
217
+ };
218
+ const handlerResult = await handler(handlerProps);
219
+ if (handlerResult) {
220
+ if (handlerResult.success !== undefined)
221
+ success = handlerResult.success;
222
+ if (handlerResult.summary !== undefined)
223
+ summary = handlerResult.summary;
224
+ commandsExecuted += handlerResult.commandsExecutedIncrement ?? 0;
225
+ if (handlerResult.shouldBreakOuter) {
226
+ shouldBreakOuter = true;
227
+ break;
228
+ }
229
+ }
230
+ }
231
+ if (shouldBreakOuter) {
232
+ break;
233
+ }
234
+ }
235
+ catch (error) {
236
+ const errorMessage = error instanceof Error ? error.message : String(error);
237
+ putContainerLog('error', 'Error during command execution loop', { error: errorMessage });
238
+ putSystemMessage('❌ Error during command execution loop', { error: errorMessage });
239
+ summary = `Task failed: Error during execution - ${errorMessage}`;
240
+ break;
241
+ }
242
+ }
243
+ maybeGainKnowledge({
244
+ actionResult: {
245
+ name: 'gainKnowledge', // Placeholder
246
+ },
247
+ systemPrompt,
248
+ taskPrompt,
249
+ taskExecutionPrompt,
250
+ generateContentFn,
251
+ container,
252
+ options,
253
+ maxContextItems: MAX_CONTEXT_ITEMS,
254
+ maxContextSize: MAX_CONTEXT_SIZE,
255
+ maxOutputLength: MAX_OUTPUT_LENGTH,
256
+ taskDescription,
257
+ summary,
258
+ }).catch((err) => {
259
+ putContainerLog('error', 'maybeGainKnowledge failed in background', {
260
+ error: err instanceof Error ? err.message : String(err),
261
+ });
262
+ });
263
+ try {
264
+ const modelResponse = await generateContentFn([
265
+ systemPrompt,
266
+ taskPrompt,
267
+ ...taskExecutionPrompt,
268
+ {
269
+ type: 'user',
270
+ text: 'Please provide a concise summary of the outcomes of the task',
271
+ },
272
+ ], {
273
+ functionDefs: getContainerCommandDefs(),
274
+ temperature: 0.7,
275
+ modelType: ModelType.LITE,
276
+ expectedResponseType: {
277
+ text: true,
278
+ functionCall: false,
279
+ media: false,
280
+ },
281
+ }, options);
282
+ for (const item of modelResponse) {
283
+ if (item.type === 'text' && item.text) {
284
+ const text = item.text.length > 1000 ? item.text.substring(0, 1000) + '...' : item.text;
285
+ putContainerLog('info', 'Final wrap-up summary from the model', { text });
286
+ summary = text;
287
+ break;
288
+ }
289
+ }
290
+ }
291
+ catch (error) {
292
+ putContainerLog('error', 'Error during post-loop wrap-up', {
293
+ error: error instanceof Error ? error.message : String(error),
294
+ });
295
+ }
296
+ if (!summary) {
297
+ summary = success ? 'Task completed' : 'Task failed or incomplete';
298
+ }
299
+ return { success, summary };
300
+ }
301
+ //# sourceMappingURL=command-execution-loop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-execution-loop.js","sourceRoot":"","sources":["../../../../../../src/prompt/steps/step-ask-question/handlers/container-task/command-execution-loop.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,SAAS,GAEV,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,cAAc,GACf,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAC;AAEjF,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAEvG,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO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AC,IAAI;YACzB,oBAAoB,EAAE;gBACpB,IAAI,EAAE,IAAI;gBACV,YAAY,EAAE,KAAK;gBACnB,KAAK,EAAE,KAAK;aACb;SACF,EACD,OAAO,CACR,CAAC;QACF,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;YACjC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBACtC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;gBACxF,eAAe,CAAC,MAAM,EAAE,sCAAsC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC1E,OAAO,GAAG,IAAI,CAAC;gBACf,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,eAAe,CAAC,OAAO,EAAE,gCAAgC,EAAE;YACzD,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC9D,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,2BAA2B,CAAC;IACrE,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { FunctionDef } from '../../../../../../ai-service/common-types.js';
2
+ import { CommandHandlerBaseProps, CommandHandlerResult } from '../container-commands-types.js';
3
+ export declare const checkContextDef: FunctionDef;
4
+ export interface CheckContextProps extends CommandHandlerBaseProps {
5
+ computeContextMetrics: () => {
6
+ messageCount: number;
7
+ estimatedTokens: number;
8
+ };
9
+ maxContextItems: number;
10
+ maxContextSize: number;
11
+ }
12
+ export declare function handleCheckContext({ actionResult, taskExecutionPrompt, computeContextMetrics, maxContextItems, maxContextSize, }: CheckContextProps): Promise<CommandHandlerResult>;
@@ -0,0 +1,41 @@
1
+ export const checkContextDef = {
2
+ name: 'checkContext',
3
+ description: 'Returns context metrics (message and token counts) and provides guidance on when to wrap context.',
4
+ parameters: {
5
+ type: 'object',
6
+ properties: {},
7
+ required: [],
8
+ },
9
+ };
10
+ export async function handleCheckContext({ actionResult, taskExecutionPrompt, computeContextMetrics, maxContextItems, maxContextSize, }) {
11
+ const { messageCount, estimatedTokens } = computeContextMetrics();
12
+ let content = `Context metrics: messages=${messageCount}, tokens≈${estimatedTokens}.`;
13
+ const messageThreshold = maxContextItems * 0.8;
14
+ const tokenThreshold = maxContextSize * 0.8;
15
+ if (messageCount > maxContextItems || estimatedTokens > maxContextSize) {
16
+ content += ` Limits exceeded: messages>${maxContextItems} or tokens>${maxContextSize}. You must call wrapContext now.`;
17
+ }
18
+ else if (messageCount > messageThreshold || estimatedTokens > tokenThreshold) {
19
+ content += ` Nearing limits. Consider calling wrapContext soon.`;
20
+ }
21
+ taskExecutionPrompt.push({
22
+ type: 'assistant',
23
+ functionCalls: [actionResult],
24
+ }, {
25
+ type: 'user',
26
+ text: content,
27
+ functionResponses: [
28
+ {
29
+ name: actionResult.name,
30
+ call_id: actionResult.id || undefined,
31
+ },
32
+ ],
33
+ });
34
+ return {
35
+ success: undefined,
36
+ summary: undefined,
37
+ commandsExecutedIncrement: 0,
38
+ shouldBreakOuter: false,
39
+ };
40
+ }
41
+ //# sourceMappingURL=check-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-context.js","sourceRoot":"","sources":["../../../../../../../src/prompt/steps/step-ask-question/handlers/container-task/commands/check-context.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,eAAe,GAAgB;IAC1C,IAAI,EAAE,cAAc;I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Props, CommandHandlerResult } from '../container-commands-types.js';
3
+ export declare const completeTaskDef: FunctionDef;
4
+ export declare function handleCompleteTask(props: Pick<CommandHandlerBaseProps, 'actionResult' | 'taskExecutionPrompt' | 'options'>): Promise<CommandHandlerResult>;
@@ -0,0 +1,49 @@
1
+ import { putAssistantMessage, putSystemMessage, putUserMessage } from '../../../../../../main/common/content-bus.js';
2
+ import { askUserForConfirmationWithAnswer } from '../../../../../../main/common/user-actions.js';
3
+ export const completeTaskDef = {
4
+ name: 'completeTask',
5
+ description: 'Mark the container task as successfully completed.',
6
+ parameters: {
7
+ type: 'object',
8
+ properties: {
9
+ summary: {
10
+ type: 'string',
11
+ description: 'A brief summary of what was accomplished.',
12
+ },
13
+ },
14
+ required: ['summary'],
15
+ },
16
+ };
17
+ export async function handleCompleteTask(props) {
18
+ const { actionResult, taskExecutionPrompt } = props;
19
+ const args = actionResult.args;
20
+ putSystemMessage('✅ Task marked as complete by internal operator.');
21
+ putAssistantMessage(args.summary);
22
+ const confirmation = await askUserForConfirmationWithAnswer('Are you sure you want to complete the task?', 'Complete task', 'Continue', true, props.options);
23
+ if (confirmation.answer) {
24
+ putUserMessage(confirmation.answer);
25
+ }
26
+ taskExecutionPrompt.push({
27
+ type: 'assistant',
28
+ text: 'Completing the task.',
29
+ functionCalls: [actionResult],
30
+ }, {
31
+ type: 'user',
32
+ functionResponses: [
33
+ {
34
+ name: actionResult.name,
35
+ call_id: actionResult.id || undefined,
36
+ content: confirmation.confirmed
37
+ ? 'Task completed successfully.'
38
+ : 'Task is incomplete. Please continue.' + (confirmation.answer ? ` ${confirmation.answer}` : ''),
39
+ },
40
+ ],
41
+ });
42
+ return {
43
+ shouldBreakOuter: confirmation.confirmed === true,
44
+ success: true,
45
+ summary: args.summary,
46
+ commandsExecutedIncrement: 0,
47
+ };
48
+ }
49
+ //# sourceMappingURL=complete-task.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"complete-task.js","sourceRoot":"","sources":["../../../../../../../src/prompt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CAAC,SAAS;oBAC7B,CAAC,CAAC,8BAA8B;oBAChC,CAAC,CAAC,sCAAsC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACpG;SACF;KACF,CACF,CAAC;IAEF,OAAO;QACL,gBAAgB,EAAE,YAAY,CAAC,SAAS,KAAK,IAAI;QACjD,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,yBAAyB,EAAE,CAAC;KAC7B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { FunctionDef } from '../../../../../../ai-service/common-types.js';
2
+ import { CommandHandlerBaseProps, CommandHandlerResult } from '../container-commands-types.js';
3
+ export declare const getCopyFromContainerDef: () => FunctionDef;
4
+ export declare function handleCopyFromContainer(props: Pick<CommandHandlerBaseProps, 'actionResult' | 'taskExecutionPrompt' | 'container' | 'options'>): Promise<CommandHandlerResult>;
@@ -0,0 +1,190 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import { abortController } from '../../../../../../main/common/abort-controller.js';
4
+ import { putContainerLog, putSystemMessage, putUserMessage } from '../../../../../../main/common/content-bus.js';
5
+ import { askUserForConfirmationWithAnswer } from '../../../../../../main/common/user-actions.js';
6
+ import { checkPathExistsInContainer, copyFromContainer, getFileContentFromContainer, listFilesInContainerArchive, } from '../utils/docker-utils.js';
7
+ import { rcConfig } from '../../../../../../main/config.js';
8
+ import { isAncestorDirectory } from '../../../../../../files/file-utils.js';
9
+ import { getSourceCode } from '../../../../../../files/read-files.js';
10
+ export const getCopyFromContainerDef = () => ({
11
+ name: 'copyFromContainer',
12
+ description: 'Copy a file or directory from the container to the host.',
13
+ parameters: {
14
+ type: 'object',
15
+ properties: {
16
+ containerPath: {
17
+ type: 'string',
18
+ description: 'The absolute destination path on the host machine, which must be within the project root directory.',
19
+ },
20
+ hostPath: {
21
+ type: 'string',
22
+ description: `The absolute destination path on the host machine, which must be within the project root directory. The file path must start from: ${rcConfig.rootDir}`,
23
+ },
24
+ },
25
+ required: ['containerPath', 'hostPath'],
26
+ },
27
+ });
28
+ export async function handleCopyFromContainer(props) {
29
+ const { actionResult, taskExecutionPrompt, container, options } = props;
30
+ const args = actionResult.args;
31
+ if (abortController?.signal.aborted) {
32
+ putContainerLog('warn', 'Copy from container cancelled by user.', undefined, 'copy');
33
+ taskExecutionPrompt.push({ type: 'assistant', functionCalls: [actionResult] }, {
34
+ type: 'user',
35
+ functionResponses: [
36
+ {
37
+ name: actionResult.name,
38
+ call_id: actionResult.id || undefined,
39
+ content: 'Operation cancelled by user.',
40
+ },
41
+ ],
42
+ });
43
+ return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
44
+ }
45
+ try {
46
+ if (!isAncestorDirectory(rcConfig.rootDir, args.hostPath)) {
47
+ const errorMsg = `Invalid host path: ${args.hostPath}. It must be within the project root directory: ${rcConfig.rootDir}`;
48
+ putContainerLog('error', errorMsg, args, 'copy');
49
+ putSystemMessage(`❌ ${errorMsg}`);
50
+ taskExecutionPrompt.push({ type: 'assistant', functionCalls: [actionResult] }, {
51
+ type: 'user',
52
+ functionResponses: [
53
+ {
54
+ name: actionResult.name,
55
+ call_id: actionResult.id || undefined,
56
+ content: `Error: Invalid host path. It must be within the project root directory: ${rcConfig.rootDir}.`,
57
+ },
58
+ ],
59
+ });
60
+ return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
61
+ }
62
+ if (!(await checkPathExistsInContainer(container, args.containerPath))) {
63
+ const errorMsg = `Invalid container path: ${args.containerPath}. It must be a valid path inside the container.`;
64
+ putContainerLog('error', errorMsg, args, 'copy');
65
+ putSystemMessage(`❌ ${errorMsg}`);
66
+ taskExecutionPrompt.push({ type: 'assistant', functionCalls: [actionResult] }, {
67
+ type: 'user',
68
+ functionResponses: [
69
+ {
70
+ name: actionResult.name,
71
+ call_id: actionResult.id || undefined,
72
+ content: `Error: Invalid container path. It must be a valid path inside the container.`,
73
+ },
74
+ ],
75
+ });
76
+ return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
77
+ }
78
+ const entriesToCopy = await listFilesInContainerArchive(container, args.containerPath);
79
+ if (entriesToCopy.length === 0) {
80
+ const message = `No files or directories found at container path "${args.containerPath}" to copy.`;
81
+ putSystemMessage(message);
82
+ taskExecutionPrompt.push({ type: 'assistant', functionCalls: [actionResult] }, {
83
+ type: 'user',
84
+ functionResponses: [{ name: actionResult.name, call_id: actionResult.id || undefined, content: message }],
85
+ });
86
+ return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
87
+ }
88
+ let extractionHostPath = args.hostPath;
89
+ if (entriesToCopy.length === 1 && path.basename(args.containerPath) === path.basename(args.hostPath)) {
90
+ extractionHostPath = path.dirname(args.hostPath);
91
+ putContainerLog('info', 'Host path appears to be a file path for a single file copy. Adjusting destination to parent directory.', { original: args.hostPath, adjusted: extractionHostPath }, 'copy');
92
+ }
93
+ const updatesForSummary = [];
94
+ const hostFilePaths = entriesToCopy
95
+ .filter((e) => e.type === 'file')
96
+ .map((entry) => path.join(extractionHostPath, entry.name));
97
+ const existingSources = getSourceCode({ filterPaths: hostFilePaths, forceAll: true }, options);
98
+ for (const entry of entriesToCopy) {
99
+ const hostFilePath = path.join(extractionHostPath, entry.name);
100
+ if (!isAncestorDirectory(rcConfig.rootDir, hostFilePath)) {
101
+ putContainerLog('warn', `Skipping entry: ${hostFilePath} as it is outside the project root directory.`, undefined, 'copy');
102
+ continue;
103
+ }
104
+ if (entry.type === 'directory') {
105
+ if (!fs.existsSync(hostFilePath)) {
106
+ updatesForSummary.push({
107
+ name: 'createDirectory',
108
+ args: {
109
+ filePath: hostFilePath,
110
+ explanation: `Directory will be created as it does not exist on the host.`,
111
+ },
112
+ });
113
+ }
114
+ }
115
+ else if (entry.type === 'file') {
116
+ const containerFilePath = path.basename(args.containerPath) === entry.name
117
+ ? args.containerPath
118
+ : path.join(args.containerPath, entry.name);
119
+ const newContent = await getFileContentFromContainer(container, containerFilePath);
120
+ const sourceFile = existingSources[hostFilePath];
121
+ const oldContent = sourceFile && 'content' in sourceFile ? sourceFile.content : undefined;
122
+ const toolName = fs.existsSync(hostFilePath) ? 'updateFile' : 'createFile';
123
+ updatesForSummary.push({
124
+ name: toolName,
125
+ args: {
126
+ filePath: hostFilePath,
127
+ newContent,
128
+ oldContent,
129
+ explanation: `Copied from container path: ${containerFilePath}`,
130
+ },
131
+ });
132
+ }
133
+ }
134
+ if (updatesForSummary.length === 0) {
135
+ const message = `No files to copy after filtering.`;
136
+ putSystemMessage(message);
137
+ taskExecutionPrompt.push({ type: 'assistant', functionCalls: [actionResult] }, {
138
+ type: 'user',
139
+ functionResponses: [{ name: actionResult.name, call_id: actionResult.id || undefined, content: message }],
140
+ });
141
+ return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
142
+ }
143
+ putContainerLog('info', `Found ${entriesToCopy.length} entries to copy from container`, { entriesToCopy }, 'copy');
144
+ putSystemMessage(`Assistant is proposing to copy from container path "${args.containerPath}" to host path "${extractionHostPath}"`, { fileUpdates: updatesForSummary });
145
+ const confirmation = await askUserForConfirmationWithAnswer(`Do you want to proceed?`, 'Copy to host', 'Reject', true, options);
146
+ if (confirmation.answer) {
147
+ putUserMessage(confirmation.answer);
148
+ }
149
+ if (!confirmation.confirmed) {
150
+ putContainerLog('warn', 'Copy from container cancelled by user.', undefined, 'copy');
151
+ putSystemMessage('Copy from container cancelled by user.');
152
+ taskExecutionPrompt.push({ type: 'assistant', functionCalls: [actionResult] }, {
153
+ type: 'user',
154
+ text: 'I reject the copy operation.' + (confirmation.answer ? ` ${confirmation.answer}` : ''),
155
+ functionResponses: [{ name: actionResult.name, call_id: actionResult.id || undefined }],
156
+ });
157
+ return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
158
+ }
159
+ if (options.dryRun) {
160
+ putSystemMessage('Dry run mode, not copying files from container');
161
+ }
162
+ else {
163
+ await copyFromContainer(container, args.containerPath, extractionHostPath);
164
+ }
165
+ taskExecutionPrompt.push({ type: 'assistant', functionCalls: [actionResult] }, {
166
+ type: 'user',
167
+ text: 'I accept the copy operation.' + (confirmation.answer ? ` ${confirmation.answer}` : ''),
168
+ functionResponses: [
169
+ {
170
+ name: actionResult.name,
171
+ call_id: actionResult.id || undefined,
172
+ content: `Successfully copied from container path ${args.containerPath} to ${extractionHostPath}.`,
173
+ },
174
+ ],
175
+ });
176
+ }
177
+ catch (error) {
178
+ const errorMessage = error instanceof Error ? error.message : String(error);
179
+ putContainerLog('error', 'Error copying from container', { error: errorMessage }, 'copy');
180
+ putSystemMessage('❌ Error copying from container', { error: errorMessage });
181
+ taskExecutionPrompt.push({ type: 'assistant', functionCalls: [actionResult] }, {
182
+ type: 'user',
183
+ functionResponses: [
184
+ { name: actionResult.name, call_id: actionResult.id || undefined, content: `Error: ${errorMessage}` },
185
+ ],
186
+ });
187
+ }
188
+ return { shouldBreakOuter: false, commandsExecutedIncrement: 0 };
189
+ }
190
+ //# sourceMappingURL=copy-from-container.js.map