diff --git a/roles/mac/README.md b/roles/mac/README.md index 24c3d24..1391fe9 100644 --- a/roles/mac/README.md +++ b/roles/mac/README.md @@ -25,13 +25,16 @@ Manages cogitator-02, an Apple Silicon Mac on the tailnet (`mac.yml`, - **Hermes settings** (tag `hermes-settings`): the individual keys in `hermes_settings` (`group_vars/mac/main.yml`), checked with `hermes config get` and fixed with `hermes config set` (or `unset` for a - null value); any change restarts the gateway with `hermes gateway restart`. + null value); any change restarts the gateway (`hermes gateway restart`) + and the dashboard. Covers update backups, timezone, not borrowing Claude Code's login, sandbox memory, disabled toolsets, skill-write approval, deny rules, streaming and voice-note transcription. Leave `agent.reasoning_effort` out: `config set` refuses it without `--force` (hermes-agent #140221). -- **Podman VM** (tag `podman`): `podman_machine_memory` for the VM that runs - Hermes's sandbox. A change stops and restarts the VM. +- **Podman VM** (tag `podman`): a launchd job (`local.podman-machine`) that + starts the VM running Hermes's sandbox at login, and `podman_machine_memory` + for its size. A resize stops the VM and starts it again through that job + (a VM started from an Ansible task is stopped when the task ends). - **Hermes cron jobs** (tag `hermes-cron`): `hermes_cron_jobs` in `group_vars/mac/main.yml`, with their scripts from `files/hermes-scripts/` copied to `~/.hermes/scripts/`. Missing jobs are created; existing ones are diff --git a/roles/mac/tasks/hermes-settings.yml b/roles/mac/tasks/hermes-settings.yml index 2f1ca4a..10ab8ae 100644 --- a/roles/mac/tasks/hermes-settings.yml +++ b/roles/mac/tasks/hermes-settings.yml @@ -21,4 +21,5 @@ when: >- (none if item.stdout is search('^Config key not set') else item.stdout | from_yaml) != item.item.value - notify: Restart Hermes gateway + # The dashboard is a separate process with its own copy of the settings. + notify: [Restart Hermes gateway, Restart Hermes dashboard] diff --git a/roles/mac/tasks/podman.yml b/roles/mac/tasks/podman.yml index 8f828c9..45f3f53 100644 --- a/roles/mac/tasks/podman.yml +++ b/roles/mac/tasks/podman.yml @@ -1,5 +1,26 @@ -# Memory for the Podman VM that runs Hermes's sandbox. Changing it means a -# stop/start, which ends any sandbox containers that are running. +# The Podman VM runs Hermes's sandbox containers. A launchd job starts it at +# login, and starts it again after a resize: a VM started from an Ansible task +# gets stopped when the task ends. +- name: Podman VM launchd job + ansible.builtin.template: + src: podman-machine.plist.j2 + dest: "{{ ansible_user_dir }}/Library/LaunchAgents/{{ podman_machine_label }}.plist" + mode: "0644" + +- name: Check the Podman VM job is loaded + ansible.builtin.command: + argv: [launchctl, print, "gui/{{ ansible_user_uid }}/{{ podman_machine_label }}"] + register: podman_job + changed_when: false + failed_when: false + check_mode: false + +- name: Load the Podman VM job + ansible.builtin.command: + argv: [launchctl, bootstrap, "gui/{{ ansible_user_uid }}", + "{{ ansible_user_dir }}/Library/LaunchAgents/{{ podman_machine_label }}.plist"] + when: podman_job.rc != 0 + - name: Read Podman VM memory ansible.builtin.command: argv: [/opt/podman/bin/podman, machine, inspect, --format, !unsafe "{{.Resources.Memory}}"] @@ -7,10 +28,21 @@ changed_when: false check_mode: false +# Stopping ends any sandbox containers that are running. - name: Resize the Podman VM ansible.builtin.shell: | set -e /opt/podman/bin/podman machine stop /opt/podman/bin/podman machine set --memory {{ podman_machine_memory }} - /opt/podman/bin/podman machine start + launchctl kickstart gui/{{ ansible_user_uid }}/{{ podman_machine_label }} when: podman_memory.stdout | int != podman_machine_memory + +- name: Podman VM is running + ansible.builtin.command: + argv: [/opt/podman/bin/podman, machine, inspect, --format, !unsafe "{{.State}}"] + register: podman_state + until: podman_state.stdout == "running" + retries: 12 + delay: 5 + changed_when: false + check_mode: false diff --git a/roles/mac/templates/podman-machine.plist.j2 b/roles/mac/templates/podman-machine.plist.j2 new file mode 100644 index 0000000..ac56de6 --- /dev/null +++ b/roles/mac/templates/podman-machine.plist.j2 @@ -0,0 +1,29 @@ + + + + + + Label + {{ podman_machine_label }} + + ProgramArguments + + /opt/podman/bin/podman + machine + start + + EnvironmentVariables + + PATH + /opt/podman/bin:/usr/bin:/bin:/usr/sbin:/sbin + + RunAtLoad + + KeepAlive + + StandardOutPath + {{ ansible_user_dir }}/Library/Logs/podman-machine.log + StandardErrorPath + {{ ansible_user_dir }}/Library/Logs/podman-machine.log + + diff --git a/roles/mac/vars/main.yml b/roles/mac/vars/main.yml index b779b37..818d3e9 100644 --- a/roles/mac/vars/main.yml +++ b/roles/mac/vars/main.yml @@ -3,3 +3,4 @@ hermes_env: "{{ ansible_user_dir }}/.hermes/.env" hermes_dashboard_label: local.hermes-dashboard tailscale_cli: /Applications/Tailscale.app/Contents/MacOS/Tailscale hermes_cli: "{{ ansible_user_dir }}/.local/bin/hermes" +podman_machine_label: local.podman-machine