| 94 | |
| 95 | function runJob(payload) { |
| 96 | if (!/^[a-zA-Z0-9_-]+$/.test(payload || '')) throw new Error('Invalid job payload.'); |
| 97 | const { id, root } = JSON.parse(Buffer.from(payload, 'base64url').toString('utf8')); |
| 98 | if (typeof root !== 'string' || !path.isAbsolute(root)) throw new Error('Invalid project root.'); |
| 99 | const file = recordPath(id, root); |
| 100 | // Removal deletes .citadel. Retained OS entries then become inert. |
| 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.'); |