144
return text;
145
}
147
>
/**
148
>
* Terminal against which a shell command is executed.
149
>
*/
150
>
export interface IShellCommandTarget {
151
>
/** URI of the managed terminal the command runs in. */
152
>
readonly terminalUri: string;
153
>
/** The kind of shell backing the terminal. */
154
>
readonly shellType: ShellType;
155
>
}
156
>
157
>
/**
158
>
* How a shell command execution finished.
159
>
*
160
>
* - `completed` — the command finished; {@link IShellCommandResult.exitCode} holds the exit code.
161
>
* - `timeout` — the command did not finish within the timeout; output is partial.
162
>
* - `background` — the terminal claim was narrowed (user chose to continue in background).
163
>
* - `altBuffer` — the command switched to the terminal's alternate buffer (interactive UI).
164
>
* - `shellExited` — the shell process exited unexpectedly.
165
>
*/
166
>
export type ShellCommandStatus = 'completed' | 'timeout' | 'background' | 'altBuffer' | 'shellExited';
167
>
168
>
/**
169
>
* Neutral, agent-agnostic result of executing a shell command. Callers map this
170
>
* to their own result shape (e.g. an SDK `ToolResultObject` or an AHP tool call
171
>
* completion).
172
>
*/
173
>
export interface IShellCommandResult {
174
>
/** How the command execution finished. */
175
>
readonly status: ShellCommandStatus;
176
>
/** Exit code, when known (`completed` and `shellExited`). */
177
>
readonly exitCode?: number;
178
>
/** Cleaned command output (empty for `background`/`altBuffer`). */
179
>
readonly output: string;
180
>
}
181
>
182
>
/**
183
>
* Execute a command on an already-created managed terminal, resolving once the
184
>
* command finishes, times out, backgrounds, enters the alternate buffer, or the
185
>
* shell exits. Uses shell integration (OSC 633) for completion detection when
186
>
* available and falls back to a sentinel echo otherwise.
187
>
*
188
>
* This is the shared shell-integration primitive used by both the Copilot SDK
189
>
* shell tools and the agent-host `!command` runner.
190
>
*/
191
>
export function executeShellCommand(
192
target: IShellCommandTarget,
193
command: string,