From f8ec4621cbeb423db87e623d2d4c46d0d441d7a4 Mon Sep 17 00:00:00 2001 From: whitelonng Date: Sun, 14 Jun 2026 14:40:14 +0800 Subject: [PATCH 1/6] feat(memory): add dedicated memory management panel in settings Kun's runtime already had a complete memory store (FileMemoryStore + HTTP routes /v1/memory + agent-loop injection + 3 tools), but the GUI only exposed a read-only, truncated-to-8 view buried inside the Agents section. This adds a first-class Memory section to Settings with full CRUD: create, edit content/tags/confidence, disable, delete, plus diagnostics (active count, tombstone count, enabled state, last injected IDs) and a scope filter (all/user/workspace/project). - Frontend only; no runtime/kun changes. - Added createMemory + getMemoryDiagnostics to the AgentProvider interface and KunRuntimeProvider (POST route already existed). - New SettingsSidebar entry (BrainCircuit icon). - 30 i18n keys added to en/zh settings.json. - The existing read-only memory block in Agents section is left intact for backward compatibility. --- src/renderer/src/agent/kun-runtime.ts | 22 ++ src/renderer/src/agent/types.ts | 10 + .../src/components/SettingsSidebar.tsx | 8 +- src/renderer/src/components/SettingsView.tsx | 63 +++- .../components/settings-section-memory.tsx | 324 ++++++++++++++++++ .../src/components/settings-sections.tsx | 1 + .../src/components/use-settings-gui-update.ts | 2 +- src/renderer/src/locales/en/settings.json | 32 +- src/renderer/src/locales/zh/settings.json | 32 +- 9 files changed, 487 insertions(+), 7 deletions(-) create mode 100644 src/renderer/src/components/settings-section-memory.tsx diff --git a/src/renderer/src/agent/kun-runtime.ts b/src/renderer/src/agent/kun-runtime.ts index 71ad9883..71368950 100644 --- a/src/renderer/src/agent/kun-runtime.ts +++ b/src/renderer/src/agent/kun-runtime.ts @@ -646,6 +646,28 @@ export class KunRuntimeProvider implements AgentProvider { ).memories ?? [] } + async createMemory(input: { + content: string + scope?: 'user' | 'workspace' | 'project' + workspace?: string + project?: string + tags?: string[] + confidence?: number + }): Promise { + const response = await rendererRuntimeClient.runtimeRequest( + KUN_MEMORY_PATH, + 'POST', + JSON.stringify(input) + ) + if (!response.ok) { + throw runtimeErrorToError(readRuntimeError(response.body, 'failed to create memory')) + } + return readRuntimeJson<{ memory: CoreMemoryRecordJson }>( + response.body, + 'runtime returned an invalid memory response' + ).memory + } + async updateMemory( memoryId: string, patch: { content?: string; tags?: string[]; confidence?: number; disabled?: boolean } diff --git a/src/renderer/src/agent/types.ts b/src/renderer/src/agent/types.ts index 82f12f04..8a3ce510 100644 --- a/src/renderer/src/agent/types.ts +++ b/src/renderer/src/agent/types.ts @@ -2,6 +2,7 @@ import type { CoreAttachmentContentResponseJson, CoreAttachmentMetadataJson, CoreAttachmentTextFallbackJson, + CoreMemoryDiagnosticsJson, CoreMemoryRecordJson, CoreRuntimeInfoJson, CoreRuntimeSkillJson, @@ -464,11 +465,20 @@ export interface AgentProvider { options?: { threadId?: string; workspace?: string } ): Promise listMemories?(options?: { workspace?: string; includeDeleted?: boolean }): Promise + createMemory?(input: { + content: string + scope?: 'user' | 'workspace' | 'project' + workspace?: string + project?: string + tags?: string[] + confidence?: number + }): Promise updateMemory?( memoryId: string, patch: { content?: string; tags?: string[]; confidence?: number; disabled?: boolean } ): Promise deleteMemory?(memoryId: string): Promise + getMemoryDiagnostics?(): Promise steerUserMessage?(threadId: string, turnId: string, text: string): Promise interruptTurn(threadId: string, turnId: string, options?: { discard?: boolean }): Promise renameThread(threadId: string, title: string): Promise diff --git a/src/renderer/src/components/SettingsSidebar.tsx b/src/renderer/src/components/SettingsSidebar.tsx index 25be4da3..8a7ac2e7 100644 --- a/src/renderer/src/components/SettingsSidebar.tsx +++ b/src/renderer/src/components/SettingsSidebar.tsx @@ -1,7 +1,7 @@ import type { Dispatch, ReactElement, SetStateAction } from 'react' -import { AudioLines, Bot, Bug, ChevronLeft, Globe, ImageIcon, Keyboard, Mic, PencilLine, RefreshCw, ServerCog, Settings, ShieldCheck, Smartphone, Sparkles } from 'lucide-react' +import { AudioLines, Bot, BrainCircuit, Bug, ChevronLeft, Globe, ImageIcon, Keyboard, Mic, PencilLine, RefreshCw, ServerCog, Settings, ShieldCheck, Smartphone, Sparkles } from 'lucide-react' -type SettingsCategory = 'general' | 'providers' | 'write' | 'imageGeneration' | 'mediaGeneration' | 'speechToText' | 'agents' | 'permissions' | 'shortcuts' | 'easterEgg' | 'claw' | 'updates' | 'debug' +type SettingsCategory = 'general' | 'providers' | 'write' | 'imageGeneration' | 'mediaGeneration' | 'speechToText' | 'agents' | 'permissions' | 'memory' | 'shortcuts' | 'easterEgg' | 'claw' | 'updates' | 'debug' export function SettingsSidebar({ category, @@ -79,6 +79,10 @@ export function SettingsSidebar({ {t('permissions')} + + ))} + + + + + {/* Editor */} + {(creating || editingId !== null) && ( +
+
+ + {creating ? t('memoryCreateTitle') : t('memoryEditTitle')} +
+