Current section
Files
Jump to
Current section
Files
lib/pixir/tools/workspace.ex
defmodule Pixir.Tools.Workspace do
@moduledoc """
Workspace confinement (CONTEXT.md): the v0.1 safety floor. File Tools resolve a
user/model-supplied path against the Workspace root and refuse anything that escapes
it. (Symlink resolution is deliberately out of scope for v0.1.)
"""
alias Pixir.Tool
@doc """
Resolve `path` (relative or absolute) against `workspace`, confined to it. Returns
`{:ok, absolute_path}` or a structured `:outside_workspace` error.
"""
@spec confine(String.t(), String.t()) :: {:ok, String.t()} | {:error, map()}
def confine(workspace, path) when is_binary(workspace) and is_binary(path) do
root = Path.expand(workspace)
abs = Path.expand(path, root)
if abs == root or String.starts_with?(abs, root <> "/") do
{:ok, abs}
else
{:error, Tool.error(:outside_workspace, "path escapes the workspace", %{path: path})}
end
end
end