Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(desktop): X 卡告知用法、公开风险与撤回方式,首次绑定拦一次确认 (#1347)
Dash4841731363ec
diff --git a/apps/desktop/src/renderer/__tests__/xUsageGuideCopy.test.ts b/apps/desktop/src/renderer/__tests__/xUsageGuideCopy.test.tsnew file mode 100644index 0000000000..e05ccddd0e--- /dev/null+++ b/apps/desktop/src/renderer/__tests__/xUsageGuideCopy.test.ts@@ -0,0 +1,162 @@+/**+ * X 用法与风险告知的四语言文案契约。+ *+ * 为什么需要专门一测:这一节的文案里有两样东西**没有任何编译期约束**,而写错的后果+ * 都是用户可见的 ——+ *+ * 1. **bot handle `@askmycindy` 硬编码在四份 locale 里。** 它不来自 binding:这一节+ * 在用户还没绑定时就要显示(评估阶段最需要看到风险), 那时候拿不到 scopeName。+ * 改 handle 时四份都得改, 漏一份就会让那个语言的用户去 @ 一个不存在的账号。+ * (硬编码是安全的: cn 与 global 两份 endpoint manifest 的 xHookWsUrl 指向同一个+ * x-hook 服务, 也就是同一个 bot。)+ * 2. **`/删除` 只该出现在 zh-CN。** 中文命令词对非中文用户是噪音 —— 他们既不会打,+ * 也会被这串看不懂的字符干扰(Dash 2026-08-02 明确)。而服务端两个词都收, 所以+ * 少宣传一个不影响任何功能。+ *+ * 三组文案本身的准确性由 XUsageGuide 的注释与 HookConnectionsSection 的用例守着;+ * 这里只钉这两条「跨语言必须一致 / 必须不一致」的契约。+ */++import { describe, expect, it } from 'vitest';++import en from '../i18n/locales/en/common.json';+import ja from '../i18n/locales/ja/common.json';+import ko from '../i18n/locales/ko/common.json';+import zhCN from '../i18n/locales/zh-CN/common.json';++const BOT_HANDLE = '@askmycindy';++type GuideCopy = {+ usageLabel: string;+ usageBody: string;+ riskLabel: string;+ riskPublicBody: string;+ riskWorkdirBody: string;+ withdrawLabel: string;+ withdrawBody: string;+ ackTitle: string;+ ackConfirm: string;+};++const LOCALES: Record<string, GuideCopy> = {+ 'zh-CN': (zhCN as never as { settings: { remoteControl: { hook: { x: { guide: GuideCopy } } } } })+ .settings.remoteControl.hook.x.guide,+ en: (en as never as { settings: { remoteControl: { hook: { x: { guide: GuideCopy } } } } })+ .settings.remoteControl.hook.x.guide,+ ja: (ja as never as { settings: { remoteControl: { hook: { x: { guide: GuideCopy } } } } })+ .settings.remoteControl.hook.x.guide,+ ko: (ko as never as { settings: { remoteControl: { hook: { x: { guide: GuideCopy } } } } })+ .settings.remoteControl.hook.x.guide,+};++describe('X 用法与风险告知的四语言文案', () => {+ it('四份 locale 都齐全, 没有空串', () => {+ for (const [loc, guide] of Object.entries(LOCALES)) {+ for (const [key, value] of Object.entries(guide)) {+ expect(typeof value, `${loc}.${key}`).toBe('string');+ expect(value.trim().length, `${loc}.${key} 不能为空`).toBeGreaterThan(0);+ }+ }+ });++ it('每份 locale 的用法说明都写出 bot handle: 漏一份就让那个语言的用户 @ 错账号', () => {+ for (const [loc, guide] of Object.entries(LOCALES)) {+ expect(guide.usageBody, `${loc}.usageBody 必须含 ${BOT_HANDLE}`).toContain(BOT_HANDLE);+ }+ });++ it('撤回说明都写出 /delete: 那是唯一四语通用的命令词', () => {+ for (const [loc, guide] of Object.entries(LOCALES)) {+ expect(guide.withdrawBody, `${loc}.withdrawBody 必须含 /delete`).toContain('/delete');+ }+ });++ it('中文命令词 /删除 只出现在 zh-CN: 对非中文用户是噪音', () => {+ expect(LOCALES['zh-CN'].withdrawBody).toContain('/删除');+ for (const loc of ['en', 'ja', 'ko']) {+ expect(LOCALES[loc].withdrawBody, `${loc} 不该提 /删除`).not.toContain('删除');+ }+ });++ it('风险那两条都点明了公开可见与默认工作目录', () => {+ // 这一节存在的理由。zh-CN 用关键词钉住, 其它语言只钉「两条都非空且互不相同」——+ // 关键词逐语言硬编码会变成翻译的枷锁, 而空/重复才是真正会丢信息的失败形态。+ expect(LOCALES['zh-CN'].riskPublicBody).toContain('公开');+ expect(LOCALES['zh-CN'].riskWorkdirBody).toContain('默认工作目录');+ for (const [loc, guide] of Object.entries(LOCALES)) {+ expect(guide.riskPublicBody, `${loc} 两条风险不得相同`).not.toBe(guide.riskWorkdirBody);+ }+ });++ it('确认按钮必须点名确认对象, 不能是泛化应答词', () => {+ // DESIGN.md §11.1「Actions = verb + object, never a bare verb」明确禁 Confirm /+ // OK / 确定 / 提交 这类无对象应答词, 并**点名 confirm-dialog 主按钮**必须带对象+ // ——「so they read correctly out of context」。这个按钮是风险告知的同意门, 被读屏+ // 单独播报时若只念「我明白」, 用户根本不知道自己在确认什么(#1347 review 由 codex+ // 指出 P2; 初版四语分别是「我明白」/ Got it / 了解しました / 이해했어요)。+ const BANNED: Record<string, readonly string[]> = {+ 'zh-CN': ['我明白', '知道了', '确定', '提交'],+ en: ['Got it', 'Got It', 'OK', 'Confirm'],+ ja: ['了解しました', 'OK'],+ ko: ['이해했어요', '확인'],+ };+ // 对象 = 风险本身。四语各自的说法, 比"长度下限"之类的代理判据准确。+ const OBJECT: Record<string, string> = {+ 'zh-CN': '风险',+ en: 'Risk',+ ja: 'リスク',+ ko: '위험',+ };+ for (const [loc, guide] of Object.entries(LOCALES)) {+ for (const word of BANNED[loc]) {+ expect(guide.ackConfirm, `${loc}.ackConfirm 不能是泛化应答词「${word}」`).not.toContain(+ word,+ );+ }+ expect(+ guide.ackConfirm,+ `${loc}.ackConfirm 必须点名确认对象(${OBJECT[loc]})`,+ ).toContain(OBJECT[loc]);+ }+ });++ it('工作目录那条不能用方位指代: 同一份文案也渲染在弹窗里, 弹窗里没有目录选择器', () => {+ // XUsageGuide 被**两处**渲染:X 卡内的常驻小节, 以及首次绑定的确认门弹窗。+ // 卡内「下面设的默认工作目录」是对的(选择器就在下方), 但弹窗里下方只有撤回那组+ // 和确认按钮 —— 方位指代会把用户指向一个不存在的控件, 而这恰好是他最需要去+ // 检查/更改那个目录的时刻(#1347 review 由 codex 指出 P2)。+ //+ // 修法刻意选「与上下文无关的措辞」而不是给组件加 variant:这一节的设计前提就是+ // 「一份文案、两处渲染, 不各写一份」, 加 variant 等于把它想消掉的漂移风险请回来。+ const BANNED: Record<string, readonly string[]> = {+ 'zh-CN': ['下面', '下方', '以下'],+ en: ['below'],+ ja: ['下で', '以下'],+ ko: ['아래'],+ };+ for (const [loc, guide] of Object.entries(LOCALES)) {+ for (const word of BANNED[loc]) {+ expect(+ guide.riskWorkdirBody,+ `${loc}.riskWorkdirBody 不能出现方位指代「${word}」—— 弹窗里指不到东西`,+ ).not.toContain(word);+ }+ }+ });++ it('公开风险那条必须给出「适合 / 不适合」的判断, 不能只陈述事实', () => {+ // Dash 2026-08-02 的产品表态:光说「回复是公开的」用户还得自己推导该拿它干什么。+ // 要明确说这个功能适合公开地找答案、解决问题, **不适合处理私事**(有隐私暴露风险)。+ // 这是最容易在后续翻译润色里被抹平的一句 —— 抹平之后风险告知就退回纯事实陈述。+ expect(LOCALES['zh-CN'].riskPublicBody).toContain('不适合');+ expect(LOCALES['zh-CN'].riskPublicBody).toContain('隐私');+ // 其它语言只钉长度:能承载「事实 + 适用性判断」两句的下限, 比逐语言硬编码关键词+ // 稳(译法可以变, 但把两句压成一句必然掉到这个长度以下)。+ for (const [loc, guide] of Object.entries(LOCALES)) {+ expect(+ guide.riskPublicBody.length,+ `${loc}.riskPublicBody 短到不可能同时讲清事实与适用性`,+ ).toBeGreaterThan(40);+ }+ });+});diff --git a/apps/desktop/src/renderer/__tests__/xUsageGuideRiskContrast.test.ts b/apps/desktop/src/renderer/__tests__/xUsageGuideRiskContrast.test.tsnew file mode 100644index 0000000000..e0b1af2a49--- /dev/null+++ b/apps/desktop/src/renderer/__tests__/xUsageGuideRiskContrast.test.ts@@ -0,0 +1,129 @@+/**+ * X 用法与风险告知 —— 风险那两段的对比度守卫。+ *+ * 为什么单独立一条:这两段是「回帖公开」与「默认工作目录可能随之公开」,是用户绑定后+ * 必须读清的后果,而它们坐在 `--warning-bg-soft` 的橙色 alpha 底上 —— 底色一合成,+ * 前景色的对比度就跟卡底上的数字不一样了,光看 token 名判断不出来。+ *+ * 初版用了 `--text-secondary`,四种主题/模式下实测 2.09 ~ 3.96,全部低于正文 4.5:1。+ * DESIGN.md §15.5 的 U2 裁决**明确把它的低对比限定在「二级信息」**(cindy-dark.ts 就把+ * 这个 token 标成「直映: 二级信息; U2 例外」),而这两段不是二级信息。同一条裁决还写明+ * text-secondary 的值 "never darken unilaterally" —— 所以修法只能是在组件内换语义色,+ * 不能去动全局 token(#1347 review 由 codex 指出 P2)。+ *+ * **本测试从组件源码里读出风险块实际用的 token**,再按四种主题/模式算合成后的对比度。+ * 这样写而不是把 'text-primary' 硬编码进断言:硬编码的话,谁把组件改回+ * `--text-secondary`,这条用例照样绿 —— 那就不是锚点了。+ */+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';++import { describe, expect, it } from 'vitest';++import { cindyDark } from '../themes/builtin/cindy-dark';+import { cindyLight } from '../themes/builtin/cindy-light';+import { colorRegistry } from '../themes/color-registry';+// 触发整表 registerColor 注册,resolveDefault 才拿得到 default 主题的值。+import '../themes/colors';++const guideSource = readFileSync(+ resolve(process.cwd(), 'src/renderer/components/settings/XUsageGuide.tsx'),+ 'utf8',+);++/** 从源码里切出风险块(warning callout 那个 div 到它闭合前),读出正文用的颜色 token。 */+function riskBodyColorToken(): string {+ const start = guideSource.indexOf('bg-[var(--warning-bg-soft)]');+ expect(start, '找不到 warning callout —— 风险块的形态被改过, 请同步本测试').toBeGreaterThan(0);+ const block = guideSource.slice(start, start + 900);+ const tokens = [...block.matchAll(/text-\[var\(--([a-z0-9-]+)\)\]/g)].map((m) => m[1]!);+ // callout 里有图标色(warning-fg)和正文色,取正文那个(出现在 span 上、非 warning-fg)+ const bodyTokens = [...new Set(tokens.filter((t) => t !== 'warning-fg'))];+ expect(bodyTokens, '风险块里的正文颜色 token 应当只有一个').toHaveLength(1);+ return bodyTokens[0]!;+}++type RGB = [number, number, number];++function parseHex(v: string): RGB {+ const h = v.replace('#', '');+ const full = h.length === 3+ ? h.split('').map((c) => c + c).join('')+ : h;+ const n = parseInt(full, 16);+ return [(n >> 16) & 255, (n >> 8) & 255, n & 255];+}++/** `rgba(r, g, b, a)` → [r,g,b,a]。warning-bg-soft 是 alpha 面,必须先合成再算对比度。 */+function parseRgba(v: string): { rgb: RGB; alpha: number } {+ const m = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)$/.exec(v.trim());+ expect(m, `warning-bg-soft 不是 rgba(): ${v}`).not.toBeNull();+ return {+ rgb: [Number(m![1]), Number(m![2]), Number(m![3])],+ alpha: m![4] === undefined ? 1 : Number(m![4]),+ };+}++function composite(fg: RGB, alpha: number, bg: RGB): RGB {+ return [0, 1, 2].map((i) => Math.round(fg[i]! * alpha + bg[i]! * (1 - alpha))) as RGB;+}++function luminance(rgb: RGB): number {+ const f = rgb.map((c) => {+ const s = c / 255;+ return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);+ });+ return 0.2126 * f[0]! + 0.7152 * f[1]! + 0.0722 * f[2]!;+}++function contrast(a: RGB, b: RGB): number {+ const la = luminance(a);+ const lb = luminance(b);+ const [hi, lo] = la > lb ? [la, lb] : [lb, la];+ return (hi + 0.05) / (lo + 0.05);+}++/** CINDY 主题没 override 的 token 落回 default(warning 系按规则 15 属语义豁免,不被 override)。 */+function resolve4(themeColors: Record<string, string> | null, id: string, mode: 'light' | 'dark'): string {+ const overridden = themeColors?.[id];+ if (overridden !== undefined) return overridden;+ const fallback = colorRegistry.resolveDefault(id, mode);+ expect(fallback, `token 未注册: ${id}`).not.toBeNull();+ return fallback!;+}++const SCENES = [+ { name: 'default light', colors: null, mode: 'light' as const },+ { name: 'default dark', colors: null, mode: 'dark' as const },+ { name: 'CINDY light', colors: cindyLight.colors as Record<string, string>, mode: 'light' as const },+ { name: 'CINDY dark', colors: cindyDark.colors as Record<string, string>, mode: 'dark' as const },+];++// 本组件渲染在两处:X 卡(surface-card-ivory)与首次绑定确认门(confirm-bg)。两处都要过。+const SURFACES = ['surface-card-ivory', 'confirm-bg'] as const;++describe('XUsageGuide 风险告知的对比度', () => {+ it('风险正文在四种主题/模式 × 卡底与弹窗底上都 ≥4.5:1(正文 AA)', () => {+ const token = riskBodyColorToken();+ const failures: string[] = [];+ for (const scene of SCENES) {+ const fg = parseHex(resolve4(scene.colors, token, scene.mode));+ const warn = parseRgba(resolve4(scene.colors, 'warning-bg-soft', scene.mode));+ for (const surface of SURFACES) {+ const base = parseHex(resolve4(scene.colors, surface, scene.mode));+ const ratio = contrast(fg, composite(warn.rgb, warn.alpha, base));+ if (ratio < 4.5) {+ failures.push(`${scene.name} × ${surface}: --${token} = ${ratio.toFixed(2)}:1`);+ }+ }+ }+ expect(failures, `风险告知的对比度不达正文 AA:\n${failures.join('\n')}`).toEqual([]);+ });++ it('风险块不得退回 --text-secondary:U2 例外只覆盖二级信息', () => {+ // 单独钉一条:上一条是数值守卫,这条把「为什么不能用它」写成可执行的判据 ——+ // 万一将来 text-secondary 的值被调亮到刚好过 4.5,数值守卫会放它过去,+ // 但 §15.5 的语义边界(U2 只给二级信息)仍然不允许拿它承载必读风险。+ expect(riskBodyColorToken()).not.toBe('text-secondary');+ });+});diff --git a/apps/desktop/src/renderer/__tests__/xUsageNotice.test.ts b/apps/desktop/src/renderer/__tests__/xUsageNotice.test.tsnew file mode 100644index 0000000000..269ed42add--- /dev/null+++ b/apps/desktop/src/renderer/__tests__/xUsageNotice.test.ts@@ -0,0 +1,112 @@+// @vitest-environment jsdom++import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++import {+ acknowledgeXUsage,+ isXUsageAcknowledged,+ resetXUsageNoticeMemoryState,+} from '@/state/xUsageNotice';++const STORAGE_KEY = 'xUsageNotice.acknowledgedPrincipals';++describe('xUsageNotice', () => {+ beforeEach(() => {+ localStorage.clear();+ resetXUsageNoticeMemoryState();+ });++ afterEach(() => {+ vi.restoreAllMocks();+ localStorage.clear();+ resetXUsageNoticeMemoryState();+ });++ it('确认过的账号判已知晓, 没确认过的不判', () => {+ expect(isXUsageAcknowledged('x-user-1')).toBe(false);+ acknowledgeXUsage('x-user-1');+ expect(isXUsageAcknowledged('x-user-1')).toBe(true);+ // 按 principalId 记账:换绑到另一个 X 账号是新的公开面, 应当再确认一次+ expect(isXUsageAcknowledged('x-user-2')).toBe(false);+ });++ it('空 principalId 既不记账也不判已知晓: 别把「拿不到账号 id」当成已确认', () => {+ acknowledgeXUsage('');+ expect(localStorage.getItem(STORAGE_KEY)).toBeNull();+ expect(isXUsageAcknowledged('')).toBe(false);+ });++ it('多次确认累积而不是互相覆盖', () => {+ acknowledgeXUsage('x-user-1');+ acknowledgeXUsage('x-user-2');+ expect(isXUsageAcknowledged('x-user-1')).toBe(true);+ expect(isXUsageAcknowledged('x-user-2')).toBe(true);+ expect(JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '[]')).toHaveLength(2);+ });++ it('坏数据按「没确认过」处理, 不抛错', () => {+ // 手改过 / 旧 schema。宁可多弹一次告知, 也绝不让整个设置页因此白屏。+ for (const bad of ['not json', '{"a":1}', '42', '"x-user-1"']) {+ localStorage.setItem(STORAGE_KEY, bad);+ expect(() => isXUsageAcknowledged('x-user-1')).not.toThrow();+ expect(isXUsageAcknowledged('x-user-1')).toBe(false);+ }+ });++ it('数组里的非字符串项被过滤掉, 不影响同数组里的合法项', () => {+ localStorage.setItem(STORAGE_KEY, JSON.stringify([null, 1, { a: 1 }, 'x-user-1']));+ expect(isXUsageAcknowledged('x-user-1')).toBe(true);+ });++ it('localStorage 写不进去时退到进程内兜底: 本次会话内不重复弹', () => {+ vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {+ throw new Error('quota exceeded');+ });+ acknowledgeXUsage('x-user-1');+ expect(isXUsageAcknowledged('x-user-1')).toBe(true);+ });++ it('localStorage 一直写不进去时, 多个账号在内存兜底里累积而不是互相覆盖', () => {+ // 上一条只测了**单个**账号, 所以漏掉了这个:storage 不可写时 readStored() 恒为空,+ // 写侧若只并 readStored, 第二个账号就把第一个从内存里覆盖掉 —— 用户切回第一个+ // 账号时又被拦一次, 而那次确认本该在本会话内一直有效(#1347 review 由 codex 指出)。+ vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {+ throw new Error('quota exceeded');+ });+ acknowledgeXUsage('x-user-1');+ acknowledgeXUsage('x-user-2');+ expect(isXUsageAcknowledged('x-user-1'), '第一个账号不该被第二个覆盖掉').toBe(true);+ expect(isXUsageAcknowledged('x-user-2')).toBe(true);+ });++ it('storage 从坏转好: 第一次写成功把内存里攒下的账号一并落盘', () => {+ const setItem = vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {+ throw new Error('quota exceeded');+ });+ acknowledgeXUsage('x-user-1');+ acknowledgeXUsage('x-user-2');+ setItem.mockRestore();+ acknowledgeXUsage('x-user-3');++ // 三个都在 storage 里, 内存态已清空 —— 所以 clear 之后三个都回到未确认+ expect(JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '[]').sort()).toEqual([+ 'x-user-1',+ 'x-user-2',+ 'x-user-3',+ ]);+ localStorage.clear();+ for (const id of ['x-user-1', 'x-user-2', 'x-user-3']) {+ expect(isXUsageAcknowledged(id), `${id} 应随 storage 清空回到未确认`).toBe(false);+ }+ });++ it('写成功后不留内存态: 别人清掉 key 之后本窗口要跟着回到未确认', () => {+ // 反方向的锚点。写成功时若同时置内存态, 跨窗口 clear 后本窗口会因为内存态+ // 永远判定已确认 —— inheritedSubscriptionNotice / providerOnboardingDismissal+ // 都踩过这一条。+ acknowledgeXUsage('x-user-1');+ expect(isXUsageAcknowledged('x-user-1')).toBe(true);+ localStorage.clear();+ expect(isXUsageAcknowledged('x-user-1')).toBe(false);+ });+});diff --git a/apps/desktop/src/renderer/components/settings/HookConnectionsSection.tsx b/apps/desktop/src/renderer/components/settings/HookConnectionsSection.tsxindex b2942fcc69..3d4b0d63d4 100644--- a/apps/desktop/src/renderer/components/settings/HookConnectionsSection.tsx+++ b/apps/desktop/src/renderer/components/settings/HookConnectionsSection.tsx@@ -49,6 +49,8 @@ import {import { useConfirmDialog } from '@/components/ui/confirm-dialog-provider';import { toast } from '@/lib/toast';import { extractIpcError } from '@/utils/ipcError';+import { acknowledgeXUsage, isXUsageAcknowledged } from '@/state/xUsageNotice';+import { XUsageGuide } from './XUsageGuide';import {HOOK_BIND_REASON_ALREADY_BOUND,HOOK_BIND_REASON_NOT_INSTALLED,@@ -429,6 +431,56 @@ export function HookConnectionsSection() {})();}, [awaitingInstall, confirm, handleToggle, runHookAction, t]);+ /**+ * X 的「用法与公开风险」确认门:绑定成功那一刻拦一次, 让用户明确点过「我明白」。+ *+ * 为什么不只靠卡内那一节:X 的回复是**公开推文**, 而且所有 X 任务都落在用户设的默认+ * 工作目录里(agent 能读写其中文件, 结论会公开回帖)—— 这两条后果只写在展开区里,+ * 不展开的人就永远看不到, 而它们恰恰是开启前就该知道的。+ *+ * 只在「未确认 → confirmed」那一沿弹一次:+ * - promptedPrincipalRef 记住正在弹或已弹过的 principalId, 状态广播导致的重渲染+ * 不重复弹(同上方"等安装"确认框的 ref 用法);+ * - 记账落在 principalId 上, 所以换绑到另一个 X 账号会再确认一次(新账号 = 新的+ * 公开面), 同账号解绑重绑则不打扰;+ * - **只有真的点了「我明白」才记账**。confirm-dialog 在 Esc / 点遮罩时 resolve 成+ * cancel(即 ok=false), 那种情况下用户并没有读到告知, 下次仍该弹。+ */+ const xBinding = hook?.x?.binding ?? null;+ const xConfirmedPrincipalId =+ xBinding !== null && xBinding.state === 'confirmed' ? xBinding.principalId : null;+ const promptedXPrincipalRef = useRef<string | null>(null);+ useEffect(() => {+ if (xConfirmedPrincipalId === null) {+ // 解绑 / 转入非 confirmed: 清掉本沿的记录, 下次绑定成功可以重新判定+ promptedXPrincipalRef.current = null;+ return;+ }+ if (promptedXPrincipalRef.current === xConfirmedPrincipalId) return;+ if (isXUsageAcknowledged(xConfirmedPrincipalId)) return;+ promptedXPrincipalRef.current = xConfirmedPrincipalId;+ void (async () => {+ const ok = await confirm({+ title: t('settings.remoteControl.hook.x.guide.ackTitle'),+ content: <XUsageGuide />,+ confirmText: t('settings.remoteControl.hook.x.guide.ackConfirm'),+ showCancel: false,+ // 主操作非破坏性(只是"我明白"), 焦点直接落在它上面+ autoFocusConfirm: true,+ maxWidth: 520,+ });+ if (!ok) {+ // Esc / 遮罩关掉 = 没读到, 允许下次再弹+ if (promptedXPrincipalRef.current === xConfirmedPrincipalId) {+ promptedXPrincipalRef.current = null;+ }+ return;+ }+ // 卸载后也照常落盘: 用户确实点过了, 少记一次会让他下次再被拦一遍+ acknowledgeXUsage(xConfirmedPrincipalId);+ })();+ }, [xConfirmedPrincipalId, confirm, t]);+const handleAddWorkspace = async () => {const res = await window.electronAPI.showOpenDirectoryDialog();if (res.canceled || !res.path) return;@@ -1043,6 +1095,15 @@ export function HookConnectionsSection() {</div>) : null}+ {/* X 专属: 用法与公开风险。两个刻意的选择 ——+ · 放在工作目录区**之前**: 风险那条讲的就是这张卡上那个默认工作目录,+ 顺序必须是先看到后果再碰控件。注意这只是**排布**上的先后 ——+ 文案本身不许用方位指代(「下面」/「below」), 因为同一组件也渲染进+ 确认门弹窗, 那里根本没有目录选择器;+ · **不按 view.enabled / cs.confirmed 收起**: 正在评估要不要打开的人+ 最需要看到「回帖是公开的」, 那时候两个条件都还不成立。 */}+ {provider === 'x' ? <XUsageGuide /> : null}+{/* 工作目录映射(清单共享, 偏好取本 provider 那份) */}{view.enabled? renderWorkdirSection(diff --git a/apps/desktop/src/renderer/components/settings/XUsageGuide.tsx b/apps/desktop/src/renderer/components/settings/XUsageGuide.tsxnew file mode 100644index 0000000000..c2cfbf0fab--- /dev/null+++ b/apps/desktop/src/renderer/components/settings/XUsageGuide.tsx@@ -0,0 +1,134 @@+/**+ * X 连接的「用法与风险」告知 —— X 卡内的常驻小节与首次绑定的确认门渲染的是+ * **同一个组件**,两处不各写一份文案:这份内容的价值全在准确,而复制两份必然漂移。+ *+ * 为什么 X 需要这一节, 而 Slack / Telegram 不需要:那两个是私密通道, 回复只有会话里+ * 的人能看到; **X 的回复是一条公开推文**。X 卡此前套用的是那两个渠道的文案口径+ * (「@提及 bot 即可派发任务」), 把这条性质差异整个漏掉了。+ *+ * 三组的取舍:+ * - 「怎么用」只说清一件事:@ 一下, 任务就派到**这台设备**上执行, 结论以回帖发回。+ * 用户最需要建立的心智模型是「X 那头只是入口, 活是在我这台机器上干的」。+ * - 「回帖是公开的」是本节存在的理由, 三层都要说:回复本身公开;**因此这个功能适合+ * 公开地找答案、解决问题, 不适合处理私事(有隐私暴露风险)**;以及 X 任务都落在默认+ * 工作目录、Agent 能读写其中文件而结论会公开回帖。中间那层是 Dash 明确要的产品+ * 表态 —— 光陈述「回复是公开的」还要用户自己推导该拿它干什么;第三层是用户判断+ * 「该不该把默认目录指到工作仓库」的唯一依据(均 2026-08-02 拍定)。+ * - 「想撤回」把服务端已交付的能力告诉用户 —— 做了但没人知道等于没做。+ *+ * 刻意不写进来的(2026-08-02 Dash 拍定):每日任务上限、上溯链上文进 prompt 的细节,+ * 以及「必须是你自己打的 @」这条约束。**最后一条有已知代价**:服务端的 isDirectMention+ * 只认用户自己打的 @, 所以用户在我们的回帖下追问时(X 自动带的继承前缀)那条追问会被+ * 判否、收不到回应 —— 要接着聊每次都得重新 @ 一次, 而现在没有任何地方告诉他。取舍是+ * 「这一节要短到有人读」优先;若日后有人反馈「追问没反应」, 这就是原因。+ *+ * **文案里不能用方位指代**(「下面」/「below」/「아래」…)。本组件被两处渲染:卡内小节+ * 与首次绑定的确认门弹窗 —— 卡内「下面」指得到目录选择器, 弹窗里下方只有撤回那组和+ * 确认按钮, 方位指代会把用户指向不存在的控件, 而那正是他最需要去检查那个目录的时刻+ * (#1347 review 由 codex 指出)。修法选「与上下文无关的措辞」而不是给组件加 variant:+ * 一加 variant 就把本组件想消掉的「两处文案漂移」风险请了回来。+ *+ * 三条落在文案里、代码里看不出来的约定(由 xUsageGuideCopy 测试守着):+ * - **bot handle `@askmycindy` 硬编码在四份 locale 的 usageBody 里。** 不走 binding:+ * 这一节在用户还没绑定时就要显示, 那时候没有 scopeName 可取。硬编码是安全的 ——+ * cn 与 global 两份 endpoint manifest 的 xHookWsUrl 指向同一个 x-hook 服务, 也就是+ * 同一个 bot。改 handle 时四份都要改。+ * - **`/删除` 只在 zh-CN 里提。** 服务端两个命令词都收, 但中文命令词对非中文用户+ * 是噪音, 少宣传一个不影响功能(Dash 2026-08-02)。+ */++import { AlertTriangle } from 'lucide-react';+import { useTranslation } from 'react-i18next';++/** 一组「标签 + 正文」。正文顶对齐、只向下伸展(见下方 clamp 说明)。 */+function GuideGroup({ label, children }: { label: string; children: React.ReactNode }) {+ return (+ <div className="flex flex-col gap-1">+ <span className="text-12 font-medium text-[var(--text-secondary)]">{label}</span>+ {children}+ </div>+ );+}++/**+ * 普通说明正文。+ *+ * **字号不得低于 12px。** DESIGN.md §3 的排版表把 Small(12px)定为「Smallest sans-serif+ * text」,并对 Micro Label(10–13px)写明「**Auxiliary / non-reading** labels only …+ * Never used for body text or anything the user reads sentence-by-sentence」。这两段是+ * 用法与撤回方式 —— 用户要逐句读、还要照着往 X 里打字的正文,不是辅助标签,所以走 Small+ * 而不是 Micro(初版误用 text-11,#1347 review 由 codex 指出 P2)。行高与本组件的风险+ * 组统一取 1.45,让三组正文只有一套度量。+ *+ * **刻意不加 line-clamp。** DESIGN.md 的说明/提示类槽位规则要求「顶对齐、槽高 = 行高 ×+ * 最大行数、折行只向下伸展」,它真正禁的是「固定小槽 + flex 垂直居中」那种会把超行文本+ * 上下双向外溢、压到相邻控件的写法 —— 这里是纯 flex 列、顶对齐、向下伸展,不会压到谁。+ * 而给一段风险告知加省略号截断,等于把我们必须告知的内容藏起来,方向完全反了;四语言里+ * 某种语言偶尔跑到三行,也比截断安全。文案本身按 ≤2 行写。+ *+ * **颜色沿用 --text-tertiary(本仓 settings 说明文字的既有 token,约 157 处在用),这里+ * 刻意没跟着风险组一起提到 --text-primary。** 两者的判据不同:风险组那两段叠在 warning+ * alpha 底上、且 U2 裁决把 text-secondary 的低对比明确限定在「二级信息」,所以必须换;+ * 而 text-tertiary 在 CINDY 两套主题里已经被整改到 AA(light #686B72 = 5.03、dark+ * #BFC1C4 = 7.38,cindy-*.ts 注明「整改: 非 U2 token AA」),default 主题那份值+ * (light #a3a3a3 = 2.39 / dark #737373 = 2.95)属**冻结的主题数据**,不是本组件能单方面+ * 决定的;只把这一节的说明文字提亮,会让它比 settings 里其它所有说明文字都重一档 ——+ * 那是视觉取舍而非规范缺陷,留给 Dash 判断。+ */+function GuideBody({ children }: { children: React.ReactNode }) {+ return <span className="text-12 leading-[1.45] text-[var(--text-tertiary)]">{children}</span>;+}++export function XUsageGuide() {+ const { t } = useTranslation();+ const k = (name: string) => `settings.remoteControl.hook.x.guide.${name}`;++ return (+ // select-text 是必须的, 不是顺手加的: 本组件也渲染进 ConfirmDialog, 而它的根节点+ // 带 select-none(confirm-dialog.tsx 的 Content), 于是弹窗里 `@askmycindy` 与+ // `/delete` 选不中、复制不了 —— 而这两个恰恰是用户要**打进 X** 的字符串。+ // DESIGN.md §14.1 的判据就是「用户会不会想复制它」: 会 → 可选。+ <div className="flex select-text flex-col gap-3">+ <GuideGroup label={t(k('usageLabel'))}>+ <GuideBody>{t(k('usageBody'))}</GuideBody>+ </GuideGroup>++ {/* 风险组:沿用仓内既有的 warning callout 形态(见 ModelPriceOverrideDialog 的+ 价格冲突提示)—— 图标 mt-0.5 shrink-0 顶对齐, 文本自己折行向下伸展。++ **但文字色刻意不跟那份:这两段走 --text-primary, 不是 --text-secondary。**+ DESIGN.md §15.5 的 U2 裁决把 text-secondary 的低对比**明确限定在「二级信息」**+ 并承认它低于正文 4.5:1(cindy-dark.ts 就把它标成「直映: 二级信息; U2 例外」)。+ 而这两段是用户绑定后必须读清的公开回帖与私密仓库暴露风险, 不是二级信息;+ 叠上 warning-bg-soft 的橙色 alpha 底之后更差。实测(见+ renderer/__tests__/xUsageGuideRiskContrast.test.ts, 有用例钉着):++ 合成底 text-secondary text-primary+ default light 3.96 12.64+ default dark 4.38 7.46+ CINDY light 2.71 8.77+ CINDY dark 2.09 7.09++ 四种组合下 secondary 全部低于 4.5, primary 全部 ≥7。修法是在组件内换语义色 ——+ **不能去改全局 token**: §15.5 写明 text-secondary 的值「never darken+ unilaterally」, 要改需要新的用户裁决(#1347 review 由 codex 指出 P2)。 */}+ <GuideGroup label={t(k('riskLabel'))}>+ <div className="flex gap-2 rounded-lg bg-[var(--warning-bg-soft)] px-3 py-2.5">+ <AlertTriangle size={15} className="mt-0.5 shrink-0 text-[var(--warning-fg)]" />+ <div className="flex flex-col gap-1.5">+ <span className="text-12 leading-[1.45] text-[var(--text-primary)]">+ {t(k('riskPublicBody'))}+ </span>+ <span className="text-12 leading-[1.45] text-[var(--text-primary)]">+ {t(k('riskWorkdirBody'))}+ </span>+ </div>+ </div>+ </GuideGroup>++ <GuideGroup label={t(k('withdrawLabel'))}>+ <GuideBody>{t(k('withdrawBody'))}</GuideBody>+ </GuideGroup>+ </div>+ );+}diff --git a/apps/desktop/src/renderer/components/settings/__tests__/HookConnectionsSection.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/HookConnectionsSection.test.tsxindex cd5528e526..ad716b9538 100644--- a/apps/desktop/src/renderer/components/settings/__tests__/HookConnectionsSection.test.tsx+++ b/apps/desktop/src/renderer/components/settings/__tests__/HookConnectionsSection.test.tsx@@ -96,6 +96,7 @@ vi.mock('../TelegramBehaviorSettings', () => ({}));import { deriveAlias, HookConnectionsSection, workspaceRowsToMap } from '../HookConnectionsSection';+import { resetXUsageNoticeMemoryState } from '@/state/xUsageNotice';/** 渠道卡收起时内容卸载(Collapse), 交互前先点开对应卡的头部行。 */async function expandChannelCard(titleKey: RegExp) {@@ -138,9 +139,15 @@ const BASE_HOOK: SlackHookView = {},};-describe('HookConnectionsSection Telegram binding actions', () => {+// 原名 'HookConnectionsSection Telegram binding actions' —— 本 suite 现在同时覆盖+// Telegram 绑定动作与 X 的用法告知/确认门, 名字得跟上, 否则失败用例的定位会误导人。+describe('HookConnectionsSection binding actions (Telegram / X)', () => {beforeEach(() => {vi.clearAllMocks();+ // X 用法确认门按 principalId 记账在 localStorage 里, 而 jsdom 的 localStorage+ // 跨用例保留 —— 不清就会被前一条用例的记账吃掉, 后面的用例白绿。+ localStorage.clear();+ resetXUsageNoticeMemoryState();ipc.onStatusChanged.mockReturnValue(() => {});ipc.setEnabled.mockResolvedValue({ hook: BASE_HOOK });ipc.setLifecycleAnnouncement.mockResolvedValue({ hook: BASE_HOOK });@@ -345,6 +352,7 @@ describe('HookConnectionsSection Telegram binding actions', () => {it('hides the X card entirely while the endpoint manifest leaves xHookWsUrl empty', async () => {// BASE_HOOK 的 x.url 为空且未启用/不可用 —— 端点清单缺失即灰度关闭,// 设置页不得出现 X 入口(providerCardState.visible 语义)。+ // 这一条必须用空 url 的 BASE_HOOK 本体, 不能换成 xUnboundHook()。ipc.get.mockResolvedValue({ hook: BASE_HOOK });render(<HookConnectionsSection />);@@ -971,4 +979,226 @@ describe('HookConnectionsSection Telegram binding actions', () => {screen.queryByLabelText('settings.remoteControl.hook.form.defaultWorkspaceAria'),).toBeNull();});++ /**+ * 「服务端已开放端点、但用户还没打开开关」的 X 卡 —— 评估阶段的真实形态。+ *+ * 不能直接用 BASE_HOOK: 它的 x.url 是空串, 而空端点会让整张卡不渲染+ * (见上面「hides the X card entirely while the endpoint manifest leaves+ * xHookWsUrl empty」那条), 于是用法与风险小节根本没有宿主。+ */+ function xUnboundHook(): SlackHookView {+ return {+ ...BASE_HOOK,+ x: { ...BASE_HOOK.x, url: 'wss://x-hook.example.test' },+ };+ }++ /** confirmed 态的 X binding, 只有 principalId 不同(确认门按它记账)。 */+ function xConfirmedHook(principalId: string): SlackHookView {+ return {+ ...BASE_HOOK,+ x: {+ enabled: true,+ url: 'wss://x-hook.example.test',+ status: 'connected',+ lastError: null,+ available: true,+ capabilityPending: false,+ defaultWorkspace: null,+ binding: {+ provider: 'x',+ state: 'confirmed',+ attemptId: null,+ bindingId: `x-binding-${principalId}`,+ principalId,+ principalName: '@dash',+ scopeId: 'bot-x',+ scopeName: 'CindyBot',+ connectUrl: null,+ expiresAt: null,+ reason: null,+ remediationUrl: 'https://x.com/CindyBot',+ actions: ['open_provider', 'revoke'],+ },+ },+ };+ }++ it('用法与风险小节只出现在 X 卡: Telegram 是私密通道, 没有这条性质差异', async () => {+ // X 的回复是一条**公开推文**, Slack / Telegram 不是 —— 这一节的存在理由就是+ // 这个差异, 所以它不该跟着渲染进别的渠道卡。+ ipc.get.mockResolvedValue({ hook: xUnboundHook() });+ render(<HookConnectionsSection />);+ await expandChannelCard(X_CARD);+ expect(+ await screen.findByText('settings.remoteControl.hook.x.guide.riskPublicBody'),+ ).toBeTruthy();++ cleanup();+ ipc.get.mockResolvedValue({ hook: xUnboundHook() });+ render(<HookConnectionsSection />);+ await expandChannelCard(TELEGRAM_CARD);+ expect(+ screen.queryByText('settings.remoteControl.hook.x.guide.riskPublicBody'),+ ).toBeNull();+ });++ it('说明区可选可复制: 弹窗根节点带 select-none, 不覆盖就复制不了 @askmycindy', async () => {+ // 本组件也渲染进 ConfirmDialog, 而它的 Content 根节点带 select-none+ // (confirm-dialog.tsx)。DESIGN.md §14.1 的判据是「用户会不会想复制它」——+ // `@askmycindy` 与 `/delete` 是用户要**打进 X** 的字符串, 当然会+ // (#1347 review 由 codex 指出 P2)。+ ipc.get.mockResolvedValue({ hook: xUnboundHook() });+ render(<HookConnectionsSection />);+ await expandChannelCard(X_CARD);+ const body = await screen.findByText('settings.remoteControl.hook.x.guide.usageBody');+ // 三组共同的祖先就是 XUsageGuide 的根+ const root = body.closest('.select-text');+ expect(root, 'XUsageGuide 根节点必须带 select-text 覆盖弹窗的 select-none').not.toBeNull();+ expect(+ root?.textContent?.includes('settings.remoteControl.hook.x.guide.withdrawBody'),+ ).toBe(true);+ });++ it('说明区没有任何小于 12px 的字号: 这是逐句阅读的正文, 不是辅助标签', async () => {+ // DESIGN.md §3 把 Small(12px)定为 sans 的最小字号, 并对 Micro Label(10–13px)写明+ // 「Auxiliary / non-reading labels only … Never used for body text or anything the+ // user reads sentence-by-sentence」。这一节的正文既要逐句读、还要照着往 X 里打字+ // (@askmycindy / delete 命令), 是正文而非标签(#1347 review 由 codex 指出 P2)。+ //+ // 刻意钉整个子树而不是单个 className: 初版只有 GuideBody 一处踩线, 但下一处新增的+ // 说明同样会想「顺手用 text-11」—— 钉子树才拦得住第二次。+ ipc.get.mockResolvedValue({ hook: xUnboundHook() });+ render(<HookConnectionsSection />);+ await expandChannelCard(X_CARD);+ const root = (+ await screen.findByText('settings.remoteControl.hook.x.guide.usageBody')+ ).closest('.select-text');+ expect(root).not.toBeNull();++ const tooSmall: string[] = [];+ for (const el of [root!, ...Array.from(root!.querySelectorAll('*'))]) {+ for (const cls of Array.from(el.classList)) {+ // 本仓的字号既有 `text-11` 这种自定义档, 也有 `text-[11px]` 这种字面量+ const px = /^text-(\d+)$/.exec(cls)?.[1] ?? /^text-\[(\d+)px\]$/.exec(cls)?.[1];+ if (px !== undefined && Number(px) < 12) tooSmall.push(cls);+ }+ }+ expect(tooSmall, `说明区出现了小于 12px 的字号: ${tooSmall.join(', ')}`).toEqual([]);+ });++ it('三组都在场, 且「默认工作目录」那条风险必须写出来', async () => {+ // 「X 任务都落在默认工作目录、agent 能读写其中文件、结论会公开回帖」是+ // 「回帖公开」的直接后果, 也是用户判断该不该把默认目录指到工作仓库的唯一依据+ // (Dash 2026-08-02 明确要求写出来) —— 少了它这一节就等于没说清风险。+ ipc.get.mockResolvedValue({ hook: xUnboundHook() });+ render(<HookConnectionsSection />);+ await expandChannelCard(X_CARD);+ for (const key of [+ 'usageLabel',+ 'usageBody',+ 'riskLabel',+ 'riskPublicBody',+ 'riskWorkdirBody',+ 'withdrawLabel',+ 'withdrawBody',+ ]) {+ expect(+ await screen.findByText(`settings.remoteControl.hook.x.guide.${key}`),+ ).toBeTruthy();+ }+ });++ it('X 未启用、未绑定时小节照样显示: 评估阶段最需要看到风险', async () => {+ // BASE_HOOK 的 x 是 enabled:false / available:false / binding:null。工作目录区+ // 按 view.enabled 门控, 这一节刻意不跟 —— 决定要不要打开的人才最需要读它。+ ipc.get.mockResolvedValue({ hook: xUnboundHook() });+ render(<HookConnectionsSection />);+ await expandChannelCard(X_CARD);+ expect(+ await screen.findByText('settings.remoteControl.hook.x.guide.riskWorkdirBody'),+ ).toBeTruthy();+ // 同一张卡上工作目录区确实是收起的, 证明两者门控独立+ expect(+ screen.queryByLabelText('settings.remoteControl.hook.form.defaultWorkspaceAria'),+ ).toBeNull();+ });++ it('首次绑定成功弹一次确认门: 单按钮、不可用取消绕过', async () => {+ ipc.get.mockResolvedValue({ hook: xConfirmedHook('x-user-1') });+ render(<HookConnectionsSection />);++ await waitFor(() => expect(dialog.confirm).toHaveBeenCalledTimes(1));+ expect(dialog.confirm.mock.calls[0][0]).toMatchObject({+ title: 'settings.remoteControl.hook.x.guide.ackTitle',+ confirmText: 'settings.remoteControl.hook.x.guide.ackConfirm',+ // 告知不该有「取消」这个出口 —— 它不是一个可选操作+ showCancel: false,+ });+ });++ it('点过「我明白」之后不再弹: 一次性告知, 不是每次开设置都拦', async () => {+ ipc.get.mockResolvedValue({ hook: xConfirmedHook('x-user-1') });+ render(<HookConnectionsSection />);+ await waitFor(() => expect(dialog.confirm).toHaveBeenCalledTimes(1));++ cleanup();+ dialog.confirm.mockClear();+ ipc.get.mockResolvedValue({ hook: xConfirmedHook('x-user-1') });+ render(<HookConnectionsSection />);+ await expandChannelCard(X_CARD);+ // 给 effect 一个真实的机会跑完再断言"没弹"+ await waitFor(() =>+ expect(screen.queryByText('settings.remoteControl.hook.x.guide.usageBody')).toBeTruthy(),+ );+ expect(dialog.confirm).not.toHaveBeenCalled();+ });++ it('换绑到另一个 X 账号会再确认一次: 新账号 = 新的公开面', async () => {+ ipc.get.mockResolvedValue({ hook: xConfirmedHook('x-user-1') });+ render(<HookConnectionsSection />);+ await waitFor(() => expect(dialog.confirm).toHaveBeenCalledTimes(1));++ cleanup();+ dialog.confirm.mockClear();+ ipc.get.mockResolvedValue({ hook: xConfirmedHook('x-user-2') });+ render(<HookConnectionsSection />);+ await waitFor(() => expect(dialog.confirm).toHaveBeenCalledTimes(1));+ });++ it('Esc / 点遮罩关掉不算已知晓: 下次仍然弹', async () => {+ // confirm-dialog 在 Esc / 遮罩点击时 resolve 成 cancel(ok=false)。那种情况下+ // 用户并没有读到告知, 记账就等于把风险悄悄咽掉了。+ dialog.confirm.mockResolvedValue(false);+ ipc.get.mockResolvedValue({ hook: xConfirmedHook('x-user-1') });+ render(<HookConnectionsSection />);+ await waitFor(() => expect(dialog.confirm).toHaveBeenCalledTimes(1));++ cleanup();+ dialog.confirm.mockClear();+ dialog.confirm.mockResolvedValue(true);+ ipc.get.mockResolvedValue({ hook: xConfirmedHook('x-user-1') });+ render(<HookConnectionsSection />);+ await waitFor(() => expect(dialog.confirm).toHaveBeenCalledTimes(1));+ });++ it('未绑定 / 绑定中不弹确认门: 只在转入 confirmed 那一沿', async () => {+ const pending = xConfirmedHook('x-user-1');+ ipc.get.mockResolvedValue({+ hook: {+ ...pending,+ x: {+ ...pending.x,+ binding: { ...pending.x.binding!, state: 'pending' as const },+ },+ },+ });+ render(<HookConnectionsSection />);+ await expandChannelCard(X_CARD);+ await waitFor(() =>+ expect(screen.queryByText('settings.remoteControl.hook.x.guide.usageBody')).toBeTruthy(),+ );+ expect(dialog.confirm).not.toHaveBeenCalled();+ });});diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex 0f9e48cbc0..47d7a8e844 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -2795,6 +2795,17 @@"description": "Link your X (Twitter) account and dispatch tasks by mentioning the Cindy bot on X.","disabledHint": "Turn on the switch, then follow the prompts to authorize your X account.","toggleAria": "Toggle X connection",+ "guide": {+ "usageLabel": "How to Use It",+ "usageBody": "Post on X mentioning @askmycindy and the task is dispatched to this device to run here; the result comes back as a reply.",+ "riskLabel": "Replies Are Public",+ "riskPublicBody": "Our reply is a public post that anyone can read. This suits questions and problems you are happy to work through in the open — not private matters, where it risks exposing them.",+ "riskWorkdirBody": "Every X task runs in the default working directory set in X connection settings. The Agent can read and write files there, and its conclusion is posted publicly — if that directory points at a private repository, file contents may become public with it.",+ "withdrawLabel": "To Withdraw a Reply",+ "withdrawBody": "Whoever asked can delete a reply by replying \"/delete\" to it. Only the public reply is deleted — the local task record is kept.",+ "ackTitle": "X Is Linked — How It Works and What to Watch For",+ "ackConfirm": "I Understand the Risks"+ },"connect": "Link X","openApp": "Open X to authorize","cancel": "Cancel linking",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex c1b47e68f8..372107f674 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -2794,6 +2794,17 @@"description": "X (Twitter) アカウントを連携し、X で Cindy bot にメンションしてタスクを依頼できます。","disabledHint": "スイッチをオンにして、案内に従って X アカウントを認証してください。","toggleAria": "X 接続を切り替え",+ "guide": {+ "usageLabel": "使い方",+ "usageBody": "X で @askmycindy をメンションしてポストすると、タスクがこの端末に届いてここで実行され、結果が返信として戻ります。",+ "riskLabel": "返信は公開されます",+ "riskPublicBody": "Cindy の返信は公開ポストで、誰でも閲覧できます。公開の場で答えを探したり問題を解決するのに向いていますが、プライベートな用件には向きません —— プライバシーが露出するおそれがあります。",+ "riskWorkdirBody": "X のタスクはすべて X 連携設定で指定した既定の作業ディレクトリで実行されます。Agent はその中のファイルを読み書きでき、結論は公開で返信されます —— 非公開リポジトリを指している場合、ファイルの内容も公開される可能性があります。",+ "withdrawLabel": "返信を取り消す",+ "withdrawBody": "質問した本人がその返信に「/delete」と返信すると削除できます。公開された返信だけが削除され、ローカルのタスク記録は残ります。",+ "ackTitle": "X を連携しました —— 使い方と注意点",+ "ackConfirm": "リスクを理解しました"+ },"connect": "X を連携","openApp": "X を開いて認証","cancel": "連携をキャンセル",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex c84b58f908..961dfe8236 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -2794,6 +2794,17 @@"description": "X (Twitter) 계정을 연결하고 X에서 Cindy bot을 멘션해 작업을 요청하세요.","disabledHint": "스위치를 켠 뒤 안내에 따라 X 계정 인증을 완료하세요.","toggleAria": "X 연결 전환",+ "guide": {+ "usageLabel": "사용 방법",+ "usageBody": "X에서 @askmycindy를 멘션해 게시글을 쓰면 작업이 이 기기로 전달되어 여기서 실행되고, 결과가 답장으로 돌아옵니다.",+ "riskLabel": "답장은 공개됩니다",+ "riskPublicBody": "Cindy의 답장은 공개 게시글이므로 누구나 볼 수 있습니다. 공개적으로 답을 찾거나 문제를 해결하는 데 적합하며, 사적인 일에는 적합하지 않습니다 —— 프라이버시가 노출될 위험이 있습니다.",+ "riskWorkdirBody": "모든 X 작업은 X 연결 설정에서 지정한 기본 작업 디렉터리에서 실행됩니다. Agent는 그 안의 파일을 읽고 쓸 수 있으며, 결론은 공개로 답장됩니다 —— 해당 디렉터리가 비공개 리포지터리를 가리키면 파일 내용도 함께 공개될 수 있습니다.",+ "withdrawLabel": "답장 철회하기",+ "withdrawBody": "질문한 본인이 그 답장에 \"/delete\"라고 답장하면 삭제됩니다. 공개 답장만 삭제되며 로컬 작업 기록은 그대로 남습니다.",+ "ackTitle": "X가 연결되었습니다 —— 사용법과 주의사항",+ "ackConfirm": "위험을 이해했습니다"+ },"connect": "X 연결","openApp": "X 열어 인증하기","cancel": "연결 취소",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex c2d0993d92..1f8e96759f 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -2794,6 +2794,17 @@"description": "关联 X (Twitter) 账号,在 X 上 @提及 Cindy bot 即可派发任务。","disabledHint": "打开开关后,按提示完成 X 账号授权。","toggleAria": "切换 X 连接",+ "guide": {+ "usageLabel": "怎么用",+ "usageBody": "在 X 上发一条推文 @askmycindy,任务就会派到这台设备上执行,结论以回帖发回给你。",+ "riskLabel": "回帖是公开的",+ "riskPublicBody": "我们的回复是一条公开推文,任何人都能看到。这个功能适合公开地找答案、解决问题,不适合处理私事 —— 那会有隐私暴露的风险。",+ "riskWorkdirBody": "X 任务都落在 X 连接设置里的默认工作目录,Agent 能读写其中文件,而结论会公开回帖 —— 默认目录指到私密仓库时,文件内容可能随之公开。",+ "withdrawLabel": "想撤回",+ "withdrawBody": "提问者对着那条回答回复「/delete」(或「/删除」)就能删掉它。只删公开那条,本地任务记录照旧保留。",+ "ackTitle": "X 已关联,先看一下用法与风险",+ "ackConfirm": "我已了解风险"+ },"connect": "关联 X","openApp": "打开 X 完成授权","cancel": "取消关联",diff --git a/apps/desktop/src/renderer/state/xUsageNotice.ts b/apps/desktop/src/renderer/state/xUsageNotice.tsnew file mode 100644index 0000000000..20defa0a4e--- /dev/null+++ b/apps/desktop/src/renderer/state/xUsageNotice.ts@@ -0,0 +1,70 @@+/**+ * xUsageNotice —— X 连接的「用法与公开风险」确认门的已知晓状态,localStorage 持久化,+ * 按**绑定的 X 账号**(principalId)分别记账。+ *+ * 为什么需要它:X 的回复是一条公开推文,而且所有 X 任务都落在用户设的默认工作目录里 ——+ * 这两条后果只写在设置卡的常驻小节里是不够的,很多人不会主动展开设置去读。所以绑定成功+ * 的那一刻要拦一次,让用户明确点过「我明白」。而这种告知只该拦一次,不能每次开设置都弹。+ *+ * 按 principalId 而不是按设备记账:换绑到另一个 X 账号 = 换了一个公开面(不同的粉丝、+ * 不同的可见范围),值得再确认一次;同一个账号解绑后重新绑定则不重复打扰。+ *+ * 与 providerOnboardingDismissal 刻意分开(同 inheritedSubscriptionNotice 的理由):+ * 那条是「零来源 → 去连接」的引导,可以在再次归零时重新出现;这条是**一次性告知**,+ * 确认过就不再打扰,不随连接状态回弹。+ *+ * 形状取自 inheritedSubscriptionNotice(同一类状态,那几个坑已经踩过),但**没有做+ * 订阅**:确认门只在绑定态转入 confirmed 的那一沿读一次,没有任何组件需要跟随本状态+ * 重渲染 —— 加一份 useSyncExternalStore 只会多一条没人用的通路。+ */++const STORAGE_KEY = 'xUsageNotice.acknowledgedPrincipals';++/** localStorage 不可用(隐私模式/配额)时的进程内兜底:至少本次会话内别重复弹。 */+let memoryAcknowledged = new Set<string>();++function readStored(): string[] {+ try {+ const raw = localStorage.getItem(STORAGE_KEY);+ if (!raw) return [];+ const parsed: unknown = JSON.parse(raw);+ // 坏数据(手改 / 旧 schema)按「没确认过」处理 —— 宁可多弹一次告知,+ // 也绝不因此抛错让整个设置页白屏。+ return Array.isArray(parsed) ? parsed.filter((v): v is string => typeof v === 'string') : [];+ } catch {+ return [];+ }+}++/** 这个 X 账号是否已经确认过告知。 */+export function isXUsageAcknowledged(principalId: string): boolean {+ if (principalId.length === 0) return false;+ return readStored().includes(principalId) || memoryAcknowledged.has(principalId);+}++/** 标记这个 X 账号的告知为已确认(一次性,不再出现)。 */+export function acknowledgeXUsage(principalId: string): void {+ if (principalId.length === 0) return;+ // **必须把 memoryAcknowledged 一起并进来**: localStorage 持续不可写时(隐私模式 /+ // 配额, 本模块明确支持的场景)readStored() 恒为空, 只并 readStored 的话第二个账号+ // 会把第一个从内存兜底里覆盖掉 —— 用户切回第一个账号时又被拦一次, 而那次确认本该+ // 在本会话内一直有效(#1347 review 由 codex 指出)。读侧本来就是两者取并集+ // (isXUsageAcknowledged), 写侧漏了同一个并集才出的错。+ //+ // 顺带一层收益: storage 从坏转好时, 第一次写成功会把内存里攒下的账号一并落盘。+ const next = new Set([...readStored(), ...memoryAcknowledged, principalId]);+ try {+ localStorage.setItem(STORAGE_KEY, JSON.stringify([...next]));+ // 写成功则 storage 是唯一真值源,不置内存态 —— 否则跨窗口清 key 后本窗口会+ // 因内存态永远判定已确认(inheritedSubscriptionNotice / providerOnboardingDismissal+ // 的既有教训)。此时 storage 已含内存那批, 清空不丢东西。+ memoryAcknowledged = new Set();+ } catch {+ memoryAcknowledged = next;+ }+}++/** 测试用:清空本模块的进程内兜底状态。 */+export function resetXUsageNoticeMemoryState(): void {+ memoryAcknowledged = new Set();+}diff --git a/i18n/GLOSSARY.md b/i18n/GLOSSARY.mdindex 9260c2a6e1..0d87171039 100644--- a/i18n/GLOSSARY.md+++ b/i18n/GLOSSARY.md@@ -151,6 +151,10 @@ Anthropic Messages API / wire protocol 的用户可见名称。四语统一保企业认证与业务服务所在区域的用户可见名称,用于组织登录检测到中国大陆服务区域时的确认文案;它描述连接的服务区域,不代表当前安装的是中国大陆版。先按现有四语文案登记为 proposed,避免后续出现“中国区/国内区/China region”等多套说法。+### reply (the bot's public post on X)++Cindy 在 X 上发出的那条公开回复。zh-CN 取「回帖」以强调它是**一条公开帖子**而不是私聊消息——这正是 X 与 Slack / Telegram 的性质差异, 也是风险告知的核心。与「消息」区分开: 后者按 task-and-conversation-naming 只用于任务内的单条往来。proposed 同上。+### Cindy Codex home远端主机上由 Cindy 管理的 Codex 凭证目录(~/.xdt-server/v1/codex-home/),与用户本机 ~/.codex 相区分。四语统一保留英文原词(home 小写),避免各语言自造「Codex 主目录」等不同说法;syncAuth 与 codexAuthMissing 等远端登录态文案使用。@@ -273,6 +277,10 @@ macOS TCC 的 kTCCServiceListenEvent(系统设置里叫「输入监控」)在 Ci企业微信 WebSocket 长连接双向 IM 能力在设置页中的名称;先登记为 proposed。+### withdraw (a reply)++用户在 X 上让 Cindy 删掉它那条公开回帖的动作(在回帖下回 /delete)。zh-CN 取「撤回」而不是「删除」——「删除」在本仓已大量用于删任务/删会话/删文件, 而这个动作的对象是「已经发出去的公开内容」, 与 IM 里的消息撤回同义。刻意登记为 proposed: X 撤回是新功能(server PR #288 / client 侧告知), 四语只有这一处用例, 等更多用例出现后再定 decided。+## 怎么加一条术语1. 在 `i18n/glossary.json` 的 `terms` 里加条目,`note` 必填——写清楚**为什么**这么定,diff --git a/i18n/glossary.json b/i18n/glossary.jsonindex a38d4dfc53..d8d9882834 100644--- a/i18n/glossary.json+++ b/i18n/glossary.json@@ -1256,6 +1256,28 @@},"checkCase": false,"note": "一次提问到一次回答结束。**内部概念,不作为界面术语**:面向用户一律说「消息」,只在确实要强调一次完整往返时说「一轮」(如「上一轮」)。不要引入「轮次」作为界面用词。"+ },+ {+ "id": "withdraw-reply",+ "status": "proposed",+ "en": "withdraw (a reply)",+ "translations": {+ "zh-CN": "撤回",+ "ja": "取り消す",+ "ko": "철회"+ },+ "note": "用户在 X 上让 Cindy 删掉它那条公开回帖的动作(在回帖下回 /delete)。zh-CN 取「撤回」而不是「删除」——「删除」在本仓已大量用于删任务/删会话/删文件, 而这个动作的对象是「已经发出去的公开内容」, 与 IM 里的消息撤回同义。刻意登记为 proposed: X 撤回是新功能(server PR #288 / client 侧告知), 四语只有这一处用例, 等更多用例出现后再定 decided。"+ },+ {+ "id": "bot-reply-post",+ "status": "proposed",+ "en": "reply (the bot's public post on X)",+ "translations": {+ "zh-CN": "回帖",+ "ja": "返信",+ "ko": "답장"+ },+ "note": "Cindy 在 X 上发出的那条公开回复。zh-CN 取「回帖」以强调它是**一条公开帖子**而不是私聊消息——这正是 X 与 Slack / Telegram 的性质差异, 也是风险告知的核心。与「消息」区分开: 后者按 task-and-conversation-naming 只用于任务内的单条往来。proposed 同上。"}]}\ No newline at end of file