Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/mobile/src/features/usage/UsageRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,12 @@ function UsageCoverageNotice(props: {
props.merged.staleEnvironments.includes(environment.environmentId),
);
const duplicateSources = props.merged.duplicateSources;
const incompleteSources = props.merged.incompleteSources;
if (
failed.length === 0 &&
stale.length === 0 &&
duplicateSources.length === 0 &&
incompleteSources.length === 0 &&
!props.isPartial
) {
return null;
Expand All @@ -489,6 +491,15 @@ function UsageCoverageNotice(props: {
{environment.label} runs an older server version and is excluded from totals.
</Text>
))}
{incompleteSources.map((source) => (
<Text
key={`${source.environmentId}:${source.provider}`}
className="text-sm text-foreground-muted"
>
{source.environmentLabel}&apos;s {PROVIDER_LABEL[source.provider]} usage{" "}
{source.status === "failed" ? "could not be read." : "is incomplete."}
</Text>
))}
{duplicateSources.length > 0 ? (
<Text className="text-sm text-foreground-muted">
Counted once across environments sharing a transcript directory:{" "}
Expand Down
7 changes: 5 additions & 2 deletions apps/mobile/src/features/usage/usageProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ import { useAppearancePreferences } from "../settings/appearance/AppearancePrefe
* Series and table order. The chart stacks providers from the bottom in this
* order, so it also fixes which band sits on top of the bars.
*/
export const PROVIDER_ORDER: readonly UsageProviderKind[] = ["codex", "claude"];
export const PROVIDER_ORDER: readonly UsageProviderKind[] = ["codex", "claude", "opencodex"];

export const PROVIDER_LABEL: Record<UsageProviderKind, string> = {
claude: "Claude Code",
codex: "Codex",
opencodex: "OpenCodex",
};

/**
* Claude's brand orange holds in both themes; Codex is neutral and must flip
* with the theme or its bars vanish against the matching background.
* with the theme or its bars vanish against the matching background. OpenCodex's
* purple accent remains legible in both themes.
*/
export function useProviderColors(): Record<UsageProviderKind, string> {
const { themeAppearance: scheme } = useAppearancePreferences();
return {
claude: "#d97757",
codex: scheme === "dark" ? "#e6e6e6" : "#3c3c43",
opencodex: scheme === "dark" ? "#D39CFF" : "#8B2BE2",
};
}
2 changes: 2 additions & 0 deletions apps/mobile/src/state/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function useUsage(input: UsageSummaryInput): UsageView {
const windowKey = useMemo(
() =>
JSON.stringify({
contractVersion: input.contractVersion,
sinceDay: input.sinceDay,
untilDay: input.untilDay,
timeZone: input.timeZone,
Expand All @@ -86,6 +87,7 @@ export function useUsage(input: UsageSummaryInput): UsageView {
untilTime: input.untilTime,
}),
[
input.contractVersion,
input.sinceDay,
input.untilDay,
input.timeZone,
Expand Down
54 changes: 54 additions & 0 deletions apps/server/src/usage/UsageService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { describe, expect, it } from "@effect/vitest";

import {
classifyUsageSourceExistence,
negotiateUsageContractVersion,
resolveOpenCodexHome,
summarizeSourceReadFailures,
} from "./UsageService.ts";

describe("classifyUsageSourceExistence", () => {
it("keeps I/O failures distinct from missing sources", () => {
expect(classifyUsageSourceExistence(true)).toBe("present");
expect(classifyUsageSourceExistence(false)).toBe("missing");
expect(classifyUsageSourceExistence(null)).toBe("failed");
});
});

describe("resolveOpenCodexHome", () => {
it("prefers OPENCODEX_HOME", () => {
expect(
resolveOpenCodexHome({ OPENCODEX_HOME: "/custom/opencodex" }, "/home/user/.opencodex"),
).toBe("/custom/opencodex");
});

it("uses the standard OpenCodex home by default", () => {
expect(resolveOpenCodexHome({}, "/home/user/.opencodex")).toBe("/home/user/.opencodex");
});
});

describe("negotiateUsageContractVersion", () => {
it("keeps v4 responses decodable for legacy clients", () => {
expect(negotiateUsageContractVersion(undefined)).toBe(4);
expect(negotiateUsageContractVersion(4)).toBe(4);
});

it("serves OpenCodex only to compatible clients", () => {
expect(negotiateUsageContractVersion(5)).toBe(5);
expect(negotiateUsageContractVersion(6)).toBe(5);
});
});

describe("summarizeSourceReadFailures", () => {
it("distinguishes healthy, partial, and failed stores", () => {
expect(summarizeSourceReadFailures(1, 0)).toEqual({ status: "ok", message: null });
expect(summarizeSourceReadFailures(2, 1)).toEqual({
status: "partial",
message: "1 usage file could not be read.",
});
expect(summarizeSourceReadFailures(1, 1)).toEqual({
status: "failed",
message: "1 usage file could not be read.",
});
});
});
Loading
Loading