-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: add hidden integrated terminal #2094
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
benjaminshafii
wants to merge
1
commit into
dev
Choose a base branch
from
feat/hidden-integrated-terminal
base: dev
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.
Open
Changes from all commits
Commits
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -56,6 +56,7 @@ import { isElectronRuntime } from "../../../../app/utils"; | |||||
| import { isCollectibleArtifactTarget, isLocalhostBrowserTarget, type OpenTarget } from "../artifacts/open-target"; | ||||||
| import { VoicePanel } from "../voice/voice-panel"; | ||||||
| import { SidePanel } from "../panel/side-panel"; | ||||||
| import { TerminalDock } from "../terminal/terminal-dock"; | ||||||
| import { useActivePanelTab, usePanelTabStore, useSessionPanelState } from "../panel/panel-tab-store"; | ||||||
| import { useWorkspaceShellLayout } from "../../../shell/workspace-shell-layout"; | ||||||
| import { useControlAction, type OpenworkControlAction } from "../../../shell/control/control-provider"; | ||||||
|
|
@@ -178,6 +179,8 @@ export type SessionPageProps = { | |||||
| onAccessibleTargetsChange?: (targets: OpenTarget[]) => void; | ||||||
| /** Settings content rendered inside the right pane when the settings rail icon is active. */ | ||||||
| settingsSlot?: React.ReactNode; | ||||||
| terminalOpen?: boolean; | ||||||
| onTerminalOpenChange?: (open: boolean) => void; | ||||||
| }; | ||||||
|
|
||||||
| function getSidebarInitialLoading(props: SessionPageSidebarProps) { | ||||||
|
|
@@ -822,8 +825,9 @@ export function SessionPage(props: SessionPageProps) { | |||||
| </div> | ||||||
| </header> | ||||||
|
|
||||||
| <div className="flex min-h-0 flex-1 overflow-hidden"> | ||||||
| <div className="relative min-w-0 flex-1 overflow-hidden bg-dls-surface mac:bg-dls-surface/85 mac:backdrop-blur-2xl mac:backdrop-saturate-150"> | ||||||
| <ResizablePanelGroup orientation="vertical" className="min-h-0 flex-1 overflow-hidden"> | ||||||
| <ResizablePanel minSize="180px" className="min-h-0"> | ||||||
| <div className="relative h-full min-w-0 overflow-hidden bg-dls-surface mac:bg-dls-surface/85 mac:backdrop-blur-2xl mac:backdrop-saturate-150"> | ||||||
| {showStartupSkeleton ? ( | ||||||
| <div className="px-6 py-14" role="status" aria-live="polite"> | ||||||
| <div className="mx-auto max-w-2xl space-y-6"> | ||||||
|
|
@@ -1114,7 +1118,20 @@ export function SessionPage(props: SessionPageProps) { | |||||
| </div> | ||||||
| ) : null} | ||||||
| </div> | ||||||
| </div> | ||||||
| </ResizablePanel> | ||||||
| {props.terminalOpen ? ( | ||||||
| <> | ||||||
| <ResizableHandle withHandle /> | ||||||
| <ResizablePanel defaultSize="280px" minSize="160px" maxSize="55%" className="min-h-0"> | ||||||
| <TerminalDock | ||||||
| workspaceRoot={props.selectedWorkspaceRoot} | ||||||
| isRemoteWorkspace={props.selectedWorkspaceDisplay.workspaceType === "remote"} | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Terminal remote gating uses workspace display type instead of runtime remote state. This can incorrectly enable a local PTY on remote sessions or block terminal on local sessions when metadata differs. Prompt for AI agents
Suggested change
|
||||||
| onClose={() => props.onTerminalOpenChange?.(false)} | ||||||
| /> | ||||||
| </ResizablePanel> | ||||||
| </> | ||||||
| ) : null} | ||||||
| </ResizablePanelGroup> | ||||||
|
|
||||||
| {shellConfig.statusBar ? ( | ||||||
| <StatusBar | ||||||
|
|
||||||
131 changes: 131 additions & 0 deletions
131
apps/app/src/react-app/domains/session/terminal/terminal-dock.tsx
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,131 @@ | ||
| /** @jsxImportSource react */ | ||
| import { useEffect, useRef, useState } from "react"; | ||
| import { FitAddon } from "@xterm/addon-fit"; | ||
| import { Terminal } from "@xterm/xterm"; | ||
| import "@xterm/xterm/css/xterm.css"; | ||
| import { X } from "lucide-react"; | ||
|
|
||
| import { Button } from "@/components/ui/button"; | ||
| import { isElectronRuntime } from "../../../../app/utils"; | ||
|
|
||
| type TerminalDockProps = { | ||
| workspaceRoot: string; | ||
| isRemoteWorkspace: boolean; | ||
| onClose: () => void; | ||
| }; | ||
|
|
||
| export function TerminalDock({ workspaceRoot, isRemoteWorkspace, onClose }: TerminalDockProps) { | ||
| const containerRef = useRef<HTMLDivElement | null>(null); | ||
| const terminalIdRef = useRef<string | null>(null); | ||
| const terminalRef = useRef<Terminal | null>(null); | ||
| const fitRef = useRef<FitAddon | null>(null); | ||
| const [status, setStatus] = useState("Starting terminal..."); | ||
|
|
||
| useEffect(() => { | ||
| if (!containerRef.current) return; | ||
| if (!isElectronRuntime()) { | ||
| setStatus("Terminal is available in the desktop app."); | ||
| return; | ||
| } | ||
| if (isRemoteWorkspace) { | ||
| setStatus("Remote workspace terminals are not wired yet."); | ||
| return; | ||
| } | ||
|
|
||
| const bridge = window.__OPENWORK_ELECTRON__?.terminal; | ||
| if (!bridge?.create || !bridge.write || !bridge.resize || !bridge.kill || !bridge.onData || !bridge.onExit) { | ||
| setStatus("Terminal bridge is unavailable."); | ||
| return; | ||
| } | ||
| const createTerminal = bridge.create; | ||
| const writeTerminal = bridge.write; | ||
| const resizeTerminal = bridge.resize; | ||
| const killTerminal = bridge.kill; | ||
| const onTerminalData = bridge.onData; | ||
| const onTerminalExit = bridge.onExit; | ||
|
|
||
| let disposed = false; | ||
| const fitAddon = new FitAddon(); | ||
| const terminal = new Terminal({ | ||
| cursorBlink: true, | ||
| convertEol: true, | ||
| fontFamily: "'SFMono-Regular', 'Cascadia Code', 'Liberation Mono', Menlo, monospace", | ||
| fontSize: 12, | ||
| theme: { | ||
| background: "#0b0d12", | ||
| foreground: "#d7dde8", | ||
| cursor: "#ffffff", | ||
| selectionBackground: "#334155", | ||
| }, | ||
| }); | ||
| terminal.loadAddon(fitAddon); | ||
| terminal.open(containerRef.current); | ||
| terminal.focus(); | ||
| fitAddon.fit(); | ||
| terminalRef.current = terminal; | ||
| fitRef.current = fitAddon; | ||
|
|
||
| const removeDataListener = onTerminalData(({ terminalId, data }) => { | ||
| if (terminalIdRef.current !== terminalId) return; | ||
| terminal.write(data); | ||
| }); | ||
| const removeExitListener = onTerminalExit(({ terminalId, exitCode }) => { | ||
| if (terminalIdRef.current !== terminalId) return; | ||
| setStatus(`Terminal exited${exitCode === null ? "" : ` with code ${exitCode}`}.`); | ||
| terminalIdRef.current = null; | ||
| }); | ||
| const inputDisposable = terminal.onData((data) => { | ||
| const terminalId = terminalIdRef.current; | ||
| if (!terminalId) return; | ||
| void writeTerminal(terminalId, data); | ||
| }); | ||
|
|
||
| const fitAndResize = () => { | ||
| fitAddon.fit(); | ||
| const terminalId = terminalIdRef.current; | ||
| if (!terminalId) return; | ||
| void resizeTerminal(terminalId, terminal.cols, terminal.rows); | ||
| }; | ||
| const resizeObserver = new ResizeObserver(fitAndResize); | ||
| resizeObserver.observe(containerRef.current); | ||
|
|
||
| void createTerminal({ cwd: workspaceRoot, cols: terminal.cols, rows: terminal.rows }).then(({ terminalId }) => { | ||
| if (disposed) { | ||
| void killTerminal(terminalId); | ||
| return; | ||
| } | ||
| terminalIdRef.current = terminalId; | ||
| setStatus(workspaceRoot); | ||
| fitAndResize(); | ||
| }).catch((error) => { | ||
| setStatus(error instanceof Error ? error.message : "Could not start terminal."); | ||
| }); | ||
|
|
||
| return () => { | ||
| disposed = true; | ||
| resizeObserver.disconnect(); | ||
| inputDisposable.dispose(); | ||
| removeDataListener(); | ||
| removeExitListener(); | ||
| const terminalId = terminalIdRef.current; | ||
| terminalIdRef.current = null; | ||
| if (terminalId) void killTerminal(terminalId); | ||
| terminal.dispose(); | ||
| terminalRef.current = null; | ||
| fitRef.current = null; | ||
| }; | ||
| }, [isRemoteWorkspace, workspaceRoot]); | ||
|
|
||
| return ( | ||
| <section className="flex h-full min-h-0 flex-col border-t border-border bg-[#0b0d12] text-white" aria-label="Terminal"> | ||
| <header className="flex h-9 shrink-0 items-center justify-between border-b border-white/10 bg-black/35 px-3 text-xs"> | ||
| <div className="min-w-0 truncate text-white/75">Terminal · {status}</div> | ||
| <Button variant="ghost" size="icon-sm" className="text-white/70 hover:bg-white/10 hover:text-white" onClick={onClose}> | ||
| <X className="size-4" /> | ||
| <span className="sr-only">Hide terminal</span> | ||
| </Button> | ||
| </header> | ||
| <div ref={containerRef} className="min-h-0 flex-1 px-2 py-1 [&_.xterm]:h-full" /> | ||
| </section> | ||
| ); | ||
| } |
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
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.
P2: Hiding the panel unmounts and kills the PTY, so reopening loses the shell session instead of just hiding it.
Prompt for AI agents