@@ -21,6 +21,8 @@ import { handleSweepCommand } from "./commands/sweep"
2121import { handleManualToggleCommand , handleManualTriggerCommand } from "./commands/manual"
2222import { handleDecompressCommand } from "./commands/decompress"
2323import { handleRecompressCommand } from "./commands/recompress"
24+ import { type HostPermissionSnapshot } from "./host-permissions"
25+ import { compressPermission , syncCompressPermissionState } from "./shared-utils"
2426import { ensureSessionInitialized } from "./state/state"
2527import { cacheSystemPromptTokens } from "./ui/utils"
2628import type { PromptStore } from "./prompts/store"
@@ -32,9 +34,7 @@ const INTERNAL_AGENT_SIGNATURES = [
3234]
3335
3436const DCP_MESSAGE_ID_TAG_REGEX = / < d c p - m e s s a g e - i d > (?: m \d + | b \d + ) < \/ d c p - m e s s a g e - i d > / g
35- const TURN_NUDGE_BLOCK_REGEX = / < i n s t r u c t i o n \s + n a m e = t u r n _ n u d g e \b [ ^ > ] * > [ \s \S ] * ?< \/ i n s t r u c t i o n > / g
36- const ITERATION_NUDGE_BLOCK_REGEX =
37- / < i n s t r u c t i o n \s + n a m e = i t e r a t i o n _ n u d g e \b [ ^ > ] * > [ \s \S ] * ?< \/ i n s t r u c t i o n > / g
37+ const DCP_SYSTEM_REMINDER_REGEX = / < d c p - s y s t e m - r e m i n d e r \b [ ^ > ] * > [ \s \S ] * ?< \/ d c p - s y s t e m - r e m i n d e r > / g
3838
3939function applyManualPrompt ( state : SessionState , messages : WithParts [ ] , logger : Logger ) : void {
4040 const pending = state . pendingManualTrigger
@@ -93,7 +93,12 @@ export function createSystemPromptHandler(
9393 return
9494 }
9595
96- if ( config . compress . permission === "deny" ) {
96+ const effectivePermission =
97+ input . sessionID && state . sessionId === input . sessionID
98+ ? compressPermission ( state , config )
99+ : config . compress . permission
100+
101+ if ( effectivePermission === "deny" ) {
97102 return
98103 }
99104
@@ -118,10 +123,13 @@ export function createChatMessageTransformHandler(
118123 logger : Logger ,
119124 config : PluginConfig ,
120125 prompts : PromptStore ,
126+ hostPermissions : HostPermissionSnapshot ,
121127) {
122128 return async ( input : { } , output : { messages : WithParts [ ] } ) => {
123129 await checkSession ( client , state , logger , output . messages , config . manualMode . enabled )
124130
131+ syncCompressPermissionState ( state , config , hostPermissions , output . messages )
132+
125133 if ( state . isSubAgent && ! config . experimental . allowSubAgents ) {
126134 return
127135 }
@@ -158,6 +166,7 @@ export function createCommandExecuteHandler(
158166 logger : Logger ,
159167 config : PluginConfig ,
160168 workingDirectory : string ,
169+ hostPermissions : HostPermissionSnapshot ,
161170) {
162171 return async (
163172 input : { command : string ; sessionID : string ; arguments : string } ,
@@ -182,6 +191,10 @@ export function createCommandExecuteHandler(
182191 config . manualMode . enabled ,
183192 )
184193
194+ syncCompressPermissionState ( state , config , hostPermissions , messages )
195+
196+ const effectivePermission = compressPermission ( state , config )
197+
185198 const args = ( input . arguments || "" ) . trim ( ) . split ( / \s + / ) . filter ( Boolean )
186199 const subcommand = args [ 0 ] ?. toLowerCase ( ) || ""
187200 const subArgs = args . slice ( 1 )
@@ -219,7 +232,7 @@ export function createCommandExecuteHandler(
219232 throw new Error ( "__DCP_MANUAL_HANDLED__" )
220233 }
221234
222- if ( subcommand === "compress" && config . compress . permission !== "deny" ) {
235+ if ( subcommand === "compress" && effectivePermission !== "deny" ) {
223236 const userFocus = subArgs . join ( " " ) . trim ( )
224237 const prompt = await handleManualTriggerCommand ( commandCtx , "compress" , userFocus )
225238 if ( ! prompt ) {
@@ -240,15 +253,15 @@ export function createCommandExecuteHandler(
240253 return
241254 }
242255
243- if ( subcommand === "decompress" && config . compress . permission !== "deny" ) {
256+ if ( subcommand === "decompress" && effectivePermission !== "deny" ) {
244257 await handleDecompressCommand ( {
245258 ...commandCtx ,
246259 args : subArgs ,
247260 } )
248261 throw new Error ( "__DCP_DECOMPRESS_HANDLED__" )
249262 }
250263
251- if ( subcommand === "recompress" && config . compress . permission !== "deny" ) {
264+ if ( subcommand === "recompress" && effectivePermission !== "deny" ) {
252265 await handleRecompressCommand ( {
253266 ...commandCtx ,
254267 args : subArgs ,
@@ -268,8 +281,7 @@ export function createTextCompleteHandler() {
268281 output : { text : string } ,
269282 ) => {
270283 output . text = output . text
271- . replace ( TURN_NUDGE_BLOCK_REGEX , "" )
272- . replace ( ITERATION_NUDGE_BLOCK_REGEX , "" )
284+ . replace ( DCP_SYSTEM_REMINDER_REGEX , "" )
273285 . replace ( DCP_MESSAGE_ID_TAG_REGEX , "" )
274286 }
275287}
0 commit comments