1+ import type { PluginConfig } from "../config"
12import type { SessionState } from "../state"
23import { parseBoundaryId } from "../message-ids"
3- import { isIgnoredUserMessage } from "../messages/utils"
4+ import { isIgnoredUserMessage , isProtectedUserMessage } from "../messages/utils"
45import { resolveAnchorMessageId , resolveBoundaryIds , resolveSelection } from "./search"
56import { COMPRESSED_BLOCK_HEADER } from "./state"
67import type {
@@ -66,6 +67,7 @@ export function resolveMessages(
6667 args : CompressMessageToolArgs ,
6768 searchContext : SearchContext ,
6869 state : SessionState ,
70+ config : PluginConfig ,
6971) : ResolvedMessageCompressionsResult {
7072 const issues : string [ ] = [ ]
7173 const plans : ResolvedMessageCompression [ ] = [ ]
@@ -88,6 +90,7 @@ export function resolveMessages(
8890 } ,
8991 searchContext ,
9092 state ,
93+ config ,
9194 )
9295 seenMessageIds . add ( plan . entry . messageId )
9396 plans . push ( plan )
@@ -111,7 +114,14 @@ function resolveMessage(
111114 entry : CompressMessageEntry ,
112115 searchContext : SearchContext ,
113116 state : SessionState ,
117+ config : PluginConfig ,
114118) : ResolvedMessageCompression {
119+ if ( entry . messageId . toUpperCase ( ) === "BLOCKED" ) {
120+ throw new SoftIssue (
121+ "messageId BLOCKED refers to a protected message and cannot be compressed." ,
122+ )
123+ }
124+
115125 const parsed = parseBoundaryId ( entry . messageId )
116126
117127 if ( ! parsed ) {
@@ -122,7 +132,7 @@ function resolveMessage(
122132
123133 if ( parsed . kind === "compressed-block" ) {
124134 throw new SoftIssue (
125- `messageId ${ entry . messageId } is invalid in message mode . Block IDs like bN are not allowed; use an mNNNN message ID instead.` ,
135+ `messageId ${ entry . messageId } is invalid here . Block IDs like bN are not allowed; use an mNNNN message ID instead.` ,
126136 )
127137 }
128138
@@ -157,6 +167,12 @@ function resolveMessage(
157167 throw new Error ( `messageId ${ parsed . ref } is not available in the current conversation.` )
158168 }
159169
170+ if ( isProtectedUserMessage ( config , message ) ) {
171+ throw new SoftIssue (
172+ `messageId ${ parsed . ref } refers to a protected message and cannot be compressed.` ,
173+ )
174+ }
175+
160176 const pruneEntry = state . prune . messages . byMessageId . get ( rawMessageId )
161177 if ( pruneEntry && pruneEntry . activeBlockIds . length > 0 ) {
162178 throw new Error ( `messageId ${ parsed . ref } is already part of an active compression.` )
0 commit comments