-
Notifications
You must be signed in to change notification settings - Fork 13k
refactor common settings logic for skills,agents #17490
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cc80688
refactor common settings logic for skills,agents
ishaanxgupta 4243a53
Merge branch 'main' into ishaan/refactor
ishaanxgupta 8f06717
fix type issue
ishaanxgupta 2fc1bf0
Merge branch 'main' into ishaan/refactor
ishaanxgupta 888d83d
add test for skills and agents to confirm refactoring works
ved015 c1df099
Merge branch 'main' into ishaan/refactor
scidomino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { | ||
| SettingScope, | ||
| isLoadableSettingScope, | ||
| type LoadableSettingScope, | ||
| type LoadedSettings, | ||
| } from '../config/settings.js'; | ||
|
|
||
| export interface ModifiedScope { | ||
| scope: SettingScope; | ||
| path: string; | ||
| } | ||
|
|
||
| export type FeatureActionStatus = 'success' | 'no-op' | 'error'; | ||
|
|
||
| export interface FeatureActionResult { | ||
| status: FeatureActionStatus; | ||
| featureName: string; | ||
| action: 'enable' | 'disable'; | ||
| /** Scopes where the feature's state was actually changed. */ | ||
| modifiedScopes: ModifiedScope[]; | ||
| /** Scopes where the feature was already in the desired state. */ | ||
| alreadyInStateScopes: ModifiedScope[]; | ||
| /** Error message if status is 'error'. */ | ||
| error?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Strategy pattern to handle differences between feature types (e.g. skills vs agents). | ||
| */ | ||
| export interface FeatureToggleStrategy { | ||
| /** | ||
| * Checks if the feature needs to be enabled in the given scope. | ||
| * For skills (blacklist): returns true if in disabled list. | ||
| * For agents (whitelist): returns true if NOT explicitly enabled (false or undefined). | ||
| */ | ||
| needsEnabling( | ||
| settings: LoadedSettings, | ||
| scope: LoadableSettingScope, | ||
| featureName: string, | ||
| ): boolean; | ||
|
|
||
| /** | ||
| * Applies the enable change to the settings object. | ||
| */ | ||
| enable( | ||
| settings: LoadedSettings, | ||
| scope: LoadableSettingScope, | ||
| featureName: string, | ||
| ): void; | ||
|
|
||
| /** | ||
| * Checks if the feature is explicitly disabled in the given scope. | ||
| * For skills (blacklist): returns true if in disabled list. | ||
| * For agents (whitelist): returns true if explicitly set to false. | ||
| */ | ||
| isExplicitlyDisabled( | ||
| settings: LoadedSettings, | ||
| scope: LoadableSettingScope, | ||
| featureName: string, | ||
| ): boolean; | ||
|
|
||
| /** | ||
| * Applies the disable change to the settings object. | ||
| */ | ||
| disable( | ||
| settings: LoadedSettings, | ||
| scope: LoadableSettingScope, | ||
| featureName: string, | ||
| ): void; | ||
| } | ||
|
|
||
| /** | ||
| * Enables a feature by ensuring it is enabled in all writable scopes. | ||
| */ | ||
| export function enableFeature( | ||
| settings: LoadedSettings, | ||
| featureName: string, | ||
| strategy: FeatureToggleStrategy, | ||
| ): FeatureActionResult { | ||
| const writableScopes = [SettingScope.Workspace, SettingScope.User]; | ||
| const foundInDisabledScopes: ModifiedScope[] = []; | ||
| const alreadyEnabledScopes: ModifiedScope[] = []; | ||
|
|
||
| for (const scope of writableScopes) { | ||
| if (isLoadableSettingScope(scope)) { | ||
| const scopePath = settings.forScope(scope).path; | ||
| if (strategy.needsEnabling(settings, scope, featureName)) { | ||
| foundInDisabledScopes.push({ scope, path: scopePath }); | ||
| } else { | ||
| alreadyEnabledScopes.push({ scope, path: scopePath }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (foundInDisabledScopes.length === 0) { | ||
| return { | ||
| status: 'no-op', | ||
| featureName, | ||
| action: 'enable', | ||
| modifiedScopes: [], | ||
| alreadyInStateScopes: alreadyEnabledScopes, | ||
| }; | ||
| } | ||
|
|
||
| const modifiedScopes: ModifiedScope[] = []; | ||
| for (const { scope, path } of foundInDisabledScopes) { | ||
| if (isLoadableSettingScope(scope)) { | ||
| strategy.enable(settings, scope, featureName); | ||
| modifiedScopes.push({ scope, path }); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| status: 'success', | ||
| featureName, | ||
| action: 'enable', | ||
| modifiedScopes, | ||
| alreadyInStateScopes: alreadyEnabledScopes, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Disables a feature in the specified scope. | ||
| */ | ||
| export function disableFeature( | ||
| settings: LoadedSettings, | ||
| featureName: string, | ||
| scope: SettingScope, | ||
| strategy: FeatureToggleStrategy, | ||
| ): FeatureActionResult { | ||
| if (!isLoadableSettingScope(scope)) { | ||
| return { | ||
| status: 'error', | ||
| featureName, | ||
| action: 'disable', | ||
| modifiedScopes: [], | ||
| alreadyInStateScopes: [], | ||
| error: `Invalid settings scope: ${scope}`, | ||
| }; | ||
| } | ||
|
|
||
| const scopePath = settings.forScope(scope).path; | ||
|
|
||
| if (strategy.isExplicitlyDisabled(settings, scope, featureName)) { | ||
| return { | ||
| status: 'no-op', | ||
| featureName, | ||
| action: 'disable', | ||
| modifiedScopes: [], | ||
| alreadyInStateScopes: [{ scope, path: scopePath }], | ||
| }; | ||
| } | ||
|
|
||
| // Check if it's already disabled in the other writable scope | ||
| const otherScope = | ||
| scope === SettingScope.Workspace | ||
| ? SettingScope.User | ||
| : SettingScope.Workspace; | ||
| const alreadyDisabledInOther: ModifiedScope[] = []; | ||
|
|
||
| if (isLoadableSettingScope(otherScope)) { | ||
| if (strategy.isExplicitlyDisabled(settings, otherScope, featureName)) { | ||
| alreadyDisabledInOther.push({ | ||
| scope: otherScope, | ||
| path: settings.forScope(otherScope).path, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| strategy.disable(settings, scope, featureName); | ||
|
|
||
| return { | ||
| status: 'success', | ||
| featureName, | ||
| action: 'disable', | ||
| modifiedScopes: [{ scope, path: scopePath }], | ||
| alreadyInStateScopes: alreadyDisabledInOther, | ||
| }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.