Skip to content

docs(ai): design the BYOH integration, and supersede ADR-007 - #673

Merged
EVWorth merged 1 commit into
mainfrom
docs/ai-design
Sep 12, 2026
Merged

EVWorth merged 1 commit into
mainfrom
docs/ai-design

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Design only — no code. Two documents for red-penning before anything gets built.

  • docs/design/AI_INTEGRATION.md — the tool surface, the policy grading, the session model, and what each harness can actually do.
  • ADR-011 in TECH_DECISIONS.md, superseding ADR-007, whose rationale assumed we hold the model session.

The decision

SQLPilot does not call a model. It exposes a database, safely, to whatever harness the user already runs and pays for. No keys, no provider abstraction, no token accounting, and — because we have no system prompt — no prompt to inject into. What remains is the part SQLPilot is uniquely placed to do: be the policy boundary between an agent and a live database.

Two things that fell out of the design

The keystone. Approval for a destructive action happens in SQLPilot's own window, whatever is driving. Copilot CLI has --allow-all and --yolo; Claude Code has --permission-mode. Any design that relies on the harness to ask the user is one flag away from not asking. BYOH is what makes the alternative possible — as a tool provider we reuse the confirmation the grid and the restore already use, rather than inventing a second one.

The old bug class becomes structural. run_select_query checked sql.to_uppercase().starts_with("SELECT") on the whole string and handed it to an executor that splits on ;, so SELECT 1; DROP TABLE users passed the read-only tool. The design replaces that with the statement splitter and effective_verb that already exist, tested, in mas-core — single-statement enforcement is a rule of the tool surface, not a string check.

Harness facts, verified 2026-09-12

Dated in the document because these surfaces move.

Both harnesses take an mcpServers config with Streamable HTTP and bearer headers, so slice 1 serves both. For the in-app view they are not equal: Claude Code has --output-format stream-json and --permission-prompt-tool (so approvals render natively in our UI); Copilot CLI documents neither, so it starts as an embedded terminal and upgrades if a structured mode appears.

Two constraints found while checking, both recorded:

  • Don't pass --bare — that mode doesn't read the subscription login and expects ANTHROPIC_API_KEY, which is exactly what we refuse to handle. It also means the session loads the working directory's hooks and MCP config, so it must be launched in a controlled directory.
  • Don't embed the Agent SDK — Anthropic's terms don't permit a third-party product to offer claude.ai login through it. Spawning the user's own authenticated CLI is what keeps this BYOH. (Their branding guidance also rules out labelling anything "Claude Code" in our UI.)

Open questions in §9

Transport and token storage; how a harness config names a connection that outlives a session id; whether tool descriptions should teach the model the policy so a refusal is instructive; the granularity of sampling grants; and whether run_ddl exists at all in v1, or whether the agent writes the migration and the user runs it.

The 13 open area/ai issues are obsolete under this design rather than fixed — they describe the implementation being replaced. I'd close them against this ADR once it's agreed, rather than leaving them to imply work that will never happen.

The AI feature is being rebuilt around a decision: SQLPilot does not call
a model. It exposes a database, safely, to whatever harness the user
already runs and pays for.

AI_INTEGRATION.md covers the tool surface (shape / analysis / query /
app-aware), the policy grading (data posture × environment × verb), the
session model, and the harness adapters. ADR-011 records the decision
and supersedes ADR-007, whose rationale assumed we hold the model
session — and which promised a rate limiter and a token budget that were
never built and are now the harness's concern.

Two things fell out of the design that are worth naming here.

The keystone: approval for a destructive action happens in SQLPilot's
own window, whatever is driving. Harnesses have escape hatches —
Copilot CLI has --yolo — so a design that relies on the harness to ask
is one flag away from not asking. BYOH is what makes this possible: as a
tool provider we reuse the confirmation the grid and the restore already
use, rather than inventing a second one.

And the old implementation's whole class of bug becomes structural: the
prefix check that let `SELECT 1; DROP TABLE users` through a "read-only"
tool is replaced by the statement splitter and `effective_verb` that
already exist, tested, in mas-core.

Harness facts were verified against current docs on 2026-09-12 and are
dated in the document, because those surfaces move. Two constraints
found while checking: Claude Code's --bare mode does not use the
subscription login and wants an API key, so we must not pass it; and
Anthropic's terms do not permit a third party to offer claude.ai login
through the Agent SDK, so we spawn the user's own authenticated CLI
rather than embedding a library.
@EVWorth
EVWorth merged commit 281ff4f into main Sep 12, 2026
12 checks passed
@EVWorth
EVWorth deleted the docs/ai-design branch September 12, 2026 14:08
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