13 Commits
Author SHA1 Message Date
w3cjandClaude Opus 5.5 b625469ac6 fix(vm): devvm rm asks before opencode's worktrees' uncommitted changes go
An export leaves out opencode's worktree folder, as a git repository's config can name a command that git runs, so the uncommitted changes in the worktrees opencode makes there (~/.local/share/opencode/worktree/<project>/<name>, opencode v2.4.1's worktree/strategies.ts) went with the VM's disk on devvm rm, and on a remake with --clean-home, with nothing to say so.

The registry gets Worktrees (opencode's worktree/*/*, below its HistoryOwn, TestDefsComplete holding each to a plain pattern there). rm's unsaved-work check, cloneCheck, becomes workCheck: the clone (cloneLost, as before) and the agents' worktrees (agentTrees), one question for both. agentTreesState reads them in the running VM in one command, in its home folder, each * of a pattern sent as *, .[!.]* and ..?* (treeGlobs), so a name that starts with a dot is found: each folder with a .git, its git status and a detached HEAD's commit nothing else has; past 100 it says more. devvm reads at most 8 MiB of the answer, cancelling the command past it, and waits at most treesWait (2 minutes). parseAgentTrees takes the answer as untrusted: whole records of a glob asked for, each path clean, matched by its pattern and once, at most 100, each with one status. Dirty, detached, unreadable (wfail) and more are shown and asked about (delete_anyway or remake_anyway), which --force never answers; refused without a terminal (no_terminal_delete_trees, naming --no-worktree-check, or the clone's no_terminal_delete when it has work too). --no-worktree-check skips the check and warns (trees_check_skipped). A failed, late or hostile answer keeps the VM (trees_check_failed), and so does a VM that doesn't start for it (trees_check_not_started).

Rm and rmGone run it, and rmGone refuses a stopped VM with opencode, which starting would make its folder again (rm_gone_stopped_trees, naming --no-export --no-worktree-check); stillGone takes the refusal to give. remaking.checkWork runs it before a remake with --clean-home (remakeTo, Update, SetClone, whose clone check it joins), its messages naming the command as typed (remakeInVM.typed), with --clean-home, which --no-worktree-check needs (needs), so devvm clone off --clean-home's clone check messages name it too. A remake's flag has its own help. The stub guest runs the read in vmhome-<vm>.

Tests that fail without the check: TestRmAgentTrees, TestRmVMAgentTrees, TestRemakeAgentTrees, TestUpdateAgentTrees, TestSetCloneAgentTrees and the rm_agent_trees script; TestAgentTreesBounded (an endless answer cancelled, a silent VM given up on, in a synctest bubble); TestAgentTreesState runs the script under sh on real worktrees, a dot-named one included; TestParseAgentTrees holds the answer's checks, TestCloneGit the stub's. TestSetCloneOff names the command with --clean-home. e2e's network section makes a worktree in opencode's folder in the real VM, and devvm rm refuses, then --no-worktree-check deletes it.

Docs: coding agents' opencode's worktrees, How it works' opencode's worktrees, deleting a VM, a VM whose folder is gone, images, clone, the overview's remake, Commands, extending and rm's help; the changelog's What to do step 4 names --no-worktree-check for scripts and devvm rm VM of a stopped VM, and opencode's block gets the check; the release page has its section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-25 00:03:05 -07:00
w3cjandClaude Opus 5.5 3e81767482 refactor(cli): each command carries its own docs link, group and samples
A command's metadata moves from hand-kept tables into the command itself:
an about (docs page, help group, why no --json) set as its Cobra
Annotations. msg.commandDocs, commandGroups and withoutJSON are gone;
TestDocLinks reads the links from the generated CLI reference, and help
output and the reference are byte-identical. AGENTS.md's cli and vm rows
point at new doc.go package comments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-08 10:05:13 -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 2a99183ea4 feat(vm): devvm update reads a changed devcontainer.json again
devvm update now makes the folder's VM again from its devcontainer.json
as it is now when the file changed, is gone or appeared since the VM was
made, as well as when its image is outdated. devcontainer_changed and
devcontainer_new name devvm update instead of devvm rm, then devvm. A
file's forwardPorts now join the VM's ports as devvm ports add adds them,
for a new VM and when devvm update reads the file again.

- vm.json's devcontainer section records what of the VM is the file's:
  image (the file's image, when the base starts from it), from_flag
  (--from won), parts (what its features mapped to), gave (those the VM
  got from the file alone, not from --tools/--layers, setup's layers,
  the folder's other files, nor unchecked), ports (its forwardPorts) and
  ports_gave (those it added to the VM's ports).
- devcontainer.Reread (pure) drops what the file gave that it no longer
  lists and adds what it lists anew that the VM lacks; the user's stay,
  and what the user took out stays out. It applies to parts
  (rereadParts) and to ports (filePorts, through AddPorts and
  RemovePorts, as devvm ports add and rm). devcontainers.reread
  re-pins a new image (or falls back to $DEVVM_FROM's), keeps --from's,
  and replaces variables and commands.
- The remake section carries reread (the new from, shared tools, ports
  and devcontainer section; tools built for the new base after the
  image) and was (what the VM had, kept when the new machine is made),
  which the undo gives back, for every remake.
- Messages: devcontainer_changed/new reworded, devcontainer_reread and
  devcontainer_gone added, devcontainer_ports_not_forwarded removed; the
  docs link points at the new "Updating a VM from the file" section.
- Tests: TestReread, TestRereadParts, TestFilePorts, TestFileParts,
  TestUpdateDevcontainer (undo and finish), TestUpDevcontainer and
  TestPlanDevcontainerFrom (the file's ports added), devcontainer.txtar
  (a new VM's ports, update after a change with the user's port added
  and the file's removed, --from winning, the file removed, a file that
  appeared), e2e's devcontainer section (the file's port reaches this
  machine; devvm update, the home kept, the new port in place of the
  old one).
- Docs: using/devcontainer (its ports, the security note), images,
  toolchains, commands, the internals overview's remake section and
  state table, the design note, the security model, attack vectors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 10:56:32 -07:00
w3cjandClaude Opus 5.5 ca8a91305b fix(ui): one failure path, and an interrupt's cleanups wait for the command
Commands fail by returning: RunE returns the error, as failed(err, what)
when it may not be a message (replacing fail and the direct Die calls in
cli), and a.env returns its failure. checkLayout returns its error from the
root's PersistentPreRunE. execute alone prints a failure (showFailure): a
backend.LoggedError with the run log's end (ui.ErrorLogged, which replaces
DieLogged), a message as it is, else what failed or output_failed, with a
corrupt file's message as names mode shows it. Exit codes stay 0, 1, 2, 130.

Die is now the UI's own die, for where no command can return: a question
without an answer, a run log that can't be opened. Error prints nothing once
the run is interrupted.

After INT, TERM or HUP, Main waited only for the logged command and then ran
the cleanups while the command's own code still ran. It now also waits for
the command to return, up to returnGrace (2 s), when there are cleanups to
run; a run without cleanups ends at once, so the proxy and the other
background processes still stop as soon as they are told to. A start's
undoStart stays registered once interrupted (interruptCleanup), as the
cleanups now run after the start returned.

Tests: TestSignalsWaitForTheCommandBeforeTheCleanups (failed on the old
ordering), TestSignalsWaitForAStuckCommandAWhile,
TestSignalsWithoutCleanupsEndAtOnce, TestExecuteShowsEachFailure;
DieLogged's tests are ErrorLogged's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 10:42:20 -07:00
w3cjandClaude Opus 5.5 e13839aa41 feat(cli): every command on the folder's VM takes --here and --parent, resolved in one place
The VM a folder uses is decided once, by vm's resolveFolder, from the
folder's own VM, the nearest parent folder's (with any repo of its own
in between) and the command's rule (vm.Env.Folder): by default the
folder's own, else the parent's unless a nested repo is in between,
else none (devvm makes the folder's own, other commands say no_vm).
--here takes only the folder's own; --parent takes the parent's across
a nested repo and past the folder's own, and refuses a folder inside
none with a VM (no_parent_vm). devvm asks nothing now, in a terminal
or not: use_parent_vm and use_parent_vm_repo are gone. The questions
before deleting, remaking or widening a parent's VM stay.

find resolves through it; own is the folder's own VM (adopt, --clone);
lookup and useParent are gone; Options.Here is the rule's.

cli: addFolderFlags (flags.go) adds --here and --parent into the run's
app, which vmEnv sets as the rule; the two are exclusive, and with -g
where a command has it; --clone and --parent are exclusive; devvm rm VM
takes neither (rm_vm_folder_flag). Commands: devvm, restart, stop,
update, rm, code, desktop, host, history export, tools (add, rm,
update), size, ports (add, rm), network (allow, deny, rm, log),
ssh-agent, git-protect, clone, secret use, secret unuse, layer add,
layer rm, group (join, leave), link (add, rm, publish, unpublish).

Tests: TestResolveFolder (own, parent, none, nested repo, --here,
--parent), TestFolderFlags (every folder command takes both, and no
other; refusals before anything runs; the rule each sets), the parent
tests and subfolder.txtar's cases updated for no questions and --parent.
Docs: the Commands page's subfolder section, first VM, --clone's
subfolders, the overview's subfolder VM; the CLI reference regenerated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 01:21:41 -07:00
w3cjandClaude Opus 5.5 e132a29b5a refactor(cli): one per-run app holds the run's services
NewRoot makes one app for the run's UI and hands it to every command.
The app makes each service the first time a command asks for it and
keeps it, or its error, for the rest of the run: devvm's folders
(dirs), a test build's overrides, the secrets store, the backends'
registry, the shared tools, the VM environment (vmEnv) and the image
builder of the backend new VMs get (builder). The retention that runs
before a command and the command itself share them.

- paths.FromEnv: 23 of 24 calls go through a.dirs; partNames, which the
  parser's flag and word checks call before any command, keeps its own.
- The registry is made once (8 newRegistry calls and newEnv's).
- builder(u) (6 calls) and cli's newBuilder are gone: a.builder and the
  per-backend builders in images, space and gc are vm.Env.Builder,
  exported, the only builder. setup's feature choice takes a build.Env
  of its folders and prompts alone.
- The shared tools are made once (newTools and vm.NewEnv's), and the
  secrets store once (companyProxy's, newTools', vm.NewEnv's and
  _proxy's): vm.NewEnv takes the run's tools and store.
- withEnv (46 calls) is a.env; autoRetain, retainOrphans and gc
  --orphans use the run's VM environment.
- thisHost and readOverrides' other callers read the overrides once
  (a.host); space and gc --caches time out on the registry's host.

TestAppMakesEachServiceOnce checks that one run makes each service once
and that the VM environment and builder share the run's registry and
tools; TestAppKeepsAFailure that a failure is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 00:53:51 -07:00
w3cjandClaude Opus 5.5 a75f4daa28 feat(update): devvm update moves the VM to newer shared tools, then remakes it only when its image is outdated
devvm update first takes devvm tools update's step (Tools.update, split out
of Tools.Update), which needs no remake because shared tools are mounted.
Then, only when the VM's image chain changed, it names what changed
(vm_changed) and asks to make the VM again through the shared remake
(canRemake, agreed and remakeNow, split out of remakeTo). Only newer tools:
recorded and a shell, with no question. Nothing newer: vm_current. A no keeps
the VM with its newer tools and opens a shell when there were some. Without a
terminal or --force, an outdated VM is refused before the tools change.
devvm tools update stays the tools-only command, and newer_tools names
devvm update.

devvm layer add and devvm layer rm move to the root help's Change your VM
group, listed by both names, while layer and layer new stay under Images:
commandGroups takes a subcommand's path, addGroups adds the group to its
parent too, and the usage template lists it in the root's group.

Tests: TestUpdateTools (tools only, both without a terminal, declined,
agreed, neither), update.txtar's tools-only, no-terminal and declined cases,
TestHelpGroupsAndDocs's groups for layer add, layer rm and layer --help, and
an e2e check that devvm update on a current image never makes the VM again.
TestRemakeDone still proves a failed delete of the old machine keeps the
remake recorded. Docs: commands, images' Outdated VMs, toolchains,
troubleshooting, coding agents, internals and contributing; the cli skill's
tree; the CLI reference regenerated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 00:10:46 -07:00
w3cjandClaude Opus 5.5 f4ad9c2c3d feat(vm): devvm update makes an outdated VM again from its image's new build, keeping its home and settings
devvm update [--force|--no-export|--clean-home] (internal/cli/update.go)
is the shared remake with the VM's own image name: Lifecycle.Update calls
toRemake, decides with build.Builds.Outdated (WarnIfOutdated's check, now
its owner) whether the chain's keys changed, says vm_current and does
nothing when they didn't, else names what changed (vm_changed) and calls
remakeTo. --from VMs are judged on the recorded digest and built with
build's lookup. The remake's flags are one adder (addRemakeFlags) for
devvm layer add and devvm update. vm_outdated names devvm update.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 19:47:49 -07:00
w3cjandClaude Opus 5.5 07ca65c098 feat(cli): devvm host, the tools noun and devvm history
devvm ssh is devvm host. devvm tools shows this folder's VM's shared
tools (TOOL VERSION NEWER BUILT, from the lock as it is, never online);
devvm tools add/rm TOOL... add and take out shared tools, each a word of
its own (joined with + refused: tools_joined; add takes only shared
tools: unknown_tool), and devvm tools update moves the VM to the newest.
devvm IMAGE on a VM that exists adds nothing and asks nothing: it fails
with vm_lacks_tools, naming the devvm tools add command, or
vm_lacks_layer, as only a new VM gets a layer. devvm export is devvm
history export [FILE]; devvm history lists the exports in the exports
folder (FILE VM FOLDER DATE SIZE), the folder from a <export>.folder
file written beside devvm's own exports and deleted with them. gc
--exports is gc --history, retention's exports.age/count are
history.age/count, and devvm space's row is history.

The in-place layer machinery goes: Launch.addLayers and runLayers,
dockerLayers' inPlace/set/unset, backend.DockerLayerVM.SetDockerLayer
and the Docker backend's SetDockerLayer, with the add_in_place,
restart_for_mounts, no_terminal_confirm, keeping, adding and
add_layer_failed messages. vm.Tools (tools.go) holds Add, Remove,
Update and List; tools.VMs.Show lists a VM's tools; tools.Remove takes
names as a list; VMs.Update compares a VM's files as a set.

New messages: vm_lacks_tools, vm_lacks_layer, has_tools, tools_joined,
history_failed, tools_failed; renamed: unknown_tool, gc_history,
gc_history_export, deleted_history, gc_older_than_needs_history.
Command files: host.go, tools.go, history.go, refreshtools.go
(_refresh-tools); ssh.go, remove.go, update.go, export.go and
gc_exports.go gone. Tests: TestImageLacks, TestToolsAdd, TestShow,
TestCompleteToolNames; history.txtar, gc_history.txtar, host_code.txtar
and the e2e tools, docker layer and host checks updated. Docs, the CLI
reference, AGENTS.md and the e2e header follow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-01 01:27:24 -08:00
w3cjandClaude Opus 5.5 1e4c772cc5 refactor(vm): split Env's commands into types by group
Env holds the shared dependencies NewEnv sets and the helpers every
group uses: finding the folder's VM, starting it, applying its size and
ports, the image builder and the ssh config. The commands are on types
that embed *Env:

- Launch: up, restart, remove, update, ssh and code; a new VM
  (up.go), an existing one (existing.go), ssh.go, agents' mounts
- Lifecycle: stop, adopt, rm and export (lifecycle.go)
- Settings: .git protection (settings.go), size (size.go), ports
  (ports.go), SSH agent forwarding (sshagent.go)
- Net: network policy, its log and allowlist (network.go), secrets
  (secret.go)
- clones (clone.go) and syncer (sync.go), used by the others

env.go holds Env, UI, NewEnv and the shared helpers. cli's commands
call the group they need, e.g. vm.Launch{Env: env}.Up. Tests follow
their code: env_test.go holds the shared helpers, with up_test.go,
lifecycle_test.go, network_test.go and ports_test.go beside them.
The most methods on one type is 24 (Launch).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 16:44:53 -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 f2aa210bf7 feat(up): existing VMs, restart, remove, update, adopt and rm
devvm opens a VM that exists instead of refusing it: unfinished VMs
(no state or no network choice) are refused before anything; --backend,
--network-policy, --no-git-protect, --cpus/--memory/--disk and --ports
are ignored with a warning each; an IMAGE naming what the VM lacks adds
it in place after asking (tools built and listed, a layer's script run
in the VM, new agents' folders mounted with a stop first); outdated
images and newer tools are warned about, the daily tools check runs,
agent folder mounts follow the host's, .git is checked per run, set-id
files are named on Linux, a stopped VM gets the size and ports its state
asks for (a running one is told they apply at its next start); then it
is started if stopped (a running VM with network policy keeps its
proxy), the self-check runs (a failure stops the VM), and it is set up
and its shell opened.

Commands: restart (stop, then open), update (newest shared tools, built
from base, then open), remove TOOLS (out of the image and tool list,
then open), adopt (a VM made for an earlier folder at this path, after
asking; .git protection restarts as appeared), rm [-f] (exports the
agents' history first unless -f, a failed export keeps the VM; a VM of
an earlier folder only after asking, without export; deletes the VM,
state, proxy, rules, run files, logs, .git locks, host keys and ssh
config entry, also when the delete failed but left no VM).

Inventory:
- vm: find/findExisting/existing, sameFolder, open, run, setUp,
  warnIgnored, checkSetID, applySize, applyPorts, addLayers,
  wantedImage, runScript, buildTools; Restart, Remove, Update, Adopt,
  Rm, export, delete; start refuses vm_unfinished and stops a leftover
  proxy for VMs without network policy
- gitprotect: Protector.Check (replaced, appeared, new submodules in
  the tree and .git/modules, unlocked hooks, commondir, delegations on
  change; locks only while stopped; unset protection set up as new),
  Locked field; platform.Immutable
- tools.Update takes a build func; build.Builder.LayerScript exported
- cli: restart, remove, update, adopt, rm; withEnv; root Long
- messages: vm_other_folder (reworded), vm_other_folder_rm/_adopt,
  delete_other_folder_vm, adopt_vm, vm_adopted, vm_already_here, no_vm,
  vm_unfinished, backend/net/git_protect/ports_flag_ignored,
  size_flags_ignored, size_next_start, ports_next_start, add_in_place,
  restart_for_mounts, no_terminal_confirm, keeping, adding,
  add_layer_failed, vm_is_now, exported, export_failed, deleted,
  rm_failed, adopt_failed, git_replaced, git_appeared,
  git_embedded_new, git_hooks_unlocked; net_unenforced_stop says devvm
  starts it again confined; vm_exists removed
- tests: testscript existing.txtar, existing_agents.txtar; Go tests for
  Check (five per-run reports, replaced/appeared, off/unset), open with
  network policy, addLayers, Rm, Adopt, remove/update/restart; limactl
  stub: delete-fails, Exec-fed scripts
- converted bats: delete (vm_unfinished, rm cleans up after a failed
  delete, rm deletes only this VM), project (folder made again, update
  twice, remove twice, five .git per-run reports), ports (applied once,
  restart warning), size (restart warning), cli (rm forgets host keys)
- e2e: project (stop and relaunch, running relaunch, restart with host
  keys, swapped .git, new submodule locked, rm unlocks; agent folder
  added/removed on restart, rm exports history without logins), tools
  (update, remove), network (relaunch confined, unenforced relaunch
  stops it, rm -f)
- docs: commands.md (existing VM, adding, deleting, a folder made
  again), coding-agents.md (mounts on launch, history), git-protection
  (on each launch), images, network, security; CLI reference

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