(workspaceDir, input)
| 200 | } |
| 201 | |
| 202 | async function readFile(workspaceDir, input) { |
| 203 | if (typeof input.path !== 'string' || !input.path) { |
| 204 | throw new Error('read_file requires a path') |
| 205 | } |
| 206 | |
| 207 | const absolutePath = resolveWorkspacePath(workspaceDir, input.path) |
| 208 | const text = await fs.readFile(absolutePath, 'utf8') |
| 209 | const maxChars = |
| 210 | Number.isInteger(input.max_chars) && input.max_chars > 0 |
| 211 | ? Math.min(input.max_chars, MAX_READ_CHARS) |
| 212 | : MAX_READ_CHARS |
| 213 | |
| 214 | return { |
| 215 | ok: true, |
| 216 | path: toWorkspaceRelative(workspaceDir, absolutePath), |
| 217 | truncated: text.length > maxChars, |
| 218 | content: text.slice(0, maxChars), |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | async function writeFile(workspaceDir, input) { |
| 223 | if (typeof input.path !== 'string' || !input.path) { |
no test coverage detected