fix: the / menu reads .claude sources only for Claude Code
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
3f78fe912d
commit
f1102524cc
3 files changed
+65
-7
No files matched your search
@@ -6,10 +6,13 @@
|
||||
// reads the person's snippets and passes them in, and it schedules the retry
|
||||
// and the debounce with the numbers exported here.
|
||||
//
|
||||
// Three sources for `/` (the design's §5.3): the built-in commands of the
|
||||
// agent, the project's own `.claude/commands/*.md` and
|
||||
// `.claude/skills/*/SKILL.md`, and the person's saved snippets. One source
|
||||
// for `@`: the files git tracks in the pane's folder.
|
||||
// Sources for `/` (the design's §5.3): the built-in commands of the agent,
|
||||
// the person's saved snippets and - for Claude Code only (`isClaudeCode`) -
|
||||
// the project's own `.claude/commands/*.md` and `.claude/skills/*/SKILL.md`
|
||||
// and the global commands of `~/.claude` and its plugins. Another agent does
|
||||
// not understand the `.claude` files, so it gets its built-ins and snippets,
|
||||
// and nothing is read for it. One source for `@`: the files git tracks in the
|
||||
// pane's folder.
|
||||
//
|
||||
// A read that fails is not an empty list: the failure is reported through
|
||||
// `onReadError` and the menu keeps what it knows. A caller with no handler
|
||||
@@ -155,8 +158,22 @@ export function retryDelay(attempt) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The commands the `/` menu offers: the agent's built-ins, the project's own
|
||||
* and the person's snippets.
|
||||
* Is this agent Claude Code (under its name or its alias)? Only its commands
|
||||
* live in `.claude` files.
|
||||
*
|
||||
* @param {string|undefined} agent
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isClaudeCode(agent) {
|
||||
const name = String(agent ?? "");
|
||||
return (AGENT_ALIASES[name] ?? name) === "claude-code";
|
||||
}
|
||||
|
||||
/**
|
||||
* The commands the `/` menu offers: the agent's built-ins and the person's
|
||||
* snippets - and, for Claude Code only, the project's own commands and the
|
||||
* global ones (`options.global`). For another agent the project is not read
|
||||
* (no `exec`) and `options.global` is ignored.
|
||||
*
|
||||
* A source that cannot be read does not take the others with it: the menu
|
||||
* shows what is known and the failure goes to `onReadError`, so the caller
|
||||
@@ -173,6 +190,9 @@ export async function commands(cwd, exec, options = {}) {
|
||||
const builtins = builtinItems(options.agent);
|
||||
const snippets = snippetItems(options.snippets);
|
||||
|
||||
// The `.claude` files mean something to Claude Code alone.
|
||||
if (!isClaudeCode(options.agent)) return [...builtins, ...snippets];
|
||||
|
||||
let project = [];
|
||||
try {
|
||||
project = await projectItems(cwd, exec);
|
||||
|
||||
@@ -2215,7 +2215,8 @@ export default class Composer extends View {
|
||||
this.closeMenu();
|
||||
return;
|
||||
}
|
||||
if (token.trigger === "/") this.refreshGlobal(cx);
|
||||
// `~/.claude` is read for Claude Code only - no other agent understands it.
|
||||
if (token.trigger === "/" && catalog.isClaudeCode(agentName(agent))) this.refreshGlobal(cx);
|
||||
this.scheduleLoad(agent, token, cx);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
|
||||
import {
|
||||
BUILTINS,
|
||||
commands,
|
||||
isClaudeCode,
|
||||
globalCommands,
|
||||
} from "../herdr/herdr-composer/mods/herdr-composer/catalog.js";
|
||||
import {
|
||||
@@ -184,3 +185,39 @@ 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 () => {
|
||||
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,
|
||||
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 global = [{ key: "handoff", desc: "h", group: GROUP_USER, insert: "/handoff " }];
|
||||
const items = await commands("/x", exec, { agent: "claude", global });
|
||||
const keys = items.map((item) => item.key);
|
||||
assert.ok(keys.includes("handoff"));
|
||||
assert.ok(keys.includes("clear"));
|
||||
});
|
||||
Reference in new issue
Block a user