Skip to content

feat: Add natural language command system#9

Merged
devonjones merged 4 commits intomainfrom
feat/command-system
Jan 15, 2026
Merged

feat: Add natural language command system#9
devonjones merged 4 commits intomainfrom
feat/command-system

Conversation

@devonjones
Copy link
Copy Markdown
Owner

Summary

Implements natural language command parsing and execution, allowing users to interact with their knowledge base using commands like:

  • "move that idea to projects"
  • "tag the last note with 'urgent'"
  • "archive that inbox item"
  • "show the last entry"

This completes both the command parser (cortex-q0ca) and command execution (cortex-pz1e) tickets.

Architecture

Command Parser (src/reflex/services/commands.py)

  • CommandParser class uses LLM (Tier 2 model for accuracy)
  • JSON schema-based prompt for structured extraction
  • ParsedCommand dataclass: action, target, keywords, parameters
  • Handles malformed responses gracefully

Command Execution Flow

  1. Intent validation - existing LLM cascade confirms it's a command
  2. Parse - extract structured data (action, target, parameters)
  3. Resolve target - find entry by recency + keyword matching
  4. Execute - perform action (move/tag/archive/show)
  5. Confirm - reply with success/error message

Target Resolution Strategy

  • Query last 10 entries from channel
  • Filter by keywords if provided (matches title or category)
  • Return most recent match
  • Clear error if no match found

Supported Actions

Action Description Parameters
move Change category new_category (person, project, idea, admin, inbox)
tag Add tags (avoids duplicates) tags (list of strings)
archive Set status=archived none
show Display entry details none

All actions:

  • Update database
  • Re-export markdown (reflects changes in frontmatter)
  • Send confirmation to Discord

Examples

Input: "move that idea about Foo into my projects"
Output: ✅ Moved entry from idea to project

Input: "tag the last note with 'urgent'"
Output: ✅ Added tags: urgent

Input: "archive that inbox item"
Output: ✅ Archived entry

Input: "show the last entry"
Output: Entry details (category, tags, status, captured date, ID)

Error Handling

  • Parse failure: "Sorry, I couldn't understand that command."
  • Target not found: "I couldn't find the entry you're referring to. Try being more specific..."
  • Invalid category: Lists valid categories
  • Missing parameters: Clear error about what's missing

Test Plan

  • Type checking passes (mypy)
  • Tests pass (pytest)
  • Deploy and test commands manually
  • Test target resolution with keywords
  • Test all actions (move/tag/archive/show)
  • Test error cases (not found, invalid params)

Future Enhancements

  • Support for "all" target ("archive all inbox items")
  • Undo command
  • Batch operations
  • More sophisticated target resolution (fuzzy matching, date ranges)

Resolves

Closes cortex-q0ca (Natural language command parser)
Closes cortex-pz1e (Command execution)

🤖 Generated with Claude Code

Implements command parser and execution for natural language commands
like "move that idea to projects", "tag the last note with 'urgent'",
and "archive that inbox item".

Changes:

**CommandParser** (`src/reflex/services/commands.py`):
- New module for parsing natural language commands
- Uses LLM (Tier 2 model) to extract structured data from commands
- ParsedCommand dataclass: action, target, keywords, parameters
- JSON schema-based prompt for reliable parsing

**ReflexBot** (`src/reflex/services/bot.py`):
- Initialize CommandParser in __init__
- execute_command() - main command execution flow
- resolve_target() - find entry by recency + keywords
- execute_move() - change entry category
- execute_tag() - add tags to entry
- execute_archive() - set status=archived
- execute_show() - display entry details
- All actions update DB + re-export markdown

**Target Resolution**:
- Query last 10 entries from channel
- Filter by keywords if provided (title/category matching)
- Return most recent match

**Confirmation Messages**:
- Clear success/error feedback
- Show affected entry title
- Specific error messages (not found, invalid category, etc.)

Resolves: cortex-q0ca, cortex-pz1e

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @devonjones, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances user interaction with the knowledge base by introducing a natural language command system. This system allows users to manage their entries more intuitively through conversational commands, streamlining common tasks like organizing, categorizing, and retrieving information. The integration of an advanced LLM for command parsing and a structured execution flow aims to improve efficiency and user experience by making the system more accessible and responsive to natural language input.

