diff --git a/apps/desktop/src/renderer/pages/CommandsPage.tsx b/apps/desktop/src/renderer/pages/CommandsPage.tsx index 8ca9522..55cc17a 100644 --- a/apps/desktop/src/renderer/pages/CommandsPage.tsx +++ b/apps/desktop/src/renderer/pages/CommandsPage.tsx @@ -35,6 +35,7 @@ import { COMMAND_NONE, commandSelection, commandTestRequest, + isInstructionInUse, llmActionLabelKey, resolveCommandPipeline, withoutHidden, @@ -180,15 +181,17 @@ export function CommandsPage(): React.ReactElement { // 한 건 삭제는 확인 대신 "삭제했습니다 · 되돌리기" — 알림이 닫힐 때 실제로 지운다. const handleDelete = (inst: CustomInstruction) => { - const wasSelected = config?.defaultLLMAction === 'custom' && config.activeInstructionId === inst.id remove({ id: inst.id, message: t('tools.commands.deleted', { name: inst.name }), commit: async () => { const res = await window.electronAPI.instruction.delete({ id: inst.id }) if (!res.success) return false - // 쓰던 명령을 지웠으면 원문 그대로 넣기로 돌린다(예전 동작 유지) - if (wasSelected) await window.electronAPI.config.set({ key: 'defaultLLMAction', value: 'none' }) + // 지금도 쓰이는 명령을 지웠으면 원문 그대로 넣기로 돌린다 — 확정 시점의 설정으로 판단한다 + const latest = await window.electronAPI.config.getAll() + if (latest.success && isInstructionInUse(latest.data, inst.id)) { + await window.electronAPI.config.set({ key: 'defaultLLMAction', value: 'none' }) + } return true }, onCommitted: () => void loadData(), diff --git a/apps/desktop/src/renderer/pages/tools/tools-model.ts b/apps/desktop/src/renderer/pages/tools/tools-model.ts index 59c2b09..af9642a 100644 --- a/apps/desktop/src/renderer/pages/tools/tools-model.ts +++ b/apps/desktop/src/renderer/pages/tools/tools-model.ts @@ -55,6 +55,17 @@ export function commandSelection(pipeline: CommandPip return '' } +/** + * 지운 명령이 지금도 받아쓰기에 쓰이는가 — 삭제 확정(되돌리기 알림이 닫힐 때) 시점의 설정으로 판단한다. + * 삭제를 누른 순간 값으로 판단하면, 그사이 사용자가 고른 다른 명령을 '원문 그대로'로 덮었다. + */ +export function isInstructionInUse( + config: { defaultLLMAction?: unknown; activeInstructionId?: unknown } | null | undefined, + instructionId: string, +): boolean { + return config?.defaultLLMAction === 'custom' && config.activeInstructionId === instructionId +} + /** 일반 후처리 액션 이름 */ export function llmActionLabelKey(action: Exclude): TranslationKey { switch (action) { diff --git a/apps/desktop/tests/unit/renderer-tools-model.test.ts b/apps/desktop/tests/unit/renderer-tools-model.test.ts index 43858bf..ecfd538 100644 --- a/apps/desktop/tests/unit/renderer-tools-model.test.ts +++ b/apps/desktop/tests/unit/renderer-tools-model.test.ts @@ -15,6 +15,7 @@ import { llmActionLabelKey, resolveCommandPipeline, withoutHidden, + isInstructionInUse, } from '../../src/renderer/pages/tools/tools-model' const polish = { id: 'i1', name: '정중하게', prompt: '{{text}} 를 정중하게' } @@ -95,3 +96,13 @@ describe('withoutHidden / documentIndexLabelKey', () => { expect(documentIndexLabelKey({ id: 'd', indexed: true }, null)).toBe('rag.indexed') }) }) + +describe('isInstructionInUse — 명령 삭제 확정 시점의 설정으로 판단', () => { + it('지운 명령이 아직 선택돼 있을 때만 true', () => { + expect(isInstructionInUse({ defaultLLMAction: 'custom', activeInstructionId: 'x' }, 'x')).toBe(true) + // 되돌리기 알림 동안 다른 명령을 골랐다 — 덮으면 안 된다 + expect(isInstructionInUse({ defaultLLMAction: 'custom', activeInstructionId: 'y' }, 'x')).toBe(false) + expect(isInstructionInUse({ defaultLLMAction: 'refine', activeInstructionId: 'x' }, 'x')).toBe(false) + expect(isInstructionInUse(null, 'x')).toBe(false) + }) +})