Skip to main content

0018: Supervised argv tasks with provider parsers, and a PTY terminal

  • Status: Proposed (implemented in Phase 2, task 011)
  • Date: 2026-12-05

Context​

Building, testing and running code means starting the workspace's own tools. Those tools run arbitrary project code, write large amounts of output and spawn process trees. Results such as compiler errors and failing tests are only useful when they are structured and clickable. Users also expect an interactive terminal. Each of these is a way for a repository to run code, so each must respect workspace trust and stay within bounds.

Decision​

  • Tasks are typed commands. A provider describes a task (TaskDescriptor with an action: build, check, restore, run, test) and resolves it to an Invocation (program, argument vector, folder, environment) plus an OutputParser. Custom commands are a program and an argument list. Nothing is joined into a shell string. The provider contract version is now 2.
  • The host decides whether and how it runs. ide-core checks trust when a task is queued and again just before the process starts. It also checks that the folder and any relative program path are inside the workspace, looks bare names up only on absolute PATH entries, and validates environment overrides. It then starts the task under the existing process supervisor, which owns the whole tree.
  • Bounded output, structured results only from parsers. Two byte rings (stdout and stderr) keep the newest 1 MiB each, with a marker for what was dropped. Each line, cut to 8 KiB, goes to the provider's parser. Results are bounded, and their paths are resolved and checked against the workspace. An exit code never becomes a diagnostic.
  • Revocation and cancellation. Revoking trust or switching folder fails queued runs and kills running trees. Cancel terminates gracefully and then kills.
  • Terminal = real PTY + mature emulator. ide-terminal uses portable-pty (Unix PTY, Windows ConPTY) and vt100, both MIT. It has a bounded scrollback, a bounded input queue, resizing, xterm key encoding and bracketed paste. A terminal is opened only by the user, needs trust, and is killed on close, revoke, folder switch or exit.
  • AI sees snapshots, not processes. The AI host can read a redacted TaskResultSnapshot with provenance. It cannot start tasks or type into a terminal.

Alternatives considered​

  • Run tasks through a shell (sh -c, cmd /c). Familiar, but it reintroduces quoting and injection problems and differs per platform. Rejected; users who need a shell can name it as the program.
  • Infer errors from exit codes or generic regexes. It is cheap, but it produces wrong or invented results. Rejected: parsers belong to providers that know the tool's format (tasks 012 to 014).
  • alacritty_terminal for emulation. It is more complete, but it brings a larger API surface and its own event loop. vt100 is small, MIT and enough for a panel terminal. This can be revisited if fidelity falls short.
  • Supervise the terminal shell like a task. It would give whole-tree ownership, but a PTY child must be the session leader of the pseudo-terminal, which portable-pty sets up. Closing the PTY hangs up the session instead.

Consequences​

  • A new crate, ide-terminal, isolates the PTY and emulator dependencies (which contain platform unsafe code) from the core.
  • Background jobs started inside a terminal can outlive it. Task process trees cannot.
  • Task settings last for the session; saving them is future work.

Validation​

  • crates/ide-core/tests/tasks.rs uses a real child process to cover:
    • argv with spaces and shell metacharacters;
    • the working folder;
    • environment overrides and secret masking;
    • trust refusal, the re-check at start, and revocation killing a process tree;
    • cancel, and the queue limits;
    • output floods with the marker;
    • exit codes without invented results;
    • program and folder checks;
    • a provider task with parsed diagnostics, tests, unreadable lines and a parser panic;
    • navigation, and the AI snapshot;
    • terminals needing trust and closing on revoke.
  • crates/ide-terminal/tests/pty.rs runs a real shell to check commands, exit codes, resizing, scrollback and input bounds, kill and hang-up, and bracketed paste.
  • The desktop tests drive the Tasks panel, the editor dialog, the palette, cancel and the terminal through the real UI.