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): add fuzzy skill name autocomplete for /skills use

cycong_17bc830042292
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 0f626437a8..d827cf0254 100644
--- a/jiuwenclaw/channels/tui/frontend/src/core/commands/builtins/skills.ts
+++ b/jiuwenclaw/channels/tui/frontend/src/core/commands/builtins/skills.ts
@@ -241,6 +241,28 @@ export function createSkillsCommand(): SlashCommand {
example: "/skills use my-skill, Code and execute a Hello World program.",
kind: CommandKind.BUILT_IN,
takesArgs: true,
+ completion: async (ctx, partial) => {
+ const commaIndex = partial.indexOf(",");
+ if (commaIndex !== -1 && partial.slice(0, commaIndex).trim()) return [];
+ const filterTerm = commaIndex !== -1 ? "" : partial;
+ try {
+ const payload = await ctx.request("skills.list", {});
+ const skills = flattenArrayPayload(payload)
+ .map((item) => {
+ if (item && typeof item === "object") {
+ const obj = item as Record<string, unknown>;
+ return typeof obj.name === "string" ? obj.name : null;
+ }
+ return null;
+ })
+ .filter((name): name is string => name !== null);
+ if (!filterTerm) return skills;
+ const lower = filterTerm.toLowerCase();
+ return skills.filter((name) => name.toLowerCase().includes(lower));
+ } catch {
+ return [];
+ }
+ },
action: async (ctx, args) => {
const parts = args.trim().split(/\s*,\s*(.*)/);
const skill_name = parts[0];
diff --git a/jiuwenclaw/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenclaw/channels/tui/frontend/src/ui/app-screen.ts
index e136306d86..a24989e685 100644
--- a/jiuwenclaw/channels/tui/frontend/src/ui/app-screen.ts
+++ b/jiuwenclaw/channels/tui/frontend/src/ui/app-screen.ts
@@ -1565,37 +1565,50 @@ export class AppScreen implements Component, Focusable {
return this.commands.getAll().map((command) => ({
name: command.name,
description: command.description,
- getArgumentCompletions: command.completion
- ? async (argumentPrefix: string): Promise<AutocompleteItem[] | null> => {
- const trimmed = argumentPrefix.trim();
- // pi-tui 把「第一个空格之后」整段当作 `/config` 的参数前缀去补全。
- // 对 `/config set model deepseek`,前缀是 `set model deepseek`,补全项却是平铺的
- // get/set/list/各 config key;若补全菜单仍打开,Enter 会先 applyCompletion 再提交,
- // 会把整段参数替换成当前选中项(常为列表首项 `get`),看起来像「变成 /config get」且 set 未执行。
- // 子命令名已匹配且后面还有 token 时关闭参数补全,让 Enter 直接提交当前输入。
- if (command.subCommands?.length && trimmed.length > 0) {
- const tokens = trimmed.split(/\s+/).filter(Boolean);
- if (tokens.length >= 2) {
+ getArgumentCompletions:
+ command.completion || command.subCommands?.some((sub) => sub.completion)
+ ? async (argumentPrefix: string): Promise<AutocompleteItem[] | null> => {
+ const trimmed = argumentPrefix.trim();
+ // pi-tui 把「第一个空格之后」整段当作 `/config` 的参数前缀去补全。
+ // 对 `/config set model deepseek`,前缀是 `set model deepseek`,补全项却是平铺的
+ // get/set/list/各 config key;若补全菜单仍打开,Enter 会先 applyCompletion 再提交,
+ // 会把整段参数替换成当前选中项(常为列表首项 `get`),看起来像「变成 /config get」且 set 未执行。
+ // 子命令名已匹配且后面还有 token 时关闭参数补全,让 Enter 直接提交当前输入。
+ if (command.subCommands?.length && trimmed.length > 0) {
+ const tokens = trimmed.split(/\s+/).filter(Boolean);
const head = tokens[0] ?? "";
- const matchedSub = command.subCommands.some(
+ const matchedSub = command.subCommands.find(
(sub) => sub.name === head || sub.altNames?.includes(head),
);
if (matchedSub) {
- return null;
+ if (matchedSub.completion) {
+ const subPartial = tokens.slice(1).join(" ");
+ const items = await matchedSub.completion(
+ this.state.getCommandContext(),
+ subPartial,
+ );
+ return items.map((name) => ({
+ value: `${head} ${name}, `,
+ label: name,
+ }));
+ }
+ if (tokens.length >= 2) {
+ return null;
+ }
}
}
+ if (command.name === "mode") {
+ return buildModeAutocompleteItems();
+ }
+ if (!command.completion) return null;
+ const items = await command.completion(this.state.getCommandContext(), argumentPrefix);
+ return items.map((value) => ({
+ value,
+ label: value,
+ description: command.description,
+ }));
}
- if (command.name === "mode") {
- return buildModeAutocompleteItems();
- }
- const items = await command.completion!(this.state.getCommandContext(), argumentPrefix);
- return items.map((value) => ({
- value,
- label: value,
- description: command.description,
- }));
- }
- : undefined,
+ : undefined,
}));
}