Files
openclaw/src/shared/tilde-path.ts
Peter Steinberger 49cc59b1e8 refactor: consolidate markdown code fences, error coercion, and byte-identical helper pairs (#99932)
* refactor(shared): add markdown code span/fence helpers and migrate seven call sites

* refactor(normalization-core): add canonical toErrorObject and migrate six copies

* refactor: consolidate byte-identical helper pairs onto owner modules

* refactor: reuse canonical path and token helpers in session tools and credentials

* refactor(packages): dedupe compaction summarization tail and session dir parsing

* fix(security): keep missing extensions dir silent in shared plugin dir lister

* refactor: reuse media-core chunk reader and shared dreaming session key helper

* fix(plugins): register error-coercion subpath in sdk alias table

* chore(plugin-sdk): re-pin callable export count after rebase

* chore(plugin-sdk): re-pin callable export count after rebase
2026-07-04 08:40:41 -04:00

24 lines
742 B
TypeScript

// Home-prefix expansion for user-configured loader path lists.
import { homedir } from "node:os";
import { join } from "node:path";
/**
* Expands a leading `~` against the OS home dir, keeping relative inputs
* relative so callers can resolve them against their own base dir. Unlike
* `resolveHomeRelativePath`, `~name` is treated as `<home>/name` (shipped
* loader behavior for prompt/skill path lists).
*/
export function expandTildePath(input: string): string {
const trimmed = input.trim();
if (trimmed === "~") {
return homedir();
}
if (trimmed.startsWith("~/")) {
return join(homedir(), trimmed.slice(2));
}
if (trimmed.startsWith("~")) {
return join(homedir(), trimmed.slice(1));
}
return trimmed;
}