Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 气泡颜色只染自己的消息,并保证气泡内文字可读
kirozeng649f152c16ef
diff --git a/apps/mobile/src/__tests__/messageNormalize.test.ts b/apps/mobile/src/__tests__/messageNormalize.test.tsindex 347f9a0c82..3f91d32116 100644--- a/apps/mobile/src/__tests__/messageNormalize.test.ts+++ b/apps/mobile/src/__tests__/messageNormalize.test.ts@@ -1198,7 +1198,7 @@ describe('normalizeRemoteMessages', () => {agentMeta: {sourceDevice: { deviceId: 'phone-1', name: 'Dash 的\niPhone', platform: 'mobile' },sourcePlugin: { pluginId: 'plugin-1', name: '日报' },- sharedTaskAuthor: { displayName: '访客甲', memberId: 'm1' },+ sharedTaskAuthor: { displayName: '访客甲', memberId: 'm1', accountId: 'acct-guest' },},}),message({@@ -1220,6 +1220,8 @@ describe('normalizeRemoteMessages', () => {['unknown-platform', undefined, undefined, undefined],['assistant-ignored', undefined, undefined, undefined],]);+ // 作者账号只用于判断「是不是我的消息」(气泡配色),不作权限依据。+ expect(items.map((item) => item.sharedAuthorAccountId)).toEqual(['acct-guest', undefined, undefined]);});it('reads the sending session of tool-sent and Orca messages without mixing it into automation', () => {diff --git a/apps/mobile/src/__tests__/userBubbleOwnership.test.ts b/apps/mobile/src/__tests__/userBubbleOwnership.test.tsnew file mode 100644index 0000000000..4bf63dcce5--- /dev/null+++ b/apps/mobile/src/__tests__/userBubbleOwnership.test.ts@@ -0,0 +1,33 @@+import { describe, expect, it } from 'vitest';+import { sharedTaskHostPeer } from '@cindy/device-link';+import { isOwnUserBubble } from '@/session/userBubbleOwnership';++const ownerDevice = 'mac-owner-device';+const guestView = sharedTaskHostPeer('shared-task-1', ownerDevice);++describe('my message bubble ownership', () => {+ it('tints only my messages when I own the task', () => {+ expect(isOwnUserBubble({}, { accountId: 'owner', remoteDeviceId: ownerDevice })).toBe(true);+ expect(isOwnUserBubble(+ { sharedAuthorName: 'Guest', sharedAuthorAccountId: 'guest' },+ { accountId: 'owner', remoteDeviceId: ownerDevice },+ )).toBe(false);+ });++ it('tints only my messages when I join as a guest', () => {+ expect(isOwnUserBubble({}, { accountId: 'guest', remoteDeviceId: guestView })).toBe(false);+ expect(isOwnUserBubble(+ { sharedAuthorName: 'Me', sharedAuthorAccountId: 'guest' },+ { accountId: 'guest', remoteDeviceId: guestView },+ )).toBe(true);+ expect(isOwnUserBubble(+ { sharedAuthorName: 'Other guest', sharedAuthorAccountId: 'other' },+ { accountId: 'guest', remoteDeviceId: guestView },+ )).toBe(false);+ });++ it('leaves attributed history without an account id untinted', () => {+ expect(isOwnUserBubble({ sharedAuthorName: 'Old' }, { accountId: 'owner', remoteDeviceId: ownerDevice })).toBe(false);+ expect(isOwnUserBubble({ sharedAuthorName: 'Old', sharedAuthorAccountId: 'x' }, { accountId: null })).toBe(false);+ });+});diff --git a/apps/mobile/src/i18n/locales/en/settings.json b/apps/mobile/src/i18n/locales/en/settings.jsonindex 397a84e322..106b931891 100644--- a/apps/mobile/src/i18n/locales/en/settings.json+++ b/apps/mobile/src/i18n/locales/en/settings.json@@ -49,7 +49,9 @@"sampleAssistant": "Sure, let’s work through your ideas together.","hint": "Colors adjust to light and dark mode so text stays easy to read. Saved on this device only.","customHint": "Drag along the color strip to choose a hue. Colors adjust to light and dark mode so text stays easy to read. Saved on this device only.",- "saveFailed": "The color is applied for now but could not be saved. Please try again.",+ "saveFailed": "The color is applied for now but could not be saved.",+ "retry": "Retry",+ "cancel": "Cancel","reset": "Reset to default","apply": "Apply","hex": "Color value"diff --git a/apps/mobile/src/i18n/locales/ja/settings.json b/apps/mobile/src/i18n/locales/ja/settings.jsonindex ecfca639d5..9cc80c8374 100644--- a/apps/mobile/src/i18n/locales/ja/settings.json+++ b/apps/mobile/src/i18n/locales/ja/settings.json@@ -49,7 +49,9 @@"sampleAssistant": "一緒にアイデアを整理しましょう。","hint": "色はライト/ダークモードに合わせて明るさが自動調整され、文字が読みやすく保たれます。この端末にのみ保存されます。","customHint": "カラーバーを左右にドラッグして色を選べます。色はライト/ダークモードに合わせて明るさが自動調整され、文字が読みやすく保たれます。この端末にのみ保存されます。",- "saveFailed": "色は適用されましたが、保存できませんでした。もう一度お試しください。",+ "saveFailed": "色は適用されましたが、保存できませんでした。",+ "retry": "再試行",+ "cancel": "キャンセル","reset": "デフォルトに戻す","apply": "適用","hex": "カラーコード"diff --git a/apps/mobile/src/i18n/locales/ko/settings.json b/apps/mobile/src/i18n/locales/ko/settings.jsonindex dbe55f3f7d..340c91113c 100644--- a/apps/mobile/src/i18n/locales/ko/settings.json+++ b/apps/mobile/src/i18n/locales/ko/settings.json@@ -49,7 +49,9 @@"sampleAssistant": "좋아요, 함께 아이디어를 정리해 봐요.","hint": "색상은 라이트·다크 모드에 맞춰 밝기가 자동 조정되어 글자가 잘 보입니다. 이 기기에만 저장됩니다.","customHint": "색상 막대를 좌우로 드래그해 색을 고르세요. 색상은 라이트·다크 모드에 맞춰 밝기가 자동 조정되어 글자가 잘 보입니다. 이 기기에만 저장됩니다.",- "saveFailed": "색상은 적용되었지만 저장하지 못했습니다. 다시 시도해 주세요.",+ "saveFailed": "색상은 적용되었지만 저장하지 못했습니다.",+ "retry": "다시 시도",+ "cancel": "취소","reset": "기본값으로 복원","apply": "적용","hex": "색상 코드"diff --git a/apps/mobile/src/i18n/locales/zh-CN/settings.json b/apps/mobile/src/i18n/locales/zh-CN/settings.jsonindex cc06d1328c..4358ca8808 100644--- a/apps/mobile/src/i18n/locales/zh-CN/settings.json+++ b/apps/mobile/src/i18n/locales/zh-CN/settings.json@@ -49,7 +49,9 @@"sampleAssistant": "好的,我们一起把想法梳理清楚。","hint": "颜色会按浅色和深色模式自动调整明暗,保证文字清晰。仅保存在此设备。","customHint": "左右拖动色带选择颜色。颜色会按浅色和深色模式自动调整明暗,保证文字清晰。仅保存在此设备。",- "saveFailed": "颜色已在本次使用中生效,但未能保存。请重试。",+ "saveFailed": "颜色已在本次使用中生效,但未能保存。",+ "retry": "重试",+ "cancel": "取消","reset": "恢复默认","apply": "应用","hex": "颜色值"diff --git a/apps/mobile/src/i18n/locales/zh-TW/settings.json b/apps/mobile/src/i18n/locales/zh-TW/settings.jsonindex dc99ef867b..bdbb033265 100644--- a/apps/mobile/src/i18n/locales/zh-TW/settings.json+++ b/apps/mobile/src/i18n/locales/zh-TW/settings.json@@ -49,7 +49,9 @@"sampleAssistant": "好的,我們一起把想法梳理清楚。","hint": "顏色會依淺色和深色模式自動調整明暗,確保文字清晰。僅儲存在此裝置。","customHint": "左右拖曳色帶選擇顏色。顏色會依淺色和深色模式自動調整明暗,確保文字清晰。僅儲存在此裝置。",- "saveFailed": "顏色已在本次使用中生效,但未能儲存。請重試。",+ "saveFailed": "顏色已在本次使用中生效,但未能儲存。",+ "retry": "重試",+ "cancel": "取消","reset": "恢復預設","apply": "套用","hex": "色碼"diff --git a/apps/mobile/src/session/BotGroupChatScreen.tsx b/apps/mobile/src/session/BotGroupChatScreen.tsxindex 0aeb2dc456..58fe81f270 100644--- a/apps/mobile/src/session/BotGroupChatScreen.tsx+++ b/apps/mobile/src/session/BotGroupChatScreen.tsx@@ -52,6 +52,7 @@ import { MainWindowActionButton, MainWindowEmptyState } from '@/components/Mobilimport { readRemoteCollectionCache } from '@/device-link/remoteResourceAvailability';import type { RemoteResourceHostTarget } from '@/device-link/remoteResources';import { useTheme, useThemedStyles, type ThemeColors } from '@/theme';+import { useUserBubbleAppearance } from '@/theme/userBubblePreference';import { fontWeight, lineHeight, radius, spacing, typeScale } from '@/theme/tokens';import { goBackGuarded } from '@/utils/backGuard';import {@@ -449,6 +450,7 @@ function BotGroupTimelineItem({}) {const { t } = useTranslation();const styles = useThemedStyles(makeStyles);+ const { colors: userBubbleColors } = useUserBubbleAppearance();if (message.kind === 'round-end') {return <BotGroupDivider testID="botGroup.roundEnd"><Text style={styles.dividerText}>{t('groupChat.timeline.roundEnded')}</Text>@@ -478,7 +480,11 @@ function BotGroupTimelineItem({{attachments.length > 0? <BotGroupMessageAttachments messageId={message.id} attachments={attachments} align="right" onResolveRemoteMedia={resolveMedia} resolveServerMedia={resolveServerMedia} />: null}- {bubble ? <View style={[styles.userBubble, compact && styles.userBubbleCompact]} testID="botGroup.message.userBubble">+ {bubble ? <View style={[+ styles.userBubble,+ compact && styles.userBubbleCompact,+ userBubbleColors && { backgroundColor: userBubbleColors.background, borderColor: userBubbleColors.border },+ ]} testID="botGroup.message.userBubble"><BotGroupUserText content={message.content} mentionLabels={mentionLabels} /></View> : null}</View>diff --git a/apps/mobile/src/session/MessageRenderer.tsx b/apps/mobile/src/session/MessageRenderer.tsxindex 5ed7ba619b..62ece6166b 100644--- a/apps/mobile/src/session/MessageRenderer.tsx+++ b/apps/mobile/src/session/MessageRenderer.tsx@@ -411,6 +411,7 @@ import type { RemoteTextFilePreviewResult } from '@/device-link/mobileMakerTransimport { fontWeight, lineHeight, radius, spacing, typeScale } from '@/theme/tokens';import { iconSize, iconStroke, monoFont, useTheme, useThemedStyles, type ThemeColors } from '@/theme';import { useUserBubbleAppearance } from '@/theme/userBubblePreference';+import { isOwnUserBubble } from './userBubbleOwnership';import { i18n } from '@/i18n';import { formatLocalizedDuration } from '@/session/sessionDurationFormat';import { mobilePresentationLocalizer } from '@/i18n/presentationLocalizer';@@ -3371,6 +3372,7 @@ function MessageBubble({actions: MessageActions & { firstUserMessageClientId?: string };}) {const { colors: userBubbleColors } = useUserBubbleAppearance();+ const { user: viewer } = useAuth();const styles = useThemedStyles(makeStyles);const { colors, mode } = useTheme();const { t, i18n: i18nInstance } = useTranslation();@@ -3752,7 +3754,9 @@ function MessageBubble({isUser ? styles.userBubble : styles.agentBubble,actions.companion && !isUser && !item.message.systemCardType && styles.companionAnswer,hookSource && styles.hookSourceBubble,- isUser && !item.message.systemCardType && userBubbleColors && { backgroundColor: userBubbleColors.background, borderColor: userBubbleColors.border },+ isUser && !item.message.systemCardType && userBubbleColors+ && isOwnUserBubble(item.message, { accountId: viewer?.id, remoteDeviceId: actions.remoteDeviceId })+ && { backgroundColor: userBubbleColors.background, borderColor: userBubbleColors.border },]}testID={isUser ? 'message.userBubble' : 'message.agentBubble'}>diff --git a/apps/mobile/src/session/PendingSendBubble.tsx b/apps/mobile/src/session/PendingSendBubble.tsxindex acf07f9a84..ee951bd9d0 100644--- a/apps/mobile/src/session/PendingSendBubble.tsx+++ b/apps/mobile/src/session/PendingSendBubble.tsx@@ -66,6 +66,7 @@ import {type ThemeColors,} from '@/theme';import { radius, spacing, typeScale } from '@/theme/tokens';+import { useUserBubbleAppearance } from '@/theme/userBubblePreference';/** 与已发送消息上的来源标签同一组图标(自动化 Timer / 任务 Send / Orca Bot / 插件 Ghost)。 */function sourceIcon(kind: MobilePendingSendSourceKind): LucideIcon {@@ -228,6 +229,8 @@ export function PendingSendBubble({const styles = useThemedStyles(makeStyles);const { colors } = useTheme();const { t } = useTranslation();+ // 待发送的一定是自己的消息;与落定后的正式气泡同色,避免发出瞬间换色。+ const { colors: userBubbleColors } = useUserBubbleAppearance();const spinning = pendingSendSpins(item.phase);const editing = item.phase === 'editing';const failed = item.phase === 'failed';@@ -426,7 +429,12 @@ export function PendingSendBubble({onTouchMove={interactive ? handleBubbleTouchMove : undefined}onTouchStart={interactive ? handleBubbleTouchStart : undefined}onTouchCancel={cancelBubbleTouch}- style={[styles.bubble, density === 'compact' && styles.bubbleCompact, density === 'rich' && styles.bubbleRich]}+ style={[+ styles.bubble,+ density === 'compact' && styles.bubbleCompact,+ density === 'rich' && styles.bubbleRich,+ userBubbleColors && { backgroundColor: userBubbleColors.background, borderColor: userBubbleColors.border },+ ]}testID={`pendingSend.body.${item.clientId}`}>{rendersSentInlineBody ? (diff --git a/apps/mobile/src/session/messageNormalize.ts b/apps/mobile/src/session/messageNormalize.tsindex c1814c099e..71a7a1dd38 100644--- a/apps/mobile/src/session/messageNormalize.ts+++ b/apps/mobile/src/session/messageNormalize.ts@@ -32,7 +32,7 @@ import {type MessageSourceGroup,type MessageSourcePlugin,} from '@cindy/maker-shared/message-source';-import { sharedTaskAuthorMemberId, sharedTaskAuthorName } from '@cindy/maker-shared';+import { sharedTaskAuthorAccountId, sharedTaskAuthorMemberId, sharedTaskAuthorName } from '@cindy/maker-shared';import { stripGoalVerdictBlock } from '@cindy/maker-shared/goal-verdict';import {formatToolResultCompactionBytes,@@ -170,6 +170,8 @@ export interface NormalizedRemoteMessage {sharedAuthorName?: string;/** 共享任务成员 id(作者标签长按显示,与模型 `[消息来源]` 的 member_id 同源)。 */sharedAuthorMemberId?: string;+ /** 共享任务作者账号 id;只用于展示归属(如「我的消息气泡颜色」只染自己的消息),不作权限依据。 */+ sharedAuthorAccountId?: string;/*** user 专用:合成 UI 指令行(桌面「失败后继续 / 中断续跑」等隐藏 prompt,* `[UI_ACTION_TRIGGER]` 前缀,对齐桌面 makerChatStore 同名标记)。保留在@@ -1103,16 +1105,18 @@ function readAutomationOrigin(message: RemoteMessage): Pick<NormalizedRemoteMess// message-source 助手,与发给模型的来源说明同一份事实。function readMessageSourceFields(message: RemoteMessage,-): Pick<NormalizedRemoteMessage, 'sourceDevice' | 'sourcePlugin' | 'sharedAuthorName' | 'sharedAuthorMemberId'> {+): Pick<NormalizedRemoteMessage, 'sourceDevice' | 'sourcePlugin' | 'sharedAuthorName' | 'sharedAuthorMemberId' | 'sharedAuthorAccountId'> {const sourceDevice = readMessageSourceDevice(message.agentMeta);const sourcePlugin = readMessageSourcePlugin(message.agentMeta);const sharedAuthorName = sanitizeSourceName(sharedTaskAuthorName(message.agentMeta));const sharedAuthorMemberId = sharedAuthorName ? sharedTaskAuthorMemberId(message.agentMeta) : undefined;+ const sharedAuthorAccountId = sharedTaskAuthorAccountId(message.agentMeta);return {...(sourceDevice ? { sourceDevice } : {}),...(sourcePlugin ? { sourcePlugin } : {}),...(sharedAuthorName ? { sharedAuthorName } : {}),...(sharedAuthorMemberId ? { sharedAuthorMemberId } : {}),+ ...(sharedAuthorAccountId ? { sharedAuthorAccountId } : {}),};}diff --git a/apps/mobile/src/session/userBubbleOwnership.ts b/apps/mobile/src/session/userBubbleOwnership.tsnew file mode 100644index 0000000000..b1acea83fa--- /dev/null+++ b/apps/mobile/src/session/userBubbleOwnership.ts@@ -0,0 +1,18 @@+import { isSharedTaskPeer } from '@cindy/device-link';++/**+ * 「我的消息气泡颜色」只染确定是自己发的消息。共享任务里所有 user 消息都右对齐,+ * 不能按对齐判断:+ * - 带共享作者的消息(访客发的)只有作者账号是当前账号才算自己的;+ * - 没有共享作者的消息是房主本人发的,只有当前不是以访客身份查看共享任务时才算自己的。+ * 归属只用于展示,不作权限依据。+ */+export function isOwnUserBubble(+ message: { sharedAuthorName?: string; sharedAuthorAccountId?: string },+ viewer: { accountId?: string | null; remoteDeviceId?: string },+): boolean {+ if (message.sharedAuthorName || message.sharedAuthorAccountId) {+ return !!viewer.accountId && message.sharedAuthorAccountId === viewer.accountId;+ }+ return !isSharedTaskPeer(viewer.remoteDeviceId);+}diff --git a/apps/mobile/src/settings/UserBubblePage.ios.tsx b/apps/mobile/src/settings/UserBubblePage.ios.tsxindex a40fd3dca1..6de6d38a03 100644--- a/apps/mobile/src/settings/UserBubblePage.ios.tsx+++ b/apps/mobile/src/settings/UserBubblePage.ios.tsx@@ -26,7 +26,6 @@ import {import {USER_BUBBLE_PRESETS,parseUserBubblePreference,- resolveUserBubbleColors,userBubbleSeed,type UserBubblePreference,} from "@cindy/maker-shared";@@ -45,7 +44,10 @@ import {spacing,typeScale,} from "@/theme";-import { useUserBubbleAppearance } from "@/theme/userBubblePreference";+import {+ resolveMobileUserBubbleColors,+ useUserBubbleAppearance,+} from "@/theme/userBubblePreference";import { goBackGuarded } from "@/utils/backGuard";import { UserBubbleHueSlider, hexToHue, hueToHex } from "./UserBubbleHueSlider";@@ -76,7 +78,7 @@ export function UserBubblePage() {// 拖动中的颜色只留在本页;松手才写全局偏好,避免所有已挂载的会话气泡逐帧重绘。const [draft, setDraft] = useState<string | null>(null);const bubble = draft- ? resolveUserBubbleColors(parseUserBubblePreference(draft), mode)+ ? resolveMobileUserBubbleColors(parseUserBubblePreference(draft), mode, colors): saved;const custom = preference.startsWith("#");// 偏好异步加载,首帧可能还是 default;起点在点按「自定义颜色」时再取。@@ -94,10 +96,14 @@ export function UserBubblePage() {}, [preference]);const [dragging, setDragging] = useState(false);const label = (name: string) => t(`settings.appearance.userBubble.${name}`);- const select = (next: UserBubblePreference) => {- if (next === preference) return;+ // 写入失败时内存里已是新值,所以「重试」要强制再写一次,不能被「没变化」跳过。+ const select = (next: UserBubblePreference, force = false) => {+ if (!force && next === preference) return;void setPreference(next).catch(() =>- Alert.alert(label("title"), label("saveFailed")),+ Alert.alert(label("title"), label("saveFailed"), [+ { text: label("cancel"), style: "cancel" },+ { text: label("retry"), onPress: () => select(next, true) },+ ]),);};return (@@ -152,7 +158,7 @@ export function UserBubblePage() {testID="settings.userBubble.presets">{USER_BUBBLE_PRESETS.map((id) => {- const swatch = resolveUserBubbleColors(id, mode);+ const swatch = resolveMobileUserBubbleColors(id, mode, colors);return (<HStack key={id} spacing={spacing.md} modifiers={[tag(id)]}><Circlediff --git a/apps/mobile/src/settings/UserBubbleSettings.tsx b/apps/mobile/src/settings/UserBubbleSettings.tsxindex d0a359eb56..48af98613c 100644--- a/apps/mobile/src/settings/UserBubbleSettings.tsx+++ b/apps/mobile/src/settings/UserBubbleSettings.tsx@@ -13,7 +13,6 @@ import {USER_BUBBLE_PRESETS,bubbleHueColor,parseUserBubblePreference,- resolveUserBubbleColors,userBubbleSeed,type UserBubblePreference,} from "@cindy/maker-shared";@@ -37,7 +36,10 @@ import {spacing,typeScale,} from "@/theme";-import { useUserBubbleAppearance } from "@/theme/userBubblePreference";+import {+ resolveMobileUserBubbleColors,+ useUserBubbleAppearance,+} from "@/theme/userBubblePreference";export function UserBubbleSettings() {const { t } = useTranslation();@@ -60,7 +62,10 @@ export function UserBubbleSettings() {const label = (name: string) => t(`settings.appearance.userBubble.${name}`);const select = (next: UserBubblePreference) => {void setPreference(next).catch(() =>- Alert.alert(label("title"), label("saveFailed")),+ Alert.alert(label("title"), label("saveFailed"), [+ { text: label("cancel"), style: "cancel" },+ { text: label("retry"), onPress: () => select(next) },+ ]),);};return (@@ -114,7 +119,7 @@ export function UserBubbleSettings() {</View><View style={styles.grid}>{USER_BUBBLE_PRESETS.map((id) => {- const palette = resolveUserBubbleColors(id, mode);+ const palette = resolveMobileUserBubbleColors(id, mode, colors);return (<Pressablekey={id}diff --git a/apps/mobile/src/theme/userBubblePreference.ts b/apps/mobile/src/theme/userBubblePreference.tsindex 8616b3b779..ef3b5ce422 100644--- a/apps/mobile/src/theme/userBubblePreference.ts+++ b/apps/mobile/src/theme/userBubblePreference.ts@@ -6,6 +6,24 @@ import {type UserBubblePreference,} from "@cindy/maker-shared";import { useTheme } from "./ThemeProvider";+import type { ThemeColors, ThemeMode } from "./tokens";++/** 气泡里实际会画出的文字色(正文、次要、弱提示、行内代码);底色按它们收敛到可读。 */+export function resolveMobileUserBubbleColors(+ preference: UserBubblePreference,+ mode: ThemeMode,+ colors: Pick<+ ThemeColors,+ "textPrimary" | "textSecondary" | "textTertiary" | "chatInlineCodeText"+ >,+) {+ return resolveUserBubbleColors(preference, mode, [+ colors.textPrimary,+ colors.textSecondary,+ colors.textTertiary,+ colors.chatInlineCodeText,+ ]);+}const key = "cindy.mobile.user-bubble.v1";let current: UserBubblePreference = "default";@@ -54,7 +72,7 @@ export function saveUserBubblePreference(return write;}export function useUserBubbleAppearance() {- const { mode } = useTheme();+ const { mode, colors } = useTheme();const preference = useSyncExternalStore(subscribe,() => current,@@ -67,6 +85,6 @@ export function useUserBubbleAppearance() {preference,setPreference: saveUserBubblePreference,mode,- colors: resolveUserBubbleColors(preference, mode),+ colors: resolveMobileUserBubbleColors(preference, mode, colors),};}diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.mdindex 28546c0924..c83fbe808b 100644--- a/docs/design-rules/DESIGN.md+++ b/docs/design-rules/DESIGN.md@@ -196,11 +196,11 @@ motion; inspect the complete action and loop boundary before accepting an asset.### Personal message bubble colors (Mobile, 2026-10-12)-手机版设置提供「我的消息气泡颜色」:默认继续跟随现有主题,另有初稿、晨光、灵感、梦境、夜猫、项圈六个预设和自定义颜色。名称取自 Cindy 自身的设定(创作的一天、黑猫与红项圈),不使用公司名或游戏 IP;各语言意译,不逐字翻译。此项是用户主动选择的个性化例外,只作用于用户消息正文气泡与设置预览,不染色 Agent 回复、系统卡片或页面背景。偏好仅保存在本机;选「默认」即删除 override。桌面端暂未提供。+手机版设置提供「我的消息气泡颜色」:默认继续跟随现有主题,另有初稿、晨光、灵感、梦境、夜猫、项圈六个预设和自定义颜色。名称取自 Cindy 自身的设定(创作的一天、黑猫与红项圈),不使用公司名或游戏 IP;各语言意译,不逐字翻译。此项是用户主动选择的个性化例外,只作用于确认是自己发出的消息气泡(会话、待发送与伙伴群聊)和设置预览,不染色 Agent 回复、系统卡片或页面背景。共享任务里所有 user 消息都右对齐,因此按归属而不是对齐判断:访客消息只有作者账号是当前账号才染,房主消息只在不是以访客身份查看时染;归属只用于展示,不作权限依据。偏好仅保存在本机;选「默认」即删除 override。桌面端暂未提供。-颜色由 packages/maker-shared/src/userBubbleAppearance.ts 在运行期按 light/dark 生成背景、前景与描边,属于治理合同 §3.4 的运行时派生值,消费者只用该结果,不把用户输入直接拼进样式。预设柔化较强;自定义色着色更明显,深色模式的着色上限保证正文对比度不低于 7:1。项圈取品牌红色相,只用柔化后的浅红调,不直接使用品牌红。+颜色由 packages/maker-shared/src/userBubbleAppearance.ts 在运行期按 light/dark 生成背景、前景与描边,属于治理合同 §3.4 的运行时派生值,消费者只用该结果,不把用户输入直接拼进样式。预设柔化较强;自定义色着色更明显。着色强度会自动收敛到气泡内实际出现的文字(正文、次要文字、弱提示、行内代码)都不低于 4.5:1、派生前景不低于 7:1;已满足的颜色不降低。项圈取品牌红色相,只用柔化后的浅红调,不直接使用品牌红。-iOS 使用原生 Form 二级页:顶部是与真实气泡同款的预览,预设与「自定义颜色」同在一个 inline Picker 勾选列表;选中自定义才在其下展开一条彩虹色带(仅选色相,外形对齐系统滑块)。iOS 没有比系统 ColorPicker 更轻的自由选色组件,系统取色面板因功能过多不采用。拖动时只更新本页预览,松手才保存。Android 沿用设置页内的面板实现。+iOS 使用原生 Form 二级页:顶部是与真实气泡同款的预览,预设与「自定义颜色」同在一个 inline Picker 勾选列表;选中自定义才在其下展开一条彩虹色带(仅选色相,外形对齐系统滑块)。iOS 没有比系统 ColorPicker 更轻的自由选色组件,系统取色面板因功能过多不采用。拖动时只更新本页预览,松手才保存;保存失败的提示提供「重试」。Android 沿用设置页内的面板实现。### Chip & Button Neutralsdiff --git a/docs/design-rules/design-inventory.md b/docs/design-rules/design-inventory.mdindex e7e910f6dd..debfe32aad 100644--- a/docs/design-rules/design-inventory.md+++ b/docs/design-rules/design-inventory.md@@ -9,7 +9,7 @@本区块由 `scripts/design-inventory.mjs` 生成,请勿手改。重新生成:`pnpm design:inventory`;校验:`pnpm check:design-inventory`。-计数快照日期:2026-10-11。生成命令:`pnpm design:inventory`。裸颜色匹配与 `scripts/hardcoded-color-audit.mjs` 共用 `scripts/shared/hardcoded-color-match.mjs`(HEX / RGB / HSL / OKLCH 等字面通道),两者在共享 matcher 内统一排除纯语义包装、注释及 PR 编号;数值颜色函数还需位于样式属性、CSS 声明/函数或任意值语境,普通文案字符串里的颜色函数文本不计入;字面 fallback 仍计入——语义 token 消费与注释引用不是迁移债务;裸圆角为粗粒度(`rounded*` class、`border-radius:` 与 React style 对象的 `borderRadius:`)。Token 计数为样式源里 `var(--token)` / `hsl(var(--token)` 的去重 ID 数;Mobile 的 ThemeColors / typeScale 等 RN 属性不计入此列,不能将 0 解释为未使用 Token。+计数快照日期:2026-10-12。生成命令:`pnpm design:inventory`。裸颜色匹配与 `scripts/hardcoded-color-audit.mjs` 共用 `scripts/shared/hardcoded-color-match.mjs`(HEX / RGB / HSL / OKLCH 等字面通道),两者在共享 matcher 内统一排除纯语义包装、注释及 PR 编号;数值颜色函数还需位于样式属性、CSS 声明/函数或任意值语境,普通文案字符串里的颜色函数文本不计入;字面 fallback 仍计入——语义 token 消费与注释引用不是迁移债务;裸圆角为粗粒度(`rounded*` class、`border-radius:` 与 React style 对象的 `borderRadius:`)。Token 计数为样式源里 `var(--token)` / `hsl(var(--token)` 的去重 ID 数;Mobile 的 ThemeColors / typeScale 等 RN 属性不计入此列,不能将 0 解释为未使用 Token。登记 surface 数:52。平台包含 Desktop 与 Mobile;静态入口发现不表示已迁移或已实机验证。diff --git a/packages/maker-shared/src/__tests__/userBubbleAppearance.test.ts b/packages/maker-shared/src/__tests__/userBubbleAppearance.test.tsindex 512169c150..932e8a9004 100644--- a/packages/maker-shared/src/__tests__/userBubbleAppearance.test.ts+++ b/packages/maker-shared/src/__tests__/userBubbleAppearance.test.ts@@ -1,8 +1,11 @@import { describe, expect, it } from "vitest";import {USER_BUBBLE_PRESETS,+ bubbleHueColor,+ contrastRatio,parseUserBubblePreference,resolveUserBubbleColors,+ type UserBubblePreference,} from "../userBubbleAppearance";function luminance(hex: string) {@@ -45,4 +48,38 @@ describe("personal message bubble appearance", () => {}}});+ it("keeps every text role drawn in the bubble readable, tinting only as far as needed", () => {+ // Body, secondary and inline-code text of the mobile themes (light / dark).+ const roles = {+ light: ["#0F0F0F", "#4D4D4A", "#686864"],+ dark: ["#EDEDED", "#BDBDBD", "#999999"],+ } as const;+ const custom: UserBubblePreference[] = [+ "#000000",+ "#ffffff",+ "#ff0000",+ "#00ff00",+ "#0000ff",+ ...Array.from(+ { length: 36 },+ (_, i) => bubbleHueColor(i * 10) as `#${string}`,+ ),+ ];+ for (const mode of ["light", "dark"] as const) {+ for (const preference of [...USER_BUBBLE_PRESETS.slice(1), ...custom]) {+ const { background } = resolveUserBubbleColors(+ preference,+ mode,+ roles[mode],+ )!;+ for (const role of roles[mode]) {+ expect(contrastRatio(background, role)).toBeGreaterThanOrEqual(4.5);+ }+ }+ }+ // A color that already reads well keeps its full tint.+ expect(resolveUserBubbleColors("sage", "light", roles.light)).toEqual(+ resolveUserBubbleColors("sage", "light"),+ );+ });});diff --git a/packages/maker-shared/src/sharedTask.ts b/packages/maker-shared/src/sharedTask.tsindex 1dd9237550..7ad15ebbd0 100644--- a/packages/maker-shared/src/sharedTask.ts+++ b/packages/maker-shared/src/sharedTask.ts@@ -21,6 +21,16 @@ export function sharedTaskAuthorMemberId(meta: unknown): string | undefined {: undefined;}+/** Account id of the shared-task author; display attribution only (e.g. "is this my message"), never authority. */+export function sharedTaskAuthorAccountId(meta: unknown): string | undefined {+ if (!meta || typeof meta !== 'object' || !('sharedTaskAuthor' in meta)) return undefined;+ const author = meta.sharedTaskAuthor;+ if (!author || typeof author !== 'object' || !('accountId' in author)) return undefined;+ return typeof author.accountId === 'string' && author.accountId.trim()+ ? author.accountId.trim().slice(0, 128)+ : undefined;+}+/** Tolerant projection for old history; this is attribution, never authority. */export function sharedTaskAuthorName(meta: unknown): string | undefined {if (!meta || typeof meta !== 'object' || !('sharedTaskAuthor' in meta)) return undefined;diff --git a/packages/maker-shared/src/userBubbleAppearance.ts b/packages/maker-shared/src/userBubbleAppearance.tsindex 41917c7cdb..ed8ba4850d 100644--- a/packages/maker-shared/src/userBubbleAppearance.ts+++ b/packages/maker-shared/src/userBubbleAppearance.ts@@ -70,25 +70,61 @@ export function userBubbleSeed(/*** Presets stay soft; custom colors are tinted more so the chosen hue reads clearly.- * Dark tint is capped so theme text keeps >= 7:1 contrast even on a white seed.+ * The derived foreground keeps >= 7:1. Callers pass the theme text colors that are+ * actually drawn inside the bubble (body, secondary, inline code...); the tint is+ * reduced until every one of them keeps >= 4.5:1. Zero tint is the theme-neutral+ * surface, which those roles already satisfy.*/const tint = {preset: { light: 0.16, dark: 0.13 },custom: { light: 0.3, dark: 0.18 },};+const FOREGROUND_MIN_CONTRAST = 7;+const TEXT_ROLE_MIN_CONTRAST = 4.5;+function luminance(hex: string): number {+ const [r, g, b] = rgb(hex)+ .map((v) => v / 255)+ .map((v) => (v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4));+ return r * 0.2126 + g * 0.7152 + b * 0.0722;+}+export function contrastRatio(a: string, b: string): number {+ const [x, y] = [luminance(a), luminance(b)];+ return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);+}export function resolveUserBubbleColors(preference: UserBubblePreference,mode: "light" | "dark",+ textRoles: readonly string[] = [],) {const seed = userBubbleSeed(preference);if (!seed) return null;const channels = rgb(seed);const dark = mode === "dark";- const strength = tint[preference.startsWith("#") ? "custom" : "preset"][mode];- const background = toHex(- channels.map((v) => (dark ? 27 + v * strength : 255 - (255 - v) * strength)),- );const foreground = toHex(Array(3).fill(dark ? 232 : 38));+ const mix = (strength: number) =>+ toHex(+ channels.map((v) =>+ dark ? 27 + v * strength : 255 - (255 - v) * strength,+ ),+ );+ const readable = (background: string) =>+ contrastRatio(background, foreground) >= FOREGROUND_MIN_CONTRAST &&+ textRoles.every(+ (role) => contrastRatio(background, role) >= TEXT_ROLE_MIN_CONTRAST,+ );+ let strength = tint[preference.startsWith("#") ? "custom" : "preset"][mode];+ if (!readable(mix(strength))) {+ // Luminance moves monotonically with strength, so the largest readable tint is a bisection.+ let low = 0;+ let high = strength;+ for (let i = 0; i < 16; i += 1) {+ const middle = (low + high) / 2;+ if (readable(mix(middle))) low = middle;+ else high = middle;+ }+ strength = low;+ }+ const background = mix(strength);const border = toHex(rgb(background).map((v) => (dark ? v + 22 : v - 24)));return { background, foreground, border };}