fix: rule colocation uri logic (#7164)
* fix: rule colocation uri logic * rename to `fileUri` * fix: type errors * fix test mocks * Update slugs.test.ts
This commit is contained in:
parent
85994118e8
commit
c1a47858f3
29 changed files with 255 additions and 153 deletions
19
.continue/rules/bigger-picture-description-rules.md
Normal file
19
.continue/rules/bigger-picture-description-rules.md
Normal file
|
|
@ -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.
|
||||
|
|
@ -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.
|
||||
63
.continue/rules/colors.md
Normal file
63
.continue/rules/colors.md
Normal file
|
|
@ -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`
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -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.
|
||||
20
.continue/rules/intellij-plugin-test-execution.md
Normal file
20
.continue/rules/intellij-plugin-test-execution.md
Normal file
|
|
@ -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*"
|
||||
```
|
||||
|
|
@ -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
|
||||
20
.continue/rules/intellij-test-standards.md
Normal file
20
.continue/rules/intellij-test-standards.md
Normal file
|
|
@ -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.
|
||||
|
|
@ -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"
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
37
.continue/rules/unit-testing-rules.md
Normal file
37
.continue/rules/unit-testing-rules.md
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
},
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<T>(
|
|||
} catch (yamlError) {
|
||||
if (
|
||||
id.uriType === "file" &&
|
||||
[".yaml", ".yml"].some((ext) => id.filePath.endsWith(ext))
|
||||
[".yaml", ".yml"].some((ext) => id.fileUri.endsWith(ext))
|
||||
) {
|
||||
throw yamlError;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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", () => {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ describe("RegistryClient", () => {
|
|||
|
||||
const id: PackageIdentifier = {
|
||||
uriType: "file",
|
||||
filePath: testFilePath,
|
||||
fileUri: testFilePath,
|
||||
};
|
||||
|
||||
const result = await client.getContent(id);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ export class RegistryClient implements Registry {
|
|||
async getContent(id: PackageIdentifier): Promise<string> {
|
||||
switch (id.uriType) {
|
||||
case "file":
|
||||
return this.getContentFromFilePath(id.filePath);
|
||||
return this.getContentFromFilePath(id.fileUri);
|
||||
case "slug":
|
||||
return this.getContentFromSlug(id.fullSlug);
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue