A folder named x--y, "foo (copy)" or "C++ stuff" failed to get a VM
(#52): project.Slug turned each character other than a-z and 0-9 into
its own dash, and Lima's instance-name grammar refuses separators in a
row. Slug now writes one dash per run.
- vmname: the project-VM grammar refuses dashes in a row
([a-z0-9]+(-[a-z0-9]+)*); HasRuns recognises the names releases up to
0.1.1-rc.3 made for such folders.
- state: a vm.json whose name HasRuns and that has no created time is
read as no state. Only a create that Lima refused leaves one (vm.json
is written before limactl clone), so the folder's next VM, in the same
hash folder, replaces it, rather than every read failing as corrupt.
One with created set is still corrupt.
- The limactl stub refuses names Lima refuses on create and clone;
TestLimactlStubContract gains a refused clone, checked against real
Lima.
- Tests: TestNamesLimaTakes (Lima's regex as the oracle), TestHasRuns,
TestVMWithRuns, TestLimactlRefusesNames, name_runs.txtar (a new VM for
x--y, and an older release's leftover state replaced).
- Docs: internals/backends.md's VM names; CHANGELOG Unreleased Fixed.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
- 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]>
The one remake in vm's Lifecycle (remake.go): the image built first, the
agents' history exported and the home folder saved (home.go: the VM's tar
stream filtered on the host), the VM stopped and its machine renamed
aside (backend.Backend's Rename, limactl rename, vmname.Aside), the new
machine made from vm.json, started, its home put back, then the old one
deleted. A failure or interrupt before that puts the old VM back; a
killed devvm leaves the remake section, which the next devvm or devvm
layer add finishes. The VM keeps its ID (design.md).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
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]>