8000 min-zed/CLAUDE.md at main · gominimal/min-zed · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
307 lines (293 loc) · 21.5 KB

CLAUDE.md

File metadata and controls

307 lines (293 loc) · 21.5 KB

CLAUDE.md

min-zed opens Minimal boxes (min sessions, libkrun microVMs) in Zed as ssh remote projects (zed ssh://min-zed.NAME/workbench), with sshd running inside the box behind a min session exec ProxyCommand. One POSIX shell script plus a python3 merger, no build step. It is the Zed twin of min-vscode (gominimal/min-vscode): same plumbing and commands; only the editor-specific constants, the merger and the loadout differ. There is no Zed extension (Zed's WASM API has no UI): the UI is Zed's own surfaces, which setup wires: the Remote Projects list (ssh_connections), global tasks, and one key.

Layout

File Role
bin/min-zed tool constants, then the transport/ssh/session plumbing, then the client layer, whose first block holds every editor-specific constant
plumbing transport, box ids (stored_id, pick_id, box_id, need_box, own_filter, id_field), PREP/prepare, stored_path, ssh options and stanzas, ssh-config, _proxy, ssh, naming, pick_session, activate_session, destroy_one, in_use_names/box_in_use, track_orphans, default_loadouts, the ssh-config record, report helpers; editor-neutral, reaching the client layer only through its hooks
client layer open/new/attach (session, stanza, settings, zed ssh://… unless --no-window; new --empty; on a terminal new offers PATH's live box), destroy (--if-idle; no NAME: the cwd's own box, else on a terminal the picker), gc, status (--json), doctor, completions, config (alias zed-config), setup, hidden _sessions; hooks client_on_connect and client_on_destroy (settings sync)
bin/min-zed-config python3 merger for three JSONC files in ~/.config/zed: settings.json (ssh_connections entries for live sessions, edited in place), tasks.json and keymap.json (a marked block at the top of the array: the Minimal tasks, the local-terminal key); --install, --sync NAME..., --remove, --doctor, --dry-run
loadouts/zed.toml, loadouts/zed/ openssh curl rsync xxhash git; sshd env prep; min:workbench rc line; a patch copying zed/skills/minimal-sandbox to ~/.claude/skills in the box. setup copies zed/ beside the linked toml: $LOADOUT_ROOT must be a real directory
skills/, loadouts/zed/skills/ Minimal's skills, vendored from gominimal/minimal-skills (MIT) at a pinned commit by just skills: the host ones (setup copies them into the Mac's ~/.agents/skills (Zed's agent) and ~/.claude/skills, marked .min-zed-copy, never over a dir with no .min-*-copy mark; one another min tool marked is shared, keeping its mark, and --remove deletes it only once no other mark is left) and minimal-sandbox (box only: the host ones teach commands a box lacks)
minimal.toml developing this repo in a box: session packages for just check; task check (min task run check)
justfile check, install/uninstall (= setup), ssh-config, zed-config, skills
tests/run.sh, tests/stubs/ plain-sh tests over stub min, zed, ssh, ssh-keygen, ps (+ find/mv for PREP races) and a tripwire for bare GUI commands; LONG_PREFIX=1 reruns them with a long host prefix; the destroy picker runs on a pty through script(1) (skipped without it); fixture ids are UUIDs (ID_A, id_of NAME), and the ids_* cases cover box ids
docs/ user docs (being rewritten for 0.2.0), public/ marks and badge

The Zed UI (what config writes)

  • One ssh_connections entry per live own session, {"host": "min-zed.NAME", "nickname": "NAME", "projects": [{"paths": ["/workbench"]}]}: the Remote Projects modal (ctrl-cmd-o), reloaded live.
  • tasks.json block, seven tasks: Minimal: New Box from Folder… (new FOLDER: the window's folder, given as env MIN_ZED_TASK_FOLDER: ${ZED_WORKTREE_ROOT:none} so the task is offered with no folder open too; with none, or a single-file window, it asks in macOS's folder picker (osascript choose folder, from $HOME; cancel exits 0); without osascript it prints one line saying to open a folder; new then offers the folder's live own box, [Y/n], before a second one), Minimal: New Empty Box (new --empty), Minimal: Open Box… (attach: picker), Minimal: Destroy Box… (destroy: the cwd's box, else picker), Minimal: Clean Up Idle Boxes… (gc), Minimal: Status, Minimal: Doctor. Each runs through "shell": {"program": "sh"} (any login shell) and calls $HOME/.local/bin/min-zed by absolute path; where that is missing (a box window: global tasks run in the box) it prints one line pointing at a local window or the local-terminal key, and exits 1. The CLI's own y/N questions and numbered pickers are the UI. reveal: always, use_new_terminal: false, allow_concurrent_runs: false, show_command: false; hide: on_success for the three that open a window, never for the rest. No $ZED_* variable in a command or cwd: Zed pastes them into a command unquoted, and a root may be a file.
  • keymap.json block, context Workspace: ctrl-alt-` → ["workspace::NewTerminal", {"local": true}] (a Mac terminal from a box window); ctrl-alt-n/ctrl-alt-o → ["task::Spawn", {"task_name": …}] for New Box from Folder…/Open Box… (Zed's welcome page is hard-coded, so keys are how the tasks reach it; both free in the default macOS and vim keymaps). Free in Zed 1.26.2's default macOS keymap, beside ctrl-` (terminal panel) and ctrl-~ (new terminal). No task bindings: cmd-shift-r, then "Minimal".

Invariants

  • Session names match ^[a-z0-9][a-z0-9-]*$, -n included: they are hostnames and ssh Host patterns. Without -n, min names the session; activate_session takes the one new session for the path and refuses a name that is no hostname.
  • Host alias is min-zed.NAME (HOST_PREFIX); nothing hard-codes the prefix length (the long-prefix test run guards it).
  • prepare re-pins the host key and re-pushes the public key on every open/attach/ssh/_proxy, so a box min-zed recreated self-heals; it never replaces a recorded id with another. _proxy always runs prepare and writes nothing to stdout before exec (stdout is the SSH byte stream). _proxy and prepare never call client hooks, never touch Zed's files.
  • ssh-config is an opt-in gate: nothing under ~/.ssh is touched until it has run. ssh-config --remove leaves ~/.ssh/config byte-identical to before install; --print writes nothing (not even a legacy key dir's adopted id: PICK_NOADOPT). Other tools' Include lines are never touched.
  • config is the same kind of gate for Zed's files: --sync is a no-op until config has run (STATE/settings-installed), and --sync (from open/attach/ssh/destroy/gc) touches only ssh_connections; only config (--install, also run by setup) writes the tasks and keymap blocks. Settings: only entries whose host starts with the prefix are added or removed; an existing entry of ours is kept verbatim; every other byte (comments between entries, CRLF, BOM) stays; the key is removed only if we added it (STATE/settings-key-added); adding ours and taking them out again gives back the bytes (a comment after the user's last entry stays on its line). 0.1.0's STATE/zed-config-installed and zed-config.json are taken over once (opt-in, key added, file created). Tasks/keymap: the block between // min-zed:begin and // min-zed:end (the marks only as comment lines of their own, the first right after the top-level [) is ours and rewritten whole (Zed's keymap editor appends after it); a file with no array gets one marked // min-zed:array, taken out with the block while nothing else went into it. For all three: dated backup in STATE/backups/ before a write; written through a symlink, replaced atomically; never written when unchanged; --remove restores the bytes it found and deletes a file it created (STATE/<file>-created) once empty; a file that does not parse (or is not UTF-8, or has the wrong top level) is refused, and then none of the three is written. Settings sync is skipped when min ls fails. ssh_connections stays keyed by host alias (min-zed.NAME, nickname NAME), never by id; it lists only own boxes (prepared_live: own_filter, without adopting).
  • The host key is pinned (StrictHostKeyChecking=yes); never accept-new.
  • Agent and X11 forwarding stay off on every client path: one option list (ssh_common) feeds both the stanza and ssh_opts.
  • Facts the box reports (user, hostkey, home, sshd) are untrusted: prepare validates them before writing anything, and dies if a write fails; stored home/sshd are re-checked on read (stored_path) by _proxy and by the ProxyCommand ssh builds.
  • gc and destroy never destroy without an explicit y; -y is the only way past destroy's question.
  • A box is gone (keys, records and stanza dropped, client_on_destroy run by destroy_one) only when a successful min ls no longer lists its id; a failed min ls keeps everything (ssh-config not rewritten), warns, and after a y exits non-zero; destroy NAME drops what was kept once a successful min ls no longer lists the recorded id, even while another box holds the name (never touching that box); for a key dir with no id, once no box is named NAME. min_ls fails unless its output has a .sessions array, so junk on exit 0 is a failed min ls, never "no box"; own_filter fails with its jq, and a box listed under NAME with no usable id (pick_id 7) is "no id to trust", never "none".
  • Every min call aimed at one box passes its id, never its name (min 0.8 resolves a name to whichever box holds it): session exec (prepare, _proxy's exec, proxy_command) and session destroy (destroy_one). The id is STATE/sessions/NAME/id (activate_session: the one id new in min ls, named NAME with -n, else for PATH, a null name refused; prepare writes it with the facts, and refuses a bad id file or a different id, never writing over either), checked against ID_ERE on every read (stored_id, which also refuses a NAME that is no session name) before it reaches a command line or a stanza. pick_id/box_id resolve NAME: own (the recorded id, listed under NAME); a key dir with no id adopts the one box named NAME (and writes it only on a connect: attach/ssh/_proxy through box_id/need_box, open through prepare once the project checks out; own_filter always runs pick_id under PICK_NOADOPT=1, so no list adopts: open's reuse, the pickers, the cwd lookup, gc, status, completions, stanzas, prepared_live; cmd_open, cmd_destroy, ssh-config, config, setup and doctor set it too). destroy never writes an id: an explicit destroy NAME reaches the one box of the name by its id without recording it, and a NAME the cwd lookup or the picker chose is refused unless its id is recorded ("NAME has no recorded box id yet; …"). gc never adopts or destroys a key dir with no id: it lists it ("no id recorded (attach NAME once)") without asking. status --json gives recorded. In-use checks of own boxes go by name and id (gc rows, gc_still_idle NAME ID, st_used, track_orphans). min_ls needs exactly one JSON value whose .sessions is an array of objects; a jq failure in pick_id is status 8 ("could not read min ls"), never "none"; pick_id returns 1 for a NAME that is no session name before touching sess_dir; several boxes named NAME, none recorded, a bad id file, or a listed box with no usable id: no id (box_id status 2, BWHY), so an explicit NAME dies saying why, doctor warns, it is not own and gets no stanza or ssh_connections entry; never a by-name call. A recorded id is never traded for a box found by name: ours gone (id unlisted; pick_id 5) with another box named NAME is box_id status 5, "your box NAME is gone": destroy NAME drops only our keys and records, everything else refuses; ours listed under another name or none (pick_id 6) is refused everywhere. A NAME chosen from the own list (the cwd, the pickers) resolves with own. A failed min ls keeps every stanza but a bad-id one. An explicit NAME that is not own and has no recorded id reaches the one box of that name (attach, ssh, open -n, destroy), refused when several share it; _proxy NAME only an own box, or the one box of that name when there is no key dir at all (a stanza of a box of ours that is gone never reaches the box that took its name). Helpers reading one session (id_field, ls_lists) select by id.
  • gc offers only own sessions (own_ls: a key dir STATE/sessions/NAME whose recorded id min ls lists under NAME; status --json gives id), and gc/status date only those in orphan/ (track_orphans, each run); boxes made by min alone are never listed. The same holds wherever a session is chosen for the user: open's reuse of a live session for PATH, new's offer of one, destroy's cwd lookup and its picker, the attach picker and _sessions (completions). Only an explicit NAME (attach NAME, ssh NAME, destroy NAME, open -n NAME) may reach another tool's box.
  • new asks only on a terminal and only without -n or --empty: [Y/n] to attach to PATH's live own session (live_box over own_filter, as open reuses), and only an n makes the second box. Without a terminal it is always a new session. A box of another tool is never offered: min's refusal stands. On a y it reaches the box by id: a key dir with no recorded id is adopted as open's reuse adopts (prepare records it); an n, or no terminal, writes no id for it.
  • destroy without NAME: exactly one own session for the cwd is it; otherwise, on a terminal (a Zed task), the own-session picker; without a terminal, or with no own session at all, the errors ("no session for DIR; pass NAME", "several sessions for DIR: …; pass NAME").
  • In use = some host process runs min session exec X ... sshd (any ssh client's connection); X is an id or a bare name (connections from before ids, other tools), and every check of an own box asks for both. Never contact a box without such a live process: a connect starts a stopped box.
  • gc re-checks gc_still_idle before each question; destroy --if-idle re-checks it too (exit 3 when in use); without a terminal, unsaved changes exit 4 and only destroy -y --force discards them.
  • Activation passes the user's default_loadouts on before --loadout zed.
  • What ssh-config created under ~/.ssh is recorded in ~/.local/state/min-clients/ssh-config-created; removing the last Include ~/.ssh/min-*.conf deletes only that, so ~/.ssh/config ends byte-identical.
  • Install never edits default_loadouts; setup --remove (just uninstall) removes only our own links, marked skill copies, Zed entries and blocks, and Include; when the merger refuses a Zed file it removes nothing else and fails. setup replaces a link only when missing, dangling, or pointing to another copy of the same file (a moved checkout); stanzas bake the ~/.local/bin link, so it follows the checkout.

External facts that bite

  • min 0.8.0-dev.381 (gominimal/minimal#2756, BOX-004/005): a session name is an alias many boxes may share. A stopped box keeps its name, and min ls still lists it, but it does not stop a new box from taking the name; only a running box (or a resume in flight) does (minimald's claim_name/running_name_holder). A name resolves to the running box, else the latest. session exec, attach, destroy, rename and policy take a full session id first (SessionLookup::parse), and min ls --json gives each session's id (lowercase hex UUID) and name (which may be null).
  • min is a zsh function on the host; MIN_BIN is resolved to an absolute path and baked into each stanza (Zed spawns ssh with the launchd PATH).
  • Without zed on PATH, bin/min-zed uses the app's own CLI ($MIN_ZED_EDITOR_APP/Contents/MacOS/cli, default /Applications/Zed.app); MIN_ZED_EDITOR_BIN overrides both. zed --version prints Zed 1.26.2 – /Applications/Zed.app; doctor notes a version other than the tested 1.26.2.
  • bin/min-zed appends /opt/homebrew/bin, /usr/local/bin and ~/.local/bin to PATH (unless MIN_NO_PATH_EXTEND=1, which tests set, with ZDOTDIR VISUAL EDITOR unset), where the real zed lives: tests must point MIN_ZED_EDITOR_BIN (and every other *_BIN) at an absolute stub path, never a bare name. Bare open, osascript, zed, code, cursor and windsurf on the test PATH are tests/stubs/tripwire (stubs live in $T/stub-bin), and any tripwire line fails the case. A mutation check never removes or bypasses a stub or the tripwire; skip any that could launch a real app.
  • ssh runs the ProxyCommand via $SHELL -c "exec ..." and expands % tokens: every word goes through shq and the whole string through pct.
  • Zed 1.26.2, seen live 2026-10-29: ssh_connections entries appear in Remote Projects and reload live; global ~/.config/zed/tasks.json tasks run on the Mac in a local window and in the box (bash, cwd /workbench) in a box window; ["workspace::NewTerminal", {"local": true}] opens a Mac terminal from a box window; a new box host opens in Restricted Mode until trusted once; agent notifications fire for box threads.
  • Zed task commands go through shellexpand (Zed source, v1.26.2): $ZED_* variables are pasted into the command text unquoted, a task whose $ZED_* variable is unset is not offered unless it is written ${ZED_VAR:default}, other $VARS are left to the shell. env values get the same substitution but are no shell text, and the task variables are exported too. ZED_WORKTREE_ROOT is set without a directory check: in a single-file window it is the file. Tasks run in an interactive terminal (sh -i -c), so [ -t 0 ] holds.
  • Restricted Mode (Zed source, v1.26.2): trust is stored per (ssh user, host, path) in Zed's SQLite db, read at startup and rewritten from memory, so each new box name asks once (a box recreated under the same name keeps its trust). Trust also lets project settings start MCP servers, which run on the Mac unless "remote": true: the box does not contain them. The Mac decides itself (worktree_store.rs calls can_trust with the Mac's settings), so a "linux" settings override that reaches the box server does not stop the dialog. The only switch, session.trust_all_worktrees, also trusts every local folder: config never writes it. Per-host trust asked upstream: zed-industries/zed#66313.
  • Zed downloads its remote server into the box itself: ~/.zed_server/zed-remote-server-stable-<ver>+stable.<build>.<sha>. Claude Agent (ACP) runs in the box with the Node Zed downloads (~/.local/share/zed/node; the loadout needs none) and reads ~/.claude/skills there; Zed's own agent runs on the Mac and reads ~/.agents/skills/<skill>/SKILL.md.
  • Claude Agent's adapter (agentclientprotocol/claude-agent-acp) runs $CLAUDE_CODE_EXECUTABLE instead of the SDK's own claude and loads user settings. Minimal's claude package (min add claude) is a /usr/bin/claude wrapper adding --plugin-dir=/usr/share/claude/plugins/minimal (skill, SessionStart primer, denial-triage hook). PREP and the loadout hook set the variable in ~/.ssh/environment only when /usr/bin/claude exists; never Zed's global agent_servers env, which local windows share. Unverified: that the variable reaches the agent process, and that the SDK runs the wrapper.
  • The box is uid 1000 with $HOME=/home, aarch64, glibc 2.44, has bash, tar, curl and awk (GNU Awk 5.4.1; seen 2026-11-10); sshd at /usr/sbin/sshd. No python3 or zsh unless a loadout or the project brings them; these loadouts need neither.
  • sshd scrubs the environment: PREP writes ~/.ssh/environment (filtering PROMPT_COMMAND/MINIMAL_MOTD) and sshd runs with PermitUserEnvironment=yes.
  • The box's env (GNU coreutils 9.12) shell-quotes values (X='a b'), which sshd would read literally: PREP and the loadout hook dump the environment with awk's ENVIRON (env only without awk), dropping multi-line values whole. gawk adds AWKPATH/AWKLIBPATH to ENVIRON when unset; they pass the filters (filtering them would drop a user's own).
  • In the box, the host key and authorized_keys live in ~/.ssh/min-zed/.
  • Without a terminal, min session destroy refuses a box with unsaved changes ("refusing to destroy the session without confirmation; pass --force").

Working here

  • Verify: just check.
  • Tests never touch the real min, Zed, ~/.ssh or ~/.config: stubs first on a private PATH, HOME, MIN_ZED_STATE_DIR, MIN_ZED_SETTINGS, MIN_ZED_TASKS and MIN_ZED_KEYMAP in a tempdir.
  • Don't create, attach or destroy min sessions, or min session exec into one, without asking. Don't run ssh-config, config, _proxy, just install/uninstall against the real HOME; use HOME=<scratch> XDG_CONFIG_HOME=<scratch> and a stub MIN_BIN.

Unverified (needs a live session)

  • New Box from Folder… with no folder open: the osascript folder picker (may open behind Zed's window).
  • Destroying the box a window is on: what that window does.

Seen end to end (Zed 1.26.2, 2026-10-29): the tasks through sh, the folder through env, hide: on_success, pickers and y/N in a task terminal, the box-window guard line, all three keys (US keyboard), Remote Projects, setup --remove restoring ~/.ssh/config byte-identical.

0