( command: HistoryEntry | string, )
| 353 | } |
| 354 | |
| 355 | async function addToPromptHistory( |
| 356 | command: HistoryEntry | string, |
| 357 | ): Promise<void> { |
| 358 | const entry = |
| 359 | typeof command === 'string' |
| 360 | ? { display: command, pastedContents: {} } |
| 361 | : command |
| 362 | |
| 363 | const storedPastedContents: Record<number, StoredPastedContent> = {} |
| 364 | if (entry.pastedContents) { |
| 365 | for (const [id, content] of Object.entries(entry.pastedContents)) { |
| 366 | // Filter out images (they're stored separately in image-cache) |
| 367 | if (content.type === 'image') { |
| 368 | continue |
| 369 | } |
| 370 | |
| 371 | // For small text content, store inline |
| 372 | if (content.content.length <= MAX_PASTED_CONTENT_LENGTH) { |
| 373 | storedPastedContents[Number(id)] = { |
| 374 | id: content.id, |
| 375 | type: content.type, |
| 376 | content: content.content, |
| 377 | mediaType: content.mediaType, |
| 378 | filename: content.filename, |
| 379 | } |
| 380 | } else { |
| 381 | // For large text content, compute hash synchronously and store reference |
| 382 | // The actual disk write happens async (fire-and-forget) |
| 383 | const hash = hashPastedText(content.content) |
| 384 | storedPastedContents[Number(id)] = { |
| 385 | id: content.id, |
| 386 | type: content.type, |
| 387 | contentHash: hash, |
| 388 | mediaType: content.mediaType, |
| 389 | filename: content.filename, |
| 390 | } |
| 391 | // Fire-and-forget disk write - don't block history entry creation |
| 392 | void storePastedText(hash, content.content) |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | const logEntry: LogEntry = { |
| 398 | ...entry, |
| 399 | pastedContents: storedPastedContents, |
| 400 | timestamp: Date.now(), |
| 401 | project: getProjectRoot(), |
| 402 | sessionId: getSessionId(), |
| 403 | } |
| 404 | |
| 405 | pendingEntries.push(logEntry) |
| 406 | lastAddedEntry = logEntry |
| 407 | currentFlushPromise = flushPromptHistory(0) |
| 408 | void currentFlushPromise |
| 409 | } |
| 410 | |
| 411 | export function addToHistory(command: HistoryEntry | string): void { |
| 412 | // Skip history when running in a tmux session spawned by Claude Code's Tungsten tool. |
no test coverage detected