Class RemoteFilesystemSpec

java.lang.Object
io.agentscope.harness.agent.filesystem.spec.RemoteFilesystemSpec

public class RemoteFilesystemSpec extends Object
Specification for the non-sandbox "composite" filesystem mode.

This spec produces a CompositeFilesystem that blends:

  • a plain LocalFilesystem (no shell) for workspace-local, unmanaged files;
  • per-route RemoteFilesystem instances for cross-node paths (memory, skills, subagents, knowledge, sessions, tasks). Each route gets its own store namespace segment to prevent key collisions across routes.

Because the default backend is LocalFilesystem (not LocalFilesystemWithShell), shell execution is intentionally not available in this mode — use a sandbox filesystem spec or LocalFilesystemWithShell if shell is required.

Default shared routes (each gets an isolated store namespace segment):

  • AGENTS.md, MEMORY.md → segment root
  • memory/ → segment memory
  • skills/ → segment skills
  • subagents/ → segment subagents
  • knowledge/ → segment knowledge
  • plans/ → segment plans
  • agents/<agentId>/sessions/ → segment sessions
  • agents/<agentId>/tasks/ → segment tasks

The store namespace for shared files is controlled by isolationScope(IsolationScope), which mirrors the sandbox isolation semantics:

  • Constructor Details

    • RemoteFilesystemSpec

      public RemoteFilesystemSpec()
      Creates a remote filesystem spec that defers store resolution to DistributedStore.baseStore().

      When used with HarnessAgent.builder().distributedStore(store), the store is injected automatically during build. Without a distributed store, an IllegalStateException is thrown at build time.

    • RemoteFilesystemSpec

      public RemoteFilesystemSpec(BaseStore store)
  • Method Details

    • hasStore

      public boolean hasStore()
      Returns whether the store has been set (either via constructor or injection).
    • store

      public BaseStore store()
      Returns the configured BaseStore, or null if not yet set.

      Used by coordination wiring (e.g. PeriodicGate) when a remote filesystem is present without a full DistributedStore.

    • injectStoreIfAbsent

      public void injectStoreIfAbsent(BaseStore store)
      Injects the store if not already set. Called by the builder during auto-wiring.
    • addSharedPrefix

      public RemoteFilesystemSpec addSharedPrefix(String prefix)
      Adds an extra workspace-relative prefix routed to the shared store.

      Examples: knowledge/, prompts/.

    • anonymousUserId

      public RemoteFilesystemSpec anonymousUserId(String userId)
      Sets the fallback user identifier when runtime userId is absent/blank.
    • isolationScope

      public RemoteFilesystemSpec isolationScope(IsolationScope scope)
      Sets the isolation scope that controls the store namespace for shared files.

      Mirrors the sandbox SandboxContext isolation semantics. Defaults to IsolationScope.USER.

      Parameters:
      scope - isolation scope
      Returns:
      this spec
    • getIsolationScope

      public IsolationScope getIsolationScope()
    • workspaceIndex

      public RemoteFilesystemSpec workspaceIndex(WorkspaceIndex index)
      Sets the workspace index for accelerating remote filesystem reads (ls/glob/exists/grep). If not set, the remote filesystem falls back to full store scans.
    • sharedLocalWorkspace

      public RemoteFilesystemSpec sharedLocalWorkspace(boolean shared)
      When true, the default backend (everything not routed to a shared prefix) serves the workspace root directly: no per-user namespace prefix and sandboxed path resolution. Files the host application writes to the workspace root with plain java.nio (e.g. uploads/<sessionId>/result.md) become visible to read_file / list_files / grep_files, and absolute paths outside the workspace are rejected instead of traversing up to the filesystem root — with the default namespaced backend such reads resolve to {workspace}/{userId}/..., which the host never writes, and UNRESTRICTED resolution lets list_files walk up to the drive root.

      Shared prefix routes (memory/, skills/, ...) keep their per-user store namespaces; only the default backend changes.

      Not safe for multi-tenant workspaces: shared mode disables per-user namespace isolation at the workspace root — users/sessions configured on the same workspace directory will read and overwrite each other's files there. Intended for single-tenant host-app integrations where the host writes uploads directly to the workspace.

      Defaults to false, preserving the namespaced default backend (#3245).

      Parameters:
      shared - whether the default backend serves the shared workspace root
      Returns:
      this spec
    • toFilesystem

      public AbstractFilesystem toFilesystem(Path workspace, String agentId, NamespaceFactory localNamespaceFactory)
      Builds the composite filesystem described by this spec.
      • default backend: LocalFilesystem (no shell), per-user namespaced
      • shared prefix routes (memory/, skills/, subagents/, knowledge/, plans/, agents/<id>/sessions/, agents/<id>/tasks/, plus any addSharedPrefix extras): wrapped in an OverlayFilesystem where the upper layer is the RemoteFilesystem (per-user, persisted in the BaseStore) and the lower layer is a read-only LocalFilesystem rooted at workspace.resolve(<routeDir>). So scaffolded template content under <workspace>/skills/, <workspace>/subagents/, etc. is visible as a baseline; per-user edits land in the remote store via copy-on-write and override the template on subsequent reads.
      • AGENTS.md, MEMORY.md, tools.json exact-file routes: wrapped in an OverlayFilesystem where the upper is the root-segment RemoteFilesystem and the lower is a read-only LocalFilesystem rooted at the workspace, so the scaffolded template files at the workspace root are visible as the baseline. CompositeFilesystem does not recurse into exact-file routes when listing/globbing the tree; it performs a single exists check against the overlay, which is satisfied by either layer.