feat: dbt_defer_state tool — Power User defer setting and profile target

HK
1d ago
+1062-2

Type of change

  • New feature

What does this PR do?

Implements the dbt_defer_state tool (package P-04, altimate-code half). Given a dbt project folder it reads dbt.deferConfigPerProject from .vscode/settings.json (comments and trailing commas allowed), finds the entry keyed by the project's path relative to its workspace folder, and returns { enabled, favorState, mode, stateDir, reason, defaultTarget, targets }.

  • Local mode: manifestPathForDeferral (with ${workspaceFolder} (the dbt project's folder, as Power User does) and ${env:NAME} expanded, relative paths resolved against the project) is returned as stateDir only when it is a directory holding a manifest.json file; otherwise reason says why.
  • Remote mode: reported as mode: remote with enabled: false and a clear reason. The request shape of dbt/v1/fetch_artifact_url could not be verified, so no download is attempted and api/fetch-artifact-url.ts is not added.
  • The profile's default target and its output names come from profiles.yml (DBT_PROFILES_DIR, the project folder, then ~/.dbt).
  • Read-only.

This branch includes the foundation commits (dbt Power User tool foundation); retarget/rebase once that PR merges. The plugin half is in the altimate-claude-plugin PR for feat/defer-target, which should merge after this one.

How did you verify your code works?

  • bun test test/altimate/dbt-defer-state.test.ts: 18 tests pass (local mode, defer off, no entry, root project key, non-directory state path, manifest.json that is a directory, project-folder expansion, unreadable settings end the search, remote reported unsupported, missing settings/profiles, comments and trailing commas).
  • Demo video (real CLI build plus a Claude session with the plugin): /Users/harish/.quikim/artifacts/pu-mods/videos/P-04.mp4 (local file; not uploaded).
  • bun typecheck passes.

Follow-ups (not in this PR)

  • env_var("X", "y") with double quotes is not resolved by the shared profile resolver (native/connections/dbt-profiles.ts), so a profile name or target written that way is returned unresolved.
  • The reported default target does not reflect an exported DBT_TARGET.

Cost side effects

None. The tool only reads local files; it adds no model calls, warehouse queries or cloud resources.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
  • I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"

Changelog

  • Added dbt_defer_state: reads the dbt Power User defer-to-production setting and the profile's default target for a dbt project.

🤖 Generated with Claude Code


Summary by cubic

Adds the dbt_defer_state tool, which reads the dbt Power User defer setting from .vscode/settings.json and reports whether defer is on, the state directory, and the profile's default target, along with the foundation the other dbt Power User tools build on.

  • Local mode returns the configured state directory even while defer is off, so a session can switch it on; the directory must hold a manifest.json, and ${workspaceFolder} is the project folder itself. An empty or whitespace-only settings file is treated as empty, and project and workspace paths are matched as written before their symlink-resolved forms. Remote mode, unknown manifest types, and non-directory paths are reported with reasons instead; a settings file that cannot be read or parsed ends the search, and env_var() in the profile, target, and state path is resolved.
  • Adds dbtAdapterFor, the gate every adapter-backed tool goes through: it refuses read-only calls, plan mode, sessions in other projects, and adapters that failed to start.
  • Adds AltimateApi.apiRequest for endpoint files to call the backend with the stored credentials.
  • Exposes nine dbt tool stubs; the eight beyond dbt_defer_state return "not implemented" placeholders.
  • dbt_defer_state is read-only; it adds no API calls, warehouse queries, or cloud resources.

Summary by CodeRabbit

  • New Features
    • Added dbt tools for checking defer state and accessing dbt capabilities, including project health, run results, SQL graphs, and documentation coverage.
    • Added API requests using saved credentials; missing or unusable credentials now produce actionable errors.
  • Limitations
    • Several newly available dbt tools currently return a message that they are not implemented in this build.