MCPcopy Index your code
hub / github.com/codeaashu/claude-code / installAsciicastRecorder

Function installAsciicastRecorder

src/utils/asciicast.ts:140–239  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

138 * Must be called before Ink mounts.
139 */
140export function installAsciicastRecorder(): void {
141 const filePath = getRecordFilePath()
142 if (!filePath) {
143 return
144 }
145
146 const { cols, rows } = getTerminalSize()
147 const startTime = performance.now()
148
149 // Write the asciicast v2 header
150 const header = jsonStringify({
151 version: 2,
152 width: cols,
153 height: rows,
154 timestamp: Math.floor(Date.now() / 1000),
155 env: {
156 SHELL: process.env.SHELL || '',
157 TERM: process.env.TERM || '',
158 },
159 })
160
161 try {
162 // eslint-disable-next-line custom-rules/no-sync-fs -- one-time init before Ink mounts
163 getFsImplementation().mkdirSync(dirname(filePath))
164 } catch {
165 // Directory may already exist
166 }
167 // eslint-disable-next-line custom-rules/no-sync-fs -- one-time init before Ink mounts
168 getFsImplementation().appendFileSync(filePath, header + '\n', { mode: 0o600 })
169
170 let pendingWrite: Promise<void> = Promise.resolve()
171
172 const writer = createBufferedWriter({
173 writeFn(content: string) {
174 // Use recordingState.filePath (mutable) so writes follow renames from --resume
175 const currentPath = recordingState.filePath
176 if (!currentPath) {
177 return
178 }
179 pendingWrite = pendingWrite
180 .then(() => appendFile(currentPath, content))
181 .catch(() => {
182 // Silently ignore write errors — don't break the session
183 })
184 },
185 flushIntervalMs: 500,
186 maxBufferSize: 50,
187 maxBufferBytes: 10 * 1024 * 1024, // 10MB
188 })
189
190 // Wrap process.stdout.write to capture output
191 const originalWrite = process.stdout.write.bind(
192 process.stdout,
193 ) as typeof process.stdout.write
194 process.stdout.write = function (
195 chunk: string | Uint8Array,
196 encodingOrCb?: BufferEncoding | ((err?: Error) => void),
197 cb?: (err?: Error) => void,

Callers 1

runFunction · 0.85

Calls 12

getRecordFilePathFunction · 0.85
getTerminalSizeFunction · 0.85
jsonStringifyFunction · 0.85
getFsImplementationFunction · 0.85
createBufferedWriterFunction · 0.85
registerCleanupFunction · 0.85
logForDebuggingFunction · 0.85
onMethod · 0.80
toStringMethod · 0.65
disposeMethod · 0.65
resolveMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected