MCPcopy Create free account
hub / github.com/HELPMEEADICE/doge-code / insertMessageChain

Method insertMessageChain

src/utils/sessionStorage.ts:1039–1129  ·  view source on GitHub ↗
(
    messages: Transcript,
    isSidechain: boolean = false,
    agentId?: string,
    startingParentUuid?: UUID | null,
    teamInfo?: { teamName?: string; agentName?: string },
  )

Source from the content-addressed store, hash-verified

1037 }
1038
1039 async insertMessageChain(
1040 messages: Transcript,
1041 isSidechain: boolean = false,
1042 agentId?: string,
1043 startingParentUuid?: UUID | null,
1044 teamInfo?: { teamName?: string; agentName?: string },
1045 ) {
1046 return this.trackWrite(async () => {
1047 let parentUuid: UUID | null = startingParentUuid ?? null
1048
1049 // First user/assistant message materializes the session file.
1050 // Hook progress/attachment messages alone stay buffered.
1051 if (
1052 this.sessionFile === null &&
1053 messages.some(m => m.type === 'user' || m.type === 'assistant')
1054 ) {
1055 await this.materializeSessionFile()
1056 }
1057
1058 // Get current git branch once for this message chain
1059 let gitBranch: string | undefined
1060 try {
1061 gitBranch = await getBranch()
1062 } catch {
1063 // Not in a git repo or git command failed
1064 gitBranch = undefined
1065 }
1066
1067 // Get slug if one exists for this session (used for plan files, etc.)
1068 const sessionId = getSessionId()
1069 const slug = getPlanSlugCache().get(sessionId)
1070
1071 for (const message of messages) {
1072 const isCompactBoundary = isCompactBoundaryMessage(message)
1073
1074 // For tool_result messages, use the assistant message UUID from the message
1075 // if available (set at creation time), otherwise fall back to sequential parent
1076 let effectiveParentUuid = parentUuid
1077 if (
1078 message.type === 'user' &&
1079 'sourceToolAssistantUUID' in message &&
1080 message.sourceToolAssistantUUID
1081 ) {
1082 effectiveParentUuid = message.sourceToolAssistantUUID
1083 }
1084
1085 const transcriptMessage: TranscriptMessage = {
1086 parentUuid: isCompactBoundary ? null : effectiveParentUuid,
1087 logicalParentUuid: isCompactBoundary ? parentUuid : undefined,
1088 isSidechain,
1089 teamName: teamInfo?.teamName,
1090 agentName: teamInfo?.agentName,
1091 promptId:
1092 message.type === 'user' ? (getPromptId() ?? undefined) : undefined,
1093 agentId,
1094 ...message,
1095 // Session-stamp fields MUST come after the spread. On --fork-session
1096 // and --resume, messages arrive as SerializedMessage (carries source

Callers 2

recordTranscriptFunction · 0.80

Calls 14

trackWriteMethod · 0.95
appendEntryMethod · 0.95
getBranchFunction · 0.85
getSessionIdFunction · 0.85
getPlanSlugCacheFunction · 0.85
isCompactBoundaryMessageFunction · 0.85
getPromptIdFunction · 0.85
getUserTypeFunction · 0.85
getEntrypointFunction · 0.85
getCwdFunction · 0.85
isChainParticipantFunction · 0.85

Tested by

no test coverage detected