Add CLI package, config file support, and workspace setup

Add cli/ package with initial scaffolding. Add config-schema to shared
package for typed configuration. Add server config-file loader for
paperclip.config.ts support. Register cli in pnpm workspace. Add
.paperclip/ and .pnpm-store/ to gitignore. Minor Companies page fix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Forgotten
2026-02-17 13:39:47 -06:00
parent 0975907121
commit 5306142542
28 changed files with 1091 additions and 7 deletions

120
cli/src/commands/doctor.ts Normal file
View File

@@ -0,0 +1,120 @@
import * as p from "@clack/prompts";
import pc from "picocolors";
import { readConfig } from "../config/store.js";
import {
configCheck,
databaseCheck,
llmCheck,
logCheck,
portCheck,
type CheckResult,
} from "../checks/index.js";
const STATUS_ICON = {
pass: pc.green("✓"),
warn: pc.yellow("!"),
fail: pc.red("✗"),
} as const;
export async function doctor(opts: {
config?: string;
repair?: boolean;
yes?: boolean;
}): Promise<void> {
p.intro(pc.bgCyan(pc.black(" paperclip doctor ")));
const results: CheckResult[] = [];
// 1. Config check (must pass before others)
const cfgResult = configCheck(opts.config);
results.push(cfgResult);
printResult(cfgResult);
if (cfgResult.status === "fail") {
printSummary(results);
return;
}
const config = readConfig(opts.config)!;
// 2. Database check
const dbResult = await databaseCheck(config);
results.push(dbResult);
printResult(dbResult);
await maybeRepair(dbResult, opts);
// 3. LLM check
const llmResult = await llmCheck(config);
results.push(llmResult);
printResult(llmResult);
// 4. Log directory check
const logResult = logCheck(config);
results.push(logResult);
printResult(logResult);
await maybeRepair(logResult, opts);
// 5. Port check
const portResult = await portCheck(config);
results.push(portResult);
printResult(portResult);
// Summary
printSummary(results);
}
function printResult(result: CheckResult): void {
const icon = STATUS_ICON[result.status];
p.log.message(`${icon} ${pc.bold(result.name)}: ${result.message}`);
if (result.status !== "pass" && result.repairHint) {
p.log.message(` ${pc.dim(result.repairHint)}`);
}
}
async function maybeRepair(
result: CheckResult,
opts: { repair?: boolean; yes?: boolean },
): Promise<void> {
if (result.status === "pass" || !result.canRepair || !result.repair) return;
if (!opts.repair) return;
let shouldRepair = opts.yes;
if (!shouldRepair) {
const answer = await p.confirm({
message: `Repair "${result.name}"?`,
initialValue: true,
});
if (p.isCancel(answer)) return;
shouldRepair = answer;
}
if (shouldRepair) {
try {
await result.repair();
p.log.success(`Repaired: ${result.name}`);
} catch (err) {
p.log.error(`Repair failed: ${err instanceof Error ? err.message : String(err)}`);
}
}
}
function printSummary(results: CheckResult[]): void {
const passed = results.filter((r) => r.status === "pass").length;
const warned = results.filter((r) => r.status === "warn").length;
const failed = results.filter((r) => r.status === "fail").length;
const parts: string[] = [];
parts.push(pc.green(`${passed} passed`));
if (warned) parts.push(pc.yellow(`${warned} warnings`));
if (failed) parts.push(pc.red(`${failed} failed`));
p.note(parts.join(", "), "Summary");
if (failed > 0) {
p.outro(pc.red("Some checks failed. Fix the issues above and re-run doctor."));
} else if (warned > 0) {
p.outro(pc.yellow("All critical checks passed with some warnings."));
} else {
p.outro(pc.green("All checks passed!"));
}
}