8000 Workspace save/restore should capture per-pane startup commands and browser tabs — plus a project-local, shareable workspace manifest · Issue #284 · amirlehmam/wmux · GitHub
[go: up one dir, main page]

Skip to content

Workspace save/restore should capture per-pane startup commands and browser tabs — plus a project-local, shareable workspace manifest #284

Closed

Description

@SriSatyaLokesh

What are you trying to do?

I want "save this workspace" to mean save what my setup was doing, not just the shape of it.

Today I can save a workspace and get the split layout and each pane's cwd back. But every pane comes back as a bare prompt, so after a restore I still hand-run the same ritual: start the API, start the web app, start the worker, bring up docker, launch claude in the agent pane, then open the browser panel on the right localhost URL. For a single service that's annoying. For a monorepo it's five different commands in five different folders that I have to remember the order of. At that point the saved workspace is a folder bookmark with a layout attached — it is not the setup I meant to save.

What I actually want is one named, reusable, checked-into-the-repo definition: panes + their cwds + the command each one runs + the browser tabs it needs, so that wmux workspace open <name> brings the entire dev environment up, and so a teammate who clones the repo gets the identical environment without me writing a README section about it.

What already works in 2.21.0 (so this is a smaller delta than it sounds)

I poked at the installed app before filing, because most of the primitives are already here:

So the engine is there. What is missing is the authoring and portability layer on top of it.

What's missing

Here is an actual saved workspace of mine (sessions/saved/Auto-save 2026-10-14 16-34.json, trimmed). Note what a surface records:

{
  "type": "leaf",
  "paneId": "pane-2e4c386d-…",
  "surfaces": [
    {
      "id": "surf-b7611f17-…",
      "type": "terminal",
      "resolvedShell": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
      "currentCwd": "D:\\…\\bu-order-ms",
      "cwd": "D:\\…\\bu-order-ms"
    }
  ],
  "activeSurfaceIndex": 0
}

