提交记录修改agent-vm.sh+28 −8看文件
| @@ -1103,6 +1103,29 @@ EOF | ||
| 1103 | 1103 | echo "Note: Existing VMs were not updated. Use --reset to re-clone them from the new base." |
| 1104 | 1104 | } |
| 1105 | 1105 | |
| 1106 | 新增:# Run a command in the VM through a login zsh. | |
| 1107 | 新增:# | |
| 1108 | 新增:# `limactl shell VM cmd` runs cmd under the shell configured for the instance, | |
| 1109 | 新增:# and Lima >= 2.2.0 defaults that to /bin/bash whatever the guest login shell | |
| 1110 | 新增:# is (lima-vm/lima#5194); older versions used "$SHELL", i.e. the login shell | |
| 1111 | 新增:# `agent-vm.setup.sh` sets with chsh. Agent PATH entries and the | |
| 1112 | 新增:# ~/.agent-vm.env sourcing both live in ~/.zshenv, so under bash the agents are | |
| 1113 | 新增:# not found and anything that is found starts without its API keys. Forcing | |
| 1114 | 新增:# `zsh -l -c` here works on every Lima version. | |
| 1115 | 新增:# | |
| 1116 | 新增:# The command and its arguments are passed as positional parameters, so the | |
| 1117 | 新增:# guest shell never re-parses them; `env` runs the command and keeps leading | |
| 1118 | 新增:# VAR=value assignments working. | |
| 1119 | 新增:# | |
| 1120 | 新增:# Usage: _agent_vm_lima_run <vm_name> <host_dir> <tty:1|""> <command> [args...] | |
| 1121 | 新增:_agent_vm_lima_run() { | |
| 1122 | 新增: local vm_name="$1" host_dir="$2" want_tty="$3" | |
| 1123 | 新增: shift 3 | |
| 1124 | 新增: local shell_opts=(--workdir "$host_dir") | |
| 1125 | 新增: [[ -n "$want_tty" ]] && shell_opts+=(--tty) | |
| 1126 | 新增: limactl shell "${shell_opts[@]}" "$vm_name" -- zsh -l -c 'exec env "$@"' agent-vm "$@" | |
| 1127 | 新增:} | |
| 1128 | 新增: | |
| 1106 | 1129 | _agent_vm_claude() { |
| 1107 | 1130 | local vm_opts=() |
| 1108 | 1131 | local args=() |
| @@ -1129,7 +1152,7 @@ _agent_vm_claude() { | ||
| 1129 | 1152 | _agent_vm_print_resources "$vm_name" |
| 1130 | 1153 | |
| 1131 | 1154 | local exit_code=0 |
| 1132 | 删除: limactl shell --workdir "$host_dir" "$vm_name" -- claude --dangerously-skip-permissions "${args[@]}" | |
| 1155 | 新增: _agent_vm_lima_run "$vm_name" "$host_dir" "" claude --dangerously-skip-permissions "${args[@]}" | |
| 1133 | 1156 | exit_code=$? |
| 1134 | 1157 | [[ -n "$rm" ]] && { echo "Removing VM..."; _agent_vm_destroy; } |
| 1135 | 1158 | return $exit_code |
| @@ -1164,7 +1187,7 @@ _agent_vm_opencode() { | ||
| 1164 | 1187 | # giving full autonomy (safe inside the sandbox). This is OpenCode's shipped |
| 1165 | 1188 | # equivalent of a "yolo" mode; the proposed --yolo flag was never merged. |
| 1166 | 1189 | local exit_code=0 |
| 1167 | 删除: limactl shell --tty --workdir "$host_dir" "$vm_name" opencode --auto "${args[@]}" | |
| 1190 | 新增: _agent_vm_lima_run "$vm_name" "$host_dir" 1 opencode --auto "${args[@]}" | |
| 1168 | 1191 | exit_code=$? |
| 1169 | 1192 | [[ -n "$rm" ]] && { echo "Removing VM..."; _agent_vm_destroy; } |
| 1170 | 1193 | return $exit_code |
| @@ -1196,7 +1219,7 @@ _agent_vm_codex() { | ||
| 1196 | 1219 | _agent_vm_print_resources "$vm_name" |
| 1197 | 1220 | |
| 1198 | 1221 | local exit_code=0 |
| 1199 | 删除: limactl shell --workdir "$host_dir" "$vm_name" codex --dangerously-bypass-approvals-and-sandbox "${args[@]}" | |
| 1222 | 新增: _agent_vm_lima_run "$vm_name" "$host_dir" "" codex --dangerously-bypass-approvals-and-sandbox "${args[@]}" | |
| 1200 | 1223 | exit_code=$? |
| 1201 | 1224 | [[ -n "$rm" ]] && { echo "Removing VM..."; _agent_vm_destroy; } |
| 1202 | 1225 | return $exit_code |
| @@ -1230,7 +1253,7 @@ _agent_vm_vibe() { | ||
| 1230 | 1253 | # Vibe is a full-screen TUI, so allocate a tty (like opencode). |
| 1231 | 1254 | # --agent auto-approve gives full autonomy (safe inside the sandbox). |
| 1232 | 1255 | local exit_code=0 |
| 1233 | 删除: limactl shell --tty --workdir "$host_dir" "$vm_name" vibe --agent auto-approve "${args[@]}" | |
| 1256 | 新增: _agent_vm_lima_run "$vm_name" "$host_dir" 1 vibe --agent auto-approve "${args[@]}" | |
| 1234 | 1257 | exit_code=$? |
| 1235 | 1258 | [[ -n "$rm" ]] && { echo "Removing VM..."; _agent_vm_destroy; } |
| 1236 | 1259 | return $exit_code |
| @@ -1322,11 +1345,8 @@ _agent_vm_run() { | ||
| 1322 | 1345 | # full-screen TUIs (opencode, vibe, htop, …) need to render correctly when |
| 1323 | 1346 | # invoked through `agent-vm run`. Without it, line-mode tools work fine but |
| 1324 | 1347 | # ncurses-style UIs break. |
| 1325 | 删除: local shell_opts=(--workdir "$host_dir") | |
| 1326 | 删除: [[ -n "$tty_flag" ]] && shell_opts+=(--tty) | |
| 1327 | 删除: | |
| 1328 | 1348 | local exit_code=0 |
| 1329 | 删除: limactl shell "${shell_opts[@]}" "$vm_name" "${args[@]}" | |
| 1349 | 新增: _agent_vm_lima_run "$vm_name" "$host_dir" "$tty_flag" "${args[@]}" | |
| 1330 | 1350 | exit_code=$? |
| 1331 | 1351 | [[ -n "$rm" ]] && { echo "Removing VM..."; _agent_vm_destroy; } |
| 1332 | 1352 | return $exit_code |

