feat(cli): --json on every command that shows or lists

ls, images, tools, size, ports, network (and -g), network log (and
--blocked), ssh-agent, git-protect, secret, history, space, retention and
doctor take --json: one JSON object on stdout with "version": 1 first,
messages on stderr (ui.DataOnly), lists [] when empty. Settings commands
only show with --json and refuse a value (json_shows_only). doctor --json
replaces --fixes: problems with key, fix (null without one) and message,
warnings, docker and every backend's features; it prints nothing else and
succeeds whatever is missing, and install.sh reads its problems with awk.
TestJSONShapes holds each command's field names and types. Each shape is
documented on its command's page, with the contract under Everyday
commands' Output for scripts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
w3cjandClaude Opus 5.5 committed 2026-11-01 03:06:56 -08:00
1 parent fe32d2a01c
commit cd6fc60576
90 files changed
+2093 -388

No files matched your search

+14 -11
View File
@@ -1,6 +1,7 @@
# doctor: what the backend new VMs get needs on this machine and how to
# get what's missing, each backend's features, and whether Docker is
# there. --fixes prints only what's missing, for scripts.
# there. --json prints what it found as JSON, for scripts, and nothing
# else.
env DEVVM_MESSAGES=names
env ALL=$PATH
chmod 0755 brew/brew
@@ -24,8 +25,9 @@ stdout '^doctor_ok backend=lima version=\S+\n\z'
! stderr .
stub_calls
stdout '^limactl --version\n\z'
exec devvm doctor --fixes
! stdout .
exec devvm doctor --json
stdout '^{\n "version": 1,\n "backend": "lima",\n "problems": \[\],\n "warnings": \[\],\n "docker": true,\n'
stdout '^ "egress-proxy": "emulated",$'
! stderr .
# Another backend, or one devvm doesn't have.
@@ -41,8 +43,9 @@ stdout '^FEATURE +DOCKER +LIMA +SMOLVM\n'
stdout '^docker_missing\n'
! stdout doctor_ok
stderr '^devvm: lima_missing$'
exec devvm doctor --fixes
stdout '^lima\t\tlima_missing\n'
exec devvm doctor --json
stdout '^ "key": "lima",\n "fix": null,\n "message": "lima_missing"\n'
stdout '^ "docker": false,$'
! stderr .
# Every command that needs the backend stops at the first problem.
@@ -56,13 +59,13 @@ cd ..
# With Homebrew, its command.
env PATH=$WORK/brew${:}$WORK/qemu${:}$DEVVM_BIN
exec devvm doctor --fixes
stdout '^lima\tbrew install lima\tlima_missing_fix fix=brew install lima\n'
exec devvm doctor --json
stdout '^ "key": "lima",\n "fix": "brew install lima",\n "message": "lima_missing_fix fix=brew install lima"\n'
# A limactl that doesn't run, as one built for another processor.
env PATH=$WORK/broken${:}$WORK/brew${:}$WORK/qemu${:}$DEVVM_BIN
exec devvm doctor --fixes
stdout '^lima\tbrew reinstall lima\tlima_broken_fix fix=brew reinstall lima\n'
exec devvm doctor --json
stdout '^ "key": "lima",\n "fix": "brew reinstall lima",\n "message": "lima_broken_fix fix=brew reinstall lima"\n'
! exec devvm doctor
stderr '^devvm: lima_broken_fix fix=brew reinstall lima$'
@@ -75,8 +78,8 @@ stderr '^devvm: lima_broken_fix fix=brew reinstall lima\ndevvm: lima_global_conf
env PATH=$ALL
! exec devvm doctor
stderr '^devvm: lima_global_config files=\S+/_config/default.yaml$'
exec devvm doctor --fixes
stdout '^lima-config\t\tlima_global_config files=\S+/_config/default.yaml\n\z'
exec devvm doctor --json
stdout '^ "problems": \[\n {\n "key": "lima-config",\n "fix": null,\n "message": "lima_global_config files=\S+/_config/default.yaml"\n }\n \],$'
-- brew/brew --
#!/bin/sh
+4
View File
@@ -47,6 +47,8 @@ exec devvm --no-network-policy --no-git-protect go
stderr '^devvm: no_subcommand command=devvm tools commands=add, rm, update given=now$'
exec devvm tools
stdout '^TOOL +VERSION +NEWER +BUILT\ngo +\S+ +- +-\n\z'
exec devvm tools --json
stdout '\A{\n "version": 1,\n "tools": \[\n {\n "tool": "go",\n "version": "\S+"\n }\n \]\n}\n\z'
exec devvm tools update
stdout '^==> checking_tools$'
stdout '^==> tools_newest vm=devvm-api-[0-9a-f]{14}$'
@@ -71,6 +73,8 @@ exec devvm
stderr '^devvm: newer_tools tools=go 9\.9\.9$'
exec devvm tools
stdout '^go +1\.0\.0 +9\.9\.9 +yes$'
exec devvm tools --json
stdout '\A{\n "version": 1,\n "tools": \[\n {\n "tool": "go",\n "version": "1\.0\.0",\n "newer": "9\.9\.9",\n "newer_built": true\n }\n \]\n}\n\z'
# tools rm: the tools leave its name and list, the rest stays; what it
# lacks is refused, and so is a layer. Names are separate words.
+4
View File
@@ -44,6 +44,10 @@ stdout '^chflags -R -P uchg /\S*/web/\.git/hooks$'
! stdout 'limactl (start|edit)'
exec devvm git-protect
stdout '\Astrict\n\z'
exec devvm git-protect --json
stdout '\A{\n "version": 1,\n "mode": "strict"\n}\n\z'
! exec devvm git-protect --json off
stderr '^devvm: json_shows_only command=devvm git-protect$'
exec sh -c 'cat "$VMS"/devvm-web-*'
stdout '^git_protect=strict$'
stdout '^git_inode=[0-9]+$'
+4
View File
@@ -17,6 +17,8 @@ stderr '^devvm: no_subcommand command=devvm history commands=export given=now$'
# None yet: the header alone, no VM needed.
exec devvm history
stdout '^FILE +VM +FOLDER +DATE +SIZE\n\z'
exec devvm history --json
stdout '\A{\n "version": 1,\n "exports": \[\]\n}\n\z'
exec devvm --no-network-policy base
exec sh -c 'limactl stop "$(basename "$VMS"/devvm-web-*)"'
@@ -58,4 +60,6 @@ stdout '^FILE +VM +FOLDER +DATE +SIZE\n'
stdout '^\S*/exports/devvm-old-12345612345612-20200101-000000\.tar\.gz +devvm-old-12345612345612 +- +2020-01-01 00:00 +\S+\n\S*/exports/devvm-web-'
stdout '^\S*/exports/devvm-web-[0-9a-f]{14}-[0-9]{8}-[0-9]{6}\.tar\.gz +devvm-web-[0-9a-f]{14} +\S*/web +[0-9-]+ [0-9:]+ +\S+$'
! stdout notes
exec devvm history --json
stdout '^ "file": "\S*/exports/devvm-old-12345612345612-20200101-000000\.tar\.gz",\n "vm": "devvm-old-12345612345612",\n "folder": "",\n "date": "2020-01-01T00:00:00[-+Z][0-9:]*",\n "size": \d+\n'
! stdout out/h
+8
View File
@@ -49,6 +49,14 @@ stderr '^images_total size=\S+$'
stdout '^node +- '
stub_calls
! stdout mise
# --json: the same as fields, sizes in bytes; the notes stay on stderr.
exec devvm images --json
stdout '^{\n "version": 1,\n "images": \[\n {\n "name": "base",\n "from": "ubuntu 26\.04 \(\d{8}\)",\n "digest": "sha256:[0-9a-f]{64}",\n "key": "[0-9a-f]{12}",\n "state": "current",\n "size": \d+,\n "sized": true,\n "backend": "lima"\n'
stdout '^ "name": "go",\n "tool": "go",\n "version": "1\.20\.0",\n "built": true,\n "backend": "smolvm",\n "libc": "musl",\n "size": \d+,\n "vms": 1,\n "state": "in use"\n'
stdout '^ "name": "go",\n "tool": "go",\n "version": "1\.27\.2",\n "built": false,\n "size": 0,\n "vms": 0,\n "state": "not built"\n'
stdout '^ "total": \d+,\n "unused_tools": \d+,\n "nix_cache": {\n "files": 0,\n "size": 0,\n "cap": \d+\n }\n}\n\z'
stderr '^images_total size=\S+$'
! stdout '^IMAGE'
# images rm: by key (an unfinished build), or by name; nothing else.
# A name is its image as it is now: foo is current again.
+82 -13
View File
@@ -105,30 +105,31 @@ stderr '^ remove it, or put \S+/prefix/bin before its folder in PATH$'
! stderr 'isn''t on your PATH'
! exists other-ran
# The fixes devvm suggests run once allowed; what it can't fix is shown.
exec bash deps.sh yes 'qemu\tsudo apt-get install -y qemu-system-arm\tQEMU not found\nkvm\t\t/dev/kvm not found: turn on virtualization\nlima\tbrew install lima\tLima not found\n'
stdout '^ /dev/kvm not found: turn on virtualization$'
# The fixes devvm suggests run once allowed; what it can't fix is shown,
# its escapes read.
exec bash deps.sh yes fixes.json
stdout '^ /dev/kvm not found: turn on "virtualization" \\ in the firmware$'
stdout '^checked$'
cmp ran ran-fixes.want
# After joining the kvm group: log in again, no check.
exec bash deps.sh yes 'kvm-access\tsudo usermod -aG kvm me\tno access to /dev/kvm\n'
exec bash deps.sh yes kvm.json
stdout 'Log out and back in'
! stdout '^checked$'
cmp ran ran-kvm.want
# Nothing runs without a yes.
exec bash deps.sh no 'kvm-access\tsudo usermod -aG kvm me\tno access to /dev/kvm\n'
exec bash deps.sh no kvm.json
stdout '^ skipped: sudo usermod -aG kvm me$'
! exists ran
# No Lima and no Homebrew: Lima's release, once allowed.
exec bash deps.sh lima 'lima\t\tLima not found\n'
exec bash deps.sh lima lima.json
stdout '^==> installed Lima 2.3.0: '
exists prefix/bin/limactl
# Nothing missing, nothing asked.
exec bash deps.sh asked ''
exec bash deps.sh asked none.json
cmp stdout deps-none.want
# The whole script: options, a release, the PATH hint.
@@ -393,14 +394,14 @@ mkdir -p "$WORK/links"
ln -s "$prefix/lib/devvm/0.1.0/devvm" "$WORK/links/devvm"
echo "linked: $(PATH="$WORK/links:$prefix/bin:$PATH" path_hint)"
-- deps.sh --
# deps.sh ANSWER LINES: install_deps with a devvm whose doctor --fixes
# prints LINES (printf's format) and whose doctor prints "checked"; the
# brew and sudo in bin/ log to $WORK/ran. ANSWER: yes (--yes), no (every
# question answered no), lima (yes, with a Lima release to install), asked
# (a question prints "asked").
# deps.sh ANSWER FILE: install_deps with a devvm whose doctor --json
# prints $WORK/FILE and whose doctor prints "checked"; the brew and sudo
# in bin/ log to $WORK/ran. ANSWER: yes (--yes), no (every question
# answered no), lima (yes, with a Lima release to install), asked (a
# question prints "asked").
. "$WORK/lib.sh"
mkdir -p "$WORK/fake"
printf '#!/bin/sh\n[ "$2" = --fixes ] && printf "%s" || echo checked\n' "$2" > "$WORK/fake/devvm"
printf '#!/bin/sh\n[ "$2" = --json ] && cat "$WORK/%s" || echo checked\n' "$2" > "$WORK/fake/devvm"
chmod 755 "$WORK/fake/devvm"
case $1 in
yes) yes=true ;;
@@ -409,6 +410,74 @@ case $1 in
asked) ask() { echo asked; } ;;
esac
install_deps "$WORK/fake/devvm"
-- fixes.json --
{
"version": 1,
"backend": "lima",
"problems": [
{
"key": "qemu",
"fix": "sudo apt-get install -y qemu-system-arm",
"message": "QEMU not found"
},
{
"key": "kvm",
"fix": null,
"message": "/dev/kvm not found: turn on \"virtualization\" \\ in the firmware"
},
{
"key": "lima",
"fix": "brew install lima",
"message": "Lima not found,"
}
],
"warnings": [],
"docker": false,
"features": {
"lima": {
"ssh": "native"
}
}
}
-- kvm.json --
{
"version": 1,
"backend": "lima",
"problems": [
{
"key": "kvm-access",
"fix": "sudo usermod -aG kvm me",
"message": "no access to /dev/kvm"
}
],
"warnings": [],
"docker": false,
"features": {}
}
-- lima.json --
{
"version": 1,
"backend": "lima",
"problems": [
{
"key": "lima",
"fix": null,
"message": "Lima not found"
}
],
"warnings": [],
"docker": false,
"features": {}
}
-- none.json --
{
"version": 1,
"backend": "lima",
"problems": [],
"warnings": [],
"docker": false,
"features": {}
}
-- deps-none.want --
==> everything devvm needs is installed
checked
+14
View File
@@ -53,6 +53,13 @@ stdout '^devvm-half-0123456789abcd +Stopped +- +- +- +lima +-\n'
! stdout devvm-tools-build
# Sorted by name.
stdout '\ndevvm-cl-.*\ndevvm-from-.*\ndevvm-half-.*\ndevvm-img-foo-.*\ndevvm-net-'
# --json: the same, the image and what its base started from apart, ""
# for what a VM lacks, and nothing else on stdout.
exec devvm ls --json
stdout '^{\n "version": 1,\n "vms": \[\n'
stdout '^ "name": "devvm-from-0123456789abcd",\n "status": "Running",\n "image": "base",\n "from": "node:24",\n "git": "on",\n "net": "off",\n "backend": "lima",\n "folder": "/p/from"\n'
stdout '^ "name": "devvm-half-0123456789abcd",\n "status": "Stopped",\n "image": "",\n "git": "",\n'
! stdout '^NAME'
# Lima can't list (not installed): fails, as a VM's state names it; with
# none, the header alone.
@@ -63,7 +70,14 @@ stderr '^devvm: lima_missing$'
rm $VMS
exec devvm ls
cmp stdout $WORK/header.txt
exec devvm ls --json
cmp stdout $WORK/none.json
-- none.json --
{
"version": 1,
"vms": []
}
-- header.txt --
NAME STATUS IMAGE GIT NET BACKEND FOLDER
-- clone.state --
+2
View File
@@ -180,6 +180,8 @@ exec cat $XDG_CONFIG_HOME/devvm/network
stdout '\Aoff\n\z'
exec devvm network -g
stdout '\Aoff\n\z'
exec devvm network -g --json
stdout '\A{\n "version": 1,\n "policy": "off"\n}\n\z'
mkdir $WORK/offsaved
cd $WORK/offsaved
exec devvm --no-git-protect base
+13
View File
@@ -14,6 +14,9 @@ exec devvm --network-policy --no-git-protect base
exec devvm network log
stdout '^==> log_empty vm=devvm-net-[0-9a-f]{14}$'
! stderr .
exec devvm network log --json
stdout '\A{\n "version": 1,\n "events": \[\]\n}\n\z'
! stderr .
# Allowed and blocked connections and requests, oldest first, the last 50
# or the last N.
@@ -29,12 +32,22 @@ exec devvm network log --lines 0
stderr '^devvm: flag_bad_value flag=--lines form=N value=x$'
! exec devvm network log -n -1
stderr '^devvm: flag_bad_value flag=--lines form=N value=-1$'
# --json: the events as the proxy logged them, without the VM's name;
# never followed.
exec devvm network log --json -n 3
stdout '\A{\n "version": 1,\n "events": \[\n {\n "time": "2026-10-09T10:00:08Z",\n "event": "tunnel",\n "host": "fd00::1",\n "port": 22,\n "method": "CONNECT",\n "rule": "\[fd00::1\]:22"\n },\n'
! stdout '"vm"'
! exec devvm network log --json -f
stderr '^devvm: flags_exclusive flag=--(json|follow) other=--(json|follow)$'
# The blocks by host and port, by when last blocked, with the command
# that allows each: only for a host name or address, and never for a
# request refused whatever the allowlist says.
exec devvm network log --blocked
cmp stdout $WORK/blocked.txt
exec devvm network log --blocked --json
stdout '\A{\n "version": 1,\n "blocked": \[\n {\n "last": "2026-10-09T10:00:07Z",\n "count": 1,\n "host": "api.github.com",\n "port": 443\n },\n'
stdout '^ "last": "2026-10-09T10:01:00Z",\n "count": 2,\n "host": "a.test",\n "port": 443,\n "allow": "a.test"\n'
! exec devvm network log --blocked -f
stderr '^devvm: flags_exclusive flag=--blocked other=--follow$'
+7
View File
@@ -77,6 +77,13 @@ stdout '^ github\.com$'
stdout '^# \S*/config/devvm/policy\n \*\.corp\.test\n# \S*/vms/devvm-net-[0-9a-f]{14}\.policy\n !bad\.example\.com\n example\.com\n'
! stdout mine
! stderr .
# --json: the same, each file with its rules; it only shows.
exec devvm network --json
stdout '\A{\n "version": 1,\n "policy": "(on|unenforced)",\n "allowlist": \[\n {\n "file": "\S*/layers/base\.policy",\n "rules": \[\n'
stdout '^ "file": "\S*/vms/devvm-net-[0-9a-f]{14}\.policy",\n "rules": \[\n "!bad\.example\.com",\n "example\.com"\n \]\n'
! stderr .
! exec devvm network --json off
stderr '^devvm: json_shows_only command=devvm network$'
# A VM without network policy: devvm network shows it off, with its
# rules, and changing them says they don't apply.
+6
View File
@@ -36,6 +36,12 @@ exec sh -c 'cat "$CFG/ports"'
stdout '\A3000-3999,5173\n\z'
exec devvm ports -g
stdout '\A3000-3999,5173\n\z'
exec devvm ports -g --json
stdout '\A{\n "version": 1,\n "ports": "3000-3999,5173"\n}\n\z'
! exec devvm ports -g --json all
stderr '^devvm: json_shows_only command=devvm ports$'
! exec devvm ports add --json 1
stderr '^devvm: flag_unknown command=devvm ports add flag=--json$'
! exec devvm ports -g add all
stderr '^devvm: ports_list_needed value="all"$'
! exec devvm ports -g rm none
+16
View File
@@ -45,6 +45,10 @@ exec cat $XDG_CONFIG_HOME/devvm/retention
cmp stdout want-retention
exec devvm retention
cmp stdout want-shown
exec devvm retention --json
cmp stdout want-shown.json
! exec devvm retention --json history.count=5
stderr '^devvm: json_shows_only command=devvm retention$'
! exec devvm retention history.count=x
cmp $XDG_CONFIG_HOME/devvm/retention want-retention
exec devvm space
@@ -118,6 +122,18 @@ history.count=off
tools.unused-age=1d
orphans.age=off
nix-cache.size=off
-- want-shown.json --
{
"version": 1,
"settings": {
"history.age": "30d",
"history.count": "off",
"logs.runs": "off",
"nix-cache.size": "off",
"orphans.age": "off",
"tools.unused-age": "1d"
}
}
-- want-all-off --
logs.runs=off
history.age=off
+6
View File
@@ -32,6 +32,10 @@ stdout '^sk-ant-oat01-testfake$'
exec devvm secret
stdout '^NAME +SAVED +USED BY$'
stdout '^claude +yes +-$'
# --json: saved or not, never the token.
exec devvm secret --json
stdout '\A{\n "version": 1,\n "secrets": \[\n {\n "name": "claude",\n "saved": true,\n "used_by": \[\]\n },\n'
! stdout 'sk-ant'
env CLAUDE_CODE_OAUTH_TOKEN=
# Only devvm's own names: never a path.
@@ -119,6 +123,8 @@ exec sh -c 'cat "$VMS"/devvm-off-*'
stdout '^secrets=github$'
exec devvm secret
stdout '^github +no +devvm-off-[0-9a-f]{14}$'
exec devvm secret --json
stdout '^ "name": "github",\n "saved": false,\n "used_by": \[\n "devvm-off-[0-9a-f]{14}"\n \]\n'
exec devvm secret unuse github
stdout '^==> secret_unused secret=github vm=devvm-off-[0-9a-f]{14}$'
stderr '^secret_unuse_copied secret=github vm=devvm-off-[0-9a-f]{14}$'
+11
View File
@@ -32,6 +32,11 @@ exec devvm size -g --memory=2.5GiB
stdout '^==> size_defaults size=cpus=2 memory=2\.5GiB$'
exec devvm size -g
cmp stdout $WORK/set
# --json: what's unset left out; it only shows.
exec devvm size -g --json
stdout '\A{\n "version": 1,\n "cpus": 2,\n "memory_gib": 2\.5\n}\n\z'
! exec devvm size -g --json --cpus 4
stderr '^devvm: json_shows_only command=devvm size$'
exec sh -c 'cat "$CFG/size"'
stdout '^cpus=2$'
stdout '^memory=2\.5$'
@@ -56,6 +61,9 @@ exec sh -c 'echo "2 8589934592 107374182400" > "$STUB_DIR/size-$(basename "$VMS"
exec devvm size
stdout '\Acpus=2 memory=8GiB disk=100GiB\n\z'
! stderr .
exec devvm size --json
stdout '\A{\n "version": 1,\n "cpus": 2,\n "memory_gib": 8,\n "disk_gib": 100\n}\n\z'
! stderr .
exec sh -c ': > "$STUB_LOG"'
exec devvm size --cpus 1 --memory 3
stderr '^devvm: size_next_start vm=devvm-web-[0-9a-f]{14}$'
@@ -68,6 +76,9 @@ stdout '^memory=3$'
exec devvm size
stdout '\Acpus=2 memory=8GiB disk=100GiB\n\z'
stderr '^size_pending size=cpus=1 memory=3GiB vm=devvm-web-[0-9a-f]{14}$'
exec devvm size --json
stdout '^ "disk_gib": 100,\n "pending": {\n "cpus": 1,\n "memory_gib": 3\n }\n}\n\z'
stderr '^size_pending '
# Back to what it has: nothing waits.
exec devvm size --cpus 2 --memory 8
stdout '^==> vm_size size=cpus=2 memory=8GiB disk=100GiB vm=devvm-web-[0-9a-f]{14}$'
+1
View File
@@ -49,6 +49,7 @@ stub_calls
# --json, for scripts.
exec devvm space --json
stdout '^{\n "version": 1,\n "devvm": \[\n'
stdout '"what": "leftover state"'
stdout '"kept": "only copy"'
stdout '"total": \d+'
+6
View File
@@ -35,6 +35,8 @@ stdout '^ ForwardAgent no$'
! stdout IdentityAgent
exec devvm ssh-agent
stdout '\Aoff\n\z'
exec devvm ssh-agent --json
stdout '\A{\n "version": 1,\n "mode": "off",\n "keys": \[\]\n}\n\z'
exec devvm --ssh-agent
stderr '^devvm: ssh_agent_flag_ignored$'
@@ -97,6 +99,10 @@ stderr '^devvm: agent_key_mounted key=\S*/web/key vm=devvm-web-[0-9a-f]{14}$'
# holds and those added to it.
exec devvm ssh-agent
stdout '\Aon\n256 SHA256:fp-deploy deploy \(ED25519\)\n\S*/keys/deploy: SHA256:fp-deploy lifetime=12h\n\z'
exec devvm ssh-agent --json
stdout '\A{\n "version": 1,\n "mode": "on",\n "keys": \[\n {\n "file": "\S*/keys/deploy",\n "fingerprint": "SHA256:fp-deploy",\n "confirm": false,\n "lifetime": "12h",\n "loaded": true\n }\n \]\n}\n\z'
! exec devvm ssh-agent --json off
stderr '^devvm: json_shows_only command=devvm ssh-agent$'
# devvm ssh-agent devvm on the running VM: from its next start. Until
# then devvm's connections and its ssh config entry carry the agent it