()
| 55 | * the file so getSessionRecordingPaths() can find it by the resumed session ID. |
| 56 | */ |
| 57 | export async function renameRecordingForSession(): Promise<void> { |
| 58 | const oldPath = recordingState.filePath |
| 59 | if (!oldPath || recordingState.timestamp === 0) { |
| 60 | return |
| 61 | } |
| 62 | const projectsDir = join(getClaudeConfigHomeDir(), 'projects') |
| 63 | const projectDir = join(projectsDir, sanitizePath(getOriginalCwd())) |
| 64 | const newPath = join( |
| 65 | projectDir, |
| 66 | `${getSessionId()}-${recordingState.timestamp}.cast`, |
| 67 | ) |
| 68 | if (oldPath === newPath) { |
| 69 | return |
| 70 | } |
| 71 | // Flush pending writes before renaming |
| 72 | await recorder?.flush() |
| 73 | const oldName = basename(oldPath) |
| 74 | const newName = basename(newPath) |
| 75 | try { |
| 76 | await rename(oldPath, newPath) |
| 77 | recordingState.filePath = newPath |
| 78 | logForDebugging(`[asciicast] Renamed recording: ${oldName} → ${newName}`) |
| 79 | } catch { |
| 80 | logForDebugging( |
| 81 | `[asciicast] Failed to rename recording from ${oldName} to ${newName}`, |
| 82 | ) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | type AsciicastRecorder = { |
| 87 | flush(): Promise<void> |
no test coverage detected