fix(bridge): resolve data dir same as Python for sync-result.json

Both readSyncResult() and probeAll() now mirror Python's
_resolve_data_dir() logic: dev detection (cwd/.obsidian-rag
or cwd/KnowledgeVault) then home dir fallback.

Previously readSyncResult always used cwd/.obsidian-rag (wrong for
server deployments) and probeAll resolved sync-result.json relative
to db path (wrong for absolute paths like /home/san/.obsidian-rag/).
This commit is contained in:
2026-04-12 00:10:38 -04:00
parent 34f3ce97f7
commit a12e27b83a
2 changed files with 25 additions and 2 deletions

View File

@@ -98,7 +98,8 @@ export async function probeAll(config: ObsidianRagConfig): Promise<ProbeResult>
if (indexExists) {
try {
const syncPath = resolve(dbPath, "..", "sync-result.json");
const dataDir = resolveDataDir();
const syncPath = resolve(dataDir, "sync-result.json");
if (existsSync(syncPath)) {
const data = JSON.parse(readFileSync(syncPath, "utf-8"));
lastSync = data.timestamp ?? null;
@@ -120,6 +121,17 @@ export async function probeAll(config: ObsidianRagConfig): Promise<ProbeResult>
};
}
function resolveDataDir(): string {
const cwd = process.cwd();
const devDataDir = resolve(cwd, ".obsidian-rag");
const devVaultMarker = resolve(cwd, "KnowledgeVault");
if (existsSync(devDataDir) || existsSync(devVaultMarker)) {
return devDataDir;
}
const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
return resolve(home, ".obsidian-rag");
}
async function probeOllama(baseUrl: string): Promise<boolean> {
try {
const res = await fetch(`${baseUrl}/api/tags`, { signal: AbortSignal.timeout(3000) });

View File

@@ -109,7 +109,7 @@ export function readSyncResult(config: ObsidianRagConfig): {
total_chunks: number;
errors: Array<{ file: string; error: string }>;
} | null {
const dataDir = resolve(process.cwd(), ".obsidian-rag");
const dataDir = _resolveDataDir();
const path = resolve(dataDir, "sync-result.json");
if (!existsSync(path)) return null;
try {
@@ -118,3 +118,14 @@ export function readSyncResult(config: ObsidianRagConfig): {
return null;
}
}
function _resolveDataDir(): string {
const cwd = process.cwd();
const devDataDir = resolve(cwd, ".obsidian-rag");
const devVaultMarker = resolve(cwd, "KnowledgeVault");
if (existsSync(devDataDir) || existsSync(devVaultMarker)) {
return devDataDir;
}
const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
return resolve(home, ".obsidian-rag");
}