Skip to content

Optional code-intelligence provider contract (GBrain / Sourcebot / Graphify)#16

Merged
time-attack merged 9 commits into
codex/gstack-2from
time-attack/gbrain-provider-contract
Jul 22, 2026
Merged

Optional code-intelligence provider contract (GBrain / Sourcebot / Graphify)#16
time-attack merged 9 commits into
codex/gstack-2from
time-attack/gbrain-provider-contract

Conversation

@time-attack

@time-attack time-attack commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Optional code-intelligence provider contract

Adds a small, optional way to pick how your codebase gets indexed and
searched, so gstack stops maintaining a home-grown indexer and instead defines a
contract that external providers implement. gstack stays fully functional with
nothing selected — callers fall back to grep / the file-only decision store.

What you can do

gstack-code-intelligence options              # GBrain (recommended), Sourcebot, Graphify + live availability
gstack-code-intelligence select graphify
gstack-code-intelligence consent               # per-repo; only for providers that send code off-machine
gstack-code-intelligence index                 # index this repo with the selected provider
gstack-code-intelligence search "what calls db"

The contract

Repo-oriented, not document-store: register_source / refresh / search /
status are required; add / delete / export are optional capabilities a
provider may advertise. Typed failures; a closed capability set enforced at
construction. Consent is two-axis and explicit: per-repo egress consent before
any content leaves the machine (skipped for local providers), and install consent
for Graphify (never auto-installed).

Three real, runtime-driven adapters (no MCP client)

  • GBrain (recommended) — gbrain CLI; full contract fit incl. the document ops.
  • Sourcebot — self-hosted server over HTTP (POST /api/search + a
    config.json edit). Local tool; no API key needed with anonymous access.
  • Graphify — local graphify CLI (graphify update + graphify query);
    fully local, never auto-installed.

Verified against real environments

Every adapter was driven against the real running tool in an isolated environment,
not just unit fakes: real Postgres-backed GBrain 0.42.56, live Sourcebot
v6.5.0
(keyless via anonymous access), and real Graphify 0.9.23 — all three
index + search a real repo end-to-end. Two of the first-round fixes were wrong and
real execution reversed them (a gbrain flag removal that broke code indexing, and
a graphify LLM claim); both are corrected and recorded honestly in
docs/designs/CODE_INTELLIGENCE_PROVIDER_CONTRACT.md. 24 unit tests, pinned to the
real captured output formats, no live tools required.

Scope / not in this PR

Standalone library + CLI + design doc; no skill-template, runtime-config, or
generated-file changes (so no gen:gstack2 / parity re-baseline). Routing the
existing gstack-decision-semantic / brain-context-load consumers through the
contract, and retiring the bespoke GBrain glue, are the documented phase 2–4
rollout — the old glue is untouched here.

🤖 Generated with Claude Code


Summary by cubic

Adds an optional code‑intelligence provider contract and CLI so repos can index and search code via GBrain, Sourcebot, or Graphify. Keeps existing flows working with zero setup and falls back to grep when no provider is selected.

  • New Features

    • Provider contract: repo‑oriented. Required ops: register_source, refresh, search, status. Optional: add, delete, export. Typed failures and capability gating.
    • Adapters: GBrain via gbrain CLI; Sourcebot over HTTP (POST /api/search); Graphify via graphify CLI. Live availability checks with graceful PROVIDER_UNAVAILABLE degrade.
    • Consent: explicit per‑repo egress consent for non‑local providers. Graphify is fully local and never auto‑installed.
    • CLI: gstack-code-intelligence options|status|select|consent|index|search.
    • Verified: real runs against GBrain 0.42.56, Sourcebot v6.5.0 (anonymous local), Graphify 0.9.23. 24 unit tests pinned to real output formats.
    • Backward‑compat: no changes to current consumers; old glue remains. Fallback uses grep and the file‑only decision store.
  • Migration

    • No action required. gstack works unchanged without a provider.
    • To opt in: run gstack-code-intelligence select <gbrain|sourcebot|graphify>, then consent (for non‑local), index, and search "<query>".

Written for commit ab7989c. Summary will update on new commits.

Review in cubic

Sinabina and others added 9 commits July 21, 2026 17:16
Design for the OPTIONAL code-intelligence provider contract that lets a
user pick how their codebase is indexed and searched, replacing gstack's
~17k LOC of bespoke GBrain glue. Repo-oriented ops (register_source/
refresh/search/status required; add/delete/export optional), a per-provider
capability matrix, GBrain-recommended-first selection, repo-scoped + install
consent, and a phased rollout that keeps gstack fully functional with no
provider selected. All three providers are driven from the runtime via CLI
or HTTP — no MCP client.

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

contract.ts: repo-oriented interface (four required ops, three optional),
typed CodeProviderError, egress + capability consent guards.

Three real, runtime-drivable adapters:
- GbrainProvider: gbrain CLI (reuses lib/gbrain-exec + lib/gbrain-sources),
  all seven capabilities.
