|
2 | 2 | * Tool parameter type definitions for native protocol |
3 | 3 | */ |
4 | 4 |
|
| 5 | +/** |
| 6 | + * Read mode for the read_file tool. |
| 7 | + * - "slice": Simple offset/limit reading (default) |
| 8 | + * - "indentation": Semantic block extraction based on code structure |
| 9 | + */ |
| 10 | +export type ReadFileMode = "slice" | "indentation" |
| 11 | + |
| 12 | +/** |
| 13 | + * Indentation-mode configuration for the read_file tool. |
| 14 | + */ |
| 15 | +export interface IndentationParams { |
| 16 | + /** 1-based line number to anchor indentation extraction (defaults to offset) */ |
| 17 | + anchor_line?: number |
| 18 | + /** Maximum indentation levels to include above anchor (0 = unlimited) */ |
| 19 | + max_levels?: number |
| 20 | + /** Include sibling blocks at the same indentation level */ |
| 21 | + include_siblings?: boolean |
| 22 | + /** Include file header (imports, comments at top) */ |
| 23 | + include_header?: boolean |
| 24 | + /** Hard cap on lines returned for indentation mode */ |
| 25 | + max_lines?: number |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * Parameters for the read_file tool (new format). |
| 30 | + * |
| 31 | + * NOTE: This is the canonical, single-file-per-call shape. |
| 32 | + */ |
| 33 | +export interface ReadFileParams { |
| 34 | + /** Path to the file, relative to workspace */ |
| 35 | + path: string |
| 36 | + /** Reading mode: "slice" (default) or "indentation" */ |
| 37 | + mode?: ReadFileMode |
| 38 | + /** 1-based line number to start reading from (slice mode, default: 1) */ |
| 39 | + offset?: number |
| 40 | + /** Maximum number of lines to read (default: 2000) */ |
| 41 | + limit?: number |
| 42 | + /** Indentation-mode configuration (only used when mode === "indentation") */ |
| 43 | + indentation?: IndentationParams |
| 44 | +} |
| 45 | + |
| 46 | +// ─── Legacy Format Types (Backward Compatibility) ───────────────────────────── |
| 47 | + |
| 48 | +/** |
| 49 | + * Line range specification for legacy read_file format. |
| 50 | + * Represents a contiguous range of lines [start, end] (1-based, inclusive). |
| 51 | + */ |
5 | 52 | export interface LineRange { |
6 | 53 | start: number |
7 | 54 | end: number |
8 | 55 | } |
9 | 56 |
|
| 57 | +/** |
| 58 | + * File entry for legacy read_file format. |
| 59 | + * Supports reading multiple disjoint line ranges from a single file. |
| 60 | + */ |
10 | 61 | export interface FileEntry { |
| 62 | + /** Path to the file, relative to workspace */ |
11 | 63 | path: string |
| 64 | + /** Optional list of line ranges to read (if omitted, reads entire file) */ |
12 | 65 | lineRanges?: LineRange[] |
13 | 66 | } |
14 | 67 |
|
| 68 | +/** |
| 69 | + * Legacy parameters for the read_file tool (pre-refactor format). |
| 70 | + * Supports reading multiple files in a single call with optional line ranges. |
| 71 | + * |
| 72 | + * @deprecated Use ReadFileParams instead. This format is maintained for |
| 73 | + * backward compatibility with existing chat histories. |
| 74 | + */ |
| 75 | +export interface LegacyReadFileParams { |
| 76 | + /** Array of file entries to read */ |
| 77 | + files: FileEntry[] |
| 78 | + /** Discriminant flag for type narrowing */ |
| 79 | + _legacyFormat: true |
| 80 | +} |
| 81 | + |
| 82 | +/** |
| 83 | + * Union type for read_file tool parameters. |
| 84 | + * Supports both new single-file format and legacy multi-file format. |
| 85 | + */ |
| 86 | +export type ReadFileToolParams = ReadFileParams | LegacyReadFileParams |
| 87 | + |
| 88 | +/** |
| 89 | + * Type guard to check if params are in legacy format. |
| 90 | + */ |
| 91 | +export function isLegacyReadFileParams(params: ReadFileToolParams): params is LegacyReadFileParams { |
| 92 | + return "_legacyFormat" in params && params._legacyFormat === true |
| 93 | +} |
| 94 | + |
15 | 95 | export interface Coordinate { |
16 | 96 | x: number |
17 | 97 | y: number |
|
0 commit comments