Merge branch 'main' into bdougie/anthropic-prompt-true
This commit is contained in:
commit
b8ddab74eb
56 changed files with 584 additions and 6889 deletions
2
.github/workflows/pr_checks.yaml
vendored
2
.github/workflows/pr_checks.yaml
vendored
|
|
@ -439,7 +439,7 @@ jobs:
|
|||
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
|
||||
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
|
||||
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
|
||||
AZURE_FOUNDRY_API_KEY: ${{ secrets.AZURE_FOUNDRY_API_KEY }}
|
||||
AZURE_FOUNDRY_CODESTRAL_API_KEY: ${{ secrets.AZURE_FOUNDRY_CODESTRAL_API_KEY }}
|
||||
AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY: ${{ secrets.AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY }}
|
||||
AZURE_OPENAI_GPT41_API_KEY: ${{ secrets.AZURE_OPENAI_GPT41_API_KEY }}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { describe, test } from "vitest";
|
||||
import { PYTHON_TEST_CASES, TYPESCRIPT_TEST_CASES } from "./testCases";
|
||||
import { testRootPathContext } from "./testUtils";
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { jest } from "@jest/globals";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { expect, vi } from "vitest";
|
||||
|
||||
import Parser from "web-tree-sitter";
|
||||
import { Position } from "../../../..";
|
||||
|
|
@ -36,7 +36,7 @@ export async function testRootPathContext(
|
|||
const importDefinitionsService = new ImportDefinitionsService(ide);
|
||||
const service = new RootPathContextService(importDefinitionsService, ide);
|
||||
|
||||
const getSnippetsMock = jest
|
||||
const getSnippetsMock = vi
|
||||
// @ts-ignore
|
||||
.spyOn(service, "getSnippets")
|
||||
// @ts-ignore
|
||||
|
|
@ -46,7 +46,7 @@ export async function testRootPathContext(
|
|||
|
||||
// Copy the folder to the test directory
|
||||
const folderPath = path.join(
|
||||
__dirname,
|
||||
process.cwd(),
|
||||
"autocomplete",
|
||||
"context",
|
||||
"root-path-context",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { stopAtStartOf, stopAtStopTokens } from "./charStream";
|
||||
|
||||
async function* createMockStream(chunks: string[]): AsyncGenerator<string> {
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
import { jest } from "@jest/globals";
|
||||
import { beforeEach, describe, expect, it, Mock, vi } from "vitest";
|
||||
|
||||
import * as lineStream from "./lineStream";
|
||||
|
||||
// eslint-disable-next-line max-lines-per-function
|
||||
describe("lineStream", () => {
|
||||
let mockFullStop: jest.Mock;
|
||||
let mockFullStop: Mock;
|
||||
|
||||
async function getLineGenerator(lines: any) {
|
||||
return (async function* () {
|
||||
|
|
@ -25,7 +25,7 @@ describe("lineStream", () => {
|
|||
}
|
||||
|
||||
beforeEach(() => {
|
||||
mockFullStop = jest.fn();
|
||||
mockFullStop = vi.fn();
|
||||
});
|
||||
|
||||
describe("noTopLevelKeywordsMidline", () => {
|
||||
|
|
@ -1,4 +1,9 @@
|
|||
import { setUpTestDir, tearDownTestDir } from "../../../test/testDir";
|
||||
import { afterAll, beforeAll, beforeEach, describe, it } from "vitest";
|
||||
import {
|
||||
addToTestDir,
|
||||
setUpTestDir,
|
||||
tearDownTestDir,
|
||||
} from "../../../test/testDir";
|
||||
|
||||
import { TEST_CASES_WITH_DIFF, TEST_CASES_WITHOUT_DIFF } from "./testCases";
|
||||
import {
|
||||
|
|
@ -18,6 +23,7 @@ describe("Autocomplete filtering tests", () => {
|
|||
beforeAll(async () => {
|
||||
tearDownTestDir();
|
||||
setUpTestDir();
|
||||
addToTestDir([".continueignore"]);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import { expect } from "vitest";
|
||||
import MockLLM from "../../../llm/llms/Mock";
|
||||
import { testConfigHandler, testIde } from "../../../test/fixtures";
|
||||
import { joinPathsToUri } from "../../../util/uri";
|
||||
|
|
|
|||
|
|
@ -1,4 +1,12 @@
|
|||
import { jest } from "@jest/globals";
|
||||
import {
|
||||
afterEach,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
Mock,
|
||||
test,
|
||||
vi,
|
||||
} from "vitest";
|
||||
import { GeneratorReuseManager } from "./GeneratorReuseManager";
|
||||
|
||||
function createMockGenerator(
|
||||
|
|
@ -14,7 +22,7 @@ function createMockGenerator(
|
|||
}
|
||||
}
|
||||
};
|
||||
const newGenerator = jest
|
||||
const newGenerator = vi
|
||||
.fn<() => AsyncGenerator<string>>()
|
||||
.mockReturnValue(mockGenerator());
|
||||
|
||||
|
|
@ -23,15 +31,15 @@ function createMockGenerator(
|
|||
|
||||
describe("GeneratorReuseManager", () => {
|
||||
let reuseManager: GeneratorReuseManager;
|
||||
let onErrorMock: jest.Mock;
|
||||
let onErrorMock: Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
onErrorMock = jest.fn();
|
||||
onErrorMock = vi.fn();
|
||||
reuseManager = new GeneratorReuseManager(onErrorMock);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test("creates new generator when there is no current generator", async () => {
|
||||
|
|
@ -169,7 +177,7 @@ describe("GeneratorReuseManager", () => {
|
|||
const mockGenerator = async function* () {
|
||||
throw error;
|
||||
};
|
||||
const newGenerator = jest
|
||||
const newGenerator = vi
|
||||
.fn<() => AsyncGenerator<string>>()
|
||||
.mockReturnValue(mockGenerator());
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { jest } from "@jest/globals";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { ListenableGenerator } from "./ListenableGenerator";
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ describe("ListenableGenerator", () => {
|
|||
it("should yield values from the source generator via tee()", async () => {
|
||||
const values = [1, 2, 3];
|
||||
const source = asyncGenerator(values);
|
||||
const onError = jest.fn();
|
||||
const onError = vi.fn();
|
||||
|
||||
const lg = new ListenableGenerator<number>(
|
||||
source,
|
||||
|
|
@ -36,7 +36,7 @@ describe("ListenableGenerator", () => {
|
|||
it("should allow listeners to receive values", async () => {
|
||||
const values = [1, 2, 3];
|
||||
const source = asyncGenerator(values, 10); // Introduce delay to simulate async behavior
|
||||
const onError = jest.fn();
|
||||
const onError = vi.fn();
|
||||
|
||||
const lg = new ListenableGenerator<number>(
|
||||
source,
|
||||
|
|
@ -44,7 +44,7 @@ describe("ListenableGenerator", () => {
|
|||
new AbortController(),
|
||||
);
|
||||
|
||||
const listener = jest.fn();
|
||||
const listener = vi.fn();
|
||||
|
||||
// Add listener after some delay to simulate late subscription
|
||||
setTimeout(() => {
|
||||
|
|
@ -64,7 +64,7 @@ describe("ListenableGenerator", () => {
|
|||
it("should buffer values for listeners added after some values have been yielded", async () => {
|
||||
const values = [1, 2, 3];
|
||||
const source = asyncGenerator(values, 10);
|
||||
const onError = jest.fn();
|
||||
const onError = vi.fn();
|
||||
|
||||
const lg = new ListenableGenerator<number>(
|
||||
source,
|
||||
|
|
@ -72,7 +72,7 @@ describe("ListenableGenerator", () => {
|
|||
new AbortController(),
|
||||
);
|
||||
|
||||
const initialListener = jest.fn();
|
||||
const initialListener = vi.fn();
|
||||
|
||||
lg.listen(initialListener);
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ describe("ListenableGenerator", () => {
|
|||
await new Promise((resolve) => setTimeout(resolve, 15));
|
||||
|
||||
// Add a second listener
|
||||
const newListener = jest.fn();
|
||||
const newListener = vi.fn();
|
||||
lg.listen(newListener);
|
||||
|
||||
// Wait for generator to finish
|
||||
|
|
@ -98,7 +98,7 @@ describe("ListenableGenerator", () => {
|
|||
it("should handle cancellation", async () => {
|
||||
const values = [1, 2, 3, 4, 5];
|
||||
const source = asyncGenerator(values, 10);
|
||||
const onError = jest.fn();
|
||||
const onError = vi.fn();
|
||||
|
||||
const lg = new ListenableGenerator<number>(
|
||||
source,
|
||||
|
|
@ -131,7 +131,7 @@ describe("ListenableGenerator", () => {
|
|||
}
|
||||
|
||||
const source = errorGenerator();
|
||||
const onError = jest.fn();
|
||||
const onError = vi.fn();
|
||||
|
||||
const lg = new ListenableGenerator<number>(
|
||||
source,
|
||||
|
|
@ -152,7 +152,7 @@ describe("ListenableGenerator", () => {
|
|||
it("should notify listeners when the generator ends", async () => {
|
||||
const values = [1, 2, 3];
|
||||
const source = asyncGenerator(values);
|
||||
const onError = jest.fn();
|
||||
const onError = vi.fn();
|
||||
|
||||
const lg = new ListenableGenerator<number>(
|
||||
source,
|
||||
|
|
@ -160,7 +160,7 @@ describe("ListenableGenerator", () => {
|
|||
new AbortController(),
|
||||
);
|
||||
|
||||
const listener = jest.fn();
|
||||
const listener = vi.fn();
|
||||
lg.listen(listener);
|
||||
|
||||
// Wait for the generator to finish
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
import { jest } from "@jest/globals";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { stopAfterMaxProcessingTime } from "./utils";
|
||||
|
||||
describe("stopAfterMaxProcessingTime", () => {
|
||||
beforeEach(() => {
|
||||
jest.useFakeTimers();
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.useRealTimers();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
async function* createMockStream(chunks: string[]): AsyncGenerator<string> {
|
||||
|
|
@ -28,7 +28,7 @@ describe("stopAfterMaxProcessingTime", () => {
|
|||
|
||||
it("should yield all chunks when maxTimeMs is not reached", async () => {
|
||||
const mockStream = createMockStream(["Hello", " world", "!"]);
|
||||
const fullStop = jest.fn();
|
||||
const fullStop = vi.fn();
|
||||
const result = stopAfterMaxProcessingTime(mockStream, 1000, fullStop);
|
||||
|
||||
const output = await streamToString(result);
|
||||
|
|
@ -37,11 +37,11 @@ describe("stopAfterMaxProcessingTime", () => {
|
|||
expect(fullStop).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.only("should stop processing after max time is reached", async () => {
|
||||
it("should stop processing after max time is reached", async () => {
|
||||
// Mock implementation of Date.now
|
||||
let currentTime = 0;
|
||||
const originalDateNow = Date.now;
|
||||
Date.now = jest.fn(() => currentTime);
|
||||
Date.now = vi.fn(() => currentTime);
|
||||
|
||||
// Create a generator that we can control
|
||||
async function* controlledGenerator(): AsyncGenerator<string> {
|
||||
|
|
@ -54,7 +54,7 @@ describe("stopAfterMaxProcessingTime", () => {
|
|||
}
|
||||
}
|
||||
|
||||
const fullStop = jest.fn();
|
||||
const fullStop = vi.fn();
|
||||
const maxTimeMs = 500;
|
||||
|
||||
const transformedGenerator = stopAfterMaxProcessingTime(
|
||||
|
|
@ -84,10 +84,10 @@ describe("stopAfterMaxProcessingTime", () => {
|
|||
it("should check time only periodically based on checkInterval", async () => {
|
||||
const chunks = Array(100).fill("x");
|
||||
const mockStream = createMockStream(chunks);
|
||||
const fullStop = jest.fn();
|
||||
const fullStop = vi.fn();
|
||||
|
||||
// Spy on Date.now to count how many times it's called
|
||||
const dateSpy = jest.spyOn(Date, "now");
|
||||
const dateSpy = vi.spyOn(Date, "now");
|
||||
|
||||
// Stream should complete normally (not hitting the timeout)
|
||||
await streamToString(
|
||||
|
|
@ -105,7 +105,7 @@ describe("stopAfterMaxProcessingTime", () => {
|
|||
|
||||
it("should handle empty stream gracefully", async () => {
|
||||
const mockStream = createMockStream([]);
|
||||
const fullStop = jest.fn();
|
||||
const fullStop = vi.fn();
|
||||
const result = stopAfterMaxProcessingTime(mockStream, 1000, fullStop);
|
||||
|
||||
const output = await streamToString(result);
|
||||
|
|
@ -117,7 +117,7 @@ describe("stopAfterMaxProcessingTime", () => {
|
|||
it("should pass through all chunks if there's no timeout", async () => {
|
||||
const chunks = Array(100).fill("test chunk");
|
||||
const mockStream = createMockStream(chunks);
|
||||
const fullStop = jest.fn();
|
||||
const fullStop = vi.fn();
|
||||
|
||||
// Use undefined as timeout to simulate no timeout
|
||||
const result = stopAfterMaxProcessingTime(
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import { beforeEach, expect, test, vi } from "vitest";
|
||||
import { GitDiffCache } from "./gitDiffCache";
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
@ -7,7 +8,7 @@ beforeEach(() => {
|
|||
|
||||
test("GitDiffCache returns cached results within cache time", async () => {
|
||||
const mockDiff = ["file1.ts", "file2.ts"];
|
||||
const getDiffFn = jest.fn().mockResolvedValue(mockDiff);
|
||||
const getDiffFn = vi.fn().mockResolvedValue(mockDiff);
|
||||
const cache = GitDiffCache.getInstance(getDiffFn, 1); // 1 second cache
|
||||
|
||||
const result1 = await cache.get();
|
||||
|
|
@ -20,7 +21,7 @@ test("GitDiffCache returns cached results within cache time", async () => {
|
|||
|
||||
test("GitDiffCache refreshes cache after expiration", async () => {
|
||||
const mockDiff = ["file1.ts"];
|
||||
const getDiffFn = jest.fn().mockResolvedValue(mockDiff);
|
||||
const getDiffFn = vi.fn().mockResolvedValue(mockDiff);
|
||||
const cache = GitDiffCache.getInstance(getDiffFn, 0.1); // 100ms cache
|
||||
|
||||
const result1 = await cache.get();
|
||||
|
|
@ -31,7 +32,7 @@ test("GitDiffCache refreshes cache after expiration", async () => {
|
|||
});
|
||||
|
||||
test("GitDiffCache returns empty array on error", async () => {
|
||||
const getDiffFn = jest.fn().mockRejectedValue(new Error("Git error"));
|
||||
const getDiffFn = vi.fn().mockRejectedValue(new Error("Git error"));
|
||||
const cache = GitDiffCache.getInstance(getDiffFn);
|
||||
|
||||
const result = await cache.get();
|
||||
|
|
@ -41,7 +42,7 @@ test("GitDiffCache returns empty array on error", async () => {
|
|||
test("GitDiffCache reuses pending request", async () => {
|
||||
const mockDiff = ["file1.ts"];
|
||||
let resolvePromise: (value: string[]) => void;
|
||||
const getDiffFn = jest.fn().mockImplementation(() => {
|
||||
const getDiffFn = vi.fn().mockImplementation(() => {
|
||||
return new Promise((resolve) => {
|
||||
resolvePromise = resolve;
|
||||
});
|
||||
|
|
@ -63,7 +64,7 @@ test("GitDiffCache reuses pending request", async () => {
|
|||
|
||||
test("GitDiffCache invalidate clears cache", async () => {
|
||||
const mockDiff = ["file1.ts"];
|
||||
const getDiffFn = jest.fn().mockResolvedValue(mockDiff);
|
||||
const getDiffFn = vi.fn().mockResolvedValue(mockDiff);
|
||||
const cache = GitDiffCache.getInstance(getDiffFn);
|
||||
|
||||
await cache.get();
|
||||
|
|
@ -74,8 +75,8 @@ test("GitDiffCache invalidate clears cache", async () => {
|
|||
});
|
||||
|
||||
test("GitDiffCache maintains singleton instance", () => {
|
||||
const getDiffFn1 = jest.fn();
|
||||
const getDiffFn2 = jest.fn();
|
||||
const getDiffFn1 = vi.fn();
|
||||
const getDiffFn2 = vi.fn();
|
||||
|
||||
const instance1 = GitDiffCache.getInstance(getDiffFn1);
|
||||
const instance2 = GitDiffCache.getInstance(getDiffFn2);
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
import { describe, expect, test } from "vitest";
|
||||
import {
|
||||
AutocompleteCodeSnippet,
|
||||
AutocompleteDiffSnippet,
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
processTestCase,
|
||||
type CompletionTestCase,
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { processTestCase } from "./completionTestUtils";
|
||||
import { processSingleLineCompletion } from "./processSingleLineCompletion";
|
||||
|
||||
|
|
@ -1,3 +1 @@
|
|||
export * from "./createMarkdownRule";
|
||||
export * from "./loadMarkdownRules";
|
||||
export * from "./parseMarkdownRule";
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import { ConfigValidationError } from "@continuedev/config-yaml";
|
||||
import {
|
||||
ConfigValidationError,
|
||||
markdownToRule,
|
||||
} from "@continuedev/config-yaml";
|
||||
import { IDE, RuleWithSource } from "../..";
|
||||
import { walkDirs } from "../../indexing/walkDir";
|
||||
import { RULES_MARKDOWN_FILENAME } from "../../llm/rules/constants";
|
||||
import { getUriPathBasename } from "../../util/uri";
|
||||
import { convertMarkdownRuleToContinueRule } from "./parseMarkdownRule";
|
||||
|
||||
/**
|
||||
* Loads rules from rules.md files colocated in the codebase
|
||||
|
|
@ -29,9 +31,9 @@ export async function loadCodebaseRules(ide: IDE): Promise<{
|
|||
for (const filePath of rulesMdFiles) {
|
||||
try {
|
||||
const content = await ide.readFile(filePath);
|
||||
const rule = convertMarkdownRuleToContinueRule(filePath, content);
|
||||
const rule = markdownToRule(content, { uriType: "file", filePath });
|
||||
|
||||
rules.push(rule);
|
||||
rules.push({ ...rule, source: "rules-block" });
|
||||
} catch (e) {
|
||||
errors.push({
|
||||
fatal: false,
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
import { markdownToRule } from "@continuedev/config-yaml";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { IDE } from "../..";
|
||||
import { walkDirs } from "../../indexing/walkDir";
|
||||
import { loadCodebaseRules } from "./loadCodebaseRules";
|
||||
import { convertMarkdownRuleToContinueRule } from "./parseMarkdownRule";
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock("../../indexing/walkDir", () => ({
|
||||
walkDirs: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("./parseMarkdownRule", () => ({
|
||||
convertMarkdownRuleToContinueRule: vi.fn(),
|
||||
vi.mock("@continuedev/config-yaml", () => ({
|
||||
markdownToRule: vi.fn(),
|
||||
}));
|
||||
|
||||
describe("loadCodebaseRules", () => {
|
||||
|
|
@ -82,10 +82,10 @@ describe("loadCodebaseRules", () => {
|
|||
return Promise.resolve(mockRuleContent[path] || "");
|
||||
});
|
||||
|
||||
// Mock convertMarkdownRuleToContinueRule to return converted rules
|
||||
(convertMarkdownRuleToContinueRule as any).mockImplementation(
|
||||
(path: string, content: string) => {
|
||||
return mockConvertedRules[path];
|
||||
// Mock markdownToRule to return converted rules
|
||||
(markdownToRule as any).mockImplementation(
|
||||
(content: string, options: any) => {
|
||||
return mockConvertedRules[options.filePath];
|
||||
},
|
||||
);
|
||||
});
|
||||
|
|
@ -107,7 +107,7 @@ describe("loadCodebaseRules", () => {
|
|||
expect(mockIde.readFile).toHaveBeenCalledWith(".continue/rules.md");
|
||||
|
||||
// Should convert all rules
|
||||
expect(convertMarkdownRuleToContinueRule).toHaveBeenCalledTimes(4);
|
||||
expect(markdownToRule).toHaveBeenCalledTimes(4);
|
||||
|
||||
// Should return all rules
|
||||
expect(rules).toHaveLength(4);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import { ConfigValidationError } from "@continuedev/config-yaml";
|
||||
import {
|
||||
ConfigValidationError,
|
||||
markdownToRule,
|
||||
} from "@continuedev/config-yaml";
|
||||
import { IDE, RuleWithSource } from "../..";
|
||||
import { getAllDotContinueDefinitionFiles } from "../loadLocalAssistants";
|
||||
import { convertMarkdownRuleToContinueRule } from "./parseMarkdownRule";
|
||||
|
||||
/**
|
||||
* Loads rules from markdown files in the .continue/rules directory
|
||||
|
|
@ -27,8 +29,11 @@ export async function loadMarkdownRules(ide: IDE): Promise<{
|
|||
// Process each markdown file
|
||||
for (const file of mdFiles) {
|
||||
try {
|
||||
const rule = convertMarkdownRuleToContinueRule(file.path, file.content);
|
||||
rules.push(rule);
|
||||
const rule = markdownToRule(file.content, {
|
||||
uriType: "file",
|
||||
filePath: file.path,
|
||||
});
|
||||
rules.push({ ...rule, source: "rules-block" });
|
||||
} catch (e) {
|
||||
errors.push({
|
||||
fatal: false,
|
||||
|
|
|
|||
|
|
@ -1,192 +0,0 @@
|
|||
import {
|
||||
convertMarkdownRuleToContinueRule,
|
||||
parseMarkdownRule,
|
||||
} from "./parseMarkdownRule";
|
||||
|
||||
describe("parseMarkdownRule", () => {
|
||||
it("should correctly parse markdown with YAML frontmatter", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is a test rule.`;
|
||||
|
||||
const result = parseMarkdownRule(content);
|
||||
expect(result.frontmatter).toEqual({ globs: "**/test/**/*.kt" });
|
||||
expect(result.markdown).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
});
|
||||
|
||||
it("should handle missing frontmatter", () => {
|
||||
const content = `# Test Rule
|
||||
|
||||
This is a test rule without frontmatter.`;
|
||||
|
||||
const result = parseMarkdownRule(content);
|
||||
expect(result.frontmatter).toEqual({});
|
||||
expect(result.markdown).toBe(content);
|
||||
});
|
||||
|
||||
it("should handle empty frontmatter", () => {
|
||||
const content = `---
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is a test rule with empty frontmatter.`;
|
||||
|
||||
const result = parseMarkdownRule(content);
|
||||
|
||||
// Log exact strings for debugging
|
||||
console.log("Actual:", JSON.stringify(result.markdown));
|
||||
console.log(
|
||||
"Expected:",
|
||||
JSON.stringify(
|
||||
"# Test Rule\n\nThis is a test rule with empty frontmatter.",
|
||||
),
|
||||
);
|
||||
|
||||
expect(result.frontmatter).toEqual({});
|
||||
expect(result.markdown).toBe(
|
||||
"# Test Rule\n\nThis is a test rule with empty frontmatter.",
|
||||
);
|
||||
});
|
||||
|
||||
it("should handle frontmatter with whitespace", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is a test rule.`;
|
||||
|
||||
const result = parseMarkdownRule(content);
|
||||
expect(result.frontmatter).toEqual({ globs: "**/test/**/*.kt" });
|
||||
expect(result.markdown).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
});
|
||||
|
||||
it("should handle Windows line endings (CRLF)", () => {
|
||||
// Using \r\n for CRLF line endings
|
||||
const content = `---\r
|
||||
globs: "**/test/**/*.kt"\r
|
||||
---\r
|
||||
\r
|
||||
# Test Rule\r
|
||||
\r
|
||||
This is a test rule.`;
|
||||
|
||||
const result = parseMarkdownRule(content);
|
||||
expect(result.frontmatter).toEqual({ globs: "**/test/**/*.kt" });
|
||||
// The result should be normalized to \n
|
||||
expect(result.markdown).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
});
|
||||
|
||||
it("should handle malformed frontmatter", () => {
|
||||
const content = `---
|
||||
globs: - "**/test/**/*.kt"
|
||||
invalid: yaml: content
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is a test rule.`;
|
||||
|
||||
// Should treat as only markdown when frontmatter is malformed
|
||||
const result = parseMarkdownRule(content);
|
||||
expect(result.frontmatter).toEqual({});
|
||||
expect(result.markdown).toBe(content);
|
||||
});
|
||||
});
|
||||
|
||||
describe("convertMarkdownRuleToContinueRule", () => {
|
||||
it("should convert markdown with frontmatter to a rule", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
name: Custom Name
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is a test rule.`;
|
||||
|
||||
const result = convertMarkdownRuleToContinueRule(
|
||||
"/path/to/rule.md",
|
||||
content,
|
||||
);
|
||||
expect(result.rule).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
expect(result.globs).toBe("**/test/**/*.kt");
|
||||
expect(result.name).toBe("Custom Name");
|
||||
expect(result.source).toBe("rules-block");
|
||||
expect(result.ruleFile).toBe("/path/to/rule.md");
|
||||
});
|
||||
|
||||
it("should use the first heading as name if not in frontmatter", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
---
|
||||
|
||||
# Test Rule Title
|
||||
|
||||
This is a test rule.`;
|
||||
|
||||
const result = convertMarkdownRuleToContinueRule(
|
||||
"/path/to/rule.md",
|
||||
content,
|
||||
);
|
||||
expect(result.name).toBe("Test Rule Title");
|
||||
});
|
||||
|
||||
it("should use filename as name if no heading or frontmatter name", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
---
|
||||
|
||||
This is a test rule without a heading.`;
|
||||
|
||||
const result = convertMarkdownRuleToContinueRule(
|
||||
"/path/to/custom-rule.md",
|
||||
content,
|
||||
);
|
||||
expect(result.name).toBe("custom-rule");
|
||||
});
|
||||
|
||||
it("should include description from frontmatter", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
name: Test Rule
|
||||
description: This is a rule description from frontmatter
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is the content of the rule.`;
|
||||
|
||||
const result = convertMarkdownRuleToContinueRule(
|
||||
"/path/to/rule.md",
|
||||
content,
|
||||
);
|
||||
expect(result.description).toBe(
|
||||
"This is a rule description from frontmatter",
|
||||
);
|
||||
});
|
||||
|
||||
it("should include `alwaysApply` from frontmatter", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
name: Test Rule
|
||||
alwaysApply: false
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is a rule with alwaysApply explicitly set to false.`;
|
||||
|
||||
const result = convertMarkdownRuleToContinueRule(
|
||||
"/path/to/rule.md",
|
||||
content,
|
||||
);
|
||||
expect(result.alwaysApply).toBe(false);
|
||||
});
|
||||
});
|
||||
21
core/config/markdown/utils.ts
Normal file
21
core/config/markdown/utils.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import {
|
||||
RULE_FILE_EXTENSION,
|
||||
sanitizeRuleName,
|
||||
} from "@continuedev/config-yaml";
|
||||
import { joinPathsToUri } from "../../util/uri";
|
||||
|
||||
/**
|
||||
* Creates the file path for a rule in the workspace .continue/rules directory
|
||||
*/
|
||||
export function createRuleFilePath(
|
||||
workspaceDir: string,
|
||||
ruleName: string,
|
||||
): string {
|
||||
const safeRuleName = sanitizeRuleName(ruleName);
|
||||
return joinPathsToUri(
|
||||
workspaceDir,
|
||||
".continue",
|
||||
"rules",
|
||||
`${safeRuleName}.${RULE_FILE_EXTENSION}`,
|
||||
);
|
||||
}
|
||||
19
core/config/markdown/utils.vitest.ts
Normal file
19
core/config/markdown/utils.vitest.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { createRuleFilePath } from "./utils";
|
||||
|
||||
describe("createRuleFilePath", () => {
|
||||
it("should create correct rule file path", () => {
|
||||
const result = createRuleFilePath("/workspace", "My Test Rule");
|
||||
expect(result).toBe("/workspace/.continue/rules/my-test-rule.md");
|
||||
});
|
||||
|
||||
it("should handle special characters in rule name", () => {
|
||||
const result = createRuleFilePath("/home/user", "Rule with @#$% chars");
|
||||
expect(result).toBe("/home/user/.continue/rules/rule-with-chars.md");
|
||||
});
|
||||
|
||||
it("should handle edge case rule names", () => {
|
||||
const result = createRuleFilePath("/test", " Multiple Spaces ");
|
||||
expect(result).toBe("/test/.continue/rules/multiple-spaces.md");
|
||||
});
|
||||
});
|
||||
|
|
@ -211,6 +211,6 @@ export function migrateJsonSharedConfig(filepath: string, ide: IDE): void {
|
|||
new GlobalContext().updateSharedConfig(shareConfigUpdates);
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error(`Migration: Failed to parse config.json: ${e}`);
|
||||
console.error(`Migration: Failed to parse config.json: ${e}`);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
import { BlockType } from "@continuedev/config-yaml";
|
||||
import { BlockType, RULE_FILE_EXTENSION } from "@continuedev/config-yaml";
|
||||
import { describe, expect, test } from "@jest/globals";
|
||||
import { RULE_FILE_EXTENSION } from "../markdown";
|
||||
import { findAvailableFilename, getFileContent } from "./workspaceBlocks";
|
||||
|
||||
describe("getFileContent", () => {
|
||||
test("returns markdown content for rules block type", () => {
|
||||
const result = getFileContent("rules");
|
||||
expect(result).toContain("# New Rule");
|
||||
expect(result).toContain("Your rule content");
|
||||
expect(result).toContain("A description of your rule");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
import { BlockType, ConfigYaml } from "@continuedev/config-yaml";
|
||||
import {
|
||||
BlockType,
|
||||
ConfigYaml,
|
||||
createRuleMarkdown,
|
||||
RULE_FILE_EXTENSION,
|
||||
} from "@continuedev/config-yaml";
|
||||
import * as YAML from "yaml";
|
||||
import { IDE } from "../..";
|
||||
import { joinPathsToUri } from "../../util/uri";
|
||||
import { RULE_FILE_EXTENSION, createRuleMarkdown } from "../markdown";
|
||||
|
||||
const BLOCK_TYPE_CONFIG: Record<
|
||||
BlockType,
|
||||
|
|
|
|||
|
|
@ -123,7 +123,6 @@ describe("LocalPlatformClient", () => {
|
|||
expect(
|
||||
(resolvedFQSNs[0] as SecretResult & { value: unknown })?.value,
|
||||
).toBe(secretValue);
|
||||
console.log("debug1 resolved fqsn", resolvedFQSNs);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ async function loadConfigYaml(options: {
|
|||
rootPath,
|
||||
}),
|
||||
{
|
||||
renderSecrets: true,
|
||||
currentUserSlug: "",
|
||||
onPremProxyUrl: null,
|
||||
orgScopeId,
|
||||
|
|
@ -142,9 +143,7 @@ async function loadConfigYaml(options: {
|
|||
controlPlaneClient,
|
||||
ide,
|
||||
),
|
||||
renderSecrets: true,
|
||||
injectBlocks: allLocalBlocks,
|
||||
asConfigResult: true,
|
||||
},
|
||||
);
|
||||
config = unrollResult.config;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,5 @@ export default {
|
|||
globalSetup: "<rootDir>/test/jest.global-setup.ts",
|
||||
setupFilesAfterEnv: ["<rootDir>/test/jest.setup-after-env.js"],
|
||||
maxWorkers: 1, // equivalent to CLI --runInBand
|
||||
modulePathIgnorePatterns: [
|
||||
"<rootDir>/config/yaml/LocalPlatformClient.test.ts",
|
||||
],
|
||||
testMatch: ["**/*.test.ts"],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -161,12 +161,7 @@ function testLLM(
|
|||
group: "Hello",
|
||||
},
|
||||
],
|
||||
toolChoice: {
|
||||
type: "function",
|
||||
function: {
|
||||
name: "say_hello",
|
||||
},
|
||||
},
|
||||
toolChoice: { type: "function", function: { name: "say_hello" } },
|
||||
},
|
||||
)) {
|
||||
const typedChunk = chunk as AssistantChatMessage;
|
||||
|
|
@ -211,10 +206,7 @@ describe("LLM", () => {
|
|||
model: "claude-3-5-sonnet-latest",
|
||||
apiKey: process.env.ANTHROPIC_API_KEY,
|
||||
}),
|
||||
{
|
||||
skip: false,
|
||||
testToolCall: true,
|
||||
},
|
||||
{ skip: false, testToolCall: true },
|
||||
);
|
||||
testLLM(new OpenAI({ apiKey: process.env.OPENAI_API_KEY, model: "gpt-4o" }), {
|
||||
skip: false,
|
||||
|
|
@ -240,12 +232,7 @@ describe("LLM", () => {
|
|||
apiKey: process.env.MISTRAL_API_KEY,
|
||||
model: "codestral-latest",
|
||||
}),
|
||||
{
|
||||
testFim: true,
|
||||
skip: false,
|
||||
testToolCall: true,
|
||||
timeout: 60000,
|
||||
},
|
||||
{ testFim: true, skip: false, testToolCall: true, timeout: 60000 },
|
||||
);
|
||||
testLLM(
|
||||
new Azure({
|
||||
|
|
@ -260,11 +247,10 @@ describe("LLM", () => {
|
|||
);
|
||||
testLLM(
|
||||
new Azure({
|
||||
apiKey: process.env.AZURE_FOUNDRY_API_KEY,
|
||||
model: "codestral-latest",
|
||||
apiBase:
|
||||
"https://codestral-2501-continue-testing.eastus.models.ai.azure.com",
|
||||
apiType: "azure-foundry",
|
||||
apiKey: process.env.AZURE_FOUNDRY_CODESTRAL_API_KEY,
|
||||
model: "Codestral-2501",
|
||||
apiBase: "https://continue-foundry-resource.services.ai.azure.com",
|
||||
env: { apiType: "azure-foundry", apiVersion: "2024-05-01-preview" },
|
||||
}),
|
||||
{ testFim: false, skip: false, timeout: 20000 },
|
||||
);
|
||||
|
|
|
|||
11
core/test/vitest.global-setup.ts
Normal file
11
core/test/vitest.global-setup.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
// Sets up the GLOBAL directory for testing - equivalent to ~/.continue
|
||||
// IMPORTANT: the CONTINUE_GLOBAL_DIR environment variable is used in utils/paths for getting all local paths
|
||||
export default async function () {
|
||||
process.env.CONTINUE_GLOBAL_DIR = path.join(__dirname, ".continue-test");
|
||||
if (fs.existsSync(process.env.CONTINUE_GLOBAL_DIR)) {
|
||||
fs.rmdirSync(process.env.CONTINUE_GLOBAL_DIR, { recursive: true });
|
||||
}
|
||||
}
|
||||
16
core/test/vitest.setup.ts
Normal file
16
core/test/vitest.setup.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { TextDecoder, TextEncoder } from "util";
|
||||
|
||||
import fetch, { Request, Response } from "node-fetch";
|
||||
import { beforeAll } from "vitest";
|
||||
|
||||
beforeAll(() => {
|
||||
// @ts-ignore
|
||||
globalThis.fetch = fetch;
|
||||
// @ts-ignore
|
||||
globalThis.Request = Request;
|
||||
// @ts-ignore
|
||||
globalThis.Response = Response;
|
||||
globalThis.TextEncoder = TextEncoder;
|
||||
// @ts-ignore
|
||||
globalThis.TextDecoder = TextDecoder;
|
||||
});
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { parseMarkdownRule } from "@continuedev/config-yaml";
|
||||
import { jest } from "@jest/globals";
|
||||
import { parseMarkdownRule } from "../../config/markdown";
|
||||
import { createRuleBlockImpl } from "./createRuleBlock";
|
||||
|
||||
const mockIde = {
|
||||
|
|
@ -40,7 +40,6 @@ test("createRuleBlockImpl should create a rule with glob pattern", async () => {
|
|||
globs: "**/*.{ts,tsx}",
|
||||
});
|
||||
|
||||
expect(markdown).toContain("# TypeScript Rule");
|
||||
expect(markdown).toContain("Use interfaces for object shapes");
|
||||
});
|
||||
|
||||
|
|
@ -76,7 +75,6 @@ test("createRuleBlockImpl should create a rule with description pattern", async
|
|||
description: "This is a detailed explanation of the rule",
|
||||
});
|
||||
|
||||
expect(markdown).toContain("# Description Test");
|
||||
expect(markdown).toContain("This is the rule content");
|
||||
});
|
||||
|
||||
|
|
@ -100,7 +98,6 @@ test("createRuleBlockImpl should include both globs and description in frontmatt
|
|||
globs: "**/*.js",
|
||||
});
|
||||
|
||||
expect(markdown).toContain("# Complete Rule");
|
||||
expect(markdown).toContain("Follow this standard");
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { createRuleMarkdown } from "@continuedev/config-yaml";
|
||||
import { ToolImpl } from ".";
|
||||
import { RuleWithSource } from "../..";
|
||||
import { createRuleFilePath, createRuleMarkdown } from "../../config/markdown";
|
||||
import { createRuleFilePath } from "../../config/markdown/utils";
|
||||
|
||||
export type CreateRuleBlockArgs = Pick<
|
||||
Required<RuleWithSource>,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { ToolImpl } from ".";
|
||||
import { parseMarkdownRule } from "../../config/markdown/parseMarkdownRule";
|
||||
|
||||
export const requestRuleImpl: ToolImpl = async (args, extras) => {
|
||||
// Find the rule by name in the config
|
||||
|
|
@ -11,14 +10,11 @@ export const requestRuleImpl: ToolImpl = async (args, extras) => {
|
|||
);
|
||||
}
|
||||
|
||||
const fileContent = await extras.ide.readFile(rule.ruleFile);
|
||||
const { markdown, frontmatter } = parseMarkdownRule(fileContent);
|
||||
|
||||
return [
|
||||
{
|
||||
name: frontmatter.name ?? "",
|
||||
description: frontmatter.description ?? "",
|
||||
content: markdown,
|
||||
name: rule.name ?? "",
|
||||
description: rule.description ?? "",
|
||||
content: rule.rule,
|
||||
uri: {
|
||||
type: "file",
|
||||
value: rule.ruleFile,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
import { execSync } from "child_process";
|
||||
import { homedir } from "os";
|
||||
|
||||
/**
|
||||
* Gets the PATH env var from the user's login shell on non-Windows platforms.
|
||||
* Windows is not implemented primarily because it is not needed at the moment.
|
||||
* @returns The enhanced PATH from the user's shell, or the current PATH if it cannot be determined
|
||||
*/
|
||||
export function getEnvPathFromUserShell(): string | undefined {
|
||||
if (process.platform === "win32") {
|
||||
console.warn(`${getEnvPathFromUserShell.name} not implemented for Windows`);
|
||||
|
|
@ -16,7 +12,8 @@ export function getEnvPathFromUserShell(): string | undefined {
|
|||
}
|
||||
|
||||
try {
|
||||
const command = `${process.env.SHELL} -l -c 'echo $PATH'`;
|
||||
// Source common profile files
|
||||
const command = `${process.env.SHELL} -l -c 'for f in ~/.zprofile ~/.zshrc ~/.bash_profile ~/.bashrc; do [ -f "$f" ] && source "$f" 2>/dev/null; done; echo $PATH'`;
|
||||
|
||||
const stdout = execSync(command, {
|
||||
encoding: "utf8",
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ export async function getQueryForFile(
|
|||
}
|
||||
|
||||
const sourcePath = path.join(
|
||||
__dirname,
|
||||
process.env.NODE_ENV === "test" ? process.cwd() : __dirname,
|
||||
"..",
|
||||
...(process.env.NODE_ENV === "test"
|
||||
? ["extensions", "vscode", "tree-sitter"]
|
||||
|
|
@ -201,7 +201,7 @@ async function loadLanguageForFileExt(
|
|||
fileExtension: string,
|
||||
): Promise<Language> {
|
||||
const wasmPath = path.join(
|
||||
__dirname,
|
||||
process.env.NODE_ENV === "test" ? process.cwd() : __dirname,
|
||||
...(process.env.NODE_ENV === "test"
|
||||
? ["node_modules", "tree-sitter-wasms", "out"]
|
||||
: ["tree-sitter-wasms"]),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,13 @@ import { defineConfig } from "vitest/config";
|
|||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
testTransformMode: {
|
||||
web: ["/.[jt]s?$/"],
|
||||
ssr: ["/.[jt]s?$/"],
|
||||
},
|
||||
globalSetup: "./test/vitest.global-setup.ts",
|
||||
setupFiles: "./test/vitest.setup.ts",
|
||||
fileParallelism: false,
|
||||
include: ["**/*.vitest.ts"],
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import TabItem from "@theme/TabItem";
|
||||
import Tabs from "@theme/Tabs";
|
||||
|
||||
# vLLM
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ pluginGroup=com.github.continuedev.continueintellijextension
|
|||
pluginName=continue-intellij-extension
|
||||
pluginRepositoryUrl=https://github.com/continuedev/continue
|
||||
# SemVer format -> https://semver.org
|
||||
pluginVersion=1.0.23
|
||||
pluginVersion=1.0.24
|
||||
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
|
||||
pluginSinceBuild=223
|
||||
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
|
||||
|
|
|
|||
4
extensions/vscode/package-lock.json
generated
4
extensions/vscode/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "1.1.47",
|
||||
"version": "1.1.48",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "1.1.47",
|
||||
"version": "1.1.48",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.14",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"name": "continue",
|
||||
"icon": "media/icon.png",
|
||||
"author": "Continue Dev, Inc",
|
||||
"version": "1.1.48",
|
||||
"version": "1.1.49",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/continuedev/continue"
|
||||
|
|
|
|||
|
|
@ -183,7 +183,6 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable {
|
|||
|
||||
async refreshSessions() {
|
||||
try {
|
||||
debugger;
|
||||
await this._refreshSessions();
|
||||
} catch (e) {
|
||||
console.error(`Error refreshing sessions: ${e}`);
|
||||
|
|
|
|||
2
gui/package-lock.json
generated
2
gui/package-lock.json
generated
|
|
@ -214,7 +214,7 @@
|
|||
},
|
||||
"../packages/config-yaml": {
|
||||
"name": "@continuedev/config-yaml",
|
||||
"version": "1.0.88",
|
||||
"version": "1.0.92",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.14",
|
||||
|
|
|
|||
4
packages/config-yaml/package-lock.json
generated
4
packages/config-yaml/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@continuedev/config-yaml",
|
||||
"version": "1.0.88",
|
||||
"version": "1.0.92",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@continuedev/config-yaml",
|
||||
"version": "1.0.88",
|
||||
"version": "1.0.92",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.14",
|
||||
|
|
|
|||
|
|
@ -1,10 +1,17 @@
|
|||
{
|
||||
"name": "@continuedev/config-yaml",
|
||||
"version": "1.0.88",
|
||||
"version": "1.0.92",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"browser": "./dist/browser.js",
|
||||
"node": "./dist/index.js",
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"bin": {
|
||||
"@continuedev/config-yaml": "./dist/cli.js"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ describe("E2E Scenarios", () => {
|
|||
},
|
||||
);
|
||||
|
||||
expect(unrolledConfig.rules?.[0]).toBeNull();
|
||||
expect(unrolledConfig.config?.rules?.[0]).toBeNull();
|
||||
});
|
||||
|
||||
it("should correctly unroll assistant", async () => {
|
||||
|
|
@ -142,19 +142,21 @@ describe("E2E Scenarios", () => {
|
|||
},
|
||||
);
|
||||
|
||||
// Test that packages were correctly unrolled and params replaced
|
||||
expect(unrolledConfig.models?.length).toBe(4);
|
||||
const config = unrolledConfig.config;
|
||||
|
||||
const openAiModel = unrolledConfig.models?.[0]!;
|
||||
// Test that packages were correctly unrolled and params replaced
|
||||
expect(config?.models?.length).toBe(4);
|
||||
|
||||
const openAiModel = config?.models?.[0]!;
|
||||
expect(openAiModel.apiKey).toBe("sk-123");
|
||||
|
||||
const geminiModel = unrolledConfig.models?.[1]!;
|
||||
const geminiModel = config?.models?.[1]!;
|
||||
expect(geminiModel.provider).toBe("continue-proxy");
|
||||
expect(geminiModel.apiKey).toBeUndefined();
|
||||
const geminiSecretLocation = "organization:test-org/GEMINI_API_KEY";
|
||||
expect((geminiModel as any).apiKeyLocation).toBe(geminiSecretLocation);
|
||||
|
||||
const anthropicModel = unrolledConfig.models?.[2]!;
|
||||
const anthropicModel = config?.models?.[2]!;
|
||||
expect(anthropicModel.provider).toBe("continue-proxy");
|
||||
expect(anthropicModel.apiKey).toBeUndefined();
|
||||
const anthropicSecretLocation =
|
||||
|
|
@ -163,15 +165,15 @@ describe("E2E Scenarios", () => {
|
|||
anthropicSecretLocation,
|
||||
);
|
||||
|
||||
const proxyOllamaModel = unrolledConfig.models?.[3]!;
|
||||
const proxyOllamaModel = config?.models?.[3]!;
|
||||
expect(proxyOllamaModel.provider).toBe("ollama");
|
||||
expect(proxyOllamaModel.defaultCompletionOptions?.stream).toBe(false);
|
||||
|
||||
expect(unrolledConfig.rules?.length).toBe(2);
|
||||
expect(unrolledConfig.docs?.[0]?.startUrl).toBe(
|
||||
expect(config?.rules?.length).toBe(2);
|
||||
expect(config?.docs?.[0]?.startUrl).toBe(
|
||||
"https://docs.python.org/release/3.13.1",
|
||||
);
|
||||
expect(unrolledConfig.docs?.[0]?.rootUrl).toBe(
|
||||
expect(config?.docs?.[0]?.rootUrl).toBe(
|
||||
"https://docs.python.org/release/3.13.1",
|
||||
);
|
||||
|
||||
|
|
@ -242,16 +244,18 @@ describe("E2E Scenarios", () => {
|
|||
},
|
||||
);
|
||||
|
||||
const config = unrolledConfig.config;
|
||||
|
||||
// The original rules array should have two items
|
||||
expect(unrolledConfig.rules?.length).toBe(3); // Now 3 with the injected block
|
||||
expect(config?.rules?.length).toBe(3); // Now 3 with the injected block
|
||||
|
||||
// Check the original doc is still there
|
||||
expect(unrolledConfig.docs?.[0]?.startUrl).toBe(
|
||||
expect(config?.docs?.[0]?.startUrl).toBe(
|
||||
"https://docs.python.org/release/3.13.1",
|
||||
);
|
||||
|
||||
// Check the injected doc block was added
|
||||
expect(unrolledConfig.rules?.[2]).toBe("Be kind");
|
||||
expect(config?.rules?.[2]).toBe("Be kind");
|
||||
});
|
||||
|
||||
it.skip("should prioritize org over user / package secrets", () => {});
|
||||
|
|
|
|||
18
packages/config-yaml/src/browser.ts
Normal file
18
packages/config-yaml/src/browser.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// Browser-compatible exports (excludes RegistryClient which uses Node.js APIs)
|
||||
export * from "./converter.js";
|
||||
export * from "./interfaces/index.js";
|
||||
export * from "./interfaces/SecretResult.js";
|
||||
export * from "./interfaces/slugs.js";
|
||||
export * from "./load/clientRender.js";
|
||||
export * from "./load/getBlockType.js";
|
||||
export * from "./load/merge.js";
|
||||
export * from "./load/proxySecretResolution.js";
|
||||
export * from "./load/typeGuards.js";
|
||||
export * from "./load/unroll.js";
|
||||
export * from "./markdown/index.js";
|
||||
export * from "./modelName.js";
|
||||
// Note: registryClient.js is excluded because it uses Node.js fs/path APIs
|
||||
export * from "./schemas/data/index.js";
|
||||
export * from "./schemas/index.js";
|
||||
export * from "./schemas/models.js";
|
||||
export * from "./validation.js";
|
||||
|
|
@ -1,16 +1,2 @@
|
|||
export * from "./converter.js";
|
||||
export * from "./interfaces/index.js";
|
||||
export * from "./interfaces/SecretResult.js";
|
||||
export * from "./interfaces/slugs.js";
|
||||
export * from "./load/clientRender.js";
|
||||
export * from "./load/getBlockType.js";
|
||||
export * from "./load/merge.js";
|
||||
export * from "./load/proxySecretResolution.js";
|
||||
export * from "./load/typeGuards.js";
|
||||
export * from "./load/unroll.js";
|
||||
export * from "./modelName.js";
|
||||
export * from "./browser.js";
|
||||
export * from "./registryClient.js";
|
||||
export * from "./schemas/data/index.js";
|
||||
export * from "./schemas/index.js";
|
||||
export * from "./schemas/models.js";
|
||||
export * from "./validation.js";
|
||||
|
|
|
|||
|
|
@ -25,6 +25,15 @@ interface FileIdentifier extends BasePackageIdentifier {
|
|||
|
||||
export type PackageIdentifier = FullSlugIdentifier | FileIdentifier;
|
||||
|
||||
export function packageIdentifierToDisplayName(id: PackageIdentifier): string {
|
||||
switch (id.uriType) {
|
||||
case "file":
|
||||
return id.filePath;
|
||||
case "slug":
|
||||
return id.fullSlug.packageSlug;
|
||||
}
|
||||
}
|
||||
|
||||
export function encodePackageIdentifier(identifier: PackageIdentifier): string {
|
||||
switch (identifier.uriType) {
|
||||
case "slug":
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import {
|
|||
FQSN,
|
||||
PackageIdentifier,
|
||||
} from "../interfaces/slugs.js";
|
||||
import { markdownToRule } from "../markdown/index.js";
|
||||
import {
|
||||
AssistantUnrolled,
|
||||
assistantUnrolledSchema,
|
||||
|
|
@ -195,7 +196,6 @@ async function extractRenderedSecretsMap(
|
|||
export interface BaseUnrollAssistantOptions {
|
||||
renderSecrets: boolean;
|
||||
injectBlocks?: PackageIdentifier[];
|
||||
asConfigResult?: true;
|
||||
}
|
||||
|
||||
export interface DoNotRenderSecretsUnrollAssistantOptions
|
||||
|
|
@ -217,24 +217,11 @@ export type UnrollAssistantOptions =
|
|||
| DoNotRenderSecretsUnrollAssistantOptions
|
||||
| RenderSecretsUnrollAssistantOptions;
|
||||
|
||||
// Overload to satisfy existing consumers of unrollAssistant.
|
||||
export async function unrollAssistant(
|
||||
id: PackageIdentifier,
|
||||
registry: Registry,
|
||||
options: UnrollAssistantOptions & { asConfigResult: true },
|
||||
): Promise<ConfigResult<AssistantUnrolled>>;
|
||||
|
||||
export async function unrollAssistant(
|
||||
id: PackageIdentifier,
|
||||
registry: Registry,
|
||||
options: UnrollAssistantOptions,
|
||||
): Promise<AssistantUnrolled>;
|
||||
|
||||
export async function unrollAssistant(
|
||||
id: PackageIdentifier,
|
||||
registry: Registry,
|
||||
options: UnrollAssistantOptions,
|
||||
): Promise<AssistantUnrolled | ConfigResult<AssistantUnrolled>> {
|
||||
): Promise<ConfigResult<AssistantUnrolled>> {
|
||||
// Request the content from the registry
|
||||
const rawContent = await registry.getContent(id);
|
||||
|
||||
|
|
@ -265,24 +252,19 @@ export async function unrollAssistantFromContent(
|
|||
rawYaml: string,
|
||||
registry: Registry,
|
||||
options: UnrollAssistantOptions,
|
||||
): Promise<AssistantUnrolled | ConfigResult<AssistantUnrolled>> {
|
||||
): Promise<ConfigResult<AssistantUnrolled>> {
|
||||
// Parse string to Zod-validated YAML
|
||||
let parsedYaml = parseConfigYaml(rawYaml);
|
||||
|
||||
// Unroll blocks and convert their secrets to FQSNs
|
||||
const unrolledAssistant = await unrollBlocks(
|
||||
parsedYaml,
|
||||
registry,
|
||||
options.injectBlocks,
|
||||
options.asConfigResult ?? false,
|
||||
);
|
||||
const {
|
||||
config: unrolledAssistant,
|
||||
configLoadInterrupted,
|
||||
errors,
|
||||
} = await unrollBlocks(parsedYaml, registry, options.injectBlocks);
|
||||
|
||||
// Back to a string so we can fill in template variables
|
||||
const rawUnrolledYaml = options.asConfigResult
|
||||
? YAML.stringify(
|
||||
(unrolledAssistant as ConfigResult<AssistantUnrolled>).config,
|
||||
)
|
||||
: YAML.stringify(unrolledAssistant);
|
||||
const rawUnrolledYaml = YAML.stringify(unrolledAssistant);
|
||||
|
||||
// Convert all of the template variables to FQSNs
|
||||
// Secrets from the block will have the assistant slug prepended to the FQSN
|
||||
|
|
@ -291,7 +273,11 @@ export async function unrollAssistantFromContent(
|
|||
});
|
||||
|
||||
if (!options.renderSecrets) {
|
||||
return parseAssistantUnrolled(templatedYaml);
|
||||
return {
|
||||
config: parseAssistantUnrolled(templatedYaml),
|
||||
errors: [],
|
||||
configLoadInterrupted: false,
|
||||
};
|
||||
}
|
||||
|
||||
// Render secret values/locations for client
|
||||
|
|
@ -312,25 +298,18 @@ export async function unrollAssistantFromContent(
|
|||
options.onPremProxyUrl,
|
||||
);
|
||||
|
||||
if (options.asConfigResult) {
|
||||
return {
|
||||
config: finalConfig,
|
||||
errors: (unrolledAssistant as ConfigResult<AssistantUnrolled>).errors,
|
||||
configLoadInterrupted: (
|
||||
unrolledAssistant as ConfigResult<AssistantUnrolled>
|
||||
).configLoadInterrupted,
|
||||
};
|
||||
}
|
||||
|
||||
return finalConfig;
|
||||
return {
|
||||
config: finalConfig,
|
||||
errors,
|
||||
configLoadInterrupted,
|
||||
};
|
||||
}
|
||||
|
||||
export async function unrollBlocks(
|
||||
assistant: ConfigYaml,
|
||||
registry: Registry,
|
||||
injectBlocks: PackageIdentifier[] | undefined,
|
||||
asConfigError: boolean,
|
||||
): Promise<AssistantUnrolled | ConfigResult<AssistantUnrolled>> {
|
||||
): Promise<ConfigResult<AssistantUnrolled>> {
|
||||
const errors: ConfigValidationError[] = [];
|
||||
|
||||
const unrolledAssistant: AssistantUnrolled = {
|
||||
|
|
@ -432,7 +411,10 @@ export async function unrollBlocks(
|
|||
for (const injectBlock of injectBlocks ?? []) {
|
||||
try {
|
||||
const blockConfigYaml = await registry.getContent(injectBlock);
|
||||
const parsedBlock = parseConfigYaml(blockConfigYaml);
|
||||
const parsedBlock = parseMarkdownRuleOrConfigYaml(
|
||||
blockConfigYaml,
|
||||
injectBlock,
|
||||
);
|
||||
const blockType = getBlockType(parsedBlock);
|
||||
const resolvedBlock = await resolveBlock(
|
||||
injectBlock,
|
||||
|
|
@ -466,20 +448,16 @@ export async function unrollBlocks(
|
|||
}
|
||||
}
|
||||
|
||||
if (asConfigError) {
|
||||
const configResult: ConfigResult<AssistantUnrolled> = {
|
||||
config: undefined,
|
||||
errors: undefined,
|
||||
configLoadInterrupted: false,
|
||||
};
|
||||
configResult.config = unrolledAssistant;
|
||||
if (errors.length > 0) {
|
||||
configResult.errors = errors;
|
||||
}
|
||||
return configResult;
|
||||
const configResult: ConfigResult<AssistantUnrolled> = {
|
||||
config: undefined,
|
||||
errors: undefined,
|
||||
configLoadInterrupted: false,
|
||||
};
|
||||
configResult.config = unrolledAssistant;
|
||||
if (errors.length > 0) {
|
||||
configResult.errors = errors;
|
||||
}
|
||||
|
||||
return unrolledAssistant;
|
||||
return configResult;
|
||||
}
|
||||
|
||||
export async function resolveBlock(
|
||||
|
|
@ -503,7 +481,60 @@ export async function resolveBlock(
|
|||
secrets: extractFQSNMap(rawYaml, [id]),
|
||||
});
|
||||
|
||||
const parsedYaml = parseBlock(templatedYaml);
|
||||
return parseMarkdownRuleOrAssistantUnrolled(templatedYaml, id);
|
||||
}
|
||||
|
||||
function parseMarkdownRuleOrAssistantUnrolled(
|
||||
content: string,
|
||||
id: PackageIdentifier,
|
||||
): AssistantUnrolled {
|
||||
// Try to parse as YAML first, then as markdown rule if that fails
|
||||
let parsedYaml: AssistantUnrolled;
|
||||
try {
|
||||
parsedYaml = parseBlock(content);
|
||||
} catch (yamlError) {
|
||||
// If YAML parsing fails, try parsing as markdown rule
|
||||
try {
|
||||
const rule = markdownToRule(content, id);
|
||||
// Convert the rule object to the expected format
|
||||
parsedYaml = {
|
||||
name: rule.name,
|
||||
version: "1.0.0",
|
||||
rules: [rule],
|
||||
};
|
||||
} catch (markdownError) {
|
||||
// If both fail, throw the original YAML error
|
||||
throw yamlError;
|
||||
}
|
||||
}
|
||||
|
||||
return parsedYaml;
|
||||
}
|
||||
|
||||
function parseMarkdownRuleOrConfigYaml(
|
||||
content: string,
|
||||
id: PackageIdentifier,
|
||||
): ConfigYaml {
|
||||
// Try to parse as YAML first, then as markdown rule if that fails
|
||||
let parsedYaml: ConfigYaml;
|
||||
try {
|
||||
parsedYaml = parseConfigYaml(content);
|
||||
} catch (yamlError) {
|
||||
// If YAML parsing fails, try parsing as markdown rule
|
||||
try {
|
||||
const rule = markdownToRule(content, id);
|
||||
// Convert the rule object to the expected format
|
||||
parsedYaml = {
|
||||
name: rule.name,
|
||||
version: "1.0.0",
|
||||
rules: [rule],
|
||||
};
|
||||
} catch (markdownError) {
|
||||
// If both fail, throw the original YAML error
|
||||
throw yamlError;
|
||||
}
|
||||
}
|
||||
|
||||
return parsedYaml;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
import { PackageIdentifier } from "../browser.js";
|
||||
import {
|
||||
createMarkdownWithFrontmatter,
|
||||
createRuleFilePath,
|
||||
createRuleMarkdown,
|
||||
sanitizeRuleName,
|
||||
} from "./createMarkdownRule";
|
||||
import { parseMarkdownRule } from "./parseMarkdownRule";
|
||||
} from "./createMarkdownRule.js";
|
||||
import { markdownToRule } from "./markdownToRule.js";
|
||||
|
||||
// Mock package identifier for testing
|
||||
const mockPackageId: PackageIdentifier = {
|
||||
uriType: "file",
|
||||
filePath: "/path/to/file",
|
||||
};
|
||||
|
||||
describe("sanitizeRuleName", () => {
|
||||
it("should sanitize rule names for filenames", () => {
|
||||
|
|
@ -25,23 +31,6 @@ describe("sanitizeRuleName", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("createRuleFilePath", () => {
|
||||
it("should create correct rule file path", () => {
|
||||
const result = createRuleFilePath("/workspace", "My Test Rule");
|
||||
expect(result).toBe("/workspace/.continue/rules/my-test-rule.md");
|
||||
});
|
||||
|
||||
it("should handle special characters in rule name", () => {
|
||||
const result = createRuleFilePath("/home/user", "Rule with @#$% chars");
|
||||
expect(result).toBe("/home/user/.continue/rules/rule-with-chars.md");
|
||||
});
|
||||
|
||||
it("should handle edge case rule names", () => {
|
||||
const result = createRuleFilePath("/test", " Multiple Spaces ");
|
||||
expect(result).toBe("/test/.continue/rules/multiple-spaces.md");
|
||||
});
|
||||
});
|
||||
|
||||
describe("createMarkdownWithFrontmatter", () => {
|
||||
it("should create properly formatted markdown with frontmatter", () => {
|
||||
const frontmatter = {
|
||||
|
|
@ -92,10 +81,13 @@ Just markdown content.`;
|
|||
originalFrontmatter,
|
||||
originalMarkdown,
|
||||
);
|
||||
const parsed = parseMarkdownRule(created);
|
||||
const parsed = markdownToRule(created, mockPackageId);
|
||||
|
||||
expect(parsed.frontmatter).toEqual(originalFrontmatter);
|
||||
expect(parsed.markdown).toBe(originalMarkdown);
|
||||
expect(parsed.name).toBe(originalFrontmatter.name);
|
||||
expect(parsed.description).toBe(originalFrontmatter.description);
|
||||
expect(parsed.globs).toEqual(originalFrontmatter.globs);
|
||||
expect(parsed.alwaysApply).toBe(originalFrontmatter.alwaysApply);
|
||||
expect(parsed.rule).toBe(originalMarkdown);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -107,23 +99,23 @@ describe("createRuleMarkdown", () => {
|
|||
alwaysApply: true,
|
||||
});
|
||||
|
||||
const parsed = parseMarkdownRule(result);
|
||||
const parsed = markdownToRule(result, mockPackageId);
|
||||
|
||||
expect(parsed.frontmatter.description).toBe("Test description");
|
||||
expect(parsed.frontmatter.globs).toEqual(["*.ts", "*.js"]);
|
||||
expect(parsed.frontmatter.alwaysApply).toBe(true);
|
||||
expect(parsed.markdown).toBe("# Test Rule\n\nThis is the rule content");
|
||||
expect(parsed.description).toBe("Test description");
|
||||
expect(parsed.globs).toEqual(["*.ts", "*.js"]);
|
||||
expect(parsed.alwaysApply).toBe(true);
|
||||
expect(parsed.rule).toBe("This is the rule content");
|
||||
});
|
||||
|
||||
it("should create rule markdown with minimal options", () => {
|
||||
const result = createRuleMarkdown("Simple Rule", "Simple content");
|
||||
|
||||
const parsed = parseMarkdownRule(result);
|
||||
const parsed = markdownToRule(result, mockPackageId);
|
||||
|
||||
expect(parsed.frontmatter.description).toBeUndefined();
|
||||
expect(parsed.frontmatter.globs).toBeUndefined();
|
||||
expect(parsed.frontmatter.alwaysApply).toBeUndefined();
|
||||
expect(parsed.markdown).toBe("# Simple Rule\n\nSimple content");
|
||||
expect(parsed.description).toBeUndefined();
|
||||
expect(parsed.globs).toBeUndefined();
|
||||
expect(parsed.alwaysApply).toBeUndefined();
|
||||
expect(parsed.rule).toBe("Simple content");
|
||||
});
|
||||
|
||||
it("should handle string globs", () => {
|
||||
|
|
@ -131,8 +123,8 @@ describe("createRuleMarkdown", () => {
|
|||
globs: "*.py",
|
||||
});
|
||||
|
||||
const parsed = parseMarkdownRule(result);
|
||||
expect(parsed.frontmatter.globs).toBe("*.py");
|
||||
const parsed = markdownToRule(result, mockPackageId);
|
||||
expect(parsed.globs).toBe("*.py");
|
||||
});
|
||||
|
||||
it("should trim description and globs", () => {
|
||||
|
|
@ -141,9 +133,9 @@ describe("createRuleMarkdown", () => {
|
|||
globs: " *.ts ",
|
||||
});
|
||||
|
||||
const parsed = parseMarkdownRule(result);
|
||||
expect(parsed.frontmatter.description).toBe("spaced description");
|
||||
expect(parsed.frontmatter.globs).toBe("*.ts");
|
||||
const parsed = markdownToRule(result, mockPackageId);
|
||||
expect(parsed.description).toBe("spaced description");
|
||||
expect(parsed.globs).toBe("*.ts");
|
||||
});
|
||||
|
||||
it("should handle alwaysApply false explicitly", () => {
|
||||
|
|
@ -151,7 +143,7 @@ describe("createRuleMarkdown", () => {
|
|||
alwaysApply: false,
|
||||
});
|
||||
|
||||
const parsed = parseMarkdownRule(result);
|
||||
expect(parsed.frontmatter.alwaysApply).toBe(false);
|
||||
const parsed = markdownToRule(result, mockPackageId);
|
||||
expect(parsed.alwaysApply).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
import * as YAML from "yaml";
|
||||
import { joinPathsToUri } from "../../util/uri";
|
||||
import { RuleFrontmatter } from "./parseMarkdownRule";
|
||||
import { RuleFrontmatter } from "./markdownToRule.js";
|
||||
|
||||
export const RULE_FILE_EXTENSION = "md";
|
||||
|
||||
|
|
@ -15,22 +14,6 @@ export function sanitizeRuleName(name: string): string {
|
|||
.replace(/^-+|-+$/g, ""); // Remove leading/trailing dashes
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the file path for a rule in the workspace .continue/rules directory
|
||||
*/
|
||||
export function createRuleFilePath(
|
||||
workspaceDir: string,
|
||||
ruleName: string,
|
||||
): string {
|
||||
const safeRuleName = sanitizeRuleName(ruleName);
|
||||
return joinPathsToUri(
|
||||
workspaceDir,
|
||||
".continue",
|
||||
"rules",
|
||||
`${safeRuleName}.${RULE_FILE_EXTENSION}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates markdown content with YAML frontmatter in the format expected by parseMarkdownRule
|
||||
*/
|
||||
|
|
@ -69,7 +52,5 @@ export function createRuleMarkdown(
|
|||
frontmatter.alwaysApply = options.alwaysApply;
|
||||
}
|
||||
|
||||
const markdownBody = `# ${name}\n\n${ruleContent}`;
|
||||
|
||||
return createMarkdownWithFrontmatter(frontmatter, markdownBody);
|
||||
return createMarkdownWithFrontmatter(frontmatter, ruleContent);
|
||||
}
|
||||
2
packages/config-yaml/src/markdown/index.ts
Normal file
2
packages/config-yaml/src/markdown/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export * from "./createMarkdownRule.js";
|
||||
export * from "./markdownToRule.js";
|
||||
173
packages/config-yaml/src/markdown/markdownToRule.test.ts
Normal file
173
packages/config-yaml/src/markdown/markdownToRule.test.ts
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
import { PackageIdentifier } from "../browser.js";
|
||||
import { markdownToRule } from "./markdownToRule.js";
|
||||
|
||||
describe("markdownToRule", () => {
|
||||
// Use a mock PackageIdentifier for testing
|
||||
const mockId: PackageIdentifier = {
|
||||
uriType: "file",
|
||||
filePath: "/path/to/file",
|
||||
};
|
||||
|
||||
it("should convert markdown with frontmatter to a rule", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
name: Custom Name
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is a test rule.`;
|
||||
|
||||
const result = markdownToRule(content, mockId);
|
||||
expect(result.rule).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
expect(result.globs).toBe("**/test/**/*.kt");
|
||||
expect(result.name).toBe("Custom Name");
|
||||
});
|
||||
|
||||
it("should correctly parse markdown with YAML frontmatter", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is a test rule.`;
|
||||
|
||||
const result = markdownToRule(content, mockId);
|
||||
expect(result.globs).toBe("**/test/**/*.kt");
|
||||
expect(result.rule).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
expect(result.name).toBe("/path/to/file"); // Should use packageIdentifierToDisplayName result
|
||||
});
|
||||
|
||||
it("should handle missing frontmatter", () => {
|
||||
const content = `# Test Rule
|
||||
|
||||
This is a test rule without frontmatter.`;
|
||||
|
||||
const result = markdownToRule(content, mockId);
|
||||
expect(result.globs).toBeUndefined();
|
||||
expect(result.rule).toBe(content);
|
||||
expect(result.name).toBe("/path/to/file"); // Should use packageIdentifierToDisplayName result
|
||||
});
|
||||
|
||||
it("should handle empty frontmatter", () => {
|
||||
const content = `---
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is a test rule with empty frontmatter.`;
|
||||
|
||||
const result = markdownToRule(content, mockId);
|
||||
expect(result.globs).toBeUndefined();
|
||||
expect(result.rule).toBe(
|
||||
"# Test Rule\n\nThis is a test rule with empty frontmatter.",
|
||||
);
|
||||
expect(result.name).toBe("/path/to/file"); // Should use packageIdentifierToDisplayName result
|
||||
});
|
||||
|
||||
it("should handle frontmatter with whitespace", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is a test rule.`;
|
||||
|
||||
const result = markdownToRule(content, mockId);
|
||||
expect(result.globs).toBe("**/test/**/*.kt");
|
||||
expect(result.rule).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
expect(result.name).toBe("/path/to/file"); // Should use packageIdentifierToDisplayName result
|
||||
});
|
||||
|
||||
it("should handle Windows line endings (CRLF)", () => {
|
||||
// Using \r\n for CRLF line endings
|
||||
const content = `---\r
|
||||
globs: "**/test/**/*.kt"\r
|
||||
---\r
|
||||
\r
|
||||
# Test Rule\r
|
||||
\r
|
||||
This is a test rule.`;
|
||||
|
||||
const result = markdownToRule(content, mockId);
|
||||
expect(result.globs).toBe("**/test/**/*.kt");
|
||||
// The result should be normalized to \n
|
||||
expect(result.rule).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
expect(result.name).toBe("/path/to/file"); // Should use packageIdentifierToDisplayName result
|
||||
});
|
||||
|
||||
it("should handle malformed frontmatter", () => {
|
||||
const content = `---
|
||||
globs: - "**/test/**/*.kt"
|
||||
invalid: yaml: content
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is a test rule.`;
|
||||
|
||||
// Should treat as only markdown when frontmatter is malformed
|
||||
const result = markdownToRule(content, mockId);
|
||||
expect(result.globs).toBeUndefined();
|
||||
expect(result.rule).toBe(content);
|
||||
expect(result.name).toBe("/path/to/file"); // Should use packageIdentifierToDisplayName result
|
||||
});
|
||||
|
||||
it("should use packageIdentifierToDisplayName if no heading or frontmatter name", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
---
|
||||
|
||||
# Test Rule Title
|
||||
|
||||
This is a test rule.`;
|
||||
|
||||
const result = markdownToRule(content, mockId);
|
||||
expect(result.name).toBe("/path/to/file"); // Should use packageIdentifierToDisplayName result
|
||||
});
|
||||
|
||||
it("should use packageIdentifierToDisplayName if no heading or frontmatter name (no heading)", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
---
|
||||
|
||||
This is a test rule without a heading.`;
|
||||
|
||||
const result = markdownToRule(content, mockId);
|
||||
expect(result.name).toBe("/path/to/file"); // Should use packageIdentifierToDisplayName result
|
||||
});
|
||||
|
||||
it("should include description from frontmatter", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
name: Test Rule
|
||||
description: This is a rule description from frontmatter
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is the content of the rule.`;
|
||||
|
||||
const result = markdownToRule(content, mockId);
|
||||
expect(result.description).toBe(
|
||||
"This is a rule description from frontmatter",
|
||||
);
|
||||
});
|
||||
|
||||
it("should include alwaysApply from frontmatter", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
name: Test Rule
|
||||
alwaysApply: false
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is a rule with alwaysApply explicitly set to false.`;
|
||||
|
||||
const result = markdownToRule(content, mockId);
|
||||
expect(result.alwaysApply).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,12 +1,15 @@
|
|||
import { basename } from "path";
|
||||
import * as YAML from "yaml";
|
||||
import { RuleWithSource } from "../..";
|
||||
import {
|
||||
PackageIdentifier,
|
||||
packageIdentifierToDisplayName,
|
||||
} from "../browser.js";
|
||||
import { RuleObject } from "../schemas/index.js";
|
||||
|
||||
export interface RuleFrontmatter {
|
||||
globs?: RuleWithSource["globs"];
|
||||
name?: RuleWithSource["name"];
|
||||
description?: RuleWithSource["description"];
|
||||
alwaysApply?: RuleWithSource["alwaysApply"];
|
||||
globs?: RuleObject["globs"];
|
||||
name?: RuleObject["name"];
|
||||
description?: RuleObject["description"];
|
||||
alwaysApply?: RuleObject["alwaysApply"];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -43,35 +46,17 @@ export function parseMarkdownRule(content: string): {
|
|||
return { frontmatter: {}, markdown: normalizedContent };
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a markdown file with YAML frontmatter to a RuleWithSource object
|
||||
*/
|
||||
export function convertMarkdownRuleToContinueRule(
|
||||
path: string,
|
||||
content: string,
|
||||
): RuleWithSource {
|
||||
const { frontmatter, markdown } = parseMarkdownRule(content);
|
||||
|
||||
// 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$/, "");
|
||||
}
|
||||
}
|
||||
export function markdownToRule(
|
||||
rule: string,
|
||||
id: PackageIdentifier,
|
||||
): RuleObject {
|
||||
const { frontmatter, markdown } = parseMarkdownRule(rule);
|
||||
|
||||
return {
|
||||
name,
|
||||
name: frontmatter.name ?? packageIdentifierToDisplayName(id),
|
||||
rule: markdown,
|
||||
globs: frontmatter.globs,
|
||||
description: frontmatter.description,
|
||||
alwaysApply: frontmatter.alwaysApply,
|
||||
source: "rules-block",
|
||||
ruleFile: path,
|
||||
};
|
||||
}
|
||||
|
|
@ -39,6 +39,7 @@ const docSchema = z.object({
|
|||
});
|
||||
|
||||
export type DocsConfig = z.infer<typeof docSchema>;
|
||||
|
||||
const ruleObjectSchema = z.object({
|
||||
name: z.string(),
|
||||
rule: z.string(),
|
||||
|
|
@ -48,8 +49,23 @@ const ruleObjectSchema = z.object({
|
|||
});
|
||||
const ruleSchema = z.union([z.string(), ruleObjectSchema]);
|
||||
|
||||
/**
|
||||
* A schema for rules.json files
|
||||
*/
|
||||
export const rulesJsonSchema = z.object({
|
||||
name: z.string(),
|
||||
version: z.string(),
|
||||
author: z.string().optional(),
|
||||
license: z.string().optional(),
|
||||
rules: z.record(z.string(), z.string()).optional(),
|
||||
});
|
||||
|
||||
export type Rule = z.infer<typeof ruleSchema>;
|
||||
export type RuleObject = z.infer<typeof ruleObjectSchema>;
|
||||
/**
|
||||
* A schema for rules.json files
|
||||
*/
|
||||
export type RulesJson = z.infer<typeof rulesJsonSchema>;
|
||||
|
||||
const defaultUsesSchema = z.string();
|
||||
|
||||
|
|
|
|||
6405
packages/continue-sdk/package-lock.json
generated
6405
packages/continue-sdk/package-lock.json
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue