continue-custom/core/tools/implementations/runTerminalCommand.ts
2024-11-29 08:38:26 -08:00

40 lines
1.1 KiB
TypeScript

import { ToolImpl } from ".";
const util = require("node:util");
const asyncExec = util.promisify(require("node:child_process").exec);
export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
const ideInfo = await extras.ide.getIdeInfo();
if (ideInfo.remoteName === "local" || ideInfo.remoteName === "") {
try {
const output = await asyncExec(args.command, {
cwd: (await extras.ide.getWorkspaceDirs())[0],
});
return [
{
name: "Terminal",
description: "Terminal command output",
content: output.stdout ?? "",
},
];
} catch (error: any) {
return [
{
name: "Terminal",
description: "Terminal command output",
content: error.stderr ?? error.toString(),
},
];
}
}
await extras.ide.runCommand(args.command);
return [
{
name: "Terminal",
description: "Terminal command output",
content:
"[Terminal output not available. This is only available in local development environments and not in SSH environments for example.]",
},
];
};