MCPcopy Create free account
hub / github.com/WJX20/claude-code / recordTranscript

Function recordTranscript

src/utils/sessionStorage.ts:1409–1450  ·  view source on GitHub ↗
(
  messages: Message[],
  teamInfo?: TeamInfo,
  startingParentUuidHint?: UUID,
  allMessages?: readonly Message[],
)

Source from the content-addressed store, hash-verified

1407// messagesToKeep → not a prefix → not tracked → CB gets parentUuid=null
1408// (correct: truncates --continue chain at compact boundary).
1409export async function recordTranscript(
1410 messages: Message[],
1411 teamInfo?: TeamInfo,
1412 startingParentUuidHint?: UUID,
1413 allMessages?: readonly Message[],
1414): Promise<UUID | null> {
1415 const cleanedMessages = cleanMessagesForLogging(messages, allMessages)
1416 const sessionId = getSessionId() as UUID
1417 const messageSet = await getSessionMessages(sessionId)
1418 const newMessages: typeof cleanedMessages = []
1419 let startingParentUuid: UUID | undefined = startingParentUuidHint
1420 let seenNewMessage = false
1421 for (const m of cleanedMessages) {
1422 if (messageSet.has(m.uuid as UUID)) {
1423 // Only track skipped messages that form a prefix. After compaction,
1424 // messagesToKeep appear AFTER new CB/summary, so this skips them.
1425 if (!seenNewMessage && isChainParticipant(m)) {
1426 startingParentUuid = m.uuid as UUID
1427 }
1428 } else {
1429 newMessages.push(m)
1430 seenNewMessage = true
1431 }
1432 }
1433 if (newMessages.length > 0) {
1434 await getProject().insertMessageChain(
1435 newMessages,
1436 false,
1437 undefined,
1438 startingParentUuid,
1439 teamInfo,
1440 )
1441 }
1442 // Return the last ACTUALLY recorded chain-participant's UUID, OR the
1443 // prefix-tracked UUID if no new chain participants were recorded. This lets
1444 // callers (useLogMessages) maintain the correct parent chain even when the
1445 // slice is all-recorded (rewind, /resume scenarios where every message is
1446 // already in messageSet). Progress is skipped — it's written to the JSONL
1447 // but nothing chains TO it (see isChainParticipant).
1448 const lastRecorded = newMessages.findLast(isChainParticipant)
1449 return (lastRecorded?.uuid as UUID | undefined) ?? startingParentUuid ?? null
1450}
1451
1452export async function recordSidechainTranscript(
1453 messages: Message[],

Callers 4

submitMessageMethod · 0.85
handleOrphanedPermissionFunction · 0.85
useLogMessagesFunction · 0.85

Calls 7

cleanMessagesForLoggingFunction · 0.85
getSessionIdFunction · 0.85
getSessionMessagesFunction · 0.85
isChainParticipantFunction · 0.85
getProjectFunction · 0.85
insertMessageChainMethod · 0.80
hasMethod · 0.45

Tested by

no test coverage detected