Routes file tool operations through ProjectView, buffer forks, and changesets.
Tools call this module instead of directly doing filesystem I/O. The routing decision tree for each file operation:
- Is there a ProjectView? YES: route through ProjectView so every tool sees workspace-local state.
- Is there an open buffer for this path AND a fork store is active? YES: route through Buffer.Fork (in-memory, instant, undo integration).
- Is there an active changeset? YES: route through Changeset overlay (filesystem-level isolation).
- Neither: fall through to direct I/O (returns
:passthroughfor writes).
Buffer.Fork handles files the user has open in a buffer. Changeset handles files that aren't open, or external tools that need a coherent filesystem view. A session can use both simultaneously.
This module is stateless. The fork store pid and changeset pid come from the caller (stored in session state, captured in tool closures).
Summary
Types
Changeset reference (nil when changeset is disabled).
Routing context passed by tool callbacks.
Fork store reference (nil when fork routing is disabled).
Functions
Returns true if any routing is active.
Returns environment variables for shell commands.
Returns environment variables for shell commands, or a tagged error if ProjectView is unavailable.
Builds a routing context from the fork store and changeset pids.
Builds a routing context with ProjectView as the first routing layer.
Deletes a file, routing through changeset if active.
Edits a file by find-and-replace, routing through fork or changeset.
Returns the filesystem path corresponding to path in the routed view.
Returns the filesystem path for search tools, or a tagged error if ProjectView is unavailable.
Returns true if a fork store is active and has forks.
Lists a directory through ProjectView when available.
Returns true when the context includes a ProjectView.
Reads a file, routing through fork or changeset if active.
Returns true if the context has any routing configured, even if it is currently dead.
Returns the working directory for shell commands.
Returns the working directory for shell commands, or a tagged error if ProjectView is unavailable.
Returns a short label for routed workspace output.
Writes a file, routing through fork or changeset if active.
Types
@type changeset() :: pid() | nil
Changeset reference (nil when changeset is disabled).
@type context() :: MingaAgent.ToolRouter.Context.t()
Routing context passed by tool callbacks.
@type fork_store() :: pid() | nil
Fork store reference (nil when fork routing is disabled).
Functions
Returns true if any routing is active.
Returns environment variables for shell commands.
Returns environment variables for shell commands, or a tagged error if ProjectView is unavailable.
@spec context(fork_store(), changeset()) :: context()
Builds a routing context from the fork store and changeset pids.
@spec context(MingaAgent.ProjectView.t() | nil, fork_store(), changeset()) :: context()
Builds a routing context with ProjectView as the first routing layer.
Deletes a file, routing through changeset if active.
Buffer forks don't support deletion (you can't delete an open buffer through a fork). Falls through to changeset or passthrough.
@spec edit_file(context(), String.t(), String.t(), String.t()) :: :ok | :passthrough | {:error, term()}
Edits a file by find-and-replace, routing through fork or changeset.
Returns the filesystem path corresponding to path in the routed view.
Returns the filesystem path for search tools, or a tagged error if ProjectView is unavailable.
Returns true if a fork store is active and has forks.
@spec list_directory(context(), String.t()) :: {:ok, [MingaAgent.ProjectView.Backend.directory_entry()]} | :passthrough | {:error, term()}
Lists a directory through ProjectView when available.
Returns true when the context includes a ProjectView.
Reads a file, routing through fork or changeset if active.
Forks take priority: if there's a fork for this path, read from it. Otherwise try the changeset. If neither, fall through to buffer/filesystem.
Returns true if the context has any routing configured, even if it is currently dead.
Returns the working directory for shell commands.
Returns the working directory for shell commands, or a tagged error if ProjectView is unavailable.
Returns a short label for routed workspace output.
Writes a file, routing through fork or changeset if active.
If a buffer is open for this path and a fork store exists, creates
a fork (lazily) and writes to it. Otherwise tries changeset.
Returns :passthrough if neither is active.