Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 灵动岛徽标吸附不再吞掉用户的自由宽度 (#719)
Dashc0a482a1a68e
diff --git a/apps/desktop/native/agent-island/macos-agent-island-helper.swift b/apps/desktop/native/agent-island/macos-agent-island-helper.swiftindex 91d6aea691..c09d6abdc6 100644--- a/apps/desktop/native/agent-island/macos-agent-island-helper.swift+++ b/apps/desktop/native/agent-island/macos-agent-island-helper.swift@@ -1957,8 +1957,8 @@ struct AgentIslandLayout: Equatable {let layoutScreenMetrics = hardwareNotchLayoutEnabled? screenMetrics: screenMetrics.disablingHardwareNotchLayout()- // Only the compact hardware-notch layout reserves room for the badge; skip the font- // measurement on every other layout tick.+ // Only the compact hardware-notch layout reserves room for the badge; every other+ // layout tick skips the reservation entirely and passes 0.let compactBadgeWidth = !expanded && layoutScreenMetrics.hasNotch && hasSession? PillBadge.intrinsicWidth(pillSnapshot: state.pillSnapshot, compact: true): 0@@ -2116,7 +2116,11 @@ struct AgentIslandLayout: Equatable {if desiredWidth <= hiddenThreshold {return hiddenWidth}- if desiredWidth <= basicWidth {+ // Only widths at or below the badge-independent basic snap upgrade to the current+ // (possibly wider) basic. Comparing against `basicWidth` would swallow free widths+ // sitting between the two snap points, and `persistedCompactContentWidth` would then+ // canonicalize them away — permanently overwriting the user's preference.+ if desiredWidth <= baseBasicWidth {return basicWidth}return clampedWidthdiff --git a/apps/desktop/src/shared/__tests__/agentIslandCompactBadgeWidth.test.ts b/apps/desktop/src/shared/__tests__/agentIslandCompactBadgeWidth.test.tsindex bf6ecf47de..255f3c6d46 100644--- a/apps/desktop/src/shared/__tests__/agentIslandCompactBadgeWidth.test.ts+++ b/apps/desktop/src/shared/__tests__/agentIslandCompactBadgeWidth.test.ts@@ -72,9 +72,12 @@ describe('getAgentIslandCompactBadgeWidth', () => {}});- it('单个计数走 22pt 最小宽度,active/total 才随位数变宽', () => {+ it('单个计数在 22pt 最小宽度内不变宽,超出后同样按位数增长', () => {expect(getAgentIslandCompactBadgeWidth({ activeSessionCount: 0, sessionCount: 1 })).toBe(22);expect(getAgentIslandCompactBadgeWidth({ activeSessionCount: 0, sessionCount: 12 })).toBe(22);+ // 位数够多时单个计数也会超过最小宽度 —— 公式对两种形态都是按 segment 长度算的。+ expect(getAgentIslandCompactBadgeWidth({ activeSessionCount: 0, sessionCount: 1234 }))+ .toBeGreaterThan(22);const oneDigit = getAgentIslandCompactBadgeWidth({ activeSessionCount: 1, sessionCount: 2 });const twoDigits = getAgentIslandCompactBadgeWidth({ activeSessionCount: 11, sessionCount: 12 });expect(twoDigits).toBeGreaterThan(oneDigit);@@ -379,6 +382,47 @@ describe('snapAgentIslandCompactHardwareContentWidth', () => {expect(narrow).toBeLessThan(wide);});+ it('介于旧 basic 与新 basic 之间的自由宽度不被吞掉', () => {+ // 回归:用户此前把岛拖到 280(旧 basic 264 之上,属自由宽度)。若按放大后的 basicWidth+ // 判定,280 会被"升级"成 306,再被 native 的持久化归一化写回 264,永久覆盖用户偏好。+ const notchWidth = 200;+ const screenMetrics = { hasNotch: true, notchWidth };+ const baseBasic = notchWidth + AGENT_ISLAND_COMPACT_HARDWARE_ACTIVE_EXTRA_WIDTH;+ for (const pillSnapshot of [+ { activeSessionCount: 11, sessionCount: 12 },+ { activeSessionCount: 123, sessionCount: 456 },+ ]) {+ const widened = getAgentIslandDefaultContentWidth({+ expanded: false,+ hasSession: true,+ screenMetrics,+ pillSnapshot,+ });+ for (const freeWidth of [baseBasic + 16, widened - 4]) {+ expect(+ snapAgentIslandCompactHardwareContentWidth({+ desiredWidth: freeWidth,+ clampedWidth: freeWidth,+ maxWidth: 920,+ hasSession: true,+ screenMetrics,+ pillSnapshot,+ }),+ `自由宽度 ${freeWidth} 被吸附掉了`,+ ).toBe(freeWidth);+ }+ // 恰好停在旧 basic 吸附位的仍然跟随到新 basic。+ expect(snapAgentIslandCompactHardwareContentWidth({+ desiredWidth: baseBasic,+ clampedWidth: baseBasic,+ maxWidth: 920,+ hasSession: true,+ screenMetrics,+ pillSnapshot,+ })).toBe(widened);+ }+ });+it('不传 pillSnapshot 时吸附行为与旧实现完全一致', () => {const notchWidth = 200;const screenMetrics = { hasNotch: true, notchWidth };diff --git a/apps/desktop/src/shared/agentIsland.ts b/apps/desktop/src/shared/agentIsland.tsindex 64c4cc8652..bff30c8b1f 100644--- a/apps/desktop/src/shared/agentIsland.ts+++ b/apps/desktop/src/shared/agentIsland.ts@@ -455,8 +455,11 @@ export const AGENT_ISLAND_COMPACT_HARDWARE_IDLE_EXTRA_WIDTH = 64;export const AGENT_ISLAND_COMPACT_HARDWARE_ACTIVE_EXTRA_WIDTH = 64;export const AGENT_ISLAND_COMPACT_HARDWARE_HIDDEN_PULL_DISTANCE = 48;// Compact count-badge metrics, kept in sync with `PillBadge` in-// `native/agent-island/macos-agent-island-helper.swift`. Only used to reserve carrier-// width; the native helper still measures the real font for what it draws.+// `native/agent-island/macos-agent-island-helper.swift`. These describe the *nominal*+// width used to reserve carrier space — the native helper computes the same nominal+// value (it does not measure the font for layout), while the badge itself is still+// drawn by SwiftUI with the real font. The nominal value is an upper bound of what+// gets drawn, so reserved space is never short.export const AGENT_ISLAND_COMPACT_BADGE_MIN_WIDTH = 22;export const AGENT_ISLAND_COMPACT_BADGE_ACTIVE_TOTAL_MIN_WIDTH = 30;export const AGENT_ISLAND_COMPACT_BADGE_CONTENT_INSET = 2;@@ -636,7 +639,10 @@ export function snapAgentIslandCompactHardwareContentWidth(input: {if (input.desiredWidth <= hiddenThreshold) {return hiddenWidth;}- if (input.desiredWidth <= basicWidth) {+ // 只有落在与徽标无关的 basic 吸附位及以下的宽度才升级到当前(可能更宽的)basic。+ // 用 basicWidth 判定会把介于两个吸附点之间的自由宽度(如旧 basic 264 与 11/12 的 306+ // 之间的 280)一并吞掉,再被 native 的持久化归一化改写成 264,永久覆盖用户偏好。+ if (input.desiredWidth <= baseBasicWidth) {return basicWidth;}return input.clampedWidth;