提交记录修改agent-vm.sh+27 −6看文件
| @@ -43,6 +43,20 @@ _agent_vm_running() { | ||
| 43 | 43 | limactl list --format '{{.Name}} {{.Status}}' 2>/dev/null | grep -q "^${1} Running$" |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 新增:# Print VM resource details (CPUs, memory, disk) | |
| 47 | 新增:_agent_vm_print_resources() { | |
| 48 | 新增: local vm_name="$1" | |
| 49 | 新增: local info | |
| 50 | 新增: info=$(limactl list --format '{{.Name}}|{{.CPUs}}|{{.Memory}}|{{.Disk}}' 2>/dev/null | grep "^${vm_name}|" | head -1) | |
| 51 | 新增: if [[ -n "$info" ]]; then | |
| 52 | 新增: local cpus mem_bytes disk_bytes | |
| 53 | 新增: IFS='|' read -r _ cpus mem_bytes disk_bytes <<< "$info" | |
| 54 | 新增: local mem_gib=$((mem_bytes / 1073741824)) | |
| 55 | 新增: local disk_gib=$((disk_bytes / 1073741824)) | |
| 56 | 新增: echo " Resources: CPUs: ${cpus}, Memory: ${mem_gib} GiB, Disk: ${disk_gib} GiB" | |
| 57 | 新增: fi | |
| 58 | 新增:} | |
| 59 | 新增: | |
| 46 | 60 | # Ensure the VM for cwd exists and is running, creating/starting as needed |
| 47 | 61 | # Usage: _agent_vm_ensure_running <vm_name> <host_dir> [--disk GB] [--memory GB] [--reset] |
| 48 | 62 | _agent_vm_ensure_running() { |
| @@ -85,6 +99,7 @@ _agent_vm_ensure_running() { | ||
| 85 | 99 | [[ -n "$memory" ]] && clone_args+=(--set ".memory=\"${memory}GiB\"") |
| 86 | 100 | [[ -n "$cpus" ]] && clone_args+=(--set ".cpus=${cpus}") |
| 87 | 101 | limactl clone "$AGENT_VM_TEMPLATE" "$vm_name" "${clone_args[@]}" &>/dev/null |
| 102 | 新增: _agent_vm_print_resources "$vm_name" | |
| 88 | 103 | # Record which base version this VM was cloned from |
| 89 | 104 | local base_ver="$AGENT_VM_STATE_DIR/.agent-vm-base-version" |
| 90 | 105 | if [[ -f "$base_ver" ]]; then |
| @@ -116,6 +131,7 @@ _agent_vm_ensure_running() { | ||
| 116 | 131 | echo "$edit_output" >&2 |
| 117 | 132 | return 1 |
| 118 | 133 | fi |
| 134 | 新增: _agent_vm_print_resources "$vm_name" | |
| 119 | 135 | fi |
| 120 | 136 | |
| 121 | 137 | # Warn if this VM was cloned from an older base |
| @@ -254,9 +270,9 @@ Commands: | ||
| 254 | 270 | help Show this help |
| 255 | 271 | |
| 256 | 272 | VM options (for claude, opencode, codex, shell, run): |
| 257 | 删除: --disk GB VM disk size (default: 20) | |
| 258 | 删除: --memory GB VM memory (default: 8) | |
| 259 | 删除: --cpus N Number of CPUs (default: 4) | |
| 273 | 新增: --disk GB VM disk size (default: 4) | |
| 274 | 新增: --memory GB VM memory (default: 1) | |
| 275 | 新增: --cpus N Number of CPUs (default: 1) | |
| 260 | 276 | --reset Destroy and re-clone the VM from the base template |
| 261 | 277 | --offline Block outbound internet (keeps host/VM communication) |
| 262 | 278 | --readonly Mount the project directory as read-only |
| @@ -287,9 +303,9 @@ EOF | ||
| 287 | 303 | } |
| 288 | 304 | |
| 289 | 305 | _agent_vm_setup() { |
| 290 | 删除: local disk=20 | |
| 291 | 删除: local memory=8 | |
| 292 | 删除: local cpus="" | |
| 306 | 新增: local disk=4 | |
| 307 | 新增: local memory=1 | |
| 308 | 新增: local cpus=1 | |
| 293 | 309 | |
| 294 | 310 | while [[ $# -gt 0 ]]; do |
| 295 | 311 | case "$1" in |
| @@ -406,6 +422,7 @@ _agent_vm_claude() { | ||
| 406 | 422 | vm_name="$(_agent_vm_name "$host_dir")" |
| 407 | 423 | |
| 408 | 424 | _agent_vm_ensure_running "$vm_name" "$host_dir" "${vm_opts[@]}" || return 1 |
| 425 | 新增: _agent_vm_print_resources "$vm_name" | |
| 409 | 426 | |
| 410 | 427 | limactl shell --workdir "$host_dir" "$vm_name" claude --dangerously-skip-permissions "${args[@]}" |
| 411 | 428 | } |
| @@ -430,6 +447,7 @@ _agent_vm_opencode() { | ||
| 430 | 447 | vm_name="$(_agent_vm_name "$host_dir")" |
| 431 | 448 | |
| 432 | 449 | _agent_vm_ensure_running "$vm_name" "$host_dir" "${vm_opts[@]}" || return 1 |
| 450 | 新增: _agent_vm_print_resources "$vm_name" | |
| 433 | 451 | |
| 434 | 452 | # TODO: add --dangerously-skip-permissions once released |
| 435 | 453 | # (waiting on https://github.com/anomalyco/opencode/pull/11833) |
| @@ -456,6 +474,7 @@ _agent_vm_codex() { | ||
| 456 | 474 | vm_name="$(_agent_vm_name "$host_dir")" |
| 457 | 475 | |
| 458 | 476 | _agent_vm_ensure_running "$vm_name" "$host_dir" "${vm_opts[@]}" || return 1 |
| 477 | 新增: _agent_vm_print_resources "$vm_name" | |
| 459 | 478 | |
| 460 | 479 | limactl shell --workdir "$host_dir" "$vm_name" codex --full-auto "${args[@]}" |
| 461 | 480 | } |
| @@ -479,6 +498,7 @@ _agent_vm_shell() { | ||
| 479 | 498 | vm_name="$(_agent_vm_name "$host_dir")" |
| 480 | 499 | |
| 481 | 500 | _agent_vm_ensure_running "$vm_name" "$host_dir" "${vm_opts[@]}" || return 1 |
| 501 | 新增: _agent_vm_print_resources "$vm_name" | |
| 482 | 502 | |
| 483 | 503 | echo "VM: $vm_name | Dir: $host_dir" |
| 484 | 504 | echo "Type 'exit' to leave (VM keeps running). Use 'agent-vm stop' to stop it." |
| @@ -509,6 +529,7 @@ _agent_vm_run() { | ||
| 509 | 529 | vm_name="$(_agent_vm_name "$host_dir")" |
| 510 | 530 | |
| 511 | 531 | _agent_vm_ensure_running "$vm_name" "$host_dir" "${vm_opts[@]}" || return 1 |
| 532 | 新增: _agent_vm_print_resources "$vm_name" | |
| 512 | 533 | |
| 513 | 534 | limactl shell --workdir "$host_dir" "$vm_name" "${args[@]}" |
| 514 | 535 | } |

