跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

提交记录

0.3.0: full rewrite in Go

This project started in shell but as we grew in features and security it became unscalable. Notably, we are now able to vendor Lima, sshocker and pkg/sftp with important security fixes on file sharing and networking. This should also simplify the installation because it doesn't require installing Lima separately anymore. The downside is that we can't use the system Lima anymore if already installed, but agent-vm's VMs were not meant to be shared with other tools in the first place.

作者
Sylvain Zimmer
时间
2026/10/14 05:39
提交
8686a52
上一个
ac64426
这个版本的全部文件
修改.gitattributes+25 −7看文件
@@ -1,10 +1,28 @@
1新增:# Everything is LF in the working tree, on Windows too: a CRLF checkout breaks
2新增:# bash scripts and the tests that compare files byte for byte.
3新增:* text=auto eol=lf
4新增:
15# Shell scripts must keep LF endings everywhere: a CRLF checkout on
2删除:# Windows breaks bash, including the test suite on the windows-latest runner.
6新增:# Windows breaks bash.
37*.sh text eol=lf
8新增:/scripts/* text eol=lf
9新增:/tests/sftp/run text eol=lf
10新增:
11新增:# Go files too: a CRLF checkout on Windows breaks the tests that compare
12新增:# them byte for byte (limaembed's copy of limactl's hostagent command).
13新增:*.go text eol=lf
14新增:
15新增:# Checked byte for byte by scripts/licenses --check.
16新增:/THIRD_PARTY_LICENSES text eol=lf
17新增:
18新增:# Images are binary, and the recorded outputs and fuzz corpora of the tests
19新增:# are never converted.
20新增:*.png binary
21新增:*.gz binary
22新增:/internal/*/testdata/** -text
23新增:/tests/sftp/testdata/** -text
424
5删除:# Left out of the release tarball (release.sh builds it with git archive):
6删除:# the site and the tests are not what an install runs.
7删除:/www export-ignore
8删除:/tests export-ignore
9删除:/test.sh export-ignore
10删除:/test-e2e.sh export-ignore
25新增:# Byte for byte as upstream and the patches have them: no line ending
26新增:# conversion, or the patches stop applying and the sync check fails.
27新增:/third_party/** -text
28新增:/patches/** -text
新增.github/workflows/go.yml+113 −0看文件
@@ -0,0 +1,113 @@
1新增:name: go
2新增:
3新增:on:
4新增: push:
5新增: pull_request:
6新增:
7新增:permissions:
8新增: contents: read
9新增:
10新增:# A newer push to a branch or pull request replaces the run in progress, never
11新增:# on main: release.sh looks for the run of the commit it releases.
12新增:concurrency:
13新增: group: ${{ github.workflow }}-${{ github.ref }}
14新增: cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
15新增:
16新增:jobs:
17新增: go:
18新增: strategy:
19新增: fail-fast: false
20新增: matrix:
21新增: os: [ubuntu-latest, macos-latest, windows-latest]
22新增: runs-on: ${{ matrix.os }}
23新增: timeout-minutes: 45
24新增: defaults:
25新增: run:
26新增: shell: bash
27新增: env:
28新增: # The Makefile's TAGS: what ships is what is tested.
29新增: GOFLAGS: -tags=yq_noxml,yq_nolua,yq_noini,yq_nohcl,yq_notoml,yq_noprops,yq_nocsv,yq_nouri,yq_nobase64,yq_nosh,yq_noshell
30新增: steps:
31新增: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
32新增: with:
33新增: # The steps below run code from the PR branch.
34新增: persist-credentials: false
35新增:
36新增: - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7
37新增: with:
38新增: go-version-file: go.mod
39新增:
40新增: # The prerequisite checks need QEMU's binary (no VM is booted: the
41新增: # tests run Lima through a fake).
42新增: - name: QEMU
43新增: if: runner.os == 'Windows'
44新增: run: winget install -e --id SoftwareFreedomConservancy.QEMU --version 11.1.0 --silent --accept-package-agreements --accept-source-agreements
45新增:
46新增: - name: third_party is upstream plus patches/
47新增: if: runner.os == 'Linux'
48新增: run: make check-third-party
49新增:
50新增: - name: go.mod and go.sum are tidy, and the modules are what go.sum says
51新增: if: runner.os == 'Linux'
52新增: run: |
53新增: go mod tidy -diff
54新增: go mod verify
55新增:
56新增: # The licenses shipped in each release: every module that goes into the
57新增: # binaries, on the three platforms.
58新增: - name: THIRD_PARTY_LICENSES is up to date
59新增: if: runner.os == 'Linux'
60新增: run: scripts/licenses --check
61新增:
62新增: # Served as `curl | sh`: plain sh, not bash. shellcheck is on the
63新增: # runner image.
64新增: - name: Shell syntax and shellcheck
65新增: if: runner.os == 'Linux'
66新增: run: |
67新增: for f in agent-vm.sh agent-vm.setup.sh release.sh runtime.example.sh tests/*.sh tests/sftp/run tests/sftp/*.sh scripts/*; do
68新增: echo "bash -n $f"
69新增: bash -n "$f"
70新增: done
71新增: sh -n www/public/install.sh
72新增: shellcheck --version
73新增: shellcheck -S warning agent-vm.sh agent-vm.setup.sh release.sh runtime.example.sh tests/*.sh tests/sftp/run tests/sftp/*.sh scripts/*
74新增: shellcheck -S warning --shell=sh www/public/install.sh
75新增:
76新增: - name: Build, with the guest agent and templates
77新增: if: runner.os != 'Windows'
78新增: run: make agent-vm
79新增:
80新增: # No make there: built without the embedded files, whose tests skip.
81新增: - name: Build
82新增: if: runner.os == 'Windows'
83新增: run: go build -o _output/bin/agent-vm.exe ./cmd/agent-vm
84新增:
85新增: - name: Vet
86新增: run: go vet . ./cmd/... ./internal/...
87新增:
88新增: - name: Vet for Windows, amd64 and arm64
89新增: if: runner.os == 'Linux'
90新增: run: make check-windows
91新增:
92新增: # Known vulnerabilities in what the code reaches, in the Linux and
93新增: # Windows builds (macOS's needs cgo and its SDK: it shares the modules).
94新增: - name: govulncheck
95新增: if: runner.os == 'Linux'
96新增: run: |
97新增: go install golang.org/x/vuln/cmd/[email protected]
98新增: govulncheck ./...
99新增: GOOS=windows govulncheck ./...
100新增:
101新增: - name: Test
102新增: run: go test . ./cmd/... ./internal/...
103新增:
104新增: - name: Tests of Lima, sshocker and pkg/sftp, patched
105新增: if: runner.os != 'Windows'
106新增: run: make test-third-party
107新增:
108新增: # Where the file system folds names (APFS, NTFS), it is the oracle of
109新增: # the read-only names' matching; Linux's matches byte for byte.
110新增: - name: Fuzz read-only name matching against the file system
111新增: if: runner.os != 'Linux'
112新增: shell: bash
113新增: run: GOWORK="$PWD/tests/fuzz/go.work" go test -vet=off -run '^$' -fuzz '^FuzzSameNameFS$' -fuzztime 2m github.com/lima-vm/sshocker/pkg/reversesshfs
删除.github/workflows/test.yml+0 −70
@@ -1,70 +0,0 @@
1删除:name: test
2删除:
3删除:on:
4删除: push:
5删除: pull_request:
6删除:
7删除:# Both jobs only read the repository.
8删除:permissions:
9删除: contents: read
10删除:
11删除:jobs:
12删除: test:
13删除: runs-on: ubuntu-latest
14删除: steps:
15删除: - uses: actions/checkout@v7
16删除: with:
17删除: # The steps below run test.sh from the PR branch. Leaving the checkout
18删除: # token in .git/config would put it within reach of that code.
19删除: persist-credentials: false
20删除:
21删除: # For the tests of the zsh shim (tests/03-install.sh).
22删除: - name: Install zsh
23删除: run: sudo apt-get update && sudo apt-get install -y zsh
24删除:
25删除: - name: Syntax check
26删除: run: |
27删除: for f in agent-vm.sh lib/*.sh agent-vm.setup.sh runtime.example.sh test.sh tests/*.sh test-e2e.sh install.sh release.sh; do
28删除: echo "bash -n $f"
29删除: bash -n "$f"
30删除: done
31删除: # Served as `curl | sh`: plain sh, not bash.
32删除: echo "sh -n www/public/install.sh"
33删除: sh -n www/public/install.sh
34删除:
35删除: - name: Test suite
36删除: run: ./test.sh
37删除:
38删除: # macOS still ships bash 3.2, which errors on empty array expansion
39删除: # under `set -u`.
40删除: # Modern bash does not, so a 3.2 run is the only way to catch it in CI.
41删除: # With perl, which macOS ships too: project-env needs it.
42删除: - name: Test suite on bash 3.2 (what macOS ships)
43删除: run: docker run --rm -v "$PWD:/w" -w /w bash:3.2 sh -c 'apk add --no-cache perl >/dev/null && ./test.sh'
44删除:
45删除: # Windows coverage: the stub suite under Git Bash, which is how agent-vm
46删除: # runs there. No docker (bash 3.2) on a Windows runner, and no
47删除: # real VM anywhere in this workflow (test-e2e.sh stays manual, on every OS).
48删除: test-windows:
49删除: runs-on: windows-latest
50删除: defaults:
51删除: run:
52删除: shell: bash
53删除: steps:
54删除: - uses: actions/checkout@v7
55删除: with:
56删除: # Same reason as above: test.sh runs code from the PR branch.
57删除: persist-credentials: false
58删除:
59删除: - name: Syntax check
60删除: run: |
61删除: for f in agent-vm.sh lib/*.sh agent-vm.setup.sh runtime.example.sh test.sh tests/*.sh test-e2e.sh install.sh release.sh; do
62删除: echo "bash -n $f"
63删除: bash -n "$f"
64删除: done
65删除: # Served as `curl | sh`: plain sh, not bash.
66删除: echo "sh -n www/public/install.sh"
67删除: sh -n www/public/install.sh
68删除:
69删除: - name: Test suite (Git Bash, stub limactl)
70删除: run: ./test.sh
修改.github/workflows/www.yml+11 −6看文件
@@ -19,15 +19,16 @@ permissions:
1919jobs:
2020 build:
2121 runs-on: ubuntu-latest
22新增: timeout-minutes: 15
2223 defaults:
2324 run:
2425 working-directory: www
2526 steps:
26删除: - uses: actions/checkout@v7
27新增: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
2728 with:
2829 persist-credentials: false
2930
30删除: - uses: actions/setup-node@v7
31新增: - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
3132 with:
3233 node-version: 24
3334 cache: npm
@@ -49,15 +50,19 @@ jobs:
4950 # does not fail the build, it just quietly serves the github.io URL.
5051 run: test -f dist/CNAME
5152
52删除: - uses: actions/upload-pages-artifact@v5
53新增: - uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5
5354 with:
5455 path: www/dist
5556
5657 deploy:
57删除: # A pull request builds but does not publish.
58删除: if: github.event_name != 'pull_request'
58新增: # Only main publishes: a pull request builds only, and a manual run
59新增: # (workflow_dispatch) from another branch would otherwise deploy that
60新增: # branch's site. The github-pages environment should restrict deployment
61新增: # branches to main too (RELEASING.md).
62新增: if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
5963 needs: build
6064 runs-on: ubuntu-latest
65新增: timeout-minutes: 15
6166 # On the deploy job only: at workflow level, a pull request build would
6267 # share the group and replace a pending deploy. The in-progress deploy is
6368 # never cancelled; a newer pending one replaces an older pending one.
@@ -72,4 +77,4 @@ jobs:
7277 url: ${{ steps.deploy.outputs.page_url }}
7378 steps:
7479 - id: deploy
75删除: uses: actions/deploy-pages@v5
80新增: uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5
修改.gitignore+10 −0看文件
@@ -2,3 +2,13 @@
22.claude
33node_modules
44dist
5新增:/_output
6新增:# Scratch checkouts and patch files for working on patches/. third_party/
7新增:# holds what is built.
8新增:/lima/
9新增:/lima-pr/
10新增:/tmp/
11新增:/sshocker-append-fix.patch
12新增:# Built by the Makefile, embedded in the binary.
13新增:/internal/limaembed/assets/*
14新增:!/internal/limaembed/assets/README
新增.shellcheckrc+2 −0看文件
@@ -0,0 +1,2 @@
1新增:# `CDPATH= cd` is meant: an empty value for that command only.
2新增:disable=SC1007
修改CHANGELOG.md+170 −0看文件
@@ -1,5 +1,173 @@
11# Changelog
22
3新增:## 0.3.0
4新增:
5新增:agent-vm 0.3 is one Go binary with Lima built in (see PLAN_0.3.0.md). The
6新增:bash version (`agent-vm.sh`, `lib/`) is gone from the repository: 0.2.x
7新增:stays on its tags. Changes against 0.2.1:
8新增:
9新增:### Added
10新增:
11新增:- Network isolation: a VM reaches the internet, not your machine (its
12新增: loopback, where the other VMs' ports are forwarded, and its own
13新增: addresses) nor your local networks. `~/.agent-vm/network` opens holes,
14新增: one per line: `allow 192.168.1.10:5432`, `allow 10.0.0.0/8`, `allow
15新增: localhost:11434` (a service on your machine's loopback, which the VM
16新增: reaches at 192.168.5.2). `domain github.com` lines make those domains
17新增: and their subdomains the only names of the internet the VMs reach:
18新增: other names do not resolve, and an address is reachable once agent-vm's
19新增: DNS gave it for one of them. A line agent-vm cannot read stops a start,
20新增: and `setup`, with the line named; `doctor` checks the file.
21新增: `AGENT_VM_UNSAFE_OPEN_NETWORK=1` turns isolation off. QEMU VMs get their own network stack, as vz ones have, so
22新增: this holds for both.
23新增:- A desktop notification when a port the VM listens on is forwarded to your
24新增: machine, and when it is not because a program of yours uses it.
25新增: `AGENT_VM_NOTIFY=0` turns them off.
26新增:- Ports 32768-60999 are no longer forwarded: the guest gives them to
27新增: programs asking for any free port (Chromium's DevTools port, language
28新增: servers...), which nobody opens from the host.
29新增:- Files your machine runs without asking are guarded: when the VM writes,
30新增: creates, renames or removes `.envrc`, `.vscode/tasks.json`,
31新增: `.vscode/settings.json`, `.vscode/launch.json`, `.pre-commit-config.yaml`,
32新增: `lefthook.yml` or `mise.toml`, a dialog asks you first (allowed until the
33新增: VM stops; a no holds a minute). Without a dialog to show, the write is
34新增: refused and a notification says so. `~/.agent-vm/guarded` adds paths, one
35新增: per line, `!path` removes one of the defaults, and `*.ext` guards an
36新增: extension. `AGENT_VM_GUARDED_WRITES=deny` refuses them all without asking.
37新增:- On a Windows host, `*.library-ms`, `*.searchConnector-ms`, `*.lnk`, `*.url`,
38新增: `*.scf` and `desktop.ini` are guarded too (names Windows makes into them,
39新增: like `a.lnk.` or `a.lnk:stream`, included): Explorer sends your NTLM hash to
40新增: the server they name when it shows them (CVE-2025-24054, CVE-2025-50154,
41新增: CVE-2025-59214). There is no dialog on Windows yet: the writes are refused.
42新增:- Windows, natively (experimental): host
43新增: paths are kept as C:/Users/me/proj, drive-aware, and the VM sees them as
44新增: 0.2 did, /c/Users/me/proj, under the same VM names. The volumes file takes
45新增: C:/x and C:\x, and 0.2's /c/x, in its sources and project filters. QEMU's
46新增: folder goes on PATH at every start, a failed start says when the Windows
47新增: Hypervisor Platform feature is off, and `install` gives the PATH line in
48新增: PowerShell's syntax. QEMU 7.2 or later is needed, for the VM's own
49新增: network stack.
50新增:- Releases have Windows binaries too (amd64, arm64), signed when
51新增: `release.sh` is given a code-signing certificate.
52新增:
53新增:### Changed
54新增:
55新增:- A port the VM listens on is no longer forwarded when a program of your
56新增: machine uses it: on macOS, the forward took that program's local
57新增: connections (a Lima patch).
58新增:- A VM name too long for Lima's socket paths under your home is cut in its
59新增: folder part, the hash of the whole path kept: such a folder could not get
60新增: a VM.
61新增:- The binary leaves out the formats of yq that Lima does not use: about 10%
62新增: smaller.
63新增:
64新增:- Lima is built in, with the patches that keep `.git` read-only and fix the
65新增: SFTP server (patches/README.md): no limactl to install, no Lima build to
66新增: download, and `setup` no longer offers one. A start never asks about a
67新增: Lima that cannot protect `.git`: `info`'s `security_questions` no longer
68新增: has `lima` or `lima-unknown`, `doctor`'s Lima section says which Lima is
69新增: built in, and `help` says so.
70新增:- The VMs live in `~/.agent-vm/lima` (`AGENT_VM_LIMA_HOME` overrides), apart
71新增: from your own Lima's. The first command that needs them offers to move
72新增: 0.2's from `~/.lima` (or `$LIMA_HOME`), once, stopping running ones first:
73新增: they keep their shares and settings. Lima's `_config` there is not taken.
74新增: `AGENT_VM_LIMA_HOME` may not be your own Lima's home.
75新增:- VM names lose their `agent-vm-` prefix, needed only while they shared
76新增: `~/.lima` with your own VMs: `proj-1a2b3c4d`, and `base` for the base
77新增: template. 0.2's VMs are renamed as they are moved. This gives back to
78新增: folder names the room `~/.agent-vm/lima` takes in Lima's socket paths
79新增: (104 characters on macOS). `stop` and `rm` take any name `list` shows.
80新增:- With `--unsafe-writable-git`, the shares stay reverse-sshfs, served by the
81新增: built-in SFTP server confined to them, without the read-only names; 0.2
82新增: went back to Lima's default mount type.
83新增:- A VM from a base built by 0.1.0 is no longer migrated in place: a start
84新增: refuses it and says to run `setup`, then `--reset`.
85新增:- `install` links the agent-vm binary (a copy where no link can be made,
86新增: replaced by the next `install`); `uninstall` removes it. Both replace or
87新增: remove 0.2's link to `agent-vm.sh`.
88新增:- A release is a tarball per platform (macOS and Linux, arm64 and
89新增: x86_64): the binary and `agent-vm.sh`, which runs it. The curl installer
90新增: takes the one of the machine; its `--version` and `--git` work as in
91新增: 0.2. In a clone, `agent-vm.sh` builds agent-vm first (Go, and on macOS
92新增: the Xcode command line tools), and again after a `git pull`. The Linux
93新增: binaries are built without cgo: the VMs' DNS lookups go through Go's
94新增: resolver there.
95新增:- What 0.2 left keeps working: its link to `agent-vm.sh` on the PATH runs
96新增: the new binary (built first in a clone), and a shell rc that sources
97新增: `agent-vm.sh` gets an `agent-vm` function running it. Running the curl
98新增: installer again, or `install`, replaces the link with one to the binary.
99新增:- `agent-vm.sh` sourced from a shell rc no longer loads agent-vm into the
100新增: shell: it defines a function running it. `install` says the line can go.
101新增:- `version --min`'s "Update it" line is always the curl installer's, until
102新增: 0.3's install methods are settled.
103新增:- agent-vm makes and starts no VM while Lima's `default.yaml` or
104新增: `override.yaml` is in `~/.agent-vm/lima/_config`: they add to every VM's
105新增: config (shares, mount type), which agent-vm sets alone. `doctor` names
106新增: them. Its `base.yaml` is not mixed into the base VM either.
107新增:- Messages that named `limactl list` name `agent-vm list`.
108新增:- `--tty` also gives the command a terminal when only stdin is one.
109新增:- `help` says how deep the git check looks: the repository holding each
110新增: share, and those up to two folders below it, 50 per share.
111新增:- A VM config Lima refuses is reported with Lima's reason, and `--reset`.
112新增:- `env get` and `project-env get` read non-ASCII values as written (`café`
113新增: came back mangled), and as the VM sources the file: CRs ending lines are
114新增: dropped, inside quoted values too; a value with a CR left in it is
115新增: refused.
116新增:- A volume's project filter with non-ASCII characters matches as written.
117新增:- A project or volume path with `&`, `<` or `>` is shared as is (they came
118新增: out escaped, as another folder). One with `{{`, which Lima expands as a
119新增: template, or bytes that are not UTF-8 is refused: Lima would share
120新增: another folder. agent-vm checks that Lima keeps every share as written.
121新增:- `doctor` and `info` only look: they no longer move 0.2's VMs (which stops
122新增: running ones); `doctor` says when some are still to move.
123新增:- A single-file volume that is a symlink (stow's dotfiles) reaches the VM.
124新增:- When the first sshfs mount fails, Lima's retry keeps the share's options
125新增: (`cache=no`) instead of replacing them (a Lima patch).
126新增:- A running VM with more read-only names than the project now needs (a
127新增: hooks folder moved) keeps running: extra names protect more, and the next
128新增: boot drops them. 0.2 asked to restart it, and aborted without a terminal.
129新增:
130新增:### Security
131新增:
132新增:- A failed `setup` prints the end of its log without escape sequences: the
133新增: log holds what the VM printed.
134新增:- A hooks folder name declined at start no longer hides the other risks
135新增: under it: with `core.hooksPath tools/hooks` and `core.fsmonitor
136新增: tools/fsmon.sh`, a no to making every `tools` read-only now lists
137新增: fsmonitor too.
138新增:- A git config file in a folder with non-ASCII characters is found: git
139新增: quotes such paths, and 0.2 missed them.
140新增:- A git setting whose path goes through a symlink in the project, halfway
141新增: along a chain of links, is now caught: 0.2 resolved the whole path at
142新增: once and never saw that link, which the VM could retarget.
143新增:- A hooks folder in a writable volume inside the repository (a volume on
144新增: `.husky` with `core.hooksPath .husky/_`) is warned about and asked: no
145新增: read-only name covers it. 0.2 made `_` read-only and left
146新增: `.husky/pre-commit` writable.
147新增:- More git settings that name a command are checked: `mergetool`,
148新增: `difftool`, `browser` and `man` tool paths, `guitool.*.cmd`,
149新增: `trailer.*.cmd`, `submodule.*.update`, `remote.*.uploadpack` and
150新增: `receivepack`, `tar.*.command`, `instaweb.httpd`, the `sendemail`
151新增: commands and `gpg.ssh.defaultKeyCommand`.
152新增:- Your own Lima home (`~/.lima` or `$LIMA_HOME`) is refused as a project,
153新增: as in 0.2: its `_config/user` key logs into your other Lima VMs.
154新增:- A git setting's command that names a file without a `/` (`alias.b =
155新增: !bash build.sh`) is checked against the shares: it runs from the top of
156新增: the repository, which the VM can write.
157新增:- On macOS, a read-only name is matched as APFS matches names: whatever
158新增: the Unicode normalization (`é` or `e` and a combining accent) and with
159新增: full case folding (`ß` as `ss`). 0.2 compared case only, so a hooks
160新增: folder with such a name could be written under another spelling.
161新增:- What the VM printed during `setup` (its window and, on failure, its log)
162新增: is shown without any control character: bell, backspace, and the C1
163新增: controls some terminals take for escape sequences, not only ESC.
164新增:- No VM starts with a share served by anything but the built-in SFTP
165新增: server over reverse-sshfs, the one confined to its folder, whatever the
166新增: options: Lima's default SFTP server lets the VM read (or write) any file
167新增: you can. 0.2 allowed it with `.git` left writable, and refused a writable
168新增: share from Lima's `_config` under `--readonly` only after the VM had
169新增: booted and got your env.
170新增:
3171## 0.2.1
4172
5173### Added
@@ -119,6 +287,8 @@
119287 of the last three are refused as a project: `cd ~ && agent-vm shell`
120288 shared `~/.ssh` and every dotfile read-write, and from inside agent-vm's
121289 folder the VM could change the files the host runs next.
290新增: `--unsafe-disable-security-prompts` shares agent-vm's own directory
291新增: anyway, with a warning, to work on agent-vm from a clone.
122292- `--readonly` on a stopped VM that last ran writable makes it read-only
123293 before it boots. It used to start it writable, then stop it and apply the
124294 change.
删除CNAME+0 −1
@@ -1 +0,0 @@
1删除:www.agent-vm.org
文件末尾没有换行
新增Makefile+125 −0看文件
@@ -0,0 +1,125 @@
1新增:# agent-vm 0.3, the Go binary, with Lima built in from third_party/.
2新增:#
3新增:# make _output/bin/agent-vm, with the guest agent and templates
4新增:# make install build it, then link it onto the PATH (AGENT_VM_BIN_DIR
5新增:# to choose where; ~/.local/bin by default)
6新增:# make limactl Lima's own limactl from third_party/, for debugging
7新增:# make test the Go tests
8新增:# make check-windows the Windows build and tests compile and vet, from any OS
9新增:# make test-third-party the tests of the modules in third_party/, patched
10新增:# make check-third-party third_party/ is upstream plus patches/, nothing else
11新增:
12新增:GO ?= go
13新增:GOOS ?= $(shell $(GO) env GOOS)
14新增:GOARCH ?= $(shell $(GO) env GOARCH)
15新增:# The tag when HEAD has one, else the next release's: a build of the 0.3
16新增:# branch is 0.3.0-dev, not 0.2.0-N after the last tag (version --min).
17新增:NEXT_VERSION := 0.3.0
18新增:VERSION ?= $(shell t=$$(git describe --tags --match 'v[0-9]*' --exact-match --dirty=.m 2>/dev/null) && echo "$$t" | sed 's/^v//' || \
19新增: echo "$(NEXT_VERSION)-dev.$$(git rev-parse --short HEAD 2>/dev/null || echo unknown)")
20新增:LIMA_VERSION := $(shell awk '$$1 == "lima" { print $$4 }' third_party/SOURCES)
21新增:
22新增:ifeq ($(GOARCH),amd64)
23新增:GUEST_ARCH := x86_64
24新增:else ifeq ($(GOARCH),arm64)
25新增:GUEST_ARCH := aarch64
26新增:else
27新增:GUEST_ARCH := $(GOARCH)
28新增:endif
29新增:ifeq ($(GOOS),windows)
30新增:EXE := .exe
31新增:endif
32新增:
33新增:ASSETS := internal/limaembed/assets
34新增:LDFLAGS := -s -w \
35新增: -X github.com/sylvinus/agent-vm/internal/version.Version=$(VERSION) \
36新增: -X github.com/lima-vm/lima/v2/pkg/version.Version=$(LIMA_VERSION)
37新增:# yq only edits Lima's YAML here: without its other formats (Lua, HCL, TOML,
38新增:# XML...), 10% smaller. Tests run with the same tags.
39新增:TAGS := yq_noxml,yq_nolua,yq_noini,yq_nohcl,yq_notoml,yq_noprops,yq_nocsv,yq_nouri,yq_nobase64,yq_nosh,yq_noshell
40新增:# cgo on macOS only, where vz and Lima's file watcher need it. On Linux the
41新增:# hostagent's DNS server uses Go's resolver (Lima builds it with the
42新增:# system's), and the binary cross-compiles with no C compiler.
43新增:ifeq ($(GOOS),darwin)
44新增:CGO_ENABLED ?= 1
45新增:else
46新增:CGO_ENABLED ?= 0
47新增:endif
48新增:GO_BUILD := CGO_ENABLED=$(CGO_ENABLED) $(GO) build -trimpath -tags $(TAGS) -ldflags "$(LDFLAGS)"
49新增:
50新增:.PHONY: all agent-vm install limactl assets test test-go check-windows test-third-party check-third-party fuzz clean
51新增:
52新增:all: agent-vm
53新增:
54新增:agent-vm: assets
55新增: $(GO_BUILD) -o _output/bin/agent-vm$(EXE) ./cmd/agent-vm
56新增:ifeq ($(GOOS),darwin)
57新增: codesign -f -v --entitlements third_party/lima/vz.entitlements -s - _output/bin/agent-vm
58新增:endif
59新增:
60新增:# For developers: the binary install puts on the PATH, with its own
61新增:# wording, replacement of earlier installs and next steps.
62新增:install: agent-vm
63新增: ./_output/bin/agent-vm$(EXE) install
64新增:
65新增:limactl:
66新增: $(GO_BUILD) -o _output/bin/limactl$(EXE) github.com/lima-vm/lima/v2/cmd/limactl
67新增: mkdir -p _output/share/lima
68新增: CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) $(GO) build -trimpath -ldflags "-s -w" \
69新增: -o _output/share/lima/lima-guestagent.Linux-$(GUEST_ARCH) github.com/lima-vm/lima/v2/cmd/lima-guestagent
70新增: rm -rf _output/share/lima/templates && cp -R third_party/lima/templates _output/share/lima/templates
71新增:ifeq ($(GOOS),darwin)
72新增: codesign -f -v --entitlements third_party/lima/vz.entitlements -s - _output/bin/limactl
73新增:endif
74新增:
75新增:# The guest agent runs in the Linux guest: built for it, without cgo.
76新增:assets:
77新增: CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) $(GO) build -trimpath \
78新增: -ldflags "-s -w -X github.com/lima-vm/lima/v2/pkg/version.Version=$(LIMA_VERSION)" \
79新增: -o $(ASSETS)/lima-guestagent.Linux-$(GUEST_ARCH) github.com/lima-vm/lima/v2/cmd/lima-guestagent
80新增: gzip -9 -n -f $(ASSETS)/lima-guestagent.Linux-$(GUEST_ARCH)
81新增: rm -rf $(ASSETS)/templates && cp -R third_party/lima/templates $(ASSETS)/templates
82新增:
83新增:test: test-go
84新增:
85新增:test-go:
86新增: $(GO) test -tags $(TAGS) . ./cmd/... ./internal/...
87新增:
88新增:# The Windows build and its tests compile and vet, from any OS. The Windows
89新增:# paths' logic is tested everywhere (paths.Windows); the tests themselves
90新增:# run on Windows in CI (windows-latest).
91新增:check-windows:
92新增: GOOS=windows GOARCH=amd64 $(GO) vet -tags $(TAGS) . ./cmd/... ./internal/...
93新增: GOOS=windows GOARCH=arm64 $(GO) vet -tags $(TAGS) . ./cmd/... ./internal/...
94新增:
95新增:# From this module, so that each library is built with the others patched.
96新增:# Lima's MCP packages and sshocker's command are not part of agent-vm (-e:
97新增:# listing them needs sums nothing built here uses; grep keeps them out of
98新增:# the tests).
99新增:test-third-party:
100新增: $(GO) test -vet=off -race github.com/pkg/sftp/...
101新增: $(GO) test -race github.com/lima-vm/sshocker/pkg/...
102新增: $(GO) test $$($(GO) list -e github.com/lima-vm/lima/v2/pkg/... | grep -v /mcp)
103新增: $(GO) test github.com/containers/gvisor-tap-vsock/pkg/...
104新增:
105新增:check-third-party:
106新增: scripts/third-party-sync all --check
107新增:
108新增:# Each fuzzer for FUZZTIME (their seeds run with the tests). The vendored
109新增:# sshocker's through tests/fuzz/go.work, which makes it fuzzable.
110新增:FUZZTIME ?= 1m
111新增:FUZZ = github.com/lima-vm/sshocker/pkg/reversesshfs github.com/pkg/sftp ./internal/env ./internal/gitguard \
112新增: ./internal/mounts ./internal/paths ./internal/runscript ./internal/ui ./internal/vmname
113新增:fuzz:
114新增: @set -e; for pkg in $(FUZZ); do \
115新增: case $$pkg in ./*) work=off ;; *) work=$(CURDIR)/tests/fuzz/go.work ;; esac; \
116新增: fs=$$(GOWORK=$$work $(GO) test -vet=off -list '^Fuzz' $$pkg) || { echo "$$fs"; exit 1; }; \
117新增: for f in $$(echo "$$fs" | grep '^Fuzz'); do \
118新增: echo "== $$pkg $$f"; \
119新增: GOWORK=$$work $(GO) test -vet=off -run '^$$' -fuzz "^$$f$$" -fuzztime $(FUZZTIME) $$pkg; \
120新增: done; \
121新增: done
122新增:
123新增:clean:
124新增: rm -rf _output
125新增: find $(ASSETS) -mindepth 1 ! -name README -exec rm -rf {} +
新增NOTICE+25 −0看文件
@@ -0,0 +1,25 @@
1新增:agent-vm
2新增:Copyright (c) 2026 Sylvain Zimmer (MIT, see LICENSE)
3新增:
4新增:agent-vm is built from, and its release binaries contain, the following
5新增:projects. Their licenses and notices are in THIRD_PARTY_LICENSES, and
6新增:`agent-vm licenses` prints them.
7新增:
8新增: Lima https://github.com/lima-vm/lima Apache-2.0
9新增: sshocker https://github.com/lima-vm/sshocker Apache-2.0
10新增: gvisor-tap-vsock https://github.com/containers/gvisor-tap-vsock Apache-2.0
11新增: pkg/sftp https://github.com/pkg/sftp BSD-2-Clause
12新增:
13新增:The third_party/ folder holds each of these as its upstream source at the
14新增:commit recorded in third_party/SOURCES, with the patches in patches/ applied
15新增:and nothing else (scripts/third-party-sync rebuilds it, and CI checks it).
16新增:
17新增:Modifications, as section 4(b) of the Apache License 2.0 requires: the files
18新增:of Lima, sshocker and gvisor-tap-vsock that the patches in patches/lima,
19新增:patches/sshocker and patches/gvisor-tap-vsock change have been modified by
20新增:agent-vm. The patches are the complete statement of the changes; their
21新增:purpose is described in patches/README.md. pkg/sftp is modified the same way
22新增:(patches/sftp), under its BSD-2-Clause license.
23新增:
24新增:The NOTICE of Lima is reproduced in THIRD_PARTY_LICENSES, as section 4(d) of
25新增:the Apache License 2.0 asks.
修改README.md+12 −10看文件
@@ -2,18 +2,17 @@
22
33Run AI coding agents in a disposable Linux VM per project, with permissions bypassed. The VM gets your project directory and nothing else of yours: no SSH keys, no browser sessions, no rest of your disk.
44
5删除:Built on [Lima](https://lima-vm.io/). Ships dev tools, Docker, headless Chromium with [Chrome DevTools MCP](https://github.com/ChromeDevTools/chrome-devtools-mcp), and [Claude Code](https://claude.ai/code), [OpenCode](https://github.com/anomalyco/opencode), [Codex CLI](https://github.com/openai/codex), [Mistral Vibe](https://docs.mistral.ai/vibe/code/cli/install-setup) and, opt-in, [Pi](https://pi.dev). macOS, Linux, and Windows (Git Bash, experimental).
5新增:One binary with [Lima](https://lima-vm.io/) built in. Ships dev tools, Docker, headless Chromium with [Chrome DevTools MCP](https://github.com/ChromeDevTools/chrome-devtools-mcp), and [Claude Code](https://claude.ai/code), [OpenCode](https://github.com/anomalyco/opencode), [Codex CLI](https://github.com/openai/codex), [Mistral Vibe](https://docs.mistral.ai/vibe/code/cli/install-setup) and, opt-in, [Pi](https://pi.dev). macOS and Linux; Windows is experimental.
66
77**Documentation: [www.agent-vm.org](https://www.agent-vm.org/)** · Chat: [#agent-vm:matrix.org](https://matrix.to/#/#agent-vm:matrix.org)
88
99## Install
1010
1111```bash
12删除:git clone https://github.com/sylvinus/agent-vm.git
13删除:cd agent-vm && ./agent-vm.sh install
12新增:curl -fsSL https://www.agent-vm.org/install.sh | sh
1413```
1514
16删除:`git pull` in the clone updates it. Or `curl -fsSL https://www.agent-vm.org/install.sh | sh`, or `brew install sylvinus/tap/agent-vm`. See [Install](https://www.agent-vm.org/#install) for prerequisites and Windows.
15新增:Or `brew install sylvinus/tap/agent-vm`. From a clone, with Go (and on macOS the Xcode command line tools): `./agent-vm.sh install` builds it and links it onto your `PATH`; after a `git pull`, run it again. See [Install](https://www.agent-vm.org/#install) for prerequisites.
1716
1817## Use
1918
@@ -36,19 +35,22 @@ Everyday use: [Usage](https://www.agent-vm.org/#usage). Every command, option, f
3635
3736The agent is root in its VM and has the network. What it can reach on your machine is what crosses the shares:
3837
39删除:- Every `.git` and `.hg`, and the folder of a `core.hooksPath` inside the project, are read-only for the VM with a Lima that has `sshfs.readonlyNames`, which `agent-vm setup` offers to install. Before a VM boots, agent-vm stops on what it cannot protect and asks whether to go on: [Protecting .git](https://www.agent-vm.org/#git).
38新增:- Every `.git` and `.hg`, and the folder of a `core.hooksPath` inside the project, are read-only for the VM: the file server built into agent-vm enforces it on your machine. Before a VM boots, agent-vm stops on what it cannot protect and asks whether to go on: [Protecting .git](https://www.agent-vm.org/#git).
39新增:- Files your machine runs without asking (`.envrc`, `.vscode/tasks.json`, `.pre-commit-config.yaml`...) are guarded: when the VM writes one, a dialog asks you first, and the write is refused where none can be shown. Add or remove paths in `~/.agent-vm/guarded`.
4040- The agent writes the project folder: on your machine, open it in your editor and use git there, and run everything else in the VM. Open agent-vm projects in VS Code's Restricted Mode, and never connect an editor to the VM over SSH (Remote-SSH trusts the VM with your machine: [SSH from your machine](https://www.agent-vm.org/#ssh-from-your-machine)). Editors, agents, commit hooks and commands you run on the host can run code the agent wrote: [What else reads the project](https://www.agent-vm.org/#what-else-on-your-machine-reads-the-project).
41删除:- The VM reaches your machine's loopback and prints to your terminal: [Security](https://www.agent-vm.org/#security).
41新增:- The VM reaches the internet, not your machine nor your local network: what it may reach there, or the only domains it may reach, go in `~/.agent-vm/network`. A port the VM listens on is forwarded to your machine's loopback, unless something there uses it already or it is in 32768-60999, the range the guest picks random ports from.
4242
4343## Development
4444
4545```bash
46删除:./test.sh # stub limactl, no VM, no network
47删除:docker run --rm -v "$PWD:/w" -w /w bash:3.2 ./test.sh # what macOS ships
48删除:./test-e2e.sh # a real VM, needs Lima
46新增:make # _output/bin/agent-vm
47新增:make test-go # no VM; 0.2's recorded behavior where it is compared
48新增:go test -tags e2e ./internal/vm/ ./internal/cli/ # real VMs
49新增:make check-third-party test-third-party # Lima, sshocker, pkg/sftp, gvisor-tap-vsock: upstream + patches/
50新增:make fuzz FUZZTIME=5m # each fuzzer; their seeds run with the tests
4951```
5052
51删除:Layout and guidelines: [Contribute](https://www.agent-vm.org/#contribute). Releases: `./release.sh X.Y.Z --dry-run`, then without it. The website is in [`www/`](www/README.md). Changes: [CHANGELOG.md](CHANGELOG.md).
53新增:Releases: [RELEASING.md](RELEASING.md). Plan: [PLAN_0.3.0.md](PLAN_0.3.0.md). The website is in [`www/`](www/README.md). Changes: [CHANGELOG.md](CHANGELOG.md).
5254
5355## License
5456
新增RELEASING.md+82 −0看文件
@@ -0,0 +1,82 @@
1新增:# Releasing agent-vm
2新增:
3新增:`release.sh` checks a commit, tags it, builds a tarball per platform from the tag, publishes them
4新增:on GitHub with their `SHA256SUMS`, and prints the Homebrew lines. It runs on a Mac: the macOS
5新增:binaries need its SDK and `codesign`; Linux and Windows are cross-built there. It bumps and
6新增:commits nothing.
7新增:
8新增:Needs: git, make, Go, the Xcode command line tools, `gh` logged in, and for signed Windows
9新增:binaries `osslsigncode` (`brew install osslsigncode`).
10新增:
11新增:## A release
12新增:
13新增:1. In an ordinary commit on the branch: `NEXT_VERSION := X.Y.Z` in the Makefile, and CHANGELOG.md's
14新增: `## Unreleased` renamed `## X.Y.Z`. Push it, and wait for CI (the `go` workflow) to pass on it.
15新增:2. On the Mac, in a clean clone of that commit:
16新增:
17新增: ```bash
18新增: ./release.sh X.Y.Z --dry-run # every check and the builds, nothing changed
19新增: ./release.sh X.Y.Z
20新增: ```
21新增:
22新增: - Windows binaries, signed: `AGENT_VM_WINDOWS_PFX=<certificate and key, .pfx>` and
23新增: `AGENT_VM_WINDOWS_PFX_PASS=<its password>`. Without, they go out unsigned, with a warning.
24新增: - Homebrew: `AGENT_VM_TAP=<clone of the tap>` updates `Formula/agent-vm.rb` there (each
25新增: platform's url and sha256) and prints the commands to commit it.
26新增: - A run that tagged and then failed is resumed by running it again.
27新增:3. In a commit after it: `NEXT_VERSION` to the next version, and a new `## Unreleased` section.
28新增:
29新增:## 0.3.0 from its branch, main staying on 0.2.1
30新增:
31新增:`main` holds 0.2.1, and the site, `www/public/install.sh` included, is deployed from it. 0.3.0 can
32新增:go out from the `0.3.0` branch for those who ask for it, while everyone else keeps 0.2.1.
33新增:
34新增:1. On `main`, the new installer only: it takes the tarball of the machine, as 0.3 publishes them,
35新增: and still installs 0.2.x releases (one tarball for all). Without it, nothing installs 0.3.0.
36新增:
37新增: ```bash
38新增: git checkout main
39新增: git checkout 0.3.0 -- www/public/install.sh
40新增: git commit -m "installer: per-platform release tarballs"
41新增: git push # the www workflow deploys it
42新增: ```
43新增:
44新增: Then check that `curl -fsSL https://www.agent-vm.org/install.sh | sh` still installs 0.2.1.
45新增:
46新增:2. On `0.3.0`: CHANGELOG.md's `## Unreleased` renamed `## 0.3.0` (`NEXT_VERSION` is already
47新增: 0.3.0), committed and pushed; CI passes on it.
48新增:
49新增:3. On the Mac, from the `0.3.0` branch:
50新增:
51新增: ```bash
52新增: RELEASE_BRANCH=0.3.0 ./release.sh 0.3.0 --not-latest --dry-run
53新增: RELEASE_BRANCH=0.3.0 ./release.sh 0.3.0 --not-latest
54新增: ```
55新增:
56新增: `--not-latest` publishes it without making it GitHub's latest release: the installer's default
57新增: stays 0.2.1. It also leaves the Homebrew formula alone, `AGENT_VM_TAP` or not.
58新增:
59新增:4. Check: `gh release view v0.3.0` shows it; a plain install still gives 0.2.1; on a test machine,
60新增: `curl -fsSL https://www.agent-vm.org/install.sh | sh -s -- --version 0.3.0` gives 0.3.0.
61新增:
62新增:5. Tell people how to try it:
63新增:
64新增: ```bash
65新增: curl -fsSL https://www.agent-vm.org/install.sh | sh -s -- --version 0.3.0
66新增: # or, from a clone (Go needed)
67新增: git checkout v0.3.0 && ./agent-vm.sh install
68新增: ```
69新增:
70新增: Their 0.2 setup carries over: the first command offers to move their VMs, and what 0.2 left on
71新增: their PATH or in their shell rc runs 0.3 (CHANGELOG.md).
72新增:
73新增:A 0.2.x release from `main` meanwhile is made with `main`'s own `release.sh`, as before. It
74新增:becomes the latest release, which the installer then gives by default, as wanted.
75新增:
76新增:## Making 0.3 the default
77新增:
78新增:1. Merge `0.3.0` into `main`: the site then documents 0.3.
79新增:2. `gh release edit v0.3.0 --latest`, or release the next 0.3.x without `--not-latest`.
80新增:3. The Homebrew formula: one url and sha256 per platform (`on_macos`/`on_linux`,
81新增: `on_arm`/`on_intel`), installing the tarball's `agent-vm`. From then on, `AGENT_VM_TAP` keeps it
82新增: up to date at each release.
新增THIRD_PARTY_LICENSES+8010 −0看文件

改动太大,不在线显示。

修改agent-vm.setup.sh+4 −4看文件
@@ -56,7 +56,7 @@ INSTALL_CODE_VIBE="${AGENT_VM_INSTALL_CODE_VIBE:-0}"
5656if [[ "$INSTALL_CODE_CLAUDE$INSTALL_CODE_CODEX$INSTALL_CODE_VIBE" == *1* ]]; then
5757 INSTALL_CODE_SERVER=1
5858fi
59删除:# MCP servers wired into every installed agent's config (see lib/setup.sh).
59新增:# MCP servers wired into every installed agent's config (see `agent-vm setup --help`).
6060INSTALL_MCP_CHROME="${AGENT_VM_INSTALL_MCP_CHROME:-1}"
6161INSTALL_MCP_PLAYWRIGHT="${AGENT_VM_INSTALL_MCP_PLAYWRIGHT:-0}"
6262
@@ -419,7 +419,7 @@ code_server_schemas() {
419419}
420420
421421if [[ "$INSTALL_CODE_SERVER" == "1" ]]; then
422删除: # The editor of `agent-vm code` (lib/code.sh). No password here: every VM
422新增: # The editor of `agent-vm code` (internal/cli/code.go). No password here: every VM
423423 # is a copy of this disk, so each one makes its own on first use.
424424 echo "Installing code-server..."
425425 curl -fsSL https://code-server.dev/install.sh | sh
@@ -432,7 +432,7 @@ if [[ "$INSTALL_CODE_SERVER" == "1" ]]; then
432432 code-server "${extensions[@]}" </dev/null
433433 fi
434434 # chat.disableAIFeatures turns off the GitHub Copilot chat and completions
435删除: # that code-server ships (lib/code.sh also disables the extension), and
435新增: # that code-server ships (code.go also disables the extension), and
436436 # chat.mcp.gallery.enabled its MCP gallery. telemetry.*: code-server's
437437 # --disable-telemetry leaves the built-in extensions sending telemetry. The
438438 # editor downloads no JSON schema: setup does, once, into the machine
@@ -485,7 +485,7 @@ if [[ "$INSTALL_CODE_SERVER" == "1" ]]; then
485485 fi
486486 # Codex and Vibe have no setting for it: their extensions start in the mode
487487 # the agent's own config names. These match the flags the command line gets
488删除: # (_agent_vm_agent in agent-vm.sh).
488新增: # (agents in internal/cli/commands.go).
489489 if [[ "$INSTALL_CODE_CODEX" == "1" ]]; then
490490 toml_prepend "$HOME/.codex/config.toml" sandbox_mode '"danger-full-access"'
491491 toml_prepend "$HOME/.codex/config.toml" approval_policy '"never"'
修改agent-vm.sh+45 −1208看文件
@@ -1,1219 +1,56 @@
11#!/usr/bin/env bash
22#
3删除:# agent-vm: Run AI coding agents inside sandboxed Lima VMs
4删除:# Part of https://www.agent-vm.org/
5删除:#
6删除:# Put it on your PATH with `./agent-vm.sh install`. It can also be sourced
7删除:# from bash, which defines agent-vm as a shell function. Commands:
8删除:# `agent-vm help` (lib/help.sh).
9删除:
10删除:# zsh, which 0.1.0's installer had source this file from ~/.zshrc: only a
11删除:# function that runs this file with bash. %x is the file being sourced, :A
12删除:# makes it absolute with links resolved. The eval keeps bash from parsing zsh
13删除:# syntax.
14删除:if [[ -n "${ZSH_VERSION:-}" ]]; then
15删除: eval '
16删除: [[ "${ZSH_EVAL_CONTEXT:-}" == *:file* ]] || exec bash "$0" "$@"
17删除: eval "agent-vm() { command bash ${(qq)${(%):-%x}:A} \"\$@\"; }"
18删除: '
3新增:# Runs agent-vm: in a release, the binary next to this script; in a clone,
4新增:# the one `make` builds, built first when missing or when HEAD moved (a git
5新增:# pull). `agent-vm.sh install` links the binary onto the PATH; the curl
6新增:# installer runs it so.
7新增:#
8新增:# What 0.2 left behind keeps working through it: a link to this file on the
9新增:# PATH (0.2's install), and a shell rc that sources it (0.1 and 0.2), which
10新增:# gets an agent-vm function running it.
11新增:
12新增:# Sourced: nothing below runs in the user's shell, where set -e or exec would
13新增:# end it.
14新增:if [ -n "${ZSH_VERSION:-}" ]; then
15新增: case "${ZSH_EVAL_CONTEXT:-}" in
16新增: *:file*)
17新增: eval '_agent_vm_sh=${(%):-%x}'
18新增: _agent_vm_sh="$(cd -P -- "$(dirname -- "$_agent_vm_sh")" >/dev/null && pwd)/$(basename -- "$_agent_vm_sh")"
19新增: agent-vm() { bash "$_agent_vm_sh" "$@"; }
20新增: return 0 ;;
21新增: esac
22新增:elif [ -n "${BASH_VERSION:-}" ] && [ "${BASH_SOURCE[0]}" != "$0" ]; then
23新增: _agent_vm_sh="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null && pwd)/$(basename -- "${BASH_SOURCE[0]}")"
24新增: agent-vm() { bash "$_agent_vm_sh" "$@"; }
1925 return 0
2026fi
2127
22删除:# Semantic version of this file. Bumped by hand on release. Integrators gate on
23删除:# it via `agent-vm version`; a build with no `version` command predates it.
24删除:AGENT_VM_VERSION="0.2.1"
25删除:
26删除:AGENT_VM_TEMPLATE="agent-vm-base"
27删除:# Overridable, for a test or a second install, without moving HOME (and
28删除:# Lima's state with it). `agent-vm info` publishes it as state_dir=.
29删除:AGENT_VM_STATE_DIR="${AGENT_VM_STATE_DIR:-${HOME}/.agent-vm}"
30删除:
31删除:# Directory of the real agent-vm.sh, symlinks followed: the PATH entry
32删除:# `install` makes is one. By hand, as macOS's readlink has no -f. `CDPATH=`
33删除:# everywhere a relative path is cd'ed to: with it set, cd searches it first.
34删除:_agent_vm_script_dir() {
35删除: local src="$1" dir n=0
36删除: # At most 40 links, as the kernel follows: a loop would never end.
37删除: while [ -L "$src" ] && [ "$n" -lt 40 ]; do
38删除: n=$((n + 1))
39删除: dir="$(CDPATH= cd -P -- "$(dirname "$src")" >/dev/null && pwd)"
40删除: src="$(readlink "$src")"
41删除: case "$src" in
42删除: /*) ;; # absolute: use as-is
43删除: *) src="$dir/$src" ;; # relative: to the link's directory
44删除: esac
45删除: done
46删除: (CDPATH= cd -P -- "$(dirname "$src")" >/dev/null && pwd)
47删除:}
48删除:AGENT_VM_SCRIPT_DIR="$(_agent_vm_script_dir "${BASH_SOURCE[0]:-$0}")"
49删除:if [[ -z "$AGENT_VM_SCRIPT_DIR" ]]; then
50删除: echo "agent-vm: cannot find the directory of agent-vm.sh" >&2
51删除: return 1 2>/dev/null || exit 1
52删除:fi
28新增:set -euo pipefail
5329
54删除:# The rest of agent-vm, one file per concern, sourced like this one. Only
55删除:# functions and settings: nothing runs until a command does. A file that is
56删除:# missing stops here, not half-way through a command.
57删除:for _agent_vm_lib in ui options host vm mounts git runtime env info install doctor help setup code; do
58删除: _agent_vm_lib="$AGENT_VM_SCRIPT_DIR/lib/$_agent_vm_lib.sh"
59删除: if [[ ! -r "$_agent_vm_lib" ]] || ! . "$_agent_vm_lib"; then
60删除: echo "agent-vm: cannot load $_agent_vm_lib" >&2
61删除: unset _agent_vm_lib
62删除: return 1 2>/dev/null || exit 1
63删除: fi
30新增:# This file's folder, through the links to it (0.2's on the PATH).
31新增:src="${BASH_SOURCE[0]:-$0}"
32新增:for _ in 1 2 3 4 5 6 7 8 9 10; do
33新增: [ -L "$src" ] || break
34新增: t="$(readlink "$src")"
35新增: case "$t" in /*) src="$t" ;; *) src="$(dirname "$src")/$t" ;; esac
6436done
65删除:unset _agent_vm_lib
66删除:
67删除:# --- starting a project's VM --------------------------------------------------
68删除:
69删除:# The security checks of a start, for the project <dir> and its VM <vm>. Reads the caller's
70删除:# vm_up, scratch and rdonly, and sets its protect_git, ro_names and
71删除:# hooks_notes. With vm_up set (a running VM that keeps running), the risks are
72删除:# printed and nothing is asked. Fails when the start must stop.
73删除:_agent_vm_start_checks() {
74删除: local host_dir="$1" vm_name="$2" lima_st=0
75删除: protect_git="" ro_names="" hooks_notes=""
76删除:
77删除: # Every .git read-only for the guest, when this Lima can enforce it and it
78删除: # was not turned off. The mounts built afterwards, on every path, follow the
79删除: # answer. A Lima that cannot, with shares left writable and nobody having
80删除: # asked for a writable .git, is a risk to accept. One whose answer could not
81删除: # be read stops the start: taking it for a no would drop the protection of
82删除: # the VM.
83删除: if [[ -n "$scratch" ]]; then
84删除: :
85删除: elif _agent_vm_writable_git_optout; then
86删除: _agent_vm_writable_git_warning >&2
87删除: else
88删除: _agent_vm_lima_protects_git || lima_st=$?
89删除: if [[ "$lima_st" == 0 ]]; then
90删除: protect_git=1
91删除: elif [[ -n "$rdonly" ]]; then
92删除: :
93删除: elif [[ "$lima_st" == 2 ]]; then
94删除: echo "Error: cannot tell whether this Lima keeps .git read-only: 'limactl validate' gave no answer agent-vm knows ('agent-vm doctor' shows more)." >&2
95删除: echo " --readonly, or --unsafe-writable-git to accept a writable .git, still starts the VM." >&2
96删除: return 1
97删除: elif _agent_vm_unprotected_mount_is_sshfs "$vm_name"; then
98删除: # Asked below, with the rest of the disk.
99删除: :
100删除: elif [[ -n "$vm_up" ]]; then
101删除: echo "Warning: this Lima cannot keep .git read-only, so the VM can write .git ('agent-vm doctor' says more)." >&2
102删除: else
103删除: _agent_vm_git_protection_hint | _agent_vm_box "Lima cannot keep .git read-only"
104删除: if ! _agent_vm_confirm_unsafe; then
105删除: echo "Aborted. Install that Lima build, or use --readonly; --unsafe-writable-git accepts a writable .git." >&2
106删除: return 1
107删除: fi
108删除: fi
109删除: fi
110删除:
111删除: # Not only .git: shares Lima does not confine leave the rest of the disk
112删除: # in reach (see _agent_vm_unprotected_mount_is_sshfs), --unsafe-writable-git
113删除: # or not. --readonly cannot be enforced on them either: refused before
114删除: # anything boots.
115删除: if [[ -z "$scratch" && -z "$protect_git" ]] && _agent_vm_unprotected_mount_is_sshfs "$vm_name"; then
116删除: if [[ -n "$rdonly" ]]; then
117删除: echo "Error: --readonly cannot be enforced here: the shares would be reverse-sshfs, which this Lima does not confine. Install the Lima build 'agent-vm setup' offers, or use --scratch." >&2
118删除: return 1
119删除: elif [[ -n "$vm_up" ]]; then
120删除: echo "Warning: this Lima cannot keep the VM to its shares: root in the VM may reach files outside them, your SSH keys included ('agent-vm doctor' says more)." >&2
121删除: else
122删除: { _agent_vm_sshfs_exposure_note; _agent_vm_git_protection_hint; } | _agent_vm_box "Lima cannot keep the VM to its shares"
123删除: if ! _agent_vm_confirm_unsafe; then
124删除: echo "Aborted. Install that Lima build, or use --scratch, which shares nothing." >&2
125删除: return 1
126删除: fi
127删除: fi
128删除: fi
129删除:
130删除: # With it, the names the shares need: those always listed, and one per
131删除: # hooks folder git runs from in a share (see _agent_vm_git_scan), its
132删除: # first component. A dot-name (.husky, .githooks) is taken as is; any
133删除: # other is read-only in every folder of every share, so it is asked first
134删除: # (yes by default, and when no one can answer). A folder that cannot be
135删除: # protected, or one declined, is a risk to accept. So are the scan's risks:
136删除: # git config files in a share, settings running commands from one, hooks
137删除: # linked into one. Under --readonly the VM writes none of them: the names
138删除: # are taken as they come, with no warning and no question.
139删除: local hooks_rel hooks_in hooks_name hooks_names=() scan=""
140删除: if [[ -n "$protect_git" ]]; then
141删除: scan="$(_agent_vm_git_scan "$host_dir")"
142删除: while IFS=$'\t' read -r hooks_rel hooks_in; do
143删除: [[ -n "$hooks_rel" ]] || continue
144删除: if [[ -n "$rdonly" ]]; then
145删除: hooks_name="$(_agent_vm_hooks_name "$hooks_in")" && hooks_names+=("$hooks_name")
146删除: continue
147删除: fi
148删除: if ! hooks_name="$(_agent_vm_hooks_name "$hooks_in")"; then
149删除: if [[ "$hooks_rel" == . ]]; then
150删除: echo "Warning: git's core.hooksPath is the project directory itself, which the VM can write: git on this machine runs the hooks the agent puts there." >&2
151删除: elif [[ "$hooks_in" == . ]]; then
152删除: echo "Warning: git's core.hooksPath is '$hooks_rel', a writable volume itself: git on this machine runs the hooks the agent puts there." >&2
153删除: else
154删除: echo "Warning: git's core.hooksPath is '$hooks_rel', which the VM can write, and its name cannot be made read-only: git on this machine runs the hooks the agent puts there." >&2
155删除: fi
156删除: if [[ -z "$vm_up" ]] && ! _agent_vm_confirm_unsafe; then
157删除: echo "Aborted. Point core.hooksPath to a folder of the project (agent-vm keeps it read-only), or outside it." >&2
158删除: return 1
159删除: fi
160删除: continue
161删除: fi
162删除: if [[ "$hooks_name" != .* && -z "$vm_up" ]] && ! _agent_vm_prompts_disabled_by >/dev/null \
163删除: && _agent_vm_can_ask \
164删除: && [[ "$(_agent_vm_ask_yn "Git runs hooks from $hooks_rel. Make every '$hooks_name' folder in the project read-only for the VM?" Y)" != "1" ]]; then
165删除: echo "Warning: '$hooks_name' stays writable, and git on this machine runs the hooks the agent puts in $hooks_rel." >&2
166删除: if ! _agent_vm_confirm_unsafe; then
167删除: echo "Aborted. Answer yes to protect it, or point core.hooksPath outside the project." >&2
168删除: return 1
169删除: fi
170删除: continue
171删除: fi
172删除: hooks_names+=("$hooks_name")
173删除: hooks_notes="$hooks_notes$(_agent_vm_hooks_note "$hooks_rel" "$hooks_name")"$'\n'
174删除: done <<< "$(_agent_vm_scan_part H "$scan")"
175删除: ro_names="$(_agent_vm_names_json ${hooks_names[@]+"${hooks_names[@]}"})"
176删除:
177删除: local git_risks=""
178删除: [[ -n "$rdonly" ]] || git_risks="$(_agent_vm_scan_part R "$scan")"
179删除: if [[ -n "$git_risks" ]]; then
180删除: echo "Warning: git on this machine uses these, and the VM can write them:" >&2
181删除: printf '%s\n' "$git_risks" | sed 's/^/ /' >&2
182删除: if [[ -z "$vm_up" ]] && ! _agent_vm_confirm_unsafe; then
183删除: echo "Aborted. Move them out of the shared folders, or have them name commands outside them." >&2
184删除: return 1
185删除: fi
186删除: fi
187删除: fi
188删除: # A repository not named .git, which no name protects (see
189删除: # _agent_vm_bare_repo_state): only a VM that can write needs the setting.
190删除: if [[ -z "$rdonly" && -z "$scratch" ]]; then
191删除: _agent_vm_check_bare_repo_setting "$vm_up" || return 1
192删除: fi
193删除:}
194删除:
195删除:# A VM that ran when the start began, so whose start asked nothing (see
196删除:# _agent_vm_start_checks), has just been stopped to boot again: ask now, as
197删除:# for any VM about to boot. Reads and clears the caller's vm_up. Fails, with
198删除:# the VM left stopped, when the start must stop.
199删除:_agent_vm_recheck_after_stop() {
200删除: [[ -n "$vm_up" ]] || return 0
201删除: vm_up=""
202删除: if ! _agent_vm_start_checks "$1" "$2"; then
203删除: echo "VM '$2' is stopped." >&2
204删除: return 1
205删除: fi
206删除:}
207删除:
208删除:# Stops <vm>, for the project <dir>, to boot it again changed, then asks what
209删除:# its start did not (see above). Fails, saying so, when it did not stop.
210删除:_agent_vm_stop_to_change() {
211删除: if ! _agent_vm_stop_vm "$1"; then
212删除: echo "Error: could not stop VM '$1': nothing was changed." >&2
213删除: return 1
214删除: fi
215删除: _agent_vm_recheck_after_stop "$2" "$1"
216删除:}
217删除:
218删除:# Gives the stopped <vm> its shares for the project <dir>, writable or not
219删除:# (<writable> true/false), with the caller's protect_git and ro_names, or none
220删除:# for its scratch, and records them (see _agent_vm_record_mounts).
221删除:_agent_vm_apply_shares() {
222删除: local vm="$1" dir="$2" writable="$3" json="[]" out
223删除: [[ -n "$scratch" ]] || json="$(_agent_vm_build_mounts_json "$vm" "$dir" "$writable" "${protect_git:+$ro_names}")"
224删除: if ! out=$(cd /tmp && limactl edit "$vm" --set "$(_agent_vm_mounts_expr "$json" "$protect_git")" 2>&1); then
225删除: echo "Error: could not set the shares of VM '$vm':" >&2
226删除: echo "$out" >&2
227删除: return 1
228删除: fi
229删除: _agent_vm_record_mounts "$vm" "$json" || return 1
230删除: _agent_vm_sshfs_cache_mode >| "$AGENT_VM_STATE_DIR/.agent-vm-sshfs-cache-$vm"
231删除:}
232删除:
233删除:# Before the stopped <vm> boots, fails, saying why, unless what Lima's config
234删除:# gives it is what agent-vm set: for a VM whose .git is protected (the
235删除:# caller's protect_git and ro_names), every share with the read-only names
236删除:# (see _agent_vm_live_shares_why); for one that shares nothing (the caller's
237删除:# scratch, or <none> set), no share at all. Lima merges the mounts of its
238删除:# _config/default.yaml and override.yaml into every VM, and agent-vm's edit
239删除:# cannot remove them.
240删除:_agent_vm_check_before_start() {
241删除: # shellcheck disable=SC2034 # set by _agent_vm_live_fields, all three
242删除: local vm="$1" none="${2:-$scratch}" live why cfg live_vmtype live_mtype live_json
243删除: [[ -n "$protect_git" || -n "$none" ]] || return 0
244删除: cfg="$(_agent_vm_lima_home)/_config"
245删除: if ! live="$(_agent_vm_live_config "$vm")" || ! _agent_vm_live_fields "$live"; then
246删除: echo "Error: could not read Lima's config for VM '$vm', so what it would boot with is not known." >&2
247删除: return 1
248删除: fi
249删除: if [[ -n "$none" ]]; then
250删除: [[ "$live_json" == null || "$live_json" == "[]" ]] && return 0
251删除: echo "Error: Lima gives VM '$vm' shares agent-vm did not ask for, so it would not boot with nothing of yours." >&2
252删除: echo " Look for 'mounts' in $cfg/override.yaml and default.yaml, and remove them." >&2
253删除: return 1
254删除: fi
255删除: why="$(_agent_vm_live_shares_why "$live" "$ro_names")" && return 0
256删除: echo "Error: VM '$vm' would boot with .git writable: $why." >&2
257删除: case "$why" in
258删除: *"mount type"*) echo " Look for 'mountType' in $cfg/override.yaml and default.yaml, and remove it." >&2 ;;
259删除: *) echo " Look for 'mounts' in $cfg/override.yaml and default.yaml, and remove them." >&2 ;;
260删除: esac
261删除: return 1
262删除:}
263删除:
264删除:# The caller's memory, cpus, ssh_port and disk, on the stopped <vm>. The disk
265删除:# apart, with a warning only: Lima rejects a whole edit that would shrink it.
266删除:_agent_vm_apply_resources() {
267删除: local vm="$1" out args=()
268删除: [[ -z "$memory" ]] || args+=(--memory "$memory")
269删除: [[ -z "$cpus" ]] || args+=(--cpus "$cpus")
270删除: [[ -z "$ssh_port" ]] || args+=(--set ".ssh.localPort = $ssh_port")
271删除: # Never without arguments: `limactl edit <vm>` alone opens $EDITOR.
272删除: if [[ ${#args[@]} -gt 0 ]] && ! out=$(cd /tmp && limactl edit "$vm" "${args[@]}" 2>&1); then
273删除: echo "Error: could not set the memory, CPUs or SSH port of VM '$vm':" >&2
274删除: echo "$out" >&2
275删除: return 1
276删除: fi
277删除: if [[ -n "$disk" ]] && ! out=$(cd /tmp && limactl edit "$vm" --disk "$disk" 2>&1); then
278删除: echo "Warning: cannot set the disk of VM '$vm' to $disk GiB: it can grow, not shrink ('agent-vm setup --disk $disk' for a smaller base)." >&2
279删除: echo "$out" >&2
280删除: fi
281删除: return 0
282删除:}
283删除:
284删除:# The env push and the write probe (see _agent_vm_push_env_and_probe), with
285删除:# the caller's vm_name, host_dir, env_payload, guest_env, guest_runtime and
286删除:# scratch, into its probe_out and is_writable: true, false, or lost when the
287删除:# share is not mounted.
288删除:_agent_vm_push_and_probe() {
289删除: local st=0
290删除: probe_out="$(_agent_vm_push_env_and_probe "$vm_name" "$host_dir" "$env_payload" \
291删除: "$guest_env" "$guest_runtime")" || st=$?
292删除: case "$st" in
293删除: 0) is_writable="true" ;;
294删除: 2) is_writable="lost" ;;
295删除: *) is_writable="false" ;;
296删除: esac
297删除: [[ "$probe_out" == *env-ok* ]] || echo "Warning: failed to push the env files into VM '$vm_name'." >&2
298删除:}
299删除:
300删除:# Ensure the VM for cwd exists and is running, creating/starting as needed
301删除:# Usage: _agent_vm_ensure_running <vm_name> <host_dir> [vm_opts...], the options
302删除:# as _agent_vm_take_opt collects them (checked already).
303删除:_agent_vm_ensure_running() {
304删除: local vm_name="$1"
305删除: local host_dir="$2"
306删除: shift 2
307删除: local disk="" memory="" cpus="" ssh_port="" reset="" rdonly="" scratch="" _agent_vm_unsafe_git_flag="" _agent_vm_unsafe_no_prompts=""
308删除: while [[ $# -gt 0 ]]; do
309删除: case "$1" in
310删除: --disk) disk="$2"; shift 2 ;;
311删除: --memory) memory="$2"; shift 2 ;;
312删除: --cpus) cpus="$2"; shift 2 ;;
313删除: --ssh-port) ssh_port="$2"; shift 2 ;;
314删除: --reset) reset=1; shift ;;
315删除: --readonly) rdonly=1; shift ;;
316删除: --scratch) scratch=1; shift ;;
317删除: --unsafe-writable-git) _agent_vm_unsafe_git_flag=1; shift ;;
318删除: --unsafe-disable-security-prompts) _agent_vm_unsafe_no_prompts=1; shift ;;
319删除: *) shift ;;
320删除: esac
321删除: done
322删除:
323删除: # --scratch (see _agent_vm_run_scratch) shares nothing: no share check
324删除: # below applies to it.
325删除: if [[ -n "$scratch" && ( -n "$reset" || -n "$rdonly" ) ]]; then
326删除: echo "Error: --scratch makes a new VM that shares nothing: --reset and --readonly do not go with it." >&2
327删除: return 1
328删除: fi
329删除:
330删除: local want_writable="true"
331删除: [[ -n "$rdonly" ]] && want_writable="false"
332删除:
333删除: # Clamped once, so every path below compares and applies the same values.
334删除: cpus="$(_agent_vm_cap_resource cpus "$cpus")"
335删除: memory="$(_agent_vm_cap_resource memory "$memory")"
336删除: _agent_vm_warn_disk_space "$disk"
337删除:
338删除: # Two VMs set to one port: the second would fail to start.
339删除: if [[ -n "$ssh_port" && "$ssh_port" != 0 ]]; then
340删除: local other
341删除: other="$(limactl list --format '{{.Name}} {{.Config.SSH.LocalPort}}' 2>/dev/null \
342删除: | awk -v vm="$vm_name" -v p="$ssh_port" '$1 != vm && $2 == p { print $1; exit }')"
343删除: if [[ -n "$other" ]]; then
344删除: echo "Error: SSH port $ssh_port is already set for VM '$other'." >&2
345删除: return 1
346删除: fi
347删除: fi
348删除:
349删除: # `cd ~ && agent-vm shell` would hand the VM your dotfiles and SSH keys,
350删除: # read-write, and a share holding agent-vm's own files lets the VM change
351删除: # what the host runs next.
352删除: local unsafe
353删除: if [[ -z "$scratch" ]] && unsafe="$(_agent_vm_unsafe_project "$host_dir")"; then
354删除: echo "Error: refusing to share $host_dir with a VM: it $unsafe." >&2
355删除: echo "Run agent-vm from a project directory." >&2
356删除: return 1
357删除: fi
358删除:
359删除: local bad
360删除: if [[ -z "$scratch" ]] && bad="$(_agent_vm_unmountable_path "$host_dir")"; then
361删除: echo "Error: project path $bad:" >&2
362删除: echo " $host_dir" >&2
363删除: echo "Rename the directory, then retry." >&2
364删除: return 1
365删除: fi
366删除:
367删除: # A run interrupted while Lima created it leaves a folder without lima.yaml.
368删除: _agent_vm_clean_partial_state "$vm_name"
369删除:
370删除: if ! _agent_vm_base_exists; then
371删除: # Distinguish "never set up" from "setup died halfway": the second one
372删除: # leaves a template that looks fine in `limactl list` but is empty.
373删除: if _agent_vm_exists "$AGENT_VM_TEMPLATE"; then
374删除: echo "Error: Base VM setup did not complete. Run 'agent-vm setup' again." >&2
375删除: else
376删除: echo "Error: Base VM not found. Run 'agent-vm setup' first." >&2
377删除: fi
378删除: return 1
379删除: fi
380删除:
381删除: # The security checks, before anything changes. A running VM is asked
382删除: # nothing until stopped (see _agent_vm_recheck_after_stop).
383删除: local vm_up="" protect_git="" ro_names="" hooks_notes=""
384删除: [[ -z "$reset" ]] && _agent_vm_running "$vm_name" && vm_up=1
385删除: _agent_vm_start_checks "$host_dir" "$vm_name" || return 1
386删除:
387删除: # Destroy existing VM if --reset was requested
388删除: if [[ -n "$reset" ]] && _agent_vm_exists "$vm_name"; then
389删除: echo "Resetting VM '$vm_name'..."
390删除: _agent_vm_delete_vm "$vm_name" || return 1
391删除: fi
392删除:
393删除: local is_new_vm="" apply_resize=""
394删除: local file_mount_entries=()
395删除: local file_mounts_cache="$AGENT_VM_STATE_DIR/.agent-vm-file-mounts-${vm_name}"
396删除:
397删除: if ! _agent_vm_exists "$vm_name"; then
398删除: is_new_vm=1
399删除: echo "Creating VM '$vm_name'..."
400删除: local create_out
401删除: if ! create_out=$(limactl clone "$AGENT_VM_TEMPLATE" "$vm_name" --tty=false 2>&1); then
402删除: echo "Error: could not clone the base template into '$vm_name':" >&2
403删除: echo "$create_out" >&2
404删除: return 1
405删除: fi
406删除: # Which agent-vm built its base: none recorded for a base of 0.1.0, which
407删除: # has no sshfs for the protected shares. Then migrated before the edit,
408删除: # on the bare clone (see _agent_vm_migrate_0_1).
409删除: rm -f "$AGENT_VM_STATE_DIR/.agent-vm-built-by-${vm_name}" "$AGENT_VM_STATE_DIR/.agent-vm-sshfs-${vm_name}"
410删除: if [[ -f "$AGENT_VM_STATE_DIR/.agent-vm-base-built-by" ]]; then
411删除: cp "$AGENT_VM_STATE_DIR/.agent-vm-base-built-by" "$AGENT_VM_STATE_DIR/.agent-vm-built-by-${vm_name}"
412删除: fi
413删除: if [[ -n "$protect_git" ]] && ! _agent_vm_migrate_0_1_if_needed "$vm_name"; then
414删除: _agent_vm_delete_vm "$vm_name"
415删除: return 1
416删除: fi
417删除: # Configured before its first start. A clone that could not be holds
418删除: # nothing yet: it goes, and the next run starts over (#21).
419删除: if ! _agent_vm_apply_shares "$vm_name" "$host_dir" "$want_writable" \
420删除: || ! _agent_vm_apply_resources "$vm_name"; then
421删除: _agent_vm_delete_vm "$vm_name"
422删除: return 1
423删除: fi
424删除: printf '%s' "$hooks_notes"
425删除: # Which base it was cloned from, for the stale warning below.
426删除: local base_ver="$AGENT_VM_STATE_DIR/.agent-vm-base-version"
427删除: if [[ -f "$base_ver" ]]; then
428删除: cp "$base_ver" "$AGENT_VM_STATE_DIR/.agent-vm-version-${vm_name}"
429删除: fi
430删除: elif { [[ -n "$disk" || -n "$memory" || -n "$cpus" ]] \
431删除: && _agent_vm_resources_differ "$vm_name" "$cpus" "$memory" "$disk"; } \
432删除: || _agent_vm_ssh_port_differs "$vm_name" "$ssh_port"; then
433删除: # Only when the request differs from what the VM has: a caller passing
434删除: # its defaults every time would otherwise be asked every time. Declined,
435删除: # the VM keeps its settings and everything below still applies.
436删除: apply_resize=1
437删除: if _agent_vm_running "$vm_name"; then
438删除: echo "VM '$vm_name' is currently running. It must be stopped to apply new settings."
439删除: if _agent_vm_can_ask && [[ "$(_agent_vm_ask_yn "Stop the VM and apply changes?" N)" == "1" ]]; then
440删除: echo "Stopping VM..."
441删除: _agent_vm_stop_to_change "$vm_name" "$host_dir" || return 1
442删除: else
443删除: echo "Not applied: the VM keeps its current settings."
444删除: apply_resize=""
445删除: fi
446删除: fi
447删除: fi
448删除: if [[ -n "$apply_resize" ]]; then
449删除: echo "Updating VM settings..."
450删除: _agent_vm_apply_resources "$vm_name" || return 1
451删除: fi
452删除:
453删除: # The same verdict as `info`'s vm_stale=.
454删除: if [[ "$(_agent_vm_stale_state "$vm_name")" == "1" ]]; then
455删除: echo "Warning: Base VM has been updated since this VM was cloned. Use --reset to re-clone from the new base." >&2
456删除: fi
457删除:
458删除: # Whether another session may be using it: read before the start below.
459删除: local was_running=""
460删除: _agent_vm_running "$vm_name" && was_running=1
461删除:
462删除: # Shares recorded otherwise than asked: the .git protection (git_stale), its
463删除: # names (names_stale), the mode (mode_stale), sshfs's cache (cache_stale). A
464删除: # stopped VM is changed before it boots, so nothing starting with it gets a
465删除: # writable window; a running one keeps its shares until stopped, or is
466删除: # offered a restart (never for the cache alone).
467删除: local was_protected="" git_stale="" names_stale="" mode_stale="" cache_stale=""
468删除: _agent_vm_mounts_protect_git "$vm_name" && was_protected=1
469删除: if [[ -n "$protect_git" && -n "$was_protected" ]]; then
470删除: # The record against what Lima has for an existing VM: a share without
471删除: # names, set outside agent-vm, leaves it unprotected whatever was
472删除: # recorded. Which names, the record says (names_stale below).
473删除: if [[ -z "$is_new_vm" ]] \
474删除: && ! _agent_vm_live_shares_why "$(_agent_vm_live_config "$vm_name")" >/dev/null; then
475删除: was_protected=""
476删除: # Running, it is served by the limactl that started it, which may not be
477删除: # the one checked above.
478删除: elif [[ -n "$was_running" ]] && ! _agent_vm_hostagent_is_limactl "$vm_name"; then
479删除: echo "Warning: VM '$vm_name' was started by another limactl than $(_agent_vm_limactl_path), which may not keep .git read-only." >&2
480删除: was_protected=""
481删除: fi
482删除: fi
483删除: [[ "$was_protected" != "$protect_git" ]] && git_stale=1
484删除: if [[ -n "$protect_git" && -n "$was_protected" ]]; then
485删除: _agent_vm_mounts_have_readonly_names "$vm_name" "$ro_names" || names_stale=1
486删除: # Shares made otherwise than _agent_vm_build_mounts_json would now (sshfs's
487删除: # cache): set again before it boots, never a reason to restart it.
488删除: _agent_vm_mounts_sshfs_current "$vm_name" || cache_stale=1
489删除: fi
490删除: if [[ -n "$scratch" ]]; then
491删除: # Shares nothing, as made: nothing to bring in line.
492删除: git_stale=""
493删除: elif [[ "$want_writable" == "false" ]]; then
494删除: _agent_vm_mounts_all_readonly "$vm_name" || mode_stale=1
495删除: elif _agent_vm_mounts_all_readonly "$vm_name"; then
496删除: mode_stale=1
497删除: fi
498删除: # A running VM lacking a protection it should have: restarting it cuts its
499删除: # other sessions, so it is asked; declined, it is a risk to accept. Not
500删除: # under --readonly, which restarts it below anyway.
501删除: if [[ -z "$rdonly" && -n "$was_running" && -n "$protect_git" && ( -n "$git_stale" || -n "$names_stale" ) ]]; then
502删除: if [[ -n "$git_stale" ]]; then
503删除: echo "Warning: VM '$vm_name' is running with .git writable, so the agent can still write .git." >&2
504删除: else
505删除: echo "Warning: VM '$vm_name' runs with an older list of read-only names (it needs $(_agent_vm_names_text "$ro_names")), so the agent can still write the new ones." >&2
506删除: fi
507删除: if ! _agent_vm_prompts_disabled_by >/dev/null && _agent_vm_can_ask \
508删除: && [[ "$(_agent_vm_ask_yn "Restart it now to apply them? Sessions using it are cut." Y)" == "1" ]]; then
509删除: _agent_vm_stop_to_change "$vm_name" "$host_dir" || return 1
510删除: was_running=""
511删除: elif ! _agent_vm_confirm_unsafe; then
512删除: echo "Aborted. 'agent-vm stop', then run again." >&2
513删除: return 1
514删除: fi
515删除: fi
516删除: if [[ -n "$git_stale" && -n "$was_running" ]]; then
517删除: if [[ -n "$protect_git" ]]; then
518删除: :
519删除: elif _agent_vm_writable_git_optout; then
520删除: echo "Note: VM '$vm_name' keeps .git read-only until it stops." >&2
521删除: else
522删除: echo "Warning: this Lima cannot keep .git read-only; VM '$vm_name' keeps its current shares until it stops." >&2
523删除: fi
524删除: elif [[ -n "$names_stale" && -n "$was_running" ]]; then
525删除: :
526删除: elif [[ -z "$was_running" && ( -n "$git_stale" || -n "$names_stale" || -n "$mode_stale" || -n "$cache_stale" ) ]]; then
527删除: if [[ -n "$git_stale" ]]; then
528删除: if [[ -n "$protect_git" ]]; then
529删除: echo "Making every .git read-only for VM '$vm_name'..."
530删除: elif _agent_vm_writable_git_optout; then
531删除: echo "Making .git writable for VM '$vm_name' ($(_agent_vm_writable_git_why))..." >&2
532删除: else
533删除: echo "Warning: this Lima cannot keep .git read-only; VM '$vm_name' goes back to Lima's default mount type." >&2
534删除: fi
535删除: elif [[ -n "$names_stale" ]]; then
536删除: echo "Making $(_agent_vm_names_text "$ro_names") read-only for VM '$vm_name'..."
537删除: fi
538删除: [[ -n "$git_stale" || -n "$names_stale" ]] && printf '%s' "$hooks_notes"
539删除: if [[ -n "$protect_git" ]]; then
540删除: _agent_vm_migrate_0_1_if_needed "$vm_name" || return 1
541删除: fi
542删除: if [[ -n "$mode_stale" && "$want_writable" == "false" ]]; then
543删除: echo "Making every share of VM '$vm_name' read-only..."
544删除: elif [[ -n "$mode_stale" ]]; then
545删除: echo "VM '$vm_name' was left read-only by --readonly; making it writable again..."
546删除: fi
547删除: _agent_vm_apply_shares "$vm_name" "$host_dir" "$want_writable" || return 1
548删除: fi
549删除:
550删除: if [[ -z "$was_running" ]]; then
551删除: _agent_vm_check_before_start "$vm_name" || return 1
552删除: echo "Starting VM '$vm_name'..."
553删除: local start_log
554删除: if ! start_log=$(limactl start "$vm_name" 2>&1); then
555删除: local ha_log
556删除: ha_log="$(_agent_vm_ha_log "$vm_name")"
557删除: echo "Error: Failed to start VM '$vm_name'." >&2
558删除: echo "--- limactl start output ---" >&2
559删除: echo "$start_log" >&2
560删除: echo "Full log: $ha_log" >&2
561删除: _agent_vm_windows_start_hint "$ha_log"
562删除: return 1
563删除: fi
564删除: fi
565删除:
566删除: # Bring the shares of the running VM in line with the mode asked: a write
567删除: # probe on the project (see _agent_vm_push_env_and_probe, which pushes the
568删除: # env too), and the record for the other shares, a missing one counting as
569删除: # writable. A mismatch is a stop, edit and start: a broken mount repaired,
570删除: # --readonly applied, or a --readonly VM made writable again.
571删除: # --scratch takes nothing of the project but ~/.agent-vm/env, and works at
572删除: # the project's path on the VM's own disk.
573删除: local is_writable="false" probe_out guest_env="" guest_runtime="" project_env="" project_runtime="" env_payload
574删除: if [[ -n "$scratch" ]]; then
575删除: if ! limactl shell "$vm_name" sh -c 'sudo install -d -o "$(id -u)" -g "$(id -g)" "$1"' sh "$host_dir" </dev/null >/dev/null 2>&1; then
576删除: echo "Error: could not make $host_dir in VM '$vm_name'." >&2
577删除: return 1
578删除: fi
579删除: env_payload="$( [ ! -f "$AGENT_VM_STATE_DIR/env" ] || _agent_vm_strip_cr < "$AGENT_VM_STATE_DIR/env" )"
580删除: else
581删除: project_env="$(_agent_vm_project_env_file "$host_dir")"
582删除: project_runtime="$(_agent_vm_project_runtime_path "$host_dir")"
583删除: # By their path in the project, the one the VM has.
584删除: local in_rel
585删除: in_rel="$(_agent_vm_project_rel "$host_dir" "$project_env")" && guest_env="$host_dir/$in_rel"
586删除: in_rel="$(_agent_vm_project_rel "$host_dir" "$project_runtime")" && guest_runtime="$host_dir/$in_rel"
587删除: env_payload="$(_agent_vm_env_payload "$host_dir")"
588删除: fi
589删除: _agent_vm_push_and_probe
590删除: # A scratch VM has no share to repair: the repair below would mount the
591删除: # project into it.
592删除: if [[ -n "$scratch" && "$is_writable" != "true" ]]; then
593删除: echo "Error: $host_dir is not writable in VM '$vm_name'." >&2
594删除: return 1
595删除: fi
596删除: local needs_remount=""
597删除: [[ "$is_writable" != "$want_writable" ]] && needs_remount=1
598删除: if [[ "$want_writable" == "false" ]] && ! _agent_vm_mounts_all_readonly "$vm_name"; then
599删除: needs_remount=1
600删除: fi
601删除:
602删除: if [[ -n "$needs_remount" ]]; then
603删除: # Stopping kills whatever else is using this VM, so ask first rather than
604删除: # yanking a running session out from under another terminal, in both
605删除: # directions. The repair direction does not ask: a broken mount is
606删除: # already unusable.
607删除: if [[ "$is_writable" == lost ]]; then
608删除: echo "Warning: the project share is not mounted in VM '$vm_name': what was written in $host_dir in the VM since then is on the VM's own disk, and hidden once the share is back." >&2
609删除: echo "Project share is not mounted; repairing..." >&2
610删除: elif [[ "$want_writable" == "true" && -n "$was_running" ]] && _agent_vm_mounts_all_readonly "$vm_name"; then
611删除: echo "VM '$vm_name' runs read-only (--readonly). It must be restarted to make its shares writable."
612删除: if ! _agent_vm_can_ask || [[ "$(_agent_vm_ask_yn "Stop the VM and make it writable? Sessions using it are cut." N)" != "1" ]]; then
613删除: echo "Error: not restarted. Pass --readonly to use it as it is, or 'agent-vm stop' it first." >&2
614删除: return 1
615删除: fi
616删除: elif [[ "$want_writable" == "false" ]] && [[ -n "$was_running" ]]; then
617删除: echo "VM '$vm_name' was already running. It must be restarted to make its shares read-only."
618删除: if ! _agent_vm_can_ask || [[ "$(_agent_vm_ask_yn "Stop the VM and apply --readonly?" N)" != "1" ]]; then
619删除: # Not "continue with current settings" like the resize path does:
620删除: # carrying on writable after --readonly was asked for is the one
621删除: # outcome that must not be silent.
622删除: echo "Error: --readonly was requested but not applied. Aborting." >&2
623删除: return 1
624删除: fi
625删除: elif [[ "$want_writable" == "true" ]]; then
626删除: echo "Project mount is not writable; repairing..." >&2
627删除: fi
628删除:
629删除: # Stopped for sure first: recording read-only shares while it still runs
630删除: # writable would claim what is not true.
631删除: _agent_vm_stop_to_change "$vm_name" "$host_dir" || return 1
632删除: if [[ -n "$protect_git" ]]; then
633删除: _agent_vm_migrate_0_1_if_needed "$vm_name" || return 1
634删除: fi
635删除: _agent_vm_apply_shares "$vm_name" "$host_dir" "$want_writable" || return 1
636删除: _agent_vm_check_before_start "$vm_name" || return 1
637删除: # Checked: the probe below cannot tell a dead VM from a read-only one.
638删除: if ! limactl start "$vm_name" &>/dev/null; then
639删除: echo "Error: VM '$vm_name' did not come back up after changing the project mount." >&2
640删除: return 1
641删除: fi
642删除: # Again: in the repair case the first probe could not see the project's
643删除: # env file and runtime script.
644删除: _agent_vm_push_and_probe
645删除: if [[ "$is_writable" != "$want_writable" ]]; then
646删除: if [[ "$is_writable" == lost ]]; then
647删除: echo "Error: the project share did not mount in VM '$vm_name':" >&2
648删除: echo " $host_dir" >&2
649删除: echo "Lima's log: $(_agent_vm_ha_log "$vm_name")" >&2
650删除: elif [[ "$want_writable" == "true" ]]; then
651删除: echo "Error: project directory is still not writable inside the VM:" >&2
652删除: echo " $host_dir" >&2
653删除: echo "The host mount failed to attach. Try 'agent-vm --reset <command>'" >&2
654删除: echo "to re-clone the VM from the base template." >&2
655删除: else
656删除: echo "Error: failed to mount the project directory read-only:" >&2
657删除: echo " $host_dir" >&2
658删除: fi
659删除: return 1
660删除: fi
661删除: fi
37新增:dir="$(CDPATH= cd -P -- "$(dirname "$src")" >/dev/null && pwd)"
66238
663删除: # --readonly is only claimed where the host enforces it (see
664删除: # _agent_vm_mount_is_host_enforced); "could not tell" is refused too.
665删除: if [[ -n "$rdonly" ]]; then
666删除: _agent_vm_mount_is_host_enforced "$vm_name"
667删除: case $? in
668删除: 0)
669删除: # Every share, those Lima's _config adds to every VM included.
670删除: if [[ "$(_agent_vm_live_config "$vm_name")" == *'"writable":true'* ]]; then
671删除: echo "Error: --readonly cannot hold: Lima gives VM '$vm_name' a writable share agent-vm did not set." >&2
672删除: echo " Look for 'mounts' in $(_agent_vm_lima_home)/_config/override.yaml and default.yaml." >&2
673删除: return 1
674删除: fi
675删除: echo "Read-only: the project and every other share (enforced on the host)." ;;
676删除: 1) echo "Error: --readonly cannot be enforced with this mount type." >&2
677删除: echo " Lima only applies it inside the guest for reverse-sshfs (without" >&2
678删除: echo " readonlyNames) and for virtiofs under QEMU, where root in the VM" >&2
679删除: echo " can remount it read-write. Use virtiofs on vz, or 9p on QEMU (both" >&2
680删除: echo " enforce it on the host), in your Lima config, then --reset." >&2
681删除: return 1 ;;
682删除: *) echo "Error: could not determine the project mount type, so --readonly" >&2
683删除: echo " cannot be confirmed as enforced outside the VM. Aborting." >&2
684删除: return 1 ;;
685删除: esac
686删除: fi
39新增:# Windows (Git Bash): agent-vm.exe.
40新增:exe=""
41新增:case "$(uname -s)" in MINGW* | MSYS* | CYGWIN*) exe=.exe ;; esac
68742
688删除: # The host's terminfo entry in the VM, for terminals Debian does not know
689删除: # (xterm-ghostty, xterm-kitty): zsh cannot read their keys otherwise. Once
690删除: # per VM and $TERM.
691删除: local term_cache="$AGENT_VM_STATE_DIR/.agent-vm-term-${vm_name}"
692删除: if [[ -n "${TERM:-}" ]] && [[ "$(cat "$term_cache" 2>/dev/null)" != "$TERM" ]] \
693删除: && infocmp -x "$TERM" &>/dev/null; then
694删除: if infocmp -x "$TERM" | limactl shell "$vm_name" sudo tic -x - &>/dev/null; then
695删除: echo "$TERM" >| "$term_cache"
696删除: else
697删除: echo "Warning: failed to install '$TERM' terminfo inside VM." >&2
698删除: fi
699删除: fi
700删除:
701删除: # Run per-user runtime script if it exists
702删除: if [ -f "$AGENT_VM_STATE_DIR/runtime.sh" ]; then
703删除: echo "Running user runtime setup..."
704删除: _agent_vm_run_runtime "$vm_name" "$host_dir" "$AGENT_VM_STATE_DIR/runtime.sh"
705删除: fi
706删除:
707删除: # Run project-specific runtime script if it exists: by its path in the VM
708删除: # when it is in the project (the probe above said whether it is there),
709删除: # piped from the host when AGENT_VM_PROJECT_RUNTIME puts it elsewhere.
710删除: if [[ -n "$guest_runtime" ]]; then
711删除: if [[ "$probe_out" == *runtime-found* ]]; then
712删除: echo "Running project runtime setup..."
713删除: _agent_vm_run_project_runtime "$vm_name" "$host_dir" "$guest_runtime"
714删除: fi
715删除: elif [ -f "$project_runtime" ]; then
716删除: echo "Running project runtime setup..."
717删除: _agent_vm_run_runtime "$vm_name" "$host_dir" "$project_runtime"
718删除: fi
719删除:
720删除: # Single files of ~/.agent-vm/volumes (see _agent_vm_build_mounts_json, which
721删除: # lists them in the cache): an existing VM's staged copy refreshed, so an
722删除: # edit saved by rename on the host shows, then each bound at its place in
723删除: # the VM, in one round trip. The bind does not survive a restart, and is
724删除: # skipped when there.
725删除: if [[ -f "$file_mounts_cache" ]]; then
726删除: local host_src host_staging bind_src bind_dst
727删除: while IFS='|' read -r host_src host_staging bind_src bind_dst; do
728删除: [[ -n "$host_staging" ]] || continue
729删除: if [[ -n "$is_new_vm" ]]; then
730删除: :
731删除: elif [[ ! -e "$host_src" ]]; then
732删除: echo "Warning: Mount source '${host_src}' no longer exists; VM will see the last-staged copy." >&2
733删除: else
734删除: _agent_vm_stage_file "$host_src" "$host_staging" \
735删除: || echo "Warning: Failed to refresh staged '${host_src}'; VM may see stale content." >&2
736删除: fi
737删除: [[ -n "$bind_src" && -n "$bind_dst" ]] && file_mount_entries+=("${bind_src}|${bind_dst}")
738删除: done < "$file_mounts_cache"
739删除: if [[ ${#file_mount_entries[@]} -gt 0 ]]; then
740删除: echo "Mounting individual files..."
741删除: # The paths as arguments, never in the script.
742删除: limactl shell "$vm_name" sudo bash -c '
743删除: set -e
744删除: for entry in "$@"; do
745删除: bind_src="${entry%%|*}"
746删除: bind_dst="${entry#*|}"
747删除: if ! findmnt -no TARGET "$bind_dst" >/dev/null 2>&1; then
748删除: mkdir -p "$(dirname "$bind_dst")" && touch "$bind_dst"
749删除: mount --bind "$bind_src" "$bind_dst"
750删除: mount -o remount,ro,bind "$bind_dst"
751删除: fi
752删除: done
753删除: ' -- "${file_mount_entries[@]}"
754删除: fi
755删除: fi
756删除:}
757删除:
758删除:# --- agent-vm: the command, dispatching to the rest ---------------------------
759删除:
760删除:agent-vm() {
761删除: # Options before the command are checked here and handed to it as written:
762删除: # the commands that start a VM read them again, with their own.
763删除: local lead=() vm_opts=() rm="" taken
764删除: while [[ $# -gt 0 ]]; do
765删除: _agent_vm_take_opt "$@" || return 1
766删除: [[ $taken -gt 0 ]] || break
767删除: lead+=("${@:1:$taken}")
768删除: shift "$taken"
769删除: done
770删除:
771删除: local cmd="${1:-help}"
772删除: shift 2>/dev/null || true
773删除:
774删除: # VM options mean nothing to the other commands: `agent-vm --readonly stop`
775删除: # must not read as if something had been made read-only.
776删除: if [[ ${#lead[@]} -gt 0 ]]; then
777删除: case "$cmd" in
778删除: stop|rm|destroy|destroy-all|list|status|name|info|env|project-env|version|--version|-V|doctor|install|uninstall|help|--help|-h)
779删除: echo "Error: ${lead[*]:0:1} is an option for the commands that start a VM (claude, opencode, codex, vibe, pi, shell, run, code), not for '$cmd'." >&2
780删除: return 1 ;;
781删除: esac
782删除: fi
783删除:
784删除: # Every command except help/setup needs limactl present. (setup installs it
785删除: # itself; help needs nothing.) Without this, stop/list/status/etc. would fail
786删除: # with confusing empty output instead of a clear, actionable message.
787删除: case "$cmd" in
788删除: help|--help|-h|setup|version|--version|-V|name|info|env|project-env|doctor|install|uninstall) ;;
789删除: *)
790删除: if [[ -z "$(_agent_vm_limactl_path)" ]]; then
791删除: echo "Error: limactl (Lima) not found. Run 'agent-vm setup' first, or install" >&2
792删除: echo "it from https://lima-vm.io/docs/installation/" >&2
793删除: return 1
794删除: fi ;;
795删除: esac
796删除:
797删除: case "$cmd" in
798删除: setup)
799删除: _agent_vm_setup ${lead[@]+"${lead[@]}"} "$@"
800删除: ;;
801删除: claude|opencode|codex|vibe|pi)
802删除: _agent_vm_agent "$cmd" ${lead[@]+"${lead[@]}"} "$@"
803删除: ;;
804删除: shell|sh)
805删除: _agent_vm_shell ${lead[@]+"${lead[@]}"} "$@"
806删除: ;;
807删除: run)
808删除: _agent_vm_run ${lead[@]+"${lead[@]}"} "$@"
809删除: ;;
810删除: code)
811删除: _agent_vm_code ${lead[@]+"${lead[@]}"} "$@"
812删除: ;;
813删除: stop)
814删除: _agent_vm_stop "$@"
815删除: ;;
816删除: rm|destroy)
817删除: _agent_vm_destroy "$@"
818删除: ;;
819删除: destroy-all)
820删除: _agent_vm_destroy_all "$@"
821删除: ;;
822删除: list|status)
823删除: _agent_vm_list
824删除: ;;
825删除: name)
826删除: local name_dir
827删除: name_dir="$(_agent_vm_abs_dir "${1:-}")" || return 1
828删除: _agent_vm_name "$name_dir"
829删除: ;;
830删除: info)
831删除: local info_dir
832删除: info_dir="$(_agent_vm_abs_dir "${1:-}")" || return 1
833删除: _agent_vm_info "$info_dir"
834删除: ;;
835删除: env)
836删除: _agent_vm_env env "$AGENT_VM_STATE_DIR/env" "" "$@"
837删除: ;;
838删除: project-env)
839删除: local project_env_file project_top="" project_rel
840删除: project_env_file="$(_agent_vm_project_env_file)"
841删除: if project_rel="$(_agent_vm_project_rel "$(pwd)" "$project_env_file")"; then
842删除: project_top="$(pwd)"
843删除: project_env_file="$project_top/$project_rel"
844删除: fi
845删除: _agent_vm_env project-env "$project_env_file" "$project_top" "$@" || return $?
846删除: # Only after a write, and only if it worked: that is when the file is
847删除: # new to the repository and when the user is looking.
848删除: if [ "${1:-}" = "set" ]; then
849删除: _agent_vm_warn_unignored "$project_env_file"
850删除: fi
851删除: ;;
852删除: version|--version|-V)
853删除: _agent_vm_version "$@"
854删除: ;;
855删除: doctor)
856删除: if [[ $# -gt 0 ]]; then
857删除: echo "Usage: agent-vm doctor" >&2
858删除: return 2
859删除: fi
860删除: _agent_vm_doctor
861删除: ;;
862删除: install)
863删除: _agent_vm_install "$@"
864删除: ;;
865删除: uninstall)
866删除: _agent_vm_uninstall "$@"
867删除: ;;
868删除: help|--help|-h)
869删除: _agent_vm_help
870删除: ;;
871删除: *)
872删除: echo "Unknown command: $cmd" >&2
873删除: echo "Run 'agent-vm help' for usage." >&2
874删除: return 1
875删除: ;;
876删除: esac
877删除:}
878删除:
879删除:# --- commands -----------------------------------------------------------------
880删除:
881删除:# Run a command in the VM through a login zsh.
882删除:#
883删除:# `limactl shell VM cmd` runs cmd under the shell configured for the instance,
884删除:# and Lima >= 2.2.0 defaults that to /bin/bash whatever the guest login shell
885删除:# is (lima-vm/lima#5194); older versions used "$SHELL", i.e. the login shell
886删除:# `agent-vm.setup.sh` sets with chsh. Agent PATH entries and the
887删除:# ~/.agent-vm.env sourcing both live in ~/.zshenv, so under bash the agents are
888删除:# not found and anything that is found starts without its API keys. Forcing
889删除:# `zsh -l -c` here works on every Lima version.
890删除:#
891删除:# The command and its arguments are passed as positional parameters, so the
892删除:# guest shell never re-parses them; `env` runs the command and keeps leading
893删除:# VAR=value assignments working. `env --`: GNU env still reads assignments
894删除:# after it, and a command starting with `-` (`run -i foo`) is not taken for
895删除:# one of its options. A command that is not there is said so, with env's
896删除:# status: an agent installed only as an editor extension has no command. A
897删除:# path is env's to run: it says why it cannot (a script without +x, 126).
898删除:#
899删除:# Usage: _agent_vm_lima_run <vm_name> <host_dir> <tty:1|""> <command> [args...]
900删除:_agent_vm_lima_run() {
901删除: local vm_name="$1" host_dir="$2" want_tty="$3"
902删除: shift 3
903删除: local shell_opts=(--workdir "$host_dir")
904删除: [[ -n "$want_tty" ]] && shell_opts+=(--tty)
905删除: limactl shell "${shell_opts[@]}" "$vm_name" -- zsh -l -c \
906删除: 'case "$1" in *=*|*/*) ;; *) command -v -- "$1" >/dev/null || { print -r -- "agent-vm: $1 is not installed in this VM." >&2; exit 127; } ;; esac; exec env -- "$@"' \
907删除: agent-vm "$@"
908删除:}
909删除:
910删除:# Starts this directory's VM with the caller's vm_opts, runs <function> with
911删除:# the VM name and the directory before its own arguments, then deletes the VM
912删除:# when the caller's rm is set. Returns the function's status. With --scratch,
913删除:# see _agent_vm_run_scratch.
914删除:_agent_vm_in_vm() {
915删除: local fn="$1" host_dir vm_name st=0 o
916删除: shift
917删除: host_dir="$(pwd)"
918删除: for o in ${vm_opts[@]+"${vm_opts[@]}"}; do
919删除: if [[ "$o" == --scratch ]]; then
920删除: _agent_vm_run_scratch "$fn" "$host_dir" "$@"
921删除: return
922删除: fi
923删除: done
924删除: vm_name="$(_agent_vm_name "$host_dir")" || return 1
925删除: _agent_vm_ensure_running "$vm_name" "$host_dir" ${vm_opts[@]+"${vm_opts[@]}"} || return 1
926删除: _agent_vm_print_resources "$vm_name"
927删除: "$fn" "$vm_name" "$host_dir" "$@" || st=$?
928删除: _agent_vm_reset_term_modes
929删除: if [[ -n "$rm" ]]; then
930删除: echo "Removing VM..."
931删除: _agent_vm_destroy
932删除: fi
933删除: return "$st"
934删除:}
935删除:
936删除:# --scratch: a new VM of its own (see _agent_vm_scratch_name), sharing
937删除:# nothing, deleted once <function> returns, whatever it returns, unless the
938删除:# user keeps it a while to look inside (asked below). Ctrl-C
939删除:# included: the trap lets the run go on to the deletion instead of ending
940删除:# the shell with the interrupted command (bash ends a script whose child dies
941删除:# of SIGINT, unless it traps it). A run that is killed outright leaves its VM
942删除:# recorded with its pid, and the next --scratch run deletes it.
943删除:_agent_vm_run_scratch() {
944删除: local fn="$1" host_dir="$2" vm_name st=0 old_int="" leftover
945删除: shift 2
946删除: while IFS= read -r leftover; do
947删除: [[ -n "$leftover" ]] || continue
948删除: echo "Deleting scratch VM '$leftover', left by a run that did not finish..."
949删除: _agent_vm_delete_vm "$leftover"
950删除: done <<< "$(_agent_vm_scratch_leftovers)"
951删除: vm_name="$(_agent_vm_scratch_name "$host_dir")" || return 1
952删除: mkdir -p "$AGENT_VM_STATE_DIR" && printf '%s\n' "$$" > "$(_agent_vm_scratch_marker "$vm_name")" || return 1
953删除: # The caller's: the shell session says the VM goes on exit.
954删除: rm=1
955删除: old_int="$(trap -p INT)"
956删除: trap ':' INT
957删除: if _agent_vm_ensure_running "$vm_name" "$host_dir" ${vm_opts[@]+"${vm_opts[@]}"}; then
958删除: _agent_vm_print_resources "$vm_name"
959删除: "$fn" "$vm_name" "$host_dir" "$@" || st=$?
960删除: _agent_vm_reset_term_modes
961删除: # Asked before the deletion, when it can be (yes by default): a no opens
962删除: # a shell in the VM, to look at what the command left, and asks again on
963删除: # its exit. Only an explicit no keeps it: no terminal, or a question cut
964删除: # short, deletes.
965删除: while _agent_vm_can_ask \
966删除: && [[ "$(_agent_vm_ask_yn "Delete scratch VM '$vm_name'?" Y)" == "0" ]]; do
967删除: echo "A shell in scratch VM '$vm_name'. Type 'exit' to be asked again."
968删除: limactl shell --workdir "$host_dir" "$vm_name" zsh -l
969删除: _agent_vm_reset_term_modes
970删除: done
971删除: else
972删除: st=1
973删除: fi
974删除: echo "Deleting scratch VM '$vm_name'..."
975删除: _agent_vm_delete_vm "$vm_name" || st=1
976删除: trap - INT
977删除: [[ -z "$old_int" ]] || eval "$old_int"
978删除: return "$st"
979删除:}
980删除:
981删除:# `agent-vm <agent> [options] [args]`: the agent, with the flag that lets it
982删除:# work unattended (safe in the VM), and a TTY for the full-screen ones.
983删除:_agent_vm_agent() {
984删除: local agent="$1" cmd=() tty="" vm_opts=() rm="" args=()
985删除: shift
986删除: case "$agent" in
987删除: # The VM also enforces bypass mode with managed settings (see
988删除: # agent-vm.setup.sh): Claude Code drops the flag when it relaunches itself.
989删除: claude) cmd=(claude --dangerously-skip-permissions) ;;
990删除: # Approves every prompt that is not explicitly denied: OpenCode's shipped
991删除: # "yolo" (a --yolo flag was proposed, never merged).
992删除: opencode) cmd=(opencode --auto); tty=1 ;;
993删除: codex) cmd=(codex --dangerously-bypass-approvals-and-sandbox) ;;
994删除: vibe) cmd=(vibe --agent auto-approve); tty=1 ;;
995删除: # No permission prompts: it runs every tool as asked.
996删除: pi) cmd=(pi); tty=1 ;;
997删除: *) echo "Error: unknown agent: $agent" >&2; return 1 ;;
998删除: esac
999删除: _agent_vm_split_args "$@" || return 1
1000删除: _agent_vm_in_vm _agent_vm_lima_run "$tty" "${cmd[@]}" ${args[@]+"${args[@]}"}
1001删除:}
1002删除:
1003删除:# `agent-vm shell [-c "command"]`: a login zsh in the VM, so ~/.zshenv (mise,
1004删除:# PATH, ~/.agent-vm.env) is loaded. Takes no command of its own, so a word it
1005删除:# does not know is an error, not something skipped as if it had applied.
1006删除:_agent_vm_shell() {
1007删除: local vm_opts=() rm="" cmd_string="" taken
1008删除: while [[ $# -gt 0 ]]; do
1009删除: _agent_vm_take_opt "$@" || return 1
1010删除: if [[ $taken -gt 0 ]]; then
1011删除: shift "$taken"
1012删除: continue
1013删除: fi
1014删除: case "$1" in
1015删除: -c|--command)
1016删除: if [[ $# -lt 2 || -z "$2" ]]; then
1017删除: echo "Error: -c/--command requires a command string." >&2
1018删除: return 1
1019删除: fi
1020删除: cmd_string="$2"; shift 2 ;;
1021删除: *)
1022删除: echo "Error: unknown argument for shell: $1" >&2
1023删除: echo "Usage: agent-vm [vm options] shell [-c \"command\"]" >&2
1024删除: return 1 ;;
1025删除: esac
1026删除: done
1027删除: _agent_vm_in_vm _agent_vm_shell_session "$cmd_string"
1028删除:}
1029删除:
1030删除:_agent_vm_shell_session() {
1031删除: local vm_name="$1" host_dir="$2" cmd_string="$3"
1032删除: if [[ -n "$cmd_string" ]]; then
1033删除: limactl shell --workdir "$host_dir" "$vm_name" zsh -l -c "$cmd_string"
1034删除: return
1035删除: fi
1036删除: echo "VM: $vm_name | Dir: $host_dir"
1037删除: if [[ -n "$rm" ]]; then
1038删除: echo "Type 'exit' to leave. VM will be destroyed after exit."
1039删除: else
1040删除: echo "Type 'exit' to leave (VM keeps running). Use 'agent-vm stop' to stop it."
1041删除: fi
1042删除: limactl shell --workdir "$host_dir" "$vm_name" zsh -l
1043删除:}
1044删除:
1045删除:# `agent-vm run [--tty] <command> [args]`. --tty gives the command a
1046删除:# pseudo-terminal, which full-screen TUIs (htop, …) need to draw.
1047删除:_agent_vm_run() {
1048删除: local vm_opts=() rm="" tty="" args=()
1049删除: _agent_vm_split_args "$@" || return 1
1050删除: if [[ ${#args[@]} -eq 0 ]]; then
1051删除: echo "Usage: agent-vm run [--tty] <command> [args]" >&2
1052删除: return 1
1053删除: fi
1054删除: _agent_vm_in_vm _agent_vm_lima_run "$tty" "${args[@]}"
1055删除:}
1056删除:
1057删除:# Resolve the VM that `stop` / `rm` acts on, and prove it exists.
1058删除:# Prints the name on stdout; diagnostics go to stderr.
1059删除:#
1060删除:# With no argument: the current directory's VM, as before.
1061删除:#
1062删除:# With one argument: a VM name as printed by `agent-vm list`. It has to be a
1063删除:# NAME and not a directory, because the case it exists for is a VM no directory
1064删除:# can reach any more: the name embeds a hash of the path, so renaming or
1065删除:# deleting the project folder orphans the VM, and `_agent_vm_abs_dir` would
1066删除:# refuse the old path anyway. `list` remains the only handle on it.
1067删除:#
1068删除:# The `agent-vm-` prefix is required: without it a typo could stop or delete an
1069删除:# unrelated Lima instance on the same machine.
1070删除:_agent_vm_resolve_target() {
1071删除: local verb="$1"
1072删除: shift
1073删除:
1074删除: local vm_name
1075删除: case $# in
1076删除: 0) vm_name="$(_agent_vm_name "$(pwd)")" || return 1 ;;
1077删除: 1)
1078删除: vm_name="$1"
1079删除: case "$vm_name" in
1080删除: agent-vm-*) ;;
1081删除: *)
1082删除: echo "Error: '$vm_name' is not an agent-vm VM name (they start with 'agent-vm-')." >&2
1083删除: echo "Run 'agent-vm list' to see them." >&2
1084删除: return 1 ;;
1085删除: esac ;;
1086删除: *)
1087删除: echo "Usage: agent-vm $verb [vm-name]" >&2
1088删除: return 1 ;;
1089删除: esac
1090删除:
1091删除: local st=0
1092删除: _agent_vm_exists "$vm_name" || st=$?
1093删除: case "$st" in
1094删除: 0) ;;
1095删除: 1)
1096删除: if [[ $# -eq 0 ]]; then
1097删除: echo "No VM found for this directory." >&2
1098删除: echo "Run 'agent-vm list' to see existing VMs, then 'agent-vm $verb <vm-name>'." >&2
1099删除: else
1100删除: echo "Error: no such VM: $vm_name" >&2
1101删除: echo "Run 'agent-vm list' to see existing VMs." >&2
1102删除: fi
1103删除: return 1 ;;
1104删除: *)
1105删除: echo "Error: could not query Lima. Is it installed and working?" >&2
1106删除: return 1 ;;
1107删除: esac
1108删除:
1109删除: echo "$vm_name"
1110删除:}
1111删除:
1112删除:_agent_vm_stop() {
1113删除: local vm_name
1114删除: vm_name="$(_agent_vm_resolve_target stop "$@")" || return 1
1115删除:
1116删除: echo "Stopping VM '$vm_name'..."
1117删除: if ! _agent_vm_stop_vm "$vm_name"; then
1118删除: echo "Error: VM '$vm_name' is still running, or Lima cannot say. See 'limactl list'." >&2
1119删除: return 1
1120删除: fi
1121删除: echo "VM stopped."
1122删除:}
1123删除:
1124删除:_agent_vm_destroy() {
1125删除: local vm_name
1126删除: vm_name="$(_agent_vm_resolve_target rm "$@")" || return 1
1127删除:
1128删除: echo "Stopping and deleting VM '$vm_name'..."
1129删除: _agent_vm_delete_vm "$vm_name" || return 1
1130删除: echo "VM destroyed."
1131删除:}
1132删除:
1133删除:# Every agent-vm VM, the base template included: this is the command that
1134删除:# gives the disk space back. `agent-vm setup` rebuilds the template.
1135删除:_agent_vm_destroy_all() {
1136删除: local list vms
1137删除: if ! list="$(limactl list -q 2>/dev/null)"; then
1138删除: echo "Error: could not query Lima. Is it installed and working?" >&2
1139删除: return 1
1140删除: fi
1141删除: vms="$(printf '%s\n' "$list" | grep "^agent-vm-" || true)"
1142删除: if [[ -z "$vms" ]]; then
1143删除: echo "No agent-vm VMs found."
1144删除: return 0
1145删除: fi
1146删除: echo "This will destroy the following VMs:"
1147删除: echo "$vms"
1148删除: if _agent_vm_has_line "$vms" "$AGENT_VM_TEMPLATE"; then
1149删除: echo "($AGENT_VM_TEMPLATE is the base template: 'agent-vm setup' rebuilds it.)"
1150删除: fi
1151删除: if ! _agent_vm_can_ask || [[ "$(_agent_vm_ask_yn "Continue?" N)" != "1" ]]; then
1152删除: echo "Aborted."
1153删除: return 0
1154删除: fi
1155删除: _agent_vm_destroy_vms "$vms" || return 1
1156删除: echo "All VMs destroyed."
1157删除:}
1158删除:
1159删除:# Stop, delete and forget each VM named on its own line in $1. Goes through
1160删除:# all of them, and fails if one could not be deleted.
1161删除:# limactl gets /dev/null as stdin (see _agent_vm_delete_vm): the names are
1162删除:# read from stdin, and a limactl that reads it would swallow the ones still to
1163删除:# come.
1164删除:_agent_vm_destroy_vms() {
1165删除: local vm st=0
1166删除: while IFS= read -r vm; do
1167删除: [[ -n "$vm" ]] || continue
1168删除: echo "Destroying $vm..."
1169删除: _agent_vm_delete_vm "$vm" || st=1
1170删除: done <<< "$1"
1171删除: return "$st"
1172删除:}
1173删除:
1174删除:# Lima's table of the agent-vm VMs, with the base each was cloned from (see
1175删除:# _agent_vm_base_label) in a last column. Lima pads every column but its last,
1176删除:# so the lines are padded here to line it up.
1177删除:# `list` and `status`: Lima's table of the agent-vm VMs, the current
1178删除:# directory's marked with >, and the base each was cloned from (see
1179删除:# _agent_vm_base_label) in a last column. Lima pads every column but its last,
1180删除:# so the lines are padded here to line it up.
1181删除:_agent_vm_list() {
1182删除: local list line lines=() w=0 header=1 current mark
1183删除: current="$(_agent_vm_name "$(pwd)" 2>/dev/null)" || current=""
1184删除: if ! list="$(limactl list 2>/dev/null)"; then
1185删除: echo "Error: could not query Lima. Is it installed and working?" >&2
1186删除: return 1
1187删除: fi
1188删除: while IFS= read -r line; do
1189删除: [[ -n "$line" ]] || continue
1190删除: if [[ ${#lines[@]} -eq 0 || "$line" == agent-vm-* ]]; then
1191删除: lines+=("$line")
1192删除: [[ ${#line} -gt $w ]] && w=${#line}
1193删除: fi
1194删除: done <<< "$list"
1195删除: if [[ ${#lines[@]} -lt 2 ]]; then
1196删除: [[ ${#lines[@]} -eq 0 ]] || printf ' %s\n' "${lines[@]}"
1197删除: echo " (no VMs)"
1198删除: return 0
1199删除: fi
1200删除: for line in "${lines[@]}"; do
1201删除: if [[ -n "$header" ]]; then
1202删除: header=""
1203删除: printf ' %-*s %s\n' "$w" "$line" "BASE"
1204删除: else
1205删除: mark=" "
1206删除: [[ "${line%% *}" == "$current" ]] && mark=">"
1207删除: printf '%s %-*s %s\n' "$mark" "$w" "$line" "$(_agent_vm_base_label "${line%% *}")"
1208删除: fi
1209删除: done
1210删除:}
43新增:if [ -f "$dir/agent-vm$exe" ]; then
44新增: exec "$dir/agent-vm$exe" "$@"
45新增:fi
121146
1212删除:# When the file is executed (the command `install` puts on PATH, or
1213删除:# `./agent-vm.sh setup`) rather than sourced, dispatch to the agent-vm
1214删除:# function so it doesn't silently no-op. BASH_SOURCE[0] differs from $0 when
1215删除:# sourced.
1216删除:if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
1217删除: agent-vm "$@"
1218删除: exit $?
47新增:bin="$dir/_output/bin/agent-vm$exe"
48新增:head="$(git -C "$dir" rev-parse HEAD 2>/dev/null || echo none)"
49新增:if [ ! -x "$bin" ] || [ "$(cat "$dir/_output/built-from" 2>/dev/null)" != "$head" ]; then
50新增: echo "agent-vm: building (Go needed, and on macOS the Xcode command line tools; a few minutes the first time)..." >&2
51新增: mkdir -p "$dir/_output"
52新增: make -C "$dir" agent-vm >"$dir/_output/build.log" 2>&1 \
53新增: || { tail -n 20 "$dir/_output/build.log" >&2; echo "agent-vm: the build failed, full log: $dir/_output/build.log" >&2; exit 1; }
54新增: echo "$head" > "$dir/_output/built-from"
121955fi
56新增:exec "$bin" "$@"
新增assets.go+21 −0看文件
@@ -0,0 +1,21 @@
1新增:// Package agentvm holds the files of this repository the binary embeds.
2新增:package agentvm
3新增:
4新增:import _ "embed"
5新增:
6新增:// SetupScript provisions the base VM: `agent-vm setup` runs it in the guest,
7新增:// after the choices as export lines.
8新增://
9新增://go:embed agent-vm.setup.sh
10新增:var SetupScript string
11新增:
12新增:// The license of agent-vm, the notice about third_party/, and the licenses of
13新增:// what the binary is built from (scripts/licenses): `agent-vm licenses`.
14新增:var (
15新增: //go:embed LICENSE
16新增: License string
17新增: //go:embed NOTICE
18新增: Notice string
19新增: //go:embed THIRD_PARTY_LICENSES
20新增: ThirdPartyLicenses string
21新增:)
新增cmd/agent-vm/main.go+18 −0看文件
@@ -0,0 +1,18 @@
1新增:// Command agent-vm runs AI coding agents in a disposable Linux VM per
2新增:// project, with Lima built in.
3新增:package main
4新增:
5新增:import (
6新增: "os"
7新增:
8新增: "github.com/sylvinus/agent-vm/internal/cli"
9新增: "github.com/sylvinus/agent-vm/internal/limaembed"
10新增:)
11新增:
12新增:func main() {
13新增: // Lima's libraries start this executable again for its hostagent.
14新增: if limaembed.Run(os.Args[1:]) {
15新增: return
16新增: }
17新增: os.Exit(cli.Main(os.Args[1:], cli.Stdio()))
18新增:}
新增cmd/agent-vm/main_darwin_gui.go+16 −0看文件
@@ -0,0 +1,16 @@
1新增://go:build darwin
2新增:
3新增:// SPDX-FileCopyrightText: Copyright The Lima Authors
4新增:// SPDX-License-Identifier: Apache-2.0
5新增:
6新增:package main
7新增:
8新增:import "runtime"
9新增:
10新增:func init() {
11新增: // Lock the main goroutine to the initial process thread before main() runs.
12新增: // VZVirtualMachineView requires GUI operations on the initial thread; without
13新增: // this, Go's scheduler may migrate the goroutine before hostagent starts.
14新增: // Assumes no other package init() triggers a scheduling point before this runs.
15新增: runtime.LockOSThread()
16新增:}
新增docs/BACKLOG.md+39 −0看文件
@@ -0,0 +1,39 @@
1新增:# Backlog
2新增:
3新增:Known gaps and ideas, not on the website.
4新增:
5新增:## Windows, natively
6新增:
7新增:Status: built, not yet tried.
8新增:
9新增:agent-vm runs on Windows without Git Bash now, its paths handled as `C:/...`
10新增:and seen by the VM as `/c/...`, as in 0.2, and its tests run on any OS. Nothing
11新增:of it has run on a Windows machine yet: setup, the shares, the network
12新增:isolation, the port check.
13新增:
14新增:## Review the agent's writes
15新增:
16新增:Status: idea.
17新增:
18新增:Every write of the VM goes through agent-vm's SFTP server. It could keep them
19新增:aside and let you review the diff, and apply all or part of it to the real
20新增:folder. A first step: the list of every path the VM wrote during a session.
21新增:
22新增:## Run a VM inside the VM
23新增:
24新增:Status: needs an M3.
25新增:
26新增:A `--allow-nested-vm` flag, for testing VM tooling from in there. Lima supports
27新增:nested virtualization, but it is off by default and cannot be turned on
28新增:unconditionally: below an Apple M3, Lima fails to start the VM instead of
29新增:degrading, so every VM would stop starting. The flag would have to detect host
30新增:support first. Nothing here has an M3 to test it on. It would also hand the
31新增:agent a hypervisor interface.
32新增:
33新增:## Run the VMs on another machine
34新增:
35新增:Status: designed, not built.
36新增:
37新增:One install on your laptop driving VMs on a box you rent. Close the laptop, the
38新增:agent keeps working. Open questions: addressing a VM by name rather than by
39新增:working directory, and who owns deleting a workspace.
新增go.mod+136 −0看文件
@@ -0,0 +1,136 @@
1新增:module github.com/sylvinus/agent-vm
2新增:
3新增:go 1.26.9
4新增:
5新增:// Lima, sshocker and pkg/sftp are built from third_party/: upstream plus
6新增:// patches/ (see scripts/third-party-sync). These replaces only apply when
7新增:// this module is the main one, so `go install ...@latest` does not build
8新增:// agent-vm: releases ship binaries.
9新增:replace (
10新增: github.com/containers/gvisor-tap-vsock => ./third_party/gvisor-tap-vsock
11新增: github.com/lima-vm/lima/v2 => ./third_party/lima
12新增: github.com/lima-vm/sshocker => ./third_party/sshocker
13新增: github.com/pkg/sftp => ./third_party/sftp
14新增:)
15新增:
16新增:tool (
17新增: github.com/lima-vm/lima/v2/cmd/lima-guestagent
18新增: github.com/lima-vm/lima/v2/cmd/limactl
19新增:)
20新增:
21新增:require (
22新增: al.essio.dev/pkg/shellescape v1.6.1
23新增: github.com/containerd/continuity v0.5.0
24新增: github.com/coreos/go-semver v0.3.1
25新增: github.com/docker/go-units v0.5.0
26新增: github.com/lima-vm/lima/v2 v2.0.0
27新增: github.com/lima-vm/sshocker v0.3.11
28新增: github.com/mattn/go-isatty v0.0.24
29新增: github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
30新增: github.com/sirupsen/logrus v1.10.2
31新增: github.com/spf13/cobra v1.10.2
32新增: golang.org/x/sys v0.48.0
33新增: golang.org/x/term v0.46.0
34新增:)
35新增:
36新增:require (
37新增: github.com/AlecAivazis/survey/v2 v2.3.7 // indirect
38新增: github.com/Code-Hex/go-infinity-channel v1.0.0 // indirect
39新增: github.com/Code-Hex/vz/v3 v3.7.1 // indirect
40新增: github.com/Microsoft/go-winio v0.6.3-0.20251027160822-ad3df93bed29 // indirect
41新增: github.com/Microsoft/hcsshim v0.14.1 // indirect
42新增: github.com/VividCortex/ewma v1.2.0 // indirect
43新增: github.com/a8m/envsubst v1.4.3 // indirect
44新增: github.com/agext/levenshtein v1.2.1 // indirect
45新增: github.com/alecthomas/participle/v2 v2.1.4 // indirect
46新增: github.com/apparentlymart/go-cidr v1.1.1 // indirect
47新增: github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
48新增: github.com/apparentlymart/go-textseg/v17 v17.0.1 // indirect
49新增: github.com/bahlo/generic-list-go v0.2.0 // indirect
50新增: github.com/balajiv113/fd v0.0.0-20230330094840-143eec500f3e // indirect
51新增: github.com/bmatcuk/doublestar/v4 v4.7.1 // indirect
52新增: github.com/buger/jsonparser v1.1.2 // indirect
53新增: github.com/cheggaaa/pb/v3 v3.2.1 // indirect
54新增: github.com/cilium/ebpf v0.22.0 // indirect
55新增: github.com/clipperhouse/uax29/v2 v2.2.0 // indirect
56新增: github.com/containerd/cgroups/v3 v3.1.3 // indirect
57新增: github.com/containerd/errdefs v1.0.0 // indirect
58新增: github.com/containerd/errdefs/pkg v0.3.0 // indirect
59新增: github.com/containerd/log v0.1.0 // indirect
60新增: github.com/containerd/typeurl/v2 v2.3.0 // indirect
61新增: github.com/containers/gvisor-tap-vsock v0.8.9 // indirect
62新增: github.com/coreos/go-systemd/v22 v22.7.0 // indirect
63新增: github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
64新增: github.com/digitalocean/go-libvirt v0.0.0-20220804181439-8648fbde413e // indirect
65新增: github.com/digitalocean/go-qemu v0.0.0-20221209210016-f035778c97f7 // indirect
66新增: github.com/dimchansky/utfbom v1.1.1 // indirect
67新增: github.com/diskfs/go-diskfs v1.9.4 // indirect
68新增: github.com/djherbis/times v1.6.0 // indirect
69新增: github.com/elliotchance/orderedmap v1.8.0 // indirect
70新增: github.com/fatih/color v1.19.0 // indirect
71新增: github.com/fsnotify/fsnotify v1.8.0 // indirect
72新增: github.com/go-ini/ini v1.67.0 // indirect
73新增: github.com/goccy/go-json v0.10.6 // indirect
74新增: github.com/goccy/go-yaml v1.19.2 // indirect
75新增: github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
76新增: github.com/google/btree v1.1.3 // indirect
77新增: github.com/google/go-cmp v0.7.0 // indirect
78新增: github.com/google/gopacket v1.1.19 // indirect
79新增: github.com/google/yamlfmt v0.21.0 // indirect
80新增: github.com/hashicorp/hcl/v2 v2.24.0 // indirect
81新增: github.com/inconshreveable/mousetrap v1.1.0 // indirect
82新增: github.com/inetaf/tcpproxy v0.0.0-20250222171855-c4b9df066048 // indirect
83新增: github.com/insomniacslk/dhcp v0.0.0-20260901064844-234b97448fae // indirect
84新增: github.com/invopop/jsonschema v0.14.0 // indirect
85新增: github.com/jinzhu/copier v0.4.0 // indirect
86新增: github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
87新增: github.com/kr/fs v0.1.0 // indirect
88新增: github.com/lima-vm/go-qcow2reader v0.8.0 // indirect
89新增: github.com/linuxkit/virtsock v0.0.0-20220523201153-1a23e78aa7a2 // indirect
90新增: github.com/magiconair/properties v1.18.11 // indirect
91新增: github.com/mattn/go-colorable v0.1.15 // indirect
92新增: github.com/mattn/go-runewidth v0.0.27 // indirect
93新增: github.com/mattn/go-shellwords v1.0.15 // indirect
94新增: github.com/mdlayher/netlink v1.11.2 // indirect
95新增: github.com/mdlayher/socket v0.6.0 // indirect
96新增: github.com/mdlayher/vsock v1.3.0 // indirect
97新增: github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
98新增: github.com/miekg/dns v1.1.73 // indirect
99新增: github.com/mikefarah/yq/v4 v4.53.6 // indirect
100新增: github.com/mitchellh/go-wordwrap v1.0.1 // indirect
101新增: github.com/mitchellh/mapstructure v1.5.0 // indirect
102新增: github.com/nxadm/tail v1.4.11 // indirect
103新增: github.com/opencontainers/go-digest v1.0.0 // indirect
104新增: github.com/pb33f/ordered-map/v2 v2.3.1 // indirect
105新增: github.com/pelletier/go-toml/v2 v2.4.3 // indirect
106新增: github.com/pierrec/lz4/v4 v4.1.26 // indirect
107新增: github.com/pkg/errors v0.9.1 // indirect
108新增: github.com/pkg/sftp v1.13.11 // indirect
109新增: github.com/rjeczalik/notify v0.9.3 // indirect
110新增: github.com/russross/blackfriday/v2 v2.1.0 // indirect
111新增: github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
112新增: github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 // indirect
113新增: github.com/sethvargo/go-password v0.4.0 // indirect
114新增: github.com/spakin/netpbm v1.3.2 // indirect
115新增: github.com/spf13/pflag v1.0.10 // indirect
116新增: github.com/u-root/uio v0.0.0-20240224005618-d2acac8f3701 // indirect
117新增: github.com/yuin/gopher-lua v1.1.2 // indirect
118新增: github.com/zclconf/go-cty v1.19.0 // indirect
119新增: go.opencensus.io v0.24.0 // indirect
120新增: go.yaml.in/yaml/v3 v3.0.5 // indirect
121新增: go.yaml.in/yaml/v4 v4.0.0-rc.6 // indirect
122新增: golang.org/x/crypto v0.57.0 // indirect
123新增: golang.org/x/image v0.46.0 // indirect
124新增: golang.org/x/mod v0.41.0 // indirect
125新增: golang.org/x/net v0.60.0 // indirect
126新增: golang.org/x/sync v0.23.0 // indirect
127新增: golang.org/x/text v0.42.0 // indirect
128新增: golang.org/x/time v0.15.0 // indirect
129新增: golang.org/x/tools v0.49.0 // indirect
130新增: google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect
131新增: google.golang.org/grpc v1.83.2 // indirect
132新增: google.golang.org/protobuf v1.36.12 // indirect
133新增: gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 // indirect
134新增: gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
135新增: gvisor.dev/gvisor v0.0.0-20240916094835-a174eb65023f // indirect
136新增:)
新增go.sum+433 −0看文件
@@ -0,0 +1,433 @@
1新增:al.essio.dev/pkg/shellescape v1.6.1 h1:ki/kUs/D3dDbZpyKbNRhwY/ajgAEIJFagVKDWKnofQ8=
2新增:al.essio.dev/pkg/shellescape v1.6.1/go.mod h1:6sIqp7X2P6mThCQ7twERpZTuigpr6KbZWtls1U8I890=
3新增:cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
4新增:github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
5新增:github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
6新增:github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
7新增:github.com/Code-Hex/go-infinity-channel v1.0.0 h1:M8BWlfDOxq9or9yvF9+YkceoTkDI1pFAqvnP87Zh0Nw=
8新增:github.com/Code-Hex/go-infinity-channel v1.0.0/go.mod h1:5yUVg/Fqao9dAjcpzoQ33WwfdMWmISOrQloDRn3bsvY=
9新增:github.com/Code-Hex/vz/v3 v3.7.1 h1:EN1yNiyrbPq+dl388nne2NySo8I94EnPppvqypA65XM=
10新增:github.com/Code-Hex/vz/v3 v3.7.1/go.mod h1:1LsW0jqW0r0cQ+IeR4hHbjdqOtSidNCVMWhStMHGho8=
11新增:github.com/Microsoft/go-winio v0.6.3-0.20251027160822-ad3df93bed29 h1:0kQAzHq8vLs7Pptv+7TxjdETLf/nIqJpIB4oC6Ba4vY=
12新增:github.com/Microsoft/go-winio v0.6.3-0.20251027160822-ad3df93bed29/go.mod h1:ZWa7ssZJT30CCDGJ7fk/2SBTq9BIQrrVjrcss0UW2s0=
13新增:github.com/Microsoft/hcsshim v0.14.1 h1:CMuB3fqQVfPdhyXhUqYdUmPUIOhJkmghCx3dJet8Cqs=
14新增:github.com/Microsoft/hcsshim v0.14.1/go.mod h1:VnzvPLyWUhxiPVsJ31P6XadxCcTogTguBFDy/1GR/OM=
15新增:github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
16新增:github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
17新增:github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
18新增:github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
19新增:github.com/a8m/envsubst v1.4.3 h1:kDF7paGK8QACWYaQo6KtyYBozY2jhQrTuNNuUxQkhJY=
20新增:github.com/a8m/envsubst v1.4.3/go.mod h1:4jjHWQlZoaXPoLQUb7H2qT4iLkZDdmEQiOUogdUmqVU=
21新增:github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
22新增:github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
23新增:github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
24新增:github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
25新增:github.com/alecthomas/participle/v2 v2.1.4 h1:W/H79S8Sat/krZ3el6sQMvMaahJ+XcM9WSI2naI7w2U=
26新增:github.com/alecthomas/participle/v2 v2.1.4/go.mod h1:8tqVbpTX20Ru4NfYQgZf4mP18eXPTBViyMWiArNEgGI=
27新增:github.com/alecthomas/repr v0.5.4 h1:OVP7JEcuzU9CCDsT6STCr3rg17oQfWILtPWd2EG0uN4=
28新增:github.com/alecthomas/repr v0.5.4/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
29新增:github.com/anchore/go-lzo v0.1.0 h1:NgAacnzqPeGH49Ky19QKLBZEuFRqtTG9cdaucc3Vncs=
30新增:github.com/anchore/go-lzo v0.1.0/go.mod h1:3kLx0bve2oN1iDwgM1U5zGku1Tfbdb0No5qp1eL1fIk=
31新增:github.com/apparentlymart/go-cidr v1.1.1 h1:oEEk8CE0HP0YpHxsegk/TaOtR2FLHdWv4p3eM4ceUwg=
32新增:github.com/apparentlymart/go-cidr v1.1.1/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc=
33新增:github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
34新增:github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
35新增:github.com/apparentlymart/go-textseg/v17 v17.0.1 h1:bpMXRgQ5cEoRNuQke1a80/Nl6w3G5eoIbWo9f3gXkAs=
36新增:github.com/apparentlymart/go-textseg/v17 v17.0.1/go.mod h1:fa8X4jgGeevslICIY6LcdjkSecWnXmYd9Lk34z/VxZs=
37新增:github.com/armon/go-proxyproto v0.0.0-20210323213023-7e956b284f0a/go.mod h1:QmP9hvJ91BbJmGVGSbutW19IC0Q9phDCLGaomwTJbgU=
38新增:github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
39新增:github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
40新增:github.com/balajiv113/fd v0.0.0-20230330094840-143eec500f3e h1:IdMhFPEfTZQU971tIHx3UhY4l+yCeynprnINrDTSrOc=
41新增:github.com/balajiv113/fd v0.0.0-20230330094840-143eec500f3e/go.mod h1:aXGMJsd3XrnUFTuyf/pTGg5jG6CY8JMZ5juywvShjgQ=
42新增:github.com/bmatcuk/doublestar/v4 v4.7.1 h1:fdDeAqgT47acgwd9bd9HxJRDmc9UAmPpc+2m0CXv75Q=
43新增:github.com/bmatcuk/doublestar/v4 v4.7.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
44新增:github.com/buger/jsonparser v1.1.2 h1:frqHqw7otoVbk5M8LlE/L7HTnIq2v9RX6EJ48i9AxJk=
45新增:github.com/buger/jsonparser v1.1.2/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
46新增:github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
47新增:github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
48新增:github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
49新增:github.com/cheggaaa/pb/v3 v3.2.1 h1:aprZbFRG+B7+ug76S8QZ6Y1PW168UHzOmbC3wa+aU6I=
50新增:github.com/cheggaaa/pb/v3 v3.2.1/go.mod h1:U9hSVxoKqJrZIE3PkFG1xXXNaK/Ilzg+EF/scpXzEdw=
51新增:github.com/cilium/ebpf v0.22.0 h1:v2ktp0roffpMOj2MMf3idtCQZOsAoC4BJbAJN+ke2bY=
52新增:github.com/cilium/ebpf v0.22.0/go.mod h1:CDzZbe2hC5JjlDC+CY3KFCzlYwN4gbxppYM+Z10bQt4=
53新增:github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
54新增:github.com/clipperhouse/uax29/v2 v2.2.0 h1:ChwIKnQN3kcZteTXMgb1wztSgaU+ZemkgWdohwgs8tY=
55新增:github.com/clipperhouse/uax29/v2 v2.2.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
56新增:github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
57新增:github.com/containerd/cgroups/v3 v3.1.3 h1:eUNflyMddm18+yrDmZPn3jI7C5hJ9ahABE5q6dyLYXQ=
58新增:github.com/containerd/cgroups/v3 v3.1.3/go.mod h1:PKZ2AcWmSBsY/tJUVhtS/rluX0b1uq1GmPO1ElCmbOw=
59新增:github.com/containerd/continuity v0.5.0 h1:7a85HZpCSs+1Zps0Ee3DPSuAWY+0SJM1JNM51nlEVDg=
60新增:github.com/containerd/continuity v0.5.0/go.mod h1:/lNJvtJKUQStBzpVQ1+rasXO1LAWtUQssk28EZvJ3nE=
61新增:github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI=
62新增:github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=
63新增:github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE=
64新增:github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk=
65新增:github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
66新增:github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
67新增:github.com/containerd/typeurl/v2 v2.3.0 h1:HZHPhRWo5XMy3QGQoPrUzbW/2ckwjfweHmOwlkIrPAQ=
68新增:github.com/containerd/typeurl/v2 v2.3.0/go.mod h1:Qk+PAdUYArVj41TnGi6rJ+48RF0PkcTc4i/taoBcK0w=
69新增:github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
70新增:github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
71新增:github.com/coreos/go-systemd/v22 v22.7.0 h1:LAEzFkke61DFROc7zNLX/WA2i5J8gYqe0rSj9KI28KA=
72新增:github.com/coreos/go-systemd/v22 v22.7.0/go.mod h1:xNUYtjHu2EDXbsxz1i41wouACIwT7Ybq9o0BQhMwD0w=
73新增:github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
74新增:github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
75新增:github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
76新增:github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
77新增:github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
78新增:github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
79新增:github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
80新增:github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
81新增:github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
82新增:github.com/digitalocean/go-libvirt v0.0.0-20220804181439-8648fbde413e h1:SCnqm8SjSa0QqRxXbo5YY//S+OryeJioe17nK+iDZpg=
83新增:github.com/digitalocean/go-libvirt v0.0.0-20220804181439-8648fbde413e/go.mod h1:o129ljs6alsIQTc8d6eweihqpmmrbxZ2g1jhgjhPykI=
84新增:github.com/digitalocean/go-qemu v0.0.0-20221209210016-f035778c97f7 h1:3OVJAbR131SnAXao7c9w8bFlAGH0oa29DCwsa88MJGk=
85新增:github.com/digitalocean/go-qemu v0.0.0-20221209210016-f035778c97f7/go.mod h1:K4+o74YGNjOb9N6yyG+LPj1NjHtk+Qz0IYQPvirbaLs=
86新增:github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U=
87新增:github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE=
88新增:github.com/diskfs/go-diskfs v1.9.4 h1:0j2d7eG4IjyxL6+ChWbDPocdBCF6HQ4HBWU2WDYWVnc=
89新增:github.com/diskfs/go-diskfs v1.9.4/go.mod h1:TePJORO83Adh5pb2SqsxAwaP0fofFxKLkxctiS/9OQc=
90新增:github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
91新增:github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
92新增:github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
93新增:github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
94新增:github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
95新增:github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
96新增:github.com/elliotchance/orderedmap v1.8.0 h1:TrOREecvh3JbS+NCgwposXG5ZTFHtEsQiCGOhPElnMw=
97新增:github.com/elliotchance/orderedmap v1.8.0/go.mod h1:wsDwEaX5jEoyhbs7x93zk2H/qv0zwuhg4inXhDkYqys=
98新增:github.com/elliotwutingfeng/asciiset v0.0.0-20260129054604-cfde2086bc57 h1:x5yxNrq8XffV/OoNUeFPM6hxHVi5OTspSTBxr/9pemg=
99新增:github.com/elliotwutingfeng/asciiset v0.0.0-20260129054604-cfde2086bc57/go.mod h1:GLo/8fDswSAniFG+BFIaiSPcK610jyzgEhWYPQwuQdw=
100新增:github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
101新增:github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
102新增:github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
103新增:github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
104新增:github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w=
105新增:github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE=
106新增:github.com/foxcpp/go-mockdns v1.2.0 h1:omK3OrHRD1IWJz1FuFBCFquhXslXoF17OvBS6JPzZF0=
107新增:github.com/foxcpp/go-mockdns v1.2.0/go.mod h1:IhLeSFGed3mJIAXPH2aiRQB+kqz7oqu8ld2qVbOu7Wk=
108新增:github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
109新增:github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
110新增:github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
111新增:github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
112新增:github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
113新增:github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
114新增:github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
115新增:github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
116新增:github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
117新增:github.com/go-quicktest/qt v1.101.1-0.20240301121107-c6c8733fa1e6 h1:teYtXy9B7y5lHTp8V9KPxpYRAVA7dozigQcMiBust1s=
118新增:github.com/go-quicktest/qt v1.101.1-0.20240301121107-c6c8733fa1e6/go.mod h1:p4lGIVX+8Wa6ZPNDvqcxq36XpUDLh42FLetFU7odllI=
119新增:github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U=
120新增:github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
121新增:github.com/goccy/go-json v0.10.6 h1:p8HrPJzOakx/mn/bQtjgNjdTcN+/S6FcG2CTtQOrHVU=
122新增:github.com/goccy/go-json v0.10.6/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
123新增:github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM=
124新增:github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
125新增:github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
126新增:github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
127新增:github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
128新增:github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
129新增:github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
130新增:github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
131新增:github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
132新增:github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
133新增:github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
134新增:github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
135新增:github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
136新增:github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
137新增:github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
138新增:github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
139新增:github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
140新增:github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
141新增:github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg=
142新增:github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
143新增:github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
144新增:github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
145新增:github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
146新增:github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
147新增:github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
148新增:github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
149新增:github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
150新增:github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
151新增:github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8=
152新增:github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo=
153新增:github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
154新增:github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
155新增:github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
156新增:github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
157新增:github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
158新增:github.com/google/yamlfmt v0.21.0 h1:9FKApQkDpMKgBjwLFytBHUCgqnQgxaQnci0uiESfbzs=
159新增:github.com/google/yamlfmt v0.21.0/go.mod h1:q6FYExB+Ueu7jZDjKECJk+EaeDXJzJ6Ne0dxx69GWfI=
160新增:github.com/hashicorp/hcl/v2 v2.24.0 h1:2QJdZ454DSsYGoaE6QheQZjtKZSUs9Nh2izTWiwQxvE=
161新增:github.com/hashicorp/hcl/v2 v2.24.0/go.mod h1:oGoO1FIQYfn/AgyOhlg9qLC6/nOJPX3qGbkZpYAcqfM=
162新增:github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
163新增:github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
164新增:github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
165新增:github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
166新增:github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
167新增:github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
168新增:github.com/inetaf/tcpproxy v0.0.0-20250222171855-c4b9df066048 h1:jaqViOFFlZtkAwqvwZN+id37fosQqR5l3Oki9Dk4hz8=
169新增:github.com/inetaf/tcpproxy v0.0.0-20250222171855-c4b9df066048/go.mod h1:Di7LXRyUcnvAcLicFhtM9/MlZl/TNgRSDHORM2c6CMI=
170新增:github.com/insomniacslk/dhcp v0.0.0-20260901064844-234b97448fae h1:nXGg65fXsylSUTNNWwvHuQsXev7mhIzQTnZREPTbWzs=
171新增:github.com/insomniacslk/dhcp v0.0.0-20260901064844-234b97448fae/go.mod h1:tGfUTcnFYGYvVNCaZZhwlJySU/fQQxh9TmpsFzWXnnY=
172新增:github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg=
173新增:github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I=
174新增:github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
175新增:github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
176新增:github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
177新增:github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
178新增:github.com/jsimonetti/rtnetlink v1.3.5 h1:hVlNQNRlLDGZz31gBPicsG7Q53rnlsz1l1Ix/9XlpVA=
179新增:github.com/jsimonetti/rtnetlink/v2 v2.0.1 h1:xda7qaHDSVOsADNouv7ukSuicKZO7GgVUCXxpaIEIlM=
180新增:github.com/jsimonetti/rtnetlink/v2 v2.0.1/go.mod h1:7MoNYNbb3UaDHtF8udiJo/RH6VsTKP1pqKLUTVCvToE=
181新增:github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
182新增:github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
183新增:github.com/klauspost/compress v1.18.5 h1:/h1gH5Ce+VWNLSWqPzOVn6XBO+vJbCNGvjoaGBFW2IE=
184新增:github.com/klauspost/compress v1.18.5/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
185新增:github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
186新增:github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
187新增:github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
188新增:github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
189新增:github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
190新增:github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
191新增:github.com/lima-vm/go-qcow2reader v0.8.0 h1:9XiPUbOt+mBjwwDZ1B7E6V8bHNjYs0/k6qQw21/jOtE=
192新增:github.com/lima-vm/go-qcow2reader v0.8.0/go.mod h1:Ai9fcmE2dXF6YFomrSCttveOT1x3+x5eG7AfIUUnSqw=
193新增:github.com/linuxkit/virtsock v0.0.0-20220523201153-1a23e78aa7a2 h1:DZMFueDbfz6PNc1GwDRA8+6lBx1TB9UnxDQliCqR73Y=
194新增:github.com/linuxkit/virtsock v0.0.0-20220523201153-1a23e78aa7a2/go.mod h1:SWzULI85WerrFt3u+nIm5F9l7EvxZTKQvd0InF3nmgM=
195新增:github.com/magiconair/properties v1.18.11 h1:j5ozYZl0zCjG7ahMDH0GWIobOvvUzT0BdAguG0ViKy0=
196新增:github.com/magiconair/properties v1.18.11/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
197新增:github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
198新增:github.com/mattn/go-colorable v0.1.15 h1:+u9SLTRGnXv73cEsnsmoZBom+dMU88B2M0aDcWy0/jY=
199新增:github.com/mattn/go-colorable v0.1.15/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
200新增:github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
201新增:github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI=
202新增:github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A=
203新增:github.com/mattn/go-runewidth v0.0.27 h1:Feg/Oou5zI/wnpgDF6omIU0OokC9GxLC/WRknhVlIR0=
204新增:github.com/mattn/go-runewidth v0.0.27/go.mod h1:3qAiGCV4Koz/yuveO58qUefmUTRm8r0IGEXZ9jeHp/8=
205新增:github.com/mattn/go-shellwords v1.0.15 h1:rx0n8+ZdM9JWZMlr2BMPAjtLU0rfluLNtwMC2FJOTtY=
206新增:github.com/mattn/go-shellwords v1.0.15/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
207新增:github.com/mdlayher/netlink v1.11.2 h1:HKh2jqe+omdSWcQ88nrT7INE61B0NXfiSPFdgL4YbNI=
208新增:github.com/mdlayher/netlink v1.11.2/go.mod h1:uT2Yc/QLaZubzDpZIBi9d4GoeLwtp3x1AMeqSRrK2sA=
209新增:github.com/mdlayher/packet v1.1.2 h1:3Up1NG6LZrsgDVn6X4L9Ge/iyRyxFEFD9o6Pr3Q1nQY=
210新增:github.com/mdlayher/packet v1.1.2/go.mod h1:GEu1+n9sG5VtiRE4SydOmX5GTwyyYlteZiFU+x0kew4=
211新增:github.com/mdlayher/socket v0.6.0 h1:ScZPaAGyO1icQnbFrhPM8mnXyMu9qukC1K4ZoM2IQKU=
212新增:github.com/mdlayher/socket v0.6.0/go.mod h1:q7vozUAnxSqnjHc12Fik5yUKIzfZ8ITCfMkhOtE9z18=
213新增:github.com/mdlayher/vsock v1.3.0 h1:bqQfZ1OznI03y6YiXp2sze05RVdzLn/zsfjnjd4+ivI=
214新增:github.com/mdlayher/vsock v1.3.0/go.mod h1:WsuksavOvwCnV5UqGHUkvAvCy+Dqy81y4goKQTzxxNY=
215新增:github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
216新增:github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
217新增:github.com/miekg/dns v1.1.73 h1:uhT8nJxmTrPJYClxVxTCX+CVn6qnzSiybRk72Z6DgrE=
218新增:github.com/miekg/dns v1.1.73/go.mod h1:RW2Obtfd5NZHvOFe3zYG0W8koWOQtAzyHaLo8vASBuQ=
219新增:github.com/mikefarah/yq/v4 v4.53.6 h1:5vB15LTZRvrF6z/metQF31bmF63SjDzCKKX8o8UemQQ=
220新增:github.com/mikefarah/yq/v4 v4.53.6/go.mod h1:3tmDcCSTOTUFa5Z1X8R4j0H1kauIwNo2wjKq9sLyAh4=
221新增:github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
222新增:github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
223新增:github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
224新增:github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
225新增:github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
226新增:github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
227新增:github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
228新增:github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
229新增:github.com/onsi/gomega v1.39.1 h1:1IJLAad4zjPn2PsnhH70V4DKRFlrCzGBNrNaru+Vf28=
230新增:github.com/onsi/gomega v1.39.1/go.mod h1:hL6yVALoTOxeWudERyfppUcZXjMwIMLnuSfruD2lcfg=
231新增:github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
232新增:github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
233新增:github.com/pb33f/ordered-map/v2 v2.3.1 h1:5319HDO0aw4DA4gzi+zv4FXU9UlSs3xGZ40wcP1nBjY=
234新增:github.com/pb33f/ordered-map/v2 v2.3.1/go.mod h1:qxFQgd0PkVUtOMCkTapqotNgzRhMPL7VvaHKbd1HnmQ=
235新增:github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0=
236新增:github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
237新增:github.com/pelletier/go-toml/v2 v2.4.3 h1:GTRvJQutkOSftxIFD5xw9aepkYNuPWmVJpffdDPYVpY=
238新增:github.com/pelletier/go-toml/v2 v2.4.3/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
239新增:github.com/pierrec/lz4/v4 v4.1.26 h1:GrpZw1gZttORinvzBdXPUXATeqlJjqUG/D87TKMnhjY=
240新增:github.com/pierrec/lz4/v4 v4.1.26/go.mod h1:EoQMVJgeeEOMsCqCzqFm2O0cJvljX2nGZjcRIPL34O4=
241新增:github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A=
242新增:github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
243新增:github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
244新增:github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
245新增:github.com/pkg/xattr v0.4.12 h1:rRTkSyFNTRElv6pkA3zpjHpQ90p/OdHQC1GmGh1aTjM=
246新增:github.com/pkg/xattr v0.4.12/go.mod h1:di8WF84zAKk8jzR1UBTEWh9AUlIZZ7M/JNt8e9B6ktU=
247新增:github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
248新增:github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
249新增:github.com/rjeczalik/notify v0.9.3 h1:6rJAzHTGKXGj76sbRgDiDcYj/HniypXmSJo1SWakZeY=
250新增:github.com/rjeczalik/notify v0.9.3/go.mod h1:gF3zSOrafR9DQEWSE8TjfI9NkooDxbyT4UgRGKZA0lc=
251新增:github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
252新增:github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
253新增:github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
254新增:github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
255新增:github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
256新增:github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
257新增:github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 h1:1EYB5IzjZawrrnELUi78f9fPu57HuXjmddZPjrls/28=
258新增:github.com/santhosh-tekuri/jsonschema/v6 v6.0.3/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
259新增:github.com/sethvargo/go-password v0.4.0 h1:eSidVKQw5C7CmTDAtH3RipBTSjdU1ZRxQaynD2GWLVU=
260新增:github.com/sethvargo/go-password v0.4.0/go.mod h1:PO3nYHwUpcHPR0F9woy7a4abZPvzRuqJr0GaeIYTm3k=
261新增:github.com/sirupsen/logrus v1.10.2 h1:G2SED73/qrAu6YwbdxOD6peLkCBI3z7L+ykJFTXJBBo=
262新增:github.com/sirupsen/logrus v1.10.2/go.mod h1:SLEg8TqYulVKKfIGHldVp2K2aYz2DKSVBq4g/H5bR7Q=
263新增:github.com/spakin/netpbm v1.3.2 h1:ZAb16Sw/+b4QeO9NokEvejVvbrYdF6DdcYJe0dKONL0=
264新增:github.com/spakin/netpbm v1.3.2/go.mod h1:cVep9uXARFgAu2UU+0c+OE1J+eKmDN2hW0EN+tazkTA=
265新增:github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
266新增:github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
267新增:github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
268新增:github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
269新增:github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
270新增:github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
271新增:github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
272新增:github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
273新增:github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
274新增:github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
275新增:github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
276新增:github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
277新增:github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
278新增:github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
279新增:github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
280新增:github.com/u-root/uio v0.0.0-20240224005618-d2acac8f3701 h1:pyC9PaHYZFgEKFdlp3G8RaCKgVpHZnecvArXvPXcFkM=
281新增:github.com/u-root/uio v0.0.0-20240224005618-d2acac8f3701/go.mod h1:P3a5rG4X7tI17Nn3aOIAYr5HbIMukwXG0urG0WuL8OA=
282新增:github.com/ulikunitz/xz v0.5.15 h1:9DNdB5s+SgV3bQ2ApL10xRc35ck0DuIX/isZvIk+ubY=
283新增:github.com/ulikunitz/xz v0.5.15/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
284新增:github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
285新增:github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
286新增:github.com/yuin/gopher-lua v1.1.2 h1:yF/FjE3hD65tBbt0VXLE13HWS9h34fdzJmrWRXwobGA=
287新增:github.com/yuin/gopher-lua v1.1.2/go.mod h1:7aRmXIWl37SqRf0koeyylBEzJ+aPt8A+mmkQ4f1ntR8=
288新增:github.com/zclconf/go-cty v1.19.0 h1:IV8WdqYZc2c5rLX9bEoLNXKojBAp0MZPBHMIrCoa/s4=
289新增:github.com/zclconf/go-cty v1.19.0/go.mod h1:12W89jGn3JCOIQi7infWr9m80rOkb5RNYJqXMZcN4c8=
290新增:github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo=
291新增:github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM=
292新增:go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
293新增:go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
294新增:go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
295新增:go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
296新增:go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU=
297新增:go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc=
298新增:go.opentelemetry.io/otel/metric v1.44.0 h1:1w0gILTcHdr3YI+ixLyjemwrVnsMURbTZFrSYCdDdmc=
299新增:go.opentelemetry.io/otel/metric v1.44.0/go.mod h1:8O7hanEPBNgEMmybD3s2VBKcgWOCsA6tzHBPODAiquo=
300新增:go.opentelemetry.io/otel/sdk v1.44.0 h1:nHYwb9lK+fJPU/dnT6s7W7Z8itMWyqrnVfbheVYrZ58=
301新增:go.opentelemetry.io/otel/sdk v1.44.0/go.mod h1:Osuydd3Se74nqjAKxid74N5eC+jfEqfTegHRnq58oK0=
302新增:go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRks6si09iEfI=
303新增:go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA=
304新增:go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk=
305新增:go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE=
306新增:go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
307新增:go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
308新增:go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
309新增:go.yaml.in/yaml/v4 v4.0.0-rc.6 h1:1h7H1ohdUh93/FyE4YaDa1Zh64K6VVbjF4K6WUxMtH4=
310新增:go.yaml.in/yaml/v4 v4.0.0-rc.6/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
311新增:golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
312新增:golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
313新增:golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
314新增:golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
315新增:golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
316新增:golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
317新增:golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
318新增:golang.org/x/image v0.46.0 h1:b1+oYj0Jbp6K5MDT4i4/eZpYlk3V8SJhhDKh6LBHAyQ=
319新增:golang.org/x/image v0.46.0/go.mod h1:3B3W05VGVQyuXucLINLjXKrqISASfi4Xj+iCVkLMwew=
320新增:golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
321新增:golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
322新增:golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
323新增:golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
324新增:golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
325新增:golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
326新增:golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
327新增:golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c=
328新增:golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o=
329新增:golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
330新增:golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
331新增:golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
332新增:golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
333新增:golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
334新增:golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
335新增:golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
336新增:golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
337新增:golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
338新增:golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
339新增:golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
340新增:golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
341新增:golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
342新增:golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
343新增:golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
344新增:golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
345新增:golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
346新增:golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
347新增:golang.org/x/sync v0.23.0 h1:KameEIfc1IkluZyXWLn39Wd4tURc6GbCiISGiZm2bQk=
348新增:golang.org/x/sync v0.23.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
349新增:golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
350新增:golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
351新增:golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
352新增:golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
353新增:golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
354新增:golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
355新增:golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
356新增:golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
357新增:golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
358新增:golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
359新增:golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
360新增:golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
361新增:golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
362新增:golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
363新增:golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
364新增:golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
365新增:golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
366新增:golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
367新增:golang.org/x/term v0.46.0 h1:3+OXuTbaKDgwk8jTi3aSLHRlmWqHEUDUtxnbFigO4YE=
368新增:golang.org/x/term v0.46.0/go.mod h1:+K02xbkittuwc0Am4abfA3Fc+XRGXkvBXNO88NCXPoc=
369新增:golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
370新增:golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
371新增:golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
372新增:golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
373新增:golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI=
374新增:golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E=
375新增:golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
376新增:golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
377新增:golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
378新增:golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
379新增:golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
380新增:golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
381新增:golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
382新增:golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
383新增:golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
384新增:golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
385新增:golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
386新增:golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI=
387新增:golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo=
388新增:golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
389新增:golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
390新增:golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
391新增:golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
392新增:gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
393新增:gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
394新增:google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
395新增:google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
396新增:google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
397新增:google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
398新增:google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
399新增:google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa h1:mZHHdPZl0dbGHCflZgAq/Q468DWVFcU2whhB2KAo8fk=
400新增:google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
401新增:google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
402新增:google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
403新增:google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
404新增:google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
405新增:google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
406新增:google.golang.org/grpc v1.83.2 h1:EManeRomTObA0BU7I8vXgg/78uE5MJ9M8B39EX2WscU=
407新增:google.golang.org/grpc v1.83.2/go.mod h1:YPI1hK3kDked6iHvgX3tR0y+nX/qpMFKhPgFsokw1S8=
408新增:google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
409新增:google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
410新增:google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
411新增:google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
412新增:google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
413新增:google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
414新增:google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
415新增:google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
416新增:google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
417新增:google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
418新增:google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
419新增:gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
420新增:gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
421新增:gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 h1:6D+BvnJ/j6e222UW8s2qTSe3wGBtvo0MbVQG/c5k8RE=
422新增:gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473/go.mod h1:N1eN2tsCx0Ydtgjl4cqmbRCsY4/+z4cYDeqwZTk6zog=
423新增:gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
424新增:gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
425新增:gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
426新增:gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
427新增:gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
428新增:gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
429新增:gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
430新增:gvisor.dev/gvisor v0.0.0-20240916094835-a174eb65023f h1:O2w2DymsOlM/nv2pLNWCMCYOldgBBMkD7H0/prN5W2k=
431新增:gvisor.dev/gvisor v0.0.0-20240916094835-a174eb65023f/go.mod h1:sxc3Uvk/vHcd3tj7/DHVBoR5wvWT/MmRq2pj7HRJnwU=
432新增:honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
433新增:honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
删除install.sh+0 −2
@@ -1,2 +0,0 @@
1删除:#!/usr/bin/env bash
2删除:exec bash "$(dirname "$0")/agent-vm.sh" "$([ "${1:-}" = --uninstall ] && echo uninstall || echo install)"
新增internal/bashref/bashref.go+272 −0看文件
@@ -0,0 +1,272 @@
1新增:// Package bashref gives the results of the bash implementation (0.2's
2新增:// agent-vm.sh and lib/), for tests that compare the Go code with it. They
3新增:// were recorded, before the bash version was removed, in each calling
4新增:// package's testdata/bashref: a test's calls must stay the ones recorded.
5新增:package bashref
6新增:
7新增:import (
8新增: "encoding/json"
9新增: "fmt"
10新增: "os"
11新增: "path/filepath"
12新增: "reflect"
13新增: "regexp"
14新增: "runtime"
15新增: "slices"
16新增: "strings"
17新增: "sync"
18新增: "testing"
19新增:)
20新增:
21新增:// Root is the repository's root, where agent-vm.sh was.
22新增:func Root() string {
23新增: _, file, _, _ := runtime.Caller(0)
24新增: return filepath.Join(filepath.Dir(file), "..", "..")
25新增:}
26新增:
27新增:// Result of a bash function. Files holds the content of each file asked
28新增:// for that exists afterwards.
29新增:type Result struct {
30新增: Stdout, Stderr string
31新增: Code int
32新增: Files map[string]string `json:",omitempty"`
33新增:}
34新增:
35新增:// Cmd is a bash snippet, run after agent-vm.sh is sourced, with Args as
36新增:// "$@", from Dir (the repository's root when empty), with HOME in a
37新增:// temporary folder and Env added. Files are read once it has run.
38新增:type Cmd struct {
39新增: Dir string `json:",omitempty"`
40新增: Env []string `json:",omitempty"`
41新增: Stdin string `json:",omitempty"`
42新增: Snippet string
43新增: Args []string `json:",omitempty"`
44新增: Files []string `json:",omitempty"`
45新增:}
46新增:
47新增:// Run runs fn with args (see Cmd).
48新增:func Run(t testing.TB, dir string, env []string, fn string, args ...string) Result {
49新增: t.Helper()
50新增: return Exec(t, Cmd{Dir: dir, Env: env, Snippet: `"$@"`, Args: append([]string{fn}, args...)})
51新增:}
52新增:
53新增:// Script runs snippet with args (see Cmd).
54新增:func Script(t testing.TB, dir string, env []string, snippet string, args ...string) Result {
55新增: t.Helper()
56新增: return Exec(t, Cmd{Dir: dir, Env: env, Snippet: snippet, Args: args})
57新增:}
58新增:
59新增:// Exec gives c's result as recorded. Skipped on Windows, never compared
60新增:// there.
61新增:func Exec(t testing.TB, c Cmd) Result {
62新增: t.Helper()
63新增: if runtime.GOOS == "windows" {
64新增: t.Skip("the bash reference is not compared on Windows")
65新增: }
66新增: if c.Dir == "" {
67新增: c.Dir = Root()
68新增: }
69新增: // Resolved, as the tests' own folders are: on macOS /var is a link to
70新增: // /private/var, and a second spelling of the same folder gets its
71新增: // recorded paths read back under the wrong one (see paths).
72新增: c.Env = append([]string{"HOME=" + evalOr(t.TempDir())}, c.Env...)
73新增: return replay(t, c)
74新增:}
75新增:
76新增:// A recorded call, its paths made portable (see paths).
77新增:type entry struct {
78新增: Cmd Cmd
79新增: Result Result
80新增:}
81新增:
82新增:// The JSON of an entry: strings that are not UTF-8 (JSON would replace
83新增:// their bytes) in base64.
84新增:type entryJSON struct {
85新增: Dir, Stdin, Snippet str
86新增: Env, Args, Files []str
87新增: Stdout, Stderr str
88新增: Code int
89新增: Out map[string]str `json:",omitempty"`
90新增:}
91新增:
92新增:type str string
93新增:
94新增:func (s *str) UnmarshalJSON(b []byte) error {
95新增: var raw map[string][]byte
96新增: if json.Unmarshal(b, &raw) == nil {
97新增: *s = str(raw["base64"])
98新增: return nil
99新增: }
100新增: return json.Unmarshal(b, (*string)(s))
101新增:}
102新增:
103新增:func strs(in []str) []string {
104新增: var out []string
105新增: for _, s := range in {
106新增: out = append(out, string(s))
107新增: }
108新增: return out
109新增:}
110新增:
111新增:func (e *entry) UnmarshalJSON(b []byte) error {
112新增: var j entryJSON
113新增: if err := json.Unmarshal(b, &j); err != nil {
114新增: return err
115新增: }
116新增: *e = entry{Cmd: Cmd{Dir: string(j.Dir), Stdin: string(j.Stdin), Snippet: string(j.Snippet),
117新增: Env: strs(j.Env), Args: strs(j.Args), Files: strs(j.Files)},
118新增: Result: Result{Stdout: string(j.Stdout), Stderr: string(j.Stderr), Code: j.Code}}
119新增: for k, v := range j.Out {
120新增: if e.Result.Files == nil {
121新增: e.Result.Files = map[string]string{}
122新增: }
123新增: e.Result.Files[k] = string(v)
124新增: }
125新增: return nil
126新增:}
127新增:
128新增:var (
129新增: mu sync.Mutex
130新增: files = map[string]map[string][]entry{} // file, test name: calls
131新增: calls = map[testing.TB]int{}
132新增: // The package's folder: tests change theirs.
133新增: pkgDir, _ = os.Getwd()
134新增:)
135新增:
136新增:// fileOf is where t's calls are kept: one file per top-level test.
137新增:func fileOf(t testing.TB) string {
138新增: top, _, _ := strings.Cut(t.Name(), "/")
139新增: return filepath.Join(pkgDir, "testdata", "bashref", top+".json")
140新增:}
141新增:
142新增:func load(path string) map[string][]entry {
143新增: if m, ok := files[path]; ok {
144新增: return m
145新增: }
146新增: m := map[string][]entry{}
147新增: if b, err := os.ReadFile(path); err == nil {
148新增: if err := json.Unmarshal(b, &m); err != nil {
149新增: panic(fmt.Sprintf("%s: %v", path, err))
150新增: }
151新增: }
152新增: files[path] = m
153新增: return m
154新增:}
155新增:
156新增:func replay(t testing.TB, c Cmd) Result {
157新增: t.Helper()
158新增: mu.Lock()
159新增: path := fileOf(t)
160新增: recorded := load(path)[t.Name()]
161新增: n, seen := calls[t]
162新增: if !seen {
163新增: t.Cleanup(func() {
164新增: mu.Lock()
165新增: delete(calls, t)
166新增: mu.Unlock()
167新增: })
168新增: }
169新增: calls[t] = n + 1
170新增: mu.Unlock()
171新增: if n >= len(recorded) {
172新增: t.Fatalf("%s: no bash result recorded for call %d of %s", path, n+1, t.Name())
173新增: }
174新增: p := newPaths()
175新增: if now := p.cmd(c); !reflect.DeepEqual(now, recorded[n].Cmd) {
176新增: t.Fatalf("%s: call %d of %s is not the recorded one:\n now: %+v\n recorded: %+v", path, n+1, t.Name(), now, recorded[n].Cmd)
177新增: }
178新增: return p.result(recorded[n].Result)
179新增:}
180新增:
181新增:// paths makes a call's paths portable: the repository is {ROOT}, a test's
182新增:// temporary folder {Ti}, i in order of appearance in the call, read back as
183新增:// the call spells it (macOS's /var or /private/var). The machine's PATH is
184新增:// left out. The output was recorded with the call's folders only: others
185新增:// under /tmp are not the test's (the guest's /tmp/...).
186新增:type paths struct {
187新增: re *regexp.Regexp
188新增: dirs []string // the folder's name under the temporary root
189新增: spell []string // the root it has in the call
190新增:}
191新增:
192新增:func newPaths() *paths {
193新增: p := &paths{}
194新增: var alts []string
195新增: for _, r := range []string{os.TempDir(), evalOr(os.TempDir())} {
196新增: if r = strings.TrimSuffix(r, "/"); !slices.Contains(alts, r) {
197新增: alts = append(alts, r)
198新增: }
199新增: }
200新增: slices.SortFunc(alts, func(a, b string) int { return len(b) - len(a) })
201新增: for i := range alts {
202新增: alts[i] = regexp.QuoteMeta(alts[i])
203新增: }
204新增: p.re = regexp.MustCompile(`(` + strings.Join(alts, "|") + `)/([^/\s'"=:,;\]\[{}]+)`)
205新增: return p
206新增:}
207新增:
208新增:func evalOr(p string) string {
209新增: if r, err := filepath.EvalSymlinks(p); err == nil {
210新增: return r
211新增: }
212新增: return p
213新增:}
214新增:
215新增:// out makes s portable.
216新增:func (p *paths) out(s string) string {
217新增: s = strings.ReplaceAll(s, Root(), "{ROOT}")
218新增: return p.re.ReplaceAllStringFunc(s, func(m string) string {
219新增: sub := p.re.FindStringSubmatch(m)
220新增: i := slices.Index(p.dirs, sub[2])
221新增: if i < 0 {
222新增: i = len(p.dirs)
223新增: p.dirs = append(p.dirs, sub[2])
224新增: p.spell = append(p.spell, sub[1])
225新增: }
226新增: return fmt.Sprintf("{T%d}", i)
227新增: })
228新增:}
229新增:
230新增:var placeholder = regexp.MustCompile(`\{T\d+\}`)
231新增:
232新增:// in is out undone, for this call's folders.
233新增:func (p *paths) in(s string) string {
234新增: s = placeholder.ReplaceAllStringFunc(s, func(m string) string {
235新增: var i int
236新增: fmt.Sscanf(m, "{T%d}", &i)
237新增: if i >= len(p.dirs) {
238新增: return m
239新增: }
240新增: return p.spell[i] + "/" + p.dirs[i]
241新增: })
242新增: return strings.ReplaceAll(s, "{ROOT}", Root())
243新增:}
244新增:
245新增:func (p *paths) cmd(c Cmd) Cmd {
246新增: o := Cmd{Dir: p.out(c.Dir), Stdin: p.out(c.Stdin), Snippet: p.out(c.Snippet)}
247新增: for _, e := range c.Env {
248新增: if k, v, ok := strings.Cut(e, "="); ok && k == "PATH" {
249新增: e = "PATH=" + strings.TrimSuffix(strings.TrimSuffix(v, os.Getenv("PATH")), ":")
250新增: }
251新增: o.Env = append(o.Env, p.out(e))
252新增: }
253新增: for _, a := range c.Args {
254新增: o.Args = append(o.Args, p.out(a))
255新增: }
256新增: for _, f := range c.Files {
257新增: o.Files = append(o.Files, p.out(f))
258新增: }
259新增: return o
260新增:}
261新增:
262新增:// result is a recorded result, with this call's paths.
263新增:func (p *paths) result(r Result) Result {
264新增: o := Result{Stdout: p.in(r.Stdout), Stderr: p.in(r.Stderr), Code: r.Code}
265新增: for k, v := range r.Files {
266新增: if o.Files == nil {
267新增: o.Files = map[string]string{}
268新增: }
269新增: o.Files[p.in(k)] = p.in(v)
270新增: }
271新增: return o
272新增:}
新增internal/cli/alive_unix.go+15 −0看文件
@@ -0,0 +1,15 @@
1新增://go:build !windows
2新增:
3新增:package cli
4新增:
5新增:import (
6新增: "errors"
7新增: "syscall"
8新增:)
9新增:
10新增:// alive reports whether the process pid exists: signal 0 reaches it, or it
11新增:// belongs to someone else.
12新增:func alive(pid int) bool {
13新增: err := syscall.Kill(pid, 0)
14新增: return err == nil || errors.Is(err, syscall.EPERM)
15新增:}
新增internal/cli/alive_windows.go+17 −0看文件
@@ -0,0 +1,17 @@
1新增:package cli
2新增:
3新增:import "golang.org/x/sys/windows"
4新增:
5新增:// alive reports whether the process pid exists and has not exited.
6新增:func alive(pid int) bool {
7新增: h, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
8新增: if err != nil {
9新增: return false
10新增: }
11新增: defer windows.CloseHandle(h)
12新增: var code uint32
13新增: if windows.GetExitCodeProcess(h, &code) != nil {
14新增: return false
15新增: }
16新增: return code == 259 // STILL_ACTIVE
17新增:}
新增internal/cli/app.go+188 −0看文件
@@ -0,0 +1,188 @@
1新增:package cli
2新增:
3新增:import (
4新增: "context"
5新增: "fmt"
6新增: "os"
7新增: "path/filepath"
8新增: "sync"
9新增:
10新增: "github.com/sylvinus/agent-vm/internal/paths"
11新增: "github.com/sylvinus/agent-vm/internal/state"
12新增: "github.com/sylvinus/agent-vm/internal/ui"
13新增: "github.com/sylvinus/agent-vm/internal/vm"
14新增: "github.com/sylvinus/agent-vm/internal/vmname"
15新增:)
16新增:
17新增:// app is what the commands work with.
18新增:type app struct {
19新增: io IO
20新增: ui *ui.UI
21新增: state state.Dir
22新增:
23新增: migrateOnce sync.Once
24新增: migrate func() // moves 0.2's VMs, when set
25新增: backOnce sync.Once
26新增: newBack func() (vm.Backend, error)
27新增: back vm.Backend
28新增: backErr error
29新增:}
30新增:
31新增:// backend is made on first use: most commands never need Lima. The first
32新增:// use by a command that changes VMs also moves 0.2's VMs (migrateOld).
33新增:func (e *app) backend() (vm.Backend, error) {
34新增: e.migrateOnce.Do(func() {
35新增: if e.migrate != nil {
36新增: e.migrate()
37新增: }
38新增: })
39新增: return e.readOnlyBackend()
40新增:}
41新增:
42新增:// readOnlyBackend is backend without the move of 0.2's VMs, for commands
43新增:// that only look (list, status, doctor, info, install). A command that goes
44新增:// on to change VMs asks for backend, which moves them then.
45新增:func (e *app) readOnlyBackend() (vm.Backend, error) {
46新增: e.backOnce.Do(func() { e.back, e.backErr = e.newBack() })
47新增: return e.back, e.backErr
48新增:}
49新增:
50新增:// migratedMarker says the VMs of 0.2 were moved into agent-vm's Lima home.
51新增:const migratedMarker = ".agent-vm-lima-migrated"
52新增:
53新增:// oldLimaHome is where 0.2 kept its VMs: Lima's home, $LIMA_HOME or ~/.lima.
54新增:func oldLimaHome() string {
55新增: if h := vm.UserLimaHome(); h != "" {
56新增: return paths.Host(absOr(h))
57新增: }
58新增: return paths.Host(filepath.Join(paths.Home(), ".lima"))
59新增:}
60新增:
61新增:// absOr is p made absolute, as it is when that cannot be done: a relative
62新增:// folder would defeat the checks that compare locations.
63新增:func absOr(p string) string {
64新增: if abs, err := filepath.Abs(p); err == nil {
65新增: return abs
66新增: }
67新增: return p
68新增:}
69新增:
70新增:// migrated reports whether 0.2's VMs were moved already.
71新增:func (e *app) migrated() bool {
72新增: _, err := os.Stat(e.state.Path(migratedMarker))
73新增: return err == nil
74新增:}
75新增:
76新增:// unmovedOld are 0.2's VMs that have not been moved yet, and the Lima home
77新增:// they are in. None for an app with no move wired (migrate unset).
78新增:func (e *app) unmovedOld() ([]vm.OldVM, string) {
79新增: old := oldLimaHome()
80新增: if e.migrate == nil || e.migrated() || sameDir(old, LimaHome(e.state)) {
81新增: return nil, old
82新增: }
83新增: vms, _ := vm.FindOld(old, vmname.OldPrefix)
84新增: return vms, old
85新增:}
86新增:
87新增:// migrateOld moves, once, the VMs agent-vm 0.2 made in the user's Lima home
88新增:// into its own (see LimaHome). Asked on a terminal, yes by default. Without
89新增:// one, the stopped ones are moved and the running ones left: moving stops
90新增:// them, which cuts sessions nobody agreed to cut. A VM that could not be
91新增:// moved stays, and is offered again.
92新增:func (e *app) migrateOld(ctx context.Context, old, now string) {
93新增: if e.migrated() || sameDir(old, now) {
94新增: return
95新增: }
96新增: vms, err := vm.FindOld(old, vmname.OldPrefix)
97新增: if err != nil || len(vms) == 0 {
98新增: return
99新增: }
100新增: w := e.io.Stderr
101新增: fmt.Fprintf(w, "agent-vm now keeps its VMs in %s, apart from your own Lima's. Found in %s:\n", now, old)
102新增: running := false
103新增: for _, v := range vms {
104新增: state := ""
105新增: if v.Running {
106新增: state, running = " (running)", true
107新增: }
108新增: fmt.Fprintf(w, " %s, as %s%s\n", v.Name, vmname.FromOld(v.Name), state)
109新增: }
110新增: canAsk := e.ui.CanAsk()
111新增: if running && canAsk {
112新增: fmt.Fprintln(w, "Running ones are stopped first: sessions using them are cut.")
113新增: }
114新增: if canAsk && !e.ui.AskYN("Move them there now?", true) {
115新增: fmt.Fprintf(w, "Not moved: this agent-vm does not see them until they are. They stay in %s.\n", old)
116新增: return
117新增: }
118新增: failed := false
119新增: for _, v := range vms {
120新增: if v.Running && !canAsk {
121新增: fmt.Fprintf(w, "%s is running and stays in %s: no terminal to ask whether to cut its sessions. Stop it, or run agent-vm in a terminal.\n", v.Name, old)
122新增: failed = true
123新增: continue
124新增: }
125新增: to := vmname.FromOld(v.Name)
126新增: fmt.Fprintf(w, "Moving %s...\n", v.Name)
127新增: if err := vm.MoveOld(ctx, old, now, v.Name, to); err != nil {
128新增: fmt.Fprintf(w, "Error: could not move %s: %v. It stays in %s.\n", v.Name, err, old)
129新增: failed = true
130新增: continue
131新增: }
132新增: if err := e.state.Rename(v.Name, to); err != nil {
133新增: fmt.Fprintf(w, "Warning: %s moved, but not all that agent-vm knows of it: %v\n", to, err)
134新增: }
135新增: }
136新增: if failed {
137新增: return
138新增: }
139新增: if err := e.state.Write(migratedMarker, []byte(old+"\n")); err != nil {
140新增: fmt.Fprintf(w, "Warning: could not record that they were moved: %v. They are looked for in %s again next time.\n", err, old)
141新增: }
142新增: fmt.Fprintln(w, "Done: they keep their shares and settings, under their new names.")
143新增:}
144新增:
145新增:// sameDir reports whether a and b are one folder, links resolved where they
146新增:// exist.
147新增:func sameDir(a, b string) bool {
148新增: if fa, err := os.Stat(a); err == nil {
149新增: if fb, err := os.Stat(b); err == nil {
150新增: return os.SameFile(fa, fb)
151新增: }
152新增: }
153新增: return filepath.Clean(a) == filepath.Clean(b)
154新增:}
155新增:
156新增:// LimaHome is where agent-vm's Lima keeps its VMs: its own, so that the
157新增:// user's limactl, of another version, never runs them, and nothing of the
158新增:// user's own Lima is touched. AGENT_VM_LIMA_HOME overrides it, made
159新增:// absolute.
160新增:func LimaHome(st state.Dir) string {
161新增: if h := os.Getenv("AGENT_VM_LIMA_HOME"); h != "" {
162新增: return paths.Host(absOr(h))
163新增: }
164新增: return st.Path("lima")
165新增:}
166新增:
167新增:func newApp(io IO) (*app, error) {
168新增: st, err := state.Default()
169新增: if err != nil {
170新增: return nil, err
171新增: }
172新增: u := ui.New()
173新增: u.Stderr = io.Stderr
174新增: e := &app{io: io, ui: u, state: st}
175新增: // Names that fit this machine's socket paths (a long home, a long user
176新增: // name): cut in their folder part, not refused.
177新增: vmname.MaxLen = vm.MaxName(LimaHome(st))
178新增: e.migrate = func() { e.migrateOld(context.Background(), oldLimaHome(), LimaHome(st)) }
179新增: e.newBack = func() (vm.Backend, error) {
180新增: // Every VM there is agent-vm's: list, rm and destroy-all take them
181新增: // all. Never a Lima home the user's own VMs live in.
182新增: if h := LimaHome(st); sameDir(h, oldLimaHome()) {
183新增: return nil, fmt.Errorf("agent-vm's Lima home %s is also your own Lima's home: set AGENT_VM_LIMA_HOME to a folder for agent-vm alone", h)
184新增: }
185新增: return vm.NewLima(LimaHome(st), string(st))
186新增: }
187新增: return e, nil
188新增:}
新增internal/cli/checks.go+200 −0看文件
@@ -0,0 +1,200 @@
1新增:package cli
2新增:
3新增:import (
4新增: "context"
5新增: "fmt"
6新增: "os"
7新增: "os/exec"
8新增: "strings"
9新增:
10新增: "github.com/sylvinus/agent-vm/internal/gitguard"
11新增: "github.com/sylvinus/agent-vm/internal/mounts"
12新增: "github.com/sylvinus/agent-vm/internal/vm"
13新增:)
14新增:
15新增:// promptsDisabledBy is what turned the security questions off, if
16新增:// something did: --unsafe-disable-security-prompts, or
17新增:// AGENT_VM_UNSAFE_DISABLE_SECURITY_PROMPTS=1 in the shell. Never a file of
18新增:// the project, which the VM can write.
19新增:func (s *start) promptsDisabledBy() (string, bool) {
20新增: switch {
21新增: case s.opts.UnsafeNoPrompts:
22新增: return "--unsafe-disable-security-prompts", true
23新增: case os.Getenv("AGENT_VM_UNSAFE_DISABLE_SECURITY_PROMPTS") == "1":
24新增: return "AGENT_VM_UNSAFE_DISABLE_SECURITY_PROMPTS=1", true
25新增: }
26新增: return "", false
27新增:}
28新增:
29新增:// confirmUnsafe is the question after a security warning: true to go on.
30新增:// No by default, and when it cannot be asked; yes when the questions are
31新增:// off.
32新增:func (s *start) confirmUnsafe() bool {
33新增: if by, ok := s.promptsDisabledBy(); ok {
34新增: fmt.Fprintf(s.io.Stderr, "Continuing: %s.\n", by)
35新增: return true
36新增: }
37新增: return s.ui.CanAsk() && s.ui.AskYN("Continue anyway?", false)
38新增:}
39新增:
40新增:func (s *start) warnf(format string, a ...any) {
41新增: fmt.Fprintf(s.io.Stderr, format+"\n", a...)
42新增:}
43新增:
44新增:// writableGitWarning is printed on every start with .git left writable.
45新增:func (s *start) writableGitWarning() {
46新增: why := "AGENT_VM_UNSAFE_WRITABLE_GIT=1"
47新增: if s.opts.UnsafeWritableGit {
48新增: why = "--unsafe-writable-git"
49新增: }
50新增: fmt.Fprintf(s.io.Stderr, `!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
51新增:!! WARNING: %s. The VM can write every .git.
52新增:!!
53新增:!! The agent can change .git/config and .git/hooks in the shared folders, and
54新增:!! git on this machine runs what they name: on your next commit, and whenever
55新增:!! your editor or shell prompt calls git. That is running commands on your
56新增:!! host, outside the VM. Without it, .git stays read-only.
57新增:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
58新增:`, why)
59新增:}
60新增:
61新增:// checks are the security checks of a start, before anything changes. A
62新增:// running VM that keeps running (s.vmUp) gets the warnings and nothing is
63新增:// asked. False when the start must stop.
64新增:func (s *start) checks() bool {
65新增: s.protect, s.names, s.notes = false, nil, ""
66新增: if !s.opts.Scratch {
67新增: if writableGitOptOut(s.opts.UnsafeWritableGit) {
68新增: s.writableGitWarning()
69新增: } else {
70新增: s.protect = true
71新增: }
72新增: }
73新增: if s.protect {
74新增: // The names the shares need: those always listed, and one per hooks
75新增: // folder git runs from in a share, its first component. A dot-name
76新增: // (.husky, .githooks) is taken as is; any other is read-only in
77新增: // every folder of every share, so it is asked first (yes by
78新增: // default, and when no one can answer). A folder that cannot be
79新增: // protected, or one declined, is a risk to accept. So are the
80新增: // scan's risks. Under --readonly the VM writes none of them.
81新增: scan := s.scan(s.ctx, s.dir)
82新增: var hooks []string
83新增: for _, h := range scan.Hooks {
84新增: rel, inRepo, _ := strings.Cut(h, "\t")
85新增: if rel == "" {
86新增: continue
87新增: }
88新增: name, ok := gitguard.HooksName(inRepo)
89新增: if s.opts.ReadOnly {
90新增: if ok {
91新增: hooks = append(hooks, name)
92新增: }
93新增: continue
94新增: }
95新增: if !ok {
96新增: switch {
97新增: case rel == ".":
98新增: s.warnf("Warning: git's core.hooksPath is the project directory itself, which the VM can write: git on this machine runs the hooks the agent puts there.")
99新增: case inRepo == ".":
100新增: s.warnf("Warning: git's core.hooksPath is '%s', which the VM can write, and no read-only name covers it (the top of a repository, or in a writable volume): git on this machine runs the hooks the agent puts there.", rel)
101新增: default:
102新增: s.warnf("Warning: git's core.hooksPath is '%s', which the VM can write, and its name cannot be made read-only: git on this machine runs the hooks the agent puts there.", rel)
103新增: }
104新增: if !s.vmUp && !s.confirmUnsafe() {
105新增: s.warnf("Aborted. Point core.hooksPath to a folder of the project (agent-vm keeps it read-only), or outside it.")
106新增: return false
107新增: }
108新增: continue
109新增: }
110新增: if _, off := s.promptsDisabledBy(); !strings.HasPrefix(name, ".") && !s.vmUp && !off && s.ui.CanAsk() &&
111新增: !s.ui.AskYN(fmt.Sprintf("Git runs hooks from %s. Make every '%s' folder in the project read-only for the VM?", rel, name), true) {
112新增: s.warnf("Warning: '%s' stays writable, and git on this machine runs the hooks the agent puts in %s.", name, rel)
113新增: if !s.confirmUnsafe() {
114新增: s.warnf("Aborted. Answer yes to protect it, or point core.hooksPath outside the project.")
115新增: return false
116新增: }
117新增: continue
118新增: }
119新增: hooks = append(hooks, name)
120新增: s.notes += fmt.Sprintf("Note: git runs hooks from %s (core.hooksPath): every '%s' in the project is read-only for the VM too.\n", rel, name)
121新增: }
122新增: s.names = gitguard.NamesWith(hooks)
123新增: // What the names accepted keep read-only is no risk; a name declined
124新增: // keeps nothing.
125新增: if risks := scan.Risks(s.names); !s.opts.ReadOnly && len(risks) > 0 {
126新增: s.warnf("Warning: git on this machine uses these, and the VM can write them:")
127新增: for _, r := range risks {
128新增: s.warnf(" %s", r)
129新增: }
130新增: if !s.vmUp && !s.confirmUnsafe() {
131新增: s.warnf("Aborted. Move them out of the shared folders, or have them name commands outside them.")
132新增: return false
133新增: }
134新增: }
135新增: }
136新增: // A repository not named .git, which no name protects: only a VM that
137新增: // can write needs the setting.
138新增: if !s.opts.ReadOnly && !s.opts.Scratch {
139新增: return s.checkBareRepo()
140新增: }
141新增: return true
142新增:}
143新增:
144新增:// checkBareRepo offers to set safe.bareRepository=explicit when it can ask.
145新增:// Not set: a security question, no by default. With the questions off,
146新增:// nothing is offered: the global git config is not changed unasked. For a
147新增:// VM already running, a warning only.
148新增:func (s *start) checkBareRepo() bool {
149新增: st := gitguard.BareState(s.ctx)
150新增: if st == gitguard.BareOK || st == gitguard.BareNoGit {
151新增: return true
152新增: }
153新增: if s.vmUp {
154新增: s.warnf("Warning: git on this machine uses repositories a VM creates under another name than .git ('agent-vm doctor' says more).")
155新增: return true
156新增: }
157新增: s.ui.Box("Git: repositories not named .git", gitguard.BareHint)
158新增: if st == gitguard.BareOld {
159新增: out, _ := exec.CommandContext(s.ctx, "git", "--version").Output()
160新增: s.warnf("Warning: %s is older than 2.38 and ignores that setting.", strings.TrimSpace(string(out)))
161新增: if s.confirmUnsafe() {
162新增: return true
163新增: }
164新增: s.warnf("Aborted. Upgrade git, then run the command above.")
165新增: return false
166新增: }
167新增: if _, off := s.promptsDisabledBy(); !off && s.ui.CanAsk() && s.ui.AskYN("Run it now? It changes your global git config.", true) {
168新增: err := exec.CommandContext(s.ctx, "git", "config", "--global", "safe.bareRepository", "explicit").Run()
169新增: if err == nil && gitguard.BareState(s.ctx) == gitguard.BareOK {
170新增: fmt.Fprintln(s.io.Stdout, "Git on this machine now ignores repositories not named .git unless you name them.")
171新增: return true
172新增: }
173新增: s.warnf("Warning: the setting did not take.")
174新增: }
175新增: s.warnf("Warning: not set. Until it is, git on this machine can run what a VM writes.")
176新增: if s.confirmUnsafe() {
177新增: return true
178新增: }
179新增: s.warnf("Aborted. Run the command above, then run agent-vm again.")
180新增: return false
181新增:}
182新增:
183新增:// start is one start of a project's VM.
184新增:type start struct {
185新增: *app
186新增: ctx context.Context
187新增: opts VMOpts
188新增: name string // the VM
189新增: dir string // the project, as the shell spells it
190新增:
191新增: created bool // this run made the VM, and it is still there
192新增: vmUp bool // running when the start began, and not reset
193新增: protect bool // every .git read-only
194新增: names []string // the read-only names, when protect
195新增: notes string // hooks notes, printed once the names apply
196新增:
197新增: built []vm.Mount // see shares
198新增: builtFiles []mounts.FileMount
199新增: builtKey string
200新增:}
新增internal/cli/cli.go+197 −0看文件
@@ -0,0 +1,197 @@
1新增:// Package cli is agent-vm's command line. The commands and options are those
2新增:// of 0.2's agent-vm.sh, with the additions and changes of 0.3 in CHANGELOG.md
3新增:// (--scratch, install, info, code, exit status 2 for wrong usage...).
4新增:package cli
5新增:
6新增:import (
7新增: "context"
8新增: _ "embed"
9新增: "fmt"
10新增: "io"
11新增: "os"
12新增: "regexp"
13新增: "strings"
14新增:
15新增: "github.com/sylvinus/agent-vm/internal/version"
16新增: "github.com/sylvinus/agent-vm/internal/vmname"
17新增:)
18新增:
19新增://go:embed help.txt
20新增:var helpText string
21新增:
22新增:// IO is where a command reads and writes.
23新增:type IO struct {
24新增: Stdin io.Reader
25新增: Stdout, Stderr io.Writer
26新增:}
27新增:
28新增:// The commands VM options mean nothing to: `agent-vm --readonly stop` must
29新增:// not read as if something had been made read-only.
30新增:var noVMOpts = map[string]bool{
31新增: "stop": true, "rm": true, "destroy": true, "destroy-all": true, "list": true, "status": true,
32新增: "name": true, "info": true, "env": true, "project-env": true, "version": true, "--version": true,
33新增: "-V": true, "licenses": true, "doctor": true, "install": true, "uninstall": true, "help": true, "--help": true, "-h": true,
34新增:}
35新增:
36新增:// exitUsage is the exit status of a command line that is wrong: an unknown
37新增:// command, option or argument, a missing value.
38新增:const exitUsage = 2
39新增:
40新增:// stateful are the commands that work on agent-vm's folder or its VMs, so
41新增:// need to know where they are. The others (help, version, licenses, a wrong
42新增:// command line) run without: `version --min` must not fail for want of a
43新增:// home folder, where 1 means "older".
44新增:var stateful = map[string]bool{
45新增: "name": true, "list": true, "status": true, "stop": true, "rm": true, "destroy": true, "destroy-all": true,
46新增: "info": true, "env": true, "project-env": true, "claude": true, "opencode": true, "codex": true, "vibe": true,
47新增: "pi": true, "shell": true, "sh": true, "run": true, "setup": true, "doctor": true, "install": true,
48新增: "uninstall": true, "code": true,
49新增:}
50新增:
51新增:// needsState reports whether the command line runs a command in stateful.
52新增:// `name` is one: the length of the Lima home's path limits the names.
53新增:func needsState(args []string) bool {
54新增: opts := newVMOpts()
55新增: _, rest, err := opts.takeAll(args)
56新增: return err == nil && len(rest) > 0 && stateful[rest[0]]
57新增:}
58新增:
59新增:// Main runs agent-vm with args (os.Args[1:]) and returns its exit status.
60新增:func Main(args []string, io IO) int {
61新增: ctx := context.Background()
62新增: if !needsState(args) {
63新增: return (&app{io: io}).main(ctx, args)
64新增: }
65新增: e, err := newApp(io)
66新增: if err != nil {
67新增: fmt.Fprintf(io.Stderr, "Error: %v\n", err)
68新增: return 1
69新增: }
70新增: return e.main(ctx, args)
71新增:}
72新增:
73新增:// main runs the command line. An app made only of io is enough for the
74新增:// commands outside stateful.
75新增:func (e *app) main(ctx context.Context, args []string) int {
76新增: io := e.io
77新增: opts := newVMOpts()
78新增: lead, args, err := opts.takeAll(args)
79新增: if err != nil {
80新增: fmt.Fprintf(io.Stderr, "Error: %v\n", err)
81新增: return exitUsage
82新增: }
83新增: cmd := "help"
84新增: if len(args) > 0 {
85新增: cmd, args = args[0], args[1:]
86新增: }
87新增: if len(lead) > 0 && noVMOpts[cmd] {
88新增: fmt.Fprintf(io.Stderr, "Error: %s is an option for the commands that start a VM (claude, opencode, codex, vibe, pi, shell, run, code), not for '%s'.\n", lead[0], cmd)
89新增: return exitUsage
90新增: }
91新增: switch cmd {
92新增: case "help", "--help", "-h":
93新增: fmt.Fprint(io.Stdout, helpText)
94新增: return 0
95新增: case "version", "--version", "-V":
96新增: return versionCmd(args, io)
97新增: case "licenses":
98新增: return licensesCmd(args, io)
99新增: case "name":
100新增: return nameCmd(args, io)
101新增: case "list", "status":
102新增: return e.listCmd(ctx, args)
103新增: case "stop":
104新增: return e.stopCmd(ctx, args)
105新增: case "rm", "destroy":
106新增: return e.rmCmd(ctx, args)
107新增: case "destroy-all":
108新增: return e.destroyAllCmd(ctx, args)
109新增: case "info":
110新增: return e.infoCmd(ctx, args)
111新增: case "env":
112新增: return e.sharedEnvCmd(args)
113新增: case "project-env":
114新增: return e.projectEnvCmd(ctx, args)
115新增: case "claude", "opencode", "codex", "vibe", "pi":
116新增: return e.agentCmd(ctx, cmd, opts, args)
117新增: case "shell", "sh":
118新增: return e.shellCmd(ctx, opts, args)
119新增: case "run":
120新增: return e.runCmd(ctx, opts, args)
121新增: case "setup":
122新增: return e.setupCmd(ctx, append(lead, args...))
123新增: case "doctor":
124新增: return e.doctorCmd(ctx, args)
125新增: case "install":
126新增: return e.installCmd(ctx, args)
127新增: case "uninstall":
128新增: return e.uninstallCmd(args)
129新增: case "code":
130新增: return e.codeCmd(ctx, opts, args)
131新增: default:
132新增: fmt.Fprintf(io.Stderr, "Unknown command: %s\nRun 'agent-vm help' for usage.\n", cmd)
133新增: return exitUsage
134新增: }
135新增:}
136新增:
137新增:var versionRe = regexp.MustCompile(`^[0-9]+(\.[0-9]+)*(-[A-Za-z0-9.]+)?$`)
138新增:
139新增:// `version [--min X.Y.Z]`: silent and 0 when this agent-vm is at least
140新增:// X.Y.Z, an error and 1 when older, 2 when the call itself is wrong.
141新增:func versionCmd(args []string, io IO) int {
142新增: if len(args) == 0 {
143新增: fmt.Fprintln(io.Stdout, version.Version)
144新增: return 0
145新增: }
146新增: want := ""
147新增: for len(args) > 0 {
148新增: switch a := args[0]; {
149新增: case a == "--min":
150新增: if len(args) < 2 {
151新增: fmt.Fprintln(io.Stderr, "Error: --min needs a version (e.g. --min 0.2.0)")
152新增: return 2
153新增: }
154新增: want, args = args[1], args[2:]
155新增: case strings.HasPrefix(a, "--min="):
156新增: want, args = strings.TrimPrefix(a, "--min="), args[1:]
157新增: default:
158新增: fmt.Fprintf(io.Stderr, "Error: unknown option for version: %s\n", a)
159新增: return 2
160新增: }
161新增: }
162新增: if !versionRe.MatchString(want) {
163新增: fmt.Fprintf(io.Stderr, "Error: --min expects a version like 1.2.3 (got: '%s')\n", want)
164新增: return 2
165新增: }
166新增: if version.AtLeast(version.Version, want) {
167新增: return 0
168新增: }
169新增: fmt.Fprintf(io.Stderr, "Error: agent-vm %s is older than the required %s.\n", version.Version, want)
170新增: fmt.Fprintf(io.Stderr, " Update it: %s\n", updateCommand())
171新增: return 1
172新增:}
173新增:
174新增:// updateCommand is how this copy of agent-vm is updated.
175新增:func updateCommand() string {
176新增: return "curl -fsSL https://www.agent-vm.org/install.sh | sh"
177新增:}
178新增:
179新增:// `name [dir]`: the VM name of a directory, the current one by default.
180新增:func nameCmd(args []string, io IO) int {
181新增: dir := ""
182新增: if len(args) > 0 {
183新增: dir = args[0]
184新增: }
185新增: abs, err := vmname.AbsDir(dir)
186新增: if err != nil {
187新增: fmt.Fprintf(io.Stderr, "Error: %v\n", err)
188新增: return 1
189新增: }
190新增: fmt.Fprintln(io.Stdout, vmname.Name(abs))
191新增: return 0
192新增:}
193新增:
194新增:// Stdio is the process's own.
195新增:func Stdio() IO {
196新增: return IO{Stdin: os.Stdin, Stdout: os.Stdout, Stderr: os.Stderr}
197新增:}
新增internal/cli/cli_test.go+137 −0看文件
@@ -0,0 +1,137 @@
1新增:package cli
2新增:
3新增:import (
4新增: "bytes"
5新增: "os"
6新增: "path/filepath"
7新增: "regexp"
8新增: "strings"
9新增: "testing"
10新增:
11新增: "github.com/sylvinus/agent-vm/internal/bashref"
12新增: "github.com/sylvinus/agent-vm/internal/version"
13新增: "github.com/sylvinus/agent-vm/internal/vmname"
14新增:)
15新增:
16新增:func run(t *testing.T, args ...string) bashref.Result {
17新增: t.Helper()
18新增: var stdout, stderr bytes.Buffer
19新增: code := Main(args, IO{Stdin: strings.NewReader(""), Stdout: &stdout, Stderr: &stderr})
20新增: return bashref.Result{Stdout: stdout.String(), Stderr: stderr.String(), Code: code}
21新增:}
22新增:
23新增:// bashAgentVM runs 0.2's agent-vm with args, in dir, with a limactl on PATH
24新增:// (it checks for one before most commands; Lima is built in here).
25新增:func bashAgentVM(t *testing.T, dir string, args ...string) bashref.Result {
26新增: t.Helper()
27新增: bin := t.TempDir()
28新增: if err := os.WriteFile(filepath.Join(bin, "limactl"), []byte("#!/bin/sh\nexit 0\n"), 0o755); err != nil {
29新增: t.Fatal(err)
30新增: }
31新增: return bashref.Script(t, dir, []string{"PATH=" + bin + ":" + os.Getenv("PATH")}, `agent-vm "$@"`, args...)
32新增:}
33新增:
34新增:// Same output and status as 0.2, with this build's version set to 0.2's.
35新增:func TestMainBash(t *testing.T) {
36新增: saved := version.Version
37新增: t.Cleanup(func() { version.Version = saved })
38新增: version.Version = strings.TrimSpace(bashref.Script(t, "", nil, `echo "$AGENT_VM_VERSION"`).Stdout)
39新增:
40新增: proj, _ := filepath.EvalSymlinks(t.TempDir())
41新增: t.Chdir(proj)
42新增: t.Setenv("PWD", proj)
43新增: cases := [][]string{
44新增: {"version"}, {"--version"}, {"-V"},
45新增: {"version", "--min", "0.1.0"}, {"version", "--min=0.2.1"}, {"version", "--min", "0.10.0"},
46新增: {"version", "--min"}, {"version", "--min", "x"}, {"version", "--min", ""}, {"version", "--max", "1"},
47新增: {"version", "--min", "1.2.3-rc.1"},
48新增: {"name"}, {"name", proj}, {"name", "."}, {"name", proj + "/missing"},
49新增: {"frobnicate"},
50新增: {"--disk"}, {"--disk", "10G", "claude"}, {"--disk=0", "shell"}, {"--memory", "-1"}, {"--ram=x"},
51新增: {"--cpus", "01"}, {"--ssh-port", "80"}, {"--ssh-port", "70000"}, {"--ssh-port=00"},
52新增: {"--readonly", "stop"}, {"--disk", "10", "--rm", "list"}, {"--rm", "version"}, {"--scratch", "help"},
53新增: {"--unsafe-writable-git=1", "name"}, {"--unsafe-disable-security-prompts", "doctor"},
54新增: }
55新增: // How to update depends on how each copy was installed.
56新增: update := regexp.MustCompile(`(?m)^ Update it: .*$`)
57新增: hash := regexp.MustCompile(`(?m)-[0-9a-f]{8}$`)
58新增: for _, args := range cases {
59新增: want := bashAgentVM(t, proj, args...)
60新增: got := run(t, args...)
61新增: want.Stderr = update.ReplaceAllString(want.Stderr, " Update it:")
62新增: got.Stderr = update.ReplaceAllString(got.Stderr, " Update it:")
63新增: // 0.3's names drop 0.2's prefix. The hash is of the folder bash had
64新增: // (TestNameBash compares hashes).
65新增: if args[0] == "name" {
66新增: want.Stdout = strings.TrimPrefix(want.Stdout, vmname.OldPrefix)
67新增: want.Stdout = hash.ReplaceAllString(want.Stdout, "-HASH")
68新增: got.Stdout = hash.ReplaceAllString(got.Stdout, "-HASH")
69新增: }
70新增: // 0.3 exits with exitUsage for a wrong command line, where 0.2 had 1.
71新增: if want.Code == 1 && got.Code == exitUsage {
72新增: want.Code = exitUsage
73新增: }
74新增: if got.Stdout != want.Stdout || got.Stderr != want.Stderr || got.Code != want.Code {
75新增: t.Errorf("agent-vm %q:\n go: %+v\n bash: %+v", args, got, want)
76新增: }
77新增: }
78新增:}
79新增:
80新增:// The help is 0.2's, but for what Lima built in changed (CHANGELOG).
81新增:func TestHelp(t *testing.T) {
82新增: want := bashref.Run(t, "", nil, "_agent_vm_help").Stdout
83新增: for _, args := range [][]string{{}, {"help"}, {"--help"}, {"-h"}} {
84新增: r := run(t, args...)
85新增: if r.Code != 0 || r.Stdout != helpText || r.Stderr != "" {
86新增: t.Errorf("%q: %+v", args, r)
87新增: }
88新增: }
89新增: strip := func(s string) string {
90新增: s = strings.Replace(s, "agent-vm rm agent-vm-old-name-1a2b3c4d ", "agent-vm rm old-name-1a2b3c4d ", 1)
91新增: for _, cut := range []string{
92新增: "AGENT_VM_BIN_DIR). Run it from the clone:\n ./agent-vm.sh install\n",
93新增: "AGENT_VM_BIN_DIR)\n",
94新增: " ~/.agent-vm/network What the VMs may reach (above)\n",
95新增: " ~/.agent-vm/guarded More files to ask about (above)\n",
96新增: " licenses Print the licenses of agent-vm and of what is built into it\n",
97新增: } {
98新增: s = strings.Replace(s, cut, "", 1)
99新增: }
100新增: // Network isolation and guarded files are new.
101新增: if before, rest, ok := strings.Cut(s, "The VMs reach the internet"); ok {
102新增: _, after, _ := strings.Cut(rest, "Both files are read when a VM starts.\n\n")
103新增: s = before + after
104新增: }
105新增: before, _, _ := strings.Cut(s, "Every .git in the shared folders")
106新增: _, after, _ := strings.Cut(s, "A VM that already runs gets the warnings only")
107新增: return before + after
108新增: }
109新增: if strip(helpText) != strip(want) {
110新增: t.Error("the help differs from 0.2's beyond the Lima paragraphs and install")
111新增: }
112新增: if strings.Contains(helpText, "Lima build") || strings.Contains(helpText, "agent-vm.sh") {
113新增: t.Error("the help still offers a Lima build or the clone")
114新增: }
115新增:}
116新增:
117新增:func TestSplit(t *testing.T) {
118新增: for _, c := range []struct {
119新增: in []string
120新增: cmd []string
121新增: tty bool
122新增: opts VMOpts
123新增: }{
124新增: {[]string{"docker", "run", "--rm", "x"}, []string{"docker", "run", "--rm", "x"}, false, newVMOpts()},
125新增: {[]string{"--rm", "--tty", "htop"}, []string{"htop"}, true, VMOpts{RM: true, SSHPort: -1}},
126新增: {[]string{"--disk=5", "--", "--rm"}, []string{"--rm"}, false, VMOpts{Disk: 5, SSHPort: -1}},
127新增: {[]string{"--ssh-port", "0", "--ram", "4", "x"}, []string{"x"}, false, VMOpts{Memory: 4, SSHPort: 0}},
128新增: {[]string{"--readonly", "--scratch", "--reset", "--unsafe-writable-git", "--unsafe-disable-security-prompts"}, []string{}, false,
129新增: VMOpts{ReadOnly: true, Scratch: true, Reset: true, UnsafeWritableGit: true, UnsafeNoPrompts: true, SSHPort: -1}},
130新增: } {
131新增: opts := newVMOpts()
132新增: cmd, tty, err := opts.split(c.in)
133新增: if err != nil || strings.Join(cmd, " ") != strings.Join(c.cmd, " ") || tty != c.tty || opts != c.opts {
134新增: t.Errorf("split(%q) = %q, %v, %+v, %v", c.in, cmd, tty, opts, err)
135新增: }
136新增: }
137新增:}
新增internal/cli/code.go+232 −0看文件
@@ -0,0 +1,232 @@
1新增:package cli
2新增:
3新增:import (
4新增: "context"
5新增: "crypto/sha256"
6新增: "encoding/hex"
7新增: "fmt"
8新增: "net"
9新增: "os"
10新增: "regexp"
11新增: "runtime"
12新增: "strconv"
13新增: "strings"
14新增: "time"
15新增: "unicode"
16新增:
17新增: "github.com/sylvinus/agent-vm/internal/paths"
18新增: "github.com/sylvinus/agent-vm/internal/ui"
19新增: "github.com/sylvinus/agent-vm/internal/vm"
20新增:)
21新增:
22新增:// codePrep runs in the VM before the editor starts, the candidate ports as
23新增:// arguments. Prints `missing` without code-server, else its config file and
24新增:// password, the port of an editor of this VM already running, and which
25新增:// candidates something in the VM listens on (ss; without it, curl, any
26新增:// answer but a refused connection, the VM's proxy bypassed).
27新增://
28新增:// The password is made in the VM, on first use, never in the base: every VM
29新增:// is a copy of the base disk, and one VM knowing another's password could
30新增:// log into it through the host's loopback, which every VM reaches. The file
31新增:// is named after the hostname, which Lima sets per VM.
32新增:const codePrep = `
33新增:command -v code-server >/dev/null 2>&1 || { echo missing; exit 0; }
34新增:cfg="$HOME/.config/code-server/agent-vm-$(hostname).yaml"
35新增:if [ ! -s "$cfg" ]; then
36新增: pw="$(od -An -N16 -tx1 /dev/urandom | tr -d " \n")"
37新增: [ "${#pw}" = 32 ] || exit 1
38新增: mkdir -p "${cfg%/*}" || exit 1
39新增: (umask 077 && printf "auth: password\npassword: %s\ncert: false\n" "$pw" > "$cfg") || exit 1
40新增:fi
41新增:echo "config=$cfg"
42新增:echo "password=$(sed -n "s/^password: //p" "$cfg")"
43新增:pgrep -u "$(id -u)" -af -- "--config $cfg" \
44新增: | sed -n "s/.*--bind-addr 127\.0\.0\.1:\([0-9]*\).*/running=\1/p" | head -n 1
45新增:if command -v ss >/dev/null 2>&1; then
46新增: open=" $(ss -Hltn 2>/dev/null | awk "{ n = split(\$4, a, \":\"); printf \"%s \", a[n] }")"
47新增: for p in "$@"; do
48新增: case "$open" in *" $p "*) echo "listening=$p" ;; esac
49新增: done
50新增:else
51新增: for p in "$@"; do
52新增: curl -s -o /dev/null --noproxy "*" --max-time 1 "http://127.0.0.1:$p/"
53新增: [ $? -eq 7 ] || echo "listening=$p"
54新增: done
55新增:fi
56新增:exit 0
57新增:`
58新增:
59新增:var hex4 = regexp.MustCompile(`^[0-9a-f]{4}$`)
60新增:
61新增:// codePorts are ten host ports for the VM's editor, from 20000 to 29999,
62新增:// from its name: the same on every start, so the browser finds the saved
63新增:// password at the same address while the first is free. The last four
64新增:// digits of the name's hash start them, so two VMs rarely share them.
65新增:func codePorts(vmName string) []int {
66新增: h := ""
67新增: if len(vmName) >= 4 {
68新增: h = vmName[len(vmName)-4:]
69新增: }
70新增: if !hex4.MatchString(h) {
71新增: sum := sha256.Sum256([]byte(vmName))
72新增: h = hex.EncodeToString(sum[:])[:4]
73新增: }
74新增: n, _ := strconv.ParseInt(h, 16, 64)
75新增: base := 20000 + int(n)%9991
76新增: var out []int
77新增: for i := range 10 {
78新增: out = append(out, base+i)
79新增: }
80新增: return out
81新增:}
82新增:
83新增:// codeHost is where the browser reaches the VM's editor: <vm>.localhost,
84新增:// which browsers send to 127.0.0.1 on their own. Browsers keep cookies per
85新增:// host name, not per port: on 127.0.0.1, a page served by any VM would get
86新增:// the session cookie of every editor. Lowercase, at most 63 characters (a
87新增:// DNS label), the hash at the end kept.
88新增:func codeHost(vmName string) string {
89新增: l := strings.ToLower(vmName)
90新增: if len(l) > 63 {
91新增: l = l[:54] + "-" + l[len(l)-8:]
92新增: }
93新增: return l + ".localhost"
94新增:}
95新增:
96新增:func hostPortOpen(p int) bool {
97新增: c, err := net.DialTimeout("tcp", "127.0.0.1:"+strconv.Itoa(p), time.Second)
98新增: if err == nil {
99新增: c.Close()
100新增: return true
101新增: }
102新增: return false
103新增:}
104新增:
105新增:// codeSay prints the editor's address and password, and a note, in a box.
106新增:// Safari leaves *.localhost to macOS, which may not resolve it: 127.0.0.1
107新增:// then, in a window of its own.
108新增:func (s *start) codeSay(port int, pw, note string) {
109新增: body := fmt.Sprintf(" Address: http://%s:%d/\n Password: %s\n", codeHost(s.name), port, pw)
110新增: if runtime.GOOS == "darwin" {
111新增: body += fmt.Sprintf("\nIf Safari does not open it: http://127.0.0.1:%d/ in a private window kept for this editor, so pages from other VMs never get its cookie.\n", port)
112新增: }
113新增: if note != "" {
114新增: body += "\n" + note + "\n"
115新增: }
116新增: s.ui.Box("VS Code", body)
117新增:}
118新增:
119新增:// `code`: code-server for the project, in the foreground until Ctrl-C.
120新增:func (e *app) codeCmd(ctx context.Context, opts VMOpts, args []string) int {
121新增: rest, tty, err := opts.split(args)
122新增: if err != nil {
123新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
124新增: return 1
125新增: }
126新增: if len(rest) > 0 || tty {
127新增: a := "--tty"
128新增: if len(rest) > 0 {
129新增: a = rest[0]
130新增: }
131新增: fmt.Fprintf(e.io.Stderr, "Error: unknown argument for code: %s\nUsage: agent-vm [vm options] code\n", a)
132新增: return 1
133新增: }
134新增: return e.inVM(ctx, opts, (*start).codeSession)
135新增:}
136新增:
137新增:func (s *start) codeSession() int {
138新增: ports := codePorts(s.name)
139新增: args := []string{"zsh", "-lc", codePrep, "agent-vm-code"}
140新增: for _, p := range ports {
141新增: args = append(args, strconv.Itoa(p))
142新增: }
143新增: b, err := s.backend()
144新增: if err != nil {
145新增: return 1
146新增: }
147新增: var out strings.Builder
148新增: code, err := b.Shell(s.ctx, s.name, vm.ShellOpts{Args: args, Stdin: strings.NewReader(""), Stdout: &out, Stderr: s.io.Stderr})
149新增: if err != nil || code != 0 {
150新增: s.warnf("Error: could not set up the editor's password in VM '%s'.", s.name)
151新增: return 1
152新增: }
153新增: var cfg, pw, running string
154新增: listening := map[string]bool{}
155新增: for _, l := range strings.Split(out.String(), "\n") {
156新增: switch {
157新增: case l == "missing":
158新增: s.warnf("Error: code-server is not installed in VM '%s'.\n 'agent-vm setup --preinstall=default,code-claude' (or code-server alone) adds it to the base, then 'agent-vm --reset code'\n re-clones this VM (its disk is lost).", s.name)
159新增: return 1
160新增: case strings.HasPrefix(l, "config="):
161新增: cfg = strings.TrimPrefix(l, "config=")
162新增: case strings.HasPrefix(l, "password="):
163新增: pw = strings.TrimPrefix(l, "password=")
164新增: case strings.HasPrefix(l, "running="):
165新增: running = strings.TrimPrefix(l, "running=")
166新增: case strings.HasPrefix(l, "listening="):
167新增: listening[strings.TrimPrefix(l, "listening=")] = true
168新增: }
169新增: }
170新增: // Printed to the terminal: nothing the VM wrote may carry escape
171新增: // sequences.
172新增: if _, perr := strconv.Atoi(running); pw == "" || strings.IndexFunc(pw+cfg, unicode.IsControl) >= 0 || running != "" && perr != nil {
173新增: s.warnf("Error: could not read the editor's password in VM '%s'.", s.name)
174新增: return 1
175新增: }
176新增: if running != "" {
177新增: p, _ := strconv.Atoi(running)
178新增: s.codeSay(p, pw, fmt.Sprintf("The editor of VM '%s' already runs, from another terminal.", s.name))
179新增: return 0
180新增: }
181新增: // The first port free both here and in the VM: Lima forwards the VM's
182新增: // port to the same one here, and only when nothing holds it.
183新增: port := 0
184新增: for _, p := range ports {
185新增: if !listening[strconv.Itoa(p)] && !hostPortOpen(p) {
186新增: port = p
187新增: break
188新增: }
189新增: }
190新增: if port == 0 {
191新增: var ps []string
192新增: for _, p := range ports {
193新增: ps = append(ps, strconv.Itoa(p))
194新增: }
195新增: s.warnf("Error: no free port for the editor among: %s ", strings.Join(ps, " "))
196新增: return 1
197新增: }
198新增: s.codeSay(port, pw, "The password is kept in the VM, in "+cfg+". Ctrl-C stops the editor.")
199新增: // A terminal for Ctrl-C to reach code-server: without one, it would
200新增: // keep running in the VM once this command ends.
201新增: tty := ui.IsTerminal(os.Stdin) && ui.IsTerminal(os.Stdout)
202新增: // Bound to the VM's loopback, which Lima forwards to this machine's
203新增: // only. The cookie suffix keeps sessions apart at 127.0.0.1.
204新增: // --disable-proxy: no route from the browser to the VM's other ports;
205新增: // empty VSCODE_PROXY_URI leaves a link to localhost:<port> at that port
206新增: // here instead of rewriting it through the editor's /proxy/. An absolute
207新增: // template such as http://localhost:{{port}}/ breaks the workbench:
208新增: // code-server runs new URL() on it before substituting {{port}}, which
209新增: // throws Invalid URL (coder/code-server#6504).
210新增: // No experiments, and the built-in Copilot Chat never loads. Claude
211新增: // Code's login pages open without the link prompt, those paths only.
212新增: //
213新增: // Not a full boundary between VMs: no VM reaches this port itself
214新增: // (netguard), but any VM can listen on a port Lima forwards to this
215新增: // machine, and a page it serves can send the browser, with this editor's
216新增: // cookie, to a host name it chose.
217新增: return s.lima(tty, "VSCODE_PROXY_URI=", "code-server",
218新增: "--config", cfg,
219新增: "--bind-addr", "127.0.0.1:"+strconv.Itoa(port),
220新增: "--cookie-suffix", s.name,
221新增: "--app-name", s.name,
222新增: "--disable-telemetry",
223新增: "--disable-update-check",
224新增: "--disable-workspace-trust",
225新增: "--disable-proxy",
226新增: "--disable-getting-started-override",
227新增: "--link-protection-trusted-domains", "https://claude.com/cai/oauth",
228新增: "--link-protection-trusted-domains", "https://platform.claude.com/oauth",
229新增: "--vscode-option", "disable-experiments",
230新增: "--vscode-option", "disable-extension=GitHub.copilot-chat",
231新增: paths.Guest(s.dir))
232新增:}
新增internal/cli/code_test.go+83 −0看文件
@@ -0,0 +1,83 @@
1新增:package cli
2新增:
3新增:import (
4新增: "fmt"
5新增: "strconv"
6新增: "strings"
7新增: "testing"
8新增:
9新增: "github.com/sylvinus/agent-vm/internal/bashref"
10新增: "github.com/sylvinus/agent-vm/internal/paths"
11新增: "github.com/sylvinus/agent-vm/internal/vm"
12新增: "github.com/sylvinus/agent-vm/internal/vmname"
13新增:)
14新增:
15新增:func TestCodePortsHostBash(t *testing.T) {
16新增: for _, n := range []string{"proj-0000270f", "proj-ffffffff", "proj-00000000", "noHash", strings.Repeat("Long", 20) + "-abcdef12"} {
17新增: var ps []string
18新增: for _, p := range codePorts(n) {
19新增: ps = append(ps, strconv.Itoa(p))
20新增: }
21新增: r := bashref.Run(t, "", nil, "_agent_vm_code_ports", n)
22新增: if strings.Join(ps, " ")+" " != r.Stdout {
23新增: t.Errorf("codePorts(%q) = %v, bash %q", n, ps, r.Stdout)
24新增: }
25新增: r = bashref.Run(t, "", nil, "_agent_vm_code_host", n)
26新增: if codeHost(n)+"\n" != r.Stdout {
27新增: t.Errorf("codeHost(%q) = %q, bash %q", n, codeHost(n), r.Stdout)
28新增: }
29新增: }
30新增:}
31新增:
32新增:func TestCode(t *testing.T) {
33新增: se := newStartEnv(t)
34新增: se.base()
35新增: name := vmname.Name(se.proj)
36新增: answer := "missing\n"
37新增: var started []string
38新增: se.fake.ShellFunc = func(n string, o vm.ShellOpts) int {
39新增: if len(o.Args) > 2 && o.Args[2] == codePrep {
40新增: fmt.Fprint(o.Stdout, answer)
41新增: return 0
42新增: }
43新增: if strings.Contains(strings.Join(o.Args, " "), "code-server --config") {
44新增: started = o.Args
45新增: return 0
46新增: }
47新增: return se.g.shell(n, o)
48新增: }
49新增: if se.run("code") != 1 || !strings.Contains(se.out(), "code-server is not installed in VM") {
50新增: t.Errorf("missing: %s", se.out())
51新增: }
52新增: ports := codePorts(name)
53新增: answer = fmt.Sprintf("config=/home/u/.config/code-server/agent-vm-h.yaml\npassword=s3cret\nlistening=%d\n", ports[0])
54新增: if se.run("code") != 0 {
55新增: t.Fatalf("code: %s", se.out())
56新增: }
57新增: want := fmt.Sprintf("Address: http://%s:%d/", codeHost(name), ports[1])
58新增: if !strings.Contains(se.out(), want) || !strings.Contains(se.out(), "Password: s3cret") {
59新增: t.Errorf("box: %s", se.out())
60新增: }
61新增: args := strings.Join(started, " ")
62新增: for _, w := range []string{"--bind-addr 127.0.0.1:" + strconv.Itoa(ports[1]), "--cookie-suffix " + name, "--app-name " + name, "--disable-proxy",
63新增: "--config /home/u/.config/code-server/agent-vm-h.yaml", "--disable-telemetry", "--disable-update-check", "--disable-workspace-trust",
64新增: "--disable-getting-started-override", "--link-protection-trusted-domains https://claude.com/cai/oauth",
65新增: "--link-protection-trusted-domains https://platform.claude.com/oauth", "--vscode-option disable-experiments",
66新增: "--vscode-option disable-extension=GitHub.copilot-chat", "VSCODE_PROXY_URI= code-server", paths.Guest(se.proj)} {
67新增: if !strings.Contains(args, w) {
68新增: t.Errorf("missing %q in %s", w, args)
69新增: }
70新增: }
71新增: answer = "config=/c.yaml\npassword=x\nrunning=23456\n"
72新增: started = nil
73新增: if se.run("code") != 0 || !strings.Contains(se.out(), "already runs, from another") || !strings.Contains(se.out(), ":23456/") || started != nil {
74新增: t.Errorf("running: %s", se.out())
75新增: }
76新增: answer = "config=/c.yaml\npassword=a\033]0;x\007\n"
77新增: if se.run("code") != 1 || !strings.Contains(se.out(), "could not read the editor's password") {
78新增: t.Errorf("control characters: %s", se.out())
79新增: }
80新增: if se.run("code", "x") != 1 || !strings.Contains(se.out(), "unknown argument for code: x") {
81新增: t.Errorf("argument: %s", se.out())
82新增: }
83新增:}
新增internal/cli/commands.go+302 −0看文件
@@ -0,0 +1,302 @@
1新增:package cli
2新增:
3新增:import (
4新增: "context"
5新增: "fmt"
6新增: "os"
7新增: "os/signal"
8新增: "strconv"
9新增: "strings"
10新增: "syscall"
11新增: "time"
12新增:
13新增: "github.com/sylvinus/agent-vm/internal/paths"
14新增: "github.com/sylvinus/agent-vm/internal/state"
15新增: "github.com/sylvinus/agent-vm/internal/ui"
16新增: "github.com/sylvinus/agent-vm/internal/vm"
17新增: "github.com/sylvinus/agent-vm/internal/vmname"
18新增:)
19新增:
20新增:// session is what runs in the VM once it is up: an agent, a shell, a
21新增:// command. It returns the exit status.
22新增:type session func(s *start) int
23新增:
24新增:// endedBySignal is ctx for a run that a kill or a closed terminal (SIGTERM,
25新增:// SIGHUP) must end: the command in the VM stops with it, and the cleanup
26新增:// that follows (--rm, --scratch) runs on a context that does not end. A
27新增:// Ctrl-C is not one: see inVM. Signals after the first are swallowed until
28新增:// stop, so that the cleanup is not cut short.
29新增:func endedBySignal(parent context.Context) (ctx context.Context, stop func()) {
30新增: ctx, cancel := context.WithCancel(parent)
31新增: sig := make(chan os.Signal, 4)
32新增: signal.Notify(sig, syscall.SIGTERM, syscall.SIGHUP)
33新增: done := make(chan struct{})
34新增: go func() {
35新增: for {
36新增: select {
37新增: case <-sig:
38新增: cancel()
39新增: case <-done:
40新增: return
41新增: }
42新增: }
43新增: }()
44新增: return ctx, func() {
45新增: signal.Stop(sig)
46新增: close(done)
47新增: cancel()
48新增: }
49新增:}
50新增:
51新增:// inVM starts this directory's VM with opts, runs fn, then deletes the VM
52新增:// when --rm asked: after fn whatever it returns, and after a start that
53新增:// failed when this run made the VM (a VM that was there before is not
54新增:// deleted for a start that did not go through). A kill or a closed terminal
55新增:// (SIGTERM, SIGHUP) ends the command and still deletes. --scratch: see
56新增:// scratch.
57新增:func (e *app) inVM(ctx context.Context, opts VMOpts, fn session) int {
58新增: dir, err := vmname.AbsDir("")
59新增: if err != nil {
60新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
61新增: return 1
62新增: }
63新增: cleanup := context.WithoutCancel(ctx)
64新增: ctx, stop := endedBySignal(ctx)
65新增: defer stop()
66新增: if opts.Scratch {
67新增: return e.scratch(ctx, cleanup, opts, dir, fn)
68新增: }
69新增: s := &start{app: e, ctx: ctx, opts: opts, dir: dir, name: vmname.Name(dir)}
70新增: st := 1
71新增: started := s.ensureRunning() == nil
72新增: if started {
73新增: s.printResources()
74新增: // A Ctrl-C is the command's, in the VM, as a shell leaves it to the job
75新增: // it waits on: this run goes on to --rm and the terminal's reset.
76新增: sig := make(chan os.Signal, 1)
77新增: signal.Notify(sig, os.Interrupt)
78新增: st = fn(s)
79新增: signal.Stop(sig)
80新增: ui.ResetTermModes(os.Stdout)
81新增: }
82新增: if opts.RM && (started || s.created) && !e.removeVM(cleanup, s.name) && st == 0 {
83新增: st = 1
84新增: }
85新增: return st
86新增:}
87新增:
88新增:// printResources says what the VM has, and when the base it was cloned
89新增:// from was built: its agents and packages are that old.
90新增:func (s *start) printResources() {
91新增: if inst, err := s.get(s.name); err == nil && inst != nil {
92新增: fmt.Fprintf(s.io.Stdout, " Resources: CPUs: %d, Memory: %d GiB, Disk: %d GiB\n", inst.CPUs, inst.Memory>>30, inst.Disk>>30)
93新增: }
94新增: if built, err := strconv.ParseInt(s.state.ReadMarker(state.VersionOf, s.name), 10, 64); err == nil && built >= 0 {
95新增: fmt.Fprintf(s.io.Stdout, " Base VM: built %s\n", time.Unix(built, 0).Format("2006-01-02"))
96新增: }
97新增:}
98新增:
99新增:// lima runs args in the VM through a login zsh, from the project: agent PATH
100新增:// entries and ~/.agent-vm.env are in ~/.zshenv. The command and its
101新增:// arguments are positional parameters, never re-parsed; `env --` runs it,
102新增:// leading VAR=value assignments working and a command starting with - not
103新增:// taken for env's option. A command that is not there is said so, with
104新增:// env's status (an agent installed only as an editor extension has none);
105新增:// a path is env's to run, and to say why it cannot (126).
106新增:func (s *start) lima(tty bool, args ...string) int {
107新增: b, err := s.backend()
108新增: if err != nil {
109新增: return 1
110新增: }
111新增: code, err := b.Shell(s.ctx, s.name, vm.ShellOpts{
112新增: Workdir: paths.Guest(s.dir),
113新增: Args: append([]string{"zsh", "-l", "-c",
114新增: `case "$1" in *=*|*/*) ;; *) command -v -- "$1" >/dev/null || { print -r -- "agent-vm: $1 is not installed in this VM." >&2; exit 127; } ;; esac; exec env -- "$@"`,
115新增: "agent-vm"}, args...),
116新增: Stdin: s.io.Stdin, Stdout: s.io.Stdout, Stderr: s.io.Stderr, Interactive: tty,
117新增: })
118新增: if err != nil {
119新增: s.warnf("Error: %v", err)
120新增: return 1
121新增: }
122新增: return code
123新增:}
124新增:
125新增:// The agents, with the flag that lets each work unattended (safe in the
126新增:// VM), and a terminal for the full-screen ones.
127新增:var agents = map[string]struct {
128新增: cmd []string
129新增: tty bool
130新增:}{
131新增: // The VM also enforces bypass mode with managed settings: Claude Code
132新增: // drops the flag when it relaunches itself.
133新增: "claude": {[]string{"claude", "--dangerously-skip-permissions"}, false},
134新增: // Approves every prompt that is not explicitly denied.
135新增: "opencode": {[]string{"opencode", "--auto"}, true},
136新增: "codex": {[]string{"codex", "--dangerously-bypass-approvals-and-sandbox"}, false},
137新增: "vibe": {[]string{"vibe", "--agent", "auto-approve"}, true},
138新增: // No permission prompts: it runs every tool as asked.
139新增: "pi": {[]string{"pi"}, true},
140新增:}
141新增:
142新增:func (e *app) agentCmd(ctx context.Context, agent string, opts VMOpts, args []string) int {
143新增: a := agents[agent]
144新增: rest, tty, err := opts.split(args)
145新增: if err != nil {
146新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
147新增: return exitUsage
148新增: }
149新增: cmd := append(append([]string(nil), a.cmd...), rest...)
150新增: return e.inVM(ctx, opts, func(s *start) int { return s.lima(a.tty || tty, cmd...) })
151新增:}
152新增:
153新增:// `run [--tty] <command> [args]`: --tty gives the command a terminal, which
154新增:// full-screen programs need to draw.
155新增:func (e *app) runCmd(ctx context.Context, opts VMOpts, args []string) int {
156新增: rest, tty, err := opts.split(args)
157新增: if err != nil {
158新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
159新增: return exitUsage
160新增: }
161新增: if len(rest) == 0 {
162新增: fmt.Fprintln(e.io.Stderr, "Usage: agent-vm run [--tty] <command> [args]")
163新增: return exitUsage
164新增: }
165新增: return e.inVM(ctx, opts, func(s *start) int { return s.lima(tty, rest...) })
166新增:}
167新增:
168新增:// `shell [-c "command"]`: a login zsh in the VM, ~/.zshenv loaded. A word
169新增:// it does not know is an error, not something skipped.
170新增:func (e *app) shellCmd(ctx context.Context, opts VMOpts, args []string) int {
171新增: command := ""
172新增: for len(args) > 0 {
173新增: n, err := opts.take(args)
174新增: if err != nil {
175新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
176新增: return exitUsage
177新增: }
178新增: if n > 0 {
179新增: args = args[n:]
180新增: continue
181新增: }
182新增: switch args[0] {
183新增: case "-c", "--command":
184新增: if len(args) < 2 || args[1] == "" {
185新增: fmt.Fprintln(e.io.Stderr, "Error: -c/--command requires a command string.")
186新增: return exitUsage
187新增: }
188新增: command, args = args[1], args[2:]
189新增: default:
190新增: fmt.Fprintf(e.io.Stderr, "Error: unknown argument for shell: %s\nUsage: agent-vm [vm options] shell [-c \"command\"]\n", args[0])
191新增: return exitUsage
192新增: }
193新增: }
194新增: return e.inVM(ctx, opts, func(s *start) int {
195新增: if command != "" {
196新增: return s.shell(false, "zsh", "-l", "-c", command)
197新增: }
198新增: fmt.Fprintf(s.io.Stdout, "VM: %s | Dir: %s\n", s.name, s.dir)
199新增: if s.opts.RM {
200新增: fmt.Fprintln(s.io.Stdout, "Type 'exit' to leave. VM will be destroyed after exit.")
201新增: } else {
202新增: fmt.Fprintln(s.io.Stdout, "Type 'exit' to leave (VM keeps running). Use 'agent-vm stop' to stop it.")
203新增: }
204新增: return s.shell(true, "zsh", "-l")
205新增: })
206新增:}
207新增:
208新增:// shellTo runs args in the VM from the project, on the terminal.
209新增:func (s *start) shellTo(tty bool, args ...string) (int, error) {
210新增: b, err := s.backend()
211新增: if err != nil {
212新增: return 1, err
213新增: }
214新增: return b.Shell(s.ctx, s.name, vm.ShellOpts{Workdir: paths.Guest(s.dir), Args: args,
215新增: Stdin: s.io.Stdin, Stdout: s.io.Stdout, Stderr: s.io.Stderr, Interactive: tty})
216新增:}
217新增:
218新增:// shell is shellTo's exit status. When the shell could not run at all (the
219新增:// VM is not running, ssh fails), the reason is said and the status is 1: a
220新增:// caller must not read that as the command's success.
221新增:func (s *start) shell(tty bool, args ...string) int {
222新增: code, err := s.shellTo(tty, args...)
223新增: if err != nil {
224新增: s.warnf("Error: %v", err)
225新增: return 1
226新增: }
227新增: return code
228新增:}
229新增:
230新增:// scratch: a new VM of its own, sharing nothing, deleted once fn returns,
231新增:// whatever it returns, unless the user keeps it a while to look inside. A
232新增:// Ctrl-C ends the command in the VM, not this run, which goes on to the
233新增:// deletion. A run killed outright leaves its VM recorded with its pid, and
234新增:// the next scratch run deletes it. cleanup is the context of the deletions,
235新增:// which a kill of this run (ctx) does not end.
236新增:func (e *app) scratch(ctx, cleanup context.Context, opts VMOpts, dir string, fn session) int {
237新增: dead, unknown := e.scratchLeftovers()
238新增: for _, left := range dead {
239新增: fmt.Fprintf(e.io.Stdout, "Deleting scratch VM '%s', left by a run that did not finish...\n", left)
240新增: e.deleteVM(cleanup, left)
241新增: }
242新增: for _, left := range unknown {
243新增: fmt.Fprintf(e.io.Stderr, "Note: scratch VM '%s' has a record without a process number, so it is not known whether a run still uses it: left alone. 'agent-vm rm %s' deletes it.\n", left, left)
244新增: }
245新增: name, err := vmname.Scratch(dir)
246新增: if err != nil {
247新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
248新增: return 1
249新增: }
250新增: if err := e.state.Write(state.ScratchOf+name, []byte(strconv.Itoa(os.Getpid())+"\n")); err != nil {
251新增: fmt.Fprintf(e.io.Stderr, "Error: could not record scratch VM '%s': %v\n", name, err)
252新增: return 1
253新增: }
254新增: opts.RM = true
255新增: s := &start{app: e, ctx: ctx, opts: opts, dir: dir, name: name}
256新增: st := 1
257新增: if s.ensureRunning() == nil {
258新增: s.printResources()
259新增: sig := make(chan os.Signal, 1)
260新增: signal.Notify(sig, os.Interrupt)
261新增: st = fn(s)
262新增: signal.Stop(sig)
263新增: ui.ResetTermModes(os.Stdout)
264新增: // Asked before the deletion, when it can be (yes by default): a no
265新增: // opens a shell in the VM, to look at what the command left, and
266新增: // asks again on its exit. No terminal, a question cut short, or a
267新增: // kill, deletes.
268新增: for ctx.Err() == nil && e.ui.CanAsk() && !e.ui.AskYN(fmt.Sprintf("Delete scratch VM '%s'?", name), true) {
269新增: fmt.Fprintf(e.io.Stdout, "A shell in scratch VM '%s'. Type 'exit' to be asked again.\n", name)
270新增: s.shell(true, "zsh", "-l")
271新增: ui.ResetTermModes(os.Stdout)
272新增: }
273新增: }
274新增: fmt.Fprintf(e.io.Stdout, "Deleting scratch VM '%s'...\n", name)
275新增: if !e.deleteVM(cleanup, name) {
276新增: st = 1
277新增: }
278新增: return st
279新增:}
280新增:
281新增:// scratchLeftovers are the scratch VMs a run could not delete (killed, its
282新增:// terminal closed), by their record: dead are those recorded by a run whose
283新增:// pid is gone (a reused pid only delays the cleanup), unknown those whose
284新增:// record holds no pid, which is no proof that no run uses them. Only names
285新增:// Scratch makes.
286新增:func (e *app) scratchLeftovers() (dead, unknown []string) {
287新增: ents, _ := os.ReadDir(string(e.state))
288新增: for _, f := range ents {
289新增: name, ok := strings.CutPrefix(f.Name(), state.ScratchOf)
290新增: if !ok || !vmname.IsScratch(name) {
291新增: continue
292新增: }
293新增: pid, err := strconv.Atoi(strings.TrimSpace(e.state.Read(f.Name())))
294新增: switch {
295新增: case err != nil || pid <= 0:
296新增: unknown = append(unknown, name)
297新增: case !alive(pid):
298新增: dead = append(dead, name)
299新增: }
300新增: }
301新增: return dead, unknown
302新增:}
新增internal/cli/doctor.go+383 −0看文件
@@ -0,0 +1,383 @@
1新增:package cli
2新增:
3新增:import (
4新增: "bytes"
5新增: "context"
6新增: "errors"
7新增: "fmt"
8新增: "os"
9新增: "os/exec"
10新增: "runtime"
11新增: "slices"
12新增: "strconv"
13新增: "strings"
14新增: "time"
15新增:
16新增: limaversion "github.com/lima-vm/lima/v2/pkg/version"
17新增:
18新增: "github.com/sylvinus/agent-vm/internal/env"
19新增: "github.com/sylvinus/agent-vm/internal/gitguard"
20新增: "github.com/sylvinus/agent-vm/internal/guard"
21新增: "github.com/sylvinus/agent-vm/internal/host"
22新增: "github.com/sylvinus/agent-vm/internal/mounts"
23新增: "github.com/sylvinus/agent-vm/internal/netguard"
24新增: "github.com/sylvinus/agent-vm/internal/runscript"
25新增: "github.com/sylvinus/agent-vm/internal/state"
26新增: "github.com/sylvinus/agent-vm/internal/version"
27新增: "github.com/sylvinus/agent-vm/internal/vm"
28新增: "github.com/sylvinus/agent-vm/internal/vmname"
29新增:)
30新增:
31新增:// doctor counts what it finds.
32新增:type doctor struct {
33新增: e *app
34新增: warn, fail int
35新增:}
36新增:
37新增:// line prints one finding: level ok, warn, fail or info, then hints.
38新增:func (d *doctor) line(level, msg string, hints ...string) {
39新增: w := d.e.io.Stdout
40新增: switch level {
41新增: case "ok":
42新增: fmt.Fprintf(w, " ok %s\n", msg)
43新增: case "warn":
44新增: fmt.Fprintf(w, " warn %s\n", msg)
45新增: d.warn++
46新增: case "fail":
47新增: fmt.Fprintf(w, " FAIL %s\n", msg)
48新增: d.fail++
49新增: default:
50新增: fmt.Fprintf(w, " - %s\n", msg)
51新增: }
52新增: for _, h := range hints {
53新增: fmt.Fprintf(w, " %s\n", h)
54新增: }
55新增:}
56新增:
57新增:func (d *doctor) section(name string) { fmt.Fprintf(d.e.io.Stdout, "\n%s\n", name) }
58新增:
59新增:// `doctor`: checks the host, Lima, the base template and the current
60新增:// directory, and says what to do about each problem. Read-only: it never
61新增:// creates, starts or stops a VM, so it is safe to run first and to paste
62新增:// into an issue (names, no secret values). 1 when a check failed.
63新增:func (e *app) doctorCmd(ctx context.Context, args []string) int {
64新增: if len(args) > 0 {
65新增: fmt.Fprintln(e.io.Stderr, "Usage: agent-vm doctor")
66新增: return 2
67新增: }
68新增: d := &doctor{e: e}
69新增: w := e.io.Stdout
70新增: fmt.Fprintln(w, "agent-vm doctor")
71新增: d.section("agent-vm")
72新增: exe, _ := os.Executable()
73新增: d.line("info", fmt.Sprintf("version %s, from %s", version.Version, exe))
74新增:
75新增: d.section("Host")
76新增: d.line("info", runtime.GOOS+" "+runtime.GOARCH)
77新增: cpus, mem := host.CPUs(), host.MemGiB()
78新增: if cpus > 0 && mem > 0 {
79新增: div, bad, invalid := host.Divisor()
80新增: var discard bytes.Buffer
81新增: d.line("info", fmt.Sprintf("%d CPUs, %d GiB RAM; a VM gets at most %d CPUs and %d GiB (a 1/%d share)",
82新增: cpus, mem, host.Cap("cpus", cpus, &discard), host.Cap("memory", mem, &discard), div))
83新增: if invalid {
84新增: d.line("warn", fmt.Sprintf("AGENT_VM_HOST_SHARE='%s' is not a positive integer: 2 is used", bad))
85新增: }
86新增: } else {
87新增: d.line("warn", "could not read the host's CPU or RAM: --cpus and --memory are not clamped")
88新增: }
89新增: dir := LimaHome(e.state)
90新增: if _, err := os.Stat(dir); err != nil {
91新增: dir, _ = os.UserHomeDir()
92新增: }
93新增: switch free, ok := host.FreeGiB(dir); {
94新增: case !ok:
95新增: d.line("warn", "could not read the free disk space")
96新增: case free < 10:
97新增: d.line("warn", fmt.Sprintf("%d GiB free for the VMs", free), "A default VM disk is 10 GiB (sparse).")
98新增: default:
99新增: d.line("ok", fmt.Sprintf("%d GiB free for the VMs", free))
100新增: }
101新增:
102新增: d.section("Lima")
103新增: d.line("info", fmt.Sprintf("Lima %s, built in; its VMs in %s", strings.TrimPrefix(limaversion.Version, "v"), LimaHome(e.state)))
104新增: for _, f := range vm.LimaOverrides(LimaHome(e.state)) {
105新增: d.line("fail", f+" adds to every VM's config: agent-vm makes and starts no VM while it is there", "Move it out of the way.")
106新增: }
107新增: protects := !writableGitOptOut(false)
108新增: if protects {
109新增: d.line("ok", "every .git is read-only for the VMs (sshfs.readonlyNames)")
110新增: } else {
111新增: d.line("warn", "AGENT_VM_UNSAFE_WRITABLE_GIT=1: the VMs can write .git, and git on this machine runs what .git/config and hooks name",
112新增: "Unset it to keep .git read-only.")
113新增: }
114新增: var prereqs bytes.Buffer
115新增: switch runtime.GOOS {
116新增: case "linux":
117新增: if host.LinuxPrereqs(&prereqs) {
118新增: d.line("ok", "QEMU and /dev/kvm are usable")
119新增: } else {
120新增: d.line("fail", "QEMU or KVM is not usable", strings.Split(strings.TrimSuffix(prereqs.String(), "\n"), "\n")...)
121新增: }
122新增: case "windows":
123新增: if host.WindowsPrereqs(&prereqs, &prereqs) {
124新增: d.line("ok", "QEMU is installed")
125新增: } else {
126新增: d.line("fail", "QEMU is not usable", strings.Split(strings.TrimSuffix(prereqs.String(), "\n"), "\n")...)
127新增: }
128新增: d.line("info", "QEMU also needs the 'Windows Hypervisor Platform' feature, which only an administrator can check or turn on",
129新增: "Without it, VMs fail to start with a WHPX error. An administrator runs, once, then reboots:", host.WHPXOn)
130新增: }
131新增:
132新增: // A bare repository is not named .git, so the names do not cover one the
133新增: // VM plants in a project.
134新增: if st := gitguard.BareState(ctx); st != gitguard.BareNoGit {
135新增: d.section("Git on this machine")
136新增: switch st {
137新增: case gitguard.BareOK:
138新增: d.line("ok", "safe.bareRepository = explicit")
139新增: case gitguard.BareOld:
140新增: out, _ := exec.CommandContext(ctx, "git", "--version").Output()
141新增: d.line("warn", strings.TrimSpace(string(out))+" is older than 2.38: it would use a repository a VM creates under another name than .git, and run what its config names",
142新增: "Upgrade git, then: git config --global safe.bareRepository explicit")
143新增: default:
144新增: d.line("warn", "safe.bareRepository is not 'explicit': git would use a repository a VM creates under another name than .git, and run what its config names",
145新增: "git config --global safe.bareRepository explicit")
146新增: }
147新增: }
148新增:
149新增: d.section("Base template")
150新增: b, berr := e.readOnlyBackend()
151新增: if vms, old := e.unmovedOld(); len(vms) > 0 {
152新增: d.line("info", fmt.Sprintf("%d VM(s) of agent-vm 0.2 in %s, not moved yet", len(vms), old),
153新增: "The next agent-vm command that starts or removes a VM offers to move them.")
154新增: }
155新增: getVM := func(name string) (*vm.Instance, error) {
156新增: if berr != nil {
157新增: return nil, berr
158新增: }
159新增: inst, err := b.Get(ctx, name)
160新增: if errors.Is(err, vm.ErrNotFound) {
161新增: return nil, nil
162新增: }
163新增: return inst, err
164新增: }
165新增: base, err := getVM(vmname.Template)
166新增: _, merr := os.Stat(e.state.Path(state.BaseVersion))
167新增: switch {
168新增: case err != nil:
169新增: d.line("warn", "could not query Lima")
170新增: case base != nil && merr == nil:
171新增: if built, perr := strconv.ParseInt(e.state.Read(state.BaseVersion), 10, 64); perr == nil {
172新增: d.line("ok", fmt.Sprintf("%s is ready, built %s", vmname.Template, time.Unix(built, 0).Format("2006-01-02")))
173新增: if time.Since(time.Unix(built, 0)) > 90*24*time.Hour {
174新增: d.line("warn", "the base template is over 90 days old", "Its agents and packages are as old. 'agent-vm setup' rebuilds it.")
175新增: }
176新增: } else {
177新增: d.line("ok", vmname.Template+" is ready")
178新增: }
179新增: if _, err := os.Stat(e.state.Path(state.BaseBuiltBy)); err != nil {
180新增: d.line("warn", "the base template was built by agent-vm 0.1.0, without what the shares that keep .git read-only need",
181新增: "'agent-vm setup' rebuilds it, then '--reset' the VMs made from it.")
182新增: }
183新增: case base != nil:
184新增: d.line("fail", vmname.Template+" exists but its setup did not complete", "Run 'agent-vm setup' again.")
185新增: default:
186新增: d.line("fail", "no base template yet", "Run 'agent-vm setup'.")
187新增: }
188新增:
189新增: d.section(fmt.Sprintf("Settings (%s)", e.state))
190新增: if content, err := os.ReadFile(e.state.Path("env")); err == nil {
191新增: keys := len(unique(env.Names(string(content))))
192新增: fi, serr := os.Stat(e.state.Path("env"))
193新增: switch {
194新增: case runtime.GOOS == "windows":
195新增: // Permission bits mean little there: the file's ACL protects it.
196新增: d.line("info", fmt.Sprintf("env: %d key(s)", keys))
197新增: case serr == nil && fi.Mode().Perm()&0o077 == 0:
198新增: d.line("ok", fmt.Sprintf("env: %d key(s), private to you (mode %o)", keys, fi.Mode().Perm()))
199新增: case serr == nil:
200新增: d.line("warn", fmt.Sprintf("env is readable by other users on this machine (mode %o)", fi.Mode().Perm()), fmt.Sprintf("chmod 600 '%s'", e.state.Path("env")))
201新增: default:
202新增: d.line("warn", "env permissions could not be checked", fmt.Sprintf("chmod 600 '%s'", e.state.Path("env")))
203新增: }
204新增: } else {
205新增: d.line("info", "env: none (agent-vm env set KEY VALUE)")
206新增: }
207新增: for _, f := range []string{"volumes", "setup.sh", "runtime.sh", guard.FileName} {
208新增: if _, err := os.Stat(e.state.Path(f)); err == nil {
209新增: d.line("info", f+": present")
210新增: }
211新增: }
212新增: switch pol, err := netguard.Load(string(e.state)); {
213新增: case err != nil:
214新增: d.line("fail", err.Error(), "No VM starts until it is fixed.")
215新增: case pol.Open:
216新增: d.line("warn", "network isolation off (AGENT_VM_UNSAFE_OPEN_NETWORK=1): the VMs reach this machine and its networks")
217新增: case len(pol.Allow) > 0 || len(pol.Domains) > 0:
218新增: d.line("info", netguard.FileName+": present")
219新增: }
220新增:
221新增: wd, _ := vmname.AbsDir("")
222新增: d.section(fmt.Sprintf("This directory (%s)", wd))
223新增: d.directory(ctx, wd, protects, getVM)
224新增:
225新增: d.section("All VMs")
226新增: if vms, err := e.lookVMs(ctx); err == nil {
227新增: n, c, m := 0, 0, 0
228新增: for _, v := range vms {
229新增: if v.Status == vm.Running {
230新增: n, c, m = n+1, c+v.CPUs, m+int(v.Memory>>30)
231新增: }
232新增: }
233新增: switch {
234新增: case n == 0:
235新增: d.line("info", "none running")
236新增: case mem > 0 && m > mem:
237新增: d.line("warn", fmt.Sprintf("%d running, %d CPUs and %d GiB in total: more memory than the host has", n, c, m),
238新增: "'agent-vm list' lists them; 'agent-vm stop <name>' frees one.")
239新增: default:
240新增: d.line("info", fmt.Sprintf("%d running, %d CPUs and %d GiB in total", n, c, m))
241新增: }
242新增: }
243新增: dead, unknown := e.scratchLeftovers()
244新增: for _, left := range dead {
245新增: d.line("warn", "scratch VM "+left+" was left by a run that did not finish", "The next --scratch run deletes it, or: agent-vm rm "+left)
246新增: }
247新增: for _, left := range unknown {
248新增: d.line("warn", "scratch VM "+left+" has a record without a process number: not known whether a run still uses it", "agent-vm rm "+left+" deletes it.")
249新增: }
250新增:
251新增: fmt.Fprintln(w)
252新增: if d.fail > 0 {
253新增: fmt.Fprintf(w, "%d problem(s), %d warning(s).\n", d.fail, d.warn)
254新增: return 1
255新增: }
256新增: fmt.Fprintf(w, "No problems found, %d warning(s).\n", d.warn)
257新增: return 0
258新增:}
259新增:
260新增:func unique(s []string) []string {
261新增: var out []string
262新增: for _, x := range s {
263新增: if !slices.Contains(out, x) {
264新增: out = append(out, x)
265新增: }
266新增: }
267新增: return out
268新增:}
269新增:
270新增:// directory checks the project dir: its path, its VM and what protects it,
271新增:// the hooks and config git runs from its shares, its runtime and env files.
272新增:func (d *doctor) directory(ctx context.Context, dir string, protects bool, getVM func(string) (*vm.Instance, error)) {
273新增: e := d.e
274新增: if why, bad := mounts.Unmountable(dir); bad {
275新增: d.line("fail", "the path "+why, "agent-vm refuses to mount it. Rename the directory.")
276新增: }
277新增: if why, bad := mounts.UnsafeProject(dir, e.refs()); bad {
278新增: d.line("fail", "this directory "+why, "agent-vm refuses to share it with a VM. Run it from a project directory.")
279新增: }
280新增: scan := e.scan(ctx, dir)
281新增: names := scan.Names()
282新增: name := vmname.Name(dir)
283新增: inst, err := getVM(name)
284新增: switch {
285新增: case err != nil:
286新增: d.line("warn", "could not query Lima")
287新增: case inst == nil:
288新增: d.line("info", name+" will be created on the first agent-vm command here")
289新增: case inst.ConfigErr != nil:
290新增: d.line("fail", "Lima cannot read the config of "+name, inst.ConfigErr.Error(), "'agent-vm --reset <command>' re-clones it.")
291新增: default:
292新增: if e.staleState(name) == "1" {
293新增: d.line("warn", name+" was cloned from an older base template", "'agent-vm --reset <command>' re-clones it.")
294新增: } else {
295新增: d.line("ok", name+" exists")
296新增: }
297新增: confined := vm.Confined(inst)
298新增: switch {
299新增: case inst.Status == vm.Running && confined == nil:
300新增: d.line("ok", "running; the project share is enforced on the host (--readonly works)")
301新增: case inst.Status == vm.Running:
302新增: d.line("warn", "running with a share the host does not confine: "+confined.Error(),
303新增: "The next start (after 'agent-vm stop') sets its shares back.")
304新增: default:
305新增: d.line("info", "stopped")
306新增: }
307新增: protected := len(inst.Mounts) > 0 && unprotected(inst, nil) == ""
308新增: current := unprotected(inst, names) == ""
309新增: switch {
310新增: case protected && !current:
311新增: d.line("warn", "its shares keep .git read-only, but not all of "+strings.Join(names, ", "),
312新增: "The next start (after 'agent-vm stop' if it runs) fixes that.")
313新增: case protected:
314新增: d.line("ok", "its shares keep every .git read-only")
315新增: case !protects:
316新增: d.line("warn", "its shares leave .git writable (AGENT_VM_UNSAFE_WRITABLE_GIT=1)")
317新增: default:
318新增: d.line("warn", "its shares leave .git writable", "The next start (after 'agent-vm stop' if it runs) fixes that.")
319新增: }
320新增: }
321新增: for _, h := range scan.Hooks {
322新增: rel, inRepo, _ := strings.Cut(h, "\t")
323新增: if rel == "" {
324新增: continue
325新增: }
326新增: what := "git runs hooks from " + rel + " (core.hooksPath)"
327新增: switch {
328新增: case rel == ".":
329新增: what = "git runs hooks from the project directory itself (core.hooksPath)"
330新增: case inRepo == ".":
331新增: what = "git runs hooks from " + rel + ", which no read-only name covers (core.hooksPath)"
332新增: }
333新增: hn, ok := gitguard.HooksName(inRepo)
334新增: current := false
335新增: if inst != nil {
336新增: current = unprotected(inst, names) == ""
337新增: }
338新增: switch {
339新增: case !ok:
340新增: d.line("warn", what+", which the VM can write",
341新增: "agent-vm can only keep a folder inside a share read-only, by a name without quotes or backslashes: point core.hooksPath to one.")
342新增: case !protects:
343新增: d.line("warn", what+", which the VM can write", "agent-vm keeps it read-only when it keeps .git read-only (see above).")
344新增: case inst == nil:
345新增: d.line("info", fmt.Sprintf("%s: every '%s' in the project will be read-only for the VM", what, hn))
346新增: case current:
347新增: d.line("ok", fmt.Sprintf("%s: every '%s' in the project is read-only for the VM", what, hn))
348新增: default:
349新增: d.line("warn", what+", which the VM can still write",
350新增: fmt.Sprintf("The next start (after 'agent-vm stop' if it runs) makes every '%s' in the project read-only.", hn))
351新增: }
352新增: }
353新增: if risks := scan.Risks(names); len(risks) > 0 {
354新增: d.line("warn", "git on this machine uses these, and the VM can write them:",
355新增: append(risks, "Move them out of the shared folders, or have them name commands outside them.")...)
356新增: }
357新增: rt := runscript.ProjectPath(dir)
358新增: if rel, ok := env.ProjectRel(dir, rt); ok {
359新增: // Not by its path: the VM can make it a symlink.
360新增: if b, err := env.ReadIn(dir, rel); err == nil {
361新增: d.line("info", fmt.Sprintf("project runtime: %s (%s)", rt, runscript.Interpreter(string(b))))
362新增: }
363新增: } else if b, err := os.ReadFile(rt); err == nil {
364新增: d.line("info", fmt.Sprintf("project runtime: %s (%s)", rt, runscript.Interpreter(string(b))))
365新增: }
366新增: pe := env.ProjectEnvFile(dir)
367新增: if _, err := os.Stat(pe); err == nil {
368新增: var warn bytes.Buffer
369新增: saved := e.io.Stderr
370新增: e.io.Stderr = &warn
371新增: e.warnUnignored(ctx, pe)
372新增: e.io.Stderr = saved
373新增: if warn.Len() > 0 {
374新增: var hints []string
375新增: for _, l := range strings.Split(strings.TrimSuffix(warn.String(), "\n"), "\n") {
376新增: hints = append(hints, strings.TrimLeft(l, " "))
377新增: }
378新增: d.line("warn", "project env: "+pe, hints...)
379新增: } else {
380新增: d.line("ok", "project env: "+pe)
381新增: }
382新增: }
383新增:}
新增internal/cli/doctor_test.go+111 −0看文件
@@ -0,0 +1,111 @@
1新增:package cli
2新增:
3新增:import (
4新增: "errors"
5新增: "os"
6新增: "os/exec"
7新增: "path/filepath"
8新增: "runtime"
9新增: "strings"
10新增: "testing"
11新增:
12新增: "github.com/sylvinus/agent-vm/internal/paths"
13新增: "github.com/sylvinus/agent-vm/internal/state"
14新增: "github.com/sylvinus/agent-vm/internal/vmname"
15新增:)
16新增:
17新增:func TestDoctor(t *testing.T) {
18新增: se := newStartEnv(t)
19新增: if code := se.run("doctor"); code != 1 || !strings.Contains(se.stdout.String(), " FAIL no base template yet") ||
20新增: !strings.Contains(se.stdout.String(), " ok safe.bareRepository = explicit") || !strings.HasSuffix(se.stdout.String(), "warning(s).\n") {
21新增: t.Errorf("no base:\n%s", se.out())
22新增: }
23新增: if se.run("doctor", "x") != 2 || !strings.Contains(se.out(), "Usage: agent-vm doctor") {
24新增: t.Errorf("an argument: %s", se.out())
25新增: }
26新增:
27新增: se.base()
28新增: exec.Command("git", "-C", se.proj, "init", "-q").Run()
29新增: exec.Command("git", "-C", se.proj, "config", "core.hooksPath", ".husky/_").Run()
30新增: se.run("run", "true")
31新增: out := func() string { se.run("doctor"); return se.stdout.String() }
32新增: o := out()
33新增: for _, want := range []string{
34新增: " ok base is ready, built ",
35新增: " ok " + vmname.Name(se.proj) + " exists",
36新增: " ok running; the project share is enforced on the host (--readonly works)",
37新增: " ok its shares keep every .git read-only",
38新增: " ok git runs hooks from .husky/_ (core.hooksPath): every '.husky' in the project is read-only for the VM",
39新增: " ok every .git is read-only for the VMs (sshfs.readonlyNames)",
40新增: "1 running, ",
41新增: " warning(s).\n",
42新增: } {
43新增: if !strings.Contains(o, want) {
44新增: t.Errorf("missing %q in:\n%s", want, o)
45新增: }
46新增: }
47新增: // The VM's shares without a name the project needs now.
48新增: v := se.fake.VMs[vmname.Name(se.proj)]
49新增: v.Mounts[0].SSHFS.ReadonlyNames = []string{".git", ".hg", ".sl", ".jj"}
50新增: o = out()
51新增: if !strings.Contains(o, " warn its shares keep .git read-only, but not all of .git, .hg, .sl, .jj, .husky") ||
52新增: !strings.Contains(o, " warn git runs hooks from .husky/_ (core.hooksPath), which the VM can still write") {
53新增: t.Errorf("older names:\n%s", o)
54新增: }
55新增: // An env others can read; a leftover scratch VM; a config risk.
56新增: os.WriteFile(se.state.Path("env"), []byte("A=1\nB=2\nA=3\n"), 0o644)
57新增: os.Chmod(se.state.Path("env"), 0o644)
58新增: os.WriteFile(se.state.Marker(state.ScratchOf, "x-scratch-0000aaaa"), []byte("999999999\n"), 0o644)
59新增: exec.Command("git", "-C", se.proj, "config", "core.fsmonitor", "./mon.sh").Run()
60新增: o = out()
61新增: // Permission bits mean little on Windows (see doctor.go): only the
62新增: // count is said there.
63新增: envReadable, envPrivate := " warn env is readable by other users on this machine (mode 644)", " ok env: 2 key(s), private to you (mode 600)"
64新增: if runtime.GOOS == "windows" {
65新增: envReadable, envPrivate = " - env: 2 key(s)", " - env: 2 key(s)"
66新增: }
67新增: for _, want := range []string{
68新增: envReadable,
69新增: " warn scratch VM x-scratch-0000aaaa was left by a run that did not finish",
70新增: " core.fsmonitor = ./mon.sh",
71新增: } {
72新增: if !strings.Contains(o, want) {
73新增: t.Errorf("missing %q in:\n%s", want, o)
74新增: }
75新增: }
76新增: os.Chmod(se.state.Path("env"), 0o600)
77新增: if o = out(); !strings.Contains(o, envPrivate) {
78新增: t.Errorf("env:\n%s", o)
79新增: }
80新增: // A mount type the host does not enforce; doctor changes nothing.
81新增: v.MountType = "9p"
82新增: se.fake.Calls = nil
83新增: if o = out(); !strings.Contains(o, " warn running with a share the host does not confine: ") || !strings.Contains(o, `the mount type is "9p"`) {
84新增: t.Errorf("9p:\n%s", o)
85新增: }
86新增: if strings.Contains(se.fake.CallLog(), "edit") || strings.Contains(se.fake.CallLog(), "start") || strings.Contains(se.fake.CallLog(), "stop") {
87新增: t.Errorf("doctor changed the VM:\n%s", se.fake.CallLog())
88新增: }
89新增: // Lima's overrides, and a config Lima refuses. Host-spelled: doctor
90新增: // spells its folders so.
91新增: cfg := paths.Host(filepath.Join(LimaHome(se.state), "_config"))
92新增: os.MkdirAll(cfg, 0o755)
93新增: os.WriteFile(cfg+"/override.yaml", []byte("mounts: []\n"), 0o644)
94新增: v.ConfigErr = errors.New("field `mounts[1].sshfs.sftpDriver` must be `builtin`")
95新增: o = out()
96新增: for _, want := range []string{
97新增: " FAIL " + cfg + "/override.yaml adds to every VM's config",
98新增: " FAIL Lima cannot read the config of " + vmname.Name(se.proj),
99新增: " field `mounts[1].sshfs.sftpDriver` must be `builtin`",
100新增: } {
101新增: if !strings.Contains(o, want) {
102新增: t.Errorf("missing %q in:\n%s", want, o)
103新增: }
104新增: }
105新增: v.ConfigErr = nil
106新增: os.Remove(cfg + "/override.yaml")
107新增: se.fake.Err = errors.New("broken")
108新增: if o = out(); !strings.Contains(o, " warn could not query Lima") {
109新增: t.Errorf("broken backend:\n%s", o)
110新增: }
111新增:}
新增internal/cli/e2e_test.go+119 −0看文件
@@ -0,0 +1,119 @@
1新增://go:build e2e
2新增:
3新增:package cli
4新增:
5新增:import (
6新增: "bytes"
7新增: "context"
8新增: "io"
9新增: "os"
10新增: "os/exec"
11新增: "path/filepath"
12新增: "strings"
13新增: "testing"
14新增: "time"
15新增:
16新增: "github.com/lima-vm/lima/v2/pkg/instance"
17新增:)
18新增:
19新增:// agent-vm as a user runs it, on real VMs: setup, then a command in a
20新增:// project, its .git read-only. go test -tags e2e -run TestE2E ./internal/cli/
21新增:// Slow without hardware acceleration: AGENT_VM_E2E_TIMEOUT (default 60m)
22新增:// for each boot, and go test's -timeout.
23新增:func TestE2E(t *testing.T) {
24新增: timeout := 60 * time.Minute
25新增: if v := os.Getenv("AGENT_VM_E2E_TIMEOUT"); v != "" {
26新增: d, err := time.ParseDuration(v)
27新增: if err != nil {
28新增: t.Fatal(err)
29新增: }
30新增: timeout = d
31新增: }
32新增: ctx := instance.WithWatchHostAgentTimeout(context.Background(), timeout)
33新增: // Short: Lima's sockets live under it, at most 104 or 108 characters.
34新增: // AGENT_VM_E2E_DIR: where, when /tmp cannot hold the VMs' disks.
35新增: parent := os.Getenv("AGENT_VM_E2E_DIR")
36新增: if parent == "" {
37新增: parent = "/tmp"
38新增: }
39新增: home, err := os.MkdirTemp(parent, "avm")
40新增: if err != nil {
41新增: t.Fatal(err)
42新增: }
43新增: t.Cleanup(func() { os.RemoveAll(home) })
44新增: t.Setenv("HOME", home)
45新增: t.Setenv("AGENT_VM_STATE_DIR", filepath.Join(home, ".agent-vm"))
46新增: t.Setenv("GIT_CONFIG_NOSYSTEM", "1")
47新增: os.Unsetenv("GIT_CONFIG_GLOBAL")
48新增: os.Unsetenv("XDG_CONFIG_HOME")
49新增: os.WriteFile(filepath.Join(home, ".gitconfig"), []byte("[safe]\n\tbareRepository = explicit\n"), 0o644)
50新增: skipPrereqs = true // for hosts without KVM: QEMU emulates
51新增:
52新增: run := func(dir string, args ...string) (int, string) {
53新增: t.Helper()
54新增: t.Chdir(dir)
55新增: t.Setenv("PWD", dir)
56新增: var out bytes.Buffer
57新增: w := io.MultiWriter(&out, os.Stderr)
58新增: e, err := newApp(IO{Stdin: strings.NewReader(""), Stdout: w, Stderr: w})
59新增: if err != nil {
60新增: t.Fatal(err)
61新增: }
62新增: return e.main(ctx, args), out.String()
63新增: }
64新增:
65新增: start := time.Now()
66新增: if code, out := run(home, "setup", "--preinstall=none"); code != 0 {
67新增: t.Fatalf("setup: %d\n%s", code, out)
68新增: }
69新增: t.Logf("setup in %v", time.Since(start).Round(time.Second))
70新增: t.Cleanup(func() { run(home, "destroy-all") })
71新增:
72新增: proj := filepath.Join(home, "proj")
73新增: os.MkdirAll(proj, 0o755)
74新增: if err := exec.Command("git", "-C", proj, "init", "-q").Run(); err != nil {
75新增: t.Fatal(err)
76新增: }
77新增: cfg, _ := os.ReadFile(filepath.Join(proj, ".git", "config"))
78新增: os.WriteFile(filepath.Join(home, ".agent-vm", "env"), []byte("SECRET='s3'\n"), 0o600)
79新增: code, out := run(proj, "run", "sh", "-c",
80新增: `echo hi > from-vm && printf 'a\n' >> from-vm && echo "secret=$SECRET" && (echo x >> .git/config && echo WROTE-GIT || echo REFUSED-GIT)`)
81新增: if code != 0 {
82新增: t.Fatalf("run: %d\n%s", code, out)
83新增: }
84新增: if !strings.Contains(out, "secret=s3") {
85新增: t.Errorf("the env did not reach the command:\n%s", out)
86新增: }
87新增: if !strings.Contains(out, "REFUSED-GIT") {
88新增: t.Errorf(".git was writable:\n%s", out)
89新增: }
90新增: if b, _ := os.ReadFile(filepath.Join(proj, ".git", "config")); !bytes.Equal(b, cfg) {
91新增: t.Errorf(".git/config changed: %q", b)
92新增: }
93新增: if b, _ := os.ReadFile(filepath.Join(proj, "from-vm")); string(b) != "hi\na\n" {
94新增: t.Errorf("on the host: %q", b)
95新增: }
96新增: if code, out := run(proj, "info"); code != 0 || !strings.Contains(out, "vm_running=1") || !strings.Contains(out, "git_protected=1") {
97新增: t.Errorf("info: %s", out)
98新增: }
99新增: // sshfs's cache off: a change on the host shows at once.
100新增: os.WriteFile(filepath.Join(proj, "f"), []byte("v1\n"), 0o644)
101新增: if code, out := run(proj, "run", "cat", "f"); code != 0 || !strings.Contains(out, "v1") {
102新增: t.Errorf("first read: %d %s", code, out)
103新增: }
104新增: os.WriteFile(filepath.Join(proj, "f"), []byte("v2, longer\n"), 0o644)
105新增: if code, out := run(proj, "run", "cat", "f"); code != 0 || !strings.Contains(out, "v2, longer") {
106新增: t.Errorf("read after a change on the host: %d %s", code, out)
107新增: }
108新增: // A share lost in the VM: found by the probe, and mounted again.
109新增: if code, out := run(proj, "run", "sh", "-c", `cd / && sudo umount -l "$1"`, "sh", proj); code != 0 {
110新增: t.Fatalf("umount: %d %s", code, out)
111新增: }
112新增: code, out = run(proj, "run", "cat", "f")
113新增: if code != 0 || !strings.Contains(out, "the project share is not mounted") || !strings.Contains(out, "v2, longer") {
114新增: t.Errorf("lost share: %d %s", code, out)
115新增: }
116新增: if code, out := run(proj, "stop"); code != 0 || !strings.Contains(out, "VM stopped.") {
117新增: t.Errorf("stop: %s", out)
118新增: }
119新增:}
新增internal/cli/envcmd.go+250 −0看文件
@@ -0,0 +1,250 @@
1新增:package cli
2新增:
3新增:import (
4新增: "context"
5新增: "errors"
6新增: "fmt"
7新增: "io"
8新增: "os"
9新增: "path/filepath"
10新增: "regexp"
11新增: "strings"
12新增:
13新增: "golang.org/x/term"
14新增:
15新增: "github.com/sylvinus/agent-vm/internal/env"
16新增: "github.com/sylvinus/agent-vm/internal/gitx"
17新增: "github.com/sylvinus/agent-vm/internal/paths"
18新增: "github.com/sylvinus/agent-vm/internal/vmname"
19新增:)
20新增:
21新增:var keyRe = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)
22新增:
23新增:// envFile is an env file: top is the project folder when the file is inside
24新增:// it, and is then only touched without following links (env.ReadIn).
25新增:type envFile struct {
26新增: path, top string
27新增:}
28新增:
29新增:func (f envFile) read() ([]byte, error) {
30新增: if f.top != "" {
31新增: return env.ReadIn(f.top, strings.TrimPrefix(f.path, strings.TrimSuffix(f.top, "/")+"/"))
32新增: }
33新增: fi, err := os.Stat(f.path)
34新增: if errors.Is(err, os.ErrNotExist) || err == nil && !fi.Mode().IsRegular() {
35新增: return nil, env.ErrNoFile
36新增: }
37新增: return os.ReadFile(f.path)
38新增:}
39新增:
40新增:// write replaces the file, atomically, mode 600.
41新增:func (f envFile) write(data []byte) error {
42新增: if f.top != "" {
43新增: return env.WriteIn(f.top, strings.TrimPrefix(f.path, strings.TrimSuffix(f.top, "/")+"/"), data)
44新增: }
45新增: if err := os.MkdirAll(filepath.Dir(f.path), 0o755); err != nil {
46新增: return err
47新增: }
48新增: tmp, err := os.CreateTemp(filepath.Dir(f.path), filepath.Base(f.path)+".")
49新增: if err != nil {
50新增: return err
51新增: }
52新增: _, werr := tmp.Write(data)
53新增: if err := errors.Join(werr, tmp.Chmod(0o600), tmp.Close()); err != nil {
54新增: os.Remove(tmp.Name())
55新增: return err
56新增: }
57新增: if err := os.Rename(tmp.Name(), f.path); err != nil {
58新增: os.Remove(tmp.Name())
59新增: return err
60新增: }
61新增: return nil
62新增:}
63新增:
64新增:// envVerb runs `env` (~/.agent-vm/env) and `project-env`: set, get, has,
65新增:// unset, list, on a file the VM's shell sources, so the quoting is done
66新增:// here, once. Writes are atomic and mode 600, other lines kept; list prints
67新增:// names, never values. The file is held in memory, never in a temporary
68新增:// file: it holds secrets.
69新增:func (e *app) envVerb(verb string, f envFile, args []string) int {
70新增: stderr := e.io.Stderr
71新增: usage := fmt.Sprintf("Usage: agent-vm %s {set KEY [VALUE]|get KEY|has KEY|unset KEY|list}", verb)
72新增: action, key := "list", ""
73新增: if len(args) > 0 {
74新增: action = args[0]
75新增: }
76新增: if len(args) > 1 {
77新增: key = args[1]
78新增: }
79新增: switch action {
80新增: case "set", "get", "has", "unset":
81新增: if key == "" {
82新增: fmt.Fprintf(stderr, "Error: 'agent-vm %s %s' needs a KEY.\n", verb, action)
83新增: return 1
84新增: }
85新增: if !keyRe.MatchString(key) {
86新增: fmt.Fprintf(stderr, "Error: '%s' is not a valid environment variable name.\n", key)
87新增: return 1
88新增: }
89新增: case "list":
90新增: default:
91新增: fmt.Fprintln(stderr, usage)
92新增: return 1
93新增: }
94新增: // A word too many is refused: `set TOKEN my secret` would store "my".
95新增: maxArgs := map[string]int{"set": 3, "list": 1}[action]
96新增: if maxArgs == 0 {
97新增: maxArgs = 2
98新增: }
99新增: if len(args) > maxArgs {
100新增: fmt.Fprintf(stderr, "Error: too many arguments for 'agent-vm %s %s'. Quote a value with spaces.\n", verb, action)
101新增: fmt.Fprintln(stderr, usage)
102新增: return 1
103新增: }
104新增: // Without VALUE, read from stdin, typed unseen on a terminal: a value on
105新增: // the command line lands in the shell history and in `ps`. From a pipe,
106新增: // one trailing newline goes, as `echo` adds it.
107新增: value := ""
108新增: if action == "set" {
109新增: if len(args) == 3 {
110新增: value = args[2]
111新增: } else if in, ok := e.io.Stdin.(*os.File); ok && term.IsTerminal(int(in.Fd())) {
112新增: fmt.Fprintf(stderr, "Value for %s (not shown): ", key)
113新增: b, err := term.ReadPassword(int(in.Fd()))
114新增: fmt.Fprintln(stderr)
115新增: if err == nil {
116新增: value = string(b)
117新增: }
118新增: } else {
119新增: b, _ := io.ReadAll(e.io.Stdin)
120新增: value = strings.TrimSuffix(string(b), "\n")
121新增: }
122新增: if len(args) < 3 && value == "" {
123新增: fmt.Fprintf(stderr, "Error: 'agent-vm %s set %s' needs a VALUE, as an argument or on stdin.\n", verb, key)
124新增: return 1
125新增: }
126新增: }
127新增:
128新增: content, err := f.read()
129新增: have := true
130新增: switch {
131新增: case err == nil:
132新增: case errors.Is(err, env.ErrNoFile):
133新增: have = false
134新增: case errors.Is(err, env.ErrUnsafe):
135新增: fmt.Fprintf(stderr, "Error: %s is a symlink, is reached through one, or is not a regular file.\n", f.path)
136新增: fmt.Fprintln(stderr, " agent-vm follows no link in the project, which the VM can write. Replace it with a plain file.")
137新增: return 2
138新增: default:
139新增: fmt.Fprintf(stderr, "Error: could not read %s\n", f.path)
140新增: return 2
141新增: }
142新增:
143新增: switch action {
144新增: case "set", "unset":
145新增: if action == "unset" && !have {
146新增: return 0
147新增: }
148新增: next := env.Drop(string(content), key)
149新增: if action == "set" {
150新增: next += fmt.Sprintf("%s='%s'\n", key, env.SQEscape(value))
151新增: }
152新增: // A write dropped silently would tell the caller a secret was stored
153新增: // when it was not.
154新增: if err := f.write([]byte(next)); err != nil {
155新增: fmt.Fprintf(stderr, "Error: could not write %s\n", f.path)
156新增: return 1
157新增: }
158新增: case "get", "has":
159新增: if !have {
160新增: return 1
161新增: }
162新增: // Read, never sourced: the project's file is one the VM can write.
163新增: v, st := env.Lookup(string(content), key)
164新增: switch st {
165新增: case env.NotFound:
166新增: return 1
167新增: case env.Refused:
168新增: fmt.Fprintf(stderr, "Error: %s in %s uses, or comes after, shell syntax agent-vm does not evaluate\n", key, f.path)
169新增: fmt.Fprintf(stderr, " ($, backquotes, backslashes, ~, ;, | ...). Rewrite it with 'agent-vm %s set'.\n", verb)
170新增: return 2
171新增: }
172新增: if action == "get" {
173新增: fmt.Fprintln(e.io.Stdout, v)
174新增: }
175新增: case "list":
176新增: if !have {
177新增: return 0
178新增: }
179新增: seen := map[string]bool{}
180新增: for _, n := range env.Names(string(content)) {
181新增: if !seen[n] {
182新增: seen[n] = true
183新增: fmt.Fprintln(e.io.Stdout, n)
184新增: }
185新增: }
186新增: }
187新增: return 0
188新增:}
189新增:
190新增:func (e *app) sharedEnvCmd(args []string) int {
191新增: return e.envVerb("env", envFile{path: e.state.Path("env")}, args)
192新增:}
193新增:
194新增:func (e *app) projectEnvCmd(ctx context.Context, args []string) int {
195新增: wd, err := vmname.AbsDir("")
196新增: if err != nil {
197新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
198新增: return 1
199新增: }
200新增: f := envFile{path: env.ProjectEnvFile(wd)}
201新增: if rel, ok := env.ProjectRel(wd, f.path); ok {
202新增: f = envFile{path: wd + "/" + rel, top: wd}
203新增: }
204新增: if st := e.envVerb("project-env", f, args); st != 0 {
205新增: return st
206新增: }
207新增: // After a write that worked: when the file is new to the repository,
208新增: // and the user is looking.
209新增: if len(args) > 0 && args[0] == "set" {
210新增: e.warnUnignored(ctx, f.path)
211新增: }
212新增: return 0
213新增:}
214新增:
215新增:// warnUnignored warns, with the line that fixes it, when file is tracked by
216新增:// git or not ignored. Silent without git or a repository.
217新增:func (e *app) warnUnignored(ctx context.Context, file string) {
218新增: if !gitx.Have() {
219新增: return
220新增: }
221新增: out, err := gitx.Untrusted(ctx, "-C", filepath.Dir(file), "rev-parse", "--show-toplevel").Output()
222新增: top := strings.TrimSuffix(string(out), "\n")
223新增: if err != nil || top == "" {
224新增: return
225新增: }
226新增: // git prints the top resolved (/var is a link to /private/var on
227新增: // macOS): the file's spelling must be, or the prefix below misses and
228新增: // the warning never fires.
229新增: if phys, err := filepath.EvalSymlinks(file); err == nil {
230新增: file = phys
231新增: }
232新增: // git prints C:/... on Windows, in either case for the drive.
233新增: rel, ok := paths.CutPrefix(filepath.ToSlash(file), filepath.ToSlash(top)+"/")
234新增: if !ok {
235新增: // A worktree elsewhere, an odd spelling: not something to lecture about.
236新增: return
237新增: }
238新增: qTop, qRel := env.SQEscape(top), env.SQEscape(rel)
239新增: if gitx.Untrusted(ctx, "-C", top, "ls-files", "--error-unmatch", file).Run() == nil {
240新增: fmt.Fprintf(e.io.Stderr, "Warning: %s is tracked by git: its contents are in the repository.\n", rel)
241新增: fmt.Fprintf(e.io.Stderr, " git -C '%s' rm --cached '%s' && echo '/%s' >> '%s/.gitignore'\n", qTop, qRel, qRel, qTop)
242新增: return
243新增: }
244新增: err = gitx.Untrusted(ctx, "-C", top, "check-ignore", "-q", file).Run()
245新增: var ee interface{ ExitCode() int }
246新增: if errors.As(err, &ee) && ee.ExitCode() == 1 {
247新增: fmt.Fprintf(e.io.Stderr, "Warning: %s is not ignored by git: it can be committed by accident.\n", rel)
248新增: fmt.Fprintf(e.io.Stderr, " echo '/%s' >> '%s/.gitignore'\n", qRel, qTop)
249新增: }
250新增:}
新增internal/cli/envcmd_test.go+155 −0看文件
@@ -0,0 +1,155 @@
1新增:package cli
2新增:
3新增:import (
4新增: "context"
5新增: "os"
6新增: "os/exec"
7新增: "path/filepath"
8新增: "strings"
9新增: "testing"
10新增:
11新增: "github.com/sylvinus/agent-vm/internal/bashref"
12新增: "github.com/sylvinus/agent-vm/internal/state"
13新增:)
14新增:
15新增:// Each sequence of env and project-env commands gives the same output,
16新增:// status and files as 0.2, run each in its own project and state folder.
17新增:func TestEnvBash(t *testing.T) {
18新增: type step struct {
19新增: args []string
20新增: stdin string
21新增: }
22新增: seqs := [][]step{
23新增: {{[]string{"env", "list"}, ""}, {[]string{"env", "get", "A"}, ""}, {[]string{"env", "has", "A"}, ""}},
24新增: {{[]string{"env", "set", "A", "O'Brien"}, ""}, {[]string{"env", "get", "A"}, ""}, {[]string{"env"}, ""}},
25新增: {{[]string{"env", "set", "A"}, "piped\n"}, {[]string{"env", "set", "B"}, "multi\nline\n"}, {[]string{"env", "get", "B"}, ""},
26新增: {[]string{"env", "set", "A", "again"}, ""}, {[]string{"env", "list"}, ""}, {[]string{"env", "unset", "A"}, ""}, {[]string{"env", "list"}, ""}},
27新增: {{[]string{"env", "set", "A"}, ""}, {[]string{"env", "set", "1A", "x"}, ""}, {[]string{"env", "set"}, ""}, {[]string{"env", "set", "A", "b", "c"}, ""},
28新增: {[]string{"env", "frob"}, ""}, {[]string{"env", "get", "A", "B"}, ""}, {[]string{"env", "list", "x"}, ""}, {[]string{"env", "unset", "NOPE"}, ""}},
29新增: {{[]string{"project-env", "set", "K", "v"}, ""}, {[]string{"project-env", "get", "K"}, ""}, {[]string{"project-env", "list"}, ""}},
30新增: }
31新增: for i, seq := range seqs {
32新增: // Resolved: the bash recordings read back under one spelling
33新增: // (/var is a link to /private/var on macOS).
34新增: gproj, _ := filepath.EvalSymlinks(t.TempDir())
35新增: bproj, _ := filepath.EvalSymlinks(t.TempDir())
36新增: gst, _ := filepath.EvalSymlinks(t.TempDir())
37新增: bst, _ := filepath.EvalSymlinks(t.TempDir())
38新增: bfiles := []string{filepath.Join(bst, "env"), filepath.Join(bproj, ".agent-vm.env")}
39新增: var want bashref.Result
40新增: for _, s := range seq {
41新增: te := newTestEnv(t, nil)
42新增: te.state = state.Dir(gst)
43新增: te.io.Stdin = strings.NewReader(s.stdin)
44新增: t.Chdir(gproj)
45新增: t.Setenv("PWD", gproj)
46新增: code := te.main(context.Background(), s.args)
47新增: got := bashref.Result{Stdout: te.stdout.String(), Stderr: te.stderr.String(), Code: code}
48新增:
49新增: want = bashStdin(t, bproj, []string{"AGENT_VM_STATE_DIR=" + bst}, s.stdin, bfiles, s.args...)
50新增: got.Stderr = strings.ReplaceAll(got.Stderr, gst, "STATE")
51新增: want.Stderr = strings.ReplaceAll(want.Stderr, bst, "STATE")
52新增: got.Stderr = strings.ReplaceAll(got.Stderr, gproj, "PROJ")
53新增: want.Stderr = strings.ReplaceAll(want.Stderr, bproj, "PROJ")
54新增: if got.Stdout != want.Stdout || got.Stderr != want.Stderr || got.Code != want.Code {
55新增: t.Errorf("seq %d, %q:\n go: %+v\n bash: %+v", i, s.args, got, want)
56新增: }
57新增: }
58新增: for j, f := range []string{filepath.Join(gst, "env"), filepath.Join(gproj, ".agent-vm.env")} {
59新增: gb, gerr := os.ReadFile(f)
60新增: bb, bok := want.Files[bfiles[j]]
61新增: if string(gb) != bb || (gerr == nil) != bok {
62新增: t.Errorf("seq %d: %s: go %q, bash %q", i, filepath.Base(f), gb, bb)
63新增: }
64新增: if gerr == nil {
65新增: if fi, _ := os.Stat(f); fi.Mode().Perm() != 0o600 {
66新增: t.Errorf("seq %d: %s mode %v", i, f, fi.Mode())
67新增: }
68新增: }
69新增: }
70新增: }
71新增:}
72新增:
73新增:func bashStdin(t *testing.T, dir string, envs []string, stdin string, files []string, args ...string) bashref.Result {
74新增: t.Helper()
75新增: return bashref.Exec(t, bashref.Cmd{Dir: dir, Env: append([]string{"PWD=" + dir}, envs...), Stdin: stdin,
76新增: Snippet: `agent-vm "$@"`, Args: args, Files: files})
77新增:}
78新增:
79新增:// After a set, the same warnings as 0.2 when git would commit the file.
80新增:func TestProjectEnvGitBash(t *testing.T) {
81新增: if _, err := exec.LookPath("git"); err != nil {
82新增: t.Skip("no git")
83新增: }
84新增: t.Setenv("GIT_CONFIG_GLOBAL", "/dev/null")
85新增: t.Setenv("GIT_CONFIG_NOSYSTEM", "1")
86新增: for _, tracked := range []bool{false, true} {
87新增: // Resolved, as above: git prints --show-toplevel resolved too.
88新增: gproj, _ := filepath.EvalSymlinks(t.TempDir())
89新增: bproj, _ := filepath.EvalSymlinks(t.TempDir())
90新增: for _, p := range []string{gproj, bproj} {
91新增: sub := filepath.Join(p, "sub")
92新增: os.MkdirAll(sub, 0o755)
93新增: exec.Command("git", "-C", p, "init", "-q").Run()
94新增: if tracked {
95新增: os.WriteFile(filepath.Join(sub, ".agent-vm.env"), []byte("X=1\n"), 0o600)
96新增: exec.Command("git", "-C", p, "add", "sub/.agent-vm.env").Run()
97新增: }
98新增: }
99新增: te := newTestEnv(t, nil)
100新增: t.Chdir(filepath.Join(gproj, "sub"))
101新增: t.Setenv("PWD", filepath.Join(gproj, "sub"))
102新增: code := te.main(context.Background(), []string{"project-env", "set", "K", "v"})
103新增: want := bashStdin(t, filepath.Join(bproj, "sub"), []string{"GIT_CONFIG_GLOBAL=/dev/null", "GIT_CONFIG_NOSYSTEM=1"}, "", nil, "project-env", "set", "K", "v")
104新增: got := strings.ReplaceAll(te.stderr.String(), gproj, "PROJ")
105新增: if code != want.Code || got != strings.ReplaceAll(want.Stderr, bproj, "PROJ") || got == "" {
106新增: t.Errorf("tracked %v:\n go: %d %q\n bash: %d %q", tracked, code, got, want.Code, want.Stderr)
107新增: }
108新增: }
109新增:}
110新增:
111新增:// A repository the VM planted in the project (a bare one made a work tree,
112新增:// its config naming a command): the warning after a set runs nothing of it,
113新增:// whatever the user's safe.bareRepository.
114新增:func TestProjectEnvPlantedRepo(t *testing.T) {
115新增: if _, err := exec.LookPath("git"); err != nil {
116新增: t.Skip("no git")
117新增: }
118新增: t.Setenv("GIT_CONFIG_GLOBAL", "/dev/null")
119新增: t.Setenv("GIT_CONFIG_NOSYSTEM", "1")
120新增: proj, marker := t.TempDir(), filepath.Join(t.TempDir(), "ran")
121新增: cmd := filepath.Join(t.TempDir(), "fsm.sh")
122新增: os.WriteFile(cmd, []byte("#!/bin/sh\necho ran >> "+marker+"\n"), 0o755)
123新增: exec.Command("git", "init", "-q", "--bare", proj).Run()
124新增: for _, kv := range [][2]string{{"core.bare", "false"}, {"core.worktree", proj}, {"core.fsmonitor", cmd}, {"core.pager", cmd}} {
125新增: exec.Command("git", "-C", proj, "config", kv[0], kv[1]).Run()
126新增: }
127新增: te := newTestEnv(t, nil)
128新增: t.Chdir(proj)
129新增: t.Setenv("PWD", proj)
130新增: if code := te.main(context.Background(), []string{"project-env", "set", "K", "v"}); code != 0 {
131新增: t.Fatalf("set: %d %s", code, te.out())
132新增: }
133新增: if _, err := os.Stat(marker); err == nil {
134新增: t.Error("ran the planted repository's command")
135新增: }
136新增:}
137新增:
138新增:// A project env file that is a symlink is never followed.
139新增:func TestProjectEnvSymlink(t *testing.T) {
140新增: proj := t.TempDir()
141新增: secret := filepath.Join(t.TempDir(), "secret")
142新增: os.WriteFile(secret, []byte("TOPSECRET=1\n"), 0o600)
143新增: os.Symlink(secret, filepath.Join(proj, ".agent-vm.env"))
144新增: t.Chdir(proj)
145新增: t.Setenv("PWD", proj)
146新增: for _, args := range [][]string{{"project-env", "get", "TOPSECRET"}, {"project-env", "list"}, {"project-env", "set", "K", "v"}, {"project-env", "unset", "TOPSECRET"}} {
147新增: te := newTestEnv(t, nil)
148新增: if code := te.main(context.Background(), args); code != 2 || !strings.Contains(te.stderr.String(), "is a symlink") || strings.Contains(te.stdout.String(), "TOPSECRET") {
149新增: t.Errorf("%q: %d %s %s", args, code, te.stdout.String(), te.stderr.String())
150新增: }
151新增: }
152新增: if b, _ := os.ReadFile(secret); string(b) != "TOPSECRET=1\n" {
153新增: t.Error("the target changed")
154新增: }
155新增:}
新增internal/cli/guest_test.go+136 −0看文件
@@ -0,0 +1,136 @@
1新增:package cli
2新增:
3新增:import (
4新增: "errors"
5新增: "os"
6新增: "os/exec"
7新增: "path/filepath"
8新增: "strings"
9新增: "testing"
10新增:
11新增: "github.com/sylvinus/agent-vm/internal/vm"
12新增:)
13新增:
14新增:// localGuest runs what the VM would, on this machine: the project is at its
15新增:// own path, as the share puts it, and the guest has its own home.
16新增:func localGuest(t *testing.T, se *startEnv) (home string, ran *[][]string) {
17新增: t.Helper()
18新增: for _, sh := range []string{"sh", "zsh", "awk"} {
19新增: if _, err := exec.LookPath(sh); err != nil {
20新增: t.Skip("no " + sh)
21新增: }
22新增: }
23新增: home = t.TempDir()
24新增: var calls [][]string
25新增: se.fake.ShellFunc = func(name string, o vm.ShellOpts) int {
26新增: calls = append(calls, append([]string{o.Workdir}, o.Args...))
27新增: cmd := exec.Command(o.Args[0], o.Args[1:]...)
28新增: cmd.Dir = o.Workdir
29新增: if cmd.Dir == "" {
30新增: cmd.Dir = home
31新增: }
32新增: cmd.Env = []string{"HOME=" + home, "PATH=" + os.Getenv("PATH"), "ZDOTDIR=" + home}
33新增: cmd.Stdin, cmd.Stdout, cmd.Stderr = o.Stdin, o.Stdout, o.Stderr
34新增: err := cmd.Run()
35新增: var ee *exec.ExitError
36新增: if errors.As(err, &ee) {
37新增: return ee.ExitCode()
38新增: }
39新增: if err != nil {
40新增: t.Fatal(err)
41新增: }
42新增: return 0
43新增: }
44新增: return home, &calls
45新增:}
46新增:
47新增:// The probe, run as the VM runs it: the env pushed private, the project's
48新增:// own after the shared one, CRs dropped; nothing left in the project.
49新增:func TestGuestProbe(t *testing.T) {
50新增: se := newStartEnv(t)
51新增: se.base()
52新增: home, _ := localGuest(t, se)
53新增: os.WriteFile(se.state.Path("env"), []byte("TOKEN='x'\n"), 0o600)
54新增: os.WriteFile(filepath.Join(se.proj, ".agent-vm.env"), []byte("P=1\r\n"), 0o600)
55新增: if code := se.run("run", "true"); code != 0 {
56新增: t.Fatalf("run: %d %s", code, se.out())
57新增: }
58新增: fi, err := os.Stat(filepath.Join(home, ".agent-vm.env"))
59新增: if err != nil || fi.Mode().Perm() != 0o600 {
60新增: t.Fatalf("guest env: %v %v", fi, err)
61新增: }
62新增: if b, _ := os.ReadFile(filepath.Join(home, ".agent-vm.env")); string(b) != "TOKEN='x'\nP=1\n" {
63新增: t.Errorf("guest env: %q", b)
64新增: }
65新增: ents, _ := os.ReadDir(se.proj)
66新增: for _, e := range ents {
67新增: if strings.Contains(e.Name(), "probe") {
68新增: t.Errorf("left in the project: %s", e.Name())
69新增: }
70新增: }
71新增: // Removed on the host: emptied in the guest.
72新增: os.Remove(se.state.Path("env"))
73新增: os.Remove(filepath.Join(se.proj, ".agent-vm.env"))
74新增: se.run("run", "true")
75新增: if b, err := os.ReadFile(filepath.Join(home, ".agent-vm.env")); err != nil || len(b) != 0 {
76新增: t.Errorf("guest env after removal: %q %v", b, err)
77新增: }
78新增:}
79新增:
80新增:// ~/.agent-vm/runtime.sh: piped whole into the VM, CRs dropped, under the
81新增:// shell its shebang names.
82新增:func TestGuestUserRuntime(t *testing.T) {
83新增: se := newStartEnv(t)
84新增: se.base()
85新增: localGuest(t, se)
86新增: os.WriteFile(se.state.Path("runtime.sh"), []byte("#!/bin/bash -e\r\necho \"bash=${BASH_VERSION:+yes}\"\r\n"), 0o644)
87新增: if code := se.run("run", "true"); code != 0 || !strings.Contains(se.out(), "Running user runtime setup...") || !strings.Contains(se.out(), "bash=yes\n") {
88新增: t.Errorf("runtime.sh: %d %q", code, se.out())
89新增: }
90新增:}
91新增:
92新增:// `run`'s wrapper: a missing command is 127 and said so, a file without +x
93新增:// is env's 126, an assignment goes to the command.
94新增:func TestGuestRun(t *testing.T) {
95新增: se := newStartEnv(t)
96新增: se.base()
97新增: localGuest(t, se)
98新增: if code := se.run("run", "no-such-command-x"); code != 127 || !strings.Contains(se.out(), "agent-vm: no-such-command-x is not installed in this VM.") {
99新增: t.Errorf("missing: %d %s", code, se.out())
100新增: }
101新增: os.WriteFile(filepath.Join(se.proj, "s.sh"), []byte("#!/bin/sh\necho hi\n"), 0o644)
102新增: if code := se.run("run", "./s.sh"); code != 126 {
103新增: t.Errorf("no +x: %d %s", code, se.out())
104新增: }
105新增: if code := se.run("run", "V=x", "sh", "-c", "echo v=$V"); code != 0 || !strings.Contains(se.out(), "v=x") {
106新增: t.Errorf("assignment: %d %s", code, se.out())
107新增: }
108新增:}
109新增:
110新增:// A project runtime script that is a link out of the project runs in the
111新增:// VM, by its path there: the host never reads it (the agent can retarget
112新增:// the link at any host file).
113新增:func TestGuestRuntimeLink(t *testing.T) {
114新增: se := newStartEnv(t)
115新增: se.base()
116新增: _, ran := localGuest(t, se)
117新增: outside := filepath.Join(t.TempDir(), "rt.sh")
118新增: os.WriteFile(outside, []byte("#!/bin/sh\necho from-runtime\n"), 0o644)
119新增: os.Symlink(outside, filepath.Join(se.proj, ".agent-vm.runtime.sh"))
120新增: if code := se.run("run", "true"); code != 0 || !strings.Contains(se.out(), "Running project runtime setup...") {
121新增: t.Fatalf("run: %d %s", code, se.out())
122新增: }
123新增: inVM := false
124新增: for _, c := range *ran {
125新增: last := c[len(c)-1]
126新增: if last == filepath.Join(se.proj, ".agent-vm.runtime.sh") && c[1] == "zsh" {
127新增: inVM = true
128新增: }
129新增: if strings.Contains(strings.Join(c, " "), " -s") && strings.HasPrefix(c[len(c)-1], "exec ") {
130新增: t.Errorf("piped from the host: %q", c)
131新增: }
132新增: }
133新增: if !inVM || !strings.Contains(se.out(), "from-runtime") {
134新增: t.Errorf("not run in the VM by its path: %q\n%s", *ran, se.out())
135新增: }
136新增:}
改名lib/help.sh → internal/cli/help.txt+35 −19看文件
@@ -1,13 +1,8 @@
1删除:# --- help ---------------------------------------------------------------------
2删除:
3删除:_agent_vm_help() {
4删除: cat << 'EOF'
51Usage: agent-vm [options] <command> [args]
62
73Commands:
84 install Put agent-vm on your PATH (a link in ~/.local/bin, or
9删除: AGENT_VM_BIN_DIR). Run it from the clone:
10删除: ./agent-vm.sh install
5新增: AGENT_VM_BIN_DIR)
116 uninstall Remove that link. VMs and ~/.agent-vm are left alone.
127 setup Create the base VM template (run once)
138 claude [args] Run Claude Code in the VM for the current directory
@@ -39,6 +34,7 @@ Commands:
3934 each was cloned from
4035 doctor Check the host, Lima, the base template and this
4136 directory, and say how to fix what is wrong. Read-only.
37新增: licenses Print the licenses of agent-vm and of what is built into it
4238 name [dir] Print the VM name for a directory (default: cwd)
4339 info [dir] Print machine-readable state as key=value lines
4440 (version, template, state_dir, project_env, dir,
@@ -128,24 +124,26 @@ Examples:
128124 agent-vm run --tty opencode -p "..." # Run a TUI with PTY allocated
129125 agent-vm code # VS Code in the browser
130126 agent-vm claude -p "fix lint errors" # Pass args to claude
131删除: agent-vm rm agent-vm-old-name-1a2b3c4d # Delete a VM by name (see 'list')
127新增: agent-vm rm old-name-1a2b3c4d # Delete a VM by name (see 'list')
132128
133129VMs are persistent and unique per directory. Running "agent-vm shell" or
134130"agent-vm claude" in the same directory will reuse the same VM.
135131
136删除:Every .git in the shared folders is read-only for the VMs when Lima supports
137删除:it (sshfs.readonlyNames, not merged upstream yet: 'agent-vm setup' offers a
138删除:Lima build that has it). Every .hg is too, and so is the folder of each
139删除:core.hooksPath in the project (.husky for husky). 'agent-vm doctor' says
140删除:where you stand.
132新增:Every .git in the shared folders is read-only for the VMs (Lima's
133新增:sshfs.readonlyNames, built into agent-vm). Every .hg is too, and so is the
134新增:folder of each core.hooksPath in the project (.husky for husky).
135新增:'agent-vm doctor' says where you stand.
141136
142137Before a VM boots with writable shares, agent-vm stops on what it cannot
143138protect, and asks whether to go on (no by default, and when it cannot ask):
144删除:a Lima without readonlyNames, hooks at the top of a share, git config,
145删除:commands it names, or hooks linked to files, in the project or a writable
146删除:volume, and git ignoring safe.bareRepository=explicit (which it offers to
147删除:set: git would otherwise use a folder with HEAD, objects/ and refs/ as a
148删除:repository, under any name). A VM that already runs gets the warnings only,
139新增:hooks no read-only name covers (the top of a share or of a repository, or a
140新增:writable volume), git config, commands it names, or hooks linked to files, in
141新增:the project or a writable volume, and git ignoring
142新增:safe.bareRepository=explicit (which it offers to set: git would otherwise use
143新增:a folder with HEAD, objects/ and refs/ as a repository, under any name). It
144新增:checks the repository holding each share and those at most two folders below
145新增:it, 50 per share; deeper ones are not checked.
146新增:A VM that already runs gets the warnings only,
149147and a restart when it lacks a protection; once stopped to boot again, it is
150148asked like any other.
151149'agent-vm info' lists what a start would ask
@@ -159,6 +157,24 @@ back a file as it was before you changed it. AGENT_VM_SSHFS_CACHE=1 in your
159157shell turns the cache on, faster on many files (git status, find), at that
160158risk, for 20 seconds. It applies when a VM is next started.
161159
160新增:The VMs reach the internet, not this machine nor its local networks.
161新增:~/.agent-vm/network (none by default) allows more, one line each:
162新增:'allow 192.168.1.10:5432', 'allow 10.0.0.0/8', 'allow localhost:11434' (a
163新增:service on this machine's loopback, at 192.168.5.2 in the VM; 'localhost'
164新增:alone: every port). 'domain github.com' lines make those domains,
165新增:subdomains included, the only names of the internet the VMs reach.
166新增:AGENT_VM_UNSAFE_OPEN_NETWORK=1 in your shell turns isolation off. A port a
167新增:VM listens on is forwarded to this machine's loopback, unless a program here
168新增:uses it: a desktop notification says which (none with AGENT_VM_NOTIFY=0).
169新增:Ports 32768-60999, those the guest hands out to whoever asks for any free
170新增:one, are not forwarded.
171新增:
172新增:Before a VM writes a file this machine runs on its own (.envrc,
173新增:.vscode/tasks.json, .pre-commit-config.yaml, mise.toml...), a dialog asks
174新增:you; the write is refused where none can be shown, and always with
175新增:AGENT_VM_GUARDED_WRITES=deny. ~/.agent-vm/guarded adds paths, one per line,
176新增:and '!path' removes one. Both files are read when a VM starts.
177新增:
162178Customization:
163179 ~/.agent-vm/env Shared env vars / tokens (dotenv-style;
164180 pushed into every VM, loaded in its shells)
@@ -171,6 +187,8 @@ Customization:
171187 matches, * as wildcard)
172188 ~/.agent-vm/setup.sh Per-user setup (runs under zsh during
173189 "agent-vm setup")
190新增: ~/.agent-vm/network What the VMs may reach (above)
191新增: ~/.agent-vm/guarded More files to ask about (above)
174192 <project>/.agent-vm.env Per-project env (agent-vm project-env)
175193 Override the path with AGENT_VM_PROJECT_ENV
176194 ~/.agent-vm/runtime.sh Per-user runtime (runs on every command
@@ -183,5 +201,3 @@ Customization:
183201 names (bash, sh; zsh otherwise).
184202
185203More info: https://www.agent-vm.org/
186删除:EOF
187删除:}
新增internal/cli/info.go+163 −0看文件
@@ -0,0 +1,163 @@
1新增:package cli
2新增:
3新增:import (
4新增: "context"
5新增: "errors"
6新增: "fmt"
7新增: "io"
8新增: "os"
9新增: "path/filepath"
10新增: "strings"
11新增:
12新增: "github.com/sylvinus/agent-vm/internal/env"
13新增: "github.com/sylvinus/agent-vm/internal/gitguard"
14新增: "github.com/sylvinus/agent-vm/internal/mounts"
15新增: "github.com/sylvinus/agent-vm/internal/paths"
16新增: "github.com/sylvinus/agent-vm/internal/state"
17新增: "github.com/sylvinus/agent-vm/internal/version"
18新增: "github.com/sylvinus/agent-vm/internal/vm"
19新增: "github.com/sylvinus/agent-vm/internal/vmname"
20新增:)
21新增:
22新增:// refs are the locations no share may reach (see mounts.Refs).
23新增:func (e *app) refs() []mounts.Ref {
24新增: self := ""
25新增: if exe, err := os.Executable(); err == nil {
26新增: if p, err := filepath.EvalSymlinks(exe); err == nil {
27新增: self = paths.Host(filepath.Dir(p))
28新增: }
29新增: }
30新增: return mounts.Refs(paths.Home(), self, string(e.state), LimaHome(e.state), oldLimaHome())
31新增:}
32新增:
33新增:// entries are the usable entries of ~/.agent-vm/volumes for the project
34新增:// dir, their warnings on warn.
35新增:func (e *app) entries(dir string, warn io.Writer) []mounts.Entry {
36新增: return mounts.Entries(e.state.Path("volumes"), dir, paths.Home(), e.refs(), warn)
37新增:}
38新增:
39新增:// scan is the git scan of the project dir's writable shares (see
40新增:// gitguard.Scan), the volumes read quietly.
41新增:func (e *app) scan(ctx context.Context, dir string) *gitguard.Result {
42新增: shares := gitguard.Shares(dir, mounts.RWDirs(e.entries(dir, io.Discard)))
43新增: return gitguard.Scan(ctx, shares, paths.Home())
44新增:}
45新增:
46新增:// writableGitOptOut: AGENT_VM_UNSAFE_WRITABLE_GIT=1, or --unsafe-writable-git
47新增:// for one command, leaves .git writable. Only the host can ask for it.
48新增:func writableGitOptOut(flag bool) bool {
49新增: return flag || os.Getenv("AGENT_VM_UNSAFE_WRITABLE_GIT") == "1"
50新增:}
51新增:
52新增:// tristate is a key's value: 1, 0, or unknown when the backend could not be
53新增:// asked, never a confident 0.
54新增:func tristate(ok bool, err error) string {
55新增: switch {
56新增: case err != nil:
57新增: return "unknown"
58新增: case ok:
59新增: return "1"
60新增: }
61新增: return "0"
62新增:}
63新增:
64新增:// `info [dir]`: machine-readable state, one key=value per line, the
65新增:// supported way for another tool to ask what agent-vm knows. Booleans are
66新增:// 1/0; what cannot be told is "unknown".
67新增://
68新增:// security_questions: what a start with writable shares of a stopped VM
69新增:// would stop on unless answered yes, comma-separated, or "none": hooks (a
70新增:// hooks folder that cannot be protected), git-config (git config or commands
71新增:// in a share), bare-repo (safe.bareRepository).
72新增:func (e *app) infoCmd(ctx context.Context, args []string) int {
73新增: d := ""
74新增: if len(args) > 0 {
75新增: d = args[0]
76新增: }
77新增: dir, err := vmname.AbsDir(d)
78新增: if err != nil {
79新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
80新增: return 1
81新增: }
82新增: name := vmname.Name(dir)
83新增: w := e.io.Stdout
84新增: fmt.Fprintf(w, "version=%s\n", version.Version)
85新增: fmt.Fprintf(w, "template=%s\n", vmname.Template)
86新增: fmt.Fprintf(w, "state_dir=%s\n", e.state)
87新增: fmt.Fprintf(w, "project_env=%s\n", env.ProjectEnvFile(dir))
88新增: fmt.Fprintf(w, "dir=%s\n", dir)
89新增: fmt.Fprintf(w, "vm_name=%s\n", name)
90新增:
91新增: b, berr := e.readOnlyBackend()
92新增: get := func(n string) (*vm.Instance, error) {
93新增: if berr != nil {
94新增: return nil, berr
95新增: }
96新增: inst, err := b.Get(ctx, n)
97新增: if errors.Is(err, vm.ErrNotFound) {
98新增: return nil, nil
99新增: }
100新增: return inst, err
101新增: }
102新增: base, baseErr := get(vmname.Template)
103新增: _, markErr := os.Stat(e.state.Path(state.BaseVersion))
104新增: fmt.Fprintf(w, "base_exists=%s\n", tristate(base != nil && markErr == nil, baseErr))
105新增: inst, instErr := get(name)
106新增: fmt.Fprintf(w, "vm_exists=%s\n", tristate(inst != nil, instErr))
107新增: fmt.Fprintf(w, "vm_running=%s\n", tristate(inst != nil && inst.Status == vm.Running, instErr))
108新增: stale := "unknown"
109新增: if inst != nil {
110新增: stale = e.staleState(name)
111新增: }
112新增: fmt.Fprintf(w, "vm_stale=%s\n", stale)
113新增: // Lima names the alias after the instance.
114新增: fmt.Fprintf(w, "ssh_host=lima-%s\n", name)
115新增: cfg := "unknown"
116新增: if inst != nil && inst.SSHConfig != "" {
117新增: cfg = inst.SSHConfig
118新增: }
119新增: fmt.Fprintf(w, "ssh_config=%s\n", cfg)
120新增:
121新增: var questions []string
122新增: protected := "1"
123新增: if writableGitOptOut(false) {
124新增: protected = "0"
125新增: } else {
126新增: scan := e.scan(ctx, dir)
127新增: for _, h := range scan.Hooks {
128新增: rel, inRepo, _ := strings.Cut(h, "\t")
129新增: if _, ok := gitguard.HooksName(inRepo); rel != "" && !ok {
130新增: questions = append(questions, "hooks")
131新增: break
132新增: }
133新增: }
134新增: if len(scan.Risks(scan.Names())) > 0 {
135新增: questions = append(questions, "git-config")
136新增: }
137新增: }
138新增: if st := gitguard.BareState(ctx); st == gitguard.BareUnset || st == gitguard.BareOld {
139新增: questions = append(questions, "bare-repo")
140新增: }
141新增: fmt.Fprintf(w, "git_protected=%s\n", protected)
142新增: q := strings.Join(questions, ",")
143新增: if q == "" {
144新增: q = "none"
145新增: }
146新增: fmt.Fprintf(w, "security_questions=%s\n", q)
147新增: return 0
148新增:}
149新增:
150新增:// staleState says whether vm was cloned from an older base than the
151新增:// current one: 1, 0, or unknown with nothing to compare against. A VM with
152新增:// no record but a known base predates the record, which makes it stale.
153新增:func (e *app) staleState(name string) string {
154新增: base, err := os.ReadFile(e.state.Path(state.BaseVersion))
155新增: if err != nil {
156新增: return "unknown"
157新增: }
158新增: mine, err := os.ReadFile(e.state.Marker(state.VersionOf, name))
159新增: if err != nil || strings.TrimRight(string(mine), "\n") != strings.TrimRight(string(base), "\n") {
160新增: return "1"
161新增: }
162新增: return "0"
163新增:}
新增internal/cli/info_test.go+109 −0看文件
@@ -0,0 +1,109 @@
1新增:package cli
2新增:
3新增:import (
4新增: "errors"
5新增: "os"
6新增: "os/exec"
7新增: "path/filepath"
8新增: "strings"
9新增: "testing"
10新增:
11新增: "github.com/sylvinus/agent-vm/internal/paths"
12新增: "github.com/sylvinus/agent-vm/internal/state"
13新增: "github.com/sylvinus/agent-vm/internal/vm"
14新增: "github.com/sylvinus/agent-vm/internal/vm/vmtest"
15新增: "github.com/sylvinus/agent-vm/internal/vmname"
16新增:)
17新增:
18新增:func infoMap(t *testing.T, te *testEnv, args ...string) map[string]string {
19新增: t.Helper()
20新增: if code := te.run(append([]string{"info"}, args...)...); code != 0 {
21新增: t.Fatalf("info: %d %s", code, te.out())
22新增: }
23新增: m := map[string]string{}
24新增: for _, l := range strings.Split(strings.TrimSuffix(te.stdout.String(), "\n"), "\n") {
25新增: k, v, ok := strings.Cut(l, "=")
26新增: if !ok {
27新增: t.Fatalf("not key=value: %q", l)
28新增: }
29新增: m[k] = v
30新增: }
31新增: return m
32新增:}
33新增:
34新增:func TestInfo(t *testing.T) {
35新增: if _, err := exec.LookPath("git"); err != nil {
36新增: t.Skip("no git")
37新增: }
38新增: home := t.TempDir()
39新增: t.Setenv("HOME", home)
40新增: // Go reads the home from USERPROFILE on Windows, not HOME.
41新增: t.Setenv("USERPROFILE", home)
42新增: t.Setenv("GIT_CONFIG_NOSYSTEM", "1")
43新增: os.Unsetenv("GIT_CONFIG_GLOBAL")
44新增: os.Unsetenv("XDG_CONFIG_HOME")
45新增: // On Windows the temporary folder is under LOCALAPPDATA, which no project may be in.
46新增: t.Setenv("APPDATA", "")
47新增: t.Setenv("LOCALAPPDATA", "")
48新增: os.WriteFile(filepath.Join(home, ".gitconfig"), []byte("[safe]\n\tbareRepository = explicit\n"), 0o644)
49新增: // Host-spelled, as AbsDir spells info's folders.
50新增: proj := paths.Host(filepath.Join(home, "proj"))
51新增: os.MkdirAll(proj, 0o755)
52新增: t.Chdir(proj)
53新增: t.Setenv("PWD", proj)
54新增: name := vmname.Name(proj)
55新增: t.Setenv("AGENT_VM_UNSAFE_WRITABLE_GIT", "")
56新增:
57新增: te := newTestEnv(t, vmtest.New())
58新增: m := infoMap(t, te)
59新增: for k, want := range map[string]string{
60新增: "template": "base", "dir": proj, "vm_name": name, "project_env": proj + "/.agent-vm.env",
61新增: "base_exists": "0", "vm_exists": "0", "vm_running": "0", "vm_stale": "unknown", "ssh_host": "lima-" + name,
62新增: "ssh_config": "unknown", "git_protected": "1", "security_questions": "none", "state_dir": string(te.state),
63新增: } {
64新增: if m[k] != want {
65新增: t.Errorf("no VM: %s=%q, want %q", k, m[k], want)
66新增: }
67新增: }
68新增:
69新增: // The base, usable once its marker is there; the VM running, from an
70新增: // older base.
71新增: te.fake.VMs[vmname.Template] = &vm.Instance{Name: vmname.Template, Status: vm.Stopped}
72新增: te.fake.VMs[name] = &vm.Instance{Name: name, Status: vm.Running, SSHConfig: "/x/ssh.config"}
73新增: if infoMap(t, te)["base_exists"] != "0" {
74新增: t.Error("a base without its marker counted")
75新增: }
76新增: os.WriteFile(te.state.Path(state.BaseVersion), []byte("2\n"), 0o644)
77新增: os.WriteFile(te.state.Marker(state.VersionOf, name), []byte("1\n"), 0o644)
78新增: m = infoMap(t, te)
79新增: if m["base_exists"] != "1" || m["vm_exists"] != "1" || m["vm_running"] != "1" || m["vm_stale"] != "1" || m["ssh_config"] != "/x/ssh.config" {
80新增: t.Errorf("with VMs: %v", m)
81新增: }
82新增: os.WriteFile(te.state.Marker(state.VersionOf, name), []byte("2\n"), 0o644)
83新增: if infoMap(t, te)["vm_stale"] != "0" {
84新增: t.Error("an up to date VM said stale")
85新增: }
86新增:
87新增: // What a start would ask.
88新增: exec.Command("git", "-C", proj, "init", "-q").Run()
89新增: exec.Command("git", "-C", proj, "config", "core.hooksPath", ".").Run()
90新增: exec.Command("git", "-C", proj, "config", "core.fsmonitor", "./mon.sh").Run()
91新增: os.WriteFile(filepath.Join(home, ".gitconfig"), nil, 0o644)
92新增: if q := infoMap(t, te)["security_questions"]; q != "hooks,git-config,bare-repo" {
93新增: t.Errorf("questions: %q", q)
94新增: }
95新增: t.Setenv("AGENT_VM_UNSAFE_WRITABLE_GIT", "1")
96新增: if m := infoMap(t, te); m["git_protected"] != "0" || m["security_questions"] != "bare-repo" {
97新增: t.Errorf("opted out: %v", m)
98新增: }
99新增:
100新增: // A backend that cannot be asked: unknown, never a confident 0.
101新增: te.fake.Err = errors.New("broken")
102新增: m = infoMap(t, te)
103新增: if m["base_exists"] != "unknown" || m["vm_exists"] != "unknown" || m["vm_running"] != "unknown" {
104新增: t.Errorf("failing backend: %v", m)
105新增: }
106新增: if te.run("info", "/no/such/dir") != 1 || !strings.Contains(te.out(), "no such directory") {
107新增: t.Errorf("missing dir: %s", te.out())
108新增: }
109新增:}
新增internal/cli/install.go+324 −0看文件
@@ -0,0 +1,324 @@
1新增:package cli
2新增:
3新增:import (
4新增: "bytes"
5新增: "context"
6新增: "crypto/sha256"
7新增: "errors"
8新增: "fmt"
9新增: "io"
10新增: "io/fs"
11新增: "os"
12新增: "path/filepath"
13新增: "regexp"
14新增: "runtime"
15新增: "strings"
16新增: "syscall"
17新增:
18新增: "github.com/sylvinus/agent-vm/internal/paths"
19新增: "github.com/sylvinus/agent-vm/internal/state"
20新增: "github.com/sylvinus/agent-vm/internal/version"
21新增: "github.com/sylvinus/agent-vm/internal/vmname"
22新增:)
23新增:
24新增:// `install` puts agent-vm on the PATH: a link to this executable in
25新增:// AGENT_VM_BIN_DIR (default ~/.local/bin), or a copy where links cannot be
26新增:// made (Windows without the symlink privilege). Safe to re-run.
27新增:
28新增:// binName is the file install makes.
29新增:func binName() string {
30新增: if runtime.GOOS == "windows" {
31新增: return "agent-vm.exe"
32新增: }
33新增: return "agent-vm"
34新增:}
35新增:
36新增:// binLink is where install puts agent-vm: in AGENT_VM_BIN_DIR, made
37新增:// absolute, or ~/.local/bin. An error without a home folder to put it in.
38新增:func binLink() (string, error) {
39新增: dir := os.Getenv("AGENT_VM_BIN_DIR")
40新增: if dir != "" {
41新增: abs, err := filepath.Abs(dir)
42新增: if err != nil {
43新增: return "", err
44新增: }
45新增: return filepath.Join(abs, binName()), nil
46新增: }
47新增: home, err := os.UserHomeDir()
48新增: if err != nil || home == "" {
49新增: return "", errors.New("cannot find your home folder: set AGENT_VM_BIN_DIR to the folder to install in")
50新增: }
51新增: return filepath.Join(home, ".local", "bin", binName()), nil
52新增:}
53新增:
54新增:// self is this executable, links resolved.
55新增:func self() (string, error) {
56新增: exe, err := os.Executable()
57新增: if err != nil {
58新增: return "", err
59新增: }
60新增: return filepath.EvalSymlinks(exe)
61新增:}
62新增:
63新增:// ours reports whether link is what install puts there for exe: a link to
64新增:// it, or a copy of it.
65新增:func ours(link, exe string) bool {
66新增: if t, err := os.Readlink(link); err == nil {
67新增: return t == exe
68新增: }
69新增: return sameContent(link, exe)
70新增:}
71新增:
72新增:// sameContent reports whether the files a and b hold the same bytes, read
73新增:// in blocks: they are executables of tens of megabytes.
74新增:func sameContent(a, b string) bool {
75新增: fa, err := os.Open(a)
76新增: if err != nil {
77新增: return false
78新增: }
79新增: defer fa.Close()
80新增: fb, err := os.Open(b)
81新增: if err != nil {
82新增: return false
83新增: }
84新增: defer fb.Close()
85新增: sa, erra := fa.Stat()
86新增: sb, errb := fb.Stat()
87新增: if erra != nil || errb != nil || !sa.Mode().IsRegular() || !sb.Mode().IsRegular() || sa.Size() != sb.Size() {
88新增: return false
89新增: }
90新增: eof := func(err error) bool { return err == io.EOF || err == io.ErrUnexpectedEOF }
91新增: ba, bb := make([]byte, 1<<16), make([]byte, 1<<16)
92新增: for {
93新增: na, erra := io.ReadFull(fa, ba)
94新增: nb, errb := io.ReadFull(fb, bb)
95新增: if na != nb || !bytes.Equal(ba[:na], bb[:nb]) {
96新增: return false
97新增: }
98新增: if erra != nil || errb != nil {
99新增: return eof(erra) && eof(errb)
100新增: }
101新增: }
102新增:}
103新增:
104新增:// installedCopy records the hash of the copy install made, so the next one
105新增:// recognises it once agent-vm itself was updated.
106新增:const installedCopy = "installed-copy.sha256"
107新增:
108新增:func sha256Of(p string) string {
109新增: f, err := os.Open(p)
110新增: if err != nil {
111新增: return ""
112新增: }
113新增: defer f.Close()
114新增: h := sha256.New()
115新增: if _, err := io.Copy(h, f); err != nil {
116新增: return ""
117新增: }
118新增: return fmt.Sprintf("%x", h.Sum(nil))
119新增:}
120新增:
121新增:// earlier reports whether link is what an earlier install made: 0.2's link
122新增:// to its agent-vm.sh, a link to an agent-vm that is gone (a clone or a
123新增:// version since removed), or a copy install recorded.
124新增:func (e *app) earlier(link string) bool {
125新增: if t, err := os.Readlink(link); err == nil {
126新增: if filepath.Base(t) == "agent-vm.sh" {
127新增: return true
128新增: }
129新增: _, err := os.Stat(link)
130新增: return errors.Is(err, fs.ErrNotExist) && (filepath.Base(t) == "agent-vm" || filepath.Base(t) == "agent-vm.exe")
131新增: }
132新增: h := sha256Of(link)
133新增: return h != "" && h == strings.TrimSpace(e.state.Read(installedCopy))
134新增:}
135新增:
136新增:var rcSourcesRe = regexp.MustCompile(`(?m)^[^#\n]*agent-vm\.sh`)
137新增:
138新增:// onPath reports whether dir is on PATH, compared as the file system does
139新增:// (C:\x and c:/x/ are one folder on Windows).
140新增:func onPath(dir string) bool {
141新增: norm := func(p string) string { return strings.TrimSuffix(paths.Host(p), "/") }
142新增: for _, p := range filepath.SplitList(os.Getenv("PATH")) {
143新增: if paths.Equal(norm(p), norm(dir)) {
144新增: return true
145新增: }
146新增: }
147新增: return false
148新增:}
149新增:
150新增:// rcSourcesUs: an uncommented line of a usual rc file names agent-vm.sh, as
151新增:// an install from before 0.2.0 added.
152新增:func rcSourcesUs() bool {
153新增: home, err := os.UserHomeDir()
154新增: if err != nil || home == "" {
155新增: return false
156新增: }
157新增: for _, f := range []string{".zshrc", ".bashrc", ".bash_profile", ".profile", ".zshenv"} {
158新增: if b, err := os.ReadFile(filepath.Join(home, f)); err == nil && rcSourcesRe.Match(b) {
159新增: return true
160新增: }
161新增: }
162新增: return false
163新增:}
164新增:
165新增:func (e *app) installCmd(ctx context.Context, args []string) int {
166新增: if len(args) > 0 {
167新增: fmt.Fprintln(e.io.Stderr, "Usage: agent-vm install")
168新增: return 2
169新增: }
170新增: w := e.io.Stdout
171新增: exe, err := self()
172新增: if err != nil {
173新增: fmt.Fprintf(e.io.Stderr, "Error: cannot find this executable: %v\n", err)
174新增: return 1
175新增: }
176新增: link, err := binLink()
177新增: if err != nil {
178新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
179新增: return 1
180新增: }
181新增: dir := filepath.Dir(link)
182新增: if err := os.MkdirAll(dir, 0o755); err != nil {
183新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
184新增: return 1
185新增: }
186新增: _, lerr := os.Lstat(link)
187新增: isOurs := lerr == nil && ours(link, exe)
188新增: if lerr == nil && !isOurs && e.earlier(link) {
189新增: if err := os.Remove(link); err != nil {
190新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
191新增: return 1
192新增: }
193新增: fmt.Fprintf(w, "Replacing %s, from an earlier install\n", link)
194新增: lerr = os.ErrNotExist
195新增: }
196新增: var serr error
197新增: if lerr != nil {
198新增: serr = symlink(exe, link)
199新增: }
200新增: switch {
201新增: case isOurs:
202新增: fmt.Fprintf(w, "agent-vm is already linked at %s\n", link)
203新增: case lerr == nil:
204新增: fmt.Fprintf(e.io.Stderr, "Error: %s already exists and is not a link to %s.\n Move it aside, or set AGENT_VM_BIN_DIR to another directory.\n", link, exe)
205新增: return 1
206新增: case serr == nil:
207新增: fmt.Fprintf(w, "Linked %s -> %s\n", link, exe)
208新增: case !symlinkUnsupported(serr):
209新增: fmt.Fprintf(e.io.Stderr, "Error: could not link %s to %s: %v\n", link, exe, serr)
210新增: return 1
211新增: default:
212新增: if err := copyFile(exe, link); err != nil {
213新增: fmt.Fprintf(e.io.Stderr, "Error: could not copy %s to %s: %v\n", exe, link, err)
214新增: return 1
215新增: }
216新增: if err := e.state.Write(installedCopy, []byte(sha256Of(link)+"\n")); err != nil {
217新增: fmt.Fprintf(e.io.Stderr, "Warning: %v: the next install will not recognise this copy.\n", err)
218新增: }
219新增: fmt.Fprintf(w, "Installed %s, a copy of %s (links are not allowed here: %v)\n", link, exe, serr)
220新增: }
221新增: if !onPath(dir) {
222新增: if paths.Windows() {
223新增: fmt.Fprintf(w, "%s is not on your PATH. Add it from PowerShell, then open a new terminal:\n [Environment]::SetEnvironmentVariable('Path', '%s;' + [Environment]::GetEnvironmentVariable('Path', 'User'), 'User')\n",
224新增: dir, strings.ReplaceAll(dir, "'", "''"))
225新增: } else {
226新增: fmt.Fprintf(w, "%s is not on your PATH. Add this line to your shell rc:\n export PATH=\"%s:$PATH\"\n", dir, dir)
227新增: }
228新增: }
229新增: if rcSourcesUs() {
230新增: fmt.Fprintln(w, "Your shell rc still sources agent-vm.sh, which this agent-vm replaces: remove that line.")
231新增: }
232新增: fmt.Fprintf(w, "\nagent-vm %s installed.\n", version.Version)
233新增: // Looking only: installing must not move 0.2's VMs, which stops running ones.
234新增: if b, err := e.readOnlyBackend(); err == nil {
235新增: if base, err := b.Get(ctx, vmname.Template); err == nil && base != nil {
236新增: if _, err := os.Stat(e.state.Path(state.BaseVersion)); err == nil {
237新增: fmt.Fprintln(w, "Next: cd your-project && agent-vm claude # or opencode, codex, vibe, pi")
238新增: return 0
239新增: }
240新增: }
241新增: }
242新增: if e.ui.CanAsk() && e.ui.AskYN("Build the base VM now with 'agent-vm setup'? It takes a few minutes.", true) {
243新增: fmt.Fprintln(w)
244新增: return e.setupCmd(ctx, nil)
245新增: }
246新增: fmt.Fprintln(w, "Next:\n agent-vm setup # build the base VM, once")
247新增: return 0
248新增:}
249新增:
250新增:// symlink makes a link; a variable for the tests, on machines that allow
251新增:// them.
252新增:var symlink = os.Symlink
253新增:
254新增:// symlinkUnsupported reports whether err says that links cannot be made
255新增:// here (Windows without the privilege, a file system without them), where a
256新增:// copy does the work, as opposed to a failure a copy would meet too (a
257新增:// read-only folder, a full disk).
258新增:func symlinkUnsupported(err error) bool {
259新增: const errPrivilegeNotHeld = syscall.Errno(1314) // Windows
260新增: return errors.Is(err, errors.ErrUnsupported) || errors.Is(err, syscall.EPERM) || errors.Is(err, errPrivilegeNotHeld)
261新增:}
262新增:
263新增:// copyFile copies src to dst through a temporary file in dst's folder,
264新增:// renamed once complete: a copy that fails half way leaves nothing behind,
265新增:// and dst is never a truncated executable.
266新增:func copyFile(src, dst string) error {
267新增: in, err := os.Open(src)
268新增: if err != nil {
269新增: return err
270新增: }
271新增: defer in.Close()
272新增: out, err := os.CreateTemp(filepath.Dir(dst), ".agent-vm-install-*")
273新增: if err != nil {
274新增: return err
275新增: }
276新增: _, err = io.Copy(out, in)
277新增: if err == nil {
278新增: err = out.Chmod(0o755)
279新增: }
280新增: if cerr := out.Close(); err == nil {
281新增: err = cerr
282新增: }
283新增: if err == nil {
284新增: err = os.Rename(out.Name(), dst)
285新增: }
286新增: if err != nil {
287新增: os.Remove(out.Name())
288新增: }
289新增: return err
290新增:}
291新增:
292新增:// `uninstall` removes what install made, and nothing else: the VMs,
293新增:// ~/.agent-vm and the executable itself stay.
294新增:func (e *app) uninstallCmd(args []string) int {
295新增: if len(args) > 0 {
296新增: fmt.Fprintln(e.io.Stderr, "Usage: agent-vm uninstall")
297新增: return 2
298新增: }
299新增: w := e.io.Stdout
300新增: link, err := binLink()
301新增: if err != nil {
302新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
303新增: return 1
304新增: }
305新增: exe, _ := self()
306新增: _, lerr := os.Lstat(link)
307新增: switch {
308新增: case lerr == nil && (exe != "" && ours(link, exe) || e.earlier(link)):
309新增: if err := os.Remove(link); err != nil {
310新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
311新增: return 1
312新增: }
313新增: fmt.Fprintf(w, "Removed %s\n", link)
314新增: case lerr == nil:
315新增: fmt.Fprintf(w, "%s is not a link to this agent-vm: left alone.\n", link)
316新增: default:
317新增: fmt.Fprintf(w, "No link to remove at %s\n", link)
318新增: }
319新增: if rcSourcesUs() {
320新增: fmt.Fprintln(w, "Your shell rc still sources agent-vm.sh: remove that line to drop the shell function.")
321新增: }
322新增: fmt.Fprintf(w, "Left as they are: the VMs ('agent-vm destroy-all' deletes them, run it first), ~/.agent-vm, and agent-vm itself at %s.\n", exe)
323新增: return 0
324新增:}
新增internal/cli/install_test.go+100 −0看文件
@@ -0,0 +1,100 @@
1新增:package cli
2新增:
3新增:import (
4新增: "os"
5新增: "path/filepath"
6新增: "strings"
7新增: "testing"
8新增:
9新增: "github.com/sylvinus/agent-vm/internal/paths"
10新增: "github.com/sylvinus/agent-vm/internal/vm/vmtest"
11新增:)
12新增:
13新增:func TestInstall(t *testing.T) {
14新增: home := t.TempDir()
15新增: t.Setenv("HOME", home)
16新增: // Go reads the home from USERPROFILE on Windows, not HOME.
17新增: t.Setenv("USERPROFILE", home)
18新增: bin := filepath.Join(t.TempDir(), "bin")
19新增: t.Setenv("AGENT_VM_BIN_DIR", bin)
20新增: te := newTestEnv(t, vmtest.New())
21新增: exe, _ := self()
22新增: link, err := binLink()
23新增: if err != nil {
24新增: t.Fatal(err)
25新增: }
26新增:
27新增: if te.run("install") != 0 || !strings.Contains(te.out(), "Linked "+link+" -> "+exe) || !strings.Contains(te.out(), "is not on your PATH") {
28新增: t.Fatalf("install: %s", te.out())
29新增: }
30新增: if !strings.Contains(te.out(), "agent-vm setup # build the base VM, once") {
31新增: t.Errorf("next step: %s", te.out())
32新增: }
33新增: if t2, _ := os.Readlink(link); t2 != exe {
34新增: t.Errorf("link: %q", t2)
35新增: }
36新增: if te.run("install") != 0 || !strings.Contains(te.out(), "already linked") {
37新增: t.Errorf("again: %s", te.out())
38新增: }
39新增: // On Windows: the hint is PowerShell's, and PATH is compared as the
40新增: // file system does.
41新增: old := paths.Windows
42新增: paths.Windows = func() bool { return true }
43新增: if te.run("install"); !strings.Contains(te.out(), "Add it from PowerShell") || !strings.Contains(te.out(), "SetEnvironmentVariable('Path', '"+bin+";'") {
44新增: t.Errorf("Windows hint: %s", te.out())
45新增: }
46新增: t.Setenv("PATH", strings.ToUpper(bin)+"/"+string(os.PathListSeparator)+os.Getenv("PATH"))
47新增: if te.run("install"); strings.Contains(te.out(), "not on your PATH") {
48新增: t.Errorf("on PATH, as Windows compares it: %s", te.out())
49新增: }
50新增: paths.Windows = old
51新增: if te.run("install", "x") != 2 {
52新增: t.Error("an argument")
53新增: }
54新增: os.WriteFile(filepath.Join(home, ".zshrc"), []byte("source ~/agent-vm/agent-vm.sh\n"), 0o644)
55新增: if te.run("uninstall") != 0 || !strings.Contains(te.out(), "Removed "+link) || !strings.Contains(te.out(), "still sources agent-vm.sh") {
56新增: t.Errorf("uninstall: %s", te.out())
57新增: }
58新增: if _, err := os.Lstat(link); err == nil {
59新增: t.Error("not removed")
60新增: }
61新增: // Someone else's file: never replaced, never removed.
62新增: os.WriteFile(link, []byte("#!/bin/sh\n"), 0o755)
63新增: if te.run("install") != 1 || !strings.Contains(te.out(), "already exists and is not a link to") {
64新增: t.Errorf("foreign file, install: %s", te.out())
65新增: }
66新增: if te.run("uninstall") != 0 || !strings.Contains(te.out(), "is not a link to this agent-vm: left alone.") {
67新增: t.Errorf("foreign file, uninstall: %s", te.out())
68新增: }
69新增: if b, _ := os.ReadFile(link); string(b) != "#!/bin/sh\n" {
70新增: t.Error("the foreign file changed")
71新增: }
72新增: // A dangling link of someone else's: refused, left.
73新增: os.Remove(link)
74新增: os.Symlink(filepath.Join(home, "gone"), link)
75新增: if te.run("install") != 1 || !strings.Contains(te.out(), "already exists and is not a link to") {
76新增: t.Errorf("dangling link: %s", te.out())
77新增: }
78新增: // 0.2's link to its agent-vm.sh: replaced.
79新增: os.Remove(link)
80新增: os.Symlink(filepath.Join(home, "agent-vm", "agent-vm.sh"), link)
81新增: if te.run("install") != 0 || !strings.Contains(te.out(), "Replacing "+link) {
82新增: t.Errorf("0.2's link: %s", te.out())
83新增: }
84新增: if t2, _ := os.Readlink(link); t2 != exe {
85新增: t.Errorf("link after 0.2's: %q", t2)
86新增: }
87新增: // A copy an earlier install recorded, since updated: replaced, and
88新增: // removed by uninstall.
89新增: os.Remove(link)
90新增: os.WriteFile(link, []byte("old agent-vm"), 0o755)
91新增: os.MkdirAll(string(te.state), 0o755)
92新增: os.WriteFile(te.state.Path(installedCopy), []byte(sha256Of(link)+"\n"), 0o644)
93新增: if te.run("uninstall") != 0 || !strings.Contains(te.out(), "Removed "+link) {
94新增: t.Errorf("recorded copy, uninstall: %s", te.out())
95新增: }
96新增: os.WriteFile(link, []byte("old agent-vm"), 0o755)
97新增: if te.run("install") != 0 || !strings.Contains(te.out(), "Replacing "+link) {
98新增: t.Errorf("recorded copy, install: %s", te.out())
99新增: }
100新增:}
新增internal/cli/licenses.go+18 −0看文件
@@ -0,0 +1,18 @@
1新增:package cli
2新增:
3新增:import (
4新增: "fmt"
5新增:
6新增: agentvm "github.com/sylvinus/agent-vm"
7新增:)
8新增:
9新增:// `licenses`: agent-vm's license, the notice about what is built into it,
10新增:// and the licenses of those parts, as embedded at build time.
11新增:func licensesCmd(args []string, io IO) int {
12新增: if len(args) > 0 {
13新增: fmt.Fprintln(io.Stderr, "Usage: agent-vm licenses")
14新增: return 2
15新增: }
16新增: fmt.Fprint(io.Stdout, agentvm.License, "\n", agentvm.Notice, "\n", agentvm.ThirdPartyLicenses)
17新增: return 0
18新增:}
新增internal/cli/licenses_test.go+40 −0看文件
@@ -0,0 +1,40 @@
1新增:package cli
2新增:
3新增:import (
4新增: "strings"
5新增: "testing"
6新增:
7新增: "github.com/sylvinus/agent-vm/internal/vm/vmtest"
8新增:)
9新增:
10新增:func TestLicenses(t *testing.T) {
11新增: te := newTestEnv(t, vmtest.New())
12新增: if code := te.run("licenses"); code != 0 || te.stderr.Len() != 0 {
13新增: t.Fatalf("licenses: %d\n%s", code, te.out())
14新增: }
15新增: out := te.stdout.String()
16新增: // agent-vm's own license, the notice, and each project built into the
17新增: // binary: Apache-2.0 (with Lima's NOTICE), BSD-2 and BSD-3 ones.
18新增: for _, want := range []string{
19新增: "MIT License", "Copyright (c) 2026 Sylvain Zimmer",
20新增: "third_party/ holds", "section 4(b)",
21新增: "github.com/lima-vm/lima/v2 ./third_party/lima: LICENSE",
22新增: "github.com/lima-vm/lima/v2 ./third_party/lima: NOTICE",
23新增: "github.com/lima-vm/sshocker ./third_party/sshocker: LICENSE",
24新增: "github.com/containers/gvisor-tap-vsock ./third_party/gvisor-tap-vsock: LICENSE",
25新增: "github.com/pkg/sftp ./third_party/sftp: LICENSE",
26新增: "golang.org/x/sys ",
27新增: "Go standard library",
28新增: "Apache License",
29新增: } {
30新增: if !strings.Contains(out, want) {
31新增: t.Errorf("the output lacks %q", want)
32新增: }
33新增: }
34新增: if te.run("licenses", "x") != 2 || !strings.Contains(te.out(), "Usage: agent-vm licenses") {
35新增: t.Errorf("an argument: %s", te.out())
36新增: }
37新增: if te.run("--readonly", "licenses") != exitUsage {
38新增: t.Errorf("a VM option: %s", te.out())
39新增: }
40新增:}
新增internal/cli/lock.go+48 −0看文件
@@ -0,0 +1,48 @@
1新增:package cli
2新增:
3新增:import (
4新增: "context"
5新增: "fmt"
6新增: "os"
7新增: "path/filepath"
8新增: "time"
9新增:)
10新增:
11新增:// lockVM takes the lock of name, which serialises what changes that VM
12新增:// between agent-vm runs: two runs in one folder would otherwise clean up,
13新增:// clone and configure the same VM at once. It waits, saying so, until the
14新增:// holder is done or ctx ends. The lock is a file in the state folder's
15新增:// locks/, kept for the next run: a crashed holder releases it with its
16新增:// process.
17新增:func (e *app) lockVM(ctx context.Context, name string) (unlock func(), err error) {
18新增: dir := e.state.Path("locks")
19新增: if err := os.MkdirAll(dir, 0o755); err != nil {
20新增: return nil, err
21新增: }
22新增: f, err := os.OpenFile(filepath.Join(dir, name), os.O_CREATE|os.O_RDWR, 0o644)
23新增: if err != nil {
24新增: return nil, err
25新增: }
26新增: told := false
27新增: for {
28新增: ok, err := tryLock(f)
29新增: if err != nil {
30新增: f.Close()
31新增: return nil, err
32新增: }
33新增: if ok {
34新增: // Closing the file releases the lock.
35新增: return func() { f.Close() }, nil
36新增: }
37新增: if !told {
38新增: fmt.Fprintf(e.io.Stderr, "Waiting for another agent-vm that is working on '%s'...\n", name)
39新增: told = true
40新增: }
41新增: select {
42新增: case <-ctx.Done():
43新增: f.Close()
44新增: return nil, ctx.Err()
45新增: case <-time.After(200 * time.Millisecond):
46新增: }
47新增: }
48新增:}
新增internal/cli/lock_unix.go+23 −0看文件
@@ -0,0 +1,23 @@
1新增://go:build !windows
2新增:
3新增:package cli
4新增:
5新增:import (
6新增: "errors"
7新增: "os"
8新增:
9新增: "golang.org/x/sys/unix"
10新增:)
11新增:
12新增:// tryLock takes an exclusive lock on f without waiting: false when another
13新增:// open file holds it. The lock goes with the file, or the process.
14新增:func tryLock(f *os.File) (bool, error) {
15新增: err := unix.Flock(int(f.Fd()), unix.LOCK_EX|unix.LOCK_NB)
16新增: switch {
17新增: case err == nil:
18新增: return true, nil
19新增: case errors.Is(err, unix.EWOULDBLOCK), errors.Is(err, unix.EINTR):
20新增: return false, nil
21新增: }
22新增: return false, err
23新增:}
新增internal/cli/lock_windows.go+22 −0看文件
@@ -0,0 +1,22 @@
1新增:package cli
2新增:
3新增:import (
4新增: "errors"
5新增: "os"
6新增:
7新增: "golang.org/x/sys/windows"
8新增:)
9新增:
10新增:// tryLock takes an exclusive lock on f without waiting: false when another
11新增:// open file holds it. The lock goes with the file, or the process.
12新增:func tryLock(f *os.File) (bool, error) {
13新增: ol := new(windows.Overlapped)
14新增: err := windows.LockFileEx(windows.Handle(f.Fd()), windows.LOCKFILE_EXCLUSIVE_LOCK|windows.LOCKFILE_FAIL_IMMEDIATELY, 0, 1, 0, ol)
15新增: switch {
16新增: case err == nil:
17新增: return true, nil
18新增: case errors.Is(err, windows.ERROR_LOCK_VIOLATION):
19新增: return false, nil
20新增: }
21新增: return false, err
22新增:}
新增internal/cli/main_test.go+26 −0看文件
@@ -0,0 +1,26 @@
1新增:package cli
2新增:
3新增:import (
4新增: "os"
5新增: "runtime"
6新增: "testing"
7新增:
8新增: limaversion "github.com/lima-vm/lima/v2/pkg/version"
9新增:
10新增: "github.com/sylvinus/agent-vm/internal/limaembed"
11新增:)
12新增:
13新增:// Lima starts its hostagent as this executable: the test binary, here.
14新增:// It is not stamped with Lima's version, as the Makefile's builds are.
15新增:func TestMain(m *testing.M) {
16新增: limaversion.Version = "v2.3.0-test"
17新增: // macOS's TMPDIR (/var/folders/...) is too long for Lima's socket
18新增: // paths (104 bytes) and cuts every VM name; real homes are short.
19新增: if runtime.GOOS == "darwin" {
20新增: os.Setenv("TMPDIR", "/tmp")
21新增: }
22新增: if limaembed.Run(os.Args[1:]) {
23新增: return
24新增: }
25新增: os.Exit(m.Run())
26新增:}
新增internal/cli/migrate_test.go+129 −0看文件
@@ -0,0 +1,129 @@
1新增:package cli
2新增:
3新增:import (
4新增: "context"
5新增: "io"
6新增: "os"
7新增: "path/filepath"
8新增: "strings"
9新增: "testing"
10新增:
11新增: "github.com/sylvinus/agent-vm/internal/state"
12新增: "github.com/sylvinus/agent-vm/internal/vm/vmtest"
13新增:)
14新增:
15新增:// agent-vm takes every VM in its Lima home as its own (list, rm,
16新增:// destroy-all): never the user's own Lima home, however spelled.
17新增:func TestOwnLimaHome(t *testing.T) {
18新增: home := t.TempDir()
19新增: t.Setenv("HOME", home)
20新增: // Go reads the home from USERPROFILE on Windows, not HOME.
21新增: t.Setenv("USERPROFILE", home)
22新增: lima := t.TempDir()
23新增: t.Setenv("LIMA_HOME", lima)
24新增: t.Setenv("AGENT_VM_LIMA_HOME", lima+"/")
25新增: e, err := newApp(IO{Stdin: strings.NewReader(""), Stdout: io.Discard, Stderr: io.Discard})
26新增: if err != nil {
27新增: t.Fatal(err)
28新增: }
29新增: if _, err := e.backend(); err == nil || !strings.Contains(err.Error(), "your own Lima's home") {
30新增: t.Errorf("own home: %v", err)
31新增: }
32新增: // The LIMA_HOME agent-vm sets for Lima is not the user's: a second
33新增: // command in the same process (setup, then a start) is not refused.
34新增: os.Unsetenv("LIMA_HOME")
35新增: t.Setenv("AGENT_VM_LIMA_HOME", "")
36新增: for i := range 2 {
37新增: e, _ := newApp(IO{Stdin: strings.NewReader(""), Stdout: io.Discard, Stderr: io.Discard})
38新增: if _, err := e.backend(); err != nil {
39新增: t.Errorf("command %d: %v", i+1, err)
40新增: }
41新增: }
42新增:}
43新增:
44新增:// doctor, info and list only look: they never move 0.2's VMs, which stops
45新增:// running ones (an editor calls info unasked); a command that changes VMs
46新增:// does.
47新增:func TestMigrateNotFromReaders(t *testing.T) {
48新增: home := t.TempDir()
49新增: t.Setenv("HOME", home)
50新增: // Go reads the home from USERPROFILE on Windows, not HOME.
51新增: t.Setenv("USERPROFILE", home)
52新增: for _, args := range [][]string{{"doctor"}, {"info"}, {"list"}, {"stop", "x"}} {
53新增: te := newTestEnv(t, vmtest.New())
54新增: moved := false
55新增: te.migrate = func() { moved = true }
56新增: te.run(args...)
57新增: if want := args[0] == "stop"; moved != want {
58新增: t.Errorf("%s: moved %v", args[0], moved)
59新增: }
60新增: }
61新增:}
62新增:
63新增:func TestMigrateOld(t *testing.T) {
64新增: old := t.TempDir()
65新增: now := filepath.Join(t.TempDir(), "lima")
66新增: // Already at the new place, under its new name: the move fails, and says
67新增: // so.
68新增: os.MkdirAll(filepath.Join(now, "p-12345678"), 0o755)
69新增: os.MkdirAll(filepath.Join(old, "agent-vm-p-12345678"), 0o755)
70新增: os.WriteFile(filepath.Join(old, "agent-vm-p-12345678", "lima.yaml"), []byte("{"), 0o644)
71新增: os.MkdirAll(filepath.Join(old, "theirs"), 0o755)
72新增: os.WriteFile(filepath.Join(old, "theirs", "lima.yaml"), []byte("{"), 0o644)
73新增:
74新增: te := newTestEnv(t, vmtest.New(), "n\n")
75新增: os.MkdirAll(string(te.state), 0o755)
76新增: os.WriteFile(te.state.Marker(state.BuiltByOf, "agent-vm-p-12345678"), []byte("0.2.1\n"), 0o644)
77新增: te.migrateOld(context.Background(), old, now)
78新增: if out := te.out(); !strings.Contains(out, " agent-vm-p-12345678, as p-12345678\n") || strings.Contains(out, "theirs") || !strings.Contains(out, "Not moved") {
79新增: t.Errorf("declined:\n%s", out)
80新增: }
81新增: if _, err := os.Stat(te.state.Path(migratedMarker)); err == nil {
82新增: t.Error("declined, and marked as done")
83新增: }
84新增:
85新增: st := te.state
86新增: te = newTestEnv(t, te.fake)
87新增: te.state = st
88新增: te.migrateOld(context.Background(), old, now)
89新增: if out := te.out(); !strings.Contains(out, "Error: could not move agent-vm-p-12345678") {
90新增: t.Errorf("no terminal, failed move:\n%s", out)
91新增: }
92新增: if _, err := os.Stat(te.state.Path(migratedMarker)); err == nil {
93新增: t.Error("a failed move was marked as done")
94新增: }
95新增:
96新增: // Without a terminal it goes ahead; Lima reads a broken config as a
97新增: // broken VM, which moves all the same. Then it is done, once.
98新增: os.RemoveAll(filepath.Join(now, "p-12345678"))
99新增: te.stderr.Reset()
100新增: te.migrateOld(context.Background(), old, now)
101新增: if out := te.out(); !strings.HasSuffix(out, "Done: they keep their shares and settings, under their new names.\n") {
102新增: t.Errorf("no terminal:\n%s", out)
103新增: }
104新增: if _, err := os.Stat(filepath.Join(now, "p-12345678", "lima.yaml")); err != nil {
105新增: t.Error("not moved")
106新增: }
107新增: if te.state.ReadMarker(state.BuiltByOf, "p-12345678") != "0.2.1" {
108新增: t.Error("its markers did not follow")
109新增: }
110新增: if _, err := os.Stat(filepath.Join(old, "theirs", "lima.yaml")); err != nil {
111新增: t.Error("another VM was moved")
112新增: }
113新增: if _, err := os.Stat(te.state.Path(migratedMarker)); err != nil {
114新增: t.Error("not marked as done")
115新增: }
116新增: os.MkdirAll(filepath.Join(old, "agent-vm-q-12345678"), 0o755)
117新增: os.WriteFile(filepath.Join(old, "agent-vm-q-12345678", "lima.yaml"), []byte("{"), 0o644)
118新增: te.stderr.Reset()
119新增: te.migrateOld(context.Background(), old, now)
120新增: if te.out() != "" {
121新增: t.Errorf("after the marker: %q", te.out())
122新增: }
123新增: // Nothing of agent-vm's: nothing said.
124新增: te = newTestEnv(t, te.fake)
125新增: te.migrateOld(context.Background(), t.TempDir(), now)
126新增: if te.out() != "" {
127新增: t.Errorf("nothing to move: %q", te.out())
128新增: }
129新增:}
新增internal/cli/options.go+137 −0看文件
@@ -0,0 +1,137 @@
1新增:package cli
2新增:
3新增:import (
4新增: "fmt"
5新增: "regexp"
6新增: "strconv"
7新增: "strings"
8新增:)
9新增:
10新增:// VMOpts are agent-vm's own options, for the commands that start a VM.
11新增:type VMOpts struct {
12新增: Disk, Memory, CPUs int // 0: not given
13新增: SSHPort int // -1: not given; 0 gives the port back to Lima
14新增: Reset bool
15新增: ReadOnly bool
16新增: Scratch bool
17新增: UnsafeWritableGit bool
18新增: UnsafeNoPrompts bool
19新增: RM bool // --rm: delete the VM after the command
20新增:}
21新增:
22新增:func newVMOpts() VMOpts {
23新增: return VMOpts{SSHPort: -1}
24新增:}
25新增:
26新增:var positiveRe = regexp.MustCompile(`^[1-9][0-9]*$`)
27新增:
28新增:// take reads the option at the start of args, if it is one of agent-vm's,
29新增:// and returns how many words it used: 0 when args[0] is not an option. A
30新增:// value is checked here, so `--disk 10G` is one clear error.
31新增:func (o *VMOpts) take(args []string) (int, error) {
32新增: if len(args) == 0 {
33新增: return 0, nil
34新增: }
35新增: opt, val, n := args[0], "", 0
36新增: switch opt {
37新增: case "--disk", "--memory", "--ram", "--cpus", "--ssh-port":
38新增: if len(args) < 2 {
39新增: return 0, fmt.Errorf("%s needs a value.", opt)
40新增: }
41新增: val, n = args[1], 2
42新增: case "--reset":
43新增: o.Reset = true
44新增: return 1, nil
45新增: case "--readonly":
46新增: o.ReadOnly = true
47新增: return 1, nil
48新增: case "--scratch":
49新增: o.Scratch = true
50新增: return 1, nil
51新增: case "--unsafe-writable-git", "--unsafe-writable-git=1":
52新增: o.UnsafeWritableGit = true
53新增: return 1, nil
54新增: case "--unsafe-disable-security-prompts":
55新增: o.UnsafeNoPrompts = true
56新增: return 1, nil
57新增: case "--rm":
58新增: o.RM = true
59新增: return 1, nil
60新增: default:
61新增: name, v, ok := strings.Cut(opt, "=")
62新增: switch {
63新增: case !ok:
64新增: return 0, nil
65新增: case name == "--disk", name == "--memory", name == "--ram", name == "--cpus", name == "--ssh-port":
66新增: opt, val, n = name, v, 1
67新增: default:
68新增: return 0, nil
69新增: }
70新增: }
71新增: if opt == "--ram" {
72新增: opt = "--memory"
73新增: }
74新增: if opt == "--ssh-port" {
75新增: p, err := strconv.Atoi(val)
76新增: if val != "0" && (!positiveRe.MatchString(val) || err != nil || p < 1024 || p > 65535) {
77新增: return 0, fmt.Errorf("--ssh-port must be 0 or a port from 1024 to 65535 (got: '%s')", val)
78新增: }
79新增: o.SSHPort = p
80新增: return n, nil
81新增: }
82新增: v, err := strconv.Atoi(val)
83新增: if !positiveRe.MatchString(val) || err != nil {
84新增: return 0, fmt.Errorf("%s must be a positive integer (got: '%s')", opt, val)
85新增: }
86新增: switch opt {
87新增: case "--disk":
88新增: o.Disk = v
89新增: case "--memory":
90新增: o.Memory = v
91新增: default:
92新增: o.CPUs = v
93新增: }
94新增: return n, nil
95新增:}
96新增:
97新增:// takeAll reads options from the start of args, and returns the words
98新增:// they used and the rest.
99新增:func (o *VMOpts) takeAll(args []string) (taken, rest []string, err error) {
100新增: for {
101新增: n, err := o.take(args)
102新增: if err != nil {
103新增: return nil, nil, err
104新增: }
105新增: if n == 0 {
106新增: return taken, args, nil
107新增: }
108新增: taken = append(taken, args[:n]...)
109新增: args = args[n:]
110新增: }
111新增:}
112新增:
113新增:// split reads agent-vm's options before a command's own words: from the
114新增:// first other word on, everything belongs to the command, so `run docker run
115新增:// --rm x` keeps its --rm. `--` ends the options, and --tty asks for a
116新增:// terminal.
117新增:func (o *VMOpts) split(args []string) (cmd []string, tty bool, err error) {
118新增: for {
119新增: n, err := o.take(args)
120新增: if err != nil {
121新增: return nil, false, err
122新增: }
123新增: if n > 0 {
124新增: args = args[n:]
125新增: continue
126新增: }
127新增: if len(args) > 0 && args[0] == "--tty" {
128新增: tty = true
129新增: args = args[1:]
130新增: continue
131新增: }
132新增: if len(args) > 0 && args[0] == "--" {
133新增: args = args[1:]
134新增: }
135新增: return args, tty, nil
136新增: }
137新增:}
新增internal/cli/policy.go+83 −0看文件
@@ -0,0 +1,83 @@
1新增:package cli
2新增:
3新增:import (
4新增: "crypto/sha256"
5新增: "encoding/hex"
6新增: "fmt"
7新增: "io"
8新增: "os"
9新增: "slices"
10新增: "strings"
11新增:
12新增: "github.com/sylvinus/agent-vm/internal/guard"
13新增: "github.com/sylvinus/agent-vm/internal/netguard"
14新增: "github.com/sylvinus/agent-vm/internal/state"
15新增:)
16新增:
17新增:// The network and guarded-files policies are read when a VM boots, by its
18新增:// hostagent, and kept until it stops. Starting a VM records what they were
19新增:// (PolicyOf); a later start that finds the VM running says so when they
20新增:// differ now.
21新增:
22新增:// quiet is AGENT_VM_QUIET=1: notices that are not about a risk to the host
23新增:// are not printed.
24新增:func quiet() bool { return os.Getenv("AGENT_VM_QUIET") == "1" }
25新增:
26新增:// policyFingerprint identifies the policies as the hostagent would load
27新增:// them now: the network file's rules and the guarded paths, comments and
28新增:// order not counting, and the two switches in the environment.
29新增:func policyFingerprint(st state.Dir) string {
30新增: var parts []string
31新增: if pol, err := netguard.Load(string(st)); err == nil {
32新增: parts = append(parts, fmt.Sprintf("open=%t", pol.Open))
33新增: for _, r := range pol.Allow {
34新增: parts = append(parts, fmt.Sprintf("allow %v %d", r.Net, r.Port))
35新增: }
36新增: for _, d := range pol.Domains {
37新增: parts = append(parts, "domain "+d)
38新增: }
39新增: } else {
40新增: parts = append(parts, "network: "+err.Error())
41新增: }
42新增: if g, err := guard.Load(string(st), ""); err == nil {
43新增: for p := range g.Paths {
44新增: parts = append(parts, "guard "+p)
45新增: }
46新增: } else {
47新增: parts = append(parts, "guarded: "+err.Error())
48新增: }
49新增: parts = append(parts, fmt.Sprintf("deny=%t", os.Getenv("AGENT_VM_GUARDED_WRITES") == "deny"))
50新增: slices.Sort(parts)
51新增: sum := sha256.Sum256([]byte(strings.Join(parts, "\n")))
52新增: return hex.EncodeToString(sum[:])
53新增:}
54新增:
55新增:// recordPolicy notes the policies the VM was just booted with.
56新增:func (s *start) recordPolicy() {
57新增: if err := s.state.Write(state.PolicyOf+s.name, []byte(policyFingerprint(s.state)+"\n")); err != nil {
58新增: s.warnf("Warning: could not record the network and guarded-files policies VM '%s' booted with: %v", s.name, err)
59新增: }
60新增:}
61新增:
62新增:// notePolicyChange says so when the running VM booted with other policies
63新增:// than the ones in force now. A VM with no record (booted by an agent-vm
64新增:// that kept none) is not said anything about.
65新增:func (s *start) notePolicyChange() {
66新增: booted := s.state.ReadMarker(state.PolicyOf, s.name)
67新增: if booted == "" || booted == policyFingerprint(s.state) {
68新增: return
69新增: }
70新增: s.warnf("Note: VM '%s' booted with other network or guarded-files settings than now (%s, %s, AGENT_VM_UNSAFE_OPEN_NETWORK, AGENT_VM_GUARDED_WRITES). The running VM keeps the old ones: 'agent-vm stop', then run again to apply them.",
71新增: s.name, netguard.FileName, guard.FileName)
72新增:}
73新增:
74新增:// warnDomains says, once per start, that the network file's 'domain' lines
75新增:// are experimental.
76新增:func warnDomains(st state.Dir, w io.Writer) {
77新增: if quiet() {
78新增: return
79新增: }
80新增: if pol, err := netguard.Load(string(st)); err == nil && len(pol.Domains) > 0 {
81新增: fmt.Fprintf(w, "Warning: the 'domain' lines in %s are experimental: do not rely on them alone to confine a VM. AGENT_VM_QUIET=1 hides this.\n", st.Path(netguard.FileName))
82新增: }
83新增:}
新增internal/cli/probe.go+79 −0看文件
@@ -0,0 +1,79 @@
1新增:package cli
2新增:
3新增:import (
4新增: "fmt"
5新增: "io"
6新增: "math/rand/v2"
7新增: "os"
8新增: "path/filepath"
9新增: "strings"
10新增:
11新增: "github.com/sylvinus/agent-vm/internal/paths"
12新增: "github.com/sylvinus/agent-vm/internal/vm"
13新增:)
14新增:
15新增:// probeResult is what the guest answered.
16新增:type probeResult struct {
17新增: writable string // "true", "false", or "lost": the share is not mounted
18新增: runtimeFound bool
19新增: envOK bool
20新增:}
21新增:
22新增:// The guest's side of the probe, its arguments the project's path, the
23新增:// project's env file and runtime script (by their paths in the VM), and the
24新增:// token the host put in the project.
25新增:const probeScript = `
26新增:(umask 077 && rm -f "$HOME/.agent-vm.env" && { cat; [ -z "$2" ] || [ ! -f "$2" ] || awk "{ sub(/\r\$/, \"\"); print }" "$2"; } > "$HOME/.agent-vm.env") && echo env-ok
27新增:[ -z "$3" ] || [ ! -f "$3" ] || echo runtime-found
28新增:[ -z "$4" ] || [ ! -f "$1/$4" ] || echo share-ok
29新增:p="$1/.agent-vm-write-probe.$$"; touch "$p" 2>/dev/null || exit 1; rm -f "$p"`
30新增:
31新增:// probe pushes the env and checks the project share, in one round trip:
32新增:// - writes ~/.agent-vm.env in the VM (mode 600, sourced by its ~/.zshenv):
33新增:// payload, then the project's env, read by the VM, CRs dropped; empty
34新增:// too, so env removed on the host goes;
35新增:// - says whether the project's runtime script is there;
36新增:// - writes into the project, a real write removed at once, not `test -w`:
37新增:// after a mode change the guest's fstab still shows the old one;
38新增:// - "lost" when the share is not mounted (sshfs died, or never mounted),
39新增:// where the VM writes on its own disk: the guest does not see the file
40新增:// put in the project just before. Not for a scratch VM, which shares
41新增:// nothing.
42新增:func (s *start) probe(payload, guestEnv, guestRuntime string) probeResult {
43新增: token := ""
44新增: if !s.opts.Scratch {
45新增: t := fmt.Sprintf(".agent-vm-probe.%d.%d", os.Getpid(), rand.IntN(1e9))
46新增: // Never through something already there.
47新增: if f, err := os.OpenFile(filepath.Join(s.dir, t), os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o644); err == nil {
48新增: f.Close()
49新增: token = t
50新增: defer os.Remove(filepath.Join(s.dir, t))
51新增: }
52新增: }
53新增: in := ""
54新增: if payload != "" {
55新增: in = payload + "\n"
56新增: }
57新增: var out strings.Builder
58新增: b, err := s.backend()
59新增: code := 1
60新增: if err == nil {
61新增: code, err = b.Shell(s.ctx, s.name, vm.ShellOpts{
62新增: Args: []string{"sh", "-c", probeScript, "sh", paths.Guest(s.dir), guestEnv, guestRuntime, token},
63新增: Stdin: strings.NewReader(in), Stdout: &out, Stderr: io.Discard,
64新增: })
65新增: }
66新增: r := probeResult{
67新增: envOK: strings.Contains(out.String(), "env-ok"),
68新增: runtimeFound: strings.Contains(out.String(), "runtime-found"),
69新增: writable: fmt.Sprint(err == nil && code == 0),
70新增: }
71新增: // The guest answered, but without the share.
72新增: if token != "" && r.envOK && !strings.Contains(out.String(), "share-ok") {
73新增: r.writable = "lost"
74新增: }
75新增: if !r.envOK {
76新增: s.warnf("Warning: failed to push the env files into VM '%s'.", s.name)
77新增: }
78新增: return r
79新增:}
新增internal/cli/setup.go+506 −0看文件
@@ -0,0 +1,506 @@
1新增:package cli
2新增:
3新增:import (
4新增: "context"
5新增: "fmt"
6新增: "io"
7新增: "os"
8新增: "path/filepath"
9新增: "strconv"
10新增: "strings"
11新增: "time"
12新增:
13新增: agentvm "github.com/sylvinus/agent-vm"
14新增: "github.com/sylvinus/agent-vm/internal/env"
15新增: "github.com/sylvinus/agent-vm/internal/host"
16新增: "github.com/sylvinus/agent-vm/internal/state"
17新增: "github.com/sylvinus/agent-vm/internal/ui"
18新增: "github.com/sylvinus/agent-vm/internal/version"
19新增: "github.com/sylvinus/agent-vm/internal/vm"
20新增: "github.com/sylvinus/agent-vm/internal/vmname"
21新增:)
22新增:
23新增:const setupUsage = "Usage: agent-vm setup [--disk GB] [--memory GB] [--cpus N] [--preinstall=LIST]"
24新增:
25新增:const setupHelp = `Usage: agent-vm setup [options]
26新增:
27新增:Create a base VM template with dev tools and agents pre-installed. Runs an
28新增:interactive wizard by default; the first prompt offers a "default install"
29新增:(everything except the opt-in Ruby, Rust, Go, Pi, Playwright MCP, code-server
30新增:and its extensions). Answer 'n' for per-component prompts. Pass
31新增:--preinstall=... to skip the wizard and pick a specific subset
32新增:non-interactively. When no terminal can be asked on (no controlling
33新增:terminal, or stderr redirected, as in CI), the wizard is skipped
34新增:automatically and the default set is installed.
35新增:
36新增:Options:
37新增: --disk GB VM disk size (default: 10)
38新增: --memory GB VM memory (default: 3, 4 with code-server in the wizard)
39新增: --cpus N Number of CPUs (default: 1)
40新增: --preinstall=LIST Comma-separated list of tools to preinstall in the base
41新增: VM image (skips the wizard). Anything not listed is
42新增: skipped. Use:
43新增: 'default' for the default set
44新增: (everything except Ruby, Rust, Go, Pi,
45新增: mcp-playwright, code-server, code-*),
46新增: 'all' for everything,
47新增: 'none' for nothing.
48新增: Available names:
49新增: python, node, ruby, rust, golang, docker, chromium,
50新增: gh, claude, opencode, codex, vibe, pi, mcp-chrome,
51新增: mcp-playwright, code-server, code-claude,
52新增: code-codex, code-vibe
53新增: 'code-server' is VS Code in the browser, for
54新增: 'agent-vm code', with GitHub Copilot turned off.
55新增: 'code-claude', 'code-codex' and 'code-vibe' add that
56新增: agent's extension, and code-server with it. Each
57新增: extension brings its own copy of the agent: 'claude',
58新增: 'codex' and 'vibe' are the command-line ones, for
59新增: 'agent-vm claude' and the others.
60新增: Selecting codex or pi also installs node (npm). So does
61新增: mcp-chrome when chromium and an agent are selected
62新增: (npx). mcp-playwright does not: list node yourself.
63新增: The mcp-* names wire an MCP server into each installed
64新增: agent's config. Both 'mcp-chrome' (Chrome DevTools) and
65新增: 'mcp-playwright' drive the preinstalled Chromium, so
66新增: both need node and chromium and are skipped, with a
67新增: notice, without them. Pi has no MCP support, so they
68新增: are not wired into it. 'mcp-playwright' is opt-in and not
69新增: part of 'default': a second browser-driving server is
70新增: redundant for most users. Omit them to leave the agents'
71新增: MCP config untouched, for when MCP servers are
72新增: managed per project rather than baked into the image.
73新增: Examples:
74新增: --preinstall=default,rust # default set plus Rust
75新增: --preinstall=python,docker,claude
76新增: --preinstall=node,chromium,opencode # no chrome MCP
77新增: --preinstall=default,code-claude # plus the editor
78新增: --help Show this help
79新增:`
80新增:
81新增:// The software of the base, as agent-vm.setup.sh names it
82新增:// (AGENT_VM_INSTALL_<NAME>).
83新增:var software = []string{"python", "node", "ruby", "rust", "golang", "docker", "chromium", "gh", "claude", "opencode", "codex", "vibe", "pi",
84新增: "code-server", "code-claude", "code-codex", "code-vibe", "mcp-chrome", "mcp-playwright"}
85新增:
86新增:// The default set. Opt-in: Ruby, Rust, Go, Pi (released several times a
87新增:// week), Playwright MCP (a second browser-driving server, whose tools cost
88新增:// context in every agent), and code-server with its extensions (an editor
89新增:// most use on the host).
90新增:var defaultSoftware = []string{"python", "node", "docker", "chromium", "gh", "claude", "opencode", "codex", "vibe", "mcp-chrome"}
91新增:
92新增:// skipPrereqs is for tests, on hosts without KVM.
93新增:var skipPrereqs = false
94新增:
95新增:type install map[string]bool
96新增:
97新增:func (in install) set(names ...string) {
98新增: for _, n := range names {
99新增: in[n] = true
100新增: }
101新增:}
102新增:
103新增:// nodeNeededBy says why the choices need Node.js, if they do: Codex and Pi
104新增:// install with npm, Chrome DevTools MCP runs with npx.
105新增:func (in install) nodeNeededBy() string {
106新增: switch {
107新增: case in["codex"]:
108新增: return "Codex CLI requires npm"
109新增: case in["pi"]:
110新增: return "Pi requires npm"
111新增: case in["chromium"] && in["mcp-chrome"] && (in["claude"] || in["opencode"] || in["vibe"] || in["code-claude"] || in["code-codex"] || in["code-vibe"]):
112新增: return "Chrome DevTools MCP uses npx"
113新增: }
114新增: return ""
115新增:}
116新增:
117新增:// exports are the choices as the setup script reads them.
118新增:func (in install) exports() string {
119新增: var b strings.Builder
120新增: for _, n := range software {
121新增: v := 0
122新增: if in[n] {
123新增: v = 1
124新增: }
125新增: fmt.Fprintf(&b, "export AGENT_VM_INSTALL_%s=%d\n", strings.ToUpper(strings.ReplaceAll(n, "-", "_")), v)
126新增: }
127新增: return b.String()
128新增:}
129新增:
130新增:// setupCmd: `setup [options]`, the options given before it included. Of the
131新增:// VM options, it takes the resources.
132新增:func (e *app) setupCmd(ctx context.Context, args []string) int {
133新增: disk, memory, cpus := 10, 3, 1
134新增: memorySeen := false
135新增: in := install{}
136新增: in.set(defaultSoftware...)
137新增: preinstall, preinstallSeen := "", false
138新增: for len(args) > 0 {
139新增: o := newVMOpts()
140新增: n, err := o.take(args)
141新增: if err != nil {
142新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
143新增: return exitUsage
144新增: }
145新增: if n > 0 {
146新增: switch {
147新增: case o.Disk > 0:
148新增: disk = o.Disk
149新增: case o.Memory > 0:
150新增: memory, memorySeen = o.Memory, true
151新增: case o.CPUs > 0:
152新增: cpus = o.CPUs
153新增: default:
154新增: name, _, _ := strings.Cut(args[0], "=")
155新增: fmt.Fprintf(e.io.Stderr, "Unknown option: %s\n%s\n", name, setupUsage)
156新增: return exitUsage
157新增: }
158新增: args = args[n:]
159新增: continue
160新增: }
161新增: switch a := args[0]; {
162新增: case a == "--help" || a == "-h":
163新增: fmt.Fprint(e.io.Stdout, setupHelp)
164新增: return 0
165新增: case a == "--preinstall":
166新增: // Only a value that is not an option: a bare --preinstall is the
167新增: // default set, without swallowing a following --disk.
168新增: preinstallSeen = true
169新增: if len(args) > 1 && args[1] != "" && !strings.HasPrefix(args[1], "-") {
170新增: preinstall, args = args[1], args[2:]
171新增: } else {
172新增: args = args[1:]
173新增: }
174新增: case strings.HasPrefix(a, "--preinstall="):
175新增: preinstall, preinstallSeen, args = strings.TrimPrefix(a, "--preinstall="), true, args[1:]
176新增: default:
177新增: fmt.Fprintf(e.io.Stderr, "Unknown option: %s\n%s\n", a, setupUsage)
178新增: return exitUsage
179新增: }
180新增: }
181新增: if preinstallSeen {
182新增: in = install{}
183新增: if preinstall == "" {
184新增: preinstall = "default"
185新增: }
186新增: for _, f := range strings.Split(preinstall, ",") {
187新增: f = strings.TrimPrefix(strings.TrimSuffix(f, " "), " ")
188新增: switch {
189新增: case f == "":
190新增: case f == "all":
191新增: in.set(software...)
192新增: case f == "default":
193新增: in.set(defaultSoftware...)
194新增: case f == "none":
195新增: case f == "code-claude" || f == "code-codex" || f == "code-vibe":
196新增: // An extension needs the editor.
197新增: in.set(f, "code-server")
198新增: case contains(software, f):
199新增: in.set(f)
200新增: default:
201新增: fmt.Fprintf(e.io.Stderr, "Unknown preinstall name: %s (names are lowercase)\n", f)
202新增: fmt.Fprintf(e.io.Stderr, "Valid: %s, default, all, none\n", strings.Join(software, ", "))
203新增: return exitUsage
204新增: }
205新增: }
206新增: }
207新增:
208新增: fmt.Fprintln(e.io.Stdout, "Starting agent-vm setup...")
209新增: if !skipPrereqs && (!host.LinuxPrereqs(e.io.Stderr) || !host.WindowsPrereqs(e.io.Stdout, e.io.Stderr)) {
210新增: return 1
211新增: }
212新增: if !preinstallSeen && e.ui.CanAsk() {
213新增: disk, memory, cpus = e.wizard(in, disk, memory, cpus, memorySeen)
214新增: }
215新增: if r := in.nodeNeededBy(); r != "" && !in["node"] {
216新增: fmt.Fprintf(e.io.Stderr, "Enabling Node.js because %s.\n", r)
217新增: in["node"] = true
218新增: }
219新增: return e.buildBase(ctx, in, disk, memory, cpus)
220新增:}
221新增:
222新增:// swapBase puts the finished build in the base's place: the old base and its
223新增:// markers go, the build is cloned to the base's name and marked ready, last
224新增:// the build goes. Under the base's lock, so that no start clones the base
225新增:// meanwhile. Lima has no rename, so the disk is copied once more; the build
226新增:// is kept if the copy cannot be made, and said.
227新增:func (e *app) swapBase(ctx context.Context, b vm.Backend) bool {
228新增: w := e.io.Stderr
229新增: unlock, err := e.lockVM(ctx, vmname.Template)
230新增: if err != nil {
231新增: fmt.Fprintf(w, "Error: could not lock the base template: %v. The new base is VM '%s'; 'agent-vm setup' again builds another.\n", err, building)
232新增: return false
233新增: }
234新增: defer unlock()
235新增: if d := filepath.Join(LimaHome(e.state), vmname.Template); isDirNoYAML(d) {
236新增: fmt.Fprintf(w, "Detected partial VM state at %s (no lima.yaml): cleaning up.\n", d)
237新增: if err := os.RemoveAll(d); err != nil {
238新增: fmt.Fprintf(w, "Error: could not remove %s: %v\n", d, err)
239新增: return false
240新增: }
241新增: }
242新增: // Forgets the old base's markers with it: from here on, nothing says a
243新增: // base is ready.
244新增: if !e.deleteVM(ctx, vmname.Template) {
245新增: fmt.Fprintf(w, "Error: could not replace the base VM. The new one is VM '%s'; 'agent-vm setup' again builds another.\n", building)
246新增: return false
247新增: }
248新增: if err := b.Clone(ctx, building, vmname.Template); err != nil {
249新增: fmt.Fprintf(w, "Error: could not copy the new base VM to '%s': %v\nThere is no base now. The new one is VM '%s'; 'agent-vm setup' again builds another.\n", vmname.Template, err, building)
250新增: return false
251新增: }
252新增: // The version last: it says the base can be cloned.
253新增: if err := e.state.Write(state.BaseBuiltBy, []byte(version.Version+"\n")); err != nil {
254新增: fmt.Fprintf(w, "Error: could not record the version that built the base: %v\nThe base VM is not marked ready: 'agent-vm setup' again.\n", err)
255新增: return false
256新增: }
257新增: if err := e.state.Write(state.BaseVersion, []byte(strconv.FormatInt(time.Now().Unix(), 10)+"\n")); err != nil {
258新增: fmt.Fprintf(w, "Error: could not record when the base was built: %v\nThe base VM is not marked ready: 'agent-vm setup' again.\n", err)
259新增: return false
260新增: }
261新增: if !e.deleteVM(ctx, building) {
262新增: fmt.Fprintf(w, "Warning: the base is ready, but VM '%s' stays: 'agent-vm rm %s' frees its disk.\n", building, building)
263新增: }
264新增: return true
265新增:}
266新增:
267新增:func contains(s []string, v string) bool {
268新增: for _, x := range s {
269新增: if x == v {
270新增: return true
271新增: }
272新增: }
273新增: return false
274新增:}
275新增:
276新增:// wizard asks for the software and the resources, on the terminal.
277新增:func (e *app) wizard(in install, disk, memory, cpus int, memorySeen bool) (int, int, int) {
278新增: w := e.io.Stderr
279新增: u := e.ui
280新增: yn := func(q string, def bool) bool { return u.AskYN(q, def) }
281新增: fmt.Fprint(w, "\nagent-vm setup wizard\n─────────────────────\n\n"+
282新增: "These settings apply to the base VM image. Every per-project VM is\n"+
283新增: "cloned from it, so anything preinstalled here is available in all\n"+
284新增: "future agent VMs. You can still install extra tools inside any\n"+
285新增: "individual VM later (e.g. via `agent-vm shell`).\n\n"+
286新增: "For more: https://www.agent-vm.org/\n\n"+
287新增: "Software\n────────\n"+
288新增: " Agents: Claude Code, OpenCode, Codex CLI, Mistral Vibe\n"+
289新增: " Tools: Python, Node.js, Docker, Chromium, gh,\n"+
290新增: " Chrome DevTools MCP\n"+
291新增: " Skip: Pi, Ruby, Rust, Go, Playwright MCP, code-server\n\n")
292新增: if !yn("Use this default", true) {
293新增: fmt.Fprint(w, "\nAI coding agents\n────────────────\n")
294新增: in["claude"] = yn("Claude Code", true)
295新增: in["opencode"] = yn("OpenCode", true)
296新增: in["codex"] = yn("Codex CLI", true)
297新增: in["vibe"] = yn("Mistral Vibe", true)
298新增: in["pi"] = yn("Pi", false)
299新增: fmt.Fprint(w, "\nEditor\n──────\n")
300新增: in["code-server"] = yn("code-server (VS Code in the browser, for 'agent-vm code')", false)
301新增: e.askCodeExtensions(in)
302新增: fmt.Fprint(w, "\nSystem tools\n────────────\n")
303新增: in["docker"] = yn("Docker", true)
304新增: in["chromium"] = yn("Chromium (headless browser)", true)
305新增: in["gh"] = yn("GitHub CLI (gh)", true)
306新增: in["mcp-chrome"], in["mcp-playwright"] = false, false
307新增: if in["chromium"] {
308新增: in["mcp-chrome"] = yn("Chrome DevTools MCP (wired into each agent's config)", true)
309新增: in["mcp-playwright"] = yn("Playwright MCP (also drives that Chromium)", false)
310新增: }
311新增: reason := in.nodeNeededBy()
312新增: fmt.Fprint(w, "\nLanguages\n─────────\n")
313新增: in["python"] = yn("Python 3", true)
314新增: if reason != "" {
315新增: in["node"] = true
316新增: fmt.Fprintf(w, "Node.js 24: yes (%s)\n", reason)
317新增: } else {
318新增: in["node"] = yn("Node.js 24", true)
319新增: }
320新增: in["ruby"] = yn("Ruby", false)
321新增: in["rust"] = yn("Rust", false)
322新增: in["golang"] = yn("Go", false)
323新增: }
324新增: // The editor needs more memory than the agents alone. --memory wins.
325新增: if in["code-server"] && !memorySeen {
326新增: memory = 4
327新增: }
328新增: fmt.Fprint(w, "\nDefault resources\n─────────────────\n(per-VM override with --disk / --memory / --cpus on any agent-vm command)\n\n")
329新增: fmt.Fprintf(w, " Disk %d GB\n Memory %d GB\n CPUs %d\n\n", disk, memory, cpus)
330新增: if !yn("Use these defaults", true) {
331新增: disk = u.AskInt("Disk size in GB", disk, 0)
332新增: memory = u.AskInt("Memory in GB", memory, 0)
333新增: cpus = u.AskInt("Number of CPUs", cpus, 0)
334新增: }
335新增: fmt.Fprintln(w)
336新增: return disk, memory, cpus
337新增:}
338新增:
339新增:// askCodeExtensions asks, after code-server, how the agents picked that
340新增:// have an extension are installed. Only when there is one.
341新增:func (e *app) askCodeExtensions(in install) {
342新增: if !in["code-server"] {
343新增: return
344新增: }
345新增: var names []string
346新增: for _, a := range []struct{ key, name string }{{"claude", "Claude Code"}, {"codex", "Codex"}, {"vibe", "Mistral Vibe"}} {
347新增: if in[a.key] {
348新增: names = append(names, a.name)
349新增: }
350新增: }
351新增: if len(names) == 0 {
352新增: return
353新增: }
354新增: fmt.Fprintf(e.io.Stderr, " %s in the editor:\n", strings.Join(names, ", "))
355新增: choice := e.ui.AskChoice("Pick one", 1, "Extension and command line (agent-vm claude...)", "Extension only", "Command line only")
356新增: if choice == 3 {
357新增: return
358新增: }
359新增: in["code-claude"], in["code-codex"], in["code-vibe"] = in["claude"], in["codex"], in["vibe"]
360新增: if choice == 2 {
361新增: in["claude"], in["codex"], in["vibe"] = false, false, false
362新增: }
363新增:}
364新增:
365新增:// building is the VM the new base is built as. The base that is there keeps
366新增:// serving the starts, with its markers, until the new one is complete.
367新增:const building = vmname.Template + "-building"
368新增:
369新增:// buildBase makes the base template: built as `building` (created, booted,
370新增:// provisioned by the setup script and the user's, stopped), then swapped in
371新增:// for the base and marked as ready. A setup that fails before the swap
372新增:// leaves the base it found.
373新增:func (e *app) buildBase(ctx context.Context, in install, disk, memory, cpus int) int {
374新增: b, err := e.backend()
375新增: if err != nil {
376新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
377新增: return 1
378新增: }
379新增: // One setup at a time: two would build in the same VM.
380新增: unlockSetup, err := e.lockVM(ctx, vmname.Template+"-setup")
381新增: if err != nil {
382新增: fmt.Fprintf(e.io.Stderr, "Error: could not lock the base template's setup: %v\n", err)
383新增: return 1
384新增: }
385新增: defer unlockSetup()
386新增: if !(&start{app: e, ctx: ctx}).limaOverridesOK() {
387新增: return 1
388新增: }
389新增: if err := policiesErr(e.state); err != nil {
390新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
391新增: return 1
392新增: }
393新增: warnDomains(e.state, e.io.Stderr)
394新增: // A build an earlier setup left, finished or not, is not this one's.
395新增: if d := filepath.Join(LimaHome(e.state), building); isDirNoYAML(d) {
396新增: fmt.Fprintf(e.io.Stderr, "Detected partial VM state at %s (no lima.yaml): cleaning up.\n", d)
397新增: if err := os.RemoveAll(d); err != nil {
398新增: fmt.Fprintf(e.io.Stderr, "Error: could not remove %s: %v\n", d, err)
399新增: return 1
400新增: }
401新增: }
402新增: if !e.deleteVM(ctx, building) {
403新增: return 1
404新增: }
405新增:
406新增: cpus = host.Cap("cpus", cpus, e.io.Stderr)
407新增: memory = host.Cap("memory", memory, e.io.Stderr)
408新增: host.WarnDiskSpace(LimaHome(e.state), disk, e.io.Stderr)
409新增:
410新增: if err := os.MkdirAll(string(e.state), 0o755); err != nil {
411新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
412新增: return 1
413新增: }
414新增: logPath := e.state.Path("setup.log")
415新增: log, err := os.Create(logPath)
416新增: if err != nil {
417新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
418新增: return 1
419新增: }
420新增: defer log.Close()
421新增: // Every step from here shows its output in a 10-line window, all of it
422新增: // kept in one log for when something fails.
423新增: windowed := func(fn func(w io.Writer) error) bool {
424新增: win := e.ui.NewWindow(e.io.Stdout, log)
425新增: err := fn(win)
426新增: win.Close()
427新增: if err != nil {
428新增: fmt.Fprintf(log, "%v\n", err)
429新增: if f, ok := e.io.Stdout.(*os.File); ok && ui.IsTerminal(f) {
430新增: fmt.Fprint(e.io.Stderr, ui.Tail(logPath, 20))
431新增: }
432新增: return false
433新增: }
434新增: return true
435新增: }
436新增: stopBase := func() { _ = b.Stop(ctx, building) }
437新增:
438新增: fmt.Fprintln(e.io.Stdout, "Creating base VM...")
439新增: none := []vm.Mount{}
440新增: if !windowed(func(w io.Writer) error {
441新增: return b.Create(ctx, building, "template:debian-13", vm.Settings{CPUs: cpus, MemoryGiB: memory, DiskGiB: disk, Mounts: &none, NoContainerd: true}, w)
442新增: }) {
443新增: fmt.Fprintf(e.io.Stderr, "Error: Failed to create base VM. Full log: %s\n", logPath)
444新增: return 1
445新增: }
446新增: (&start{app: e, ctx: ctx, name: building}).printResources()
447新增:
448新增: fmt.Fprintln(e.io.Stdout, "Starting base VM (the first run downloads a Debian image)...")
449新增: if !windowed(func(w io.Writer) error { return b.Start(ctx, building, w) }) {
450新增: ha := filepath.Join(LimaHome(e.state), building, "ha.stderr.log")
451新增: fmt.Fprintf(e.io.Stderr, "Error: Failed to start base VM. Full log: %s\nLima's own log: %s\n", logPath, ha)
452新增: host.WindowsStartHint(e.io.Stderr, logPath, ha)
453新增: return 1
454新增: }
455新增:
456新增: // The choices as export lines, then the script, on stdin. Without them it
457新增: // installs the default set.
458新增: fmt.Fprintln(e.io.Stdout, "Installing packages inside VM...")
459新增: if !windowed(func(w io.Writer) error {
460新增: code, err := b.Shell(ctx, building, vm.ShellOpts{Args: []string{"bash", "-l"},
461新增: Stdin: strings.NewReader(in.exports() + agentvm.SetupScript), Stdout: w, Stderr: w})
462新增: if err == nil && code != 0 {
463新增: err = fmt.Errorf("exit status %d", code)
464新增: }
465新增: return err
466新增: }) {
467新增: fmt.Fprintf(e.io.Stderr, "Error: Setup script failed. Full log: %s\n", logPath)
468新增: stopBase()
469新增: return 1
470新增: }
471新增:
472新增: if user, ok := readRegular(e.state.Path("setup.sh")); ok {
473新增: fmt.Fprintf(e.io.Stdout, "Running custom setup from %s...\n", e.state.Path("setup.sh"))
474新增: code, err := b.Shell(ctx, building, vm.ShellOpts{Args: []string{"zsh", "-l"},
475新增: Stdin: strings.NewReader(env.StripCR(user)), Stdout: e.io.Stdout, Stderr: e.io.Stderr})
476新增: if err != nil || code != 0 {
477新增: fmt.Fprintln(e.io.Stderr, "Error: Custom setup script failed.")
478新增: stopBase()
479新增: return 1
480新增: }
481新增: }
482新增:
483新增: // Ready only once stopped: Lima clones only a stopped instance.
484新增: if !e.stopVM(ctx, building) {
485新增: fmt.Fprintf(e.io.Stderr, "Error: the new base VM is set up but did not stop: 'agent-vm stop %s', then 'agent-vm setup' again. The base from before is untouched.\n", building)
486新增: return 1
487新增: }
488新增: if !e.swapBase(ctx, b) {
489新增: return 1
490新增: }
491新增:
492新增: fmt.Fprint(e.io.Stdout, "\nBase VM ready. Try one of these in any project directory:\n agent-vm shell\n")
493新增: for _, a := range []string{"claude", "opencode", "codex", "vibe", "pi"} {
494新增: if in[a] {
495新增: fmt.Fprintf(e.io.Stdout, " agent-vm %s\n", a)
496新增: }
497新增: }
498新增: if in["code-server"] {
499新增: fmt.Fprintln(e.io.Stdout, " agent-vm code")
500新增: }
501新增: // Only worth saying to someone with a VM to re-clone.
502新增: if vms, err := e.agentVMs(ctx); err == nil && len(vms) > 1 {
503新增: fmt.Fprint(e.io.Stdout, "\nNote: Existing VMs were not updated. Use --reset to re-clone them from the new base.\n")
504新增: }
505新增: return 0
506新增:}
新增internal/cli/setup_test.go+282 −0看文件
@@ -0,0 +1,282 @@
1新增:package cli
2新增:
3新增:import (
4新增: "context"
5新增: "errors"
6新增: "io"
7新增: "os"
8新增: "path/filepath"
9新增: "strings"
10新增: "testing"
11新增:
12新增: agentvm "github.com/sylvinus/agent-vm"
13新增: "github.com/sylvinus/agent-vm/internal/host"
14新增: "github.com/sylvinus/agent-vm/internal/state"
15新增: "github.com/sylvinus/agent-vm/internal/vm"
16新增: "github.com/sylvinus/agent-vm/internal/vm/vmtest"
17新增: "github.com/sylvinus/agent-vm/internal/vmname"
18新增:)
19新增:
20新增:// setupRun runs setup against a fake, with the host's prerequisites taken
21新增:// as met, and returns what the guest was given to run.
22新增:func setupRun(t *testing.T, args ...string) (*testEnv, int, []string) {
23新增: t.Helper()
24新增: te := newTestEnv(t, vmtest.New())
25新增: host.CPUs = func() int { return 64 }
26新增: host.MemGiB = func() int { return 256 }
27新增: var stdin []string
28新增: te.fake.ShellFunc = func(name string, o vm.ShellOpts) int {
29新增: b, _ := io.ReadAll(o.Stdin)
30新增: stdin = append(stdin, string(b))
31新增: return 0
32新增: }
33新增: code := te.setupBase(append([]string{"setup"}, args...))
34新增: return te, code, stdin
35新增:}
36新增:
37新增:// setupBase is setup without the host's prerequisites, which a test host
38新增:// may lack.
39新增:func (te *testEnv) setupBase(args []string) int {
40新增: te.stdout.Reset()
41新增: te.stderr.Reset()
42新增: te.fake.Calls = nil
43新增: saved := skipPrereqs
44新增: skipPrereqs = true
45新增: defer func() { skipPrereqs = saved }()
46新增: return te.main(context.Background(), args)
47新增:}
48新增:
49新增:func exportsOf(t *testing.T, stdin []string) map[string]string {
50新增: t.Helper()
51新增: if len(stdin) == 0 || !strings.HasSuffix(stdin[0], agentvm.SetupScript) {
52新增: t.Fatalf("the setup script was not run: %q", stdin)
53新增: }
54新增: m := map[string]string{}
55新增: for _, l := range strings.Split(strings.TrimSuffix(stdin[0], agentvm.SetupScript), "\n") {
56新增: if k, v, ok := strings.Cut(strings.TrimPrefix(l, "export AGENT_VM_INSTALL_"), "="); ok {
57新增: m[k] = v
58新增: }
59新增: }
60新增: return m
61新增:}
62新增:
63新增:func on(m map[string]string) string {
64新增: var out []string
65新增: for _, n := range software {
66新增: if m[strings.ToUpper(strings.ReplaceAll(n, "-", "_"))] == "1" {
67新增: out = append(out, n)
68新增: }
69新增: }
70新增: return strings.Join(out, ",")
71新增:}
72新增:
73新增:func TestSetupPreinstall(t *testing.T) {
74新增: for _, c := range []struct {
75新增: args []string
76新增: want string
77新增: }{
78新增: {[]string{"--preinstall=default"}, "python,node,docker,chromium,gh,claude,opencode,codex,vibe,mcp-chrome"},
79新增: {[]string{"--preinstall", "--disk", "20"}, "python,node,docker,chromium,gh,claude,opencode,codex,vibe,mcp-chrome"},
80新增: {[]string{"--preinstall=none"}, ""},
81新增: {[]string{"--preinstall=all"}, strings.Join(software, ",")},
82新增: {[]string{"--preinstall=python, docker,claude"}, "python,docker,claude"},
83新增: {[]string{"--preinstall=code-vibe"}, "code-server,code-vibe"},
84新增: // Codex needs npm: node goes in, and it is said.
85新增: {[]string{"--preinstall=codex"}, "node,codex"},
86新增: } {
87新增: te, code, stdin := setupRun(t, c.args...)
88新增: if code != 0 {
89新增: t.Fatalf("%q: %d %s", c.args, code, te.out())
90新增: }
91新增: if got := on(exportsOf(t, stdin)); got != c.want {
92新增: t.Errorf("%q: %s, want %s", c.args, got, c.want)
93新增: }
94新增: if c.want == "node,codex" && !strings.Contains(te.out(), "Enabling Node.js because Codex CLI requires npm.") {
95新增: t.Errorf("node not said: %s", te.out())
96新增: }
97新增: }
98新增: te, code, _ := setupRun(t, "--preinstall=Claude")
99新增: if code != exitUsage || !strings.Contains(te.out(), "Unknown preinstall name: Claude (names are lowercase)") {
100新增: t.Errorf("unknown name: %s", te.out())
101新增: }
102新增: te, code, _ = setupRun(t, "--reset")
103新增: if code != exitUsage || !strings.Contains(te.out(), "Unknown option: --reset") {
104新增: t.Errorf("--reset: %s", te.out())
105新增: }
106新增: for _, args := range [][]string{{"--rm"}, {"--scratch"}, {"--ssh-port=2222"}, {"--disk", "10G"}, {"--disk"}, {"--unsafe-writable-git"}, {"--unsafe-disable-security-prompts"}} {
107新增: if te, code, _ = setupRun(t, args...); code != exitUsage || te.fake.CallLog() != "" {
108新增: t.Errorf("%q: %d %s", args, code, te.out())
109新增: }
110新增: }
111新增: te, code, _ = setupRun(t, "--help")
112新增: if code != 0 || te.stdout.String() != setupHelp {
113新增: t.Error("--help")
114新增: }
115新增:}
116新增:
117新增:// wizardRun is setupRun on a terminal, answering the wizard.
118新增:func wizardRun(t *testing.T, answers ...string) (*testEnv, []string) {
119新增: t.Helper()
120新增: te := newTestEnv(t, vmtest.New(), answers...)
121新增: host.CPUs = func() int { return 64 }
122新增: host.MemGiB = func() int { return 256 }
123新增: var stdin []string
124新增: te.fake.ShellFunc = func(name string, o vm.ShellOpts) int {
125新增: b, _ := io.ReadAll(o.Stdin)
126新增: stdin = append(stdin, string(b))
127新增: return 0
128新增: }
129新增: if code := te.setupBase([]string{"setup"}); code != 0 {
130新增: t.Fatalf("%d %s", code, te.out())
131新增: }
132新增: return te, stdin
133新增:}
134新增:
135新增:func TestSetupWizard(t *testing.T) {
136新增: // Enter everywhere: the default set and resources.
137新增: te, stdin := wizardRun(t)
138新增: if got := on(exportsOf(t, stdin)); got != strings.Join(defaultSoftware, ",") {
139新增: t.Errorf("default: %s", got)
140新增: }
141新增: if b := te.fake.VMs[vmname.Template]; b.CPUs != 1 || b.Memory != 3<<30 || b.Disk != 10<<30 {
142新增: t.Errorf("default resources: %+v", b)
143新增: }
144新增: if !strings.Contains(te.out(), " Resources: CPUs: 1, Memory: 3 GiB, Disk: 10 GiB\n") {
145新增: t.Errorf("resources not shown: %s", te.out())
146新增: }
147新增:
148新增: // Each component: Claude and Codex as extensions only, whose Chrome
149新增: // DevTools MCP needs Node.js; code-server makes the default memory 4.
150新增: te, stdin = wizardRun(t,
151新增: "n", // the default set
152新增: "", "n", "y", "n", "", // Claude, OpenCode, Codex, Vibe, Pi
153新增: "y", "2", // code-server, extension only
154新增: "n", "y", "n", "y", "", // Docker, Chromium, gh, Chrome MCP, Playwright MCP
155新增: "n", "y", "", "", // Python, Ruby, Rust, Go
156新增: "n", "15", "", "3") // resources
157新增: if got := on(exportsOf(t, stdin)); got != "node,ruby,chromium,code-server,code-claude,code-codex,mcp-chrome" {
158新增: t.Errorf("picked: %s", got)
159新增: }
160新增: if b := te.fake.VMs[vmname.Template]; b.CPUs != 3 || b.Memory != 4<<30 || b.Disk != 15<<30 {
161新增: t.Errorf("resources: %+v", b)
162新增: }
163新增: if !strings.Contains(te.out(), "Node.js 24: yes (Chrome DevTools MCP uses npx)") || !strings.Contains(te.out(), " agent-vm code\n") ||
164新增: strings.Contains(te.out(), " agent-vm claude\n") {
165新增: t.Errorf("output: %s", te.out())
166新增: }
167新增:}
168新增:
169新增:// code-server makes the default memory 4, but --memory wins. No terminal:
170新增:// no wizard, the default set.
171新增:func TestSetupWizardMemory(t *testing.T) {
172新增: te := newTestEnv(t, vmtest.New(), "n", "", "", "", "", "", "y")
173新增: host.CPUs = func() int { return 64 }
174新增: host.MemGiB = func() int { return 256 }
175新增: if te.setupBase([]string{"setup", "--memory", "2"}) != 0 {
176新增: t.Fatal(te.out())
177新增: }
178新增: if b := te.fake.VMs[vmname.Template]; b.Memory != 2<<30 || !strings.Contains(te.out(), "code-server (VS Code") {
179新增: t.Errorf("--memory with code-server: %+v %s", b, te.out())
180新增: }
181新增:
182新增: te, code, stdin := setupRun(t)
183新增: if code != 0 || strings.Contains(te.out(), "setup wizard") || on(exportsOf(t, stdin)) != strings.Join(defaultSoftware, ",") {
184新增: t.Errorf("no terminal: %d %s", code, te.out())
185新增: }
186新增:}
187新增:
188新增:func TestSetupFailures(t *testing.T) {
189新增: for _, c := range []struct{ op, want string }{
190新增: {"create", "Error: Failed to create base VM. Full log: "},
191新增: {"start", "Error: Failed to start base VM. Full log: "},
192新增: {"shell", "Error: Setup script failed. Full log: "},
193新增: } {
194新增: te := newTestEnv(t, vmtest.New())
195新增: te.fake.FailOn = map[string]error{c.op: errors.New("boom")}
196新增: if te.setupBase([]string{"setup", "--preinstall=none"}) != 1 || !strings.Contains(te.out(), c.want+te.state.Path("setup.log")) {
197新增: t.Errorf("%s: %s", c.op, te.out())
198新增: }
199新增: if log, _ := os.ReadFile(te.state.Path("setup.log")); !strings.Contains(string(log), "boom") {
200新增: t.Errorf("%s: log %q", c.op, log)
201新增: }
202新增: if _, err := os.Stat(te.state.Path(state.BaseVersion)); err == nil {
203新增: t.Errorf("%s: ready marker", c.op)
204新增: }
205新增: }
206新增: // A base that does not stop is not marked ready: Lima clones only a
207新增: // stopped one.
208新增: te := newTestEnv(t, vmtest.New())
209新增: te.fake.Sticky[building] = true
210新增: if te.setupBase([]string{"setup", "--preinstall=none"}) != 1 || !strings.Contains(te.out(), "the new base VM is set up but did not stop") {
211新增: t.Errorf("running base: %s", te.out())
212新增: }
213新增: if _, err := os.Stat(te.state.Path(state.BaseVersion)); err == nil {
214新增: t.Error("a running base was marked ready")
215新增: }
216新增:}
217新增:
218新增:// Said only to someone with VMs cloned from the previous base.
219新增:func TestSetupExistingNote(t *testing.T) {
220新增: const note = "Existing VMs were not updated"
221新增: te, _, _ := setupRun(t, "--preinstall=none")
222新增: if strings.Contains(te.out(), note) {
223新增: t.Errorf("no VM, but: %s", te.out())
224新增: }
225新增: te.fake.VMs["proj-deadbeef"] = &vm.Instance{Name: "proj-deadbeef", Status: vm.Stopped}
226新增: if te.setupBase([]string{"setup", "--preinstall=none"}) != 0 || !strings.Contains(te.out(), note) {
227新增: t.Errorf("with a VM: %s", te.out())
228新增: }
229新增:}
230新增:
231新增:func TestSetupBase(t *testing.T) {
232新增: te, code, stdin := setupRun(t, "--preinstall=none", "--disk", "12", "--memory=5", "--cpus", "2")
233新增: if code != 0 {
234新增: t.Fatalf("%d %s", code, te.out())
235新增: }
236新增: base := te.fake.VMs[vmname.Template]
237新增: if base == nil || base.Status != vm.Stopped || base.CPUs != 2 || base.Memory != 5<<30 || base.Disk != 12<<30 || len(base.Mounts) != 0 {
238新增: t.Fatalf("base: %+v", base)
239新增: }
240新增: if !strings.HasPrefix(te.fake.CallLog(), "delete base-building\ncreate base-building template:debian-13\nstart base-building\nshell base-building bash -l\nstop base-building\ndelete base\nclone base-building base\ndelete base-building") {
241新增: t.Errorf("calls:\n%s", te.fake.CallLog())
242新增: }
243新增: if len(stdin) != 1 {
244新增: t.Errorf("guest stdin: %q", stdin)
245新增: }
246新增: if te.state.Read(state.BaseBuiltBy) == "" || te.state.Read(state.BaseVersion) == "" {
247新增: t.Error("markers not written")
248新增: }
249新增: if !strings.Contains(te.out(), "Base VM ready.") || strings.Contains(te.out(), "agent-vm claude") {
250新增: t.Errorf("output: %s", te.out())
251新增: }
252新增: // The user's setup.sh, CRs dropped, under zsh; a failure fails setup and
253新增: // leaves no marker.
254新增: os.WriteFile(te.state.Path("setup.sh"), []byte("echo x\r\n"), 0o644)
255新增: var got []string
256新增: te.fake.ShellFunc = func(name string, o vm.ShellOpts) int {
257新增: b, _ := io.ReadAll(o.Stdin)
258新增: got = append(got, strings.Join(o.Args, " ")+": "+string(b))
259新增: if o.Args[0] == "zsh" {
260新增: return 1
261新增: }
262新增: return 0
263新增: }
264新增: if te.setupBase([]string{"setup", "--preinstall=none"}) != 1 || !strings.Contains(te.out(), "Custom setup script failed") {
265新增: t.Errorf("failing setup.sh: %s", te.out())
266新增: }
267新增: if len(got) != 2 || got[1] != "zsh -l: echo x\n" {
268新增: t.Errorf("setup.sh: %q", got)
269新增: }
270新增: // The base from before is untouched.
271新增: if _, err := os.Stat(te.state.Path(state.BaseVersion)); err != nil || te.fake.VMs[vmname.Template] == nil {
272新增: t.Error("a failed setup took the base from before")
273新增: }
274新增: // Lima's override.yaml: nothing made.
275新增: cfg := filepath.Join(LimaHome(te.state), "_config")
276新增: os.MkdirAll(cfg, 0o755)
277新增: os.WriteFile(filepath.Join(cfg, "override.yaml"), []byte("mounts: []\n"), 0o644)
278新增: te.fake.Calls = nil
279新增: if te.setupBase([]string{"setup", "--preinstall=none"}) != 1 || !strings.Contains(te.out(), "override.yaml adds to every VM's config") || te.fake.CallLog() != "" {
280新增: t.Errorf("override.yaml: %s\n%s", te.out(), te.fake.CallLog())
281新增: }
282新增:}
新增internal/cli/start.go+867 −0看文件
@@ -0,0 +1,867 @@
1新增:package cli
2新增:
3新增:import (
4新增: "bytes"
5新增: "context"
6新增: "errors"
7新增: "fmt"
8新增: "io"
9新增: "os"
10新增: "os/exec"
11新增: "path/filepath"
12新增: "reflect"
13新增: "slices"
14新增: "strings"
15新增:
16新增: "github.com/sylvinus/agent-vm/internal/env"
17新增: "github.com/sylvinus/agent-vm/internal/guard"
18新增: "github.com/sylvinus/agent-vm/internal/host"
19新增: "github.com/sylvinus/agent-vm/internal/mounts"
20新增: "github.com/sylvinus/agent-vm/internal/netguard"
21新增: "github.com/sylvinus/agent-vm/internal/paths"
22新增: "github.com/sylvinus/agent-vm/internal/runscript"
23新增: "github.com/sylvinus/agent-vm/internal/state"
24新增: "github.com/sylvinus/agent-vm/internal/vm"
25新增: "github.com/sylvinus/agent-vm/internal/vmname"
26新增:)
27新增:
28新增:var errStop = errors.New("stop")
29新增:
30新增:// get is the VM name, nil when there is none.
31新增:func (s *start) get(name string) (*vm.Instance, error) {
32新增: b, err := s.backend()
33新增: if err != nil {
34新增: return nil, err
35新增: }
36新增: inst, err := b.Get(s.ctx, name)
37新增: if errors.Is(err, vm.ErrNotFound) {
38新增: return nil, nil
39新增: }
40新增: return inst, err
41新增:}
42新增:
43新增:func (s *start) running() bool {
44新增: inst, err := s.get(s.name)
45新增: return err == nil && inst != nil && inst.Status == vm.Running
46新增:}
47新增:
48新增:// shares is what the VM gets now: the project and the volumes, writable or
49新增:// not, with the read-only names when .git is protected; nothing for a
50新增:// scratch VM. The mount type that goes with them is reverse-sshfs: with the
51新增:// read-only names, it is what enforces them; without, the builtin SFTP
52新增:// server still serves the shares alone.
53新增://
54新增:// Built once per mode and names, so its warnings show once.
55新增:func (s *start) shares(writable bool) ([]vm.Mount, []mounts.FileMount) {
56新增: if s.opts.Scratch {
57新增: return []vm.Mount{}, nil
58新增: }
59新增: n := s.names
60新增: if !s.protect {
61新增: n = []string{}
62新增: }
63新增: key := fmt.Sprint(writable, n)
64新增: if s.built != nil && s.builtKey == key {
65新增: return s.built, s.builtFiles
66新增: }
67新增: s.built, s.builtFiles = mounts.Build(mounts.Shares{
68新增: VM: s.name, Dir: s.dir, Writable: writable, Names: n,
69新增: Entries: s.entries(s.dir, s.io.Stderr), StateDir: string(s.state), Warn: s.io.Stderr,
70新增: })
71新增: s.builtKey = key
72新增: return s.built, s.builtFiles
73新增:}
74新增:
75新增:// applyShares gives the stopped VM its shares, and records the single files
76新增:// of the volumes for the bind once it runs.
77新增:func (s *start) applyShares(writable bool) error {
78新增: b, err := s.backend()
79新增: if err != nil {
80新增: return err
81新增: }
82新增: ms, files := s.shares(writable)
83新增: mt := vm.ReverseSSHFS
84新增: if err := b.Edit(s.ctx, s.name, vm.Settings{Mounts: &ms, MountType: &mt}); err != nil {
85新增: s.warnf("Error: could not set the shares of VM '%s':\n%v", s.name, err)
86新增: return errStop
87新增: }
88新增: cache := s.state.Marker(state.FileMountsOf, s.name)
89新增: if err := os.Remove(cache); err != nil && !os.IsNotExist(err) {
90新增: s.warnf("Error: could not remove %s:\n%v", cache, err)
91新增: return errStop
92新增: }
93新增: if len(files) > 0 {
94新增: var lines []string
95新增: for _, f := range files {
96新增: lines = append(lines, f.Line())
97新增: }
98新增: if err := s.state.Write(state.FileMountsOf+s.name, []byte(strings.Join(lines, "\n")+"\n")); err != nil {
99新增: s.warnf("Error: could not record the single files of ~/.agent-vm/volumes for VM '%s':\n%v", s.name, err)
100新增: return errStop
101新增: }
102新增: }
103新增: return nil
104新增:}
105新增:
106新增:// applyResources gives the stopped VM the memory, CPUs and SSH port asked
107新增:// for. The disk apart, with a warning only: it can grow, not shrink.
108新增:func (s *start) applyResources() error {
109新增: b, err := s.backend()
110新增: if err != nil {
111新增: return err
112新增: }
113新增: set := vm.Settings{CPUs: s.opts.CPUs, MemoryGiB: s.opts.Memory}
114新增: if s.opts.SSHPort >= 0 {
115新增: p := s.opts.SSHPort
116新增: set.SSHLocalPort = &p
117新增: }
118新增: if err := b.Edit(s.ctx, s.name, set); err != nil {
119新增: s.warnf("Error: could not set the memory, CPUs or SSH port of VM '%s':\n%v", s.name, err)
120新增: return errStop
121新增: }
122新增: if s.opts.Disk > 0 {
123新增: if err := b.Edit(s.ctx, s.name, vm.Settings{DiskGiB: s.opts.Disk}); err != nil {
124新增: s.warnf("Warning: cannot set the disk of VM '%s' to %d GiB: it can grow, not shrink ('agent-vm setup --disk %d' for a smaller base).\n%v", s.name, s.opts.Disk, s.opts.Disk, err)
125新增: }
126新增: }
127新增: return nil
128新增:}
129新增:
130新增:// resourcesDiffer: would the resources asked change anything? Compared in
131新增:// bytes; the disk one way, since it can only grow. True when the VM cannot
132新增:// be read: never "no change" from missing information.
133新增:func (s *start) resourcesDiffer(inst *vm.Instance) bool {
134新增: o := s.opts
135新增: switch {
136新增: case inst == nil:
137新增: return true
138新增: case o.CPUs > 0 && o.CPUs != inst.CPUs:
139新增: return true
140新增: case o.Memory > 0 && int64(o.Memory)<<30 != inst.Memory:
141新增: return true
142新增: case o.Disk > 0 && int64(o.Disk)<<30 > inst.Disk:
143新增: return true
144新增: }
145新增: return false
146新增:}
147新增:
148新增:// stopToChange stops the VM to change it, then asks what its start did not,
149新增:// a running VM having been asked nothing.
150新增:func (s *start) stopToChange() error {
151新增: if !s.stopVM(s.ctx, s.name) {
152新增: s.warnf("Error: could not stop VM '%s': nothing was changed.", s.name)
153新增: return errStop
154新增: }
155新增: if s.vmUp {
156新增: s.vmUp = false
157新增: if !s.checks() {
158新增: s.warnf("VM '%s' is stopped.", s.name)
159新增: return errStop
160新增: }
161新增: }
162新增: return nil
163新增:}
164新增:
165新增:// beforeBoot fails unless what Lima would boot the stopped VM with is what
166新增:// agent-vm set: every share with the read-only names when protected, no
167新增:// share for a scratch VM.
168新增:func (s *start) beforeBoot() error {
169新增: inst, err := s.get(s.name)
170新增: if err != nil || inst == nil {
171新增: s.warnf("Error: could not read Lima's config for VM '%s', so what it would boot with is not known.", s.name)
172新增: return errStop
173新增: }
174新增: // Each that applies, none in place of another: --readonly with .git
175新增: // protected must hold both.
176新增: var whys []string
177新增: if s.opts.Scratch && len(inst.Mounts) > 0 {
178新增: whys = append(whys, "a share, though a scratch VM gets none")
179新增: }
180新增: if err := vm.Confined(inst); err != nil {
181新增: whys = append(whys, err.Error())
182新增: }
183新增: if s.protect && !s.opts.Scratch {
184新增: whys = append(whys, unprotected(inst, s.names))
185新增: }
186新增: if s.opts.ReadOnly {
187新增: whys = append(whys, notReadOnly(inst))
188新增: }
189新增: for _, why := range whys {
190新增: if why != "" {
191新增: s.warnf("Error: VM '%s' would not boot as asked: %s.", s.name, why)
192新增: return errStop
193新增: }
194新增: }
195新增: if err := policiesErr(s.state); err != nil {
196新增: s.warnf("Error: %v", err)
197新增: return errStop
198新增: }
199新增: return nil
200新增:}
201新增:
202新增:// policiesErr is what the hostagent would stop on in the network and
203新增:// guarded files: said here, where the user sees it, not in Lima's log.
204新增:func policiesErr(st state.Dir) error {
205新增: if _, err := netguard.Load(string(st)); err != nil {
206新增: return err
207新增: }
208新增: _, err := guard.Load(string(st), "")
209新增: return err
210新增:}
211新增:
212新增:// configErr says so when Lima cannot read inst's config.
213新增:func (s *start) configErr(inst *vm.Instance) bool {
214新增: if inst == nil || inst.ConfigErr == nil {
215新增: return false
216新增: }
217新增: s.warnf("Error: Lima cannot read the config of VM '%s':\n %v\n'agent-vm --reset <command>' re-clones it.", inst.Name, inst.ConfigErr)
218新增: return true
219新增:}
220新增:
221新增:// limaOverridesOK says so when Lima's default.yaml or override.yaml would
222新增:// add to what agent-vm sets for every VM.
223新增:func (s *start) limaOverridesOK() bool {
224新增: found := vm.LimaOverrides(LimaHome(s.state))
225新增: for _, f := range found {
226新增: s.warnf("Error: %s adds to every VM's config (shares, mount type...): agent-vm makes and starts no VM while it is there. Move it out of the way.", f)
227新增: }
228新增: return len(found) == 0
229新增:}
230新增:
231新增:// The verdicts on a VM's shares, "" when they hold. Each starts from
232新增:// vm.Confined: only the builtin SFTP server over reverse-sshfs enforces
233新增:// anything on the host.
234新增:
235新增:// unprotected says why inst's shares leave .git writable: not confined, or
236新增:// a share without one of names (mounts.BaseNames when nil; more is no less
237新增:// safe).
238新增:func unprotected(inst *vm.Instance, names []string) string {
239新增: if err := vm.Confined(inst); err != nil {
240新增: return err.Error()
241新增: }
242新增: if names == nil {
243新增: names = mounts.BaseNames
244新增: }
245新增: for _, m := range inst.Mounts {
246新增: if slices.ContainsFunc(names, func(n string) bool { return !slices.Contains(m.SSHFS.ReadonlyNames, n) }) {
247新增: return "the share of " + m.Location + " lacks the read-only names"
248新增: }
249新增: }
250新增: return ""
251新增:}
252新增:
253新增:// notReadOnly says why inst's shares are not all read-only on the host.
254新增:func notReadOnly(inst *vm.Instance) string {
255新增: if err := vm.Confined(inst); err != nil {
256新增: return err.Error()
257新增: }
258新增: for _, m := range inst.Mounts {
259新增: if m.Writable {
260新增: return "a writable share of " + m.Location
261新增: }
262新增: }
263新增: return ""
264新增:}
265新增:
266新增:// sharesDiffer reports whether inst's shares differ from want, Lima's
267新增:// defaults (sshfs's cache on, no SFTP driver named) filled in on both.
268新增:func sharesDiffer(inst *vm.Instance, want []vm.Mount) bool {
269新增: if len(inst.Mounts) == 0 && len(want) == 0 {
270新增: return false
271新增: }
272新增: norm := func(ms []vm.Mount) []vm.Mount {
273新增: out := make([]vm.Mount, len(ms))
274新增: for i, m := range ms {
275新增: o := vm.SSHFS{}
276新增: if m.SSHFS != nil {
277新增: o = *m.SSHFS
278新增: }
279新增: if o.Cache == nil {
280新增: on := true
281新增: o.Cache = &on
282新增: }
283新增: if len(o.ReadonlyNames) == 0 {
284新增: o.ReadonlyNames = nil
285新增: }
286新增: m.SSHFS = &o
287新增: out[i] = m
288新增: }
289新增: return out
290新增: }
291新增: return !reflect.DeepEqual(norm(inst.Mounts), norm(want)) || inst.MountType != vm.ReverseSSHFS
292新增:}
293新增:
294新增:// allReadOnly reports whether every share of inst is read-only.
295新增:func allReadOnly(inst *vm.Instance) bool {
296新增: for _, m := range inst.Mounts {
297新增: if m.Writable {
298新增: return false
299新增: }
300新增: }
301新增: return len(inst.Mounts) > 0
302新增:}
303新增:
304新增:// ensureRunning makes the project's VM exist and run, with its shares as
305新增:// asked: cloned from the base, changed while stopped, the security checks
306新增:// done first. Under the VM's lock: another run in the same folder waits for
307新增:// this one to be done with the VM, and cleans up nothing of it meanwhile.
308新增:func (s *start) ensureRunning() error {
309新增: // A scratch VM has a name of its own, which no other run uses.
310新增: if !s.opts.Scratch {
311新增: unlock, err := s.lockVM(s.ctx, s.name)
312新增: if err != nil {
313新增: s.warnf("Error: could not lock VM '%s': %v", s.name, err)
314新增: return errStop
315新增: }
316新增: defer unlock()
317新增: }
318新增: return s.ensureRunningLocked()
319新增:}
320新增:
321新增:func (s *start) ensureRunningLocked() error {
322新增: o := &s.opts
323新增: if o.Scratch && (o.Reset || o.ReadOnly) {
324新增: s.warnf("Error: --scratch makes a new VM that shares nothing: --reset and --readonly do not go with it.")
325新增: return errStop
326新增: }
327新增: wantWritable := !o.ReadOnly
328新增: o.CPUs = host.Cap("cpus", o.CPUs, s.io.Stderr)
329新增: o.Memory = host.Cap("memory", o.Memory, s.io.Stderr)
330新增: host.WarnDiskSpace(LimaHome(s.state), o.Disk, s.io.Stderr)
331新增: b, err := s.backend()
332新增: if err != nil {
333新增: s.warnf("Error: %v", err)
334新增: return errStop
335新增: }
336新增: if !s.limaOverridesOK() {
337新增: return errStop
338新增: }
339新增: warnDomains(s.state, s.io.Stderr)
340新增: // Two VMs set to one port: the second would fail to start.
341新增: if o.SSHPort > 0 {
342新增: if all, err := b.List(s.ctx); err == nil {
343新增: for _, v := range all {
344新增: if v.Name != s.name && v.SSHPortConfig == o.SSHPort {
345新增: s.warnf("Error: SSH port %d is already set for VM '%s'.", o.SSHPort, v.Name)
346新增: return errStop
347新增: }
348新增: }
349新增: }
350新增: }
351新增: // `cd ~ && agent-vm shell` would hand the VM your dotfiles and SSH
352新增: // keys, read-write; a share holding agent-vm's own files lets the VM
353新增: // change what the host runs next. agent-vm's own clone may be shared
354新增: // once the security prompts are off: working on agent-vm in its VM.
355新增: if !o.Scratch {
356新增: refs := s.refs()
357新增: if _, off := s.promptsDisabledBy(); off {
358新增: var others []mounts.Ref
359新增: for _, r := range refs {
360新增: if r.What != mounts.SelfRef {
361新增: others = append(others, r)
362新增: }
363新增: }
364新增: if _, bad := mounts.UnsafeProject(s.dir, others); !bad {
365新增: if why, self := mounts.UnsafeLocation(s.dir, refs); self {
366新增: s.warnf("Warning: sharing %s with the VM: it %s. The VM can change the agent-vm this machine runs next.", s.dir, why)
367新增: s.confirmUnsafe()
368新增: }
369新增: refs = others
370新增: }
371新增: }
372新增: if why, bad := mounts.UnsafeProject(s.dir, refs); bad {
373新增: s.warnf("Error: refusing to share %s with a VM: it %s.\nRun agent-vm from a project directory.", s.dir, why)
374新增: return errStop
375新增: }
376新增: if why, bad := mounts.Unmountable(s.dir); bad {
377新增: s.warnf("Error: project path %s:\n %s\nRename the directory, then retry.", why, s.dir)
378新增: return errStop
379新增: }
380新增: }
381新增: // A run interrupted while Lima made it leaves a folder without lima.yaml.
382新增: // Under the VM's lock: no other run is making it now.
383新增: if d := filepath.Join(LimaHome(s.state), s.name); isDirNoYAML(d) {
384新增: s.warnf("Detected partial VM state at %s (no lima.yaml): cleaning up.", d)
385新增: if err := os.RemoveAll(d); err != nil {
386新增: s.warnf("Error: could not remove %s:\n%v", d, err)
387新增: return errStop
388新增: }
389新增: }
390新增: base, err := s.get(vmname.Template)
391新增: if err != nil {
392新增: s.warnf("Error: could not query Lima: %v", err)
393新增: return errStop
394新增: }
395新增: if s.configErr(base) {
396新增: return errStop
397新增: }
398新增: if _, merr := os.Stat(s.state.Path(state.BaseVersion)); base == nil || merr != nil {
399新增: if base != nil {
400新增: s.warnf("Error: Base VM setup did not complete. Run 'agent-vm setup' again.")
401新增: } else {
402新增: s.warnf("Error: Base VM not found. Run 'agent-vm setup' first.")
403新增: }
404新增: return errStop
405新增: }
406新增:
407新增: s.vmUp = !o.Reset && s.running()
408新增: if !s.checks() {
409新增: return errStop
410新增: }
411新增: inst, err := s.get(s.name)
412新增: if err != nil {
413新增: s.warnf("Error: could not query Lima: %v", err)
414新增: return errStop
415新增: }
416新增: if !o.Reset && s.configErr(inst) {
417新增: return errStop
418新增: }
419新增: if o.Reset && inst != nil {
420新增: fmt.Fprintf(s.io.Stdout, "Resetting VM '%s'...\n", s.name)
421新增: if !s.deleteVM(s.ctx, s.name) {
422新增: return errStop
423新增: }
424新增: inst = nil
425新增: }
426新增:
427新增: // 0.1.0 recorded no version for its bases, and their VMs have no sshfs,
428新增: // which the shares need; 0.2 migrated them in place.
429新增: if inst != nil && !o.Scratch && !exists(s.state.Marker(state.BuiltByOf, s.name)) && !exists(s.state.Marker(state.SSHFSOf, s.name)) {
430新增: s.warnf("Error: VM '%s' comes from a base built by agent-vm 0.1.0, without the sshfs its shares need. Run 'agent-vm setup', then 'agent-vm --reset <command>' here.", s.name)
431新增: return errStop
432新增: }
433新增:
434新增: isNew := inst == nil
435新增: applyResize := false
436新增: if isNew {
437新增: fmt.Fprintf(s.io.Stdout, "Creating VM '%s'...\n", s.name)
438新增: marks, err := s.cloneBase()
439新增: if err != nil {
440新增: s.warnf("Error: could not clone the base template into '%s':\n%v", s.name, err)
441新增: if errors.Is(err, vm.ErrNameTooLong) {
442新增: s.warnf(" The VM's name comes from the project folder's: give the folder a shorter name.")
443新增: }
444新增: return errStop
445新增: }
446新增: s.created = true
447新增: for _, k := range []string{state.BuiltByOf, state.SSHFSOf} {
448新增: os.Remove(s.state.Marker(k, s.name))
449新增: }
450新增: if marks.builtBy != nil {
451新增: if err := s.state.Write(state.BuiltByOf+s.name, marks.builtBy); err != nil {
452新增: s.warnf("Error: could not record which agent-vm built the base of VM '%s': %v", s.name, err)
453新增: s.dropNew()
454新增: return errStop
455新增: }
456新增: } else if s.protect {
457新增: // 0.1.0's bases have no sshfs for the protected shares.
458新增: s.warnf("Error: the base VM was built by agent-vm 0.1.0, without what the shares that keep .git read-only need. Run 'agent-vm setup' to build a new one.")
459新增: s.dropNew()
460新增: return errStop
461新增: }
462新增: // Configured before its first start. A clone that could not be holds
463新增: // nothing yet: it goes, and the next run starts over.
464新增: if s.applyShares(wantWritable) != nil || s.applyResources() != nil {
465新增: s.dropNew()
466新增: return errStop
467新增: }
468新增: fmt.Fprint(s.io.Stdout, s.notes)
469新增: if marks.version != nil {
470新增: if err := s.state.Write(state.VersionOf+s.name, marks.version); err != nil {
471新增: s.warnf("Warning: could not record the base VM '%s' was cloned from: %v. Every start will say that the base has been updated.", s.name, err)
472新增: }
473新增: }
474新增: } else if ((o.Disk > 0 || o.Memory > 0 || o.CPUs > 0) && s.resourcesDiffer(inst)) || (o.SSHPort >= 0 && o.SSHPort != inst.SSHPortConfig) {
475新增: // Only when the request differs: a caller passing its defaults every
476新增: // time would otherwise be asked every time. Declined, the VM keeps
477新增: // its settings and everything below still applies.
478新增: applyResize = true
479新增: if s.running() {
480新增: fmt.Fprintf(s.io.Stdout, "VM '%s' is currently running. It must be stopped to apply new settings.\n", s.name)
481新增: if s.ui.CanAsk() && s.ui.AskYN("Stop the VM and apply changes?", false) {
482新增: fmt.Fprintln(s.io.Stdout, "Stopping VM...")
483新增: if err := s.stopToChange(); err != nil {
484新增: return err
485新增: }
486新增: } else {
487新增: fmt.Fprintln(s.io.Stdout, "Not applied: the VM keeps its current settings.")
488新增: applyResize = false
489新增: }
490新增: }
491新增: }
492新增: if applyResize {
493新增: fmt.Fprintln(s.io.Stdout, "Updating VM settings...")
494新增: if err := s.applyResources(); err != nil {
495新增: return err
496新增: }
497新增: }
498新增: if s.staleState(s.name) == "1" {
499新增: s.warnf("Warning: Base VM has been updated since this VM was cloned. Use --reset to re-clone from the new base.")
500新增: }
501新增:
502新增: // The shares Lima has, against those asked: a stopped VM is changed
503新增: // before it boots, so nothing starting with it gets a writable window; a
504新增: // running one keeps its shares until stopped, or is offered a restart.
505新增: wasRunning := s.running()
506新增: if inst, err = s.get(s.name); err != nil || inst == nil {
507新增: s.warnf("Error: could not query Lima: %v", err)
508新增: return errStop
509新增: }
510新增: want, _ := s.shares(wantWritable)
511新增: wasProtected := len(inst.Mounts) > 0 && unprotected(inst, nil) == ""
512新增: gitStale := !o.Scratch && wasProtected != s.protect
513新增: namesStale := s.protect && wasProtected && unprotected(inst, s.names) != ""
514新增: stale := sharesDiffer(inst, want)
515新增: if !o.ReadOnly && wasRunning && s.protect && (gitStale || namesStale) {
516新增: if gitStale {
517新增: s.warnf("Warning: VM '%s' is running with .git writable, so the agent can still write .git.", s.name)
518新增: } else {
519新增: s.warnf("Warning: VM '%s' runs with an older list of read-only names (it needs %s), so the agent can still write the new ones.", s.name, strings.Join(s.names, ", "))
520新增: }
521新增: if _, off := s.promptsDisabledBy(); !off && s.ui.CanAsk() && s.ui.AskYN("Restart it now to apply them? Sessions using it are cut.", true) {
522新增: if err := s.stopToChange(); err != nil {
523新增: return err
524新增: }
525新增: wasRunning = false
526新增: } else if !s.confirmUnsafe() {
527新增: s.warnf("Aborted. 'agent-vm stop', then run again.")
528新增: return errStop
529新增: }
530新增: }
531新增: switch {
532新增: case gitStale && wasRunning && !s.protect:
533新增: s.warnf("Note: VM '%s' keeps .git read-only until it stops.", s.name)
534新增: case !wasRunning && stale:
535新增: switch {
536新增: case gitStale && s.protect:
537新增: fmt.Fprintf(s.io.Stdout, "Making every .git read-only for VM '%s'...\n", s.name)
538新增: case gitStale:
539新增: s.warnf("Making .git writable for VM '%s' (%s)...", s.name, map[bool]string{true: "--unsafe-writable-git", false: "AGENT_VM_UNSAFE_WRITABLE_GIT=1"}[o.UnsafeWritableGit])
540新增: case namesStale:
541新增: fmt.Fprintf(s.io.Stdout, "Making %s read-only for VM '%s'...\n", strings.Join(s.names, ", "), s.name)
542新增: }
543新增: if gitStale || namesStale {
544新增: fmt.Fprint(s.io.Stdout, s.notes)
545新增: }
546新增: if !isNew {
547新增: switch {
548新增: case !wantWritable && !allReadOnly(inst):
549新增: fmt.Fprintf(s.io.Stdout, "Making every share of VM '%s' read-only...\n", s.name)
550新增: case wantWritable && allReadOnly(inst):
551新增: fmt.Fprintf(s.io.Stdout, "VM '%s' was left read-only by --readonly; making it writable again...\n", s.name)
552新增: }
553新增: }
554新增: if err := s.applyShares(wantWritable); err != nil {
555新增: return err
556新增: }
557新增: }
558新增:
559新增: if wasRunning {
560新增: s.notePolicyChange()
561新增: } else if err := s.boot(); err != nil {
562新增: return err
563新增: }
564新增: return s.afterBoot(isNew, wasRunning, wantWritable)
565新增:}
566新增:
567新增:// baseMarkers are the base's markers as they were when it was cloned: nil
568新增:// for one that was not there.
569新增:type baseMarkers struct{ builtBy, version []byte }
570新增:
571新增:// cloneBase clones the base template into the VM, under the base's lock: a
572新增:// setup swapping the base in is not cloned from half way. The base's markers
573新增:// are read under it too, so that they are those of the base cloned.
574新增:func (s *start) cloneBase() (baseMarkers, error) {
575新增: var m baseMarkers
576新增: b, err := s.backend()
577新增: if err != nil {
578新增: return m, err
579新增: }
580新增: unlock, err := s.lockVM(s.ctx, vmname.Template)
581新增: if err != nil {
582新增: return m, err
583新增: }
584新增: defer unlock()
585新增: if err := b.Clone(s.ctx, vmname.Template, s.name); err != nil {
586新增: return m, err
587新增: }
588新增: m.builtBy, _ = os.ReadFile(s.state.Path(state.BaseBuiltBy))
589新增: m.version, _ = os.ReadFile(s.state.Path(state.BaseVersion))
590新增: return m, nil
591新增:}
592新增:
593新增:// dropNew deletes the VM this run just made and could not set up.
594新增:func (s *start) dropNew() {
595新增: if s.deleteVM(context.WithoutCancel(s.ctx), s.name) {
596新增: s.created = false
597新增: }
598新增:}
599新增:
600新增:func isDirNoYAML(d string) bool {
601新增: if fi, err := os.Stat(d); err != nil || !fi.IsDir() {
602新增: return false
603新增: }
604新增: _, err := os.Stat(filepath.Join(d, "lima.yaml"))
605新增: return err != nil
606新增:}
607新增:
608新增:// boot starts the stopped VM, its config checked first.
609新增:func (s *start) boot() error {
610新增: if err := s.beforeBoot(); err != nil {
611新增: return err
612新增: }
613新增: // Windows: QEMU's folder on PATH (winget does not put it there), for the
614新增: // hostagent this starts.
615新增: if !host.WindowsPrereqs(s.io.Stdout, s.io.Stderr) {
616新增: return errStop
617新增: }
618新增: fmt.Fprintf(s.io.Stdout, "Starting VM '%s'...\n", s.name)
619新增: b, _ := s.backend()
620新增: var log bytes.Buffer
621新增: if err := b.Start(s.ctx, s.name, &log); err != nil {
622新增: ha := paths.Host(filepath.Join(LimaHome(s.state), s.name, "ha.stderr.log"))
623新增: s.warnf("Error: Failed to start VM '%s'.\n--- Lima's output ---\n%s%v\nFull log: %s", s.name, log.String(), err, ha)
624新增: host.WindowsStartHint(s.io.Stderr, ha)
625新增: return errStop
626新增: }
627新增: s.recordPolicy()
628新增: return nil
629新增:}
630新增:
631新增:// afterBoot brings the running VM's shares in line with the mode asked, by
632新增:// a write probe on the project (which pushes the env too), then installs
633新增:// the terminal's terminfo, runs the runtime scripts and binds single files.
634新增:func (s *start) afterBoot(isNew, wasRunning, wantWritable bool) error {
635新增: o := s.opts
636新增: guest := paths.Guest(s.dir)
637新增: var guestEnv, guestRuntime, projectRuntime, payload string
638新增: if o.Scratch {
639新增: if code, err := s.shellRun(nil, "", "sh", "-c", `sudo install -d -o "$(id -u)" -g "$(id -g)" "$1"`, "sh", guest); err != nil || code != 0 {
640新增: s.warnf("Error: could not make %s in VM '%s'.", s.dir, s.name)
641新增: return errStop
642新增: }
643新增: // Only the shared file: the project's stays out. Read as the other
644新增: // path does, a regular file only (a FIFO would block the start).
645新增: if b, ok := readRegular(s.state.Path("env")); ok {
646新增: payload = strings.TrimRight(env.StripCR(b), "\n")
647新增: }
648新增: } else {
649新增: pe := env.ProjectEnvFile(s.dir)
650新增: projectRuntime = runscript.ProjectPath(s.dir)
651新增: // By their path in the project, the one the VM has.
652新增: if rel, ok := env.ProjectRel(s.dir, pe); ok {
653新增: guestEnv = guest + "/" + rel
654新增: }
655新增: if rel, ok := env.ProjectRel(s.dir, projectRuntime); ok {
656新增: guestRuntime = guest + "/" + rel
657新增: }
658新增: payload = strings.TrimRight(env.Payload(s.state.Path("env"), s.dir), "\n")
659新增: }
660新增: probe := s.probe(payload, guestEnv, guestRuntime)
661新增: if o.Scratch && probe.writable != "true" {
662新增: s.warnf("Error: %s is not writable in VM '%s'.", s.dir, s.name)
663新增: return errStop
664新增: }
665新增: inst, _ := s.get(s.name)
666新增: want := fmt.Sprint(wantWritable)
667新增: if !o.Scratch && (probe.writable != want || !wantWritable && inst != nil && !allReadOnly(inst)) {
668新增: switch {
669新增: case probe.writable == "lost":
670新增: s.warnf("Warning: the project share is not mounted in VM '%s': what was written in %s in the VM since then is on the VM's own disk, and hidden once the share is back.", s.name, s.dir)
671新增: s.warnf("Project share is not mounted; repairing...")
672新增: case wantWritable && wasRunning && inst != nil && allReadOnly(inst):
673新增: fmt.Fprintf(s.io.Stdout, "VM '%s' runs read-only (--readonly). It must be restarted to make its shares writable.\n", s.name)
674新增: if !s.ui.CanAsk() || !s.ui.AskYN("Stop the VM and make it writable? Sessions using it are cut.", false) {
675新增: s.warnf("Error: not restarted. Pass --readonly to use it as it is, or 'agent-vm stop' it first.")
676新增: return errStop
677新增: }
678新增: case !wantWritable && wasRunning:
679新增: fmt.Fprintf(s.io.Stdout, "VM '%s' was already running. It must be restarted to make its shares read-only.\n", s.name)
680新增: if !s.ui.CanAsk() || !s.ui.AskYN("Stop the VM and apply --readonly?", false) {
681新增: // Carrying on writable after --readonly was asked for is the
682新增: // one outcome that must not be silent.
683新增: s.warnf("Error: --readonly was requested but not applied. Aborting.")
684新增: return errStop
685新增: }
686新增: case wantWritable:
687新增: s.warnf("Project mount is not writable; repairing...")
688新增: }
689新增: // Stopped for sure first: applying read-only shares while it still
690新增: // runs writable would claim what is not true.
691新增: if err := s.stopToChange(); err != nil {
692新增: return err
693新增: }
694新增: if err := s.applyShares(wantWritable); err != nil {
695新增: return err
696新增: }
697新增: if err := s.beforeBoot(); err != nil {
698新增: return err
699新增: }
700新增: b, _ := s.backend()
701新增: if err := b.Start(s.ctx, s.name, io.Discard); err != nil {
702新增: s.warnf("Error: VM '%s' did not come back up after changing the project mount.", s.name)
703新增: return errStop
704新增: }
705新增: s.recordPolicy()
706新增: if probe = s.probe(payload, guestEnv, guestRuntime); probe.writable != want {
707新增: switch {
708新增: case probe.writable == "lost":
709新增: s.warnf("Error: the project share did not mount in VM '%s':\n %s\nLima's log: %s", s.name, s.dir, filepath.Join(LimaHome(s.state), s.name, "ha.stderr.log"))
710新增: case wantWritable:
711新增: s.warnf("Error: project directory is still not writable inside the VM:\n %s\nThe host mount failed to attach. Try 'agent-vm --reset <command>'\nto re-clone the VM from the base template.", s.dir)
712新增: default:
713新增: s.warnf("Error: failed to mount the project directory read-only:\n %s", s.dir)
714新增: }
715新增: return errStop
716新增: }
717新增: }
718新增: // --readonly is claimed once every share Lima has is read-only: the
719新增: // builtin SFTP server enforces it on the host.
720新增: if o.ReadOnly {
721新增: inst, _ := s.get(s.name)
722新增: if inst == nil {
723新增: s.warnf("Error: --readonly cannot hold: could not read Lima's config for VM '%s'.", s.name)
724新增: return errStop
725新增: }
726新增: why := notReadOnly(inst)
727新增: if why == "" && !allReadOnly(inst) {
728新增: why = "no share"
729新增: }
730新增: if why != "" {
731新增: s.warnf("Error: --readonly cannot hold: VM '%s' runs with %s.", s.name, why)
732新增: return errStop
733新增: }
734新增: fmt.Fprintln(s.io.Stdout, "Read-only: the project and every other share (enforced on the host).")
735新增: }
736新增:
737新增: s.terminfo()
738新增: if _, err := os.Stat(s.state.Path("runtime.sh")); err == nil {
739新增: fmt.Fprintln(s.io.Stdout, "Running user runtime setup...")
740新增: s.runHostScript(s.state.Path("runtime.sh"))
741新增: }
742新增: switch {
743新增: case guestRuntime != "":
744新增: if probe.runtimeFound {
745新增: fmt.Fprintln(s.io.Stdout, "Running project runtime setup...")
746新增: s.shellRun(nil, guest, "zsh", "-lc", `[ -f "$3" ] || exit 0; i="$(awk "$1" "$3")" && awk "$2" "$3" | "$i" -s`,
747新增: "agent-vm", runscript.ShebangAWK, runscript.StripCRAWK, guestRuntime)
748新增: }
749新增: case projectRuntime != "" && isFile(projectRuntime):
750新增: fmt.Fprintln(s.io.Stdout, "Running project runtime setup...")
751新增: s.runHostScript(projectRuntime)
752新增: }
753新增: s.bindFiles(isNew)
754新增: return nil
755新增:}
756新增:
757新增:func isFile(p string) bool { fi, err := os.Stat(p); return err == nil && fi.Mode().IsRegular() }
758新增:
759新增:// readRegular is the content of p when it is a regular file once links are
760新增:// followed. Another kind (a FIFO, a device) is not read: it could block.
761新增:func readRegular(p string) (string, bool) {
762新增: if !isFile(p) {
763新增: return "", false
764新增: }
765新增: b, err := os.ReadFile(p)
766新增: return string(b), err == nil
767新增:}
768新增:
769新增:// runHostScript runs a runtime script the host reads in the VM, piped in,
770新增:// CRs dropped, under the shell it declares, from a login zsh: the VM's PATH
771新增:// and ~/.agent-vm.env apply.
772新增:func (s *start) runHostScript(path string) {
773新增: b, ok := readRegular(path)
774新增: if !ok {
775新增: s.warnf("Warning: could not read %s (not a regular file, or unreadable): not run.", path)
776新增: return
777新增: }
778新增: interp := runscript.Interpreter(b)
779新增: s.shellRun(strings.NewReader(env.StripCR(b)), paths.Guest(s.dir), "zsh", "-lc", "exec "+interp+" -s")
780新增:}
781新增:
782新增:// shellRun runs args in the VM, its output on the command's, and returns
783新增:// the exit status.
784新增:func (s *start) shellRun(stdin io.Reader, workdir string, args ...string) (int, error) {
785新增: b, err := s.backend()
786新增: if err != nil {
787新增: return 0, err
788新增: }
789新增: if stdin == nil {
790新增: stdin = strings.NewReader("")
791新增: }
792新增: return b.Shell(s.ctx, s.name, vm.ShellOpts{Workdir: workdir, Args: args, Stdin: stdin, Stdout: s.io.Stdout, Stderr: s.io.Stderr})
793新增:}
794新增:
795新增:// terminfo puts the host's terminfo entry in the VM, for terminals Debian
796新增:// does not know (xterm-ghostty, xterm-kitty), once per VM and $TERM.
797新增:func (s *start) terminfo() {
798新增: t := os.Getenv("TERM")
799新增: if t == "" || s.state.ReadMarker(state.TermOf, s.name) == t {
800新增: return
801新增: }
802新增: entry, err := exec.CommandContext(s.ctx, "infocmp", "-x", t).Output()
803新增: if err != nil {
804新增: return
805新增: }
806新增: b, _ := s.backend()
807新增: code, err := b.Shell(s.ctx, s.name, vm.ShellOpts{Args: []string{"sudo", "tic", "-x", "-"}, Stdin: bytes.NewReader(entry), Stdout: io.Discard, Stderr: io.Discard})
808新增: if err != nil || code != 0 {
809新增: s.warnf("Warning: failed to install '%s' terminfo inside VM.", t)
810新增: return
811新增: }
812新增: if err := s.state.Write(state.TermOf+s.name, []byte(t+"\n")); err != nil {
813新增: s.warnf("Warning: could not record that VM '%s' has the terminfo of '%s': %v", s.name, t, err)
814新增: }
815新增:}
816新增:
817新增:// bindFiles binds the single files of ~/.agent-vm/volumes in place in the
818新增:// VM, an existing VM's staged copy refreshed first, so an edit saved by
819新增:// rename on the host shows. A bind does not survive a restart, and is
820新增:// skipped when there.
821新增:func (s *start) bindFiles(isNew bool) {
822新增: b, err := os.ReadFile(s.state.Marker(state.FileMountsOf, s.name))
823新增: if err != nil {
824新增: return
825新增: }
826新增: var entries []string
827新增: for _, line := range strings.Split(strings.TrimSuffix(string(b), "\n"), "\n") {
828新增: f := strings.SplitN(line, "|", 4)
829新增: if len(f) != 4 || f[1] == "" {
830新增: continue
831新增: }
832新增: switch {
833新增: case isNew:
834新增: case !exists(f[0]):
835新增: s.warnf("Warning: Mount source '%s' no longer exists; VM will see the last-staged copy.", f[0])
836新增: case !mounts.Stage(f[0], f[1], s.io.Stderr):
837新增: s.warnf("Warning: Failed to refresh staged '%s'; VM may see stale content.", f[0])
838新增: }
839新增: if f[2] != "" && f[3] != "" {
840新增: entries = append(entries, f[2]+"|"+f[3])
841新增: }
842新增: }
843新增: if len(entries) == 0 {
844新增: return
845新增: }
846新增: fmt.Fprintln(s.io.Stdout, "Mounting individual files...")
847新增: // The paths as arguments, never in the script.
848新增: code, err := s.shellRun(nil, "", append([]string{"sudo", "bash", "-c", `
849新增: set -e
850新增: for entry in "$@"; do
851新增: bind_src="${entry%%|*}"
852新增: bind_dst="${entry#*|}"
853新增: if ! findmnt -no TARGET "$bind_dst" >/dev/null 2>&1; then
854新增: mkdir -p "$(dirname "$bind_dst")" && touch "$bind_dst"
855新增: mount --bind "$bind_src" "$bind_dst"
856新增: mount -o remount,ro,bind "$bind_dst"
857新增: fi
858新增: done
859新增: `, "--"}, entries...)...)
860新增: if err != nil {
861新增: s.warnf("Warning: could not bind the single files of ~/.agent-vm/volumes in VM '%s': %v", s.name, err)
862新增: } else if code != 0 {
863新增: s.warnf("Warning: binding the single files of ~/.agent-vm/volumes in VM '%s' failed (status %d).", s.name, code)
864新增: }
865新增:}
866新增:
867新增:func exists(p string) bool { _, err := os.Stat(p); return err == nil }
新增internal/cli/start_test.go+815 −0看文件
@@ -0,0 +1,815 @@
1新增:package cli
2新增:
3新增:import (
4新增: "context"
5新增: "errors"
6新增: "fmt"
7新增: "io"
8新增: "os"
9新增: "os/exec"
10新增: "path/filepath"
11新增: "strings"
12新增: "testing"
13新增:
14新增: "github.com/sylvinus/agent-vm/internal/paths"
15新增: "github.com/sylvinus/agent-vm/internal/state"
16新增: "github.com/sylvinus/agent-vm/internal/vm"
17新增: "github.com/sylvinus/agent-vm/internal/vm/vmtest"
18新增: "github.com/sylvinus/agent-vm/internal/vmname"
19新增:)
20新增:
21新增:// guest answers like a VM: the probe by its shares (lost when the test says
22新增:// so), the rest by running nothing.
23新增:type guest struct {
24新增: fake *vmtest.Fake
25新增: lost bool
26新增: payloads []string
27新增: ran [][]string
28新增:}
29新增:
30新增:func (g *guest) shell(name string, o vm.ShellOpts) int {
31新增: if len(o.Args) > 2 && o.Args[0] == "sh" && o.Args[2] == probeScript {
32新增: b, _ := io.ReadAll(o.Stdin)
33新增: g.payloads = append(g.payloads, string(b))
34新增: fmt.Fprintln(o.Stdout, "env-ok")
35新增: if o.Args[6] != "" && !g.lost {
36新增: fmt.Fprintln(o.Stdout, "share-ok")
37新增: }
38新增: v := g.fake.VMs[name]
39新增: if g.lost || v == nil || len(v.Mounts) == 0 && !strings.Contains(name, "scratch") || len(v.Mounts) > 0 && !v.Mounts[0].Writable {
40新增: return 1
41新增: }
42新增: return 0
43新增: }
44新增: g.ran = append(g.ran, append([]string{o.Workdir}, o.Args...))
45新增: return 0
46新增:}
47新增:
48新增:type startEnv struct {
49新增: *testEnv
50新增: g *guest
51新增: home, proj string
52新增:}
53新增:
54新增:func newStartEnv(t *testing.T, answers ...string) *startEnv {
55新增: t.Helper()
56新增: if _, err := exec.LookPath("git"); err != nil {
57新增: t.Skip("no git")
58新增: }
59新增: home, _ := filepath.EvalSymlinks(t.TempDir())
60新增: // Host-spelled, as AbsDir spells the callers' folders: mixed
61新增: // separators never compare on Windows.
62新增: home = paths.Host(home)
63新增: t.Setenv("HOME", home)
64新增: // Go reads the home from USERPROFILE on Windows, not HOME.
65新增: t.Setenv("USERPROFILE", home)
66新增: t.Setenv("GIT_CONFIG_NOSYSTEM", "1")
67新增: os.Unsetenv("GIT_CONFIG_GLOBAL")
68新增: os.Unsetenv("XDG_CONFIG_HOME")
69新增: // On Windows the temporary folder is under LOCALAPPDATA, which no project may be in.
70新增: t.Setenv("APPDATA", "")
71新增: t.Setenv("LOCALAPPDATA", "")
72新增: t.Setenv("AGENT_VM_UNSAFE_WRITABLE_GIT", "")
73新增: t.Setenv("AGENT_VM_UNSAFE_DISABLE_SECURITY_PROMPTS", "")
74新增: t.Setenv("AGENT_VM_SSHFS_CACHE", "")
75新增: t.Setenv("TERM", "")
76新增: os.WriteFile(filepath.Join(home, ".gitconfig"), []byte("[safe]\n\tbareRepository = explicit\n"), 0o644)
77新增: proj := home + "/proj"
78新增: os.MkdirAll(proj, 0o755)
79新增: t.Chdir(proj)
80新增: t.Setenv("PWD", proj)
81新增: fake := vmtest.New()
82新增: g := &guest{fake: fake}
83新增: fake.ShellFunc = g.shell
84新增: te := newTestEnv(t, fake, answers...)
85新增: te.state = state.Dir(home + "/.agent-vm")
86新增: os.MkdirAll(string(te.state), 0o755)
87新增: return &startEnv{testEnv: te, g: g, home: home, proj: proj}
88新增:}
89新增:
90新增:func (se *startEnv) base() {
91新增: se.fake.VMs[vmname.Template] = &vm.Instance{Name: vmname.Template, Status: vm.Stopped, CPUs: 1, Memory: 3 << 30, Disk: 10 << 30}
92新增: os.WriteFile(se.state.Path(state.BaseVersion), []byte("1759000000\n"), 0o644)
93新增: os.WriteFile(se.state.Path(state.BaseBuiltBy), []byte("0.3.0\n"), 0o644)
94新增:}
95新增:
96新增:func TestStartNoBase(t *testing.T) {
97新增: se := newStartEnv(t)
98新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "Error: Base VM not found. Run 'agent-vm setup' first.") {
99新增: t.Errorf("no base: %s", se.out())
100新增: }
101新增: se.fake.VMs[vmname.Template] = &vm.Instance{Name: vmname.Template, Status: vm.Stopped}
102新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "Base VM setup did not complete") {
103新增: t.Errorf("base without its marker: %s", se.out())
104新增: }
105新增:}
106新增:
107新增:func TestStartNewVM(t *testing.T) {
108新增: se := newStartEnv(t)
109新增: se.base()
110新增: os.WriteFile(se.state.Path("env"), []byte("TOKEN='x'\r\n"), 0o600)
111新增: name := vmname.Name(se.proj)
112新增: if code := se.run("run", "echo", "hi"); code != 0 {
113新增: t.Fatalf("run: %d %s", code, se.out())
114新增: }
115新增: if !strings.HasPrefix(se.fake.CallLog(), "clone base "+name+"\nedit "+name+"\nedit "+name+"\nstart "+name) {
116新增: t.Errorf("calls:\n%s", se.fake.CallLog())
117新增: }
118新增: v := se.fake.VMs[name]
119新增: if v.Status != vm.Running || v.MountType != vm.ReverseSSHFS || len(v.Mounts) != 1 || !v.Mounts[0].Writable ||
120新增: v.Mounts[0].SSHFS == nil || strings.Join(v.Mounts[0].SSHFS.ReadonlyNames, ",") != ".git,.hg,.sl,.jj" || v.Mounts[0].SSHFS.Cache == nil || *v.Mounts[0].SSHFS.Cache {
121新增: t.Errorf("VM: %+v %+v", v, v.Mounts)
122新增: }
123新增: if len(se.g.payloads) != 1 || se.g.payloads[0] != "TOKEN='x'\n" {
124新增: t.Errorf("payload: %q", se.g.payloads)
125新增: }
126新增: last := se.g.ran[len(se.g.ran)-1]
127新增: if last[0] != paths.Guest(se.proj) || last[1] != "zsh" || last[len(last)-2] != "echo" || last[len(last)-1] != "hi" {
128新增: t.Errorf("command: %q", last)
129新增: }
130新增: for _, m := range []string{state.VersionOf, state.BuiltByOf} {
131新增: if _, err := os.Stat(se.state.Marker(m, name)); err != nil {
132新增: t.Errorf("marker %s not recorded", m)
133新增: }
134新增: }
135新增: // Again: nothing to change, nothing restarted.
136新增: se.run("run", "true")
137新增: if strings.Contains(se.fake.CallLog(), "edit") || strings.Contains(se.fake.CallLog(), "start") || strings.Contains(se.fake.CallLog(), "stop") {
138新增: t.Errorf("second run changed the VM:\n%s", se.fake.CallLog())
139新增: }
140新增: // --rm: deleted after.
141新增: if se.run("--rm", "run", "true") != 0 || se.fake.VMs[name] != nil || !strings.Contains(se.out(), "VM destroyed.") {
142新增: t.Errorf("--rm: %s", se.out())
143新增: }
144新增:}
145新增:
146新增:// The resources asked against the VM's: in bytes, the disk one way (it
147新增:// only grows), a VM that cannot be read counts as a change.
148新增:func TestResourcesDiffer(t *testing.T) {
149新增: inst := &vm.Instance{CPUs: 2, Memory: 4 << 30, Disk: 20 << 30}
150新增: for _, c := range []struct {
151新增: o VMOpts
152新增: want bool
153新增: }{
154新增: {VMOpts{}, false},
155新增: {VMOpts{CPUs: 2, Memory: 4, Disk: 20}, false},
156新增: {VMOpts{CPUs: 3}, true},
157新增: {VMOpts{Memory: 5}, true},
158新增: {VMOpts{Disk: 10}, false},
159新增: {VMOpts{Disk: 30}, true},
160新增: } {
161新增: s := &start{opts: c.o}
162新增: if got := s.resourcesDiffer(inst); got != c.want {
163新增: t.Errorf("%+v: %v", c.o, got)
164新增: }
165新增: }
166新增: if !(&start{opts: VMOpts{CPUs: 2}}).resourcesDiffer(nil) {
167新增: t.Error("an unknown VM is no change")
168新增: }
169新增: // Half a GiB more than asked: a change.
170新增: if !(&start{opts: VMOpts{Memory: 4}}).resourcesDiffer(&vm.Instance{Memory: 4<<30 + 1<<29}) {
171新增: t.Error("compared in whole GiB")
172新增: }
173新增:}
174新增:
175新增:// A folder left without lima.yaml by an interrupted creation is cleaned up.
176新增:func TestStartPartialVM(t *testing.T) {
177新增: se := newStartEnv(t)
178新增: se.base()
179新增: d := filepath.Join(LimaHome(se.state), vmname.Name(se.proj))
180新增: os.MkdirAll(d, 0o755)
181新增: os.WriteFile(filepath.Join(d, "basedisk"), nil, 0o644)
182新增: if se.run("run", "true") != 0 || !strings.Contains(se.out(), "Detected partial VM state at "+d) {
183新增: t.Errorf("partial: %s", se.out())
184新增: }
185新增: if _, err := os.Stat(filepath.Join(d, "basedisk")); err == nil {
186新增: t.Error("left")
187新增: }
188新增:}
189新增:
190新增:// --ssh-port: set before the first start, not set again when unchanged, 0
191新增:// back to Lima's choice; a port another VM has is refused.
192新增:func TestStartSSHPort(t *testing.T) {
193新增: se := newStartEnv(t)
194新增: se.base()
195新增: name := vmname.Name(se.proj)
196新增: se.fake.VMs["other-00000000"] = &vm.Instance{Name: "other-00000000", Status: vm.Stopped, SSHPortConfig: 2222}
197新增: if se.run("--ssh-port", "2222", "run", "true") != 1 || !strings.Contains(se.out(), "SSH port 2222 is already set for VM 'other-00000000'") || se.fake.CallLog() != "" {
198新增: t.Errorf("taken: %s\n%s", se.out(), se.fake.CallLog())
199新增: }
200新增: if se.run("--ssh-port", "2223", "run", "true") != 0 || se.fake.VMs[name].SSHPortConfig != 2223 ||
201新增: strings.Index(se.fake.CallLog(), "start ") < strings.LastIndex(se.fake.CallLog(), "edit ") {
202新增: t.Errorf("new VM: %s\n%s", se.out(), se.fake.CallLog())
203新增: }
204新增: se.fake.VMs[name].Status = vm.Stopped
205新增: if se.run("--ssh-port", "2223", "run", "true") != 0 || strings.Contains(se.fake.CallLog(), "edit") {
206新增: t.Errorf("unchanged: %s\n%s", se.out(), se.fake.CallLog())
207新增: }
208新增: se.fake.VMs[name].Status = vm.Stopped
209新增: if se.run("--ssh-port", "0", "run", "true") != 0 || se.fake.VMs[name].SSHPortConfig != 0 {
210新增: t.Errorf("0: %s\n%s", se.out(), se.fake.CallLog())
211新增: }
212新增:}
213新增:
214新增:// A new VM that cannot be configured is deleted, never started, nothing
215新增:// recorded; --reset that cannot delete changes nothing.
216新增:func TestStartFailures(t *testing.T) {
217新增: se := newStartEnv(t)
218新增: se.base()
219新增: name := vmname.Name(se.proj)
220新增: for _, op := range []string{"clone", "edit"} {
221新增: se.fake.FailOn = map[string]error{op: errors.New("no")}
222新增: if se.run("run", "true") != 1 || strings.Contains(se.fake.CallLog(), "start") || se.fake.VMs[name] != nil {
223新增: t.Errorf("%s fails: %s\n%s", op, se.out(), se.fake.CallLog())
224新增: }
225新增: if _, err := os.Stat(se.state.Marker(state.VersionOf, name)); err == nil {
226新增: t.Errorf("%s fails: recorded", op)
227新增: }
228新增: }
229新增: se.fake.FailOn = nil
230新增: if se.run("run", "true") != 0 {
231新增: t.Fatalf("run: %s", se.out())
232新增: }
233新增: se.fake.FailOn = map[string]error{"delete": errors.New("no")}
234新增: se.fake.Sticky[name] = true
235新增: if se.run("--reset", "run", "true") != 1 || strings.Contains(se.fake.CallLog(), "clone") {
236新增: t.Errorf("--reset, delete fails: %s\n%s", se.out(), se.fake.CallLog())
237新增: }
238新增: se.fake.FailOn, se.fake.Sticky = nil, map[string]bool{}
239新增: if se.run("--reset", "run", "true") != 0 || !strings.Contains(se.out(), "Resetting VM") || !strings.Contains(se.fake.CallLog(), "delete "+name+"\nclone ") {
240新增: t.Errorf("--reset: %s\n%s", se.out(), se.fake.CallLog())
241新增: }
242新增:}
243新增:
244新增:// A VM from a 0.1.0 base (no record of what built it): told how to replace
245新增:// it, not started; --reset does.
246新增:func TestStartFrom01(t *testing.T) {
247新增: se := newStartEnv(t)
248新增: se.base()
249新增: name := vmname.Name(se.proj)
250新增: se.fake.VMs[name] = &vm.Instance{Name: name, Status: vm.Stopped}
251新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "comes from a base built by agent-vm 0.1.0") || se.fake.CallLog() != "" {
252新增: t.Errorf("0.1.0: %s\n%s", se.out(), se.fake.CallLog())
253新增: }
254新增: if se.run("--reset", "run", "true") != 0 {
255新增: t.Errorf("--reset: %s", se.out())
256新增: }
257新增:}
258新增:
259新增:func TestStartRefusesHome(t *testing.T) {
260新增: se := newStartEnv(t)
261新增: se.base()
262新增: // Go reads the home from USERPROFILE on Windows, not HOME.
263新增: t.Setenv("USERPROFILE", se.home)
264新增: t.Chdir(se.home)
265新增: t.Setenv("PWD", se.home)
266新增: if se.run("shell") != 1 || !strings.Contains(se.out(), "refusing to share "+se.home+" with a VM: it is, or contains, your home directory") {
267新增: t.Errorf("home: %s", se.out())
268新增: }
269新增: if strings.Contains(se.fake.CallLog(), "clone") {
270新增: t.Error("cloned anyway")
271新增: }
272新增: // The user's own Lima home: its _config/user key logs into their VMs.
273新增: key := filepath.Join(se.home, ".lima", "_config")
274新增: os.MkdirAll(key, 0o755)
275新增: t.Chdir(key)
276新增: t.Setenv("PWD", key)
277新增: if se.run("shell") != 1 || !strings.Contains(se.out(), "is inside Lima's state") {
278新增: t.Errorf("~/.lima: %s", se.out())
279新增: }
280新增:}
281新增:
282新增:// agent-vm's own folder: refused, shared under
283新增:// --unsafe-disable-security-prompts. The home directory stays refused.
284新增:func TestStartSelfDir(t *testing.T) {
285新增: se := newStartEnv(t)
286新增: se.base()
287新增: exe, err := os.Executable()
288新增: if err != nil {
289新增: t.Skip(err)
290新增: }
291新增: exe, _ = filepath.EvalSymlinks(exe)
292新增: self := paths.Host(filepath.Dir(exe))
293新增: t.Chdir(self)
294新增: t.Setenv("PWD", self)
295新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "it is, or contains, agent-vm itself") {
296新增: t.Errorf("self: %s", se.out())
297新增: }
298新增: if strings.Contains(se.fake.CallLog(), "clone") {
299新增: t.Error("cloned anyway")
300新增: }
301新增: if se.run("--unsafe-disable-security-prompts", "run", "true") != 0 ||
302新增: !strings.Contains(se.out(), "Warning: sharing "+self+" with the VM: it is, or contains, agent-vm itself") ||
303新增: !strings.Contains(se.out(), "Continuing: --unsafe-disable-security-prompts.") {
304新增: t.Errorf("self, prompts off: %s", se.out())
305新增: }
306新增: t.Setenv("USERPROFILE", se.home)
307新增: t.Chdir(se.home)
308新增: t.Setenv("PWD", se.home)
309新增: if se.run("--unsafe-disable-security-prompts", "shell") != 1 || !strings.Contains(se.out(), "your home directory") {
310新增: t.Errorf("home, prompts off: %s", se.out())
311新增: }
312新增:}
313新增:
314新增:func TestStartReadonly(t *testing.T) {
315新增: se := newStartEnv(t)
316新增: se.base()
317新增: if se.run("--readonly", "run", "true") != 0 || !strings.Contains(se.out(), "Read-only: the project and every other share (enforced on the host).") {
318新增: t.Fatalf("--readonly: %s", se.out())
319新增: }
320新增: name := vmname.Name(se.proj)
321新增: if v := se.fake.VMs[name]; v.Mounts[0].Writable {
322新增: t.Error("writable under --readonly")
323新增: }
324新增: // An rw volume too: read-only, said so. Host-spelled: entries spell
325新增: // their sources so.
326新增: vol := paths.Host(filepath.Join(t.TempDir(), "vol"))
327新增: os.MkdirAll(vol, 0o755)
328新增: os.WriteFile(se.state.Path("volumes"), []byte(vol+":/mnt/vol:rw\n"), 0o644)
329新增: se.fake.VMs[name].Status = vm.Stopped
330新增: if se.run("--readonly", "run", "true") != 0 || !strings.Contains(se.out(), "Note: --readonly: '"+vol+"' (rw in ~/.agent-vm/volumes) is mounted read-only too.") {
331新增: t.Fatalf("--readonly with an rw volume: %s", se.out())
332新增: }
333新增: for _, m := range se.fake.VMs[name].Mounts {
334新增: if m.Writable {
335新增: t.Errorf("writable under --readonly: %+v", m)
336新增: }
337新增: }
338新增: os.Remove(se.state.Path("volumes"))
339新增: se.fake.VMs[name].Status = vm.Stopped
340新增: se.run("--readonly", "run", "true")
341新增: // Back to writable: the running read-only VM is asked before a restart;
342新增: // no terminal, refused.
343新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "not restarted") {
344新增: t.Errorf("writable again, no terminal: %s", se.out())
345新增: }
346新增: se2 := &startEnv{testEnv: newTestEnv(t, se.fake, "y\n"), g: se.g, home: se.home, proj: se.proj}
347新增: se2.state = se.state
348新增: if se2.run("run", "true") != 0 || !se.fake.VMs[name].Mounts[0].Writable {
349新增: t.Errorf("writable again, yes: %s\n%s", se2.out(), se.fake.CallLog())
350新增: }
351新增:}
352新增:
353新增:// beforeBoot holds every check that applies: --readonly with .git
354新增:// protected refuses a protected share left writable.
355新增:func TestBeforeBootAll(t *testing.T) {
356新增: se := newStartEnv(t)
357新增: se.base()
358新增: if se.run("run", "true") != 0 {
359新增: t.Fatal(se.out())
360新增: }
361新增: name := vmname.Name(se.proj)
362新增: se.fake.VMs[name].Status = vm.Stopped
363新增: s := &start{app: se.app, ctx: context.Background(), name: name, opts: VMOpts{ReadOnly: true}, protect: true, names: []string{".git", ".hg"}}
364新增: if s.beforeBoot() == nil || !strings.Contains(se.stderr.String(), "a writable share of "+se.proj) {
365新增: t.Errorf("--readonly, protected, writable: %s", se.out())
366新增: }
367新增: s.opts.ReadOnly = false
368新增: if s.beforeBoot() != nil {
369新增: t.Errorf("writable asked: %s", se.out())
370新增: }
371新增:}
372新增:
373新增:// The verdicts on a VM's shares: confined first, then the names or the
374新增:// read-only mode.
375新增:func TestShareVerdicts(t *testing.T) {
376新增: b := func(names ...string) *vm.SSHFS { return &vm.SSHFS{SFTPDriver: "builtin", ReadonlyNames: names} }
377新增: inst := func(mt string, ms ...vm.Mount) *vm.Instance { return &vm.Instance{MountType: mt, Mounts: ms} }
378新增: rs := vm.ReverseSSHFS
379新增: for _, c := range []struct {
380新增: inst *vm.Instance
381新增: names []string
382新增: unprot, notRO string
383新增: }{
384新增: {inst(rs, vm.Mount{Location: "/p", SSHFS: b(".git", ".hg")}), []string{".git"}, "", ""},
385新增: {inst(rs, vm.Mount{Location: "/p", SSHFS: b(".git", ".hg", "tools")}), []string{".git", ".hg"}, "", ""},
386新增: {inst(rs, vm.Mount{Location: "/p", SSHFS: b(".git")}), []string{".git", "tools"}, "lacks the read-only names", ""},
387新增: {inst(rs, vm.Mount{Location: "/p", SSHFS: b()}), nil, "lacks the read-only names", ""},
388新增: {inst(rs, vm.Mount{Location: "/p", Writable: true, SSHFS: b(".git", ".hg", ".sl", ".jj")}), nil, "", "a writable share of /p"},
389新增: {inst(rs, vm.Mount{Location: "/p", SSHFS: b("tools")}), nil, "lacks the read-only names", ""},
390新增: {inst(rs, vm.Mount{Location: "/p", SSHFS: &vm.SSHFS{ReadonlyNames: []string{".git"}}}), nil, "not served by the builtin SFTP server", "not served by the builtin SFTP server"},
391新增: {inst("9p", vm.Mount{Location: "/p", SSHFS: b(".git")}), nil, "the mount type", "the mount type"},
392新增: } {
393新增: if got := unprotected(c.inst, c.names); c.unprot == "" && got != "" || !strings.Contains(got, c.unprot) {
394新增: t.Errorf("unprotected %+v %v: %q", c.inst.Mounts, c.names, got)
395新增: }
396新增: if got := notReadOnly(c.inst); c.notRO == "" && got != "" || !strings.Contains(got, c.notRO) {
397新增: t.Errorf("notReadOnly %+v: %q", c.inst.Mounts, got)
398新增: }
399新增: }
400新增:}
401新增:
402新增:// Lima's own config: its override files refuse everything; a VM config it
403新增:// cannot read is said, nothing touched.
404新增:func TestStartLimaConfig(t *testing.T) {
405新增: se := newStartEnv(t)
406新增: se.base()
407新增: name := vmname.Name(se.proj)
408新增: if se.run("run", "true") != 0 {
409新增: t.Fatalf("first run: %s", se.out())
410新增: }
411新增: cfg := paths.Host(filepath.Join(se.home, ".agent-vm", "lima", "_config"))
412新增: os.MkdirAll(cfg, 0o755)
413新增: os.WriteFile(cfg+"/default.yaml", []byte("cpus: 8\n"), 0o644)
414新增: se.fake.Calls = nil
415新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), cfg+"/default.yaml adds to every VM's config") || se.fake.CallLog() != "" {
416新增: t.Errorf("default.yaml: %s\n%s", se.out(), se.fake.CallLog())
417新增: }
418新增: os.Remove(cfg + "/default.yaml")
419新增: se.fake.VMs[name].Status, se.fake.VMs[name].ConfigErr = vm.Broken, errors.New("field `mounts[1].sshfs.sftpDriver` must be `builtin`")
420新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "Lima cannot read the config of VM '"+name+"':\n field `mounts[1]") {
421新增: t.Errorf("unreadable: %s", se.out())
422新增: }
423新增: if strings.Contains(se.fake.CallLog(), "start") || strings.Contains(se.fake.CallLog(), "edit") {
424新增: t.Errorf("touched:\n%s", se.fake.CallLog())
425新增: }
426新增:}
427新增:
428新增:// More of the hooks and config questions at start.
429新增:func TestStartHooksCases(t *testing.T) {
430新增: se := newStartEnv(t)
431新增: se.base()
432新增: name := vmname.Name(se.proj)
433新增: git := func(args ...string) { exec.Command("git", append([]string{"-C", se.proj}, args...)...).Run() }
434新增: git("init", "-q")
435新增: names := func() string { return strings.Join(se.fake.VMs[name].Mounts[0].SSHFS.ReadonlyNames, ",") }
436新增:
437新增: // A plain name, no terminal: protected (yes by default), started.
438新增: git("config", "core.hooksPath", "tools/hooks")
439新增: if se.run("run", "true") != 0 || names() != ".git,.hg,.sl,.jj,tools" {
440新增: t.Errorf("plain name, no terminal: %s", se.out())
441新增: }
442新增: // A name the shares cannot carry: aborted without a terminal, nothing
443新增: // touched; running, only warned.
444新增: git("config", "core.hooksPath", `a"b/x`)
445新增: se.fake.VMs[name].Status = vm.Stopped
446新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "Aborted.") || se.fake.CallLog() != "" {
447新增: t.Errorf("bad name: %s\n%s", se.out(), se.fake.CallLog())
448新增: }
449新增: se.fake.VMs[name].Status = vm.Running
450新增: if se.run("run", "true") != 0 || !strings.Contains(se.out(), "Warning: git's core.hooksPath is") || strings.Contains(se.fake.CallLog(), "stop") {
451新增: t.Errorf("bad name, running: %s\n%s", se.out(), se.fake.CallLog())
452新增: }
453新增: // --readonly: nothing asked, the hooks names still given.
454新增: git("config", "core.hooksPath", "tools/hooks")
455新增: git("config", "core.fsmonitor", "./mon.sh")
456新增: se.fake.VMs[name].Status = vm.Stopped
457新增: if se.run("--readonly", "run", "true") != 0 || strings.Contains(se.out(), "Warning: git on this machine uses these") || names() != ".git,.hg,.sl,.jj,tools" {
458新增: t.Errorf("--readonly: %s %s", se.out(), names())
459新增: }
460新增: // A config risk alone: aborted without a terminal, nothing touched.
461新增: git("config", "--unset", "core.hooksPath")
462新增: se.fake.VMs[name].Status = vm.Stopped
463新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "core.fsmonitor = ./mon.sh") || se.fake.CallLog() != "" {
464新增: t.Errorf("config risk: %s\n%s", se.out(), se.fake.CallLog())
465新增: }
466新增: git("config", "--unset", "core.fsmonitor")
467新增: // sshfs's cache: on with AGENT_VM_SSHFS_CACHE=1, off again without; a
468新增: // running VM differing only by it is left alone.
469新增: cache := func() bool { c := se.fake.VMs[name].Mounts[0].SSHFS.Cache; return c == nil || *c }
470新增: t.Setenv("AGENT_VM_SSHFS_CACHE", "1")
471新增: se.fake.VMs[name].Status = vm.Stopped
472新增: if se.run("run", "true") != 0 || !cache() {
473新增: t.Errorf("cache on: %s", se.out())
474新增: }
475新增: t.Setenv("AGENT_VM_SSHFS_CACHE", "")
476新增: if se.run("run", "true") != 0 || strings.Contains(se.fake.CallLog(), "stop") || strings.Contains(se.out(), "Warning") {
477新增: t.Errorf("running, cache differs: %s\n%s", se.out(), se.fake.CallLog())
478新增: }
479新增: se.fake.VMs[name].Status = vm.Stopped
480新增: if se.run("run", "true") != 0 || cache() {
481新增: t.Errorf("cache off: %s", se.out())
482新增: }
483新增:}
484新增:
485新增:// Hooks in a writable volume inside the project: no name covers them, so a
486新增:// risk to accept, not a name.
487新增:func TestStartHooksInVolume(t *testing.T) {
488新增: se := newStartEnv(t)
489新增: se.base()
490新增: exec.Command("git", "-C", se.proj, "init", "-q").Run()
491新增: exec.Command("git", "-C", se.proj, "config", "core.hooksPath", ".husky/_").Run()
492新增: os.MkdirAll(filepath.Join(se.proj, ".husky", "_"), 0o755)
493新增: os.WriteFile(se.state.Path("volumes"), []byte(filepath.Join(se.proj, ".husky")+":/mnt/husky:rw\n"), 0o644)
494新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "core.hooksPath is '.husky/_', which the VM can write, and no read-only name covers it") ||
495新增: !strings.Contains(se.out(), "Aborted.") {
496新增: t.Errorf("hooks in a volume: %s", se.out())
497新增: }
498新增:}
499新增:
500新增:func TestStartHooksQuestions(t *testing.T) {
501新增: se := newStartEnv(t)
502新增: se.base()
503新增: exec.Command("git", "-C", se.proj, "init", "-q").Run()
504新增: exec.Command("git", "-C", se.proj, "config", "core.hooksPath", ".").Run()
505新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "core.hooksPath is the project directory itself") || !strings.Contains(se.out(), "Aborted.") {
506新增: t.Errorf("hooks '.': %s", se.out())
507新增: }
508新增: if se.fake.CallLog() != "" {
509新增: t.Errorf("touched before the abort: %s", se.fake.CallLog())
510新增: }
511新增: if se.run("--unsafe-disable-security-prompts", "run", "true") != 0 || !strings.Contains(se.out(), "Continuing: --unsafe-disable-security-prompts.") {
512新增: t.Errorf("prompts off: %s", se.out())
513新增: }
514新增: // A plain name, asked; a yes protects it.
515新增: exec.Command("git", "-C", se.proj, "config", "core.hooksPath", "tools/hooks").Run()
516新增: se.fake.VMs[vmname.Name(se.proj)].Status = vm.Stopped
517新增: se3 := &startEnv{testEnv: newTestEnv(t, se.fake, "y\n"), g: se.g, home: se.home, proj: se.proj}
518新增: se3.state = se.state
519新增: if se3.run("run", "true") != 0 || strings.Join(se.fake.VMs[vmname.Name(se.proj)].Mounts[0].SSHFS.ReadonlyNames, ",") != ".git,.hg,.sl,.jj,tools" {
520新增: t.Errorf("tools: %s %+v", se3.out(), se.fake.VMs[vmname.Name(se.proj)].Mounts)
521新增: }
522新增: if !strings.Contains(se3.out(), "Making .git, .hg, .sl, .jj, tools read-only for VM") || !strings.Contains(se3.out(), "every 'tools' in the project is read-only") {
523新增: t.Errorf("not said: %s", se3.out())
524新增: }
525新增: // Declined: what is under tools is a risk again, said with the hooks.
526新增: exec.Command("git", "-C", se.proj, "config", "core.fsmonitor", "tools/fsmon.sh").Run()
527新增: se.fake.VMs[vmname.Name(se.proj)].Status = vm.Stopped
528新增: se4 := &startEnv{testEnv: newTestEnv(t, se.fake, "n\n", "y\n", "n\n"), g: se.g, home: se.home, proj: se.proj}
529新增: se4.state = se.state
530新增: if se4.run("run", "true") != 1 || !strings.Contains(se4.out(), "'tools' stays writable") || !strings.Contains(se4.out(), "core.fsmonitor = tools/fsmon.sh") {
531新增: t.Errorf("declined: %s", se4.out())
532新增: }
533新增:}
534新增:
535新增:func TestStartBareRepo(t *testing.T) {
536新增: se := newStartEnv(t)
537新增: se.base()
538新增: os.WriteFile(filepath.Join(se.home, ".gitconfig"), nil, 0o644)
539新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "Git: repositories not named .git") || !strings.Contains(se.out(), "Aborted. Run the command above") {
540新增: t.Errorf("bare repo, no terminal: %s", se.out())
541新增: }
542新增: se2 := &startEnv{testEnv: newTestEnv(t, se.fake, "y\n"), g: se.g, home: se.home, proj: se.proj}
543新增: se2.state = se.state
544新增: if se2.run("run", "true") != 0 || !strings.Contains(se2.out(), "now ignores repositories not named .git") {
545新增: t.Errorf("bare repo, yes: %s", se2.out())
546新增: }
547新增: if b, _ := os.ReadFile(filepath.Join(se.home, ".gitconfig")); !strings.Contains(string(b), "bareRepository = explicit") {
548新增: t.Errorf("global config: %q", b)
549新增: }
550新增: name := vmname.Name(se.proj)
551新增: unset := func() {
552新增: os.WriteFile(filepath.Join(se.home, ".gitconfig"), nil, 0o644)
553新增: se.fake.VMs[name].Status = vm.Stopped
554新增: }
555新增: asked := func(answers ...string) *startEnv {
556新增: s := &startEnv{testEnv: newTestEnv(t, se.fake, answers...), g: se.g, home: se.home, proj: se.proj}
557新增: s.state = se.state
558新增: return s
559新增: }
560新增: // No, then no: aborted, nothing set.
561新增: unset()
562新增: if s := asked("n\n", "n\n"); s.run("run", "true") != 1 || !strings.Contains(s.out(), "Warning: not set.") || !strings.Contains(s.out(), "Aborted. Run the command above") {
563新增: t.Errorf("no, no: %s", s.out())
564新增: }
565新增: // No, then go on anyway.
566新增: if s := asked("n\n", "y\n"); s.run("run", "true") != 0 || !strings.Contains(s.out(), "Warning: not set.") {
567新增: t.Errorf("no, yes: %s", s.out())
568新增: }
569新增: if b, _ := os.ReadFile(filepath.Join(se.home, ".gitconfig")); len(b) != 0 {
570新增: t.Errorf("set although declined: %q", b)
571新增: }
572新增: // Questions off: nothing set, said so.
573新增: unset()
574新增: if se.run("--unsafe-disable-security-prompts", "run", "true") != 0 || !strings.Contains(se.out(), "Continuing") {
575新增: t.Errorf("prompts off: %s", se.out())
576新增: }
577新增: if b, _ := os.ReadFile(filepath.Join(se.home, ".gitconfig")); len(b) != 0 {
578新增: t.Errorf("set with prompts off: %q", b)
579新增: }
580新增: // Running: a warning, no question.
581新增: se.fake.VMs[name].Status = vm.Running
582新增: if se.run("run", "true") != 0 || !strings.Contains(se.out(), "Warning: git on this machine uses repositories a VM creates") {
583新增: t.Errorf("running: %s", se.out())
584新增: }
585新增: // --readonly: the VM writes nothing, nothing asked.
586新增: unset()
587新增: if se.run("--readonly", "run", "true") != 0 || strings.Contains(se.out(), "repositories not named .git") {
588新增: t.Errorf("--readonly: %s", se.out())
589新增: }
590新增: // A yes that git cannot apply: said so, then asked to go on.
591新增: unset()
592新增: os.Remove(filepath.Join(se.home, ".gitconfig"))
593新增: os.MkdirAll(filepath.Join(se.home, ".gitconfig"), 0o755)
594新增: // A .gitconfig git cannot read is a risk of its own, asked first.
595新增: if s := asked("y\n", "y\n", "n\n"); s.run("run", "true") != 1 || !strings.Contains(s.out(), "Warning: the setting did not take.") {
596新增: t.Errorf("did not take: %s", s.out())
597新增: }
598新增:}
599新增:
600新增:func TestStartRepairsLostShare(t *testing.T) {
601新增: se := newStartEnv(t)
602新增: se.base()
603新增: se.run("run", "true")
604新增: se.g.lost = true
605新增: code := se.run("run", "true")
606新增: if code != 1 || !strings.Contains(se.out(), "the project share is not mounted") || !strings.Contains(se.out(), "did not mount") {
607新增: t.Errorf("lost, stays lost: %d %s", code, se.out())
608新增: }
609新增: if !strings.Contains(se.fake.CallLog(), "stop "+vmname.Name(se.proj)) {
610新增: t.Errorf("not restarted: %s", se.fake.CallLog())
611新增: }
612新增:}
613新增:
614新增:func TestStartOlderNames(t *testing.T) {
615新增: se := newStartEnv(t)
616新增: se.base()
617新增: se.run("run", "true")
618新增: exec.Command("git", "-C", se.proj, "init", "-q").Run()
619新增: exec.Command("git", "-C", se.proj, "config", "core.hooksPath", ".husky/_").Run()
620新增: // Running, no terminal: a risk to accept, refused by default.
621新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "runs with an older list of read-only names (it needs .git, .hg, .sl, .jj, .husky)") {
622新增: t.Errorf("older names: %s", se.out())
623新增: }
624新增: se2 := &startEnv{testEnv: newTestEnv(t, se.fake, "y\n"), g: se.g, home: se.home, proj: se.proj}
625新增: se2.state = se.state
626新增: if se2.run("run", "true") != 0 || strings.Join(se.fake.VMs[vmname.Name(se.proj)].Mounts[0].SSHFS.ReadonlyNames, ",") != ".git,.hg,.sl,.jj,.husky" {
627新增: t.Errorf("restarted: %s %s", se2.out(), se.fake.CallLog())
628新增: }
629新增:}
630新增:
631新增:// A VM whose shares leave .git writable: protected before it boots when
632新增:// stopped; when running, a restart offered (stop, edit, start, in that
633新增:// order), refused without a terminal.
634新增:func TestStartGitStale(t *testing.T) {
635新增: se := newStartEnv(t)
636新增: se.base()
637新增: name := vmname.Name(se.proj)
638新增: se.run("run", "true")
639新增: unprotect := func() {
640新增: for i := range se.fake.VMs[name].Mounts {
641新增: se.fake.VMs[name].Mounts[i].SSHFS.ReadonlyNames = nil
642新增: }
643新增: }
644新增: unprotect()
645新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "is running with .git writable") || !strings.Contains(se.out(), "Aborted. 'agent-vm stop'") ||
646新增: strings.Contains(se.fake.CallLog(), "stop") {
647新增: t.Errorf("running, no terminal: %s\n%s", se.out(), se.fake.CallLog())
648新增: }
649新增: if se.run("--unsafe-disable-security-prompts", "run", "true") != 0 || !strings.Contains(se.out(), "Continuing") || strings.Contains(se.fake.CallLog(), "stop") {
650新增: t.Errorf("running, prompts off: %s\n%s", se.out(), se.fake.CallLog())
651新增: }
652新增: se2 := &startEnv{testEnv: newTestEnv(t, se.fake, "y\n"), g: se.g, home: se.home, proj: se.proj}
653新增: se2.state = se.state
654新增: if se2.run("run", "true") != 0 || !strings.HasPrefix(se.fake.CallLog(), "stop "+name+"\nedit "+name+"\nstart "+name) {
655新增: t.Errorf("running, restarted: %s\n%s", se2.out(), se.fake.CallLog())
656新增: }
657新增: // Stopped: protected before its one start.
658新增: unprotect()
659新增: se.fake.VMs[name].Status = vm.Stopped
660新增: if se.run("run", "true") != 0 || !strings.Contains(se.out(), "Making every .git read-only for VM") ||
661新增: !strings.HasPrefix(se.fake.CallLog(), "edit "+name+"\nstart "+name) || strings.Count(se.fake.CallLog(), "start ") != 1 {
662新增: t.Errorf("stopped: %s\n%s", se.out(), se.fake.CallLog())
663新增: }
664新增:}
665新增:
666新增:// Left writable on purpose: a warning on every start, the shares still the
667新增:// confined server's, without the names. Only "1" counts.
668新增:func TestStartWritableGit(t *testing.T) {
669新增: se := newStartEnv(t)
670新增: se.base()
671新增: name := vmname.Name(se.proj)
672新增: se.run("run", "true")
673新增: // Running and protected: kept so until it stops.
674新增: if se.run("--unsafe-writable-git", "run", "true") != 0 || !strings.Contains(se.out(), "WARNING: --unsafe-writable-git") ||
675新增: !strings.Contains(se.out(), "keeps .git read-only until it stops") || strings.Contains(se.fake.CallLog(), "stop") {
676新增: t.Errorf("running: %s\n%s", se.out(), se.fake.CallLog())
677新增: }
678新增: se.fake.VMs[name].Status = vm.Stopped
679新增: t.Setenv("AGENT_VM_UNSAFE_WRITABLE_GIT", "1")
680新增: if se.run("run", "true") != 0 || !strings.Contains(se.out(), "WARNING: AGENT_VM_UNSAFE_WRITABLE_GIT=1") || !strings.Contains(se.out(), "Making .git writable for VM") {
681新增: t.Errorf("stopped: %s", se.out())
682新增: }
683新增: m := se.fake.VMs[name].Mounts[0]
684新增: if se.fake.VMs[name].MountType != vm.ReverseSSHFS || m.SSHFS == nil || m.SSHFS.SFTPDriver != "builtin" || len(m.SSHFS.ReadonlyNames) != 0 {
685新增: t.Errorf("shares: %+v %+v", se.fake.VMs[name], m.SSHFS)
686新增: }
687新增: // Anything but 1: protected again (stopped, so no question).
688新增: t.Setenv("AGENT_VM_UNSAFE_WRITABLE_GIT", "yes")
689新增: se.fake.VMs[name].Status = vm.Stopped
690新增: if se.run("run", "true") != 0 || strings.Contains(se.out(), "WARNING") || len(se.fake.VMs[name].Mounts[0].SSHFS.ReadonlyNames) == 0 {
691新增: t.Errorf("yes: %s", se.out())
692新增: }
693新增: t.Setenv("AGENT_VM_UNSAFE_WRITABLE_GIT", "")
694新增: // The prompts switch, likewise: "yes" still asks (no terminal: no).
695新增: exec.Command("git", "-C", se.proj, "init", "-q").Run()
696新增: exec.Command("git", "-C", se.proj, "config", "core.hooksPath", ".").Run()
697新增: se.fake.VMs[name].Status = vm.Stopped
698新增: t.Setenv("AGENT_VM_UNSAFE_DISABLE_SECURITY_PROMPTS", "yes")
699新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "Aborted.") {
700新增: t.Errorf("prompts yes: %s", se.out())
701新增: }
702新增: t.Setenv("AGENT_VM_UNSAFE_DISABLE_SECURITY_PROMPTS", "1")
703新增: if se.run("run", "true") != 0 {
704新增: t.Errorf("prompts 1: %s", se.out())
705新增: }
706新增:}
707新增:
708新增:// --readonly on a stopped writable VM: its shares read-only before its one
709新增:// start; back to writable the same way, said so.
710新增:func TestStartReadonlyStopped(t *testing.T) {
711新增: se := newStartEnv(t)
712新增: se.base()
713新增: name := vmname.Name(se.proj)
714新增: se.run("run", "true")
715新增: se.fake.VMs[name].Status = vm.Stopped
716新增: if se.run("--readonly", "run", "true") != 0 || !strings.HasPrefix(se.fake.CallLog(), "edit "+name+"\nstart "+name) ||
717新增: strings.Count(se.fake.CallLog(), "start ") != 1 || strings.Contains(se.fake.CallLog(), "stop") || !strings.Contains(se.out(), "Making every share of VM") {
718新增: t.Errorf("--readonly: %s\n%s", se.out(), se.fake.CallLog())
719新增: }
720新增: se.fake.VMs[name].Status = vm.Stopped
721新增: if se.run("run", "true") != 0 || !strings.HasPrefix(se.fake.CallLog(), "edit "+name+"\nstart "+name) ||
722新增: !strings.Contains(se.out(), "was left read-only by --readonly; making it writable again") || !se.fake.VMs[name].Mounts[0].Writable {
723新增: t.Errorf("writable again: %s\n%s", se.out(), se.fake.CallLog())
724新增: }
725新增:}
726新增:
727新增:func TestStartScratch(t *testing.T) {
728新增: se := newStartEnv(t)
729新增: se.base()
730新增: os.WriteFile(filepath.Join(se.proj, ".agent-vm.env"), []byte("P=1\n"), 0o600)
731新增: os.WriteFile(se.state.Path("env"), []byte("S=1\n"), 0o600)
732新增: if code := se.run("--scratch", "run", "true"); code != 0 {
733新增: t.Fatalf("scratch: %d %s", code, se.out())
734新增: }
735新增: for name := range se.fake.VMs {
736新增: if name != vmname.Template {
737新增: t.Errorf("left: %s", name)
738新增: }
739新增: }
740新增: if !strings.Contains(se.fake.CallLog(), "-scratch-") || !strings.Contains(se.out(), "Deleting scratch VM") {
741新增: t.Errorf("scratch: %s\n%s", se.out(), se.fake.CallLog())
742新增: }
743新增: if len(se.g.payloads) != 1 || se.g.payloads[0] != "S=1\n" {
744新增: t.Errorf("only the shared env goes in: %q", se.g.payloads)
745新增: }
746新增: if se.run("--scratch", "--readonly", "run", "true") != 1 || !strings.Contains(se.out(), "--reset and --readonly do not go with it") {
747新增: t.Errorf("scratch readonly: %s", se.out())
748新增: }
749新增: // A leftover of a run that is gone is deleted; one in use is not.
750新增: gone := "proj-scratch-0000aaaa"
751新增: used := "proj-scratch-0000bbbb"
752新增: for _, n := range []string{gone, used} {
753新增: se.fake.VMs[n] = &vm.Instance{Name: n, Status: vm.Running}
754新增: }
755新增: os.WriteFile(se.state.Marker(state.ScratchOf, gone), []byte("999999999\n"), 0o644)
756新增: os.WriteFile(se.state.Marker(state.ScratchOf, used), []byte(fmt.Sprintln(os.Getpid())), 0o644)
757新增: se.run("--scratch", "run", "true")
758新增: if se.fake.VMs[gone] != nil || se.fake.VMs[used] == nil {
759新增: t.Errorf("leftovers: %s", se.out())
760新增: }
761新增:}
762新增:
763新增:// On a terminal: a no opens a shell in the VM, then asks again.
764新增:func TestStartScratchAsk(t *testing.T) {
765新增: se := newStartEnv(t, "n", "y")
766新增: se.base()
767新增: if code := se.run("--scratch", "run", "true"); code != 0 {
768新增: t.Fatalf("scratch: %d %s", code, se.out())
769新增: }
770新增: log := se.fake.CallLog()
771新增: // The scratch VM's own name, which socket room may cut short: read
772新增: // it, rather than the folder's.
773新增: name := ""
774新增: if i := strings.Index(se.out(), "Deleting scratch VM '"); i >= 0 {
775新增: rest := se.out()[i+len("Deleting scratch VM '"):]
776新增: if j := strings.IndexByte(rest, '\''); j >= 0 {
777新增: name = rest[:j]
778新增: }
779新增: }
780新增: shell, del := strings.LastIndex(log, " zsh -l\n"), strings.Index(log, "delete "+name)
781新增: if strings.Count(se.out(), "Delete scratch VM '") != 2 || !strings.Contains(se.out(), "Type 'exit' to be asked again.") ||
782新增: name == "" || shell < 0 || del < shell {
783新增: t.Errorf("asked: %s\n%s", se.out(), log)
784新增: }
785新增: if len(se.fake.VMs) != 1 {
786新增: t.Errorf("left: %v", se.fake.VMs)
787新增: }
788新增:}
789新增:
790新增:// A network file the hostagent would stop on stops the start here, named;
791新增:// setup too; doctor says it.
792新增:func TestStartPolicyFiles(t *testing.T) {
793新增: se := newStartEnv(t)
794新增: se.base()
795新增: os.WriteFile(se.state.Path("network"), []byte("allow 10.0.0.0/8\nallow nowhere\n"), 0o644)
796新增: if se.run("run", "true") != 1 || !strings.Contains(se.out(), "network, line 2") || strings.Contains(se.fake.CallLog(), "start ") {
797新增: t.Errorf("bad network file: %s\n%s", se.out(), se.fake.CallLog())
798新增: }
799新增: if se.setupBase([]string{"setup", "--preinstall=none"}) != 1 || !strings.Contains(se.out(), "network, line 2") || se.fake.CallLog() != "" {
800新增: t.Errorf("setup: %s\n%s", se.out(), se.fake.CallLog())
801新增: }
802新增: se.run("doctor")
803新增: if !strings.Contains(se.stdout.String(), " FAIL "+se.state.Path("network")+", line 2") {
804新增: t.Errorf("doctor: %s", se.stdout.String())
805新增: }
806新增: os.WriteFile(se.state.Path("network"), []byte("allow localhost:11434\n"), 0o644)
807新增: if se.run("run", "true") != 0 {
808新增: t.Errorf("good network file: %s", se.out())
809新增: }
810新增: t.Setenv("AGENT_VM_UNSAFE_OPEN_NETWORK", "1")
811新增: se.run("doctor")
812新增: if !strings.Contains(se.stdout.String(), " warn network isolation off") {
813新增: t.Errorf("doctor, open: %s", se.stdout.String())
814新增: }
815新增:}
新增internal/cli/testdata/bashref/TestCodePortsHostBash.json+164 −0看文件
@@ -0,0 +1,164 @@
1新增:{
2新增: "TestCodePortsHostBash": [
3新增: {
4新增: "Dir": "{ROOT}",
5新增: "Stdin": "",
6新增: "Snippet": "\"$@\"",
7新增: "Env": [
8新增: "HOME={T0}/001"
9新增: ],
10新增: "Args": [
11新增: "_agent_vm_code_ports",
12新增: "proj-0000270f"
13新增: ],
14新增: "Files": null,
15新增: "Stdout": "20008 20009 20010 20011 20012 20013 20014 20015 20016 20017 ",
16新增: "Stderr": "",
17新增: "Code": 0
18新增: },
19新增: {
20新增: "Dir": "{ROOT}",
21新增: "Stdin": "",
22新增: "Snippet": "\"$@\"",
23新增: "Env": [
24新增: "HOME={T0}/002"
25新增: ],
26新增: "Args": [
27新增: "_agent_vm_code_host",
28新增: "proj-0000270f"
29新增: ],
30新增: "Files": null,
31新增: "Stdout": "proj-0000270f.localhost\n",
32新增: "Stderr": "",
33新增: "Code": 0
34新增: },
35新增: {
36新增: "Dir": "{ROOT}",
37新增: "Stdin": "",
38新增: "Snippet": "\"$@\"",
39新增: "Env": [
40新增: "HOME={T0}/003"
41新增: ],
42新增: "Args": [
43新增: "_agent_vm_code_ports",
44新增: "proj-ffffffff"
45新增: ],
46新增: "Files": null,
47新增: "Stdout": "25589 25590 25591 25592 25593 25594 25595 25596 25597 25598 ",
48新增: "Stderr": "",
49新增: "Code": 0
50新增: },
51新增: {
52新增: "Dir": "{ROOT}",
53新增: "Stdin": "",
54新增: "Snippet": "\"$@\"",
55新增: "Env": [
56新增: "HOME={T0}/004"
57新增: ],
58新增: "Args": [
59新增: "_agent_vm_code_host",
60新增: "proj-ffffffff"
61新增: ],
62新增: "Files": null,
63新增: "Stdout": "proj-ffffffff.localhost\n",
64新增: "Stderr": "",
65新增: "Code": 0
66新增: },
67新增: {
68新增: "Dir": "{ROOT}",
69新增: "Stdin": "",
70新增: "Snippet": "\"$@\"",
71新增: "Env": [
72新增: "HOME={T0}/005"
73新增: ],
74新增: "Args": [
75新增: "_agent_vm_code_ports",
76新增: "proj-00000000"
77新增: ],
78新增: "Files": null,
79新增: "Stdout": "20000 20001 20002 20003 20004 20005 20006 20007 20008 20009 ",
80新增: "Stderr": "",
81新增: "Code": 0
82新增: },
83新增: {
84新增: "Dir": "{ROOT}",
85新增: "Stdin": "",
86新增: "Snippet": "\"$@\"",
87新增: "Env": [
88新增: "HOME={T0}/006"
89新增: ],
90新增: "Args": [
91新增: "_agent_vm_code_host",
92新增: "proj-00000000"
93新增: ],
94新增: "Files": null,
95新增: "Stdout": "proj-00000000.localhost\n",
96新增: "Stderr": "",
97新增: "Code": 0
98新增: },
99新增: {
100新增: "Dir": "{ROOT}",
101新增: "Stdin": "",
102新增: "Snippet": "\"$@\"",
103新增: "Env": [
104新增: "HOME={T0}/007"
105新增: ],
106新增: "Args": [
107新增: "_agent_vm_code_ports",
108新增: "noHash"
109新增: ],
110新增: "Files": null,
111新增: "Stdout": "24723 24724 24725 24726 24727 24728 24729 24730 24731 24732 ",
112新增: "Stderr": "",
113新增: "Code": 0
114新增: },
115新增: {
116新增: "Dir": "{ROOT}",
117新增: "Stdin": "",
118新增: "Snippet": "\"$@\"",
119新增: "Env": [
120新增: "HOME={T0}/008"
121新增: ],
122新增: "Args": [
123新增: "_agent_vm_code_host",
124新增: "noHash"
125新增: ],
126新增: "Files": null,
127新增: "Stdout": "nohash.localhost\n",
128新增: "Stderr": "",
129新增: "Code": 0
130新增: },
131新增: {
132新增: "Dir": "{ROOT}",
133新增: "Stdin": "",
134新增: "Snippet": "\"$@\"",
135新增: "Env": [
136新增: "HOME={T0}/009"
137新增: ],
138新增: "Args": [
139新增: "_agent_vm_code_ports",
140新增: "LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong-abcdef12"
141新增: ],
142新增: "Files": null,
143新增: "Stdout": "21256 21257 21258 21259 21260 21261 21262 21263 21264 21265 ",
144新增: "Stderr": "",
145新增: "Code": 0
146新增: },
147新增: {
148新增: "Dir": "{ROOT}",
149新增: "Stdin": "",
150新增: "Snippet": "\"$@\"",
151新增: "Env": [
152新增: "HOME={T0}/010"
153新增: ],
154新增: "Args": [
155新增: "_agent_vm_code_host",
156新增: "LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong-abcdef12"
157新增: ],
158新增: "Files": null,
159新增: "Stdout": "longlonglonglonglonglonglonglonglonglonglonglonglonglo-abcdef12.localhost\n",
160新增: "Stderr": "",
161新增: "Code": 0
162新增: }
163新增: ]
164新增:}
新增internal/cli/testdata/bashref/TestEnvBash.json+570 −0看文件
@@ -0,0 +1,570 @@
1新增:{
2新增: "TestEnvBash": [
3新增: {
4新增: "Dir": "{T0}/002",
5新增: "Stdin": "",
6新增: "Snippet": "agent-vm \"$@\"",
7新增: "Env": [
8新增: "HOME={T0}/006",
9新增: "PWD={T0}/002",
10新增: "AGENT_VM_STATE_DIR={T0}/004"
11新增: ],
12新增: "Args": [
13新增: "env",
14新增: "list"
15新增: ],
16新增: "Files": [
17新增: "{T0}/004/env",
18新增: "{T0}/002/.agent-vm.env"
19新增: ],
20新增: "Stdout": "",
21新增: "Stderr": "",
22新增: "Code": 0
23新增: },
24新增: {
25新增: "Dir": "{T0}/002",
26新增: "Stdin": "",
27新增: "Snippet": "agent-vm \"$@\"",
28新增: "Env": [
29新增: "HOME={T0}/008",
30新增: "PWD={T0}/002",
31新增: "AGENT_VM_STATE_DIR={T0}/004"
32新增: ],
33新增: "Args": [
34新增: "env",
35新增: "get",
36新增: "A"
37新增: ],
38新增: "Files": [
39新增: "{T0}/004/env",
40新增: "{T0}/002/.agent-vm.env"
41新增: ],
42新增: "Stdout": "",
43新增: "Stderr": "",
44新增: "Code": 1
45新增: },
46新增: {
47新增: "Dir": "{T0}/002",
48新增: "Stdin": "",
49新增: "Snippet": "agent-vm \"$@\"",
50新增: "Env": [
51新增: "HOME={T0}/010",
52新增: "PWD={T0}/002",
53新增: "AGENT_VM_STATE_DIR={T0}/004"
54新增: ],
55新增: "Args": [
56新增: "env",
57新增: "has",
58新增: "A"
59新增: ],
60新增: "Files": [
61新增: "{T0}/004/env",
62新增: "{T0}/002/.agent-vm.env"
63新增: ],
64新增: "Stdout": "",
65新增: "Stderr": "",
66新增: "Code": 1
67新增: },
68新增: {
69新增: "Dir": "{T0}/012",
70新增: "Stdin": "",
71新增: "Snippet": "agent-vm \"$@\"",
72新增: "Env": [
73新增: "HOME={T0}/016",
74新增: "PWD={T0}/012",
75新增: "AGENT_VM_STATE_DIR={T0}/014"
76新增: ],
77新增: "Args": [
78新增: "env",
79新增: "set",
80新增: "A",
81新增: "O'Brien"
82新增: ],
83新增: "Files": [
84新增: "{T0}/014/env",
85新增: "{T0}/012/.agent-vm.env"
86新增: ],
87新增: "Stdout": "",
88新增: "Stderr": "",
89新增: "Code": 0,
90新增: "Out": {
91新增: "{T0}/014/env": "A='O'\"'\"'Brien'\n"
92新增: }
93新增: },
94新增: {
95新增: "Dir": "{T0}/012",
96新增: "Stdin": "",
97新增: "Snippet": "agent-vm \"$@\"",
98新增: "Env": [
99新增: "HOME={T0}/018",
100新增: "PWD={T0}/012",
101新增: "AGENT_VM_STATE_DIR={T0}/014"
102新增: ],
103新增: "Args": [
104新增: "env",
105新增: "get",
106新增: "A"
107新增: ],
108新增: "Files": [
109新增: "{T0}/014/env",
110新增: "{T0}/012/.agent-vm.env"
111新增: ],
112新增: "Stdout": "O'Brien\n",
113新增: "Stderr": "",
114新增: "Code": 0,
115新增: "Out": {
116新增: "{T0}/014/env": "A='O'\"'\"'Brien'\n"
117新增: }
118新增: },
119新增: {
120新增: "Dir": "{T0}/012",
121新增: "Stdin": "",
122新增: "Snippet": "agent-vm \"$@\"",
123新增: "Env": [
124新增: "HOME={T0}/020",
125新增: "PWD={T0}/012",
126新增: "AGENT_VM_STATE_DIR={T0}/014"
127新增: ],
128新增: "Args": [
129新增: "env"
130新增: ],
131新增: "Files": [
132新增: "{T0}/014/env",
133新增: "{T0}/012/.agent-vm.env"
134新增: ],
135新增: "Stdout": "A\n",
136新增: "Stderr": "",
137新增: "Code": 0,
138新增: "Out": {
139新增: "{T0}/014/env": "A='O'\"'\"'Brien'\n"
140新增: }
141新增: },
142新增: {
143新增: "Dir": "{T0}/022",
144新增: "Stdin": "piped\n",
145新增: "Snippet": "agent-vm \"$@\"",
146新增: "Env": [
147新增: "HOME={T0}/026",
148新增: "PWD={T0}/022",
149新增: "AGENT_VM_STATE_DIR={T0}/024"
150新增: ],
151新增: "Args": [
152新增: "env",
153新增: "set",
154新增: "A"
155新增: ],
156新增: "Files": [
157新增: "{T0}/024/env",
158新增: "{T0}/022/.agent-vm.env"
159新增: ],
160新增: "Stdout": "",
161新增: "Stderr": "",
162新增: "Code": 0,
163新增: "Out": {
164新增: "{T0}/024/env": "A='piped'\n"
165新增: }
166新增: },
167新增: {
168新增: "Dir": "{T0}/022",
169新增: "Stdin": "multi\nline\n",
170新增: "Snippet": "agent-vm \"$@\"",
171新增: "Env": [
172新增: "HOME={T0}/028",
173新增: "PWD={T0}/022",
174新增: "AGENT_VM_STATE_DIR={T0}/024"
175新增: ],
176新增: "Args": [
177新增: "env",
178新增: "set",
179新增: "B"
180新增: ],
181新增: "Files": [
182新增: "{T0}/024/env",
183新增: "{T0}/022/.agent-vm.env"
184新增: ],
185新增: "Stdout": "",
186新增: "Stderr": "",
187新增: "Code": 0,
188新增: "Out": {
189新增: "{T0}/024/env": "A='piped'\nB='multi\nline'\n"
190新增: }
191新增: },
192新增: {
193新增: "Dir": "{T0}/022",
194新增: "Stdin": "",
195新增: "Snippet": "agent-vm \"$@\"",
196新增: "Env": [
197新增: "HOME={T0}/030",
198新增: "PWD={T0}/022",
199新增: "AGENT_VM_STATE_DIR={T0}/024"
200新增: ],
201新增: "Args": [
202新增: "env",
203新增: "get",
204新增: "B"
205新增: ],
206新增: "Files": [
207新增: "{T0}/024/env",
208新增: "{T0}/022/.agent-vm.env"
209新增: ],
210新增: "Stdout": "multi\nline\n",
211新增: "Stderr": "",
212新增: "Code": 0,
213新增: "Out": {
214新增: "{T0}/024/env": "A='piped'\nB='multi\nline'\n"
215新增: }
216新增: },
217新增: {
218新增: "Dir": "{T0}/022",
219新增: "Stdin": "",
220新增: "Snippet": "agent-vm \"$@\"",
221新增: "Env": [
222新增: "HOME={T0}/032",
223新增: "PWD={T0}/022",
224新增: "AGENT_VM_STATE_DIR={T0}/024"
225新增: ],
226新增: "Args": [
227新增: "env",
228新增: "set",
229新增: "A",
230新增: "again"
231新增: ],
232新增: "Files": [
233新增: "{T0}/024/env",
234新增: "{T0}/022/.agent-vm.env"
235新增: ],
236新增: "Stdout": "",
237新增: "Stderr": "",
238新增: "Code": 0,
239新增: "Out": {
240新增: "{T0}/024/env": "B='multi\nline'\nA='again'\n"
241新增: }
242新增: },
243新增: {
244新增: "Dir": "{T0}/022",
245新增: "Stdin": "",
246新增: "Snippet": "agent-vm \"$@\"",
247新增: "Env": [
248新增: "HOME={T0}/034",
249新增: "PWD={T0}/022",
250新增: "AGENT_VM_STATE_DIR={T0}/024"
251新增: ],
252新增: "Args": [
253新增: "env",
254新增: "list"
255新增: ],
256新增: "Files": [
257新增: "{T0}/024/env",
258新增: "{T0}/022/.agent-vm.env"
259新增: ],
260新增: "Stdout": "B\nA\n",
261新增: "Stderr": "",
262新增: "Code": 0,
263新增: "Out": {
264新增: "{T0}/024/env": "B='multi\nline'\nA='again'\n"
265新增: }
266新增: },
267新增: {
268新增: "Dir": "{T0}/022",
269新增: "Stdin": "",
270新增: "Snippet": "agent-vm \"$@\"",
271新增: "Env": [
272新增: "HOME={T0}/036",
273新增: "PWD={T0}/022",
274新增: "AGENT_VM_STATE_DIR={T0}/024"
275新增: ],
276新增: "Args": [
277新增: "env",
278新增: "unset",
279新增: "A"
280新增: ],
281新增: "Files": [
282新增: "{T0}/024/env",
283新增: "{T0}/022/.agent-vm.env"
284新增: ],
285新增: "Stdout": "",
286新增: "Stderr": "",
287新增: "Code": 0,
288新增: "Out": {
289新增: "{T0}/024/env": "B='multi\nline'\n"
290新增: }
291新增: },
292新增: {
293新增: "Dir": "{T0}/022",
294新增: "Stdin": "",
295新增: "Snippet": "agent-vm \"$@\"",
296新增: "Env": [
297新增: "HOME={T0}/038",
298新增: "PWD={T0}/022",
299新增: "AGENT_VM_STATE_DIR={T0}/024"
300新增: ],
301新增: "Args": [
302新增: "env",
303新增: "list"
304新增: ],
305新增: "Files": [
306新增: "{T0}/024/env",
307新增: "{T0}/022/.agent-vm.env"
308新增: ],
309新增: "Stdout": "B\n",
310新增: "Stderr": "",
311新增: "Code": 0,
312新增: "Out": {
313新增: "{T0}/024/env": "B='multi\nline'\n"
314新增: }
315新增: },
316新增: {
317新增: "Dir": "{T0}/040",
318新增: "Stdin": "",
319新增: "Snippet": "agent-vm \"$@\"",
320新增: "Env": [
321新增: "HOME={T0}/044",
322新增: "PWD={T0}/040",
323新增: "AGENT_VM_STATE_DIR={T0}/042"
324新增: ],
325新增: "Args": [
326新增: "env",
327新增: "set",
328新增: "A"
329新增: ],
330新增: "Files": [
331新增: "{T0}/042/env",
332新增: "{T0}/040/.agent-vm.env"
333新增: ],
334新增: "Stdout": "",
335新增: "Stderr": "Error: 'agent-vm env set A' needs a VALUE, as an argument or on stdin.\n",
336新增: "Code": 1
337新增: },
338新增: {
339新增: "Dir": "{T0}/040",
340新增: "Stdin": "",
341新增: "Snippet": "agent-vm \"$@\"",
342新增: "Env": [
343新增: "HOME={T0}/046",
344新增: "PWD={T0}/040",
345新增: "AGENT_VM_STATE_DIR={T0}/042"
346新增: ],
347新增: "Args": [
348新增: "env",
349新增: "set",
350新增: "1A",
351新增: "x"
352新增: ],
353新增: "Files": [
354新增: "{T0}/042/env",
355新增: "{T0}/040/.agent-vm.env"
356新增: ],
357新增: "Stdout": "",
358新增: "Stderr": "Error: '1A' is not a valid environment variable name.\n",
359新增: "Code": 1
360新增: },
361新增: {
362新增: "Dir": "{T0}/040",
363新增: "Stdin": "",
364新增: "Snippet": "agent-vm \"$@\"",
365新增: "Env": [
366新增: "HOME={T0}/048",
367新增: "PWD={T0}/040",
368新增: "AGENT_VM_STATE_DIR={T0}/042"
369新增: ],
370新增: "Args": [
371新增: "env",
372新增: "set"
373新增: ],
374新增: "Files": [
375新增: "{T0}/042/env",
376新增: "{T0}/040/.agent-vm.env"
377新增: ],
378新增: "Stdout": "",
379新增: "Stderr": "Error: 'agent-vm env set' needs a KEY.\n",
380新增: "Code": 1
381新增: },
382新增: {
383新增: "Dir": "{T0}/040",
384新增: "Stdin": "",
385新增: "Snippet": "agent-vm \"$@\"",
386新增: "Env": [
387新增: "HOME={T0}/050",
388新增: "PWD={T0}/040",
389新增: "AGENT_VM_STATE_DIR={T0}/042"
390新增: ],
391新增: "Args": [
392新增: "env",
393新增: "set",
394新增: "A",
395新增: "b",
396新增: "c"
397新增: ],
398新增: "Files": [
399新增: "{T0}/042/env",
400新增: "{T0}/040/.agent-vm.env"
401新增: ],
402新增: "Stdout": "",
403新增: "Stderr": "Error: too many arguments for 'agent-vm env set'. Quote a value with spaces.\nUsage: agent-vm env {set KEY [VALUE]|get KEY|has KEY|unset KEY|list}\n",
404新增: "Code": 1
405新增: },
406新增: {
407新增: "Dir": "{T0}/040",
408新增: "Stdin": "",
409新增: "Snippet": "agent-vm \"$@\"",
410新增: "Env": [
411新增: "HOME={T0}/052",
412新增: "PWD={T0}/040",
413新增: "AGENT_VM_STATE_DIR={T0}/042"
414新增: ],
415新增: "Args": [
416新增: "env",
417新增: "frob"
418新增: ],
419新增: "Files": [
420新增: "{T0}/042/env",
421新增: "{T0}/040/.agent-vm.env"
422新增: ],
423新增: "Stdout": "",
424新增: "Stderr": "Usage: agent-vm env {set KEY [VALUE]|get KEY|has KEY|unset KEY|list}\n",
425新增: "Code": 1
426新增: },
427新增: {
428新增: "Dir": "{T0}/040",
429新增: "Stdin": "",
430新增: "Snippet": "agent-vm \"$@\"",
431新增: "Env": [
432新增: "HOME={T0}/054",
433新增: "PWD={T0}/040",
434新增: "AGENT_VM_STATE_DIR={T0}/042"
435新增: ],
436新增: "Args": [
437新增: "env",
438新增: "get",
439新增: "A",
440新增: "B"
441新增: ],
442新增: "Files": [
443新增: "{T0}/042/env",
444新增: "{T0}/040/.agent-vm.env"
445新增: ],
446新增: "Stdout": "",
447新增: "Stderr": "Error: too many arguments for 'agent-vm env get'. Quote a value with spaces.\nUsage: agent-vm env {set KEY [VALUE]|get KEY|has KEY|unset KEY|list}\n",
448新增: "Code": 1
449新增: },
450新增: {
451新增: "Dir": "{T0}/040",
452新增: "Stdin": "",
453新增: "Snippet": "agent-vm \"$@\"",
454新增: "Env": [
455新增: "HOME={T0}/056",
456新增: "PWD={T0}/040",
457新增: "AGENT_VM_STATE_DIR={T0}/042"
458新增: ],
459新增: "Args": [
460新增: "env",
461新增: "list",
462新增: "x"
463新增: ],
464新增: "Files": [
465新增: "{T0}/042/env",
466新增: "{T0}/040/.agent-vm.env"
467新增: ],
468新增: "Stdout": "",
469新增: "Stderr": "Error: too many arguments for 'agent-vm env list'. Quote a value with spaces.\nUsage: agent-vm env {set KEY [VALUE]|get KEY|has KEY|unset KEY|list}\n",
470新增: "Code": 1
471新增: },
472新增: {
473新增: "Dir": "{T0}/040",
474新增: "Stdin": "",
475新增: "Snippet": "agent-vm \"$@\"",
476新增: "Env": [
477新增: "HOME={T0}/058",
478新增: "PWD={T0}/040",
479新增: "AGENT_VM_STATE_DIR={T0}/042"
480新增: ],
481新增: "Args": [
482新增: "env",
483新增: "unset",
484新增: "NOPE"
485新增: ],
486新增: "Files": [
487新增: "{T0}/042/env",
488新增: "{T0}/040/.agent-vm.env"
489新增: ],
490新增: "Stdout": "",
491新增: "Stderr": "",
492新增: "Code": 0
493新增: },
494新增: {
495新增: "Dir": "{T0}/060",
496新增: "Stdin": "",
497新增: "Snippet": "agent-vm \"$@\"",
498新增: "Env": [
499新增: "HOME={T0}/064",
500新增: "PWD={T0}/060",
501新增: "AGENT_VM_STATE_DIR={T0}/062"
502新增: ],
503新增: "Args": [
504新增: "project-env",
505新增: "set",
506新增: "K",
507新增: "v"
508新增: ],
509新增: "Files": [
510新增: "{T0}/062/env",
511新增: "{T0}/060/.agent-vm.env"
512新增: ],
513新增: "Stdout": "",
514新增: "Stderr": "",
515新增: "Code": 0,
516新增: "Out": {
517新增: "{T0}/060/.agent-vm.env": "K='v'\n"
518新增: }
519新增: },
520新增: {
521新增: "Dir": "{T0}/060",
522新增: "Stdin": "",
523新增: "Snippet": "agent-vm \"$@\"",
524新增: "Env": [
525新增: "HOME={T0}/066",
526新增: "PWD={T0}/060",
527新增: "AGENT_VM_STATE_DIR={T0}/062"
528新增: ],
529新增: "Args": [
530新增: "project-env",
531新增: "get",
532新增: "K"
533新增: ],
534新增: "Files": [
535新增: "{T0}/062/env",
536新增: "{T0}/060/.agent-vm.env"
537新增: ],
538新增: "Stdout": "v\n",
539新增: "Stderr": "",
540新增: "Code": 0,
541新增: "Out": {
542新增: "{T0}/060/.agent-vm.env": "K='v'\n"
543新增: }
544新增: },
545新增: {
546新增: "Dir": "{T0}/060",
547新增: "Stdin": "",
548新增: "Snippet": "agent-vm \"$@\"",
549新增: "Env": [
550新增: "HOME={T0}/068",
551新增: "PWD={T0}/060",
552新增: "AGENT_VM_STATE_DIR={T0}/062"
553新增: ],
554新增: "Args": [
555新增: "project-env",
556新增: "list"
557新增: ],
558新增: "Files": [
559新增: "{T0}/062/env",
560新增: "{T0}/060/.agent-vm.env"
561新增: ],
562新增: "Stdout": "K\n",
563新增: "Stderr": "",
564新增: "Code": 0,
565新增: "Out": {
566新增: "{T0}/060/.agent-vm.env": "K='v'\n"
567新增: }
568新增: }
569新增: ]
570新增:}
新增internal/cli/testdata/bashref/TestHelp.json+19 −0看文件
@@ -0,0 +1,19 @@
1新增:{
2新增: "TestHelp": [
3新增: {
4新增: "Dir": "{ROOT}",
5新增: "Stdin": "",
6新增: "Snippet": "\"$@\"",
7新增: "Env": [
8新增: "HOME={T0}/001"
9新增: ],
10新增: "Args": [
11新增: "_agent_vm_help"
12新增: ],
13新增: "Files": null,
14新增: "Stdout": "Usage: agent-vm [options] \u003ccommand\u003e [args]\n\nCommands:\n install Put agent-vm on your PATH (a link in ~/.local/bin, or\n AGENT_VM_BIN_DIR). Run it from the clone:\n ./agent-vm.sh install\n uninstall Remove that link. VMs and ~/.agent-vm are left alone.\n setup Create the base VM template (run once)\n claude [args] Run Claude Code in the VM for the current directory\n opencode [args] Run OpenCode in the VM for the current directory\n codex [args] Run Codex CLI in the VM for the current directory\n vibe [args] Run Mistral Vibe in the VM for the current directory\n pi [args] Run Pi in the VM for the current directory (opt-in at\n setup: --preinstall=default,pi)\n shell, sh Open a shell in the VM. Add -c \"...\" to run a one-shot\n command via login zsh and exit.\n run \u003ccmd\u003e [args] Run a command in the VM (no shell: for pipes/redirects\n use 'shell -c \"...\"' instead; pass --tty for TUIs like\n opencode, vibe, htop, etc.)\n code Serve VS Code (code-server) from the VM, at\n http://\u003cvm-name\u003e.localhost:\u003cport\u003e/, until Ctrl-C. The\n address and the password, made in each VM, are\n printed: open it in your browser. Opt-in at setup, with the agents'\n extensions or without: --preinstall=default,code-claude\n (or code-codex, code-vibe, code-server)\n stop [vm-name] Stop the VM for the current directory, or the named one\n rm [vm-name] Stop and delete the VM for the current directory, or the\n named one. Pass a name from 'agent-vm list' to reach a VM\n whose directory was renamed or deleted: its name is a\n hash of the old path, so no 'cd' can name it any more.\n destroy-all Stop and delete every agent-vm VM, the base template\n included ('agent-vm setup' rebuilds it)\n list, status List all agent-vm VMs, the current directory's marked\n with \u003e, with the agent-vm version and date of the base\n each was cloned from\n doctor Check the host, Lima, the base template and this\n directory, and say how to fix what is wrong. Read-only.\n name [dir] Print the VM name for a directory (default: cwd)\n info [dir] Print machine-readable state as key=value lines\n (version, template, state_dir, project_env, dir,\n vm_name, base_exists, vm_exists, vm_running, vm_stale,\n ssh_host, ssh_config, git_protected,\n security_questions).\n Use this from scripts instead of parsing the output\n of the human-facing commands.\n env \u003csub\u003e [args] Read/write ~/.agent-vm/env, the secrets pushed into every\n VM. Subcommands: set KEY [VALUE] (without VALUE, read\n from stdin, or typed unseen: out of your shell history),\n get KEY, has KEY (exit status only), unset KEY, list\n (key names, never values).\n Use this rather than editing the file: it is sourced by a\n shell, so one bad quote costs every secret in it.\n project-env \u003csub\u003e Same subcommands, for THIS directory's project only. Its\n values are pushed after the shared ones, so a key set in\n both takes the project's value. Stored IN the project\n (.agent-vm.env by default, AGENT_VM_PROJECT_ENV to put it\n elsewhere): so it follows the project and dies with it.\n Being in a repository, it is the wrong place for a secret:\n `agent-vm env` is outside any. `set` warns, with the line\n to run, when the file is not ignored by git. `info` prints\n the path as project_env=.\n version Print the agent-vm version\n version --min X.Y.Z\n Check it: silent and 0 when this engine is at least\n X.Y.Z, an actionable error and 1 when it is older\n (2 when the call itself is wrong). For integrators.\n help Show this help\n\nVM options (for claude, opencode, codex, vibe, pi, shell, run, code), read before the\ncommand or right after its name, never later: in 'agent-vm run docker run\n--rm x', --rm belongs to docker.\n --disk GB VM disk size\n --memory GB VM memory\n --cpus N Number of CPUs\n Without them, a new VM has the base template's: 10, 3\n and 1 unless 'setup' was given others.\n Memory and CPUs are clamped to a share of the host (half\n of it, with a notice) so the VM cannot starve the\n machine it runs on.\n AGENT_VM_HOST_SHARE overrides the divisor.\n --ssh-port N Fixed host port for the VM's SSH, for tools that save the\n port (default: a new one on each start; 0 goes back)\n --reset Destroy and re-clone the VM from the base template\n --readonly Make every host share read-only: the project and the\n ~/.agent-vm/volumes entries, rw ones included. Enforced\n on the host side, so root in the VM cannot lift it.\n A running VM in the other mode is restarted, asked first\n (no by default; declined or with no terminal, the\n command fails). The resource options ask the same, and\n declined, the VM keeps its settings.\n --unsafe-writable-git\n Leave every .git writable, so the agent can commit (see\n below). Also accepted as --unsafe-writable-git=1.\n --unsafe-disable-security-prompts\n Go on where a start would stop to ask about a security\n risk (below), without offering to change your git\n config; the warnings are still printed. For scripts\n with no terminal. Also\n AGENT_VM_UNSAFE_DISABLE_SECURITY_PROMPTS=1 in your shell.\n --rm Automatically destroy the VM after the command exits\n --scratch A new VM with nothing of yours mounted (no project, no\n volumes), deleted when the command ends, Ctrl-C included.\n On a terminal, the deletion is asked first: no opens a\n shell in the VM, and its exit asks again.\n The project's env file and runtime script stay out;\n ~/.agent-vm/env and runtime.sh go in. The folder's own\n VM is left alone, and several can run at once.\n\nExamples:\n agent-vm setup # Create base VM\n agent-vm claude # Run Claude in a VM\n agent-vm opencode # Run OpenCode in a VM\n agent-vm codex # Run Codex in a VM\n agent-vm vibe # Run Mistral Vibe in a VM\n agent-vm pi # Run Pi in a VM\n agent-vm --disk 50 --memory 16 --cpus 8 claude # Custom resources\n agent-vm --reset claude # Fresh VM from base template\n agent-vm --rm claude # Destroy VM after Claude exits\n agent-vm --readonly shell # Nothing on the host is writable\n agent-vm --scratch claude # Nothing of yours mounted, then deleted\n agent-vm shell # Shell into the VM\n agent-vm sh -c \"ls -la | grep config\" # One-shot command via login zsh\n agent-vm run npm install # Run a command in the VM\n agent-vm run --tty opencode -p \"...\" # Run a TUI with PTY allocated\n agent-vm code # VS Code in the browser\n agent-vm claude -p \"fix lint errors\" # Pass args to claude\n agent-vm rm agent-vm-old-name-1a2b3c4d # Delete a VM by name (see 'list')\n\nVMs are persistent and unique per directory. Running \"agent-vm shell\" or\n\"agent-vm claude\" in the same directory will reuse the same VM.\n\nEvery .git in the shared folders is read-only for the VMs when Lima supports\nit (sshfs.readonlyNames, not merged upstream yet: 'agent-vm setup' offers a\nLima build that has it). Every .hg is too, and so is the folder of each\ncore.hooksPath in the project (.husky for husky). 'agent-vm doctor' says\nwhere you stand.\n\nBefore a VM boots with writable shares, agent-vm stops on what it cannot\nprotect, and asks whether to go on (no by default, and when it cannot ask):\na Lima without readonlyNames, hooks at the top of a share, git config,\ncommands it names, or hooks linked to files, in the project or a writable\nvolume, and git ignoring safe.bareRepository=explicit (which it offers to\nset: git would otherwise use a folder with HEAD, objects/ and refs/ as a\nrepository, under any name). A VM that already runs gets the warnings only,\nand a restart when it lacks a protection; once stopped to boot again, it is\nasked like any other.\n'agent-vm info' lists what a start would ask\n(security_questions=).\n--unsafe-writable-git, or AGENT_VM_UNSAFE_WRITABLE_GIT=1 in your shell, leaves\n.git writable anyway, so the agent can commit in the project; a warning is\nprinted on every run. Changing it applies when the VM is next started.\n\nThe writable shares are served without sshfs's cache, so the VM never writes\nback a file as it was before you changed it. AGENT_VM_SSHFS_CACHE=1 in your\nshell turns the cache on, faster on many files (git status, find), at that\nrisk, for 20 seconds. It applies when a VM is next started.\n\nCustomization:\n ~/.agent-vm/env Shared env vars / tokens (dotenv-style;\n pushed into every VM, loaded in its shells)\n ~/.agent-vm/volumes Extra host paths to mount in VMs, one per\n line, directories or files:\n source[:destination][:ro|rw[:project]]\n (ro by default; a relative destination is\n in the project; project, after an explicit\n mode, limits the entry to the projects it\n matches, * as wildcard)\n ~/.agent-vm/setup.sh Per-user setup (runs under zsh during\n \"agent-vm setup\")\n \u003cproject\u003e/.agent-vm.env Per-project env (agent-vm project-env)\n Override the path with AGENT_VM_PROJECT_ENV\n ~/.agent-vm/runtime.sh Per-user runtime (runs on every command\n that enters a VM)\n \u003cproject\u003e/.agent-vm.runtime.sh Per-project runtime (same, after the\n per-user one)\n Override the path with AGENT_VM_PROJECT_RUNTIME\n (relative to the project, or absolute).\n Runtimes run under the shell their shebang\n names (bash, sh; zsh otherwise).\n\nMore info: https://www.agent-vm.org/\n",
15新增: "Stderr": "",
16新增: "Code": 0
17新增: }
18新增: ]
19新增:}
新增internal/cli/testdata/bashref/TestMainBash.json+545 −0看文件
@@ -0,0 +1,545 @@
1新增:{
2新增: "TestMainBash": [
3新增: {
4新增: "Dir": "{ROOT}",
5新增: "Stdin": "",
6新增: "Snippet": "echo \"$AGENT_VM_VERSION\"",
7新增: "Env": [
8新增: "HOME={T0}/001"
9新增: ],
10新增: "Args": null,
11新增: "Files": null,
12新增: "Stdout": "0.2.1\n",
13新增: "Stderr": "",
14新增: "Code": 0
15新增: },
16新增: {
17新增: "Dir": "{T0}/002",
18新增: "Stdin": "",
19新增: "Snippet": "agent-vm \"$@\"",
20新增: "Env": [
21新增: "HOME={T0}/004",
22新增: "PATH={T0}/003"
23新增: ],
24新增: "Args": [
25新增: "version"
26新增: ],
27新增: "Files": null,
28新增: "Stdout": "0.2.1\n",
29新增: "Stderr": "",
30新增: "Code": 0
31新增: },
32新增: {
33新增: "Dir": "{T0}/002",
34新增: "Stdin": "",
35新增: "Snippet": "agent-vm \"$@\"",
36新增: "Env": [
37新增: "HOME={T0}/006",
38新增: "PATH={T0}/005"
39新增: ],
40新增: "Args": [
41新增: "--version"
42新增: ],
43新增: "Files": null,
44新增: "Stdout": "0.2.1\n",
45新增: "Stderr": "",
46新增: "Code": 0
47新增: },
48新增: {
49新增: "Dir": "{T0}/002",
50新增: "Stdin": "",
51新增: "Snippet": "agent-vm \"$@\"",
52新增: "Env": [
53新增: "HOME={T0}/008",
54新增: "PATH={T0}/007"
55新增: ],
56新增: "Args": [
57新增: "-V"
58新增: ],
59新增: "Files": null,
60新增: "Stdout": "0.2.1\n",
61新增: "Stderr": "",
62新增: "Code": 0
63新增: },
64新增: {
65新增: "Dir": "{T0}/002",
66新增: "Stdin": "",
67新增: "Snippet": "agent-vm \"$@\"",
68新增: "Env": [
69新增: "HOME={T0}/010",
70新增: "PATH={T0}/009"
71新增: ],
72新增: "Args": [
73新增: "version",
74新增: "--min",
75新增: "0.1.0"
76新增: ],
77新增: "Files": null,
78新增: "Stdout": "",
79新增: "Stderr": "",
80新增: "Code": 0
81新增: },
82新增: {
83新增: "Dir": "{T0}/002",
84新增: "Stdin": "",
85新增: "Snippet": "agent-vm \"$@\"",
86新增: "Env": [
87新增: "HOME={T0}/012",
88新增: "PATH={T0}/011"
89新增: ],
90新增: "Args": [
91新增: "version",
92新增: "--min=0.2.1"
93新增: ],
94新增: "Files": null,
95新增: "Stdout": "",
96新增: "Stderr": "",
97新增: "Code": 0
98新增: },
99新增: {
100新增: "Dir": "{T0}/002",
101新增: "Stdin": "",
102新增: "Snippet": "agent-vm \"$@\"",
103新增: "Env": [
104新增: "HOME={T0}/014",
105新增: "PATH={T0}/013"
106新增: ],
107新增: "Args": [
108新增: "version",
109新增: "--min",
110新增: "0.10.0"
111新增: ],
112新增: "Files": null,
113新增: "Stdout": "",
114新增: "Stderr": "Error: agent-vm 0.2.1 is older than the required 0.10.0.\n Update it: git -C '{ROOT}' pull\n",
115新增: "Code": 1
116新增: },
117新增: {
118新增: "Dir": "{T0}/002",
119新增: "Stdin": "",
120新增: "Snippet": "agent-vm \"$@\"",
121新增: "Env": [
122新增: "HOME={T0}/016",
123新增: "PATH={T0}/015"
124新增: ],
125新增: "Args": [
126新增: "version",
127新增: "--min"
128新增: ],
129新增: "Files": null,
130新增: "Stdout": "",
131新增: "Stderr": "Error: --min needs a version (e.g. --min 0.2.0)\n",
132新增: "Code": 2
133新增: },
134新增: {
135新增: "Dir": "{T0}/002",
136新增: "Stdin": "",
137新增: "Snippet": "agent-vm \"$@\"",
138新增: "Env": [
139新增: "HOME={T0}/018",
140新增: "PATH={T0}/017"
141新增: ],
142新增: "Args": [
143新增: "version",
144新增: "--min",
145新增: "x"
146新增: ],
147新增: "Files": null,
148新增: "Stdout": "",
149新增: "Stderr": "Error: --min expects a version like 1.2.3 (got: 'x')\n",
150新增: "Code": 2
151新增: },
152新增: {
153新增: "Dir": "{T0}/002",
154新增: "Stdin": "",
155新增: "Snippet": "agent-vm \"$@\"",
156新增: "Env": [
157新增: "HOME={T0}/020",
158新增: "PATH={T0}/019"
159新增: ],
160新增: "Args": [
161新增: "version",
162新增: "--min",
163新增: ""
164新增: ],
165新增: "Files": null,
166新增: "Stdout": "",
167新增: "Stderr": "Error: --min expects a version like 1.2.3 (got: '')\n",
168新增: "Code": 2
169新增: },
170新增: {
171新增: "Dir": "{T0}/002",
172新增: "Stdin": "",
173新增: "Snippet": "agent-vm \"$@\"",
174新增: "Env": [
175新增: "HOME={T0}/022",
176新增: "PATH={T0}/021"
177新增: ],
178新增: "Args": [
179新增: "version",
180新增: "--max",
181新增: "1"
182新增: ],
183新增: "Files": null,
184新增: "Stdout": "",
185新增: "Stderr": "Error: unknown option for version: --max\n",
186新增: "Code": 2
187新增: },
188新增: {
189新增: "Dir": "{T0}/002",
190新增: "Stdin": "",
191新增: "Snippet": "agent-vm \"$@\"",
192新增: "Env": [
193新增: "HOME={T0}/024",
194新增: "PATH={T0}/023"
195新增: ],
196新增: "Args": [
197新增: "version",
198新增: "--min",
199新增: "1.2.3-rc.1"
200新增: ],
201新增: "Files": null,
202新增: "Stdout": "",
203新增: "Stderr": "Error: agent-vm 0.2.1 is older than the required 1.2.3-rc.1.\n Update it: git -C '{ROOT}' pull\n",
204新增: "Code": 1
205新增: },
206新增: {
207新增: "Dir": "{T0}/002",
208新增: "Stdin": "",
209新增: "Snippet": "agent-vm \"$@\"",
210新增: "Env": [
211新增: "HOME={T0}/026",
212新增: "PATH={T0}/025"
213新增: ],
214新增: "Args": [
215新增: "name"
216新增: ],
217新增: "Files": null,
218新增: "Stdout": "agent-vm-002-e8f570af\n",
219新增: "Stderr": "",
220新增: "Code": 0
221新增: },
222新增: {
223新增: "Dir": "{T0}/002",
224新增: "Stdin": "",
225新增: "Snippet": "agent-vm \"$@\"",
226新增: "Env": [
227新增: "HOME={T0}/028",
228新增: "PATH={T0}/027"
229新增: ],
230新增: "Args": [
231新增: "name",
232新增: "{T0}/002"
233新增: ],
234新增: "Files": null,
235新增: "Stdout": "agent-vm-002-e8f570af\n",
236新增: "Stderr": "",
237新增: "Code": 0
238新增: },
239新增: {
240新增: "Dir": "{T0}/002",
241新增: "Stdin": "",
242新增: "Snippet": "agent-vm \"$@\"",
243新增: "Env": [
244新增: "HOME={T0}/030",
245新增: "PATH={T0}/029"
246新增: ],
247新增: "Args": [
248新增: "name",
249新增: "."
250新增: ],
251新增: "Files": null,
252新增: "Stdout": "agent-vm-002-e8f570af\n",
253新增: "Stderr": "",
254新增: "Code": 0
255新增: },
256新增: {
257新增: "Dir": "{T0}/002",
258新增: "Stdin": "",
259新增: "Snippet": "agent-vm \"$@\"",
260新增: "Env": [
261新增: "HOME={T0}/032",
262新增: "PATH={T0}/031"
263新增: ],
264新增: "Args": [
265新增: "name",
266新增: "{T0}/002/missing"
267新增: ],
268新增: "Files": null,
269新增: "Stdout": "",
270新增: "Stderr": "Error: no such directory: {T0}/002/missing\n",
271新增: "Code": 1
272新增: },
273新增: {
274新增: "Dir": "{T0}/002",
275新增: "Stdin": "",
276新增: "Snippet": "agent-vm \"$@\"",
277新增: "Env": [
278新增: "HOME={T0}/034",
279新增: "PATH={T0}/033"
280新增: ],
281新增: "Args": [
282新增: "frobnicate"
283新增: ],
284新增: "Files": null,
285新增: "Stdout": "",
286新增: "Stderr": "Unknown command: frobnicate\nRun 'agent-vm help' for usage.\n",
287新增: "Code": 1
288新增: },
289新增: {
290新增: "Dir": "{T0}/002",
291新增: "Stdin": "",
292新增: "Snippet": "agent-vm \"$@\"",
293新增: "Env": [
294新增: "HOME={T0}/036",
295新增: "PATH={T0}/035"
296新增: ],
297新增: "Args": [
298新增: "--disk"
299新增: ],
300新增: "Files": null,
301新增: "Stdout": "",
302新增: "Stderr": "Error: --disk needs a value.\n",
303新增: "Code": 1
304新增: },
305新增: {
306新增: "Dir": "{T0}/002",
307新增: "Stdin": "",
308新增: "Snippet": "agent-vm \"$@\"",
309新增: "Env": [
310新增: "HOME={T0}/038",
311新增: "PATH={T0}/037"
312新增: ],
313新增: "Args": [
314新增: "--disk",
315新增: "10G",
316新增: "claude"
317新增: ],
318新增: "Files": null,
319新增: "Stdout": "",
320新增: "Stderr": "Error: --disk must be a positive integer (got: '10G')\n",
321新增: "Code": 1
322新增: },
323新增: {
324新增: "Dir": "{T0}/002",
325新增: "Stdin": "",
326新增: "Snippet": "agent-vm \"$@\"",
327新增: "Env": [
328新增: "HOME={T0}/040",
329新增: "PATH={T0}/039"
330新增: ],
331新增: "Args": [
332新增: "--disk=0",
333新增: "shell"
334新增: ],
335新增: "Files": null,
336新增: "Stdout": "",
337新增: "Stderr": "Error: --disk must be a positive integer (got: '0')\n",
338新增: "Code": 1
339新增: },
340新增: {
341新增: "Dir": "{T0}/002",
342新增: "Stdin": "",
343新增: "Snippet": "agent-vm \"$@\"",
344新增: "Env": [
345新增: "HOME={T0}/042",
346新增: "PATH={T0}/041"
347新增: ],
348新增: "Args": [
349新增: "--memory",
350新增: "-1"
351新增: ],
352新增: "Files": null,
353新增: "Stdout": "",
354新增: "Stderr": "Error: --memory must be a positive integer (got: '-1')\n",
355新增: "Code": 1
356新增: },
357新增: {
358新增: "Dir": "{T0}/002",
359新增: "Stdin": "",
360新增: "Snippet": "agent-vm \"$@\"",
361新增: "Env": [
362新增: "HOME={T0}/044",
363新增: "PATH={T0}/043"
364新增: ],
365新增: "Args": [
366新增: "--ram=x"
367新增: ],
368新增: "Files": null,
369新增: "Stdout": "",
370新增: "Stderr": "Error: --memory must be a positive integer (got: 'x')\n",
371新增: "Code": 1
372新增: },
373新增: {
374新增: "Dir": "{T0}/002",
375新增: "Stdin": "",
376新增: "Snippet": "agent-vm \"$@\"",
377新增: "Env": [
378新增: "HOME={T0}/046",
379新增: "PATH={T0}/045"
380新增: ],
381新增: "Args": [
382新增: "--cpus",
383新增: "01"
384新增: ],
385新增: "Files": null,
386新增: "Stdout": "",
387新增: "Stderr": "Error: --cpus must be a positive integer (got: '01')\n",
388新增: "Code": 1
389新增: },
390新增: {
391新增: "Dir": "{T0}/002",
392新增: "Stdin": "",
393新增: "Snippet": "agent-vm \"$@\"",
394新增: "Env": [
395新增: "HOME={T0}/048",
396新增: "PATH={T0}/047"
397新增: ],
398新增: "Args": [
399新增: "--ssh-port",
400新增: "80"
401新增: ],
402新增: "Files": null,
403新增: "Stdout": "",
404新增: "Stderr": "Error: --ssh-port must be 0 or a port from 1024 to 65535 (got: '80')\n",
405新增: "Code": 1
406新增: },
407新增: {
408新增: "Dir": "{T0}/002",
409新增: "Stdin": "",
410新增: "Snippet": "agent-vm \"$@\"",
411新增: "Env": [
412新增: "HOME={T0}/050",
413新增: "PATH={T0}/049"
414新增: ],
415新增: "Args": [
416新增: "--ssh-port",
417新增: "70000"
418新增: ],
419新增: "Files": null,
420新增: "Stdout": "",
421新增: "Stderr": "Error: --ssh-port must be 0 or a port from 1024 to 65535 (got: '70000')\n",
422新增: "Code": 1
423新增: },
424新增: {
425新增: "Dir": "{T0}/002",
426新增: "Stdin": "",
427新增: "Snippet": "agent-vm \"$@\"",
428新增: "Env": [
429新增: "HOME={T0}/052",
430新增: "PATH={T0}/051"
431新增: ],
432新增: "Args": [
433新增: "--ssh-port=00"
434新增: ],
435新增: "Files": null,
436新增: "Stdout": "",
437新增: "Stderr": "Error: --ssh-port must be 0 or a port from 1024 to 65535 (got: '00')\n",
438新增: "Code": 1
439新增: },
440新增: {
441新增: "Dir": "{T0}/002",
442新增: "Stdin": "",
443新增: "Snippet": "agent-vm \"$@\"",
444新增: "Env": [
445新增: "HOME={T0}/054",
446新增: "PATH={T0}/053"
447新增: ],
448新增: "Args": [
449新增: "--readonly",
450新增: "stop"
451新增: ],
452新增: "Files": null,
453新增: "Stdout": "",
454新增: "Stderr": "Error: --readonly is an option for the commands that start a VM (claude, opencode, codex, vibe, pi, shell, run, code), not for 'stop'.\n",
455新增: "Code": 1
456新增: },
457新增: {
458新增: "Dir": "{T0}/002",
459新增: "Stdin": "",
460新增: "Snippet": "agent-vm \"$@\"",
461新增: "Env": [
462新增: "HOME={T0}/056",
463新增: "PATH={T0}/055"
464新增: ],
465新增: "Args": [
466新增: "--disk",
467新增: "10",
468新增: "--rm",
469新增: "list"
470新增: ],
471新增: "Files": null,
472新增: "Stdout": "",
473新增: "Stderr": "Error: --disk is an option for the commands that start a VM (claude, opencode, codex, vibe, pi, shell, run, code), not for 'list'.\n",
474新增: "Code": 1
475新增: },
476新增: {
477新增: "Dir": "{T0}/002",
478新增: "Stdin": "",
479新增: "Snippet": "agent-vm \"$@\"",
480新增: "Env": [
481新增: "HOME={T0}/058",
482新增: "PATH={T0}/057"
483新增: ],
484新增: "Args": [
485新增: "--rm",
486新增: "version"
487新增: ],
488新增: "Files": null,
489新增: "Stdout": "",
490新增: "Stderr": "Error: --rm is an option for the commands that start a VM (claude, opencode, codex, vibe, pi, shell, run, code), not for 'version'.\n",
491新增: "Code": 1
492新增: },
493新增: {
494新增: "Dir": "{T0}/002",
495新增: "Stdin": "",
496新增: "Snippet": "agent-vm \"$@\"",
497新增: "Env": [
498新增: "HOME={T0}/060",
499新增: "PATH={T0}/059"
500新增: ],
501新增: "Args": [
502新增: "--scratch",
503新增: "help"
504新增: ],
505新增: "Files": null,
506新增: "Stdout": "",
507新增: "Stderr": "Error: --scratch is an option for the commands that start a VM (claude, opencode, codex, vibe, pi, shell, run, code), not for 'help'.\n",
508新增: "Code": 1
509新增: },
510新增: {
511新增: "Dir": "{T0}/002",
512新增: "Stdin": "",
513新增: "Snippet": "agent-vm \"$@\"",
514新增: "Env": [
515新增: "HOME={T0}/062",
516新增: "PATH={T0}/061"
517新增: ],
518新增: "Args": [
519新增: "--unsafe-writable-git=1",
520新增: "name"
521新增: ],
522新增: "Files": null,
523新增: "Stdout": "",
524新增: "Stderr": "Error: --unsafe-writable-git=1 is an option for the commands that start a VM (claude, opencode, codex, vibe, pi, shell, run, code), not for 'name'.\n",
525新增: "Code": 1
526新增: },
527新增: {
528新增: "Dir": "{T0}/002",
529新增: "Stdin": "",
530新增: "Snippet": "agent-vm \"$@\"",
531新增: "Env": [
532新增: "HOME={T0}/064",
533新增: "PATH={T0}/063"
534新增: ],
535新增: "Args": [
536新增: "--unsafe-disable-security-prompts",
537新增: "doctor"
538新增: ],
539新增: "Files": null,
540新增: "Stdout": "",
541新增: "Stderr": "Error: --unsafe-disable-security-prompts is an option for the commands that start a VM (claude, opencode, codex, vibe, pi, shell, run, code), not for 'doctor'.\n",
542新增: "Code": 1
543新增: }
544新增: ]
545新增:}
新增internal/cli/testdata/bashref/TestProjectEnvGitBash.json+46 −0看文件
@@ -0,0 +1,46 @@
1新增:{
2新增: "TestProjectEnvGitBash": [
3新增: {
4新增: "Dir": "{T0}/002/sub",
5新增: "Stdin": "",
6新增: "Snippet": "agent-vm \"$@\"",
7新增: "Env": [
8新增: "HOME={T0}/004",
9新增: "PWD={T0}/002/sub",
10新增: "GIT_CONFIG_GLOBAL=/dev/null",
11新增: "GIT_CONFIG_NOSYSTEM=1"
12新增: ],
13新增: "Args": [
14新增: "project-env",
15新增: "set",
16新增: "K",
17新增: "v"
18新增: ],
19新增: "Files": null,
20新增: "Stdout": "",
21新增: "Stderr": "Warning: sub/.agent-vm.env is not ignored by git: it can be committed by accident.\n echo '/sub/.agent-vm.env' \u003e\u003e '{T0}/002/.gitignore'\n",
22新增: "Code": 0
23新增: },
24新增: {
25新增: "Dir": "{T0}/006/sub",
26新增: "Stdin": "",
27新增: "Snippet": "agent-vm \"$@\"",
28新增: "Env": [
29新增: "HOME={T0}/008",
30新增: "PWD={T0}/006/sub",
31新增: "GIT_CONFIG_GLOBAL=/dev/null",
32新增: "GIT_CONFIG_NOSYSTEM=1"
33新增: ],
34新增: "Args": [
35新增: "project-env",
36新增: "set",
37新增: "K",
38新增: "v"
39新增: ],
40新增: "Files": null,
41新增: "Stdout": "",
42新增: "Stderr": "Warning: sub/.agent-vm.env is tracked by git: its contents are in the repository.\n git -C '{T0}/006' rm --cached 'sub/.agent-vm.env' \u0026\u0026 echo '/sub/.agent-vm.env' \u003e\u003e '{T0}/006/.gitignore'\n",
43新增: "Code": 0
44新增: }
45新增: ]
46新增:}
新增internal/cli/vms.go+243 −0看文件
@@ -0,0 +1,243 @@
1新增:package cli
2新增:
3新增:import (
4新增: "context"
5新增: "errors"
6新增: "fmt"
7新增: "strings"
8新增: "text/tabwriter"
9新增:
10新增: "github.com/docker/go-units"
11新增:
12新增: "github.com/sylvinus/agent-vm/internal/paths"
13新增: "github.com/sylvinus/agent-vm/internal/vm"
14新增: "github.com/sylvinus/agent-vm/internal/vmname"
15新增:)
16新增:
17新增:// target is the VM `stop` and `rm` act on: the current directory's, or one
18新增:// named as `list` prints it. Agent-vm's Lima home holds its VMs alone (see
19新增:// newApp), so any name there is one of them. A VM no folder names any more
20新增:// (renamed, deleted) is reached by its name. The status is 0 when the VM is
21新增:// found, else the exit status of the command.
22新增:func (e *app) target(ctx context.Context, verb string, args []string) (name string, status int) {
23新增: switch len(args) {
24新增: case 0:
25新增: wd, err := vmname.AbsDir("")
26新增: if err != nil {
27新增: fmt.Fprintf(e.io.Stderr, "Error: %v\n", err)
28新增: return "", 1
29新增: }
30新增: name = vmname.Name(wd)
31新增: case 1:
32新增: name = args[0]
33新增: default:
34新增: fmt.Fprintf(e.io.Stderr, "Usage: agent-vm %s [vm-name]\n", verb)
35新增: return "", exitUsage
36新增: }
37新增: b, err := e.backend()
38新增: if err == nil {
39新增: _, err = b.Get(ctx, name)
40新增: }
41新增: switch {
42新增: case err == nil:
43新增: return name, 0
44新增: case errors.Is(err, vm.ErrNotFound) && len(args) == 0:
45新增: fmt.Fprintln(e.io.Stderr, "No VM found for this directory.")
46新增: fmt.Fprintf(e.io.Stderr, "Run 'agent-vm list' to see existing VMs, then 'agent-vm %s <vm-name>'.\n", verb)
47新增: case errors.Is(err, vm.ErrNotFound):
48新增: fmt.Fprintf(e.io.Stderr, "Error: no such VM: %s\n", name)
49新增: fmt.Fprintln(e.io.Stderr, "Run 'agent-vm list' to see existing VMs.")
50新增: default:
51新增: fmt.Fprintf(e.io.Stderr, "Error: could not query Lima: %v\n", err)
52新增: }
53新增: return "", 1
54新增:}
55新增:
56新增:func (e *app) stopCmd(ctx context.Context, args []string) int {
57新增: name, status := e.target(ctx, "stop", args)
58新增: if status != 0 {
59新增: return status
60新增: }
61新增: fmt.Fprintf(e.io.Stdout, "Stopping VM '%s'...\n", name)
62新增: if !e.stopVM(ctx, name) {
63新增: fmt.Fprintf(e.io.Stderr, "Error: VM '%s' is still running, or Lima cannot say. See 'agent-vm list'.\n", name)
64新增: return 1
65新增: }
66新增: fmt.Fprintln(e.io.Stdout, "VM stopped.")
67新增: return 0
68新增:}
69新增:
70新增:// stopVM stops name, and reports whether it is known to be stopped.
71新增:func (e *app) stopVM(ctx context.Context, name string) bool {
72新增: b, err := e.backend()
73新增: if err != nil {
74新增: return false
75新增: }
76新增: _ = b.Stop(ctx, name)
77新增: inst, err := b.Get(ctx, name)
78新增: return err == nil && inst.Status != vm.Running
79新增:}
80新增:
81新增:func (e *app) rmCmd(ctx context.Context, args []string) int {
82新增: name, status := e.target(ctx, "rm", args)
83新增: if status != 0 {
84新增: return status
85新增: }
86新增: if !e.removeVM(ctx, name) {
87新增: return 1
88新增: }
89新增: return 0
90新增:}
91新增:
92新增:// removeVM stops and deletes name, saying so, and reports whether it is gone.
93新增:func (e *app) removeVM(ctx context.Context, name string) bool {
94新增: fmt.Fprintf(e.io.Stdout, "Stopping and deleting VM '%s'...\n", name)
95新增: if !e.deleteVM(ctx, name) {
96新增: return false
97新增: }
98新增: fmt.Fprintln(e.io.Stdout, "VM destroyed.")
99新增: return true
100新增:}
101新增:
102新增:// deleteVM stops and deletes name, then forgets what agent-vm knew of it.
103新增:// Fails, saying so, when it is still there (or cannot be asked): --reset
104新增:// would otherwise go on with the old VM and its shares.
105新增:func (e *app) deleteVM(ctx context.Context, name string) bool {
106新增: b, err := e.backend()
107新增: if err == nil {
108新增: _ = b.Delete(ctx, name)
109新增: _, err = b.Get(ctx, name)
110新增: }
111新增: if !errors.Is(err, vm.ErrNotFound) {
112新增: fmt.Fprintf(e.io.Stderr, "Error: could not delete VM '%s'. See 'agent-vm list', then retry.\n", name)
113新增: return false
114新增: }
115新增: if err := e.state.Forget(name, vmname.Template); err != nil {
116新增: fmt.Fprintf(e.io.Stderr, "Warning: %v\n", err)
117新增: }
118新增: return true
119新增:}
120新增:
121新增:// `destroy-all`: every agent-vm VM, the base template included: the command
122新增:// that gives the disk space back. `agent-vm setup` rebuilds the template.
123新增:func (e *app) destroyAllCmd(ctx context.Context, args []string) int {
124新增: if len(args) > 0 {
125新增: fmt.Fprintln(e.io.Stderr, "Usage: agent-vm destroy-all")
126新增: return exitUsage
127新增: }
128新增: vms, err := e.agentVMs(ctx)
129新增: if err != nil {
130新增: fmt.Fprintf(e.io.Stderr, "Error: could not query Lima: %v\n", err)
131新增: return 1
132新增: }
133新增: if len(vms) == 0 {
134新增: fmt.Fprintln(e.io.Stdout, "No agent-vm VMs found.")
135新增: return 0
136新增: }
137新增: fmt.Fprintln(e.io.Stdout, "This will destroy the following VMs:")
138新增: base := false
139新增: for _, v := range vms {
140新增: fmt.Fprintln(e.io.Stdout, v.Name)
141新增: base = base || v.Name == vmname.Template
142新增: }
143新增: if base {
144新增: fmt.Fprintf(e.io.Stdout, "(%s is the base template: 'agent-vm setup' rebuilds it.)\n", vmname.Template)
145新增: }
146新增: if !e.ui.CanAsk() {
147新增: fmt.Fprintln(e.io.Stderr, "Error: destroy-all asks before it deletes, and there is no terminal to ask on. Nothing was destroyed.")
148新增: return 1
149新增: }
150新增: if !e.ui.AskYN("Continue?", false) {
151新增: fmt.Fprintln(e.io.Stdout, "Aborted.")
152新增: return 0
153新增: }
154新增: st := 0
155新增: for _, v := range vms {
156新增: fmt.Fprintf(e.io.Stdout, "Destroying %s...\n", v.Name)
157新增: if !e.deleteVM(ctx, v.Name) {
158新增: st = 1
159新增: }
160新增: }
161新增: if st != 0 {
162新增: return st
163新增: }
164新增: fmt.Fprintln(e.io.Stdout, "All VMs destroyed.")
165新增: return 0
166新增:}
167新增:
168新增:// agentVMs lists the VMs, after moving 0.2's: for the commands that change
169新增:// them.
170新增:func (e *app) agentVMs(ctx context.Context) ([]*vm.Instance, error) {
171新增: b, err := e.backend()
172新增: if err != nil {
173新增: return nil, err
174新增: }
175新增: return b.List(ctx)
176新增:}
177新增:
178新增:// lookVMs lists the VMs without moving 0.2's: for the commands that only look.
179新增:func (e *app) lookVMs(ctx context.Context) ([]*vm.Instance, error) {
180新增: b, err := e.readOnlyBackend()
181新增: if err != nil {
182新增: return nil, err
183新增: }
184新增: return b.List(ctx)
185新增:}
186新增:
187新增:// `list`, `status`: the agent-vm VMs as Lima's table shows them, the
188新增:// current directory's marked with >, and the base each was cloned from in a
189新增:// last column. Read-only: 0.2's VMs are said to wait, not moved.
190新增:func (e *app) listCmd(ctx context.Context, args []string) int {
191新增: if len(args) > 0 {
192新增: fmt.Fprintln(e.io.Stderr, "Usage: agent-vm list")
193新增: return exitUsage
194新增: }
195新增: current := ""
196新增: if wd, err := vmname.AbsDir(""); err == nil {
197新增: current = vmname.Name(wd)
198新增: }
199新增: vms, err := e.lookVMs(ctx)
200新增: if err != nil {
201新增: fmt.Fprintf(e.io.Stderr, "Error: could not query Lima: %v\n", err)
202新增: return 1
203新增: }
204新增: if old, from := e.unmovedOld(); len(old) > 0 {
205新增: fmt.Fprintf(e.io.Stderr, "%d VM(s) of agent-vm 0.2 in %s are not listed: the next command that starts a VM offers to move them.\n", len(old), from)
206新增: }
207新增: if len(vms) == 0 {
208新增: fmt.Fprintln(e.io.Stdout, " (no VMs)")
209新增: return 0
210新增: }
211新增: lines := strings.Split(strings.TrimSuffix(table(vms), "\n"), "\n")
212新增: w := 0
213新增: for _, l := range lines {
214新增: w = max(w, len(l))
215新增: }
216新增: fmt.Fprintf(e.io.Stdout, " %-*s %s\n", w, lines[0], "BASE")
217新增: for i, l := range lines[1:] {
218新增: mark := " "
219新增: if vms[i].Name == current {
220新增: mark = ">"
221新增: }
222新增: fmt.Fprintf(e.io.Stdout, "%s %-*s %s\n", mark, w, l, e.state.BaseLabel(vms[i].Name, vmname.Template))
223新增: }
224新增: return 0
225新增:}
226新增:
227新增:// table is Lima's `limactl list` table, every column shown.
228新增:func table(vms []*vm.Instance) string {
229新增: var b strings.Builder
230新增: w := tabwriter.NewWriter(&b, 4, 8, 4, ' ', 0)
231新增: fmt.Fprintln(w, "NAME\tSTATUS\tSSH\tVMTYPE\tARCH\tCPUS\tMEMORY\tDISK\tDIR")
232新增: home := paths.Home()
233新增: for _, v := range vms {
234新增: dir := paths.Host(v.Dir)
235新增: if rel, ok := paths.In(dir, home); ok {
236新增: dir = strings.TrimSuffix("~/"+rel, "/.")
237新增: }
238新增: fmt.Fprintf(w, "%s\t%s\t%s:%d\t%s\t%s\t%d\t%s\t%s\t%s\n", v.Name, v.Status, v.SSHAddress, v.SSHLocalPort,
239新增: v.VMType, v.Arch, v.CPUs, units.BytesSize(float64(v.Memory)), units.BytesSize(float64(v.Disk)), dir)
240新增: }
241新增: w.Flush()
242新增: return b.String()
243新增:}
新增internal/cli/vms_test.go+222 −0看文件
@@ -0,0 +1,222 @@
1新增:package cli
2新增:
3新增:import (
4新增: "bytes"
5新增: "context"
6新增: "errors"
7新增: "io"
8新增: "os"
9新增: "path/filepath"
10新增: "strings"
11新增: "testing"
12新增: "time"
13新增:
14新增: "github.com/sylvinus/agent-vm/internal/state"
15新增: "github.com/sylvinus/agent-vm/internal/ui"
16新增: "github.com/sylvinus/agent-vm/internal/vm"
17新增: "github.com/sylvinus/agent-vm/internal/vm/vmtest"
18新增: "github.com/sylvinus/agent-vm/internal/vmname"
19新增:)
20新增:
21新增:// testEnv runs commands against fake, with a state folder of its own and
22新增:// no terminal, unless answers are given: then one is asked each time.
23新增:type testEnv struct {
24新增: *app
25新增: fake *vmtest.Fake
26新增: stdout, stderr bytes.Buffer
27新增:}
28新增:
29新增:func newTestEnv(t *testing.T, fake *vmtest.Fake, answers ...string) *testEnv {
30新增: t.Helper()
31新增: te := &testEnv{fake: fake}
32新增: u := &ui.UI{Stderr: &te.stderr, OpenTTY: func() (io.ReadCloser, error) { return nil, errors.New("no tty") }}
33新增: if answers != nil {
34新增: u.StderrIsTerminal = true
35新增: pop := func() string {
36新增: a := ""
37新增: if len(answers) > 0 {
38新增: a, answers = answers[0], answers[1:]
39新增: }
40新增: return a
41新增: }
42新增: u.OpenTTY = func() (io.ReadCloser, error) { return &answer{pop: pop}, nil }
43新增: }
44新增: te.app = &app{
45新增: io: IO{Stdin: strings.NewReader(""), Stdout: &te.stdout, Stderr: &te.stderr},
46新增: ui: u,
47新增: state: state.Dir(t.TempDir()),
48新增: newBack: func() (vm.Backend, error) { return fake, nil },
49新增: }
50新增: return te
51新增:}
52新增:
53新增:// answer is a terminal that holds the next answer once read: opening it to
54新增:// see whether there is one (CanAsk) takes none.
55新增:type answer struct {
56新增: pop func() string
57新增: r io.Reader
58新增:}
59新增:
60新增:func (a *answer) Read(p []byte) (int, error) {
61新增: if a.r == nil {
62新增: a.r = strings.NewReader(a.pop())
63新增: }
64新增: return a.r.Read(p)
65新增:}
66新增:
67新增:func (a *answer) Close() error { return nil }
68新增:
69新增:func (te *testEnv) run(args ...string) int {
70新增: te.stdout.Reset()
71新增: te.stderr.Reset()
72新增: te.fake.Calls = nil
73新增: return te.main(context.Background(), args)
74新增:}
75新增:
76新增:func (te *testEnv) out() string { return te.stdout.String() + te.stderr.String() }
77新增:
78新增:func running(name string) *vm.Instance { return &vm.Instance{Name: name, Status: vm.Running} }
79新增:
80新增:func TestStopRm(t *testing.T) {
81新增: te := newTestEnv(t, vmtest.New(running("proj-deadbeef")))
82新增: if te.run("stop", "proj-deadbeef") != 0 || te.fake.CallLog() != "stop proj-deadbeef" {
83新增: t.Errorf("stop <name>: %s %s", te.fake.CallLog(), te.out())
84新增: }
85新增: if te.out() != "Stopping VM 'proj-deadbeef'...\nVM stopped.\n" {
86新增: t.Errorf("stop said: %q", te.out())
87新增: }
88新增:
89新增: // A VM that stays running is said, not reported as stopped.
90新增: te.fake.VMs["proj-deadbeef"].Status = vm.Running
91新增: te.fake.Sticky["proj-deadbeef"] = true
92新增: if te.run("stop", "proj-deadbeef") != 1 || !strings.Contains(te.out(), "is still running") {
93新增: t.Errorf("stop that did not take: %s", te.out())
94新增: }
95新增: // Nor a delete that did not take.
96新增: os.WriteFile(te.state.Marker(state.VersionOf, "proj-deadbeef"), []byte("1\n"), 0o644)
97新增: if te.run("rm", "proj-deadbeef") != 1 || !strings.Contains(te.out(), "could not delete VM 'proj-deadbeef'") ||
98新增: strings.Contains(te.out(), "VM destroyed.") {
99新增: t.Errorf("rm that did not take: %s", te.out())
100新增: }
101新增: if _, err := os.Stat(te.state.Marker(state.VersionOf, "proj-deadbeef")); err != nil {
102新增: t.Error("a VM still there was forgotten")
103新增: }
104新增: te.fake.Sticky = map[string]bool{}
105新增: if te.run("rm", "proj-deadbeef") != 0 || te.fake.CallLog() != "delete proj-deadbeef" || !strings.HasSuffix(te.out(), "VM destroyed.\n") {
106新增: t.Errorf("rm <name>: %s %s", te.fake.CallLog(), te.out())
107新增: }
108新增: if _, err := os.Stat(te.state.Marker(state.VersionOf, "proj-deadbeef")); !os.IsNotExist(err) {
109新增: t.Error("rm left the VM's markers")
110新增: }
111新增:
112新增: // agent-vm's Lima home holds its VMs alone: any name is looked up.
113新增: if te.run("rm", "some-other-vm") != 1 || !strings.Contains(te.out(), "no such VM: some-other-vm") || te.fake.CallLog() != "" {
114新增: t.Errorf("rm unknown: %s %s", te.out(), te.fake.CallLog())
115新增: }
116新增: if te.run("stop", "does-not-exist") != 1 || !strings.Contains(te.out(), "no such VM: does-not-exist") || te.fake.CallLog() != "" {
117新增: t.Errorf("stop unknown: %s", te.out())
118新增: }
119新增: if te.run("stop", "a-00000000", "b-00000000") != exitUsage || !strings.Contains(te.out(), "Usage: agent-vm stop [vm-name]") {
120新增: t.Errorf("stop two: %s", te.out())
121新增: }
122新增:
123新增: // Without a name, the current directory's VM.
124新增: proj := t.TempDir()
125新增: t.Chdir(proj)
126新增: t.Setenv("PWD", proj)
127新增: if te.run("stop") != 1 || !strings.Contains(te.out(), "No VM found for this directory.") {
128新增: t.Errorf("stop, no VM here: %s", te.out())
129新增: }
130新增: te.fake.VMs[vmname.Name(proj)] = running(vmname.Name(proj))
131新增: if te.run("stop") != 0 || te.fake.CallLog() != "stop "+vmname.Name(proj) {
132新增: t.Errorf("stop here: %s %s", te.fake.CallLog(), te.out())
133新增: }
134新增:}
135新增:
136新增:func TestDestroyAll(t *testing.T) {
137新增: te := newTestEnv(t, vmtest.New(running("a-00000000"), running("base")))
138新增: if te.run("destroy-all") != 1 || !strings.Contains(te.out(), "no terminal to ask on. Nothing was destroyed.") || te.fake.CallLog() != "" {
139新增: t.Errorf("no terminal: %s %s", te.out(), te.fake.CallLog())
140新增: }
141新增: if !strings.Contains(te.out(), "(base is the base template: 'agent-vm setup' rebuilds it.)") {
142新增: t.Errorf("the base is not named: %s", te.out())
143新增: }
144新增: te = newTestEnv(t, te.fake, "n\n")
145新增: if te.run("destroy-all") != 0 || te.fake.CallLog() != "" {
146新增: t.Errorf("a no: %s", te.fake.CallLog())
147新增: }
148新增: te = newTestEnv(t, te.fake, "y\n", "y\n")
149新增: te.fake.Sticky["a-00000000"] = true
150新增: if te.run("destroy-all") != 1 || !strings.Contains(te.out(), "could not delete VM 'a-00000000'") || strings.Contains(te.out(), "All VMs destroyed.") {
151新增: t.Errorf("one stays: %s", te.out())
152新增: }
153新增: te.fake.Sticky = map[string]bool{}
154新增: te.fake.VMs["base"] = running("base")
155新增: os.MkdirAll(string(te.state), 0o755)
156新增: for _, f := range []string{state.BaseVersion, state.BaseBuiltBy} {
157新增: os.WriteFile(te.state.Path(f), []byte("x\n"), 0o644)
158新增: }
159新增: if te.run("destroy-all") != 0 || !strings.HasSuffix(te.stdout.String(), "All VMs destroyed.\n") || len(te.fake.VMs) != 0 {
160新增: t.Errorf("a yes: %s", te.out())
161新增: }
162新增: for _, f := range []string{state.BaseVersion, state.BaseBuiltBy} {
163新增: if _, err := os.Stat(te.state.Path(f)); err == nil {
164新增: t.Errorf("%s left: the next start would take a missing base as ready", f)
165新增: }
166新增: }
167新增: if te.run("destroy-all") != 0 || te.out() != "No agent-vm VMs found.\n" {
168新增: t.Errorf("none left: %q", te.out())
169新增: }
170新增: te.fake.Err = errors.New("broken")
171新增: if te.run("destroy-all") != 1 || !strings.Contains(te.out(), "could not query Lima") {
172新增: t.Errorf("a backend that fails: %s", te.out())
173新增: }
174新增:}
175新增:
176新增:func TestList(t *testing.T) {
177新增: proj := t.TempDir()
178新增: t.Chdir(proj)
179新增: t.Setenv("PWD", proj)
180新增: here := vmname.Name(proj)
181新增: te := newTestEnv(t, vmtest.New())
182新增: if te.run("list") != 0 || te.out() != " (no VMs)\n" {
183新增: t.Errorf("no VM: %q", te.out())
184新增: }
185新增: te.fake.VMs[here] = &vm.Instance{Name: here, Status: vm.Running, SSHAddress: "127.0.0.1", SSHLocalPort: 60022,
186新增: VMType: "qemu", Arch: "aarch64", CPUs: 2, Memory: 4 << 30, Disk: 10 << 30, Dir: filepath.Join(proj, "lima", here)}
187新增: te.fake.VMs["base"] = &vm.Instance{Name: "base", Status: vm.Stopped, VMType: "qemu", Arch: "aarch64", CPUs: 1, Memory: 2 << 30, Disk: 10 << 30}
188新增: os.WriteFile(te.state.Path(state.BaseVersion), []byte("1759000000\n"), 0o644)
189新增: os.WriteFile(te.state.Path(state.BaseBuiltBy), []byte("0.2.1\n"), 0o644)
190新增: os.WriteFile(te.state.Marker(state.BuiltByOf, here), []byte("0.2.0\n"), 0o644)
191新增: if te.run("status") != 0 {
192新增: t.Fatal(te.out())
193新增: }
194新增: // Rows in name order, this folder's marked, the base last and aligned.
195新增: day := time.Unix(1759000000, 0).Format("2006-01-02")
196新增: want := map[string]string{" NAME ": "BASE", " base ": "0.2.1 " + day, "> " + here + " ": "0.2.0 -"}
197新增: lines := strings.Split(strings.TrimSuffix(te.out(), "\n"), "\n")
198新增: col := -1
199新增: for _, l := range lines {
200新增: found := false
201新增: for prefix, label := range want {
202新增: if strings.HasPrefix(l, prefix) && strings.HasSuffix(l, " "+label) {
203新增: found = true
204新增: if c := len(l) - len(label); col >= 0 && c != col {
205新增: t.Errorf("BASE not aligned in %q", l)
206新增: } else {
207新增: col = c
208新增: }
209新增: }
210新增: }
211新增: if !found {
212新增: t.Errorf("unexpected line %q", l)
213新增: }
214新增: }
215新增: if len(lines) != 3 {
216新增: t.Errorf("list:\n%s", te.out())
217新增: }
218新增: te.fake.Err = errors.New("broken")
219新增: if te.run("list") != 1 || !strings.Contains(te.out(), "could not query Lima") {
220新增: t.Errorf("failing backend: %s", te.out())
221新增: }
222新增:}
新增internal/desktop/desktop.go+119 −0看文件
@@ -0,0 +1,119 @@
1新增:// Package desktop reaches the user out of any terminal: notifications and
2新增:// yes/no dialogs, where the desktop has a way (osascript on macOS; notify-send,
3新增:// zenity or kdialog on Linux). Text always goes as arguments, never as script.
4新增:package desktop
5新增:
6新增:import (
7新增: "context"
8新增: "errors"
9新增: "os"
10新增: "os/exec"
11新增: "runtime"
12新增: "strings"
13新增: "time"
14新增:)
15新增:
16新增:// Notify shows a notification, without waiting; nothing where there is no
17新增:// way.
18新增:func Notify(title, msg string) {
19新增: var cmd *exec.Cmd
20新增: switch runtime.GOOS {
21新增: case "darwin":
22新增: cmd = exec.Command("osascript", "-e", "on run argv", "-e", "display notification (item 2 of argv) with title (item 1 of argv)", "-e", "end run", title, msg)
23新增: case "linux":
24新增: if _, err := exec.LookPath("notify-send"); err != nil {
25新增: return
26新增: }
27新增: cmd = exec.Command("notify-send", "--", title, msg)
28新增: default:
29新增: return
30新增: }
31新增: if cmd.Start() == nil {
32新增: go func() { _ = cmd.Wait() }()
33新增: }
34新增:}
35新增:
36新增:// Ask shows a dialog with Deny (the default) and Allow, until ctx ends (a
37新增:// refusal). ok is false when no dialog could be shown (no tool, no display or
38新增:// graphical session, the tool failed to start): allow is then false and nobody
39新增:// answered. ok is true when the user answered, or ctx ended with the dialog up.
40新增:func Ask(ctx context.Context, title, msg string) (allow, ok bool) {
41新增: switch runtime.GOOS {
42新增: case "darwin":
43新增: res := run(ctx, "osascript", "-e", "on run argv",
44新增: "-e", `display dialog (item 2 of argv) with title (item 1 of argv) buttons {"Deny", "Allow"} default button "Deny" with icon caution`,
45新增: "-e", "end run", title, msg)
46新增: switch {
47新增: case res.err == nil:
48新增: return strings.Contains(res.stdout, "button returned:Allow"), true
49新增: case res.timedOut:
50新增: return false, true
51新增: }
52新增: // Deny by closing the dialog is "User canceled. (-128)", an exit status 1. Without a
53新增: // graphical session osascript exits 1 as well, with another error.
54新增: return false, strings.Contains(res.stderr, "(-128)")
55新增: case "linux":
56新增: if os.Getenv("DISPLAY") == "" && os.Getenv("WAYLAND_DISPLAY") == "" {
57新增: return false, false
58新增: }
59新增: if _, err := exec.LookPath("zenity"); err == nil {
60新增: res := run(ctx, "zenity", "--question", "--title", title, "--text", msg,
61新增: "--ok-label=Allow", "--cancel-label=Deny", "--default-cancel", "--no-markup")
62新增: if allow, ok := linuxAnswer(res, 1, "cannot open display", "failed to open display", "unable to init server"); ok {
63新增: return allow, true
64新增: }
65新增: }
66新增: if _, err := exec.LookPath("kdialog"); err == nil {
67新增: res := run(ctx, "kdialog", "--title", title, "--warningyesno", msg,
68新增: "--yes-label", "Allow", "--no-label", "Deny")
69新增: if allow, ok := linuxAnswer(res, 2, "could not connect to display", "cannot connect to x server", "no qt platform plugin"); ok {
70新增: return allow, true
71新增: }
72新增: }
73新增: }
74新增: return false, false
75新增:}
76新增:
77新增:// linuxAnswer reads the result of zenity or kdialog: exit 0 is Allow, and an exit status up to
78新增:// maxDeny is Deny, unless stderr says the tool had no display to show the dialog on.
79新增:func linuxAnswer(res result, maxDeny int, noDisplay ...string) (allow, ok bool) {
80新增: if res.err == nil {
81新增: return true, true
82新增: }
83新增: if res.timedOut {
84新增: return false, true
85新增: }
86新增: if res.code < 1 || res.code > maxDeny {
87新增: return false, false
88新增: }
89新增: stderr := strings.ToLower(res.stderr)
90新增: for _, s := range noDisplay {
91新增: if strings.Contains(stderr, s) {
92新增: return false, false
93新增: }
94新增: }
95新增: return false, true
96新增:}
97新增:
98新增:type result struct {
99新增: stdout, stderr string
100新增: err error
101新增: code int // the exit status, -1 when the tool did not exit (not found, killed)
102新增: timedOut bool // ctx ended while the tool ran
103新增:}
104新增:
105新增:func run(ctx context.Context, name string, args ...string) result {
106新增: cmd := exec.CommandContext(ctx, name, args...)
107新增: var stdout, stderr strings.Builder
108新增: cmd.Stdout, cmd.Stderr = &stdout, &stderr
109新增: cmd.WaitDelay = time.Second
110新增: err := cmd.Run()
111新增: res := result{stdout: stdout.String(), stderr: stderr.String(), err: err, code: -1}
112新增: var ee *exec.ExitError
113新增: if errors.As(err, &ee) {
114新增: res.code = ee.ExitCode()
115新增: // Killed when ctx ended, rather than exited.
116新增: res.timedOut = res.code == -1 && ctx.Err() != nil
117新增: }
118新增: return res
119新增:}
新增internal/desktop/desktop_test.go+137 −0看文件
@@ -0,0 +1,137 @@
1新增:package desktop
2新增:
3新增:import (
4新增: "context"
5新增: "fmt"
6新增: "os"
7新增: "path/filepath"
8新增: "runtime"
9新增: "testing"
10新增: "time"
11新增:)
12新增:
13新增:// fake puts a shell script named name first in PATH, and nothing else that could show a dialog.
14新增:func fake(t *testing.T, name, script string) {
15新增: t.Helper()
16新增: dir := t.TempDir()
17新增: if script != "" {
18新增: if err := os.WriteFile(filepath.Join(dir, name), []byte("#!/bin/sh\n"+script+"\n"), 0o755); err != nil {
19新增: t.Fatal(err)
20新增: }
21新增: }
22新增: // /usr/bin and /bin for sh and sleep: no dialog tool lives there in the test environment.
23新增: t.Setenv("PATH", dir+":/usr/bin:/bin")
24新增:}
25新增:
26新增:type want struct{ allow, ok bool }
27新增:
28新增:func TestAskLinux(t *testing.T) {
29新增: if runtime.GOOS != "linux" {
30新增: t.Skip("linux")
31新增: }
32新增: for _, tool := range []struct {
33新增: name string
34新增: deny int // the exit status of a Deny
35新增: display string
36新增: }{
37新增: {"zenity", 1, "cannot open display"},
38新增: {"kdialog", 1, "could not connect to display"},
39新增: {"kdialog", 2, "cannot connect to X server"},
40新增: } {
41新增: for _, c := range []struct {
42新增: name string
43新增: script string
44新增: env string
45新增: want want
46新增: }{
47新增: {"allow", "exit 0", ":0", want{true, true}},
48新增: {"deny", fmt.Sprintf("exit %d", tool.deny), ":0", want{false, true}},
49新增: {"no display tool", "echo '" + tool.display + "' >&2; exit 1", ":0", want{false, false}},
50新增: {"crash", "kill -SEGV $$", ":0", want{false, false}},
51新增: {"no display variable", "exit 0", "", want{false, false}},
52新增: {"tool missing", "", ":0", want{false, false}},
53新增: } {
54新增: t.Run(tool.name+"/"+c.name, func(t *testing.T) {
55新增: t.Setenv("DISPLAY", c.env)
56新增: t.Setenv("WAYLAND_DISPLAY", "")
57新增: fake(t, tool.name, c.script)
58新增: allow, ok := Ask(context.Background(), "t", "m")
59新增: if (want{allow, ok}) != c.want {
60新增: t.Errorf("got allow=%v ok=%v, want %v", allow, ok, c.want)
61新增: }
62新增: })
63新增: }
64新增: }
65新增:}
66新增:
67新增:// zenity that cannot show a dialog falls back to kdialog.
68新增:func TestAskLinuxFallback(t *testing.T) {
69新增: if runtime.GOOS != "linux" {
70新增: t.Skip("linux")
71新增: }
72新增: t.Setenv("DISPLAY", ":0")
73新增: t.Setenv("WAYLAND_DISPLAY", "")
74新增: fake(t, "zenity", "echo 'cannot open display' >&2; exit 1")
75新增: dir := filepath.SplitList(os.Getenv("PATH"))[0]
76新增: if err := os.WriteFile(filepath.Join(dir, "kdialog"), []byte("#!/bin/sh\nexit 0\n"), 0o755); err != nil {
77新增: t.Fatal(err)
78新增: }
79新增: if allow, ok := Ask(context.Background(), "t", "m"); !allow || !ok {
80新增: t.Errorf("got allow=%v ok=%v", allow, ok)
81新增: }
82新增:}
83新增:
84新增:// The dialog is up when the context ends: an answer, a refusal.
85新增:func TestAskTimeout(t *testing.T) {
86新增: var tool string
87新增: switch runtime.GOOS {
88新增: case "linux":
89新增: tool = "zenity"
90新增: t.Setenv("DISPLAY", ":0")
91新增: t.Setenv("WAYLAND_DISPLAY", "")
92新增: case "darwin":
93新增: tool = "osascript"
94新增: default:
95新增: t.Skip("no dialog")
96新增: }
97新增: fake(t, tool, "exec sleep 30")
98新增: ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
99新增: defer cancel()
100新增: start := time.Now()
101新增: allow, ok := Ask(ctx, "t", "m")
102新增: if allow || !ok {
103新增: t.Errorf("got allow=%v ok=%v", allow, ok)
104新增: }
105新增: if time.Since(start) > 10*time.Second {
106新增: t.Error("did not stop with the context")
107新增: }
108新增:}
109新增:
110新增:func TestAskDarwin(t *testing.T) {
111新增: if runtime.GOOS != "darwin" {
112新增: t.Skip("macOS")
113新增: }
114新增: for _, c := range []struct {
115新增: name string
116新增: script string
117新增: want want
118新增: }{
119新增: {"allow", "echo 'button returned:Allow'", want{true, true}},
120新增: {"deny button", "echo 'button returned:Deny'", want{false, true}},
121新增: {"closed", "echo 'execution error: User canceled. (-128)' >&2; exit 1", want{false, true}},
122新增: {"no session", "echo 'execution error: Application isn'\\''t running. (-600)' >&2; exit 1", want{false, false}},
123新增: {"missing", "", want{false, false}},
124新增: } {
125新增: t.Run(c.name, func(t *testing.T) {
126新增: fake(t, "osascript", c.script)
127新增: if c.script == "" {
128新增: // The real osascript lives in /usr/bin and would show a dialog.
129新增: t.Setenv("PATH", t.TempDir())
130新增: }
131新增: allow, ok := Ask(context.Background(), "t", "m")
132新增: if (want{allow, ok}) != c.want {
133新增: t.Errorf("got allow=%v ok=%v, want %v", allow, ok, c.want)
134新增: }
135新增: })
136新增: }
137新增:}
新增internal/env/fuzz_test.go+61 −0看文件
@@ -0,0 +1,61 @@
1新增:package env
2新增:
3新增:import (
4新增: "os"
5新增: "os/exec"
6新增: "strings"
7新增: "testing"
8新增:)
9新增:
10新增:// Lookup reads a value "as a shell sourcing the file would": whenever it
11新增:// answers, sh sourcing the file as the VM gets it gives the same value. It only answers for
12新增:// files of plain assignments, so sh runs nothing else here.
13新增:func FuzzLookup(f *testing.F) {
14新增: for _, s := range []string{"K=v\n", "K='a b'\n", "export K=\"x\" # note\n", "K='multi\nline'\n", "K=a'b'\"c\"\n", " K=1\nK=2\n", "K=v\r\n", "# c\n\nK=\n"} {
15新增: f.Add(s)
16新增: }
17新增: f.Fuzz(func(t *testing.T, content string) {
18新增: if strings.ContainsRune(content, 0) {
19新增: return
20新增: }
21新增: v, st := Lookup(content, "K")
22新增: if st != Found {
23新增: return
24新增: }
25新增: dir := t.TempDir()
26新增: file := dir + "/env"
27新增: // As the VM gets it: CRs dropped (a file from a Windows editor).
28新增: if err := os.WriteFile(file, []byte(StripCR(content)), 0o600); err != nil {
29新增: t.Fatal(err)
30新增: }
31新增: cmd := exec.Command("sh", "-c", `. "$1" && printf %s "$K"`, "sh", file)
32新增: cmd.Dir, cmd.Env = dir, []string{"PATH=/usr/bin:/bin"}
33新增: out, err := cmd.Output()
34新增: if err != nil {
35新增: t.Fatalf("Lookup accepted %q, sh refused it: %v", content, err)
36新增: }
37新增: if string(out) != v {
38新增: t.Fatalf("Lookup(%q) = %q, sh reads %q", content, v, out)
39新增: }
40新增: })
41新增:}
42新增:
43新增:// A value written as key='SQEscape(value)' is read back by the shell as
44新增:// itself: nothing in it ends the quotes and runs.
45新增:func FuzzSQEscape(f *testing.F) {
46新增: for _, s := range []string{"plain", "it's", "'", "''", `'"'"'`, "$(id)", "`id`", "a\nb", "\\'", "x'; touch /tmp/pwned; '"} {
47新增: f.Add(s)
48新增: }
49新增: f.Fuzz(func(t *testing.T, s string) {
50新增: if strings.ContainsRune(s, 0) {
51新增: return // not in a shell word, nor in an env file
52新增: }
53新增: out, err := exec.Command("sh", "-c", "printf %s '"+SQEscape(s)+"'").Output()
54新增: if err != nil {
55新增: t.Fatalf("sh refused %q: %v", SQEscape(s), err)
56新增: }
57新增: if string(out) != s {
58新增: t.Fatalf("%q came back as %q", s, out)
59新增: }
60新增: })
61新增:}
新增internal/env/nofollow.go+64 −0看文件
@@ -0,0 +1,64 @@
1新增:package env
2新增:
3新增:import (
4新增: "errors"
5新增: "strings"
6新增:)
7新增:
8新增:// The ways a NoFollow call fails.
9新增:var (
10新增: // ErrNoFile: the file is not there (Read only).
11新增: ErrNoFile = errors.New("no such file")
12新增: // ErrUnsafe: a symlink, or something other than a folder or a regular
13新增: // file, is on the way.
14新增: ErrUnsafe = errors.New("a symlink, or not a regular file or folder, on the way")
15新增:)
16新增:
17新增:// The NoFollow operations, each on top/rel, following no symlink below top:
18新增:// the one way the host touches the project, which the VM can write. Through
19新增:// a link planted there, a plain read would copy any file of the user's into
20新增:// the project, and a write could land anywhere; checking for links first is
21新增:// not enough, the VM can swap one in between the check and the use.
22新增://
23新增:// Missing folders are made, except by Read. Write replaces the file with a
24新增:// new one, mode 600, renamed over it: a link there is replaced, not followed.
25新增:
26新增:// ReadIn is the content of top/rel.
27新增:func ReadIn(top, rel string) ([]byte, error) { return noFollow("read", top, rel, nil) }
28新增:
29新增:// WriteIn replaces top/rel with data.
30新增:func WriteIn(top, rel string, data []byte) error {
31新增: _, err := noFollow("write", top, rel, data)
32新增: return err
33新增:}
34新增:
35新增:// MkdirIn makes the folder top/rel and those above it.
36新增:func MkdirIn(top, rel string) error {
37新增: _, err := noFollow("mkdir", top, rel, nil)
38新增: return err
39新增:}
40新增:
41新增:// TouchIn makes top/rel an empty file unless it is a regular file already.
42新增:func TouchIn(top, rel string) error {
43新增: _, err := noFollow("touch", top, rel, nil)
44新增: return err
45新增:}
46新增:
47新增:// split is rel's folders and its last name; ErrUnsafe for ".." anywhere, or
48新增:// no name.
49新增:func split(rel string) (dirs []string, name string, err error) {
50新增: for _, c := range strings.Split(rel, "/") {
51新增: if c != "" && c != "." {
52新增: dirs = append(dirs, c)
53新增: }
54新增: }
55新增: if len(dirs) == 0 {
56新增: return nil, "", ErrUnsafe
57新增: }
58新增: for _, c := range dirs {
59新增: if c == ".." {
60新增: return nil, "", ErrUnsafe
61新增: }
62新增: }
63新增: return dirs[:len(dirs)-1], dirs[len(dirs)-1], nil
64新增:}
新增internal/env/nofollow_test.go+160 −0看文件
@@ -0,0 +1,160 @@
1新增://go:build !windows
2新增:
3新增:package env
4新增:
5新增:import (
6新增: "errors"
7新增: "os"
8新增: "path/filepath"
9新增: "strconv"
10新增: "syscall"
11新增: "testing"
12新增:
13新增: "github.com/sylvinus/agent-vm/internal/bashref"
14新增:)
15新增:
16新增:func code(err error) int {
17新增: switch {
18新增: case err == nil:
19新增: return 0
20新增: case errors.Is(err, ErrNoFile):
21新增: return 1
22新增: case errors.Is(err, ErrUnsafe):
23新增: return 3
24新增: }
25新增: return 2
26新增:}
27新增:
28新增:// layout makes a project with every kind of thing NoFollow meets, and a
29新增:// secret outside it.
30新增:func layout(t *testing.T) (top, secret string) {
31新增: t.Helper()
32新增: root := t.TempDir()
33新增: top = filepath.Join(root, "proj")
34新增: secret = filepath.Join(root, "secret")
35新增: must := func(err error) {
36新增: if err != nil {
37新增: t.Fatal(err)
38新增: }
39新增: }
40新增: must(os.MkdirAll(filepath.Join(top, "d/e"), 0o755))
41新增: must(os.WriteFile(secret, []byte("SECRET\n"), 0o600))
42新增: must(os.MkdirAll(filepath.Join(root, "outdir"), 0o755))
43新增: must(os.WriteFile(filepath.Join(top, "plain"), []byte("A=1\n"), 0o644))
44新增: must(os.WriteFile(filepath.Join(top, "d/e/f"), []byte("deep\n"), 0o644))
45新增: must(os.Symlink(secret, filepath.Join(top, "link")))
46新增: must(os.Symlink(filepath.Join(root, "outdir"), filepath.Join(top, "dirlink")))
47新增: must(os.Symlink("plain", filepath.Join(top, "innerlink")))
48新增: must(syscall.Mkfifo(filepath.Join(top, "fifo"), 0o644))
49新增: return top, secret
50新增:}
51新增:
52新增:var rels = []string{"plain", "d/e/f", "missing", "new/dir/file", "link", "dirlink/x", "innerlink", "fifo", "d", "d/e", "../secret", "", "./plain", "d//e/./f"}
53新增:
54新增:func TestNoFollowBash(t *testing.T) {
55新增: if _, err := os.Stat("/usr/bin/perl"); err != nil {
56新增: t.Skip("no perl for the bash reference")
57新增: }
58新增: for _, op := range []string{"read", "write", "mkdir", "touch"} {
59新增: for _, rel := range rels {
60新增: gtop, gsecret := layout(t)
61新增: btop, bsecret := layout(t)
62新增: var got []byte
63新增: var err error
64新增: switch op {
65新增: case "read":
66新增: got, err = ReadIn(gtop, rel)
67新增: case "write":
68新增: err = WriteIn(gtop, rel, []byte("NEW\n"))
69新增: case "mkdir":
70新增: err = MkdirIn(gtop, rel)
71新增: case "touch":
72新增: err = TouchIn(gtop, rel)
73新增: }
74新增: r := bashref.Script(t, "", nil, `printf 'NEW\n' | _agent_vm_nofollow "$@"`, op, btop, rel)
75新增: if code(err) != r.Code {
76新增: t.Errorf("%s %q: go %d (%v), bash %d %s", op, rel, code(err), err, r.Code, r.Stderr)
77新增: }
78新增: if op == "read" && err == nil && string(got) != r.Stdout {
79新增: t.Errorf("read %q: go %q, bash %q", rel, got, r.Stdout)
80新增: }
81新增: if b, _ := os.ReadFile(gsecret); string(b) != "SECRET\n" {
82新增: t.Errorf("%s %q changed the secret outside the project", op, rel)
83新增: }
84新增: if b, _ := os.ReadFile(bsecret); string(b) != "SECRET\n" {
85新增: t.Errorf("bash %s %q changed the secret", op, rel)
86新增: }
87新增: if _, err := os.Stat(filepath.Join(filepath.Dir(gtop), "outdir", "x")); err == nil {
88新增: t.Errorf("%s %q wrote through a linked folder", op, rel)
89新增: }
90新增: if op == "write" && err == nil {
91新增: if b, _ := os.ReadFile(filepath.Join(gtop, rel)); string(b) != "NEW\n" {
92新增: t.Errorf("write %q: %q", rel, b)
93新增: }
94新增: fi, _ := os.Lstat(filepath.Join(gtop, rel))
95新增: if fi.Mode().Perm() != 0o600 || !fi.Mode().IsRegular() {
96新增: t.Errorf("write %q: mode %v", rel, fi.Mode())
97新增: }
98新增: }
99新增: }
100新增: }
101新增:}
102新增:
103新增:func TestProjectRelBash(t *testing.T) {
104新增: root := t.TempDir()
105新增: proj := filepath.Join(root, "proj")
106新增: os.MkdirAll(filepath.Join(proj, "sub"), 0o755)
107新增: os.MkdirAll(filepath.Join(root, "else"), 0o755)
108新增: os.Symlink(proj, filepath.Join(root, "projlink"))
109新增: os.Symlink(filepath.Join(root, "else"), filepath.Join(root, "elselink"))
110新增: os.Symlink(filepath.Join(proj, "sub"), filepath.Join(root, "else", "into"))
111新增: os.Symlink("../proj/sub", filepath.Join(root, "rellink"))
112新增: loop := filepath.Join(root, "loop")
113新增: os.Symlink(loop, loop)
114新增: for _, target := range []string{
115新增: proj + "/.agent-vm.env", proj + "/sub/x", root + "/projlink/x", root + "/elselink/x", root + "/else/into/y",
116新增: root + "/rellink/z", root + "/proj", root + "/other/x", loop + "/x", "/etc/passwd", proj + "/../proj/x",
117新增: root + "/elselink/../proj/x",
118新增: } {
119新增: r := bashref.Run(t, "", nil, "_agent_vm_project_rel", proj, target)
120新增: rel, ok := ProjectRel(proj, target)
121新增: want := r.Stdout
122新增: if len(want) > 0 {
123新增: want = want[:len(want)-1]
124新增: }
125新增: if ok != (r.Code == 0) || (ok && rel != want) {
126新增: t.Errorf("ProjectRel(%q) = %q %v, bash %q %d", target, rel, ok, want, r.Code)
127新增: }
128新增: }
129新增:}
130新增:
131新增:func TestPayloadBash(t *testing.T) {
132新增: root := t.TempDir()
133新增: proj := filepath.Join(root, "proj")
134新增: os.MkdirAll(proj, 0o755)
135新增: st := filepath.Join(root, "state")
136新增: os.MkdirAll(st, 0o755)
137新增: for i, c := range []struct{ shared, projEnv, projFile string }{
138新增: {"A=1\r\nB=2", "", ""},
139新增: {"A=1\n", "../outside.env", "P=1\r\n"},
140新增: {"", ".agent-vm.env", "P=1\n"},
141新增: {"A=1", "", ""},
142新增: } {
143新增: os.Remove(filepath.Join(st, "env"))
144新增: if c.shared != "" {
145新增: os.WriteFile(filepath.Join(st, "env"), []byte(c.shared), 0o600)
146新增: }
147新增: envs := []string{"AGENT_VM_STATE_DIR=" + st}
148新增: if c.projEnv != "" {
149新增: envs = append(envs, "AGENT_VM_PROJECT_ENV="+c.projEnv)
150新增: t.Setenv("AGENT_VM_PROJECT_ENV", c.projEnv)
151新增: os.WriteFile(ProjectPath(proj, c.projEnv), []byte(c.projFile), 0o600)
152新增: } else {
153新增: t.Setenv("AGENT_VM_PROJECT_ENV", "")
154新增: }
155新增: r := bashref.Run(t, "", envs, "_agent_vm_env_payload", proj)
156新增: if got := Payload(filepath.Join(st, "env"), proj); got != r.Stdout {
157新增: t.Errorf("case %s: Payload = %q, bash %q", strconv.Itoa(i), got, r.Stdout)
158新增: }
159新增: }
160新增:}
新增internal/env/nofollow_unix.go+116 −0看文件
@@ -0,0 +1,116 @@
1新增://go:build !windows
2新增:
3新增:package env
4新增:
5新增:import (
6新增: "errors"
7新增: "fmt"
8新增: "io"
9新增: "math/rand/v2"
10新增: "os"
11新增:
12新增: "golang.org/x/sys/unix"
13新增:)
14新增:
15新增:// noFollow enters each folder with openat and O_NOFOLLOW, checking it is
16新增:// the one lstat saw, and opens the file with O_NOFOLLOW and O_NONBLOCK (a
17新增:// FIFO cannot hang it).
18新增:func noFollow(op, top, rel string, data []byte) ([]byte, error) {
19新增: dirs, name, err := split(rel)
20新增: if err != nil {
21新增: return nil, err
22新增: }
23新增: if op == "mkdir" {
24新增: dirs = append(dirs, name)
25新增: }
26新增: fd, err := unix.Open(top, unix.O_RDONLY|unix.O_DIRECTORY|unix.O_CLOEXEC, 0)
27新增: if err != nil {
28新增: return nil, err
29新增: }
30新增: defer func() { unix.Close(fd) }()
31新增: for _, d := range dirs {
32新增: var st unix.Stat_t
33新增: err := unix.Fstatat(fd, d, &st, unix.AT_SYMLINK_NOFOLLOW)
34新增: if errors.Is(err, unix.ENOENT) {
35新增: if op == "read" {
36新增: return nil, ErrNoFile
37新增: }
38新增: if err := unix.Mkdirat(fd, d, 0o777); err != nil && !errors.Is(err, unix.EEXIST) {
39新增: return nil, err
40新增: }
41新增: err = unix.Fstatat(fd, d, &st, unix.AT_SYMLINK_NOFOLLOW)
42新增: }
43新增: if err != nil {
44新增: return nil, err
45新增: }
46新增: if st.Mode&unix.S_IFMT != unix.S_IFDIR {
47新增: return nil, ErrUnsafe
48新增: }
49新增: next, err := unix.Openat(fd, d, unix.O_RDONLY|unix.O_DIRECTORY|unix.O_NOFOLLOW|unix.O_CLOEXEC, 0)
50新增: if err != nil {
51新增: return nil, ErrUnsafe
52新增: }
53新增: var in unix.Stat_t
54新增: if err := unix.Fstat(next, &in); err != nil || in.Dev != st.Dev || in.Ino != st.Ino {
55新增: unix.Close(next)
56新增: return nil, ErrUnsafe
57新增: }
58新增: unix.Close(fd)
59新增: fd = next
60新增: }
61新增: switch op {
62新增: case "mkdir":
63新增: return nil, nil
64新增: case "touch":
65新增: var st unix.Stat_t
66新增: if err := unix.Fstatat(fd, name, &st, unix.AT_SYMLINK_NOFOLLOW); err == nil {
67新增: if st.Mode&unix.S_IFMT == unix.S_IFREG {
68新增: return nil, nil
69新增: }
70新增: return nil, ErrUnsafe
71新增: }
72新增: f, err := unix.Openat(fd, name, unix.O_WRONLY|unix.O_CREAT|unix.O_EXCL|unix.O_NOFOLLOW|unix.O_CLOEXEC, 0o666)
73新增: if err != nil {
74新增: return nil, err
75新增: }
76新增: return nil, unix.Close(f)
77新增: case "read":
78新增: f, err := unix.Openat(fd, name, unix.O_RDONLY|unix.O_NOFOLLOW|unix.O_NONBLOCK|unix.O_CLOEXEC, 0)
79新增: if errors.Is(err, unix.ENOENT) {
80新增: return nil, ErrNoFile
81新增: }
82新增: if err != nil {
83新增: return nil, ErrUnsafe
84新增: }
85新增: file := os.NewFile(uintptr(f), name)
86新增: defer file.Close()
87新增: if fi, err := file.Stat(); err != nil || !fi.Mode().IsRegular() {
88新增: return nil, ErrUnsafe
89新增: }
90新增: return io.ReadAll(file)
91新增: }
92新增: // write: a new file, renamed over the old one.
93新增: var tmp string
94新增: f := -1
95新增: for range 20 {
96新增: tmp = fmt.Sprintf(".%s.agent-vm.%d.%d", name, os.Getpid(), rand.IntN(1e9))
97新增: if f, err = unix.Openat(fd, tmp, unix.O_WRONLY|unix.O_CREAT|unix.O_EXCL|unix.O_NOFOLLOW|unix.O_CLOEXEC, 0o600); err == nil {
98新增: break
99新增: }
100新增: }
101新增: if f < 0 {
102新增: return nil, err
103新增: }
104新增: file := os.NewFile(uintptr(f), tmp)
105新增: _, werr := file.Write(data)
106新增: cerr := file.Close()
107新增: if err := errors.Join(werr, cerr); err != nil {
108新增: unix.Unlinkat(fd, tmp, 0)
109新增: return nil, err
110新增: }
111新增: if err := unix.Renameat(fd, tmp, fd, name); err != nil {
112新增: unix.Unlinkat(fd, tmp, 0)
113新增: return nil, err
114新增: }
115新增: return nil, nil
116新增:}
新增internal/env/nofollow_windows.go+100 −0看文件
@@ -0,0 +1,100 @@
1新增:package env
2新增:
3新增:import (
4新增: "errors"
5新增: "fmt"
6新增: "io"
7新增: "io/fs"
8新增: "math/rand/v2"
9新增: "os"
10新增: "path/filepath"
11新增:)
12新增:
13新增:// noFollow on Windows checks each step with Lstat, a reparse point (a
14新增:// symlink, a junction) being refused, then works in an os.Root, which
15新增:// cannot be left. A swap between the check and the use is not caught here as
16新增:// it is on Unix.
17新增:func noFollow(op, top, rel string, data []byte) ([]byte, error) {
18新增: dirs, name, err := split(rel)
19新增: if err != nil {
20新增: return nil, err
21新增: }
22新增: if op == "mkdir" {
23新增: dirs = append(dirs, name)
24新增: }
25新增: root, err := os.OpenRoot(top)
26新增: if err != nil {
27新增: return nil, err
28新增: }
29新增: defer root.Close()
30新增: sub := "."
31新增: for _, d := range dirs {
32新增: sub = filepath.Join(sub, d)
33新增: fi, err := root.Lstat(sub)
34新增: if errors.Is(err, fs.ErrNotExist) {
35新增: if op == "read" {
36新增: return nil, ErrNoFile
37新增: }
38新增: if err := root.Mkdir(sub, 0o777); err != nil && !errors.Is(err, fs.ErrExist) {
39新增: return nil, err
40新增: }
41新增: fi, err = root.Lstat(sub)
42新增: }
43新增: if err != nil {
44新增: return nil, err
45新增: }
46新增: if !fi.IsDir() || fi.Mode()&fs.ModeSymlink != 0 || fi.Mode()&fs.ModeIrregular != 0 {
47新增: return nil, ErrUnsafe
48新增: }
49新增: }
50新增: if op == "mkdir" {
51新增: return nil, nil
52新增: }
53新增: p := filepath.Join(sub, name)
54新增: fi, err := root.Lstat(p)
55新增: switch {
56新增: case err == nil && !fi.Mode().IsRegular():
57新增: return nil, ErrUnsafe
58新增: case errors.Is(err, fs.ErrNotExist) && op == "read":
59新增: return nil, ErrNoFile
60新增: }
61新增: switch op {
62新增: case "touch":
63新增: if err == nil {
64新增: return nil, nil
65新增: }
66新增: f, err := root.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o666)
67新增: if err != nil {
68新增: return nil, err
69新增: }
70新增: return nil, f.Close()
71新增: case "read":
72新增: f, err := root.Open(p)
73新增: if err != nil {
74新增: return nil, ErrUnsafe
75新增: }
76新增: defer f.Close()
77新增: return io.ReadAll(f)
78新增: }
79新增: var tmp string
80新增: var f *os.File
81新增: for range 20 {
82新增: tmp = filepath.Join(sub, fmt.Sprintf(".%s.agent-vm.%d.%d", name, os.Getpid(), rand.IntN(1e9)))
83新增: if f, err = root.OpenFile(tmp, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o600); err == nil {
84新增: break
85新增: }
86新增: }
87新增: if f == nil {
88新增: return nil, err
89新增: }
90新增: _, werr := f.Write(data)
91新增: if err := errors.Join(werr, f.Close()); err != nil {
92新增: root.Remove(tmp)
93新增: return nil, err
94新增: }
95新增: if err := root.Rename(tmp, p); err != nil {
96新增: root.Remove(tmp)
97新增: return nil, err
98新增: }
99新增: return nil, nil
100新增:}
新增internal/env/parse.go+212 −0看文件
@@ -0,0 +1,212 @@
1新增:// Package env reads and writes agent-vm's env files, ~/.agent-vm/env and a
2新增:// project's .agent-vm.env, which the VM's shell sources: without ever running
3新增:// a shell on the host, since the VM can write the project's.
4新增:package env
5新增:
6新增:import (
7新增: "regexp"
8新增: "strings"
9新增:)
10新增:
11新增:// SQEscape makes s safe inside a single-quoted shell literal: ' becomes
12新增:// '"'"'.
13新增:func SQEscape(s string) string {
14新增: return strings.ReplaceAll(s, "'", `'"'"'`)
15新增:}
16新增:
17新增:// Status of a read.
18新增:const (
19新增: Found = 0
20新增: NotFound = 1
21新增: // Refused: the file uses syntax this reader does not interpret, and no
22新增: // key can be answered.
23新增: Refused = 3
24新增:)
25新增:
26新增:// records splits content as awk reads lines: a last line without a newline
27新增:// is one too.
28新增:func records(content string) []string {
29新增: if content == "" {
30新增: return nil
31新增: }
32新增: return strings.Split(strings.TrimSuffix(content, "\n"), "\n")
33新增:}
34新增:
35新增:var (
36新增: leadingBlank = regexp.MustCompile(`^[ \t]+`)
37新增: exportPrefix = regexp.MustCompile(`^export[ \t]+`)
38新增: assignment = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*=`)
39新增: blankOrNote = regexp.MustCompile(`^(#.*)?$`) // CRs already dropped (Lookup)
40新增: restOK = regexp.MustCompile(`^[ \t]+(#.*)?$`)
41新增:)
42新增:
43新增:// Lookup is the value content assigns to key, as a shell sourcing it would,
44新增:// without a shell. Accepted: an optional `export `, then single-quoted parts
45新增:// (which may span lines, as Set writes a value with a newline), double-quoted
46新增:// parts with nothing to expand, and bare characters other than
47新增:// $ ` \ ; & | < > ( ) ~, then an optional `# comment`. The last assignment
48新增:// wins. One line refused, and no key is answered: a quote left open or a
49新增:// trailing backslash makes the shell read the next lines into that value,
50新增:// and other syntax can run anything, an assignment to any key included. A
51新增:// line that is not an assignment, a comment or blank counts as refused.
52新增:func Lookup(content, key string) (string, int) {
53新增: // As the VM sources it: the CR ending each line dropped (StripCR),
54新增: // inside a quoted value too.
55新增: lines := records(StripCR(content))
56新增: found := false
57新增: val := ""
58新增: for i := 0; i < len(lines); i++ {
59新增: line := leadingBlank.ReplaceAllString(lines[i], "")
60新增: if blankOrNote.MatchString(line) {
61新增: continue
62新增: }
63新增: line = exportPrefix.ReplaceAllString(line, "")
64新增: if !assignment.MatchString(line) {
65新增: return "", Refused
66新增: }
67新增: eq := strings.IndexByte(line, '=')
68新增: v, st, used := parseValue(line[eq+1:], lines[i+1:])
69新增: i += used
70新增: if st != Found {
71新增: return "", Refused
72新增: }
73新增: if line[:eq] == key {
74新增: found, val = true, v
75新增: }
76新增: }
77新增: if !found {
78新增: return "", NotFound
79新增: }
80新增: return val, Found
81新增:}
82新增:
83新增:// parseValue reads the value s starts, taking from more the lines a
84新增:// single-quoted part goes on to; used is how many.
85新增:func parseValue(s string, more []string) (v string, st, used int) {
86新增: for s != "" {
87新增: switch c := s[0]; {
88新增: case c == '\'':
89新增: s = s[1:]
90新增: for {
91新增: e := strings.IndexByte(s, '\'')
92新增: if e >= 0 {
93新增: v += s[:e]
94新增: s = s[e+1:]
95新增: break
96新增: }
97新增: if used == len(more) {
98新增: return v, Refused, used
99新增: }
100新增: v += s + "\n"
101新增: s = more[used]
102新增: used++
103新增: }
104新增: case c == '"':
105新增: s = s[1:]
106新增: e := strings.IndexByte(s, '"')
107新增: if e < 0 || strings.ContainsAny(s[:e], "$`\\") {
108新增: return v, Refused, used
109新增: }
110新增: v += s[:e]
111新增: s = s[e+1:]
112新增: case c == ' ' || c == '\t':
113新增: if restOK.MatchString(s) {
114新增: return v, Found, used
115新增: }
116新增: return v, Refused, used
117新增: case strings.IndexByte("$`\\;&|<>()~\r", c) >= 0:
118新增: return v, Refused, used
119新增: default:
120新增: v += s[:1] // the byte, not string(c), which would encode it as a rune
121新增: s = s[1:]
122新增: }
123新增: }
124新增: return v, Found, used
125新增:}
126新增:
127新增:var nameAssign = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*=`)
128新增:
129新增:// Names is every name content assigns, once per assignment, in order.
130新增:func Names(content string) []string {
131新增: var names []string
132新增: walk(content, func(_ string, name string) { names = append(names, name) }, nil)
133新增: return names
134新增:}
135新增:
136新增:// Drop is content without key's assignments, whole: a value Set wrote over
137新增:// several lines goes with its first line. Each line keeps its newline.
138新增:func Drop(content, key string) string {
139新增: var b strings.Builder
140新增: walk(content, nil, func(line, name string) {
141新增: if name != key {
142新增: b.WriteString(line + "\n")
143新增: }
144新增: })
145新增: return b.String()
146新增:}
147新增:
148新增:// walk calls name for each assignment, and line for each line with the name
149新增:// of the assignment it belongs to ("" for none). A line inside a quoted value
150新增:// is never read as an assignment: it is data.
151新增:func walk(content string, name func(line, name string), line func(line, name string)) {
152新增: q := byte(0) // the open quote: ', ", or $ for $'...'
153新增: cur := ""
154新增: scan := func(s string) {
155新增: for i := 0; i < len(s); i++ {
156新增: c := s[i]
157新增: switch q {
158新增: case '\'':
159新增: if c == '\'' {
160新增: q = 0
161新增: }
162新增: continue
163新增: case '$':
164新增: if c == '\\' {
165新增: i++
166新增: } else if c == '\'' {
167新增: q = 0
168新增: }
169新增: continue
170新增: case '"':
171新增: if c == '\\' {
172新增: i++
173新增: } else if c == '"' {
174新增: q = 0
175新增: }
176新增: continue
177新增: }
178新增: switch {
179新增: case c == '\\':
180新增: i++
181新增: case c == '$' && i+1 < len(s) && s[i+1] == '\'':
182新增: q = '$'
183新增: i++
184新增: case c == '\'' || c == '"':
185新增: q = c
186新增: case c == '#' && i > 0 && (s[i-1] == ' ' || s[i-1] == '\t'):
187新增: return
188新增: }
189新增: }
190新增: }
191新增: for _, l := range records(content) {
192新增: if q != 0 {
193新增: scan(l)
194新增: if line != nil {
195新增: line(l, cur)
196新增: }
197新增: continue
198新增: }
199新增: cur = ""
200新增: t := exportPrefix.ReplaceAllString(leadingBlank.ReplaceAllString(l, ""), "")
201新增: if m := nameAssign.FindString(t); m != "" {
202新增: cur = m[:len(m)-1]
203新增: if name != nil {
204新增: name(l, cur)
205新增: }
206新增: scan(t[len(m):])
207新增: }
208新增: if line != nil {
209新增: line(l, cur)
210新增: }
211新增: }
212新增:}
新增internal/env/parse_test.go+110 −0看文件
@@ -0,0 +1,110 @@
1新增:package env
2新增:
3新增:import (
4新增: "math/rand"
5新增: "strings"
6新增: "testing"
7新增:
8新增: "github.com/sylvinus/agent-vm/internal/bashref"
9新增:)
10新增:
11新增:var corpus = []string{
12新增: "",
13新增: "A=1\n",
14新增: "A=1",
15新增: "export A=1\nB=2\n",
16新增: " export A='x y'\n",
17新增: "A='multi\nline\nB=inside'\nB=2\n",
18新增: "A='open\nB=2\n",
19新增: "A=\"plain\"\nB=\"$HOME\"\n",
20新增: "A=x # comment\nB=y#notcomment\n",
21新增: "A=x;rm -rf /\n",
22新增: "A=$(id)\n",
23新增: "A=$HOME\n",
24新增: "B=1\nA=x$y\n",
25新增: "A=~/x\n",
26新增: "# just a comment\n\n \nA=1\r\nB='crlf'\r\n",
27新增: "A=1\nA=2\n",
28新增: "A='it'\"'\"'s'\n",
29新增: "not an assignment\nA=1\n",
30新增: "A=x\\\ny\n",
31新增: "A= 1\n",
32新增: "A=\tB\n",
33新增: "1A=x\n",
34新增: "A=x y\n",
35新增: "A='x' # c\n",
36新增: "A=$'esc\\'aped'\nB=after\n",
37新增: "A=\"dq \\\" esc\"\nB=after\n",
38新增: "A='a'\"b\"c\n",
39新增: "export\tA=1\nexport B\n",
40新增: "A=x # ' not a quote\nB=1\n",
41新增: "A='x # not a comment'\nB=1\n",
42新增: "A=café\nB='naïve'\n",
43新增: "A=\x92\xff\n",
44新增:}
45新增:
46新增:func bashRead(t *testing.T, content, key string) (string, int) {
47新增: r := bashref.Script(t, "", nil, `printf '%s' "$1" | _agent_vm_env_read - "$2"`, content, key)
48新增: return r.Stdout, r.Code
49新增:}
50新增:
51新增:func TestReadBash(t *testing.T) {
52新增: for _, c := range corpus {
53新增: for _, k := range []string{"A", "B", "C"} {
54新增: v, st := Lookup(c, k)
55新增: bv, bst := bashRead(t, c, k)
56新增: if v != bv || st != bst {
57新增: t.Errorf("Read(%q, %s) = %q %d, bash %q %d", c, k, v, st, bv, bst)
58新增: }
59新增: }
60新增: }
61新增:}
62新增:
63新增:func TestNamesDropBash(t *testing.T) {
64新增: for _, c := range corpus {
65新增: r := bashref.Script(t, "", nil, `printf '%s' "$1" | _agent_vm_env_lines list -`, c)
66新增: if got := strings.Join(Names(c), "\n"); got != strings.TrimSuffix(r.Stdout, "\n") {
67新增: t.Errorf("Names(%q) = %q, bash %q", c, got, r.Stdout)
68新增: }
69新增: for _, k := range []string{"A", "B"} {
70新增: r := bashref.Script(t, "", nil, `printf '%s' "$1" | _agent_vm_env_lines drop - "$2"`, c, k)
71新增: if got := Drop(c, k); got != r.Stdout {
72新增: t.Errorf("Drop(%q, %s) = %q, bash %q", c, k, got, r.Stdout)
73新增: }
74新增: }
75新增: }
76新增:}
77新增:
78新增:// Random files of the characters that matter, against bash.
79新增:func TestReadBashRandom(t *testing.T) {
80新增: if testing.Short() {
81新增: t.Skip()
82新增: }
83新增: alphabet := []string{"A=", "B=", "export ", "'", "\"", "$", "\\", "#", " ", "\t", "\n", "x", ";", "\r", "~", "$'", "="}
84新增: rnd := rand.New(rand.NewSource(1))
85新增: for n := 0; n < 300; n++ {
86新增: var b strings.Builder
87新增: for i := rnd.Intn(14); i >= 0; i-- {
88新增: b.WriteString(alphabet[rnd.Intn(len(alphabet))])
89新增: }
90新增: c := b.String()
91新增: v, st := Lookup(c, "A")
92新增: bv, bst := bashRead(t, c, "A")
93新增: if v != bv || st != bst {
94新增: t.Errorf("Read(%q, A) = %q %d, bash %q %d", c, v, st, bv, bst)
95新增: }
96新增: r := bashref.Script(t, "", nil, `printf '%s' "$1" | _agent_vm_env_lines drop - A`, c)
97新增: if got := Drop(c, "A"); got != r.Stdout {
98新增: t.Errorf("Drop(%q, A) = %q, bash %q", c, got, r.Stdout)
99新增: }
100新增: }
101新增:}
102新增:
103新增:func TestSQEscapeBash(t *testing.T) {
104新增: for _, s := range []string{"", "plain", "O'Brien", "''", "a'b'c", "new\nline"} {
105新增: r := bashref.Run(t, "", nil, "_agent_vm_sq_escape", s)
106新增: if SQEscape(s) != r.Stdout {
107新增: t.Errorf("SQEscape(%q) = %q, bash %q", s, SQEscape(s), r.Stdout)
108新增: }
109新增: }
110新增:}
新增internal/env/project.go+139 −0看文件
@@ -0,0 +1,139 @@
1新增:package env
2新增:
3新增:import (
4新增: "os"
5新增: "strings"
6新增:
7新增: "github.com/sylvinus/agent-vm/internal/paths"
8新增:)
9新增:
10新增:// ProjectPath is a project file's path: p relative to the project dir
11新增:// unless absolute. An integrator moves the env file and the runtime script
12新增:// into a folder of its own (".mytool/env") with AGENT_VM_PROJECT_ENV and
13新增:// AGENT_VM_PROJECT_RUNTIME.
14新增:func ProjectPath(dir, p string) string {
15新增: return paths.Abs(dir, p)
16新增:}
17新增:
18新增:// ProjectEnvFile is the project dir's env file: in the project, so it
19新增:// follows a clone, a move and a delete.
20新增:func ProjectEnvFile(dir string) string {
21新增: p := os.Getenv("AGENT_VM_PROJECT_ENV")
22新增: if p == "" {
23新增: p = ".agent-vm.env"
24新增: }
25新增: return ProjectPath(dir, p)
26新增:}
27新增:
28新增:// ProjectRel is target relative to the project dir, when it is inside it,
29新增:// where the VM can write. The host must not read such a file by its path:
30新增:// the VM can make it a symlink, and the host would follow it to any file of
31新增:// the user's and hand the content over. It is read in the VM, or with
32新增:// NoFollow.
33新增://
34新增:// Inside by its spelling, or by where it leads: the project reached through
35新增:// a link of the user's, the other spelling of a linked folder (/tmp and
36新增:// /private/tmp on macOS), another case where the file system ignores it. So
37新增:// target is resolved one component at a time, links followed one hop at a
38新增:// time, and the first step that reaches the project decides, before
39新增:// anything in it is followed. Before that point, every link is outside the
40新增:// project, where the VM cannot change it.
41新增:func ProjectRel(dir, target string) (string, bool) {
42新增: dir = strings.TrimSuffix(dir, "/")
43新增: if rest, ok := strings.CutPrefix(target, dir+"/"); ok {
44新增: return rest, true
45新增: }
46新增: pdir, err := paths.Real(dir)
47新增: if err != nil || pdir == "" {
48新增: return "", false
49新增: }
50新增: // From the root: "", or the drive on Windows ("C:").
51新增: root := paths.Root(target)
52新增: cur, hops := strings.TrimSuffix(root, "/"), 0
53新增: rest := strings.TrimPrefix(target, root) + "/"
54新增: for rest != "" {
55新增: var comp string
56新增: comp, rest, _ = strings.Cut(rest, "/")
57新增: switch comp {
58新增: case "", ".":
59新增: continue
60新增: case "..":
61新增: if i := strings.LastIndexByte(cur, '/'); i >= 0 {
62新增: cur = cur[:i]
63新增: }
64新增: continue
65新增: }
66新增: next := cur + "/" + comp
67新增: if inside, ok := paths.In(next, pdir); ok {
68新增: r := strings.TrimSuffix(rest, "/")
69新增: if inside != "." {
70新增: r = inside + "/" + r
71新增: }
72新增: return strings.TrimSuffix(strings.TrimPrefix(r, "/"), "/"), true
73新增: }
74新增: if fi, err := os.Lstat(next); err == nil && fi.Mode()&os.ModeSymlink != 0 {
75新增: if hops++; hops > 40 {
76新增: return "", false
77新增: }
78新增: t, err := os.Readlink(next)
79新增: if err != nil {
80新增: return "", false
81新增: }
82新增: if t = paths.Host(t); paths.IsAbs(t) {
83新增: r := paths.Root(t)
84新增: cur, t = strings.TrimSuffix(r, "/"), t[len(r):]
85新增: }
86新增: rest = strings.TrimPrefix(t, "/") + "/" + rest
87新增: continue
88新增: }
89新增: cur = next
90新增: }
91新增: return "", false
92新增:}
93新增:
94新增:// InProject reports whether target is inside the project dir (see
95新增:// ProjectRel).
96新增:func InProject(dir, target string) bool {
97新增: _, ok := ProjectRel(dir, target)
98新增: return ok
99新增:}
100新增:
101新增:// StripCR is content with a CR ending a line removed, each line ending with
102新增:// a newline: a CRLF file (Windows) would put a CR at the end of every value
103新增:// in the guest.
104新增:func StripCR(content string) string {
105新增: var b strings.Builder
106新增: for _, l := range records(content) {
107新增: b.WriteString(strings.TrimSuffix(l, "\r") + "\n")
108新增: }
109新增: return b.String()
110新增:}
111新增:
112新增:// Payload is what is pushed into the VM of the project dir: the shared file
113新增:// first, the project's next, so the project's value wins (the guest sources
114新增:// it). The project's file is only in here when AGENT_VM_PROJECT_ENV puts it
115新增:// outside the project; inside, the VM reads it itself (see ProjectRel).
116新增:func Payload(shared, dir string) string {
117新增: var b strings.Builder
118新增: if s, ok := readRegular(shared); ok {
119新增: // The newline keeps a shared file without one from gluing its last
120新增: // line to the project's first.
121新增: b.WriteString(StripCR(s) + "\n")
122新增: }
123新增: if pf := ProjectEnvFile(dir); !InProject(dir, pf) {
124新增: if p, ok := readRegular(pf); ok {
125新增: b.WriteString(StripCR(p))
126新增: }
127新增: }
128新增: return b.String()
129新增:}
130新增:
131新增:// readRegular is the content of p, a regular file once links are followed:
132新增:// one of the user's own, outside the project.
133新增:func readRegular(p string) (string, bool) {
134新增: if fi, err := os.Stat(p); err != nil || !fi.Mode().IsRegular() {
135新增: return "", false
136新增: }
137新增: b, err := os.ReadFile(p)
138新增: return string(b), err == nil
139新增:}
新增internal/env/testdata/bashref/TestNamesDropBash.json+1516 −0看文件
@@ -0,0 +1,1516 @@
1新增:{
2新增: "TestNamesDropBash": [
3新增: {
4新增: "Dir": "{ROOT}",
5新增: "Stdin": "",
6新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
7新增: "Env": [
8新增: "HOME={T0}/001"
9新增: ],
10新增: "Args": [
11新增: ""
12新增: ],
13新增: "Files": null,
14新增: "Stdout": "",
15新增: "Stderr": "",
16新增: "Code": 0
17新增: },
18新增: {
19新增: "Dir": "{ROOT}",
20新增: "Stdin": "",
21新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
22新增: "Env": [
23新增: "HOME={T0}/002"
24新增: ],
25新增: "Args": [
26新增: "",
27新增: "A"
28新增: ],
29新增: "Files": null,
30新增: "Stdout": "",
31新增: "Stderr": "",
32新增: "Code": 0
33新增: },
34新增: {
35新增: "Dir": "{ROOT}",
36新增: "Stdin": "",
37新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
38新增: "Env": [
39新增: "HOME={T0}/003"
40新增: ],
41新增: "Args": [
42新增: "",
43新增: "B"
44新增: ],
45新增: "Files": null,
46新增: "Stdout": "",
47新增: "Stderr": "",
48新增: "Code": 0
49新增: },
50新增: {
51新增: "Dir": "{ROOT}",
52新增: "Stdin": "",
53新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
54新增: "Env": [
55新增: "HOME={T0}/004"
56新增: ],
57新增: "Args": [
58新增: "A=1\n"
59新增: ],
60新增: "Files": null,
61新增: "Stdout": "A\n",
62新增: "Stderr": "",
63新增: "Code": 0
64新增: },
65新增: {
66新增: "Dir": "{ROOT}",
67新增: "Stdin": "",
68新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
69新增: "Env": [
70新增: "HOME={T0}/005"
71新增: ],
72新增: "Args": [
73新增: "A=1\n",
74新增: "A"
75新增: ],
76新增: "Files": null,
77新增: "Stdout": "",
78新增: "Stderr": "",
79新增: "Code": 0
80新增: },
81新增: {
82新增: "Dir": "{ROOT}",
83新增: "Stdin": "",
84新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
85新增: "Env": [
86新增: "HOME={T0}/006"
87新增: ],
88新增: "Args": [
89新增: "A=1\n",
90新增: "B"
91新增: ],
92新增: "Files": null,
93新增: "Stdout": "A=1\n",
94新增: "Stderr": "",
95新增: "Code": 0
96新增: },
97新增: {
98新增: "Dir": "{ROOT}",
99新增: "Stdin": "",
100新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
101新增: "Env": [
102新增: "HOME={T0}/007"
103新增: ],
104新增: "Args": [
105新增: "A=1"
106新增: ],
107新增: "Files": null,
108新增: "Stdout": "A\n",
109新增: "Stderr": "",
110新增: "Code": 0
111新增: },
112新增: {
113新增: "Dir": "{ROOT}",
114新增: "Stdin": "",
115新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
116新增: "Env": [
117新增: "HOME={T0}/008"
118新增: ],
119新增: "Args": [
120新增: "A=1",
121新增: "A"
122新增: ],
123新增: "Files": null,
124新增: "Stdout": "",
125新增: "Stderr": "",
126新增: "Code": 0
127新增: },
128新增: {
129新增: "Dir": "{ROOT}",
130新增: "Stdin": "",
131新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
132新增: "Env": [
133新增: "HOME={T0}/009"
134新增: ],
135新增: "Args": [
136新增: "A=1",
137新增: "B"
138新增: ],
139新增: "Files": null,
140新增: "Stdout": "A=1\n",
141新增: "Stderr": "",
142新增: "Code": 0
143新增: },
144新增: {
145新增: "Dir": "{ROOT}",
146新增: "Stdin": "",
147新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
148新增: "Env": [
149新增: "HOME={T0}/010"
150新增: ],
151新增: "Args": [
152新增: "export A=1\nB=2\n"
153新增: ],
154新增: "Files": null,
155新增: "Stdout": "A\nB\n",
156新增: "Stderr": "",
157新增: "Code": 0
158新增: },
159新增: {
160新增: "Dir": "{ROOT}",
161新增: "Stdin": "",
162新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
163新增: "Env": [
164新增: "HOME={T0}/011"
165新增: ],
166新增: "Args": [
167新增: "export A=1\nB=2\n",
168新增: "A"
169新增: ],
170新增: "Files": null,
171新增: "Stdout": "B=2\n",
172新增: "Stderr": "",
173新增: "Code": 0
174新增: },
175新增: {
176新增: "Dir": "{ROOT}",
177新增: "Stdin": "",
178新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
179新增: "Env": [
180新增: "HOME={T0}/012"
181新增: ],
182新增: "Args": [
183新增: "export A=1\nB=2\n",
184新增: "B"
185新增: ],
186新增: "Files": null,
187新增: "Stdout": "export A=1\n",
188新增: "Stderr": "",
189新增: "Code": 0
190新增: },
191新增: {
192新增: "Dir": "{ROOT}",
193新增: "Stdin": "",
194新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
195新增: "Env": [
196新增: "HOME={T0}/013"
197新增: ],
198新增: "Args": [
199新增: " export A='x y'\n"
200新增: ],
201新增: "Files": null,
202新增: "Stdout": "A\n",
203新增: "Stderr": "",
204新增: "Code": 0
205新增: },
206新增: {
207新增: "Dir": "{ROOT}",
208新增: "Stdin": "",
209新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
210新增: "Env": [
211新增: "HOME={T0}/014"
212新增: ],
213新增: "Args": [
214新增: " export A='x y'\n",
215新增: "A"
216新增: ],
217新增: "Files": null,
218新增: "Stdout": "",
219新增: "Stderr": "",
220新增: "Code": 0
221新增: },
222新增: {
223新增: "Dir": "{ROOT}",
224新增: "Stdin": "",
225新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
226新增: "Env": [
227新增: "HOME={T0}/015"
228新增: ],
229新增: "Args": [
230新增: " export A='x y'\n",
231新增: "B"
232新增: ],
233新增: "Files": null,
234新增: "Stdout": " export A='x y'\n",
235新增: "Stderr": "",
236新增: "Code": 0
237新增: },
238新增: {
239新增: "Dir": "{ROOT}",
240新增: "Stdin": "",
241新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
242新增: "Env": [
243新增: "HOME={T0}/016"
244新增: ],
245新增: "Args": [
246新增: "A='multi\nline\nB=inside'\nB=2\n"
247新增: ],
248新增: "Files": null,
249新增: "Stdout": "A\nB\n",
250新增: "Stderr": "",
251新增: "Code": 0
252新增: },
253新增: {
254新增: "Dir": "{ROOT}",
255新增: "Stdin": "",
256新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
257新增: "Env": [
258新增: "HOME={T0}/017"
259新增: ],
260新增: "Args": [
261新增: "A='multi\nline\nB=inside'\nB=2\n",
262新增: "A"
263新增: ],
264新增: "Files": null,
265新增: "Stdout": "B=2\n",
266新增: "Stderr": "",
267新增: "Code": 0
268新增: },
269新增: {
270新增: "Dir": "{ROOT}",
271新增: "Stdin": "",
272新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
273新增: "Env": [
274新增: "HOME={T0}/018"
275新增: ],
276新增: "Args": [
277新增: "A='multi\nline\nB=inside'\nB=2\n",
278新增: "B"
279新增: ],
280新增: "Files": null,
281新增: "Stdout": "A='multi\nline\nB=inside'\n",
282新增: "Stderr": "",
283新增: "Code": 0
284新增: },
285新增: {
286新增: "Dir": "{ROOT}",
287新增: "Stdin": "",
288新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
289新增: "Env": [
290新增: "HOME={T0}/019"
291新增: ],
292新增: "Args": [
293新增: "A='open\nB=2\n"
294新增: ],
295新增: "Files": null,
296新增: "Stdout": "A\n",
297新增: "Stderr": "",
298新增: "Code": 0
299新增: },
300新增: {
301新增: "Dir": "{ROOT}",
302新增: "Stdin": "",
303新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
304新增: "Env": [
305新增: "HOME={T0}/020"
306新增: ],
307新增: "Args": [
308新增: "A='open\nB=2\n",
309新增: "A"
310新增: ],
311新增: "Files": null,
312新增: "Stdout": "",
313新增: "Stderr": "",
314新增: "Code": 0
315新增: },
316新增: {
317新增: "Dir": "{ROOT}",
318新增: "Stdin": "",
319新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
320新增: "Env": [
321新增: "HOME={T0}/021"
322新增: ],
323新增: "Args": [
324新增: "A='open\nB=2\n",
325新增: "B"
326新增: ],
327新增: "Files": null,
328新增: "Stdout": "A='open\nB=2\n",
329新增: "Stderr": "",
330新增: "Code": 0
331新增: },
332新增: {
333新增: "Dir": "{ROOT}",
334新增: "Stdin": "",
335新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
336新增: "Env": [
337新增: "HOME={T0}/022"
338新增: ],
339新增: "Args": [
340新增: "A=\"plain\"\nB=\"$HOME\"\n"
341新增: ],
342新增: "Files": null,
343新增: "Stdout": "A\nB\n",
344新增: "Stderr": "",
345新增: "Code": 0
346新增: },
347新增: {
348新增: "Dir": "{ROOT}",
349新增: "Stdin": "",
350新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
351新增: "Env": [
352新增: "HOME={T0}/023"
353新增: ],
354新增: "Args": [
355新增: "A=\"plain\"\nB=\"$HOME\"\n",
356新增: "A"
357新增: ],
358新增: "Files": null,
359新增: "Stdout": "B=\"$HOME\"\n",
360新增: "Stderr": "",
361新增: "Code": 0
362新增: },
363新增: {
364新增: "Dir": "{ROOT}",
365新增: "Stdin": "",
366新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
367新增: "Env": [
368新增: "HOME={T0}/024"
369新增: ],
370新增: "Args": [
371新增: "A=\"plain\"\nB=\"$HOME\"\n",
372新增: "B"
373新增: ],
374新增: "Files": null,
375新增: "Stdout": "A=\"plain\"\n",
376新增: "Stderr": "",
377新增: "Code": 0
378新增: },
379新增: {
380新增: "Dir": "{ROOT}",
381新增: "Stdin": "",
382新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
383新增: "Env": [
384新增: "HOME={T0}/025"
385新增: ],
386新增: "Args": [
387新增: "A=x # comment\nB=y#notcomment\n"
388新增: ],
389新增: "Files": null,
390新增: "Stdout": "A\nB\n",
391新增: "Stderr": "",
392新增: "Code": 0
393新增: },
394新增: {
395新增: "Dir": "{ROOT}",
396新增: "Stdin": "",
397新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
398新增: "Env": [
399新增: "HOME={T0}/026"
400新增: ],
401新增: "Args": [
402新增: "A=x # comment\nB=y#notcomment\n",
403新增: "A"
404新增: ],
405新增: "Files": null,
406新增: "Stdout": "B=y#notcomment\n",
407新增: "Stderr": "",
408新增: "Code": 0
409新增: },
410新增: {
411新增: "Dir": "{ROOT}",
412新增: "Stdin": "",
413新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
414新增: "Env": [
415新增: "HOME={T0}/027"
416新增: ],
417新增: "Args": [
418新增: "A=x # comment\nB=y#notcomment\n",
419新增: "B"
420新增: ],
421新增: "Files": null,
422新增: "Stdout": "A=x # comment\n",
423新增: "Stderr": "",
424新增: "Code": 0
425新增: },
426新增: {
427新增: "Dir": "{ROOT}",
428新增: "Stdin": "",
429新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
430新增: "Env": [
431新增: "HOME={T0}/028"
432新增: ],
433新增: "Args": [
434新增: "A=x;rm -rf /\n"
435新增: ],
436新增: "Files": null,
437新增: "Stdout": "A\n",
438新增: "Stderr": "",
439新增: "Code": 0
440新增: },
441新增: {
442新增: "Dir": "{ROOT}",
443新增: "Stdin": "",
444新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
445新增: "Env": [
446新增: "HOME={T0}/029"
447新增: ],
448新增: "Args": [
449新增: "A=x;rm -rf /\n",
450新增: "A"
451新增: ],
452新增: "Files": null,
453新增: "Stdout": "",
454新增: "Stderr": "",
455新增: "Code": 0
456新增: },
457新增: {
458新增: "Dir": "{ROOT}",
459新增: "Stdin": "",
460新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
461新增: "Env": [
462新增: "HOME={T0}/030"
463新增: ],
464新增: "Args": [
465新增: "A=x;rm -rf /\n",
466新增: "B"
467新增: ],
468新增: "Files": null,
469新增: "Stdout": "A=x;rm -rf /\n",
470新增: "Stderr": "",
471新增: "Code": 0
472新增: },
473新增: {
474新增: "Dir": "{ROOT}",
475新增: "Stdin": "",
476新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
477新增: "Env": [
478新增: "HOME={T0}/031"
479新增: ],
480新增: "Args": [
481新增: "A=$(id)\n"
482新增: ],
483新增: "Files": null,
484新增: "Stdout": "A\n",
485新增: "Stderr": "",
486新增: "Code": 0
487新增: },
488新增: {
489新增: "Dir": "{ROOT}",
490新增: "Stdin": "",
491新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
492新增: "Env": [
493新增: "HOME={T0}/032"
494新增: ],
495新增: "Args": [
496新增: "A=$(id)\n",
497新增: "A"
498新增: ],
499新增: "Files": null,
500新增: "Stdout": "",
501新增: "Stderr": "",
502新增: "Code": 0
503新增: },
504新增: {
505新增: "Dir": "{ROOT}",
506新增: "Stdin": "",
507新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
508新增: "Env": [
509新增: "HOME={T0}/033"
510新增: ],
511新增: "Args": [
512新增: "A=$(id)\n",
513新增: "B"
514新增: ],
515新增: "Files": null,
516新增: "Stdout": "A=$(id)\n",
517新增: "Stderr": "",
518新增: "Code": 0
519新增: },
520新增: {
521新增: "Dir": "{ROOT}",
522新增: "Stdin": "",
523新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
524新增: "Env": [
525新增: "HOME={T0}/034"
526新增: ],
527新增: "Args": [
528新增: "A=$HOME\n"
529新增: ],
530新增: "Files": null,
531新增: "Stdout": "A\n",
532新增: "Stderr": "",
533新增: "Code": 0
534新增: },
535新增: {
536新增: "Dir": "{ROOT}",
537新增: "Stdin": "",
538新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
539新增: "Env": [
540新增: "HOME={T0}/035"
541新增: ],
542新增: "Args": [
543新增: "A=$HOME\n",
544新增: "A"
545新增: ],
546新增: "Files": null,
547新增: "Stdout": "",
548新增: "Stderr": "",
549新增: "Code": 0
550新增: },
551新增: {
552新增: "Dir": "{ROOT}",
553新增: "Stdin": "",
554新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
555新增: "Env": [
556新增: "HOME={T0}/036"
557新增: ],
558新增: "Args": [
559新增: "A=$HOME\n",
560新增: "B"
561新增: ],
562新增: "Files": null,
563新增: "Stdout": "A=$HOME\n",
564新增: "Stderr": "",
565新增: "Code": 0
566新增: },
567新增: {
568新增: "Dir": "{ROOT}",
569新增: "Stdin": "",
570新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
571新增: "Env": [
572新增: "HOME={T0}/037"
573新增: ],
574新增: "Args": [
575新增: "B=1\nA=x$y\n"
576新增: ],
577新增: "Files": null,
578新增: "Stdout": "B\nA\n",
579新增: "Stderr": "",
580新增: "Code": 0
581新增: },
582新增: {
583新增: "Dir": "{ROOT}",
584新增: "Stdin": "",
585新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
586新增: "Env": [
587新增: "HOME={T0}/038"
588新增: ],
589新增: "Args": [
590新增: "B=1\nA=x$y\n",
591新增: "A"
592新增: ],
593新增: "Files": null,
594新增: "Stdout": "B=1\n",
595新增: "Stderr": "",
596新增: "Code": 0
597新增: },
598新增: {
599新增: "Dir": "{ROOT}",
600新增: "Stdin": "",
601新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
602新增: "Env": [
603新增: "HOME={T0}/039"
604新增: ],
605新增: "Args": [
606新增: "B=1\nA=x$y\n",
607新增: "B"
608新增: ],
609新增: "Files": null,
610新增: "Stdout": "A=x$y\n",
611新增: "Stderr": "",
612新增: "Code": 0
613新增: },
614新增: {
615新增: "Dir": "{ROOT}",
616新增: "Stdin": "",
617新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
618新增: "Env": [
619新增: "HOME={T0}/040"
620新增: ],
621新增: "Args": [
622新增: "A=~/x\n"
623新增: ],
624新增: "Files": null,
625新增: "Stdout": "A\n",
626新增: "Stderr": "",
627新增: "Code": 0
628新增: },
629新增: {
630新增: "Dir": "{ROOT}",
631新增: "Stdin": "",
632新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
633新增: "Env": [
634新增: "HOME={T0}/041"
635新增: ],
636新增: "Args": [
637新增: "A=~/x\n",
638新增: "A"
639新增: ],
640新增: "Files": null,
641新增: "Stdout": "",
642新增: "Stderr": "",
643新增: "Code": 0
644新增: },
645新增: {
646新增: "Dir": "{ROOT}",
647新增: "Stdin": "",
648新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
649新增: "Env": [
650新增: "HOME={T0}/042"
651新增: ],
652新增: "Args": [
653新增: "A=~/x\n",
654新增: "B"
655新增: ],
656新增: "Files": null,
657新增: "Stdout": "A=~/x\n",
658新增: "Stderr": "",
659新增: "Code": 0
660新增: },
661新增: {
662新增: "Dir": "{ROOT}",
663新增: "Stdin": "",
664新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
665新增: "Env": [
666新增: "HOME={T0}/043"
667新增: ],
668新增: "Args": [
669新增: "# just a comment\n\n \nA=1\r\nB='crlf'\r\n"
670新增: ],
671新增: "Files": null,
672新增: "Stdout": "A\nB\n",
673新增: "Stderr": "",
674新增: "Code": 0
675新增: },
676新增: {
677新增: "Dir": "{ROOT}",
678新增: "Stdin": "",
679新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
680新增: "Env": [
681新增: "HOME={T0}/044"
682新增: ],
683新增: "Args": [
684新增: "# just a comment\n\n \nA=1\r\nB='crlf'\r\n",
685新增: "A"
686新增: ],
687新增: "Files": null,
688新增: "Stdout": "# just a comment\n\n \nB='crlf'\r\n",
689新增: "Stderr": "",
690新增: "Code": 0
691新增: },
692新增: {
693新增: "Dir": "{ROOT}",
694新增: "Stdin": "",
695新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
696新增: "Env": [
697新增: "HOME={T0}/045"
698新增: ],
699新增: "Args": [
700新增: "# just a comment\n\n \nA=1\r\nB='crlf'\r\n",
701新增: "B"
702新增: ],
703新增: "Files": null,
704新增: "Stdout": "# just a comment\n\n \nA=1\r\n",
705新增: "Stderr": "",
706新增: "Code": 0
707新增: },
708新增: {
709新增: "Dir": "{ROOT}",
710新增: "Stdin": "",
711新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
712新增: "Env": [
713新增: "HOME={T0}/046"
714新增: ],
715新增: "Args": [
716新增: "A=1\nA=2\n"
717新增: ],
718新增: "Files": null,
719新增: "Stdout": "A\nA\n",
720新增: "Stderr": "",
721新增: "Code": 0
722新增: },
723新增: {
724新增: "Dir": "{ROOT}",
725新增: "Stdin": "",
726新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
727新增: "Env": [
728新增: "HOME={T0}/047"
729新增: ],
730新增: "Args": [
731新增: "A=1\nA=2\n",
732新增: "A"
733新增: ],
734新增: "Files": null,
735新增: "Stdout": "",
736新增: "Stderr": "",
737新增: "Code": 0
738新增: },
739新增: {
740新增: "Dir": "{ROOT}",
741新增: "Stdin": "",
742新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
743新增: "Env": [
744新增: "HOME={T0}/048"
745新增: ],
746新增: "Args": [
747新增: "A=1\nA=2\n",
748新增: "B"
749新增: ],
750新增: "Files": null,
751新增: "Stdout": "A=1\nA=2\n",
752新增: "Stderr": "",
753新增: "Code": 0
754新增: },
755新增: {
756新增: "Dir": "{ROOT}",
757新增: "Stdin": "",
758新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
759新增: "Env": [
760新增: "HOME={T0}/049"
761新增: ],
762新增: "Args": [
763新增: "A='it'\"'\"'s'\n"
764新增: ],
765新增: "Files": null,
766新增: "Stdout": "A\n",
767新增: "Stderr": "",
768新增: "Code": 0
769新增: },
770新增: {
771新增: "Dir": "{ROOT}",
772新增: "Stdin": "",
773新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
774新增: "Env": [
775新增: "HOME={T0}/050"
776新增: ],
777新增: "Args": [
778新增: "A='it'\"'\"'s'\n",
779新增: "A"
780新增: ],
781新增: "Files": null,
782新增: "Stdout": "",
783新增: "Stderr": "",
784新增: "Code": 0
785新增: },
786新增: {
787新增: "Dir": "{ROOT}",
788新增: "Stdin": "",
789新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
790新增: "Env": [
791新增: "HOME={T0}/051"
792新增: ],
793新增: "Args": [
794新增: "A='it'\"'\"'s'\n",
795新增: "B"
796新增: ],
797新增: "Files": null,
798新增: "Stdout": "A='it'\"'\"'s'\n",
799新增: "Stderr": "",
800新增: "Code": 0
801新增: },
802新增: {
803新增: "Dir": "{ROOT}",
804新增: "Stdin": "",
805新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
806新增: "Env": [
807新增: "HOME={T0}/052"
808新增: ],
809新增: "Args": [
810新增: "not an assignment\nA=1\n"
811新增: ],
812新增: "Files": null,
813新增: "Stdout": "A\n",
814新增: "Stderr": "",
815新增: "Code": 0
816新增: },
817新增: {
818新增: "Dir": "{ROOT}",
819新增: "Stdin": "",
820新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
821新增: "Env": [
822新增: "HOME={T0}/053"
823新增: ],
824新增: "Args": [
825新增: "not an assignment\nA=1\n",
826新增: "A"
827新增: ],
828新增: "Files": null,
829新增: "Stdout": "not an assignment\n",
830新增: "Stderr": "",
831新增: "Code": 0
832新增: },
833新增: {
834新增: "Dir": "{ROOT}",
835新增: "Stdin": "",
836新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
837新增: "Env": [
838新增: "HOME={T0}/054"
839新增: ],
840新增: "Args": [
841新增: "not an assignment\nA=1\n",
842新增: "B"
843新增: ],
844新增: "Files": null,
845新增: "Stdout": "not an assignment\nA=1\n",
846新增: "Stderr": "",
847新增: "Code": 0
848新增: },
849新增: {
850新增: "Dir": "{ROOT}",
851新增: "Stdin": "",
852新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
853新增: "Env": [
854新增: "HOME={T0}/055"
855新增: ],
856新增: "Args": [
857新增: "A=x\\\ny\n"
858新增: ],
859新增: "Files": null,
860新增: "Stdout": "A\n",
861新增: "Stderr": "",
862新增: "Code": 0
863新增: },
864新增: {
865新增: "Dir": "{ROOT}",
866新增: "Stdin": "",
867新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
868新增: "Env": [
869新增: "HOME={T0}/056"
870新增: ],
871新增: "Args": [
872新增: "A=x\\\ny\n",
873新增: "A"
874新增: ],
875新增: "Files": null,
876新增: "Stdout": "y\n",
877新增: "Stderr": "",
878新增: "Code": 0
879新增: },
880新增: {
881新增: "Dir": "{ROOT}",
882新增: "Stdin": "",
883新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
884新增: "Env": [
885新增: "HOME={T0}/057"
886新增: ],
887新增: "Args": [
888新增: "A=x\\\ny\n",
889新增: "B"
890新增: ],
891新增: "Files": null,
892新增: "Stdout": "A=x\\\ny\n",
893新增: "Stderr": "",
894新增: "Code": 0
895新增: },
896新增: {
897新增: "Dir": "{ROOT}",
898新增: "Stdin": "",
899新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
900新增: "Env": [
901新增: "HOME={T0}/058"
902新增: ],
903新增: "Args": [
904新增: "A= 1\n"
905新增: ],
906新增: "Files": null,
907新增: "Stdout": "A\n",
908新增: "Stderr": "",
909新增: "Code": 0
910新增: },
911新增: {
912新增: "Dir": "{ROOT}",
913新增: "Stdin": "",
914新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
915新增: "Env": [
916新增: "HOME={T0}/059"
917新增: ],
918新增: "Args": [
919新增: "A= 1\n",
920新增: "A"
921新增: ],
922新增: "Files": null,
923新增: "Stdout": "",
924新增: "Stderr": "",
925新增: "Code": 0
926新增: },
927新增: {
928新增: "Dir": "{ROOT}",
929新增: "Stdin": "",
930新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
931新增: "Env": [
932新增: "HOME={T0}/060"
933新增: ],
934新增: "Args": [
935新增: "A= 1\n",
936新增: "B"
937新增: ],
938新增: "Files": null,
939新增: "Stdout": "A= 1\n",
940新增: "Stderr": "",
941新增: "Code": 0
942新增: },
943新增: {
944新增: "Dir": "{ROOT}",
945新增: "Stdin": "",
946新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
947新增: "Env": [
948新增: "HOME={T0}/061"
949新增: ],
950新增: "Args": [
951新增: "A=\tB\n"
952新增: ],
953新增: "Files": null,
954新增: "Stdout": "A\n",
955新增: "Stderr": "",
956新增: "Code": 0
957新增: },
958新增: {
959新增: "Dir": "{ROOT}",
960新增: "Stdin": "",
961新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
962新增: "Env": [
963新增: "HOME={T0}/062"
964新增: ],
965新增: "Args": [
966新增: "A=\tB\n",
967新增: "A"
968新增: ],
969新增: "Files": null,
970新增: "Stdout": "",
971新增: "Stderr": "",
972新增: "Code": 0
973新增: },
974新增: {
975新增: "Dir": "{ROOT}",
976新增: "Stdin": "",
977新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
978新增: "Env": [
979新增: "HOME={T0}/063"
980新增: ],
981新增: "Args": [
982新增: "A=\tB\n",
983新增: "B"
984新增: ],
985新增: "Files": null,
986新增: "Stdout": "A=\tB\n",
987新增: "Stderr": "",
988新增: "Code": 0
989新增: },
990新增: {
991新增: "Dir": "{ROOT}",
992新增: "Stdin": "",
993新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
994新增: "Env": [
995新增: "HOME={T0}/064"
996新增: ],
997新增: "Args": [
998新增: "1A=x\n"
999新增: ],
1000新增: "Files": null,
1001新增: "Stdout": "",
1002新增: "Stderr": "",
1003新增: "Code": 0
1004新增: },
1005新增: {
1006新增: "Dir": "{ROOT}",
1007新增: "Stdin": "",
1008新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1009新增: "Env": [
1010新增: "HOME={T0}/065"
1011新增: ],
1012新增: "Args": [
1013新增: "1A=x\n",
1014新增: "A"
1015新增: ],
1016新增: "Files": null,
1017新增: "Stdout": "1A=x\n",
1018新增: "Stderr": "",
1019新增: "Code": 0
1020新增: },
1021新增: {
1022新增: "Dir": "{ROOT}",
1023新增: "Stdin": "",
1024新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1025新增: "Env": [
1026新增: "HOME={T0}/066"
1027新增: ],
1028新增: "Args": [
1029新增: "1A=x\n",
1030新增: "B"
1031新增: ],
1032新增: "Files": null,
1033新增: "Stdout": "1A=x\n",
1034新增: "Stderr": "",
1035新增: "Code": 0
1036新增: },
1037新增: {
1038新增: "Dir": "{ROOT}",
1039新增: "Stdin": "",
1040新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
1041新增: "Env": [
1042新增: "HOME={T0}/067"
1043新增: ],
1044新增: "Args": [
1045新增: "A=x y\n"
1046新增: ],
1047新增: "Files": null,
1048新增: "Stdout": "A\n",
1049新增: "Stderr": "",
1050新增: "Code": 0
1051新增: },
1052新增: {
1053新增: "Dir": "{ROOT}",
1054新增: "Stdin": "",
1055新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1056新增: "Env": [
1057新增: "HOME={T0}/068"
1058新增: ],
1059新增: "Args": [
1060新增: "A=x y\n",
1061新增: "A"
1062新增: ],
1063新增: "Files": null,
1064新增: "Stdout": "",
1065新增: "Stderr": "",
1066新增: "Code": 0
1067新增: },
1068新增: {
1069新增: "Dir": "{ROOT}",
1070新增: "Stdin": "",
1071新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1072新增: "Env": [
1073新增: "HOME={T0}/069"
1074新增: ],
1075新增: "Args": [
1076新增: "A=x y\n",
1077新增: "B"
1078新增: ],
1079新增: "Files": null,
1080新增: "Stdout": "A=x y\n",
1081新增: "Stderr": "",
1082新增: "Code": 0
1083新增: },
1084新增: {
1085新增: "Dir": "{ROOT}",
1086新增: "Stdin": "",
1087新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
1088新增: "Env": [
1089新增: "HOME={T0}/070"
1090新增: ],
1091新增: "Args": [
1092新增: "A='x' # c\n"
1093新增: ],
1094新增: "Files": null,
1095新增: "Stdout": "A\n",
1096新增: "Stderr": "",
1097新增: "Code": 0
1098新增: },
1099新增: {
1100新增: "Dir": "{ROOT}",
1101新增: "Stdin": "",
1102新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1103新增: "Env": [
1104新增: "HOME={T0}/071"
1105新增: ],
1106新增: "Args": [
1107新增: "A='x' # c\n",
1108新增: "A"
1109新增: ],
1110新增: "Files": null,
1111新增: "Stdout": "",
1112新增: "Stderr": "",
1113新增: "Code": 0
1114新增: },
1115新增: {
1116新增: "Dir": "{ROOT}",
1117新增: "Stdin": "",
1118新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1119新增: "Env": [
1120新增: "HOME={T0}/072"
1121新增: ],
1122新增: "Args": [
1123新增: "A='x' # c\n",
1124新增: "B"
1125新增: ],
1126新增: "Files": null,
1127新增: "Stdout": "A='x' # c\n",
1128新增: "Stderr": "",
1129新增: "Code": 0
1130新增: },
1131新增: {
1132新增: "Dir": "{ROOT}",
1133新增: "Stdin": "",
1134新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
1135新增: "Env": [
1136新增: "HOME={T0}/073"
1137新增: ],
1138新增: "Args": [
1139新增: "A=$'esc\\'aped'\nB=after\n"
1140新增: ],
1141新增: "Files": null,
1142新增: "Stdout": "A\nB\n",
1143新增: "Stderr": "",
1144新增: "Code": 0
1145新增: },
1146新增: {
1147新增: "Dir": "{ROOT}",
1148新增: "Stdin": "",
1149新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1150新增: "Env": [
1151新增: "HOME={T0}/074"
1152新增: ],
1153新增: "Args": [
1154新增: "A=$'esc\\'aped'\nB=after\n",
1155新增: "A"
1156新增: ],
1157新增: "Files": null,
1158新增: "Stdout": "B=after\n",
1159新增: "Stderr": "",
1160新增: "Code": 0
1161新增: },
1162新增: {
1163新增: "Dir": "{ROOT}",
1164新增: "Stdin": "",
1165新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1166新增: "Env": [
1167新增: "HOME={T0}/075"
1168新增: ],
1169新增: "Args": [
1170新增: "A=$'esc\\'aped'\nB=after\n",
1171新增: "B"
1172新增: ],
1173新增: "Files": null,
1174新增: "Stdout": "A=$'esc\\'aped'\n",
1175新增: "Stderr": "",
1176新增: "Code": 0
1177新增: },
1178新增: {
1179新增: "Dir": "{ROOT}",
1180新增: "Stdin": "",
1181新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
1182新增: "Env": [
1183新增: "HOME={T0}/076"
1184新增: ],
1185新增: "Args": [
1186新增: "A=\"dq \\\" esc\"\nB=after\n"
1187新增: ],
1188新增: "Files": null,
1189新增: "Stdout": "A\nB\n",
1190新增: "Stderr": "",
1191新增: "Code": 0
1192新增: },
1193新增: {
1194新增: "Dir": "{ROOT}",
1195新增: "Stdin": "",
1196新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1197新增: "Env": [
1198新增: "HOME={T0}/077"
1199新增: ],
1200新增: "Args": [
1201新增: "A=\"dq \\\" esc\"\nB=after\n",
1202新增: "A"
1203新增: ],
1204新增: "Files": null,
1205新增: "Stdout": "B=after\n",
1206新增: "Stderr": "",
1207新增: "Code": 0
1208新增: },
1209新增: {
1210新增: "Dir": "{ROOT}",
1211新增: "Stdin": "",
1212新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1213新增: "Env": [
1214新增: "HOME={T0}/078"
1215新增: ],
1216新增: "Args": [
1217新增: "A=\"dq \\\" esc\"\nB=after\n",
1218新增: "B"
1219新增: ],
1220新增: "Files": null,
1221新增: "Stdout": "A=\"dq \\\" esc\"\n",
1222新增: "Stderr": "",
1223新增: "Code": 0
1224新增: },
1225新增: {
1226新增: "Dir": "{ROOT}",
1227新增: "Stdin": "",
1228新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
1229新增: "Env": [
1230新增: "HOME={T0}/079"
1231新增: ],
1232新增: "Args": [
1233新增: "A='a'\"b\"c\n"
1234新增: ],
1235新增: "Files": null,
1236新增: "Stdout": "A\n",
1237新增: "Stderr": "",
1238新增: "Code": 0
1239新增: },
1240新增: {
1241新增: "Dir": "{ROOT}",
1242新增: "Stdin": "",
1243新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1244新增: "Env": [
1245新增: "HOME={T0}/080"
1246新增: ],
1247新增: "Args": [
1248新增: "A='a'\"b\"c\n",
1249新增: "A"
1250新增: ],
1251新增: "Files": null,
1252新增: "Stdout": "",
1253新增: "Stderr": "",
1254新增: "Code": 0
1255新增: },
1256新增: {
1257新增: "Dir": "{ROOT}",
1258新增: "Stdin": "",
1259新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1260新增: "Env": [
1261新增: "HOME={T0}/081"
1262新增: ],
1263新增: "Args": [
1264新增: "A='a'\"b\"c\n",
1265新增: "B"
1266新增: ],
1267新增: "Files": null,
1268新增: "Stdout": "A='a'\"b\"c\n",
1269新增: "Stderr": "",
1270新增: "Code": 0
1271新增: },
1272新增: {
1273新增: "Dir": "{ROOT}",
1274新增: "Stdin": "",
1275新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
1276新增: "Env": [
1277新增: "HOME={T0}/082"
1278新增: ],
1279新增: "Args": [
1280新增: "export\tA=1\nexport B\n"
1281新增: ],
1282新增: "Files": null,
1283新增: "Stdout": "A\n",
1284新增: "Stderr": "",
1285新增: "Code": 0
1286新增: },
1287新增: {
1288新增: "Dir": "{ROOT}",
1289新增: "Stdin": "",
1290新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1291新增: "Env": [
1292新增: "HOME={T0}/083"
1293新增: ],
1294新增: "Args": [
1295新增: "export\tA=1\nexport B\n",
1296新增: "A"
1297新增: ],
1298新增: "Files": null,
1299新增: "Stdout": "export B\n",
1300新增: "Stderr": "",
1301新增: "Code": 0
1302新增: },
1303新增: {
1304新增: "Dir": "{ROOT}",
1305新增: "Stdin": "",
1306新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1307新增: "Env": [
1308新增: "HOME={T0}/084"
1309新增: ],
1310新增: "Args": [
1311新增: "export\tA=1\nexport B\n",
1312新增: "B"
1313新增: ],
1314新增: "Files": null,
1315新增: "Stdout": "export\tA=1\nexport B\n",
1316新增: "Stderr": "",
1317新增: "Code": 0
1318新增: },
1319新增: {
1320新增: "Dir": "{ROOT}",
1321新增: "Stdin": "",
1322新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
1323新增: "Env": [
1324新增: "HOME={T0}/085"
1325新增: ],
1326新增: "Args": [
1327新增: "A=x # ' not a quote\nB=1\n"
1328新增: ],
1329新增: "Files": null,
1330新增: "Stdout": "A\nB\n",
1331新增: "Stderr": "",
1332新增: "Code": 0
1333新增: },
1334新增: {
1335新增: "Dir": "{ROOT}",
1336新增: "Stdin": "",
1337新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1338新增: "Env": [
1339新增: "HOME={T0}/086"
1340新增: ],
1341新增: "Args": [
1342新增: "A=x # ' not a quote\nB=1\n",
1343新增: "A"
1344新增: ],
1345新增: "Files": null,
1346新增: "Stdout": "B=1\n",
1347新增: "Stderr": "",
1348新增: "Code": 0
1349新增: },
1350新增: {
1351新增: "Dir": "{ROOT}",
1352新增: "Stdin": "",
1353新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1354新增: "Env": [
1355新增: "HOME={T0}/087"
1356新增: ],
1357新增: "Args": [
1358新增: "A=x # ' not a quote\nB=1\n",
1359新增: "B"
1360新增: ],
1361新增: "Files": null,
1362新增: "Stdout": "A=x # ' not a quote\n",
1363新增: "Stderr": "",
1364新增: "Code": 0
1365新增: },
1366新增: {
1367新增: "Dir": "{ROOT}",
1368新增: "Stdin": "",
1369新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
1370新增: "Env": [
1371新增: "HOME={T0}/088"
1372新增: ],
1373新增: "Args": [
1374新增: "A='x # not a comment'\nB=1\n"
1375新增: ],
1376新增: "Files": null,
1377新增: "Stdout": "A\nB\n",
1378新增: "Stderr": "",
1379新增: "Code": 0
1380新增: },
1381新增: {
1382新增: "Dir": "{ROOT}",
1383新增: "Stdin": "",
1384新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1385新增: "Env": [
1386新增: "HOME={T0}/089"
1387新增: ],
1388新增: "Args": [
1389新增: "A='x # not a comment'\nB=1\n",
1390新增: "A"
1391新增: ],
1392新增: "Files": null,
1393新增: "Stdout": "B=1\n",
1394新增: "Stderr": "",
1395新增: "Code": 0
1396新增: },
1397新增: {
1398新增: "Dir": "{ROOT}",
1399新增: "Stdin": "",
1400新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1401新增: "Env": [
1402新增: "HOME={T0}/090"
1403新增: ],
1404新增: "Args": [
1405新增: "A='x # not a comment'\nB=1\n",
1406新增: "B"
1407新增: ],
1408新增: "Files": null,
1409新增: "Stdout": "A='x # not a comment'\n",
1410新增: "Stderr": "",
1411新增: "Code": 0
1412新增: },
1413新增: {
1414新增: "Dir": "{ROOT}",
1415新增: "Stdin": "",
1416新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
1417新增: "Env": [
1418新增: "HOME={T0}/091"
1419新增: ],
1420新增: "Args": [
1421新增: "A=café\nB='naïve'\n"
1422新增: ],
1423新增: "Files": null,
1424新增: "Stdout": "A\nB\n",
1425新增: "Stderr": "",
1426新增: "Code": 0
1427新增: },
1428新增: {
1429新增: "Dir": "{ROOT}",
1430新增: "Stdin": "",
1431新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1432新增: "Env": [
1433新增: "HOME={T0}/092"
1434新增: ],
1435新增: "Args": [
1436新增: "A=café\nB='naïve'\n",
1437新增: "A"
1438新增: ],
1439新增: "Files": null,
1440新增: "Stdout": "B='naïve'\n",
1441新增: "Stderr": "",
1442新增: "Code": 0
1443新增: },
1444新增: {
1445新增: "Dir": "{ROOT}",
1446新增: "Stdin": "",
1447新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1448新增: "Env": [
1449新增: "HOME={T0}/093"
1450新增: ],
1451新增: "Args": [
1452新增: "A=café\nB='naïve'\n",
1453新增: "B"
1454新增: ],
1455新增: "Files": null,
1456新增: "Stdout": "A=café\n",
1457新增: "Stderr": "",
1458新增: "Code": 0
1459新增: },
1460新增: {
1461新增: "Dir": "{ROOT}",
1462新增: "Stdin": "",
1463新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines list -",
1464新增: "Env": [
1465新增: "HOME={T0}/094"
1466新增: ],
1467新增: "Args": [
1468新增: {
1469新增: "base64": "QT2S/wo="
1470新增: }
1471新增: ],
1472新增: "Files": null,
1473新增: "Stdout": "A\n",
1474新增: "Stderr": "",
1475新增: "Code": 0
1476新增: },
1477新增: {
1478新增: "Dir": "{ROOT}",
1479新增: "Stdin": "",
1480新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1481新增: "Env": [
1482新增: "HOME={T0}/095"
1483新增: ],
1484新增: "Args": [
1485新增: {
1486新增: "base64": "QT2S/wo="
1487新增: },
1488新增: "A"
1489新增: ],
1490新增: "Files": null,
1491新增: "Stdout": "",
1492新增: "Stderr": "",
1493新增: "Code": 0
1494新增: },
1495新增: {
1496新增: "Dir": "{ROOT}",
1497新增: "Stdin": "",
1498新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_lines drop - \"$2\"",
1499新增: "Env": [
1500新增: "HOME={T0}/096"
1501新增: ],
1502新增: "Args": [
1503新增: {
1504新增: "base64": "QT2S/wo="
1505新增: },
1506新增: "B"
1507新增: ],
1508新增: "Files": null,
1509新增: "Stdout": {
1510新增: "base64": "QT2S/wo="
1511新增: },
1512新增: "Stderr": "",
1513新增: "Code": 0
1514新增: }
1515新增: ]
1516新增:}
新增internal/env/testdata/bashref/TestNoFollowBash.json+956 −0看文件
@@ -0,0 +1,956 @@
1新增:{
2新增: "TestNoFollowBash": [
3新增: {
4新增: "Dir": "{ROOT}",
5新增: "Stdin": "",
6新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
7新增: "Env": [
8新增: "HOME={T0}/003"
9新增: ],
10新增: "Args": [
11新增: "read",
12新增: "{T0}/002/proj",
13新增: "plain"
14新增: ],
15新增: "Files": null,
16新增: "Stdout": "A=1\n",
17新增: "Stderr": "",
18新增: "Code": 0
19新增: },
20新增: {
21新增: "Dir": "{ROOT}",
22新增: "Stdin": "",
23新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
24新增: "Env": [
25新增: "HOME={T0}/006"
26新增: ],
27新增: "Args": [
28新增: "read",
29新增: "{T0}/005/proj",
30新增: "d/e/f"
31新增: ],
32新增: "Files": null,
33新增: "Stdout": "deep\n",
34新增: "Stderr": "",
35新增: "Code": 0
36新增: },
37新增: {
38新增: "Dir": "{ROOT}",
39新增: "Stdin": "",
40新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
41新增: "Env": [
42新增: "HOME={T0}/009"
43新增: ],
44新增: "Args": [
45新增: "read",
46新增: "{T0}/008/proj",
47新增: "missing"
48新增: ],
49新增: "Files": null,
50新增: "Stdout": "",
51新增: "Stderr": "",
52新增: "Code": 1
53新增: },
54新增: {
55新增: "Dir": "{ROOT}",
56新增: "Stdin": "",
57新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
58新增: "Env": [
59新增: "HOME={T0}/012"
60新增: ],
61新增: "Args": [
62新增: "read",
63新增: "{T0}/011/proj",
64新增: "new/dir/file"
65新增: ],
66新增: "Files": null,
67新增: "Stdout": "",
68新增: "Stderr": "",
69新增: "Code": 1
70新增: },
71新增: {
72新增: "Dir": "{ROOT}",
73新增: "Stdin": "",
74新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
75新增: "Env": [
76新增: "HOME={T0}/015"
77新增: ],
78新增: "Args": [
79新增: "read",
80新增: "{T0}/014/proj",
81新增: "link"
82新增: ],
83新增: "Files": null,
84新增: "Stdout": "",
85新增: "Stderr": "",
86新增: "Code": 3
87新增: },
88新增: {
89新增: "Dir": "{ROOT}",
90新增: "Stdin": "",
91新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
92新增: "Env": [
93新增: "HOME={T0}/018"
94新增: ],
95新增: "Args": [
96新增: "read",
97新增: "{T0}/017/proj",
98新增: "dirlink/x"
99新增: ],
100新增: "Files": null,
101新增: "Stdout": "",
102新增: "Stderr": "",
103新增: "Code": 3
104新增: },
105新增: {
106新增: "Dir": "{ROOT}",
107新增: "Stdin": "",
108新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
109新增: "Env": [
110新增: "HOME={T0}/021"
111新增: ],
112新增: "Args": [
113新增: "read",
114新增: "{T0}/020/proj",
115新增: "innerlink"
116新增: ],
117新增: "Files": null,
118新增: "Stdout": "",
119新增: "Stderr": "",
120新增: "Code": 3
121新增: },
122新增: {
123新增: "Dir": "{ROOT}",
124新增: "Stdin": "",
125新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
126新增: "Env": [
127新增: "HOME={T0}/024"
128新增: ],
129新增: "Args": [
130新增: "read",
131新增: "{T0}/023/proj",
132新增: "fifo"
133新增: ],
134新增: "Files": null,
135新增: "Stdout": "",
136新增: "Stderr": "",
137新增: "Code": 3
138新增: },
139新增: {
140新增: "Dir": "{ROOT}",
141新增: "Stdin": "",
142新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
143新增: "Env": [
144新增: "HOME={T0}/027"
145新增: ],
146新增: "Args": [
147新增: "read",
148新增: "{T0}/026/proj",
149新增: "d"
150新增: ],
151新增: "Files": null,
152新增: "Stdout": "",
153新增: "Stderr": "",
154新增: "Code": 3
155新增: },
156新增: {
157新增: "Dir": "{ROOT}",
158新增: "Stdin": "",
159新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
160新增: "Env": [
161新增: "HOME={T0}/030"
162新增: ],
163新增: "Args": [
164新增: "read",
165新增: "{T0}/029/proj",
166新增: "d/e"
167新增: ],
168新增: "Files": null,
169新增: "Stdout": "",
170新增: "Stderr": "",
171新增: "Code": 3
172新增: },
173新增: {
174新增: "Dir": "{ROOT}",
175新增: "Stdin": "",
176新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
177新增: "Env": [
178新增: "HOME={T0}/033"
179新增: ],
180新增: "Args": [
181新增: "read",
182新增: "{T0}/032/proj",
183新增: "../secret"
184新增: ],
185新增: "Files": null,
186新增: "Stdout": "",
187新增: "Stderr": "",
188新增: "Code": 3
189新增: },
190新增: {
191新增: "Dir": "{ROOT}",
192新增: "Stdin": "",
193新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
194新增: "Env": [
195新增: "HOME={T0}/036"
196新增: ],
197新增: "Args": [
198新增: "read",
199新增: "{T0}/035/proj",
200新增: ""
201新增: ],
202新增: "Files": null,
203新增: "Stdout": "",
204新增: "Stderr": "",
205新增: "Code": 3
206新增: },
207新增: {
208新增: "Dir": "{ROOT}",
209新增: "Stdin": "",
210新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
211新增: "Env": [
212新增: "HOME={T0}/039"
213新增: ],
214新增: "Args": [
215新增: "read",
216新增: "{T0}/038/proj",
217新增: "./plain"
218新增: ],
219新增: "Files": null,
220新增: "Stdout": "A=1\n",
221新增: "Stderr": "",
222新增: "Code": 0
223新增: },
224新增: {
225新增: "Dir": "{ROOT}",
226新增: "Stdin": "",
227新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
228新增: "Env": [
229新增: "HOME={T0}/042"
230新增: ],
231新增: "Args": [
232新增: "read",
233新增: "{T0}/041/proj",
234新增: "d//e/./f"
235新增: ],
236新增: "Files": null,
237新增: "Stdout": "deep\n",
238新增: "Stderr": "",
239新增: "Code": 0
240新增: },
241新增: {
242新增: "Dir": "{ROOT}",
243新增: "Stdin": "",
244新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
245新增: "Env": [
246新增: "HOME={T0}/045"
247新增: ],
248新增: "Args": [
249新增: "write",
250新增: "{T0}/044/proj",
251新增: "plain"
252新增: ],
253新增: "Files": null,
254新增: "Stdout": "",
255新增: "Stderr": "",
256新增: "Code": 0
257新增: },
258新增: {
259新增: "Dir": "{ROOT}",
260新增: "Stdin": "",
261新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
262新增: "Env": [
263新增: "HOME={T0}/048"
264新增: ],
265新增: "Args": [
266新增: "write",
267新增: "{T0}/047/proj",
268新增: "d/e/f"
269新增: ],
270新增: "Files": null,
271新增: "Stdout": "",
272新增: "Stderr": "",
273新增: "Code": 0
274新增: },
275新增: {
276新增: "Dir": "{ROOT}",
277新增: "Stdin": "",
278新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
279新增: "Env": [
280新增: "HOME={T0}/051"
281新增: ],
282新增: "Args": [
283新增: "write",
284新增: "{T0}/050/proj",
285新增: "missing"
286新增: ],
287新增: "Files": null,
288新增: "Stdout": "",
289新增: "Stderr": "",
290新增: "Code": 0
291新增: },
292新增: {
293新增: "Dir": "{ROOT}",
294新增: "Stdin": "",
295新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
296新增: "Env": [
297新增: "HOME={T0}/054"
298新增: ],
299新增: "Args": [
300新增: "write",
301新增: "{T0}/053/proj",
302新增: "new/dir/file"
303新增: ],
304新增: "Files": null,
305新增: "Stdout": "",
306新增: "Stderr": "",
307新增: "Code": 0
308新增: },
309新增: {
310新增: "Dir": "{ROOT}",
311新增: "Stdin": "",
312新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
313新增: "Env": [
314新增: "HOME={T0}/057"
315新增: ],
316新增: "Args": [
317新增: "write",
318新增: "{T0}/056/proj",
319新增: "link"
320新增: ],
321新增: "Files": null,
322新增: "Stdout": "",
323新增: "Stderr": "",
324新增: "Code": 0
325新增: },
326新增: {
327新增: "Dir": "{ROOT}",
328新增: "Stdin": "",
329新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
330新增: "Env": [
331新增: "HOME={T0}/060"
332新增: ],
333新增: "Args": [
334新增: "write",
335新增: "{T0}/059/proj",
336新增: "dirlink/x"
337新增: ],
338新增: "Files": null,
339新增: "Stdout": "",
340新增: "Stderr": "",
341新增: "Code": 3
342新增: },
343新增: {
344新增: "Dir": "{ROOT}",
345新增: "Stdin": "",
346新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
347新增: "Env": [
348新增: "HOME={T0}/063"
349新增: ],
350新增: "Args": [
351新增: "write",
352新增: "{T0}/062/proj",
353新增: "innerlink"
354新增: ],
355新增: "Files": null,
356新增: "Stdout": "",
357新增: "Stderr": "",
358新增: "Code": 0
359新增: },
360新增: {
361新增: "Dir": "{ROOT}",
362新增: "Stdin": "",
363新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
364新增: "Env": [
365新增: "HOME={T0}/066"
366新增: ],
367新增: "Args": [
368新增: "write",
369新增: "{T0}/065/proj",
370新增: "fifo"
371新增: ],
372新增: "Files": null,
373新增: "Stdout": "",
374新增: "Stderr": "",
375新增: "Code": 0
376新增: },
377新增: {
378新增: "Dir": "{ROOT}",
379新增: "Stdin": "",
380新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
381新增: "Env": [
382新增: "HOME={T0}/069"
383新增: ],
384新增: "Args": [
385新增: "write",
386新增: "{T0}/068/proj",
387新增: "d"
388新增: ],
389新增: "Files": null,
390新增: "Stdout": "",
391新增: "Stderr": "",
392新增: "Code": 2
393新增: },
394新增: {
395新增: "Dir": "{ROOT}",
396新增: "Stdin": "",
397新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
398新增: "Env": [
399新增: "HOME={T0}/072"
400新增: ],
401新增: "Args": [
402新增: "write",
403新增: "{T0}/071/proj",
404新增: "d/e"
405新增: ],
406新增: "Files": null,
407新增: "Stdout": "",
408新增: "Stderr": "",
409新增: "Code": 2
410新增: },
411新增: {
412新增: "Dir": "{ROOT}",
413新增: "Stdin": "",
414新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
415新增: "Env": [
416新增: "HOME={T0}/075"
417新增: ],
418新增: "Args": [
419新增: "write",
420新增: "{T0}/074/proj",
421新增: "../secret"
422新增: ],
423新增: "Files": null,
424新增: "Stdout": "",
425新增: "Stderr": "",
426新增: "Code": 3
427新增: },
428新增: {
429新增: "Dir": "{ROOT}",
430新增: "Stdin": "",
431新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
432新增: "Env": [
433新增: "HOME={T0}/078"
434新增: ],
435新增: "Args": [
436新增: "write",
437新增: "{T0}/077/proj",
438新增: ""
439新增: ],
440新增: "Files": null,
441新增: "Stdout": "",
442新增: "Stderr": "",
443新增: "Code": 3
444新增: },
445新增: {
446新增: "Dir": "{ROOT}",
447新增: "Stdin": "",
448新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
449新增: "Env": [
450新增: "HOME={T0}/081"
451新增: ],
452新增: "Args": [
453新增: "write",
454新增: "{T0}/080/proj",
455新增: "./plain"
456新增: ],
457新增: "Files": null,
458新增: "Stdout": "",
459新增: "Stderr": "",
460新增: "Code": 0
461新增: },
462新增: {
463新增: "Dir": "{ROOT}",
464新增: "Stdin": "",
465新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
466新增: "Env": [
467新增: "HOME={T0}/084"
468新增: ],
469新增: "Args": [
470新增: "write",
471新增: "{T0}/083/proj",
472新增: "d//e/./f"
473新增: ],
474新增: "Files": null,
475新增: "Stdout": "",
476新增: "Stderr": "",
477新增: "Code": 0
478新增: },
479新增: {
480新增: "Dir": "{ROOT}",
481新增: "Stdin": "",
482新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
483新增: "Env": [
484新增: "HOME={T0}/087"
485新增: ],
486新增: "Args": [
487新增: "mkdir",
488新增: "{T0}/086/proj",
489新增: "plain"
490新增: ],
491新增: "Files": null,
492新增: "Stdout": "",
493新增: "Stderr": "",
494新增: "Code": 3
495新增: },
496新增: {
497新增: "Dir": "{ROOT}",
498新增: "Stdin": "",
499新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
500新增: "Env": [
501新增: "HOME={T0}/090"
502新增: ],
503新增: "Args": [
504新增: "mkdir",
505新增: "{T0}/089/proj",
506新增: "d/e/f"
507新增: ],
508新增: "Files": null,
509新增: "Stdout": "",
510新增: "Stderr": "",
511新增: "Code": 3
512新增: },
513新增: {
514新增: "Dir": "{ROOT}",
515新增: "Stdin": "",
516新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
517新增: "Env": [
518新增: "HOME={T0}/093"
519新增: ],
520新增: "Args": [
521新增: "mkdir",
522新增: "{T0}/092/proj",
523新增: "missing"
524新增: ],
525新增: "Files": null,
526新增: "Stdout": "",
527新增: "Stderr": "",
528新增: "Code": 0
529新增: },
530新增: {
531新增: "Dir": "{ROOT}",
532新增: "Stdin": "",
533新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
534新增: "Env": [
535新增: "HOME={T0}/096"
536新增: ],
537新增: "Args": [
538新增: "mkdir",
539新增: "{T0}/095/proj",
540新增: "new/dir/file"
541新增: ],
542新增: "Files": null,
543新增: "Stdout": "",
544新增: "Stderr": "",
545新增: "Code": 0
546新增: },
547新增: {
548新增: "Dir": "{ROOT}",
549新增: "Stdin": "",
550新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
551新增: "Env": [
552新增: "HOME={T0}/099"
553新增: ],
554新增: "Args": [
555新增: "mkdir",
556新增: "{T0}/098/proj",
557新增: "link"
558新增: ],
559新增: "Files": null,
560新增: "Stdout": "",
561新增: "Stderr": "",
562新增: "Code": 3
563新增: },
564新增: {
565新增: "Dir": "{ROOT}",
566新增: "Stdin": "",
567新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
568新增: "Env": [
569新增: "HOME={T0}/102"
570新增: ],
571新增: "Args": [
572新增: "mkdir",
573新增: "{T0}/101/proj",
574新增: "dirlink/x"
575新增: ],
576新增: "Files": null,
577新增: "Stdout": "",
578新增: "Stderr": "",
579新增: "Code": 3
580新增: },
581新增: {
582新增: "Dir": "{ROOT}",
583新增: "Stdin": "",
584新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
585新增: "Env": [
586新增: "HOME={T0}/105"
587新增: ],
588新增: "Args": [
589新增: "mkdir",
590新增: "{T0}/104/proj",
591新增: "innerlink"
592新增: ],
593新增: "Files": null,
594新增: "Stdout": "",
595新增: "Stderr": "",
596新增: "Code": 3
597新增: },
598新增: {
599新增: "Dir": "{ROOT}",
600新增: "Stdin": "",
601新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
602新增: "Env": [
603新增: "HOME={T0}/108"
604新增: ],
605新增: "Args": [
606新增: "mkdir",
607新增: "{T0}/107/proj",
608新增: "fifo"
609新增: ],
610新增: "Files": null,
611新增: "Stdout": "",
612新增: "Stderr": "",
613新增: "Code": 3
614新增: },
615新增: {
616新增: "Dir": "{ROOT}",
617新增: "Stdin": "",
618新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
619新增: "Env": [
620新增: "HOME={T0}/111"
621新增: ],
622新增: "Args": [
623新增: "mkdir",
624新增: "{T0}/110/proj",
625新增: "d"
626新增: ],
627新增: "Files": null,
628新增: "Stdout": "",
629新增: "Stderr": "",
630新增: "Code": 0
631新增: },
632新增: {
633新增: "Dir": "{ROOT}",
634新增: "Stdin": "",
635新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
636新增: "Env": [
637新增: "HOME={T0}/114"
638新增: ],
639新增: "Args": [
640新增: "mkdir",
641新增: "{T0}/113/proj",
642新增: "d/e"
643新增: ],
644新增: "Files": null,
645新增: "Stdout": "",
646新增: "Stderr": "",
647新增: "Code": 0
648新增: },
649新增: {
650新增: "Dir": "{ROOT}",
651新增: "Stdin": "",
652新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
653新增: "Env": [
654新增: "HOME={T0}/117"
655新增: ],
656新增: "Args": [
657新增: "mkdir",
658新增: "{T0}/116/proj",
659新增: "../secret"
660新增: ],
661新增: "Files": null,
662新增: "Stdout": "",
663新增: "Stderr": "",
664新增: "Code": 3
665新增: },
666新增: {
667新增: "Dir": "{ROOT}",
668新增: "Stdin": "",
669新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
670新增: "Env": [
671新增: "HOME={T0}/120"
672新增: ],
673新增: "Args": [
674新增: "mkdir",
675新增: "{T0}/119/proj",
676新增: ""
677新增: ],
678新增: "Files": null,
679新增: "Stdout": "",
680新增: "Stderr": "",
681新增: "Code": 3
682新增: },
683新增: {
684新增: "Dir": "{ROOT}",
685新增: "Stdin": "",
686新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
687新增: "Env": [
688新增: "HOME={T0}/123"
689新增: ],
690新增: "Args": [
691新增: "mkdir",
692新增: "{T0}/122/proj",
693新增: "./plain"
694新增: ],
695新增: "Files": null,
696新增: "Stdout": "",
697新增: "Stderr": "",
698新增: "Code": 3
699新增: },
700新增: {
701新增: "Dir": "{ROOT}",
702新增: "Stdin": "",
703新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
704新增: "Env": [
705新增: "HOME={T0}/126"
706新增: ],
707新增: "Args": [
708新增: "mkdir",
709新增: "{T0}/125/proj",
710新增: "d//e/./f"
711新增: ],
712新增: "Files": null,
713新增: "Stdout": "",
714新增: "Stderr": "",
715新增: "Code": 3
716新增: },
717新增: {
718新增: "Dir": "{ROOT}",
719新增: "Stdin": "",
720新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
721新增: "Env": [
722新增: "HOME={T0}/129"
723新增: ],
724新增: "Args": [
725新增: "touch",
726新增: "{T0}/128/proj",
727新增: "plain"
728新增: ],
729新增: "Files": null,
730新增: "Stdout": "",
731新增: "Stderr": "",
732新增: "Code": 0
733新增: },
734新增: {
735新增: "Dir": "{ROOT}",
736新增: "Stdin": "",
737新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
738新增: "Env": [
739新增: "HOME={T0}/132"
740新增: ],
741新增: "Args": [
742新增: "touch",
743新增: "{T0}/131/proj",
744新增: "d/e/f"
745新增: ],
746新增: "Files": null,
747新增: "Stdout": "",
748新增: "Stderr": "",
749新增: "Code": 0
750新增: },
751新增: {
752新增: "Dir": "{ROOT}",
753新增: "Stdin": "",
754新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
755新增: "Env": [
756新增: "HOME={T0}/135"
757新增: ],
758新增: "Args": [
759新增: "touch",
760新增: "{T0}/134/proj",
761新增: "missing"
762新增: ],
763新增: "Files": null,
764新增: "Stdout": "",
765新增: "Stderr": "",
766新增: "Code": 0
767新增: },
768新增: {
769新增: "Dir": "{ROOT}",
770新增: "Stdin": "",
771新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
772新增: "Env": [
773新增: "HOME={T0}/138"
774新增: ],
775新增: "Args": [
776新增: "touch",
777新增: "{T0}/137/proj",
778新增: "new/dir/file"
779新增: ],
780新增: "Files": null,
781新增: "Stdout": "",
782新增: "Stderr": "",
783新增: "Code": 0
784新增: },
785新增: {
786新增: "Dir": "{ROOT}",
787新增: "Stdin": "",
788新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
789新增: "Env": [
790新增: "HOME={T0}/141"
791新增: ],
792新增: "Args": [
793新增: "touch",
794新增: "{T0}/140/proj",
795新增: "link"
796新增: ],
797新增: "Files": null,
798新增: "Stdout": "",
799新增: "Stderr": "",
800新增: "Code": 3
801新增: },
802新增: {
803新增: "Dir": "{ROOT}",
804新增: "Stdin": "",
805新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
806新增: "Env": [
807新增: "HOME={T0}/144"
808新增: ],
809新增: "Args": [
810新增: "touch",
811新增: "{T0}/143/proj",
812新增: "dirlink/x"
813新增: ],
814新增: "Files": null,
815新增: "Stdout": "",
816新增: "Stderr": "",
817新增: "Code": 3
818新增: },
819新增: {
820新增: "Dir": "{ROOT}",
821新增: "Stdin": "",
822新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
823新增: "Env": [
824新增: "HOME={T0}/147"
825新增: ],
826新增: "Args": [
827新增: "touch",
828新增: "{T0}/146/proj",
829新增: "innerlink"
830新增: ],
831新增: "Files": null,
832新增: "Stdout": "",
833新增: "Stderr": "",
834新增: "Code": 3
835新增: },
836新增: {
837新增: "Dir": "{ROOT}",
838新增: "Stdin": "",
839新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
840新增: "Env": [
841新增: "HOME={T0}/150"
842新增: ],
843新增: "Args": [
844新增: "touch",
845新增: "{T0}/149/proj",
846新增: "fifo"
847新增: ],
848新增: "Files": null,
849新增: "Stdout": "",
850新增: "Stderr": "",
851新增: "Code": 3
852新增: },
853新增: {
854新增: "Dir": "{ROOT}",
855新增: "Stdin": "",
856新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
857新增: "Env": [
858新增: "HOME={T0}/153"
859新增: ],
860新增: "Args": [
861新增: "touch",
862新增: "{T0}/152/proj",
863新增: "d"
864新增: ],
865新增: "Files": null,
866新增: "Stdout": "",
867新增: "Stderr": "",
868新增: "Code": 3
869新增: },
870新增: {
871新增: "Dir": "{ROOT}",
872新增: "Stdin": "",
873新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
874新增: "Env": [
875新增: "HOME={T0}/156"
876新增: ],
877新增: "Args": [
878新增: "touch",
879新增: "{T0}/155/proj",
880新增: "d/e"
881新增: ],
882新增: "Files": null,
883新增: "Stdout": "",
884新增: "Stderr": "",
885新增: "Code": 3
886新增: },
887新增: {
888新增: "Dir": "{ROOT}",
889新增: "Stdin": "",
890新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
891新增: "Env": [
892新增: "HOME={T0}/159"
893新增: ],
894新增: "Args": [
895新增: "touch",
896新增: "{T0}/158/proj",
897新增: "../secret"
898新增: ],
899新增: "Files": null,
900新增: "Stdout": "",
901新增: "Stderr": "",
902新增: "Code": 3
903新增: },
904新增: {
905新增: "Dir": "{ROOT}",
906新增: "Stdin": "",
907新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
908新增: "Env": [
909新增: "HOME={T0}/162"
910新增: ],
911新增: "Args": [
912新增: "touch",
913新增: "{T0}/161/proj",
914新增: ""
915新增: ],
916新增: "Files": null,
917新增: "Stdout": "",
918新增: "Stderr": "",
919新增: "Code": 3
920新增: },
921新增: {
922新增: "Dir": "{ROOT}",
923新增: "Stdin": "",
924新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
925新增: "Env": [
926新增: "HOME={T0}/165"
927新增: ],
928新增: "Args": [
929新增: "touch",
930新增: "{T0}/164/proj",
931新增: "./plain"
932新增: ],
933新增: "Files": null,
934新增: "Stdout": "",
935新增: "Stderr": "",
936新增: "Code": 0
937新增: },
938新增: {
939新增: "Dir": "{ROOT}",
940新增: "Stdin": "",
941新增: "Snippet": "printf 'NEW\\n' | _agent_vm_nofollow \"$@\"",
942新增: "Env": [
943新增: "HOME={T0}/168"
944新增: ],
945新增: "Args": [
946新增: "touch",
947新增: "{T0}/167/proj",
948新增: "d//e/./f"
949新增: ],
950新增: "Files": null,
951新增: "Stdout": "",
952新增: "Stderr": "",
953新增: "Code": 0
954新增: }
955新增: ]
956新增:}
新增internal/env/testdata/bashref/TestPayloadBash.json+74 −0看文件
@@ -0,0 +1,74 @@
1新增:{
2新增: "TestPayloadBash": [
3新增: {
4新增: "Dir": "{ROOT}",
5新增: "Stdin": "",
6新增: "Snippet": "\"$@\"",
7新增: "Env": [
8新增: "HOME={T0}/002",
9新增: "AGENT_VM_STATE_DIR={T0}/001/state"
10新增: ],
11新增: "Args": [
12新增: "_agent_vm_env_payload",
13新增: "{T0}/001/proj"
14新增: ],
15新增: "Files": null,
16新增: "Stdout": "A=1\nB=2\n\n",
17新增: "Stderr": "",
18新增: "Code": 0
19新增: },
20新增: {
21新增: "Dir": "{ROOT}",
22新增: "Stdin": "",
23新增: "Snippet": "\"$@\"",
24新增: "Env": [
25新增: "HOME={T0}/003",
26新增: "AGENT_VM_STATE_DIR={T0}/001/state",
27新增: "AGENT_VM_PROJECT_ENV=../outside.env"
28新增: ],
29新增: "Args": [
30新增: "_agent_vm_env_payload",
31新增: "{T0}/001/proj"
32新增: ],
33新增: "Files": null,
34新增: "Stdout": "A=1\n\nP=1\n",
35新增: "Stderr": "",
36新增: "Code": 0
37新增: },
38新增: {
39新增: "Dir": "{ROOT}",
40新增: "Stdin": "",
41新增: "Snippet": "\"$@\"",
42新增: "Env": [
43新增: "HOME={T0}/004",
44新增: "AGENT_VM_STATE_DIR={T0}/001/state",
45新增: "AGENT_VM_PROJECT_ENV=.agent-vm.env"
46新增: ],
47新增: "Args": [
48新增: "_agent_vm_env_payload",
49新增: "{T0}/001/proj"
50新增: ],
51新增: "Files": null,
52新增: "Stdout": "",
53新增: "Stderr": "",
54新增: "Code": 0
55新增: },
56新增: {
57新增: "Dir": "{ROOT}",
58新增: "Stdin": "",
59新增: "Snippet": "\"$@\"",
60新增: "Env": [
61新增: "HOME={T0}/005",
62新增: "AGENT_VM_STATE_DIR={T0}/001/state"
63新增: ],
64新增: "Args": [
65新增: "_agent_vm_env_payload",
66新增: "{T0}/001/proj"
67新增: ],
68新增: "Files": null,
69新增: "Stdout": "A=1\n\n",
70新增: "Stderr": "",
71新增: "Code": 0
72新增: }
73新增: ]
74新增:}
新增internal/env/testdata/bashref/TestProjectRelBash.json+208 −0看文件
@@ -0,0 +1,208 @@
1新增:{
2新增: "TestProjectRelBash": [
3新增: {
4新增: "Dir": "{ROOT}",
5新增: "Stdin": "",
6新增: "Snippet": "\"$@\"",
7新增: "Env": [
8新增: "HOME={T0}/002"
9新增: ],
10新增: "Args": [
11新增: "_agent_vm_project_rel",
12新增: "{T0}/001/proj",
13新增: "{T0}/001/proj/.agent-vm.env"
14新增: ],
15新增: "Files": null,
16新增: "Stdout": ".agent-vm.env\n",
17新增: "Stderr": "",
18新增: "Code": 0
19新增: },
20新增: {
21新增: "Dir": "{ROOT}",
22新增: "Stdin": "",
23新增: "Snippet": "\"$@\"",
24新增: "Env": [
25新增: "HOME={T0}/003"
26新增: ],
27新增: "Args": [
28新增: "_agent_vm_project_rel",
29新增: "{T0}/001/proj",
30新增: "{T0}/001/proj/sub/x"
31新增: ],
32新增: "Files": null,
33新增: "Stdout": "sub/x\n",
34新增: "Stderr": "",
35新增: "Code": 0
36新增: },
37新增: {
38新增: "Dir": "{ROOT}",
39新增: "Stdin": "",
40新增: "Snippet": "\"$@\"",
41新增: "Env": [
42新增: "HOME={T0}/004"
43新增: ],
44新增: "Args": [
45新增: "_agent_vm_project_rel",
46新增: "{T0}/001/proj",
47新增: "{T0}/001/projlink/x"
48新增: ],
49新增: "Files": null,
50新增: "Stdout": "x\n",
51新增: "Stderr": "",
52新增: "Code": 0
53新增: },
54新增: {
55新增: "Dir": "{ROOT}",
56新增: "Stdin": "",
57新增: "Snippet": "\"$@\"",
58新增: "Env": [
59新增: "HOME={T0}/005"
60新增: ],
61新增: "Args": [
62新增: "_agent_vm_project_rel",
63新增: "{T0}/001/proj",
64新增: "{T0}/001/elselink/x"
65新增: ],
66新增: "Files": null,
67新增: "Stdout": "",
68新增: "Stderr": "",
69新增: "Code": 1
70新增: },
71新增: {
72新增: "Dir": "{ROOT}",
73新增: "Stdin": "",
74新增: "Snippet": "\"$@\"",
75新增: "Env": [
76新增: "HOME={T0}/006"
77新增: ],
78新增: "Args": [
79新增: "_agent_vm_project_rel",
80新增: "{T0}/001/proj",
81新增: "{T0}/001/else/into/y"
82新增: ],
83新增: "Files": null,
84新增: "Stdout": "sub/y\n",
85新增: "Stderr": "",
86新增: "Code": 0
87新增: },
88新增: {
89新增: "Dir": "{ROOT}",
90新增: "Stdin": "",
91新增: "Snippet": "\"$@\"",
92新增: "Env": [
93新增: "HOME={T0}/007"
94新增: ],
95新增: "Args": [
96新增: "_agent_vm_project_rel",
97新增: "{T0}/001/proj",
98新增: "{T0}/001/rellink/z"
99新增: ],
100新增: "Files": null,
101新增: "Stdout": "",
102新增: "Stderr": "",
103新增: "Code": 1
104新增: },
105新增: {
106新增: "Dir": "{ROOT}",
107新增: "Stdin": "",
108新增: "Snippet": "\"$@\"",
109新增: "Env": [
110新增: "HOME={T0}/008"
111新增: ],
112新增: "Args": [
113新增: "_agent_vm_project_rel",
114新增: "{T0}/001/proj",
115新增: "{T0}/001/proj"
116新增: ],
117新增: "Files": null,
118新增: "Stdout": "\n",
119新增: "Stderr": "",
120新增: "Code": 0
121新增: },
122新增: {
123新增: "Dir": "{ROOT}",
124新增: "Stdin": "",
125新增: "Snippet": "\"$@\"",
126新增: "Env": [
127新增: "HOME={T0}/009"
128新增: ],
129新增: "Args": [
130新增: "_agent_vm_project_rel",
131新增: "{T0}/001/proj",
132新增: "{T0}/001/other/x"
133新增: ],
134新增: "Files": null,
135新增: "Stdout": "",
136新增: "Stderr": "",
137新增: "Code": 1
138新增: },
139新增: {
140新增: "Dir": "{ROOT}",
141新增: "Stdin": "",
142新增: "Snippet": "\"$@\"",
143新增: "Env": [
144新增: "HOME={T0}/010"
145新增: ],
146新增: "Args": [
147新增: "_agent_vm_project_rel",
148新增: "{T0}/001/proj",
149新增: "{T0}/001/loop/x"
150新增: ],
151新增: "Files": null,
152新增: "Stdout": "",
153新增: "Stderr": "",
154新增: "Code": 1
155新增: },
156新增: {
157新增: "Dir": "{ROOT}",
158新增: "Stdin": "",
159新增: "Snippet": "\"$@\"",
160新增: "Env": [
161新增: "HOME={T0}/011"
162新增: ],
163新增: "Args": [
164新增: "_agent_vm_project_rel",
165新增: "{T0}/001/proj",
166新增: "/etc/passwd"
167新增: ],
168新增: "Files": null,
169新增: "Stdout": "",
170新增: "Stderr": "",
171新增: "Code": 1
172新增: },
173新增: {
174新增: "Dir": "{ROOT}",
175新增: "Stdin": "",
176新增: "Snippet": "\"$@\"",
177新增: "Env": [
178新增: "HOME={T0}/012"
179新增: ],
180新增: "Args": [
181新增: "_agent_vm_project_rel",
182新增: "{T0}/001/proj",
183新增: "{T0}/001/proj/../proj/x"
184新增: ],
185新增: "Files": null,
186新增: "Stdout": "../proj/x\n",
187新增: "Stderr": "",
188新增: "Code": 0
189新增: },
190新增: {
191新增: "Dir": "{ROOT}",
192新增: "Stdin": "",
193新增: "Snippet": "\"$@\"",
194新增: "Env": [
195新增: "HOME={T0}/013"
196新增: ],
197新增: "Args": [
198新增: "_agent_vm_project_rel",
199新增: "{T0}/001/proj",
200新增: "{T0}/001/elselink/../proj/x"
201新增: ],
202新增: "Files": null,
203新增: "Stdout": "x\n",
204新增: "Stderr": "",
205新增: "Code": 0
206新增: }
207新增: ]
208新增:}
新增internal/env/testdata/bashref/TestReadBash.json+1548 −0看文件
@@ -0,0 +1,1548 @@
1新增:{
2新增: "TestReadBash": [
3新增: {
4新增: "Dir": "{ROOT}",
5新增: "Stdin": "",
6新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
7新增: "Env": [
8新增: "HOME={T0}/001"
9新增: ],
10新增: "Args": [
11新增: "",
12新增: "A"
13新增: ],
14新增: "Files": null,
15新增: "Stdout": "",
16新增: "Stderr": "",
17新增: "Code": 1
18新增: },
19新增: {
20新增: "Dir": "{ROOT}",
21新增: "Stdin": "",
22新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
23新增: "Env": [
24新增: "HOME={T0}/002"
25新增: ],
26新增: "Args": [
27新增: "",
28新增: "B"
29新增: ],
30新增: "Files": null,
31新增: "Stdout": "",
32新增: "Stderr": "",
33新增: "Code": 1
34新增: },
35新增: {
36新增: "Dir": "{ROOT}",
37新增: "Stdin": "",
38新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
39新增: "Env": [
40新增: "HOME={T0}/003"
41新增: ],
42新增: "Args": [
43新增: "",
44新增: "C"
45新增: ],
46新增: "Files": null,
47新增: "Stdout": "",
48新增: "Stderr": "",
49新增: "Code": 1
50新增: },
51新增: {
52新增: "Dir": "{ROOT}",
53新增: "Stdin": "",
54新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
55新增: "Env": [
56新增: "HOME={T0}/004"
57新增: ],
58新增: "Args": [
59新增: "A=1\n",
60新增: "A"
61新增: ],
62新增: "Files": null,
63新增: "Stdout": "1",
64新增: "Stderr": "",
65新增: "Code": 0
66新增: },
67新增: {
68新增: "Dir": "{ROOT}",
69新增: "Stdin": "",
70新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
71新增: "Env": [
72新增: "HOME={T0}/005"
73新增: ],
74新增: "Args": [
75新增: "A=1\n",
76新增: "B"
77新增: ],
78新增: "Files": null,
79新增: "Stdout": "",
80新增: "Stderr": "",
81新增: "Code": 1
82新增: },
83新增: {
84新增: "Dir": "{ROOT}",
85新增: "Stdin": "",
86新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
87新增: "Env": [
88新增: "HOME={T0}/006"
89新增: ],
90新增: "Args": [
91新增: "A=1\n",
92新增: "C"
93新增: ],
94新增: "Files": null,
95新增: "Stdout": "",
96新增: "Stderr": "",
97新增: "Code": 1
98新增: },
99新增: {
100新增: "Dir": "{ROOT}",
101新增: "Stdin": "",
102新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
103新增: "Env": [
104新增: "HOME={T0}/007"
105新增: ],
106新增: "Args": [
107新增: "A=1",
108新增: "A"
109新增: ],
110新增: "Files": null,
111新增: "Stdout": "1",
112新增: "Stderr": "",
113新增: "Code": 0
114新增: },
115新增: {
116新增: "Dir": "{ROOT}",
117新增: "Stdin": "",
118新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
119新增: "Env": [
120新增: "HOME={T0}/008"
121新增: ],
122新增: "Args": [
123新增: "A=1",
124新增: "B"
125新增: ],
126新增: "Files": null,
127新增: "Stdout": "",
128新增: "Stderr": "",
129新增: "Code": 1
130新增: },
131新增: {
132新增: "Dir": "{ROOT}",
133新增: "Stdin": "",
134新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
135新增: "Env": [
136新增: "HOME={T0}/009"
137新增: ],
138新增: "Args": [
139新增: "A=1",
140新增: "C"
141新增: ],
142新增: "Files": null,
143新增: "Stdout": "",
144新增: "Stderr": "",
145新增: "Code": 1
146新增: },
147新增: {
148新增: "Dir": "{ROOT}",
149新增: "Stdin": "",
150新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
151新增: "Env": [
152新增: "HOME={T0}/010"
153新增: ],
154新增: "Args": [
155新增: "export A=1\nB=2\n",
156新增: "A"
157新增: ],
158新增: "Files": null,
159新增: "Stdout": "1",
160新增: "Stderr": "",
161新增: "Code": 0
162新增: },
163新增: {
164新增: "Dir": "{ROOT}",
165新增: "Stdin": "",
166新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
167新增: "Env": [
168新增: "HOME={T0}/011"
169新增: ],
170新增: "Args": [
171新增: "export A=1\nB=2\n",
172新增: "B"
173新增: ],
174新增: "Files": null,
175新增: "Stdout": "2",
176新增: "Stderr": "",
177新增: "Code": 0
178新增: },
179新增: {
180新增: "Dir": "{ROOT}",
181新增: "Stdin": "",
182新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
183新增: "Env": [
184新增: "HOME={T0}/012"
185新增: ],
186新增: "Args": [
187新增: "export A=1\nB=2\n",
188新增: "C"
189新增: ],
190新增: "Files": null,
191新增: "Stdout": "",
192新增: "Stderr": "",
193新增: "Code": 1
194新增: },
195新增: {
196新增: "Dir": "{ROOT}",
197新增: "Stdin": "",
198新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
199新增: "Env": [
200新增: "HOME={T0}/013"
201新增: ],
202新增: "Args": [
203新增: " export A='x y'\n",
204新增: "A"
205新增: ],
206新增: "Files": null,
207新增: "Stdout": "x y",
208新增: "Stderr": "",
209新增: "Code": 0
210新增: },
211新增: {
212新增: "Dir": "{ROOT}",
213新增: "Stdin": "",
214新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
215新增: "Env": [
216新增: "HOME={T0}/014"
217新增: ],
218新增: "Args": [
219新增: " export A='x y'\n",
220新增: "B"
221新增: ],
222新增: "Files": null,
223新增: "Stdout": "",
224新增: "Stderr": "",
225新增: "Code": 1
226新增: },
227新增: {
228新增: "Dir": "{ROOT}",
229新增: "Stdin": "",
230新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
231新增: "Env": [
232新增: "HOME={T0}/015"
233新增: ],
234新增: "Args": [
235新增: " export A='x y'\n",
236新增: "C"
237新增: ],
238新增: "Files": null,
239新增: "Stdout": "",
240新增: "Stderr": "",
241新增: "Code": 1
242新增: },
243新增: {
244新增: "Dir": "{ROOT}",
245新增: "Stdin": "",
246新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
247新增: "Env": [
248新增: "HOME={T0}/016"
249新增: ],
250新增: "Args": [
251新增: "A='multi\nline\nB=inside'\nB=2\n",
252新增: "A"
253新增: ],
254新增: "Files": null,
255新增: "Stdout": "multi\nline\nB=inside",
256新增: "Stderr": "",
257新增: "Code": 0
258新增: },
259新增: {
260新增: "Dir": "{ROOT}",
261新增: "Stdin": "",
262新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
263新增: "Env": [
264新增: "HOME={T0}/017"
265新增: ],
266新增: "Args": [
267新增: "A='multi\nline\nB=inside'\nB=2\n",
268新增: "B"
269新增: ],
270新增: "Files": null,
271新增: "Stdout": "2",
272新增: "Stderr": "",
273新增: "Code": 0
274新增: },
275新增: {
276新增: "Dir": "{ROOT}",
277新增: "Stdin": "",
278新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
279新增: "Env": [
280新增: "HOME={T0}/018"
281新增: ],
282新增: "Args": [
283新增: "A='multi\nline\nB=inside'\nB=2\n",
284新增: "C"
285新增: ],
286新增: "Files": null,
287新增: "Stdout": "",
288新增: "Stderr": "",
289新增: "Code": 1
290新增: },
291新增: {
292新增: "Dir": "{ROOT}",
293新增: "Stdin": "",
294新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
295新增: "Env": [
296新增: "HOME={T0}/019"
297新增: ],
298新增: "Args": [
299新增: "A='open\nB=2\n",
300新增: "A"
301新增: ],
302新增: "Files": null,
303新增: "Stdout": "",
304新增: "Stderr": "",
305新增: "Code": 3
306新增: },
307新增: {
308新增: "Dir": "{ROOT}",
309新增: "Stdin": "",
310新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
311新增: "Env": [
312新增: "HOME={T0}/020"
313新增: ],
314新增: "Args": [
315新增: "A='open\nB=2\n",
316新增: "B"
317新增: ],
318新增: "Files": null,
319新增: "Stdout": "",
320新增: "Stderr": "",
321新增: "Code": 3
322新增: },
323新增: {
324新增: "Dir": "{ROOT}",
325新增: "Stdin": "",
326新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
327新增: "Env": [
328新增: "HOME={T0}/021"
329新增: ],
330新增: "Args": [
331新增: "A='open\nB=2\n",
332新增: "C"
333新增: ],
334新增: "Files": null,
335新增: "Stdout": "",
336新增: "Stderr": "",
337新增: "Code": 3
338新增: },
339新增: {
340新增: "Dir": "{ROOT}",
341新增: "Stdin": "",
342新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
343新增: "Env": [
344新增: "HOME={T0}/022"
345新增: ],
346新增: "Args": [
347新增: "A=\"plain\"\nB=\"$HOME\"\n",
348新增: "A"
349新增: ],
350新增: "Files": null,
351新增: "Stdout": "",
352新增: "Stderr": "",
353新增: "Code": 3
354新增: },
355新增: {
356新增: "Dir": "{ROOT}",
357新增: "Stdin": "",
358新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
359新增: "Env": [
360新增: "HOME={T0}/023"
361新增: ],
362新增: "Args": [
363新增: "A=\"plain\"\nB=\"$HOME\"\n",
364新增: "B"
365新增: ],
366新增: "Files": null,
367新增: "Stdout": "",
368新增: "Stderr": "",
369新增: "Code": 3
370新增: },
371新增: {
372新增: "Dir": "{ROOT}",
373新增: "Stdin": "",
374新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
375新增: "Env": [
376新增: "HOME={T0}/024"
377新增: ],
378新增: "Args": [
379新增: "A=\"plain\"\nB=\"$HOME\"\n",
380新增: "C"
381新增: ],
382新增: "Files": null,
383新增: "Stdout": "",
384新增: "Stderr": "",
385新增: "Code": 3
386新增: },
387新增: {
388新增: "Dir": "{ROOT}",
389新增: "Stdin": "",
390新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
391新增: "Env": [
392新增: "HOME={T0}/025"
393新增: ],
394新增: "Args": [
395新增: "A=x # comment\nB=y#notcomment\n",
396新增: "A"
397新增: ],
398新增: "Files": null,
399新增: "Stdout": "x",
400新增: "Stderr": "",
401新增: "Code": 0
402新增: },
403新增: {
404新增: "Dir": "{ROOT}",
405新增: "Stdin": "",
406新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
407新增: "Env": [
408新增: "HOME={T0}/026"
409新增: ],
410新增: "Args": [
411新增: "A=x # comment\nB=y#notcomment\n",
412新增: "B"
413新增: ],
414新增: "Files": null,
415新增: "Stdout": "y#notcomment",
416新增: "Stderr": "",
417新增: "Code": 0
418新增: },
419新增: {
420新增: "Dir": "{ROOT}",
421新增: "Stdin": "",
422新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
423新增: "Env": [
424新增: "HOME={T0}/027"
425新增: ],
426新增: "Args": [
427新增: "A=x # comment\nB=y#notcomment\n",
428新增: "C"
429新增: ],
430新增: "Files": null,
431新增: "Stdout": "",
432新增: "Stderr": "",
433新增: "Code": 1
434新增: },
435新增: {
436新增: "Dir": "{ROOT}",
437新增: "Stdin": "",
438新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
439新增: "Env": [
440新增: "HOME={T0}/028"
441新增: ],
442新增: "Args": [
443新增: "A=x;rm -rf /\n",
444新增: "A"
445新增: ],
446新增: "Files": null,
447新增: "Stdout": "",
448新增: "Stderr": "",
449新增: "Code": 3
450新增: },
451新增: {
452新增: "Dir": "{ROOT}",
453新增: "Stdin": "",
454新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
455新增: "Env": [
456新增: "HOME={T0}/029"
457新增: ],
458新增: "Args": [
459新增: "A=x;rm -rf /\n",
460新增: "B"
461新增: ],
462新增: "Files": null,
463新增: "Stdout": "",
464新增: "Stderr": "",
465新增: "Code": 3
466新增: },
467新增: {
468新增: "Dir": "{ROOT}",
469新增: "Stdin": "",
470新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
471新增: "Env": [
472新增: "HOME={T0}/030"
473新增: ],
474新增: "Args": [
475新增: "A=x;rm -rf /\n",
476新增: "C"
477新增: ],
478新增: "Files": null,
479新增: "Stdout": "",
480新增: "Stderr": "",
481新增: "Code": 3
482新增: },
483新增: {
484新增: "Dir": "{ROOT}",
485新增: "Stdin": "",
486新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
487新增: "Env": [
488新增: "HOME={T0}/031"
489新增: ],
490新增: "Args": [
491新增: "A=$(id)\n",
492新增: "A"
493新增: ],
494新增: "Files": null,
495新增: "Stdout": "",
496新增: "Stderr": "",
497新增: "Code": 3
498新增: },
499新增: {
500新增: "Dir": "{ROOT}",
501新增: "Stdin": "",
502新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
503新增: "Env": [
504新增: "HOME={T0}/032"
505新增: ],
506新增: "Args": [
507新增: "A=$(id)\n",
508新增: "B"
509新增: ],
510新增: "Files": null,
511新增: "Stdout": "",
512新增: "Stderr": "",
513新增: "Code": 3
514新增: },
515新增: {
516新增: "Dir": "{ROOT}",
517新增: "Stdin": "",
518新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
519新增: "Env": [
520新增: "HOME={T0}/033"
521新增: ],
522新增: "Args": [
523新增: "A=$(id)\n",
524新增: "C"
525新增: ],
526新增: "Files": null,
527新增: "Stdout": "",
528新增: "Stderr": "",
529新增: "Code": 3
530新增: },
531新增: {
532新增: "Dir": "{ROOT}",
533新增: "Stdin": "",
534新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
535新增: "Env": [
536新增: "HOME={T0}/034"
537新增: ],
538新增: "Args": [
539新增: "A=$HOME\n",
540新增: "A"
541新增: ],
542新增: "Files": null,
543新增: "Stdout": "",
544新增: "Stderr": "",
545新增: "Code": 3
546新增: },
547新增: {
548新增: "Dir": "{ROOT}",
549新增: "Stdin": "",
550新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
551新增: "Env": [
552新增: "HOME={T0}/035"
553新增: ],
554新增: "Args": [
555新增: "A=$HOME\n",
556新增: "B"
557新增: ],
558新增: "Files": null,
559新增: "Stdout": "",
560新增: "Stderr": "",
561新增: "Code": 3
562新增: },
563新增: {
564新增: "Dir": "{ROOT}",
565新增: "Stdin": "",
566新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
567新增: "Env": [
568新增: "HOME={T0}/036"
569新增: ],
570新增: "Args": [
571新增: "A=$HOME\n",
572新增: "C"
573新增: ],
574新增: "Files": null,
575新增: "Stdout": "",
576新增: "Stderr": "",
577新增: "Code": 3
578新增: },
579新增: {
580新增: "Dir": "{ROOT}",
581新增: "Stdin": "",
582新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
583新增: "Env": [
584新增: "HOME={T0}/037"
585新增: ],
586新增: "Args": [
587新增: "B=1\nA=x$y\n",
588新增: "A"
589新增: ],
590新增: "Files": null,
591新增: "Stdout": "",
592新增: "Stderr": "",
593新增: "Code": 3
594新增: },
595新增: {
596新增: "Dir": "{ROOT}",
597新增: "Stdin": "",
598新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
599新增: "Env": [
600新增: "HOME={T0}/038"
601新增: ],
602新增: "Args": [
603新增: "B=1\nA=x$y\n",
604新增: "B"
605新增: ],
606新增: "Files": null,
607新增: "Stdout": "",
608新增: "Stderr": "",
609新增: "Code": 3
610新增: },
611新增: {
612新增: "Dir": "{ROOT}",
613新增: "Stdin": "",
614新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
615新增: "Env": [
616新增: "HOME={T0}/039"
617新增: ],
618新增: "Args": [
619新增: "B=1\nA=x$y\n",
620新增: "C"
621新增: ],
622新增: "Files": null,
623新增: "Stdout": "",
624新增: "Stderr": "",
625新增: "Code": 3
626新增: },
627新增: {
628新增: "Dir": "{ROOT}",
629新增: "Stdin": "",
630新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
631新增: "Env": [
632新增: "HOME={T0}/040"
633新增: ],
634新增: "Args": [
635新增: "A=~/x\n",
636新增: "A"
637新增: ],
638新增: "Files": null,
639新增: "Stdout": "",
640新增: "Stderr": "",
641新增: "Code": 3
642新增: },
643新增: {
644新增: "Dir": "{ROOT}",
645新增: "Stdin": "",
646新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
647新增: "Env": [
648新增: "HOME={T0}/041"
649新增: ],
650新增: "Args": [
651新增: "A=~/x\n",
652新增: "B"
653新增: ],
654新增: "Files": null,
655新增: "Stdout": "",
656新增: "Stderr": "",
657新增: "Code": 3
658新增: },
659新增: {
660新增: "Dir": "{ROOT}",
661新增: "Stdin": "",
662新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
663新增: "Env": [
664新增: "HOME={T0}/042"
665新增: ],
666新增: "Args": [
667新增: "A=~/x\n",
668新增: "C"
669新增: ],
670新增: "Files": null,
671新增: "Stdout": "",
672新增: "Stderr": "",
673新增: "Code": 3
674新增: },
675新增: {
676新增: "Dir": "{ROOT}",
677新增: "Stdin": "",
678新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
679新增: "Env": [
680新增: "HOME={T0}/043"
681新增: ],
682新增: "Args": [
683新增: "# just a comment\n\n \nA=1\r\nB='crlf'\r\n",
684新增: "A"
685新增: ],
686新增: "Files": null,
687新增: "Stdout": "1",
688新增: "Stderr": "",
689新增: "Code": 0
690新增: },
691新增: {
692新增: "Dir": "{ROOT}",
693新增: "Stdin": "",
694新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
695新增: "Env": [
696新增: "HOME={T0}/044"
697新增: ],
698新增: "Args": [
699新增: "# just a comment\n\n \nA=1\r\nB='crlf'\r\n",
700新增: "B"
701新增: ],
702新增: "Files": null,
703新增: "Stdout": "crlf",
704新增: "Stderr": "",
705新增: "Code": 0
706新增: },
707新增: {
708新增: "Dir": "{ROOT}",
709新增: "Stdin": "",
710新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
711新增: "Env": [
712新增: "HOME={T0}/045"
713新增: ],
714新增: "Args": [
715新增: "# just a comment\n\n \nA=1\r\nB='crlf'\r\n",
716新增: "C"
717新增: ],
718新增: "Files": null,
719新增: "Stdout": "",
720新增: "Stderr": "",
721新增: "Code": 1
722新增: },
723新增: {
724新增: "Dir": "{ROOT}",
725新增: "Stdin": "",
726新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
727新增: "Env": [
728新增: "HOME={T0}/046"
729新增: ],
730新增: "Args": [
731新增: "A=1\nA=2\n",
732新增: "A"
733新增: ],
734新增: "Files": null,
735新增: "Stdout": "2",
736新增: "Stderr": "",
737新增: "Code": 0
738新增: },
739新增: {
740新增: "Dir": "{ROOT}",
741新增: "Stdin": "",
742新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
743新增: "Env": [
744新增: "HOME={T0}/047"
745新增: ],
746新增: "Args": [
747新增: "A=1\nA=2\n",
748新增: "B"
749新增: ],
750新增: "Files": null,
751新增: "Stdout": "",
752新增: "Stderr": "",
753新增: "Code": 1
754新增: },
755新增: {
756新增: "Dir": "{ROOT}",
757新增: "Stdin": "",
758新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
759新增: "Env": [
760新增: "HOME={T0}/048"
761新增: ],
762新增: "Args": [
763新增: "A=1\nA=2\n",
764新增: "C"
765新增: ],
766新增: "Files": null,
767新增: "Stdout": "",
768新增: "Stderr": "",
769新增: "Code": 1
770新增: },
771新增: {
772新增: "Dir": "{ROOT}",
773新增: "Stdin": "",
774新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
775新增: "Env": [
776新增: "HOME={T0}/049"
777新增: ],
778新增: "Args": [
779新增: "A='it'\"'\"'s'\n",
780新增: "A"
781新增: ],
782新增: "Files": null,
783新增: "Stdout": "it's",
784新增: "Stderr": "",
785新增: "Code": 0
786新增: },
787新增: {
788新增: "Dir": "{ROOT}",
789新增: "Stdin": "",
790新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
791新增: "Env": [
792新增: "HOME={T0}/050"
793新增: ],
794新增: "Args": [
795新增: "A='it'\"'\"'s'\n",
796新增: "B"
797新增: ],
798新增: "Files": null,
799新增: "Stdout": "",
800新增: "Stderr": "",
801新增: "Code": 1
802新增: },
803新增: {
804新增: "Dir": "{ROOT}",
805新增: "Stdin": "",
806新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
807新增: "Env": [
808新增: "HOME={T0}/051"
809新增: ],
810新增: "Args": [
811新增: "A='it'\"'\"'s'\n",
812新增: "C"
813新增: ],
814新增: "Files": null,
815新增: "Stdout": "",
816新增: "Stderr": "",
817新增: "Code": 1
818新增: },
819新增: {
820新增: "Dir": "{ROOT}",
821新增: "Stdin": "",
822新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
823新增: "Env": [
824新增: "HOME={T0}/052"
825新增: ],
826新增: "Args": [
827新增: "not an assignment\nA=1\n",
828新增: "A"
829新增: ],
830新增: "Files": null,
831新增: "Stdout": "",
832新增: "Stderr": "",
833新增: "Code": 3
834新增: },
835新增: {
836新增: "Dir": "{ROOT}",
837新增: "Stdin": "",
838新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
839新增: "Env": [
840新增: "HOME={T0}/053"
841新增: ],
842新增: "Args": [
843新增: "not an assignment\nA=1\n",
844新增: "B"
845新增: ],
846新增: "Files": null,
847新增: "Stdout": "",
848新增: "Stderr": "",
849新增: "Code": 3
850新增: },
851新增: {
852新增: "Dir": "{ROOT}",
853新增: "Stdin": "",
854新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
855新增: "Env": [
856新增: "HOME={T0}/054"
857新增: ],
858新增: "Args": [
859新增: "not an assignment\nA=1\n",
860新增: "C"
861新增: ],
862新增: "Files": null,
863新增: "Stdout": "",
864新增: "Stderr": "",
865新增: "Code": 3
866新增: },
867新增: {
868新增: "Dir": "{ROOT}",
869新增: "Stdin": "",
870新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
871新增: "Env": [
872新增: "HOME={T0}/055"
873新增: ],
874新增: "Args": [
875新增: "A=x\\\ny\n",
876新增: "A"
877新增: ],
878新增: "Files": null,
879新增: "Stdout": "",
880新增: "Stderr": "",
881新增: "Code": 3
882新增: },
883新增: {
884新增: "Dir": "{ROOT}",
885新增: "Stdin": "",
886新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
887新增: "Env": [
888新增: "HOME={T0}/056"
889新增: ],
890新增: "Args": [
891新增: "A=x\\\ny\n",
892新增: "B"
893新增: ],
894新增: "Files": null,
895新增: "Stdout": "",
896新增: "Stderr": "",
897新增: "Code": 3
898新增: },
899新增: {
900新增: "Dir": "{ROOT}",
901新增: "Stdin": "",
902新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
903新增: "Env": [
904新增: "HOME={T0}/057"
905新增: ],
906新增: "Args": [
907新增: "A=x\\\ny\n",
908新增: "C"
909新增: ],
910新增: "Files": null,
911新增: "Stdout": "",
912新增: "Stderr": "",
913新增: "Code": 3
914新增: },
915新增: {
916新增: "Dir": "{ROOT}",
917新增: "Stdin": "",
918新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
919新增: "Env": [
920新增: "HOME={T0}/058"
921新增: ],
922新增: "Args": [
923新增: "A= 1\n",
924新增: "A"
925新增: ],
926新增: "Files": null,
927新增: "Stdout": "",
928新增: "Stderr": "",
929新增: "Code": 3
930新增: },
931新增: {
932新增: "Dir": "{ROOT}",
933新增: "Stdin": "",
934新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
935新增: "Env": [
936新增: "HOME={T0}/059"
937新增: ],
938新增: "Args": [
939新增: "A= 1\n",
940新增: "B"
941新增: ],
942新增: "Files": null,
943新增: "Stdout": "",
944新增: "Stderr": "",
945新增: "Code": 3
946新增: },
947新增: {
948新增: "Dir": "{ROOT}",
949新增: "Stdin": "",
950新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
951新增: "Env": [
952新增: "HOME={T0}/060"
953新增: ],
954新增: "Args": [
955新增: "A= 1\n",
956新增: "C"
957新增: ],
958新增: "Files": null,
959新增: "Stdout": "",
960新增: "Stderr": "",
961新增: "Code": 3
962新增: },
963新增: {
964新增: "Dir": "{ROOT}",
965新增: "Stdin": "",
966新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
967新增: "Env": [
968新增: "HOME={T0}/061"
969新增: ],
970新增: "Args": [
971新增: "A=\tB\n",
972新增: "A"
973新增: ],
974新增: "Files": null,
975新增: "Stdout": "",
976新增: "Stderr": "",
977新增: "Code": 3
978新增: },
979新增: {
980新增: "Dir": "{ROOT}",
981新增: "Stdin": "",
982新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
983新增: "Env": [
984新增: "HOME={T0}/062"
985新增: ],
986新增: "Args": [
987新增: "A=\tB\n",
988新增: "B"
989新增: ],
990新增: "Files": null,
991新增: "Stdout": "",
992新增: "Stderr": "",
993新增: "Code": 3
994新增: },
995新增: {
996新增: "Dir": "{ROOT}",
997新增: "Stdin": "",
998新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
999新增: "Env": [
1000新增: "HOME={T0}/063"
1001新增: ],
1002新增: "Args": [
1003新增: "A=\tB\n",
1004新增: "C"
1005新增: ],
1006新增: "Files": null,
1007新增: "Stdout": "",
1008新增: "Stderr": "",
1009新增: "Code": 3
1010新增: },
1011新增: {
1012新增: "Dir": "{ROOT}",
1013新增: "Stdin": "",
1014新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1015新增: "Env": [
1016新增: "HOME={T0}/064"
1017新增: ],
1018新增: "Args": [
1019新增: "1A=x\n",
1020新增: "A"
1021新增: ],
1022新增: "Files": null,
1023新增: "Stdout": "",
1024新增: "Stderr": "",
1025新增: "Code": 3
1026新增: },
1027新增: {
1028新增: "Dir": "{ROOT}",
1029新增: "Stdin": "",
1030新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1031新增: "Env": [
1032新增: "HOME={T0}/065"
1033新增: ],
1034新增: "Args": [
1035新增: "1A=x\n",
1036新增: "B"
1037新增: ],
1038新增: "Files": null,
1039新增: "Stdout": "",
1040新增: "Stderr": "",
1041新增: "Code": 3
1042新增: },
1043新增: {
1044新增: "Dir": "{ROOT}",
1045新增: "Stdin": "",
1046新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1047新增: "Env": [
1048新增: "HOME={T0}/066"
1049新增: ],
1050新增: "Args": [
1051新增: "1A=x\n",
1052新增: "C"
1053新增: ],
1054新增: "Files": null,
1055新增: "Stdout": "",
1056新增: "Stderr": "",
1057新增: "Code": 3
1058新增: },
1059新增: {
1060新增: "Dir": "{ROOT}",
1061新增: "Stdin": "",
1062新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1063新增: "Env": [
1064新增: "HOME={T0}/067"
1065新增: ],
1066新增: "Args": [
1067新增: "A=x y\n",
1068新增: "A"
1069新增: ],
1070新增: "Files": null,
1071新增: "Stdout": "",
1072新增: "Stderr": "",
1073新增: "Code": 3
1074新增: },
1075新增: {
1076新增: "Dir": "{ROOT}",
1077新增: "Stdin": "",
1078新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1079新增: "Env": [
1080新增: "HOME={T0}/068"
1081新增: ],
1082新增: "Args": [
1083新增: "A=x y\n",
1084新增: "B"
1085新增: ],
1086新增: "Files": null,
1087新增: "Stdout": "",
1088新增: "Stderr": "",
1089新增: "Code": 3
1090新增: },
1091新增: {
1092新增: "Dir": "{ROOT}",
1093新增: "Stdin": "",
1094新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1095新增: "Env": [
1096新增: "HOME={T0}/069"
1097新增: ],
1098新增: "Args": [
1099新增: "A=x y\n",
1100新增: "C"
1101新增: ],
1102新增: "Files": null,
1103新增: "Stdout": "",
1104新增: "Stderr": "",
1105新增: "Code": 3
1106新增: },
1107新增: {
1108新增: "Dir": "{ROOT}",
1109新增: "Stdin": "",
1110新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1111新增: "Env": [
1112新增: "HOME={T0}/070"
1113新增: ],
1114新增: "Args": [
1115新增: "A='x' # c\n",
1116新增: "A"
1117新增: ],
1118新增: "Files": null,
1119新增: "Stdout": "x",
1120新增: "Stderr": "",
1121新增: "Code": 0
1122新增: },
1123新增: {
1124新增: "Dir": "{ROOT}",
1125新增: "Stdin": "",
1126新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1127新增: "Env": [
1128新增: "HOME={T0}/071"
1129新增: ],
1130新增: "Args": [
1131新增: "A='x' # c\n",
1132新增: "B"
1133新增: ],
1134新增: "Files": null,
1135新增: "Stdout": "",
1136新增: "Stderr": "",
1137新增: "Code": 1
1138新增: },
1139新增: {
1140新增: "Dir": "{ROOT}",
1141新增: "Stdin": "",
1142新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1143新增: "Env": [
1144新增: "HOME={T0}/072"
1145新增: ],
1146新增: "Args": [
1147新增: "A='x' # c\n",
1148新增: "C"
1149新增: ],
1150新增: "Files": null,
1151新增: "Stdout": "",
1152新增: "Stderr": "",
1153新增: "Code": 1
1154新增: },
1155新增: {
1156新增: "Dir": "{ROOT}",
1157新增: "Stdin": "",
1158新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1159新增: "Env": [
1160新增: "HOME={T0}/073"
1161新增: ],
1162新增: "Args": [
1163新增: "A=$'esc\\'aped'\nB=after\n",
1164新增: "A"
1165新增: ],
1166新增: "Files": null,
1167新增: "Stdout": "",
1168新增: "Stderr": "",
1169新增: "Code": 3
1170新增: },
1171新增: {
1172新增: "Dir": "{ROOT}",
1173新增: "Stdin": "",
1174新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1175新增: "Env": [
1176新增: "HOME={T0}/074"
1177新增: ],
1178新增: "Args": [
1179新增: "A=$'esc\\'aped'\nB=after\n",
1180新增: "B"
1181新增: ],
1182新增: "Files": null,
1183新增: "Stdout": "",
1184新增: "Stderr": "",
1185新增: "Code": 3
1186新增: },
1187新增: {
1188新增: "Dir": "{ROOT}",
1189新增: "Stdin": "",
1190新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1191新增: "Env": [
1192新增: "HOME={T0}/075"
1193新增: ],
1194新增: "Args": [
1195新增: "A=$'esc\\'aped'\nB=after\n",
1196新增: "C"
1197新增: ],
1198新增: "Files": null,
1199新增: "Stdout": "",
1200新增: "Stderr": "",
1201新增: "Code": 3
1202新增: },
1203新增: {
1204新增: "Dir": "{ROOT}",
1205新增: "Stdin": "",
1206新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1207新增: "Env": [
1208新增: "HOME={T0}/076"
1209新增: ],
1210新增: "Args": [
1211新增: "A=\"dq \\\" esc\"\nB=after\n",
1212新增: "A"
1213新增: ],
1214新增: "Files": null,
1215新增: "Stdout": "",
1216新增: "Stderr": "",
1217新增: "Code": 3
1218新增: },
1219新增: {
1220新增: "Dir": "{ROOT}",
1221新增: "Stdin": "",
1222新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1223新增: "Env": [
1224新增: "HOME={T0}/077"
1225新增: ],
1226新增: "Args": [
1227新增: "A=\"dq \\\" esc\"\nB=after\n",
1228新增: "B"
1229新增: ],
1230新增: "Files": null,
1231新增: "Stdout": "",
1232新增: "Stderr": "",
1233新增: "Code": 3
1234新增: },
1235新增: {
1236新增: "Dir": "{ROOT}",
1237新增: "Stdin": "",
1238新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1239新增: "Env": [
1240新增: "HOME={T0}/078"
1241新增: ],
1242新增: "Args": [
1243新增: "A=\"dq \\\" esc\"\nB=after\n",
1244新增: "C"
1245新增: ],
1246新增: "Files": null,
1247新增: "Stdout": "",
1248新增: "Stderr": "",
1249新增: "Code": 3
1250新增: },
1251新增: {
1252新增: "Dir": "{ROOT}",
1253新增: "Stdin": "",
1254新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1255新增: "Env": [
1256新增: "HOME={T0}/079"
1257新增: ],
1258新增: "Args": [
1259新增: "A='a'\"b\"c\n",
1260新增: "A"
1261新增: ],
1262新增: "Files": null,
1263新增: "Stdout": "abc",
1264新增: "Stderr": "",
1265新增: "Code": 0
1266新增: },
1267新增: {
1268新增: "Dir": "{ROOT}",
1269新增: "Stdin": "",
1270新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1271新增: "Env": [
1272新增: "HOME={T0}/080"
1273新增: ],
1274新增: "Args": [
1275新增: "A='a'\"b\"c\n",
1276新增: "B"
1277新增: ],
1278新增: "Files": null,
1279新增: "Stdout": "",
1280新增: "Stderr": "",
1281新增: "Code": 1
1282新增: },
1283新增: {
1284新增: "Dir": "{ROOT}",
1285新增: "Stdin": "",
1286新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1287新增: "Env": [
1288新增: "HOME={T0}/081"
1289新增: ],
1290新增: "Args": [
1291新增: "A='a'\"b\"c\n",
1292新增: "C"
1293新增: ],
1294新增: "Files": null,
1295新增: "Stdout": "",
1296新增: "Stderr": "",
1297新增: "Code": 1
1298新增: },
1299新增: {
1300新增: "Dir": "{ROOT}",
1301新增: "Stdin": "",
1302新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1303新增: "Env": [
1304新增: "HOME={T0}/082"
1305新增: ],
1306新增: "Args": [
1307新增: "export\tA=1\nexport B\n",
1308新增: "A"
1309新增: ],
1310新增: "Files": null,
1311新增: "Stdout": "",
1312新增: "Stderr": "",
1313新增: "Code": 3
1314新增: },
1315新增: {
1316新增: "Dir": "{ROOT}",
1317新增: "Stdin": "",
1318新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1319新增: "Env": [
1320新增: "HOME={T0}/083"
1321新增: ],
1322新增: "Args": [
1323新增: "export\tA=1\nexport B\n",
1324新增: "B"
1325新增: ],
1326新增: "Files": null,
1327新增: "Stdout": "",
1328新增: "Stderr": "",
1329新增: "Code": 3
1330新增: },
1331新增: {
1332新增: "Dir": "{ROOT}",
1333新增: "Stdin": "",
1334新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1335新增: "Env": [
1336新增: "HOME={T0}/084"
1337新增: ],
1338新增: "Args": [
1339新增: "export\tA=1\nexport B\n",
1340新增: "C"
1341新增: ],
1342新增: "Files": null,
1343新增: "Stdout": "",
1344新增: "Stderr": "",
1345新增: "Code": 3
1346新增: },
1347新增: {
1348新增: "Dir": "{ROOT}",
1349新增: "Stdin": "",
1350新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1351新增: "Env": [
1352新增: "HOME={T0}/085"
1353新增: ],
1354新增: "Args": [
1355新增: "A=x # ' not a quote\nB=1\n",
1356新增: "A"
1357新增: ],
1358新增: "Files": null,
1359新增: "Stdout": "x",
1360新增: "Stderr": "",
1361新增: "Code": 0
1362新增: },
1363新增: {
1364新增: "Dir": "{ROOT}",
1365新增: "Stdin": "",
1366新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1367新增: "Env": [
1368新增: "HOME={T0}/086"
1369新增: ],
1370新增: "Args": [
1371新增: "A=x # ' not a quote\nB=1\n",
1372新增: "B"
1373新增: ],
1374新增: "Files": null,
1375新增: "Stdout": "1",
1376新增: "Stderr": "",
1377新增: "Code": 0
1378新增: },
1379新增: {
1380新增: "Dir": "{ROOT}",
1381新增: "Stdin": "",
1382新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1383新增: "Env": [
1384新增: "HOME={T0}/087"
1385新增: ],
1386新增: "Args": [
1387新增: "A=x # ' not a quote\nB=1\n",
1388新增: "C"
1389新增: ],
1390新增: "Files": null,
1391新增: "Stdout": "",
1392新增: "Stderr": "",
1393新增: "Code": 1
1394新增: },
1395新增: {
1396新增: "Dir": "{ROOT}",
1397新增: "Stdin": "",
1398新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1399新增: "Env": [
1400新增: "HOME={T0}/088"
1401新增: ],
1402新增: "Args": [
1403新增: "A='x # not a comment'\nB=1\n",
1404新增: "A"
1405新增: ],
1406新增: "Files": null,
1407新增: "Stdout": "x # not a comment",
1408新增: "Stderr": "",
1409新增: "Code": 0
1410新增: },
1411新增: {
1412新增: "Dir": "{ROOT}",
1413新增: "Stdin": "",
1414新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1415新增: "Env": [
1416新增: "HOME={T0}/089"
1417新增: ],
1418新增: "Args": [
1419新增: "A='x # not a comment'\nB=1\n",
1420新增: "B"
1421新增: ],
1422新增: "Files": null,
1423新增: "Stdout": "1",
1424新增: "Stderr": "",
1425新增: "Code": 0
1426新增: },
1427新增: {
1428新增: "Dir": "{ROOT}",
1429新增: "Stdin": "",
1430新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1431新增: "Env": [
1432新增: "HOME={T0}/090"
1433新增: ],
1434新增: "Args": [
1435新增: "A='x # not a comment'\nB=1\n",
1436新增: "C"
1437新增: ],
1438新增: "Files": null,
1439新增: "Stdout": "",
1440新增: "Stderr": "",
1441新增: "Code": 1
1442新增: },
1443新增: {
1444新增: "Dir": "{ROOT}",
1445新增: "Stdin": "",
1446新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1447新增: "Env": [
1448新增: "HOME={T0}/091"
1449新增: ],
1450新增: "Args": [
1451新增: "A=café\nB='naïve'\n",
1452新增: "A"
1453新增: ],
1454新增: "Files": null,
1455新增: "Stdout": "café",
1456新增: "Stderr": "",
1457新增: "Code": 0
1458新增: },
1459新增: {
1460新增: "Dir": "{ROOT}",
1461新增: "Stdin": "",
1462新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1463新增: "Env": [
1464新增: "HOME={T0}/092"
1465新增: ],
1466新增: "Args": [
1467新增: "A=café\nB='naïve'\n",
1468新增: "B"
1469新增: ],
1470新增: "Files": null,
1471新增: "Stdout": "naïve",
1472新增: "Stderr": "",
1473新增: "Code": 0
1474新增: },
1475新增: {
1476新增: "Dir": "{ROOT}",
1477新增: "Stdin": "",
1478新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1479新增: "Env": [
1480新增: "HOME={T0}/093"
1481新增: ],
1482新增: "Args": [
1483新增: "A=café\nB='naïve'\n",
1484新增: "C"
1485新增: ],
1486新增: "Files": null,
1487新增: "Stdout": "",
1488新增: "Stderr": "",
1489新增: "Code": 1
1490新增: },
1491新增: {
1492新增: "Dir": "{ROOT}",
1493新增: "Stdin": "",
1494新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1495新增: "Env": [
1496新增: "HOME={T0}/094"
1497新增: ],
1498新增: "Args": [
1499新增: {
1500新增: "base64": "QT2S/wo="
1501新增: },
1502新增: "A"
1503新增: ],
1504新增: "Files": null,
1505新增: "Stdout": {
1506新增: "base64": "kv8="
1507新增: },
1508新增: "Stderr": "",
1509新增: "Code": 0
1510新增: },
1511新增: {
1512新增: "Dir": "{ROOT}",
1513新增: "Stdin": "",
1514新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1515新增: "Env": [
1516新增: "HOME={T0}/095"
1517新增: ],
1518新增: "Args": [
1519新增: {
1520新增: "base64": "QT2S/wo="
1521新增: },
1522新增: "B"
1523新增: ],
1524新增: "Files": null,
1525新增: "Stdout": "",
1526新增: "Stderr": "",
1527新增: "Code": 1
1528新增: },
1529新增: {
1530新增: "Dir": "{ROOT}",
1531新增: "Stdin": "",
1532新增: "Snippet": "printf '%s' \"$1\" | _agent_vm_env_read - \"$2\"",
1533新增: "Env": [
1534新增: "HOME={T0}/096"
1535新增: ],
1536新增: "Args": [
1537新增: {
1538新增: "base64": "QT2S/wo="
1539新增: },
1540新增: "C"
1541新增: ],
1542新增: "Files": null,
1543新增: "Stdout": "",
1544新增: "Stderr": "",
1545新增: "Code": 1
1546新增: }
1547新增: ]
1548新增:}
新增internal/env/testdata/bashref/TestReadBashRandom.json+9304 −0看文件

改动太大,不在线显示。

新增internal/env/testdata/bashref/TestSQEscapeBash.json+100 −0看文件

改动太大,不在线显示。

新增internal/env/testdata/fuzz/FuzzLookup/33accaf57e822b83+2 −0看文件

改动太大,不在线显示。

新增internal/env/testdata/fuzz/FuzzLookup/4f2c5729a064cfe5+2 −0看文件

改动太大,不在线显示。

新增internal/env/testdata/fuzz/FuzzLookup/980388dfb02d924a+2 −0看文件

改动太大,不在线显示。

新增internal/env/windows_test.go+28 −0看文件

改动太大,不在线显示。

新增internal/gitguard/bare.go+68 −0看文件

改动太大,不在线显示。

新增internal/gitguard/fuzz_test.go+112 −0看文件

改动太大,不在线显示。

新增internal/gitguard/linked_unix.go+18 −0看文件

改动太大,不在线显示。

新增internal/gitguard/linked_windows.go+5 −0看文件

改动太大,不在线显示。

新增internal/gitguard/scan.go+800 −0看文件

改动太大,不在线显示。

新增internal/gitguard/scan_native_test.go+337 −0看文件

改动太大,不在线显示。

新增internal/gitguard/scan_test.go+469 −0看文件

改动太大,不在线显示。

新增internal/gitguard/testdata/bashref/TestRisksUnderDeclinedName.json+23 −0看文件

改动太大,不在线显示。

新增internal/gitguard/testdata/bashref/TestScanBash.json+654 −0看文件

改动太大,不在线显示。

新增internal/gitguard/testdata/fuzz/FuzzHops/2dd930902a01074c+2 −0看文件

改动太大,不在线显示。

新增internal/gitx/gitx.go+24 −0看文件

改动太大,不在线显示。

新增internal/guard/guard.go+451 −0看文件

改动太大,不在线显示。

新增internal/guard/guard_test.go+173 −0看文件

改动太大,不在线显示。

新增internal/host/disk_linux.go+12 −0看文件

改动太大,不在线显示。

新增internal/host/disk_linux_test.go+21 −0看文件

改动太大,不在线显示。

新增internal/host/disk_other_unix.go+10 −0看文件

改动太大,不在线显示。

新增internal/host/disk_test.go+26 −0看文件

改动太大,不在线显示。

新增internal/host/disk_unix.go+14 −0看文件

改动太大,不在线显示。

新增internal/host/disk_windows.go+16 −0看文件

改动太大,不在线显示。

新增internal/host/host.go+96 −0看文件

改动太大,不在线显示。

新增internal/host/host_test.go+49 −0看文件

改动太大,不在线显示。

新增internal/host/prereqs.go+148 −0看文件

改动太大,不在线显示。

新增internal/host/testdata/bashref/TestCapBash.json+1822 −0看文件

改动太大,不在线显示。

新增internal/limaembed/assets/README+3 −0看文件

改动太大,不在线显示。

新增internal/limaembed/hostagent.go+213 −0看文件

改动太大,不在线显示。

新增internal/limaembed/hostagent_test.go+33 −0看文件

改动太大,不在线显示。

新增internal/limaembed/limaembed.go+106 −0看文件

改动太大,不在线显示。

新增internal/limaembed/notify.go+69 −0看文件

改动太大,不在线显示。

新增internal/limaembed/notify_test.go+32 −0看文件

改动太大,不在线显示。

新增internal/limaembed/share.go+93 −0看文件

改动太大,不在线显示。

新增internal/mounts/build.go+153 −0看文件

改动太大,不在线显示。

新增internal/mounts/build_test.go+76 −0看文件

改动太大,不在线显示。

新增internal/mounts/fuzz_test.go+155 −0看文件

改动太大,不在线显示。

新增internal/mounts/mounts_test.go+149 −0看文件

改动太大,不在线显示。

新增internal/mounts/safety.go+236 −0看文件

改动太大,不在线显示。

新增internal/mounts/safety_test.go+146 −0看文件

改动太大,不在线显示。

新增internal/mounts/testdata/bashref/TestBuildBash.json+80 −0看文件

改动太大,不在线显示。

新增internal/mounts/testdata/bashref/TestEntriesBash.json+21 −0看文件

改动太大,不在线显示。

新增internal/mounts/testdata/bashref/TestMatchesBash.json+274 −0看文件

改动太大,不在线显示。

新增internal/mounts/testdata/bashref/TestProjectMountpointBash.json+175 −0看文件

改动太大,不在线显示。

新增internal/mounts/testdata/bashref/TestUnsafeProjectBash.json+259 −0看文件

改动太大,不在线显示。

新增internal/mounts/testdata/fuzz/FuzzMatches/b2dea5d34a1df710+3 −0看文件

改动太大,不在线显示。

新增internal/mounts/volumes.go+311 −0看文件

改动太大,不在线显示。

新增internal/mounts/windows_test.go+89 −0看文件

改动太大,不在线显示。

新增internal/netguard/netguard.go+272 −0看文件

改动太大,不在线显示。

新增internal/netguard/netguard_test.go+213 −0看文件

改动太大,不在线显示。

新增internal/paths/fuzz_test.go+38 −0看文件

改动太大,不在线显示。

新增internal/paths/paths.go+177 −0看文件

改动太大,不在线显示。

新增internal/paths/paths_test.go+72 −0看文件

改动太大,不在线显示。

新增internal/paths/testdata/bashref/TestJoinBash.json+225 −0看文件

改动太大,不在线显示。

新增internal/paths/testdata/fuzz/FuzzIn/1efe21c438796110+4 −0看文件

改动太大,不在线显示。

新增internal/paths/testdata/fuzz/FuzzIn/2e4c64451faad453+4 −0看文件

改动太大,不在线显示。

新增internal/runscript/fuzz_test.go+36 −0看文件

改动太大,不在线显示。

新增internal/runscript/runscript.go+67 −0看文件

改动太大,不在线显示。

新增internal/runscript/runscript_test.go+58 −0看文件

改动太大,不在线显示。

新增internal/state/state.go+169 −0看文件

改动太大,不在线显示。

新增internal/state/state_test.go+96 −0看文件

改动太大,不在线显示。

新增internal/ui/fuzz_test.go+69 −0看文件

改动太大,不在线显示。

新增internal/ui/testdata/bashref/TestBoxBash.json+36 −0看文件

改动太大,不在线显示。

新增internal/ui/testdata/bashref/TestWrapBash.json+1044 −0看文件

改动太大,不在线显示。

新增internal/ui/tty_unix.go+12 −0看文件

改动太大,不在线显示。

新增internal/ui/tty_windows.go+11 −0看文件

改动太大,不在线显示。

新增internal/ui/ui.go+198 −0看文件

改动太大,不在线显示。

新增internal/ui/ui_test.go+90 −0看文件

改动太大,不在线显示。

新增internal/ui/window.go+164 −0看文件

改动太大,不在线显示。

新增internal/ui/window_test.go+63 −0看文件

改动太大,不在线显示。

新增internal/version/testdata/bashref/TestAtLeastBash.json+276 −0看文件

改动太大,不在线显示。

新增internal/version/version.go+88 −0看文件

改动太大,不在线显示。

新增internal/version/version_test.go+81 −0看文件

改动太大,不在线显示。

新增internal/vm/driver_hcs_windows.go+10 −0看文件

改动太大,不在线显示。

新增internal/vm/driver_qemu.go+10 −0看文件

改动太大,不在线显示。

新增internal/vm/driver_vz_darwin.go+10 −0看文件

改动太大,不在线显示。

新增internal/vm/driver_wsl2_windows.go+10 −0看文件

改动太大,不在线显示。

新增internal/vm/lima.go+600 −0看文件

改动太大,不在线显示。

新增internal/vm/lima_e2e_test.go+155 −0看文件

改动太大,不在线显示。

新增internal/vm/lima_test.go+377 −0看文件

改动太大,不在线显示。

新增internal/vm/main_test.go+26 −0看文件

改动太大,不在线显示。

新增internal/vm/migrate.go+175 −0看文件

改动太大,不在线显示。

新增internal/vm/migrate_test.go+74 −0看文件

改动太大,不在线显示。

新增internal/vm/migrate_unix_test.go+71 −0看文件

改动太大,不在线显示。

新增internal/vm/networkconfined.go+32 −0看文件

改动太大,不在线显示。

新增internal/vm/networkconfined_test.go+50 −0看文件

改动太大,不在线显示。

新增internal/vm/vm.go+150 −0看文件

改动太大,不在线显示。

新增internal/vm/vmtest/fake.go+210 −0看文件

改动太大,不在线显示。

新增internal/vmname/fuzz_test.go+36 −0看文件

改动太大,不在线显示。

新增internal/vmname/testdata/bashref/TestNameBash.json+180 −0看文件

改动太大,不在线显示。

新增internal/vmname/testdata/bashref/TestScratchBash.json+180 −0看文件

改动太大,不在线显示。

新增internal/vmname/vmname.go+165 −0看文件

改动太大,不在线显示。

新增internal/vmname/vmname_test.go+175 −0看文件

改动太大,不在线显示。

删除lib/code.sh+0 −184

改动太大,不在线显示。

删除lib/doctor.sh+0 −388

改动太大,不在线显示。

删除lib/env.sh+0 −521

改动太大,不在线显示。

删除lib/git.sh+0 −887

改动太大,不在线显示。

删除lib/host.sh+0 −273

改动太大,不在线显示。

删除lib/info.sh+0 −194

改动太大,不在线显示。

删除lib/install.sh+0 −120

改动太大,不在线显示。

删除lib/mounts.sh+0 −583

改动太大,不在线显示。

删除lib/options.sh+0 −82

改动太大,不在线显示。

删除lib/runtime.sh+0 −57

改动太大,不在线显示。

删除lib/setup.sh+0 −591

改动太大,不在线显示。

删除lib/ui.sh+0 −162

改动太大,不在线显示。

删除lib/vm.sh+0 −518

改动太大,不在线显示。

新增patches/README.md+165 −0看文件

改动太大,不在线显示。

新增patches/gvisor-tap-vsock/0001-outbound-policy.patch+119 −0看文件

改动太大,不在线显示。

新增patches/gvisor-tap-vsock/0002-dns-policy.patch+197 −0看文件

改动太大,不在线显示。

新增patches/lima/0001-mounts-add-sshfs.readonlyNames.patch+426 −0看文件

改动太大,不在线显示。

新增patches/lima/0002-hostagent-relay-host-deletions.patch+380 −0看文件

改动太大,不在线显示。

新增patches/lima/0003-hostagent-keep-sshfs-options-on-retry.patch+13 −0看文件

改动太大,不在线显示。

新增patches/lima/0004-portfwd-not-next-to-a-host-program.patch+247 −0看文件

改动太大,不在线显示。

新增patches/lima/0005-network-isolation-hooks.patch+389 −0看文件

改动太大,不在线显示。

新增patches/sftp/0001-sequential.patch+106 −0看文件

改动太大,不在线显示。

新增patches/sftp/0002-664-handle-file.patch+135 −0看文件

改动太大,不在线显示。

新增patches/sftp/0003-mkdir-attrs.patch+65 −0看文件

改动太大,不在线显示。

新增patches/sftp/0004-robustness.patch+837 −0看文件

改动太大,不在线显示。

新增patches/sftp/0005-fuzz-request-server.patch+87 −0看文件

改动太大,不在线显示。

新增patches/sshocker/0001-rooted-server-readonly-names.patch+2152 −0看文件

改动太大,不在线显示。

新增patches/sshocker/0002-expect-remove.patch+333 −0看文件

改动太大,不在线显示。

新增patches/sshocker/0003-append-fix.patch+114 −0看文件

改动太大,不在线显示。

新增patches/sshocker/0004-664-sequential.patch+240 −0看文件

改动太大,不在线显示。

新增patches/sshocker/0005-append-mkdir-guards.patch+219 −0看文件

改动太大,不在线显示。

新增patches/sshocker/0006-robustness.patch+783 −0看文件

改动太大,不在线显示。

新增patches/sshocker/0007-name-folding-fuzz.patch+485 −0看文件

改动太大,不在线显示。

新增patches/sshocker/0008-write-guard.patch+525 −0看文件

改动太大,不在线显示。

新增patches/sshocker/0009-relay-ignore-own-removals.patch+495 −0看文件

改动太大,不在线显示。

修改release.sh+340 −61看文件

改动太大,不在线显示。

修改runtime.example.sh+1 −1看文件

改动太大,不在线显示。

新增scripts/licenses+106 −0看文件

改动太大,不在线显示。

新增scripts/third-party-sync+103 −0看文件

改动太大,不在线显示。

新增setup_script_test.go+41 −0看文件

改动太大,不在线显示。

删除test-e2e.sh+0 −361

改动太大,不在线显示。

删除test.sh+0 −29

改动太大,不在线显示。

删除tests/01-basics.sh+0 −215

改动太大,不在线显示。

删除tests/02-setup-output.sh+0 −150

改动太大,不在线显示。

删除tests/03-install.sh+0 −200

改动太大,不在线显示。

删除tests/04-env.sh+0 −304

改动太大,不在线显示。

删除tests/05-host-version-runtime.sh+0 −179

改动太大,不在线显示。

删除tests/07-stop-rm.sh+0 −79

改动太大,不在线显示。

删除tests/08-mount-mode.sh+0 −161

改动太大,不在线显示。

删除tests/09-env-read.sh+0 −143

改动太大,不在线显示。

删除tests/10-names-and-paths.sh+0 −59

改动太大,不在线显示。

删除tests/11-recorded-commands.sh+0 −229

改动太大,不在线显示。

删除tests/12-ssh-port-and-creation.sh+0 −76

改动太大,不在线显示。

删除tests/13-volumes-and-readonly.sh+0 −327

改动太大,不在线显示。

删除tests/14-git-protection.sh+0 −841

改动太大,不在线显示。

删除tests/15-status-and-doctor.sh+0 −183

改动太大,不在线显示。

删除tests/16-setup.sh+0 −386

改动太大,不在线显示。

删除tests/17-curl-installer.sh+0 −136

改动太大,不在线显示。

删除tests/18-windows.sh+0 −374

改动太大,不在线显示。

删除tests/19-wsl.sh+0 −48

改动太大,不在线显示。

删除tests/20-project-files.sh+0 −228

改动太大,不在线显示。

删除tests/21-scratch.sh+0 −154

改动太大,不在线显示。

删除tests/22-code.sh+0 −108

改动太大,不在线显示。

新增tests/fuzz/go.work+10 −0看文件

改动太大,不在线显示。

新增tests/fuzz/go.work.sum+6 −0看文件

改动太大,不在线显示。

删除tests/helpers.sh+0 −119

改动太大,不在线显示。

新增tests/installer.sh+260 −0看文件

改动太大,不在线显示。

新增tests/release.sh+298 −0看文件

改动太大,不在线显示。

改名tests/06-help-and-setup-script.sh → tests/setup-script.sh+33 −76看文件

改动太大,不在线显示。

新增tests/sftp/fs_suite.py+852 −0看文件

改动太大,不在线显示。

新增tests/sftp/openssh_harness.sh+13 −0看文件

改动太大,不在线显示。

新增tests/sftp/run+39 −0看文件

改动太大,不在线显示。

新增tests/sftp/testdata/harness/harness_export.go+23 −0看文件

改动太大,不在线显示。

新增tests/sftp/testdata/harness/main.go+68 −0看文件

改动太大,不在线显示。

新增third_party/SOURCES+9 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/.dockerignore+4 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/.gitattributes+1 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/.github/dependabot.yml+17 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/.github/workflows/go.yml+83 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/.github/workflows/golangci-lint.yml+20 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/.github/workflows/release.yml+59 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/.gitignore+4 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/.golangci.yml+29 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/.packit.yaml+76 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/CODE-OF-CONDUCT.md+3 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/DEVELOPMENT.md+86 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/LICENSE+202 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/Makefile+95 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/OWNERS+13 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/README.md+250 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/SECURITY.md+3 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/cmd/gvproxy/config.go+446 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/cmd/gvproxy/config.yaml+41 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/cmd/gvproxy/config_test.go+598 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/cmd/gvproxy/main.go+437 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/cmd/qemu-wrapper/README.md+6 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/cmd/qemu-wrapper/main.go+27 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/cmd/ssh-over-vsock/client.go+66 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/cmd/ssh-over-vsock/main.go+63 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/cmd/test-companion/main.go+53 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/cmd/vm/main_linux.go+224 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/cmd/win-sshproxy/event-hook.go+72 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/cmd/win-sshproxy/main.go+235 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/contrib/networkmanager/vsock0.nmconnection+15 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/contrib/systemd/[email protected]+13 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/doc/MAINTAINERS.md+53 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/doc/curl.png看文件

二进制文件,不显示改动。

新增third_party/gvisor-tap-vsock/doc/http.png看文件

二进制文件,不显示改动。

新增third_party/gvisor-tap-vsock/go.mod+52 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/go.sum+223 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/images/Dockerfile+9 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/images/udhcpc.sh+68 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/pkg/client/client.go+178 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/pkg/fs/umask_unix.go+9 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/pkg/fs/umask_windows.go+8 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/pkg/net/stdio/dial.go+51 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/pkg/net/stdio/ioaddr.go+12 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/pkg/net/stdio/ioconn.go+50 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/pkg/notification/sender.go+75 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/pkg/notification/sender_test.go+91 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/pkg/services/dhcp/dhcp.go+137 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/pkg/services/dns/dns.go+334 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/pkg/services/dns/dns_test.go+484 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/pkg/services/forwarder/ports.go+394 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/pkg/services/forwarder/tcp.go+73 −0看文件

改动太大,不在线显示。

新增third_party/gvisor-tap-vsock/pkg/services/forwarder/udp.go+60 −0看文件

改动太大,不在线显示。

还有 931 个文件没有列出(一次最多显示 300 个)。