Skip to content

Commit 4753ea2

Browse files
mayoalexanderclaude
andcommitted
feat(desktop): Settings > Account — who you are, your plan, this week's allowance (#187966 K1+K2)
The app acted "as you" without being able to say who you were. Settings now opens with Account: name, email and user id, the plan, and one allowance meter. - /iris/me: identity + plan + allowance in one read, so the tab cannot show one person's name beside another's usage. Identity comes from /api/v1/auth/whoami, the route `iris auth whoami` reads, so Settings and the CLI cannot disagree. /api/user would have: for user 193 it says "FREELABEL" where whoami says "admin". - The allowance is read with ?peek=1. Opening Settings never consumes the weekly notice. - One meter, the gate's own usageFraction() (ADR-01). "Could not ask" and "no limit" have their own words and are never drawn as an empty bar. An unmeasured plan reads "Unknown", never "Free". - A Hive node key signing the app in is called out as a machine, not a person. Verified on a compiled build (cf-ray 0, so not the hosted UI): user 193 shows admin / [email protected] / #193 / Staff / $0.24 of $5.00 (5%) with the 90% mark, matching `iris auth whoami` field by field. Tests: 5 new. desktop-native locale detection fails identically without this change. Sign-out (D3) is not in this commit: it needs a decision about the Hive node key. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01MwMa2AKTS4rsGekZG13sk4
1 parent 5df8dad commit 4753ea2

6 files changed

Lines changed: 393 additions & 3 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { describe, expect, test } from "bun:test"
2+
import { meterView, planLabel, sourceNote, type AccountState } from "./account"
3+
4+
const allowance = (over: Partial<AccountState["allowance"]> = {}): AccountState["allowance"] => ({
5+
measured: true,
6+
window: "week",
7+
capUsd: 5,
8+
uncapped: false,
9+
spendUsd: 3.1,
10+
fraction: 0.62,
11+
resetsAt: "2026-10-12T00:00:00Z",
12+
thresholds: [0.9],
13+
upgradeUrl: null,
14+
...over,
15+
})
16+
17+
describe("Settings > Account (#187966)", () => {
18+
test("the meter is the gate's fraction, in dollars, with the one 90% notice marked", () => {
19+
const m = meterView(allowance(), new Date("2026-10-07T00:00:00Z"))
20+
expect(m.kind).toBe("meter")
21+
if (m.kind !== "meter") return
22+
expect(m.percent).toBe(62)
23+
expect(m.text).toBe("$3.10 of $5.00 this week (62%)")
24+
expect(m.marks).toEqual([90])
25+
expect(m.resets).toStartWith("Resets ")
26+
})
27+
28+
test("could-not-ask and no-limit are never drawn as an empty bar", () => {
29+
expect(meterView(undefined).kind).toBe("unknown")
30+
expect(meterView(allowance({ measured: false })).kind).toBe("unknown")
31+
expect(meterView(allowance({ fraction: null })).kind).toBe("unknown")
32+
expect(meterView(allowance({ uncapped: true, capUsd: null, fraction: null })).kind).toBe("uncapped")
33+
})
34+
35+
test("over the cap clamps to 100 rather than drawing past the bar", () => {
36+
const m = meterView(allowance({ fraction: 1.4, spendUsd: 7 }))
37+
expect(m.kind === "meter" && m.percent).toBe(100)
38+
})
39+
40+
test("an unmeasured plan is Unknown, never Free; staff have no plan", () => {
41+
expect(planLabel(undefined)).toBe("Unknown")
42+
expect(planLabel({ measured: false, plan: "free", paid: false, uncapped: false, upgradeUrl: null })).toBe("Unknown")
43+
expect(planLabel({ measured: true, plan: "pro", paid: true, uncapped: false, upgradeUrl: null })).toBe("Pro")
44+
// User 193 as measured on 2026-10-07: staff, paid, and still capped at $5.
45+
expect(planLabel({ measured: true, plan: null, paid: true, uncapped: false, upgradeUrl: null })).toBe("Staff")
46+
})
47+
48+
test("a Hive node key is called out as a machine, not a person", () => {
49+
expect(sourceNote("~/.iris/config.json (node_api_key)")).toContain("Hive node key")
50+
expect(sourceNote("~/.iris/sdk/.env")).toBe("Credential from ~/.iris/sdk/.env.")
51+
expect(sourceNote("none (not signed in)")).toBeNull()
52+
})
53+
})
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
import { Component, Show, createResource } from "solid-js"
2+
import { ButtonV2 } from "@opencode-ai/ui/v2/button-v2"
3+
import { usePlatform } from "@/context/platform"
4+
import { useServer } from "@/context/server"
5+
import { SettingsListV2 } from "./parts/list"
6+
import { SettingsRowV2 } from "./parts/row"
7+
import "./settings-v2.css"
8+
9+
/**
10+
* Settings > Account (#187966 K1 + K2): who the app is acting as, their plan, and how much of the
11+
* week's allowance is left.
12+
*
13+
* The copy is English, like the rest of the IRIS-only surfaces (titlebar pills, Upgrade dialog):
14+
* the locale files carry the upstream app's strings, and parity requires every key in all 61.
15+
*/
16+
17+
export interface AccountState {
18+
measured: boolean
19+
reason?: string
20+
signedIn: boolean
21+
tokenSource: string
22+
id: number | null
23+
name: string | null
24+
email: string | null
25+
plan: { measured: boolean; plan: string | null; paid: boolean | null; uncapped: boolean; upgradeUrl: string | null }
26+
allowance: {
27+
measured: boolean
28+
window: string
29+
capUsd: number | null
30+
uncapped: boolean
31+
spendUsd: number | null
32+
fraction: number | null
33+
resetsAt: string | null
34+
thresholds: number[]
35+
upgradeUrl: string | null
36+
}
37+
}
38+
39+
export type MeterView =
40+
| { kind: "unknown"; text: string }
41+
| { kind: "uncapped"; text: string }
42+
| { kind: "meter"; percent: number; text: string; resets: string | null; marks: number[] }
43+
44+
const usd = (n: number) => `$${n.toFixed(2)}`
45+
46+
/**
47+
* One meter, read from the gate (ADR-01). "Could not ask" and "no limit" each get their own words.
48+
* Neither is ever drawn as an empty bar, which would tell someone they have used nothing.
49+
*/
50+
export function meterView(a: AccountState["allowance"] | undefined, now = new Date()): MeterView {
51+
if (!a?.measured) return { kind: "unknown", text: "Usage is unavailable right now. This is not zero." }
52+
if (a.uncapped || a.capUsd === null) return { kind: "uncapped", text: "No weekly limit on this account." }
53+
if (a.fraction === null || a.spendUsd === null)
54+
return { kind: "unknown", text: "Usage is unavailable right now. This is not zero." }
55+
const percent = Math.max(0, Math.min(100, Math.round(a.fraction * 100)))
56+
return {
57+
kind: "meter",
58+
percent,
59+
text: `${usd(a.spendUsd)} of ${usd(a.capUsd)} this ${a.window} (${percent}%)`,
60+
resets: resetsText(a.resetsAt, now),
61+
marks: a.thresholds.filter((t) => t > 0 && t < 1).map((t) => Math.round(t * 100)),
62+
}
63+
}
64+
65+
function resetsText(iso: string | null, now: Date): string | null {
66+
if (!iso) return null
67+
const at = new Date(iso)
68+
if (Number.isNaN(at.getTime())) return null
69+
const day = at.toLocaleDateString(undefined, { weekday: "long", month: "short", day: "numeric" })
70+
return at.getTime() <= now.getTime() ? "Resets now" : `Resets ${day}`
71+
}
72+
73+
/** The server reports staff as plan null (fl-iris-api 4eda580d). An unmeasured plan is "Unknown", never "Free". */
74+
export function planLabel(p: AccountState["plan"] | undefined): string {
75+
if (!p?.measured) return "Unknown"
76+
if (p.plan === null) return "Staff"
77+
return p.plan.charAt(0).toUpperCase() + p.plan.slice(1)
78+
}
79+
80+
/** A Hive node key can sign the app in, but it belongs to a machine, not to a person. */
81+
export function sourceNote(source: string): string | null {
82+
if (source.includes("node_api_key")) return "Signed in with this machine's Hive node key, not a personal sign-in."
83+
if (source.startsWith("none")) return null
84+
return `Credential from ${source}.`
85+
}
86+
87+
export const SettingsAccountV2: Component = () => {
88+
const platform = usePlatform()
89+
const server = useServer()
90+
91+
const [me, { refetch }] = createResource(
92+
() => server.current?.http?.url?.replace(/\/$/, ""),
93+
async (base): Promise<AccountState | undefined> => {
94+
try {
95+
const res = await (platform.fetch ?? globalThis.fetch)(`${base}/iris/me`)
96+
return res.ok ? ((await res.json()) as AccountState) : undefined
97+
} catch {
98+
return undefined
99+
}
100+
},
101+
)
102+
103+
const meter = () => meterView(me()?.allowance)
104+
const upgradeUrl = () => {
105+
const p = me()?.plan
106+
return p?.measured && p.paid === false ? (p.upgradeUrl ?? me()?.allowance.upgradeUrl ?? null) : null
107+
}
108+
109+
return (
110+
<>
111+
<div class="settings-v2-tab-header">
112+
<h2 class="settings-v2-tab-title">Account</h2>
113+
</div>
114+
<div class="settings-v2-tab-body">
115+
<div class="settings-v2-section">
116+
<SettingsListV2>
117+
<Show
118+
when={me()?.signedIn}
119+
fallback={
120+
<SettingsRowV2
121+
title={me.loading ? "Checking…" : me()?.measured === false ? "Can't reach IRIS" : "Not signed in"}
122+
description={
123+
me()?.measured === false
124+
? `IRIS did not answer (${me()?.reason ?? "no response"}). You may still be signed in.`
125+
: "Sign in to use IRIS models, Atlas and Hive."
126+
}
127+
>
128+
<ButtonV2 size="normal" variant="neutral" onClick={() => void refetch()}>
129+
Retry
130+
</ButtonV2>
131+
</SettingsRowV2>
132+
}
133+
>
134+
<SettingsRowV2
135+
title={me()?.name ?? me()?.email ?? `User ${me()?.id}`}
136+
description={
137+
<>
138+
<span data-action="account-email">{me()?.email ?? "No email on this account"}</span>
139+
<Show when={sourceNote(me()?.tokenSource ?? "")}>
140+
{(note) => (
141+
<>
142+
<br />
143+
{note()}
144+
</>
145+
)}
146+
</Show>
147+
</>
148+
}
149+
>
150+
<span data-action="account-id" class="text-text-weak">
151+
#{me()?.id}
152+
</span>
153+
</SettingsRowV2>
154+
<SettingsRowV2 title="Plan" description={upgradeUrl() ? "Upgrade for a higher weekly allowance." : ""}>
155+
<div class="flex items-center gap-2">
156+
<span data-action="account-plan">{planLabel(me()?.plan)}</span>
157+
<Show when={upgradeUrl()}>
158+
{(url) => (
159+
<ButtonV2 size="normal" variant="neutral" onClick={() => platform.openExternal(url())}>
160+
Upgrade
161+
</ButtonV2>
162+
)}
163+
</Show>
164+
</div>
165+
</SettingsRowV2>
166+
</Show>
167+
</SettingsListV2>
168+
</div>
169+
170+
<Show when={me()?.signedIn}>
171+
<div class="settings-v2-section">
172+
<h3 class="settings-v2-section-title">This week's allowance</h3>
173+
<SettingsListV2>
174+
<div data-component="settings-v2-row" data-action="account-allowance">
175+
<div data-slot="settings-v2-row-copy" style={{ width: "100%" }}>
176+
<div data-slot="settings-v2-row-title">{meter().text}</div>
177+
<Show
178+
when={meter().kind === "meter" ? (meter() as Extract<MeterView, { kind: "meter" }>) : undefined}
179+
>
180+
{(m) => (
181+
<>
182+
<div
183+
role="meter"
184+
aria-valuemin={0}
185+
aria-valuemax={100}
186+
aria-valuenow={m().percent}
187+
aria-label="Weekly allowance used"
188+
style={{
189+
position: "relative",
190+
height: "8px",
191+
"border-radius": "4px",
192+
"margin-top": "8px",
193+
background: "var(--border-base, rgba(127, 127, 127, 0.35))",
194+
}}
195+
>
196+
<div
197+
style={{
198+
width: `${m().percent}%`,
199+
height: "100%",
200+
"border-radius": "4px",
201+
background:
202+
m().percent >= 90
203+
? "var(--icon-critical-base, #d14343)"
204+
: "var(--icon-interactive-base, #3b82f6)",
205+
}}
206+
/>
207+
{m().marks.map((mark) => (
208+
<div
209+
title={`You are told once at ${mark}%`}
210+
style={{
211+
position: "absolute",
212+
left: `${mark}%`,
213+
top: "-3px",
214+
width: "2px",
215+
height: "14px",
216+
background: "var(--text-weak, #888)",
217+
}}
218+
/>
219+
))}
220+
</div>
221+
<div data-slot="settings-v2-row-description" style={{ "margin-top": "6px" }}>
222+
{[m().resets, m().marks.length ? `You are told once at ${m().marks.join("%, ")}%.` : null]
223+
.filter(Boolean)
224+
.join(" · ")}
225+
</div>
226+
</>
227+
)}
228+
</Show>
229+
</div>
230+
</div>
231+
</SettingsListV2>
232+
</div>
233+
</Show>
234+
</div>
235+
</>
236+
)
237+
}

‎packages/app/src/components/settings-v2/dialog-settings-v2.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { SettingsProvidersV2 } from "./providers"
1010
import { SettingsModelsV2 } from "./models"
1111
import "./settings-v2.css"
1212
import { SettingsServersV2 } from "./servers"
13+
import { SettingsAccountV2 } from "./account"
1314
import { useDialog } from "@opencode-ai/ui/context/dialog"
1415
import { useLayout } from "@/context/layout"
1516
import { useTabs } from "@/context/tabs"
@@ -57,6 +58,10 @@ export const DialogSettings: Component<{
5758
<div class="flex flex-col gap-1.5">
5859
<TabsV2.SectionTitle>{language.t("settings.section.desktop")}</TabsV2.SectionTitle>
5960
<div class="flex flex-col gap-1.5 w-full">
61+
<TabsV2.Trigger value="account">
62+
<Icon name="circle-check" />
63+
Account
64+
</TabsV2.Trigger>
6065
<TabsV2.Trigger value="general">
6166
<Icon name="sliders" />
6267
{language.t("settings.tab.general")}
@@ -93,6 +98,9 @@ export const DialogSettings: Component<{
9398
</div>
9499
</div>
95100
</TabsV2.List>
101+
<TabsV2.Content value="account" class="settings-v2-panel">
102+
<SettingsAccountV2 />
103+
</TabsV2.Content>
96104
<TabsV2.Content value="general" class="settings-v2-panel">
97105
<SettingsGeneralV2 sessionID={props.sessionID} />
98106
</TabsV2.Content>

‎packages/opencode/src/iris/platform.ts‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,11 @@ const EMPTY_ALLOWANCE: Allowance = {
535535
* is a deliberate server-side design — asking whether a notice is due and marking it delivered
536536
* cannot be two steps without a race — and it makes this function unusual enough to say twice.
537537
*/
538-
export async function fetchAllowance(): Promise<PlatformResult<Allowance>> {
538+
export async function fetchAllowance(opts: { peek?: boolean } = {}): Promise<PlatformResult<Allowance>> {
539539
try {
540-
const res = await irisFetch("/api/v6/allowance/me", IRIS_API)
540+
// peek: the same numbers without consuming the notice (fl-iris-api 4eda580d). The Account tab
541+
// reads with it, because opening Settings must not eat somebody's only warning of the week.
542+
const res = await irisFetch(opts.peek ? "/api/v6/allowance/me?peek=1" : "/api/v6/allowance/me", IRIS_API)
541543
if (!res.ok) return { measured: false, reason: `iris-api ${res.status}`, data: EMPTY_ALLOWANCE }
542544
const j = (await res.json()) as any
543545
const num = (v: unknown) => (typeof v === "number" && Number.isFinite(v) ? v : null)
@@ -574,6 +576,37 @@ export async function fetchAllowance(): Promise<PlatformResult<Allowance>> {
574576
}
575577
}
576578

579+
/**
580+
* Who the app is acting as (#187966 K1). Read from /api/v1/auth/whoami, the route `iris auth whoami`
581+
* reads, so Settings and the CLI cannot name the same credential differently. /api/user would
582+
* have worked too, and it does disagree: for user 193 it says "FREELABEL", whoami says "admin".
583+
*/
584+
export interface Me {
585+
id: number | null
586+
name: string | null
587+
email: string | null
588+
}
589+
590+
export async function fetchMe(): Promise<PlatformResult<Me>> {
591+
const empty: Me = { id: null, name: null, email: null }
592+
try {
593+
const res = await irisFetch("/api/v1/auth/whoami")
594+
if (!res.ok) return { measured: false, reason: `fl-api ${res.status}`, data: empty }
595+
const u = ((await res.json()) as any)?.data
596+
const text = (v: unknown) => (typeof v === "string" && v.trim() ? v.trim() : null)
597+
return {
598+
measured: true,
599+
data: {
600+
id: typeof u?.id === "number" ? u.id : null,
601+
name: text(u?.name),
602+
email: text(u?.email),
603+
},
604+
}
605+
} catch (e) {
606+
return { measured: false, reason: e instanceof Error ? e.message : String(e), data: empty }
607+
}
608+
}
609+
577610
export interface Plan {
578611
/** free | pro | business, or null for staff, who have no plan. */
579612
plan: string | null

0 commit comments

Comments
 (0)