跳到主要内容

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

提交记录
修改CHANGELOG.md+38 −3看文件
@@ -4,8 +4,9 @@
44
55### Added
66
7删除:- `agent-vm code`: VS Code (code-server) served from the VM and opened in
8删除: the browser, until Ctrl-C. Opt-in at setup: `--preinstall=code-server`
7新增:- `agent-vm code`: VS Code (code-server) served from the VM, until Ctrl-C.
8新增: Its address and password are printed in a box, for you to open in the
9新增: browser. Opt-in at setup: `--preinstall=code-server`
910 for the editor alone, `code-claude`, `code-codex` and `code-vibe` for it
1011 with that agent's extension, each starting with no permission prompts.
1112 The wizard asks about the editor after the agents, then whether the
@@ -23,12 +24,46 @@
2324 per port, so at `127.0.0.1` a page served by any VM would get the session
2425 of every editor, which logs into it. Safari may not resolve `*.localhost`:
2526 then `127.0.0.1` in a private window kept for the editor. code-server's
26删除: port proxy is off.
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.
30新增:- With code-server picked in the wizard, the base gets 4 GB of memory
31新增: instead of 3, unless `--memory` says otherwise.
2732
2833### Changed
2934
3035- A command that is not in the VM (`agent-vm run foo`, or an agent not
3136 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新增: with its shares, with a warning that what it wrote meanwhile is on its own
44新增: disk.
45新增:
46新增:### Security
47新增:
48新增:- The check for a Lima with `sshfs.readonlyNames` no longer depends on the
49新增: mount type: with `mountType: reverse-sshfs` in Lima's
50新增: `_config/override.yaml`, a Lima that has it was taken for one that does
51新增: not.
52新增:- A VM recorded as protected is checked against the shares Lima has for it:
53新增: 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.
3267
3368## 0.2.0
3469
修改agent-vm.setup.sh+13 −6看文件
@@ -390,8 +390,6 @@ if [[ "$INSTALL_CODE_SERVER" == "1" ]]; then
390390 # schema: setup does, once, into the machine settings (code_server_schemas).
391391 # The rest is the welcome page, tips, recommendations, experiments and
392392 # online settings search.
393删除: # The Claude keys start its conversations in bypass mode, as the managed
394删除: # settings above do for the CLI.
395393 mkdir -p "$HOME/.local/share/code-server/User"
396394 jq -n --arg claude "$INSTALL_CODE_CLAUDE" '
397395 {
@@ -413,8 +411,6 @@ if [[ "$INSTALL_CODE_SERVER" == "1" ]]; then
413411 "update.mode": "none",
414412 "update.showReleaseNotes": false
415413 } + if $claude == "1" then {
416删除: "claudeCode.allowDangerouslySkipPermissions": true,
417删除: "claudeCode.initialPermissionMode": "bypassPermissions",
418414 "claudeCode.hideOnboarding": true
419415 } else {} end' > "$HOME/.local/share/code-server/User/settings.json"
420416 # The .deb's /usr/bin/code-server is a script running /usr/lib/code-server;
@@ -424,8 +420,19 @@ if [[ "$INSTALL_CODE_SERVER" == "1" ]]; then
424420 cs_root="$(dirname "$(dirname "$(readlink -f "$(command -v code-server)")")")"
425421 fi
426422 echo "Downloading the JSON schemas the editor uses..."
427删除: code_server_schemas "$cs_root/lib/vscode/extensions" \
428删除: "$HOME/.local/share/code-server/Machine/settings.json"
423新增: cs_machine="$HOME/.local/share/code-server/Machine/settings.json"
424新增: code_server_schemas "$cs_root/lib/vscode/extensions" "$cs_machine"
425新增: # Claude's conversations start in bypass mode, as the managed settings above
426新增: # do for the CLI. These keys are machine-scoped: code-server ignores them in
427新增: # the user settings.
428新增: 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 '. + {
431新增: "claudeCode.allowDangerouslySkipPermissions": true,
432新增: "claudeCode.initialPermissionMode": "bypassPermissions"
433新增: }' > "$cs_machine.tmp"
434新增: mv "$cs_machine.tmp" "$cs_machine"
435新增: fi
429436 # Codex and Vibe have no setting for it: their extensions start in the mode
430437 # the agent's own config names. These match the flags the command line gets
431438 # (_agent_vm_agent in agent-vm.sh).
修改agent-vm.sh+51 −10看文件
@@ -166,11 +166,11 @@ _agent_vm_start_checks() {
166166 fi
167167 hooks_names+=("$hooks_name")
168168 hooks_notes="$hooks_notes$(_agent_vm_hooks_note "$hooks_rel" "$hooks_name")"$'\n'
169删除: done <<< "$(_agent_vm_project_hooks "$host_dir")"
169新增: done <<< "$(_agent_vm_share_hooks "$host_dir")"
170170 ro_names="$(_agent_vm_names_json ${hooks_names[@]+"${hooks_names[@]}"})"
171171
172172 local git_risks=""
173删除: [[ -n "$rdonly" ]] || git_risks="$(_agent_vm_project_config_risks "$host_dir")"
173新增: [[ -n "$rdonly" ]] || git_risks="$(_agent_vm_share_config_risks "$host_dir")"
174174 if [[ -n "$git_risks" ]]; then
175175 echo "Warning: git on this machine uses these, and the VM can write them:" >&2
176176 printf '%s\n' "$git_risks" | sed 's/^/ /' >&2
@@ -245,12 +245,19 @@ _agent_vm_apply_resources() {
245245}
246246
247247# The env push and the write probe (see _agent_vm_push_env_and_probe), with
248删除:# the caller's vm_name, host_dir, env_payload, guest_env and guest_runtime,
249删除:# into its probe_out and is_writable.
248新增:# the caller's vm_name, host_dir, env_payload, guest_env, guest_runtime and
249新增:# 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.
250252_agent_vm_push_and_probe() {
251删除: is_writable="false"
253新增: local st=0
252254 probe_out="$(_agent_vm_push_env_and_probe "$vm_name" "$host_dir" "$env_payload" \
253删除: "$guest_env" "$guest_runtime")" && is_writable="true"
255新增: "$guest_env" "$guest_runtime")" || st=$?
256新增: case "$st" in
257新增: 0) is_writable="true" ;;
258新增: 2) if [[ -n "$scratch" ]]; then is_writable="true"; else is_writable="lost"; fi ;;
259新增: *) is_writable="false" ;;
260新增: esac
254261 [[ "$probe_out" == *env-ok* ]] || echo "Warning: failed to push the env files into VM '$vm_name'." >&2
255262}
256263
@@ -420,13 +427,32 @@ _agent_vm_ensure_running() {
420427 # names (names_stale), the mode (mode_stale). A stopped VM is changed before
421428 # it boots, so nothing starting with it gets a writable window; a running
422429 # one keeps its shares until stopped, or is offered a restart.
423删除: local was_protected="" git_stale="" names_stale="" mode_stale=""
430新增: local was_protected="" git_stale="" names_stale="" mode_stale="" cache_stale=""
424431 _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=""
445新增: fi
425446 [[ "$was_protected" != "$protect_git" ]] && git_stale=1
426447 if [[ -n "$protect_git" && -n "$was_protected" ]] \
427448 && ! _agent_vm_mounts_have_readonly_names "$vm_name" "$ro_names"; then
428449 names_stale=1
429450 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
455新增: fi
430456 if [[ -n "$scratch" ]]; then
431457 # Shares nothing, as made: nothing to bring in line.
432458 git_stale=""
@@ -463,7 +489,7 @@ _agent_vm_ensure_running() {
463489 fi
464490 elif [[ -n "$names_stale" && -n "$was_running" ]]; then
465491 :
466删除: elif [[ -z "$was_running" && ( -n "$git_stale" || -n "$names_stale" || -n "$mode_stale" ) ]]; then
492新增: elif [[ -z "$was_running" && ( -n "$git_stale" || -n "$names_stale" || -n "$mode_stale" || -n "$cache_stale" ) ]]; then
467493 if [[ -n "$git_stale" ]]; then
468494 if [[ -n "$protect_git" ]]; then
469495 echo "Making every .git read-only for VM '$vm_name'..."
@@ -487,6 +513,14 @@ _agent_vm_ensure_running() {
487513 _agent_vm_apply_shares "$vm_name" "$host_dir" "$want_writable" || return 1
488514 fi
489515
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新增:
490524 if [[ -z "$was_running" ]]; then
491525 echo "Starting VM '$vm_name'..."
492526 local start_log
@@ -543,7 +577,10 @@ _agent_vm_ensure_running() {
543577 # yanking a running session out from under another terminal, in both
544578 # directions. The repair direction does not ask: a broken mount is
545579 # already unusable.
546删除: if [[ "$want_writable" == "true" && -n "$was_running" ]] && _agent_vm_mounts_all_readonly "$vm_name"; then
580新增: if [[ "$is_writable" == lost ]]; then
581新增: echo "Warning: the project share is not mounted in VM '$vm_name': what was written in $host_dir in the VM since then is on the VM's own disk, and hidden once the share is back." >&2
582新增: echo "Project share is not mounted; repairing..." >&2
583新增: elif [[ "$want_writable" == "true" && -n "$was_running" ]] && _agent_vm_mounts_all_readonly "$vm_name"; then
547584 echo "VM '$vm_name' runs read-only (--readonly). It must be restarted to make its shares writable."
548585 if ! _agent_vm_can_ask || [[ "$(_agent_vm_ask_yn "Stop the VM and make it writable? Sessions using it are cut." N)" != "1" ]]; then
549586 echo "Error: not restarted. Pass --readonly to use it as it is, or 'agent-vm stop' it first." >&2
@@ -578,7 +615,11 @@ _agent_vm_ensure_running() {
578615 # env file and runtime script.
579616 _agent_vm_push_and_probe
580617 if [[ "$is_writable" != "$want_writable" ]]; then
581删除: if [[ "$want_writable" == "true" ]]; then
618新增: if [[ "$is_writable" == lost ]]; then
619新增: echo "Error: the project share did not mount in VM '$vm_name':" >&2
620新增: echo " $host_dir" >&2
621新增: echo "Lima's log: $(_agent_vm_lima_home)/$vm_name/ha.stderr.log" >&2
622新增: elif [[ "$want_writable" == "true" ]]; then
582623 echo "Error: project directory is still not writable inside the VM:" >&2
583624 echo " $host_dir" >&2
584625 echo "The host mount failed to attach. Try 'agent-vm --reset <command>'" >&2
修改lib/code.sh+24 −40看文件
@@ -1,4 +1,4 @@
1删除:# --- code: code-server in the VM, opened in the host's browser ----------------
1新增:# --- code: code-server in the VM, for the host's browser ----------------------
22
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
@@ -58,35 +58,19 @@ _agent_vm_host_port_open() {
5858 (exec 3<>"/dev/tcp/127.0.0.1/$1") 2>/dev/null
5959}
6060
61删除:# The editor's <url> on <port>, and its <password>. Safari leaves *.localhost
62删除:# to macOS, which may not resolve it: 127.0.0.1 then, in a window of its own.
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.
6364_agent_vm_code_say() {
64删除: echo "Editor: $1"
65删除: echo "Password: $3"
66删除: if [[ "$(uname -s)" == Darwin ]]; then
67删除: echo "(Safari may not resolve it: then http://127.0.0.1:$2/, in a private window kept for this editor, so pages from other VMs never get its cookie.)"
68删除: fi
69删除:}
70删除:
71删除:# Open <url> in the host's browser once Lima forwards <port>.
72删除:_agent_vm_code_open() {
73删除: local url="$1" port="$2" i=0
74删除: until _agent_vm_host_port_open "$port"; do
75删除: i=$((i + 1))
76删除: if [[ $i -ge 60 ]]; then
77删除: echo "Warning: nothing on 127.0.0.1:$port after 60s: Lima did not forward the editor's port." >&2
78删除: return 1
65新增: {
66新增: echo " Address: $1"
67新增: echo " Password: $3"
68新增: if [[ "$(uname -s)" == Darwin ]]; then
69新增: echo ""
70新增: echo "If Safari does not open it: http://127.0.0.1:$2/ in a private window kept for this editor, so pages from other VMs never get its cookie."
7971 fi
80删除: sleep 1
81删除: done
82删除: if _agent_vm_on_windows; then
83删除: start "$url"
84删除: elif [[ "$(uname -s)" == Darwin ]]; then
85删除: open "$url"
86删除: elif [[ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ]] && command -v xdg-open >/dev/null 2>&1; then
87删除: xdg-open "$url"
88删除: fi >/dev/null 2>&1
89删除: return 0
72新增: [[ -z "${4:-}" ]] || printf '\n%s\n' "$4"
73新增: } | _agent_vm_box "VS Code"
9074}
9175
9276# `agent-vm code`: code-server for the project, in the foreground until
@@ -104,7 +88,7 @@ _agent_vm_code() {
10488
10589_agent_vm_code_session() {
10690 local vm_name="$1" host_dir="$2" ports out line cfg="" pw="" running="" listening=" " port="" p
107删除: local url opener="" want_tty="" st=0
91新增: local url want_tty="" st=0
10892 ports="$(_agent_vm_code_ports "$vm_name")" || {
10993 echo "Error: cannot hash the VM name: install shasum or sha256sum." >&2
11094 return 1
@@ -135,9 +119,7 @@ _agent_vm_code_session() {
135119
136120 if [[ -n "$running" ]]; then
137121 url="http://$(_agent_vm_code_host "$vm_name"):$running/"
138删除: echo "The editor of VM '$vm_name' already runs, from another terminal."
139删除: _agent_vm_code_say "$url" "$running" "$pw"
140删除: [[ -t 1 ]] && _agent_vm_code_open "$url" "$running"
122新增: _agent_vm_code_say "$url" "$running" "$pw" "The editor of VM '$vm_name' already runs, from another terminal."
141123 return 0
142124 fi
143125
@@ -155,12 +137,7 @@ _agent_vm_code_session() {
155137 fi
156138
157139 url="http://$(_agent_vm_code_host "$vm_name"):$port/"
158删除: _agent_vm_code_say "$url" "$port" "$pw"
159删除: echo "The password is kept in the VM, in $cfg. Ctrl-C stops the editor."
160删除: if [[ -t 1 ]]; then
161删除: _agent_vm_code_open "$url" "$port" &
162删除: opener=$!
163删除: fi
140新增: _agent_vm_code_say "$url" "$port" "$pw" "The password is kept in the VM, in $cfg. Ctrl-C stops the editor."
164141 # A terminal for Ctrl-C to reach code-server: without one, it would keep
165142 # running in the VM once this command ends.
166143 [[ -t 0 && -t 1 ]] && want_tty=1
@@ -171,7 +148,13 @@ _agent_vm_code_session() {
171148 # The --vscode-option ones reach the VS Code server inside: no experiments,
172149 # and the built-in Copilot Chat never loads (it updates itself otherwise).
173150 # The settings written at setup do the rest (agent-vm.setup.sh).
174删除: _agent_vm_lima_run "$vm_name" "$host_dir" "$want_tty" code-server \
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.
156新增: _agent_vm_lima_run "$vm_name" "$host_dir" "$want_tty" \
157新增: 'VSCODE_PROXY_URI=http://localhost:{{port}}/' code-server \
175158 --config "$cfg" \
176159 --bind-addr "127.0.0.1:$port" \
177160 --cookie-suffix "$vm_name" \
@@ -181,9 +164,10 @@ _agent_vm_code_session() {
181164 --disable-workspace-trust \
182165 --disable-proxy \
183166 --disable-getting-started-override \
167新增: --link-protection-trusted-domains https://claude.com/cai/oauth \
168新增: --link-protection-trusted-domains https://platform.claude.com/oauth \
184169 --vscode-option disable-experiments \
185170 --vscode-option disable-extension=GitHub.copilot-chat \
186171 "$host_dir" || st=$?
187删除: [[ -z "$opener" ]] || kill "$opener" 2>/dev/null
188172 return "$st"
189173}
修改lib/doctor.sh+2 −2看文件
@@ -308,11 +308,11 @@ _agent_vm_doctor() {
308308 $d warn "$hooks_what, which the VM can still write" \
309309 "The next start (after 'agent-vm stop' if it runs) makes every '$hooks_name' in the project read-only."
310310 fi
311删除: done <<< "$(_agent_vm_project_hooks "$host_dir")"
311新增: done <<< "$(_agent_vm_share_hooks "$host_dir")"
312312 # Git config the VM can write, or commands it names in the project (see
313313 # _agent_vm_repo_config_risks).
314314 local git_risks
315删除: git_risks="$(_agent_vm_project_config_risks "$host_dir")"
315新增: git_risks="$(_agent_vm_share_config_risks "$host_dir")"
316316 if [[ -n "$git_risks" ]]; then
317317 $d warn "git on this machine uses these, and the VM can write them:"
318318 printf '%s\n' "$git_risks" | sed 's/^/ /'
修改lib/git.sh+96 −20看文件
@@ -25,19 +25,21 @@ AGENT_VM_LIMA_ISSUE="https://github.com/lima-vm/lima/issues/5529"
2525
2626# Does this Lima enforce sshfs.readonlyNames? 0 yes, 1 no, 2 cannot tell.
2727# Stock Lima accepts the field and ignores it, with a mere warning, so support
28删除:# is probed, never assumed: `limactl validate` on a config pairing it with
29删除:# virtiofs, which a Lima that knows the field rejects, naming it. One that
30删除:# does not know it warns about an "unknown field". Any other answer (no
31删除:# limactl, a failure that names neither, a Lima that accepts the file without
32删除:# a word) is "cannot tell", never "no": callers must not drop the protection
33删除:# of a VM on an answer they could not read.
28新增:# is probed, never assumed: `limactl validate` on a config giving it a name
29新增:# with a slash, which a Lima that knows the field rejects, naming it, whatever
30新增:# mount type Lima's _config/override.yaml imposes (with another than
31新增:# reverse-sshfs, it rejects that too). One that does not know it warns about
32新增:# an "unknown field". Any other answer (no limactl, a failure that names
33新增:# neither, a Lima that accepts the file without a word) is "cannot tell",
34新增:# never "no": callers must not drop the protection of a VM on an answer they
35新增:# could not read.
3436#
3537# Not cached: agent-vm is also a shell function, where a cached answer would
3638# outlive a Lima upgrade.
3739_agent_vm_lima_protects_git() {
3840 local dir out accepted=""
3941 dir="$(mktemp -d 2>/dev/null)" || return 2
40删除: printf 'images: [{location: "/"}]\nmountType: virtiofs\nmounts: [{location: "%s", sshfs: {sftpDriver: builtin, readonlyNames: [.git]}}]\n' \
42新增: printf 'images: [{location: "/"}]\nmountType: reverse-sshfs\nmounts: [{location: "%s", sshfs: {sftpDriver: builtin, readonlyNames: [a/b]}}]\n' \
4143 "$(_agent_vm_host_path "$dir")" > "$dir/probe.yaml"
4244 out="$(limactl validate "$(_agent_vm_host_path "$dir/probe.yaml")" 2>&1)" && accepted=1
4345 rm -rf "$dir"
@@ -151,20 +153,56 @@ _agent_vm_project_repos() {
151153# names it: lib/x/.githooks is .githooks), or the same again. Fails otherwise,
152154# or when git cannot tell. `--git-path` without --path-format (git 2.31)
153155# 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.
154160_agent_vm_repo_hooks() {
155删除: local repo="$1" proj="$2" base top top_rel hooks rel in_repo
161新增: local repo="$1" proj="$2" base top top_rel hooks phys h rel in_repo found=""
156162 base="$(_agent_vm_git_spelling "$repo")" || return 1
157删除: hooks="$(_agent_vm_git_untrusted -C "$repo" rev-parse --git-path hooks 2>/dev/null)" || 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"
173新增: fi
174新增: printf '%s\t%s\n' "$rel" "$in_repo"
175新增: found=1
176新增: done
177新增: [[ -n "$found" ]]
178新增:}
179新增:
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
158186 [[ -n "$hooks" && "$hooks" != *$'\n'* && "$hooks" != *$'\t'* ]] || return 1
159删除: hooks="$(_agent_vm_git_abs "$hooks" "$base")"
160删除: rel="$(_agent_vm_rel_in "$hooks" "$proj")" || return 1
161删除: [[ "$rel" == . ]] || ! _agent_vm_under_readonly_name "$rel" || return 1
162删除: in_repo="$rel"
163删除: if top="$(_agent_vm_git_untrusted -C "$repo" rev-parse --show-toplevel 2>/dev/null)" \
164删除: && top_rel="$(_agent_vm_rel_in "$top" "$proj")" && [[ "$top_rel" != . ]]; then
165删除: in_repo="$(_agent_vm_rel_in "$hooks" "$top")" || in_repo="$rel"
166删除: fi
167删除: printf '%s\t%s\n' "$rel" "$in_repo"
187新增: _agent_vm_git_abs "$hooks" "$base"
188新增:}
189新增:
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
195新增: 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" ;;
201新增: esac
202新增: done
203新增: [[ -e "$f" ]] || return 1
204新增: d="$(_agent_vm_git_spelling "$(dirname "$f")")" || return 1
205新增: printf '%s/%s\n' "${d%/}" "$(basename "$f")"
168206}
169207
170208# Every hooks folder of the project <dir>'s repositories that is in the
@@ -178,6 +216,21 @@ _agent_vm_project_hooks() {
178216 done | awk '!seen[$0]++'
179217}
180218
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.
223新增:_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")"
232新增:}
233新增:
181234# The name that keeps the hooks folder <rel> read-only: its first component,
182235# which covers the folder and whatever it calls next to it (husky's hooks call
183236# .husky/<hook>). Fails for the project itself, and for a name the mounts JSON
@@ -207,7 +260,7 @@ _agent_vm_readonly_names() {
207260 while IFS=$'\t' read -r rel in_repo; do
208261 [[ -n "$rel" ]] || continue
209262 name="$(_agent_vm_hooks_name "$in_repo")" && names+=("$name")
210删除: done <<< "$(_agent_vm_project_hooks "$1")"
263新增: done <<< "$(_agent_vm_share_hooks "$1")"
211264 _agent_vm_names_json ${names[@]+"${names[@]}"}
212265}
213266
@@ -235,7 +288,7 @@ _agent_vm_hooks_note() {
235288# `git config --list` prints them) with a path in their value: a start runs
236289# this, and a fork per line would show.
237290_agent_vm_repo_config_risks() {
238删除: local repo="$1" proj="$2" base top kind a b w rel
291新增: local repo="$1" proj="$2" base top kind a b w rel hooks f p
239292 base="$(_agent_vm_git_spelling "$repo")" || return 0
240293 top="$(_agent_vm_git_untrusted -C "$repo" rev-parse --show-toplevel 2>/dev/null)" || return 0
241294 _agent_vm_git_untrusted -C "$repo" config --list --show-origin --includes 2>/dev/null \
@@ -285,6 +338,16 @@ _agent_vm_repo_config_risks() {
285338 break
286339 done
287340 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
288351}
289352
290353# The same for every repository of the project <dir>, each line once.
@@ -296,6 +359,19 @@ _agent_vm_project_config_risks() {
296359 done | awk '!seen[$0]++'
297360}
298361
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新增:
299375# What a Lima without readonlyNames exposes when the shares are reverse-sshfs
300376# (see _agent_vm_unprotected_mount_is_sshfs), one paragraph, before
301377# _agent_vm_git_protection_hint.
修改lib/help.sh+3 −3看文件
@@ -22,9 +22,9 @@ Commands:
2222 use 'shell -c "..."' instead; pass --tty for TUIs like
2323 opencode, vibe, htop, etc.)
2424 code Serve VS Code (code-server) from the VM, at
25删除: http://<vm-name>.localhost:<port>/, and open it in the
26删除: browser, until Ctrl-C. Its password is made in each VM
27删除: and printed. Opt-in at setup, with the agents'
25新增: http://<vm-name>.localhost:<port>/, until Ctrl-C. The
26新增: address and the password, made in each VM, are
27新增: printed: open it in your browser. Opt-in at setup, with the agents'
2828 extensions or without: --preinstall=default,code-claude
2929 (or code-codex, code-vibe, code-server)
3030 stop [vm-name] Stop the VM for the current directory, or the named one
修改lib/info.sh+2 −2看文件
@@ -181,8 +181,8 @@ _agent_vm_info() {
181181 questions="${questions:+$questions,}hooks"
182182 break
183183 fi
184删除: done <<< "$(_agent_vm_project_hooks "$dir")"
185删除: [[ -z "$(_agent_vm_project_config_risks "$dir")" ]] || questions="${questions:+$questions,}git-config"
184新增: done <<< "$(_agent_vm_share_hooks "$dir")"
185新增: [[ -z "$(_agent_vm_share_config_risks "$dir")" ]] || questions="${questions:+$questions,}git-config"
186186 fi
187187 case "$(_agent_vm_bare_repo_state)" in
188188 unset|old) questions="${questions:+$questions,}bare-repo" ;;
修改lib/mounts.sh+181 −72看文件
@@ -82,6 +82,111 @@ _agent_vm_project_mountpoint() {
8282 printf '%s\n' "$p"
8383}
8484
85新增:# The entries of ~/.agent-vm/volumes for the project <dir>, one per line,
86新增:# 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.
91新增:_agent_vm_volume_entries() {
92新增: local host_dir="$1" quiet="${2:-}" raw line mounts_file="$AGENT_VM_STATE_DIR/volumes"
93新增: [[ -f "$mounts_file" ]] || return 0
94新增: while IFS= read -r raw || [[ -n "$raw" ]]; do
95新增: line="${raw%%#*}" # strip comments
96新增: line="${line#"${line%%[![:space:]]*}"}" # trim leading whitespace
97新增: line="${line%"${line##*[![:space:]]}"}" # trim trailing whitespace
98新增: [[ -z "$line" ]] && continue
99新增: # A control character (a tab, an ESC...) is invalid unescaped in the JSON
100新增: # handed to limactl. The CR of a CRLF file went with the trim above.
101新增: if [[ "$line" == *[[:cntrl:]]* ]]; then
102新增: _agent_vm_volume_warn "$quiet" "Mount entry '${raw}' (from ~/.agent-vm/volumes) contains a control character, skipping."
103新增: continue
104新增: fi
105新增: # An optional 4th field, after an explicit mode, limits the entry to the
106新增: # projects it matches: source:destination:mode:filter. An empty one
107新增: # (`src:dst:rw:`) is refused, not read as "no filter": that would mount
108新增: # an entry meant for one project in every project.
109新增: local filter="" has_filter="" before="${line%:*}"
110新增: if [[ "$line" == *:* && ( "$before" == *:ro || "$before" == *:rw ) ]]; then
111新增: filter="${line##*:}"
112新增: has_filter=1
113新增: line="$before"
114新增: fi
115新增: if [[ -n "$has_filter" ]]; then
116新增: 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."
118新增: continue
119新增: 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
125新增: fi
126新增: # Parse source[:destination][:mode] syntax (like docker compose volumes).
127新增: # The trailing mode segment is only recognized when it equals "ro" or
128新增: # "rw": anything else is treated as a destination path.
129新增: local src="$line" dst="" mode="ro" entry="$line"
130新增: if [[ "$line" == *:ro || "$line" == *:rw ]]; then
131新增: mode="${line##*:}"
132新增: line="${line%:*}"
133新增: fi
134新增: if [[ "$line" == *:* ]]; then
135新增: src="${line%%:*}"
136新增: dst="${line#*:}"
137新增: else
138新增: src="$line"
139新增: fi
140新增: # A ':' left in the destination is a field out of place: a project
141新增: # without a mode before it (`src:dst:/p`), a mode after it
142新增: # (`src:dst:/p:rw`), a second mode, a fifth field. Read as a destination,
143新增: # the entry would be mounted in every project, the project filter lost.
144新增: 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."
146新增: continue
147新增: fi
148新增: 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新增: 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."
153新增: continue
154新增: fi
155新增: if [[ ! -e "$src" ]]; then
156新增: _agent_vm_volume_warn "$quiet" "Mount path '${src}' (from ~/.agent-vm/volumes) does not exist, skipping."
157新增: continue
158新增: 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."
164新增: continue
165新增: 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."
169新增: continue
170新增: fi
171新增: printf '%s|%s|%s|%s\n' "$src" "$dst" "$mode" "$entry"
172新增: done < "$mounts_file"
173新增:}
174新增:
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新增:
180新增:# The writable directories of ~/.agent-vm/volumes for the project <dir>, one
181新增:# per line: shares the VM can write besides the project. Read quietly: the
182新增:# start that mounts them says what is wrong with an entry.
183新增:_agent_vm_rw_volume_dirs() {
184新增: local src dst mode entry
185新增: 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)"
188新增:}
189新增:
85190# _agent_vm_build_mounts_json <vm> <dir> [<writable>] [<names>]: the .mounts
86191# JSON array for `limactl edit --set`. The project <dir> first, writable
87192# unless <writable> is false, then the entries of ~/.agent-vm/volumes
@@ -99,9 +204,12 @@ _agent_vm_project_mountpoint() {
99204# the VM.
100205_agent_vm_build_mounts_json() {
101206 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.
102210 case "${4:-}" in
103删除: 1) sshfs=", \"sshfs\": {\"sftpDriver\": \"builtin\", \"readonlyNames\": $(_agent_vm_readonly_names "$host_dir")}" ;;
104删除: \[*) sshfs=", \"sshfs\": {\"sftpDriver\": \"builtin\", \"readonlyNames\": $4}" ;;
211新增: 1) sshfs=", \"sshfs\": {\"sftpDriver\": \"builtin\", \"cache\": false, \"readonlyNames\": $(_agent_vm_readonly_names "$host_dir")}" ;;
212新增: \[*) sshfs=", \"sshfs\": {\"sftpDriver\": \"builtin\", \"cache\": false, \"readonlyNames\": $4}" ;;
105213 esac
106214 # Every entry names its mount point: agent-vm addresses the guest side by the
107215 # shell's spelling of the path (--workdir, the write probe), which on Windows
@@ -112,68 +220,9 @@ _agent_vm_build_mounts_json() {
112220 local file_mounts_cache="$AGENT_VM_STATE_DIR/.agent-vm-file-mounts-${vm_name}"
113221
114222 if [[ -f "$mounts_file" ]]; then
115删除: local staging_idx=0 raw line
116删除: while IFS= read -r raw || [[ -n "$raw" ]]; do
117删除: line="${raw%%#*}" # strip comments
118删除: line="${line#"${line%%[![:space:]]*}"}" # trim leading whitespace
119删除: line="${line%"${line##*[![:space:]]}"}" # trim trailing whitespace
120删除: [[ -z "$line" ]] && continue
121删除: # A control character (a tab, an ESC...) is invalid unescaped in the JSON
122删除: # handed to limactl. The CR of a CRLF file went with the trim above.
123删除: if [[ "$line" == *[[:cntrl:]]* ]]; then
124删除: echo "Warning: Mount entry '${raw}' (from ~/.agent-vm/volumes) contains a control character, skipping." >&2
125删除: continue
126删除: fi
127删除: # An optional 4th field, after an explicit mode, limits the entry to the
128删除: # projects it matches: source:destination:mode:filter. An empty one
129删除: # (`src:dst:rw:`) is refused, not read as "no filter": that would mount
130删除: # an entry meant for one project in every project.
131删除: local filter="" has_filter="" before="${line%:*}"
132删除: if [[ "$line" == *:* && ( "$before" == *:ro || "$before" == *:rw ) ]]; then
133删除: filter="${line##*:}"
134删除: has_filter=1
135删除: line="$before"
136删除: fi
137删除: if [[ -n "$has_filter" ]]; then
138删除: if [[ -z "$filter" ]]; then
139删除: echo "Warning: Mount entry '${raw}' (from ~/.agent-vm/volumes) has an empty project filter; refusing to mount it in every project. Skipping." >&2
140删除: continue
141删除: fi
142删除: _agent_vm_volume_matches "$filter" "$host_dir" || continue
143删除: fi
144删除: # Parse source[:destination][:mode] syntax (like docker compose volumes).
145删除: # The trailing mode segment is only recognized when it equals "ro" or
146删除: # "rw": anything else is treated as a destination path.
147删除: local src="$line" dst="" mode="ro"
148删除: if [[ "$line" == *:ro || "$line" == *:rw ]]; then
149删除: mode="${line##*:}"
150删除: line="${line%:*}"
151删除: fi
152删除: if [[ "$line" == *:* ]]; then
153删除: src="${line%%:*}"
154删除: dst="${line#*:}"
155删除: else
156删除: src="$line"
157删除: fi
158删除: # A ':' left in the destination is a field out of place: a project
159删除: # without a mode before it (`src:dst:/p`), a mode after it
160删除: # (`src:dst:/p:rw`), a second mode, a fifth field. Read as a destination,
161删除: # the entry would be mounted in every project, the project filter lost.
162删除: if [[ "$dst" == *:* ]]; then
163删除: 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
164删除: continue
165删除: fi
166删除: src="${src/#\~/$HOME}" # expand ~
167删除: # Reject characters that would break JSON interpolation below or the
168删除: # pipe-separated cache format used for file mounts.
169删除: if [[ "$src" == *[$'"\\\n|']* || "$dst" == *[$'"\\\n|']* ]]; then
170删除: echo "Warning: Mount entry '${raw}' (from ~/.agent-vm/volumes) contains invalid characters (quote/backslash/newline/pipe), skipping." >&2
171删除: continue
172删除: fi
173删除: if [[ ! -e "$src" ]]; then
174删除: echo "Warning: Mount path '${src}' (from ~/.agent-vm/volumes) does not exist, skipping." >&2
175删除: continue
176删除: fi
223新增: local staging_idx=0 src dst mode line
224新增: while IFS='|' read -r src dst mode line; do
225新增: [[ -n "$src" ]] || continue
177226 if [[ -n "$dst" && "$dst" != /* ]]; then
178227 dst="$(_agent_vm_project_mountpoint "$host_dir" "$dst" "$src")" || continue
179228 fi
@@ -215,7 +264,7 @@ _agent_vm_build_mounts_json() {
215264 fi
216265 fi
217266 mounts_json+=", {\"location\": \"$(_agent_vm_host_path "$src")\", \"mountPoint\": \"${dst:-$src}\", \"writable\": ${writable}${sshfs}}"
218删除: done < "$mounts_file"
267新增: done <<< "$(_agent_vm_volume_entries "$host_dir")"
219268 fi
220269 mounts_json+="]"
221270
@@ -264,6 +313,52 @@ _agent_vm_mounts_have_readonly_names() {
264313 [[ -f "$record" ]] && grep -qF "\"readonlyNames\": $2" "$record"
265314}
266315
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
326新增: # As Lima prints it: no space after the commas (a name may hold a space).
327新增: [[ -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 }'
332新增:}
333新增:
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.
339新增:_agent_vm_hostagent_is_limactl() {
340新增: local pid exe mine
341新增: _agent_vm_on_windows && return 0
342新增: pid="$(cat "$(_agent_vm_lima_home)/$1/ha.pid" 2>/dev/null)"
343新增: [[ "$pid" =~ ^[0-9]+$ ]] || return 0
344新增: if [[ -e "/proc/$pid/exe" ]]; then
345新增: exe="$(readlink "/proc/$pid/exe" 2>/dev/null)"
346新增: else
347新增: exe="$(ps -o comm= -p "$pid" 2>/dev/null)"
348新增: fi
349新增: [[ "$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)" ]]
354新增:}
355新增:
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"
360新增:}
361新增:
267362# _agent_vm_push_env_and_probe <vm> <dir> <payload> [<env> [<runtime>]], in
268363# one round trip:
269364# - writes ~/.agent-vm.env in the VM (mode 600, sourced by its ~/.zshenv):
@@ -271,16 +366,29 @@ _agent_vm_mounts_have_readonly_names() {
271366# the VM, CRs dropped; empty too, so env removed on the host goes. Prints
272367# env-ok.
273368# - prints runtime-found when the project's <runtime> is there.
274删除:# - returns whether a write into the project <dir> succeeds. A real write, not
275删除:# `test -w`: after a mode change the guest's fstab still shows the old one.
369新增:# - 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.
276375_agent_vm_push_env_and_probe() {
277删除: local vm_name="$1" host_dir="$2" payload="$3"
278删除: { [ -z "$payload" ] || printf '%s\n' "$payload"; } \
376新增: local vm_name="$1" host_dir="$2" payload="$3" token out st=0
377新增: token="$$.$RANDOM$RANDOM"
378新增: out="$({ [ -z "$payload" ] || printf '%s\n' "$payload"; } \
279379 | limactl shell "$vm_name" sh -c '
280380 (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
281381 [ -z "$3" ] || [ ! -f "$3" ] || echo runtime-found
282删除: p="$1/.agent-vm-write-probe.$$"; touch "$p" 2>/dev/null || exit 1; rm -f "$p"' \
283删除: sh "$host_dir" "${4:-}" "${5:-}" 2>/dev/null
382新增: touch "$1/.agent-vm-write-probe.$4" 2>/dev/null || exit 1; echo probe-written' \
383新增: sh "$host_dir" "${4:-}" "${5:-}" "$token" 2>/dev/null)" || st=$?
384新增: 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
284392}
285393
286394# Are <vm>'s shares ones whose read-only flag is enforced outside the guest?
@@ -310,7 +418,8 @@ _agent_vm_mount_is_host_enforced() {
310418 # The record says agent-vm gave it readonlyNames, and the Lima installed
311419 # now serves them: a stock limactl started by hand would not.
312420 ?*" reverse-sshfs")
313删除: _agent_vm_mounts_protect_git "$1" && _agent_vm_lima_protects_git && return 0
421新增: _agent_vm_mounts_protect_git "$1" && _agent_vm_lima_protects_git \
422新增: && _agent_vm_live_shares_protected "$1" && return 0
314423 return 1 ;;
315424 *) return 2 ;;
316425 esac
修改lib/setup.sh+8 −3看文件
@@ -122,7 +122,7 @@ _agent_vm_ask_code_extensions() {
122122
123123_agent_vm_setup() {
124124 local disk=10
125删除: local memory=3
125新增: local memory=3 memory_seen=""
126126 local cpus=1
127127 local preinstall=""
128128 local preinstall_seen=""
@@ -151,7 +151,7 @@ _agent_vm_setup() {
151151 local opt="${vm_opts[*]-}"
152152 case "$opt" in
153153 "--disk "*) disk="${opt#--disk }" ;;
154删除: "--memory "*) memory="${opt#--memory }" ;;
154新增: "--memory "*) memory="${opt#--memory }"; memory_seen=1 ;;
155155 "--cpus "*) cpus="${opt#--cpus }" ;;
156156 *)
157157 echo "Unknown option: ${1%%=*}" >&2
@@ -175,7 +175,7 @@ the wizard is skipped automatically and the default set is installed.
175175
176176Options:
177177 --disk GB VM disk size (default: 10)
178删除: --memory GB VM memory (default: 3)
178新增: --memory GB VM memory (default: 3, 4 with code-server in the wizard)
179179 --cpus N Number of CPUs (default: 1)
180180 --preinstall=LIST Comma-separated list of tools to preinstall in the base
181181 VM image (skips the wizard). Anything not listed is
@@ -429,6 +429,11 @@ EOF
429429 install_golang=$(_agent_vm_ask_yn "Go" N)
430430 fi
431431
432新增: # The editor needs more memory than the agents alone. --memory wins.
433新增: if [[ "$install_code_server" == 1 && -z "$memory_seen" ]]; then
434新增: memory=4
435新增: fi
436新增:
432437 # Resources second, the same way, accepted in one go or not. Current
433438 # values reflect any --disk/--memory/--cpus already passed on the CLI.
434439 # These are starting values: any later `agent-vm` command can resize the
修改lib/vm.sh+6 −0看文件
@@ -91,6 +91,12 @@ _agent_vm_unsafe_project() {
9191 return 0 ;;
9292 esac
9393 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.
96新增: if _agent_vm_under_readonly_name "${dir#/}"; then
97新增: printf 'is, or is inside, a folder git or Mercurial keeps its repository in (.git, .hg)\n'
98新增: return 0
99新增: fi
94100 return 1
95101}
96102
修改tests/06-help-and-setup-script.sh+10 −3看文件
@@ -322,9 +322,16 @@ $(awk '/^configure_mcp\(\) \{/,/^\}/' "$SETUP_SH")"
322322 check "the three extensions, in one call" \
323323 "$(grep '^code-server' "$CSA/calls.log" | head -n 1)" \
324324 "code-server --install-extension anthropic.claude-code --install-extension openai.chatgpt --install-extension mistralai.mistral-vibe-code"
325删除: check "claude: bypass mode allowed and picked, no onboarding checklist" \
326删除: "$(jq -r '[."claudeCode.allowDangerouslySkipPermissions", ."claudeCode.initialPermissionMode", ."claudeCode.hideOnboarding"] | map(tostring) | join(" ")' \
327删除: "$CSA/.local/share/code-server/User/settings.json")" "true bypassPermissions true"
325新增: # The permission keys are machine-scoped: code-server reads them from the
326新增: # machine settings only.
327新增: check "claude: bypass mode allowed and picked, in the machine settings" \
328新增: "$(jq -r '[."claudeCode.allowDangerouslySkipPermissions", ."claudeCode.initialPermissionMode"] | map(tostring) | join(" ")' \
329新增: "$CSA/.local/share/code-server/Machine/settings.json")" "true bypassPermissions"
330新增: check "claude: and not in the user settings, where they do nothing" \
331新增: "$(jq -r 'keys | map(select(startswith("claudeCode.") and . != "claudeCode.hideOnboarding")) | length' \
332新增: "$CSA/.local/share/code-server/User/settings.json")" "0"
333新增: check "claude: no onboarding checklist" \
334新增: "$(jq -r '."claudeCode.hideOnboarding"' "$CSA/.local/share/code-server/User/settings.json")" "true"
328335 check "codex: full access, once, before any table" \
329336 "$(head -n 2 "$CSA/.codex/config.toml" | sort | tr '\n' ' '; grep -c '^approval_policy' "$CSA/.codex/config.toml")" \
330337 'approval_policy = "never" sandbox_mode = "danger-full-access" 1'
修改tests/08-mount-mode.sh+7 −2看文件
@@ -28,7 +28,7 @@ esac
2828
2929# .git protection: Lima refuses readonlyNames unless EVERY mount uses the
3030# builtin driver, so the volumes entries need it as much as the project.
31删除:SSHFS_RO='"sshfs": {"sftpDriver": "builtin", "readonlyNames": [".git", ".hg"]}'
31新增:SSHFS_RO='"sshfs": {"sftpDriver": "builtin", "cache": false, "readonlyNames": [".git", ".hg"]}'
3232printf '%s:/mnt/v:rw\n' "$SB/extra-vol" > "$HOME/.agent-vm/volumes"
3333mounts_prot="$(_agent_vm_build_mounts_json agent-vm-t "$PROJ" true 1)"
3434rm -f "$HOME/.agent-vm/volumes"
@@ -58,6 +58,7 @@ 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
6162[ "\$1" = list ] && { printf '%s\n' "$1"; exit 0; }
6263[ "\$1" = validate ] && [ -n "\${MT_PROTECTS:-}" ] && { echo 'field mounts[*].sshfs.readonlyNames requires mountType to be reverse-sshfs' >&2; exit 1; }
6364exit 1
@@ -92,7 +93,11 @@ check "unset on QEMU, no lima-version: reverse-sshfs, not" "$(LIMA_HOME="$SB/lim
9293# cannot tell the servers apart: the record of the applied mounts does.
9394mkdir -p "$HOME/.agent-vm"
9495printf '[{"location": "%s", "writable": false, %s}]\n' "$PROJ" "$SSHFS_RO" > "$HOME/.agent-vm/.agent-vm-mounts-agent-vm-t"
95删除:check "reverse-sshfs with readonlyNames is" "$(MT_PROTECTS=1 mount_types 'qemu reverse-sshfs')" "0"
96新增:LIVE_OK='reverse-sshfs [{"location":"/p","writable":false,"sshfs":{"cache":false,"sftpDriver":"builtin","readonlyNames":[".git",".hg"]}}]'
97新增:check "reverse-sshfs with readonlyNames is" "$(MT_PROTECTS=1 MT_LIVE="$LIVE_OK" mount_types 'qemu reverse-sshfs')" "0"
98新增:# Recorded so, but Lima has a share without them, set outside agent-vm: not.
99新增:check "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"
96101# Recorded so, but served by a Lima without them (a stock limactl started it
97102# since): not.
98103check "recorded with readonlyNames, a Lima without them: not" "$(mount_types 'qemu reverse-sshfs')" "1"
修改tests/11-recorded-commands.sh+15 −2看文件
@@ -10,7 +10,8 @@ section "commands against a recording limactl"
1010# would. AGENT_VM_TEST_STOP_FAIL makes `stop` leave it running.
1111# AGENT_VM_TEST_SSHFS_FAIL fails the sshfs install of a 0.1.0 VM.
1212# AGENT_VM_TEST_RUNTIME_FOUND makes the probe find the project's runtime
13删除:# script. What is piped into the env push goes to AGENT_VM_TEST_STDIN.
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.
1415# `validate` answers like stock Lima 2.2 does to readonlyNames, or, while the
1516# file $PROTECTS exists, like a Lima that has it (both messages copied from
1617# the real binaries). AGENT_VM_TEST_VALIDATE_SILENT makes it accept the file
@@ -43,6 +44,17 @@ case "$1" in
4344 listed && echo "$AGENT_VM_TEST_VM ${AGENT_VM_TEST_SSH_PORT:-0}" ;;
4445 *"{{.Config.SSH.LocalPort}}"*) listed && echo "${AGENT_VM_TEST_SSH_PORT:-0}" ;;
4546 *"{{.SSHConfigFile}}"*) listed && echo "/lima/$AGENT_VM_TEST_VM/ssh.config" ;;
47新增: # Lima's config for the VM: the shares agent-vm last set, as Lima prints
48新增: # them, unless AGENT_VM_TEST_LIVE_UNPROTECTED adds one set by hand.
49新增: *"{{json .Config.Mounts}}"*)
50新增: 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"
55新增: else
56新增: echo "${AGENT_VM_TEST_MOUNTTYPE:-virtiofs} [{\"location\":\"/x\",\"writable\":true}]"
57新增: fi ;;
4658 *"{{.VMType}}"*) echo "${AGENT_VM_TEST_VMTYPE:-vz} ${AGENT_VM_TEST_MOUNTTYPE:-virtiofs}" ;;
4759 *"{{.CPUs}}"*"{{.Disk}}"*) listed && echo "$AGENT_VM_TEST_VM|1|3221225472|10737418240" ;;
4860 *"{{.Status}}|"*) listed && echo "$AGENT_VM_TEST_VM|Running|1|3221225472" ;;
@@ -67,7 +79,8 @@ case "$1" in
6779 [ -n "${AGENT_VM_TEST_ENV_FAIL:-}" ] || echo env-ok
6880 [ -z "${AGENT_VM_TEST_RUNTIME_FOUND:-}" ] || echo runtime-found ;;
6981 esac
70删除: [ -z "${AGENT_VM_TEST_RO:-}" ] || exit 1 ;;
82新增: [ -z "${AGENT_VM_TEST_RO:-}" ] || exit 1
83新增: [ -z "${AGENT_VM_TEST_PROBE_LOST:-}" ] || echo probe-written ;;
7184 *"exec "*" -s"*) cat >> "${AGENT_VM_TEST_STDIN:-/dev/null}" ;;
7285 # The editor's prep (lib/code.sh): AGENT_VM_TEST_CODE_PREP is its answer.
7386 *"agent-vm-code "*)
修改tests/13-volumes-and-readonly.sh+33 −0看文件
@@ -167,6 +167,16 @@ case "$out" in *"Project mount is not writable; repairing"*) pass "a writable VM
167167# project's env file or runtime: the repaired VM gets them pushed again.
168168check "after a repair, the env is pushed again, with the project's files" \
169169 "$(grep -c 'rm -f "$HOME/.agent-vm.env"' "$REC") $(grep -c "^shell $PV sh -c" "$REC")" "2 2"
170新增:# A share that is gone: the VM writes in the bare mount point on its own
171新增:# disk, which a write probe in the VM alone takes for a writable project.
172新增:out="$(AGENT_VM_TEST_PROBE_LOST=1 rec run true; echo "rc=$?")"
173新增:case "$out" in
174新增: *"project share is not mounted in VM"*"on the VM's own disk"*"Project share is not mounted; repairing"*) pass "a share that is gone: said, and repaired" ;;
175新增: *) fail "share gone: $out" ;;
176新增:esac
177新增:rec_has "stop $PV" && rec_has "edit $PV" && rec_has "start $PV" && pass "and the VM is stopped, its shares set again, started" \
178新增: || fail "share gone, not repaired: $(cat "$REC")"
179新增:case "$out" in *"the project share did not mount"*"rc=1") pass "still gone after the repair: an error" ;; *) fail "share still gone: $out" ;; esac
170180rm -f "$REC_MOUNTS"
171181ro_run
172182rec_has "edit $PV --set del(.mountType) | .mounts" && pass "no record (an older VM): remounted to be sure" \
@@ -261,3 +271,26 @@ case "$(_agent_vm_unsafe_project "$HOME/proj-under-home" 2>/dev/null || echo non
261271 none) pass "a project inside the home directory is fine" ;;
262272 *) fail "a project inside the home directory was refused" ;;
263273esac
274新增:# The read-only names apply below a share's root: a .git shared as the
275新增:# project would be writable whole.
276新增:mkdir -p "$PROJ/.git/hooks" "$PROJ/sub.git" "$PROJ/.Hg"
277新增:check "a .git" "$(refused "$PROJ/.git")" "refused"
278新增:check "a folder inside a .git" "$(refused "$PROJ/.git/hooks")" "refused"
279新增:check "a .hg, whatever the case" "$(refused "$PROJ/.Hg")" "refused"
280新增:case "$(_agent_vm_unsafe_project "$PROJ/sub.git" 2>/dev/null || echo none)" in
281新增: none) pass "a name ending in .git is fine" ;;
282新增: *) fail "sub.git was refused" ;;
283新增:esac
284新增:rm -rf "$PROJ/.git/hooks" "$PROJ/sub.git" "$PROJ/.Hg"
285新增:rmdir "$PROJ/.git" 2>/dev/null
286新增:
287新增:# Nor as volumes: agent-vm's state (the VM would add a share for its next
288新增:# start), or a destination covering the project.
289新增:mkdir -p "$SB/vol-ok"
290新增:printf '%s:/mnt/s:rw\n%s:%s:rw\n%s:/mnt/ok:rw\n' "$HOME/.agent-vm" "$SB/vol-ok" "$(dirname "$PROJ")" "$SB/vol-ok" > "$HOME/.agent-vm/volumes"
291新增:vols_err="$(_agent_vm_build_mounts_json agent-vm-t "$PROJ" 2>&1 >/dev/null)"
292新增:vols="$(_agent_vm_build_mounts_json agent-vm-t "$PROJ" 2>/dev/null)"
293新增:case "$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
295新增:check "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"
修改tests/14-git-protection.sh+105 −0看文件
@@ -30,6 +30,21 @@ for t in mktemp rm; do
3030 chmod +x "$SB/nolimactl/$t"
3131done
3232check "no limactl: cannot tell" "$(PATH="$SB/nolimactl" probe)" "unknown"
33新增:# A Lima with readonlyNames whose _config/override.yaml sets mountType:
34新增:# reverse-sshfs accepts readonlyNames with any other mount type; a name with
35新增:# a slash it still refuses (the message copied from the real binary).
36新增:mkdir -p "$SB/override-lima"
37新增:cat > "$SB/override-lima/limactl" <<'STUB'
38新增:#!/usr/bin/env bash
39新增:f="${2:-}"
40新增:if grep -q 'readonlyNames: \[[^]]*/' "$f" 2>/dev/null; then
41新增: echo 'level=fatal msg="failed to validate YAML file `probe.yaml`: field `mounts[0].sshfs.readonlyNames` must contain file names, got `a/b`"' >&2
42新增: exit 1
43新增:fi
44新增:echo 'level=info msg="`probe.yaml`: OK"' >&2
45新增:STUB
46新增:chmod +x "$SB/override-lima/limactl"
47新增:check "a Lima with readonlyNames, whatever mount type its config imposes: protection" "$(PATH="$SB/override-lima:$PATH" probe)" "yes"
3348check "a Lima accepting the probe without a word: cannot tell" \
3449 "$(AGENT_VM_TEST_VALIDATE_SILENT=1 probe)" "unknown"
3550
@@ -316,6 +331,45 @@ _agent_vm_mounts_have_readonly_names "$PV" '[".git", ".hg"]' && pass "names: rec
316331out="$(AGENT_VM_TEST_STOPPED=1 rec run true)"
317332rec_has "edit $PV" && fail "names: edited again with nothing to change" || pass "names: nothing to change the next time"
318333
334新增:# Shares from before sshfs's cache was off: set again while stopped, never
335新增:# a reason to restart a running VM.
336新增:names_rec '[".git", ".hg"]'
337新增:out="$(rec run true)"
338新增:rec_has "edit $PV" && fail "cache: a running VM was changed" || pass "cache: a running VM is left as it is"
339新增:rec_has "stop $PV" && fail "cache: a running VM was stopped" || pass "cache: and not stopped"
340新增:names_rec '[".git", ".hg"]'
341新增:AGENT_VM_TEST_STOPPED=1 rec run true >/dev/null
342新增:rec_has "edit $PV --set .mountType = \"reverse-sshfs\" | .mounts = [{$(mnt "$PROJ"), \"writable\": true, $SSHFS_RO}]" \
343新增: && 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")"
345新增:
346新增:# A share in Lima's config without the names, set outside agent-vm (by hand,
347新增:# or from Lima's _config): the record cannot be trusted.
348新增:out="$(AGENT_VM_TEST_LIVE_UNPROTECTED=1 rec run true)"
349新增:case "$out" in *"is running with .git writable"*) pass "live: a running VM with such a share is warned about" ;; *) fail "live, running: $out" ;; esac
350新增:out="$(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
352新增:rec_has "start $PV" && fail "live: started anyway" || pass "live: and not started"
353新增:
354新增:# A running VM served by another binary than the limactl on PATH (a stock
355新增:# Lima that ignores the names): its pid file points to that process.
356新增:if _agent_vm_on_windows; then
357新增: printf ' skip the limactl serving a running VM (not told on Windows)\n'
358新增:else
359新增: names_rec '[".git", ".hg"]'
360新增: printf '%s\n' "$(cat "$REC_MOUNTS" | sed 's/"readonlyNames"/"cache": false, "readonlyNames"/')" > "$REC_MOUNTS"
361新增: mkdir -p "$(_agent_vm_lima_home)/$PV"
362新增: : > "$(_agent_vm_lima_home)/$PV/lima.yaml"
363新增: sleep 30 & other_pid=$!
364新增: echo "$other_pid" > "$(_agent_vm_lima_home)/$PV/ha.pid"
365新增: out="$(rec run true)"
366新增: 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
367新增: kill "$other_pid" 2>/dev/null; wait "$other_pid" 2>/dev/null
368新增: rm -f "$(_agent_vm_lima_home)/$PV/ha.pid" "$(_agent_vm_lima_home)/$PV/lima.yaml"
369新增: out="$(rec run true)"
370新增: case "$out" in *"another limactl"*) fail "hostagent: no pid file, warned anyway" ;; *) pass "hostagent: when it cannot tell, nothing is said" ;; esac
371新增:fi
372新增:
319373# core.hooksPath in the project: its first component joins the names.
320374if command -v git >/dev/null 2>&1; then
321375 # In subshells: bash 3.2 would keep git hashed for a later test that hides
@@ -386,6 +440,57 @@ if command -v git >/dev/null 2>&1; then
386440 || fail "hooks: nested, start: $(grep '^edit' "$REC")"
387441 rm -rf "$PROJ/lib"
388442
443新增: # Hooks through symlinks: git runs what the link points to.
444新增: if [ -n "$AGENT_VM_HAS_SYMLINKS" ]; then
445新增: hp .husky/_
446新增: mkdir -p "$PROJ/scripts/hooks"
447新增: ( git -C "$PROJ" config --unset core.hooksPath )
448新增: mv "$PROJ/.git/hooks" "$SB/hooks-saved"
449新增: ln -s ../scripts/hooks "$PROJ/.git/hooks"
450新增: check "hooks: .git/hooks linked into the project: its folder joins the names" "$(names)" '[".git", ".hg", "scripts"]'
451新增: rm "$PROJ/.git/hooks"
452新增: mv "$SB/hooks-saved" "$PROJ/.git/hooks"
453新增: ln -s scripts/hooks "$PROJ/.githooks"
454新增: hp .githooks
455新增: check "hooks: core.hooksPath linked elsewhere in the project: both names" "$(names)" '[".git", ".hg", ".githooks", "scripts"]'
456新增: ( git -C "$PROJ" config --unset core.hooksPath )
457新增: rm "$PROJ/.githooks"
458新增: printf '#!/bin/sh\n' > "$PROJ/scripts/pre-commit"
459新增: ln -s ../../scripts/pre-commit "$PROJ/.git/hooks/pre-commit"
460新增: ln -s "$SB/elsewhere-hook" "$PROJ/.git/hooks/post-commit"
461新增: case "$(_agent_vm_project_config_risks "$PROJ")" in
462新增: *"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")" ;;
464新增: esac
465新增: case "$(_agent_vm_project_config_risks "$PROJ")" in
466新增: *post-commit*) fail "hooks: a link out of the project counted as a risk" ;;
467新增: *) pass "hooks: and one linked out of it is not" ;;
468新增: esac
469新增: rm -f "$PROJ/.git/hooks/pre-commit" "$PROJ/.git/hooks/post-commit"
470新增: rm -rf "$PROJ/scripts"
471新增: hp .husky/_
472新增: else
473新增: printf ' skip hooks through symlinks (no symlinks here)\n'
474新增: fi
475新增:
476新增: # A repository in a writable volume: git on this machine runs its hooks and
477新增: # config as much as the project's.
478新增: VREPO="$SB/vrepo"
479新增: mkdir -p "$VREPO"
480新增: ( git -C "$VREPO" init -q && git -C "$VREPO" config core.hooksPath tools/hooks \
481新增: && git -C "$VREPO" config core.fsmonitor ./fsmon.sh )
482新增: printf '%s:/mnt/vrepo:rw\n' "$VREPO" > "$HOME/.agent-vm/volumes"
483新增: check "volumes: a writable volume's hooks folder joins the names" "$(names)" '[".git", ".hg", ".husky", "tools"]'
484新增: 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
485新增: 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" ;;
487新增: *) fail "volumes: risks: $(_agent_vm_share_config_risks "$PROJ")" ;;
488新增: esac
489新增: printf '%s:/mnt/vrepo:ro\n' "$VREPO" > "$HOME/.agent-vm/volumes"
490新增: check "volumes: a read-only volume adds nothing" "$(names)" '[".git", ".hg", ".husky"]'
491新增: [ -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"
493新增:
389494 # A name that is not a dot-name is read-only in every folder of the
390495 # project, so it is asked first: yes by default, and when no one can answer.
391496 hp tools/hooks
修改tests/16-setup.sh+26 −0看文件
@@ -29,6 +29,7 @@ cat > "$SB/wizlima/limactl" <<STUB
2929case "\$1" in
3030 shell) cat > "$SB/wizard.stdin" ;;
3131 list) [ "\$2" = -q ] && echo agent-vm-base ;;
32新增: create) echo "\$*" > "$SB/wizard.create" ;;
3233esac
3334exit 0
3435STUB
@@ -48,6 +49,31 @@ check "wizard defaults: Ruby, Rust, Go, Pi and Playwright MCP off; Claude on" \
4849 "$(grep -E '^export AGENT_VM_INSTALL_(RUBY|RUST|GOLANG|PI|MCP_PLAYWRIGHT|CLAUDE)=' "$SB/wizard.stdin" 2>/dev/null | cut -d_ -f4- | tr '\n' ' ')" \
4950 "RUBY=0 RUST=0 GOLANG=0 CLAUDE=1 PI=0 MCP_PLAYWRIGHT=0 "
5051
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.
54新增:wiz_memory() {
55新增: rm -f "$SB/wizard.create"
56新增: ( PATH="$SB/wizlima:$PATH"; AGENT_VM_STATE_DIR="$SB/wizstate"
57新增: _agent_vm_have_tty() { return 0; }
58新增: _agent_vm_host_mem_gib() { echo 64; }
59新增: _agent_vm_ask_yn() {
60新增: case "$1" in
61新增: "Use this default") echo "${DEFAULT_SOFTWARE:-0}" ;;
62新增: "Use these defaults") echo 1 ;;
63新增: code-server*) echo "${CODE:-0}" ;;
64新增: *) case "$2" in [Yy]) echo 1 ;; *) echo 0 ;; esac ;;
65新增: esac
66新增: }
67新增: _agent_vm_ask_choice() { echo 3; }
68新增: _agent_vm_offer_git_protection() { :; }
69新增: _agent_vm_setup "$@" ) >/dev/null 2>&1
70新增: grep -o -- '--memory=[0-9]*' "$SB/wizard.create" 2>/dev/null
71新增:}
72新增:check "code-server picked: 4 GB" "$(CODE=1 wiz_memory)" "--memory=4"
73新增:check "code-server not picked: 3 GB" "$(CODE=0 wiz_memory)" "--memory=3"
74新增:check "default software (no code-server): 3 GB" "$(DEFAULT_SOFTWARE=1 wiz_memory)" "--memory=3"
75新增:check "code-server picked, --memory 2 kept" "$(CODE=1 wiz_memory --memory 2)" "--memory=2"
76新增:
5177section "release.sh"
5278REL="$SELF_DIR/release.sh"
5379notes="$("$REL" notes "$AGENT_VM_VERSION" 2>&1)"
修改tests/20-project-files.sh+20 −3看文件
@@ -113,10 +113,12 @@ STUB
113113chmod +x "$SB/localvm/limactl"
114114printf 'B=2\r\nA=project\r\n' > "$PF/.agent-vm.env"
115115: > "$PF/.agent-vm.runtime.sh"
116删除:out="$(PATH="$SB/localvm:$PATH" _agent_vm_push_env_and_probe vm "$PF" "A=shared" "$PF/.agent-vm.env" "$PF/.agent-vm.runtime.sh")"
116新增:out="$(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, and that the runtime is there" "$(printf '%s' "$out" | tr '\n' ' ')" "env-ok runtime-found"
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"
120122if _agent_vm_on_windows; then
121123 printf ' skip the guest env file is private (permission bits are emulated on Windows)\n'
122124else
@@ -124,7 +126,22 @@ else
124126fi
125127rm -f "$PF/.agent-vm.runtime.sh"
126128out="$(PATH="$SB/localvm:$PATH" _agent_vm_push_env_and_probe vm "$PF" "" "$PF/.agent-vm.env" "$PF/.agent-vm.runtime.sh")"
127删除:check "no runtime there: not found" "$out" "env-ok"
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.
133新增:mkdir -p "$SB/guest-only" "$SB/lostvm"
134新增:cat > "$SB/lostvm/limactl" <<STUB
135新增:#!/usr/bin/env bash
136新增:[ "\$1" = shell ] || exit 0
137新增:script="\$5"
138新增:shift 7
139新增:HOME="$GH" exec sh -c "\$script" sh "$SB/guest-only" "\$@"
140新增:STUB
141新增:chmod +x "$SB/lostvm/limactl"
142新增:out="$(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新增:rm -rf "$SB/guest-only" "$SB/lostvm"
128145if command -v zsh >/dev/null 2>&1; then
129146 printf '#!/usr/bin/env bash\r\necho "ran:${BASH_VERSION:+bash}" > "$HOME/rt-out"\r\n' > "$PF/.agent-vm.runtime.sh"
130147 PATH="$SB/localvm:$PATH" _agent_vm_run_project_runtime vm "$PF" "$PF/.agent-vm.runtime.sh" >/dev/null 2>&1
修改tests/22-code.sh+10 −5看文件
@@ -21,21 +21,26 @@ if _agent_vm_host_port_open "$first"; then
2121 printf ' skip code launch tests (port %s is taken on this machine)\n' "$first"
2222else
2323 out="$(rec code)"
24删除: rec_has "agent-vm code-server --config /home/u/.config/code-server/agent-vm-lima-x.yaml --bind-addr 127.0.0.1:$first --cookie-suffix $PV" \
24新增: rec_has "agent-vm VSCODE_PROXY_URI=http://localhost:{{port}}/ code-server --config /home/u/.config/code-server/agent-vm-lima-x.yaml --bind-addr 127.0.0.1:$first --cookie-suffix $PV" \
2525 && pass "code-server on the VM's loopback, the VM's own config and cookie" \
2626 || fail "code: $(grep 'code-server --config' "$REC")"
27新增: rec_has "--disable-getting-started-override --link-protection-trusted-domains https://claude.com/cai/oauth --link-protection-trusted-domains https://platform.claude.com/oauth --vscode-option" \
28新增: && pass "Claude Code's login pages are trusted, by path" || fail "trusted domains: $(grep 'code-server' "$REC")"
2729 rec_has "--disable-telemetry --disable-update-check --disable-workspace-trust --disable-proxy" \
2830 && pass "no telemetry, update check or port proxy" || fail "code flags: $(grep 'code-server --config' "$REC")"
2931 rec_has "--vscode-option disable-experiments --vscode-option disable-extension=GitHub.copilot-chat $PROJ" \
3032 && pass "no experiments, Copilot never loaded, and the project opened" || fail "code flags: $(grep 'code-server --config' "$REC")"
3133 case "$out" in
32删除: *"Editor: http://$PV.localhost:$first/"*"Password: 0123456789abcdef0123456789abcdef"*)
33删除: pass "the VM's own host name, and the password" ;;
34新增: *"+- VS Code"*"| Address: http://$PV.localhost:$first/"*"| Password: 0123456789abcdef0123456789abcdef"*"Ctrl-C stops the"*)
35新增: pass "the VM's own host name, and the password, in a box" ;;
3436 *) fail "code output: $out" ;;
3537 esac
3638 check "the Safari fallback, on macOS only" \
37删除: "$(uname() { echo Linux; }; _agent_vm_code_say u 20000 pw | grep -c 127.0.0.1; uname() { echo Darwin; }; _agent_vm_code_say u 20000 pw | grep -c 'http://127.0.0.1:20000/')" \
39新增: "$(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/')" \
3840 "$(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"
3944
4045 AGENT_VM_TEST_CODE_PREP="config=/c.yaml\npassword=pw\nlistening=$first\n" rec code >/dev/null
4146 rec_has "--bind-addr 127.0.0.1:$((first + 1))" \
@@ -45,7 +50,7 @@ else
4550 rec_has "code-server --config" && fail "a second editor was started" \
4651 || pass "an editor already running is not started again"
4752 case "$out" in
48删除: *"already runs"*"http://$PV.localhost:$first/"*"Password: pw"*) pass "and its address is given" ;;
53新增: *"Address: http://$PV.localhost:$first/"*"Password: pw"*"already runs"*) pass "and its address is given" ;;
4954 *) fail "running: $out" ;;
5055 esac
5156fi
修改www/src/i18n/en.ts+2 −2看文件
@@ -183,7 +183,7 @@ export const en = {
183183 },
184184 {
185185 title: 'Resize on the fly',
186删除: body: 'A new VM gets the template’s 10 GB of disk, 3 GB of memory and 1 CPU. Pass another value and the VM is reconfigured, after asking if it is running. Disk only grows. CPU and memory are capped at half the host, per VM.',
186新增: body: 'A new VM gets the template’s 10 GB of disk, 3 GB of memory (4 with code-server picked in the wizard) and 1 CPU. Pass another value and the VM is reconfigured, after asking if it is running. Disk only grows. CPU and memory are capped at half the host, per VM.',
187187 code: 'agent-vm --disk 50 opencode\nagent-vm --memory 16 --cpus 8 shell\nagent-vm --reset claude # re-clone from the base template',
188188 },
189189 {
@@ -229,7 +229,7 @@ export const en = {
229229 rows: [
230230 ['shell, sh', 'Open a zsh shell in the VM. `-c "…"` runs a one-shot command through a login shell.'],
231231 ['run <cmd> [args]', 'Run a command with no shell. `--tty` allocates a PTY for TUIs.'],
232删除: ['code', 'Serve VS Code (code-server) from the VM at `http://<vm-name>.localhost:<port>/` and open it in your browser, until Ctrl-C. Its password is made in the VM on first use and printed. Needs `code-server` or a `code-*` name at setup ([What is in the VM](#what-is-in-the-vm)).'],
232新增: ['code', 'Serve VS Code (code-server) from the VM at `http://<vm-name>.localhost:<port>/`, until Ctrl-C, for you to open in your browser. Its password is made in the VM on first use and printed with the address. Needs `code-server` or a `code-*` name at setup ([What is in the VM](#what-is-in-the-vm)).'],
233233 ],
234234 },
235235 {
修改www/src/i18n/fr.ts+2 −2看文件
@@ -185,7 +185,7 @@ export const fr: Dictionary = {
185185 },
186186 {
187187 title: 'Redimensionner à la volée',
188删除: body: 'Une nouvelle VM reprend les 10 Go de disque, 3 Go de mémoire et 1 CPU de l\'image. Passe une autre valeur et la VM est reconfigurée, après confirmation si elle tourne. Le disque ne fait que grandir. CPU et mémoire sont plafonnés à la moitié de l\'hôte, par VM.',
188新增: body: 'Une nouvelle VM reprend les 10 Go de disque, 3 Go de mémoire (4 avec code-server choisi dans l\'assistant) et 1 CPU de l\'image. Passe une autre valeur et la VM est reconfigurée, après confirmation si elle tourne. Le disque ne fait que grandir. CPU et mémoire sont plafonnés à la moitié de l\'hôte, par VM.',
189189 code: 'agent-vm --disk 50 opencode\nagent-vm --memory 16 --cpus 8 shell\nagent-vm --reset claude # re-cloner depuis l\'image',
190190 },
191191 {
@@ -231,7 +231,7 @@ export const fr: Dictionary = {
231231 rows: [
232232 ['shell, sh', 'Ouvre un shell zsh dans la VM. `-c "…"` exécute une commande unique via un shell de connexion.'],
233233 ['run <cmd> [args]', 'Exécute une commande sans shell. `--tty` alloue un PTY pour les TUI.'],
234删除: ['code', 'Sert VS Code (code-server) depuis la VM à `http://<nom-de-vm>.localhost:<port>/` et l\'ouvre dans ton navigateur, jusqu\'à Ctrl-C. Son mot de passe est créé dans la VM à la première utilisation, puis affiché. Demande `code-server` ou un nom `code-*` au setup ([Ce qu\'il y a dans la VM](#what-is-in-the-vm)).'],
234新增: ['code', 'Sert VS Code (code-server) depuis la VM à `http://<nom-de-vm>.localhost:<port>/`, jusqu\'à Ctrl-C, à ouvrir dans ton navigateur. Son mot de passe est créé dans la VM à la première utilisation, puis affiché avec l\'adresse. Demande `code-server` ou un nom `code-*` au setup ([Ce qu\'il y a dans la VM](#what-is-in-the-vm)).'],
235235 ],
236236 },
237237 {