diff --git a/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap b/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap
index 96e7c71..1319499 100644
--- a/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap
+++ b/src/core/prompts/__tests__/__snapshots__/system.test.ts.snap
@@ -3300,6 +3300,43 @@ Example: Requesting to list all top level source code definitions in the current
.
+## write_to_file
+Description: Request to write full content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file.
+Parameters:
+- path: (required) The path of the file to write to (relative to the current working directory /test/path)
+- content: (required) The content to write to the file. ALWAYS provide the COMPLETE intended content of the file, without any truncation or omissions. You MUST include ALL parts of the file, even if they haven't been modified. Do NOT include the line numbers in the content though, just the actual content of the file.
+- line_count: (required) The number of lines in the file. Make sure to compute this based on the actual content of the file, not the number of lines in the content you're providing.
+Usage:
+
+File path here
+
+Your file content here
+
+total number of lines in the file, including empty lines
+
+
+Example: Requesting to write to frontend-config.json
+
+frontend-config.json
+
+{
+ "apiEndpoint": "https://api.example.com",
+ "theme": {
+ "primaryColor": "#007bff",
+ "secondaryColor": "#6c757d",
+ "fontFamily": "Arial, sans-serif"
+ },
+ "features": {
+ "darkMode": true,
+ "notifications": true,
+ "analytics": false
+ },
+ "version": "1.0.0"
+}
+
+14
+
+
## ask_followup_question
Description: Ask the user a question to gather additional information needed to complete the task. This tool should be used when you encounter ambiguities, need clarification, or require more details to proceed effectively. It allows for interactive problem-solving by enabling direct communication with the user. Use this tool judiciously to maintain a balance between gathering necessary information and avoiding excessive back-and-forth.
Parameters:
diff --git a/src/shared/__tests__/modes.test.ts b/src/shared/__tests__/modes.test.ts
index 1405d1c..c438ba8 100644
--- a/src/shared/__tests__/modes.test.ts
+++ b/src/shared/__tests__/modes.test.ts
@@ -83,6 +83,26 @@ describe("isToolAllowedForMode", () => {
const diffError = isToolAllowedForMode("apply_diff", "markdown-editor", customModes, undefined, "test.js")
expect(diffError).toBeInstanceOf(FileRestrictionError)
})
+
+ it("allows ask mode to edit markdown files only", () => {
+ // Should allow editing markdown files
+ const mdResult = isToolAllowedForMode("write_to_file", "ask", [], undefined, "test.md")
+ expect(mdResult).toBe(true)
+
+ // Should allow applying diffs to markdown files
+ const diffResult = isToolAllowedForMode("apply_diff", "ask", [], undefined, "readme.md")
+ expect(diffResult).toBe(true)
+
+ // Should reject non-markdown files
+ const jsResult = isToolAllowedForMode("write_to_file", "ask", [], undefined, "test.js")
+ expect(jsResult).toBeInstanceOf(FileRestrictionError)
+ expect((jsResult as FileRestrictionError).message).toContain("Markdown files only")
+
+ // Should maintain read capabilities
+ expect(isToolAllowedForMode("read_file", "ask", [])).toBe(true)
+ expect(isToolAllowedForMode("browser_action", "ask", [])).toBe(true)
+ expect(isToolAllowedForMode("use_mcp_tool", "ask", [])).toBe(true)
+ })
})
it("handles non-existent modes", () => {
@@ -99,9 +119,15 @@ describe("isToolAllowedForMode", () => {
})
describe("FileRestrictionError", () => {
- it("formats error message correctly", () => {
+ it("formats error message with pattern when no description provided", () => {
const error = new FileRestrictionError("Markdown Editor", "\\.md$")
expect(error.message).toBe("This mode (Markdown Editor) can only edit files matching the pattern: \\.md$")
expect(error.name).toBe("FileRestrictionError")
})
+
+ it("formats error message with description when provided", () => {
+ const error = new FileRestrictionError("Markdown Editor", "\\.md$", "Markdown files only")
+ expect(error.message).toBe("This mode (Markdown Editor) can only edit files matching Markdown files only")
+ expect(error.name).toBe("FileRestrictionError")
+ })
})
diff --git a/src/shared/modes.ts b/src/shared/modes.ts
index 73f9cc4..63d3d7e 100644
--- a/src/shared/modes.ts
+++ b/src/shared/modes.ts
@@ -89,7 +89,7 @@ export const modes: readonly ModeConfig[] = [
name: "Ask",
roleDefinition:
"You are Roo, a knowledgeable technical assistant focused on answering questions and providing information about software development, technology, and related topics. You can analyze code, explain concepts, and access external resources while maintaining a read-only approach to the codebase. Make sure to answer the user's questions and don't rush to switch to implementing code.",
- groups: ["read", "browser", "mcp"],
+ groups: ["read", ["edit", { fileRegex: "\\.md$", description: "Markdown files only" }], "browser", "mcp"],
},
] as const
@@ -146,8 +146,10 @@ export function isCustomMode(slug: string, customModes?: ModeConfig[]): boolean
// Custom error class for file restrictions
export class FileRestrictionError extends Error {
- constructor(mode: string, pattern: string) {
- super(`This mode (${mode}) can only edit files matching the pattern: ${pattern}`)
+ constructor(mode: string, pattern: string, description?: string) {
+ super(
+ `This mode (${mode}) can only edit files matching ${description ? description : `the pattern: ${pattern}`}`,
+ )
this.name = "FileRestrictionError"
}
}
@@ -194,7 +196,7 @@ export function isToolAllowedForMode(
// For the edit group, check file regex if specified
if (groupName === "edit" && options.fileRegex) {
if (!filePath || !doesFileMatchRegex(filePath, options.fileRegex)) {
- return new FileRestrictionError(mode.name, options.fileRegex)
+ return new FileRestrictionError(mode.name, options.fileRegex, options.description)
}
return true
}