|
| 1 | +import type OpenAI from "openai" |
| 2 | + |
| 3 | +/** |
| 4 | + * Native tool definition for read_command_output. |
| 5 | + * |
| 6 | + * This tool allows the LLM to retrieve full command output that was truncated |
| 7 | + * during execute_command. When command output exceeds the preview threshold, |
| 8 | + * the full output is persisted to disk and an artifact_id is provided. The |
| 9 | + * LLM can then use this tool to read the full content or search within it. |
| 10 | + */ |
| 11 | + |
| 12 | +const READ_COMMAND_OUTPUT_DESCRIPTION = `Retrieve the full output from a command that was truncated in execute_command. Use this tool when: |
| 13 | +1. The execute_command result shows "[OUTPUT TRUNCATED - Full output saved to artifact: cmd-XXXX.txt]" |
| 14 | +2. You need to see more of the command output beyond the preview |
| 15 | +3. You want to search for specific content in large command output |
| 16 | +
|
| 17 | +The tool supports two modes: |
| 18 | +- **Read mode**: Read output starting from a byte offset with optional limit |
| 19 | +- **Search mode**: Filter lines matching a regex or literal pattern (like grep) |
| 20 | +
|
| 21 | +Parameters: |
| 22 | +- artifact_id: (required) The artifact filename from the truncated output message (e.g., "cmd-1706119234567.txt") |
| 23 | +- search: (optional) Pattern to filter lines. Supports regex or literal strings. Case-insensitive. |
| 24 | +- offset: (optional) Byte offset to start reading from. Default: 0. Use for pagination. |
| 25 | +- limit: (optional) Maximum bytes to return. Default: 32KB. |
| 26 | +
|
| 27 | +Example: Reading truncated command output |
| 28 | +{ "artifact_id": "cmd-1706119234567.txt" } |
| 29 | +
|
| 30 | +Example: Reading with pagination (after first 32KB) |
| 31 | +{ "artifact_id": "cmd-1706119234567.txt", "offset": 32768 } |
| 32 | +
|
| 33 | +Example: Searching for errors in build output |
| 34 | +{ "artifact_id": "cmd-1706119234567.txt", "search": "error|failed|Error" } |
| 35 | +
|
| 36 | +Example: Finding specific test failures |
| 37 | +{ "artifact_id": "cmd-1706119234567.txt", "search": "FAIL" }` |
| 38 | + |
| 39 | +const ARTIFACT_ID_DESCRIPTION = `The artifact filename from the truncated command output (e.g., "cmd-1706119234567.txt")` |
| 40 | + |
| 41 | +const SEARCH_DESCRIPTION = `Optional regex or literal pattern to filter lines (case-insensitive, like grep)` |
| 42 | + |
| 43 | +const OFFSET_DESCRIPTION = `Byte offset to start reading from (default: 0, for pagination)` |
| 44 | + |
| 45 | +const LIMIT_DESCRIPTION = `Maximum bytes to return (default: 32KB)` |
| 46 | + |
| 47 | +export default { |
| 48 | + type: "function", |
| 49 | + function: { |
| 50 | + name: "read_command_output", |
| 51 | + description: READ_COMMAND_OUTPUT_DESCRIPTION, |
| 52 | + strict: true, |
| 53 | + parameters: { |
| 54 | + type: "object", |
| 55 | + properties: { |
| 56 | + artifact_id: { |
| 57 | + type: "string", |
| 58 | + description: ARTIFACT_ID_DESCRIPTION, |
| 59 | + }, |
| 60 | + search: { |
| 61 | + type: ["string", "null"], |
| 62 | + description: SEARCH_DESCRIPTION, |
| 63 | + }, |
| 64 | + offset: { |
| 65 | + type: ["number", "null"], |
| 66 | + description: OFFSET_DESCRIPTION, |
| 67 | + }, |
| 68 | + limit: { |
| 69 | + type: ["number", "null"], |
| 70 | + description: LIMIT_DESCRIPTION, |
| 71 | + }, |
| 72 | + }, |
| 73 | + required: ["artifact_id", "search", "offset", "limit"], |
| 74 | + additionalProperties: false, |
| 75 | + }, |
| 76 | + }, |
| 77 | +} satisfies OpenAI.Chat.ChatCompletionTool |
0 commit comments