Skip to content

RulesContextProvider #6070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 11, 2025
Merged

RulesContextProvider #6070

merged 5 commits into from
Jun 11, 2025

Conversation

sestinj
Copy link
Contributor

@sestinj sestinj commented Jun 10, 2025

Description

Introduces the RulesContextProvider, which is available by default

Screenshot 2025-06-10 at 3 19 42 PM Screenshot 2025-06-10 at 3 19 59 PM Screenshot 2025-06-10 at 3 20 10 PM

Checklist

  • I've read the contributing guide
  • The relevant docs, if any, have been updated or created
  • The relevant tests, if any, have been updated or created

Tests

I don't feel that any meaningful logic was introduced that needs to be tested. If we tested some of the private methods on the class, that feels like it would be overkill

@sestinj sestinj requested a review from a team as a code owner June 10, 2025 22:19
@sestinj sestinj requested review from tomasz-stefaniak and removed request for a team June 10, 2025 22:19
Copy link
Contributor

cubic-dev-ai bot commented Jun 10, 2025

Your cubic subscription is currently inactive. Please reactivate your subscription to receive AI reviews and use cubic.

Copy link

netlify bot commented Jun 10, 2025

Deploy Preview for continuedev canceled.

Name Link
🔨 Latest commit 1bd881f
🔍 Latest deploy log https://app.netlify.com/projects/continuedev/deploys/6848f003fed6bb0008635d5e

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 10, 2025
@sestinj sestinj changed the title Nate/rules-as-context-providers RulesContextProvider Jun 10, 2025
@sestinj sestinj requested review from Patrick-Erichsen and removed request for tomasz-stefaniak June 10, 2025 22:20
Copy link
Collaborator

@Patrick-Erichsen Patrick-Erichsen left a comment

Choose a reason for hiding this comment

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

LGTM, few nitpick comments, only other thing is I think we should use the PencilIcon instead of the current default ChatBubbleIcon so that we mirror what is in the notch.

@@ -39,6 +41,24 @@ import { migrateJsonSharedConfig } from "../migrateSharedConfig";
import { rectifySelectedModelsFromGlobalContext } from "../selectedModels";
import { loadContinueConfigFromYaml } from "../yaml/loadYaml";

async function loadRules(ide: IDE) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is going to conflict with @tomasz-stefaniak PR, I think this is a good improvement though because his PR adds a 3rd rule source that we load from

return rule.ruleFile ?? rule.slug ?? rule.name ?? rule.rule;
}

private getNameFromRule(rule: RuleWithSource): string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We do this in convertMarkdownRuleToContinueRule to grab a fallback name from the first H1 tag in the markdown.

  // Try to extract title from first heading if no name in frontmatter
  let name = frontmatter.name;
  if (!name) {
    // Look for a heading in the markdown
    const headingMatch = markdown.match(/^#\s+(.+)$/m);
    if (headingMatch) {
      name = headingMatch[1].trim();
    } else {
      // Fall back to filename
      name = basename(path).replace(/\.md$/, "");
    }
  }

Kind of edge case though when we have the name property. If you don't think it's worth pulling in here maybe we just get rid of that logic in convertMarkdownRuleToContinueRule to keep behavior consistent though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the difference between this and convertMarkdownRuleToContinueRule is that RuleWithSource doesn't need to have a name. That function actually should get called prior to this one, so I don't think this method will ever be used. But is necessary for typing because I don't think we'd want to make name required on RuleWithSource (it wouldn't match the .md source). The name, id, and description are really concepts that are unique to the ContextItem interface so I don't think they would need to be used anywhere else

Copy link
Collaborator

Choose a reason for hiding this comment

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

A lot of the logic here feels like it should live in loadMarkdownRules.ts or some other rules subfolder so that we can reuse it, which I anticipate happening. E.g. most of @tomasz-stefaniak 's new work lives in core/config/markdown

Also would make it easier to test some of these helper fns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for the reason mentioned in my other comment I actually kind of think that these small methods won't ever need to be used anywhere else

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Jun 10, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 10, 2025
@sestinj sestinj merged commit a15d7c7 into main Jun 11, 2025
37 checks passed
@sestinj sestinj deleted the nate/rules-as-context-providers branch June 11, 2025 03:50
@github-project-automation github-project-automation bot moved this from In Progress to Done in Issues and PRs Jun 11, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jun 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants