Skip to content
683 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 Cloudflare's usage over its billing cycle: every page read, included amounts once a cycle, a projection, test-mode charges never money in (billing 0052)10import { PAUSE_LEVELS, capPercent, count, daySeries, givenParts as givenBy, 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 )}
Merge Cloudflare's usage over its billing cycle: every page read, included amounts once a cycle, a projection, test-mode charges never money in (billing 0052)176 {(report.unattributedMicros ?? 0) > 0 && (
177 <p className="mt-3 text-xs text-muted">
178 And {usd(report.unattributedMicros ?? 0, { cents: true })} of running g1t on days no workspace used anything: no one&apos;s, so not above. The
179 workspaces&apos; costs and this add up to the cost in the statement.
180 </p>
181 )}
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily182 </Section>
183
184 </main>
185 );
186}
187
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays188function CapMeter({ label, used, cap, hint }: { label: string; used: number; cap: number; hint: ReactNode }) {
189 const percent = capPercent(used, cap);
Merge branch 'worktree-agent-ad7c6d88d93adc817'190 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 pays191 return (
192 <div className="rounded-md border border-line px-4 py-3">
193 <div className="flex flex-wrap items-baseline justify-between gap-2">
194 <span className="text-sm font-medium">{label}</span>
195 <span className="tabular text-sm">
196 {usd(used)} <span className="text-faint">of {cap > 0 ? usd(cap) : "no cap"}</span>
197 </span>
198 </div>
199 <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}>
200 <div className={`h-full ${tone}`} style={{ width: `${percent}%` }} />
201 </div>
202 <p className="mt-1.5 text-xs text-muted">{hint}</p>
203 </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 running204 );
205}
206
207/**
208 * Where the money went, as a short statement: usage sold and running g1t
209 * (each against what paid for it), what g1t gave away on purpose (a budget,
210 * never a loss), and who was paid.
211 */
212function Statement({ report, floor, range, proposals }: { report: CostsReport; floor: number; range: number; proposals: number }) {
213 const o = report.overall;
214 // Reports from before the statement have only the totals.
215 const given = o.givenMicros ?? 0;
216 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)217 const included = o.includedMicros ?? 0;
218 const usageIn = o.usageMicros + included;
219 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 sold220 // Under a cent sold, a percentage says nothing (a few micros against none).
221 const soldSomething = usageIn >= 10_000;
222 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 running223 const running = o.runningCostMicros ?? 0;
224 const unmapped = o.unmappedCostMicros ?? 0;
Merge Cloudflare's usage over its billing cycle: every page read, included amounts once a cycle, a projection, test-mode charges never money in (billing 0052)225 // Cloudflare's subscriptions are not on the usage bill: each day's share of its billing cycle.
226 const subscriptions = subscriptionsOver(report.caps.fixedMonthlyMicros, range, o);
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises227 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 running228 const moneyIn = o.usageMicros + o.plansMicros;
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises229 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 running230 const net = moneyIn - spent;
Merge Cloudflare's usage over its billing cycle: every page read, included amounts once a cycle, a projection, test-mode charges never money in (billing 0052)231 const givenParts = givenBy(o);
232 const gateway = o.gatewayCostMicros ?? 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 running233 const rows: { title: string; note: string; in: number | null; cost: number; result: number | null; tone?: "danger" | "warn" | "muted" }[] = [
234 {
235 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)236 note:
237 included > 0
sudo: the costs statement reads to the cent238 ? `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)239 : "What workspaces paid for usage, against what that usage cost",
240 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 running241 cost: usageCost,
242 result: usageMargin,
243 tone: usageMargin < 0 ? "danger" : undefined,
244 },
245 {
246 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)247 note:
248 included > 0
sudo: the costs statement reads to the cent249 ? `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)250 : "Plans, against Workers, D1, KV, Queues and the rest of the platform",
251 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 running252 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)253 result: o.plansMicros - included - running,
254 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 running255 },
256 {
257 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 & pricing258 note:
259 report.caps.fixedSource === "cloudflare"
Merge Cloudflare's usage over its billing cycle: every page read, included amounts once a cycle, a projection, test-mode charges never money in (billing 0052)260 ? `Fixed, as Cloudflare lists them${(report.caps.fixedItems ?? []).length > 0 ? ` (${(report.caps.fixedItems ?? []).map((i) => i.name).join(", ")})` : ""}; not on the usage bill. Each day is its billing cycle's share of ${usd(report.caps.fixedMonthlyMicros, { cents: true })} a month`
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing261 : "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 running262 in: null,
263 cost: subscriptions,
264 result: -subscriptions,
265 tone: "muted",
266 },
267 ...(unmapped > 0
268 ? [{ title: "Not mapped", note: "Billed by Cloudflare, charged for by nothing yet", in: null, cost: unmapped, result: -unmapped, tone: "danger" as const }]
269 : []),
270 {
271 title: "Given away",
sudo: the costs statement reads to the cent272 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 running273 in: null,
274 cost: given,
275 result: null,
276 tone: "muted",
277 },
278 ];
279 const resultClass = (tone?: string) => (tone === "danger" ? "text-danger" : tone === "warn" ? "text-warn" : tone === "muted" ? "text-muted" : "text-fg");
280 return (
281 <>
282 <div className="mt-5 grid grid-cols-2 gap-3 lg:grid-cols-4">
283 <Stat
284 label="Margin on usage sold"
285 value={percentLabel(usagePercent)}
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises286 hint={
287 soldSomething
288 ? `Of the price: ${usd(usageIn, { cents: true })} paid for usage that cost ${usd(usageCost, { cents: true })}`
289 : "No usage sold in this range"
290 }
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 running291 tone={marginTone(usagePercent, floor)}
292 />
293 <Stat
294 label="Given away on purpose"
sudo: the costs statement reads to the cent295 value={usd(given, { cents: true })}
296 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 running297 />
298 <Stat
299 label="Who g1t paid"
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises300 value={usd(paid.totalMicros, { cents: true })}
Merge Cloudflare's usage over its billing cycle: every page read, included amounts once a cycle, a projection, test-mode charges never money in (billing 0052)301 hint={`Cloudflare's usage ${usd(paid.cloudflareMicros, { cents: true })} and subscriptions ${usd(paid.subscriptionsMicros, { cents: true })}, model providers ${usd(paid.modelsMicros, { cents: true })}${gateway > 0 && Math.abs(gateway - paid.modelsMicros) >= 10_000 ? ` (AI Gateway priced them at ${usd(gateway, { cents: true })}; see Drift)` : ""}; 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 running302 />
303 <Stat
304 label="Proposals waiting"
305 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 & pricing306 hint={
307 <>
308 <Link to={costsHref("bill", range) + "#proposals"} className="underline underline-offset-2">
309 On Bill &amp; pricing
310 </Link>
311 {report.fetchedAt ? (
312 <>
313 {" "}
314 · bill read <When at={report.fetchedAt} time />
315 </>
316 ) : (
317 " · the bill has not been read yet"
318 )}
319 </>
320 }
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 running321 tone={proposals > 0 ? "warn" : undefined}
322 />
323 </div>
324 <div className="mt-3 overflow-x-auto rounded-lg border border-line bg-surface">
325 <table className="w-full min-w-[36rem] text-sm">
326 <thead>
327 <tr className="border-b border-line text-left text-xs text-muted">
328 <th className="px-4 py-2 font-medium sm:px-5">
329 {report.since} to {report.until}
330 </th>
331 <th className="px-4 py-2 text-right font-medium">Paid in</th>
332 <th className="px-4 py-2 text-right font-medium">Cost</th>
333 <th className="px-4 py-2 text-right font-medium sm:pr-5">Result</th>
334 </tr>
335 </thead>
336 <tbody>
337 {rows.map((row) => (
338 <tr key={row.title} className="border-b border-line">
339 <td className="px-4 py-2.5 sm:px-5">
340 <span className="text-fg">{row.title}</span>
341 <span className="block text-xs text-faint">{row.note}</span>
342 </td>
sudo: the costs statement reads to the cent343 <td className="tabular px-4 py-2.5 text-right">{row.in == null ? <span className="text-faint">—</span> : usd(row.in, { cents: true })}</td>
344 <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 running345 <td className={`tabular px-4 py-2.5 text-right sm:pr-5 ${resultClass(row.tone)}`}>
sudo: the costs statement reads to the cent346 {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 running347 </td>
348 </tr>
349 ))}
350 <tr>
351 <td className="px-4 py-2.5 sm:px-5">
352 <span className="font-medium text-fg">All in</span>
353 <span className="block text-xs text-faint">
sudo: the costs statement reads to the cent354 {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 running355 </span>
356 </td>
sudo: the costs statement reads to the cent357 <td className="tabular px-4 py-2.5 text-right font-medium">{usd(moneyIn, { cents: true })}</td>
358 <td className="tabular px-4 py-2.5 text-right font-medium">{usd(spent, { cents: true })}</td>
359 <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 running360 </tr>
361 </tbody>
362 </table>
363 </div>
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging364 <p className="mt-2 text-xs text-faint">
365 Credits from g1t, {report.since} to {report.until}: {usd(o.creditsGivenMicros ?? 0, { cents: true })} given, {usd(o.creditsUsedMicros ?? 0, { cents: true })}{" "}
366 spent on usage. What promotional and goodwill credit paid for is given away above, never money in; refunds took{" "}
367 {usd(o.creditsRefundedMicros ?? 0, { cents: true })} off money in on the days they refund.{" "}
368 <Link to="/credits" className="underline underline-offset-2">
369 Every credit
370 </Link>
371 </p>
Merge Stripe Tax, the card fee on card payments, and one free workspace per person372 <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">
373 <div>
374 <dt className="text-xs text-muted">Tax collected</dt>
375 <dd className="tabular text-fg">{usd(o.taxCollectedMicros ?? 0, { cents: true })}</dd>
376 <dd className="text-xs text-faint">Owed to tax authorities; never in money in or margin. Filed from Stripe Tax.</dd>
377 </div>
378 <div>
379 <dt className="text-xs text-muted">Card fees passed on</dt>
380 <dd className="tabular text-fg">{usd(o.cardFeesMicros ?? 0, { cents: true })}</dd>
381 <dd className="text-xs text-faint">Paid Stripe&apos;s card fees; not revenue either.</dd>
382 </div>
383 </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 running384 </>
385 );
386}
387
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises388function 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 pays389 const { rows, totalMicros } = spendRows(caps);
390 const net = caps.revenueMicros - totalMicros;
391 return (
392 <Section
393 className="mt-6"
394 id="spend"
395 title="g1t's own spend"
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises396 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 pays397 >
398 <div className="grid gap-3 lg:grid-cols-2">
399 <CapMeter
400 label={`Today, ${caps.day} (UTC)`}
401 used={caps.todayMicros}
402 cap={caps.dailyCapMicros}
403 hint={
404 caps.tripped ? (
405 <span className="text-danger">
406 Breaker open{caps.trippedAt ? <> since <When at={caps.trippedAt} time /></> : null}: new hosted-model runs g1t pays for wait until 00:00 UTC.
407 </span>
408 ) : caps.liftedBy ? (
409 <>
410 Lifted for today by {caps.liftedBy}
411 {caps.liftNote ? `: “${caps.liftNote}”` : ""}.
412 </>
413 ) : (
414 "Paying workspaces on a live card are never paused. PLATFORM_DAILY_SPEND_CAP_MICROS."
415 )
416 }
417 />
418 {caps.comped.map((b) => (
419 <CapMeter
420 key={b.account}
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging421 label={`${b.name}, ${caps.month} (100% discount)`}
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays422 used={b.usedMicros}
423 cap={b.ceilingMicros}
424 hint={
425 <>
426 {b.ceilingMicros > 0 && b.usedMicros >= b.ceilingMicros ? (
427 <span className="text-danger">Used up: new work on it is refused. </span>
428 ) : null}
429 {b.defaultCeiling ? "The default budget (COMPED_MONTHLY_CEILING_MICROS)" : "Its own budget, in its terms"}. Raise it on{" "}
430 <Link to={`/workspaces/${encodeURIComponent(b.name)}#billing`} className="underline underline-offset-2">
431 its account
432 </Link>
433 : Terms, Limit.
434 </>
435 }
436 />
437 ))}
438 </div>
439 {(caps.tripped || error) && (
440 <form method="post" action="#spend" className="mt-4 flex flex-col gap-2 sm:flex-row sm:items-end">
441 <input type="hidden" name="intent" value="lift" />
442 <Field label="Why lift it" hint="Recorded in the audit log.">
443 <Input name="note" required minLength={5} maxLength={500} placeholder="e.g. Launch day; watching it" className="sm:min-w-[24rem]" />
444 </Field>
445 <Button type="submit" variant="danger">
446 Lift for today
447 </Button>
448 </form>
449 )}
450 {error && (
451 <div className="mt-3">
452 <Notice tone="error">{error}</Notice>
453 </div>
454 )}
455 <div className="-mx-4 mt-5 overflow-x-auto sm:-mx-5">
456 <table className="w-full min-w-[34rem] text-sm">
457 <thead>
458 <tr className="border-b border-line text-left text-xs text-muted">
459 <th className="px-4 py-2 font-medium sm:px-5">{caps.month}, so far</th>
460 <th className="px-4 py-2 text-right font-medium sm:pr-5">g1t paid</th>
461 </tr>
462 </thead>
463 <tbody>
464 {rows.map((row) => (
465 <tr key={row.key} className="border-b border-line align-top">
466 <td className="px-4 py-2.5 sm:px-5">
467 {row.title}
468 <span className="block text-xs text-faint">{row.note}</span>
469 </td>
470 <td className="tabular px-4 py-2.5 text-right sm:pr-5">{usd(row.micros)}</td>
471 </tr>
472 ))}
473 <tr className="border-b border-line font-medium">
474 <td className="px-4 py-2.5 sm:px-5">All of it</td>
475 <td className="tabular px-4 py-2.5 text-right sm:pr-5">{usd(totalMicros)}</td>
476 </tr>
477 <tr className="border-b border-line">
478 <td className="px-4 py-2.5 sm:px-5">
479 Money in
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises480 <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 pays481 </td>
482 <td className="tabular px-4 py-2.5 text-right sm:pr-5">{usd(caps.revenueMicros)}</td>
483 </tr>
484 <tr>
485 <td className="px-4 py-2.5 sm:px-5">Money in less what g1t paid</td>
486 <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>
487 </tr>
488 </tbody>
489 </table>
490 </div>
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises491 <p className="mt-3 text-xs text-muted">
492 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
493 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
Merge Cloudflare's usage over its billing cycle: every page read, included amounts once a cycle, a projection, test-mode charges never money in (billing 0052)494 cost. Cloudflare&apos;s subscriptions are counted the same way in both: each day its billing cycle&apos;s share of the month&apos;s price.
Merge costs and margin review: gateway query, own spend, discount meters, superseded rises495 {(caps.resetMicros ?? 0) > 0 && (
496 <>
497 {" "}
498 And {usd(caps.resetMicros ?? 0, { cents: true })} of this was spent on {(caps.resetWorkspaces ?? []).join(", ")} before a testing reset wiped
499 {(caps.resetWorkspaces ?? []).length === 1 ? " its" : " their"} billing: still g1t&apos;s spend, but the statement has it only where the reset kept
500 it, as given away.
501 </>
502 )}
503 </p>
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays504 </Section>
505 );
506}
507
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)508
509/**
510 * The platform pause and the hourly usage watch (billing's platform.rs,
511 * docs/SPEND-GUARDRAILS.md): four levels staff can pause across g1t, what
512 * Cloudflare counted in the last hour against each threshold, and the
513 * last day's breaches.
514 */
515function PlatformSection({
516 guard,
517 unavailable,
518 failed,
519}: {
520 guard: PlatformGuard | null;
521 unavailable: string | null;
522 failed: CostsActionResult | null;
523}) {
524 return (
525 <Section
526 className="mt-6"
527 id="platform"
528 title="Platform pause"
529 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."
530 >
531 {!guard ? (
532 <Notice tone="warn">Billing did not answer for the platform pause: {unavailable}</Notice>
533 ) : (
534 <>
535 {!guard.can_read && (
536 <div className="mb-4">
537 <Notice tone="warn">Billing has no Cloudflare token with Account Analytics Read, so the hourly watch reads nothing. The pause still works.</Notice>
538 </div>
539 )}
540 {(guard.blind ?? []).length > 0 && (
541 <div className="mb-4">
542 <Notice tone="warn">
543 The watcher can&apos;t see: {(guard.blind ?? []).map((b) => b.key).join(", ")}
544 {guard.last_run ? ` (the run for ${guard.last_run})` : ""}. Their metrics are not watched until it is fixed; three runs in a row email
545 staff.
546 <ul className="mt-2 space-y-1 text-xs">
547 {(guard.blind ?? []).map((b) => (
548 <li key={b.key}>
549 <code>{b.dataset}</code> ({b.key}): {b.error}
550 </li>
551 ))}
552 </ul>
553 </Notice>
554 </div>
555 )}
556 {guard.empty && (
557 <div className="mb-4">
558 <Notice tone="warn">
559 Every dataset answered with no rows{guard.last_run ? ` in the run for ${guard.last_run}` : ""}, the month so far included: likely the wrong
560 account or a token that cannot see its analytics. The watcher sees nothing.
561 </Notice>
562 </div>
563 )}
564 {failed?.section === "platform" && (
565 <div className="mb-4">
566 <Notice tone="error">{failed.error}</Notice>
567 </div>
568 )}
569 <div className="grid gap-3 lg:grid-cols-2">
570 {PAUSE_LEVELS.map(({ level, title, stops }) => {
571 const state = guard.levels.find((l) => l.level === level);
572 const paused = state?.paused ?? false;
573 const error = failed?.section === `pause-${level}` ? failed.error : null;
574 return (
575 <div key={level} className={`rounded-lg border p-4 ${paused ? "border-danger/50 bg-danger/8" : "border-line"}`}>
576 <div className="flex items-center justify-between gap-2">
577 <span className="font-medium">{title}</span>
578 {paused ? <Badge tone="danger">Paused</Badge> : <Badge tone="mint">Running</Badge>}
579 </div>
580 <p className="mt-1 text-xs text-muted">{stops}</p>
581 {state?.set_at && (
582 <p className="mt-2 text-xs text-faint">
583 {paused ? "Paused" : "Resumed"} <When at={state.set_at} time /> by {state.auto ? "the usage watcher" : state.set_by}
584 {state.note ? `: “${state.note}”` : ""}
585 </p>
586 )}
587 <form method="post" action="#platform" className="mt-3 flex flex-col gap-2 sm:flex-row sm:items-end">
588 <input type="hidden" name="intent" value={paused ? "resume" : "pause"} />
589 <input type="hidden" name="level" value={level} />
590 <Field label={paused ? "Why resume it" : "Why pause it"} hint="Recorded in the audit log.">
591 <Input name="note" required minLength={5} maxLength={500} placeholder={paused ? "e.g. Fixed the loop in search" : "e.g. KV lists runaway"} />
592 </Field>
593 <Button type="submit" variant={paused ? "primary" : "danger"}>
594 {paused ? "Resume" : "Pause"}
595 </Button>
596 </form>
597 {error && (
598 <div className="mt-2">
599 <Notice tone="error">{error}</Notice>
600 </div>
601 )}
602 </div>
603 );
604 })}
605 </div>
606 <p className="mt-3 text-xs text-muted">
607 A severe breach may pause: {guard.auto_pause.length ? guard.auto_pause.join(", ") : "nothing (AUTO_PAUSE is empty)"}.
608 </p>
609
610 <h3 className="mt-6 text-sm font-medium">Breaches in the last 24 hours</h3>
611 {guard.breaches.length === 0 ? (
612 <p className="mt-2 text-sm text-muted">None.</p>
613 ) : (
614 <ul className="mt-2 space-y-2 text-sm">
615 {guard.breaches.map((b) => (
616 <li key={b.id} className="rounded-md border border-line px-3 py-2">
617 <div className="flex flex-wrap items-center gap-2">
618 <Badge tone={b.severe ? "danger" : "warn"}>{b.severe ? "Severe" : b.rule === "spike" ? "Spike" : "Over threshold"}</Badge>
619 <span className="text-xs text-faint">
620 <When at={b.opened_at} time />
621 {b.emailed_at ? ", emailed" : ""}
622 </span>
623 </div>
624 <p className="mt-1 text-fg-soft">{b.detail}</p>
625 </li>
626 ))}
627 </ul>
628 )}
629
630 <UsageTable title={guard.hour ? `The hour from ${guard.hour}` : "The last hour"} metrics={guard.last_hour} hourly />
631 <UsageTable title={`${guard.month}, so far`} metrics={guard.month_to_date} hourly={false} />
632 <p className="mt-3 text-xs text-muted">
633 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
634 namespace.
635 </p>
636 </>
637 )}
638 </Section>
639 );
640}
641
642function UsageTable({ title, metrics, hourly }: { title: string; metrics: PlatformMetric[]; hourly: boolean }) {
643 return (
644 <>
645 <h3 className="mt-6 text-sm font-medium">{title}</h3>
646 {metrics.length === 0 ? (
647 <p className="mt-2 text-sm text-muted">Nothing read yet.</p>
648 ) : (
649 <div className="-mx-4 mt-2 overflow-x-auto sm:-mx-5">
650 <table className="w-full min-w-[36rem] text-sm">
651 <thead>
652 <tr className="border-b border-line text-left text-xs text-muted">
653 <th className="px-4 py-2 font-medium sm:px-5">Metric</th>
654 <th className="px-4 py-2 text-right font-medium">Count</th>
655 {hourly && <th className="px-4 py-2 text-right font-medium">Of threshold</th>}
656 <th className="px-4 py-2 font-medium sm:pr-5">Most from</th>
657 </tr>
658 </thead>
659 <tbody>
660 {metrics.map((m) => {
661 const share = thresholdShare(m.value, m.threshold);
662 return (
663 <tr key={m.metric} className="border-b border-line last:border-0">
664 <td className="px-4 py-2.5 sm:px-5">{m.title}</td>
665 <td className="tabular px-4 py-2.5 text-right">{count(m.value)}</td>
666 {hourly && (
667 <td className={`tabular px-4 py-2.5 text-right ${share != null && share > 100 ? "text-danger" : "text-muted"}`}>
668 {share == null ? "—" : `${share}% of ${count(m.threshold)}`}
669 </td>
670 )}
671 <td className="max-w-[16rem] truncate px-4 py-2.5 text-xs text-faint sm:pr-5">
672 {m.top_name ? `${m.top_name} (${count(m.top_value ?? 0)})` : "—"}
673 </td>
674 </tr>
675 );
676 })}
677 </tbody>
678 </table>
679 </div>
680 )}
681 </>
682 );
683}

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