Class PathHelper
- Namespace
- Oscova.Agents.Utils
- Assembly
- Oscova.Agents.dll
Path security utilities for containment checks and safe logging.
public static class PathHelperInheritance
Inherited Members
Fields
- SelfAgentPath
-
Agent-facing path of the acting agent's own folder.
- SharedAgentPath
-
Agent-facing path of the host-wide folder shared by permitted users.
Methods
- ArePathsEqual(string, string)
-
Returns true when two paths resolve to the same filesystem location. Uses the platform's default path comparison rules.
- GetAgentPathRoots(string, IReadOnlyList<AllowedDirectory>)
-
Matches the most specific granted alias roots without interpreting another device's native paths.
- GetPathComparisonKey(string)
-
Returns a normalized path key using the executing platform's default path comparison rules.
- GetRelativePathUnderRoot(string, string, StringComparison)
-
Returns a path relative to a named root, or null when it lies outside that root.
- GetShellRootVariables(IReadOnlyList<AllowedDirectory>)
-
Names each granted root consistently for prompt references and child-process environment variables.
- HasSymlinkInPath(string, string)
-
Returns true if any path segment beneath
normalizedDirectoryPathis a symlink or reparse point. Inaccessible segments are treated conservatively as unsafe. - IsDirectChildOfAnyDirectory(string, IEnumerable<string>)
-
Returns true when
relativePathis a direct file child of any supplied top-level directory name. - IsPathWithinAnyDirectory(string, IReadOnlyList<string>)
-
Returns true if
fullPathis located inside any of the supplied directory roots. - IsPathWithinDirectory(string, string)
-
Returns true if
fullPathis located insidenormalizedDirectoryPath. Uses System.IO.Path.GetRelativePath(System.String,System.String) which is natively case-sensitive on Linux/macOS and case-insensitive on Windows. - MapRetiredSelfAgentPath(string)
-
Maps a normalized path under the retired own-folder root
privateto Oscova.Agents.Utils.PathHelper.SelfAgentPath. Stored chat transcripts keep the old root, so they are mapped when opened instead of rewritten. - ResolveAuthorizedHostPath(string, IReadOnlyList<AllowedDirectory>, WorkspacePathAccess)
-
Resolves and authorizes an agent path against current directory grants, including symlink and access checks.
- ResolveToAgentPath(string, IReadOnlyList<AllowedDirectory>)
-
Converts a resolved host path to the active run's agent-facing path or throws a tool-friendly error.
- ResolveToHostPath(string, Func<IReadOnlyList<AllowedDirectory>>)
-
Resolves an agent-supplied path through a live allowed-directory resolver or throws a tool-friendly error.
- ResolveWorkingDirectoryAgentPath(IReadOnlyList<AllowedDirectory>)
-
Returns the canonical working-directory path, falling back to its native path for grants without an alias.
- ResolveWorkingDirectoryHostPath(IReadOnlyList<AllowedDirectory>)
-
Returns the host directory that acts as the working directory for relative agent paths.
- SanitizeForLog(string)
-
Replaces control characters in a file path with
'?'to prevent log injection via crafted filenames containing newlines or other control characters. - SanitizeMountName(string)
-
Converts arbitrary workspace labels into stable container mount names.
- ToExtraMountAgentPath(string)
-
Builds the agent-facing mount path for an extra (non-workspace, non-private) allowed directory, e.g.
/mnt/chat-attachments-for-this-thread. Single owner of the/mnt/<label>rule. - ToPlatformRelativePath(string)
-
Converts a slash-separated relative path into the current platform's directory-separator form.
- ToSlashSeparatedRelativePath(string)
-
Converts a relative path to the forward-slash form used by skill files, zip entries, and model-facing paths.
- ToWorkspaceAgentPath(string)
-
Builds the agent-facing mount path for a named workspace, e.g.
/workspace/default. Single owner of the/workspace/<name>rule. - TryGetContainingDirectory(string, IReadOnlyList<AllowedDirectory>, out AllowedDirectory?)
-
Finds the most specific allowed directory that contains
fullPath. - TryResolveToAgentPath(string, IReadOnlyList<AllowedDirectory>, out string)
-
Converts a resolved host path back to the most specific agent-facing allowed-directory path.
- TryResolveToHostPath(string, IReadOnlyList<AllowedDirectory>, string?, out string)
-
THE PATH CONTRACT. This method translates agent-facing paths and checks logical workspace authorization. Physical workspace IO must use Oscova.Agents.Workspace.IWorkspaceFileAccess so authorization and filesystem access stay bound to held handles. The agent is only ever shown paths that resolve through this contract:
- sandbox mode:
/workspace/<name>,/self,/mnt/<label>; - host / disabled mode: the real host paths plus stable file-tool aliases.
In sandbox mode those agent-facing roots are bind-mounted into the container at exactly these paths, so a file tool (host IO) and the sandboxed shell see the same bytes. Relative paths resolve against the working directory in every mode. The argument is never mutated, so tool output keeps showing the agent the path it passed.
The invariant that keeps both surfaces consistent: never present the agent a path that does not resolve here / is not mounted into the sandbox. Tools may use this method for translation or validation, but must use Oscova.Agents.Workspace.IWorkspaceFileAccess for physical file access.
- sandbox mode: