Skip to content

Commit 7cca5f3

Browse files
committed
fix: limit protect tags
1 parent f821b1d commit 7cca5f3

2 files changed

Lines changed: 67 additions & 6 deletions

File tree

lib/compress/protected-content.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ export function appendProtectedPromptInfo(
7272

7373
const message = searchContext.rawMessagesById.get(messageId)
7474
if (!message) continue
75+
if (message.info.role !== "user") continue
76+
if (isIgnoredUserMessage(message)) continue
7577

7678
const parts = Array.isArray(message.parts) ? message.parts : []
7779
for (const part of parts) {

tests/compress-message.test.ts

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ test("compress message mode batches individual message summaries", async () => {
230230
test("compress message mode appends protected prompt info", async () => {
231231
const sessionID = `ses_message_protect_tag_${Date.now()}`
232232
const rawMessages = buildMessages(sessionID)
233-
const assistant = rawMessages.find((message) => message.info.id === "msg-assistant-1")
234-
const part = assistant?.parts[0]
233+
const user = rawMessages.find((message) => message.info.id === "msg-user-1")
234+
const part = user?.parts[0]
235235
if (part?.type === "text") {
236-
part.text = "I mapped the code path. <protect>Always preserve release checklist.</protect>"
236+
part.text = "Investigate the issue. <protect>Always preserve release checklist.</protect>"
237237
}
238238

239239
const state = createSessionState()
@@ -263,9 +263,9 @@ test("compress message mode appends protected prompt info", async () => {
263263
topic: "Protected note",
264264
content: [
265265
{
266-
messageId: "m0002",
267-
topic: "Code path note",
268-
summary: "Captured the assistant's code-path findings.",
266+
messageId: "m0001",
267+
topic: "User request note",
268+
summary: "Captured the user's investigation request.",
269269
},
270270
],
271271
},
@@ -285,6 +285,65 @@ test("compress message mode appends protected prompt info", async () => {
285285
assert.match(block?.summary || "", /Always preserve release checklist\./)
286286
})
287287

288+
test("compress message mode ignores protect tags on ignored user messages", async () => {
289+
const sessionID = `ses_message_ignored_protect_tag_${Date.now()}`
290+
const rawMessages = buildMessages(sessionID)
291+
const user = rawMessages.find((message) => message.info.id === "msg-user-1")
292+
const part = user?.parts[0] as any
293+
if (part?.type === "text") {
294+
part.text = "Ignored notification. <protect>Do not preserve ignored note.</protect>"
295+
part.ignored = true
296+
}
297+
298+
const state = createSessionState()
299+
const logger = new Logger(false)
300+
const config = buildConfig()
301+
config.compress.protectTags = true
302+
const tool = createCompressMessageTool({
303+
client: {
304+
session: {
305+
messages: async () => ({ data: rawMessages }),
306+
get: async () => ({ data: { parentID: null } }),
307+
},
308+
},
309+
state,
310+
logger,
311+
config,
312+
prompts: {
313+
reload() {},
314+
getRuntimePrompts() {
315+
return { compressMessage: "", compressRange: "" }
316+
},
317+
},
318+
} as any)
319+
320+
await tool.execute(
321+
{
322+
topic: "Ignored protected note",
323+
content: [
324+
{
325+
messageId: "m0001",
326+
topic: "Ignored note",
327+
summary: "Captured the ignored user message.",
328+
},
329+
],
330+
},
331+
{
332+
ask: async () => {},
333+
metadata: () => {},
334+
sessionID,
335+
messageID: "msg-compress-ignored-protect-tag",
336+
},
337+
)
338+
339+
const block = Array.from(state.prune.messages.blocksById.values())[0]
340+
assert.doesNotMatch(
341+
block?.summary || "",
342+
/The following protected prompt information was included in this conversation verbatim:/,
343+
)
344+
assert.doesNotMatch(block?.summary || "", /Do not preserve ignored note\./)
345+
})
346+
288347
test("compress message mode stores call id for later duration attachment", async () => {
289348
const sessionID = `ses_message_compress_duration_${Date.now()}`
290349
const rawMessages = buildMessages(sessionID)

0 commit comments

Comments
 (0)