Skip to content

Conversation

@devxpain
Copy link
Contributor

@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 799a1cde160fe0899430fa29c4b7cf96b6fc4161. You can customize this summary. It will automatically update as commits are pushed.

@devxpain devxpain requested review from cte and mrubens 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
Member

@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.

Copy link
Member

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?

Copy link
Contributor Author

@devxpain devxpain Jun 2, 2025

Choose a reason for hiding this comment

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

ae788e7e93d6aac4ff507f369d335fc6eaff8845

Copy link
Member

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?

Copy link
Contributor Author

@devxpain devxpain Jun 2, 2025

Choose a reason for hiding this comment

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

753d77893507be4b8a87009b74aa608f5f1beb1f

Copy link
Member

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.

Copy link
Contributor Author

@devxpain devxpain Jun 2, 2025

Choose a reason for hiding this comment

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

070939c076ec08e6ed8dab1036791798d705cf3a

Copy link
Member

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?

Copy link
Contributor Author

@devxpain devxpain Jun 2, 2025

Choose a reason for hiding this comment

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

7b11bce832d589e4b0f400bd5f222c96cd84d07a

Copy link
Member

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?

Copy link
Contributor Author

@devxpain devxpain Jun 2, 2025

Choose a reason for hiding this comment

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

46092af20e27cc7c5d96ede14322ac56af986e10

Right now, I’ve just made sure that pnpm test runs without any errors. I’ll add tests after confirming that the current changes are solid.

@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
Contributor 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.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 2, 2025
@devxpain
Copy link
Contributor Author

devxpain commented Jun 2, 2025

Hi @daniel-lxs, I’ve pushed more commits based on your feedback.
Could you review the latest changes and let me know if they look good?

Instead of focusing only on Custom Instructions, I refactored the code to be more generic. The goal is to also support Mode-specific Custom Instructions (optional) and potentially other settings that could benefit from this change.

As for the tests, I’ll add them once we confirm that the current approach is correct and stable.

@devxpain devxpain requested a review from daniel-lxs June 2, 2025 06:43
@devxpain devxpain force-pushed the dev branch 2 times, most recently from 46092af to 17718ba Compare June 3, 2025 09:45
@daniel-lxs daniel-lxs moved this from PR [Draft / In Progress] to PR [Needs Prelim Review] in Roo Code Roadmap Jun 3, 2025
Copy link
Member

@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, Thank you for addressing my previous points so quickly.

I apologize for the delay in reviewing your PR.

I left some additional points I missed in my previous preview, hopefully with these changes we should be good.

Also I noticed the translations action is failing, it would be great if you can take a look at that.

Copy link
Member

Choose a reason for hiding this comment

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

Any specific reason to have these methods inside ClineProvider?

If not, it might be a good idea to move them out since this class is already quite big.

src/utils/fs.ts Outdated
Copy link
Member

Choose a reason for hiding this comment

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

This error handling pattern for ENOENT is duplicated in multiple places:

  • Here in safeReadFile
  • In ClineProvider.updateContent
  • In custom-instructions.ts
  • In custom-system-prompt.ts

It would be a good idea to consolidate this on a single helper function.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if the error handling can be improved:

  1. When filePath is undefined, log is created but an error is not thrown or the user is not notified
  2. When file operations fail, errors are thrown but not caught by callers
  3. No validation for file size, content format, or concurrent modifications

It might be better to:

  • Add proper error boundaries and user notifications
  • Validate content before writing (size limits, format)
  • Handle concurrent modification scenarios
  • Consider using a try-catch wrapper for all file operations

Since this increases complexity to some degree it might be better to move these methods out of ClineProvider.

Copy link
Member

Choose a reason for hiding this comment

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

The error handling here only logs to console but doesn't provide feedback to the user. When operations fail, users won't know what went wrong.

Consider:

  • Sending error messages back to the webview
  • Showing user-friendly error notifications
  • Adding proper error recovery mechanisms

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

devxpain commented Jun 6, 2025

Hey @devxpain, Thank you for addressing my previous points so quickly.

I apologize for the delay in reviewing your PR.

I left some additional points I missed in my previous preview, hopefully with these changes we should be good.

Also I noticed the translations action is failing, it would be great if you can take a look at that.

Hi @daniel-lxs,

Thanks again for your feedback.
Apologies — I'm not a VS Code Extension specialist and don’t aim to be one, so I might not be aware of all the built-in features VS Code offers. I mostly rely on the Roo-Code and focus on implementing the minimum necessary to provide the intended feature.

If I do a full refactor too early, it might distract from the main focus, especially since I wasn’t sure about the direction you all want to take with the refactor. That’s why your feedback is so valuable to me.

Thanks again — I’ll review your suggestions and address them as soon as possible.

@daniel-lxs
Copy link
Member

Hey @devxpain, No worries, the purpose of the feedback is not to point out something you did wrong, is to point out things that could be a bit better.

The better we get your implementation the higher the chance is merged.

If you have any questions please let me know, again this review is not meant to discourage you at all.

devxpain added 6 commits June 7, 2025 17:19
…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.
- Moved `safeReadFile` function from multiple files to `src/utils/fs.ts`
- Updated imports in affected files to use the centralized `safeReadFile` function
- Simplified file reading logic by removing redundant implementations
- Wrap file write and global state update in try-catch block
- Log error message if migration fails
- Refactor custom instructions management to a generic 'content' system, introducing `GlobalContentIds`.
- Implement new `openContent`, `updateContent`, and `refreshContent` methods in `ClineProvider` to handle various content types.
- Update webview message interfaces (`WebviewMessage`, `ExtensionMessage`) to support content IDs and a new `contentRefreshed` event.
- Enhance the custom instructions UI in the webview with a dedicated `useRefreshableContent` hook.
- Add visual feedback for content refresh operations, including a loading spinner and a success message.
- Replaced direct `vscode.commands.executeCommand("vscode.open")` call with the `openFile` utility.
- Centralizes file opening logic, improving reusability and maintainability within the webview provider.
- Ensure `safeReadFile` handles empty content gracefully to prevent potential errors.
- Update Jest mocks for `fs` utility functions in tests to correctly spread original exports, improving test reliability.
- Add comprehensive `globalState` mocking in `migrateSettings` tests for better test coverage.
- Move content-related methods (openContent, refreshContent, updateContent, readContent) from ClineProvider to a new ContentManager class.
- Instantiate ContentManager in ClineProvider and delegate content operations to it.
- Improve separation of concerns by centralizing content file system interactions and state updates within ContentManager.
@daniel-lxs daniel-lxs moved this from PR [Draft / In Progress] to PR [Needs Prelim Review] in Roo Code Roadmap Jun 10, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Draft / In Progress] in Roo Code Roadmap Jun 12, 2025
@hannesrudolph
Copy link
Collaborator

stales

@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 7, 2025
@github-project-automation github-project-automation bot moved this from PR [Draft / In Progress] to Done in Roo Code Roadmap Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR - Draft / In Progress size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants