Skip to content

Commit efa299c

Browse files
committed
refactor: gate ID injection on compress permission
1 parent 63ed2c2 commit efa299c

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

lib/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export function createChatMessageTransformHandler(
120120

121121
prune(state, logger, config, output.messages)
122122
insertPruneToolContext(state, config, logger, output.messages)
123-
insertMessageIdContext(state, output.messages)
123+
insertMessageIdContext(state, config, output.messages)
124124

125125
applyPendingManualTriggerPrompt(state, output.messages, logger)
126126

lib/message-ids.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function parseBoundaryId(id: string): ParsedBoundaryId | null {
8484
}
8585

8686
export function formatMessageIdTag(ref: string): string {
87-
return `<${MESSAGE_ID_TAG_NAME}>${ref}</${MESSAGE_ID_TAG_NAME}>`
87+
return `\n<${MESSAGE_ID_TAG_NAME}>${ref}</${MESSAGE_ID_TAG_NAME}>`
8888
}
8989

9090
export function assignMessageRefs(state: SessionState, messages: WithParts[]): number {

lib/messages/inject.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export const insertPruneToolContext = (
288288
return
289289
}
290290

291-
const combinedContent = contentParts.join("\n")
291+
const combinedContent = `\n${contentParts.join("\n")}`
292292

293293
if (!lastUserMessage) {
294294
return
@@ -324,7 +324,15 @@ export const insertPruneToolContext = (
324324
}
325325
}
326326

327-
export const insertMessageIdContext = (state: SessionState, messages: WithParts[]): void => {
327+
export const insertMessageIdContext = (
328+
state: SessionState,
329+
config: PluginConfig,
330+
messages: WithParts[],
331+
): void => {
332+
if (config.tools.compress.permission === "deny") {
333+
return
334+
}
335+
328336
const lastUserMessage = getLastUserMessage(messages)
329337
const toolModelId = lastUserMessage
330338
? ((lastUserMessage.info as UserMessage).model.modelID ?? "")

lib/messages/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ export const appendMessageIdTagToToolOutput = (part: ToolPart, tag: string): boo
115115
return true
116116
}
117117

118-
const separator = part.state.output.length > 0 && !part.state.output.endsWith("\n") ? "\n" : ""
119-
part.state.output = `${part.state.output}${separator}${tag}`
118+
part.state.output = `${part.state.output}${tag}`
120119
return true
121120
}
122121

lib/prompts/system.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ AVAILABLE TOOLS FOR CONTEXT MANAGEMENT
1414
<compress>THE COMPRESS TOOL
1515
`compress` is a sledgehammer and should be used accordingly. It's purpose is to reduce whole part of the conversation to its essence and technical details in order to leave room for newer context. Your summary MUST be technical and specific enough to preserve FULL understanding of WHAT TRANSPIRED, such that NO AMBIGUITY remains about what was done, found, or decided. Your compress summary must be thorough and precise. `compress` will replace everything in the range you match, user and assistant messages, tool inputs and outputs. It is preferred to not compress preemptively, but rather wait for natural breakpoints in the conversation. Those breakpoints are to be infered from user messages. You WILL NOT compress based on thinking that you are done with the task, wait for conversation queues that the user has moved on from current phase. Use injected boundary IDs (`startId`/`endId`) to select ranges.
1616

17+
Injected boundary IDs are surfaced as XML tags in conversation context, e.g. `<dcp-message-id>m0001</dcp-message-id>` for message IDs and `<dcp-message-id>b3</dcp-message-id>` for compressed blocks. These IDs are internal boundary markers for `compress` only. Do not reference, explain, or surface these IDs in normal user-facing responses unless you are actively constructing a `compress` tool call.
18+
1719
This tool will typically be used at the end of a phase of work, when conversation starts to accumulate noise that would better served summarized, or when you've done significant exploration and can FULLY synthesize your findings and understanding into a technical summary.
1820

1921
Use only injected `mNNNN`/`bN` IDs that are visible in the current context. If compressed blocks are included in your range, preserve their content through required `(bN)` placeholders in your summary. Be VERY CAREFUL AND CONSERVATIVE when using `compress`.

0 commit comments

Comments
 (0)