import { type ChildProcess, type SpawnOptions } from "node:child_process"; /** * Commands the user runs themselves from the app's input (`!git status`). * * Not the agent's bash tool: no sandbox, no guards, no timeout. These run with * the user's own shell, environment and permissions in the project folder, * exactly as if typed in a terminal, and only ever because the user submitted * them (see shell-routes.ts for the confirmation gate). */ /** * Error output (stderr) is wrapped in these private-use characters in the * window's copy of the output, so it can be shown differently while keeping * its place among normal output. The agent's copy never contains them. The * app (ShellBlock.tsx) uses the same two characters. */ export declare const STDERR_START = "\uE000"; export declare const STDERR_END = "\uE001"; export declare function stripStderrMarks(text: string): string; /** A cut that starts inside error output reopens it, so the first lines keep their look. */ export declare function reopenStderr(text: string): string; /** Output streamed to the window per command; the rest is summarised. */ export declare const SHELL_DISPLAY_MAX_CHARS = 1000000; /** What the agent (and the saved transcript) gets: the end, where results are. */ export declare const SHELL_CONTEXT_MAX_LINES = 200; export declare const SHELL_CONTEXT_MAX_CHARS = 16000; export declare const SHELL_COMMAND_MAX_CHARS = 8000; export interface ShellRunEnd { runId: string; command: string; cwd: string; exitCode: number | null; signal: string | null; durationMs: number; /** Stopped by the user. */ cancelled: boolean; /** The last lines of output (redacted, plain text), for the agent. */ tail: string; /** The same lines with error output marked, for the saved row. */ displayTail: string; /** True when `tail` is not the whole output. */ tailTruncated: boolean; /** True when the window stopped receiving output partway. */ displayTruncated: boolean; /** The shell itself could not start. */ error?: string; } export type ParsedShellRun = { ok: true; runId: string; command: string; confirmed: boolean; } | { ok: false; error: string; }; export declare function parseShellRunBody(raw: string): ParsedShellRun; /** The user's own environment, minus the app's private daemon variables. */ export declare function userShellEnv(env: NodeJS.ProcessEnv): Record; /** * The user's login shell ($SHELL) where there is one, so their usual shell * syntax works; otherwise the same shell the agent uses (Git Bash or cmd on * Windows). */ export declare function userShellLaunch(command: string, opts?: { platform?: NodeJS.Platform; env?: NodeJS.ProcessEnv; }): { file: string; args: string[]; }; /** The last `maxLines` lines, capped to `maxChars`, and whether anything was cut. */ export declare function tailOutput(text: string, maxLines?: number, maxChars?: number): { text: string; truncated: boolean; }; /** One command, as the agent reads it. */ export declare function formatShellContext(run: ShellRunEnd): string; export interface ShellRunnerOptions { /** Window frames: shell_output { id, chunk }. */ emit: (type: string, data: unknown) => void; onEnd: (run: ShellRunEnd) => void; spawn?: (file: string, args: string[], options: SpawnOptions) => ChildProcess; env?: NodeJS.ProcessEnv; platform?: NodeJS.Platform; now?: () => number; } /** The user's commands for one window session. */ export declare class ShellRunner { private readonly opts; private readonly runs; constructor(opts: ShellRunnerOptions); isRunning(runId: string): boolean; start(runId: string, command: string, cwd: string): { ok: true; } | { ok: false; error: string; }; /** Stop one command and everything it started. False when it isn't running. */ cancel(runId: string): boolean; /** Window closing: stop every command still running. */ stopAll(): void; }