text stringlengths 0 1.47k |
|---|
async def write(self, sid: str, path: str, data: bytes) -> bool: |
member = _safe_member(path) |
if not member: |
return False |
key = self.key_for(sid) |
raw = await self.blob.get(self.kb, key) |
def _rewrite() -> bytes: |
out = io.BytesIO() |
wrote = False |
with tarfile.open(fileobj=out, mode="w:gz") as dst: |
if raw: |
with tarfile.open(fileobj=io.BytesIO(raw), mode="r:gz") as src: |
for m in src.getmembers(): |
name = m.name[2:] if m.name.startswith("./") else m.name |
if name == member: |
continue # replaced below |
f = src.extractfile(m) if m.isfile() else None |
dst.addfile(m, f) |
info = tarfile.TarInfo(member) |
info.size = len(data) |
info.mtime = int(time.time()) |
info.mode = 0o644 |
dst.addfile(info, io.BytesIO(data)) |
wrote = True |
return out.getvalue() if wrote else b"" |
try: |
tar = await asyncio.to_thread(_rewrite) |
except Exception: # noqa: BLE001 |
return False |
return bool(tar) and await self.blob.put(self.kb, key, tar) |
def make_backing(*, client_getter, vg_url: str, vg_key: str, vg_tenant: str, |
vault_url: str, vault_key: str) -> Backing: |
"""Build the configured backing. HR_BACKING=vg|local; unset ⇒ vg when VG_GATEWAY_URL is |
configured (production), local otherwise (a laptop clone works with zero env).""" |
mode = os.environ.get("HR_BACKING", "").strip().lower() or ("vg" if vg_url else "local") |
# Where a session's workspace actually lives, which is the one thing that differs most between |
# the two deployments: a live directory the runner owns and serves, or a checkpoint tarball |
# that is the only copy between turns. |
ws_key = lambda sid: f"sessions/{sid}/workspace.tgz" # noqa: E731 — matches gateway._ws_blob |
if mode == "vg": |
from backing_vg import VgBlobStore, VgGraphStore, VaultSecretStore |
blob = VgBlobStore(client_getter, vg_url, vg_key) |
return Backing( |
graph=VgGraphStore(client_getter, vg_url, vg_key, vg_tenant), |
blob=blob, |
secrets=VaultSecretStore(client_getter, vault_url, vault_key), |
mode="vg", |
workspace=CheckpointWorkspaceFiles(blob, os.environ.get("HARNESS_BLOB_KB", "harness-sessions"), ws_key)) |
data = os.environ.get("HR_DATA_DIR", ".hr-data") |
local_blob = FileBlobStore(os.path.join(data, "blobs")) |
return Backing( |
graph=SqliteGraphStore(os.path.join(data, "graph.db")), |
blob=local_blob, |
secrets=FileSecretStore(os.path.join(data, "secrets")), |
mode="local", |
workspace=RunnerWorkspaceFiles(os.environ.get("POOL_MGMT_ENDPOINT", "http://127.0.0.1:8081"), |
os.environ.get("HARNESS_INTERNAL_KEY", ""), |
local_blob, |
os.environ.get("HARNESS_RESP_BLOB_KB", "harness-responses"))) |
# ===== file: gateway/browser_plane.py ===== |
"""The browser server's plane: a real browser, in a vendor's cloud or the operator's own, driven |
from this gateway over the Chrome DevTools Protocol, handed to the agent as a dozen typed tools |
and nothing else. |
The operator's own browser (HR_BROWSER_CDP_URL, a Chrome started with --remote-debugging-port or |
any CDP endpoint) takes the vendor's place whole: no vendor session, no live view, no charge, one |
browser context per harness session on the one browser, and the private-address rule lifted, |
since that browser sits on the operator's own network and reaches what the operator's shell |
already can (a customer's crawler behind a headful Chrome broker, 2026-09-30). |
One browser session per harness session, made on the first call and stopped at the end of the |
turn, after idle, or at the session cap. The vendor is behind one adapter (Browser Use Cloud |
first; Browserbase has the same shape: a session id and a CDP address), so the tools, the guards |
and the metering never learn a vendor's name. |
What the agent is never given: a JavaScript evaluator, downloads, cookies, the vendor's key, the |
CDP address. What every request is checked against, subresources and redirects included: the |
harness's allow and deny lists and the private, loopback, link-local and metadata address ranges. |
Money: the vendor's list price, no markup. A session is priced BEFORE it starts as the session cap |
times the per-minute rate (that is what counts against the task's cost cap), and metered AFTER |
from the vendor's own figures for the minutes it ran (rounded up, one-minute minimum). The prices |
below are the estimate's; the meter reads what the vendor reports. |
""" |
from __future__ import annotations |
import asyncio |
import ipaddress |
import json |
import math |
import os |
import socket |
import time |
import urllib.parse |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.