Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

feat(desktop): replay-ready wording, the next spin's wheel, recent spins

ogsamrat968c5bf26997
diff --git a/apps/app/src/app/lib/quality.ts b/apps/app/src/app/lib/quality.ts
index f2ff7b75..319d187c 100644
--- a/apps/app/src/app/lib/quality.ts
+++ b/apps/app/src/app/lib/quality.ts
@@ -271,7 +271,19 @@ export function nearMissText(spin: QualitySpin, jackpotTokens?: number | null):
}
/** The star, explained wherever it shows. */
-export const CLIENT_GRADE_NOTE = "★ Client-grade sessions earn +2 spins on a richer wheel.";
+export const CLIENT_GRADE_NOTE = "★ Replay-ready sessions earn +2 spins on a richer wheel.";
+/** What users read for a client-grade session or spin (internal fields keep `client`). */
+export const REPLAY_READY_LABEL = "replay-ready ★";
+
+/**
+ * The prize shown `progress` (0..1) into the count-up: an ease-out that never
+ * passes the server's value and ends exactly on it.
+ */
+export function countUpValue(value: number, progress: number): number {
+ const p = Math.min(1, Math.max(0, progress));
+ if (p >= 1) return value;
+ return Math.min(value, Math.floor(value * (1 - (1 - p) ** 3)));
+}
export function newSpinIdempotencyKey(): string {
return globalThis.crypto.randomUUID();
diff --git a/apps/app/src/react-app/domains/quality/quality-notice.tsx b/apps/app/src/react-app/domains/quality/quality-notice.tsx
index d1399e5d..cec56623 100644
--- a/apps/app/src/react-app/domains/quality/quality-notice.tsx
+++ b/apps/app/src/react-app/domains/quality/quality-notice.tsx
@@ -7,6 +7,7 @@ import { cn } from "@/lib/utils";
import { omnirushAccountStatus, omnirushQualityDetails } from "../../../app/lib/desktop";
import {
CLIENT_GRADE_NOTE,
+ REPLAY_READY_LABEL,
NOTICE_SEEN_STORAGE_KEY,
NUDGE_SEEN_STORAGE_KEY,
canSpinNow,
@@ -35,10 +36,13 @@ const FALLBACK_FAIL_LABELS: Record<string, string> = {
small_fix: "a small fix",
one_shot: "a one-shot answer",
non_coding: "not coding work",
+ old_client: "old app version",
};
export function failLabel(fail: string, labels: Record<string, string> = {}): string {
- return labels[fail] ?? FALLBACK_FAIL_LABELS[fail] ?? fail.replace(/[_-]+/g, " ");
+ const label = labels[fail] ?? FALLBACK_FAIL_LABELS[fail] ?? fail.replace(/[_-]+/g, " ");
+ // Users never read "client" here, not even in a server label: it names the app instead.
+ return label.replace(/\bold client\b/gi, "old app version").replace(/\bclient\b/gi, "app");
}
export type QualitySessionReasons = { sessions: OmniRushQualitySession[]; failLabels: Record<string, string> };
@@ -73,7 +77,7 @@ export function SessionReasons({ reasons }: { reasons: QualitySessionReasons | n
{session.fails.length || session.reproducible === "pass" || session.clientGrade ? (
<div className="mt-1 flex flex-wrap gap-1">
{session.clientGrade ? (
- <span data-testid="quality-client-grade" className="rounded-full bg-amber-300/15 px-1.5 py-0.5 text-[10px] font-semibold text-amber-200">client-grade ★</span>
+ <span data-testid="quality-client-grade" className="rounded-full bg-amber-300/15 px-1.5 py-0.5 text-[10px] font-semibold text-amber-200">{REPLAY_READY_LABEL}</span>
) : session.reproducible === "pass" ? (
<span data-testid="quality-reproducible" className="rounded-full bg-[#a3e635]/15 px-1.5 py-0.5 text-[10px] text-[#d9f99d]">reproducible ✓</span>
) : null}
diff --git a/apps/app/src/react-app/domains/quality/quality-parts.tsx b/apps/app/src/react-app/domains/quality/quality-parts.tsx
index dad83c90..78aa98eb 100644
--- a/apps/app/src/react-app/domains/quality/quality-parts.tsx
+++ b/apps/app/src/react-app/domains/quality/quality-parts.tsx
@@ -87,7 +87,7 @@ export function SpinButton(props: {
data-spins={ready}
data-client-spins={stars}
title={ready > 0
- ? `${ready} spin${ready === 1 ? "" : "s"} ready${stars > 0 ? `, ${stars} client-grade ★ on the richer wheel` : ""}`
+ ? `${ready} spin${ready === 1 ? "" : "s"} ready${stars > 0 ? `, ${stars} replay-ready ★ on the richer wheel` : ""}`
: "No spins yet: good sessions earn spins."}
className={cn(
"relative inline-flex h-6 items-center gap-1.5 rounded-full px-2.5 text-[11px] font-semibold transition",
diff --git a/apps/app/src/react-app/domains/quality/quality-spin-dialog.tsx b/apps/app/src/react-app/domains/quality/quality-spin-dialog.tsx
index 66355981..3e2d5b98 100644
--- a/apps/app/src/react-app/domains/quality/quality-spin-dialog.tsx
+++ b/apps/app/src/react-app/domains/quality/quality-spin-dialog.tsx
@@ -3,11 +3,14 @@ import { useCallback, useEffect, useRef, useState } from "react";
import { Loader2, Sparkles, Volume2, VolumeX, X } from "lucide-react";
import { cn } from "@/lib/utils";
+import type { OmniRushQualitySpinRecord, OmniRushQualitySpinTotals } from "@omnirush/types/desktop-ipc";
import { omnirushAccountStatus, omnirushQualityDetails, omnirushQualitySpin, omnirushQualitySpins } from "../../../app/lib/desktop";
import { compactTokenCount } from "../../../app/lib/omnirush-usage";
import {
CLIENT_GRADE_NOTE,
+ REPLAY_READY_LABEL,
+ countUpValue,
DEFAULT_WHEEL_SEGMENTS,
SOUND_STORAGE_KEY,
canSpinNow,
@@ -43,8 +46,11 @@ export function usePrefersReducedMotion(): boolean {
return reduced;
}
-/** Counts up to `value` once `active`; jumps straight there with reduced motion. */
-function useCountUp(value: number, active: boolean, reducedMotion: boolean, durationMs = 1_400): number {
+/**
+ * Counts up to `value` once `active`; jumps straight there with reduced
+ * motion. `done` only once the shown number is exactly `value`.
+ */
+function useCountUp(value: number, active: boolean, reducedMotion: boolean, durationMs = 1_400): { shown: number; done: boolean } {
const [shown, setShown] = useState(0);
useEffect(() => {
if (!active) {
@@ -59,17 +65,46 @@ function useCountUp(value: number, active: boolean, reducedMotion: boolean, dura
const started = performance.now();
const step = (now: number) => {
const progress = Math.min(1, (now - started) / durationMs);
- setShown(Math.round(value * (1 - (1 - progress) ** 3)));
+ setShown(countUpValue(value, progress));
if (progress < 1) frame = requestAnimationFrame(step);
};
frame = requestAnimationFrame(step);
return () => cancelAnimationFrame(frame);
}, [active, durationMs, reducedMotion, value]);
- return shown;
+ return { shown, done: active && shown === value };
}
type Phase = "idle" | "requesting" | "spinning" | "result" | "error";
+/** The last spins (newest first), ★ on the replay-ready ones. */
+export function RecentSpins({ spins }: { spins: OmniRushQualitySpinRecord[] }) {
+ const shown = spins.slice(0, 10);
+ if (!shown.length) return null;
+ return (
+ <div className="mt-1 w-full" data-testid="quality-recent-spins">
+ <div className="mb-1 text-center text-[10px] font-semibold uppercase tracking-[0.18em] text-white/35">Recent spins</div>
+ <ul className="flex flex-wrap justify-center gap-1">
+ {shown.map((spin) => (
+ <li
+ key={spin.id}
+ data-replay-ready={spin.clientGrade ? "" : undefined}
+ title={spin.clientGrade ? REPLAY_READY_LABEL : spin.status}
+ className={cn(
+ "rounded-full border px-2 py-0.5 text-[10.5px] tabular-nums",
+ spin.clientGrade ? "border-amber-300/40 bg-amber-300/10 text-amber-200" : "border-white/10 text-white/55",
+ )}
+ >
+ {spin.clientGrade ? "★ " : ""}
+ {spin.status === "spun"
+ ? spin.prizeTokens !== null ? compactTokenCount(spin.prizeTokens) : "spun"
+ : spin.status === "ready" ? "ready" : spin.status}
+ </li>
+ ))}
+ </ul>
+ </div>
+ );
+}
+
export type QualitySpinDialogProps = {
quality: AccountQuality;
onClose: () => void;
@@ -88,14 +123,18 @@ export function QualitySpinDialog(props: QualitySpinDialogProps) {
const [segments, setSegments] = useState<WheelSegment[]>(DEFAULT_WHEEL_SEGMENTS);
const [expectedTokens, setExpectedTokens] = useState<number | null>(null);
const [jackpotTokens, setJackpotTokens] = useState<number | null>(null);
- const [totals, setTotals] = useState<{ spun: number; paidTokens: number } | null>(null);
+ const [clientSegments, setClientSegments] = useState<WheelSegment[]>([]);
+ const [totals, setTotals] = useState<OmniRushQualitySpinTotals | null>(null);
const [phase, setPhase] = useState<Phase>("idle");
const [result, setResult] = useState<QualitySpin | null>(null);
const [error, setError] = useState<string | null>(null);
const [spinId, setSpinId] = useState(0);
const [soundEnabled, setSoundEnabled] = useState(() => readPref(SOUND_STORAGE_KEY) === "on");
const spinsLeft = result ? result.spinsAvailable : quality.spinsAvailable;
- const prize = useCountUp(result?.prizeTokens ?? 0, phase === "result", reducedMotion);
+ const count = useCountUp(result?.prizeTokens ?? 0, phase === "result", reducedMotion);
+ const prize = count.shown;
+ // The final state (payout, chips, Spin again) waits for the count-up to land on the server's prize.
+ const settled = phase === "result" && count.done;
const closeRef = useRef<HTMLButtonElement | null>(null);
useEffect(() => {
@@ -106,6 +145,7 @@ export function QualitySpinDialog(props: QualitySpinDialogProps) {
if (details.segments.length) setSegments(details.segments);
setExpectedTokens(details.expectedTokens);
setJackpotTokens(details.jackpotTokens ?? null);
+ setClientSegments(details.clientSegments ?? []);
})
.catch(() => undefined);
void omnirushQualitySpins()
@@ -162,10 +202,15 @@ export function QualitySpinDialog(props: QualitySpinDialogProps) {
};
const resting = !canSpinNow(quality) && quality.spinsAvailable > 0;
- const tease = result && phase === "result" ? nearMissText(result, jackpotTokens) : null;
+ const tease = result && settled ? nearMissText(result, jackpotTokens) : null;
const celebrate = result?.celebrate ?? "none";
- const busy = phase === "requesting" || phase === "spinning";
+ const busy = phase === "requesting" || phase === "spinning" || (phase === "result" && !settled);
const canSpin = !busy && spinsLeft > 0 && !(phase !== "result" && resting);
+ // Before a spin: the wheel the next spin uses (the richer one while replay-ready spins are
+ // waiting). From the answer on: the wheel the server actually used.
+ const nextIsReplayReady = !result && quality.clientSpinsAvailable > 0 && clientSegments.length > 0;
+ const shownSegments = result ? segments : nextIsReplayReady ? clientSegments : segments;
+ const goldHeader = result ? (result.clientGrade ? "★ replay-ready wheel" : null) : nextIsReplayReady ? "★ replay-ready wheel (next spin)" : null;
return (
<div className="fixed inset-0 z-[76] flex items-center justify-center bg-black/70 p-4 backdrop-blur-sm" data-testid="quality-spin-overlay">
@@ -177,12 +222,12 @@ export function QualitySpinDialog(props: QualitySpinDialogProps) {
data-phase={phase}
className="relative w-full max-w-[520px] overflow-hidden rounded-[28px] border border-white/10 bg-[radial-gradient(ellipse_at_top,#1a2e05_0%,#0b1120_45%,#05070c_100%)] p-6 text-white shadow-2xl shadow-black/60"
>
- {result?.clientGrade ? (
+ {goldHeader ? (
<div
data-testid="quality-client-grade-header"
className="-mx-6 -mt-6 mb-4 bg-gradient-to-r from-amber-500/30 via-amber-300/25 to-amber-500/30 px-6 py-2 text-center text-xs font-bold uppercase tracking-[0.24em] text-amber-200"
>
- ★ client-grade wheel
+ {goldHeader}
</div>
) : null}
<div className="flex items-start justify-between gap-3">
@@ -192,7 +237,7 @@ export function QualitySpinDialog(props: QualitySpinDialogProps) {
<span className="text-[11px] text-white/50">
{spinsLeft} spin{spinsLeft === 1 ? "" : "s"} ready
{!result && quality.clientSpinsAvailable > 0 ? (
- <span className="ms-1 font-semibold text-amber-200" data-testid="quality-dialog-client-spins">· ★{quality.clientSpinsAvailable} client-grade</span>
+ <span className="ms-1 font-semibold text-amber-200" data-testid="quality-dialog-client-spins">· ★{quality.clientSpinsAvailable} replay-ready</span>
) : null}
</span>
</div>
@@ -230,7 +275,7 @@ export function QualitySpinDialog(props: QualitySpinDialogProps) {
<div className="relative mt-4">
<QualityWheel
- segments={segments}
+ segments={shownSegments}
targetIndex={result ? result.segmentIndex : null}
spinId={spinId}
onDone={landed}
@@ -244,17 +289,17 @@ export function QualitySpinDialog(props: QualitySpinDialogProps) {
</div>
<div className="mt-3 flex flex-wrap justify-center gap-1.5" data-testid="quality-wheel-legend">
- {segments.map((segment, index) => (
+ {shownSegments.map((segment, index) => (
<span
key={index}
className={cn(
"rounded-full border px-2 py-0.5 text-[10.5px] tabular-nums",
- result && phase === "result" && index === result.segmentIndex
+ result && settled && index === result.segmentIndex
? "border-[#a3e635] bg-[#a3e635]/20 text-[#ecfccb]"
: "border-white/10 text-white/55",
)}
>
- {compactTokenCount(segment.tokens)} · {segmentOdds(segments, index)}
+ {compactTokenCount(segment.tokens)} · {segmentOdds(shownSegments, index)}
</span>
))}
</div>
@@ -275,13 +320,15 @@ export function QualitySpinDialog(props: QualitySpinDialogProps) {
{celebrate === "jackpot" ? (
<div className="mt-1 text-sm font-semibold uppercase tracking-[0.3em] text-amber-300">Jackpot</div>
) : null}
+ {settled ? (
+ <>
<div className={cn("mt-1 text-sm", result.preview || result.capped ? "text-amber-200" : "text-[#bef264]")} data-testid="quality-spin-payout">
{spinPayoutText(result)}
</div>
<div className="mt-2 flex flex-wrap items-center justify-center gap-2 text-[11px]">
{result.clientGrade ? (
<span className="inline-flex items-center gap-1 rounded-full border border-amber-300/50 bg-amber-300/15 px-2 py-0.5 font-semibold text-amber-200">
- client-grade ★
+ {REPLAY_READY_LABEL}
</span>
) : result.reproducible ? (
<span className="inline-flex items-center gap-1 rounded-full border border-[#a3e635]/40 bg-[#a3e635]/10 px-2 py-0.5 text-[#d9f99d]">
@@ -296,6 +343,8 @@ export function QualitySpinDialog(props: QualitySpinDialogProps) {
{tease ? (
<div className="mt-2 text-sm font-semibold text-amber-300" data-testid="quality-near-miss">{tease}</div>
) : null}
+ </>
+ ) : null}
</div>
) : phase === "error" && error ? (
<div className="pt-4 text-sm text-amber-200" data-testid="quality-spin-error">{error}</div>
@@ -322,7 +371,7 @@ export function QualitySpinDialog(props: QualitySpinDialogProps) {
className="inline-flex min-w-[200px] items-center justify-center gap-2 rounded-full bg-[#a3e635] px-6 py-3 text-sm font-bold uppercase tracking-[0.12em] text-[#1a2e05] shadow-[0_0_30px_rgba(163,230,53,0.45)] transition hover:bg-[#bef264] disabled:cursor-not-allowed disabled:opacity-60"
>
{busy ? <Loader2 className="size-4 animate-spin" aria-hidden="true" /> : null}
- {busy ? "Spinning" : phase === "result" ? `Spin again (${spinsLeft} left)` : spinsLeft > 1 ? `Spin (${spinsLeft} ready)` : "Spin"}
+ {busy ? "Spinning" : settled ? `Spin again (${spinsLeft} left)` : spinsLeft > 1 ? `Spin (${spinsLeft} ready)` : "Spin"}
</button>
) : (
<div className="text-xs text-white/50">No spins left. Good sessions earn more.</div>
@@ -332,6 +381,7 @@ export function QualitySpinDialog(props: QualitySpinDialogProps) {
{totals.spun} spin{totals.spun === 1 ? "" : "s"} so far · {compactTokenCount(totals.paidTokens)} tokens won
</div>
) : null}
+ {totals ? <RecentSpins spins={totals.recent ?? []} /> : null}
</div>
</section>
</div>
diff --git a/apps/app/tests/quality.test.tsx b/apps/app/tests/quality.test.tsx
index 907560b2..f49e377e 100644
--- a/apps/app/tests/quality.test.tsx
+++ b/apps/app/tests/quality.test.tsx
@@ -5,6 +5,7 @@ import {
DEFAULT_WHEEL_SEGMENTS,
NOTICE_SEEN_STORAGE_KEY,
canSpinNow,
+ countUpValue,
jackpotIndex,
refreshAccountStatus,
setQualitySessionId,
@@ -28,7 +29,7 @@ import {
} from "../src/app/lib/quality";
import { QualityTierBadge, SpinButton, streakText } from "../src/react-app/domains/quality/quality-parts";
import { QualityNoticeCard, QualityRewards, SessionReasons, failLabel } from "../src/react-app/domains/quality/quality-notice";
-import { QualitySpinDialog } from "../src/react-app/domains/quality/quality-spin-dialog";
+import { QualitySpinDialog, RecentSpins } from "../src/react-app/domains/quality/quality-spin-dialog";
const quality: AccountQuality = {
tier: "gold",
@@ -253,6 +254,8 @@ describe("revision: fail labels, jackpot, open session", () => {
expect(failLabel("outside_path", { outside_path: "Edits outside the project folder" })).toBe("Edits outside the project folder");
expect(failLabel("outside_path")).toBe("edits outside the project folder");
expect(failLabel("capture_truncated")).toBe("capture truncated");
+ expect(failLabel("old_client")).toBe("old app version");
+ expect(failLabel("x", { x: "Recorded by an old client" })).toBe("Recorded by an old app version");
const html = renderToStaticMarkup(
<SessionReasons
reasons={{
@@ -267,11 +270,11 @@ describe("revision: fail labels, jackpot, open session", () => {
expect(html).toContain("Started in your home folder");
expect(html).toContain("3 code files · 120 lines · no tests");
expect(html).toContain("reproducible ✓");
- expect(html).not.toContain("client-grade ★");
+ expect(html).not.toContain("replay-ready ★");
expect(html).toContain("+2 spins on a richer wheel");
});
- test("the spin button shows a ★ count only for client-grade spins", () => {
+ test("the spin button shows a ★ count only for replay-ready spins", () => {
const plain = renderToStaticMarkup(<SpinButton quality={quality} onClick={() => undefined} />);
expect(plain).not.toContain("quality-client-spins");
const starred = renderToStaticMarkup(<SpinButton quality={{ ...quality, clientSpinsAvailable: 1 }} onClick={() => undefined} />);
@@ -279,7 +282,7 @@ describe("revision: fail labels, jackpot, open session", () => {
expect(starred).toContain("★1");
});
- test("a client-grade session shows the star instead of the check", () => {
+ test("a replay-ready session shows the star instead of the check", () => {
const html = renderToStaticMarkup(
<SessionReasons
reasons={{
@@ -291,7 +294,7 @@ describe("revision: fail labels, jackpot, open session", () => {
}}
/>,
);
- expect(html).toContain("client-grade ★");
+ expect(html).toContain("replay-ready ★");
expect(html).not.toContain("reproducible ✓");
});
@@ -316,3 +319,60 @@ describe("revision: fail labels, jackpot, open session", () => {
useAccountStatusStore.getState().set(null);
});
});
+
+describe("replay-ready wording, history and the count-up", () => {
+ test("users never read the word client", () => {
+ const starred = { ...quality, clientSpinsAvailable: 2, tier: "coaching" as const };
+ const notice = { id: "c-1", kind: "tier-coaching", title: "Here is how to get spins", body: "" };
+ const html = [
+ renderToStaticMarkup(<SpinButton quality={starred} onClick={() => undefined} />),
+ renderToStaticMarkup(<QualityNoticeCard quality={starred} notice={notice} onSpin={() => undefined} onDismiss={() => undefined} />),
+ renderToStaticMarkup(<QualitySpinDialog quality={starred} onClose={() => undefined} />),
+ renderToStaticMarkup(
+ <SessionReasons
+ reasons={{
+ failLabels: {},
+ sessions: [{
+ sessionId: "s", at: null, verdict: null, why: null, fails: ["old_client", "client_tool"], workspace: null, spins: 2, counted: true,
+ reproducible: "pass", reproClient: "pass", clientGrade: true, workSize: null, work: null,
+ }],
+ }}
+ />,
+ ),
+ renderToStaticMarkup(<RecentSpins spins={[{ id: "a", status: "spun", reason: null, reproducible: true, clientGrade: true, sessionId: null, earnedAt: null, expiresAt: null, spunAt: null, prizeTokens: 2_000_000, paidTokens: 2_000_000 }]} />),
+ ].join("\n");
+ // Only attribute values (test ids, data-*) may say "client"; no text a user reads.
+ const text = html.replace(/<[^>]*>/g, " ");
+ expect(text.toLowerCase()).not.toContain("client");
+ expect(text).toContain("old app version");
+ expect(text).toContain("replay-ready ★");
+ expect(text).toContain("Replay-ready sessions earn +2 spins on a richer wheel.");
+ });
+
+ test("recent spins: the last 10, ★ on replay-ready ones", () => {
+ const spins = Array.from({ length: 12 }, (_, index) => ({
+ id: `s${index}`, status: "spun" as const, reason: null, reproducible: true, clientGrade: index % 2 === 0, sessionId: null,
+ earnedAt: null, expiresAt: null, spunAt: null, prizeTokens: 500_000, paidTokens: 500_000,
+ }));
+ const html = renderToStaticMarkup(<RecentSpins spins={spins} />);
+ expect(html.match(/<li /g)?.length).toBe(10);
+ expect(html.match(/data-replay-ready/g)?.length).toBe(5);
+ expect(html).toContain("★ 500K");
+ expect(renderToStaticMarkup(<RecentSpins spins={[]} />)).toBe("");
+ });
+
+ test("the count-up ends exactly on the server's prize and never passes it", () => {
+ for (const value of [0, 250_000, 1_000_000, 1_234_567, 9_999_999, 10_000_000]) {
+ let last = 0;
+ for (let step = 0; step <= 100; step += 1) {
+ const shown = countUpValue(value, step / 100);
+ expect(shown).toBeLessThanOrEqual(value);
+ expect(shown).toBeGreaterThanOrEqual(last);
+ last = shown;
+ }
+ expect(countUpValue(value, 1)).toBe(value);
+ expect(countUpValue(value, 1.5)).toBe(value);
+ if (value > 0) expect(countUpValue(value, 0.999)).toBeLessThan(value);
+ }
+ });
+});
diff --git a/apps/desktop/electron/omnirush-account.mjs b/apps/desktop/electron/omnirush-account.mjs
index 39aaa7a4..206a7900 100644
--- a/apps/desktop/electron/omnirush-account.mjs
+++ b/apps/desktop/electron/omnirush-account.mjs
@@ -13,7 +13,7 @@ import {
writePlaintextCredentialFile,
} from "./plaintext-credential-file.mjs";
import { CLIENT_HEADER, guiClientHeaderValue, parseClientUpdate } from "./update-gate.mjs";
-import { parseAccountQuality, parseFailLabels, parseQualitySessions, profileSessionId, parseSpinResult, parseWheelSegments, spinIdempotencyKey, spinRefusal } from "./quality.mjs";
+import { parseAccountQuality, parseFailLabels, parseQualitySessions, parseSpinHistory, profileSessionId, parseSpinResult, parseWheelSegments, spinIdempotencyKey, spinRefusal } from "./quality.mjs";
const execFileAsync = promisify(execFile);
@@ -1140,15 +1140,12 @@ export function createDesktopOmniRushAccountStore({
}
}
- /** GET /me/quality/spins totals; null when unavailable. */
+ /** GET /me/quality/spins: totals and the last 10 spins; null when unavailable. */
async function qualitySpinTotals() {
try {
const response = await sendAuthorized("/me/quality/spins", { method: "GET" });
if (!response?.ok) return null;
- const payload = await response.json();
- const totals = payload && typeof payload === "object" ? payload.totals : null;
- if (!totals || typeof totals !== "object") return null;
- return { spun: Math.max(0, Number(totals.spun) || 0), paidTokens: Math.max(0, Number(totals.paid_tokens) || 0) };
+ return parseSpinHistory(await response.json());
} catch {
return null;
}
diff --git a/apps/desktop/electron/quality.mjs b/apps/desktop/electron/quality.mjs
index 7da0cb81..b397417e 100644
--- a/apps/desktop/electron/quality.mjs
+++ b/apps/desktop/electron/quality.mjs
@@ -227,6 +227,35 @@ function parseSessionWork(value) {
};
}
+const SPIN_STATUSES = ["ready", "spun", "expired", "forfeit"];
+
+/** GET /me/quality/spins: the totals and the newest `limit` spins. */
+export function parseSpinHistory(value, limit = 10) {
+ if (!value || typeof value !== "object") return null;
+ const totals = value.totals && typeof value.totals === "object" ? value.totals : {};
+ const spins = Array.isArray(value.spins) ? value.spins : [];
+ return {
+ spun: count(totals.spun),
+ paidTokens: count(totals.paid_tokens),
+ recent: spins
+ .filter((spin) => spin && typeof spin === "object" && text(spin.id))
+ .slice(0, limit)
+ .map((spin) => ({
+ id: text(spin.id),
+ status: SPIN_STATUSES.includes(spin.status) ? spin.status : "ready",
+ reason: text(spin.reason),
+ reproducible: spin.reproducible === true,
+ clientGrade: spin.client_grade === true,
+ sessionId: text(spin.session_id),
+ earnedAt: isoTime(spin.earned_at),
+ expiresAt: isoTime(spin.expires_at),
+ spunAt: isoTime(spin.spun_at),
+ prizeTokens: spin.prize_tokens === null || spin.prize_tokens === undefined ? null : count(spin.prize_tokens),
+ paidTokens: spin.paid_tokens === null || spin.paid_tokens === undefined ? null : count(spin.paid_tokens),
+ })),
+ };
+}
+
/** `fail_labels` of GET /me/quality: `{code: label}`, strings only. */
export function parseFailLabels(value) {
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
diff --git a/apps/desktop/electron/quality.test.mjs b/apps/desktop/electron/quality.test.mjs
index 8ed179db..ea2db386 100644
--- a/apps/desktop/electron/quality.test.mjs
+++ b/apps/desktop/electron/quality.test.mjs
@@ -5,7 +5,7 @@ import path from "node:path";
import test from "node:test";
import { createDesktopOmniRushAccountStore } from "./omnirush-account.mjs";
-import { parseAccountQuality, parseSpinResult, spinIdempotencyKey, spinRefusal } from "./quality.mjs";
+import { parseAccountQuality, parseSpinHistory, parseSpinResult, spinIdempotencyKey, spinRefusal } from "./quality.mjs";
const GATEWAY = "http://localhost:8090/omnirush/v1";
const SEGMENTS = [
@@ -262,3 +262,19 @@ test("the profile read names the open session: /device/me?session_id=", async ()
await store.status({ sessionId: "../etc?x=1" });
assert.deepEqual(seen, ["?session_id=ses_abc123", "", ""]);
});
+
+test("spins history: totals and the last 10 spins, each marked when replay-ready", () => {
+ const spins = Array.from({ length: 12 }, (_, index) => ({
+ id: `spin-${index}`, status: index === 0 ? "ready" : "spun", reason: null, reproducible: true, client_grade: index === 1,
+ session_id: "ses_1", earned_at: "2026-10-04T10:00:00Z", expires_at: "2026-10-06T10:00:00Z",
+ spun_at: index === 0 ? null : "2026-10-04T11:00:00Z", prize_tokens: index === 0 ? null : 1000000, paid_tokens: index === 0 ? null : 1000000,
+ }));
+ const history = parseSpinHistory({ spins, totals: { spun: 12, paid_tokens: 18250000 } });
+ assert.equal(history.spun, 12);
+ assert.equal(history.paidTokens, 18250000);
+ assert.equal(history.recent.length, 10);
+ assert.equal(history.recent[0].prizeTokens, null);
+ assert.equal(history.recent[1].clientGrade, true);
+ assert.equal(history.recent[2].clientGrade, false);
+ assert.equal(parseSpinHistory(null), null);
+});
diff --git a/packages/types/src/desktop-ipc.ts b/packages/types/src/desktop-ipc.ts
index e3d979c5..90f48f87 100644
--- a/packages/types/src/desktop-ipc.ts
+++ b/packages/types/src/desktop-ipc.ts
@@ -278,8 +278,23 @@ export type OmniRushQualityDetails = {
failLabels: Record<string, string>;
};
-/** GET /me/quality/spins totals. */
-export type OmniRushQualitySpinTotals = { spun: number; paidTokens: number };
+export type OmniRushQualitySpinRecord = {
+ id: string;
+ status: "ready" | "spun" | "expired" | "forfeit";
+ reason: string | null;
+ reproducible: boolean;
+ /** Earned by a replay-ready (client-grade) session. */
+ clientGrade: boolean;
+ sessionId: string | null;
+ earnedAt: string | null;
+ expiresAt: string | null;
+ spunAt: string | null;
+ prizeTokens: number | null;
+ paidTokens: number | null;
+};
+
+/** GET /me/quality/spins: totals and the newest spins (up to 10). */
+export type OmniRushQualitySpinTotals = { spun: number; paidTokens: number; recent: OmniRushQualitySpinRecord[] };
export type OmniRushWheelSegment = { tokens: number; weight: number };