mirror of
https://github.com/earendil-works/pi.git
synced 2026-09-29 17:19:06 +08:00
fix(tui): rank skill autocomplete by bare name (#9120)
This commit is contained in:
@@ -332,7 +332,11 @@ export class CombinedAutocompleteProvider implements AutocompleteProvider {
|
||||
};
|
||||
});
|
||||
|
||||
const filtered = fuzzyFilter(commandItems, prefix, (item) => item.name).map((item) => ({
|
||||
const filtered = fuzzyFilter(commandItems, prefix, (item) =>
|
||||
!prefix.startsWith("skill:") && item.name.startsWith("skill:")
|
||||
? item.name.slice("skill:".length)
|
||||
: item.name,
|
||||
).map((item) => ({
|
||||
value: item.name,
|
||||
label: item.label,
|
||||
...(item.description && { description: item.description }),
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import assert from "node:assert";
|
||||
import { describe, it } from "node:test";
|
||||
import { CombinedAutocompleteProvider } from "../src/autocomplete.ts";
|
||||
|
||||
describe("CombinedAutocompleteProvider slash-command filter", () => {
|
||||
const commands = [
|
||||
{ name: "skill:deep-research", description: "Multi-agent deep research" },
|
||||
{ name: "skill:research-idea", description: "Refine a raw idea into a falsifiable seed" },
|
||||
{ name: "skill:to-sidecar", description: "Route work to a sidecar" },
|
||||
{ name: "model", description: "Select the active model" },
|
||||
];
|
||||
|
||||
async function suggestionsFor(prefix: string): Promise<string[]> {
|
||||
const provider = new CombinedAutocompleteProvider(commands, process.cwd());
|
||||
const line = `/${prefix}`;
|
||||
const result = await provider.getSuggestions([line], 0, line.length, {
|
||||
signal: new AbortController().signal,
|
||||
});
|
||||
assert.ok(result, `expected suggestions for "/${prefix}"`);
|
||||
return result.items.map((item) => item.value);
|
||||
}
|
||||
|
||||
it("ranks skill:research-idea first for query 'idea'", async () => {
|
||||
const items = await suggestionsFor("idea");
|
||||
assert.equal(items[0], "skill:research-idea");
|
||||
assert.ok(!items.includes("skill:deep-research"));
|
||||
});
|
||||
|
||||
it("keeps ordinary slash commands matching", async () => {
|
||||
const items = await suggestionsFor("mod");
|
||||
assert.ok(items.includes("model"));
|
||||
});
|
||||
|
||||
it("keeps explicit skill: queries working", async () => {
|
||||
const items = await suggestionsFor("skill:side");
|
||||
assert.ok(items.includes("skill:to-sidecar"));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user