Some checks failed
Release Binaries / release (push) Has been cancelled
Features: - Binary-Free Mode: No OpenCode binary required - NomadArch Native mode with free Zen models - Native session management - Provider routing (Zen, Qwen, Z.AI) - Fixed MCP connection with explicit connectAll() - Updated installers and launchers for all platforms - UI binary selector with Native option Free Models Available: - GPT-5 Nano (400K context) - Grok Code Fast 1 (256K context) - GLM-4.7 (205K context) - Doubao Seed Code (256K context) - Big Pickle (200K context)
69 lines
1.5 KiB
TypeScript
69 lines
1.5 KiB
TypeScript
export interface KeyboardShortcut {
|
|
key: string
|
|
meta?: boolean
|
|
ctrl?: boolean
|
|
shift?: boolean
|
|
alt?: boolean
|
|
}
|
|
|
|
export interface Command {
|
|
id: string
|
|
label: string | (() => string)
|
|
description: string
|
|
keywords?: string[]
|
|
shortcut?: KeyboardShortcut
|
|
action: () => void | Promise<void>
|
|
category?: string
|
|
}
|
|
|
|
export function createCommandRegistry() {
|
|
const commands = new Map<string, Command>()
|
|
|
|
function register(command: Command) {
|
|
commands.set(command.id, command)
|
|
}
|
|
|
|
function unregister(id: string) {
|
|
commands.delete(id)
|
|
}
|
|
|
|
function get(id: string) {
|
|
return commands.get(id)
|
|
}
|
|
|
|
function getAll() {
|
|
return Array.from(commands.values())
|
|
}
|
|
|
|
function execute(id: string) {
|
|
const command = commands.get(id)
|
|
if (command) {
|
|
return command.action()
|
|
}
|
|
}
|
|
|
|
function search(query: string) {
|
|
if (!query) return getAll()
|
|
|
|
const lowerQuery = query.toLowerCase()
|
|
return getAll().filter((cmd) => {
|
|
const label = typeof cmd.label === "function" ? cmd.label() : cmd.label
|
|
const labelMatch = label.toLowerCase().includes(lowerQuery)
|
|
const descMatch = cmd.description.toLowerCase().includes(lowerQuery)
|
|
const keywordMatch = cmd.keywords?.some((k) => k.toLowerCase().includes(lowerQuery))
|
|
return labelMatch || descMatch || keywordMatch
|
|
})
|
|
}
|
|
|
|
return {
|
|
register,
|
|
unregister,
|
|
get,
|
|
getAll,
|
|
execute,
|
|
search,
|
|
}
|
|
}
|
|
|
|
export type CommandRegistry = ReturnType<typeof createCommandRegistry>
|