Repository navigation
docs(ai): design the BYOH integration, and supersede ADR-007 - #673
Merged
Merged
Conversation
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.
This was referenced Sep 12, 2026
[P1][bug] AI tool handler uses .expect() — slow tool panics the worker and kills the AI session
#314
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.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-alland--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_querycheckedsql.to_uppercase().starts_with("SELECT")on the whole string and handed it to an executor that splits on;, soSELECT 1; DROP TABLE userspassed the read-only tool. The design replaces that with the statement splitter andeffective_verbthat already exist, tested, inmas-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
mcpServersconfig 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-jsonand--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:
--bare— that mode doesn't read the subscription login and expectsANTHROPIC_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.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_ddlexists at all in v1, or whether the agent writes the migration and the user runs it.The 13 open
area/aiissues 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.