Skip to content

base

base

EditApplier ABC, registry, and context types for the execute phase.

Each concrete applier implements validate/apply/rollback for a single EditOp. Appliers are registered in an EditApplierRegistry keyed by EditOp.

See spec §7.1.

Classes

ApplyContext dataclass

ApplyContext(openjarvis_home: Path, session_id: str)

Shared context passed to all appliers.

ValidationResult dataclass

ValidationResult(ok: bool, reason: str = '')

Result of EditApplier.validate().

ApplyResult dataclass

ApplyResult(changed_files: list[str] = list())

Result of EditApplier.apply().

EditApplier

Bases: ABC

Abstract base for edit appliers.

Each subclass handles one EditOp. It validates the edit against the current config state, applies the mutation, and can roll back.

Functions
validate abstractmethod
validate(edit: Edit, ctx: ApplyContext) -> ValidationResult

Check if the edit can be applied to the current config.

Source code in src/openjarvis/learning/distillation/execute/base.py
@abstractmethod
def validate(self, edit: Edit, ctx: ApplyContext) -> ValidationResult:
    """Check if the edit can be applied to the current config."""
    ...
apply abstractmethod
apply(edit: Edit, ctx: ApplyContext) -> ApplyResult

Mutate the config. Must be idempotent.

Source code in src/openjarvis/learning/distillation/execute/base.py
@abstractmethod
def apply(self, edit: Edit, ctx: ApplyContext) -> ApplyResult:
    """Mutate the config. Must be idempotent."""
    ...
rollback abstractmethod
rollback(edit: Edit, ctx: ApplyContext) -> None

Restore pre-edit state. Most appliers delegate to git checkout.

Source code in src/openjarvis/learning/distillation/execute/base.py
@abstractmethod
def rollback(self, edit: Edit, ctx: ApplyContext) -> None:
    """Restore pre-edit state. Most appliers delegate to git checkout."""
    ...

EditApplierRegistry

EditApplierRegistry()

Registry of EditApplier instances keyed by EditOp.

Source code in src/openjarvis/learning/distillation/execute/base.py
def __init__(self) -> None:
    self._appliers: dict[EditOp, EditApplier] = {}
Functions
register
register(applier: EditApplier) -> None

Register an applier instance.

Source code in src/openjarvis/learning/distillation/execute/base.py
def register(self, applier: EditApplier) -> None:
    """Register an applier instance."""
    self._appliers[applier.op] = applier
get
get(op: EditOp) -> EditApplier

Return the applier for the given op. Raises KeyError if not found.

Source code in src/openjarvis/learning/distillation/execute/base.py
def get(self, op: EditOp) -> EditApplier:
    """Return the applier for the given op. Raises KeyError if not found."""
    return self._appliers[op]
is_supported
is_supported(op: EditOp) -> bool

Return True if an applier is registered for the op.

Source code in src/openjarvis/learning/distillation/execute/base.py
def is_supported(self, op: EditOp) -> bool:
    """Return True if an applier is registered for the op."""
    return op in self._appliers