Skip to content
685 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays1import type { ReactNode } from "react";
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing2import { Link } from "react-router";
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily3
Merge platform pause and the hourly usage watcher: staff can pause compute, schedules, indexing or renders for everyone, the watcher emails on a breach and is never blind quietly, and the models proxy holds each run to its cap (billing 0051, integrations 0006)4import type { CostsReport, PlatformGuard, PlatformMetric } from "@g1t/contracts";
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily5
6import type { Route } from "./+types/costs";
7import { DaysChart } from "~/components/costs";
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing8import { CostsHeader, chip, costsHref } from "~/components/costs-header";
9import { Badge, Button, Field, Input, Notice, Section, Stat, When } from "~/components/ui";
Merge platform pause and the hourly usage watcher: staff can pause compute, schedules, indexing or renders for everyone, the watcher emails on a breach and is never blind quietly, and the models proxy holds each run to its cap (billing 0051, integrations 0006)10import { PAUSE_LEVELS, capPercent, count, daySeries, marginOnPrice, marginTone, parseBucket, percentLabel, spendRows, subscriptionsOver, thresholdShare, whoPaid } from "~/lib/costs";
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing11import { type CostsActionResult, costsAction, costsLoader } from "~/lib/costs-route.server";
12import { usd } from "~/lib/money";
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily13
14export const meta: Route.MetaFunction = () => [{ title: "Costs & margin · sudo" }, { name: "robots", content: "noindex, nofollow" }];
15
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises16/** Billing's MARGIN_PERCENT: what is added to cost. */
17const MARKUP_PERCENT = 20;
18
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing19export const loader = ({ request, context }: Route.LoaderArgs) => costsLoader(request, context);
20export const action = ({ request, context }: Route.ActionArgs) => costsAction(request, context);
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily21
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing22/**
23 * Where g1t's money goes: the statement, what g1t pays for itself against
24 * its caps, and the same by day, by product and by workspace.
25 */
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily26export default function Costs({ loaderData, actionData }: Route.ComponentProps) {
27 const { range, report, error, done } = loaderData;
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing28 const failed = actionData && "error" in actionData ? (actionData as CostsActionResult) : null;
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises29 const description = `What g1t cost to run (Cloudflare's bill and the model providers') against what workspaces paid, with what g1t gave away on purpose kept apart. Prices are cost plus ${MARKUP_PERCENT}%, a ${percentLabel(marginOnPrice(MARKUP_PERCENT))} margin: every margin here is a share of the price, not of the cost. The bill itself, drift and the price book are on Bill & pricing.`;
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily30 if (!report) {
31 return (
32 <main className="mx-auto max-w-6xl px-4 py-8 sm:py-10">
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing33 <CostsHeader page="costs" range={range} report={null} done={null} runError={null} description={description} />
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily34 <div className="mt-5">
35 <Notice tone="warn">Billing did not answer for costs: {error}</Notice>
36 </div>
Merge platform pause and the hourly usage watcher: staff can pause compute, schedules, indexing or renders for everyone, the watcher emails on a breach and is never blind quietly, and the models proxy holds each run to its cap (billing 0051, integrations 0006)37 <PlatformSection guard={loaderData.guard} unavailable={loaderData.guardError} failed={failed} />
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily38 </main>
39 );
40 }
41 const bucket = parseBucket(loaderData.bucket, report.products.map((p) => p.bucket));
42 const product = report.products.find((p) => p.bucket === bucket) ?? null;
43 const series = daySeries(report.days, report.since, report.until, bucket);
44 const floor = report.settings.marginFloorPercent;
45 const open = report.proposals.filter((p) => p.status === "open");
46 return (
47 <main className="mx-auto max-w-6xl px-4 py-8 sm:py-10">
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing48 <CostsHeader page="costs" range={range} report={report} done={done} runError={failed?.section === "run" ? failed.error : null} description={description} />
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily49
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running50 <Statement report={report} floor={floor} range={range} proposals={open.length} />
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily51
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises52 <SpendSection caps={report.caps} range={range} error={failed?.section === "lift" ? failed.error : null} />
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays53
Merge platform pause and the hourly usage watcher: staff can pause compute, schedules, indexing or renders for everyone, the watcher emails on a breach and is never blind quietly, and the models proxy holds each run to its cap (billing 0051, integrations 0006)54 <PlatformSection guard={loaderData.guard} unavailable={loaderData.guardError} failed={failed} />
55
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily56 <Section
57 className="mt-6"
58 title={product ? `${product.title}, by day` : "By day"}
59 description={
60 product
61 ? "What customers were charged for it at price, before included usage and pools paid part, against what it cost."
62 : "Money in (usage paid for and the plan) against every cost. Pick a product to see its own."
63 }
64 >
65 <nav aria-label="Product" className="mb-4 flex flex-wrap gap-2">
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing66 <Link to={costsHref("costs", range, null)} aria-current={!bucket ? "page" : undefined} className={chip(!bucket)}>
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily67 All of g1t
68 </Link>
69 {report.products.map((p) => (
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing70 <Link key={p.bucket} to={costsHref("costs", range, p.bucket)} aria-current={p.bucket === bucket ? "page" : undefined} className={chip(p.bucket === bucket)}>
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily71 {p.title}
72 </Link>
73 ))}
74 </nav>
75 <DaysChart
76 days={series}
77 floor={floor}
78 revenueLabel={product ? "Charged at price" : "Money in"}
79 label={product ? `${product.title}: charged against Cloudflare cost by day` : "Money in against Cloudflare cost by day"}
80 />
81 </Section>
82
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises83 <Section
84 className="mt-6"
85 title="By product"
86 description={`Each of g1t's products over the last ${range} days: what customers were charged at price, given away or not, against what it cost. The margin is the charge less the cost, as a share of the charge; at cost plus ${MARKUP_PERCENT}% it is ${percentLabel(marginOnPrice(MARKUP_PERCENT))}. The floor is ${floor}%.`}
87 >
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily88 <div className="-mx-4 overflow-x-auto sm:-mx-5">
89 <table className="w-full min-w-[44rem] text-sm">
90 <thead>
91 <tr className="border-b border-line text-left text-xs text-muted">
92 <th className="px-4 py-2 font-medium sm:px-5">Product</th>
93 <th className="px-4 py-2 text-right font-medium">Charged at price</th>
94 <th className="px-4 py-2 text-right font-medium">Cost</th>
95 <th className="px-4 py-2 text-right font-medium">Price book said</th>
96 <th className="px-4 py-2 text-right font-medium">Margin</th>
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises97 <th className="px-4 py-2 text-right font-medium sm:pr-5">% of price</th>
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily98 </tr>
99 </thead>
100 <tbody>
101 {report.products.map((p) => {
102 const tone = p.overhead ? undefined : marginTone(p.marginPercent, floor);
103 return (
104 <tr key={p.bucket} className="border-b border-line last:border-0">
105 <td className="px-4 py-2.5 sm:px-5">
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing106 <Link to={costsHref("costs", range, p.bucket)} className="text-fg hover:underline">
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily107 {p.title}
108 </Link>
109 <span className="block text-xs text-faint">
110 {p.overhead ? "Paid by the plan" : p.costSource === "ledger" ? "Cost from the gateway, not Cloudflare" : p.bucket}
111 </span>
112 </td>
113 <td className="tabular px-4 py-2.5 text-right">{usd(p.valueMicros)}</td>
114 <td className="tabular px-4 py-2.5 text-right">{usd(p.costMicros)}</td>
115 <td className="tabular px-4 py-2.5 text-right text-muted">{usd(p.ownCostMicros)}</td>
116 <td className={`tabular px-4 py-2.5 text-right ${p.marginMicros < 0 && !p.overhead ? "text-danger" : ""}`}>{usd(p.marginMicros)}</td>
117 <td className="px-4 py-2.5 text-right sm:pr-5">
118 {p.overhead ? (
119 <span className="text-faint">—</span>
120 ) : (
121 <Badge tone={tone === "mint" ? "mint" : tone === "warn" ? "warn" : tone === "danger" ? "danger" : "plain"}>{percentLabel(p.marginPercent)}</Badge>
122 )}
123 </td>
124 </tr>
125 );
126 })}
127 </tbody>
128 </table>
129 </div>
130 </Section>
131
132 <Section
133 className="mt-6"
134 title="Workspaces that cost most"
135 description="Cloudflare's costs shared out by each workspace's own meters (its git operations, its usage), against what it paid. Over its revenue for 30 days, a workspace shows on Reach out."
136 >
137 {report.topWorkspaces.length === 0 ? (
138 <p className="text-sm text-muted">No costs shared out yet.</p>
139 ) : (
140 <div className="-mx-4 overflow-x-auto sm:-mx-5">
141 <table className="w-full min-w-[34rem] text-sm">
142 <thead>
143 <tr className="border-b border-line text-left text-xs text-muted">
144 <th className="px-4 py-2 font-medium sm:px-5">Workspace</th>
145 <th className="px-4 py-2 text-right font-medium">Cost to g1t</th>
Costs: margin is measured on what was sold; comped workspaces, free periods, the trial and the pools are given away, a budget shown beside it146 <th className="px-4 py-2 text-right font-medium">Given away</th>
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily147 <th className="px-4 py-2 text-right font-medium">Paid</th>
148 <th className="px-4 py-2 text-right font-medium sm:pr-5">Net</th>
149 </tr>
150 </thead>
151 <tbody>
152 {report.topWorkspaces.map((w) => {
153 const net = w.revenueMicros - w.costMicros;
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises154 // What was given away on purpose is a budget, not a loss:
155 // red only for what neither paid nor was given.
156 const lost = net + (w.givenMicros ?? 0) < 0;
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily157 return (
158 <tr key={w.workspace} className="border-b border-line last:border-0">
159 <td className="px-4 py-2.5 sm:px-5">
160 <Link to={`/workspaces/${encodeURIComponent(w.workspace)}#billing`} className="font-mono text-fg hover:underline">
161 {w.workspace}
162 </Link>
163 {w.internal && <span className="ml-2 text-xs text-faint">g1t's own</span>}
164 </td>
165 <td className="tabular px-4 py-2.5 text-right">{usd(w.costMicros)}</td>
Costs: margin is measured on what was sold; comped workspaces, free periods, the trial and the pools are given away, a budget shown beside it166 <td className="tabular px-4 py-2.5 text-right text-fg-soft">{usd(w.givenMicros ?? 0)}</td>
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily167 <td className="tabular px-4 py-2.5 text-right">{usd(w.revenueMicros)}</td>
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises168 <td className={`tabular px-4 py-2.5 text-right sm:pr-5 ${lost && !w.internal ? "text-danger" : "text-fg-soft"}`}>{usd(net)}</td>
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily169 </tr>
170 );
171 })}
172 </tbody>
173 </table>
174 </div>
175 )}
176 </Section>
177
178 </main>
179 );
180}
181
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays182function CapMeter({ label, used, cap, hint }: { label: string; used: number; cap: number; hint: ReactNode }) {
183 const percent = capPercent(used, cap);
Merge branch 'worktree-agent-ad7c6d88d93adc817'184 const tone = cap > 0 && used >= cap ? "bg-danger" : percent >= 75 ? "bg-warn" : "bg-accent";
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays185 return (
186 <div className="rounded-md border border-line px-4 py-3">
187 <div className="flex flex-wrap items-baseline justify-between gap-2">
188 <span className="text-sm font-medium">{label}</span>
189 <span className="tabular text-sm">
190 {usd(used)} <span className="text-faint">of {cap > 0 ? usd(cap) : "no cap"}</span>
191 </span>
192 </div>
193 <div className="mt-2 h-1.5 overflow-hidden rounded-full bg-line" role="meter" aria-valuemin={0} aria-valuemax={100} aria-valuenow={Math.round(percent)} aria-label={label}>
194 <div className={`h-full ${tone}`} style={{ width: `${percent}%` }} />
195 </div>
196 <p className="mt-1.5 text-xs text-muted">{hint}</p>
197 </div>
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running198 );
199}
200
201/**
202 * Where the money went, as a short statement: usage sold and running g1t
203 * (each against what paid for it), what g1t gave away on purpose (a budget,
204 * never a loss), and who was paid.
205 */
206function Statement({ report, floor, range, proposals }: { report: CostsReport; floor: number; range: number; proposals: number }) {
207 const o = report.overall;
208 // Reports from before the statement have only the totals.
209 const given = o.givenMicros ?? 0;
210 const usageCost = o.usageCostMicros ?? o.costMicros - given;
Costs: the plan's included usage counts as paid for the usage it covered, out of what plans leave for running g1t; the run button shows it is running with CSS alone (sudo ships no JavaScript)211 const included = o.includedMicros ?? 0;
212 const usageIn = o.usageMicros + included;
213 const usageMargin = o.usageMarginMicros ?? usageIn - usageCost;
sudo: a billing reset runs the costs analysis again so every figure is fresh; every submit button shows it is working (CSS only); no margin percentage on less than a cent sold214 // Under a cent sold, a percentage says nothing (a few micros against none).
215 const soldSomething = usageIn >= 10_000;
216 const usagePercent = soldSomething && o.usageMarginPercent !== undefined ? o.usageMarginPercent : null;
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running217 const running = o.runningCostMicros ?? 0;
218 const unmapped = o.unmappedCostMicros ?? 0;
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises219 // Cloudflare's subscriptions are not on the usage bill: a month's, over the range.
220 const subscriptions = subscriptionsOver(report.caps.fixedMonthlyMicros, range);
221 const paid = whoPaid(o, subscriptions);
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running222 const moneyIn = o.usageMicros + o.plansMicros;
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises223 const spent = paid.totalMicros;
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running224 const net = moneyIn - spent;
225 const givenParts = [
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging226 ["100% discounts", o.givenCompedMicros ?? 0],
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running227 ["free use", o.givenFreeMicros ?? 0],
228 ["trial", o.givenTrialMicros ?? 0],
229 ["open-source pool", o.givenPoolMicros ?? 0],
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging230 ["partial discounts", o.givenDiscountMicros ?? 0],
231 ["promotional credit", o.givenCreditPromotionalMicros ?? 0],
232 ["goodwill credit", o.givenCreditGoodwillMicros ?? 0],
Merge branch 'main' into worktree-agent-a69aeabc4b0deeb97233 ["testing resets", o.givenResetMicros ?? 0],
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running234 ].filter(([, micros]) => (micros as number) > 0) as [string, number][];
235 const rows: { title: string; note: string; in: number | null; cost: number; result: number | null; tone?: "danger" | "warn" | "muted" }[] = [
236 {
237 title: "Usage sold",
Costs: the plan's included usage counts as paid for the usage it covered, out of what plans leave for running g1t; the run button shows it is running with CSS alone (sudo ships no JavaScript)238 note:
239 included > 0
sudo: the costs statement reads to the cent240 ? `What workspaces paid for usage (${usd(o.usageMicros, { cents: true })}) and their plan's included usage (${usd(included, { cents: true })}), against what it cost`
Costs: the plan's included usage counts as paid for the usage it covered, out of what plans leave for running g1t; the run button shows it is running with CSS alone (sudo ships no JavaScript)241 : "What workspaces paid for usage, against what that usage cost",
242 in: usageIn,
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running243 cost: usageCost,
244 result: usageMargin,
245 tone: usageMargin < 0 ? "danger" : undefined,
246 },
247 {
248 title: "Running g1t",
Costs: the plan's included usage counts as paid for the usage it covered, out of what plans leave for running g1t; the run button shows it is running with CSS alone (sudo ships no JavaScript)249 note:
250 included > 0
sudo: the costs statement reads to the cent251 ? `Plans (${usd(o.plansMicros, { cents: true })}) less the included usage they paid for, against Workers, D1, KV, Queues and the rest`
Costs: the plan's included usage counts as paid for the usage it covered, out of what plans leave for running g1t; the run button shows it is running with CSS alone (sudo ships no JavaScript)252 : "Plans, against Workers, D1, KV, Queues and the rest of the platform",
253 in: o.plansMicros - included,
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running254 cost: running,
Costs: the plan's included usage counts as paid for the usage it covered, out of what plans leave for running g1t; the run button shows it is running with CSS alone (sudo ships no JavaScript)255 result: o.plansMicros - included - running,
256 tone: o.plansMicros - included - running < 0 ? "warn" : undefined,
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running257 },
258 {
259 title: "Cloudflare subscriptions",
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing260 note:
261 report.caps.fixedSource === "cloudflare"
262 ? `Fixed, as Cloudflare lists them${(report.caps.fixedItems ?? []).length > 0 ? ` (${(report.caps.fixedItems ?? []).map((i) => i.name).join(", ")})` : ""}; not on the usage bill`
263 : "Fixed, an estimate (CLOUDFLARE_FIXED_MONTHLY_MICROS) until Cloudflare's list is read; not on the usage bill",
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running264 in: null,
265 cost: subscriptions,
266 result: -subscriptions,
267 tone: "muted",
268 },
269 ...(unmapped > 0
270 ? [{ title: "Not mapped", note: "Billed by Cloudflare, charged for by nothing yet", in: null, cost: unmapped, result: -unmapped, tone: "danger" as const }]
271 : []),
272 {
273 title: "Given away",
sudo: the costs statement reads to the cent274 note: givenParts.length > 0 ? givenParts.map(([why, micros]) => `${why} ${usd(micros, { cents: true })}`).join(" · ") : "Nothing this range",
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running275 in: null,
276 cost: given,
277 result: null,
278 tone: "muted",
279 },
280 ];
281 const resultClass = (tone?: string) => (tone === "danger" ? "text-danger" : tone === "warn" ? "text-warn" : tone === "muted" ? "text-muted" : "text-fg");
282 return (
283 <>
284 <div className="mt-5 grid grid-cols-2 gap-3 lg:grid-cols-4">
285 <Stat
286 label="Margin on usage sold"
287 value={percentLabel(usagePercent)}
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises288 hint={
289 soldSomething
290 ? `Of the price: ${usd(usageIn, { cents: true })} paid for usage that cost ${usd(usageCost, { cents: true })}`
291 : "No usage sold in this range"
292 }
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running293 tone={marginTone(usagePercent, floor)}
294 />
295 <Stat
296 label="Given away on purpose"
sudo: the costs statement reads to the cent297 value={usd(given, { cents: true })}
298 hint={givenParts.length > 0 ? givenParts.map(([why, micros]) => `${usd(micros, { cents: true })} ${why}`).join(", ") : "Nothing given this range"}
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running299 />
300 <Stat
301 label="Who g1t paid"
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises302 value={usd(paid.totalMicros, { cents: true })}
303 hint={`Cloudflare's usage ${usd(paid.cloudflareMicros, { cents: true })} and subscriptions ${usd(paid.subscriptionsMicros, { cents: true })}, model providers ${usd(paid.modelsMicros, { cents: true })}; the cost in All in`}
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running304 />
305 <Stat
306 label="Proposals waiting"
307 value={String(proposals)}
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing308 hint={
309 <>
310 <Link to={costsHref("bill", range) + "#proposals"} className="underline underline-offset-2">
311 On Bill &amp; pricing
312 </Link>
313 {report.fetchedAt ? (
314 <>
315 {" "}
316 · bill read <When at={report.fetchedAt} time />
317 </>
318 ) : (
319 " · the bill has not been read yet"
320 )}
321 </>
322 }
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running323 tone={proposals > 0 ? "warn" : undefined}
324 />
325 </div>
326 <div className="mt-3 overflow-x-auto rounded-lg border border-line bg-surface">
327 <table className="w-full min-w-[36rem] text-sm">
328 <thead>
329 <tr className="border-b border-line text-left text-xs text-muted">
330 <th className="px-4 py-2 font-medium sm:px-5">
331 {report.since} to {report.until}
332 </th>
333 <th className="px-4 py-2 text-right font-medium">Paid in</th>
334 <th className="px-4 py-2 text-right font-medium">Cost</th>
335 <th className="px-4 py-2 text-right font-medium sm:pr-5">Result</th>
336 </tr>
337 </thead>
338 <tbody>
339 {rows.map((row) => (
340 <tr key={row.title} className="border-b border-line">
341 <td className="px-4 py-2.5 sm:px-5">
342 <span className="text-fg">{row.title}</span>
343 <span className="block text-xs text-faint">{row.note}</span>
344 </td>
sudo: the costs statement reads to the cent345 <td className="tabular px-4 py-2.5 text-right">{row.in == null ? <span className="text-faint">—</span> : usd(row.in, { cents: true })}</td>
346 <td className="tabular px-4 py-2.5 text-right">{usd(row.cost, { cents: true })}</td>
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running347 <td className={`tabular px-4 py-2.5 text-right sm:pr-5 ${resultClass(row.tone)}`}>
sudo: the costs statement reads to the cent348 {row.result == null ? "a budget" : usd(row.result, { signed: true, cents: true })}
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running349 </td>
350 </tr>
351 ))}
352 <tr>
353 <td className="px-4 py-2.5 sm:px-5">
354 <span className="font-medium text-fg">All in</span>
355 <span className="block text-xs text-faint">
sudo: the costs statement reads to the cent356 {given > 0 ? `${usd(given, { cents: true })} of the cost was given away on purpose; without it, ${usd(net + given, { signed: true, cents: true })}` : "Everything above"}
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running357 </span>
358 </td>
sudo: the costs statement reads to the cent359 <td className="tabular px-4 py-2.5 text-right font-medium">{usd(moneyIn, { cents: true })}</td>
360 <td className="tabular px-4 py-2.5 text-right font-medium">{usd(spent, { cents: true })}</td>
361 <td className="tabular px-4 py-2.5 text-right font-medium text-fg sm:pr-5">{usd(net, { signed: true, cents: true })}</td>
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running362 </tr>
363 </tbody>
364 </table>
365 </div>
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging366 <p className="mt-2 text-xs text-faint">
367 Credits from g1t, {report.since} to {report.until}: {usd(o.creditsGivenMicros ?? 0, { cents: true })} given, {usd(o.creditsUsedMicros ?? 0, { cents: true })}{" "}
368 spent on usage. What promotional and goodwill credit paid for is given away above, never money in; refunds took{" "}
369 {usd(o.creditsRefundedMicros ?? 0, { cents: true })} off money in on the days they refund.{" "}
370 <Link to="/credits" className="underline underline-offset-2">
371 Every credit
372 </Link>
373 </p>
Merge Stripe Tax, the card fee on card payments, and one free workspace per person374 <dl className="mt-3 grid grid-cols-2 gap-3 rounded-lg border border-line bg-surface px-4 py-3 text-sm sm:px-5">
375 <div>
376 <dt className="text-xs text-muted">Tax collected</dt>
377 <dd className="tabular text-fg">{usd(o.taxCollectedMicros ?? 0, { cents: true })}</dd>
378 <dd className="text-xs text-faint">Owed to tax authorities; never in money in or margin. Filed from Stripe Tax.</dd>
379 </div>
380 <div>
381 <dt className="text-xs text-muted">Card fees passed on</dt>
382 <dd className="tabular text-fg">{usd(o.cardFeesMicros ?? 0, { cents: true })}</dd>
383 <dd className="text-xs text-faint">Paid Stripe&apos;s card fees; not revenue either.</dd>
384 </div>
385 </dl>
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running386 </>
387 );
388}
389
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises390function SpendSection({ caps, range, error }: { caps: CostsReport["caps"]; range: number; error: string | null }) {
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays391 const { rows, totalMicros } = spendRows(caps);
392 const net = caps.revenueMicros - totalMicros;
393 return (
394 <Section
395 className="mt-6"
396 id="spend"
397 title="g1t's own spend"
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises398 description="What g1t pays for itself this calendar month, today included: accounts on a 100% discount, the trial and open-source pools, free workspaces' overruns, and usage charged without real money behind it. Each is what the work cost g1t, never its price, counted as each charge settled: the model providers' cost, and the price book's cost of sandboxes and builds. Two caps hold it: each 100%-discount account's monthly budget, and a daily breaker on all of it that pauses new hosted-model agent runs g1t would pay for."
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays399 >
400 <div className="grid gap-3 lg:grid-cols-2">
401 <CapMeter
402 label={`Today, ${caps.day} (UTC)`}
403 used={caps.todayMicros}
404 cap={caps.dailyCapMicros}
405 hint={
406 caps.tripped ? (
407 <span className="text-danger">
408 Breaker open{caps.trippedAt ? <> since <When at={caps.trippedAt} time /></> : null}: new hosted-model runs g1t pays for wait until 00:00 UTC.
409 </span>
410 ) : caps.liftedBy ? (
411 <>
412 Lifted for today by {caps.liftedBy}
413 {caps.liftNote ? `: “${caps.liftNote}”` : ""}.
414 </>
415 ) : (
416 "Paying workspaces on a live card are never paused. PLATFORM_DAILY_SPEND_CAP_MICROS."
417 )
418 }
419 />
420 {caps.comped.map((b) => (
421 <CapMeter
422 key={b.account}
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging423 label={`${b.name}, ${caps.month} (100% discount)`}
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays424 used={b.usedMicros}
425 cap={b.ceilingMicros}
426 hint={
427 <>
428 {b.ceilingMicros > 0 && b.usedMicros >= b.ceilingMicros ? (
429 <span className="text-danger">Used up: new work on it is refused. </span>
430 ) : null}
431 {b.defaultCeiling ? "The default budget (COMPED_MONTHLY_CEILING_MICROS)" : "Its own budget, in its terms"}. Raise it on{" "}
432 <Link to={`/workspaces/${encodeURIComponent(b.name)}#billing`} className="underline underline-offset-2">
433 its account
434 </Link>
435 : Terms, Limit.
436 </>
437 }
438 />
439 ))}
440 </div>
441 {(caps.tripped || error) && (
442 <form method="post" action="#spend" className="mt-4 flex flex-col gap-2 sm:flex-row sm:items-end">
443 <input type="hidden" name="intent" value="lift" />
444 <Field label="Why lift it" hint="Recorded in the audit log.">
445 <Input name="note" required minLength={5} maxLength={500} placeholder="e.g. Launch day; watching it" className="sm:min-w-[24rem]" />
446 </Field>
447 <Button type="submit" variant="danger">
448 Lift for today
449 </Button>
450 </form>
451 )}
452 {error && (
453 <div className="mt-3">
454 <Notice tone="error">{error}</Notice>
455 </div>
456 )}
457 <div className="-mx-4 mt-5 overflow-x-auto sm:-mx-5">
458 <table className="w-full min-w-[34rem] text-sm">
459 <thead>
460 <tr className="border-b border-line text-left text-xs text-muted">
461 <th className="px-4 py-2 font-medium sm:px-5">{caps.month}, so far</th>
462 <th className="px-4 py-2 text-right font-medium sm:pr-5">g1t paid</th>
463 </tr>
464 </thead>
465 <tbody>
466 {rows.map((row) => (
467 <tr key={row.key} className="border-b border-line align-top">
468 <td className="px-4 py-2.5 sm:px-5">
469 {row.title}
470 <span className="block text-xs text-faint">{row.note}</span>
471 </td>
472 <td className="tabular px-4 py-2.5 text-right sm:pr-5">{usd(row.micros)}</td>
473 </tr>
474 ))}
475 <tr className="border-b border-line font-medium">
476 <td className="px-4 py-2.5 sm:px-5">All of it</td>
477 <td className="tabular px-4 py-2.5 text-right sm:pr-5">{usd(totalMicros)}</td>
478 </tr>
479 <tr className="border-b border-line">
480 <td className="px-4 py-2.5 sm:px-5">
481 Money in
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises482 <span className="block text-xs text-faint">Usage paid for with real money and the plan, as last reconciled</span>
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays483 </td>
484 <td className="tabular px-4 py-2.5 text-right sm:pr-5">{usd(caps.revenueMicros)}</td>
485 </tr>
486 <tr>
487 <td className="px-4 py-2.5 sm:px-5">Money in less what g1t paid</td>
488 <td className={`tabular px-4 py-2.5 text-right sm:pr-5 ${net < 0 ? "text-danger" : "text-fg-soft"}`}>{usd(net, { signed: true })}</td>
489 </tr>
490 </tbody>
491 </table>
492 </div>
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises493 <p className="mt-3 text-xs text-muted">
494 Why this differs from the statement above: this is {caps.month} so far, the statement the last {range} days. The statement takes Cloudflare&apos;s bill as the
495 cost of what Cloudflare runs, so sandboxes and builds inside Cloudflare&apos;s included usage cost nothing there, and here what the price book says they
496 cost. Here are Cloudflare&apos;s subscriptions for the whole month, there for the range.
497 {(caps.resetMicros ?? 0) > 0 && (
498 <>
499 {" "}
500 And {usd(caps.resetMicros ?? 0, { cents: true })} of this was spent on {(caps.resetWorkspaces ?? []).join(", ")} before a testing reset wiped
501 {(caps.resetWorkspaces ?? []).length === 1 ? " its" : " their"} billing: still g1t&apos;s spend, but the statement has it only where the reset kept
502 it, as given away.
503 </>
504 )}
505 </p>
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays506 </Section>
507 );
508}
509
Merge platform pause and the hourly usage watcher: staff can pause compute, schedules, indexing or renders for everyone, the watcher emails on a breach and is never blind quietly, and the models proxy holds each run to its cap (billing 0051, integrations 0006)510
511/**
512 * The platform pause and the hourly usage watch (billing's platform.rs,
513 * docs/SPEND-GUARDRAILS.md): four levels staff can pause across g1t, what
514 * Cloudflare counted in the last hour against each threshold, and the
515 * last day's breaches.
516 */
517function PlatformSection({
518 guard,
519 unavailable,
520 failed,
521}: {
522 guard: PlatformGuard | null;
523 unavailable: string | null;
524 failed: CostsActionResult | null;
525}) {
526 return (
527 <Section
528 className="mt-6"
529 id="platform"
530 title="Platform pause"
531 description="What Cloudflare counted for all of g1t, read at a quarter past each hour: Workers, D1, Queues, Durable Objects, KV and Artifacts, each against an hourly threshold (PLATFORM_HOURLY_* in billing's wrangler.jsonc). A breach emails staff once per metric every 6 hours. Five times a threshold pauses what that metric feeds, of the levels AUTO_PAUSE names. Any level can be paused here by hand; every service sees a change within 30 seconds."
532 >
533 {!guard ? (
534 <Notice tone="warn">Billing did not answer for the platform pause: {unavailable}</Notice>
535 ) : (
536 <>
537 {!guard.can_read && (
538 <div className="mb-4">
539 <Notice tone="warn">Billing has no Cloudflare token with Account Analytics Read, so the hourly watch reads nothing. The pause still works.</Notice>
540 </div>
541 )}
542 {(guard.blind ?? []).length > 0 && (
543 <div className="mb-4">
544 <Notice tone="warn">
545 The watcher can&apos;t see: {(guard.blind ?? []).map((b) => b.key).join(", ")}
546 {guard.last_run ? ` (the run for ${guard.last_run})` : ""}. Their metrics are not watched until it is fixed; three runs in a row email
547 staff.
548 <ul className="mt-2 space-y-1 text-xs">
549 {(guard.blind ?? []).map((b) => (
550 <li key={b.key}>
551 <code>{b.dataset}</code> ({b.key}): {b.error}
552 </li>
553 ))}
554 </ul>
555 </Notice>
556 </div>
557 )}
558 {guard.empty && (
559 <div className="mb-4">
560 <Notice tone="warn">
561 Every dataset answered with no rows{guard.last_run ? ` in the run for ${guard.last_run}` : ""}, the month so far included: likely the wrong
562 account or a token that cannot see its analytics. The watcher sees nothing.
563 </Notice>
564 </div>
565 )}
566 {failed?.section === "platform" && (
567 <div className="mb-4">
568 <Notice tone="error">{failed.error}</Notice>
569 </div>
570 )}
571 <div className="grid gap-3 lg:grid-cols-2">
572 {PAUSE_LEVELS.map(({ level, title, stops }) => {
573 const state = guard.levels.find((l) => l.level === level);
574 const paused = state?.paused ?? false;
575 const error = failed?.section === `pause-${level}` ? failed.error : null;
576 return (
577 <div key={level} className={`rounded-lg border p-4 ${paused ? "border-danger/50 bg-danger/8" : "border-line"}`}>
578 <div className="flex items-center justify-between gap-2">
579 <span className="font-medium">{title}</span>
580 {paused ? <Badge tone="danger">Paused</Badge> : <Badge tone="mint">Running</Badge>}
581 </div>
582 <p className="mt-1 text-xs text-muted">{stops}</p>
583 {state?.set_at && (
584 <p className="mt-2 text-xs text-faint">
585 {paused ? "Paused" : "Resumed"} <When at={state.set_at} time /> by {state.auto ? "the usage watcher" : state.set_by}
586 {state.note ? `: “${state.note}”` : ""}
587 </p>
588 )}
589 <form method="post" action="#platform" className="mt-3 flex flex-col gap-2 sm:flex-row sm:items-end">
590 <input type="hidden" name="intent" value={paused ? "resume" : "pause"} />
591 <input type="hidden" name="level" value={level} />
592 <Field label={paused ? "Why resume it" : "Why pause it"} hint="Recorded in the audit log.">
593 <Input name="note" required minLength={5} maxLength={500} placeholder={paused ? "e.g. Fixed the loop in search" : "e.g. KV lists runaway"} />
594 </Field>
595 <Button type="submit" variant={paused ? "primary" : "danger"}>
596 {paused ? "Resume" : "Pause"}
597 </Button>
598 </form>
599 {error && (
600 <div className="mt-2">
601 <Notice tone="error">{error}</Notice>
602 </div>
603 )}
604 </div>
605 );
606 })}
607 </div>
608 <p className="mt-3 text-xs text-muted">
609 A severe breach may pause: {guard.auto_pause.length ? guard.auto_pause.join(", ") : "nothing (AUTO_PAUSE is empty)"}.
610 </p>
611
612 <h3 className="mt-6 text-sm font-medium">Breaches in the last 24 hours</h3>
613 {guard.breaches.length === 0 ? (
614 <p className="mt-2 text-sm text-muted">None.</p>
615 ) : (
616 <ul className="mt-2 space-y-2 text-sm">
617 {guard.breaches.map((b) => (
618 <li key={b.id} className="rounded-md border border-line px-3 py-2">
619 <div className="flex flex-wrap items-center gap-2">
620 <Badge tone={b.severe ? "danger" : "warn"}>{b.severe ? "Severe" : b.rule === "spike" ? "Spike" : "Over threshold"}</Badge>
621 <span className="text-xs text-faint">
622 <When at={b.opened_at} time />
623 {b.emailed_at ? ", emailed" : ""}
624 </span>
625 </div>
626 <p className="mt-1 text-fg-soft">{b.detail}</p>
627 </li>
628 ))}
629 </ul>
630 )}
631
632 <UsageTable title={guard.hour ? `The hour from ${guard.hour}` : "The last hour"} metrics={guard.last_hour} hourly />
633 <UsageTable title={`${guard.month}, so far`} metrics={guard.month_to_date} hourly={false} />
634 <p className="mt-3 text-xs text-muted">
635 Ids are Cloudflare&apos;s. <code>node scripts/ops/platform-usage.mjs</code> names them and shows the last 24 hours per script, queue, database and
636 namespace.
637 </p>
638 </>
639 )}
640 </Section>
641 );
642}
643
644function UsageTable({ title, metrics, hourly }: { title: string; metrics: PlatformMetric[]; hourly: boolean }) {
645 return (
646 <>
647 <h3 className="mt-6 text-sm font-medium">{title}</h3>
648 {metrics.length === 0 ? (
649 <p className="mt-2 text-sm text-muted">Nothing read yet.</p>
650 ) : (
651 <div className="-mx-4 mt-2 overflow-x-auto sm:-mx-5">
652 <table className="w-full min-w-[36rem] text-sm">
653 <thead>
654 <tr className="border-b border-line text-left text-xs text-muted">
655 <th className="px-4 py-2 font-medium sm:px-5">Metric</th>
656 <th className="px-4 py-2 text-right font-medium">Count</th>
657 {hourly && <th className="px-4 py-2 text-right font-medium">Of threshold</th>}
658 <th className="px-4 py-2 font-medium sm:pr-5">Most from</th>
659 </tr>
660 </thead>
661 <tbody>
662 {metrics.map((m) => {
663 const share = thresholdShare(m.value, m.threshold);
664 return (
665 <tr key={m.metric} className="border-b border-line last:border-0">
666 <td className="px-4 py-2.5 sm:px-5">{m.title}</td>
667 <td className="tabular px-4 py-2.5 text-right">{count(m.value)}</td>
668 {hourly && (
669 <td className={`tabular px-4 py-2.5 text-right ${share != null && share > 100 ? "text-danger" : "text-muted"}`}>
670 {share == null ? "—" : `${share}% of ${count(m.threshold)}`}
671 </td>
672 )}
673 <td className="max-w-[16rem] truncate px-4 py-2.5 text-xs text-faint sm:pr-5">
674 {m.top_name ? `${m.top_name} (${count(m.top_value ?? 0)})` : "—"}
675 </td>
676 </tr>
677 );
678 })}
679 </tbody>
680 </table>
681 </div>
682 )}
683 </>
684 );
685}

This file's history is long; its oldest lines are credited to the oldest commit read.