diff --git a/apps/server/src/guide/topics.ts b/apps/server/src/guide/topics.ts index 911656e47..adccbc7b0 100644 --- a/apps/server/src/guide/topics.ts +++ b/apps/server/src/guide/topics.ts @@ -294,7 +294,7 @@ While this computer is asleep or Threadlines is closed, assistants are told it's Claude's models come from Claude Code itself, so a new one shows up without a Threadlines update. A model Threadlines has no settings of its own for starts on Default reasoning: no level is sent and Claude Code picks one. When Claude Code stops listing a model, the picker stops offering it, but a thread, room agent or setting already on it keeps it. -How much of each plan you've used is on {place:usage}. +How much of each plan you've used is on {place:usage}. The ring beside the composer's send button shows the same limits when you hover or tap it; a short upright tick on each bar marks how much of that limit's window has passed, so a bar filled past its tick is on track to run out before the reset, and its line says "ahead of pace" once it is clearly past. Clicking a limit there opens {place:usage}. An agent's row that says Can't start means its program is on this computer but fails to launch, usually because an update stopped partway. It is not a sign-in problem: the sign-in is still saved. The row has Reinstall when Threadlines can put that same copy back: with npm, bun or Homebrew for a copy they installed, or with the agent's own installer for a copy sitting where that installer puts it (Claude, OpenCode, Cursor, fx, Muse Code, and Codex on Windows). For Pi it reinstalls an npm copy, or installs Threadlines' own copy of Pi. There is no Reinstall for a copy from pnpm, Scoop, winget or Nix, for one at a custom path, or for Grok from xAI's installer (it would switch the release channel); reinstall those the way they were installed. An update that leaves an agent unable to start runs that reinstall once on its own before reporting. Community agents are installed by Threadlines itself and have Install again instead. Antigravity is downloaded and checked by Threadlines, so it isn't covered. diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx index 4fa488416..9505af168 100644 --- a/apps/web/src/components/chat/ChatComposer.tsx +++ b/apps/web/src/components/chat/ChatComposer.tsx @@ -45,6 +45,7 @@ import { useState, } from "react"; import { useQuery } from "@tanstack/react-query"; +import { useNavigate } from "@tanstack/react-router"; import { useDebouncedValue } from "@tanstack/react-pacer"; import { serializeComposerMentionPath } from "~/composerMentionPath"; import type { FileSelectionContextDraft } from "~/lib/fileSelectionContext"; @@ -376,6 +377,8 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions( contextCompactInFlight?: boolean | undefined; contextCompactDisabledReason?: string | null | undefined; }) { + const navigate = useNavigate(); + const openUsage = useCallback(() => void navigate({ to: "/usage" }), [navigate]); return ( <> { } }); + it("marks the pace on a usage bar and opens the Usage page from its row", async () => { + const openUsage = vi.fn(); + const screen = await render( + + window.key === "secondary" ? { ...window, elapsedPercent: 14.3 } : window, + ), + }} + onOpenUsage={openUsage} + />, + ); + + try { + await page.getByRole("button", { name: /Context window/ }).click(); + const paceMarks = document.querySelectorAll("[data-usage-pace-mark]"); + // Only the window that knows its length gets a mark. + expect(paceMarks).toHaveLength(1); + expect(paceMarks[0]?.style.left).toBe("14.3%"); + + await page.getByRole("button", { name: /Weekly 36% used, 14% of the window passed/ }).click(); + expect(openUsage).toHaveBeenCalledTimes(1); + await expect.element(page.getByText("Codex usage")).not.toBeInTheDocument(); + } finally { + await screen.unmount(); + } + }); + it("offers Sign in from the usage popout only when the provider is signed out", async () => { const signIn = vi.fn(); const meter = (notice: NonNullable) => ( diff --git a/apps/web/src/components/chat/ContextWindowMeter.tsx b/apps/web/src/components/chat/ContextWindowMeter.tsx index 63c77571a..2eef4df46 100644 --- a/apps/web/src/components/chat/ContextWindowMeter.tsx +++ b/apps/web/src/components/chat/ContextWindowMeter.tsx @@ -1,5 +1,5 @@ import { ChevronDownIcon } from "lucide-react"; -import { type ReactNode, useCallback, useLayoutEffect, useRef, useState } from "react"; +import { type ReactNode, useCallback, useLayoutEffect, useMemo, useRef, useState } from "react"; import { openExternalUrl } from "~/lib/externalLinks"; import { cn } from "~/lib/utils"; @@ -15,6 +15,7 @@ import { usageMeterColor, } from "~/lib/providerUsage"; import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover"; +import { UsagePaceMark, usagePaceLabel } from "../usage/UsagePaceMark"; import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; function isDomNode(value: unknown): value is Node { @@ -24,34 +25,59 @@ function isDomNode(value: unknown): value is Node { const contextWindowActionButtonClassName = "h-5 shrink-0 cursor-pointer rounded-sm border border-border/70 px-1.5 font-medium text-[10px] text-foreground leading-none transition-colors hover:border-border hover:bg-muted hover:text-foreground focus-visible:border-focus-ring focus-visible:bg-muted focus-visible:outline-none disabled:pointer-events-none disabled:cursor-default disabled:opacity-55"; +/** + * One account usage line: its label and detail over a bar, with the pace mark + * when the window's length is known. With `onOpen` the whole line is a button + * (the Usage page), plain until hover like the rest of a popover's rows. + */ function AccountUsageBar(props: { usageLabel: string; rowLabel: string; detail: string; usedPercent: number; warning: boolean; + elapsedPercent?: number | undefined; + onOpen?: (() => void) | undefined; }) { const meterColor = usageMeterColor(props.usedPercent, props.warning); - return ( -
-
+ const meterLabel = `${props.usageLabel} ${props.rowLabel} ${props.usedPercent}% used${usagePaceLabel(props.elapsedPercent)}`; + const content = ( + <> + {props.rowLabel} {props.detail} -
-
+ -
-
-
+ {props.elapsedPercent !== undefined ? ( + + ) : null} + + + ); + if (!props.onOpen) return
{content}
; + return ( + ); } @@ -156,6 +182,8 @@ export function ContextWindowMeter(props: { contextWindowLabel?: string | null; onResetAccountUsage?: (() => void) | undefined; accountUsageResetInFlight?: boolean | undefined; + /** Opens the Usage page; makes each usage line in the popover a button. */ + onOpenUsage?: (() => void) | undefined; onCompactContext?: (() => void) | undefined; contextCompactDisabled?: boolean | undefined; contextCompactInFlight?: boolean | undefined; @@ -256,6 +284,17 @@ export function ContextWindowMeter(props: { }; }, [isOpen, onOpenChange]); const isMeterActive = isOpen || isPinnedOpen; + const { onOpenUsage } = props; + const openUsage = useMemo( + () => + onOpenUsage + ? () => { + onOpenChange(false); + onOpenUsage(); + } + : undefined, + [onOpenChange, onOpenUsage], + ); return ( @@ -531,6 +570,7 @@ export function ContextWindowMeter(props: { detail={accountUsage.spendControl.detail} usedPercent={accountUsage.spendControl.usedPercent} warning={accountUsage.spendControl.warning} + onOpen={openUsage} /> ) : null} {accountUsage.windows.map((window) => ( @@ -541,6 +581,8 @@ export function ContextWindowMeter(props: { detail={window.detail} usedPercent={window.usedPercent} warning={window.warning} + elapsedPercent={window.elapsedPercent} + onOpen={openUsage} /> ))} {accountUsage.notice ? ( diff --git a/apps/web/src/components/usage/UsagePaceMark.tsx b/apps/web/src/components/usage/UsagePaceMark.tsx new file mode 100644 index 000000000..8d8426679 --- /dev/null +++ b/apps/web/src/components/usage/UsagePaceMark.tsx @@ -0,0 +1,28 @@ +import { cn } from "~/lib/utils"; + +/** + * The pace mark on a usage bar: a short upright tick at how much of the + * window has passed. Usage that stops left of it lasts until the reset. Put it + * inside the bar's track, which needs `relative` and must not clip it. + */ +export function UsagePaceMark(props: { elapsedPercent: number; className?: string }) { + const left = Math.max(0, Math.min(100, props.elapsedPercent)); + return ( + -
+
+ {meter.elapsedPercent !== undefined ? ( + + ) : null}
))} diff --git a/apps/web/src/components/usage/usageView.logic.ts b/apps/web/src/components/usage/usageView.logic.ts index e73eb5bdd..986b5472a 100644 --- a/apps/web/src/components/usage/usageView.logic.ts +++ b/apps/web/src/components/usage/usageView.logic.ts @@ -987,6 +987,8 @@ export interface UsagePlanLimitMeter { readonly usedPercent: number; readonly warning: boolean; readonly reachedLimit: boolean; + /** How much of the window has passed, for the pace mark; see the shared presentation. */ + readonly elapsedPercent?: number; } export interface UsagePlanLimitRow { @@ -1031,6 +1033,7 @@ export function buildUsagePlanLimitRows( usedPercent: window.usedPercent, warning: window.warning, reachedLimit: window.reachedLimit, + ...(window.elapsedPercent !== undefined ? { elapsedPercent: window.elapsedPercent } : {}), })); if (presentation.spendControl) { meters.push({ diff --git a/apps/web/src/lib/providerUsage.test.ts b/apps/web/src/lib/providerUsage.test.ts index 48c5c2850..97162e1b2 100644 --- a/apps/web/src/lib/providerUsage.test.ts +++ b/apps/web/src/lib/providerUsage.test.ts @@ -18,6 +18,7 @@ import { providerRateLimitResetCreditExpirationUrgency, providerUsageNearLimitColor, usageMeterColor, + usageWindowElapsedPercent, } from "./providerUsage"; describe("deriveProviderAccountUsagePresentation", () => { @@ -63,6 +64,7 @@ describe("deriveProviderAccountUsagePresentation", () => { remainingPercent: 63, reachedLimit: false, warning: false, + elapsedPercent: 80, }, ], }); @@ -110,15 +112,17 @@ describe("deriveProviderAccountUsagePresentation", () => { remainingPercent: 63, reachedLimit: false, warning: false, + elapsedPercent: 80, }, { key: "secondary", label: "Weekly", - detail: "64% used · resets in 7d", + detail: "64% used · ahead of pace · resets in 7d", usedPercent: 64, remainingPercent: 36, reachedLimit: false, warning: false, + elapsedPercent: 0, }, ], }); @@ -331,6 +335,7 @@ describe("deriveProviderAccountUsagePresentation", () => { remainingPercent: 63, reachedLimit: false, warning: false, + elapsedPercent: 80, }, ], }); @@ -412,15 +417,17 @@ describe("deriveProviderAccountUsagePresentation", () => { remainingPercent: 69, reachedLimit: false, warning: false, + elapsedPercent: 49.3, }, { key: "secondary", label: "Weekly", - detail: "69% used · resets in 7d", + detail: "69% used · ahead of pace · resets in 7d", usedPercent: 69, remainingPercent: 31, reachedLimit: false, warning: false, + elapsedPercent: 0, }, ], }); @@ -470,25 +477,28 @@ describe("deriveProviderAccountUsagePresentation", () => { remainingPercent: 65, reachedLimit: false, warning: false, + elapsedPercent: 49.3, }, { key: "secondary", label: "Weekly", - detail: "39% used · resets in 7d", + detail: "39% used · ahead of pace · resets in 7d", usedPercent: 39, remainingPercent: 61, reachedLimit: false, warning: false, + elapsedPercent: 0, }, { key: "scoped-0", label: "Fable (weekly)", shortLabel: "Fable", - detail: "78% used · resets in 7d", + detail: "78% used · ahead of pace · resets in 7d", usedPercent: 78, remainingPercent: 22, reachedLimit: false, warning: true, + elapsedPercent: 0, scope: { name: "Fable", period: "Weekly", resetDetail: "resets in 7d" }, }, ]); @@ -543,6 +553,7 @@ describe("deriveProviderAccountUsagePresentation", () => { remainingPercent: 0, reachedLimit: true, warning: true, + elapsedPercent: 0, scope: { name: "Fable", period: "Weekly", resetDetail: "resets in 7d" }, }, ]); @@ -586,6 +597,7 @@ describe("deriveProviderAccountUsagePresentation", () => { remainingPercent: 0, reachedLimit: true, warning: true, + elapsedPercent: 33.3, }, { key: "secondary", @@ -595,6 +607,7 @@ describe("deriveProviderAccountUsagePresentation", () => { remainingPercent: 91, reachedLimit: false, warning: false, + elapsedPercent: 78.7, }, ], }); @@ -643,6 +656,7 @@ describe("deriveProviderAccountUsagePresentation", () => { remainingPercent: 0, reachedLimit: true, warning: true, + elapsedPercent: 33.3, }, { key: "secondary", @@ -652,6 +666,7 @@ describe("deriveProviderAccountUsagePresentation", () => { remainingPercent: 36, reachedLimit: false, warning: false, + elapsedPercent: 78.7, }, ], }); @@ -700,6 +715,7 @@ describe("deriveProviderAccountUsagePresentation", () => { remainingPercent: 58, reachedLimit: false, warning: false, + elapsedPercent: 33.3, }, { key: "secondary", @@ -709,6 +725,7 @@ describe("deriveProviderAccountUsagePresentation", () => { remainingPercent: 0, reachedLimit: true, warning: true, + elapsedPercent: 78.7, }, ], }); @@ -755,6 +772,48 @@ describe("deriveProviderAccountUsagePresentation", () => { }); }); +describe("usageWindowElapsedPercent", () => { + const nowMs = 1_800_000_000_000; + + it("places a reading in its window, and leaves out readings it can't place", () => { + // Two days into a week: 2/7 of the window has passed. + const week = { windowDurationMins: 10_080, resetsAt: (nowMs + 5 * 86_400_000) / 1000 }; + expect(usageWindowElapsedPercent(week, nowMs)).toBe(28.6); + // No window length, or a reset time already past or further off than the window. + expect(usageWindowElapsedPercent({ resetsAt: week.resetsAt }, nowMs)).toBeUndefined(); + expect(usageWindowElapsedPercent({ ...week, resetsAt: nowMs / 1000 - 60 }, nowMs)).toBe( + undefined, + ); + expect( + usageWindowElapsedPercent({ ...week, resetsAt: (nowMs + 8 * 86_400_000) / 1000 }, nowMs), + ).toBeUndefined(); + }); + + it("says a limit is ahead of pace only once usage is clearly past the mark", () => { + const detailAt = (usedPercent: number) => + deriveProviderAccountUsagePresentation( + { + source: "codex-rate-limits", + checkedAt: "2026-04-10T00:00:00.000Z", + limits: [ + { + secondary: { + usedPercent, + remainingPercent: 100 - usedPercent, + resetsAt: (nowMs + 5 * 86_400_000) / 1000, + windowDurationMins: 10_080, + }, + }, + ], + }, + nowMs, + )?.windows[0]?.detail; + // 28.6% of the week has passed. + expect(detailAt(30)).toBe("30% used · resets in 5d"); + expect(detailAt(34)).toBe("34% used · ahead of pace · resets in 5d"); + }); +}); + describe("deriveProviderAccountUsagePresentationForProvider", () => { const nowMs = Date.parse("2026-07-09T12:00:00.000Z"); const claude = ProviderDriverKind.make("claudeAgent"); diff --git a/apps/web/src/lib/providerUsage.ts b/apps/web/src/lib/providerUsage.ts index 8b8080595..6b7ff8138 100644 --- a/apps/web/src/lib/providerUsage.ts +++ b/apps/web/src/lib/providerUsage.ts @@ -27,6 +27,13 @@ export interface ProviderAccountUsageWindowPresentation { readonly remainingPercent: number; readonly reachedLimit: boolean; readonly warning: boolean; + /** + * How much of the window has passed (0-100), where a usage bar draws its + * pace mark: usage left of the mark is on track to last until the reset. + * Unset when the provider doesn't say how long the window is or when it + * resets. + */ + readonly elapsedPercent?: number; /** * Set on a window that caps one model, not the whole account (Claude's * per-model weekly limits): the name the provider gives it ("Fable"), its @@ -225,6 +232,37 @@ function formatReadingAgeDetail(checkedAt: string | undefined, nowMs: number): s : `as of ${Math.floor(elapsedHours / 24)}d ago`; } +/** + * How much of a usage window has passed, from its length and its reset time. + * Unset for a reading that can't be placed in its window: no length, no reset + * time, a reset already past, or one further off than the window is long. + */ +export function usageWindowElapsedPercent( + window: Pick, + nowMs: number, +): number | undefined { + const resetMs = normalizeResetTimestampMs(window.resetsAt); + const minutes = window.windowDurationMins; + if (resetMs === null || minutes === undefined || minutes <= 0) return undefined; + const durationMs = minutes * 60_000; + const remainingMs = resetMs - nowMs; + if (remainingMs <= 0 || remainingMs > durationMs) return undefined; + return Math.round((1 - remainingMs / durationMs) * 1000) / 10; +} + +/** + * How far usage may run past the pace mark before the detail says so, in + * percentage points. Keeps a bar sitting on its mark, or one early in its + * window, from flagging every small burst. + */ +const AHEAD_OF_PACE_MARGIN_PERCENT = 5; + +/** "ahead of pace" when usage is on track to run out before the reset. */ +function formatPaceDetail(usedPercent: number, elapsedPercent: number | undefined): string | null { + if (elapsedPercent === undefined) return null; + return usedPercent - elapsedPercent >= AHEAD_OF_PACE_MARGIN_PERCENT ? "ahead of pace" : null; +} + function formatResetDetail(resetsAt: number | undefined, nowMs: number): string | null { const resetMs = normalizeResetTimestampMs(resetsAt); if (resetMs === null) return null; @@ -395,8 +433,13 @@ function formatUsageWindowPresentation( const blockedByLimitDetail = windowReachedLimit ? null : formatBlockedByLimitDetail(blockingLimitLabels); + const elapsedPercent = usageWindowElapsedPercent(window, nowMs); const detailParts = [ windowReachedLimit ? "limit reached" : `${usedPercent}% used`, + // Pace stops mattering once this limit or another one is the blocker. + windowReachedLimit || blockedByLimitDetail + ? null + : formatPaceDetail(usedPercent, elapsedPercent), blockedByLimitDetail, resetDetail, formatReadingAgeDetail(window.checkedAt, nowMs), @@ -410,6 +453,7 @@ function formatUsageWindowPresentation( remainingPercent, reachedLimit: windowReachedLimit, warning: windowReachedLimit || usedPercent >= USAGE_WARNING_THRESHOLD_PERCENT, + ...(elapsedPercent !== undefined ? { elapsedPercent } : {}), }; } @@ -430,8 +474,10 @@ function formatScopedUsageWindowPresentation( const severityWarning = window.severity !== undefined && window.severity !== "normal"; const resetDetail = formatResetDetail(window.resetsAt, nowMs); const durationLabel = formatUsageWindowDurationLabel(window, ""); + const elapsedPercent = usageWindowElapsedPercent(window, nowMs); const detailParts = [ reachedLimit ? "limit reached" : `${usedPercent}% used`, + reachedLimit ? null : formatPaceDetail(usedPercent, elapsedPercent), resetDetail, formatReadingAgeDetail(window.checkedAt, nowMs), ].filter((part): part is string => Boolean(part)); @@ -447,6 +493,7 @@ function formatScopedUsageWindowPresentation( remainingPercent, reachedLimit, warning: reachedLimit || severityWarning || usedPercent >= USAGE_WARNING_THRESHOLD_PERCENT, + ...(elapsedPercent !== undefined ? { elapsedPercent } : {}), scope: { name: window.scopeLabel, period: durationLabel || null, resetDetail }, }; }