Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(mcp expose): interactivity through isInteractive(); egress only when published beyond loopback; docs

garrytan508352247155
diff --git a/docs/guides/remote-mcp.md b/docs/guides/remote-mcp.md
index e6767a1170..0e4c0a0996 100644
--- a/docs/guides/remote-mcp.md
+++ b/docs/guides/remote-mcp.md
@@ -43,7 +43,7 @@ PGLite brain's single-writer lock. Every step is reported as a named check
| Step | What happens |
| --- | --- |
| `plan` | Resolves options; detects platform, execution environment and engine kind (PGLite vs Postgres); prints what will be installed or changed. A host with **no brain config** (no `gbrain init` yet, or an unreadable config) is refused here with `no_brain_config` — a service there would only crash-loop — unless you pass `--no-service` to publish a server you run yourself (`--dry-run` still prints the plan, with the refusal marked, and exits 0). On a PGLite brain it also reads the lock file: a live process that is not gbrain's own running service adds a `Lock` line and a `pglite_lock` **warning** (the service cannot start until that process exits — stop it, or move to Postgres); the run proceeds. `--no-tailscale` while the receipt says the brain is published on the tailnet (it records a MagicDNS name) is refused with `tailscale_receipt_present` — rewriting the receipt to loopback would leave the live Serve/Funnel mapping unfindable; run `gbrain mcp expose --remove --yes` first, or drop the flag. Then it probes `127.0.0.1:<port>`: **anything listening there** — a TCP connect that is accepted (a non-HTTP service too) or an HTTP answer of any status on `/health` (a 404 or 500 counts — the port is occupied) — with no receipt claiming that port stops the run with `foreign_listener` ("Something already answers on 127.0.0.1:<port> and no expose receipt claims it. Stop it, pick another --port, or pass --no-service to only publish it. If this is a gbrain server left behind by an interrupted `gbrain mcp expose`, run `gbrain mcp expose --remove --yes` first.") **before** anything is published. `--dry-run` stops here. |
-| `consent` | Installing Tailscale, running `tailscale up`, writing the serve/funnel config and creating a user service change system state. Interactive: one y/N prompt; declining is `pending` / exit 2 with "Nothing changed. Re-run with --yes to confirm." Non-interactive without `--yes`: prints the plan plus "pass --yes to confirm" and exits 2. |
+| `consent` | Installing Tailscale, running `tailscale up`, writing the serve/funnel config and creating a user service change system state (effects `persistent_install`, plus `egress` unless `--no-tailscale`). Interactive: one y/N prompt; declining is `pending` / exit 2 with "Nothing changed: the confirmation was declined." Non-interactive without `--yes` (no terminal, `CI`, or an agent process): prints the plan and an `[AGENT]` block with the words to ask the user, and exits 2; under `--json` the `pending` document also carries the consent fields (`code: confirmation_required`, `effects`, `user_message`, `fix` with `next: ask_user`). |
| `tailscale.binary` | Finds `tailscale` on PATH or in the usual macOS/Homebrew/Linux locations. Missing: macOS installs `brew install --cask tailscale-app`; Linux runs the official `curl -fsSL https://tailscale.com/install.sh \| sh` installer (it prompts for sudo itself). `--no-install` prints the plan and exits 1 instead. Other platforms: exit 1 with https://tailscale.com/download. |
| `tailscale.login` | Reads `tailscale status --json`. Not logged in: Linux runs `sudo tailscale set --operator=$USER` first (so you can run `serve` without root afterwards; a failure is noted, not fatal) and then a flagless `sudo tailscale up`; macOS runs the app CLI's `tailscale up` (after a fresh `brew` install it opens the app and gives it a moment first). Linux puts `sudo` in front of the binary **only when it is a system install** (`/usr/bin`, `/usr/local/bin`, `/opt/homebrew/bin`, or a symlink resolving there); a `tailscale` found elsewhere on `PATH` (say `~/.local/bin`) is never run as root — the step stops with `tailscale_login_manual` (exit 2) and, if you trust that binary, asks you to run `sudo <that path> set --operator=$USER && sudo <that path> up` yourself (the full path, because a binary outside sudo's `secure_path` is exactly this case), then re-run. Shows the login URL. Waits up to five minutes; still not running: exit 2 (`tailscale_login_pending`) with the exact re-run command. |
| `tailscale.identity` | Takes your MagicDNS name → `https://your-machine.your-tailnet.ts.net`, then pre-checks the tailnet features `serve`/`funnel` need — the Tailscale CLI does not fail when they are missing, it prints an enablement URL and waits for you interactively, so `expose` never starts it blind. `CertDomains` empty (HTTPS certificates not enabled) → `pending`, exit 2, reason `tailscale_https_not_enabled`, with https://login.tailscale.com/admin/dns and the re-run command. `--funnel` on a node without the Funnel capability → `pending`, exit 2, reason `tailscale_funnel_not_enabled`, with https://login.tailscale.com/admin/acls and the [Funnel docs](https://tailscale.com/kb/1223/funnel). In both cases nothing has been published yet. |
@@ -419,7 +419,7 @@ check. Logs: `~/.gbrain/serve/serve.log` and `serve.err`.
| `tailscale_login_manual` (exit 2) — "tailscale at <path> is not a system install, so gbrain will not run it with sudo" | The `tailscale` on your `PATH` lives outside the system install locations, and gbrain never hands root to a user-writable binary. If you trust that binary, sign in yourself with the printed command — `sudo <that path> set --operator=$USER && sudo <that path> up`, the full path because sudo's `secure_path` would not find it — then re-run the printed command. | user | none | `gbrain mcp expose --status --json` |
| `tailscale_receipt_present` (exit 1, `plan` fails) — "This brain is already published on your tailnet at <url>" | You passed `--no-tailscale` while the receipt records a live Serve/Funnel mapping. Run `gbrain mcp expose --remove --yes` first, or re-run without `--no-tailscale`. | agent, after the user agrees | none | `gbrain mcp expose --status --json` |
| `tailscale_daemon_not_running` — "failed to connect to local Tailscale service" (exit 2 from the login step, nothing published; exit 1 when a `serve status` read or the publish itself is classified this way) | macOS: `open -a Tailscale`. Linux: `sudo systemctl enable --now tailscaled`. Then re-run. | user | none | `gbrain mcp expose --status --json` |
-| `confirmation_required` / `declined` (exit 2, `consent` pending) | Not a TTY without `--yes`, or you answered no at the prompt. Nothing changed; pass `--yes` once the printed plan is what you want. | agent, after the user agrees | `persistent_install`; `egress` with `--funnel` | `gbrain mcp expose --status --json` |
+| `confirmation_required` / `declined` (exit 2, `consent` pending) | Not a TTY without `--yes`, or you answered no at the prompt. Nothing changed; relay `user_message` and run `fix.command` (it adds `--yes`) once the user agrees to the printed plan. | agent, after the user agrees | `persistent_install`; `egress` unless `--no-tailscale` | `gbrain mcp expose --status --json` |
| `invalid_arguments` (exit 1) | An unknown, duplicate, conflicting or malformed flag; the message names it. `gbrain mcp expose --help`. | agent | none | `gbrain mcp expose --help` |
| `tailscale_missing` (exit 1, `--no-install`) / `tailscale_unsupported_platform` (exit 1) / `tailscale_install_failed` (exit 1) | Tailscale is not installed and `expose` would not (or could not) install it: run the printed install command, or install from https://tailscale.com/download, sign in, then re-run. | user | `persistent_install` (installs Tailscale) | `gbrain mcp expose --status --json` |
| `tailscale_no_dns_name` (exit 1, `tailscale.identity` fails) — the node has no MagicDNS name | Enable **MagicDNS** and **HTTPS Certificates** at https://login.tailscale.com/admin/dns, then re-run. Nothing was published. | user | none | `gbrain mcp expose --status --json` |
diff --git a/llms-full.txt b/llms-full.txt
index 680db458ca..209d4f27af 100644
--- a/llms-full.txt
+++ b/llms-full.txt
@@ -56,7 +56,7 @@ PGLite brain's single-writer lock. Every step is reported as a named check
| Step | What happens |
| --- | --- |
| `plan` | Resolves options; detects platform, execution environment and engine kind (PGLite vs Postgres); prints what will be installed or changed. A host with **no brain config** (no `gbrain init` yet, or an unreadable config) is refused here with `no_brain_config` — a service there would only crash-loop — unless you pass `--no-service` to publish a server you run yourself (`--dry-run` still prints the plan, with the refusal marked, and exits 0). On a PGLite brain it also reads the lock file: a live process that is not gbrain's own running service adds a `Lock` line and a `pglite_lock` **warning** (the service cannot start until that process exits — stop it, or move to Postgres); the run proceeds. `--no-tailscale` while the receipt says the brain is published on the tailnet (it records a MagicDNS name) is refused with `tailscale_receipt_present` — rewriting the receipt to loopback would leave the live Serve/Funnel mapping unfindable; run `gbrain mcp expose --remove --yes` first, or drop the flag. Then it probes `127.0.0.1:<port>`: **anything listening there** — a TCP connect that is accepted (a non-HTTP service too) or an HTTP answer of any status on `/health` (a 404 or 500 counts — the port is occupied) — with no receipt claiming that port stops the run with `foreign_listener` ("Something already answers on 127.0.0.1:<port> and no expose receipt claims it. Stop it, pick another --port, or pass --no-service to only publish it. If this is a gbrain server left behind by an interrupted `gbrain mcp expose`, run `gbrain mcp expose --remove --yes` first.") **before** anything is published. `--dry-run` stops here. |
-| `consent` | Installing Tailscale, running `tailscale up`, writing the serve/funnel config and creating a user service change system state. Interactive: one y/N prompt; declining is `pending` / exit 2 with "Nothing changed. Re-run with --yes to confirm." Non-interactive without `--yes`: prints the plan plus "pass --yes to confirm" and exits 2. |
+| `consent` | Installing Tailscale, running `tailscale up`, writing the serve/funnel config and creating a user service change system state (effects `persistent_install`, plus `egress` unless `--no-tailscale`). Interactive: one y/N prompt; declining is `pending` / exit 2 with "Nothing changed: the confirmation was declined." Non-interactive without `--yes` (no terminal, `CI`, or an agent process): prints the plan and an `[AGENT]` block with the words to ask the user, and exits 2; under `--json` the `pending` document also carries the consent fields (`code: confirmation_required`, `effects`, `user_message`, `fix` with `next: ask_user`). |
| `tailscale.binary` | Finds `tailscale` on PATH or in the usual macOS/Homebrew/Linux locations. Missing: macOS installs `brew install --cask tailscale-app`; Linux runs the official `curl -fsSL https://tailscale.com/install.sh \| sh` installer (it prompts for sudo itself). `--no-install` prints the plan and exits 1 instead. Other platforms: exit 1 with https://tailscale.com/download. |
| `tailscale.login` | Reads `tailscale status --json`. Not logged in: Linux runs `sudo tailscale set --operator=$USER` first (so you can run `serve` without root afterwards; a failure is noted, not fatal) and then a flagless `sudo tailscale up`; macOS runs the app CLI's `tailscale up` (after a fresh `brew` install it opens the app and gives it a moment first). Linux puts `sudo` in front of the binary **only when it is a system install** (`/usr/bin`, `/usr/local/bin`, `/opt/homebrew/bin`, or a symlink resolving there); a `tailscale` found elsewhere on `PATH` (say `~/.local/bin`) is never run as root — the step stops with `tailscale_login_manual` (exit 2) and, if you trust that binary, asks you to run `sudo <that path> set --operator=$USER && sudo <that path> up` yourself (the full path, because a binary outside sudo's `secure_path` is exactly this case), then re-run. Shows the login URL. Waits up to five minutes; still not running: exit 2 (`tailscale_login_pending`) with the exact re-run command. |
| `tailscale.identity` | Takes your MagicDNS name → `https://your-machine.your-tailnet.ts.net`, then pre-checks the tailnet features `serve`/`funnel` need — the Tailscale CLI does not fail when they are missing, it prints an enablement URL and waits for you interactively, so `expose` never starts it blind. `CertDomains` empty (HTTPS certificates not enabled) → `pending`, exit 2, reason `tailscale_https_not_enabled`, with https://login.tailscale.com/admin/dns and the re-run command. `--funnel` on a node without the Funnel capability → `pending`, exit 2, reason `tailscale_funnel_not_enabled`, with https://login.tailscale.com/admin/acls and the [Funnel docs](https://tailscale.com/kb/1223/funnel). In both cases nothing has been published yet. |
@@ -432,7 +432,7 @@ check. Logs: `~/.gbrain/serve/serve.log` and `serve.err`.
| `tailscale_login_manual` (exit 2) — "tailscale at <path> is not a system install, so gbrain will not run it with sudo" | The `tailscale` on your `PATH` lives outside the system install locations, and gbrain never hands root to a user-writable binary. If you trust that binary, sign in yourself with the printed command — `sudo <that path> set --operator=$USER && sudo <that path> up`, the full path because sudo's `secure_path` would not find it — then re-run the printed command. | user | none | `gbrain mcp expose --status --json` |
| `tailscale_receipt_present` (exit 1, `plan` fails) — "This brain is already published on your tailnet at <url>" | You passed `--no-tailscale` while the receipt records a live Serve/Funnel mapping. Run `gbrain mcp expose --remove --yes` first, or re-run without `--no-tailscale`. | agent, after the user agrees | none | `gbrain mcp expose --status --json` |
| `tailscale_daemon_not_running` — "failed to connect to local Tailscale service" (exit 2 from the login step, nothing published; exit 1 when a `serve status` read or the publish itself is classified this way) | macOS: `open -a Tailscale`. Linux: `sudo systemctl enable --now tailscaled`. Then re-run. | user | none | `gbrain mcp expose --status --json` |
-| `confirmation_required` / `declined` (exit 2, `consent` pending) | Not a TTY without `--yes`, or you answered no at the prompt. Nothing changed; pass `--yes` once the printed plan is what you want. | agent, after the user agrees | `persistent_install`; `egress` with `--funnel` | `gbrain mcp expose --status --json` |
+| `confirmation_required` / `declined` (exit 2, `consent` pending) | Not a TTY without `--yes`, or you answered no at the prompt. Nothing changed; relay `user_message` and run `fix.command` (it adds `--yes`) once the user agrees to the printed plan. | agent, after the user agrees | `persistent_install`; `egress` unless `--no-tailscale` | `gbrain mcp expose --status --json` |
| `invalid_arguments` (exit 1) | An unknown, duplicate, conflicting or malformed flag; the message names it. `gbrain mcp expose --help`. | agent | none | `gbrain mcp expose --help` |
| `tailscale_missing` (exit 1, `--no-install`) / `tailscale_unsupported_platform` (exit 1) / `tailscale_install_failed` (exit 1) | Tailscale is not installed and `expose` would not (or could not) install it: run the printed install command, or install from https://tailscale.com/download, sign in, then re-run. | user | `persistent_install` (installs Tailscale) | `gbrain mcp expose --status --json` |
| `tailscale_no_dns_name` (exit 1, `tailscale.identity` fails) — the node has no MagicDNS name | Enable **MagicDNS** and **HTTPS Certificates** at https://login.tailscale.com/admin/dns, then re-run. Nothing was published. | user | none | `gbrain mcp expose --status --json` |
diff --git a/plugin/skills/remote-mcp/SKILL.md b/plugin/skills/remote-mcp/SKILL.md
index ba694e87a0..f05d7c6f69 100644
--- a/plugin/skills/remote-mcp/SKILL.md
+++ b/plugin/skills/remote-mcp/SKILL.md
@@ -178,7 +178,7 @@ Relay every prompt the command surfaces:
| `service: manual` (no supervisor: cloud sandbox, container) | Relay the printed foreground and `nohup … &` commands; this is a documented outcome, not a failure |
| `verify.local: warn` (exit 2, `local_health_timeout`) | The handler is published, the service installed and the receipt written — this exit 2 is NOT "nothing published"; `--status` / `--remove` find them. `/health` did not answer within the wait: check `~/.gbrain/serve/serve.err`, then `gbrain mcp expose --status` |
| `verify.tailnet: pending` (exit 2, `tailnet_health_pending`; `--status` reports it with exit 1) | Same: handler, service and receipt are already in place. First certificate issuance can take a minute; `gbrain mcp expose --status` later |
-| `confirmation_required` (exit 2) | Non-TTY run without `--yes`. Nothing changed; show the printed plan, get the operator's yes, then re-run with `--yes` |
+| `confirmation_required` (exit 2) | Non-TTY run without `--yes`. Nothing changed; show the printed plan, relay the payload's `user_message`, and run its `fix.command` (it adds `--yes`) only after the operator agrees |
| `tailscale_no_dns_name` (exit 1) — the node has no MagicDNS name | Enable MagicDNS + HTTPS Certificates at `https://login.tailscale.com/admin/dns`, then re-run; nothing was published |
| `tailscale_missing` (exit 1, `--no-install`) / `tailscale_unsupported_platform` / `tailscale_install_failed` (exit 1) | Tailscale is not installed and was not (or could not be) installed. Relay the printed install command or `https://tailscale.com/download`, have the user sign in, then re-run |
| `tailscale_publish_unconfirmed` (exit 1) — `serve --bg` exited 0 but the re-read shows no handler (or could not be read) | Run `tailscale serve status`; `gbrain mcp expose --remove --yes` clears a handler for the port without a receipt (`--force` when no wrapper or service of gbrain's exists yet), then re-run |
diff --git a/skills/remote-mcp/SKILL.md b/skills/remote-mcp/SKILL.md
index ba694e87a0..f05d7c6f69 100644
--- a/skills/remote-mcp/SKILL.md
+++ b/skills/remote-mcp/SKILL.md
@@ -178,7 +178,7 @@ Relay every prompt the command surfaces:
| `service: manual` (no supervisor: cloud sandbox, container) | Relay the printed foreground and `nohup … &` commands; this is a documented outcome, not a failure |
| `verify.local: warn` (exit 2, `local_health_timeout`) | The handler is published, the service installed and the receipt written — this exit 2 is NOT "nothing published"; `--status` / `--remove` find them. `/health` did not answer within the wait: check `~/.gbrain/serve/serve.err`, then `gbrain mcp expose --status` |
| `verify.tailnet: pending` (exit 2, `tailnet_health_pending`; `--status` reports it with exit 1) | Same: handler, service and receipt are already in place. First certificate issuance can take a minute; `gbrain mcp expose --status` later |
-| `confirmation_required` (exit 2) | Non-TTY run without `--yes`. Nothing changed; show the printed plan, get the operator's yes, then re-run with `--yes` |
+| `confirmation_required` (exit 2) | Non-TTY run without `--yes`. Nothing changed; show the printed plan, relay the payload's `user_message`, and run its `fix.command` (it adds `--yes`) only after the operator agrees |
| `tailscale_no_dns_name` (exit 1) — the node has no MagicDNS name | Enable MagicDNS + HTTPS Certificates at `https://login.tailscale.com/admin/dns`, then re-run; nothing was published |
| `tailscale_missing` (exit 1, `--no-install`) / `tailscale_unsupported_platform` / `tailscale_install_failed` (exit 1) | Tailscale is not installed and was not (or could not be) installed. Relay the printed install command or `https://tailscale.com/download`, have the user sign in, then re-run |
| `tailscale_publish_unconfirmed` (exit 1) — `serve --bg` exited 0 but the re-read shows no handler (or could not be read) | Run `tailscale serve status`; `gbrain mcp expose --remove --yes` clears a handler for the port without a receipt (`--force` when no wrapper or service of gbrain's exists yet), then re-run |
diff --git a/skills/skills.lock.json b/skills/skills.lock.json
index bb5581fb92..2485165415 100644
--- a/skills/skills.lock.json
+++ b/skills/skills.lock.json
@@ -178,7 +178,7 @@
"publish/SKILL.md": "df87df3ab6c0e799f5dc88edaec7f6b4049c49bbee5525874fe24f1765c3028c",
"query/SKILL.md": "8905796d90cae85873cbb9fa6aacba47e51bb0f6037edb72d733981c47f83d3b",
"query/routing-eval.jsonl": "74f5a91e52fabc54e0e9403fa17db87ee26bb7ebb8ae8005148c51142abc62fe",
- "remote-mcp/SKILL.md": "d797778d9bfdfc8291d3fa7979a6f8503f02fc14aafb2c01b4509947512a46c2",
+ "remote-mcp/SKILL.md": "d5b7401dba8076a817bc6fcb5c70000638b09b57452b0021feb5e669f0fdf5e2",
"remote-mcp/routing-eval.jsonl": "7287693135c9fe2d6495d81d22746ddf41b116254db4b6e683dbdee251e08f8e",
"repo-architecture/SKILL.md": "9b16948d5d0a953a4446aa03e40014f19da0903990da6fa53a7ea1702b44c4a0",
"reports/SKILL.md": "69d39aad7c4b118347c48732d3866883a68903ae57c682d0b46f4dc8ffc74e98",
diff --git a/src/commands/mcp-expose.ts b/src/commands/mcp-expose.ts
index 7bd9031a07..cdb22523c2 100644
--- a/src/commands/mcp-expose.ts
+++ b/src/commands/mcp-expose.ts
@@ -19,6 +19,7 @@ import { existsSync, unlinkSync } from 'node:fs';
import { dirname, resolve as resolvePath } from 'node:path';
import { homedir, userInfo } from 'node:os';
import { promptLineStderr } from '../core/cli-util.ts';
+import { isInteractive } from '../core/interaction.ts';
import { isConsentRefusal, renderConsentRefusal, requireConsent } from '../core/consent.ts';
import type { Effect } from '../core/agent-output.ts';
import { gbrainPath, isThinClient, loadConfig, type GBrainConfig } from '../core/config.ts';
@@ -223,7 +224,7 @@ function resolveDeps(deps: McpExposeDeps): Resolved {
fetch: deps.fetch ?? ((url, init) => fetch(url, init as RequestInit)),
tcpProbe: deps.tcpProbe ?? defaultTcpProbe,
lookup: deps.lookup ?? defaultLookup,
- isTTY: deps.isTTY ?? (process.stdin.isTTY === true && process.stderr.isTTY === true),
+ isTTY: deps.isTTY ?? isInteractive({ stdoutIsTTY: process.stderr.isTTY === true }),
prompt: deps.prompt ?? ((q: string) => promptLineStderr(q)),
out: deps.stdout ?? ((line: string) => { process.stdout.write(`${line}\n`); }),
err: deps.stderr ?? ((line: string) => { process.stderr.write(`${line}\n`); }),
@@ -459,7 +460,7 @@ function publishConsent(opts: ExposeOptions): ConsentExtra {
yes: opts.yes, nextAction: rerunCommand(opts),
confirmationMessage: 'These are system-state changes (Tailscale, serve config, a user service). Pass --yes to confirm.',
argv: ['gbrain', 'mcp', 'expose', ...publishFlags(opts)],
- effects: ['persistent_install', 'egress'],
+ effects: opts.noTailscale ? ['persistent_install'] : ['persistent_install', 'egress'],
what: 'mcp expose',
why: `Publishes this brain's MCP server ${where}${opts.noService ? '' : ' and installs a user service that keeps it running'}, so authorized agents on other machines can reach it.`,
risk: 'Changes system state (Tailscale serve config, a user service, files under the serve directory); `gbrain mcp expose --remove` undoes it.',