stax
Composition layer

Merge Rules

How package layers are merged into consuming agents

When an agent or package depends on other packages, their layers are merged together. stax uses a deterministic merge strategy based on declaration order and precedence.

Precedence Order

Layers are merged with the following precedence (highest wins):

  1. The consuming artifact's own layers (highest)
  2. Direct dependencies in declaration order
  3. Transitive dependencies (lowest)

Merge Table

Each layer type has specific merge rules:

LayerMerge unitConflict keyRule
MCPServer objectServer nameReplace entire server object at the highest-precedence definition
SkillsTop-level skill directorySkill nameHigher precedence replaces the entire skill directory
RulesRule fileRule id if present, else archive pathHigher precedence replaces matching rule; otherwise append in precedence order
KnowledgeArchive pathNormalized pathHigher precedence replaces matching path
SurfacesSurface fileBasenameHigher precedence replaces the entire file
SecretsSecret keykeyHigher precedence replaces entire declaration

Why Replace, Not Deep Merge

stax uses replace, not deep merge, for structured conflicts. This avoids non-deterministic behavior and ambiguous list merging.

For example, if two packages define the github MCP server, the higher-precedence definition replaces the lower one entirely. There is no attempt to merge individual server fields.

Rules Ordering

After rule replacement and deduplication, remaining rules are ordered by:

  1. Precedence level (lowest to highest)
  2. Explicit priority ascending
  3. Normalized archive path ascending

Consumers may apply additional runtime-specific ordering but should preserve the canonical order when possible.

Skills Conflict Behavior

A skill is identified by its top-level directory name. If two packages provide skills/fix-issue/, the higher-precedence package wins and the lower-precedence directory is discarded entirely.

Knowledge Conflict Behavior

Knowledge files are identified by normalized archive path. If two sources provide the same path, the higher-precedence file wins. Consumers should retain path provenance when materializing or indexing merged knowledge.

Secrets Merging

Secrets are merged by key. Higher precedence replaces the full declaration, including required, description, kind, and exposeAs.

On this page