A local-first multi-agent app development platform, built on PenguinHarness
fix(web,docs): hide Change password in the desktop shell's own window (#349)
Yaowei Zheng424c3d5ea01f
diff --git a/changelog/unreleased/2026-08-19-desktop-change-password.md b/changelog/unreleased/2026-08-19-desktop-change-password.mdnew file mode 100644index 00000000..b0c47aaf--- /dev/null+++ b/changelog/unreleased/2026-08-19-desktop-change-password.md@@ -0,0 +1,28 @@+# Web App: the desktop window stops offering "Change password"++- **Date:** 2026-08-19+- **Type:** fix+- **Scope:** `web`, `docs`+- **PR:** [#349](https://github.com/Prism-Shadow/penguin-harness/pull/349)+- **Issue:** [#346](https://github.com/Prism-Shadow/penguin-harness/issues/346)++[中文版](2026-08-19-desktop-change-password.zh.md)++The sidebar user menu offered **Change password** to every session, including the desktop app's own window — the one session that has never seen a password. The desktop shell signs in by redeeming a one-shot token instead of a login form, and the seed password of a desktop-created data root is fully random and deliberately never printed, so the entry asked its holder to replace a secret they could not name. It is now hidden there, joining the update row, the Users entry and sign-out, which desktop mode already dropped.++## What the entry is keyed on++Visibility is decided by a small pure predicate (`offersChangePassword`), on the pair of fields `GET /api/me` already reports — `desktopMode` (the server was spawned by the desktop shell) and `sessionVia` (this session came from the shell's token rather than the login form). Both must hold, which mirrors the server's own gate on `PUT /api/me/password`, and matters in two directions:++- Keying on `desktopMode` alone — the shape the sibling entries in that menu use — would also strip the control from a browser pointed at the same desktop-mode server over loopback. That session typed a real password at the login form and the server still lets it change one, so it would have been stranded.+- Keying on `sessionVia` alone would strip it from a desktop cookie replayed against a plain `penguin server` on the same shared data root, where the old password is required like anywhere else.++No new mechanism was introduced: `desktopMode` was already the web app's single source for desktop-mode branching, and the change-password dialog was already keyed on `sessionVia`.++## The route is untouched++Nothing was removed or gated server-side. `PUT /api/me/password` stays reachable and fully functional in desktop mode, including its no-old-password path for desktop sessions — the hidden entry is a working control, not a broken one, so a future caller or an automation is unaffected. A desktop-created root that later needs a password a human can actually use gets one offline from `penguin server reset-admin-password`, which the desktop quickstart now points at.++## Regression cover++A unit test pins the rule by value across all four `desktopMode` × `sessionVia` states — absent only in the desktop shell's window, present in the browser and multi-user cases — and asserts the menu consumes the predicate rather than rendering the entry unconditionally, since the frontend suite runs node-only and cannot render the menu itself.diff --git a/changelog/unreleased/2026-08-19-desktop-change-password.zh.md b/changelog/unreleased/2026-08-19-desktop-change-password.zh.mdnew file mode 100644index 00000000..745b9c42--- /dev/null+++ b/changelog/unreleased/2026-08-19-desktop-change-password.zh.md@@ -0,0 +1,28 @@+# Web App:桌面窗口不再提供「修改密码」++- **Date:** 2026-08-19+- **Type:** fix+- **Scope:** `web`, `docs`+- **PR:** [#349](https://github.com/Prism-Shadow/penguin-harness/pull/349)+- **Issue:** [#346](https://github.com/Prism-Shadow/penguin-harness/issues/346)++[English](2026-08-19-desktop-change-password.md)++侧边栏的用户菜单对每一个会话都提供**修改密码**,桌面应用自己的窗口也在其中——而那恰恰是唯一一个从未见过密码的会话。桌面外壳通过兑换一次性令牌登录,而不是走登录表单;由桌面端创建的数据根目录,其种子密码是完全随机且刻意从不打印的。于是这一项等于是在要求它的持有者去替换一个自己根本说不出来的秘密。现在它在那里被隐藏了,加入了更新行、用户管理入口与退出登录的行列——那几项桌面模式早已去掉。++## 这一项以什么为判据++是否显示由一个小的纯函数(`offersChangePassword`)决定,依据的是 `GET /api/me` 本就返回的那一对字段——`desktopMode`(服务端由桌面外壳拉起)与 `sessionVia`(本会话来自外壳的令牌,而非登录表单)。两者必须同时成立,这与服务端自己对 `PUT /api/me/password` 的判据一致,并且在两个方向上都有意义:++- 只看 `desktopMode`——也就是该菜单里其余几项所用的写法——会连带把这项从「浏览器经环回地址连到同一个桌面模式服务端」的会话上一并拿掉。那个会话是在登录表单里真真切切输过密码的,服务端至今仍允许它修改密码,这样一来它就被困住了。+- 只看 `sessionVia`,则会把这项从「桌面会话的 cookie 被拿到同一个共享数据根目录上的普通 `penguin server` 去重放」的情形中拿掉,而在那里旧密码和别处一样是必填的。++没有引入任何新机制:`desktopMode` 本就是 Web 应用做桌面模式分支的唯一来源,而修改密码对话框本就以 `sessionVia` 为判据。++## 路由本身未被改动++服务端没有删除也没有新增任何拦截。`PUT /api/me/password` 在桌面模式下依旧可达且完全可用,包括它为桌面会话准备的免旧密码路径——被隐藏的是一个仍然有效的控件,而不是一个已经坏掉的控件,因此将来的调用方或自动化脚本不受影响。若一个由桌面端创建的数据根目录之后需要一个人类真正能用的密码,可以离线通过 `penguin server reset-admin-password` 获得,桌面端快速上手文档现在也指向了它。++## 回归防护++一个单元测试在 `desktopMode` × `sessionVia` 的全部四种状态上按值钉住了这条规则——仅在桌面外壳自己的窗口中缺席,在浏览器与多用户场景中均存在——并断言菜单确实使用了该判据,而不是无条件渲染这一项;因为前端测试套件运行在 node 环境下,无法真正渲染菜单本身。diff --git a/packages/docs/content/quickstart-desktop.en.md b/packages/docs/content/quickstart-desktop.en.mdindex 68fc353b..fa43bb5c 100644--- a/packages/docs/content/quickstart-desktop.en.md+++ b/packages/docs/content/quickstart-desktop.en.md@@ -3,7 +3,7 @@ title: Desktop appdescription: A double-click install that opens already signed in — the route that asks the least of a terminal.----The full Web experience as a standalone application: it embeds the server and opens already signed in — no login page, no initial password to copy, and nothing to install from a command line. Builds are not signed yet, so macOS and Linux may each need one command the first time the system blocks the app; the box below carries it. It shares its data root with a [CLI install](/quickstart-cli), so the two can be mixed freely.+The full Web experience as a standalone application: it embeds the server and opens already signed in — no login page, no initial password to copy, and nothing to install from a command line. The user menu leaves out **Change password** accordingly: the window signs itself in, so there is no password to type or to change. Builds are not signed yet, so macOS and Linux may each need one command the first time the system blocks the app; the box below carries it. It shares its data root with a [CLI install](/quickstart-cli), so the two can be mixed freely — if you later serve that root over the network with `penguin server`, give its admin a usable password first with `penguin server reset-admin-password` (server stopped), since the desktop app deliberately seeds one nobody can read.## Download and installdiff --git a/packages/docs/content/quickstart-desktop.zh.md b/packages/docs/content/quickstart-desktop.zh.mdindex 2c7183d6..f96c758a 100644--- a/packages/docs/content/quickstart-desktop.zh.md+++ b/packages/docs/content/quickstart-desktop.zh.md@@ -3,7 +3,7 @@ title: 桌面端应用description: 双击安装,打开即已登录——对终端要求最少的那条路线。----完整的 Web 体验打包成一个独立应用:内嵌服务端,双击打开即已登录——没有登录页,不用抄初始密码,也不必从命令行安装任何东西。目前的构建尚未签名,macOS 与 Linux 在系统拦下首次启动时各需要执行一条命令,下面的方框里写了。它与[命令行安装](/quickstart-cli)共用同一个数据目录,两者可以混用。+完整的 Web 体验打包成一个独立应用:内嵌服务端,双击打开即已登录——没有登录页,不用抄初始密码,也不必从命令行安装任何东西。用户菜单里相应地没有**修改密码**这一项:这个窗口自己完成登录,因此既没有要输的密码,也没有要改的密码。目前的构建尚未签名,macOS 与 Linux 在系统拦下首次启动时各需要执行一条命令,下面的方框里写了。它与[命令行安装](/quickstart-cli)共用同一个数据目录,两者可以混用——如果之后想用 `penguin server` 把这个数据目录放到网络上,请先用 `penguin server reset-admin-password`(服务端已停止时执行)给其中的 admin 设一个可用的密码,因为桌面端刻意生成的是一个谁也读不到的初始密码。## 下载与安装diff --git a/packages/web/src/components/layout/sidebar.tsx b/packages/web/src/components/layout/sidebar.tsxindex beb8e754..23e039d2 100644--- a/packages/web/src/components/layout/sidebar.tsx+++ b/packages/web/src/components/layout/sidebar.tsx@@ -37,6 +37,7 @@ import { sessionRowActivity } from "../../lib/session-activity";import type { SessionActivity } from "../../lib/session-activity";import { forgetSession, noteSessionSeen, useSessionSeen } from "../../lib/session-seen";import { apiErrorText } from "../../lib/api-error";+import { offersChangePassword } from "../../lib/account-menu";import { useAuth } from "../../state/auth";import { useLocale } from "../../state/locale";import type { LangPref } from "../../state/locale";@@ -284,7 +285,7 @@ export function Sidebar({onCollapse?: () => void;}) {const navigate = useNavigate();- const { user, logout, desktopMode } = useAuth();+ const { user, logout, desktopMode, sessionVia } = useAuth();const { mode, setMode, fontScale, setFontScale, accent, setAccent, currency, setCurrency } =useTheme();const { lang, locale, setLang } = useLocale();@@ -1756,16 +1757,25 @@ export function Sidebar({</SettingRow></div><div className="mt-1 border-t border-gray-100 pt-1 dark:border-gray-800">- <button- type="button"- className={menuItemClass}- onClick={() => {- setUserOpen(false);- setChangePasswordOpen(true);- }}- >- {S.account.changePassword}- </button>+ {/* Hidden in the desktop shell's own window: it signs in through the shell's+ one-shot token rather than a login form, and the seed password of a+ desktop-created root is fully random and never printed — there is no+ password its holder has seen, or needs. Deliberately NOT keyed on+ desktopMode alone: a browser signed into the same desktop-mode server over+ loopback holds a password session that can, and still does, change it.+ See offersChangePassword for the full rule. */}+ {offersChangePassword({ desktopMode, sessionVia }) && (+ <button+ type="button"+ className={menuItemClass}+ onClick={() => {+ setUserOpen(false);+ setChangePasswordOpen(true);+ }}+ >+ {S.account.changePassword}+ </button>+ )}{/* Admin-only, server-global proxy settings: one menu row opening thedialog (same idiom as Change password above) — the switch, addressinput and their live-save semantics live in ProxySettingsDialog. */}diff --git a/packages/web/src/lib/account-menu.ts b/packages/web/src/lib/account-menu.tsnew file mode 100644index 00000000..4e4cad17--- /dev/null+++ b/packages/web/src/lib/account-menu.ts@@ -0,0 +1,39 @@+/**+ * Which account controls the sidebar user menu offers for the current session.+ *+ * The menu's own desktop-mode rules live inline in sidebar.tsx, but this one needs a+ * two-field condition and a regression test, and vitest runs node-only here (no jsdom, so+ * nothing renders). The rule therefore lives here as a pure predicate that the menu+ * consumes — see test/account-menu.test.ts.+ */+import type { MeResponse } from "@prismshadow/penguin-server/api";++/** The two fields of `GET /api/me` that describe who is asking, and from where. */+export interface AccountMenuSession {+ /** Whether the SERVER was spawned by the desktop shell (single-user mode). */+ desktopMode: boolean;+ /** How THIS session was established: the shell's one-shot token, or the login form. */+ sessionVia: MeResponse["sessionVia"];+}++/**+ * Whether to offer a change-password entry at all.+ *+ * The desktop shell's own window is the one session with no password to change: it signs+ * in through the shell's one-shot token instead of a login form, and the seed password of+ * a desktop-created root is fully random and deliberately never printed, so its holder has+ * never seen one and has nothing to type. A root that later needs a usable password — to+ * be served by `penguin server` instead — is handled offline by `penguin server+ * reset-admin-password` from the machine that owns it.+ *+ * BOTH halves are required, mirroring the server's own gate in `routes/me.ts`.+ * `desktopMode` alone would also strip the control from a browser signed in against the+ * same desktop-mode server over loopback: that session typed a real password and can still+ * change it (pinned by server/test/desktop.test.ts, "keeps requiring oldPassword for+ * password-established sessions in desktop mode"). `sessionVia` alone would strip it from a+ * stale desktop cookie replayed against a plain `penguin server` on the same shared data+ * root, where the server requires the old password like any other session.+ */+export function offersChangePassword(session: AccountMenuSession): boolean {+ return !(session.desktopMode && session.sessionVia === "desktop");+}diff --git a/packages/web/test/account-menu.test.ts b/packages/web/test/account-menu.test.tsnew file mode 100644index 00000000..596c1834--- /dev/null+++ b/packages/web/test/account-menu.test.ts@@ -0,0 +1,70 @@+/**+ * account-menu.ts unit tests: which sessions the sidebar user menu offers a+ * change-password entry to.+ *+ * The rule is pinned by value in all four combinations rather than by shape, because the+ * tempting simplification — keying on `desktopMode` alone, like the sibling sign-out and+ * Users entries do — is wrong in a way nothing else would catch: it also strips the+ * control from a browser signed in against a desktop-mode server over loopback, whose+ * password session can still change its password (server/test/desktop.test.ts, "keeps+ * requiring oldPassword for password-established sessions in desktop mode").+ *+ * vitest runs node-only here (`environment: "node"`, no jsdom), so this asserts against the+ * exported predicate rather than a rendered menu (title-reveal.test.ts convention).+ */+import { readFileSync } from "node:fs";+import { dirname, resolve } from "node:path";+import { fileURLToPath } from "node:url";+import { describe, expect, it } from "vitest";+import { offersChangePassword } from "../src/lib/account-menu";++describe("offersChangePassword", () => {+ it("hides it in the desktop shell's own window — no login form, seed password never shown", () => {+ expect(offersChangePassword({ desktopMode: true, sessionVia: "desktop" })).toBe(false);+ });++ it("offers it on an ordinary multi-user server reached from a browser", () => {+ expect(offersChangePassword({ desktopMode: false, sessionVia: "password" })).toBe(true);+ });++ it("offers it to a browser signed into a desktop-mode server over loopback", () => {+ // That session typed a real password at the login form; the server still lets it+ // change one, so hiding the entry would strand it.+ expect(offersChangePassword({ desktopMode: true, sessionVia: "password" })).toBe(true);+ });++ it("offers it to a desktop cookie replayed against a plain server on the same data root", () => {+ // The shared data root makes this reachable, and there the server requires the old+ // password like any other session — so the control is live and must stay visible.+ expect(offersChangePassword({ desktopMode: false, sessionVia: "desktop" })).toBe(true);+ });++ it("is hidden in exactly one of the four states", () => {+ const states = [true, false].flatMap((desktopMode) =>+ (["password", "desktop"] as const).map((sessionVia) => ({ desktopMode, sessionVia })),+ );+ expect(states.filter((s) => !offersChangePassword(s))).toEqual([+ { desktopMode: true, sessionVia: "desktop" },+ ]);+ });+});++describe("the sidebar user menu", () => {+ const source = readFileSync(+ resolve(dirname(fileURLToPath(import.meta.url)), "../src/components/layout/sidebar.tsx"),+ "utf8",+ );++ it("gates its change-password entry on the predicate rather than rendering it always", () => {+ // Without this the predicate could pass every test above while the menu ignored it,+ // which is the exact regression this change guards against.+ expect(source).toContain("offersChangePassword({ desktopMode, sessionVia })");+ });++ it("leaves the sibling entries on their own desktopMode gate", () => {+ // Sign out and Users are hidden for the whole desktop-mode server, not just the+ // shell's window; the narrower rule above must not be copied onto them by accident.+ expect(source).toContain("{!desktopMode && (");+ expect(source).toContain("{user?.isAdmin && !desktopMode && (");+ });+});