Skip to content

The agent that grows with you

refactor(tools): tirith/wire micro-collapses

Teknium49b04e2058e8
diff --git a/tools/skills_sync_client_wire.py b/tools/skills_sync_client_wire.py
index 5fc9cc5194f..367942fbd82 100644
--- a/tools/skills_sync_client_wire.py
+++ b/tools/skills_sync_client_wire.py
@@ -149,10 +149,9 @@ def build_root_tree(node: Dict[str, Any], objects: ObjectSet, *, manifest_hash:
adds the root ``sync-manifest`` BLOB entry (cannot collide with a skill dir: those are trees)."""
entries: List[Dict[str, str]] = []
for name, child in node.items():
- if isinstance(child, dict) and "__tree__" in child and len(child) == 1:
- entries.append(_entry(name, KIND_TREE, child["__tree__"], MODE_DIR))
- else:
- entries.append(_entry(name, KIND_TREE, build_root_tree(child, objects), MODE_DIR))
+ leaf = isinstance(child, dict) and "__tree__" in child and len(child) == 1
+ entries.append(_entry(name, KIND_TREE, child["__tree__"] if leaf else build_root_tree(child, objects),
+ MODE_DIR))
if manifest_hash is not None:
entries.append(_entry(SYNC_MANIFEST_ENTRY_NAME, KIND_BLOB, manifest_hash, MODE_FILE))
return _add_tree(entries, objects)
@@ -190,18 +189,16 @@ class SyncConflict(RuntimeError):
def __init__(self, actual: Optional[str]):
self.actual: Optional[str] = actual or None
- super().__init__(
- f"CAS conflict; actual head {self.actual}" if self.actual else "CAS conflict; the ref does not exist yet"
- )
+ super().__init__(f"CAS conflict; actual head {self.actual}" if self.actual
+ else "CAS conflict; the ref does not exist yet")
def _check_version(caps: Dict[str, Any]) -> None:
"""Reject an incompatible server major version."""
ver = str(caps.get("hsp_version") or "") # wire field name
if ver.split(".", 1)[0] != WIRE_VERSION:
- raise SyncError(
- f"this server speaks sync version {ver!r}, but this Hermes speaks "
- f"{WIRE_VERSION} — update Hermes to sync with it")
+ raise SyncError(f"this server speaks sync version {ver!r}, but this Hermes speaks "
+ f"{WIRE_VERSION} — update Hermes to sync with it")
def _body(r) -> Dict[str, Any]:
@@ -276,7 +273,8 @@ class SyncClient:
hashes are no-ops. ``org_scope`` adds ``?scope=org`` (required before an org CAS/propose)."""
files = [(h, (kind, data, "application/octet-stream")) for h, (kind, data) in objects.items()]
return _body(self._request(
- "POST", "objects", "put_objects", ok=(200, 201), files=files, params={"scope": "org"} if org_scope else None,
+ "POST", "objects", "put_objects", ok=(200, 201), files=files,
+ params={"scope": "org"} if org_scope else None,
errors={413: "object too large (413)", 422: lambda r: f"hash_mismatch (422): {r.text}"}))
def cas_ref(self, name: str, from_hash: Optional[str], to_hash: str) -> Dict[str, Any]:
diff --git a/tools/tirith_security.py b/tools/tirith_security.py
index 030a33227cd..4f245dd032a 100644
--- a/tools/tirith_security.py
+++ b/tools/tirith_security.py
@@ -164,8 +164,7 @@ def _clear_install_failed():
def _disk_marker_blocks_install() -> bool:
"""Apply a still-valid disk marker to module state; True if install must be skipped.
Keeps the marker's real reason so in-process retry can detect cosign_missing."""
- disk_reason = _read_failure_reason()
- if disk_reason is None or not _is_install_failed_on_disk():
+ if (disk_reason := _read_failure_reason()) is None or not _is_install_failed_on_disk():
return False
_set_failed(disk_reason)
return True
@@ -220,11 +219,11 @@ def _verify_cosign(checksums_path: str, sig_path: str, cert_path: str) -> bool |
except (OSError, subprocess.TimeoutExpired) as exc:
logger.warning("cosign execution failed: %s", exc)
return None
- if result.returncode == 0:
- logger.info("cosign provenance verification passed")
- return True
- logger.warning("cosign verification failed (exit %d): %s", result.returncode, result.stderr.strip())
- return False
+ if result.returncode:
+ logger.warning("cosign verification failed (exit %d): %s", result.returncode, result.stderr.strip())
+ return False
+ logger.info("cosign provenance verification passed")
+ return True
def _verify_release_provenance(base_url: str, tmpdir: str, checksums_path: str, log) -> tuple[bool, str]:
@@ -234,8 +233,7 @@ def _verify_release_provenance(base_url: str, tmpdir: str, checksums_path: str,
logger.info("cosign not on PATH — installing tirith with SHA-256 verification only "
"(install cosign for full supply chain verification)")
return False, ""
- sig_path = os.path.join(tmpdir, "checksums.txt.sig")
- cert_path = os.path.join(tmpdir, "checksums.txt.pem")
+ sig_path, cert_path = os.path.join(tmpdir, "checksums.txt.sig"), os.path.join(tmpdir, "checksums.txt.pem")
try:
_download_file(f"{base_url}/checksums.txt.sig", sig_path)
_download_file(f"{base_url}/checksums.txt.pem", cert_path)
@@ -303,8 +301,7 @@ def _install_tirith(*, log_failures: bool = True) -> tuple[str | None, str]:
log("tirith install failed: cannot create temp dir: %s", exc)
return None, "no_space"
try:
- archive_path = os.path.join(tmpdir, archive_name)
- checksums_path = os.path.join(tmpdir, "checksums.txt")
+ archive_path, checksums_path = os.path.join(tmpdir, archive_name), os.path.join(tmpdir, "checksums.txt")
logger.info("tirith not found — downloading latest release for %s...", target)
try:
_download_file(f"{base_url}/{archive_name}", archive_path)