Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
fix: offer a release within minutes of its iPhone app reaching the App Store
leepokaib56e53d46f96
diff --git a/.github/workflows/release-gate.yml b/.github/workflows/release-gate.ymlindex 4b75db49..3cccd1c8 100644--- a/.github/workflows/release-gate.yml+++ b/.github/workflows/release-gate.yml@@ -3,13 +3,12 @@ name: Release gate# Marks the newest release the App Store's iPhone app works with as GitHub's latest and points the# Homebrew tap at it (tools/release-gate.py): website downloads, install.sh and every updater follow# that mark, so a release that needs a newer iPhone app waits for App Review. After each release,-# and hourly for the App Store to catch up.+# and every 5 minutes while a newer release waits or the Homebrew tap trails the latest one: the cloud+# Worker's cron (cloud/src/release-gate.ts) dispatches it, since GitHub runs schedules late or not at all.on:workflow_run:workflows: ["Release desktop", "codync-host"]types: [completed]- schedule:- - cron: "17 * * * *"workflow_dispatch:inputs:allow_back:diff --git a/cloud/README.md b/cloud/README.mdindex d77244a0..d3cde919 100644--- a/cloud/README.md+++ b/cloud/README.md@@ -4,8 +4,9 @@ Cloudflare Worker for accounts and the off-LAN relay (spec: [docs/reference/remo- **`/v1` API** (`src/api.ts`, route groups in `src/routes/`): Clerk-authenticated account routes (devices, claims, computers, accessrequests, grants), `Codync-Sig`-authenticated host routes (`/v1/host/*`), the Clerk webhook, and a- 15-minute cron that expires requests and prunes nonces, and the public routine webhook route- `POST /v1/hooks/:computerId/:routineId` (spec §7.8). D1 schema: `migrations/` (later files rebuild some tables).+ 15-minute cron that expires requests and prunes nonces, a 5-minute cron that runs the release gate+ while a release waits behind GitHub's latest mark or the Homebrew tap trails it (`src/release-gate.ts`), and the public routine+ webhook route `POST /v1/hooks/:computerId/:routineId` (spec §7.8). D1 schema: `migrations/` (later files rebuild some tables).- **`ComputerRelay`** (`src/relay.ts`): one Durable Object per computer (SQLite storage, WebSocketHibernation). It admits device sockets against the host-signed ACL, forwards channel frames it can'tread, reports presence, holds the offline mailbox, and queues routine webhook deliveries (`hookbox`,@@ -59,10 +60,15 @@ npx wrangler deploy --env dev # → https://dev-api.codync.dev|---|---|---|| `CLERK_SECRET_KEY` | secret | JWKS for session tokens || `CLERK_WEBHOOK_SECRET` | secret | Svix signature on `/v1/webhooks/clerk` (`user.deleted`) |+| `RELEASE_GATE_TOKEN` | secret, main only | fine-grained GitHub token, *Actions: write* on `leepokai/Codync`: dispatches the release gate || `CLERK_ISSUER` | var | Clerk Frontend API URL; tokens must carry this `iss` || `CLERK_AUTHORIZED_PARTIES` | var, optional | comma-separated; a token with `azp` must match || `CLERK_JWT_KEY` | var, dev/e2e only | public key for networkless verification |+`RELEASE_GATE_TOKEN` is a fine-grained token without expiry. If it's revoked, set a new one with+`npx wrangler secret put RELEASE_GATE_TOKEN`: without a working token the release gate runs only after+each release, and only the Worker's cron logs show it (`GitHub graphql: 401`, `release gate dispatch: 403`).+New computers are limited to 10 per IP per minute with the Workers Rate Limiting binding`REGISTER_LIMITER` (`[[ratelimits]]`; each environment needs its own `namespace_id`).Public routine webhook deliveries are limited to 60 per sender IP and hook per minute withdiff --git a/cloud/src/index.ts b/cloud/src/index.tsindex 941e59f9..2b0241ee 100644--- a/cloud/src/index.ts+++ b/cloud/src/index.ts@@ -5,6 +5,7 @@import * as api from "./api";import { ApiError, type Ctx } from "./api";import type { ComputerRelay } from "./relay";+import { nudgeReleaseGate } from "./release-gate";export { ComputerRelay } from "./relay";@@ -25,6 +26,8 @@ export interface Env {CLERK_JWT_KEY?: string;CLERK_AUTHORIZED_PARTIES?: string;CLERK_WEBHOOK_SECRET?: string;+ /** GitHub token (Actions: write) that wakes the release gate; unset outside production. */+ RELEASE_GATE_TOKEN?: string;}type Handler = (c: Ctx, params: string[]) => Promise<unknown>;@@ -32,6 +35,10 @@ type Handler = (c: Ctx, params: string[]) => Promise<unknown>;/** Above every route's own limit (64 KB bodies); the routes check theirs. */const MAX_REQUEST = 128 * 1024;+/** wrangler.toml's crons, matched exactly: one that matches neither throws. */+const SWEEP_CRON = "*/15 * * * *";+const RELEASE_GATE_CRON = "*/5 * * * *";+const ID = "([A-Za-z0-9_-]{1,64})";const routes: [string, RegExp, Handler][] = [["GET", /^\/v1\/health$/, api.health],@@ -89,7 +96,9 @@ export default {}},- async scheduled(_controller: ScheduledController, env: Env): Promise<void> {- await api.sweep(env, Date.now());+ async scheduled(controller: ScheduledController, env: Env): Promise<void> {+ if (controller.cron === RELEASE_GATE_CRON) await nudgeReleaseGate(env);+ else if (controller.cron === SWEEP_CRON) await api.sweep(env, Date.now());+ else throw new Error(`unknown cron ${controller.cron}`);},} satisfies ExportedHandler<Env>;diff --git a/cloud/src/release-gate.ts b/cloud/src/release-gate.tsnew file mode 100644index 00000000..314e66a3--- /dev/null+++ b/cloud/src/release-gate.ts@@ -0,0 +1,56 @@+// Runs the release gate (.github/workflows/release-gate.yml) every 5 minutes while a published release+// waits behind GitHub's latest mark, for App Review (its MIN_APP is ahead of the App Store) or for its+// last files, and while the Homebrew tap trails the latest release (a tap update that failed after the+// mark moved). The App Store's iPhone app asks for its own host the moment it's out+// (docs/reference/compatibility.md, "Holding releases for the App Store"), and GitHub ran the+// workflow's hourly schedule late or not at all, so this replaced it.+// The gate reads the App Store itself, on GitHub's runners: Apple refuses the lookup from Workers (403).+// Without a token (`RELEASE_GATE_TOKEN`, Actions: write on the repository) it does nothing.++import type { Env } from "./index";++const DISPATCH = "https://api.github.com/repos/leepokai/Codync/actions/workflows/release-gate.yml/dispatches";+// One small request a tick: the REST release list carries every asset (megabytes).+const STATE = `{+ codync: repository(owner: "leepokai", name: "Codync") {+ latestRelease { tagName }+ releases(first: 10, orderBy: { field: CREATED_AT, direction: DESC }) { nodes { tagName isDraft isPrerelease } }+ }+ tap: repository(owner: "leepokai", name: "homebrew-codync") {+ cask: object(expression: "HEAD:Casks/codync.rb") { ... on Blob { text } }+ }+}`;++/** `a` is a later `major.minor.patch` than `b` (a leading `v` is ignored); false for anything unreadable. */+export function isNewer(a: string, b: string): boolean {+ const [x, y] = [a, b].map((v) => /^v?(\d+)\.(\d+)\.(\d+)$/.exec(v)?.slice(1).map(Number));+ if (!x || !y) return false;+ for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] > y[i];+ return false;+}++export type Release = { tagName: string; isDraft?: boolean; isPrerelease?: boolean };+export type State = {+ codync: { latestRelease: { tagName: string } | null; releases: { nodes: Release[] } };+ tap: { cask: { text: string } | null };+};++export async function nudgeReleaseGate(env: Env): Promise<void> {+ if (!env.RELEASE_GATE_TOKEN) return;+ const headers = {+ Accept: "application/vnd.github+json",+ Authorization: `Bearer ${env.RELEASE_GATE_TOKEN}`,+ "User-Agent": "codync-cloud",+ };+ const res = await fetch("https://api.github.com/graphql", { method: "POST", headers, body: JSON.stringify({ query: STATE }) });+ const { data, errors } = (await res.json()) as { data?: State; errors?: unknown };+ if (!res.ok || !data) throw new Error(`GitHub graphql: ${res.status} ${JSON.stringify(errors)}`);+ const latest = data.codync.latestRelease?.tagName ?? "v0.0.0";+ const tap = /^\s+version "([^"]+)"/m.exec(data.tap.cask?.text ?? "")?.[1];+ if (!tap) throw new Error("the Homebrew cask has no version line");+ const waiting = data.codync.releases.nodes.filter((r) => !r.isDraft && !r.isPrerelease && isNewer(r.tagName, latest));+ if (waiting.length === 0 && tap === latest.replace(/^v/, "")) return;+ const dispatch = await fetch(DISPATCH, { method: "POST", headers, body: JSON.stringify({ ref: "main" }) });+ if (!dispatch.ok) throw new Error(`release gate dispatch: ${dispatch.status} ${await dispatch.text()}`);+ console.log("release gate run", { latest, waiting: waiting.map((r) => r.tagName), tap });+}diff --git a/cloud/test/api.test.ts b/cloud/test/api.test.tsindex d2e9b58e..edaa8ecb 100644--- a/cloud/test/api.test.ts+++ b/cloud/test/api.test.ts@@ -539,8 +539,12 @@ describe("cron", () => {expect((await call("GET", `/v1/access-requests/${id}`, { token: u.token })).body.status).toBe("expired");const decision = await call("POST", `/v1/host/access-requests/${id}/decision`, { key: host.sign, body: { decision: "approve" } });expect(decision.body.error.code).toBe("requestExpired");- await worker.scheduled(createScheduledController(), env);+ await worker.scheduled(createScheduledController({ cron: "*/15 * * * *" }), env);const row = await env.DB.prepare("SELECT status, host_nonce FROM access_requests WHERE id = ?").bind(id).first();expect(row).toEqual({ status: "expired", host_nonce: null });});++ it("refuses a cron it has no job for", async () => {+ await expect(worker.scheduled(createScheduledController({ cron: "*/3 * * * *" }), env)).rejects.toThrow("unknown cron");+ });});diff --git a/cloud/test/release-gate.test.ts b/cloud/test/release-gate.test.tsnew file mode 100644index 00000000..256084f0--- /dev/null+++ b/cloud/test/release-gate.test.ts@@ -0,0 +1,80 @@+// The cron that runs the release gate while a release waits behind GitHub's latest mark or the tap trails it.++import { afterEach, describe, expect, it, vi } from "vitest";+import type { Env } from "../src/index";+import { isNewer, nudgeReleaseGate, type Release, type State } from "../src/release-gate";++/** Stubs fetch to answer the GraphQL state query with `releases`, the `latest` mark and the tap's cask (at+ * `tap`, by default the latest release); returns the dispatch requests sent. */+function fake(releases: Release[], latest: string, { dispatch = 204, tap = ` version "${latest.slice(1)}"` } = {}) {+ const state: State = {+ codync: { latestRelease: { tagName: latest }, releases: { nodes: releases } },+ tap: { cask: { text: `cask "codync" do\n${tap}\nend\n` } },+ };+ const spy = vi.spyOn(globalThis, "fetch").mockImplementation(async (input) =>+ String(input).endsWith("/graphql") ? Response.json({ data: state }) : new Response(null, { status: dispatch }),+ );+ return () =>+ spy.mock.calls.filter(([url]) => String(url).endsWith("/dispatches")).map(([url, init]) => ({ url: String(url), init }));+}++const env = { RELEASE_GATE_TOKEN: "t" } as Env;++afterEach(() => vi.restoreAllMocks());++describe("release gate nudge", () => {+ it("compares versions", () => {+ expect(isNewer("v2.20.1", "v2.20.0")).toBe(true);+ expect(isNewer("v2.20.1", "v2.20.2")).toBe(false);+ expect(isNewer("v2.20.1", "v2.20.1")).toBe(false);+ expect(isNewer("v2.10.0", "v2.9.9")).toBe(true);+ expect(isNewer("garbage", "v2.20.0")).toBe(false);+ expect(isNewer("v2.21.0-rc.1", "v2.20.2")).toBe(false);+ expect(isNewer("v2.21", "v2.20.2")).toBe(false);+ expect(isNewer("v3.x", "v2.20.2")).toBe(false);+ });++ it("runs the gate while a release waits behind the latest mark", async () => {+ const dispatches = fake([{ tagName: "v2.20.2" }, { tagName: "v2.20.1" }, { tagName: "v2.20.0" }], "v2.20.0");+ await nudgeReleaseGate(env);+ const [call] = dispatches();+ expect(dispatches()).toHaveLength(1);+ expect(call.url).toBe("https://api.github.com/repos/leepokai/Codync/actions/workflows/release-gate.yml/dispatches");+ expect(JSON.parse(call.init?.body as string)).toEqual({ ref: "main" });+ expect((call.init?.headers as Record<string, string>).Authorization).toBe("Bearer t");+ });++ it("leaves the gate alone when the latest mark is on the newest release", async () => {+ const dispatches = fake([{ tagName: "v2.20.2" }, { tagName: "v2.20.1" }], "v2.20.2");+ await nudgeReleaseGate(env);+ expect(dispatches()).toHaveLength(0);+ });++ it("runs the gate while the Homebrew tap trails the latest release", async () => {+ const dispatches = fake([{ tagName: "v2.20.2" }], "v2.20.2", { tap: ` version "2.20.1"` });+ await nudgeReleaseGate(env);+ expect(dispatches()).toHaveLength(1);+ });++ it("fails loudly on a cask it can't read the version of", async () => {+ fake([{ tagName: "v2.20.2" }], "v2.20.2", { tap: "" });+ await expect(nudgeReleaseGate(env)).rejects.toThrow("no version line");+ });++ it("ignores drafts and pre-releases", async () => {+ const dispatches = fake([{ tagName: "v2.21.0", isDraft: true }, { tagName: "v2.20.3", isPrerelease: true }, { tagName: "v2.20.2" }], "v2.20.2");+ await nudgeReleaseGate(env);+ expect(dispatches()).toHaveLength(0);+ });++ it("does nothing without a token", async () => {+ const dispatches = fake([{ tagName: "v2.20.2" }], "v2.20.0");+ await nudgeReleaseGate({} as Env);+ expect(dispatches()).toHaveLength(0);+ });++ it("fails loudly when GitHub refuses the dispatch", async () => {+ fake([{ tagName: "v2.20.2" }], "v2.20.0", { dispatch: 403 });+ await expect(nudgeReleaseGate(env)).rejects.toThrow("release gate dispatch: 403");+ });+});diff --git a/cloud/wrangler.toml b/cloud/wrangler.tomlindex 86156202..58e731d2 100644--- a/cloud/wrangler.toml+++ b/cloud/wrangler.toml@@ -41,8 +41,10 @@ name = "HOOK_LIMITER"namespace_id = "1021"simple = { limit = 60, period = 60 }+# Sweep expired requests and nonces; wake the release gate (src/release-gate.ts).+# src/index.ts routes on these exact strings (SWEEP_CRON, RELEASE_GATE_CRON): change both together.[triggers]-crons = ["*/15 * * * *"]+crons = ["*/15 * * * *", "*/5 * * * *"]# dev: the deployed test environment at dev-api.codync.dev (Clerk development instance).[env.dev]diff --git a/docs/guides/environments-and-deployment.md b/docs/guides/environments-and-deployment.mdindex 577280a4..4f58bed7 100644--- a/docs/guides/environments-and-deployment.md+++ b/docs/guides/environments-and-deployment.md@@ -19,7 +19,7 @@ The environment is chosen when building, never stored: the host compiles in its## Checked-in readiness- **Development:** app configuration and Worker configuration target `https://dev-api.codync.dev`; dev Clerk issuer and D1 binding are configured in source. Exercise the live path before claiming readiness.-- **Production:** `main.plist` targets `https://api.codync.dev` with the Clerk production instance (`clerk.codync.dev`, Google sign-in through the `codync-auth` Google Cloud project, published). The root Worker is deployed with D1 `codync`, `CLERK_SECRET_KEY` and `CLERK_WEBHOOK_SECRET` (Clerk webhook endpoint `https://api.codync.dev/v1/webhooks/clerk`, `user.deleted`).+- **Production:** `main.plist` targets `https://api.codync.dev` with the Clerk production instance (`clerk.codync.dev`, Google sign-in through the `codync-auth` Google Cloud project, published). The root Worker is deployed with D1 `codync`, `CLERK_SECRET_KEY` and `CLERK_WEBHOOK_SECRET` (Clerk webhook endpoint `https://api.codync.dev/v1/webhooks/clerk`, `user.deleted`), and `RELEASE_GATE_TOKEN` (dispatches the release gate; renewal in the [cloud README](../../cloud/README.md)).- **Local:** Wrangler's `local` environment supports the isolated integration test and its test issuer. It is not a real Google sign-in test.## Troubleshooting: a running host appears offline on another computerdiff --git a/docs/reference/compatibility.md b/docs/reference/compatibility.mdindex 04358c86..baf46ec2 100644--- a/docs/reference/compatibility.md+++ b/docs/reference/compatibility.md@@ -71,20 +71,28 @@ computer set up from it would lock out the iPhone it pairs with. So what anyonefollows the App Store:- **Release gate** (`tools/release-gate.py`, run by `.github/workflows/release-gate.yml` after- each release and hourly): releases are published without GitHub's *latest* mark. The gate- marks the newest fully uploaded release whose `MIN_APP` the App Store's iPhone version meets+ each release, and every 5 minutes while a newer release waits or the Homebrew tap trails the+ latest one, dispatched by the cloud Worker's cron: `cloud/src/release-gate.ts`, token+ `RELEASE_GATE_TOKEN`): releases are published without GitHub's *latest* mark. The gate marks+ the newest fully uploaded release whose `MIN_APP` the App Store's iPhone version meets(`itunes.apple.com/lookup?id=6760984418`, with a query string of its own each time: Apple's CDNkeeps the bare URL for up to a day after a release) and points the Homebrew tap (cask and formula) atit. The website's download links (`releases/latest/download/…`), `packaging/install.sh`,electron-updater and `codync-host update` all read the latest release, so none of them seesa release that waits. Every release after a raise waits with it, desktop-only ones too, until- App Review passes; the next hourly run then offers the newest. The mark only moves forward- on its own (a lookup can briefly answer with an older version); to move it back, run the- *Release gate* workflow by hand with `allow_back` on. `DRY_RUN=1 python3- tools/release-gate.py` prints the decision; `python3 tools/release-gate-test.py` checks it.- Before the gate, 2.18.0 (the first real raise) went straight to the website: in its first- day 33 new computers were paired by the App Store's iPhone 2.17.0 and received no message- from it.+ App Review passes; within 5 minutes the gate then offers the newest. The new iPhone app asks for+ its own host at once, so the wait has to be short. The gate itself reads the App Store from+ GitHub's runners (Apple answers Workers with 403). The cron replaced the workflow's hourly GitHub+ schedule, which GitHub ran late or not at all: on 2026-10-20 iPhone 2.20.1 reached the App Store+ at 09:49 UTC while the next scheduled run came at 11:43, so for two hours every phone that+ updated said to update the computer to a host no updater could see. If the Worker can't dispatch+ (its cron logs show `GitHub graphql: 401` or `release gate dispatch: 403`), releases wait for the+ next release's own run or a run by hand. The mark only moves forward on its own (a lookup can+ briefly answer with an older version); to move it back, run the *Release gate* workflow by hand+ with `allow_back` on. `DRY_RUN=1 python3 tools/release-gate.py` prints the decision;+ `python3 tools/release-gate-test.py` checks it. Before the gate, 2.18.0 (the first real raise)+ went straight to the website: in its first day 33 new computers were paired by the App Store's+ iPhone 2.17.0 and received no message from it.- **Updaters** only compare versions with the latest release; they don't ask the App Storethemselves (they did from 2.5.0 to 2.19.2, before the gate). The hidden `codync-host compat`command stays: the desktop app runs it to read `environment` before installing the host, anddiff --git a/tools/release-gate.py b/tools/release-gate.pyindex 9d3eea5d..932ca92f 100644--- a/tools/release-gate.py+++ b/tools/release-gate.py@@ -12,8 +12,9 @@ Homebrew tap follows it, so this decides what anyone can get: the newest complethost serves the iPhone app the App Store has (its `MIN_APP`). A newer one waits for App Review;offered earlier, a computer on it would tell every paired iPhone to update to a version still inreview. The mark only moves forward on its own: an App Store lookup that briefly answers with an-older version doesn't take downloads back. Runs after each release and hourly-(.github/workflows/release-gate.yml).+older version doesn't take downloads back. Runs after each release, and every 5 minutes while+a newer release waits or the tap trails the latest one (.github/workflows/release-gate.yml, dispatched by+cloud/src/release-gate.ts)."""import json@@ -141,6 +142,8 @@ def main():"only on a run with allow_back (Actions → Release gate → Run workflow)")returnprint(f"App Store: {store}; latest release: {current} → {tag}")+ # The mark first: a tap that fails mustn't hold everyone's downloads back. The Worker runs the gate+ # again while the tap trails the mark.if tag != current and not DRY_RUN:run("gh", "release", "edit", tag, "--repo", REPO, "--latest")tap(tag)