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: 诊断预填在保留未发送草稿时一并保留工作区目标

Dash2cb08d8f1a95
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 a4692a28be..0f19b6c287 100644
--- a/apps/desktop/src/renderer/components/chat/__tests__/ErrorLocalization.test.tsx
+++ b/apps/desktop/src/renderer/components/chat/__tests__/ErrorLocalization.test.tsx
@@ -22,6 +22,7 @@ import { remoteErrorMessageForBanner } from '@/lib/makerChatStore';
import { buildErrorDiagnosisPrompt, prefillErrorDiagnosisDraft } from '@/lib/errorDiagnosisPrompt';
import { clearDraft, getDraft, plainTextToTiptapDoc, saveDraft } from '@/lib/composerDraftStore';
import { NEW_MAKER_DRAFT_KEY } from '@/features/cc-agent/newMakerDraftKeys';
+import { getDraft as getNewMakerDraft, patchDraft } from '@/state/newMakerDraft';
const locales = { en, 'zh-CN': zhCN, 'zh-TW': zhTW, ja, ko };
const raw = JSON.stringify({ error: {
@@ -50,6 +51,7 @@ it('offers diagnosis after expanding details with a redacted prompt for the fail
// 新建任务页已有未发送内容时,诊断预填只追加,不能丢掉用户的文字与附件。
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;
+ patchDraft({ workingDir: '/tmp/my-project', extraDirs: ['/tmp/extra'] });
saveDraft(NEW_MAKER_DRAFT_KEY, { text: plainTextToTiptapDoc('我写到一半的内容'), attachments: [attachment], pendingGhostId: 'plugin-1' });
prefillErrorDiagnosisDraft('请帮我诊断这个错误');
const draft = getDraft(NEW_MAKER_DRAFT_KEY)!;
@@ -58,6 +60,13 @@ it('appends the diagnosis prompt to an unsent new-task draft instead of replacin
expect(text.indexOf('请帮我诊断这个错误')).toBeGreaterThan(text.indexOf('我写到一半的内容'));
expect(draft.attachments).toHaveLength(1);
expect(draft.pendingGhostId).toBe('plugin-1');
+ expect(getNewMakerDraft().workingDir).toBe('/tmp/my-project');
+ expect(getNewMakerDraft().extraDirs).toEqual(['/tmp/extra']);
+ clearDraft(NEW_MAKER_DRAFT_KEY);
+ // 空草稿则复位工作区目标,残留的目录授权不带进诊断任务。
+ prefillErrorDiagnosisDraft('请帮我诊断这个错误');
+ expect(getNewMakerDraft().extraDirs).toEqual([]);
+ expect(getNewMakerDraft().workingDir).toBeNull();
clearDraft(NEW_MAKER_DRAFT_KEY);
});
diff --git a/apps/desktop/src/renderer/lib/errorDiagnosisPrompt.ts b/apps/desktop/src/renderer/lib/errorDiagnosisPrompt.ts
index ed41229170..2c34998f92 100644
--- a/apps/desktop/src/renderer/lib/errorDiagnosisPrompt.ts
+++ b/apps/desktop/src/renderer/lib/errorDiagnosisPrompt.ts
@@ -33,7 +33,8 @@ export function buildErrorDiagnosisPrompt(
/**
* 新建任务页已有未发送的内容时不覆盖:以原草稿为底整体保留(附件、浏览器评论、插件交接、
- * 旧版引用等全部字段),只把诊断提示追加在正文之后。草稿为空时与其他预填入口一致,整体写入。
+ * 旧版引用、工作区目标等全部内容),只把诊断提示追加在正文之后。草稿为空时与其他预填入口一致,
+ * 整体写入并复位工作区目标(避免残留的远程目标或额外授权目录带进诊断任务)。
*/
export function prefillErrorDiagnosisDraft(prompt: string): void {
const existing = getDraft(NEW_MAKER_DRAFT_KEY);
@@ -44,14 +45,14 @@ export function prefillErrorDiagnosisDraft(prompt: string): void {
(existing?.attachments.length ?? 0) > 0 ||
(existing?.browserComments?.length ?? 0) > 0 ||
(existing?.quotes?.length ?? 0) > 0;
- saveDraft(
- NEW_MAKER_DRAFT_KEY,
- existing && hasUnsent
- ? {
- ...existing,
- text: { ...added, content: [...existingContent, ...(added.content ?? [])] },
- }
- : { text: added, attachments: [] },
- );
+ if (existing && hasUnsent) {
+ // 用户自己的未发送草稿:工作区目标(项目、远程电脑、额外授权目录)也属于它,原样保留。
+ saveDraft(NEW_MAKER_DRAFT_KEY, {
+ ...existing,
+ text: { ...added, content: [...existingContent, ...(added.content ?? [])] },
+ });
+ return;
+ }
+ saveDraft(NEW_MAKER_DRAFT_KEY, { text: added, attachments: [] });
resetDraftWorkspaceTargets();
}