File size: 1,763 Bytes
3e8ea5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env node

import { fileURLToPath } from 'node:url';

import { isMainModule, parseJsonPayload, printJson, runCommand } from './command-center-utils.mjs';

const HF_DOCTOR_SCRIPT = fileURLToPath(new URL('./doctor-hf-space.mjs', import.meta.url));
const DOCTOR_TIMEOUT_MS = 120_000;

function parseArgs(argv) {
    const unknown = argv.find((arg) => !['--help', '-h', '--skip-remote'].includes(arg));
    if (unknown) throw new Error(`Unknown option: ${unknown}`);
    return {
        help: argv.includes('--help') || argv.includes('-h'),
        skipRemote: argv.includes('--skip-remote')
    };
}

function printHelp() {
    console.log(`Usage:
  npm run doctor
  npm run doctor -- --skip-remote

Options:
  --skip-remote  Skip read-only Hugging Face remote checks.
  --help         Show this help.`);
}

function main() {
    const options = parseArgs(process.argv.slice(2));
    if (options.help) {
        printHelp();
        return;
    }

    const args = [HF_DOCTOR_SCRIPT, ...(options.skipRemote ? ['--skip-remote'] : [])];
    const result = runCommand(process.execPath, args, { timeoutMs: DOCTOR_TIMEOUT_MS });
    const child = result.stdout ? parseJsonPayload(result.stdout, 'doctor:hf-space') : {};
    const ok = result.ok && child.ok !== false;
    printJson({
        ok,
        profile: 'local-and-hf-space',
        checks: child.checks || [],
        nextActions: child.nextActions || [],
        ...(ok ? {} : { error: child.error || result.stderr || result.error || 'doctor failed' })
    });
    if (!ok) process.exit(1);
}

try {
    if (isMainModule(import.meta.url, process.argv[1])) main();
} catch (error) {
    printJson({ ok: false, error: error instanceof Error ? error.message : String(error) });
    process.exit(1);
}