提交记录修改CHANGELOG.md+38 −3看文件
修改agent-vm.setup.sh+13 −6看文件
修改agent-vm.sh+51 −10看文件
修改lib/code.sh+24 −40看文件
修改lib/doctor.sh+2 −2看文件
修改lib/git.sh+96 −20看文件
修改lib/help.sh+3 −3看文件
修改lib/info.sh+2 −2看文件
修改lib/mounts.sh+181 −72看文件
修改lib/setup.sh+8 −3看文件
修改lib/vm.sh+6 −0看文件
修改tests/06-help-and-setup-script.sh+10 −3看文件
修改tests/08-mount-mode.sh+7 −2看文件
修改tests/11-recorded-commands.sh+15 −2看文件
修改tests/13-volumes-and-readonly.sh+33 −0看文件
修改tests/14-git-protection.sh+105 −0看文件
修改tests/16-setup.sh+26 −0看文件
修改tests/20-project-files.sh+20 −3看文件
修改tests/22-code.sh+10 −5看文件
修改www/src/i18n/en.ts+2 −2看文件
修改www/src/i18n/fr.ts+2 −2看文件
| @@ -4,8 +4,9 @@ | ||
| 4 | 4 | |
| 5 | 5 | ### Added |
| 6 | 6 | |
| 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` | |
| 9 | 10 | for the editor alone, `code-claude`, `code-codex` and `code-vibe` for it |
| 10 | 11 | with that agent's extension, each starting with no permission prompts. |
| 11 | 12 | The wizard asks about the editor after the agents, then whether the |
| @@ -23,12 +24,46 @@ | ||
| 23 | 24 | per port, so at `127.0.0.1` a page served by any VM would get the session |
| 24 | 25 | of every editor, which logs into it. Safari may not resolve `*.localhost`: |
| 25 | 26 | 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. | |
| 27 | 32 | |
| 28 | 33 | ### Changed |
| 29 | 34 | |
| 30 | 35 | - A command that is not in the VM (`agent-vm run foo`, or an agent not |
| 31 | 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 | 新增: 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. | |
| 32 | 67 | |
| 33 | 68 | ## 0.2.0 |
| 34 | 69 | |
| @@ -390,8 +390,6 @@ if [[ "$INSTALL_CODE_SERVER" == "1" ]]; then | ||
| 390 | 390 | # schema: setup does, once, into the machine settings (code_server_schemas). |
| 391 | 391 | # The rest is the welcome page, tips, recommendations, experiments and |
| 392 | 392 | # online settings search. |
| 393 | 删除: # The Claude keys start its conversations in bypass mode, as the managed | |
| 394 | 删除: # settings above do for the CLI. | |
| 395 | 393 | mkdir -p "$HOME/.local/share/code-server/User" |
| 396 | 394 | jq -n --arg claude "$INSTALL_CODE_CLAUDE" ' |
| 397 | 395 | { |
| @@ -413,8 +411,6 @@ if [[ "$INSTALL_CODE_SERVER" == "1" ]]; then | ||
| 413 | 411 | "update.mode": "none", |
| 414 | 412 | "update.showReleaseNotes": false |
| 415 | 413 | } + if $claude == "1" then { |
| 416 | 删除: "claudeCode.allowDangerouslySkipPermissions": true, | |
| 417 | 删除: "claudeCode.initialPermissionMode": "bypassPermissions", | |
| 418 | 414 | "claudeCode.hideOnboarding": true |
| 419 | 415 | } else {} end' > "$HOME/.local/share/code-server/User/settings.json" |
| 420 | 416 | # 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 | ||
| 424 | 420 | cs_root="$(dirname "$(dirname "$(readlink -f "$(command -v code-server)")")")" |
| 425 | 421 | fi |
| 426 | 422 | 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 | |
| 429 | 436 | # Codex and Vibe have no setting for it: their extensions start in the mode |
| 430 | 437 | # the agent's own config names. These match the flags the command line gets |
| 431 | 438 | # (_agent_vm_agent in agent-vm.sh). |
| @@ -166,11 +166,11 @@ _agent_vm_start_checks() { | ||
| 166 | 166 | fi |
| 167 | 167 | hooks_names+=("$hooks_name") |
| 168 | 168 | 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")" | |
| 170 | 170 | ro_names="$(_agent_vm_names_json ${hooks_names[@]+"${hooks_names[@]}"})" |
| 171 | 171 | |
| 172 | 172 | 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")" | |
| 174 | 174 | if [[ -n "$git_risks" ]]; then |
| 175 | 175 | echo "Warning: git on this machine uses these, and the VM can write them:" >&2 |
| 176 | 176 | printf '%s\n' "$git_risks" | sed 's/^/ /' >&2 |
| @@ -245,12 +245,19 @@ _agent_vm_apply_resources() { | ||
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | # 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. | |
| 250 | 252 | _agent_vm_push_and_probe() { |
| 251 | 删除: is_writable="false" | |
| 253 | 新增: local st=0 | |
| 252 | 254 | 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 | |
| 254 | 261 | [[ "$probe_out" == *env-ok* ]] || echo "Warning: failed to push the env files into VM '$vm_name'." >&2 |
| 255 | 262 | } |
| 256 | 263 | |
| @@ -420,13 +427,32 @@ _agent_vm_ensure_running() { | ||
| 420 | 427 | # names (names_stale), the mode (mode_stale). A stopped VM is changed before |
| 421 | 428 | # it boots, so nothing starting with it gets a writable window; a running |
| 422 | 429 | # 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="" | |
| 424 | 431 | _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 | |
| 425 | 446 | [[ "$was_protected" != "$protect_git" ]] && git_stale=1 |
| 426 | 447 | if [[ -n "$protect_git" && -n "$was_protected" ]] \ |
| 427 | 448 | && ! _agent_vm_mounts_have_readonly_names "$vm_name" "$ro_names"; then |
| 428 | 449 | names_stale=1 |
| 429 | 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 | |
| 455 | 新增: fi | |
| 430 | 456 | if [[ -n "$scratch" ]]; then |
| 431 | 457 | # Shares nothing, as made: nothing to bring in line. |
| 432 | 458 | git_stale="" |
| @@ -463,7 +489,7 @@ _agent_vm_ensure_running() { | ||
| 463 | 489 | fi |
| 464 | 490 | elif [[ -n "$names_stale" && -n "$was_running" ]]; then |
| 465 | 491 | : |
| 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 | |
| 467 | 493 | if [[ -n "$git_stale" ]]; then |
| 468 | 494 | if [[ -n "$protect_git" ]]; then |
| 469 | 495 | echo "Making every .git read-only for VM '$vm_name'..." |
| @@ -487,6 +513,14 @@ _agent_vm_ensure_running() { | ||
| 487 | 513 | _agent_vm_apply_shares "$vm_name" "$host_dir" "$want_writable" || return 1 |
| 488 | 514 | fi |
| 489 | 515 | |
| 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 | 新增: | |
| 490 | 524 | if [[ -z "$was_running" ]]; then |
| 491 | 525 | echo "Starting VM '$vm_name'..." |
| 492 | 526 | local start_log |
| @@ -543,7 +577,10 @@ _agent_vm_ensure_running() { | ||
| 543 | 577 | # yanking a running session out from under another terminal, in both |
| 544 | 578 | # directions. The repair direction does not ask: a broken mount is |
| 545 | 579 | # 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 | |
| 547 | 584 | echo "VM '$vm_name' runs read-only (--readonly). It must be restarted to make its shares writable." |
| 548 | 585 | if ! _agent_vm_can_ask || [[ "$(_agent_vm_ask_yn "Stop the VM and make it writable? Sessions using it are cut." N)" != "1" ]]; then |
| 549 | 586 | 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() { | ||
| 578 | 615 | # env file and runtime script. |
| 579 | 616 | _agent_vm_push_and_probe |
| 580 | 617 | 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 | |
| 582 | 623 | echo "Error: project directory is still not writable inside the VM:" >&2 |
| 583 | 624 | echo " $host_dir" >&2 |
| 584 | 625 | echo "The host mount failed to attach. Try 'agent-vm --reset <command>'" >&2 |
| @@ -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 ---------------------- | |
| 2 | 2 | |
| 3 | 3 | # Run in the VM before the editor starts, with the candidate ports as |
| 4 | 4 | # arguments. Prints `missing` without code-server, else its config file and |
| @@ -58,35 +58,19 @@ _agent_vm_host_port_open() { | ||
| 58 | 58 | (exec 3<>"/dev/tcp/127.0.0.1/$1") 2>/dev/null |
| 59 | 59 | } |
| 60 | 60 | |
| 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. | |
| 63 | 64 | _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." | |
| 79 | 71 | 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" | |
| 90 | 74 | } |
| 91 | 75 | |
| 92 | 76 | # `agent-vm code`: code-server for the project, in the foreground until |
| @@ -104,7 +88,7 @@ _agent_vm_code() { | ||
| 104 | 88 | |
| 105 | 89 | _agent_vm_code_session() { |
| 106 | 90 | 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 | |
| 108 | 92 | ports="$(_agent_vm_code_ports "$vm_name")" || { |
| 109 | 93 | echo "Error: cannot hash the VM name: install shasum or sha256sum." >&2 |
| 110 | 94 | return 1 |
| @@ -135,9 +119,7 @@ _agent_vm_code_session() { | ||
| 135 | 119 | |
| 136 | 120 | if [[ -n "$running" ]]; then |
| 137 | 121 | 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." | |
| 141 | 123 | return 0 |
| 142 | 124 | fi |
| 143 | 125 | |
| @@ -155,12 +137,7 @@ _agent_vm_code_session() { | ||
| 155 | 137 | fi |
| 156 | 138 | |
| 157 | 139 | 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." | |
| 164 | 141 | # A terminal for Ctrl-C to reach code-server: without one, it would keep |
| 165 | 142 | # running in the VM once this command ends. |
| 166 | 143 | [[ -t 0 && -t 1 ]] && want_tty=1 |
| @@ -171,7 +148,13 @@ _agent_vm_code_session() { | ||
| 171 | 148 | # The --vscode-option ones reach the VS Code server inside: no experiments, |
| 172 | 149 | # and the built-in Copilot Chat never loads (it updates itself otherwise). |
| 173 | 150 | # 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 \ | |
| 175 | 158 | --config "$cfg" \ |
| 176 | 159 | --bind-addr "127.0.0.1:$port" \ |
| 177 | 160 | --cookie-suffix "$vm_name" \ |
| @@ -181,9 +164,10 @@ _agent_vm_code_session() { | ||
| 181 | 164 | --disable-workspace-trust \ |
| 182 | 165 | --disable-proxy \ |
| 183 | 166 | --disable-getting-started-override \ |
| 167 | 新增: --link-protection-trusted-domains https://claude.com/cai/oauth \ | |
| 168 | 新增: --link-protection-trusted-domains https://platform.claude.com/oauth \ | |
| 184 | 169 | --vscode-option disable-experiments \ |
| 185 | 170 | --vscode-option disable-extension=GitHub.copilot-chat \ |
| 186 | 171 | "$host_dir" || st=$? |
| 187 | 删除: [[ -z "$opener" ]] || kill "$opener" 2>/dev/null | |
| 188 | 172 | return "$st" |
| 189 | 173 | } |
| @@ -308,11 +308,11 @@ _agent_vm_doctor() { | ||
| 308 | 308 | $d warn "$hooks_what, which the VM can still write" \ |
| 309 | 309 | "The next start (after 'agent-vm stop' if it runs) makes every '$hooks_name' in the project read-only." |
| 310 | 310 | fi |
| 311 | 删除: done <<< "$(_agent_vm_project_hooks "$host_dir")" | |
| 311 | 新增: done <<< "$(_agent_vm_share_hooks "$host_dir")" | |
| 312 | 312 | # Git config the VM can write, or commands it names in the project (see |
| 313 | 313 | # _agent_vm_repo_config_risks). |
| 314 | 314 | local git_risks |
| 315 | 删除: git_risks="$(_agent_vm_project_config_risks "$host_dir")" | |
| 315 | 新增: git_risks="$(_agent_vm_share_config_risks "$host_dir")" | |
| 316 | 316 | if [[ -n "$git_risks" ]]; then |
| 317 | 317 | $d warn "git on this machine uses these, and the VM can write them:" |
| 318 | 318 | printf '%s\n' "$git_risks" | sed 's/^/ /' |
| @@ -25,19 +25,21 @@ AGENT_VM_LIMA_ISSUE="https://github.com/lima-vm/lima/issues/5529" | ||
| 25 | 25 | |
| 26 | 26 | # Does this Lima enforce sshfs.readonlyNames? 0 yes, 1 no, 2 cannot tell. |
| 27 | 27 | # 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. | |
| 34 | 36 | # |
| 35 | 37 | # Not cached: agent-vm is also a shell function, where a cached answer would |
| 36 | 38 | # outlive a Lima upgrade. |
| 37 | 39 | _agent_vm_lima_protects_git() { |
| 38 | 40 | local dir out accepted="" |
| 39 | 41 | 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' \ | |
| 41 | 43 | "$(_agent_vm_host_path "$dir")" > "$dir/probe.yaml" |
| 42 | 44 | out="$(limactl validate "$(_agent_vm_host_path "$dir/probe.yaml")" 2>&1)" && accepted=1 |
| 43 | 45 | rm -rf "$dir" |
| @@ -151,20 +153,56 @@ _agent_vm_project_repos() { | ||
| 151 | 153 | # names it: lib/x/.githooks is .githooks), or the same again. Fails otherwise, |
| 152 | 154 | # or when git cannot tell. `--git-path` without --path-format (git 2.31) |
| 153 | 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. | |
| 154 | 160 | _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="" | |
| 156 | 162 | 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 | |
| 158 | 186 | [[ -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")" | |
| 168 | 206 | } |
| 169 | 207 | |
| 170 | 208 | # Every hooks folder of the project <dir>'s repositories that is in the |
| @@ -178,6 +216,21 @@ _agent_vm_project_hooks() { | ||
| 178 | 216 | done | awk '!seen[$0]++' |
| 179 | 217 | } |
| 180 | 218 | |
| 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 | 新增: | |
| 181 | 234 | # The name that keeps the hooks folder <rel> read-only: its first component, |
| 182 | 235 | # which covers the folder and whatever it calls next to it (husky's hooks call |
| 183 | 236 | # .husky/<hook>). Fails for the project itself, and for a name the mounts JSON |
| @@ -207,7 +260,7 @@ _agent_vm_readonly_names() { | ||
| 207 | 260 | while IFS=$'\t' read -r rel in_repo; do |
| 208 | 261 | [[ -n "$rel" ]] || continue |
| 209 | 262 | name="$(_agent_vm_hooks_name "$in_repo")" && names+=("$name") |
| 210 | 删除: done <<< "$(_agent_vm_project_hooks "$1")" | |
| 263 | 新增: done <<< "$(_agent_vm_share_hooks "$1")" | |
| 211 | 264 | _agent_vm_names_json ${names[@]+"${names[@]}"} |
| 212 | 265 | } |
| 213 | 266 | |
| @@ -235,7 +288,7 @@ _agent_vm_hooks_note() { | ||
| 235 | 288 | # `git config --list` prints them) with a path in their value: a start runs |
| 236 | 289 | # this, and a fork per line would show. |
| 237 | 290 | _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 | |
| 239 | 292 | base="$(_agent_vm_git_spelling "$repo")" || return 0 |
| 240 | 293 | top="$(_agent_vm_git_untrusted -C "$repo" rev-parse --show-toplevel 2>/dev/null)" || return 0 |
| 241 | 294 | _agent_vm_git_untrusted -C "$repo" config --list --show-origin --includes 2>/dev/null \ |
| @@ -285,6 +338,16 @@ _agent_vm_repo_config_risks() { | ||
| 285 | 338 | break |
| 286 | 339 | done |
| 287 | 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 | |
| 288 | 351 | } |
| 289 | 352 | |
| 290 | 353 | # The same for every repository of the project <dir>, each line once. |
| @@ -296,6 +359,19 @@ _agent_vm_project_config_risks() { | ||
| 296 | 359 | done | awk '!seen[$0]++' |
| 297 | 360 | } |
| 298 | 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 | 新增: | |
| 299 | 375 | # What a Lima without readonlyNames exposes when the shares are reverse-sshfs |
| 300 | 376 | # (see _agent_vm_unprotected_mount_is_sshfs), one paragraph, before |
| 301 | 377 | # _agent_vm_git_protection_hint. |
| @@ -22,9 +22,9 @@ Commands: | ||
| 22 | 22 | use 'shell -c "..."' instead; pass --tty for TUIs like |
| 23 | 23 | opencode, vibe, htop, etc.) |
| 24 | 24 | 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' | |
| 28 | 28 | extensions or without: --preinstall=default,code-claude |
| 29 | 29 | (or code-codex, code-vibe, code-server) |
| 30 | 30 | stop [vm-name] Stop the VM for the current directory, or the named one |
| @@ -181,8 +181,8 @@ _agent_vm_info() { | ||
| 181 | 181 | questions="${questions:+$questions,}hooks" |
| 182 | 182 | break |
| 183 | 183 | 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" | |
| 186 | 186 | fi |
| 187 | 187 | case "$(_agent_vm_bare_repo_state)" in |
| 188 | 188 | unset|old) questions="${questions:+$questions,}bare-repo" ;; |
| @@ -82,6 +82,111 @@ _agent_vm_project_mountpoint() { | ||
| 82 | 82 | printf '%s\n' "$p" |
| 83 | 83 | } |
| 84 | 84 | |
| 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 | 新增: | |
| 85 | 190 | # _agent_vm_build_mounts_json <vm> <dir> [<writable>] [<names>]: the .mounts |
| 86 | 191 | # JSON array for `limactl edit --set`. The project <dir> first, writable |
| 87 | 192 | # unless <writable> is false, then the entries of ~/.agent-vm/volumes |
| @@ -99,9 +204,12 @@ _agent_vm_project_mountpoint() { | ||
| 99 | 204 | # the VM. |
| 100 | 205 | _agent_vm_build_mounts_json() { |
| 101 | 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. | |
| 102 | 210 | 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}" ;; | |
| 105 | 213 | esac |
| 106 | 214 | # Every entry names its mount point: agent-vm addresses the guest side by the |
| 107 | 215 | # shell's spelling of the path (--workdir, the write probe), which on Windows |
| @@ -112,68 +220,9 @@ _agent_vm_build_mounts_json() { | ||
| 112 | 220 | local file_mounts_cache="$AGENT_VM_STATE_DIR/.agent-vm-file-mounts-${vm_name}" |
| 113 | 221 | |
| 114 | 222 | 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 | |
| 177 | 226 | if [[ -n "$dst" && "$dst" != /* ]]; then |
| 178 | 227 | dst="$(_agent_vm_project_mountpoint "$host_dir" "$dst" "$src")" || continue |
| 179 | 228 | fi |
| @@ -215,7 +264,7 @@ _agent_vm_build_mounts_json() { | ||
| 215 | 264 | fi |
| 216 | 265 | fi |
| 217 | 266 | 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")" | |
| 219 | 268 | fi |
| 220 | 269 | mounts_json+="]" |
| 221 | 270 | |
| @@ -264,6 +313,52 @@ _agent_vm_mounts_have_readonly_names() { | ||
| 264 | 313 | [[ -f "$record" ]] && grep -qF "\"readonlyNames\": $2" "$record" |
| 265 | 314 | } |
| 266 | 315 | |
| 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 | 新增: | |
| 267 | 362 | # _agent_vm_push_env_and_probe <vm> <dir> <payload> [<env> [<runtime>]], in |
| 268 | 363 | # one round trip: |
| 269 | 364 | # - writes ~/.agent-vm.env in the VM (mode 600, sourced by its ~/.zshenv): |
| @@ -271,16 +366,29 @@ _agent_vm_mounts_have_readonly_names() { | ||
| 271 | 366 | # the VM, CRs dropped; empty too, so env removed on the host goes. Prints |
| 272 | 367 | # env-ok. |
| 273 | 368 | # - 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. | |
| 276 | 375 | _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"; } \ | |
| 279 | 379 | | limactl shell "$vm_name" sh -c ' |
| 280 | 380 | (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 |
| 281 | 381 | [ -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 | |
| 284 | 392 | } |
| 285 | 393 | |
| 286 | 394 | # Are <vm>'s shares ones whose read-only flag is enforced outside the guest? |
| @@ -310,7 +418,8 @@ _agent_vm_mount_is_host_enforced() { | ||
| 310 | 418 | # The record says agent-vm gave it readonlyNames, and the Lima installed |
| 311 | 419 | # now serves them: a stock limactl started by hand would not. |
| 312 | 420 | ?*" 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 | |
| 314 | 423 | return 1 ;; |
| 315 | 424 | *) return 2 ;; |
| 316 | 425 | esac |
| @@ -122,7 +122,7 @@ _agent_vm_ask_code_extensions() { | ||
| 122 | 122 | |
| 123 | 123 | _agent_vm_setup() { |
| 124 | 124 | local disk=10 |
| 125 | 删除: local memory=3 | |
| 125 | 新增: local memory=3 memory_seen="" | |
| 126 | 126 | local cpus=1 |
| 127 | 127 | local preinstall="" |
| 128 | 128 | local preinstall_seen="" |
| @@ -151,7 +151,7 @@ _agent_vm_setup() { | ||
| 151 | 151 | local opt="${vm_opts[*]-}" |
| 152 | 152 | case "$opt" in |
| 153 | 153 | "--disk "*) disk="${opt#--disk }" ;; |
| 154 | 删除: "--memory "*) memory="${opt#--memory }" ;; | |
| 154 | 新增: "--memory "*) memory="${opt#--memory }"; memory_seen=1 ;; | |
| 155 | 155 | "--cpus "*) cpus="${opt#--cpus }" ;; |
| 156 | 156 | *) |
| 157 | 157 | echo "Unknown option: ${1%%=*}" >&2 |
| @@ -175,7 +175,7 @@ the wizard is skipped automatically and the default set is installed. | ||
| 175 | 175 | |
| 176 | 176 | Options: |
| 177 | 177 | --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) | |
| 179 | 179 | --cpus N Number of CPUs (default: 1) |
| 180 | 180 | --preinstall=LIST Comma-separated list of tools to preinstall in the base |
| 181 | 181 | VM image (skips the wizard). Anything not listed is |
| @@ -429,6 +429,11 @@ EOF | ||
| 429 | 429 | install_golang=$(_agent_vm_ask_yn "Go" N) |
| 430 | 430 | fi |
| 431 | 431 | |
| 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 | 新增: | |
| 432 | 437 | # Resources second, the same way, accepted in one go or not. Current |
| 433 | 438 | # values reflect any --disk/--memory/--cpus already passed on the CLI. |
| 434 | 439 | # These are starting values: any later `agent-vm` command can resize the |
| @@ -91,6 +91,12 @@ _agent_vm_unsafe_project() { | ||
| 91 | 91 | return 0 ;; |
| 92 | 92 | esac |
| 93 | 93 | 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 | |
| 94 | 100 | return 1 |
| 95 | 101 | } |
| 96 | 102 | |
| @@ -322,9 +322,16 @@ $(awk '/^configure_mcp\(\) \{/,/^\}/' "$SETUP_SH")" | ||
| 322 | 322 | check "the three extensions, in one call" \ |
| 323 | 323 | "$(grep '^code-server' "$CSA/calls.log" | head -n 1)" \ |
| 324 | 324 | "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" | |
| 328 | 335 | check "codex: full access, once, before any table" \ |
| 329 | 336 | "$(head -n 2 "$CSA/.codex/config.toml" | sort | tr '\n' ' '; grep -c '^approval_policy' "$CSA/.codex/config.toml")" \ |
| 330 | 337 | 'approval_policy = "never" sandbox_mode = "danger-full-access" 1' |
| @@ -28,7 +28,7 @@ esac | ||
| 28 | 28 | |
| 29 | 29 | # .git protection: Lima refuses readonlyNames unless EVERY mount uses the |
| 30 | 30 | # 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"]}' | |
| 32 | 32 | printf '%s:/mnt/v:rw\n' "$SB/extra-vol" > "$HOME/.agent-vm/volumes" |
| 33 | 33 | mounts_prot="$(_agent_vm_build_mounts_json agent-vm-t "$PROJ" true 1)" |
| 34 | 34 | rm -f "$HOME/.agent-vm/volumes" |
| @@ -58,6 +58,7 @@ mount_types() { | ||
| 58 | 58 | cat > "$SB/bin/limactl" <<STUB |
| 59 | 59 | #!/usr/bin/env bash |
| 60 | 60 | [ "\$1" = shell ] && { echo 9p; exit 0; } |
| 61 | 新增:case "\$*" in *"json .Config.Mounts"*) printf '%s\n' "\${MT_LIVE:-}"; exit 0 ;; esac | |
| 61 | 62 | [ "\$1" = list ] && { printf '%s\n' "$1"; exit 0; } |
| 62 | 63 | [ "\$1" = validate ] && [ -n "\${MT_PROTECTS:-}" ] && { echo 'field mounts[*].sshfs.readonlyNames requires mountType to be reverse-sshfs' >&2; exit 1; } |
| 63 | 64 | exit 1 |
| @@ -92,7 +93,11 @@ check "unset on QEMU, no lima-version: reverse-sshfs, not" "$(LIMA_HOME="$SB/lim | ||
| 92 | 93 | # cannot tell the servers apart: the record of the applied mounts does. |
| 93 | 94 | mkdir -p "$HOME/.agent-vm" |
| 94 | 95 | printf '[{"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" | |
| 96 | 101 | # Recorded so, but served by a Lima without them (a stock limactl started it |
| 97 | 102 | # since): not. |
| 98 | 103 | check "recorded with readonlyNames, a Lima without them: not" "$(mount_types 'qemu reverse-sshfs')" "1" |
| @@ -10,7 +10,8 @@ section "commands against a recording limactl" | ||
| 10 | 10 | # would. AGENT_VM_TEST_STOP_FAIL makes `stop` leave it running. |
| 11 | 11 | # AGENT_VM_TEST_SSHFS_FAIL fails the sshfs install of a 0.1.0 VM. |
| 12 | 12 | # 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. | |
| 14 | 15 | # `validate` answers like stock Lima 2.2 does to readonlyNames, or, while the |
| 15 | 16 | # file $PROTECTS exists, like a Lima that has it (both messages copied from |
| 16 | 17 | # the real binaries). AGENT_VM_TEST_VALIDATE_SILENT makes it accept the file |
| @@ -43,6 +44,17 @@ case "$1" in | ||
| 43 | 44 | listed && echo "$AGENT_VM_TEST_VM ${AGENT_VM_TEST_SSH_PORT:-0}" ;; |
| 44 | 45 | *"{{.Config.SSH.LocalPort}}"*) listed && echo "${AGENT_VM_TEST_SSH_PORT:-0}" ;; |
| 45 | 46 | *"{{.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 ;; | |
| 46 | 58 | *"{{.VMType}}"*) echo "${AGENT_VM_TEST_VMTYPE:-vz} ${AGENT_VM_TEST_MOUNTTYPE:-virtiofs}" ;; |
| 47 | 59 | *"{{.CPUs}}"*"{{.Disk}}"*) listed && echo "$AGENT_VM_TEST_VM|1|3221225472|10737418240" ;; |
| 48 | 60 | *"{{.Status}}|"*) listed && echo "$AGENT_VM_TEST_VM|Running|1|3221225472" ;; |
| @@ -67,7 +79,8 @@ case "$1" in | ||
| 67 | 79 | [ -n "${AGENT_VM_TEST_ENV_FAIL:-}" ] || echo env-ok |
| 68 | 80 | [ -z "${AGENT_VM_TEST_RUNTIME_FOUND:-}" ] || echo runtime-found ;; |
| 69 | 81 | 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 ;; | |
| 71 | 84 | *"exec "*" -s"*) cat >> "${AGENT_VM_TEST_STDIN:-/dev/null}" ;; |
| 72 | 85 | # The editor's prep (lib/code.sh): AGENT_VM_TEST_CODE_PREP is its answer. |
| 73 | 86 | *"agent-vm-code "*) |
| @@ -167,6 +167,16 @@ case "$out" in *"Project mount is not writable; repairing"*) pass "a writable VM | ||
| 167 | 167 | # project's env file or runtime: the repaired VM gets them pushed again. |
| 168 | 168 | check "after a repair, the env is pushed again, with the project's files" \ |
| 169 | 169 | "$(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 | |
| 170 | 180 | rm -f "$REC_MOUNTS" |
| 171 | 181 | ro_run |
| 172 | 182 | rec_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 | ||
| 261 | 271 | none) pass "a project inside the home directory is fine" ;; |
| 262 | 272 | *) fail "a project inside the home directory was refused" ;; |
| 263 | 273 | esac |
| 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" | |
| @@ -30,6 +30,21 @@ for t in mktemp rm; do | ||
| 30 | 30 | chmod +x "$SB/nolimactl/$t" |
| 31 | 31 | done |
| 32 | 32 | check "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" | |
| 33 | 48 | check "a Lima accepting the probe without a word: cannot tell" \ |
| 34 | 49 | "$(AGENT_VM_TEST_VALIDATE_SILENT=1 probe)" "unknown" |
| 35 | 50 | |
| @@ -316,6 +331,45 @@ _agent_vm_mounts_have_readonly_names "$PV" '[".git", ".hg"]' && pass "names: rec | ||
| 316 | 331 | out="$(AGENT_VM_TEST_STOPPED=1 rec run true)" |
| 317 | 332 | rec_has "edit $PV" && fail "names: edited again with nothing to change" || pass "names: nothing to change the next time" |
| 318 | 333 | |
| 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 | 新增: | |
| 319 | 373 | # core.hooksPath in the project: its first component joins the names. |
| 320 | 374 | if command -v git >/dev/null 2>&1; then |
| 321 | 375 | # 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 | ||
| 386 | 440 | || fail "hooks: nested, start: $(grep '^edit' "$REC")" |
| 387 | 441 | rm -rf "$PROJ/lib" |
| 388 | 442 | |
| 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 | 新增: | |
| 389 | 494 | # A name that is not a dot-name is read-only in every folder of the |
| 390 | 495 | # project, so it is asked first: yes by default, and when no one can answer. |
| 391 | 496 | hp tools/hooks |
| @@ -29,6 +29,7 @@ cat > "$SB/wizlima/limactl" <<STUB | ||
| 29 | 29 | case "\$1" in |
| 30 | 30 | shell) cat > "$SB/wizard.stdin" ;; |
| 31 | 31 | list) [ "\$2" = -q ] && echo agent-vm-base ;; |
| 32 | 新增: create) echo "\$*" > "$SB/wizard.create" ;; | |
| 32 | 33 | esac |
| 33 | 34 | exit 0 |
| 34 | 35 | STUB |
| @@ -48,6 +49,31 @@ check "wizard defaults: Ruby, Rust, Go, Pi and Playwright MCP off; Claude on" \ | ||
| 48 | 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' ' ')" \ |
| 49 | 50 | "RUBY=0 RUST=0 GOLANG=0 CLAUDE=1 PI=0 MCP_PLAYWRIGHT=0 " |
| 50 | 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. | |
| 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 | 新增: | |
| 51 | 77 | section "release.sh" |
| 52 | 78 | REL="$SELF_DIR/release.sh" |
| 53 | 79 | notes="$("$REL" notes "$AGENT_VM_VERSION" 2>&1)" |
| @@ -113,10 +113,12 @@ STUB | ||
| 113 | 113 | chmod +x "$SB/localvm/limactl" |
| 114 | 114 | printf 'B=2\r\nA=project\r\n' > "$PF/.agent-vm.env" |
| 115 | 115 | : > "$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=$?")" | |
| 117 | 117 | check "the VM writes the shared payload, then the project's file, without CRs" \ |
| 118 | 118 | "$(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" | |
| 120 | 122 | if _agent_vm_on_windows; then |
| 121 | 123 | printf ' skip the guest env file is private (permission bits are emulated on Windows)\n' |
| 122 | 124 | else |
| @@ -124,7 +126,22 @@ else | ||
| 124 | 126 | fi |
| 125 | 127 | rm -f "$PF/.agent-vm.runtime.sh" |
| 126 | 128 | out="$(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" | |
| 128 | 145 | if command -v zsh >/dev/null 2>&1; then |
| 129 | 146 | printf '#!/usr/bin/env bash\r\necho "ran:${BASH_VERSION:+bash}" > "$HOME/rt-out"\r\n' > "$PF/.agent-vm.runtime.sh" |
| 130 | 147 | PATH="$SB/localvm:$PATH" _agent_vm_run_project_runtime vm "$PF" "$PF/.agent-vm.runtime.sh" >/dev/null 2>&1 |
| @@ -21,21 +21,26 @@ if _agent_vm_host_port_open "$first"; then | ||
| 21 | 21 | printf ' skip code launch tests (port %s is taken on this machine)\n' "$first" |
| 22 | 22 | else |
| 23 | 23 | 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" \ | |
| 25 | 25 | && pass "code-server on the VM's loopback, the VM's own config and cookie" \ |
| 26 | 26 | || 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")" | |
| 27 | 29 | rec_has "--disable-telemetry --disable-update-check --disable-workspace-trust --disable-proxy" \ |
| 28 | 30 | && pass "no telemetry, update check or port proxy" || fail "code flags: $(grep 'code-server --config' "$REC")" |
| 29 | 31 | rec_has "--vscode-option disable-experiments --vscode-option disable-extension=GitHub.copilot-chat $PROJ" \ |
| 30 | 32 | && pass "no experiments, Copilot never loaded, and the project opened" || fail "code flags: $(grep 'code-server --config' "$REC")" |
| 31 | 33 | 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" ;; | |
| 34 | 36 | *) fail "code output: $out" ;; |
| 35 | 37 | esac |
| 36 | 38 | 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/')" \ | |
| 38 | 40 | "$(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" | |
| 39 | 44 | |
| 40 | 45 | AGENT_VM_TEST_CODE_PREP="config=/c.yaml\npassword=pw\nlistening=$first\n" rec code >/dev/null |
| 41 | 46 | rec_has "--bind-addr 127.0.0.1:$((first + 1))" \ |
| @@ -45,7 +50,7 @@ else | ||
| 45 | 50 | rec_has "code-server --config" && fail "a second editor was started" \ |
| 46 | 51 | || pass "an editor already running is not started again" |
| 47 | 52 | 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" ;; | |
| 49 | 54 | *) fail "running: $out" ;; |
| 50 | 55 | esac |
| 51 | 56 | fi |
| @@ -183,7 +183,7 @@ export const en = { | ||
| 183 | 183 | }, |
| 184 | 184 | { |
| 185 | 185 | 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.', | |
| 187 | 187 | code: 'agent-vm --disk 50 opencode\nagent-vm --memory 16 --cpus 8 shell\nagent-vm --reset claude # re-clone from the base template', |
| 188 | 188 | }, |
| 189 | 189 | { |
| @@ -229,7 +229,7 @@ export const en = { | ||
| 229 | 229 | rows: [ |
| 230 | 230 | ['shell, sh', 'Open a zsh shell in the VM. `-c "…"` runs a one-shot command through a login shell.'], |
| 231 | 231 | ['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)).'], | |
| 233 | 233 | ], |
| 234 | 234 | }, |
| 235 | 235 | { |
| @@ -185,7 +185,7 @@ export const fr: Dictionary = { | ||
| 185 | 185 | }, |
| 186 | 186 | { |
| 187 | 187 | 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.', | |
| 189 | 189 | code: 'agent-vm --disk 50 opencode\nagent-vm --memory 16 --cpus 8 shell\nagent-vm --reset claude # re-cloner depuis l\'image', |
| 190 | 190 | }, |
| 191 | 191 | { |
| @@ -231,7 +231,7 @@ export const fr: Dictionary = { | ||
| 231 | 231 | rows: [ |
| 232 | 232 | ['shell, sh', 'Ouvre un shell zsh dans la VM. `-c "…"` exécute une commande unique via un shell de connexion.'], |
| 233 | 233 | ['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)).'], | |
| 235 | 235 | ], |
| 236 | 236 | }, |
| 237 | 237 | { |