Shell, cwd, cwd again — and nothing about what was running. Concretely the gaps are:

  1. No way to author a command per pane when saving. startupCommands can be persisted, but as a user I have no UI or file to put my own commands in. They only get populated implicitly (agent spawn, --cmd, the Restore Claude Code sessions on workspace restore (claude --resume), behind an opt-in setting #186 resume path) and are marked consumed after firing.
  2. No project-local, shareable workspace file. Saved workspaces live in a machine-global %APPDATA% folder. I cannot commit one next to the code it brings up, so I cannot share it with the team, version it with the repo, or have different branches imply different bring-up.
  3. Browser panel is one URL, not a tab set. Monorepo work needs web app + API docs + admin + Grafana open simultaneously.
  4. No ordering or readiness. Postgres must be listening before the API's migrations run; the API must be up before the e2e watcher is useful. Firing all panes at t=0 just means some of them crash-loop in front of me.
  5. No run-once vs run-every-time distinction that I control. startupConsumed is an internal one-shot flag; I want npm install to be once-per-create and npm run dev to be every-open.

Real-world use cases

These are the ones that actually cost me time, not hypotheticals.

1. Morning bring-up of a monorepo. Five services, five folders, five commands, one dependency order. Currently ~2 minutes of mechanical typing before I can do anything, every single morning, and I get the order wrong often enough to notice.

2. Onboarding a new developer. Right now this is a README section titled "Running locally" that is always slightly out of date. With a committed workspace file it becomes: clone, wmux workspace open, trust the prompt, done. The environment definition lives next to the code and rots at the same rate as the code — which is to say it gets fixed when it breaks.

3. Incident / hotfix. A dedicated hotfix workspace: one pane tailing prod logs, one pane on the hotfix branch, browser tabs pinned to Grafana + the incident doc + the deploy pipeline. I want to enter that context in one command at 2am, not assemble it.

4. Code review. A review workspace: pane 1 gh pr checkout $PR && git diff main...HEAD, pane 2 running the app at a different port than my main dev workspace so both can coexist, browser on that preview port. Today the port collision alone makes me tear down my main workspace first.

5. Multi-agent work (wmux's whole premise). Three claude panes, each already cd'd into a different package with a different scoped starting prompt, plus one orchestrator pane at the repo root. This is exactly the layout wmux is built for, and it is currently the thing I rebuild by hand most often. #186 solved resuming an existing session; this is about standing up the intended set in the first place.

6. Client/context switching. Two client monorepos with overlapping default ports. Each workspace file pins its own PORT env and its own browser tabs, so switching contexts is one command instead of a port-conflict scavenger hunt.

7. Demos. Deterministic bring-up with fixed ports and pre-opened tabs, so a demo never starts with me typing commands on a projector.

Proposed design

A. Per-pane startup commands in the save flow (the minimum useful version).

When saving a workspace, each pane gets an editable command field, prefilled with a best guess from what that pane actually ran (wmux already receives this: report_startup_command / report_command arrive over raw-v1 from the shell integration). Persist it into the existing per-surface startupCommands. That alone fixes the single-service case with no new file format.

B. A project-local workspace manifest (the part that makes it shareable).

A file the repo owns — wmux.workspace.json at the repo root, or .wmux/workspace.json:

{
  "version": 1,
  "name": "platform-monorepo",
  "root": ".",                       // resolved relative to the manifest
  "browser": {
    "tabs": [
      "http://localhost:5173",       // web app
      "http://localhost:4000/docs"   // API docs
    ],
    "active": 0
  },
  "layout": { "direction": "vertical", "ratio": 0.6 },
  "panes": [
    {
      "id": "infra",
      "cwd": ".",
      "run": ["docker compose up db redis"],
      "when": "always"
    },
    {
      "id": "api",
      "cwd": "apps/api",
      "run": ["pnpm install", "pnpm dev"],
      "runOnce": ["pnpm install"],         // first create only
      "after": ["infra"],
      "waitFor": { "port": 5432, "timeoutMs": 60000 },
      "env": { "PORT": "4000" }
    },
    {
      "id": "web",
      "cwd": "apps/web",
      "run": ["pnpm dev"],
      "after": ["api"],
      "waitFor": { "http": "http://localhost:4000/health", "timeoutMs": 60000 },
      "env": { "PORT": "5173", "VITE_API_URL": "http://localhost:4000" }
    },
    { "id": "worker", "cwd": "apps/worker", "run": ["pnpm dev:worker"], "after": ["infra"] },
    { "id": "agent",  "cwd": ".",            "type": "agent", "run": ["claude"] }
  ]
}

Single-service projects just write the short version:

{
  "version": 1,
  "name": "my-api",
  "panes": [
    { "cwd": ".", "run": ["npm run dev"] },
    { "cwd": ".", "run": ["claude"] }
  ],
  "browser": { "tabs": ["http://localhost:3000"] }
}

C. CLI surface.

wmux workspace save <name> [--to ./wmux.workspace.json]   # capture live workspace → manifest
wmux workspace open [path|name] [--trust] [--dry-run]     # bring it up
wmux workspace list
wmux workspace validate ./wmux.workspace.json

--dry-run prints the pane tree, resolved cwds, resolved order and the exact commands, and runs nothing. That doubles as the preview for the trust prompt below.

How this could be built without much new machinery

Roughly in dependency order, each step shippable on its own:

  1. Capture + edit. Add a freezeSurfaceStartupCommands alongside the existing freezeSurfaceCwds so the save path folds live/authored commands into the saved tree. Prefill from the report_startup_command value wmux already receives. (Schema already supports it — nothing new to persist.)
  2. UI. Per-pane command field in the save dialog; the startupCommandsPlaceholder / startupCommandsToggle components already exist in the bundle and can be reused rather than designed.
  3. Browser tabs. Widen the existing workspace-level browserUrl: string to an optional browserTabs: string[] (keep browserUrl as the v1 fallback so old saves keep working). Browser is already a surface type, so panel tabs and in-tree browser surfaces can share the restore path.
  4. Manifest reader. Parse wmux.workspace.json into the same internal spec the quick-launch profiles from Feedback from a Windows user: notification sounds, installer/Store distribution, CLI new-instance bug, and per-pane quick-launch profiles #32 already consume ({name, type, cwd, startupCommands}). The manifest is then just a second, project-local front-end to an object shape the app already understands.
  5. Execution. Reuse typeStartupCommands + WMUX_STARTUP_COMMANDS / bakeIntoInit exactly as-is. This is the path already hardened against Restore races the shell: the injected 'claude --resume' is partly swallowed, leaving 'esume' in the session picker #251; the feature must not introduce a second, unhardened way to inject text into a pane.
  6. Ordering. after is a tiny DAG (topological sort, reject cycles at validate time). waitFor is a bounded poll in the main process — port = TCP connect, http = GET expecting <500, delay = ms — gating only the dependent pane's command dispatch, never the pane creation itself. Panes with no after all start at t=0 as today.
  7. CLI verb. workspace joins the existing verb set over the current local-socket transport. No new IPC mechanism.

Guardrails

This feature executes commands from a file, and point B means that file can arrive from a git clone. That is the whole risk surface and it needs to be designed in from the start, not added later.

Security

  • Workspace trust, mandatory. A manifest must never auto-run on first open. Prompt once per (path + content hash), showing the full resolved command list, exactly like VS Code Workspace Trust or direnv allow. Store the allowlist outside the repo (in %APPDATA%/wmux), so the repo can never mark itself trusted.
  • Re-prompt on change. Any edit to the manifest invalidates the stored hash and re-prompts, with a diff of what changed. Otherwise a trusted repo becomes a persistent execution channel that a later git pull can quietly repoint.
  • Never auto-open a manifest just because one is present in the cwd. Opening a workspace manifest is always an explicit user action (wmux workspace open, or a clearly-labelled "this folder has a workspace file — open it?" affordance). No ambient discovery-and-run.
  • No secrets in the manifest. It is committed. env values should support indirection (${env:FOO}, or a pointer to a gitignored .env) and the docs should say plainly that literal tokens do not belong there. Consider warning at validate time on values that look like credentials.
  • Path containment. Resolve every cwd against the manifest root and reject escapes (.., absolute paths, symlinks out of the tree) unless the user explicitly opts in. A manifest should not be able to point a pane at C:\Windows\System32 without the user seeing it.
  • Shell-injection realism. Commands are strings run in a shell by design; the protection is the trust prompt and the visible preview, so the preview must show the final resolved string after any variable expansion, not the template.

Reliability

  • Reuse the Restore races the shell: the injected 'claude --resume' is partly swallowed, leaving 'esume' in the session picker #251-hardened injection path. Do not type into a cold PTY. If a shell has no integration available, fall back to the env/init handoff rather than racing.
  • Bounded waits. Every waitFor needs a timeout with a sane default. On timeout, surface a clear error in that pane and continue with the rest — a stuck dependency must not hang the whole restore.
  • Visible failures. If a command exits non-zero immediately, or a port is already in use, that pane should show it loudly. The current failure mode of this feature class is a pane that looks fine but silently never started — worse than no automation at all.
  • Idempotency / double-start. Detect that the target port is already listening and ask rather than starting a second copy. Re-opening an already-open workspace should focus it, not fork the whole environment.
  • runOnce vs run. Honour the existing consumed-once semantics for the install-type steps, and re-run the long-lived ones. The user, not the app, decides which is which.
  • Concurrency cap. Bringing up 8 services at once on a laptop is a thundering herd. A small default parallelism limit (with an override) keeps restore from pinning the machine.
  • Respect the existing per-pane toggle. If the user has startup commands switched off for a pane, the manifest must not override it.
  • Graceful degradation. Missing folder, missing binary, unparseable manifest → fail that pane with a readable message and still restore the layout. Never refuse to open the workspace at all.

Relationship to existing issues

Not a duplicate of these, but it builds directly on them:

Acceptance criteria

  • A pane's startup command can be entered/edited by the user and survives save → restore.
  • A workspace can be saved to, and opened from, a project-local file that can be committed.
  • Opening a monorepo manifest brings up N panes in N different cwds with N different commands, plus the agent pane, in one action.
  • Browser panel restores multiple tabs, not just one URL.
  • after / waitFor order the bring-up, with bounded timeouts and visible failures.
  • An untrusted manifest never executes anything before an explicit, preview-showing consent; edits re-prompt.
  • --dry-run shows the fully resolved plan and runs nothing.
  • Existing saved workspaces (no commands, browserUrl only) keep working unchanged.

Environment

  • wmux 2.21.0, Windows 11 Pro 10.0.26300, default shell pwsh 7.

Activity

  1. amirlehmam commented on Oct 14, 2026

    @amirlehmam
    Owner

    Thanks, this was an excellent writeup. Shipped in 2.23.0. The format is your proposal B almost as written, and the guardrails are built in rather than added later. Full reference: docs/workspace-manifest.md.

    Your acceptance criteria

    • A pane's startup command can be entered/edited and survives save → restore. Right-click a terminal tab → Startup command…. It is stored in the existing startupCommands field, so it runs on restore and from saved sessions and layouts, and wmux workspace save writes it as that pane's run.
    • Saved to and opened from a project-local file that can be committed. wmux.workspace.json or .wmux/workspace.json, via wmux workspace save [--to …] and wmux workspace open [path]. The palette also has Open workspace file….
    • A monorepo manifest brings up N panes in N folders with N commands, plus the ag 7BC4 ent pane, in one action.
    • Several browser tabs. browser.tabs opens as tabs in one browser pane. The old single-URL side panel is unchanged, so existing saves keep working.
    • after / waitFor order the bring-up, with bounded timeouts and visible failures.
      • after is sorted so dependencies go first, and a cycle is rejected when the file is checked.
      • waitFor takes exactly one of port, http (any answer below 500) or delay. The timeout defaults to 60 s, with a 10 min maximum.
      • A held pane shows a yellow [wmux] waiting for api, port 5432… line. A timed-out pane says so and runs nothing, and the panes after it still start.
      • Panes are created immediately; only their commands wait.
    • An untrusted manifest never runs anything before an explicit consent that shows the commands, and edits re-prompt.
    • --dry-run shows the fully resolved plan and runs nothing.
    • Existing saved workspaces keep working unchanged.

    Guardrails, and where I went a different way

    • There is no --trust flag. Consent is a wmux dialog, not a pipe argument. Every terminal wmux opens can talk to the pipe, AI agents included, so an agent could pass --trust on a manifest it just edited. That is exactly the hole the trust prompt exists to close.
      • The dialog shows the same plan that will run: the file is read once, hashed, and that text is what you approve.
      • Trust is keyed on (path, sha256) and stored in %APPDATA%\wmux. Any edit re-prompts with the added and removed commands.
      • Open without running brings up the layout, folders and env and types nothing.
    • Paths and hosts are restricted. cwd must be relative and stay inside the repo, also after resolving links, so a junction can't point out of it. waitFor only probes this machine: a file someone else wrote shouldn't be able to make wmux scan other hosts.
    • Secrets and command shape. ${env:NAME} is resolved when the pane starts and saved only as the reference. A literal value under a key that looks like a secret gets a warning at validate time. A command can't contain a line break, so the preview is always exactly what gets typed.
    • Commands are not saved in wmux's session. After a wmux restart the layout comes back, and wmux workspace open starts the processes again. Replaying them on restore would skip the trust check after a git pull changed the file. Re-opening a workspace that's already open focuses it; --new opens a second copy.
    • No pre-filled command field from what the pane last ran. wmux deliberately never sends typed command lines around internally, because that's where credentials show up. So you set the command yourself (right-click the tab, or write it in the file).
    • Not in this version: detecting that a port is already in use, a limit on how many panes start at once (a workspace is capped at 8 panes), and per-pane when values other than always. layout takes the same presets as wmux new-workspace --layout rather than a direction and ratio. If any of these turns out to matter in practice, I'm happy to add it.

    Every command goes through the same input path as #251, so this adds no second way of typing into a pane. A held pane gets its commands once its shell is ready.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0