From c1a47858f389efdfe900f88dd5011bf72a8d80c5 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 15 Aug 2025 10:00:17 -0700 Subject: [PATCH] fix: rule colocation uri logic (#7164) * fix: rule colocation uri logic * rename to `fileUri` * fix: type errors * fix test mocks * Update slugs.test.ts --- .../rules/bigger-picture-description-rules.md | 19 ++++++ .../bigger-picture-description-rules.yaml | 13 ---- .continue/rules/colors.md | 63 +++++++++++++++++++ .continue/rules/colors.yaml | 27 -------- .../rules/edit-aggregator-singleton-rule.md | 8 --- .../rules/intellij-plugin-test-execution.md | 20 ++++++ .../rules/intellij-plugin-test-execution.yaml | 15 ----- .continue/rules/intellij-test-standards.md | 20 ++++++ .continue/rules/intellij-test-standards.yaml | 10 --- .continue/rules/new-protocol-message.md | 1 + .continue/rules/unit-testing-rules.md | 37 +++++++++++ .continue/rules/unit-testing-rules.yaml | 28 --------- core/config/markdown/loadCodebaseRules.ts | 20 +++++- .../markdown/loadCodebaseRules.vitest.ts | 24 ++++++- core/config/markdown/loadMarkdownRules.ts | 7 ++- core/config/profile/LocalProfileLoader.ts | 3 +- core/config/profile/doLoadConfig.ts | 10 +-- core/config/yaml/loadLocalYamlBlocks.ts | 2 +- core/config/yaml/loadYaml.ts | 4 +- .../config-yaml/src/__tests__/index.test.ts | 12 ++-- .../config-yaml/src/interfaces/slugs.test.ts | 6 +- packages/config-yaml/src/interfaces/slugs.ts | 10 +-- packages/config-yaml/src/load/unroll.test.ts | 8 +-- packages/config-yaml/src/load/unroll.ts | 6 +- .../src/markdown/createMarkdownRule.test.ts | 2 +- .../src/markdown/markdownToRule.test.ts | 22 +++---- .../src/markdown/markdownToRule.ts | 7 ++- .../config-yaml/src/registryClient.test.ts | 2 +- packages/config-yaml/src/registryClient.ts | 2 +- 29 files changed, 255 insertions(+), 153 deletions(-) create mode 100644 .continue/rules/bigger-picture-description-rules.md delete mode 100644 .continue/rules/bigger-picture-description-rules.yaml create mode 100644 .continue/rules/colors.md delete mode 100644 .continue/rules/colors.yaml delete mode 100644 .continue/rules/edit-aggregator-singleton-rule.md create mode 100644 .continue/rules/intellij-plugin-test-execution.md delete mode 100644 .continue/rules/intellij-plugin-test-execution.yaml create mode 100644 .continue/rules/intellij-test-standards.md delete mode 100644 .continue/rules/intellij-test-standards.yaml create mode 100644 .continue/rules/unit-testing-rules.md delete mode 100644 .continue/rules/unit-testing-rules.yaml diff --git a/.continue/rules/bigger-picture-description-rules.md b/.continue/rules/bigger-picture-description-rules.md new file mode 100644 index 000000000..b1a759abe --- /dev/null +++ b/.continue/rules/bigger-picture-description-rules.md @@ -0,0 +1,19 @@ +--- +name: Bigger Picture Description Rules +description: Guidelines for explaining how code works in context +alwaysApply: false +--- + +When a user asks how a certain part of the code works: + +## 1. Describe what the code does in isolation + +Explain the functionality of the code without considering its interactions with other parts of the codebase. + +## 2. Describe interactions with other parts of the codebase + +If the code interacts with other parts of the codebase, describe how the code is imported and used in other parts of the codebase. + +## 3. Include parent function for clarity + +When describing each use-case, include the parent function for clarity. diff --git a/.continue/rules/bigger-picture-description-rules.yaml b/.continue/rules/bigger-picture-description-rules.yaml deleted file mode 100644 index 4e076e88a..000000000 --- a/.continue/rules/bigger-picture-description-rules.yaml +++ /dev/null @@ -1,13 +0,0 @@ -name: bigger-picture-description-rules -version: 0.0.1 -schema: v1 -rules: - - name: bigger-picture-description-rules - rule: >- - When a user asks how a certain part of the code works: - - 1. Describe what the code does in isolation. - - 2. If the code interacts with other parts of the codebase, describe how the code is imported and used in other parts of the codebase. - - 3. When describing each use-case, include the parent function for clarity. diff --git a/.continue/rules/colors.md b/.continue/rules/colors.md new file mode 100644 index 000000000..0d031cbd0 --- /dev/null +++ b/.continue/rules/colors.md @@ -0,0 +1,63 @@ +--- +name: Extension Color Themes +description: Guidelines for using theme colors in GUI components +alwaysApply: false +globs: "gui/**/*.tsx" +--- + +When adding colors to components, use tailwind color classes. +Do NOT use explicit colors like text-gray-400. Instead, use theme colors. + +## Available theme colors + +### Normal text + +- `foreground`, `description`, `description-muted` + +### Other text, icons, etc + +- `success`, `warning`, `error`, `accent`, `link` + +### General components + +- `background`, `border`, `border-focus` + +### Specific components + +#### Button + +- `primary`, `primary-foreground`, `primary-hover` +- `secondary`, `secondary-foreground`, `secondary-hover` + +#### Input + +- `input`, `input-foreground`, `input-border`, `input-placeholder` + +#### Badge + +- `badge`, `badge-foreground` + +#### List/Dropdown items + +- `list-hover`, `list-active`, `list-active-foreground` + +#### Code Editor + +- `editor`, `editor-foreground` + +## Usage examples + +Any of these colors can be used in tailwind classes: + +- `bg-primary` +- `text-success` +- `border-error` +- `hover:bg-list-hover` + +## Excluded colors + +The following less-used colors are excluded from this guide: + +- Command (only used by tip-tap): `command`, `command-foreground`, `command-border`, `command-border-focus` +- Find widget colors: `find-match`, `find-match-selected` +- `table-oddRow` diff --git a/.continue/rules/colors.yaml b/.continue/rules/colors.yaml deleted file mode 100644 index 8ca60672e..000000000 --- a/.continue/rules/colors.yaml +++ /dev/null @@ -1,27 +0,0 @@ -name: GUI -version: 0.0.1 -schema: v1 -rules: - - name: Extension Color Themes - rule: | - When adding colors to components, use tailwind color classes. - Do NOT use explicit colors like text-gray-400. Instead, use theme colors. - - The common available theme colors are: - - For normal text: foreground, description, description-muted - - For other text, icons, etc: success, warning, error, accent, link - - For general components background, border, border-focus - - For specific components: - - Button: primary, primary-foreground, primary-hover, secondary, secondary-foreground, secondary-hover - - Input: input, input-foreground, input-border, input-placeholder - - Badge: badge, badge-foreground - - List/Dropdown items: list-hover, list-active, list-active-foreground - - Code Editor: editor, editor-foreground - - Any of these colors can be used in tailwind e.g. bg-primary, text-success, border-error, hover:bg-list-hover, etc. - globs: "gui/**/*.tsx" -# Excluding the following less-used colors: -# Command (only used by tip-tap): command, command-foreground, command-border, command-border-focus -# Find widget colors: find-match, find-match-selected -# table-oddRow - diff --git a/.continue/rules/edit-aggregator-singleton-rule.md b/.continue/rules/edit-aggregator-singleton-rule.md deleted file mode 100644 index 05ad0917b..000000000 --- a/.continue/rules/edit-aggregator-singleton-rule.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -patterns: ["EditAggregator", "processEdit"] -glob: "**/*.tsx" -name: "Enforce EditAggregator Singleton" -description: "Ensure that EditAggregator is used as a singleton in the codebase." ---- - -When you encounter usage of EditAggregator, be sure that this is compatible with the singleton nature of the EditAggregator class. If you are creating a new instance of EditAggregator, you should instead use the existing singleton. Refer to the `aggregateEdits.ts` to examine how the singleton pattern is used. Do not create a new instance of EditAggregator. diff --git a/.continue/rules/intellij-plugin-test-execution.md b/.continue/rules/intellij-plugin-test-execution.md new file mode 100644 index 000000000..8b35745a6 --- /dev/null +++ b/.continue/rules/intellij-plugin-test-execution.md @@ -0,0 +1,20 @@ +--- +name: IntelliJ Plugin Test Execution +description: Guidelines for running IntelliJ plugin tests with Gradle +alwaysApply: false +globs: extensions/intellij/**/*Test.kt +--- + +Run IntelliJ plugin tests using Gradle with the fully qualified test class or method name: + +## Run test class + +```bash +./gradlew test --tests "com.github.continuedev.continueintellijextension.unit.ApplyToFileHandlerTest" +``` + +## Run specific test method + +```bash +./gradlew test --tests "com.github.continuedev.continueintellijextension.unit.ApplyToFileHandlerTest.should*" +``` diff --git a/.continue/rules/intellij-plugin-test-execution.yaml b/.continue/rules/intellij-plugin-test-execution.yaml deleted file mode 100644 index 386a72a2b..000000000 --- a/.continue/rules/intellij-plugin-test-execution.yaml +++ /dev/null @@ -1,15 +0,0 @@ -name: IntelliJ Plugin Test Execution -version: 0.0.1 -schema: v1 -rules: - - name: IntelliJ Plugin Test Execution - rule: |- - Run IntelliJ plugin tests using Gradle with the fully qualified test class or method name: - ```bash - # Run test class - ./gradlew test --tests "com.github.continuedev.continueintellijextension.unit.ApplyToFileHandlerTest" - - # Run specific test method - ./gradlew test --tests "com.github.continuedev.continueintellijextension.unit.ApplyToFileHandlerTest.should*" - ``` - globs: extensions/intellij/**/*Test.kt diff --git a/.continue/rules/intellij-test-standards.md b/.continue/rules/intellij-test-standards.md new file mode 100644 index 000000000..6e04518b6 --- /dev/null +++ b/.continue/rules/intellij-test-standards.md @@ -0,0 +1,20 @@ +--- +name: IntelliJ Test Standards +description: Standards for writing tests in the IntelliJ plugin +alwaysApply: false +globs: "**/test/**/*.kt" +--- + +When writing tests for the IntelliJ plugin: + +## Use mockk library for mocking + +Prefer mockk's idiomatic syntax for creating and verifying mocks. + +## Structure tests with clear patterns + +Always structure tests with clear Arrange-Act-Assert patterns. + +## Use descriptive test names + +Use descriptive test names that indicate the scenario being tested. diff --git a/.continue/rules/intellij-test-standards.yaml b/.continue/rules/intellij-test-standards.yaml deleted file mode 100644 index f706757e2..000000000 --- a/.continue/rules/intellij-test-standards.yaml +++ /dev/null @@ -1,10 +0,0 @@ -name: IntelliJ Test Standards -version: 0.0.1 -schema: v1 -rules: - - name: IntelliJ Test Standards - rule: When writing tests for the IntelliJ plugin, use the mockk library for - mocking. Prefer mockk's idiomatic syntax for creating and verifying mocks. - Always structure tests with clear Arrange-Act-Assert patterns and use - descriptive test names that indicate the scenario being tested. - globs: "**/test/**/*.kt" diff --git a/.continue/rules/new-protocol-message.md b/.continue/rules/new-protocol-message.md index 23c6ba638..b01961242 100644 --- a/.continue/rules/new-protocol-message.md +++ b/.continue/rules/new-protocol-message.md @@ -1,6 +1,7 @@ --- name: New protocol message description: Create a new protocol message from core/gui/ide to core/gui/ide +alwaysApply: false --- Create a new protocol message by taking the following steps: diff --git a/.continue/rules/unit-testing-rules.md b/.continue/rules/unit-testing-rules.md new file mode 100644 index 000000000..bd9fb0109 --- /dev/null +++ b/.continue/rules/unit-testing-rules.md @@ -0,0 +1,37 @@ +--- +name: Unit Testing Rules +description: Guidelines for unit testing in this project +alwaysApply: false +--- + +For unit testing in this project: + +## 1. Testing frameworks + +The project uses Vitest and Jest for testing. Prefer Vitest. + +## 2. Test execution location + +Run tests from within the specific package directory (e.g., `cd core && ..`). + +## 3. Vitest tests + +- Test files follow the pattern `*.vitest.ts` +- Run tests using `vitest` from within the specific package/module directory: + ```bash + cd [directory] && vitest -- [test file path] + ``` + +## 4. Jest tests + +- Test files follow the pattern `*.test.ts` +- Run tests using `npm test` from within the specific package/module directory: + ```bash + cd [directory] && npm test -- [test file path] + ``` +- The test script uses experimental VM modules via NODE_OPTIONS flag + +## 5. Test structure + +- Write tests as top-level `test()` functions - DO NOT use `describe()` blocks +- Include the function name being tested in the test description for clarity diff --git a/.continue/rules/unit-testing-rules.yaml b/.continue/rules/unit-testing-rules.yaml deleted file mode 100644 index f846986c2..000000000 --- a/.continue/rules/unit-testing-rules.yaml +++ /dev/null @@ -1,28 +0,0 @@ -name: unit-testing-rules -version: 0.0.1 -schema: v1 -rules: - - name: unit-testing-rules - rule: >- - For unit testing in this project: - - 1. The project uses Vitest and Jest for testing. Prefer Vitest - - 2. Run tests from within the specific package directory (e.g., `cd core && ..` - - 3. For vitest tests, - - Test files follow the pattern `*.vitest.ts` - - Run tests using `vitest` from within the specific package/module - directory: `cd [directory] && vitest -- [test file path]` - - 4. For jest tests, - - Test files follow the pattern `*.test.ts` - - Run tests using `npm test` from within the specific package/module - directory: `cd [directory] && npm test -- [test file path]` - - The test script uses experimental VM modules via NODE_OPTIONS flag - - 5. For both - - Write tests as top-level `test()` functions - DO NOT use `describe()` - blocks - - Include the function name being tested in the test description for - clarity diff --git a/core/config/markdown/loadCodebaseRules.ts b/core/config/markdown/loadCodebaseRules.ts index e0d76bfec..dc6696576 100644 --- a/core/config/markdown/loadCodebaseRules.ts +++ b/core/config/markdown/loadCodebaseRules.ts @@ -5,7 +5,7 @@ import { import { IDE, RuleWithSource } from "../.."; import { walkDirs } from "../../indexing/walkDir"; import { RULES_MARKDOWN_FILENAME } from "../../llm/rules/constants"; -import { getUriPathBasename } from "../../util/uri"; +import { findUriInDirs, getUriPathBasename } from "../../util/uri"; export class CodebaseRulesCache { private static instance: CodebaseRulesCache | null = null; @@ -26,7 +26,14 @@ export class CodebaseRulesCache { } async update(ide: IDE, uri: string) { const content = await ide.readFile(uri); - const rule = markdownToRule(content, { uriType: "file", filePath: uri }); + const { relativePathOrBasename } = findUriInDirs( + uri, + await ide.getWorkspaceDirs(), + ); + const rule = markdownToRule(content, { + uriType: "file", + fileUri: relativePathOrBasename, + }); const ruleWithSource: RuleWithSource = { ...rule, source: "colocated-markdown", @@ -68,7 +75,14 @@ export async function loadCodebaseRules(ide: IDE): Promise<{ for (const filePath of rulesMdFiles) { try { const content = await ide.readFile(filePath); - const rule = markdownToRule(content, { uriType: "file", filePath }); + const { relativePathOrBasename } = findUriInDirs( + filePath, + await ide.getWorkspaceDirs(), + ); + const rule = markdownToRule(content, { + uriType: "file", + fileUri: relativePathOrBasename, + }); rules.push({ ...rule, diff --git a/core/config/markdown/loadCodebaseRules.vitest.ts b/core/config/markdown/loadCodebaseRules.vitest.ts index f9c3972c8..74da02684 100644 --- a/core/config/markdown/loadCodebaseRules.vitest.ts +++ b/core/config/markdown/loadCodebaseRules.vitest.ts @@ -2,6 +2,7 @@ import { markdownToRule } from "@continuedev/config-yaml"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { IDE } from "../.."; import { walkDirs } from "../../indexing/walkDir"; +import { findUriInDirs, getUriPathBasename } from "../../util/uri"; import { loadCodebaseRules } from "./loadCodebaseRules"; // Mock dependencies @@ -13,12 +14,20 @@ vi.mock("@continuedev/config-yaml", () => ({ markdownToRule: vi.fn(), })); +vi.mock("../../util/uri", () => ({ + findUriInDirs: vi.fn(), + getUriPathBasename: vi.fn(), +})); + describe("loadCodebaseRules", () => { // Mock IDE with properly typed mock functions const mockIde = { readFile: vi.fn() as unknown as IDE["readFile"] & { mockImplementation: Function; }, + getWorkspaceDirs: vi.fn() as unknown as IDE["getWorkspaceDirs"] & { + mockImplementation: Function; + }, } as unknown as IDE; // Setup test files @@ -77,6 +86,19 @@ describe("loadCodebaseRules", () => { // Mock walkDirs to return our test files (walkDirs as any).mockResolvedValue(mockFiles); + // Mock getWorkspaceDirs to return a workspace directory + (mockIde.getWorkspaceDirs as any).mockResolvedValue(["/workspace"]); + + // Mock getUriPathBasename to return just the filename + (getUriPathBasename as any).mockImplementation((path: string) => { + return path.split("/").pop() || ""; + }); + + // Mock findUriInDirs to return relative path + (findUriInDirs as any).mockImplementation((uri: string) => { + return { relativePathOrBasename: uri }; + }); + // Mock readFile to return content based on path (mockIde.readFile as any).mockImplementation((path: string) => { return Promise.resolve(mockRuleContent[path] || ""); @@ -85,7 +107,7 @@ describe("loadCodebaseRules", () => { // Mock markdownToRule to return converted rules (markdownToRule as any).mockImplementation( (content: string, options: any) => { - return mockConvertedRules[options.filePath]; + return mockConvertedRules[options.fileUri]; }, ); }); diff --git a/core/config/markdown/loadMarkdownRules.ts b/core/config/markdown/loadMarkdownRules.ts index e3d32e237..1ee771c05 100644 --- a/core/config/markdown/loadMarkdownRules.ts +++ b/core/config/markdown/loadMarkdownRules.ts @@ -3,6 +3,7 @@ import { markdownToRule, } from "@continuedev/config-yaml"; import { IDE, RuleWithSource } from "../.."; +import { findUriInDirs } from "../../util/uri"; import { getAllDotContinueDefinitionFiles } from "../loadLocalAssistants"; /** @@ -29,9 +30,13 @@ export async function loadMarkdownRules(ide: IDE): Promise<{ // Process each markdown file for (const file of mdFiles) { try { + const { relativePathOrBasename } = findUriInDirs( + file.path, + await ide.getWorkspaceDirs(), + ); const rule = markdownToRule(file.content, { uriType: "file", - filePath: file.path, + fileUri: relativePathOrBasename, }); rules.push({ ...rule, source: "rules-block", ruleFile: file.path }); } catch (e) { diff --git a/core/config/profile/LocalProfileLoader.ts b/core/config/profile/LocalProfileLoader.ts index 466243b3f..56d416d0b 100644 --- a/core/config/profile/LocalProfileLoader.ts +++ b/core/config/profile/LocalProfileLoader.ts @@ -65,8 +65,7 @@ export default class LocalProfileLoader implements IProfileLoader { orgScopeId: null, packageIdentifier: { uriType: "file", - filePath: - this.overrideAssistantFile?.path ?? getPrimaryConfigFilePath(), + fileUri: this.overrideAssistantFile?.path ?? getPrimaryConfigFilePath(), }, }); diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index 48da9934d..95db22eb9 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -62,6 +62,11 @@ async function loadRules(ide: IDE) { rules.unshift(...markdownRules); errors.push(...markdownRulesErrors); + // Add colocated rules from CodebaseRulesCache + const codebaseRulesCache = CodebaseRulesCache.getInstance(); + rules.unshift(...codebaseRulesCache.rules); + errors.push(...codebaseRulesCache.errors); + return { rules, errors }; } export default async function doLoadConfig(options: { @@ -182,11 +187,6 @@ export default async function doLoadConfig(options: { } }); - // Add rules from colocated rules.md files in the codebase - const codebaseRulesCache = CodebaseRulesCache.getInstance(); - newConfig.rules.unshift(...codebaseRulesCache.rules); - errors.push(...codebaseRulesCache.errors); - // Rectify model selections for each role newConfig = rectifySelectedModelsFromGlobalContext(newConfig, profileId); diff --git a/core/config/yaml/loadLocalYamlBlocks.ts b/core/config/yaml/loadLocalYamlBlocks.ts index 8c3cde9cb..aa769eb0c 100644 --- a/core/config/yaml/loadLocalYamlBlocks.ts +++ b/core/config/yaml/loadLocalYamlBlocks.ts @@ -23,7 +23,7 @@ export async function unrollLocalYamlBlocks( const unrollResult = await unrollAssistantFromContent( { uriType: "file", - filePath: "", + fileUri: "", }, "name: FILLER\nschema: v1\nversion: 0.0.1", registryClient, diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 5b3bc17ca..6772a2d02 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -72,7 +72,7 @@ async function loadConfigYaml(options: { ); return localBlocks.map((b) => ({ uriType: "file" as const, - filePath: b.path, + fileUri: b.path, })); }); const localPackageIdentifiers: PackageIdentifier[] = ( @@ -87,7 +87,7 @@ async function loadConfigYaml(options: { const getRegistryClient = async () => { const rootPath = packageIdentifier.uriType === "file" - ? dirname(getCleanUriPath(packageIdentifier.filePath)) + ? dirname(getCleanUriPath(packageIdentifier.fileUri)) : undefined; return new RegistryClient({ accessToken: await controlPlaneClient.getAccessToken(), diff --git a/packages/config-yaml/src/__tests__/index.test.ts b/packages/config-yaml/src/__tests__/index.test.ts index 5e0a3cdb9..4ba87bb81 100644 --- a/packages/config-yaml/src/__tests__/index.test.ts +++ b/packages/config-yaml/src/__tests__/index.test.ts @@ -96,7 +96,7 @@ describe("E2E Scenarios", () => { const filePath = id.uriType === "slug" ? `./src/__tests__/packages/${slug}.yaml` - : id.filePath; + : id.fileUri; return fs.readFileSync(filePath).toString(); }, }; @@ -244,7 +244,7 @@ describe("E2E Scenarios", () => { }, { uriType: "file", - filePath: "./src/__tests__/local-files/rules.yaml", + fileUri: "./src/__tests__/local-files/rules.yaml", }, ], }, @@ -276,7 +276,7 @@ describe("E2E Scenarios", () => { const unrolledConfig = await unrollAssistant( { uriType: "file", - filePath: "./src/__tests__/local-files/duplicate-test-assistant.yaml", + fileUri: "./src/__tests__/local-files/duplicate-test-assistant.yaml", }, registry, { @@ -289,15 +289,15 @@ describe("E2E Scenarios", () => { injectBlocks: [ { uriType: "file", - filePath: "./src/__tests__/local-files/rules.yaml", + fileUri: "./src/__tests__/local-files/rules.yaml", }, { uriType: "file", - filePath: "./src/__tests__/local-files/mcpServer.yaml", + fileUri: "./src/__tests__/local-files/mcpServer.yaml", }, { uriType: "file", - filePath: "./src/__tests__/local-files/prompt.yaml", + fileUri: "./src/__tests__/local-files/prompt.yaml", }, ], }, diff --git a/packages/config-yaml/src/interfaces/slugs.test.ts b/packages/config-yaml/src/interfaces/slugs.test.ts index e07e6f700..423694dc6 100644 --- a/packages/config-yaml/src/interfaces/slugs.test.ts +++ b/packages/config-yaml/src/interfaces/slugs.test.ts @@ -117,7 +117,7 @@ describe("PackageIdentifier", () => { it("should encode/decode file-based package identifier with relative path", () => { const testIdentifier = { uriType: "file" as const, - filePath: "./path/to/package.yaml", + fileUri: "./path/to/package.yaml", }; const encoded = encodePackageIdentifier(testIdentifier); expect(encoded).toBe("./path/to/package.yaml"); @@ -129,7 +129,7 @@ describe("PackageIdentifier", () => { it("should encode/decode file-based package identifier with absolute path", () => { const testIdentifier = { uriType: "file" as const, - filePath: "/absolute/path/to/package.yaml", + fileUri: "/absolute/path/to/package.yaml", }; const encoded = encodePackageIdentifier(testIdentifier); expect(encoded).toBe("/absolute/path/to/package.yaml"); @@ -144,7 +144,7 @@ describe("PackageIdentifier", () => { expect(decoded).toEqual({ uriType: "file" as const, - filePath: "/path/to/package.yaml", + fileUri: "/path/to/package.yaml", }); }); diff --git a/packages/config-yaml/src/interfaces/slugs.ts b/packages/config-yaml/src/interfaces/slugs.ts index 5e1417982..2215468d2 100644 --- a/packages/config-yaml/src/interfaces/slugs.ts +++ b/packages/config-yaml/src/interfaces/slugs.ts @@ -20,7 +20,7 @@ interface FullSlugIdentifier extends BasePackageIdentifier { interface FileIdentifier extends BasePackageIdentifier { uriType: "file"; - filePath: string; + fileUri: string; } export type PackageIdentifier = FullSlugIdentifier | FileIdentifier; @@ -28,7 +28,7 @@ export type PackageIdentifier = FullSlugIdentifier | FileIdentifier; export function packageIdentifierToDisplayName(id: PackageIdentifier): string { switch (id.uriType) { case "file": - return id.filePath; + return id.fileUri; case "slug": return id.fullSlug.packageSlug; } @@ -40,7 +40,7 @@ export function encodePackageIdentifier(identifier: PackageIdentifier): string { return encodeFullSlug(identifier.fullSlug); case "file": // For file paths, just return the path directly without a prefix - return identifier.filePath; + return identifier.fileUri; default: throw new Error(`Unknown URI type: ${(identifier as any).uriType}`); } @@ -51,14 +51,14 @@ export function decodePackageIdentifier(identifier: string): PackageIdentifier { if (identifier.startsWith(".") || identifier.startsWith("/")) { return { uriType: "file", - filePath: identifier, + fileUri: identifier, }; } // Keep support for explicit file:// protocol else if (identifier.startsWith("file://")) { return { uriType: "file", - filePath: identifier.substring(7), + fileUri: identifier.substring(7), }; } // Otherwise, it's a slug diff --git a/packages/config-yaml/src/load/unroll.test.ts b/packages/config-yaml/src/load/unroll.test.ts index 83bec0cd0..5df66084b 100644 --- a/packages/config-yaml/src/load/unroll.test.ts +++ b/packages/config-yaml/src/load/unroll.test.ts @@ -5,7 +5,7 @@ describe("parseMarkdownRuleOrAssistantUnrolled tests", () => { it("parses valid YAML content as AssistantUnrolled", () => { const mockId: PackageIdentifier = { uriType: "file", - filePath: "./foo/bar.yaml", + fileUri: "./foo/bar.yaml", }; const yamlContent = ` name: Test Assistant @@ -26,7 +26,7 @@ models: it("parses markdown rule content as AssistantUnrolled", () => { const mockId: PackageIdentifier = { uriType: "file", - filePath: "./foo/bar.md", + fileUri: "./foo/bar.md", }; const markdownContent = ` --- @@ -55,7 +55,7 @@ This is the rule it("throws error for invalid content in yaml file", () => { const mockId: PackageIdentifier = { uriType: "file", - filePath: "./foo/bar.yaml", + fileUri: "./foo/bar.yaml", }; const invalidContent = ` name: Test Assistant @@ -74,7 +74,7 @@ model: # should be models it("Every non-YAML file is a rule", () => { const mockId: PackageIdentifier = { uriType: "file", - filePath: "./foo/bar", + fileUri: "./foo/bar", }; const dubiousContent = `This is not \nproper #YAML#`; const result = parseMarkdownRuleOrAssistantUnrolled(dubiousContent, mockId); diff --git a/packages/config-yaml/src/load/unroll.ts b/packages/config-yaml/src/load/unroll.ts index 5225f79aa..21af99303 100644 --- a/packages/config-yaml/src/load/unroll.ts +++ b/packages/config-yaml/src/load/unroll.ts @@ -465,14 +465,14 @@ export async function unrollBlocks( resolvedBlock, source: injectBlock.uriType === "file" - ? injectBlock.filePath + ? injectBlock.fileUri : undefined, error: null, }; } catch (err) { let msg = ""; if (injectBlock.uriType === "file") { - msg = `${(err as Error).message}.\n> ${injectBlock.filePath}`; + msg = `${(err as Error).message}.\n> ${injectBlock.fileUri}`; } else { msg = `${(err as Error).message}.\n> ${injectBlock.fullSlug}`; } @@ -669,7 +669,7 @@ function parseYamlOrMarkdownRule( } catch (yamlError) { if ( id.uriType === "file" && - [".yaml", ".yml"].some((ext) => id.filePath.endsWith(ext)) + [".yaml", ".yml"].some((ext) => id.fileUri.endsWith(ext)) ) { throw yamlError; } diff --git a/packages/config-yaml/src/markdown/createMarkdownRule.test.ts b/packages/config-yaml/src/markdown/createMarkdownRule.test.ts index 982e823bf..169463953 100644 --- a/packages/config-yaml/src/markdown/createMarkdownRule.test.ts +++ b/packages/config-yaml/src/markdown/createMarkdownRule.test.ts @@ -9,7 +9,7 @@ import { markdownToRule } from "./markdownToRule.js"; // Mock package identifier for testing const mockPackageId: PackageIdentifier = { uriType: "file", - filePath: "/path/to/folder", + fileUri: "/path/to/folder", }; describe("sanitizeRuleName", () => { diff --git a/packages/config-yaml/src/markdown/markdownToRule.test.ts b/packages/config-yaml/src/markdown/markdownToRule.test.ts index 0d96ab19e..7103e3e2c 100644 --- a/packages/config-yaml/src/markdown/markdownToRule.test.ts +++ b/packages/config-yaml/src/markdown/markdownToRule.test.ts @@ -5,7 +5,7 @@ describe("markdownToRule", () => { // Use a mock PackageIdentifier for testing const mockId: PackageIdentifier = { uriType: "file", - filePath: "/path/to/file", + fileUri: "/path/to/file", }; it("should convert markdown with frontmatter to a rule", () => { @@ -115,7 +115,7 @@ name: glob pattern testing const result = markdownToRule(content, { uriType: "file", - filePath: "/", + fileUri: "/", }); expect(result.globs).toBe("/**/src/**/Dockerfile"); }); @@ -151,7 +151,7 @@ name: glob pattern testing const result = markdownToRule(content, { uriType: "file", - filePath: "/Documents/myproject/.continue/rules/rule1.md", + fileUri: "/Documents/myproject/.continue/rules/rule1.md", }); expect(result.globs).toBe(".git"); }); @@ -268,7 +268,7 @@ describe("getRuleName", () => { const frontmatter = { name: "Custom Rule Name" }; const id: PackageIdentifier = { uriType: "file", - filePath: "/path/to/my-rule.md", + fileUri: "/path/to/my-rule.md", }; const result = getRuleName(frontmatter, id); @@ -279,7 +279,7 @@ describe("getRuleName", () => { const frontmatter = {}; const id: PackageIdentifier = { uriType: "file", - filePath: "/long/path/to/rules/my-rule.md", + fileUri: "/long/path/to/rules/my-rule.md", }; const result = getRuleName(frontmatter, id); @@ -290,7 +290,7 @@ describe("getRuleName", () => { const frontmatter = {}; const id: PackageIdentifier = { uriType: "file", - filePath: "C:\\long\\path\\to\\rules\\my-rule.md", + fileUri: "C:\\long\\path\\to\\rules\\my-rule.md", }; const result = getRuleName(frontmatter, id); @@ -301,7 +301,7 @@ describe("getRuleName", () => { const frontmatter = {}; const id: PackageIdentifier = { uriType: "file", - filePath: "/path/to\\rules/my-rule.md", + fileUri: "/path/to\\rules/my-rule.md", }; const result = getRuleName(frontmatter, id); @@ -312,7 +312,7 @@ describe("getRuleName", () => { const frontmatter = {}; const id: PackageIdentifier = { uriType: "file", - filePath: "my-rule.md", + fileUri: "my-rule.md", }; const result = getRuleName(frontmatter, id); @@ -323,7 +323,7 @@ describe("getRuleName", () => { const frontmatter = {}; const id: PackageIdentifier = { uriType: "file", - filePath: "rules/my-rule.md", + fileUri: "rules/my-rule.md", }; const result = getRuleName(frontmatter, id); @@ -349,7 +349,7 @@ describe("getRuleName", () => { const frontmatter = { name: "Override Name" }; const id: PackageIdentifier = { uriType: "file", - filePath: "/very/long/path/to/rules/original-name.md", + fileUri: "/very/long/path/to/rules/original-name.md", }; const result = getRuleName(frontmatter, id); @@ -360,7 +360,7 @@ describe("getRuleName", () => { const frontmatter = { name: "" }; const id: PackageIdentifier = { uriType: "file", - filePath: "/path/to/rules/my-rule.md", + fileUri: "/path/to/rules/my-rule.md", }; const result = getRuleName(frontmatter, id); diff --git a/packages/config-yaml/src/markdown/markdownToRule.ts b/packages/config-yaml/src/markdown/markdownToRule.ts index f584a0549..f0489ced4 100644 --- a/packages/config-yaml/src/markdown/markdownToRule.ts +++ b/packages/config-yaml/src/markdown/markdownToRule.ts @@ -77,7 +77,10 @@ function getGlobPattern( if (id.uriType !== "file") { return globs; } - let dir = path.dirname(id.filePath); + let dir = path.dirname(id.fileUri); + + // TODO: This is likely causing bugs for Windows users. + // We can't access `core/util/uri.ts` from this package though. if (dir.includes(".continue")) { return globs; } @@ -112,6 +115,6 @@ export function markdownToRule( regex: frontmatter.regex, description: frontmatter.description, alwaysApply: frontmatter.alwaysApply, - sourceFile: id.uriType === "file" ? id.filePath : undefined, + sourceFile: id.uriType === "file" ? id.fileUri : undefined, }; } diff --git a/packages/config-yaml/src/registryClient.test.ts b/packages/config-yaml/src/registryClient.test.ts index bff0b9e84..d5875771a 100644 --- a/packages/config-yaml/src/registryClient.test.ts +++ b/packages/config-yaml/src/registryClient.test.ts @@ -95,7 +95,7 @@ describe("RegistryClient", () => { const id: PackageIdentifier = { uriType: "file", - filePath: testFilePath, + fileUri: testFilePath, }; const result = await client.getContent(id); diff --git a/packages/config-yaml/src/registryClient.ts b/packages/config-yaml/src/registryClient.ts index 3dab5e062..c027b31e8 100644 --- a/packages/config-yaml/src/registryClient.ts +++ b/packages/config-yaml/src/registryClient.ts @@ -26,7 +26,7 @@ export class RegistryClient implements Registry { async getContent(id: PackageIdentifier): Promise { switch (id.uriType) { case "file": - return this.getContentFromFilePath(id.filePath); + return this.getContentFromFilePath(id.fileUri); case "slug": return this.getContentFromSlug(id.fullSlug); default: