Holds the mapping of file paths to Buffer.Fork pids for an agent session.
Each agent session gets its own store. Forks are created lazily on the first write to a file that has an open buffer. The store monitors each fork and removes it if the fork process dies.
The store is an Agent wrapping a map and a list of monitor refs. Tool callbacks (which run in a spawned Task) query and update it via the public API.
Lifecycle
{:ok, store} = BufferForkStore.start_link()
{:ok, fork_pid} = BufferForkStore.get_or_create(store, "/abs/path/lib/foo.ex", buffer_pid)
forks = BufferForkStore.all(store)
BufferForkStore.stop(store)
Summary
Functions
Returns all forks as a %{path => fork_pid} map.
Returns a specification to start this module under a supervisor.
Discards all forks without merging.
Returns the fork pid for path, or nil if no fork exists.
Returns the fork pid for path, creating one from buffer_pid if needed.
Merges all dirty forks back to their parent buffers. Returns results per path.
Starts a new empty fork store.
Stops the store, cleaning up all forks.
Types
Functions
@spec all(GenServer.server()) :: %{required(String.t()) => pid()}
Returns all forks as a %{path => fork_pid} map.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec discard_all(GenServer.server()) :: :ok
Discards all forks without merging.
@spec get(GenServer.server(), String.t()) :: pid() | nil
Returns the fork pid for path, or nil if no fork exists.
@spec get_or_create(GenServer.server(), String.t(), pid()) :: {:ok, pid()} | {:error, term()}
Returns the fork pid for path, creating one from buffer_pid if needed.
If a fork already exists for this path, returns it. Otherwise creates a new fork from the parent buffer, stores it, and returns the pid.
@spec merge_all(GenServer.server()) :: [ {String.t(), :ok | {:conflict, term()} | {:error, term()}} ]
Merges all dirty forks back to their parent buffers. Returns results per path.
@spec start_link(keyword()) :: GenServer.on_start()
Starts a new empty fork store.
@spec stop(GenServer.server()) :: :ok
Stops the store, cleaning up all forks.