Merge pull request #2781 from QwenLM/feat/hooks-remove-experimental

feat(hooks): remove experimental flag and add disabled state UI
This commit is contained in:
tanzhenxin 2026-04-01 15:37:34 +08:00 committed by GitHub
commit a29e059d2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 745 additions and 350 deletions

View file

@ -419,12 +419,15 @@ export interface ConfigParameters {
modelProvidersConfig?: ModelProvidersConfig;
/** Multi-agent collaboration settings (Arena, Team, Swarm) */
agents?: AgentsCollabSettings;
/** Enable hook system for lifecycle events */
enableHooks?: boolean;
/**
* Disable all hooks (default: false, hooks enabled).
* Migration note: This replaces the deprecated hooksConfig.enabled setting.
* Users with old settings.json containing hooksConfig.enabled should migrate
* to use disableAllHooks instead (note: inverted logic - enabled:true disableAllHooks:false).
*/
disableAllHooks?: boolean;
/** Hooks configuration from settings */
hooks?: Record<string, unknown>;
/** Hooks config settings (enabled, disabled list) */
hooksConfig?: Record<string, unknown>;
/** Warnings generated during configuration resolution */
warnings?: string[];
/**
@ -594,9 +597,8 @@ export class Config {
private readonly eventEmitter?: EventEmitter;
private readonly channel: string | undefined;
private readonly defaultFileEncoding: FileEncodingType | undefined;
private readonly enableHooks: boolean;
private readonly disableAllHooks: boolean;
private readonly hooks?: Record<string, unknown>;
private readonly hooksConfig?: Record<string, unknown>;
private hookSystem?: HookSystem;
private messageBus?: MessageBus;
@ -761,9 +763,8 @@ export class Config {
enabledExtensionOverrides: this.overrideExtensions,
isWorkspaceTrusted: this.isTrustedFolder(),
});
this.enableHooks = params.enableHooks ?? false;
this.disableAllHooks = params.disableAllHooks ?? false;
this.hooks = params.hooks;
this.hooksConfig = params.hooksConfig;
}
/**
@ -788,7 +789,7 @@ export class Config {
this.debugLogger.debug('Extension manager initialized');
// Initialize hook system if enabled
if (this.enableHooks) {
if (!this.disableAllHooks) {
this.hookSystem = new HookSystem(this);
await this.hookSystem.initialize();
this.debugLogger.debug('Hook system initialized');
@ -1074,7 +1075,7 @@ export class Config {
// Fire auth_success notification hook (supports both interactive & non-interactive)
const messageBus = this.getMessageBus();
const hooksEnabled = this.getEnableHooks();
const hooksEnabled = !this.getDisableAllHooks();
if (hooksEnabled && messageBus) {
fireNotificationHook(
messageBus,
@ -1781,10 +1782,10 @@ export class Config {
}
/**
* Check if hooks are enabled.
* Check if all hooks are disabled.
*/
getEnableHooks(): boolean {
return this.enableHooks;
getDisableAllHooks(): boolean {
return this.disableAllHooks;
}
/**
@ -1803,17 +1804,6 @@ export class Config {
this.messageBus = messageBus;
}
/**
* Get the list of disabled hook names.
* This is used by the HookRegistry to filter out disabled hooks.
*/
getDisabledHooks(): string[] {
const hooksConfig = this.hooksConfig;
if (!hooksConfig) return [];
const disabled = hooksConfig['disabled'];
return Array.isArray(disabled) ? (disabled as string[]) : [];
}
/**
* Get project-level hooks configuration.
* This is used by the HookRegistry to load project-specific hooks.