Open History to see the last commit
1import { expect, it } from "@effect/vitest";
2
3import {
4 expandPiSkillReference,
5 parsePiCompactCommand,
6 parsePiDiscoveredCommands,
7 PI_COMPACT_SLASH_COMMAND,
8 withPiBuiltinSlashCommands,
9} from "./PiCommands.ts";
10
11it("maps current Pi skill metadata to T3's user and project skill scopes", () => {
12 expect(
13 parsePiDiscoveredCommands({
14 commands: [
15 {
16 name: "skill:global-review",
17 description: "Review changes.",
18 source: "skill",
19 sourceInfo: {
20 path: "/home/test/.agents/skills/global-review/SKILL.md",
21 scope: "user",
22 },
23 },
24 {
25 name: "skill:project-deploy",
26 description: "Deploy this project.",
27 source: "skill",
28 sourceInfo: {
29 path: "/workspace/.agents/skills/project-deploy/SKILL.md",
30 scope: "project",
31 },
32 },
33 { name: "hello", description: "Say hello.", source: "extension" },
34 ],
35 }),
36 ).toEqual({
37 skills: [
38 {
39 name: "global-review",
40 description: "Review changes.",
41 path: "/home/test/.agents/skills/global-review/SKILL.md",
42 scope: "user",
43 enabled: true,
44 },
45 {
46 name: "project-deploy",
47 description: "Deploy this project.",
48 path: "/workspace/.agents/skills/project-deploy/SKILL.md",
49 scope: "project",
50 enabled: true,
51 },
52 ],
53 slashCommands: [{ name: "hello", description: "Say hello." }],
54 });
55});
56
57it("maps Pi global location and interface labels onto T3 skill fields", () => {
58 expect(
59 parsePiDiscoveredCommands({
60 commands: [
61 {
62 name: "skill:global-review",
63 description: "Review changes.",
64 source: "skill",
65 location: "global",
66 interface: {
67 displayName: "Global Review",
68 shortDescription: "Review diffs.",
69 },
70 },
71 ],
72 }),
73 ).toEqual({
74 skills: [
75 {
76 name: "global-review",
77 description: "Review changes.",
78 path: "pi:skill:global-review",
79 scope: "user",
80 enabled: true,
81 displayName: "Global Review",
82 shortDescription: "Review diffs.",
83 },
84 ],
85 slashCommands: [],
86 });
87});
88
89it("parses a standalone /compact command and optional instructions", () => {
90 expect(parsePiCompactCommand("/compact")).toEqual({});
91 expect(parsePiCompactCommand(" /compact ")).toEqual({});
92 expect(parsePiCompactCommand("/compact keep the auth rewrite")).toEqual({
93 customInstructions: "keep the auth rewrite",
94 });
95 expect(parsePiCompactCommand("/compacted")).toBeNull();
96 expect(parsePiCompactCommand("/compact-now")).toBeNull();
97 expect(parsePiCompactCommand("please /compact")).toBeNull();
98});
99
100it("prepends the builtin compact command without duplicating a discovered one", () => {
101 expect(withPiBuiltinSlashCommands([{ name: "hello", description: "Say hello." }])).toEqual([
102 PI_COMPACT_SLASH_COMMAND,
103 { name: "hello", description: "Say hello." },
104 ]);
105 expect(
106 withPiBuiltinSlashCommands([
107 { name: "compact", description: "Extension compact." },
108 { name: "hello" },
109 ]),
110 ).toEqual([PI_COMPACT_SLASH_COMMAND, { name: "hello" }]);
111});
112
113it("leaves unrelated dollar-prefixed text unchanged", () => {
114 expect(expandPiSkillReference("Explain $HOME", new Set(["global-review"]))).toBe("Explain $HOME");
115});
116
117it("hoists every known $ skill and keeps the rest of the prompt", () => {
118 expect(expandPiSkillReference("use $alpha then $beta please", new Set(["alpha", "beta"]))).toBe(
119 "/skill:alpha /skill:beta use then please",
120 );
121});
122
123it("preserves code indentation and line breaks when expanding a skill", () => {
124 expect(expandPiSkillReference("$review\n```ts\n const x = 1;\n```", new Set(["review"]))).toBe(
125 "/skill:review ```ts\n const x = 1;\n```",
126 );
127});