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:
@@ -154,11 +154,12 @@ export function buildSessionMemoryEntries({
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
const profile =
|
// Always call ensureUserMemoryProfile when userContext is available so that
|
||||||
loadUserMemoryProfile(workingDir) ??
|
// stale displayName values (e.g. UUID written before nickname was resolved)
|
||||||
(userContext?.userId
|
// are healed on the next session init.
|
||||||
? ensureUserMemoryProfile(workingDir, userContext)
|
const profile = userContext?.userId
|
||||||
: null);
|
? ensureUserMemoryProfile(workingDir, userContext)
|
||||||
|
: loadUserMemoryProfile(workingDir);
|
||||||
|
|
||||||
const addressName = resolveUserAddressName({
|
const addressName = resolveUserAddressName({
|
||||||
displayName: profile?.displayName ?? userContext?.displayName,
|
displayName: profile?.displayName ?? userContext?.displayName,
|
||||||
|
|||||||
+6
-3
@@ -24,13 +24,16 @@ function renderBrandingBlock(userAddressName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Preferred name when addressing the user in chat (display name > username > slug). */
|
/** 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 } = {}) {
|
export function resolveUserAddressName({ displayName, username, slug } = {}) {
|
||||||
const preferred = String(displayName ?? '').trim();
|
const preferred = String(displayName ?? '').trim();
|
||||||
if (preferred) return preferred;
|
if (preferred && !INTERNAL_ID_PATTERN.test(preferred)) return preferred;
|
||||||
const uname = String(username ?? '').trim();
|
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();
|
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 '用户';
|
return '用户';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user