@@ -28,13 +28,17 @@ import { KeyboardAwareLegendList } from "@legendapp/list/keyboard";
2828import { useViewabilityAmount , type LegendListRef } from "@legendapp/list/react-native" ;
2929import { scopeThreadRef } from "@t3tools/client-runtime/environment" ;
3030import type { HandoffEndpoints } from "@t3tools/client-runtime/handoff" ;
31- import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message" ;
31+ import {
32+ IDLE_COMPACTING_LABELS ,
33+ resolveUserMessagePresentation ,
34+ } from "@t3tools/client-runtime/user-message" ;
3235import { canForkProjectedAssistantItem } from "@t3tools/client-runtime/state/thread-workflows" ;
3336import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints" ;
3437import { formatDiffCount } from "@t3tools/client-runtime/diff-count" ;
3538import type { WorkflowOpening } from "@t3tools/client-runtime/state/subagentRuntime" ;
3639import {
3740 AuthFilesystemReadScope ,
41+ idleCompactionOf ,
3842 type OrchestrationMessageContext ,
3943 ThreadId ,
4044 type ChatAttachment ,
@@ -195,6 +199,7 @@ import {
195199} from "../../lib/markdownLinks" ;
196200import {
197201 createThreadFeedCache ,
202+ threadFeedCompactionLabels ,
198203 failedFeedRunIds ,
199204 deriveThreadFeedPresentation ,
200205 threadFeedRunIsUnsettled ,
@@ -224,7 +229,11 @@ import {
224229 ThreadWorkLog ,
225230 WORK_GROUP_TOGGLE_HEIGHT ,
226231} from "./thread-work-log" ;
227- import { appendPendingThreadMessages , type PendingThreadFeedEntry } from "./pending-thread-feed" ;
232+ import {
233+ appendPendingThreadMessages ,
234+ isCompactionCommandFeedEntry ,
235+ type PendingThreadFeedEntry ,
236+ } from "./pending-thread-feed" ;
228237import type { QueuedThreadMessage } from "../../state/thread-outbox-model" ;
229238import { resolveThreadFeedFixedItemSize } from "./thread-feed-item-size" ;
230239import { htmlRenderFrameHeight } from "@t3tools/shared/htmlRender" ;
@@ -1192,6 +1201,13 @@ function ThreadAutomationMessageRow(props: {
11921201 ) ;
11931202}
11941203
1204+ /** Leads with why T3 Code compacted, when it did so without being asked. */
1205+ function compactionLabel ( label : string , title : string | undefined ) {
1206+ return title !== undefined && label . startsWith ( "Context compacted" )
1207+ ? title + label . slice ( "Context compacted" . length )
1208+ : label ;
1209+ }
1210+
11951211function renderFeedEntry (
11961212 info : { item : PendingThreadFeedEntry ; index : number } ,
11971213 props : Pick <
@@ -1210,6 +1226,7 @@ function renderFeedEntry(
12101226 readonly workGroupScrollPositions : Map < string , ThreadWorkGroupScrollPosition > ;
12111227 readonly terminalAssistantMessageIds : ReadonlySet < string > ;
12121228 readonly unsettledTurnId : RunId | null ;
1229+ readonly compactionLabelsByEntryId : ReadonlyMap < string , { title : string ; compacting : string } > ;
12131230 readonly failedRunIds : ReadonlySet < RunId > ;
12141231 readonly onCopyWorkRow : ( rowId : string , value : string ) => void ;
12151232 readonly onToggleWorkGroup : ( groupId : string , anchorKey ?: string ) => void ;
@@ -1361,16 +1378,29 @@ function renderFeedEntry(
13611378
13621379 if ( entry . type === "activity-group" && isContextCompactionActivityGroup ( entry ) ) {
13631380 const label = entry . activities [ 0 ] ! . summary ;
1381+ const item = entry . activities [ 0 ] ! . projectedItem . item ;
13641382 const active =
13651383 props . unsettledTurnId !== null &&
13661384 entry . runId === props . unsettledTurnId &&
1367- entry . activities [ 0 ] ! . projectedItem . item . status === "running" ;
1385+ item . status === "running" ;
1386+ const labels = props . compactionLabelsByEntryId . get ( entry . id ) ;
1387+ const failure =
1388+ item . type === "compaction" && item . status === "failed" ? item . summary ?. trim ( ) : undefined ;
13681389 return (
13691390 < ThreadContextDivider
1370- label = { label }
1371- icon = "arrow.down.right.and.arrow.up.left"
1391+ label = {
1392+ failure
1393+ ? `${ label } · ${ failure } `
1394+ : active && labels
1395+ ? labels . compacting
1396+ : compactionLabel ( label , labels ?. title )
1397+ }
1398+ icon = {
1399+ item . status === "failed" ? "exclamationmark.circle" : "arrow.down.right.and.arrow.up.left"
1400+ }
13721401 iconColor = { iconSubtleColor }
13731402 active = { active }
1403+ failed = { item . status === "failed" }
13741404 />
13751405 ) ;
13761406 }
@@ -1409,6 +1439,25 @@ function renderFeedEntry(
14091439 />
14101440 ) ;
14111441 }
1442+ if ( isCompactionCommandFeedEntry ( entry ) ) {
1443+ // Stands in for the compaction item until the provider reports it.
1444+ const active = props . unsettledTurnId !== null && message . runId === props . unsettledTurnId ;
1445+ const reason = idleCompactionOf ( message ) ;
1446+ return (
1447+ < ThreadContextDivider
1448+ label = {
1449+ ! active
1450+ ? "Context compaction"
1451+ : reason === undefined
1452+ ? "Compacting context"
1453+ : IDLE_COMPACTING_LABELS [ reason ]
1454+ }
1455+ icon = "arrow.down.right.and.arrow.up.left"
1456+ iconColor = { iconSubtleColor }
1457+ active = { active }
1458+ />
1459+ ) ;
1460+ }
14121461 if ( isUser && presentation . attribution === "automation" ) {
14131462 const rowId = `automation:${ message . id } ` ;
14141463 return (
@@ -2505,6 +2554,10 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
25052554 ) ;
25062555 const reviewCommentColors = useReviewCommentColors ( ) ;
25072556 const unsettledTurnId = threadFeedRunIsUnsettled ( props . latestRun ) ? props . latestRun . runId : null ;
2557+ const compactionLabelsByEntryId = useMemo (
2558+ ( ) => threadFeedCompactionLabels ( props . feed ) ,
2559+ [ props . feed ] ,
2560+ ) ;
25082561 // LegendList does not invalidate visible rows when only the renderItem closure changes.
25092562 // Include turn completion so unchanged message rows reveal their footer and spacing
25102563 // even when the final message update arrives before the turn settles.
@@ -2987,6 +3040,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
29873040 workGroupScrollPositions,
29883041 terminalAssistantMessageIds,
29893042 unsettledTurnId,
3043+ compactionLabelsByEntryId,
29903044 failedRunIds,
29913045 onCopyWorkRow,
29923046 onToggleWorkGroup,
@@ -3124,6 +3178,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
31243178 keyExtractor = { ( entry ) => entry . id }
31253179 getItemType = { ( entry ) => {
31263180 if ( entry . type !== "message" ) return entry . type ;
3181+ if ( isCompactionCommandFeedEntry ( entry ) ) return "message:compaction" ;
31273182 const { attribution } = resolveUserMessagePresentation ( entry . message ) ;
31283183 return attribution === "automation" || attribution === "agent"
31293184 ? `message:${ attribution } `
0 commit comments