Highlights

  • Natural Language Command System: Introduces a comprehensive natural language command system, enabling users to interact with their knowledge base using intuitive commands like "move that idea to projects" or "tag the last note with 'urgent'".
  • LLM-Powered Parsing: Implements an LLM (Tier 2 model)-based CommandParser to accurately interpret natural language commands into a structured format, ensuring robust and flexible command understanding.
  • Command Execution: Adds functionality to execute parsed commands, supporting actions such as 'move' (change category), 'tag' (add tags), 'archive' (set status), and 'show' (display details) on knowledge base entries.
  • Intelligent Target Resolution: Incorporates a strategy to resolve the target entry for commands by querying recent entries and filtering them using keywords provided in the natural language command.
  • Robust Error Handling: Includes comprehensive error handling for scenarios like parse failures, target not found, invalid parameters, and unknown actions, providing clear feedback to the user.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a natural language command system, which is a great new feature. The implementation is solid, with a clear separation between parsing and execution. I've identified a few areas for improvement, primarily focusing on robustness, maintainability, and adherence to asynchronous programming best practices. My main points include a logical bug in how command targets are resolved, suggestions to make the command parser more robust and async-native, and a few refactoring opportunities to improve code structure and maintainability. Addressing these points will make the new command system more reliable and easier to extend in the future.

Comment thread src/reflex/services/bot.py
Comment thread src/reflex/services/commands.py Outdated
Comment thread src/reflex/services/commands.py
Comment thread src/reflex/services/bot.py
Comment thread src/reflex/services/bot.py Outdated
Comment thread src/reflex/services/commands.py
…ON prompt

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@devonjones
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a natural language command system, which is a significant feature. The implementation is well-structured, with a clear separation between parsing (CommandParser) and execution (ReflexBot). The use of an LLM for parsing with a JSON schema is a solid approach.

My review focuses on improving robustness, maintainability, and adherence to async best practices. Key suggestions include:

  • Refactoring the synchronous CommandParser to be fully asynchronous using httpx.AsyncClient.
  • Improving data modeling by using frozenset for constant collections, Literal types for specific string values, and suggesting Enum for statuses to avoid magic strings.
  • Enhancing code clarity with list comprehensions and making the JSON extraction from LLM responses more robust with regular expressions.

Overall, this is a great addition. Addressing these points will make the new command system more efficient and easier to maintain.

Comment thread src/reflex/services/commands.py
Comment thread src/reflex/services/bot.py
Comment thread src/reflex/services/bot.py
Comment thread src/reflex/services/bot.py
Comment thread src/reflex/services/commands.py Outdated
Comment thread src/reflex/services/commands.py
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@devonjones
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant and well-architected natural language command system. The separation of concerns into parsing, target resolution, and execution is clean and logical. The use of an LLM with a JSON schema for command parsing is a robust approach.

My review focuses on improving the robustness of the command parser, particularly in handling malformed LLM responses, and suggests adopting more idiomatic asynchronous patterns for network requests to improve efficiency. I've also included some minor refactoring suggestions to enhance maintainability. Overall, this is a solid implementation of a complex feature.

Comment thread src/reflex/services/commands.py
Comment thread src/reflex/services/bot.py
Comment thread src/reflex/services/bot.py
Comment thread src/reflex/services/commands.py
Comment thread src/reflex/services/commands.py
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@devonjones
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a natural language command system, which is a significant and well-implemented feature. The code is generally clean and follows a good structure with command parsing and execution separated into different services.

My review focuses on a few key areas for improvement:

  • Adopting asynchronous patterns for network requests to improve performance.
  • Enhancing the robustness of the LLM response parsing.
  • Refactoring some logic to improve maintainability and readability, such as using dispatch tables and list comprehensions.

Overall, this is a solid contribution. The suggested changes are aimed at refining the implementation and ensuring it's robust and scalable.

Comment thread src/reflex/services/commands.py
Comment thread src/reflex/services/bot.py
Comment thread src/reflex/services/bot.py
Comment thread src/reflex/services/commands.py
@devonjones devonjones merged commit 6f405a7 into main Jan 15, 2026
2 checks passed
@devonjones devonjones deleted the feat/command-system branch January 15, 2026 18:40
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