Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Google connector + open-loop engine (more)
Subsystem index · Previous entries.
src/core/harness/oauth-setup.ts+client-setup.ts— explicit client metadata projection, flow selection, native OAuth setup/private-file validation, and live-row-locked secret delivery recovery. Public PKCE needs no journal; confidential exports validate the retained secret against current registration, and machine exports discard cached tokens. Unknown/mixed flows refuse until an explicit supported flow is selected.src/core/harness/capabilities.ts+src/mcp/capabilities.ts— Shared effective-grant orientation for OAuth whoami and authenticatedgbrain://capabilities. A stored client token lifetime outside 60 to 7,776,000 seconds (AuthInfo.tokenTtlSeconds) reportstoken_ttl_invalid, and the delegation repair template then includes a--token-ttl <APPROVED_TTL_SECONDS>choice, since every grant write validates the merged lifetime. The resource preserves the exact seven-tool surface; source, operation, scope, fence and server-gate restrictions remain enforced at dispatch.grant_diagnosis(shared with doctorgrant_new_ops_availablethroughgrantOperationGaps,grantAgeandgrantRescopeArgvs) counts the operations the grant's scopes allow but its operation snapshot, its client pin or the server ceiling block, names none of them, keeps inferred grant age apart (intent_unknownwithout catalog provenance), and builds host commands only from the verifier's principal. No worker probe or per-tool database query during discovery (one audit read for provenance when a snapshot excludes operations). Shared administration guidance explains separate owner authority, links the MCP admin runbook, and exposes an admin URL only for a configured credential-free HTTP MCP endpoint. Stdio never infers an HTTP address. D4 in band:grantBlockedNotice(diagnosis, {refused})builds thegrant_blocked_operationsnotice (blocker counts, grant age apart, missing scope only when refused; a client narrowed on purpose — grant ageprovenance_recorded, nothing predating, every blocker an operation snapshot — gets it only on a refused call) andgrantRepairActionthe host-owned repair (preview argv,thenapply, verify = doctorgrant_new_ops_availableorwhoami; server ceiling alone → the read-only doctor check). Dispatch (grantBlockedNotices) delivers it once per (principal, session) or, stateless, per (principal, grant revision).src/commands/mcp.ts+mcp-provision.ts+harness-connect.ts— Host-side grant/preview/CAS and recoverable private delivery, followed by installation inside the intended harness. Codex, Claude Code and opencode installs (src/core/harness/install.ts) store the bearer token inline in the harness config;inlineTokenReceiptaddstoken_storage,config_path,renew_command,if_exposed(invalidate-tokens preview/apply, renew, reload;renew_commandcarries--fresh-tokenfor renewable handoffs so it always exchanges a new token) and atoken_warningwhen a Git working tree would commit the file, andharness-connect.tsrepeats them on stderr in human mode without printing the token (#5775;test/harness-token-receipt.test.ts). Running PGLite hosts are administered through their authenticated API, never by opening a second database process. CLI status uses the delivery-aware exit verdict.mcp-admin.tsandmcp-admin-http.tsprovide engine-free owner commands with explicit-file/env credential precedence, in-memory sessions, private native exports, versioned lifecycle previews, and safe stage/outcome/remedy receipts. Unknown mutation outcomes require inspection instead of automatic repetition.runMcpalso dispatchesgbrain mcp exposetorunMcpExpose(dynamic import of./mcp-expose.ts; HELP carries the expose lines so the flag registry harvests them) and sets the CLI exit verdict from its returned code.mcpNeedsEngine(args)is true only forgrantwithout an owner credential (--admin-token-fileorGBRAIN_ADMIN_BOOTSTRAP_TOKEN) and outside help;admin,expose, andverifynever open the database.src/commands/mcp-expose.ts—gbrain mcp expose [--port N] [--funnel] [--surface] [--enable-dcr] [--no-tailscale] [--no-service] [--no-install] [--force] [--dry-run] [--yes] [--json]/--status/--remove: publishesgbrain serve --httpon the user's Tailscale tailnet (Serve by default, Funnel only with the explicit flag) and keeps it running as a user service.runMcpExpose(args, deps?)returns the exit code (0 done, 1 failed, 2 needs--yes, the prompt was declined, or a step is pending — a tailnet feature to enable, Tailscale login, tailnet certificate). Arg validation viavalidateHarnessArguments(exclusive pairs--status/--remove,--funnel/--no-tailscale,--dry-run/--status); the help text names every flag and theverify.local/verify.tailnetchecks. Ordered named checks —plan(platform, execution environment, engine kind fromloadConfig(); thin clients are refused with "run on the brain host";engine === 'unknown'— no config or an unreadable one — without--no-serviceis refused asno_brain_config/ exit 1 with next actiongbrain initBEFORE consent, because a service around a missing brain only crash-loops, while--dry-runstill prints the plan with the refusal marked and exits 0; on a PGLite enginedeps.pgliteHolder(defaultprobeLivePgliteHolderfromsrc/core/bootstrap/uninstall.ts, a read-only lock-file probe) is consulted withcfg.database_path, and a live holder that is not our own managed service — receipt present withservice.staterunning/loaded— adds aLockplan line plus apglite_lockcheck with statuswarn(never a stop);--no-tailscaleover an existing receipt whosetailscale.dns_nameis set (a live Serve/Funnel mapping) is refused BEFORE consent astailscale_receipt_present/ exit 1 with next actionsgbrain mcp expose --remove --yesand the re-run without the flag —--dry-runmarks itWOULD BE REFUSED; then probes127.0.0.1:<port>withprobeOccupied(d, port, url)— occupied when EITHER the injectabledeps.tcpProbe(defaultdefaultTcpProbe, onenode:netconnect, socket destroyed on every outcome; true on connect, false on refusal / timeout / throw) accepts a TCP connect OR the/healthfetch RESOLVES with ANY status (2xx, 404, 500), so a non-HTTP listener counts too; only both rejecting is free — and refuses a foreign listener with no receipt claiming that port asforeign_listenerBEFORE anything is published unless--no-service; the message names the interrupted-run escape hatchgbrain mcp expose --remove --yes;probeHealth(res.ok) stays the bar forverify.local/verify.tailnet/--status),consent(sharedconfirmOrFinishfor publish and--remove: one stderr y/N prompt on a TTY; declining ispending/ exit 2 /declinedwith "Nothing changed. Re-run with --yes to confirm."; non-interactive without--yesprints the plan and exits 2 /confirmation_required; every re-run hint is rendered byrerunCommand(opts)— the user's publish flags +--yes),tailscale.binary(install plan: brew cask on macOS — thenopen -a Tailscaleand a bounded poll oftailscale status --json, up to 20 attempts 1s apart, breaking as soon as the app's daemon answers and otherwise falling through to the login step's daemon-not-running handling — official installer on Linux,--no-install→ exit 1),tailscale.login(Linuxsudo tailscale set --operator=<user>non-fatal then flaglesssudo tailscale up—sudois put in front of the binary ONLY whenisSystemTailscaleBinary(binary)holds (one ofTAILSCALE_BINARY_CANDIDATES, literally or viarealpathSync); a user-writabletailscalefound on PATH stops the step aspending/ exit 2 /tailscale_login_manualwith the message "tailscale atsrc/core/connector-install-links.ts— pure builders for one-click client links:cursorInstallLink(mcpUrl, name='gbrain')(Cursor's documentedcursor://anysphere.cursor-deeplink/mcp/install?name=…&config=…, config = base64 ofJSON.stringify({ url }), thenencodeURIComponent),claudeConnectorLink(mcpUrl, name='GBrain')(Anthropic's documented custom connector install link,https://claude.ai/customize/connectors?modal=add-custom-connector&connectorName=…&connectorUrl=…),connectorInstallLinks(mcpUrl, isPublic)(Claude only whenisPublic, since claude.ai connects from Anthropic's cloud)installLinkLines(links, isPublic)(the two-column human lines) andprintInstallLinks(mcpUrl, isPublic, say)(builds, prints, returns the links for--json). Every builder returns null unless the URL parses as absolutehttps:with a hostname and no userinfo, so a link never carries a credential.test/connector-install-links.test.tspins the docs' gbrain.io links to these builders.src/commands/mcp-expose-probe.ts— the health / occupancy probesmcp-expose.tsruns, peeled out behind a narrowProbeDeps(fetch,tcpProbe,lookup,now,sleep,healthIntervalMs) rather than the whole resolved-deps bag:tryFetch(d, url, timeoutMs)(one bounded fetch,redirect: 'manual', never throws →FetchOutcome { res, unresolved }),probeHealth(res.ok— theverify.*/--statusbar),probeOccupied(an accepted TCP connect OR any HTTP answer — the foreign-listener bar),pollHealth(wall-clock budget fromd.now(), per-probe timeoutmin(1500, remaining), attempt capceil(budget / healthIntervalMs)as the frozen-clock backstop,unresolved= the LAST probe's verdict),unresolvedDetail(dnsName),defaultTcpProbe(onenode:netconnect, socket destroyed on every outcome) anddefaultLookup(local RFC 6761.invalidrejection, otherwisedns.promises.lookup). The name-resolution verdict is the reason the module exists: Bun'sfetchrejects an unresolvable host with the SAME error as a refused connection ("Unable to connect. Is the computer able to access the url?", codeConnectionRefused), so a message match alone never fires in production. After a rejectionnameUnresolvedtakesnew URL(url).hostname, skips IP literals (isIP) andlocalhost, and otherwise awaitsd.lookup(host)raced against the probe'stimeoutMs(a lookup that does not answer in time proves nothing; the race keeps a late rejection handled);isUnresolvedLookupErrorclassifies the lookup rejection bycode—ENOTFOUND,EAI_AGAIN,EAI_NONAME,EAI_NODATA,DNS_ENOTFOUND(a resolver outage counts: the verdict is about THIS host) — or by those tokens in its message, and the fetch-message regex (ENOTFOUND|getaddrinfo|EAI_AGAIN|failed to resolve|Unable to connect.*resolve) is OR-ed in afterwards as the secondary hint. Tests inject a fake fetch, TCP probe and resolver (test/mcp-expose.test.ts; the fixture's defaultlookupresolves every name, reserved-name and label-boundary cases do not query external DNS, and the realdefaultLookupresolves localhost).statusOnlyHealthDetail(port)reads this host's live status-only marker for the port soverify.localreads "status-only ()" instead of a timeout or "no answer".