Skip to content

An open-source, faster Devin alternative

TypeScript

Onboarding: $5 in credits for starring diggerhq/opencomputer (#1026)

opencomputer-app[bot]74409b7ef023
diff --git a/cloudflare-workers/api-edge/migrations/0024_orgs_github_star.sql b/cloudflare-workers/api-edge/migrations/0024_orgs_github_star.sql
new file mode 100644
index 00000000..3099618e
--- /dev/null
+++ b/cloudflare-workers/api-edge/migrations/0024_orgs_github_star.sql
@@ -0,0 +1,4 @@
+-- Onboarding "star us on GitHub" bonus. The baseline is the repo's stargazer
+-- count when the person went to star it; bonus_at is when the credits landed.
+ALTER TABLE orgs ADD COLUMN github_star_baseline INTEGER;
+ALTER TABLE orgs ADD COLUMN github_star_bonus_at INTEGER;
diff --git a/cloudflare-workers/api-edge/src/dashboard.ts b/cloudflare-workers/api-edge/src/dashboard.ts
index 10decc67..353557da 100644
--- a/cloudflare-workers/api-edge/src/dashboard.ts
+++ b/cloudflare-workers/api-edge/src/dashboard.ts
@@ -37,6 +37,7 @@ import { enableManagedBilling } from "./model_billing";
import { paywallContext } from "./billing_onramp";
import { insufficientManagedAgentCredits } from "./managed_agent_credit_gate";
import { sendSlackAlert, teammateInvitedAlert } from "./slack_alerts";
+import { handleGitHubStarClaim, handleGitHubStarStart, handleGitHubStarState } from "./github_star";
export interface DashboardEnv extends BillingEventsEnv {
/** Computer rollout (work 052): see computerEnabledFor in computer.ts. */
@@ -65,6 +66,8 @@ export interface DashboardEnv extends BillingEventsEnv {
OPENROUTER_BASE_URL?: string;
OPENROUTER_MARKUP_BPS?: string;
OC_MANAGED_CRED_HMAC_SECRET: string;
+ // Optional read-only token for the onboarding star bonus (github_star.ts).
+ GITHUB_TOKEN?: string;
}
const SESSION_COOKIE = "oc_session";
@@ -702,6 +705,9 @@ export async function handleDashboard(
if (m && method === "DELETE") return handleRevokeInvitation(req, env, caller, m[1]);
}
if (sub === "/org/credits" && method === "GET") return handleGetCredits(req, env, caller);
+ if (sub === "/github-star" && method === "GET") return handleGitHubStarState(env, caller.orgID);
+ if (sub === "/github-star/start" && method === "POST") return handleGitHubStarStart(env, caller.orgID);
+ if (sub === "/github-star/claim" && method === "POST") return handleGitHubStarClaim(env, caller.orgID);
// ── api keys ───────────────────────────────────────────────────────────
if (sub === "/api-keys" && method === "GET") return handleListAPIKeys(req, env, caller);
diff --git a/cloudflare-workers/api-edge/src/github_star.test.ts b/cloudflare-workers/api-edge/src/github_star.test.ts
new file mode 100644
index 00000000..3305fef7
--- /dev/null
+++ b/cloudflare-workers/api-edge/src/github_star.test.ts
@@ -0,0 +1,97 @@
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { handleGitHubStarClaim, handleGitHubStarStart, type GitHubStarEnv } from "./github_star";
+
+const orgID = "org-1";
+
+function setup(opts: { provider?: string; stars: number[]; autumnFails?: boolean }) {
+ const row = {
+ billing_provider: opts.provider ?? "autumn",
+ github_star_baseline: null as number | null,
+ github_star_bonus_at: null as number | null,
+ };
+ const db = {
+ prepare(sql: string) {
+ let args: unknown[] = [];
+ const stmt = {
+ bind(...a: unknown[]) { args = a; return stmt; },
+ async first() { return { ...row }; },
+ async run() {
+ let changes = 0;
+ if (sql.includes("SET github_star_baseline")) {
+ if (row.github_star_bonus_at === null) { row.github_star_baseline = args[0] as number; changes = 1; }
+ } else if (sql.includes("SET github_star_bonus_at = NULL")) {
+ row.github_star_bonus_at = null; changes = 1;
+ } else if (sql.includes("SET github_star_bonus_at")) {
+ if (row.github_star_bonus_at === null) { row.github_star_bonus_at = args[0] as number; changes = 1; }
+ }
+ return { meta: { changes } };
+ },
+ };
+ return stmt;
+ },
+ };
+ const tracks: unknown[] = [];
+ const stars = [...opts.stars];
+ vi.stubGlobal("fetch", vi.fn(async (url: string, init?: RequestInit) => {
+ if (url.startsWith("https://api.github.com/")) {
+ return new Response(JSON.stringify({ stargazers_count: stars.shift() }));
+ }
+ if (url.endsWith("/track")) {
+ tracks.push(JSON.parse(String(init?.body)));
+ if (opts.autumnFails) return new Response("boom", { status: 500 });
+ return new Response(JSON.stringify({ balance: { remaining: 15 } }));
+ }
+ return new Response("not found", { status: 404 });
+ }));
+ vi.spyOn(console, "error").mockImplementation(() => {});
+ const env = { OPENCOMPUTER_DB: db, AUTUMN_SECRET_KEY: "k" } as unknown as GitHubStarEnv;
+ return { env, row, tracks };
+}
+
+afterEach(() => {
+ vi.unstubAllGlobals();
+ vi.restoreAllMocks();
+});
+
+describe("github star bonus", () => {
+ it("grants $5 once the star count goes up, and only once", async () => {
+ const { env, row, tracks } = setup({ stars: [100, 101, 102] });
+ expect((await handleGitHubStarStart(env, orgID)).status).toBe(200);
+ expect(row.github_star_baseline).toBe(100);
+
+ const res = await handleGitHubStarClaim(env, orgID);
+ expect(await res.json()).toMatchObject({ claimed: true, eligible: false });
+ expect(tracks).toEqual([
+ expect.objectContaining({ customer_id: orgID, feature_id: "credits", value: -5, idempotency_key: `github-star-bonus-${orgID}` }),
+ ]);
+
+ await handleGitHubStarClaim(env, orgID);
+ expect(tracks).toHaveLength(1);
+ });
+
+ it("refuses while the count has not moved", async () => {
+ const { env, tracks } = setup({ stars: [100, 100] });
+ await handleGitHubStarStart(env, orgID);
+ expect((await handleGitHubStarClaim(env, orgID)).status).toBe(409);
+ expect(tracks).toHaveLength(0);
+ });
+
+ it("refuses a claim without a start", async () => {
+ const { env } = setup({ stars: [100] });
+ expect((await handleGitHubStarClaim(env, orgID)).status).toBe(409);
+ });
+
+ it("is not offered to orgs off Autumn", async () => {
+ const { env, row } = setup({ provider: "legacy", stars: [100] });
+ const res = await handleGitHubStarStart(env, orgID);
+ expect(await res.json()).toMatchObject({ eligible: false });
+ expect(row.github_star_baseline).toBeNull();
+ });
+
+ it("leaves the bonus claimable when Autumn fails", async () => {
+ const { env, row } = setup({ stars: [100, 101], autumnFails: true });
+ await handleGitHubStarStart(env, orgID);
+ expect((await handleGitHubStarClaim(env, orgID)).status).toBe(502);
+ expect(row.github_star_bonus_at).toBeNull();
+ });
+});
diff --git a/cloudflare-workers/api-edge/src/github_star.ts b/cloudflare-workers/api-edge/src/github_star.ts
new file mode 100644
index 00000000..2f9b84b8
--- /dev/null
+++ b/cloudflare-workers/api-edge/src/github_star.ts
@@ -0,0 +1,138 @@
+// github_star.ts — "Star us on GitHub, get $5" during onboarding.
+//
+// Verification is deliberately loose (Mohamed, 2026-11-11): the bonus is for
+// engagement and the trial is three days, so we do not tie a star to a GitHub
+// identity. Clicking "Star on GitHub" records the repo's stargazer count; the
+// claim succeeds once the count has gone up since. A fraudster can claim on
+// someone else's star, and that is fine. One bonus per org, Autumn orgs only.
+
+import { syncAutumnToD1, trackAutumnUsage, type AutumnSyncEnv } from "./autumn_webhook";
+
+export const GITHUB_STAR_REPO = "diggerhq/opencomputer";
+export const GITHUB_STAR_BONUS_USD = 5;
+
+export interface GitHubStarEnv extends AutumnSyncEnv {
+ OPENCOMPUTER_DB: D1Database;
+ AUTUMN_SECRET_KEY: string;
+ AUTUMN_BASE_URL?: string;
+ // Optional: any token that can read public repos. Unauthenticated calls
+ // share GitHub's 60/hour limit with everything else on Cloudflare's IP.
+ GITHUB_TOKEN?: string;
+}
+
+interface StarRow {
+ billing_provider: string;
+ github_star_baseline: number | null;
+ github_star_bonus_at: number | null;
+}
+
+export interface GitHubStarState {
+ eligible: boolean;
+ claimed: boolean;
+ started: boolean;
+ bonusUsd: number;
+ repoUrl: string;
+}
+
+function json(body: unknown, status = 200): Response {
+ return new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
+}
+
+async function readRow(env: GitHubStarEnv, orgID: string): Promise<StarRow | null> {
+ return env.OPENCOMPUTER_DB.prepare(
+ "SELECT billing_provider, github_star_baseline, github_star_bonus_at FROM orgs WHERE id = ?1",
+ ).bind(orgID).first<StarRow>();
+}
+
+function stateOf(row: StarRow): GitHubStarState {
+ return {
+ eligible: row.billing_provider === "autumn" && row.github_star_bonus_at === null,
+ claimed: row.github_star_bonus_at !== null,
+ started: row.github_star_baseline !== null,
+ bonusUsd: GITHUB_STAR_BONUS_USD,
+ repoUrl: `https://github.com/${GITHUB_STAR_REPO}`,
+ };
+}
+
+export async function stargazerCount(env: GitHubStarEnv): Promise<number> {
+ const headers: Record<string, string> = {
+ accept: "application/vnd.github+json",
+ "user-agent": "opencomputer-api-edge",
+ };
+ if (env.GITHUB_TOKEN) headers.authorization = `Bearer ${env.GITHUB_TOKEN}`;
+ const resp = await fetch(`https://api.github.com/repos/${GITHUB_STAR_REPO}`, { headers });
+ if (!resp.ok) throw new Error(`github repo ${resp.status}: ${await resp.text()}`);
+ const body = (await resp.json()) as { stargazers_count?: unknown };
+ if (typeof body.stargazers_count !== "number") throw new Error("github repo: no stargazers_count");
+ return body.stargazers_count;
+}
+
+// GET /github-star
+export async function handleGitHubStarState(env: GitHubStarEnv, orgID: string): Promise<Response> {
+ const row = await readRow(env, orgID);
+ if (!row) return json({ error: "org not found" }, 404);
+ return json(stateOf(row));
+}
+
+// POST /github-star/start — the person is off to GitHub; remember the count.
+export async function handleGitHubStarStart(env: GitHubStarEnv, orgID: string): Promise<Response> {
+ const row = await readRow(env, orgID);
+ if (!row) return json({ error: "org not found" }, 404);
+ if (!stateOf(row).eligible) return json(stateOf(row));
+ let count: number;
+ try {
+ count = await stargazerCount(env);
+ } catch (err) {
+ console.error(`github-star start ${orgID}`, err);
+ return json({ error: "couldn't reach GitHub" }, 502);
+ }
+ await env.OPENCOMPUTER_DB.prepare(
+ "UPDATE orgs SET github_star_baseline = ?1 WHERE id = ?2 AND github_star_bonus_at IS NULL",
+ ).bind(count, orgID).run();
+ return json(stateOf({ ...row, github_star_baseline: count }));
+}
+
+// POST /github-star/claim — grant the bonus once the count went up.
+export async function handleGitHubStarClaim(env: GitHubStarEnv, orgID: string): Promise<Response> {
+ const row = await readRow(env, orgID);
+ if (!row) return json({ error: "org not found" }, 404);
+ const state = stateOf(row);
+ if (!state.eligible) return json(state);
+ if (row.github_star_baseline === null) return json({ error: "star the repo first" }, 409);
+ let count: number;
+ try {
+ count = await stargazerCount(env);
+ } catch (err) {
+ console.error(`github-star claim ${orgID}`, err);
+ return json({ error: "couldn't reach GitHub" }, 502);
+ }
+ if (count <= row.github_star_baseline) return json({ error: "no new star yet" }, 409);
+
+ // Mark first so two concurrent claims grant once; Autumn's idempotency key
+ // backs that up across retries.
+ const now = Math.floor(Date.now() / 1000);
+ const marked = await env.OPENCOMPUTER_DB.prepare(
+ "UPDATE orgs SET github_star_bonus_at = ?1 WHERE id = ?2 AND github_star_bonus_at IS NULL",
+ ).bind(now, orgID).run();
+ if (!marked.meta.changes) return json(stateOf({ ...row, github_star_bonus_at: now }));
+ try {
+ // A negative track adds to the balance.
+ await trackAutumnUsage(env, {
+ customerID: orgID,
+ featureID: "credits",
+ value: -GITHUB_STAR_BONUS_USD,
+ idempotencyKey: `github-star-bonus-${orgID}`,
+ });
+ } catch (err) {
+ console.error(`github-star grant ${orgID}`, err);
+ await env.OPENCOMPUTER_DB.prepare("UPDATE orgs SET github_star_bonus_at = NULL WHERE id = ?1")
+ .bind(orgID).run();
+ return json({ error: "couldn't add the credits" }, 502);
+ }
+ try {
+ await syncAutumnToD1(env, orgID);
+ } catch (err) {
+ console.error(`github-star sync ${orgID}`, err);
+ }
+ return json(stateOf({ ...row, github_star_bonus_at: now }));
+}
diff --git a/web/src/api/client.ts b/web/src/api/client.ts
index 0cd97514..3dd75649 100644
--- a/web/src/api/client.ts
+++ b/web/src/api/client.ts
@@ -251,6 +251,25 @@ export const switchOrg = (orgId: string) =>
// Credits
export const getCredits = () => apiFetch('/org/credits', {}, S.CreditsSchema)
+// Onboarding "star us on GitHub" bonus (api-edge github_star.ts).
+const GitHubStarSchema = z.object({
+ eligible: z.boolean(),
+ claimed: z.boolean(),
+ started: z.boolean(),
+ bonusUsd: z.number(),
+ repoUrl: z.string(),
+})
+export type GitHubStar = z.infer<typeof GitHubStarSchema>
+
+export const getGitHubStar = () =>
+ apiFetch('/github-star', {}, GitHubStarSchema)
+
+export const startGitHubStar = () =>
+ apiFetch('/github-star/start', { method: 'POST' }, GitHubStarSchema)
+
+export const claimGitHubStar = () =>
+ apiFetch('/github-star/claim', { method: 'POST' }, GitHubStarSchema)
+
// Billing API
export const getBilling = () => apiFetch('/billing', {}, S.BillingStateSchema)
@@ -325,4 +344,3 @@ export const setAutumnAutoTopup = (cfg: {
method: 'POST',
body: JSON.stringify(cfg),
})
-
diff --git a/web/src/api/mock.ts b/web/src/api/mock.ts
index 8cc0b72a..1fb17f3c 100644
--- a/web/src/api/mock.ts
+++ b/web/src/api/mock.ts
@@ -187,6 +187,14 @@ const orgInvitations = [
type Handler = () => unknown
+let githubStar = {
+ eligible: true,
+ claimed: false,
+ started: false,
+ bonusUsd: 5,
+ repoUrl: 'https://github.com/diggerhq/opencomputer',
+}
+
// A handler may return NOT_FOUND to mimic a 404 (mockFetch throws, like a real
// missing resource). No handler uses it today.
const NOT_FOUND = Symbol('not_found')
@@ -804,6 +812,7 @@ const ROUTES: Array<[RegExp, Handler]> = [
}),
],
[/^\/api-keys$/, () => apiKeys],
+ [/^\/github-star$/, () => githubStar],
[/^\/billing\/autumn$/, () => autumnMock()],
[/^\/billing\/invoices/, () => ({ invoices: [] })],
[/^\/billing$/, () => billing],
@@ -815,6 +824,11 @@ const ROUTES: Array<[RegExp, Handler]> = [
// Mutations the preview needs to echo something parseable (e.g. the Slack
// wizard's POST …/slack/manifest → manifest+steps). Everything else 204-ish.
const POST_ROUTES: [RegExp, () => unknown][] = [
+ [/^\/github-star\/start$/, () => (githubStar = { ...githubStar, started: true })],
+ [
+ /^\/github-star\/claim$/,
+ () => (githubStar = { ...githubStar, eligible: false, claimed: true }),
+ ],
[/^\/managed-agents\/computer$/, previewComputer],
[
/^\/managed-agents\/computer\/slack\/install$/,
diff --git a/web/src/managed-agents/Computer.tsx b/web/src/managed-agents/Computer.tsx
index b8f3e24c..67dbf361 100644
--- a/web/src/managed-agents/Computer.tsx
+++ b/web/src/managed-agents/Computer.tsx
@@ -55,6 +55,7 @@ import { useTransientFlag } from '@/lib/use-transient-flag'
import { PixelScene } from './pixel-scene'
import { AuthContext } from '@/hooks/useAuth'
import { addManagedGitHubConnection } from './api'
+import { GitHubStarBonus } from './GitHubStarBonus'
import { launchAuthorizationWindow } from './authorization-window'
import { SlackInstallButton, UnlinkSlackDialog } from './computer-slack'
import {
@@ -988,11 +989,10 @@ function Setup({
</p>
</SetupItem>
</ol>
- <SetupContext
- step={step}
- agentCard={agentCard}
- className="xl:[grid-area:context]"
- />
+ <div className="flex flex-col gap-6 self-start xl:[grid-area:context]">
+ <SetupContext step={step} agentCard={agentCard} />
+ <GitHubStarBonus />
+ </div>
{/* The scene only uses height nobody else needs: its area is a size
container that adds nothing to the page (no row gap either), and
the scene shows when the space left fits it plus clearance. */}
diff --git a/web/src/managed-agents/GitHubStarBonus.tsx b/web/src/managed-agents/GitHubStarBonus.tsx
new file mode 100644
index 00000000..c267429f
--- /dev/null
+++ b/web/src/managed-agents/GitHubStarBonus.tsx
@@ -0,0 +1,85 @@
+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
+import { Loader2, Star } from 'lucide-react'
+import { ApiError } from '@/api/errors'
+import {
+ claimGitHubStar,
+ getGitHubStar,
+ startGitHubStar,
+ type GitHubStar,
+} from '@/api/client'
+import { Button } from '@/components/ui/button'
+import { notifyError, notifySuccess } from '@/lib/errors'
+
+const queryKey = ['github-star']
+
+/**
+ * "Star us on GitHub, get $5" beside setup. The check is loose on purpose:
+ * the edge only sees the repo's star count go up after the click.
+ */
+export function GitHubStarBonus() {
+ const queryClient = useQueryClient()
+ const star = useQuery({ queryKey, queryFn: getGitHubStar, retry: false })
+ const save = (next: GitHubStar) => queryClient.setQueryData(queryKey, next)
+
+ const start = useMutation({ mutationFn: startGitHubStar, onSuccess: save })
+ const claim = useMutation({
+ mutationFn: claimGitHubStar,
+ onSuccess: (next) => {
+ save(next)
+ if (!next.claimed) return
+ notifySuccess(
+ `$${next.bonusUsd} added to your credits. Thanks for the star!`,
+ )
+ void queryClient.invalidateQueries({ queryKey: ['autumn-billing'] })
+ },
+ onError: (error) =>
+ notifyError(
+ error instanceof ApiError && error.status === 409
+ ? "We don't see your star yet. Give GitHub a few seconds and try again."
+ : "Couldn't add the credits.",
+ error,
+ ),
+ })
+
+ const data = star.data
+ if (!data?.eligible) return null
+ return (
+ <div className="bg-panel rounded-xl border p-5 text-sm shadow-sm">
+ <h2 className="flex items-center gap-2 font-semibold">
+ <Star className="size-4 fill-amber-400 text-amber-400" aria-hidden />
+ Get ${data.bonusUsd} in credits
+ </h2>
+ <p className="text-muted-foreground mt-2">
+ Star OpenComputer on GitHub and we add ${data.bonusUsd} to your trial.
+ </p>
+ <div className="mt-4 flex flex-wrap gap-2">
+ <Button
+ variant={data.started ? 'outline' : 'default'}
+ size="sm"
+ asChild
+ >
+ <a
+ href={data.repoUrl}
+ target="_blank"
+ rel="noreferrer"
+ onClick={() => start.mutate()}
+ >
+ Star on GitHub
+ </a>
+ </Button>
+ {data.started ? (
+ <Button
+ size="sm"
+ disabled={claim.isPending}
+ onClick={() => claim.mutate()}
+ >
+ {claim.isPending ? (
+ <Loader2 className="size-4 animate-spin" aria-hidden />
+ ) : null}
+ I starred it
+ </Button>
+ ) : null}
+ </div>
+ </div>
+ )
+}