( log: LogOption, targetSessionId: SessionId, )
| 237 | * and forked sessions from clobbering each other's plan files. |
| 238 | */ |
| 239 | export async function copyPlanForFork( |
| 240 | log: LogOption, |
| 241 | targetSessionId: SessionId, |
| 242 | ): Promise<boolean> { |
| 243 | const originalSlug = getSlugFromLog(log) |
| 244 | if (!originalSlug) { |
| 245 | return false |
| 246 | } |
| 247 | |
| 248 | const plansDir = getPlansDirectory() |
| 249 | const originalPlanPath = join(plansDir, `${originalSlug}.md`) |
| 250 | |
| 251 | // Generate a new slug for the forked session (do NOT reuse the original) |
| 252 | const newSlug = getPlanSlug(targetSessionId) |
| 253 | const newPlanPath = join(plansDir, `${newSlug}.md`) |
| 254 | try { |
| 255 | await copyFile(originalPlanPath, newPlanPath) |
| 256 | return true |
| 257 | } catch (error) { |
| 258 | if (isENOENT(error)) { |
| 259 | return false |
| 260 | } |
| 261 | logError(error) |
| 262 | return false |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Recover plan content from the message history. Plan content can appear in |
no test coverage detected