UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

62 lines (61 loc) • 2.78 kB
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { f as safeStat } from "./path-existence-Co7-GyVr.mjs"; import { d as pathExists, g as readRegularFile, n as appendRegularFile } from "./fs-safe-BbWvmdVn.mjs"; import { r as decodeUtf8Input } from "./utf8-input-BHczGT8v.mjs"; import "./path-existence-runtime-LOpU--Vt.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; import "./security-runtime-C-zE_Zy_.mjs"; import "./runtime-doctor-migrations-YTlcIEpR.mjs"; import { d as markMigrationItemSkipped, t as MIGRATION_REASON_MISSING_SOURCE_OR_TARGET, u as markMigrationItemError } from "./migration-C73lp9ea.mjs"; import path from "node:path"; import fs from "node:fs/promises"; import os from "node:os"; //#region extensions/migrate-claude/helpers.ts function resolveHomePath(e) { const t = e.trim(); if (!t) return t; return path.resolve(t.replace(/^~(?=$|[\\/])/u, () => os.homedir())); } async function isDirectory(e) { return (await safeStat(e))?.isDirectory() === true; } function sanitizeName(e) { return e.trim().toLowerCase().replaceAll(/[^a-z0-9._-]+/g, "-").replaceAll(/^-+|-+$/g, ""); } async function readJsonObject(e) { const t = e ? await fs.realpath(e).then((e) => readRegularFile({ filePath: e })).catch(() => void 0) : void 0; if (!t) return {}; const n = decodeUtf8Input(t.buffer, `Claude configuration file ${e} (re-save or re-encode it as UTF-8, then rerun the migration)`); try { const e = JSON.parse(n); return isRecord(e) ? e : {}; } catch { return {}; } } async function appendItem(e) { if (!e.source || !e.target) return markMigrationItemError(e, MIGRATION_REASON_MISSING_SOURCE_OR_TARGET); try { const { buffer: t } = await readRegularFile({ filePath: await fs.realpath(e.source) }); const n = decodeUtf8Input(t, `Claude instruction file ${e.source} (re-save or re-encode it as UTF-8, then rerun the migration)`); const r = typeof e.details?.sourceLabel === "string" ? e.details.sourceLabel : path.basename(e.source); const i = n.trimEnd(); if (!i) return markMigrationItemSkipped(e, "source file is empty"); const a = `\n\n<!-- Imported from Claude: ${r} -->\n\n${i}\n`; if ((await pathExists(e.target) ? (await readRegularFile({ filePath: e.target })).buffer.toString("utf8") : "").includes(a)) return markMigrationItemSkipped(e, "already imported from Claude"); await fs.mkdir(path.dirname(e.target), { recursive: true }); await appendRegularFile({ filePath: e.target, content: a, rejectSymlinkParents: true }); return { ...e, status: "migrated" }; } catch (t) { return markMigrationItemError(e, t instanceof Error ? t.message : String(t)); } } //#endregion export { sanitizeName as a, resolveHomePath as i, isDirectory as n, readJsonObject as r, appendItem as t };