@astrofoundry/astrogate 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -2
- package/agents/foreman.md +27 -0
- package/cli/astro-install.sh +242 -0
- package/cli/astro.sh +449 -0
- package/cli/astro.test.ts +65 -0
- package/cli/astrogate.sh +309 -0
- package/cli/astrogate.test.ts +113 -0
- package/cli/verify-release.sh +77 -0
- package/cli/verify-release.test.ts +140 -0
- package/dist/bridge.js +9950 -0
- package/dist/claude.js +7899 -0
- package/dist/extensions/bridge/index.js +9937 -0
- package/dist/extensions/gate/index.js +286 -0
- package/dist/extensions/guard/index.js +364 -0
- package/dist/extensions/subagents/index.js +8458 -0
- package/extensions/bridge/admin.ts +86 -0
- package/extensions/bridge/approvals.ts +147 -0
- package/extensions/bridge/attachments.ts +65 -0
- package/extensions/bridge/chunk.ts +50 -0
- package/extensions/bridge/claude-run.test.ts +62 -0
- package/extensions/bridge/claude-run.ts +301 -0
- package/extensions/bridge/commands.ts +89 -0
- package/extensions/bridge/config.ts +263 -0
- package/extensions/bridge/conversations.ts +144 -0
- package/extensions/bridge/daemon.ts +60 -0
- package/extensions/bridge/discord.test.ts +547 -0
- package/extensions/bridge/gateway.ts +222 -0
- package/extensions/bridge/index.ts +951 -0
- package/extensions/bridge/launcher.ts +36 -0
- package/extensions/bridge/lifecycle.test.ts +78 -0
- package/extensions/bridge/open-work.ts +74 -0
- package/extensions/bridge/plugin.ts +172 -0
- package/extensions/bridge/quote.ts +39 -0
- package/extensions/bridge/reports.ts +65 -0
- package/extensions/bridge/rest.ts +217 -0
- package/extensions/bridge/setup.ts +218 -0
- package/extensions/gate/approvals.test.ts +40 -0
- package/extensions/gate/config.ts +110 -0
- package/extensions/gate/core.ts +114 -0
- package/extensions/gate/index.test.ts +202 -0
- package/extensions/gate/index.ts +114 -0
- package/extensions/gate/risky.ts +14 -0
- package/extensions/gate/types.ts +19 -0
- package/extensions/guard/config.test.ts +107 -0
- package/extensions/guard/config.ts +120 -0
- package/extensions/guard/defaults.ts +40 -0
- package/extensions/guard/index.test.ts +313 -0
- package/extensions/guard/index.ts +183 -0
- package/extensions/guard/rules.test.ts +118 -0
- package/extensions/guard/rules.ts +101 -0
- package/extensions/guard/types.ts +12 -0
- package/extensions/subagents/agents.test.ts +137 -0
- package/extensions/subagents/agents.ts +207 -0
- package/extensions/subagents/bundled.test.ts +29 -0
- package/extensions/subagents/child.test.ts +202 -0
- package/extensions/subagents/child.ts +367 -0
- package/extensions/subagents/index.test.ts +123 -0
- package/extensions/subagents/index.ts +352 -0
- package/extensions/subagents/pi-paths.test.ts +39 -0
- package/extensions/subagents/pi-paths.ts +58 -0
- package/extensions/subagents/render.ts +221 -0
- package/extensions/subagents/sessions.test.ts +32 -0
- package/extensions/subagents/sessions.ts +34 -0
- package/extensions/subagents/ticker.test.ts +40 -0
- package/extensions/subagents/ticker.ts +36 -0
- package/harness/claude/agents.ts +93 -0
- package/harness/claude/claude.test.ts +171 -0
- package/harness/claude/hook.ts +77 -0
- package/harness/claude/main.ts +122 -0
- package/harness/claude/mcp.ts +174 -0
- package/harness/claude/settings.ts +63 -0
- package/package.json +71 -4
- package/release.sha256 +99 -0
- package/release.sha256.sig +6 -0
- package/specialists/AGENTS.md +67 -0
- package/specialists/README.md +81 -0
- package/specialists/entry/specialist-cli.sh +22 -0
- package/specialists/entry/specialist-install.sh +861 -0
- package/specialists/entry/specialist-install.test.ts +305 -0
- package/specialists/lib/argv.ts +19 -0
- package/specialists/lib/audit.ts +20 -0
- package/specialists/lib/config.ts +27 -0
- package/specialists/lib/errors.ts +8 -0
- package/specialists/lib/flush.test.ts +21 -0
- package/specialists/lib/lib.test.ts +87 -0
- package/specialists/lib/lock.test.ts +42 -0
- package/specialists/lib/lock.ts +67 -0
- package/specialists/lib/main.ts +40 -0
- package/specialists/lib/output.ts +11 -0
- package/specialists/lib/paths.ts +22 -0
- package/specialists/lib/pinned.test.ts +55 -0
- package/specialists/lib/pinned.ts +67 -0
- package/specialists/lib/proc.ts +49 -0
- package/specialists/lib/repo.ts +198 -0
- package/specialists/lib/runtime.test.ts +81 -0
- package/specialists/lib/sanitize.ts +43 -0
- package/specialists/lib/secrets.ts +28 -0
- package/specialists/lib/ssh.ts +38 -0
- package/specialists/lib/tunnel.test.ts +44 -0
- package/specialists/lib/tunnel.ts +76 -0
- package/specialists/provision/provision.sh +96 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Specialists: implementation notes
|
|
2
|
+
|
|
3
|
+
Read `README.md` in this folder first: it defines the model, the host setup, and the limits. This file is for changing the framework: the shared library, the entry point, the root installer, the gate, and the pack format. The specialists themselves (wrappers, agents, skills, risky patterns) live in a site pack; the 37 and Mira pack is `homelab/astro-site/`, with its own `AGENTS.md`.
|
|
4
|
+
|
|
5
|
+
## Boundaries, in one table
|
|
6
|
+
|
|
7
|
+
| Control | Where | Strength |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| What an identity may do | Service side: Arcane role, Zitadel role, UniFi key scope, forced commands on SSH targets | Hard |
|
|
10
|
+
| Credential confidentiality | macOS user `specialist`, home `0700`, one sudo entry point, password for general sudo | Hard |
|
|
11
|
+
| Reach of an SSH key | Forced command on the target; on the VPS also an exact sudoers list; the IAP service account can only open tunnels | Hard |
|
|
12
|
+
| Short-lived Arcane access | Zitadel JWT profile token per call, 300 s Arcane token | Hard |
|
|
13
|
+
| Audit | `~/.specialists/audit.log`, one JSON line per call | Hard (`--caller` is informational) |
|
|
14
|
+
| One specialist per note | Construction: one tool, one wrapper, one secrets folder; agent has no `bash`, `write`, `edit` | Soft |
|
|
15
|
+
| Only the specialist child has the tool | `specialist-gate` matches `ASTRO_SUBAGENT_AGENT`; blocks elsewhere; `security-guard` duplicates the blocks | Soft |
|
|
16
|
+
|
|
17
|
+
macOS cannot tell which agent made a call; the OS user protects the credential, the service decides what the identity may do. Do not present the gate as a security boundary.
|
|
18
|
+
|
|
19
|
+
## Layout
|
|
20
|
+
|
|
21
|
+
```text
|
|
22
|
+
extensions/specialist-gate/ index.ts (tool registration, tool_call blocks, /specialists), risky.ts (no Pi imports, packs test against it), config.ts, types.ts
|
|
23
|
+
specialists/lib/ secrets.ts, config.ts, proc.ts, ssh.ts, tunnel.ts, repo.ts, pinned.ts, sanitize.ts, audit.ts, argv.ts, main.ts, output.ts, paths.ts, errors.ts, lock.ts;
|
|
24
|
+
a pack adds its own service helpers to its copy of lib/ (the 37 and Mira pack keeps them in specialists/site-lib/)
|
|
25
|
+
specialists/provision/ provision.sh (Vaultwarden to files)
|
|
26
|
+
specialists/entry/ specialist-cli.sh (sudo entry point), specialist-install.sh (root installer for Node, signed packs, arcane-cli, trendarr, python, gcloud, bw, jq)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Wrappers ship as TypeScript and run under Node 24 type stripping: erasable syntax only (no enums, namespaces, parameter properties), explicit `.ts` import extensions. A pack copies `lib/` from the pi-astro version it pins and may add its own helpers to that copy; `specialist-install pack <version>` installs the pack's wrappers and `lib/` into `~/.specialists/bin/`, and the entry point runs them with the root-owned Node, `/usr/local/libexec/specialist-node/current/bin/node`.
|
|
30
|
+
|
|
31
|
+
## Rules for wrapper code
|
|
32
|
+
|
|
33
|
+
- No shell. `run()` spawns an executable with an argument array; secrets travel in `env` or `stdin`, never argv.
|
|
34
|
+
- Secrets only through `readSecret(service, FIELD)`; it refuses files wider than `0600` and names outside `UPPER_SNAKE`.
|
|
35
|
+
- Config only through `readConfig(service, shape)`; every field required, no fallbacks, no env vars.
|
|
36
|
+
- Exit codes: `UsageError` 2, `ServiceError` 1, success 0. Diagnostics on stderr, results on stdout, JSON where possible.
|
|
37
|
+
- Output filters (`lib/sanitize.ts`): `stripKeys(value, denied)` removes a service's secret-bearing keys at every depth, with a list the pack keeps for that service; `redactSecrets` masks values under secret-like key names. A pack adds keys to its list rather than filtering in a wrapper.
|
|
38
|
+
- Repository access is `lib/repo.ts` (`repoCommand`, `RepoSpec`, `trackedFile`): one clone per specialist under `~/.specialists/work/<checkoutName>` (`homelab-edge`, `homelab-identity`; never share a checkout between specialists), a write deploy key, and an optional `writeRoot` that limits `git write` and refuses its `system/` folders (entry scripts, sudoers). Paths with a `.git` segment in any case are refused (APFS ignores case). `edge` (`deploy-nginx`) and `identity` (`dmz deploy-config`) deploy only what origin has: `trackedFile` refuses a dirty, ahead, or behind checkout. The DMZ entry keeps the previous template and restores it when render or restart fails.
|
|
39
|
+
- Pi executes sibling tool calls in parallel, so two wrapper processes of the same specialist can run at once. `lib/lock.ts` (`withLock`, a directory lock under `~/.specialists/work/locks`, stale after 10 minutes) serialises shared resources; `edge` holds `edge-tunnel` around the fixed IAP port and the gcloud configuration directory. `arcane` holds `arcane-gitops` (stale after 3 hours) around `git`, `manager-upgrade`, `stack-update`, and `stack-rollback`, because an update keeps the checkout for up to about two hours; `dns` holds `dns-node-change` around `technitium host <node> restart|upgrade` and refuses a second one at once; the other `repo.ts` checkouts are not locked yet.
|
|
40
|
+
- TLS pinning for self-signed consoles is `lib/pinned.ts` (`pinnedRequest`): it opens the TLS socket, checks the fingerprint on `secureConnect`, and only then sends the request on that socket (`createConnection`), so a wrong peer never receives the API key; `network` and `proxmox` use it with a `*CertSha256` config value obtained once through the wrapper's `fingerprint` command.
|
|
41
|
+
- Every wrapper answers `--help` without reading config, so agents can discover subcommands before anything else is set up.
|
|
42
|
+
- `entry/specialist-install.sh` runs as root, so it runs only `/usr/bin`, `/bin`, `/usr/sbin`, `/sbin` and the Node it installed, never Homebrew or anything else the main user can write; it checks that `/usr/local/libexec/specialist-node` (and each `specialist-<tool>` folder) and its parents belong to root and are writable by nobody else. Arguments are checked before the root test (tests exercise that part). Downloads go to a root-only temporary directory and are verified before use: Node against `SHASUMS256.txt` and the LTS flag in `index.json`, npm tarballs against the registry's `sha512` integrity, arcane-cli against the release's checksums file. Inside `/Users/specialist` it works only as `specialist` (`sudo -u specialist -H`), from a staging directory root hands over, so a link the specialist plants cannot redirect a root write. Each component switches by rename after a check (every installed wrapper's `--help`, `--version` of the new binary) and restores the previous copy when the check fails. Older versions are refused; `rollback` swaps current and previous. `python`, `gcloud`, `bw`, and `jq` follow the same rules: version folders under `/usr/local/libexec/specialist-<tool>/` behind the links `current` and `previous`, sealed `root:wheel` and not writable by others, smoke-tested as `specialist` before `current` moves; `python` refuses a switch that breaks the current gcloud. Consumers use the `current` paths: `provision.sh` for `bw` and `jq`, `edge.json` for `gcloud` and `gcloudPython`. Nothing a wrapper runs with secrets may come from Homebrew.
|
|
43
|
+
- `main()` waits for stdout and stderr to flush before `process.exit`: on a pipe, exiting right after a write drops everything past the 64 KiB buffer, which cut large answers such as `projects list --all` until 2026-09-25 (`lib/flush.test.ts`).
|
|
44
|
+
|
|
45
|
+
## Gate
|
|
46
|
+
|
|
47
|
+
`extensions/specialist-gate/index.ts` loads `~/.pi/agent/specialists.json` (`PI_CODING_AGENT_DIR` overrides the directory in tests). `astro-subagents` sets `ASTRO_SUBAGENT_AGENT` on every child it spawns; with a matching value the gate registers the tool and runs `sudo -n -u <user> -H <entry> <service> --caller <agent> -- <args>` through `pi.exec`, raising the CLI's stderr as the tool error. In every session it blocks `bash` commands containing `specialist-cli`, `arcane-cli`, `<service>-run`, `-u <user>`, `su <user>`, and `read`/`write`/`edit` under `/Users/<user>`. An invalid config keeps the blocks with defaults and reports the error on `session_start`.
|
|
48
|
+
|
|
49
|
+
## Packs
|
|
50
|
+
|
|
51
|
+
A pack is a signed tarball: `pack.json` (name, version, the pi-astro version of its `lib/`, and per specialist `service`, `agent` = `astro.<service>`, `tool` = `<service>`, `timeoutMs`, `risky`), `agents/<service>.md`, `skills/<service>/SKILL.md`, `specialists/<service>/run.ts`, `specialists/lib/`, and `specialists/provision/provision.sh`. A pack may add `bridge/index.js` (the site's bridge plugin) and `site/`: `site.json` (the Vaultwarden server and tool versions, which `astro install` reads on a new machine) and `config/` (the specialists' config files: `<service>.json`, or a `.yml` a wrapper names).
|
|
52
|
+
|
|
53
|
+
- Trust: `specialist-install pack <version>` takes `pack-<version>.tgz` and its `.sig` from `/private/var/tmp/astro-pack`, checks the SSH signature (`ssh-keygen -Y verify`, namespace and identity `astro-pack`) against the root-owned `/usr/local/etc/astro/allowed_signers`, refuses a version older than the installed one, checks every service name (`valid_service`), and swaps the wrappers in. It then writes the pack's `site/config/` files into `~/.specialists/config/` as `specialist` (plain files up to 64 KiB with a valid name; JSON must parse, checked before the swap), replacing files of the same name and leaving the others. The signed pack is the only source of a specialist's config: a change is a pack release, and a hand edit lasts until the next pack that carries a different file. A replaced file stays in `~/.specialists/rollback/wrappers/.config/`, and `rollback wrappers` swaps it back with the wrappers. The npm `wrappers` action stays for hosts without a pack; its 0.40.x versions are older than any pack 1.x, so it cannot replace a pack.
|
|
54
|
+
- Agents and skills: `astro-subagents` loads `~/.pi/agent/pack/agents/*.md` as `astro.<name>` (source `pack`, after bundled, before user and project agents) and resolves skills in `~/.pi/agent/pack/skills` first.
|
|
55
|
+
- Install on a host: `astro update pack <version>` (`cli/astro.sh`) checks the signature, runs `specialist-install pack`, puts the agents, skills, and bridge plugin in `~/.pi/agent/pack/` (the previous pack stays in `pack.previous`), and writes the pack's specialists, timeouts, and risky patterns into `~/.pi/agent/specialists.json` (the previous file stays as `specialists.json.before-pack`); `astro rollback pack` swaps both back. Without `risky`, only `--confirm` asks for approval.
|
|
56
|
+
|
|
57
|
+
## Adding a specialist
|
|
58
|
+
|
|
59
|
+
Add it to the site pack (see the pack's `AGENTS.md`). The framework needs no change: `specialist-cli` runs any installed service whose name matches `^[a-z][a-z0-9-]{0,30}$` except `lib`, `VERSION`, and `rollback`, and `provision` is its own action. A helper two packs could share goes into `specialists/lib/` with its tests; a helper for one site's services stays in that pack.
|
|
60
|
+
|
|
61
|
+
## Harnesses
|
|
62
|
+
|
|
63
|
+
The specialists do not depend on Pi: the entry point, the wrappers, and the pack work for any caller. `extensions/specialist-gate/core.ts` (approval request, guard markers, entry arguments, failure texts) has no Pi imports and serves two harnesses. Pi registers the tool in the specialist child (`index.ts`). Claude Code gets `harness/claude/`: an MCP server per specialist, defined inline in its `astro-<service>` subagent so no other session has the tool, and a PreToolUse hook that blocks the same commands and paths as the Pi guard, refuses a specialist tool outside its subagent, and asks Claude Code's permission prompt for a risky call (including in auto mode, where a hook's ask goes to the prompt; it refuses one in bypass and dontAsk modes). From a chat bridge both harnesses ask the bridge's owners instead: the Pi gate in the tool, the Claude Code hook before the call (a headless `claude -p` denies an `ask` outright, and hooks see the bridge's environment). The MCP server itself never approves anything.
|
|
64
|
+
|
|
65
|
+
## Chat bridges
|
|
66
|
+
|
|
67
|
+
`extensions/astro-discord/` runs specialists for Discord messages through `runAgent` and passes `ASTRO_APPROVAL_URL`/`ASTRO_APPROVAL_TOKEN` to the child. The gate checks `isRisky(args, entry.risky)` from `risky.ts` and blocks on a ticket until an owner decides (no exemption for `--help` or `-h`, because a wrapper reads help only as the first argument and would run the command otherwise; flags are ignored when matching, so they cannot hide a command). Every `--confirm` command is risky by construction; the pack keeps its patterns in step with its wrappers.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Specialists
|
|
2
|
+
|
|
3
|
+
A specialist is a Pi subagent that is the only way to operate one area of a site. It has one tool, one skill, and one Vaultwarden note. Every other agent is blocked from the area's CLIs and credentials.
|
|
4
|
+
|
|
5
|
+
pi-astro ships the framework: the gate, the sudo entry point, the root installer, the shared wrapper library, and `provision`. The specialists come from a signed site pack, installed per host; the 37 and Mira pack is `homelab/astro-site/` (`SETUP.md` there lists its specialists and the host setup).
|
|
6
|
+
|
|
7
|
+
Call one with `/run astro.<name> -- <task>` or through the `subagent` tool (both from the bundled `astro-subagents` extension). `/run` saves the specialist's session under `~/.pi/agent/subagent-sessions/<agent>/`; `/run astro.<name> --continue -- <task>` resumes the last one started from the same directory, so the specialist keeps what it saw. Sessions older than 7 days are deleted. Specialists may call each other once (`maxSubagentDepth: 1`). They run on `openai-codex/gpt-6-astra` with `xhigh` thinking, set by `model` and `thinking` in each `agents/<name>.md`; an agent without these fields inherits the caller's model and thinking. Each tool takes `args`, an array of strings; `["--help"]` lists the subcommands.
|
|
8
|
+
|
|
9
|
+
## How it is secured
|
|
10
|
+
|
|
11
|
+
- Credentials and CLIs belong to a dedicated macOS user `specialist` on the host. Agents run as the main user and reach the wrappers only through `sudo -n -u specialist -H /usr/local/bin/specialist-cli`, the single passwordless sudo rule. General sudo asks for a password.
|
|
12
|
+
- Credentials come from Vaultwarden (`homelab` / `specialists`, one Secure Note per specialist) through `specialist-cli provision`, into `0600` files. Wrappers never call `bw`.
|
|
13
|
+
- The wrappers run on a root-owned Node in `/usr/local/libexec/specialist-node/` (latest LTS from nodejs.org), not on Homebrew's, because the main user owns all of `/opt/homebrew` and could otherwise swap the interpreter that reads every secret. `/usr/local/sbin/specialist-install` (root, one passwordless sudo rule) installs that Node, the signed pack's wrappers, and the tools the wrappers run with secrets from downloads it checks against the publisher's checksums; it refuses older versions and keeps the previous one for `rollback`.
|
|
14
|
+
- Services use short-lived tokens, API keys, or SSH keys that the targets pin to forced commands.
|
|
15
|
+
- A pack installs only with an SSH signature from a key in the root-owned `/usr/local/etc/astro/allowed_signers`, which the owner installs with their own sudo.
|
|
16
|
+
- Every call is logged in `/Users/specialist/.specialists/audit.log`.
|
|
17
|
+
- The `specialist-gate` extension registers the tool only inside the matching specialist child and blocks other agents from calling the CLIs or reading `/Users/specialist`. `security-guard` carries the same blocks.
|
|
18
|
+
|
|
19
|
+
## Enable specialists on a host
|
|
20
|
+
|
|
21
|
+
The short way: with Node, Pi, and pi-astro installed, put the pack's `pack-<version>.tgz` and `.sig` into `/private/var/tmp/astro-pack/` and run, in a terminal, `sh ~/.pi/agent/npm/node_modules/@astrofoundry/pi-astro/cli/astro.sh install <version> <allowed_signers file>`. It prints what is missing (signing key, root files, sudo rules, the `specialist` user, the tools and config the pack's `site/` folder names, the Vaultwarden login, the pack), changes nothing before you confirm, asks for your sudo password and the specialists' Vaultwarden API key and master password, and ends with `astro doctor`. It skips what is already there, so it can run again. It sets up Claude Code's subagents when `claude` is installed and no Discord bridge. The steps below are what it does, for a setup by hand.
|
|
22
|
+
|
|
23
|
+
Steps for macOS; `<main>` is the user that runs Pi. The pack's own setup lists its Vaultwarden notes, config files, and SSH targets. A pack that carries config files writes them on every install, so a config change is a pack release.
|
|
24
|
+
|
|
25
|
+
1. **User and sudo**, as an administrator:
|
|
26
|
+
```sh
|
|
27
|
+
printf '<main> ALL=(specialist) NOPASSWD: /usr/local/bin/specialist-cli\n' | sudo tee /etc/sudoers.d/specialists >/dev/null
|
|
28
|
+
printf '<main> ALL=(root) NOPASSWD: /usr/local/sbin/specialist-install\n' | sudo tee /etc/sudoers.d/specialist-install >/dev/null
|
|
29
|
+
sudo chmod 0440 /etc/sudoers.d/specialists /etc/sudoers.d/specialist-install && sudo visudo -c
|
|
30
|
+
sudo sysadminctl -addUser specialist -fullName "Specialists" -home /Users/specialist -shell /bin/zsh -password -
|
|
31
|
+
sudo dscl . create /Users/specialist IsHidden 1 && sudo createhomedir -c -u specialist && sudo chmod 700 /Users/specialist
|
|
32
|
+
sudo install -d -m 0755 -o root -g wheel /usr/local/sbin /usr/local/etc /usr/local/etc/astro
|
|
33
|
+
sudo install -m 0755 -o root -g wheel <package>/specialists/entry/specialist-install.sh /usr/local/sbin/specialist-install
|
|
34
|
+
sudo install -m 0755 -o root -g wheel <package>/specialists/entry/specialist-cli.sh /usr/local/bin/specialist-cli
|
|
35
|
+
sudo install -m 0644 -o root -g wheel <pack>/allowed_signers /usr/local/etc/astro/allowed_signers
|
|
36
|
+
sudo /usr/local/sbin/specialist-install node <LTS version>
|
|
37
|
+
sudo /usr/local/sbin/specialist-install jq <version>
|
|
38
|
+
sudo /usr/local/sbin/specialist-install bw <version>
|
|
39
|
+
```
|
|
40
|
+
`<package>` is the installed pi-astro directory, `~/.pi/agent/npm/node_modules/@astrofoundry/pi-astro`.
|
|
41
|
+
2. **Bootstrap**, as `specialist` (`sudo -u specialist -H zsh`, `umask 077`): `~/.config/specialists/client.env` with `BW_SERVER`, `BW_CLIENTID`, `BW_CLIENTSECRET`; `~/.config/specialists/master-password`. Both `0600`. Then `specialist-cli provision` writes each note's fields into `0600` files.
|
|
42
|
+
3. **Pack**: the pack's release copies `pack-<version>.tgz` and its signature to `/private/var/tmp/astro-pack/` and runs `specialist-install pack <version>`; it installs the agents and skills into `~/.pi/agent/pack/` and the gate entries into `~/.pi/agent/specialists.json` (`entry` `/usr/local/bin/specialist-cli`, `user` `specialist`).
|
|
43
|
+
|
|
44
|
+
## Installer
|
|
45
|
+
|
|
46
|
+
Updates go through the installer, one component at a time, each checked before and after the switch:
|
|
47
|
+
```sh
|
|
48
|
+
sudo /usr/local/sbin/specialist-install node <LTS version>
|
|
49
|
+
sudo /usr/local/sbin/specialist-install pack <pack version>
|
|
50
|
+
sudo /usr/local/sbin/specialist-install wrappers <pi-astro version>
|
|
51
|
+
sudo /usr/local/sbin/specialist-install arcane-cli <Arcane server version>
|
|
52
|
+
sudo /usr/local/sbin/specialist-install trendarr <version>
|
|
53
|
+
sudo /usr/local/sbin/specialist-install jq|bw|gcloud <version>
|
|
54
|
+
sudo /usr/local/sbin/specialist-install python <x.y.z+YYYYMMDD>
|
|
55
|
+
sudo /usr/local/sbin/specialist-install rollback node|wrappers|arcane-cli|trendarr|python|gcloud|bw|jq
|
|
56
|
+
sudo /usr/local/sbin/specialist-install status
|
|
57
|
+
```
|
|
58
|
+
- `node` accepts only an LTS release listed in `https://nodejs.org/dist/index.json`, checks the tarball against `SHASUMS256.txt`, and switches `current` only after every installed wrapper answers `--help` with it; `previous` keeps the last one.
|
|
59
|
+
- `pack` takes `/private/var/tmp/astro-pack/pack-<version>.tgz` only when `pack-<version>.tgz.sig` is an SSH signature (`ssh-keygen -Y sign -n astro-pack`) from a key in `/usr/local/etc/astro/allowed_signers`, as identity `astro-pack`. That file and its folders must be root-owned and writable by nobody else; the owner installs it with their own sudo, so neither the `cortex` user nor a specialist can add a key. The installer copies both files into its own work folder before it checks them, reads the services from the pack's `pack.json` (whose `version` must match), installs them into the wrappers' slot, and keeps `pack.json` beside them. `specialist-cli` accepts any installed service name, so a new specialist in a pack needs no new `specialist-cli`.
|
|
60
|
+
- `wrappers` takes the pi-astro tarball from the npm registry, checks its `sha512` integrity, and installs the twelve services pi-astro 0.40.105 and older shipped; later versions carry none, so it refuses them. A pack's version (1.x) is newer than every pi-astro 0.40.x, so `wrappers` cannot replace an installed pack.
|
|
61
|
+
- `arcane-cli` checks the release tarball against `arcane_<version>_checksums.txt`; it follows the Arcane server's version.
|
|
62
|
+
- `python` installs a python-build-standalone `install_only_stripped` build (astral-sh), checked against the release's `SHA256SUMS`; before the switch it imports `ssl` and `sqlite3` and runs the current gcloud with the new Python.
|
|
63
|
+
- `gcloud` assembles the SDK from Google's component snapshot `components-v<version>.json` (core, core-nix, gcloud-deps, and their darwin-arm parts), each tarball checked against the snapshot's sha256, because Google lists the full archive's sha256 only in the table on its versioned-archives page, for the current release; it needs the installed Python and answers `gcloud version` before the switch.
|
|
64
|
+
- `bw` takes `bw-bit-macos-arm64-<version>.zip` (`bw-macos-arm64-<version>.zip` before 2026.11.0) from the bitwarden/clients release `cli-v<version>`, checked against the asset digest from the GitHub API; `jq` takes `jq-macos-arm64` from the jqlang/jq release, checked against its `sha256sum.txt`.
|
|
65
|
+
- `trendarr` installs with the root-owned Node's npm, without install scripts, into `trendarr-<version>`.
|
|
66
|
+
- A version older than the installed one is refused; `rollback` swaps back to the kept previous copy. `status` prints the installed versions as JSON.
|
|
67
|
+
|
|
68
|
+
## Discord
|
|
69
|
+
|
|
70
|
+
The `astro-discord` extension gives Discord users access to the specialists from a channel. It runs in a headless Pi host on Cortex (LaunchAgent `com.astrofoundry.astro-discord`, user `cortex`), never in interactive sessions.
|
|
71
|
+
|
|
72
|
+
- Channels are configured one by one (`channels.<id>`): `trigger` is `always` (every message that names a specialist counts) or `mention` (only messages that start with `@Cortex` or reply to the bot); `specialists` is `*` or a list. A channel with one specialist needs no prefix: every message there is a task for it. In a channel with several, `dns list the zones` names the specialist; an addressed message without a name gets a reply asking for one. In the admin channel, an owner's message that names no specialist goes to `astro.foreman` when the pack ships it: the foreman splits the request, delegates each part to a specialist, and the specialists' risky calls post their approval buttons in the same place; a reply to the foreman, or a message naming `foreman`, continues with it. Threads inherit their parent channel's entry; unlisted channels are ignored. The bot replies at once with "<specialist> is working on your task" and shows the typing indicator until the answer replaces that reply. Reactions on your message: ⏳ running, 🔒 waiting for an owner's approval, ✅ done, ❌ failed. `help` shows the specialists you may use in that channel and the commands (`status` lists running tasks; owners in the admin channel also see the `config` commands). Each channel and specialist has one conversation: a reply to the bot's answer, or another task for that specialist within 30 minutes, continues it with everything the specialist saw before; otherwise a new one starts, and a task beginning with `new` forces that. Replied-to and forwarded messages (text, embeds, attachment names) travel with the task, so "check this" on a forwarded alert works. Image attachments on the message or on what it quotes (up to 4, 8 MiB each) are downloaded and passed to the specialist, which sees them; other file types are named only. Sessions live under `~/.config/astro-discord/sessions/<specialist>/` and are deleted after 7 days. Long answers arrive as a `.md` attachment. When the bridge restarts, open approval requests are marked cancelled and running tasks interrupted in Discord; ask again. Scheduled reports are a list in the config, one entry per report: `"reports": [{ "report": "arcane", "channelId": "<id>", "time": "06:00", "timeZone": "Europe/Madrid" }, { "report": "tools", "channelId": "<admin channel id>", "time": "06:00", "timeZone": "Europe/Madrid" }]` (the earlier single `dailyReport` key is refused; move it into the list). A `daily` entry (on Cortex: 05:00 Europe/Paris, the daily channel) starts the morning run and replaces the other reports' own times, except `media-weekly`: it posts the Security, Cortex Tools, and Arcane reports in their own channels, each applying its automatic updates; then it reads every specialist's area (backups, the front door, both Proxmox hosts with their package upgrades and a Reboot button when one is needed, guest updates, RADIUS and both Tailscale routers, the DMZ, DNS with one Technitium node upgraded per morning, Nexus, downloads, and macOS on Cortex and Nexus), tags the owners in the related channel for each problem, and posts a summary without mentions in the daily channel. The Arcane report posts an "Arcane Daily Report:" message from a fresh `update-report`: one section per stack with updates, each service as current to target version with the kind of change, and a release-notes verdict on every pending update. A stack without a major version and without notes that need attention updates on its own after the post and is checked again five minutes later; a failed check rolls back a Compose change, tags the owners, and starts the foreman in a thread. A major whose notes say nothing relevant gets an Update button; anything else gets Upgrade carefully, which opens a thread where the arcane specialist posts a plan and waits for "go". Only owners can press the buttons (Update runs `arcane stack-update <stack>`; the button turns into the outcome and the reason arrives as a note only the clicker sees). Stacks held in `update-holds.json` at the root of the arcane GitOps repository (`{ "supabase": "coordinated release: review first" }`) show the reason and get no button. Replying to the report asks the arcane specialist with the report as context. The tools report posts "Cortex Tools Report:": every tool on Cortex with a newer version (Homebrew packages installed on request and casks, Pi, pi-astro, and through `specialist-install` the wrappers, arcane-cli at the Arcane server's version, trendarr, and the specialist Node at the latest LTS), a release-notes verdict from `astro.release-reviewer` for the tools the specialists build on, an Update button per line, and one Upgrade everything for Homebrew. Lines without a major version or notes that need attention update on their own after the post; Pi always waits for its button, and casks that need a password stay by hand. Only owners can press the buttons. After an update that needs it, the bridge, herdr, or Astrogate restarts as soon as nothing runs on it; after a day of waiting, a Restart now button appears. The bridge calls `sudo -n /usr/local/sbin/specialist-install` through the sudoers rule from step 4.
|
|
73
|
+
- Site plugin: the bridge loads `~/.pi/agent/pack/bridge/index.js` from the installed pack, which adds the site's scheduled reports, slash commands, and buttons (contract in `extensions/astro-discord/plugin.ts`). Without it the bridge runs specialist tasks and approvals only.
|
|
74
|
+
- Access: `owners` may use every specialist and decide approvals; `access.<specialist>` lists extra users for that specialist; everyone else gets no reply. Owners change the configuration from the admin channel (`adminChannelId`) without a shell: `config show`, `config channel <#channel> <always|mention> <*|dns,edge>`, `config channel <#channel> remove`, `config access <specialist> add|remove <@user>`; the bot writes `~/.config/astro-discord/config.json` on Cortex, which is also editable by hand and re-read on every message. Deny the bot's role View Channel on channels it must never read; that is the boundary the map cannot provide.
|
|
75
|
+
- Approvals: a risky call (anything with `--confirm`, plus writes such as record or zone deletes, Zitadel changes, every UniFi write, Pomerium deploys, service restarts, and on Arcane destructive actions: `down`, deletes, prunes, image, volume, or network removal, `system upgrade`, `gitops delete`, plus `manager-upgrade`, `manager-rollback`, `host db-restore`, and the Radarr host-config reads; `stack-update` asks only across a major version, through its `--confirm`; an owner's Update click on the report needs no approval; `--help` as the first argument never asks, anywhere else it does not exempt the call) pauses the specialist and posts Approve/Deny buttons; only owners' clicks count; no decision within `approvalTimeoutMinutes` denies it. The specialist then reports the denial. Ambiguous tasks get a question back instead of an action.
|
|
76
|
+
- Setup, as `cortex`: `d=$(mktemp -d) && cp ~/.pi/agent/npm/node_modules/@astrofoundry/pi-astro/extensions/astro-discord/*.ts "$d" && node --disable-warning=ExperimentalWarning "$d/setup.ts"` (Node does not strip types inside `node_modules`, so the files are copied first) prompts for the bot token and the ids, checks each against Discord, and writes `~/.config/astro-discord/{token,config.json,run.sh}` and the LaunchAgent; it prints the `launchctl bootstrap` line. After a pi-astro update restart the bridge with `launchctl kickstart -k gui/$(id -u)/com.astrofoundry.astro-discord`. Log: `~/Library/Logs/astro-discord.log`.
|
|
77
|
+
- Discord side: application `Cortex` with a bot, Message Content Intent enabled, invited with scopes `bot` and `applications.commands` and permissions View Channel, Send Messages, Attach Files, Read Message History, Add Reactions.
|
|
78
|
+
|
|
79
|
+
## Rotation and operations
|
|
80
|
+
|
|
81
|
+
A pack documents its Vaultwarden fields, rotation, and forced-command scripts. After any change in Vaultwarden run `specialist-cli provision`. See `AGENTS.md` for the framework's implementation rules.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/bin/zsh
|
|
2
|
+
# /usr/local/bin/specialist-cli: the only sudo entry point into the `specialist` user.
|
|
3
|
+
# Installed root-owned 0755. Runs as `specialist` through
|
|
4
|
+
# cortex ALL=(specialist) NOPASSWD: /usr/local/bin/specialist-cli
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
|
|
7
|
+
service="${1:-}"; [[ -n "$service" ]] && shift
|
|
8
|
+
# Any service the installed wrappers or pack provide; the other names in the wrapper folder are taken.
|
|
9
|
+
case "$service" in
|
|
10
|
+
provision) exec /bin/sh "$HOME/.specialists/bin/provision.sh" ;;
|
|
11
|
+
lib|VERSION|rollback) print -u2 "usage: specialist-cli <service> [--caller <agent>] [--] <args...>"; exit 2 ;;
|
|
12
|
+
esac
|
|
13
|
+
[[ "$service" =~ '^[a-z][a-z0-9-]{0,30}$' ]] || { print -u2 "usage: specialist-cli <service> [--caller <agent>] [--] <args...>"; exit 2; }
|
|
14
|
+
|
|
15
|
+
caller="unknown"
|
|
16
|
+
if [[ "${1:-}" == "--caller" ]]; then caller="${2:-unknown}"; shift 2; fi
|
|
17
|
+
[[ "${1:-}" == "--" ]] && shift
|
|
18
|
+
|
|
19
|
+
runner="$HOME/.specialists/bin/$service/run.ts"
|
|
20
|
+
[[ -f "$runner" ]] || { print -u2 "specialist '$service' is not installed"; exit 2; }
|
|
21
|
+
# The root-owned Node from specialist-install; Homebrew's belongs to the cortex user.
|
|
22
|
+
exec /usr/local/libexec/specialist-node/current/bin/node --disable-warning=ExperimentalWarning "$runner" --caller "$caller" -- "$@"
|