Repository navigation
feat(webview): setValues batch persistence and reset cleanup (N4, split 4/5 of #1546) #2236
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
base: main
Are you sure you want to change the base?
Changes from all commits
e67ab35
f28c486
7906df6
f560872
6340998
9849018
7b610a1
7de336e
035f117
c723553
faa3982
9b68e06
ac73edb
04350e2
d96c8a3
66184ce
9a01dd8
e8307ef
5841fc1
ff26ffc
8145b37
a95c43c
e3ca230
877ea0a
ec54bce
509f92c
492cfb3
610b6de
41bd742
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -353,6 +353,28 @@ export class CustomModesManager { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Every definition of a mode, per source file, without the project-over-global hiding that | ||
| * `getCustomModes` applies. A rollback has to restore both: a batch that overwrites a global | ||
| * definition through a slug that also exists as a project mode would otherwise leave the global | ||
| * copy permanently replaced by the batch's version. | ||
| */ | ||
| public async getCustomModeDefinitions(slugs: readonly string[]): Promise<ModeConfig[]> { | ||
| const wanted = new Set(slugs) | ||
| const settingsPath = await this.getCustomModesFilePath() | ||
| const settingsModes = await this.loadModesFromFile(settingsPath) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| const roomodesPath = await this.getWorkspaceRoomodes() | ||
| const roomodesModes = roomodesPath ? await this.loadModesFromFile(roomodesPath) : [] | ||
|
|
||
| return [ | ||
| ...roomodesModes | ||
| .filter((mode) => wanted.has(mode.slug)) | ||
| .map((mode) => ({ ...mode, source: "project" as const })), | ||
| ...settingsModes | ||
| .filter((mode) => wanted.has(mode.slug)) | ||
| .map((mode) => ({ ...mode, source: "global" as const })), | ||
| ] | ||
| } | ||
| public async getCustomModes(): Promise<ModeConfig[]> { | ||
| // Check if we have a valid cached result. | ||
| const now = Date.now() | ||
|
|
@@ -553,6 +575,44 @@ export class CustomModesManager { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Removes a mode's entry from the mode files and refreshes the merged state, without | ||
| * touching its rules folder. Rollback paths need this variant: `deleteCustomMode` also | ||
| * deletes `.roo/rules-<slug>` (or `~/.roo/rules-<slug>`), and a rollback cannot know | ||
| * whether that folder predates the batch whose registration it is undoing - deleting it | ||
| * would discard rules the user wrote earlier. | ||
| * | ||
| * Returns whether an entry was actually removed so a caller can report a miss instead of | ||
| * assuming cleanup happened. Errors propagate; rollback callers decide how loud to be. | ||
| */ | ||
| public async removeCustomModeEntry(slug: string): Promise<boolean> { | ||
| const settingsPath = await this.getCustomModesFilePath() | ||
| const roomodesPath = await this.getWorkspaceRoomodes() | ||
| const projectModes = roomodesPath ? await this.loadModesFromFile(roomodesPath) : [] | ||
| const settingsModes = await this.loadModesFromFile(settingsPath) | ||
| const inProjectFile = projectModes.some((mode) => mode.slug === slug) | ||
| const inSettingsFile = settingsModes.some((mode) => mode.slug === slug) | ||
|
|
||
| if (!inProjectFile && !inSettingsFile) { | ||
| return false | ||
| } | ||
|
|
||
| await this.queueWrite(async () => { | ||
| if (roomodesPath && inProjectFile) { | ||
| await this.updateModesInFile(roomodesPath, (modes) => modes.filter((m) => m.slug !== slug)) | ||
| } | ||
|
|
||
| if (inSettingsFile) { | ||
| await this.updateModesInFile(settingsPath, (modes) => modes.filter((m) => m.slug !== slug)) | ||
| } | ||
|
|
||
| this.clearCache() | ||
| await this.refreshMergedState() | ||
| }) | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| /** | ||
| * Deletes the rules folder for a specific mode | ||
| * @param slug - The mode slug | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.