refactor: ♻️ Updates to code to remove negative cases first (linting)

This commit is contained in:
chezsmithy 2025-06-04 22:23:39 -07:00
parent 3c5332ac0a
commit 2d3bdbe256

View file

@ -130,26 +130,7 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
return;
}
if (!waitForCompletion) {
// Already resolved, just update the UI with final output
if (extras.onPartialOutput) {
const status =
code === 0 || !code
? "\nBackground command completed"
: `\nBackground command failed with exit code ${code}`;
extras.onPartialOutput({
toolCallId,
contextItems: [
{
name: "Terminal",
description: "Terminal command output",
content: terminalOutput,
status: status,
},
],
});
}
} else {
if (waitForCompletion) {
// Normal completion, resolve now
if (code === 0) {
const status = "Command completed";
@ -172,6 +153,25 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
},
]);
}
} else {
// Already resolved, just update the UI with final output
if (extras.onPartialOutput) {
const status =
code === 0 || !code
? "\nBackground command completed"
: `\nBackground command failed with exit code ${code}`;
extras.onPartialOutput({
toolCallId,
contextItems: [
{
name: "Terminal",
description: "Terminal command output",
content: terminalOutput,
status: status,
},
],
});
}
}
});
@ -197,7 +197,31 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
const workspaceDirs = await extras.ide.getWorkspaceDirs();
const cwd = fileURLToPath(workspaceDirs[0]);
if (!waitForCompletion) {
if (waitForCompletion) {
// Standard execution, waiting for completion
try {
const output = await asyncExec(args.command, { cwd });
const status = "Command completed";
return [
{
name: "Terminal",
description: "Terminal command output",
content: output.stdout ?? "",
status: status,
},
];
} catch (error: any) {
const status = `Command failed with: ${error.message || error.toString()}`;
return [
{
name: "Terminal",
description: "Terminal command output",
content: error.stderr ?? error.toString(),
status: status,
},
];
}
} else {
// For non-streaming but also not waiting for completion, use spawn
// but don't attach any listeners other than error
try {
@ -246,30 +270,6 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
},
];
}
} else {
// Standard execution, waiting for completion
try {
const output = await asyncExec(args.command, { cwd });
const status = "Command completed";
return [
{
name: "Terminal",
description: "Terminal command output",
content: output.stdout ?? "",
status: status,
},
];
} catch (error: any) {
const status = `Command failed with: ${error.message || error.toString()}`;
return [
{
name: "Terminal",
description: "Terminal command output",
content: error.stderr ?? error.toString(),
status: status,
},
];
}
}
}
}