MCPcopy Index your code
hub / github.com/Opencode-DCP/opencode-dynamic-context-pruning / resolveSelection

Function resolveSelection

lib/compress/search.ts:109–197  ·  view source on GitHub ↗
(
    context: SearchContext,
    startReference: BoundaryReference,
    endReference: BoundaryReference,
)

Source from the content-addressed store, hash-verified

107}
108
109export function resolveSelection(
110 context: SearchContext,
111 startReference: BoundaryReference,
112 endReference: BoundaryReference,
113): SelectionResolution {
114 const startRawIndex = startReference.rawIndex
115 const endRawIndex = endReference.rawIndex
116 const messageIds: string[] = []
117 const messageSeen = new Set<string>()
118 const toolIds: string[] = []
119 const toolSeen = new Set<string>()
120 const requiredBlockIds: number[] = []
121 const requiredBlockSeen = new Set<number>()
122 const messageTokenById = new Map<string, number>()
123
124 for (let index = startRawIndex; index <= endRawIndex; index++) {
125 const rawMessage = context.rawMessages[index]
126 if (!rawMessage) {
127 continue
128 }
129 if (isIgnoredUserMessage(rawMessage)) {
130 continue
131 }
132
133 const messageId = rawMessage.info.id
134 if (!messageSeen.has(messageId)) {
135 messageSeen.add(messageId)
136 messageIds.push(messageId)
137 }
138
139 if (!messageTokenById.has(messageId)) {
140 messageTokenById.set(messageId, countAllMessageTokens(rawMessage))
141 }
142
143 const parts = Array.isArray(rawMessage.parts) ? rawMessage.parts : []
144 for (const part of parts) {
145 if (part.type !== "tool" || !part.callID) {
146 continue
147 }
148 if (toolSeen.has(part.callID)) {
149 continue
150 }
151 toolSeen.add(part.callID)
152 toolIds.push(part.callID)
153 }
154 }
155
156 const selectedMessageIds = new Set(messageIds)
157 const summariesInSelection: Array<{ blockId: number; rawIndex: number }> = []
158 for (const summary of context.summaryByBlockId.values()) {
159 if (!selectedMessageIds.has(summary.anchorMessageId)) {
160 continue
161 }
162
163 const anchorIndex = context.rawIndexById.get(summary.anchorMessageId)
164 if (anchorIndex === undefined) {
165 continue
166 }

Callers 2

resolveMessageFunction · 0.90
resolveRangesFunction · 0.90

Calls 2

isIgnoredUserMessageFunction · 0.90
countAllMessageTokensFunction · 0.90

Tested by

no test coverage detected