提交记录修改CHANGELOG.md+64 −31看文件
修改agent-vm.setup.sh+95 −46看文件
修改agent-vm.sh+91 −55看文件
修改lib/code.sh+41 −34看文件
修改lib/doctor.sh+19 −10看文件
修改lib/git.sh+346 −198看文件
修改lib/help.sh+12 −6看文件
修改lib/host.sh+10 −0看文件
修改lib/info.sh+4 −2看文件
修改lib/mounts.sh+262 −148看文件
修改lib/setup.sh+6 −10看文件
修改lib/ui.sh+12 −14看文件
修改lib/vm.sh+55 −17看文件
修改test-e2e.sh+7 −4看文件
修改tests/06-help-and-setup-script.sh+37 −10看文件
修改tests/08-mount-mode.sh+37 −7看文件
修改tests/11-recorded-commands.sh+51 −21看文件
修改tests/13-volumes-and-readonly.sh+26 −2看文件
修改tests/14-git-protection.sh+161 −17看文件
修改tests/16-setup.sh+9 −17看文件
修改tests/18-windows.sh+1 −1看文件
修改tests/20-project-files.sh+38 −8看文件
修改tests/21-scratch.sh+7 −1看文件
修改tests/22-code.sh+36 −4看文件
修改www/src/i18n/en.ts+7 −5看文件
修改www/src/i18n/fr.ts+7 −5看文件
| @@ -16,32 +16,49 @@ | ||
| 16 | 16 | theme, GitHub Copilot disabled, no telemetry, no welcome page, tips, |
| 17 | 17 | recommendations or experiments. The JSON schemas the editor validates |
| 18 | 18 | files with (`package.json`, `tsconfig.json`...) are downloaded once by |
| 19 | 删除: `setup`: opening a file sends no request. | |
| 19 | 新增: `setup`, in parallel, each stored under the URL the editor asks for (a | |
| 20 | 新增: schema's references followed from its `$id`, as the editor does): | |
| 21 | 新增: opening a file sends no request. | |
| 20 | 22 | - The editor's password is made in each VM on first use, never in the base, |
| 21 | 23 | of which every VM is a copy, and printed. Each VM's editor is at |
| 22 | 删除: `http://<vm-name>.localhost:<port>/`, a port of its own from 20000 to | |
| 23 | 删除: 29999, the same on every start: browsers keep cookies per host name, not | |
| 24 | 删除: per port, so at `127.0.0.1` a page served by any VM would get the session | |
| 25 | 删除: of every editor, which logs into it. Safari may not resolve `*.localhost`: | |
| 26 | 删除: then `127.0.0.1` in a private window kept for the editor. code-server's | |
| 27 | 删除: port proxy is off: links to `localhost:<port>` open at that port on your | |
| 28 | 删除: machine, where Lima forwards it. Claude Code's login pages open without the editor's | |
| 29 | 删除: link prompt; other links still ask. | |
| 24 | 新增: `http://<vm-name>.localhost:<port>/`, the first of ten ports from 20000 to | |
| 25 | 新增: 29999 picked from its name that is free, so the same on every start while | |
| 26 | 新增: it is: browsers keep cookies per host name, not per port, so a page a VM | |
| 27 | 新增: serves at `127.0.0.1` does not get the session of every editor. Safari may | |
| 28 | 新增: not resolve `*.localhost`: then `127.0.0.1` in a private window kept for | |
| 29 | 新增: the editor. code-server's port proxy is off: links to `localhost:<port>` | |
| 30 | 新增: open at that port on your machine, where Lima forwards it. Claude Code's | |
| 31 | 新增: login pages open without the editor's link prompt; other links still ask. | |
| 32 | 新增:- Not a boundary between VMs: a VM can listen on a port Lima forwards to | |
| 33 | 新增: your machine and send your browser to another VM's editor host name on | |
| 34 | 新增: it, getting that editor's session. Keeping VMs apart needs network | |
| 35 | 新增: isolation, on the roadmap; until then, stop `agent-vm code` when not | |
| 36 | 新增: using it. | |
| 30 | 37 | - With code-server picked in the wizard, the base gets 4 GB of memory |
| 31 | 38 | instead of 3, unless `--memory` says otherwise. |
| 32 | 39 | |
| 33 | 40 | ### Changed |
| 34 | 41 | |
| 35 | 42 | - A command that is not in the VM (`agent-vm run foo`, or an agent not |
| 36 | 删除: installed) says so, with status 127, instead of `env`'s error. | |
| 37 | 删除:- The protected shares turn sshfs's cache off: with it, a file the host | |
| 38 | 删除: changed showed as it was for up to 20 seconds, and an agent writing back | |
| 39 | 删除: what it read undid the change. Existing VMs get it on their next start | |
| 40 | 删除: from stopped. | |
| 41 | 删除:- A project share that is no longer mounted (sshfs died) is caught: the | |
| 42 | 删除: write probe now checks that its file reached the host. The VM is restarted | |
| 43 | 新增: installed) says so, with status 127, instead of `env`'s error. A path | |
| 44 | 新增: (`./build.sh`) is still `env`'s to run, with its reason: a script without | |
| 45 | 新增: +x is denied, status 126. | |
| 46 | 新增:- The protected writable shares turn sshfs's cache off: with it, a file the | |
| 47 | 新增: host changed showed as it was for up to 20 seconds, and an agent writing | |
| 48 | 新增: back what it read undid the change. `AGENT_VM_SSHFS_CACHE=1` in the shell | |
| 49 | 新增: turns it back on, faster on many files (a repeated `git status` sends | |
| 50 | 新增: about 20 times fewer requests). The read-only shares keep it. Existing VMs | |
| 51 | 新增: get it on their next start from stopped. | |
| 52 | 新增:- A project share that is no longer mounted (sshfs died) is caught: the VM | |
| 53 | 新增: must see a file this machine just put in the project. The VM is restarted | |
| 43 | 54 | with its shares, with a warning that what it wrote meanwhile is on its own |
| 44 | 删除: disk. | |
| 55 | 新增: disk. No probe file is left anywhere, a `--scratch` folder included. | |
| 56 | 新增:- `agent-vm code` finds the ports something in the VM listens on with `ss`, | |
| 57 | 新增: whatever it speaks, and never through the VM's HTTP proxy, which made | |
| 58 | 新增: every port look taken. | |
| 59 | 新增:- A start reads `~/.agent-vm/volumes` and scans the repositories of each | |
| 60 | 新增: share once: about 4 times fewer processes with a writable volume holding | |
| 61 | 新增: many repositories. | |
| 45 | 62 | |
| 46 | 63 | ### Security |
| 47 | 64 | |
| @@ -51,19 +68,35 @@ | ||
| 51 | 68 | not. |
| 52 | 69 | - A VM recorded as protected is checked against the shares Lima has for it: |
| 53 | 70 | a share without the read-only names, set by hand or by Lima's `_config`, |
| 54 | 删除: makes it unprotected, and a stopped VM that keeps one is not started. A | |
| 55 | 删除: running VM served by another `limactl` than the one on `PATH` (a stock | |
| 56 | 删除: Lima started it) is not taken as protected either. | |
| 57 | 删除:- Hooks reached through symlinks: `.git/hooks` or `core.hooksPath` linked to | |
| 58 | 删除: a folder of the project makes that folder read-only too, and a hook that | |
| 59 | 删除: is a link to a file of the project is a risk to accept. | |
| 60 | 删除:- Repositories in writable `~/.agent-vm/volumes` get the same checks as the | |
| 61 | 删除: project's: their hooks folders join the read-only names, and their config | |
| 62 | 删除: naming commands in them is a risk to accept. | |
| 63 | 删除:- A `.git` or `.hg`, or a folder inside one, is refused as a project: the | |
| 64 | 删除: read-only names apply below a share's root only. A volume is refused when | |
| 65 | 删除: it would be refused as a project (agent-vm's state, Lima's, the home | |
| 66 | 删除: directory), or when its destination covers the project. | |
| 71 | 新增: makes it unprotected, and no boot (a first start, a repair, a restart for | |
| 72 | 新增: `--readonly`, the 0.1.0 migration) happens with one; the error says which | |
| 73 | 新增: share, or that the mount type is wrong. A VM that shares nothing | |
| 74 | 新增: (`--scratch`, the migration) boots with no share at all. A running VM | |
| 75 | 新增: served by another `limactl` build than the one on `PATH` (a stock Lima | |
| 76 | 新增: started it) is not taken as protected either, by a start, by `--readonly` | |
| 77 | 新增: or by `doctor`: on macOS the running binary is asked of `lsof`, which a | |
| 78 | 新增: Homebrew link does not fool, and the same build reinstalled since is not | |
| 79 | 新增: taken for another. `--readonly` is refused when Lima's `_config` gives the | |
| 80 | 新增: VM a writable share. | |
| 81 | 新增:- What git on this machine runs from a share, found wherever it points: | |
| 82 | 新增: hooks folders, hooks, commands and included config in the project, in a | |
| 83 | 新增: writable volume, or pointing from one to another (`core.hooksPath` or | |
| 84 | 新增: `core.fsmonitor` into a volume), and git's own global config kept in one. | |
| 85 | 新增: A hooks folder becomes a read-only name; anything else is a risk to | |
| 86 | 新增: accept. Every symlink on the way is followed, a link not there yet | |
| 87 | 新增: included (the VM could create its target), and a link inside the | |
| 88 | 新增: project on the way is protected as well. Writable volumes reached through | |
| 89 | 新增: a symlink are searched, bare repositories in them get their folder's name | |
| 90 | 新增: read-only, and more than 50 repositories in one share is said. A hook | |
| 91 | 新增: linked to another inside its own read-only folder is no risk any more. | |
| 92 | 新增: Names printed from the shares have their control characters made | |
| 93 | 新增: visible. | |
| 94 | 新增:- A `.git` or `.hg`, a bare repository, or a folder inside one, is refused as | |
| 95 | 新增: the project, and as a writable volume: the read-only names apply below a | |
| 96 | 新增: share's root only. A volume is refused when it is, contains or is inside | |
| 97 | 新增: agent-vm's state, Lima's or agent-vm itself, or contains the home folder, | |
| 98 | 新增: read-only or not, and when it would be mounted at or above the project, or | |
| 99 | 新增: where another volume is, whatever the spelling or with no destination. | |
| 67 | 100 | |
| 68 | 101 | ## 0.2.0 |
| 69 | 102 | |
| @@ -314,7 +347,7 @@ has passwordless sudo, so anything enforced there is advisory at best. | ||
| 314 | 347 | that save the port rather than an alias (#28). `0` goes back to a new port on |
| 315 | 348 | each start. A port another agent-vm VM has is refused. `info` gains |
| 316 | 349 | `ssh_host` and `ssh_config`: Lima's alias for the VM and the SSH config file |
| 317 | 删除: it keeps current. [The website](https://www.agent-vm.org/#connect-an-ide-over-ssh) | |
| 350 | 新增: it keeps current. [The website](https://www.agent-vm.org/#ssh-from-your-machine) | |
| 318 | 351 | has the `~/.ssh/config` lines to use them, which keep the host's SSH agent out |
| 319 | 352 | of the VM. |
| 320 | 353 | - `curl -fsSL https://www.agent-vm.org/install.sh | sh` installs the latest |
| @@ -51,6 +51,8 @@ INSTALL_CODE_SERVER="${AGENT_VM_INSTALL_CODE_SERVER:-0}" | ||
| 51 | 51 | INSTALL_CODE_CLAUDE="${AGENT_VM_INSTALL_CODE_CLAUDE:-0}" |
| 52 | 52 | INSTALL_CODE_CODEX="${AGENT_VM_INSTALL_CODE_CODEX:-0}" |
| 53 | 53 | INSTALL_CODE_VIBE="${AGENT_VM_INSTALL_CODE_VIBE:-0}" |
| 54 | 新增:# An extension needs the editor: `agent-vm setup` says so already, a run of | |
| 55 | 新增:# this script on its own may not. | |
| 54 | 56 | if [[ "$INSTALL_CODE_CLAUDE$INSTALL_CODE_CODEX$INSTALL_CODE_VIBE" == *1* ]]; then |
| 55 | 57 | INSTALL_CODE_SERVER=1 |
| 56 | 58 | fi |
| @@ -321,49 +323,94 @@ toml_prepend() { | ||
| 321 | 323 | mv "$file.tmp" "$file" |
| 322 | 324 | } |
| 323 | 325 | |
| 326 | 新增:# The URL <ref> points to from the http(s) URL <base>, fragments dropped: | |
| 327 | 新增:# absolute, scheme-relative, absolute-path or relative, its . and .. | |
| 328 | 新增:# segments resolved (RFC 3986). Fails for another scheme (vscode://..., the | |
| 329 | 新增:# editor's own schemas). | |
| 330 | 新增:schema_url_resolve() { | |
| 331 | 新增: local base="${1%%#*}" ref="${2%%#*}" scheme rest host path seg | |
| 332 | 新增: local -a segs=() kept=() | |
| 333 | 新增: case "$ref" in | |
| 334 | 新增: http://*|https://*) base="$ref" ref="" ;; | |
| 335 | 新增: *://*) return 1 ;; | |
| 336 | 新增: esac | |
| 337 | 新增: scheme="${base%%://*}" | |
| 338 | 新增: rest="${base#*://}" | |
| 339 | 新增: host="${rest%%/*}" | |
| 340 | 新增: path=/ | |
| 341 | 新增: [[ "$rest" != */* ]] || path="/${rest#*/}" | |
| 342 | 新增: case "$ref" in | |
| 343 | 新增: "") ;; | |
| 344 | 新增: //*) | |
| 345 | 新增: host="${ref#//}" | |
| 346 | 新增: path=/ | |
| 347 | 新增: if [[ "$host" == */* ]]; then path="/${host#*/}"; host="${host%%/*}"; fi ;; | |
| 348 | 新增: /*) path="$ref" ;; | |
| 349 | 新增: *) path="${path%/*}/$ref" ;; | |
| 350 | 新增: esac | |
| 351 | 新增: IFS=/ read -ra segs <<< "$path" | |
| 352 | 新增: for seg in ${segs[@]+"${segs[@]}"}; do | |
| 353 | 新增: case "$seg" in | |
| 354 | 新增: ""|.) ;; | |
| 355 | 新增: ..) [[ ${#kept[@]} -eq 0 ]] || unset 'kept[-1]' ;; | |
| 356 | 新增: *) kept+=("$seg") ;; | |
| 357 | 新增: esac | |
| 358 | 新增: done | |
| 359 | 新增: local IFS=/ | |
| 360 | 新增: printf '%s://%s/%s\n' "$scheme" "$host" "${kept[*]}" | |
| 361 | 新增:} | |
| 362 | 新增: | |
| 324 | 363 | # Write to <out> code-server's machine settings with every JSON schema its |
| 325 | 364 | # built-in extensions (in <ext-dir>) name by URL, and every schema those refer |
| 326 | 删除:# to, downloaded now. A json.schemas entry with a URL and its content makes | |
| 327 | 删除:# the editor use the content instead of fetching the URL, so with downloads | |
| 328 | 删除:# off (the user settings) opening a file sends no request. A failed download | |
| 329 | 删除:# only leaves its files unvalidated. | |
| 365 | 新增:# to, downloaded now, a level of references at a time, in parallel. A | |
| 366 | 新增:# json.schemas entry with a URL and its content makes the editor use the | |
| 367 | 新增:# content instead of fetching the URL, so with downloads off (the user | |
| 368 | 新增:# settings) opening a file sends no request. A failed download only leaves | |
| 369 | 新增:# its files unvalidated. | |
| 370 | 新增:# The editor resolves a schema's relative references against its $id when it | |
| 371 | 新增:# has one (www.schemastore.org/package says json.schemastore.org/package.json), | |
| 372 | 新增:# else against the URL it loaded it from: so are they here, for each to be | |
| 373 | 新增:# stored under the URL the editor asks for. | |
| 374 | 新增:# These are the machine settings: a json.schemas of the user settings would | |
| 375 | 新增:# be replaced by this one, not added to (VS Code merges objects across | |
| 376 | 新增:# settings, not arrays). A schema of your own goes in a workspace's settings. | |
| 330 | 377 | code_server_schemas() { |
| 331 | 删除: local ext_dir="$1" out="$2" dir u f r base fetch n=0 | |
| 332 | 删除: local -a queue | |
| 333 | 删除: local -A seen | |
| 378 | 新增: local ext_dir="$1" out="$2" dir u f r base i n=0 | |
| 379 | 新增: local -a level next fetch | |
| 380 | 新增: local -A seen urls | |
| 334 | 381 | dir="$(mktemp -d)" |
| 335 | 382 | : > "$dir/entries" |
| 336 | 删除: mapfile -t queue < <(jq -r '.contributes.jsonValidation[]?.url | select(test("^https?://"))' \ | |
| 383 | 新增: mapfile -t level < <(jq -r '.contributes.jsonValidation[]?.url | select(test("^https?://"))' \ | |
| 337 | 384 | "$ext_dir"/*/package.json | sort -u) |
| 338 | 删除: while [[ ${#queue[@]} -gt 0 ]]; do | |
| 339 | 删除: u="${queue[0]}" | |
| 340 | 删除: queue=("${queue[@]:1}") | |
| 341 | 删除: [[ -z "${seen[$u]:-}" ]] || continue | |
| 342 | 删除: seen[$u]=1 | |
| 343 | 删除: n=$((n + 1)) | |
| 344 | 删除: f="$dir/$n.json" | |
| 345 | 删除: # json.schemastore.org only redirects to www.schemastore.org. | |
| 346 | 删除: fetch="${u%%#*}" | |
| 347 | 删除: fetch="${fetch/#https:\/\/json.schemastore.org\//https://www.schemastore.org/}" | |
| 348 | 删除: if ! curl -fsSL --max-time 30 -o "$f" "$fetch" </dev/null || ! jq -e . "$f" >/dev/null 2>&1; then | |
| 349 | 删除: echo "Warning: could not download the JSON schema $u: files using it are not validated." >&2 | |
| 350 | 删除: continue | |
| 351 | 删除: fi | |
| 352 | 删除: jq -c --arg u "$u" '{url: $u, schema: .}' "$f" >> "$dir/entries" | |
| 353 | 删除: # Relative references resolve against the URL the schema was loaded from. | |
| 354 | 删除: # Other schemes (vscode://) are the editor's own. | |
| 355 | 删除: base="${u%%#*}" | |
| 356 | 删除: while IFS= read -r r; do | |
| 357 | 删除: case "$r" in | |
| 358 | 删除: http://*|https://*) ;; | |
| 359 | 删除: *://*) continue ;; | |
| 360 | 删除: /*) r="${base%%://*}://$(printf '%s' "${base#*://}" | cut -d/ -f1)$r" ;; | |
| 361 | 删除: *) r="${base%/*}/$r" ;; | |
| 362 | 删除: esac | |
| 363 | 删除: while [[ "$r" == */./* ]]; do r="${r/\/.\///}"; done | |
| 364 | 删除: while [[ "$r" =~ ^(.*://.*)/[^/]+/\.\./(.*)$ ]]; do r="${BASH_REMATCH[1]}/${BASH_REMATCH[2]}"; done | |
| 365 | 删除: queue+=("$r") | |
| 366 | 删除: done < <(jq -r '[.. | objects | ."$ref"? | strings | sub("#.*$"; "") | select(length > 0)] | unique[]' "$f") | |
| 385 | 新增: while [[ ${#level[@]} -gt 0 ]]; do | |
| 386 | 新增: fetch=() urls=() next=() | |
| 387 | 新增: for u in "${level[@]}"; do | |
| 388 | 新增: u="${u%%#*}" | |
| 389 | 新增: [[ -z "${seen[$u]:-}" ]] || continue | |
| 390 | 新增: seen[$u]=1 | |
| 391 | 新增: n=$((n + 1)) | |
| 392 | 新增: urls[$n]="$u" | |
| 393 | 新增: # Fetched where json.schemastore.org redirects to, stored under the URL | |
| 394 | 新增: # the editor asks for. | |
| 395 | 新增: fetch+=(-o "$dir/$n.json" "${u/#https:\/\/json.schemastore.org\//https://www.schemastore.org/}") | |
| 396 | 新增: done | |
| 397 | 新增: # Each file checked below: one failed download fails curl as a whole. | |
| 398 | 新增: [[ ${#fetch[@]} -eq 0 ]] || curl -fsSL --max-time 30 --parallel --parallel-max 8 "${fetch[@]}" </dev/null || true | |
| 399 | 新增: for i in "${!urls[@]}"; do | |
| 400 | 新增: u="${urls[$i]}" | |
| 401 | 新增: f="$dir/$i.json" | |
| 402 | 新增: if ! jq -c --arg u "$u" '{url: $u, schema: .}' "$f" > "$f.entry" 2>/dev/null; then | |
| 403 | 新增: echo "Warning: could not download the JSON schema $u: files using it are not validated." >&2 | |
| 404 | 新增: continue | |
| 405 | 新增: fi | |
| 406 | 新增: cat "$f.entry" >> "$dir/entries" | |
| 407 | 新增: base="$(jq -r '(."$id" // .id // empty) | strings | select(test("^https?://"))' "$f")" | |
| 408 | 新增: [[ -n "$base" ]] || base="$u" | |
| 409 | 新增: while IFS= read -r r; do | |
| 410 | 新增: r="$(schema_url_resolve "$base" "$r")" && next+=("$r") | |
| 411 | 新增: done < <(jq -r '[.. | objects | ."$ref"? | strings | select(startswith("#") | not)] | unique[]' "$f") | |
| 412 | 新增: done | |
| 413 | 新增: level=(${next[@]+"${next[@]}"}) | |
| 367 | 414 | done |
| 368 | 415 | mkdir -p "$(dirname "$out")" |
| 369 | 416 | jq -sc '{"json.schemas": .}' "$dir/entries" > "$out" |
| @@ -384,12 +431,15 @@ if [[ "$INSTALL_CODE_SERVER" == "1" ]]; then | ||
| 384 | 431 | code-server "${extensions[@]}" </dev/null |
| 385 | 432 | fi |
| 386 | 433 | # chat.disableAIFeatures turns off the GitHub Copilot chat and completions |
| 387 | 删除: # that code-server ships (lib/code.sh also disables the extension). | |
| 388 | 删除: # telemetry.telemetryLevel: code-server's --disable-telemetry leaves the | |
| 389 | 删除: # built-in extensions sending telemetry. The editor downloads no JSON | |
| 390 | 删除: # schema: setup does, once, into the machine settings (code_server_schemas). | |
| 391 | 删除: # The rest is the welcome page, tips, recommendations, experiments and | |
| 392 | 删除: # online settings search. | |
| 434 | 新增: # that code-server ships (lib/code.sh also disables the extension), and | |
| 435 | 新增: # chat.mcp.gallery.enabled its MCP gallery. telemetry.*: code-server's | |
| 436 | 新增: # --disable-telemetry leaves the built-in extensions sending telemetry. The | |
| 437 | 新增: # editor downloads no JSON schema: setup does, once, into the machine | |
| 438 | 新增: # settings (code_server_schemas). remote.autoForwardPorts: Lima forwards | |
| 439 | 新增: # the VM's ports already. update.*: setup installs code-server, the editor | |
| 440 | 新增: # does not update itself. The rest is the look (dark theme, no secondary | |
| 441 | 新增: # side bar), the welcome page, tips, recommendations, experiments, online | |
| 442 | 新增: # settings search, and Claude's onboarding checklist. | |
| 393 | 443 | mkdir -p "$HOME/.local/share/code-server/User" |
| 394 | 444 | jq -n --arg claude "$INSTALL_CODE_CLAUDE" ' |
| 395 | 445 | { |
| @@ -426,11 +476,10 @@ if [[ "$INSTALL_CODE_SERVER" == "1" ]]; then | ||
| 426 | 476 | # do for the CLI. These keys are machine-scoped: code-server ignores them in |
| 427 | 477 | # the user settings. |
| 428 | 478 | if [[ "$INSTALL_CODE_CLAUDE" == "1" ]]; then |
| 429 | 删除: mkdir -p "$(dirname "$cs_machine")" | |
| 430 | 删除: { if [[ -f "$cs_machine" ]]; then cat "$cs_machine"; else echo '{}'; fi; } | jq '. + { | |
| 479 | 新增: jq -c '. + { | |
| 431 | 480 | "claudeCode.allowDangerouslySkipPermissions": true, |
| 432 | 481 | "claudeCode.initialPermissionMode": "bypassPermissions" |
| 433 | 删除: }' > "$cs_machine.tmp" | |
| 482 | 新增: }' "$cs_machine" > "$cs_machine.tmp" | |
| 434 | 483 | mv "$cs_machine.tmp" "$cs_machine" |
| 435 | 484 | fi |
| 436 | 485 | # Codex and Vibe have no setting for it: their extensions start in the mode |
| @@ -32,8 +32,10 @@ AGENT_VM_STATE_DIR="${AGENT_VM_STATE_DIR:-${HOME}/.agent-vm}" | ||
| 32 | 32 | # `install` makes is one. By hand, as macOS's readlink has no -f. `CDPATH=` |
| 33 | 33 | # everywhere a relative path is cd'ed to: with it set, cd searches it first. |
| 34 | 34 | _agent_vm_script_dir() { |
| 35 | 删除: local src="$1" dir | |
| 36 | 删除: while [ -L "$src" ]; do | |
| 35 | 新增: local src="$1" dir n=0 | |
| 36 | 新增: # At most 40 links, as the kernel follows: a loop would never end. | |
| 37 | 新增: while [ -L "$src" ] && [ "$n" -lt 40 ]; do | |
| 38 | 新增: n=$((n + 1)) | |
| 37 | 39 | dir="$(CDPATH= cd -P -- "$(dirname "$src")" >/dev/null && pwd)" |
| 38 | 40 | src="$(readlink "$src")" |
| 39 | 41 | case "$src" in |
| @@ -126,16 +128,17 @@ _agent_vm_start_checks() { | ||
| 126 | 128 | fi |
| 127 | 129 | |
| 128 | 130 | # With it, the names the shares need: those always listed, and one per |
| 129 | 删除: # hooks folder git runs from in the project (see _agent_vm_project_hooks), | |
| 130 | 删除: # its first component. A dot-name (.husky, .githooks) is taken as is; any | |
| 131 | 删除: # other is read-only in every folder of the project, so it is asked first | |
| 131 | 新增: # hooks folder git runs from in a share (see _agent_vm_git_scan), its | |
| 132 | 新增: # first component. A dot-name (.husky, .githooks) is taken as is; any | |
| 133 | 新增: # other is read-only in every folder of every share, so it is asked first | |
| 132 | 134 | # (yes by default, and when no one can answer). A folder that cannot be |
| 133 | 删除: # protected, or one declined, is a risk to accept. So are git config files | |
| 134 | 删除: # in the project, and settings running commands from it. Under --readonly | |
| 135 | 删除: # the VM writes none of them: the names are taken as they come, with no | |
| 136 | 删除: # warning and no question. | |
| 137 | 删除: local hooks_rel hooks_in hooks_name hooks_names=() | |
| 135 | 新增: # protected, or one declined, is a risk to accept. So are the scan's risks: | |
| 136 | 新增: # git config files in a share, settings running commands from one, hooks | |
| 137 | 新增: # linked into one. Under --readonly the VM writes none of them: the names | |
| 138 | 新增: # are taken as they come, with no warning and no question. | |
| 139 | 新增: local hooks_rel hooks_in hooks_name hooks_names=() scan="" | |
| 138 | 140 | if [[ -n "$protect_git" ]]; then |
| 141 | 新增: scan="$(_agent_vm_git_scan "$host_dir")" | |
| 139 | 142 | while IFS=$'\t' read -r hooks_rel hooks_in; do |
| 140 | 143 | [[ -n "$hooks_rel" ]] || continue |
| 141 | 144 | if [[ -n "$rdonly" ]]; then |
| @@ -145,8 +148,10 @@ _agent_vm_start_checks() { | ||
| 145 | 148 | if ! hooks_name="$(_agent_vm_hooks_name "$hooks_in")"; then |
| 146 | 149 | if [[ "$hooks_rel" == . ]]; then |
| 147 | 150 | echo "Warning: git's core.hooksPath is the project directory itself, which the VM can write: git on this machine runs the hooks the agent puts there." >&2 |
| 151 | 新增: elif [[ "$hooks_in" == . ]]; then | |
| 152 | 新增: echo "Warning: git's core.hooksPath is '$hooks_rel', a writable volume itself: git on this machine runs the hooks the agent puts there." >&2 | |
| 148 | 153 | else |
| 149 | 删除: echo "Warning: git's core.hooksPath is '$hooks_rel', in the project, and its name cannot be made read-only: git on this machine runs the hooks the agent puts there." >&2 | |
| 154 | 新增: echo "Warning: git's core.hooksPath is '$hooks_rel', which the VM can write, and its name cannot be made read-only: git on this machine runs the hooks the agent puts there." >&2 | |
| 150 | 155 | fi |
| 151 | 156 | if [[ -z "$vm_up" ]] && ! _agent_vm_confirm_unsafe; then |
| 152 | 157 | echo "Aborted. Point core.hooksPath to a folder of the project (agent-vm keeps it read-only), or outside it." >&2 |
| @@ -166,16 +171,16 @@ _agent_vm_start_checks() { | ||
| 166 | 171 | fi |
| 167 | 172 | hooks_names+=("$hooks_name") |
| 168 | 173 | hooks_notes="$hooks_notes$(_agent_vm_hooks_note "$hooks_rel" "$hooks_name")"$'\n' |
| 169 | 删除: done <<< "$(_agent_vm_share_hooks "$host_dir")" | |
| 174 | 新增: done <<< "$(_agent_vm_scan_part H "$scan")" | |
| 170 | 175 | ro_names="$(_agent_vm_names_json ${hooks_names[@]+"${hooks_names[@]}"})" |
| 171 | 176 | |
| 172 | 177 | local git_risks="" |
| 173 | 删除: [[ -n "$rdonly" ]] || git_risks="$(_agent_vm_share_config_risks "$host_dir")" | |
| 178 | 新增: [[ -n "$rdonly" ]] || git_risks="$(_agent_vm_scan_part R "$scan")" | |
| 174 | 179 | if [[ -n "$git_risks" ]]; then |
| 175 | 180 | echo "Warning: git on this machine uses these, and the VM can write them:" >&2 |
| 176 | 181 | printf '%s\n' "$git_risks" | sed 's/^/ /' >&2 |
| 177 | 182 | if [[ -z "$vm_up" ]] && ! _agent_vm_confirm_unsafe; then |
| 178 | 删除: echo "Aborted. Move them out of the project, or have them name commands outside it." >&2 | |
| 183 | 新增: echo "Aborted. Move them out of the shared folders, or have them name commands outside them." >&2 | |
| 179 | 184 | return 1 |
| 180 | 185 | fi |
| 181 | 186 | fi |
| @@ -221,7 +226,39 @@ _agent_vm_apply_shares() { | ||
| 221 | 226 | echo "$out" >&2 |
| 222 | 227 | return 1 |
| 223 | 228 | fi |
| 224 | 删除: _agent_vm_record_mounts "$vm" "$json" | |
| 229 | 新增: _agent_vm_record_mounts "$vm" "$json" || return 1 | |
| 230 | 新增: _agent_vm_sshfs_cache_mode >| "$AGENT_VM_STATE_DIR/.agent-vm-sshfs-cache-$vm" | |
| 231 | 新增:} | |
| 232 | 新增: | |
| 233 | 新增:# Before the stopped <vm> boots, fails, saying why, unless what Lima's config | |
| 234 | 新增:# gives it is what agent-vm set: for a VM whose .git is protected (the | |
| 235 | 新增:# caller's protect_git and ro_names), every share with the read-only names | |
| 236 | 新增:# (see _agent_vm_live_shares_why); for one that shares nothing (the caller's | |
| 237 | 新增:# scratch, or <none> set), no share at all. Lima merges the mounts of its | |
| 238 | 新增:# _config/default.yaml and override.yaml into every VM, and agent-vm's edit | |
| 239 | 新增:# cannot remove them. | |
| 240 | 新增:_agent_vm_check_before_start() { | |
| 241 | 新增: # shellcheck disable=SC2034 # set by _agent_vm_live_fields, all three | |
| 242 | 新增: local vm="$1" none="${2:-$scratch}" live why cfg live_vmtype live_mtype live_json | |
| 243 | 新增: [[ -n "$protect_git" || -n "$none" ]] || return 0 | |
| 244 | 新增: cfg="$(_agent_vm_lima_home)/_config" | |
| 245 | 新增: if ! live="$(_agent_vm_live_config "$vm")" || ! _agent_vm_live_fields "$live"; then | |
| 246 | 新增: echo "Error: could not read Lima's config for VM '$vm', so what it would boot with is not known." >&2 | |
| 247 | 新增: return 1 | |
| 248 | 新增: fi | |
| 249 | 新增: if [[ -n "$none" ]]; then | |
| 250 | 新增: [[ "$live_json" == null || "$live_json" == "[]" ]] && return 0 | |
| 251 | 新增: echo "Error: Lima gives VM '$vm' shares agent-vm did not ask for, so it would not boot with nothing of yours." >&2 | |
| 252 | 新增: echo " Look for 'mounts' in $cfg/override.yaml and default.yaml, and remove them." >&2 | |
| 253 | 新增: return 1 | |
| 254 | 新增: fi | |
| 255 | 新增: why="$(_agent_vm_live_shares_why "$live" "$ro_names")" && return 0 | |
| 256 | 新增: echo "Error: VM '$vm' would boot with .git writable: $why." >&2 | |
| 257 | 新增: case "$why" in | |
| 258 | 新增: *"mount type"*) echo " Look for 'mountType' in $cfg/override.yaml and default.yaml, and remove it." >&2 ;; | |
| 259 | 新增: *) echo " Look for 'mounts' in $cfg/override.yaml and default.yaml, and remove them." >&2 ;; | |
| 260 | 新增: esac | |
| 261 | 新增: return 1 | |
| 225 | 262 | } |
| 226 | 263 | |
| 227 | 264 | # The caller's memory, cpus, ssh_port and disk, on the stopped <vm>. The disk |
| @@ -247,15 +284,14 @@ _agent_vm_apply_resources() { | ||
| 247 | 284 | # The env push and the write probe (see _agent_vm_push_env_and_probe), with |
| 248 | 285 | # the caller's vm_name, host_dir, env_payload, guest_env, guest_runtime and |
| 249 | 286 | # scratch, into its probe_out and is_writable: true, false, or lost when the |
| 250 | 删除:# share is not mounted. A scratch VM works on its own disk: nothing reaches | |
| 251 | 删除:# this machine there, by design. | |
| 287 | 新增:# share is not mounted. | |
| 252 | 288 | _agent_vm_push_and_probe() { |
| 253 | 289 | local st=0 |
| 254 | 290 | probe_out="$(_agent_vm_push_env_and_probe "$vm_name" "$host_dir" "$env_payload" \ |
| 255 | 291 | "$guest_env" "$guest_runtime")" || st=$? |
| 256 | 292 | case "$st" in |
| 257 | 293 | 0) is_writable="true" ;; |
| 258 | 删除: 2) if [[ -n "$scratch" ]]; then is_writable="true"; else is_writable="lost"; fi ;; | |
| 294 | 新增: 2) is_writable="lost" ;; | |
| 259 | 295 | *) is_writable="false" ;; |
| 260 | 296 | esac |
| 261 | 297 | [[ "$probe_out" == *env-ok* ]] || echo "Warning: failed to push the env files into VM '$vm_name'." >&2 |
| @@ -424,34 +460,32 @@ _agent_vm_ensure_running() { | ||
| 424 | 460 | _agent_vm_running "$vm_name" && was_running=1 |
| 425 | 461 | |
| 426 | 462 | # Shares recorded otherwise than asked: the .git protection (git_stale), its |
| 427 | 删除: # names (names_stale), the mode (mode_stale). A stopped VM is changed before | |
| 428 | 删除: # it boots, so nothing starting with it gets a writable window; a running | |
| 429 | 删除: # one keeps its shares until stopped, or is offered a restart. | |
| 463 | 新增: # names (names_stale), the mode (mode_stale), sshfs's cache (cache_stale). A | |
| 464 | 新增: # stopped VM is changed before it boots, so nothing starting with it gets a | |
| 465 | 新增: # writable window; a running one keeps its shares until stopped, or is | |
| 466 | 新增: # offered a restart (never for the cache alone). | |
| 430 | 467 | local was_protected="" git_stale="" names_stale="" mode_stale="" cache_stale="" |
| 431 | 468 | _agent_vm_mounts_protect_git "$vm_name" && was_protected=1 |
| 432 | 删除: # The record against what Lima has for the VM, for a VM that exists: a | |
| 433 | 删除: # share without names set outside agent-vm makes it unprotected, whatever | |
| 434 | 删除: # was recorded. Which names, the record says (names_stale below). | |
| 435 | 删除: if [[ -n "$protect_git" && -n "$was_protected" && -z "$is_new_vm" ]] \ | |
| 436 | 删除: && ! _agent_vm_live_shares_protected "$vm_name"; then | |
| 437 | 删除: was_protected="" | |
| 438 | 删除: fi | |
| 439 | 删除: # Running, it is served by the limactl that started it, which may not be | |
| 440 | 删除: # the one checked above. | |
| 441 | 删除: if [[ -n "$protect_git" && -n "$was_protected" ]] && _agent_vm_running "$vm_name" \ | |
| 442 | 删除: && ! _agent_vm_hostagent_is_limactl "$vm_name"; then | |
| 443 | 删除: echo "Warning: VM '$vm_name' was started by another limactl than $(command -v limactl), which may not keep .git read-only." >&2 | |
| 444 | 删除: was_protected="" | |
| 469 | 新增: if [[ -n "$protect_git" && -n "$was_protected" ]]; then | |
| 470 | 新增: # The record against what Lima has for an existing VM: a share without | |
| 471 | 新增: # names, set outside agent-vm, leaves it unprotected whatever was | |
| 472 | 新增: # recorded. Which names, the record says (names_stale below). | |
| 473 | 新增: if [[ -z "$is_new_vm" ]] \ | |
| 474 | 新增: && ! _agent_vm_live_shares_why "$(_agent_vm_live_config "$vm_name")" >/dev/null; then | |
| 475 | 新增: was_protected="" | |
| 476 | 新增: # Running, it is served by the limactl that started it, which may not be | |
| 477 | 新增: # the one checked above. | |
| 478 | 新增: elif [[ -n "$was_running" ]] && ! _agent_vm_hostagent_is_limactl "$vm_name"; then | |
| 479 | 新增: echo "Warning: VM '$vm_name' was started by another limactl than $(_agent_vm_limactl_path), which may not keep .git read-only." >&2 | |
| 480 | 新增: was_protected="" | |
| 481 | 新增: fi | |
| 445 | 482 | fi |
| 446 | 483 | [[ "$was_protected" != "$protect_git" ]] && git_stale=1 |
| 447 | 删除: if [[ -n "$protect_git" && -n "$was_protected" ]] \ | |
| 448 | 删除: && ! _agent_vm_mounts_have_readonly_names "$vm_name" "$ro_names"; then | |
| 449 | 删除: names_stale=1 | |
| 450 | 删除: fi | |
| 451 | 删除: # Shares from before sshfs's cache was turned off: set again before it | |
| 452 | 删除: # boots, never a reason to restart it. | |
| 453 | 删除: if [[ -n "$protect_git" && -n "$was_protected" ]] && ! _agent_vm_mounts_cache_off "$vm_name"; then | |
| 454 | 删除: cache_stale=1 | |
| 484 | 新增: if [[ -n "$protect_git" && -n "$was_protected" ]]; then | |
| 485 | 新增: _agent_vm_mounts_have_readonly_names "$vm_name" "$ro_names" || names_stale=1 | |
| 486 | 新增: # Shares made otherwise than _agent_vm_build_mounts_json would now (sshfs's | |
| 487 | 新增: # cache): set again before it boots, never a reason to restart it. | |
| 488 | 新增: _agent_vm_mounts_sshfs_current "$vm_name" || cache_stale=1 | |
| 455 | 489 | fi |
| 456 | 490 | if [[ -n "$scratch" ]]; then |
| 457 | 491 | # Shares nothing, as made: nothing to bring in line. |
| @@ -513,20 +547,13 @@ _agent_vm_ensure_running() { | ||
| 513 | 547 | _agent_vm_apply_shares "$vm_name" "$host_dir" "$want_writable" || return 1 |
| 514 | 548 | fi |
| 515 | 549 | |
| 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 | 删除: | |
| 524 | 550 | if [[ -z "$was_running" ]]; then |
| 551 | 新增: _agent_vm_check_before_start "$vm_name" || return 1 | |
| 525 | 552 | echo "Starting VM '$vm_name'..." |
| 526 | 553 | local start_log |
| 527 | 554 | if ! start_log=$(limactl start "$vm_name" 2>&1); then |
| 528 | 555 | local ha_log |
| 529 | 删除: ha_log="$(_agent_vm_lima_home)/$vm_name/ha.stderr.log" | |
| 556 | 新增: ha_log="$(_agent_vm_ha_log "$vm_name")" | |
| 530 | 557 | echo "Error: Failed to start VM '$vm_name'." >&2 |
| 531 | 558 | echo "--- limactl start output ---" >&2 |
| 532 | 559 | echo "$start_log" >&2 |
| @@ -606,6 +633,7 @@ _agent_vm_ensure_running() { | ||
| 606 | 633 | _agent_vm_migrate_0_1_if_needed "$vm_name" || return 1 |
| 607 | 634 | fi |
| 608 | 635 | _agent_vm_apply_shares "$vm_name" "$host_dir" "$want_writable" || return 1 |
| 636 | 新增: _agent_vm_check_before_start "$vm_name" || return 1 | |
| 609 | 637 | # Checked: the probe below cannot tell a dead VM from a read-only one. |
| 610 | 638 | if ! limactl start "$vm_name" &>/dev/null; then |
| 611 | 639 | echo "Error: VM '$vm_name' did not come back up after changing the project mount." >&2 |
| @@ -618,7 +646,7 @@ _agent_vm_ensure_running() { | ||
| 618 | 646 | if [[ "$is_writable" == lost ]]; then |
| 619 | 647 | echo "Error: the project share did not mount in VM '$vm_name':" >&2 |
| 620 | 648 | echo " $host_dir" >&2 |
| 621 | 删除: echo "Lima's log: $(_agent_vm_lima_home)/$vm_name/ha.stderr.log" >&2 | |
| 649 | 新增: echo "Lima's log: $(_agent_vm_ha_log "$vm_name")" >&2 | |
| 622 | 650 | elif [[ "$want_writable" == "true" ]]; then |
| 623 | 651 | echo "Error: project directory is still not writable inside the VM:" >&2 |
| 624 | 652 | echo " $host_dir" >&2 |
| @@ -637,7 +665,14 @@ _agent_vm_ensure_running() { | ||
| 637 | 665 | if [[ -n "$rdonly" ]]; then |
| 638 | 666 | _agent_vm_mount_is_host_enforced "$vm_name" |
| 639 | 667 | case $? in |
| 640 | 删除: 0) echo "Read-only: the project and every other share (enforced on the host)." ;; | |
| 668 | 新增: 0) | |
| 669 | 新增: # Every share, those Lima's _config adds to every VM included. | |
| 670 | 新增: if [[ "$(_agent_vm_live_config "$vm_name")" == *'"writable":true'* ]]; then | |
| 671 | 新增: echo "Error: --readonly cannot hold: Lima gives VM '$vm_name' a writable share agent-vm did not set." >&2 | |
| 672 | 新增: echo " Look for 'mounts' in $(_agent_vm_lima_home)/_config/override.yaml and default.yaml." >&2 | |
| 673 | 新增: return 1 | |
| 674 | 新增: fi | |
| 675 | 新增: echo "Read-only: the project and every other share (enforced on the host)." ;; | |
| 641 | 676 | 1) echo "Error: --readonly cannot be enforced with this mount type." >&2 |
| 642 | 677 | echo " Lima only applies it inside the guest for reverse-sshfs (without" >&2 |
| 643 | 678 | echo " readonlyNames) and for virtiofs under QEMU, where root in the VM" >&2 |
| @@ -858,7 +893,8 @@ agent-vm() { | ||
| 858 | 893 | # VAR=value assignments working. `env --`: GNU env still reads assignments |
| 859 | 894 | # after it, and a command starting with `-` (`run -i foo`) is not taken for |
| 860 | 895 | # one of its options. A command that is not there is said so, with env's |
| 861 | 删除:# status: an agent installed only as an editor extension has no command. | |
| 896 | 新增:# status: an agent installed only as an editor extension has no command. A | |
| 897 | 新增:# path is env's to run: it says why it cannot (a script without +x, 126). | |
| 862 | 898 | # |
| 863 | 899 | # Usage: _agent_vm_lima_run <vm_name> <host_dir> <tty:1|""> <command> [args...] |
| 864 | 900 | _agent_vm_lima_run() { |
| @@ -867,7 +903,7 @@ _agent_vm_lima_run() { | ||
| 867 | 903 | local shell_opts=(--workdir "$host_dir") |
| 868 | 904 | [[ -n "$want_tty" ]] && shell_opts+=(--tty) |
| 869 | 905 | limactl shell "${shell_opts[@]}" "$vm_name" -- zsh -l -c \ |
| 870 | 删除: 'case "$1" in *=*) ;; *) command -v -- "$1" >/dev/null || { print -r -- "agent-vm: $1 is not installed in this VM." >&2; exit 127; } ;; esac; exec env -- "$@"' \ | |
| 906 | 新增: 'case "$1" in *=*|*/*) ;; *) command -v -- "$1" >/dev/null || { print -r -- "agent-vm: $1 is not installed in this VM." >&2; exit 127; } ;; esac; exec env -- "$@"' \ | |
| 871 | 907 | agent-vm "$@" |
| 872 | 908 | } |
| 873 | 909 | |
| @@ -3,7 +3,8 @@ | ||
| 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 |
| 5 | 5 | # password, the port of an editor of this VM already running, and which |
| 6 | 删除:# candidates something in the VM listens on. | |
| 6 | 新增:# candidates something in the VM listens on, whatever it speaks (ss; without | |
| 7 | 新增:# it, curl, any answer but a refused connection, the VM's proxy bypassed). | |
| 7 | 8 | # |
| 8 | 9 | # The password is made here, in the VM, on first use, never in the base: |
| 9 | 10 | # every VM is a copy of the base disk, and one VM knowing another's password |
| @@ -23,19 +24,30 @@ echo "config=$cfg" | ||
| 23 | 24 | echo "password=$(sed -n "s/^password: //p" "$cfg")" |
| 24 | 25 | pgrep -u "$(id -u)" -af -- "--config $cfg" \ |
| 25 | 26 | | sed -n "s/.*--bind-addr 127\.0\.0\.1:\([0-9]*\).*/running=\1/p" | head -n 1 |
| 26 | 删除:for p in "$@"; do | |
| 27 | 删除: curl -s -o /dev/null --max-time 1 "http://127.0.0.1:$p/" && echo "listening=$p" | |
| 28 | 删除:done | |
| 27 | 新增:if command -v ss >/dev/null 2>&1; then | |
| 28 | 新增: open=" $(ss -Hltn 2>/dev/null | awk "{ n = split(\$4, a, \":\"); printf \"%s \", a[n] }")" | |
| 29 | 新增: for p in "$@"; do | |
| 30 | 新增: case "$open" in *" $p "*) echo "listening=$p" ;; esac | |
| 31 | 新增: done | |
| 32 | 新增:else | |
| 33 | 新增: for p in "$@"; do | |
| 34 | 新增: curl -s -o /dev/null --noproxy "*" --max-time 1 "http://127.0.0.1:$p/" | |
| 35 | 新增: [ $? -eq 7 ] || echo "listening=$p" | |
| 36 | 新增: done | |
| 37 | 新增:fi | |
| 29 | 38 | exit 0 |
| 30 | 39 | ' |
| 31 | 40 | |
| 32 | 删除:# Ten host ports for <vm>'s editor, from its name: the same on every start, | |
| 33 | 删除:# so the browser finds the saved password at the same address. | |
| 41 | 新增:# Ten host ports for <vm>'s editor, from 20000 to 29999, from its name: the | |
| 42 | 新增:# same on every start, so the browser finds the saved password at the same | |
| 43 | 新增:# address while the first is free. VM names end with a hash (see | |
| 44 | 新增:# _agent_vm_name): its last four digits start the ten, anywhere in the range, | |
| 45 | 新增:# so two VMs rarely start at the same port. | |
| 34 | 46 | _agent_vm_code_ports() { |
| 35 | 删除: local h base i | |
| 36 | 删除: h="$(printf '%s' "$1" | _agent_vm_sha256 | cut -c1-4)" | |
| 47 | 新增: local h="${1: -4}" base i | |
| 48 | 新增: [[ "$h" =~ ^[0-9a-f]{4}$ ]] || h="$(printf '%s' "$1" | _agent_vm_sha256 | cut -c1-4)" | |
| 37 | 49 | [[ "$h" =~ ^[0-9a-f]{4}$ ]] || return 1 |
| 38 | 删除: base=$((20000 + (16#$h % 1000) * 10)) | |
| 50 | 新增: base=$((20000 + 16#$h % 9991)) | |
| 39 | 51 | for i in 0 1 2 3 4 5 6 7 8 9; do printf '%s ' $((base + i)); done |
| 40 | 52 | } |
| 41 | 53 | |
| @@ -58,12 +70,12 @@ _agent_vm_host_port_open() { | ||
| 58 | 70 | (exec 3<>"/dev/tcp/127.0.0.1/$1") 2>/dev/null |
| 59 | 71 | } |
| 60 | 72 | |
| 61 | 删除:# The editor's <url> on <port>, its <password>, and a last line <note>, in a | |
| 62 | 删除:# box. Safari leaves *.localhost to macOS, which may not resolve it: | |
| 63 | 删除:# 127.0.0.1 then, in a window of its own. | |
| 73 | 新增:# The address of <vm>'s editor on <port>, its <password>, and a last line | |
| 74 | 新增:# <note>, in a box. Safari leaves *.localhost to macOS, which may not resolve | |
| 75 | 新增:# it: 127.0.0.1 then, in a window of its own. | |
| 64 | 76 | _agent_vm_code_say() { |
| 65 | 77 | { |
| 66 | 删除: echo " Address: $1" | |
| 78 | 新增: echo " Address: http://$(_agent_vm_code_host "$1"):$2/" | |
| 67 | 79 | echo " Password: $3" |
| 68 | 80 | if [[ "$(uname -s)" == Darwin ]]; then |
| 69 | 81 | echo "" |
| @@ -87,8 +99,7 @@ _agent_vm_code() { | ||
| 87 | 99 | } |
| 88 | 100 | |
| 89 | 101 | _agent_vm_code_session() { |
| 90 | 删除: local vm_name="$1" host_dir="$2" ports out line cfg="" pw="" running="" listening=" " port="" p | |
| 91 | 删除: local url want_tty="" st=0 | |
| 102 | 新增: local vm_name="$1" host_dir="$2" ports out line cfg="" pw="" running="" port="" p want_tty="" | |
| 92 | 103 | ports="$(_agent_vm_code_ports "$vm_name")" || { |
| 93 | 104 | echo "Error: cannot hash the VM name: install shasum or sha256sum." >&2 |
| 94 | 105 | return 1 |
| @@ -108,7 +119,6 @@ _agent_vm_code_session() { | ||
| 108 | 119 | config=*) cfg="${line#config=}" ;; |
| 109 | 120 | password=*) pw="${line#password=}" ;; |
| 110 | 121 | running=*) running="${line#running=}" ;; |
| 111 | 删除: listening=*) listening="$listening${line#listening=} " ;; | |
| 112 | 122 | esac |
| 113 | 123 | done <<< "$out" |
| 114 | 124 | # Printed to the terminal: nothing the VM wrote may carry escape sequences. |
| @@ -118,15 +128,14 @@ _agent_vm_code_session() { | ||
| 118 | 128 | fi |
| 119 | 129 | |
| 120 | 130 | if [[ -n "$running" ]]; then |
| 121 | 删除: url="http://$(_agent_vm_code_host "$vm_name"):$running/" | |
| 122 | 删除: _agent_vm_code_say "$url" "$running" "$pw" "The editor of VM '$vm_name' already runs, from another terminal." | |
| 131 | 新增: _agent_vm_code_say "$vm_name" "$running" "$pw" "The editor of VM '$vm_name' already runs, from another terminal." | |
| 123 | 132 | return 0 |
| 124 | 133 | fi |
| 125 | 134 | |
| 126 | 135 | # The first port free both here and in the VM: Lima forwards the VM's port |
| 127 | 136 | # to the same one here, and only when nothing holds it. |
| 128 | 137 | for p in $ports; do |
| 129 | 删除: [[ "$listening" == *" $p "* ]] && continue | |
| 138 | 新增: _agent_vm_has_line "$out" "listening=$p" && continue | |
| 130 | 139 | _agent_vm_host_port_open "$p" && continue |
| 131 | 140 | port="$p" |
| 132 | 141 | break |
| @@ -136,23 +145,22 @@ _agent_vm_code_session() { | ||
| 136 | 145 | return 1 |
| 137 | 146 | fi |
| 138 | 147 | |
| 139 | 删除: url="http://$(_agent_vm_code_host "$vm_name"):$port/" | |
| 140 | 删除: _agent_vm_code_say "$url" "$port" "$pw" "The password is kept in the VM, in $cfg. Ctrl-C stops the editor." | |
| 148 | 新增: _agent_vm_code_say "$vm_name" "$port" "$pw" "The password is kept in the VM, in $cfg. Ctrl-C stops the editor." | |
| 141 | 149 | # A terminal for Ctrl-C to reach code-server: without one, it would keep |
| 142 | 150 | # running in the VM once this command ends. |
| 143 | 151 | [[ -t 0 && -t 1 ]] && want_tty=1 |
| 144 | 152 | # Bound to the VM's loopback, which Lima forwards to this machine's only. |
| 145 | 删除: # The cookie suffix keeps sessions apart at 127.0.0.1, where two editors | |
| 146 | 删除: # would overwrite each other's cookie. --disable-proxy: no route from the | |
| 147 | 删除: # browser to the VM's other ports, and the proxy is where CVE-2025-47269 was. | |
| 148 | 删除: # The --vscode-option ones reach the VS Code server inside: no experiments, | |
| 149 | 删除: # and the built-in Copilot Chat never loads (it updates itself otherwise). | |
| 150 | 删除: # The settings written at setup do the rest (agent-vm.setup.sh). | |
| 151 | 删除: # Claude Code's login pages open without the link protection prompt: | |
| 152 | 删除: # these paths only, matched by segment (code-server 4.100+). | |
| 153 | 删除: # VSCODE_PROXY_URI: links to localhost:<port> (or 127.0.0.1, 0.0.0.0) open | |
| 154 | 删除: # at localhost:<port> here, where Lima forwards the VM's ports, instead of | |
| 155 | 删除: # code-server's /proxy/<port>/, which --disable-proxy turns off. | |
| 153 | 新增: # The cookie suffix keeps sessions apart at 127.0.0.1. --disable-proxy: no | |
| 154 | 新增: # route from the browser to the VM's other ports; VSCODE_PROXY_URI sends a | |
| 155 | 新增: # link to localhost:<port> to that port here instead. The --vscode-option | |
| 156 | 新增: # ones: no experiments, and the built-in Copilot Chat never loads. Claude | |
| 157 | 新增: # Code's login pages open without the link prompt, those paths only. | |
| 158 | 新增: # | |
| 159 | 新增: # Not a boundary between VMs: any VM can listen on a port Lima forwards to | |
| 160 | 新增: # this machine, and a page it serves can send the browser, with this | |
| 161 | 新增: # editor's cookie, to a host name it chose. Every VM can reach every | |
| 162 | 新增: # other's editor; keeping them apart needs network isolation, which | |
| 163 | 新增: # agent-vm does not have yet. | |
| 156 | 164 | _agent_vm_lima_run "$vm_name" "$host_dir" "$want_tty" \ |
| 157 | 165 | 'VSCODE_PROXY_URI=http://localhost:{{port}}/' code-server \ |
| 158 | 166 | --config "$cfg" \ |
| @@ -168,6 +176,5 @@ _agent_vm_code_session() { | ||
| 168 | 176 | --link-protection-trusted-domains https://platform.claude.com/oauth \ |
| 169 | 177 | --vscode-option disable-experiments \ |
| 170 | 178 | --vscode-option disable-extension=GitHub.copilot-chat \ |
| 171 | 删除: "$host_dir" || st=$? | |
| 172 | 删除: return "$st" | |
| 179 | 新增: "$host_dir" | |
| 173 | 180 | } |
| @@ -229,9 +229,10 @@ _agent_vm_doctor() { | ||
| 229 | 229 | done |
| 230 | 230 | |
| 231 | 231 | echo "" |
| 232 | 删除: local host_dir vm_name vm_exists="" ro_names="" | |
| 232 | 新增: local host_dir vm_name vm_exists="" ro_names="" scan | |
| 233 | 233 | host_dir="$(pwd)" |
| 234 | 删除: [[ -n "$protects_git" ]] && ro_names="$(_agent_vm_readonly_names "$host_dir")" | |
| 234 | 新增: scan="$(_agent_vm_git_scan "$host_dir")" | |
| 235 | 新增: [[ -n "$protects_git" ]] && ro_names="$(_agent_vm_readonly_names "$host_dir" "$scan")" | |
| 235 | 236 | echo "This directory ($host_dir)" |
| 236 | 237 | local bad |
| 237 | 238 | if bad="$(_agent_vm_unmountable_path "$host_dir")"; then |
| @@ -270,7 +271,14 @@ _agent_vm_doctor() { | ||
| 270 | 271 | fi |
| 271 | 272 | # What the VM was given, which may predate the Lima installed now: |
| 272 | 273 | # the next start brings it in line (see _agent_vm_ensure_running). |
| 273 | 删除: if [[ -n "$protects_git" ]] && _agent_vm_mounts_protect_git "$vm_name" \ | |
| 274 | 新增: local prot_why="" | |
| 275 | 新增: if _agent_vm_mounts_protect_git "$vm_name"; then | |
| 276 | 新增: prot_why="$(_agent_vm_protection_why "$vm_name")" && prot_why="" | |
| 277 | 新增: fi | |
| 278 | 新增: if [[ -n "$prot_why" ]]; then | |
| 279 | 新增: $d warn "its shares were given the read-only names, but .git is not read-only: $prot_why" \ | |
| 280 | 新增: "'agent-vm stop', then the next start says what to change." | |
| 281 | 新增: elif [[ -n "$protects_git" ]] && _agent_vm_mounts_protect_git "$vm_name" \ | |
| 274 | 282 | && ! _agent_vm_mounts_have_readonly_names "$vm_name" "$ro_names"; then |
| 275 | 283 | $d warn "its shares keep .git read-only, but not all of $(_agent_vm_names_text "$ro_names")" \ |
| 276 | 284 | "The next start (after 'agent-vm stop' if it runs) fixes that." |
| @@ -288,15 +296,17 @@ _agent_vm_doctor() { | ||
| 288 | 296 | fi |
| 289 | 297 | fi |
| 290 | 298 | # Hooks folders the VM can write, and git on this machine runs (see |
| 291 | 删除: # _agent_vm_project_hooks), in this project and the repositories below it. | |
| 299 | 新增: # _agent_vm_git_scan), in this project, its writable volumes, and the | |
| 300 | 新增: # repositories in them. | |
| 292 | 301 | local hooks_rel hooks_in hooks_name hooks_what |
| 293 | 302 | while IFS=$'\t' read -r hooks_rel hooks_in; do |
| 294 | 303 | [[ -n "$hooks_rel" ]] || continue |
| 295 | 304 | hooks_what="git runs hooks from $hooks_rel (core.hooksPath)" |
| 296 | 305 | [[ "$hooks_rel" == . ]] && hooks_what="git runs hooks from the project directory itself (core.hooksPath)" |
| 306 | 新增: [[ "$hooks_rel" != . && "$hooks_in" == . ]] && hooks_what="git runs hooks from $hooks_rel, a writable volume itself (core.hooksPath)" | |
| 297 | 307 | if ! hooks_name="$(_agent_vm_hooks_name "$hooks_in")"; then |
| 298 | 308 | $d warn "$hooks_what, which the VM can write" \ |
| 299 | 删除: "agent-vm can only keep a folder of the project read-only, by a name without quotes or backslashes: point core.hooksPath to one." | |
| 309 | 新增: "agent-vm can only keep a folder inside a share read-only, by a name without quotes or backslashes: point core.hooksPath to one." | |
| 300 | 310 | elif [[ -z "$protects_git" ]]; then |
| 301 | 311 | $d warn "$hooks_what, which the VM can write" \ |
| 302 | 312 | "agent-vm keeps it read-only when it keeps .git read-only (see above)." |
| @@ -308,15 +318,14 @@ _agent_vm_doctor() { | ||
| 308 | 318 | $d warn "$hooks_what, which the VM can still write" \ |
| 309 | 319 | "The next start (after 'agent-vm stop' if it runs) makes every '$hooks_name' in the project read-only." |
| 310 | 320 | fi |
| 311 | 删除: done <<< "$(_agent_vm_share_hooks "$host_dir")" | |
| 312 | 删除: # Git config the VM can write, or commands it names in the project (see | |
| 313 | 删除: # _agent_vm_repo_config_risks). | |
| 321 | 新增: done <<< "$(_agent_vm_scan_part H "$scan")" | |
| 322 | 新增: # Git config, commands and hooks the VM can write (see _agent_vm_git_scan). | |
| 314 | 323 | local git_risks |
| 315 | 删除: git_risks="$(_agent_vm_share_config_risks "$host_dir")" | |
| 324 | 新增: git_risks="$(_agent_vm_scan_part R "$scan")" | |
| 316 | 325 | if [[ -n "$git_risks" ]]; then |
| 317 | 326 | $d warn "git on this machine uses these, and the VM can write them:" |
| 318 | 327 | printf '%s\n' "$git_risks" | sed 's/^/ /' |
| 319 | 删除: printf ' %s\n' "Move them out of the project, or have them name commands outside it." | |
| 328 | 新增: printf ' %s\n' "Move them out of the shared folders, or have them name commands outside them." | |
| 320 | 329 | fi |
| 321 | 330 | local runtime runtime_text runtime_rel project_env |
| 322 | 331 | runtime="$(_agent_vm_project_runtime_path "$host_dir")" |
| @@ -68,25 +68,36 @@ _agent_vm_mounts_expr() { | ||
| 68 | 68 | # The names readonlyNames always lists, one per line. .hg: Mercurial runs the |
| 69 | 69 | # hooks of .hg/hgrc in a repository the user owns, which files written through |
| 70 | 70 | # a share are. |
| 71 | 新增:_AGENT_VM_BASE_NAMES=$'.git\n.hg' | |
| 71 | 72 | _agent_vm_base_readonly_names() { |
| 72 | 删除: printf '%s\n' .git .hg | |
| 73 | 新增: printf '%s\n' "$_AGENT_VM_BASE_NAMES" | |
| 73 | 74 | } |
| 74 | 75 | |
| 75 | 删除:# 0 when the relative path <rel> goes through one of the names above, matched | |
| 76 | 删除:# as the SFTP server does: per component, whatever the case. | |
| 76 | 新增:# 0 when the relative path <rel> goes through one of <names> (one per line; | |
| 77 | 新增:# the names above by default), matched as the SFTP server does: per | |
| 78 | 新增:# component, whatever the case. | |
| 77 | 79 | _agent_vm_under_readonly_name() { |
| 78 | 删除: local rest="$1/" c names | |
| 79 | 删除: names=$'\n'"$(_agent_vm_base_readonly_names)"$'\n' | |
| 80 | 新增: local rest="$1/" names=$'\n'"${2:-$_AGENT_VM_BASE_NAMES}"$'\n' c st=1 set_nocase="" | |
| 81 | 新增: shopt -q nocasematch || { shopt -s nocasematch; set_nocase=1; } | |
| 80 | 82 | while [[ -n "$rest" ]]; do |
| 81 | 删除: c="$(printf '%s' "${rest%%/*}" | tr '[:upper:]' '[:lower:]')" | |
| 83 | 新增: c="${rest%%/*}" | |
| 82 | 84 | rest="${rest#*/}" |
| 83 | 删除: [[ "$names" == *$'\n'"$c"$'\n'* ]] && return 0 | |
| 85 | 新增: if [[ -n "$c" && "$names" == *$'\n'"$c"$'\n'* ]]; then | |
| 86 | 新增: st=0 | |
| 87 | 新增: break | |
| 88 | 新增: fi | |
| 84 | 89 | done |
| 85 | 删除: return 1 | |
| 90 | 新增: [[ -z "$set_nocase" ]] || shopt -u nocasematch | |
| 91 | 新增: return "$st" | |
| 86 | 92 | } |
| 87 | 93 | |
| 88 | 94 | # 0 on the hosts whose file systems ignore case by default: macOS, Windows. |
| 95 | 新增:# A caller asking many times sets _agent_vm_nocase_memo to 1 or 0 first. | |
| 89 | 96 | _agent_vm_fs_nocase() { |
| 97 | 新增: case "${_agent_vm_nocase_memo:-}" in | |
| 98 | 新增: 1) return 0 ;; | |
| 99 | 新增: 0) return 1 ;; | |
| 100 | 新增: esac | |
| 90 | 101 | [[ "$(uname -s 2>/dev/null)" == Darwin ]] || _agent_vm_on_windows |
| 91 | 102 | } |
| 92 | 103 | |
| @@ -104,15 +115,20 @@ _agent_vm_fold() { | ||
| 104 | 115 | # Compared whatever the case where the file system ignores it, so a path |
| 105 | 116 | # spelled with other capitals is still found inside. |
| 106 | 117 | _agent_vm_rel_in() { |
| 107 | 删除: local target="${1%/}" dir="${2%/}" p d | |
| 108 | 删除: p="$(_agent_vm_fold "$target")" | |
| 109 | 删除: d="$(_agent_vm_fold "$dir")" | |
| 110 | 删除: if [[ "$p" == "$d" ]]; then | |
| 118 | 新增: local target="${1%/}" dir="${2%/}" st=1 set_nocase="" | |
| 119 | 新增: if _agent_vm_fs_nocase && ! shopt -q nocasematch; then | |
| 120 | 新增: shopt -s nocasematch | |
| 121 | 新增: set_nocase=1 | |
| 122 | 新增: fi | |
| 123 | 新增: if [[ "$target" == "$dir" ]]; then | |
| 111 | 124 | printf '.\n' |
| 112 | 删除: return 0 | |
| 125 | 新增: st=0 | |
| 126 | 新增: elif [[ -n "$dir" && "$target" == "$dir/"* ]]; then | |
| 127 | 新增: printf '%s\n' "${target:$(( ${#dir} + 1 ))}" | |
| 128 | 新增: st=0 | |
| 113 | 129 | fi |
| 114 | 删除: [[ -n "$d" && "$p" == "$d/"* ]] || return 1 | |
| 115 | 删除: printf '%s\n' "${target:$(( ${#dir} + 1 ))}" | |
| 130 | 新增: [[ -z "$set_nocase" ]] || shopt -u nocasematch | |
| 131 | 新增: return "$st" | |
| 116 | 132 | } |
| 117 | 133 | |
| 118 | 134 | # <dir> as git spells it: the physical path, C:/... on Windows. |
| @@ -132,103 +148,331 @@ _agent_vm_git_abs() { | ||
| 132 | 148 | esac |
| 133 | 149 | } |
| 134 | 150 | |
| 135 | 删除:# The git repositories git on this machine uses in the project <dir>: the one | |
| 136 | 删除:# holding <dir>, then those up to two levels below it (node_modules skipped), | |
| 137 | 删除:# fifty at most. One directory per line, to run git in. | |
| 138 | 删除:_agent_vm_project_repos() { | |
| 139 | 删除: local dir="$1" | |
| 140 | 删除: command -v git >/dev/null 2>&1 || return 0 | |
| 141 | 删除: _agent_vm_git_untrusted -C "$dir" rev-parse --git-dir >/dev/null 2>&1 && printf '%s\n' "$dir" | |
| 142 | 删除: find "$dir" -mindepth 2 -maxdepth 3 \( -name node_modules -prune \) -o \( -name .git -print -prune \) 2>/dev/null \ | |
| 143 | 删除: | awk 'NR <= 50' | while IFS= read -r g; do | |
| 144 | 删除: printf '%s\n' "${g%/.git}" | |
| 145 | 删除: done | |
| 151 | 新增:# --- what git on this machine runs from the shares ----------------------------- | |
| 152 | 新增:# The VM can write the project and the writable volumes. git on this machine | |
| 153 | 新增:# runs hooks, and commands its config names, from paths anywhere: in the | |
| 154 | 新增:# repository's own share, in another share (core.hooksPath into a volume), or | |
| 155 | 新增:# from git's own config kept in one. Each path is followed through every | |
| 156 | 新增:# symlink on the way, and checked against every share. | |
| 157 | 新增: | |
| 158 | 新增:# The folders the VM can write, one per line, in git's spelling (symlinks | |
| 159 | 新增:# resolved): the project <dir> first, then its writable volumes (see | |
| 160 | 新增:# _agent_vm_rw_volume_dirs), each once. | |
| 161 | 新增:_agent_vm_writable_shares() { | |
| 162 | 新增: local d | |
| 163 | 新增: { printf '%s\n' "$1"; _agent_vm_rw_volume_dirs "$1"; } | while IFS= read -r d; do | |
| 164 | 新增: [[ -z "$d" ]] || _agent_vm_git_spelling "$d" | |
| 165 | 新增: done | awk '!seen[$0]++' | |
| 146 | 166 | } |
| 147 | 167 | |
| 148 | 删除:# The folder git on the host runs the hooks of the repository at <repo> from, | |
| 149 | 删除:# when core.hooksPath puts it in the project <proj> (in git's spelling) and | |
| 150 | 删除:# outside the names above (husky sets .husky/_). Two fields, tab-separated: | |
| 151 | 删除:# the folder relative to the project, "." for the project itself, then | |
| 152 | 删除:# relative to the top of the repository when that is in the project (what | |
| 153 | 删除:# names it: lib/x/.githooks is .githooks), or the same again. Fails otherwise, | |
| 154 | 删除:# or when git cannot tell. `--git-path` without --path-format (git 2.31) | |
| 155 | 删除:# answers relative to <repo>. | |
| 156 | 删除:# | |
| 157 | 删除:# The folder as named, and as it is on disk when a symlink takes it elsewhere | |
| 158 | 删除:# (.git/hooks or a core.hooksPath linked to scripts/hooks): git runs what is | |
| 159 | 删除:# in the folder the link points to. A line for each that needs a name. | |
| 160 | 删除:_agent_vm_repo_hooks() { | |
| 161 | 删除: local repo="$1" proj="$2" base top top_rel hooks phys h rel in_repo found="" | |
| 162 | 删除: base="$(_agent_vm_git_spelling "$repo")" || return 1 | |
| 163 | 删除: hooks="$(_agent_vm_repo_hooks_dir "$repo")" || return 1 | |
| 164 | 删除: phys="$(_agent_vm_git_spelling "$hooks" 2>/dev/null)" || phys="" | |
| 165 | 删除: [[ "$phys" != "$hooks" ]] || phys="" | |
| 166 | 删除: top="$(_agent_vm_git_untrusted -C "$repo" rev-parse --show-toplevel 2>/dev/null)" || top="" | |
| 167 | 删除: for h in "$hooks" ${phys:+"$phys"}; do | |
| 168 | 删除: rel="$(_agent_vm_rel_in "$h" "$proj")" || continue | |
| 169 | 删除: [[ "$rel" == . ]] || ! _agent_vm_under_readonly_name "$rel" || continue | |
| 170 | 删除: in_repo="$rel" | |
| 171 | 删除: if [[ -n "$top" ]] && top_rel="$(_agent_vm_rel_in "$top" "$proj")" && [[ "$top_rel" != . ]]; then | |
| 172 | 删除: in_repo="$(_agent_vm_rel_in "$h" "$top")" || in_repo="$rel" | |
| 168 | 新增:# Sets the caller's hit_share and hit_rel to the deepest of the caller's | |
| 169 | 新增:# shares (one per line, in git's spelling) holding <path>, and <path> | |
| 170 | 新增:# relative to it ("." for the share itself). Fails when none does. No | |
| 171 | 新增:# subshell: it runs for every path a scan looks at. | |
| 172 | 新增:_agent_vm_in_share() { | |
| 173 | 新增: local t="${1%/}" s d r set_nocase="" | |
| 174 | 新增: hit_share="" hit_rel="" | |
| 175 | 新增: if _agent_vm_fs_nocase && ! shopt -q nocasematch; then | |
| 176 | 新增: shopt -s nocasematch | |
| 177 | 新增: set_nocase=1 | |
| 178 | 新增: fi | |
| 179 | 新增: while IFS= read -r s; do | |
| 180 | 新增: d="${s%/}" | |
| 181 | 新增: [[ -n "$d" ]] || continue | |
| 182 | 新增: if [[ "$t" == "$d" ]]; then | |
| 183 | 新增: r=. | |
| 184 | 新增: elif [[ "$t" == "$d/"* ]]; then | |
| 185 | 新增: r="${t:$(( ${#d} + 1 ))}" | |
| 186 | 新增: else | |
| 187 | 新增: continue | |
| 173 | 188 | fi |
| 174 | 删除: printf '%s\t%s\n' "$rel" "$in_repo" | |
| 175 | 删除: found=1 | |
| 189 | 新增: if [[ ${#d} -gt ${#hit_share} ]]; then | |
| 190 | 新增: hit_share="$d" | |
| 191 | 新增: hit_rel="$r" | |
| 192 | 新增: fi | |
| 193 | 新增: done <<< "$shares" | |
| 194 | 新增: [[ -z "$set_nocase" ]] || shopt -u nocasematch | |
| 195 | 新增: [[ -n "$hit_share" ]] | |
| 196 | 新增:} | |
| 197 | 新增: | |
| 198 | 新增:# Every path the file system goes through to reach <path> (absolute, in | |
| 199 | 新增:# git's spelling), one per line: <path>, the same with its folder's symlinks | |
| 200 | 新增:# resolved, then the same again for the target of each symlink on the way, | |
| 201 | 新增:# up to 40 links, whether the last one exists or not. A VM able to write any | |
| 202 | 新增:# of them chooses what is found there. | |
| 203 | 新增:_agent_vm_path_hops() { | |
| 204 | 新增: local p="$1" d n=0 t | |
| 205 | 新增: while :; do | |
| 206 | 新增: printf '%s\n' "$p" | |
| 207 | 新增: d="${p%/*}" | |
| 208 | 新增: if d="$(_agent_vm_git_spelling "${d:-/}" 2>/dev/null)"; then | |
| 209 | 新增: d="${d%/}/${p##*/}" | |
| 210 | 新增: if [[ "$d" != "$p" ]]; then | |
| 211 | 新增: p="$d" | |
| 212 | 新增: printf '%s\n' "$p" | |
| 213 | 新增: fi | |
| 214 | 新增: fi | |
| 215 | 新增: [[ -L "$p" ]] || return 0 | |
| 216 | 新增: n=$((n + 1)) | |
| 217 | 新增: [[ "$n" -le 40 ]] || return 0 | |
| 218 | 新增: t="$(readlink "$p")" || return 0 | |
| 219 | 新增: [[ "$t" != /* ]] || t="$(_agent_vm_host_path "$t")" | |
| 220 | 新增: p="$(_agent_vm_git_abs "$t" "${p%/*}")" | |
| 176 | 221 | done |
| 177 | 删除: [[ -n "$found" ]] | |
| 178 | 222 | } |
| 179 | 223 | |
| 180 | 删除:# The hooks folder of the repository at <repo>, absolute, in git's spelling, | |
| 181 | 删除:# as git names it (symlinks not resolved). Fails when git cannot tell. | |
| 182 | 删除:_agent_vm_repo_hooks_dir() { | |
| 183 | 删除: local base hooks | |
| 184 | 删除: base="$(_agent_vm_git_spelling "$1")" || return 1 | |
| 185 | 删除: hooks="$(_agent_vm_git_untrusted -C "$1" rev-parse --git-path hooks 2>/dev/null)" || return 1 | |
| 186 | 删除: [[ -n "$hooks" && "$hooks" != *$'\n'* && "$hooks" != *$'\t'* ]] || return 1 | |
| 187 | 删除: _agent_vm_git_abs "$hooks" "$base" | |
| 224 | 新增:# git, for the repository <at> of kind <kind>: W a work tree, B a bare | |
| 225 | 新增:# repository (named explicitly, as safe.bareRepository=explicit allows), G | |
| 226 | 新增:# none, for git's own global and system config. | |
| 227 | 新增:_agent_vm_git_at() { | |
| 228 | 新增: local kind="$1" at="$2" | |
| 229 | 新增: shift 2 | |
| 230 | 新增: case "$kind" in | |
| 231 | 新增: W) _agent_vm_git_untrusted -C "$at" "$@" ;; | |
| 232 | 新增: B) _agent_vm_git_untrusted --git-dir="$at" "$@" ;; | |
| 233 | 新增: *) _agent_vm_git_untrusted -C / "$@" ;; | |
| 234 | 新增: esac | |
| 188 | 235 | } |
| 189 | 236 | |
| 190 | 删除:# <file> with every symlink resolved, the last component included, in git's | |
| 191 | 删除:# spelling. Fails when it does not resolve (a dangling link, a loop). | |
| 192 | 删除:_agent_vm_physical_file() { | |
| 193 | 删除: local f="$1" t n=0 d | |
| 194 | 删除: while [[ -L "$f" ]]; do | |
| 237 | 新增:# The repositories git on this machine finds in the share <dir> (git's | |
| 238 | 新增:# spelling), one per line, the kind before a tab (see _agent_vm_git_at): the | |
| 239 | 新增:# one holding <dir>, then work trees and bare repositories up to two levels | |
| 240 | 新增:# below it (node_modules skipped), 50 at most. X and <dir> when there are | |
| 241 | 新增:# more: those are not checked. | |
| 242 | 新增:_agent_vm_share_repos() { | |
| 243 | 新增: local dir="$1" g n=0 | |
| 244 | 新增: _agent_vm_git_untrusted -C "$dir" rev-parse --git-dir >/dev/null 2>&1 && printf 'W\t%s\n' "$dir" | |
| 245 | 新增: while IFS= read -r g; do | |
| 246 | 新增: case "$g" in | |
| 247 | 新增: */.git) g="${g%/.git}" ;; | |
| 248 | 新增: */objects) | |
| 249 | 新增: g="${g%/objects}" | |
| 250 | 新增: [[ -f "$g/HEAD" && -d "$g/refs" ]] || continue ;; | |
| 251 | 新增: *) continue ;; | |
| 252 | 新增: esac | |
| 195 | 253 | n=$((n + 1)) |
| 196 | 删除: [[ "$n" -le 40 ]] || return 1 | |
| 197 | 删除: t="$(readlink "$f")" || return 1 | |
| 198 | 删除: case "$t" in | |
| 199 | 删除: /*) f="$t" ;; | |
| 200 | 删除: *) f="$(dirname "$f")/$t" ;; | |
| 254 | 新增: if [[ "$n" -gt 50 ]]; then | |
| 255 | 新增: printf 'X\t%s\n' "$dir" | |
| 256 | 新增: break | |
| 257 | 新增: fi | |
| 258 | 新增: if [[ -e "$g/.git" ]]; then printf 'W\t%s\n' "$g"; else printf 'B\t%s\n' "$g"; fi | |
| 259 | 新增: done <<< "$(find "$dir/" -mindepth 2 -maxdepth 3 \( -name node_modules -prune \) \ | |
| 260 | 新增: -o \( -name .git -print -prune \) -o \( -name objects -type d -print -prune \) 2>/dev/null \ | |
| 261 | 新增: | sed 's#//*#/#g')" | |
| 262 | 新增:} | |
| 263 | 新增: | |
| 264 | 新增:# The hooks folder of the repository <at> of kind <kind>, absolute, in git's | |
| 265 | 新增:# spelling, as git names it: symlinks not resolved. For G, the absolute | |
| 266 | 新增:# core.hooksPath git's own config sets for every repository. Fails when there | |
| 267 | 新增:# is none, or git cannot tell. `--git-path` without --path-format (git 2.31) | |
| 268 | 新增:# answers relative to where git runs. | |
| 269 | 新增:# | |
| 270 | 新增:# Two lines: the top of the work tree (empty but for W), then the folder. | |
| 271 | 新增:_agent_vm_scan_hooks_dir() { | |
| 272 | 新增: local hooks base=/ top="" | |
| 273 | 新增: case "$1" in | |
| 274 | 新增: G) | |
| 275 | 新增: hooks="$(_agent_vm_git_at G / config --get core.hooksPath 2>/dev/null)" || return 1 | |
| 276 | 新增: [[ "$hooks" != "~/"* ]] || hooks="$home/${hooks#\~/}" | |
| 277 | 新增: [[ "$hooks" == /* || "$hooks" == [A-Za-z]:/* ]] || return 1 ;; | |
| 278 | 新增: W) | |
| 279 | 新增: hooks="$(_agent_vm_git_at W "$2" rev-parse --show-toplevel --git-path hooks 2>/dev/null)" || return 1 | |
| 280 | 新增: [[ "$hooks" == *$'\n'* ]] || return 1 | |
| 281 | 新增: top="${hooks%%$'\n'*}" | |
| 282 | 新增: hooks="${hooks#*$'\n'}" | |
| 283 | 新增: base="$(_agent_vm_git_spelling "$2")" || return 1 ;; | |
| 284 | 新增: *) | |
| 285 | 新增: hooks="$(_agent_vm_git_at "$1" "$2" rev-parse --git-path hooks 2>/dev/null)" || return 1 ;; | |
| 286 | 新增: esac | |
| 287 | 新增: [[ -n "$hooks" && "$hooks" != *[$'\n\t']* && "$top" != *$'\t'* ]] || return 1 | |
| 288 | 新增: printf '%s\n' "$top" | |
| 289 | 新增: _agent_vm_git_abs "$hooks" "$base" | |
| 290 | 新增:} | |
| 291 | 新增: | |
| 292 | 新增:# 0 when one of the paths the file system goes through to reach <path> (see | |
| 293 | 新增:# _agent_vm_path_hops) is in one of the caller's shares, outside the caller's | |
| 294 | 新增:# names: the VM can choose what is found there. Sets the caller's shown to | |
| 295 | 新增:# that path, relative to the project when it is there. | |
| 296 | 新增:_agent_vm_scan_hit() { | |
| 297 | 新增: local h hit_share hit_rel | |
| 298 | 新增: [[ -n "$1" ]] || return 1 | |
| 299 | 新增: while IFS= read -r h; do | |
| 300 | 新增: [[ -n "$h" ]] && _agent_vm_in_share "$h" || continue | |
| 301 | 新增: _agent_vm_under_readonly_name "$hit_rel" "$names" && continue | |
| 302 | 新增: shown="$h" | |
| 303 | 新增: [[ "$hit_share" != "$proj" ]] || shown="$hit_rel" | |
| 304 | 新增: return 0 | |
| 305 | 新增: done <<< "$(_agent_vm_path_hops "$1")" | |
| 306 | 新增: return 1 | |
| 307 | 新增:} | |
| 308 | 新增: | |
| 309 | 新增:# A risk line of the scan: <text>, its control characters made visible. | |
| 310 | 新增:_agent_vm_scan_risk() { | |
| 311 | 新增: local t="$1" | |
| 312 | 新增: printf 'R\t%s\n' "${t//[[:cntrl:]]/?}" | |
| 313 | 新增:} | |
| 314 | 新增: | |
| 315 | 新增:# The risk lines of the config of the repository <at> of kind <kind>, whose | |
| 316 | 新增:# work tree is <top> (see _agent_vm_git_at): its own config, or git's global | |
| 317 | 新增:# and system config for G. Config files in a share, included ones whether | |
| 318 | 新增:# they exist yet or not (git skips a missing one, and the VM can create it). | |
| 319 | 新增:# Settings whose command a share holds: a path in their value, relative to | |
| 320 | 新增:# the top of the repository, where git runs most of them (git's own config | |
| 321 | 新增:# has none to take them from). awk sorts the config first, so the shell only | |
| 322 | 新增:# sees each file once and the settings that hold a command (section and key | |
| 323 | 新增:# names lowercased, as `git config --list` prints them) with a path in their | |
| 324 | 新增:# value: a start runs this, and a fork per line would show. | |
| 325 | 新增:_agent_vm_scan_config() { | |
| 326 | 新增: local kind="$1" at="$2" cmd_base="$3" base=/ scope=--local k a b c w shown | |
| 327 | 新增: case "$kind" in | |
| 328 | 新增: W) base="$(_agent_vm_git_spelling "$at")" || return 0 ;; | |
| 329 | 新增: B) cmd_base="$at" ;; | |
| 330 | 新增: *) scope="" ;; | |
| 331 | 新增: esac | |
| 332 | 新增: _agent_vm_git_at "$kind" "$at" config --list ${scope:+"$scope"} --show-origin --includes 2>/dev/null \ | |
| 333 | 新增: | awk -F '\t' ' | |
| 334 | 新增: { | |
| 335 | 新增: origin = $1; kv = substr($0, length($1) + 2); f = "" | |
| 336 | 新增: if (origin ~ /^file:/) { f = substr(origin, 6); gsub(/^"|"$/, "", f) } | |
| 337 | 新增: if (f != "" && !(f in seen)) { seen[f] = 1; print "O\t" f } | |
| 338 | 新增: key = kv; sub(/=.*/, "", key); val = substr(kv, length(key) + 2); lk = tolower(key) | |
| 339 | 新增: if (lk == "include.path" || lk ~ /^includeif\..*\.path$/) { | |
| 340 | 新增: if (f != "") print "I\t" f "\t" val | |
| 341 | 新增: next | |
| 342 | 新增: } | |
| 343 | 新增: if (lk !~ /^(core\.(fsmonitor|sshcommand|editor|pager|askpass|gitproxy|alternaterefscommand)|sequence\.editor|gpg\.program|gpg\..*\.program|diff\.external|diff\..*\.(command|textconv)|(difftool|mergetool|browser|man)\..*\.cmd|merge\..*\.driver|filter\..*\.(clean|smudge|process)|credential\.helper|credential\..*\.helper|pager\..*|alias\..*|interactive\.difffilter|uploadpack\.packobjectshook|web\.browser)$/) next | |
| 344 | 新增: if (lk ~ /^alias\./ && val !~ /^!/) next | |
| 345 | 新增: if (val ~ /\//) print "K\t" f "\t" key "\t" val | |
| 346 | 新增: }' \ | |
| 347 | 新增: | while IFS=$'\t' read -r k a b c; do | |
| 348 | 新增: case "$k" in | |
| 349 | 新增: O) | |
| 350 | 新增: _agent_vm_scan_hit "$(_agent_vm_git_abs "$a" "$base")" && _agent_vm_scan_risk "config file $shown" ;; | |
| 351 | 新增: I) | |
| 352 | 新增: # Relative to the file holding it, as git takes it. | |
| 353 | 新增: [[ "$b" != "~/"* ]] || b="$home/${b#\~/}" | |
| 354 | 新增: a="$(_agent_vm_git_abs "$a" "$base")" | |
| 355 | 新增: _agent_vm_scan_hit "$(_agent_vm_git_abs "$b" "${a%/*}")" && _agent_vm_scan_risk "config file $shown" ;; | |
| 356 | 新增: K) | |
| 357 | 新增: # Word by word, through awk: an unquoted expansion would glob them. | |
| 358 | 新增: printf '%s\n' "${c#!}" | awk '{ for (i = 1; i <= NF; i++) print $i }' \ | |
| 359 | 新增: | while IFS= read -r w; do | |
| 360 | 新增: w="${w#[\"\']}"; w="${w%[\"\']}" | |
| 361 | 新增: # Not an option, an assignment or a URL: a path. | |
| 362 | 新增: [[ "$w" == */* && "$w" != -* && "$w" != *=* && "$w" != *://* ]] || continue | |
| 363 | 新增: [[ "$w" != "~/"* ]] || w="$home/${w#\~/}" | |
| 364 | 新增: [[ "$w" == /* || "$w" == [A-Za-z]:/* || -n "$cmd_base" ]] || continue | |
| 365 | 新增: _agent_vm_scan_hit "$(_agent_vm_git_abs "$w" "$cmd_base")" || continue | |
| 366 | 新增: _agent_vm_scan_risk "$b = $c" | |
| 367 | 新增: break | |
| 368 | 新增: done ;; | |
| 369 | 新增: esac | |
| 370 | 新增: done | |
| 371 | 新增:} | |
| 372 | 新增: | |
| 373 | 新增:# What git on this machine runs, or reads, from the folders the VM can write | |
| 374 | 新增:# (see _agent_vm_writable_shares) for the project <dir>: the repositories of | |
| 375 | 新增:# each share and git's own config. One line each, its kind first, then | |
| 376 | 新增:# tab-separated: | |
| 377 | 新增:# - H: a hooks folder, or a link on the way to it, in a share and outside the | |
| 378 | 新增:# names always listed. Where it is (relative to the project when it is | |
| 379 | 新增:# there, else absolute), then what names it (see _agent_vm_hooks_name): | |
| 380 | 新增:# relative to the top of its repository when that is in the share | |
| 381 | 新增:# (lib/x/.githooks is .githooks), else to the share; "." for a share | |
| 382 | 新增:# itself, empty for a name no share can carry. | |
| 383 | 新增:# - R: a risk to accept, as text: a config file in a share, a setting whose | |
| 384 | 新增:# command is in one, a hook linked to a file in one, a share with more | |
| 385 | 新增:# repositories than are checked. | |
| 386 | 新增:# What a name keeps read-only is no risk: the names always listed, and those | |
| 387 | 新增:# of the hooks folders found here. Each line once. | |
| 388 | 新增:_agent_vm_git_scan() { | |
| 389 | 新增: command -v git >/dev/null 2>&1 || return 0 | |
| 390 | 新增: _agent_vm_git_scan_lines "$1" | awk '!seen[$0]++' | |
| 391 | 新增:} | |
| 392 | 新增: | |
| 393 | 新增:_agent_vm_git_scan_lines() { | |
| 394 | 新增: local shares proj home s kind at i n=0 hooks hp top h f t in_repo name shown | |
| 395 | 新增: local hit_share hit_rel top_share top_rel names="$_AGENT_VM_BASE_NAMES" | |
| 396 | 新增: local _agent_vm_windows_memo=0 _agent_vm_nocase_memo=0 kinds=() ats=() hookss=() tops=() | |
| 397 | 新增: _agent_vm_on_windows && _agent_vm_windows_memo=1 | |
| 398 | 新增: _agent_vm_fs_nocase && _agent_vm_nocase_memo=1 | |
| 399 | 新增: shares="$(_agent_vm_writable_shares "$1")" | |
| 400 | 新增: [[ -n "$shares" ]] || return 0 | |
| 401 | 新增: proj="${shares%%$'\n'*}" | |
| 402 | 新增: home="$(_agent_vm_host_path "$HOME")" | |
| 403 | 新增: while IFS=$'\t' read -r kind at; do | |
| 404 | 新增: case "$kind" in | |
| 405 | 新增: X) | |
| 406 | 新增: shown="$at" | |
| 407 | 新增: _agent_vm_in_share "$at" && [[ "$hit_share" == "$proj" ]] && shown="$hit_rel" | |
| 408 | 新增: _agent_vm_scan_risk "more than 50 repositories in $shown: those after the 50th are not checked" ;; | |
| 409 | 新增: W|B|G) kinds[n]="$kind"; ats[n]="$at"; n=$((n + 1)) ;; | |
| 201 | 410 | esac |
| 411 | 新增: done <<< "$(while IFS= read -r s; do _agent_vm_share_repos "$s"; done <<< "$shares" | |
| 412 | 新增: printf 'G\t/\n')" | |
| 413 | 新增: # The hooks folders first: their names keep what is under them read-only. | |
| 414 | 新增: for ((i = 0; i < n; i++)); do | |
| 415 | 新增: top="" hooks="" | |
| 416 | 新增: if h="$(_agent_vm_scan_hooks_dir "${kinds[i]}" "${ats[i]}")"; then | |
| 417 | 新增: top="${h%%$'\n'*}" | |
| 418 | 新增: hooks="${h#*$'\n'}" | |
| 419 | 新增: elif [[ "${kinds[i]}" == W ]]; then | |
| 420 | 新增: top="$(_agent_vm_git_at W "${ats[i]}" rev-parse --show-toplevel 2>/dev/null)" || top="" | |
| 421 | 新增: fi | |
| 422 | 新增: hookss[i]="$hooks" | |
| 423 | 新增: tops[i]="$top" | |
| 424 | 新增: [[ -n "$hooks" ]] || continue | |
| 425 | 新增: top_share="" top_rel="" | |
| 426 | 新增: if [[ -n "$top" ]] && _agent_vm_in_share "$top"; then | |
| 427 | 新增: top_share="$hit_share" top_rel="$hit_rel" | |
| 428 | 新增: fi | |
| 429 | 新增: while IFS= read -r h; do | |
| 430 | 新增: [[ -n "$h" ]] && _agent_vm_in_share "$h" || continue | |
| 431 | 新增: [[ "$hit_rel" == . ]] || ! _agent_vm_under_readonly_name "$hit_rel" || continue | |
| 432 | 新增: in_repo="$hit_rel" | |
| 433 | 新增: if [[ "$hit_share" == "$top_share" && "$top_rel" != . ]]; then | |
| 434 | 新增: in_repo="$(_agent_vm_rel_in "$h" "$top")" || in_repo="$hit_rel" | |
| 435 | 新增: fi | |
| 436 | 新增: [[ "$in_repo" != *[[:cntrl:]]* ]] || in_repo="" | |
| 437 | 新增: shown="$h" | |
| 438 | 新增: [[ "$hit_share" != "$proj" ]] || shown="$hit_rel" | |
| 439 | 新增: printf 'H\t%s\t%s\n' "${shown//[[:cntrl:]]/?}" "$in_repo" | |
| 440 | 新增: if name="$(_agent_vm_hooks_name "$in_repo")"; then | |
| 441 | 新增: names="$names"$'\n'"$name" | |
| 442 | 新增: fi | |
| 443 | 新增: done <<< "$(_agent_vm_path_hops "$hooks")" | |
| 202 | 444 | done |
| 203 | 删除: [[ -e "$f" ]] || return 1 | |
| 204 | 删除: d="$(_agent_vm_git_spelling "$(dirname "$f")")" || return 1 | |
| 205 | 删除: printf '%s/%s\n' "${d%/}" "$(basename "$f")" | |
| 206 | 删除:} | |
| 207 | 删除: | |
| 208 | 删除:# Every hooks folder of the project <dir>'s repositories that is in the | |
| 209 | 删除:# project and outside the names above (see _agent_vm_repo_hooks), one per | |
| 210 | 删除:# line, with its two fields. | |
| 211 | 删除:_agent_vm_project_hooks() { | |
| 212 | 删除: local dir="$1" proj repo | |
| 213 | 删除: proj="$(_agent_vm_git_spelling "$dir")" || return 0 | |
| 214 | 删除: _agent_vm_project_repos "$dir" | while IFS= read -r repo; do | |
| 215 | 删除: _agent_vm_repo_hooks "$repo" "$proj" | |
| 216 | 删除: done | awk '!seen[$0]++' | |
| 445 | 新增: for ((i = 0; i < n; i++)); do | |
| 446 | 新增: _agent_vm_scan_config "${kinds[i]}" "${ats[i]}" "${tops[i]}" | |
| 447 | 新增: # A hook linked to a file a share holds: git runs that file, which may | |
| 448 | 新增: # be outside every name. | |
| 449 | 新增: hooks="${hookss[i]}" | |
| 450 | 新增: [[ -n "$hooks" ]] && hp="$(_agent_vm_git_spelling "$hooks")" || continue | |
| 451 | 新增: for f in "$hp"/*; do | |
| 452 | 新增: [[ -L "$f" && "$f" != *.sample ]] || continue | |
| 453 | 新增: t="$(readlink "$f")" || continue | |
| 454 | 新增: [[ "$t" != /* ]] || t="$(_agent_vm_host_path "$t")" | |
| 455 | 新增: _agent_vm_scan_hit "$(_agent_vm_git_abs "$t" "$hp")" && _agent_vm_scan_risk "hook ${f##*/} runs $shown" | |
| 456 | 新增: done | |
| 457 | 新增: done | |
| 458 | 新增:} | |
| 459 | 新增: | |
| 460 | 新增:# The lines of kind <kind> (H or R) of a scan (see _agent_vm_git_scan), the | |
| 461 | 新增:# kind dropped. | |
| 462 | 新增:_agent_vm_scan_part() { | |
| 463 | 新增: printf '%s\n' "$2" | awk -F '\t' -v k="$1" '$1 == k { print substr($0, length(k) + 2) }' | |
| 217 | 464 | } |
| 218 | 465 | |
| 219 | 删除:# The same for the project <dir> and the writable volumes it gets (see | |
| 220 | 删除:# _agent_vm_rw_volume_dirs): their names are read-only on every share, and | |
| 221 | 删除:# git on this machine runs the hooks of a repository in a volume as much. A | |
| 222 | 删除:# volume's folder is named by its path. | |
| 466 | 新增:# The hooks folders of the project <dir>'s shares, as the H lines of the | |
| 467 | 新增:# scan: where, then what names it, tab-separated. | |
| 223 | 468 | _agent_vm_share_hooks() { |
| 224 | 删除: local v rel in_repo | |
| 225 | 删除: _agent_vm_project_hooks "$1" | |
| 226 | 删除: while IFS= read -r v; do | |
| 227 | 删除: [[ -n "$v" ]] || continue | |
| 228 | 删除: while IFS=$'\t' read -r rel in_repo; do | |
| 229 | 删除: [[ -n "$rel" ]] && printf '%s\t%s\n' "${v%/}/$rel" "$in_repo" | |
| 230 | 删除: done <<< "$(_agent_vm_project_hooks "$v")" | |
| 231 | 删除: done <<< "$(_agent_vm_rw_volume_dirs "$1")" | |
| 469 | 新增: _agent_vm_scan_part H "$(_agent_vm_git_scan "$1")" | |
| 470 | 新增:} | |
| 471 | 新增: | |
| 472 | 新增:# The risks to accept for the project <dir>'s shares, as the R lines of the | |
| 473 | 新增:# scan. | |
| 474 | 新增:_agent_vm_share_config_risks() { | |
| 475 | 新增: _agent_vm_scan_part R "$(_agent_vm_git_scan "$1")" | |
| 232 | 476 | } |
| 233 | 477 | |
| 234 | 478 | # The name that keeps the hooks folder <rel> read-only: its first component, |
| @@ -254,13 +498,14 @@ _agent_vm_names_json() { | ||
| 254 | 498 | |
| 255 | 499 | # The readonlyNames JSON array a start gives the project <dir> unless the user |
| 256 | 500 | # declines a name: the names always listed, and those keeping its hooks |
| 257 | 删除:# folders read-only. | |
| 501 | 新增:# folders read-only. From <scan> (see _agent_vm_git_scan) when given. | |
| 258 | 502 | _agent_vm_readonly_names() { |
| 259 | 删除: local rel in_repo name names=() | |
| 503 | 新增: local rel in_repo name names=() scan | |
| 504 | 新增: if [[ $# -ge 2 ]]; then scan="$2"; else scan="$(_agent_vm_git_scan "$1")"; fi | |
| 260 | 505 | while IFS=$'\t' read -r rel in_repo; do |
| 261 | 506 | [[ -n "$rel" ]] || continue |
| 262 | 507 | name="$(_agent_vm_hooks_name "$in_repo")" && names+=("$name") |
| 263 | 删除: done <<< "$(_agent_vm_share_hooks "$1")" | |
| 508 | 新增: done <<< "$(_agent_vm_scan_part H "$scan")" | |
| 264 | 509 | _agent_vm_names_json ${names[@]+"${names[@]}"} |
| 265 | 510 | } |
| 266 | 511 | |
| @@ -275,103 +520,6 @@ _agent_vm_hooks_note() { | ||
| 275 | 520 | echo "Note: git runs hooks from $1 (core.hooksPath): every '$2' in the project is read-only for the VM too." |
| 276 | 521 | } |
| 277 | 522 | |
| 278 | 删除:# What git on this machine takes from files the VM can write, for the | |
| 279 | 删除:# repository at <repo> in the project <proj> (git's spelling), one line each: | |
| 280 | 删除:# a config file included from the project (whether it exists yet or not), | |
| 281 | 删除:# and a setting whose command names | |
| 282 | 删除:# a file in the project. The protected names are excepted, and core.hooksPath, | |
| 283 | 删除:# which _agent_vm_repo_hooks covers. A relative path in a command is taken | |
| 284 | 删除:# from the top of the repository, where git runs most of them. | |
| 285 | 删除:# | |
| 286 | 删除:# awk sorts the config first, so the shell only sees each file once and the | |
| 287 | 删除:# settings that hold a command (section and key names lowercased, as | |
| 288 | 删除:# `git config --list` prints them) with a path in their value: a start runs | |
| 289 | 删除:# this, and a fork per line would show. | |
| 290 | 删除:_agent_vm_repo_config_risks() { | |
| 291 | 删除: local repo="$1" proj="$2" base top kind a b w rel hooks f p | |
| 292 | 删除: base="$(_agent_vm_git_spelling "$repo")" || return 0 | |
| 293 | 删除: top="$(_agent_vm_git_untrusted -C "$repo" rev-parse --show-toplevel 2>/dev/null)" || return 0 | |
| 294 | 删除: _agent_vm_git_untrusted -C "$repo" config --list --show-origin --includes 2>/dev/null \ | |
| 295 | 删除: | awk -F '\t' ' | |
| 296 | 删除: { | |
| 297 | 删除: origin = $1; kv = substr($0, length($1) + 2) | |
| 298 | 删除: if (origin ~ /^file:/ && !(origin in seen)) { | |
| 299 | 删除: seen[origin] = 1; f = substr(origin, 6); gsub(/^"|"$/, "", f); print "O\t" f | |
| 300 | 删除: } | |
| 301 | 删除: key = kv; sub(/=.*/, "", key); val = substr(kv, length(key) + 2); lk = tolower(key) | |
| 302 | 删除: if (lk == "include.path" || lk ~ /^includeif\..*\.path$/) { | |
| 303 | 删除: if (origin ~ /^file:/) { f = substr(origin, 6); gsub(/^"|"$/, "", f); print "I\t" f "\t" val } | |
| 304 | 删除: next | |
| 305 | 删除: } | |
| 306 | 删除: if (lk !~ /^(core\.(fsmonitor|sshcommand|editor|pager|askpass|gitproxy|alternaterefscommand)|sequence\.editor|gpg\.program|gpg\..*\.program|diff\.external|diff\..*\.(command|textconv)|(difftool|mergetool|browser|man)\..*\.cmd|merge\..*\.driver|filter\..*\.(clean|smudge|process)|credential\.helper|credential\..*\.helper|pager\..*|alias\..*|interactive\.difffilter|uploadpack\.packobjectshook|web\.browser)$/) next | |
| 307 | 删除: if (lk ~ /^alias\./ && val !~ /^!/) next | |
| 308 | 删除: if (val ~ /\//) print "K\t" key "\t" val | |
| 309 | 删除: }' \ | |
| 310 | 删除: | while IFS=$'\t' read -r kind a b; do | |
| 311 | 删除: if [[ "$kind" == O ]]; then | |
| 312 | 删除: rel="$(_agent_vm_rel_in "$(_agent_vm_git_abs "$a" "$base")" "$proj")" \ | |
| 313 | 删除: && ! _agent_vm_under_readonly_name "$rel" \ | |
| 314 | 删除: && printf 'config file %s\n' "$rel" | |
| 315 | 删除: continue | |
| 316 | 删除: fi | |
| 317 | 删除: # An include, by its value: git skips a file that does not exist, so | |
| 318 | 删除: # --includes does not list it, and the VM can create it once the VM | |
| 319 | 删除: # runs. Relative to the file holding it, as git takes it. | |
| 320 | 删除: if [[ "$kind" == I ]]; then | |
| 321 | 删除: [[ "$b" == "~/"* ]] && b="$HOME/${b#\~/}" | |
| 322 | 删除: a="$(_agent_vm_git_abs "$a" "$base")" | |
| 323 | 删除: rel="$(_agent_vm_rel_in "$(_agent_vm_git_abs "$b" "${a%/*}")" "$proj")" \ | |
| 324 | 删除: && ! _agent_vm_under_readonly_name "$rel" \ | |
| 325 | 删除: && printf 'config file %s\n' "$rel" | |
| 326 | 删除: continue | |
| 327 | 删除: fi | |
| 328 | 删除: # Word by word, through awk: an unquoted expansion would glob them. | |
| 329 | 删除: printf '%s\n' "${b#!}" | awk '{ for (i = 1; i <= NF; i++) print $i }' \ | |
| 330 | 删除: | while IFS= read -r w; do | |
| 331 | 删除: w="${w#[\"\']}"; w="${w%[\"\']}" | |
| 332 | 删除: # Not an option, an assignment or a URL: a path. | |
| 333 | 删除: [[ "$w" == */* && "$w" != -* && "$w" != *=* && "$w" != *://* ]] || continue | |
| 334 | 删除: [[ "$w" == "~/"* ]] && w="$HOME/${w#\~/}" | |
| 335 | 删除: rel="$(_agent_vm_rel_in "$(_agent_vm_git_abs "$w" "$top")" "$proj")" || continue | |
| 336 | 删除: _agent_vm_under_readonly_name "$rel" && continue | |
| 337 | 删除: printf '%s = %s\n' "$a" "$b" | |
| 338 | 删除: break | |
| 339 | 删除: done | |
| 340 | 删除: done | |
| 341 | 删除: # A hook that is a symlink to a file of the project: git runs that file, | |
| 342 | 删除: # which no name keeps read-only, from a hooks folder that is. | |
| 343 | 删除: hooks="$(_agent_vm_repo_hooks_dir "$repo")" || return 0 | |
| 344 | 删除: for f in "$hooks"/*; do | |
| 345 | 删除: [[ -L "$f" && "$f" != *.sample ]] || continue | |
| 346 | 删除: p="$(_agent_vm_physical_file "$f")" || continue | |
| 347 | 删除: rel="$(_agent_vm_rel_in "$p" "$proj")" || continue | |
| 348 | 删除: _agent_vm_under_readonly_name "$rel" && continue | |
| 349 | 删除: printf 'hook %s runs %s\n' "${f##*/}" "$rel" | |
| 350 | 删除: done | |
| 351 | 删除:} | |
| 352 | 删除: | |
| 353 | 删除:# The same for every repository of the project <dir>, each line once. | |
| 354 | 删除:_agent_vm_project_config_risks() { | |
| 355 | 删除: local dir="$1" proj repo | |
| 356 | 删除: proj="$(_agent_vm_git_spelling "$dir")" || return 0 | |
| 357 | 删除: _agent_vm_project_repos "$dir" | while IFS= read -r repo; do | |
| 358 | 删除: _agent_vm_repo_config_risks "$repo" "$proj" | |
| 359 | 删除: done | awk '!seen[$0]++' | |
| 360 | 删除:} | |
| 361 | 删除: | |
| 362 | 删除:# The same for the project <dir> and its writable volumes, a volume's lines | |
| 363 | 删除:# after its path. | |
| 364 | 删除:_agent_vm_share_config_risks() { | |
| 365 | 删除: local v line | |
| 366 | 删除: _agent_vm_project_config_risks "$1" | |
| 367 | 删除: while IFS= read -r v; do | |
| 368 | 删除: [[ -n "$v" ]] || continue | |
| 369 | 删除: while IFS= read -r line; do | |
| 370 | 删除: [[ -n "$line" ]] && printf '%s: %s\n' "$v" "$line" | |
| 371 | 删除: done <<< "$(_agent_vm_project_config_risks "$v")" | |
| 372 | 删除: done <<< "$(_agent_vm_rw_volume_dirs "$1")" | |
| 373 | 删除:} | |
| 374 | 删除: | |
| 375 | 523 | # What a Lima without readonlyNames exposes when the shares are reverse-sshfs |
| 376 | 524 | # (see _agent_vm_unprotected_mount_is_sshfs), one paragraph, before |
| 377 | 525 | # _agent_vm_git_protection_hint. |
| @@ -141,18 +141,24 @@ where you stand. | ||
| 141 | 141 | |
| 142 | 142 | Before a VM boots with writable shares, agent-vm stops on what it cannot |
| 143 | 143 | protect, and asks whether to go on (no by default, and when it cannot ask): |
| 144 | 删除:a Lima without readonlyNames, hooks at the top of the project, git config or | |
| 145 | 删除:commands it names in files of the project, and git ignoring | |
| 146 | 删除:safe.bareRepository=explicit (which it offers to set: git would otherwise use | |
| 147 | 删除:a folder with HEAD, objects/ and refs/ as a repository, under any name). A | |
| 148 | 删除:VM that already runs gets the warnings only, and a restart when it lacks a | |
| 149 | 删除:protection; once stopped to boot again, it is asked like any other. | |
| 144 | 新增:a Lima without readonlyNames, hooks at the top of a share, git config, | |
| 145 | 新增:commands it names, or hooks linked to files, in the project or a writable | |
| 146 | 新增:volume, and git ignoring safe.bareRepository=explicit (which it offers to | |
| 147 | 新增:set: git would otherwise use a folder with HEAD, objects/ and refs/ as a | |
| 148 | 新增:repository, under any name). A VM that already runs gets the warnings only, | |
| 149 | 新增:and a restart when it lacks a protection; once stopped to boot again, it is | |
| 150 | 新增:asked like any other. | |
| 150 | 151 | 'agent-vm info' lists what a start would ask |
| 151 | 152 | (security_questions=). |
| 152 | 153 | --unsafe-writable-git, or AGENT_VM_UNSAFE_WRITABLE_GIT=1 in your shell, leaves |
| 153 | 154 | .git writable anyway, so the agent can commit in the project; a warning is |
| 154 | 155 | printed on every run. Changing it applies when the VM is next started. |
| 155 | 156 | |
| 157 | 新增:The writable shares are served without sshfs's cache, so the VM never writes | |
| 158 | 新增:back a file as it was before you changed it. AGENT_VM_SSHFS_CACHE=1 in your | |
| 159 | 新增:shell turns the cache on, faster on many files (git status, find), at that | |
| 160 | 新增:risk, for 20 seconds. It applies when a VM is next started. | |
| 161 | 新增: | |
| 156 | 162 | Customization: |
| 157 | 163 | ~/.agent-vm/env Shared env vars / tokens (dotenv-style; |
| 158 | 164 | pushed into every VM, loaded in its shells) |
| @@ -162,6 +162,11 @@ _agent_vm_check_linux_prereqs() { | ||
| 162 | 162 | # 0 when running on Windows (Git Bash, MSYS2 or Cygwin), as reported by |
| 163 | 163 | # uname: MINGW64_NT-..., MSYS_NT-... or CYGWIN_NT-.... |
| 164 | 164 | _agent_vm_on_windows() { |
| 165 | 新增: # A caller asking many times sets _agent_vm_windows_memo to 1 or 0 first. | |
| 166 | 新增: case "${_agent_vm_windows_memo:-}" in | |
| 167 | 新增: 1) return 0 ;; | |
| 168 | 新增: 0) return 1 ;; | |
| 169 | 新增: esac | |
| 165 | 170 | case "$(uname -s 2>/dev/null)" in |
| 166 | 171 | MINGW*|MSYS*|CYGWIN*) return 0 ;; |
| 167 | 172 | *) return 1 ;; |
| @@ -197,6 +202,11 @@ _agent_vm_lima_home() { | ||
| 197 | 202 | printf '%s\n' "${LIMA_HOME:-$HOME/.lima}" |
| 198 | 203 | } |
| 199 | 204 | |
| 205 | 新增:# The log of <vm>'s Lima host agent, which says why it did not start. | |
| 206 | 新增:_agent_vm_ha_log() { | |
| 207 | 新增: printf '%s/%s/ha.stderr.log\n' "$(_agent_vm_lima_home)" "$1" | |
| 208 | 新增:} | |
| 209 | 新增: | |
| 200 | 210 | # WSL generation from the kernel release: prints 2 or 1, or nothing when not |
| 201 | 211 | # on WSL. Only meaningful on Linux (WSL1 reports Microsoft without WSL2). |
| 202 | 212 | _agent_vm_wsl_version() { |
| @@ -175,14 +175,16 @@ _agent_vm_info() { | ||
| 175 | 175 | esac |
| 176 | 176 | fi |
| 177 | 177 | if [[ "$protected" == 1 ]]; then |
| 178 | 新增: local scan | |
| 179 | 新增: scan="$(_agent_vm_git_scan "$dir")" | |
| 178 | 180 | while IFS=$'\t' read -r rel in_repo; do |
| 179 | 181 | [[ -n "$rel" ]] || continue |
| 180 | 182 | if ! _agent_vm_hooks_name "$in_repo" >/dev/null; then |
| 181 | 183 | questions="${questions:+$questions,}hooks" |
| 182 | 184 | break |
| 183 | 185 | fi |
| 184 | 删除: done <<< "$(_agent_vm_share_hooks "$dir")" | |
| 185 | 删除: [[ -z "$(_agent_vm_share_config_risks "$dir")" ]] || questions="${questions:+$questions,}git-config" | |
| 186 | 新增: done <<< "$(_agent_vm_scan_part H "$scan")" | |
| 187 | 新增: [[ -z "$(_agent_vm_scan_part R "$scan")" ]] || questions="${questions:+$questions,}git-config" | |
| 186 | 188 | fi |
| 187 | 189 | case "$(_agent_vm_bare_repo_state)" in |
| 188 | 190 | unset|old) questions="${questions:+$questions,}bare-repo" ;; |
| @@ -84,13 +84,19 @@ _agent_vm_project_mountpoint() { | ||
| 84 | 84 | |
| 85 | 85 | # The entries of ~/.agent-vm/volumes for the project <dir>, one per line, |
| 86 | 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. | |
| 87 | 新增:# existing), destination (absolute and normalized, relative as written, or | |
| 88 | 新增:# empty for the source's own path), mode (ro or rw), and the entry as | |
| 89 | 新增:# source:destination:mode, for messages. Entries that cannot be used are | |
| 90 | 新增:# skipped, with a warning on stderr. Nothing is created: that is | |
| 91 | 新增:# _agent_vm_build_mounts_json's. | |
| 91 | 92 | _agent_vm_volume_entries() { |
| 92 | 删除: local host_dir="$1" quiet="${2:-}" raw line mounts_file="$AGENT_VM_STATE_DIR/volumes" | |
| 93 | 新增: local host_dir="$1" raw line mounts_file="$AGENT_VM_STATE_DIR/volumes" why mp proj_mp seen_mps=$'\n' | |
| 93 | 94 | [[ -f "$mounts_file" ]] || return 0 |
| 95 | 新增: local _agent_vm_unsafe_refs _agent_vm_windows_memo=0 _agent_vm_nocase_memo=0 | |
| 96 | 新增: _agent_vm_on_windows && _agent_vm_windows_memo=1 | |
| 97 | 新增: _agent_vm_fs_nocase && _agent_vm_nocase_memo=1 | |
| 98 | 新增: _agent_vm_unsafe_refs="$(_agent_vm_unsafe_ref_dirs)" | |
| 99 | 新增: proj_mp="$(_agent_vm_path_join / "$host_dir")" | |
| 94 | 100 | while IFS= read -r raw || [[ -n "$raw" ]]; do |
| 95 | 101 | line="${raw%%#*}" # strip comments |
| 96 | 102 | line="${line#"${line%%[![:space:]]*}"}" # trim leading whitespace |
| @@ -99,7 +105,7 @@ _agent_vm_volume_entries() { | ||
| 99 | 105 | # A control character (a tab, an ESC...) is invalid unescaped in the JSON |
| 100 | 106 | # handed to limactl. The CR of a CRLF file went with the trim above. |
| 101 | 107 | if [[ "$line" == *[[:cntrl:]]* ]]; then |
| 102 | 删除: _agent_vm_volume_warn "$quiet" "Mount entry '${raw}' (from ~/.agent-vm/volumes) contains a control character, skipping." | |
| 108 | 新增: echo "Warning: Mount entry '${raw}' (from ~/.agent-vm/volumes) contains a control character, skipping." >&2 | |
| 103 | 109 | continue |
| 104 | 110 | fi |
| 105 | 111 | # An optional 4th field, after an explicit mode, limits the entry to the |
| @@ -114,14 +120,10 @@ _agent_vm_volume_entries() { | ||
| 114 | 120 | fi |
| 115 | 121 | if [[ -n "$has_filter" ]]; then |
| 116 | 122 | if [[ -z "$filter" ]]; then |
| 117 | 删除: _agent_vm_volume_warn "$quiet" "Mount entry '${raw}' (from ~/.agent-vm/volumes) has an empty project filter; refusing to mount it in every project. Skipping." | |
| 123 | 新增: echo "Warning: Mount entry '${raw}' (from ~/.agent-vm/volumes) has an empty project filter; refusing to mount it in every project. Skipping." >&2 | |
| 118 | 124 | continue |
| 119 | 125 | fi |
| 120 | 删除: if [[ -n "$quiet" ]]; then | |
| 121 | 删除: _agent_vm_volume_matches "$filter" "$host_dir" 2>/dev/null || continue | |
| 122 | 删除: else | |
| 123 | 删除: _agent_vm_volume_matches "$filter" "$host_dir" || continue | |
| 124 | 删除: fi | |
| 126 | 新增: _agent_vm_volume_matches "$filter" "$host_dir" || continue | |
| 125 | 127 | fi |
| 126 | 128 | # Parse source[:destination][:mode] syntax (like docker compose volumes). |
| 127 | 129 | # The trailing mode segment is only recognized when it equals "ro" or |
| @@ -142,49 +144,57 @@ _agent_vm_volume_entries() { | ||
| 142 | 144 | # (`src:dst:/p:rw`), a second mode, a fifth field. Read as a destination, |
| 143 | 145 | # the entry would be mounted in every project, the project filter lost. |
| 144 | 146 | if [[ "$dst" == *:* ]]; then |
| 145 | 删除: _agent_vm_volume_warn "$quiet" "Mount entry '${raw}' (from ~/.agent-vm/volumes) does not read as source:destination:mode:project (the mode goes before the project, and is needed with one). Skipping." | |
| 147 | 新增: echo "Warning: Mount entry '${raw}' (from ~/.agent-vm/volumes) does not read as source:destination:mode:project (the mode goes before the project, and is needed with one). Skipping." >&2 | |
| 146 | 148 | continue |
| 147 | 149 | fi |
| 148 | 150 | src="${src/#\~/$HOME}" # expand ~ |
| 149 | 删除: # Reject characters that would break JSON interpolation below or the | |
| 150 | 删除: # pipe-separated cache format used for file mounts. | |
| 151 | 新增: # Reject characters that would break the mounts JSON or the |-separated | |
| 152 | 新增: # lines this prints and the file mounts cache. | |
| 151 | 153 | if [[ "$src" == *[$'"\\\n|']* || "$dst" == *[$'"\\\n|']* ]]; then |
| 152 | 删除: _agent_vm_volume_warn "$quiet" "Mount entry '${raw}' (from ~/.agent-vm/volumes) contains invalid characters (quote/backslash/newline/pipe), skipping." | |
| 154 | 新增: echo "Warning: Mount entry '${raw}' (from ~/.agent-vm/volumes) contains invalid characters (quote/backslash/newline/pipe), skipping." >&2 | |
| 153 | 155 | continue |
| 154 | 156 | fi |
| 155 | 157 | if [[ ! -e "$src" ]]; then |
| 156 | 删除: _agent_vm_volume_warn "$quiet" "Mount path '${src}' (from ~/.agent-vm/volumes) does not exist, skipping." | |
| 158 | 新增: echo "Warning: Mount path '${src}' (from ~/.agent-vm/volumes) does not exist, skipping." >&2 | |
| 159 | 新增: continue | |
| 160 | 新增: fi | |
| 161 | 新增: # What is refused as a project, refused as a volume (see | |
| 162 | 新增: # _agent_vm_unsafe_project), a repository's own folder only when the VM | |
| 163 | 新增: # could write it. | |
| 164 | 新增: if why="$(_agent_vm_unsafe_location "$src")" \ | |
| 165 | 新增: || { [[ "$mode" == rw && -d "$src" ]] && why="$(_agent_vm_git_dir_share "$src")"; }; then | |
| 166 | 新增: echo "Warning: Mount path '${src}' (from ~/.agent-vm/volumes) $why, skipping." >&2 | |
| 157 | 167 | continue |
| 158 | 168 | fi |
| 159 | 删除: # What is refused as a project, refused as a volume: agent-vm's state | |
| 160 | 删除: # (the VM could add a share for its next start), Lima's, the home folder. | |
| 161 | 删除: local why | |
| 162 | 删除: if why="$(_agent_vm_unsafe_project "$src")"; then | |
| 163 | 删除: _agent_vm_volume_warn "$quiet" "Mount path '${src}' (from ~/.agent-vm/volumes) $why, skipping." | |
| 169 | 新增: # Where the VM sees it: the destination, or the source's own path, as | |
| 170 | 新增: # Lima takes it. At the project or above it, it would hide the project's | |
| 171 | 新增: # share. At another entry's place, Lima would merge the two into one | |
| 172 | 新增: # share, with the second one's mode. | |
| 173 | 新增: mp="${dst:-$src}" | |
| 174 | 新增: [[ "$mp" == /* ]] || mp="$host_dir/$mp" | |
| 175 | 新增: mp="$(_agent_vm_path_join / "$mp")" | |
| 176 | 新增: [[ -z "$dst" || "$dst" != /* ]] || dst="$mp" | |
| 177 | 新增: if [[ "${proj_mp%/}/" == "${mp%/}/"* ]]; then | |
| 178 | 新增: echo "Warning: Mount entry '${entry}' (from ~/.agent-vm/volumes) would be mounted at $mp, which covers the project, skipping." >&2 | |
| 164 | 179 | continue |
| 165 | 180 | fi |
| 166 | 删除: # Mounted at the project, or above it, it would hide the project's share. | |
| 167 | 删除: if [[ "$dst" == /* && "${host_dir%/}/" == "${dst%/}/"* ]]; then | |
| 168 | 删除: _agent_vm_volume_warn "$quiet" "Mount destination '${dst}' (from ~/.agent-vm/volumes) would cover the project, skipping." | |
| 181 | 新增: if [[ "$seen_mps" == *$'\n'"$mp"$'\n'* ]]; then | |
| 182 | 新增: echo "Warning: Mount entry '${entry}' (from ~/.agent-vm/volumes) would be mounted at $mp, as an entry before it, skipping." >&2 | |
| 169 | 183 | continue |
| 170 | 184 | fi |
| 185 | 新增: seen_mps="$seen_mps$mp"$'\n' | |
| 171 | 186 | printf '%s|%s|%s|%s\n' "$src" "$dst" "$mode" "$entry" |
| 172 | 187 | done < "$mounts_file" |
| 173 | 188 | } |
| 174 | 189 | |
| 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 | 190 | # The writable directories of ~/.agent-vm/volumes for the project <dir>, one |
| 181 | 191 | # per line: shares the VM can write besides the project. Read quietly: the |
| 182 | 192 | # start that mounts them says what is wrong with an entry. |
| 183 | 193 | _agent_vm_rw_volume_dirs() { |
| 184 | 194 | local src dst mode entry |
| 185 | 195 | while IFS='|' read -r src dst mode entry; do |
| 186 | 删除: [[ "$mode" == rw && -d "$src" && ! -f "$src" ]] && printf '%s\n' "$src" | |
| 187 | 删除: done <<< "$(_agent_vm_volume_entries "$1" 1)" | |
| 196 | 新增: [[ "$mode" == rw && -d "$src" ]] && printf '%s\n' "$src" | |
| 197 | 新增: done <<< "$(_agent_vm_volume_entries "$1" 2>/dev/null)" | |
| 188 | 198 | } |
| 189 | 199 | |
| 190 | 200 | # _agent_vm_build_mounts_json <vm> <dir> [<writable>] [<names>]: the .mounts |
| @@ -203,69 +213,77 @@ _agent_vm_rw_volume_dirs() { | ||
| 203 | 213 | # there and listed in ~/.agent-vm/.agent-vm-file-mounts-<vm> for the bind in |
| 204 | 214 | # the VM. |
| 205 | 215 | _agent_vm_build_mounts_json() { |
| 206 | 删除: local vm_name="$1" host_dir="$2" project_writable="${3:-true}" sshfs="" | |
| 207 | 删除: # cache: false, sshfs's -o cache=no: with its cache, a file the host adds, | |
| 208 | 删除: # deletes or extends shows as it was for up to 20 seconds, and an agent | |
| 209 | 删除: # writing back what it read would undo the host's change. | |
| 216 | 新增: local vm_name="$1" host_dir="$2" project_writable="${3:-true}" names="" sshfs_ro="" sshfs_rw="" | |
| 210 | 217 | case "${4:-}" in |
| 211 | 删除: 1) sshfs=", \"sshfs\": {\"sftpDriver\": \"builtin\", \"cache\": false, \"readonlyNames\": $(_agent_vm_readonly_names "$host_dir")}" ;; | |
| 212 | 删除: \[*) sshfs=", \"sshfs\": {\"sftpDriver\": \"builtin\", \"cache\": false, \"readonlyNames\": $4}" ;; | |
| 218 | 新增: 1) names="$(_agent_vm_readonly_names "$host_dir")" ;; | |
| 219 | 新增: \[*) names="$4" ;; | |
| 213 | 220 | esac |
| 221 | 新增: # sshfs's cache (cache: false is -o cache=no): with it, a file the host | |
| 222 | 新增: # adds, deletes or extends shows as it was for up to 20 seconds, and an | |
| 223 | 新增: # agent writing back what it read would undo the host's change. Off on the | |
| 224 | 新增: # writable shares (see _agent_vm_sshfs_cache_mode). | |
| 225 | 新增: if [[ -n "$names" ]]; then | |
| 226 | 新增: sshfs_ro=", \"sshfs\": {\"sftpDriver\": \"builtin\", \"readonlyNames\": $names}" | |
| 227 | 新增: sshfs_rw="$sshfs_ro" | |
| 228 | 新增: [[ "$(_agent_vm_sshfs_cache_mode)" == on ]] \ | |
| 229 | 新增: || sshfs_rw=", \"sshfs\": {\"sftpDriver\": \"builtin\", \"cache\": false, \"readonlyNames\": $names}" | |
| 230 | 新增: fi | |
| 231 | 新增: local sshfs="$sshfs_ro" | |
| 232 | 新增: [[ "$project_writable" != true ]] || sshfs="$sshfs_rw" | |
| 214 | 233 | # Every entry names its mount point: agent-vm addresses the guest side by the |
| 215 | 234 | # shell's spelling of the path (--workdir, the write probe), which on Windows |
| 216 | 235 | # is not the C:/... form Lima reads the location in. |
| 217 | 236 | local mounts_json="[{\"location\": \"$(_agent_vm_host_path "$host_dir")\", \"mountPoint\": \"${host_dir}\", \"writable\": ${project_writable}${sshfs}}" |
| 218 | 删除: local mounts_file="$AGENT_VM_STATE_DIR/volumes" | |
| 219 | 237 | local file_mount_entries=() |
| 220 | 238 | local file_mounts_cache="$AGENT_VM_STATE_DIR/.agent-vm-file-mounts-${vm_name}" |
| 221 | 239 | |
| 222 | 删除: if [[ -f "$mounts_file" ]]; then | |
| 223 | 删除: local staging_idx=0 src dst mode line | |
| 224 | 删除: while IFS='|' read -r src dst mode line; do | |
| 225 | 删除: [[ -n "$src" ]] || continue | |
| 226 | 删除: if [[ -n "$dst" && "$dst" != /* ]]; then | |
| 227 | 删除: dst="$(_agent_vm_project_mountpoint "$host_dir" "$dst" "$src")" || continue | |
| 228 | 删除: fi | |
| 229 | 删除: if [[ -f "$src" ]]; then | |
| 230 | 删除: if [[ "$mode" == "rw" ]]; then | |
| 231 | 删除: echo "Warning: Mount entry '${line}' (from ~/.agent-vm/volumes) requests rw on a file; only directories support rw. Mount the parent directory instead. Skipping." >&2 | |
| 232 | 删除: continue | |
| 233 | 删除: fi | |
| 234 | 删除: # File mount: hardlink the source into a per-VM host staging dir so | |
| 235 | 删除: # the VM sees only this file (never the source's parent). Lima mounts | |
| 236 | 删除: # the staging dir; a bind mount inside the VM (applied after boot) | |
| 237 | 删除: # exposes the file at its final destination. | |
| 238 | 删除: local filename="" | |
| 239 | 删除: filename="$(basename "$src")" | |
| 240 | 删除: local file_staging_dir="$AGENT_VM_STATE_DIR/file-mounts/${vm_name}/${staging_idx}" | |
| 241 | 删除: local host_staging="${file_staging_dir}/${filename}" | |
| 242 | 删除: if ! _agent_vm_stage_file "$src" "$host_staging"; then | |
| 243 | 删除: echo "Warning: Failed to stage '${src}', skipping." >&2 | |
| 244 | 删除: rm -rf "$file_staging_dir" | |
| 245 | 删除: continue | |
| 246 | 删除: fi | |
| 247 | 删除: local staging_mount="/tmp/.agent-vm-file-mounts/${staging_idx}" | |
| 248 | 删除: local bind_dst="${dst:-${src}}" | |
| 249 | 删除: file_mount_entries+=("${src}|${host_staging}|${staging_mount}/${filename}|${bind_dst}") | |
| 250 | 删除: mounts_json+=", {\"location\": \"$(_agent_vm_host_path "$file_staging_dir")\", \"mountPoint\": \"${staging_mount}\", \"writable\": false${sshfs}}" | |
| 251 | 删除: staging_idx=$((staging_idx + 1)) | |
| 240 | 新增: local staging_idx=0 src dst mode line | |
| 241 | 新增: while IFS='|' read -r src dst mode line; do | |
| 242 | 新增: [[ -n "$src" ]] || continue | |
| 243 | 新增: if [[ -n "$dst" && "$dst" != /* ]]; then | |
| 244 | 新增: dst="$(_agent_vm_project_mountpoint "$host_dir" "$dst" "$src")" || continue | |
| 245 | 新增: fi | |
| 246 | 新增: if [[ -f "$src" ]]; then | |
| 247 | 新增: if [[ "$mode" == "rw" ]]; then | |
| 248 | 新增: echo "Warning: Mount entry '${line}' (from ~/.agent-vm/volumes) requests rw on a file; only directories support rw. Mount the parent directory instead. Skipping." >&2 | |
| 252 | 249 | continue |
| 253 | 250 | fi |
| 254 | 删除: if [[ ! -d "$src" ]]; then | |
| 255 | 删除: echo "Warning: Mount path '${src}' (from ~/.agent-vm/volumes) is not a regular file or directory, skipping." >&2 | |
| 251 | 新增: # File mount: hardlink the source into a per-VM host staging dir so | |
| 252 | 新增: # the VM sees only this file (never the source's parent). Lima mounts | |
| 253 | 新增: # the staging dir; a bind mount inside the VM (applied after boot) | |
| 254 | 新增: # exposes the file at its final destination. | |
| 255 | 新增: local filename="" | |
| 256 | 新增: filename="$(basename "$src")" | |
| 257 | 新增: local file_staging_dir="$AGENT_VM_STATE_DIR/file-mounts/${vm_name}/${staging_idx}" | |
| 258 | 新增: local host_staging="${file_staging_dir}/${filename}" | |
| 259 | 新增: if ! _agent_vm_stage_file "$src" "$host_staging"; then | |
| 260 | 新增: echo "Warning: Failed to stage '${src}', skipping." >&2 | |
| 261 | 新增: rm -rf "$file_staging_dir" | |
| 256 | 262 | continue |
| 257 | 263 | fi |
| 258 | 删除: local writable="false" | |
| 259 | 删除: if [[ "$mode" == "rw" ]]; then | |
| 260 | 删除: if [[ "$project_writable" == "true" ]]; then | |
| 261 | 删除: writable="true" | |
| 262 | 删除: else | |
| 263 | 删除: echo "Note: --readonly: '${src}' (rw in ~/.agent-vm/volumes) is mounted read-only too." >&2 | |
| 264 | 删除: fi | |
| 264 | 新增: local staging_mount="/tmp/.agent-vm-file-mounts/${staging_idx}" | |
| 265 | 新增: local bind_dst="${dst:-${src}}" | |
| 266 | 新增: file_mount_entries+=("${src}|${host_staging}|${staging_mount}/${filename}|${bind_dst}") | |
| 267 | 新增: mounts_json+=", {\"location\": \"$(_agent_vm_host_path "$file_staging_dir")\", \"mountPoint\": \"${staging_mount}\", \"writable\": false${sshfs_ro}}" | |
| 268 | 新增: staging_idx=$((staging_idx + 1)) | |
| 269 | 新增: continue | |
| 270 | 新增: fi | |
| 271 | 新增: if [[ ! -d "$src" ]]; then | |
| 272 | 新增: echo "Warning: Mount path '${src}' (from ~/.agent-vm/volumes) is not a regular file or directory, skipping." >&2 | |
| 273 | 新增: continue | |
| 274 | 新增: fi | |
| 275 | 新增: local writable="false" | |
| 276 | 新增: if [[ "$mode" == "rw" ]]; then | |
| 277 | 新增: if [[ "$project_writable" == "true" ]]; then | |
| 278 | 新增: writable="true" | |
| 279 | 新增: else | |
| 280 | 新增: echo "Note: --readonly: '${src}' (rw in ~/.agent-vm/volumes) is mounted read-only too." >&2 | |
| 265 | 281 | fi |
| 266 | 删除: mounts_json+=", {\"location\": \"$(_agent_vm_host_path "$src")\", \"mountPoint\": \"${dst:-$src}\", \"writable\": ${writable}${sshfs}}" | |
| 267 | 删除: done <<< "$(_agent_vm_volume_entries "$host_dir")" | |
| 268 | 删除: fi | |
| 282 | 新增: fi | |
| 283 | 新增: sshfs="$sshfs_ro" | |
| 284 | 新增: [[ "$writable" != true ]] || sshfs="$sshfs_rw" | |
| 285 | 新增: mounts_json+=", {\"location\": \"$(_agent_vm_host_path "$src")\", \"mountPoint\": \"${dst:-$src}\", \"writable\": ${writable}${sshfs}}" | |
| 286 | 新增: done <<< "$(_agent_vm_volume_entries "$host_dir")" | |
| 269 | 287 | mounts_json+="]" |
| 270 | 288 | |
| 271 | 289 | rm -f "$file_mounts_cache" |
| @@ -283,80 +301,174 @@ _agent_vm_build_mounts_json() { | ||
| 283 | 301 | # protection or the mode the VM had before (a protected .git, read-only |
| 284 | 302 | # shares), and the next start would trust it. With none, it rebuilds them. |
| 285 | 303 | _agent_vm_record_mounts() { |
| 286 | 删除: local record="$AGENT_VM_STATE_DIR/.agent-vm-mounts-$1" | |
| 304 | 新增: local record | |
| 305 | 新增: record="$(_agent_vm_mounts_record "$1")" | |
| 287 | 306 | mkdir -p "$AGENT_VM_STATE_DIR" 2>/dev/null && printf '%s\n' "$2" >| "$record" && return 0 |
| 288 | 307 | rm -f "$record" |
| 289 | 308 | echo "Error: could not record the shares of VM '$1' in $record." >&2 |
| 290 | 309 | return 1 |
| 291 | 310 | } |
| 292 | 311 | |
| 312 | 新增:# Where that record is kept for <vm>. | |
| 313 | 新增:_agent_vm_mounts_record() { | |
| 314 | 新增: printf '%s\n' "$AGENT_VM_STATE_DIR/.agent-vm-mounts-$1" | |
| 315 | 新增:} | |
| 316 | 新增: | |
| 317 | 新增:# 0 when <vm>'s record holds the text <s>. A missing record holds nothing. | |
| 318 | 新增:_agent_vm_mounts_record_has() { | |
| 319 | 新增: local record | |
| 320 | 新增: record="$(_agent_vm_mounts_record "$1")" | |
| 321 | 新增: [[ -f "$record" ]] && grep -qF -- "$2" "$record" | |
| 322 | 新增:} | |
| 323 | 新增: | |
| 293 | 324 | # 0 when <vm> is recorded with no writable share at all. A missing record |
| 294 | 325 | # counts as "not known to be read-only". |
| 295 | 326 | _agent_vm_mounts_all_readonly() { |
| 296 | 删除: local record="$AGENT_VM_STATE_DIR/.agent-vm-mounts-$1" mounts | |
| 297 | 删除: [[ -f "$record" ]] || return 1 | |
| 298 | 删除: mounts="$(cat "$record")" | |
| 299 | 删除: [[ "$mounts" != *'"writable": true'* ]] | |
| 327 | 新增: [[ -f "$(_agent_vm_mounts_record "$1")" ]] && ! _agent_vm_mounts_record_has "$1" '"writable": true' | |
| 300 | 328 | } |
| 301 | 329 | |
| 302 | 330 | # 0 when <vm> is recorded with every .git read-only (see |
| 303 | 331 | # _agent_vm_build_mounts_json). A missing record counts as "not protected". |
| 304 | 332 | _agent_vm_mounts_protect_git() { |
| 305 | 删除: local record="$AGENT_VM_STATE_DIR/.agent-vm-mounts-$1" | |
| 306 | 删除: [[ -f "$record" ]] && grep -q '"readonlyNames"' "$record" | |
| 333 | 新增: _agent_vm_mounts_record_has "$1" '"readonlyNames"' | |
| 307 | 334 | } |
| 308 | 335 | |
| 309 | 336 | # 0 when <vm> is recorded with readonlyNames <names> (a JSON array, as |
| 310 | 337 | # _agent_vm_readonly_names prints it). |
| 311 | 338 | _agent_vm_mounts_have_readonly_names() { |
| 312 | 删除: local record="$AGENT_VM_STATE_DIR/.agent-vm-mounts-$1" | |
| 313 | 删除: [[ -f "$record" ]] && grep -qF "\"readonlyNames\": $2" "$record" | |
| 339 | 新增: _agent_vm_mounts_record_has "$1" "\"readonlyNames\": $2" | |
| 314 | 340 | } |
| 315 | 341 | |
| 316 | 删除:# 0 when Lima's config for <vm> gives every share the builtin SFTP server and | |
| 317 | 删除:# the read-only names <names> (a JSON array; any names when empty), with the | |
| 318 | 删除:# mount type that serves them. Asked of Lima, not of the record: a share set | |
| 319 | 删除:# outside agent-vm (by hand, or from Lima's _config/override.yaml or | |
| 320 | 删除:# default.yaml, which Lima adds to every VM) has none, and the VM can write | |
| 321 | 删除:# the .git it holds. | |
| 322 | 删除:_agent_vm_live_shares_protected() { | |
| 323 | 删除: local out want='"readonlyNames":[' | |
| 324 | 删除: out="$(limactl list --format '{{.Config.MountType}} {{json .Config.Mounts}}' "$1" 2>/dev/null)" || return 1 | |
| 325 | 删除: [[ "${out%% *}" == reverse-sshfs ]] || return 1 | |
| 342 | 新增:# Lima's config for <vm>, in one call: its VM type, mount type and mounts (as | |
| 343 | 新增:# JSON), space-separated. Asked of Lima, not of agent-vm's record: Lima adds | |
| 344 | 新增:# the mounts of its _config/default.yaml and override.yaml to every VM, and | |
| 345 | 新增:# its config is what a running VM booted with (Lima refuses to edit a | |
| 346 | 新增:# running one). | |
| 347 | 新增:_agent_vm_live_config() { | |
| 348 | 新增: limactl list --format '{{.VMType}} {{.Config.MountType}} {{json .Config.Mounts}}' "$1" 2>/dev/null | |
| 349 | 新增:} | |
| 350 | 新增: | |
| 351 | 新增:# Sets the caller's live_vmtype, live_mtype and live_json from <live> (see | |
| 352 | 新增:# _agent_vm_live_config). The mount type may be missing; the JSON, null or an | |
| 353 | 新增:# array, is last. Fails when <live> holds no JSON: Lima did not answer. | |
| 354 | 新增:_agent_vm_live_fields() { | |
| 355 | 新增: local rest | |
| 356 | 新增: live_vmtype="${1%% *}" live_mtype="" live_json="" | |
| 357 | 新增: [[ "$1" == *" "* ]] || return 1 | |
| 358 | 新增: rest="${1#* }" | |
| 359 | 新增: rest="${rest# }" | |
| 360 | 新增: case "$rest" in | |
| 361 | 新增: null*|"["*) ;; | |
| 362 | 新增: *) live_mtype="${rest%% *}"; rest="${rest#"$live_mtype"}"; rest="${rest# }" ;; | |
| 363 | 新增: esac | |
| 364 | 新增: case "$rest" in | |
| 365 | 新增: null|"["*) live_json="$rest" ;; | |
| 366 | 新增: *) return 1 ;; | |
| 367 | 新增: esac | |
| 368 | 新增:} | |
| 369 | 新增: | |
| 370 | 新增:# Fails, printing why, unless the config <live> (see _agent_vm_live_config) | |
| 371 | 新增:# gives every share the builtin SFTP server and the read-only names <names> | |
| 372 | 新增:# (a JSON array; any names when empty), served by reverse-sshfs. A VM without | |
| 373 | 新增:# a share passes. A share without them lets the VM write the .git it holds. | |
| 374 | 新增:_agent_vm_live_shares_why() { | |
| 375 | 新增: local live_vmtype live_mtype live_json want='"readonlyNames":[' | |
| 376 | 新增: if ! _agent_vm_live_fields "$1"; then | |
| 377 | 新增: echo "Lima could not be asked for the VM's config" | |
| 378 | 新增: return 1 | |
| 379 | 新增: fi | |
| 326 | 380 | # As Lima prints it: no space after the commas (a name may hold a space). |
| 327 | 381 | [[ -z "${2:-}" ]] || want="\"readonlyNames\":${2//\", \"/\",\"}" |
| 328 | 删除: # One record per share: what follows each "location". | |
| 329 | 删除: printf '%s\n' "${out#* }" | awk -v want="$want" 'BEGIN { RS = "\"location\"" } | |
| 330 | 删除: NR > 1 { n++; if (index($0, "\"sftpDriver\":\"builtin\"") == 0 || index($0, want) == 0) bad++ } | |
| 331 | 删除: END { exit (n > 0 && bad == 0) ? 0 : 1 }' | |
| 382 | 新增: # One record per share: each mount object starts with its location, and no | |
| 383 | 新增: # name can hold a quote. | |
| 384 | 新增: printf '%s\n' "$live_json" | awk -v want="$want" -v mtype="${live_mtype:-unset}" ' | |
| 385 | 新增: BEGIN { RS = "[{]\"location\":" } | |
| 386 | 新增: NR > 1 { | |
| 387 | 新增: n++ | |
| 388 | 新增: if (index($0, "\"sftpDriver\":\"builtin\"") == 0 || index($0, want) == 0) { | |
| 389 | 新增: loc = $0; sub(/^"/, "", loc); sub(/".*/, "", loc) | |
| 390 | 新增: print "the share of " loc " lacks the read-only names, or the builtin SFTP server" | |
| 391 | 新增: bad = 1 | |
| 392 | 新增: exit | |
| 393 | 新增: } | |
| 394 | 新增: } | |
| 395 | 新增: END { | |
| 396 | 新增: if (!bad && n > 0 && mtype != "reverse-sshfs") { | |
| 397 | 新增: print "its mount type is " mtype ", and the read-only names need reverse-sshfs" | |
| 398 | 新增: bad = 1 | |
| 399 | 新增: } | |
| 400 | 新增: exit bad | |
| 401 | 新增: }' | |
| 332 | 402 | } |
| 333 | 403 | |
| 334 | 删除:# 1 when the running <vm> is served by another limactl than the one on PATH, | |
| 335 | 删除:# which agent-vm checked: a stock Lima started it (by hand, at login, or from | |
| 336 | 删除:# a shell with another PATH) and ignores the read-only names, or an older | |
| 337 | 删除:# build since replaced. 0 when it is the same, or when that cannot be told | |
| 338 | 删除:# (Windows, no pid file): never a reason to stop on its own. | |
| 404 | 新增:# Fails, printing why, unless .git is read-only for <vm> now: agent-vm gave | |
| 405 | 新增:# its shares the read-only names (the record), the Lima installed serves | |
| 406 | 新增:# them, Lima's config (<live> when given, see _agent_vm_live_config) gives | |
| 407 | 新增:# them to every share (see _agent_vm_live_shares_why), and the limactl | |
| 408 | 新增:# serving it, when it runs, is that Lima (see _agent_vm_hostagent_is_limactl). | |
| 409 | 新增:_agent_vm_protection_why() { | |
| 410 | 新增: local why live | |
| 411 | 新增: if [[ $# -ge 2 ]]; then live="$2"; else live="$(_agent_vm_live_config "$1")"; fi | |
| 412 | 新增: if ! _agent_vm_mounts_protect_git "$1"; then | |
| 413 | 新增: echo "agent-vm did not give its shares the read-only names" | |
| 414 | 新增: return 1 | |
| 415 | 新增: fi | |
| 416 | 新增: if ! _agent_vm_lima_protects_git; then | |
| 417 | 新增: echo "the Lima installed cannot keep .git read-only" | |
| 418 | 新增: return 1 | |
| 419 | 新增: fi | |
| 420 | 新增: why="$(_agent_vm_live_shares_why "$live")" || { echo "$why"; return 1; } | |
| 421 | 新增: if _agent_vm_running "$1" && ! _agent_vm_hostagent_is_limactl "$1"; then | |
| 422 | 新增: echo "it was started by another limactl than $(_agent_vm_limactl_path)" | |
| 423 | 新增: return 1 | |
| 424 | 新增: fi | |
| 425 | 新增:} | |
| 426 | 新增: | |
| 427 | 新增:# 1 when the running <vm> is served by another limactl build than the one on | |
| 428 | 新增:# PATH, which agent-vm checked: a stock Lima started it (by hand, at login, | |
| 429 | 新增:# or from a shell with another PATH) and ignores the read-only names, or an | |
| 430 | 新增:# older build since replaced. 0 when it is the same file, or the same | |
| 431 | 新增:# version, or when that cannot be told (Windows, no pid file, no way to see | |
| 432 | 新增:# the running binary): never a reason to stop on its own. | |
| 433 | 新增:# The running binary is asked of the kernel: /proc on Linux, where it can | |
| 434 | 新增:# still be run after its file was replaced; lsof on macOS, where ps only | |
| 435 | 新增:# knows the path it was started by, a Homebrew link that may point elsewhere | |
| 436 | 新增:# now. | |
| 339 | 437 | _agent_vm_hostagent_is_limactl() { |
| 340 | 删除: local pid exe mine | |
| 438 | 新增: local pid="" exe="" run="" mine | |
| 341 | 439 | _agent_vm_on_windows && return 0 |
| 342 | 删除: pid="$(cat "$(_agent_vm_lima_home)/$1/ha.pid" 2>/dev/null)" | |
| 440 | 新增: read -r pid < "$(_agent_vm_lima_home)/$1/ha.pid" 2>/dev/null | |
| 343 | 441 | [[ "$pid" =~ ^[0-9]+$ ]] || return 0 |
| 344 | 442 | if [[ -e "/proc/$pid/exe" ]]; then |
| 345 | 443 | exe="$(readlink "/proc/$pid/exe" 2>/dev/null)" |
| 346 | 删除: else | |
| 347 | 删除: exe="$(ps -o comm= -p "$pid" 2>/dev/null)" | |
| 444 | 新增: run="/proc/$pid/exe" | |
| 445 | 新增: elif command -v lsof >/dev/null 2>&1; then | |
| 446 | 新增: exe="$(lsof -a -p "$pid" -d txt -Fn 2>/dev/null | awk '/^n/ { print substr($0, 2); exit }')" | |
| 447 | 新增: run="$exe" | |
| 348 | 448 | fi |
| 349 | 449 | [[ "$exe" == /* ]] || return 0 |
| 350 | 删除: mine="$(_agent_vm_physical_file "$(command -v limactl)")" || return 0 | |
| 351 | 删除: [[ "$(_agent_vm_physical_file "$exe" 2>/dev/null)" == "$mine" ]] && return 0 | |
| 352 | 删除: # Another path to the same build (a shim on PATH): the same version. | |
| 353 | 删除: [[ -x "$exe" && "$("$exe" --version 2>/dev/null)" == "$(limactl --version 2>/dev/null)" ]] | |
| 450 | 新增: mine="$(_agent_vm_limactl_path)" | |
| 451 | 新增: [[ -n "$mine" ]] || return 0 | |
| 452 | 新增: [[ "$exe" -ef "$mine" ]] && return 0 | |
| 453 | 新增: [[ -x "$run" && "$("$run" --version 2>/dev/null)" == "$(limactl --version 2>/dev/null)" ]] | |
| 354 | 454 | } |
| 355 | 455 | |
| 356 | 删除:# 0 when <vm> is recorded with sshfs's cache off (see _agent_vm_build_mounts_json). | |
| 357 | 删除:_agent_vm_mounts_cache_off() { | |
| 358 | 删除: local record="$AGENT_VM_STATE_DIR/.agent-vm-mounts-$1" | |
| 359 | 删除: [[ -f "$record" ]] && grep -q '"cache": false' "$record" | |
| 456 | 新增:# How sshfs caches what the shares serve (see _agent_vm_build_mounts_json): | |
| 457 | 新增:# writable-off by default, the cache off on the writable shares only; on | |
| 458 | 新增:# with AGENT_VM_SSHFS_CACHE=1, read from the shell, never from the project. | |
| 459 | 新增:# On is faster on many files (a repeated `git status` sends about 20 times | |
| 460 | 新增:# fewer requests to the host), and the VM may then see a file as it was for | |
| 461 | 新增:# up to 20 seconds, and write that back. | |
| 462 | 新增:_agent_vm_sshfs_cache_mode() { | |
| 463 | 新增: if [[ "${AGENT_VM_SSHFS_CACHE:-}" == 1 ]]; then echo on; else echo writable-off; fi | |
| 464 | 新增:} | |
| 465 | 新增: | |
| 466 | 新增:# 0 when <vm>'s shares were given the cache mode they would get now (recorded | |
| 467 | 新增:# by _agent_vm_apply_shares). | |
| 468 | 新增:_agent_vm_mounts_sshfs_current() { | |
| 469 | 新增: local mode="" | |
| 470 | 新增: read -r mode < "$AGENT_VM_STATE_DIR/.agent-vm-sshfs-cache-$1" 2>/dev/null | |
| 471 | 新增: [[ "$mode" == "$(_agent_vm_sshfs_cache_mode)" ]] | |
| 360 | 472 | } |
| 361 | 473 | |
| 362 | 474 | # _agent_vm_push_env_and_probe <vm> <dir> <payload> [<env> [<runtime>]], in |
| @@ -367,28 +479,32 @@ _agent_vm_mounts_cache_off() { | ||
| 367 | 479 | # env-ok. |
| 368 | 480 | # - prints runtime-found when the project's <runtime> is there. |
| 369 | 481 | # - returns whether a write into the project <dir> succeeds: 0 yes, 1 no. A |
| 370 | 删除:# real write, not `test -w`: after a mode change the guest's fstab still | |
| 371 | 删除:# shows the old one. 2 when the write succeeded in the VM but did not reach | |
| 372 | 删除:# <dir> on this machine: the share is not mounted (sshfs died, or never | |
| 373 | 删除:# mounted), and the VM writes in the bare mount point on its own disk. The | |
| 374 | 删除:# guest leaves the file for this machine to find, and remove. | |
| 482 | 新增:# real write, removed at once, not `test -w`: after a mode change the | |
| 483 | 新增:# guest's fstab still shows the old one. | |
| 484 | 新增:# - returns 2 when the share is not mounted (sshfs died, or never mounted), | |
| 485 | 新增:# where the VM writes in the bare mount point on its own disk: the guest | |
| 486 | 新增:# does not see the file this machine put in <dir> just before (prints | |
| 487 | 新增:# share-ok when it does). Not for the caller's scratch VM, which shares | |
| 488 | 新增:# nothing: no file is put on this machine then. | |
| 375 | 489 | _agent_vm_push_env_and_probe() { |
| 376 | 删除: local vm_name="$1" host_dir="$2" payload="$3" token out st=0 | |
| 377 | 删除: token="$$.$RANDOM$RANDOM" | |
| 490 | 新增: local vm_name="$1" host_dir="$2" payload="$3" token="" out st=0 | |
| 491 | 新增: if [[ -z "${scratch:-}" ]]; then | |
| 492 | 新增: token=".agent-vm-probe.$$.$RANDOM$RANDOM" | |
| 493 | 新增: # Never through something already there: set -C refuses it. | |
| 494 | 新增: ( set -C; : > "$host_dir/$token" ) 2>/dev/null || token="" | |
| 495 | 新增: fi | |
| 378 | 496 | out="$({ [ -z "$payload" ] || printf '%s\n' "$payload"; } \ |
| 379 | 497 | | limactl shell "$vm_name" sh -c ' |
| 380 | 498 | (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 |
| 381 | 499 | [ -z "$3" ] || [ ! -f "$3" ] || echo runtime-found |
| 382 | 删除: touch "$1/.agent-vm-write-probe.$4" 2>/dev/null || exit 1; echo probe-written' \ | |
| 500 | 新增: [ -z "$4" ] || [ ! -f "$1/$4" ] || echo share-ok | |
| 501 | 新增: p="$1/.agent-vm-write-probe.$$"; touch "$p" 2>/dev/null || exit 1; rm -f "$p"' \ | |
| 383 | 502 | sh "$host_dir" "${4:-}" "${5:-}" "$token" 2>/dev/null)" || st=$? |
| 503 | 新增: [[ -z "$token" ]] || rm -f "$host_dir/$token" | |
| 384 | 504 | printf '%s\n' "$out" |
| 385 | 删除: [[ "$st" == 0 ]] || return 1 | |
| 386 | 删除: [[ "$out" == *probe-written* ]] || return 0 | |
| 387 | 删除: if [[ -e "$host_dir/.agent-vm-write-probe.$token" ]]; then | |
| 388 | 删除: rm -f "$host_dir/.agent-vm-write-probe.$token" | |
| 389 | 删除: return 0 | |
| 390 | 删除: fi | |
| 391 | 删除: return 2 | |
| 505 | 新增: # The guest answered, but without the share. | |
| 506 | 新增: [[ -z "$token" || "$out" != *env-ok* || "$out" == *share-ok* ]] || return 2 | |
| 507 | 新增: [[ "$st" == 0 ]] | |
| 392 | 508 | } |
| 393 | 509 | |
| 394 | 510 | # Are <vm>'s shares ones whose read-only flag is enforced outside the guest? |
| @@ -400,26 +516,24 @@ _agent_vm_push_env_and_probe() { | ||
| 400 | 516 | # virtiofsd has no read-only mode and Lima passes none |
| 401 | 517 | # (virtio-fs/virtiofsd#97), so the flag only reaches the guest's fstab. |
| 402 | 518 | # reverse-sshfs is enforced only when served by the builtin SFTP server of a |
| 403 | 删除:# Lima with readonlyNames, which is answered from the mounts agent-vm last | |
| 404 | 删除:# applied. Otherwise it only gets `-o ro` inside the guest, where root can | |
| 405 | 删除:# remount it rw. Returns 0 (enforced), 1 (not enforced), or 2 (could not tell). | |
| 519 | 新增:# Lima with readonlyNames, as _agent_vm_protection_why tells. Otherwise it | |
| 520 | 新增:# only gets `-o ro` inside the guest, where root can remount it rw, and the | |
| 521 | 新增:# SFTP server is not confined to the shares. Returns 0 (enforced), 1 (not | |
| 522 | 新增:# enforced), or 2 (could not tell). | |
| 406 | 523 | _agent_vm_mount_is_host_enforced() { |
| 407 | 删除: local types vmtype mtype | |
| 408 | 删除: types="$(limactl list --format '{{.VMType}} {{.Config.MountType}}' "$1" 2>/dev/null)" || return 2 | |
| 409 | 删除: vmtype="${types%% *}" | |
| 410 | 删除: mtype="${types#* }" | |
| 411 | 删除: [[ "$types" == *" "* ]] || mtype="" | |
| 524 | 新增: local live vmtype mtype live_vmtype live_mtype live_json | |
| 525 | 新增: live="$(_agent_vm_live_config "$1")" || return 2 | |
| 526 | 新增: _agent_vm_live_fields "$live" || return 2 | |
| 527 | 新增: vmtype="$live_vmtype" | |
| 528 | 新增: mtype="$live_mtype" | |
| 412 | 529 | case "$mtype" in |
| 413 | 530 | ""|default|"<nil>"|"<no value>") mtype="$(_agent_vm_default_mount_type "$1" "$vmtype")" ;; |
| 414 | 531 | esac |
| 415 | 532 | case "$vmtype $mtype" in |
| 416 | 533 | "vz virtiofs"|"qemu 9p") return 0 ;; |
| 417 | 534 | "qemu virtiofs") return 1 ;; |
| 418 | 删除: # The record says agent-vm gave it readonlyNames, and the Lima installed | |
| 419 | 删除: # now serves them: a stock limactl started by hand would not. | |
| 420 | 535 | ?*" reverse-sshfs") |
| 421 | 删除: _agent_vm_mounts_protect_git "$1" && _agent_vm_lima_protects_git \ | |
| 422 | 删除: && _agent_vm_live_shares_protected "$1" && return 0 | |
| 536 | 新增: _agent_vm_protection_why "$1" "$live" >/dev/null && return 0 | |
| 423 | 537 | return 1 ;; |
| 424 | 538 | *) return 2 ;; |
| 425 | 539 | esac |
| @@ -302,9 +302,10 @@ EOF | ||
| 302 | 302 | mcp-chrome) install_mcp_chrome=1 ;; |
| 303 | 303 | mcp-playwright) install_mcp_playwright=1 ;; |
| 304 | 304 | code-server) install_code_server=1 ;; |
| 305 | 删除: code-claude) install_code_claude=1 ;; | |
| 306 | 删除: code-codex) install_code_codex=1 ;; | |
| 307 | 删除: code-vibe) install_code_vibe=1 ;; | |
| 305 | 新增: # An extension needs the editor. | |
| 306 | 新增: code-claude) install_code_claude=1 install_code_server=1 ;; | |
| 307 | 新增: code-codex) install_code_codex=1 install_code_server=1 ;; | |
| 308 | 新增: code-vibe) install_code_vibe=1 install_code_server=1 ;; | |
| 308 | 309 | *) |
| 309 | 310 | echo "Unknown preinstall name: $f (names are lowercase)" >&2 |
| 310 | 311 | echo "Valid: python, node, ruby, rust, golang, docker, chromium, gh, claude, opencode, codex, vibe, pi, mcp-chrome, mcp-playwright, code-server, code-claude, code-codex, code-vibe, default, all, none" >&2 |
| @@ -463,11 +464,6 @@ EOF | ||
| 463 | 464 | echo "Running security checks..." |
| 464 | 465 | [[ -n "$declined_protection" ]] || _agent_vm_offer_git_protection |
| 465 | 466 | |
| 466 | 删除: # An extension needs the editor. | |
| 467 | 删除: if [[ "$install_code_claude$install_code_codex$install_code_vibe" == *1* ]]; then | |
| 468 | 删除: install_code_server=1 | |
| 469 | 删除: fi | |
| 470 | 删除: | |
| 471 | 467 | # --preinstall can name what needs node without node. |
| 472 | 468 | local node_reason |
| 473 | 469 | node_reason="$(_agent_vm_node_needed_by)" |
| @@ -519,8 +515,8 @@ EOF | ||
| 519 | 515 | echo "Starting base VM (the first run downloads a Debian image)..." |
| 520 | 516 | if ! _agent_vm_windowed "$setup_log" limactl start "$AGENT_VM_TEMPLATE" </dev/null; then |
| 521 | 517 | echo "Error: Failed to start base VM. Full log: $setup_log" >&2 |
| 522 | 删除: echo "Lima's own log: $(_agent_vm_lima_home)/$AGENT_VM_TEMPLATE/ha.stderr.log" >&2 | |
| 523 | 删除: _agent_vm_windows_start_hint "$setup_log" "$(_agent_vm_lima_home)/$AGENT_VM_TEMPLATE/ha.stderr.log" | |
| 518 | 新增: echo "Lima's own log: $(_agent_vm_ha_log "$AGENT_VM_TEMPLATE")" >&2 | |
| 519 | 新增: _agent_vm_windows_start_hint "$setup_log" "$(_agent_vm_ha_log "$AGENT_VM_TEMPLATE")" | |
| 524 | 520 | return 1 |
| 525 | 521 | fi |
| 526 | 522 | |
| @@ -47,14 +47,7 @@ _agent_vm_ask_choice() { | ||
| 47 | 47 | printf ' %s) %s\n' "$i" "$reply" >&2 |
| 48 | 48 | i=$((i + 1)) |
| 49 | 49 | done |
| 50 | 删除: while true; do | |
| 51 | 删除: reply="$(_agent_vm_ask "$prompt" "$default")" | |
| 52 | 删除: if [[ "$reply" =~ ^[1-9][0-9]*$ && "$reply" -le $# ]]; then | |
| 53 | 删除: printf '%s\n' "$reply" | |
| 54 | 删除: return 0 | |
| 55 | 删除: fi | |
| 56 | 删除: printf ' (a number from 1 to %s; got: %s)\n' "$#" "$reply" >&2 | |
| 57 | 删除: done | |
| 50 | 新增: _agent_vm_ask_int "$prompt" "$default" "$#" | |
| 58 | 51 | } |
| 59 | 52 | |
| 60 | 53 | # Can a question be asked, and seen? A terminal to read the answer from, and |
| @@ -148,17 +141,22 @@ _agent_vm_box() { | ||
| 148 | 141 | } >&2 |
| 149 | 142 | } |
| 150 | 143 | |
| 151 | 删除:# Prompt for a positive integer with default. Re-prompts on invalid input. | |
| 152 | 删除:# Used for disk/memory/cpus where a typo (e.g. "10G") would otherwise produce | |
| 153 | 删除:# a cryptic limactl error several seconds later. | |
| 144 | 新增:# Prompt for a positive integer with default, at most <max> when given. | |
| 145 | 新增:# Re-prompts on invalid input. Used for disk/memory/cpus where a typo (e.g. | |
| 146 | 新增:# "10G") would otherwise produce a cryptic limactl error several seconds | |
| 147 | 新增:# later, and for the menus of _agent_vm_ask_choice. | |
| 154 | 148 | _agent_vm_ask_int() { |
| 155 | 删除: local prompt="$1" default="$2" reply | |
| 149 | 新增: local prompt="$1" default="$2" max="${3:-}" reply | |
| 156 | 150 | while true; do |
| 157 | 151 | reply=$(_agent_vm_ask "$prompt" "$default") |
| 158 | 删除: if [[ "$reply" =~ ^[1-9][0-9]*$ ]]; then | |
| 152 | 新增: if [[ "$reply" =~ ^[1-9][0-9]*$ ]] && [[ -z "$max" || "$reply" -le "$max" ]]; then | |
| 159 | 153 | printf '%s\n' "$reply" |
| 160 | 154 | return 0 |
| 161 | 155 | fi |
| 162 | 删除: printf ' (must be a positive integer, e.g. 10; got: %s)\n' "$reply" >&2 | |
| 156 | 新增: if [[ -n "$max" ]]; then | |
| 157 | 新增: printf ' (a number from 1 to %s; got: %s)\n' "$max" "$reply" >&2 | |
| 158 | 新增: else | |
| 159 | 新增: printf ' (must be a positive integer, e.g. 10; got: %s)\n' "$reply" >&2 | |
| 160 | 新增: fi | |
| 163 | 161 | done |
| 164 | 162 | } |
| @@ -48,20 +48,19 @@ _agent_vm_unmountable_path() { | ||
| 48 | 48 | fi |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 删除:# Prints why <dir> must not be shared with a VM ("is, or contains, ..." or "is | |
| 52 | 删除:# inside ..."), and returns 0, when it is or contains your home directory | |
| 53 | 删除:# (dotfiles, SSH keys, every other project), or is, contains or is inside | |
| 54 | 删除:# agent-vm itself (the host runs its files), agent-vm's state (every VM's env) | |
| 55 | 删除:# or Lima's (the VMs' SSH key and disks, override.yaml adding mounts to every | |
| 56 | 删除:# VM). A project inside the home directory is what is expected. Returns 1 | |
| 57 | 删除:# when it is none of them. | |
| 58 | 删除:# Compared as physical paths: a share is the directory a path resolves to. | |
| 59 | 删除:# And whatever the case where the file system ignores it: `cd /c/users/me` | |
| 60 | 删除:# reaches the home directory in Git Bash, which keeps the spelling typed. | |
| 51 | 新增:# Prints why the project <dir> must not be shared with a VM, and returns 0, | |
| 52 | 新增:# when it is one of the locations below (_agent_vm_unsafe_location) or a | |
| 53 | 新增:# repository's own folder (_agent_vm_git_dir_share): the project is a | |
| 54 | 新增:# writable share. Returns 1 when it is neither. | |
| 61 | 55 | _agent_vm_unsafe_project() { |
| 62 | 删除: local dir p rp what | |
| 63 | 删除: dir="$(CDPATH= cd -P -- "$1" 2>/dev/null && pwd)" || dir="$1" | |
| 64 | 删除: dir="$(_agent_vm_fold "$dir")" | |
| 56 | 新增: _agent_vm_unsafe_location "$1" || _agent_vm_git_dir_share "$1" | |
| 57 | 新增:} | |
| 58 | 新增: | |
| 59 | 新增:# The locations no share may reach, one per line, physical and folded (see | |
| 60 | 新增:# _agent_vm_unsafe_location), each after what it is and a tab. A caller | |
| 61 | 新增:# checking several paths sets _agent_vm_unsafe_refs to this once. | |
| 62 | 新增:_agent_vm_unsafe_ref_dirs() { | |
| 63 | 新增: local p rp what | |
| 65 | 64 | for what in "your home directory" "agent-vm itself" "agent-vm's state" "Lima's state"; do |
| 66 | 65 | case "$what" in |
| 67 | 66 | "your home directory") p="$HOME" ;; |
| @@ -78,7 +77,27 @@ _agent_vm_unsafe_project() { | ||
| 78 | 77 | p="${p%/}" |
| 79 | 78 | fi |
| 80 | 79 | [[ -n "$p" ]] || continue |
| 81 | 删除: p="$(_agent_vm_fold "$p")" | |
| 80 | 新增: printf '%s\t%s\n' "$what" "$(_agent_vm_fold "$p")" | |
| 81 | 新增: done | |
| 82 | 新增:} | |
| 83 | 新增: | |
| 84 | 新增:# Prints why <dir> must not be shared with a VM, writable or not ("is, or | |
| 85 | 新增:# contains, ..." or "is inside ..."), and returns 0, when it is or contains | |
| 86 | 新增:# your home directory (dotfiles, SSH keys, every other project), or is, | |
| 87 | 新增:# contains or is inside agent-vm itself (the host runs its files), agent-vm's | |
| 88 | 新增:# state (every VM's env) or Lima's (the VMs' SSH key and disks, override.yaml | |
| 89 | 新增:# adding mounts to every VM). A project inside the home directory is what is | |
| 90 | 新增:# expected. Returns 1 when it is none of them. | |
| 91 | 新增:# Compared as physical paths: a share is the directory a path resolves to. | |
| 92 | 新增:# And whatever the case where the file system ignores it: `cd /c/users/me` | |
| 93 | 新增:# reaches the home directory in Git Bash, which keeps the spelling typed. | |
| 94 | 新增:_agent_vm_unsafe_location() { | |
| 95 | 新增: local dir what p refs="${_agent_vm_unsafe_refs:-}" | |
| 96 | 新增: [[ -n "$refs" ]] || refs="$(_agent_vm_unsafe_ref_dirs)" | |
| 97 | 新增: dir="$(CDPATH= cd -P -- "$1" 2>/dev/null && pwd)" || dir="$1" | |
| 98 | 新增: dir="$(_agent_vm_fold "$dir")" | |
| 99 | 新增: while IFS=$'\t' read -r what p; do | |
| 100 | 新增: [[ -n "$p" ]] || continue | |
| 82 | 101 | case "${p%/}/" in |
| 83 | 102 | "${dir%/}/"*) |
| 84 | 103 | printf 'is, or contains, %s\n' "$what" |
| @@ -90,9 +109,26 @@ _agent_vm_unsafe_project() { | ||
| 90 | 109 | printf 'is inside %s\n' "$what" |
| 91 | 110 | return 0 ;; |
| 92 | 111 | esac |
| 112 | 新增: done <<< "$refs" | |
| 113 | 新增: return 1 | |
| 114 | 新增:} | |
| 115 | 新增: | |
| 116 | 新增:# Prints why <dir> must not be a writable share, and returns 0, when it is a | |
| 117 | 新增:# repository's own folder or inside one: a .git or .hg (by name, as the SFTP | |
| 118 | 新增:# server matches them), or a bare repository (HEAD, objects/ and refs/, as git | |
| 119 | 新增:# finds one). The read-only names apply below a share's root, so such a share | |
| 120 | 新增:# is writable whole: hooks and config included. | |
| 121 | 新增:_agent_vm_git_dir_share() { | |
| 122 | 新增: local dir a | |
| 123 | 新增: dir="$(CDPATH= cd -P -- "$1" 2>/dev/null && pwd)" || dir="$1" | |
| 124 | 新增: a="${dir%/}" | |
| 125 | 新增: while [[ -n "$a" ]]; do | |
| 126 | 新增: if [[ -f "$a/HEAD" && -d "$a/objects" && -d "$a/refs" ]]; then | |
| 127 | 新增: printf 'is, or is inside, a git repository'"'"'s own folder (%s)\n' "$a" | |
| 128 | 新增: return 0 | |
| 129 | 新增: fi | |
| 130 | 新增: a="${a%/*}" | |
| 93 | 131 | 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 | 132 | if _agent_vm_under_readonly_name "${dir#/}"; then |
| 97 | 133 | printf 'is, or is inside, a folder git or Mercurial keeps its repository in (.git, .hg)\n' |
| 98 | 134 | return 0 |
| @@ -245,7 +281,8 @@ _agent_vm_cleanup_state() { | ||
| 245 | 281 | rm -f "$AGENT_VM_STATE_DIR/.agent-vm-sshfs-${vm_name}" |
| 246 | 282 | rm -f "$AGENT_VM_STATE_DIR/.agent-vm-term-${vm_name}" |
| 247 | 283 | rm -f "$AGENT_VM_STATE_DIR/.agent-vm-file-mounts-${vm_name}" |
| 248 | 删除: rm -f "$AGENT_VM_STATE_DIR/.agent-vm-mounts-${vm_name}" | |
| 284 | 新增: rm -f "$(_agent_vm_mounts_record "$vm_name")" | |
| 285 | 新增: rm -f "$AGENT_VM_STATE_DIR/.agent-vm-sshfs-cache-${vm_name}" | |
| 249 | 286 | rm -f "$(_agent_vm_scratch_marker "$vm_name")" |
| 250 | 287 | rm -rf "$AGENT_VM_STATE_DIR/file-mounts/${vm_name}" |
| 251 | 288 | # Deleting the template retires the marker that says it is usable. |
| @@ -362,6 +399,7 @@ _agent_vm_migrate_0_1() { | ||
| 362 | 399 | echo "$out" >&2 |
| 363 | 400 | return 1 |
| 364 | 401 | fi |
| 402 | 新增: _agent_vm_check_before_start "$vm_name" 1 || return 1 | |
| 365 | 403 | echo "Starting VM '$vm_name' without shares to install sshfs..." |
| 366 | 404 | if ! out=$(limactl start "$vm_name" 2>&1); then |
| 367 | 405 | echo "Error: Failed to start VM '$vm_name' to install sshfs:" >&2 |
| @@ -47,7 +47,10 @@ fi | ||
| 47 | 47 | SB="$(mktemp -d /tmp/agent-vm-e2e.XXXXXX)" |
| 48 | 48 | export AGENT_VM_STATE_DIR="$SB/state" |
| 49 | 49 | export LIMA_HOME="$SB/lima" |
| 50 | 删除:PROJ="$SB/project" | |
| 50 | 新增:# In a folder of its own: a volume holding it must not hold the state | |
| 51 | 新增:# directories, which agent-vm refuses to share. | |
| 52 | 新增:WORK="$SB/work" | |
| 53 | 新增:PROJ="$WORK/project" | |
| 51 | 54 | mkdir -p "$AGENT_VM_STATE_DIR" "$LIMA_HOME" "$PROJ" |
| 52 | 55 | git -C "$PROJ" init -q |
| 53 | 56 | |
| @@ -238,11 +241,11 @@ section "--readonly covers every share, not just the project" | ||
| 238 | 241 | # ============================================================================= |
| 239 | 242 | # A writable volume that contains the project is a second path to the same |
| 240 | 243 | # files, and the hypervisor enforces read-only per share. Under --readonly it |
| 241 | 删除:# has to be read-only as well. $SB is the project's parent. | |
| 244 | 新增:# has to be read-only as well. $WORK is the project's parent. | |
| 242 | 245 | # |
| 243 | 246 | # Volumes are mounted when a VM is created, so --reset: on the existing VM the |
| 244 | 247 | # volume would simply be absent, and the write would fail for that reason. |
| 245 | 删除:printf '%s:/mnt/sb:rw\n' "$SB" > "$AGENT_VM_STATE_DIR/volumes" | |
| 248 | 新增:printf '%s:/mnt/sb:rw\n' "$WORK" > "$AGENT_VM_STATE_DIR/volumes" | |
| 246 | 249 | ro_run --reset run sudo sh -c \ |
| 247 | 250 | "test -d /mnt/sb/project || exit 3; echo x > /mnt/sb/project/via-volume.txt" |
| 248 | 251 | via_status=$? |
| @@ -269,7 +272,7 @@ else | ||
| 269 | 272 | fail "the project stayed read-only after --readonly was dropped" |
| 270 | 273 | fi |
| 271 | 274 | if (cd "$PROJ" && "$AGENT_VM" run sh -c "echo back > /mnt/sb/volume-again.txt") \ |
| 272 | 删除: && [ -e "$SB/volume-again.txt" ]; then | |
| 275 | 新增: && [ -e "$WORK/volume-again.txt" ]; then | |
| 273 | 276 | pass "and an rw volume is writable again" |
| 274 | 277 | else |
| 275 | 278 | fail "the rw volume stayed read-only after --readonly was dropped" |
| @@ -152,6 +152,15 @@ sshfs_stub ' -o follow_symlinks' | ||
| 152 | 152 | check "sshfs wrapper: an older sshfs gets the arguments unchanged" \ |
| 153 | 153 | "$(sh "$SB/sshfs-wrapper" ':/p' /p -o slave)" ":/p /p -o slave" |
| 154 | 154 | |
| 155 | 新增:# An agent is there as a command, as an extension, or both: either way its | |
| 156 | 新增:# config (managed settings, MCP servers) is written. The lines setup derives | |
| 157 | 新增:# it with, run as setup does. | |
| 158 | 新增:has_block="$(awk '/^HAS_CLAUDE=0 HAS_CODEX=0 HAS_VIBE=0$/,/HAS_VIBE=1$/' "$SETUP_SH")" | |
| 159 | 新增:has() { ( INSTALL_CLAUDE="$1" INSTALL_CODE_CLAUDE="$2" INSTALL_CODEX="$3" INSTALL_CODE_CODEX="$4" INSTALL_VIBE="$5" INSTALL_CODE_VIBE="$6" | |
| 160 | 新增: eval "$has_block"; echo "$HAS_CLAUDE$HAS_CODEX$HAS_VIBE" ); } | |
| 161 | 新增:check "setup: the agents' config, for a command or an extension" \ | |
| 162 | 新增: "$(has 1 0 0 0 0 0) $(has 0 1 0 0 0 0) $(has 0 0 0 1 0 0) $(has 0 0 0 0 1 1) $(has 0 0 0 0 0 0)" "100 100 010 001 000" | |
| 163 | 新增: | |
| 155 | 164 | # ============================================================================= |
| 156 | 165 | section "MCP config writer" |
| 157 | 166 | # ============================================================================= |
| @@ -235,19 +244,37 @@ else | ||
| 235 | 244 | echo '{"$ref":"../top.json"}' > "$SCH/web/$(web https://h.test/s/rel.json)" |
| 236 | 245 | echo '{"type":"string"}' > "$SCH/web/$(web https://h.test/top.json)" |
| 237 | 246 | echo '{"type":"number"}' > "$SCH/web/$(web https://www.schemastore.org/b)" |
| 247 | 新增: # c: listed at one URL, its $id another, which its relative references | |
| 248 | 新增: # follow, as the editor's do. d: references up two folders. | |
| 249 | 新增: mkdir -p "$SCH/ext/c" | |
| 250 | 新增: echo '{"contributes":{"jsonValidation":[{"fileMatch":"c.json","url":"https://www.schemastore.org/package"},{"fileMatch":"d.json","url":"https://h.test/s/a/b/d.json"}]}}' > "$SCH/ext/c/package.json" | |
| 251 | 新增: echo '{"$id":"https://json.schemastore.org/package.json","properties":{"e":{"$ref":"eslintrc.json#"}}}' > "$SCH/web/$(web https://www.schemastore.org/package)" | |
| 252 | 新增: echo '{"type":"boolean"}' > "$SCH/web/$(web https://www.schemastore.org/eslintrc.json)" | |
| 253 | 新增: echo '{"$ref":"../../c.json"}' > "$SCH/web/$(web https://h.test/s/a/b/d.json)" | |
| 254 | 新增: echo '{"type":"null"}' > "$SCH/web/$(web https://h.test/s/c.json)" | |
| 238 | 255 | out="$( ( curl() { |
| 239 | 删除: local o="" u="" | |
| 240 | 删除: while [ $# -gt 0 ]; do case "$1" in -o) o="$2"; shift 2 ;; -*) shift ;; *) u="$1"; shift ;; esac; done | |
| 241 | 删除: echo "$u" >> "$SCH/fetched" | |
| 242 | 删除: [ -f "$SCH/web/$(web "$u")" ] || return 22 | |
| 243 | 删除: cp "$SCH/web/$(web "$u")" "$o" | |
| 256 | 新增: local o="" st=0 | |
| 257 | 新增: echo call >> "$SCH/calls" | |
| 258 | 新增: while [ $# -gt 0 ]; do | |
| 259 | 新增: case "$1" in | |
| 260 | 新增: -o) o="$2"; shift 2 ;; | |
| 261 | 新增: --parallel-max|--max-time) shift 2 ;; | |
| 262 | 新增: -*) shift ;; | |
| 263 | 新增: *) | |
| 264 | 新增: echo "$1" >> "$SCH/fetched" | |
| 265 | 新增: if [ -f "$SCH/web/$(web "$1")" ]; then cp "$SCH/web/$(web "$1")" "$o"; else st=22; fi | |
| 266 | 新增: shift ;; | |
| 267 | 新增: esac | |
| 268 | 新增: done | |
| 269 | 新增: return "$st" | |
| 244 | 270 | } |
| 245 | 271 | set -euo pipefail |
| 246 | 删除: eval "$(awk '/^code_server_schemas\(\) \{/,/^\}/' "$SETUP_SH")" | |
| 272 | 新增: eval "$(awk '/^(code_server_schemas|schema_url_resolve)\(\) \{/,/^\}/' "$SETUP_SH")" | |
| 247 | 273 | code_server_schemas "$SCH/ext" "$SCH/machine/settings.json"; echo "rc=$?" ) 2>&1)" |
| 248 | 274 | check "every schema named, and every one they refer to, by the URL the editor asks" \ |
| 249 | 275 | "$(jq -r '."json.schemas"[].url' "$SCH/machine/settings.json" 2>/dev/null | sort | tr '\n' ' ')" \ |
| 250 | 删除: "https://h.test/abs.json https://h.test/s/a https://h.test/s/rel.json https://h.test/top.json https://json.schemastore.org/b " | |
| 276 | 新增: "https://h.test/abs.json https://h.test/s/a https://h.test/s/a/b/d.json https://h.test/s/c.json https://h.test/s/rel.json https://h.test/top.json https://json.schemastore.org/b https://json.schemastore.org/eslintrc.json https://www.schemastore.org/package " | |
| 277 | 新增: check "a level of references fetched in one call" "$(wc -l < "$SCH/calls" | tr -d ' ')" "3" | |
| 251 | 278 | check "each with its content" \ |
| 252 | 279 | "$(jq -r '."json.schemas"[] | select(.url == "https://h.test/top.json") | .schema.type' "$SCH/machine/settings.json" 2>/dev/null)" "string" |
| 253 | 280 | check "json.schemastore.org fetched from www.schemastore.org, where it redirects" \ |
| @@ -273,8 +300,8 @@ $(awk '/^if \[\[ "\$INSTALL_CODE_SERVER" == "1" \]\]; then/,/^fi$/' "$SETUP_SH") | ||
| 273 | 300 | $(awk '/^configure_mcp\(\) \{/,/^\}/' "$SETUP_SH")" |
| 274 | 301 | # <home> <claude> <codex> <vibe>: the extensions asked for. |
| 275 | 302 | # Under set -e, as the script runs: a failing step must show here. Twice: |
| 276 | 删除: # setup can be run again on a base. The first run's state is kept in | |
| 277 | 删除: # <home>/first. | |
| 303 | 新增: # what it writes must not pile up when it runs again in the same VM. The | |
| 304 | 新增: # first run's state is kept in <home>/first. | |
| 278 | 305 | run_cs_block() { |
| 279 | 306 | mkdir -p "$1/.config/code-server"; echo "password: from-the-base" > "$1/.config/code-server/config.yaml" |
| 280 | 307 | ( set -e |
| @@ -282,7 +309,7 @@ $(awk '/^configure_mcp\(\) \{/,/^\}/' "$SETUP_SH")" | ||
| 282 | 309 | HAS_CLAUDE="$2" HAS_CODEX="$3" HAS_VIBE="$4" INSTALL_OPENCODE=0 |
| 283 | 310 | curl() { echo "curl $*" >> "$HOME/calls.log"; } |
| 284 | 311 | code-server() { echo "code-server $*" >> "$HOME/calls.log"; } |
| 285 | 删除: code_server_schemas() { echo "schemas $*" >> "$HOME/calls.log"; } | |
| 312 | 新增: code_server_schemas() { echo "schemas $*" >> "$HOME/calls.log"; mkdir -p "$(dirname "$2")"; echo '{"json.schemas":[]}' > "$2"; } | |
| 286 | 313 | eval "$cs_block" |
| 287 | 314 | mkdir -p "$HOME/first" |
| 288 | 315 | for f in .codex/config.toml .vibe/config.toml; do [ ! -f "$HOME/$f" ] || cp "$HOME/$f" "$HOME/first/${f%%/*}"; done |
| @@ -58,9 +58,16 @@ 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 | 新增:case "\$*" in *"json .Config.Mounts"*) printf '%s\n' "\${MT_LIVE:-$1 null}"; exit 0 ;; esac | |
| 62 | 62 | [ "\$1" = list ] && { printf '%s\n' "$1"; exit 0; } |
| 63 | 删除:[ "\$1" = validate ] && [ -n "\${MT_PROTECTS:-}" ] && { echo 'field mounts[*].sshfs.readonlyNames requires mountType to be reverse-sshfs' >&2; exit 1; } | |
| 63 | 新增:if [ "\$1" = validate ]; then | |
| 64 | 新增: if [ -n "\${MT_PROTECTS:-}" ]; then | |
| 65 | 新增: echo 'level=fatal msg="failed to validate YAML file \`probe.yaml\`: field \`mounts[0].sshfs.readonlyNames\` must contain file names, got \`a/b\`"' >&2 | |
| 66 | 新增: exit 1 | |
| 67 | 新增: fi | |
| 68 | 新增: echo 'level=warning msg="Non-strict YAML detected; please check for typos" error="[3:158] unknown field \"readonlyNames\""' >&2 | |
| 69 | 新增: exit 0 | |
| 70 | 新增:fi | |
| 64 | 71 | exit 1 |
| 65 | 72 | STUB |
| 66 | 73 | chmod +x "$SB/bin/limactl" |
| @@ -93,15 +100,38 @@ check "unset on QEMU, no lima-version: reverse-sshfs, not" "$(LIMA_HOME="$SB/lim | ||
| 93 | 100 | # cannot tell the servers apart: the record of the applied mounts does. |
| 94 | 101 | mkdir -p "$HOME/.agent-vm" |
| 95 | 102 | printf '[{"location": "%s", "writable": false, %s}]\n' "$PROJ" "$SSHFS_RO" > "$HOME/.agent-vm/.agent-vm-mounts-agent-vm-t" |
| 96 | 删除:LIVE_OK='reverse-sshfs [{"location":"/p","writable":false,"sshfs":{"cache":false,"sftpDriver":"builtin","readonlyNames":[".git",".hg"]}}]' | |
| 103 | 新增:LIVE_OK='qemu reverse-sshfs [{"location":"/p","writable":false,"sshfs":{"cache":false,"sftpDriver":"builtin","readonlyNames":[".git",".hg"]}}]' | |
| 97 | 104 | check "reverse-sshfs with readonlyNames is" "$(MT_PROTECTS=1 MT_LIVE="$LIVE_OK" mount_types 'qemu reverse-sshfs')" "0" |
| 98 | 105 | # Recorded so, but Lima has a share without them, set outside agent-vm: not. |
| 106 | 新增:# Built apart: bash 3.2 brace-expands {...,...} in a quoted $( ). | |
| 107 | 新增:live="${LIVE_OK%]},{\"location\":\"/elsewhere\",\"writable\":true}]" | |
| 99 | 108 | 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" | |
| 101 | 删除:# Recorded so, but served by a Lima without them (a stock limactl started it | |
| 102 | 删除:# since): not. | |
| 103 | 删除:check "recorded with readonlyNames, a Lima without them: not" "$(mount_types 'qemu reverse-sshfs')" "1" | |
| 109 | 新增: "$(MT_PROTECTS=1 MT_LIVE="$live" mount_types 'qemu reverse-sshfs')" "1" | |
| 110 | 新增:# Recorded so, and so in Lima's config, but served by a Lima without them (a | |
| 111 | 新增:# stock limactl installed since): not. | |
| 112 | 新增:check "recorded with readonlyNames, a Lima without them: not" "$(MT_LIVE="$LIVE_OK" mount_types 'qemu reverse-sshfs')" "1" | |
| 104 | 113 | rm -f "$HOME/.agent-vm/.agent-vm-mounts-agent-vm-t" |
| 114 | 新增: | |
| 115 | 新增:# Each part of Lima's config the protection needs (see | |
| 116 | 新增:# _agent_vm_live_shares_why), and what is said when one is missing. | |
| 117 | 新增:why() { _agent_vm_live_shares_why "$@" >/dev/null && echo ok || echo not; } | |
| 118 | 新增:check "live: every share with the builtin server and the names" "$(why "$LIVE_OK")" "ok" | |
| 119 | 新增:check "live: another mount type" "$(why "${LIVE_OK/reverse-sshfs/virtiofs}")" "not" | |
| 120 | 新增:case "$(_agent_vm_live_shares_why "${LIVE_OK/reverse-sshfs/virtiofs}")" in | |
| 121 | 新增: *"mount type is virtiofs"*) pass "live: and says it is the mount type" ;; | |
| 122 | 新增: *) fail "live: mount type: $(_agent_vm_live_shares_why "${LIVE_OK/reverse-sshfs/virtiofs}")" ;; | |
| 123 | 新增:esac | |
| 124 | 新增:check "live: a share without the builtin server" "$(why "${LIVE_OK/\"sftpDriver\":\"builtin\",/}")" "not" | |
| 125 | 新增:check "live: other names than those asked" "$(why "$LIVE_OK" '[".git", ".hg", "tools"]')" "not" | |
| 126 | 新增:check "live: the names asked" "$(why "$LIVE_OK" '[".git", ".hg"]')" "ok" | |
| 127 | 新增:live='qemu reverse-sshfs [{"location":"/p","sshfs":{"sftpDriver":"builtin","readonlyNames":[".git",".hg","location"]}},{"location":"/q","sshfs":{"sftpDriver":"builtin","readonlyNames":[".git",".hg","location"]}}]' | |
| 128 | 新增:check "live: a name 'location' does not split a share" "$(why "$live" '[".git", ".hg", "location"]')" "ok" | |
| 129 | 新增:check "live: no share at all" "$(why 'vz virtiofs null')" "ok" | |
| 130 | 新增:fields() { local live_vmtype live_mtype live_json; _agent_vm_live_fields "$1" && echo "$live_vmtype|$live_mtype|$live_json" || echo none; } | |
| 131 | 新增:check "live: the three fields" "$(fields 'vz reverse-sshfs [{"location":"/p"}]')" 'vz|reverse-sshfs|[{"location":"/p"}]' | |
| 132 | 新增:check "live: no mount type" "$(fields 'qemu null')|$(fields 'qemu null')" "qemu||null|qemu||null" | |
| 133 | 新增:check "live: no JSON, no answer" "$(fields 'vz virtiofs')" "none" | |
| 134 | 新增:check "live: Lima not answering" "$(why '')" "not" | |
| 105 | 135 | # Restore the shared stub: mount_fstype replaced it with its own. |
| 106 | 136 | cat > "$SB/bin/limactl" <<'STUB' |
| 107 | 137 | #!/usr/bin/env bash |
| @@ -3,19 +3,25 @@ section "commands against a recording limactl" | ||
| 3 | 3 | # ============================================================================= |
| 4 | 4 | # One stub for the sections below. It logs every call, lists the base template |
| 5 | 5 | # and the VM named by AGENT_VM_TEST_VM, and reports its mount type as |
| 6 | 删除:# virtiofs (AGENT_VM_TEST_MOUNTTYPE to change it) on vz (AGENT_VM_TEST_VMTYPE). With AGENT_VM_TEST_CLONED set, | |
| 7 | 删除:# that VM only exists once `clone` has created the file. AGENT_VM_TEST_STOPPED | |
| 8 | 删除:# lists it as stopped, as does a `stop` until the next `start`, and | |
| 9 | 删除:# AGENT_VM_TEST_RO makes the project write probe fail, as a read-only share | |
| 10 | 删除:# would. AGENT_VM_TEST_STOP_FAIL makes `stop` leave it running. | |
| 6 | 新增:# virtiofs (AGENT_VM_TEST_MOUNTTYPE to change it) on vz | |
| 7 | 新增:# (AGENT_VM_TEST_VMTYPE). Lima's config for the VM holds the mounts last set | |
| 8 | 新增:# by `edit` in the run, else those of agent-vm's record; | |
| 9 | 新增:# AGENT_VM_TEST_LIVE_UNPROTECTED adds a share without read-only names to | |
| 10 | 新增:# them, as Lima's _config would. With AGENT_VM_TEST_CLONED set, that VM only | |
| 11 | 新增:# exists once `clone` has created the file. AGENT_VM_TEST_STOPPED lists it as | |
| 12 | 新增:# stopped, as does a `stop` until the next `start`, and AGENT_VM_TEST_RO | |
| 13 | 新增:# makes the project write probe fail, as a read-only share would. | |
| 14 | 新增:# AGENT_VM_TEST_STOP_FAIL makes `stop` leave it running. | |
| 11 | 15 | # AGENT_VM_TEST_SSHFS_FAIL fails the sshfs install of a 0.1.0 VM. |
| 12 | 16 | # AGENT_VM_TEST_RUNTIME_FOUND makes the probe find the project's runtime |
| 13 | 删除:# script. AGENT_VM_TEST_PROBE_LOST makes its write succeed in the VM without | |
| 14 | 删除:# reaching the project, as when the share is not mounted. What is piped into the env push goes to AGENT_VM_TEST_STDIN. | |
| 15 | 删除:# `validate` answers like stock Lima 2.2 does to readonlyNames, or, while the | |
| 16 | 删除:# file $PROTECTS exists, like a Lima that has it (both messages copied from | |
| 17 | 删除:# the real binaries). AGENT_VM_TEST_VALIDATE_SILENT makes it accept the file | |
| 18 | 删除:# without a word, an answer agent-vm cannot read. | |
| 17 | 新增:# script. AGENT_VM_TEST_PROBE_LOST makes the project's share look gone: the | |
| 18 | 新增:# guest does not see the file this machine put there. What is piped into the | |
| 19 | 新增:# env push goes to AGENT_VM_TEST_STDIN. | |
| 20 | 新增:# `validate` answers the probe of _agent_vm_lima_protects_git like stock Lima | |
| 21 | 新增:# 2.2 does, or, while the file $PROTECTS exists, like the fork | |
| 22 | 新增:# (v2.3.0-sylvinus.2): both messages copied from the real binaries. | |
| 23 | 新增:# AGENT_VM_TEST_VALIDATE_SILENT makes it accept the file without a word, an | |
| 24 | 新增:# answer agent-vm cannot read. | |
| 19 | 25 | REC="$SB/rec.log" |
| 20 | 26 | PROTECTS="$SB/lima-protects" |
| 21 | 27 | cat > "$SB/bin/limactl" <<'STUB' |
| @@ -27,7 +33,7 @@ case "$1" in | ||
| 27 | 33 | validate) |
| 28 | 34 | [ -z "${AGENT_VM_TEST_VALIDATE_SILENT:-}" ] || exit 0 |
| 29 | 35 | if [ -e "${AGENT_VM_TEST_PROTECTS:-/nonexistent}" ]; then |
| 30 | 删除: echo 'level=fatal msg="failed to validate YAML file `probe.yaml`: field `mounts[*].sshfs.readonlyNames` requires `mountType` to be `reverse-sshfs`"' >&2 | |
| 36 | 新增: echo 'level=fatal msg="failed to validate YAML file `probe.yaml`: field `mounts[0].sshfs.readonlyNames` must contain file names, got `a/b`"' >&2 | |
| 31 | 37 | exit 1 |
| 32 | 38 | fi |
| 33 | 39 | echo 'level=warning msg="Non-strict YAML detected; please check for typos" error="[3:158] unknown field \"readonlyNames\""' >&2 |
| @@ -35,7 +41,19 @@ case "$1" in | ||
| 35 | 41 | clone) |
| 36 | 42 | [ -z "${AGENT_VM_TEST_CLONE_FAIL:-}" ] || { echo 'level=fatal msg="clone boom"' >&2; exit 1; } |
| 37 | 43 | [ -n "${AGENT_VM_TEST_CLONED:-}" ] && touch "$AGENT_VM_TEST_CLONED" ;; |
| 38 | 删除: edit) [ -z "${AGENT_VM_TEST_EDIT_FAIL:-}" ] || { echo 'level=fatal msg="edit boom"' >&2; exit 1; } ;; | |
| 44 | 新增: # Lima's config then holds the mounts set, until the next run (see rec). | |
| 45 | 新增: edit) | |
| 46 | 新增: [ -z "${AGENT_VM_TEST_EDIT_FAIL:-}" ] || { echo 'level=fatal msg="edit boom"' >&2; exit 1; } | |
| 47 | 新增: expr="" prev="" | |
| 48 | 新增: for a in "$@"; do [ "$prev" = --set ] && expr="$a"; prev="$a"; done | |
| 49 | 新增: case "$expr" in | |
| 50 | 新增: *".mounts = "*) | |
| 51 | 新增: case "$expr" in | |
| 52 | 新增: *'.mountType = "reverse-sshfs"'*) t=reverse-sshfs ;; | |
| 53 | 新增: *) t="${AGENT_VM_TEST_MOUNTTYPE:-virtiofs}" ;; | |
| 54 | 新增: esac | |
| 55 | 新增: printf '%s %s\n' "$t" "$(printf '%s' "${expr#*.mounts = }" | tr -d ' ')" > "$AGENT_VM_TEST_REC.live" ;; | |
| 56 | 新增: esac ;; | |
| 39 | 57 | list) |
| 40 | 58 | case "$*" in |
| 41 | 59 | *"{{.Name}} {{.Config.SSH.LocalPort}}"*) |
| @@ -48,12 +66,22 @@ case "$1" in | ||
| 48 | 66 | # them, unless AGENT_VM_TEST_LIVE_UNPROTECTED adds one set by hand. |
| 49 | 67 | *"{{json .Config.Mounts}}"*) |
| 50 | 68 | r="$HOME/.agent-vm/.agent-vm-mounts-$AGENT_VM_TEST_VM" |
| 51 | 删除: if [ -f "$r" ] && grep -q readonlyNames "$r"; then | |
| 52 | 删除: m="$(tr -d ' ' < "$r")" | |
| 53 | 删除: [ -z "${AGENT_VM_TEST_LIVE_UNPROTECTED:-}" ] || m="${m%]},{\"location\":\"/elsewhere\",\"writable\":true}]" | |
| 54 | 删除: echo "reverse-sshfs $m" | |
| 69 | 新增: extra() { | |
| 70 | 新增: [ -n "${AGENT_VM_TEST_LIVE_UNPROTECTED:-}" ] || { printf '%s\n' "$1"; return; } | |
| 71 | 新增: case "$1" in | |
| 72 | 新增: null|"[]") echo '[{"location":"/elsewhere","writable":true}]' ;; | |
| 73 | 新增: *) printf '%s\n' "${1%]},{\"location\":\"/elsewhere\",\"writable\":true}]" ;; | |
| 74 | 新增: esac | |
| 75 | 新增: } | |
| 76 | 新增: if [ -f "$AGENT_VM_TEST_REC.live" ]; then | |
| 77 | 新增: read -r t m < "$AGENT_VM_TEST_REC.live" | |
| 78 | 新增: echo "${AGENT_VM_TEST_VMTYPE:-vz} ${AGENT_VM_TEST_LIVE_MOUNTTYPE:-$t} $(extra "$m")" | |
| 79 | 新增: elif [ -f "$r" ] && grep -q readonlyNames "$r"; then | |
| 80 | 新增: echo "${AGENT_VM_TEST_VMTYPE:-vz} ${AGENT_VM_TEST_LIVE_MOUNTTYPE:-reverse-sshfs} $(extra "$(tr -d ' ' < "$r")")" | |
| 81 | 新增: elif [ -f "$r" ]; then | |
| 82 | 新增: echo "${AGENT_VM_TEST_VMTYPE:-vz} ${AGENT_VM_TEST_MOUNTTYPE:-virtiofs} $(extra "$(tr -d ' ' < "$r")")" | |
| 55 | 83 | else |
| 56 | 删除: echo "${AGENT_VM_TEST_MOUNTTYPE:-virtiofs} [{\"location\":\"/x\",\"writable\":true}]" | |
| 84 | 新增: echo "${AGENT_VM_TEST_VMTYPE:-vz} ${AGENT_VM_TEST_MOUNTTYPE:-virtiofs} $(extra null)" | |
| 57 | 85 | fi ;; |
| 58 | 86 | *"{{.VMType}}"*) echo "${AGENT_VM_TEST_VMTYPE:-vz} ${AGENT_VM_TEST_MOUNTTYPE:-virtiofs}" ;; |
| 59 | 87 | *"{{.CPUs}}"*"{{.Disk}}"*) listed && echo "$AGENT_VM_TEST_VM|1|3221225472|10737418240" ;; |
| @@ -79,8 +107,8 @@ case "$1" in | ||
| 79 | 107 | [ -n "${AGENT_VM_TEST_ENV_FAIL:-}" ] || echo env-ok |
| 80 | 108 | [ -z "${AGENT_VM_TEST_RUNTIME_FOUND:-}" ] || echo runtime-found ;; |
| 81 | 109 | esac |
| 82 | 删除: [ -z "${AGENT_VM_TEST_RO:-}" ] || exit 1 | |
| 83 | 删除: [ -z "${AGENT_VM_TEST_PROBE_LOST:-}" ] || echo probe-written ;; | |
| 110 | 新增: [ -n "${AGENT_VM_TEST_PROBE_LOST:-}" ] || echo share-ok | |
| 111 | 新增: [ -z "${AGENT_VM_TEST_RO:-}" ] || exit 1 ;; | |
| 84 | 112 | *"exec "*" -s"*) cat >> "${AGENT_VM_TEST_STDIN:-/dev/null}" ;; |
| 85 | 113 | # The editor's prep (lib/code.sh): AGENT_VM_TEST_CODE_PREP is its answer. |
| 86 | 114 | *"agent-vm-code "*) |
| @@ -108,9 +136,11 @@ _agent_vm_check_windows_prereqs() { return 0; } | ||
| 108 | 136 | if _agent_vm_on_windows; then |
| 109 | 137 | _agent_vm_unprotected_mount_is_sshfs() { return 1; } |
| 110 | 138 | fi |
| 139 | 新增:# Each run starts from the record the test wrote: Lima's config follows it | |
| 140 | 新增:# until an edit in the run. | |
| 111 | 141 | rec() { |
| 112 | 142 | : > "$REC" |
| 113 | 删除: rm -f "$REC.stopped" | |
| 143 | 新增: rm -f "$REC.stopped" "$REC.live" | |
| 114 | 144 | ( cd "$PROJ" || exit 1 |
| 115 | 145 | export AGENT_VM_TEST_REC="$REC" AGENT_VM_TEST_VM="$PV" AGENT_VM_TEST_PROTECTS="$PROTECTS" |
| 116 | 146 | agent-vm "$@" </dev/null 2>&1 ) |
| @@ -291,6 +291,30 @@ printf '%s:/mnt/s:rw\n%s:%s:rw\n%s:/mnt/ok:rw\n' "$HOME/.agent-vm" "$SB/vol-ok" | ||
| 291 | 291 | vols_err="$(_agent_vm_build_mounts_json agent-vm-t "$PROJ" 2>&1 >/dev/null)" |
| 292 | 292 | vols="$(_agent_vm_build_mounts_json agent-vm-t "$PROJ" 2>/dev/null)" |
| 293 | 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 | |
| 294 | 新增:case "$vols_err" in *"would be mounted at $(dirname "$PROJ"), which covers the project"*) pass "volumes: a destination above the project is refused" ;; *) fail "volumes: cover: $vols_err" ;; esac | |
| 295 | 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" | |
| 296 | 新增:# Mounted where it is, without a destination: the parent covers the project, | |
| 297 | 新增:# and the project itself would be merged into its share by Lima. Spellings | |
| 298 | 新增:# that are the same place, and two entries at one place, likewise. | |
| 299 | 新增:# A project of its own, under a folder holding nothing else. | |
| 300 | 新增:P2="$SB/cov/proj" | |
| 301 | 新增:mkdir -p "$P2" "$SB/vol-ok" "$SB/vol-ok2" | |
| 302 | 新增:printf '%s:ro\n%s\n%s:%s/./x/..//:rw\n%s:/mnt/d:ro\n%s:/mnt/d/:rw\n' \ | |
| 303 | 新增: "$SB/cov" "$P2" "$SB/vol-ok" "$P2" "$SB/vol-ok" "$SB/vol-ok2" > "$HOME/.agent-vm/volumes" | |
| 304 | 新增:vols_err="$(_agent_vm_volume_entries "$P2" 2>&1 >/dev/null)" | |
| 305 | 新增:vols="$(_agent_vm_volume_entries "$P2" 2>/dev/null)" | |
| 306 | 新增:check "volumes: covering the project or merged with another, whatever the spelling: all refused" \ | |
| 307 | 新增: "$(printf '%s\n' "$vols_err" | grep -c 'covers the project')/$(printf '%s\n' "$vols_err" | grep -c 'as an entry before it')" "3/1" | |
| 308 | 新增:check "volumes: the first at a place is kept, its destination normalized" "$vols" "$SB/vol-ok|/mnt/d|ro|$SB/vol-ok:/mnt/d:ro" | |
| 309 | 新增:rm -rf "$SB/vol-ok" "$SB/vol-ok2" "$SB/cov" "$HOME/.agent-vm/volumes" | |
| 310 | 新增:# A repository's own folder: refused writable, where the VM would write its | |
| 311 | 新增:# hooks and config, not read-only. | |
| 312 | 新增:mkdir -p "$SB/bare.git/objects" "$SB/bare.git/refs" && : > "$SB/bare.git/HEAD" | |
| 313 | 新增:printf '%s:/mnt/b:rw\n' "$SB/bare.git" > "$HOME/.agent-vm/volumes" | |
| 314 | 新增:case "$(_agent_vm_volume_entries "$PROJ" 2>&1)" in *"a git repository's own folder"*) pass "volumes: a bare repository, writable: refused" ;; *) fail "volumes: bare rw: $(_agent_vm_volume_entries "$PROJ" 2>&1)" ;; esac | |
| 315 | 新增:printf '%s:/mnt/b:ro\n' "$SB/bare.git" > "$HOME/.agent-vm/volumes" | |
| 316 | 新增:check "volumes: read-only: kept" "$(_agent_vm_volume_entries "$PROJ" 2>/dev/null)" "$SB/bare.git|/mnt/b|ro|$SB/bare.git:/mnt/b:ro" | |
| 317 | 新增:rm -rf "$SB/bare.git" "$HOME/.agent-vm/volumes" | |
| 318 | 新增:mkdir -p "$PROJ/inner.git/objects" "$PROJ/inner.git/refs" && : > "$PROJ/inner.git/HEAD" | |
| 319 | 新增:check "a bare repository as the project" "$(refused "$PROJ/inner.git")" "refused" | |
| 320 | 新增:rm -rf "$PROJ/inner.git" | |
| @@ -143,6 +143,11 @@ case "$out" in *"could not install sshfs"*"E: no sshfs"*"rc=1") pass "0.1.0 VM, | ||
| 143 | 143 | rec_has "reverse-sshfs" && fail "0.1.0 VM, install failed: shares changed" || pass "0.1.0 VM, install failed: no protected shares" |
| 144 | 144 | rec_has "agent-vm-write-probe" && fail "0.1.0 VM, install failed: the command ran" || pass "0.1.0 VM, install failed: the command did not run" |
| 145 | 145 | [ -e "$MIGRATED" ] && fail "0.1.0 VM, install failed: recorded as migrated" || pass "0.1.0 VM, install failed: tried again next time" |
| 146 | 新增:# The boot without shares has none from Lima's _config either. | |
| 147 | 新增:old_vm | |
| 148 | 新增:out="$(AGENT_VM_TEST_STOPPED=1 AGENT_VM_TEST_LIVE_UNPROTECTED=1 rec run true; echo "rc=$?")" | |
| 149 | 新增:case "$out" in *"shares agent-vm did not ask for"*"rc=1") pass "0.1.0 VM: a share from Lima's _config stops the boot without shares" ;; *) fail "0.1.0 VM, _config: $out" ;; esac | |
| 150 | 新增:rec_has "start $PV" && fail "0.1.0 VM, _config: started anyway" || pass "0.1.0 VM, _config: not started" | |
| 146 | 151 | |
| 147 | 152 | old_vm |
| 148 | 153 | rm -f "$PROTECTS" |
| @@ -331,25 +336,60 @@ _agent_vm_mounts_have_readonly_names "$PV" '[".git", ".hg"]' && pass "names: rec | ||
| 331 | 336 | out="$(AGENT_VM_TEST_STOPPED=1 rec run true)" |
| 332 | 337 | rec_has "edit $PV" && fail "names: edited again with nothing to change" || pass "names: nothing to change the next time" |
| 333 | 338 | |
| 334 | 删除:# Shares from before sshfs's cache was off: set again while stopped, never | |
| 335 | 删除:# a reason to restart a running VM. | |
| 339 | 新增:# Shares from before sshfs's cache was off (no cache mode recorded): set | |
| 340 | 新增:# again while stopped, never a reason to restart a running VM. | |
| 341 | 新增:CACHE_MODE="$HOME/.agent-vm/.agent-vm-sshfs-cache-$PV" | |
| 336 | 342 | names_rec '[".git", ".hg"]' |
| 343 | 新增:rm -f "$CACHE_MODE" | |
| 337 | 344 | out="$(rec run true)" |
| 338 | 345 | rec_has "edit $PV" && fail "cache: a running VM was changed" || pass "cache: a running VM is left as it is" |
| 339 | 346 | rec_has "stop $PV" && fail "cache: a running VM was stopped" || pass "cache: and not stopped" |
| 340 | 删除:names_rec '[".git", ".hg"]' | |
| 347 | 新增:case "$out" in *Warning*) fail "cache: a running VM warned about: $out" ;; *) pass "cache: and nothing said" ;; esac | |
| 341 | 348 | AGENT_VM_TEST_STOPPED=1 rec run true >/dev/null |
| 342 | 349 | rec_has "edit $PV --set .mountType = \"reverse-sshfs\" | .mounts = [{$(mnt "$PROJ"), \"writable\": true, $SSHFS_RO}]" \ |
| 343 | 350 | && pass "cache: a stopped VM gets its shares with the cache off" || fail "cache: not updated: $(grep '^edit' "$REC")" |
| 344 | 删除:_agent_vm_mounts_cache_off "$PV" && pass "cache: recorded" || fail "cache: record: $(cat "$REC_MOUNTS")" | |
| 351 | 新增:_agent_vm_mounts_sshfs_current "$PV" && pass "cache: recorded" || fail "cache: record: $(cat "$CACHE_MODE" 2>/dev/null)" | |
| 352 | 新增:# AGENT_VM_SSHFS_CACHE=1: the cache on, everywhere, the next time it starts. | |
| 353 | 新增:AGENT_VM_SSHFS_CACHE=1 AGENT_VM_TEST_STOPPED=1 rec run true >/dev/null | |
| 354 | 新增:rec_has "edit $PV --set .mountType = \"reverse-sshfs\" | .mounts = [{$(mnt "$PROJ"), \"writable\": true, \"sshfs\": {\"sftpDriver\": \"builtin\", \"readonlyNames\": [\".git\", \".hg\"]}}]" \ | |
| 355 | 新增: && pass "cache: AGENT_VM_SSHFS_CACHE=1 turns it on" || fail "cache: flag: $(grep '^edit' "$REC")" | |
| 356 | 新增:AGENT_VM_TEST_STOPPED=1 rec run true >/dev/null | |
| 357 | 新增:rec_has "\"cache\": false" && pass "cache: and without it, off again" || fail "cache: back off: $(grep '^edit' "$REC")" | |
| 345 | 358 | |
| 346 | 359 | # A share in Lima's config without the names, set outside agent-vm (by hand, |
| 347 | 360 | # or from Lima's _config): the record cannot be trusted. |
| 348 | 361 | out="$(AGENT_VM_TEST_LIVE_UNPROTECTED=1 rec run true)" |
| 349 | 362 | 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 | 363 | 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 | |
| 364 | 新增:case "$out" in *"would boot with .git writable: the share of /elsewhere lacks the read-only names"*"'mounts' in"*"_config/override.yaml"*"rc=1") pass "live: a stopped VM keeping one after its edit is not started" ;; *) fail "live, stopped: $out" ;; esac | |
| 352 | 365 | rec_has "start $PV" && fail "live: started anyway" || pass "live: and not started" |
| 366 | 新增:# Another mount type from Lima's _config: said as such. | |
| 367 | 新增:out="$(AGENT_VM_TEST_LIVE_MOUNTTYPE=virtiofs AGENT_VM_TEST_STOPPED=1 rec run true; echo "rc=$?")" | |
| 368 | 新增:case "$out" in *"mount type is virtiofs"*"'mountType' in"*"rc=1") pass "live: another mount type is named" ;; *) fail "live, mount type: $out" ;; esac | |
| 369 | 新增:# Nor through the restart of a repair: every boot is checked. | |
| 370 | 新增:out="$(AGENT_VM_TEST_LIVE_UNPROTECTED=1 AGENT_VM_TEST_PROBE_LOST=1 rec run true; echo "rc=$?")" | |
| 371 | 新增:case "$out" in *"would boot with .git writable"*"rc=1") pass "live: a repair restart is checked too" ;; *) fail "live, repair: $out" ;; esac | |
| 372 | 新增:rec_has "start $PV" && fail "live: the repair started it anyway" || pass "live: and the repair does not start it" | |
| 373 | 新增:# --readonly with a writable share from Lima's _config: refused. | |
| 374 | 新增:ro_rec_live() { printf '[{"location": "%s", "writable": false, %s}]\n' "$PROJ" "${SSHFS_RO/, \"cache\": false/}" > "$REC_MOUNTS"; } | |
| 375 | 新增:ro_rec_live | |
| 376 | 新增:out="$(AGENT_VM_TEST_LIVE_UNPROTECTED=1 AGENT_VM_TEST_RO=1 AGENT_VM_TEST_MOUNTTYPE=reverse-sshfs rec --readonly run true; echo "rc=$?")" | |
| 377 | 新增:case "$out" in *"Read-only: the project and every other share"*) fail "--readonly claimed with a writable share: $out" ;; *"rc=1") pass "--readonly: a writable share from Lima's _config is refused" ;; *) fail "--readonly, live: $out" ;; esac | |
| 378 | 新增:# The same on vz with virtiofs, enforced on the host, and a stock Lima. | |
| 379 | 新增:rm -f "$PROTECTS" | |
| 380 | 新增:printf '[{"location": "%s", "writable": false}]\n' "$PROJ" > "$REC_MOUNTS" | |
| 381 | 新增:out="$(AGENT_VM_TEST_LIVE_UNPROTECTED=1 AGENT_VM_TEST_RO=1 rec --readonly run true; echo "rc=$?")" | |
| 382 | 新增:case "$out" in *"Lima gives VM '$PV' a writable share agent-vm did not set"*"rc=1") pass "--readonly on virtiofs: a writable share from Lima's _config is refused" ;; *) fail "--readonly, virtiofs, live: $out" ;; esac | |
| 383 | 新增:out="$(AGENT_VM_TEST_RO=1 rec --readonly run true; echo "rc=$?")" | |
| 384 | 新增:case "$out" in *"Read-only: the project and every other share"*"rc=0") pass "--readonly on virtiofs: and without it, enforced" ;; *) fail "--readonly, virtiofs: $out" ;; esac | |
| 385 | 新增:touch "$PROTECTS" | |
| 386 | 新增:# doctor tells the same as a start. | |
| 387 | 新增:names_rec '[".git", ".hg"]' | |
| 388 | 新增:out="$(AGENT_VM_TEST_LIVE_UNPROTECTED=1 rec doctor)" | |
| 389 | 新增:case "$out" in *"warn its shares were given the read-only names, but .git is not read-only: the share of /elsewhere lacks"*) pass "doctor: a share without the names in Lima's config" ;; *) fail "doctor: live: $out" ;; esac | |
| 390 | 新增:out="$(rec doctor)" | |
| 391 | 新增:case "$out" in *"ok its shares keep every .git read-only"*) pass "doctor: and without it, ok" ;; *) fail "doctor: protected: $out" ;; esac | |
| 392 | 新增:names_rec '[".git", ".hg"]' | |
| 353 | 393 | |
| 354 | 394 | # A running VM served by another binary than the limactl on PATH (a stock |
| 355 | 395 | # Lima that ignores the names): its pid file points to that process. |
| @@ -357,14 +397,40 @@ if _agent_vm_on_windows; then | ||
| 357 | 397 | printf ' skip the limactl serving a running VM (not told on Windows)\n' |
| 358 | 398 | else |
| 359 | 399 | names_rec '[".git", ".hg"]' |
| 360 | 删除: printf '%s\n' "$(cat "$REC_MOUNTS" | sed 's/"readonlyNames"/"cache": false, "readonlyNames"/')" > "$REC_MOUNTS" | |
| 361 | 400 | mkdir -p "$(_agent_vm_lima_home)/$PV" |
| 362 | 401 | : > "$(_agent_vm_lima_home)/$PV/lima.yaml" |
| 363 | 402 | sleep 30 & other_pid=$! |
| 364 | 403 | echo "$other_pid" > "$(_agent_vm_lima_home)/$PV/ha.pid" |
| 365 | 404 | out="$(rec run true)" |
| 366 | 405 | case "$out" in *"was started by another limactl"*"is running with .git writable"*) pass "hostagent: a VM another limactl runs is not taken as protected" ;; *) fail "hostagent: $out" ;; esac |
| 406 | 新增: # --readonly does not take it as enforced either. | |
| 407 | 新增: ro_rec_live | |
| 408 | 新增: out="$(AGENT_VM_TEST_RO=1 AGENT_VM_TEST_MOUNTTYPE=reverse-sshfs rec --readonly run true; echo "rc=$?")" | |
| 409 | 新增: case "$out" in *"Read-only: the project and every other share"*) fail "hostagent: --readonly claimed: $out" ;; *"rc=1") pass "hostagent: --readonly is refused" ;; *) fail "hostagent, --readonly: $out" ;; esac | |
| 410 | 新增: names_rec '[".git", ".hg"]' | |
| 367 | 411 | kill "$other_pid" 2>/dev/null; wait "$other_pid" 2>/dev/null |
| 412 | 新增: # The limactl on PATH serving it: here a copy of bash standing for it (any | |
| 413 | 新增: # name runs it, unlike a multi-call busybox), run through a link as | |
| 414 | 新增: # Homebrew installs it. Then that file replaced by the same build while it | |
| 415 | 新增: # runs (an upgrade to the same version), then by another one. | |
| 416 | 新增: if [ -e /proc/self/exe ]; then | |
| 417 | 新增: mkdir -p "$SB/ha-bin" "$SB/ha-link" | |
| 418 | 新增: cp "$BASH" "$SB/ha-bin/limactl" | |
| 419 | 新增: ln -sf "$SB/ha-bin/limactl" "$SB/ha-link/limactl" | |
| 420 | 新增: "$SB/ha-link/limactl" -c 'sleep 30; :' & other_pid=$! | |
| 421 | 新增: echo "$other_pid" > "$(_agent_vm_lima_home)/$PV/ha.pid" | |
| 422 | 新增: ha() { ( PATH="$SB/ha-link:$PATH"; _agent_vm_hostagent_is_limactl "$PV" && echo same || echo other ); } | |
| 423 | 新增: check "hostagent: the stand-in for the hostagent runs" "$(kill -0 "$other_pid" 2>/dev/null && echo yes)" "yes" | |
| 424 | 新增: check "hostagent: the limactl on PATH, through a link" "$(ha)" "same" | |
| 425 | 新增: rm "$SB/ha-bin/limactl" && cp "$BASH" "$SB/ha-bin/limactl" | |
| 426 | 新增: check "hostagent: its file replaced by the same build since" "$(ha)" "same" | |
| 427 | 新增: rm "$SB/ha-bin/limactl" && printf '#!/bin/sh\necho limactl version 9\n' > "$SB/ha-bin/limactl" && chmod +x "$SB/ha-bin/limactl" | |
| 428 | 新增: check "hostagent: by another build" "$(ha)" "other" | |
| 429 | 新增: kill "$other_pid" 2>/dev/null; wait "$other_pid" 2>/dev/null | |
| 430 | 新增: rm -rf "$SB/ha-bin" "$SB/ha-link" | |
| 431 | 新增: else | |
| 432 | 新增: printf ' skip the limactl serving a running VM, same build (no /proc here)\n' | |
| 433 | 新增: fi | |
| 368 | 434 | rm -f "$(_agent_vm_lima_home)/$PV/ha.pid" "$(_agent_vm_lima_home)/$PV/lima.yaml" |
| 369 | 435 | out="$(rec run true)" |
| 370 | 436 | case "$out" in *"another limactl"*) fail "hostagent: no pid file, warned anyway" ;; *) pass "hostagent: when it cannot tell, nothing is said" ;; esac |
| @@ -432,7 +498,7 @@ if command -v git >/dev/null 2>&1; then | ||
| 432 | 498 | mkdir -p "$PROJ/lib/inner" |
| 433 | 499 | ( git -C "$PROJ/lib/inner" init -q && git -C "$PROJ/lib/inner" config core.hooksPath .githooks ) |
| 434 | 500 | check "hooks: a nested repository's folder joins the names" "$(names)" '[".git", ".hg", ".husky", ".githooks"]' |
| 435 | 删除: case "$(_agent_vm_project_hooks "$PROJ")" in *"lib/inner/.githooks"*) pass "hooks: named from the project" ;; *) fail "hooks: nested: $(_agent_vm_project_hooks "$PROJ")" ;; esac | |
| 501 | 新增: case "$(_agent_vm_share_hooks "$PROJ")" in *"lib/inner/.githooks"*) pass "hooks: named from the project" ;; *) fail "hooks: nested: $(_agent_vm_share_hooks "$PROJ")" ;; esac | |
| 436 | 502 | names_rec '[".git", ".hg"]' |
| 437 | 503 | AGENT_VM_TEST_STOPPED=1 rec run true >/dev/null |
| 438 | 504 | rec_has "\"readonlyNames\": [\".git\", \".hg\", \".husky\", \".githooks\"]}}]" \ |
| @@ -455,19 +521,56 @@ if command -v git >/dev/null 2>&1; then | ||
| 455 | 521 | check "hooks: core.hooksPath linked elsewhere in the project: both names" "$(names)" '[".git", ".hg", ".githooks", "scripts"]' |
| 456 | 522 | ( git -C "$PROJ" config --unset core.hooksPath ) |
| 457 | 523 | rm "$PROJ/.githooks" |
| 524 | 新增: risks() { _agent_vm_share_config_risks "$PROJ"; } | |
| 458 | 525 | printf '#!/bin/sh\n' > "$PROJ/scripts/pre-commit" |
| 526 | 新增: printf '#!/bin/sh\n' > "$SB/elsewhere-hook" | |
| 459 | 527 | ln -s ../../scripts/pre-commit "$PROJ/.git/hooks/pre-commit" |
| 460 | 528 | ln -s "$SB/elsewhere-hook" "$PROJ/.git/hooks/post-commit" |
| 461 | 删除: case "$(_agent_vm_project_config_risks "$PROJ")" in | |
| 529 | 新增: case "$(risks)" in | |
| 462 | 530 | *"hook pre-commit runs scripts/pre-commit"*) pass "hooks: a hook linked to a file of the project is a risk" ;; |
| 463 | 删除: *) fail "hooks: linked hook: $(_agent_vm_project_config_risks "$PROJ")" ;; | |
| 531 | 新增: *) fail "hooks: linked hook: $(risks)" ;; | |
| 464 | 532 | esac |
| 465 | 删除: case "$(_agent_vm_project_config_risks "$PROJ")" in | |
| 533 | 新增: case "$(risks)" in | |
| 466 | 534 | *post-commit*) fail "hooks: a link out of the project counted as a risk" ;; |
| 467 | 535 | *) pass "hooks: and one linked out of it is not" ;; |
| 468 | 536 | esac |
| 469 | 删除: rm -f "$PROJ/.git/hooks/pre-commit" "$PROJ/.git/hooks/post-commit" | |
| 470 | 删除: rm -rf "$PROJ/scripts" | |
| 537 | 新增: # Not there yet: the VM can create it. | |
| 538 | 新增: ln -s ../../later/pre-push "$PROJ/.git/hooks/pre-push" | |
| 539 | 新增: case "$(risks)" in *"hook pre-push runs later/pre-push"*) pass "hooks: a hook linked to a file of the project not there yet" ;; *) fail "hooks: dangling: $(risks)" ;; esac | |
| 540 | 新增: # Through a link in the project to a file outside it: the VM can change | |
| 541 | 新增: # the link. | |
| 542 | 新增: ln -s "$SB/elsewhere-hook" "$PROJ/scripts/relay" | |
| 543 | 新增: ln -s ../../scripts/relay "$PROJ/.git/hooks/post-merge" | |
| 544 | 新增: case "$(risks)" in *"hook post-merge runs scripts/relay"*) pass "hooks: a hook reached through a link in the project" ;; *) fail "hooks: chain: $(risks)" ;; esac | |
| 545 | 新增: # Out of the project, then back into it. | |
| 546 | 新增: ln -s "$PROJ/scripts/pre-commit" "$SB/back-link" | |
| 547 | 新增: ln -s "$SB/back-link" "$PROJ/.git/hooks/pre-rebase" | |
| 548 | 新增: case "$(risks)" in *"hook pre-rebase runs scripts/pre-commit"*) pass "hooks: a hook linked out of the project and back" ;; *) fail "hooks: back: $(risks)" ;; esac | |
| 549 | 新增: rm -f "$PROJ/.git/hooks/pre-commit" "$PROJ/.git/hooks/post-commit" "$PROJ/.git/hooks/pre-push" "$PROJ/.git/hooks/post-merge" \ | |
| 550 | 新增: "$PROJ/.git/hooks/pre-rebase" "$SB/back-link" | |
| 551 | 新增: # The hooks folder itself linked to a folder not there yet, or through a | |
| 552 | 新增: # link in the project to one outside it. | |
| 553 | 新增: mv "$PROJ/.git/hooks" "$SB/hooks-saved" | |
| 554 | 新增: ln -s ../tools/hooks "$PROJ/.git/hooks" | |
| 555 | 新增: check "hooks: .git/hooks linked to a folder of the project not there yet" "$(names)" '[".git", ".hg", "tools"]' | |
| 556 | 新增: rm "$PROJ/.git/hooks" | |
| 557 | 新增: mkdir -p "$SB/shared-hooks" | |
| 558 | 新增: ln -s "$SB/shared-hooks" "$PROJ/scripts/hooks-relay" | |
| 559 | 新增: ln -s ../scripts/hooks-relay "$PROJ/.git/hooks" | |
| 560 | 新增: check "hooks: .git/hooks through a link in the project to a folder outside" "$(names)" '[".git", ".hg", "scripts"]' | |
| 561 | 新增: rm "$PROJ/.git/hooks" | |
| 562 | 新增: mv "$SB/hooks-saved" "$PROJ/.git/hooks" | |
| 563 | 新增: # A hook linked to another in its own folder, which its name keeps | |
| 564 | 新增: # read-only: no risk. | |
| 565 | 新增: mkdir -p "$PROJ/.githooks" | |
| 566 | 新增: printf '#!/bin/sh\n' > "$PROJ/.githooks/post-merge" | |
| 567 | 新增: ln -s post-merge "$PROJ/.githooks/post-rewrite" | |
| 568 | 新增: hp .githooks | |
| 569 | 新增: case "$(risks)" in *post-rewrite*) fail "hooks: a link inside a protected hooks folder counted as a risk: $(risks)" ;; *) pass "hooks: a link inside a protected hooks folder is no risk" ;; esac | |
| 570 | 新增: # A name of a hook printed as is: control characters made visible. | |
| 571 | 新增: ln -s ../scripts/pre-commit "$PROJ/.githooks/$(printf 'a\033]0;x\007b')" | |
| 572 | 新增: case "$(risks)" in *$'\033'*) fail "hooks: a control character printed" ;; *"hook a?]0;x?b runs scripts/pre-commit"*) pass "hooks: control characters in a hook's name made visible" ;; *) fail "hooks: control: $(risks | cat -v)" ;; esac | |
| 573 | 新增: rm -rf "$PROJ/.githooks" "$PROJ/scripts" "$SB/shared-hooks" "$SB/elsewhere-hook" | |
| 471 | 574 | hp .husky/_ |
| 472 | 575 | else |
| 473 | 576 | printf ' skip hooks through symlinks (no symlinks here)\n' |
| @@ -483,13 +586,54 @@ if command -v git >/dev/null 2>&1; then | ||
| 483 | 586 | check "volumes: a writable volume's hooks folder joins the names" "$(names)" '[".git", ".hg", ".husky", "tools"]' |
| 484 | 587 | 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 | 588 | case "$(_agent_vm_share_config_risks "$PROJ")" in |
| 486 | 删除: *"$VREPO: core.fsmonitor = ./fsmon.sh"*) pass "volumes: its config naming a command in it is a risk" ;; | |
| 589 | 新增: *"core.fsmonitor = ./fsmon.sh"*) pass "volumes: its config naming a command in it is a risk" ;; | |
| 487 | 590 | *) fail "volumes: risks: $(_agent_vm_share_config_risks "$PROJ")" ;; |
| 488 | 591 | esac |
| 489 | 592 | printf '%s:/mnt/vrepo:ro\n' "$VREPO" > "$HOME/.agent-vm/volumes" |
| 490 | 593 | check "volumes: a read-only volume adds nothing" "$(names)" '[".git", ".hg", ".husky"]' |
| 491 | 594 | [ -z "$(_agent_vm_share_config_risks "$PROJ")" ] && pass "volumes: nor risks" || fail "volumes: ro risks: $(_agent_vm_share_config_risks "$PROJ")" |
| 492 | 删除: rm -rf "$VREPO" "$HOME/.agent-vm/volumes" | |
| 595 | 新增: rm -rf "$VREPO" | |
| 596 | 新增: # From one share into another: the project's git config naming a command, | |
| 597 | 新增: # a hooks folder or a config file in a writable volume that is no | |
| 598 | 新增: # repository, and git's own config in one. | |
| 599 | 新增: VOL="$SB/teamtools" | |
| 600 | 新增: mkdir -p "$VOL/hooks" | |
| 601 | 新增: printf '%s:/mnt/teamtools:rw\n' "$VOL" > "$HOME/.agent-vm/volumes" | |
| 602 | 新增: ( git -C "$PROJ" config core.fsmonitor "$VOL/fsmon.sh" && git -C "$PROJ" config include.path "$VOL/gitconfig" ) | |
| 603 | 新增: case "$(_agent_vm_share_config_risks "$PROJ")" in | |
| 604 | 新增: *"core.fsmonitor = $VOL/fsmon.sh"*"config file $VOL/gitconfig"*|*"config file $VOL/gitconfig"*"core.fsmonitor = $VOL/fsmon.sh"*) | |
| 605 | 新增: pass "volumes: the project's config naming a command and a file in a volume" ;; | |
| 606 | 新增: *) fail "volumes: cross: $(_agent_vm_share_config_risks "$PROJ")" ;; | |
| 607 | 新增: esac | |
| 608 | 新增: ( git -C "$PROJ" config --unset core.fsmonitor; git -C "$PROJ" config --unset include.path ) | |
| 609 | 新增: hp "$VOL/hooks" | |
| 610 | 新增: check "volumes: the project's hooks folder in a volume is named from it" "$(names)" '[".git", ".hg", "hooks"]' | |
| 611 | 新增: hp .husky/_ | |
| 612 | 新增: mkdir -p "$VOL/git" | |
| 613 | 新增: printf '[core]\n\tfsmonitor = %s/fsmon.sh\n' "$VOL" > "$VOL/git/config" | |
| 614 | 新增: case "$( XDG_CONFIG_HOME="$VOL" _agent_vm_share_config_risks "$PROJ" )" in | |
| 615 | 新增: *"config file $VOL/git/config"*) pass "volumes: git's own config kept in a volume" ;; | |
| 616 | 新增: *) fail "volumes: global: $( XDG_CONFIG_HOME="$VOL" _agent_vm_share_config_risks "$PROJ" )" ;; | |
| 617 | 新增: esac | |
| 618 | 新增: # A volume reached through a symlink is searched all the same. | |
| 619 | 新增: mkdir -p "$SB/data/code/app" | |
| 620 | 新增: ln -s "$SB/data/code" "$SB/code-link" | |
| 621 | 新增: ( git -C "$SB/data/code/app" init -q && git -C "$SB/data/code/app" config core.hooksPath .husky/_ ) | |
| 622 | 新增: printf '%s:/mnt/code:rw\n' "$SB/code-link" > "$HOME/.agent-vm/volumes" | |
| 623 | 新增: case "$(_agent_vm_share_hooks "$PROJ")" in *"$SB/data/code/app/.husky/_"*) pass "volumes: a volume through a symlink is searched" ;; *) fail "volumes: symlinked: $(_agent_vm_share_hooks "$PROJ")" ;; esac | |
| 624 | 新增: # The project inside a writable volume: each folder once, named from the | |
| 625 | 新增: # project. | |
| 626 | 新增: mkdir -p "$SB/up/app" | |
| 627 | 新增: ( git -C "$SB/up/app" init -q && git -C "$SB/up/app" config core.hooksPath .husky/_ ) | |
| 628 | 新增: printf '%s:/mnt/up:rw\n' "$SB/up" > "$HOME/.agent-vm/volumes" | |
| 629 | 新增: check "volumes: the project inside one: each hooks folder once" "$(_agent_vm_share_hooks "$SB/up/app")" "$(printf '.husky/_\t.husky/_')" | |
| 630 | 新增: rm -rf "$SB/up" | |
| 631 | 新增: # A bare repository in a writable volume: its own folder is named. | |
| 632 | 新增: mkdir -p "$SB/remotes" | |
| 633 | 新增: ( git init -q --bare "$SB/remotes/proj.git" ) | |
| 634 | 新增: printf '%s:/mnt/remotes:rw\n' "$SB/remotes" > "$HOME/.agent-vm/volumes" | |
| 635 | 新增: check "volumes: a bare repository in one is protected by its name" "$(names)" '[".git", ".hg", ".husky", "proj.git"]' | |
| 636 | 新增: rm -rf "$VOL" "$SB/data" "$SB/code-link" "$SB/remotes" "$HOME/.agent-vm/volumes" | |
| 493 | 637 | |
| 494 | 638 | # A name that is not a dot-name is read-only in every folder of the |
| 495 | 639 | # project, so it is asked first: yes by default, and when no one can answer. |
| @@ -548,12 +692,12 @@ if command -v git >/dev/null 2>&1; then | ||
| 548 | 692 | git -C "$PROJ" config core.pager less |
| 549 | 693 | git -C "$PROJ" config core.sshCommand "ssh -o ProxyCommand=/usr/bin/nc" |
| 550 | 694 | git -C "$PROJ" config alias.st status ) |
| 551 | 删除: check "config: nothing in the project, nothing said" "$(_agent_vm_project_config_risks "$PROJ")" "" | |
| 695 | 新增: check "config: nothing in the project, nothing said" "$(_agent_vm_share_config_risks "$PROJ")" "" | |
| 552 | 696 | ( printf '[core]\n\tfsmonitor = ./watch.sh\n' > "$PROJ/.gitconfig" |
| 553 | 697 | git -C "$PROJ" config include.path ../.gitconfig |
| 554 | 698 | git -C "$PROJ" config filter.x.clean "scripts/clean.sh %f" |
| 555 | 699 | git -C "$PROJ" config alias.t '!./t.sh' ) |
| 556 | 删除: risks="$(_agent_vm_project_config_risks "$PROJ")" | |
| 700 | 新增: risks="$(_agent_vm_share_config_risks "$PROJ")" | |
| 557 | 701 | case "$risks" in *"config file .gitconfig"*) pass "config: an included file in the project" ;; *) fail "config: include: $risks" ;; esac |
| 558 | 702 | case "$risks" in *"core.fsmonitor = ./watch.sh"*) pass "config: a command it sets" ;; *) fail "config: fsmonitor: $risks" ;; esac |
| 559 | 703 | case "$risks" in *"filter.x.clean = scripts/clean.sh %f"*) pass "config: a relative command path" ;; *) fail "config: filter: $risks" ;; esac |
| @@ -565,7 +709,7 @@ if command -v git >/dev/null 2>&1; then | ||
| 565 | 709 | ( git -C "$PROJ" config includeIf.gitdir:/.path ../later.gitconfig |
| 566 | 710 | git -C "$PROJ" config --add include.path ../.git/x.gitconfig |
| 567 | 711 | git -C "$PROJ" config --add include.path "$SB/outside.gitconfig" ) |
| 568 | 删除: risks="$(_agent_vm_project_config_risks "$PROJ")" | |
| 712 | 新增: risks="$(_agent_vm_share_config_risks "$PROJ")" | |
| 569 | 713 | case "$risks" in *"config file later.gitconfig"*) pass "config: an include of a file not there yet" ;; *) fail "config: missing include: $risks" ;; esac |
| 570 | 714 | case "$risks" in *x.gitconfig*|*outside.gitconfig*) fail "config: an include in .git or outside the project listed: $risks" ;; *) pass "config: includes in .git or outside left out" ;; esac |
| 571 | 715 | ( git -C "$PROJ" config --unset-all includeIf.gitdir:/.path |
| @@ -34,23 +34,9 @@ esac | ||
| 34 | 34 | exit 0 |
| 35 | 35 | STUB |
| 36 | 36 | chmod +x "$SB/wizlima/limactl" |
| 37 | 删除:( PATH="$SB/wizlima:$PATH"; AGENT_VM_STATE_DIR="$SB/wizstate" | |
| 38 | 删除: _agent_vm_have_tty() { return 0; } | |
| 39 | 删除: _agent_vm_ask_yn() { | |
| 40 | 删除: case "$1" in | |
| 41 | 删除: "Use this default") echo 0 ;; | |
| 42 | 删除: "Use these defaults") echo 1 ;; | |
| 43 | 删除: *) case "$2" in [Yy]) echo 1 ;; *) echo 0 ;; esac ;; | |
| 44 | 删除: esac | |
| 45 | 删除: } | |
| 46 | 删除: _agent_vm_offer_git_protection() { :; } | |
| 47 | 删除: _agent_vm_setup ) >/dev/null 2>&1 | |
| 48 | 删除:check "wizard defaults: Ruby, Rust, Go, Pi and Playwright MCP off; Claude on" \ | |
| 49 | 删除: "$(grep -E '^export AGENT_VM_INSTALL_(RUBY|RUST|GOLANG|PI|MCP_PLAYWRIGHT|CLAUDE)=' "$SB/wizard.stdin" 2>/dev/null | cut -d_ -f4- | tr '\n' ' ')" \ | |
| 50 | 删除: "RUBY=0 RUST=0 GOLANG=0 CLAUDE=1 PI=0 MCP_PLAYWRIGHT=0 " | |
| 51 | 删除: | |
| 52 | 删除:section "setup wizard: 4 GB of memory with code-server" | |
| 53 | 删除:# CODE=1 answers yes to code-server. The host is big enough not to clamp. | |
| 37 | 新增:# The wizard, every question answered with its default but those set: | |
| 38 | 新增:# DEFAULT_SOFTWARE=1 takes the default set, CODE=1 picks code-server. The | |
| 39 | 新增:# host is big enough not to clamp the memory, printed after. | |
| 54 | 40 | wiz_memory() { |
| 55 | 41 | rm -f "$SB/wizard.create" |
| 56 | 42 | ( PATH="$SB/wizlima:$PATH"; AGENT_VM_STATE_DIR="$SB/wizstate" |
| @@ -69,6 +55,12 @@ wiz_memory() { | ||
| 69 | 55 | _agent_vm_setup "$@" ) >/dev/null 2>&1 |
| 70 | 56 | grep -o -- '--memory=[0-9]*' "$SB/wizard.create" 2>/dev/null |
| 71 | 57 | } |
| 58 | 新增:wiz_memory >/dev/null | |
| 59 | 新增:check "wizard defaults: Ruby, Rust, Go, Pi and Playwright MCP off; Claude on" \ | |
| 60 | 新增: "$(grep -E '^export AGENT_VM_INSTALL_(RUBY|RUST|GOLANG|PI|MCP_PLAYWRIGHT|CLAUDE)=' "$SB/wizard.stdin" 2>/dev/null | cut -d_ -f4- | tr '\n' ' ')" \ | |
| 61 | 新增: "RUBY=0 RUST=0 GOLANG=0 CLAUDE=1 PI=0 MCP_PLAYWRIGHT=0 " | |
| 62 | 新增: | |
| 63 | 新增:section "setup wizard: 4 GB of memory with code-server" | |
| 72 | 64 | check "code-server picked: 4 GB" "$(CODE=1 wiz_memory)" "--memory=4" |
| 73 | 65 | check "code-server not picked: 3 GB" "$(CODE=0 wiz_memory)" "--memory=3" |
| 74 | 66 | check "default software (no code-server): 3 GB" "$(DEFAULT_SOFTWARE=1 wiz_memory)" "--memory=3" |
| @@ -275,7 +275,7 @@ check "CRLF env files reach the VM without CRs" \ | ||
| 275 | 275 | # which only the builtin SFTP server with readonlyNames enforces. On any other |
| 276 | 276 | # host the same VM gets 9p. A limactl of its own, reporting QEMU and no type. |
| 277 | 277 | mkdir -p "$SB/qemulima" "$SB/qemulima-home/agent-vm-w" |
| 278 | 删除:printf '#!/bin/sh\n[ "$1" = list ] && echo "qemu <nil>"\nexit 0\n' > "$SB/qemulima/limactl" | |
| 278 | 新增:printf '#!/bin/sh\n[ "$1" = list ] && echo "qemu <nil> null"\nexit 0\n' > "$SB/qemulima/limactl" | |
| 279 | 279 | chmod +x "$SB/qemulima/limactl" |
| 280 | 280 | echo 2.1.0 > "$SB/qemulima-home/agent-vm-w/lima-version" |
| 281 | 281 | enforced_on() { # <fake uname dir> |
| @@ -116,9 +116,9 @@ printf 'B=2\r\nA=project\r\n' > "$PF/.agent-vm.env" | ||
| 116 | 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, that the runtime is there, and that its write reached the project" \ | |
| 120 | 删除: "$(printf '%s' "$out" | tr '\n' ' ')" "env-ok runtime-found probe-written rc=0" | |
| 121 | 删除:check "the write probe leaves no file in the project" "$(ls -A "$PF" | grep -c agent-vm-write-probe)" "0" | |
| 119 | 新增:check "and says it did, that the runtime is there, and that it sees the project from this machine" \ | |
| 120 | 新增: "$(printf '%s' "$out" | tr '\n' ' ')" "env-ok runtime-found share-ok rc=0" | |
| 121 | 新增:check "the probes leave no file in the project" "$(ls -A "$PF" | grep -c 'agent-vm-.*probe')" "0" | |
| 122 | 122 | if _agent_vm_on_windows; then |
| 123 | 123 | printf ' skip the guest env file is private (permission bits are emulated on Windows)\n' |
| 124 | 124 | else |
| @@ -126,10 +126,11 @@ else | ||
| 126 | 126 | fi |
| 127 | 127 | rm -f "$PF/.agent-vm.runtime.sh" |
| 128 | 128 | out="$(PATH="$SB/localvm:$PATH" _agent_vm_push_env_and_probe vm "$PF" "" "$PF/.agent-vm.env" "$PF/.agent-vm.runtime.sh")" |
| 129 | 删除:check "no runtime there: not found" "$(printf '%s' "$out" | tr '\n' ' ')" "env-ok probe-written" | |
| 130 | 删除:# A write that stays in the VM: the share is not mounted (a guest whose | |
| 131 | 删除:# project path is a directory of its own). `limactl shell <vm> sh -c <script> | |
| 132 | 删除:# sh <dir> ...`: the script runs on that other directory. | |
| 129 | 新增:check "no runtime there: not found" "$(printf '%s' "$out" | tr '\n' ' ')" "env-ok share-ok" | |
| 130 | 新增:# The share is not mounted: a guest whose project path is a directory of its | |
| 131 | 新增:# own, which does not hold what this machine put in the project. `limactl | |
| 132 | 新增:# shell <vm> sh -c <script> sh <dir> ...`: the script runs on that other | |
| 133 | 新增:# directory. | |
| 133 | 134 | mkdir -p "$SB/guest-only" "$SB/lostvm" |
| 134 | 135 | cat > "$SB/lostvm/limactl" <<STUB |
| 135 | 136 | #!/usr/bin/env bash |
| @@ -140,8 +141,37 @@ HOME="$GH" exec sh -c "\$script" sh "$SB/guest-only" "\$@" | ||
| 140 | 141 | STUB |
| 141 | 142 | chmod +x "$SB/lostvm/limactl" |
| 142 | 143 | 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 | 新增:case "$out" in *share-ok*) fail "lost share: seen as mounted: $out" ;; *"rc=2") pass "the project not seen from the VM: the share is not mounted" ;; *) fail "lost share: $out" ;; esac | |
| 145 | 新增:check "and the VM's own directory is left empty" "$(ls -A "$SB/guest-only" | wc -l | tr -d ' ')" "0" | |
| 146 | 新增:check "and the project too" "$(ls -A "$PF" | grep -c 'agent-vm-.*probe')" "0" | |
| 147 | 新增:# A scratch VM shares nothing: nothing is put on this machine, and its own | |
| 148 | 新增:# directory is left as it was. | |
| 149 | 新增:out="$(scratch=1 PATH="$SB/lostvm:$PATH" _agent_vm_push_env_and_probe vm "$PF" "" </dev/null; echo "rc=$?")" | |
| 150 | 新增:case "$out" in *"rc=0") pass "scratch: writable, on the VM's own disk" ;; *) fail "scratch probe: $out" ;; esac | |
| 151 | 新增:check "scratch: its directory is left empty" "$(ls -A "$SB/guest-only" | wc -l | tr -d ' ')" "0" | |
| 144 | 152 | rm -rf "$SB/guest-only" "$SB/lostvm" |
| 153 | 新增:# A command in the VM (_agent_vm_lima_run): `limactl shell ... -- zsh -l -c | |
| 154 | 新增:# <script> agent-vm <command>`, run here. | |
| 155 | 新增:if command -v zsh >/dev/null 2>&1; then | |
| 156 | 新增: mkdir -p "$SB/runvm" | |
| 157 | 新增: cat > "$SB/runvm/limactl" <<'STUB' | |
| 158 | 新增:#!/usr/bin/env bash | |
| 159 | 新增:while [ "$#" -gt 0 ] && [ "$1" != -- ]; do [ "$1" = --workdir ] && { cd "$2" || exit 1; shift; }; shift; done | |
| 160 | 新增:shift | |
| 161 | 新增:exec "$@" | |
| 162 | 新增:STUB | |
| 163 | 新增: chmod +x "$SB/runvm/limactl" | |
| 164 | 新增: mkdir -p "$SB/runwd/adir" | |
| 165 | 新增: printf '#!/bin/sh\necho ran\n' > "$SB/runwd/noexec.sh" | |
| 166 | 新增: lrun() { PATH="$SB/runvm:$PATH" _agent_vm_lima_run vm "$SB/runwd" "" "$@" 2>&1; echo "rc=$?"; } | |
| 167 | 新增: case "$(lrun agent-vm-nosuchcmd)" in *"agent-vm-nosuchcmd is not installed in this VM."*"rc=127") pass "run: a command not there, said so" ;; *) fail "run: missing: $(lrun agent-vm-nosuchcmd)" ;; esac | |
| 168 | 新增: case "$(lrun ./noexec.sh)" in *"not installed"*) fail "run: a script without +x said not installed" ;; *"rc=126") pass "run: a script without +x, env's reason and status" ;; *) fail "run: noexec: $(lrun ./noexec.sh)" ;; esac | |
| 169 | 新增: case "$(lrun ./adir)" in *"not installed"*) fail "run: a directory said not installed" ;; *"rc=126") pass "run: a directory, env's reason" ;; *) fail "run: dir: $(lrun ./adir)" ;; esac | |
| 170 | 新增: case "$(lrun X=1 sh -c 'echo "$X"')" in *"1"*"rc=0") pass "run: an assignment before the command" ;; *) fail "run: assignment: $(lrun X=1 sh -c 'echo "$X"')" ;; esac | |
| 171 | 新增: rm -rf "$SB/runvm" "$SB/runwd" | |
| 172 | 新增:else | |
| 173 | 新增: printf ' skip a command in the VM (zsh is not installed)\n' | |
| 174 | 新增:fi | |
| 145 | 175 | if command -v zsh >/dev/null 2>&1; then |
| 146 | 176 | printf '#!/usr/bin/env bash\r\necho "ran:${BASH_VERSION:+bash}" > "$HOME/rt-out"\r\n' > "$PF/.agent-vm.runtime.sh" |
| 147 | 177 | PATH="$SB/localvm:$PATH" _agent_vm_run_project_runtime vm "$PF" "$PF/.agent-vm.runtime.sh" >/dev/null 2>&1 |
| @@ -7,7 +7,7 @@ SCR="agent-vm-proj-scratch-00000000" | ||
| 7 | 7 | SCR_CLONED="$SB/scr-cloned" |
| 8 | 8 | sc() { |
| 9 | 9 | : > "$REC" |
| 10 | 删除: rm -f "$REC.stopped" "$SCR_CLONED" | |
| 10 | 新增: rm -f "$REC.stopped" "$REC.live" "$SCR_CLONED" | |
| 11 | 11 | ( cd "${SC_DIR:-$PROJ}" || exit 1 |
| 12 | 12 | export AGENT_VM_TEST_REC="$REC" AGENT_VM_TEST_VM="$SCR" AGENT_VM_TEST_PROTECTS="$PROTECTS" AGENT_VM_TEST_CLONED="$SCR_CLONED" |
| 13 | 13 | _agent_vm_scratch_name() { echo "$SCR"; } |
| @@ -33,6 +33,12 @@ if [ -n "$d" ] && [ -n "$p" ] && [ "$d" -gt "$p" ]; then pass "then the VM is de | ||
| 33 | 33 | case "$out" in *"Deleting scratch VM '$SCR'"*) pass "and it says so" ;; *) fail "no notice: $out" ;; esac |
| 34 | 34 | grep -Eq "^(stop|delete|edit|start) $PV( |$)" "$REC" && fail "the folder's own VM was touched" || pass "the folder's own VM is left alone" |
| 35 | 35 | [ -e "$(_agent_vm_scratch_marker "$SCR")" ] && fail "the run's record outlived it" || pass "nothing left recorded" |
| 36 | 新增:[ -n "$(ls -A "$PROJ" | grep 'agent-vm-.*probe')" ] && fail "a probe file left in the folder" || pass "no probe file put in the folder" | |
| 37 | 新增:# Lima's _config giving every VM a share: a scratch VM would not share | |
| 38 | 新增:# nothing. Not started, and deleted. | |
| 39 | 新增:out="$(AGENT_VM_TEST_LIVE_UNPROTECTED=1 AGENT_VM_TEST_STOPPED=1 sc --scratch run true; echo "rc=$?")" | |
| 40 | 新增:case "$out" in *"shares agent-vm did not ask for"*"rc=1") pass "a share from Lima's _config stops it" ;; *) fail "scratch, _config: $out" ;; esac | |
| 41 | 新增:rec_has "start $SCR" && fail "scratch, _config: started anyway" || pass "and it is not started" | |
| 36 | 42 | |
| 37 | 43 | # Before the deletion, asked when it can be: a no opens a shell in the VM, |
| 38 | 44 | # and asks again on its exit. Yes, or an answer cut short, deletes. ANSWERS |
| @@ -14,8 +14,36 @@ check "host name: the VM's, lowercased" "$(_agent_vm_code_host agent-vm-My-Proj- | ||
| 14 | 14 | long="agent-vm-$(printf 'x%.0s' $(seq 1 80))-0a1b2c3d" |
| 15 | 15 | check "host name: a DNS label, the hash kept" \ |
| 16 | 16 | "$(_agent_vm_code_host "$long" | sed 's/\.localhost$//' | awk '{ print length($0) <= 63, substr($0, length($0) - 8) }')" "1 -0a1b2c3d" |
| 17 | 新增:check "the ten start at the last digits of the name's hash" "$(_agent_vm_code_ports agent-vm-a-0000270f)" \ | |
| 18 | 新增: "20008 20009 20010 20011 20012 20013 20014 20015 20016 20017 " | |
| 17 | 19 | check "another VM, other ports" \ |
| 18 | 删除: "$([ "$(_agent_vm_code_ports agent-vm-other-00000000)" != "$ports" ] && echo differ)" "differ" | |
| 20 | 新增: "$([ "$(_agent_vm_code_ports agent-vm-a-00000001)" != "$(_agent_vm_code_ports agent-vm-b-00000002)" ] && echo differ)" "differ" | |
| 21 | 新增: | |
| 22 | 新增:# Which candidates something in the VM listens on, run as the VM does: any | |
| 23 | 新增:# protocol (ss), or, without ss, any answer but a refused connection, never | |
| 24 | 新增:# through the VM's proxy. | |
| 25 | 新增:if command -v zsh >/dev/null 2>&1; then | |
| 26 | 新增: mkdir -p "$SB/prep-bin" "$SB/prep-home" | |
| 27 | 新增: printf '#!/bin/sh\nexit 0\n' > "$SB/prep-bin/code-server" | |
| 28 | 新增: printf '#!/bin/sh\nexit 1\n' > "$SB/prep-bin/pgrep" | |
| 29 | 新增: printf '#!/bin/sh\nprintf "LISTEN 0 4096 0.0.0.0:20001 0.0.0.0:*\\nLISTEN 0 128 [::]:20002 [::]:*\\n"\n' > "$SB/prep-bin/ss" | |
| 30 | 新增: printf '#!/bin/sh\nfor a in "$@"; do [ "$a" = --noproxy ] && np=1; done\ncase "$*" in *:20000/*) exit 7 ;; *:20001/*) [ -n "$np" ] && exit 56 ;; esac\nexit 7\n' > "$SB/prep-curl" | |
| 31 | 新增: chmod +x "$SB/prep-bin/"* "$SB/prep-curl" | |
| 32 | 新增: prep() { HOME="$SB/prep-home" PATH="$1:$PATH" zsh -c "$_AGENT_VM_CODE_PREP" agent-vm-code 20000 20001 20002 2>/dev/null | grep '^listening=' | tr '\n' ' '; } | |
| 33 | 新增: check "prep: what ss lists, whatever it speaks" "$(prep "$SB/prep-bin")" "listening=20001 listening=20002 " | |
| 34 | 新增: rm "$SB/prep-bin/ss" | |
| 35 | 新增: mkdir -p "$SB/prep-nossbin" | |
| 36 | 新增: for t in sh awk sed grep cat od tr id mkdir head hostname; do | |
| 37 | 新增: ln -sf "$(command -v "$t")" "$SB/prep-nossbin/$t" 2>/dev/null | |
| 38 | 新增: done | |
| 39 | 新增: cp "$SB/prep-bin/"* "$SB/prep-nossbin/" | |
| 40 | 新增: cp "$SB/prep-curl" "$SB/prep-nossbin/curl" | |
| 41 | 新增: prep_noss() { HOME="$SB/prep-home" http_proxy=http://127.0.0.1:9/ PATH="$SB/prep-nossbin" "$(command -v zsh)" -c "$_AGENT_VM_CODE_PREP" agent-vm-code 20000 20001 2>/dev/null | grep '^listening=' | tr '\n' ' '; } | |
| 42 | 新增: check "prep without ss: a port that answers, not through the proxy" "$(prep_noss)" "listening=20001 " | |
| 43 | 新增: rm -rf "$SB/prep-bin" "$SB/prep-nossbin" "$SB/prep-home" "$SB/prep-curl" | |
| 44 | 新增:else | |
| 45 | 新增: printf ' skip the editor prep run (zsh is not installed)\n' | |
| 46 | 新增:fi | |
| 19 | 47 | |
| 20 | 48 | if _agent_vm_host_port_open "$first"; then |
| 21 | 49 | printf ' skip code launch tests (port %s is taken on this machine)\n' "$first" |
| @@ -38,9 +66,13 @@ else | ||
| 38 | 66 | check "the Safari fallback, on macOS only" \ |
| 39 | 67 | "$(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/')" \ |
| 40 | 68 | "$(printf '0\n1')" |
| 41 | 删除: # The user opens it: nothing is started on this machine. | |
| 42 | 删除: grep -q 'xdg-open\|open "\$url"\|start "\$url"' "$AGENT_VM_SCRIPT_DIR/lib/code.sh" \ | |
| 43 | 删除: && fail "the browser is opened" || pass "the browser is not opened" | |
| 69 | 新增: # The user opens it: no opener is run on this machine. | |
| 70 | 新增: mkdir -p "$SB/openers" | |
| 71 | 新增: for o in open xdg-open start; do printf '#!/bin/sh\n: > "%s/opened"\n' "$SB" > "$SB/openers/$o"; chmod +x "$SB/openers/$o"; done | |
| 72 | 新增: rm -f "$SB/opened" | |
| 73 | 新增: PATH="$SB/openers:$PATH" rec code >/dev/null | |
| 74 | 新增: [ -e "$SB/opened" ] && fail "the browser is opened" || pass "the browser is not opened" | |
| 75 | 新增: rm -rf "$SB/openers" "$SB/opened" | |
| 44 | 76 | |
| 45 | 77 | AGENT_VM_TEST_CODE_PREP="config=/c.yaml\npassword=pw\nlistening=$first\n" rec code >/dev/null |
| 46 | 78 | rec_has "--bind-addr 127.0.0.1:$((first + 1))" \ |
| @@ -267,7 +267,7 @@ export const en = { | ||
| 267 | 267 | optionsHeaders: ['Flag', 'What it does', 'Default'], |
| 268 | 268 | options: [ |
| 269 | 269 | ['--disk GB', 'VM disk size. Can grow, never shrink.', 'the template’s (10)'], |
| 270 | 删除: ['--memory GB', 'VM memory. Clamped to half the host, per VM.', 'the template’s (3)'], | |
| 270 | 新增: ['--memory GB', 'VM memory. Clamped to half the host, per VM.', 'the template’s (3, or 4 with code-server picked in the wizard)'], | |
| 271 | 271 | ['--cpus N', 'CPU count. Clamped to half the host, per VM.', 'the template’s (1)'], |
| 272 | 272 | ['--ssh-port N', 'Fixed host port for the VM’s SSH, for tools that save it. `0` goes back to a new one on each start. Restarts a running VM, asked first.', 'a new one per start'], |
| 273 | 273 | ['--reset', 'Destroy and re-clone the VM from the base template.', 'off'], |
| @@ -288,6 +288,7 @@ export const en = { | ||
| 288 | 288 | ['AGENT_VM_BIN_DIR', 'Where `install` links `agent-vm`.', '~/.local/bin'], |
| 289 | 289 | ['AGENT_VM_LIMA_DIR', 'Windows: where `setup` puts its Lima build.', '~/.local/share/lima-sylvinus'], |
| 290 | 290 | ['AGENT_VM_QEMU_DIR', 'Windows: where QEMU is, when not on `PATH`.', '/c/Program Files/qemu'], |
| 291 | 新增: ['AGENT_VM_SSHFS_CACHE', '`1`: sshfs caches the writable shares too, faster on many files (`git status`, `find`); the VM may then see a file as it was up to 20 seconds before, and write that back. Applies when a VM is next started.', 'unset'], | |
| 291 | 292 | ['AGENT_VM_UNSAFE_WRITABLE_GIT', '`1`: same as `--unsafe-writable-git`.', 'unset'], |
| 292 | 293 | ['AGENT_VM_UNSAFE_DISABLE_SECURITY_PROMPTS', '`1`: same as `--unsafe-disable-security-prompts`.', 'unset'], |
| 293 | 294 | ], |
| @@ -442,7 +443,7 @@ export const en = { | ||
| 442 | 443 | title: 'Why .git', |
| 443 | 444 | paras: [ |
| 444 | 445 | 'Git on your machine runs what a repository’s `.git/config` and hooks name: `core.fsmonitor` on every `git status`, hooks on commit. Your editor and prompt run `git status` on their own, so a VM able to write `.git` could run commands on your host within seconds, invisible in `git diff`.', |
| 445 | 删除: 'With a Lima that has `sshfs.readonlyNames`, every `.git` and `.hg` in the shares is read-only for the VM, at any depth, enforced on the host by Lima’s SFTP server. The agent reads the history but cannot commit. It is not merged upstream yet ([lima-vm/lima#5529](https://github.com/lima-vm/lima/issues/5529)), so `agent-vm setup` offers a build that has it. The shares then use `reverse-sshfs`, slower on many files (see [Node.js](#node)).', | |
| 446 | 新增: 'With a Lima that has `sshfs.readonlyNames`, every `.git` and `.hg` in the shares is read-only for the VM, at any depth, enforced on the host by Lima’s SFTP server. The agent reads the history but cannot commit. It is not merged upstream yet ([lima-vm/lima#5529](https://github.com/lima-vm/lima/issues/5529)), so `agent-vm setup` offers a build that has it. The shares then use `reverse-sshfs`, slower on many files (see [Node.js](#node)), and without sshfs’s cache on the writable ones, so the VM never writes back a file as it was before you changed it: `AGENT_VM_SSHFS_CACHE=1` trades that for speed.', | |
| 446 | 447 | ], |
| 447 | 448 | list: [], |
| 448 | 449 | code: 'brew unlink lima; brew install sylvinus/tap/lima-sylvinus\nagent-vm doctor # where you stand\n\n# let the agent commit anyway\nagent-vm --unsafe-writable-git claude', |
| @@ -450,7 +451,7 @@ export const en = { | ||
| 450 | 451 | { |
| 451 | 452 | title: 'Beyond the name .git', |
| 452 | 453 | paras: [ |
| 453 | 删除: 'The folder a `core.hooksPath` points to in the project (`.husky` for husky) is read-only too. A folder holding git’s internals (`HEAD`, `objects/`, `refs/`, a `config`) is a repository under any name: setting `safe.bareRepository` to `explicit` in your global git config makes git ignore it. A config included from the project, or hooks at the top of a repository, are the same kind of door.', | |
| 454 | 新增: 'The folder a `core.hooksPath` points to in a share (`.husky` for husky) is read-only too, as is a link on the way to it, and the same goes for the repositories in your writable volumes. A folder holding git’s internals (`HEAD`, `objects/`, `refs/`, a `config`) is a repository under any name: setting `safe.bareRepository` to `explicit` in your global git config makes git ignore it, and one in a writable volume is read-only by its name. A config included from a share, a command or a hook git runs from one, or hooks at the top of a share, are the same kind of door.', | |
| 454 | 455 | 'Before a VM boots with writable shares, agent-vm stops on each of these it finds, and on a Lima without `readonlyNames`, and asks: Enter, or no terminal, aborts. `doctor` lists them. `--unsafe-writable-git` (or `AGENT_VM_UNSAFE_WRITABLE_GIT=1` in your shell, never read from the project) lets the agent commit and reopens that path to your host, with a warning on every run.', |
| 455 | 456 | ], |
| 456 | 457 | list: [], |
| @@ -530,7 +531,7 @@ export const en = { | ||
| 530 | 531 | { |
| 531 | 532 | title: 'SSH from your machine', |
| 532 | 533 | paras: [ |
| 533 | 删除: 'Do not connect VS Code Remote-SSH or open-remote-ssh to an agent VM. They run a server in the VM, which root in the VM controls, and the editor on your machine trusts it. Microsoft’s Remote-SSH page says so: “a compromised remote could use the VS Code Remote connection to execute code on your local machine”, and it is by design. Public write-ups show it opening a terminal on the host and running commands there. That removes the boundary agent-vm sets up, which is worse than opening the project in Restricted Mode. JetBrains Gateway most likely works the same way; it has not been checked. For language servers and a debugger with the VM’s packages, use [`agent-vm code`](#edit-with-the-vm-s-tools).', | |
| 534 | 新增: 'Do not connect VS Code Remote-SSH or open-remote-ssh to an agent VM. They run a server in the VM, which root in the VM controls, and the editor on your machine trusts it. Microsoft’s Remote-SSH page says so: “a compromised remote could use the VS Code Remote connection to execute code on your local machine”, and it is by design. Public write-ups show it opening a terminal on the host and running commands there. That removes the boundary agent-vm sets up, which is worse than opening the project in Restricted Mode. JetBrains Gateway does not say it is safer: its security model page says what the backend loads goes to your machine without asking, the backend opens links there (after a prompt), and decides which client version your machine downloads. For language servers and a debugger with the VM’s packages, use [`agent-vm code`](#edit-with-the-vm-s-tools).', | |
| 534 | 535 | 'For scripts, `scp` or `rsync`, `agent-vm info` prints the SSH alias as `ssh_host`. Put these lines at the top of `~/.ssh/config`: a `ForwardAgent yes` found before them would hand the VM your SSH keys. `--ssh-port` pins the port for tools that save it.', |
| 535 | 536 | ], |
| 536 | 537 | list: [], |
| @@ -580,7 +581,8 @@ export const en = { | ||
| 580 | 581 | title: 'Network and ports', |
| 581 | 582 | paras: [ |
| 582 | 583 | 'The VM reaches the internet and every service on your machine’s loopback, at `192.168.5.2`. Lima forwards every port a VM listens on to your `127.0.0.1` when it is free: a VM that listens first on 5432 receives the connections, and passwords, meant for your local Postgres. Blocking this is [on the roadmap](#roadmap).', |
| 583 | 删除: 'So every VM can reach the editor of every other one. `agent-vm code` gives each its own password, made in that VM, and its own host name, `<vm-name>.localhost`: browsers keep cookies per host name and not per port, so at `127.0.0.1` any page a VM serves would receive the editor sessions of the others, and with them a way in. Chrome and Firefox resolve `*.localhost` themselves; Safari may not, and then `127.0.0.1` in a private window kept for the editor does the same.', | |
| 584 | 新增: 'So every VM can reach the editor of every other one. `agent-vm code` gives each its own password, made in that VM, and its own host name, `<vm-name>.localhost`: browsers keep cookies per host name and not per port, so a page a VM serves at `127.0.0.1` does not receive the editor sessions of the others. Chrome and Firefox resolve `*.localhost` themselves; Safari may not, and then `127.0.0.1` in a private window kept for the editor does the same.', | |
| 585 | 新增: 'That stops a page, not a VM bent on it. A VM can listen on a port Lima forwards to your machine and send your browser to another VM’s host name on that port: the browser hands it that editor’s session, and the VM can use it on the editor’s own port, with its terminals. Keeping VMs out of each other needs network isolation, which agent-vm does not have yet ([roadmap](#roadmap)). Until then, stop `agent-vm code` (Ctrl-C) when you are not using it, and treat an editor as reachable from every VM that runs.', | |
| 584 | 586 | ], |
| 585 | 587 | list: [], |
| 586 | 588 | code: '', |
| @@ -269,7 +269,7 @@ export const fr: Dictionary = { | ||
| 269 | 269 | optionsHeaders: ['Option', 'Rôle', 'Défaut'], |
| 270 | 270 | options: [ |
| 271 | 271 | ['--disk GB', 'Taille du disque. Peut grandir, jamais rétrécir.', 'celle de l\'image (10)'], |
| 272 | 删除: ['--memory GB', 'Mémoire de la VM. Plafonnée à la moitié de l\'hôte, par VM.', 'celle de l\'image (3)'], | |
| 272 | 新增: ['--memory GB', 'Mémoire de la VM. Plafonnée à la moitié de l\'hôte, par VM.', 'celle de l\'image (3, ou 4 avec code-server choisi dans l\'assistant)'], | |
| 273 | 273 | ['--cpus N', 'Nombre de CPU. Plafonné à la moitié de l\'hôte, par VM.', 'celui de l\'image (1)'], |
| 274 | 274 | ['--ssh-port N', 'Port fixe sur l\'hôte pour le SSH de la VM, pour les outils qui l\'enregistrent. `0` revient à un nouveau port à chaque démarrage. Redémarre une VM en marche, après confirmation.', 'un nouveau par démarrage'], |
| 275 | 275 | ['--reset', 'Détruit la VM et la re-clone depuis l\'image de base.', 'inactif'], |
| @@ -290,6 +290,7 @@ export const fr: Dictionary = { | ||
| 290 | 290 | ['AGENT_VM_BIN_DIR', 'Où `install` place le lien `agent-vm`.', '~/.local/bin'], |
| 291 | 291 | ['AGENT_VM_LIMA_DIR', 'Windows : où `setup` installe sa version de Lima.', '~/.local/share/lima-sylvinus'], |
| 292 | 292 | ['AGENT_VM_QEMU_DIR', 'Windows : où trouver QEMU, s\'il n\'est pas dans le `PATH`.', '/c/Program Files/qemu'], |
| 293 | 新增: ['AGENT_VM_SSHFS_CACHE', '`1` : sshfs met aussi en cache les partages modifiables, plus rapide sur beaucoup de fichiers (`git status`, `find`) ; la VM peut alors voir un fichier tel qu\'il était jusqu\'à 20 secondes avant, et le réécrire ainsi. S\'applique au prochain démarrage d\'une VM.', 'non définie'], | |
| 293 | 294 | ['AGENT_VM_UNSAFE_WRITABLE_GIT', '`1` : équivaut à `--unsafe-writable-git`.', 'non définie'], |
| 294 | 295 | ['AGENT_VM_UNSAFE_DISABLE_SECURITY_PROMPTS', '`1` : équivaut à `--unsafe-disable-security-prompts`.', 'non définie'], |
| 295 | 296 | ], |
| @@ -444,7 +445,7 @@ export const fr: Dictionary = { | ||
| 444 | 445 | title: 'Pourquoi .git', |
| 445 | 446 | paras: [ |
| 446 | 447 | 'Git, sur ta machine, exécute ce que désignent le `.git/config` et les hooks d\'un dépôt : `core.fsmonitor` à chaque `git status`, les hooks au commit. Ton éditeur et ton prompt lancent `git status` d\'eux-mêmes : une VM capable d\'écrire dans `.git` pourrait lancer des commandes sur ton hôte en quelques secondes, sans que rien n\'apparaisse dans `git diff`.', |
| 447 | 删除: 'Avec un Lima qui a `sshfs.readonlyNames`, chaque `.git` et `.hg` des partages est en lecture seule pour la VM, à toute profondeur, et c\'est le serveur SFTP de Lima, sur l\'hôte, qui l\'impose. L\'agent lit l\'historique mais ne peut pas commiter. Ce n\'est pas encore intégré en amont ([lima-vm/lima#5529](https://github.com/lima-vm/lima/issues/5529)) : `agent-vm setup` propose une version qui l\'a. Les partages passent alors en `reverse-sshfs`, plus lent sur beaucoup de fichiers (voir [Node.js](#node)).', | |
| 448 | 新增: 'Avec un Lima qui a `sshfs.readonlyNames`, chaque `.git` et `.hg` des partages est en lecture seule pour la VM, à toute profondeur, et c\'est le serveur SFTP de Lima, sur l\'hôte, qui l\'impose. L\'agent lit l\'historique mais ne peut pas commiter. Ce n\'est pas encore intégré en amont ([lima-vm/lima#5529](https://github.com/lima-vm/lima/issues/5529)) : `agent-vm setup` propose une version qui l\'a. Les partages passent alors en `reverse-sshfs`, plus lent sur beaucoup de fichiers (voir [Node.js](#node)), et sans le cache de sshfs sur ceux qui sont modifiables, pour que la VM ne réécrive jamais un fichier tel qu\'il était avant que tu le changes : `AGENT_VM_SSHFS_CACHE=1` échange cela contre de la vitesse.', | |
| 448 | 449 | ], |
| 449 | 450 | list: [], |
| 450 | 451 | code: 'brew unlink lima; brew install sylvinus/tap/lima-sylvinus\nagent-vm doctor # où tu en es\n\n# laisser l\'agent commiter quand même\nagent-vm --unsafe-writable-git claude', |
| @@ -452,7 +453,7 @@ export const fr: Dictionary = { | ||
| 452 | 453 | { |
| 453 | 454 | title: 'Au-delà du nom .git', |
| 454 | 455 | paras: [ |
| 455 | 删除: 'Le dossier vers lequel pointe un `core.hooksPath` du projet (`.husky` pour husky) est aussi en lecture seule. Un dossier qui contient les fichiers internes de git (`HEAD`, `objects/`, `refs/`, un `config`) est un dépôt sous n\'importe quel nom : régler `safe.bareRepository` à `explicit` dans ta config git globale le fait ignorer par git. Une config incluse depuis le projet, ou des hooks à la racine d\'un dépôt, ouvrent la même porte.', | |
| 456 | 新增: 'Le dossier vers lequel pointe un `core.hooksPath` dans un partage (`.husky` pour husky) est aussi en lecture seule, comme un lien sur le chemin qui y mène, et de même pour les dépôts de tes volumes modifiables. Un dossier qui contient les fichiers internes de git (`HEAD`, `objects/`, `refs/`, un `config`) est un dépôt sous n\'importe quel nom : régler `safe.bareRepository` à `explicit` dans ta config git globale le fait ignorer par git, et celui d\'un volume modifiable est en lecture seule par son nom. Une config incluse depuis un partage, une commande ou un hook que git y lance, ou des hooks à la racine d\'un partage, ouvrent la même porte.', | |
| 456 | 457 | 'Avant de démarrer une VM aux partages modifiables, agent-vm s\'arrête sur chacun de ceux qu\'il trouve, et sur un Lima sans `readonlyNames`, pour demander : Entrée, ou l\'absence de terminal, annule. `doctor` les liste. `--unsafe-writable-git` (ou `AGENT_VM_UNSAFE_WRITABLE_GIT=1` dans ton shell, jamais lu depuis le projet) laisse l\'agent commiter et rouvre ce chemin vers ton hôte, avec un avertissement à chaque lancement.', |
| 457 | 458 | ], |
| 458 | 459 | list: [], |
| @@ -532,7 +533,7 @@ export const fr: Dictionary = { | ||
| 532 | 533 | { |
| 533 | 534 | title: 'SSH depuis ta machine', |
| 534 | 535 | paras: [ |
| 535 | 删除: 'Ne branche pas VS Code Remote-SSH ou open-remote-ssh sur une VM d\'agent. Ils font tourner un serveur dans la VM, que contrôle root dans la VM, et l\'éditeur sur ta machine lui fait confiance. La page de Remote-SSH chez Microsoft le dit : « a compromised remote could use the VS Code Remote connection to execute code on your local machine », et c\'est voulu. Des articles publics le montrent ouvrant un terminal sur l\'hôte et y lançant des commandes. Cela supprime la frontière que pose agent-vm, ce qui est pire qu\'ouvrir le projet en mode restreint. JetBrains Gateway fonctionne très probablement de la même façon ; ce n\'est pas vérifié. Pour les serveurs de langage et un débogueur avec les paquets de la VM, utilise [`agent-vm code`](#edit-with-the-vm-s-tools).', | |
| 536 | 新增: 'Ne branche pas VS Code Remote-SSH ou open-remote-ssh sur une VM d\'agent. Ils font tourner un serveur dans la VM, que contrôle root dans la VM, et l\'éditeur sur ta machine lui fait confiance. La page de Remote-SSH chez Microsoft le dit : « a compromised remote could use the VS Code Remote connection to execute code on your local machine », et c\'est voulu. Des articles publics le montrent ouvrant un terminal sur l\'hôte et y lançant des commandes. Cela supprime la frontière que pose agent-vm, ce qui est pire qu\'ouvrir le projet en mode restreint. JetBrains Gateway ne se dit pas plus sûr : sa page sur le modèle de sécurité dit que ce que charge le backend arrive sur ta machine sans rien demander, que le backend y ouvre des liens (après confirmation) et décide de la version du client qu\'elle télécharge. Pour les serveurs de langage et un débogueur avec les paquets de la VM, utilise [`agent-vm code`](#edit-with-the-vm-s-tools).', | |
| 536 | 537 | 'Pour des scripts, `scp` ou `rsync`, `agent-vm info` affiche l\'alias SSH comme `ssh_host`. Mets ces lignes en haut de `~/.ssh/config` : un `ForwardAgent yes` trouvé avant elles donnerait tes clés SSH à la VM. `--ssh-port` fixe le port pour les outils qui l\'enregistrent.', |
| 537 | 538 | ], |
| 538 | 539 | list: [], |
| @@ -582,7 +583,8 @@ export const fr: Dictionary = { | ||
| 582 | 583 | title: 'Réseau et ports', |
| 583 | 584 | paras: [ |
| 584 | 585 | 'La VM atteint Internet et tous les services de la boucle locale de ta machine, à `192.168.5.2`. Lima redirige chaque port qu\'écoute une VM vers ton `127.0.0.1` s\'il est libre : une VM qui écoute la première sur 5432 reçoit les connexions, et les mots de passe, destinés à ton Postgres local. Le bloquer est [sur la feuille de route](#roadmap).', |
| 585 | 删除: 'Chaque VM peut donc joindre l\'éditeur de toutes les autres. `agent-vm code` donne à chacune son propre mot de passe, créé dans cette VM, et son propre nom d\'hôte, `<nom-de-vm>.localhost` : les navigateurs rangent les cookies par nom d\'hôte et non par port, si bien qu\'à `127.0.0.1` n\'importe quelle page servie par une VM recevrait les sessions d\'éditeur des autres, et avec elles une porte d\'entrée. Chrome et Firefox résolvent `*.localhost` eux-mêmes ; Safari peut ne pas le faire, et `127.0.0.1` dans une fenêtre privée réservée à l\'éditeur fait alors la même chose.', | |
| 586 | 新增: 'Chaque VM peut donc joindre l\'éditeur de toutes les autres. `agent-vm code` donne à chacune son propre mot de passe, créé dans cette VM, et son propre nom d\'hôte, `<nom-de-vm>.localhost` : les navigateurs rangent les cookies par nom d\'hôte et non par port, si bien qu\'une page servie par une VM à `127.0.0.1` ne reçoit pas les sessions d\'éditeur des autres. Chrome et Firefox résolvent `*.localhost` eux-mêmes ; Safari peut ne pas le faire, et `127.0.0.1` dans une fenêtre privée réservée à l\'éditeur fait alors la même chose.', | |
| 587 | 新增: 'Cela arrête une page, pas une VM décidée. Une VM peut écouter sur un port que Lima transfère vers ta machine et envoyer ton navigateur au nom d\'hôte d\'une autre VM sur ce port : le navigateur lui remet la session de cet éditeur, que la VM peut utiliser sur le port de l\'éditeur, avec ses terminaux. Tenir les VM à l\'écart les unes des autres demande une isolation réseau, qu\'agent-vm n\'a pas encore ([feuille de route](#roadmap)). D\'ici là, arrête `agent-vm code` (Ctrl-C) quand tu ne t\'en sers pas, et considère qu\'un éditeur est joignable par chaque VM qui tourne.', | |
| 586 | 588 | ], |
| 587 | 589 | list: [], |
| 588 | 590 | code: '', |

