( tasks: CronTask[], dir?: string, )
| 163 | * the file watcher sees a change event on last-task-removed. |
| 164 | */ |
| 165 | export async function writeCronTasks( |
| 166 | tasks: CronTask[], |
| 167 | dir?: string, |
| 168 | ): Promise<void> { |
| 169 | const root = dir ?? getProjectRoot() |
| 170 | await mkdir(join(root, '.claude'), { recursive: true }) |
| 171 | // Strip the runtime-only `durable` flag — everything on disk is durable |
| 172 | // by definition, and keeping the flag out means readCronTasks() naturally |
| 173 | // yields durable: undefined without having to set it explicitly. |
| 174 | const body: CronFile = { |
| 175 | tasks: tasks.map(({ durable: _durable, ...rest }) => rest), |
| 176 | } |
| 177 | await writeFile( |
| 178 | getCronFilePath(root), |
| 179 | jsonStringify(body, null, 2) + '\n', |
| 180 | 'utf-8', |
| 181 | ) |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Append a task. Returns the generated id. Caller is responsible for having |
no test coverage detected