UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.48 kB
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{l as pathExists,m as readRegularFile,n as appendRegularFile}from"./fs-safe-Bxzu1j4h.mjs";import{p as safeStat}from"./path-existence-BR9MXlgL.mjs";import{r as decodeUtf8Input}from"./utf8-input-CiFSnxL0.mjs";import"./path-existence-runtime-BFjuPvea.mjs";import"./string-coerce-runtime-BYDH9Quw.mjs";import"./security-runtime-Y28JTB1K.mjs";import"./runtime-doctor-migrations-DjW1C-6Q.mjs";import{d as markMigrationItemSkipped,t as MIGRATION_REASON_MISSING_SOURCE_OR_TARGET,u as markMigrationItemError}from"./migration-B8ObiJfa.mjs";import path from"node:path";import fs from"node:fs/promises";import os from"node:os"; //!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))}}export{sanitizeName as a,resolveHomePath as i,isDirectory as n,readJsonObject as r,appendItem as t};