| 101 | if (!fs.existsSync(file)) return; |
| 102 | const job = JSON.parse(fs.readFileSync(file, 'utf8')); |
| 103 | if (job.id !== id || job.projectRoot !== root || typeof job.command !== 'string' || !job.command.trim()) { |
| 104 | throw new Error('Invalid schedule record.'); |
| 105 | } |
| 106 | const invocation = platformInvocation({ command: 'claude', args: ['--permission-mode', 'default', '-p', '--', job.command] }); |
| 107 | const result = spawnSync(invocation.command, invocation.args, { cwd: root, shell: false, stdio: 'inherit', env: { ...process.env, CLAUDE_PROJECT_DIR: root } }); |
| 108 | if (result.error) throw result.error; |
| 109 | process.exitCode = result.status === null ? 1 : result.status; |