| 229 | Partial<WorkspaceApplyPatchExecutor> {} |
| 230 | |
| 231 | export class LocalWorkspaceExecutor implements WorkspaceExecutor { |
| 232 | readonly facts = LOCAL_WORKSPACE_EXECUTOR_FACTS; |
| 233 | |
| 234 | async exec(input: WorkspaceExecInput): Promise<WorkspaceExecResult> { |
| 235 | const options = { |
| 236 | cwd: input.cwd, |
| 237 | timeoutMs: input.timeoutMs, |
| 238 | ...(input.env ? { env: input.env } : {}), |
| 239 | ...(input.fdInputs ? { fdInputs: input.fdInputs } : {}), |
| 240 | ...(input.abortSignal ? { abortSignal: input.abortSignal } : {}), |
| 241 | ...(input.emitOutput ? { emitOutput: input.emitOutput } : {}), |
| 242 | ...(input.shell ? { shell: input.shell } : {}), |
| 243 | }; |
| 244 | const result = input.argv |
| 245 | ? await runProcessWithBoundedTail(input.argv[0] ?? '', input.argv.slice(1), options) |
| 246 | : await runShellWithBoundedTail(input.command, options); |
| 247 | return { |
| 248 | stdout: result.stdout, |
| 249 | stderr: result.stderr, |
| 250 | exitCode: result.timedOut ? 124 : result.aborted ? 130 : result.exitCode, |
| 251 | stdoutTruncated: result.stdoutTruncated, |
| 252 | stderrTruncated: result.stderrTruncated, |
| 253 | timedOut: result.timedOut, |
| 254 | aborted: result.aborted, |
| 255 | }; |
| 256 | } |
| 257 | |
| 258 | async readFile(input: WorkspaceReadFileInput): Promise<WorkspaceReadFileResult> { |
| 259 | if (isSupportedImagePath(input.path)) { |
| 260 | return await readWorkspaceImage(input.path); |
| 261 | } |
| 262 | const content = await fs.readFile(input.path, 'utf8'); |
| 263 | if (input.offset === undefined && input.limit === undefined) return { content }; |
| 264 | const lines = content.split('\n'); |
| 265 | const start = input.offset ?? 0; |
| 266 | const end = input.limit ? start + input.limit : lines.length; |
| 267 | return { content: lines.slice(start, end).join('\n') }; |
| 268 | } |
| 269 | |
| 270 | async writeFile(input: WorkspaceWriteFileInput): Promise<WorkspaceWriteFileResult> { |
| 271 | await fs.writeFile(input.path, input.content, 'utf8'); |
| 272 | return { |
| 273 | ok: true, |
| 274 | path: input.path, |
| 275 | bytes: Buffer.byteLength(input.content, 'utf8'), |
| 276 | }; |
| 277 | } |
| 278 | |
| 279 | async applyPatch(input: WorkspaceApplyPatchInput): Promise<WorkspaceApplyPatchResult> { |
| 280 | if (input.action !== 'update') { |
| 281 | const path = await resolveDirectoryEntryPathInScope( |
| 282 | input.cwd, |
| 283 | input.path, |
| 284 | input.label, |
| 285 | input.scope, |
| 286 | ); |
| 287 | if (input.action === 'create') await createPatchedFile(path, input.diff); |
| 288 | else await fs.unlink(path); |
nothing calls this directly
no outgoing calls
no test coverage detected