Implements the Lazarus Pit v2.0 foundation: - cell.py: Cell model, SQLite registry, filesystem packager with per-cell HERMES_HOME - operator_ctl.py: summon, invite, team, status, close, destroy commands - backends/base.py + process_backend.py: backend abstraction with process implementation - cli.py: operator CLI entrypoint - tests/test_cell.py: 13 tests for isolation, registry, TTL, lifecycle - README.md: quick start and architecture invariants All acceptance criteria for #274 and #269 are scaffolded and tested. 13 tests pass.
51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
"""
|
|
Backend abstraction for Lazarus Pit cells.
|
|
|
|
Every backend must implement the same contract so that cells,
|
|
teams, and operators do not need to know how a cell is actually running.
|
|
"""
|
|
|
|
from abc import ABC, abstractmethod
|
|
from dataclasses import dataclass
|
|
from typing import Optional
|
|
|
|
|
|
@dataclass
|
|
class BackendResult:
|
|
success: bool
|
|
stdout: str = ""
|
|
stderr: str = ""
|
|
pid: Optional[int] = None
|
|
message: str = ""
|
|
|
|
|
|
class Backend(ABC):
|
|
"""Abstract cell backend."""
|
|
|
|
name: str = "abstract"
|
|
|
|
@abstractmethod
|
|
def spawn(self, cell_id: str, hermes_home: str, command: list, env: Optional[dict] = None) -> BackendResult:
|
|
"""Spawn the cell process/environment."""
|
|
...
|
|
|
|
@abstractmethod
|
|
def probe(self, cell_id: str) -> BackendResult:
|
|
"""Check if the cell is alive and responsive."""
|
|
...
|
|
|
|
@abstractmethod
|
|
def logs(self, cell_id: str, tail: int = 50) -> BackendResult:
|
|
"""Return recent logs from the cell."""
|
|
...
|
|
|
|
@abstractmethod
|
|
def close(self, cell_id: str) -> BackendResult:
|
|
"""Gracefully close the cell."""
|
|
...
|
|
|
|
@abstractmethod
|
|
def destroy(self, cell_id: str) -> BackendResult:
|
|
"""Forcefully destroy the cell and all runtime state."""
|
|
...
|