open source is social v-it.org
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2026 sol pbc
3
4import { spawnSync } from 'node:child_process';
5import { loadConfig, saveConfig } from '../lib/config.js';
6import { requireNotAgent } from '../lib/agent.js';
7import { which } from '../lib/compat.js';
8import { mark, brand, name } from '../lib/brand.js';
9
10export default function register(program) {
11 program
12 .command('setup')
13 .description('Initialize user-level vit setup')
14 .action(async () => {
15 try {
16 const gate = requireNotAgent();
17 if (!gate.ok) {
18 console.error(`${name} setup must be run by a human. run it in your own terminal.`);
19 process.exitCode = 1;
20 return;
21 }
22
23 const gitPath = which('git');
24 console.log(`${mark} git: ${gitPath ? 'found' : 'not found'}`);
25 if (!gitPath) {
26 console.error('missing required tool: git');
27 process.exitCode = 1;
28 return;
29 }
30
31 // skill installation
32 const npxPath = which('npx');
33 if (npxPath) {
34 try {
35 const result = spawnSync(
36 'npx', ['skills', 'add', 'https://github.com/solpbc/vit/tree/main/skills/vit', '-a', 'claude-code', '-y'],
37 {
38 encoding: 'utf-8',
39 stdio: ['pipe', 'pipe', 'pipe'],
40 }
41 );
42 if (result.status === 0) {
43 console.log(`${mark} skill: installed (using-vit)`);
44 } else {
45 const errText = (result.stderr || '').trim();
46 console.log(`${mark} skill: failed (${errText || 'unknown error'})`);
47 }
48 } catch {
49 console.log(`${mark} skill: failed (could not run npx skills)`);
50 }
51 } else {
52 console.log(`${mark} skill: skipped (npx not found)`);
53 }
54
55 const config = loadConfig();
56 if (config.did) {
57 console.log(`${mark} login: ${config.did}`);
58 } else {
59 console.log(`${mark} login: not logged in`);
60 console.log(`next: run '${name} login <handle>' to authenticate with Bluesky`);
61 }
62
63 if (!config.setup_at) {
64 config.setup_at = Math.floor(Date.now() / 1000);
65 saveConfig(config);
66 }
67
68 if (config.did) {
69 console.log(`${brand} setup complete`);
70 }
71 } catch (err) {
72 console.error(err instanceof Error ? err.message : String(err));
73 process.exitCode = 1;
74 }
75 });
76}