Add keyboard shortcut 'W' for creating new agent session

- Added newSession shortcut to ACTION_SHORTCUTS in use-keyboard-shortcuts.ts
- Updated SessionManager to expose quick create function via ref
- Updated AgentView to register the shortcut and trigger new session creation
- Display shortcut key indicator (W) on the New session button
- Updated feature_list.json to mark feature as verified

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Cody Seibert
2025-12-09 08:56:58 -05:00
parent 243c41d359
commit 9a6e6ea594
4 changed files with 64 additions and 3 deletions

View File

@@ -54,6 +54,6 @@
"category": "Agent Runner",
"description": "Can you please add a shortcut for starting a new session?",
"steps": [],
"status": "backlog"
"status": "verified"
}
]
]

View File

@@ -24,6 +24,7 @@ import {
} from "lucide-react";
import { cn } from "@/lib/utils";
import type { SessionListItem } from "@/types/electron";
import { ACTION_SHORTCUTS } from "@/hooks/use-keyboard-shortcuts";
// Random session name generator
const adjectives = [
@@ -50,6 +51,7 @@ interface SessionManagerProps {
onSelectSession: (sessionId: string | null) => void;
projectPath: string;
isCurrentSessionThinking?: boolean;
onQuickCreateRef?: React.MutableRefObject<(() => Promise<void>) | null>;
}
export function SessionManager({
@@ -57,6 +59,7 @@ export function SessionManager({
onSelectSession,
projectPath,
isCurrentSessionThinking = false,
onQuickCreateRef,
}: SessionManagerProps) {
const [sessions, setSessions] = useState<SessionListItem[]>([]);
const [activeTab, setActiveTab] = useState<"active" | "archived">("active");
@@ -118,6 +121,18 @@ export function SessionManager({
}
};
// Expose the quick create function via ref for keyboard shortcuts
useEffect(() => {
if (onQuickCreateRef) {
onQuickCreateRef.current = handleQuickCreateSession;
}
return () => {
if (onQuickCreateRef) {
onQuickCreateRef.current = null;
}
};
}, [onQuickCreateRef, projectPath]);
// Rename session
const handleRenameSession = async (sessionId: string) => {
if (!editingName.trim() || !window.electronAPI?.sessions) return;
@@ -192,9 +207,13 @@ export function SessionManager({
size="sm"
onClick={handleQuickCreateSession}
data-testid="new-session-button"
title={`New Session (${ACTION_SHORTCUTS.newSession})`}
>
<Plus className="w-4 h-4 mr-1" />
New
<span className="ml-1.5 px-1.5 py-0.5 text-[10px] font-mono rounded bg-white/20 text-white/80">
{ACTION_SHORTCUTS.newSession}
</span>
</Button>
)}
</div>

View File

@@ -1,6 +1,6 @@
"use client";
import { useState, useCallback, useRef, useEffect } from "react";
import { useState, useCallback, useRef, useEffect, useMemo } from "react";
import { useAppStore } from "@/store/app-store";
import { Card, CardContent } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
@@ -23,6 +23,11 @@ import { cn } from "@/lib/utils";
import { useElectronAgent } from "@/hooks/use-electron-agent";
import { SessionManager } from "@/components/session-manager";
import type { ImageAttachment } from "@/store/app-store";
import {
useKeyboardShortcuts,
ACTION_SHORTCUTS,
KeyboardShortcut,
} from "@/hooks/use-keyboard-shortcuts";
export function AgentView() {
const { currentProject } = useAppStore();
@@ -41,6 +46,9 @@ export function AgentView() {
// Input ref for auto-focus
const inputRef = useRef<HTMLInputElement>(null);
// Ref for quick create session function from SessionManager
const quickCreateSessionRef = useRef<(() => Promise<void>) | null>(null);
// Use the Electron agent hook (only if we have a session)
const {
messages,
@@ -369,6 +377,29 @@ export function AgentView() {
}
}, [currentSessionId]);
// Keyboard shortcuts for agent view
const agentShortcuts: KeyboardShortcut[] = useMemo(() => {
const shortcuts: KeyboardShortcut[] = [];
// New session shortcut - only when in agent view with a project
if (currentProject) {
shortcuts.push({
key: ACTION_SHORTCUTS.newSession,
action: () => {
if (quickCreateSessionRef.current) {
quickCreateSessionRef.current();
}
},
description: "Create new session",
});
}
return shortcuts;
}, [currentProject]);
// Register keyboard shortcuts
useKeyboardShortcuts(agentShortcuts);
if (!currentProject) {
return (
<div
@@ -413,6 +444,7 @@ export function AgentView() {
onSelectSession={setCurrentSessionId}
projectPath={currentProject.path}
isCurrentSessionThinking={isProcessing}
onQuickCreateRef={quickCreateSessionRef}
/>
</div>
)}

View File

@@ -100,10 +100,20 @@ export const NAV_SHORTCUTS: Record<string, string> = {
settings: "S", // S for Settings
};
/**
* Shortcut definitions for UI controls
*/
export const UI_SHORTCUTS: Record<string, string> = {
toggleSidebar: "`", // Backtick to toggle sidebar
};
/**
* Shortcut definitions for add buttons
*/
export const ACTION_SHORTCUTS: Record<string, string> = {
addFeature: "N", // N for New feature
addContextFile: "F", // F for File (add context file)
startNext: "Q", // Q for Queue (start next features from backlog)
newSession: "W", // W for new session (in agent view)
openProject: "O", // O for Open project (navigate to welcome view)
};