Skip to content

Query input parsing#11

Merged
gblikas merged 18 commits intomainfrom
cursor/query-input-parsing-19cf
Feb 2, 2026
Merged

Query input parsing#11
gblikas merged 18 commits intomainfrom
cursor/query-input-parsing-19cf

Conversation

@gblikas
Copy link
Copy Markdown
Owner

@gblikas gblikas commented Feb 1, 2026

Add a new input parser module to enable real-time parsing of partial search queries for UI/UX features like highlighting and autocomplete.


Open in Cursor Open in Web

…search input

This adds a new input-parser module that allows developers to parse
incomplete/in-progress query input from search bars and extract structured
information like:
- Key and value being typed
- Operator being used
- Cursor position context
- Position information for highlighting

Main exports:
- parseQueryInput: Parse input and get full context
- extractKeyValue: Simple key/value extraction
- getTermAtPosition: Get term at cursor position
- isInputComplete: Check if input is complete

This enables UX features like:
- Key-value highlighting in search inputs
- Autocomplete suggestions based on context
- Real-time validation feedback
@cursor
Copy link
Copy Markdown

cursor Bot commented Feb 1, 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

@cursor
Copy link
Copy Markdown

cursor Bot commented Feb 1, 2026

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on March 18.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Feb 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
querykit Ready Ready Preview, Comment Feb 2, 2026 11:11pm

Adds comprehensive tests that document the known differences between:
- QueryParser (Liqe-based, for execution)
- parseQueryInput (regex-based, for UI)

Key divergences documented:
1. Logical keywords as values: Main parser REJECTS status:AND/OR/NOT,
   input parser correctly handles them (workaround: quote the value)
2. Incomplete input: Main parser rejects, input parser returns partial
3. Quote handling: Main strips quotes, input preserves them
4. Type conversion: Main converts to proper types, input keeps strings
5. Complex syntax: Main fully handles ranges/arrays, input has limits

This helps developers understand when to use each parser.
…ence

Adds a new function parseQueryTokens() that returns an interleaved
sequence of terms and operators, making it easier to:
- Render query tokens as UI chips/tags
- Build visual query builders
- Implement proper syntax highlighting

Example:
  parseQueryTokens('status:done AND priority:high')
  // Returns:
  // [
  //   { type: 'term', key: 'status', value: 'done', ... },
  //   { type: 'operator', operator: 'AND', ... },
  //   { type: 'term', key: 'priority', value: 'high', ... }
  // ]

New exports:
- parseQueryTokens: Parse input into token sequence
- IQueryTermToken: Term token type
- IQueryOperatorToken: Operator token type
- QueryToken: Union type for both
- IQueryTokenSequence: Result type with tokens + active token info
…ural analysis

Adds parseWithContext() method to QueryParser that provides:
- Success/failure indication (never throws)
- Full AST on success, error info on failure
- Token sequence (always available, even on failure)
- Cursor-aware active token detection
- Structural analysis:
  - Query depth (parenthesis nesting)
  - Clause count
  - Operator count
  - Balanced parentheses/quotes check
  - Referenced fields list
  - Complexity classification (simple/moderate/complex)
  - Completeness check

This enables building rich search UIs with:
- Real-time validation feedback
- Query complexity indicators
- Field extraction for autocomplete
- Error context for user feedback

Phase 1 of parseWithContext implementation.
Phases 2-3 will add: schema validation, security pre-check,
autocomplete hints, and error recovery suggestions.
…d input parser

Adds 32 tests verifying that parseWithContext returns identical token
information as the standalone input parser (parseQueryTokens/parseQueryInput):

- Token count consistency across various inputs
- Token content consistency (type, key, value, operator)
- Position consistency (startPosition, endPosition, raw)
- Cursor/active token consistency
- Edge case handling (empty, incomplete, invalid input)
- Structure field consistency

This ensures the integration between the two parsing approaches is correct
and developers can rely on consistent behavior regardless of which API they use.
…thContext (Phase 2)

Extends parseWithContext with Phase 2 features:

## Schema Validation (when schema option provided)
- Validates referenced fields against provided schema
- Reports unknown fields with 'unknown_field' reason
- Provides typo suggestions using:
  - Case-insensitive matching
  - Prefix matching
  - Levenshtein distance (for short field names)
