Lines 6755-6795javascript
6756// packages/ai/src/bash/runtime.ts
6757import { exec } from "child_process";
6758import { promisify } from "util";
6759function isRecord7(value) {
6760 return typeof value === "object" && value !== null;
6762function toRecord(value) {
6763 return isRecord7(value) ? value : {};
6765function getStringProperty(record, key) {
6766 const value = record[key];
6767 return typeof value === "string" ? value : undefined;
6769function getNumericExitCode(record) {
6770 const value = record.code;
6771 return typeof value === "number" ? value : 1;
6773async function executeBash(input, workspaceContext = getDefaultWorkspaceContext()) {
6774 const parsedInput = bashInputSchema.parse(input);
6776 const result = await execAsync(parsedInput.command, {
6777 cwd: workspaceContext.root,
6778 timeout: parsedInput.timeoutMs,
6779 maxBuffer: 10 * 1024 * 1024,
6782 const stdoutTruncated = truncateText(result.stdout, parsedInput.maxOutputChars);
6783 const stderrTruncated = truncateText(result.stderr, Math.max(2000, Math.floor(parsedInput.maxOutputChars / 4)));
6784 return bashOutputSchema.parse({
6785 command: parsedInput.command,
6786 cwd: workspaceContext.root,
6787 stdout: stdoutTruncated.text,
6788 stderr: stderrTruncated.text,
6790 truncated: stdoutTruncated.truncated || stderrTruncated.truncated
6793 const errorRecord = toRecord(error);
6794 const stdout = getStringProperty(errorRecord, "stdout") ?? "";
6795 const stderr = getStringProperty(errorRecord, "stderr") ?? getStringProperty(errorRecord, "message") ?? "Command failed.";