openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
16 lines • 4.83 kB
JavaScript
import"./sleep-BeLUM6My.mjs";import{c as isPathInside$1,t as resolveStateDir,u as normalizeWindowsPathPreservingCase}from"./state-dir-C22DK7p0.mjs";import{a as resolveUserPath,c as resolveEffectiveHomeDir,s as normalizeHomeDirValue}from"./home-dir-C2A7IM0a.mjs";import fsSync from"node:fs";import"@openclaw/fs-safe/path";import path from"node:path";import"@openclaw/fs-safe/advanced";import{FsSafeError as FsSafeError$1}from"@openclaw/fs-safe/errors";import fsPromises from"node:fs/promises";import os from"node:os";import"@openclaw/fs-safe/output";import{root}from"@openclaw/fs-safe/root";import{readSecureFile}from"@openclaw/fs-safe/secure-file";import"@openclaw/fs-safe/walk";
//!packages/terminal-core/src/ansi-sequences.ts
const ANSI_OSC_INTRODUCER_PATTERN=`(?:\\x1b\\]|\\x9d)`;const ANSI_STRING_TERMINATOR_PATTERN=`(?:\\x1b\\\\|\\x07|\\x9c)`;const ANSI_OSC_PATTERN=`${ANSI_OSC_INTRODUCER_PATTERN}[^\\x07\\x1b\\x9c]*${ANSI_STRING_TERMINATOR_PATTERN}`;const ANSI_COMPAT_CONTROL_SEQUENCE_PATTERN=`[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]`;const ansiOscAtIndexRegex=new RegExp(ANSI_OSC_PATTERN,`y`);function matchAnsiOscAt(e,t){ansiOscAtIndexRegex.lastIndex=t;return ansiOscAtIndexRegex.exec(e)?.[0]}function scanAnsiCsiAt(e,t){const n=e.charCodeAt(t);if(n!==155&&(n!==27||e.charCodeAt(t+1)!==91))return;let r=t+(n===155?1:2);const i=[];let a=false;while(r<e.length){const t=e.charCodeAt(r);if(t===24||t===26){r+=1;a=true;break}if(t===27||t===155){a=true;break}if(t<=31||t===127){i.push(e.charAt(r));r+=1;continue}if(t>=32&&t<=63){r+=1;continue}if(t>=64&&t<=126)r+=1;a=true;break}return{controls:i,ended:a,value:e.slice(t,r)}}
//!packages/terminal-core/src/ansi.ts
const ANSI_OSC_SEQUENCE_PATTERN=`${ANSI_OSC_INTRODUCER_PATTERN}[\\s\\S]*?${ANSI_STRING_TERMINATOR_PATTERN}`;const ANSI_COMPAT_SEQUENCE_AT_INDEX_REGEX=new RegExp(`${ANSI_OSC_SEQUENCE_PATTERN}|${ANSI_COMPAT_CONTROL_SEQUENCE_PATTERN}`,`y`);const graphemeSegmenter=new Intl.Segmenter(void 0,{granularity:`grapheme`});function hasAnsiIntroducer(e){return e.includes(`\x1B`)||e.includes(``)||e.includes(``)}function stripAnsiInternal(e,t){if(!hasAnsiIntroducer(e))return e;const n=[];let r=0;let i=0;while(i<e.length){const a=e.charCodeAt(i);if(a!==27&&a!==155&&a!==157){i+=1;continue}const o=matchAnsiOscAt(e,i);const s=o?void 0:scanAnsiCsiAt(e,i);ANSI_COMPAT_SEQUENCE_AT_INDEX_REGEX.lastIndex=i;const c=!o&&t.compatibilityGrammar?ANSI_COMPAT_SEQUENCE_AT_INDEX_REGEX.exec(e)?.[0]:void 0;let l=o?.length??s?.value.length??c?.length;if(l===void 0){i+=1;continue}if(s&&!s.ended&&t.preserveIncompleteCsi)break;if(s?.controls.length===0&&c)l=Math.max(l,c.length);n.push(e.slice(r,i),...s?.controls??[]);i+=l;r=i}n.push(e.slice(r));return n.join(``)}function stripAnsi(e){return stripAnsiInternal(e,{compatibilityGrammar:false})}const LOG_CONTROL_CHARS_REGEX=new RegExp(`[${String.fromCharCode(0)}-${String.fromCharCode(31)}${String.fromCharCode(127)}-${String.fromCharCode(159)}]`,`g`);function sanitizeForLog(e){return stripAnsi(e).replace(LOG_CONTROL_CHARS_REGEX,``)}
//!packages/terminal-core/src/safe-text.ts
function sanitizeTerminalText(e){return stripAnsi(e).replace(/[\p{Cc}\p{Bidi_Control}]/gu,e=>e===`\r`?`\\r`:e===`
`?`\\n`:e===` `?`\\t`:``)}
//!src/infra/config-dir.ts
function resolveConfigDir(e=process.env,t=os.homedir){const n=e.OPENCLAW_STATE_DIR?.trim();if(n)return resolveUserPath(n,e,t);const r=e.OPENCLAW_CONFIG_PATH?.trim();if(r)return path.dirname(resolveUserPath(r,e,t));return resolveStateDir(e,t)}
//!src/infra/home-display.ts
function shortenPathWithHome(e,{home:t,prefix:n}){if(e===t)return n;if(e.startsWith(`${t}/`)||process.platform===`win32`&&e.startsWith(`${t}\\`))return`${n}${e.slice(t.length)}`;if(process.platform===`win32`&&path.win32.isAbsolute(e)&&isPathInside$1(t,e)){const r=path.win32.relative(normalizeWindowsPathPreservingCase(t),normalizeWindowsPathPreservingCase(e));return path.win32.join(n,r)}return e}
//!src/infra/fs-safe.ts
async function root$1(e,t){return await root(e,t)}
//!src/utils.ts
function resolveHomeDir(){return resolveEffectiveHomeDir(process.env,os.homedir)}const HOME_TEXT_START=String.raw`(?<=^|[\s"'\x60(\[{<=:;]|file://)`;const HOME_TEXT_DELIMITER=String.raw`[\s"'\x60)\]}>]`;const HOME_TEXT_LIST_NEXT=String.raw`[:;](?=[/\\~$]|[A-Za-z]:)`;function resolveHomeDisplayPrefix(){const e=resolveHomeDir();if(!e)return;if(normalizeHomeDirValue(process.env.OPENCLAW_HOME))return{home:e,prefix:`$OPENCLAW_HOME`};return{home:e,prefix:`~`}}function shortenHomePath(e){const t=resolveHomeDisplayPrefix();if(!t)return e;return shortenPathWithHome(e,t)}let CONFIG_DIR=resolveConfigDir();export{root$1 as a,sanitizeForLog as c,readSecureFile as i,stripAnsi as l,shortenHomePath as n,resolveConfigDir as o,FsSafeError$1 as r,sanitizeTerminalText as s,CONFIG_DIR as t};