Skip to content

Commit 1cec126

Browse files
committed
Add docs to ts library
1 parent 5d8d5d4 commit 1cec126

5 files changed

Lines changed: 110 additions & 26 deletions

File tree

docs/protocol/initialization.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ The Client **SHOULD** specify whether it supports the following capabilities:
120120
#### Terminal
121121

122122
<ParamField path="terminal" type="boolean">
123-
All `terminal/*` methods are available, allowing the Agent to execute and manage shell commands.
123+
All `terminal/*` methods are available, allowing the Agent to execute and
124+
manage shell commands.
124125
</ParamField>
125126

126127
<Card icon="terminal" horizontal href="./terminals">

docs/protocol/schema.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,9 +2124,11 @@ File modification shown as a diff.
21242124
</ResponseField>
21252125

21262126
<ResponseField name="terminal">
2127-
Embed a terminal created with `terminal/create`
2127+
Embed a terminal created with `terminal/create` by its id.
21282128

2129-
The terminal must be added to the tool call before calling `terminal/release`.
2129+
The terminal must be added before calling `terminal/release`.
2130+
2131+
See protocol docs: [Terminal](https://agentclientprotocol.com/protocol/terminal)
21302132

21312133
<Expandable title="Properties">
21322134

docs/protocol/terminals.mdx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,23 @@ The `terminal/create` method starts a command in a new terminal:
6464
<ParamField path="env" type="EnvVariable[]">
6565
Optional environment variables for the command.
6666

67-
Each variable has:
68-
- `name`: The environment variable name
69-
- `value`: The environment variable value
67+
Each variable has:
68+
69+
- `name`: The environment variable name
70+
- `value`: The environment variable value
71+
7072
</ParamField>
7173

7274
<ParamField path="cwd" type="string">
7375
Optional working directory for the command (absolute path)
7476
</ParamField>
7577

7678
<ParamField path="outputByteLimit" type="number">
77-
Optional maximum number of output bytes to retain. Once exceeded, earlier output is truncated to stay within this limit.
79+
Optional maximum number of output bytes to retain. Once exceeded, earlier
80+
output is truncated to stay within this limit.
7881
</ParamField>
7982

80-
The Client returns a Terminal ID immediately without waiting for completion:
83+
The Client returns a Terminal ID immediately without waiting for completion:
8184

8285
```json
8386
{
@@ -94,11 +97,10 @@ This allows the command to run in the background while the Agent performs other
9497
After creating the terminal, the Agent can use the `terminal/wait_for_exit` method to wait for the command to complete.
9598

9699
<Note>
97-
The Agent **MUST** release the terminal using `terminal/release` when it's no longer needed.
100+
The Agent **MUST** release the terminal using `terminal/release` when it's no
101+
longer needed.
98102
</Note>
99103

100-
101-
102104
## Embedding in Tool Calls
103105

104106
Terminals can be embedded directly in [tool calls](./tool-calls) to provide real-time output to users:
@@ -171,8 +173,10 @@ The Client responds with the current output and exit status (if the command has
171173

172174
<ResponseField name="exitStatus" type="TerminalExitStatus">
173175
Present only if the command has exited. Contains:
174-
- `exitCode`: The process exit code (may be null)
175-
- `signal`: The signal that terminated the process (may be null)
176+
177+
- `exitCode`: The process exit code (may be null)
178+
- `signal`: The signal that terminated the process (may be null)
179+
176180
</ResponseField>
177181

178182
## Waiting for Exit
@@ -229,6 +233,7 @@ The `terminal/kill` method terminates a command without releasing the terminal:
229233
```
230234

231235
After killing a command, the terminal remains valid and can be used with:
236+
232237
- `terminal/output` to get the final output
233238
- `terminal/wait_for_exit` to get the exit status
234239

schema/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@
17421742
"type": "object"
17431743
},
17441744
{
1745-
"description": "Embed a terminal created with `terminal/create`\n\nThe terminal must be added to the tool call before calling `terminal/release`.",
1745+
"description": "Embed a terminal created with `terminal/create` by its id.\n\nThe terminal must be added before calling `terminal/release`.\n\nSee protocol docs: [Terminal](https://agentclientprotocol.com/protocol/terminal)",
17461746
"properties": {
17471747
"terminalId": {
17481748
"type": "string"

typescript/acp.ts

Lines changed: 88 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
*/
190213
export 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

Comments
 (0)