Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
209 linesCodeBlameRaw
1/**
2 * The parts of g1t the page lists, and how each is checked. Every address
3 * comes from the Worker's vars, so an installation of its own names its own
4 * hosts; a part whose address is empty is not part of that installation
5 * and is left off the page.
6 *
7 * Checks go over the public internet, as people reach g1t, so they measure
8 * what people see. Billing has no public address of its own, so it is the
9 * one part checked through a service binding, when there is one.
10 */
11
12/** The Worker's vars that say where things are. */
13export type Targets = {
14 /** The site: `https://g1t.sh`. */
15 SITE_URL: string;
16 /** The API: `https://api.g1t.sh`. */
17 API_URL: string;
18 MCP_URL: string;
19 DOCS_URL: string;
20 /** Where deployed apps live: `https://g1t.page`. */
21 PAGES_URL: string;
22 /** A public repository that always exists, `owner/name`, to fetch refs of. */
23 PROBE_REPO: string;
24 /** The site as browsers reach it, when the checks reach it another way. */
25 PUBLIC_SITE_URL?: string;
26};
27
28/** One request a check makes, and the answer that means the part works. */
29export type Step = {
30 url: string;
31 headers?: Record<string, string>;
32 /** The status that means it works; any 2xx when absent. */
33 expect?: number;
34 /**
35 * A page people open in a browser: asked for with a browser's user agent
36 * (probe.ts `BROWSER_USER_AGENT`), so the site streams it as it does for
37 * people, and the time is to the first byte, not to a crawler's full render.
38 */
39 browser?: boolean;
40};
41
42export type Check =
43 | { kind: "http"; steps: Step[] }
44 /** Billing, through its binding: reading its price book. */
45 | { kind: "billing" }
46 /** Git storage, through the repos service binding: how the store answered lately. */
47 | { kind: "storage" }
48 /** No check yet: the page says so rather than showing green. */
49 | { kind: "none" };
50
51export type ComponentInfo = {
52 key: string;
53 name: string;
54 address: string;
55 checks: string;
56 /** Whether g1t as a whole is down when this is. */
57 core: boolean;
58 check: Check;
59 /** Slower than this, it counts as degraded; `SLOW_MS` when absent. */
60 slowMs?: number;
61};
62
63/**
64 * The page-speed budget the status page holds the site to: the slower of a
65 * public project page and Explore, to the first byte of the answer, from a
66 * Cloudflare data centre. CONTRIBUTING.md, "Speed", has the site's targets.
67 */
68export const SPEED_BUDGET_MS = 800;
69
70/** A token no one holds: the API asks identity about it and refuses it. */
71export const NO_TOKEN = `g1t_${"0".repeat(40)}`;
72
73function host(url: string): string {
74 try {
75 return new URL(url).host;
76 } catch {
77 return url;
78 }
79}
80
81const trim = (url: string | undefined) => (url ?? "").trim().replace(/\/+$/, "");
82
83/** Git storage counts as degraded when its calls took longer than this on average. */
84export const STORAGE_SLOW_MS = 1500;
85
86/** The parts, in the order the page lists them. `storage`: whether the repos service is bound. */
87export function components(vars: Partial<Targets>, billing = true, storage = false): ComponentInfo[] {
88 const site = trim(vars.SITE_URL);
89 const api = trim(vars.API_URL);
90 const mcp = trim(vars.MCP_URL);
91 const docs = trim(vars.DOCS_URL);
92 const pages = trim(vars.PAGES_URL);
93 const repo = (vars.PROBE_REPO ?? "").trim();
94 // What the page shows as the site's address: where people reach it.
95 const shown = host(trim(vars.PUBLIC_SITE_URL) || site);
96 const list: (ComponentInfo | null)[] = [
97 site
98 ? {
99 key: "site",
100 name: "Website and sign-in",
101 address: shown,
102 checks: api
103 ? "The sign-in page loading, and the account service answering an access token through the API."
104 : "The sign-in page loading.",
105 core: true,
106 check: {
107 kind: "http",
108 steps: [
109 { url: `${site}/login`, browser: true },
110 ...(api ? [{ url: `${api}/v1/user`, headers: { authorization: `Bearer ${NO_TOKEN}` }, expect: 401 }] : []),
111 ],
112 },
113 }
114 : null,
115 api
116 ? {
117 key: "api",
118 name: "API",
119 address: host(api),
120 checks: "The API's front page.",
121 core: true,
122 check: { kind: "http", steps: [{ url: `${api}/` }] },
123 }
124 : null,
125 site && repo
126 ? {
127 key: "git",
128 name: "Git and repositories",
129 address: `${shown}/<owner>/<repo>.git`,
130 checks: "Listing the branches of a public repository over HTTPS, the first step of every clone.",
131 core: true,
132 check: { kind: "http", steps: [{ url: `${site}/${repo}.git/info/refs?service=git-upload-pack` }] },
133 }
134 : null,
135 storage && site
136 ? {
137 key: "storage",
138 name: "Git storage",
139 address: "Where every repository is kept",
140 checks: `How g1t's git storage answered over the last five minutes, as g1t saw it: failures, rate limits, and how long calls took. Rate limited, or slower than ${STORAGE_SLOW_MS} ms on average, counts as degraded.`,
141 core: false,
142 check: { kind: "storage" },
143 slowMs: STORAGE_SLOW_MS,
144 }
145 : null,
146 site && repo
147 ? {
148 key: "speed",
149 name: "Page speed",
150 address: `${shown}/${repo}`,
151 checks: `A public project page and Explore each answering within ${SPEED_BUDGET_MS} ms. Slower counts as degraded.`,
152 core: false,
153 check: { kind: "http", steps: [{ url: `${site}/${repo}`, browser: true }, { url: `${site}/explore`, browser: true }] },
154 slowMs: SPEED_BUDGET_MS,
155 }
156 : null,
157 mcp
158 ? {
159 key: "mcp",
160 name: "MCP server",
161 address: host(mcp),
162 checks: "The MCP server's description.",
163 core: false,
164 check: { kind: "http", steps: [{ url: `${mcp}/`, headers: { accept: "application/json" } }] },
165 }
166 : null,
167 docs
168 ? {
169 key: "docs",
170 name: "Documentation",
171 address: host(docs),
172 checks: "The documentation's front page.",
173 core: false,
174 check: { kind: "http", steps: [{ url: `${docs}/` }] },
175 }
176 : null,
177 pages
178 ? {
179 key: "deployments",
180 name: "Deployments",
181 address: `*.${host(pages)}`,
182 checks: `${host(pages)} answering. Each deployed app is not checked one by one.`,
183 core: false,
184 check: { kind: "http", steps: [{ url: `${pages}/` }] },
185 }
186 : null,
187 pages
188 ? {
189 key: "sandboxes",
190 name: "Sandboxes",
191 address: "Checks, workflows and builds",
192 checks: "Starting a sandbox costs money and takes seconds, so it is not checked from here yet.",
193 core: false,
194 check: { kind: "none" },
195 }
196 : null,
197 billing && site
198 ? {
199 key: "billing",
200 name: "Billing",
201 address: `${shown}/<workspace>/-/billing`,
202 checks: "The billing service reading its price book. Stripe itself is not checked.",
203 core: false,
204 check: { kind: "billing" },
205 }
206 : null,
207 ];
208 return list.filter((c): c is ComponentInfo => c != null);
209}