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