Skip to content

Query history in context#439

Draft
Bl3f wants to merge 1 commit intomainfrom
cursor/custom-user-data-directory-8370
Draft

Query history in context#439
Bl3f wants to merge 1 commit intomainfrom
cursor/custom-user-data-directory-8370

Conversation

@Bl3f
Copy link
Contributor

@Bl3f Bl3f commented Mar 12, 2026

fix #228

Implements query history for the agent context and renames accessor to template.

The addition of query history allows the how_to_use template to generate documentation based on actual table usage, including common joins and frequently run queries, making the generated context more practical and helpful for users. The accessor to template rename improves consistency and clarity across the codebase.

Open in Web Open in Cursor 

…gents

Implements #228 - Add queries history in agent context.

Changes:
- Rename 'accessor' to 'template' in config (backward-compatible via
  model_validator that migrates legacy 'accessors' YAML key)
- Add DatabaseTemplate.HOW_TO_USE enum value
- Add query_history_days config field on DatabaseConfig
- Add get_query_history_sql() to DatabaseConfig with overrides for
  BigQuery, Snowflake, Databricks, Postgres, and Redshift
- Implement query history extraction pipeline (query_history.py):
  - Extract table references from FROM/JOIN via sqlglot with regex fallback
  - Compute per-table usage stats: usage count, common joins, top queries
- Add how_to_use.md.j2 template rendering per-table usage context
- Integrate query history into database sync flow: fetch history once
  per database, compute stats across all selected tables, pass to template
- Add sqlglot dependency
- Add 17 new tests for query history module + 2 config backward compat tests

Co-authored-by: Christophe Blefari <christophe.blefari@gmail.com>
@cursor
Copy link

cursor bot commented Mar 12, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@Bl3f Bl3f changed the title Custom user data directory Query history in context Mar 12, 2026
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.

Add queries history in agent context

2 participants