(sessionId?: SessionId)
| 30 | * If a plan file with the generated slug already exists, retries up to 10 times. |
| 31 | */ |
| 32 | export function getPlanSlug(sessionId?: SessionId): string { |
| 33 | const id = sessionId ?? getSessionId() |
| 34 | const cache = getPlanSlugCache() |
| 35 | let slug = cache.get(id) |
| 36 | if (!slug) { |
| 37 | const plansDir = getPlansDirectory() |
| 38 | // Try to find a unique slug that doesn't conflict with existing files |
| 39 | for (let i = 0; i < MAX_SLUG_RETRIES; i++) { |
| 40 | slug = generateWordSlug() |
| 41 | const filePath = join(plansDir, `${slug}.md`) |
| 42 | if (!getFsImplementation().existsSync(filePath)) { |
| 43 | break |
| 44 | } |
| 45 | } |
| 46 | cache.set(id, slug!) |
| 47 | } |
| 48 | return slug! |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Set a specific plan slug for a session (used when resuming a session) |
no test coverage detected