Skip to content

feat(rules): persist and inject global Cursor rules - #345

Open
philau2512 wants to merge 2 commits into
leookun:mainfrom
philaudev:feat/global-rules
Open

feat(rules): persist and inject global Cursor rules#345
philau2512 wants to merge 2 commits into
leookun:mainfrom
philaudev:feat/global-rules

Conversation

@philau2512

Copy link
Copy Markdown
Contributor

Feature Pull Request

User Story

  • As a: Cursor BYOK user
  • I want to: create and manage global rules from Cursor
  • So that: my reusable instructions are applied to every locally routed model conversation.

Acceptance Criteria

  • Cursor Knowledge Base add, list, update, and remove requests are handled locally.
  • Global rules persist at ~/.cursor-byok-v3/rules/global/.
  • Every production prompt compiler reads the current global rules for each model request.
  • Global rules are appended to PromptSpec.instructions, which reaches OpenAI Chat, OpenAI Responses, and Anthropic system instructions.
  • Directly constructed test compilers do not read rules from the user’s local directory.
  • Rule frontmatter is excluded before a rule is appended to the model prompt.
  • Empty rule content is rejected.

Key Changes

  • Added server/src/cursor/rules.rs to manage persisted global rule files and Cursor-compatible protobuf handlers.
  • Added local routing for the four Knowledge Base endpoints:
    • KnowledgeBaseAdd
    • KnowledgeBaseList
    • KnowledgeBaseUpdate
    • KnowledgeBaseRemove
  • Added ~/.cursor-byok-v3/rules/global/ as the managed storage location for global rules.
  • Configured the production PromptCompiler from App with the global rules directory.
  • Appended active rules to PromptSpec.instructions in a <shared_user_rules> section.
  • Escaped rule content for the XML-like prompt format and stripped optional Markdown frontmatter.
  • Added unit tests for protobuf response encoding and the rule storage lifecycle.

Demo

N/A

Testing

  • Self-reviewed
  • Unit / Integration Tests:
    • cargo test rules::tests
    • cargo check
  • Manual Test Steps:
    1. Start Cursor BYOK and configure the Cursor proxy.
    2. Create a global rule in Cursor.
    3. Confirm that the rule is listed and stored under ~/.cursor-byok-v3/rules/global/.
    4. Start a new local/BYOK model conversation.
    5. Confirm the provider request contains the rule in its system instructions.
    6. Update or remove the rule and confirm subsequent model requests reflect the current rule set.

Impact & Reviewer Notes

  • Database Migration: No.
  • Environment Variables: No.
  • Permissions / Access Control: No new permissions.
  • Risk / Review Focus: Review the protobuf contracts for the Knowledge Base endpoints and verify global rules are injected only by the production compiler, not direct test constructors.

@leookun

leookun commented Aug 25, 2026

Copy link
Copy Markdown
Owner

Great, I'll take a look.

@philau2512
philau2512 marked this pull request as draft August 25, 2026 14:42
@philau2512

Copy link
Copy Markdown
Contributor Author

Added local handling for FetchRelevantKnowledgeForConversation. Persisted Global Rules are now returned independently of workspace git_origin, so they remain available after switching projects. Added route/proxy coverage and regression tests.

@philau2512
philau2512 marked this pull request as ready for review August 25, 2026 14:58
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