Skip to content

Conversation

@yujonglee
Copy link
Contributor

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented Jul 9, 2025

📝 Walkthrough

Walkthrough

This change refactors grammar handling across the codebase by replacing static grammar files and string-based selection with a new serializable Grammar enum. Grammar construction is now dynamic and parameterized, with section data passed via structured objects instead of generated strings. Template and enhancement logic is updated to use the new approach.

Changes

Files/Groups Change Summary
apps/desktop/src/components/editor-area/index.tsx Refactored template and grammar handling: removed dynamic grammar string generation, now passes structured Grammar objects.
crates/gbnf/assets/enhance-hypr.gbnf,
crates/gbnf/assets/enhance-other.gbnf,
crates/gbnf/assets/tags.gbnf,
crates/gbnf/assets/title.gbnf
Deleted all static grammar definition files.
crates/gbnf/Cargo.toml Added serde and specta dependencies with "derive" features.
crates/gbnf/src/lib.rs Replaced static grammar string constants and GBNF enum with serializable Grammar enum and dynamic grammar generation. Updated tests.
crates/llama/src/lib.rs Updated test to use new Grammar enum for grammar construction.
plugins/local-llm/src/server.rs Removed select_grammar function; now deserializes Grammar from request metadata and builds grammar dynamically.
plugins/template/Cargo.toml Added dependency on hypr-gbnf.
plugins/template/js/bindings.gen.ts Added exported TypeScript type alias Grammar matching the new Rust enum structure.
plugins/template/src/lib.rs Registered hypr_gbnf::Grammar with tauri_specta builder for type recognition.

Sequence Diagram(s)

sequenceDiagram
    participant UI as Editor UI
    participant Desktop as Desktop App
    participant Template as Template Plugin
    participant LLM as Local LLM Provider

    UI->>Desktop: Trigger Enhance Mutation
    Desktop->>Template: Fetch Template (with ID)
    Template-->>Desktop: Return Template Object
    Desktop->>LLM: streamText({ grammar: Grammar { task: "enhance", sections } })
    LLM->>Desktop: Generate Enhanced Content (using built grammar)
    Desktop-->>UI: Display Enhanced Content
Loading

Possibly related PRs

  • fastrepl/hyprnote#1111: Refactors template selection and enhancement logic in the same component, closely related to changes in grammar and template handling.
  • fastrepl/hyprnote#1050: Introduces the dynamic custom grammar generation that this PR now removes and replaces with structured Grammar objects.
  • fastrepl/hyprnote#1094: Adds static grammar files and enum variants that are now replaced by the new dynamic, serializable Grammar enum in this PR.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Clippy (1.86.0)
Updating git repository `https://github.com/RustAudio/cpal`

error: failed to load source for dependency cpal

Caused by:
Unable to update https://github.com/RustAudio/cpal?rev=51c3b43#51c3b43c

Caused by:
failed to create directory /usr/local/git/db/cpal-476cd1dd23dbc279

Caused by:
Permission denied (os error 13)


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 35ee5e8 and 08e1f57.

