@@ -43,27 +43,37 @@ export function escapePromptVars(config, text) {
4343 * - 开:不注入人格(`source: "none"`)。default 退回它的本意:只兜「这一帧解析不到
4444 * 身份」的会话(无名会话本来就是 default 卡的受众)。
4545 * 默认关是有意的:这是一次口径变更,不能让老用户的注入文本在升级后静默变化。
46+ *
47+ * 严格模式有一格例外(#587):`byAgent` **整体为空**时仍回落 default。两种处境必须
48+ * 分开——「建了卡、只是没这张身份的卡」是真该按 none 处理(否则关掉一张卡等于没关),
49+ * 而「一张身份卡都没建」时 default 是用户手里唯一的一张卡,按 none 处理等于把它永久
50+ * 废掉,且面板不报错。DS Bot 这类宿主里所有 bot 会话共用 `agentPreset: "standard"`
51+ * (`ds-bot/src/host/roster.js:72-80` 强制写入),用户按 bot 名字建卡永远不会命中,
52+ * 于是必然落进后一种处境:开了严格寻址就把唯一那张卡静默关死。
4653 */
4754export function resolvePersonaCard ( settings , agentId , { strict = false } = { } ) {
4855 const store = settings . getPersona ( ) ;
4956 const id = typeof agentId === "string" && agentId . trim ( ) ? agentId . trim ( ) : "" ;
5057 const card = id ? store . byAgent [ id ] : null ;
5158 if ( card && card . enabled === true ) return { card, source : "byAgent" } ;
52- if ( id && strict ) return { card : { } , source : "none" } ;
59+ // 严格模式只在「确实建过身份卡」时才拒绝兜底:一张都没建时兜底是唯一的出路。
60+ if ( id && strict && Object . keys ( store . byAgent ) . length > 0 ) return { card : { } , source : "none" } ;
5361 return { card : store . default , source : "default" } ;
5462}
5563
5664/**
5765 * 按会话身份取自动事实卡(resolvePersonaCard 的镜像,形状不同:facts 没有
5866 * enabled 位,「卡存在」就是非空数组)。strict 语义与人格一致:有身份但没这张
5967 * 身份的卡时不落 default——两个 bot 对用户的认知不互串是 store 层分区(输入行)
60- * 与本层寻址(输出注入)共同守住的边界。
68+ * 与本层寻址(输出注入)共同守住的边界。与人格同一条例外(#587):`byAgent` 整体
69+ * 为空时仍落 default,「一张都没建」不等于「这一张没建」。
6170 */
6271export function resolveFactsCard ( factsStore , agentId , { strict = false } = { } ) {
6372 const id = typeof agentId === "string" && agentId . trim ( ) ? agentId . trim ( ) : "" ;
64- const card = id ? ( factsStore ?. byAgent ?. [ id ] ?? null ) : null ;
73+ const byAgent = factsStore ?. byAgent ?? { } ;
74+ const card = id ? ( byAgent [ id ] ?? null ) : null ;
6575 if ( card && card . length ) return { facts : card , source : "byAgent" } ;
66- if ( id && strict ) return { facts : [ ] , source : "none" } ;
76+ if ( id && strict && Object . keys ( byAgent ) . length > 0 ) return { facts : [ ] , source : "none" } ;
6777 return { facts : factsStore ?. default ?? [ ] , source : "default" } ;
6878}
6979
0 commit comments