From f91b62f4859452b8b4088e05e1647c377a93d3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E9=98=BF=E6=B1=9F=28Relakkes?= =?UTF-8?q?=29?= Date: Sun, 26 Jul 2026 16:04:04 +0800 Subject: [PATCH] docs(desktop): document the component library and its rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `components/AGENTS.md` is the reference: what to use for a given need, where a new component goes, and the style / i18n / a11y / test rules. `desktop/AGENTS.md` now routes here — the line it replaces ("reuse the existing desktop design system") named nothing to look up and so was not an executable instruction for a person or a model. `docs/component-library-plan.md` keeps the audit evidence and a record of what actually shipped, including where the plan was wrong. Two rules earned their own sections because the library broke them itself: - Overriding a component's utility with `className` does not reliably win. Tailwind sorts same-utility arbitrary values by value and takes the last, regardless of the order they were passed. `hoverTone="danger"` was a no-op with exactly the two tones it was built for, and its test passed because it only asserted the red class was *present*, never that the neutral one was gone. Assert that a class prefix appears exactly once, and prove it by reverting the fix. - The library must not compose user-visible English. `SearchField` built `Clear ${label}`, which made adopting it an i18n regression for every caller that had already translated its clear button. The first repair — falling back to `label` — was worse: the input and its clear button then shared an accessible name and `getByLabelText` matched both. Reuse went from 22% to 75% (524 component uses against 179 remaining native buttons). The remainder are elements that should not be components: `role="tab"`, `menuitem`, `option`, `treeitem`, `gridcell`, whole-row and whole-card click targets, drag handles, and the OS titlebar. --- desktop/AGENTS.md | 3 +- desktop/docs/component-library-plan.md | 678 +++++++++++++++++++++++++ desktop/src/components/AGENTS.md | 250 +++++++++ 3 files changed, 930 insertions(+), 1 deletion(-) create mode 100644 desktop/docs/component-library-plan.md create mode 100644 desktop/src/components/AGENTS.md diff --git a/desktop/AGENTS.md b/desktop/AGENTS.md index 68c53464..94da05fd 100644 --- a/desktop/AGENTS.md +++ b/desktop/AGENTS.md @@ -2,7 +2,8 @@ These rules apply to `desktop/` changes in addition to the root instructions. -- Reuse the existing desktop design system and component/store/API patterns. Use `lucide-react` for common icons and keep operational UI dense, stable, and readable. +- Before adding or editing anything under `desktop/src/components/`, read `desktop/src/components/AGENTS.md`. It is the authoritative index of reusable components, the placement rules for new ones, and the required style/i18n/a11y/test conventions. Do not add a component that duplicates one listed there, and do not add new files to `components/shared/` or `components/common/`. +- Reuse the existing desktop store/API patterns. Use `lucide-react` for common icons and keep operational UI dense, stable, and readable. - Add focused Vitest or Testing Library coverage for UI, store, or API behavior. Run it first, then follow `bun run check:impact`; desktop product changes normally select `bun run check:desktop`. - Chat transport, WebSocket lifecycle, first-turn runtime selection, reconnect, or session changes also require the offline `bun run check:chat-contract` when selected. - Electron host, sidecar, packaging, or version changes require `bun run check:native` when selected. diff --git a/desktop/docs/component-library-plan.md b/desktop/docs/component-library-plan.md new file mode 100644 index 00000000..0775f819 --- /dev/null +++ b/desktop/docs/component-library-plan.md @@ -0,0 +1,678 @@ +# 桌面端组件库:抽取与迁移计划 + +本文是 [`desktop/src/components/AGENTS.md`](../src/components/AGENTS.md) 的配套执行文档,记录审计证据、待抽组件的 API 草稿和分批落地顺序。 + +审计范围:`desktop/src/**`(492 个 ts/tsx,其中 tsx 235 个)。方法:5 个并行只读 agent 分域扫描(设计 token / 交互原语 / 浮层 / 数据展示 / 共享层与工程约束),结论经主控 agent 抽样复核。 + +> **执行状态(2026-07-26)**:阶段 0–8 已全部落地,`shared/` 与 `common/` 已删除。 +> 落地过程中对本文的偏离与新发现记录在 [附录二](#附二实施记录与对本文的偏离)。**改动清单以那一节为准,本文正文保留为当时的审计快照。** + +--- + +## 一、现状:问题不是"开发者偷懒" + +### 1.1 量化 + +| 指标 | 数值 | +|---|---| +| `components/` 下组件 / 测试文件 | 117 / 67 | +| 原生 `