refactor: dedupe memory wiki source path helpers

This commit is contained in:
Peter Steinberger
2026-04-06 20:28:01 +01:00
parent ccfdfec43f
commit f5bb8cbb98
3 changed files with 18 additions and 28 deletions

View File

@@ -10,6 +10,7 @@ import type { OpenClawConfig } from "../api.js";
import type { ResolvedMemoryWikiConfig } from "./config.js";
import { appendMemoryWikiLog } from "./log.js";
import { renderMarkdownFence, renderWikiMarkdown, slugifyWikiSegment } from "./markdown.js";
import { pathExists, resolveArtifactKey } from "./source-path-shared.js";
import {
pruneImportedSourceEntries,
readMemoryWikiSourceSyncState,
@@ -37,15 +38,6 @@ export type BridgeMemoryWikiResult = {
pagePaths: string[];
};
async function pathExists(filePath: string): Promise<boolean> {
try {
await fs.access(filePath);
return true;
} catch {
return false;
}
}
async function listMarkdownFilesRecursive(rootDir: string): Promise<string[]> {
const entries = await fs.readdir(rootDir, { withFileTypes: true }).catch(() => []);
const files: string[] = [];
@@ -62,11 +54,6 @@ async function listMarkdownFilesRecursive(rootDir: string): Promise<string[]> {
return files.toSorted((left, right) => left.localeCompare(right));
}
async function resolveArtifactKey(absolutePath: string): Promise<string> {
const canonicalPath = await fs.realpath(absolutePath).catch(() => path.resolve(absolutePath));
return process.platform === "win32" ? canonicalPath.toLowerCase() : canonicalPath;
}
async function collectWorkspaceArtifacts(
workspaceDir: string,
bridgeConfig: ResolvedMemoryWikiConfig["bridge"],

View File

@@ -0,0 +1,16 @@
import fs from "node:fs/promises";
import path from "node:path";
export async function pathExists(filePath: string): Promise<boolean> {
try {
await fs.access(filePath);
return true;
} catch {
return false;
}
}
export async function resolveArtifactKey(absolutePath: string): Promise<string> {
const canonicalPath = await fs.realpath(absolutePath).catch(() => path.resolve(absolutePath));
return process.platform === "win32" ? canonicalPath.toLowerCase() : canonicalPath;
}

View File

@@ -5,6 +5,7 @@ import type { BridgeMemoryWikiResult } from "./bridge.js";
import type { ResolvedMemoryWikiConfig } from "./config.js";
import { appendMemoryWikiLog } from "./log.js";
import { renderMarkdownFence, renderWikiMarkdown, slugifyWikiSegment } from "./markdown.js";
import { pathExists, resolveArtifactKey } from "./source-path-shared.js";
import {
pruneImportedSourceEntries,
readMemoryWikiSourceSyncState,
@@ -23,20 +24,6 @@ type UnsafeLocalArtifact = {
const DIRECTORY_TEXT_EXTENSIONS = new Set([".json", ".jsonl", ".md", ".txt", ".yaml", ".yml"]);
async function pathExists(filePath: string): Promise<boolean> {
try {
await fs.access(filePath);
return true;
} catch {
return false;
}
}
async function resolveArtifactKey(absolutePath: string): Promise<string> {
const canonicalPath = await fs.realpath(absolutePath).catch(() => path.resolve(absolutePath));
return process.platform === "win32" ? canonicalPath.toLowerCase() : canonicalPath;
}
function detectFenceLanguage(filePath: string): string {
const ext = path.extname(filePath).toLowerCase();
if (ext === ".json" || ext === ".jsonl") {