(
messages: Transcript,
isSidechain: boolean = false,
agentId?: string,
startingParentUuid?: UUID | null,
teamInfo?: { teamName?: string; agentName?: string },
)
| 1073 | } |
| 1074 | |
| 1075 | async insertMessageChain( |
| 1076 | messages: Transcript, |
| 1077 | isSidechain: boolean = false, |
| 1078 | agentId?: string, |
| 1079 | startingParentUuid?: UUID | null, |
| 1080 | teamInfo?: { teamName?: string; agentName?: string }, |
| 1081 | ) { |
| 1082 | return this.trackWrite(async () => { |
| 1083 | let parentUuid: UUID | null = startingParentUuid ?? null |
| 1084 | |
| 1085 | // First user/assistant message materializes the session file. |
| 1086 | // Hook progress/attachment messages alone stay buffered. |
| 1087 | if ( |
| 1088 | this.sessionFile === null && |
| 1089 | messages.some(m => m.type === 'user' || m.type === 'assistant') |
| 1090 | ) { |
| 1091 | await this.materializeSessionFile() |
| 1092 | } |
| 1093 | |
| 1094 | // Get current git branch once for this message chain |
| 1095 | let gitBranch: string | undefined |
| 1096 | try { |
| 1097 | gitBranch = await getBranch() |
| 1098 | } catch { |
| 1099 | // Not in a git repo or git command failed |
| 1100 | gitBranch = undefined |
| 1101 | } |
| 1102 | |
| 1103 | // Get slug if one exists for this session (used for plan files, etc.) |
| 1104 | const sessionId = getSessionId() |
| 1105 | const slug = getPlanSlugCache().get(sessionId) |
| 1106 | |
| 1107 | for (const message of messages) { |
| 1108 | const isCompactBoundary = isCompactBoundaryMessage(message) |
| 1109 | |
| 1110 | // For tool_result messages, use the assistant message UUID from the message |
| 1111 | // if available (set at creation time), otherwise fall back to sequential parent |
| 1112 | let effectiveParentUuid = parentUuid |
| 1113 | if ( |
| 1114 | message.type === 'user' && |
| 1115 | 'sourceToolAssistantUUID' in message && |
| 1116 | message.sourceToolAssistantUUID |
| 1117 | ) { |
| 1118 | effectiveParentUuid = message.sourceToolAssistantUUID |
| 1119 | } |
| 1120 | |
| 1121 | const transcriptMessage: TranscriptMessage = { |
| 1122 | parentUuid: isCompactBoundary ? null : effectiveParentUuid, |
| 1123 | logicalParentUuid: isCompactBoundary ? parentUuid : undefined, |
| 1124 | isSidechain, |
| 1125 | teamName: teamInfo?.teamName, |
| 1126 | agentName: teamInfo?.agentName, |
| 1127 | promptId: |
| 1128 | message.type === 'user' ? (getPromptId() ?? undefined) : undefined, |
| 1129 | agentId, |
| 1130 | ...message, |
| 1131 | // Session-stamp fields MUST come after the spread. On --fork-session |
| 1132 | // and --resume, messages arrive as SerializedMessage (carries source |
no test coverage detected