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: 诊断预填不覆盖新建任务页已有的未发送草稿

Dash4a2bd9932d99
diff --git a/apps/desktop/src/renderer/components/chat/__tests__/ErrorLocalization.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/ErrorLocalization.test.tsx
index 5cc6026df8..722c810613 100644
--- a/apps/desktop/src/renderer/components/chat/__tests__/ErrorLocalization.test.tsx
+++ b/apps/desktop/src/renderer/components/chat/__tests__/ErrorLocalization.test.tsx
@@ -19,7 +19,9 @@ import { ErrorBanner } from '../ErrorBanner';
import { ErrorMessageCard } from '../ErrorMessageCard';
import { ErrorTailErrorBanner } from '../InterruptedTurnBanner';
import { remoteErrorMessageForBanner } from '@/lib/makerChatStore';
-import { buildErrorDiagnosisPrompt } from '@/lib/errorDiagnosisPrompt';
+import { buildErrorDiagnosisPrompt, prefillErrorDiagnosisDraft } from '@/lib/errorDiagnosisPrompt';
+import { clearDraft, getDraft, plainTextToTiptapDoc, saveDraft } from '@/lib/composerDraftStore';
+import { NEW_MAKER_DRAFT_KEY } from '@/features/cc-agent/newMakerDraftKeys';
const locales = { en, 'zh-CN': zhCN, 'zh-TW': zhTW, ja, ko };
const raw = JSON.stringify({ error: {
@@ -45,6 +47,19 @@ it('offers diagnosis after expanding details with a redacted prompt for the fail
expect(prompt).not.toContain('private-test-value');
});
+// 新建任务页已有未发送内容时,诊断预填只追加,不能丢掉用户的文字与附件。
+it('appends the diagnosis prompt to an unsent new-task draft instead of replacing it', () => {
+ const attachment = { id: 'a1', name: 'note.txt', path: '/tmp/note.txt' } as never;
+ saveDraft(NEW_MAKER_DRAFT_KEY, { text: plainTextToTiptapDoc('我写到一半的内容'), attachments: [attachment] });
+ prefillErrorDiagnosisDraft('请帮我诊断这个错误');
+ const draft = getDraft(NEW_MAKER_DRAFT_KEY)!;
+ const text = JSON.stringify(draft.text);
+ expect(text.indexOf('我写到一半的内容')).toBeGreaterThanOrEqual(0);
+ expect(text.indexOf('请帮我诊断这个错误')).toBeGreaterThan(text.indexOf('我写到一半的内容'));
+ expect(draft.attachments).toHaveLength(1);
+ clearDraft(NEW_MAKER_DRAFT_KEY);
+});
+
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/lib/errorDiagnosisPrompt.ts b/apps/desktop/src/renderer/lib/errorDiagnosisPrompt.ts
index 357b11e1a5..c6ccf553be 100644
--- a/apps/desktop/src/renderer/lib/errorDiagnosisPrompt.ts
+++ b/apps/desktop/src/renderer/lib/errorDiagnosisPrompt.ts
@@ -7,7 +7,7 @@
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 { getDraft, plainTextToTiptapDoc, saveDraft } from '@/lib/composerDraftStore';
import { resetDraftWorkspaceTargets } from '@/state/newMakerDraft';
export interface ErrorDiagnosisSource {
@@ -31,10 +31,20 @@ export function buildErrorDiagnosisPrompt(
});
}
+/**
+ * 新建任务页已有未发送的内容时不覆盖:诊断提示追加在原文之后,附件与浏览器评论原样保留。
+ * 草稿为空时与其他预填入口一致,整体写入。
+ */
export function prefillErrorDiagnosisDraft(prompt: string): void {
+ const existing = getDraft(NEW_MAKER_DRAFT_KEY);
+ const added = plainTextToTiptapDoc(prompt);
+ const existingContent = existing?.text?.content ?? [];
saveDraft(NEW_MAKER_DRAFT_KEY, {
- text: plainTextToTiptapDoc(prompt),
- attachments: [],
+ ...(existing?.browserComments?.length ? { browserComments: existing.browserComments } : {}),
+ text: existingContent.length > 0
+ ? { ...added, content: [...existingContent, ...(added.content ?? [])] }
+ : added,
+ attachments: existing?.attachments ?? [],
});
resetDraftWorkspaceTargets();
}