Skip to content

Commit 78b8373

Browse files
authored
Merge pull request #382 from Opencode-DCP/dev
merge dev into master
2 parents 11e3774 + 253d004 commit 78b8373

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

lib/messages/inject.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,20 @@ const shouldInjectCompressNudge = (
117117
return false
118118
}
119119

120+
const lastAssistant = messages.findLast((msg) => msg.info.role === "assistant")
121+
if (lastAssistant) {
122+
const parts = Array.isArray(lastAssistant.parts) ? lastAssistant.parts : []
123+
const hasDcpTool = parts.some(
124+
(part) =>
125+
part.type === "tool" &&
126+
part.state.status === "completed" &&
127+
(part.tool === "compress" || part.tool === "prune" || part.tool === "distill"),
128+
)
129+
if (hasDcpTool) {
130+
return false
131+
}
132+
}
133+
120134
const contextLimit = resolveContextLimit(config, state, providerId, modelId)
121135
if (contextLimit === undefined) {
122136
return false

lib/messages/prune.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const PRUNED_TOOL_OUTPUT_REPLACEMENT =
99
"[Output removed to save context - information superseded or no longer needed]"
1010
const PRUNED_TOOL_ERROR_INPUT_REPLACEMENT = "[input removed due to failed tool call]"
1111
const PRUNED_QUESTION_INPUT_REPLACEMENT = "[questions removed - see output for user's answers]"
12+
const PRUNED_COMPRESS_INPUT_REPLACEMENT =
13+
"[compress content removed - topic retained for reference]"
1214

1315
export const prune = (
1416
state: SessionState,
@@ -39,11 +41,6 @@ const pruneFullTool = (state: SessionState, logger: Logger, messages: WithParts[
3941
continue
4042
}
4143

42-
if (part.tool === "compress" && part.state.status === "completed") {
43-
partsToRemove.push(part.callID)
44-
continue
45-
}
46-
4744
if (!state.prune.tools.has(part.callID)) {
4845
continue
4946
}
@@ -111,6 +108,13 @@ const pruneToolInputs = (state: SessionState, logger: Logger, messages: WithPart
111108
if (part.type !== "tool") {
112109
continue
113110
}
111+
if (part.tool === "compress" && part.state.status === "completed") {
112+
if (part.state.input?.content !== undefined) {
113+
part.state.input.content = PRUNED_COMPRESS_INPUT_REPLACEMENT
114+
}
115+
continue
116+
}
117+
114118
if (!state.prune.tools.has(part.callID)) {
115119
continue
116120
}

lib/tools/utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { partial_ratio } from "fuzzball"
22
import type { WithParts } from "../state"
33
import type { Logger } from "../logger"
4+
import { isIgnoredUserMessage } from "../messages/utils"
45

56
export interface FuzzyConfig {
67
minScore: number
@@ -25,6 +26,9 @@ function extractMessageContent(msg: WithParts): string {
2526

2627
for (const part of parts) {
2728
const p = part as Record<string, unknown>
29+
if ((part as any).ignored) {
30+
continue
31+
}
2832

2933
switch (part.type) {
3034
case "text":
@@ -81,6 +85,9 @@ function findExactMatches(messages: WithParts[], searchString: string): MatchRes
8185

8286
for (let i = 0; i < messages.length; i++) {
8387
const msg = messages[i]
88+
if (isIgnoredUserMessage(msg)) {
89+
continue
90+
}
8491
const content = extractMessageContent(msg)
8592
if (content.includes(searchString)) {
8693
matches.push({
@@ -104,6 +111,9 @@ function findFuzzyMatches(
104111

105112
for (let i = 0; i < messages.length; i++) {
106113
const msg = messages[i]
114+
if (isIgnoredUserMessage(msg)) {
115+
continue
116+
}
107117
const content = extractMessageContent(msg)
108118
const score = partial_ratio(searchString, content)
109119
if (score >= minScore) {
@@ -145,7 +155,7 @@ export function findStringInMessages(
145155
const fuzzyMatches = findFuzzyMatches(searchableMessages, searchString, fuzzyConfig.minScore)
146156

147157
if (fuzzyMatches.length === 0) {
148-
if (lastMessage) {
158+
if (lastMessage && !isIgnoredUserMessage(lastMessage)) {
149159
const lastMsgContent = extractMessageContent(lastMessage)
150160
const lastMsgIndex = messages.length - 1
151161
if (lastMsgContent.includes(searchString)) {

0 commit comments

Comments
 (0)