* Point the file watcher at the current tasks directory. Called on start * and whenever #fetch detects the task list ID has changed (e.g. when * TeamCreateTool sets leaderTeamName mid-session).
(dir: string)
| 88 | * TeamCreateTool sets leaderTeamName mid-session). |
| 89 | */ |
| 90 | #rewatch(dir: string): void { |
| 91 | // Retry even on same dir if the previous watch attempt failed (dir |
| 92 | // didn't exist yet). Once the watcher is established, same-dir is a no-op. |
| 93 | if (dir === this.#watchedDir && this.#watcher !== null) return |
| 94 | this.#watcher?.close() |
| 95 | this.#watcher = null |
| 96 | this.#watchedDir = dir |
| 97 | try { |
| 98 | this.#watcher = watch(dir, this.#debouncedFetch) |
| 99 | this.#watcher.unref() |
| 100 | } catch { |
| 101 | // Directory may not exist yet (ensureTasksDir is called by writers). |
| 102 | // Not critical — onTasksUpdated covers in-process updates and the |
| 103 | // poll timer covers cross-process updates. |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | #debouncedFetch = (): void => { |
| 108 | if (this.#debounceTimer) clearTimeout(this.#debounceTimer) |