-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterminal.ts
More file actions
108 lines (101 loc) · 2.9 KB
/
Copy pathterminal.ts
File metadata and controls
108 lines (101 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { z } from "zod"
/**
* CommandExecutionStatus
*/
export const commandExecutionStatusSchema = z.discriminatedUnion("status", [
z.object({
executionId: z.string(),
status: z.literal("started"),
pid: z.number().optional(),
command: z.string(),
}),
z.object({
executionId: z.string(),
status: z.literal("output"),
output: z.string(),
}),
z.object({
executionId: z.string(),
status: z.literal("exited"),
exitCode: z.number().optional(),
}),
z.object({
// User-initiated kill (the inline "Abort"/Kill Command button), as opposed
// to a natural `"exited"` or a `"timeout"`. Carries whatever exit code the
// signal produced (e.g. 130 for SIGINT, 137 for SIGKILL) when available.
executionId: z.string(),
status: z.literal("terminated"),
exitCode: z.number().optional(),
}),
z.object({
executionId: z.string(),
status: z.literal("fallback"),
}),
z.object({
executionId: z.string(),
status: z.literal("timeout"),
}),
])
export type CommandExecutionStatus = z.infer<typeof commandExecutionStatusSchema>
/**
* PersistedCommandOutput
*
* Represents the result of a terminal command execution that may have been
* truncated and persisted to disk.
*
* When command output exceeds the configured preview threshold, the full
* output is saved to a disk artifact file. The LLM receives this structure
* which contains:
* - A preview of the output (for immediate display in context)
* - Metadata about the full output (size, truncation status)
* - A path to the artifact file for later retrieval via `read_command_output`
*
* ## Usage in execute_command Response
*
* The response format depends on whether truncation occurred:
*
* **Not truncated** (output fits in preview):
* ```json
* {
* "preview": "full output here...",
* "totalBytes": 1234,
* "artifactPath": null,
* "truncated": false
* }
* ```
*
* **Truncated** (output exceeded threshold):
* ```json
* {
* "preview": "first 4KB of output...",
* "totalBytes": 1048576,
* "artifactPath": "/path/to/tasks/123/command-output/cmd-1706119234567.txt",
* "truncated": true
* }
* ```
*
* @see OutputInterceptor - Creates these results during command execution
* @see ReadCommandOutputTool - Retrieves full content from artifact files
*/
export interface PersistedCommandOutput {
/**
* Preview of the command output, truncated to the preview threshold.
* Always contains the beginning of the output, even if truncated.
*/
preview: string
/**
* Total size of the command output in bytes.
* Useful for determining if additional reads are needed.
*/
totalBytes: number
/**
* Absolute path to the artifact file containing full output.
* `null` if output wasn't truncated (no artifact was created).
*/
artifactPath: string | null
/**
* Whether the output was truncated (exceeded preview threshold).
* When `true`, use `read_command_output` to retrieve full content.
*/
truncated: boolean
}