Changesets · Branches · Tags · Compare
| Changeset | a840de7f3a7a3a6cba6a70d53da4774e0d34c2a78285a0937e1e1479a7fea12a |
|---|---|
| Author | Tomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-06-11 14:39 -07:00 |
| Committer | Tomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-06-11 14:39 -07:00 |
| Parents | b6f6b229557f |
4 files changed
modified core/config/markdown/loadCodebaseRules.ts +2 −21
| @@ -1,27 +1,9 @@ | ||
| 1 | 1 | import { ConfigValidationError } from "@continuedev/config-yaml"; |
| 2 | 2 | import { IDE, RuleWithSource } from "../.."; |
| 3 | 3 | import { walkDirs } from "../../indexing/walkDir"; |
| 4 | +import { getUriPathBasename } from "../../util/uri"; | |
| 4 | 5 | import { convertMarkdownRuleToContinueRule } from "./parseMarkdownRule"; |
| 5 | 6 | |
| 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 | - | |
| 25 | 7 | /** |
| 26 | 8 | * Loads rules from rules.md files colocated in the codebase |
| 27 | 9 | */ |
| @@ -38,8 +20,7 @@ | ||
| 38 | 20 | |
| 39 | 21 | // Filter to just rules.md files |
| 40 | 22 | const rulesMdFiles = allFiles.filter((file) => { |
| 41 | - const parts = file.split("/"); | |
| 42 | - const filename = parts[parts.length - 1]; | |
| 23 | + const filename = getUriPathBasename(file); | |
| 43 | 24 | return filename === "rules.md"; |
| 44 | 25 | }); |
| 45 | 26 |
modified core/core.ts +4 −5
| @@ -64,6 +64,7 @@ | ||
| 64 | 64 | import { OnboardingModes } from "./protocol/core"; |
| 65 | 65 | import type { IMessenger, Message } from "./protocol/messenger"; |
| 66 | 66 | import { StreamAbortManager } from "./util/abortManager"; |
| 67 | +import { getUriPathBasename } from "./util/uri"; | |
| 67 | 68 | |
| 68 | 69 | export class Core { |
| 69 | 70 | configHandler: ConfigHandler; |
| @@ -581,8 +582,7 @@ | ||
| 581 | 582 | // Check for rules.md files being created |
| 582 | 583 | let rulesFileCreated = false; |
| 583 | 584 | for (const uri of data.uris) { |
| 584 | - const parts = uri.split("/"); | |
| 585 | - const filename = parts[parts.length - 1]; | |
| 585 | + const filename = getUriPathBasename(uri); | |
| 586 | 586 | if (filename === "rules.md") { |
| 587 | 587 | rulesFileCreated = true; |
| 588 | 588 | break; |
| @@ -613,8 +613,7 @@ | ||
| 613 | 613 | // Check for rules.md files being deleted |
| 614 | 614 | let rulesFileDeleted = false; |
| 615 | 615 | for (const uri of data.uris) { |
| 616 | - const parts = uri.split("/"); | |
| 617 | - const filename = parts[parts.length - 1]; | |
| 616 | + const filename = getUriPathBasename(uri); | |
| 618 | 617 | if (filename === "rules.md") { |
| 619 | 618 | rulesFileDeleted = true; |
| 620 | 619 | break; |
| @@ -851,7 +850,7 @@ | ||
| 851 | 850 | uri.endsWith(".prompt") || |
| 852 | 851 | uri.endsWith(SYSTEM_PROMPT_DOT_FILE) || |
| 853 | 852 | (uri.includes(".continue") && uri.endsWith(".yaml")) || |
| 854 | - uri.endsWith("rules.md") // Add check for rules.md files | |
| 853 | + uri.endsWith("rules.md") | |
| 855 | 854 | ) { |
| 856 | 855 | await this.configHandler.reloadConfig(); |
| 857 | 856 | } else if ( |
modified core/llm/rules/getSystemMessageWithRules.ts +7 −25
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | UserChatMessage, |
| 7 | 7 | } from "../.."; |
| 8 | 8 | import { renderChatMessage } from "../../util/messageContent"; |
| 9 | +import { getCleanUriPath } from "../../util/uri"; | |
| 9 | 10 | import { extractPathsFromCodeBlocks } from "../utils/extractPathsFromCodeBlocks"; |
| 10 | 11 | |
| 11 | 12 | /** |
| @@ -50,25 +51,6 @@ | ||
| 50 | 51 | return false; |
| 51 | 52 | }; |
| 52 | 53 | |
| 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 | - | |
| 72 | 54 | /** |
| 73 | 55 | * Determines if a file path is within a specific directory or its subdirectories |
| 74 | 56 | * |
| @@ -100,10 +82,7 @@ | ||
| 100 | 82 | // This is a simple check to see if the file might be in this directory |
| 101 | 83 | const containsDir = normalizedFilePath.includes(`${dirName}/`); |
| 102 | 84 | |
| 103 | - // For logging | |
| 104 | - const result = containsDir; | |
| 105 | - | |
| 106 | - return result; | |
| 85 | + return containsDir; | |
| 107 | 86 | }; |
| 108 | 87 | |
| 109 | 88 | /** |
| @@ -163,11 +142,14 @@ | ||
| 163 | 142 | |
| 164 | 143 | // For non-root rules, we need to check if any files are in the rule's directory |
| 165 | 144 | 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) : ""; | |
| 167 | 149 | |
| 168 | 150 | // Filter to only files in this directory or its subdirectories |
| 169 | 151 | const filesInRuleDirectory = filePaths.filter((filePath) => |
| 170 | - isFileInDirectory(filePath, ruleDirectory), | |
| 152 | + isFileInDirectory(filePath, ruleDirPath), | |
| 171 | 153 | ); |
| 172 | 154 | |
| 173 | 155 | // If no files are in this directory, don't apply the rule |
modified core/tools/implementations/createRuleBlock.ts +6 −5
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | import { ToolImpl } from "."; |
| 3 | 3 | import { RuleWithSource } from "../.."; |
| 4 | 4 | import { RuleFrontmatter } from "../../config/markdown/parseMarkdownRule"; |
| 5 | -import { joinPathsToUri } from "../../util/uri"; | |
| 5 | +import { joinPathsToUri, pathToUriPathSegment } from "../../util/uri"; | |
| 6 | 6 | |
| 7 | 7 | export type CreateRuleBlockArgs = Pick< |
| 8 | 8 | Required<RuleWithSource>, |
| @@ -14,11 +14,12 @@ | ||
| 14 | 14 | args: CreateRuleBlockArgs, |
| 15 | 15 | extras, |
| 16 | 16 | ) => { |
| 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) | |
| 19 | 19 | .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 | |
| 22 | 23 | |
| 23 | 24 | const fileExtension = "md"; |
| 24 | 25 |