Skip to content

fix: updated openrouter defaults and settings window#7

Merged
VariableThe merged 1 commit into
mainfrom
fix/openrouter-defaults-and-settings
Jun 20, 2026
Merged

fix: updated openrouter defaults and settings window#7
VariableThe merged 1 commit into
mainfrom
fix/openrouter-defaults-and-settings

Conversation

@VariableThe

@VariableThe VariableThe commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Updates for defaults and settings window bounds

Summary by CodeRabbit

  • New Features

    • Added /ctx and /context commands for AI prompts with context mode
    • Settings window now sizes and positions relative to the main window
    • Added Escape key and Close Settings button to close settings
  • Documentation

    • Updated AI setup section with instructions for OpenAI, OpenRouter, and local LLM configurations
  • Security

    • API keys now stored securely instead of plain text

@VariableThe VariableThe merged commit f51dff1 into main Jun 20, 2026
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 59924b77-63df-48b1-844f-0bca352c4894

📥 Commits

Reviewing files that changed from the base of the PR and between e90bccf and f4be610.

📒 Files selected for processing (10)
  • README.md
  • electron/main.ts
  • fix_ts.py
  • src/App.css
  • src/App.tsx
  • src/Settings.css
  • src/Settings.tsx
  • src/lib/editor/plugins.ts
  • src/lib/editor/widgets.ts
  • src/store/useAIStore.ts

📝 Walkthrough

Walkthrough

Adds /ctx and /context editor commands that attach full-note context to AI prompts, switches the default AI provider from OpenAI to OpenRouter/Nemotron, improves the Settings window with secure API key storage and relative positioning, adds a close button, and applies TypeScript type-safety fixes via a codemod script across nine source files.

Changes

Context command and OpenRouter AI migration

Layer / File(s) Summary
ContextWidget and pill/highlight styling
src/lib/editor/widgets.ts, src/App.css
Adds ContextWidget (renders a cm-ctx-pill span reading "Context Attached") and defines purple-tinted cm-ctx-pill and cm-ctx-highlight CSS rules.
Editor decoration for /ctx and /context
src/lib/editor/plugins.ts
In hideMarkdownPlugin, a new regex pass detects /ctx and /context spans and applies ContextWidget replacement (non-cursor) or cm-ctx-highlight mark (cursor).
App.tsx command parsing, AI request path, and store defaults
src/App.tsx, src/store/useAIStore.ts
Extends the Enter-key handler to recognize /ctx//context prefixes, builds context-mode messages by truncating the document and wrapping it as Context: ... Prompt: ..., adds defaultHeaders to the client, adds defensive choice/error validation, and switches all OpenRouter/Nemotron defaults in both the handler fallback and the Zustand store.
README AI setup docs
README.md
Replaces single-paragraph AI setup text with bullet points covering OpenAI, OpenRouter free models, and local LLMs; updates the Settings shortcut to Cmd+Shift+S.

Settings window improvements

Layer / File(s) Summary
Settings window positioning and main window restore
electron/main.ts
Settings window is sized and positioned from win.getBounds() with a default fallback; the 'closed' handler re-shows the main note window.
Secure storage, close handler, and localStorage migration
src/Settings.tsx
Imports getSecure/setSecure, loads API key asynchronously on mount, registers an Escape handler, persists the key via setSecure, removes the insecure entry, migrates remaining fields to new localStorage keys, adds closeSettings, and updates input placeholders to OpenRouter examples.
Settings footer UI and CSS layout
src/Settings.tsx, src/Settings.css
Adds a "Close Settings" button and reorders footer actions; converts .settings-footer to flex with gap, changes .save-btn/.quit-btn to flex: 1, and adds .close-btn and .close-btn:hover rules.

TypeScript type-safety codemod

Layer / File(s) Summary
fix_ts.py codemod across all targets
fix_ts.py
Defines fix_file() and applies string replacements to useNoteStorage.ts, useReminders.ts, useVariables.ts, plugins.ts, utils.ts, utils.test.ts, App.tsx, RemindersPage.tsx, and GraphView.tsx to add optional chaining, non-null assertions, and || '' fallbacks.

Sequence Diagram

sequenceDiagram
  participant User as User
  participant Editor as CodeMirror Editor
  participant AppTsx as App.tsx Enter Handler
  participant OpenRouter as OpenRouter API

  User->>Editor: Types /ctx <prompt> and presses Enter
  Editor->>AppTsx: keydown Enter event
  AppTsx->>AppTsx: Detect /ctx prefix, compute prompt substring
  AppTsx->>AppTsx: Truncate full doc, build Context+Prompt message
  AppTsx->>OpenRouter: POST /chat/completions (defaultHeaders + nvidia/nemotron model)
  OpenRouter-->>AppTsx: completion.choices[0].message.content
  AppTsx->>Editor: Insert AI response at cursor position
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • VariableThe/PaperCache#5: The fix_ts.py codemod applies type-safety edits directly to src/components/RemindersPage.tsx, which is a core file introduced by this Tasks feature PR.

Poem

🐇 Hop hop, the context rides along,
A purple pill where /ctx belongs!
OpenRouter now leads the way,
With Nemotron free to play.
Settings locked in secrets tight,
The bunny codes from dawn to night! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/openrouter-defaults-and-settings

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.

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