Skip to content

Commit acc6bb3

Browse files
committed
Optimize mode export: merge custom prompts before YAML generation
- Add customPrompts parameter to exportModeWithRules() method - Remove inefficient parse/stringify cycle in webview message handler - Merge custom prompts directly during export creation instead of post-processing
1 parent 2da5c5c commit acc6bb3

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

src/core/config/CustomModesManager.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,10 @@ export class CustomModesManager {
617617
/**
618618
* Exports a mode configuration with its associated rules files into a shareable YAML format
619619
* @param slug - The mode identifier to export
620+
* @param customPrompts - Optional custom prompts to merge into the export
620621
* @returns Success status with YAML content or error message
621622
*/
622-
public async exportModeWithRules(slug: string): Promise<ExportResult> {
623+
public async exportModeWithRules(slug: string, customPrompts?: any): Promise<ExportResult> {
623624
try {
624625
// Import modes from shared to check built-in modes
625626
const { modes: builtInModes } = await import("../../shared/modes")
@@ -702,6 +703,14 @@ export class CustomModesManager {
702703
source: "project" as const,
703704
}
704705

706+
// Merge custom prompts if provided
707+
if (customPrompts) {
708+
if (customPrompts.roleDefinition) exportMode.roleDefinition = customPrompts.roleDefinition
709+
if (customPrompts.description) exportMode.description = customPrompts.description
710+
if (customPrompts.whenToUse) exportMode.whenToUse = customPrompts.whenToUse
711+
if (customPrompts.customInstructions) exportMode.customInstructions = customPrompts.customInstructions
712+
}
713+
705714
// Add rules files if any exist
706715
if (rulesFiles.length > 0) {
707716
exportMode.rulesFiles = rulesFiles

src/core/webview/webviewMessageHandler.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,32 +1509,10 @@ export const webviewMessageHandler = async (
15091509
const customModePrompts = getGlobalState("customModePrompts") || {}
15101510
const customPrompt = customModePrompts[message.slug]
15111511

1512-
// Export the mode with any customizations
1513-
const result = await provider.customModesManager.exportModeWithRules(message.slug)
1512+
// Export the mode with any customizations merged directly
1513+
const result = await provider.customModesManager.exportModeWithRules(message.slug, customPrompt)
15141514

15151515
if (result.success && result.yaml) {
1516-
// If there are custom prompts for this mode, merge them into the export
1517-
if (customPrompt && result.yaml) {
1518-
try {
1519-
const exportData = yaml.parse(result.yaml)
1520-
if (exportData.customModes && exportData.customModes[0]) {
1521-
// Merge custom prompt data into the mode
1522-
const mode = exportData.customModes[0]
1523-
if (customPrompt.roleDefinition) mode.roleDefinition = customPrompt.roleDefinition
1524-
if (customPrompt.description) mode.description = customPrompt.description
1525-
if (customPrompt.whenToUse) mode.whenToUse = customPrompt.whenToUse
1526-
if (customPrompt.customInstructions)
1527-
mode.customInstructions = customPrompt.customInstructions
1528-
1529-
// Re-stringify the updated data
1530-
result.yaml = yaml.stringify(exportData)
1531-
}
1532-
} catch (error) {
1533-
// If parsing fails, continue with original yaml
1534-
provider.log(`Failed to merge custom prompts into export: ${error}`)
1535-
}
1536-
}
1537-
15381516
// Get last used directory for export
15391517
const lastExportPath = getGlobalState("lastModeExportPath")
15401518
let defaultUri: vscode.Uri

0 commit comments

Comments
 (0)