Elffuss BraidHub

kikocis/continue public

fix: uri utils
Changeseta840de7f3a7a3a6cba6a70d53da4774e0d34c2a78285a0937e1e1479a7fea12a
AuthorTomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-06-11 14:39 -07:00
CommitterTomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-06-11 14:39 -07:00
Parentsb6f6b229557f

Browse the files at this changeset

4 files changed

modified core/config/markdown/loadCodebaseRules.ts +2 −21
@@ -1,27 +1,9 @@
11 import { ConfigValidationError } from "@continuedev/config-yaml";
22 import { IDE, RuleWithSource } from "../..";
33 import { walkDirs } from "../../indexing/walkDir";
4+import { getUriPathBasename } from "../../util/uri";
45 import { convertMarkdownRuleToContinueRule } from "./parseMarkdownRule";
56
6-/**
7- * Gets the directory part of a path (without using Node.js path module)
8- */
9-const getDirname = (filePath: string): string => {
10- // Normalize path separators to forward slash
11- const normalizedPath = filePath.replace(/\\/g, "/");
12-
13- // Find the last slash
14- const lastSlashIndex = normalizedPath.lastIndexOf("/");
15-
16- // If no slash found, return empty string (current directory)
17- if (lastSlashIndex === -1) {
18- return "";
19- }
20-
21- // Return everything up to the last slash
22- return normalizedPath.substring(0, lastSlashIndex);
23-};
24-
257 /**
268 * Loads rules from rules.md files colocated in the codebase
279 */
@@ -38,8 +20,7 @@
3820
3921 // Filter to just rules.md files
4022 const rulesMdFiles = allFiles.filter((file) => {
41- const parts = file.split("/");
42- const filename = parts[parts.length - 1];
23+ const filename = getUriPathBasename(file);
4324 return filename === "rules.md";
4425 });
4526
modified core/core.ts +4 −5
@@ -64,6 +64,7 @@
6464 import { OnboardingModes } from "./protocol/core";
6565 import type { IMessenger, Message } from "./protocol/messenger";
6666 import { StreamAbortManager } from "./util/abortManager";
67+import { getUriPathBasename } from "./util/uri";
6768
6869 export class Core {
6970 configHandler: ConfigHandler;
@@ -581,8 +582,7 @@
581582 // Check for rules.md files being created
582583 let rulesFileCreated = false;
583584 for (const uri of data.uris) {
584- const parts = uri.split("/");
585- const filename = parts[parts.length - 1];
585+ const filename = getUriPathBasename(uri);
586586 if (filename === "rules.md") {
587587 rulesFileCreated = true;
588588 break;
@@ -613,8 +613,7 @@
613613 // Check for rules.md files being deleted
614614 let rulesFileDeleted = false;
615615 for (const uri of data.uris) {
616- const parts = uri.split("/");
617- const filename = parts[parts.length - 1];
616+ const filename = getUriPathBasename(uri);
618617 if (filename === "rules.md") {
619618 rulesFileDeleted = true;
620619 break;
@@ -851,7 +850,7 @@
851850 uri.endsWith(".prompt") ||
852851 uri.endsWith(SYSTEM_PROMPT_DOT_FILE) ||
853852 (uri.includes(".continue") && uri.endsWith(".yaml")) ||
854- uri.endsWith("rules.md") // Add check for rules.md files
853+ uri.endsWith("rules.md")
855854 ) {
856855 await this.configHandler.reloadConfig();
857856 } else if (
modified core/llm/rules/getSystemMessageWithRules.ts +7 −25
@@ -6,6 +6,7 @@
66 UserChatMessage,
77 } from "../..";
88 import { renderChatMessage } from "../../util/messageContent";
9+import { getCleanUriPath } from "../../util/uri";
910 import { extractPathsFromCodeBlocks } from "../utils/extractPathsFromCodeBlocks";
1011
1112 /**
@@ -50,25 +51,6 @@
5051 return false;
5152 };
5253
53-/**
54- * Gets the directory part of a path (without using Node.js path module)
55- */
56-const getDirname = (filePath: string): string => {
57- // Normalize path separators to forward slash
58- const normalizedPath = filePath.replace(/\\/g, "/");
59-
60- // Find the last slash
61- const lastSlashIndex = normalizedPath.lastIndexOf("/");
62-
63- // If no slash found, return empty string (current directory)
64- if (lastSlashIndex === -1) {
65- return "";
66- }
67-
68- // Return everything up to the last slash
69- return normalizedPath.substring(0, lastSlashIndex);
70-};
71-
7254 /**
7355 * Determines if a file path is within a specific directory or its subdirectories
7456 *
@@ -100,10 +82,7 @@
10082 // This is a simple check to see if the file might be in this directory
10183 const containsDir = normalizedFilePath.includes(`${dirName}/`);
10284
103- // For logging
104- const result = containsDir;
105-
106- return result;
85+ return containsDir;
10786 };
10887
10988 /**
@@ -163,11 +142,14 @@
163142
164143 // For non-root rules, we need to check if any files are in the rule's directory
165144 if (!isRootRule && rule.ruleFile) {
166- const ruleDirectory = getDirname(rule.ruleFile);
145+ const ruleDirectory = getCleanUriPath(rule.ruleFile);
146+ const lastSlashIndex = ruleDirectory.lastIndexOf("/");
147+ const ruleDirPath =
148+ lastSlashIndex !== -1 ? ruleDirectory.substring(0, lastSlashIndex) : "";
167149
168150 // Filter to only files in this directory or its subdirectories
169151 const filesInRuleDirectory = filePaths.filter((filePath) =>
170- isFileInDirectory(filePath, ruleDirectory),
152+ isFileInDirectory(filePath, ruleDirPath),
171153 );
172154
173155 // If no files are in this directory, don't apply the rule
modified core/tools/implementations/createRuleBlock.ts +6 −5
@@ -2,7 +2,7 @@
22 import { ToolImpl } from ".";
33 import { RuleWithSource } from "../..";
44 import { RuleFrontmatter } from "../../config/markdown/parseMarkdownRule";
5-import { joinPathsToUri } from "../../util/uri";
5+import { joinPathsToUri, pathToUriPathSegment } from "../../util/uri";
66
77 export type CreateRuleBlockArgs = Pick<
88 Required<RuleWithSource>,
@@ -14,11 +14,12 @@
1414 args: CreateRuleBlockArgs,
1515 extras,
1616 ) => {
17- // Sanitize rule name for use in filename (remove special chars, replace spaces with dashes)
18- const safeRuleName = args.name
17+ // Use the pathToUriPathSegment utility for sanitizing the name
18+ const safeRuleName = pathToUriPathSegment(args.name)
1919 .toLowerCase()
20- .replace(/[^a-z0-9\s-]/g, "")
21- .replace(/\s+/g, "-");
20+ .replace(/[^a-z0-9-]/g, "") // Further sanitize to remove any remaining special chars
21+ .replace(/-+/g, "-") // Replace multiple dashes with a single dash
22+ .replace(/^-|-$/g, ""); // Remove leading/trailing dashes
2223
2324 const fileExtension = "md";
2425