Skip to content

ui: run shell commands in the background and show them in a side card - #107

Draft
allozaur wants to merge 4 commits into
allozaur/feat/tools-on-demandfrom
allozaur/feat/background-tasks
Draft

allozaur wants to merge 4 commits into
allozaur/feat/tools-on-demandfrom
allozaur/feat/background-tasks

Conversation

@allozaur

@allozaur allozaur commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Overview

Ask the agent to start a dev server or a watcher and it keeps running in the background: a card on the right of the chat lists such tasks, shows their output and stops them.

Additional information

Layer 5 of the planned stack, on #102 (tools on demand). Unlike the layers below it, this one changes llama-server too. Not tried in a container or over ssh (--tools-runtime); the tests for those need docker.

The model's start call asks for permission like any shell command. Reading or stopping a task asks for nothing.

Cause

exec_shell_command reads the output pipe until it closes. A command such as npm run dev & leaves a child that keeps the pipe open, and the timeout kills only the shell, so the call hung until that child exited, which for a server means never. Reproduced on a local build: a timeout: 3 call with (sleep 25; echo late) & returned after 25 s.

What changed

llama-server (tools/server/server-tools.cpp):

  • exec_shell_command takes run_in_background. It starts the command, waits for its first output (up to 5 s, or 1 s of quiet), and returns that output plus [background task: N]. The tool description tells the model to use it for dev servers, watchers and log followers, and not to end a command with &.
  • A new shell_task tool, enabled with exec_shell_command, with action: list (tasks with status, exit code, cwd, start/end time), output (output from a byte offset on, the newest part when there is more; returns next_offset for polling) and stop.
  • Each task runs as the leader of its own process group (setsid where it exists, else set -m). Stop sends SIGTERM to the group, then SIGKILL after 3 s; server exit kills every task. In a --tools-runtime isolate the signal is sent inside it.
  • Each task keeps the newest 256 KB of its output. At most 16 tasks run at once, and the 32 newest finished ones are kept.
  • The cwd and the runtime are the same as for any shell command (x-tool-cwd, x-tool-runtime, --tools-runtime).
  • A foreground command that leaves a child in the background now returns about 1 s after its timeout instead of hanging.
  • On a Windows host with no --tools-runtime, stop ends only the cmd process (no process groups there).

Llama Chat:

  • backgroundTasksStore: each task with its id, command, cwd, conversation, status, exit code, start time and output. Fed by the agentic loop's tool results and by polling shell_task while a task runs (the list every 2 s, the open task's output every 1 s). The conversation of each task is kept in localStorage.
  • ChatSideCards: from 1024 px a third column of the chat screen, beside the messages, so the cards narrow the chat instead of covering it; below that, folded cards floating in the top right corner. More cards can be added later. The first is Background tasks: the tasks the conversation on screen started, running and finished, with status, elapsed time and Stop; Clear finished. The column only appears while a card has something to show for that conversation, so the new-chat screen has none.
  • ChatForm: the one-row layout no longer flips back and forth (Svelte's update depth error) when an empty row does not fit, which the narrower chat column made happen.
  • Opening a task shows its output in TerminalOutput: monospace, ANSI colours mapped to the status tokens, carriage returns applied, follows the tail until you scroll up.
  • The exec_shell_command block of a background start says it is running in the background (or stopped/exited, live from the store) with a Show task link.
  • Storybook: BackgroundTasksCard (tasks, open task, stopping, folded) and TerminalOutput (dev server, tail, progress bar, empty).
Testing
  • Server: tools/server/tests/unit/test_tools_builtin.py passes (22 passed, 5 skipped for docker/podman). New tests: a foreground call with a background child ends near its timeout; start, list, read from an offset, read the tail, stop, and the grandchild is gone after stop; a quick exit reports its exit code; error cases; shell_task is enabled with exec_shell_command; tasks are killed on server exit. The shell_task tests also pass with a setsid on the PATH, and the wrapper was checked with dash.
  • ui/apps/chat: npm run check, npm run lint and the 913 unit tests pass, including new tests for the ANSI parser, the background-task line parser and the store (track, keying by the server list, reading from an offset, stop, dropping tasks the server forgot, Clear finished).
  • In the app against a local build: a task started over /tools shows in the card, its output follows the tail with colours, and Stop ends it. Asked to "start a dev server for static files in /tmp on port 18500", the model (Inkling 2 Mini) called exec_shell_command with run_in_background: true, and the permission card asked for it. The rest of that run (the block's background row) was not checked, because the permission card needs a person to answer it.

Requirements

@github-actions github-actions Bot added documentation Improvements or additions to documentation server server/ui labels Nov 21, 2026
@allozaur
allozaur added this pull request to stack #110 November 21, 2026 13:48
@allozaur
allozaur force-pushed the allozaur/feat/background-tasks branch 2 times, most recently from f781025 to 5213e9c Compare November 24, 2026 06:24
@allozaur
allozaur force-pushed the allozaur/feat/background-tasks branch from 5213e9c to c792f33 Compare November 24, 2026 06:56
@allozaur
allozaur force-pushed the allozaur/feat/background-tasks branch from c792f33 to 0162f51 Compare November 24, 2026 08:28
@allozaur
allozaur force-pushed the allozaur/feat/background-tasks branch from 0162f51 to 4b11fbc Compare November 24, 2026 09:40
@allozaur
allozaur removed this pull request from stack #110 November 24, 2026 09:41
@allozaur
allozaur added this pull request to stack #114 November 24, 2026 09:41
@allozaur
allozaur force-pushed the allozaur/feat/background-tasks branch 2 times, most recently from 4dd26c6 to b144bbe Compare November 24, 2026 13:57
@allozaur
allozaur removed this pull request from stack #114 November 24, 2026 13:58
@allozaur
allozaur added this pull request to stack #126 November 24, 2026 13:58
@allozaur
allozaur force-pushed the allozaur/feat/background-tasks branch from b144bbe to 5226c91 Compare November 24, 2026 14:10
@allozaur
allozaur removed this pull request from stack #126 November 24, 2026 14:10
@allozaur
allozaur added this pull request to stack #127 November 24, 2026 14:10
@allozaur
allozaur removed this pull request from stack #127 November 24, 2026 14:45
@allozaur
allozaur force-pushed the allozaur/feat/background-tasks branch from 5226c91 to c49e493 Compare November 24, 2026 14:45
@allozaur
allozaur added this pull request to stack #129 November 24, 2026 14:46
exec_shell_command takes run_in_background: it returns the first output
and a task id. The new shell_task tool lists tasks, reads their output
from an offset and stops them. Each task runs in a process group of its
own, so stop and server exit reach every process it started.

A command that leaves a child in the background no longer holds a
foreground call past its timeout.

Assisted-by: Claude (Opus 5.5 Medium)
…and a Stop key

Assisted-by: Claude (Opus 5.5 Medium)
On wide screens the side cards now sit in a third column of the chat
screen, which narrows the messages instead of covering them. Narrower
screens keep the folded floating cards. The chat form's one-row layout
no longer flips back and forth when an empty row does not fit the
narrower column.

Assisted-by: Claude (Opus 5.5 Medium)
The side cards show the tasks of the conversation on screen, so the
new-chat screen has no column and one chat's tasks never show in
another. Clear finished clears only that chat's tasks.

Assisted-by: Claude (Opus 5.5 Medium)
@allozaur
allozaur force-pushed the allozaur/feat/background-tasks branch from c49e493 to 4c2e058 Compare November 24, 2026 16:43

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation server/ui server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant