Class MarketplaceStager

java.lang.Object
io.agentscope.harness.agent.skill.runtime.MarketplaceStager

public final class MarketplaceStager extends Object
Materialises non-workspace skill resources (Layer 1 / Layer 2 / marketplace) to <wsRoot>/.skills-cache/<source-ns>/<skill-name>/ so that:
  • shell-mode HarnessAgents (sandbox or Local-with-shell) can execute the staged scripts via absolute paths
  • sandbox projection (which includes .skills-cache in DEFAULT_WORKSPACE_PROJECTION_ROOTS) hydrates the staged content into the sandbox at start time

The stager keeps no cross-call state: each invocation rebuilds the white-list of directories that should remain under .skills-cache, materialises any files whose SHA-256 has changed, and deletes orphan directories not present in the white-list.

The cache is shared. One stager instance serves every concurrent call against a workspace root, and on a shared volume other replicas write into the same tree. A white-list built from one call's visible skills therefore says nothing about what other in-flight calls still need: with per-user skill visibility, call B's "orphan" is call A's live filesRoot. Orphan GC is consequently gated on DEFAULT_ORPHAN_GRACE — a directory is deleted only after sitting untouched for that long, and every retained directory is touched on each pass — and every traversal tolerates entries deleted underneath it.

Workspace-native skills (those produced by WorkspaceSkillRepository) are NOT staged: they already live under <wsRoot>/skills/ (or are produced lazily from the sandbox-backed filesystem) and projection covers them through the regular skills root.

  • Field Details

    • CACHE_DIR

      public static final String CACHE_DIR
      See Also:
    • GLOBAL_NAMESPACE

      public static final String GLOBAL_NAMESPACE
      See Also:
    • DEFAULT_ORPHAN_GRACE

      public static final Duration DEFAULT_ORPHAN_GRACE
      How long an orphan must sit untouched before it may be deleted. The window has to outlast the longest call that could still shell out to a staged script, because a staged path is handed to the model in the system prompt and used much later in the call. Leaving a stale directory costs a few KB; deleting a live one breaks another user's call, so the default errs long.
    • SHARED_SCOPE

      public static final String SHARED_SCOPE
      Segment used when the caller has no isolation identity to key on.
      See Also:
  • Constructor Details

    • MarketplaceStager

      public MarketplaceStager(Path workspaceRoot)
    • MarketplaceStager

      public MarketplaceStager(Path workspaceRoot, Duration orphanGrace)
      Overload for callers (and tests) that need a non-default orphan grace window.
  • Method Details

    • stage

      public Map<String,MarketplaceStager.StageResult> stage(List<MarketplaceStager.RepoBound> visible, Map<io.agentscope.core.skill.repository.AgentSkillRepository,String> sourceNs)
      Stage all eligible inputs and return a map from skill.name to its resolved MarketplaceStager.StageResult. Inputs whose source repository is a WorkspaceSkillRepository are returned as MarketplaceStager.StageResult.WorkspaceNative — they need no staging because the workspace tree already contains them.

      The white-list of staged directories is rebuilt every call; any pre-existing directory under .skills-cache/<source-ns>/ not in the white-list is removed (cheap orphan GC: marketplace repos that no longer publish a given skill leave no residue).

      Parameters:
      visible - skill+repository pairs in compose order (winner per name already deduped upstream)
      sourceNs - map from repository identity to its resolved source namespace (handles repos with colliding getSource() via _idx suffix)
      Returns:
      ordered map (insertion-order preserved) keyed by skill.name
    • stage

      public Map<String,MarketplaceStager.StageResult> stage(List<MarketplaceStager.RepoBound> visible, Map<io.agentscope.core.skill.repository.AgentSkillRepository,String> sourceNs, String scope)
      Stages into this call's isolation scope. Every directory GC may remove lives under .skills-cache/<scope>/, and only calls that share a scope share that subtree — so a white-list built from one call's visible skills is authoritative for everything it can reach, which is the property the flat layout never had.
      Parameters:
      scope - per-call isolation key (typically userId or sessionId); blank collapses to "_shared"
    • invalidateAll

      public void invalidateAll()
      Convenience for callers that don't care about return values.
    • resolveSourceNamespaces

      public static Map<io.agentscope.core.skill.repository.AgentSkillRepository,String> resolveSourceNamespaces(List<io.agentscope.core.skill.repository.AgentSkillRepository> repos)
      Resolves per-repository source namespaces. When two repositories report the same getSource(), the second and subsequent ones receive an _<idx> suffix (with a warning log). Layer-1 host repositories whose source string is empty get GLOBAL_NAMESPACE.