feat: share memory and KG across users when workspace sharing is enabled

Memory (MEMORY.md, memory/*) and knowledge graph are now shared when
workspace sharing is active, matching the filesystem sharing behavior.
Previously memory was always per-user isolated even with shared workspace,
causing inconsistencies when collaborating on the same files.

Adds MemoryUserID(ctx) helper that returns empty userID (global scope)
when shared memory flag is set, used by memory interceptor, memory tools,
and KG search. UI warning updated to note data is not migrated on toggle.
This commit is contained in:
viettranx committed 2026-03-12 12:09:38 +07:00
1 parent 25b24ebd50
commit bece4525ba
8 files changed
+36 -10

No files matched your search

+3 -3
View File
@@ -96,7 +96,7 @@ func (m *MemoryInterceptor) ReadFile(ctx context.Context, path string) (string,
// Normalize absolute path to workspace-relative for DB storage
relPath := normalizeToRelative(path, m.workspace)
userID := store.UserIDFromContext(ctx)
userID := store.MemoryUserID(ctx)
agentStr := agentID.String()
// Try per-user first, then global
@@ -136,7 +136,7 @@ func (m *MemoryInterceptor) WriteFile(ctx context.Context, path, content string)
// Normalize absolute path to workspace-relative for DB storage
relPath := normalizeToRelative(path, m.workspace)
userID := store.UserIDFromContext(ctx)
userID := store.MemoryUserID(ctx)
agentStr := agentID.String()
// Write document to DB
@@ -175,7 +175,7 @@ func (m *MemoryInterceptor) ListFiles(ctx context.Context, path string) (string,
return "", false, nil
}
userID := store.UserIDFromContext(ctx)
userID := store.MemoryUserID(ctx)
docs, err := m.memStore.ListDocuments(ctx, agentID.String(), userID)
if err != nil {
return "", true, err