@@ -600,8 +600,8 @@ impl<A: API + ConsoleWriter + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
600600 }
601601 TopLevelCommand :: Workspace ( index_group) => {
602602 match index_group. command {
603- crate :: cli:: WorkspaceCommand :: Sync { path, batch_size } => {
604- self . on_index ( path, batch_size ) . await ?;
603+ crate :: cli:: WorkspaceCommand :: Sync { path, init } => {
604+ self . on_index ( path, init ) . await ?;
605605 }
606606 crate :: cli:: WorkspaceCommand :: List { porcelain } => {
607607 self . on_list_workspaces ( porcelain) . await ?;
@@ -1980,8 +1980,7 @@ impl<A: API + ConsoleWriter + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
19801980 }
19811981 SlashCommand :: Index => {
19821982 let working_dir = self . state . cwd . clone ( ) ;
1983- // Use default batch size of 100 for slash command
1984- self . on_index ( working_dir, 100 ) . await ?;
1983+ self . on_index ( working_dir, false ) . await ?;
19851984 }
19861985 SlashCommand :: AgentSwitch ( agent_id) => {
19871986 // Validate that the agent exists by checking against loaded agents
@@ -3634,11 +3633,7 @@ impl<A: API + ConsoleWriter + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
36343633 Ok ( ( ) )
36353634 }
36363635
3637- async fn on_index (
3638- & mut self ,
3639- path : std:: path:: PathBuf ,
3640- batch_size : usize ,
3641- ) -> anyhow:: Result < ( ) > {
3636+ async fn on_index ( & mut self , path : std:: path:: PathBuf , init : bool ) -> anyhow:: Result < ( ) > {
36423637 use forge_domain:: SyncProgress ;
36433638 use forge_spinner:: ProgressBarManager ;
36443639
@@ -3647,7 +3642,17 @@ impl<A: API + ConsoleWriter + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
36473642 self . init_forge_services ( ) . await ?;
36483643 }
36493644
3650- let mut stream = self . api . sync_workspace ( path. clone ( ) , batch_size) . await ?;
3645+ // When init is set, check if the workspace is already initialized
3646+ // via get_workspace_info before calling init, so we only initialize
3647+ // when a workspace does not yet exist for the given path.
3648+ if init {
3649+ let workspace_info = self . api . get_workspace_info ( path. clone ( ) ) . await ?;
3650+ if workspace_info. is_none ( ) {
3651+ self . on_workspace_init ( path. clone ( ) ) . await ?;
3652+ }
3653+ }
3654+
3655+ let mut stream = self . api . sync_workspace ( path. clone ( ) ) . await ?;
36513656 let mut progress_bar = ProgressBarManager :: default ( ) ;
36523657
36533658 while let Some ( event) = stream. next ( ) . await {
@@ -3998,19 +4003,20 @@ impl<A: API + ConsoleWriter + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
39984003
39994004 /// Initialize workspace for a directory without syncing files
40004005 async fn on_workspace_init ( & mut self , path : std:: path:: PathBuf ) -> anyhow:: Result < ( ) > {
4006+ // Check if auth already exists and create if needed
4007+ if !self . api . is_authenticated ( ) . await ? {
4008+ self . init_forge_services ( ) . await ?;
4009+ }
4010+
40014011 self . spinner . start ( Some ( "Initializing workspace" ) ) ?;
40024012
40034013 let workspace_id = self . api . init_workspace ( path. clone ( ) ) . await ?;
40044014
40054015 self . spinner . stop ( None ) ?;
40064016
4007- // Resolve and display the path
4008- let canonical_path = path. canonicalize ( ) . unwrap_or_else ( |_| path. clone ( ) ) ;
4009-
40104017 self . writeln_title (
40114018 TitleFormat :: info ( "Workspace initialized successfully" )
4012- . sub_title ( format ! ( "Path: {}" , canonical_path. display( ) ) )
4013- . sub_title ( format ! ( "Workspace ID: {}" , workspace_id) ) ,
4019+ . sub_title ( format ! ( "{}" , workspace_id) ) ,
40144020 ) ?;
40154021
40164022 Ok ( ( ) )
0 commit comments