Skip to content

feat(memory): add dedicated memory management panel in settings#288

Merged
XingYu-Zhong merged 6 commits into
KunAgent:developfrom
whitelonng:feat/memory-gui
Jun 14, 2026
Merged

feat(memory): add dedicated memory management panel in settings#288
XingYu-Zhong merged 6 commits into
KunAgent:developfrom
whitelonng:feat/memory-gui

Conversation

@whitelonng

@whitelonng whitelonng commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a first-class Memory management panel to Settings, giving users full CRUD over the assistant's long-term memory records.

Screenshots

Settings entry — the Memory item sits in the Settings sidebar:

Memory entry in Settings sidebar

Management panel — overview stats + full record list with CRUD:

Memory management panel

Create memory — editor with content, scope, tags, confidence:

Create memory editor

Scope dropdown — user / workspace / project:

Scope dropdown

Memory in action — user memories injected into the chat + LLM proactively calling memory_create:

Memory injected in chat and proactive memory_create call

Background

Kun's runtime already had a complete memory subsystem — FileMemoryStore, HTTP routes (GET/POST/PATCH/DELETE /v1/memory + /v1/memory/diagnostics), automatic injection into the agent loop, and memory_create/update/delete tools. But the GUI only exposed a read-only, truncated-to-8 view buried inside the Agents settings section. Users had no way to create, edit, or audit memories from the UI.

What's new

A dedicated Memory entry in the Settings sidebar (BrainCircuit icon) with:

  • Overview card — active count, tombstone count, and enabled/disabled status from /v1/memory/diagnostics
  • Full record list with scope filter (All / User / Workspace / Project) — no longer truncated to 8
  • Create — new memory with content, scope, tags, and confidence
  • Edit — inline editor for content, tags, and confidence
  • Disable / Delete — soft-disable (Ban) and soft-delete (Trash), same as before
  • Last injected — shows which memory IDs were injected into the most recent turn

Changes

Frontend (GUI panel):

Area Files Change
Runtime client kun-runtime.ts, types.ts Add createMemory + getMemoryDiagnostics to AgentProvider interface and KunRuntimeProvider (POST route already existed in runtime)
Settings section settings-section-memory.tsx (new) Full CRUD UI
Registration settings-sections.tsx, SettingsView.tsx, SettingsSidebar.tsx, use-settings-gui-update.ts Register new memory category
Handlers SettingsView.tsx createMemoryRecord, updateMemoryRecord, refreshMemoryDiagnostics
i18n locales/{en,zh}/settings.json +30 keys

Runtime (memory retrieval fixes):

Area Files Change
Retrieval kun/src/memory/memory-store.ts User-scope memories injected unconditionally (was gated behind keyword scoring, so semantic queries like "who am I?" never surfaced them); CJK retrieval fixed via n-gram fingerprinting (was split on [^a-z0-9_]+, treating every Chinese char as a separator); workspace-scope memories with no workspace field now retrievable
System prompt kun/src/prompt/kun-system-prompt.ts Document memory_create/update/delete tools so the LLM proactively persists durable facts
Tests kun/tests/memory-store.test.ts +3 regression tests: CJK retrieval, workspace-less workspace memories, semantic-query user-memory injection

Memory retrieval bug — root cause

The retrieve path gated every record behind keyword-overlap scoring. This broke memory injection in three ways:

  1. Semantic identity queries never matched user memories. Asking "你知道我是谁吗" against a stored whitelonng shares zero keyword/n-gram overlap → score=0 → filtered out → not injected. The LLM only saw it when the user typed an explicit keyword like "用户记忆". User memories are now injected unconditionally — they are small, high-value identity facts.
  2. CJK retrieval was completely broken. scoreMemory split the query on [^a-z0-9_]+, which treats every Chinese character as a separator and produced an empty token set for Chinese queries.
  3. GUI-created workspace memories were silently dropped. inScope required an exact workspace match, but the GUI creates memories without one.

Backward compatibility

The existing read-only memory block in the Agents settings section is left intact — it still shows the first 8 records with disable/delete buttons. The new Memory section is additive. Workspace/project memories keep the scored retrieval path.

Verification

  • npm run typecheck passes
  • npm run lint — 0 errors (9 pre-existing warnings unchanged)
  • npx vitest run src/renderer/src/components — 257/257 passed
  • npx vitest run tests/memory-store.test.ts — 8/8 passed (kun runtime)
  • npx tsc --noEmit (kun) — clean
  • tests/loop.test.ts — 3 pre-existing failures confirmed unchanged via git stash (unrelated to this change)
  • Manual end-to-end: user memory injected into chat + LLM proactively calls memory_create (see screenshots)

Notes

  • This is the first of a series of features being ported over from a sibling project. Designed to be standalone and low-risk — touches only the GUI layer and reuses existing runtime infrastructure.

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.
Two UX fixes from manual testing:

1. When create/update fails (e.g. memory capability disabled in runtime),
   the editor no longer closes and discards the user's draft. The handler
   now returns boolean success; the editor only closes on success.

2. When memory is disabled (memoryDiagnostics.enabled === false), an
   amber warning banner appears above the record list explaining that
   memory must be enabled in runtime config before records can be
   created. Previously the user could click 'New', fill in content,
   hit Save, and see nothing happen with no feedback.
Previously memory could only be enabled by manually editing the Kun
config file — there was no GUI control. The Memory settings page
showed 'Status: Off' but offered no way to turn it on, so users
couldn't create or use memory records without finding the hidden
runtime config.

This adds:
- memoryEnabled boolean to KunRuntimeSettingsV1 (default: false)
- resolveKunMemoryEnabled + mergeKunRuntimeSettings support
- kun-process writes capabilities.memory.enabled from the GUI setting
- A Toggle at the top of the Memory settings section
- i18n keys (en/zh)
The settings:set IPC payload is validated with a strict zod schema
that rejects unknown keys. Adding memoryEnabled to KunRuntimeSettingsV1
without also adding it to kunRuntimePatchSchema caused every settings
save to fail with 'Invalid payload for setting' — even on first load,
because the auto-apply feature saves immediately on any field change.
…rieval

The memory retrieve path gated every record behind keyword-overlap scoring.
This caused three independent failures:

1. Semantic identity queries ("who am I?", "你知道我是谁吗") never matched
   user memories because the query shares zero keyword/n-gram overlap with
   the stored content (e.g. "whitelonng"). The LLM only saw the memory when
   the user explicitly typed a keyword like "用户记忆". User-scope memories
   are now injected unconditionally — they are small, high-value identity
   facts that semantic prompts must surface. Workspace/project memories keep
   the scored retrieval path.

2. scoreMemory split the query on [^a-z0-9_]+, which treats every CJK
   character as a separator and produced an empty token set for Chinese
   queries — workspace/project memories in Chinese were never retrieved.
   Replaced with language-agnostic n-gram fingerprinting (trigrams for
   ASCII words, bigrams for CJK runs), no tokenizer dependency.

3. inScope required an exact workspace match for workspace-scope records,
   but the GUI creates memories without a workspace field, so they were
   silently filtered out. A missing workspace now matches any request.

Also document the memory tools in the system prompt so the LLM proactively
persists durable facts via memory_create/update/delete instead of waiting
for an explicit instruction.

Adds regression tests for CJK retrieval, workspace-less workspace memories,
and semantic-query user-memory injection.
@XingYu-Zhong XingYu-Zhong merged commit e6abab2 into KunAgent:develop Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants