Skip to content

add workspace widget with git branch and worktree management#151

Merged
morgmart merged 8 commits intomainfrom
workspace-widget
Apr 10, 2026
Merged

add workspace widget with git branch and worktree management#151
morgmart merged 8 commits intomainfrom
workspace-widget

Conversation

@morgmart
Copy link
Copy Markdown
Collaborator

@morgmart morgmart commented Apr 10, 2026

Category: new-feature
User Impact: Users can now switch branches, create worktrees, fetch, pull, and manage their git workspace directly from the context panel without leaving the chat.

Problem: The context panel showed static git information (branch names, worktree paths) but offered no way to interact with the workspace. Users had to switch to a terminal to change branches, create worktrees, or pull changes — breaking their flow.

Solution: Replaced the monolithic workspace section with a composable widget architecture. The new WorkspaceWidget includes a working context picker for switching between worktrees and branches (with dirty-state handling), inline fetch/pull actions, and a split-button for creating new branches or worktrees. The active working context is synced per-session to ACP so the agent always knows which branch and directory it's operating in.

File changes

src-tauri/src/commands/git.rs
Added Tauri commands for branch switching, stashing, init, fetch, pull, branch creation, and worktree creation. Includes helpers for path validation, worktree naming, and incoming commit counting.

src-tauri/src/lib.rs
Registered the new git commands with the Tauri command handler.

src/shared/types/git.ts
Extended GitState with incomingCommitCount and localBranches. Added CreatedWorktree type.

src/shared/api/git.ts
Added frontend API wrappers for all new git Tauri commands.

src/shared/ui/split-button.tsx
New shared SplitButton component — a primary action button with a dropdown to switch between actions. Used for the "Create branch / Create worktree" toggle.

src/shared/ui/dropdown-menu.tsx
Changed focus text color from text-muted-foreground to text-foreground for better readability on highlighted dropdown items.

src/features/chat/stores/chatSessionStore.ts
Added WorkingContext type and activeWorkingContextBySession state to track the selected branch/path per session. Cleanup on session deletion.

src/features/chat/ui/ChatView.tsx
Reads activeWorkingContext from the store and syncs it to ACP when it changes. Injects a working context system prompt fragment so the agent knows the active branch and directory.

src/features/chat/ui/ChatContextPanel.tsx
Passes sessionId through to ContextPanel.

src/features/chat/ui/ContextPanel.tsx
Refactored from a single large component into a composition of extracted widgets. Wires up git action callbacks and delegates rendering to WorkspaceWidget, ChangesWidget, McpServersWidget, and ProcessesWidget.

src/features/chat/ui/widgets/Widget.tsx
Extracted the shared widget chrome (header bar with icon/title/action, content area) into a reusable component.

src/features/chat/ui/widgets/WorkspaceWidget.tsx
The main workspace widget — shows project info, the working context picker, action buttons, and handles the non-git/loading/error states.

src/features/chat/ui/widgets/WorkingContextPicker.tsx
Popover-based picker for switching between worktrees and branches. Handles dirty-state conflicts with a stash-or-carry dialog. Routes branch switches to the correct worktree path.

src/features/chat/ui/widgets/WorkspaceActionsMenu.tsx
Inline action bar with split-button for create (branch/worktree) and ghost buttons for fetch/pull. Shows incoming commit count on the pull button.

src/features/chat/ui/widgets/WorkspaceCreateDialog.tsx
Dialog for creating branches or worktrees. Syncs worktree name to branch name, shows path preview, supports both new-branch and existing-branch modes for worktrees.

src/features/chat/ui/widgets/formatError.ts
Shared error formatting utility extracted from the two widget files that needed it.

src/features/chat/ui/widgets/ChangesWidget.tsx, McpServersWidget.tsx, ProcessesWidget.tsx
Placeholder widgets for future changes, MCP servers, and processes panels.

src/shared/i18n/locales/en/chat.json, es/chat.json
Added translation keys for all new UI strings (picker, dialogs, git actions, create forms).

src/features/chat/ui/tests/ContextPanel.test.tsx
Comprehensive tests for the workspace widget: picker rendering, branch switching, worktree creation, dirty-state dialogs, and action button behavior.

scripts/check-file-sizes.mjs
Added scoped exception for the test file (550 lines).

