> ## Documentation Index
> Fetch the complete documentation index at: https://amd-gaia.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Terminal in the Desktop App

> A real terminal inside the GAIA desktop app, tied to the conversation, for commands GAIA can't run by itself

# Terminal in the Desktop App

> [!NOTE]
>
> **Status:** Phase 1 is built: the panel, **Run in terminal** on commands, and
> **Send result to GAIA**, in the desktop app only. Phase 2, where GAIA runs its own
> commands in the terminal, is built and switched off until the agent evals cover it.
> Phase 3 is not committed.
> See [What Phase 1 leaves out](#what-phase-1-leaves-out) before treating the rest as
> current behaviour.

## The problem

When GAIA can't finish a command itself, it shows the command and says "run this
yourself". The user then leaves the app, finds a terminal, pastes, runs, comes back
and describes what happened. The reported case: asked to clone a repository, GAIA
installed Git, couldn't see the Git it had just installed, had one step declined
(which blocks that site for the rest of the request), and ended on a command to copy
after two minutes and nine steps.

A terminal in the app turns that dead end into three clicks and one key press.

## What it is

A panel between the conversation and the message box that holds a real shell:
PowerShell on Windows, the user's own shell on macOS and Linux. Three things tie it
to the conversation:

| Piece | What the user sees |
| - | - |
| **The terminal panel** | Hidden until wanted. Opens from the chat header or `` Ctrl+` ``. Tabs, resizable, remembers its height. |
| **Run in terminal** | A button beside **Copy** on a one-line command in an answer. It opens the panel and types the command at the prompt. The user presses Enter. |
| **Send result to GAIA** | When a command ends, the panel says **Finished** or **Failed** and offers to attach the command and its output to the next message. |

## The journey

1. GAIA shows a command with **Run in terminal** beside it.
2. The user clicks it. The panel opens with the command typed and a line under the
   terminal: "From GAIA. Press Enter to run it, or edit it first."
3. The user presses Enter. Output appears as it happens.
4. The panel says "Finished" with how long it took, or "Failed" with the exit code.
5. The user clicks **Send result to GAIA** (or **Ask GAIA about this error**). A
   text attachment and a ready sentence appear in the message box; they send it and
   GAIA continues.

## Design rules

These are Phase 1's rules. [Phase 2](#phase-2-gaia-drives-the-terminal) replaces the
first two for GAIA's own tabs: there GAIA runs commands under the chat's permission
mode and reads their output. The user's own tabs keep these rules.

* **The user presses Enter.** GAIA can put a command at a prompt. It can never run
  one there. Only a single line is ever typed, because a line break typed into a
  shell runs what came before it.
* **GAIA sees only what is sent.** Nothing in the terminal reaches GAIA unless the
  user clicks Send, and what is sent is one command and the end of its output
  (the last 200 lines).
* **Out of the way until needed.** No terminal on first launch and nothing new in
  the sidebar. This is what keeps the feature compatible with the
  [UI redesign](https://amd-gaia.ai/docs/plans/gaia-ui-redesign.md), whose concern was forcing terminal habits
  on first-time users.
* **Desktop only.** A browser tab and the phone link get no terminal and no Run
  button. The shell is reachable only through the desktop window's own bridge,
  never through the web interface.
* **Plain words.** "Terminal", "Run in terminal", "Finished", "Failed".

## Scenarios

| Scenario | What happens |
| - | - |
| A command needs typing (a sign-in, a password, yes/no) | The user answers the prompt in the terminal. GAIA never sees what is typed. |
| Something long is running | Output streams. The panel can be hidden; the header button shows a dot while a command runs. |
| A program installed a minute ago "isn't found" | Each new tab reads Windows' current program list, so it sees new installs. |
| The command fails | "Failed", the exit code, and **Ask GAIA about this error**. |
| A step was declined earlier | That block applies to GAIA. Running the command in the terminal is the user's own action and works. |
| Quit while a command runs | GAIA asks first: "A command is still running in the terminal." |
| Arabic | Labels mirror and translate; the terminal itself stays left to right. |

## How it works

The desktop app's main process starts the shell under a pseudo-terminal
([node-pty](https://github.com/microsoft/node-pty)) and the window draws it with
[xterm.js](https://xtermjs.org). The Python backend is not involved, so the terminal
behaves the same whether the agent runs in the backend or as a sidecar.

PowerShell, bash and zsh are started with a prompt hook that reports each command's
exit code, which is how the panel knows a command ended. Any other shell runs without
it: no Finished/Failed line, and a **Send what's on screen to GAIA** button instead.

Options that were considered and set aside:

| Option | Why not |
| - | - |
| A terminal served by the Python backend | It would put a shell behind the web interface, including the phone link. |
| An output viewer with no typing | Sign-ins and prompts, the main case, would still send the user elsewhere. |
| A button that opens the system terminal | The user still leaves the app and GAIA never learns the result. |

## What Phase 1 leaves out

* **The chat's folder.** A new tab starts in the home folder, not the chat's folder.
* **Scripts.** A block of several lines keeps **Copy** only.
* **A paste warning.** Pasting several lines runs them, as in any terminal.
* **Undo.** Undo can't restore files a terminal command changed, and the changes
  list does not yet say that a command was run in the terminal.
* **Internet off.** The terminal is the user's and keeps its network access when a
  chat's Internet switch is off; the panel does not yet say so.
* **Packaged-app checks.** The terminal library is the app's first compiled add-on.
  It ships prebuilt for Windows and macOS and compiles on Linux at install time.
  Installers must be built and tried on a clean PC for each before release.

## Phase 2: GAIA drives the terminal

> [!NOTE]
>
> **Status:** built and switched off. With the switch on, GAIA's commands run in a
> visible GAIA tab, GAIA reads their output while they run, and it can answer a
> question, wait for more or stop them. It passes a local stress run against the real
> desktop app and a live run of GAIA's own agent loop with DeepSeek on Fireworks (see
> [How it was tested](#how-it-was-tested)). It is not offered to users until the agent
> evals cover it (see [Proving it](#proving-it)).

Phase 1 makes the user the courier: GAIA shows a command, the user runs it and sends
the result back. Phase 2 removes the courier. GAIA runs its own commands in a visible
terminal tab, reads the output as it arrives, and can react while a command is still
running. What it may run is decided where it is decided today: the chat's permission
mode and the command tool's guardrails.

### What changes for the user

* **A GAIA tab per chat.** GAIA's commands run in their own tab, one per chat, so a
  command left running in one chat keeps its output and its **Stop** while another chat
  runs its own. GAIA never types into the user's tabs.
* **Same rules as today.** In Ask mode the existing prompt appears first. In Full access
  the command just runs. Blocked commands, declined steps and Internet off stop a
  command exactly as they do now, before anything reaches the terminal.
* **Live, for both.** The user watches the output. GAIA reads it too, so on a long
  install it can report progress, notice an error and stop, or answer a yes/no question.
* **The user can step in.** The tab takes the keyboard like any terminal: typing a
  sign-in code or pressing Ctrl+C works, and GAIA sees the result.
* **Quiet by default.** The panel does not open on every command; the header button
  shows a dot while one runs. The panel opens on its own only when a command waits for
  the user, and only for the chat on screen: another chat's command never takes the
  keyboard from what the user is typing.
* **The command stays in view.** The status line under the terminal names the command
  ("GAIA is running this. `npm install`"), because every new process on Windows clears
  the screen as it starts and pushes the tab's own label out of sight.

### The reported case, after Phase 2

Ask mode: "GAIA wants to run `git clone …`" → **Allow once** → the clone streams in the
GAIA tab → GAIA reads "done" and carries on. If git asks for a password, the panel opens
on that line and says the command is waiting for the user. Full access: the same without
the prompt. No copy, no paste, no Send.

### Scenarios

| Scenario | What happens |
| - | - |
| A long install | GAIA starts it and gets "still running" with the output so far after 30 seconds, then reads more, answers or stops it. |
| A yes/no question | The command is handed back to GAIA as soon as it goes quiet on the question (about 2 seconds), not after the 30-second wait, and GAIA types the answer (Ask mode asks first, showing the text). |
| A password, code or key | GAIA never types it. The panel opens on that line, says the command is waiting for the user, and GAIA tells them. This also holds when the password prompt comes after a question GAIA answered. |
| A shell, interpreter, pager or remote session (`python`, `bash`, `less`, `ssh`, `psql`, also behind `uv run` or `npx`) | Outside Full access GAIA types only answers there (`y`, `n`, `yes`, `no`, a number, or Enter), since any other line would be a command no rule can check. Pagers are turned off for GAIA's commands. |
| A command that ends while GAIA is busy elsewhere | Its exit code and last output wait for GAIA's next read, and the chat's next command waits until GAIA has read them. |
| More output than is kept between two reads | GAIA is told that earlier output was not kept, then gets the latest lines. |
| The user's Stop, closing the tab, the chat's Stop, a time limit | The command and everything it started end; GAIA is told it was stopped or timed out, with what it printed. |
| The window reloads mid-command | The command keeps running; the tab comes back with its screen so far. |
| The user switches chats mid-command | It keeps running. A new command in a chat not on screen runs hidden, as today. |
| GAIA desktop is open but does not answer | Nothing runs, and GAIA says why: one of the chat's commands may still be going there, so running it hidden could run it twice. A command that loses the terminal after it started is reported as started, state unknown, never as not run. |
| Browser, phone link, TUI, scheduled runs, `gaia -p` | No desktop window, so commands run hidden as today. |

### How it works

* **The desktop bridge.** The agent reaches GAIA desktop over the same loopback bridge
  the browser pane uses (a token in a discovery file, local connections only), with a
  new `terminal` operation: `status`, `run`, `read`, `input`, `stop`, `reveal`. The
  agent finds it the same way from the backend and from an installed sidecar, so it
  works however GAIA is installed.
* **The same command, in a terminal.** Each approved step is started as its own process
  under a pseudo-terminal, with the exact program, arguments and folder the tool builds
  today (`cmd.exe` on Windows). The program is sent as an absolute path, and only what
  GAIA adds to the environment travels; the desktop app lays it over a fresh copy of the
  PC's environment, so a program installed a minute ago is found.
* **A screen model.** The desktop app models each command's screen with a headless
  terminal, so a progress bar reads as its final state and what GAIA reads does not
  depend on the window being open or visible.
* **One tool grows, three are added.** `run_shell_command` keeps its name and result
  shape and can return `status: "running"`. `read_terminal`, `send_terminal_input` and
  `stop_terminal_command` are added to a turn only while the desktop terminal serves its
  chat, so by default the tool list the model sees is unchanged.
* **Secrets, twice.** A prompt asking for a password, passphrase, code, token or key is
  refused for typing by the agent and again by the desktop app, which checks the screen
  with the latest output drawn.

### The switch

Off by default and not in Settings. In the desktop app's developer console:
`localStorage.setItem('gaia.terminal.agentRuns', '1')`, then reload.

### How it was tested

**Unit tests** cover the agent side (69 tests), the desktop app's terminal service (57)
and the bridge's checks, including requests from outside the app and relative program
paths on each platform.

**A stress run** drives the real pieces: the real terminal service and bridge in a real
Electron process, and the real `run_shell_command` and terminal tools in a separate
process that finds the app through its discovery file, as an installed sidecar does.
Real processes under ConPTY on Windows 11. 72 checks, all passing:

| Area | What must hold |
| - | - |
| 30 quick commands back to back | Each result is exactly its own output and exit code, Unicode intact |
| Large output (3,000 and 20,000 lines) | The last line arrives; the size cap holds |
| Long commands, questions, passwords | Every line once across reads; `y` typed once; a password never typed, by either side |
| Busy, time limit, chat Stop, resume in a later turn | Refused, ended or picked up as described above |
| Hostile requests to the bridge | No token, a wrong token, a web page's Origin, a rebound Host, bad JSON, a 1 MB body, a missing folder, a huge wait, another chat's command: all refused, nothing started |
| Eight runs started at once | Exactly one starts |
| 25 start-and-stop cycles; a child and a detached grandchild | No process left behind |

**The real window**, with the built UI in Electron: stopping from the GAIA tab, answering
a question in it, a reload mid-command, and a password prompt the user types. Each GAIA
tab scene is also checked in English and Arabic, light and dark, including a long command
and two chats at once.

**GAIA's own agent loop, live**, with DeepSeek (`deepseek-v4p1-flash` on Fireworks)
choosing the tools: run and read a long command, answer a question, stop a command, and
a script that asks a question and then a password, each in its own chat with that chat
on screen. On the final code the model answered the question in the terminal in about
11 seconds, and never typed a password: it answered the first question, stopped at
`Password:` and told the user it was their turn. The live runs found four defects that
scripted tests had not, all fixed: a line half printed at a read came back twice; GAIA's
own Stop was reported as a failure; a password prompt that followed GAIA's answer was not
handed to the user; and a command waiting at a question sat for the full 30-second wait
(or was killed by a shorter time limit) before GAIA saw it.

One thing the model does on its own: asked to watch a command and stop it, it sometimes
starts it in the background with `run_python` and a log file rather than letting
`run_shell_command` hand it back. It gets the right answer that way; teaching it the
terminal route is a tool-description change, which needs the agent evals.

**Two independent code reviews** found the rest, all fixed with a test that fails without
the fix: a result lost when a command ended between reads or was overwritten by the next
one; a Stop that left child processes running; output dropped silently past the
scrollback or after `clear`; one GAIA tab shared by every chat; lines typed into a shell,
interpreter or pager going unchecked outside Full access; a bridge failure mid-command
reported as "not run"; and the agent marker missing from a sidecar's commands.

**The packaged app** (an unpacked Windows build): node-pty and the screen model are
inside it, node-pty's native module is unpacked beside it, and the packaged Electron
starts a real command through it.

**Linux**, in a Debian container: the whole Electron suite (2,202 tests pass; the one
failure, a dev-server log test, fails the same way on `main`) and the agent-side terminal
tests (69 pass, with and without `git` installed), plus the terminal service on a real
node-pty built from source, under bash and zsh. It found one more bug, fixed: the
Windows shell lookup used the host's path rules, so it failed on the Linux CI runner.

**The `gaia_shell` agent eval**, on a Windows dev PC with Gemma-4-E4B, on this branch and
on `main`, one after the other. With no window the terminal tools stay out of the schema,
so this checks that the changes to the hidden path broke nothing: 12 of 17 passed here
against 8 of 17 on `main`. The one scenario that passed on `main` and failed here
(`shell_long_and_noisy_scripts`) passed both re-runs here and failed a re-run on `main`,
so it was noise. The five failures here are the model's own choices, such as estimating
a line count instead of counting it.

What this does not show:

* Each command in the terminal takes about 1.5 seconds longer than hidden: node-pty
  waits a second for the last output after a process exits on Windows.
* The terminal path under a local model: the evals run with no window, so they cover
  only the hidden path. The other eval categories wait for the Strix Halo pool.
* macOS is untested, and so is the Linux desktop app as a whole: the Linux run drove the
  terminal service, not a window. So is an installer built by the release workflow,
  which recompiles node-pty (the build above used node-pty's own prebuilt module, as the
  PC had no compiler).

### Proving it

Per the project's rule, nothing is offered until it is proven:

* It stays behind the switch until the agent evals pass on the Strix Halo pool with the
  new tools in the schema. The evals run with no window, so they cover the hidden path;
  watch every category whose scenarios call `run_shell_command`.
* The terminal path needs a desktop journey test against a real shell on Windows, macOS
  and Linux, and a run of the installed app.
* Tests start from the cold state the reported case had: a PC without the program the
  command needs.

### Risks

* **A command that asks for input now waits** instead of failing at once. Step time
  limits still apply, and a secret prompt is handed to the user.
* **More tool calls per task.** Polling a long command costs turns; `run_shell_command`
  waits 30 seconds before handing a command back, so most finish in one call.
* **Two ways to run a command.** With and without a window must agree; the shared
  command line and the result-shape tests are what hold them together.

## Phase 3: shared sessions

A long-lived interactive shell that GAIA and the user both drive (an SSH session, a
REPL). Not committed; Phase 2 covers running programs, not standing shells.

## Related fixes

Two bugs in the reported case stand apart from this plan:

* After GAIA installs a program, its next command should find it.
* The message after a declined step should say that the user declined a step that
  contacts that site, not that "the tool is blocking" a command.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.