@@ -9,7 +9,7 @@ import { updatePersistedState } from "@/hooks/usePersistedState";
99import { getRetryStateKey } from "@/constants/storage" ;
1010import { CUSTOM_EVENTS } from "@/constants/events" ;
1111import { useSyncExternalStore } from "react" ;
12- import { isCaughtUpMessage , isStreamError , isDeleteMessage } from "@/types/ipc" ;
12+ import { isCaughtUpMessage , isStreamError , isDeleteMessage , isCmuxMessage } from "@/types/ipc" ;
1313import { MapStore } from "./MapStore" ;
1414import { createDisplayUsage } from "@/utils/tokens/displayUsage" ;
1515import { WorkspaceConsumerManager } from "./WorkspaceConsumerManager" ;
@@ -20,6 +20,7 @@ import { getCancelledCompactionKey } from "@/constants/storage";
2020import { isCompactingStream , findCompactionRequestMessage } from "@/utils/compaction/handler" ;
2121
2222export interface WorkspaceState {
23+ name : string ; // User-facing workspace name (e.g., "feature-branch")
2324 messages : DisplayedMessage [ ] ;
2425 canInterrupt : boolean ;
2526 isCompacting : boolean ;
@@ -108,6 +109,7 @@ export class WorkspaceStore {
108109 private caughtUp = new Map < string , boolean > ( ) ;
109110 private historicalMessages = new Map < string , CmuxMessage [ ] > ( ) ;
110111 private pendingStreamEvents = new Map < string , WorkspaceChatMessage [ ] > ( ) ;
112+ private workspaceMetadata = new Map < string , FrontendWorkspaceMetadata > ( ) ; // Store metadata for name lookup
111113
112114 /**
113115 * Map of event types to their handlers. This is the single source of truth for:
@@ -335,8 +337,10 @@ export class WorkspaceStore {
335337 const isCaughtUp = this . caughtUp . get ( workspaceId ) ?? false ;
336338 const activeStreams = aggregator . getActiveStreams ( ) ;
337339 const messages = aggregator . getAllMessages ( ) ;
340+ const metadata = this . workspaceMetadata . get ( workspaceId ) ;
338341
339342 return {
343+ name : metadata ?. name ?? workspaceId , // Fall back to ID if metadata missing
340344 messages : aggregator . getDisplayedMessages ( ) ,
341345 canInterrupt : activeStreams . length > 0 ,
342346 isCompacting : aggregator . isCompacting ( ) ,
@@ -730,6 +734,9 @@ export class WorkspaceStore {
730734 return ;
731735 }
732736
737+ // Store metadata for name lookup
738+ this . workspaceMetadata . set ( workspaceId , metadata ) ;
739+
733740 const aggregator = this . getOrCreateAggregator ( workspaceId , metadata . createdAt ) ;
734741
735742 // Initialize recency cache and bump derived store immediately
@@ -958,23 +965,26 @@ export class WorkspaceStore {
958965 }
959966
960967 // Regular messages (CmuxMessage without type field)
961- const isCaughtUp = this . caughtUp . get ( workspaceId ) ?? false ;
962- if ( ! isCaughtUp && "role" in data && ! ( "type" in data ) ) {
963- // Buffer historical CmuxMessages
964- const historicalMsgs = this . historicalMessages . get ( workspaceId ) ?? [ ] ;
965- historicalMsgs . push ( data ) ;
966- this . historicalMessages . set ( workspaceId , historicalMsgs ) ;
967- } else if ( isCaughtUp && "role" in data ) {
968- // Process live events immediately (after history loaded)
969- // Check for role field to ensure this is a CmuxMessage
970- aggregator . handleMessage ( data ) ;
971- this . states . bump ( workspaceId ) ;
972- this . checkAndBumpRecencyIfChanged ( ) ;
973- } else if ( "role" in data || "type" in data ) {
974- // Unexpected: message with role/type field didn't match any condition
975- console . error ( "[WorkspaceStore] Message not processed - unexpected state" , {
968+ if ( isCmuxMessage ( data ) ) {
969+ const isCaughtUp = this . caughtUp . get ( workspaceId ) ?? false ;
970+ if ( ! isCaughtUp ) {
971+ // Buffer historical CmuxMessages
972+ const historicalMsgs = this . historicalMessages . get ( workspaceId ) ?? [ ] ;
973+ historicalMsgs . push ( data ) ;
974+ this . historicalMessages . set ( workspaceId , historicalMsgs ) ;
975+ } else {
976+ // Process live events immediately (after history loaded)
977+ aggregator . handleMessage ( data ) ;
978+ this . states . bump ( workspaceId ) ;
979+ this . checkAndBumpRecencyIfChanged ( ) ;
980+ }
981+ return ;
982+ }
983+
984+ // If we reach here, unknown message type - log for debugging
985+ if ( "role" in data || "type" in data ) {
986+ console . error ( "[WorkspaceStore] Unknown message type - not processed" , {
976987 workspaceId,
977- isCaughtUp,
978988 hasRole : "role" in data ,
979989 hasType : "type" in data ,
980990 type : "type" in data ? ( data as { type : string } ) . type : undefined ,
0 commit comments