(
messages: Transcript,
isSidechain: boolean = false,
agentId?: string,
startingParentUuid?: UUID | null,
teamInfo?: { teamName?: string; agentName?: string },
)
| 1013 | } |
| 1014 | |
| 1015 | async insertMessageChain( |
| 1016 | messages: Transcript, |
| 1017 | isSidechain: boolean = false, |
| 1018 | agentId?: string, |
| 1019 | startingParentUuid?: UUID | null, |
| 1020 | teamInfo?: { teamName?: string; agentName?: string }, |
| 1021 | ) { |
| 1022 | return this.trackWrite(async () => { |
| 1023 | let parentUuid: UUID | null = startingParentUuid ?? null |
| 1024 | |
| 1025 | // First user/assistant message materializes the session file. |
| 1026 | // Hook progress/attachment messages alone stay buffered. |
| 1027 | if ( |
| 1028 | this.sessionFile === null && |
| 1029 | messages.some(m => m.type === 'user' || m.type === 'assistant') |
| 1030 | ) { |
| 1031 | await this.materializeSessionFile() |
| 1032 | } |
| 1033 | |
| 1034 | // Get current git branch once for this message chain |
| 1035 | let gitBranch: string | undefined |
| 1036 | try { |
| 1037 | gitBranch = await getBranch() |
| 1038 | } catch { |
| 1039 | // Not in a git repo or git command failed |
| 1040 | gitBranch = undefined |
| 1041 | } |
| 1042 | |
| 1043 | // Get slug if one exists for this session (used for plan files, etc.) |
| 1044 | const sessionId = getSessionId() |
| 1045 | const slug = getPlanSlugCache().get(sessionId) |
| 1046 | |
| 1047 | for (const message of messages) { |
| 1048 | const isCompactBoundary = isCompactBoundaryMessage(message) |
| 1049 | |
| 1050 | // For tool_result messages, use the assistant message UUID from the message |
| 1051 | // if available (set at creation time), otherwise fall back to sequential parent |
| 1052 | let effectiveParentUuid = parentUuid |
| 1053 | if ( |
| 1054 | message.type === 'user' && |
| 1055 | 'sourceToolAssistantUUID' in message && |
| 1056 | message.sourceToolAssistantUUID |
| 1057 | ) { |
| 1058 | effectiveParentUuid = message.sourceToolAssistantUUID as UUID |
| 1059 | } |
| 1060 | |
| 1061 | const transcriptMessage: TranscriptMessage = { |
| 1062 | parentUuid: isCompactBoundary ? null : effectiveParentUuid, |
| 1063 | logicalParentUuid: isCompactBoundary ? parentUuid : undefined, |
| 1064 | isSidechain, |
| 1065 | teamName: teamInfo?.teamName, |
| 1066 | agentName: teamInfo?.agentName, |
| 1067 | promptId: |
| 1068 | message.type === 'user' ? (getPromptId() ?? undefined) : undefined, |
| 1069 | agentId, |
| 1070 | ...message, |
| 1071 | // Session-stamp fields MUST come after the spread. On --fork-session |
| 1072 | // and --resume, messages arrive as SerializedMessage (carries source |
no test coverage detected