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

Function pruneFullTool

lib/messages/prune.ts:27–71  ·  view source on GitHub ↗
(state: SessionState, logger: Logger, messages: WithParts[])

Source from the content-addressed store, hash-verified

25}
26
27const pruneFullTool = (state: SessionState, logger: Logger, messages: WithParts[]): void => {
28 const messagesToRemove: string[] = []
29
30 for (const msg of messages) {
31 if (isMessageCompacted(state, msg)) {
32 continue
33 }
34
35 const parts = Array.isArray(msg.parts) ? msg.parts : []
36 const partsToRemove: string[] = []
37
38 for (const part of parts) {
39 if (part.type !== "tool") {
40 continue
41 }
42
43 if (!state.prune.tools.has(part.callID)) {
44 continue
45 }
46 if (part.tool !== "edit" && part.tool !== "write") {
47 continue
48 }
49
50 partsToRemove.push(part.callID)
51 }
52
53 if (partsToRemove.length === 0) {
54 continue
55 }
56
57 msg.parts = parts.filter(
58 (part) => part.type !== "tool" || !partsToRemove.includes(part.callID),
59 )
60
61 if (msg.parts.length === 0) {
62 messagesToRemove.push(msg.info.id)
63 }
64 }
65
66 if (messagesToRemove.length > 0) {
67 const result = messages.filter((msg) => !messagesToRemove.includes(msg.info.id))
68 messages.length = 0
69 messages.push(...result)
70 }
71}
72
73const pruneToolOutputs = (state: SessionState, logger: Logger, messages: WithParts[]): void => {
74 for (const msg of messages) {

Callers

nothing calls this directly

Calls 1

isMessageCompactedFunction · 0.90

Tested by

no test coverage detected