@@ -14,10 +14,13 @@ import { useResumeManager } from "./hooks/useResumeManager";
1414import { useUnreadTracking } from "./hooks/useUnreadTracking" ;
1515import { useAutoCompactContinue } from "./hooks/useAutoCompactContinue" ;
1616import { useWorkspaceStoreRaw , useWorkspaceRecency } from "./stores/WorkspaceStore" ;
17+ import { FirstMessageInput } from "./components/FirstMessageInput" ;
1718
1819import { useStableReference , compareMaps } from "./hooks/useStableReference" ;
1920import { CommandRegistryProvider , useCommandRegistry } from "./contexts/CommandRegistryContext" ;
2021import type { CommandAction } from "./contexts/CommandRegistryContext" ;
22+ import { ModeProvider } from "./contexts/ModeContext" ;
23+ import { ThinkingProvider } from "./contexts/ThinkingContext" ;
2124import { CommandPalette } from "./components/CommandPalette" ;
2225import { buildCoreSources , type BuildSourcesParams } from "./utils/commands/sources" ;
2326
@@ -57,6 +60,9 @@ function AppInner() {
5760 const [ workspaceModalLoadError , setWorkspaceModalLoadError ] = useState < string | null > ( null ) ;
5861 const workspaceModalProjectRef = useRef < string | null > ( null ) ;
5962
63+ // Track when we're in "new workspace creation" mode (show FirstMessageInput)
64+ const [ pendingNewWorkspaceProject , setPendingNewWorkspaceProject ] = useState < string | null > ( null ) ;
65+
6066 // Auto-collapse sidebar on mobile by default
6167 const isMobile = typeof window !== "undefined" && window . innerWidth <= 768 ;
6268 const [ sidebarCollapsed , setSidebarCollapsed ] = usePersistedState ( "sidebarCollapsed" , isMobile ) ;
@@ -114,9 +120,10 @@ function AppInner() {
114120 window . history . replaceState ( null , "" , newHash ) ;
115121 }
116122
117- // Update window title with workspace name
123+ // Update window title with workspace name (prefer displayName if available)
124+ const metadata = workspaceMetadata . get ( selectedWorkspace . workspaceId ) ;
118125 const workspaceName =
119- workspaceMetadata . get ( selectedWorkspace . workspaceId ) ?. name ?? selectedWorkspace . workspaceId ;
126+ metadata ?. displayName ?? metadata ?. name ?? selectedWorkspace . workspaceId ;
120127 const title = `${ workspaceName } - ${ selectedWorkspace . projectName } - cmux` ;
121128 void window . api . window . setTitle ( title ) ;
122129 } else {
@@ -169,46 +176,15 @@ function AppInner() {
169176 [ removeProject , selectedWorkspace , setSelectedWorkspace ]
170177 ) ;
171178
172- const handleAddWorkspace = useCallback ( async ( projectPath : string ) => {
173- const projectName = projectPath . split ( "/" ) . pop ( ) ?? projectPath . split ( "\\" ) . pop ( ) ?? "project" ;
174-
175- workspaceModalProjectRef . current = projectPath ;
176- setWorkspaceModalProject ( projectPath ) ;
177- setWorkspaceModalProjectName ( projectName ) ;
178- setWorkspaceModalBranches ( [ ] ) ;
179- setWorkspaceModalDefaultTrunk ( undefined ) ;
180- setWorkspaceModalLoadError ( null ) ;
181- setWorkspaceModalOpen ( true ) ;
182-
183- try {
184- const branchResult = await window . api . projects . listBranches ( projectPath ) ;
185-
186- // Guard against race condition: only update state if this is still the active project
187- if ( workspaceModalProjectRef . current !== projectPath ) {
188- return ;
189- }
190-
191- const sanitizedBranches = Array . isArray ( branchResult ?. branches )
192- ? branchResult . branches . filter ( ( branch ) : branch is string => typeof branch === "string" )
193- : [ ] ;
194-
195- const recommended =
196- typeof branchResult ?. recommendedTrunk === "string" &&
197- sanitizedBranches . includes ( branchResult . recommendedTrunk )
198- ? branchResult . recommendedTrunk
199- : sanitizedBranches [ 0 ] ;
200-
201- setWorkspaceModalBranches ( sanitizedBranches ) ;
202- setWorkspaceModalDefaultTrunk ( recommended ) ;
203- setWorkspaceModalLoadError ( null ) ;
204- } catch ( err ) {
205- console . error ( "Failed to load branches for modal:" , err ) ;
206- const message = err instanceof Error ? err . message : "Unknown error" ;
207- setWorkspaceModalLoadError (
208- `Unable to load branches automatically: ${ message } . You can still enter the trunk branch manually.`
209- ) ;
210- }
211- } , [ ] ) ;
179+ const handleAddWorkspace = useCallback (
180+ ( projectPath : string ) => {
181+ // Show FirstMessageInput for this project
182+ setPendingNewWorkspaceProject ( projectPath ) ;
183+ // Clear any selected workspace so FirstMessageInput is shown
184+ setSelectedWorkspace ( null ) ;
185+ } ,
186+ [ setSelectedWorkspace ]
187+ ) ;
212188
213189 // Memoize callbacks to prevent LeftSidebar/ProjectSidebar re-renders
214190 const handleAddProjectCallback = useCallback ( ( ) => {
@@ -646,6 +622,48 @@ function AppInner() {
646622 }
647623 />
648624 </ ErrorBoundary >
625+ ) : pendingNewWorkspaceProject || projects . size === 1 ? (
626+ ( ( ) => {
627+ const projectPath = pendingNewWorkspaceProject ?? Array . from ( projects . keys ( ) ) [ 0 ] ;
628+ const projectName =
629+ projectPath . split ( "/" ) . pop ( ) ?? projectPath . split ( "\\" ) . pop ( ) ?? "Project" ;
630+ return (
631+ < ModeProvider projectPath = { projectPath } >
632+ < ThinkingProvider projectPath = { projectPath } >
633+ < FirstMessageInput
634+ projectPath = { projectPath }
635+ projectName = { projectName }
636+ onWorkspaceCreated = { ( metadata ) => {
637+ // Add to workspace metadata map
638+ setWorkspaceMetadata ( ( prev ) => new Map ( prev ) . set ( metadata . id , metadata ) ) ;
639+
640+ // Switch to new workspace
641+ handleWorkspaceSwitch ( {
642+ workspaceId : metadata . id ,
643+ projectPath : metadata . projectPath ,
644+ projectName : metadata . projectName ,
645+ namedWorkspacePath : metadata . namedWorkspacePath ,
646+ } ) ;
647+
648+ // Track telemetry
649+ telemetry . workspaceCreated ( metadata . id ) ;
650+
651+ // Clear pending state
652+ setPendingNewWorkspaceProject ( null ) ;
653+ } }
654+ onCancel = {
655+ pendingNewWorkspaceProject
656+ ? ( ) => {
657+ // User cancelled workspace creation - clear pending state
658+ setPendingNewWorkspaceProject ( null ) ;
659+ }
660+ : undefined
661+ }
662+ />
663+ </ ThinkingProvider >
664+ </ ModeProvider >
665+ ) ;
666+ } ) ( )
649667 ) : (
650668 < div
651669 className = "[&_p]:text-muted mx-auto w-full max-w-3xl text-center [&_h2]:mb-4 [&_h2]:font-bold [&_h2]:tracking-tight [&_h2]:text-white [&_p]:leading-[1.6]"
0 commit comments