mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-25 14:43:05 +09:00
Checkpoint: File edits
Automatic checkpoint created by Claude Code - Branch: v3 - Timestamp: 2026-01-07T19:26:56Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
533b919f30
commit
82cf740e6e
1 file changed
+59
-7
@@ -176,10 +176,11 @@ export const commands: Command[] = [
|
||||
|
||||
/**
|
||||
* Command registry map for quick lookup
|
||||
* Supports both sync (core commands) and async (lazy-loaded) commands
|
||||
*/
|
||||
export const commandRegistry = new Map<string, Command>();
|
||||
|
||||
// Register all commands and their aliases
|
||||
// Register core commands and their aliases
|
||||
for (const cmd of commands) {
|
||||
commandRegistry.set(cmd.name, cmd);
|
||||
if (cmd.aliases) {
|
||||
@@ -190,24 +191,46 @@ for (const cmd of commands) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get command by name
|
||||
* Get command by name (sync for core commands, returns undefined for lazy commands)
|
||||
* Use getCommandAsync for lazy-loaded commands
|
||||
*/
|
||||
export function getCommand(name: string): Command | undefined {
|
||||
return commandRegistry.get(name);
|
||||
return loadedCommands.get(name) || commandRegistry.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if command exists
|
||||
* Get command by name (async - supports lazy loading)
|
||||
*/
|
||||
export async function getCommandAsync(name: string): Promise<Command | undefined> {
|
||||
// Check already-loaded commands first
|
||||
const cached = loadedCommands.get(name);
|
||||
if (cached) return cached;
|
||||
|
||||
// Check sync registry
|
||||
const synced = commandRegistry.get(name);
|
||||
if (synced) return synced;
|
||||
|
||||
// Try lazy loading
|
||||
return loadCommand(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if command exists (sync check for core commands)
|
||||
*/
|
||||
export function hasCommand(name: string): boolean {
|
||||
return commandRegistry.has(name);
|
||||
return loadedCommands.has(name) || commandRegistry.has(name) || name in commandLoaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all command names (including aliases)
|
||||
* Get all command names (including aliases and lazy-loadable)
|
||||
*/
|
||||
export function getCommandNames(): string[] {
|
||||
return Array.from(commandRegistry.keys());
|
||||
const names = new Set([
|
||||
...Array.from(commandRegistry.keys()),
|
||||
...Array.from(loadedCommands.keys()),
|
||||
...Object.keys(commandLoaders),
|
||||
]);
|
||||
return Array.from(names);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,6 +240,25 @@ export function getUniqueCommands(): Command[] {
|
||||
return commands.filter(cmd => !cmd.hidden);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all commands (populates lazy-loaded commands)
|
||||
* Use this when you need all commands available synchronously
|
||||
*/
|
||||
export async function loadAllCommands(): Promise<Command[]> {
|
||||
const allCommands: Command[] = [...commands];
|
||||
|
||||
for (const name of Object.keys(commandLoaders)) {
|
||||
if (!loadedCommands.has(name)) {
|
||||
const cmd = await loadCommand(name);
|
||||
if (cmd && !allCommands.includes(cmd)) {
|
||||
allCommands.push(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return allCommands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup commands in a CLI instance
|
||||
*/
|
||||
@@ -225,3 +267,13 @@ export function setupCommands(cli: { command: (cmd: Command) => void }): void {
|
||||
cli.command(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup all commands including lazy-loaded (async)
|
||||
*/
|
||||
export async function setupAllCommands(cli: { command: (cmd: Command) => void }): Promise<void> {
|
||||
const allCommands = await loadAllCommands();
|
||||
for (const cmd of allCommands) {
|
||||
cli.command(cmd);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user