Shared memory and context tools for agentic work.
Code Rooms
import { useEffect } from 'react';
export interface ShortcutHandlers {
onCommandPalette?: () => void; // Cmd+K / Ctrl+K
onEscape?: () => void; // Escape
onClearGraph?: () => void; // Ctrl+Backspace
onIngest?: () => void; // Ctrl+I
}
/**
* Register global keyboard shortcuts.
* Handlers are stable refs — safe to pass inline functions (updated each render).
*/
export function useKeyboardShortcuts(handlers: ShortcutHandlers) {
useEffect(() => {
function handleKeyDown(e: KeyboardEvent) {
const meta = e.metaKey || e.ctrlKey;
if (meta && e.key === 'k') {
e.preventDefault();
handlers.onCommandPalette?.();
return;
if (e.key === 'Escape') {
handlers.onEscape?.();
if (meta && e.key === 'Backspace') {
handlers.onClearGraph?.();
if (meta && e.key === 'i') {
handlers.onIngest?.();
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
});