(taskId: string)
| 398 | * Creates an empty file to ensure the path exists. |
| 399 | */ |
| 400 | export function initTaskOutput(taskId: string): Promise<string> { |
| 401 | return track( |
| 402 | (async () => { |
| 403 | await ensureOutputDir() |
| 404 | const outputPath = getTaskOutputPath(taskId) |
| 405 | // SECURITY: O_NOFOLLOW prevents symlink-following attacks from the sandbox. |
| 406 | // O_EXCL ensures we create a new file and fail if something already exists at this path. |
| 407 | // On Windows, use string flags — numeric O_EXCL can produce EINVAL through libuv. |
| 408 | const fh = await open( |
| 409 | outputPath, |
| 410 | process.platform === 'win32' |
| 411 | ? 'wx' |
| 412 | : fsConstants.O_WRONLY | |
| 413 | fsConstants.O_CREAT | |
| 414 | fsConstants.O_EXCL | |
| 415 | O_NOFOLLOW, |
| 416 | ) |
| 417 | await fh.close() |
| 418 | return outputPath |
| 419 | })(), |
| 420 | ) |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * Initialize output file as a symlink to another file (e.g., agent transcript). |
no test coverage detected