(taskListId: string)
| 147 | * Uses file locking to prevent race conditions when multiple Claudes run in parallel. |
| 148 | */ |
| 149 | export async function resetTaskList(taskListId: string): Promise<void> { |
| 150 | const dir = getTasksDir(taskListId) |
| 151 | const lockPath = await ensureTaskListLockFile(taskListId) |
| 152 | |
| 153 | let release: (() => Promise<void>) | undefined |
| 154 | try { |
| 155 | // Acquire exclusive lock on the task list |
| 156 | release = await lockfile.lock(lockPath, LOCK_OPTIONS) |
| 157 | |
| 158 | // Find the current highest ID and save it to the high water mark file |
| 159 | const currentHighest = await findHighestTaskIdFromFiles(taskListId) |
| 160 | if (currentHighest > 0) { |
| 161 | const existingMark = await readHighWaterMark(taskListId) |
| 162 | if (currentHighest > existingMark) { |
| 163 | await writeHighWaterMark(taskListId, currentHighest) |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // Delete all task files |
| 168 | let files: string[] |
| 169 | try { |
| 170 | files = await readdir(dir) |
| 171 | } catch { |
| 172 | files = [] |
| 173 | } |
| 174 | for (const file of files) { |
| 175 | if (file.endsWith('.json') && !file.startsWith('.')) { |
| 176 | const filePath = join(dir, file) |
| 177 | try { |
| 178 | await unlink(filePath) |
| 179 | } catch { |
| 180 | // Ignore errors, file may already be deleted |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | notifyTasksUpdated() |
| 185 | } finally { |
| 186 | if (release) { |
| 187 | await release() |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Gets the task list ID based on the current context. |
no test coverage detected