A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 快捷指令保存被拒时编辑框留着,删除被拒时确认框留着(7.49)
lmliheng465cb695ca3e
diff --git a/changelog/unreleased/2026-10-27-shortcuts-write-refusal.md b/changelog/unreleased/2026-10-27-shortcuts-write-refusal.mdnew file mode 100644index 00000000..6d894d36--- /dev/null+++ b/changelog/unreleased/2026-10-27-shortcuts-write-refusal.md@@ -0,0 +1,43 @@+# A refused shortcut save keeps the editor, and a refused delete keeps its card++- **Date:** 2026-10-27+- **Type:** fix+- **Scope:** `web`, `docs`+- **Breaking:** no++[中文](2026-10-27-shortcuts-write-refusal.zh.md)++The draft screen's **My shortcuts** folder puts two questions in front of a write — the shortcut+editor and the delete confirmation — and both answered the click instead of the write. Saving+closed the editor the moment **Save** was pressed, so a server that refused the write (an older+server, a read-only prefs row, a rejected value) rolled the folder back and took the name and the+prompt with it: a prompt the user had just typed, gone, with a toast saying why. Deleting closed+its card the same way, so the refusal arrived as a toast that dismissed itself while the row it+failed to remove was still in the folder.++Both now close only once the write lands. The editor keeps every field exactly as it was — the+name, the prompt, the caret — and draws the server's words above them; the delete card carries the+same words inside `ConfirmModal`'s `refusal` slot. In both, the button that asked is the button+that retries.++## Details++- `packages/web/src/features/chat/shortcuts-folder.tsx`: `persist()` (fire-and-forget, rollback ++ toast) became `write()`, which resolves to the reason or `null` and still rolls the list back on+ a refusal. `saveDraft` and the new `removeDeleting` await it, keep a `busy` flag while it is in+ flight, and only then decide whether to close. `draftRefusal` / `deleteRefusal` are cleared when+ a dialog opens and when it closes, so a reopened dialog never shows the previous attempt's+ reason. The editor's refusal is a `NoticeStrip` (`tone="danger"`, `role="alert"`) at the top of+ the body; the card's is the ui package's own `refusal` slot, with `S.common.refused` as the+ lead-in every other confirmation in the app uses.+- `packages/web/e2e/shortcuts-write-refusal.spec.mjs`: one browser test that refuses the prefs+ write with a 500 (`prefs_readonly`, a code nothing translates, so the sentence on screen can only+ be the probe's), checks that the editor stays open with the rename still in the field and the+ card stays open with the row still listed, then lets the same clicks through and checks both+ land — including the stored list afterwards.+- Docs: the shortcuts section of `packages/docs/content/chat.{zh,en}.md`.++## Compatibility++- No dependency, API, on-disk or protocol change: the same `PUT /api/me/prefs` call, made from the+ dialog instead of beside it. The server is untouched.diff --git a/changelog/unreleased/2026-10-27-shortcuts-write-refusal.zh.md b/changelog/unreleased/2026-10-27-shortcuts-write-refusal.zh.mdnew file mode 100644index 00000000..6b2feda1--- /dev/null+++ b/changelog/unreleased/2026-10-27-shortcuts-write-refusal.zh.md@@ -0,0 +1,36 @@+# 保存快捷指令被拒时编辑框留着,删除被拒时确认框留着++- **Date:** 2026-10-27+- **Type:** fix+- **Scope:** `web`, `docs`+- **Breaking:** no++[English](2026-10-27-shortcuts-write-refusal.md)++草稿页的**我的快捷指令**折叠夹里,有两处是「问一句再写」的 —— 快捷指令的编辑框和删除确认框 ——+它们过去都按「点了」收尾,而不是按「写成了」收尾。保存按下**保存**的那一刻编辑框就关了:服务端一旦拒绝+(旧版服务端、prefs 行只读、取值不合格),折叠夹回滚,连同刚写下的名称与 Prompt 一起消失,只剩一条+自己会走的提示。删除也一样,确认框先关,原因随后以一条会自己消失的提示出现,而它没能删掉的那一行还留在+折叠夹里。++现在两处都等到写入落地才收框。编辑框把每一个字段原样留着 —— 名称、Prompt、光标 —— 并把服务端的话画在+它们上面;删除确认框把同样的话画在 `ConfirmModal` 的 `refusal` 槽里。两处都是「哪个按钮问的,哪个按钮+重试」。++## 细节++- `packages/web/src/features/chat/shortcuts-folder.tsx`:原来的 `persist()`(发出去就不管、回滚 ++ 提示)改成 `write()`,返回原因或 `null`,被拒时仍然回滚列表。`saveDraft` 与新的 `removeDeleting`+ 都等它,等在飞时亮 `busy`,拿到结果再决定收不收框。`draftRefusal` / `deleteRefusal` 在开框与关框时+ 各清一次,重开的框不会带着上一次尝试的原因。编辑框那条是框体顶部的 `NoticeStrip`(`tone="danger"`、+ `role="alert"`);确认框那条走 ui 包自己的 `refusal` 槽,前缀用全 App 一致的 `S.common.refused`。+- `packages/web/e2e/shortcuts-write-refusal.spec.mjs`:一条真浏览器用例,用 500(`prefs_readonly`,+ 一个没有任何翻译的表里也找不到的码,所以屏幕上的那句话只可能来自探针)拒掉对 prefs 的写入,确认编辑框+ 留着、改名还在字段里,确认框留着、那一行还在列表里;然后放行同样的点击,确认两次都落地 —— 包括事后+ 读出服务器上存的列表。+- 文档:`packages/docs/content/chat.{zh,en}.md` 的快捷指令一节。++## 兼容性++- 不改依赖、不改接口、不改磁盘格式与协议:仍是同一个 `PUT /api/me/prefs`,从框里发出而不是从框旁边+ 发出。服务端一行没动。diff --git a/packages/docs/content/chat.en.md b/packages/docs/content/chat.en.mdindex f533cb93..a669f52f 100644--- a/packages/docs/content/chat.en.md+++ b/packages/docs/content/chat.en.md@@ -49,7 +49,7 @@ The last folder, **My shortcuts**, holds up to 3 prompts of your own.2. In **My shortcuts**, select **New shortcut**. The editor opens with the composer's text, and suggests its first line as the **Name**.3. Save.-A shortcut is a name (at most 40 characters) and a prompt (at most 4000 characters). It pins no Skills. Shortcuts are stored per user on the server, so they follow you to another browser or machine. Each row has edit and delete actions, and deleting asks first. The folder header counts them, such as `2/3`, and the **New shortcut** row disappears once 3 are saved; the cap keeps this folder the same height as a built-in one.+A shortcut is a name (at most 40 characters) and a prompt (at most 4000 characters). It pins no Skills. Shortcuts are stored per user on the server, so they follow you to another browser or machine. Each row has edit and delete actions, and deleting asks first. Both a save and a delete close only once the server has the write: if it refuses, the editor (with the name and prompt you typed still in it) or the confirmation card stays open with the reason inside it, and the same button retries. The folder header counts them, such as `2/3`, and the **New shortcut** row disappears once 3 are saved; the cap keeps this folder the same height as a built-in one.## Send a messagediff --git a/packages/docs/content/chat.zh.md b/packages/docs/content/chat.zh.mdindex a06ee0dc..00f39a19 100644--- a/packages/docs/content/chat.zh.md+++ b/packages/docs/content/chat.zh.md@@ -49,7 +49,7 @@ Session 创建后,Workspace 就锁定了;模型仍然可以换,见[切换2. 在**我的快捷指令**中选择**新建快捷指令**。编辑框会带上输入框里的内容,并把第一行建议为**名称**。3. 保存。-一条快捷指令由名称(最多 40 个字符)和 Prompt(最多 4000 个字符)组成,不绑定 Skill。快捷指令按用户保存在服务器上,换浏览器、换机器都还在。每行都有编辑和删除操作,删除前会确认。折叠夹标题会显示用量,例如 `2/3`;存满 3 条后,**新建快捷指令**这一行不再出现。设这个上限,是为了让它和内置折叠夹一样高。+一条快捷指令由名称(最多 40 个字符)和 Prompt(最多 4000 个字符)组成,不绑定 Skill。快捷指令按用户保存在服务器上,换浏览器、换机器都还在。每行都有编辑和删除操作,删除前会确认。保存和删除都等服务器写入成功才收框:被拒绝时编辑框(连同你写下的名称与 Prompt)或那张确认框会留着,原因写在框里,再点一次就是重试。折叠夹标题会显示用量,例如 `2/3`;存满 3 条后,**新建快捷指令**这一行不再出现。设这个上限,是为了让它和内置折叠夹一样高。## 发送消息diff --git a/packages/web/e2e/shortcuts-write-refusal.spec.mjs b/packages/web/e2e/shortcuts-write-refusal.spec.mjsnew file mode 100644index 00000000..53a31de4--- /dev/null+++ b/packages/web/e2e/shortcuts-write-refusal.spec.mjs@@ -0,0 +1,128 @@+/**+ * Regression: the draft screen's shortcuts ask before they write, and a refused write keeps the+ * question — with the server's words inside it — instead of closing on the way out.+ *+ * Both dialogs used to dismiss themselves on the click: the editor closed before the request even+ * left, so a refused save rolled the list back and took the title and prompt the user had just+ * typed with it, and the delete card closed on a toast that dismissed itself while the row it had+ * failed to remove stayed on screen. Both now close only once the write landed: a refusal leaves+ * the editor exactly as it was (fields, caret, the Save button that retries the same write) and+ * the delete card carries `ConfirmModal`'s `refusal` slot.+ *+ * The refusal is a 500 with its own code (`prefs_readonly`), which nothing in the app translates —+ * so the sentence that shows up is the one the probe sent, proving the card reports the server.+ */+import { test, expect } from "@playwright/test";+import { provisionAndLogin } from "./auth.mjs";++const BASE = process.env.BASE_URL;+const MOCK = process.env.MOCK_URL;+const U = "shortcutrefusal";+const P = "password123";++/** The refusal: a code no client translation covers, so its message reaches the dialog verbatim. */+const REFUSAL = { code: "prefs_readonly", message: "prefs are read-only right now" };+const SHOWN = `操作被拒绝:${REFUSAL.message}`;++const SEED = {+ id: "sc-e2e-refusal",+ title: "探针快捷指令",+ prompt: "探针正文:把这段填进输入框。",+};+const RENAMED = "改名后的快捷指令";++/** Fail every write to the prefs route from now on; `off()` lets the same click land. */+async function refusePrefsWrites(page) {+ const turnOff = async () => {+ await page.unroute("**/api/me/prefs");+ };+ await page.route("**/api/me/prefs", async (route) => {+ if (route.request().method() !== "PUT") return route.continue();+ return route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: REFUSAL }),+ });+ });+ return turnOff;+}++test("shortcuts: a refused save and a refused delete keep their dialog, with the server's words", async ({+ page,+}) => {+ await provisionAndLogin(page.request, U, P);++ const projects = await (await page.request.get(`${BASE}/api/projects`)).json();+ const projectId = projects.projects[0].projectId;+ // A Project needs a model, or the onboarding overlay covers the draft page.+ const models = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {+ data: {+ defaultModel: { provider: "custom", modelId: "claude-4-8" },+ models: [+ {+ provider: "custom",+ modelId: "claude-4-8",+ apiKey: "sk-mock",+ baseUrl: MOCK,+ contextWindow: 200000,+ },+ ],+ },+ });+ expect(models.ok(), "put models").toBeTruthy();++ // One shortcut to edit and to delete, seeded through the route the folder reads.+ const seeded = await page.request.put(`${BASE}/api/me/prefs`, {+ data: { draftShortcuts: [SEED] },+ });+ expect(seeded.ok(), "seed a shortcut").toBeTruthy();++ await page.goto(`${BASE}/chat/new`);+ const folder = page.getByRole("button", { name: /我的快捷指令/ });+ await folder.click();+ await expect(page.getByRole("button", { name: SEED.title })).toBeVisible();++ // ---- the editor: a refused save keeps the dialog and the typed text ----------------------+ await page.getByRole("button", { name: "编辑" }).first().click();+ const editor = page.getByRole("dialog");+ await expect(editor).toBeVisible();++ const title = editor.getByLabel("名称");+ await title.fill(RENAMED);++ let turnOff = await refusePrefsWrites(page);+ await editor.getByRole("button", { name: "保存" }).click();++ // Still open, still saying why, and the rename the user typed is still in the field.+ await expect(editor).toBeVisible();+ await expect(editor.getByText(SHOWN)).toBeVisible();+ await expect(title).toHaveValue(RENAMED);++ // The same button retries the same write: the card closes once it lands, and only then.+ await turnOff();+ await editor.getByRole("button", { name: "保存" }).click();+ await expect(editor).toBeHidden();+ await expect(page.getByRole("button", { name: RENAMED })).toBeVisible();++ // ---- the delete card: a refused delete keeps the card and the row ------------------------+ await page.getByRole("button", { name: "删除" }).first().click();+ const card = page.getByRole("dialog");+ await expect(card).toBeVisible();++ turnOff = await refusePrefsWrites(page);+ await card.getByRole("button", { name: "删除" }).click();++ await expect(card).toBeVisible();+ await expect(card.getByText(SHOWN)).toBeVisible();+ // Nothing was removed: the row is still there for the retry the card now offers.+ await expect(page.getByRole("button", { name: RENAMED })).toBeVisible();++ await turnOff();+ await card.getByRole("button", { name: "删除" }).click();+ await expect(card).toBeHidden();+ await expect(page.getByRole("button", { name: RENAMED })).toHaveCount(0);++ // And the write really landed: the stored list no longer holds the shortcut.+ const prefs = await (await page.request.get(`${BASE}/api/me/prefs`)).json();+ expect(prefs.prefs.draftShortcuts).toEqual([]);+});diff --git a/packages/web/src/features/chat/shortcuts-folder.tsx b/packages/web/src/features/chat/shortcuts-folder.tsxindex 2b0ff406..63437629 100644--- a/packages/web/src/features/chat/shortcuts-folder.tsx+++ b/packages/web/src/features/chat/shortcuts-folder.tsx@@ -5,8 +5,12 @@* sends it. Three things about it are its own rather than a built-in folder's:** - **Its rows are server state**, per user (`ui_prefs.draftShortcuts`), fetched on mount and- * written back on every change. Optimistic: the list updates first and rolls back with a toast- * if the write fails, because the value being written is already on screen.+ * written back on every change. Optimistic: the list updates first and rolls back if the write+ * fails, because the value being written is already on screen. The two dialogs that can ask for+ * a write — the shortcut editor and the delete confirmation — close on the write landing, not on+ * the click: a refused save would otherwise throw away the title and prompt the user just typed,+ * and a refused delete would come back as a toast that dismisses itself while the row it failed+ * to remove stays on screen.* - **Its length is the user's**, bounded to SHORTCUT_MAX_COUNT. There is no scroll area and no* pinned height: past the cap the New-shortcut row is what the editor refuses, so the folder* cannot grow into a list that needs scrolling.@@ -24,9 +28,9 @@ import {ICON_SIZE,Input,Modal,+ NoticeStrip,PlusIcon,Textarea,- toastError,} from "@adelie/ui";import * as api from "../../api/endpoints";import { S } from "../../lib/strings";@@ -100,7 +104,13 @@ export function ShortcutsFolder({/** Until the stored list has arrived the body stays blank: the empty state must not flash first. */const [loaded, setLoaded] = useState(false);const [draft, setDraft] = useState<ShortcutDraft | null>(null);+ const [saving, setSaving] = useState(false);+ /** The server's words for the save it refused: shown in the editor, which stays open on them. */+ const [draftRefusal, setDraftRefusal] = useState<string | null>(null);const [deleting, setDeleting] = useState<UserShortcut | null>(null);+ const [removing, setRemoving] = useState(false);+ /** The same, for the delete confirmation. */+ const [deleteRefusal, setDeleteRefusal] = useState<string | null>(null);useEffect(() => {let cancelled = false;@@ -121,26 +131,50 @@ export function ShortcutsFolder({/** Latest list for the rollback value: a stale closure would restore a list two edits old. */const shortcutsRef = useRef(shortcuts);shortcutsRef.current = shortcuts;- const persist = useCallback((next: UserShortcut[]) => {+ /**+ * Writes the list and answers with the refusal (null when it landed). The rows already show+ * `next`, so a refused write puts the previous list back; the caller is the dialog that asked,+ * and it keeps itself open on the returned reason rather than dismissing it with a toast.+ */+ const write = useCallback(async (next: UserShortcut[]): Promise<string | null> => {const rollback = shortcutsRef.current;setShortcuts(next);- api.putPrefs({ draftShortcuts: next }).catch((e: unknown) => {+ try {+ await api.putPrefs({ draftShortcuts: next });+ return null;+ } catch (e) {setShortcuts(rollback);- toastError(apiErrorText(e));- });+ return apiErrorText(e);+ }}, []);const startCreate = () => {// The high-value path: whatever is already in the composer becomes the body of the new// shortcut, with its first line suggested as the name. Both fields stay editable.const text = readComposerText().trim();+ setDraftRefusal(null);setDraft({ id: null, title: defaultShortcutTitle(text), prompt: text });};- const saveDraft = () => {- if (draft === null || shortcutDraftError(draft) !== null) return;- persist(upsertShortcut(shortcuts, draft));- setDraft(null);+ const saveDraft = async () => {+ if (draft === null || saving || shortcutDraftError(draft) !== null) return;+ setSaving(true);+ const refused = await write(upsertShortcut(shortcuts, draft));+ setSaving(false);+ // A refusal leaves the editor exactly as it was: the fields keep what was typed, and the+ // Save button retries the same write.+ if (refused !== null) setDraftRefusal(refused);+ else setDraft(null);+ };++ const removeDeleting = async () => {+ const target = deleting;+ if (target === null || removing) return;+ setRemoving(true);+ const refused = await write(removeShortcut(shortcuts, target.id));+ setRemoving(false);+ if (refused !== null) setDeleteRefusal(refused);+ else setDeleting(null);};const draftError = draft === null ? null : shortcutDraftError(draft);@@ -177,13 +211,19 @@ export function ShortcutsFolder({<RowActionlabel={S.common.edit}glyph={ICONS.pencil}- onClick={() => setDraft({ ...shortcut })}+ onClick={() => {+ setDraftRefusal(null);+ setDraft({ ...shortcut });+ }}/><RowActionlabel={S.common.delete}glyph={ICONS.trash}danger- onClick={() => setDeleting(shortcut)}+ onClick={() => {+ setDeleteRefusal(null);+ setDeleting(shortcut);+ }}/></li>))}@@ -213,14 +253,29 @@ export function ShortcutsFolder({<Modalopen={draft !== null}title={editing ? S.chat.shortcuts.editTitle : S.chat.shortcuts.createTitle}- onClose={() => setDraft(null)}+ onClose={() => {+ setDraft(null);+ setDraftRefusal(null);+ }}widthClass="sm:max-w-lg"footer={<>- <Button size="sm" onClick={() => setDraft(null)}>+ <Button+ size="sm"+ disabled={saving}+ onClick={() => {+ setDraft(null);+ setDraftRefusal(null);+ }}+ >{S.common.cancel}</Button>- <Button size="sm" variant="primary" disabled={draftError !== null} onClick={saveDraft}>+ <Button+ size="sm"+ variant="primary"+ disabled={draftError !== null || saving}+ onClick={() => void saveDraft()}+ >{S.common.save}</Button></>@@ -228,6 +283,17 @@ export function ShortcutsFolder({>{draft !== null && (<div className="space-y-3">+ {/* The save this editor asked for and the server refused: the same words the app's+ confirmations carry, here in the dialog that keeps the typed shortcut. */}+ {draftRefusal !== null && (+ <NoticeStrip+ tone="danger"+ role="alert"+ className="rounded-md border px-2.5 py-2 text-xs"+ >+ <span data-slot="body">{S.common.refused(draftRefusal)}</span>+ </NoticeStrip>+ )}<Inputsize="sm"label={S.chat.shortcuts.titleLabel}@@ -244,7 +310,7 @@ export function ShortcutsFolder({onKeyDown={(e) => {// isComposing guard (the repo's IME convention): accepting a Chinese candidate// fires Enter, which would otherwise save the raw pinyin.- if (e.key === "Enter" && !e.nativeEvent.isComposing) saveDraft();+ if (e.key === "Enter" && !e.nativeEvent.isComposing) void saveDraft();}}/><Textarea@@ -272,11 +338,13 @@ export function ShortcutsFolder({title={S.chat.shortcuts.deleteTitle}confirmLabel={S.common.delete}cancelLabel={S.common.cancel}- onClose={() => setDeleting(null)}- onConfirm={() => {- if (deleting !== null) persist(removeShortcut(shortcuts, deleting.id));+ busy={removing}+ onClose={() => {setDeleting(null);+ setDeleteRefusal(null);}}+ onConfirm={() => void removeDeleting()}+ refusal={deleteRefusal === null ? undefined : S.common.refused(deleteRefusal)}><p className="text-sm text-gray-600 dark:text-gray-300">{deleting !== null ? S.chat.shortcuts.deleteConfirm(deleting.title) : ""}