feat(hooks): Enable hooks in the CLI [ENG-1375] (#7948)

* feat(cli): Add hooks_enabled support to CLI settings

- Add hooks_enabled field to Settings proto message (field 134)
- Add hooks_enabled parsing to CLI settings parser
- Enables users to toggle hooks via -s hooks_enabled=true/false flag

Fixes missing CLI support for hooks that was available in the VSCode extension

* feat(hooks): Enable hooks in the CLI

* Add include back in after resolving merge conflict

* feat(hooks): Changes as per human code review feedback.

---------

Co-authored-by: NightTrek <Daniels@dual4t.com>
This commit is contained in:
CandiedUniverseandNightTrek authored and GitHub committed 2025-12-09 10:32:18 -08:00
1 parent 8ce7e132d2
commit dec215cd9c
14 files changed
+66 -17

No files matched your search

+1
View File
@@ -110,6 +110,7 @@ func (m *Manager) ListSettings(ctx context.Context) error {
"dictationSettings",
"autoCondenseThreshold",
"autoApprovalSettings",
"hooksEnabled",
}
// Render each field using the renderer
+1 -1
View File
@@ -79,7 +79,7 @@ func RenderField(key string, value interface{}, censor bool) error {
"planActSeparateModelsSetting", "enableCheckpointsSetting",
"terminalReuseEnabled", "mcpResponsesCollapsed", "strictPlanModeEnabled",
"useAutoCondense", "yoloModeToggled", "shellIntegrationTimeout",
"terminalOutputLineLimit", "autoCondenseThreshold":
"terminalOutputLineLimit", "autoCondenseThreshold", "hooksEnabled":
fmt.Printf("%s: %s\n", camelToKebab(key), formatValue(value, key, censor))
return nil
+6
View File
@@ -290,6 +290,12 @@ func setSimpleField(settings *cline.Settings, key, value string) error {
return err
}
settings.ActModeAwsBedrockCustomSelected = boolPtr(val)
case "hooks_enabled":
val, err := parseBool(value)
if err != nil {
return err
}
settings.HooksEnabled = boolPtr(val)
// Integer fields
case "request_timeout_ms":
+1
View File
@@ -228,6 +228,7 @@ message Settings {
optional string act_mode_aihubmix_model_id = 132;
optional OpenAiCompatibleModelInfo act_mode_aihubmix_model_info = 133;
optional bool cline_web_tools_enabled = 134;
optional bool hooks_enabled = 135;
}
message DictationSettings {
+4
View File
@@ -2,6 +2,7 @@ import * as vscode from "vscode"
import {
cleanupMcpMarketplaceCatalogFromGlobalState,
migrateCustomInstructionsToGlobalRules,
migrateHooksEnabledToBoolean,
migrateTaskHistoryToFile,
migrateWelcomeViewCompleted,
migrateWorkspaceToGlobalStorage,
@@ -62,6 +63,9 @@ export async function initialize(context: vscode.ExtensionContext): Promise<Webv
// Ensure taskHistory.json exists and migrate legacy state (runs once)
await migrateTaskHistoryToFile(context)
// Migrate hooksEnabled from ClineFeatureSetting to boolean (one-time cleanup)
await migrateHooksEnabledToBoolean(context)
// Clean up MCP marketplace catalog from global state (moved to disk cache)
await cleanupMcpMarketplaceCatalogFromGlobalState(context)
+1 -4
View File
@@ -989,14 +989,11 @@ export class Controller {
user: this.stateManager.getGlobalStateKey("multiRootEnabled"),
featureFlag: true, // Multi-root workspace is now always enabled
},
hooksEnabled: {
user: this.stateManager.getGlobalStateKey("hooksEnabled"),
featureFlag: featureFlagsService.getHooksEnabled(),
},
clineWebToolsEnabled: {
user: this.stateManager.getGlobalSettingsKey("clineWebToolsEnabled"),
featureFlag: featureFlagsService.getWebtoolsEnabled(),
},
hooksEnabled: this.stateManager.getGlobalSettingsKey("hooksEnabled"),
lastDismissedInfoBannerVersion,
lastDismissedModelBannerVersion,
remoteConfigSettings: this.stateManager.getRemoteConfigSettings(),
+12
View File
@@ -80,6 +80,18 @@ export async function newTask(controller: Controller, request: NewTaskRequest):
...(request.taskSettings?.actModeApiProvider !== undefined && {
actModeApiProvider: convertProtoToApiProvider(request.taskSettings.actModeApiProvider),
}),
...(request.taskSettings?.hooksEnabled !== undefined && {
hooksEnabled: (() => {
const isEnabled = !!request.taskSettings.hooksEnabled
// Platform validation: Only allow enabling hooks on macOS and Linux
if (isEnabled && process.platform === "win32") {
throw new Error("Hooks are not yet supported on Windows")
}
return isEnabled
})(),
}),
}).filter(([_, value]) => value !== undefined),
)
+33
View File
@@ -659,3 +659,36 @@ export async function cleanupMcpMarketplaceCatalogFromGlobalState(context: vscod
// Continue execution - cleanup failure shouldn't break extension startup
}
}
/**
* Legacy type definition for the old ClineFeatureSetting structure
*/
type LegacyHooksEnabled = { user?: boolean; featureFlag?: boolean }
/**
* Migrates hooksEnabled from ClineFeatureSetting {user: boolean, featureFlag: boolean} to boolean
*/
export async function migrateHooksEnabledToBoolean(context: vscode.ExtensionContext) {
try {
const hooksEnabled = await context.globalState.get("hooksEnabled")
// Check if hooksEnabled exists and is an object (the old ClineFeatureSetting structure)
if (hooksEnabled !== undefined && typeof hooksEnabled === "object" && hooksEnabled !== null) {
console.log("Migrating hooksEnabled from ClineFeatureSetting to boolean...")
// Cast to the legacy type to access properties safely
const legacySetting = hooksEnabled as LegacyHooksEnabled
// Extract the boolean value from the 'user' field
const booleanValue = legacySetting.user === true
// Update with the new boolean value
await context.globalState.update("hooksEnabled", booleanValue)
console.log(`Successfully migrated hooksEnabled to boolean: ${booleanValue}`)
}
} catch (error) {
console.error("Failed to migrate hooksEnabled to boolean:", error)
// Continue execution - migration failure shouldn't break extension startup
}
}
+1 -1
View File
@@ -101,7 +101,7 @@ export interface ExtensionState {
lastDismissedInfoBannerVersion: number
lastDismissedModelBannerVersion: number
lastDismissedCliBannerVersion: number
hooksEnabled?: ClineFeatureSetting
hooksEnabled?: boolean
remoteConfigSettings?: Partial<RemoteConfigFields>
subagentsEnabled?: boolean
nativeToolCallSetting?: boolean
-1
View File
@@ -49,7 +49,6 @@ export interface GlobalState {
workspaceRoots: WorkspaceRoot[] | undefined
primaryRootIndex: number
multiRootEnabled: boolean
hooksEnabled: boolean
lastDismissedInfoBannerVersion: number
lastDismissedModelBannerVersion: number
lastDismissedCliBannerVersion: number
+2 -3
View File
@@ -62,9 +62,8 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
const task = useMemo(() => messages.at(0), [messages]) // leaving this less safe version here since if the first message is not a task, then the extension is in a bad state and needs to be debugged (see Cline.abort)
const modifiedMessages = useMemo(() => {
const slicedMessages = messages.slice(1)
// Only combine hook sequences if hooks are enabled (both user setting and feature flag)
const areHooksEnabled = hooksEnabled?.user
const withHooks = areHooksEnabled ? combineHookSequences(slicedMessages) : slicedMessages
// Only combine hook sequences if hooks are enabled
const withHooks = hooksEnabled ? combineHookSequences(slicedMessages) : slicedMessages
return combineErrorRetryMessages(combineApiRequests(combineCommandSequences(withHooks)))
}, [messages, hooksEnabled])
// has to be after api_req_finished are all reduced into api_req_started messages
@@ -62,8 +62,7 @@ const ClineRulesToggleModal: React.FC = () => {
// Auto-switch to rules tab if hooks become disabled while viewing hooks tab
useEffect(() => {
const areHooksEnabled = hooksEnabled?.user
if (currentView === "hooks" && !areHooksEnabled) {
if (currentView === "hooks" && !hooksEnabled) {
setCurrentView("rules")
}
}, [currentView, hooksEnabled])
@@ -415,7 +414,7 @@ const ClineRulesToggleModal: React.FC = () => {
<TabButton isActive={currentView === "workflows"} onClick={() => setCurrentView("workflows")}>
Workflows
</TabButton>
{hooksEnabled?.user && (
{hooksEnabled && (
<TabButton isActive={currentView === "hooks"} onClick={() => setCurrentView("hooks")}>
Hooks
</TabButton>
@@ -376,7 +376,7 @@ const FeatureSettingsSection = ({ renderSectionHeader }: FeatureSettingsSectionP
)}
<div className="mt-2.5">
<VSCodeCheckbox
checked={hooksEnabled?.user}
checked={hooksEnabled}
disabled={!isMacOSOrLinux()}
onChange={(e: any) => {
const checked = e.target.checked === true
@@ -1,7 +1,6 @@
import { DEFAULT_AUTO_APPROVAL_SETTINGS } from "@shared/AutoApprovalSettings"
import { findLastIndex } from "@shared/array"
import { DEFAULT_BROWSER_SETTINGS } from "@shared/BrowserSettings"
import { ClineFeatureSetting } from "@shared/ClineFeatureSetting"
import { DEFAULT_DICTATION_SETTINGS, DictationSettings } from "@shared/DictationSettings"
import { DEFAULT_PLATFORM, type ExtensionState } from "@shared/ExtensionMessage"
import { DEFAULT_FOCUS_CHAIN_SETTINGS } from "@shared/FocusChainSettings"
@@ -51,7 +50,6 @@ export interface ExtensionStateContextType extends ExtensionState {
// View state
showMcp: boolean
hooksEnabled?: ClineFeatureSetting
mcpTab?: McpViewTab
showSettings: boolean
settingsTargetSection?: string
@@ -249,7 +247,7 @@ export const ExtensionStateContextProvider: React.FC<{
primaryRootIndex: 0,
isMultiRootWorkspace: false,
multiRootSetting: { user: false, featureFlag: false },
hooksEnabled: { user: false, featureFlag: false },
hooksEnabled: false,
nativeToolCallSetting: false,
})
const [expandTaskHeader, setExpandTaskHeader] = useState(true)