Skip to content

Commit 64ff54c

Browse files
mayoalexanderclaude
andcommitted
feat(desktop): Sign out (option A), and Settings names the credential chat actually uses (#188505, #188506)
Sign out (#187966 D3, option A, decided 2026-10-08): POST /iris/sign-out removes the personal sign-in shared by the desktop and the CLI (IRIS_API_KEY and IRIS_USER_ID from ~/.iris/sdk/.env, the `iris` auth-store entry) and never touches ~/.iris/config.json, so the Hive node key and the daemon keep running. The engine holds the old key in memory, so the tab then restarts the app; the shell's startup check finds no key and opens the sign-in screen. No Rust change. Two-step button (Sign out, then "Sign out and restart"), desktop only. #188506: /iris/me read the panels' token (auth store first) while chat uses IRIS_API_KEY. It now asks with the key chat uses, and says so when the panels resolve a different one. #188505: a Hive node key is refused by whoami (401), which the tab showed as "Can't reach IRIS". /iris/me now reports credential = personal | machine | rejected | none, and each gets its own words and fix ("Signed in as this computer's Hive node", "Your sign-in was refused", Sign in). #188507 (part): the three account calls time out at 8s, and a failed /iris/me reads "Couldn't load your account", not "Not signed in". Verified: live server from source as user 193 (personal, #193 admin) and with the node key as the chat key (machine, panelsDiffer true). Sign-out end to end against a throwaway HOME: removed exactly the three entries, kept other lines, the other auth entry and the node key, and /iris/me then reported machine. Tests: 6 new (account.ts) + 1 (accountStatus); app and opencode typecheck 0 errors with real deps. Not seen: the Sign out row in the native app (browser preview runs as the web platform, which hides it). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01MwMa2AKTS4rsGekZG13sk4
1 parent 4753ea2 commit 64ff54c

9 files changed

Lines changed: 431 additions & 30 deletions

File tree

‎packages/app/src/components/settings-v2/account.test.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, test } from "bun:test"
2-
import { meterView, planLabel, sourceNote, type AccountState } from "./account"
2+
import { accountStatus, meterView, planLabel, sourceNote, type AccountState } from "./account"
33

44
const allowance = (over: Partial<AccountState["allowance"]> = {}): AccountState["allowance"] => ({
55
measured: true,
@@ -50,4 +50,31 @@ describe("Settings > Account (#187966)", () => {
5050
expect(sourceNote("~/.iris/sdk/.env")).toBe("Credential from ~/.iris/sdk/.env.")
5151
expect(sourceNote("none (not signed in)")).toBeNull()
5252
})
53+
54+
test("each reason nobody is signed in as a person gets its own words and fix (#188505, #188507)", () => {
55+
const base = {
56+
measured: true,
57+
signedIn: false,
58+
panelsDiffer: false,
59+
tokenSource: "",
60+
id: null,
61+
name: null,
62+
email: null,
63+
} as any
64+
expect(accountStatus(undefined, false)).toMatchObject({ title: "Couldn't load your account", action: "retry" })
65+
expect(accountStatus({ ...base, credential: "machine" }, false)).toMatchObject({
66+
title: "Signed in as this computer's Hive node",
67+
action: "sign-in",
68+
})
69+
expect(accountStatus({ ...base, credential: "rejected", reason: "fl-api 401" }, false).title).toBe(
70+
"Your sign-in was refused",
71+
)
72+
expect(accountStatus({ ...base, credential: "none" }, false).action).toBe("sign-in")
73+
expect(
74+
accountStatus({ ...base, credential: "personal", measured: false, reason: "fl-api 502" }, false),
75+
).toMatchObject({
76+
title: "Can't reach IRIS",
77+
action: "retry",
78+
})
79+
})
5380
})

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

Lines changed: 128 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Show, createResource } from "solid-js"
1+
import { Component, Show, createResource, createSignal } from "solid-js"
22
import { ButtonV2 } from "@opencode-ai/ui/v2/button-v2"
33
import { usePlatform } from "@/context/platform"
44
import { useServer } from "@/context/server"
@@ -18,6 +18,8 @@ export interface AccountState {
1818
measured: boolean
1919
reason?: string
2020
signedIn: boolean
21+
credential: "personal" | "machine" | "rejected" | "none"
22+
panelsDiffer: boolean
2123
tokenSource: string
2224
id: number | null
2325
name: string | null
@@ -77,6 +79,47 @@ export function planLabel(p: AccountState["plan"] | undefined): string {
7779
return p.plan.charAt(0).toUpperCase() + p.plan.slice(1)
7880
}
7981

82+
/**
83+
* The headline when nobody is signed in as a person. Each cause gets its own words, because
84+
* each has a different fix: "can't reach IRIS" for a refused key sent people to check their
85+
* network (#188505), and a failed /iris/me read as "Not signed in" (#188507).
86+
*/
87+
export function accountStatus(
88+
state: AccountState | undefined,
89+
loading: boolean,
90+
): { title: string; description: string; action: "retry" | "sign-in" } {
91+
if (loading) return { title: "Checking…", description: "", action: "retry" }
92+
if (!state) {
93+
return {
94+
title: "Couldn't load your account",
95+
description: "IRIS on this computer did not answer. Your sign-in is probably fine.",
96+
action: "retry",
97+
}
98+
}
99+
if (state.credential === "machine") {
100+
return {
101+
title: "Signed in as this computer's Hive node",
102+
description: "Chat and Atlas act as this machine, not as you. Sign in to use your own account.",
103+
action: "sign-in",
104+
}
105+
}
106+
if (state.credential === "rejected") {
107+
return {
108+
title: "Your sign-in was refused",
109+
description: `IRIS rejected the saved key (${state.reason ?? "401"}). It may have expired or been revoked. Sign in again.`,
110+
action: "sign-in",
111+
}
112+
}
113+
if (state.credential === "none") {
114+
return { title: "Not signed in", description: "Sign in to use IRIS models, Atlas and Hive.", action: "sign-in" }
115+
}
116+
return {
117+
title: "Can't reach IRIS",
118+
description: `IRIS did not answer (${state.reason ?? "no response"}). You may still be signed in.`,
119+
action: "retry",
120+
}
121+
}
122+
80123
/** A Hive node key can sign the app in, but it belongs to a machine, not to a person. */
81124
export function sourceNote(source: string): string | null {
82125
if (source.includes("node_api_key")) return "Signed in with this machine's Hive node key, not a personal sign-in."
@@ -100,6 +143,22 @@ export const SettingsAccountV2: Component = () => {
100143
},
101144
)
102145

146+
const [signOutStep, setSignOutStep] = createSignal<"idle" | "confirm" | "working" | "failed">("idle")
147+
const canSignOut = () => platform.platform === "desktop"
148+
const signOut = async () => {
149+
setSignOutStep("working")
150+
try {
151+
const base = server.current?.http?.url?.replace(/\/$/, "")
152+
const res = await (platform.fetch ?? globalThis.fetch)(`${base}/iris/sign-out`, { method: "POST" })
153+
if (!res.ok) throw new Error(String(res.status))
154+
// The engine still holds the old key in memory. Restarting re-runs the startup check,
155+
// which finds no key and opens the sign-in screen.
156+
await platform.restart()
157+
} catch {
158+
setSignOutStep("failed")
159+
}
160+
}
161+
103162
const meter = () => meterView(me()?.allowance)
104163
const upgradeUrl = () => {
105164
const p = me()?.plan
@@ -116,20 +175,27 @@ export const SettingsAccountV2: Component = () => {
116175
<SettingsListV2>
117176
<Show
118177
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-
}
178+
fallback={(() => {
179+
const s = () => accountStatus(me(), me.loading)
180+
return (
181+
<SettingsRowV2 title={s().title} description={s().description}>
182+
<span data-action="account-status">
183+
<Show
184+
when={s().action === "sign-in" && platform.openSignIn}
185+
fallback={
186+
<ButtonV2 size="normal" variant="neutral" onClick={() => void refetch()}>
187+
Retry
188+
</ButtonV2>
189+
}
190+
>
191+
<ButtonV2 size="normal" variant="neutral" onClick={() => platform.openSignIn?.()}>
192+
Sign in
193+
</ButtonV2>
194+
</Show>
195+
</span>
196+
</SettingsRowV2>
197+
)
198+
})()}
133199
>
134200
<SettingsRowV2
135201
title={me()?.name ?? me()?.email ?? `User ${me()?.id}`}
@@ -144,6 +210,13 @@ export const SettingsAccountV2: Component = () => {
144210
</>
145211
)}
146212
</Show>
213+
<Show when={me()?.panelsDiffer}>
214+
<br />
215+
<span data-action="account-panels-differ">
216+
Atlas and Hive panels are using a different saved sign-in from chat. Sign out and back in to
217+
line them up.
218+
</span>
219+
</Show>
147220
</>
148221
}
149222
>
@@ -163,6 +236,46 @@ export const SettingsAccountV2: Component = () => {
163236
</Show>
164237
</div>
165238
</SettingsRowV2>
239+
<Show when={canSignOut()}>
240+
<SettingsRowV2
241+
title="Sign out"
242+
description={
243+
signOutStep() === "failed"
244+
? "Sign-out failed. Nothing was restarted. Try again."
245+
: "Signs this computer out of IRIS, in the app and in the iris command. Hive keeps running on this machine."
246+
}
247+
>
248+
<span data-action="account-sign-out">
249+
<Show
250+
when={signOutStep() === "confirm" || signOutStep() === "working"}
251+
fallback={
252+
<ButtonV2 size="normal" variant="neutral" onClick={() => setSignOutStep("confirm")}>
253+
Sign out
254+
</ButtonV2>
255+
}
256+
>
257+
<div class="flex items-center gap-2">
258+
<ButtonV2
259+
size="normal"
260+
variant="neutral"
261+
disabled={signOutStep() === "working"}
262+
onClick={() => setSignOutStep("idle")}
263+
>
264+
Cancel
265+
</ButtonV2>
266+
<ButtonV2
267+
size="normal"
268+
variant="neutral"
269+
disabled={signOutStep() === "working"}
270+
onClick={() => void signOut()}
271+
>
272+
{signOutStep() === "working" ? "Signing out…" : "Sign out and restart"}
273+
</ButtonV2>
274+
</div>
275+
</Show>
276+
</span>
277+
</SettingsRowV2>
278+
</Show>
166279
</Show>
167280
</SettingsListV2>
168281
</div>

‎packages/app/src/context/platform.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ type PlatformBase = {
4747
/** Restart the app */
4848
restart(): Promise<void>
4949

50+
/** Open the IRIS sign-in window (desktop). Absent where there is nothing to open. */
51+
openSignIn?(): void
52+
5053
/** Send a system notification */
5154
notify(title: string, description?: string, onClick?: () => void): Promise<void>
5255

‎packages/desktop/src/index.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ const platform: Platform = {
176176
await relaunch()
177177
},
178178

179+
openSignIn: () => {
180+
void invoke("open_login_window").catch(() => undefined)
181+
},
182+
179183
notify: async (title, description, onClick) => {
180184
const granted = await isPermissionGranted().catch(() => false)
181185
const permission = granted ? "granted" : await requestPermission().catch(() => "denied")
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* Who the app acts as, and signing out of it (#187966 K1, D3).
3+
*
4+
* Kept apart from platform.ts so it can be tested against a temporary home directory: these
5+
* functions decide what gets DELETED from a person's machine, and they take `home` as an
6+
* argument rather than reading the real one.
7+
*/
8+
import { existsSync, readFileSync, writeFileSync } from "fs"
9+
import path from "path"
10+
11+
/**
12+
* The credential CHAT uses. The model provider reads `process.env.IRIS_API_KEY` and nothing else
13+
* (provider.ts), which the desktop sets from ~/.iris/sdk/.env when it spawns the engine. The
14+
* panels resolve their own token and prefer the auth store, so the two can differ (#188506).
15+
* Settings must name the one the agent acts as.
16+
*/
17+
export function agentCredential(env: NodeJS.ProcessEnv, fallback: () => { token: string | null; source: string }) {
18+
const key = env.IRIS_API_KEY?.trim()
19+
if (key) return { token: key, source: "~/.iris/sdk/.env (the key chat uses)" }
20+
return fallback()
21+
}
22+
23+
/** The Hive node key: it belongs to the machine, and sign-out must leave it alone. */
24+
export function readNodeKey(home: string): string | null {
25+
try {
26+
const cfg = path.join(home, ".iris", "config.json")
27+
if (!existsSync(cfg)) return null
28+
const key = JSON.parse(readFileSync(cfg, "utf-8"))?.node_api_key
29+
return typeof key === "string" && key ? key : null
30+
} catch {
31+
return null
32+
}
33+
}
34+
35+
export type CredentialKind = "personal" | "machine" | "none"
36+
37+
export function credentialKind(token: string | null, nodeKey: string | null): CredentialKind {
38+
if (!token) return "none"
39+
if (nodeKey && token === nodeKey) return "machine"
40+
return "personal"
41+
}
42+
43+
const PERSONAL_ENV_KEYS = ["IRIS_API_KEY", "IRIS_USER_ID"]
44+
45+
/** ~/.iris/sdk/.env without the personal sign-in. Every other line is kept as written. */
46+
export function stripPersonalKeys(text: string): { text: string; removed: string[] } {
47+
const removed: string[] = []
48+
const kept = text.split("\n").filter((line) => {
49+
const t = line.trim().replace(/^export\s+/, "")
50+
const key = PERSONAL_ENV_KEYS.find((k) => t.startsWith(`${k}=`))
51+
if (key) removed.push(key)
52+
return !key
53+
})
54+
return { text: kept.join("\n"), removed }
55+
}
56+
57+
/**
58+
* Sign out of IRIS on this machine, for the desktop AND the CLI, which share these files
59+
* (option A, decided 2026-10-08). Removes the personal key and user id from ~/.iris/sdk/.env
60+
* and the `iris` entry from the auth store. Leaves ~/.iris/config.json alone: the Hive node key
61+
* is the machine's, and removing it would take this machine off Hive.
62+
*
63+
* The running engine still holds its key in memory. The caller must restart it; the desktop
64+
* restarts the app, whose startup check then shows the sign-in screen.
65+
*/
66+
export function signOutPersonal(opts: { home: string; dataDir: string }): { removed: string[] } {
67+
const removed: string[] = []
68+
69+
const envFile = path.join(opts.home, ".iris", "sdk", ".env")
70+
if (existsSync(envFile)) {
71+
const before = readFileSync(envFile, "utf-8")
72+
const after = stripPersonalKeys(before)
73+
if (after.removed.length) {
74+
// writeFileSync keeps the existing file's permissions (0600 from sign-in).
75+
writeFileSync(envFile, after.text)
76+
removed.push(...after.removed.map((k) => `~/.iris/sdk/.env ${k}`))
77+
}
78+
}
79+
80+
const authFile = path.join(opts.dataDir, "auth.json")
81+
if (existsSync(authFile)) {
82+
try {
83+
const store = JSON.parse(readFileSync(authFile, "utf-8"))
84+
if (store && typeof store === "object" && "iris" in store) {
85+
delete store.iris
86+
writeFileSync(authFile, JSON.stringify(store, null, 2))
87+
removed.push("auth store: iris")
88+
}
89+
} catch {
90+
// An unreadable auth store is not ours to rewrite. Report nothing removed from it.
91+
}
92+
}
93+
94+
return { removed }
95+
}

0 commit comments

Comments
 (0)