(rootEntries: Array<{ rootPath: string; label?: string }>)
| 429 | } |
| 430 | |
| 431 | function syncKnownRoots(rootEntries: Array<{ rootPath: string; label?: string }>): void { |
| 432 | const nextRoots = new Map<string, { rootPath: string; label?: string }>(); |
| 433 | const normalizedRoots = |
| 434 | rootEntries.length > 0 ? rootEntries : primaryRootPath ? [{ rootPath: primaryRootPath }] : []; |
| 435 | |
| 436 | for (const entry of normalizedRoots) { |
| 437 | const resolvedRootPath = path.resolve(entry.rootPath); |
| 438 | nextRoots.set(normalizeRootKey(resolvedRootPath), { |
| 439 | rootPath: resolvedRootPath, |
| 440 | label: entry.label?.trim() || undefined |
| 441 | }); |
| 442 | } |
| 443 | |
| 444 | // Always include config-registered roots — config is additive (REPO-03) |
| 445 | for (const [rootKey, rootEntry] of configRoots.entries()) { |
| 446 | if (!nextRoots.has(rootKey)) { |
| 447 | nextRoots.set(rootKey, rootEntry); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | for (const [rootKey, existingRoot] of knownRoots.entries()) { |
| 452 | if (!nextRoots.has(rootKey)) { |
| 453 | removeProject(existingRoot.rootPath); |
| 454 | forgetProjectPath(existingRoot.rootPath); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | for (const project of getAllProjects()) { |
| 459 | const stillAllowed = Array.from(nextRoots.values()).some((knownRoot) => |
| 460 | isPathWithin(knownRoot.rootPath, project.rootPath) |
| 461 | ); |
| 462 | if (!stillAllowed) { |
| 463 | removeProject(project.rootPath); |
| 464 | forgetProjectPath(project.rootPath); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | knownRoots.clear(); |
| 469 | clearDiscoveredProjectPaths(); |
| 470 | for (const [rootKey, rootEntry] of nextRoots.entries()) { |
| 471 | knownRoots.set(rootKey, rootEntry); |
| 472 | rememberProjectPath(rootEntry.rootPath, 'root', { touch: false }); |
| 473 | } |
| 474 | |
| 475 | if (activeProjectKey) { |
| 476 | if (!getTrackedRootPathByKey(activeProjectKey)) { |
| 477 | activeProjectKey = undefined; |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | function parseProjectSelector(value: unknown): string | undefined { |
| 483 | if (typeof value !== 'string') return undefined; |
no test coverage detected