pub fn ensure_history_link(link_path: &Path, target_dir: &Path) -> Result<()>Expand description
Best-effort: ensure link_path (a projects/ subdirectory inside an
isolated_auth_enabled-isolated provider credential dir) is a
directory junction (Windows) / symlink (Unix) pointing at
target_dir (the always-global DataPaths::identity_history_dir),
so a provider’s session transcripts stay reachable across a
channel/build change even though the credential directory around them
is per-channel isolated. See
docs/specs/SPEC_AGENT_IDENTITY_HISTORY_PERSISTENCE_PROTOCOL_2026_08_16.md
§4.1.
A Windows junction (not a symlink) is used deliberately —
std::os::windows::fs::symlink_dir requires SeCreateSymbolicLinkPrivilege
(admin, or Developer Mode enabled), which this app cannot assume every
user has; junctions need no special privilege. Uses the junction
crate (FSCTL_SET_REPARSE_POINT under the hood) rather than
hand-rolled reparse-point FFI, for the same reason this codebase’s own
bundle.rs comment notes about Windows symlink privilege requirements
— this is credential-adjacent storage, not a place to improvise
low-level filesystem code.
Idempotent: a no-op if link_path is already a link pointing at
target_dir. If a REAL directory already exists at link_path (data
written before this function existed, or before isolated_auth_enabled
applied to this bundle), its entries are moved into target_dir one
by one via rename (atomic, same-volume — always true here, both
live under the single ~/.agentmux tree) before the now-empty
directory is replaced with the link. Never deletes or overwrites
data: an entry whose name already exists at the target is left
exactly where it was, under the old per-channel path, rather than
risking clobbering real history — it becomes reachable again once a
human resolves the name collision, rather than silently lost. Any
I/O error at any step is returned to the caller, who is expected to
treat this as best-effort (log and continue spawning) per the same
philosophy as the jekt-key injection in agent_config.rs.