@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
59 lines • 2.9 kB
TypeScript
import type { ExecShell } from "../../../vendor/senpi-machine-ops/index.js";
import type { ToolMachine } from "./tool-machine.ts";
/**
* Pluggable operations for the bash tool.
* Override these to delegate command execution to remote systems (for example SSH).
*/
export interface BashOperations {
/**
* Execute a command and stream output.
* @param command The command to execute
* @param cwd Working directory
* @param options Execution options
* @returns Promise resolving to the exit code. Report signal terminations as 128 + signal number;
* a null exit code is treated as a failed command.
*/
exec: (command: string, cwd: string, options: {
onData: (data: Buffer, stream?: "stdout" | "stderr") => void;
signal?: AbortSignal;
timeout?: number;
env?: NodeJS.ProcessEnv;
redactSecretsInOutput?: boolean;
/** The session the command runs for; a local host attests the spawned shell to it (senpi#6972). */
sessionId?: string;
}) => Promise<{
exitCode: number | null;
}>;
}
/** What a shell run needs from the host it runs for: the shell, the cwd check, the environment and pid tracking. */
export interface ShellExecHost {
/** The shell the command runs in; undefined lets the machine choose (`/bin/sh -c` on POSIX). */
resolveShell(): ExecShell | undefined;
/** Rejects when `cwd` does not exist where the command runs. */
checkCwd(cwd: string, signal: AbortSignal | undefined): Promise<void>;
/** "exact" runs with the tool's environment alone; "overlay" lays it over the machine's curated base. */
readonly envMode: "exact" | "overlay";
/** The environment when the caller passes none. */
defaultEnv(): NodeJS.ProcessEnv | undefined;
/** The number of a terminating signal, for the 128 + n exit code. */
signalNumber(signal: string): number | undefined;
onSpawn?(pid: number): void;
onExit?(pid: number): void;
/** Attests a shell this process spawned to the calling session; absent where the shell is not our child. */
attestSessionSpawn?(sessionId: string, pid: number): {
release(): unknown;
};
/** Runs once the exec settles, success or not. */
afterExec?(): void;
}
/**
* A host that knows only the tool machine: the machine's shell and environment, the cwd checked there, and the signal
* numbers of the machine's own OS.
*/
export declare function machineShellExecHost(machine: ToolMachine, shell?: ExecShell): ShellExecHost;
/**
* Shell execution used by the built-in shell tools: one `process.exec` of the operation layer (own process group,
* abort/timeout kill the group). The tool keeps its own output handling.
*/
export declare function createShellOperations(shellName: string, machine: ToolMachine, host: ShellExecHost): BashOperations;
//# sourceMappingURL=shell-operations.d.ts.map