1import { expect, it } from "@effect/vitest";
2
3import {
4 parsePiCompactCommand,
5 parsePiDiscoveredCommands,
6 PI_COMPACT_SLASH_COMMAND,
7 withPiBuiltinSlashCommands,
8} from "./commands.ts";
9
10it("maps current Pi skill metadata to T3's user and project skill scopes", () => {
11 expect(
12 parsePiDiscoveredCommands({
13 commands: [
14 {
15 name: "skill:global-review",
16 description: "Review changes.",
17 source: "skill",
18 sourceInfo: {
19 path: "/home/test/.agents/skills/global-review/SKILL.md",
20 scope: "user",
21 },
22 },
23 {
24 name: "skill:project-deploy",
25 description: "Deploy this project.",
26 source: "skill",
27 sourceInfo: {
28 path: "/workspace/.agents/skills/project-deploy/SKILL.md",
29 scope: "project",
30 },
31 },
32 { name: "hello", description: "Say hello.", source: "extension" },
33 ],
34 }),
35 ).toEqual({
36 skills: [
37 {
38 name: "global-review",
39 description: "Review changes.",
40 path: "/home/test/.agents/skills/global-review/SKILL.md",
41 scope: "user",
42 enabled: true,
43 },
44 {
45 name: "project-deploy",
46 description: "Deploy this project.",
47 path: "/workspace/.agents/skills/project-deploy/SKILL.md",
48 scope: "project",
49 enabled: true,
50 },
51 ],
52 slashCommands: [{ name: "hello", description: "Say hello." }],
53 });
54});
55
56it("maps Pi global location and interface labels onto T3 skill fields", () => {
57 expect(
58 parsePiDiscoveredCommands({
59 commands: [
60 {
61 name: "skill:global-review",
62 description: "Review changes.",
63 source: "skill",
64 location: "global",
65 interface: {
66 displayName: "Global Review",
67 shortDescription: "Review diffs.",
68 },
69 },
70 ],
71 }),
72 ).toEqual({
73 skills: [
74 {
75 name: "global-review",
76 description: "Review changes.",
77 path: "pi:skill:global-review",
78 scope: "user",
79 enabled: true,
80 displayName: "Global Review",
81 shortDescription: "Review diffs.",
82 },
83 ],
84 slashCommands: [],
85 });
86});
87
88it("parses a standalone /compact command and optional instructions", () => {
89 expect(parsePiCompactCommand("/compact")).toEqual({});
90 expect(parsePiCompactCommand(" /compact ")).toEqual({});
91 expect(parsePiCompactCommand("/compact keep the auth rewrite")).toEqual({
92 customInstructions: "keep the auth rewrite",
93 });
94 expect(parsePiCompactCommand("/compacted")).toBeNull();
95 expect(parsePiCompactCommand("/compact-now")).toBeNull();
96 expect(parsePiCompactCommand("please /compact")).toBeNull();
97});
98
99it("prepends the builtin compact command without duplicating a discovered one", () => {
100 expect(withPiBuiltinSlashCommands([{ name: "hello", description: "Say hello." }])).toEqual([
101 PI_COMPACT_SLASH_COMMAND,
102 { name: "hello", description: "Say hello." },
103 ]);
104 expect(
105 withPiBuiltinSlashCommands([
106 { name: "compact", description: "Extension compact." },
107 { name: "hello" },
108 ]),
109 ).toEqual([PI_COMPACT_SLASH_COMMAND, { name: "hello" }]);
110});