-
Notifications
You must be signed in to change notification settings - Fork 483
feat: add external terminal support with cross-platform detection #565
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
Merged
stefandevo
merged 13 commits into
AutoMaker-Org:v0.13.0rc
from
stefandevo:feature/open-in-terminal
Jan 19, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
16f2449
feat(platform): add cross-platform openInTerminal utility
Shironex af69ca7
feat(server): add open-in-terminal endpoint
stefandevo 099ebaf
feat(ui): add Open in Terminal action to worktree dropdown
stefandevo 03103fd
fix(ui): open in terminal navigates to Automaker terminal view
stefandevo ce4b9b6
feat(ui): add terminal open mode setting (new tab vs split)
stefandevo 502361f
feat(ui): display branch name in terminal header with git icon
stefandevo 111eb24
feat: add external terminal support with cross-platform detection
stefandevo 9529afb
fix: address PR review comments
stefandevo 5d68e75
fix: address PR review security and validation issues
stefandevo c42b786
chore: update package-lock.json
stefandevo 36bdf8c
fix: use response.json() to prevent disposal race condition in E2E test
stefandevo 306f6bb
Revert "fix: use response.json() to prevent disposal race condition i…
stefandevo df88857
fix: address PR review feedback for terminal feature
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
Some comments aren't visible on the classic Files Changed page.
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
181 changes: 181 additions & 0 deletions
181
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,181 @@ | ||
| /** | ||
| * 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 || typeof worktreePath !== 'string') { | ||
| res.status(400).json({ | ||
| success: false, | ||
| error: 'worktreePath required and must be a string', | ||
| }); | ||
| 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 { | ||
| const { worktreePath, terminalId } = req.body as { | ||
| worktreePath: string; | ||
| terminalId?: string; | ||
| }; | ||
|
|
||
| if (!worktreePath || typeof worktreePath !== 'string') { | ||
| res.status(400).json({ | ||
| success: false, | ||
| error: 'worktreePath required and must be a string', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| if (!isAbsolute(worktreePath)) { | ||
| res.status(400).json({ | ||
| success: false, | ||
| error: 'worktreePath must be an absolute path', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| 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.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: AutoMaker-Org/automaker
Length of output: 543
🏁 Script executed:
Repository: AutoMaker-Org/automaker
Length of output: 996
🏁 Script executed:
Repository: AutoMaker-Org/automaker
Length of output: 904
Validate
terminalIdtype before delegating.If a client sends a non-string
terminalId, it would pass the truthiness check but silently fail infindTerminalById()due to string comparison mismatch, causing unexpected fallback behavior instead of returning a clear 400 error. Add a lightweight runtime check.🛠️ Proposed fix
const { worktreePath, terminalId } = req.body as { worktreePath: string; terminalId?: string; }; if (!worktreePath || typeof worktreePath !== 'string') { res.status(400).json({ success: false, error: 'worktreePath required and must be a string', }); return; } + if (terminalId !== undefined && typeof terminalId !== 'string') { + res.status(400).json({ + success: false, + error: 'terminalId must be a string', + }); + return; + } + if (!isAbsolute(worktreePath)) { res.status(400).json({ success: false, error: 'worktreePath must be an absolute path', }); return; }🤖 Prompt for AI Agents