@@ -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"
@@ -91,7 +93,12 @@ export function createSystemPromptHandler(
9193 return
9294 }
9395
94- 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" ) {
95102 return
96103 }
97104
@@ -116,10 +123,13 @@ export function createChatMessageTransformHandler(
116123 logger : Logger ,
117124 config : PluginConfig ,
118125 prompts : PromptStore ,
126+ hostPermissions : HostPermissionSnapshot ,
119127) {
120128 return async ( input : { } , output : { messages : WithParts [ ] } ) => {
121129 await checkSession ( client , state , logger , output . messages , config . manualMode . enabled )
122130
131+ syncCompressPermissionState ( state , config , hostPermissions , output . messages )
132+
123133 if ( state . isSubAgent && ! config . experimental . allowSubAgents ) {
124134 return
125135 }
@@ -156,6 +166,7 @@ export function createCommandExecuteHandler(
156166 logger : Logger ,
157167 config : PluginConfig ,
158168 workingDirectory : string ,
169+ hostPermissions : HostPermissionSnapshot ,
159170) {
160171 return async (
161172 input : { command : string ; sessionID : string ; arguments : string } ,
@@ -180,6 +191,10 @@ export function createCommandExecuteHandler(
180191 config . manualMode . enabled ,
181192 )
182193
194+ syncCompressPermissionState ( state , config , hostPermissions , messages )
195+
196+ const effectivePermission = compressPermission ( state , config )
197+
183198 const args = ( input . arguments || "" ) . trim ( ) . split ( / \s + / ) . filter ( Boolean )
184199 const subcommand = args [ 0 ] ?. toLowerCase ( ) || ""
185200 const subArgs = args . slice ( 1 )
@@ -217,7 +232,7 @@ export function createCommandExecuteHandler(
217232 throw new Error ( "__DCP_MANUAL_HANDLED__" )
218233 }
219234
220- if ( subcommand === "compress" && config . compress . permission !== "deny" ) {
235+ if ( subcommand === "compress" && effectivePermission !== "deny" ) {
221236 const userFocus = subArgs . join ( " " ) . trim ( )
222237 const prompt = await handleManualTriggerCommand ( commandCtx , "compress" , userFocus )
223238 if ( ! prompt ) {
@@ -238,15 +253,15 @@ export function createCommandExecuteHandler(
238253 return
239254 }
240255
241- if ( subcommand === "decompress" && config . compress . permission !== "deny" ) {
256+ if ( subcommand === "decompress" && effectivePermission !== "deny" ) {
242257 await handleDecompressCommand ( {
243258 ...commandCtx ,
244259 args : subArgs ,
245260 } )
246261 throw new Error ( "__DCP_DECOMPRESS_HANDLED__" )
247262 }
248263
249- if ( subcommand === "recompress" && config . compress . permission !== "deny" ) {
264+ if ( subcommand === "recompress" && effectivePermission !== "deny" ) {
250265 await handleRecompressCommand ( {
251266 ...commandCtx ,
252267 args : subArgs ,
0 commit comments