* Removes command files for workflows that are no longer selected in the active profile. * Returns the number of files removed.
(
projectPath: string,
toolId: string,
desiredWorkflows: readonly (typeof ALL_WORKFLOWS)[number][]
)
| 484 | * Returns the number of files removed. |
| 485 | */ |
| 486 | private async removeUnselectedCommandFiles( |
| 487 | projectPath: string, |
| 488 | toolId: string, |
| 489 | desiredWorkflows: readonly (typeof ALL_WORKFLOWS)[number][] |
| 490 | ): Promise<number> { |
| 491 | let removed = 0; |
| 492 | |
| 493 | const adapter = CommandAdapterRegistry.get(toolId); |
| 494 | if (!adapter) return 0; |
| 495 | |
| 496 | const desiredSet = new Set(desiredWorkflows); |
| 497 | |
| 498 | for (const workflow of ALL_WORKFLOWS) { |
| 499 | if (desiredSet.has(workflow)) continue; |
| 500 | const cmdPath = adapter.getFilePath(workflow); |
| 501 | const fullPath = path.isAbsolute(cmdPath) ? cmdPath : path.join(projectPath, cmdPath); |
| 502 | |
| 503 | try { |
| 504 | if (fs.existsSync(fullPath)) { |
| 505 | await fs.promises.unlink(fullPath); |
| 506 | removed++; |
| 507 | } |
| 508 | } catch { |
| 509 | // Ignore errors |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | return removed; |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * Detect and handle legacy OpenSpec artifacts. |
no test coverage detected