32 Commits
Author SHA1 Message Date
w3cjandClaude Opus 5.5 947decb301 fix(vm): VMs get the host terminal's COLORTERM (fixes #54)
limactl shell asks ssh to send COLORTERM (SendEnv), but its session
rides Lima's shared ssh connection (ControlMaster), opened without it,
and the master filters a session's environment by its own SendEnv, so
the variable never reached the VM (lima-vm/lima#2208, #1481). Closing
that connection would end every session and the VM's SSH agent relay,
so devvm now sets COLORTERM in the command it runs in the VM instead:

- backend.ShellOpts and ExecOpts get ColorTerm. Lima's Exec runs
  `cd D && export COLORTERM=<quoted> && exec argv`, and its Shell, with
  a ColorTerm, runs `sh -c 'export COLORTERM=<quoted> && exec "$SHELL"
  --login'`, as limactl shell does without a command; without one, the
  argv is as it was. colorTerm (lima) quotes the value with shell.Quote
  and links Lima #2208, so it can go once Lima sends it.
- vm's colorTerm is the one allow-list: only truecolor and 24bit pass,
  anything else or none is "". target.shell (devvm's shell) and
  AgentLogin.loginOpts (an agent's login on a terminal) fill it from
  Env.Getenv; no other command in the VM gets it.
- devvm's ssh config entries add `SendEnv COLORTERM`, so plain ssh by
  name (ControlMaster no) sends it: the e2e showed the base's sshd has
  AcceptEnv COLORTERM. It adds to a Host *'s SendEnv.

Tests, each failing without the fix: TestExecAndShellColorTerm (lima),
TestColorTerm (vm: the shell's and the login's value for allowed,
near-miss and injection-shaped values), testdata/script/colorterm.txtar
(the stub limactl's argv for the shell and an agent's login), ssh.txtar
and sshconfig's pinned lines, and e2e: a fresh VM's first shell, a
login shell on a terminal in the folder (24bit, and none for another
value) and ssh devvm-web. The structure test's dynamicScripts lists
both new built scripts.

Docs: Managing VMs, ssh access by name, How it works' Lima (A shell's
colors) and security (the ssh entries), and CHANGELOG Fixed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-20 11:27:28 -07:00
w3cjandClaude Opus 5.5 19f9900b86 fix(sshagent): a VM reaches its SSH agent only through its proxy's relay
OpenSSH's ssh-agent answers every request a forwarded connection sends,
so a VM that forwarded your agent or devvm's own (shared by every VM
that uses it) could remove all its keys (ssh-add -D), lock it with a
password of its own (ssh-add -x) or add keys without bound, denying the
agent to you and to the other VMs. Checked with a throwaway sshd and
ssh-agent: all three succeed over ssh -A.

Each VM's proxy now relays the agent its start chose on a socket of the
VM's own (paths.Dirs.AgentRelay, run/agent-<hash>.sock, mode 600), and
the VM's backend, devvm's own connections and the ssh entries for
editors name that socket. The relay passes on only
SSH_AGENTC_REQUEST_IDENTITIES, SSH_AGENTC_SIGN_REQUEST and the
[email protected] extension (so destination-constrained keys keep
their constraints), answers everything else with SSH_AGENT_FAILURE,
reads messages whole up to OpenSSH's 256 KiB, carries at most 16
connections and closes one idle for 2 minutes. A filtering relay rather
than an agent per VM: it covers your own agent too, needs no copy of a
key or a passphrase per VM, and fronts hardware and app-held keys.

- proxy: Config.Agent/AgentSocket (checked together, absolute), the
  relay in agent.go, listened before the proxy says it's ready; its
  accept loop backs off after an error that leaves the listener open
  (EMFILE), 5 ms doubling to 1 s, logging the first.
- daemon: AcceptRetry, vmssh's acceptRetry moved to the stdlib-only
  package the proxy already imports, so the relay, the port forwarder,
  the link session and a login's forward share one owner.
- netpolicy: Prepare takes a start's agent; a running VM's proxy keeps
  its start's agent from proxy.json (relayedAgent); Stop deletes the
  relay's socket.
- structure: paths.Dirs may have 62 methods (AgentRelay); the relay's
  goroutines in goroutineSites.
- sshagent: Made.Relayed, which RecordStart sets on every start of this
  devvm's whose choice forwards an agent, one without SSH_AUTH_SOCK
  included, and ReachOf(st,
  start): a relayed start gets the relay (or none while it's down), a
  start devvm didn't record (one outside devvm) gets none, or its
  proxy's relay, and only an older devvm's recorded start keeps the raw
  agent until its next start (runningConfinement, finder.inspect,
  sshconfig).
- vm: LeftoverSockets also finds a killed proxy's relay socket for
  devvm gc --orphans and devvm space.
- Tests: relay filter, wiring through Main, bounds and idle close, real
  ssh-agent/ssh-add/ssh-keygen through the relay, Prepare's relay,
  RecordStart/Relayed, sshconfig entries, vm agent tests, ssh_agent.txtar,
  an outside start in ssh_agent.txtar, and e2e checks that the VM can't
  remove, lock or add to your agent, nor the VM or an editor's
  connection remove devvm's agent's keys.
- Docs: processes (the SSH agents, listeners), ssh, attack-vectors,
  security, design, lima, overview, space, structure, proxy README,
  AGENTS.md, CHANGELOG Fixed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 22:04:31 -07:00
w3cjandClaude Opus 5.5 b6954e1e11 refactor(vmname): a VM's name is a vmname.VM, parsed where it's read
vmname.VM is the name of every machine devvm runs on a backend: a
project VM, an image's machine (devvm-img-<key>), a build VM and a
remake's aside. Fields, parameters, results and map keys that held a VM's
name as a string now hold a VM, from the backend interface down to the
CLI's --json structs, whose output is byte for byte the same.

Boundary parsers, the only places a string becomes a VM:
- vmname.Parse: a project VM's name (state's vm.json name, export file
  names, devvm _links's argument, the forwarder's -vm, project.Nth)
- vmname.ParseListed: one path element, for what a backend lists
- VM.UnmarshalText: JSON (Lima's list, proxy config and events, links'
  targets in state, link lists); empty stays no VM
- vmname.Image(key), VM.Aside(), and typed constants for Lima's build VMs
- msg.M.VM: the VM a message's function took, read back

vmname's functions on names became methods (Hash, Slug, Short, Aside,
AsideHash, ImageKey, IsProject); Lima's image prefix moved to vmname;
vmname.Join joins VM lists. Messages' vm and vm_name fields are typed
by the generator. Seven messages whose field took something else became
what= (backend_lacks, backend_unreviewed, backend_unreviewed_used,
starting, deleting, configuring, running_script) and rm_vm_failed's
name=: the text is unchanged, the names-mode scripts follow.
Review.RequireFor names an image or the tools being built.

Typed sites per package (added lines with vmname.VM, non-test): msg 347
(generated), vm 124, lima 48, backendtest 32, vmssh 31, netpolicy 22,
backend 16, gitprotect 14, proxy 11, cli 11, project 10, state 8,
ports 6, paths 3, sshagent 2, sshconfig 2, tools 2.

The structure test's owners rule now fails on a field, parameter or
result named for a VM (vm, vms, otherVM, vmName) typed string, []string
or map[string]…, and on converting anything but a literal to vmname.VM
outside the files it lists; internal/stubtest is free. depguard holds
internal/vmname to the standard library, and the proxy may import it.

