From 29dec8580f4c37ee5e743d7dbaabe94334bf963a Mon Sep 17 00:00:00 2001 From: marius-kilocode Date: Thu, 6 Aug 2026 16:22:13 +0200 Subject: [PATCH 1/2] refactor(agent-manager): extract keybinding defaults into keybind-defaults.ts Move the platform-aware defaultBindings map (and its MAX_JUMP_INDEX helper) out of AgentManagerApp.tsx into a vscode-free helper module, following the documented extraction pattern for capped files. This reduces AgentManagerApp.tsx from 2808 to 2781 lines and lowers the ESLint max-lines cap from 2800 to 2785 to lock in the improvement. --- packages/kilo-vscode/eslint.config.mjs | 8 ++--- .../agent-manager/AgentManagerApp.tsx | 29 +----------------- .../agent-manager/keybind-defaults.ts | 30 +++++++++++++++++++ 3 files changed, 35 insertions(+), 32 deletions(-) create mode 100644 packages/kilo-vscode/webview-ui/agent-manager/keybind-defaults.ts diff --git a/packages/kilo-vscode/eslint.config.mjs b/packages/kilo-vscode/eslint.config.mjs index 8aedaac465c..5db05cfbe92 100644 --- a/packages/kilo-vscode/eslint.config.mjs +++ b/packages/kilo-vscode/eslint.config.mjs @@ -43,10 +43,10 @@ export default [ }, { files: ["webview-ui/agent-manager/AgentManagerApp.tsx"], - // Lowered 3210 → 2800 after extracting the sidebar body (SidebarBody.tsx) - // and the tab bar (TabBar.tsx) into components. Keep shrinking as more - // logic moves out; do not raise. - rules: { complexity: ["error", 74], "max-lines": ["error", 2800] }, + // Lowered 3210 → 2800 → 2785 after extracting the sidebar body (SidebarBody.tsx), + // the tab bar (TabBar.tsx) into components, and the keybinding defaults + // (keybind-defaults.ts). Keep shrinking as more logic moves out; do not raise. + rules: { complexity: ["error", 74], "max-lines": ["error", 2785] }, }, { files: ["src/agent-manager/AgentManagerProvider.ts"], diff --git a/packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx b/packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx index 615ebb350d0..e95775758df 100644 --- a/packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx +++ b/packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx @@ -199,37 +199,10 @@ interface SetupState { type SidebarSelection = typeof LOCAL | string | null type SidePanel = "diff" | "pr" | "terminal" | null const isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent) -// Fallback keybindings before extension sends resolved ones -const MAX_JUMP_INDEX = 9 const SIDE_RESIZE_INTERVAL_MS = 32 -const defaultBindings: Record = { - previousSession: isMac ? "⌘⌥↑" : "Ctrl+Alt+↑", - nextSession: isMac ? "⌘⌥↓" : "Ctrl+Alt+↓", - previousTab: isMac ? "⌘⌥←" : "Ctrl+Alt+←", - nextTab: isMac ? "⌘⌥→" : "Ctrl+Alt+→", - search: isMac ? "⌘F" : "Ctrl+F", - showTerminal: isMac ? "⌘/" : "Ctrl+/", - newTerminal: isMac ? "⌘⇧T" : "Ctrl+Shift+T", - runScript: isMac ? "⌘E" : "Ctrl+E", - toggleDiff: isMac ? "⌘D" : "Ctrl+D", - showShortcuts: isMac ? "⌘⇧/" : "Ctrl+Shift+/", - newTab: isMac ? "⌘T" : "Ctrl+T", - closeTab: isMac ? "⌘W" : "Ctrl+W", - newWorktree: isMac ? "⌘N" : "Ctrl+N", - quickWorktree: isMac ? "⌘⇧N" : "Ctrl+Shift+N", - closeWorktree: isMac ? "⌘⇧W" : "Ctrl+Shift+W", - openWorktree: isMac ? "⌘⇧O" : "Ctrl+Shift+O", - openPR: isMac ? "⌘⇧R" : "Ctrl+Shift+R", - agentManagerOpen: isMac ? "⌘⇧M" : "Ctrl+Shift+M", - cycleAgentMode: isMac ? "⌘." : "Ctrl+.", - cyclePreviousAgentMode: isMac ? "⌘⇧." : "Ctrl+Shift+.", - ...Object.fromEntries( - Array.from({ length: MAX_JUMP_INDEX }, (_, i) => [`jumpTo${i + 1}`, isMac ? `⌘${i + 1}` : `Ctrl+${i + 1}`]), - ), -} - import { parseBindingTokens } from "./keybind-tokens" +import { defaultBindings } from "./keybind-defaults" const AgentManagerContent: Component = () => { const { t } = useLanguage() diff --git a/packages/kilo-vscode/webview-ui/agent-manager/keybind-defaults.ts b/packages/kilo-vscode/webview-ui/agent-manager/keybind-defaults.ts new file mode 100644 index 00000000000..9ec6bd79552 --- /dev/null +++ b/packages/kilo-vscode/webview-ui/agent-manager/keybind-defaults.ts @@ -0,0 +1,30 @@ +const isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent) + +const MAX_JUMP_INDEX = 9 + +/** Fallback keybindings before the extension sends resolved ones. */ +export const defaultBindings: Record = { + previousSession: isMac ? "⌘⌥↑" : "Ctrl+Alt+↑", + nextSession: isMac ? "⌘⌥↓" : "Ctrl+Alt+↓", + previousTab: isMac ? "⌘⌥←" : "Ctrl+Alt+←", + nextTab: isMac ? "⌘⌥→" : "Ctrl+Alt+→", + search: isMac ? "⌘F" : "Ctrl+F", + showTerminal: isMac ? "⌘/" : "Ctrl+/", + newTerminal: isMac ? "⌘⇧T" : "Ctrl+Shift+T", + runScript: isMac ? "⌘E" : "Ctrl+E", + toggleDiff: isMac ? "⌘D" : "Ctrl+D", + showShortcuts: isMac ? "⌘⇧/" : "Ctrl+Shift+/", + newTab: isMac ? "⌘T" : "Ctrl+T", + closeTab: isMac ? "⌘W" : "Ctrl+W", + newWorktree: isMac ? "⌘N" : "Ctrl+N", + quickWorktree: isMac ? "⌘⇧N" : "Ctrl+Shift+N", + closeWorktree: isMac ? "⌘⇧W" : "Ctrl+Shift+W", + openWorktree: isMac ? "⌘⇧O" : "Ctrl+Shift+O", + openPR: isMac ? "⌘⇧R" : "Ctrl+Shift+R", + agentManagerOpen: isMac ? "⌘⇧M" : "Ctrl+Shift+M", + cycleAgentMode: isMac ? "⌘." : "Ctrl+.", + cyclePreviousAgentMode: isMac ? "⌘⇧." : "Ctrl+Shift+.", + ...Object.fromEntries( + Array.from({ length: MAX_JUMP_INDEX }, (_, i) => [`jumpTo${i + 1}`, isMac ? `⌘${i + 1}` : `Ctrl+${i + 1}`]), + ), +} From 07b45a348b7038ef705e6e5b6fc1458b637a057d Mon Sep 17 00:00:00 2001 From: marius-kilocode Date: Thu, 6 Aug 2026 16:56:26 +0200 Subject: [PATCH 2/2] test(agent-manager): read keybinding literals from keybind-defaults.ts The defaultBindings map moved out of AgentManagerApp.tsx into keybind-defaults.ts, so the source-content assertion that checked for the newWorktree/quickWorktree literals against AgentManagerApp.tsx no longer holds. Point it at the new file instead. --- packages/kilo-vscode/tests/unit/agent-manager-arch.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/kilo-vscode/tests/unit/agent-manager-arch.test.ts b/packages/kilo-vscode/tests/unit/agent-manager-arch.test.ts index 3d41e4e7dcd..6b7e8e2de75 100644 --- a/packages/kilo-vscode/tests/unit/agent-manager-arch.test.ts +++ b/packages/kilo-vscode/tests/unit/agent-manager-arch.test.ts @@ -64,6 +64,7 @@ const TSX_FILES = [ path.join(ROOT, "webview-ui/diff-viewer/BaseBranchPicker.tsx"), ] const TSX_FILE = TSX_FILES[0]! +const KEYBIND_DEFAULTS_FILE = path.join(ROOT, "webview-ui/agent-manager/keybind-defaults.ts") const PROVIDER_FILE = path.join(ROOT, "src/agent-manager/AgentManagerProvider.ts") const DIFF_CONTROLLER_FILE = path.join(ROOT, "src/agent-manager/worktree-diff-controller.ts") const IMPORTER_FILE = path.join(ROOT, "src/agent-manager/worktree-importer.ts") @@ -365,7 +366,6 @@ describe("Agent Manager Worktree Actions", () => { const manifest = JSON.parse(fs.readFileSync(path.join(ROOT, "package.json"), "utf-8")) as { contributes: { keybindings: { command: string; key?: string; mac?: string }[] } } - const source = fs.readFileSync(TSX_FILE, "utf-8") const dialog = manifest.contributes.keybindings.find( (item) => item.command === "kilo-code.new.agentManager.newWorktree", ) @@ -375,8 +375,9 @@ describe("Agent Manager Worktree Actions", () => { expect(dialog).toMatchObject({ key: "ctrl+n", mac: "cmd+n" }) expect(quick).toMatchObject({ key: "ctrl+shift+n", mac: "cmd+shift+n" }) - expect(source).toContain('newWorktree: isMac ? "⌘N" : "Ctrl+N"') - expect(source).toContain('quickWorktree: isMac ? "⌘⇧N" : "Ctrl+Shift+N"') + const bindings = fs.readFileSync(KEYBIND_DEFAULTS_FILE, "utf-8") + expect(bindings).toContain('newWorktree: isMac ? "⌘N" : "Ctrl+N"') + expect(bindings).toContain('quickWorktree: isMac ? "⌘⇧N" : "Ctrl+Shift+N"') }) it("forwards the quick-worktree command to immediate creation", () => {