Skip to content

feat: /sql-graph — a model's CTEs, joins and filters as a list in a pane - #29

Open
hkaltai wants to merge 13 commits into
mainfrom
feat/sql-graph
Open

hkaltai wants to merge 13 commits into
mainfrom
feat/sql-graph

Conversation

@hkaltai

@hkaltai hkaltai commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What this does

/sql-graph [model] opens a pane listing the model's CTEs, joins and filters from the altimate-code dbt_sql_graph tool (AltimateAI/altimate-code#1735, which merges first). With no name it uses the model Claude last read or edited.

  • One row per node in dependency order: name, type, column count and its inputs (rows, edges and selection use the node's unique id, so two nodes with one name stay two). Pressing a row shows that node's SQL. No picture on the terminal; the list is the surface.
  • After Claude edits a model, one context line, N CTEs · /sql-graph, counted from the file. No backend call on edit.
  • The tool starts the dbt adapter, so it runs through the CLI with --allow-write (the plugin's MCP server stays read-only). A failure (no dbt project, no Altimate key, read-only) is shown in the pane and as the command's reply.

This branch contains the Power User foundation commits; this PR's own change is hooks/features/sql-graph.tsx, its test and SqlGraphState in types/index.d.ts.

Verification

claude plugin test ./plugins/altimate-code (228 pass, including the sql-graph tests: ordering, command, pane, row press, same-named nodes, failure, escapes, SQL limit, model folders, edit line) and bash tests/*.sh (all pass). claude plugin validate --strict reports the same warnings as the foundation branch before this change.

Cost

One backend call and one warehouse metadata read per /sql-graph, never per edit.

Demo

Review

Independent Claude and Codex reviews ran on this PR; every finding has a reply in the PR comments. Open follow-ups, not changed here: a nested monorepo project is not selected for the CLI run (plugin-wide runTool behaviour), docs, a second project lookup per edit, parallel asks not merged.

Demo video (hosted)

P-01.mp4 — watch on Notion (Altimate workspace; recorded from the approved head of this PR).

🤖 Generated with Claude Code

hkaltai and others added 8 commits November 13, 2026 16:31
Each feature gets its own file under hooks/features/, called by name from
features/index.ts in a fixed order: its own hooks, the session and turn
events, its band line and its tool-call phases. One tool.call hook
(tool-chain.ts) runs Bash and file handling in fixed phases: bashRewrite,
bashGate, the call, bashAfter, editAfter, readOrEditAfter. The status line
is built from parts (status-line.ts). runTool moves to altimate-cli.ts with
a `write` option that goes through the CLI with --allow-write.
dbt-command.ts finds the dbt invocations in a shell command line. New
userConfig fields: maxScanBytes, healthBlocksPush, healthConfigPath,
commentsPollSeconds, commentsInContext.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Subshells after keywords, case patterns, process substitution, arrays,
arithmetic and function definitions parse again; quotes in a heredoc inside
a substitution are text; a function or case pattern named dbt is not an
invocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… newer ask is not replaced by an older answer, output is plain text

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… stay two

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…xt, a size limit on a node's SQL, model folders inside a model path, a package's models are not the project's

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@hkaltai

hkaltai commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Review round (Claude + Codex, independent CLI runs) — findings and replies

Fixes are in the latest commits on this branch.

# Finding (reviewer) Reply
1 MAJOR error/failure text, model titles and node text reach the terminal unsanitized (both) Fixed: one plain() (OSC/CSI escapes, C0/C1 controls, U+2028/9) now covers the message, titles, command replies, row labels and the SQL view.
2 MAJOR selected SQL has no size bound (Codex) Fixed: a node's SQL is cut at 20,000 characters with a "N more characters not shown" line.
3 MINOR model folders named tests, macros… inside a model path rejected (both) Fixed: macros/tests/analyses/snapshots/seeds excluded only at the top of the project; target/dbt_packages/dbt_modules at any depth. A dependency package's own models are no longer taken as the project's.
4 MINOR failure reason lost when output is empty (Claude) Fixed: falls back to metadata.error.
5 MINOR test fixtures off-contract; unsupported label query (both) Fixed: fixtures carry id/error; the query is replaced by an inputsOf assertion. Tests added for escapes, the SQL limit, same-named nodes, folders.
6 Node identity by name (this PR's side of tool PR #1735) Rows, edges, ordering and selection now use the node id.
7 MAJOR nested monorepo project not selected for the CLI run (Codex) Deferred, pre-existing and plugin-wide: the CLI finds the project from its working directory, which runTool/runAltimate (foundation) set the same way for every feature. Not changed here.
8 MINOR gating hook without .catch for command.run (Codex) Not changed: the same diagnostic is reported for the integrations and lineage commands; claude plugin validate --strict . passes.
9 MINOR docs, a second project lookup per edit, parallel asks not merged, bidi controls, surrogate split in the cut (Claude/Codex) Noted for follow-up; none affects correctness of the pane.

Attack-the-fix gate (fresh Codex and Claude processes): PASS. claude plugin test ./plugins/altimate-code 228 pass, claude plugin validate --strict . passes, tests/*.sh pass.

@hkaltai

hkaltai commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

review-loop: APPROVED at 423558d

Confirm gate (fresh Claude + Codex, read-only): both APPROVED, no findings.

@kilo-code-bot

kilo-code-bot Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 2 Issues Found | Recommendation: Merge after the two suggestions (or accept as-is)

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 2

The incremental change since 5e37e6ad (the .. resolution in sql-graph.tsx and its two new test cases) resolves the earlier unanchored-prefix finding: an absolute path is stripped only against from, and an absolute path outside the project maps to null. The new loop does introduce one new edge case (a path that climbs above the project root is clamped instead of being treated as outside), and the carried order-of-invocations suggestion is unchanged at HEAD.

Issue Details (click to expand)

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/features/sql-graph.tsx 54 kept.pop() on an empty list silently drops a .. that leaves the project, so packages-install-path: ../vendor (or /repo/../vendor) is read as vendor inside the project and a nested project under <project>/vendor is treated as an installed package
plugins/altimate-code/hooks/dbt-command.ts 300 Sorting invocations by start, which includes leading VAR=x words, lists an outer command before a $(dbt …) written in its own assignment: T=$(dbt build) dbt test yields ['test', 'build'], against the "in the order written" contract
Files Reviewed (3 files)
  • plugins/altimate-code/hooks/features/sql-graph.tsx - 1 new suggestion (.. clamped at the project root)
  • plugins/altimate-code/hooks/features/sql-graph.test.tsx - no new issues (new cache/../vendor cases verified against the pre-fix behaviour; the escaping-above-root case is not covered)
  • plugins/altimate-code/hooks/dbt-command.ts - 1 carried suggestion (re-verified at HEAD: start is still words[0]!.start at line 457, unchanged since the last review)

Fix these issues in Kilo Cloud

Previous Review Summaries (4 snapshots, latest commit 5e37e6a)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 5e37e6a)

Status: 1 Issue Found | Recommendation: Merge after the one remaining suggestion (or accept as-is)

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1

The two files changed since the previous review (sql-graph.tsx, sql-graph.test.tsx) resolve the earlier prefix-strip finding: the install-path value is now compared as a path from the enclosing project with an anchored prefix, an absolute path outside the project maps to no folder, and the new tests cover /vendor, vendor/repo/, /vendor/repo/, cache/repo/vendor and /opt/repo/vendor. No new defect found in those changed lines.

Issue Details (click to expand)

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/dbt-command.ts 300 Sorting invocations by start, which includes leading VAR=x words, lists an outer command before a $(dbt …) written in its own assignment: T=$(dbt build) dbt test yields ['test', 'build'], against the "in the order written" contract
Files Reviewed (3 files)
  • plugins/altimate-code/hooks/features/sql-graph.tsx - no new issues (previous prefix-strip finding fixed)
  • plugins/altimate-code/hooks/features/sql-graph.test.tsx - no new issues (new install-path cases verified against the pre-fix behaviour)
  • plugins/altimate-code/hooks/dbt-command.ts - 1 carried suggestion (re-verified at HEAD, unchanged since the last review)

Previous review (commit 0c3cc7d)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 2
Issue Details (click to expand)

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/dbt-command.ts 300 Sorting invocations by start (which includes leading VAR=x words) lists an outer command before a $(dbt …) written in its own assignment: T=$(dbt build) dbt test yields ['test', 'build'], against the "order written" contract
plugins/altimate-code/hooks/features/sql-graph.tsx 57 The project-prefix strip is unanchored (vendor/repo/x under /repo becomes vendorx), and !own.startsWith('/') is unreachable after filtering empty segments, so an absolute packages-install-path outside the project is compared as project-relative
Files Reviewed (4 files)
  • plugins/altimate-code/hooks/dbt-command.ts - 1 issue
  • plugins/altimate-code/hooks/dbt-command.test.ts
  • plugins/altimate-code/hooks/features/sql-graph.tsx - 1 issue
  • plugins/altimate-code/hooks/features/sql-graph.test.tsx

Fix these issues in Kilo Cloud

Previous review (commit 33d997b)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
plugins/altimate-code/hooks/dbt-command.ts 308 substitutionsIn tracks ' but not ", so an apostrophe inside a double-quoted word turns off scanning and echo "it's $(dbt run)" reports no invocation — a fail-open for the scan gate and defer injection
Files Reviewed (4 files)
  • plugins/altimate-code/hooks/dbt-command.ts - 1 issue
  • plugins/altimate-code/hooks/dbt-command.test.ts
  • plugins/altimate-code/hooks/features/sql-graph.tsx
  • plugins/altimate-code/hooks/features/sql-graph.test.tsx

Fix these issues in Kilo Cloud

Previous review (commit 423558d)

Status: 6 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 3
SUGGESTION 3
Issue Details (click to expand)

WARNING

File Line Issue
plugins/altimate-code/hooks/dbt-command.ts 285 dbt invocations inside $(…)/backticks are folded into one word and silently dropped, so a future scan gate can be bypassed
plugins/altimate-code/hooks/features/sql-graph.test.tsx 211 SQL-limit test only matches the trailing notice; a render that keeps all 25,000 characters would still pass
plugins/altimate-code/hooks/features/sql-graph.test.tsx 144 Pane test names dependency order but asserts only key existence; rendering graph.nodes directly would pass

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/features/sql-graph.tsx 52 Package detection checks only the immediate parent folder name, so a non-default packages-install-path (e.g. vendor/) is treated as project models
plugins/altimate-code/hooks/features/sql-graph.test.tsx 262 The 'replaced' reply branch is unreachable in the test because the older ask already timed out at 2 s
plugins/altimate-code/hooks/features/sql-graph.test.tsx 196 Escaping test covers only the error message; node fields/SQL are not exercised and /u2028/ cannot match a raw U+2028
Files Reviewed (20 files)
  • plugins/altimate-code/.claude-plugin/plugin.json
  • plugins/altimate-code/hooks/altimate-cli.ts
  • plugins/altimate-code/hooks/dbt-command.test.ts
  • plugins/altimate-code/hooks/dbt-command.ts - 1 issue
  • plugins/altimate-code/hooks/features/comments.tsx
  • plugins/altimate-code/hooks/features/cost.tsx
  • plugins/altimate-code/hooks/features/cte-profile.tsx
  • plugins/altimate-code/hooks/features/defer.tsx
  • plugins/altimate-code/hooks/features/docs.tsx
  • plugins/altimate-code/hooks/features/health.tsx
  • plugins/altimate-code/hooks/features/index.ts
  • plugins/altimate-code/hooks/features/runs.tsx
  • plugins/altimate-code/hooks/features/sql-graph.test.tsx - 4 issues
  • plugins/altimate-code/hooks/features/sql-graph.tsx - 1 issue
  • plugins/altimate-code/hooks/features/to-model.tsx
  • plugins/altimate-code/hooks/integrations.tsx
  • plugins/altimate-code/hooks/lineage.tsx
  • plugins/altimate-code/hooks/status-line.ts
  • plugins/altimate-code/hooks/tool-chain.test.ts
  • plugins/altimate-code/hooks/tool-chain.ts

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash-1017 · Input: 39.4K · Output: 7.4K · Cached: 255.7K

…r any install path are not models, tests that prove the cut, the order, the replaced reply and the escaping

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
let quoted = false
for (let i = start; i < end; i++) {
const c = line[i]
if (quoted) quoted = c !== "'"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[WARNING]: An apostrophe inside a double-quoted word still hides a substitution

substitutionsIn toggles quoted on every ' and never tracks ". For echo "it's $(dbt run)" the apostrophe flips it into quoted state for the rest of the word, so $(dbt run) is skipped — but bash does substitute inside double quotes, so the run executes while parseDbtCommand does not report it (readSimple sees echo and it's $(dbt run), so the outer pass misses it too). That is the same fail-open for the scan gate and defer injection: track double-quoted state as well, and treat ' as a delimiter only outside " (and " only outside '). Test: expect(shape('echo "it\'s $(dbt run)"')).toEqual([run]) currently yields [].

…mands come in the order written, install paths are compared as paths from the project, outer projects are still asked

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
}
finish()
// An inner command (in a substitution) is listed where it is written, not before the command around it.
return found.sort((a, b) => a.start - b.start)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[SUGGESTION]: Sorting by start puts a command before a substitution written in its own leading assignment

start includes the invocation's leading VAR=x words, so for TARGET=$(dbt run-operation get_target) dbt run the outer invocation starts at 0 while the inner dbt run-operation starts at the $( — the sort lists the outer command first, although the substitution is both written and executed before it. That contradicts the "in the order written" contract this line adds; the pre-sort code got this case right by accident because the inner invocation was pushed before finish(). Sorting on the first word after the assignments (or leaving the inner/outer insertion order alone for assignment-only prefixes) keeps the contract. Test candidate: parseDbtCommand('T=$(dbt build) dbt test').map(i => i.subcommand) currently gives ['test', 'build'].

.join('/')
const here = inside.join('/')
// An enclosing project that does not hold this one among its packages leaves the outer ones to be asked.
if (own && !own.startsWith('/') && (here === own || here.startsWith(`${own}/`))) return true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[SUGGESTION]: The project-prefix strip is unanchored, and the !own.startsWith('/') guard can never fail

custom.replace(${dir}/, '') removes the first occurrence anywhere in the value, not only a leading one, so a relative packages-install-path that merely contains the project path is mangled: with the project at /repo and packages-install-path: vendor/repo/x, own becomes vendorx, and the nested-project check compares against the wrong folder. Separately, after .split('/').filter(part => part && part !== '.'), own can no longer start with /, so the guard that was meant to skip an absolute path outside this project is unreachable — such a value (say /opt/packages under a /repo project, giving own === 'opt/packages') is silently compared as if it were project-relative and can mark repo/opt/packages/... as an installed package. Anchor the strip on custom.startsWith(${dir}/), and skip the value when it is absolute and not under dir.

hkaltai and others added 3 commits November 15, 2026 22:30
…ect: anchored prefix, absolute paths outside the project match nothing

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e is not read as inside it

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… is compared

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
const relative = given.startsWith('/') ? (given.startsWith(from) ? given.slice(from.length) : null) : given
const kept: string[] = []
for (const part of relative === null ? [] : relative.split('/')) {
if (part === '..') kept.pop()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[SUGGESTION]: A .. that leaves the project is silently clamped to the project root

kept.pop() on an empty list is a no-op, so a packages-install-path that climbs above dir is read as a path inside it. With the project at /repo and packages-install-path: ../vendor, the real install folder is /vendor, but own becomes vendor, so a nested project at /repo/vendor/pkg matches here.startsWith('vendor/') and its models are dropped as a package's. The absolute branch has the same hole: /repo/../vendor is stripped to ../vendor and clamped identically. Count the .. steps and skip this project when the path leaves dir (its packages cannot be under it), or resolve .. before the absolute-prefix strip and compare the result with dir. Adding '../vendor' and `${ROOT}/../vendor` to the loop at line 135 would cover it, since the current cases never climb above the root.

@hkaltai

hkaltai commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

review-loop: APPROVED at b8ab823

Verify-only gate over the review-fix commits (33d997be … b8ab823b). Claude approved at this head. Codex's rounds found real gaps (double quotes in a substitution, install-path normalisation, .. in the path), each fixed with a test that fails without the fix. Its last finding, escaped nested backticks (\echo \`dbt run\``), is in the existing substitutionEnd/lex` code and is not caused by this change, so it is left as a follow-up.

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