feat: the / menu reads the sources of the agent's profile and its history
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
0263eca263
commit
1b12550d04
3 files changed
+307
-170
No files matched your search
+126
-32
@@ -3,16 +3,23 @@ import assert from "node:assert/strict";
|
||||
import {
|
||||
BUILTINS,
|
||||
commands,
|
||||
isClaudeCode,
|
||||
globalCommands,
|
||||
historyCommands,
|
||||
} from "../herdr/herdr-composer/mods/herdr-composer/catalog.js";
|
||||
import {
|
||||
DEFAULT_PROFILES,
|
||||
resolveProfile,
|
||||
} from "../herdr/herdr-composer/mods/herdr-composer/profiles.js";
|
||||
import {
|
||||
GROUPS,
|
||||
GROUP_HISTORY,
|
||||
GROUP_USER,
|
||||
GROUP_PLUGIN,
|
||||
} from "../herdr/herdr-composer/mods/herdr-composer/suggest.js";
|
||||
|
||||
const HOME = "C:/Users/Test";
|
||||
const CC_PROFILE = DEFAULT_PROFILES[0];
|
||||
const CC = CC_PROFILE.sources;
|
||||
|
||||
/**
|
||||
* A fake machine: `files` maps a path to its text. `exec` answers the POSIX
|
||||
@@ -129,7 +136,7 @@ test("globalCommands: an enabled plugin gives plugin:name (default skills dir)",
|
||||
...plugins({ "superpowers@official": true }, { "superpowers@official": "C:\\p\\superpowers\\7.0.2" }),
|
||||
[`${dir}/skills/brainstorming/SKILL.md`]: skill("brainstorming"),
|
||||
});
|
||||
const items = await globalCommands(HOME, exec, readText);
|
||||
const items = await globalCommands(HOME, exec, readText, { sources: CC });
|
||||
assert.equal(items.length, 1);
|
||||
assert.equal(items[0].key, "superpowers:brainstorming");
|
||||
assert.equal(items[0].group, GROUP_PLUGIN);
|
||||
@@ -144,7 +151,7 @@ test("globalCommands: disabled or unlisted plugin gives nothing", async () => {
|
||||
[`${dir}/skills/x/SKILL.md`]: skill("x"),
|
||||
["C:/p/b/1/skills/y/SKILL.md"]: skill("y"),
|
||||
});
|
||||
assert.deepEqual(await globalCommands(HOME, exec, readText), []);
|
||||
assert.deepEqual(await globalCommands(HOME, exec, readText, { sources: CC }), []);
|
||||
});
|
||||
|
||||
test("globalCommands: plugin.json skills array takes only the named dirs", async () => {
|
||||
@@ -156,7 +163,7 @@ test("globalCommands: plugin.json skills array takes only the named dirs", async
|
||||
[`${dir}/skills/eng/other/SKILL.md`]: skill("other"),
|
||||
[`${dir}/skills/direct/SKILL.md`]: skill("direct"),
|
||||
});
|
||||
const keys = (await globalCommands(HOME, exec, readText)).map((item) => item.key);
|
||||
const keys = (await globalCommands(HOME, exec, readText, { sources: CC })).map((item) => item.key);
|
||||
assert.deepEqual(keys, ["mp:tdd"]);
|
||||
});
|
||||
|
||||
@@ -168,7 +175,7 @@ test("globalCommands: plugin commands dir and user-invocable false", async () =>
|
||||
[`${dir}/skills/hidden/SKILL.md`]: skill("hidden", "user-invocable: false\n"),
|
||||
[`${dir}/skills/shown/SKILL.md`]: skill("shown"),
|
||||
});
|
||||
const keys = (await globalCommands(HOME, exec, readText)).map((item) => item.key).sort();
|
||||
const keys = (await globalCommands(HOME, exec, readText, { sources: CC })).map((item) => item.key).sort();
|
||||
assert.deepEqual(keys, ["c:ship", "c:shown"]);
|
||||
});
|
||||
|
||||
@@ -176,7 +183,7 @@ test("globalCommands: name: in the front matter wins over the folder name", asyn
|
||||
const { exec, readText } = machine({
|
||||
[`${HOME}/.claude/skills/folder/SKILL.md`]: skill("real-name"),
|
||||
});
|
||||
const items = await globalCommands(HOME, exec, readText);
|
||||
const items = await globalCommands(HOME, exec, readText, { sources: CC });
|
||||
assert.deepEqual(items.map((item) => item.key), ["real-name"]);
|
||||
});
|
||||
|
||||
@@ -184,7 +191,7 @@ test("globalCommands: a user command gives handoff in Użytkownik", async () =>
|
||||
const { exec, readText } = machine({
|
||||
[`${HOME}/.claude/commands/handoff.md`]: "---\ndescription: Przekazanie\n---\n",
|
||||
});
|
||||
const items = await globalCommands(HOME, exec, readText);
|
||||
const items = await globalCommands(HOME, exec, readText, { sources: CC });
|
||||
assert.equal(items.length, 1);
|
||||
assert.equal(items[0].key, "handoff");
|
||||
assert.equal(items[0].group, GROUP_USER);
|
||||
@@ -193,23 +200,23 @@ test("globalCommands: a user command gives handoff in Użytkownik", async () =>
|
||||
|
||||
test("globalCommands: no settings.json, broken json: user items only, no throw", async () => {
|
||||
const none = machine({ [`${HOME}/.claude/commands/a.md`]: "x" });
|
||||
assert.deepEqual((await globalCommands(HOME, none.exec, none.readText)).map((i) => i.key), ["a"]);
|
||||
assert.deepEqual((await globalCommands(HOME, none.exec, none.readText, { sources: CC })).map((i) => i.key), ["a"]);
|
||||
|
||||
const broken = machine({
|
||||
[`${HOME}/.claude/settings.json`]: "{nope",
|
||||
[`${HOME}/.claude/plugins/installed_plugins.json`]: "[[",
|
||||
[`${HOME}/.claude/commands/a.md`]: "x",
|
||||
});
|
||||
assert.deepEqual((await globalCommands(HOME, broken.exec, broken.readText)).map((i) => i.key), ["a"]);
|
||||
assert.deepEqual((await globalCommands(HOME, broken.exec, broken.readText, { sources: CC })).map((i) => i.key), ["a"]);
|
||||
});
|
||||
|
||||
test("globalCommands: a listing failure goes to onReadError, or throws", async () => {
|
||||
const { exec, readText } = machine({}, { listError: true });
|
||||
const errors = [];
|
||||
const items = await globalCommands(HOME, exec, readText, { onReadError: (err) => errors.push(err) });
|
||||
const items = await globalCommands(HOME, exec, readText, { sources: CC, onReadError: (err) => errors.push(err) });
|
||||
assert.deepEqual(items, []);
|
||||
assert.equal(errors.length, 1);
|
||||
await assert.rejects(() => globalCommands(HOME, exec, readText));
|
||||
await assert.rejects(() => globalCommands(HOME, exec, readText, { sources: CC }));
|
||||
});
|
||||
|
||||
test("paths with spaces and Polish letters are not put in the PowerShell script as text", async () => {
|
||||
@@ -222,7 +229,7 @@ test("paths with spaces and Polish letters are not put in the PowerShell script
|
||||
}
|
||||
throw new Error("no");
|
||||
};
|
||||
await globalCommands(home, exec, async () => null);
|
||||
await globalCommands(home, exec, async () => null, { sources: CC });
|
||||
assert.ok(script.length > 0);
|
||||
assert.ok(!script.includes("Zażółć"));
|
||||
});
|
||||
@@ -233,7 +240,7 @@ test("commands: options.global joins after the project, first key wins", async (
|
||||
{ key: "clear", desc: "dup", group: GROUP_USER, insert: "/clear " },
|
||||
{ key: "handoff", desc: "h", group: GROUP_USER, insert: "/handoff " },
|
||||
];
|
||||
const items = await commands("/x", exec, { agent: "claude-code", global });
|
||||
const items = await commands("/x", exec, { profile: CC_PROFILE, global });
|
||||
assert.equal(items.filter((item) => item.key === "clear").length, 1);
|
||||
assert.equal(
|
||||
items.find((item) => item.key === "clear").desc,
|
||||
@@ -242,37 +249,25 @@ test("commands: options.global joins after the project, first key wins", async (
|
||||
assert.ok(items.some((item) => item.key === "handoff"));
|
||||
});
|
||||
|
||||
test("isClaudeCode: claude-code and its alias only", () => {
|
||||
assert.equal(isClaudeCode("claude-code"), true);
|
||||
assert.equal(isClaudeCode("claude"), true);
|
||||
for (const name of ["codex", "kiro-cli", "", undefined]) assert.equal(isClaudeCode(name), false, String(name));
|
||||
});
|
||||
|
||||
test("commands: another agent gets its builtins and snippets - no project, no global, no exec", async () => {
|
||||
test("commands: codex gets its builtins and snippets - no project sources, no exec", async () => {
|
||||
let calls = 0;
|
||||
const exec = async () => {
|
||||
calls += 1;
|
||||
return { code: 0, stdout: "", stderr: "" };
|
||||
};
|
||||
const global = [{ key: "handoff", desc: "h", group: GROUP_USER, insert: "/handoff " }];
|
||||
const items = await commands("/x", exec, {
|
||||
agent: "codex",
|
||||
global,
|
||||
profile: resolveProfile([], "codex"),
|
||||
snippets: [{ key: "mine", desc: "s" }],
|
||||
});
|
||||
assert.equal(calls, 0);
|
||||
const keys = items.map((item) => item.key);
|
||||
assert.deepEqual(keys, [...BUILTINS.codex.map((item) => item.key), "mine"]);
|
||||
assert.ok(!keys.includes("handoff"));
|
||||
});
|
||||
|
||||
test("commands: claude-code still reads the project and takes the global ones", async () => {
|
||||
const exec = async (command) => {
|
||||
if (command === "sh") return { code: 0, stdout: ".claude/commands/p.md\n", stderr: "" };
|
||||
return { code: 1, stdout: "", stderr: "" };
|
||||
};
|
||||
const { exec } = ccMachine({ ".claude/commands/p.md": "x" });
|
||||
const global = [{ key: "handoff", desc: "h", group: GROUP_USER, insert: "/handoff " }];
|
||||
const items = await commands("/x", exec, { agent: "claude", global });
|
||||
const items = await commands("/x", exec, { profile: resolveProfile([], "claude"), global });
|
||||
const keys = items.map((item) => item.key);
|
||||
assert.ok(keys.includes("handoff"));
|
||||
assert.ok(keys.includes("clear"));
|
||||
@@ -333,9 +328,108 @@ const EXPECTED_CC = [
|
||||
{"key":"sp:brainstorming","group":"Pluginy","insert":"/sp:brainstorming ","desc":"Opis brainstorming"},
|
||||
];
|
||||
|
||||
test("the / menu of Claude Code stays as it was (pinned before profiles)", async () => {
|
||||
test("the / menu of Claude Code stays as it was", async () => {
|
||||
const { exec, readText } = ccMachine(CC_FILES);
|
||||
const global = await globalCommands(HOME, exec, readText);
|
||||
const items = await commands("/proj", exec, { agent: "claude-code", global });
|
||||
const global = await globalCommands(HOME, exec, readText, { sources: CC });
|
||||
const items = await commands("/proj", exec, { profile: resolveProfile([], "claude-code"), global });
|
||||
assert.deepEqual(items.map(ccRow), EXPECTED_CC);
|
||||
});
|
||||
|
||||
test("commands: no profile gives only the history and the snippets, and no exec", async () => {
|
||||
let calls = 0;
|
||||
const exec = async () => {
|
||||
calls += 1;
|
||||
return { code: 0, stdout: "", stderr: "" };
|
||||
};
|
||||
const h = { key: "clear", desc: "", group: GROUP_HISTORY, insert: "/clear " };
|
||||
assert.deepEqual(await commands("/x", exec, { profile: null, history: [h] }), [h]);
|
||||
assert.equal(calls, 0);
|
||||
});
|
||||
|
||||
test("commands: a profile project source with a prefix", async () => {
|
||||
const profile = {
|
||||
id: "kiro",
|
||||
match: ["kiro-cli"],
|
||||
builtins: [],
|
||||
sources: [{ scope: "project", path: ".kiro/prompts", pattern: "*.md", prefix: "@" }],
|
||||
};
|
||||
const { exec } = ccMachine({ ".kiro/prompts/review.md": "---\ndescription: R\n---\n" });
|
||||
const items = await commands("/x", exec, { profile });
|
||||
assert.deepEqual(items, [
|
||||
{ key: "review", desc: "R", group: "Projekt", insert: "@review " },
|
||||
]);
|
||||
});
|
||||
|
||||
test("commands: a project source path never reaches the shell as a script", async () => {
|
||||
const seen = [];
|
||||
const exec = async (command, args) => {
|
||||
seen.push([command, args]);
|
||||
return { code: 0, stdout: "", stderr: "" };
|
||||
};
|
||||
const profile = {
|
||||
id: "x",
|
||||
match: ["x"],
|
||||
builtins: [],
|
||||
sources: [{ scope: "project", path: ".a b/Zażółć", pattern: "*.md", prefix: "/" }],
|
||||
};
|
||||
await commands("/x", exec, { profile });
|
||||
assert.equal(seen.length, 1);
|
||||
assert.ok(!seen[0][1][1].includes("Zażółć"));
|
||||
assert.ok(seen[0][1].includes(".a b/Zażółć"));
|
||||
});
|
||||
|
||||
test("globalCommands: no sources gives [] and no exec", async () => {
|
||||
let calls = 0;
|
||||
const exec = async () => {
|
||||
calls += 1;
|
||||
return { code: 0, stdout: "", stderr: "" };
|
||||
};
|
||||
assert.deepEqual(await globalCommands(HOME, exec, async () => null, { sources: [] }), []);
|
||||
assert.deepEqual(await globalCommands(HOME, exec, async () => null), []);
|
||||
assert.equal(calls, 0);
|
||||
});
|
||||
|
||||
test("globalCommands: a home source gives the Użytkownik group with its prefix", async () => {
|
||||
const { exec, readText } = machine({ [`${HOME}/.kiro/prompts/plan.md`]: "---\ndescription: P\n---\n" });
|
||||
const sources = [{ scope: "home", path: ".kiro/prompts", pattern: "*.md", prefix: "@" }];
|
||||
const items = await globalCommands(HOME, exec, readText, { sources });
|
||||
assert.deepEqual(items, [{ key: "plan", desc: "P", group: GROUP_USER, insert: "@plan " }]);
|
||||
});
|
||||
|
||||
test("globalCommands: a project source is not read from home", async () => {
|
||||
const { exec, readText } = machine({ [`${HOME}/.kiro/prompts/plan.md`]: "x" });
|
||||
const sources = [{ scope: "project", path: ".kiro/prompts", pattern: "*.md", prefix: "/" }];
|
||||
assert.deepEqual(await globalCommands(HOME, exec, readText, { sources }), []);
|
||||
});
|
||||
|
||||
test("historyCommands: commands of this agent, newest first, no paths", () => {
|
||||
const e = (text, sentAt, agentName = "claude-code") => ({ text, sentAt, agentName });
|
||||
const history = [
|
||||
e("/clear", 1),
|
||||
e(" /superpowers:brainstorming x", 5),
|
||||
e("/c/Users/x", 6),
|
||||
e("/ cos", 7),
|
||||
e("/", 8),
|
||||
e("hej /clear", 9),
|
||||
e("/other", 10, "codex"),
|
||||
];
|
||||
const items = historyCommands(history, "Claude-Code");
|
||||
assert.deepEqual(items.map((i) => i.key), ["superpowers:brainstorming", "clear"]);
|
||||
assert.ok(items.every((i) => i.group === "Z historii" && i.desc === ""));
|
||||
assert.equal(items[0].insert, "/superpowers:brainstorming ");
|
||||
});
|
||||
|
||||
test("commands: a history command that is a builtin shows once, as Wbudowane", async () => {
|
||||
const exec = async () => ({ code: 0, stdout: "", stderr: "" });
|
||||
const items = await commands("/x", exec, {
|
||||
profile: resolveProfile([], "codex"),
|
||||
history: historyCommands([{ text: "/model", sentAt: 1, agentName: "codex" }], "codex"),
|
||||
});
|
||||
const model = items.filter((i) => i.key === "model");
|
||||
assert.equal(model.length, 1);
|
||||
assert.equal(model[0].group, "Wbudowane");
|
||||
});
|
||||
|
||||
test("GROUPS has Z historii right after Pluginy", () => {
|
||||
assert.equal(GROUPS[GROUPS.indexOf("Pluginy") + 1], "Z historii");
|
||||
});
|
||||
Reference in new issue
Block a user