Skip to content

Commit 279b3ff

Browse files
fix: CRITICAL FOR COPILOT USERS | moving to use completed assistant message and tool part to inject prunable tools list
1 parent ef665bf commit 279b3ff

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

lib/messages/inject.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import type { Logger } from "../logger"
33
import type { PluginConfig } from "../config"
44
import type { UserMessage } from "@opencode-ai/sdk/v2"
55
import { loadPrompt } from "../prompts"
6-
import { extractParameterKey, buildToolIdList, createSyntheticUserMessage } from "./utils"
6+
import {
7+
extractParameterKey,
8+
buildToolIdList,
9+
createSyntheticAssistantMessageWithToolPart,
10+
} from "./utils"
711
import { getFilePathFromParameters, isProtectedFilePath } from "../protected-file-patterns"
812
import { getLastUserMessage } from "../shared-utils"
913

@@ -132,6 +136,7 @@ export const insertPruneToolContext = (
132136
if (!lastUserMessage) {
133137
return
134138
}
135-
const variant = state.variant ?? (lastUserMessage.info as UserMessage).variant
136-
messages.push(createSyntheticUserMessage(lastUserMessage, prunableToolsContent, variant))
139+
messages.push(
140+
createSyntheticAssistantMessageWithToolPart(lastUserMessage, prunableToolsContent),
141+
)
137142
}

lib/messages/utils.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { UserMessage } from "@opencode-ai/sdk/v2"
55

66
const SYNTHETIC_MESSAGE_ID = "msg_01234567890123456789012345"
77
const SYNTHETIC_PART_ID = "prt_01234567890123456789012345"
8+
const SYNTHETIC_CALL_ID = "call_01234567890123456789012345"
89

910
export const createSyntheticUserMessage = (
1011
baseMessage: WithParts,
@@ -37,6 +38,50 @@ export const createSyntheticUserMessage = (
3738
}
3839
}
3940

41+
export const createSyntheticAssistantMessageWithToolPart = (
42+
baseMessage: WithParts,
43+
content: string,
44+
): WithParts => {
45+
const userInfo = baseMessage.info as UserMessage
46+
const now = Date.now()
47+
return {
48+
info: {
49+
id: SYNTHETIC_MESSAGE_ID,
50+
sessionID: userInfo.sessionID,
51+
role: "assistant",
52+
parentID: userInfo.id,
53+
modelID: userInfo.model.modelID,
54+
providerID: userInfo.model.providerID,
55+
mode: "default",
56+
path: {
57+
cwd: "/",
58+
root: "/",
59+
},
60+
time: { created: now, completed: now },
61+
cost: 0,
62+
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
63+
},
64+
parts: [
65+
{
66+
id: SYNTHETIC_PART_ID,
67+
sessionID: userInfo.sessionID,
68+
messageID: SYNTHETIC_MESSAGE_ID,
69+
type: "tool",
70+
callID: SYNTHETIC_CALL_ID,
71+
tool: "context_info",
72+
state: {
73+
status: "completed",
74+
input: {},
75+
output: content,
76+
title: "Context Info",
77+
metadata: {},
78+
time: { start: now, end: now },
79+
},
80+
},
81+
],
82+
}
83+
}
84+
4085
/**
4186
* Extracts a human-readable key from tool metadata for display purposes.
4287
*/

lib/strategies/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function getCurrentParams(
2828
const agent: string = userInfo.agent
2929
const providerId: string | undefined = userInfo.model.providerID
3030
const modelId: string | undefined = userInfo.model.modelID
31-
const variant: string | undefined = state.variant ?? userInfo.variant
31+
const variant: string | undefined = state.variant
3232

3333
return { providerId, modelId, agent, variant }
3434
}

0 commit comments

Comments
 (0)