feat(composer): list skills with slash commands (#7737)
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com>
This commit is contained in:
11 files changed
+255
-21
No files matched your search
@@ -119,6 +119,7 @@ const CommandRow = memo(function CommandRow(props: {
|
||||
readonly item: ComposerCommandItem;
|
||||
readonly onPress: () => void;
|
||||
readonly isLast: boolean;
|
||||
readonly isSlashSkill: boolean;
|
||||
}) {
|
||||
const iconName = itemIcon(props.item);
|
||||
const iconColor = useThemeColor("--color-icon-subtle");
|
||||
@@ -144,7 +145,14 @@ const CommandRow = memo(function CommandRow(props: {
|
||||
<SymbolView name={iconName} size={14} tintColor={iconColor} type="monochrome" />
|
||||
) : null}
|
||||
<Text className="shrink-0 text-base font-t3-medium text-foreground" numberOfLines={1}>
|
||||
{props.item.label}
|
||||
{props.isSlashSkill && props.item.type === "skill" ? (
|
||||
<>
|
||||
<Text className="text-foreground-muted">skill:</Text>
|
||||
{props.item.skill.name}
|
||||
</>
|
||||
) : (
|
||||
props.item.label
|
||||
)}
|
||||
</Text>
|
||||
{props.item.description ? (
|
||||
<Text className="min-w-0 flex-1 text-xs text-foreground-muted" numberOfLines={1}>
|
||||
@@ -181,6 +189,7 @@ export const ComposerCommandPopover = memo(function ComposerCommandPopover(
|
||||
item={item}
|
||||
onPress={() => props.onSelect(item)}
|
||||
isLast={index === props.items.length - 1}
|
||||
isSlashSkill={props.triggerKind === "slash-command" && item.type === "skill"}
|
||||
/>
|
||||
))}
|
||||
</ScrollView>
|
||||
|
||||
@@ -67,6 +67,7 @@ import {
|
||||
import { resolveProviderOptionDescriptors } from "../../lib/providerOptions";
|
||||
import { useComposerPathSearch } from "../../state/use-composer-path-search";
|
||||
import { ComposerCommandPopover, type ComposerCommandItem } from "./ComposerCommandPopover";
|
||||
import { matchesSlashSkillQuery } from "./composerSlashSkillSearch";
|
||||
import {
|
||||
type ExistingThreadSettingsRouteSession,
|
||||
useExistingThreadSettingsRoutePresentation,
|
||||
@@ -430,7 +431,17 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
});
|
||||
}
|
||||
|
||||
return [...builtIn, ...providerCommands];
|
||||
const skillItems = (selectedProviderStatus?.skills ?? [])
|
||||
.filter((skill) => matchesSlashSkillQuery(skill, q))
|
||||
.map((skill) => ({
|
||||
id: `skill:${skill.name}`,
|
||||
type: "skill" as const,
|
||||
skill,
|
||||
label: `skill:${skill.name}`,
|
||||
description: skill.shortDescription ?? skill.description ?? "",
|
||||
}));
|
||||
|
||||
return [...builtIn, ...providerCommands, ...skillItems];
|
||||
}
|
||||
|
||||
if (composerTrigger.kind === "skill") {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { matchesSlashSkillQuery } from "./composerSlashSkillSearch";
|
||||
|
||||
const browserSkill = {
|
||||
name: "browser",
|
||||
path: "/skills/browser/SKILL.md",
|
||||
enabled: true,
|
||||
shortDescription: "Open and control the in-app browser",
|
||||
};
|
||||
|
||||
describe("matchesSlashSkillQuery", () => {
|
||||
it("matches the rendered skill prefix", () => {
|
||||
expect(matchesSlashSkillQuery(browserSkill, "skill")).toBe(true);
|
||||
expect(matchesSlashSkillQuery(browserSkill, "skill:brow")).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { ServerProviderSkill } from "@t3tools/contracts";
|
||||
|
||||
export function matchesSlashSkillQuery(skill: ServerProviderSkill, query: string): boolean {
|
||||
if (!skill.enabled) return false;
|
||||
const normalizedQuery = query.toLowerCase();
|
||||
const skillQuery =
|
||||
normalizedQuery === "skill"
|
||||
? ""
|
||||
: normalizedQuery.startsWith("skill:")
|
||||
? normalizedQuery.slice("skill:".length)
|
||||
: normalizedQuery;
|
||||
if (!skillQuery) return true;
|
||||
return [skill.name, skill.displayName, skill.shortDescription, skill.description].some((value) =>
|
||||
value?.toLowerCase().includes(skillQuery),
|
||||
);
|
||||
}
|
||||
@@ -1117,10 +1117,24 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
}),
|
||||
);
|
||||
const query = composerTrigger.query.trim().toLowerCase();
|
||||
const slashCommandItems = [...builtInSlashCommandItems, ...providerSlashCommandItems];
|
||||
if (!query) {
|
||||
return slashCommandItems;
|
||||
}
|
||||
const skillItems = (selectedProviderStatus?.skills ?? [])
|
||||
.filter((skill) => skill.enabled)
|
||||
.map((skill) => ({
|
||||
id: `skill:${selectedProvider}:${skill.name}`,
|
||||
type: "skill" as const,
|
||||
provider: selectedProvider,
|
||||
skill,
|
||||
label: `skill:${skill.name}`,
|
||||
description:
|
||||
skill.shortDescription ??
|
||||
skill.description ??
|
||||
(skill.scope ? `${skill.scope} skill` : ""),
|
||||
}));
|
||||
const slashCommandItems = [
|
||||
...builtInSlashCommandItems,
|
||||
...providerSlashCommandItems,
|
||||
...skillItems,
|
||||
];
|
||||
return searchSlashCommandItems(slashCommandItems, query);
|
||||
}
|
||||
if (composerTrigger.kind === "skill") {
|
||||
|
||||
@@ -86,4 +86,36 @@ describe("ComposerCommandMenu", () => {
|
||||
expect(markup).toContain("<svg");
|
||||
expect(markup).toContain("text-icon-muted");
|
||||
});
|
||||
|
||||
it("renders slash skill results with only the skill prefix dimmed", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ComposerCommandMenu
|
||||
items={[
|
||||
{
|
||||
id: "skill:codex:browser",
|
||||
type: "skill",
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
skill: {
|
||||
name: "browser",
|
||||
path: "/skills/browser/SKILL.md",
|
||||
enabled: true,
|
||||
},
|
||||
label: "skill:browser",
|
||||
description: "Open and control the in-app browser",
|
||||
},
|
||||
]}
|
||||
resolvedTheme="dark"
|
||||
isLoading={false}
|
||||
triggerKind="slash-command"
|
||||
activeItemId="skill:codex:browser"
|
||||
onHighlightedItemChange={() => {}}
|
||||
onSelect={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain('<span class="text-secondary-label">skill:</span>browser');
|
||||
expect(markup).toContain("Open and control the in-app browser");
|
||||
expect(markup).not.toContain("font-medium text-secondary-label");
|
||||
expect(markup).not.toContain("<svg");
|
||||
});
|
||||
});
|
||||
@@ -99,6 +99,7 @@ export const ComposerCommandMenu = memo(function ComposerCommandMenu(props: {
|
||||
<ComposerCommandMenuItem
|
||||
key={item.id}
|
||||
item={item}
|
||||
triggerKind={props.triggerKind}
|
||||
resolvedTheme={props.resolvedTheme}
|
||||
isActive={props.activeItemId === item.id}
|
||||
onHighlight={props.onHighlightedItemChange}
|
||||
@@ -130,6 +131,7 @@ export const ComposerCommandMenu = memo(function ComposerCommandMenu(props: {
|
||||
|
||||
const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: {
|
||||
item: ComposerCommandItem;
|
||||
triggerKind: ComposerTriggerKind | null;
|
||||
resolvedTheme: "light" | "dark";
|
||||
isActive: boolean;
|
||||
onHighlight: (itemId: string | null) => void;
|
||||
@@ -137,6 +139,8 @@ const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: {
|
||||
}) {
|
||||
const skillSourceKind =
|
||||
props.item.type === "skill" ? resolveProviderSkillSourceKind(props.item.skill) : null;
|
||||
const slashSkill =
|
||||
props.triggerKind === "slash-command" && props.item.type === "skill" ? props.item.skill : null;
|
||||
|
||||
return (
|
||||
<CommandItem
|
||||
@@ -162,11 +166,20 @@ const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: {
|
||||
kind={props.item.pathKind}
|
||||
theme={props.resolvedTheme}
|
||||
/>
|
||||
) : skillSourceKind ? (
|
||||
) : skillSourceKind && !slashSkill ? (
|
||||
<SkillSourceIcon kind={skillSourceKind} />
|
||||
) : null}
|
||||
<span className="flex min-w-0 flex-1 items-baseline gap-3">
|
||||
<span className="shrink-0 font-sans text-xs font-medium">{props.item.label}</span>
|
||||
<span className="shrink-0 font-sans text-xs font-medium">
|
||||
{slashSkill ? (
|
||||
<>
|
||||
<span className="text-secondary-label">skill:</span>
|
||||
{slashSkill.name}
|
||||
</>
|
||||
) : (
|
||||
props.item.label
|
||||
)}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate text-right text-secondary-label text-xs">
|
||||
{props.item.description}
|
||||
</span>
|
||||
|
||||
@@ -33,7 +33,7 @@ describe("searchSlashCommandItems", () => {
|
||||
description: "Create distinctive, production-grade frontend interfaces",
|
||||
},
|
||||
] satisfies Array<
|
||||
Extract<ComposerCommandItem, { type: "slash-command" | "provider-slash-command" }>
|
||||
Extract<ComposerCommandItem, { type: "slash-command" | "provider-slash-command" | "skill" }>
|
||||
>;
|
||||
|
||||
expect(searchSlashCommandItems(items, "ui").map((item) => item.id)).toEqual([
|
||||
@@ -61,11 +61,111 @@ describe("searchSlashCommandItems", () => {
|
||||
description: "General GitHub help",
|
||||
},
|
||||
] satisfies Array<
|
||||
Extract<ComposerCommandItem, { type: "slash-command" | "provider-slash-command" }>
|
||||
Extract<ComposerCommandItem, { type: "slash-command" | "provider-slash-command" | "skill" }>
|
||||
>;
|
||||
|
||||
expect(searchSlashCommandItems(items, "gfc").map((item) => item.id)).toEqual([
|
||||
"provider-slash-command:claudeAgent:gh-fix-ci",
|
||||
]);
|
||||
});
|
||||
|
||||
it("includes skills by name and description", () => {
|
||||
const items = [
|
||||
{
|
||||
id: "skill:claudeAgent:browser",
|
||||
type: "skill",
|
||||
provider: claudeDriver,
|
||||
skill: {
|
||||
name: "browser",
|
||||
path: "/skills/browser/SKILL.md",
|
||||
enabled: true,
|
||||
shortDescription: "Open and control the in-app browser",
|
||||
},
|
||||
label: "skill:browser",
|
||||
description: "Open and control the in-app browser",
|
||||
},
|
||||
] satisfies Array<Extract<ComposerCommandItem, { type: "skill" }>>;
|
||||
|
||||
expect(searchSlashCommandItems(items, "browser").map((item) => item.id)).toEqual([
|
||||
"skill:claudeAgent:browser",
|
||||
]);
|
||||
expect(searchSlashCommandItems(items, "control").map((item) => item.id)).toEqual([
|
||||
"skill:claudeAgent:browser",
|
||||
]);
|
||||
});
|
||||
|
||||
it("matches skills by display name", () => {
|
||||
const items = [
|
||||
{
|
||||
id: "skill:claudeAgent:browser",
|
||||
type: "skill",
|
||||
provider: claudeDriver,
|
||||
skill: {
|
||||
name: "browser",
|
||||
displayName: "Web Navigator",
|
||||
path: "/skills/browser/SKILL.md",
|
||||
enabled: true,
|
||||
shortDescription: "Open and control the in-app browser",
|
||||
},
|
||||
label: "skill:browser",
|
||||
description: "Open and control the in-app browser",
|
||||
},
|
||||
] satisfies Array<Extract<ComposerCommandItem, { type: "skill" }>>;
|
||||
|
||||
expect(searchSlashCommandItems(items, "navigator").map((item) => item.id)).toEqual([
|
||||
"skill:claudeAgent:browser",
|
||||
]);
|
||||
});
|
||||
|
||||
it("matches skills by their rendered prefix", () => {
|
||||
const items = [
|
||||
{
|
||||
id: "skill:claudeAgent:browser",
|
||||
type: "skill",
|
||||
provider: claudeDriver,
|
||||
skill: {
|
||||
name: "browser",
|
||||
path: "/skills/browser/SKILL.md",
|
||||
enabled: true,
|
||||
},
|
||||
label: "skill:browser",
|
||||
description: "Open and control the in-app browser",
|
||||
},
|
||||
] satisfies Array<Extract<ComposerCommandItem, { type: "skill" }>>;
|
||||
|
||||
expect(searchSlashCommandItems(items, "/skill:brow").map((item) => item.id)).toEqual([
|
||||
"skill:claudeAgent:browser",
|
||||
]);
|
||||
expect(searchSlashCommandItems(items, "/sk")).toEqual([]);
|
||||
expect(searchSlashCommandItems(items, "/ill")).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps skills alongside commands for an empty slash query", () => {
|
||||
const items = [
|
||||
{
|
||||
id: "slash:model",
|
||||
type: "slash-command",
|
||||
command: "model",
|
||||
label: "/model",
|
||||
description: "Switch model",
|
||||
},
|
||||
{
|
||||
id: "skill:claudeAgent:unslop",
|
||||
type: "skill",
|
||||
provider: claudeDriver,
|
||||
skill: {
|
||||
name: "unslop",
|
||||
path: "/skills/unslop/SKILL.md",
|
||||
enabled: true,
|
||||
},
|
||||
label: "skill:unslop",
|
||||
description: "Cut AI tells from writing",
|
||||
},
|
||||
] satisfies Array<Extract<ComposerCommandItem, { type: "slash-command" | "skill" }>>;
|
||||
|
||||
expect(searchSlashCommandItems(items, "").map((item) => item.id)).toEqual([
|
||||
"slash:model",
|
||||
"skill:claudeAgent:unslop",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -5,11 +5,20 @@ import {
|
||||
} from "@t3tools/shared/searchRanking";
|
||||
|
||||
import type { ComposerCommandItem } from "./ComposerCommandMenu";
|
||||
import { scoreProviderSkill } from "../../providerSkillSearch";
|
||||
|
||||
type SlashSearchItem = Extract<
|
||||
ComposerCommandItem,
|
||||
{ type: "slash-command" | "provider-slash-command" | "skill" }
|
||||
>;
|
||||
|
||||
function scoreSlashCommandItem(item: SlashSearchItem, query: string): number | null {
|
||||
if (item.type === "skill") {
|
||||
const skillQuery =
|
||||
query === "skill" ? "" : query.startsWith("skill:") ? query.slice("skill:".length) : query;
|
||||
return skillQuery ? scoreProviderSkill(item.skill, skillQuery) : 0;
|
||||
}
|
||||
|
||||
function scoreSlashCommandItem(
|
||||
item: Extract<ComposerCommandItem, { type: "slash-command" | "provider-slash-command" }>,
|
||||
query: string,
|
||||
): number | null {
|
||||
const primaryValue =
|
||||
item.type === "slash-command" ? item.command.toLowerCase() : item.command.name.toLowerCase();
|
||||
const description = item.description.toLowerCase();
|
||||
@@ -43,18 +52,16 @@ function scoreSlashCommandItem(
|
||||
}
|
||||
|
||||
export function searchSlashCommandItems(
|
||||
items: ReadonlyArray<
|
||||
Extract<ComposerCommandItem, { type: "slash-command" | "provider-slash-command" }>
|
||||
>,
|
||||
items: ReadonlyArray<SlashSearchItem>,
|
||||
query: string,
|
||||
): Array<Extract<ComposerCommandItem, { type: "slash-command" | "provider-slash-command" }>> {
|
||||
): SlashSearchItem[] {
|
||||
const normalizedQuery = normalizeSearchQuery(query, { trimLeadingPattern: /^\/+/ });
|
||||
if (!normalizedQuery) {
|
||||
return [...items];
|
||||
}
|
||||
|
||||
const ranked: Array<{
|
||||
item: Extract<ComposerCommandItem, { type: "slash-command" | "provider-slash-command" }>;
|
||||
item: SlashSearchItem;
|
||||
score: number;
|
||||
tieBreaker: string;
|
||||
}> = [];
|
||||
@@ -73,7 +80,9 @@ export function searchSlashCommandItems(
|
||||
tieBreaker:
|
||||
item.type === "slash-command"
|
||||
? `0\u0000${item.command}`
|
||||
: `1\u0000${item.command.name}\u0000${item.provider}`,
|
||||
: item.type === "provider-slash-command"
|
||||
? `1\u0000${item.command.name}\u0000${item.provider}`
|
||||
: `2\u0000${item.skill.name}\u0000${item.provider}`,
|
||||
},
|
||||
Number.POSITIVE_INFINITY,
|
||||
);
|
||||
|
||||
@@ -56,4 +56,17 @@ describe("searchProviderSkills", () => {
|
||||
|
||||
expect(searchProviderSkills(skills, "ui").map((skill) => skill.name)).toEqual([]);
|
||||
});
|
||||
|
||||
it("returns every enabled skill for an empty query", () => {
|
||||
const skills = [
|
||||
makeSkill({ name: "unslop" }),
|
||||
makeSkill({ name: "browser" }),
|
||||
makeSkill({ name: "disabled", enabled: false }),
|
||||
];
|
||||
|
||||
expect(searchProviderSkills(skills, "").map((skill) => skill.name)).toEqual([
|
||||
"unslop",
|
||||
"browser",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
scoreQueryMatch,
|
||||
} from "@t3tools/shared/searchRanking";
|
||||
|
||||
function scoreProviderSkill(skill: ServerProviderSkill, query: string): number | null {
|
||||
export function scoreProviderSkill(skill: ServerProviderSkill, query: string): number | null {
|
||||
const normalizedName = skill.name.toLowerCase();
|
||||
const normalizedLabel = formatProviderSkillDisplayName(skill).toLowerCase();
|
||||
const normalizedShortDescription = skill.shortDescription?.toLowerCase() ?? "";
|
||||
|
||||
Reference in new issue
Block a user