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