()
| 325 | * process.exit() will kill it. |
| 326 | */ |
| 327 | export async function stopTeamMemoryWatcher(): Promise<void> { |
| 328 | if (debounceTimer) { |
| 329 | clearTimeout(debounceTimer) |
| 330 | debounceTimer = null |
| 331 | } |
| 332 | if (watcher) { |
| 333 | watcher.close() |
| 334 | watcher = null |
| 335 | } |
| 336 | // Await any in-flight push |
| 337 | if (currentPushPromise) { |
| 338 | try { |
| 339 | await currentPushPromise |
| 340 | } catch { |
| 341 | // Ignore errors during shutdown |
| 342 | } |
| 343 | } |
| 344 | // Flush pending changes that were debounced but not yet pushed |
| 345 | if (hasPendingChanges && syncState && pushSuppressedReason === null) { |
| 346 | try { |
| 347 | await pushTeamMemory(syncState) |
| 348 | } catch { |
| 349 | // Best-effort — shutdown may kill this |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Test-only: reset module state and optionally seed syncState. |
no test coverage detected