Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
#!/usr/bin/env python3
"""Build `release-artifacts.json`, the manifest install.sh / install.ps1 read.
The release workflows call this after collecting their artifacts:
release_manifest.py --component cli --version 0.3.0 --dir release/ \
--base-url https://github.com/trycua/cua/releases/download/cua-sdk-v0.3.0 \
--merge previous.json --out release/release-artifacts.json
Artifact names it recognises (anything else in --dir is ignored):
cli: cua-cli-<version>-<platform>.tar.gz (macOS, Linux)
cua-cli-<version>-<platform>.zip (Windows)
app: cua-spaces-<version>-darwin-universal.dmg / .pkg
cua-spaces-<version>-linux-<arch>.AppImage / .deb
cua-spaces-<version>-windows-<arch>.msi / -setup.exe
the Electron app (electron-builder names, kinds electron-*):
Cua-Spaces-<version>-<arm64|universal>.dmg / -mac.zip,
Cua-Spaces-<version>-<x86_64|arm64>.AppImage,
cua-spaces_<version>_<amd64|arm64>.deb,
Cua-Spaces-Setup-<version>[-<x64|arm64>].exe
<platform> is darwin-arm64, darwin-x64, linux-x64, linux-arm64, windows-x64 or
windows-arm64; a darwin-universal app is listed under both macOS platforms,
and a universal Electron app (kind electron-*-universal) under both macOS or
both Windows platforms. The installers pick only the dmg, pkg, appimage, deb,
msi and nsis kinds, so the Electron entries never change what they install.
Optional signatures next to an artifact: `<name>.minisig` (minisign) and
`<name>.sigstore.json` (cosign bundle).
Format contract (install.sh parses it with grep/sed, no jq): the file is JSON
with `"schema": 1`, and every artifact object sits on ONE line with string
values that contain no double quotes.
"""
from __future__ import annotations
import argparse
import hashlib
import json
import re
import sys
from pathlib import Path
SCHEMA = 1
PLATFORMS = ("darwin-arm64", "darwin-x64", "linux-x64", "linux-arm64", "windows-x64", "windows-arm64")
VERSION = r"(?P<version>\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)"
# Lazy, and the suffix itself lazily optional (`??`): electron-builder puts an
# optional architecture after the version, so a stable 1.2.3-x64.exe is
# version 1.2.3 and arch x64, not a "1.2.3-x64" prerelease.
EVERSION = r"(?P<version>\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+?)??)"
PATTERNS = [
("cli", "tar.gz", re.compile(rf"^cua-cli-{VERSION}-(?P<platform>(?:darwin|linux)-(?:x64|arm64))\.tar\.gz$")),
("cli", "zip", re.compile(rf"^cua-cli-{VERSION}-(?P<platform>windows-(?:x64|arm64))\.zip$")),
("app", "dmg", re.compile(rf"^cua-spaces-{VERSION}-(?P<platform>darwin-(?:universal|x64|arm64))\.dmg$")),
("app", "pkg", re.compile(rf"^cua-spaces-{VERSION}-(?P<platform>darwin-(?:universal|x64|arm64))\.pkg$")),
("app", "appimage", re.compile(rf"^cua-spaces-{VERSION}-(?P<platform>linux-(?:x64|arm64))\.AppImage$")),
("app", "deb", re.compile(rf"^cua-spaces-{VERSION}-(?P<platform>linux-(?:x64|arm64))\.deb$")),
("app", "msi", re.compile(rf"^cua-spaces-{VERSION}-(?P<platform>windows-(?:x64|arm64))\.msi$")),
("app", "nsis", re.compile(rf"^cua-spaces-{VERSION}-(?P<platform>windows-(?:x64|arm64))-setup\.exe$")),
# The Electron app (apps/cua-spaces-desktop), named by electron-builder.
("app", "electron-dmg", re.compile(rf"^Cua-Spaces-{EVERSION}-(?P<arch>arm64|universal)\.dmg$")),
("app", "electron-zip", re.compile(rf"^Cua-Spaces-{EVERSION}-(?P<arch>arm64|universal)-mac\.zip$")),
("app", "electron-appimage", re.compile(rf"^Cua-Spaces-{EVERSION}-(?P<arch>x86_64|arm64)\.AppImage$")),
("app", "electron-deb", re.compile(rf"^cua-spaces_{EVERSION}_(?P<arch>amd64|arm64)\.deb$")),
("app", "electron-nsis", re.compile(rf"^Cua-Spaces-Setup-{EVERSION}(?:-(?P<arch>x64|arm64))?\.exe$")),
]
# Electron's architecture names, per kind, as platforms.
ELECTRON_PLATFORMS = {
"electron-dmg": {"arm64": "darwin-arm64", "universal": "darwin-universal"},
"electron-zip": {"arm64": "darwin-arm64", "universal": "darwin-universal"},
"electron-appimage": {"x86_64": "linux-x64", "arm64": "linux-arm64"},
"electron-deb": {"amd64": "linux-x64", "arm64": "linux-arm64"},
"electron-nsis": {"x64": "windows-x64", "arm64": "windows-arm64", None: "windows-universal"},
}
UNIVERSAL = {
"darwin-universal": ["darwin-arm64", "darwin-x64"],
"windows-universal": ["windows-x64", "windows-arm64"],
}
SAFE = re.compile(r'^[^"\\\x00-\x1f]*$')
def classify(name: str):
for component, kind, pattern in PATTERNS:
match = pattern.match(name)
if match:
if kind in ELECTRON_PLATFORMS:
platform = ELECTRON_PLATFORMS[kind][match.group("arch")]
if platform in UNIVERSAL:
kind = f"{kind}-universal"
else:
platform = match.group("platform")
return component, kind, platform, match.group("version")
return None
def sha256(path: Path) -> str:
digest = hashlib.sha256()
with path.open("rb") as handle:
for block in iter(lambda: handle.read(1 << 20), b""):
digest.update(block)
return digest.hexdigest()
def url_for(base_url: str | None, name: str) -> str:
return f"{base_url.rstrip('/')}/{name}" if base_url else name
def scan(component: str, version: str, directory: Path, base_url: str | None) -> list[dict]:
entries = []
for path in sorted(directory.iterdir()):
if not path.is_file():
continue
found = classify(path.name)
if not found or found[0] != component:
continue
_, kind, platform, file_version = found
if file_version != version:
raise SystemExit(f"{path.name}: version {file_version} does not match --version {version}")
platforms = UNIVERSAL.get(platform, [platform])
common = {
"name": path.name,
"url": url_for(base_url, path.name),
"sha256": sha256(path),
"size": path.stat().st_size,
}
for suffix, key in ((".minisig", "minisig"), (".sigstore.json", "cosign_bundle")):
if (directory / f"{path.name}{suffix}").is_file():
common[key] = url_for(base_url, f"{path.name}{suffix}")
for p in platforms:
entries.append({"component": component, "platform": p, "kind": kind, "version": version, **common})
if not entries:
raise SystemExit(f"no {component} artifacts for {version} in {directory}")
return entries
def render(manifest: dict) -> str:
"""JSON with one artifact object per line (the install.sh contract)."""
for artifact in manifest["artifacts"]:
for key, value in artifact.items():
if isinstance(value, str) and not SAFE.match(value):
raise SystemExit(f"unsafe characters in {key}: {value!r}")
head = {k: v for k, v in manifest.items() if k != "artifacts"}
lines = ["{"]
for key, value in head.items():
lines.append(f" {json.dumps(key)}: {json.dumps(value, separators=(', ', ': '))},")
lines.append(' "artifacts": [')
rows = [json.dumps(a, separators=(",", ":")) for a in manifest["artifacts"]]
lines.extend(f" {row}{',' if i < len(rows) - 1 else ''}" for i, row in enumerate(rows))
lines.append(" ]")
lines.append("}")
return "\n".join(lines) + "\n"
def build(args: argparse.Namespace) -> dict:
previous: dict = {}
if args.merge and Path(args.merge).is_file():
previous = json.loads(Path(args.merge).read_text())
if previous.get("schema") != SCHEMA:
raise SystemExit(f"{args.merge}: unsupported schema {previous.get('schema')!r}")
ours = scan(args.component, args.version, Path(args.dir), args.base_url)
if args.carry_forward_platforms:
# A partial release (CUA-2068): platforms this release did not build
# keep the artifacts of the build that is current for them, each with
# its own version, so the installers pick the newest build per platform.
built = {a["platform"] for a in ours}
kept = [a for a in previous.get("artifacts", []) if a.get("component") != args.component or a.get("platform") not in built]
carried = {a["platform"] for a in kept if a.get("component") == args.component}
missing = [p for p in PLATFORMS if p not in built and p not in carried]
if missing:
raise SystemExit(
f"--carry-forward-platforms: no previous {args.component} artifact for {', '.join(missing)}; "
"a platform with nothing to carry forward must be built"
)
else:
kept = [a for a in previous.get("artifacts", []) if a.get("component") != args.component]
versions = dict(previous.get("versions", {}))
versions[args.component] = args.version
artifacts = sorted(kept + ours, key=lambda a: (a["component"], a["platform"], a["kind"]))
return {"schema": SCHEMA, "repo": args.repo, "versions": versions, "artifacts": artifacts}
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("--component", choices=("cli", "app"), required=True)
parser.add_argument("--version", required=True)
parser.add_argument("--dir", required=True, help="directory holding the release artifacts")
parser.add_argument("--base-url", help="download URL prefix (default: names relative to the manifest)")
parser.add_argument("--merge", help="existing manifest; its other components are kept")
parser.add_argument("--repo", default="trycua/cua")
parser.add_argument(
"--carry-forward-platforms",
action="store_true",
help="partial release: keep the --merge file's artifacts for platforms this release has none for "
"(default: replace every artifact of the component)",
)
parser.add_argument("--out", help="output path (default stdout)")
args = parser.parse_args(argv)
text = render(build(args))
if args.out:
Path(args.out).write_text(text)
else:
sys.stdout.write(text)
return 0
if __name__ == "__main__":
sys.exit(main())