8000 feat(custom-instructions): migrate custom instructions to file-based storage by devxpain · Pull Request #4002 · RooCodeInc/Roo-Code · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(custom-instructions): migrate custom instructions to file-based storage #4002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

devxpain
Copy link
@devxpain devxpain commented May 26, 2025

Related GitHub Issue

Discussions: #4000

Description

Migrated the storage of "Custom Instructions for All Modes" from VS Code's global state to a dedicated file: ...Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/custom_instructions.md.

Key changes include:

  • Implemented a migration utility to automatically move existing custom instructions from global state to the new file upon extension update.
  • Introduced new commands and UI buttons within the Prompts view to:
    • Open the custom_instructions.md file directly in the editor for easy editing.
    • Refresh the custom instructions in the UI by re-reading them from the file, ensuring changes made directly to the file are reflected.
  • The updateCustomInstructions function now writes/deletes the file instead of updating global state.
  • The initial state and refreshes now read custom instructions directly from the file.

This change provides a more robust and user-friendly way to manage custom instructions, allowing for external editing and version control.

Test Procedure

Build .vsix and install then test manually

Type of Change

  • 🐛 Bug Fix: Non-breaking change that fixes an issue.
  • New Feature: Non-breaking change that adds functionality.
  • 💥 Breaking Change: Fix or feature that would cause existing functionality to not work as expected.
  • ♻️ Refactor: Code change that neither fixes a bug nor adds a feature.
  • 💅 Style: Changes that do not affect the meaning of the code (white-space, formatting, etc.).
  • 📚 Documentation: Updates to documentation files.
  • ⚙️ Build/CI: Changes to the build process or CI configuration.
  • 🧹 Chore: Other changes that don't modify src or test files.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Code Quality:
    • My code adheres to the project's style guidelines.
    • There are no new linting errors or warnings (npm run lint).
    • All debug code (e.g., console.log) has been removed.
  • Testing:
    • New and/or updated tests have been added to cover my changes.
    • All tests pass locally (npm test).
    • The application builds successfully with my changes.
  • Branch Hygiene: My branch is up-to-date (rebased) with the main branch.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Changeset: A changeset has been created using npm run changeset if this PR includes user-facing changes or dependency updates.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Screenshot 2025-05-27 at 12 50 44 AM

Documentation Updates

Additional Notes

Get in Touch


Important

Migrate custom instructions from VS Code's global state to a file-based system with new UI and commands for management.

  • Behavior:
    • Migrate custom instructions from global state to custom_instructions.md file in ClineProvider.ts.
    • Add openCustomInstructionsFile and refreshCustomInstructions commands in webviewMessageHandler.ts.
    • Update PromptsView.tsx to include UI buttons for opening and refreshing custom instructions.
  • Migration:
    • Implement migration utility in migrateSettings.ts to move instructions from global state to file.
  • UI:
    • Add buttons in PromptsView.tsx for opening and refreshing the custom_instructions.md file.
  • i18n:
    • Update prompts.json to include new strings for custom instructions management.

This description was created by Ellipsis for 799a1cd. You can customize this summary. It will automatically update as commits are pushed.

…storage

See discussion: RooCodeInc#4000

Migrated the storage of "Custom Instructions for All Modes" from VS Code's global state to a dedicated file: `...Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/custom_instructions.md`.

Key changes include:
- Implemented a migration utility to automatically move existing custom instructions from global state to the new file upon extension update.
- Introduced new commands and UI buttons within the Prompts view to:
  - Open the `custom_instructions.md` file directly in the editor for easy editing.
  - Refresh the custom instructions in the UI by re-reading them from the file, ensuring changes made directly to the file are reflected.
- The `updateCustomInstructions` function now writes/deletes the file instead of updating global state.
- The initial state and refreshes now read custom instructions directly from the file.

This change provides a more robust and user-friendly way to manage custom instructions, allowing for external editing and version control.
@devxpain devxpain requested review from mrubens and cte as code owners May 26, 2025 16:53
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label May 27, 2025
@hannesrudolph hannesrudolph moved this from Triage to PR [Needs Preliminary Review] in Roo Code Roadmap May 28, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels May 28, 2025
Copy link
Collaborator
@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @devxpain, This looks like a great idea, it should help a lot with the memory issues we are having.

I left some questions that are worth looking into to prevent potential issues with the file.

But overall I like what you did here, let me know if you want to discuss this further.

content = await fs.readFile(customInstructionsFilePath, "utf-8")
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
throw error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed we're silently catching ENOENT errors here but throwing others. Is this intentional? Should we be consistent with error handling across all the new methods?

const customInstructionsFilePath = path.join(settingsDir, GlobalFileNames.customInstructions)

if (customInstructionsContent && !(await fileExistsAtPath(customInstructionsFilePath))) {
await fs.writeFile(customInstructionsFilePath, customInstructionsContent, "utf-8")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the migration fails partway through (e.g., file write succeeds but globalState update fails)? Should we wrap this in a try-catch and potentially rollback on failure to prevent data loss?

type: "refreshCustomInstructions",
})
}}
title={t("prompts:globalCustomInstructions.refreshFile")}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When users click the refresh button, should we provide some visual feedback (like a brief loading state or toast notification) to confirm the refresh happened? Right now it might not be clear if the action succeeded.

const settingsDirPath = await this.ensureSettingsDirectoryExists()
const customInstructionsFilePath = path.join(settingsDirPath, GlobalFileNames.customInstructions)
const fileUri = vscode.Uri.file(customInstructionsFilePath)
await vscode.commands.executeCommand("vscode.open", fileUri, { preview: false, preserveFocus: true })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the custom instructions file doesn't exist when a user clicks the open button? Should we create an empty file first to avoid VSCode showing an error?

await vscode.commands.executeCommand("workbench.action.files.revert", fileUri)
}

async refreshCustomInstructions(): Promise<void> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed there aren't any tests for these new methods. Should we add test coverage for:

File creation/deletion behavior
Migration logic
Error handling scenarios
The new UI interactions?

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Draft / In Progress] in Roo Code Roadmap May 29, 2025
@devxpain
Copy link
Author

Hey @devxpain, This looks like a great idea, it should help a lot with the memory issues we are having.

I left some questions that are worth looking into to prevent potential issues with the file.

But overall I like what you did here, let me know if you want to discuss this further.

Hi @daniel-lxs, thanks for your feedback and review!
I actually used Roo-Code itself to help analyze and edit the code for this proof of concept.
I’d be happy to discuss the best way to handle it and work together to finalize this pull request.
Feel free to reach out to me on Discord or here. I’ll go through the comments you left and see what I can improve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: PR [Draft / In Progress]
Development

Successfully merging this pull request may close these issues.

3 participants
0