()
| 80 | * the file so getSessionRecordingPaths() can find it by the resumed session ID. |
| 81 | */ |
| 82 | export async function renameRecordingForSession(): Promise<void> { |
| 83 | const oldPath = recordingState.filePath |
| 84 | if (!oldPath || recordingState.timestamp === 0) { |
| 85 | return |
| 86 | } |
| 87 | const projectsDir = join(getClaudeConfigHomeDir(), 'projects') |
| 88 | const projectDir = join(projectsDir, sanitizePath(getOriginalCwd())) |
| 89 | const newPath = join( |
| 90 | projectDir, |
| 91 | `${getSessionId()}-${recordingState.timestamp}.cast`, |
| 92 | ) |
| 93 | if (oldPath === newPath) { |
| 94 | return |
| 95 | } |
| 96 | // Flush pending writes before renaming |
| 97 | await recorder?.flush() |
| 98 | const oldName = basename(oldPath) |
| 99 | const newName = basename(newPath) |
| 100 | try { |
| 101 | await rename(oldPath, newPath) |
| 102 | recordingState.filePath = newPath |
| 103 | logForDebugging(`[asciicast] Renamed recording: ${oldName} → ${newName}`) |
| 104 | } catch { |
| 105 | logForDebugging( |
| 106 | `[asciicast] Failed to rename recording from ${oldName} to ${newName}`, |
| 107 | ) |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | type AsciicastRecorder = { |
| 112 | flush(): Promise<void> |
no test coverage detected