Skip to content

Commit 7413d64

Browse files
committed
Let ask mode write markdown too
1 parent 4e77fb9 commit 7413d64

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

src/core/prompts/__tests__/__snapshots__/system.test.ts.snap

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3300,6 +3300,43 @@ Example: Requesting to list all top level source code definitions in the current
33003300
<path>.</path>
33013301
</list_code_definition_names>
33023302
3303+
## write_to_file
3304+
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.
3305+
Parameters:
3306+
- path: (required) The path of the file to write to (relative to the current working directory /test/path)
3307+
- 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.
3308+
- 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.
3309+
Usage:
3310+
<write_to_file>
3311+
<path>File path here</path>
3312+
<content>
3313+
Your file content here
3314+
</content>
3315+
<line_count>total number of lines in the file, including empty lines</line_count>
3316+
</write_to_file>
3317+
3318+
Example: Requesting to write to frontend-config.json
3319+
<write_to_file>
3320+
<path>frontend-config.json</path>
3321+
<content>
3322+
{
3323+
"apiEndpoint": "https://api.example.com",
3324+
"theme": {
3325+
"primaryColor": "#007bff",
3326+
"secondaryColor": "#6c757d",
3327+
"fontFamily": "Arial, sans-serif"
3328+
},
3329+
"features": {
3330+
"darkMode": true,
3331+
"notifications": true,
3332+
"analytics": false
3333+
},
3334+
"version": "1.0.0"
3335+
}
3336+
</content>
3337+
<line_count>14</line_count>
3338+
</write_to_file>
3339+
33033340
## ask_followup_question
33043341
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.
33053342
Parameters:

src/shared/__tests__/modes.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ describe("isToolAllowedForMode", () => {
8383
const diffError = isToolAllowedForMode("apply_diff", "markdown-editor", customModes, undefined, "test.js")
8484
expect(diffError).toBeInstanceOf(FileRestrictionError)
8585
})
86+
87+
it("allows ask mode to edit markdown files only", () => {
88+
// Should allow editing markdown files
89+
const mdResult = isToolAllowedForMode("write_to_file", "ask", [], undefined, "test.md")
90+
expect(mdResult).toBe(true)
91+
92+
// Should allow applying diffs to markdown files
93+
const diffResult = isToolAllowedForMode("apply_diff", "ask", [], undefined, "readme.md")
94+
expect(diffResult).toBe(true)
95+
96+
// Should reject non-markdown files
97+
const jsResult = isToolAllowedForMode("write_to_file", "ask", [], undefined, "test.js")
98+
expect(jsResult).toBeInstanceOf(FileRestrictionError)
99+
expect((jsResult as FileRestrictionError).message).toContain("Markdown files only")
100+
101+
// Should maintain read capabilities
102+
expect(isToolAllowedForMode("read_file", "ask", [])).toBe(true)
103+
expect(isToolAllowedForMode("browser_action", "ask", [])).toBe(true)
104+
expect(isToolAllowedForMode("use_mcp_tool", "ask", [])).toBe(true)
105+
})
86106
})
87107

88108
it("handles non-existent modes", () => {
@@ -99,9 +119,15 @@ describe("isToolAllowedForMode", () => {
99119
})
100120

101121
describe("FileRestrictionError", () => {
102-
it("formats error message correctly", () => {
122+
it("formats error message with pattern when no description provided", () => {
103123
const error = new FileRestrictionError("Markdown Editor", "\\.md$")
104124
expect(error.message).toBe("This mode (Markdown Editor) can only edit files matching the pattern: \\.md$")
105125
expect(error.name).toBe("FileRestrictionError")
106126
})
127+
128+
it("formats error message with description when provided", () => {
129+
const error = new FileRestrictionError("Markdown Editor", "\\.md$", "Markdown files only")
130+
expect(error.message).toBe("This mode (Markdown Editor) can only edit files matching Markdown files only")
131+
expect(error.name).toBe("FileRestrictionError")
132+
})
107133
})

src/shared/modes.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const modes: readonly ModeConfig[] = [
8989
name: "Ask",
9090
roleDefinition:
9191
"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.",
92-
groups: ["read", "browser", "mcp"],
92+
groups: ["read", ["edit", { fileRegex: "\\.md$", description: "Markdown files only" }], "browser", "mcp"],
9393
},
9494
] as const
9595

@@ -146,8 +146,10 @@ export function isCustomMode(slug: string, customModes?: ModeConfig[]): boolean
146146

147147
// Custom error class for file restrictions
148148
export class FileRestrictionError extends Error {
149-
constructor(mode: string, pattern: string) {
150-
super(`This mode (${mode}) can only edit files matching the pattern: ${pattern}`)
149+
constructor(mode: string, pattern: string, description?: string) {
150+
super(
151+
`This mode (${mode}) can only edit files matching ${description ? description : `the pattern: ${pattern}`}`,
152+
)
151153
this.name = "FileRestrictionError"
152154
}
153155
}
@@ -194,7 +196,7 @@ export function isToolAllowedForMode(
194196
// For the edit group, check file regex if specified
195197
if (groupName === "edit" && options.fileRegex) {
196198
if (!filePath || !doesFileMatchRegex(filePath, options.fileRegex)) {
197-
return new FileRestrictionError(mode.name, options.fileRegex)
199+
return new FileRestrictionError(mode.name, options.fileRegex, options.description)
198200
}
199201
return true
200202
}

0 commit comments

Comments
 (0)