File System utilities make local artifacts predictable: normalize the path, resolve aliases, use configured encodings, then read or write through one small contract.
1. Core Idea
pj(...) is the canonical path join helper. It joins path parts, expands ~ and environment variables, normalizes separators, optionally returns an absolute path, and can resolve caller-provided aliases.
Think of it as a small path vocabulary. . means the current working location, ~ expands to the user home, environment variables expand through the operating system, and aliases such as % or & can point to a runtime folder or resource folder when the caller or config manager provides that alias map.
File and serialization helpers wrap common I/O for the same reason configuration wraps hyperparameters: callers should not pass encoding, indentation, and platform path details through every function. Defaults such as heavenbase.serialize.encoding and heavenbase.serialize.indent live in CM_HVNB.
Utility
pj(...) handles normal paths and caller aliases. CM_HVNB.pj(...) handles HeavenBase package aliases: %/ for package-local runtime data and &/ for package resources.2. Build a Path
Usepj(...) for ordinary local paths:
3. Prepare Files and Folders
Usetouch_dir(...) and touch_file(...) before writing artifacts. Both create missing parents and return an absolute path.
clear=True only when the folder or file should start empty:
4. Read and Write Data
Use JSON and YAML for machine-readable artifacts, text for human-readable output, and JSONL when a workflow appends one event at a time.heavenbase.serialize.encoding, which is utf-8 in the default config. JSON and YAML indentation default to heavenbase.serialize.indent, which is 4.
5. List, Copy, and Delete Artifacts
list_files(...) reads direct children. enum_files(...) walks recursively. Both return stable, case-insensitive order.
replace, skip, and strict; directories also support merge.
6. Show a Folder Diagram
Usefolder_diagram(...) for compact diagnostics in logs, reports, and docs snippets.

