Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat: 错误卡展开详情后提供「诊断」入口
Dash4e508aa46885
diff --git a/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx b/apps/desktop/src/renderer/components/chat/ErrorBanner.tsxindex 13a81d14a1..1faf77c8cb 100644--- a/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx+++ b/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx@@ -62,6 +62,7 @@ import {} from '../../../shared/claudeGatewayError';import { isPiImageInputUnsupportedError } from '../../../shared/inputError';import type { ToolLoopErrorDetails } from '@cindy/maker-core';+import type { ErrorDiagnosisSource } from '@/lib/errorDiagnosisPrompt';interface ErrorBannerProps {error: string;@@ -118,6 +119,8 @@ interface ErrorBannerProps {silentEncryptedRetryEnabled?: boolean;onForkStripEncrypted?: () => void | Promise<void>;forkStripEncryptedRunning?: boolean;+ /** 展开详情后的「诊断」:上层带着错误与出错任务去新任务里排查。 */+ onDiagnose?: (error: ErrorDiagnosisSource) => void;/** 当前 error 是非终止的 recoverableError(turn 还在跑,agent/daemon 在自动* 重试,如 codex 网络 retry-loop 透出)。网络类分支据此区分文案:「正在自动* 重试…」vs「服务暂时不可达,可点击重试」。历史尾部行恒为 false。 */@@ -152,6 +155,7 @@ export function ErrorBanner({silentEncryptedRetryEnabled = false,onForkStripEncrypted,forkStripEncryptedRunning = false,+ onDiagnose,isRecoverable = false,sessionSource,style,@@ -675,6 +679,11 @@ export function ErrorBanner({: undefined}details={canShowErrorDetails ? error : undefined}+ onDiagnose={+ onDiagnose+ ? () => onDiagnose({ message: displayError, details: error, reason: errorReason })+ : undefined+ }onDismiss={onCancel}icon={openAiConnectionRecoveredSinceError ? (diff --git a/apps/desktop/src/renderer/components/chat/InterruptedTurnBanner.tsx b/apps/desktop/src/renderer/components/chat/InterruptedTurnBanner.tsxindex 1c2eba25a8..3f2d9a05f3 100644--- a/apps/desktop/src/renderer/components/chat/InterruptedTurnBanner.tsx+++ b/apps/desktop/src/renderer/components/chat/InterruptedTurnBanner.tsx@@ -36,6 +36,7 @@ import { cn } from '@/lib/utils';import { extractUsageLimitRecoveryHint } from '@/lib/usageLimitRecovery';import type { ToolLoopErrorDetails } from '@cindy/maker-core';import { ErrorBanner } from './ErrorBanner';+import type { ErrorDiagnosisSource } from '@/lib/errorDiagnosisPrompt';import { ErrorNotice } from '@/components/ui/error-notice';import { Button } from '@/components/ui/button';@@ -111,6 +112,7 @@ export function ErrorTailErrorBanner({silentEncryptedRetryEnabled,onForkStripEncrypted,forkStripEncryptedRunning,+ onDiagnose,errorReason,toolLoop,onSilentStopContinue,@@ -138,6 +140,7 @@ export function ErrorTailErrorBanner({silentEncryptedRetryEnabled?: boolean;onForkStripEncrypted?: () => void | Promise<void>;forkStripEncryptedRunning?: boolean;+ onDiagnose?: (error: ErrorDiagnosisSource) => void;errorReason?: string | null;toolLoop?: ToolLoopErrorDetails;onSilentStopContinue?: () => void;@@ -173,6 +176,7 @@ export function ErrorTailErrorBanner({silentEncryptedRetryEnabled={silentEncryptedRetryEnabled}onForkStripEncrypted={onForkStripEncrypted}forkStripEncryptedRunning={forkStripEncryptedRunning}+ onDiagnose={onDiagnose}sessionSource={sessionSource}className={className}style={style}diff --git a/apps/desktop/src/renderer/components/chat/__tests__/ErrorLocalization.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/ErrorLocalization.test.tsxindex b8f99540f8..5cc6026df8 100644--- a/apps/desktop/src/renderer/components/chat/__tests__/ErrorLocalization.test.tsx+++ b/apps/desktop/src/renderer/components/chat/__tests__/ErrorLocalization.test.tsx@@ -19,6 +19,7 @@ import { ErrorBanner } from '../ErrorBanner';import { ErrorMessageCard } from '../ErrorMessageCard';import { ErrorTailErrorBanner } from '../InterruptedTurnBanner';import { remoteErrorMessageForBanner } from '@/lib/makerChatStore';+import { buildErrorDiagnosisPrompt } from '@/lib/errorDiagnosisPrompt';const locales = { en, 'zh-CN': zhCN, 'zh-TW': zhTW, ja, ko };const raw = JSON.stringify({ error: {@@ -27,6 +28,23 @@ const raw = JSON.stringify({ error: {} });afterEach(cleanup);+// 诊断入口只在展开详情后出现;预填给新任务的提示带出错任务链接,且与详情同样脱敏。+it('offers diagnosis after expanding details with a redacted prompt for the failed session', async () => {+ const i18n = createInstance();+ await i18n.init({ lng: 'en', resources: { en: { translation: en } }, interpolation: { escapeValue: false } });+ const onDiagnose = vi.fn();+ const error = 'Unexpected provider failure; api_key=private-test-value';+ render(<I18nextProvider i18n={i18n}><ErrorBanner error={error} onRetry={vi.fn()} onDiagnose={onDiagnose} /></I18nextProvider>);+ expect(screen.queryByText(en.chat.errorBanner.diagnose)).toBeNull();+ fireEvent.click(screen.getByText(en.chat.errorBanner.networkShowRaw));+ fireEvent.click(screen.getByText(en.chat.errorBanner.diagnose));+ const prompt = buildErrorDiagnosisPrompt(i18n.t, 'cindy://session/s1', onDiagnose.mock.calls[0][0]);+ expect(prompt).toContain('cindy://session/s1');+ expect(prompt).toContain(en.chat.errorBanner.replyFailed);+ expect(prompt).toContain('Unexpected provider failure');+ expect(prompt).not.toContain('private-test-value');+});+describe.each(SUPPORTED_LOCALES)('error presentation in %s', locale => {it('keeps the localized blocked-input fallback visible instead of a reply-failure summary', async () => {const i18n = createInstance();diff --git a/apps/desktop/src/renderer/components/ui/error-notice.tsx b/apps/desktop/src/renderer/components/ui/error-notice.tsxindex ba7d7df623..cc560194cf 100644--- a/apps/desktop/src/renderer/components/ui/error-notice.tsx+++ b/apps/desktop/src/renderer/components/ui/error-notice.tsx@@ -5,7 +5,7 @@ import {type ComponentPropsWithoutRef,type ReactNode,} from 'react';-import { AlertCircle, ChevronDown, ChevronRight, X } from 'lucide-react';+import { AlertCircle, ChevronDown, ChevronRight, Stethoscope, X } from 'lucide-react';import { useTranslation } from 'react-i18next';import { redactSensitiveText } from '@cindy/maker-shared/error-redaction';import { cn } from '@/lib/utils';@@ -17,6 +17,8 @@ interface ErrorNoticeProps extends Omit<ComponentPropsWithoutRef<'div'>, 'childrdescription?: ReactNode;actions?: ReactNode;details?: string;+ /** Offered only after the user expands details; the caller decides where diagnosis happens. */+ onDiagnose?: () => void;icon?: ReactNode;onDismiss?: () => void;dismissLabel?: string;@@ -30,6 +32,7 @@ export const ErrorNotice = forwardRef<HTMLDivElement, ErrorNoticeProps>(functiondescription,actions,details,+ onDiagnose,icon,onDismiss,dismissLabel,@@ -77,6 +80,19 @@ export const ErrorNotice = forwardRef<HTMLDivElement, ErrorNoticeProps>(function{t(expanded ? 'chat.errorBanner.networkHideRaw' : 'chat.errorBanner.networkShowRaw')}</Button>)}+ {details && expanded && onDiagnose && (+ <Button+ size="sm"+ compact+ type="button"+ data-split-pane-route-action=""+ onClick={onDiagnose}+ title={t('chat.errorBanner.diagnoseTitle')}+ >+ <Stethoscope size={12} />+ {t('chat.errorBanner.diagnose')}+ </Button>+ )}</div>{details && expanded && (<pre className="mt-2 max-h-40 overflow-auto whitespace-pre-wrap break-all rounded-lg bg-[hsl(var(--surface-hsl))] p-2 text-12 leading-5 text-[var(--text-secondary)]">diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsxindex 4a51891619..969d8cd7dc 100644--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx@@ -32,6 +32,12 @@ import { CINDY_MAKE_ENABLED, isCindyMakeSource } from '@cindy/maker-shared/cindyimport { CindyMakeSessionGate } from './CindyMakeSessionGate';import { dbToMakerAgentKind, normalizeDbAgentKind } from '../../../shared/agentKindConversion';import { useTranslation } from 'react-i18next';+import { buildSessionDeepLink } from '@/lib/deepLink';+import {+ buildErrorDiagnosisPrompt,+ prefillErrorDiagnosisDraft,+ type ErrorDiagnosisSource,+} from '@/lib/errorDiagnosisPrompt';import {isCodexResumeNotReadyProjectionError,type AgentInputReference,@@ -2234,6 +2240,19 @@ function CCAgentSessionContent({const handleViewBalance = useCallback(() => {navigate('/settings?tab=billing');}, [navigate]);+ // 诊断在本机新任务里进行;共享任务的访客读不到原任务,不提供。+ const canDiagnoseError = !readOnly && canNavigateSession && !isSharedTaskPeer(remoteDeviceId);+ const handleDiagnoseError = useCallback(+ (source: ErrorDiagnosisSource) => {+ if (!sessionId) return;+ const sessionUrl = buildSessionDeepLink(sessionId, {+ deviceId: rightSidebarDeviceLinkDeviceId,+ });+ prefillErrorDiagnosisDraft(buildErrorDiagnosisPrompt(t, sessionUrl, source));+ navigate('/cc-agent/new');+ },+ [navigate, rightSidebarDeviceLinkDeviceId, sessionId, t],+ );// live 错误的来源 provider 快照:错误出现时取值、任务切换时重置、错误存续期间// 切 provider 不跟随。语义与边界条件见 useLiveErrorSourceProvider 头注释。const liveErrorSourceProviderId = useLiveErrorSourceProvider(@@ -5331,6 +5350,7 @@ function CCAgentSessionContent({!readOnly && canNavigateSession && !isSharedTaskPeer(remoteDeviceId) ? handleForkStripEncrypted : undefined}forkStripEncryptedRunning={forkStripEncryptedRunning}+ onDiagnose={canDiagnoseError ? handleDiagnoseError : undefined}style={{ width: inputWidth }}/>))}@@ -5407,6 +5427,7 @@ function CCAgentSessionContent({!readOnly && canNavigateSession && !isSharedTaskPeer(remoteDeviceId) ? handleForkStripEncrypted : undefined}forkStripEncryptedRunning={forkStripEncryptedRunning}+ onDiagnose={canDiagnoseError ? handleDiagnoseError : undefined}style={{ width: inputWidth }}/>)}diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex 3ca709ca51..767d7b96f5 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -11193,6 +11193,9 @@"streamInterruptedNoRetry": "The model stream was interrupted. This is usually a temporary upstream issue. Try again in a little while.","networkShowRaw": "Error Details","networkHideRaw": "Hide Details",+ "diagnose": "Diagnose",+ "diagnoseTitle": "Diagnose this error in a new session",+ "diagnosePrompt": "Please diagnose this error: find the cause and tell me how to fix it.\n\nSession: {{sessionUrl}}\nError: {{message}}\nDetails:\n{{details}}\n\nIf you find it's a problem with Cindy itself, let me know so I can choose whether to file an issue with the Cindy team.","gatewayProxyTokenInvalid": "Cindy AI credentials are no longer valid. Click Retry. If it happens again, sign out and sign back in","gatewayProxyTokenInvalidNoRetry": "Cindy AI credentials are no longer valid. If it happens again, sign out and sign back in","modelAccessDenied": "The upstream account cannot access this model. Select another model or check its access with the provider",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex 69f7f5d090..5150a9f4a9 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -11149,6 +11149,9 @@"streamInterruptedNoRetry": "モデル出力が途中で中断されました。一時的な上流障害であることが多いので、しばらくしてから再試行してください","networkShowRaw": "エラーの詳細","networkHideRaw": "詳細を閉じる",+ "diagnose": "診断",+ "diagnoseTitle": "新しいセッションでこのエラーを診断",+ "diagnosePrompt": "このエラーを診断して、原因と解決方法を教えてください。\n\nエラーが起きたセッション:{{sessionUrl}}\nエラー表示:{{message}}\nエラー詳細:\n{{details}}\n\nCindy 自体の問題だと分かった場合は教えてください。Cindy チームに issue を提出するかどうかは私が選びます。","gatewayProxyTokenInvalid": "Cindy AI の認証情報が無効になりました。「再試行」をクリックしてください。繰り返す場合はサインアウトしてから再ログインしてください","gatewayProxyTokenInvalidNoRetry": "Cindy AI の認証情報が無効になりました。繰り返す場合はサインアウトしてから再ログインしてください","modelAccessDenied": "接続先のアカウントにはこのモデルへのアクセス権限がありません。別のモデルに切り替えるか、プロバイダーにアクセス権限を確認してください",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex db910d7101..bb36b0a8f9 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -11149,6 +11149,9 @@"streamInterruptedNoRetry": "모델 출력이 중간에 중단되었습니다. 보통은 일시적인 상위 서비스 장애입니다. 잠시 후 다시 시도해 주세요","networkShowRaw": "오류 상세 정보","networkHideRaw": "상세 정보 접기",+ "diagnose": "진단",+ "diagnoseTitle": "새 세션에서 이 오류 진단",+ "diagnosePrompt": "이 오류를 진단해서 원인과 해결 방법을 알려 주세요.\n\n오류가 발생한 세션: {{sessionUrl}}\n오류 메시지: {{message}}\n오류 상세:\n{{details}}\n\nCindy 자체의 문제로 확인되면 알려 주세요. Cindy 팀에 issue를 제출할지는 제가 선택할게요.","gatewayProxyTokenInvalid": "Cindy AI 자격 증명이 더 이상 유효하지 않습니다. 재시도를 클릭하세요. 반복되면 로그아웃 후 다시 로그인하세요","gatewayProxyTokenInvalidNoRetry": "Cindy AI 자격 증명이 더 이상 유효하지 않습니다. 반복되면 로그아웃 후 다시 로그인하세요","modelAccessDenied": "연결된 서비스 계정에 이 모델의 접근 권한이 없습니다. 다른 모델로 전환하거나 제공자에게 모델 접근 권한을 확인하세요",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 933d1ba01c..c3d2eea399 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -11149,6 +11149,9 @@"streamInterruptedNoRetry": "模型输出中途中断了。通常是上游暂时故障,请稍后重试。","networkShowRaw": "错误详情","networkHideRaw": "收起详情",+ "diagnose": "诊断",+ "diagnoseTitle": "在新任务中诊断这个错误",+ "diagnosePrompt": "请帮我诊断这个错误:找出原因,并告诉我怎么解决。\n\n出错任务:{{sessionUrl}}\n错误提示:{{message}}\n错误详情:\n{{details}}\n\n如果确认是 Cindy 本身的问题,请告诉我,我可以选择向 Cindy 团队提交 issue。","gatewayProxyTokenInvalid": "Cindy AI 凭据已失效。请点击「重试」。若仍失败,请退出后重新登录","gatewayProxyTokenInvalidNoRetry": "Cindy AI 凭据已失效。若后续仍失败,请退出后重新登录","modelAccessDenied": "当前上游账号无权访问此模型。请切换模型,或向供应商确认模型访问权限",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.jsonindex 6ef2d1d0b3..176d7f2ab1 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json@@ -11148,6 +11148,9 @@"streamInterruptedNoRetry": "模型輸出中途中斷了。通常是上游暫時故障,請稍後重試。","networkShowRaw": "錯誤詳情","networkHideRaw": "收起詳情",+ "diagnose": "診斷",+ "diagnoseTitle": "在新任務中診斷這個錯誤",+ "diagnosePrompt": "請幫我診斷這個錯誤:找出原因,並告訴我怎麼解決。\n\n出錯任務:{{sessionUrl}}\n錯誤提示:{{message}}\n錯誤詳情:\n{{details}}\n\n如果確認是 Cindy 本身的問題,請告訴我,我可以選擇向 Cindy 團隊提交 issue。","gatewayProxyTokenInvalid": "Cindy AI 憑據已失效。請點「重試」。若仍失敗,請退出後重新登入","gatewayProxyTokenInvalidNoRetry": "Cindy AI 憑據已失效。若後續仍失敗,請退出後重新登入","modelAccessDenied": "目前上游帳號無權存取此模型。請切換模型,或向供應商確認模型存取權限",diff --git a/apps/desktop/src/renderer/lib/errorDiagnosisPrompt.ts b/apps/desktop/src/renderer/lib/errorDiagnosisPrompt.tsnew file mode 100644index 0000000000..357b11e1a5--- /dev/null+++ b/apps/desktop/src/renderer/lib/errorDiagnosisPrompt.ts@@ -0,0 +1,40 @@+/**+ * errorDiagnosisPrompt — 错误卡「诊断」:把错误和出错任务链接预填进新任务草稿。+ *+ * 沿用 contacts / issue 预填入口的「不预创建会话」模式:只写 New Maker 草稿并复位+ * 工作区目标,调用方随后 navigate('/cc-agent/new')。不自动发送,用户确认后再发。+ */+import type { TFunction } from 'i18next';+import { redactSensitiveText } from '@cindy/maker-shared/error-redaction';+import { NEW_MAKER_DRAFT_KEY } from '@/features/cc-agent/newMakerDraftKeys';+import { plainTextToTiptapDoc, saveDraft } from '@/lib/composerDraftStore';+import { resetDraftWorkspaceTargets } from '@/state/newMakerDraft';++export interface ErrorDiagnosisSource {+ /** 卡片上给用户看的错误提示。 */+ message: string;+ /** 展开详情里的原始错误。 */+ details: string;+ reason?: string | null;+}++export function buildErrorDiagnosisPrompt(+ t: TFunction,+ sessionUrl: string,+ source: ErrorDiagnosisSource,+): string {+ const details = redactSensitiveText(source.details).trim();+ return t('chat.errorBanner.diagnosePrompt', {+ sessionUrl,+ message: redactSensitiveText(source.message).trim(),+ details: source.reason ? `${details}\nreason: ${source.reason}` : details,+ });+}++export function prefillErrorDiagnosisDraft(prompt: string): void {+ saveDraft(NEW_MAKER_DRAFT_KEY, {+ text: plainTextToTiptapDoc(prompt),+ attachments: [],+ });+ resetDraftWorkspaceTargets();+}diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsxindex da7ec4109a..f6aa5a9429 100644--- a/apps/mobile/app/sessions/[sessionId].tsx+++ b/apps/mobile/app/sessions/[sessionId].tsx@@ -422,6 +422,7 @@ import {} from '@/session/queueEditLifecycle';import { findErrorTailClientId, isContinuationQueueItem, resolveSessionTailBanner } from '@/session/sessionTailBannerModel';import { SessionTailBanner } from '@/session/SessionTailBanner';+import { buildErrorDiagnosisPrompt, type ErrorDiagnosisSource } from '@/session/errorDiagnosisPrompt';import { useHistoryRecoveryNavigation } from '@/session/useHistoryRecoveryNavigation';import { canOfferCodexHistoryRecovery } from '@cindy/maker-shared/error-redaction';import {@@ -618,6 +619,7 @@ import {} from '@/session/messageScroll';import { countMobileRenderItemDiffs } from '@/session/messagePresentation';import {+ buildMobileSessionDeepLink,buildMobileSessionMessageDeepLink,parseSessionDeepLinkUrl,resolveSessionLinkDeviceId,@@ -3076,6 +3078,20 @@ function SessionScreenContent() {guardedPush({ pathname: '/sessions/new', params: { deviceId, deviceName } });});}, [deviceId, deviceName, guardedPush, queueDrawerNavigation]);+ // 诊断任务建在出错任务所在的电脑上,链接不带 device;共享任务的访客读不到原任务,不提供。+ const canDiagnoseError = !!deviceId && !!sessionId && !isSharedTaskPeer(deviceId);+ const handleDiagnoseError = useCallback((source: ErrorDiagnosisSource) => {+ if (!deviceId || !sessionId) return;+ guardedPush({+ pathname: '/sessions/new',+ params: {+ deviceId,+ deviceName,+ deviceExplicit: '1',+ draft: buildErrorDiagnosisPrompt(t, buildMobileSessionDeepLink(sessionId), source),+ },+ });+ }, [deviceId, deviceName, guardedPush, sessionId, t]);const handleComposerInputPressIn = useCallback(() => {if (voiceRecordingActiveRef.current || voiceState === 'listening') {// Tapping the input to stop dictation means the user wants to type.@@ -10186,6 +10202,7 @@ function SessionScreenContent() {onRecoverHistory={canRecoverHistory ? () => void recoverReadableHistory() : undefined}onContinue={() => void continueTailBanner()}onDismiss={dismissTailBanner}+ onDiagnose={canDiagnoseError ? handleDiagnoseError : undefined}state={tailBannerState}/>) : null}@@ -10211,6 +10228,7 @@ function SessionScreenContent() {onCancelUsageLimitWait={cancelUsageLimitWait}onResume={resumeQueue}onRetryError={retryQueueError}+ onDiagnose={canDiagnoseError ? handleDiagnoseError : undefined}projection={inputProjection}readOnlyReason={queueAvailabilityReason}/>diff --git a/apps/mobile/src/__tests__/AgentErrorLocalization.test.tsx b/apps/mobile/src/__tests__/AgentErrorLocalization.test.tsxindex c4e2745967..956a666517 100644--- a/apps/mobile/src/__tests__/AgentErrorLocalization.test.tsx+++ b/apps/mobile/src/__tests__/AgentErrorLocalization.test.tsx@@ -13,6 +13,7 @@ import { AgentErrorDetails } from '@/session/AgentErrorDetails';import { resolveSessionTailBanner } from '@/session/sessionTailBannerModel';import { normalizeRemoteMessages } from '@/session/messageNormalize';import type { InputProjection, RemoteMessage } from '@/session/types';+import { buildErrorDiagnosisPrompt } from '@/session/errorDiagnosisPrompt';vi.mock('react-native', async () => {const { createElement } = await import('react');@@ -23,7 +24,7 @@ vi.mock('react-native', async () => {StyleSheet: { create: (s: unknown) => s, hairlineWidth: 1 } };});vi.mock('@/components/AppText', async () => ({ Text: (await import('react-native')).Text }));-vi.mock('lucide-react-native', () => ({ Pause: () => null, Play: () => null, CircleAlert: () => null, Split: () => null, X: () => null, ChevronRight: () => null, ChevronDown: () => null }));+vi.mock('lucide-react-native', () => ({ Pause: () => null, Play: () => null, CircleAlert: () => null, Split: () => null, X: () => null, ChevronRight: () => null, ChevronDown: () => null, Stethoscope: () => null }));vi.mock('@/theme', async () => {const tokens = await import('@/theme/tokens');return { ...tokens, useTheme: () => ({ colors: tokens.lightColors }),@@ -43,6 +44,24 @@ const clickText = (text: string) => {expect(button).toBeTruthy(); button!.click();};+// 诊断入口只在展开详情后出现;预填给新任务的提示带出错任务链接,且与详情同样脱敏。+it('offers diagnosis after expanding details with a redacted prompt for the failed session', async () => {+ await i18n.changeLanguage('en');+ const onDiagnose = vi.fn();+ const error = 'Unexpected provider failure; api_key=private-test-value';+ await act(async () => root.render(<SessionTailBanner+ state={{ kind: 'error-tail', text: 'Reply failed', rawError: error, reason: 'tool_use_loop_detected', clientId: 'e', continueKind: 'error', retryable: true }}+ onContinue={vi.fn()} onDismiss={vi.fn()} onDiagnose={onDiagnose} />));+ expect(host.querySelector('[data-testid="agentError.diagnose"]')).toBeNull();+ await act(async () => clickText(i18n.t('session.tail.showErrorDetails')));+ await act(async () => host.querySelector<HTMLButtonElement>('[data-testid="agentError.diagnose"]')!.click());+ const prompt = buildErrorDiagnosisPrompt(i18n.t, 'cindy://session/s1', onDiagnose.mock.calls[0][0]);+ expect(prompt).toContain('cindy://session/s1');+ expect(prompt).toContain('Reply failed');+ expect(prompt).toContain('reason: tool_use_loop_detected');+ expect(prompt).not.toContain('private-test-value');+});+describe.each(SUPPORTED_LOCALES)('mobile errors in %s', locale => {it.each(['live', 'tail'] as const)('offers explicit %s recovery without automatically retrying', async surface => {await i18n.changeLanguage(locale);diff --git a/apps/mobile/src/__tests__/sessionTailBannerModel.test.ts b/apps/mobile/src/__tests__/sessionTailBannerModel.test.tsindex 966518f719..cf88de48f8 100644--- a/apps/mobile/src/__tests__/sessionTailBannerModel.test.ts+++ b/apps/mobile/src/__tests__/sessionTailBannerModel.test.ts@@ -57,6 +57,7 @@ describe('resolveSessionTailBanner — error-tail', () => {clientId: 'e1',text: i18n.t('session.tail.replyFailed'),rawError: 'process exited unexpectedly',+ reason: null,summaryKey: 'session.tail.replyFailed',continueKind: 'error',retryable: true,diff --git a/apps/mobile/src/i18n/locales/en/session.json b/apps/mobile/src/i18n/locales/en/session.jsonindex 3f81ff24f6..915462f9b3 100644--- a/apps/mobile/src/i18n/locales/en/session.json+++ b/apps/mobile/src/i18n/locales/en/session.json@@ -509,6 +509,9 @@"replyFailed": "Could not complete the reply","showErrorDetails": "Error Details","hideErrorDetails": "Hide Details",+ "diagnose": "Diagnose",+ "diagnoseHint": "Diagnose this error in a new session",+ "diagnosePrompt": "Please diagnose this error: find the cause and tell me how to fix it.\n\nSession: {{sessionUrl}}\nError: {{message}}\nDetails:\n{{details}}\n\nIf you find it's a problem with Cindy itself, let me know so I can choose whether to file an issue with the Cindy team.","interrupted": "The app exited mid-task, so it was interrupted.","continueTask": "Continue Task","retry": "Retry",diff --git a/apps/mobile/src/i18n/locales/ja/session.json b/apps/mobile/src/i18n/locales/ja/session.jsonindex 2e0bc4c5bb..a1dbdff563 100644--- a/apps/mobile/src/i18n/locales/ja/session.json+++ b/apps/mobile/src/i18n/locales/ja/session.json@@ -509,6 +509,9 @@"replyFailed": "返信を完了できませんでした","showErrorDetails": "エラーの詳細","hideErrorDetails": "詳細を閉じる",+ "diagnose": "診断",+ "diagnoseHint": "新しいセッションでこのエラーを診断",+ "diagnosePrompt": "このエラーを診断して、原因と解決方法を教えてください。\n\nエラーが起きたセッション:{{sessionUrl}}\nエラー表示:{{message}}\nエラー詳細:\n{{details}}\n\nCindy 自体の問題だと分かった場合は教えてください。Cindy チームに issue を提出するかどうかは私が選びます。","interrupted": "タスクの実行中にアプリが終了したため、中断されました。","continueTask": "タスクを続ける","retry": "再試行",diff --git a/apps/mobile/src/i18n/locales/ko/session.json b/apps/mobile/src/i18n/locales/ko/session.jsonindex cae2b5c0ef..20ef1b5e2d 100644--- a/apps/mobile/src/i18n/locales/ko/session.json+++ b/apps/mobile/src/i18n/locales/ko/session.json@@ -505,6 +505,9 @@"replyFailed": "답변을 완료하지 못했습니다","showErrorDetails": "오류 상세 정보","hideErrorDetails": "상세 정보 접기",+ "diagnose": "진단",+ "diagnoseHint": "새 세션에서 이 오류 진단",+ "diagnosePrompt": "이 오류를 진단해서 원인과 해결 방법을 알려 주세요.\n\n오류가 발생한 세션: {{sessionUrl}}\n오류 메시지: {{message}}\n오류 상세:\n{{details}}\n\nCindy 자체의 문제로 확인되면 알려 주세요. Cindy 팀에 issue를 제출할지는 제가 선택할게요.","interrupted": "작업 실행 도중 앱이 종료되어 중단되었습니다.","continueTask": "작업 계속","retry": "다시 시도",diff --git a/apps/mobile/src/i18n/locales/zh-CN/session.json b/apps/mobile/src/i18n/locales/zh-CN/session.jsonindex 60a732272c..6dd1e85bc1 100644--- a/apps/mobile/src/i18n/locales/zh-CN/session.json+++ b/apps/mobile/src/i18n/locales/zh-CN/session.json@@ -505,6 +505,9 @@"replyFailed": "回复未完成","showErrorDetails": "错误详情","hideErrorDetails": "收起详情",+ "diagnose": "诊断",+ "diagnoseHint": "在新任务中诊断这个错误",+ "diagnosePrompt": "请帮我诊断这个错误:找出原因,并告诉我怎么解决。\n\n出错任务:{{sessionUrl}}\n错误提示:{{message}}\n错误详情:\n{{details}}\n\n如果确认是 Cindy 本身的问题,请告诉我,我可以选择向 Cindy 团队提交 issue。","interrupted": "任务执行到一半时应用退出,已被中断。","continueTask": "继续任务","retry": "重试",diff --git a/apps/mobile/src/i18n/locales/zh-TW/session.json b/apps/mobile/src/i18n/locales/zh-TW/session.jsonindex 8c42012c0a..fc688d03a8 100644--- a/apps/mobile/src/i18n/locales/zh-TW/session.json+++ b/apps/mobile/src/i18n/locales/zh-TW/session.json@@ -509,6 +509,9 @@"replyFailed": "回覆未完成","showErrorDetails": "錯誤詳情","hideErrorDetails": "收起詳情",+ "diagnose": "診斷",+ "diagnoseHint": "在新任務中診斷這個錯誤",+ "diagnosePrompt": "請幫我診斷這個錯誤:找出原因,並告訴我怎麼解決。\n\n出錯任務:{{sessionUrl}}\n錯誤提示:{{message}}\n錯誤詳情:\n{{details}}\n\n如果確認是 Cindy 本身的問題,請告訴我,我可以選擇向 Cindy 團隊提交 issue。","interrupted": "任務執行到一半時應用退出,已被中斷。","continueTask": "繼續任務","retry": "重試",diff --git a/apps/mobile/src/session/AgentErrorDetails.tsx b/apps/mobile/src/session/AgentErrorDetails.tsxindex 87a31695f1..4c72eb354a 100644--- a/apps/mobile/src/session/AgentErrorDetails.tsx+++ b/apps/mobile/src/session/AgentErrorDetails.tsx@@ -1,9 +1,10 @@import { useEffect, useState, type ReactNode } from 'react';-import { ChevronDown, ChevronRight } from 'lucide-react-native';+import { ChevronDown, ChevronRight, Stethoscope } from 'lucide-react-native';import { Pressable, StyleSheet, View } from 'react-native';import { useTranslation } from 'react-i18next';import { redactSensitiveText } from '@cindy/maker-shared/error-redaction';import { Text } from '@/components/AppText';+import { ErrorNoticeAction } from '@/components/ErrorNotice';import {iconSize,iconStroke,@@ -18,9 +19,12 @@ import { lineHeight, radius, spacing, typeScale } from '@/theme/tokens';export function AgentErrorDetails({message,actions,+ onDiagnose,}: {message: string;actions?: ReactNode;+ /** Offered only after the user expands details; the caller decides where diagnosis happens. */+ onDiagnose?: () => void;}) {const { t } = useTranslation();const styles = useThemedStyles(makeStyles);@@ -63,6 +67,21 @@ export function AgentErrorDetails({)}</Text></Pressable>+ {expanded && onDiagnose ? (+ <ErrorNoticeAction+ label={t('session.tail.diagnose')}+ hint={t('session.tail.diagnoseHint')}+ icon={+ <Stethoscope+ color={colors.textPrimary}+ size={iconSize.sm}+ strokeWidth={iconStroke.regular}+ />+ }+ onPress={onDiagnose}+ testID="agentError.diagnose"+ />+ ) : null}</View>{expanded ? (<Text selectable style={styles.detail}>diff --git a/apps/mobile/src/session/InlineQueueSection.tsx b/apps/mobile/src/session/InlineQueueSection.tsxindex ab43219161..8bcbdc3785 100644--- a/apps/mobile/src/session/InlineQueueSection.tsx+++ b/apps/mobile/src/session/InlineQueueSection.tsx@@ -27,6 +27,7 @@ import { Text } from '@/components/AppText';import { Pause, Play } from 'lucide-react-native';import { describeAgentAuthError } from '@/device-link/remoteStatus';import type { InputProjection } from '@/session/types';+import type { ErrorDiagnosisSource } from '@/session/errorDiagnosisPrompt';import { inputProjectionErrorI18nKey } from '@/session/inputProjectionError';import { localizeAgentError, localizeUnclassifiedAgentError, requiresAgentErrorConfigurationChange } from '@/session/agentErrorI18n';import {@@ -51,6 +52,8 @@ export interface InlineQueueSectionProps {onClearError(): void;/** 取消账号限额重置后的自动继续(只在投影带 usageLimitWait 时出现)。 */onCancelUsageLimitWait?(): void;+ /** 展开详情后的「诊断」:上层带着错误与出错任务去新任务里排查。 */+ onDiagnose?(error: ErrorDiagnosisSource): void;}export function InlineQueueSection({@@ -63,6 +66,7 @@ export function InlineQueueSection({onRetryError,onClearError,onCancelUsageLimitWait,+ onDiagnose,}: InlineQueueSectionProps) {const styles = useThemedStyles(makeStyles);const { colors } = useTheme();@@ -112,7 +116,13 @@ export function InlineQueueSection({dismissBusy={busy}dismissHint={errorDisabledReason ?? undefined}>- <AgentErrorDetails message={projection.error} actions={<>+ <AgentErrorDetails message={projection.error} onDiagnose={onDiagnose+ ? () => onDiagnose({+ message: projectionError ?? '',+ details: projection.error ?? '',+ reason: projection.errorReason,+ })+ : undefined} actions={<>{retryable ? <ErrorNoticeActionprimarydisabled={!!retryDisabledReason}diff --git a/apps/mobile/src/session/SessionTailBanner.tsx b/apps/mobile/src/session/SessionTailBanner.tsxindex e2861e0460..f2604cf4d7 100644--- a/apps/mobile/src/session/SessionTailBanner.tsx+++ b/apps/mobile/src/session/SessionTailBanner.tsx@@ -15,6 +15,7 @@ import { ReadableHistoryRecovery } from './ReadableHistoryRecovery';import { StyleSheet, View } from 'react-native';import { useTranslation } from 'react-i18next';import type { SessionTailBannerState } from '@/session/sessionTailBannerModel';+import type { ErrorDiagnosisSource } from '@/session/errorDiagnosisPrompt';import { spacing } from '@/theme/tokens';@@ -22,6 +23,8 @@ export interface SessionTailBannerProps {state: NonNullable<SessionTailBannerState>;busy?: boolean;onRecoverHistory?: () => void;+ /** 展开详情后的「诊断」:上层带着错误与出错任务去新任务里排查。 */+ onDiagnose?: (error: ErrorDiagnosisSource) => void;onContinue(): void;onDismiss(): void;}@@ -32,6 +35,7 @@ export function SessionTailBanner({onContinue,onDismiss,onRecoverHistory,+ onDiagnose,}: SessionTailBannerProps) {const { t } = useTranslation();const isInterrupted =@@ -82,7 +86,15 @@ export function SessionTailBanner({dismissBusy={busy}>{state.kind === 'error-tail' && state.rawError && !isInterrupted ? (- <AgentErrorDetails message={state.rawError} actions={actions} />+ <AgentErrorDetails+ message={state.rawError}+ actions={actions}+ onDiagnose={+ onDiagnose+ ? () => onDiagnose({ message: text, details: state.rawError ?? '', reason: state.reason })+ : undefined+ }+ />) : (<View style={styles.actions}>{actions}</View>)}diff --git a/apps/mobile/src/session/errorDiagnosisPrompt.ts b/apps/mobile/src/session/errorDiagnosisPrompt.tsnew file mode 100644index 0000000000..5184affbe6--- /dev/null+++ b/apps/mobile/src/session/errorDiagnosisPrompt.ts@@ -0,0 +1,27 @@+/**+ * 错误卡「诊断」的预填提示:与桌面 lib/errorDiagnosisPrompt 同形,经 /sessions/new 的+ * draft 参数填进新任务输入框,不自动发送。+ */+import type { TFunction } from "i18next";+import { redactSensitiveText } from "@cindy/maker-shared/error-redaction";++export interface ErrorDiagnosisSource {+ /** 卡片上给用户看的错误提示。 */+ message: string;+ /** 展开详情里的原始错误。 */+ details: string;+ reason?: string | null;+}++export function buildErrorDiagnosisPrompt(+ t: TFunction,+ sessionUrl: string,+ source: ErrorDiagnosisSource,+): string {+ const details = redactSensitiveText(source.details).trim();+ return t("session.tail.diagnosePrompt", {+ sessionUrl,+ message: redactSensitiveText(source.message).trim(),+ details: source.reason ? `${details}\nreason: ${source.reason}` : details,+ });+}diff --git a/apps/mobile/src/session/sessionTailBannerModel.ts b/apps/mobile/src/session/sessionTailBannerModel.tsindex 08b1cdb731..c4366ef484 100644--- a/apps/mobile/src/session/sessionTailBannerModel.ts+++ b/apps/mobile/src/session/sessionTailBannerModel.ts@@ -45,6 +45,8 @@ export interface SessionTailErrorBanner {/** 本地化展示文案;未知错误的技术原文放入 rawError。 */text: string;rawError?: string;+ /** 错误行的稳定 reason key,供诊断提示带上。 */+ reason?: string | null;summaryKey?: string;/** 主按钮语义:中断标记行 →「继续任务」;普通失败行 →「重试」。 */continueKind: 'interrupted' | 'error';@@ -111,6 +113,7 @@ export function resolveSessionTailBanner(input: ResolveSessionTailBannerInput):clientId: tail.clientId,text: nonRetryableGuidance ?? agentErrorGuidance ?? localizeUnclassifiedAgentError(tail.text, input.session?.source),rawError: tail.text,+ reason: tail.reason,...(!nonRetryableGuidance && !agentErrorGuidance ? { summaryKey: unclassifiedAgentErrorI18nKey(tail.text, input.session?.source) } : {}),continueKind: tail.reason === APP_EXIT_INTERRUPTED_REASON ? 'interrupted' : 'error',retryable: nonRetryableGuidance === null && !requiresAgentErrorConfigurationChange(tail.text),