提交记录修改README.md+9 −2看文件
修改agent-vm.sh+42 −4看文件
| @@ -89,10 +89,17 @@ Each directory gets its own persistent VM. You can manage it with: | ||
| 89 | 89 | ```bash |
| 90 | 90 | agent-vm status # Show status of all VMs (current dir marked with >) |
| 91 | 91 | agent-vm stop # Stop the VM (can be restarted later) |
| 92 | 删除:agent-vm destroy # Stop and permanently delete the VM | |
| 92 | 新增:agent-vm rm # Stop and permanently delete the VM | |
| 93 | 93 | agent-vm destroy-all # Stop and delete all agent-vm VMs |
| 94 | 94 | ``` |
| 95 | 95 | |
| 96 | 新增:To automatically destroy a VM after the agent exits (like `docker run --rm`): | |
| 97 | 新增: | |
| 98 | 新增:```bash | |
| 99 | 新增:agent-vm --rm claude # Run Claude, then destroy the VM | |
| 100 | 新增:agent-vm --rm run npm test # Run tests, then destroy the VM | |
| 101 | 新增:``` | |
| 102 | 新增: | |
| 96 | 103 | To resize an existing VM's disk or memory, just pass `--disk` or `--memory` again — the VM will be stopped, reconfigured, and restarted automatically: |
| 97 | 104 | |
| 98 | 105 | ```bash |
| @@ -177,7 +184,7 @@ To add more MCP servers, add them to `~/.claude.json` in your `~/.agent-vm/setup | ||
| 177 | 184 | 1. **`agent-vm setup`** creates a Debian 13 VM with Lima, runs `agent-vm.setup.sh` inside it to install dev tools + Chrome + agents, and stops it as a reusable base template |
| 178 | 185 | 2. **`agent-vm claude|opencode|codex [args]`** clones the base template into a persistent per-directory VM, mounts your working directory, runs optional runtime scripts (`~/.agent-vm/runtime.sh` then `.agent-vm.runtime.sh`), then launches the agent with full permissions |
| 179 | 186 | 3. The VM persists after exit. Running any agent command or `agent-vm shell` in the same directory reuses the same VM |
| 180 | 删除:4. Use `agent-vm stop` to stop the VM or `agent-vm destroy` to delete it | |
| 187 | 新增:4. Use `agent-vm stop` to stop the VM or `agent-vm rm` to delete it. Use `--rm` to auto-delete after the command exits | |
| 181 | 188 | |
| 182 | 189 | Each VM is fully isolated — agents must authenticate independently inside their VM (e.g. `claude login`). Credentials persist within the VM across restarts but are not shared between VMs or with the host. |
| 183 | 190 | |
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | # agent-vm codex - Run Codex CLI in a persistent VM for cwd |
| 14 | 14 | # agent-vm shell - Open a shell in the persistent VM for cwd |
| 15 | 15 | # agent-vm stop - Stop the VM for cwd |
| 16 | 删除:# agent-vm destroy - Stop and delete the VM for cwd | |
| 16 | 新增:# agent-vm rm - Stop and delete the VM for cwd | |
| 17 | 17 | # agent-vm list - List all agent-vm VMs |
| 18 | 18 | # agent-vm status - Show status of all VMs (current dir marked with >) |
| 19 | 19 | # agent-vm help - Show help |
| @@ -198,6 +198,8 @@ agent-vm() { | ||
| 198 | 198 | vm_opts+=(--offline); shift ;; |
| 199 | 199 | --readonly) |
| 200 | 200 | vm_opts+=(--readonly); shift ;; |
| 201 | 新增: --rm) | |
| 202 | 新增: vm_opts+=(--rm); shift ;; | |
| 201 | 203 | *) |
| 202 | 204 | break ;; |
| 203 | 205 | esac |
| @@ -228,7 +230,7 @@ agent-vm() { | ||
| 228 | 230 | stop) |
| 229 | 231 | _agent_vm_stop "$@" |
| 230 | 232 | ;; |
| 231 | 删除: destroy) | |
| 233 | 新增: rm|destroy) | |
| 232 | 234 | _agent_vm_destroy "$@" |
| 233 | 235 | ;; |
| 234 | 236 | destroy-all) |
| @@ -263,7 +265,7 @@ Commands: | ||
| 263 | 265 | shell Open a shell in the VM for the current directory |
| 264 | 266 | run <cmd> [args] Run a command in the VM for the current directory |
| 265 | 267 | stop Stop the VM for the current directory |
| 266 | 删除: destroy Stop and delete the VM for the current directory | |
| 268 | 新增: rm Stop and delete the VM for the current directory | |
| 267 | 269 | destroy-all Stop and delete all agent-vm VMs |
| 268 | 270 | list List all agent-vm VMs |
| 269 | 271 | status Show status of all VMs (current dir marked with >) |
| @@ -276,6 +278,7 @@ VM options (for claude, opencode, codex, shell, run): | ||
| 276 | 278 | --reset Destroy and re-clone the VM from the base template |
| 277 | 279 | --offline Block outbound internet (keeps host/VM communication) |
| 278 | 280 | --readonly Mount the project directory as read-only |
| 281 | 新增: --rm Automatically destroy the VM after the command exits | |
| 279 | 282 | |
| 280 | 283 | Examples: |
| 281 | 284 | agent-vm setup # Create base VM |
| @@ -284,6 +287,7 @@ Examples: | ||
| 284 | 287 | agent-vm codex # Run Codex in a VM |
| 285 | 288 | agent-vm --disk 50 --memory 16 --cpus 8 claude # Custom resources |
| 286 | 289 | agent-vm --reset claude # Fresh VM from base template |
| 290 | 新增: agent-vm --rm claude # Destroy VM after Claude exits | |
| 287 | 291 | agent-vm --offline claude # No internet access |
| 288 | 292 | agent-vm --readonly shell # Read-only project mount |
| 289 | 293 | agent-vm shell # Shell into the VM |
| @@ -405,6 +409,7 @@ _agent_vm_setup() { | ||
| 405 | 409 | _agent_vm_claude() { |
| 406 | 410 | local vm_opts=() |
| 407 | 411 | local args=() |
| 412 | 新增: local rm="" | |
| 408 | 413 | while [[ $# -gt 0 ]]; do |
| 409 | 414 | case "$1" in |
| 410 | 415 | --disk) vm_opts+=(--disk "$2"); shift 2 ;; |
| @@ -413,6 +418,7 @@ _agent_vm_claude() { | ||
| 413 | 418 | --reset) vm_opts+=(--reset); shift ;; |
| 414 | 419 | --offline) vm_opts+=(--offline); shift ;; |
| 415 | 420 | --readonly) vm_opts+=(--readonly); shift ;; |
| 421 | 新增: --rm) rm=1; shift ;; | |
| 416 | 422 | *) args+=("$1"); shift ;; |
| 417 | 423 | esac |
| 418 | 424 | done |
| @@ -424,12 +430,17 @@ _agent_vm_claude() { | ||
| 424 | 430 | _agent_vm_ensure_running "$vm_name" "$host_dir" "${vm_opts[@]}" || return 1 |
| 425 | 431 | _agent_vm_print_resources "$vm_name" |
| 426 | 432 | |
| 433 | 新增: local exit_code=0 | |
| 427 | 434 | limactl shell --workdir "$host_dir" "$vm_name" claude --dangerously-skip-permissions "${args[@]}" |
| 435 | 新增: exit_code=$? | |
| 436 | 新增: [[ -n "$rm" ]] && { echo "Removing VM..."; _agent_vm_destroy; } | |
| 437 | 新增: return $exit_code | |
| 428 | 438 | } |
| 429 | 439 | |
| 430 | 440 | _agent_vm_opencode() { |
| 431 | 441 | local vm_opts=() |
| 432 | 442 | local args=() |
| 443 | 新增: local rm="" | |
| 433 | 444 | while [[ $# -gt 0 ]]; do |
| 434 | 445 | case "$1" in |
| 435 | 446 | --disk) vm_opts+=(--disk "$2"); shift 2 ;; |
| @@ -438,6 +449,7 @@ _agent_vm_opencode() { | ||
| 438 | 449 | --reset) vm_opts+=(--reset); shift ;; |
| 439 | 450 | --offline) vm_opts+=(--offline); shift ;; |
| 440 | 451 | --readonly) vm_opts+=(--readonly); shift ;; |
| 452 | 新增: --rm) rm=1; shift ;; | |
| 441 | 453 | *) args+=("$1"); shift ;; |
| 442 | 454 | esac |
| 443 | 455 | done |
| @@ -451,12 +463,17 @@ _agent_vm_opencode() { | ||
| 451 | 463 | |
| 452 | 464 | # TODO: add --dangerously-skip-permissions once released |
| 453 | 465 | # (waiting on https://github.com/anomalyco/opencode/pull/11833) |
| 466 | 新增: local exit_code=0 | |
| 454 | 467 | limactl shell --tty --workdir "$host_dir" "$vm_name" opencode "${args[@]}" |
| 468 | 新增: exit_code=$? | |
| 469 | 新增: [[ -n "$rm" ]] && { echo "Removing VM..."; _agent_vm_destroy; } | |
| 470 | 新增: return $exit_code | |
| 455 | 471 | } |
| 456 | 472 | |
| 457 | 473 | _agent_vm_codex() { |
| 458 | 474 | local vm_opts=() |
| 459 | 475 | local args=() |
| 476 | 新增: local rm="" | |
| 460 | 477 | while [[ $# -gt 0 ]]; do |
| 461 | 478 | case "$1" in |
| 462 | 479 | --disk) vm_opts+=(--disk "$2"); shift 2 ;; |
| @@ -465,6 +482,7 @@ _agent_vm_codex() { | ||
| 465 | 482 | --reset) vm_opts+=(--reset); shift ;; |
| 466 | 483 | --offline) vm_opts+=(--offline); shift ;; |
| 467 | 484 | --readonly) vm_opts+=(--readonly); shift ;; |
| 485 | 新增: --rm) rm=1; shift ;; | |
| 468 | 486 | *) args+=("$1"); shift ;; |
| 469 | 487 | esac |
| 470 | 488 | done |
| @@ -476,11 +494,16 @@ _agent_vm_codex() { | ||
| 476 | 494 | _agent_vm_ensure_running "$vm_name" "$host_dir" "${vm_opts[@]}" || return 1 |
| 477 | 495 | _agent_vm_print_resources "$vm_name" |
| 478 | 496 | |
| 497 | 新增: local exit_code=0 | |
| 479 | 498 | limactl shell --workdir "$host_dir" "$vm_name" codex --full-auto "${args[@]}" |
| 499 | 新增: exit_code=$? | |
| 500 | 新增: [[ -n "$rm" ]] && { echo "Removing VM..."; _agent_vm_destroy; } | |
| 501 | 新增: return $exit_code | |
| 480 | 502 | } |
| 481 | 503 | |
| 482 | 504 | _agent_vm_shell() { |
| 483 | 505 | local vm_opts=() |
| 506 | 新增: local rm="" | |
| 484 | 507 | while [[ $# -gt 0 ]]; do |
| 485 | 508 | case "$1" in |
| 486 | 509 | --disk) vm_opts+=(--disk "$2"); shift 2 ;; |
| @@ -489,6 +512,7 @@ _agent_vm_shell() { | ||
| 489 | 512 | --reset) vm_opts+=(--reset); shift ;; |
| 490 | 513 | --offline) vm_opts+=(--offline); shift ;; |
| 491 | 514 | --readonly) vm_opts+=(--readonly); shift ;; |
| 515 | 新增: --rm) rm=1; shift ;; | |
| 492 | 516 | *) shift ;; |
| 493 | 517 | esac |
| 494 | 518 | done |
| @@ -501,13 +525,22 @@ _agent_vm_shell() { | ||
| 501 | 525 | _agent_vm_print_resources "$vm_name" |
| 502 | 526 | |
| 503 | 527 | echo "VM: $vm_name | Dir: $host_dir" |
| 504 | 删除: echo "Type 'exit' to leave (VM keeps running). Use 'agent-vm stop' to stop it." | |
| 528 | 新增: if [[ -n "$rm" ]]; then | |
| 529 | 新增: echo "Type 'exit' to leave. VM will be destroyed after exit." | |
| 530 | 新增: else | |
| 531 | 新增: echo "Type 'exit' to leave (VM keeps running). Use 'agent-vm stop' to stop it." | |
| 532 | 新增: fi | |
| 533 | 新增: local exit_code=0 | |
| 505 | 534 | limactl shell --workdir "$host_dir" "$vm_name" zsh -l |
| 535 | 新增: exit_code=$? | |
| 536 | 新增: [[ -n "$rm" ]] && { echo "Removing VM..."; _agent_vm_destroy; } | |
| 537 | 新增: return $exit_code | |
| 506 | 538 | } |
| 507 | 539 | |
| 508 | 540 | _agent_vm_run() { |
| 509 | 541 | local vm_opts=() |
| 510 | 542 | local args=() |
| 543 | 新增: local rm="" | |
| 511 | 544 | while [[ $# -gt 0 ]]; do |
| 512 | 545 | case "$1" in |
| 513 | 546 | --disk) vm_opts+=(--disk "$2"); shift 2 ;; |
| @@ -516,6 +549,7 @@ _agent_vm_run() { | ||
| 516 | 549 | --reset) vm_opts+=(--reset); shift ;; |
| 517 | 550 | --offline) vm_opts+=(--offline); shift ;; |
| 518 | 551 | --readonly) vm_opts+=(--readonly); shift ;; |
| 552 | 新增: --rm) rm=1; shift ;; | |
| 519 | 553 | *) args+=("$1"); shift ;; |
| 520 | 554 | esac |
| 521 | 555 | done |
| @@ -531,7 +565,11 @@ _agent_vm_run() { | ||
| 531 | 565 | _agent_vm_ensure_running "$vm_name" "$host_dir" "${vm_opts[@]}" || return 1 |
| 532 | 566 | _agent_vm_print_resources "$vm_name" |
| 533 | 567 | |
| 568 | 新增: local exit_code=0 | |
| 534 | 569 | limactl shell --workdir "$host_dir" "$vm_name" "${args[@]}" |
| 570 | 新增: exit_code=$? | |
| 571 | 新增: [[ -n "$rm" ]] && { echo "Removing VM..."; _agent_vm_destroy; } | |
| 572 | 新增: return $exit_code | |
| 535 | 573 | } |
| 536 | 574 | |
| 537 | 575 | _agent_vm_stop() { |

