Skip to content

Conversation

@pavanimanchala53
Copy link

@pavanimanchala53 pavanimanchala53 commented Dec 13, 2025

Summary

Implements shell hotkey integration for Cortex, allowing users to get AI-powered command suggestions directly in their terminal using a configurable hotkey.

Features

  • Bash and Zsh shell integration
  • Ctrl+L hotkey to replace current input with suggested command
  • cortex --install-integration command for easy setup
  • Lightweight, non-intrusive design

Usage

cortex --install-integration
# restart shell
# press Ctrl+L on any typed command

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Bash and Zsh shell integration with Ctrl+L to receive command suggestions
  * Command-suggestion endpoint accessible from the CLI for inline shell replacement
  * Desktop notification management via a new notify command (config, enable, disable, dnd, send)

* **Tests**
  * Added basic tests for the suggestion logic

* **Chores**
  * Removed CodeQL GitHub Actions workflow

<sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->


fixes #265 

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 13, 2025

Walkthrough

Adds shell hotkey integration (Bash/Zsh) and installer, a CLI bridge to request command suggestions, a shell_integration backend that calls the interpreter, unit tests, and a new CLI notify subcommand for desktop notification management.

Changes

Cohort / File(s) Summary
CLI — shell bridge & notify
cortex/cli.py
Added module-level shell_suggest(text: str) -> int to call cortex.shell_integration.suggest_command and print/exit accordingly; added CortexCLI.notify(self, args) to manage notification actions (config, enable, disable, dnd, send) via NotificationManager; integrated notify into CLI dispatch/help.
Shell suggestion backend
cortex/shell_integration.py
New module with suggest_command(user_input: str) -> Optional[str] that trims input, lazily imports interpret, invokes it, validates the result, and returns a command string or None.
Shell integration installer
cortex/shell_installer.py
New module defining BASH_MARKER, ZSH_MARKER, helper _append_if_missing(rc_path: Path, block: str) -> bool, and install_shell_integration() that detects bash/zsh, constructs an injection block referencing shipped script, and appends it to the user's RC file.
Bash integration script
scripts/cortex_bash.sh
New script adding _cortex_suggest() which reads the current readline line, calls cortex _shell_suggest and, if a suggestion is returned, replaces the line and moves the cursor; binds Ctrl+L to that function.
Zsh integration script
scripts/cortex_zsh.zsh
New script adding _cortex_suggest() that reads BUFFER, calls cortex _shell_suggest, sets BUFFER to the suggestion and moves cursor to end; registers a ZLE widget and binds it to Ctrl+L.
Tests
tests/test_shell_integration.py
New tests for suggest_command: empty input returns None; non-empty input returns either None or a string without raising.
CI workflow removed
.github/workflows/codeql.yml
Removed CodeQL analysis workflow file.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor User
    participant Shell as "Shell (Bash/Zsh)"
    participant CLI as "cortex CLI"
    participant ShellInt as "cortex.shell_integration"
    participant Interp as "cortex.interpreter"

    User->>Shell: Press Ctrl+L (hotkey)
    Shell->>CLI: run `cortex _shell_suggest [current_input]`
    CLI->>ShellInt: suggest_command(user_input)
    ShellInt->>Interp: interpret(user_input)  -- lazy import
    Interp-->>ShellInt: interpretation (may include "command")
    ShellInt-->>CLI: suggested_command or None
    CLI-->>Shell: print suggestion (exit 0) or no output (exit 1)
    Shell->>Shell: replace current input with suggestion (if provided)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review lazy import error handling and return-types in cortex/shell_integration.py.
  • Verify path resolution, marker idempotency, file creation, and permission edge cases in cortex/shell_installer.py.
  • Validate shell scripts for different readline/zle environments and correct cursor placement (scripts/cortex_bash.sh, scripts/cortex_zsh.zsh).
  • Check CLI notify argument validation and NotificationManager integration in cortex/cli.py.

Poem

🐰 Ctrl+L, a twitch of paws, I peek at lines and craft my laws,
I nudge the shell and shape a clue, a helpful command just made for you,
With bash and zsh I hop and play, suggestions bloom to light your way,
Small bells ring out and scripts take flight—hop, press, accept, and code all night. ✨

Pre-merge checks and finishing touches

