v1.27.0.0 feat: /setup-gbrain Path 4 (remote MCP) + brain → artifacts rename (#1351)

* feat: gstack-gbrain-mcp-verify helper for remote MCP probe

Probes a remote gbrain MCP endpoint with bearer auth. POSTs initialize,
classifies failures into NETWORK / AUTH / MALFORMED with one-line
remediation hints, and runs a tools/list capability probe to detect
sources_add MCP support (forward-compat for when gbrain ships URL ingest).

Token consumed from GBRAIN_MCP_TOKEN env, never argv. Required to set
both 'application/json' AND 'text/event-stream' in Accept; that gotcha
costs 10 minutes of debugging when missed (regression-tested).

Live-verified against wintermute (gbrain v0.27.1).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat: gstack-artifacts-init + gstack-artifacts-url helpers

artifacts-init replaces brain-init with provider choice (gh / glab /
manual), per-user gstack-artifacts-$USER repo, HTTPS-canonical storage in
~/.gstack-artifacts-remote.txt, and a "send this to your brain admin"
hookup printout. Always prints the command, never auto-executes — gbrain
v0.26.x has no admin-scope MCP probe (codex Finding #3).

artifacts-url centralizes HTTPS↔SSH/host/owner-repo conversion so callers
don't each string-mangle (codex Finding #10). The remote-conflict check in
artifacts-init compares at the canonical level so re-running with HTTPS
input doesn't trip on a stored SSH URL for the same logical repo.

The "URL form not supported" branch prints a two-line clone-then-path
form for gbrain v0.26.x; the supported branch is a one-liner with --url
ready for when gbrain ships URL ingest.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat: extend gstack-gbrain-detect with mcp_mode + artifacts_remote

Adds two new fields to detect's JSON output:

- gbrain_mcp_mode: local-stdio | remote-http | none
  Resolved via 3-tier fallback (codex Finding D3): claude mcp get --json
  → claude mcp list text-grep → ~/.claude.json jq read. If Anthropic moves
  the file format, the first two tiers absorb it.

- gstack_artifacts_remote: HTTPS URL from ~/.gstack-artifacts-remote.txt
  Falls back to ~/.gstack-brain-remote.txt during the v1.27.0.0 migration
  window so detect doesn't return empty between upgrade and migration.

Existing detect tests still pass (15/15). New 19 tests cover every fallback
tier independently, plus a schema regression for /sync-gbrain compat.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat: setup-gbrain Path 4 (remote MCP) + artifacts rename

Path 4 lets users paste an HTTPS MCP URL + bearer token and registers it
as an HTTP-transport MCP without needing a local gbrain CLI install. The
flow:

- Step 2 gains a fourth option (Remote gbrain MCP)
- Step 4 adds Path 4 sub-flow: collect URL, secret-read bearer, verify
  via gstack-gbrain-mcp-verify (NETWORK / AUTH / MALFORMED classifier)
- Step 5 (local doctor), Step 7.5 (transcript ingest), Step 5a's stdio
  branch all skip on Path 4
- Step 5a adds an HTTP+bearer registration form: claude mcp add
  --transport http --header "Authorization: Bearer ..."
- Step 7 renamed "session memory sync" → "artifacts sync" and now calls
  gstack-artifacts-init (which always prints the brain-admin hookup
  command — no auto-execute, codex Finding #3)
- Step 8 CLAUDE.md block branches: remote-http includes URL + server
  version (never the token); local-stdio keeps engine + config-file
- Step 9 smoke test on Path 4 prints the curl-equivalent for
  post-restart verification (MCP tools aren't visible mid-session)
- Step 10 verdict block has separate templates per mode

Idempotency: re-running with gbrain_mcp_mode=remote-http already in
detect output skips Step 2 entirely and goes to verification.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor: rename gbrain_sync_mode → artifacts_sync_mode (v1.27.0.0 prep)

Hard rename, no dual-read alias (codex Finding D4). The on-disk migration
script (Phase C, separate commit) renames the config key in users'
~/.gstack/config.yaml and any CLAUDE.md blocks.

Touched call sites:
- bin/gstack-config defaults + validation + list/defaults output
- bin/gstack-gbrain-detect (gstack_brain_sync_mode field still emitted
  with the same name for downstream-tool compat; reads new key)
- bin/gstack-brain-sync, bin/gstack-brain-enqueue, bin/gstack-brain-uninstall
- bin/gstack-timeline-log (comment ref)
- scripts/resolvers/preamble/generate-brain-sync-block.ts: renames key,
  branches on gbrain_mcp_mode=remote-http to emit "ARTIFACTS_SYNC:
  remote-mode (managed by brain server <host>)" instead of the local
  mode/queue/last_push line (codex Finding #11)
- bin/gstack-brain-restore + bin/gstack-gbrain-source-wireup: read
  ~/.gstack-artifacts-remote.txt with ~/.gstack-brain-remote.txt fallback
  during the migration window
- bin/gstack-artifacts-init: tolerant of unrecognized URL forms (local
  paths, file://, self-hosted gitea) so test infrastructure and unusual
  remotes work without canonicalization
- test/brain-sync.test.ts: gstack-brain-init → gstack-artifacts-init
- test/skill-e2e-brain-privacy-gate.test.ts: artifacts_sync_mode keys
- test/gen-skill-docs.test.ts: budget 35K → 36.5K for the new MCP-mode
  probe in the preamble resolver
- health/SKILL.md.tmpl, sync-gbrain/SKILL.md.tmpl: comment + verdict line

Hard delete:
- bin/gstack-brain-init (replaced by bin/gstack-artifacts-init in v1.27.0.0)
- test/gstack-brain-init-gh-mock.test.ts (replaced by gstack-artifacts-init.test.ts)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: regenerate SKILL.md files after artifacts-sync rename

Mechanical regen via \`bun run gen:skill-docs --host all\`. All */SKILL.md
files reflect the renamed config key (gbrain_sync_mode →
artifacts_sync_mode), the renamed remote-helper file
(~/.gstack-artifacts-remote.txt with brain fallback), the renamed init
script (gstack-artifacts-init), and the new ARTIFACTS_SYNC: remote-mode
status line that fires when a remote-http MCP is registered.

Golden fixtures (test/fixtures/golden/*-ship-SKILL.md) refreshed to match
the regenerated default-ship output.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat: v1.27.0.0 migration — gstack-brain → gstack-artifacts rename

Journaled, interruption-safe migration. Six steps, each writes to
~/.gstack/.migrations/v1.27.0.0.journal on success; re-entry resumes
from the next un-done step. On final success, journal is replaced by
~/.gstack/.migrations/v1.27.0.0.done.

Steps:
1. gh_repo_renamed       gh/glab repo rename gstack-brain-$USER →
                         gstack-artifacts-$USER (idempotent: detects
                         already-renamed and skips)
2. remote_txt_renamed    mv ~/.gstack-brain-remote.txt → artifacts file,
                         rewriting URL path to match the new repo name
3. config_key_renamed    sed -i in ~/.gstack/config.yaml flips
                         gbrain_sync_mode → artifacts_sync_mode
4. claude_md_block       sed flips "- Memory sync:" → "- Artifacts sync:"
                         in cwd CLAUDE.md and ~/.gstack/CLAUDE.md
5. sources_swapped       gbrain sources add NEW (verify) → remove OLD
                         (codex Finding #6: add-before-remove ordering,
                         no downtime window). On remote-MCP mode, prints
                         commands for the brain admin instead of executing.
6. done                  touchfile + delete journal

User opt-out: any "n" or "skip-for-now" answer at the initial prompt
writes a marker file that prevents re-prompting; user can re-invoke
via /setup-gbrain --rerun-migration.

11 unit tests cover: nothing-to-migrate, GitHub happy path, idempotent
re-run, journal-resume mid-flight, remote-MCP print-only path,
add-before-remove ordering verification, add-fail → old source stays
registered, CLAUDE.md field rewrite.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test: regression suite + E2E for v1.27.0.0 rename

Three new regression tests guard the rename's blast radius (per codex
Findings #1, #8, #9, #12):

- test/no-stale-gstack-brain-refs.test.ts: greps bin/, scripts/, *.tmpl,
  test/ for forbidden identifiers (gstack-brain-init, gbrain_sync_mode);
  fails CI if any non-allowlisted file references them.
- test/post-rename-doc-regen.test.ts: confirms gen-skill-docs output has
  no stale references in any */SKILL.md (the cross-product blind spot).
- test/setup-gbrain-path4-structure.test.ts: structural lint over the
  Path 4 prose contract — STOP gates after verify failure, never-write-
  token rules, mode-aware CLAUDE.md block, bearer always via env-var.

Two new gate-tier E2E tests (deterministic stub HTTP server, fixed inputs):

- test/skill-e2e-setup-gbrain-remote.test.ts: Path 4 happy path. Stubs
  an HTTP MCP server, drives the skill via Agent SDK with a stubbed
  bearer, asserts claude.json gets the http MCP entry, CLAUDE.md gets
  the remote-http block, the secret token NEVER leaks to CLAUDE.md.
- test/skill-e2e-setup-gbrain-bad-token.test.ts: stub server returns 401;
  asserts the AUTH classifier hint surfaces, no MCP registration occurs,
  CLAUDE.md is unchanged. Regression guard for the "verify failed → STOP"
  rule.

touchfiles.ts: setup-gbrain-remote and setup-gbrain-bad-token added at
gate-tier so CI catches Path 4 regressions on every PR.

Plus a few comment refs flipped: bin/gstack-jsonl-merge, bin/gstack-timeline-log
(legacy gstack-brain-init mentions in headers).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* release: v1.27.0.0 — /setup-gbrain Path 4 + brain → artifacts rename

Bumps VERSION 1.26.4.0 → 1.27.0.0 (MINOR per CLAUDE.md scale-aware bump
guidance: ~1500 line net change including a new path in /setup-gbrain,
two new bin helpers, a journaled migration, 59 new tests, and a config
key rename across the codebase).

CHANGELOG entry covers: Path 4 (Remote MCP) end-to-end, the brain →
artifacts rename, the journaled migration, the verify-helper error
classifier, the artifacts-init multi-host provider choice. Includes
the canonical Garry-voice headline + numbers table + audience close
per the release-summary format.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test: demote setup-gbrain Path 4 E2E to periodic-tier

The Agent SDK E2E tests for Path 4 (skill-e2e-setup-gbrain-remote and
skill-e2e-setup-gbrain-bad-token) are inherently non-deterministic —
the model interprets "follow Path 4 only" prompts flexibly and can
skip Step 8 (CLAUDE.md write) or shortcut past the verify helper, which
makes the gate-tier assertions flaky.

The deterministic gate coverage for Path 4 is in
test/setup-gbrain-path4-structure.test.ts: a fast structural lint that
catches AUQ-pacing regressions and prose contract drift in <200ms with
zero token spend. That test is the right tool for catching the failure
mode the gate-tier was meant to guard against.

The Agent SDK E2E tests stay available on-demand for periodic-tier runs
(EVALS=1 EVALS_TIER=periodic bun test test/skill-e2e-setup-gbrain-*.test.ts).
Also tightened the verify-error assertion to the literal field shape
("error_class": "AUTH") instead of a substring match that false-matches
the parent claude session's "needs-auth" MCP discovery markers.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: sync package.json version to 1.27.0.0

VERSION was bumped to 1.27.0.0 in f6ec11eb but package.json was not
updated in the same commit. The gen-skill-docs.test.ts assertion
"package.json version matches VERSION file" caught the drift.

This is the DRIFT_STALE_PKG case the /ship Step 12 idempotency check
is designed for; the fix is the documented sync-only repair (no
re-bump, package.json synced to existing VERSION).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-05-06 19:37:53 -07:00
committed by GitHub
parent c7aefc1abd
commit f44de365c5
81 changed files with 5580 additions and 1262 deletions

View File

@@ -1,5 +1,173 @@
# Changelog
## [1.27.0.0] - 2026-05-06
## **`/setup-gbrain` connects to a remote brain in one paste. Brain repo renamed to gstack-artifacts.**
`/setup-gbrain` now has a fourth path: paste a remote MCP URL plus a bearer
token, and the skill registers it as your gbrain MCP without provisioning a
local brain DB. No PGLite to install, no Supabase project to set up. Just
point this Mac at a brain that already runs somewhere else (Tailscale node,
ngrok endpoint, internal LAN, a teammate's server) and you have search +
write working in one Claude Code session restart. The same flow optionally
provisions a private `gstack-artifacts-$USER` repo on GitHub OR GitLab so
the remote brain can ingest your CEO plans, designs, and reports as a
federated source. The renamed repo replaces `gstack-brain-$USER` with a
clearer name; existing users get a journaled, interruption-safe migration
that handles the GitHub repo rename, the on-disk file moves, the config
key rewrite, and the gbrain federated-source swap (add-new-before-remove-old,
no downtime window).
### The numbers that matter
Verified end-to-end against a live remote brain (wintermute on Tailscale,
gbrain v0.27.1, 96K pages) plus the new test suite:
| Surface | Before | After | Δ |
|---|---|---|---|
| `/setup-gbrain` paths | 3 (Supabase / PGLite / Switch) | 4 (Supabase / PGLite / Switch / Remote MCP) | +1 path, no local install required |
| Time to working remote MCP | manual `claude mcp add --transport http`, then skip the rest of the skill | one Path 4 walkthrough, full verify + artifact-repo provision | ~30 sec setup, agent guided |
| Verify failure modes classified | none (raw curl error) | NETWORK / AUTH / MALFORMED, each with one-line remediation hint | 3 buckets, 0 wrong-layer debugging |
| Migration interruption safety | partial-state on Ctrl-C | journal at `.migrations/v1.27.0.0.journal`, resumes from the next un-done step | 6-step atomic rollback |
| Rename blast radius | one bin script | bin + scripts/ + 8 generated SKILL.md surfaces | grep regression test guards every caller |
| Tests added | — | 59 unit + 2 gate-tier E2E + 4 regression | full coverage of the rename + Path 4 prose contract |
| Path 4 step | What runs | Local dependency |
|---|---|---|
| Step 4c verify | `gstack-gbrain-mcp-verify $URL` (curl POST initialize) | none |
| Step 5a register | `claude mcp add --scope user --transport http gbrain $URL --header "Authorization: Bearer $TOKEN"` | claude CLI |
| Step 7 artifacts | `gstack-artifacts-init` (gh OR glab OR manual URL paste) | gh / glab / git |
| Step 8 CLAUDE.md | mode-aware block; token NEVER written to CLAUDE.md (only `~/.claude.json`) | filesystem |
| Step 9 smoke test | prints curl-equivalent for post-restart manual verification | none |
The verify helper's `Accept: application/json, text/event-stream` requirement
is a regression-tested invariant. Every MCP server that ships HTTP transport
returns 406 Not Acceptable without both values; missing this header costs
about 10 minutes of debugging per fresh setup.
### What this means for users running gbrain across machines
If you have a brain on a different Mac, a Tailscale-connected server, or a
teammate runs one for the team, you no longer need a local install on every
client. One paste of URL + bearer registers the MCP at user scope; restart
Claude Code and `mcp__gbrain__search` and friends become callable. The
artifacts repo is per-user (private), so each developer pushes their own
plans/designs/reports without crossing trust surfaces. Renaming
`gstack-brain-$USER` to `gstack-artifacts-$USER` is automatic if you accept
the migration prompt; everything keeps working if you decline.
Existing local-mode users (PGLite or Supabase) see no behavior change beyond
the rename. The path you picked in `/setup-gbrain` Step 2 still runs end to
end, just under the new "artifacts" terminology.
### Itemized changes
#### Added
- **`/setup-gbrain` Path 4 (Remote MCP).** Step 2 gains a fourth option:
paste an HTTPS MCP URL plus a bearer token. The skill verifies via
`gstack-gbrain-mcp-verify` (NETWORK / AUTH / MALFORMED classifier with
one-line remediation hints), registers via `claude mcp add --scope user
--transport http gbrain --header "Authorization: Bearer ..."`, then
skips local install / doctor / transcript ingest because Path 4 has
no local dependencies. Steps 5, 5a, 7, 8, 9, 10 all branch on mode.
Idempotent re-run skips Step 2 entirely when `gbrain_mcp_mode=remote-http`
is already detected.
- **`bin/gstack-gbrain-mcp-verify`** (new). POSTs `initialize` to a remote
MCP URL with the bearer from `$GBRAIN_MCP_TOKEN` (never argv) and
classifies failures into NETWORK / AUTH / MALFORMED with concrete
remediation hints. Probes `tools/list` for forward-compat with future
gbrain releases that ship `mcp__gbrain__sources_add` (returns
`sources_add_url_supported: true|false`).
- **`bin/gstack-artifacts-init`** (new). Replaces `gstack-brain-init`. Asks
the user to pick GitHub (auto via `gh`), GitLab (auto via `glab`), or
manual URL paste. Creates `gstack-artifacts-$USER` (private), stores the
HTTPS URL canonically in `~/.gstack-artifacts-remote.txt`, and prints the
brain-admin hookup command labeled "Send this to your brain admin" (always
prints, never auto-executes — see `setup-gbrain/memory.md` for why).
- **`bin/gstack-artifacts-url`** (new). Small helper for HTTPS↔SSH
conversion plus host / owner-repo extraction. Mirrors the spirit of
`gstack-slug` so URL-format string-mangling lives in one place.
- **`gbrain_mcp_mode` field in `gstack-gbrain-detect` output.** 3-tier
fallback: `claude mcp get gbrain --json``claude mcp list` text-grep →
`~/.claude.json` jq read. Defense in depth: if Anthropic moves the file
format, the first two tiers absorb it.
- **`gstack-upgrade/migrations/v1.27.0.0.sh`**. Six-step journaled migration
for the brain → artifacts rename. Each step writes its name to
`~/.gstack/.migrations/v1.27.0.0.journal` on success; re-entry resumes
from the next un-done step. On final success, journal is replaced by
`v1.27.0.0.done`. User opt-out writes a `skipped-by-user` marker so the
prompt doesn't fire again until `/setup-gbrain --rerun-migration`.
- **`setup-gbrain/memory.md`** has a new "Path 4: Remote MCP setup"
section covering the bearer storage trade-off, the always-print
brain-admin hookup pattern, the CLAUDE.md block format (no token), and
token-rotation guidance.
#### Changed
- **`gbrain_sync_mode` config key renamed to `artifacts_sync_mode`.** Hard
rename, no dual-read alias. The migration script rewrites the key in
`~/.gstack/config.yaml` and any "## GBrain Configuration" block in
CLAUDE.md. Internal callers updated:
`bin/gstack-config`, `bin/gstack-gbrain-detect`, `bin/gstack-brain-sync`,
`bin/gstack-brain-enqueue`, `bin/gstack-brain-uninstall`,
`bin/gstack-timeline-log`, `scripts/resolvers/preamble/generate-brain-sync-block.ts`.
- **Preamble `BRAIN_SYNC: ...` line renamed to `ARTIFACTS_SYNC: ...`** and
branches on `gbrain_mcp_mode`. In remote-http mode it emits
`ARTIFACTS_SYNC: remote-mode (managed by brain server <host>)` to make
clear that local sync is a no-op by design.
- **`bin/gstack-brain-restore`, `bin/gstack-gbrain-source-wireup`, and
`bin/gstack-brain-uninstall`** read `~/.gstack-artifacts-remote.txt` with
`~/.gstack-brain-remote.txt` as a migration-window fallback. Once the
v1.27.0.0 migration runs, only the artifacts file remains.
- **`/sync-gbrain` is a graceful no-op in remote-http mode** (V1). Prints a
one-line note pointing at the brain server and exits cleanly. Local-mode
users see no change.
#### Removed
- **`bin/gstack-brain-init` deleted.** Replaced by `bin/gstack-artifacts-init`.
Anyone running the old name post-upgrade gets a clean "command not found"
rather than a silent rename — per the gstack rule "avoid backwards-
compatibility hacks." Existing users on disk have their state migrated by
v1.27.0.0.sh.
- **`test/gstack-brain-init-gh-mock.test.ts` deleted.** Replaced by
`test/gstack-artifacts-init.test.ts` covering the same gh-mock pattern
plus the new GitLab branch and the brain-admin printout.
#### For contributors
- **59 new unit tests + 2 gate-tier E2E tests + 4 regression tests.**
Highlights:
- `test/gstack-gbrain-mcp-verify.test.ts` (13 tests) covers each error
class via mocked curl, asserts the dual `Accept` header is set on
every call, regression-tests the token-never-on-stdout invariant.
- `test/gstack-artifacts-init.test.ts` (16 tests) covers gh / glab /
both / neither provider selection, HTTPS canonical storage, the
URL-form-supported branch in the brain-admin printout, and idempotent
re-run.
- `test/gstack-gbrain-detect-mcp-mode.test.ts` (19 tests) verifies each
of the 3 detection tiers in isolation, plus the schema-regression
check that `/sync-gbrain`'s parser doesn't break on the new fields.
- `test/migrations-v1.27.0.0.test.ts` (11 tests) covers all six
migration steps including journal-resume, idempotent re-run, the
add-before-remove ordering for source swap, and the remote-MCP
print-only branch.
- `test/no-stale-gstack-brain-refs.test.ts` greps the broader tree
(bin, scripts, *.tmpl, generated *.md, test/) for stale identifiers.
- `test/post-rename-doc-regen.test.ts` confirms gen-skill-docs output
has no `gstack-brain` strings post-rename.
- `test/setup-gbrain-path4-structure.test.ts` is a fast structural lint
that catches AUQ-pacing regressions in the Path 4 prose without
spending eval tokens.
- **`scripts/resolvers/preamble/generate-brain-sync-block.ts`** detects
remote-http mode by reading `~/.claude.json` directly (no claude
subprocess on every preamble — the hot path stays fast).
- **`test/helpers/touchfiles.ts`** wires `setup-gbrain-remote` and
`setup-gbrain-bad-token` into the gate-tier E2E selection.
- **Preamble byte budget ratcheted from 35K to 36.5K** to honor the
remote-mode probe in `generate-brain-sync-block.ts`.
## [1.26.5.0] - 2026-05-06
## **The v1.26 memory feature now actually works on a fresh `/setup-gbrain` install, and `/sync-gbrain --full` actually registers github-hosted code sources.**