Skip to content

fix(sync): separate init and sync commands, extract file discovery#2613

Merged
tusharmath merged 21 commits intomainfrom
fix/avoid-creating-workspace-in-sync-command
Mar 23, 2026
Merged

fix(sync): separate init and sync commands, extract file discovery#2613
tusharmath merged 21 commits intomainfrom
fix/avoid-creating-workspace-in-sync-command

Conversation

@laststylebender14
Copy link
Contributor

@laststylebender14 laststylebender14 commented Mar 20, 2026

Summary

Separate the sync and init workspace commands so that sync no longer auto-creates a workspace, and introduce a dedicated --init flag (and sync-init slash command) for first-time workspace setup.

Context

Previously, workspace sync would silently auto-create a workspace if one did not exist, blurring the distinction between initializing and synchronizing a workspace. This caused confusion and made it difficult to run sync safely in environments where the workspace had not been explicitly set up. The fix ensures that sync is purely a sync operation and initialization is an explicit, opt-in step.

Changes

Core Behavior Change

  • workspace sync no longer auto-creates a workspace — it will fail gracefully if no workspace exists for the given path
  • A new --init flag on workspace sync conditionally initializes the workspace first (only if it does not already exist), then proceeds with sync
  • A new sync-init built-in slash command and shell plugin action are added to expose workspace init directly from the UI

Refactoring: File Discovery Extraction

The file discovery logic that was embedded in context_engine.rs has been extracted into three focused modules:

  • fd.rsFileDiscovery trait, ALLOWED_EXTENSIONS filter, discover_sync_file_paths helper, and FdDefault routing implementation
  • fd_git.rsFsGit: git-based discovery via git ls-files
  • fd_walker.rsFdWalker: filesystem-walker-based fallback

This makes each strategy independently testable and removes ~200 lines from context_engine.rs.

API Simplification

  • sync_workspace no longer takes a batch_size parameter — batch size is now sourced from the environment internally, removing an accidental public API surface
  • get_workspace_by_path helper added to context_engine.rs for DRY path-to-workspace resolution with a clear error message

MCP Cleanup

  • Removed the per-server timeout field from McpStdioServer and McpHttpServer (and associated tests) — timeout configuration is handled globally via FORGE_MCP_TIMEOUT

Shell Plugin

  • _forge_action_sync now passes --init so the interactive sync flow still sets up the workspace on first use
  • New _forge_action_sync_init action and sync-init dispatcher entry for explicit init-only flows

Testing

# Run all tests
cargo insta test --accept

# Test sync on an uninitialized workspace (should fail without --init)
forge workspace sync /path/to/new/project

# Test sync with --init on an uninitialized workspace (should init then sync)
forge workspace sync --init /path/to/new/project

# Test sync with --init on an already-initialized workspace (should skip init and sync)
forge workspace sync --init /path/to/existing/project

# Test explicit init-only
forge workspace init /path/to/project

@github-actions github-actions bot added the type: fix Iterations on existing features or infrastructure. label Mar 20, 2026
@laststylebender14 laststylebender14 marked this pull request as ready for review March 21, 2026 10:31
@augmentcode
Copy link

augmentcode bot commented Mar 21, 2026

🤖 Augment PR Summary

Summary: This PR changes workspace syncing so it no longer implicitly creates/registers a workspace on first sync.

Changes:

  • Updates context engine sync to require an existing (already initialized) workspace and returns a clear error when none is indexed.
  • Always fetches remote file hashes during sync now that new-workspace creation is removed from the sync path.
  • Adds a new shell-plugin action/command entry sync-init to initialize a workspace without syncing files.
  • Wires sync-init through the zsh dispatcher and action handlers to call forge workspace init non-interactively.

Technical Notes: Sync now depends on list_workspaces lookup via find_workspace_by_path and will fail fast if the workspace hasn’t been initialized.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

@tusharmath tusharmath changed the title fix(context_engine): stop auto-creating workspace in sync fix(sync): use env-based batch size for consistent file-read concurrency Mar 23, 2026
@tusharmath tusharmath force-pushed the fix/avoid-creating-workspace-in-sync-command branch from e9d60d2 to 0224542 Compare March 23, 2026 11:51
@tusharmath tusharmath enabled auto-merge (squash) March 23, 2026 11:52
@tusharmath tusharmath changed the title fix(sync): use env-based batch size for consistent file-read concurrency fix(sync): separate init and sync commands, extract file discovery Mar 23, 2026
@tusharmath tusharmath merged commit 9650937 into main Mar 23, 2026
8 checks passed
@tusharmath tusharmath deleted the fix/avoid-creating-workspace-in-sync-command branch March 23, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Iterations on existing features or infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants