@@ -6,6 +6,7 @@ import { useAtomValue } from "@effect/atom-react";
66import { shouldCompactBeforeSend } from "@t3tools/client-runtime/state/context-window" ;
77import { threadRuntimeIsActive } from "@t3tools/client-runtime/state/shell" ;
88import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints" ;
9+ import { threadSteersDuringCompaction } from "@t3tools/client-runtime/state/thread-workflows" ;
910import { resolvePendingHandoff } from "@t3tools/client-runtime/handoff" ;
1011import {
1112 deriveProviderSubagentStatus ,
@@ -84,6 +85,7 @@ import {
8485} from "./use-composer-drafts" ;
8586import { isClearComposerCommand , parseSideChatCommand } from "@t3tools/shared/composerTrigger" ;
8687import {
88+ compactionBlocksSteering ,
8789 resolveComposerDispatchMode ,
8890 type ActiveTurnComposerAction ,
8991} from "@t3tools/client-runtime/state/composer-dispatch" ;
@@ -322,24 +324,19 @@ export function useThreadComposerState(input: {
322324 ? deriveThreadActivityRun ( selectedThreadProjection . projection )
323325 : ( selectedThreadShell ?. latestRun ?? null ) ;
324326
325- const isCompacting = ( ( ) => {
327+ const activeRunId =
328+ selectedThreadRuntime ?. activeRunId && threadRuntimeIsActive ( selectedThreadRuntime )
329+ ? selectedThreadRuntime . activeRunId
330+ : null ;
331+ const compactCommandIsActive = ( ( ) => {
326332 const queuedCompact = selectedThreadQueuedMessages . some (
327333 ( message ) =>
328334 message . messageId === dispatchingQueuedMessageId &&
329335 message . text . trim ( ) . toLowerCase ( ) === "/compact" &&
330336 message . attachments . length === 0 ,
331337 ) ;
332338 if ( queuedCompact ) return true ;
333- const activeRunId = selectedThreadRuntime ?. activeRunId ;
334- if ( ! activeRunId || ! threadRuntimeIsActive ( selectedThreadRuntime ) ) return false ;
335- if (
336- selectedThreadVisibleTurnItems . some (
337- ( { item } ) =>
338- item . runId === activeRunId && item . type === "compaction" && item . status === "running" ,
339- )
340- ) {
341- return true ;
342- }
339+ if ( ! activeRunId ) return false ;
343340 const compactMessage = selectedThreadVisibleTurnItems . findLast (
344341 ( { item } ) =>
345342 item . runId === activeRunId &&
@@ -358,8 +355,21 @@ export function useThreadComposerState(input: {
358355 item . status === "cancelled" ) ,
359356 ) ;
360357 } ) ( ) ;
361- // A compacting turn cannot take steering input, so follow-ups queue meanwhile.
362- const canSteerActiveTurn = queueWorkflow ?. canPromoteToSteer === true && ! isCompacting ;
358+ const compactionRunning =
359+ activeRunId !== null &&
360+ selectedThreadVisibleTurnItems . some (
361+ ( { item } ) =>
362+ item . runId === activeRunId && item . type === "compaction" && item . status === "running" ,
363+ ) ;
364+ const isCompacting = compactCommandIsActive || compactionRunning ;
365+ const compactionBlocksSteer = compactionBlocksSteering ( {
366+ compactCommandIsActive,
367+ compactionRunning,
368+ steersDuringCompaction : threadSteersDuringCompaction ( selectedThreadProjection ?. projection ) ,
369+ run : selectedThreadProjection ?. projection . runs . find ( ( run ) => run . id === activeRunId ) ,
370+ messages : selectedThreadMessages ,
371+ } ) ;
372+ const canSteerActiveTurn = queueWorkflow ?. canPromoteToSteer === true && ! compactionBlocksSteer ;
363373 // A stop or a restart holds the queue, completion wakes included, until it
364374 // is resumed; the queue sheet lists only the user's own messages.
365375 const queueHeld = queueWorkflow ?. isHeld === true ;
0 commit comments