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

+5 -1
View File
@@ -104,8 +104,12 @@ func (l *Loop) runLoop(ctx context.Context, req RunRequest) (*RunResult, error)
cachedWs = ws
}
effectiveWorkspace := cachedWs.(string)
if !l.shouldShareWorkspace(req.UserID, req.PeerKind) {
shared := l.shouldShareWorkspace(req.UserID, req.PeerKind)
if !shared {
effectiveWorkspace = filepath.Join(effectiveWorkspace, sanitizePathSegment(req.UserID))
} else {
// Shared workspace → share memory across users too.
ctx = store.WithSharedMemory(ctx)
}
if err := os.MkdirAll(effectiveWorkspace, 0755); err != nil {
slog.Warn("failed to create user workspace directory", "workspace", effectiveWorkspace, "user", req.UserID, "error", err)