@@ -167,9 +167,16 @@ export class AgentSideConnection {
167167 }
168168
169169 /**
170- * @internal **UNSTABLE**
170+ * Executes a command in a new terminal.
171171 *
172- * This method is not part of the spec, and may be removed or changed at any point.
172+ * Returns a `TerminalHandle` that can be used to get output, wait for exit,
173+ * kill the command, or release the terminal.
174+ *
175+ * The terminal can also be embedded in tool calls by using its ID in
176+ * `ToolCallContent` with type "terminal".
177+ *
178+ * @param params - The terminal creation parameters
179+ * @returns A handle to control and monitor the terminal
173180 */
174181 async createTerminal (
175182 params : schema . CreateTerminalRequest ,
@@ -187,6 +194,22 @@ export class AgentSideConnection {
187194 }
188195}
189196
197+ /**
198+ * Handle for controlling and monitoring a terminal created via `createTerminal`.
199+ *
200+ * Provides methods to:
201+ * - Get current output without waiting
202+ * - Wait for command completion
203+ * - Kill the running command
204+ * - Release terminal resources
205+ *
206+ * **Important:** Always call `release()` when done with the terminal to free resources.
207+
208+ * The terminal supports async disposal via `Symbol.asyncDispose` for automatic cleanup.
209+
210+ * You can use `await using` to ensure the terminal is automatically released when it
211+ * goes out of scope.
212+ */
190213export class TerminalHandle {
191214 #sessionId: string ;
192215 #connection: Connection ;
@@ -200,6 +223,9 @@ export class TerminalHandle {
200223 this . #connection = conn ;
201224 }
202225
226+ /**
227+ * Gets the current terminal output without waiting for the command to exit.
228+ */
203229 async currentOutput ( ) : Promise < schema . TerminalOutputResponse > {
204230 return await this . #connection. sendRequest (
205231 schema . CLIENT_METHODS . terminal_output ,
@@ -210,6 +236,9 @@ export class TerminalHandle {
210236 ) ;
211237 }
212238
239+ /**
240+ * Waits for the terminal command to complete and returns its exit status.
241+ */
213242 async waitForExit ( ) : Promise < schema . WaitForTerminalExitResponse > {
214243 return await this . #connection. sendRequest (
215244 schema . CLIENT_METHODS . terminal_wait_for_exit ,
@@ -220,6 +249,16 @@ export class TerminalHandle {
220249 ) ;
221250 }
222251
252+ /**
253+ * Kills the terminal command without releasing the terminal.
254+ *
255+ * The terminal remains valid after killing, allowing you to:
256+ * - Get the final output with `currentOutput()`
257+ * - Check the exit status
258+ * - Release the terminal when done
259+ *
260+ * Useful for implementing timeouts or cancellation.
261+ */
223262 async kill ( ) : Promise < void > {
224263 return await this . #connection. sendRequest (
225264 schema . CLIENT_METHODS . terminal_kill ,
@@ -230,6 +269,18 @@ export class TerminalHandle {
230269 ) ;
231270 }
232271
272+ /**
273+ * Releases the terminal and frees all associated resources.
274+ *
275+ * If the command is still running, it will be killed.
276+ * After release, the terminal ID becomes invalid and cannot be used
277+ * with other terminal methods.
278+ *
279+ * Tool calls that already reference this terminal will continue to
280+ * display its output.
281+ *
282+ * **Important:** Always call this method when done with the terminal.
283+ */
233284 async release ( ) : Promise < void > {
234285 await this . #connection. sendRequest ( schema . CLIENT_METHODS . terminal_release , {
235286 sessionId : this . #sessionId,
@@ -851,43 +902,68 @@ export interface Client {
851902 ) : Promise < schema . ReadTextFileResponse > ;
852903
853904 /**
854- * @internal **UNSTABLE**
905+ * Creates a new terminal to execute a command.
855906 *
856- * This method is not part of the spec, and may be removed or changed at any point.
907+ * Only available if the `terminal` capability is set to `true`.
908+ *
909+ * The Agent must call `releaseTerminal` when done with the terminal
910+ * to free resources.
911+
912+ * @see {@link https://agentclientprotocol.com/protocol/terminals | Terminal Documentation }
857913 */
858914 createTerminal ?(
859915 params : schema . CreateTerminalRequest ,
860916 ) : Promise < schema . CreateTerminalResponse > ;
861917
862918 /**
863- * @internal **UNSTABLE**
919+ * Gets the current output and exit status of a terminal.
864920 *
865- * This method is not part of the spec, and may be removed or changed at any point.
921+ * Returns immediately without waiting for the command to complete.
922+ * If the command has already exited, the exit status is included.
923+ *
924+ * @see {@link https://agentclientprotocol.com/protocol/terminals#getting-output | Getting Terminal Output }
866925 */
867926 terminalOutput ?(
868927 params : schema . TerminalOutputRequest ,
869928 ) : Promise < schema . TerminalOutputResponse > ;
870929
871930 /**
872- * @internal **UNSTABLE**
931+ * Releases a terminal and frees all associated resources.
873932 *
874- * This method is not part of the spec, and may be removed or changed at any point.
933+ * The command is killed if it hasn't exited yet. After release,
934+ * the terminal ID becomes invalid for all other terminal methods.
935+ *
936+ * Tool calls that already contain the terminal ID continue to
937+ * display its output.
938+ *
939+ * @see {@link https://agentclientprotocol.com/protocol/terminals#releasing-terminals | Releasing Terminals }
875940 */
876941 releaseTerminal ?( params : schema . ReleaseTerminalRequest ) : Promise < void > ;
877942
878943 /**
879- * @internal **UNSTABLE**
944+ * Waits for a terminal command to exit and returns its exit status.
880945 *
881- * This method is not part of the spec, and may be removed or changed at any point.
946+ * This method returns once the command completes, providing the
947+ * exit code and/or signal that terminated the process.
948+ *
949+ * @see {@link https://agentclientprotocol.com/protocol/terminals#waiting-for-exit | Waiting for Exit }
882950 */
883951 waitForTerminalExit ?(
884952 params : schema . WaitForTerminalExitRequest ,
885953 ) : Promise < schema . WaitForTerminalExitResponse > ;
886954
887955 /**
888- * @internal **UNSTABLE**
956+ * Kills a terminal command without releasing the terminal.
889957 *
890- * This method is not part of the spec, and may be removed or changed at any point.
958+ * While `releaseTerminal` also kills the command, this method keeps
959+ * the terminal ID valid so it can be used with other methods.
960+ *
961+ * Useful for implementing command timeouts that terminate the command
962+ * and then retrieve the final output.
963+ *
964+ * Note: Call `releaseTerminal` when the terminal is no longer needed.
965+ *
966+ * @see {@link https://agentclientprotocol.com/protocol/terminals#killing-commands | Killing Commands }
891967 */
892968 killTerminal ?( params : schema . KillTerminalCommandRequest ) : Promise < void > ;
893969}
0 commit comments