Class WorkspacePathNormalizer

java.lang.Object
io.agentscope.harness.agent.workspace.WorkspacePathNormalizer

public final class WorkspacePathNormalizer extends Object
Normalizes file paths to workspace-relative form by stripping the active mode's workspace prefix.

Only the prefix matching the current filesystem mode is registered, so there is no risk of a sandbox prefix (/workspace/) accidentally matching a real host directory in local mode, or vice versa.

Paths that don't match any registered prefix pass through unchanged, preserving the ability to access non-workspace files in modes that allow it.

  • Method Details

    • of

      public static WorkspacePathNormalizer of(String workspacePrefix)
      Creates a normalizer that strips the given prefix.
      Parameters:
      workspacePrefix - the workspace root path for the active mode (e.g. "/workspace" for sandbox, or the host workspace absolute path for local)
    • of

      public static WorkspacePathNormalizer of(String... workspacePrefixes)
      Creates a normalizer that tries multiple prefixes in order. Use only when the active mode has more than one valid prefix (e.g. local-with-shell where project dir and workspace dir are both valid roots).
    • of

      public static WorkspacePathNormalizer of(String workspacePrefix, NamespaceFactory namespaceFactory)
      Creates a normalizer that also strips the runtime namespace beneath the workspace prefix. This is needed when a prompt advertises a session-scoped absolute path while the filesystem applies the same namespace to relative paths at operation time.
      Parameters:
      workspacePrefix - the unscoped workspace root
      namespaceFactory - factory for the current runtime namespace
    • normalize

      @Deprecated public String normalize(String path)
      Deprecated.
      Normalize a path to workspace-relative form by stripping the active mode's prefix.

      Callers using a normalizer with a namespace factory should use normalize(String, RuntimeContext) so the operation context is available. This overload is retained for compatibility and uses an empty context.

      Parameters:
      path - the raw path (absolute or relative)
      Returns:
      workspace-relative path, or the original path if no registered prefix matched
    • normalize

      public String normalize(String path, io.agentscope.core.agent.RuntimeContext runtimeContext)
      Normalizes a path using the namespace for the supplied runtime context.

      Namespaced workspace prefixes are checked before the unscoped prefix, so an absolute path such as /workspace/session-1/file.txt becomes file.txt rather than session-1/file.txt when the active namespace is session-1.

      Parameters:
      path - the raw path (absolute or relative)
      runtimeContext - current operation context
      Returns:
      workspace-relative path, or the original path if no registered prefix matched