- GraphifyProvider: graphify CLI — `graphify <dir>` builds the local graph,
  `graphify query` searches it, export reads graphify-out/graph.json. Fully
  local; never auto-installed.
- SourcebotProvider: self-hosted server over HTTP — register writes a local
  git connection to config.json, search is POST /api/search, status is a
  liveness probe. Loopback base URL = local (no egress); remote = consent.

selection.ts persists the chosen provider + per-repo indexing consent under
$GSTACK_HOME. picker.ts recommends GBrain first, resolves the selected
provider or null (provider-OFF), and probes live availability. Every adapter
degrades to PROVIDER_UNAVAILABLE when its tool/server is absent.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
User-facing command tying the contract together: `options`/`status` show
providers with GBrain first and live availability, `select <provider>`
persists the choice, `consent [path]` records per-repo indexing consent,
`index [path]` registers + indexes the repo with the selected provider
(refusing non-local providers until consented), and `search <query>` runs a
query, degrading with a clear message when the provider is unavailable.

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

Capability matrix, result parsers, selection store + per-repo consent +
provider-OFF, egress gating, and each adapter end-to-end against a fake CLI
shim (gbrain, graphify) or injected fetch + temp config.json (sourcebot),
plus PROVIDER_UNAVAILABLE degrade for every provider. 19 tests, no live
tools required.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…e testing)

Parallel real-environment tests (graphify 0.9.23, Sourcebot v5 in Docker,
gbrain 0.42.56) surfaced real mismatches:

- graphify: build via `graphify update <dir>` (the local, no-LLM path) instead
  of `graphify <dir>` (which runs an LLM backend needing a key + network, so the
  old path wasn't actually local); query via `graphify query --graph <graph.json>`
  so it reads the indexed graph regardless of cwd; parse the real NODE/EDGE output
  (file lives at src=/at=) instead of an invented format.
- sourcebot: Sourcebot v5 gates /api/search behind auth — send
  `Authorization: Bearer <SOURCEBOT_API_KEY>`; treat 401/403 as PROVIDER_UNAVAILABLE;
  make status probe /api/search without following the login redirect.
- gbrain: degrade engine/DB init failures (e.g. pglite WASM, garrytan/gbrain#223)
  to PROVIDER_UNAVAILABLE with a one-line message instead of PROVIDER_ERROR + a raw
  stack dump; drop flags the real CLI doesn't define (`sync --strategy`,
  `search --source`); align put/delete to stdin, export to brain-wide.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
search was running in cwd and missing the repo you indexed. Persist the indexed
path per provider in the selection store and resolve it back so `search` reads
the same graph `index` built. Graphify availability now checks `graphify --version`
(installed = selectable) instead of "a graph already exists here", and the CLI
keys Graphify sources on the repo path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Rewrite the Graphify and Sourcebot expectations against the real formats captured
from live tools (graphify NODE/EDGE query output; Sourcebot v5 response + Bearer
auth), add a gbrain engine-down -> PROVIDER_UNAVAILABLE degrade test and a
no-phantom-`--source` search assertion, and cover the persisted indexed-root path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Update the capability matrix and provider notes to the verified real interfaces
(graphify update, Sourcebot v5 Bearer auth) and add a "Verified against real
environments" section documenting what the live tests found and fixed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Ran real backends in isolated environments (real Postgres-backed gbrain,
live Sourcebot v6.5.0 with anonymous access, real graphify 0.9.23). All three
now index + search end-to-end. Fixes:

- gbrain: RESTORE `--strategy code` in refresh — round 1 removed it on a --help
  misread, which silently stopped code from ever being indexed. refresh now runs
  the verified two-pass (`sync`, then `sync --strategy code --full`). Pinned by a
  new test so the regression can't return.
- sourcebot: an API key is NOT required for local use — anonymous access
  (FORCE_ENABLE_ANONYMOUS_ACCESS=true) serves /api/search keyless (verified). Key
  stays optional; only the messaging changed (anonymous-access first, key as
  fallback) plus a note that a local repo needs remote.origin.url to index.
- graphify: correct the docstring — for CODE both `graphify <dir>` and
  `graphify update` are AST-only (no LLM); the LLM only renames clusters and
  ingests non-code, which our parser ignores. No LLM mode; local=true is correct.

Docs: capability matrix + "Verified against real environments" updated to record
all three proven end-to-end and to correct the two first-round mistakes.

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

cursor Bot commented Jul 22, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@time-attack
time-attack changed the base branch from main to codex/gstack-2 July 22, 2026 01:15
@time-attack
time-attack merged commit bfc9224 into codex/gstack-2 Jul 22, 2026
5 of 18 checks passed
time-attack pushed a commit that referenced this pull request Jul 22, 2026
…ical rules

Documents the #16 code-intelligence marketplace (GBrain/Sourcebot/Graphify) as
an authorized optional external-service category: off by default, grep fallback,
per-repo egress consent for off-machine providers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
time-attack pushed a commit that referenced this pull request Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant