Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import * as FileSystem from "effect/FileSystem";
5import * as Path from "effect/Path";
6
7import { discoverAntigravitySkills } from "./AntigravitySkills.ts";
8import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
9
10const writeSkill = Effect.fn("writeSkill")(function* (directory: string, contents: string) {
11 const fileSystem = yield* FileSystem.FileSystem;
12 const path = yield* Path.Path;
13 yield* fileSystem.makeDirectory(directory, { recursive: true });
14 const skillPath = path.join(directory, "SKILL.md");
15 yield* fileSystem.writeFileString(skillPath, contents);
16 return skillPath;
17});
18
19const makeWorkspace = Effect.fn("makeWorkspace")(function* () {
20 const fileSystem = yield* FileSystem.FileSystem;
21 const path = yield* Path.Path;
22 const temporaryDirectory = yield* fileSystem.makeTempDirectoryScoped({
23 prefix: "t3-antigravity-skills-",
24 });
25 return {
26 cwd: path.join(temporaryDirectory, "workspace"),
27 userHome: path.join(temporaryDirectory, "home"),
28 };
29});
30
31it.layer(NodeServices.layer)("discoverAntigravitySkills", (it) => {
32 it.effect("does not read user skills from a nested project or from ~/.agents", () =>
33 Effect.gen(function* () {
34 const path = yield* Path.Path;
35 const input = yield* makeWorkspace();
36 const nested = { ...input, cwd: path.join(input.userHome, "AI", "Projects", "Something") };
37 const skillPath = yield* writeSkill(
38 path.join(input.userHome, ".gemini", "config", "skills", "review"),
39 "---\nname: review\ndescription: Review changes.\n---\n",
40 );
41 yield* writeSkill(
42 path.join(input.userHome, ".agents", "skills", "ignored"),
43 "---\nname: ignored\n---\n",
44 );
45
46 assert.deepEqual(yield* discoverAntigravitySkills(nested), [
47 {
48 name: "review",
49 description: "Review changes.",
50 path: skillPath,
51 scope: "user",
52 enabled: true,
53 },
54 ]);
55 assert.deepEqual(
56 (yield* discoverAntigravitySkills({ ...input, cwd: input.userHome })).map((skill) => [
57 skill.name,
58 skill.scope,
59 ]),
60 [
61 ["ignored", "project"],
62 ["review", "user"],
63 ],
64 );
65 }),
66 );
67
68 it.effect("reads skill names, descriptions and paths from the current native roots", () =>
69 Effect.gen(function* () {
70 const path = yield* Path.Path;
71 const input = yield* makeWorkspace();
72 const roots = [
73 { directory: path.join(input.userHome, ".gemini", "config", "skills"), scope: "user" },
74 { directory: path.join(input.cwd, ".gemini", "skills"), scope: "project" },
75 {
76 directory: path.join(input.userHome, ".gemini", "antigravity-cli", "skills"),
77 scope: "user",
78 },
79 { directory: path.join(input.cwd, ".agents", "skills"), scope: "project" },
80 ];
81 const expected = [];
82 for (const [index, root] of roots.entries()) {
83 const name = `review-${index}`;
84 const description = `Review changes in root ${index}.`;
85 const skillPath = yield* writeSkill(
86 path.join(root.directory, name),
87 `---\nname: ${name}\ndescription: ${description}\n---\n# Review\n`,
88 );
89 expected.push({ name, description, path: skillPath, scope: root.scope, enabled: true });
90 }
91
92 assert.deepEqual(yield* discoverAntigravitySkills(input), expected);
93 }),
94 );
95
96 it.effect("uses native root order for duplicate names", () =>
97 Effect.gen(function* () {
98 const fileSystem = yield* FileSystem.FileSystem;
99 const path = yield* Path.Path;
100 const input = yield* makeWorkspace();
101 const roots = [
102 path.join(input.userHome, ".gemini", "config", "skills"),
103 path.join(input.cwd, ".gemini", "skills"),
104 path.join(input.userHome, ".gemini", "antigravity-cli", "skills"),
105 path.join(input.cwd, ".agents", "skills"),
106 path.join(input.cwd, ".agent", "skills"),
107 ];
108 for (const [index, root] of roots.entries()) {
109 yield* writeSkill(
110 path.join(root, `copy-${index}`),
111 `---\nname: review\ndescription: Copy ${index}.\n---\n`,
112 );
113 }
114
115 for (const [index, root] of roots.entries()) {
116 const skills = yield* discoverAntigravitySkills(input);
117 assert.equal(skills.length, 1);
118 assert.equal(skills[0]?.path, path.join(root, `copy-${index}`, "SKILL.md"));
119 yield* fileSystem.remove(root, { recursive: true });
120 }
121 }),
122 );
123
124 it.effect("loads a root skill without scanning its children", () =>
125 Effect.gen(function* () {
126 const fileSystem = yield* FileSystem.FileSystem;
127 const path = yield* Path.Path;
128 const input = yield* makeWorkspace();
129 const root = path.join(input.cwd, ".agents", "skills");
130 const skillPath = yield* writeSkill(root, "---\nname: root-skill\n---\n");
131 yield* writeSkill(path.join(root, "child"), "---\nname: child-skill\n---\n");
132
133 assert.deepEqual(yield* discoverAntigravitySkills(input), [
134 { name: "root-skill", path: skillPath, scope: "project", enabled: true },
135 ]);
136
137 yield* fileSystem.writeFileString(skillPath, "---\nname: [invalid\n---\n");
138 assert.deepEqual(yield* discoverAntigravitySkills(input), []);
139 }),
140 );
141
142 it.effect("uses the filename when valid frontmatter has no name", () =>
143 Effect.gen(function* () {
144 const fileSystem = yield* FileSystem.FileSystem;
145 const path = yield* Path.Path;
146 const input = yield* makeWorkspace();
147 const skillPath = yield* writeSkill(
148 path.join(input.cwd, ".agents", "skills", "not-the-name"),
149 "---\n---\n# Skill body\n",
150 );
151
152 assert.deepEqual(yield* discoverAntigravitySkills(input), [
153 { name: "SKILL", path: skillPath, scope: "project", enabled: true },
154 ]);
155
156 const lowerCasePath = path.join(path.dirname(skillPath), "skill.md");
157 yield* fileSystem.rename(skillPath, lowerCasePath);
158 assert.deepEqual(yield* discoverAntigravitySkills(input), [
159 { name: "skill", path: lowerCasePath, scope: "project", enabled: true },
160 ]);
161
162 yield* fileSystem.rename(lowerCasePath, path.join(path.dirname(skillPath), "SKILL.MD"));
163 assert.deepEqual(yield* discoverAntigravitySkills(input), []);
164 }),
165 );
166
167 it.effect("accepts native metadata delimiters after leading text", () =>
168 Effect.gen(function* () {
169 const path = yield* Path.Path;
170 const input = yield* makeWorkspace();
171 const skillPath = yield* writeSkill(
172 path.join(input.cwd, ".agents", "skills", "review"),
173 "Leading text.---\nname: review\ndescription: null\n---Skill body.",
174 );
175
176 assert.deepEqual(yield* discoverAntigravitySkills(input), [
177 { name: "review", path: skillPath, scope: "project", enabled: true },
178 ]);
179 }),
180 );
181
182 it.effect("ignores invalid files and deeper directories but keeps native hidden skills", () =>
183 Effect.gen(function* () {
184 const fileSystem = yield* FileSystem.FileSystem;
185 const path = yield* Path.Path;
186 const input = yield* makeWorkspace();
187 const root = path.join(input.cwd, ".agents", "skills");
188 const invalidSkills = [
189 ["plain", "# Missing frontmatter\n"],
190 ["broken", "---\nname: [unclosed\n---\n"],
191 ["scalar", "---\n42\n---\n"],
192 ["wrong-type", "---\nname: invalid\ndescription: {}\n---\n"],
193 ["blank-name", '---\nname: " "\n---\n'],
194 ] as const;
195 for (const [name, contents] of invalidSkills) {
196 yield* writeSkill(path.join(root, name), contents);
197 }
198 yield* writeSkill(path.join(root, "nested", "deep"), "---\nname: too-deep\n---\n");
199 yield* writeSkill(
200 path.join(input.cwd, ".claude", "skills", "wrong-provider"),
201 "---\nname: wrong-provider\n---\n",
202 );
203 yield* fileSystem.makeDirectory(path.join(root, ".not-a-skill"));
204 yield* fileSystem.writeFileString(path.join(root, "README.md"), "Not a skill.");
205 const skillPath = yield* writeSkill(
206 path.join(root, ".native-hidden-skill"),
207 "---\nname: native-name\ndescription: >\n Review the code\n and run tests.\n---\n",
208 );
209
210 assert.deepEqual(yield* discoverAntigravitySkills(input), [
211 {
212 name: "native-name",
213 description: "Review the code and run tests.",
214 path: skillPath,
215 scope: "project",
216 enabled: true,
217 },
218 ]);
219 }),
220 );
221
222 it.effect("uses native URI order within a root and skips an invalid higher root", () =>
223 Effect.gen(function* () {
224 const fileSystem = yield* FileSystem.FileSystem;
225 const path = yield* Path.Path;
226 const input = yield* makeWorkspace();
227 const root = path.join(input.cwd, ".agents", "skills");
228 yield* writeSkill(
229 path.join(input.userHome, ".gemini", "config", "skills", "review"),
230 "---\nname: [invalid\n---\n",
231 );
232 const nativeOrder = [" space-copy", "!-copy", "ø-copy", "a-copy"];
233 for (const name of nativeOrder) {
234 yield* writeSkill(path.join(root, name), "---\nname: review\n---\n");
235 }
236
237 for (const name of nativeOrder) {
238 assert.deepEqual(yield* discoverAntigravitySkills(input), [
239 {
240 name: "review",
241 path: path.join(root, name, "SKILL.md"),
242 scope: "project",
243 enabled: true,
244 },
245 ]);
246 yield* fileSystem.remove(path.join(root, name), { recursive: true });
247 }
248 }),
249 );
250
251 it.effect.skipIf(!symlinksSupported)(
252 "follows directory symlinks used to install shared skills",
253 () =>
254 Effect.gen(function* () {
255 const fileSystem = yield* FileSystem.FileSystem;
256 const path = yield* Path.Path;
257 const input = yield* makeWorkspace();
258 const sourceDirectory = path.join(input.userHome, "shared-review");
259 yield* writeSkill(sourceDirectory, "---\nname: review\n---\n");
260 const root = path.join(input.cwd, ".agents", "skills");
261 const linkedDirectory = path.join(root, "review");
262 yield* fileSystem.makeDirectory(root, { recursive: true });
263 yield* fileSystem.symlink(sourceDirectory, linkedDirectory);
264
265 assert.deepEqual(yield* discoverAntigravitySkills(input), [
266 {
267 name: "review",
268 path: path.join(linkedDirectory, "SKILL.md"),
269 scope: "project",
270 enabled: true,
271 },
272 ]);
273 }),
274 );
275
276 it.effect("rejects an oversized skill instead of returning an incomplete catalog", () =>
277 Effect.gen(function* () {
278 const path = yield* Path.Path;
279 const input = yield* makeWorkspace();
280 const skillPath = yield* writeSkill(
281 path.join(input.cwd, ".agents", "skills", "oversized"),
282 `---\nname: oversized\ndescription: Read a large skill.\n---\n${"x".repeat(1_000_000)}`,
283 );
284
285 const result = yield* discoverAntigravitySkills(input).pipe(Effect.result);
286 assert.equal(result._tag, "Failure");
287 if (result._tag === "Failure") {
288 assert.equal(result.failure.reason, "scan-budget-exhausted");
289 assert.equal(result.failure.path, skillPath);
290 }
291 }),
292 );
293
294 it.effect("bounds the total read size across skills", () =>
295 Effect.gen(function* () {
296 const path = yield* Path.Path;
297 const input = yield* makeWorkspace();
298 const root = path.join(input.cwd, ".agents", "skills");
299 for (let index = 0; index < 9; index += 1) {
300 yield* writeSkill(
301 path.join(root, `large-${index}`),
302 `---\nname: large-${index}\n---\n${"x".repeat(900_000)}`,
303 );
304 }
305
306 const result = yield* discoverAntigravitySkills(input).pipe(Effect.result);
307 assert.equal(result._tag, "Failure");
308 if (result._tag === "Failure") {
309 assert.equal(result.failure.reason, "scan-budget-exhausted");
310 assert.equal(result.failure.path, path.join(root, "large-8", "SKILL.md"));
311 }
312 }),
313 );
314});