📒 Files selected for processing (2)
  • apps/desktop/src/components/editor-area/index.tsx (4 hunks)
  • crates/gbnf/src/lib.rs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/desktop/src/components/editor-area/index.tsx
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{js,ts,tsx,rs}`: 1. No error handling. 2. No unused imports, variables, or functions. 3. For comments, keep it minimal. It should be about "Why", not "What".

**/*.{js,ts,tsx,rs}: 1. No error handling.
2. No unused imports, variables, or functions.
3. For comments, keep it minimal. It should be about "Why", not "What".

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • crates/gbnf/src/lib.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: ci (windows, windows-latest)
  • GitHub Check: ci (macos, macos-latest)
  • GitHub Check: ci
🔇 Additional comments (8)
crates/gbnf/src/lib.rs (8)

1-10: Well-structured enum with proper serde configuration.

The Grammar enum is well-designed with appropriate serde annotations for serialization. The tagged union with #[serde(tag = "task")] provides clear discrimination between variants.


12-20: Clean implementation with proper variant matching.

The build method correctly delegates to specialized builder functions for each grammar variant, maintaining good separation of concerns.


33-57: Efficient dynamic grammar construction.

The function correctly builds grammar rules dynamically based on section names, with proper indexing and rule formatting.


59-79: Smart fallback logic for grammar selection.

The function provides good fallback behavior: uses auto-generated grammar when sections are None or empty, otherwise builds from known sections.


81-89: Correct title grammar implementation.

The grammar properly enforces title case formatting with uppercase first letters followed by lowercase characters.


91-98: Proper tags grammar with JSON array format.

The grammar correctly validates JSON array format for tags with proper escaping and whitespace handling.


119-119: Test correctly updated for new builder function.

The test properly calls the new build_title_grammar() function instead of a static constant.


132-132: Test correctly updated for new builder function.

The test properly calls the new build_tags_grammar() function instead of a static constant.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
crates/gbnf/src/lib.rs (1)

175-177: Remove or fix the commented test assertion.

The test has a commented assertion that should either be removed or fixed.

 let _gbnf = gbnf_validator::Validator::new().unwrap();
-// assert!(gbnf.validate(ENHANCE_AUTO, input_1).unwrap());

If the test is needed, update it to use the new grammar system:

-let _gbnf = gbnf_validator::Validator::new().unwrap();
-// assert!(gbnf.validate(ENHANCE_AUTO, input_1).unwrap());
+let gbnf = gbnf_validator::Validator::new().unwrap();
+let grammar = Grammar::Enhance { sections: None };
+assert!(gbnf.validate(&grammar.build(), input_1).unwrap());
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 188d000 and 35ee5e8.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • apps/desktop/src/components/editor-area/index.tsx (4 hunks)
  • crates/gbnf/Cargo.toml (1 hunks)
  • crates/gbnf/assets/enhance-hypr.gbnf (0 hunks)
  • crates/gbnf/assets/enhance-other.gbnf (0 hunks)
  • crates/gbnf/assets/tags.gbnf (0 hunks)
  • crates/gbnf/assets/title.gbnf (0 hunks)
  • crates/gbnf/src/lib.rs (3 hunks)
  • crates/llama/src/lib.rs (1 hunks)
  • plugins/local-llm/src/server.rs (1 hunks)
  • plugins/template/Cargo.toml (1 hunks)
  • plugins/template/js/bindings.gen.ts (1 hunks)
  • plugins/template/src/lib.rs (1 hunks)
💤 Files with no reviewable changes (4)
  • crates/gbnf/assets/tags.gbnf
  • crates/gbnf/assets/title.gbnf
  • crates/gbnf/assets/enhance-hypr.gbnf
  • crates/gbnf/assets/enhance-other.gbnf
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{js,ts,tsx,rs}`: 1. No error handling. 2. No unused imports, variables, or functions. 3. For comments, keep it minimal. It should be about "Why", not "What".

**/*.{js,ts,tsx,rs}: 1. No error handling.
2. No unused imports, variables, or functions.
3. For comments, keep it minimal. It should be about "Why", not "What".

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • plugins/template/src/lib.rs
  • plugins/template/js/bindings.gen.ts
  • plugins/local-llm/src/server.rs
  • crates/llama/src/lib.rs
  • apps/desktop/src/components/editor-area/index.tsx
  • crates/gbnf/src/lib.rs
🧬 Code Graph Analysis (4)
plugins/template/src/lib.rs (1)
plugins/template/js/bindings.gen.ts (1)
  • Grammar (28-28)
plugins/local-llm/src/server.rs (1)
plugins/template/js/bindings.gen.ts (1)
  • Grammar (28-28)
crates/llama/src/lib.rs (1)
plugins/template/js/bindings.gen.ts (1)
  • Grammar (28-28)
apps/desktop/src/components/editor-area/index.tsx (1)
plugins/template/js/bindings.gen.ts (1)
  • Grammar (28-28)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: ci (windows, windows-latest)
  • GitHub Check: ci (macos, macos-latest)
  • GitHub Check: ci
🔇 Additional comments (7)
crates/gbnf/Cargo.toml (1)

6-8: LGTM! Dependencies correctly added for Grammar enum serialization.

The serde and specta dependencies with derive features are properly configured to support the new serializable Grammar enum functionality.

plugins/template/Cargo.toml (1)

18-18: LGTM! Dependency correctly added for Grammar enum integration.

The hypr-gbnf dependency enables the template plugin to use the new Grammar types, aligning with the refactoring objectives.

plugins/template/src/lib.rs (1)

32-32: LGTM! Grammar type properly registered for TypeScript bindings.

The .typ::<hypr_gbnf::Grammar>() registration enables tauri-specta to generate the corresponding TypeScript types, ensuring type safety across the Rust-TypeScript boundary.

crates/llama/src/lib.rs (1)

394-394: LGTM! Grammar construction correctly updated to new API.

The change from hypr_gbnf::GBNF::EnhanceOther.build() to hypr_gbnf::Grammar::Enhance { sections: None }.build() properly reflects the refactoring to the new parameterized Grammar enum.

plugins/template/js/bindings.gen.ts (1)

28-28: LGTM! TypeScript Grammar type correctly mirrors Rust enum structure.

The discriminated union properly represents the three grammar variants with appropriate typing for the sections field in the enhance variant.

apps/desktop/src/components/editor-area/index.tsx (2)

285-297: Clean refactoring of template retrieval logic.

The extraction of template retrieval into the getTemplate function improves readability and maintains consistent null handling.


358-362: Proper type-safe grammar metadata implementation.

The use of the Grammar type with satisfies ensures type safety while maintaining the correct structure for the enhance task.

@yujonglee yujonglee merged commit ed15aeb into main Jul 9, 2025
6 checks passed
@yujonglee yujonglee deleted the gbnf-template-rs branch July 9, 2025 20:31
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