import { spawn } from "node:child_process"; import type { Component, SelectItem } from "@mariozechner/pi-tui"; import { createSearchableSelectList } from "./components/selectors.js";
return await new Promise<boolean>((resolve) => {
deps.chatLog.addSystem("Allow local shell commands for this session?");
deps.chatLog.addSystem( "This runs commands on YOUR machine (not the gateway) and may delete files or reveal secrets.",
);
deps.chatLog.addSystem("Select Yes/No (arrows + Enter), Esc to cancel."); const selector = createSelector(
[
{ value: "no", label: "No" },
{ value: "yes", label: "Yes" },
], 2,
);
selector.onSelect = (item) => {
deps.closeOverlay(); if (item.value === "yes") {
localExecAllowed = true;
deps.chatLog.addSystem("local shell: enabled for this session");
resolve(true);
} else {
deps.chatLog.addSystem("local shell: not enabled");
resolve(false);
}
deps.tui.requestRender();
};
selector.onCancel = () => {
deps.closeOverlay();
deps.chatLog.addSystem("local shell: cancelled");
deps.tui.requestRender();
resolve(false);
};
deps.openOverlay(selector);
deps.tui.requestRender();
});
};
const runLocalShellLine = async (line: string) => { const cmd = line.slice(1); // NOTE: A lone '!' is handled by the submit handler as a normal message. // Keep this guard anyway in case this is called directly. if (cmd === "") { return;
}
if (localExecAsked && !localExecAllowed) {
deps.chatLog.addSystem("local shell: not enabled for this session");
deps.tui.requestRender(); return;
}
const allowed = await ensureLocalExecAllowed(); if (!allowed) { return;
}
await new Promise<void>((resolve) => { const child = spawnCommand(cmd, { // Intentionally a shell: this is an operator-only local TUI feature (prefixed with `!`) // and is gated behind an explicit in-session approval prompt.
shell: true,
cwd: getCwd(),
env: { ...env, OPENCLAW_SHELL: "tui-local" },
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.