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