Instead of showing alarming warnings on first run when storage, log, and database directories don't exist, the doctor checks now silently create them and report pass. LLM provider is treated as optional rather than a warning when not configured. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import fs from "node:fs";
|
|
import type { PaperclipConfig } from "../config/schema.js";
|
|
import type { CheckResult } from "./index.js";
|
|
import { resolveRuntimeLikePath } from "./path-resolver.js";
|
|
|
|
export async function databaseCheck(config: PaperclipConfig, configPath?: string): Promise<CheckResult> {
|
|
if (config.database.mode === "postgres") {
|
|
if (!config.database.connectionString) {
|
|
return {
|
|
name: "Database",
|
|
status: "fail",
|
|
message: "PostgreSQL mode selected but no connection string configured",
|
|
canRepair: false,
|
|
repairHint: "Run `paperclipai configure --section database`",
|
|
};
|
|
}
|
|
|
|
try {
|
|
const { createDb } = await import("@paperclipai/db");
|
|
const db = createDb(config.database.connectionString);
|
|
await db.execute("SELECT 1");
|
|
return {
|
|
name: "Database",
|
|
status: "pass",
|
|
message: "PostgreSQL connection successful",
|
|
};
|
|
} catch (err) {
|
|
return {
|
|
name: "Database",
|
|
status: "fail",
|
|
message: `Cannot connect to PostgreSQL: ${err instanceof Error ? err.message : String(err)}`,
|
|
canRepair: false,
|
|
repairHint: "Check your connection string and ensure PostgreSQL is running",
|
|
};
|
|
}
|
|
}
|
|
|
|
if (config.database.mode === "embedded-postgres") {
|
|
const dataDir = resolveRuntimeLikePath(config.database.embeddedPostgresDataDir, configPath);
|
|
const reportedPath = dataDir;
|
|
if (!fs.existsSync(dataDir)) {
|
|
fs.mkdirSync(reportedPath, { recursive: true });
|
|
}
|
|
|
|
return {
|
|
name: "Database",
|
|
status: "pass",
|
|
message: `Embedded PostgreSQL configured at ${dataDir} (port ${config.database.embeddedPostgresPort})`,
|
|
};
|
|
}
|
|
|
|
return {
|
|
name: "Database",
|
|
status: "fail",
|
|
message: `Unknown database mode: ${String(config.database.mode)}`,
|
|
canRepair: false,
|
|
repairHint: "Run `paperclipai configure --section database`",
|
|
};
|
|
}
|