Skip to content

refactor: Use state.db.tables for assistant and run context - #732

Merged
ilyabo merged 1 commit into
mainfrom
deprecate-getAllTablesFromSchemaTrees
Jun 19, 2026
Merged

ilyabo merged 1 commit into
mainfrom
deprecate-getAllTablesFromSchemaTrees

Conversation

@ilyabo

@ilyabo ilyabo commented Jun 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Switch assistant context, run-context formatting, and CLI sidebar data surfaces to read from state.db.tables
  • Use each table’s qualified toString() identifier consistently for selection and lookup
  • Mark getAllTablesFromSchemaTrees as deprecated in duckdb-core

Testing

  • Not run (not requested)

Summary by CodeRabbit

  • Refactor
    • Optimized table data access patterns for improved consistency and performance.
    • Enhanced internal data retrieval and table selection handling.
    • Updated table context management for better maintainability.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Across four files in the CLI UI app, table lists previously derived from schemaTrees via getAllTablesFromSchemaTrees/makeQualifiedTableName are replaced by direct reads of state.db.tables as DataTable[], with table.table.toString() used as the canonical table ID everywhere. getAllTablesFromSchemaTrees is marked @deprecated in the duckdb-core package.

Changes

db.tables Migration

Layer / File(s) Summary
Sidebar table listing migrated to DataTable
apps/sqlrooms-cli-ui/src/workspace/sidebar/CliDataSidebarSection.tsx
Reads tables directly from the room store as DataTable[], removes useMemo/schemaTrees derivation, updates the select callback to table.table.toString(), changes the displayed label to table.table.table, and updates formatTableMeta's parameter type.
useAssistantContextItems hook migrated to DataTable
apps/sqlrooms-cli-ui/src/components/useAssistantContextItems.ts
useContextTables return type changes to DataTable[] via s.db.tables; selector item IDs and the useValidatedSelectedIds validation set both switch from makeQualifiedTableName to table.table.toString().
Run context builders and deprecation
apps/sqlrooms-cli-ui/src/context/getRunContext.ts, apps/sqlrooms-cli-ui/src/context/formatRunContextInstructions.ts, packages/duckdb-core/src/schema-tree/schemaTreeUtils.ts
buildTablesMap accepts DataTable[] | undefined; getRunContext passes db.tables instead of schemaTrees; formatTableContextInstructions calls state.db.findTable(item.id) in place of findTableInSchemaTrees; getAllTablesFromSchemaTrees is annotated @deprecated.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • sqlrooms/sqlrooms#664: Introduced table context support in useAssistantContextItems.ts using schemaTrees; this PR replaces that approach with db.tables.
  • sqlrooms/sqlrooms#671: Aligned DataTable.table.toString() as the canonical table identifier in a different slice; the same ID format is adopted here across UI context selectors.
  • sqlrooms/sqlrooms#707: Modified the AI run-context path in getRunContext.ts and useAssistantContextItems.ts, directly overlapping with this PR's changes to context ID building and validation.

Suggested reviewers

  • dmitriy-kostianetskiy

Poem

🐇 Hop, hop, no more tree to climb,
schemaTrees left behind in time.
db.tables now leads the way,
toString() brightens every day.
Less code to carry, lighter pack—
this bunny's never looking back! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately describes the main refactoring objective: migrating from schemaTrees to state.db.tables across assistant and run context modules.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch deprecate-getAllTablesFromSchemaTrees

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ilyabo ilyabo changed the title Use state.db.tables for assistant and run context fix: Use state.db.tables for assistant and run context Jun 19, 2026
@ilyabo ilyabo changed the title fix: Use state.db.tables for assistant and run context refactor: Use state.db.tables for assistant and run context Jun 19, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/duckdb-core/src/schema-tree/schemaTreeUtils.ts (1)

7-7: ⚡ Quick win

Make the deprecation message package-agnostic.

state.db.tables is an app-store implementation detail; documenting it in a packages/ public utility couples this API to one consumer architecture. Reword the deprecation guidance to a generic source of table metadata.

Suggested wording
- * `@deprecated` Use state.db.tables
+ * `@deprecated` Prefer consuming tables from your host application's table catalog/state (for example, a `db.tables` collection) instead of traversing schema trees.

As per coding guidelines, "Treat public exports in packages/ as library APIs: keep them generic, composable, documented, and free of app/example-specific assumptions."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/duckdb-core/src/schema-tree/schemaTreeUtils.ts` at line 7, The
deprecation message at line 7 in schemaTreeUtils.ts references
"state.db.tables", which is an app-store specific implementation detail that
couples this public utility API to a particular consumer architecture. Update
the `@deprecated` comment to provide generic guidance that is package-agnostic,
such as directing users to a generic source of table metadata instead of a
specific application implementation. This ensures the deprecation guidance
remains composable and free of app-specific assumptions, consistent with library
API best practices for packages/.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/duckdb-core/src/schema-tree/schemaTreeUtils.ts`:
- Line 7: The deprecation message at line 7 in schemaTreeUtils.ts references
"state.db.tables", which is an app-store specific implementation detail that
couples this public utility API to a particular consumer architecture. Update
the `@deprecated` comment to provide generic guidance that is package-agnostic,
such as directing users to a generic source of table metadata instead of a
specific application implementation. This ensures the deprecation guidance
remains composable and free of app-specific assumptions, consistent with library
API best practices for packages/.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cc8551a1-ac7a-40bf-96df-0c3fb451bdd4

📥 Commits

Reviewing files that changed from the base of the PR and between 2330b43 and 712280d.

📒 Files selected for processing (5)
  • apps/sqlrooms-cli-ui/src/components/useAssistantContextItems.ts
  • apps/sqlrooms-cli-ui/src/context/formatRunContextInstructions.ts
  • apps/sqlrooms-cli-ui/src/context/getRunContext.ts
  • apps/sqlrooms-cli-ui/src/workspace/sidebar/CliDataSidebarSection.tsx
  • packages/duckdb-core/src/schema-tree/schemaTreeUtils.ts

@ilyabo
ilyabo merged commit da52b6c into main Jun 19, 2026
5 of 6 checks passed
@ilyabo
ilyabo deleted the deprecate-getAllTablesFromSchemaTrees branch June 19, 2026 08:55
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