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