Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 侧栏版本行不再给 Global 构建贴区域标签 (#872)
Dash436cf864a40f
diff --git a/apps/desktop/src/main/github-issue/githubIssueSubmitService.ts b/apps/desktop/src/main/github-issue/githubIssueSubmitService.tsindex bbcee2fffc..59a1d8a031 100644--- a/apps/desktop/src/main/github-issue/githubIssueSubmitService.ts+++ b/apps/desktop/src/main/github-issue/githubIssueSubmitService.ts@@ -12,7 +12,7 @@import type { CindyRegion } from '@cindy/maker-shared/brand-identity';-import { ISSUE_REGION_CODE } from '../../shared/issueRegionCode.js';+import { CINDY_REGION_CODE } from '../../shared/regionCode.js';import { normalizeIssuePublicName } from '../../shared/issuePublicName.js';import type {IssueConfirmDecision,@@ -154,11 +154,11 @@ export async function submitGithubIssueWithConfirm(decision.type !== req.type;const uiLanguage = decision.uiLanguage ?? deps.getFallbackLocale();- const regionCode = ISSUE_REGION_CODE[env.region];+ const regionCode = CINDY_REGION_CODE[env.region];const envBlock = ['','---',- // global 不写这一行 —— 缺失即默认区域,理由见 ISSUE_REGION_CODE(与确认卡片同源)。+ // global 不写这一行 —— 缺失即默认区域,理由见 CINDY_REGION_CODE(与确认卡片同源)。...(regionCode ? [`**版本区域**: ${regionCode}`] : []),`**OS**: ${env.platform} ${env.arch} (${env.osVersion})`,`**界面语言**: ${uiLanguage}`,diff --git a/apps/desktop/src/renderer/__tests__/issueRegionCode.consistency.test.ts b/apps/desktop/src/renderer/__tests__/issueRegionCode.consistency.test.tsdeleted file mode 100644index c78a99fc05..0000000000--- a/apps/desktop/src/renderer/__tests__/issueRegionCode.consistency.test.ts+++ /dev/null@@ -1,67 +0,0 @@-/**- * issue 区域代号的跨侧一致性 —— 确认卡片(走 i18n)与 issue 正文(走- * ISSUE_REGION_CODE 常量)必须对同一个区域给出同一个代号。- *- * 为什么需要专门一测:确认卡片的契约是「展示的就是最终写进 issue 的内容」,但两侧- * 走的是不同机制(卡片按 DESIGN.md §16.3 要求走 i18n,便于日后改判为可译文案;正文- * 直接落常量,因为读者是维护者、不跟随界面语言)。机制不同就没有编译期约束——改了- * 一边的取值、或新增区域只补了一边,typecheck 与各自的单测都不会响,用户确认时看到- * 的区域却与实际提交的正文不一致。这一测就是补上那道缺失的信号。- */--import { describe, expect, it } from 'vitest';--import { ISSUE_REGION_CODE, shouldLabelIssueRegion } from '../../shared/issueRegionCode';-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 LOCALES: Record<string, { issueAgent: { confirm: Record<string, unknown> } }> = {- 'zh-CN': zhCN,- en,- ja,- ko,-};--/** region → 卡片 i18n key 后缀(cn → regionCodeCn)。 */-function confirmKeyFor(region: string): string {- return `regionCode${region.charAt(0).toUpperCase()}${region.slice(1)}`;-}--describe('issue 区域代号:卡片 i18n 与 issue 正文常量一致', () => {- it('有代号的区域: 四语 i18n 值逐字等于常量,且不被翻译', () => {- const labeled = Object.entries(ISSUE_REGION_CODE).filter(([, code]) => code !== null);- // 防塌陷:常量被清空时下面的循环会变成空跑而全绿。- expect(labeled.length).toBeGreaterThan(0);- for (const [region, code] of labeled) {- for (const [locale, bundle] of Object.entries(LOCALES)) {- expect(- bundle.issueAgent.confirm[confirmKeyFor(region)],- `${locale} 的 issueAgent.confirm.${confirmKeyFor(region)} 应为 ${code}(区域代号四语同文、不翻译)`,- ).toBe(code);- }- }- });-- it('不标注的区域: 四语都不得存在对应 key,避免出现「能显示但正文不写」的半套实现', () => {- const unlabeled = Object.entries(ISSUE_REGION_CODE).filter(([, code]) => code === null);- expect(unlabeled.length).toBeGreaterThan(0);- for (const [region] of unlabeled) {- for (const [locale, bundle] of Object.entries(LOCALES)) {- expect(- bundle.issueAgent.confirm[confirmKeyFor(region)],- `${locale} 不应有 issueAgent.confirm.${confirmKeyFor(region)}——${region} 按产品规则不标注(DESIGN.md §16.3)`,- ).toBeUndefined();- }- }- });-- it('global 不标是硬规则(DESIGN.md §16.3 不得回退),缺失 region 同样不标', () => {- expect(ISSUE_REGION_CODE.global).toBeNull();- expect(shouldLabelIssueRegion('global')).toBe(false);- expect(shouldLabelIssueRegion(undefined)).toBe(false);- expect(shouldLabelIssueRegion('cn')).toBe(true);- expect(shouldLabelIssueRegion('dev')).toBe(true);- });-});diff --git a/apps/desktop/src/renderer/__tests__/regionCode.consistency.test.ts b/apps/desktop/src/renderer/__tests__/regionCode.consistency.test.tsnew file mode 100644index 0000000000..63d3f2381e--- /dev/null+++ b/apps/desktop/src/renderer/__tests__/regionCode.consistency.test.ts@@ -0,0 +1,207 @@+/**+ * 区域代号的跨机制一致性 —— 界面展示(走 i18n)与常量(走 CINDY_REGION_CODE)必须+ * 对同一个区域给出同一个代号,且各条消费链路之间不得互相漂移。+ *+ * 为什么需要专门一测:界面文案与常量走的是不同机制(界面按 DESIGN.md §16.3 要求走+ * i18n,便于日后改判为可译文案;issue 正文直接落常量,因为读者是维护者、不跟随界面+ * 语言)。机制不同就没有编译期约束——改了一边的取值、或新增区域 / 新增消费链路只补了+ * 一边,typecheck 与各自的单测都不会响。issue 链路还额外有「卡片展示的就是最终写进+ * issue 正文的内容」这条契约,漂移会直接骗到用户;侧栏版本行与登录页徽标则会让同一个+ * 构建在不同界面报出不同的区域身份。这一测就是补上那道缺失的信号。+ *+ * 当前覆盖三条消费链路:issue 提交确认卡片、侧栏用户卡片版本行、登录页标题旁区域+ * 徽标。**新增消费链路时把它的 i18n 命名空间加进 CONSUMERS 即可**,不要另写一份平行+ * 断言——漏进表就等于那条链路不受约束(2026-07-29 review 即因此漏掉登录页徽标)。+ */++import { describe, expect, it } from 'vitest';++import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';++import type { CindyRegion } from '@cindy/maker-shared/brand-identity';++import { CINDY_REGION_CODE, shouldLabelRegion } from '../../shared/regionCode';+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';++type Bundle = Record<string, unknown>;++const LOCALES: Record<string, Bundle> = {+ 'zh-CN': zhCN as Bundle,+ en: en as Bundle,+ ja: ja as Bundle,+ ko: ko as Bundle,+};++/** region → 多数链路的 i18n key 后缀(cn → regionCodeCn)。 */+function regionCodeKeyFor(region: string): string {+ return `regionCode${region.charAt(0).toUpperCase()}${region.slice(1)}`;+}++/**+ * 消费区域代号的各条链路:i18n key 所在对象 + 该链路的 key 命名。+ *+ * 登录页徽标的 key 命名与另两条不同(`login.regionPill.cn` 而非 `regionCodeCn`),+ * 所以 keyFor 可按链路覆盖。+ *+ * ⚠️ 本表只覆盖 **i18n bundle 侧**:某个区域在四语包里有没有 key、取值对不对。+ * 「组件里有没有真的引用到那个 key」是另一回事,由下面的 SOURCE_CONSUMERS 用源码+ * 字面量扫描覆盖(各组件都把 key 写成字面量分支而非动态拼接,为的是 `pnpm check:i18n`+ * 的静态提取能看到——正好也让这种扫描可行)。两者缺一都留口子:只有 bundle 就防不住+ * 组件漏引用,只有源码扫描就防不住 bundle 缺 key 或取值被译走。+ */+const CONSUMERS: ReadonlyArray<{+ label: string;+ prefix: string;+ pick: (b: Bundle) => Bundle;+ keyFor?: (region: string) => string;+}> = [+ {+ label: 'issue 提交确认卡片',+ prefix: 'issueAgent.confirm',+ pick: (b) => (b.issueAgent as { confirm: Bundle }).confirm,+ },+ {+ label: '侧栏用户卡片版本行',+ prefix: 'sidebar.user',+ pick: (b) => (b.sidebar as { user: Bundle }).user,+ },+ {+ label: '登录页标题旁区域徽标',+ prefix: 'login.regionPill',+ pick: (b) => (b.login as { regionPill: Bundle }).regionPill,+ keyFor: (region) => region,+ },+];++/** 取某条链路上该区域的 i18n key 名。 */+function keyOf(consumer: (typeof CONSUMERS)[number], region: string): string {+ return (consumer.keyFor ?? regionCodeKeyFor)(region);+}++/**+ * 各消费点组件源码 + 它引用 i18n key 的完整路径写法。+ *+ * 为什么要扫源码:三条链路的「哪个区域用哪个 key」都由组件自己维护(LoginPage 的+ * REGION_PILL_KEY 映射表、侧栏与 issue 卡片的三元字面量分支)。新增区域时只补了+ * CINDY_REGION_CODE 与四语 bundle、忘了补组件分支,上面的 bundle 断言照样全绿,而+ * 该区域在界面上拿不到文案 —— 这一组断言补的就是那道信号。+ */+const SOURCE_CONSUMERS: ReadonlyArray<{+ label: string;+ file: string;+ keyPathFor: (region: string) => string;+}> = [+ {+ label: '登录页标题旁区域徽标',+ file: 'components/login/LoginPage.tsx',+ keyPathFor: (region) => `login.regionPill.${region}`,+ },+ {+ label: '侧栏用户卡片版本行',+ file: 'components/sidebar/UserInfoSection.tsx',+ keyPathFor: (region) => `sidebar.user.${regionCodeKeyFor(region)}`,+ },+ {+ label: 'issue 提交确认卡片',+ file: 'features/cc-agent/IssueConfirmCard.tsx',+ keyPathFor: (region) => `issueAgent.confirm.${regionCodeKeyFor(region)}`,+ },+];++function readConsumerSource(file: string): string {+ return readFileSync(resolve(__dirname, '..', file), 'utf8');+}++describe('区域代号:界面 i18n 与常量一致', () => {+ it('有代号的区域: 每条链路的四语 i18n 值逐字等于常量,且不被翻译', () => {+ const labeled = Object.entries(CINDY_REGION_CODE).filter(([, code]) => code !== null);+ // 防塌陷:常量或消费链路被清空时下面的循环会变成空跑而全绿。+ expect(labeled.length).toBeGreaterThan(0);+ expect(CONSUMERS.length).toBeGreaterThan(0);+ for (const [region, code] of labeled) {+ for (const consumer of CONSUMERS) {+ for (const [locale, bundle] of Object.entries(LOCALES)) {+ const key = keyOf(consumer, region);+ expect(+ consumer.pick(bundle)[key],+ `${locale} 的 ${consumer.prefix}.${key}(${consumer.label})应为 ${code}(区域代号四语同文、不翻译)`,+ ).toBe(code);+ }+ }+ }+ });++ it('不标注的区域: 各链路四语都不得存在对应 key,避免出现「能显示但契约不写」的半套实现', () => {+ const unlabeled = Object.entries(CINDY_REGION_CODE).filter(([, code]) => code === null);+ expect(unlabeled.length).toBeGreaterThan(0);+ for (const [region] of unlabeled) {+ for (const consumer of CONSUMERS) {+ for (const [locale, bundle] of Object.entries(LOCALES)) {+ const key = keyOf(consumer, region);+ expect(+ consumer.pick(bundle)[key],+ `${locale} 不应有 ${consumer.prefix}.${key}——${region} 按产品规则不标注(DESIGN.md §16.3)`,+ ).toBeUndefined();+ }+ }+ }+ });++ it('global 不标是硬规则(DESIGN.md §16.3 不得回退),缺失 region 同样不标', () => {+ expect(CINDY_REGION_CODE.global).toBeNull();+ expect(shouldLabelRegion('global')).toBe(false);+ expect(shouldLabelRegion(undefined)).toBe(false);+ expect(shouldLabelRegion('cn')).toBe(true);+ expect(shouldLabelRegion('dev')).toBe(true);+ });++ it('每个消费点组件都真的引用了各自的 key —— 只补 bundle 不补组件分支要能被发现', () => {+ const labeled = Object.keys(CINDY_REGION_CODE).filter(+ (region) => CINDY_REGION_CODE[region as CindyRegion] !== null,+ );+ expect(labeled.length).toBeGreaterThan(0);+ expect(SOURCE_CONSUMERS.length).toBeGreaterThan(0);+ for (const consumer of SOURCE_CONSUMERS) {+ const source = readConsumerSource(consumer.file);+ for (const region of labeled) {+ const keyPath = consumer.keyPathFor(region);+ expect(+ source.includes(`'${keyPath}'`),+ `${consumer.file}(${consumer.label})应引用 '${keyPath}'——${region} 有代号却没在组件里落地,界面会拿不到文案`,+ ).toBe(true);+ }+ }+ });++ it('不标注的区域不得在任何消费点组件里出现 key 引用', () => {+ const unlabeled = Object.keys(CINDY_REGION_CODE).filter(+ (region) => CINDY_REGION_CODE[region as CindyRegion] === null,+ );+ expect(unlabeled.length).toBeGreaterThan(0);+ for (const consumer of SOURCE_CONSUMERS) {+ const source = readConsumerSource(consumer.file);+ for (const region of unlabeled) {+ const keyPath = consumer.keyPathFor(region);+ expect(+ source.includes(`'${keyPath}'`),+ `${consumer.file}(${consumer.label})不应引用 '${keyPath}'——${region} 按产品规则不标注(DESIGN.md §16.3)`,+ ).toBe(false);+ }+ }+ });++ it('未知 region 按不标处理 —— 表里取不到值时不得落进「有代号」分支', () => {+ // issue 链路的 region 来自 IPC payload,运行期不受 CindyRegion 类型保证。+ // 旧实现用 `!== null` 判定,undefined !== null 成立 → 未知区域被误判为要标注。+ for (const bogus of ['xx', 'GLOBAL', 'Cn', '', 'production']) {+ expect(+ shouldLabelRegion(bogus as CindyRegion),+ `未知 region ${JSON.stringify(bogus)} 必须 fail-closed 到不标注`,+ ).toBe(false);+ }+ });+});diff --git a/apps/desktop/src/renderer/__tests__/userInfoSectionHover.test.ts b/apps/desktop/src/renderer/__tests__/userInfoSectionHover.test.tsindex fc97fcd578..fda5c5f909 100644--- a/apps/desktop/src/renderer/__tests__/userInfoSectionHover.test.ts+++ b/apps/desktop/src/renderer/__tests__/userInfoSectionHover.test.ts@@ -58,12 +58,24 @@ describe('UserInfoSection — outer wrapper takes over full-row hover', () => {});describe('UserInfoSection — version label', () => {- it('shows the build region alongside the app version', () => {+ it('labels only the non-global builds alongside the app version', () => {expect(source).toContain("import { CURRENT_CINDY_REGION } from '../../../shared/brandRegion';");- expect(source).toContain(- "const appRegionLabel = CURRENT_CINDY_REGION === 'global' ? 'Global' : 'CN';",+ // 「哪些区域要标」必须来自 shared 单点,不得在组件里再写一份映射+ // (issue 反馈链路同源;口径见 DESIGN.md §16.3 / region-and-editions §2.3)。+ expect(source).toContain("import { shouldLabelRegion } from '../../../shared/regionCode';");+ expect(source).not.toMatch(/const REGION_LABEL/);+ // global 故意不贴标签,落到 null 分支只显示版本号。+ expect(source).toMatch(+ /const appRegionLabel = !shouldLabelRegion\(CURRENT_CINDY_REGION\)\s*\n\s*\? null\s*\n\s*: CURRENT_CINDY_REGION === 'cn'/,+ );+ // 展示文案走 i18n,且 key 为字面量分支(check:i18n 静态提取要看得到)。+ expect(source).toContain("t('sidebar.user.regionCodeCn')");+ expect(source).toContain("t('sidebar.user.regionCodeDev')");+ expect(source).not.toContain("'Global'");+ expect(source).not.toMatch(/'CN'|'Dev'/);+ expect(source).toMatch(+ /const appVersionLabel = appRegionLabel\s*\n\s*\? `\$\{appRegionLabel\} · \$\{appDisplayVersion\}`\s*\n\s*: appDisplayVersion;/,);- expect(source).toContain('const appVersionLabel = `${appRegionLabel} · ${appDisplayVersion}`;');expect(source).not.toContain('XD.Inc');expect(source).toContain('{appVersionLabel}');expect(source).toContain('title={appVersionLabelDetail}');diff --git a/apps/desktop/src/renderer/components/login/LoginPage.tsx b/apps/desktop/src/renderer/components/login/LoginPage.tsxindex 17f39f95d7..eb34f18b30 100644--- a/apps/desktop/src/renderer/components/login/LoginPage.tsx+++ b/apps/desktop/src/renderer/components/login/LoginPage.tsx@@ -46,6 +46,7 @@ import {} from './LoginControls';import { useResendCountdown } from './useResendCountdown';import { CURRENT_CINDY_REGION } from '../../../shared/brandRegion';+import { shouldLabelRegion } from '../../../shared/regionCode';import { LEGAL_LINKS } from '../../../shared/legalLinks';import { resolveIdentifierMethod } from '../../../shared/loginIdentifierMethod';import {@@ -74,6 +75,13 @@ import { canResumePendingConsent, makeConsentStamp, type ConsentStamp } from './** 值为四语同文的区域代号(与旧 login.globalRegion 一致:区域标识不翻译),仍走* i18n 以便日后改判为「中国大陆版」这类可译文案时不必回改组件。+ *+ * ⚠️ 本表只负责「哪个区域用哪个 i18n key」。**「标不标」不由本表决定**——那是+ * `shared/regionCode.ts` 的 `CINDY_REGION_CODE` 一处说了算(issue 反馈链路、侧栏+ * 版本行同源),消费处统一过 `shouldLabelRegion()`。否则改了 shared 映射、登录页+ * 这张表没跟上,徽标就会与其它界面报出不同的区域身份而没有任何信号。两者的对齐+ * (有代号的区域必须有 key、不标的区域不得有 key)由+ * `renderer/__tests__/regionCode.consistency.test.ts` 断言。*/const REGION_PILL_KEY: Partial<Record<typeof CURRENT_CINDY_REGION, string>> = {cn: 'login.regionPill.cn',@@ -248,7 +256,11 @@ export function LoginPage() {const isGlobalBuild = import.meta.env.VITE_CINDY_AUTH_REGION === 'global';// 徽标读 CURRENT_CINDY_REGION 而非上面的 env 字面比较:未注入区域的本地 dev// 构建经 resolveCindyRegion 落到默认 global,正确地不挂徽标(而非误挂 Dev)。- const regionPillKey = REGION_PILL_KEY[CURRENT_CINDY_REGION];+ // 「标不标」过 shouldLabelRegion(shared 单点,与侧栏 / issue 链路同源),本组件的+ // REGION_PILL_KEY 只回答「用哪个 key」——两层分开,shared 映射改了这里不会静默漂移。+ const regionPillKey = shouldLabelRegion(CURRENT_CINDY_REGION)+ ? REGION_PILL_KEY[CURRENT_CINDY_REGION]+ : undefined;// identifier 形态 = 构建区域确定性推导(用户拍板 2026-07-21:手机/邮箱分区互斥,// 双 tab 切换移除);providers 仅兜底区域首选方式未下发的场景。const identifierKind: VerificationKind = useMemo(diff --git a/apps/desktop/src/renderer/components/sidebar/UserInfoSection.tsx b/apps/desktop/src/renderer/components/sidebar/UserInfoSection.tsxindex 636b35f245..75438cd1c7 100644--- a/apps/desktop/src/renderer/components/sidebar/UserInfoSection.tsx+++ b/apps/desktop/src/renderer/components/sidebar/UserInfoSection.tsx@@ -8,6 +8,7 @@ import { useAuth } from '@/contexts/AuthContext';import { useUpdateStatus } from '@/hooks/useUpdateStatus';import { useUpdateBannerDismiss } from '@/hooks/useUpdateBannerDismiss';import { CURRENT_CINDY_REGION } from '../../../shared/brandRegion';+import { shouldLabelRegion } from '../../../shared/regionCode';import { MobileDownloadDialog } from './MobileDownloadDialog';interface UserInfoSectionProps {@@ -47,9 +48,24 @@ export function UserInfoSection({ isCollapsed, onOpenUpdateNotice }: UserInfoSecconst initial = displayName.charAt(0).toUpperCase();const appDisplayVersion = window.electronAPI.appDisplayVersion;const appDisplayVersionDetail = window.electronAPI.appDisplayVersionDetail;- const appRegionLabel = CURRENT_CINDY_REGION === 'global' ? 'Global' : 'CN';- const appVersionLabel = `${appRegionLabel} · ${appDisplayVersion}`;- const appVersionLabelDetail = `${appRegionLabel} · ${appDisplayVersionDetail}`;+ // 版本行的区域前缀。「哪些区域要标」只有 CINDY_REGION_CODE 一个事实源(issue+ // 反馈链路同源),口径见 DESIGN.md §16.3 与 region-and-editions.md §2.3:+ // cn → CN、dev → Dev、**global 不标**——Cindy 默认版本不给自己贴标签自证是全球版,+ // global 构建这一行只剩版本号。展示文案走 i18n(同 login.regionPill.* 的做法),+ // 便于日后改判为「中国大陆版」这类可译文案时不必回改组件;key 写成字面量分支而非+ // 动态拼接,保证 pnpm check:i18n 的静态提取能看到全部 key。一致性由+ // __tests__/regionCode.consistency.test.ts 逐区域逐语言断言。+ const appRegionLabel = !shouldLabelRegion(CURRENT_CINDY_REGION)+ ? null+ : CURRENT_CINDY_REGION === 'cn'+ ? t('sidebar.user.regionCodeCn')+ : t('sidebar.user.regionCodeDev');+ const appVersionLabel = appRegionLabel+ ? `${appRegionLabel} · ${appDisplayVersion}`+ : appDisplayVersion;+ const appVersionLabelDetail = appRegionLabel+ ? `${appRegionLabel} · ${appDisplayVersionDetail}`+ : appDisplayVersionDetail;const remoteAvailable = mode === 'cloud';const handleClick = () => {diff --git a/apps/desktop/src/renderer/features/cc-agent/IssueConfirmCard.tsx b/apps/desktop/src/renderer/features/cc-agent/IssueConfirmCard.tsxindex 209f92744e..74852f4523 100644--- a/apps/desktop/src/renderer/features/cc-agent/IssueConfirmCard.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/IssueConfirmCard.tsx@@ -23,7 +23,7 @@ import {} from '@/lib/issueConfirmDraftStore';import { cn } from '@/lib/utils';import type { PendingIssueConfirm } from '@/lib/makerChatStore';-import { shouldLabelIssueRegion } from '../../../shared/issueRegionCode';+import { shouldLabelRegion } from '../../../shared/regionCode';import { ISSUE_PUBLIC_NAME_MAX, normalizeIssuePublicName } from '../../../shared/issuePublicName';interface IssueConfirmCardProps {@@ -94,14 +94,14 @@ export function IssueConfirmCard({ sessionId, pending, onRespond }: IssueConfirm);// 构建区域代号,与登录页区域徽标同一套不对称命名(DESIGN.md §16.3):cn → CN、- // dev → Dev、global 不标。「哪些区域要标」只有 ISSUE_REGION_CODE 一个事实源 ——+ // dev → Dev、global 不标。「哪些区域要标」只有 CINDY_REGION_CODE 一个事实源 ——// main 侧 issue 正文用的是同一个常量,卡片承诺展示的就是最终写进 issue 的内容,// 两侧各写一份判断迟早漂移。region 缺失(IPC payload 异常)时按不标处理,不猜。// 展示文案仍走 i18n(同 login.regionPill.*,便于日后改判为可译文案),所以这里是// 「常量决定标不标 + i18n 提供文案」;两者逐区域逐语言的一致性由- // __tests__/issueRegionCode.consistency.test.ts 断言。key 写成字面量分支而非+ // __tests__/regionCode.consistency.test.ts 断言。key 写成字面量分支而非// 动态拼接,保证 pnpm check:i18n 的静态提取能看到全部 key。- const regionCode = !shouldLabelIssueRegion(pending.env.region)+ const regionCode = !shouldLabelRegion(pending.env.region)? null: pending.env.region === 'cn'? t('issueAgent.confirm.regionCodeCn')diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex 18a4d43fbe..6a400b990b 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -3909,6 +3909,8 @@"user": {"settingsLink": "Settings, current user: {{name}}","canaryBadge": "Canary user",+ "regionCodeCn": "CN",+ "regionCodeDev": "Dev","viewReleaseNotes": "View release notes","reopenUpdateBanner": "Update ready — click to review","downloadMobile": "Download Cindy Mobile"diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex bf89cc0beb..01d64bf839 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -3908,6 +3908,8 @@"user": {"settingsLink": "設定, 現在のユーザー: {{name}}","canaryBadge": "Canary ユーザー",+ "regionCodeCn": "CN",+ "regionCodeDev": "Dev","viewReleaseNotes": "リリースノートを表示","reopenUpdateBanner": "更新の準備完了 — クリックして確認","downloadMobile": "Cindy モバイル版をダウンロード"diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex f982048045..a6d0b376b5 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -3908,6 +3908,8 @@"user": {"settingsLink": "설정, 현재 사용자: {{name}}","canaryBadge": "Canary 사용자",+ "regionCodeCn": "CN",+ "regionCodeDev": "Dev","viewReleaseNotes": "릴리즈 노트 보기","reopenUpdateBanner": "업데이트 준비됨 — 클릭하여 확인","downloadMobile": "Cindy 모바일 다운로드"diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 0507c71678..6d7a1242da 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -3908,6 +3908,8 @@"user": {"settingsLink": "设置,当前用户:{{name}}","canaryBadge": "灰度用户",+ "regionCodeCn": "CN",+ "regionCodeDev": "Dev","viewReleaseNotes": "查看版本日志","reopenUpdateBanner": "有更新待重启,点击查看","downloadMobile": "下载 Cindy 移动端"diff --git a/apps/desktop/src/renderer/lib/issueConfirmPayload.ts b/apps/desktop/src/renderer/lib/issueConfirmPayload.tsindex cbece85cb9..4cb0500003 100644--- a/apps/desktop/src/renderer/lib/issueConfirmPayload.ts+++ b/apps/desktop/src/renderer/lib/issueConfirmPayload.ts@@ -7,7 +7,7 @@ import { normalizeIssuePublicName } from '../../shared/issuePublicName';** 写成字面量比较而非「数组 + includes + as CindyRegion」:narrowing 直接得出* `CindyRegion`,不需要类型断言,也就不会在 `CindyRegion` 改动后继续静默通过。- * 新增区域时的漏改由同族的 `shared/issueRegionCode.ts` 兜住——那里的+ * 新增区域时的漏改由同族的 `shared/regionCode.ts` 兜住——那里的* `Record<CindyRegion, …>` 会编译报错,改它时会一并看到本函数。*/export function parseIssueEnvRegion(raw: unknown): CindyRegion | undefined {diff --git a/apps/desktop/src/shared/issueRegionCode.ts b/apps/desktop/src/shared/issueRegionCode.tsdeleted file mode 100644index 6637f68d36..0000000000--- a/apps/desktop/src/shared/issueRegionCode.ts+++ /dev/null@@ -1,41 +0,0 @@-/**- * issueRegionCode — issue 反馈链路的构建区域代号,main(写进 issue 正文)与- * renderer(提交确认卡片)共用的**唯一事实源**。- *- * 为什么需要这个单点:确认卡片的契约是「展示的就是最终写进 issue 的内容」。- * 区域标注一旦在两侧各写一份「哪些区域要标」的判断,任一侧被改动就会让用户- * 确认时看到的区域与实际提交的正文不一致,而这种漂移没有任何编译期信号。- *- * 代号与登录页区域徽标同一套不对称命名(DESIGN.md §16.3「区域徽标」):- * cn → `CN`、dev → `Dev`、**global 不标**(值为 null)。- *- * ⚠️ global 故意为 null,两条理由叠在一起:- * 1. 产品叙事硬规则(DESIGN.md §16.3「给 global 恢复徽标即回退该决策,不得- * 回退」)——Cindy 默认版本不给自己贴标签自证是全球版,只标为特定法规单独- * 构建的版本;- * 2. global 是 DEFAULT_CINDY_REGION,「没有这一行」因此是个有含义的信号,不是- * 漏附加。新增区域时要么给代号,要么明确复用这条默认语义,别让第二个区域也- * 落进 null——那样两个区域就又分不清了。- *- * 代号本身四语同文、不翻译(术语表 region-code-cn / region-code-dev)。但卡片- * 上的展示文案仍走 i18n(`issueAgent.confirm.regionCode*`,同 login.regionPill.*- * 的做法),以便日后改判为「中国大陆版」这类可译文案时不必回改组件——本常量因此- * 只负责「标不标 + 正文写什么」,不直接当卡片文案用。两者的一致性由- * `renderer/__tests__/issueRegionCode.consistency.test.ts` 逐区域逐语言断言。- *- * Record<CindyRegion, …> 是 exhaustiveness 哨兵:`CindyRegion` 新增取值时本对象- * 会编译报错,提醒一并决定新区域标不标、补齐四语 key。- */--import type { CindyRegion } from '@cindy/maker-shared/brand-identity';--export const ISSUE_REGION_CODE: Readonly<Record<CindyRegion, string | null>> = Object.freeze({- cn: 'CN',- global: null,- dev: 'Dev',-});--/** 该区域是否需要在卡片与 issue 正文里标注(global / 未知一律 false)。 */-export function shouldLabelIssueRegion(region: CindyRegion | undefined): boolean {- return !!region && ISSUE_REGION_CODE[region] !== null;-}diff --git a/apps/desktop/src/shared/regionCode.ts b/apps/desktop/src/shared/regionCode.tsnew file mode 100644index 0000000000..b34748f523--- /dev/null+++ b/apps/desktop/src/shared/regionCode.ts@@ -0,0 +1,51 @@+/**+ * regionCode — 构建区域代号「标不标 + 标什么」的**唯一事实源**,main 与 renderer+ * 共用,跨全部消费链路(issue 反馈、侧栏版本行,后续新增的一并接进来)。+ *+ * 为什么必须是单点:区域标注一旦在各处各写一份「哪些区域要标」的判断,任一处被+ * 改动都不会有编译期信号,界面之间就会给同一个构建报出不同的区域身份;issue 链路+ * 还额外有「卡片展示的就是最终写进 issue 正文的内容」这条契约,两侧漂移会直接骗到+ * 用户。原 `issueRegionCode.ts` 只服务 issue 链路,侧栏接入时泛化为本文件。+ *+ * 代号与登录页区域徽标同一套不对称命名(DESIGN.md §16.3「区域徽标」):+ * cn → `CN`、dev → `Dev`、**global 不标**(值为 null)。+ *+ * ⚠️ global 故意为 null,两条理由叠在一起:+ * 1. 产品叙事硬规则(DESIGN.md §16.3「给 global 恢复徽标即回退该决策,不得+ * 回退」;产品侧同源条款 region-and-editions.md §2.3)——Cindy 默认版本不给+ * 自己贴标签自证是全球版,只标为特定法规单独构建的版本;+ * 2. global 是 DEFAULT_CINDY_REGION,「没有这一行」因此是个有含义的信号,不是+ * 漏附加。新增区域时要么给代号,要么明确复用这条默认语义,别让第二个区域也+ * 落进 null——那样两个区域就又分不清了。+ *+ * 代号本身四语同文、不翻译(术语表 region-code-cn / region-code-dev)。但**界面上+ * 的展示文案仍走 i18n**(`issueAgent.confirm.regionCode*`、`sidebar.user.regionCode*`,+ * 同 login.regionPill.* 的做法),以便日后改判为「中国大陆版」这类可译文案时不必回改+ * 组件——本常量因此只负责「标不标 + 写进非界面文本(如 issue 正文)时用什么」,不直接+ * 当界面文案用。各链路 i18n 值与本常量的一致性由+ * `renderer/__tests__/regionCode.consistency.test.ts` 逐链路逐区域逐语言断言。+ *+ * Record<CindyRegion, …> 是 exhaustiveness 哨兵:`CindyRegion` 新增取值时本对象+ * 会编译报错,提醒一并决定新区域标不标、补齐各链路的四语 key。+ */++import type { CindyRegion } from '@cindy/maker-shared/brand-identity';++export const CINDY_REGION_CODE: Readonly<Record<CindyRegion, string | null>> = Object.freeze({+ cn: 'CN',+ global: null,+ dev: 'Dev',+});++/**+ * 该区域是否需要在界面与非界面文本里标注(global / 缺失 / 未知一律 false)。+ *+ * ⚠️ 判定用「取到的是字符串」而不是「!== null」:未知 region 在表里取不到值,拿到的是+ * `undefined`,而 `undefined !== null` 成立——那样会把未知区域误判成要标注,继续走进+ * 有代号的渲染分支。类型上 `CindyRegion` 已穷举,但 issue 链路的 region 来自 IPC+ * payload,运行期不受类型保证,这里必须自己 fail-closed(呼应 IssueConfirmCard 的+ * 「region 缺失时按不标处理,不猜」)。+ */+export function shouldLabelRegion(region: CindyRegion | undefined): boolean {+ return !!region && typeof CINDY_REGION_CODE[region] === 'string';+}diff --git a/docs/product-rules/region-and-editions.md b/docs/product-rules/region-and-editions.mdindex 14510ead1d..df74312b20 100644--- a/docs/product-rules/region-and-editions.md+++ b/docs/product-rules/region-and-editions.md@@ -127,7 +127,7 @@ Cindy 是一个面向全球的产品。中国大陆版是它为当地法规、| 项 | 现状 | 冲突条款 | 收敛难点 || --- | --- | --- | --- || 登录页区域徽标 | 原设计规范规定国际区在标题旁显示红色 `Global` pill、中国大陆版不标。规范散落三处:`docs/design-rules/DESIGN.md` §16.1、`docs/design-rules/figma-component-spec.md` §4.10、`docs/design-rules/token-decision-table.md`(§3 的 `#df0c27` 语义与 `login-global-badge-bg` token)。落码在 `apps/desktop/src/renderer/components/login/LoginControls.tsx` 的 `LoginTitleBlock`(`LoginPage.tsx` 只负责传入) | §2.3 | **正在收敛**:PR #554 已将徽标翻转为 global 不标、`cn` / `dev` 标注,并同步修订 `DESIGN.md`。但它只改了三份设计源中的一份——`figma-component-spec.md` §4.10 与 `token-decision-table.md` 仍规定 `Global` pill 可见。**本行的删除条件是实现与三份设计源全部收敛,而不是 #554 单独合并** |-| 侧栏与移动端的区域标签 | `apps/desktop/src/renderer/components/sidebar/UserInfoSection.tsx:50` 对 Global 构建显示 `Global`、否则显示 `CN`;`apps/mobile/src/settings/mobileSettings.ts:124` 的 debug 项同样输出 `Global` / `CN` | §2.3、§2.5(`CN` 也不是本文规定的 `Mainland China`) | 属于调试 / 身份自查信息而非产品叙事表达,收敛优先级低于登录页,但不应在收敛登录页时被遗漏 |+| 侧栏与移动端的区域标签 | 桌面侧栏 `apps/desktop/src/renderer/components/sidebar/UserInfoSection.tsx` 的 **§2.3 部分已收敛**:区域代号统一走 `apps/desktop/src/shared/regionCode.ts` 的 `CINDY_REGION_CODE`(cn → `CN`、dev → `Dev`、global 为 `null` 不标),Global 构建的版本行只剩版本号。**§2.5 部分未收敛**:cn 构建仍渲染代号 `CN`,不是本文规定的 `Mainland China`。`apps/mobile/src/settings/mobileSettings.ts:124` 的 debug 项两条都未收敛,仍输出 `Global` / `CN` | §2.5(桌面);§2.3、§2.5(移动端) | 属于调试 / 身份自查信息而非产品叙事表达,收敛优先级低于登录页。**`CN` → `Mainland China` 是待产品裁决项**,不是单纯落码:术语表把 `CN` / `Dev` 登记为 `proposed`(`i18n/GLOSSARY.md` region-code-cn / region-code-dev),且 `DESIGN.md` §16.3 现规定徽标值就是四语同文的区域代号——改判要同时动设计规范、术语表与三条消费链路(登录页徽标、侧栏版本行、issue 正文)。本行的删除条件是移动端补上 §2.3、且 `CN` 措辞冲突被裁决或重新归类 || 端点清单文件名 | `config/endpoint.json` 是中国大陆版,`config/endpoint.global.json` 才是 Global | §2.1 | 改名牵动构建脚本与发布链路 || Electron userData 目录名 | `cn` 为 `Cindy`、`global` 为 `CindyGlobal` | §2.1 | 已发布客户端的数据目录不能直接改名,需要迁移方案 || Mobile 构建的 region 缺省 | `apps/mobile/app.config.js` 的 `resolveRegion()` 与 `scripts/shared/client-endpoint-build-env.cjs` 的 `resolveRegion()` 在未注入 `EXPO_PUBLIC_CINDY_AUTH_REGION` 时缺省为 `cn` | §2.2 | **有意保留的兼容基线**:这是 mobile 原生指纹基线,翻转默认值即触发一次全量冷更(`app.config.js` 顶部注释已写明)。日常开发脚本都显式注入 `global`,该缺省只在无 env 时兜底。收敛必须并入一次计划内冷更,并按 `docs/dev-rules/mobile-development.md` 的「冷更边界」取得把关人确认 |diff --git a/i18n/GLOSSARY.md b/i18n/GLOSSARY.mdindex d150227319..992d1efda5 100644--- a/i18n/GLOSSARY.md+++ b/i18n/GLOSSARY.md@@ -166,13 +166,13 @@ OAuth 2.0 Device Authorization Grant 中由用户在另一设备验证页输入### CN-中国大陆版登录页区域徽标上的标签值(DESIGN.md §16.3)。四语同值、**不翻译**——它是区域代号不是可译文案,所以把 en 原样写进各语言 translations(同 Agent 条目的做法),这让 caseStandardFor 生效、guard 能挡住 cn/Cn 之类的大小写漂移。forbidden 用条件形态(whenEn=CN)补另一半:大小写规则挡不住“被整体译走”,条件形态又能把拦截精确限定在英文源为 CN 的 key 上,不误伤别处正当的“国内”“中国版”表述。列的是最可能的自造说法,不求穷举。status 取 proposed 与 region-badge 一致:产品尚未拍板是否改用可译文案,改判后本条应随之作废而非沿用。2026-07-28 起同一代号也用于 submit_github_issue 的提交确认卡片与 issue 正文(`issueAgent.confirm.regionCodeCn`),口径与徽标完全一致:global 不标。+中国大陆版登录页区域徽标上的标签值(DESIGN.md §16.3)。四语同值、**不翻译**——它是区域代号不是可译文案,所以把 en 原样写进各语言 translations(同 Agent 条目的做法),这让 caseStandardFor 生效、guard 能挡住 cn/Cn 之类的大小写漂移。forbidden 用条件形态(whenEn=CN)补另一半:大小写规则挡不住“被整体译走”,条件形态又能把拦截精确限定在英文源为 CN 的 key 上,不误伤别处正当的“国内”“中国版”表述。列的是最可能的自造说法,不求穷举。status 取 proposed 与 region-badge 一致:产品尚未拍板是否改用可译文案,改判后本条应随之作废而非沿用。2026-07-28 起同一代号也用于 submit_github_issue 的提交确认卡片与 issue 正文(`issueAgent.confirm.regionCodeCn`)与侧栏用户卡片版本行(`sidebar.user.regionCodeCn`),口径与徽标完全一致:global 不标;「哪些区域要标」的唯一事实源是 `apps/desktop/src/shared/regionCode.ts`。已确定禁用:`中国版(仅当英文含 CN)`(zh-CN)、`国内版(仅当英文含 CN)`(zh-CN)、`中国版(仅当英文含 CN)`(ja)、`중국판(仅当英文含 CN)`(ko)### Dev-dev 版登录页区域徽标上的标签值(DESIGN.md §16.3),四语同值、不翻译,理由同 region-code-cn。与 CN 不同的是 dev 还是个普通技术词:豁免的两条文案里“Always on in dev mode.”“dev builds may be authorized…”“dev 模式下始终开启”指的是开发模式而非本区域标签,小写本就正确(四语同 key 一并覆盖)。用 exempt 精确豁免这两条、而不是整条关掉 checkCase,是为了保住徽标值本身的大小写约束——这正是本条存在的意义。2026-07-28 起同一代号也用于 submit_github_issue 的提交确认卡片与 issue 正文(`issueAgent.confirm.regionCodeDev`),口径与徽标完全一致:global 不标。+dev 版登录页区域徽标上的标签值(DESIGN.md §16.3),四语同值、不翻译,理由同 region-code-cn。与 CN 不同的是 dev 还是个普通技术词:豁免的两条文案里“Always on in dev mode.”“dev builds may be authorized…”“dev 模式下始终开启”指的是开发模式而非本区域标签,小写本就正确(四语同 key 一并覆盖)。用 exempt 精确豁免这两条、而不是整条关掉 checkCase,是为了保住徽标值本身的大小写约束——这正是本条存在的意义。2026-07-28 起同一代号也用于 submit_github_issue 的提交确认卡片与 issue 正文(`issueAgent.confirm.regionCodeDev`)与侧栏用户卡片版本行(`sidebar.user.regionCodeDev`),口径与徽标完全一致:global 不标;「哪些区域要标」的唯一事实源是 `apps/desktop/src/shared/regionCode.ts`。已确定禁用:`开发版(仅当英文含 Dev)`(zh-CN)、`開発版(仅当英文含 Dev)`(ja)、`개발판(仅当英文含 Dev)`(ko)diff --git a/i18n/glossary.json b/i18n/glossary.jsonindex 6528a56826..3f029849ef 100644--- a/i18n/glossary.json+++ b/i18n/glossary.json@@ -153,7 +153,7 @@}]},- "note": "中国大陆版登录页区域徽标上的标签值(DESIGN.md §16.3)。四语同值、**不翻译**——它是区域代号不是可译文案,所以把 en 原样写进各语言 translations(同 Agent 条目的做法),这让 caseStandardFor 生效、guard 能挡住 cn/Cn 之类的大小写漂移。forbidden 用条件形态(whenEn=CN)补另一半:大小写规则挡不住“被整体译走”,条件形态又能把拦截精确限定在英文源为 CN 的 key 上,不误伤别处正当的“国内”“中国版”表述。列的是最可能的自造说法,不求穷举。status 取 proposed 与 region-badge 一致:产品尚未拍板是否改用可译文案,改判后本条应随之作废而非沿用。2026-07-28 起同一代号也用于 submit_github_issue 的提交确认卡片与 issue 正文(`issueAgent.confirm.regionCodeCn`),口径与徽标完全一致:global 不标。"+ "note": "中国大陆版登录页区域徽标上的标签值(DESIGN.md §16.3)。四语同值、**不翻译**——它是区域代号不是可译文案,所以把 en 原样写进各语言 translations(同 Agent 条目的做法),这让 caseStandardFor 生效、guard 能挡住 cn/Cn 之类的大小写漂移。forbidden 用条件形态(whenEn=CN)补另一半:大小写规则挡不住“被整体译走”,条件形态又能把拦截精确限定在英文源为 CN 的 key 上,不误伤别处正当的“国内”“中国版”表述。列的是最可能的自造说法,不求穷举。status 取 proposed 与 region-badge 一致:产品尚未拍板是否改用可译文案,改判后本条应随之作废而非沿用。2026-07-28 起同一代号也用于 submit_github_issue 的提交确认卡片与 issue 正文(`issueAgent.confirm.regionCodeCn`)与侧栏用户卡片版本行(`sidebar.user.regionCodeCn`),口径与徽标完全一致:global 不标;「哪些区域要标」的唯一事实源是 `apps/desktop/src/shared/regionCode.ts`。"},{"id": "region-code-dev",@@ -188,7 +188,7 @@"desktop:settings.about.debugLogDescription","desktop:settings.voiceInput.permissions.inputMonitoring.tooltip"],- "note": "dev 版登录页区域徽标上的标签值(DESIGN.md §16.3),四语同值、不翻译,理由同 region-code-cn。与 CN 不同的是 dev 还是个普通技术词:豁免的两条文案里“Always on in dev mode.”“dev builds may be authorized…”“dev 模式下始终开启”指的是开发模式而非本区域标签,小写本就正确(四语同 key 一并覆盖)。用 exempt 精确豁免这两条、而不是整条关掉 checkCase,是为了保住徽标值本身的大小写约束——这正是本条存在的意义。2026-07-28 起同一代号也用于 submit_github_issue 的提交确认卡片与 issue 正文(`issueAgent.confirm.regionCodeDev`),口径与徽标完全一致:global 不标。"+ "note": "dev 版登录页区域徽标上的标签值(DESIGN.md §16.3),四语同值、不翻译,理由同 region-code-cn。与 CN 不同的是 dev 还是个普通技术词:豁免的两条文案里“Always on in dev mode.”“dev builds may be authorized…”“dev 模式下始终开启”指的是开发模式而非本区域标签,小写本就正确(四语同 key 一并覆盖)。用 exempt 精确豁免这两条、而不是整条关掉 checkCase,是为了保住徽标值本身的大小写约束——这正是本条存在的意义。2026-07-28 起同一代号也用于 submit_github_issue 的提交确认卡片与 issue 正文(`issueAgent.confirm.regionCodeDev`)与侧栏用户卡片版本行(`sidebar.user.regionCodeDev`),口径与徽标完全一致:global 不标;「哪些区域要标」的唯一事实源是 `apps/desktop/src/shared/regionCode.ts`。"},{"id": "agent",