❌ Failed checks (3 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is missing the 'Related Issue' section as required by the template; it only includes Summary and mentions 'fixes #265' without the required 'Closes #' format in the designated section. Restructure the description to include the 'Related Issue' section with 'Closes #265' and move the fixes mention there. Also add a Checklist section with test status and PR title format confirmation.
Out of Scope Changes check ⚠️ Warning The PR includes out-of-scope changes: removal of .github/workflows/codeql.yml was not requested in issue #265 and appears unrelated to shell hotkey integration objectives. Revert the deletion of .github/workflows/codeql.yml to keep the PR focused on shell hotkey integration. Address code security analysis feedback separately if needed.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: shell hotkey integration' accurately and concisely summarizes the main change—adding shell hotkey integration for AI-powered command suggestions.
Linked Issues check ✅ Passed The PR implementation meets all coding requirements from issue #265: Bash/Zsh shell integration [#265], install command implementation [#265], configurable hotkey via Ctrl+L [#265], and command suggestion functionality [#265].
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cbec3d4 and 5ec7f65.

📒 Files selected for processing (1)
  • .github/workflows/codeql.yml (0 hunks)
💤 Files with no reviewable changes (1)
  • .github/workflows/codeql.yml

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.

Copy link
Contributor

@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: 7

🧹 Nitpick comments (4)
scripts/cortex_zsh.zsh (1)

16-17: Ctrl+L rebinds the standard "clear screen" shortcut.

Binding Ctrl+L will override the default terminal behavior of clearing the screen. Consider documenting this in installation output or offering an alternative keybinding option for users who rely on the default behavior.

scripts/cortex_bash.sh (1)

1-2: Add a shell directive for shellcheck compatibility.

While this script is sourced rather than executed directly, adding a shell directive helps static analysis tools and documents the expected shell environment.

+# shellcheck shell=bash
 # Cortex Bash shell integration
 # Binds Ctrl+L to send current input to Cortex and replace it with a suggestion
cortex/cli.py (1)

133-144: Consider exposing a public save_config method on NotificationManager.

Calling mgr._save_config() directly couples this code to the private implementation. While the inline comment acknowledges this, a public method would be cleaner.

cortex/shell_installer.py (1)

4-5: Both markers are identical, but only BASH_MARKER is checked.

BASH_MARKER and ZSH_MARKER have the same value, and _append_if_missing only checks for BASH_MARKER. This works coincidentally but is confusing. Consider either using a single MARKER constant or passing the marker to check as a parameter.

-BASH_MARKER = "# >>> cortex shell integration >>>"
-ZSH_MARKER = "# >>> cortex shell integration >>>"
+SHELL_MARKER = "# >>> cortex shell integration >>>"

Then use SHELL_MARKER consistently throughout.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b8a042 and 8b3e08c.

📒 Files selected for processing (5)
  • cortex/cli.py (2 hunks)
  • cortex/shell_installer.py (1 hunks)
  • cortex/shell_integration.py (1 hunks)
  • scripts/cortex_bash.sh (1 hunks)
  • scripts/cortex_zsh.zsh (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Follow PEP 8 style guide
Type hints required in Python code
Docstrings required for all public APIs

Files:

  • cortex/shell_integration.py
  • cortex/shell_installer.py
  • cortex/cli.py
**/*install*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*install*.py: Dry-run by default for all installations in command execution
No silent sudo execution - require explicit user confirmation
Implement audit logging to ~/.cortex/history.db for all package operations

Files:

  • cortex/shell_installer.py
🧬 Code graph analysis (1)
cortex/cli.py (1)
cortex/shell_integration.py (1)
  • suggest_command (11-48)
🪛 Shellcheck (0.11.0)
scripts/cortex_bash.sh

[error] 1-1: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.

(SC2148)

🔇 Additional comments (3)
cortex/shell_integration.py (1)

26-34: Defensive error handling is appropriate for shell integration.

The broad except Exception catches are suitable here since this code runs in a shell hotkey context where any failure should silently return None rather than break the user's terminal session.

cortex/cli.py (2)

116-131: LGTM: Graceful handling of missing subcommand.

The check for args.notify_action with a helpful error message is good defensive coding.


152-158: Good: Time format validation added.

The validation using datetime.strptime with proper error handling ensures users provide valid HH:MM times.

Copy link
Contributor

@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: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8b3e08c and cbec3d4.

📒 Files selected for processing (1)
  • tests/test_shell_integration.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Follow PEP 8 style guide
Type hints required in Python code
Docstrings required for all public APIs

Files:

  • tests/test_shell_integration.py
tests/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Maintain >80% test coverage for pull requests

Files:

  • tests/test_shell_integration.py
🧬 Code graph analysis (1)
tests/test_shell_integration.py (1)
cortex/shell_integration.py (1)
  • suggest_command (11-48)

@Sahilbhatane
Copy link
Collaborator

@pavanimanchala53 resolve the coderabbit suggestions and delete codeql.yml file from .github/workflows code security analysis is already enabled.

@sonarqubecloud
Copy link

@pavanimanchala53
Copy link
Author

pavanimanchala53 commented Dec 15, 2025

@pavanimanchala53 resolve the coderabbit suggestions and delete codeql.yml file from .github/workflows code security analysis is already enabled.

Hi @Sahilbhatane & @mikejmorgan-ai ,

This branch is ready for review. Please let me know if everything looks good so we can proceed with the merge.

Thanks!

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.

Shell Hotkey Integration for Instant AI Suggestions

2 participants