UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

34 lines (33 loc) • 2.65 kB
/** * Pure path arithmetic for a workspace whose ROOT moved: rebase an absolute path from the old root * onto the new one. No I/O, no state, no dependency on anything — which is why it lives here rather * than inside the restore phase that used to own it. The read-face phase needs the same arithmetic, * and a phase reaching sideways into a sibling phase for a helper is the shape the dependency * gate exists to stop; the answer is to put the helper where both can reach DOWN to it. */ /** * rebase one checkpointed absolute path from the OLD workspace root onto the RESTORED * one (divergent `resumeVM`). POSIX-ONLY by contract: every remote lane's `mountPath` is a container * path (e2b/k8s/ssh/adb/local-docker are all Linux targets), so a backslash ANYWHERE in the inputs marks * the value outside this function's domain and it returns `p` UNCHANGED — an un-rebased path is honestly * observable (the divergence observation already fired) while a WRONGLY-rebased one silently corrupts * cwd/read-state (r4: drive-root and cross-family recomposition are not implementable without a Windows * path model no lane needs). Trailing slashes are tolerated (from="/app/" must not weld the suffix); * bare "/" keeps filesystem-root semantics; a path outside `from` (incl. the prefix-sibling * "/application" vs "/app") returns unchanged. Exported for direct unit pinning. */ export declare function rebaseWorkspacePath(p: string, fromRaw: string, toRaw: string): string; /** * {@link rebaseWorkspacePath} over a SET of accepted spellings of the old root: the first * prefix that actually matches wins, and a path under none of them is returned unchanged. * * The set exists because "the old root" has no single spelling. `WorkspaceHandle.mountPath` is whatever the * adapter called the mount, while the persisted paths being migrated were spelled by whoever produced them * (a `cd` the env canonicalized, a Read key resolved through realpath). On a target where the root has an * equivalent alias (`/var` ↔ `/private/var`) those disagree while naming the same directory, and a * single-prefix rebase then matched nothing and silently left the resumed shell in the pre-suspend tree — * under a disclosure that said the task follows the restored root. Order is caller-chosen (the checkpointed * spelling first, its canonical form second) and only matters if one prefix is a prefix of another, in * which case the earlier — more specific — spelling is the intended one. Exported for direct unit pinning. */ export declare function rebaseWorkspacePathAcross(p: string, froms: readonly string[], to: string): string;