feat: add custom slash commands support (#384)

Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
Charles Packer
2025-12-24 14:56:42 -08:00
committed by GitHub
parent 1f35f403c0
commit 552a006e97
4 changed files with 405 additions and 34 deletions

View File

@@ -1,5 +1,5 @@
import { Box, Text, useInput } from "ink";
import { useCallback, useMemo, useState } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
import { getVersion } from "../../version";
import { commands } from "../commands/registry";
import { colors } from "./colors";
@@ -28,18 +28,34 @@ export function HelpDialog({ onClose }: HelpDialogProps) {
const [activeTab, setActiveTab] = useState<HelpTab>("commands");
const [currentPage, setCurrentPage] = useState(0);
const [selectedIndex, setSelectedIndex] = useState(0);
const [customCommands, setCustomCommands] = useState<CommandItem[]>([]);
// Get all non-hidden commands, sorted by order
// Load custom commands once on mount
useEffect(() => {
import("../commands/custom.js").then(({ getCustomCommands }) => {
getCustomCommands().then((customs) => {
setCustomCommands(
customs.map((cmd) => ({
name: `/${cmd.id}`,
description: `${cmd.description} (${cmd.source}${cmd.namespace ? `:${cmd.namespace}` : ""})`,
order: 200 + (cmd.source === "project" ? 0 : 100),
})),
);
});
});
}, []);
// Get all non-hidden commands, sorted by order (includes custom commands)
const allCommands = useMemo<CommandItem[]>(() => {
return Object.entries(commands)
const builtins = Object.entries(commands)
.filter(([_, cmd]) => !cmd.hidden)
.map(([name, cmd]) => ({
name,
description: cmd.desc,
order: cmd.order ?? 100,
}))
.sort((a, b) => a.order - b.order);
}, []);
}));
return [...builtins, ...customCommands].sort((a, b) => a.order - b.order);
}, [customCommands]);
// Keyboard shortcuts
const shortcuts = useMemo<ShortcutItem[]>(() => {