Skip to content

InMemoryWorkspace

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework.Workspace

InMemoryWorkspace Class

Thread-safe in-memory IWorkspace backed by a System.Collections.Concurrent.ConcurrentDictionary<>. Suitable for testing, sandboxed agent runs, and scenarios where persistence is not needed.

public sealed class InMemoryWorkspace : NexusLabs.Needlr.AgentFramework.Workspace.IWorkspace

Inheritance System.Object 🡒 InMemoryWorkspace

Implements IWorkspace

Remarks

Marked NexusLabs.Needlr.DoNotAutoRegisterAttribute to prevent Needlr from registering it as a singleton — workspaces have per-orchestration lifecycle and must be explicitly constructed.

Paths are normalized: backslashes are replaced with forward slashes, leading slashes are trimmed, and comparison is case-insensitive (matching Windows file system behavior by default).

Methods

InMemoryWorkspace.CompareExchange(string, string, string) Method

Atomically replaces file content only if the current content matches expectedContent. Returns true if the swap succeeded, false if the content had changed.

public bool CompareExchange(string path, string expectedContent, string newContent);

Parameters

path System.String

expectedContent System.String

newContent System.String

Implements CompareExchange(string, string, string)

Returns

System.Boolean

Remarks

Enables optimistic concurrency for multi-agent pipelines where multiple agents may edit the same file. Callers read, transform, then CAS — if another agent wrote in between, the CAS fails and the caller can re-read and retry.

InMemoryWorkspace.FileExists(string) Method

Returns whether a file exists at the given path.

public bool FileExists(string path);

Parameters

path System.String

Implements FileExists(string)

Returns

System.Boolean

InMemoryWorkspace.GetFilePaths() Method

Returns all file paths in the workspace.

public System.Collections.Generic.IEnumerable<string> GetFilePaths();

Implements GetFilePaths()

Returns

System.Collections.Generic.IEnumerable<System.String>

InMemoryWorkspace.ReadFile(string) Method

Reads the entire content of a file.

public string ReadFile(string path);

Parameters

path System.String

Implements ReadFile(string)

Returns

System.String

Exceptions

System.IO.FileNotFoundException
The file does not exist.

InMemoryWorkspace.SeedFile(string, string) Method

Seeds the workspace with a file before agent execution begins. Convenience method for test setup and scenario harnesses.

public void SeedFile(string path, string content);

Parameters

path System.String

content System.String

InMemoryWorkspace.WriteFile(string, string) Method

Writes content to a file, creating or overwriting it.

public void WriteFile(string path, string content);

Parameters

path System.String

content System.String

Implements WriteFile(string, string)