@@ -478,12 +478,8 @@ export interface AcpAdapterV2Flavor {
478478 ) => Effect . Effect < void > ;
479479 readonly subagentsIdleOnTurnCompletion ?: boolean ;
480480 readonly supportsCompaction ?: boolean ;
481- /**
482- * Name of the slash command an agent runs natively to compact its own context
483- * (`compact` for agents that implement `/compact` as a prompt command).
484- * Turns `/compact` into an agent turn; rejected unless the agent advertises it.
485- */
486- readonly compactCommand ?: string ;
481+ /** Sends `/compact` as a prompt, only to sessions whose advertised commands include `compact`. */
482+ readonly compactViaAdvertisedCommand ?: boolean ;
487483 /**
488484 * Native steering: `send` queues a message into the running turn and returns the
489485 * agent's id for it, which `injectedSteerId` reads from the update that delivers it.
@@ -2011,16 +2007,11 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
20112007 const promptInstructionStates = yield * Ref . make ( new Map < string , T3AcpInstructionState > ( ) ) ;
20122008 // Unique markers keep delayed prompt completions from clearing later compactions.
20132009 const compactionMarkers = yield * Ref . make ( new Map < string , symbol > ( ) ) ;
2014- // Commands each agent session advertised; `/compact` is only sent to agents that list it.
20152010 const advertisedCommandNames = yield * Ref . make ( new Map < string , ReadonlySet < string > > ( ) ) ;
2016- // Agents that run `/compact` themselves advertise it as a command, so they take part in
2017- // T3 compaction even though ACP has no dedicated compact method.
2018- const compactCommand = flavor . compactCommand ?. trim ( ) . replace ( / ^ \/ + / u, "" ) . toLowerCase ( ) ;
2019- const compactPromptText = `/${ compactCommand ?? "compact" } ` ;
20202011 const compactsContext =
20212012 flavor . supportsCompaction === true ||
20222013 flavor . compactSession !== undefined ||
2023- compactCommand !== undefined ;
2014+ flavor . compactViaAdvertisedCommand === true ;
20242015 const runtimeRestartRequired = yield * Ref . make ( false ) ;
20252016 const runtimeTeardownState = yield * Ref . make < AcpRuntimeTeardownState > ( { _tag : "Idle" } ) ;
20262017 const runtimeCallbackGeneration = yield * Ref . make ( 0 ) ;
@@ -7761,8 +7752,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
77617752 const now = yield * DateTime . now ;
77627753 if (
77637754 compactsContext &&
7764- context . input . message . text . trim ( ) . toLowerCase ( ) === compactPromptText &&
7765- context . input . message . attachments . length === 0 &&
7755+ isCompactionMessage ( context . input . message ) &&
77667756 settledStatus === "completed" &&
77677757 ! context . tools . keys ( ) . some ( ( id ) => id . startsWith ( "acp-compaction:" ) )
77687758 ) {
@@ -8226,17 +8216,17 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
82268216 yield * Ref . set ( activeInteractionMode , turnInput . runtimePolicy . interactionMode ) ;
82278217 }
82288218 }
8219+ // Checked after activation: a loaded session advertises its own commands.
82298220 if (
8230- compactCommand !== undefined &&
8231- turnInput . message . text . trim ( ) . toLowerCase ( ) === compactPromptText &&
8232- turnInput . message . attachments . length === 0
8221+ flavor . compactViaAdvertisedCommand === true &&
8222+ isCompactionMessage ( turnInput . message ) &&
8223+ ( yield * Ref . get ( advertisedCommandNames ) ) . get ( requestedSessionId ) ?. has ( "compact" ) !==
8224+ true
82338225 ) {
8234- const advertised = ( yield * Ref . get ( advertisedCommandNames ) ) . get ( requestedSessionId ) ;
8235- if ( advertised !== undefined && ! advertised . has ( compactCommand ) ) {
8236- return yield * Effect . fail (
8237- `This agent does not advertise a /${ compactCommand } command.` ,
8238- ) ;
8239- }
8226+ return yield * new ProviderAdapter . ProviderCompactionUnsupportedError ( {
8227+ driver,
8228+ providerThreadId : turnInput . providerThread . id ,
8229+ } ) ;
82408230 }
82418231 yield * validateModelSelection ( turnInput . modelSelection ) ;
82428232 yield * Ref . set ( lastTurnRoute , {
@@ -8911,7 +8901,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
89118901 ) {
89128902 return yield * startTurn ( {
89138903 ...turnInput ,
8914- message : { ...turnInput . message , text : compactPromptText } ,
8904+ message : { ...turnInput . message , text : "/compact" } ,
89158905 } ) ;
89168906 } ) ,
89178907 }
0 commit comments