-
Notifications
You must be signed in to change notification settings - Fork 482
feat: worktree panel enhancements and bug fixes #558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Shironex
wants to merge
9
commits into
main
Choose a base branch
from
feature/open-in-terminal-merge-fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,029
−185
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
db0c1e2
fix: sanitize featureId in worktree routes
Shironex 509a007
refactor: simplify Claude usage service PTY and ANSI handling
Shironex 8401082
feat(platform): add cross-platform openInTerminal utility
Shironex e67be4c
feat(server): add open-in-terminal and discard-changes endpoints
Shironex 40f7dd6
feat(ui): add worktree panel enhancements
Shironex 44e44c1
fix(ui): improve mobile responsiveness for inputs and dialogs
Shironex dd447bc
feat: add branchName to running agents and output modal
Shironex b415209
fix: address Windows crash and command injection vulnerabilities
Shironex 64b24a3
fix: disable ConPTY on Windows to prevent AttachConsole errors
Shironex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
apps/server/src/routes/worktree/routes/discard-changes.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /** | ||
| * POST /discard-changes endpoint - Discard all uncommitted changes in a worktree | ||
| * | ||
| * This performs a destructive operation that: | ||
| * 1. Resets staged changes (git reset HEAD) | ||
| * 2. Discards modified tracked files (git checkout .) | ||
| * 3. Removes untracked files and directories (git clean -fd) | ||
| * | ||
| * Note: Git repository validation (isGitRepo) is handled by | ||
| * the requireGitRepoOnly middleware in index.ts | ||
| */ | ||
|
|
||
| import type { Request, Response } from 'express'; | ||
| import { exec } from 'child_process'; | ||
| import { promisify } from 'util'; | ||
| import { getErrorMessage, logError } from '../common.js'; | ||
|
|
||
| const execAsync = promisify(exec); | ||
|
|
||
| export function createDiscardChangesHandler() { | ||
| return async (req: Request, res: Response): Promise<void> => { | ||
| try { | ||
| const { worktreePath } = req.body as { | ||
| worktreePath: string; | ||
| }; | ||
|
|
||
| if (!worktreePath) { | ||
| res.status(400).json({ | ||
| success: false, | ||
| error: 'worktreePath required', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| // Check for uncommitted changes first | ||
| const { stdout: status } = await execAsync('git status --porcelain', { | ||
| cwd: worktreePath, | ||
| }); | ||
|
|
||
| if (!status.trim()) { | ||
| res.json({ | ||
| success: true, | ||
| result: { | ||
| discarded: false, | ||
| message: 'No changes to discard', | ||
| }, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| // Count the files that will be affected | ||
| const lines = status.trim().split('\n').filter(Boolean); | ||
| const fileCount = lines.length; | ||
|
|
||
| // Get branch name before discarding | ||
| const { stdout: branchOutput } = await execAsync('git rev-parse --abbrev-ref HEAD', { | ||
| cwd: worktreePath, | ||
| }); | ||
| const branchName = branchOutput.trim(); | ||
|
|
||
| // Discard all changes: | ||
| // 1. Reset any staged changes | ||
| await execAsync('git reset HEAD', { cwd: worktreePath }).catch(() => { | ||
| // Ignore errors - might fail if there's nothing staged | ||
| }); | ||
|
|
||
| // 2. Discard changes in tracked files | ||
| await execAsync('git checkout .', { cwd: worktreePath }).catch(() => { | ||
| // Ignore errors - might fail if there are no tracked changes | ||
| }); | ||
|
|
||
| // 3. Remove untracked files and directories | ||
| await execAsync('git clean -fd', { cwd: worktreePath }).catch(() => { | ||
| // Ignore errors - might fail if there are no untracked files | ||
| }); | ||
|
|
||
| // Verify all changes were discarded | ||
| const { stdout: finalStatus } = await execAsync('git status --porcelain', { | ||
| cwd: worktreePath, | ||
| }); | ||
|
|
||
| if (finalStatus.trim()) { | ||
| // Some changes couldn't be discarded (possibly ignored files or permission issues) | ||
| const remainingCount = finalStatus.trim().split('\n').filter(Boolean).length; | ||
| res.json({ | ||
| success: true, | ||
| result: { | ||
| discarded: true, | ||
| filesDiscarded: fileCount - remainingCount, | ||
| filesRemaining: remainingCount, | ||
| branch: branchName, | ||
| message: `Discarded ${fileCount - remainingCount} files, ${remainingCount} files could not be removed`, | ||
| }, | ||
| }); | ||
| } else { | ||
| res.json({ | ||
| success: true, | ||
| result: { | ||
| discarded: true, | ||
| filesDiscarded: fileCount, | ||
| filesRemaining: 0, | ||
| branch: branchName, | ||
| message: `Discarded ${fileCount} ${fileCount === 1 ? 'file' : 'files'}`, | ||
| }, | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| logError(error, 'Discard changes failed'); | ||
| res.status(500).json({ success: false, error: getErrorMessage(error) }); | ||
| } | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
apps/server/src/routes/worktree/routes/open-in-terminal.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /** | ||
| * POST /open-in-terminal endpoint - Open a terminal in a worktree directory | ||
| * | ||
| * This module uses @automaker/platform for cross-platform terminal launching. | ||
| */ | ||
|
|
||
| import type { Request, Response } from 'express'; | ||
| import { isAbsolute } from 'path'; | ||
| import { openInTerminal } from '@automaker/platform'; | ||
| import { getErrorMessage, logError } from '../common.js'; | ||
|
|
||
| export function createOpenInTerminalHandler() { | ||
| return async (req: Request, res: Response): Promise<void> => { | ||
| try { | ||
| const { worktreePath } = req.body as { | ||
| worktreePath: string; | ||
| }; | ||
|
|
||
| if (!worktreePath) { | ||
| res.status(400).json({ | ||
| success: false, | ||
| error: 'worktreePath required', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| // Security: Validate that worktreePath is an absolute path | ||
| if (!isAbsolute(worktreePath)) { | ||
| res.status(400).json({ | ||
| success: false, | ||
| error: 'worktreePath must be an absolute path', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| // Use the platform utility to open in terminal | ||
| const result = await openInTerminal(worktreePath); | ||
| res.json({ | ||
| success: true, | ||
| result: { | ||
| message: `Opened terminal in ${worktreePath}`, | ||
| terminalName: result.terminalName, | ||
| }, | ||
| }); | ||
| } catch (error) { | ||
| logError(error, 'Open in terminal failed'); | ||
| res.status(500).json({ success: false, error: getErrorMessage(error) }); | ||
| } | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
featureIdsanitization logic is duplicated in multiple places. This reduces maintainability, as any change to the sanitization rule would need to be updated in all locations. Consider creating a shared helper function to centralize this logic.This logic is repeated in:
apps/server/src/routes/worktree/routes/file-diff.tsapps/server/src/routes/worktree/routes/info.tsapps/server/src/routes/worktree/routes/status.tsapps/server/src/services/auto-mode-service.tsA shared function like
getWorktreePath(projectPath, featureId)could be created in a common utility file.