-
Notifications
You must be signed in to change notification settings - Fork 483
feat: add external terminal support with cross-platform detection #561
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
Closed
stefandevo
wants to merge
9
commits into
AutoMaker-Org:v0.12.0rc
from
stefandevo:feature/open-in-terminal
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f553f99
feat(platform): add cross-platform openInTerminal utility
Shironex 1e5ed55
feat(server): add open-in-terminal endpoint
stefandevo ca16d35
feat(ui): add Open in Terminal action to worktree dropdown
stefandevo e56df91
fix(ui): open in terminal navigates to Automaker terminal view
stefandevo b3dcb82
feat(ui): add terminal open mode setting (new tab vs split)
stefandevo 5c280ed
feat(ui): display branch name in terminal header with git icon
stefandevo e4a326f
feat: add external terminal support with cross-platform detection
stefandevo 5bb3415
fix: address PR review comments
stefandevo 6df310a
fix: add project name testid to project switcher item
stefandevo 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
166 changes: 166 additions & 0 deletions
166
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,166 @@ | ||
| /** | ||
| * Terminal endpoints for opening worktree directories in terminals | ||
| * | ||
| * POST /open-in-terminal - Open in system default terminal (integrated) | ||
| * GET /available-terminals - List all available external terminals | ||
| * GET /default-terminal - Get the default external terminal | ||
| * POST /refresh-terminals - Clear terminal cache and re-detect | ||
| * POST /open-in-external-terminal - Open a directory in an external terminal | ||
| */ | ||
|
|
||
| import type { Request, Response } from 'express'; | ||
| import { isAbsolute } from 'path'; | ||
| import { | ||
| openInTerminal, | ||
| clearTerminalCache, | ||
| detectAllTerminals, | ||
| detectDefaultTerminal, | ||
| openInExternalTerminal, | ||
| } from '@automaker/platform'; | ||
| import { createLogger } from '@automaker/utils'; | ||
| import { getErrorMessage, logError } from '../common.js'; | ||
|
|
||
| const logger = createLogger('open-in-terminal'); | ||
|
|
||
| /** | ||
| * Handler to open in system default terminal (integrated terminal behavior) | ||
| */ | ||
| 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) }); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Handler to get all available external terminals | ||
| */ | ||
| export function createGetAvailableTerminalsHandler() { | ||
| return async (_req: Request, res: Response): Promise<void> => { | ||
| try { | ||
| const terminals = await detectAllTerminals(); | ||
| res.json({ | ||
| success: true, | ||
| result: { | ||
| terminals, | ||
| }, | ||
| }); | ||
| } catch (error) { | ||
| logError(error, 'Get available terminals failed'); | ||
| res.status(500).json({ success: false, error: getErrorMessage(error) }); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Handler to get the default external terminal | ||
| */ | ||
| export function createGetDefaultTerminalHandler() { | ||
| return async (_req: Request, res: Response): Promise<void> => { | ||
| try { | ||
| const terminal = await detectDefaultTerminal(); | ||
| res.json({ | ||
| success: true, | ||
| result: terminal | ||
| ? { | ||
| terminalId: terminal.id, | ||
| terminalName: terminal.name, | ||
| terminalCommand: terminal.command, | ||
| } | ||
| : null, | ||
| }); | ||
| } catch (error) { | ||
| logError(error, 'Get default terminal failed'); | ||
| res.status(500).json({ success: false, error: getErrorMessage(error) }); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Handler to refresh the terminal cache and re-detect available terminals | ||
| * Useful when the user has installed/uninstalled terminals | ||
| */ | ||
| export function createRefreshTerminalsHandler() { | ||
| return async (_req: Request, res: Response): Promise<void> => { | ||
| try { | ||
| // Clear the cache | ||
| clearTerminalCache(); | ||
|
|
||
| // Re-detect terminals (this will repopulate the cache) | ||
| const terminals = await detectAllTerminals(); | ||
|
|
||
| logger.info(`Terminal cache refreshed, found ${terminals.length} terminals`); | ||
|
|
||
| res.json({ | ||
| success: true, | ||
| result: { | ||
| terminals, | ||
| message: `Found ${terminals.length} available external terminals`, | ||
| }, | ||
| }); | ||
| } catch (error) { | ||
| logError(error, 'Refresh terminals failed'); | ||
| res.status(500).json({ success: false, error: getErrorMessage(error) }); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Handler to open a directory in an external terminal | ||
| */ | ||
| export function createOpenInExternalTerminalHandler() { | ||
| return async (req: Request, res: Response): Promise<void> => { | ||
| try { | ||
| // worktreePath is validated by validatePathParams middleware | ||
| const { worktreePath, terminalId } = req.body as { | ||
| worktreePath: string; | ||
| terminalId?: string; | ||
| }; | ||
|
|
||
| const result = await openInExternalTerminal(worktreePath, terminalId); | ||
| res.json({ | ||
| success: true, | ||
| result: { | ||
| message: `Opened ${worktreePath} in ${result.terminalName}`, | ||
| terminalName: result.terminalName, | ||
| }, | ||
| }); | ||
| } catch (error) { | ||
| logError(error, 'Open in external terminal failed'); | ||
| res.status(500).json({ success: false, error: getErrorMessage(error) }); | ||
| } | ||
| }; | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.