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

Method appendEntry

src/utils/sessionStorage.ts:1129–1266  ·  view source on GitHub ↗
(entry: Entry, sessionId: UUID = getSessionId() as UUID)

Source from the content-addressed store, hash-verified

1127 }
1128
1129 async appendEntry(entry: Entry, sessionId: UUID = getSessionId() as UUID) {
1130 if (this.shouldSkipPersistence()) {
1131 return
1132 }
1133
1134 const currentSessionId = getSessionId() as UUID
1135 const isCurrentSession = sessionId === currentSessionId
1136
1137 let sessionFile: string
1138 if (isCurrentSession) {
1139 // Buffer until materializeSessionFile runs (first user/assistant message).
1140 if (this.sessionFile === null) {
1141 this.pendingEntries.push(entry)
1142 return
1143 }
1144 sessionFile = this.sessionFile
1145 } else {
1146 const existing = await this.getExistingSessionFile(sessionId)
1147 if (!existing) {
1148 logError(
1149 new Error(
1150 `appendEntry: session file not found for other session ${sessionId}`,
1151 ),
1152 )
1153 return
1154 }
1155 sessionFile = existing
1156 }
1157
1158 // Only load current session messages if needed
1159 if (entry.type === 'summary') {
1160 // Summaries can always be appended
1161 void this.enqueueWrite(sessionFile, entry)
1162 } else if (entry.type === 'custom-title') {
1163 // Custom titles can always be appended
1164 void this.enqueueWrite(sessionFile, entry)
1165 } else if (entry.type === 'ai-title') {
1166 // AI titles can always be appended
1167 void this.enqueueWrite(sessionFile, entry)
1168 } else if (entry.type === 'last-prompt') {
1169 void this.enqueueWrite(sessionFile, entry)
1170 } else if (entry.type === 'task-summary') {
1171 void this.enqueueWrite(sessionFile, entry)
1172 } else if (entry.type === 'tag') {
1173 // Tags can always be appended
1174 void this.enqueueWrite(sessionFile, entry)
1175 } else if (entry.type === 'agent-name') {
1176 // Agent names can always be appended
1177 void this.enqueueWrite(sessionFile, entry)
1178 } else if (entry.type === 'agent-color') {
1179 // Agent colors can always be appended
1180 void this.enqueueWrite(sessionFile, entry)
1181 } else if (entry.type === 'agent-setting') {
1182 // Agent settings can always be appended
1183 void this.enqueueWrite(sessionFile, entry)
1184 } else if (entry.type === 'pr-link') {
1185 // PR links can always be appended
1186 void this.enqueueWrite(sessionFile, entry)

Calls 12

shouldSkipPersistenceMethod · 0.95
enqueueWriteMethod · 0.95
persistToRemoteMethod · 0.95
getSessionIdFunction · 0.85
getAgentTranscriptPathFunction · 0.85
getSessionMessagesFunction · 0.85
asAgentIdFunction · 0.85
isTranscriptMessageFunction · 0.85
logErrorFunction · 0.70
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected