Conversation
Step 2 of the plugin work. The dialect cannot be guessed safely, so it has to be asked — and an MCP server on stdio has no channel to ask through. Asking therefore lives in the CLI and, later, in /clgraph:setup. clgraph detect proposes a SQL directory and a dialect with the evidence attached, ranked: a dbt profile's adapter type (authoritative, high confidence), then dialect-specific syntax markers, then parse scoring. It writes nothing and decides nothing. --json makes it agent-readable. clgraph init records the answer in clgraph.toml, or [tool.clgraph] with --into-pyproject, and adds .clgraph/ to .gitignore. Run bare it prompts with detection pre-filling the defaults; with --yes it never prompts and fails instead, which is how agents and CI invoke it. A missing dialect is an error either way. Two things testing turned up, both fixed here: Parse scoring counted only raised ParseErrors, but sqlglot far more often degrades unsupported syntax into an exp.Command node without erroring — so a wrong dialect scored as a clean parse. Both now count as failures. Even so, scoring stays weak: Snowflake-only syntax like QUALIFY and IFF() parses cleanly under all eight candidates. TestParseScoringIsWeak pins that, since it is the concrete reason this design refuses to guess. sqlglot logged warnings while probing wrong dialects, and in any process with logging configured to stdout those landed inside the JSON that `clgraph detect --json` emits. Scoring now silences sqlglot and restores the prior level.
This branch has not been deployed
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.
Step 2 of packaging clgraph as a coding-agent plugin: A6 (detection) and A7 (
clgraph init).Why
The dialect can't be guessed safely, so it has to be asked. But an MCP server on stdio has no channel to ask through — stdin and stdout are the protocol. So asking lives in the CLI, and later in
/clgraph:setupwhere the agent asks on the server's behalf.clgraph detectProposes a SQL directory and a dialect, with evidence attached and a confidence rating. Writes nothing, decides nothing.
Evidence is ranked: a dbt profile's adapter
type:(authoritative →high), then dialect-specific syntax markers (QUALIFY,SAFE_CAST,::VARIANT, …), then parse scoring.--jsonfor agents.clgraph initRecords the answer in
clgraph.toml, or[tool.clgraph]with--into-pyproject, and adds.clgraph/to.gitignore. Run bare it prompts with detection pre-filling the defaults;--yesnever prompts and fails instead — how agents and CI invoke it. A missing dialect is an error either way, never a guess.Validation runs before anything is written, so a rejected call leaves the project untouched.
Two bugs testing turned up
Parse scoring counted the wrong thing. It counted raised
ParseErrors, but sqlglot far more often degrades unsupported syntax into anexp.Commandnode without erroring — so a wrong dialect scored as a clean parse. Both now count as failures.Even fixed, scoring stays weak: Snowflake-only syntax like
QUALIFYandIFF()parses cleanly under all eight candidates.TestParseScoringIsWeakpins that, because it's the concrete evidence for why this design refuses to guess. The module docstring says so plainly rather than overselling the heuristic.sqlglot warnings corrupted
--json. Probing wrong dialects logs warnings, and in any process with logging configured to stdout they landed inside the JSON an agent was parsing. Caught only when the full suite ran in an order where airflow had configured logging — it passed in isolation. Scoring now silences sqlglot and restores the prior level.Test plan
tests/test_detect.py— 30 tests: directory ranking, noise exclusion, dbt marking, all three evidence tiers, low-confidence honesty on portable SQL, JSON serialization, a read-only assertion, and the output-purity regressiontests/test_config_writer.py— 23 tests: round trip throughresolve(), both config surfaces, overwrite refusal, validation-before-write,.gitignoreidempotence and formattingtests/test_cli.py— 11 new tests for both commandsmake pre-commitclean;tyholds at its 52-diagnostic baselineQUALIFY/IFF()at medium confidence →--yeswithout a dialect refuses and names the suggestion →initwrites config and gitignore → the MCP server boots configured and tracesanalytics.revenue.bucket→raw.orders.amount→ re-runninginitrefuses without--forceNext
Step 3 — A2,
clgraph indexand the on-disk cache.