Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 设置页协同与 Agent 资源占用对齐房规卡片版式 (#2075)
Kirozeng01dbc422f775
diff --git a/apps/desktop/src/renderer/components/settings/AgentResourceSection.tsx b/apps/desktop/src/renderer/components/settings/AgentResourceSection.tsxindex ce3cd2dd49..d48cf815f0 100644--- a/apps/desktop/src/renderer/components/settings/AgentResourceSection.tsx+++ b/apps/desktop/src/renderer/components/settings/AgentResourceSection.tsx@@ -23,6 +23,36 @@ type PresetId = 'full' | 'balanced' | 'background';const PRIORITY_OPTIONS: AgentResourceProcessPriority[] = ['normal', 'low', 'lowest'];const MAX_CONCURRENT_CAP = 64;+/** 档位提示的全部取值(含 activePreset 为 null 时的 custom);顺序即 DOM 叠放顺序。 */+const PRESET_HINT_KEYS = ['full', 'balanced', 'background', 'custom'] as const;++/** 带分割线的多行卡片:卡片自身不留内边距,由每行 `px-4 py-4` 承担(房规见 SubagentModelSection 卡 2)。 */+const CARD_CLASS = cn(+ 'flex flex-col rounded-xl',+ 'bg-[var(--settings-theme-card-bg)]',+ 'border border-[var(--settings-theme-card-border)]',+);+/** 卡片内一行:左侧标签 + 说明,右侧控件相对整块垂直居中(设置页各 section 通用版式)。 */+const ROW_CLASS = 'flex items-center justify-between gap-3 px-4 py-4';+const ROW_LABEL_CLASS = 'text-13 font-medium text-[var(--settings-section-sublabel)]';+const ROW_HINT_CLASS =+ 'text-12 leading-[1.4] text-[var(--settings-section-sublabel)] opacity-70';+/** 行间分割线:左右缩进与行内边距对齐。 */+const DIVIDER_CLASS = 'mx-4 h-px bg-[var(--settings-theme-card-border)]';++/**+ * 数字输入框的框体规格,与设置页统一输入框 `SettingsTextInput` 的 md 档一致+ * (DESIGN.md §4-5:单行输入走药丸圆角;fill 必须是 `--surface-elevated` —— 设置卡片+ * 本身是 ivory,ivory 输入压在 ivory 卡上会与背景同色、填充对比度归零)。+ * 上下调节沿用浏览器原生步进器,不自绘 —— 设置页的控件样式统一是独立议题,留待整体收敛。+ */+const NUMBER_INPUT_CLASS = cn(+ 'h-9 w-24 shrink-0 rounded-full px-4 text-13 outline-none transition-colors',+ 'bg-[var(--surface-elevated)] text-[var(--settings-input-text)]',+ 'border border-[var(--settings-input-border)] focus:border-[var(--settings-input-border-focus)]',+ 'focus:ring-2 focus:ring-[var(--focus-ring)]',+);+/*** 均衡档并发值:本机核数的一半,至少 2(与 main 侧 toolchain-thread-cap 的口径一致),* 且不超过 IPC 校验上限 —— 超高核数工作站(>128 核)算出的值若越过 cap,首个 IPC 写@@ -173,8 +203,10 @@ export function AgentResourceSection() {if (!settings) return null;return (- <div className="flex flex-col gap-6">- <div className="flex items-center justify-between gap-3">+ <div className="flex flex-col gap-[14px]">+ {/* min-h 锁住标题行高度:DefaultOverrideControls 未自定义时返回 null,若不预留+ 高度,首次改动让「已自定义」+ 恢复按钮(30px)出现会把整段往下顶,列表抖一下。 */}+ <div className="flex min-h-[30px] items-center justify-between gap-3"><h2 className="text-16 font-medium leading-[1.2] text-[var(--settings-section-title)]">{t('settings.agentResource.title')}</h2>@@ -196,134 +228,165 @@ export function AgentResourceSection() {/></div>- <p className="text-11 leading-relaxed text-[var(--text-tertiary)]">+ <p className="text-12 leading-[1.45] text-[var(--settings-section-desc)]">{t('settings.agentResource.description')}</p>- {/* 预设条:三个字段的组合快捷方式;都不匹配 = 自定义,均不高亮 */}- <div className="flex flex-col gap-1.5">- <span className="text-12 font-medium text-[var(--text-primary)]">- {t('settings.agentResource.preset')}- </span>- <div- role="radiogroup"- aria-label={t('settings.agentResource.preset')}- className="flex w-fit shrink-0 items-center gap-0.5 rounded-full border border-[var(--settings-theme-card-border)] p-0.5"- >- {(['full', 'balanced', 'background'] as const).map((id) => {- const active = activePreset === id;- return (- <button- key={id}- type="button"- role="radio"- aria-checked={active}- disabled={applyingPreset}- onClick={() => void applyPreset(id)}- className={cn(- 'rounded-full px-2.5 py-1 text-xs transition-colors',- active- ? 'bg-[var(--chat-input-chip-bg)] font-medium text-[var(--msg-assistant-text)]'- : 'text-[var(--settings-section-sublabel)] hover:bg-sidebar-item-hover',- applyingPreset && 'opacity-60',- )}- >- {t(`settings.agentResource.presets.${id}`)}- </button>- );- })}+ <div className={CARD_CLASS}>+ {/* 预设条:三个字段的组合快捷方式;都不匹配 = 自定义,均不高亮。+ 这行提示随档位变化,四语长度差异极大(en full 162 字符 vs custom 53),会在不同+ 行数间跳变、把下方各行顶动。防抖靠下面的 grid 叠放 —— 四段提示占同一格,容器+ 高度恒等于四者中最高的一段,与窗口宽度和语言都无关(固定 min-height 只是下限,+ 长文案照样会溢出撑高)。因为与宽度无关,提示就留在左列、不必独占整行,分段控件+ 才能像同卡其它行一样相对「标签 + 说明」整块垂直居中。 */}+ <div className={ROW_CLASS}>+ <div className="flex min-w-0 flex-col gap-1">+ <p className={ROW_LABEL_CLASS} style={{ letterSpacing: '0.12px' }}>+ {t('settings.agentResource.preset')}+ </p>+ {/* 四段提示全部常挂载、叠在同一个 grid 格里,只有当前档位那段可见(其余+ visibility:hidden —— 不进无障碍树、不可聚焦,但仍参与撑高)。 */}+ <div className="grid">+ {PRESET_HINT_KEYS.map((key) => {+ const shown = (activePreset ?? 'custom') === key;+ return (+ <p+ key={key}+ data-preset-hint={key}+ aria-hidden={!shown || undefined}+ className={cn(+ ROW_HINT_CLASS,+ 'col-start-1 row-start-1',+ !shown && 'invisible',+ )}+ >+ {t(`settings.agentResource.presetHints.${key}`)}+ </p>+ );+ })}+ </div>+ </div>+ <div+ role="radiogroup"+ aria-label={t('settings.agentResource.preset')}+ className="flex w-fit shrink-0 items-center gap-0.5 rounded-full border border-[var(--settings-theme-card-border)] p-0.5"+ >+ {(['full', 'balanced', 'background'] as const).map((id) => {+ const active = activePreset === id;+ return (+ <button+ key={id}+ type="button"+ role="radio"+ aria-checked={active}+ disabled={applyingPreset}+ onClick={() => void applyPreset(id)}+ className={cn(+ 'rounded-full px-2.5 py-1 text-xs transition-colors',+ active+ ? 'bg-[var(--chat-input-chip-bg)] font-medium text-[var(--msg-assistant-text)]'+ : 'text-[var(--settings-section-sublabel)] hover:bg-sidebar-item-hover',+ applyingPreset && 'opacity-60',+ )}+ >+ {t(`settings.agentResource.presets.${id}`)}+ </button>+ );+ })}+ </div></div>- <span className="text-11 text-[var(--text-tertiary)]">- {activePreset- ? t(`settings.agentResource.presetHints.${activePreset}`)- : t('settings.agentResource.presetHints.custom')}- </span>- </div>- {/* 并发命令上限 */}- <label className="flex flex-col gap-1.5">- <span className="text-12 font-medium text-[var(--text-primary)]">- {t('settings.agentResource.maxConcurrent')}- </span>- <span className="text-11 text-[var(--text-tertiary)]">- {t('settings.agentResource.maxConcurrentHint')}- </span>- <input- type="number"- min={0}- max={MAX_CONCURRENT_CAP}- disabled={applyingPreset}- value={maxDraft ?? String(settings.maxConcurrentCommands)}- onChange={(e) => setMaxDraft(e.target.value)}- onBlur={() => {- // 唯一提交点(DESIGN §14.3:Settings 单行编辑器 Enter 不得提交):- // 仅 0..64 的整数且与当前值不同才写盘;非法/未变草稿作废,- // 回显权威值(clamp 会绕过 main 侧硬拒语义,一律拒绝不改写)- const text = (maxDraft ?? '').trim();- setMaxDraft(null);- if (!/^\d+$/.test(text)) return;- const raw = Number(text);- if (raw > MAX_CONCURRENT_CAP) return;- if (raw === settings.maxConcurrentCommands) return;- persist('maxConcurrentCommands', raw);- }}- className="mt-0.5 w-24 rounded-full border border-[var(--border-default)] bg-[var(--surface-elevated)] px-3 py-1.5 text-13 text-[var(--settings-input-text)] outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring-soft)]"- />- </label>+ <div className={DIVIDER_CLASS} />- {/* 进程优先级 */}- <div className="flex flex-col gap-1.5">- <span className="text-12 font-medium text-[var(--text-primary)]">- {t('settings.agentResource.priority')}- </span>- <span className="text-11 text-[var(--text-tertiary)]">- {t('settings.agentResource.priorityHint')}- </span>- <div- role="radiogroup"- aria-label={t('settings.agentResource.priority')}- className="mt-0.5 flex w-fit shrink-0 items-center gap-0.5 rounded-full border border-[var(--settings-theme-card-border)] p-0.5"- >- {PRIORITY_OPTIONS.map((tier) => {- const active = settings.processPriority === tier;- return (- <button- key={tier}- type="button"- role="radio"- aria-checked={active}- disabled={applyingPreset}- onClick={() => persist('processPriority', tier)}- className={cn(- 'rounded-full px-2.5 py-1 text-xs transition-colors',- active- ? 'bg-[var(--chat-input-chip-bg)] font-medium text-[var(--msg-assistant-text)]'- : 'text-[var(--settings-section-sublabel)] hover:bg-sidebar-item-hover',- )}- >- {t(`settings.agentResource.priorityOptions.${tier}`)}- </button>- );- })}+ {/* 并发命令上限 */}+ <label className={ROW_CLASS}>+ <span className="flex min-w-0 flex-col gap-1">+ <span className={ROW_LABEL_CLASS} style={{ letterSpacing: '0.12px' }}>+ {t('settings.agentResource.maxConcurrent')}+ </span>+ <span className={ROW_HINT_CLASS}>+ {t('settings.agentResource.maxConcurrentHint')}+ </span>+ </span>+ <input+ type="number"+ min={0}+ max={MAX_CONCURRENT_CAP}+ disabled={applyingPreset}+ value={maxDraft ?? String(settings.maxConcurrentCommands)}+ onChange={(e) => setMaxDraft(e.target.value)}+ onBlur={() => {+ // 唯一提交点(DESIGN §14.3:Settings 单行编辑器 Enter 不得提交):+ // 仅 0..64 的整数且与当前值不同才写盘;非法/未变草稿作废,+ // 回显权威值(clamp 会绕过 main 侧硬拒语义,一律拒绝不改写)+ const text = (maxDraft ?? '').trim();+ setMaxDraft(null);+ if (!/^\d+$/.test(text)) return;+ const raw = Number(text);+ if (raw > MAX_CONCURRENT_CAP) return;+ if (raw === settings.maxConcurrentCommands) return;+ persist('maxConcurrentCommands', raw);+ }}+ className={NUMBER_INPUT_CLASS}+ />+ </label>++ <div className={DIVIDER_CLASS} />++ {/* 进程优先级 */}+ <div className={ROW_CLASS}>+ <div className="flex min-w-0 flex-col gap-1">+ <p className={ROW_LABEL_CLASS} style={{ letterSpacing: '0.12px' }}>+ {t('settings.agentResource.priority')}+ </p>+ <p className={ROW_HINT_CLASS}>{t('settings.agentResource.priorityHint')}</p>+ </div>+ <div+ role="radiogroup"+ aria-label={t('settings.agentResource.priority')}+ className="flex w-fit shrink-0 items-center gap-0.5 rounded-full border border-[var(--settings-theme-card-border)] p-0.5"+ >+ {PRIORITY_OPTIONS.map((tier) => {+ const active = settings.processPriority === tier;+ return (+ <button+ key={tier}+ type="button"+ role="radio"+ aria-checked={active}+ disabled={applyingPreset}+ onClick={() => persist('processPriority', tier)}+ className={cn(+ 'rounded-full px-2.5 py-1 text-xs transition-colors',+ active+ ? 'bg-[var(--chat-input-chip-bg)] font-medium text-[var(--msg-assistant-text)]'+ : 'text-[var(--settings-section-sublabel)] hover:bg-sidebar-item-hover',+ )}+ >+ {t(`settings.agentResource.priorityOptions.${tier}`)}+ </button>+ );+ })}+ </div></div>- </div>- {/* 工具链限核 */}- <div className="flex items-start justify-between gap-4">- <div className="flex flex-col gap-1.5">- <span className="text-12 font-medium text-[var(--text-primary)]">- {t('settings.agentResource.capThreads')}- </span>- <span className="text-11 text-[var(--text-tertiary)]">- {t('settings.agentResource.capThreadsHint')}- </span>+ <div className={DIVIDER_CLASS} />++ {/* 工具链限核 */}+ <div className={ROW_CLASS}>+ <div className="flex min-w-0 flex-col gap-1">+ <p className={ROW_LABEL_CLASS} style={{ letterSpacing: '0.12px' }}>+ {t('settings.agentResource.capThreads')}+ </p>+ <p className={ROW_HINT_CLASS}>{t('settings.agentResource.capThreadsHint')}</p>+ </div>+ <Switch+ checked={settings.capToolchainThreads}+ disabled={applyingPreset}+ onCheckedChange={(next) => persist('capToolchainThreads', next)}+ aria-label={t('settings.agentResource.capThreads')}+ /></div>- <Switch- checked={settings.capToolchainThreads}- disabled={applyingPreset}- onCheckedChange={(next) => persist('capToolchainThreads', next)}- aria-label={t('settings.agentResource.capThreads')}- /></div></div>);diff --git a/apps/desktop/src/renderer/components/settings/AppearanceSection.tsx b/apps/desktop/src/renderer/components/settings/AppearanceSection.tsxindex 6ff7d8d334..71f5408723 100644--- a/apps/desktop/src/renderer/components/settings/AppearanceSection.tsx+++ b/apps/desktop/src/renderer/components/settings/AppearanceSection.tsx@@ -813,7 +813,7 @@ export function AppearanceSection() {<divrole="radiogroup"aria-label={t('settings.appearance.sidebarCardMode.aria')}- className="flex shrink-0 items-center gap-0.5 rounded-lg border border-[var(--settings-theme-card-border)] p-0.5"+ className="flex shrink-0 items-center gap-0.5 rounded-full border border-[var(--settings-theme-card-border)] p-0.5">{([{ value: 'text', labelKey: 'ccAgent.sidebar.viewStyleList' },@@ -827,7 +827,7 @@ export function AppearanceSection() {aria-checked={sidebarViewMode === opt.value}onClick={() => setSidebarViewMode(opt.value)}className={cn(- 'rounded-md px-2.5 py-1 text-xs transition-colors',+ 'rounded-full px-2.5 py-1 text-xs transition-colors',sidebarViewMode === opt.value? 'bg-[var(--chat-input-chip-bg)] font-medium text-[var(--msg-assistant-text)]': 'text-[var(--settings-section-sublabel)] hover:bg-sidebar-item-hover',diff --git a/apps/desktop/src/renderer/components/settings/CollaborationSection.tsx b/apps/desktop/src/renderer/components/settings/CollaborationSection.tsxindex 0aef3e97ba..cf2bc6cdd1 100644--- a/apps/desktop/src/renderer/components/settings/CollaborationSection.tsx+++ b/apps/desktop/src/renderer/components/settings/CollaborationSection.tsx@@ -4,9 +4,37 @@import { useState, useEffect } from 'react';import { useTranslation } from 'react-i18next';+import { cn } from '@/lib/utils';import { toast } from '@/lib/toast';import { DefaultOverrideControls } from './DefaultOverrideControls';+/** 带分割线的多行卡片:卡片自身不留内边距,由每行 `px-4 py-4` 承担(房规见 SubagentModelSection 卡 2)。 */+const CARD_CLASS = cn(+ 'flex flex-col rounded-xl',+ 'bg-[var(--settings-theme-card-bg)]',+ 'border border-[var(--settings-theme-card-border)]',+);+/** 卡片内一行:左侧标签 + 说明,右侧控件相对整块垂直居中。 */+const ROW_CLASS = 'flex items-center justify-between gap-3 px-4 py-4';+const ROW_LABEL_CLASS = 'text-13 font-medium text-[var(--settings-section-sublabel)]';+const ROW_HINT_CLASS =+ 'text-12 leading-[1.4] text-[var(--settings-section-sublabel)] opacity-70';+/** 行间分割线:左右缩进与行内边距对齐。 */+const DIVIDER_CLASS = 'mx-4 h-px bg-[var(--settings-theme-card-border)]';++/**+ * 数字输入框的框体规格,与设置页统一输入框 `SettingsTextInput` 的 md 档一致+ * (DESIGN.md §4-5:单行输入走药丸圆角;fill 必须是 `--surface-elevated` —— 设置卡片+ * 本身是 ivory,ivory 输入压在 ivory 卡上会与背景同色、填充对比度归零)。+ * 上下调节沿用浏览器原生步进器,不自绘 —— 设置页的控件样式统一是独立议题,留待整体收敛。+ */+const NUMBER_INPUT_CLASS = cn(+ 'h-9 w-24 shrink-0 rounded-full px-4 text-13 outline-none transition-colors',+ 'bg-[var(--surface-elevated)] text-[var(--settings-input-text)]',+ 'border border-[var(--settings-input-border)] focus:border-[var(--settings-input-border-focus)]',+ 'focus:ring-2 focus:ring-[var(--focus-ring)]',+);+interface CollaborationSettings {workerSoftLimit: number;workerHardLimit: number;@@ -52,8 +80,10 @@ export function CollaborationSection() {}return (- <div className="flex flex-col gap-6">- <div className="flex items-center justify-between gap-3">+ <div className="flex flex-col gap-[14px]">+ {/* min-h 锁住标题行高度:DefaultOverrideControls 未自定义时返回 null,若不预留+ 高度,首次改动让「已自定义」+ 恢复按钮(30px)出现会把整段往下顶,列表抖一下。 */}+ <div className="flex min-h-[30px] items-center justify-between gap-3"><h2 className="text-16 font-medium leading-[1.2] text-[var(--settings-section-title)]">{t('settings.collaboration.title')}</h2>@@ -73,69 +103,81 @@ export function CollaborationSection() {/></div>- {/* Worker Soft Limit */}- <label className="flex flex-col gap-1.5">- <span className="text-12 font-medium text-[var(--text-primary)]">- {t('settings.collaboration.workerSoftLimit')}- </span>- <span className="text-11 text-[var(--text-tertiary)]">- {t('settings.collaboration.workerSoftLimitHint')}- </span>- <input- type="number"- min={1}- max={settings.workerHardLimit}- value={settings.workerSoftLimit}- onChange={(e) => {- const v = Math.max(1, Math.min(settings.workerHardLimit, Number(e.target.value) || 1));- persist('workerSoftLimit', v);- }}- className="mt-0.5 w-20 rounded-lg border border-[var(--border-default)] bg-transparent px-3 py-1.5 text-13 text-[var(--settings-input-text)] outline-none"- />- </label>+ <div className={CARD_CLASS}>+ {/* Worker Soft Limit */}+ <label className={ROW_CLASS}>+ <span className="flex min-w-0 flex-col gap-1">+ <span className={ROW_LABEL_CLASS} style={{ letterSpacing: '0.12px' }}>+ {t('settings.collaboration.workerSoftLimit')}+ </span>+ <span className={ROW_HINT_CLASS}>+ {t('settings.collaboration.workerSoftLimitHint')}+ </span>+ </span>+ <input+ type="number"+ min={1}+ max={settings.workerHardLimit}+ value={settings.workerSoftLimit}+ onChange={(e) => {+ const v = Math.max(1, Math.min(settings.workerHardLimit, Number(e.target.value) || 1));+ persist('workerSoftLimit', v);+ }}+ className={NUMBER_INPUT_CLASS}+ />+ </label>- {/* Worker Hard Limit */}- <label className="flex flex-col gap-1.5">- <span className="text-12 font-medium text-[var(--text-primary)]">- {t('settings.collaboration.workerHardLimit')}- </span>- <span className="text-11 text-[var(--text-tertiary)]">- {t('settings.collaboration.workerHardLimitHint')}- </span>- <input- type="number"- min={settings.workerSoftLimit}- max={20}- value={settings.workerHardLimit}- onChange={(e) => {- const v = Math.max(settings.workerSoftLimit, Math.min(20, Number(e.target.value) || settings.workerSoftLimit));- persist('workerHardLimit', v);- }}- className="mt-0.5 w-20 rounded-lg border border-[var(--border-default)] bg-transparent px-3 py-1.5 text-13 text-[var(--settings-input-text)] outline-none"- />- </label>+ <div className={DIVIDER_CLASS} />- {/* Idle Release Minutes */}- <label className="flex flex-col gap-1.5">- <span className="text-12 font-medium text-[var(--text-primary)]">- {t('settings.collaboration.idleRelease')}- </span>- <span className="text-11 text-[var(--text-tertiary)]">- {t('settings.collaboration.idleReleaseHint')}- </span>- <input- type="number"- min={0}- max={120}- value={settings.workerIdleReleaseMinutes}- onChange={(e) => {- const raw = Number(e.target.value);- const v = Math.max(0, Math.min(120, Number.isFinite(raw) ? Math.trunc(raw) : 0));- persist('workerIdleReleaseMinutes', v);- }}- className="mt-0.5 w-20 rounded-lg border border-[var(--border-default)] bg-transparent px-3 py-1.5 text-13 text-[var(--settings-input-text)] outline-none"- />- </label>+ {/* Worker Hard Limit */}+ <label className={ROW_CLASS}>+ <span className="flex min-w-0 flex-col gap-1">+ <span className={ROW_LABEL_CLASS} style={{ letterSpacing: '0.12px' }}>+ {t('settings.collaboration.workerHardLimit')}+ </span>+ <span className={ROW_HINT_CLASS}>+ {t('settings.collaboration.workerHardLimitHint')}+ </span>+ </span>+ <input+ type="number"+ min={settings.workerSoftLimit}+ max={20}+ value={settings.workerHardLimit}+ onChange={(e) => {+ const v = Math.max(settings.workerSoftLimit, Math.min(20, Number(e.target.value) || settings.workerSoftLimit));+ persist('workerHardLimit', v);+ }}+ className={NUMBER_INPUT_CLASS}+ />+ </label>++ <div className={DIVIDER_CLASS} />++ {/* Idle Release Minutes */}+ <label className={ROW_CLASS}>+ <span className="flex min-w-0 flex-col gap-1">+ <span className={ROW_LABEL_CLASS} style={{ letterSpacing: '0.12px' }}>+ {t('settings.collaboration.idleRelease')}+ </span>+ <span className={ROW_HINT_CLASS}>+ {t('settings.collaboration.idleReleaseHint')}+ </span>+ </span>+ <input+ type="number"+ min={0}+ max={120}+ value={settings.workerIdleReleaseMinutes}+ onChange={(e) => {+ const raw = Number(e.target.value);+ const v = Math.max(0, Math.min(120, Number.isFinite(raw) ? Math.trunc(raw) : 0));+ persist('workerIdleReleaseMinutes', v);+ }}+ className={NUMBER_INPUT_CLASS}+ />+ </label>+ </div></div>);}diff --git a/apps/desktop/src/renderer/components/settings/LinkOpenSection.tsx b/apps/desktop/src/renderer/components/settings/LinkOpenSection.tsxindex 1e3393f4d5..d5ec9cc3dc 100644--- a/apps/desktop/src/renderer/components/settings/LinkOpenSection.tsx+++ b/apps/desktop/src/renderer/components/settings/LinkOpenSection.tsx@@ -63,7 +63,7 @@ export function LinkOpenSection() {<divrole="radiogroup"aria-label={t('settings.linkOpen.card.ariaLabel')}- className="flex w-fit shrink-0 items-center gap-0.5 rounded-lg border border-[var(--settings-theme-card-border)] p-0.5"+ className="flex w-fit shrink-0 items-center gap-0.5 rounded-full border border-[var(--settings-theme-card-border)] p-0.5">{OPTIONS.map((opt) => {const active = preference === opt.value;@@ -75,7 +75,7 @@ export function LinkOpenSection() {aria-checked={active}onClick={() => setPreference(opt.value)}className={cn(- 'rounded-md px-2.5 py-1 text-xs transition-colors',+ 'rounded-full px-2.5 py-1 text-xs transition-colors',active? 'bg-[var(--chat-input-chip-bg)] font-medium text-[var(--msg-assistant-text)]': 'text-[var(--settings-section-sublabel)] hover:bg-sidebar-item-hover',diff --git a/apps/desktop/src/renderer/components/settings/WindowBehaviorSection.tsx b/apps/desktop/src/renderer/components/settings/WindowBehaviorSection.tsxindex c14c418d33..09aa9cc07b 100644--- a/apps/desktop/src/renderer/components/settings/WindowBehaviorSection.tsx+++ b/apps/desktop/src/renderer/components/settings/WindowBehaviorSection.tsx@@ -138,7 +138,7 @@ export function WindowBehaviorSection() {<divrole="radiogroup"aria-label={t('settings.windowBehavior.closeBehavior.aria')}- className="flex w-fit shrink-0 items-center gap-0.5 rounded-lg border border-[var(--settings-theme-card-border)] p-0.5"+ className="flex w-fit shrink-0 items-center gap-0.5 rounded-full border border-[var(--settings-theme-card-border)] p-0.5">{(['tray', 'quit'] as const).map((behavior) => {const active = windowsCloseBehavior === behavior;@@ -150,7 +150,7 @@ export function WindowBehaviorSection() {aria-checked={active}onClick={() => setWindowsCloseBehavior(behavior)}className={cn(- 'rounded-md px-2.5 py-1 text-xs transition-colors',+ 'rounded-full px-2.5 py-1 text-xs transition-colors',active? 'bg-[var(--chat-input-chip-bg)] font-medium text-[var(--msg-assistant-text)]': 'text-[var(--settings-section-sublabel)] hover:bg-sidebar-item-hover',diff --git a/apps/desktop/src/renderer/components/settings/__tests__/AgentResourceSectionRendering.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/AgentResourceSectionRendering.test.tsxindex 107bc90a6c..1ff07507ee 100644--- a/apps/desktop/src/renderer/components/settings/__tests__/AgentResourceSectionRendering.test.tsx+++ b/apps/desktop/src/renderer/components/settings/__tests__/AgentResourceSectionRendering.test.tsx@@ -33,6 +33,19 @@ vi.mock('@/components/ui/switch', () => ({),}));+/**+ * 档位提示的四段文案全部常挂载(叠在同一 grid 格里防布局抖动),只有当前档位那段+ * 可见 —— 因此断言必须看可见性,不能看存在性(getByText 对四段一律成立)。+ * 同时校验"有且仅有一段可见",防止叠放层的显隐条件写错导致两段同时露出。+ */+function visiblePresetHint(): string | null {+ const shown = Array.from(document.querySelectorAll('[data-preset-hint]')).filter(+ (el) => el.getAttribute('aria-hidden') !== 'true',+ );+ expect(shown).toHaveLength(1);+ return shown[0]?.textContent ?? null;+}+type WireShape = {maxConcurrentCommands: number;processPriority: 'normal' | 'low' | 'lowest';@@ -93,7 +106,7 @@ describe('AgentResourceSection', () => {});const fullBtn = screen.getByText('settings.agentResource.presets.full');expect(fullBtn.getAttribute('aria-checked')).toBe('true');- expect(screen.getByText('settings.agentResource.presetHints.full')).toBeTruthy();+ expect(visiblePresetHint()).toBe('settings.agentResource.presetHints.full');const numberInput = screen.getByRole('spinbutton') as HTMLInputElement;expect(numberInput.value).toBe('0');expect(screen.getByRole('switch').getAttribute('aria-checked')).toBe('false');@@ -133,7 +146,7 @@ describe('AgentResourceSection', () => {render(<AgentResourceSection />);await waitFor(() => {- expect(screen.getByText('settings.agentResource.presetHints.custom')).toBeTruthy();+ expect(visiblePresetHint()).toBe('settings.agentResource.presetHints.custom');});for (const preset of ['full', 'balanced', 'background']) {expect(diff --git a/apps/desktop/src/renderer/components/settings/__tests__/CollaborationSectionRendering.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/CollaborationSectionRendering.test.tsxnew file mode 100644index 0000000000..18bb3bde6e--- /dev/null+++ b/apps/desktop/src/renderer/components/settings/__tests__/CollaborationSectionRendering.test.tsx@@ -0,0 +1,140 @@+// @vitest-environment jsdom++/**+ * 「协同」设置面板的渲染与写入回归。+ *+ * 这一段的落盘语义与「Agent 资源占用」相反 —— 它是 onChange 即写盘 + clamp(而不是+ * onBlur 提交制 + 拒绝非法值)。这里把该口径钉住,重点覆盖软/硬上限的耦合:软上限的+ * 上界是当前硬上限,不是常量。+ */++import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++import { CollaborationSection } from '../CollaborationSection';++vi.mock('react-i18next', () => ({+ useTranslation: () => ({ t: (key: string) => key }),+}));++vi.mock('@/lib/toast', () => ({+ toast: { error: vi.fn(), success: vi.fn() },+}));++type Wire = {+ workerSoftLimit: number;+ workerHardLimit: number;+ workerIdleReleaseMinutes: number;+ isCustomized?: boolean;+};++const DEFAULT_WIRE: Wire = {+ workerSoftLimit: 5,+ workerHardLimit: 8,+ workerIdleReleaseMinutes: 0,+ isCustomized: false,+};++function installElectronApi(initial: Wire) {+ let current = { ...initial };+ const getCollaborationSettings = vi.fn(async () => current);+ const setCollaborationSetting = vi.fn(async (key: string, value: number) => {+ current = { ...current, [key]: value, isCustomized: true };+ return current;+ });+ const resetCollaborationSettings = vi.fn(async () => {+ current = { ...DEFAULT_WIRE };+ return current;+ });+ (window as unknown as { electronAPI: unknown }).electronAPI = {+ localDb: {+ orcaWorkflows: {+ getCollaborationSettings,+ setCollaborationSetting,+ resetCollaborationSettings,+ },+ },+ };+ return { getCollaborationSettings, setCollaborationSetting, resetCollaborationSettings };+}++/** 三个数字框按 DOM 顺序 = 软上限 / 硬上限 / 空闲释放。 */+function limitInputs(): HTMLInputElement[] {+ return screen.getAllByRole('spinbutton') as HTMLInputElement[];+}++describe('CollaborationSection', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });+ afterEach(() => {+ cleanup();+ });++ it('renders the three worker limits', async () => {+ installElectronApi(DEFAULT_WIRE);+ render(<CollaborationSection />);++ await waitFor(() => {+ expect(screen.getByText('settings.collaboration.title')).toBeTruthy();+ });+ expect(limitInputs().map((i) => i.value)).toEqual(['5', '8', '0']);+ });++ it('writes the soft limit on change without waiting for blur', async () => {+ const api = installElectronApi(DEFAULT_WIRE);+ render(<CollaborationSection />);+ await waitFor(() => limitInputs());++ fireEvent.change(limitInputs()[0]!, { target: { value: '6' } });+ await waitFor(() => {+ expect(api.setCollaborationSetting).toHaveBeenCalledWith('workerSoftLimit', 6);+ });+ });++ it('clamps the soft limit to the current hard limit', async () => {+ const api = installElectronApi(DEFAULT_WIRE); // hard = 8+ render(<CollaborationSection />);+ await waitFor(() => limitInputs());++ // 软上限的上界是硬上限(8),不是常量 —— 越界值被夹到 8 而不是原样落盘+ fireEvent.change(limitInputs()[0]!, { target: { value: '99' } });+ await waitFor(() => {+ expect(api.setCollaborationSetting).toHaveBeenCalledWith('workerSoftLimit', 8);+ });+ });++ it('clamps the hard limit between the current soft limit and 20', async () => {+ const api = installElectronApi(DEFAULT_WIRE); // soft = 5+ render(<CollaborationSection />);+ await waitFor(() => limitInputs());++ // 上界是常量 20+ fireEvent.change(limitInputs()[1]!, { target: { value: '99' } });+ await waitFor(() => {+ expect(api.setCollaborationSetting).toHaveBeenCalledWith('workerHardLimit', 20);+ });++ // 下界是当前软上限(5),不是 1 —— 硬上限必须 >= 软上限+ fireEvent.change(limitInputs()[1]!, { target: { value: '1' } });+ await waitFor(() => {+ expect(api.setCollaborationSetting).toHaveBeenCalledWith('workerHardLimit', 5);+ });+ });++ it('clamps the idle-release minutes into range and truncates decimals', async () => {+ const api = installElectronApi(DEFAULT_WIRE);+ render(<CollaborationSection />);+ await waitFor(() => limitInputs());++ fireEvent.change(limitInputs()[2]!, { target: { value: '999' } });+ await waitFor(() => {+ expect(api.setCollaborationSetting).toHaveBeenCalledWith('workerIdleReleaseMinutes', 120);+ });++ fireEvent.change(limitInputs()[2]!, { target: { value: '7.9' } });+ await waitFor(() => {+ expect(api.setCollaborationSetting).toHaveBeenCalledWith('workerIdleReleaseMinutes', 7);+ });+ });+});