UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

66 lines • 2.68 kB
import { getShellConfig } from "../../../../../utils/shell.js"; import { attestSessionSpawn } from "../../../../session-spawn-attestation.js"; /** * Resolve the configured shell (honoring `SENPI_GIT_BASH_PATH` + shell kind) and spawn a * terminal session that runs `command` through it. For stdin-transport shells (legacy WSL * bash `-s`) the command is written to the PTY after start; otherwise it rides in argv. */ export async function spawnCommandSession(ctx, request) { const shell = getShellConfig(ctx.shellPath); const useStdin = shell.commandTransport === "stdin"; const args = useStdin ? [...shell.args] : [...shell.args, request.command]; const launch = ctx.launchBarrier?.wrap(shell.shell, args) ?? { command: shell.shell, args }; const created = await ctx.manager.create(shell.shell, { command: launch.command, args: [...launch.args], cwd: request.cwd ?? ctx.cwd, env: { ...ctx.getEnv(), ...request.envOverrides }, cols: request.cols, rows: request.rows, timeoutMs: request.timeoutMs, redactSecretsInOutput: ctx.redactSecretsInOutput, }); const spawnedPid = created.runtime.session.pid; if (request.sessionId !== undefined && spawnedPid !== undefined) { const attestation = attestSessionSpawn(request.sessionId, spawnedPid); created.runtime.session.onExit(() => void attestation.release()); await attestation.recorded; } if (ctx.launchBarrier !== undefined) { const session = created.runtime.session; try { await ctx.launchBarrier.release({ pid: session.pid, write: (data) => session.write(data), onExit: (listener) => session.onExit(() => listener(session.exitResult?.exitCode ?? null)), }); } catch (error) { // The command never ran: its gated shim and its registration go with the refusal. await ctx.manager.stop(created.id); throw error; } } if (useStdin) { created.runtime.session.write(`${request.command}\n`); } return created; } /** Snapshot the human-facing exit status of a finished session. */ export function describeExit(runtime) { const exit = runtime.exitResult; if (!exit) return null; if (exit.timedOut) return "timed_out"; if (exit.cancelled) return "killed"; if (exit.exitCode === 0) return "completed"; if (exit.exitCode !== null) return `exited_${exit.exitCode}`; if (exit.signal) return `signal_${exit.signal}`; return "exited"; } //# sourceMappingURL=spawn.js.map