feat(desktop): add background preset launch mode

Closed
MI
3mo ago
+480-66

What & why

Presets that launch GUI tools (e.g. fork ., zed .) opened a foreground
terminal tab that stole focus from the CLI you were working in, needed a
manual ; exit to close themselves and showed the generic terminal glyph
in the presets bar instead of the app's icon.

For v2 workspaces this PR adds:

  • A new background execution mode: commands run in a pane-less
    host-service session with ; exit appended, so nothing opens in the
    foreground, focus stays put and the terminal exits and closes itself
    when the run finishes. While running, the session sits behind the
    existing background-terminals button (adopt or kill from there) and is
    marked so session auto-adoption leaves it alone. The preset editor
    offers the mode as a "Background" segment (single command) or "In the
    background" select entry (grouped commands); the v1 editor does not
    offer it and v1 degrades legacy data to the default new-tab behaviour.
  • A failure toast: useV2PresetExecution listens to terminal:lifecycle
    and toasts the preset name and exit code when a background run exits
    non-zero. Kills arrive as signal exits or dispose broadcasts with code
    0, so they stay silent.
  • Real app icons for GUI-tool presets: a new external.getCommandAppIcons
    procedure resolves the preset's executable via login-shell which,
    follows symlinks to the containing .app bundle and returns
    app.getFileIcon as a cached data URI. The presets bar, its manage
    dropdown and the settings rows fall back to it, so fork . shows
    Fork's icon and zed . shows Zed's. Agent icons (Claude, Codex) keep
    precedence and non-app commands keep the terminal glyph.

How I tested it

  • bun test in apps/desktop: 2296 pass; the 3 failures
    (shell-wrappers, shell-env git.test.ts) also fail on the base
    commit in this sandbox. New unit cases cover normalizeExecutionMode,
    getPresetLaunchPlan, buildBackgroundTerminalCommand,
    getPresetModeLabel and getLaunchModeValue.
  • bun run typecheck --filter=@superset/desktop --filter=@superset/local-db
    and bun run lint pass.
  • Not verified in a running app as don't know how to test locally. May be worth a
    quick visual check that Fork/Zed presets pick up their bundle icons and
    that the background-terminals button shows the session while running
    and clears once it exits.

Checklist

  • PR title follows conventional commits (type(scope): subject)
  • bun run lint and bun run typecheck pass (CI fails on lint warnings too)
  • "Allow edits from maintainers" is checked on fork PRs

Open in Stage

Summary by cubic

Adds a v2-only “background” launch mode for presets so GUI-tool commands run without opening a tab or stealing focus, and adds macOS app‑bundle icons for GUI‑tool presets like fork . and zed .. Background sessions auto‑close and show a failure toast on non‑zero exit.

  • New Features

    • Background execution: pane‑less host session behind the background‑terminals button; appends “; exit” so it closes when done; not auto‑adopted; always uses the background plan regardless of target. The v2 editor offers “Background”/“In the background”; v1 hides it and normalizes to standard tab modes.
    • Failure feedback: listens to terminal:lifecycle exits; non‑zero exits from background runs toast the preset name and code; signal kills stay silent.
    • App icons for GUI tools: external.getCommandAppIcons resolves .app bundle icons via which + Electron app.getFileIcon, caching data URIs. The presets bar (items and manage menu) and settings rows fall back to these when no agent icon matches; non‑app, path‑based, or conflicting commands keep the terminal glyph.
  • Bug Fixes

    • Opening a new terminal tab still creates a blank tab when all apply‑on‑new‑tab presets are background.

Summary by CodeRabbit

  • New Features

    • Added a Background launch mode for terminal presets, allowing commands to run without opening a terminal pane.
    • Added status updates and error notifications for background command execution.
    • Added macOS application icons for command-based presets in preset bars and terminal settings.
    • Added clearer launch-mode settings and guidance for background execution.
  • Bug Fixes

    • Improved handling and persistence of background presets, including mixed or invalid commands.
    • Improved command icon resolution and fallback behavior.