summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/slashCommandProcessor.ts
diff options
context:
space:
mode:
authorSeth Troisi <[email protected]>2025-04-30 00:26:07 +0000
committerSeth Troisi <[email protected]>2025-04-30 22:17:08 +0000
commit5f5edb4c9bac24c4875ffc1a5a97ad8cf11f4436 (patch)
tree376f7f0863d0db0c354ec6f2212d16f9c20cd995 /packages/cli/src/ui/hooks/slashCommandProcessor.ts
parent68a3020044b3c8567641c8fdcd5a369366dab981 (diff)
Added bang(!) commands as a shell passthrough
Diffstat (limited to 'packages/cli/src/ui/hooks/slashCommandProcessor.ts')
-rw-r--r--packages/cli/src/ui/hooks/slashCommandProcessor.ts21
1 files changed, 11 insertions, 10 deletions
diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts
index 6608001b..f7f93b9d 100644
--- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts
+++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts
@@ -7,7 +7,7 @@
import { useCallback } from 'react';
import { type PartListUnion } from '@google/genai';
import { HistoryItem } from '../types.js';
-import { isSlashCommand } from '../utils/commandUtils.js';
+import { getCommandFromQuery } from '../utils/commandUtils.js';
export interface SlashCommand {
name: string; // slash command
@@ -88,30 +88,31 @@ export const useSlashCommandProcessor = (
// Removed /theme command, handled in App.tsx
];
- // Checks if the query is a slash command and executes it if it is.
+ // Checks if the query is a slash command and executes the command if it is.
const handleSlashCommand = useCallback(
(rawQuery: PartListUnion): boolean => {
if (typeof rawQuery !== 'string') {
return false;
}
- const trimmedQuery = rawQuery.trim();
- if (!isSlashCommand(trimmedQuery)) {
- return false; // Not a slash command
- }
+ const trimmed = rawQuery.trim();
+ const [symbol, test] = getCommandFromQuery(trimmed);
- const commandName = trimmedQuery.slice(1).split(/\s+/)[0]; // Get command name after '/'
+ // Skip non slash commands
+ if (symbol !== '/') {
+ return false;
+ }
for (const cmd of slashCommands) {
- if (commandName === cmd.name) {
+ if (test === cmd.name) {
// Add user message *before* execution
const userMessageTimestamp = Date.now();
addHistoryItem(
setHistory,
- { type: 'user', text: trimmedQuery },
+ { type: 'user', text: trimmed },
userMessageTimestamp,
);
- cmd.action(trimmedQuery);
+ cmd.action(trimmed);
return true; // Command was handled
}
}