Skip to content

Commit b28f212

Browse files
authored
Merge pull request #246 from Opencode-DCP/beta
merge beta into master
2 parents 4861dd7 + 07f3f24 commit b28f212

File tree

3 files changed

+13
-50
lines changed

3 files changed

+13
-50
lines changed

lib/messages/inject.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
extractParameterKey,
88
buildToolIdList,
99
createSyntheticAssistantMessageWithToolPart,
10-
createSyntheticUserMessage,
1110
} from "./utils"
1211
import { getFilePathFromParameters, isProtectedFilePath } from "../protected-file-patterns"
1312
import { getLastUserMessage } from "../shared-utils"
@@ -140,25 +139,20 @@ export const insertPruneToolContext = (
140139

141140
const userInfo = lastUserMessage.info as UserMessage
142141
const providerID = userInfo.model.providerID
142+
const modelID = userInfo.model.modelID
143143
const isGitHubCopilot =
144144
providerID === "github-copilot" || providerID === "github-copilot-enterprise"
145+
const isAnthropic = modelID.includes("claude")
145146

146-
logger.info("Injecting prunable-tools list", {
147-
providerID,
148-
isGitHubCopilot,
149-
injectionType: isGitHubCopilot ? "assistant-with-tool-part" : "user-message",
150-
})
151-
152-
const variant = state.variant ?? (lastUserMessage.info as UserMessage).variant
153-
if (isGitHubCopilot) {
154-
messages.push(
155-
createSyntheticAssistantMessageWithToolPart(
156-
lastUserMessage,
157-
prunableToolsContent,
158-
variant,
159-
),
160-
)
161-
} else {
162-
messages.push(createSyntheticUserMessage(lastUserMessage, prunableToolsContent, variant))
147+
if (isGitHubCopilot || isAnthropic) {
148+
const lastMessage = messages[messages.length - 1]
149+
if (lastMessage?.info?.role === "user") {
150+
return
151+
}
163152
}
153+
154+
const variant = state.variant ?? userInfo.variant
155+
messages.push(
156+
createSyntheticAssistantMessageWithToolPart(lastUserMessage, prunableToolsContent, variant),
157+
)
164158
}

lib/messages/utils.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,6 @@ const SYNTHETIC_MESSAGE_ID = "msg_01234567890123456789012345"
77
const SYNTHETIC_PART_ID = "prt_01234567890123456789012345"
88
const SYNTHETIC_CALL_ID = "call_01234567890123456789012345"
99

10-
export const createSyntheticUserMessage = (
11-
baseMessage: WithParts,
12-
content: string,
13-
variant?: string,
14-
): WithParts => {
15-
const userInfo = baseMessage.info as UserMessage
16-
return {
17-
info: {
18-
id: SYNTHETIC_MESSAGE_ID,
19-
sessionID: userInfo.sessionID,
20-
role: "user",
21-
time: { created: Date.now() },
22-
agent: userInfo.agent || "code",
23-
model: {
24-
providerID: userInfo.model.providerID,
25-
modelID: userInfo.model.modelID,
26-
},
27-
...(variant !== undefined && { variant }),
28-
},
29-
parts: [
30-
{
31-
id: SYNTHETIC_PART_ID,
32-
sessionID: userInfo.sessionID,
33-
messageID: SYNTHETIC_MESSAGE_ID,
34-
type: "text",
35-
text: content,
36-
},
37-
],
38-
}
39-
}
40-
4110
export const createSyntheticAssistantMessageWithToolPart = (
4211
baseMessage: WithParts,
4312
content: string,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://json.schemastore.org/package.json",
33
"name": "@tarquinen/opencode-dcp",
4-
"version": "1.1.6",
4+
"version": "1.1.7-beta.1",
55
"type": "module",
66
"description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context",
77
"main": "./dist/index.js",

0 commit comments

Comments
 (0)