text
stringlengths
0
1.47k
Two environments, genuinely different storage, one interface:
* **Self-hosted** — the runner shares this container and the workspace is a live directory on
the data volume. A write is a write.
* **Hosted** — sandboxes are ephemeral, so between turns a workspace exists ONLY as the
checkpoint tarball in blob storage (`sessions/<sid>/workspace.tgz`). A write has to rewrite
that archive, because there is no filesystem to write to until the next turn hydrates one.
This exists so an app built on a Harness can own state the agent also edits — the slides kit
keeps deck.json here — without either side needing to know which deployment it is running in.
"""
async def read(self, sid: str, path: str) -> bytes | None: ...
async def write(self, sid: str, path: str, data: bytes) -> bool: ...
class Backing:
def __init__(self, graph: GraphStore, blob: BlobStore, secrets: SecretStore, mode: str,
workspace: "WorkspaceFiles"):
self.graph, self.blob, self.secrets, self.mode = graph, blob, secrets, mode
self.workspace = workspace
# ── local: SQLite graph ───────────────────────────────────────────────────────────
class SqliteGraphStore:
"""Vertices/edges in one SQLite file. VG upsert semantics preserved: property() sets the
listed props and keeps the rest (merge, not replace); edge ids are the same uuid5(src|label|dst)
so re-adds are idempotent. find() filters by property equality in Python — dev-scale data,
no json_extract dialect games."""
def __init__(self, path: str):
self._path = path
Path(path).parent.mkdir(parents=True, exist_ok=True)
with self._conn() as c:
c.execute("CREATE TABLE IF NOT EXISTS vertices (vid TEXT PRIMARY KEY, label TEXT NOT NULL, props TEXT NOT NULL)")
c.execute("CREATE INDEX IF NOT EXISTS idx_vertices_label ON vertices(label)")
c.execute("CREATE TABLE IF NOT EXISTS edges (eid TEXT PRIMARY KEY, label TEXT NOT NULL, src TEXT NOT NULL, dst TEXT NOT NULL)")
def _conn(self) -> sqlite3.Connection:
c = sqlite3.connect(self._path, timeout=30)
c.execute("PRAGMA journal_mode=WAL")
return c
async def get(self, vid: str, label: str | None = None) -> dict | None:
def _do():
with self._conn() as c:
row = c.execute("SELECT vid, label, props FROM vertices WHERE vid=?", (vid,)).fetchone()
if not row:
return None
if label is not None and row[1] != label:
return None # label filter is load-bearing where the id is caller-controlled
return {"id": row[0], **json.loads(row[2])}
return await asyncio.to_thread(_do)
async def upsert(self, label: str, vid: str, props: dict, *, raise_on_fail: bool = False) -> None:
clean = {k: str(v) for k, v in props.items()} # VG stores string props; keep parity
def _do():
with self._conn() as c:
row = c.execute("SELECT props FROM vertices WHERE vid=?", (vid,)).fetchone()
merged = {**(json.loads(row[0]) if row else {}), **clean}
c.execute("INSERT INTO vertices(vid,label,props) VALUES(?,?,?) "
"ON CONFLICT(vid) DO UPDATE SET props=excluded.props",
(vid, label, json.dumps(merged)))
try:
await asyncio.to_thread(_do)
except Exception:
if raise_on_fail:
raise RuntimeError("graph write failed")
async def add_edge(self, label: str, src: str, dst: str) -> None:
if not (src and dst):
return
eid = str(uuid.uuid5(uuid.NAMESPACE_URL, f"{src}|{label}|{dst}"))
def _do():
with self._conn() as c:
c.execute("INSERT OR IGNORE INTO edges(eid,label,src,dst) VALUES(?,?,?,?)",
(eid, label, src, dst))
try:
await asyncio.to_thread(_do)
except Exception: # noqa: BLE001 — best-effort, matches VG edge semantics
pass
async def delete(self, vid: str, label: str | None = None) -> bool:
def _do():
with self._conn() as c:
row = c.execute("SELECT label FROM vertices WHERE vid=?", (vid,)).fetchone()
if not row or (label is not None and row[0] != label):
return False
c.execute("DELETE FROM vertices WHERE vid=?", (vid,))
c.execute("DELETE FROM edges WHERE src=? OR dst=?", (vid, vid))
return True
try:
return await asyncio.to_thread(_do)
except Exception: # noqa: BLE001
return False
async def find(self, label: str, eq: dict | None = None, neq: dict | None = None) -> list[dict]:
def _do():