MCPcopy Create free account
hub / github.com/IgorWarzocha/howcode / buildThreadHistorySlice

Function buildThreadHistorySlice

shared/thread-history.ts:140–175  ·  view source on GitHub ↗
(
  pathEntries: SessionPathEntry[],
  revealedCompactions: number,
)

Source from the content-addressed store, hash-verified

138}
139
140export function buildThreadHistorySlice(
141 pathEntries: SessionPathEntry[],
142 revealedCompactions: number,
143) {
144 const selectedCompactionIndex = getSelectedCompactionIndex(pathEntries, revealedCompactions)
145 if (selectedCompactionIndex === -1) {
146 return {
147 sourceMessages: buildSourceMessagesFromPathEntries(pathEntries),
148 previousMessageCount: 0,
149 }
150 }
151
152 const selectedCompaction = pathEntries[selectedCompactionIndex]
153 const firstKeptEntryId = selectedCompaction?.firstKeptEntryId
154 const firstKeptIndex = firstKeptEntryId ? findEntryIndexById(pathEntries, firstKeptEntryId) : -1
155
156 if (!selectedCompaction || firstKeptIndex === -1 || firstKeptIndex > selectedCompactionIndex) {
157 return {
158 sourceMessages: buildSourceMessagesFromPathEntries(pathEntries),
159 previousMessageCount: 0,
160 }
161 }
162
163 const sourceMessages: AgentMessage[] = []
164 appendSourceMessagesFromEntryRange(
165 sourceMessages,
166 pathEntries,
167 firstKeptIndex,
168 pathEntries.length,
169 )
170
171 return {
172 sourceMessages,
173 previousMessageCount: countDisplayableEntriesInRange(pathEntries, 0, firstKeptIndex),
174 }
175}

Callers 3

buildLiveThreadDataFunction · 0.90
buildLiveThreadDataFunction · 0.90
loadThreadSnapshotFunction · 0.90

Tested by

no test coverage detected