- Includes allowed values from schema for enum fields

## Security Pre-check (when securityOptions provided)
- Checks denied fields
- Checks allowed fields whitelist
- Validates dot notation usage
- Checks query depth limits (with warnings at 80%)
- Checks clause count limits (with warnings at 80%)
- Warns about complex queries

New types:
- IFieldSchema: Schema definition for fields
- IFieldValidationResult: Field validation results
- ISecurityCheckResult: Security check results
- ISecurityViolation: Security violation details
- ISecurityWarning: Security warnings

28 new tests for Phase 2 features.
This phase completes the parseWithContext enhancement with:

Autocomplete Suggestions:
- Context-aware suggestions based on cursor position
- Field suggestions with fuzzy matching (prefix, contains, Levenshtein)
- Value suggestions for fields with allowedValues in schema
- Boolean value suggestions for boolean fields
- Operator suggestions with applicability hints for field types
- Logical operator suggestions (AND, OR, NOT) between terms
- Replace text and range info for easy insertion

Error Recovery:
- Unclosed quote detection with auto-fix
- Unclosed parenthesis detection with auto-fix
- Trailing operator detection with auto-fix
- Missing value detection
- Generic syntax error fallback
- Position tracking for errors

New types:
- IAutocompleteSuggestions
- IFieldSuggestion
- IValueSuggestion
- IOperatorSuggestion
- IErrorRecovery

Includes 30 new tests for Phase 3 features.
README.md:
- Add section on Input Parsing for Search UIs
- Document parseQueryInput and parseQueryTokens for real-time parsing
- Document parseWithContext with schema validation and autocomplete
- Document error recovery with autofix suggestions
- Add React search bar example with highlighting
- Update roadmap to reflect completed features

BUGBOT.md:
- Add query parsing security guidelines
- Document two-tier parser architecture
- Add common issues for parser usage
- Add testing guidelines for parser features

Example app (qk-next):
- Replace simple regex highlighter with parseQueryTokens-based implementation
- Provides accurate tokenization for key:value highlighting
- Supports comparison operators, logical operators, quoted values
- Highlights keys (orange), operators (gray), values (blue), logical ops (purple)
- Update @gblikas/querykit dependency to use workspace:* for local linking
- Add pnpm-workspace.yaml to set up workspace packages
- Fix highlightQueryHtml to detect negation from key prefix instead of isNegated property
- Remove deprecated swcMinify option from next.config.ts
- Remove duplicate pnpm-lock.yaml in example folder

The example app now builds successfully and uses the local querykit package.
- Change @gblikas/querykit dependency from workspace:* to file:../..
- Add vercel.json to configure proper build commands:
  - Install from root to get all workspace dependencies
  - Build root package first, then example app

The workspace:* protocol doesn't work on Vercel as it expects npm packages.
The file: protocol allows Vercel to resolve the local package properly.
- Move vercel.json from examples/qk-next to repository root
- Add packageManager field to root package.json for Vercel detection
- Add build:example script to build both packages in sequence
- Update vercel.json to use pnpm run build:example

This configuration requires Vercel project root directory to be set to '/'
(the repository root) rather than the example folder.
Vercel runs commands from the detected project directory, not the repo root.
Using pnpm -w flag ensures commands run from the workspace root.
Next.js needs to transpile the local querykit package to resolve exports
properly, especially when using file: protocol for workspace linking.
Modern bundlers like Next.js require explicit exports declarations
for proper module resolution, especially when using file: protocol.

Added:
- exports field with proper types/import/require/default conditions
- module field pointing to dist/index.js
- Subpath exports for parser, adapters, and translators
@gblikas gblikas marked this pull request as ready for review February 2, 2026 23:00
Copy link
Copy Markdown
Owner Author

@gblikas gblikas left a comment

Choose a reason for hiding this comment

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

Pending QA.

@gblikas gblikas merged commit a6b04e8 into main Feb 2, 2026
6 checks passed
@gblikas gblikas deleted the cursor/query-input-parsing-19cf branch February 2, 2026 23:11
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.

2 participants