| @@ -77,6 +77,17 @@ _agent_vm_ensure_running() { |
| 77 | 77 | esac |
| 78 | 78 | done |
| 79 | 79 | |
| 80 | +新增: # Lima's host mount cannot share a path containing whitespace: the mount |
| 81 | +新增: # fails silently and the VM starts with a bare, root-owned mountpoint, so |
| 82 | +新增: # every write into the project (e.g. creating .claude) fails with |
| 83 | +新增: # "Permission denied". Fail fast with an actionable message instead. |
| 84 | +新增: if [[ "$host_dir" == *[[:space:]]* ]]; then |
| 85 | +新增: echo "Error: project path contains whitespace, which Lima cannot mount:" >&2 |
| 86 | +新增: echo " $host_dir" >&2 |
| 87 | +新增: echo "Rename the directory to remove spaces (e.g. with '-'), then retry." >&2 |
| 88 | +新增: return 1 |
| 89 | +新增: fi |
| 90 | +新增: |
| 80 | 91 | if ! limactl list -q 2>/dev/null | grep -q "^${AGENT_VM_TEMPLATE}$"; then |
| 81 | 92 | echo "Error: Base VM not found. Run 'agent-vm setup' first." >&2 |
| 82 | 93 | return 1 |
| @@ -158,6 +169,32 @@ _agent_vm_ensure_running() { |
| 158 | 169 | limactl start "$vm_name" &>/dev/null |
| 159 | 170 | fi |
| 160 | 171 | |
| 172 | +新增: # Sanity-check that the project directory is actually shared and writable. |
| 173 | +新增: # A silently-failed or stale mount leaves a bare, root-owned mountpoint; |
| 174 | +新增: # without this check every later write (runtime scripts, the agent itself) |
| 175 | +新增: # fails with a confusing cascade of "Permission denied" instead of one clear |
| 176 | +新增: # error. Runs before the optional --readonly remount below, so it reflects |
| 177 | +新增: # the mount itself, not the requested read-only restriction. |
| 178 | +新增: # |
| 179 | +新增: # If the mount is broken, try to self-heal once: re-apply the mount config |
| 180 | +新增: # (Lima only allows editing a stopped VM) and restart. This repairs a stale |
| 181 | +新增: # or silently-missing mount without forcing a full --reset, and adds no |
| 182 | +新增: # overhead on the common path where the mount is already healthy. |
| 183 | +新增: if ! limactl shell "$vm_name" test -w "$host_dir" &>/dev/null; then |
| 184 | +新增: echo "Project mount is not writable; repairing..." >&2 |
| 185 | +新增: limactl stop "$vm_name" &>/dev/null |
| 186 | +新增: (cd /tmp && limactl edit "$vm_name" \ |
| 187 | +新增: --set ".mounts = [{\"location\": \"${host_dir}\", \"writable\": true}]") &>/dev/null |
| 188 | +新增: limactl start "$vm_name" &>/dev/null |
| 189 | +新增: if ! limactl shell "$vm_name" test -w "$host_dir" &>/dev/null; then |
| 190 | +新增: echo "Error: project directory is still not writable inside the VM:" >&2 |
| 191 | +新增: echo " $host_dir" >&2 |
| 192 | +新增: echo "The host mount failed to attach. Try 'agent-vm --reset <command>'" >&2 |
| 193 | +新增: echo "to re-clone the VM from the base template." >&2 |
| 194 | +新增: return 1 |
| 195 | +新增: fi |
| 196 | +新增: fi |
| 197 | +新增: |
| 161 | 198 | # Install the host's terminfo entry inside the VM so non-standard terminals |
| 162 | 199 | # (xterm-ghostty, xterm-kitty, …) work correctly. Without this, zsh/ZLE |
| 163 | 200 | # can't decode keys → broken backspace, arrows, etc. Cached per-VM so we only |
| @@ -242,6 +279,19 @@ agent-vm() { |
| 242 | 279 | local cmd="${1:-help}" |
| 243 | 280 | shift 2>/dev/null || true |
| 244 | 281 | |
| 282 | +新增: # Every command except help/setup needs limactl present. (setup installs it |
| 283 | +新增: # itself; help needs nothing.) Without this, stop/list/status/etc. would fail |
| 284 | +新增: # with confusing empty output instead of a clear, actionable message. |
| 285 | +新增: case "$cmd" in |
| 286 | +新增: help|--help|-h|setup) ;; |
| 287 | +新增: *) |
| 288 | +新增: if ! command -v limactl &>/dev/null; then |
| 289 | +新增: echo "Error: limactl (Lima) not found. Run 'agent-vm setup' first, or install" >&2 |
| 290 | +新增: echo "it from https://lima-vm.io/docs/installation/" >&2 |
| 291 | +新增: return 1 |
| 292 | +新增: fi ;; |
| 293 | +新增: esac |
| 294 | +新增: |
| 245 | 295 | case "$cmd" in |
| 246 | 296 | setup) |
| 247 | 297 | _agent_vm_setup "${vm_opts[@]}" "$@" |
| @@ -307,7 +357,7 @@ Commands: |
| 307 | 357 | |
| 308 | 358 | VM options (for claude, opencode, codex, shell, run): |
| 309 | 359 | --disk GB VM disk size (default: 10) |
| 310 | | −删除: --memory GB VM memory (default: 2) |
| 360 | +新增: --memory GB VM memory (default: 3) |
| 311 | 361 | --cpus N Number of CPUs (default: 1) |
| 312 | 362 | --reset Destroy and re-clone the VM from the base template |
| 313 | 363 | --offline Block outbound internet (keeps host/VM communication) |
| @@ -356,7 +406,7 @@ _agent_vm_setup() { |
| 356 | 406 | echo "" |
| 357 | 407 | echo "Options:" |
| 358 | 408 | echo " --disk GB VM disk size (default: 10)" |
| 359 | | −删除: echo " --memory GB VM memory (default: 2)" |
| 409 | +新增: echo " --memory GB VM memory (default: 3)" |
| 360 | 410 | echo " --cpus N Number of CPUs (default: 1)" |
| 361 | 411 | echo " --help Show this help" |
| 362 | 412 | return 0 |