The best way to control Claude Code, Codex and more from any computer or phone

main
ts 86 lines 3.46 KB
Raw
1 import { describe, expect, it } from "vite-plus/test";
2
3 import { planClaudeSkillDispatch, type ClaudeSkillTarget } from "./ClaudeSkillDispatch.ts";
4
5 const skillPath = (name: string) => `/home/me/.claude/skills/${name}/SKILL.md`;
6
7 const skillMap = (names: Iterable<string>) =>
8 new Map<string, ClaudeSkillTarget>([...names].map((name) => [name, { path: skillPath(name) }]));
9
10 const SKILLS = skillMap(["2spec", "implement", "review", "re-release-version"]);
11
12 describe("planClaudeSkillDispatch", () => {
13 // regression: #9128 skills picked from the composer did not run
14 it("leaves a prompt without a known skill untouched", () => {
15 expect(planClaudeSkillDispatch("fix the build", SKILLS)).toBeUndefined();
16 expect(planClaudeSkillDispatch("echo $HOME then $unknown", SKILLS)).toBeUndefined();
17 });
18
19 it("keeps the whole request ahead of a mid-prompt slash command", () => {
20 expect(planClaudeSkillDispatch("ok, now $implement all the tickets", SKILLS)).toEqual({
21 leadingText: "ok, now /implement all the tickets",
22 commandText: "/implement all the tickets",
23 });
24 });
25
26 it("keeps a mention that opens the prompt as a single command block", () => {
27 expect(planClaudeSkillDispatch("$review\nfocus on auth", SKILLS)).toEqual({
28 leadingText: undefined,
29 commandText: "/review\nfocus on auth",
30 });
31 });
32
33 it("dispatches the last mention and rewrites earlier ones inline", () => {
34 expect(planClaudeSkillDispatch("$review the diff, then $implement the fixes", SKILLS)).toEqual({
35 leadingText: "/review the diff, then /implement the fixes",
36 commandText: "/implement the fixes",
37 });
38 });
39
40 it("dispatches currency-prefixed mentions and preserves their source boundaries", () => {
41 for (const symbol of ["€", "£", "¥", "₹", "₩", "₿", "𑿝"]) {
42 expect(
43 planClaudeSkillDispatch(
44 `${symbol}review the diff, then ${symbol}implement the fixes`,
45 SKILLS,
46 ),
47 ).toEqual({
48 leadingText: "/review the diff, then /implement the fixes",
49 commandText: "/implement the fixes",
50 });
51 expect(planClaudeSkillDispatch(`${symbol}2spec for this`, SKILLS)).toEqual({
52 leadingText: undefined,
53 commandText: "/2spec for this",
54 });
55 expect(planClaudeSkillDispatch(`5${symbol}review ${symbol}unknown`, SKILLS)).toBeUndefined();
56 }
57 });
58
59 it("ignores currency amounts and compact monetary expressions", () => {
60 const skillsWithCurrency = skillMap([...SKILLS.keys(), "20", "20k", "100M", "1e6"]);
61 for (const symbol of ["$", "€", "£", "¥", "₹", "₩", "₿", "𑿝"]) {
62 expect(
63 planClaudeSkillDispatch(
64 `pay ${symbol}20 ${symbol}20k ${symbol}100M ${symbol}1e6 tomorrow`,
65 skillsWithCurrency,
66 ),
67 ).toBeUndefined();
68 }
69 });
70
71 it("bounds notes for repeated user-only skills and leaves the native dispatch unannotated", () => {
72 const skills = new Map([
73 ["interrogate", { path: skillPath("interrogate"), userInvocationOnly: true }],
74 ["implement", { path: skillPath("implement"), userInvocationOnly: true }],
75 ]);
76 expect(
77 planClaudeSkillDispatch(
78 "$interrogate then $interrogate then $implement and $implement the fixes",
79 skills,
80 ),
81 ).toEqual({
82 leadingText: `/interrogate [The user invoked this skill. Follow the instructions at: ${skillPath("interrogate")}] then /interrogate then /implement and /implement the fixes`,
83 commandText: "/implement the fixes",
84 });
85 });
86 });