Repository navigation
fix: sql explain / AI consent and output fixes - #169
Merged
Merged
Conversation
…#141) HasPlaceholders only tracked single-quote state, so a "$1" inside a dollar-quoted string constant ($$ … $$ or $tag$ … $tag$) was reported as a parameter placeholder and `sql explain` printed the generic-plan "parameter values unknown" caveat for a query that has no parameters. The scanner now recognises a dollar-quote opening delimiter and skips to its matching close (or to the end of the query when unterminated). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The --json branch of runSQLExplain printed the raw plan and returned before the `if llm != nil` block, so --json --ai resolved the model, asked for consent to send the SQL, then silently dropped the AI explanation. Appending prose to --json output would break parsers, so the combination is now rejected up front as a usage error (exit 64), before a model is resolved, consent is requested, or a connection made. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gs (#140) printAISection was written for `pgbot explain`/`ask` and hard-coded "The findings above are complete/authoritative…". `sql explain --ai` reused it, so a command that computes no findings told the reader the findings were complete — including on model error, when only a plan had been printed. printAISection now takes what the section explains (findings or a query plan) and words the fallback note and footer accordingly; the findings commands keep their existing text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
confirmDisclosureOf returned true for `yes || !isInteractive()`, so in CI, pipes, containers and agent shells the disclosure line was printed and the payload sent without any confirmation or --yes. For `sql explain --ai` that payload is the user's SQL text, which can carry literal values; `explain` and `ask` share the same gate. Only --yes now short-circuits the prompt for a remote endpoint. With no terminal to answer it, the command refuses before connecting and tells the user to re-run with --yes. Local endpoints keep auto-consent since nothing leaves the machine. isInteractive becomes a variable so the regression test can pin it; the piped `sql explain --ai` help example now shows --yes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
) runExplain resolved the model first and returned ai.Resolve's error before connecting, so with no key `pgbot explain` printed nothing and exited 3 (the connection/execution-failure code) — contrary to the README's promise that the deterministic report still stands when the key is unset. Only a failed model call after rendering degraded gracefully. A missing model is now not a command error: resolveExplainModel returns the resolve error as the AI section's "unavailable" reason, the inspection runs and renders as usual, and the process exits on the findings' code. Consent is still asked before connecting when a model is configured, and a refused consent still aborts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md
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.
Fixes #156
Fixes #143
Fixes #140
Fixes #139
Fixes #141
One commit per issue, each with a regression test and a CHANGELOG
[Unreleased] → Fixedline. The--jsonContext schema (internal/model,schema/*.json) is unchanged.What changed
pgbot explainexits 3 without printing the deterministic report whenGEMINI_API_KEYis unset #156pgbot explainwith no AI key. Before,runExplainreturnedai.Resolve's error before connecting, so it printed no report and exited 3. Now a missing model is passed to the AI section as the "unavailable" reason. The inspection runs, the deterministic report prints, and the exit code comes from the findings, asREADME.mdalready promised. When a model is configured, consent is still asked before connecting.confirmDisclosureOftreated!isInteractive()as consent, so with no terminal (CI, pipes, containers) it sent data to a remote provider without asking. Only the existing--yesflag skips the prompt now. With no terminal, the command stops before connecting and says to re-run with--yes. Local endpoints still need no confirmation. This gate is shared, sosql explain --ai,explainandaskall change. The pipedsql explain --aihelp example and the README now mention--yes.printAISectiontakes what it explains: findings or a query plan. Forsql explain --ai, the footer and the "unavailable" note now refer to the query plan, not "the findings above".--json --ai. This combination is now a usage error (exit 64), checked before a model is resolved, consent is asked or a connection is made. Before, it asked for consent and then silently dropped the AI part. Adding prose to--jsonoutput would break parsers.HasPlaceholders. Text inside dollar-quoted literals ($$…$$,$tag$…$tag$) is now skipped, so a$1inside one is no longer counted as a placeholder.How verified
TestHasPlaceholders(new cases),TestSQLExplainRejectsJSONWithAI,TestPrintAISectionWording,TestConfirmDisclosureNonInteractive,TestResolveExplainModelWithoutKey. The HasPlaceholders treats $1 inside a dollar-quoted literal as a placeholder #141, SQL explain --json --ai returns before the AI section #139 and sql explain --ai sends SQL text to the model provider without consent when stdin is not a TTY #143 tests fail onmainwith assertion errors. The SQL explain --ai describes the plan as findings #140 andpgbot explainexits 3 without printing the deterministic report whenGEMINI_API_KEYis unset #156 tests fail onmainat compile time, because they call the newaiSubjectparameter and the newresolveExplainModelhelper.gofmt -l .(nothing listed),go build ./...,go vet ./...,go test -race ./...,golangci-lint run ./...(v2.14.0, 0 issues): all clean. The DB integration tests skipped becausePGBOT_TEST_DSNwas not set.sql explain --aiwithout--yesaborts before connecting and prints the--yeshint.--json --aiexits 64.explainwith no key now goes on to connect instead of exiting with the key error.explainreport against a live Postgres, because the local test database wasn't available.🤖 Generated with Claude Code