ParseListed and UnmarshalText refuse a name starting with -, which would read as a flag in limactl's argv, and vmname.Image refuses a key that's empty, holds a / or NUL, or makes a project VM's name, so Lima's ImageSize and DeleteImage no longer check it themselves. The check also fails on a *string VM name and an alias of vmname.VM, and says what it doesn't see.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 19:36:28 -07:00
w3cjandClaude Opus 5.5 8d44175601 refactor: the Go module is github.com/devvmhq/devvm
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 06:16:29 -07:00
w3cjandClaude Opus 5.5 d58b24affe refactor(ui): prompts in one place: each question declares its answer
Every question is a msg.Question that declares what answers it where
devvm can't ask: AnsweredBy("--force") names a flag or command, which the
refusal names (no_input), and RefusedWith(msg.X(...)) gives a question no
flag answers its own refusal. msg.AnswerFor and its table go.

The Reporter's Ask, Confirm and Answer, and the UI's Secret, take a
Question and return a *msg.Refusal where they can't ask: with --no-input,
without a terminal, or at the end of the input, one refusal for all three
causes. Commands return it through the failure path (showFailure ->
UI.Refused: the question, then the refusal); nothing dies on an unanswered
question any more. Questions with a usual answer fall back on it instead:
network policy on, restart no, history import later, the Include line
warned, an unenforced VM stopped, the first run's size kept.

Gone: confirmed() in cli (4 callers), force_needed and no_input_terminal,
vm.Env.CanAsk and ui.CanAsk, vm's interactive, setup's terminal, the
Reporter's StdinIsTerminal/StdoutIsTerminal and the Fake's StdoutTerminal,
and every caller's terminal check (18 in vm, netpolicy, build and
sshconfig; 3 CanAsk; 1 interactive; 2 in cli). The picker's check
(CanPick) stays in the picker, which keeps its choices with --no-input
too; setup and the first run's agents and the new-VM summary still read
CanPick, because what they save or say depends on whether the picker
showed.

A Question's About context (the network policy's, a secret's howto, the
restart's changes, the size's host) is said only when it's asked.
devvm update asks before its tools change, so a refusal leaves the VM as
it is.

The CLI tests answer through a terminal (ttyin) or, explicitly, with a
test build's DEVVM_PIPED_ANSWERS=1, a line of input each.

Tests: ui's TestConfirm, TestAsk, TestAnswer, TestPromptsOnlyAtATerminal,
TestSecret, TestNoInput, TestNoTerminal, TestNoAnswer, TestPipedAnswers,
TestRefusedInterrupted, TestPickNoInput; msg's TestQuestionRefused,
TestQuestionAbout; cli's agreement test TestQuestionsDeclareAnswers (every
AnsweredBy names devvm's flags and commands, every RefusedWith a message,
no Question made otherwise) and TestCheckAnswer; vm's
TestSizeChoiceRefused; testscript prompts.txtar (each cause, a refusal of
its own, piped answers).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 11:49:57 -07:00
w3cjandClaude Opus 5.5 ac5aaeef0c refactor(vmssh): one checked ssh for a VM, vmssh.Checked
vmssh.Checked(ctx, dirs, review, backend, vm, ReadKeys|PinKeys) is the one
way to a running VM's ssh: the review lets the backend's ssh through, its
SSH target passes FromTarget, and the VM's host keys for its current start
are read (KnownHostsFor) or pinned (PinHostKeys). It returns a Reach (SSH,
the backend's other ssh options, the record's start). A failure before the
host keys is an *UnusableError, the host keys' own wrap ErrNoHostKeys.

It replaces vm's ownSSH body (ReadKeys), Forwards.start (PinKeys; Forwards
gets a Review, from NewForwards) and sshconfig.Write (PinKeys, skipping
UnusableError and ErrNoHostKeys; the start now comes from the record, not a
second Running). Tests: TestChecked (refused, stopped, off loopback, read
before a pin, pin, read, another start).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 11:30:08 -07:00
w3cjandClaude Opus 5.5 7bdaf8e99e refactor: one Reporter for every package's messages and prompts
msg.Reporter is what every package below cli prints and asks through:
Info, Say, Note, Warn, Status, Ask, Confirm, Answer, the terminal checks
and CanPick, the run log (LogNote, LogWriter, LoggedCmd, WithSteps),
Stdout, Stderr, AddCleanup and Interrupted, under the UI's signatures.
*ui.UI implements it (a compile-time check in ui), and msg.Fake is the
tests': quiet as its zero value, its On funcs and fields record and
answer.

The six UI interfaces (tools, netpolicy, lima, registry, sshagent, vm)
are gone, and the copied output and prompt func fields of tools.Env,
tools.Making, gitprotect.Protector, secrets.Store, netpolicy.Proxy,
from.Lookup, backend.Review, lima.Lima, sshagent.Agent, vm.Env,
vm.SizeChoice, vm.AgentsChoice, vm.LayersChoice, vm.NetworkChoice,
vmssh.Forwards, build.Env and sshconfig.Config: each embeds the
Reporter. Lima's and the shared tools' Warn, which says where the run
log is too, is a method of their own over it; vm's interactive check is
a function over it. The pickers (build.Env.Pick, vm.Env's PickFeatures
and PickParts, the choices' Pick) and vm.Env.CanAsk stay fields: they
carry types of their own or cli's answer. The test UIs of tools,
netpolicy, lima, registry, build and vm become msg.Fake.

Coverage baselines raised: internal/backend/lima, internal/msg,
internal/tools.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 10:57:23 -07:00
w3cjandClaude Opus 5.5 e6f64dae31 refactor(vm): one VM inventory per run
vm.Inventory (internal/vm/inventory.go) holds each project VM's state,
backend and Instance, read in one place: ReadStates for the states
alone, ReadInventory (UsedBackends or AllBackends) for the backends'
lists too, each within the host's list wait (30 s), with the backend's
Check saying why a list failed. It replaces Env.mounts, recordedVMs,
vm.List and vm.ToolsInUse, linkstate's clientStates listing, the
secret list's, Leftovers.Find's (and backendVMs), cli/space.go's two
(backendRows' list, vmFolders), images' state.Backends and sshconfig's
running list: sshconfig.Write takes the inventory's Running VMs.
state.ReadAll reads each VM folder on its own (only the inventory calls
it, a structure-test callers rule); state.Backends and Registry.Used go.

One failure policy:
- a backend that can't list fails a listing (Inventory.Err) only when
  some VM's state names it: devvm ls and the ssh config fail, and the
  ssh config stays as it was rather than lose that backend's entries;
  space and gc --orphans name it and leave its VMs alone;
- an unreadable vm.json is its own row: ls lists the VM with its name
  and status alone and warns (vm_state_unreadable); links, the secret
  list, rm VM and link targets leave it out; gc --orphans never takes it
  for an orphan; ToolsInUse and Mounts (images, gc, space, the SSH
  agent's mounted-key check) fail on it, naming the file;
- FolderOf is bounded (5 s): a folder on a hung share is there.

Mounts come from the states alone, stopped VMs and agents' folders
included, so the mounted-key check asks no backend. ui.Table shows every
cell through msg.OneLine, so ls's cells can't move the cursor or break
a row.

Docs: internals/overview's listing, troubleshooting's file devvm can't
read, ssh's mounted keys, contributing's owners table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 02:30:53 -07:00
w3cjandClaude Opus 5.5 da5bae47f9 fix: tighten VM names, validate aliases, make written folders private and choose build VMs' ssh ports under the claims lock
- vmname.IsVM takes a name's folder part only as project.Slug makes it
  ([a-z0-9-], a letter or digit at each end), so a hand-edited name never
  carries spaces, slashes, newlines or ssh patterns. TestSlug checks that
  every name project.New makes is one.
- vmname.Short and vmname.IsAlias: a VM's alias is devvm-<folder> of its
  own name or the name itself. sshconfig.Host, ChooseAlias and
  project.Named ignore any other alias, so one edited into vm.json never
  reaches the ssh config's Host line or names a VM.
- state's writeFileMode makes a missing folder with PrivateDir (exactly
  700, whatever the umask, a link refused); a folder already there keeps
  its mode.
- ports.Allocator.Build chooses a build VM's ssh port on macOS under the
  claims lock (state.Claims, which VM.Claim now shares), records it in
  run/build-ports/<name> until limactl start returns, and ports.Used
  reads those records, so no VM or forwarder takes the port before Lima
  binds it. Lima's own freePort and platform.PortFree, its only user, go;
  Lima gets a Ports field (the allocator). paths.Dirs.BuildPorts is new,
  and Dirs' method limit goes to 54.

Tests: TestIsVM, TestIsAlias, TestSlug, TestChooseAlias, TestWrite,
TestTargets, TestWriteFileMakesPrivateDir, TestBuild,
TestStartBuildSSHPort; layout.txtar lists run/build-ports on macOS.
Docs: internals (backends, overview, design), contributing, using/space.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 23:21:52 -07:00
w3cjandClaude Opus 5.5 50b0db2f7e refactor(vmssh): one host-key record per VM per start, which every ssh of devvm's checks
vmssh owns a VM's host keys: PinHostKeys reads them from the running VM through its backend (at most 64 KiB within 30 s) once for each start, into one record in the VM's folder, vms/<hash>/run/known_hosts (paths.VM.KnownHosts), whose first line names the start it was read for (backend.Run.ID). A record of another start is read again, keys read while the VM started again aren't recorded, and ErrNoHostKeys says none can be pinned. KnownHostsFor returns the record for the current start without reading, for links' sessions; ForgetHostKeys removes it before each start. ParseHostKeys is the one parser, for every key type: a line is kept only when its key decodes, names its own type and has more after it, and certificates, markers, patterns and anything else are dropped.

The ssh config's entries, the port forwarder (-known-hosts), links' sessions and a --clone VM's git all check the VM against that record. sshconfig's own parser, recordHostKeys, changeKnownHosts, HostKey and ForgetHostKeys go, with the shared known_hosts and its lock (Dirs.KnownHosts, Dirs.KnownHostsLock): a record per VM, each written whole, loses no other VM's keys. The forwarder's ports.known_hosts copy and Forwards.HostKey go, and teardown leaves the record to the VM's folder. paths.Dirs's method limit drops to 47.

Tests: TestParseHostKeys, TestPinHostKeys, TestPinHostKeysNone, TestPinHostKeysTogether (vmssh); TestForwardsStart and TestForwardsRun use the record; TestWrite reads keys again after a start, TestWriteUnreadableRecord (sshconfig); TestLinkConn refuses a target without a record and never reads one; up_test's call lists. The limactl stub shows a wire-format ed25519 key per VM. testscripts ssh (a launch keeps the record, a restart reads it again), up, existing, host_code, clone and layout updated; e2e's project and link checks read the VM's record. Docs: internals/security.md, design.md, overview.md, ports.md, lima.md, backends.md, git-protection.md, using/ssh.md and space.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 01:21:02 -07:00
w3cjandClaude Opus 5.5 6379e52c54 refactor(vmssh): a backend's ssh target carries its key, and vmssh.FromTarget checks it for links and the ssh config
backend.SSHTarget has Key, the one private key file that logs in (Lima:
its ssh config's first IdentityFile), and Options no longer carry
IdentityFile. vmssh.FromTarget is the one check of a target: a user and
an absolute key that can't break an ssh config line, on a port of the
host's loopback (vmssh.Loopback, 127.0.0.1) and nowhere else.

Links' linkSSH uses it in place of its own IdentityFile parsing and
checks. The ssh config uses it too, which adds the loopback check it
lacked: a VM whose backend names another address, a name, no user or no
key gets no entry, so an editor's ssh (and a forwarded agent) never
goes elsewhere. Entries write Hostname, User and IdentityFile from the
checked target.

Tests: TestFromTarget (vmssh); TestWriteNoAddress gains other
addresses, a name, 0.0.0.0, no user and no key (failed before on the
addresses); TestSSH (lima) checks Key is the first IdentityFile alone;
the conformance reach check needs a user and a key.

Docs: using/ssh.md says entries reach the VM on 127.0.0.1 alone;
internals/design.md says links take a VM's ssh only there, and names
internal/vmssh's path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 00:28:17 -07:00
w3cjandClaude Opus 5.5 6128f400e4 refactor(backend): Backend is four role interfaces, and Running replaces StartID, Confined and Lifeline
backend.Backend is Name, Caps and four roles, each required:
- Host: Problems, NameMax, Location, DiskDirs, Floors
- Images: BuildImage, Images, ImageSize, DeleteImage, BuildTools,
  ToolFormat, KeyFiles
- Machines: CreateVM, Start, Running, ProxyURL, Stop, Delete, Rename,
  List, Inspect, Exec, Shell, SSH, ForwardTarget
- Housekeeping: Usage, Strays, DevvmCache, DeleteCache

The optional interfaces Lima implemented (KeyFiles, Storage, Locator,
UsageReporter, StrayFinder, CacheCleaner) are gone into the roles, and
their callers call the methods directly; Forgetter stays the one
optional role, found with backend.As. Running(ctx, vm) returns a
backend.Run (ID, Confined, Lifeline) in place of StartID, Confined and
Lifeline. Space.Check, Space.Warning and LocationOf take a Host.

lima.Lima keeps its fields, Name, Caps and its shared helpers (14
methods), and embeds host, images, machines and housekeeping, each over
the Lima it's part of (withRoles); backendtest.Fake is split the same
way. The guard has every role's methods, its own for the ones it guards.

Structure test: max-methods counts an interface's declared methods too;
Lima and the fake leave largeTypes. Tests: TestRunning, TestGuardRoles,
TestAs (Forgetter), TestFakeRunningAndNone, two TestRulesFail cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 19:58:19 -07:00
w3cjandClaude Opus 5.5 c40f9bbf74 fix(sshconfig): change known_hosts under its own lock
Pinning or forgetting a VM's host keys takes known_hosts.lock (an OS file lock, paths.Dirs.KnownHostsLock), reads the file again inside it and writes it whole with state.WriteFile, so two devvms at once lose neither's pin. ForgetHostKeys takes its caller's ctx. TestHostKeyConcurrent holds two pins' reads until both have read; it fails on the unlocked code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 19:38:27 -07:00
w3cjandClaude Opus 5.5 9f6f62d28a refactor(state): vm.json, typed state in package sections, changed under the VM's lock
A VM's state is vms/<hash>/vm.json: core fields (version, id, name,
alias, image, chain, from, dir, folder, backend, backend_at, created)
and one section per package, each a json.RawMessage its owner decodes
into its own type (state.Section, state.SetSection), what was asked for
at its top level and what devvm made under "made":
net (netpolicy), git (gitprotect), ports (the new internal/ports),
agent (sshagent), tools (tools), secrets (secrets), and size, clone,
devcontainer, desktop and links (vm, internal/vm/state.go).

- state.VM.Update takes vms/<hash>/lock (platform.LockFile), reads the
  file again, applies a change and writes it once; a failed change, or
  write, writes nothing. VM.Set and its calls are gone; read-modify-write
  of lists (links, publish, secrets, tools, size, ports) happens inside
  Update. VM.Claim also holds run/claims.lock, after the VM's own;
  VM.Create writes a new VM's whole record once, its alias chosen
  (sshconfig.ChooseAlias) under the claims lock. Reads take no lock.
- created replaces "net unset" as unfinished (VM.Finished).
- internal/ports: the ports section (forward, host.ssh/proxy/desktop),
  ports.Used (was netpolicy.UsedPorts), and one Allocator for ssh, proxy
  and desktop ports under the claims lock (desktop allocated without
  one before; run/ports.lock and netpolicy's own ports key are gone).
- gitprotect: mode recorded before the backend makes the VM (NewMode;
  clone for --clone, which ls and git-protect share as gitprotect.Mode);
  made.git_id (platform.FolderID), one git_dirs list for modules and
  embedded git dirs, delegations, protected; Unlock takes the union of
  recorded and current git dirs.
- links' entries, git dirs, tools and devcontainer commands are JSON
  lists, not strings in values; the key=value parser is gone.
- vm.checkState reads every section of the folder's VM as it's found.
- registry.For drops its unused Dirs.
- Tests: TestVMRoundTrip, TestVMOtherName, TestVMID, TestVMUpdate,
  TestVMUpdateTogether (two writers on one VM and on crossed VMs),
  TestVMClaim, TestVMFailures, TestVMCorrupt, TestChooseAliasTogether,
  TestUsed, TestSSH, TestChooseTogether, TestUnlockRecorded,
  TestCheckState, TestChangesTogether, TestChangesAtOnce; testscript's
  vm_state, json_set with dotted and := keys; e2e's vm_state/vm_set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 14:47:06 -07:00
w3cjandClaude Opus 5.5 1917072228 refactor(backend): remove the Docker backend
devvm is about VMs, and Docker's containers aren't VMs: Lima is the
default backend and smolvm stays experimental. The backend architecture
(Backend, Caps, Require, the registry, backendtest.Fake) stays, so
another backend is an addition.

Removed:
- internal/backend/docker, its registry entry and Names/Experimental's
  docker half; devvm _docker-connect and _docker-ports
  (internal/cli/dockerssh.go); assets/docker/unpack.sh.
- Test-build overrides DEVVM_DOCKER_KIND, DEVVM_DOCKER_PROC_SYS,
  DEVVM_LINUX_BUILD_URL/_SHA256, the registry.linuxURL/linuxSHA256
  ldflags vars and the CLI tests' Linux-build archive (linux_release).
- Interfaces only Docker implemented, with their callers:
  backend.ProxySocket/ProxySocketOf (the proxy's -listen-unix),
  DiskUser (ls's and size's disk-over warning, size's disk_used and
  --json disk_used_gib), Reporter (doctor), LeftoverLister and Leftover
  (gc --orphans' volumes, networks, containers and images),
  DockerLayerVM and VMSpec.DockerLayer, SSHTarget.ProxyCommand and
  vmssh.SSH.Proxy, vmssh.SSH.SessionArgs, CacheEntry.Name.
- The docker layer's runtime on a backend that makes VMs for it:
  vm/dockerlayer.go, KeyDockerLayer, chooseNet's refusal (chooseNet
  returns a bool now), the refusals at start and devvm network on, ls's
  "(sysbox)" and --json docker_layer, size_disk_default_unused.
- The proxy's relay mode (relay.go, -relay, -relay-to, -listen-unix).
- paths.Dirs.Docker and paths.VM.Lifeline.
- assets/guest/tools.sh's linked-folder branch; services.sh's
  DEVVM_LOOP, DEVVM_DOCKERD and DEVVM_SSHD=inetd.
- Messages: every docker_* the backend used, docker_layer_runtime,
  net_docker_layer, net_off_docker_layer, committing_image,
  pulling_image, unpacking_tools, disk_over, size_disk_default_unused,
  gc_orphan_volume/_network/_container/_image, docker_connect_failed;
  gc_orphan_elsewhere reworded.
- Tests: docker.txtar, the docker stub's engine (its --from half
  stays), the ssh stub's login-shell branch; e2e's --backend docker,
  --engine, the docker host VM and Docker Desktop runs.
- Release: one GoReleaser pass, no Linux-build pin in the macOS builds,
  no Linux devvm in the Homebrew formula's libexec. Linux builds stay.
- Docs: backends/docker.md and internals/docker.md, design.md's Docker
  notes, the Docker column of the feature table, and every page's
  mentions of the Docker backend, Docker Desktop as one, and Sysbox.

Kept: the docker layer in Lima VMs, devcontainer docker-in-docker,
--from with images only a local Docker has, Docker Hub references.

State written by a Docker VM before this reads as an unknown backend
(backend_unknown_vm).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 10:26:07 -07:00
w3cjandClaude Opus 5.5 d8a7d4de7f refactor(state): a folder per VM, keyed by its project folder's hash
Every file devvm keeps for a project VM is in one folder, vms/<hash>/,
where <hash> is the 14-hex hash of the project folder's path that the VM's
name ends with: its state, its own rules (policy), its backend's files
(backend/: record.json, key, known_hosts, proxy, ports and the port
forwarder's ports.*), what its runs leave (run/: proxy.*, sandbox.sb,
started, lifeline.pid, secrets.*, links.*) and its logs (logs/:
network.jsonl, proxy.log, links.log). Build VMs keep the same layout in
run/builds/<name>/. The top-level run/ holds only what isn't one VM's or
must be short: the hashed control sockets, links' link-<hash>.sock/.ctl,
the QEMU wrapper and the ports lock.

A folder's VM is found by its path's hash (state.ReadHash), with the name
and backend its state records, so devvm --backend docker then devvm in
the same folder opens the one VM, and a backend's name limit applies to
new VMs only. The state records the VM's name and its ssh alias, chosen
once at creation (sshconfig.ChooseAlias) and never recomputed. Links'
targets match recorded names, aliases and folders (project.Targets).

One teardown (vmFolders.teardown) replaces Lifecycle.forget,
undoCreate's own list, Leftovers.Forget's, Proxy.Forget and space's
leftoverFiles: it stops the proxy and link session, then the pieces
outside the folder (clone remote or .git locks, other VMs' links and the
group, host keys, the backend's leftovers), removes the folder, and
writes the ssh config. Each backend's Delete and Forget remove the VM's
backend/ folder (vmssh.Forwards.Forget). A new VM made where an earlier
one's folder was left clears it first. devvm space counts an orphan's
whole folder as leftover state and the other VMs' logs as network logs.

Path builders move into paths: Dirs.VMDir, Dirs.VM and paths.VM's files
(secrets' BindingsFile/PolicyFile, netpolicy's run, EventLog, ProxyLog,
LinkList, VMPolicyFile, Lima's profileFile, startedFile, forwards.file,
vmssh.Forwards.file, links' LinksLog/linksPID, Docker's vmFile and
lifeline), ToolLockConfig, ToolLockChecked and ToolsCheckLog; the
user's cache folder for Lima's and smolvm's caches is Dirs.UserCache,
from HOME, not os.UserCacheDir. Dirs.VMState, LimaVMs, SmolvmVM and
DockerVM go. vmname.HashOf and IsHash, project.Hash.

The proxy takes the links' sockets' folder (-link-sockets, devvm's run
folder) apart from the links' list, which is in the VM's run folder.

Tests: a VM made and removed (rm, gc --orphans) leaves nothing under
vms/, and with network policy has no file named for it outside its
folder (TestTeardownLeavesNothing); a new VM over an old folder starts
clean; lookup finds a VM made on another backend with a long folder name
and makes no second one (TestLookupOtherBackend, and in docker.txtar);
the alias stays put when a second VM shares the folder name
(TestChooseAlias, ssh.txtar); every socket fits under a 35-character
home with the longest VM name (TestSocketsFit); space counts an
orphan's whole folder (TestLeftoverFolders); paths.VM's files; state by
hash and name; the proxy refuses a socket in the list's own folder.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 08:16:39 -07:00
w3cjandClaude Opus 5.5 dd3f0deb3f feat(state): config.toml and settings.json hold the defaults, and devvm's own files move to the data folder
~/.config/devvm/config.toml is the defaults you write by hand: backend,
network, ports, features, agents, [size] cpus/memory/disk and
[retention]'s six keys. devvm reads it and never writes it, strictly: an
unknown key (toml.MetaData.Undecoded, its line found by key) or a value
its check refuses (ParseCPUs, ParseGiB, ParsePorts, ask/on/off, a
backend's name, image.FeatureName, image.Agents, ParseDuration,
ParseSize, counts) fails naming the file and the line.
~/.local/share/devvm/settings.json holds what devvm setup, size -g,
ports -g, network -g and retention save (unknown fields ignored).

internal/settings owns both: Defaults (Value and List, each with its
Source: flag, config.toml, settings.json or built-in), Read, Save, which
refuses a key config.toml sets (set_in_config, with a doc link), and
the parsers and retention settings that moved from vm and state. A flag
wins over config.toml, config.toml over settings.json, settings.json
over the built-in default. Settings methods lose their files; setup
uses vm.NetworkChoice instead of its own copy; creation.plan reads one
snapshot (firstRun) after the first-run questions; the registry gets
the default backend through DefaultBackend; state's featureName copy
goes with base-features.

devvm size -g, ports -g, network -g and retention show each value's
source after a #, and in --json (source, sources); devvm doctor names
the file that sets its backend (doctor_backend_from) and adds
backend_source. devvm setup skips what config.toml answers
(setup_in_config) and refuses a flag that would change it.

ssh_config (and so the ~/.ssh/config Include line), known_hosts,
agent-keys.json and secrets/ move to the data folder. agent-keys.json is
{"keys": [{file, fingerprint, confirm, lifetime}]}, parsed once
(AddedKey); Keys formats KeyList.

Tests: settings' table tests (every key, unknown keys, bad values, an
empty file, precedence, Save's refusal and merge, settings.json's
fields), agent-keys.json, the registry's default backend, setup with
config.toml, SizeChoice with config.toml; CLI scripts for size -g,
ports -g, network -g, retention, setup and doctor's sources, each
refusal, a hand-edited config.toml with a typo, and ssh -G resolving
devvm-web through the Include line. Docs: settings.md's config.toml
section with a full example, linked from each command's page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 07:56:29 -07:00
w3cjandClaude Opus 5.5 f2a8ddd404 refactor: write every file whole through state, and make private folders with state.PrivateDir
internal/state is the one writer of whole files outside the proxy:
state.WriteFileMode joins state.WriteFile for another mode (0700 for
the QEMU wrapper and Docker's copies of devvm's Linux build), and
state.PrivateDir makes a folder the user's alone (700), refusing a file
or a symbolic link there, as vmssh's runDir did.

- Deleted: both writeOwn (backend's build proxy, Docker's egress), lima's
  writeFile (the Seatbelt profile, the QEMU wrapper, the start record),
  vmssh's writeWhole and runDir, Docker's copyFile, the Linux build
  fetch's temporary file (fetch.Open's body is read whole, its SHA-256
  checked, then written with state.WriteFileMode), and Resolve's
  .tmp-and-rename loop. The host's mise stays fetch.Download's.
- os.WriteFile to state.WriteFile: tools (Resolve's and lockVersions'
  mise.toml, the checked file, the tools build's files), sshagent (two),
  ubuntu's checksum files, docgen's pages and backendtest's fake tool
  images.
- state.PrivateDir for nine MkdirAll and Chmod pairs (eleven folders):
  the run log's two, tools' logs, secrets, netpolicy's CA, run, logs and
  socket folder, lima's run folder and the exports folder. MakePrivate
  and ~/.ssh keep following a link: where they live is the user's choice.
- The proxy's writers are one, writeAtomic: the login files' writeJSON
  and the Nix cache's size file use it, its temporary files named
  .<name>.tmp-* as state's are.
- forbidigo bans os.WriteFile outside internal/state, internal/proxy,
  internal/msg/gen, internal/stubtest and tests, with its line in
  testdata/lint/forbidigo.go.

Tests: TestWriteFileMode, TestPrivateDir (a symbolic link to a folder
refused, its folder's mode unchanged), TestWriteAtomic; mode checks on
the Seatbelt profile and Docker's Linux build copy. Coverage baselines
raised: lima, netpolicy, proxy, secrets, ui.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-02 15:50:40 -07:00
w3cjandClaude Opus 5.5 82566e9010 refactor: shell quoting, the VM-name grammar and value patterns each in one place
internal/shell, a stdlib leaf: Quote, QuoteJoin and EnvName. They
replace the 4 shell quoters (lima's shq and shqJoin, docker's shq, vm's
and devcontainer's shellQuote) and the 4 variable-name regexes (docker's
envKey, vmssh's envName, vm's envVarName, devcontainer's envName).
lima's quoting tests move there as TestQuote and FuzzQuote.

internal/vmname, a stdlib leaf below project: Prefix, HashLen, IsVM and
SlugOf. project's vmName regex, IsVM and Prefix go (callers use vmname),
lima's projectVM, docker's hostname parsing and cli's export-name regex
use it. TestImageKey (lima) pinned imageKey before the change;
TestParseExportName covers the export names.

Value patterns exported once: from.IsDigest (lima's idPattern),
image.IsKey (build's keyLike and the keyPattern copies in lima, docker
and smolvm), image.ToolVersion (tools' versionLike) and image.ToolName,
with TestIsDigest and TestValuePatterns. state's featureName stays:
internal/state may not import internal/image.

netpolicy.PolicyFiles names a user layer's policy file only for a part
image.LayerName takes, so an image-name part such as ../x never names a
file outside the user's layers; TestPolicyFiles's ../x cases failed
without the check.

The structure test's owners check gets literals: a non-test string
literal holding '\'' outside internal/shell, or [0-9a-f]{14} outside
internal/vmname, fails, naming the owner. TestRulesFail has cases that
break and keep both. shell and vmname join the leaves' layer, and
devcontainer may import shell. Coverage baselines: shell and vmname
added at 100.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-02 16:07:18 -07:00
w3cjandClaude Opus 5.5 4ea141b918 feat(link): devvm link, link add, rm, publish and unpublish, with their state and checks
Links between VMs' commands and state, without anything carrying a
connection yet.

- state: every VM gets a random ID (KeyID, "id") when CreateVM makes it.
- vm: Links (links.go) lists, adds and removes the folder's VM's links
  (KeyLinks, "links": NAME,PORT,TARGET,TARGET_ID,ADDR entries) and
  publishes and withdraws its ports (KeyPublish, "publish"). Each target
  gets one address in 127.77.0.0/16 per client, the lowest free. CheckLink
  says why a link doesn't apply (gone, replaced, unpublished, policy).
- project: Matching (which sshconfig.Alias now uses), IsPath, ForDir and
  Targets resolve a link's TARGET: a path, a VM's name or a folder name.
- cli: link.go, in the Links between VMs group; --json on devvm link and
  devvm link publish; --as checked with the other flag values.
- Messages: no_vm_link, link_failed, link_port_invalid, link_ports_invalid,
  link_unknown_target, link_ambiguous_target, link_self,
  link_not_published, link_policy_mismatch, link_name_invalid,
  link_name_host, link_name_taken, link_target_named, link_exists,
  link_added, link_trust, link_removed, link_not_found, link_port_taken,
  published, unpublished, port_not_published.
- Docs: the Links between VMs table on the Commands page, the CLI
  reference, AGENTS.md and the cli skill's tree.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-01 06:13:15 -08:00
w3cjandClaude Opus 5.5 16b4ad8771 feat(cli): --no-input, a flag or command for every question, and --force only skips a confirmation
A global --no-input (persistent on the root, with --help and -v): no
question is asked or read. The ui's prompts (Ask, Confirm, Answer,
Secret, Pick/PickOne in a terminal) show the question, then fail with
no_input naming what answers it (msg.AnswerFor, by the question's ID),
or no_input_terminal for a question only a terminal answers. ui.Flags
and SetFlags carry -v and --no-input.

Answers: --network-policy/--no-network-policy, --here, devvm size -g,
devvm setup --features/--backend, devvm network -g, devvm ssh-agent add,
devvm restart, --ssh-config (new, on devvm, host and code: the Include
line without asking; sshconfig.Config.AddInclude, vm.Env.AddInclude),
--stdin, and --force.

--force (-f) only skips a confirmation, and destructive commands need it
without a terminal (force_needed, a failure, not a usage error): rm (new
rm_confirm), gc (it went ahead without a terminal), gc --caches (now
allowed without a terminal with --force), images rm (images_rm_confirm),
secret rm (secret_rm_confirm), adopt (adopt_vm), rebuild when images
are built on the one rebuilt (build.Env.Force). rm --no-export skips the
export; rm's parent-folder, earlier-folder and --clone confirmations are
terminal-only and --force never answers them (vm.RmOptions). gc --tools
--force splits: --recent (only with --tools, gc_recent_needs_tools)
drops the hour's hold and keeps the refusal while a VM is being made
(gc_recent_making); gc_tools_recent names devvm gc --tools --recent.
gc_caches_need_terminal goes.

Tests: TestNoInput, TestAnswers, TestConfirmed, TestRmConfirms, TestAdopt
(--force), TestRebuild (force_needed, then Force); secret, rebuild,
images, gc*, clone, subfolder, existing scripts. e2e: rm/gc/images
rm/secret rm/rebuild with --force (and --no-export where rm -f skipped
the export), and the clone section's rm with its checks. Docs:
commands.md (Questions devvm asks, rm, flags), first-vm, clone, images
(cleaning up, --recent), space, coding-agents, internals overview and
images; CLI reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-01 03:51:27 -08:00
w3cjandClaude Opus 5.5 b27cd9b9b3 feat(lima): forward ports through devvm's own forwarder
Lima VMs forward their ports, every port and listed ones, through
devvm's forwarder (devvm _lima-ports), as Docker's do: loopback only,
exclusive binds, every port from 1024 up, never a port a host program
or another VM's record holds. Lima's own portForwards are ignore rules
for TCP and UDP on every address. The port choice is a record
(lima-vms/<vm>.ports), so changing it edits no Lima config and keeps
the VM's host keys. The forwarder pins the host key devvm pins
(Confinement.HostKey, sshconfig.HostKey) and ends with the hostagent
(the shared lifeline in vmssh). Lima's ports and ports-all are
emulated, reviewed: design note, threat check, e2e.

Docs: the forwarding rules for every backend, UDP not forwarded and
the socat alternative, in the docs voice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 21:43:10 -07:00
w3cjandClaude Opus 5.5 edc0c865ed fix(vm): launches ask only the backends a VM's state names
A launch lists VMs (the ssh config, the SSH agent's folder checks) only
on backends some VM's state names, so a Lima user's launch never runs
docker or smolvm, and a wedged or missing engine never slows one down.

- state.Backends: the backends the VMs' states name; Registry.Used: the
  registered ones among them, sorted. ls and images use state.Backends
  to fail only on a backend a VM's state names (vm.BackendUsed goes).
- Env.mounts and sshconfig ask Registry.Used; sshconfig.Config.Backends
  is a function read at each write, and Write fails on unreadable state.
- up.txtar: a new and an existing Lima VM's launches run neither docker
  nor smolvm; registry_test covers Used.
- tests/e2e.sh: the from section's launches make no docker call but
  image inspect.
- docs: backends.md says which backends a launch asks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 01:49:13 -06:00
w3cjandClaude Opus 5.5 db07c9a43d fix(ssh-agent): the ssh config's agent follows the VM's running start
A VM's ssh config entry, devvm's own SSH_AUTH_SOCK and its key reloads
use the agent choice the VM's current start was made with; a stopped
VM, or one started outside devvm, follows the stored choice. Turning
forwarding on or off for a running VM reaches ssh by name, editors and
devvm's shell at its next start, as agent_next_start says.

- Backend.StartID: Lima's hostagent pid file, smolvm's lifeline, the
  container ID and StartedAt on Docker; the fake counts starts
- state: ssh_agent_started=<mode>_<hash of the start>, written after
  each start; sshagent.Running reads it
- tests: TestRunningAgent, TestWriteAgentStarted, ssh_agent.txtar,
  docker.txtar, smolvm.txtar; e2e on Lima, smolvm and Docker

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 23:11:51 -06:00
w3cjandClaude Opus 5.5 6f597d7e1f feat(docker): ssh, ports and agent forwarding over docker exec
Docker VMs get ssh for editors, listed ports, every port, agent
forwarding and agent toggling, all over one transport: devvm's ssh
config reaches a VM through `devvm _docker-connect`, which runs
`sshd -i` in the labelled container by ID with docker exec. The
container publishes nothing and runs no listening sshd.

- internal/backend/vmssh: VM keys, host-key parsing, the port
  forwarder and its processes, shared by smolvm and docker
- `devvm _docker-ports`: every port, or the listed ones; ports a host
  program has are skipped (ports_taken)
- the agent goes only to ssh sessions (ForwardAgent, IdentityAgent);
  no socket is mounted
- --clone on Docker, its clone in a per-VM volume
- platform.ListenExclusive keeps SO_REUSEADDR on Linux; UsedPorts
  leaves out the VM's own listed ports
- messages: vm_no_ssh, vm_no_sshd, ports_no_ssh, ports_forward_failed,
  forwarder_failed, docker_ssh_path, docker_connect_failed
- reviewed: design notes and threat check in design.md; e2e checks for
  a hostile sshd config, host ports kept on every address family, and
  ports not forwarded off loopback or listed by another VM

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 10:33:41 -06:00
w3cjandClaude Opus 5.5 4bbd35a24b refactor(ui): make the UI an instance only cli holds
internal/ui has no package state: ui.UI holds the streams, terminal
flags, run log, status line, cleanup stack and interrupt flag, and its
functions are methods. ui.Main makes the run's UI on devvm's own
streams, owns signals, recovers Die and runs the cleanups; ui.New makes
one on other streams. cmd/devvm passes it to cli.Execute, and every cli
command gets it through its constructor.

Only cmd/devvm and internal/cli import internal/ui (a depguard rule).
Each other package defines the small UI interface it needs, which its
constructor takes, filling fields tests set:
- gitprotect.New, secrets.NewStore, from.NewLookup: a warn func
- ubuntu.New: LoggedCmd, Note
- netpolicy.NewProxy: Note, Warn, Ask, Confirm, StdinIsTerminal; its
  log lines drop control characters themselves (oneLine)
- sshagent.New: Info, Note, Warn, LogWriter
- tools.New: Info, Warn, LogNote, Status, LoggedCmd, AddCleanup
- lima.New, smolvm.New: Info, Warn, LoggedCmd (their Runner's Run),
  WithSteps, AddCleanup, Interrupted; lima LogNote and ubuntu's too
- backends.Registry: lima's and smolvm's
- vm.NewEnv: all of the above, Say, Stdout, Stderr; Env has Stdout,
  LogNote, LogWriter, LoggedCmd, AddCleanup, Interrupted fields
- build.Builder: Terminal and LogNote fields
- sshconfig.New: its caller sets what it prints and asks

ui's tests build their own UI over buffers and run in parallel; other
packages' tests use small fakes; cli's unit tests a UI over buffers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 16:23:51 -06:00
w3cjandClaude Opus 5.5 7fcac40758 refactor: test seams on structs, not package vars
Tests set fields; no test outside internal/proxy and internal/ui assigns
a package var.

- backend.Review: Unreviewed and Warn, with Require and Allowed as its
  methods; Registry embeds it, set by backends.Registry (a test build
  reads DEVVM_UNREVIEWED); build.Builder.Review, sshconfig.Config.Review,
  and Tools.Build takes the review with the backend
- netpolicy.Log: Path and Tick (NewLog), with Write and WriteBlocked;
  Proxy.Terminal for Choose and SelfCheck
- vm.Env.Terminal, sshconfig.Config.Terminal
- cli: setup's terminal check and backend picker are fields of setup;
  versionOf takes the release's version
- from.Registry.RetryDelay, ubuntu.Finder.RetryDelay, lima.Lima.OCIWait
- msg's tests use real messages, not entries added to docs and specs

The tests these free run in parallel. AGENTS.md: test seams are fields;
internal/proxy's globals and internal/ui's process-wide state are the
exceptions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 15:28:37 -06:00
w3cjandClaude Opus 5.5 86a1466cec refactor: print and prompt only from cli
Packages other than cli and ui take what they print and ask as fields,
set to ui's by their constructors or by cli:

- vm.Env: Info, Warn, Note, Say, Ask, Confirm, PickFeatures (cli sets
  PickFeatures); AgentMounts, UpdateAgentDirs, warnIgnored, applyAgent,
  applySize, applyPorts, removeRemote and saveFetched are Env methods
- build.Builder: Info, Warn, Say, Confirm, Pick (build.Feature); cli's
  newBuilder sets them, its pickFeatures asks through ui.Pick
- netpolicy.Proxy: Note, Warn, Ask, Confirm; Choose, SelfCheck and
  Unproxied are Proxy methods
- sshconfig.Config: Info, Warn, Say, Confirm
- secrets.Store: Warn; LoginKept takes the warn function

Tests set the fields and check messages through them. AGENTS.md: only
cli calls ui's messages and prompts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 15:12:36 -06:00
w3cjandClaude Opus 5.5 83726f6a56 feat(smolvm): ssh for editors
ssh for editors is emulated on smolvm, and reviewed: devvm ssh, devvm code,
--clone and the ssh config's entries work as on Lima.

- sshd: sshd.sh installs openssh-server in base after its scripts (from the
  snapshot they pin; before them, the live archive's systemd libraries broke
  Docker's install) and deletes its host keys; prepare.sh sets the user's
  password to * (sshd without PAM refuses a locked account's keys). Both are in
  base's key.
- Start: Confinement.SSH (set by vm.start when Require lets ssh through)
  forwards guest port 22 from a host loopback port (Confinement.SSHPort, else
  the recorded one while free, else a new one; never one of the VM's own
  forwards: smolvm_ssh_port_forwarded), then services.sh makes new ed25519
  host keys at every start, writes the VM's only authorized key and devvm's
  own sshd config (VM's user only, publickey only, local forwarding only, no
  remote forwarding, tunnels or X11; SetEnv of /etc/environment and the
  proxy's variables, by name), and starts sshd. The record's ssh_up is cleared
  before each start and set once sshd runs; SSH answers only then.
- An image without sshd (probed before services.sh) starts without ssh,
  warned (smolvm_no_sshd).
- Keys: one per VM, smolvm/vms/<vm>.key (mode 600, OpenSSH format made in Go,
  its public half read back from it), deleted with the VM. SSH returns
  127.0.0.1, the port, the user, IdentityFile, IdentitiesOnly yes,
  PreferredAuthentications publickey.
- Ports: smolvm forwards at most 64 per machine, so a VM's own are at most
  63; port 22 in --ports is refused (smolvm_port_ssh).
- Shared ssh entries (Lima too): ForwardX11 no, ForwardX11Trusted no, Tunnel
  no, PermitRemoteOpen none, AddKeysToAgent no, ProxyJump none, ProxyCommand
  none, UpdateHostKeys no, HashKnownHosts no; no IgnoreUnknown (its first
  value would replace a user's Host * one), so devvm needs OpenSSH 8.7 or
  newer. sshconfig.Write skips a backend whose ssh isn't usable
  (backend.Allowed); vm.reach checks the backend's SSH.
- netpolicy: freePort avoids every VM's forwarded ports, and a stopped VM's
  ssh_port is picked again when it's one of its own.
- Lima: layers/base.sh writes /etc/ssh/sshd_config.d/00-devvm.conf (local
  forwarding only, no remote forwarding, tunnels or X11), which changes base's
  image key on Lima and smolvm.
- Messages: smolvm_port_ssh, smolvm_no_ssh, smolvm_no_sshd,
  smolvm_ssh_port_forwarded.
- Tests: unit (keys and their parsing, Start with and without ssh, port reuse
  and collisions, ssh_up, no sshd, Allowed, entries under a user's Host * with
  an IgnoreUnknown through the real ssh -G, netpolicy forwards); testscript
  smolvm.txtar (forward, services args, entry, pinned keys, devvm ssh, no
  sshd, port 22) and ssh.txtar (entry options); e2e smolvm: entry and
  loopback-only forward, listening ports, net backend pinned (virtio-net with
  a forward, TSI without), pinned host keys of each VM's own and new ones per
  start, a changed key refused, environment, agent off with ssh -A as the
  control, password/keyboard-interactive/other key/root/other user refused,
  remote forwarding refused, sshd -T, a hostile sshd that gets no display and
  no key through a Host * asking (command-line controls, and ssh -R shown not
  covered), devvm ssh and code, another VM's key refused, a squatted port, no
  sshd, stop and rm, --clone seed/fetch/push/rm, and under network policy ssh
  on ssh_port with the proxy's variables, no way out through local or remote
  forwards (with controls), DNS no-leak with the forward and the nettop DNS
  control on a machine without one; e2e Lima: its sshd's forwarding refused,
  the entry's options under a hostile Host *.
- Docs: smolvm.md (ssh for editors), backends.md, security.md (ssh into VMs,
  remote forwards you ask for), ssh.md, install.md (OpenSSH 8.7), design.md
  (the design note: the guarantee, what keeps a session from carrying the VM
  out, DNS detection by net backend, not covered: remote forwards you ask
  for), limits.md, testing.md, contributing.md; AGENTS.md gotchas.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 13:43:00 -06:00
w3cjandClaude Opus 5.5 06780fee5d feat(ssh): devvm ssh and devvm code, VS Code's Machine settings kept
devvm ssh gets this folder's VM ready for ssh and editors, as a launch
does without its shell, then names the host they reach it by; devvm code
does the same, then opens the folder in VS Code over Remote-SSH.

- vm: launch (from open: .git and set-id checks, a stopped VM's size,
  ports and agent forwarding, the user's agent checked, run with its
  self-check) and setUpVM (from setUp: sync, ssh config, a --clone VM's
  clone) shared by launches, SSH and Code; reach requires the backend's
  ssh, then offers the Include line (EnsureInclude). Code runs code
  --remote ssh-remote+HOST DIR in devvm's place with the environment
  devvm started with (Env.Environ), so the editor keeps the user's
  SSH_AUTH_SOCK.
- sshconfig: Host (the alias among every backend's project VMs), with
  the listing shared with Write.
- cli: ssh and code commands; CLI reference regenerated.
- Messages: ssh_host_info, no_code_command (linked to ssh.md),
  ssh_failed, code_failed.
- Tests: ssh_code.txtar (no VM, usage, a stopped VM started and set up
  without a shell, the Include line shown not added, a pending size
  waiting, code's arguments and agent, two folders named alike, no code
  on PATH, a direct route stopping the VM); guest.txtar's VS Code
  Machine settings case; a stub code. e2e: devvm ssh on a stopped VM and
  ssh reaching it, the Machine settings set and set again, devvm code
  with a stub code; network: devvm ssh's self-check, passing and
  stopping a VM started outside devvm.
- Docs: ssh.md (devvm ssh and devvm code, VS Code), commands.md,
  security.md, clone.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 22:33:29 -06:00
w3cjandClaude Opus 5.5 fd479df9d8 feat(ssh-agent): devvm ssh-agent and --ssh-agent, with devvm's own agent
SSH agent forwarding per VM: off by default, on (your agent, --ssh-agent
for a new VM) or devvm (devvm's own agent, holding only keys added to it).
devvm ssh-agent [on|devvm|off] shows or changes it from the VM's next
start; devvm ssh-agent add KEY_FILE [--confirm] [--lifetime D] loads a key
into devvm's agent and records it with its pinned fingerprint
(agent-keys); devvm ssh-agent keys lists them. Keys are loaded again on
launch (after a reboot or their lifetime), only while the file holds the
pinned key and isn't in a folder a VM mounts.

- internal/sshagent: Mode/Key, Agent (Ensure, Add, Keys), its messages.
- vm: --ssh-agent on create, applyAgent and checkAgent on relaunch,
  ssh_agent_flag_ignored, devvm's agent socket at start, SSH_AUTH_SOCK
  per mode for devvm's own connections, SetSSHAgent/SSHAgent.
- sshconfig: ForwardAgent from the VM's state; devvm mode forwards and
  names devvm's socket (IdentityAgent).
- ssh_remote_hint names devvm ssh-agent on; skipped with --ssh-agent.
- Tests: sshagent table tests (the five bats cases) plus one with real
  OpenSSH tools and a throwaway agent; vm tests; ssh_agent.txtar with
  ssh-agent/ssh-add/ssh-keygen stubs; e2e project section "SSH agents".
  The test task and e2e unset SSH_AUTH_SOCK.
- Docs: ssh.md agent forwarding and devvm's own agent, commands,
  security, contributing; CLI reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 19:41:09 -06:00
w3cjandClaude Opus 5.5 4bdb3ea843 feat(ssh): ssh config and pinned host keys
Each running project VM can be reached as devvm-<folder> (or by its full
name when two folders share a name) through ~/.config/devvm/ssh_config,
which up rewrites after the VM's setup. Every entry checks the VM's own
host keys, kept in ~/.config/devvm/known_hosts and read from the VM
through its backend, and sets StrictHostKeyChecking yes, ForwardAgent no
(unless the VM forwards), and its own connection. Only Lima's login
options are copied. Host keys are dropped before each start, and when an
interrupted new VM is deleted, so they're read again.

Ported: write_ssh_config (sshconfig.Write), record_host_keys,
forget_host_keys (ForgetHostKeys, in vm start and the interrupt cleanup),
ensure_ssh_include (EnsureInclude: asks with [Y/n] on a terminal, else
says to add the line; no caller yet: --clone and devvm ssh/code),
ssh_alias (Alias), is_project_vm (project.IsVM), check_ssh_agent (vm
checkAgent, run when a new VM forwards the agent). Backend.SSH's
SSHTarget gains Options (Lima: identityfile, identitiesonly,
preferredauthentications, batchmode, compression, gssapiauthentication,
ciphers). Registry.All, state.WriteFile.

Messages: ssh_include_needed, ssh_include_yourself, add_it_now,
ssh_include_added, no_ssh_agent, ssh_agent_empty, load_key, key_loaded,
key_loaded_keychain, load_key_with. Doc links: ssh_remote_hint,
ssh_include_yourself.

Converted bats cases: cli.bats "ssh config: only running VMs, each with
its own host key checked; Lima's unchecked settings left out" (ssh.txtar,
lima TestSSH, sshconfig TestWrite; the rm half waits for rm),
delete.bats "ls and the ssh config include a project VM named like an
image" (ssh config half: ssh.txtar, TestWrite), project.bats "ssh_alias:
short name unless two folders share it" (TestAlias, ssh.txtar). New:
TestWriteUnchecked, TestParseHostKeys, TestEnsureInclude, TestCheckAgent,
TestIsVM. Stub limactl: Lima-like ssh.config at start, host keys from
shell, sshLocalPort/sshConfigFile in list.

e2e: project checks the hostname, the entry, pinned host keys, ssh
devvm-web through an ~/.ssh/config of the run's own (Include plus Host *
ForwardAgent yes), no agent forwarded (a throwaway agent), a changed host
key refused; network checks ssh devvm-net. Nothing touches the real
~/.ssh.

Docs: ssh.md (from the ssh page), linked from the index, commands,
security, images and contributing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 11:39:20 -06:00