Repository navigation
feat: public agent usage leaderboard #6875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
saddlepaddle
merged 8 commits into
ParadevAI:main
from
harshithmullapudi:feat/leaderboard
Aug 26, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9ac788b
feat: public agent usage leaderboard
harshithmullapudi 61834e0
fix(trpc): exclude deleted users from stats, cap window span, map han…
harshithmullapudi 4cf9183
fix(leaderboard): address review findings on publish, ranking and pub…
harshithmullapudi c862ce6
refactor(leaderboard): serve the public board over tRPC and address r…
harshithmullapudi a6fef09
refactor(leaderboard): co-locate components and hooks per AGENTS.md
harshithmullapudi 4164938
fix(leaderboard): make leave atomic and fix token rounding carry
harshithmullapudi 4d94c94
fix(leaderboard): bound the client-asserted publish payload
harshithmullapudi 0c7a8a1
fix(leaderboard): close host-cap bypass and keep rollup sums exact
harshithmullapudi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
apps/desktop/src/renderer/components/LeaderboardJoinDialog/LeaderboardJoinDialog.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import { Button } from "@superset/ui/button"; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from "@superset/ui/dialog"; | ||
| import { Input } from "@superset/ui/input"; | ||
| import { Label } from "@superset/ui/label"; | ||
| import { useEffect, useState } from "react"; | ||
| import { RankTeaser } from "./components/RankTeaser"; | ||
| import type { LeaderboardPreview } from "./types"; | ||
|
|
||
| const HANDLE_PATTERN = /^[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){1,38}$/; | ||
|
|
||
| interface LeaderboardJoinDialogProps { | ||
| open: boolean; | ||
| onOpenChange: (open: boolean) => void; | ||
| preview: LeaderboardPreview | null; | ||
| suggestedHandle: string | null; | ||
| isLoading: boolean; | ||
| isJoining: boolean; | ||
| onConfirm: (handle: string) => void; | ||
| } | ||
|
|
||
| export function LeaderboardJoinDialog({ | ||
| open, | ||
| onOpenChange, | ||
| preview, | ||
| suggestedHandle, | ||
| isLoading, | ||
| isJoining, | ||
| onConfirm, | ||
| }: LeaderboardJoinDialogProps) { | ||
| const [handle, setHandle] = useState(""); | ||
| const [edited, setEdited] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| if (!edited && suggestedHandle) setHandle(suggestedHandle); | ||
| }, [edited, suggestedHandle]); | ||
|
|
||
| const trimmed = handle.trim().toLowerCase(); | ||
| const valid = HANDLE_PATTERN.test(trimmed); | ||
|
|
||
| return ( | ||
| <Dialog open={open} onOpenChange={onOpenChange}> | ||
| <DialogContent className="max-w-md"> | ||
| <DialogHeader> | ||
| <DialogTitle>Join the leaderboard</DialogTitle> | ||
| <DialogDescription> | ||
| Publishes your token counts and model names, never repo names, file | ||
| paths or prompts. You can leave at any time, which deletes | ||
| everything you've published. | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
|
|
||
| <div className="space-y-4"> | ||
| {isLoading ? ( | ||
| <p className="text-sm text-muted-foreground"> | ||
| Reading your local usage… | ||
| </p> | ||
| ) : preview ? ( | ||
| <RankTeaser preview={preview} /> | ||
| ) : null} | ||
|
|
||
| <div className="space-y-1.5"> | ||
| <Label htmlFor="leaderboard-handle">Handle</Label> | ||
| <Input | ||
| id="leaderboard-handle" | ||
| value={handle} | ||
| onChange={(event) => { | ||
| setEdited(true); | ||
| setHandle(event.target.value); | ||
| }} | ||
| placeholder="pick a name for the board" | ||
| autoComplete="off" | ||
| spellCheck={false} | ||
| /> | ||
| <p className="text-xs text-muted-foreground"> | ||
| Shown publicly alongside your name. | ||
| </p> | ||
| </div> | ||
| </div> | ||
|
|
||
| <DialogFooter> | ||
| <Button | ||
| variant="ghost" | ||
| size="sm" | ||
| onClick={() => onOpenChange(false)} | ||
| disabled={isJoining} | ||
| > | ||
| Cancel | ||
| </Button> | ||
| <Button | ||
| size="sm" | ||
| disabled={!valid || isJoining} | ||
| onClick={() => onConfirm(trimmed)} | ||
| > | ||
| {isJoining ? "Joining…" : "Join"} | ||
| </Button> | ||
| </DialogFooter> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } |
33 changes: 33 additions & 0 deletions
33
...esktop/src/renderer/components/LeaderboardJoinDialog/components/RankTeaser/RankTeaser.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { formatTokens } from "@superset/shared/format-tokens"; | ||
| import type { LeaderboardPreview } from "../../types"; | ||
|
|
||
| const MIN_PARTICIPANTS_FOR_RANK = 50; | ||
|
|
||
| export function RankTeaser({ preview }: { preview: LeaderboardPreview }) { | ||
| if (preview.tokens === 0) { | ||
| return ( | ||
| <p className="text-sm text-muted-foreground"> | ||
| No Claude or Codex usage found on this machine yet. Join now and you'll | ||
| appear once you've used an agent. | ||
| </p> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="space-y-1"> | ||
| {preview.total >= MIN_PARTICIPANTS_FOR_RANK ? ( | ||
| <p className="text-sm"> | ||
| You'd be{" "} | ||
| <span className="font-medium text-foreground">#{preview.rank}</span>{" "} | ||
| of {preview.total}. | ||
| </p> | ||
| ) : ( | ||
| <p className="text-sm">You'd be one of the first on the board.</p> | ||
| )} | ||
| <p className="text-xs text-muted-foreground"> | ||
| Based on {formatTokens(preview.tokens)} tokens in the last 30 days, | ||
| counting {preview.providers.join(" and ")}. | ||
| </p> | ||
| </div> | ||
| ); | ||
| } |
1 change: 1 addition & 0 deletions
1
apps/desktop/src/renderer/components/LeaderboardJoinDialog/components/RankTeaser/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { RankTeaser } from "./RankTeaser"; |
2 changes: 2 additions & 0 deletions
2
apps/desktop/src/renderer/components/LeaderboardJoinDialog/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { LeaderboardJoinDialog } from "./LeaderboardJoinDialog"; | ||
| export type { LeaderboardPreview } from "./types"; |
9 changes: 9 additions & 0 deletions
9
apps/desktop/src/renderer/components/LeaderboardJoinDialog/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import type { RouterOutputs } from "@superset/trpc"; | ||
|
|
||
| export type LeaderboardPreview = Pick< | ||
| RouterOutputs["leaderboard"]["previewRank"], | ||
| "rank" | "total" | ||
| > & { | ||
| tokens: number; | ||
| providers: string[]; | ||
| }; |
65 changes: 65 additions & 0 deletions
65
apps/desktop/src/renderer/lib/leaderboard/askedState.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { afterAll, beforeEach, describe, expect, it } from "bun:test"; | ||
| import { markLeaderboardAsked, readLeaderboardAsked } from "./askedState"; | ||
|
|
||
| const originalLocalStorage = Object.getOwnPropertyDescriptor( | ||
| globalThis, | ||
| "localStorage", | ||
| ); | ||
|
|
||
| function installStorage(): void { | ||
| const entries = new Map<string, string>(); | ||
| Object.defineProperty(globalThis, "localStorage", { | ||
| configurable: true, | ||
| writable: true, | ||
| value: { | ||
| getItem: (key: string) => entries.get(key) ?? null, | ||
| setItem: (key: string, value: string) => { | ||
| entries.set(key, value); | ||
| }, | ||
| removeItem: (key: string) => { | ||
| entries.delete(key); | ||
| }, | ||
| clear: () => entries.clear(), | ||
| key: (index: number) => [...entries.keys()][index] ?? null, | ||
| get length() { | ||
| return entries.size; | ||
| }, | ||
| } satisfies Storage, | ||
| }); | ||
| } | ||
|
|
||
| beforeEach(installStorage); | ||
|
|
||
| afterAll(() => { | ||
| if (originalLocalStorage) { | ||
| Object.defineProperty(globalThis, "localStorage", originalLocalStorage); | ||
| } else { | ||
| Reflect.deleteProperty(globalThis, "localStorage"); | ||
| } | ||
| }); | ||
|
|
||
| describe("leaderboard asked flag", () => { | ||
| it("reports not asked on a fresh profile", () => { | ||
| expect(readLeaderboardAsked()).toBe(false); | ||
| }); | ||
|
|
||
| it("round-trips through markLeaderboardAsked", () => { | ||
| markLeaderboardAsked(); | ||
| expect(readLeaderboardAsked()).toBe(true); | ||
| }); | ||
|
|
||
| it("treats an unrecognised value as not asked", () => { | ||
| localStorage.setItem("leaderboard-asked-v1", "{}"); | ||
| expect(readLeaderboardAsked()).toBe(false); | ||
| }); | ||
|
|
||
| it("suppresses the prompt when storage is unavailable", () => { | ||
| Object.defineProperty(globalThis, "localStorage", { | ||
| configurable: true, | ||
| get() { | ||
| throw new Error("denied"); | ||
| }, | ||
| }); | ||
| expect(readLeaderboardAsked()).toBe(true); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| const STORAGE_KEY = "leaderboard-asked-v1"; | ||
|
|
||
| export function readLeaderboardAsked(): boolean { | ||
| try { | ||
| return localStorage.getItem(STORAGE_KEY) === "true"; | ||
| } catch { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| export function markLeaderboardAsked(): void { | ||
| try { | ||
| localStorage.setItem(STORAGE_KEY, "true"); | ||
| } catch { | ||
| return; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| export { markLeaderboardAsked, readLeaderboardAsked } from "./askedState"; | ||
| export type { | ||
| LeaderboardFactoryDay, | ||
| LeaderboardPayload, | ||
| LeaderboardPayloadDay, | ||
| } from "./publishUsage"; | ||
| export { | ||
| BACKFILL_DAYS, | ||
| buildPayload, | ||
| PREVIEW_DAYS, | ||
| publishPayload, | ||
| publishUsage, | ||
| } from "./publishUsage"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import type { RouterInputs } from "@superset/trpc"; | ||
| import { PUBLISH_PAYLOAD_VERSION } from "@superset/trpc/leaderboard-schema"; | ||
| import { apiTrpcClient } from "renderer/lib/api-trpc-client"; | ||
| import { getHostServiceClientByUrl } from "renderer/lib/host-service-client"; | ||
|
|
||
| export const BACKFILL_DAYS = 30; | ||
|
|
||
| export const PREVIEW_DAYS = 30; | ||
|
|
||
| type PublishInput = RouterInputs["leaderboard"]["publish"]; | ||
|
|
||
| export type LeaderboardPayloadDay = PublishInput["days"][number]; | ||
| export type LeaderboardFactoryDay = NonNullable< | ||
| PublishInput["factoryDays"] | ||
| >[number]; | ||
|
|
||
| export interface LeaderboardPayload { | ||
| days: LeaderboardPayloadDay[]; | ||
| factoryDays: LeaderboardFactoryDay[]; | ||
| } | ||
|
|
||
| export async function buildPayload( | ||
| hostUrl: string, | ||
| days: number, | ||
| ): Promise<LeaderboardPayload> { | ||
| return await getHostServiceClientByUrl( | ||
| hostUrl, | ||
| ).usage.leaderboardPayload.query({ days }); | ||
| } | ||
|
|
||
| export async function publishPayload( | ||
| machineId: string, | ||
| payload: LeaderboardPayload, | ||
| ): Promise<{ written: number; days: number }> { | ||
| if (payload.days.length === 0 && payload.factoryDays.length === 0) { | ||
| return { written: 0, days: 0 }; | ||
| } | ||
|
|
||
| return await apiTrpcClient.leaderboard.publish.mutate({ | ||
| payloadVersion: PUBLISH_PAYLOAD_VERSION, | ||
| hostId: machineId, | ||
| days: payload.days, | ||
| factoryDays: payload.factoryDays, | ||
| }); | ||
| } | ||
|
|
||
| export async function publishUsage( | ||
| hostUrl: string, | ||
| machineId: string, | ||
| days: number = BACKFILL_DAYS, | ||
| ): Promise<{ written: number; days: number }> { | ||
| return await publishPayload(machineId, await buildPayload(hostUrl, days)); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.