-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.ts
More file actions
573 lines (510 loc) · 22 KB
/
Copy pathindex.ts
File metadata and controls
573 lines (510 loc) · 22 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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
#!/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 fs from 'fs';
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';
import { isSyncCtlInLoginShell, getShellProfile, cargoBinDir, execCommand, isWindows } from './utils.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);
/**
* Verify sync-ctl is accessible from a fresh login shell and fix PATH if needed.
* This ensures AI agents (which spawn fresh shells) can actually find sync-ctl.
*/
async function verifySyncCtlPath(opts: { yes?: boolean }): Promise<void> {
const inLoginShell = await isSyncCtlInLoginShell();
if (inLoginShell) {
console.log(chalk.green(' ✓ sync-ctl accessible from shell PATH'));
return;
}
const syncCtlBinary = path.join(cargoBinDir(), isWindows() ? 'sync-ctl.exe' : 'sync-ctl');
if (!fs.existsSync(syncCtlBinary)) {
// Binary doesn't exist at all — nothing to fix here
return;
}
console.log(chalk.yellow('\n ⚠ sync-ctl is installed but NOT in your shell PATH.'));
console.log(chalk.yellow(' AI agents will fail with "sync-ctl: command not found".\n'));
if (isWindows()) {
console.log(chalk.cyan(' To fix, add this to your system PATH:'));
console.log(chalk.dim(` ${cargoBinDir()}\n`));
return;
}
const choices = [
{ name: 'Create symlink in /usr/local/bin (recommended, may need sudo)', value: 'symlink' },
{ name: `Add ~/.cargo/bin to shell profile (${getShellProfile()})`, value: 'profile' },
{ name: 'Skip — I will fix it manually', value: 'skip' },
];
const { fix } = opts.yes
? { fix: 'profile' }
: await inquirer.prompt([{
type: 'list',
name: 'fix',
message: 'How would you like to fix this?',
choices,
}]);
if (fix === 'symlink') {
const spinner = ora(' Creating symlink...').start();
try {
await execCommand(`sudo ln -sf "${syncCtlBinary}" /usr/local/bin/sync-ctl`);
spinner.succeed(' Symlink created: /usr/local/bin/sync-ctl');
} catch {
spinner.fail(' Failed to create symlink (sudo may have been denied)');
console.log(chalk.dim(` Try manually: sudo ln -sf "${syncCtlBinary}" /usr/local/bin/sync-ctl`));
}
} else if (fix === 'profile') {
const profilePath = getShellProfile();
const exportLine = 'export PATH="$HOME/.cargo/bin:$PATH"';
// Check if it's already in the profile
try {
const profileContent = fs.existsSync(profilePath) ? fs.readFileSync(profilePath, 'utf-8') : '';
if (profileContent.includes('.cargo/bin')) {
console.log(chalk.yellow(` ~/.cargo/bin is already in ${profilePath} but your current shell hasn't sourced it.`));
console.log(chalk.cyan(` Run: source ${profilePath}\n`));
return;
}
} catch {
// Can't read profile — proceed with append
}
try {
fs.appendFileSync(profilePath, `\n# Added by syncable-cli-skills installer\n${exportLine}\n`);
console.log(chalk.green(` ✓ Added to ${profilePath}`));
console.log(chalk.cyan(` Restart your terminal or run: source ${profilePath}\n`));
} catch {
console.log(chalk.red(` Failed to update ${profilePath}. Add this line manually:`));
console.log(chalk.dim(` ${exportLine}\n`));
}
} else {
console.log(chalk.dim(` To fix later, run: export PATH="$HOME/.cargo/bin:$PATH"\n`));
}
}
/**
* Print agent-specific post-install instructions that users need to know.
*/
function printPostInstallNotes(agents: AgentConfig[]): void {
const notes: string[] = [];
for (const agent of agents) {
switch (agent.name) {
case 'claude':
notes.push(
` ${chalk.cyan('Claude Code')}: Skills are auto-enabled. If they don't appear:`,
` 1. Run ${chalk.bold('/reload-plugins')} inside Claude Code`,
` 2. Or manually: ${chalk.bold('/plugin marketplace add syncable-dev/syncable-cli')}`,
` then: ${chalk.bold('/plugin install syncable-cli-skills@syncable')}`,
);
break;
case 'codex':
notes.push(
` ${chalk.cyan('Codex')}: You must enable skills when starting Codex:`,
` ${chalk.bold('codex --enable skills')}`,
` Or invoke explicitly: ${chalk.bold('$syncable-analyze')}`,
` Skills installed to: ${chalk.dim('~/.codex/skills/')}`,
);
break;
case 'gemini':
notes.push(
` ${chalk.cyan('Gemini CLI')}: Skills are auto-discovered. Verify with:`,
` ${chalk.bold('/skills list')} inside Gemini CLI`,
` Skills installed to: ${chalk.dim('~/.gemini/skills/')}`,
);
break;
case 'cursor':
notes.push(
` ${chalk.cyan('Cursor')}: Rules are loaded automatically in projects.`,
);
break;
case 'windsurf':
notes.push(
` ${chalk.cyan('Windsurf')}: Rules are loaded automatically in projects.`,
);
break;
}
}
if (notes.length > 0) {
console.log(chalk.bold('\n Agent-specific notes:\n'));
for (const note of notes) {
console.log(note);
}
console.log();
}
}
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') {
const latestInfo = syncCtlStatus.latestVersion ? ` → ${syncCtlStatus.latestVersion} available` : '';
console.log(chalk.yellow(` ⚠ sync-ctl v${syncCtlStatus.version} (outdated${latestInfo})`));
} 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') {
if (syncCtlStatus.status === 'outdated') {
// Always auto-upgrade to latest — no prompt needed
const latestLabel = syncCtlStatus.latestVersion ? ` to v${syncCtlStatus.latestVersion}` : '';
const spinner = ora(` Upgrading sync-ctl${latestLabel}...`).start();
const success = await installSyncCtl(true); // force = true for upgrade
if (success) {
spinner.succeed(` sync-ctl upgraded${latestLabel}`);
} else {
spinner.fail(' Failed to upgrade sync-ctl. Try: cargo install syncable-cli --force');
}
} else {
// Missing — ask to install
const { installCli } = opts.yes
? { installCli: true }
: await inquirer.prompt([{ type: 'confirm', name: 'installCli', message: 'Install syncable-cli via cargo?', default: true }]);
if (installCli) {
const spinner = ora(' Running: cargo install syncable-cli').start();
const success = await installSyncCtl(false);
if (success) {
spinner.succeed(' sync-ctl installed');
} else {
spinner.fail(' Failed to install sync-ctl. Try: cargo install syncable-cli');
}
}
}
}
}
// Verify sync-ctl is actually in the shell PATH (not just this process)
await verifySyncCtlPath(opts);
}
// 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':
await 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(', ')}`);
// Print agent-specific post-install notes (Codex --enable skills, etc.)
printPostInstallNotes(selectedAgents);
// Manual install fallback — if installer didn't work for some reason
console.log(chalk.dim(' If skills are not loading, install manually from GitHub:'));
console.log(chalk.dim(' https://github.com/syncable-dev/syncable-cli/tree/main/installer/skills'));
console.log();
console.log(` Try it: Open your agent 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':
await 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-*');
// Also clean old antigravity profile location from previous installer versions
const oldGeminiDir = path.join(os.homedir(), '.gemini', 'antigravity', 'skills');
if (fs.existsSync(oldGeminiDir)) {
removeSyncableSkills(oldGeminiDir, '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]);
// NOTE: Do NOT pass --skip-cli here — update must always check for and install the latest sync-ctl
await program.commands.find((c) => c.name() === 'install')!.parseAsync(['node', 'x', ...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')}`);
}
// Check if sync-ctl is visible in login shell
const inPath = await isSyncCtlInLoginShell();
if (syncCtlStatus.status === 'ok' && !inPath) {
console.log(chalk.yellow(`\n ⚠ sync-ctl is installed but NOT in your shell PATH.`));
console.log(chalk.yellow(` AI agents may not be able to run skills.`));
console.log(chalk.dim(` Fix: run "syncable-cli-skills install" to update your PATH`));
}
console.log();
});
program
.command('doctor')
.description('Diagnose installation health')
.action(async () => {
console.log(chalk.bold('\n Syncable CLI Skills Doctor\n'));
let issues = 0;
// 1. Check sync-ctl binary exists
const syncCtlStatus = await checkSyncCtl();
if (syncCtlStatus.status === 'ok') {
console.log(chalk.green(` ✓ sync-ctl v${syncCtlStatus.version} installed`));
} else {
console.log(chalk.red(' ✗ sync-ctl not installed'));
console.log(chalk.dim(' Fix: cargo install syncable-cli'));
issues++;
}
// 2. Check sync-ctl is in login shell PATH
const inPath = await isSyncCtlInLoginShell();
if (inPath) {
console.log(chalk.green(' ✓ sync-ctl accessible from shell PATH'));
} else if (syncCtlStatus.status === 'ok') {
console.log(chalk.red(' ✗ sync-ctl NOT in shell PATH — agents will fail'));
console.log(chalk.dim(' Fix: run "syncable-cli-skills install" to update PATH'));
issues++;
}
// 3. Check each agent's skill directory
const detectionResults = await detectAgents();
for (const { agent, detected } of detectionResults) {
if (!detected) continue;
const dest = agent.getSkillPath();
const count = countInstalledSkills(dest, agent.name);
if (count > 0) {
console.log(chalk.green(` ✓ ${agent.displayName}: ${count} skills at ${dest}`));
} else {
console.log(chalk.red(` ✗ ${agent.displayName}: no skills found at ${dest}`));
issues++;
}
// Claude-specific: check enabledPlugins
if (agent.name === 'claude') {
const settingsFile = path.join(os.homedir(), '.claude', 'settings.json');
try {
const settings = JSON.parse(fs.readFileSync(settingsFile, 'utf-8'));
const key = 'syncable-cli-skills@syncable';
if (settings.enabledPlugins && settings.enabledPlugins[key] === true) {
console.log(chalk.green(' ✓ Claude Code: plugin enabled in settings.json'));
} else {
console.log(chalk.red(' ✗ Claude Code: plugin NOT enabled in settings.json'));
console.log(chalk.dim(' Fix: run "syncable-cli-skills install --agents claude"'));
issues++;
}
} catch {
console.log(chalk.red(' ✗ Claude Code: could not read settings.json'));
issues++;
}
}
}
console.log('\n ' + '─'.repeat(40));
if (issues === 0) {
console.log(chalk.green.bold(' ✓ Everything looks good!\n'));
} else {
console.log(chalk.yellow.bold(` Found ${issues} issue${issues === 1 ? '' : 's'} — see above for fixes.\n`));
}
});
program.parse();