(options: SpawnSessionOptions)
| 282 | |
| 283 | // Spawn a new session (sessionId reserved for future --resume functionality) |
| 284 | const spawnSession = async (options: SpawnSessionOptions): Promise<SpawnSessionResult> => { |
| 285 | logger.debugLargeJson('[RUNNER RUN] Spawning session', options); |
| 286 | |
| 287 | const { directory, sessionId, machineId, approvedNewDirectoryCreation = true } = options; |
| 288 | const agent = options.agent ?? 'claude'; |
| 289 | const yolo = options.yolo === true; |
| 290 | const sessionType = options.sessionType ?? 'simple'; |
| 291 | const worktreeName = options.worktreeName; |
| 292 | let directoryCreated = false; |
| 293 | let spawnDirectory = directory; |
| 294 | let worktreeInfo: WorktreeInfo | null = null; |
| 295 | let happyProcess: ReturnType<typeof spawnHappyCLI> | null = null; |
| 296 | |
| 297 | if (sessionType === 'simple') { |
| 298 | try { |
| 299 | await fs.access(directory); |
| 300 | logger.debug(`[RUNNER RUN] Directory exists: ${directory}`); |
| 301 | } catch (error) { |
| 302 | logger.debug(`[RUNNER RUN] Directory doesn't exist, creating: ${directory}`); |
| 303 | |
| 304 | // Check if directory creation is approved |
| 305 | if (!approvedNewDirectoryCreation) { |
| 306 | logger.debug(`[RUNNER RUN] Directory creation not approved for: ${directory}`); |
| 307 | return { |
| 308 | type: 'requestToApproveDirectoryCreation', |
| 309 | directory |
| 310 | }; |
| 311 | } |
| 312 | |
| 313 | try { |
| 314 | await fs.mkdir(directory, { recursive: true }); |
| 315 | logger.debug(`[RUNNER RUN] Successfully created directory: ${directory}`); |
| 316 | directoryCreated = true; |
| 317 | } catch (mkdirError: any) { |
| 318 | let errorMessage = `Unable to create directory at '${directory}'. `; |
| 319 | |
| 320 | // Provide more helpful error messages based on the error code |
| 321 | if (mkdirError.code === 'EACCES') { |
| 322 | errorMessage += `Permission denied. You don't have write access to create a folder at this location. Try using a different path or check your permissions.`; |
| 323 | } else if (mkdirError.code === 'ENOTDIR') { |
| 324 | errorMessage += `A file already exists at this path or in the parent path. Cannot create a directory here. Please choose a different location.`; |
| 325 | } else if (mkdirError.code === 'ENOSPC') { |
| 326 | errorMessage += `No space left on device. Your disk is full. Please free up some space and try again.`; |
| 327 | } else if (mkdirError.code === 'EROFS') { |
| 328 | errorMessage += `The file system is read-only. Cannot create directories here. Please choose a writable location.`; |
| 329 | } else { |
| 330 | errorMessage += `System error: ${mkdirError.message || mkdirError}. Please verify the path is valid and you have the necessary permissions.`; |
| 331 | } |
| 332 | |
| 333 | logger.debug(`[RUNNER RUN] Directory creation failed: ${errorMessage}`); |
| 334 | return { |
| 335 | type: 'error', |
| 336 | errorMessage |
| 337 | }; |
| 338 | } |
| 339 | } |
| 340 | } else { |
| 341 | try { |
no test coverage detected