summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/slashCommandProcessor.ts
diff options
context:
space:
mode:
authorAbhi <[email protected]>2025-07-20 16:57:34 -0400
committerGitHub <[email protected]>2025-07-20 20:57:34 +0000
commit2a95c8287ed3b6fc38e7dcec5f0a19b9e2d843e7 (patch)
tree1a9ffb6be8468aa44e54bfcb8ae2f961b970cf9a /packages/cli/src/ui/hooks/slashCommandProcessor.ts
parent7a9821607bafcbb98cf059705aaab358d46e711c (diff)
prefactor(commands): Command Service Prefactor for Extensible Commands (#4511)
Diffstat (limited to 'packages/cli/src/ui/hooks/slashCommandProcessor.ts')
-rw-r--r--packages/cli/src/ui/hooks/slashCommandProcessor.ts21
1 files changed, 15 insertions, 6 deletions
diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts
index b56adeaf..cdf071b1 100644
--- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts
+++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts
@@ -21,6 +21,7 @@ import {
import { LoadedSettings } from '../../config/settings.js';
import { type CommandContext, type SlashCommand } from '../commands/types.js';
import { CommandService } from '../../services/CommandService.js';
+import { BuiltinCommandLoader } from '../../services/BuiltinCommandLoader.js';
/**
* Hook to define and process slash commands (e.g., /help, /clear).
@@ -42,7 +43,7 @@ export const useSlashCommandProcessor = (
openPrivacyNotice: () => void,
) => {
const session = useSessionStats();
- const [commands, setCommands] = useState<SlashCommand[]>([]);
+ const [commands, setCommands] = useState<readonly SlashCommand[]>([]);
const gitService = useMemo(() => {
if (!config?.getProjectRoot()) {
return;
@@ -158,16 +159,24 @@ export const useSlashCommandProcessor = (
],
);
- const commandService = useMemo(() => new CommandService(config), [config]);
-
useEffect(() => {
+ const controller = new AbortController();
const load = async () => {
- await commandService.loadCommands();
+ // TODO - Add other loaders for custom commands.
+ const loaders = [new BuiltinCommandLoader(config)];
+ const commandService = await CommandService.create(
+ loaders,
+ controller.signal,
+ );
setCommands(commandService.getCommands());
};
load();
- }, [commandService]);
+
+ return () => {
+ controller.abort();
+ };
+ }, [config]);
const handleSlashCommand = useCallback(
async (
@@ -199,7 +208,7 @@ export const useSlashCommandProcessor = (
for (const part of commandPath) {
const foundCommand = currentCommands.find(
- (cmd) => cmd.name === part || cmd.altName === part,
+ (cmd) => cmd.name === part || cmd.altNames?.includes(part),
);
if (foundCommand) {