dsh-feiyu-life 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/mind.js +57 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# 更新记录
|
|
2
2
|
|
|
3
|
+
## 2.3.1
|
|
4
|
+
|
|
5
|
+
- **用户关系去重**:反思模型可能把同一个人写成「用户 / 你 / 对方 / 他」,关系模型现在统一收口为「用户」,读取旧 `feiyu-life-mind.json` 时也会合并重复行并回写,避免关系上下文出现两个竞争的人。
|
|
6
|
+
- **测试**:新增别名合并、认知更新不再新建别名行、旧文件磁盘迁移的回归测试。
|
|
7
|
+
|
|
3
8
|
## 2.3.0
|
|
4
9
|
|
|
5
10
|
- **有依据的主动分享**:新增 `sharing.js`,只从已经发生的小事阶段、已完成时间线、首日身体变化和可追溯的连续性后续中构建候选;未来计划、天气、人物和地点不编造。
|
package/mind.js
CHANGED
|
@@ -97,8 +97,19 @@ function normGoal(item, now) {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* The user is addressed in many ways by the reflection model. Keep one
|
|
102
|
+
* canonical relationship row instead of letting "用户", "你", "对方" and "他"
|
|
103
|
+
* become four competing people. Other named people are untouched.
|
|
104
|
+
*/
|
|
105
|
+
export function canonicalRelationshipName(value) {
|
|
106
|
+
const name = text(value, 60)
|
|
107
|
+
if (!name) return ''
|
|
108
|
+
return /^(?:用户|用户本人|你|对方|他|他本人)$/.test(name) ? '用户' : name
|
|
109
|
+
}
|
|
110
|
+
|
|
100
111
|
function normRelationship(item, now) {
|
|
101
|
-
const name =
|
|
112
|
+
const name = canonicalRelationshipName(item?.name || item?.person)
|
|
102
113
|
if (!name) return null
|
|
103
114
|
return {
|
|
104
115
|
id: text(item?.id, 80) || `rel-${hash(name)}`, name,
|
|
@@ -108,6 +119,32 @@ function normRelationship(item, now) {
|
|
|
108
119
|
}
|
|
109
120
|
}
|
|
110
121
|
|
|
122
|
+
/** Merge aliases that already landed in older files; newest row wins. */
|
|
123
|
+
function mergeRelationships(list) {
|
|
124
|
+
const out = []
|
|
125
|
+
const index = new Map()
|
|
126
|
+
for (const rel of list) {
|
|
127
|
+
const key = normalized(rel.name)
|
|
128
|
+
if (!index.has(key)) {
|
|
129
|
+
index.set(key, out.length)
|
|
130
|
+
out.push(rel)
|
|
131
|
+
continue
|
|
132
|
+
}
|
|
133
|
+
const at = index.get(key)
|
|
134
|
+
const previous = out[at]
|
|
135
|
+
const latest = rel.updatedAt >= previous.updatedAt ? rel : previous
|
|
136
|
+
const older = latest === rel ? previous : rel
|
|
137
|
+
out[at] = {
|
|
138
|
+
...latest,
|
|
139
|
+
createdAt: Math.min(previous.createdAt || latest.createdAt, rel.createdAt || latest.createdAt),
|
|
140
|
+
interactionCount: Math.max(previous.interactionCount || 0, rel.interactionCount || 0),
|
|
141
|
+
summary: latest.summary || older.summary,
|
|
142
|
+
updatedAt: Math.max(previous.updatedAt || 0, rel.updatedAt || 0),
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return out
|
|
146
|
+
}
|
|
147
|
+
|
|
111
148
|
export function normalizeMind(raw, config = {}, now = Date.now()) {
|
|
112
149
|
const base = defaultMind(config, now)
|
|
113
150
|
if (!raw || typeof raw !== 'object') return base
|
|
@@ -123,7 +160,7 @@ export function normalizeMind(raw, config = {}, now = Date.now()) {
|
|
|
123
160
|
memories: (Array.isArray(raw.memories) ? raw.memories : []).map((x) => normMemory(x, now)).filter(Boolean).slice(-2000),
|
|
124
161
|
preferences: (Array.isArray(raw.preferences) ? raw.preferences : []).map((x) => normPreference(x, now)).filter(Boolean).slice(-300),
|
|
125
162
|
goals: (Array.isArray(raw.goals) ? raw.goals : []).map((x) => normGoal(x, now)).filter(Boolean).slice(-100),
|
|
126
|
-
relationships: (Array.isArray(raw.relationships) ? raw.relationships : []).map((x) => normRelationship(x, now)).filter(Boolean).slice(-100),
|
|
163
|
+
relationships: mergeRelationships((Array.isArray(raw.relationships) ? raw.relationships : []).map((x) => normRelationship(x, now)).filter(Boolean)).slice(-100),
|
|
127
164
|
identityEvidence: (Array.isArray(raw.identityEvidence) ? raw.identityEvidence : []).flatMap((x) => {
|
|
128
165
|
const trait = text(x?.trait, 40); const reason = text(x?.reason, 140)
|
|
129
166
|
return trait && reason ? [{ trait, polarity: x?.polarity === 'against' ? 'against' : 'for', reason, confidence: clamp(x?.confidence, 0, 1), eventId: text(x?.eventId, 100), at: Number(x?.at) || now }] : []
|
|
@@ -144,9 +181,20 @@ export function normalizeMind(raw, config = {}, now = Date.now()) {
|
|
|
144
181
|
}
|
|
145
182
|
|
|
146
183
|
export function readMind(config = {}, now = Date.now()) {
|
|
147
|
-
|
|
148
|
-
try {
|
|
184
|
+
for (const path of [mindPath(), mindPath() + '.bak']) {
|
|
185
|
+
try {
|
|
186
|
+
const raw = JSON.parse(readFileSync(path, 'utf8'))
|
|
187
|
+
const clean = normalizeMind(raw, config, now)
|
|
188
|
+
const rawRelationships = Array.isArray(raw?.relationships) ? raw.relationships : []
|
|
189
|
+
const needsAliasMigration = rawRelationships.length !== clean.relationships.length
|
|
190
|
+
|| rawRelationships.some((x) => canonicalRelationshipName(x?.name || x?.person) !== text(x?.name || x?.person, 60))
|
|
191
|
+
if (needsAliasMigration) {
|
|
192
|
+
try { writeMind(clean, config, now) } catch {}
|
|
193
|
+
}
|
|
194
|
+
return clean
|
|
195
|
+
} catch {}
|
|
149
196
|
}
|
|
197
|
+
return defaultMind(config, now)
|
|
150
198
|
}
|
|
151
199
|
|
|
152
200
|
export function writeMind(value, config = {}, now = Date.now()) {
|
|
@@ -193,7 +241,7 @@ export function normalizeCognition(raw) {
|
|
|
193
241
|
return trait && reason && !containsSensitive({ trait, reason }) ? [{ trait, polarity: x?.polarity === 'against' ? 'against' : 'for', reason, confidence: clamp(x?.confidence, 0, 1, 0.5) }] : []
|
|
194
242
|
}).slice(0, 3)
|
|
195
243
|
const relationshipCandidates = (Array.isArray(raw.relationshipCandidates) ? raw.relationshipCandidates : []).flatMap((x) => {
|
|
196
|
-
const person = text(x?.person, 60); const reason = text(x?.reason, 140)
|
|
244
|
+
const person = canonicalRelationshipName(text(x?.person, 60)); const reason = text(x?.reason, 140)
|
|
197
245
|
return person && reason && !containsSensitive({ person, reason }) ? [{ person, tone: ['warm', 'tense'].includes(x?.tone) ? x.tone : 'neutral', reason, confidence: clamp(x?.confidence, 0, 1, 0.7) }] : []
|
|
198
246
|
}).slice(0, 3)
|
|
199
247
|
const cue = raw.initiative && typeof raw.initiative === 'object' ? raw.initiative : null
|
|
@@ -254,14 +302,15 @@ export function applyCognition(eventId, cognition, config = {}, now = Date.now()
|
|
|
254
302
|
}
|
|
255
303
|
for (const item of c.relationshipCandidates) {
|
|
256
304
|
if (item.confidence < 0.6) continue
|
|
257
|
-
|
|
258
|
-
|
|
305
|
+
const personName = canonicalRelationshipName(item.person)
|
|
306
|
+
let relation = mind.relationships.find((x) => normalized(x.name) === normalized(personName))
|
|
307
|
+
if (!relation) { relation = normRelationship({ name: personName }, now); mind.relationships.push(relation) }
|
|
259
308
|
relation.interactionCount += 1
|
|
260
309
|
relation.warmth = clamp(relation.warmth + (item.tone === 'warm' ? 1 : item.tone === 'tense' ? -1 : 0), 0, 100, relation.warmth)
|
|
261
310
|
relation.trust = clamp(relation.trust + (item.tone === 'warm' ? 0.5 : item.tone === 'tense' ? -0.5 : 0), 0, 100, relation.trust)
|
|
262
311
|
relation.tension = clamp(relation.tension + (item.tone === 'tense' ? 2 : item.tone === 'warm' ? -1 : -0.25), 0, 100, relation.tension)
|
|
263
312
|
relation.summary = item.reason; relation.updatedAt = now
|
|
264
|
-
changes.push(`关系感受:${
|
|
313
|
+
changes.push(`关系感受:${personName}(${item.tone})`)
|
|
265
314
|
}
|
|
266
315
|
for (const item of c.identityEvidence) if (item.confidence >= 0.72) mind.identityEvidence.push({ ...item, eventId: id, at: now })
|
|
267
316
|
// A trait changes only after three independent pieces of aligned evidence.
|