Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions lib/messages/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
extractParameterKey,
buildToolIdList,
createSyntheticAssistantMessageWithToolPart,
createSyntheticUserMessage,
} from "./utils"
import { getFilePathFromParameters, isProtectedFilePath } from "../protected-file-patterns"
import { getLastUserMessage } from "../shared-utils"
Expand Down Expand Up @@ -143,22 +142,15 @@ export const insertPruneToolContext = (
const isGitHubCopilot =
providerID === "github-copilot" || providerID === "github-copilot-enterprise"

logger.info("Injecting prunable-tools list", {
providerID,
isGitHubCopilot,
injectionType: isGitHubCopilot ? "assistant-with-tool-part" : "user-message",
})

const variant = state.variant ?? (lastUserMessage.info as UserMessage).variant
if (isGitHubCopilot) {
messages.push(
createSyntheticAssistantMessageWithToolPart(
lastUserMessage,
prunableToolsContent,
variant,
),
)
} else {
messages.push(createSyntheticUserMessage(lastUserMessage, prunableToolsContent, variant))
const lastMessage = messages[messages.length - 1]
if (lastMessage?.info?.role === "user") {
return
}
}

const variant = state.variant ?? userInfo.variant
messages.push(
createSyntheticAssistantMessageWithToolPart(lastUserMessage, prunableToolsContent, variant),
)
}
31 changes: 0 additions & 31 deletions lib/messages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,6 @@ const SYNTHETIC_MESSAGE_ID = "msg_01234567890123456789012345"
const SYNTHETIC_PART_ID = "prt_01234567890123456789012345"
const SYNTHETIC_CALL_ID = "call_01234567890123456789012345"

export const createSyntheticUserMessage = (
baseMessage: WithParts,
content: string,
variant?: string,
): WithParts => {
const userInfo = baseMessage.info as UserMessage
return {
info: {
id: SYNTHETIC_MESSAGE_ID,
sessionID: userInfo.sessionID,
role: "user",
time: { created: Date.now() },
agent: userInfo.agent || "code",
model: {
providerID: userInfo.model.providerID,
modelID: userInfo.model.modelID,
},
...(variant !== undefined && { variant }),
},
parts: [
{
id: SYNTHETIC_PART_ID,
sessionID: userInfo.sessionID,
messageID: SYNTHETIC_MESSAGE_ID,
type: "text",
text: content,
},
],
}
}

export const createSyntheticAssistantMessageWithToolPart = (
baseMessage: WithParts,
content: string,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@tarquinen/opencode-dcp",
"version": "1.1.6",
"version": "1.1.7-beta.0",
"type": "module",
"description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context",
"main": "./dist/index.js",
Expand Down