Reproduction Steps

  1. Open the app with a project that has a git repository configured
  2. Open the context panel — you should see the workspace widget with the current branch and path displayed in a picker button
  3. Click the picker to see all worktrees and local branches; select a different branch to switch
  4. If there are uncommitted changes, a dialog should appear offering to stash or carry them
  5. Use the "Create branch" button to create a new branch from the current one
  6. Click the chevron on the create button to switch to "Create worktree" mode
  7. Use Fetch and Pull buttons to sync with remote; Pull should show incoming commit count when available
  8. For a non-git directory, an "Initialize Git" button should appear instead
Screenshot 2026-04-10 at 2 44 44 PM

- Introduced `activeWorkingContextBySession` to track the working context for each chat session.
- Added methods `setActiveWorkingContext` and `getActiveWorkingContext` to manage the active working context.
- Updated relevant components (ChatView, ContextPanel) to utilize the new working context state.
- Enhanced tests to cover the new working context functionality.

This change improves the chat session management by allowing users to maintain context across different sessions, enhancing the overall user experience.
…onality

- Removed the `getActiveWorkingContext` method from the chat session store as it was no longer needed.
- Added `stashChanges` and `initRepo` functions to the Git API for managing repository state.
- Updated the `ContextPanel` to include handlers for stashing changes and initializing a Git repository.
- Enhanced the `WorkingContextPicker` to support stashing changes before switching branches.
- Updated UI components to reflect new functionalities and improved user experience.
- Added tests to cover new features and ensure proper functionality.

These changes improve the chat application's integration with Git, allowing users to manage their repository state more effectively.
- Removed the `type` property from the `WorkingContext` interface in `chatSessionStore`.
- Enhanced the `ContextPanel` tests to reflect changes in local branches and worktree selection.
- Updated the `WorkingContextPicker` to utilize the current project path for better context handling.
- Improved UI labels and interactions for selecting worktrees and branches.
- Added new tests to ensure proper functionality of worktree and branch selection.

These changes streamline the management of working contexts in the chat application, improving user experience and code maintainability.
…ctionality

- Added utility functions to simplify branch button retrieval in ContextPanel tests.
- Updated tests to reflect changes in branch display and selection behavior.
- Refactored WorkingContextPicker to improve path handling for branch switching.
- Removed unnecessary UI elements and improved localization for branch labels.
- Enhanced test coverage for worktree and branch interactions, ensuring accurate functionality.

These changes improve the reliability of the ContextPanel tests and streamline the user experience in managing branches and worktrees.
…ements

- Added handlers for fetching, pulling, creating branches, and creating worktrees in the ContextPanel.
- Updated the ContextPanel UI to include new actions for managing branches and worktrees.
- Improved error handling in refetch calls to prevent unhandled promise rejections.
- Enhanced WorkingContextPicker to better handle path display logic.
- Updated localization files to include new strings for branch and worktree management.

These changes improve the user experience by providing more robust Git management features within the chat application.
…ponents

- Added a new file size limit for the ContextPanel test file to ensure integration tests remain efficient.
- Refactored error handling in the ChatView component to prevent unhandled promise rejections.
- Improved formatting and readability in various components, including WorkingContextPicker and WorkspaceActionsMenu.
- Updated imports to use consistent icon libraries and removed redundant error formatting functions.

These changes enhance the robustness of the chat application's file handling and improve overall code quality.
@morgmart morgmart requested a review from wesbillman as a code owner April 10, 2026 21:36
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b5afb61b14

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@morgmart morgmart merged commit 6d6b4b9 into main Apr 10, 2026
8 checks passed
@morgmart morgmart deleted the workspace-widget branch April 10, 2026 21:51
lifeizhou-ap added a commit to lifeizhou-ap/goose2 that referenced this pull request Apr 13, 2026
* main:
  show per-message assistant identity from metadata instead of props (block#156)
  add file-aware widgets to context panel, simplify session search (block#154)
  Add i18n and cross-boundary dead data checks to code review skill (block#153)
  search session message content (block#152)
  add workspace widget with git branch and worktree management (block#151)
  fix: strip XML wrapper from replayed user messages (block#150)
  feat: add file @-mention autocomplete with project file scanning (block#147)
  improve sidebar contrast and constrain model picker (block#149)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant