-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.ts
More file actions
330 lines (295 loc) · 12.4 KB
/
Copy pathindex.ts
File metadata and controls
330 lines (295 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/usr/bin/env node
import { Command } from 'commander';
import inquirer from 'inquirer';
import ora from 'ora';
import path from 'path';
import os from 'os';
import chalk from 'chalk';
import { createRequire } from 'module';
import { checkNodeVersion, checkCargo, checkSyncCtl } from './prerequisites/check.js';
import { installRustup } from './prerequisites/install-rustup.js';
import { installSyncCtl } from './prerequisites/install-cli.js';
import { detectAgents, allAgents } from './agents/detect.js';
import { AgentConfig, AgentName } from './agents/types.js';
import { loadSkills, getBundledSkillsDir } from './skills.js';
import {
writeSkillsForClaude,
writeSkillsForCodex,
writeSkillsForCursor,
writeSkillsForWindsurf,
writeSkillsForGemini,
InstallOptions,
} from './commands/install.js';
import { removeSyncableSkills, removeGeminiSection } from './commands/uninstall.js';
import { uninstallClaudePlugin } from './transformers/claude.js';
import { countInstalledSkills } from './commands/status.js';
const require = createRequire(import.meta.url);
const pkg = require('../package.json');
const program = new Command();
program
.name('syncable-cli-skills')
.description('Install Syncable CLI skills for AI coding agents')
.version(pkg.version);
program
.command('install', { isDefault: true })
.description('Install sync-ctl and skills')
.option('--skip-cli', 'Skip sync-ctl installation check')
.option('--dry-run', 'Show what would be done without doing it')
.option('--agents <list>', 'Comma-separated agent list')
.option('--global-only', 'Only install global skills')
.option('--project-only', 'Only install project-level rules')
.option('-y, --yes', 'Skip confirmations')
.option('--verbose', 'Show detailed output')
.action(async (opts) => {
const verbose = opts.verbose || false;
console.log(chalk.bold('\n Syncable CLI Skills Installer'));
console.log(' ' + '─'.repeat(29) + '\n');
// Check Node.js version
const nodeCheck = checkNodeVersion();
if (nodeCheck.status === 'outdated') {
console.error(chalk.red(` Node.js >= 18.0.0 required. Found: ${nodeCheck.version}`));
process.exit(1);
}
console.log(chalk.green(` ✓ Node.js ${nodeCheck.version}`));
// Check prerequisites
if (!opts.skipCli) {
const cargoStatus = await checkCargo();
const syncCtlStatus = await checkSyncCtl();
if (cargoStatus.status === 'ok') {
console.log(chalk.green(` ✓ cargo ${cargoStatus.version}`));
} else {
console.log(chalk.red(' ✗ cargo not found'));
}
if (syncCtlStatus.status === 'ok') {
console.log(chalk.green(` ✓ sync-ctl v${syncCtlStatus.version}`));
} else if (syncCtlStatus.status === 'outdated') {
console.log(chalk.yellow(` ⚠ sync-ctl v${syncCtlStatus.version} (outdated)`));
} else {
console.log(chalk.red(' ✗ sync-ctl not found'));
}
// Install missing prerequisites
if (cargoStatus.status === 'missing') {
console.log(chalk.yellow('\n sync-ctl requires Rust\'s cargo package manager.\n'));
const { installRust } = opts.yes
? { installRust: true }
: await inquirer.prompt([{ type: 'confirm', name: 'installRust', message: 'Install Rust toolchain via rustup?', default: true }]);
if (installRust) {
const spinner = ora(' Installing rustup...').start();
const success = await installRustup();
if (success) {
spinner.succeed(' Rust toolchain installed');
} else {
spinner.fail(' Failed to install Rust. Install manually: https://rustup.rs');
}
}
}
if (syncCtlStatus.status === 'missing' || syncCtlStatus.status === 'outdated') {
const cargoNow = await checkCargo();
if (cargoNow.status === 'ok') {
const message = syncCtlStatus.status === 'outdated'
? 'Update syncable-cli via cargo?'
: 'Install syncable-cli via cargo?';
const { installCli } = opts.yes
? { installCli: true }
: await inquirer.prompt([{ type: 'confirm', name: 'installCli', message, default: true }]);
if (installCli) {
const spinner = ora(' Running: cargo install syncable-cli').start();
const force = syncCtlStatus.status === 'outdated';
const success = await installSyncCtl(force);
if (success) {
spinner.succeed(' sync-ctl installed');
} else {
spinner.fail(' Failed to install sync-ctl. Try: cargo install syncable-cli');
}
}
}
}
}
// Detect agents
console.log(chalk.bold('\n Detecting AI coding agents...\n'));
const detectionResults = await detectAgents();
for (const { agent, detected } of detectionResults) {
if (detected) {
console.log(chalk.green(` ✓ ${agent.displayName} detected`));
if (verbose) console.log(chalk.dim(` path: ${agent.getSkillPath()}`));
} else {
console.log(chalk.dim(` ✗ ${agent.displayName} not detected`));
}
}
// Determine which agents to install for
let selectedAgents: AgentConfig[];
if (opts.agents) {
const names = opts.agents.split(',').map((n: string) => n.trim()) as AgentName[];
selectedAgents = allAgents().filter((a) => names.includes(a.name));
} else if (opts.globalOnly) {
selectedAgents = detectionResults.filter((r) => r.detected && r.agent.installType === 'global').map((r) => r.agent);
} else if (opts.projectOnly) {
selectedAgents = detectionResults.filter((r) => r.detected && r.agent.installType === 'project').map((r) => r.agent);
} else if (opts.yes) {
selectedAgents = detectionResults.filter((r) => r.detected).map((r) => r.agent);
} else {
const choices = detectionResults.map((r) => ({
name: `${r.agent.displayName} — ${r.agent.installType} install`,
value: r.agent.name,
checked: r.detected,
}));
const { agents } = await inquirer.prompt([{
type: 'checkbox',
name: 'agents',
message: 'Which agents should receive Syncable skills?',
choices,
}]);
selectedAgents = allAgents().filter((a) => agents.includes(a.name));
}
if (selectedAgents.length === 0) {
if (opts.globalOnly) {
console.log(chalk.yellow('\n No global agents detected (Claude Code, Codex). Nothing to install.'));
} else if (opts.projectOnly) {
console.log(chalk.yellow('\n No project agents detected (Cursor, Windsurf, Gemini). Nothing to install.'));
} else {
console.log(chalk.yellow('\n No agents selected. Nothing to install.'));
}
return;
}
// Load and install skills
const skills = loadSkills(getBundledSkillsDir());
const commandCount = skills.filter((s) => s.category === 'command').length;
const workflowCount = skills.filter((s) => s.category === 'workflow').length;
for (const agent of selectedAgents) {
const spinner = ora(` Installing skills for ${agent.displayName}...`).start();
if (opts.dryRun) {
spinner.info(` Would install ${skills.length} skills for ${agent.displayName}`);
continue;
}
try {
const dest = agent.getSkillPath();
switch (agent.name) {
case 'claude':
writeSkillsForClaude(skills, dest);
break;
case 'codex':
writeSkillsForCodex(skills, dest);
break;
case 'cursor':
writeSkillsForCursor(skills, dest);
break;
case 'windsurf':
writeSkillsForWindsurf(skills, dest);
break;
case 'gemini':
writeSkillsForGemini(skills, dest);
break;
}
spinner.succeed(` ${skills.length} skills installed for ${agent.displayName}`);
if (verbose) console.log(chalk.dim(` dest: ${dest}`));
} catch (err) {
spinner.fail(` Failed to install skills for ${agent.displayName}: ${err}`);
}
}
// Summary
console.log('\n ' + '─'.repeat(29));
console.log(chalk.green.bold(' ✓ Setup complete!\n'));
console.log(` Installed:`);
console.log(` • ${commandCount} command skills + ${workflowCount} workflow skills`);
console.log(` • Agents: ${selectedAgents.map((a) => a.displayName).join(', ')}`);
console.log(`\n Try it: Open Claude Code and say "assess this project"\n`);
});
program
.command('uninstall')
.description('Remove skills from agents')
.option('--agents <list>', 'Comma-separated agent list')
.option('-y, --yes', 'Skip confirmations')
.action(async (opts) => {
const agents = opts.agents
? allAgents().filter((a) => opts.agents.split(',').includes(a.name))
: allAgents();
if (!opts.yes) {
const { confirm } = await inquirer.prompt([{
type: 'confirm',
name: 'confirm',
message: `Remove Syncable skills from ${agents.map((a) => a.displayName).join(', ')}?`,
default: false,
}]);
if (!confirm) return;
}
for (const agent of agents) {
const spinner = ora(` Removing skills from ${agent.displayName}...`).start();
try {
const dest = agent.getSkillPath();
switch (agent.name) {
case 'claude':
uninstallClaudePlugin();
break;
case 'codex':
removeSyncableSkills(dest, 'syncable-*');
// Also clean old location (~/.codex/skills/)
removeSyncableSkills(path.join(os.homedir(), '.codex', 'skills'), 'syncable-*');
break;
case 'cursor':
removeSyncableSkills(dest, 'syncable-*.mdc');
break;
case 'windsurf':
removeSyncableSkills(dest, 'syncable-*.md');
break;
case 'gemini':
removeSyncableSkills(dest, 'syncable-*');
break;
}
spinner.succeed(` Skills removed from ${agent.displayName}`);
} catch (err) {
spinner.fail(` Failed to remove skills from ${agent.displayName}: ${err}`);
}
}
});
program
.command('update')
.description('Update skills to latest version')
.option('--agents <list>', 'Comma-separated agent list')
.option('--dry-run', 'Show what would be done without doing it')
.option('--global-only', 'Only update global skills')
.option('--project-only', 'Only update project-level rules')
.option('-y, --yes', 'Skip confirmations')
.option('--verbose', 'Show detailed output')
.action(async (opts) => {
const yesFlag = opts.yes ? ['--yes'] : [];
const agentsFlag = opts.agents ? ['--agents', opts.agents] : [];
const dryRunFlag = opts.dryRun ? ['--dry-run'] : [];
const globalOnlyFlag = opts.globalOnly ? ['--global-only'] : [];
const projectOnlyFlag = opts.projectOnly ? ['--project-only'] : [];
const verboseFlag = opts.verbose ? ['--verbose'] : [];
await program.commands.find((c) => c.name() === 'uninstall')!.parseAsync(['node', 'x', ...agentsFlag, ...yesFlag]);
await program.commands.find((c) => c.name() === 'install')!.parseAsync(['node', 'x', '--skip-cli', ...agentsFlag, ...yesFlag, ...dryRunFlag, ...globalOnlyFlag, ...projectOnlyFlag, ...verboseFlag]);
});
program
.command('status')
.description('Show what is installed and where')
.action(async () => {
console.log(chalk.bold('\n Syncable CLI Skills Status\n'));
const detectionResults = await detectAgents();
const syncCtlStatus = await checkSyncCtl();
const cargoStatus = await checkCargo();
console.log(' Agent Status Location');
console.log(' ' + '─'.repeat(60));
for (const { agent } of detectionResults) {
const dest = agent.getSkillPath();
const count = countInstalledSkills(dest, agent.name);
if (count > 0) {
console.log(` ${agent.displayName.padEnd(14)} ${chalk.green('✓ installed')} ${dest} (${count} skills)`);
} else {
console.log(` ${agent.displayName.padEnd(14)} ${chalk.dim('✗ not installed')}`);
}
}
console.log();
if (syncCtlStatus.status === 'ok') {
console.log(` sync-ctl ${chalk.green('✓')} v${syncCtlStatus.version}`);
} else {
console.log(` sync-ctl ${chalk.red('✗ not found')}`);
}
if (cargoStatus.status === 'ok') {
console.log(` cargo ${chalk.green('✓')} v${cargoStatus.version}`);
} else {
console.log(` cargo ${chalk.red('✗ not found')}`);
}
console.log();
});
program.parse();