Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(tui): /skills use fuzzy completion not working

cycong_15cf52c2105e9
diff --git a/jiuwenclaw/channels/tui/frontend/src/core/commands/builtins/skills.ts b/jiuwenclaw/channels/tui/frontend/src/core/commands/builtins/skills.ts
index d0edd6e4a8..5932327647 100644
--- a/jiuwenclaw/channels/tui/frontend/src/core/commands/builtins/skills.ts
+++ b/jiuwenclaw/channels/tui/frontend/src/core/commands/builtins/skills.ts
@@ -312,6 +312,7 @@ export function createSkillsCommand(): SlashCommand {
example: "/skills use my-skill, Code and execute a Hello World program.",
kind: CommandKind.BUILT_IN,
takesArgs: true,
+ completionSuffix: ", ",
completion: async (ctx, partial) => {
const commaIndex = partial.indexOf(",");
if (commaIndex !== -1 && partial.slice(0, commaIndex).trim()) return [];
diff --git a/jiuwenclaw/channels/tui/frontend/src/core/commands/types.ts b/jiuwenclaw/channels/tui/frontend/src/core/commands/types.ts
index 2742876262..12feb3b36d 100644
--- a/jiuwenclaw/channels/tui/frontend/src/core/commands/types.ts
+++ b/jiuwenclaw/channels/tui/frontend/src/core/commands/types.ts
@@ -101,6 +101,7 @@ export interface SlashCommand {
kind: CommandKind;
action: (ctx: CommandContext, args: string) => void | Promise<void>;
completion?: (ctx: CommandContext, partial: string) => string[] | Promise<string[]>;
+ completionSuffix?: string;
takesArgs?: boolean;
subCommands?: SlashCommand[];
}
diff --git a/jiuwenclaw/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenclaw/channels/tui/frontend/src/ui/app-screen.ts
index 7344b3be47..2661e999c5 100644
--- a/jiuwenclaw/channels/tui/frontend/src/ui/app-screen.ts
+++ b/jiuwenclaw/channels/tui/frontend/src/ui/app-screen.ts
@@ -2535,10 +2535,12 @@ export class AppScreen implements Component, Focusable {
}
private buildSlashCommands(): TuiSlashCommand[] {
+ const hasAnyCompletion = (cmd: SlashCommand): boolean =>
+ !!cmd.completion || (cmd.subCommands?.some(hasAnyCompletion) ?? false);
return this.commands.getAll().map((command) => ({
name: command.name,
description: command.description,
- getArgumentCompletions: command.completion
+ getArgumentCompletions: hasAnyCompletion(command)
? async (argumentPrefix: string): Promise<AutocompleteItem[] | null> => {
const trimmed = argumentPrefix.trim();
// Traverse subcommand chain to find the deepest command with completion
@@ -2579,12 +2581,12 @@ export class AppScreen implements Component, Focusable {
}
const remainingArgs = remainingTokens.join(" ");
const items = await currentCommand.completion(this.state.getCommandContext(), remainingArgs);
- // Prefix completions with matched path if traversed
const prefix = matchedPath.length > 0 ? matchedPath.join(" ") + " " : "";
+ const suffix = currentCommand.completionSuffix ?? "";
return items.map((value) => ({
- value: prefix + value,
- label: prefix + value,
- description: currentCommand.description,
+ value: prefix + value + suffix,
+ label: value,
+ description: "",
}));
}