跳到主要内容

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

提交记录
修改CHANGELOG.md+64 −31看文件
@@ -16,32 +16,49 @@
1616 theme, GitHub Copilot disabled, no telemetry, no welcome page, tips,
1717 recommendations or experiments. The JSON schemas the editor validates
1818 files with (`package.json`, `tsconfig.json`...) are downloaded once by
19删除: `setup`: opening a file sends no request.
19新增: `setup`, in parallel, each stored under the URL the editor asks for (a
20新增: schema's references followed from its `$id`, as the editor does):
21新增: opening a file sends no request.
2022- The editor's password is made in each VM on first use, never in the base,
2123 of which every VM is a copy, and printed. Each VM's editor is at
22删除: `http://<vm-name>.localhost:<port>/`, a port of its own from 20000 to
23删除: 29999, the same on every start: browsers keep cookies per host name, not
24删除: per port, so at `127.0.0.1` a page served by any VM would get the session
25删除: of every editor, which logs into it. Safari may not resolve `*.localhost`:
26删除: then `127.0.0.1` in a private window kept for the editor. code-server's
27删除: port proxy is off: links to `localhost:<port>` open at that port on your
28删除: machine, where Lima forwards it. Claude Code's login pages open without the editor's
29删除: link prompt; other links still ask.
24新增: `http://<vm-name>.localhost:<port>/`, the first of ten ports from 20000 to
25新增: 29999 picked from its name that is free, so the same on every start while
26新增: it is: browsers keep cookies per host name, not per port, so a page a VM
27新增: serves at `127.0.0.1` does not get the session of every editor. Safari may
28新增: not resolve `*.localhost`: then `127.0.0.1` in a private window kept for
29新增: the editor. code-server's port proxy is off: links to `localhost:<port>`
30新增: open at that port on your machine, where Lima forwards it. Claude Code's
31新增: login pages open without the editor's link prompt; other links still ask.
32新增:- Not a boundary between VMs: a VM can listen on a port Lima forwards to
33新增: your machine and send your browser to another VM's editor host name on
34新增: it, getting that editor's session. Keeping VMs apart needs network
35新增: isolation, on the roadmap; until then, stop `agent-vm code` when not
36新增: using it.
3037- With code-server picked in the wizard, the base gets 4 GB of memory
3138 instead of 3, unless `--memory` says otherwise.
3239
3340### Changed
3441
3542- A command that is not in the VM (`agent-vm run foo`, or an agent not
36删除: installed) says so, with status 127, instead of `env`'s error.
37删除:- The protected shares turn sshfs's cache off: with it, a file the host
38删除: changed showed as it was for up to 20 seconds, and an agent writing back
39删除: what it read undid the change. Existing VMs get it on their next start
40删除: from stopped.
41删除:- A project share that is no longer mounted (sshfs died) is caught: the
42删除: write probe now checks that its file reached the host. The VM is restarted
43新增: installed) says so, with status 127, instead of `env`'s error. A path
44新增: (`./build.sh`) is still `env`'s to run, with its reason: a script without
45新增: +x is denied, status 126.
46新增:- The protected writable shares turn sshfs's cache off: with it, a file the
47新增: host changed showed as it was for up to 20 seconds, and an agent writing
48新增: back what it read undid the change. `AGENT_VM_SSHFS_CACHE=1` in the shell
49新增: turns it back on, faster on many files (a repeated `git status` sends
50新增: about 20 times fewer requests). The read-only shares keep it. Existing VMs
51新增: get it on their next start from stopped.
52新增:- A project share that is no longer mounted (sshfs died) is caught: the VM
53新增: must see a file this machine just put in the project. The VM is restarted
4354 with its shares, with a warning that what it wrote meanwhile is on its own
44删除: disk.
55新增: disk. No probe file is left anywhere, a `--scratch` folder included.
56新增:- `agent-vm code` finds the ports something in the VM listens on with `ss`,
57新增: whatever it speaks, and never through the VM's HTTP proxy, which made
58新增: every port look taken.
59新增:- A start reads `~/.agent-vm/volumes` and scans the repositories of each
60新增: share once: about 4 times fewer processes with a writable volume holding
61新增: many repositories.
4562
4663### Security
4764
@@ -51,19 +68,35 @@
5168 not.
5269- A VM recorded as protected is checked against the shares Lima has for it:
5370 a share without the read-only names, set by hand or by Lima's `_config`,
54删除: makes it unprotected, and a stopped VM that keeps one is not started. A
55删除: running VM served by another `limactl` than the one on `PATH` (a stock
56删除: Lima started it) is not taken as protected either.
57删除:- Hooks reached through symlinks: `.git/hooks` or `core.hooksPath` linked to
58删除: a folder of the project makes that folder read-only too, and a hook that
59删除: is a link to a file of the project is a risk to accept.
60删除:- Repositories in writable `~/.agent-vm/volumes` get the same checks as the
61删除: project's: their hooks folders join the read-only names, and their config
62删除: naming commands in them is a risk to accept.
63删除:- A `.git` or `.hg`, or a folder inside one, is refused as a project: the
64删除: read-only names apply below a share's root only. A volume is refused when
65删除: it would be refused as a project (agent-vm's state, Lima's, the home
66删除: directory), or when its destination covers the project.
71新增: makes it unprotected, and no boot (a first start, a repair, a restart for
72新增: `--readonly`, the 0.1.0 migration) happens with one; the error says which
73新增: share, or that the mount type is wrong. A VM that shares nothing
74新增: (`--scratch`, the migration) boots with no share at all. A running VM
75新增: served by another `limactl` build than the one on `PATH` (a stock Lima
76新增: started it) is not taken as protected either, by a start, by `--readonly`
77新增: or by `doctor`: on macOS the running binary is asked of `lsof`, which a
78新增: Homebrew link does not fool, and the same build reinstalled since is not
79新增: taken for another. `--readonly` is refused when Lima's `_config` gives the
80新增: VM a writable share.
81新增:- What git on this machine runs from a share, found wherever it points:
82新增: hooks folders, hooks, commands and included config in the project, in a
83新增: writable volume, or pointing from one to another (`core.hooksPath` or
84新增: `core.fsmonitor` into a volume), and git's own global config kept in one.
85新增: A hooks folder becomes a read-only name; anything else is a risk to
86新增: accept. Every symlink on the way is followed, a link not there yet
87新增: included (the VM could create its target), and a link inside the
88新增: project on the way is protected as well. Writable volumes reached through
89新增: a symlink are searched, bare repositories in them get their folder's name
90新增: read-only, and more than 50 repositories in one share is said. A hook
91新增: linked to another inside its own read-only folder is no risk any more.
92新增: Names printed from the shares have their control characters made
93新增: visible.
94新增:- A `.git` or `.hg`, a bare repository, or a folder inside one, is refused as
95新增: the project, and as a writable volume: the read-only names apply below a
96新增: share's root only. A volume is refused when it is, contains or is inside
97新增: agent-vm's state, Lima's or agent-vm itself, or contains the home folder,
98新增: read-only or not, and when it would be mounted at or above the project, or
99新增: where another volume is, whatever the spelling or with no destination.
67100
68101## 0.2.0
69102
@@ -314,7 +347,7 @@ has passwordless sudo, so anything enforced there is advisory at best.
314347 that save the port rather than an alias (#28). `0` goes back to a new port on
315348 each start. A port another agent-vm VM has is refused. `info` gains
316349 `ssh_host` and `ssh_config`: Lima's alias for the VM and the SSH config file
317删除: it keeps current. [The website](https://www.agent-vm.org/#connect-an-ide-over-ssh)
350新增: it keeps current. [The website](https://www.agent-vm.org/#ssh-from-your-machine)
318351 has the `~/.ssh/config` lines to use them, which keep the host's SSH agent out
319352 of the VM.
320353- `curl -fsSL https://www.agent-vm.org/install.sh | sh` installs the latest
修改agent-vm.setup.sh+95 −46看文件
@@ -51,6 +51,8 @@ INSTALL_CODE_SERVER="${AGENT_VM_INSTALL_CODE_SERVER:-0}"
5151INSTALL_CODE_CLAUDE="${AGENT_VM_INSTALL_CODE_CLAUDE:-0}"
5252INSTALL_CODE_CODEX="${AGENT_VM_INSTALL_CODE_CODEX:-0}"
5353INSTALL_CODE_VIBE="${AGENT_VM_INSTALL_CODE_VIBE:-0}"
54新增:# An extension needs the editor: `agent-vm setup` says so already, a run of
55新增:# this script on its own may not.
5456if [[ "$INSTALL_CODE_CLAUDE$INSTALL_CODE_CODEX$INSTALL_CODE_VIBE" == *1* ]]; then
5557 INSTALL_CODE_SERVER=1
5658fi
@@ -321,49 +323,94 @@ toml_prepend() {
321323 mv "$file.tmp" "$file"
322324}
323325
326新增:# The URL <ref> points to from the http(s) URL <base>, fragments dropped:
327新增:# absolute, scheme-relative, absolute-path or relative, its . and ..
328新增:# segments resolved (RFC 3986). Fails for another scheme (vscode://..., the
329新增:# editor's own schemas).
330新增:schema_url_resolve() {
331新增: local base="${1%%#*}" ref="${2%%#*}" scheme rest host path seg
332新增: local -a segs=() kept=()
333新增: case "$ref" in
334新增: http://*|https://*) base="$ref" ref="" ;;
335新增: *://*) return 1 ;;
336新增: esac
337新增: scheme="${base%%://*}"
338新增: rest="${base#*://}"
339新增: host="${rest%%/*}"
340新增: path=/
341新增: [[ "$rest" != */* ]] || path="/${rest#*/}"
342新增: case "$ref" in
343新增: "") ;;
344新增: //*)
345新增: host="${ref#//}"
346新增: path=/
347新增: if [[ "$host" == */* ]]; then path="/${host#*/}"; host="${host%%/*}"; fi ;;
348新增: /*) path="$ref" ;;
349新增: *) path="${path%/*}/$ref" ;;
350新增: esac
351新增: IFS=/ read -ra segs <<< "$path"
352新增: for seg in ${segs[@]+"${segs[@]}"}; do
353新增: case "$seg" in
354新增: ""|.) ;;
355新增: ..) [[ ${#kept[@]} -eq 0 ]] || unset 'kept[-1]' ;;
356新增: *) kept+=("$seg") ;;
357新增: esac
358新增: done
359新增: local IFS=/
360新增: printf '%s://%s/%s\n' "$scheme" "$host" "${kept[*]}"
361新增:}
362新增:
324363# Write to <out> code-server's machine settings with every JSON schema its
325364# built-in extensions (in <ext-dir>) name by URL, and every schema those refer
326删除:# to, downloaded now. A json.schemas entry with a URL and its content makes
327删除:# the editor use the content instead of fetching the URL, so with downloads
328删除:# off (the user settings) opening a file sends no request. A failed download
329删除:# only leaves its files unvalidated.
365新增:# to, downloaded now, a level of references at a time, in parallel. A
366新增:# json.schemas entry with a URL and its content makes the editor use the
367新增:# content instead of fetching the URL, so with downloads off (the user
368新增:# settings) opening a file sends no request. A failed download only leaves
369新增:# its files unvalidated.
370新增:# The editor resolves a schema's relative references against its $id when it
371新增:# has one (www.schemastore.org/package says json.schemastore.org/package.json),
372新增:# else against the URL it loaded it from: so are they here, for each to be
373新增:# stored under the URL the editor asks for.
374新增:# These are the machine settings: a json.schemas of the user settings would
375新增:# be replaced by this one, not added to (VS Code merges objects across
376新增:# settings, not arrays). A schema of your own goes in a workspace's settings.
330377code_server_schemas() {
331删除: local ext_dir="$1" out="$2" dir u f r base fetch n=0
332删除: local -a queue
333删除: local -A seen
378新增: local ext_dir="$1" out="$2" dir u f r base i n=0
379新增: local -a level next fetch
380新增: local -A seen urls
334381 dir="$(mktemp -d)"
335382 : > "$dir/entries"
336删除: mapfile -t queue < <(jq -r '.contributes.jsonValidation[]?.url | select(test("^https?://"))' \
383新增: mapfile -t level < <(jq -r '.contributes.jsonValidation[]?.url | select(test("^https?://"))' \
337384 "$ext_dir"/*/package.json | sort -u)
338删除: while [[ ${#queue[@]} -gt 0 ]]; do
339删除: u="${queue[0]}"
340删除: queue=("${queue[@]:1}")
341删除: [[ -z "${seen[$u]:-}" ]] || continue
342删除: seen[$u]=1
343删除: n=$((n + 1))
344删除: f="$dir/$n.json"
345删除: # json.schemastore.org only redirects to www.schemastore.org.
346删除: fetch="${u%%#*}"
347删除: fetch="${fetch/#https:\/\/json.schemastore.org\//https://www.schemastore.org/}"
348删除: if ! curl -fsSL --max-time 30 -o "$f" "$fetch" </dev/null || ! jq -e . "$f" >/dev/null 2>&1; then
349删除: echo "Warning: could not download the JSON schema $u: files using it are not validated." >&2
350删除: continue
351删除: fi
352删除: jq -c --arg u "$u" '{url: $u, schema: .}' "$f" >> "$dir/entries"
353删除: # Relative references resolve against the URL the schema was loaded from.
354删除: # Other schemes (vscode://) are the editor's own.
355删除: base="${u%%#*}"
356删除: while IFS= read -r r; do
357删除: case "$r" in
358删除: http://*|https://*) ;;
359删除: *://*) continue ;;
360删除: /*) r="${base%%://*}://$(printf '%s' "${base#*://}" | cut -d/ -f1)$r" ;;
361删除: *) r="${base%/*}/$r" ;;
362删除: esac
363删除: while [[ "$r" == */./* ]]; do r="${r/\/.\///}"; done
364删除: while [[ "$r" =~ ^(.*://.*)/[^/]+/\.\./(.*)$ ]]; do r="${BASH_REMATCH[1]}/${BASH_REMATCH[2]}"; done
365删除: queue+=("$r")
366删除: done < <(jq -r '[.. | objects | ."$ref"? | strings | sub("#.*$"; "") | select(length > 0)] | unique[]' "$f")
385新增: while [[ ${#level[@]} -gt 0 ]]; do
386新增: fetch=() urls=() next=()
387新增: for u in "${level[@]}"; do
388新增: u="${u%%#*}"
389新增: [[ -z "${seen[$u]:-}" ]] || continue
390新增: seen[$u]=1
391新增: n=$((n + 1))
392新增: urls[$n]="$u"
393新增: # Fetched where json.schemastore.org redirects to, stored under the URL
394新增: # the editor asks for.
395新增: fetch+=(-o "$dir/$n.json" "${u/#https:\/\/json.schemastore.org\//https://www.schemastore.org/}")
396新增: done
397新增: # Each file checked below: one failed download fails curl as a whole.
398新增: [[ ${#fetch[@]} -eq 0 ]] || curl -fsSL --max-time 30 --parallel --parallel-max 8 "${fetch[@]}" </dev/null || true
399新增: for i in "${!urls[@]}"; do
400新增: u="${urls[$i]}"
401新增: f="$dir/$i.json"
402新增: if ! jq -c --arg u "$u" '{url: $u, schema: .}' "$f" > "$f.entry" 2>/dev/null; then
403新增: echo "Warning: could not download the JSON schema $u: files using it are not validated." >&2
404新增: continue
405新增: fi
406新增: cat "$f.entry" >> "$dir/entries"
407新增: base="$(jq -r '(."$id" // .id // empty) | strings | select(test("^https?://"))' "$f")"
408新增: [[ -n "$base" ]] || base="$u"
409新增: while IFS= read -r r; do
410新增: r="$(schema_url_resolve "$base" "$r")" && next+=("$r")
411新增: done < <(jq -r '[.. | objects | ."$ref"? | strings | select(startswith("#") | not)] | unique[]' "$f")
412新增: done
413新增: level=(${next[@]+"${next[@]}"})
367414 done
368415 mkdir -p "$(dirname "$out")"
369416 jq -sc '{"json.schemas": .}' "$dir/entries" > "$out"
@@ -384,12 +431,15 @@ if [[ "$INSTALL_CODE_SERVER" == "1" ]]; then
384431 code-server "${extensions[@]}" </dev/null
385432 fi
386433 # chat.disableAIFeatures turns off the GitHub Copilot chat and completions
387删除: # that code-server ships (lib/code.sh also disables the extension).
388删除: # telemetry.telemetryLevel: code-server's --disable-telemetry leaves the
389删除: # built-in extensions sending telemetry. The editor downloads no JSON
390删除: # schema: setup does, once, into the machine settings (code_server_schemas).
391删除: # The rest is the welcome page, tips, recommendations, experiments and
392删除: # online settings search.
434新增: # that code-server ships (lib/code.sh also disables the extension), and
435新增: # chat.mcp.gallery.enabled its MCP gallery. telemetry.*: code-server's
436新增: # --disable-telemetry leaves the built-in extensions sending telemetry. The
437新增: # editor downloads no JSON schema: setup does, once, into the machine
438新增: # settings (code_server_schemas). remote.autoForwardPorts: Lima forwards
439新增: # the VM's ports already. update.*: setup installs code-server, the editor
440新增: # does not update itself. The rest is the look (dark theme, no secondary
441新增: # side bar), the welcome page, tips, recommendations, experiments, online
442新增: # settings search, and Claude's onboarding checklist.
393443 mkdir -p "$HOME/.local/share/code-server/User"
394444 jq -n --arg claude "$INSTALL_CODE_CLAUDE" '
395445 {
@@ -426,11 +476,10 @@ if [[ "$INSTALL_CODE_SERVER" == "1" ]]; then
426476 # do for the CLI. These keys are machine-scoped: code-server ignores them in
427477 # the user settings.
428478 if [[ "$INSTALL_CODE_CLAUDE" == "1" ]]; then
429删除: mkdir -p "$(dirname "$cs_machine")"
430删除: { if [[ -f "$cs_machine" ]]; then cat "$cs_machine"; else echo '{}'; fi; } | jq '. + {
479新增: jq -c '. + {
431480 "claudeCode.allowDangerouslySkipPermissions": true,
432481 "claudeCode.initialPermissionMode": "bypassPermissions"
433删除: }' > "$cs_machine.tmp"
482新增: }' "$cs_machine" > "$cs_machine.tmp"
434483 mv "$cs_machine.tmp" "$cs_machine"
435484 fi
436485 # Codex and Vibe have no setting for it: their extensions start in the mode
修改agent-vm.sh+91 −55看文件
@@ -32,8 +32,10 @@ AGENT_VM_STATE_DIR="${AGENT_VM_STATE_DIR:-${HOME}/.agent-vm}"
3232# `install` makes is one. By hand, as macOS's readlink has no -f. `CDPATH=`
3333# everywhere a relative path is cd'ed to: with it set, cd searches it first.
3434_agent_vm_script_dir() {
35删除: local src="$1" dir
36删除: while [ -L "$src" ]; do
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))
3739 dir="$(CDPATH= cd -P -- "$(dirname "$src")" >/dev/null && pwd)"
3840 src="$(readlink "$src")"
3941 case "$src" in
@@ -126,16 +128,17 @@ _agent_vm_start_checks() {
126128 fi
127129
128130 # With it, the names the shares need: those always listed, and one per
129删除: # hooks folder git runs from in the project (see _agent_vm_project_hooks),
130删除: # its first component. A dot-name (.husky, .githooks) is taken as is; any
131删除: # other is read-only in every folder of the project, so it is asked first
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
132134 # (yes by default, and when no one can answer). A folder that cannot be
133删除: # protected, or one declined, is a risk to accept. So are git config files
134删除: # in the project, and settings running commands from it. Under --readonly
135删除: # the VM writes none of them: the names are taken as they come, with no
136删除: # warning and no question.
137删除: local hooks_rel hooks_in hooks_name hooks_names=()
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=""
138140 if [[ -n "$protect_git" ]]; then
141新增: scan="$(_agent_vm_git_scan "$host_dir")"
139142 while IFS=$'\t' read -r hooks_rel hooks_in; do
140143 [[ -n "$hooks_rel" ]] || continue
141144 if [[ -n "$rdonly" ]]; then
@@ -145,8 +148,10 @@ _agent_vm_start_checks() {
145148 if ! hooks_name="$(_agent_vm_hooks_name "$hooks_in")"; then
146149 if [[ "$hooks_rel" == . ]]; then
147150 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
148153 else
149删除: echo "Warning: git's core.hooksPath is '$hooks_rel', in the project, and its name cannot be made read-only: git on this machine runs the hooks the agent puts there." >&2
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
150155 fi
151156 if [[ -z "$vm_up" ]] && ! _agent_vm_confirm_unsafe; then
152157 echo "Aborted. Point core.hooksPath to a folder of the project (agent-vm keeps it read-only), or outside it." >&2
@@ -166,16 +171,16 @@ _agent_vm_start_checks() {
166171 fi
167172 hooks_names+=("$hooks_name")
168173 hooks_notes="$hooks_notes$(_agent_vm_hooks_note "$hooks_rel" "$hooks_name")"$'\n'
169删除: done <<< "$(_agent_vm_share_hooks "$host_dir")"
174新增: done <<< "$(_agent_vm_scan_part H "$scan")"
170175 ro_names="$(_agent_vm_names_json ${hooks_names[@]+"${hooks_names[@]}"})"
171176
172177 local git_risks=""
173删除: [[ -n "$rdonly" ]] || git_risks="$(_agent_vm_share_config_risks "$host_dir")"
178新增: [[ -n "$rdonly" ]] || git_risks="$(_agent_vm_scan_part R "$scan")"
174179 if [[ -n "$git_risks" ]]; then
175180 echo "Warning: git on this machine uses these, and the VM can write them:" >&2
176181 printf '%s\n' "$git_risks" | sed 's/^/ /' >&2
177182 if [[ -z "$vm_up" ]] && ! _agent_vm_confirm_unsafe; then
178删除: echo "Aborted. Move them out of the project, or have them name commands outside it." >&2
183新增: echo "Aborted. Move them out of the shared folders, or have them name commands outside them." >&2
179184 return 1
180185 fi
181186 fi
@@ -221,7 +226,39 @@ _agent_vm_apply_shares() {
221226 echo "$out" >&2
222227 return 1
223228 fi
224删除: _agent_vm_record_mounts "$vm" "$json"
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
225262}
226263
227264# The caller's memory, cpus, ssh_port and disk, on the stopped <vm>. The disk
@@ -247,15 +284,14 @@ _agent_vm_apply_resources() {
247284# The env push and the write probe (see _agent_vm_push_env_and_probe), with
248285# the caller's vm_name, host_dir, env_payload, guest_env, guest_runtime and
249286# scratch, into its probe_out and is_writable: true, false, or lost when the
250删除:# share is not mounted. A scratch VM works on its own disk: nothing reaches
251删除:# this machine there, by design.
287新增:# share is not mounted.
252288_agent_vm_push_and_probe() {
253289 local st=0
254290 probe_out="$(_agent_vm_push_env_and_probe "$vm_name" "$host_dir" "$env_payload" \
255291 "$guest_env" "$guest_runtime")" || st=$?
256292 case "$st" in
257293 0) is_writable="true" ;;
258删除: 2) if [[ -n "$scratch" ]]; then is_writable="true"; else is_writable="lost"; fi ;;
294新增: 2) is_writable="lost" ;;
259295 *) is_writable="false" ;;
260296 esac
261297 [[ "$probe_out" == *env-ok* ]] || echo "Warning: failed to push the env files into VM '$vm_name'." >&2
@@ -424,34 +460,32 @@ _agent_vm_ensure_running() {
424460 _agent_vm_running "$vm_name" && was_running=1
425461
426462 # Shares recorded otherwise than asked: the .git protection (git_stale), its
427删除: # names (names_stale), the mode (mode_stale). A stopped VM is changed before
428删除: # it boots, so nothing starting with it gets a writable window; a running
429删除: # one keeps its shares until stopped, or is offered a restart.
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).
430467 local was_protected="" git_stale="" names_stale="" mode_stale="" cache_stale=""
431468 _agent_vm_mounts_protect_git "$vm_name" && was_protected=1
432删除: # The record against what Lima has for the VM, for a VM that exists: a
433删除: # share without names set outside agent-vm makes it unprotected, whatever
434删除: # was recorded. Which names, the record says (names_stale below).
435删除: if [[ -n "$protect_git" && -n "$was_protected" && -z "$is_new_vm" ]] \
436删除: && ! _agent_vm_live_shares_protected "$vm_name"; then
437删除: was_protected=""
438删除: fi
439删除: # Running, it is served by the limactl that started it, which may not be
440删除: # the one checked above.
441删除: if [[ -n "$protect_git" && -n "$was_protected" ]] && _agent_vm_running "$vm_name" \
442删除: && ! _agent_vm_hostagent_is_limactl "$vm_name"; then
443删除: echo "Warning: VM '$vm_name' was started by another limactl than $(command -v limactl), which may not keep .git read-only." >&2
444删除: was_protected=""
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
445482 fi
446483 [[ "$was_protected" != "$protect_git" ]] && git_stale=1
447删除: if [[ -n "$protect_git" && -n "$was_protected" ]] \
448删除: && ! _agent_vm_mounts_have_readonly_names "$vm_name" "$ro_names"; then
449删除: names_stale=1
450删除: fi
451删除: # Shares from before sshfs's cache was turned off: set again before it
452删除: # boots, never a reason to restart it.
453删除: if [[ -n "$protect_git" && -n "$was_protected" ]] && ! _agent_vm_mounts_cache_off "$vm_name"; then
454删除: cache_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
455489 fi
456490 if [[ -n "$scratch" ]]; then
457491 # Shares nothing, as made: nothing to bring in line.
@@ -513,20 +547,13 @@ _agent_vm_ensure_running() {
513547 _agent_vm_apply_shares "$vm_name" "$host_dir" "$want_writable" || return 1
514548 fi
515549
516删除: # A share agent-vm did not set, which its edit cannot remove: one from
517删除: # Lima's _config, added to every VM.
518删除: if [[ -z "$was_running" && -n "$protect_git" ]] && ! _agent_vm_live_shares_protected "$vm_name" "$ro_names"; then
519删除: echo "Error: Lima gives VM '$vm_name' a share without the read-only names, so the VM could write the .git in it." >&2
520删除: echo " Look for 'mounts' in $(_agent_vm_lima_home)/_config/override.yaml and default.yaml, and remove them." >&2
521删除: return 1
522删除: fi
523删除:
524550 if [[ -z "$was_running" ]]; then
551新增: _agent_vm_check_before_start "$vm_name" || return 1
525552 echo "Starting VM '$vm_name'..."
526553 local start_log
527554 if ! start_log=$(limactl start "$vm_name" 2>&1); then
528555 local ha_log
529删除: ha_log="$(_agent_vm_lima_home)/$vm_name/ha.stderr.log"
556新增: ha_log="$(_agent_vm_ha_log "$vm_name")"
530557 echo "Error: Failed to start VM '$vm_name'." >&2
531558 echo "--- limactl start output ---" >&2
532559 echo "$start_log" >&2
@@ -606,6 +633,7 @@ _agent_vm_ensure_running() {
606633 _agent_vm_migrate_0_1_if_needed "$vm_name" || return 1
607634 fi
608635 _agent_vm_apply_shares "$vm_name" "$host_dir" "$want_writable" || return 1
636新增: _agent_vm_check_before_start "$vm_name" || return 1
609637 # Checked: the probe below cannot tell a dead VM from a read-only one.
610638 if ! limactl start "$vm_name" &>/dev/null; then
611639 echo "Error: VM '$vm_name' did not come back up after changing the project mount." >&2
@@ -618,7 +646,7 @@ _agent_vm_ensure_running() {
618646 if [[ "$is_writable" == lost ]]; then
619647 echo "Error: the project share did not mount in VM '$vm_name':" >&2
620648 echo " $host_dir" >&2
621删除: echo "Lima's log: $(_agent_vm_lima_home)/$vm_name/ha.stderr.log" >&2
649新增: echo "Lima's log: $(_agent_vm_ha_log "$vm_name")" >&2
622650 elif [[ "$want_writable" == "true" ]]; then
623651 echo "Error: project directory is still not writable inside the VM:" >&2
624652 echo " $host_dir" >&2
@@ -637,7 +665,14 @@ _agent_vm_ensure_running() {
637665 if [[ -n "$rdonly" ]]; then
638666 _agent_vm_mount_is_host_enforced "$vm_name"
639667 case $? in
640删除: 0) echo "Read-only: the project and every other share (enforced on the host)." ;;
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)." ;;
641676 1) echo "Error: --readonly cannot be enforced with this mount type." >&2
642677 echo " Lima only applies it inside the guest for reverse-sshfs (without" >&2
643678 echo " readonlyNames) and for virtiofs under QEMU, where root in the VM" >&2
@@ -858,7 +893,8 @@ agent-vm() {
858893# VAR=value assignments working. `env --`: GNU env still reads assignments
859894# after it, and a command starting with `-` (`run -i foo`) is not taken for
860895# one of its options. A command that is not there is said so, with env's
861删除:# status: an agent installed only as an editor extension has no command.
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).
862898#
863899# Usage: _agent_vm_lima_run <vm_name> <host_dir> <tty:1|""> <command> [args...]
864900_agent_vm_lima_run() {
@@ -867,7 +903,7 @@ _agent_vm_lima_run() {
867903 local shell_opts=(--workdir "$host_dir")
868904 [[ -n "$want_tty" ]] && shell_opts+=(--tty)
869905 limactl shell "${shell_opts[@]}" "$vm_name" -- zsh -l -c \
870删除: '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 -- "$@"' \
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 -- "$@"' \
871907 agent-vm "$@"
872908}
873909
修改lib/code.sh+41 −34看文件
@@ -3,7 +3,8 @@
33# Run in the VM before the editor starts, with the candidate ports as
44# arguments. Prints `missing` without code-server, else its config file and
55# password, the port of an editor of this VM already running, and which
6删除:# candidates something in the VM listens on.
6新增:# candidates something in the VM listens on, whatever it speaks (ss; without
7新增:# it, curl, any answer but a refused connection, the VM's proxy bypassed).
78#
89# The password is made here, in the VM, on first use, never in the base:
910# every VM is a copy of the base disk, and one VM knowing another's password
@@ -23,19 +24,30 @@ echo "config=$cfg"
2324echo "password=$(sed -n "s/^password: //p" "$cfg")"
2425pgrep -u "$(id -u)" -af -- "--config $cfg" \
2526 | sed -n "s/.*--bind-addr 127\.0\.0\.1:\([0-9]*\).*/running=\1/p" | head -n 1
26删除:for p in "$@"; do
27删除: curl -s -o /dev/null --max-time 1 "http://127.0.0.1:$p/" && echo "listening=$p"
28删除:done
27新增:if command -v ss >/dev/null 2>&1; then
28新增: open=" $(ss -Hltn 2>/dev/null | awk "{ n = split(\$4, a, \":\"); printf \"%s \", a[n] }")"
29新增: for p in "$@"; do
30新增: case "$open" in *" $p "*) echo "listening=$p" ;; esac
31新增: done
32新增:else
33新增: for p in "$@"; do
34新增: curl -s -o /dev/null --noproxy "*" --max-time 1 "http://127.0.0.1:$p/"
35新增: [ $? -eq 7 ] || echo "listening=$p"
36新增: done
37新增:fi
2938exit 0
3039'
3140
32删除:# Ten host ports for <vm>'s editor, from its name: the same on every start,
33删除:# so the browser finds the saved password at the same address.
41新增:# Ten host ports for <vm>'s editor, from 20000 to 29999, from its name: the
42新增:# same on every start, so the browser finds the saved password at the same
43新增:# address while the first is free. VM names end with a hash (see
44新增:# _agent_vm_name): its last four digits start the ten, anywhere in the range,
45新增:# so two VMs rarely start at the same port.
3446_agent_vm_code_ports() {
35删除: local h base i
36删除: h="$(printf '%s' "$1" | _agent_vm_sha256 | cut -c1-4)"
47新增: local h="${1: -4}" base i
48新增: [[ "$h" =~ ^[0-9a-f]{4}$ ]] || h="$(printf '%s' "$1" | _agent_vm_sha256 | cut -c1-4)"
3749 [[ "$h" =~ ^[0-9a-f]{4}$ ]] || return 1
38删除: base=$((20000 + (16#$h % 1000) * 10))
50新增: base=$((20000 + 16#$h % 9991))
3951 for i in 0 1 2 3 4 5 6 7 8 9; do printf '%s ' $((base + i)); done
4052}
4153
@@ -58,12 +70,12 @@ _agent_vm_host_port_open() {
5870 (exec 3<>"/dev/tcp/127.0.0.1/$1") 2>/dev/null
5971}
6072
61删除:# The editor's <url> on <port>, its <password>, and a last line <note>, in a
62删除:# box. Safari leaves *.localhost to macOS, which may not resolve it:
63删除:# 127.0.0.1 then, in a window of its own.
73新增:# The address of <vm>'s editor on <port>, its <password>, and a last line
74新增:# <note>, in a box. Safari leaves *.localhost to macOS, which may not resolve
75新增:# it: 127.0.0.1 then, in a window of its own.
6476_agent_vm_code_say() {
6577 {
66删除: echo " Address: $1"
78新增: echo " Address: http://$(_agent_vm_code_host "$1"):$2/"
6779 echo " Password: $3"
6880 if [[ "$(uname -s)" == Darwin ]]; then
6981 echo ""
@@ -87,8 +99,7 @@ _agent_vm_code() {
8799}
88100
89101_agent_vm_code_session() {
90删除: local vm_name="$1" host_dir="$2" ports out line cfg="" pw="" running="" listening=" " port="" p
91删除: local url want_tty="" st=0
102新增: local vm_name="$1" host_dir="$2" ports out line cfg="" pw="" running="" port="" p want_tty=""
92103 ports="$(_agent_vm_code_ports "$vm_name")" || {
93104 echo "Error: cannot hash the VM name: install shasum or sha256sum." >&2
94105 return 1
@@ -108,7 +119,6 @@ _agent_vm_code_session() {
108119 config=*) cfg="${line#config=}" ;;
109120 password=*) pw="${line#password=}" ;;
110121 running=*) running="${line#running=}" ;;
111删除: listening=*) listening="$listening${line#listening=} " ;;
112122 esac
113123 done <<< "$out"
114124 # Printed to the terminal: nothing the VM wrote may carry escape sequences.
@@ -118,15 +128,14 @@ _agent_vm_code_session() {
118128 fi
119129
120130 if [[ -n "$running" ]]; then
121删除: url="http://$(_agent_vm_code_host "$vm_name"):$running/"
122删除: _agent_vm_code_say "$url" "$running" "$pw" "The editor of VM '$vm_name' already runs, from another terminal."
131新增: _agent_vm_code_say "$vm_name" "$running" "$pw" "The editor of VM '$vm_name' already runs, from another terminal."
123132 return 0
124133 fi
125134
126135 # The first port free both here and in the VM: Lima forwards the VM's port
127136 # to the same one here, and only when nothing holds it.
128137 for p in $ports; do
129删除: [[ "$listening" == *" $p "* ]] && continue
138新增: _agent_vm_has_line "$out" "listening=$p" && continue
130139 _agent_vm_host_port_open "$p" && continue
131140 port="$p"
132141 break
@@ -136,23 +145,22 @@ _agent_vm_code_session() {
136145 return 1
137146 fi
138147
139删除: url="http://$(_agent_vm_code_host "$vm_name"):$port/"
140删除: _agent_vm_code_say "$url" "$port" "$pw" "The password is kept in the VM, in $cfg. Ctrl-C stops the editor."
148新增: _agent_vm_code_say "$vm_name" "$port" "$pw" "The password is kept in the VM, in $cfg. Ctrl-C stops the editor."
141149 # A terminal for Ctrl-C to reach code-server: without one, it would keep
142150 # running in the VM once this command ends.
143151 [[ -t 0 && -t 1 ]] && want_tty=1
144152 # Bound to the VM's loopback, which Lima forwards to this machine's only.
145删除: # The cookie suffix keeps sessions apart at 127.0.0.1, where two editors
146删除: # would overwrite each other's cookie. --disable-proxy: no route from the
147删除: # browser to the VM's other ports, and the proxy is where CVE-2025-47269 was.
148删除: # The --vscode-option ones reach the VS Code server inside: no experiments,
149删除: # and the built-in Copilot Chat never loads (it updates itself otherwise).
150删除: # The settings written at setup do the rest (agent-vm.setup.sh).
151删除: # Claude Code's login pages open without the link protection prompt:
152删除: # these paths only, matched by segment (code-server 4.100+).
153删除: # VSCODE_PROXY_URI: links to localhost:<port> (or 127.0.0.1, 0.0.0.0) open
154删除: # at localhost:<port> here, where Lima forwards the VM's ports, instead of
155删除: # code-server's /proxy/<port>/, which --disable-proxy turns off.
153新增: # The cookie suffix keeps sessions apart at 127.0.0.1. --disable-proxy: no
154新增: # route from the browser to the VM's other ports; VSCODE_PROXY_URI sends a
155新增: # link to localhost:<port> to that port here instead. The --vscode-option
156新增: # ones: no experiments, and the built-in Copilot Chat never loads. Claude
157新增: # Code's login pages open without the link prompt, those paths only.
158新增: #
159新增: # Not a boundary between VMs: any VM can listen on a port Lima forwards to
160新增: # this machine, and a page it serves can send the browser, with this
161新增: # editor's cookie, to a host name it chose. Every VM can reach every
162新增: # other's editor; keeping them apart needs network isolation, which
163新增: # agent-vm does not have yet.
156164 _agent_vm_lima_run "$vm_name" "$host_dir" "$want_tty" \
157165 'VSCODE_PROXY_URI=http://localhost:{{port}}/' code-server \
158166 --config "$cfg" \
@@ -168,6 +176,5 @@ _agent_vm_code_session() {
168176 --link-protection-trusted-domains https://platform.claude.com/oauth \
169177 --vscode-option disable-experiments \
170178 --vscode-option disable-extension=GitHub.copilot-chat \
171删除: "$host_dir" || st=$?
172删除: return "$st"
179新增: "$host_dir"
173180}
修改lib/doctor.sh+19 −10看文件
@@ -229,9 +229,10 @@ _agent_vm_doctor() {
229229 done
230230
231231 echo ""
232删除: local host_dir vm_name vm_exists="" ro_names=""
232新增: local host_dir vm_name vm_exists="" ro_names="" scan
233233 host_dir="$(pwd)"
234删除: [[ -n "$protects_git" ]] && ro_names="$(_agent_vm_readonly_names "$host_dir")"
234新增: scan="$(_agent_vm_git_scan "$host_dir")"
235新增: [[ -n "$protects_git" ]] && ro_names="$(_agent_vm_readonly_names "$host_dir" "$scan")"
235236 echo "This directory ($host_dir)"
236237 local bad
237238 if bad="$(_agent_vm_unmountable_path "$host_dir")"; then
@@ -270,7 +271,14 @@ _agent_vm_doctor() {
270271 fi
271272 # What the VM was given, which may predate the Lima installed now:
272273 # the next start brings it in line (see _agent_vm_ensure_running).
273删除: if [[ -n "$protects_git" ]] && _agent_vm_mounts_protect_git "$vm_name" \
274新增: local prot_why=""
275新增: if _agent_vm_mounts_protect_git "$vm_name"; then
276新增: prot_why="$(_agent_vm_protection_why "$vm_name")" && prot_why=""
277新增: fi
278新增: if [[ -n "$prot_why" ]]; then
279新增: $d warn "its shares were given the read-only names, but .git is not read-only: $prot_why" \
280新增: "'agent-vm stop', then the next start says what to change."
281新增: elif [[ -n "$protects_git" ]] && _agent_vm_mounts_protect_git "$vm_name" \
274282 && ! _agent_vm_mounts_have_readonly_names "$vm_name" "$ro_names"; then
275283 $d warn "its shares keep .git read-only, but not all of $(_agent_vm_names_text "$ro_names")" \
276284 "The next start (after 'agent-vm stop' if it runs) fixes that."
@@ -288,15 +296,17 @@ _agent_vm_doctor() {
288296 fi
289297 fi
290298 # Hooks folders the VM can write, and git on this machine runs (see
291删除: # _agent_vm_project_hooks), in this project and the repositories below it.
299新增: # _agent_vm_git_scan), in this project, its writable volumes, and the
300新增: # repositories in them.
292301 local hooks_rel hooks_in hooks_name hooks_what
293302 while IFS=$'\t' read -r hooks_rel hooks_in; do
294303 [[ -n "$hooks_rel" ]] || continue
295304 hooks_what="git runs hooks from $hooks_rel (core.hooksPath)"
296305 [[ "$hooks_rel" == . ]] && hooks_what="git runs hooks from the project directory itself (core.hooksPath)"
306新增: [[ "$hooks_rel" != . && "$hooks_in" == . ]] && hooks_what="git runs hooks from $hooks_rel, a writable volume itself (core.hooksPath)"
297307 if ! hooks_name="$(_agent_vm_hooks_name "$hooks_in")"; then
298308 $d warn "$hooks_what, which the VM can write" \
299删除: "agent-vm can only keep a folder of the project read-only, by a name without quotes or backslashes: point core.hooksPath to one."
309新增: "agent-vm can only keep a folder inside a share read-only, by a name without quotes or backslashes: point core.hooksPath to one."
300310 elif [[ -z "$protects_git" ]]; then
301311 $d warn "$hooks_what, which the VM can write" \
302312 "agent-vm keeps it read-only when it keeps .git read-only (see above)."
@@ -308,15 +318,14 @@ _agent_vm_doctor() {
308318 $d warn "$hooks_what, which the VM can still write" \
309319 "The next start (after 'agent-vm stop' if it runs) makes every '$hooks_name' in the project read-only."
310320 fi
311删除: done <<< "$(_agent_vm_share_hooks "$host_dir")"
312删除: # Git config the VM can write, or commands it names in the project (see
313删除: # _agent_vm_repo_config_risks).
321新增: done <<< "$(_agent_vm_scan_part H "$scan")"
322新增: # Git config, commands and hooks the VM can write (see _agent_vm_git_scan).
314323 local git_risks
315删除: git_risks="$(_agent_vm_share_config_risks "$host_dir")"
324新增: git_risks="$(_agent_vm_scan_part R "$scan")"
316325 if [[ -n "$git_risks" ]]; then
317326 $d warn "git on this machine uses these, and the VM can write them:"
318327 printf '%s\n' "$git_risks" | sed 's/^/ /'
319删除: printf ' %s\n' "Move them out of the project, or have them name commands outside it."
328新增: printf ' %s\n' "Move them out of the shared folders, or have them name commands outside them."
320329 fi
321330 local runtime runtime_text runtime_rel project_env
322331 runtime="$(_agent_vm_project_runtime_path "$host_dir")"
修改lib/git.sh+346 −198看文件
@@ -68,25 +68,36 @@ _agent_vm_mounts_expr() {
6868# The names readonlyNames always lists, one per line. .hg: Mercurial runs the
6969# hooks of .hg/hgrc in a repository the user owns, which files written through
7070# a share are.
71新增:_AGENT_VM_BASE_NAMES=$'.git\n.hg'
7172_agent_vm_base_readonly_names() {
72删除: printf '%s\n' .git .hg
73新增: printf '%s\n' "$_AGENT_VM_BASE_NAMES"
7374}
7475
75删除:# 0 when the relative path <rel> goes through one of the names above, matched
76删除:# as the SFTP server does: per component, whatever the case.
76新增:# 0 when the relative path <rel> goes through one of <names> (one per line;
77新增:# the names above by default), matched as the SFTP server does: per
78新增:# component, whatever the case.
7779_agent_vm_under_readonly_name() {
78删除: local rest="$1/" c names
79删除: names=$'\n'"$(_agent_vm_base_readonly_names)"$'\n'
80新增: local rest="$1/" names=$'\n'"${2:-$_AGENT_VM_BASE_NAMES}"$'\n' c st=1 set_nocase=""
81新增: shopt -q nocasematch || { shopt -s nocasematch; set_nocase=1; }
8082 while [[ -n "$rest" ]]; do
81删除: c="$(printf '%s' "${rest%%/*}" | tr '[:upper:]' '[:lower:]')"
83新增: c="${rest%%/*}"
8284 rest="${rest#*/}"
83删除: [[ "$names" == *$'\n'"$c"$'\n'* ]] && return 0
85新增: if [[ -n "$c" && "$names" == *$'\n'"$c"$'\n'* ]]; then
86新增: st=0
87新增: break
88新增: fi
8489 done
85删除: return 1
90新增: [[ -z "$set_nocase" ]] || shopt -u nocasematch
91新增: return "$st"
8692}
8793
8894# 0 on the hosts whose file systems ignore case by default: macOS, Windows.
95新增:# A caller asking many times sets _agent_vm_nocase_memo to 1 or 0 first.
8996_agent_vm_fs_nocase() {
97新增: case "${_agent_vm_nocase_memo:-}" in
98新增: 1) return 0 ;;
99新增: 0) return 1 ;;
100新增: esac
90101 [[ "$(uname -s 2>/dev/null)" == Darwin ]] || _agent_vm_on_windows
91102}
92103
@@ -104,15 +115,20 @@ _agent_vm_fold() {
104115# Compared whatever the case where the file system ignores it, so a path
105116# spelled with other capitals is still found inside.
106117_agent_vm_rel_in() {
107删除: local target="${1%/}" dir="${2%/}" p d
108删除: p="$(_agent_vm_fold "$target")"
109删除: d="$(_agent_vm_fold "$dir")"
110删除: if [[ "$p" == "$d" ]]; then
118新增: local target="${1%/}" dir="${2%/}" st=1 set_nocase=""
119新增: if _agent_vm_fs_nocase && ! shopt -q nocasematch; then
120新增: shopt -s nocasematch
121新增: set_nocase=1
122新增: fi
123新增: if [[ "$target" == "$dir" ]]; then
111124 printf '.\n'
112删除: return 0
125新增: st=0
126新增: elif [[ -n "$dir" && "$target" == "$dir/"* ]]; then
127新增: printf '%s\n' "${target:$(( ${#dir} + 1 ))}"
128新增: st=0
113129 fi
114删除: [[ -n "$d" && "$p" == "$d/"* ]] || return 1
115删除: printf '%s\n' "${target:$(( ${#dir} + 1 ))}"
130新增: [[ -z "$set_nocase" ]] || shopt -u nocasematch
131新增: return "$st"
116132}
117133
118134# <dir> as git spells it: the physical path, C:/... on Windows.
@@ -132,103 +148,331 @@ _agent_vm_git_abs() {
132148 esac
133149}
134150
135删除:# The git repositories git on this machine uses in the project <dir>: the one
136删除:# holding <dir>, then those up to two levels below it (node_modules skipped),
137删除:# fifty at most. One directory per line, to run git in.
138删除:_agent_vm_project_repos() {
139删除: local dir="$1"
140删除: command -v git >/dev/null 2>&1 || return 0
141删除: _agent_vm_git_untrusted -C "$dir" rev-parse --git-dir >/dev/null 2>&1 && printf '%s\n' "$dir"
142删除: find "$dir" -mindepth 2 -maxdepth 3 \( -name node_modules -prune \) -o \( -name .git -print -prune \) 2>/dev/null \
143删除: | awk 'NR <= 50' | while IFS= read -r g; do
144删除: printf '%s\n' "${g%/.git}"
145删除: done
151新增:# --- what git on this machine runs from the shares -----------------------------
152新增:# The VM can write the project and the writable volumes. git on this machine
153新增:# runs hooks, and commands its config names, from paths anywhere: in the
154新增:# repository's own share, in another share (core.hooksPath into a volume), or
155新增:# from git's own config kept in one. Each path is followed through every
156新增:# symlink on the way, and checked against every share.
157新增:
158新增:# The folders the VM can write, one per line, in git's spelling (symlinks
159新增:# resolved): the project <dir> first, then its writable volumes (see
160新增:# _agent_vm_rw_volume_dirs), each once.
161新增:_agent_vm_writable_shares() {
162新增: local d
163新增: { printf '%s\n' "$1"; _agent_vm_rw_volume_dirs "$1"; } | while IFS= read -r d; do
164新增: [[ -z "$d" ]] || _agent_vm_git_spelling "$d"
165新增: done | awk '!seen[$0]++'
146166}
147167
148删除:# The folder git on the host runs the hooks of the repository at <repo> from,
149删除:# when core.hooksPath puts it in the project <proj> (in git's spelling) and
150删除:# outside the names above (husky sets .husky/_). Two fields, tab-separated:
151删除:# the folder relative to the project, "." for the project itself, then
152删除:# relative to the top of the repository when that is in the project (what
153删除:# names it: lib/x/.githooks is .githooks), or the same again. Fails otherwise,
154删除:# or when git cannot tell. `--git-path` without --path-format (git 2.31)
155删除:# answers relative to <repo>.
156删除:#
157删除:# The folder as named, and as it is on disk when a symlink takes it elsewhere
158删除:# (.git/hooks or a core.hooksPath linked to scripts/hooks): git runs what is
159删除:# in the folder the link points to. A line for each that needs a name.
160删除:_agent_vm_repo_hooks() {
161删除: local repo="$1" proj="$2" base top top_rel hooks phys h rel in_repo found=""
162删除: base="$(_agent_vm_git_spelling "$repo")" || return 1
163删除: hooks="$(_agent_vm_repo_hooks_dir "$repo")" || return 1
164删除: phys="$(_agent_vm_git_spelling "$hooks" 2>/dev/null)" || phys=""
165删除: [[ "$phys" != "$hooks" ]] || phys=""
166删除: top="$(_agent_vm_git_untrusted -C "$repo" rev-parse --show-toplevel 2>/dev/null)" || top=""
167删除: for h in "$hooks" ${phys:+"$phys"}; do
168删除: rel="$(_agent_vm_rel_in "$h" "$proj")" || continue
169删除: [[ "$rel" == . ]] || ! _agent_vm_under_readonly_name "$rel" || continue
170删除: in_repo="$rel"
171删除: if [[ -n "$top" ]] && top_rel="$(_agent_vm_rel_in "$top" "$proj")" && [[ "$top_rel" != . ]]; then
172删除: in_repo="$(_agent_vm_rel_in "$h" "$top")" || in_repo="$rel"
168新增:# Sets the caller's hit_share and hit_rel to the deepest of the caller's
169新增:# shares (one per line, in git's spelling) holding <path>, and <path>
170新增:# relative to it ("." for the share itself). Fails when none does. No
171新增:# subshell: it runs for every path a scan looks at.
172新增:_agent_vm_in_share() {
173新增: local t="${1%/}" s d r set_nocase=""
174新增: hit_share="" hit_rel=""
175新增: if _agent_vm_fs_nocase && ! shopt -q nocasematch; then
176新增: shopt -s nocasematch
177新增: set_nocase=1
178新增: fi
179新增: while IFS= read -r s; do
180新增: d="${s%/}"
181新增: [[ -n "$d" ]] || continue
182新增: if [[ "$t" == "$d" ]]; then
183新增: r=.
184新增: elif [[ "$t" == "$d/"* ]]; then
185新增: r="${t:$(( ${#d} + 1 ))}"
186新增: else
187新增: continue
173188 fi
174删除: printf '%s\t%s\n' "$rel" "$in_repo"
175删除: found=1
189新增: if [[ ${#d} -gt ${#hit_share} ]]; then
190新增: hit_share="$d"
191新增: hit_rel="$r"
192新增: fi
193新增: done <<< "$shares"
194新增: [[ -z "$set_nocase" ]] || shopt -u nocasematch
195新增: [[ -n "$hit_share" ]]
196新增:}
197新增:
198新增:# Every path the file system goes through to reach <path> (absolute, in
199新增:# git's spelling), one per line: <path>, the same with its folder's symlinks
200新增:# resolved, then the same again for the target of each symlink on the way,
201新增:# up to 40 links, whether the last one exists or not. A VM able to write any
202新增:# of them chooses what is found there.
203新增:_agent_vm_path_hops() {
204新增: local p="$1" d n=0 t
205新增: while :; do
206新增: printf '%s\n' "$p"
207新增: d="${p%/*}"
208新增: if d="$(_agent_vm_git_spelling "${d:-/}" 2>/dev/null)"; then
209新增: d="${d%/}/${p##*/}"
210新增: if [[ "$d" != "$p" ]]; then
211新增: p="$d"
212新增: printf '%s\n' "$p"
213新增: fi
214新增: fi
215新增: [[ -L "$p" ]] || return 0
216新增: n=$((n + 1))
217新增: [[ "$n" -le 40 ]] || return 0
218新增: t="$(readlink "$p")" || return 0
219新增: [[ "$t" != /* ]] || t="$(_agent_vm_host_path "$t")"
220新增: p="$(_agent_vm_git_abs "$t" "${p%/*}")"
176221 done
177删除: [[ -n "$found" ]]
178222}
179223
180删除:# The hooks folder of the repository at <repo>, absolute, in git's spelling,
181删除:# as git names it (symlinks not resolved). Fails when git cannot tell.
182删除:_agent_vm_repo_hooks_dir() {
183删除: local base hooks
184删除: base="$(_agent_vm_git_spelling "$1")" || return 1
185删除: hooks="$(_agent_vm_git_untrusted -C "$1" rev-parse --git-path hooks 2>/dev/null)" || return 1
186删除: [[ -n "$hooks" && "$hooks" != *$'\n'* && "$hooks" != *$'\t'* ]] || return 1
187删除: _agent_vm_git_abs "$hooks" "$base"
224新增:# git, for the repository <at> of kind <kind>: W a work tree, B a bare
225新增:# repository (named explicitly, as safe.bareRepository=explicit allows), G
226新增:# none, for git's own global and system config.
227新增:_agent_vm_git_at() {
228新增: local kind="$1" at="$2"
229新增: shift 2
230新增: case "$kind" in
231新增: W) _agent_vm_git_untrusted -C "$at" "$@" ;;
232新增: B) _agent_vm_git_untrusted --git-dir="$at" "$@" ;;
233新增: *) _agent_vm_git_untrusted -C / "$@" ;;
234新增: esac
188235}
189236
190删除:# <file> with every symlink resolved, the last component included, in git's
191删除:# spelling. Fails when it does not resolve (a dangling link, a loop).
192删除:_agent_vm_physical_file() {
193删除: local f="$1" t n=0 d
194删除: while [[ -L "$f" ]]; do
237新增:# The repositories git on this machine finds in the share <dir> (git's
238新增:# spelling), one per line, the kind before a tab (see _agent_vm_git_at): the
239新增:# one holding <dir>, then work trees and bare repositories up to two levels
240新增:# below it (node_modules skipped), 50 at most. X and <dir> when there are
241新增:# more: those are not checked.
242新增:_agent_vm_share_repos() {
243新增: local dir="$1" g n=0
244新增: _agent_vm_git_untrusted -C "$dir" rev-parse --git-dir >/dev/null 2>&1 && printf 'W\t%s\n' "$dir"
245新增: while IFS= read -r g; do
246新增: case "$g" in
247新增: */.git) g="${g%/.git}" ;;
248新增: */objects)
249新增: g="${g%/objects}"
250新增: [[ -f "$g/HEAD" && -d "$g/refs" ]] || continue ;;
251新增: *) continue ;;
252新增: esac
195253 n=$((n + 1))
196删除: [[ "$n" -le 40 ]] || return 1
197删除: t="$(readlink "$f")" || return 1
198删除: case "$t" in
199删除: /*) f="$t" ;;
200删除: *) f="$(dirname "$f")/$t" ;;
254新增: if [[ "$n" -gt 50 ]]; then
255新增: printf 'X\t%s\n' "$dir"
256新增: break
257新增: fi
258新增: if [[ -e "$g/.git" ]]; then printf 'W\t%s\n' "$g"; else printf 'B\t%s\n' "$g"; fi
259新增: done <<< "$(find "$dir/" -mindepth 2 -maxdepth 3 \( -name node_modules -prune \) \
260新增: -o \( -name .git -print -prune \) -o \( -name objects -type d -print -prune \) 2>/dev/null \
261新增: | sed 's#//*#/#g')"
262新增:}
263新增:
264新增:# The hooks folder of the repository <at> of kind <kind>, absolute, in git's
265新增:# spelling, as git names it: symlinks not resolved. For G, the absolute
266新增:# core.hooksPath git's own config sets for every repository. Fails when there
267新增:# is none, or git cannot tell. `--git-path` without --path-format (git 2.31)
268新增:# answers relative to where git runs.
269新增:#
270新增:# Two lines: the top of the work tree (empty but for W), then the folder.
271新增:_agent_vm_scan_hooks_dir() {
272新增: local hooks base=/ top=""
273新增: case "$1" in
274新增: G)
275新增: hooks="$(_agent_vm_git_at G / config --get core.hooksPath 2>/dev/null)" || return 1
276新增: [[ "$hooks" != "~/"* ]] || hooks="$home/${hooks#\~/}"
277新增: [[ "$hooks" == /* || "$hooks" == [A-Za-z]:/* ]] || return 1 ;;
278新增: W)
279新增: hooks="$(_agent_vm_git_at W "$2" rev-parse --show-toplevel --git-path hooks 2>/dev/null)" || return 1
280新增: [[ "$hooks" == *$'\n'* ]] || return 1
281新增: top="${hooks%%$'\n'*}"
282新增: hooks="${hooks#*$'\n'}"
283新增: base="$(_agent_vm_git_spelling "$2")" || return 1 ;;
284新增: *)
285新增: hooks="$(_agent_vm_git_at "$1" "$2" rev-parse --git-path hooks 2>/dev/null)" || return 1 ;;
286新增: esac
287新增: [[ -n "$hooks" && "$hooks" != *[$'\n\t']* && "$top" != *$'\t'* ]] || return 1
288新增: printf '%s\n' "$top"
289新增: _agent_vm_git_abs "$hooks" "$base"
290新增:}
291新增:
292新增:# 0 when one of the paths the file system goes through to reach <path> (see
293新增:# _agent_vm_path_hops) is in one of the caller's shares, outside the caller's
294新增:# names: the VM can choose what is found there. Sets the caller's shown to
295新增:# that path, relative to the project when it is there.
296新增:_agent_vm_scan_hit() {
297新增: local h hit_share hit_rel
298新增: [[ -n "$1" ]] || return 1
299新增: while IFS= read -r h; do
300新增: [[ -n "$h" ]] && _agent_vm_in_share "$h" || continue
301新增: _agent_vm_under_readonly_name "$hit_rel" "$names" && continue
302新增: shown="$h"
303新增: [[ "$hit_share" != "$proj" ]] || shown="$hit_rel"
304新增: return 0
305新增: done <<< "$(_agent_vm_path_hops "$1")"
306新增: return 1
307新增:}
308新增:
309新增:# A risk line of the scan: <text>, its control characters made visible.
310新增:_agent_vm_scan_risk() {
311新增: local t="$1"
312新增: printf 'R\t%s\n' "${t//[[:cntrl:]]/?}"
313新增:}
314新增:
315新增:# The risk lines of the config of the repository <at> of kind <kind>, whose
316新增:# work tree is <top> (see _agent_vm_git_at): its own config, or git's global
317新增:# and system config for G. Config files in a share, included ones whether
318新增:# they exist yet or not (git skips a missing one, and the VM can create it).
319新增:# Settings whose command a share holds: a path in their value, relative to
320新增:# the top of the repository, where git runs most of them (git's own config
321新增:# has none to take them from). awk sorts the config first, so the shell only
322新增:# sees each file once and the settings that hold a command (section and key
323新增:# names lowercased, as `git config --list` prints them) with a path in their
324新增:# value: a start runs this, and a fork per line would show.
325新增:_agent_vm_scan_config() {
326新增: local kind="$1" at="$2" cmd_base="$3" base=/ scope=--local k a b c w shown
327新增: case "$kind" in
328新增: W) base="$(_agent_vm_git_spelling "$at")" || return 0 ;;
329新增: B) cmd_base="$at" ;;
330新增: *) scope="" ;;
331新增: esac
332新增: _agent_vm_git_at "$kind" "$at" config --list ${scope:+"$scope"} --show-origin --includes 2>/dev/null \
333新增: | awk -F '\t' '
334新增: {
335新增: origin = $1; kv = substr($0, length($1) + 2); f = ""
336新增: if (origin ~ /^file:/) { f = substr(origin, 6); gsub(/^"|"$/, "", f) }
337新增: if (f != "" && !(f in seen)) { seen[f] = 1; print "O\t" f }
338新增: key = kv; sub(/=.*/, "", key); val = substr(kv, length(key) + 2); lk = tolower(key)
339新增: if (lk == "include.path" || lk ~ /^includeif\..*\.path$/) {
340新增: if (f != "") print "I\t" f "\t" val
341新增: next
342新增: }
343新增: if (lk !~ /^(core\.(fsmonitor|sshcommand|editor|pager|askpass|gitproxy|alternaterefscommand)|sequence\.editor|gpg\.program|gpg\..*\.program|diff\.external|diff\..*\.(command|textconv)|(difftool|mergetool|browser|man)\..*\.cmd|merge\..*\.driver|filter\..*\.(clean|smudge|process)|credential\.helper|credential\..*\.helper|pager\..*|alias\..*|interactive\.difffilter|uploadpack\.packobjectshook|web\.browser)$/) next
344新增: if (lk ~ /^alias\./ && val !~ /^!/) next
345新增: if (val ~ /\//) print "K\t" f "\t" key "\t" val
346新增: }' \
347新增: | while IFS=$'\t' read -r k a b c; do
348新增: case "$k" in
349新增: O)
350新增: _agent_vm_scan_hit "$(_agent_vm_git_abs "$a" "$base")" && _agent_vm_scan_risk "config file $shown" ;;
351新增: I)
352新增: # Relative to the file holding it, as git takes it.
353新增: [[ "$b" != "~/"* ]] || b="$home/${b#\~/}"
354新增: a="$(_agent_vm_git_abs "$a" "$base")"
355新增: _agent_vm_scan_hit "$(_agent_vm_git_abs "$b" "${a%/*}")" && _agent_vm_scan_risk "config file $shown" ;;
356新增: K)
357新增: # Word by word, through awk: an unquoted expansion would glob them.
358新增: printf '%s\n' "${c#!}" | awk '{ for (i = 1; i <= NF; i++) print $i }' \
359新增: | while IFS= read -r w; do
360新增: w="${w#[\"\']}"; w="${w%[\"\']}"
361新增: # Not an option, an assignment or a URL: a path.
362新增: [[ "$w" == */* && "$w" != -* && "$w" != *=* && "$w" != *://* ]] || continue
363新增: [[ "$w" != "~/"* ]] || w="$home/${w#\~/}"
364新增: [[ "$w" == /* || "$w" == [A-Za-z]:/* || -n "$cmd_base" ]] || continue
365新增: _agent_vm_scan_hit "$(_agent_vm_git_abs "$w" "$cmd_base")" || continue
366新增: _agent_vm_scan_risk "$b = $c"
367新增: break
368新增: done ;;
369新增: esac
370新增: done
371新增:}
372新增:
373新增:# What git on this machine runs, or reads, from the folders the VM can write
374新增:# (see _agent_vm_writable_shares) for the project <dir>: the repositories of
375新增:# each share and git's own config. One line each, its kind first, then
376新增:# tab-separated:
377新增:# - H: a hooks folder, or a link on the way to it, in a share and outside the
378新增:# names always listed. Where it is (relative to the project when it is
379新增:# there, else absolute), then what names it (see _agent_vm_hooks_name):
380新增:# relative to the top of its repository when that is in the share
381新增:# (lib/x/.githooks is .githooks), else to the share; "." for a share
382新增:# itself, empty for a name no share can carry.
383新增:# - R: a risk to accept, as text: a config file in a share, a setting whose
384新增:# command is in one, a hook linked to a file in one, a share with more
385新增:# repositories than are checked.
386新增:# What a name keeps read-only is no risk: the names always listed, and those
387新增:# of the hooks folders found here. Each line once.
388新增:_agent_vm_git_scan() {
389新增: command -v git >/dev/null 2>&1 || return 0
390新增: _agent_vm_git_scan_lines "$1" | awk '!seen[$0]++'
391新增:}
392新增:
393新增:_agent_vm_git_scan_lines() {
394新增: local shares proj home s kind at i n=0 hooks hp top h f t in_repo name shown
395新增: local hit_share hit_rel top_share top_rel names="$_AGENT_VM_BASE_NAMES"
396新增: local _agent_vm_windows_memo=0 _agent_vm_nocase_memo=0 kinds=() ats=() hookss=() tops=()
397新增: _agent_vm_on_windows && _agent_vm_windows_memo=1
398新增: _agent_vm_fs_nocase && _agent_vm_nocase_memo=1
399新增: shares="$(_agent_vm_writable_shares "$1")"
400新增: [[ -n "$shares" ]] || return 0
401新增: proj="${shares%%$'\n'*}"
402新增: home="$(_agent_vm_host_path "$HOME")"
403新增: while IFS=$'\t' read -r kind at; do
404新增: case "$kind" in
405新增: X)
406新增: shown="$at"
407新增: _agent_vm_in_share "$at" && [[ "$hit_share" == "$proj" ]] && shown="$hit_rel"
408新增: _agent_vm_scan_risk "more than 50 repositories in $shown: those after the 50th are not checked" ;;
409新增: W|B|G) kinds[n]="$kind"; ats[n]="$at"; n=$((n + 1)) ;;
201410 esac
411新增: done <<< "$(while IFS= read -r s; do _agent_vm_share_repos "$s"; done <<< "$shares"
412新增: printf 'G\t/\n')"
413新增: # The hooks folders first: their names keep what is under them read-only.
414新增: for ((i = 0; i < n; i++)); do
415新增: top="" hooks=""
416新增: if h="$(_agent_vm_scan_hooks_dir "${kinds[i]}" "${ats[i]}")"; then
417新增: top="${h%%$'\n'*}"
418新增: hooks="${h#*$'\n'}"
419新增: elif [[ "${kinds[i]}" == W ]]; then
420新增: top="$(_agent_vm_git_at W "${ats[i]}" rev-parse --show-toplevel 2>/dev/null)" || top=""
421新增: fi
422新增: hookss[i]="$hooks"
423新增: tops[i]="$top"
424新增: [[ -n "$hooks" ]] || continue
425新增: top_share="" top_rel=""
426新增: if [[ -n "$top" ]] && _agent_vm_in_share "$top"; then
427新增: top_share="$hit_share" top_rel="$hit_rel"
428新增: fi
429新增: while IFS= read -r h; do
430新增: [[ -n "$h" ]] && _agent_vm_in_share "$h" || continue
431新增: [[ "$hit_rel" == . ]] || ! _agent_vm_under_readonly_name "$hit_rel" || continue
432新增: in_repo="$hit_rel"
433新增: if [[ "$hit_share" == "$top_share" && "$top_rel" != . ]]; then
434新增: in_repo="$(_agent_vm_rel_in "$h" "$top")" || in_repo="$hit_rel"
435新增: fi
436新增: [[ "$in_repo" != *[[:cntrl:]]* ]] || in_repo=""
437新增: shown="$h"
438新增: [[ "$hit_share" != "$proj" ]] || shown="$hit_rel"
439新增: printf 'H\t%s\t%s\n' "${shown//[[:cntrl:]]/?}" "$in_repo"
440新增: if name="$(_agent_vm_hooks_name "$in_repo")"; then
441新增: names="$names"$'\n'"$name"
442新增: fi
443新增: done <<< "$(_agent_vm_path_hops "$hooks")"
202444 done
203删除: [[ -e "$f" ]] || return 1
204删除: d="$(_agent_vm_git_spelling "$(dirname "$f")")" || return 1
205删除: printf '%s/%s\n' "${d%/}" "$(basename "$f")"
206删除:}
207删除:
208删除:# Every hooks folder of the project <dir>'s repositories that is in the
209删除:# project and outside the names above (see _agent_vm_repo_hooks), one per
210删除:# line, with its two fields.
211删除:_agent_vm_project_hooks() {
212删除: local dir="$1" proj repo
213删除: proj="$(_agent_vm_git_spelling "$dir")" || return 0
214删除: _agent_vm_project_repos "$dir" | while IFS= read -r repo; do
215删除: _agent_vm_repo_hooks "$repo" "$proj"
216删除: done | awk '!seen[$0]++'
445新增: for ((i = 0; i < n; i++)); do
446新增: _agent_vm_scan_config "${kinds[i]}" "${ats[i]}" "${tops[i]}"
447新增: # A hook linked to a file a share holds: git runs that file, which may
448新增: # be outside every name.
449新增: hooks="${hookss[i]}"
450新增: [[ -n "$hooks" ]] && hp="$(_agent_vm_git_spelling "$hooks")" || continue
451新增: for f in "$hp"/*; do
452新增: [[ -L "$f" && "$f" != *.sample ]] || continue
453新增: t="$(readlink "$f")" || continue
454新增: [[ "$t" != /* ]] || t="$(_agent_vm_host_path "$t")"
455新增: _agent_vm_scan_hit "$(_agent_vm_git_abs "$t" "$hp")" && _agent_vm_scan_risk "hook ${f##*/} runs $shown"
456新增: done
457新增: done
458新增:}
459新增:
460新增:# The lines of kind <kind> (H or R) of a scan (see _agent_vm_git_scan), the
461新增:# kind dropped.
462新增:_agent_vm_scan_part() {
463新增: printf '%s\n' "$2" | awk -F '\t' -v k="$1" '$1 == k { print substr($0, length(k) + 2) }'
217464}
218465
219删除:# The same for the project <dir> and the writable volumes it gets (see
220删除:# _agent_vm_rw_volume_dirs): their names are read-only on every share, and
221删除:# git on this machine runs the hooks of a repository in a volume as much. A
222删除:# volume's folder is named by its path.
466新增:# The hooks folders of the project <dir>'s shares, as the H lines of the
467新增:# scan: where, then what names it, tab-separated.
223468_agent_vm_share_hooks() {
224删除: local v rel in_repo
225删除: _agent_vm_project_hooks "$1"
226删除: while IFS= read -r v; do
227删除: [[ -n "$v" ]] || continue
228删除: while IFS=$'\t' read -r rel in_repo; do
229删除: [[ -n "$rel" ]] && printf '%s\t%s\n' "${v%/}/$rel" "$in_repo"
230删除: done <<< "$(_agent_vm_project_hooks "$v")"
231删除: done <<< "$(_agent_vm_rw_volume_dirs "$1")"
469新增: _agent_vm_scan_part H "$(_agent_vm_git_scan "$1")"
470新增:}
471新增:
472新增:# The risks to accept for the project <dir>'s shares, as the R lines of the
473新增:# scan.
474新增:_agent_vm_share_config_risks() {
475新增: _agent_vm_scan_part R "$(_agent_vm_git_scan "$1")"
232476}
233477
234478# The name that keeps the hooks folder <rel> read-only: its first component,
@@ -254,13 +498,14 @@ _agent_vm_names_json() {
254498
255499# The readonlyNames JSON array a start gives the project <dir> unless the user
256500# declines a name: the names always listed, and those keeping its hooks
257删除:# folders read-only.
501新增:# folders read-only. From <scan> (see _agent_vm_git_scan) when given.
258502_agent_vm_readonly_names() {
259删除: local rel in_repo name names=()
503新增: local rel in_repo name names=() scan
504新增: if [[ $# -ge 2 ]]; then scan="$2"; else scan="$(_agent_vm_git_scan "$1")"; fi
260505 while IFS=$'\t' read -r rel in_repo; do
261506 [[ -n "$rel" ]] || continue
262507 name="$(_agent_vm_hooks_name "$in_repo")" && names+=("$name")
263删除: done <<< "$(_agent_vm_share_hooks "$1")"
508新增: done <<< "$(_agent_vm_scan_part H "$scan")"
264509 _agent_vm_names_json ${names[@]+"${names[@]}"}
265510}
266511
@@ -275,103 +520,6 @@ _agent_vm_hooks_note() {
275520 echo "Note: git runs hooks from $1 (core.hooksPath): every '$2' in the project is read-only for the VM too."
276521}
277522
278删除:# What git on this machine takes from files the VM can write, for the
279删除:# repository at <repo> in the project <proj> (git's spelling), one line each:
280删除:# a config file included from the project (whether it exists yet or not),
281删除:# and a setting whose command names
282删除:# a file in the project. The protected names are excepted, and core.hooksPath,
283删除:# which _agent_vm_repo_hooks covers. A relative path in a command is taken
284删除:# from the top of the repository, where git runs most of them.
285删除:#
286删除:# awk sorts the config first, so the shell only sees each file once and the
287删除:# settings that hold a command (section and key names lowercased, as
288删除:# `git config --list` prints them) with a path in their value: a start runs
289删除:# this, and a fork per line would show.
290删除:_agent_vm_repo_config_risks() {
291删除: local repo="$1" proj="$2" base top kind a b w rel hooks f p
292删除: base="$(_agent_vm_git_spelling "$repo")" || return 0
293删除: top="$(_agent_vm_git_untrusted -C "$repo" rev-parse --show-toplevel 2>/dev/null)" || return 0
294删除: _agent_vm_git_untrusted -C "$repo" config --list --show-origin --includes 2>/dev/null \
295删除: | awk -F '\t' '
296删除: {
297删除: origin = $1; kv = substr($0, length($1) + 2)
298删除: if (origin ~ /^file:/ && !(origin in seen)) {
299删除: seen[origin] = 1; f = substr(origin, 6); gsub(/^"|"$/, "", f); print "O\t" f
300删除: }
301删除: key = kv; sub(/=.*/, "", key); val = substr(kv, length(key) + 2); lk = tolower(key)
302删除: if (lk == "include.path" || lk ~ /^includeif\..*\.path$/) {
303删除: if (origin ~ /^file:/) { f = substr(origin, 6); gsub(/^"|"$/, "", f); print "I\t" f "\t" val }
304删除: next
305删除: }
306删除: if (lk !~ /^(core\.(fsmonitor|sshcommand|editor|pager|askpass|gitproxy|alternaterefscommand)|sequence\.editor|gpg\.program|gpg\..*\.program|diff\.external|diff\..*\.(command|textconv)|(difftool|mergetool|browser|man)\..*\.cmd|merge\..*\.driver|filter\..*\.(clean|smudge|process)|credential\.helper|credential\..*\.helper|pager\..*|alias\..*|interactive\.difffilter|uploadpack\.packobjectshook|web\.browser)$/) next
307删除: if (lk ~ /^alias\./ && val !~ /^!/) next
308删除: if (val ~ /\//) print "K\t" key "\t" val
309删除: }' \
310删除: | while IFS=$'\t' read -r kind a b; do
311删除: if [[ "$kind" == O ]]; then
312删除: rel="$(_agent_vm_rel_in "$(_agent_vm_git_abs "$a" "$base")" "$proj")" \
313删除: && ! _agent_vm_under_readonly_name "$rel" \
314删除: && printf 'config file %s\n' "$rel"
315删除: continue
316删除: fi
317删除: # An include, by its value: git skips a file that does not exist, so
318删除: # --includes does not list it, and the VM can create it once the VM
319删除: # runs. Relative to the file holding it, as git takes it.
320删除: if [[ "$kind" == I ]]; then
321删除: [[ "$b" == "~/"* ]] && b="$HOME/${b#\~/}"
322删除: a="$(_agent_vm_git_abs "$a" "$base")"
323删除: rel="$(_agent_vm_rel_in "$(_agent_vm_git_abs "$b" "${a%/*}")" "$proj")" \
324删除: && ! _agent_vm_under_readonly_name "$rel" \
325删除: && printf 'config file %s\n' "$rel"
326删除: continue
327删除: fi
328删除: # Word by word, through awk: an unquoted expansion would glob them.
329删除: printf '%s\n' "${b#!}" | awk '{ for (i = 1; i <= NF; i++) print $i }' \
330删除: | while IFS= read -r w; do
331删除: w="${w#[\"\']}"; w="${w%[\"\']}"
332删除: # Not an option, an assignment or a URL: a path.
333删除: [[ "$w" == */* && "$w" != -* && "$w" != *=* && "$w" != *://* ]] || continue
334删除: [[ "$w" == "~/"* ]] && w="$HOME/${w#\~/}"
335删除: rel="$(_agent_vm_rel_in "$(_agent_vm_git_abs "$w" "$top")" "$proj")" || continue
336删除: _agent_vm_under_readonly_name "$rel" && continue
337删除: printf '%s = %s\n' "$a" "$b"
338删除: break
339删除: done
340删除: done
341删除: # A hook that is a symlink to a file of the project: git runs that file,
342删除: # which no name keeps read-only, from a hooks folder that is.
343删除: hooks="$(_agent_vm_repo_hooks_dir "$repo")" || return 0
344删除: for f in "$hooks"/*; do
345删除: [[ -L "$f" && "$f" != *.sample ]] || continue
346删除: p="$(_agent_vm_physical_file "$f")" || continue
347删除: rel="$(_agent_vm_rel_in "$p" "$proj")" || continue
348删除: _agent_vm_under_readonly_name "$rel" && continue
349删除: printf 'hook %s runs %s\n' "${f##*/}" "$rel"
350删除: done
351删除:}
352删除:
353删除:# The same for every repository of the project <dir>, each line once.
354删除:_agent_vm_project_config_risks() {
355删除: local dir="$1" proj repo
356删除: proj="$(_agent_vm_git_spelling "$dir")" || return 0
357删除: _agent_vm_project_repos "$dir" | while IFS= read -r repo; do
358删除: _agent_vm_repo_config_risks "$repo" "$proj"
359删除: done | awk '!seen[$0]++'
360删除:}
361删除:
362删除:# The same for the project <dir> and its writable volumes, a volume's lines
363删除:# after its path.
364删除:_agent_vm_share_config_risks() {
365删除: local v line
366删除: _agent_vm_project_config_risks "$1"
367删除: while IFS= read -r v; do
368删除: [[ -n "$v" ]] || continue
369删除: while IFS= read -r line; do
370删除: [[ -n "$line" ]] && printf '%s: %s\n' "$v" "$line"
371删除: done <<< "$(_agent_vm_project_config_risks "$v")"
372删除: done <<< "$(_agent_vm_rw_volume_dirs "$1")"
373删除:}
374删除:
375523# What a Lima without readonlyNames exposes when the shares are reverse-sshfs
376524# (see _agent_vm_unprotected_mount_is_sshfs), one paragraph, before
377525# _agent_vm_git_protection_hint.
修改lib/help.sh+12 −6看文件
@@ -141,18 +141,24 @@ where you stand.
141141
142142Before a VM boots with writable shares, agent-vm stops on what it cannot
143143protect, and asks whether to go on (no by default, and when it cannot ask):
144删除:a Lima without readonlyNames, hooks at the top of the project, git config or
145删除:commands it names in files of the project, and git ignoring
146删除:safe.bareRepository=explicit (which it offers to set: git would otherwise use
147删除:a folder with HEAD, objects/ and refs/ as a repository, under any name). A
148删除:VM that already runs gets the warnings only, and a restart when it lacks a
149删除:protection; once stopped to boot again, it is asked like any other.
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,
149新增:and a restart when it lacks a protection; once stopped to boot again, it is
150新增:asked like any other.
150151'agent-vm info' lists what a start would ask
151152(security_questions=).
152153--unsafe-writable-git, or AGENT_VM_UNSAFE_WRITABLE_GIT=1 in your shell, leaves
153154.git writable anyway, so the agent can commit in the project; a warning is
154155printed on every run. Changing it applies when the VM is next started.
155156
157新增:The writable shares are served without sshfs's cache, so the VM never writes
158新增:back a file as it was before you changed it. AGENT_VM_SSHFS_CACHE=1 in your
159新增:shell turns the cache on, faster on many files (git status, find), at that
160新增:risk, for 20 seconds. It applies when a VM is next started.
161新增:
156162Customization:
157163 ~/.agent-vm/env Shared env vars / tokens (dotenv-style;
158164 pushed into every VM, loaded in its shells)
修改lib/host.sh+10 −0看文件
@@ -162,6 +162,11 @@ _agent_vm_check_linux_prereqs() {
162162# 0 when running on Windows (Git Bash, MSYS2 or Cygwin), as reported by
163163# uname: MINGW64_NT-..., MSYS_NT-... or CYGWIN_NT-....
164164_agent_vm_on_windows() {
165新增: # A caller asking many times sets _agent_vm_windows_memo to 1 or 0 first.
166新增: case "${_agent_vm_windows_memo:-}" in
167新增: 1) return 0 ;;
168新增: 0) return 1 ;;
169新增: esac
165170 case "$(uname -s 2>/dev/null)" in
166171 MINGW*|MSYS*|CYGWIN*) return 0 ;;
167172 *) return 1 ;;
@@ -197,6 +202,11 @@ _agent_vm_lima_home() {
197202 printf '%s\n' "${LIMA_HOME:-$HOME/.lima}"
198203}
199204
205新增:# The log of <vm>'s Lima host agent, which says why it did not start.
206新增:_agent_vm_ha_log() {
207新增: printf '%s/%s/ha.stderr.log\n' "$(_agent_vm_lima_home)" "$1"
208新增:}
209新增:
200210# WSL generation from the kernel release: prints 2 or 1, or nothing when not
201211# on WSL. Only meaningful on Linux (WSL1 reports Microsoft without WSL2).
202212_agent_vm_wsl_version() {
修改lib/info.sh+4 −2看文件
@@ -175,14 +175,16 @@ _agent_vm_info() {
175175 esac
176176 fi
177177 if [[ "$protected" == 1 ]]; then
178新增: local scan
179新增: scan="$(_agent_vm_git_scan "$dir")"
178180 while IFS=$'\t' read -r rel in_repo; do
179181 [[ -n "$rel" ]] || continue
180182 if ! _agent_vm_hooks_name "$in_repo" >/dev/null; then
181183 questions="${questions:+$questions,}hooks"
182184 break
183185 fi
184删除: done <<< "$(_agent_vm_share_hooks "$dir")"
185删除: [[ -z "$(_agent_vm_share_config_risks "$dir")" ]] || questions="${questions:+$questions,}git-config"
186新增: done <<< "$(_agent_vm_scan_part H "$scan")"
187新增: [[ -z "$(_agent_vm_scan_part R "$scan")" ]] || questions="${questions:+$questions,}git-config"
186188 fi
187189 case "$(_agent_vm_bare_repo_state)" in
188190 unset|old) questions="${questions:+$questions,}bare-repo" ;;
修改lib/mounts.sh+262 −148看文件
@@ -84,13 +84,19 @@ _agent_vm_project_mountpoint() {
8484
8585# The entries of ~/.agent-vm/volumes for the project <dir>, one per line,
8686# four fields separated by |, which none can hold: source (~ expanded,
87删除:# existing), destination (as written, maybe empty or relative), mode (ro or
88删除:# rw), and the entry as source:destination:mode, for messages. Entries that
89删除:# cannot be used are skipped, with a warning unless <quiet> is set. Nothing
90删除:# is created: that is _agent_vm_build_mounts_json's.
87新增:# existing), destination (absolute and normalized, relative as written, or
88新增:# empty for the source's own path), mode (ro or rw), and the entry as
89新增:# source:destination:mode, for messages. Entries that cannot be used are
90新增:# skipped, with a warning on stderr. Nothing is created: that is
91新增:# _agent_vm_build_mounts_json's.
9192_agent_vm_volume_entries() {
92删除: local host_dir="$1" quiet="${2:-}" raw line mounts_file="$AGENT_VM_STATE_DIR/volumes"
93新增: local host_dir="$1" raw line mounts_file="$AGENT_VM_STATE_DIR/volumes" why mp proj_mp seen_mps=$'\n'
9394 [[ -f "$mounts_file" ]] || return 0
95新增: local _agent_vm_unsafe_refs _agent_vm_windows_memo=0 _agent_vm_nocase_memo=0
96新增: _agent_vm_on_windows && _agent_vm_windows_memo=1
97新增: _agent_vm_fs_nocase && _agent_vm_nocase_memo=1
98新增: _agent_vm_unsafe_refs="$(_agent_vm_unsafe_ref_dirs)"
99新增: proj_mp="$(_agent_vm_path_join / "$host_dir")"
94100 while IFS= read -r raw || [[ -n "$raw" ]]; do
95101 line="${raw%%#*}" # strip comments
96102 line="${line#"${line%%[![:space:]]*}"}" # trim leading whitespace
@@ -99,7 +105,7 @@ _agent_vm_volume_entries() {
99105 # A control character (a tab, an ESC...) is invalid unescaped in the JSON
100106 # handed to limactl. The CR of a CRLF file went with the trim above.
101107 if [[ "$line" == *[[:cntrl:]]* ]]; then
102删除: _agent_vm_volume_warn "$quiet" "Mount entry '${raw}' (from ~/.agent-vm/volumes) contains a control character, skipping."
108新增: echo "Warning: Mount entry '${raw}' (from ~/.agent-vm/volumes) contains a control character, skipping." >&2
103109 continue
104110 fi
105111 # An optional 4th field, after an explicit mode, limits the entry to the
@@ -114,14 +120,10 @@ _agent_vm_volume_entries() {
114120 fi
115121 if [[ -n "$has_filter" ]]; then
116122 if [[ -z "$filter" ]]; then
117删除: _agent_vm_volume_warn "$quiet" "Mount entry '${raw}' (from ~/.agent-vm/volumes) has an empty project filter; refusing to mount it in every project. Skipping."
123新增: echo "Warning: Mount entry '${raw}' (from ~/.agent-vm/volumes) has an empty project filter; refusing to mount it in every project. Skipping." >&2
118124 continue
119125 fi
120删除: if [[ -n "$quiet" ]]; then
121删除: _agent_vm_volume_matches "$filter" "$host_dir" 2>/dev/null || continue
122删除: else
123删除: _agent_vm_volume_matches "$filter" "$host_dir" || continue
124删除: fi
126新增: _agent_vm_volume_matches "$filter" "$host_dir" || continue
125127 fi
126128 # Parse source[:destination][:mode] syntax (like docker compose volumes).
127129 # The trailing mode segment is only recognized when it equals "ro" or
@@ -142,49 +144,57 @@ _agent_vm_volume_entries() {
142144 # (`src:dst:/p:rw`), a second mode, a fifth field. Read as a destination,
143145 # the entry would be mounted in every project, the project filter lost.
144146 if [[ "$dst" == *:* ]]; then
145删除: _agent_vm_volume_warn "$quiet" "Mount entry '${raw}' (from ~/.agent-vm/volumes) does not read as source:destination:mode:project (the mode goes before the project, and is needed with one). Skipping."
147新增: echo "Warning: Mount entry '${raw}' (from ~/.agent-vm/volumes) does not read as source:destination:mode:project (the mode goes before the project, and is needed with one). Skipping." >&2
146148 continue
147149 fi
148150 src="${src/#\~/$HOME}" # expand ~
149删除: # Reject characters that would break JSON interpolation below or the
150删除: # pipe-separated cache format used for file mounts.
151新增: # Reject characters that would break the mounts JSON or the |-separated
152新增: # lines this prints and the file mounts cache.
151153 if [[ "$src" == *[$'"\\\n|']* || "$dst" == *[$'"\\\n|']* ]]; then
152删除: _agent_vm_volume_warn "$quiet" "Mount entry '${raw}' (from ~/.agent-vm/volumes) contains invalid characters (quote/backslash/newline/pipe), skipping."
154新增: echo "Warning: Mount entry '${raw}' (from ~/.agent-vm/volumes) contains invalid characters (quote/backslash/newline/pipe), skipping." >&2
153155 continue
154156 fi
155157 if [[ ! -e "$src" ]]; then
156删除: _agent_vm_volume_warn "$quiet" "Mount path '${src}' (from ~/.agent-vm/volumes) does not exist, skipping."
158新增: echo "Warning: Mount path '${src}' (from ~/.agent-vm/volumes) does not exist, skipping." >&2
159新增: continue
160新增: fi
161新增: # What is refused as a project, refused as a volume (see
162新增: # _agent_vm_unsafe_project), a repository's own folder only when the VM
163新增: # could write it.
164新增: if why="$(_agent_vm_unsafe_location "$src")" \
165新增: || { [[ "$mode" == rw && -d "$src" ]] && why="$(_agent_vm_git_dir_share "$src")"; }; then
166新增: echo "Warning: Mount path '${src}' (from ~/.agent-vm/volumes) $why, skipping." >&2
157167 continue
158168 fi
159删除: # What is refused as a project, refused as a volume: agent-vm's state
160删除: # (the VM could add a share for its next start), Lima's, the home folder.
161删除: local why
162删除: if why="$(_agent_vm_unsafe_project "$src")"; then
163删除: _agent_vm_volume_warn "$quiet" "Mount path '${src}' (from ~/.agent-vm/volumes) $why, skipping."
169新增: # Where the VM sees it: the destination, or the source's own path, as
170新增: # Lima takes it. At the project or above it, it would hide the project's
171新增: # share. At another entry's place, Lima would merge the two into one
172新增: # share, with the second one's mode.
173新增: mp="${dst:-$src}"
174新增: [[ "$mp" == /* ]] || mp="$host_dir/$mp"
175新增: mp="$(_agent_vm_path_join / "$mp")"
176新增: [[ -z "$dst" || "$dst" != /* ]] || dst="$mp"
177新增: if [[ "${proj_mp%/}/" == "${mp%/}/"* ]]; then
178新增: echo "Warning: Mount entry '${entry}' (from ~/.agent-vm/volumes) would be mounted at $mp, which covers the project, skipping." >&2
164179 continue
165180 fi
166删除: # Mounted at the project, or above it, it would hide the project's share.
167删除: if [[ "$dst" == /* && "${host_dir%/}/" == "${dst%/}/"* ]]; then
168删除: _agent_vm_volume_warn "$quiet" "Mount destination '${dst}' (from ~/.agent-vm/volumes) would cover the project, skipping."
181新增: if [[ "$seen_mps" == *$'\n'"$mp"$'\n'* ]]; then
182新增: echo "Warning: Mount entry '${entry}' (from ~/.agent-vm/volumes) would be mounted at $mp, as an entry before it, skipping." >&2
169183 continue
170184 fi
185新增: seen_mps="$seen_mps$mp"$'\n'
171186 printf '%s|%s|%s|%s\n' "$src" "$dst" "$mode" "$entry"
172187 done < "$mounts_file"
173188}
174189
175删除:# A warning about ~/.agent-vm/volumes, unless <quiet> is set.
176删除:_agent_vm_volume_warn() {
177删除: [[ -n "$1" ]] || echo "Warning: $2" >&2
178删除:}
179删除:
180190# The writable directories of ~/.agent-vm/volumes for the project <dir>, one
181191# per line: shares the VM can write besides the project. Read quietly: the
182192# start that mounts them says what is wrong with an entry.
183193_agent_vm_rw_volume_dirs() {
184194 local src dst mode entry
185195 while IFS='|' read -r src dst mode entry; do
186删除: [[ "$mode" == rw && -d "$src" && ! -f "$src" ]] && printf '%s\n' "$src"
187删除: done <<< "$(_agent_vm_volume_entries "$1" 1)"
196新增: [[ "$mode" == rw && -d "$src" ]] && printf '%s\n' "$src"
197新增: done <<< "$(_agent_vm_volume_entries "$1" 2>/dev/null)"
188198}
189199
190200# _agent_vm_build_mounts_json <vm> <dir> [<writable>] [<names>]: the .mounts
@@ -203,69 +213,77 @@ _agent_vm_rw_volume_dirs() {
203213# there and listed in ~/.agent-vm/.agent-vm-file-mounts-<vm> for the bind in
204214# the VM.
205215_agent_vm_build_mounts_json() {
206删除: local vm_name="$1" host_dir="$2" project_writable="${3:-true}" sshfs=""
207删除: # cache: false, sshfs's -o cache=no: with its cache, a file the host adds,
208删除: # deletes or extends shows as it was for up to 20 seconds, and an agent
209删除: # writing back what it read would undo the host's change.
216新增: local vm_name="$1" host_dir="$2" project_writable="${3:-true}" names="" sshfs_ro="" sshfs_rw=""
210217 case "${4:-}" in
211删除: 1) sshfs=", \"sshfs\": {\"sftpDriver\": \"builtin\", \"cache\": false, \"readonlyNames\": $(_agent_vm_readonly_names "$host_dir")}" ;;
212删除: \[*) sshfs=", \"sshfs\": {\"sftpDriver\": \"builtin\", \"cache\": false, \"readonlyNames\": $4}" ;;
218新增: 1) names="$(_agent_vm_readonly_names "$host_dir")" ;;
219新增: \[*) names="$4" ;;
213220 esac
221新增: # sshfs's cache (cache: false is -o cache=no): with it, a file the host
222新增: # adds, deletes or extends shows as it was for up to 20 seconds, and an
223新增: # agent writing back what it read would undo the host's change. Off on the
224新增: # writable shares (see _agent_vm_sshfs_cache_mode).
225新增: if [[ -n "$names" ]]; then
226新增: sshfs_ro=", \"sshfs\": {\"sftpDriver\": \"builtin\", \"readonlyNames\": $names}"
227新增: sshfs_rw="$sshfs_ro"
228新增: [[ "$(_agent_vm_sshfs_cache_mode)" == on ]] \
229新增: || sshfs_rw=", \"sshfs\": {\"sftpDriver\": \"builtin\", \"cache\": false, \"readonlyNames\": $names}"
230新增: fi
231新增: local sshfs="$sshfs_ro"
232新增: [[ "$project_writable" != true ]] || sshfs="$sshfs_rw"
214233 # Every entry names its mount point: agent-vm addresses the guest side by the
215234 # shell's spelling of the path (--workdir, the write probe), which on Windows
216235 # is not the C:/... form Lima reads the location in.
217236 local mounts_json="[{\"location\": \"$(_agent_vm_host_path "$host_dir")\", \"mountPoint\": \"${host_dir}\", \"writable\": ${project_writable}${sshfs}}"
218删除: local mounts_file="$AGENT_VM_STATE_DIR/volumes"
219237 local file_mount_entries=()
220238 local file_mounts_cache="$AGENT_VM_STATE_DIR/.agent-vm-file-mounts-${vm_name}"
221239
222删除: if [[ -f "$mounts_file" ]]; then
223删除: local staging_idx=0 src dst mode line
224删除: while IFS='|' read -r src dst mode line; do
225删除: [[ -n "$src" ]] || continue
226删除: if [[ -n "$dst" && "$dst" != /* ]]; then
227删除: dst="$(_agent_vm_project_mountpoint "$host_dir" "$dst" "$src")" || continue
228删除: fi
229删除: if [[ -f "$src" ]]; then
230删除: if [[ "$mode" == "rw" ]]; then
231删除: echo "Warning: Mount entry '${line}' (from ~/.agent-vm/volumes) requests rw on a file; only directories support rw. Mount the parent directory instead. Skipping." >&2
232删除: continue
233删除: fi
234删除: # File mount: hardlink the source into a per-VM host staging dir so
235删除: # the VM sees only this file (never the source's parent). Lima mounts
236删除: # the staging dir; a bind mount inside the VM (applied after boot)
237删除: # exposes the file at its final destination.
238删除: local filename=""
239删除: filename="$(basename "$src")"
240删除: local file_staging_dir="$AGENT_VM_STATE_DIR/file-mounts/${vm_name}/${staging_idx}"
241删除: local host_staging="${file_staging_dir}/${filename}"
242删除: if ! _agent_vm_stage_file "$src" "$host_staging"; then
243删除: echo "Warning: Failed to stage '${src}', skipping." >&2
244删除: rm -rf "$file_staging_dir"
245删除: continue
246删除: fi
247删除: local staging_mount="/tmp/.agent-vm-file-mounts/${staging_idx}"
248删除: local bind_dst="${dst:-${src}}"
249删除: file_mount_entries+=("${src}|${host_staging}|${staging_mount}/${filename}|${bind_dst}")
250删除: mounts_json+=", {\"location\": \"$(_agent_vm_host_path "$file_staging_dir")\", \"mountPoint\": \"${staging_mount}\", \"writable\": false${sshfs}}"
251删除: staging_idx=$((staging_idx + 1))
240新增: local staging_idx=0 src dst mode line
241新增: while IFS='|' read -r src dst mode line; do
242新增: [[ -n "$src" ]] || continue
243新增: if [[ -n "$dst" && "$dst" != /* ]]; then
244新增: dst="$(_agent_vm_project_mountpoint "$host_dir" "$dst" "$src")" || continue
245新增: fi
246新增: if [[ -f "$src" ]]; then
247新增: if [[ "$mode" == "rw" ]]; then
248新增: echo "Warning: Mount entry '${line}' (from ~/.agent-vm/volumes) requests rw on a file; only directories support rw. Mount the parent directory instead. Skipping." >&2
252249 continue
253250 fi
254删除: if [[ ! -d "$src" ]]; then
255删除: echo "Warning: Mount path '${src}' (from ~/.agent-vm/volumes) is not a regular file or directory, skipping." >&2
251新增: # File mount: hardlink the source into a per-VM host staging dir so
252新增: # the VM sees only this file (never the source's parent). Lima mounts
253新增: # the staging dir; a bind mount inside the VM (applied after boot)
254新增: # exposes the file at its final destination.
255新增: local filename=""
256新增: filename="$(basename "$src")"
257新增: local file_staging_dir="$AGENT_VM_STATE_DIR/file-mounts/${vm_name}/${staging_idx}"
258新增: local host_staging="${file_staging_dir}/${filename}"
259新增: if ! _agent_vm_stage_file "$src" "$host_staging"; then
260新增: echo "Warning: Failed to stage '${src}', skipping." >&2
261新增: rm -rf "$file_staging_dir"
256262 continue
257263 fi
258删除: local writable="false"
259删除: if [[ "$mode" == "rw" ]]; then
260删除: if [[ "$project_writable" == "true" ]]; then
261删除: writable="true"
262删除: else
263删除: echo "Note: --readonly: '${src}' (rw in ~/.agent-vm/volumes) is mounted read-only too." >&2
264删除: fi
264新增: local staging_mount="/tmp/.agent-vm-file-mounts/${staging_idx}"
265新增: local bind_dst="${dst:-${src}}"
266新增: file_mount_entries+=("${src}|${host_staging}|${staging_mount}/${filename}|${bind_dst}")
267新增: mounts_json+=", {\"location\": \"$(_agent_vm_host_path "$file_staging_dir")\", \"mountPoint\": \"${staging_mount}\", \"writable\": false${sshfs_ro}}"
268新增: staging_idx=$((staging_idx + 1))
269新增: continue
270新增: fi
271新增: if [[ ! -d "$src" ]]; then
272新增: echo "Warning: Mount path '${src}' (from ~/.agent-vm/volumes) is not a regular file or directory, skipping." >&2
273新增: continue
274新增: fi
275新增: local writable="false"
276新增: if [[ "$mode" == "rw" ]]; then
277新增: if [[ "$project_writable" == "true" ]]; then
278新增: writable="true"
279新增: else
280新增: echo "Note: --readonly: '${src}' (rw in ~/.agent-vm/volumes) is mounted read-only too." >&2
265281 fi
266删除: mounts_json+=", {\"location\": \"$(_agent_vm_host_path "$src")\", \"mountPoint\": \"${dst:-$src}\", \"writable\": ${writable}${sshfs}}"
267删除: done <<< "$(_agent_vm_volume_entries "$host_dir")"
268删除: fi
282新增: fi
283新增: sshfs="$sshfs_ro"
284新增: [[ "$writable" != true ]] || sshfs="$sshfs_rw"
285新增: mounts_json+=", {\"location\": \"$(_agent_vm_host_path "$src")\", \"mountPoint\": \"${dst:-$src}\", \"writable\": ${writable}${sshfs}}"
286新增: done <<< "$(_agent_vm_volume_entries "$host_dir")"
269287 mounts_json+="]"
270288
271289 rm -f "$file_mounts_cache"
@@ -283,80 +301,174 @@ _agent_vm_build_mounts_json() {
283301# protection or the mode the VM had before (a protected .git, read-only
284302# shares), and the next start would trust it. With none, it rebuilds them.
285303_agent_vm_record_mounts() {
286删除: local record="$AGENT_VM_STATE_DIR/.agent-vm-mounts-$1"
304新增: local record
305新增: record="$(_agent_vm_mounts_record "$1")"
287306 mkdir -p "$AGENT_VM_STATE_DIR" 2>/dev/null && printf '%s\n' "$2" >| "$record" && return 0
288307 rm -f "$record"
289308 echo "Error: could not record the shares of VM '$1' in $record." >&2
290309 return 1
291310}
292311
312新增:# Where that record is kept for <vm>.
313新增:_agent_vm_mounts_record() {
314新增: printf '%s\n' "$AGENT_VM_STATE_DIR/.agent-vm-mounts-$1"
315新增:}
316新增:
317新增:# 0 when <vm>'s record holds the text <s>. A missing record holds nothing.
318新增:_agent_vm_mounts_record_has() {
319新增: local record
320新增: record="$(_agent_vm_mounts_record "$1")"
321新增: [[ -f "$record" ]] && grep -qF -- "$2" "$record"
322新增:}
323新增:
293324# 0 when <vm> is recorded with no writable share at all. A missing record
294325# counts as "not known to be read-only".
295326_agent_vm_mounts_all_readonly() {
296删除: local record="$AGENT_VM_STATE_DIR/.agent-vm-mounts-$1" mounts
297删除: [[ -f "$record" ]] || return 1
298删除: mounts="$(cat "$record")"
299删除: [[ "$mounts" != *'"writable": true'* ]]
327新增: [[ -f "$(_agent_vm_mounts_record "$1")" ]] && ! _agent_vm_mounts_record_has "$1" '"writable": true'
300328}
301329
302330# 0 when <vm> is recorded with every .git read-only (see
303331# _agent_vm_build_mounts_json). A missing record counts as "not protected".
304332_agent_vm_mounts_protect_git() {
305删除: local record="$AGENT_VM_STATE_DIR/.agent-vm-mounts-$1"
306删除: [[ -f "$record" ]] && grep -q '"readonlyNames"' "$record"
333新增: _agent_vm_mounts_record_has "$1" '"readonlyNames"'
307334}
308335
309336# 0 when <vm> is recorded with readonlyNames <names> (a JSON array, as
310337# _agent_vm_readonly_names prints it).
311338_agent_vm_mounts_have_readonly_names() {
312删除: local record="$AGENT_VM_STATE_DIR/.agent-vm-mounts-$1"
313删除: [[ -f "$record" ]] && grep -qF "\"readonlyNames\": $2" "$record"
339新增: _agent_vm_mounts_record_has "$1" "\"readonlyNames\": $2"
314340}
315341
316删除:# 0 when Lima's config for <vm> gives every share the builtin SFTP server and
317删除:# the read-only names <names> (a JSON array; any names when empty), with the
318删除:# mount type that serves them. Asked of Lima, not of the record: a share set
319删除:# outside agent-vm (by hand, or from Lima's _config/override.yaml or
320删除:# default.yaml, which Lima adds to every VM) has none, and the VM can write
321删除:# the .git it holds.
322删除:_agent_vm_live_shares_protected() {
323删除: local out want='"readonlyNames":['
324删除: out="$(limactl list --format '{{.Config.MountType}} {{json .Config.Mounts}}' "$1" 2>/dev/null)" || return 1
325删除: [[ "${out%% *}" == reverse-sshfs ]] || return 1
342新增:# Lima's config for <vm>, in one call: its VM type, mount type and mounts (as
343新增:# JSON), space-separated. Asked of Lima, not of agent-vm's record: Lima adds
344新增:# the mounts of its _config/default.yaml and override.yaml to every VM, and
345新增:# its config is what a running VM booted with (Lima refuses to edit a
346新增:# running one).
347新增:_agent_vm_live_config() {
348新增: limactl list --format '{{.VMType}} {{.Config.MountType}} {{json .Config.Mounts}}' "$1" 2>/dev/null
349新增:}
350新增:
351新增:# Sets the caller's live_vmtype, live_mtype and live_json from <live> (see
352新增:# _agent_vm_live_config). The mount type may be missing; the JSON, null or an
353新增:# array, is last. Fails when <live> holds no JSON: Lima did not answer.
354新增:_agent_vm_live_fields() {
355新增: local rest
356新增: live_vmtype="${1%% *}" live_mtype="" live_json=""
357新增: [[ "$1" == *" "* ]] || return 1
358新增: rest="${1#* }"
359新增: rest="${rest# }"
360新增: case "$rest" in
361新增: null*|"["*) ;;
362新增: *) live_mtype="${rest%% *}"; rest="${rest#"$live_mtype"}"; rest="${rest# }" ;;
363新增: esac
364新增: case "$rest" in
365新增: null|"["*) live_json="$rest" ;;
366新增: *) return 1 ;;
367新增: esac
368新增:}
369新增:
370新增:# Fails, printing why, unless the config <live> (see _agent_vm_live_config)
371新增:# gives every share the builtin SFTP server and the read-only names <names>
372新增:# (a JSON array; any names when empty), served by reverse-sshfs. A VM without
373新增:# a share passes. A share without them lets the VM write the .git it holds.
374新增:_agent_vm_live_shares_why() {
375新增: local live_vmtype live_mtype live_json want='"readonlyNames":['
376新增: if ! _agent_vm_live_fields "$1"; then
377新增: echo "Lima could not be asked for the VM's config"
378新增: return 1
379新增: fi
326380 # As Lima prints it: no space after the commas (a name may hold a space).
327381 [[ -z "${2:-}" ]] || want="\"readonlyNames\":${2//\", \"/\",\"}"
328删除: # One record per share: what follows each "location".
329删除: printf '%s\n' "${out#* }" | awk -v want="$want" 'BEGIN { RS = "\"location\"" }
330删除: NR > 1 { n++; if (index($0, "\"sftpDriver\":\"builtin\"") == 0 || index($0, want) == 0) bad++ }
331删除: END { exit (n > 0 && bad == 0) ? 0 : 1 }'
382新增: # One record per share: each mount object starts with its location, and no
383新增: # name can hold a quote.
384新增: printf '%s\n' "$live_json" | awk -v want="$want" -v mtype="${live_mtype:-unset}" '
385新增: BEGIN { RS = "[{]\"location\":" }
386新增: NR > 1 {
387新增: n++
388新增: if (index($0, "\"sftpDriver\":\"builtin\"") == 0 || index($0, want) == 0) {
389新增: loc = $0; sub(/^"/, "", loc); sub(/".*/, "", loc)
390新增: print "the share of " loc " lacks the read-only names, or the builtin SFTP server"
391新增: bad = 1
392新增: exit
393新增: }
394新增: }
395新增: END {
396新增: if (!bad && n > 0 && mtype != "reverse-sshfs") {
397新增: print "its mount type is " mtype ", and the read-only names need reverse-sshfs"
398新增: bad = 1
399新增: }
400新增: exit bad
401新增: }'
332402}
333403
334删除:# 1 when the running <vm> is served by another limactl than the one on PATH,
335删除:# which agent-vm checked: a stock Lima started it (by hand, at login, or from
336删除:# a shell with another PATH) and ignores the read-only names, or an older
337删除:# build since replaced. 0 when it is the same, or when that cannot be told
338删除:# (Windows, no pid file): never a reason to stop on its own.
404新增:# Fails, printing why, unless .git is read-only for <vm> now: agent-vm gave
405新增:# its shares the read-only names (the record), the Lima installed serves
406新增:# them, Lima's config (<live> when given, see _agent_vm_live_config) gives
407新增:# them to every share (see _agent_vm_live_shares_why), and the limactl
408新增:# serving it, when it runs, is that Lima (see _agent_vm_hostagent_is_limactl).
409新增:_agent_vm_protection_why() {
410新增: local why live
411新增: if [[ $# -ge 2 ]]; then live="$2"; else live="$(_agent_vm_live_config "$1")"; fi
412新增: if ! _agent_vm_mounts_protect_git "$1"; then
413新增: echo "agent-vm did not give its shares the read-only names"
414新增: return 1
415新增: fi
416新增: if ! _agent_vm_lima_protects_git; then
417新增: echo "the Lima installed cannot keep .git read-only"
418新增: return 1
419新增: fi
420新增: why="$(_agent_vm_live_shares_why "$live")" || { echo "$why"; return 1; }
421新增: if _agent_vm_running "$1" && ! _agent_vm_hostagent_is_limactl "$1"; then
422新增: echo "it was started by another limactl than $(_agent_vm_limactl_path)"
423新增: return 1
424新增: fi
425新增:}
426新增:
427新增:# 1 when the running <vm> is served by another limactl build than the one on
428新增:# PATH, which agent-vm checked: a stock Lima started it (by hand, at login,
429新增:# or from a shell with another PATH) and ignores the read-only names, or an
430新增:# older build since replaced. 0 when it is the same file, or the same
431新增:# version, or when that cannot be told (Windows, no pid file, no way to see
432新增:# the running binary): never a reason to stop on its own.
433新增:# The running binary is asked of the kernel: /proc on Linux, where it can
434新增:# still be run after its file was replaced; lsof on macOS, where ps only
435新增:# knows the path it was started by, a Homebrew link that may point elsewhere
436新增:# now.
339437_agent_vm_hostagent_is_limactl() {
340删除: local pid exe mine
438新增: local pid="" exe="" run="" mine
341439 _agent_vm_on_windows && return 0
342删除: pid="$(cat "$(_agent_vm_lima_home)/$1/ha.pid" 2>/dev/null)"
440新增: read -r pid < "$(_agent_vm_lima_home)/$1/ha.pid" 2>/dev/null
343441 [[ "$pid" =~ ^[0-9]+$ ]] || return 0
344442 if [[ -e "/proc/$pid/exe" ]]; then
345443 exe="$(readlink "/proc/$pid/exe" 2>/dev/null)"
346删除: else
347删除: exe="$(ps -o comm= -p "$pid" 2>/dev/null)"
444新增: run="/proc/$pid/exe"
445新增: elif command -v lsof >/dev/null 2>&1; then
446新增: exe="$(lsof -a -p "$pid" -d txt -Fn 2>/dev/null | awk '/^n/ { print substr($0, 2); exit }')"
447新增: run="$exe"
348448 fi
349449 [[ "$exe" == /* ]] || return 0
350删除: mine="$(_agent_vm_physical_file "$(command -v limactl)")" || return 0
351删除: [[ "$(_agent_vm_physical_file "$exe" 2>/dev/null)" == "$mine" ]] && return 0
352删除: # Another path to the same build (a shim on PATH): the same version.
353删除: [[ -x "$exe" && "$("$exe" --version 2>/dev/null)" == "$(limactl --version 2>/dev/null)" ]]
450新增: mine="$(_agent_vm_limactl_path)"
451新增: [[ -n "$mine" ]] || return 0
452新增: [[ "$exe" -ef "$mine" ]] && return 0
453新增: [[ -x "$run" && "$("$run" --version 2>/dev/null)" == "$(limactl --version 2>/dev/null)" ]]
354454}
355455
356删除:# 0 when <vm> is recorded with sshfs's cache off (see _agent_vm_build_mounts_json).
357删除:_agent_vm_mounts_cache_off() {
358删除: local record="$AGENT_VM_STATE_DIR/.agent-vm-mounts-$1"
359删除: [[ -f "$record" ]] && grep -q '"cache": false' "$record"
456新增:# How sshfs caches what the shares serve (see _agent_vm_build_mounts_json):
457新增:# writable-off by default, the cache off on the writable shares only; on
458新增:# with AGENT_VM_SSHFS_CACHE=1, read from the shell, never from the project.
459新增:# On is faster on many files (a repeated `git status` sends about 20 times
460新增:# fewer requests to the host), and the VM may then see a file as it was for
461新增:# up to 20 seconds, and write that back.
462新增:_agent_vm_sshfs_cache_mode() {
463新增: if [[ "${AGENT_VM_SSHFS_CACHE:-}" == 1 ]]; then echo on; else echo writable-off; fi
464新增:}
465新增:
466新增:# 0 when <vm>'s shares were given the cache mode they would get now (recorded
467新增:# by _agent_vm_apply_shares).
468新增:_agent_vm_mounts_sshfs_current() {
469新增: local mode=""
470新增: read -r mode < "$AGENT_VM_STATE_DIR/.agent-vm-sshfs-cache-$1" 2>/dev/null
471新增: [[ "$mode" == "$(_agent_vm_sshfs_cache_mode)" ]]
360472}
361473
362474# _agent_vm_push_env_and_probe <vm> <dir> <payload> [<env> [<runtime>]], in
@@ -367,28 +479,32 @@ _agent_vm_mounts_cache_off() {
367479# env-ok.
368480# - prints runtime-found when the project's <runtime> is there.
369481# - returns whether a write into the project <dir> succeeds: 0 yes, 1 no. A
370删除:# real write, not `test -w`: after a mode change the guest's fstab still
371删除:# shows the old one. 2 when the write succeeded in the VM but did not reach
372删除:# <dir> on this machine: the share is not mounted (sshfs died, or never
373删除:# mounted), and the VM writes in the bare mount point on its own disk. The
374删除:# guest leaves the file for this machine to find, and remove.
482新增:# real write, removed at once, not `test -w`: after a mode change the
483新增:# guest's fstab still shows the old one.
484新增:# - returns 2 when the share is not mounted (sshfs died, or never mounted),
485新增:# where the VM writes in the bare mount point on its own disk: the guest
486新增:# does not see the file this machine put in <dir> just before (prints
487新增:# share-ok when it does). Not for the caller's scratch VM, which shares
488新增:# nothing: no file is put on this machine then.
375489_agent_vm_push_env_and_probe() {
376删除: local vm_name="$1" host_dir="$2" payload="$3" token out st=0
377删除: token="$$.$RANDOM$RANDOM"
490新增: local vm_name="$1" host_dir="$2" payload="$3" token="" out st=0
491新增: if [[ -z "${scratch:-}" ]]; then
492新增: token=".agent-vm-probe.$$.$RANDOM$RANDOM"
493新增: # Never through something already there: set -C refuses it.
494新增: ( set -C; : > "$host_dir/$token" ) 2>/dev/null || token=""
495新增: fi
378496 out="$({ [ -z "$payload" ] || printf '%s\n' "$payload"; } \
379497 | limactl shell "$vm_name" sh -c '
380498 (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
381499 [ -z "$3" ] || [ ! -f "$3" ] || echo runtime-found
382删除: touch "$1/.agent-vm-write-probe.$4" 2>/dev/null || exit 1; echo probe-written' \
500新增: [ -z "$4" ] || [ ! -f "$1/$4" ] || echo share-ok
501新增: p="$1/.agent-vm-write-probe.$$"; touch "$p" 2>/dev/null || exit 1; rm -f "$p"' \
383502 sh "$host_dir" "${4:-}" "${5:-}" "$token" 2>/dev/null)" || st=$?
503新增: [[ -z "$token" ]] || rm -f "$host_dir/$token"
384504 printf '%s\n' "$out"
385删除: [[ "$st" == 0 ]] || return 1
386删除: [[ "$out" == *probe-written* ]] || return 0
387删除: if [[ -e "$host_dir/.agent-vm-write-probe.$token" ]]; then
388删除: rm -f "$host_dir/.agent-vm-write-probe.$token"
389删除: return 0
390删除: fi
391删除: return 2
505新增: # The guest answered, but without the share.
506新增: [[ -z "$token" || "$out" != *env-ok* || "$out" == *share-ok* ]] || return 2
507新增: [[ "$st" == 0 ]]
392508}
393509
394510# Are <vm>'s shares ones whose read-only flag is enforced outside the guest?
@@ -400,26 +516,24 @@ _agent_vm_push_env_and_probe() {
400516# virtiofsd has no read-only mode and Lima passes none
401517# (virtio-fs/virtiofsd#97), so the flag only reaches the guest's fstab.
402518# reverse-sshfs is enforced only when served by the builtin SFTP server of a
403删除:# Lima with readonlyNames, which is answered from the mounts agent-vm last
404删除:# applied. Otherwise it only gets `-o ro` inside the guest, where root can
405删除:# remount it rw. Returns 0 (enforced), 1 (not enforced), or 2 (could not tell).
519新增:# Lima with readonlyNames, as _agent_vm_protection_why tells. Otherwise it
520新增:# only gets `-o ro` inside the guest, where root can remount it rw, and the
521新增:# SFTP server is not confined to the shares. Returns 0 (enforced), 1 (not
522新增:# enforced), or 2 (could not tell).
406523_agent_vm_mount_is_host_enforced() {
407删除: local types vmtype mtype
408删除: types="$(limactl list --format '{{.VMType}} {{.Config.MountType}}' "$1" 2>/dev/null)" || return 2
409删除: vmtype="${types%% *}"
410删除: mtype="${types#* }"
411删除: [[ "$types" == *" "* ]] || mtype=""
524新增: local live vmtype mtype live_vmtype live_mtype live_json
525新增: live="$(_agent_vm_live_config "$1")" || return 2
526新增: _agent_vm_live_fields "$live" || return 2
527新增: vmtype="$live_vmtype"
528新增: mtype="$live_mtype"
412529 case "$mtype" in
413530 ""|default|"<nil>"|"<no value>") mtype="$(_agent_vm_default_mount_type "$1" "$vmtype")" ;;
414531 esac
415532 case "$vmtype $mtype" in
416533 "vz virtiofs"|"qemu 9p") return 0 ;;
417534 "qemu virtiofs") return 1 ;;
418删除: # The record says agent-vm gave it readonlyNames, and the Lima installed
419删除: # now serves them: a stock limactl started by hand would not.
420535 ?*" reverse-sshfs")
421删除: _agent_vm_mounts_protect_git "$1" && _agent_vm_lima_protects_git \
422删除: && _agent_vm_live_shares_protected "$1" && return 0
536新增: _agent_vm_protection_why "$1" "$live" >/dev/null && return 0
423537 return 1 ;;
424538 *) return 2 ;;
425539 esac
修改lib/setup.sh+6 −10看文件
@@ -302,9 +302,10 @@ EOF
302302 mcp-chrome) install_mcp_chrome=1 ;;
303303 mcp-playwright) install_mcp_playwright=1 ;;
304304 code-server) install_code_server=1 ;;
305删除: code-claude) install_code_claude=1 ;;
306删除: code-codex) install_code_codex=1 ;;
307删除: code-vibe) install_code_vibe=1 ;;
305新增: # An extension needs the editor.
306新增: code-claude) install_code_claude=1 install_code_server=1 ;;
307新增: code-codex) install_code_codex=1 install_code_server=1 ;;
308新增: code-vibe) install_code_vibe=1 install_code_server=1 ;;
308309 *)
309310 echo "Unknown preinstall name: $f (names are lowercase)" >&2
310311 echo "Valid: python, node, ruby, rust, golang, docker, chromium, gh, claude, opencode, codex, vibe, pi, mcp-chrome, mcp-playwright, code-server, code-claude, code-codex, code-vibe, default, all, none" >&2
@@ -463,11 +464,6 @@ EOF
463464 echo "Running security checks..."
464465 [[ -n "$declined_protection" ]] || _agent_vm_offer_git_protection
465466
466删除: # An extension needs the editor.
467删除: if [[ "$install_code_claude$install_code_codex$install_code_vibe" == *1* ]]; then
468删除: install_code_server=1
469删除: fi
470删除:
471467 # --preinstall can name what needs node without node.
472468 local node_reason
473469 node_reason="$(_agent_vm_node_needed_by)"
@@ -519,8 +515,8 @@ EOF
519515 echo "Starting base VM (the first run downloads a Debian image)..."
520516 if ! _agent_vm_windowed "$setup_log" limactl start "$AGENT_VM_TEMPLATE" </dev/null; then
521517 echo "Error: Failed to start base VM. Full log: $setup_log" >&2
522删除: echo "Lima's own log: $(_agent_vm_lima_home)/$AGENT_VM_TEMPLATE/ha.stderr.log" >&2
523删除: _agent_vm_windows_start_hint "$setup_log" "$(_agent_vm_lima_home)/$AGENT_VM_TEMPLATE/ha.stderr.log"
518新增: echo "Lima's own log: $(_agent_vm_ha_log "$AGENT_VM_TEMPLATE")" >&2
519新增: _agent_vm_windows_start_hint "$setup_log" "$(_agent_vm_ha_log "$AGENT_VM_TEMPLATE")"
524520 return 1
525521 fi
526522
修改lib/ui.sh+12 −14看文件
@@ -47,14 +47,7 @@ _agent_vm_ask_choice() {
4747 printf ' %s) %s\n' "$i" "$reply" >&2
4848 i=$((i + 1))
4949 done
50删除: while true; do
51删除: reply="$(_agent_vm_ask "$prompt" "$default")"
52删除: if [[ "$reply" =~ ^[1-9][0-9]*$ && "$reply" -le $# ]]; then
53删除: printf '%s\n' "$reply"
54删除: return 0
55删除: fi
56删除: printf ' (a number from 1 to %s; got: %s)\n' "$#" "$reply" >&2
57删除: done
50新增: _agent_vm_ask_int "$prompt" "$default" "$#"
5851}
5952
6053# Can a question be asked, and seen? A terminal to read the answer from, and
@@ -148,17 +141,22 @@ _agent_vm_box() {
148141 } >&2
149142}
150143
151删除:# Prompt for a positive integer with default. Re-prompts on invalid input.
152删除:# Used for disk/memory/cpus where a typo (e.g. "10G") would otherwise produce
153删除:# a cryptic limactl error several seconds later.
144新增:# Prompt for a positive integer with default, at most <max> when given.
145新增:# Re-prompts on invalid input. Used for disk/memory/cpus where a typo (e.g.
146新增:# "10G") would otherwise produce a cryptic limactl error several seconds
147新增:# later, and for the menus of _agent_vm_ask_choice.
154148_agent_vm_ask_int() {
155删除: local prompt="$1" default="$2" reply
149新增: local prompt="$1" default="$2" max="${3:-}" reply
156150 while true; do
157151 reply=$(_agent_vm_ask "$prompt" "$default")
158删除: if [[ "$reply" =~ ^[1-9][0-9]*$ ]]; then
152新增: if [[ "$reply" =~ ^[1-9][0-9]*$ ]] && [[ -z "$max" || "$reply" -le "$max" ]]; then
159153 printf '%s\n' "$reply"
160154 return 0
161155 fi
162删除: printf ' (must be a positive integer, e.g. 10; got: %s)\n' "$reply" >&2
156新增: if [[ -n "$max" ]]; then
157新增: printf ' (a number from 1 to %s; got: %s)\n' "$max" "$reply" >&2
158新增: else
159新增: printf ' (must be a positive integer, e.g. 10; got: %s)\n' "$reply" >&2
160新增: fi
163161 done
164162}
修改lib/vm.sh+55 −17看文件
@@ -48,20 +48,19 @@ _agent_vm_unmountable_path() {
4848 fi
4949}
5050
51删除:# Prints why <dir> must not be shared with a VM ("is, or contains, ..." or "is
52删除:# inside ..."), and returns 0, when it is or contains your home directory
53删除:# (dotfiles, SSH keys, every other project), or is, contains or is inside
54删除:# agent-vm itself (the host runs its files), agent-vm's state (every VM's env)
55删除:# or Lima's (the VMs' SSH key and disks, override.yaml adding mounts to every
56删除:# VM). A project inside the home directory is what is expected. Returns 1
57删除:# when it is none of them.
58删除:# Compared as physical paths: a share is the directory a path resolves to.
59删除:# And whatever the case where the file system ignores it: `cd /c/users/me`
60删除:# reaches the home directory in Git Bash, which keeps the spelling typed.
51新增:# Prints why the project <dir> must not be shared with a VM, and returns 0,
52新增:# when it is one of the locations below (_agent_vm_unsafe_location) or a
53新增:# repository's own folder (_agent_vm_git_dir_share): the project is a
54新增:# writable share. Returns 1 when it is neither.
6155_agent_vm_unsafe_project() {
62删除: local dir p rp what
63删除: dir="$(CDPATH= cd -P -- "$1" 2>/dev/null && pwd)" || dir="$1"
64删除: dir="$(_agent_vm_fold "$dir")"
56新增: _agent_vm_unsafe_location "$1" || _agent_vm_git_dir_share "$1"
57新增:}
58新增:
59新增:# The locations no share may reach, one per line, physical and folded (see
60新增:# _agent_vm_unsafe_location), each after what it is and a tab. A caller
61新增:# checking several paths sets _agent_vm_unsafe_refs to this once.
62新增:_agent_vm_unsafe_ref_dirs() {
63新增: local p rp what
6564 for what in "your home directory" "agent-vm itself" "agent-vm's state" "Lima's state"; do
6665 case "$what" in
6766 "your home directory") p="$HOME" ;;
@@ -78,7 +77,27 @@ _agent_vm_unsafe_project() {
7877 p="${p%/}"
7978 fi
8079 [[ -n "$p" ]] || continue
81删除: p="$(_agent_vm_fold "$p")"
80新增: printf '%s\t%s\n' "$what" "$(_agent_vm_fold "$p")"
81新增: done
82新增:}
83新增:
84新增:# Prints why <dir> must not be shared with a VM, writable or not ("is, or
85新增:# contains, ..." or "is inside ..."), and returns 0, when it is or contains
86新增:# your home directory (dotfiles, SSH keys, every other project), or is,
87新增:# contains or is inside agent-vm itself (the host runs its files), agent-vm's
88新增:# state (every VM's env) or Lima's (the VMs' SSH key and disks, override.yaml
89新增:# adding mounts to every VM). A project inside the home directory is what is
90新增:# expected. Returns 1 when it is none of them.
91新增:# Compared as physical paths: a share is the directory a path resolves to.
92新增:# And whatever the case where the file system ignores it: `cd /c/users/me`
93新增:# reaches the home directory in Git Bash, which keeps the spelling typed.
94新增:_agent_vm_unsafe_location() {
95新增: local dir what p refs="${_agent_vm_unsafe_refs:-}"
96新增: [[ -n "$refs" ]] || refs="$(_agent_vm_unsafe_ref_dirs)"
97新增: dir="$(CDPATH= cd -P -- "$1" 2>/dev/null && pwd)" || dir="$1"
98新增: dir="$(_agent_vm_fold "$dir")"
99新增: while IFS=$'\t' read -r what p; do
100新增: [[ -n "$p" ]] || continue
82101 case "${p%/}/" in
83102 "${dir%/}/"*)
84103 printf 'is, or contains, %s\n' "$what"
@@ -90,9 +109,26 @@ _agent_vm_unsafe_project() {
90109 printf 'is inside %s\n' "$what"
91110 return 0 ;;
92111 esac
112新增: done <<< "$refs"
113新增: return 1
114新增:}
115新增:
116新增:# Prints why <dir> must not be a writable share, and returns 0, when it is a
117新增:# repository's own folder or inside one: a .git or .hg (by name, as the SFTP
118新增:# server matches them), or a bare repository (HEAD, objects/ and refs/, as git
119新增:# finds one). The read-only names apply below a share's root, so such a share
120新增:# is writable whole: hooks and config included.
121新增:_agent_vm_git_dir_share() {
122新增: local dir a
123新增: dir="$(CDPATH= cd -P -- "$1" 2>/dev/null && pwd)" || dir="$1"
124新增: a="${dir%/}"
125新增: while [[ -n "$a" ]]; do
126新增: if [[ -f "$a/HEAD" && -d "$a/objects" && -d "$a/refs" ]]; then
127新增: printf 'is, or is inside, a git repository'"'"'s own folder (%s)\n' "$a"
128新增: return 0
129新增: fi
130新增: a="${a%/*}"
93131 done
94删除: # The read-only names apply below a share's root: a share that is a .git,
95删除: # or inside one, is writable whole.
96132 if _agent_vm_under_readonly_name "${dir#/}"; then
97133 printf 'is, or is inside, a folder git or Mercurial keeps its repository in (.git, .hg)\n'
98134 return 0
@@ -245,7 +281,8 @@ _agent_vm_cleanup_state() {
245281 rm -f "$AGENT_VM_STATE_DIR/.agent-vm-sshfs-${vm_name}"
246282 rm -f "$AGENT_VM_STATE_DIR/.agent-vm-term-${vm_name}"
247283 rm -f "$AGENT_VM_STATE_DIR/.agent-vm-file-mounts-${vm_name}"
248删除: rm -f "$AGENT_VM_STATE_DIR/.agent-vm-mounts-${vm_name}"
284新增: rm -f "$(_agent_vm_mounts_record "$vm_name")"
285新增: rm -f "$AGENT_VM_STATE_DIR/.agent-vm-sshfs-cache-${vm_name}"
249286 rm -f "$(_agent_vm_scratch_marker "$vm_name")"
250287 rm -rf "$AGENT_VM_STATE_DIR/file-mounts/${vm_name}"
251288 # Deleting the template retires the marker that says it is usable.
@@ -362,6 +399,7 @@ _agent_vm_migrate_0_1() {
362399 echo "$out" >&2
363400 return 1
364401 fi
402新增: _agent_vm_check_before_start "$vm_name" 1 || return 1
365403 echo "Starting VM '$vm_name' without shares to install sshfs..."
366404 if ! out=$(limactl start "$vm_name" 2>&1); then
367405 echo "Error: Failed to start VM '$vm_name' to install sshfs:" >&2
修改test-e2e.sh+7 −4看文件
@@ -47,7 +47,10 @@ fi
4747SB="$(mktemp -d /tmp/agent-vm-e2e.XXXXXX)"
4848export AGENT_VM_STATE_DIR="$SB/state"
4949export LIMA_HOME="$SB/lima"
50删除:PROJ="$SB/project"
50新增:# In a folder of its own: a volume holding it must not hold the state
51新增:# directories, which agent-vm refuses to share.
52新增:WORK="$SB/work"
53新增:PROJ="$WORK/project"
5154mkdir -p "$AGENT_VM_STATE_DIR" "$LIMA_HOME" "$PROJ"
5255git -C "$PROJ" init -q
5356
@@ -238,11 +241,11 @@ section "--readonly covers every share, not just the project"
238241# =============================================================================
239242# A writable volume that contains the project is a second path to the same
240243# files, and the hypervisor enforces read-only per share. Under --readonly it
241删除:# has to be read-only as well. $SB is the project's parent.
244新增:# has to be read-only as well. $WORK is the project's parent.
242245#
243246# Volumes are mounted when a VM is created, so --reset: on the existing VM the
244247# volume would simply be absent, and the write would fail for that reason.
245删除:printf '%s:/mnt/sb:rw\n' "$SB" > "$AGENT_VM_STATE_DIR/volumes"
248新增:printf '%s:/mnt/sb:rw\n' "$WORK" > "$AGENT_VM_STATE_DIR/volumes"
246249ro_run --reset run sudo sh -c \
247250 "test -d /mnt/sb/project || exit 3; echo x > /mnt/sb/project/via-volume.txt"
248251via_status=$?
@@ -269,7 +272,7 @@ else
269272 fail "the project stayed read-only after --readonly was dropped"
270273fi
271274if (cd "$PROJ" && "$AGENT_VM" run sh -c "echo back > /mnt/sb/volume-again.txt") \
272删除: && [ -e "$SB/volume-again.txt" ]; then
275新增: && [ -e "$WORK/volume-again.txt" ]; then
273276 pass "and an rw volume is writable again"
274277else
275278 fail "the rw volume stayed read-only after --readonly was dropped"
修改tests/06-help-and-setup-script.sh+37 −10看文件
@@ -152,6 +152,15 @@ sshfs_stub ' -o follow_symlinks'
152152check "sshfs wrapper: an older sshfs gets the arguments unchanged" \
153153 "$(sh "$SB/sshfs-wrapper" ':/p' /p -o slave)" ":/p /p -o slave"
154154
155新增:# An agent is there as a command, as an extension, or both: either way its
156新增:# config (managed settings, MCP servers) is written. The lines setup derives
157新增:# it with, run as setup does.
158新增:has_block="$(awk '/^HAS_CLAUDE=0 HAS_CODEX=0 HAS_VIBE=0$/,/HAS_VIBE=1$/' "$SETUP_SH")"
159新增:has() { ( INSTALL_CLAUDE="$1" INSTALL_CODE_CLAUDE="$2" INSTALL_CODEX="$3" INSTALL_CODE_CODEX="$4" INSTALL_VIBE="$5" INSTALL_CODE_VIBE="$6"
160新增: eval "$has_block"; echo "$HAS_CLAUDE$HAS_CODEX$HAS_VIBE" ); }
161新增:check "setup: the agents' config, for a command or an extension" \
162新增: "$(has 1 0 0 0 0 0) $(has 0 1 0 0 0 0) $(has 0 0 0 1 0 0) $(has 0 0 0 0 1 1) $(has 0 0 0 0 0 0)" "100 100 010 001 000"
163新增:
155164# =============================================================================
156165section "MCP config writer"
157166# =============================================================================
@@ -235,19 +244,37 @@ else
235244 echo '{"$ref":"../top.json"}' > "$SCH/web/$(web https://h.test/s/rel.json)"
236245 echo '{"type":"string"}' > "$SCH/web/$(web https://h.test/top.json)"
237246 echo '{"type":"number"}' > "$SCH/web/$(web https://www.schemastore.org/b)"
247新增: # c: listed at one URL, its $id another, which its relative references
248新增: # follow, as the editor's do. d: references up two folders.
249新增: mkdir -p "$SCH/ext/c"
250新增: echo '{"contributes":{"jsonValidation":[{"fileMatch":"c.json","url":"https://www.schemastore.org/package"},{"fileMatch":"d.json","url":"https://h.test/s/a/b/d.json"}]}}' > "$SCH/ext/c/package.json"
251新增: echo '{"$id":"https://json.schemastore.org/package.json","properties":{"e":{"$ref":"eslintrc.json#"}}}' > "$SCH/web/$(web https://www.schemastore.org/package)"
252新增: echo '{"type":"boolean"}' > "$SCH/web/$(web https://www.schemastore.org/eslintrc.json)"
253新增: echo '{"$ref":"../../c.json"}' > "$SCH/web/$(web https://h.test/s/a/b/d.json)"
254新增: echo '{"type":"null"}' > "$SCH/web/$(web https://h.test/s/c.json)"
238255 out="$( ( curl() {
239删除: local o="" u=""
240删除: while [ $# -gt 0 ]; do case "$1" in -o) o="$2"; shift 2 ;; -*) shift ;; *) u="$1"; shift ;; esac; done
241删除: echo "$u" >> "$SCH/fetched"
242删除: [ -f "$SCH/web/$(web "$u")" ] || return 22
243删除: cp "$SCH/web/$(web "$u")" "$o"
256新增: local o="" st=0
257新增: echo call >> "$SCH/calls"
258新增: while [ $# -gt 0 ]; do
259新增: case "$1" in
260新增: -o) o="$2"; shift 2 ;;
261新增: --parallel-max|--max-time) shift 2 ;;
262新增: -*) shift ;;
263新增: *)
264新增: echo "$1" >> "$SCH/fetched"
265新增: if [ -f "$SCH/web/$(web "$1")" ]; then cp "$SCH/web/$(web "$1")" "$o"; else st=22; fi
266新增: shift ;;
267新增: esac
268新增: done
269新增: return "$st"
244270 }
245271 set -euo pipefail
246删除: eval "$(awk '/^code_server_schemas\(\) \{/,/^\}/' "$SETUP_SH")"
272新增: eval "$(awk '/^(code_server_schemas|schema_url_resolve)\(\) \{/,/^\}/' "$SETUP_SH")"
247273 code_server_schemas "$SCH/ext" "$SCH/machine/settings.json"; echo "rc=$?" ) 2>&1)"
248274 check "every schema named, and every one they refer to, by the URL the editor asks" \
249275 "$(jq -r '."json.schemas"[].url' "$SCH/machine/settings.json" 2>/dev/null | sort | tr '\n' ' ')" \
250删除: "https://h.test/abs.json https://h.test/s/a https://h.test/s/rel.json https://h.test/top.json https://json.schemastore.org/b "
276新增: "https://h.test/abs.json https://h.test/s/a https://h.test/s/a/b/d.json https://h.test/s/c.json https://h.test/s/rel.json https://h.test/top.json https://json.schemastore.org/b https://json.schemastore.org/eslintrc.json https://www.schemastore.org/package "
277新增: check "a level of references fetched in one call" "$(wc -l < "$SCH/calls" | tr -d ' ')" "3"
251278 check "each with its content" \
252279 "$(jq -r '."json.schemas"[] | select(.url == "https://h.test/top.json") | .schema.type' "$SCH/machine/settings.json" 2>/dev/null)" "string"
253280 check "json.schemastore.org fetched from www.schemastore.org, where it redirects" \
@@ -273,8 +300,8 @@ $(awk '/^if \[\[ "\$INSTALL_CODE_SERVER" == "1" \]\]; then/,/^fi$/' "$SETUP_SH")
273300$(awk '/^configure_mcp\(\) \{/,/^\}/' "$SETUP_SH")"
274301 # <home> <claude> <codex> <vibe>: the extensions asked for.
275302 # Under set -e, as the script runs: a failing step must show here. Twice:
276删除: # setup can be run again on a base. The first run's state is kept in
277删除: # <home>/first.
303新增: # what it writes must not pile up when it runs again in the same VM. The
304新增: # first run's state is kept in <home>/first.
278305 run_cs_block() {
279306 mkdir -p "$1/.config/code-server"; echo "password: from-the-base" > "$1/.config/code-server/config.yaml"
280307 ( set -e
@@ -282,7 +309,7 @@ $(awk '/^configure_mcp\(\) \{/,/^\}/' "$SETUP_SH")"
282309 HAS_CLAUDE="$2" HAS_CODEX="$3" HAS_VIBE="$4" INSTALL_OPENCODE=0
283310 curl() { echo "curl $*" >> "$HOME/calls.log"; }
284311 code-server() { echo "code-server $*" >> "$HOME/calls.log"; }
285删除: code_server_schemas() { echo "schemas $*" >> "$HOME/calls.log"; }
312新增: code_server_schemas() { echo "schemas $*" >> "$HOME/calls.log"; mkdir -p "$(dirname "$2")"; echo '{"json.schemas":[]}' > "$2"; }
286313 eval "$cs_block"
287314 mkdir -p "$HOME/first"
288315 for f in .codex/config.toml .vibe/config.toml; do [ ! -f "$HOME/$f" ] || cp "$HOME/$f" "$HOME/first/${f%%/*}"; done
修改tests/08-mount-mode.sh+37 −7看文件
@@ -58,9 +58,16 @@ mount_types() {
5858 cat > "$SB/bin/limactl" <<STUB
5959#!/usr/bin/env bash
6060[ "\$1" = shell ] && { echo 9p; exit 0; }
61删除:case "\$*" in *"json .Config.Mounts"*) printf '%s\n' "\${MT_LIVE:-}"; exit 0 ;; esac
61新增:case "\$*" in *"json .Config.Mounts"*) printf '%s\n' "\${MT_LIVE:-$1 null}"; exit 0 ;; esac
6262[ "\$1" = list ] && { printf '%s\n' "$1"; exit 0; }
63删除:[ "\$1" = validate ] && [ -n "\${MT_PROTECTS:-}" ] && { echo 'field mounts[*].sshfs.readonlyNames requires mountType to be reverse-sshfs' >&2; exit 1; }
63新增:if [ "\$1" = validate ]; then
64新增: if [ -n "\${MT_PROTECTS:-}" ]; then
65新增: echo 'level=fatal msg="failed to validate YAML file \`probe.yaml\`: field \`mounts[0].sshfs.readonlyNames\` must contain file names, got \`a/b\`"' >&2
66新增: exit 1
67新增: fi
68新增: echo 'level=warning msg="Non-strict YAML detected; please check for typos" error="[3:158] unknown field \"readonlyNames\""' >&2
69新增: exit 0
70新增:fi
6471exit 1
6572STUB
6673 chmod +x "$SB/bin/limactl"
@@ -93,15 +100,38 @@ check "unset on QEMU, no lima-version: reverse-sshfs, not" "$(LIMA_HOME="$SB/lim
93100# cannot tell the servers apart: the record of the applied mounts does.
94101mkdir -p "$HOME/.agent-vm"
95102printf '[{"location": "%s", "writable": false, %s}]\n' "$PROJ" "$SSHFS_RO" > "$HOME/.agent-vm/.agent-vm-mounts-agent-vm-t"
96删除:LIVE_OK='reverse-sshfs [{"location":"/p","writable":false,"sshfs":{"cache":false,"sftpDriver":"builtin","readonlyNames":[".git",".hg"]}}]'
103新增:LIVE_OK='qemu reverse-sshfs [{"location":"/p","writable":false,"sshfs":{"cache":false,"sftpDriver":"builtin","readonlyNames":[".git",".hg"]}}]'
97104check "reverse-sshfs with readonlyNames is" "$(MT_PROTECTS=1 MT_LIVE="$LIVE_OK" mount_types 'qemu reverse-sshfs')" "0"
98105# Recorded so, but Lima has a share without them, set outside agent-vm: not.
106新增:# Built apart: bash 3.2 brace-expands {...,...} in a quoted $( ).
107新增:live="${LIVE_OK%]},{\"location\":\"/elsewhere\",\"writable\":true}]"
99108check "recorded with readonlyNames, a share in Lima's config without them: not" \
100删除: "$(MT_PROTECTS=1 MT_LIVE="${LIVE_OK%]},{\"location\":\"/elsewhere\",\"writable\":true}]" mount_types 'qemu reverse-sshfs')" "1"
101删除:# Recorded so, but served by a Lima without them (a stock limactl started it
102删除:# since): not.
103删除:check "recorded with readonlyNames, a Lima without them: not" "$(mount_types 'qemu reverse-sshfs')" "1"
109新增: "$(MT_PROTECTS=1 MT_LIVE="$live" mount_types 'qemu reverse-sshfs')" "1"
110新增:# Recorded so, and so in Lima's config, but served by a Lima without them (a
111新增:# stock limactl installed since): not.
112新增:check "recorded with readonlyNames, a Lima without them: not" "$(MT_LIVE="$LIVE_OK" mount_types 'qemu reverse-sshfs')" "1"
104113rm -f "$HOME/.agent-vm/.agent-vm-mounts-agent-vm-t"
114新增:
115新增:# Each part of Lima's config the protection needs (see
116新增:# _agent_vm_live_shares_why), and what is said when one is missing.
117新增:why() { _agent_vm_live_shares_why "$@" >/dev/null && echo ok || echo not; }
118新增:check "live: every share with the builtin server and the names" "$(why "$LIVE_OK")" "ok"
119新增:check "live: another mount type" "$(why "${LIVE_OK/reverse-sshfs/virtiofs}")" "not"
120新增:case "$(_agent_vm_live_shares_why "${LIVE_OK/reverse-sshfs/virtiofs}")" in
121新增: *"mount type is virtiofs"*) pass "live: and says it is the mount type" ;;
122新增: *) fail "live: mount type: $(_agent_vm_live_shares_why "${LIVE_OK/reverse-sshfs/virtiofs}")" ;;
123新增:esac
124新增:check "live: a share without the builtin server" "$(why "${LIVE_OK/\"sftpDriver\":\"builtin\",/}")" "not"
125新增:check "live: other names than those asked" "$(why "$LIVE_OK" '[".git", ".hg", "tools"]')" "not"
126新增:check "live: the names asked" "$(why "$LIVE_OK" '[".git", ".hg"]')" "ok"
127新增:live='qemu reverse-sshfs [{"location":"/p","sshfs":{"sftpDriver":"builtin","readonlyNames":[".git",".hg","location"]}},{"location":"/q","sshfs":{"sftpDriver":"builtin","readonlyNames":[".git",".hg","location"]}}]'
128新增:check "live: a name 'location' does not split a share" "$(why "$live" '[".git", ".hg", "location"]')" "ok"
129新增:check "live: no share at all" "$(why 'vz virtiofs null')" "ok"
130新增:fields() { local live_vmtype live_mtype live_json; _agent_vm_live_fields "$1" && echo "$live_vmtype|$live_mtype|$live_json" || echo none; }
131新增:check "live: the three fields" "$(fields 'vz reverse-sshfs [{"location":"/p"}]')" 'vz|reverse-sshfs|[{"location":"/p"}]'
132新增:check "live: no mount type" "$(fields 'qemu null')|$(fields 'qemu null')" "qemu||null|qemu||null"
133新增:check "live: no JSON, no answer" "$(fields 'vz virtiofs')" "none"
134新增:check "live: Lima not answering" "$(why '')" "not"
105135# Restore the shared stub: mount_fstype replaced it with its own.
106136cat > "$SB/bin/limactl" <<'STUB'
107137#!/usr/bin/env bash
修改tests/11-recorded-commands.sh+51 −21看文件
@@ -3,19 +3,25 @@ section "commands against a recording limactl"
33# =============================================================================
44# One stub for the sections below. It logs every call, lists the base template
55# and the VM named by AGENT_VM_TEST_VM, and reports its mount type as
6删除:# virtiofs (AGENT_VM_TEST_MOUNTTYPE to change it) on vz (AGENT_VM_TEST_VMTYPE). With AGENT_VM_TEST_CLONED set,
7删除:# that VM only exists once `clone` has created the file. AGENT_VM_TEST_STOPPED
8删除:# lists it as stopped, as does a `stop` until the next `start`, and
9删除:# AGENT_VM_TEST_RO makes the project write probe fail, as a read-only share
10删除:# would. AGENT_VM_TEST_STOP_FAIL makes `stop` leave it running.
6新增:# virtiofs (AGENT_VM_TEST_MOUNTTYPE to change it) on vz
7新增:# (AGENT_VM_TEST_VMTYPE). Lima's config for the VM holds the mounts last set
8新增:# by `edit` in the run, else those of agent-vm's record;
9新增:# AGENT_VM_TEST_LIVE_UNPROTECTED adds a share without read-only names to
10新增:# them, as Lima's _config would. With AGENT_VM_TEST_CLONED set, that VM only
11新增:# exists once `clone` has created the file. AGENT_VM_TEST_STOPPED lists it as
12新增:# stopped, as does a `stop` until the next `start`, and AGENT_VM_TEST_RO
13新增:# makes the project write probe fail, as a read-only share would.
14新增:# AGENT_VM_TEST_STOP_FAIL makes `stop` leave it running.
1115# AGENT_VM_TEST_SSHFS_FAIL fails the sshfs install of a 0.1.0 VM.
1216# AGENT_VM_TEST_RUNTIME_FOUND makes the probe find the project's runtime
13删除:# script. AGENT_VM_TEST_PROBE_LOST makes its write succeed in the VM without
14删除:# reaching the project, as when the share is not mounted. What is piped into the env push goes to AGENT_VM_TEST_STDIN.
15删除:# `validate` answers like stock Lima 2.2 does to readonlyNames, or, while the
16删除:# file $PROTECTS exists, like a Lima that has it (both messages copied from
17删除:# the real binaries). AGENT_VM_TEST_VALIDATE_SILENT makes it accept the file
18删除:# without a word, an answer agent-vm cannot read.
17新增:# script. AGENT_VM_TEST_PROBE_LOST makes the project's share look gone: the
18新增:# guest does not see the file this machine put there. What is piped into the
19新增:# env push goes to AGENT_VM_TEST_STDIN.
20新增:# `validate` answers the probe of _agent_vm_lima_protects_git like stock Lima
21新增:# 2.2 does, or, while the file $PROTECTS exists, like the fork
22新增:# (v2.3.0-sylvinus.2): both messages copied from the real binaries.
23新增:# AGENT_VM_TEST_VALIDATE_SILENT makes it accept the file without a word, an
24新增:# answer agent-vm cannot read.
1925REC="$SB/rec.log"
2026PROTECTS="$SB/lima-protects"
2127cat > "$SB/bin/limactl" <<'STUB'
@@ -27,7 +33,7 @@ case "$1" in
2733 validate)
2834 [ -z "${AGENT_VM_TEST_VALIDATE_SILENT:-}" ] || exit 0
2935 if [ -e "${AGENT_VM_TEST_PROTECTS:-/nonexistent}" ]; then
30删除: echo 'level=fatal msg="failed to validate YAML file `probe.yaml`: field `mounts[*].sshfs.readonlyNames` requires `mountType` to be `reverse-sshfs`"' >&2
36新增: echo 'level=fatal msg="failed to validate YAML file `probe.yaml`: field `mounts[0].sshfs.readonlyNames` must contain file names, got `a/b`"' >&2
3137 exit 1
3238 fi
3339 echo 'level=warning msg="Non-strict YAML detected; please check for typos" error="[3:158] unknown field \"readonlyNames\""' >&2
@@ -35,7 +41,19 @@ case "$1" in
3541 clone)
3642 [ -z "${AGENT_VM_TEST_CLONE_FAIL:-}" ] || { echo 'level=fatal msg="clone boom"' >&2; exit 1; }
3743 [ -n "${AGENT_VM_TEST_CLONED:-}" ] && touch "$AGENT_VM_TEST_CLONED" ;;
38删除: edit) [ -z "${AGENT_VM_TEST_EDIT_FAIL:-}" ] || { echo 'level=fatal msg="edit boom"' >&2; exit 1; } ;;
44新增: # Lima's config then holds the mounts set, until the next run (see rec).
45新增: edit)
46新增: [ -z "${AGENT_VM_TEST_EDIT_FAIL:-}" ] || { echo 'level=fatal msg="edit boom"' >&2; exit 1; }
47新增: expr="" prev=""
48新增: for a in "$@"; do [ "$prev" = --set ] && expr="$a"; prev="$a"; done
49新增: case "$expr" in
50新增: *".mounts = "*)
51新增: case "$expr" in
52新增: *'.mountType = "reverse-sshfs"'*) t=reverse-sshfs ;;
53新增: *) t="${AGENT_VM_TEST_MOUNTTYPE:-virtiofs}" ;;
54新增: esac
55新增: printf '%s %s\n' "$t" "$(printf '%s' "${expr#*.mounts = }" | tr -d ' ')" > "$AGENT_VM_TEST_REC.live" ;;
56新增: esac ;;
3957 list)
4058 case "$*" in
4159 *"{{.Name}} {{.Config.SSH.LocalPort}}"*)
@@ -48,12 +66,22 @@ case "$1" in
4866 # them, unless AGENT_VM_TEST_LIVE_UNPROTECTED adds one set by hand.
4967 *"{{json .Config.Mounts}}"*)
5068 r="$HOME/.agent-vm/.agent-vm-mounts-$AGENT_VM_TEST_VM"
51删除: if [ -f "$r" ] && grep -q readonlyNames "$r"; then
52删除: m="$(tr -d ' ' < "$r")"
53删除: [ -z "${AGENT_VM_TEST_LIVE_UNPROTECTED:-}" ] || m="${m%]},{\"location\":\"/elsewhere\",\"writable\":true}]"
54删除: echo "reverse-sshfs $m"
69新增: extra() {
70新增: [ -n "${AGENT_VM_TEST_LIVE_UNPROTECTED:-}" ] || { printf '%s\n' "$1"; return; }
71新增: case "$1" in
72新增: null|"[]") echo '[{"location":"/elsewhere","writable":true}]' ;;
73新增: *) printf '%s\n' "${1%]},{\"location\":\"/elsewhere\",\"writable\":true}]" ;;
74新增: esac
75新增: }
76新增: if [ -f "$AGENT_VM_TEST_REC.live" ]; then
77新增: read -r t m < "$AGENT_VM_TEST_REC.live"
78新增: echo "${AGENT_VM_TEST_VMTYPE:-vz} ${AGENT_VM_TEST_LIVE_MOUNTTYPE:-$t} $(extra "$m")"
79新增: elif [ -f "$r" ] && grep -q readonlyNames "$r"; then
80新增: echo "${AGENT_VM_TEST_VMTYPE:-vz} ${AGENT_VM_TEST_LIVE_MOUNTTYPE:-reverse-sshfs} $(extra "$(tr -d ' ' < "$r")")"
81新增: elif [ -f "$r" ]; then
82新增: echo "${AGENT_VM_TEST_VMTYPE:-vz} ${AGENT_VM_TEST_MOUNTTYPE:-virtiofs} $(extra "$(tr -d ' ' < "$r")")"
5583 else
56删除: echo "${AGENT_VM_TEST_MOUNTTYPE:-virtiofs} [{\"location\":\"/x\",\"writable\":true}]"
84新增: echo "${AGENT_VM_TEST_VMTYPE:-vz} ${AGENT_VM_TEST_MOUNTTYPE:-virtiofs} $(extra null)"
5785 fi ;;
5886 *"{{.VMType}}"*) echo "${AGENT_VM_TEST_VMTYPE:-vz} ${AGENT_VM_TEST_MOUNTTYPE:-virtiofs}" ;;
5987 *"{{.CPUs}}"*"{{.Disk}}"*) listed && echo "$AGENT_VM_TEST_VM|1|3221225472|10737418240" ;;
@@ -79,8 +107,8 @@ case "$1" in
79107 [ -n "${AGENT_VM_TEST_ENV_FAIL:-}" ] || echo env-ok
80108 [ -z "${AGENT_VM_TEST_RUNTIME_FOUND:-}" ] || echo runtime-found ;;
81109 esac
82删除: [ -z "${AGENT_VM_TEST_RO:-}" ] || exit 1
83删除: [ -z "${AGENT_VM_TEST_PROBE_LOST:-}" ] || echo probe-written ;;
110新增: [ -n "${AGENT_VM_TEST_PROBE_LOST:-}" ] || echo share-ok
111新增: [ -z "${AGENT_VM_TEST_RO:-}" ] || exit 1 ;;
84112 *"exec "*" -s"*) cat >> "${AGENT_VM_TEST_STDIN:-/dev/null}" ;;
85113 # The editor's prep (lib/code.sh): AGENT_VM_TEST_CODE_PREP is its answer.
86114 *"agent-vm-code "*)
@@ -108,9 +136,11 @@ _agent_vm_check_windows_prereqs() { return 0; }
108136if _agent_vm_on_windows; then
109137 _agent_vm_unprotected_mount_is_sshfs() { return 1; }
110138fi
139新增:# Each run starts from the record the test wrote: Lima's config follows it
140新增:# until an edit in the run.
111141rec() {
112142 : > "$REC"
113删除: rm -f "$REC.stopped"
143新增: rm -f "$REC.stopped" "$REC.live"
114144 ( cd "$PROJ" || exit 1
115145 export AGENT_VM_TEST_REC="$REC" AGENT_VM_TEST_VM="$PV" AGENT_VM_TEST_PROTECTS="$PROTECTS"
116146 agent-vm "$@" </dev/null 2>&1 )
修改tests/13-volumes-and-readonly.sh+26 −2看文件
@@ -291,6 +291,30 @@ printf '%s:/mnt/s:rw\n%s:%s:rw\n%s:/mnt/ok:rw\n' "$HOME/.agent-vm" "$SB/vol-ok"
291291vols_err="$(_agent_vm_build_mounts_json agent-vm-t "$PROJ" 2>&1 >/dev/null)"
292292vols="$(_agent_vm_build_mounts_json agent-vm-t "$PROJ" 2>/dev/null)"
293293case "$vols_err" in *"'$HOME/.agent-vm' (from ~/.agent-vm/volumes) is, or contains, agent-vm's state"*) pass "volumes: agent-vm's state is refused" ;; *) fail "volumes: state: $vols_err" ;; esac
294删除:case "$vols_err" in *"Mount destination '$(dirname "$PROJ")' (from ~/.agent-vm/volumes) would cover the project"*) pass "volumes: a destination above the project is refused" ;; *) fail "volumes: cover: $vols_err" ;; esac
294新增:case "$vols_err" in *"would be mounted at $(dirname "$PROJ"), which covers the project"*) pass "volumes: a destination above the project is refused" ;; *) fail "volumes: cover: $vols_err" ;; esac
295295check "volumes: only the sound entry is mounted" "$(printf '%s' "$vols" | grep -o '"mountPoint"' | wc -l | tr -d ' ')" "2"
296删除:rm -rf "$SB/vol-ok" "$HOME/.agent-vm/volumes"
296新增:# Mounted where it is, without a destination: the parent covers the project,
297新增:# and the project itself would be merged into its share by Lima. Spellings
298新增:# that are the same place, and two entries at one place, likewise.
299新增:# A project of its own, under a folder holding nothing else.
300新增:P2="$SB/cov/proj"
301新增:mkdir -p "$P2" "$SB/vol-ok" "$SB/vol-ok2"
302新增:printf '%s:ro\n%s\n%s:%s/./x/..//:rw\n%s:/mnt/d:ro\n%s:/mnt/d/:rw\n' \
303新增: "$SB/cov" "$P2" "$SB/vol-ok" "$P2" "$SB/vol-ok" "$SB/vol-ok2" > "$HOME/.agent-vm/volumes"
304新增:vols_err="$(_agent_vm_volume_entries "$P2" 2>&1 >/dev/null)"
305新增:vols="$(_agent_vm_volume_entries "$P2" 2>/dev/null)"
306新增:check "volumes: covering the project or merged with another, whatever the spelling: all refused" \
307新增: "$(printf '%s\n' "$vols_err" | grep -c 'covers the project')/$(printf '%s\n' "$vols_err" | grep -c 'as an entry before it')" "3/1"
308新增:check "volumes: the first at a place is kept, its destination normalized" "$vols" "$SB/vol-ok|/mnt/d|ro|$SB/vol-ok:/mnt/d:ro"
309新增:rm -rf "$SB/vol-ok" "$SB/vol-ok2" "$SB/cov" "$HOME/.agent-vm/volumes"
310新增:# A repository's own folder: refused writable, where the VM would write its
311新增:# hooks and config, not read-only.
312新增:mkdir -p "$SB/bare.git/objects" "$SB/bare.git/refs" && : > "$SB/bare.git/HEAD"
313新增:printf '%s:/mnt/b:rw\n' "$SB/bare.git" > "$HOME/.agent-vm/volumes"
314新增:case "$(_agent_vm_volume_entries "$PROJ" 2>&1)" in *"a git repository's own folder"*) pass "volumes: a bare repository, writable: refused" ;; *) fail "volumes: bare rw: $(_agent_vm_volume_entries "$PROJ" 2>&1)" ;; esac
315新增:printf '%s:/mnt/b:ro\n' "$SB/bare.git" > "$HOME/.agent-vm/volumes"
316新增:check "volumes: read-only: kept" "$(_agent_vm_volume_entries "$PROJ" 2>/dev/null)" "$SB/bare.git|/mnt/b|ro|$SB/bare.git:/mnt/b:ro"
317新增:rm -rf "$SB/bare.git" "$HOME/.agent-vm/volumes"
318新增:mkdir -p "$PROJ/inner.git/objects" "$PROJ/inner.git/refs" && : > "$PROJ/inner.git/HEAD"
319新增:check "a bare repository as the project" "$(refused "$PROJ/inner.git")" "refused"
320新增:rm -rf "$PROJ/inner.git"
修改tests/14-git-protection.sh+161 −17看文件
@@ -143,6 +143,11 @@ case "$out" in *"could not install sshfs"*"E: no sshfs"*"rc=1") pass "0.1.0 VM,
143143rec_has "reverse-sshfs" && fail "0.1.0 VM, install failed: shares changed" || pass "0.1.0 VM, install failed: no protected shares"
144144rec_has "agent-vm-write-probe" && fail "0.1.0 VM, install failed: the command ran" || pass "0.1.0 VM, install failed: the command did not run"
145145[ -e "$MIGRATED" ] && fail "0.1.0 VM, install failed: recorded as migrated" || pass "0.1.0 VM, install failed: tried again next time"
146新增:# The boot without shares has none from Lima's _config either.
147新增:old_vm
148新增:out="$(AGENT_VM_TEST_STOPPED=1 AGENT_VM_TEST_LIVE_UNPROTECTED=1 rec run true; echo "rc=$?")"
149新增:case "$out" in *"shares agent-vm did not ask for"*"rc=1") pass "0.1.0 VM: a share from Lima's _config stops the boot without shares" ;; *) fail "0.1.0 VM, _config: $out" ;; esac
150新增:rec_has "start $PV" && fail "0.1.0 VM, _config: started anyway" || pass "0.1.0 VM, _config: not started"
146151
147152old_vm
148153rm -f "$PROTECTS"
@@ -331,25 +336,60 @@ _agent_vm_mounts_have_readonly_names "$PV" '[".git", ".hg"]' && pass "names: rec
331336out="$(AGENT_VM_TEST_STOPPED=1 rec run true)"
332337rec_has "edit $PV" && fail "names: edited again with nothing to change" || pass "names: nothing to change the next time"
333338
334删除:# Shares from before sshfs's cache was off: set again while stopped, never
335删除:# a reason to restart a running VM.
339新增:# Shares from before sshfs's cache was off (no cache mode recorded): set
340新增:# again while stopped, never a reason to restart a running VM.
341新增:CACHE_MODE="$HOME/.agent-vm/.agent-vm-sshfs-cache-$PV"
336342names_rec '[".git", ".hg"]'
343新增:rm -f "$CACHE_MODE"
337344out="$(rec run true)"
338345rec_has "edit $PV" && fail "cache: a running VM was changed" || pass "cache: a running VM is left as it is"
339346rec_has "stop $PV" && fail "cache: a running VM was stopped" || pass "cache: and not stopped"
340删除:names_rec '[".git", ".hg"]'
347新增:case "$out" in *Warning*) fail "cache: a running VM warned about: $out" ;; *) pass "cache: and nothing said" ;; esac
341348AGENT_VM_TEST_STOPPED=1 rec run true >/dev/null
342349rec_has "edit $PV --set .mountType = \"reverse-sshfs\" | .mounts = [{$(mnt "$PROJ"), \"writable\": true, $SSHFS_RO}]" \
343350 && pass "cache: a stopped VM gets its shares with the cache off" || fail "cache: not updated: $(grep '^edit' "$REC")"
344删除:_agent_vm_mounts_cache_off "$PV" && pass "cache: recorded" || fail "cache: record: $(cat "$REC_MOUNTS")"
351新增:_agent_vm_mounts_sshfs_current "$PV" && pass "cache: recorded" || fail "cache: record: $(cat "$CACHE_MODE" 2>/dev/null)"
352新增:# AGENT_VM_SSHFS_CACHE=1: the cache on, everywhere, the next time it starts.
353新增:AGENT_VM_SSHFS_CACHE=1 AGENT_VM_TEST_STOPPED=1 rec run true >/dev/null
354新增:rec_has "edit $PV --set .mountType = \"reverse-sshfs\" | .mounts = [{$(mnt "$PROJ"), \"writable\": true, \"sshfs\": {\"sftpDriver\": \"builtin\", \"readonlyNames\": [\".git\", \".hg\"]}}]" \
355新增: && pass "cache: AGENT_VM_SSHFS_CACHE=1 turns it on" || fail "cache: flag: $(grep '^edit' "$REC")"
356新增:AGENT_VM_TEST_STOPPED=1 rec run true >/dev/null
357新增:rec_has "\"cache\": false" && pass "cache: and without it, off again" || fail "cache: back off: $(grep '^edit' "$REC")"
345358
346359# A share in Lima's config without the names, set outside agent-vm (by hand,
347360# or from Lima's _config): the record cannot be trusted.
348361out="$(AGENT_VM_TEST_LIVE_UNPROTECTED=1 rec run true)"
349362case "$out" in *"is running with .git writable"*) pass "live: a running VM with such a share is warned about" ;; *) fail "live, running: $out" ;; esac
350363out="$(AGENT_VM_TEST_LIVE_UNPROTECTED=1 AGENT_VM_TEST_STOPPED=1 rec run true; echo "rc=$?")"
351删除:case "$out" in *"a share without the read-only names"*"_config/override.yaml"*"rc=1") pass "live: a stopped VM keeping one after its edit is not started" ;; *) fail "live, stopped: $out" ;; esac
364新增:case "$out" in *"would boot with .git writable: the share of /elsewhere lacks the read-only names"*"'mounts' in"*"_config/override.yaml"*"rc=1") pass "live: a stopped VM keeping one after its edit is not started" ;; *) fail "live, stopped: $out" ;; esac
352365rec_has "start $PV" && fail "live: started anyway" || pass "live: and not started"
366新增:# Another mount type from Lima's _config: said as such.
367新增:out="$(AGENT_VM_TEST_LIVE_MOUNTTYPE=virtiofs AGENT_VM_TEST_STOPPED=1 rec run true; echo "rc=$?")"
368新增:case "$out" in *"mount type is virtiofs"*"'mountType' in"*"rc=1") pass "live: another mount type is named" ;; *) fail "live, mount type: $out" ;; esac
369新增:# Nor through the restart of a repair: every boot is checked.
370新增:out="$(AGENT_VM_TEST_LIVE_UNPROTECTED=1 AGENT_VM_TEST_PROBE_LOST=1 rec run true; echo "rc=$?")"
371新增:case "$out" in *"would boot with .git writable"*"rc=1") pass "live: a repair restart is checked too" ;; *) fail "live, repair: $out" ;; esac
372新增:rec_has "start $PV" && fail "live: the repair started it anyway" || pass "live: and the repair does not start it"
373新增:# --readonly with a writable share from Lima's _config: refused.
374新增:ro_rec_live() { printf '[{"location": "%s", "writable": false, %s}]\n' "$PROJ" "${SSHFS_RO/, \"cache\": false/}" > "$REC_MOUNTS"; }
375新增:ro_rec_live
376新增:out="$(AGENT_VM_TEST_LIVE_UNPROTECTED=1 AGENT_VM_TEST_RO=1 AGENT_VM_TEST_MOUNTTYPE=reverse-sshfs rec --readonly run true; echo "rc=$?")"
377新增:case "$out" in *"Read-only: the project and every other share"*) fail "--readonly claimed with a writable share: $out" ;; *"rc=1") pass "--readonly: a writable share from Lima's _config is refused" ;; *) fail "--readonly, live: $out" ;; esac
378新增:# The same on vz with virtiofs, enforced on the host, and a stock Lima.
379新增:rm -f "$PROTECTS"
380新增:printf '[{"location": "%s", "writable": false}]\n' "$PROJ" > "$REC_MOUNTS"
381新增:out="$(AGENT_VM_TEST_LIVE_UNPROTECTED=1 AGENT_VM_TEST_RO=1 rec --readonly run true; echo "rc=$?")"
382新增:case "$out" in *"Lima gives VM '$PV' a writable share agent-vm did not set"*"rc=1") pass "--readonly on virtiofs: a writable share from Lima's _config is refused" ;; *) fail "--readonly, virtiofs, live: $out" ;; esac
383新增:out="$(AGENT_VM_TEST_RO=1 rec --readonly run true; echo "rc=$?")"
384新增:case "$out" in *"Read-only: the project and every other share"*"rc=0") pass "--readonly on virtiofs: and without it, enforced" ;; *) fail "--readonly, virtiofs: $out" ;; esac
385新增:touch "$PROTECTS"
386新增:# doctor tells the same as a start.
387新增:names_rec '[".git", ".hg"]'
388新增:out="$(AGENT_VM_TEST_LIVE_UNPROTECTED=1 rec doctor)"
389新增:case "$out" in *"warn its shares were given the read-only names, but .git is not read-only: the share of /elsewhere lacks"*) pass "doctor: a share without the names in Lima's config" ;; *) fail "doctor: live: $out" ;; esac
390新增:out="$(rec doctor)"
391新增:case "$out" in *"ok its shares keep every .git read-only"*) pass "doctor: and without it, ok" ;; *) fail "doctor: protected: $out" ;; esac
392新增:names_rec '[".git", ".hg"]'
353393
354394# A running VM served by another binary than the limactl on PATH (a stock
355395# Lima that ignores the names): its pid file points to that process.
@@ -357,14 +397,40 @@ if _agent_vm_on_windows; then
357397 printf ' skip the limactl serving a running VM (not told on Windows)\n'
358398else
359399 names_rec '[".git", ".hg"]'
360删除: printf '%s\n' "$(cat "$REC_MOUNTS" | sed 's/"readonlyNames"/"cache": false, "readonlyNames"/')" > "$REC_MOUNTS"
361400 mkdir -p "$(_agent_vm_lima_home)/$PV"
362401 : > "$(_agent_vm_lima_home)/$PV/lima.yaml"
363402 sleep 30 & other_pid=$!
364403 echo "$other_pid" > "$(_agent_vm_lima_home)/$PV/ha.pid"
365404 out="$(rec run true)"
366405 case "$out" in *"was started by another limactl"*"is running with .git writable"*) pass "hostagent: a VM another limactl runs is not taken as protected" ;; *) fail "hostagent: $out" ;; esac
406新增: # --readonly does not take it as enforced either.
407新增: ro_rec_live
408新增: out="$(AGENT_VM_TEST_RO=1 AGENT_VM_TEST_MOUNTTYPE=reverse-sshfs rec --readonly run true; echo "rc=$?")"
409新增: case "$out" in *"Read-only: the project and every other share"*) fail "hostagent: --readonly claimed: $out" ;; *"rc=1") pass "hostagent: --readonly is refused" ;; *) fail "hostagent, --readonly: $out" ;; esac
410新增: names_rec '[".git", ".hg"]'
367411 kill "$other_pid" 2>/dev/null; wait "$other_pid" 2>/dev/null
412新增: # The limactl on PATH serving it: here a copy of bash standing for it (any
413新增: # name runs it, unlike a multi-call busybox), run through a link as
414新增: # Homebrew installs it. Then that file replaced by the same build while it
415新增: # runs (an upgrade to the same version), then by another one.
416新增: if [ -e /proc/self/exe ]; then
417新增: mkdir -p "$SB/ha-bin" "$SB/ha-link"
418新增: cp "$BASH" "$SB/ha-bin/limactl"
419新增: ln -sf "$SB/ha-bin/limactl" "$SB/ha-link/limactl"
420新增: "$SB/ha-link/limactl" -c 'sleep 30; :' & other_pid=$!
421新增: echo "$other_pid" > "$(_agent_vm_lima_home)/$PV/ha.pid"
422新增: ha() { ( PATH="$SB/ha-link:$PATH"; _agent_vm_hostagent_is_limactl "$PV" && echo same || echo other ); }
423新增: check "hostagent: the stand-in for the hostagent runs" "$(kill -0 "$other_pid" 2>/dev/null && echo yes)" "yes"
424新增: check "hostagent: the limactl on PATH, through a link" "$(ha)" "same"
425新增: rm "$SB/ha-bin/limactl" && cp "$BASH" "$SB/ha-bin/limactl"
426新增: check "hostagent: its file replaced by the same build since" "$(ha)" "same"
427新增: rm "$SB/ha-bin/limactl" && printf '#!/bin/sh\necho limactl version 9\n' > "$SB/ha-bin/limactl" && chmod +x "$SB/ha-bin/limactl"
428新增: check "hostagent: by another build" "$(ha)" "other"
429新增: kill "$other_pid" 2>/dev/null; wait "$other_pid" 2>/dev/null
430新增: rm -rf "$SB/ha-bin" "$SB/ha-link"
431新增: else
432新增: printf ' skip the limactl serving a running VM, same build (no /proc here)\n'
433新增: fi
368434 rm -f "$(_agent_vm_lima_home)/$PV/ha.pid" "$(_agent_vm_lima_home)/$PV/lima.yaml"
369435 out="$(rec run true)"
370436 case "$out" in *"another limactl"*) fail "hostagent: no pid file, warned anyway" ;; *) pass "hostagent: when it cannot tell, nothing is said" ;; esac
@@ -432,7 +498,7 @@ if command -v git >/dev/null 2>&1; then
432498 mkdir -p "$PROJ/lib/inner"
433499 ( git -C "$PROJ/lib/inner" init -q && git -C "$PROJ/lib/inner" config core.hooksPath .githooks )
434500 check "hooks: a nested repository's folder joins the names" "$(names)" '[".git", ".hg", ".husky", ".githooks"]'
435删除: case "$(_agent_vm_project_hooks "$PROJ")" in *"lib/inner/.githooks"*) pass "hooks: named from the project" ;; *) fail "hooks: nested: $(_agent_vm_project_hooks "$PROJ")" ;; esac
501新增: case "$(_agent_vm_share_hooks "$PROJ")" in *"lib/inner/.githooks"*) pass "hooks: named from the project" ;; *) fail "hooks: nested: $(_agent_vm_share_hooks "$PROJ")" ;; esac
436502 names_rec '[".git", ".hg"]'
437503 AGENT_VM_TEST_STOPPED=1 rec run true >/dev/null
438504 rec_has "\"readonlyNames\": [\".git\", \".hg\", \".husky\", \".githooks\"]}}]" \
@@ -455,19 +521,56 @@ if command -v git >/dev/null 2>&1; then
455521 check "hooks: core.hooksPath linked elsewhere in the project: both names" "$(names)" '[".git", ".hg", ".githooks", "scripts"]'
456522 ( git -C "$PROJ" config --unset core.hooksPath )
457523 rm "$PROJ/.githooks"
524新增: risks() { _agent_vm_share_config_risks "$PROJ"; }
458525 printf '#!/bin/sh\n' > "$PROJ/scripts/pre-commit"
526新增: printf '#!/bin/sh\n' > "$SB/elsewhere-hook"
459527 ln -s ../../scripts/pre-commit "$PROJ/.git/hooks/pre-commit"
460528 ln -s "$SB/elsewhere-hook" "$PROJ/.git/hooks/post-commit"
461删除: case "$(_agent_vm_project_config_risks "$PROJ")" in
529新增: case "$(risks)" in
462530 *"hook pre-commit runs scripts/pre-commit"*) pass "hooks: a hook linked to a file of the project is a risk" ;;
463删除: *) fail "hooks: linked hook: $(_agent_vm_project_config_risks "$PROJ")" ;;
531新增: *) fail "hooks: linked hook: $(risks)" ;;
464532 esac
465删除: case "$(_agent_vm_project_config_risks "$PROJ")" in
533新增: case "$(risks)" in
466534 *post-commit*) fail "hooks: a link out of the project counted as a risk" ;;
467535 *) pass "hooks: and one linked out of it is not" ;;
468536 esac
469删除: rm -f "$PROJ/.git/hooks/pre-commit" "$PROJ/.git/hooks/post-commit"
470删除: rm -rf "$PROJ/scripts"
537新增: # Not there yet: the VM can create it.
538新增: ln -s ../../later/pre-push "$PROJ/.git/hooks/pre-push"
539新增: case "$(risks)" in *"hook pre-push runs later/pre-push"*) pass "hooks: a hook linked to a file of the project not there yet" ;; *) fail "hooks: dangling: $(risks)" ;; esac
540新增: # Through a link in the project to a file outside it: the VM can change
541新增: # the link.
542新增: ln -s "$SB/elsewhere-hook" "$PROJ/scripts/relay"
543新增: ln -s ../../scripts/relay "$PROJ/.git/hooks/post-merge"
544新增: case "$(risks)" in *"hook post-merge runs scripts/relay"*) pass "hooks: a hook reached through a link in the project" ;; *) fail "hooks: chain: $(risks)" ;; esac
545新增: # Out of the project, then back into it.
546新增: ln -s "$PROJ/scripts/pre-commit" "$SB/back-link"
547新增: ln -s "$SB/back-link" "$PROJ/.git/hooks/pre-rebase"
548新增: case "$(risks)" in *"hook pre-rebase runs scripts/pre-commit"*) pass "hooks: a hook linked out of the project and back" ;; *) fail "hooks: back: $(risks)" ;; esac
549新增: rm -f "$PROJ/.git/hooks/pre-commit" "$PROJ/.git/hooks/post-commit" "$PROJ/.git/hooks/pre-push" "$PROJ/.git/hooks/post-merge" \
550新增: "$PROJ/.git/hooks/pre-rebase" "$SB/back-link"
551新增: # The hooks folder itself linked to a folder not there yet, or through a
552新增: # link in the project to one outside it.
553新增: mv "$PROJ/.git/hooks" "$SB/hooks-saved"
554新增: ln -s ../tools/hooks "$PROJ/.git/hooks"
555新增: check "hooks: .git/hooks linked to a folder of the project not there yet" "$(names)" '[".git", ".hg", "tools"]'
556新增: rm "$PROJ/.git/hooks"
557新增: mkdir -p "$SB/shared-hooks"
558新增: ln -s "$SB/shared-hooks" "$PROJ/scripts/hooks-relay"
559新增: ln -s ../scripts/hooks-relay "$PROJ/.git/hooks"
560新增: check "hooks: .git/hooks through a link in the project to a folder outside" "$(names)" '[".git", ".hg", "scripts"]'
561新增: rm "$PROJ/.git/hooks"
562新增: mv "$SB/hooks-saved" "$PROJ/.git/hooks"
563新增: # A hook linked to another in its own folder, which its name keeps
564新增: # read-only: no risk.
565新增: mkdir -p "$PROJ/.githooks"
566新增: printf '#!/bin/sh\n' > "$PROJ/.githooks/post-merge"
567新增: ln -s post-merge "$PROJ/.githooks/post-rewrite"
568新增: hp .githooks
569新增: case "$(risks)" in *post-rewrite*) fail "hooks: a link inside a protected hooks folder counted as a risk: $(risks)" ;; *) pass "hooks: a link inside a protected hooks folder is no risk" ;; esac
570新增: # A name of a hook printed as is: control characters made visible.
571新增: ln -s ../scripts/pre-commit "$PROJ/.githooks/$(printf 'a\033]0;x\007b')"
572新增: case "$(risks)" in *$'\033'*) fail "hooks: a control character printed" ;; *"hook a?]0;x?b runs scripts/pre-commit"*) pass "hooks: control characters in a hook's name made visible" ;; *) fail "hooks: control: $(risks | cat -v)" ;; esac
573新增: rm -rf "$PROJ/.githooks" "$PROJ/scripts" "$SB/shared-hooks" "$SB/elsewhere-hook"
471574 hp .husky/_
472575 else
473576 printf ' skip hooks through symlinks (no symlinks here)\n'
@@ -483,13 +586,54 @@ if command -v git >/dev/null 2>&1; then
483586 check "volumes: a writable volume's hooks folder joins the names" "$(names)" '[".git", ".hg", ".husky", "tools"]'
484587 case "$(_agent_vm_share_hooks "$PROJ")" in *"$VREPO/tools/hooks"*) pass "volumes: named by the volume's path" ;; *) fail "volumes: hooks: $(_agent_vm_share_hooks "$PROJ")" ;; esac
485588 case "$(_agent_vm_share_config_risks "$PROJ")" in
486删除: *"$VREPO: core.fsmonitor = ./fsmon.sh"*) pass "volumes: its config naming a command in it is a risk" ;;
589新增: *"core.fsmonitor = ./fsmon.sh"*) pass "volumes: its config naming a command in it is a risk" ;;
487590 *) fail "volumes: risks: $(_agent_vm_share_config_risks "$PROJ")" ;;
488591 esac
489592 printf '%s:/mnt/vrepo:ro\n' "$VREPO" > "$HOME/.agent-vm/volumes"
490593 check "volumes: a read-only volume adds nothing" "$(names)" '[".git", ".hg", ".husky"]'
491594 [ -z "$(_agent_vm_share_config_risks "$PROJ")" ] && pass "volumes: nor risks" || fail "volumes: ro risks: $(_agent_vm_share_config_risks "$PROJ")"
492删除: rm -rf "$VREPO" "$HOME/.agent-vm/volumes"
595新增: rm -rf "$VREPO"
596新增: # From one share into another: the project's git config naming a command,
597新增: # a hooks folder or a config file in a writable volume that is no
598新增: # repository, and git's own config in one.
599新增: VOL="$SB/teamtools"
600新增: mkdir -p "$VOL/hooks"
601新增: printf '%s:/mnt/teamtools:rw\n' "$VOL" > "$HOME/.agent-vm/volumes"
602新增: ( git -C "$PROJ" config core.fsmonitor "$VOL/fsmon.sh" && git -C "$PROJ" config include.path "$VOL/gitconfig" )
603新增: case "$(_agent_vm_share_config_risks "$PROJ")" in
604新增: *"core.fsmonitor = $VOL/fsmon.sh"*"config file $VOL/gitconfig"*|*"config file $VOL/gitconfig"*"core.fsmonitor = $VOL/fsmon.sh"*)
605新增: pass "volumes: the project's config naming a command and a file in a volume" ;;
606新增: *) fail "volumes: cross: $(_agent_vm_share_config_risks "$PROJ")" ;;
607新增: esac
608新增: ( git -C "$PROJ" config --unset core.fsmonitor; git -C "$PROJ" config --unset include.path )
609新增: hp "$VOL/hooks"
610新增: check "volumes: the project's hooks folder in a volume is named from it" "$(names)" '[".git", ".hg", "hooks"]'
611新增: hp .husky/_
612新增: mkdir -p "$VOL/git"
613新增: printf '[core]\n\tfsmonitor = %s/fsmon.sh\n' "$VOL" > "$VOL/git/config"
614新增: case "$( XDG_CONFIG_HOME="$VOL" _agent_vm_share_config_risks "$PROJ" )" in
615新增: *"config file $VOL/git/config"*) pass "volumes: git's own config kept in a volume" ;;
616新增: *) fail "volumes: global: $( XDG_CONFIG_HOME="$VOL" _agent_vm_share_config_risks "$PROJ" )" ;;
617新增: esac
618新增: # A volume reached through a symlink is searched all the same.
619新增: mkdir -p "$SB/data/code/app"
620新增: ln -s "$SB/data/code" "$SB/code-link"
621新增: ( git -C "$SB/data/code/app" init -q && git -C "$SB/data/code/app" config core.hooksPath .husky/_ )
622新增: printf '%s:/mnt/code:rw\n' "$SB/code-link" > "$HOME/.agent-vm/volumes"
623新增: case "$(_agent_vm_share_hooks "$PROJ")" in *"$SB/data/code/app/.husky/_"*) pass "volumes: a volume through a symlink is searched" ;; *) fail "volumes: symlinked: $(_agent_vm_share_hooks "$PROJ")" ;; esac
624新增: # The project inside a writable volume: each folder once, named from the
625新增: # project.
626新增: mkdir -p "$SB/up/app"
627新增: ( git -C "$SB/up/app" init -q && git -C "$SB/up/app" config core.hooksPath .husky/_ )
628新增: printf '%s:/mnt/up:rw\n' "$SB/up" > "$HOME/.agent-vm/volumes"
629新增: check "volumes: the project inside one: each hooks folder once" "$(_agent_vm_share_hooks "$SB/up/app")" "$(printf '.husky/_\t.husky/_')"
630新增: rm -rf "$SB/up"
631新增: # A bare repository in a writable volume: its own folder is named.
632新增: mkdir -p "$SB/remotes"
633新增: ( git init -q --bare "$SB/remotes/proj.git" )
634新增: printf '%s:/mnt/remotes:rw\n' "$SB/remotes" > "$HOME/.agent-vm/volumes"
635新增: check "volumes: a bare repository in one is protected by its name" "$(names)" '[".git", ".hg", ".husky", "proj.git"]'
636新增: rm -rf "$VOL" "$SB/data" "$SB/code-link" "$SB/remotes" "$HOME/.agent-vm/volumes"
493637
494638 # A name that is not a dot-name is read-only in every folder of the
495639 # project, so it is asked first: yes by default, and when no one can answer.
@@ -548,12 +692,12 @@ if command -v git >/dev/null 2>&1; then
548692 git -C "$PROJ" config core.pager less
549693 git -C "$PROJ" config core.sshCommand "ssh -o ProxyCommand=/usr/bin/nc"
550694 git -C "$PROJ" config alias.st status )
551删除: check "config: nothing in the project, nothing said" "$(_agent_vm_project_config_risks "$PROJ")" ""
695新增: check "config: nothing in the project, nothing said" "$(_agent_vm_share_config_risks "$PROJ")" ""
552696 ( printf '[core]\n\tfsmonitor = ./watch.sh\n' > "$PROJ/.gitconfig"
553697 git -C "$PROJ" config include.path ../.gitconfig
554698 git -C "$PROJ" config filter.x.clean "scripts/clean.sh %f"
555699 git -C "$PROJ" config alias.t '!./t.sh' )
556删除: risks="$(_agent_vm_project_config_risks "$PROJ")"
700新增: risks="$(_agent_vm_share_config_risks "$PROJ")"
557701 case "$risks" in *"config file .gitconfig"*) pass "config: an included file in the project" ;; *) fail "config: include: $risks" ;; esac
558702 case "$risks" in *"core.fsmonitor = ./watch.sh"*) pass "config: a command it sets" ;; *) fail "config: fsmonitor: $risks" ;; esac
559703 case "$risks" in *"filter.x.clean = scripts/clean.sh %f"*) pass "config: a relative command path" ;; *) fail "config: filter: $risks" ;; esac
@@ -565,7 +709,7 @@ if command -v git >/dev/null 2>&1; then
565709 ( git -C "$PROJ" config includeIf.gitdir:/.path ../later.gitconfig
566710 git -C "$PROJ" config --add include.path ../.git/x.gitconfig
567711 git -C "$PROJ" config --add include.path "$SB/outside.gitconfig" )
568删除: risks="$(_agent_vm_project_config_risks "$PROJ")"
712新增: risks="$(_agent_vm_share_config_risks "$PROJ")"
569713 case "$risks" in *"config file later.gitconfig"*) pass "config: an include of a file not there yet" ;; *) fail "config: missing include: $risks" ;; esac
570714 case "$risks" in *x.gitconfig*|*outside.gitconfig*) fail "config: an include in .git or outside the project listed: $risks" ;; *) pass "config: includes in .git or outside left out" ;; esac
571715 ( git -C "$PROJ" config --unset-all includeIf.gitdir:/.path
修改tests/16-setup.sh+9 −17看文件
@@ -34,23 +34,9 @@ esac
3434exit 0
3535STUB
3636chmod +x "$SB/wizlima/limactl"
37删除:( PATH="$SB/wizlima:$PATH"; AGENT_VM_STATE_DIR="$SB/wizstate"
38删除: _agent_vm_have_tty() { return 0; }
39删除: _agent_vm_ask_yn() {
40删除: case "$1" in
41删除: "Use this default") echo 0 ;;
42删除: "Use these defaults") echo 1 ;;
43删除: *) case "$2" in [Yy]) echo 1 ;; *) echo 0 ;; esac ;;
44删除: esac
45删除: }
46删除: _agent_vm_offer_git_protection() { :; }
47删除: _agent_vm_setup ) >/dev/null 2>&1
48删除:check "wizard defaults: Ruby, Rust, Go, Pi and Playwright MCP off; Claude on" \
49删除: "$(grep -E '^export AGENT_VM_INSTALL_(RUBY|RUST|GOLANG|PI|MCP_PLAYWRIGHT|CLAUDE)=' "$SB/wizard.stdin" 2>/dev/null | cut -d_ -f4- | tr '\n' ' ')" \
50删除: "RUBY=0 RUST=0 GOLANG=0 CLAUDE=1 PI=0 MCP_PLAYWRIGHT=0 "
51删除:
52删除:section "setup wizard: 4 GB of memory with code-server"
53删除:# CODE=1 answers yes to code-server. The host is big enough not to clamp.
37新增:# The wizard, every question answered with its default but those set:
38新增:# DEFAULT_SOFTWARE=1 takes the default set, CODE=1 picks code-server. The
39新增:# host is big enough not to clamp the memory, printed after.
5440wiz_memory() {
5541 rm -f "$SB/wizard.create"
5642 ( PATH="$SB/wizlima:$PATH"; AGENT_VM_STATE_DIR="$SB/wizstate"
@@ -69,6 +55,12 @@ wiz_memory() {
6955 _agent_vm_setup "$@" ) >/dev/null 2>&1
7056 grep -o -- '--memory=[0-9]*' "$SB/wizard.create" 2>/dev/null
7157}
58新增:wiz_memory >/dev/null
59新增:check "wizard defaults: Ruby, Rust, Go, Pi and Playwright MCP off; Claude on" \
60新增: "$(grep -E '^export AGENT_VM_INSTALL_(RUBY|RUST|GOLANG|PI|MCP_PLAYWRIGHT|CLAUDE)=' "$SB/wizard.stdin" 2>/dev/null | cut -d_ -f4- | tr '\n' ' ')" \
61新增: "RUBY=0 RUST=0 GOLANG=0 CLAUDE=1 PI=0 MCP_PLAYWRIGHT=0 "
62新增:
63新增:section "setup wizard: 4 GB of memory with code-server"
7264check "code-server picked: 4 GB" "$(CODE=1 wiz_memory)" "--memory=4"
7365check "code-server not picked: 3 GB" "$(CODE=0 wiz_memory)" "--memory=3"
7466check "default software (no code-server): 3 GB" "$(DEFAULT_SOFTWARE=1 wiz_memory)" "--memory=3"
修改tests/18-windows.sh+1 −1看文件
@@ -275,7 +275,7 @@ check "CRLF env files reach the VM without CRs" \
275275# which only the builtin SFTP server with readonlyNames enforces. On any other
276276# host the same VM gets 9p. A limactl of its own, reporting QEMU and no type.
277277mkdir -p "$SB/qemulima" "$SB/qemulima-home/agent-vm-w"
278删除:printf '#!/bin/sh\n[ "$1" = list ] && echo "qemu <nil>"\nexit 0\n' > "$SB/qemulima/limactl"
278新增:printf '#!/bin/sh\n[ "$1" = list ] && echo "qemu <nil> null"\nexit 0\n' > "$SB/qemulima/limactl"
279279chmod +x "$SB/qemulima/limactl"
280280echo 2.1.0 > "$SB/qemulima-home/agent-vm-w/lima-version"
281281enforced_on() { # <fake uname dir>
修改tests/20-project-files.sh+38 −8看文件
@@ -116,9 +116,9 @@ printf 'B=2\r\nA=project\r\n' > "$PF/.agent-vm.env"
116116out="$(PATH="$SB/localvm:$PATH" _agent_vm_push_env_and_probe vm "$PF" "A=shared" "$PF/.agent-vm.env" "$PF/.agent-vm.runtime.sh"; echo "rc=$?")"
117117check "the VM writes the shared payload, then the project's file, without CRs" \
118118 "$(od -c < "$GH/.agent-vm.env" | grep -c '\\r') $(tr '\n' ' ' < "$GH/.agent-vm.env")" "0 A=shared B=2 A=project "
119删除:check "and says it did, that the runtime is there, and that its write reached the project" \
120删除: "$(printf '%s' "$out" | tr '\n' ' ')" "env-ok runtime-found probe-written rc=0"
121删除:check "the write probe leaves no file in the project" "$(ls -A "$PF" | grep -c agent-vm-write-probe)" "0"
119新增:check "and says it did, that the runtime is there, and that it sees the project from this machine" \
120新增: "$(printf '%s' "$out" | tr '\n' ' ')" "env-ok runtime-found share-ok rc=0"
121新增:check "the probes leave no file in the project" "$(ls -A "$PF" | grep -c 'agent-vm-.*probe')" "0"
122122if _agent_vm_on_windows; then
123123 printf ' skip the guest env file is private (permission bits are emulated on Windows)\n'
124124else
@@ -126,10 +126,11 @@ else
126126fi
127127rm -f "$PF/.agent-vm.runtime.sh"
128128out="$(PATH="$SB/localvm:$PATH" _agent_vm_push_env_and_probe vm "$PF" "" "$PF/.agent-vm.env" "$PF/.agent-vm.runtime.sh")"
129删除:check "no runtime there: not found" "$(printf '%s' "$out" | tr '\n' ' ')" "env-ok probe-written"
130删除:# A write that stays in the VM: the share is not mounted (a guest whose
131删除:# project path is a directory of its own). `limactl shell <vm> sh -c <script>
132删除:# sh <dir> ...`: the script runs on that other directory.
129新增:check "no runtime there: not found" "$(printf '%s' "$out" | tr '\n' ' ')" "env-ok share-ok"
130新增:# The share is not mounted: a guest whose project path is a directory of its
131新增:# own, which does not hold what this machine put in the project. `limactl
132新增:# shell <vm> sh -c <script> sh <dir> ...`: the script runs on that other
133新增:# directory.
133134mkdir -p "$SB/guest-only" "$SB/lostvm"
134135cat > "$SB/lostvm/limactl" <<STUB
135136#!/usr/bin/env bash
@@ -140,8 +141,37 @@ HOME="$GH" exec sh -c "\$script" sh "$SB/guest-only" "\$@"
140141STUB
141142chmod +x "$SB/lostvm/limactl"
142143out="$(PATH="$SB/lostvm:$PATH" _agent_vm_push_env_and_probe vm "$PF" "" </dev/null; echo "rc=$?")"
143删除:case "$out" in *probe-written*"rc=2") pass "a write that does not reach the project: the share is not mounted" ;; *) fail "lost share: $out" ;; esac
144新增:case "$out" in *share-ok*) fail "lost share: seen as mounted: $out" ;; *"rc=2") pass "the project not seen from the VM: the share is not mounted" ;; *) fail "lost share: $out" ;; esac
145新增:check "and the VM's own directory is left empty" "$(ls -A "$SB/guest-only" | wc -l | tr -d ' ')" "0"
146新增:check "and the project too" "$(ls -A "$PF" | grep -c 'agent-vm-.*probe')" "0"
147新增:# A scratch VM shares nothing: nothing is put on this machine, and its own
148新增:# directory is left as it was.
149新增:out="$(scratch=1 PATH="$SB/lostvm:$PATH" _agent_vm_push_env_and_probe vm "$PF" "" </dev/null; echo "rc=$?")"
150新增:case "$out" in *"rc=0") pass "scratch: writable, on the VM's own disk" ;; *) fail "scratch probe: $out" ;; esac
151新增:check "scratch: its directory is left empty" "$(ls -A "$SB/guest-only" | wc -l | tr -d ' ')" "0"
144152rm -rf "$SB/guest-only" "$SB/lostvm"
153新增:# A command in the VM (_agent_vm_lima_run): `limactl shell ... -- zsh -l -c
154新增:# <script> agent-vm <command>`, run here.
155新增:if command -v zsh >/dev/null 2>&1; then
156新增: mkdir -p "$SB/runvm"
157新增: cat > "$SB/runvm/limactl" <<'STUB'
158新增:#!/usr/bin/env bash
159新增:while [ "$#" -gt 0 ] && [ "$1" != -- ]; do [ "$1" = --workdir ] && { cd "$2" || exit 1; shift; }; shift; done
160新增:shift
161新增:exec "$@"
162新增:STUB
163新增: chmod +x "$SB/runvm/limactl"
164新增: mkdir -p "$SB/runwd/adir"
165新增: printf '#!/bin/sh\necho ran\n' > "$SB/runwd/noexec.sh"
166新增: lrun() { PATH="$SB/runvm:$PATH" _agent_vm_lima_run vm "$SB/runwd" "" "$@" 2>&1; echo "rc=$?"; }
167新增: case "$(lrun agent-vm-nosuchcmd)" in *"agent-vm-nosuchcmd is not installed in this VM."*"rc=127") pass "run: a command not there, said so" ;; *) fail "run: missing: $(lrun agent-vm-nosuchcmd)" ;; esac
168新增: case "$(lrun ./noexec.sh)" in *"not installed"*) fail "run: a script without +x said not installed" ;; *"rc=126") pass "run: a script without +x, env's reason and status" ;; *) fail "run: noexec: $(lrun ./noexec.sh)" ;; esac
169新增: case "$(lrun ./adir)" in *"not installed"*) fail "run: a directory said not installed" ;; *"rc=126") pass "run: a directory, env's reason" ;; *) fail "run: dir: $(lrun ./adir)" ;; esac
170新增: case "$(lrun X=1 sh -c 'echo "$X"')" in *"1"*"rc=0") pass "run: an assignment before the command" ;; *) fail "run: assignment: $(lrun X=1 sh -c 'echo "$X"')" ;; esac
171新增: rm -rf "$SB/runvm" "$SB/runwd"
172新增:else
173新增: printf ' skip a command in the VM (zsh is not installed)\n'
174新增:fi
145175if command -v zsh >/dev/null 2>&1; then
146176 printf '#!/usr/bin/env bash\r\necho "ran:${BASH_VERSION:+bash}" > "$HOME/rt-out"\r\n' > "$PF/.agent-vm.runtime.sh"
147177 PATH="$SB/localvm:$PATH" _agent_vm_run_project_runtime vm "$PF" "$PF/.agent-vm.runtime.sh" >/dev/null 2>&1
修改tests/21-scratch.sh+7 −1看文件
@@ -7,7 +7,7 @@ SCR="agent-vm-proj-scratch-00000000"
77SCR_CLONED="$SB/scr-cloned"
88sc() {
99 : > "$REC"
10删除: rm -f "$REC.stopped" "$SCR_CLONED"
10新增: rm -f "$REC.stopped" "$REC.live" "$SCR_CLONED"
1111 ( cd "${SC_DIR:-$PROJ}" || exit 1
1212 export AGENT_VM_TEST_REC="$REC" AGENT_VM_TEST_VM="$SCR" AGENT_VM_TEST_PROTECTS="$PROTECTS" AGENT_VM_TEST_CLONED="$SCR_CLONED"
1313 _agent_vm_scratch_name() { echo "$SCR"; }
@@ -33,6 +33,12 @@ if [ -n "$d" ] && [ -n "$p" ] && [ "$d" -gt "$p" ]; then pass "then the VM is de
3333case "$out" in *"Deleting scratch VM '$SCR'"*) pass "and it says so" ;; *) fail "no notice: $out" ;; esac
3434grep -Eq "^(stop|delete|edit|start) $PV( |$)" "$REC" && fail "the folder's own VM was touched" || pass "the folder's own VM is left alone"
3535[ -e "$(_agent_vm_scratch_marker "$SCR")" ] && fail "the run's record outlived it" || pass "nothing left recorded"
36新增:[ -n "$(ls -A "$PROJ" | grep 'agent-vm-.*probe')" ] && fail "a probe file left in the folder" || pass "no probe file put in the folder"
37新增:# Lima's _config giving every VM a share: a scratch VM would not share
38新增:# nothing. Not started, and deleted.
39新增:out="$(AGENT_VM_TEST_LIVE_UNPROTECTED=1 AGENT_VM_TEST_STOPPED=1 sc --scratch run true; echo "rc=$?")"
40新增:case "$out" in *"shares agent-vm did not ask for"*"rc=1") pass "a share from Lima's _config stops it" ;; *) fail "scratch, _config: $out" ;; esac
41新增:rec_has "start $SCR" && fail "scratch, _config: started anyway" || pass "and it is not started"
3642
3743# Before the deletion, asked when it can be: a no opens a shell in the VM,
3844# and asks again on its exit. Yes, or an answer cut short, deletes. ANSWERS
修改tests/22-code.sh+36 −4看文件
@@ -14,8 +14,36 @@ check "host name: the VM's, lowercased" "$(_agent_vm_code_host agent-vm-My-Proj-
1414long="agent-vm-$(printf 'x%.0s' $(seq 1 80))-0a1b2c3d"
1515check "host name: a DNS label, the hash kept" \
1616 "$(_agent_vm_code_host "$long" | sed 's/\.localhost$//' | awk '{ print length($0) <= 63, substr($0, length($0) - 8) }')" "1 -0a1b2c3d"
17新增:check "the ten start at the last digits of the name's hash" "$(_agent_vm_code_ports agent-vm-a-0000270f)" \
18新增: "20008 20009 20010 20011 20012 20013 20014 20015 20016 20017 "
1719check "another VM, other ports" \
18删除: "$([ "$(_agent_vm_code_ports agent-vm-other-00000000)" != "$ports" ] && echo differ)" "differ"
20新增: "$([ "$(_agent_vm_code_ports agent-vm-a-00000001)" != "$(_agent_vm_code_ports agent-vm-b-00000002)" ] && echo differ)" "differ"
21新增:
22新增:# Which candidates something in the VM listens on, run as the VM does: any
23新增:# protocol (ss), or, without ss, any answer but a refused connection, never
24新增:# through the VM's proxy.
25新增:if command -v zsh >/dev/null 2>&1; then
26新增: mkdir -p "$SB/prep-bin" "$SB/prep-home"
27新增: printf '#!/bin/sh\nexit 0\n' > "$SB/prep-bin/code-server"
28新增: printf '#!/bin/sh\nexit 1\n' > "$SB/prep-bin/pgrep"
29新增: printf '#!/bin/sh\nprintf "LISTEN 0 4096 0.0.0.0:20001 0.0.0.0:*\\nLISTEN 0 128 [::]:20002 [::]:*\\n"\n' > "$SB/prep-bin/ss"
30新增: printf '#!/bin/sh\nfor a in "$@"; do [ "$a" = --noproxy ] && np=1; done\ncase "$*" in *:20000/*) exit 7 ;; *:20001/*) [ -n "$np" ] && exit 56 ;; esac\nexit 7\n' > "$SB/prep-curl"
31新增: chmod +x "$SB/prep-bin/"* "$SB/prep-curl"
32新增: prep() { HOME="$SB/prep-home" PATH="$1:$PATH" zsh -c "$_AGENT_VM_CODE_PREP" agent-vm-code 20000 20001 20002 2>/dev/null | grep '^listening=' | tr '\n' ' '; }
33新增: check "prep: what ss lists, whatever it speaks" "$(prep "$SB/prep-bin")" "listening=20001 listening=20002 "
34新增: rm "$SB/prep-bin/ss"
35新增: mkdir -p "$SB/prep-nossbin"
36新增: for t in sh awk sed grep cat od tr id mkdir head hostname; do
37新增: ln -sf "$(command -v "$t")" "$SB/prep-nossbin/$t" 2>/dev/null
38新增: done
39新增: cp "$SB/prep-bin/"* "$SB/prep-nossbin/"
40新增: cp "$SB/prep-curl" "$SB/prep-nossbin/curl"
41新增: prep_noss() { HOME="$SB/prep-home" http_proxy=http://127.0.0.1:9/ PATH="$SB/prep-nossbin" "$(command -v zsh)" -c "$_AGENT_VM_CODE_PREP" agent-vm-code 20000 20001 2>/dev/null | grep '^listening=' | tr '\n' ' '; }
42新增: check "prep without ss: a port that answers, not through the proxy" "$(prep_noss)" "listening=20001 "
43新增: rm -rf "$SB/prep-bin" "$SB/prep-nossbin" "$SB/prep-home" "$SB/prep-curl"
44新增:else
45新增: printf ' skip the editor prep run (zsh is not installed)\n'
46新增:fi
1947
2048if _agent_vm_host_port_open "$first"; then
2149 printf ' skip code launch tests (port %s is taken on this machine)\n' "$first"
@@ -38,9 +66,13 @@ else
3866 check "the Safari fallback, on macOS only" \
3967 "$(uname() { echo Linux; }; _agent_vm_code_say u 20000 pw 2>&1 | grep -c 127.0.0.1; uname() { echo Darwin; }; _agent_vm_code_say u 20000 pw 2>&1 | grep -c 'http://127.0.0.1:20000/')" \
4068 "$(printf '0\n1')"
41删除: # The user opens it: nothing is started on this machine.
42删除: grep -q 'xdg-open\|open "\$url"\|start "\$url"' "$AGENT_VM_SCRIPT_DIR/lib/code.sh" \
43删除: && fail "the browser is opened" || pass "the browser is not opened"
69新增: # The user opens it: no opener is run on this machine.
70新增: mkdir -p "$SB/openers"
71新增: for o in open xdg-open start; do printf '#!/bin/sh\n: > "%s/opened"\n' "$SB" > "$SB/openers/$o"; chmod +x "$SB/openers/$o"; done
72新增: rm -f "$SB/opened"
73新增: PATH="$SB/openers:$PATH" rec code >/dev/null
74新增: [ -e "$SB/opened" ] && fail "the browser is opened" || pass "the browser is not opened"
75新增: rm -rf "$SB/openers" "$SB/opened"
4476
4577 AGENT_VM_TEST_CODE_PREP="config=/c.yaml\npassword=pw\nlistening=$first\n" rec code >/dev/null
4678 rec_has "--bind-addr 127.0.0.1:$((first + 1))" \
修改www/src/i18n/en.ts+7 −5看文件
@@ -267,7 +267,7 @@ export const en = {
267267 optionsHeaders: ['Flag', 'What it does', 'Default'],
268268 options: [
269269 ['--disk GB', 'VM disk size. Can grow, never shrink.', 'the template’s (10)'],
270删除: ['--memory GB', 'VM memory. Clamped to half the host, per VM.', 'the template’s (3)'],
270新增: ['--memory GB', 'VM memory. Clamped to half the host, per VM.', 'the template’s (3, or 4 with code-server picked in the wizard)'],
271271 ['--cpus N', 'CPU count. Clamped to half the host, per VM.', 'the template’s (1)'],
272272 ['--ssh-port N', 'Fixed host port for the VM’s SSH, for tools that save it. `0` goes back to a new one on each start. Restarts a running VM, asked first.', 'a new one per start'],
273273 ['--reset', 'Destroy and re-clone the VM from the base template.', 'off'],
@@ -288,6 +288,7 @@ export const en = {
288288 ['AGENT_VM_BIN_DIR', 'Where `install` links `agent-vm`.', '~/.local/bin'],
289289 ['AGENT_VM_LIMA_DIR', 'Windows: where `setup` puts its Lima build.', '~/.local/share/lima-sylvinus'],
290290 ['AGENT_VM_QEMU_DIR', 'Windows: where QEMU is, when not on `PATH`.', '/c/Program Files/qemu'],
291新增: ['AGENT_VM_SSHFS_CACHE', '`1`: sshfs caches the writable shares too, faster on many files (`git status`, `find`); the VM may then see a file as it was up to 20 seconds before, and write that back. Applies when a VM is next started.', 'unset'],
291292 ['AGENT_VM_UNSAFE_WRITABLE_GIT', '`1`: same as `--unsafe-writable-git`.', 'unset'],
292293 ['AGENT_VM_UNSAFE_DISABLE_SECURITY_PROMPTS', '`1`: same as `--unsafe-disable-security-prompts`.', 'unset'],
293294 ],
@@ -442,7 +443,7 @@ export const en = {
442443 title: 'Why .git',
443444 paras: [
444445 'Git on your machine runs what a repository’s `.git/config` and hooks name: `core.fsmonitor` on every `git status`, hooks on commit. Your editor and prompt run `git status` on their own, so a VM able to write `.git` could run commands on your host within seconds, invisible in `git diff`.',
445删除: 'With a Lima that has `sshfs.readonlyNames`, every `.git` and `.hg` in the shares is read-only for the VM, at any depth, enforced on the host by Lima’s SFTP server. The agent reads the history but cannot commit. It is not merged upstream yet ([lima-vm/lima#5529](https://github.com/lima-vm/lima/issues/5529)), so `agent-vm setup` offers a build that has it. The shares then use `reverse-sshfs`, slower on many files (see [Node.js](#node)).',
446新增: 'With a Lima that has `sshfs.readonlyNames`, every `.git` and `.hg` in the shares is read-only for the VM, at any depth, enforced on the host by Lima’s SFTP server. The agent reads the history but cannot commit. It is not merged upstream yet ([lima-vm/lima#5529](https://github.com/lima-vm/lima/issues/5529)), so `agent-vm setup` offers a build that has it. The shares then use `reverse-sshfs`, slower on many files (see [Node.js](#node)), and without sshfs’s cache on the writable ones, so the VM never writes back a file as it was before you changed it: `AGENT_VM_SSHFS_CACHE=1` trades that for speed.',
446447 ],
447448 list: [],
448449 code: 'brew unlink lima; brew install sylvinus/tap/lima-sylvinus\nagent-vm doctor # where you stand\n\n# let the agent commit anyway\nagent-vm --unsafe-writable-git claude',
@@ -450,7 +451,7 @@ export const en = {
450451 {
451452 title: 'Beyond the name .git',
452453 paras: [
453删除: 'The folder a `core.hooksPath` points to in the project (`.husky` for husky) is read-only too. A folder holding git’s internals (`HEAD`, `objects/`, `refs/`, a `config`) is a repository under any name: setting `safe.bareRepository` to `explicit` in your global git config makes git ignore it. A config included from the project, or hooks at the top of a repository, are the same kind of door.',
454新增: 'The folder a `core.hooksPath` points to in a share (`.husky` for husky) is read-only too, as is a link on the way to it, and the same goes for the repositories in your writable volumes. A folder holding git’s internals (`HEAD`, `objects/`, `refs/`, a `config`) is a repository under any name: setting `safe.bareRepository` to `explicit` in your global git config makes git ignore it, and one in a writable volume is read-only by its name. A config included from a share, a command or a hook git runs from one, or hooks at the top of a share, are the same kind of door.',
454455 'Before a VM boots with writable shares, agent-vm stops on each of these it finds, and on a Lima without `readonlyNames`, and asks: Enter, or no terminal, aborts. `doctor` lists them. `--unsafe-writable-git` (or `AGENT_VM_UNSAFE_WRITABLE_GIT=1` in your shell, never read from the project) lets the agent commit and reopens that path to your host, with a warning on every run.',
455456 ],
456457 list: [],
@@ -530,7 +531,7 @@ export const en = {
530531 {
531532 title: 'SSH from your machine',
532533 paras: [
533删除: 'Do not connect VS Code Remote-SSH or open-remote-ssh to an agent VM. They run a server in the VM, which root in the VM controls, and the editor on your machine trusts it. Microsoft’s Remote-SSH page says so: “a compromised remote could use the VS Code Remote connection to execute code on your local machine”, and it is by design. Public write-ups show it opening a terminal on the host and running commands there. That removes the boundary agent-vm sets up, which is worse than opening the project in Restricted Mode. JetBrains Gateway most likely works the same way; it has not been checked. For language servers and a debugger with the VM’s packages, use [`agent-vm code`](#edit-with-the-vm-s-tools).',
534新增: 'Do not connect VS Code Remote-SSH or open-remote-ssh to an agent VM. They run a server in the VM, which root in the VM controls, and the editor on your machine trusts it. Microsoft’s Remote-SSH page says so: “a compromised remote could use the VS Code Remote connection to execute code on your local machine”, and it is by design. Public write-ups show it opening a terminal on the host and running commands there. That removes the boundary agent-vm sets up, which is worse than opening the project in Restricted Mode. JetBrains Gateway does not say it is safer: its security model page says what the backend loads goes to your machine without asking, the backend opens links there (after a prompt), and decides which client version your machine downloads. For language servers and a debugger with the VM’s packages, use [`agent-vm code`](#edit-with-the-vm-s-tools).',
534535 'For scripts, `scp` or `rsync`, `agent-vm info` prints the SSH alias as `ssh_host`. Put these lines at the top of `~/.ssh/config`: a `ForwardAgent yes` found before them would hand the VM your SSH keys. `--ssh-port` pins the port for tools that save it.',
535536 ],
536537 list: [],
@@ -580,7 +581,8 @@ export const en = {
580581 title: 'Network and ports',
581582 paras: [
582583 'The VM reaches the internet and every service on your machine’s loopback, at `192.168.5.2`. Lima forwards every port a VM listens on to your `127.0.0.1` when it is free: a VM that listens first on 5432 receives the connections, and passwords, meant for your local Postgres. Blocking this is [on the roadmap](#roadmap).',
583删除: 'So every VM can reach the editor of every other one. `agent-vm code` gives each its own password, made in that VM, and its own host name, `<vm-name>.localhost`: browsers keep cookies per host name and not per port, so at `127.0.0.1` any page a VM serves would receive the editor sessions of the others, and with them a way in. Chrome and Firefox resolve `*.localhost` themselves; Safari may not, and then `127.0.0.1` in a private window kept for the editor does the same.',
584新增: 'So every VM can reach the editor of every other one. `agent-vm code` gives each its own password, made in that VM, and its own host name, `<vm-name>.localhost`: browsers keep cookies per host name and not per port, so a page a VM serves at `127.0.0.1` does not receive the editor sessions of the others. Chrome and Firefox resolve `*.localhost` themselves; Safari may not, and then `127.0.0.1` in a private window kept for the editor does the same.',
585新增: 'That stops a page, not a VM bent on it. A VM can listen on a port Lima forwards to your machine and send your browser to another VM’s host name on that port: the browser hands it that editor’s session, and the VM can use it on the editor’s own port, with its terminals. Keeping VMs out of each other needs network isolation, which agent-vm does not have yet ([roadmap](#roadmap)). Until then, stop `agent-vm code` (Ctrl-C) when you are not using it, and treat an editor as reachable from every VM that runs.',
584586 ],
585587 list: [],
586588 code: '',
修改www/src/i18n/fr.ts+7 −5看文件
@@ -269,7 +269,7 @@ export const fr: Dictionary = {
269269 optionsHeaders: ['Option', 'Rôle', 'Défaut'],
270270 options: [
271271 ['--disk GB', 'Taille du disque. Peut grandir, jamais rétrécir.', 'celle de l\'image (10)'],
272删除: ['--memory GB', 'Mémoire de la VM. Plafonnée à la moitié de l\'hôte, par VM.', 'celle de l\'image (3)'],
272新增: ['--memory GB', 'Mémoire de la VM. Plafonnée à la moitié de l\'hôte, par VM.', 'celle de l\'image (3, ou 4 avec code-server choisi dans l\'assistant)'],
273273 ['--cpus N', 'Nombre de CPU. Plafonné à la moitié de l\'hôte, par VM.', 'celui de l\'image (1)'],
274274 ['--ssh-port N', 'Port fixe sur l\'hôte pour le SSH de la VM, pour les outils qui l\'enregistrent. `0` revient à un nouveau port à chaque démarrage. Redémarre une VM en marche, après confirmation.', 'un nouveau par démarrage'],
275275 ['--reset', 'Détruit la VM et la re-clone depuis l\'image de base.', 'inactif'],
@@ -290,6 +290,7 @@ export const fr: Dictionary = {
290290 ['AGENT_VM_BIN_DIR', 'Où `install` place le lien `agent-vm`.', '~/.local/bin'],
291291 ['AGENT_VM_LIMA_DIR', 'Windows : où `setup` installe sa version de Lima.', '~/.local/share/lima-sylvinus'],
292292 ['AGENT_VM_QEMU_DIR', 'Windows : où trouver QEMU, s\'il n\'est pas dans le `PATH`.', '/c/Program Files/qemu'],
293新增: ['AGENT_VM_SSHFS_CACHE', '`1` : sshfs met aussi en cache les partages modifiables, plus rapide sur beaucoup de fichiers (`git status`, `find`) ; la VM peut alors voir un fichier tel qu\'il était jusqu\'à 20 secondes avant, et le réécrire ainsi. S\'applique au prochain démarrage d\'une VM.', 'non définie'],
293294 ['AGENT_VM_UNSAFE_WRITABLE_GIT', '`1` : équivaut à `--unsafe-writable-git`.', 'non définie'],
294295 ['AGENT_VM_UNSAFE_DISABLE_SECURITY_PROMPTS', '`1` : équivaut à `--unsafe-disable-security-prompts`.', 'non définie'],
295296 ],
@@ -444,7 +445,7 @@ export const fr: Dictionary = {
444445 title: 'Pourquoi .git',
445446 paras: [
446447 'Git, sur ta machine, exécute ce que désignent le `.git/config` et les hooks d\'un dépôt : `core.fsmonitor` à chaque `git status`, les hooks au commit. Ton éditeur et ton prompt lancent `git status` d\'eux-mêmes : une VM capable d\'écrire dans `.git` pourrait lancer des commandes sur ton hôte en quelques secondes, sans que rien n\'apparaisse dans `git diff`.',
447删除: 'Avec un Lima qui a `sshfs.readonlyNames`, chaque `.git` et `.hg` des partages est en lecture seule pour la VM, à toute profondeur, et c\'est le serveur SFTP de Lima, sur l\'hôte, qui l\'impose. L\'agent lit l\'historique mais ne peut pas commiter. Ce n\'est pas encore intégré en amont ([lima-vm/lima#5529](https://github.com/lima-vm/lima/issues/5529)) : `agent-vm setup` propose une version qui l\'a. Les partages passent alors en `reverse-sshfs`, plus lent sur beaucoup de fichiers (voir [Node.js](#node)).',
448新增: 'Avec un Lima qui a `sshfs.readonlyNames`, chaque `.git` et `.hg` des partages est en lecture seule pour la VM, à toute profondeur, et c\'est le serveur SFTP de Lima, sur l\'hôte, qui l\'impose. L\'agent lit l\'historique mais ne peut pas commiter. Ce n\'est pas encore intégré en amont ([lima-vm/lima#5529](https://github.com/lima-vm/lima/issues/5529)) : `agent-vm setup` propose une version qui l\'a. Les partages passent alors en `reverse-sshfs`, plus lent sur beaucoup de fichiers (voir [Node.js](#node)), et sans le cache de sshfs sur ceux qui sont modifiables, pour que la VM ne réécrive jamais un fichier tel qu\'il était avant que tu le changes : `AGENT_VM_SSHFS_CACHE=1` échange cela contre de la vitesse.',
448449 ],
449450 list: [],
450451 code: 'brew unlink lima; brew install sylvinus/tap/lima-sylvinus\nagent-vm doctor # où tu en es\n\n# laisser l\'agent commiter quand même\nagent-vm --unsafe-writable-git claude',
@@ -452,7 +453,7 @@ export const fr: Dictionary = {
452453 {
453454 title: 'Au-delà du nom .git',
454455 paras: [
455删除: 'Le dossier vers lequel pointe un `core.hooksPath` du projet (`.husky` pour husky) est aussi en lecture seule. Un dossier qui contient les fichiers internes de git (`HEAD`, `objects/`, `refs/`, un `config`) est un dépôt sous n\'importe quel nom : régler `safe.bareRepository` à `explicit` dans ta config git globale le fait ignorer par git. Une config incluse depuis le projet, ou des hooks à la racine d\'un dépôt, ouvrent la même porte.',
456新增: 'Le dossier vers lequel pointe un `core.hooksPath` dans un partage (`.husky` pour husky) est aussi en lecture seule, comme un lien sur le chemin qui y mène, et de même pour les dépôts de tes volumes modifiables. Un dossier qui contient les fichiers internes de git (`HEAD`, `objects/`, `refs/`, un `config`) est un dépôt sous n\'importe quel nom : régler `safe.bareRepository` à `explicit` dans ta config git globale le fait ignorer par git, et celui d\'un volume modifiable est en lecture seule par son nom. Une config incluse depuis un partage, une commande ou un hook que git y lance, ou des hooks à la racine d\'un partage, ouvrent la même porte.',
456457 'Avant de démarrer une VM aux partages modifiables, agent-vm s\'arrête sur chacun de ceux qu\'il trouve, et sur un Lima sans `readonlyNames`, pour demander : Entrée, ou l\'absence de terminal, annule. `doctor` les liste. `--unsafe-writable-git` (ou `AGENT_VM_UNSAFE_WRITABLE_GIT=1` dans ton shell, jamais lu depuis le projet) laisse l\'agent commiter et rouvre ce chemin vers ton hôte, avec un avertissement à chaque lancement.',
457458 ],
458459 list: [],
@@ -532,7 +533,7 @@ export const fr: Dictionary = {
532533 {
533534 title: 'SSH depuis ta machine',
534535 paras: [
535删除: 'Ne branche pas VS Code Remote-SSH ou open-remote-ssh sur une VM d\'agent. Ils font tourner un serveur dans la VM, que contrôle root dans la VM, et l\'éditeur sur ta machine lui fait confiance. La page de Remote-SSH chez Microsoft le dit : « a compromised remote could use the VS Code Remote connection to execute code on your local machine », et c\'est voulu. Des articles publics le montrent ouvrant un terminal sur l\'hôte et y lançant des commandes. Cela supprime la frontière que pose agent-vm, ce qui est pire qu\'ouvrir le projet en mode restreint. JetBrains Gateway fonctionne très probablement de la même façon ; ce n\'est pas vérifié. Pour les serveurs de langage et un débogueur avec les paquets de la VM, utilise [`agent-vm code`](#edit-with-the-vm-s-tools).',
536新增: 'Ne branche pas VS Code Remote-SSH ou open-remote-ssh sur une VM d\'agent. Ils font tourner un serveur dans la VM, que contrôle root dans la VM, et l\'éditeur sur ta machine lui fait confiance. La page de Remote-SSH chez Microsoft le dit : « a compromised remote could use the VS Code Remote connection to execute code on your local machine », et c\'est voulu. Des articles publics le montrent ouvrant un terminal sur l\'hôte et y lançant des commandes. Cela supprime la frontière que pose agent-vm, ce qui est pire qu\'ouvrir le projet en mode restreint. JetBrains Gateway ne se dit pas plus sûr : sa page sur le modèle de sécurité dit que ce que charge le backend arrive sur ta machine sans rien demander, que le backend y ouvre des liens (après confirmation) et décide de la version du client qu\'elle télécharge. Pour les serveurs de langage et un débogueur avec les paquets de la VM, utilise [`agent-vm code`](#edit-with-the-vm-s-tools).',
536537 'Pour des scripts, `scp` ou `rsync`, `agent-vm info` affiche l\'alias SSH comme `ssh_host`. Mets ces lignes en haut de `~/.ssh/config` : un `ForwardAgent yes` trouvé avant elles donnerait tes clés SSH à la VM. `--ssh-port` fixe le port pour les outils qui l\'enregistrent.',
537538 ],
538539 list: [],
@@ -582,7 +583,8 @@ export const fr: Dictionary = {
582583 title: 'Réseau et ports',
583584 paras: [
584585 'La VM atteint Internet et tous les services de la boucle locale de ta machine, à `192.168.5.2`. Lima redirige chaque port qu\'écoute une VM vers ton `127.0.0.1` s\'il est libre : une VM qui écoute la première sur 5432 reçoit les connexions, et les mots de passe, destinés à ton Postgres local. Le bloquer est [sur la feuille de route](#roadmap).',
585删除: 'Chaque VM peut donc joindre l\'éditeur de toutes les autres. `agent-vm code` donne à chacune son propre mot de passe, créé dans cette VM, et son propre nom d\'hôte, `<nom-de-vm>.localhost` : les navigateurs rangent les cookies par nom d\'hôte et non par port, si bien qu\'à `127.0.0.1` n\'importe quelle page servie par une VM recevrait les sessions d\'éditeur des autres, et avec elles une porte d\'entrée. Chrome et Firefox résolvent `*.localhost` eux-mêmes ; Safari peut ne pas le faire, et `127.0.0.1` dans une fenêtre privée réservée à l\'éditeur fait alors la même chose.',
586新增: 'Chaque VM peut donc joindre l\'éditeur de toutes les autres. `agent-vm code` donne à chacune son propre mot de passe, créé dans cette VM, et son propre nom d\'hôte, `<nom-de-vm>.localhost` : les navigateurs rangent les cookies par nom d\'hôte et non par port, si bien qu\'une page servie par une VM à `127.0.0.1` ne reçoit pas les sessions d\'éditeur des autres. Chrome et Firefox résolvent `*.localhost` eux-mêmes ; Safari peut ne pas le faire, et `127.0.0.1` dans une fenêtre privée réservée à l\'éditeur fait alors la même chose.',
587新增: 'Cela arrête une page, pas une VM décidée. Une VM peut écouter sur un port que Lima transfère vers ta machine et envoyer ton navigateur au nom d\'hôte d\'une autre VM sur ce port : le navigateur lui remet la session de cet éditeur, que la VM peut utiliser sur le port de l\'éditeur, avec ses terminaux. Tenir les VM à l\'écart les unes des autres demande une isolation réseau, qu\'agent-vm n\'a pas encore ([feuille de route](#roadmap)). D\'ici là, arrête `agent-vm code` (Ctrl-C) quand tu ne t\'en sers pas, et considère qu\'un éditeur est joignable par chaque VM qui tourne.',
586588 ],
587589 list: [],
588590 code: '',