goose knows about nix
This commit is contained in:
1 parent
25fcf85855
commit
25f648d606
8 files changed
+35
-11
No files matched your search
+4
-2
@@ -31,11 +31,13 @@ flowchart LR
|
||||
|
||||
**Lifecycle threads:** `manager.EnsureProgress` reports `StartEvent`s (placing, booting, registered) only when it really starts a container. The bot (`bot/lifecycle.go`) turns them into replies in a dedicated top-level message for that container, pins it, and unpins the previous run's message. The message's channel and timestamp are kept on the owner (`lifecycle_channel`, `lifecycle_ts`). The user's thread only gets a link. Stops (`stop`, the button, the idle reaper) post to the same thread, and `manager.WaitStopped` confirms when the machine is gone.
|
||||
|
||||
**Files:** attachments on a message (`file_share`, or `files` on an `app_mention`) are downloaded by the bot and written into the home with the node's `write_file` call, then their paths are added to the prompt. The other way, goose gets the `slackerbot` MCP server (`slackerbot tools`, run inside the container as `slackerbot-tools`) through `mcpServers` in `session/new` and `session/load`. Its `send_file` tool only checks the path and size and answers "queued". The bot watches the ACP `tool_call` / `tool_call_update` messages, and when a `send_file` call completes it reads the file with `read_file` and uploads it to the thread with `files.uploadV2`. Bytes go node → master → Slack, so slaves never need a Slack token. Both calls work in 4 MB chunks, open files with `os.Root` so symlinks and `..` can't leave the home, and are capped by `max_send_file_mb`. An older slave answers "unknown call", which surfaces as `node.ErrTooOld` and a polite reply.
|
||||
**Files:** attachments on a message (`file_share`, or `files` on an `app_mention`) are downloaded by the bot and written into the home with the node's `write_file` call, then their paths are added to the prompt. The other way, goose gets the `slackerbot` MCP server (`slackerbot tools`, run inside the container as `slackerbot-tools`) through `mcpServers` in `session/new` and `session/load`. Its `initialize` reply carries `instructions` (how to use Nix in the container), which goose adds to its system prompt. Its `send_file` tool only checks the path and size and answers "queued". The bot watches the ACP `tool_call` / `tool_call_update` messages, and when a `send_file` call completes it reads the file with `read_file` and uploads it to the thread with `files.uploadV2`. Bytes go node → master → Slack, so slaves never need a Slack token. Both calls work in 4 MB chunks, open files with `os.Root` so symlinks and `..` can't leave the home, and are capped by `max_send_file_mb`. An older slave answers "unknown call", which surfaces as `node.ErrTooOld` and a polite reply.
|
||||
|
||||
**Commands as tools:** the same MCP server also lists one tool per Slack command (`tools.Commands`: `status`, `scale`, `keep`, `storage`, `move`, `listen`, `grant`, …), each with an optional `args` string that's appended to the verb, exactly as a user would type it. The MCP server can't reach the bot, so the call goes round: the bot spots the `tool_call` over ACP (`tools.CommandCall`), runs the command through the same code as Slack (`bot.runCommand`, `bot.move`) as the user whose message started the turn, and writes the reply with `write_file` to `/root/.slackerbot/replies/<hash of tool and args>-<random>.json`. The server waits up to a minute for a file with that prefix and claims it by deleting it. Commands that change something are also posted in the thread. `stop` waits for the turn to end (`agentCommands.Finish`), and `move` reports as soon as it starts, since its final pass waits for the reply to finish anyway.
|
||||
|
||||
**Containers** are `systemd-nspawn` machines started through `systemd-run`, each in its own `slackerbot-<machine>.service` unit, with CPU and memory limits. They boot the NixOS system built by `nix build .#agent` (`nix/container.nix`), which runs `goose serve` on port 1984. `/nix/store` is shared read-only. `/root` is bind-mounted from a btrfs subvolume on one of the node's drives, and is the only thing that persists. `ro_binds` and `rw_binds` add more mounts, and their missing source folders are created first. The agent's env file (API keys, the per-container goose secret) is written by the host and bind-mounted in read-only.
|
||||
**Containers** are `systemd-nspawn` machines started through `systemd-run`, each in its own `slackerbot-<machine>.service` unit, with CPU and memory limits. They boot the NixOS system built by `nix build .#agent` (`nix/container.nix`), which runs `goose serve` on port 1984. Containers use user namespacing (`--private-users=pick`), so their root is an unprivileged uid on the host. `/root` is bind-mounted from a btrfs subvolume on one of the node's drives, and is the only thing that persists. `ro_binds` and `rw_binds` add more mounts, and their missing source folders are created first. The agent's env file (API keys, the per-container goose secret) is written by the host and bind-mounted in read-only. The home, the env file and `/nix/store` (read-only) are mounted with `idmap`, so files stay owned by host root on disk and show up as container root inside.
|
||||
|
||||
**Nix in containers:** the host's `/nix/var/nix/daemon-socket` is bind-mounted in, and `container.nix` turns off the container's own `nix-daemon` and enables flakes. `nix build`/`nix develop` inside a container go to the host daemon, which sees an unprivileged uid and so treats it as an untrusted user: builds are sandboxed and it can't add substituters or import unsigned paths. Outputs land in the shared store, outside the home quota, and aren't GC roots on the host. The MCP server's `initialize` `instructions` tell goose to use a flake and `devShells.default` for each project.
|
||||
|
||||
**System updates:** each node reports running containers whose `slackerbot-<machine>.service` command ends with a different system's `init` than the node's current `system` (`outdated` in `RunningMachine`, read over D-Bus; unknown counts as current). After a reply, the bot asks once per container (`bot/update.go`, remembered in memory) whether to restart. **Restart now** calls `manager.Restart` (power off, wait, then the normal start), unless a reply is in progress.
|
||||
|
||||
|
||||
Reference in new issue
Block a user