Open History to see the last commit
1import * as Schema from "effect/Schema";
2import { compareSemverVersions } from "@t3tools/shared/semver";
3
4export const ANTIGRAVITY_CLI_MANIFEST_BASE =
5 "https://antigravity-cli-auto-updater-974169037036.us-central1.run.app/manifests";
6
7const Manifest = Schema.Struct({
8 version: Schema.String.check(Schema.isPattern(/^\d+\.\d+\.\d+$/u)),
9 url: Schema.String,
10 sha512: Schema.String.check(Schema.isPattern(/^[a-fA-F0-9]{128}$/u)),
11});
12const decodeManifest = Schema.decodeUnknownOption(Manifest);
13
14export interface AntigravityCliReleaseAsset {
15 readonly version: string;
16 readonly url: string;
17 readonly sha512: string;
18 readonly executable: { readonly name: string };
19 readonly format: "tar.gz" | "executable";
20}
21
22export function antigravityCliTarget(platform: NodeJS.Platform, arch: string, musl = false) {
23 if (!["darwin", "linux", "win32"].includes(platform) || !["x64", "arm64"].includes(arch)) {
24 return null;
25 }
26 const os = platform === "win32" ? "windows" : platform;
27 return `${os}_${arch === "x64" ? "amd64" : arch}${platform === "linux" && musl ? "_musl" : ""}`;
28}
29
30export function parseAntigravityCliRelease(
31 value: unknown,
32 platform: NodeJS.Platform,
33 arch: string,
34 musl = false,
35): AntigravityCliReleaseAsset | null {
36 const decoded = decodeManifest(value);
37 if (decoded._tag === "None" || antigravityCliTarget(platform, arch, musl) === null) return null;
38 const manifest = decoded.value;
39 if (compareSemverVersions(manifest.version, "1.5.0") < 0) return null;
40 const os = platform === "darwin" ? "mac" : platform === "win32" ? "windows" : "linux";
41 const cpu = arch === "x64" ? "x64" : "arm64";
42 const suffix = platform === "linux" && musl ? "_musl" : "";
43 const extension = platform === "win32" ? "exe" : "tar.gz";
44 const folder = `${platform === "win32" ? "windows" : platform}-${arch === "arm64" ? "arm" : "x64"}${suffix ? "-musl" : ""}`;
45 const prefix = `https://storage.googleapis.com/antigravity-public/antigravity-cli/${manifest.version}-`;
46 const rest = manifest.url.startsWith(prefix) ? manifest.url.slice(prefix.length) : "";
47 if (
48 !/^\d+\//u.test(rest) ||
49 rest.replace(/^\d+\//u, "") !== `${folder}/cli_${os}_${cpu}${suffix}.${extension}`
50 ) {
51 return null;
52 }
53 return {
54 version: manifest.version,
55 url: manifest.url,
56 sha512: manifest.sha512.toLowerCase(),
57 executable: { name: platform === "win32" ? "agy.exe" : "antigravity" },
58 format: platform === "win32" ? "executable" : "tar.gz",
59 };
60}