Skip to content

Commit 5802b68

Browse files
authored
[PROTOBUS] Move createRuleFile to protobus 🚌💨 (RooCodeInc#3122)
* createRuleFile protobus migration * deleteRuleFile protobus * mend * mend * mend * Generic response for delete request * refactored deleteRuleFile for consolidation * rename ruleFileResult to ruleFile * rebase and cleanup * createRuleFile protobus migration * ellipsis changes * consolidated ruleFile protos * prep for merge on to 3124 * removed ruleFileOperations
1 parent 4a76870 commit 5802b68

File tree

14 files changed

+196
-169
lines changed

14 files changed

+196
-169
lines changed

.changeset/hungry-islands-jog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
createRuleFile protobus migration

proto/common.proto

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,3 @@ message BooleanRequest {
4949
message Boolean {
5050
bool value = 1;
5151
}
52-
53-
// Generic response for operations that return success status and a message
54-
message OperationResponse {
55-
bool success = 1; // Whether the operation was successful
56-
string message = 2; // Success or error message
57-
}

proto/file.proto

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,26 @@ service FileService {
1313

1414
// Opens an image in the system viewer
1515
rpc openImage(StringRequest) returns (Empty);
16-
16+
1717
// Deletes a rule file from either global or workspace rules directory
18-
rpc deleteRuleFile(DeleteRuleFileRequest) returns (RuleFile);
18+
rpc deleteRuleFile(RuleFileRequest) returns (RuleFile);
19+
20+
// Creates a rule file from either global or workspace rules directory
21+
rpc createRuleFile(RuleFileRequest) returns (RuleFile);
1922
}
2023

21-
// Request for deleteRuleFile
22-
message DeleteRuleFileRequest {
24+
// Unified request for all rule file operations
25+
message RuleFileRequest {
2326
Metadata metadata = 1;
24-
string rule_path = 2;
25-
bool is_global = 3;
27+
bool is_global = 2; // Common field for all operations
28+
optional string rule_path = 3; // Path field for deleteRuleFile (optional)
29+
optional string filename = 4; // Filename field for createRuleFile (optional)
2630
}
2731

2832
// Result for rule file operations with meaningful data only
2933
message RuleFile {
3034
string file_path = 1; // Path to the rule file
3135
string display_name = 2; // Filename for display purposes
36+
bool already_exists = 3; // For createRuleFile, indicates if file already existed
3237
}
38+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Controller } from ".."
2+
import { RuleFileRequest, RuleFile } from "@shared/proto/file"
3+
import { FileMethodHandler } from "./index"
4+
import {
5+
createRuleFile as createRuleFileImpl,
6+
refreshClineRulesToggles,
7+
} from "@core/context/instructions/user-instructions/cline-rules"
8+
import * as vscode from "vscode"
9+
import * as path from "path"
10+
import { handleFileServiceRequest } from "./index"
11+
import { cwd } from "@core/task"
12+
13+
/**
14+
* Creates a rule file in either global or workspace rules directory
15+
* @param controller The controller instance
16+
* @param request The request containing filename and isGlobal flag
17+
* @returns Result with file path and display name
18+
* @throws Error if operation fails
19+
*/
20+
export const createRuleFile: FileMethodHandler = async (controller: Controller, request: RuleFileRequest): Promise<RuleFile> => {
21+
if (typeof request.isGlobal !== "boolean" || typeof request.filename !== "string" || !request.filename) {
22+
console.error("createRuleFile: Missing or invalid parameters", {
23+
isGlobal: typeof request.isGlobal === "boolean" ? request.isGlobal : `Invalid: ${typeof request.isGlobal}`,
24+
filename: typeof request.filename === "string" ? request.filename : `Invalid: ${typeof request.filename}`,
25+
})
26+
throw new Error("Missing or invalid parameters")
27+
}
28+
29+
const { filePath, fileExists } = await createRuleFileImpl(request.isGlobal, request.filename, cwd)
30+
31+
if (!filePath) {
32+
throw new Error("Failed to create rule file.")
33+
}
34+
35+
if (fileExists) {
36+
vscode.window.showWarningMessage(`Rule file "${request.filename}" already exists.`)
37+
// Still open it for editing
38+
await handleFileServiceRequest(controller, "openFile", { value: filePath })
39+
} else {
40+
await refreshClineRulesToggles(controller.context, cwd)
41+
await controller.postStateToWebview()
42+
43+
await handleFileServiceRequest(controller, "openFile", { value: filePath })
44+
45+
vscode.window.showInformationMessage(
46+
`Created new ${request.isGlobal ? "global" : "workspace"} rule file: ${request.filename}`,
47+
)
48+
}
49+
50+
return RuleFile.create({
51+
filePath: filePath,
52+
displayName: path.basename(filePath),
53+
alreadyExists: fileExists,
54+
})
55+
}

src/core/controller/file/deleteRuleFile.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Controller } from ".."
2-
import { DeleteRuleFileRequest, RuleFile } from "@shared/proto/file"
2+
import { RuleFileRequest, RuleFile } from "@shared/proto/file"
33
import { FileMethodHandler } from "./index"
44
import {
55
deleteRuleFile as deleteRuleFileImpl,
@@ -16,10 +16,7 @@ import { cwd } from "@core/task"
1616
* @returns Result with file path and display name
1717
* @throws Error if operation fails
1818
*/
19-
export const deleteRuleFile: FileMethodHandler = async (
20-
controller: Controller,
21-
request: DeleteRuleFileRequest,
22-
): Promise<RuleFile> => {
19+
export const deleteRuleFile: FileMethodHandler = async (controller: Controller, request: RuleFileRequest): Promise<RuleFile> => {
2320
if (typeof request.isGlobal !== "boolean" || typeof request.rulePath !== "string" || !request.rulePath) {
2421
console.error("deleteRuleFile: Missing or invalid parameters", {
2522
isGlobal: typeof request.isGlobal === "boolean" ? request.isGlobal : `Invalid: ${typeof request.isGlobal}`,
@@ -43,5 +40,6 @@ export const deleteRuleFile: FileMethodHandler = async (
4340
return RuleFile.create({
4441
filePath: request.rulePath,
4542
displayName: fileName,
43+
alreadyExists: false,
4644
})
4745
}

src/core/controller/file/methods.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
// Import all method implementations
55
import { registerMethod } from "./index"
6+
import { createRuleFile } from "./createRuleFile"
67
import { deleteRuleFile } from "./deleteRuleFile"
78
import { openFile } from "./openFile"
89
import { openImage } from "./openImage"
910

1011
// Register all file service methods
1112
export function registerAllMethods(): void {
1213
// Register each method with the registry
14+
registerMethod("createRuleFile", createRuleFile)
1315
registerMethod("deleteRuleFile", deleteRuleFile)
1416
registerMethod("openFile", openFile)
1517
registerMethod("openImage", openImage)

src/core/controller/index.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -384,36 +384,6 @@ export class Controller {
384384
break
385385
case "fetchOpenGraphData":
386386
this.fetchOpenGraphData(message.text!)
387-
break
388-
case "createRuleFile":
389-
if (typeof message.isGlobal !== "boolean" || typeof message.filename !== "string" || !message.filename) {
390-
console.error("createRuleFile: Missing or invalid parameters", {
391-
isGlobal:
392-
typeof message.isGlobal === "boolean" ? message.isGlobal : `Invalid: ${typeof message.isGlobal}`,
393-
filename: typeof message.filename === "string" ? message.filename : `Invalid: ${typeof message.filename}`,
394-
})
395-
return
396-
}
397-
const { filePath, fileExists } = await createRuleFile(message.isGlobal, message.filename, cwd)
398-
if (fileExists && filePath) {
399-
vscode.window.showWarningMessage(`Rule file "${message.filename}" already exists.`)
400-
// Still open it for editing
401-
await handleFileServiceRequest(this, "openFile", { value: filePath })
402-
return
403-
} else if (filePath && !fileExists) {
404-
await refreshClineRulesToggles(this.context, cwd)
405-
await this.postStateToWebview()
406-
407-
await handleFileServiceRequest(this, "openFile", { value: filePath })
408-
409-
vscode.window.showInformationMessage(
410-
`Created new ${message.isGlobal ? "global" : "workspace"} rule file: ${message.filename}`,
411-
)
412-
} else {
413-
// null filePath
414-
vscode.window.showErrorMessage(`Failed to create rule file.`)
415-
}
416-
417387
break
418388
case "openMention":
419389
openMention(message.text)

src/shared/WebviewMessage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export interface WebviewMessage {
2424
| "requestOllamaModels"
2525
| "requestLmStudioModels"
2626
| "openInBrowser"
27-
| "createRuleFile"
2827
| "openMention"
2928
| "showChatView"
3029
| "refreshOpenRouterModels"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { RuleFileRequest } from "../proto/file"
2+
3+
/**
4+
* Simplified clean interface for RuleFile requests
5+
*/
6+
7+
// Helper for creating delete requests
8+
export const DeleteRuleFileRequest = {
9+
create: (params: { rulePath: string; isGlobal: boolean; metadata?: any }): RuleFileRequest => {
10+
return RuleFileRequest.create({
11+
rulePath: params.rulePath,
12+
isGlobal: params.isGlobal,
13+
metadata: params.metadata,
14+
})
15+
},
16+
}
17+
18+
// Helper for creating create requests
19+
export const CreateRuleFileRequest = {
20+
create: (params: { filename: string; isGlobal: boolean; metadata?: any }): RuleFileRequest => {
21+
return RuleFileRequest.create({
22+
filename: params.filename,
23+
isGlobal: params.isGlobal,
24+
metadata: params.metadata,
25+
})
26+
},
27+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./file"

0 commit comments

Comments
 (0)