@kurokeita/add-skill 1.6.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/bin/cli.js +691 -26
- package/dist/skills/skill-creator/scripts/init_skill.cjs +31 -31
- package/dist/skills/skill-creator/scripts/package_skill.cjs +29 -29
- package/dist/skills/skill-creator/scripts/validate_skill.cjs +41 -41
- package/package.json +11 -6
- package/dist/src/commands/add.js +0 -235
- package/dist/src/commands/import.js +0 -116
- package/dist/src/commands/list.js +0 -92
- package/dist/src/commands/remove.js +0 -118
- package/dist/src/utils/github.js +0 -65
- package/dist/src/utils/paths.js +0 -45
package/dist/bin/cli.js
CHANGED
|
@@ -1,29 +1,694 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// bin/cli.ts
|
|
2
4
|
import { Command } from "commander";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
|
|
6
|
+
// src/commands/add.ts
|
|
7
|
+
import os3 from "node:os";
|
|
8
|
+
import path3 from "node:path";
|
|
9
|
+
import {
|
|
10
|
+
cancel,
|
|
11
|
+
confirm,
|
|
12
|
+
intro,
|
|
13
|
+
isCancel,
|
|
14
|
+
multiselect,
|
|
15
|
+
note,
|
|
16
|
+
outro,
|
|
17
|
+
spinner
|
|
18
|
+
} from "@clack/prompts";
|
|
19
|
+
import fs2 from "fs-extra";
|
|
20
|
+
import pc from "picocolors";
|
|
21
|
+
|
|
22
|
+
// src/utils/github.ts
|
|
23
|
+
import os from "node:os";
|
|
24
|
+
import path from "node:path";
|
|
25
|
+
import fs from "fs-extra";
|
|
26
|
+
async function fetchSkillFromGitHub(url) {
|
|
27
|
+
const regex = /github\.com\/([^/]+)\/([^/]+)\/(?:tree|blob)\/([^/]+)\/(.+)/;
|
|
28
|
+
const match = url.match(regex);
|
|
29
|
+
if (!match) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
"Invalid GitHub URL. Format: https://github.com/owner/repo/tree/branch/path/to/skill or blob/branch/path/to/file"
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
const [, owner, repo, ref, skillPath] = match;
|
|
35
|
+
const skillName = path.basename(skillPath);
|
|
36
|
+
const initialApiUrl = `https://api.github.com/repos/${owner}/${repo}/contents/${skillPath}?ref=${ref}`;
|
|
37
|
+
const tempDir = path.join(os.tmpdir(), "ai-agents-install", skillName);
|
|
38
|
+
await fs.ensureDir(tempDir);
|
|
39
|
+
await fs.emptyDir(tempDir);
|
|
40
|
+
let isFile = false;
|
|
41
|
+
async function downloadDirectory(apiUrl, localDir) {
|
|
42
|
+
const response = await fetch(apiUrl, {
|
|
43
|
+
headers: {
|
|
44
|
+
"User-Agent": "ai-agents-cli",
|
|
45
|
+
Accept: "application/vnd.github.v3+json"
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Failed to fetch from GitHub (${response.status}): ${response.statusText}`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
const data = await response.json();
|
|
54
|
+
if (!Array.isArray(data) && data.type === "file") {
|
|
55
|
+
isFile = true;
|
|
56
|
+
const item = data;
|
|
57
|
+
if (item.download_url) {
|
|
58
|
+
const fileContentResponse = await fetch(item.download_url);
|
|
59
|
+
if (!fileContentResponse.ok) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`Failed to download ${item.name}: ${fileContentResponse.statusText}`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
const content = await fileContentResponse.text();
|
|
65
|
+
await fs.writeFile(path.join(localDir, item.name), content);
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (!Array.isArray(data)) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
"Invalid response from GitHub API. Expected directory listing or file object."
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const files = data;
|
|
75
|
+
for (const item of files) {
|
|
76
|
+
if (item.type === "file" && item.download_url) {
|
|
77
|
+
const fileContentResponse = await fetch(item.download_url);
|
|
78
|
+
if (!fileContentResponse.ok) {
|
|
79
|
+
console.warn(
|
|
80
|
+
`Failed to download ${item.name}: ${fileContentResponse.statusText}`
|
|
81
|
+
);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const content = await fileContentResponse.text();
|
|
85
|
+
await fs.writeFile(path.join(localDir, item.name), content);
|
|
86
|
+
} else if (item.type === "dir") {
|
|
87
|
+
const newLocalDir = path.join(localDir, item.name);
|
|
88
|
+
await fs.ensureDir(newLocalDir);
|
|
89
|
+
await downloadDirectory(item.url, newLocalDir);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
await downloadDirectory(initialApiUrl, tempDir);
|
|
94
|
+
return { tempDir, skillName, isFile };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/utils/paths.ts
|
|
98
|
+
import os2 from "node:os";
|
|
99
|
+
import path2 from "node:path";
|
|
100
|
+
import { fileURLToPath } from "node:url";
|
|
101
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
102
|
+
var __dirname = path2.dirname(__filename);
|
|
103
|
+
var PROJECT_ROOT = path2.resolve(__dirname, "../..");
|
|
104
|
+
var PLATFORM_LABELS = {
|
|
105
|
+
antigravity: "Antigravity",
|
|
106
|
+
gemini: "Gemini CLI",
|
|
107
|
+
copilot: "GitHub Copilot",
|
|
108
|
+
windsurf: "Windsurf"
|
|
109
|
+
};
|
|
110
|
+
var PLATFORM_PATHS_SKILLS = {
|
|
111
|
+
antigravity: path2.join(os2.homedir(), ".gemini/antigravity/global_skills"),
|
|
112
|
+
copilot: path2.join(os2.homedir(), ".copilot/skills"),
|
|
113
|
+
gemini: path2.join(os2.homedir(), ".gemini/skills"),
|
|
114
|
+
windsurf: path2.join(os2.homedir(), ".codeium/windsurf/skills")
|
|
115
|
+
};
|
|
116
|
+
var PLATFORM_PATHS_AGENTS = {
|
|
117
|
+
antigravity: path2.join(os2.homedir(), ".gemini/antigravity/global_agents"),
|
|
118
|
+
copilot: path2.join(os2.homedir(), ".copilot/agents"),
|
|
119
|
+
gemini: path2.join(os2.homedir(), ".gemini/agents"),
|
|
120
|
+
windsurf: path2.join(os2.homedir(), ".codeium/windsurf/agents")
|
|
121
|
+
};
|
|
122
|
+
var PLATFORM_PATHS_WORKFLOWS = {
|
|
123
|
+
antigravity: path2.join(os2.homedir(), ".gemini/antigravity/global_workflows"),
|
|
124
|
+
copilot: path2.join(os2.homedir(), ".copilot/prompts"),
|
|
125
|
+
gemini: path2.join(os2.homedir(), ".gemini/commands"),
|
|
126
|
+
windsurf: path2.join(os2.homedir(), ".codeium/windsurf/global_workflows")
|
|
127
|
+
};
|
|
128
|
+
var TYPE_DIRS = {
|
|
129
|
+
skill: path2.join(PROJECT_ROOT, "skills"),
|
|
130
|
+
agent: path2.join(PROJECT_ROOT, "agents"),
|
|
131
|
+
workflow: path2.join(PROJECT_ROOT, "workflows")
|
|
132
|
+
};
|
|
133
|
+
function getTargetPaths(type) {
|
|
134
|
+
switch (type) {
|
|
135
|
+
case "agent":
|
|
136
|
+
return PLATFORM_PATHS_AGENTS;
|
|
137
|
+
case "workflow":
|
|
138
|
+
return PLATFORM_PATHS_WORKFLOWS;
|
|
139
|
+
default:
|
|
140
|
+
return PLATFORM_PATHS_SKILLS;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/utils/toml.ts
|
|
145
|
+
function convertToGeminiCommandTOML(markdownContent) {
|
|
146
|
+
const lines = markdownContent.split("\n");
|
|
147
|
+
let description = "";
|
|
148
|
+
for (let i = 0; i < lines.length; i++) {
|
|
149
|
+
const trimmedLine = lines[i].trim();
|
|
150
|
+
if (trimmedLine && trimmedLine !== "---" && !trimmedLine.startsWith("<!--")) {
|
|
151
|
+
if (trimmedLine.startsWith("#")) {
|
|
152
|
+
description = trimmedLine.replace(/^#+\s*/, "");
|
|
153
|
+
} else {
|
|
154
|
+
description = trimmedLine;
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (description.length > 100) {
|
|
160
|
+
description = `${description.substring(0, 97)}...`;
|
|
161
|
+
}
|
|
162
|
+
const escapedContent = markdownContent.replace(/"""/g, '\\"\\"\\"');
|
|
163
|
+
return `description = ${JSON.stringify(description)}
|
|
164
|
+
|
|
165
|
+
prompt = """
|
|
166
|
+
${escapedContent.trim()}
|
|
167
|
+
"""
|
|
168
|
+
`;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/commands/add.ts
|
|
172
|
+
function getPlatformOptions(type) {
|
|
173
|
+
const paths = getTargetPaths(type);
|
|
174
|
+
return Object.entries(paths).map(([platform, pathStr]) => ({
|
|
175
|
+
label: PLATFORM_LABELS[platform],
|
|
176
|
+
value: platform,
|
|
177
|
+
hint: pathStr.replace(os3.homedir(), "~")
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
async function installItem(itemName, overwrite, sourcePath, targetBaseDir) {
|
|
181
|
+
const targetPath = path3.join(targetBaseDir, itemName);
|
|
182
|
+
if (!await fs2.pathExists(sourcePath)) {
|
|
183
|
+
throw new Error(`Item '${itemName}' not found at ${sourcePath}`);
|
|
184
|
+
}
|
|
185
|
+
if (!overwrite && await fs2.pathExists(targetPath)) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
await fs2.ensureDir(targetBaseDir);
|
|
189
|
+
await fs2.copy(sourcePath, targetPath, { overwrite });
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
async function add(type, url) {
|
|
193
|
+
intro(pc.bgCyan(pc.black(` AI Manager : Add ${type} `)));
|
|
194
|
+
const normalizedType = type.toLowerCase().endsWith("s") ? type.slice(0, -1) : type;
|
|
195
|
+
if (!TYPE_DIRS[normalizedType]) {
|
|
196
|
+
cancel(`Unknown type: ${type}. Supported: skill, agent, workflow`);
|
|
197
|
+
process.exit(1);
|
|
198
|
+
}
|
|
199
|
+
let tempDir = null;
|
|
200
|
+
let selectedItems = [];
|
|
201
|
+
try {
|
|
202
|
+
if (url) {
|
|
203
|
+
const s2 = spinner();
|
|
204
|
+
s2.start(`Fetching ${normalizedType} from GitHub...`);
|
|
205
|
+
try {
|
|
206
|
+
const result = await fetchSkillFromGitHub(url);
|
|
207
|
+
tempDir = result.tempDir;
|
|
208
|
+
selectedItems = [result.skillName];
|
|
209
|
+
s2.stop(pc.green(`Fetched ${normalizedType}: ${result.skillName}`));
|
|
210
|
+
} catch (e) {
|
|
211
|
+
s2.stop(pc.red("Failed to fetch"));
|
|
212
|
+
throw e;
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
const sourceDir = TYPE_DIRS[normalizedType];
|
|
216
|
+
if (!await fs2.pathExists(sourceDir)) {
|
|
217
|
+
cancel(`${normalizedType} directory not found!`);
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
220
|
+
const entries = await fs2.readdir(sourceDir, { withFileTypes: true });
|
|
221
|
+
const availableItems = entries.filter(
|
|
222
|
+
(entry) => entry.isDirectory() || (normalizedType === "workflow" || normalizedType === "agent") && entry.isFile() && entry.name.endsWith(".md")
|
|
223
|
+
).map((entry) => ({ label: entry.name, value: entry.name })).sort((a, b) => a.label.localeCompare(b.label));
|
|
224
|
+
if (availableItems.length === 0) {
|
|
225
|
+
cancel(`No ${normalizedType}s found in directory.`);
|
|
226
|
+
process.exit(0);
|
|
227
|
+
}
|
|
228
|
+
const items = await multiselect({
|
|
229
|
+
message: `Select ${normalizedType}s to install:`,
|
|
230
|
+
options: availableItems,
|
|
231
|
+
required: true
|
|
232
|
+
});
|
|
233
|
+
if (isCancel(items)) {
|
|
234
|
+
cancel("Operation cancelled.");
|
|
235
|
+
process.exit(0);
|
|
236
|
+
}
|
|
237
|
+
selectedItems = items;
|
|
238
|
+
}
|
|
239
|
+
const supportedPaths = getTargetPaths(normalizedType);
|
|
240
|
+
const currentPlatformOptions = getPlatformOptions(normalizedType);
|
|
241
|
+
if (currentPlatformOptions.length === 0) {
|
|
242
|
+
cancel(`No supported platforms found for type '${normalizedType}'.`);
|
|
243
|
+
process.exit(1);
|
|
244
|
+
}
|
|
245
|
+
const platforms = await multiselect({
|
|
246
|
+
message: "Select target platforms:",
|
|
247
|
+
options: currentPlatformOptions,
|
|
248
|
+
required: true
|
|
249
|
+
});
|
|
250
|
+
if (isCancel(platforms)) {
|
|
251
|
+
console.log("Cleaning up...");
|
|
252
|
+
if (tempDir) await fs2.remove(tempDir);
|
|
253
|
+
cancel("Operation cancelled.");
|
|
254
|
+
process.exit(0);
|
|
255
|
+
}
|
|
256
|
+
const selectedPlatforms = platforms;
|
|
257
|
+
const existingItems = [];
|
|
258
|
+
for (const platform of selectedPlatforms) {
|
|
259
|
+
const targetBase = supportedPaths[platform];
|
|
260
|
+
if (!targetBase) continue;
|
|
261
|
+
for (const item of selectedItems) {
|
|
262
|
+
const targetPath = path3.join(targetBase, item);
|
|
263
|
+
if (await fs2.pathExists(targetPath)) {
|
|
264
|
+
existingItems.push({ item, platform });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
let overwrite = true;
|
|
269
|
+
if (existingItems.length > 0) {
|
|
270
|
+
const limit = 5;
|
|
271
|
+
const displayList = existingItems.slice(0, limit).map((e) => `${pc.bold(e.item)} (${e.platform})`).join(", ");
|
|
272
|
+
const remainder = existingItems.length - limit;
|
|
273
|
+
const message = remainder > 0 ? `The following items already exist: ${displayList}, and ${remainder} others.` : `The following items already exist: ${displayList}.`;
|
|
274
|
+
note(message, "Attention");
|
|
275
|
+
const shouldOverwrite = await confirm({
|
|
276
|
+
message: "Do you want to overwrite existing items?",
|
|
277
|
+
initialValue: false
|
|
278
|
+
});
|
|
279
|
+
if (isCancel(shouldOverwrite)) {
|
|
280
|
+
if (tempDir) await fs2.remove(tempDir);
|
|
281
|
+
cancel("Operation cancelled.");
|
|
282
|
+
process.exit(0);
|
|
283
|
+
}
|
|
284
|
+
overwrite = shouldOverwrite;
|
|
285
|
+
}
|
|
286
|
+
note(
|
|
287
|
+
`Installing ${selectedItems.length} ${normalizedType}s to ${selectedPlatforms.length} platforms...`,
|
|
288
|
+
"Summary"
|
|
289
|
+
);
|
|
290
|
+
const s = spinner();
|
|
291
|
+
s.start("Installing...");
|
|
292
|
+
const errors = [];
|
|
293
|
+
let installedCount = 0;
|
|
294
|
+
let skippedCount = 0;
|
|
295
|
+
for (const platform of selectedPlatforms) {
|
|
296
|
+
const targetBase = supportedPaths[platform];
|
|
297
|
+
if (!targetBase) continue;
|
|
298
|
+
for (const item of selectedItems) {
|
|
299
|
+
const message = `Installing ${pc.bold(item)} to ${pc.cyan(platform)}...`;
|
|
300
|
+
s.message(message);
|
|
301
|
+
try {
|
|
302
|
+
if (url && tempDir) {
|
|
303
|
+
}
|
|
304
|
+
let currentSourcePath;
|
|
305
|
+
if (url && tempDir) {
|
|
306
|
+
const potentialFile = path3.join(tempDir, item);
|
|
307
|
+
if (await fs2.pathExists(potentialFile) && (await fs2.stat(potentialFile)).isFile()) {
|
|
308
|
+
currentSourcePath = potentialFile;
|
|
309
|
+
} else {
|
|
310
|
+
currentSourcePath = tempDir;
|
|
311
|
+
}
|
|
312
|
+
} else {
|
|
313
|
+
const src = path3.join(TYPE_DIRS[normalizedType], item);
|
|
314
|
+
if ((await fs2.stat(src)).isFile()) {
|
|
315
|
+
currentSourcePath = src;
|
|
316
|
+
} else {
|
|
317
|
+
currentSourcePath = src;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
let targetItemName = item;
|
|
321
|
+
if (platform === "windsurf" && normalizedType === "agent") {
|
|
322
|
+
targetItemName = path3.join(path3.parse(item).name, "AGENTS.md");
|
|
323
|
+
}
|
|
324
|
+
if (platform === "gemini" && normalizedType === "workflow" && currentSourcePath.endsWith(".md")) {
|
|
325
|
+
const targetPath = path3.join(
|
|
326
|
+
targetBase,
|
|
327
|
+
item.replace(/\.md$/, ".toml")
|
|
328
|
+
);
|
|
329
|
+
if (!overwrite && await fs2.pathExists(targetPath)) {
|
|
330
|
+
skippedCount++;
|
|
331
|
+
} else {
|
|
332
|
+
const content = await fs2.readFile(currentSourcePath, "utf-8");
|
|
333
|
+
const tomlContent = convertToGeminiCommandTOML(content);
|
|
334
|
+
await fs2.ensureDir(targetBase);
|
|
335
|
+
await fs2.writeFile(targetPath, tomlContent);
|
|
336
|
+
installedCount++;
|
|
337
|
+
}
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
const installed = await installItem(
|
|
341
|
+
targetItemName,
|
|
342
|
+
overwrite,
|
|
343
|
+
currentSourcePath,
|
|
344
|
+
targetBase
|
|
345
|
+
);
|
|
346
|
+
if (installed) {
|
|
347
|
+
installedCount++;
|
|
348
|
+
} else {
|
|
349
|
+
skippedCount++;
|
|
350
|
+
}
|
|
351
|
+
} catch (err) {
|
|
352
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
353
|
+
errors.push(`${item} -> ${platform}: ${errorMessage}`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (tempDir) {
|
|
358
|
+
await fs2.remove(tempDir);
|
|
359
|
+
}
|
|
360
|
+
if (errors.length > 0) {
|
|
361
|
+
s.stop(
|
|
362
|
+
pc.yellow(
|
|
363
|
+
`Completed with errors. Installed: ${installedCount}, Skipped: ${skippedCount}, Errors: ${errors.length}`
|
|
364
|
+
)
|
|
365
|
+
);
|
|
366
|
+
console.error(pc.red("\nErrors encountered:"));
|
|
367
|
+
for (const e of errors) {
|
|
368
|
+
console.error(pc.red(`- ${e}`));
|
|
369
|
+
}
|
|
370
|
+
} else {
|
|
371
|
+
s.stop(
|
|
372
|
+
pc.green(
|
|
373
|
+
`Successfully installed ${installedCount} ${normalizedType}s. (${skippedCount} skipped)`
|
|
374
|
+
)
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
outro("You're all set!");
|
|
378
|
+
} catch (error) {
|
|
379
|
+
if (tempDir) await fs2.remove(tempDir);
|
|
380
|
+
cancel(`An error occurred: ${error}`);
|
|
381
|
+
process.exit(1);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/commands/import.ts
|
|
386
|
+
import path4 from "node:path";
|
|
387
|
+
import {
|
|
388
|
+
cancel as cancel2,
|
|
389
|
+
confirm as confirm2,
|
|
390
|
+
intro as intro2,
|
|
391
|
+
isCancel as isCancel2,
|
|
392
|
+
outro as outro2,
|
|
393
|
+
spinner as spinner2
|
|
394
|
+
} from "@clack/prompts";
|
|
395
|
+
import fs3 from "fs-extra";
|
|
396
|
+
import pc2 from "picocolors";
|
|
397
|
+
async function importItem(type, url) {
|
|
398
|
+
intro2(pc2.bgCyan(pc2.black(` AI Manager : Import ${type} `)));
|
|
399
|
+
const normalizedType = type.toLowerCase().endsWith("s") ? type.slice(0, -1) : type;
|
|
400
|
+
const targetBaseDir = TYPE_DIRS[normalizedType];
|
|
401
|
+
if (!targetBaseDir) {
|
|
402
|
+
cancel2(`Unknown type: ${type}. Supported: skill, agent, workflow`);
|
|
403
|
+
process.exit(1);
|
|
404
|
+
}
|
|
405
|
+
if (!url) {
|
|
406
|
+
cancel2("GitHub URL is required.");
|
|
407
|
+
process.exit(1);
|
|
408
|
+
}
|
|
409
|
+
let tempDir = null;
|
|
410
|
+
try {
|
|
411
|
+
const s = spinner2();
|
|
412
|
+
s.start(`Fetching ${normalizedType} from GitHub...`);
|
|
413
|
+
let itemName = "";
|
|
414
|
+
let isFile = false;
|
|
415
|
+
try {
|
|
416
|
+
const result = await fetchSkillFromGitHub(url);
|
|
417
|
+
tempDir = result.tempDir;
|
|
418
|
+
if (!tempDir) throw new Error("Failed to create temp directory");
|
|
419
|
+
itemName = result.skillName;
|
|
420
|
+
isFile = result.isFile;
|
|
421
|
+
s.stop(pc2.green(`Fetched: ${itemName}`));
|
|
422
|
+
} catch (e) {
|
|
423
|
+
s.stop(pc2.red("Failed to fetch"));
|
|
424
|
+
throw e;
|
|
425
|
+
}
|
|
426
|
+
const shouldFlatten = (normalizedType === "agent" || normalizedType === "workflow") && !isFile;
|
|
427
|
+
const targetPath = shouldFlatten ? targetBaseDir : path4.join(targetBaseDir, itemName);
|
|
428
|
+
if (shouldFlatten) {
|
|
429
|
+
const srcFiles = await fs3.readdir(tempDir);
|
|
430
|
+
const conflicts = [];
|
|
431
|
+
for (const file of srcFiles) {
|
|
432
|
+
if (await fs3.pathExists(path4.join(targetBaseDir, file))) {
|
|
433
|
+
conflicts.push(file);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (conflicts.length > 0) {
|
|
437
|
+
const limit = 5;
|
|
438
|
+
const displayList = conflicts.slice(0, limit).join(", ");
|
|
439
|
+
const remainder = conflicts.length - limit;
|
|
440
|
+
const message = remainder > 0 ? `Files ${displayList} (and ${remainder} others) already exist in ${targetBaseDir}. Overwrite?` : `Files ${displayList} already exist in ${targetBaseDir}. Overwrite?`;
|
|
441
|
+
const shouldOverwrite = await confirm2({
|
|
442
|
+
message,
|
|
443
|
+
initialValue: false
|
|
444
|
+
});
|
|
445
|
+
if (isCancel2(shouldOverwrite) || !shouldOverwrite) {
|
|
446
|
+
if (tempDir) await fs3.remove(tempDir);
|
|
447
|
+
cancel2("Operation cancelled.");
|
|
448
|
+
process.exit(0);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
} else if (await fs3.pathExists(targetPath)) {
|
|
452
|
+
const shouldOverwrite = await confirm2({
|
|
453
|
+
message: `${normalizedType} '${itemName}' already exists in the repo. Overwrite?`,
|
|
454
|
+
initialValue: false
|
|
455
|
+
});
|
|
456
|
+
if (isCancel2(shouldOverwrite) || !shouldOverwrite) {
|
|
457
|
+
if (tempDir) await fs3.remove(tempDir);
|
|
458
|
+
cancel2("Operation cancelled.");
|
|
459
|
+
process.exit(0);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
s.start(`Importing ${itemName} to ${targetBaseDir}...`);
|
|
463
|
+
await fs3.ensureDir(targetBaseDir);
|
|
464
|
+
if (isFile) {
|
|
465
|
+
await fs3.copy(path4.join(tempDir, itemName), targetPath, {
|
|
466
|
+
overwrite: true
|
|
467
|
+
});
|
|
468
|
+
} else {
|
|
469
|
+
if (shouldFlatten) {
|
|
470
|
+
await fs3.copy(tempDir, targetBaseDir, { overwrite: true });
|
|
471
|
+
} else {
|
|
472
|
+
await fs3.copy(tempDir, targetPath, { overwrite: true });
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
s.stop(pc2.green(`Successfully imported ${itemName}!`));
|
|
476
|
+
if (tempDir) {
|
|
477
|
+
await fs3.remove(tempDir);
|
|
478
|
+
}
|
|
479
|
+
outro2(`${normalizedType} available at: ${targetPath}`);
|
|
480
|
+
} catch (error) {
|
|
481
|
+
if (tempDir) await fs3.remove(tempDir);
|
|
482
|
+
cancel2(`An error occurred: ${error}`);
|
|
483
|
+
process.exit(1);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// src/commands/list.ts
|
|
488
|
+
import fs4 from "fs-extra";
|
|
489
|
+
import pc3 from "picocolors";
|
|
490
|
+
async function list(type, options) {
|
|
491
|
+
try {
|
|
492
|
+
const typesToList = type ? [type.toLowerCase()] : ["skill", "agent", "workflow"];
|
|
493
|
+
for (const t of typesToList) {
|
|
494
|
+
const normalizedType = t.endsWith("s") ? t.slice(0, -1) : t;
|
|
495
|
+
if (options?.local) {
|
|
496
|
+
console.log(pc3.bold(pc3.blue(`Installed ${normalizedType}s (Local):`)));
|
|
497
|
+
const targetPaths = getTargetPaths(normalizedType);
|
|
498
|
+
let foundAny = false;
|
|
499
|
+
for (const [platform, pathStr] of Object.entries(targetPaths)) {
|
|
500
|
+
const fullPath = pathStr;
|
|
501
|
+
if (await fs4.pathExists(fullPath)) {
|
|
502
|
+
const entries = await fs4.readdir(fullPath, {
|
|
503
|
+
withFileTypes: true
|
|
504
|
+
});
|
|
505
|
+
const items = entries.filter(
|
|
506
|
+
(entry) => entry.isDirectory() || // For local items, agents/workflows might be directories OR .md files depending on how they were installed/flattened.
|
|
507
|
+
// Usually flattened -> directory (if unpacked) or file (if generic).
|
|
508
|
+
// Existing add logic:
|
|
509
|
+
// Agents/Workflows can be flattened (unpacked to base) or not.
|
|
510
|
+
// If flattened, they are files in the base dir? No, unpacked to base means they are files/dirs IN the base dir.
|
|
511
|
+
// Wait, if I import "agent-a" (dir) and flatten, it copies contents of agent-a to agents/.
|
|
512
|
+
// So "agents/skill.md" might exist.
|
|
513
|
+
// The user requirement says "list all installed agents/skills/workflows".
|
|
514
|
+
// In local global_skills (antigravity), they are directories.
|
|
515
|
+
// In local global_agents, they might be directories or .md files.
|
|
516
|
+
// Let's list directories and .md files.
|
|
517
|
+
entry.isFile() && entry.name.endsWith(".md")
|
|
518
|
+
).map((entry) => entry.name).sort();
|
|
519
|
+
if (items.length > 0) {
|
|
520
|
+
foundAny = true;
|
|
521
|
+
console.log(pc3.cyan(` ${platform}:`));
|
|
522
|
+
for (const item of items) {
|
|
523
|
+
console.log(` - ${item}`);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
if (!foundAny) {
|
|
529
|
+
console.log(pc3.dim(` No installed ${normalizedType}s found.`));
|
|
530
|
+
}
|
|
531
|
+
console.log("");
|
|
532
|
+
} else {
|
|
533
|
+
if (!TYPE_DIRS[normalizedType]) {
|
|
534
|
+
if (type) {
|
|
535
|
+
console.error(
|
|
536
|
+
pc3.red(
|
|
537
|
+
`Unknown type: ${type}. Supported types: skill, agent, workflow`
|
|
538
|
+
)
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
const dirPath = TYPE_DIRS[normalizedType];
|
|
544
|
+
if (!await fs4.pathExists(dirPath)) {
|
|
545
|
+
if (type) {
|
|
546
|
+
console.log(pc3.yellow(`No ${t} directory found at: ${dirPath}`));
|
|
547
|
+
}
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
const entries = await fs4.readdir(dirPath, { withFileTypes: true });
|
|
551
|
+
const items = entries.filter(
|
|
552
|
+
(entry) => entry.isDirectory() || normalizedType !== "skill" && entry.isFile() && entry.name.endsWith(".md")
|
|
553
|
+
).map((entry) => entry.name).sort();
|
|
554
|
+
if (items.length > 0) {
|
|
555
|
+
console.log(pc3.bold(pc3.blue(`Available ${normalizedType}s:`)));
|
|
556
|
+
for (const item of items) {
|
|
557
|
+
console.log(`- ${item}`);
|
|
558
|
+
}
|
|
559
|
+
console.log(pc3.dim(`Total: ${items.length} ${normalizedType}s
|
|
560
|
+
`));
|
|
561
|
+
} else if (type) {
|
|
562
|
+
console.log(pc3.dim(`No ${normalizedType}s found.`));
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
} catch (error) {
|
|
567
|
+
console.error(pc3.red("Error listing items:"), error);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// src/commands/remove.ts
|
|
572
|
+
import path5 from "node:path";
|
|
573
|
+
import {
|
|
574
|
+
cancel as cancel3,
|
|
575
|
+
confirm as confirm3,
|
|
576
|
+
intro as intro3,
|
|
577
|
+
isCancel as isCancel3,
|
|
578
|
+
multiselect as multiselect2,
|
|
579
|
+
outro as outro3,
|
|
580
|
+
spinner as spinner3
|
|
581
|
+
} from "@clack/prompts";
|
|
582
|
+
import fs5 from "fs-extra";
|
|
583
|
+
import pc4 from "picocolors";
|
|
584
|
+
async function remove(type) {
|
|
585
|
+
intro3(pc4.bgCyan(pc4.black(` AI Manager : Remove ${type} `)));
|
|
586
|
+
const normalizedType = type.toLowerCase().endsWith("s") ? type.slice(0, -1) : type;
|
|
587
|
+
const targetPaths = getTargetPaths(normalizedType);
|
|
588
|
+
const uniqueItems = /* @__PURE__ */ new Set();
|
|
589
|
+
const s = spinner3();
|
|
590
|
+
s.start("Scanning for installed items...");
|
|
591
|
+
for (const pathStr of Object.values(targetPaths)) {
|
|
592
|
+
if (await fs5.pathExists(pathStr)) {
|
|
593
|
+
const entries = await fs5.readdir(pathStr, {
|
|
594
|
+
withFileTypes: true
|
|
595
|
+
});
|
|
596
|
+
for (const entry of entries) {
|
|
597
|
+
if (entry.isDirectory() || normalizedType === "workflow" && entry.isFile() && entry.name.endsWith(".md") || normalizedType === "agent" && entry.isFile() && entry.name.endsWith(".md")) {
|
|
598
|
+
uniqueItems.add(entry.name);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
s.stop(`Found ${uniqueItems.size} unique installed ${normalizedType}s.`);
|
|
604
|
+
if (uniqueItems.size === 0) {
|
|
605
|
+
cancel3(`No installed ${normalizedType}s found.`);
|
|
606
|
+
process.exit(0);
|
|
607
|
+
}
|
|
608
|
+
const sortedItems = Array.from(uniqueItems).sort();
|
|
609
|
+
const itemSelections = await multiselect2({
|
|
610
|
+
message: `Select ${normalizedType}s to remove:`,
|
|
611
|
+
options: sortedItems.map((item) => ({ value: item, label: item })),
|
|
612
|
+
required: true
|
|
613
|
+
});
|
|
614
|
+
if (isCancel3(itemSelections)) {
|
|
615
|
+
cancel3("Operation cancelled.");
|
|
616
|
+
process.exit(0);
|
|
617
|
+
}
|
|
618
|
+
const selectedItems = itemSelections;
|
|
619
|
+
const platformOptions = Object.entries(targetPaths).map(([platform]) => ({
|
|
620
|
+
label: PLATFORM_LABELS[platform],
|
|
621
|
+
value: platform
|
|
622
|
+
}));
|
|
623
|
+
const platformSelections = await multiselect2({
|
|
624
|
+
message: "Select platforms to remove from:",
|
|
625
|
+
options: platformOptions,
|
|
626
|
+
required: true
|
|
627
|
+
});
|
|
628
|
+
if (isCancel3(platformSelections)) {
|
|
629
|
+
cancel3("Operation cancelled.");
|
|
630
|
+
process.exit(0);
|
|
631
|
+
}
|
|
632
|
+
const selectedPlatforms = platformSelections;
|
|
633
|
+
const confirmDelete = await confirm3({
|
|
634
|
+
message: `Are you sure you want to remove ${selectedItems.length} item(s) from ${selectedPlatforms.length} platform(s)?`,
|
|
635
|
+
initialValue: false
|
|
636
|
+
});
|
|
637
|
+
if (isCancel3(confirmDelete) || !confirmDelete) {
|
|
638
|
+
cancel3("Operation cancelled.");
|
|
639
|
+
process.exit(0);
|
|
640
|
+
}
|
|
641
|
+
const sDel = spinner3();
|
|
642
|
+
sDel.start("Removing items...");
|
|
643
|
+
let removedCount = 0;
|
|
644
|
+
let notFoundCount = 0;
|
|
645
|
+
const errors = [];
|
|
646
|
+
for (const platform of selectedPlatforms) {
|
|
647
|
+
const targetBase = targetPaths[platform];
|
|
648
|
+
if (!targetBase) continue;
|
|
649
|
+
for (const item of selectedItems) {
|
|
650
|
+
const targetPath = path5.join(targetBase, item);
|
|
651
|
+
if (await fs5.pathExists(targetPath)) {
|
|
652
|
+
sDel.message(`Removing ${pc4.bold(item)} from ${pc4.cyan(platform)}...`);
|
|
653
|
+
try {
|
|
654
|
+
await fs5.remove(targetPath);
|
|
655
|
+
removedCount++;
|
|
656
|
+
} catch (err) {
|
|
657
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
658
|
+
errors.push(`${item} (${platform}): ${msg}`);
|
|
659
|
+
}
|
|
660
|
+
} else {
|
|
661
|
+
notFoundCount++;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
if (errors.length > 0) {
|
|
666
|
+
sDel.stop(
|
|
667
|
+
pc4.yellow(
|
|
668
|
+
`Completed with errors. Removed: ${removedCount}, Not Found: ${notFoundCount}, Errors: ${errors.length}`
|
|
669
|
+
)
|
|
670
|
+
);
|
|
671
|
+
console.error(pc4.red("\nErrors encountered:"));
|
|
672
|
+
for (const e of errors) {
|
|
673
|
+
console.error(pc4.red(`- ${e}`));
|
|
674
|
+
}
|
|
675
|
+
} else {
|
|
676
|
+
sDel.stop(
|
|
677
|
+
pc4.green(
|
|
678
|
+
`Successfully removed ${removedCount} items. (${notFoundCount} not found)`
|
|
679
|
+
)
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
outro3("Done!");
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// bin/cli.ts
|
|
686
|
+
var program = new Command();
|
|
687
|
+
program.name("ai-agent").description("CLI to manage AI agents, skills, and workflows").version("1.4.0");
|
|
688
|
+
program.command("list [type]").description("List available items (skills, agents, workflows)").option("-l, --local", "List installed items locally").action(list);
|
|
689
|
+
program.command("add <type> [url]").description(
|
|
690
|
+
"Add an item (skill, agent, workflow) to platforms (Interactive or from GitHub URL)"
|
|
691
|
+
).action(add);
|
|
692
|
+
program.command("import <type> <url>").description("Import an item from GitHub to the repo").action(importItem);
|
|
693
|
+
program.command("remove <type>").description("Remove locally installed items (skills, agents, workflows)").action(remove);
|
|
29
694
|
program.parse();
|