open source is social v-it.org
1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (c) 2026 sol pbc
3
4import { loadConfig } from '../lib/config.js';
5import { restoreAgent } from '../lib/oauth.js';
6import { readProjectConfig } from '../lib/vit-dir.js';
7import { existsSync, lstatSync } from 'node:fs';
8import { join } from 'node:path';
9import { mark, name } from '../lib/brand.js';
10import { which } from '../lib/compat.js';
11
12export default function register(program) {
13 async function checkHealth() {
14 try {
15 const config = loadConfig();
16 if (config.setup_at) {
17 const when = new Date(config.setup_at * 1000).toISOString();
18 console.log(`${mark} setup: ok (${when})`);
19 } else {
20 console.log(`${mark} setup: not done (run ${name} setup)`);
21 }
22
23 const vitPath = which(name);
24 if (!vitPath) {
25 console.log(`${mark} install: not on PATH`);
26 } else {
27 try {
28 if (lstatSync(vitPath).isSymbolicLink()) {
29 console.log(`${mark} install: linked (${vitPath})`);
30 } else if (vitPath.includes('node_modules')) {
31 console.log(`${mark} install: global`);
32 } else {
33 console.log(`${mark} install: source (${vitPath})`);
34 }
35 } catch {
36 console.log(`${mark} install: source (${vitPath})`);
37 }
38 }
39
40 const projConfig = readProjectConfig();
41 if (projConfig.beacon) {
42 console.log(`${mark} beacon: ${projConfig.beacon}`);
43 } else {
44 console.log(`${mark} beacon: not set`);
45 }
46
47 const skillPath = join(process.cwd(), '.claude', 'skills', 'using-vit', 'SKILL.md');
48 if (existsSync(skillPath)) {
49 console.log(`${mark} skill: ok (using-vit)`);
50 } else {
51 console.log(`${mark} skill: not installed (run ${name} setup)`);
52 }
53
54 if (!config.did) {
55 console.log(`${mark} bluesky: not logged in (run ${name} login <handle>)`);
56 } else {
57 try {
58 const { session } = await restoreAgent(config.did);
59 const pds = session.serverMetadata?.issuer;
60 console.log(`${mark} bluesky: ok (${session.did}${pds ? ', ' + pds : ''})`);
61 } catch {
62 console.log(`${mark} bluesky: token expired or invalid (run ${name} login <handle>)`);
63 }
64 }
65 } catch (err) {
66 console.error(err instanceof Error ? err.message : String(err));
67 process.exitCode = 1;
68 }
69 }
70
71 program.command('doctor')
72 .description('Verify vit environment and project configuration')
73 .action(checkHealth);
74 program.command('status')
75 .description('Alias for doctor')
76 .action(checkHealth);
77}