Elffuss BraidHub

kikocis/continue public

fix: type errors / formatting
Changesetb6f6b229557f4a66c71a4e764b6bc7bd210bd78504b65e6319e7d8169dd59232
AuthorTomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-06-09 16:07 -07:00
CommitterTomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-06-09 17:11 -07:00
Parents456405ec0111

Browse the files at this changeset

6 files changed

modified core/config/markdown/loadCodebaseRules.vitest.ts +93 −85
@@ -1,153 +1,161 @@
1-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2-import { loadCodebaseRules } from './loadCodebaseRules';
3-import { walkDirs } from '../../indexing/walkDir';
4-import { IDE } from '../..';
5-import { convertMarkdownRuleToContinueRule } from './parseMarkdownRule';
1+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2+import { IDE } from "../..";
3+import { walkDirs } from "../../indexing/walkDir";
4+import { loadCodebaseRules } from "./loadCodebaseRules";
5+import { convertMarkdownRuleToContinueRule } from "./parseMarkdownRule";
66
77 // Mock dependencies
8-vi.mock('../../indexing/walkDir', () => ({
8+vi.mock("../../indexing/walkDir", () => ({
99 walkDirs: vi.fn(),
1010 }));
1111
12-vi.mock('./parseMarkdownRule', () => ({
12+vi.mock("./parseMarkdownRule", () => ({
1313 convertMarkdownRuleToContinueRule: vi.fn(),
1414 }));
1515
16-describe('loadCodebaseRules', () => {
17- // Mock IDE
16+describe("loadCodebaseRules", () => {
17+ // Mock IDE with properly typed mock functions
1818 const mockIde = {
19- readFile: vi.fn(),
19+ readFile: vi.fn() as unknown as IDE["readFile"] & {
20+ mockImplementation: Function;
21+ },
2022 } as unknown as IDE;
2123
2224 // Setup test files
2325 const mockFiles = [
24- 'src/rules.md',
25- 'src/redux/rules.md',
26- 'src/components/rules.md',
27- 'src/utils/helper.ts', // Non-rules file
28- '.continue/rules.md', // This should also be loaded
26+ "src/rules.md",
27+ "src/redux/rules.md",
28+ "src/components/rules.md",
29+ "src/utils/helper.ts", // Non-rules file
30+ ".continue/rules.md", // This should also be loaded
2931 ];
3032
3133 // Mock rule content
32- const mockRuleContent = {
33- 'src/rules.md': '# General Rules\nFollow coding standards',
34- 'src/redux/rules.md': '---\nglobs: "**/*.{ts,tsx}"\n---\n# Redux Rules\nUse Redux Toolkit',
35- 'src/components/rules.md': '---\nglobs: ["**/*.tsx", "**/*.jsx"]\n---\n# Component Rules\nUse functional components',
36- '.continue/rules.md': '# Global Rules\nFollow project guidelines',
34+ const mockRuleContent: Record<string, string> = {
35+ "src/rules.md": "# General Rules\nFollow coding standards",
36+ "src/redux/rules.md":
37+ '---\nglobs: "**/*.{ts,tsx}"\n---\n# Redux Rules\nUse Redux Toolkit',
38+ "src/components/rules.md":
39+ '---\nglobs: ["**/*.tsx", "**/*.jsx"]\n---\n# Component Rules\nUse functional components',
40+ ".continue/rules.md": "# Global Rules\nFollow project guidelines",
3741 };
3842
3943 // Mock converted rules
40- const mockConvertedRules = {
41- 'src/rules.md': {
42- name: 'General Rules',
43- rule: 'Follow coding standards',
44- source: 'rules-block',
45- ruleFile: 'src/rules.md',
44+ const mockConvertedRules: Record<string, any> = {
45+ "src/rules.md": {
46+ name: "General Rules",
47+ rule: "Follow coding standards",
48+ source: "rules-block",
49+ ruleFile: "src/rules.md",
4650 },
47- 'src/redux/rules.md': {
48- name: 'Redux Rules',
49- rule: 'Use Redux Toolkit',
50- globs: '**/*.{ts,tsx}',
51- source: 'rules-block',
52- ruleFile: 'src/redux/rules.md',
51+ "src/redux/rules.md": {
52+ name: "Redux Rules",
53+ rule: "Use Redux Toolkit",
54+ globs: "**/*.{ts,tsx}",
55+ source: "rules-block",
56+ ruleFile: "src/redux/rules.md",
5357 },
54- 'src/components/rules.md': {
55- name: 'Component Rules',
56- rule: 'Use functional components',
57- globs: ['**/*.tsx', '**/*.jsx'],
58- source: 'rules-block',
59- ruleFile: 'src/components/rules.md',
58+ "src/components/rules.md": {
59+ name: "Component Rules",
60+ rule: "Use functional components",
61+ globs: ["**/*.tsx", "**/*.jsx"],
62+ source: "rules-block",
63+ ruleFile: "src/components/rules.md",
6064 },
61- '.continue/rules.md': {
62- name: 'Global Rules',
63- rule: 'Follow project guidelines',
64- source: 'rules-block',
65- ruleFile: '.continue/rules.md',
65+ ".continue/rules.md": {
66+ name: "Global Rules",
67+ rule: "Follow project guidelines",
68+ source: "rules-block",
69+ ruleFile: ".continue/rules.md",
6670 },
6771 };
6872
6973 beforeEach(() => {
7074 // Setup mocks
7175 vi.resetAllMocks();
72-
76+
7377 // Mock walkDirs to return our test files
7478 (walkDirs as any).mockResolvedValue(mockFiles);
75-
79+
7680 // Mock readFile to return content based on path
77- mockIde.readFile.mockImplementation((path: string) => {
78- return Promise.resolve(mockRuleContent[path] || '');
81+ (mockIde.readFile as any).mockImplementation((path: string) => {
82+ return Promise.resolve(mockRuleContent[path] || "");
7983 });
80-
84+
8185 // Mock convertMarkdownRuleToContinueRule to return converted rules
82- (convertMarkdownRuleToContinueRule as any).mockImplementation((path: string, content: string) => {
83- return mockConvertedRules[path];
84- });
86+ (convertMarkdownRuleToContinueRule as any).mockImplementation(
87+ (path: string, content: string) => {
88+ return mockConvertedRules[path];
89+ },
90+ );
8591 });
8692
8793 afterEach(() => {
8894 vi.resetAllMocks();
8995 });
90-
91- it('should load rules from all rules.md files in the workspace', async () => {
96+ it("should load rules from all rules.md files in the workspace", async () => {
9297 const { rules, errors } = await loadCodebaseRules(mockIde);
93-
98+
9499 // Should find all rules.md files
95100 expect(walkDirs).toHaveBeenCalledWith(mockIde);
96-
101+
97102 // Should read all rules.md files
98103 expect(mockIde.readFile).toHaveBeenCalledTimes(4);
99- expect(mockIde.readFile).toHaveBeenCalledWith('src/rules.md');
100- expect(mockIde.readFile).toHaveBeenCalledWith('src/redux/rules.md');
101- expect(mockIde.readFile).toHaveBeenCalledWith('src/components/rules.md');
102- expect(mockIde.readFile).toHaveBeenCalledWith('.continue/rules.md');
103-
104+ expect(mockIde.readFile).toHaveBeenCalledWith("src/rules.md");
105+ expect(mockIde.readFile).toHaveBeenCalledWith("src/redux/rules.md");
106+ expect(mockIde.readFile).toHaveBeenCalledWith("src/components/rules.md");
107+ expect(mockIde.readFile).toHaveBeenCalledWith(".continue/rules.md");
108+
104109 // Should convert all rules
105110 expect(convertMarkdownRuleToContinueRule).toHaveBeenCalledTimes(4);
106-
111+
107112 // Should return all rules
108113 expect(rules).toHaveLength(4);
109- expect(rules).toContainEqual(mockConvertedRules['src/rules.md']);
110- expect(rules).toContainEqual(mockConvertedRules['src/redux/rules.md']);
111- expect(rules).toContainEqual(mockConvertedRules['src/components/rules.md']);
112- expect(rules).toContainEqual(mockConvertedRules['.continue/rules.md']);
113-
114+ expect(rules).toContainEqual(mockConvertedRules["src/rules.md"]);
115+ expect(rules).toContainEqual(mockConvertedRules["src/redux/rules.md"]);
116+ expect(rules).toContainEqual(mockConvertedRules["src/components/rules.md"]);
117+ expect(rules).toContainEqual(mockConvertedRules[".continue/rules.md"]);
118+
114119 // Should not have errors
115120 expect(errors).toHaveLength(0);
116121 });
117122
118- it('should handle errors when reading a rule file', async () => {
123+ it("should handle errors when reading a rule file", async () => {
119124 // Setup mock to throw for a specific file
120- mockIde.readFile.mockImplementation((path: string) => {
121- if (path === 'src/redux/rules.md') {
122- return Promise.reject(new Error('Failed to read file'));
125+ (mockIde.readFile as any).mockImplementation((path: string) => {
126+ if (path === "src/redux/rules.md") {
127+ return Promise.reject(new Error("Failed to read file"));
123128 }
124- return Promise.resolve(mockRuleContent[path] || '');
129+ return Promise.resolve(mockRuleContent[path] || "");
125130 });
126-
131+
127132 const { rules, errors } = await loadCodebaseRules(mockIde);
128-
133+
129134 // Should still return other rules
130135 expect(rules).toHaveLength(3);
131- expect(rules).toContainEqual(mockConvertedRules['src/rules.md']);
132- expect(rules).toContainEqual(mockConvertedRules['src/components/rules.md']);
133- expect(rules).toContainEqual(mockConvertedRules['.continue/rules.md']);
134-
136+ expect(rules).toContainEqual(mockConvertedRules["src/rules.md"]);
137+ expect(rules).toContainEqual(mockConvertedRules["src/components/rules.md"]);
138+ expect(rules).toContainEqual(mockConvertedRules[".continue/rules.md"]);
139+
135140 // Should have one error
136141 expect(errors).toHaveLength(1);
137- expect(errors[0].message).toContain('Failed to parse colocated rule file src/redux/rules.md');
142+ expect(errors[0].message).toContain(
143+ "Failed to parse colocated rule file src/redux/rules.md",
144+ );
138145 });
139146
140- it('should handle errors when walkDirs fails', async () => {
147+ it("should handle errors when walkDirs fails", async () => {
141148 // Setup mock to throw
142- (walkDirs as any).mockRejectedValue(new Error('Failed to walk directories'));
143-
149+ (walkDirs as any).mockRejectedValue(
150+ new Error("Failed to walk directories"),
151+ );
144152 const { rules, errors } = await loadCodebaseRules(mockIde);
145-
153+
146154 // Should return no rules
147155 expect(rules).toHaveLength(0);
148-
156+
149157 // Should have one error
150158 expect(errors).toHaveLength(1);
151- expect(errors[0].message).toContain('Error loading colocated rule files');
159+ expect(errors[0].message).toContain("Error loading colocated rule files");
152160 });
153-});
No newline at the end of the file
161+});
modified core/config/markdown/ruleCollocationApplication.vitest.ts +31 −27
@@ -1,6 +1,12 @@
11 import path from "path";
22 import { beforeEach, describe, expect, it } from "vitest";
3-import { ContextItemWithId, RuleWithSource, UserChatMessage } from "../..";
3+import {
4+ ContextItemId,
5+ ContextItemWithId,
6+ RuleWithSource,
7+ UserChatMessage,
8+} from "../..";
9+
410 import { getApplicableRules } from "../../llm/rules/getSystemMessageWithRules";
511
612 describe("Rule Colocation Application", () => {
@@ -68,86 +74,82 @@
6874 beforeEach(() => {
6975 // Setup user messages with different code blocks
7076 userMessageWithComponentFile = {
71- id: "1",
7277 role: "user",
7378 content:
7479 "Can you help me with this component file?\n```tsx src/components/Button.tsx\nexport const Button = () => {...}\n```",
75- createdAt: new Date().toISOString(),
7680 };
7781
7882 userMessageWithComponentJsxFile = {
79- id: "1b",
8083 role: "user",
8184 content:
8285 "Can you help me with this JSX component file?\n```jsx src/components/OldButton.jsx\nexport const OldButton = () => {...}\n```",
83- createdAt: new Date().toISOString(),
8486 };
8587
8688 userMessageWithReduxFile = {
87- id: "2",
8889 role: "user",
8990 content:
9091 'Can you help with this redux slice?\n```ts src/redux/userSlice.ts\nimport { createSlice } from "@reduxjs/toolkit";\n```',
91- createdAt: new Date().toISOString(),
9292 };
9393
9494 userMessageWithRootFile = {
95- id: "3",
9695 role: "user",
9796 content:
9897 "Can you help with this utility file?\n```ts src/utils/helpers.ts\nexport const formatDate = (date) => {...}\n```",
99- createdAt: new Date().toISOString(),
10098 };
10199
102100 userMessageWithApiUtilFile = {
103- id: "4",
104101 role: "user",
105102 content:
106103 "Can you help with this API utility file?\n```ts src/utils/api/requests.ts\nexport const fetchData = () => {...}\n```",
107- createdAt: new Date().toISOString(),
108104 };
109105
110106 // Setup context items
111107 componentTsxContextItem = {
112- id: "context1",
108+ id: { providerTitle: "file", itemId: "context1" } as ContextItemId,
113109 uri: { type: "file", value: "src/components/Button.tsx" },
114110 content: "export const Button = () => {...}",
115- retrievedAt: new Date().toISOString(),
111+ name: "Button.tsx",
112+ description: "Component file",
116113 };
117114
118115 componentJsxContextItem = {
119- id: "context1b",
116+ id: { providerTitle: "file", itemId: "context1b" } as ContextItemId,
120117 uri: { type: "file", value: "src/components/OldButton.jsx" },
121118 content: "export const OldButton = () => {...}",
122- retrievedAt: new Date().toISOString(),
119+ name: "OldButton.jsx",
120+ description: "Component file",
123121 };
124122
125123 reduxContextItem = {
126- id: "context2",
124+ id: { providerTitle: "file", itemId: "context2" } as ContextItemId,
127125 uri: { type: "file", value: "src/redux/userSlice.ts" },
128126 content: 'import { createSlice } from "@reduxjs/toolkit";',
129- retrievedAt: new Date().toISOString(),
127+ name: "userSlice.ts",
128+ description: "Redux slice",
130129 };
131130
132131 rootContextItem = {
133- id: "context3",
132+ id: { providerTitle: "file", itemId: "context3" } as ContextItemId,
134133 uri: { type: "file", value: "src/utils/helpers.ts" },
135134 content: "export const formatDate = (date) => {...}",
136- retrievedAt: new Date().toISOString(),
135+ name: "helpers.ts",
136+ description: "Utility file",
137137 };
138138
139139 apiUtilContextItem = {
140- id: "context4",
140+ id: { providerTitle: "file", itemId: "context4" } as ContextItemId,
141141 uri: { type: "file", value: "src/utils/api/requests.ts" },
142142 content: "export const fetchData = () => {...}",
143- retrievedAt: new Date().toISOString(),
143+ name: "requests.ts",
144+ description: "API utility file",
144145 };
145146
146147 otherUtilContextItem = {
147- id: "context5",
148+ id: { providerTitle: "file", itemId: "context5" } as ContextItemId,
148149 uri: { type: "file", value: "src/utils/format.ts" },
149150 content: "export const formatCurrency = (amount) => {...}",
150- retrievedAt: new Date().toISOString(),
151+ name: "format.ts",
152+ description: "Formatting utility",
151153 };
152154 });
153155
@@ -338,17 +340,19 @@
338340
339341 // Create context items for different files
340342 const modelFileContext: ContextItemWithId = {
341- id: "models1",
343+ id: { providerTitle: "file", itemId: "models1" } as ContextItemId,
342344 uri: { type: "file", value: "src/models/user.ts" },
343345 content: "export interface User {...}",
344- retrievedAt: new Date().toISOString(),
346+ name: "user.ts",
347+ description: "User model",
345348 };
346349
347350 const serviceFileContext: ContextItemWithId = {
348- id: "services1",
351+ id: { providerTitle: "file", itemId: "services1" } as ContextItemId,
349352 uri: { type: "file", value: "src/services/auth.ts" },
350353 content: "export const login = () => {...}",
351- retrievedAt: new Date().toISOString(),
354+ name: "auth.ts",
355+ description: "Auth service",
352356 };
353357
354358 // Test with model file - should apply only the models rule
modified core/llm/rules/alwaysApplyRules.vitest.ts +69 −67
@@ -1,137 +1,139 @@
1-import { describe, expect, it } from 'vitest';
2-import { ContextItemWithId, RuleWithSource, UserChatMessage } from '../..';
3-import { getApplicableRules } from './getSystemMessageWithRules';
4-
5-describe('Rule application with alwaysApply', () => {
1+import { describe, expect, it } from "vitest";
2+import {
3+ ContextItemId,
4+ ContextItemWithId,
5+ RuleWithSource,
6+ UserChatMessage,
7+} from "../..";
8+import { getApplicableRules } from "./getSystemMessageWithRules";
9+
10+describe("Rule application with alwaysApply", () => {
611 // Create an always-apply rule
712 const alwaysApplyRule: RuleWithSource = {
8- name: 'Always Apply Rule',
9- rule: 'This rule should always be applied',
13+ name: "Always Apply Rule",
14+ rule: "This rule should always be applied",
1015 alwaysApply: true,
11- source: 'rules-block',
12- ruleFile: '.continue/always-apply.md',
16+ source: "rules-block",
17+ ruleFile: ".continue/always-apply.md",
1318 };
14-
19+
1520 // Create a colocated rule in a nested directory
1621 const nestedDirRule: RuleWithSource = {
17- name: 'Nested Directory Rule',
18- rule: 'This rule applies to files in the nested directory',
19- source: 'rules-block',
20- ruleFile: 'nested-folder/rules.md',
22+ name: "Nested Directory Rule",
23+ rule: "This rule applies to files in the nested directory",
24+ source: "rules-block",
25+ ruleFile: "nested-folder/rules.md",
2126 };
2227
23- it('should apply alwaysApply rules even with no file references', () => {
28+ it("should apply alwaysApply rules even with no file references", () => {
2429 // Message with no code blocks or file references
2530 const simpleMessage: UserChatMessage = {
26- id: '1',
27- role: 'user',
28- content: 'Can you help me understand how this works?',
29- createdAt: new Date().toISOString(),
31+ role: "user",
32+ content: "Can you help me understand how this works?",
3033 };
3134
3235 // Apply rules with no context items
3336 const applicableRules = getApplicableRules(
34- simpleMessage,
37+ simpleMessage,
3538 [alwaysApplyRule, nestedDirRule],
36- []
39+ [],
3740 );
3841
3942 // The always apply rule should be included regardless of context
4043 expect(applicableRules).toHaveLength(1);
41- expect(applicableRules.map(r => r.name)).toContain('Always Apply Rule');
42- expect(applicableRules.map(r => r.name)).not.toContain('Nested Directory Rule');
44+ expect(applicableRules.map((r) => r.name)).toContain("Always Apply Rule");
45+ expect(applicableRules.map((r) => r.name)).not.toContain(
46+ "Nested Directory Rule",
47+ );
4348 });
4449
45- it('should apply nested directory rules to files in that directory', () => {
50+ it("should apply nested directory rules to files in that directory", () => {
4651 // Context with a file in the nested directory
4752 const nestedFileContext: ContextItemWithId = {
48- id: 'context1',
49- uri: { type: 'file', value: 'nested-folder/example.ts' },
50- content: 'export const example = () => {...}',
51- retrievedAt: new Date().toISOString(),
53+ id: { providerTitle: "file", itemId: "context1" } as ContextItemId,
54+ uri: { type: "file", value: "nested-folder/example.ts" },
55+ content: "export const example = () => {...}",
56+ name: "example.ts",
57+ description: "Example file",
5258 };
5359
5460 // Apply rules with file context in nested directory
5561 const applicableRules = getApplicableRules(
5662 undefined, // No message needed
5763 [alwaysApplyRule, nestedDirRule],
58- [nestedFileContext]
64+ [nestedFileContext],
5965 );
6066
6167 // Both rules should apply
6268 expect(applicableRules).toHaveLength(2);
63- expect(applicableRules.map(r => r.name)).toContain('Always Apply Rule');
64- expect(applicableRules.map(r => r.name)).toContain('Nested Directory Rule');
69+ expect(applicableRules.map((r) => r.name)).toContain("Always Apply Rule");
70+ expect(applicableRules.map((r) => r.name)).toContain(
71+ "Nested Directory Rule",
72+ );
6573 });
6674
67- it('should NOT apply nested directory rules to files outside that directory', () => {
75+ it("should NOT apply nested directory rules to files outside that directory", () => {
6876 // Context with a file outside the nested directory
6977 const outsideFileContext: ContextItemWithId = {
70- id: 'context2',
71- uri: { type: 'file', value: 'src/utils/helper.ts' },
72- content: 'export const helper = () => {...}',
73- retrievedAt: new Date().toISOString(),
78+ id: { providerTitle: "file", itemId: "context2" } as ContextItemId,
79+ uri: { type: "file", value: "src/utils/helper.ts" },
80+ content: "export const helper = () => {...}",
81+ name: "helper.ts",
82+ description: "Helper utility",
7483 };
7584
7685 // Apply rules with file context outside nested directory
7786 const applicableRules = getApplicableRules(
7887 undefined, // No message needed
7988 [alwaysApplyRule, nestedDirRule],
80- [outsideFileContext]
89+ [outsideFileContext],
8190 );
8291
8392 // Only the always apply rule should be included
8493 expect(applicableRules).toHaveLength(1);
85- expect(applicableRules.map(r => r.name)).toContain('Always Apply Rule');
86- expect(applicableRules.map(r => r.name)).not.toContain('Nested Directory Rule');
94+ expect(applicableRules.map((r) => r.name)).toContain("Always Apply Rule");
95+ expect(applicableRules.map((r) => r.name)).not.toContain(
96+ "Nested Directory Rule",
97+ );
8798 });
8899
89- it('should correctly apply rules when a file is mentioned in a message', () => {
100+ it("should correctly apply rules when a file is mentioned in a message", () => {
90101 // Message with a file reference
91102 const messageWithFile: UserChatMessage = {
92- id: '3',
93- role: 'user',
94- content: 'Can you help with this file?\n```ts nested-folder/example.ts\nexport const example = () => {...}\n```',
95- createdAt: new Date().toISOString(),
103+ role: "user",
104+ content:
105+ "Can you help with this file?\n```ts nested-folder/example.ts\nexport const example = () => {...}\n```",
96106 };
97107
98108 // Apply rules with a message containing a file reference
99109 const applicableRules = getApplicableRules(
100110 messageWithFile,
101111 [alwaysApplyRule, nestedDirRule],
102- []
112+ [],
103113 );
104114
105115 // Both rules should apply
106116 expect(applicableRules).toHaveLength(2);
107- expect(applicableRules.map(r => r.name)).toContain('Always Apply Rule');
108- expect(applicableRules.map(r => r.name)).toContain('Nested Directory Rule');
117+ expect(applicableRules.map((r) => r.name)).toContain("Always Apply Rule");
118+ expect(applicableRules.map((r) => r.name)).toContain(
119+ "Nested Directory Rule",
120+ );
109121 });
110122
111- it('should always apply rules with alwaysApply regardless of message or context', () => {
123+ it("should always apply rules with alwaysApply regardless of message or context", () => {
112124 // Test with no message or context
113- let applicableRules = getApplicableRules(
114- undefined,
115- [alwaysApplyRule],
116- []
117- );
125+ let applicableRules = getApplicableRules(undefined, [alwaysApplyRule], []);
118126 expect(applicableRules).toHaveLength(1);
119- expect(applicableRules.map(r => r.name)).toContain('Always Apply Rule');
120-
127+ expect(applicableRules.map((r) => r.name)).toContain("Always Apply Rule");
128+
121129 // Test with message but no file references and no context
122130 const simpleMessage: UserChatMessage = {
123- id: '4',
124- role: 'user',
125- content: 'Hello, can you help me?',
126- createdAt: new Date().toISOString(),
131+ role: "user",
132+ content: "Hello, can you help me?",
127133 };
128-
129- applicableRules = getApplicableRules(
130- simpleMessage,
131- [alwaysApplyRule],
132- []
133- );
134+
135+ applicableRules = getApplicableRules(simpleMessage, [alwaysApplyRule], []);
134136 expect(applicableRules).toHaveLength(1);
135- expect(applicableRules.map(r => r.name)).toContain('Always Apply Rule');
137+ expect(applicableRules.map((r) => r.name)).toContain("Always Apply Rule");
136138 });
137-});
No newline at the end of the file
139+});
modified core/llm/rules/fileProtocolMatching.vitest.ts +25 −23
@@ -1,53 +1,55 @@
1-import { describe, expect, it } from 'vitest';
2-import { RuleWithSource } from '../..';
3-import { shouldApplyRule } from './getSystemMessageWithRules';
1+import { describe, expect, it } from "vitest";
2+import { RuleWithSource } from "../..";
3+import { shouldApplyRule } from "./getSystemMessageWithRules";
44
5-describe('File Path Protocol Matching', () => {
5+describe("File Path Protocol Matching", () => {
66 // Test rule with a file:// protocol in the path - simulating what happens in VSCode
77 const ruleWithFileProtocol: RuleWithSource = {
8- name: 'Rule with file:// protocol',
9- rule: 'This is a test rule',
10- source: 'rules-block',
11- ruleFile: 'file:///Users/user/project/nested-folder/rules.md',
8+ name: "Rule with file:// protocol",
9+ rule: "This is a test rule",
10+ source: "rules-block",
11+ ruleFile: "file:///Users/user/project/nested-folder/rules.md",
1212 };
1313
14- it('should match relative paths with file:// protocol paths', () => {
14+ it("should match relative paths with file:// protocol paths", () => {
1515 // This is the key test case that would have failed before:
1616 // A relative path should match with a file:// protocol directory path
17- const relativePaths = ['nested-folder/example.py'];
18-
17+ const relativePaths = ["nested-folder/example.py"];
18+
1919 // Before the fix, this would have failed because the string comparison
20- // would be checking if 'nested-folder/example.py' starts with
20+ // would be checking if 'nested-folder/example.py' starts with
2121 // 'file:///Users/user/project/nested-folder/'
2222 expect(shouldApplyRule(ruleWithFileProtocol, relativePaths)).toBe(true);
2323 });
2424
25- it('should match when directory name appears in the path', () => {
25+ it("should match when directory name appears in the path", () => {
2626 // Even with a more complex relative path, it should match as long as
2727 // it contains the right directory structure
28- const nestedPaths = ['src/components/nested-folder/example.py'];
28+ const nestedPaths = ["src/components/nested-folder/example.py"];
2929 expect(shouldApplyRule(ruleWithFileProtocol, nestedPaths)).toBe(true);
3030 });
3131
32- it('should not match when directory name is not in the path', () => {
32+ it("should not match when directory name is not in the path", () => {
3333 // Should not match when the path doesn't contain the directory name
34- const unrelatedPaths = ['src/components/other-folder/example.py'];
34+ const unrelatedPaths = ["src/components/other-folder/example.py"];
3535 expect(shouldApplyRule(ruleWithFileProtocol, unrelatedPaths)).toBe(false);
3636 });
3737
38- it('should match absolute paths with the same protocol', () => {
38+ it("should match absolute paths with the same protocol", () => {
3939 // Should also work with absolute paths
40- const absolutePaths = ['file:///Users/user/project/nested-folder/example.py'];
40+ const absolutePaths = [
41+ "file:///Users/user/project/nested-folder/example.py",
42+ ];
4143 expect(shouldApplyRule(ruleWithFileProtocol, absolutePaths)).toBe(true);
4244 });
4345
44- it('should handle mixed path types in the same call', () => {
46+ it("should handle mixed path types in the same call", () => {
4547 // Should handle a mix of relative and absolute paths
4648 const mixedPaths = [
47- 'nested-folder/example.py',
48- 'file:///Users/user/project/nested-folder/other.py',
49- 'src/unrelated/file.py'
49+ "nested-folder/example.py",
50+ "file:///Users/user/project/nested-folder/other.py",
51+ "src/unrelated/file.py",
5052 ];
5153 expect(shouldApplyRule(ruleWithFileProtocol, mixedPaths)).toBe(true);
5254 });
53-});
No newline at the end of the file
55+});
modified core/llm/rules/implicitGlobalRules.vitest.ts +72 −65
@@ -1,129 +1,136 @@
1-import { describe, expect, it } from 'vitest';
2-import { ContextItemWithId, RuleWithSource, UserChatMessage } from '../..';
3-import { getApplicableRules } from './getSystemMessageWithRules';
4-
5-describe('Implicit global rules application', () => {
1+import { describe, expect, it } from "vitest";
2+import { RuleWithSource, UserChatMessage } from "../..";
3+import { getApplicableRules } from "./getSystemMessageWithRules";
4+
5+describe("Implicit global rules application", () => {
66 // Create a rule with no alwaysApply and no globs - should behave like a global rule
77 const implicitGlobalRule: RuleWithSource = {
8- name: 'Implicit Global Rule',
9- rule: 'This rule should be applied to all messages (implicit global)',
10- source: 'rules-block',
11- ruleFile: '.continue/global-rule.md',
8+ name: "Implicit Global Rule",
9+ rule: "This rule should be applied to all messages (implicit global)",
10+ source: "rules-block",
11+ ruleFile: ".continue/global-rule.md",
1212 // No alwaysApply specified
1313 // No globs specified
1414 };
15-
15+
1616 // Create a rule with explicit alwaysApply: true for comparison
1717 const explicitGlobalRule: RuleWithSource = {
18- name: 'Explicit Global Rule',
19- rule: 'This rule should always be applied (explicit global)',
18+ name: "Explicit Global Rule",
19+ rule: "This rule should always be applied (explicit global)",
2020 alwaysApply: true,
21- source: 'rules-block',
22- ruleFile: '.continue/explicit-global.md',
21+ source: "rules-block",
22+ ruleFile: ".continue/explicit-global.md",
2323 };
24-
24+
2525 // Create a colocated rule in a nested directory
2626 const nestedDirRule: RuleWithSource = {
27- name: 'Nested Directory Rule',
28- rule: 'This rule applies to files in the nested directory',
29- source: 'rules-block',
30- ruleFile: 'nested-folder/rules.md',
27+ name: "Nested Directory Rule",
28+ rule: "This rule applies to files in the nested directory",
29+ source: "rules-block",
30+ ruleFile: "nested-folder/rules.md",
3131 };
3232
33- it('should apply rules with no alwaysApply and no globs to all messages, even with no file references', () => {
33+ it("should apply rules with no alwaysApply and no globs to all messages, even with no file references", () => {
3434 // Message with no code blocks or file references
3535 const simpleMessage: UserChatMessage = {
36- id: '1',
37- role: 'user',
38- content: 'Can you help me understand how this works?',
39- createdAt: new Date().toISOString(),
36+ role: "user",
37+ content: "Can you help me understand how this works?",
4038 };
4139
4240 // Apply rules with no context items
4341 const applicableRules = getApplicableRules(
44- simpleMessage,
42+ simpleMessage,
4543 [implicitGlobalRule, explicitGlobalRule, nestedDirRule],
46- []
44+ [],
4745 );
4846
4947 // Both global rules should be included regardless of context
5048 expect(applicableRules).toHaveLength(2);
51- expect(applicableRules.map(r => r.name)).toContain('Implicit Global Rule');
52- expect(applicableRules.map(r => r.name)).toContain('Explicit Global Rule');
53- expect(applicableRules.map(r => r.name)).not.toContain('Nested Directory Rule');
49+ expect(applicableRules.map((r) => r.name)).toContain(
50+ "Implicit Global Rule",
51+ );
52+ expect(applicableRules.map((r) => r.name)).toContain(
53+ "Explicit Global Rule",
54+ );
55+ expect(applicableRules.map((r) => r.name)).not.toContain(
56+ "Nested Directory Rule",
57+ );
5458 });
5559
56- it('should treat root-level rules with no globs as global rules', () => {
60+ it("should treat root-level rules with no globs as global rules", () => {
5761 // Root rule with no globs
5862 const rootNoGlobsRule: RuleWithSource = {
59- name: 'Root No Globs Rule',
60- rule: 'This is a root-level rule with no globs',
61- source: 'rules-block',
62- ruleFile: '.continue/rules.md',
63+ name: "Root No Globs Rule",
64+ rule: "This is a root-level rule with no globs",
65+ source: "rules-block",
66+ ruleFile: ".continue/rules.md",
6367 // No alwaysApply, no globs
6468 };
65-
69+
6670 // Test with no file context
6771 const applicableRules = getApplicableRules(
6872 undefined,
6973 [rootNoGlobsRule],
70- []
74+ [],
7175 );
72-
76+
7377 // Should include the rule even with no context
7478 expect(applicableRules).toHaveLength(1);
75- expect(applicableRules[0].name).toBe('Root No Globs Rule');
79+ expect(applicableRules[0].name).toBe("Root No Globs Rule");
7680 });
7781
78- it('should apply implicit global rules alongside file-specific rules', () => {
82+ it("should apply implicit global rules alongside file-specific rules", () => {
7983 // File-specific message
8084 const messageWithFile: UserChatMessage = {
81- id: '2',
82- role: 'user',
83- content: 'Can you help with this file?\n```ts nested-folder/example.ts\nexport const example = () => {...}\n```',
84- createdAt: new Date().toISOString(),
85+ role: "user",
86+ content:
87+ "Can you help with this file?\n```ts nested-folder/example.ts\nexport const example = () => {...}\n```",
8588 };
86-
89+
8790 // Apply all rule types together
8891 const applicableRules = getApplicableRules(
8992 messageWithFile,
9093 [implicitGlobalRule, explicitGlobalRule, nestedDirRule],
91- []
94+ [],
9295 );
93-
96+
9497 // Should include all rules
9598 expect(applicableRules).toHaveLength(3);
96- expect(applicableRules.map(r => r.name)).toContain('Implicit Global Rule');
97- expect(applicableRules.map(r => r.name)).toContain('Explicit Global Rule');
98- expect(applicableRules.map(r => r.name)).toContain('Nested Directory Rule');
99+ expect(applicableRules.map((r) => r.name)).toContain(
100+ "Implicit Global Rule",
101+ );
102+ expect(applicableRules.map((r) => r.name)).toContain(
103+ "Explicit Global Rule",
104+ );
105+ expect(applicableRules.map((r) => r.name)).toContain(
106+ "Nested Directory Rule",
107+ );
99108 });
100-
101- it('should apply implicit global rules for first message without code', () => {
109+
110+ it("should apply implicit global rules for first message without code", () => {
102111 // Simple first message
103112 const firstMessage: UserChatMessage = {
104- id: '3',
105- role: 'user',
106- content: 'Hello, can you help me?',
107- createdAt: new Date().toISOString(),
113+ role: "user",
114+ content: "Hello, can you help me?",
108115 };
109-
116+
110117 // Assistant rules that should always apply
111118 const assistantRule: RuleWithSource = {
112- name: 'Assistant Guidelines',
113- rule: 'SOLID Design Principles - Coding Assistant Guidelines',
114- source: 'rules-block',
115- ruleFile: '.continue/rules.md',
119+ name: "Assistant Guidelines",
120+ rule: "SOLID Design Principles - Coding Assistant Guidelines",
121+ source: "rules-block",
122+ ruleFile: ".continue/rules.md",
116123 // No alwaysApply, no globs - should still apply
117124 };
118-
125+
119126 const applicableRules = getApplicableRules(
120127 firstMessage,
121128 [assistantRule],
122- []
129+ [],
123130 );
124-
131+
125132 // Should include the assistant rule even though there's no code
126133 expect(applicableRules).toHaveLength(1);
127- expect(applicableRules[0].name).toBe('Assistant Guidelines');
134+ expect(applicableRules[0].name).toBe("Assistant Guidelines");
128135 });
129-});
No newline at the end of the file
136+});
modified core/llm/rules/nestedDirectoryRules.vitest.ts +21 −13
@@ -1,5 +1,10 @@
11 import { describe, expect, it } from "vitest";
2-import { ContextItemWithId, RuleWithSource, UserChatMessage } from "../..";
2+import {
3+ ContextItemId,
4+ ContextItemWithId,
5+ RuleWithSource,
6+ UserChatMessage,
7+} from "../..";
38 import { getApplicableRules } from "./getSystemMessageWithRules";
49
510 describe("Nested directory rules application", () => {
@@ -23,13 +28,14 @@
2328 it("should apply nested directory rules to files in that directory", () => {
2429 // Create a context with a file in the nested directory
2530 const nestedFileContext: ContextItemWithId = {
26- id: "nested1",
31+ id: { providerTitle: "file", itemId: "nested1" } as ContextItemId,
2732 uri: {
2833 type: "file",
2934 value: "manual-testing-sandbox/nested-folder/hellonested.py",
3035 },
3136 content: 'print("Hello nested")',
32- retrievedAt: new Date().toISOString(),
37+ name: "hellonested.py",
38+ description: "Nested file",
3339 };
3440
3541 // Apply rules with the nested file context
@@ -48,11 +54,9 @@
4854 it("should also work with file references in messages", () => {
4955 // Message with a file reference in the nested directory
5056 const messageWithNestedFile: UserChatMessage = {
51- id: "msg1",
5257 role: "user",
5358 content:
5459 'Can you explain this file?\n```python manual-testing-sandbox/nested-folder/hellonested.py\nprint("Hello nested")\n```',
55- createdAt: new Date().toISOString(),
5660 };
5761
5862 // Apply rules with the message containing a nested file reference
@@ -71,10 +75,11 @@
7175 it("should NOT apply nested directory rules to files outside that directory", () => {
7276 // Context with a file outside the nested directory
7377 const outsideFileContext: ContextItemWithId = {
74- id: "outside1",
78+ id: { providerTitle: "file", itemId: "outside1" } as ContextItemId,
7579 uri: { type: "file", value: "src/utils/helper.ts" },
7680 content: "export const helper = () => {...}",
77- retrievedAt: new Date().toISOString(),
81+ name: "helper.ts",
82+ description: "Helper file",
7883 };
7984
8085 // Apply rules with file context outside nested directory
@@ -112,26 +117,29 @@
112117
113118 // A file in src/
114119 const srcPythonFileContext: ContextItemWithId = {
115- id: "python1",
120+ id: { providerTitle: "file", itemId: "python1" } as ContextItemId,
116121 uri: { type: "file", value: "src/pythonfile.py" },
117122 content: 'print("Hello")',
118- retrievedAt: new Date().toISOString(),
123+ name: "pythonfile.py",
124+ description: "Python file in src",
119125 };
120126
121127 // A file in utils/
122128 const utilsPythonFileContext: ContextItemWithId = {
123- id: "python2",
129+ id: { providerTitle: "file", itemId: "python2" } as ContextItemId,
124130 uri: { type: "file", value: "utils/pythonfile.py" },
125131 content: 'print("Hello")',
126- retrievedAt: new Date().toISOString(),
132+ name: "pythonfile.py",
133+ description: "Python file in utils",
127134 };
128135
129136 // A file in manual-testing-sandbox/
130137 const manualTestingPythonFileContext: ContextItemWithId = {
131- id: "python3",
138+ id: { providerTitle: "file", itemId: "python3" } as ContextItemId,
132139 uri: { type: "file", value: "manual-testing-sandbox/pythonfile.py" },
133140 content: 'print("Hello")',
134- retrievedAt: new Date().toISOString(),
141+ name: "pythonfile.py",
142+ description: "Python file in manual-testing-sandbox",
135143 };
136144
137145 // Apply src rule to src file - should match