Commit Graph
8 Commits
Author SHA1 Message Date
w3cjandClaude Opus 5.5 548113d726 build(lint): enforce contexts, nolint reasons, reassign and function size
.golangci.yml:
- forbidigo bans context.Background and context.TODO outside internal/ui
  and cmd/devvm.
- nolintlint requires each //nolint to name its linters and say why, and
  reports unused ones.
- reassign (patterns .*) forbids setting another package's variables,
  tests included.
- revive keeps its default rules and adds function-length (100
  statements, 160 lines) and cognitive-complexity (75).

Fixes:
- Backend.Lifeline takes a ctx: smolvm's machine data-dir lookup runs
  with the caller's.
- The proxy's TLS handshake with a VM uses the request's context, limited
  to 30 seconds.
- OAuth token refreshes run within refreshTimeout (30 seconds).
- Tests use t.Context().
- Launch.create is split into plan, newVM.record and undoCreate.
- lima's TestStartConfined is split into helpers.
- smolvm's Terminal comes from its UI's StdinIsTerminal.
- Unused //nolint directives are removed.
- Fresh contexts that remain (an in-memory TLS parse, lookups shared by
  every request, a test cleanup) each carry a nolint saying why.

Docs: contributing.md lists which lint rule enforces which convention;
AGENTS.md names the linters behind its Go conventions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 18:43:14 -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 d53bfdb5d1 feat(smolvm): network policy through devvm's proxy
egress-proxy is emulated on smolvm, and reviewed: a VM with network policy reaches nothing but its proxy.

- smolvm Start (NetProxy): allow list of the gateway alone (--reset-allow-list --allow-cidr 100.96.0.1/32), DNS closed (--allow-host-pattern devvm.invalid), and the start through devvm's decider (--mediated-egress --egress-interceptor, token in SMOLVM_INTERCEPTOR_TOKEN, never in arguments); a start without policy removes them (--net --reset-allow-list --no-egress-interceptor). The proxy's environment goes in by a quiet update, as smolvm prints the values it sets. Confined compares agent.pid with the confined start's and re-checks the allow lists on every call.
- The proxy is smolvm's mediated-egress decider (protocol v2, internal/proxy/decider.go, stdlib only): -decider, -decider-to, -decider-token-file; it takes over only connections to its own address in the VM, served with password and policy, and refuses and logs the rest; the token is checked before anything past it is read, first bytes capped at 8 KiB; FuzzPrelude.
- Interface: Confinement.Decider/DeciderToken, backend.Decider (UsesDecider); netpolicy.Proxy.Prepare takes the backend, allocates decider_port and a decider_token new at each start.
- A running network-policy VM whose proxy can't start again (port taken, start failed) is stopped, on Lima and smolvm (net_proxy_down_stopped; proxy_port_taken reworded); the stop isn't cancelled by an interrupt.
- DEVVM_UNREVIEWED=backend:feature lets unreviewed emulations through, warned (backend_unreviewed_used), only in test builds (-X internal/backend/backends.unreviewed=allowed: tests/e2e.sh and the CLI tests).
- Tests: decider, prelude and token unit tests; Prepare with a decider; Unproxied; smolvm Start/Confined on the stub (allow lists, decider requirement, env echo); testscript smolvm.txtar (policy VM, no password in run logs, proxy down stops it), network.txtar (Lima: proxy down stops it), doctor.txtar; e2e smolvm network section: proxy and decider, allow list, allowed/blocked hosts, direct connections as root (controls off policy), DNS refused per smolvm's decision log with devvm.invalid as control, UDP and ICMP (UDP allow control), token nowhere, log, policy, a widened allow list unenforced, fail closed with the proxy gone or a fake decider (garbage, silent, allow-direct; take-over as control), no start without a decider, someone else's decider stopped, network off/on.
- Docs: design note (how it works, what it relies on, what could break it, not covered: UDP allows the host's user adds, the devvm.invalid DNS channel), smolvm.md, backends.md, security.md, network.md, testing.md (DEVVM_UNREVIEWED, a canary DNS zone check), contributing, limits; AGENTS.md gotchas and a deliberate change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 10:47:43 -06:00
w3cjandClaude Opus 5.5 31d1f3c78e feat(smolvm): an experimental smolvm backend, its native features
A second backend, registered beside Lima: each VM is a smolvm machine
(a microVM running its image as a container, no init system), each
image a pack in devvm's data folder.

- internal/backend/smolvm: images built as packs (pack create --from-vm)
  from Ubuntu's container image by its registry digest (or --from's,
  registry images only), base prepared first (prepare.sh: sudo, CA
  certificates, bash, the host's user and uid); systemctl/rc-update
  stand-ins while a build's scripts run (shims.sh); project VMs made
  from a pack with network, CPUs, memory and disk set; after each start
  the loop devices, the tools' mounts and dockerd (services.sh); Exec as
  the VM's user with a login's environment; ports, agent folders, size;
  a record per VM of what smolvm doesn't show. On macOS every machine
  carries the label devvm.data=<data folder> and nothing without it is
  touched (smolvm_machine_foreign); on Linux --state-dir too.
  SMOLVM_USAGE=0, SMOLVM_MACHINE_NAME never passed on. Images used by a
  VM aren't deleted (their pack is read when a disk grows).
- Caps: native for everything but egress-proxy, ssh, ports-all and
  agent-toggle (none until their emulations are reviewed), refused in
  one line naming the VM.
- Interface: two features, ports-all (every port; new VMs' default) and
  agent-toggle (forwarding changed after create), each Lima-native;
  Backend.ToolFormat and ToolsSpec.Format; backend.KeyFiles, the
  backend's own scripts in base's key; --clone requires ssh. Lima's
  image and tool keys are unchanged: the format is hashed only when it
  isn't build.sh's own, and backend files only when there are any.
- Tool images: smolvm's tools build runs tools/build.sh unchanged, then
  remakes each image uncompressed (plain.sh); its format is named by
  plain.sh's hash. tools.Target (libc and format) replaces the libc
  argument; devvm images counts an image current for any backend.
- The proxy reads only the lifeline's first line (smolvm's has the start
  time on a second). guest/sync.sh tells a running systemd by
  /run/systemd/system (Docker's packages install systemctl).
- Messages: smolvm_missing(_fix), smolvm_broken(_fix), smolvm_old(_fix),
  smolvm_host_unsupported, smolvm_machine_foreign, smolvm_update_failed,
  smolvm_script_failed, smolvm_from_registry_only, smolvm_mount_colon,
  smolvm_too_many_ports, smolvm_no_agent, creating_from_image,
  packing_image, pack_failed; doc links to the smolvm page.
- Tests: internal/backend/smolvm (caps, ports, create, only ours, start,
  base build, failed build, set calls, Linux state dir, problems) on
  testdata/stubs/smolvm; testscript smolvm.txtar; TestE2EExecQuoting for
  smolvm; tests/e2e.sh --backend smolvm (the smolvm section: 34 checks);
  existing scripts expect the second backend.
- Docs: new smolvm.md; backends.md's column and the two new rows;
  design.md's smolvm section as built; limits, contributing; AGENTS.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 01:31:24 -06:00
w3cjandClaude Opus 5.5 a8a20a085e feat(policy): devvm policy, the allowlist of a folder's VM
devvm policy shows the policy files of this folder's VM that have rules,
in order, comments left out. devvm policy allow|deny|rm RULE... edit the
VM's own file, or with -g/--global the user's file for every VM; the
VM's proxy re-reads a changed file, so changes apply at once.

- proxy.ValidRule: the rules devvm policy takes (host, *.host, **, an
  address or CIDR, optional port and !); AllowRule's suggestions are
  valid (FuzzRequest checks it), and FuzzParseRule checks valid rules
  parse.
- netpolicy: Rule, AddRule, RemoveRule, WriteRules; files rewritten
  whole through a link; duplicates and rm match in any case, comments
  aside.
- vm: Env.Policy and Env.PolicyChange; net_off_policy for a VM without
  network policy.
- state.VMNames skips <vm>.policy files.
- Messages: net_off_policy, no_vm_policy, not_a_rule, rule_added,
  rule_added_global, rule_present, rule_removed, rule_removed_global,
  rule_missing, policy_failed.
- testdata/script/policy.txtar: allow/deny/rm, -g, IPv6 rules, refused
  rules, the rules shown per file, a VM without network policy, and a
  new VM not inheriting rules of one deleted outside devvm.
- e2e network: the allow command devvm log --blocked suggests applies
  at once on the running proxy; rm blocks again.
- Docs: network.md (Changing rules), commands.md, CLI reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 16:52:37 -06:00
w3cjandClaude Opus 5.5 60f23a6f4e feat(log): devvm log, the network log of a folder's VM
devvm log [-f] [-n N] [--blocked] shows what this folder's VM's proxy
allowed and blocked, the last 50 events unless -n, following new ones
with -f, or the blocks grouped by host and port with the devvm policy
allow command that allows each (--blocked). Control characters from the
VM are dropped.

- internal/netpolicy/log.go: WriteLog (tail and follow, a partial last
  line and an emptied log handled), FormatEvent, WriteBlocked.
- internal/proxy: event is exported as Event; AllowRule.
- internal/ui: OneLine, for VM-made values on one line of data.
- internal/vm: Env.Log; internal/cli/log.go.
- Messages: net_off_log, log_empty, log_failed.
- Tests: testdata/script/log.txtar (the three network.bats log cases),
  netpolicy and proxy table tests; e2e network checks devvm log and
  --blocked.
- Docs: network.md (Logs), commands.md (Network policy), CLI reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 16:37:46 -06:00
w3cjandClaude Opus 5.5 49d7205360 feat(sync): host settings, agent config and mounts for VMs
A new VM's setup now sends the whole of guest/sync.sh and its host
side, staged in memory: the hostname, timezone, UTF-8 locale and git
identity; the agents' config files (never their history), with their
folders mounted read-only at their host paths (one with a comma is left
out, with a warning); and the VM's tokens, as they are without network
policy (naming MCP servers whose secrets go too) or as its own
placeholders with it. With network policy it also sends devvm's CA, the
proxy's address (Backend.ProxyURL), the logins' copies with placeholders
and the agents' settings files with secret-looking values redacted (one
that can't be read that way isn't sent). UpdateAgentDirs keeps an
existing VM's agent mounts current through Backend.SetAgentDirs; its
caller comes with up for an existing VM. New docs page: coding agents.

Ported: sync_vm, agent_dirs, agent_files, agent_mounts,
update_agent_mounts, host_tz, claude_mcp_warn, the settings redaction;
guest/sync.sh copied whole (one comment edited).

Bats cases converted:
- project.bats: agent_mounts (one per line, names with spaces); the
  four update_agent_mounts cases (Go table tests, plus a running VM
  restarted once the user agrees)
- build.bats: sync_vm staging removed on failure, settings redacted
  with network policy (testscript sync.txtar)
- guest.bats: the prompt, blocked since the last prompt, MCP servers'
  merge (testscript guest.txtar)
- network.bats: claude_mcp_warn (sync.txtar, secrets Go test)
Deferred: guest.bats VS Code settings (ssh/code).

e2e: project gains agent folders and the VM's setup (mount read-only,
settings copied, history never, git identity, timezone, hostname, the
token without network policy); network becomes claude+codex and checks
the CA installed, the VM's own placeholder, the logins' copies and the
host's login files unchanged, with curl verifying TLS (no -k). Agent
folders on relaunch and restart wait for those commands.

Messages: agent_dir_comma, agent_dirs_added, agent_dirs_removed,
update_mounts, mounts_next_start, mounts_updated, no_claude_token,
claude_token_invalid, no_github_token, login_copy_failed,
config_redacted, config_not_copied, claude_mcp_secrets_copied;
sync_failed reworded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 11:20:03 -06:00
w3cjandClaude Opus 5.5 f4508dfb61 feat(proxy): the network policy proxy as devvm _proxy
The network policy proxy moves into the binary as internal/proxy
(standard library only), run by the hidden devvm _proxy with its own
flags. Main returns errors instead of exiting, writes only to the
streams devvm hands it (the event log and data on stdout, its log
lines on stderr), and returns when the VM's hostagent is gone. The
connect mode is gone: devvm _qemu connect does that. Logins copied
as they are are warned about through ui.

Its tests come along, with a short run, fuzz targets for policy rules,
request targets and ClientHellos, a testscript, and the network page
of the docs for the proxy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 10:12:26 -06:00