pynydus.engine.merger

Egg merge operations: apply ADD/SET/REMOVE directives to a base egg.

Implements local-only egg inheritance: load a base .egg archive, then apply merge operations to produce a modified EggPartial.

Module Contents

Functions

load_base_egg

Load a base .egg archive from a local file path.

merge

Apply merge operations to a base egg and return the resulting EggPartial.

_apply_add

Add a new record to the specified bucket.

_apply_set

Replace all records matching the selector.

_apply_remove

Remove records matching the key/selector.

_skill_matches_remove_key

Return True if skill should be dropped by a REMOVE skill key.

_resolve_value

If value looks like a file path, read its contents. Otherwise return as-is.

_parse_selector

Parse key=value selector string.

_matches_selector

Check if a record matches a selector (attribute == value).

_extract_label_from_key

Extract label from a key like ‘label=fact’.

_infer_skill_name

Infer a skill name from a file path or text.

Data

API

pynydus.engine.merger.logger

‘getLogger(…)’

pynydus.engine.merger.load_base_egg(egg_path: str) pynydus.api.schemas.Egg

Load a base .egg archive from a local file path.

Args: egg_path: Path to the .egg file on disk.

Returns: Loaded Egg with structured modules.

Raises: HatchError: If the file does not exist or cannot be unpacked.

pynydus.engine.merger.merge(base_egg: pynydus.api.schemas.Egg, ops: list[pynydus.engine.nydusfile.MergeOp], *, base_dir: pathlib.Path | None = None) pynydus.api.schemas.EggPartial

Apply merge operations to a base egg and return the resulting EggPartial.

Args: base_egg: Loaded base Egg. ops: Parsed ADD / SET / REMOVE operations. base_dir: Nydusfile directory. relative paths in values resolve here.

Returns: Partial egg with merged modules.

pynydus.engine.merger._apply_add(partial: pynydus.api.schemas.EggPartial, op: pynydus.engine.nydusfile.MergeOp, base_dir: pathlib.Path | None) None

Add a new record to the specified bucket.

pynydus.engine.merger._apply_set(partial: pynydus.api.schemas.EggPartial, op: pynydus.engine.nydusfile.MergeOp, base_dir: pathlib.Path | None) None

Replace all records matching the selector.

pynydus.engine.merger._apply_remove(partial: pynydus.api.schemas.EggPartial, op: pynydus.engine.nydusfile.MergeOp) None

Remove records matching the key/selector.

Identifier comparisons are case-insensitive but otherwise exact. For skills, the key may match either the skill name or the file stem of metadata['source_file']. Logs a warning when no records matched.

pynydus.engine.merger._skill_matches_remove_key(skill: pynydus.api.schemas.AgentSkill, key_lower: str) bool

Return True if skill should be dropped by a REMOVE skill key.

Matches case-insensitively on either the skill name or the file stem of metadata['source_file'] (e.g. db-creation matches a skill extracted from skills/db-creation.md).

pynydus.engine.merger._resolve_value(value: str, base_dir: pathlib.Path | None = None) str

If value looks like a file path, read its contents. Otherwise return as-is.

Relative paths are resolved against base_dir (the Nydusfile’s directory). Raises NydusfileError if the value looks like a path but the file does not exist.

pynydus.engine.merger._parse_selector(selector: str) tuple[str, str]

Parse key=value selector string.

pynydus.engine.merger._matches_selector(record: object, key: str, value: str) bool

Check if a record matches a selector (attribute == value).

pynydus.engine.merger._extract_label_from_key(key: str) str | None

Extract label from a key like ‘label=fact’.

pynydus.engine.merger._infer_skill_name(value: str) str

Infer a skill name from a file path or text.