Fix UUID leaking as user display name in agent context

resolveUserAddressName now filters UUID-format strings (same as wx_*),
preventing user.id from being used as a display name when nickname/
displayName is absent.

buildSessionMemoryEntries always calls ensureUserMemoryProfile when
userContext is available so stale profiles with UUID display names are
auto-healed on next session init.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
john
2026-06-26 15:56:22 +08:00
parent 9b4a25799f
commit 8502775042
2 changed files with 12 additions and 8 deletions
+6 -5
View File
@@ -154,11 +154,12 @@ export function buildSessionMemoryEntries({
return entries;
}
const profile =
loadUserMemoryProfile(workingDir) ??
(userContext?.userId
? ensureUserMemoryProfile(workingDir, userContext)
: null);
// Always call ensureUserMemoryProfile when userContext is available so that
// stale displayName values (e.g. UUID written before nickname was resolved)
// are healed on the next session init.
const profile = userContext?.userId
? ensureUserMemoryProfile(workingDir, userContext)
: loadUserMemoryProfile(workingDir);
const addressName = resolveUserAddressName({
displayName: profile?.displayName ?? userContext?.displayName,
+6 -3
View File
@@ -24,13 +24,16 @@ function renderBrandingBlock(userAddressName) {
}
/** Preferred name when addressing the user in chat (display name > username > slug). */
const INTERNAL_ID_PATTERN =
/^wx_[a-z0-9_]{4,64}$|^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
export function resolveUserAddressName({ displayName, username, slug } = {}) {
const preferred = String(displayName ?? '').trim();
if (preferred) return preferred;
if (preferred && !INTERNAL_ID_PATTERN.test(preferred)) return preferred;
const uname = String(username ?? '').trim();
if (uname && !/^wx_[a-z0-9_]{4,64}$/i.test(uname)) return uname;
if (uname && !INTERNAL_ID_PATTERN.test(uname)) return uname;
const fallback = String(slug ?? '').trim();
if (fallback && !/^wx_[a-z0-9_]{4,64}$/i.test(fallback)) return fallback;
if (fallback && !INTERNAL_ID_PATTERN.test(fallback)) return fallback;
return '用户';
}