Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(i18n): 修正动态展示文案

davidb5f9dfdafd7f
diff --git a/apps/desktop/src/renderer/features/scheduler/lib/__tests__/formatters.test.ts b/apps/desktop/src/renderer/features/scheduler/lib/__tests__/formatters.test.ts
new file mode 100644
index 0000000000..7d5cfd9c06
--- /dev/null
+++ b/apps/desktop/src/renderer/features/scheduler/lib/__tests__/formatters.test.ts
@@ -0,0 +1,23 @@
+import type { TFunction } from 'i18next';
+import { describe, expect, it } from 'vitest';
+
+import { formatNextRun } from '../formatters';
+
+const zhTranslate = ((key: string, options?: Record<string, unknown>) => {
+ const count = Number(options?.count ?? 0);
+ if (key.endsWith('intervalMinutes')) return `${count}分钟`;
+ if (key.endsWith('intervalHours')) return `${count}小时`;
+ if (key.endsWith('intervalDays')) return `${count}天`;
+ if (key.endsWith('.next')) return `下次 ${options?.when}(${options?.interval}后)`;
+ return String(options?.defaultValue ?? key);
+}) as TFunction;
+
+describe('scheduler formatters', () => {
+ it('localizes the next-run interval before interpolating it into the sentence', () => {
+ const now = new Date(2026, 0, 1, 9, 0).getTime();
+
+ expect(formatNextRun(now + 30 * 60_000, now, zhTranslate)).toContain('(30分钟后)');
+ expect(formatNextRun(now + 3 * 60 * 60_000, now, zhTranslate)).toContain('(3小时后)');
+ expect(formatNextRun(now + 2 * 24 * 60 * 60_000, now, zhTranslate)).toContain('(2天后)');
+ });
+});
diff --git a/apps/desktop/src/renderer/features/scheduler/lib/formatters.ts b/apps/desktop/src/renderer/features/scheduler/lib/formatters.ts
index 9318d5dcce..eed41ee342 100644
--- a/apps/desktop/src/renderer/features/scheduler/lib/formatters.ts
+++ b/apps/desktop/src/renderer/features/scheduler/lib/formatters.ts
@@ -189,9 +189,25 @@ export function formatNextRun(
const today = startOfLocalDay(new Date(now));
const nextDay = startOfLocalDay(next);
let interval: string;
- if (diff < MS_HOUR) interval = `${Math.floor(diff / MS_MIN)}m`;
- else if (diff < MS_DAY) interval = `${Math.floor(diff / MS_HOUR)}h`;
- else interval = `${Math.floor(diff / MS_DAY)}d`;
+ if (diff < MS_HOUR) {
+ const count = Math.floor(diff / MS_MIN);
+ interval = translate?.('scheduler.presentation.time.intervalMinutes', {
+ defaultValue: `${count}m`,
+ count,
+ }) ?? `${count}m`;
+ } else if (diff < MS_DAY) {
+ const count = Math.floor(diff / MS_HOUR);
+ interval = translate?.('scheduler.presentation.time.intervalHours', {
+ defaultValue: `${count}h`,
+ count,
+ }) ?? `${count}h`;
+ } else {
+ const count = Math.floor(diff / MS_DAY);
+ interval = translate?.('scheduler.presentation.time.intervalDays', {
+ defaultValue: `${count}d`,
+ count,
+ }) ?? `${count}d`;
+ }
const time = hm(next);
let when: string;
if (nextDay.getTime() === today.getTime()) when = time;
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 85a9f6ef05..1c2b5e4e5e 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -8487,6 +8487,9 @@
"startedSeconds": "Started {{count}}s ago",
"startedMinutes": "Started {{count}}m ago",
"startedHours": "Started {{count}}h ago",
+ "intervalMinutes": "{{count}}m",
+ "intervalHours": "{{count}}h",
+ "intervalDays": "{{count}}d",
"nextLessThanMinute": "Next less than 1 min",
"next": "Next {{when}} (in {{interval}})"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 8be0c06dae..6eb2feae8d 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -8475,8 +8475,11 @@
"startedSeconds": "{{count}} 秒前に開始",
"startedMinutes": "{{count}} 分前に開始",
"startedHours": "{{count}} 時間前に開始",
+ "intervalMinutes": "{{count}}分",
+ "intervalHours": "{{count}}時間",
+ "intervalDays": "{{count}}日",
"nextLessThanMinute": "次回は 1 分以内",
- "next": "次回 {{when}}({{interval}} 後)"
+ "next": "次回 {{when}}({{interval}}後)"
},
"destination": {
"boundSession": "タスク {{id}} に紐付け",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index d7993385b3..cbddf70ac5 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -8475,6 +8475,9 @@
"startedSeconds": "{{count}}초 전에 시작",
"startedMinutes": "{{count}}분 전에 시작",
"startedHours": "{{count}}시간 전에 시작",
+ "intervalMinutes": "{{count}}분",
+ "intervalHours": "{{count}}시간",
+ "intervalDays": "{{count}}일",
"nextLessThanMinute": "다음 실행까지 1분 미만",
"next": "다음 {{when}}({{interval}} 후)"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 5f96721fd2..6a74b71a90 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -8475,8 +8475,11 @@
"startedSeconds": "{{count}} 秒前开始",
"startedMinutes": "{{count}} 分钟前开始",
"startedHours": "{{count}} 小时前开始",
+ "intervalMinutes": "{{count}}分钟",
+ "intervalHours": "{{count}}小时",
+ "intervalDays": "{{count}}天",
"nextLessThanMinute": "下次不到 1 分钟",
- "next": "下次 {{when}}({{interval}} 后)"
+ "next": "下次 {{when}}({{interval}}后)"
},
"destination": {
"boundSession": "绑定到任务 {{id}}",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 948914b490..4a64f1a52b 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -8475,8 +8475,11 @@
"startedSeconds": "{{count}} 秒前開始",
"startedMinutes": "{{count}} 分鐘前開始",
"startedHours": "{{count}} 小時前開始",
+ "intervalMinutes": "{{count}}分鐘",
+ "intervalHours": "{{count}}小時",
+ "intervalDays": "{{count}}天",
"nextLessThanMinute": "下次不到 1 分鐘",
- "next": "下次 {{when}}({{interval}} 後)"
+ "next": "下次 {{when}}({{interval}}後)"
},
"destination": {
"boundSession": "繫結到任務 {{id}}",
diff --git a/apps/mobile/app/sessions/new.tsx b/apps/mobile/app/sessions/new.tsx
index f6e578b62d..2fe416b5be 100644
--- a/apps/mobile/app/sessions/new.tsx
+++ b/apps/mobile/app/sessions/new.tsx
@@ -4391,10 +4391,10 @@ export default function NewRemoteSessionScreen() {
});
} catch (err) {
if (!isCurrentOwner()) return;
- // agent 未鉴权(电脑端没配 key / 没登录)是新会话失败的高频原因,
- // 换成带引导的中文提示;其它错误维持原文。
+ // agent 未鉴权(电脑端没配 key / 没登录)是新任务失败的高频原因。
+ // state 保留结构化原文,渲染时再按当前语言生成引导,避免切换语言后缓存旧文案。
const raw = formatRemoteError(err);
- setError(describeAgentAuthError(raw) ?? raw);
+ setError(raw);
} finally {
releasePrecreatedRegistration?.();
if (!handedOff) {
@@ -5613,7 +5613,9 @@ export default function NewRemoteSessionScreen() {
</View>
) : null}
- {error ? <Text style={styles.errorText}>{error}</Text> : null}
+ {error ? (
+ <Text style={styles.errorText}>{describeAgentAuthError(error) ?? error}</Text>
+ ) : null}
{/* 发送前鉴权提示:选中 agent 在被控端无已连接供应商时提前告知;
error 已展示(含被门禁拦截的同款文案)时不重复出现。 */}
{!error && agentAuthVerdict === 'unauthenticated' ? (
diff --git a/apps/mobile/src/__tests__/homeLiveActivity.test.ts b/apps/mobile/src/__tests__/homeLiveActivity.test.ts
index 8986c04834..1594e5e244 100644
--- a/apps/mobile/src/__tests__/homeLiveActivity.test.ts
+++ b/apps/mobile/src/__tests__/homeLiveActivity.test.ts
@@ -1,5 +1,6 @@
import { beforeEach, describe, expect, it } from 'vitest';
import { SESSION_ACTIVITY_CHANNEL } from '@cindy/device-link';
+import { i18n } from '@/i18n';
import { buildMobileHomePresentation } from '@/session/mobileHome';
import { remoteSessionStore } from '@/session/remoteSessionStore';
import {
@@ -105,4 +106,23 @@ describe('mobile Home live activity', () => {
expect(remoteSessionStore.isSessionRunning('s1')).toBe(true);
expect(item ? buildRemoteSessionCardPreview(item, { running: true }) : null).toBe('正在检查失败测试');
});
+
+ it('preserves a real project basename that matches the shared fallback copy', async () => {
+ const previousLanguage = i18n.language;
+ try {
+ await i18n.changeLanguage('en');
+ const home = buildMobileHomePresentation({
+ devices: [{ canOpen: true, deviceId: 'dev-1', name: 'Mac' }],
+ sessions: [session('same-as-fallback', {
+ deviceLinkDeviceId: 'dev-1',
+ deviceLinkDeviceName: 'Mac',
+ workingDir: '/repo/未分类项目',
+ })],
+ });
+
+ expect(home.projects[0]?.title).toBe('未分类项目');
+ } finally {
+ await i18n.changeLanguage(previousLanguage);
+ }
+ });
});
diff --git a/apps/mobile/src/__tests__/mobilePresentationRefresh.test.ts b/apps/mobile/src/__tests__/mobilePresentationRefresh.test.ts
index e342684162..1f4d69e6da 100644
--- a/apps/mobile/src/__tests__/mobilePresentationRefresh.test.ts
+++ b/apps/mobile/src/__tests__/mobilePresentationRefresh.test.ts
@@ -66,6 +66,13 @@ describe('mobile localized presentation refresh', () => {
expect(source.match(/\[currentSession\?\.orcaRole, i18nInstance\.language\]/g)).toHaveLength(2);
});
+ it('keeps new-task authentication errors raw until render time', () => {
+ const source = read('app/sessions/new.tsx');
+
+ expect(source).toContain('setError(raw)');
+ expect(source).toContain('{describeAgentAuthError(error) ?? error}');
+ });
+
it('rebuilds localized session sections when the language changes', () => {
const source = read('app/devices/[deviceId].tsx');
const sectionProjection = source.slice(
diff --git a/apps/mobile/src/__tests__/sessionList.test.ts b/apps/mobile/src/__tests__/sessionList.test.ts
index 754c851f19..5019992c99 100644
--- a/apps/mobile/src/__tests__/sessionList.test.ts
+++ b/apps/mobile/src/__tests__/sessionList.test.ts
@@ -153,6 +153,25 @@ describe('sessionList', () => {
}, { running: true })).toBe('自动化运行中');
});
+ it('does not translate a real message that happens to match a generated preview state', async () => {
+ const previousLanguage = i18n.language;
+ try {
+ await i18n.changeLanguage('en');
+ const item = toRemoteSessionListItem(
+ session('literal-status-message'),
+ Date.now(),
+ undefined,
+ 0,
+ '运行中',
+ );
+
+ expect(buildRemoteSessionCardPreview(item)).toBe('运行中');
+ expect(buildRemoteSessionCardPreview(item, { running: true })).toBe('Running');
+ } finally {
+ await i18n.changeLanguage(previousLanguage);
+ }
+ });
+
it('shows the device-link preview on idle rows, null when the session has no message', () => {
// 首页未打开的会话消息未 load,改由 device-link 会话列表带的 session.preview(桌面产出),
// 经 sessionRowMessagePreview 流入 item.messagePreview;真正零消息会话则留空。
diff --git a/apps/mobile/src/session/mobileHome.ts b/apps/mobile/src/session/mobileHome.ts
index 3d4bed0be4..42f92da5e2 100644
--- a/apps/mobile/src/session/mobileHome.ts
+++ b/apps/mobile/src/session/mobileHome.ts
@@ -46,9 +46,9 @@ export function buildMobileHomePresentation(options: MobileHomeOptions): MobileH
deviceName,
sessions: project.sessions.map((item) => localizeRemoteSessionListItem(item, now)),
subtitle: [deviceName, workingDir].filter(Boolean).join(' · '),
- title: project.title === '未分类项目'
- ? i18n.t('devices.presentation.home.uncategorizedProject')
- : project.title,
+ title: project.workingDir
+ ? project.title
+ : i18n.t('devices.presentation.home.uncategorizedProject'),
};
}),
};
diff --git a/apps/mobile/src/session/sessionList.ts b/apps/mobile/src/session/sessionList.ts
index 10215889d7..6455d65e45 100644
--- a/apps/mobile/src/session/sessionList.ts
+++ b/apps/mobile/src/session/sessionList.ts
@@ -1,4 +1,5 @@
import { i18n } from '@/i18n';
+import { mobilePresentationLocalizer } from '@/i18n/presentationLocalizer';
import {
buildRemoteSessionCardPreview as buildRemoteSessionCardPreviewShared,
buildRemoteSessionListContext as buildRemoteSessionListContextShared,
@@ -121,21 +122,10 @@ export function buildRemoteSessionCardPreview(
item: RemoteSessionListItem,
options: { running?: boolean } = {},
): string | null {
- const preview = buildRemoteSessionCardPreviewShared(item, options);
- const key = preview === '等待授权'
- ? 'permission'
- : preview === '等待计划审阅'
- ? 'planReview'
- : preview === '等待你的回复'
- ? 'answer'
- : preview === '等待你处理'
- ? 'attention'
- : preview === '自动化执行中'
- ? 'automationRunning'
- : preview === '运行中'
- ? 'running'
- : null;
- return key ? i18n.t(`devices.presentation.sessionList.preview.${key}`) : preview;
+ return buildRemoteSessionCardPreviewShared(item, {
+ ...options,
+ localizer: mobilePresentationLocalizer,
+ });
}
export function formatRemoteSessionSidebarTime(iso: string | undefined, now = Date.now()): string {
diff --git a/packages/maker-shared/src/__tests__/sessionList.test.ts b/packages/maker-shared/src/__tests__/sessionList.test.ts
index 38fda526b8..e943bce697 100644
--- a/packages/maker-shared/src/__tests__/sessionList.test.ts
+++ b/packages/maker-shared/src/__tests__/sessionList.test.ts
@@ -271,6 +271,22 @@ describe('sessionList', () => {
expect(buildRemoteSessionCardPreview(base, { running: false })).toBe('旧的消息摘要');
});
+ it('localizes generated preview states without treating message text as a state marker', () => {
+ const message = toRemoteSessionListItem(
+ session('s1', { title: 'Run tests' }),
+ new Date('2026-01-01T00:10:00.000Z').getTime(),
+ undefined,
+ 0,
+ '运行中',
+ );
+ const localizer = {
+ translate: (key: string, fallback: string) => key.endsWith('.running') ? 'Running' : fallback,
+ };
+
+ expect(buildRemoteSessionCardPreview(message, { localizer })).toBe('运行中');
+ expect(buildRemoteSessionCardPreview(message, { localizer, running: true })).toBe('Running');
+ });
+
it('prefers human awaiting copy over stale tool status when interaction is pending', () => {
const base = toRemoteSessionListItem(
session('s1', { title: 'Ask something' }),
diff --git a/packages/maker-shared/src/sessionList.ts b/packages/maker-shared/src/sessionList.ts
index 3b633057df..b473dab30d 100644
--- a/packages/maker-shared/src/sessionList.ts
+++ b/packages/maker-shared/src/sessionList.ts
@@ -1,5 +1,6 @@
import { messageContentToPreview } from './messageNormalize.js';
import { stripTrailingPathSeparators } from './pathText.js';
+import { presentationText, type PresentationLocalizer } from './presentationLocalization.js';
import { isSyntheticTriggerText } from './syntheticTrigger.js';
import type { RemoteSchedule, RemoteScheduleRun, RemoteScheduleRunStatus } from './scheduleTypes.js';
import { toMillis } from './scheduleModel.js';
@@ -528,7 +529,7 @@ function remoteSessionListItemIsRunning(
export function buildRemoteSessionCardPreview(
item: RemoteSessionListItem,
- options: { running?: boolean } = {},
+ options: { running?: boolean; localizer?: PresentationLocalizer } = {},
): string | null {
// 等待交互优先于一切:此时 compactDetail 往往是过期的 tool 状态行(典型
// 'ask_user_question running...'),和"在等你"的语义打架。与桌面卡片 awaitingText
@@ -538,17 +539,49 @@ export function buildRemoteSessionCardPreview(
|| (live != null && isActiveLiveActivity(live) && live.phase === 'needs-interaction');
if (awaiting) {
const kind = live?.interactionKind;
- if (kind === 'permission') return '等待授权';
- if (kind === 'plan_review') return '等待计划审阅';
- if (kind === 'ask_user_question') return '等待你的回复';
- return '等待你处理';
+ if (kind === 'permission') {
+ return presentationText(
+ options.localizer,
+ 'devices.presentation.sessionList.preview.permission',
+ '等待授权',
+ );
+ }
+ if (kind === 'plan_review') {
+ return presentationText(
+ options.localizer,
+ 'devices.presentation.sessionList.preview.planReview',
+ '等待计划审阅',
+ );
+ }
+ if (kind === 'ask_user_question') {
+ return presentationText(
+ options.localizer,
+ 'devices.presentation.sessionList.preview.answer',
+ '等待你的回复',
+ );
+ }
+ return presentationText(
+ options.localizer,
+ 'devices.presentation.sessionList.preview.attention',
+ '等待你处理',
+ );
}
if (options.running === true) {
if (live && isActiveLiveActivity(live)) {
const text = normalizeInlinePreview(live.compactDetail);
if (text) return text;
}
- return item.scheduleInfo?.running || item.session.source === 'scheduler' ? '自动化执行中' : '运行中';
+ return item.scheduleInfo?.running || item.session.source === 'scheduler'
+ ? presentationText(
+ options.localizer,
+ 'devices.presentation.sessionList.preview.automationRunning',
+ '自动化执行中',
+ )
+ : presentationText(
+ options.localizer,
+ 'devices.presentation.sessionList.preview.running',
+ '运行中',
+ );
}
// idle:展示最近一条消息预览。messagePreview 来自已 load 的消息(打开过的会话),
// 或由首页构建时回退到 device-link 带的 session.preview(见 buildMobileHomePresentation /