Skip to content

feat: /to-model turns raw SQL into a dbt model - #32

Open
hkaltai wants to merge 6 commits into
mainfrom
feat/to-model
Open

hkaltai wants to merge 6 commits into
mainfrom
feat/to-model

Conversation

@hkaltai

@hkaltai hkaltai commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What

/to-model <name> [path] turns raw SQL into a dbt model. The SQL comes from the file, or from the person's selection when no path is given. The mod calls altimate-code's dbt_map_relations tool through runTool (straight to the CLI, whose --json carries the mapping), which matches each table to a ref() or source().

  • A Pane lists the tables with unmatched and partial rows on top.
  • One instruction goes to Claude: write models/<layer>/<name>.sql using exactly those replacements, and ask before adding sources for unmatched tables.
  • The instruction is sent right after the command's hook returns, because the host refuses prompt.submit from inside a command.run hook.
  • A CLI without the tool gets one line telling the person to upgrade. A bad model name, an unreadable or empty file, no SQL, a tool error, or a query with no tables each give a one-line reply and submit nothing.
  • ToModelState is filled in types/index.d.ts. Only hooks/features/to-model.tsx and its test use it.

Tests

claude plugin test ./plugins/altimate-code: 209 pass, including 7 new tests in hooks/features/to-model.test.tsx that cover the submitted prompt for a fixture mapping, the pane row order, the selection path, and each refusal. claude plugin validate --strict . passes, and all tests/*.sh pass. claude plugin validate --strict ./plugins/altimate-code still fails on four type warnings in hooks/lineage.test.tsx (not touched here); to-model.tsx has none.

Changelog lines

  • /to-model <name> [path]: turn raw SQL into a dbt model, with tables mapped to ref() and source().

Merge the altimate-code PR (AltimateAI/altimate-code#1737) first: this mod calls the installed CLI.

Demo

Demo video (hosted)

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

🤖 Generated with Claude Code

hkaltai and others added 6 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 Opus 5.5 <noreply@anthropic.com>
Maps each table of a file or selection to a ref() or source() call, shows the
unmatched and partial rows first in a pane, and asks Claude to write the model
with exactly those replacements.

Co-Authored-By: Claude Sonnet 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>
…roject's manifest, reports a missing CLI

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

hkaltai commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Review round: findings and what was done

Two independent reviewers (Claude and Codex) read this PR with the altimate-code PR; a fresh reviewer then attacked the fixes. Fixes are in 0207c75.

Fixed

  1. Prompt injection (Codex, MAJOR): SQL with a line of three backticks could close the prompt's fence and put text outside it, and a table name with a newline could start its own line. The fence is now longer than any backtick run in the SQL, table names are quoted on one line (line separators escaped), and the prompt says the SQL and names are data.
  2. No manifest for a project below the root (Claude, MAJOR 0.7): for a SQL file, the nearest dbt_project.yml above it (up to the session root, .. resolved first) gives manifest_path. Without a path the tool looks around the working directory.
  3. A failed runTool (no CLI, timeout) escaped the command (both, MINOR): now a one-line reply; a missing CLI says to install it.
  4. The "needs a newer altimate-code" reply matched "not found" in any error (Claude, MINOR): it now needs "unknown tool", which the CLI prints for an unknown tool (tool-cli/runner.ts:69).
  5. An answer the plugin cannot read (for example a new match kind) gave a confusing message (Claude, MINOR): it now says to update the plugin and altimate-code to matching versions.
  6. Duplicate pane keys when two rows have the same text; the dialect was stored but never shown; the match union was written twice.
  7. Tests added: subfolder project, prompt breakout, missing CLI, "not found" error, unreadable answer, pane for case_insensitive and extra candidates, the empty pane, state cleared at session start.

Not changed

  • The command waits for the tool, where /lineage caps its wait (Claude, MINOR 0.6): this command's reply is the mapping; one manifest read.
  • ~/q.sql is not expanded (NIT): no verified home-directory API.
  • target/manifest.json is fixed: it is the tool's own default as well.
  • README and CHANGELOG entries are not files this package owns; the changelog line is in the description.
  • claude plugin validate --strict ./plugins/altimate-code still reports warnings in dbt-command.ts and lineage.test.tsx, neither touched here; to-model.tsx has none.

Tests: claude plugin test ./plugins/altimate-code 224 pass, tests/*.sh pass.

🤖 Generated with Claude Code

@hkaltai
hkaltai marked this pull request as ready for review November 13, 2026 17:39
@kilo-code-bot

kilo-code-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

Kilo Code Review could not run — your account is out of credits.

Add credits or switch to a free model to enable reviews on this change.

@hkaltai

hkaltai commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

review-loop: APPROVED at 0207c75

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