Skip to content

paths

paths

Filesystem path resolution for the distillation subsystem.

The keystone of artifact isolation (spec §11): the resolved distillation root must NEVER be inside the OpenJarvis source tree. resolve_distillation_root walks up from this module's __file__ looking for a pyproject.toml that identifies the OpenJarvis source root, then refuses to operate if the resolved root is inside it. Defense in depth — if a user accidentally points OPENJARVIS_HOME at the repo, the system fails loudly instead of silently writing artifacts into the working tree.

Classes

ConfigurationError

Bases: RuntimeError

Raised when path configuration would violate isolation guarantees.

Functions

resolve_distillation_root

resolve_distillation_root() -> Path

Return the absolute path of the distillation root directory.

The root is $OPENJARVIS_HOME/learning (or ~/.openjarvis/learning by default). Raises ConfigurationError if the resolved path lies inside the OpenJarvis source tree, to prevent dev artifacts from leaking into the repo.

Source code in src/openjarvis/learning/distillation/storage/paths.py
def resolve_distillation_root() -> Path:
    """Return the absolute path of the distillation root directory.

    The root is ``$OPENJARVIS_HOME/learning`` (or ``~/.openjarvis/learning``
    by default). Raises ``ConfigurationError`` if the resolved path lies
    inside the OpenJarvis source tree, to prevent dev artifacts from leaking
    into the repo.
    """
    home = _resolve_openjarvis_home()
    source_root = _find_source_root()
    if source_root is not None:
        try:
            home.relative_to(source_root)
        except ValueError:
            pass  # Good — not inside the source tree.
        else:
            raise ConfigurationError(
                f"OPENJARVIS_HOME ({home}) is inside the source tree "
                f"({source_root}). Distillation refuses to write runtime "
                "artifacts inside the OpenJarvis repo. Set OPENJARVIS_HOME "
                "to a directory outside the repo (default: ~/.openjarvis)."
            )
    return home / "learning"

ensure_distillation_dirs

ensure_distillation_dirs() -> Path

Create the distillation directory layout if missing.

Returns the distillation root. Creates sessions/, benchmarks/, benchmarks/reference_outputs/, and pending_review/ underneath it, all with restrictive 0o700 permissions via secure_mkdir.

Source code in src/openjarvis/learning/distillation/storage/paths.py
def ensure_distillation_dirs() -> Path:
    """Create the distillation directory layout if missing.

    Returns the distillation root. Creates ``sessions/``, ``benchmarks/``,
    ``benchmarks/reference_outputs/``, and ``pending_review/`` underneath it,
    all with restrictive ``0o700`` permissions via ``secure_mkdir``.
    """
    root = resolve_distillation_root()
    secure_mkdir(root)
    secure_mkdir(root / "sessions")
    secure_mkdir(root / "benchmarks")
    secure_mkdir(root / "benchmarks" / "reference_outputs")
    secure_mkdir(root / "pending_review")
    return root