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(pi): localize Desktop runtime recovery receipts

zqchris6525f31b3daf
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts
index 70b01b637b..0066cd7ef3 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts
@@ -1,6 +1,7 @@
import { Session, type AgentEvent, type AgentSessionHandle } from '@cindy/maker-core';
import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest';
import { handleSessionEvent, type SessionEventDependencies } from '../sessionEventPipeline.js';
+import { setMainLocale } from '../../i18n.js';
import { installSessionTurnObserver } from '../sessionTurnObserver.js';
import { createSessionBindingLifecycle } from '../sessionBindingLifecycle.js';
import { SessionTurnActivityTracker } from '../sessionTurnActivityTracker.js';
@@ -238,7 +239,7 @@ function harness() {
attemptBotCompactRuntimeRefresh: vi.fn(),
botDelegationServiceHolder: { settleSession: vi.fn(async () => {}) },
isFencedStaleSessionTerminal: vi.fn(() => false),
- redactEventForRenderer: vi.fn((value: AgentEvent) => ({ ...value, data: { redacted: true } })),
+ redactEventForRenderer: vi.fn((value: AgentEvent): AgentEvent => ({ ...value, data: { redacted: true } })),
interruptedTurnAutoResumeGuard: {
noteAttemptEvent: vi.fn(),
noteTurnStarted: vi.fn(),
@@ -367,6 +368,7 @@ beforeEach(() => {
effects.fn('verdictForModelRoute').mockResolvedValue({ kind: 'pass' });
});
afterEach(() => {
+ setMainLocale('en');
vi.clearAllTimers();
vi.useRealTimers();
});
@@ -381,20 +383,44 @@ function ordered(...names: string[]) {
}
describe('production Session event pipeline', () => {
- it('persists and broadcasts a retirement recovery receipt after a successful product terminal', async () => {
+ it.each([
+ ['zh-CN', 'Pi 扩展未能完成刷新。请重启 Cindy 后再使用 Pi。'],
+ ['zh-TW', 'Pi 擴充功能未能完成重新整理。請重新啟動 Cindy 後再使用 Pi。'],
+ ['en', 'Pi extensions could not be refreshed. Restart Cindy before using Pi again.'],
+ ['ja', 'Pi 拡張機能を更新できませんでした。Pi を再び使用する前に Cindy を再起動してください。'],
+ ['ko', 'Pi 확장을 새로 고치지 못했습니다. Pi를 다시 사용하기 전에 Cindy를 다시 시작하세요.'],
+ ] as const)('persists and broadcasts localized post-terminal recovery in %s', async (locale, text) => {
+ setMainLocale(locale);
const h = harness();
+ // Production redaction preserves text events; the general harness replaces all data.
+ h.deps.redactEventForRenderer.mockImplementation((value: AgentEvent) => value);
h.emit(event('done', { status: 'completed', result: 'saved' }, { source: 'pi' }));
- const data = { isFinal: true, text: 'partial: restart-cindy-to-refresh-packages' };
+ const data = { isFinal: true, text: '[Cindy Pi package runtime convergence receipt] {"recoveryAction":"restart-cindy-to-refresh-packages"}' };
+ const receipt = event('text', data, {
+ source: 'pi', runtimeRecovery: true,
+ sessionInstanceId: h.session.instanceId, sessionTurnGeneration: 0,
+ });
effects.fn('onAssistantTextEvent').mockClear();
effects.fn('broadcast').mockClear();
- h.emit(event('text', data, { source: 'pi' }));
- expect(effects.fn('onAssistantTextEvent')).toHaveBeenCalledWith('task', data, null);
- expect(effects.fn('broadcast')).toHaveBeenCalled();
+ h.emit(receipt);
+ expect(effects.fn('onAssistantTextEvent')).toHaveBeenCalledWith('task', { ...data, text }, null);
+ expect(effects.fn('broadcast')).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({
+ sessionId: 'task', event: { ...receipt, data: { ...data, text } },
+ }));
+ expect(receipt.data).toEqual(data);
expect(h.activity.isSessionInTurn('task')).toBe(false);
expect(h.handle.send).not.toHaveBeenCalled();
await h.dispose();
});
+ it('preserves ordinary Pi text without the Host recovery marker', async () => {
+ const h = harness();
+ const data = { isFinal: true, text: 'partial: restart-cindy-to-refresh-packages' };
+ h.emit(event('text', data, { source: 'pi' }));
+ expect(effects.fn('onAssistantTextEvent')).toHaveBeenCalledWith('task', data, null);
+ await h.dispose();
+ });
+
it('keeps continuation segments running, then seals the final product boundary', async () => {
const h = harness();
vi.setSystemTime(1000);
diff --git a/apps/desktop/src/main/maker-ipc/sessionEventPreparation.ts b/apps/desktop/src/main/maker-ipc/sessionEventPreparation.ts
index 4f5b739433..490d765e3c 100644
--- a/apps/desktop/src/main/maker-ipc/sessionEventPreparation.ts
+++ b/apps/desktop/src/main/maker-ipc/sessionEventPreparation.ts
@@ -15,6 +15,7 @@ import { noteSubagentObservationTurnStarted } from '../subagentObservationRewind
import { persistSessionFields } from '../localDb/ipc/sessions.js';
import { createLogger } from '../logger.js';
+import { t } from '../i18n.js';
import type { GitSnapshotCoordinator } from '../git-snapshot/gitSnapshotCoordinator.js';
import { markSessionTurnStarted } from '../localDb/sessionActiveTurn.js';
import {
@@ -145,6 +146,17 @@ export function prepareSessionEvent(
});
return;
}
+ // Post-terminal Host recovery bypasses the model. Localize before both
+ // persistence and renderer delivery, without mutating the internal receipt.
+ if (event.runtimeRecovery && event.source === 'pi' && event.type === 'text') {
+ event = {
+ ...event,
+ data: {
+ ...(event.data as Record<string, unknown>),
+ text: t('settings.piPackages.failure.runtimeRetirementFailed'),
+ },
+ };
+ }
// 自动续跑的 pending 不能只靠 status(isRunning=true) 清理:Pi/Claude 的
// terminal-only 路径可能首个事件就是 error。Session 已把 host-owned token
// 盖到事件上,首个匹配 token 的事件即视为 provider accepted。