Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(island): 计数徽标改为「需要关注 · 运行中」
Dash935919d3e327
diff --git a/apps/desktop/native/agent-island/macos-agent-island-helper.swift b/apps/desktop/native/agent-island/macos-agent-island-helper.swiftindex c2e8e20198..6cc03127b2 100644--- a/apps/desktop/native/agent-island/macos-agent-island-helper.swift+++ b/apps/desktop/native/agent-island/macos-agent-island-helper.swift@@ -1392,7 +1392,7 @@ struct AgentIslandPillSnapshot: Codable {let priorityMicroTitle: Stringlet priorityCompactTitle: Stringlet sessionCount: Int- let activeSessionCount: Int+ let runningSessionCount: Intlet pendingInteractionCount: Intlet unreadCompletedCount: Intlet deferredRevealCount: Int@@ -1404,7 +1404,7 @@ struct AgentIslandPillSnapshot: Codable {priorityMicroTitle: "",priorityCompactTitle: "",sessionCount: 0,- activeSessionCount: 0,+ runningSessionCount: 0,pendingInteractionCount: 0,unreadCompletedCount: 0,deferredRevealCount: 0,@@ -3051,7 +3051,7 @@ struct PillBadge: View {let pillSnapshot: AgentIslandPillSnapshotvar compact: Bool = false- /// Text runs and minimum capsule width for the badge variant a snapshot renders.+ /// Text runs and minimum width for the badge variant a snapshot renders./// Shared by `body` and `intrinsicWidth` so reserved layout width can never/// drift away from what actually gets drawn.struct Metrics {@@ -3061,23 +3061,48 @@ struct PillBadge: View {let fontSize: CGFloat}+ /// One colored text run of the badge.+ struct Run {+ let text: String+ let color: Color+ }++ /// Mirrors `getAgentIslandCompactBadgeSegments` in `shared/agentIsland.ts`:+ /// running only → `running`; attention + running → `attention · running`;+ /// attention only → `attention`; neither → session count.+ static func runs(pillSnapshot: AgentIslandPillSnapshot) -> [Run] {+ let attention = pillSnapshot.attentionCount+ let running = pillSnapshot.runningSessionCount+ // 等用户操作(提问 / 授权)优先于完成未读,与列表里的状态点同色。+ let attentionColor = pillSnapshot.pendingInteractionCount > 0 ? agentIslandBlue : agentIslandUnreadGreen+ if attention > 0 && running > 0 {+ return [+ Run(text: "\(attention)", color: attentionColor),+ Run(text: "·", color: Color.white.opacity(0.42)),+ Run(text: "\(running)", color: agentIslandOrange),+ ]+ }+ if attention > 0 {+ return [Run(text: "\(attention)", color: attentionColor)]+ }+ if running > 0 {+ return [Run(text: "\(running)", color: agentIslandOrange)]+ }+ return [Run(text: "\(max(1, pillSnapshot.sessionCount))", color: Color.white.opacity(0.92))]+ }+static func metrics(pillSnapshot: AgentIslandPillSnapshot, compact: Bool) -> Metrics {let fontSize: CGFloat = compact ? 10 : 11- if pillSnapshot.activeSessionCount > 0 && pillSnapshot.sessionCount > 1 {- return Metrics(- segments: ["\(pillSnapshot.activeSessionCount)", "/", "\(pillSnapshot.sessionCount)"],- minWidth: compact ? 30 : 34,- fontSize: fontSize- )- }+ let segments = runs(pillSnapshot: pillSnapshot).map(\.text)+ let isPair = segments.count > 1return Metrics(- segments: ["\(max(1, pillSnapshot.sessionCount))"],- minWidth: compact ? 22 : 24,+ segments: segments,+ minWidth: isPair ? (compact ? 30 : 34) : (compact ? 22 : 24),fontSize: fontSize)}- /// Width the hardware-notch layout reserves for the capsule so a multi-digit count is+ /// Width the hardware-notch layout reserves for the badge so a multi-digit count is/// never clipped.////// This is deliberately a *nominal* width computed from digit counts, not an `NSFont`@@ -3092,11 +3117,11 @@ struct PillBadge: View {let segmentsWidth = metrics.segments.reduce(CGFloat(0)) { total, segment intotal + CGFloat(segment.count) * nominalCharWidth + segmentRoundingSlack}- let spacing = activeTotalSpacing * CGFloat(max(0, metrics.segments.count - 1))+ let spacing = runSpacing * CGFloat(max(0, metrics.segments.count - 1))return max(metrics.minWidth, segmentsWidth + spacing + contentInset * 2)}- private static let activeTotalSpacing: CGFloat = 1+ private static let runSpacing: CGFloat = 1private static let contentInset: CGFloat = 2/// Upper bound for one monospaced 10pt digit (real advance is ~6pt). Mirrors/// `AGENT_ISLAND_COMPACT_BADGE_CHAR_WIDTH_BOUND` on the TS side.@@ -3106,48 +3131,18 @@ struct PillBadge: View {private static let segmentRoundingSlack: CGFloat = 1var body: some View {- if pillSnapshot.activeSessionCount > 0 && pillSnapshot.sessionCount > 1 {- activeTotalBadge(- active: pillSnapshot.activeSessionCount,- total: pillSnapshot.sessionCount,- emphasized: isEmphasized- )- } else {- badge("\(max(1, pillSnapshot.sessionCount))", emphasized: isEmphasized)- }- }-- private func badge(_ text: String, emphasized: Bool) -> some View {- Text(text)- .font(badgeFont)- .foregroundColor(Color.white.opacity(0.92))- .lineLimit(1)- .padding(.horizontal, Self.contentInset)- .frame(minWidth: metrics.minWidth, minHeight: compact ? 18 : 20)- .background(Color.white.opacity(emphasized ? 0.11 : 0.065))- .clipShape(Capsule())- // Fix the whole capsule, not just the text: a squeezed `minWidth` frame would- // otherwise shrink the background while multi-digit text overflows it.- .fixedSize(horizontal: true, vertical: false)- }-- private func activeTotalBadge(active: Int, total: Int, emphasized: Bool) -> some View {- HStack(spacing: Self.activeTotalSpacing) {- Text("\(active)")- .foregroundColor(emphasized ? agentIslandBlue : agentIslandOrange)- Text("/")- .foregroundColor(Color.white.opacity(0.42))- Text("\(total)")- .foregroundColor(Color.white.opacity(0.92))+ HStack(spacing: Self.runSpacing) {+ ForEach(Array(Self.runs(pillSnapshot: pillSnapshot).enumerated()), id: \.offset) { _, run in+ Text(run.text)+ .foregroundColor(run.color)+ }}.font(badgeFont).lineLimit(1).padding(.horizontal, Self.contentInset).frame(minWidth: metrics.minWidth, minHeight: compact ? 18 : 20)- .background(Color.white.opacity(emphasized ? 0.11 : 0.065))- .clipShape(Capsule())- // Fix the whole capsule, not just the text: a squeezed `minWidth` frame would- // otherwise shrink the background while multi-digit text overflows it.+ // Keep the full reserved width (mirrored on the TS side) instead of letting a+ // squeezed `minWidth` frame truncate multi-digit text..fixedSize(horizontal: true, vertical: false)}@@ -3158,10 +3153,6 @@ struct PillBadge: View {private var badgeFont: Font {.system(size: metrics.fontSize, weight: .semibold, design: .monospaced)}-- private var isEmphasized: Bool {- pillSnapshot.pendingInteractionCount > 0 || pillSnapshot.attentionCount > 0- }}struct AgentIslandWaveText: View {@@ -6289,7 +6280,7 @@ enum AgentIslandDebugHarness {now: Double) -> AgentIslandDisplayState {let current = sessions.first { $0.sessionId == currentSessionId } ?? sessions[0]- let activeCount = sessions.filter { $0.phase == "running" || $0.phase == "needs-interaction" }.count+ let runningCount = sessions.filter { $0.phase == "running" }.countlet pendingCount = sessions.filter { $0.phase == "needs-interaction" }.countlet unreadDoneCount = sessions.filter { $0.phase == "completed" || $0.phase == "error" }.countreturn AgentIslandDisplayState(@@ -6310,7 +6301,7 @@ enum AgentIslandDebugHarness {priorityMicroTitle: current.displayTitle,priorityCompactTitle: current.displayTitle,sessionCount: sessions.count,- activeSessionCount: activeCount,+ runningSessionCount: runningCount,pendingInteractionCount: pendingCount,unreadCompletedCount: unreadDoneCount,deferredRevealCount: 1,diff --git a/apps/desktop/src/main/agent-island/__tests__/state.test.ts b/apps/desktop/src/main/agent-island/__tests__/state.test.tsindex 7855e3fff6..bd89f6bf38 100644--- a/apps/desktop/src/main/agent-island/__tests__/state.test.ts+++ b/apps/desktop/src/main/agent-island/__tests__/state.test.ts@@ -183,7 +183,7 @@ describe('Agent Island display state', () => {priorityMicroTitle: '',priorityCompactTitle: '',sessionCount: 0,- activeSessionCount: 0,+ runningSessionCount: 0,pendingInteractionCount: 0,unreadCompletedCount: 0,deferredRevealCount: 0,@@ -213,7 +213,7 @@ describe('Agent Island display state', () => {expect(display.currentSessionId).toBe('b');expect(display.pillSnapshot.priorityId).toBe('b');expect(display.pillSnapshot.priorityCompactTitle).toBe('B');- expect(display.pillSnapshot.activeSessionCount).toBe(2);+ expect(display.pillSnapshot.runningSessionCount).toBe(2);expect(display.sessions.map((session) => session.sessionId)).toEqual(['b', 'a']);expect(display.totalCount).toBe(2);expect(display.shadowVisible).toBe(false);@@ -230,7 +230,7 @@ describe('Agent Island display state', () => {expect(firstDisplay.currentSessionId).toBe('b');expect(firstDisplay.pillSnapshot).toMatchObject({priorityId: 'b',- activeSessionCount: 2,+ runningSessionCount: 2,sessionCount: 2,});expect(getNextAgentIslandTimerAt(state, 1_200)).toBeNull();@@ -967,7 +967,8 @@ describe('Agent Island display state', () => {expect(display.pillSnapshot).toMatchObject({priorityId: 'ask',priorityStatus: 'needs-interaction',- activeSessionCount: 2,+ // 等回答的 ask 只算需要关注,不再重复计入运行中。+ runningSessionCount: 1,pendingInteractionCount: 1,unreadCompletedCount: 2,sessionCount: 4,@@ -1869,7 +1870,7 @@ describe('Agent Island display state', () => {expect(stillCompletion.displaySurface).toBe('completionCard');expect(stillCompletion.currentSessionId).toBe('done');expect(stillCompletion.sessions.map((session) => session.sessionId)).toEqual(['done']);- expect(stillCompletion.pillSnapshot.activeSessionCount).toBe(1);+ expect(stillCompletion.pillSnapshot.runningSessionCount).toBe(1);const display = buildAgentIslandDisplayState(state, 14_200);@@ -1891,7 +1892,7 @@ describe('Agent Island display state', () => {expect(stillCompletion.displaySurface).toBe('completionCard');expect(stillCompletion.currentSessionId).toBe('done');expect(stillCompletion.sessions.map((session) => session.sessionId)).toEqual(['done']);- expect(stillCompletion.pillSnapshot.activeSessionCount).toBe(1);+ expect(stillCompletion.pillSnapshot.runningSessionCount).toBe(1);});it('shows running sessions only for manual hover expansion, not completion auto expansion', () => {@@ -1904,7 +1905,7 @@ describe('Agent Island display state', () => {expect(autoExpanded.displayPolicy).toBe('transient');expect(autoExpanded.displaySurface).toBe('completionCard');expect(autoExpanded.sessions.map((session) => session.sessionId)).toEqual(['done']);- expect(autoExpanded.pillSnapshot.activeSessionCount).toBe(1);+ expect(autoExpanded.pillSnapshot.runningSessionCount).toBe(1);setAgentIslandHovered(state, true, 14_100);const manualExpanded = buildAgentIslandDisplayState(state, 14_700);diff --git a/apps/desktop/src/main/agent-island/state.ts b/apps/desktop/src/main/agent-island/state.tsindex 4dff349b1e..5407301d1a 100644--- a/apps/desktop/src/main/agent-island/state.ts+++ b/apps/desktop/src/main/agent-island/state.ts@@ -2292,8 +2292,9 @@ function isStackableTransientSession(session: AgentIslandSessionState, now: numb|| Boolean(session.errorUntil && session.errorUntil > now);}-function isCompactActiveSession(session: AgentIslandSessionState): boolean {- return session.phase === 'running' || session.phase === 'needs-interaction' || session.pendingInteractionIds.size > 0;+// 徽标里「运行中」与「需要关注」互斥:等用户回答的任务只算需要关注,不重复计入运行中。+function isBadgeRunningSession(session: AgentIslandSessionState): boolean {+ return session.phase === 'running' && !isBlockingSession(session);}function isBlockingSession(session: AgentIslandSessionState): boolean {@@ -2397,14 +2398,14 @@ function buildPillSnapshot(sessions: AgentIslandSessionState[],current: AgentIslandSessionState | null,): AgentIslandPillSnapshot {- let activeSessionCount = 0;+ let runningSessionCount = 0;let pendingInteractionCount = 0;let unreadCompletedCount = 0;let deferredRevealCount = 0;let attentionCount = 0;for (const session of sessions) {- if (isCompactActiveSession(session)) activeSessionCount += 1;- if (session.pendingInteractionIds.size > 0) pendingInteractionCount += 1;+ if (isBadgeRunningSession(session)) runningSessionCount += 1;+ if (isBlockingSession(session)) pendingInteractionCount += 1;if (session.unread && (session.phase === 'completed' || session.phase === 'error')) {unreadCompletedCount += 1;}@@ -2417,7 +2418,7 @@ function buildPillSnapshot(priorityMicroTitle: current ? pillTitle(current, 'micro') : '',priorityCompactTitle: current ? pillTitle(current, 'compact') : '',sessionCount: sessions.length,- activeSessionCount,+ runningSessionCount,pendingInteractionCount,unreadCompletedCount,deferredRevealCount,diff --git a/apps/desktop/src/shared/__tests__/agentIslandCompactBadgeWidth.test.ts b/apps/desktop/src/shared/__tests__/agentIslandCompactBadgeWidth.test.tsindex 042ee45a27..c7cf206f31 100644--- a/apps/desktop/src/shared/__tests__/agentIslandCompactBadgeWidth.test.ts+++ b/apps/desktop/src/shared/__tests__/agentIslandCompactBadgeWidth.test.ts@@ -1,6 +1,7 @@import { describe, expect, it } from 'vitest';import {+ type AgentIslandCompactBadgeCounts,AGENT_ISLAND_CARRIER_COMPACT_INSET,AGENT_ISLAND_COMPACT_HARDWARE_ACTIVE_EXTRA_WIDTH,AGENT_ISLAND_COMPACT_HARDWARE_BADGE_RESERVED_INSET,@@ -8,6 +9,7 @@ import {AGENT_ISLAND_COMPACT_HARDWARE_IDLE_EXTRA_WIDTH,AGENT_ISLAND_COMPACT_IDLE_WIDTH,AGENT_ISLAND_MAX_RESIZABLE_WIDTH,+ getAgentIslandCompactBadgeSegments,getAgentIslandCompactBadgeWidth,getAgentIslandDefaultContentWidth,snapAgentIslandCompactHardwareContentWidth,@@ -27,21 +29,21 @@ import {*/const NATIVE_COMPACT_BADGE_WIDTH: Array<{label: string;- pillSnapshot: { activeSessionCount: number; sessionCount: number };+ pillSnapshot: AgentIslandCompactBadgeCounts;/** Swift `PillBadge.intrinsicWidth(compact: true)` 应算出的值,必须与 TS 完全一致。 */layoutWidth: number;/** SwiftUI 实绘宽度,标称宽度必须 >= 它,否则仍会被裁。 */renderedWidth: number;}> = [- { label: '单会话', pillSnapshot: { activeSessionCount: 0, sessionCount: 1 }, layoutWidth: 22, renderedWidth: 22 },- { label: '12 个任务', pillSnapshot: { activeSessionCount: 0, sessionCount: 12 }, layoutWidth: 22, renderedWidth: 22 },- { label: '1/2', pillSnapshot: { activeSessionCount: 1, sessionCount: 2 }, layoutWidth: 30, renderedWidth: 30 },- { label: '9/9', pillSnapshot: { activeSessionCount: 9, sessionCount: 9 }, layoutWidth: 30, renderedWidth: 30 },- { label: '1/12', pillSnapshot: { activeSessionCount: 1, sessionCount: 12 }, layoutWidth: 37, renderedWidth: 33 },- { label: '11/12', pillSnapshot: { activeSessionCount: 11, sessionCount: 12 }, layoutWidth: 44, renderedWidth: 39 },- { label: '10/100', pillSnapshot: { activeSessionCount: 10, sessionCount: 100 }, layoutWidth: 51, renderedWidth: 45 },- { label: '99/99', pillSnapshot: { activeSessionCount: 99, sessionCount: 99 }, layoutWidth: 44, renderedWidth: 39 },- { label: '123/456', pillSnapshot: { activeSessionCount: 123, sessionCount: 456 }, layoutWidth: 58, renderedWidth: 51 },+ { label: '单会话', pillSnapshot: { attentionCount: 0, runningSessionCount: 0, sessionCount: 1 }, layoutWidth: 22, renderedWidth: 22 },+ { label: '12 个任务', pillSnapshot: { attentionCount: 0, runningSessionCount: 0, sessionCount: 12 }, layoutWidth: 22, renderedWidth: 22 },+ { label: '1·2', pillSnapshot: { attentionCount: 1, runningSessionCount: 2, sessionCount: 3 }, layoutWidth: 30, renderedWidth: 30 },+ { label: '9·9', pillSnapshot: { attentionCount: 9, runningSessionCount: 9, sessionCount: 18 }, layoutWidth: 30, renderedWidth: 30 },+ { label: '1·12', pillSnapshot: { attentionCount: 1, runningSessionCount: 12, sessionCount: 13 }, layoutWidth: 37, renderedWidth: 33 },+ { label: '11·12', pillSnapshot: { attentionCount: 11, runningSessionCount: 12, sessionCount: 23 }, layoutWidth: 44, renderedWidth: 39 },+ { label: '10·100', pillSnapshot: { attentionCount: 10, runningSessionCount: 100, sessionCount: 110 }, layoutWidth: 51, renderedWidth: 45 },+ { label: '99·99', pillSnapshot: { attentionCount: 99, runningSessionCount: 99, sessionCount: 198 }, layoutWidth: 44, renderedWidth: 39 },+ { label: '123·456', pillSnapshot: { attentionCount: 123, runningSessionCount: 456, sessionCount: 579 }, layoutWidth: 58, renderedWidth: 51 },];const NOTCH_WIDTHS = [180, 200, 210, 215];@@ -56,6 +58,18 @@ function trailingInset(side: number): number {return Math.max(7, (Math.min(side, 40) - 22) / 2);}+describe('getAgentIslandCompactBadgeSegments', () => {+ it('只有运行中时显示一个数;有需要关注的任务时变成「关注 · 运行中」', () => {+ const segments = (attentionCount: number, runningSessionCount: number, sessionCount: number) =>+ getAgentIslandCompactBadgeSegments({ attentionCount, runningSessionCount, sessionCount });+ expect(segments(0, 10, 10)).toEqual(['10']);+ expect(segments(2, 8, 10)).toEqual(['2', '·', '8']);+ expect(segments(3, 0, 3)).toEqual(['3']);+ // 只剩已读完成等既不运行也不需关注的任务时,退回任务总数。+ expect(segments(0, 0, 2)).toEqual(['2']);+ });+});+describe('getAgentIslandCompactBadgeWidth', () => {it('与 Swift PillBadge.intrinsicWidth 逐值一致(两侧公式必须同步)', () => {for (const { label, pillSnapshot, layoutWidth } of NATIVE_COMPACT_BADGE_WIDTH) {@@ -73,18 +87,18 @@ describe('getAgentIslandCompactBadgeWidth', () => {});it('单个计数在 22pt 最小宽度内不变宽,超出后同样按位数增长', () => {- expect(getAgentIslandCompactBadgeWidth({ activeSessionCount: 0, sessionCount: 1 })).toBe(22);- expect(getAgentIslandCompactBadgeWidth({ activeSessionCount: 0, sessionCount: 12 })).toBe(22);+ expect(getAgentIslandCompactBadgeWidth({ attentionCount: 0, runningSessionCount: 0, sessionCount: 1 })).toBe(22);+ expect(getAgentIslandCompactBadgeWidth({ attentionCount: 0, runningSessionCount: 0, sessionCount: 12 })).toBe(22);// 位数够多时单个计数也会超过最小宽度 —— 公式对两种形态都是按 segment 长度算的。- expect(getAgentIslandCompactBadgeWidth({ activeSessionCount: 0, sessionCount: 1234 }))+ expect(getAgentIslandCompactBadgeWidth({ attentionCount: 0, runningSessionCount: 0, sessionCount: 1234 })).toBeGreaterThan(22);- const oneDigit = getAgentIslandCompactBadgeWidth({ activeSessionCount: 1, sessionCount: 2 });- const twoDigits = getAgentIslandCompactBadgeWidth({ activeSessionCount: 11, sessionCount: 12 });+ const oneDigit = getAgentIslandCompactBadgeWidth({ attentionCount: 1, runningSessionCount: 2, sessionCount: 3 });+ const twoDigits = getAgentIslandCompactBadgeWidth({ attentionCount: 11, runningSessionCount: 12, sessionCount: 23 });expect(twoDigits).toBeGreaterThan(oneDigit);});it('sessionCount 为 0 时按 1 处理,不产出小于最小宽度的值', () => {- expect(getAgentIslandCompactBadgeWidth({ activeSessionCount: 0, sessionCount: 0 })).toBe(22);+ expect(getAgentIslandCompactBadgeWidth({ attentionCount: 0, runningSessionCount: 0, sessionCount: 0 })).toBe(22);});});@@ -122,13 +136,13 @@ describe('getAgentIslandDefaultContentWidth: 刻痕机为计数徽标预留宽expanded: false,hasSession: true,screenMetrics: { hasNotch: true, notchWidth },- pillSnapshot: { activeSessionCount: 0, sessionCount: 1 },+ pillSnapshot: { attentionCount: 0, runningSessionCount: 0, sessionCount: 1 },})).toBe(legacyActive);expect(getAgentIslandDefaultContentWidth({expanded: false,hasSession: false,screenMetrics: { hasNotch: true, notchWidth },- pillSnapshot: { activeSessionCount: 11, sessionCount: 12 },+ pillSnapshot: { attentionCount: 11, runningSessionCount: 12, sessionCount: 23 },})).toBe(legacyIdle);}});@@ -148,7 +162,7 @@ describe('getAgentIslandDefaultContentWidth: 刻痕机为计数徽标预留宽it('预留量等于 (徽标宽 + inset 上界) * 2', () => {const notchWidth = 200;- const pillSnapshot = { activeSessionCount: 11, sessionCount: 12 };+ const pillSnapshot = { attentionCount: 11, runningSessionCount: 12, sessionCount: 23 };const badgeWidth = getAgentIslandCompactBadgeWidth(pillSnapshot);expect(getAgentIslandDefaultContentWidth({expanded: false,@@ -161,7 +175,7 @@ describe('getAgentIslandDefaultContentWidth: 刻痕机为计数徽标预留宽});it('非刻痕机与 expanded 形态不受影响', () => {- const pillSnapshot = { activeSessionCount: 11, sessionCount: 12 };+ const pillSnapshot = { attentionCount: 11, runningSessionCount: 12, sessionCount: 23 };const simulated = getAgentIslandDefaultContentWidth({expanded: false,hasSession: true,@@ -267,7 +281,7 @@ describe('TS carrier 宽度 → native 宽度链路', () => {describe('snapAgentIslandCompactHardwareContentWidth', () => {it('吸附点跟随预留后的默认宽度', () => {const notchWidth = 200;- const pillSnapshot = { activeSessionCount: 11, sessionCount: 12 };+ const pillSnapshot = { attentionCount: 11, runningSessionCount: 12, sessionCount: 23 };const screenMetrics = { hasNotch: true, notchWidth };const basicWidth = getAgentIslandDefaultContentWidth({expanded: false,@@ -294,7 +308,7 @@ describe('snapAgentIslandCompactHardwareContentWidth', () => {maxWidth: 920,hasSession: true,screenMetrics: { hasNotch: true, notchWidth },- pillSnapshot: { activeSessionCount: 11, sessionCount: 12 },+ pillSnapshot: { attentionCount: 11, runningSessionCount: 12, sessionCount: 23 },})).toBe(notchWidth);});@@ -305,9 +319,9 @@ describe('snapAgentIslandCompactHardwareContentWidth', () => {const persistedBasicWidth = notchWidth + AGENT_ISLAND_COMPACT_HARDWARE_ACTIVE_EXTRA_WIDTH;const screenMetrics = { hasNotch: true, notchWidth };for (const pillSnapshot of [- { activeSessionCount: 10, sessionCount: 100 },- { activeSessionCount: 11, sessionCount: 12 },- { activeSessionCount: 123, sessionCount: 456 },+ { attentionCount: 10, runningSessionCount: 100, sessionCount: 110 },+ { attentionCount: 11, runningSessionCount: 12, sessionCount: 23 },+ { attentionCount: 123, runningSessionCount: 456, sessionCount: 579 },]) {const widened = getAgentIslandDefaultContentWidth({expanded: false,@@ -323,7 +337,7 @@ describe('snapAgentIslandCompactHardwareContentWidth', () => {screenMetrics,pillSnapshot,});- expect(resolved, `${pillSnapshot.activeSessionCount}/${pillSnapshot.sessionCount} 塌缩到了 ${resolved}`)+ expect(resolved, `${pillSnapshot.attentionCount}·${pillSnapshot.runningSessionCount} 塌缩到了 ${resolved}`).not.toBe(notchWidth);expect(resolved).toBe(widened);}@@ -332,7 +346,7 @@ describe('snapAgentIslandCompactHardwareContentWidth', () => {it('hidden 阈值与旧实现一致:略窄于旧 basic 仍吸附到 basic,更窄才隐藏', () => {const notchWidth = 200;const screenMetrics = { hasNotch: true, notchWidth };- const pillSnapshot = { activeSessionCount: 11, sessionCount: 12 };+ const pillSnapshot = { attentionCount: 11, runningSessionCount: 12, sessionCount: 23 };const widened = getAgentIslandDefaultContentWidth({expanded: false,hasSession: true,@@ -364,7 +378,7 @@ describe('snapAgentIslandCompactHardwareContentWidth', () => {const notchWidth = 200;const screenMetrics = { hasNotch: true, notchWidth };const persisted = notchWidth + AGENT_ISLAND_COMPACT_HARDWARE_ACTIVE_EXTRA_WIDTH;- const resolveFor = (pillSnapshot: { activeSessionCount: number; sessionCount: number }) =>+ const resolveFor = (pillSnapshot: AgentIslandCompactBadgeCounts) =>snapAgentIslandCompactHardwareContentWidth({desiredWidth: persisted,clampedWidth: persisted,@@ -374,8 +388,8 @@ describe('snapAgentIslandCompactHardwareContentWidth', () => {pillSnapshot,});- const wide = resolveFor({ activeSessionCount: 11, sessionCount: 12 });- const narrow = resolveFor({ activeSessionCount: 0, sessionCount: 1 });+ const wide = resolveFor({ attentionCount: 11, runningSessionCount: 12, sessionCount: 23 });+ const narrow = resolveFor({ attentionCount: 0, runningSessionCount: 0, sessionCount: 1 });expect(wide).toBeGreaterThan(persisted);// 计数回落后必须收缩回旧的 basic 宽度,不能停在为宽徽标撑开的宽度上。expect(narrow).toBe(persisted);@@ -389,8 +403,8 @@ describe('snapAgentIslandCompactHardwareContentWidth', () => {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 },+ { attentionCount: 11, runningSessionCount: 12, sessionCount: 23 },+ { attentionCount: 123, runningSessionCount: 456, sessionCount: 579 },]) {const widened = getAgentIslandDefaultContentWidth({expanded: false,diff --git a/apps/desktop/src/shared/agentIsland.ts b/apps/desktop/src/shared/agentIsland.tsindex b29354ecff..dae4aa672d 100644--- a/apps/desktop/src/shared/agentIsland.ts+++ b/apps/desktop/src/shared/agentIsland.ts@@ -374,7 +374,9 @@ export interface AgentIslandPillSnapshot {priorityMicroTitle: string;priorityCompactTitle: string;sessionCount: number;- activeSessionCount: number;+ /** Running and not waiting on the user; disjoint from `attentionCount`. */+ runningSessionCount: number;+ /** Sessions blocked on the user (question / permission). */pendingInteractionCount: number;unreadCompletedCount: number;deferredRevealCount: number;@@ -388,7 +390,7 @@ export function createEmptyAgentIslandPillSnapshot(): AgentIslandPillSnapshot {priorityMicroTitle: '',priorityCompactTitle: '',sessionCount: 0,- activeSessionCount: 0,+ runningSessionCount: 0,pendingInteractionCount: 0,unreadCompletedCount: 0,deferredRevealCount: 0,@@ -479,7 +481,7 @@ export const AGENT_ISLAND_COMPACT_HARDWARE_HIDDEN_PULL_DISTANCE = 48;// 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_PAIR_MIN_WIDTH = 30;export const AGENT_ISLAND_COMPACT_BADGE_CONTENT_INSET = 2;export const AGENT_ISLAND_COMPACT_BADGE_TEXT_SPACING = 1;/** Generous upper bound for one monospaced 10pt digit (real advance is ~6pt). */@@ -522,6 +524,29 @@ export function computeAgentIslandSimulatedNotchWidth(displayWidth: number): num);}+export type AgentIslandCompactBadgeCounts = Pick<+ AgentIslandPillSnapshot,+ 'attentionCount' | 'runningSessionCount' | 'sessionCount'+>;++/**+ * Text segments of the compact count badge, mirroring `PillBadge.segments` in+ * `macos-agent-island-helper.swift`:+ *+ * - only running tasks → `running`+ * - something needs attention and tasks are running → `attention · running`+ * - only attention → `attention`+ * - neither (e.g. read completions still on the island) → session count+ */+export function getAgentIslandCompactBadgeSegments(input: AgentIslandCompactBadgeCounts): string[] {+ if (input.attentionCount > 0 && input.runningSessionCount > 0) {+ return [`${input.attentionCount}`, '·', `${input.runningSessionCount}`];+ }+ if (input.attentionCount > 0) return [`${input.attentionCount}`];+ if (input.runningSessionCount > 0) return [`${input.runningSessionCount}`];+ return [`${Math.max(1, input.sessionCount)}`];+}+/*** Upper-bound width of the compact count badge the native helper draws, mirroring* `PillBadge.intrinsicWidth` in `macos-agent-island-helper.swift`.@@ -532,14 +557,8 @@ export function computeAgentIslandSimulatedNotchWidth(displayWidth: number): num* monospaced 10pt advance is ~6pt, and overestimating only leaves invisible slack* inside the carrier's transparent inset.*/-export function getAgentIslandCompactBadgeWidth(input: {- activeSessionCount: number;- sessionCount: number;-}): number {- const isActiveTotal = input.activeSessionCount > 0 && input.sessionCount > 1;- const segments = isActiveTotal- ? [`${input.activeSessionCount}`, '/', `${input.sessionCount}`]- : [`${Math.max(1, input.sessionCount)}`];+export function getAgentIslandCompactBadgeWidth(input: AgentIslandCompactBadgeCounts): number {+ const segments = getAgentIslandCompactBadgeSegments(input);const segmentsWidth = segments.reduce((total, segment) => total+ segment.length * AGENT_ISLAND_COMPACT_BADGE_CHAR_WIDTH_BOUND@@ -547,8 +566,8 @@ export function getAgentIslandCompactBadgeWidth(input: {0,);const spacing = AGENT_ISLAND_COMPACT_BADGE_TEXT_SPACING * Math.max(0, segments.length - 1);- const minWidth = isActiveTotal- ? AGENT_ISLAND_COMPACT_BADGE_ACTIVE_TOTAL_MIN_WIDTH+ const minWidth = segments.length > 1+ ? AGENT_ISLAND_COMPACT_BADGE_PAIR_MIN_WIDTH: AGENT_ISLAND_COMPACT_BADGE_MIN_WIDTH;return Math.max(minWidth,@@ -561,7 +580,7 @@ export function getAgentIslandDefaultContentWidth(input: {hasSession: boolean;displayWidth?: number;screenMetrics?: AgentIslandScreenLayoutMetrics | null;- pillSnapshot?: Pick<AgentIslandPillSnapshot, 'activeSessionCount' | 'sessionCount'> | null;+ pillSnapshot?: AgentIslandCompactBadgeCounts | null;}): number {if (input.expanded) {return input.hasSession ? AGENT_ISLAND_MAX_EXPANDED_WIDTH : AGENT_ISLAND_IDLE_EXPANDED_WIDTH;@@ -621,7 +640,7 @@ export function snapAgentIslandCompactHardwareContentWidth(input: {maxWidth: number;hasSession: boolean;screenMetrics?: AgentIslandScreenLayoutMetrics | null;- pillSnapshot?: Pick<AgentIslandPillSnapshot, 'activeSessionCount' | 'sessionCount'> | null;+ pillSnapshot?: AgentIslandCompactBadgeCounts | null;}): number {if (!input.screenMetrics?.hasNotch) {return input.clampedWidth;