Elffuss BraidHub

kikocis/continue public

fix: :art: Prettier fixes
Changeseta394da99efe1154420b27ce4c25acf39650a74b7a1191bbd182c0367b6f9ce92
Authorchezsmithy <chezsmithy@me.com> · 2025-07-28 17:41 -07:00
Committerchezsmithy <chezsmithy@me.com> · 2025-08-08 00:05 -07:00
Parents245005345e6e

Browse the files at this changeset

2 files changed

modified core/tools/implementations/runTerminalCommand.test.ts +18 −12
@@ -356,10 +356,12 @@
356356 it("should handle missing workspace directory gracefully", async () => {
357357 // Mock IDE to return empty workspace directories
358358 const mockEmptyWorkspace = jest.fn().mockReturnValue(Promise.resolve([]));
359-
359+
360360 // Create IDE mock with empty workspace
361361 const mockIde = {
362- getIdeInfo: jest.fn().mockReturnValue(Promise.resolve({ remoteName: "local" })),
362+ getIdeInfo: jest
363+ .fn()
364+ .mockReturnValue(Promise.resolve({ remoteName: "local" })),
363365 getWorkspaceDirs: mockEmptyWorkspace,
364366 runCommand: jest.fn(),
365367 getIdeSettings: jest.fn(),
@@ -393,7 +395,7 @@
393395 expect(result[0].description).toBe("Terminal command output");
394396 expect(result[0].content).toContain("no workspace test");
395397 expect(result[0].status).toBe("Command completed");
396-
398+
397399 // Verify workspace dirs was called but returned empty
398400 expect(mockEmptyWorkspace).toHaveBeenCalled();
399401 });
@@ -401,12 +403,12 @@
401403 it("should handle case where cwd fallbacks all fail", async () => {
402404 // Mock IDE to return empty workspace directories
403405 const mockEmptyWorkspace = jest.fn().mockReturnValue(Promise.resolve([]));
404-
406+
405407 // Save original environment variables and process.cwd
406408 const originalHome = process.env.HOME;
407409 const originalUserProfile = process.env.USERPROFILE;
408410 const originalCwd = process.cwd;
409-
411+
410412 try {
411413 // Mock all fallbacks to fail
412414 delete process.env.HOME;
@@ -414,10 +416,12 @@
414416 process.cwd = jest.fn().mockImplementation(() => {
415417 throw new Error("Current directory unavailable");
416418 });
417-
419+
418420 // Create IDE mock with empty workspace
419421 const mockIde = {
420- getIdeInfo: jest.fn().mockReturnValue(Promise.resolve({ remoteName: "local" })),
422+ getIdeInfo: jest
423+ .fn()
424+ .mockReturnValue(Promise.resolve({ remoteName: "local" })),
421425 getWorkspaceDirs: mockEmptyWorkspace,
422426 runCommand: jest.fn(),
423427 getIdeSettings: jest.fn(),
@@ -445,15 +449,17 @@
445449
446450 // This should now handle the case gracefully by falling back to temp directory
447451 const result = await runTerminalCommandImpl(args, extras);
448-
452+
449453 // Should work using the temp directory as fallback
450454 expect(result).toHaveLength(1);
451455 expect(result[0].name).toBe("Terminal");
452456 expect(result[0].content).toContain("fallback test");
453457 expect(result[0].status).toBe("Command completed");
454-
455- console.log("Successfully handled cwd fallback to temp directory:", result[0].status);
456-
458+
459+ console.log(
460+ "Successfully handled cwd fallback to temp directory:",
461+ result[0].status,
462+ );
457463 } finally {
458464 // Always restore original values
459465 if (originalHome !== undefined) {
@@ -465,4 +471,4 @@
465471 process.cwd = originalCwd;
466472 }
467473 });
468-});
No newline at the end of the file
474+});
modified core/tools/implementations/runTerminalCommand.ts +118 −109
@@ -78,7 +78,7 @@
7878 if (extras.onPartialOutput) {
7979 try {
8080 const workspaceDirs = await extras.ide.getWorkspaceDirs();
81-
81+
8282 // Handle case where no workspace is available
8383 let cwd: string;
8484 if (workspaceDirs.length > 0) {
@@ -119,58 +119,98 @@
119119 cwd,
120120 env: getColorEnv(), // Add enhanced environment for colors
121121 });
122+ }
123+ }
122124
123- childProc.stdout?.on("data", (data) => {
124- // Skip if this process has been backgrounded
125- if (isProcessBackgrounded(toolCallId)) return;
126-
127- const newOutput = getDecodedOutput(data);
128- terminalOutput += newOutput;
125+ // Use spawn with color environment
126+ const childProc = childProcess.spawn(command, {
127+ cwd,
128+ shell: true,
129+ env: getColorEnv(), // Add enhanced environment for colors
130+ });
129131
130- // Send partial output to UI
131- if (extras.onPartialOutput) {
132- const status = waitForCompletion
133- ? ""
134- : "Command is running in the background...";
135- extras.onPartialOutput({
136- toolCallId,
137- contextItems: [
138- {
139- name: "Terminal",
140- description: "Terminal command output",
141- content: terminalOutput,
142- status: status,
143- },
144- ],
145- });
146- }
132+ childProc.stdout?.on("data", (data) => {
133+ // Skip if this process has been backgrounded
134+ if (isProcessBackgrounded(toolCallId)) return;
135+
136+ const newOutput = getDecodedOutput(data);
137+ terminalOutput += newOutput;
138+
139+ // Send partial output to UI
140+ if (extras.onPartialOutput) {
141+ const status = waitForCompletion
142+ ? ""
143+ : "Command is running in the background...";
144+ extras.onPartialOutput({
145+ toolCallId,
146+ contextItems: [
147+ {
148+ name: "Terminal",
149+ description: "Terminal command output",
150+ content: terminalOutput,
151+ status: status,
152+ },
153+ ],
147154 });
155+ }
156+ });
148157
149- childProc.stderr?.on("data", (data) => {
150- // Skip if this process has been backgrounded
151- if (isProcessBackgrounded(toolCallId)) return;
158+ childProc.stderr?.on("data", (data) => {
159+ // Skip if this process has been backgrounded
160+ if (isProcessBackgrounded(toolCallId)) return;
161+
162+ const newOutput = getDecodedOutput(data);
163+ terminalOutput += newOutput;
164+
165+ // Send partial output to UI, status is not required
166+ if (extras.onPartialOutput) {
167+ extras.onPartialOutput({
168+ toolCallId,
169+ contextItems: [
170+ {
171+ name: "Terminal",
172+ description: "Terminal command output",
173+ content: terminalOutput,
174+ },
175+ ],
176+ });
177+ }
178+ });
152179
153- const newOutput = getDecodedOutput(data);
154- terminalOutput += newOutput;
180+ // If we don't need to wait for completion, resolve immediately
181+ if (!waitForCompletion) {
182+ const status = "Command is running in the background...";
183+ resolve([
184+ {
185+ name: "Terminal",
186+ description: "Terminal command output",
187+ content: terminalOutput,
188+ status: status,
189+ },
190+ ]);
191+ }
155192
156- // Send partial output to UI, status is not required
157- if (extras.onPartialOutput) {
158- extras.onPartialOutput({
159- toolCallId,
160- contextItems: [
161- {
162- name: "Terminal",
163- description: "Terminal command output",
164- content: terminalOutput,
165- },
166- ],
167- });
168- }
169- });
193+ childProc.on("close", (code) => {
194+ // If this process has been backgrounded, clean it up from the map and return
195+ if (isProcessBackgrounded(toolCallId)) {
196+ removeBackgroundedProcess(toolCallId);
197+ return;
198+ }
170199
171- // If we don't need to wait for completion, resolve immediately
172- if (!waitForCompletion) {
173- const status = "Command is running in the background...";
200+ if (waitForCompletion) {
201+ // Normal completion, resolve now
202+ if (code === 0) {
203+ const status = "Command completed";
204+ resolve([
205+ {
206+ name: "Terminal",
207+ description: "Terminal command output",
208+ content: terminalOutput,
209+ status: status,
210+ },
211+ ]);
212+ } else {
213+ const status = `Command failed with exit code ${code}`;
174214 resolve([
175215 {
176216 name: "Terminal",
@@ -180,76 +220,45 @@
180220 },
181221 ]);
182222 }
223+ } else {
224+ // Already resolved, just update the UI with final output
225+ if (extras.onPartialOutput) {
226+ const status =
227+ code === 0 || !code
228+ ? "\nBackground command completed"
229+ : `\nBackground command failed with exit code ${code}`;
230+ extras.onPartialOutput({
231+ toolCallId,
232+ contextItems: [
233+ {
234+ name: "Terminal",
235+ description: "Terminal command output",
236+ content: terminalOutput,
237+ status: status,
238+ },
239+ ],
240+ });
241+ }
242+ }
243+ });
183244
184- childProc.on("close", (code) => {
185- // If this process has been backgrounded, clean it up from the map and return
186- if (isProcessBackgrounded(toolCallId)) {
187- removeBackgroundedProcess(toolCallId);
188- return;
189- }
190-
191- if (waitForCompletion) {
192- // Normal completion, resolve now
193- if (code === 0) {
194- const status = "Command completed";
195- resolve([
196- {
197- name: "Terminal",
198- description: "Terminal command output",
199- content: terminalOutput,
200- status: status,
201- },
202- ]);
203- } else {
204- const status = `Command failed with exit code ${code}`;
205- resolve([
206- {
207- name: "Terminal",
208- description: "Terminal command output",
209- content: terminalOutput,
210- status: status,
211- },
212- ]);
213- }
214- } else {
215- // Already resolved, just update the UI with final output
216- if (extras.onPartialOutput) {
217- const status =
218- code === 0 || !code
219- ? "\nBackground command completed"
220- : `\nBackground command failed with exit code ${code}`;
221- extras.onPartialOutput({
222- toolCallId,
223- contextItems: [
224- {
225- name: "Terminal",
226- description: "Terminal command output",
227- content: terminalOutput,
228- status: status,
229- },
230- ],
231- });
232- }
233- }
234- });
235-
236- childProc.on("error", (error) => {
237- // If this process has been backgrounded, clean it up from the map and return
238- if (isProcessBackgrounded(toolCallId)) {
239- removeBackgroundedProcess(toolCallId);
240- return;
241- }
245+ childProc.on("error", (error) => {
246+ // If this process has been backgrounded, clean it up from the map and return
247+ if (isProcessBackgrounded(toolCallId)) {
248+ removeBackgroundedProcess(toolCallId);
249+ return;
250+ }
242251
243- reject(error);
244- });
245- });
252+ reject(error);
253+ });
254+ });
246255 } catch (error: any) {
247256 throw error;
248257 }
249258 } else {
250259 // Fallback to non-streaming for older clients
251260 const workspaceDirs = await extras.ide.getWorkspaceDirs();
252-
261+
253262 // Handle case where no workspace is available
254263 let cwd: string;
255264 if (workspaceDirs.length > 0) {
@@ -397,4 +406,4 @@
397406 status: "Command failed",
398407 },
399408 ];
400-};
No newline at the end of the file
409+};