luckytri 1.0.4 → 1.0.6
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/LICENSE +21 -21
- package/README.en.md +2 -0
- package/README.md +2 -0
- package/docs/en/CHANGELOG.md +20 -13
- package/docs/en/guide.md +7 -5
- package/docs/en/her-life.md +2 -2
- package/docs/en/webui.md +1 -1
- package/docs/zh/CHANGELOG.md +20 -13
- package/docs/zh/guide.md +7 -5
- package/docs/zh/her-life.md +2 -2
- package/docs/zh/webui.md +1 -1
- package/package.json +2 -1
- package/public/app/assets/ChatsPage-CFMVozoG.css +1 -0
- package/public/app/assets/{ChatsPage-CshdtTzV.js → ChatsPage-DCYMkJ91.js} +2 -2
- package/public/app/assets/{Empty-C7yzOBzy.js → Empty-CLyZkxR5.js} +1 -1
- package/public/app/assets/{Empty-DmUB2-Bk.css → Empty-DIobYG3x.css} +1 -1
- package/public/app/assets/{Field-BjFv4Rfn.js → Field-BpaRwLI_.js} +1 -1
- package/public/app/assets/{HeartPage-eqo6ru16.js → HeartPage-BIOMTiwr.js} +1 -1
- package/public/app/assets/HeartPage-C-2jvgzF.css +1 -0
- package/public/app/assets/{LifePage-CN8GE5NK.js → LifePage-BCgM4JkR.js} +1 -1
- package/public/app/assets/LifePage-CG1OHbRK.css +1 -0
- package/public/app/assets/MemoryPage-C_Bu4rfb.css +1 -0
- package/public/app/assets/{MemoryPage-CCpMN4Wg.js → MemoryPage-vShvRqMt.js} +1 -1
- package/public/app/assets/NaturePage-CPZlImT0.css +1 -0
- package/public/app/assets/{NaturePage-C0JqdBTR.js → NaturePage-Cy9ptr4G.js} +2 -2
- package/public/app/assets/PeoplePage-3RRUITDz.css +1 -0
- package/public/app/assets/{PeoplePage-BXGBbO4u.js → PeoplePage-CUZekB2E.js} +1 -1
- package/public/app/assets/{PluginsPage-Dksp5AV5.js → PluginsPage-1RM4rmJP.js} +1 -1
- package/public/app/assets/{SystemPage-BenIyTvk.css → SystemPage-BI2CB5Ig.css} +1 -1
- package/public/app/assets/{SystemPage-Cd7aa8eE.js → SystemPage-BeT5TmIV.js} +1 -1
- package/public/app/assets/TimePage-C-guwPk2.css +1 -0
- package/public/app/assets/{TimePage-Bs_zImb4.js → TimePage-taTmPMM8.js} +2 -2
- package/public/app/assets/{index-BHZcHUMh.css → index-DY5AM0Hz.css} +1 -1
- package/public/app/assets/{index-CyRtYxP3.js → index-DdYwC5ZU.js} +3 -3
- package/public/app/assets/{knowledge-BJOIyuJo.js → knowledge-DJmfu2KN.js} +1 -1
- package/public/app/assets/{media-Bwtx8blz.js → media-BEtnE0Gv.js} +1 -1
- package/public/app/assets/{mind-DtTVrW6Z.js → mind-Dtiw0-QK.js} +1 -1
- package/public/app/index.html +6 -5
- package/public/guide.en.html +11 -3
- package/public/guide.html +6 -3
- package/public/tutorial.en.md +2 -0
- package/public/tutorial.md +2 -0
- package/scripts/import-data.js +128 -128
- package/scripts/proxy-config.js +167 -167
- package/scripts/service-supervisor.js +50 -0
- package/scripts/start-server.js +71 -16
- package/scripts/update-instance.js +201 -201
- package/server/channels/adapters.js +27 -27
- package/server/channels/onebot/adapter.js +288 -288
- package/server/channels/qqbot/adapter.js +253 -253
- package/server/channels/qqbot/api.js +199 -199
- package/server/channels/qqbot/credentials.js +11 -11
- package/server/channels/qqbot/gateway.js +274 -274
- package/server/channels/qqbot/index.js +389 -389
- package/server/channels/segments.js +40 -40
- package/server/channels/session-key.js +153 -153
- package/server/channels/state.js +42 -42
- package/server/core/api.js +564 -564
- package/server/core/context-builder.js +288 -288
- package/server/core/context-compactor.js +454 -454
- package/server/core/conversation-cues.js +325 -325
- package/server/core/conversation-manager.js +87 -87
- package/server/core/feedback.js +8 -8
- package/server/core/group-style.js +72 -72
- package/server/core/initiative-context.js +66 -66
- package/server/core/input-budget.js +32 -32
- package/server/core/local-demo.js +98 -98
- package/server/core/message-manager.js +118 -118
- package/server/core/message-scheduler.js +78 -78
- package/server/core/model-json.js +190 -190
- package/server/core/model-presets.js +900 -900
- package/server/core/name-call.js +29 -29
- package/server/core/network.js +157 -157
- package/server/core/person-name.js +22 -22
- package/server/core/persona-manager.js +2 -1
- package/server/core/reply-delivery.js +404 -403
- package/server/core/reply-target-resolver.js +50 -50
- package/server/core/response-generator.js +50 -50
- package/server/core/response-validator.js +14 -2
- package/server/core/retired-prompts.js +51 -51
- package/server/core/sessions.js +109 -109
- package/server/core/speaker-names.js +92 -92
- package/server/core/topic-tracker.js +65 -65
- package/server/http.js +18 -18
- package/server/i18n/decisions.js +209 -206
- package/server/i18n/errors.js +4 -0
- package/server/i18n/index.js +144 -144
- package/server/i18n/models.js +111 -111
- package/server/knowledge/api.js +342 -342
- package/server/knowledge/embedding-profile.js +114 -114
- package/server/knowledge/index.js +13 -13
- package/server/knowledge/retrieval.js +93 -93
- package/server/knowledge/schema.js +158 -158
- package/server/knowledge/vector-index.js +90 -90
- package/server/mind/affect.js +265 -265
- package/server/mind/attention.js +200 -200
- package/server/mind/bonds.js +565 -565
- package/server/mind/clock.js +83 -83
- package/server/mind/continuity.js +562 -562
- package/server/mind/conversation-origin.js +175 -175
- package/server/mind/days.js +210 -210
- package/server/mind/evidence-read.js +45 -45
- package/server/mind/faces.js +373 -373
- package/server/mind/guard.js +60 -60
- package/server/mind/initiative.js +338 -338
- package/server/mind/life/activities.js +21 -21
- package/server/mind/life/context.js +330 -323
- package/server/mind/life/diary.js +20 -0
- package/server/mind/life/growth.js +261 -254
- package/server/mind/life/index.js +10 -2
- package/server/mind/life/presence.js +305 -305
- package/server/mind/meetings.js +1069 -1069
- package/server/mind/memory-policy.js +48 -48
- package/server/mind/memory.js +888 -888
- package/server/mind/nature.js +358 -358
- package/server/mind/novelty.js +19 -19
- package/server/mind/periods.js +118 -118
- package/server/mind/reading.js +120 -120
- package/server/mind/relationship-context.js +71 -0
- package/server/mind/relationships.js +390 -279
- package/server/mind/salience.js +201 -201
- package/server/mind/schema.js +567 -567
- package/server/mind/self.js +484 -484
- package/server/mind/thoughts.js +274 -274
- package/server/mind/time/agenda.js +242 -242
- package/server/mind/time/api.js +200 -200
- package/server/mind/time/attention.js +34 -34
- package/server/mind/time/delivery-links.js +130 -130
- package/server/mind/time/model-material.js +77 -77
- package/server/mind/time/presentation.js +51 -51
- package/server/mind/time/schedule.js +83 -83
- package/server/mind/time/schema.js +84 -84
- package/server/mind/time/search.js +383 -383
- package/server/mind/time/sharing.js +472 -472
- package/server/mind/time/task-links.js +311 -311
- package/server/mind/time/works.js +432 -432
- package/server/mind/traits.js +191 -191
- package/server/mind/view.js +9 -1
- package/server/runtime/installation.js +116 -116
- package/server/runtime/update-execution.js +2 -1
- package/server/runtime/update-manager.js +140 -140
- package/server/storage/data-package.js +298 -298
- package/server/storage/data-transfer-api.js +50 -50
- package/server/storage/data-transfer-worker.js +18 -18
- package/server/storage/data-transfer.js +416 -416
- package/server/studio/display-names.js +139 -139
- package/server/studio/management.js +102 -102
- package/server/studio/updates.js +144 -144
- package/server/version.js +10 -10
- package/public/app/assets/ChatsPage-DfyPCS9N.css +0 -1
- package/public/app/assets/HeartPage-Bft9wZp5.css +0 -1
- package/public/app/assets/LifePage-BUi5euBF.css +0 -1
- package/public/app/assets/MemoryPage-cZvXfkXb.css +0 -1
- package/public/app/assets/NaturePage-CHkpb5NK.css +0 -1
- package/public/app/assets/PeoplePage-BTU0H1pM.css +0 -1
- package/public/app/assets/TimePage-BOms_n4I.css +0 -1
package/server/mind/traits.js
CHANGED
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { evidenceRoots, externalEvidence } from "./evidence.js";
|
|
3
|
-
import { lifeDayStart } from "./nature.js";
|
|
4
|
-
import { evidence, hasCredential, similar, text } from "./util.js";
|
|
5
|
-
|
|
6
|
-
export const LIVED_TRAITS = [
|
|
7
|
-
"warmth",
|
|
8
|
-
"sarcasm",
|
|
9
|
-
"humor",
|
|
10
|
-
"activity",
|
|
11
|
-
"initiative",
|
|
12
|
-
];
|
|
13
|
-
const TRAIT_HALF_LIFE = 180;
|
|
14
|
-
const DAILY_SHIFT_CAP = 4;
|
|
15
|
-
export function personaNeedsRephrase(content, mind) {
|
|
16
|
-
const value = String(content || "");
|
|
17
|
-
return (
|
|
18
|
-
value.length > 100 ||
|
|
19
|
-
/今天|昨天|明天|今晚|这几天|刚才|比如|下次|打完/.test(value) ||
|
|
20
|
-
!mind.meetings.sayable(value, "")
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Nature is the starting point. These small, cited changes are what she has
|
|
25
|
-
// actually learned about how she wants to show up; they belong to one self.
|
|
26
|
-
export class Traits {
|
|
27
|
-
constructor(mind) {
|
|
28
|
-
this.mind = mind;
|
|
29
|
-
this.db = mind.db;
|
|
30
|
-
}
|
|
31
|
-
current(nature = this.mind.nature.current(), before = Date.now()) {
|
|
32
|
-
const values = Object.fromEntries(
|
|
33
|
-
LIVED_TRAITS.map((key) => [key, Number(nature[key])]),
|
|
34
|
-
);
|
|
35
|
-
const rows = this.db
|
|
36
|
-
.prepare(
|
|
37
|
-
"SELECT trait,delta,created FROM mind_trait_changes WHERE nature_version=? AND created<=? ORDER BY created,rowid",
|
|
38
|
-
)
|
|
39
|
-
.all(nature.version, before);
|
|
40
|
-
const lived = this.mind.days.lived(before);
|
|
41
|
-
for (const row of rows) {
|
|
42
|
-
if (!LIVED_TRAITS.includes(row.trait)) continue;
|
|
43
|
-
values[row.trait] +=
|
|
44
|
-
row.delta * 0.5 ** (lived.since(row.created) / TRAIT_HALF_LIFE);
|
|
45
|
-
}
|
|
46
|
-
for (const trait of LIVED_TRAITS)
|
|
47
|
-
values[trait] = Math.max(0, Math.min(100, Math.round(values[trait])));
|
|
48
|
-
return values;
|
|
49
|
-
}
|
|
50
|
-
effective(nature = this.mind.nature.current(), before = Date.now()) {
|
|
51
|
-
const persona = this.persona(nature, before);
|
|
52
|
-
return {
|
|
53
|
-
...nature,
|
|
54
|
-
...this.current(nature, before),
|
|
55
|
-
...(persona ? { livedPersona: persona.content } : {}),
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
persona(nature = this.mind.nature.current(), before = Date.now()) {
|
|
59
|
-
return (
|
|
60
|
-
this.db
|
|
61
|
-
.prepare(
|
|
62
|
-
"SELECT * FROM mind_persona_growth WHERE nature_version=? AND created<=? ORDER BY created DESC,rowid DESC LIMIT 1",
|
|
63
|
-
)
|
|
64
|
-
.get(nature.version, before) || null
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
personaHistory(limit = 15) {
|
|
68
|
-
return this.db
|
|
69
|
-
.prepare(
|
|
70
|
-
"SELECT * FROM mind_persona_growth ORDER BY created DESC,rowid DESC LIMIT ?",
|
|
71
|
-
)
|
|
72
|
-
.all(limit)
|
|
73
|
-
.map((row) => ({ ...row, sources: JSON.parse(row.sources) }));
|
|
74
|
-
}
|
|
75
|
-
proposePersona(
|
|
76
|
-
input,
|
|
77
|
-
{ valid, origin = "solitude", time = Date.now() } = {},
|
|
78
|
-
) {
|
|
79
|
-
const content = text(input?.content, 240);
|
|
80
|
-
if (
|
|
81
|
-
content.length < 12 ||
|
|
82
|
-
hasCredential(content) ||
|
|
83
|
-
personaNeedsRephrase(content, this.mind)
|
|
84
|
-
)
|
|
85
|
-
return { rejected: "不适合长期自述或含私下内容" };
|
|
86
|
-
const sources = evidence(input?.sources).filter(
|
|
87
|
-
(s) => !valid || valid.has(s),
|
|
88
|
-
);
|
|
89
|
-
if (!sources.length) return { rejected: "缺少亲历来源" };
|
|
90
|
-
const nature = this.mind.nature.current(time);
|
|
91
|
-
const previous = this.persona(nature, time);
|
|
92
|
-
const correcting =
|
|
93
|
-
previous && personaNeedsRephrase(previous.content, this.mind);
|
|
94
|
-
const grounded = externalEvidence(this.db, sources, time);
|
|
95
|
-
if (!correcting && !grounded.length)
|
|
96
|
-
return { rejected: "自述需要模型之外的新经历" };
|
|
97
|
-
if (previous && similar(content, previous.content, 0.85))
|
|
98
|
-
return { rejected: "没有实质变化" };
|
|
99
|
-
const spent = new Set(
|
|
100
|
-
this.db
|
|
101
|
-
.prepare(
|
|
102
|
-
"SELECT sources FROM mind_persona_growth WHERE nature_version=? AND created<=?",
|
|
103
|
-
)
|
|
104
|
-
.all(nature.version, time)
|
|
105
|
-
.flatMap((row) =>
|
|
106
|
-
evidenceRoots(this.db, JSON.parse(row.sources), time),
|
|
107
|
-
),
|
|
108
|
-
);
|
|
109
|
-
if (
|
|
110
|
-
previous &&
|
|
111
|
-
!personaNeedsRephrase(previous.content, this.mind) &&
|
|
112
|
-
!grounded.some((root) => !spent.has(root))
|
|
113
|
-
)
|
|
114
|
-
return { rejected: "没有新的亲历来源" };
|
|
115
|
-
const id = randomUUID();
|
|
116
|
-
this.db
|
|
117
|
-
.prepare(
|
|
118
|
-
"INSERT INTO mind_persona_growth(id,created,content,sources,origin,nature_version) VALUES (?,?,?,?,?,?)",
|
|
119
|
-
)
|
|
120
|
-
.run(id, time, content, JSON.stringify(sources), origin, nature.version);
|
|
121
|
-
return { id };
|
|
122
|
-
}
|
|
123
|
-
history(limit = 30) {
|
|
124
|
-
return this.db
|
|
125
|
-
.prepare(
|
|
126
|
-
"SELECT id,created,trait,value,delta,reason,sources,origin,nature_version FROM mind_trait_changes ORDER BY created DESC,rowid DESC LIMIT ?",
|
|
127
|
-
)
|
|
128
|
-
.all(limit)
|
|
129
|
-
.map((row) => ({ ...row, sources: JSON.parse(row.sources) }));
|
|
130
|
-
}
|
|
131
|
-
propose(input, { valid, origin = "solitude", time = Date.now() } = {}) {
|
|
132
|
-
const trait = String(input?.trait || "");
|
|
133
|
-
if (!LIVED_TRAITS.includes(trait)) return { rejected: "未知性格维度" };
|
|
134
|
-
const direction = Number(input?.direction);
|
|
135
|
-
if (!Number.isFinite(direction) || direction === 0)
|
|
136
|
-
return { rejected: "没有方向" };
|
|
137
|
-
const reason = text(input?.why, 180);
|
|
138
|
-
if (!reason || hasCredential(reason)) return { rejected: "缺少可用的理由" };
|
|
139
|
-
const sources = evidence(input?.sources).filter(
|
|
140
|
-
(s) => !valid || valid.has(s),
|
|
141
|
-
);
|
|
142
|
-
if (!sources.length) return { rejected: "缺少亲历来源" };
|
|
143
|
-
const nature = this.mind.nature.current(time);
|
|
144
|
-
const grounded = externalEvidence(this.db, sources, time);
|
|
145
|
-
if (!grounded.length) return { rejected: "性格变化需要模型之外的经历" };
|
|
146
|
-
const spent = new Set(
|
|
147
|
-
this.db
|
|
148
|
-
.prepare(
|
|
149
|
-
"SELECT sources FROM mind_trait_changes WHERE trait=? AND nature_version=?",
|
|
150
|
-
)
|
|
151
|
-
.all(trait, nature.version)
|
|
152
|
-
.flatMap((row) =>
|
|
153
|
-
evidenceRoots(this.db, JSON.parse(row.sources), time),
|
|
154
|
-
),
|
|
155
|
-
);
|
|
156
|
-
if (!grounded.some((source) => !spent.has(source)))
|
|
157
|
-
return { rejected: "这段经历已经改变过它" };
|
|
158
|
-
const previous = this.current(nature, time)[trait];
|
|
159
|
-
const start = lifeDayStart(nature, time, this.mind.timeZone());
|
|
160
|
-
const used = this.db
|
|
161
|
-
.prepare(
|
|
162
|
-
"SELECT COALESCE(SUM(ABS(delta)),0) n FROM mind_trait_changes WHERE trait=? AND nature_version=? AND created>=? AND created<=?",
|
|
163
|
-
)
|
|
164
|
-
.get(trait, nature.version, start, time).n;
|
|
165
|
-
const allowance = Math.max(0, DAILY_SHIFT_CAP - used);
|
|
166
|
-
if (!allowance) return { rejected: "今天这项性格已经改变过,留些时间检验" };
|
|
167
|
-
// A single reflection may nudge a tendency, never replace her overnight.
|
|
168
|
-
const delta =
|
|
169
|
-
Math.sign(direction) *
|
|
170
|
-
Math.min(allowance, Math.max(1, Math.round(Math.abs(direction))));
|
|
171
|
-
const value = Math.max(0, Math.min(100, previous + delta));
|
|
172
|
-
if (value === previous) return { rejected: "已到边界" };
|
|
173
|
-
const id = randomUUID();
|
|
174
|
-
this.db
|
|
175
|
-
.prepare(
|
|
176
|
-
"INSERT INTO mind_trait_changes(id,created,trait,value,delta,reason,sources,origin,nature_version) VALUES (?,?,?,?,?,?,?,?,?)",
|
|
177
|
-
)
|
|
178
|
-
.run(
|
|
179
|
-
id,
|
|
180
|
-
time,
|
|
181
|
-
trait,
|
|
182
|
-
value,
|
|
183
|
-
value - previous,
|
|
184
|
-
reason,
|
|
185
|
-
JSON.stringify(sources),
|
|
186
|
-
origin,
|
|
187
|
-
nature.version,
|
|
188
|
-
);
|
|
189
|
-
return { id, value };
|
|
190
|
-
}
|
|
191
|
-
}
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { evidenceRoots, externalEvidence } from "./evidence.js";
|
|
3
|
+
import { lifeDayStart } from "./nature.js";
|
|
4
|
+
import { evidence, hasCredential, similar, text } from "./util.js";
|
|
5
|
+
|
|
6
|
+
export const LIVED_TRAITS = [
|
|
7
|
+
"warmth",
|
|
8
|
+
"sarcasm",
|
|
9
|
+
"humor",
|
|
10
|
+
"activity",
|
|
11
|
+
"initiative",
|
|
12
|
+
];
|
|
13
|
+
const TRAIT_HALF_LIFE = 180;
|
|
14
|
+
const DAILY_SHIFT_CAP = 4;
|
|
15
|
+
export function personaNeedsRephrase(content, mind) {
|
|
16
|
+
const value = String(content || "");
|
|
17
|
+
return (
|
|
18
|
+
value.length > 100 ||
|
|
19
|
+
/今天|昨天|明天|今晚|这几天|刚才|比如|下次|打完/.test(value) ||
|
|
20
|
+
!mind.meetings.sayable(value, "")
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Nature is the starting point. These small, cited changes are what she has
|
|
25
|
+
// actually learned about how she wants to show up; they belong to one self.
|
|
26
|
+
export class Traits {
|
|
27
|
+
constructor(mind) {
|
|
28
|
+
this.mind = mind;
|
|
29
|
+
this.db = mind.db;
|
|
30
|
+
}
|
|
31
|
+
current(nature = this.mind.nature.current(), before = Date.now()) {
|
|
32
|
+
const values = Object.fromEntries(
|
|
33
|
+
LIVED_TRAITS.map((key) => [key, Number(nature[key])]),
|
|
34
|
+
);
|
|
35
|
+
const rows = this.db
|
|
36
|
+
.prepare(
|
|
37
|
+
"SELECT trait,delta,created FROM mind_trait_changes WHERE nature_version=? AND created<=? ORDER BY created,rowid",
|
|
38
|
+
)
|
|
39
|
+
.all(nature.version, before);
|
|
40
|
+
const lived = this.mind.days.lived(before);
|
|
41
|
+
for (const row of rows) {
|
|
42
|
+
if (!LIVED_TRAITS.includes(row.trait)) continue;
|
|
43
|
+
values[row.trait] +=
|
|
44
|
+
row.delta * 0.5 ** (lived.since(row.created) / TRAIT_HALF_LIFE);
|
|
45
|
+
}
|
|
46
|
+
for (const trait of LIVED_TRAITS)
|
|
47
|
+
values[trait] = Math.max(0, Math.min(100, Math.round(values[trait])));
|
|
48
|
+
return values;
|
|
49
|
+
}
|
|
50
|
+
effective(nature = this.mind.nature.current(), before = Date.now()) {
|
|
51
|
+
const persona = this.persona(nature, before);
|
|
52
|
+
return {
|
|
53
|
+
...nature,
|
|
54
|
+
...this.current(nature, before),
|
|
55
|
+
...(persona ? { livedPersona: persona.content } : {}),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
persona(nature = this.mind.nature.current(), before = Date.now()) {
|
|
59
|
+
return (
|
|
60
|
+
this.db
|
|
61
|
+
.prepare(
|
|
62
|
+
"SELECT * FROM mind_persona_growth WHERE nature_version=? AND created<=? ORDER BY created DESC,rowid DESC LIMIT 1",
|
|
63
|
+
)
|
|
64
|
+
.get(nature.version, before) || null
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
personaHistory(limit = 15) {
|
|
68
|
+
return this.db
|
|
69
|
+
.prepare(
|
|
70
|
+
"SELECT * FROM mind_persona_growth ORDER BY created DESC,rowid DESC LIMIT ?",
|
|
71
|
+
)
|
|
72
|
+
.all(limit)
|
|
73
|
+
.map((row) => ({ ...row, sources: JSON.parse(row.sources) }));
|
|
74
|
+
}
|
|
75
|
+
proposePersona(
|
|
76
|
+
input,
|
|
77
|
+
{ valid, origin = "solitude", time = Date.now() } = {},
|
|
78
|
+
) {
|
|
79
|
+
const content = text(input?.content, 240);
|
|
80
|
+
if (
|
|
81
|
+
content.length < 12 ||
|
|
82
|
+
hasCredential(content) ||
|
|
83
|
+
personaNeedsRephrase(content, this.mind)
|
|
84
|
+
)
|
|
85
|
+
return { rejected: "不适合长期自述或含私下内容" };
|
|
86
|
+
const sources = evidence(input?.sources).filter(
|
|
87
|
+
(s) => !valid || valid.has(s),
|
|
88
|
+
);
|
|
89
|
+
if (!sources.length) return { rejected: "缺少亲历来源" };
|
|
90
|
+
const nature = this.mind.nature.current(time);
|
|
91
|
+
const previous = this.persona(nature, time);
|
|
92
|
+
const correcting =
|
|
93
|
+
previous && personaNeedsRephrase(previous.content, this.mind);
|
|
94
|
+
const grounded = externalEvidence(this.db, sources, time);
|
|
95
|
+
if (!correcting && !grounded.length)
|
|
96
|
+
return { rejected: "自述需要模型之外的新经历" };
|
|
97
|
+
if (previous && similar(content, previous.content, 0.85))
|
|
98
|
+
return { rejected: "没有实质变化" };
|
|
99
|
+
const spent = new Set(
|
|
100
|
+
this.db
|
|
101
|
+
.prepare(
|
|
102
|
+
"SELECT sources FROM mind_persona_growth WHERE nature_version=? AND created<=?",
|
|
103
|
+
)
|
|
104
|
+
.all(nature.version, time)
|
|
105
|
+
.flatMap((row) =>
|
|
106
|
+
evidenceRoots(this.db, JSON.parse(row.sources), time),
|
|
107
|
+
),
|
|
108
|
+
);
|
|
109
|
+
if (
|
|
110
|
+
previous &&
|
|
111
|
+
!personaNeedsRephrase(previous.content, this.mind) &&
|
|
112
|
+
!grounded.some((root) => !spent.has(root))
|
|
113
|
+
)
|
|
114
|
+
return { rejected: "没有新的亲历来源" };
|
|
115
|
+
const id = randomUUID();
|
|
116
|
+
this.db
|
|
117
|
+
.prepare(
|
|
118
|
+
"INSERT INTO mind_persona_growth(id,created,content,sources,origin,nature_version) VALUES (?,?,?,?,?,?)",
|
|
119
|
+
)
|
|
120
|
+
.run(id, time, content, JSON.stringify(sources), origin, nature.version);
|
|
121
|
+
return { id };
|
|
122
|
+
}
|
|
123
|
+
history(limit = 30) {
|
|
124
|
+
return this.db
|
|
125
|
+
.prepare(
|
|
126
|
+
"SELECT id,created,trait,value,delta,reason,sources,origin,nature_version FROM mind_trait_changes ORDER BY created DESC,rowid DESC LIMIT ?",
|
|
127
|
+
)
|
|
128
|
+
.all(limit)
|
|
129
|
+
.map((row) => ({ ...row, sources: JSON.parse(row.sources) }));
|
|
130
|
+
}
|
|
131
|
+
propose(input, { valid, origin = "solitude", time = Date.now() } = {}) {
|
|
132
|
+
const trait = String(input?.trait || "");
|
|
133
|
+
if (!LIVED_TRAITS.includes(trait)) return { rejected: "未知性格维度" };
|
|
134
|
+
const direction = Number(input?.direction);
|
|
135
|
+
if (!Number.isFinite(direction) || direction === 0)
|
|
136
|
+
return { rejected: "没有方向" };
|
|
137
|
+
const reason = text(input?.why, 180);
|
|
138
|
+
if (!reason || hasCredential(reason)) return { rejected: "缺少可用的理由" };
|
|
139
|
+
const sources = evidence(input?.sources).filter(
|
|
140
|
+
(s) => !valid || valid.has(s),
|
|
141
|
+
);
|
|
142
|
+
if (!sources.length) return { rejected: "缺少亲历来源" };
|
|
143
|
+
const nature = this.mind.nature.current(time);
|
|
144
|
+
const grounded = externalEvidence(this.db, sources, time);
|
|
145
|
+
if (!grounded.length) return { rejected: "性格变化需要模型之外的经历" };
|
|
146
|
+
const spent = new Set(
|
|
147
|
+
this.db
|
|
148
|
+
.prepare(
|
|
149
|
+
"SELECT sources FROM mind_trait_changes WHERE trait=? AND nature_version=?",
|
|
150
|
+
)
|
|
151
|
+
.all(trait, nature.version)
|
|
152
|
+
.flatMap((row) =>
|
|
153
|
+
evidenceRoots(this.db, JSON.parse(row.sources), time),
|
|
154
|
+
),
|
|
155
|
+
);
|
|
156
|
+
if (!grounded.some((source) => !spent.has(source)))
|
|
157
|
+
return { rejected: "这段经历已经改变过它" };
|
|
158
|
+
const previous = this.current(nature, time)[trait];
|
|
159
|
+
const start = lifeDayStart(nature, time, this.mind.timeZone());
|
|
160
|
+
const used = this.db
|
|
161
|
+
.prepare(
|
|
162
|
+
"SELECT COALESCE(SUM(ABS(delta)),0) n FROM mind_trait_changes WHERE trait=? AND nature_version=? AND created>=? AND created<=?",
|
|
163
|
+
)
|
|
164
|
+
.get(trait, nature.version, start, time).n;
|
|
165
|
+
const allowance = Math.max(0, DAILY_SHIFT_CAP - used);
|
|
166
|
+
if (!allowance) return { rejected: "今天这项性格已经改变过,留些时间检验" };
|
|
167
|
+
// A single reflection may nudge a tendency, never replace her overnight.
|
|
168
|
+
const delta =
|
|
169
|
+
Math.sign(direction) *
|
|
170
|
+
Math.min(allowance, Math.max(1, Math.round(Math.abs(direction))));
|
|
171
|
+
const value = Math.max(0, Math.min(100, previous + delta));
|
|
172
|
+
if (value === previous) return { rejected: "已到边界" };
|
|
173
|
+
const id = randomUUID();
|
|
174
|
+
this.db
|
|
175
|
+
.prepare(
|
|
176
|
+
"INSERT INTO mind_trait_changes(id,created,trait,value,delta,reason,sources,origin,nature_version) VALUES (?,?,?,?,?,?,?,?,?)",
|
|
177
|
+
)
|
|
178
|
+
.run(
|
|
179
|
+
id,
|
|
180
|
+
time,
|
|
181
|
+
trait,
|
|
182
|
+
value,
|
|
183
|
+
value - previous,
|
|
184
|
+
reason,
|
|
185
|
+
JSON.stringify(sources),
|
|
186
|
+
origin,
|
|
187
|
+
nature.version,
|
|
188
|
+
);
|
|
189
|
+
return { id, value };
|
|
190
|
+
}
|
|
191
|
+
}
|
package/server/mind/view.js
CHANGED
|
@@ -5,6 +5,7 @@ import { agoLabel, elapsedLabel } from "./clock.js";
|
|
|
5
5
|
import { describeFace } from "./faces.js";
|
|
6
6
|
import { SELF_KINDS } from "./self.js";
|
|
7
7
|
import { DAY, text } from "./util.js";
|
|
8
|
+
import { relationshipHistory } from "./relationship-context.js";
|
|
8
9
|
|
|
9
10
|
const FORGOTTEN = "(很久没想起了)";
|
|
10
11
|
|
|
@@ -89,6 +90,12 @@ export function innerView(
|
|
|
89
90
|
const face = mind.faces.current(session, now);
|
|
90
91
|
const living = mind.self.living({ before: now, now, room: session });
|
|
91
92
|
const cues = speakerCues(cue);
|
|
93
|
+
const relationships = mind.relationships.context({
|
|
94
|
+
room: session,
|
|
95
|
+
people,
|
|
96
|
+
cue,
|
|
97
|
+
now,
|
|
98
|
+
});
|
|
92
99
|
const carries = (thread) => mind.meetings.stays(thread, session, now);
|
|
93
100
|
const visibleThreads = relevantContext(
|
|
94
101
|
mind.self
|
|
@@ -150,7 +157,7 @@ export function innerView(
|
|
|
150
157
|
? {
|
|
151
158
|
threads: visibleThreads.map(
|
|
152
159
|
(t) =>
|
|
153
|
-
`${SELF_KINDS[t.kind]}:${text(t.content, 80)}${t.status === "emerging" ? "(刚开始有这种感觉)" : ""}`,
|
|
160
|
+
`${SELF_KINDS[t.kind]}:${relationshipHistory(text(t.content, 80), t.created, relationships)}${t.status === "emerging" ? "(刚开始有这种感觉)" : ""}`,
|
|
154
161
|
),
|
|
155
162
|
}
|
|
156
163
|
: {}),
|
|
@@ -254,6 +261,7 @@ export function innerView(
|
|
|
254
261
|
currentLife: mind.time.view({ session, now, cue }),
|
|
255
262
|
state: `${affect.phaseLabel},精力${affect.energyLabel},心情${affect.mood}${cause ? `(${cause})` : ""}${affect.lately ? `,${affect.lately}` : ""}`,
|
|
256
263
|
...(persons.length ? { people: persons } : {}),
|
|
264
|
+
...(relationships.known.length ? { relationships } : {}),
|
|
257
265
|
...(continuity ? { continuity } : {}),
|
|
258
266
|
...(group ? { thisGroup: group.feel } : {}),
|
|
259
267
|
...(thoughts.length
|
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
import {
|
|
2
|
-
existsSync,
|
|
3
|
-
lstatSync,
|
|
4
|
-
mkdirSync,
|
|
5
|
-
readFileSync,
|
|
6
|
-
realpathSync,
|
|
7
|
-
readdirSync,
|
|
8
|
-
renameSync,
|
|
9
|
-
rmdirSync,
|
|
10
|
-
writeFileSync,
|
|
11
|
-
unlinkSync,
|
|
12
|
-
} from "node:fs";
|
|
13
|
-
import { join, relative, isAbsolute } from "node:path";
|
|
14
|
-
import { randomUUID } from "node:crypto";
|
|
15
|
-
import { compareVersions } from "../studio/updates.js";
|
|
16
|
-
export const UPDATE_ID =
|
|
17
|
-
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
|
|
18
|
-
export const updateRoot = (home) => join(home, "runtime");
|
|
19
|
-
export function updatePath(home, id) {
|
|
20
|
-
if (!UPDATE_ID.test(String(id))) throw Error("更新任务无效");
|
|
21
|
-
const root = updateRoot(home),
|
|
22
|
-
path = join(root, "releases", id);
|
|
23
|
-
// Managed paths cannot be symlinked into an unrelated installation.
|
|
24
|
-
for (const p of [root, join(root, "releases"), path])
|
|
25
|
-
if (existsSync(p) && lstatSync(p).isSymbolicLink())
|
|
26
|
-
throw Error("更新目录无效");
|
|
27
|
-
return path;
|
|
28
|
-
}
|
|
29
|
-
export function readActive(home) {
|
|
30
|
-
try {
|
|
31
|
-
return JSON.parse(
|
|
32
|
-
readFileSync(join(updateRoot(home), "active.json"), "utf8"),
|
|
33
|
-
);
|
|
34
|
-
} catch {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export function atomicJson(file, value) {
|
|
39
|
-
const tmp = `${file}.${randomUUID()}.partial`;
|
|
40
|
-
try {
|
|
41
|
-
writeFileSync(tmp, JSON.stringify(value), {
|
|
42
|
-
mode: 0o600,
|
|
43
|
-
flag: "wx",
|
|
44
|
-
flush: true,
|
|
45
|
-
});
|
|
46
|
-
renameSync(tmp, file);
|
|
47
|
-
} finally {
|
|
48
|
-
if (existsSync(tmp)) unlinkSync(tmp);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export function writeActive(home, value) {
|
|
52
|
-
const root = updateRoot(home);
|
|
53
|
-
if (value) updatePath(home, value.id);
|
|
54
|
-
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
55
|
-
if (value) atomicJson(join(root, "active.json"), value);
|
|
56
|
-
else if (existsSync(join(root, "active.json")))
|
|
57
|
-
unlinkSync(join(root, "active.json"));
|
|
58
|
-
}
|
|
59
|
-
export function installedRelease(home, id, version) {
|
|
60
|
-
const slot = updatePath(home, id),
|
|
61
|
-
root = join(slot, "node_modules", "luckytri");
|
|
62
|
-
const part = relative(realpathSync(slot), realpathSync(root));
|
|
63
|
-
if (part.startsWith("..") || isAbsolute(part)) throw Error("更新目录无效");
|
|
64
|
-
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
65
|
-
if (
|
|
66
|
-
pkg.name !== "luckytri" ||
|
|
67
|
-
pkg.version !== version ||
|
|
68
|
-
!existsSync(join(root, "server", "index.js")) ||
|
|
69
|
-
!existsSync(join(root, "public", "app", "index.html"))
|
|
70
|
-
)
|
|
71
|
-
throw Error("更新程序校验失败");
|
|
72
|
-
return root;
|
|
73
|
-
}
|
|
74
|
-
export function resolveInstallation(home, basePackage, baseVersion) {
|
|
75
|
-
const active = readActive(home);
|
|
76
|
-
if (active) {
|
|
77
|
-
try {
|
|
78
|
-
// An explicit newer/equal global npm or source install takes precedence.
|
|
79
|
-
if (compareVersions(active.version, baseVersion) > 0)
|
|
80
|
-
return {
|
|
81
|
-
package: installedRelease(home, active.id, active.version),
|
|
82
|
-
version: active.version,
|
|
83
|
-
};
|
|
84
|
-
} catch {
|
|
85
|
-
/* Invalid receipts never route the launcher to arbitrary code. */
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return { package: basePackage, version: baseVersion };
|
|
89
|
-
}
|
|
90
|
-
export function pruneInstallations(home, keep) {
|
|
91
|
-
const root = join(updateRoot(home), "releases");
|
|
92
|
-
if (!existsSync(root)) return;
|
|
93
|
-
for (const entry of readdirSync(root, { withFileTypes: true })) {
|
|
94
|
-
if (
|
|
95
|
-
!entry.isDirectory() ||
|
|
96
|
-
!UPDATE_ID.test(entry.name) ||
|
|
97
|
-
keep.includes(entry.name)
|
|
98
|
-
)
|
|
99
|
-
continue;
|
|
100
|
-
const path = updatePath(home, entry.name),
|
|
101
|
-
part = relative(realpathSync(root), realpathSync(path));
|
|
102
|
-
if (!part || part.startsWith("..") || isAbsolute(part))
|
|
103
|
-
throw Error("更新目录无效");
|
|
104
|
-
// File removal uses unlink, including Unicode/short Windows paths where
|
|
105
|
-
// recursive rm can return without actually removing a lock or directory.
|
|
106
|
-
const remove = (directory) => {
|
|
107
|
-
for (const child of readdirSync(directory, { withFileTypes: true })) {
|
|
108
|
-
const target = join(directory, child.name);
|
|
109
|
-
if (child.isDirectory() && !child.isSymbolicLink()) remove(target);
|
|
110
|
-
else unlinkSync(target);
|
|
111
|
-
}
|
|
112
|
-
rmdirSync(directory);
|
|
113
|
-
};
|
|
114
|
-
remove(path);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
lstatSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
realpathSync,
|
|
7
|
+
readdirSync,
|
|
8
|
+
renameSync,
|
|
9
|
+
rmdirSync,
|
|
10
|
+
writeFileSync,
|
|
11
|
+
unlinkSync,
|
|
12
|
+
} from "node:fs";
|
|
13
|
+
import { join, relative, isAbsolute } from "node:path";
|
|
14
|
+
import { randomUUID } from "node:crypto";
|
|
15
|
+
import { compareVersions } from "../studio/updates.js";
|
|
16
|
+
export const UPDATE_ID =
|
|
17
|
+
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
|
|
18
|
+
export const updateRoot = (home) => join(home, "runtime");
|
|
19
|
+
export function updatePath(home, id) {
|
|
20
|
+
if (!UPDATE_ID.test(String(id))) throw Error("更新任务无效");
|
|
21
|
+
const root = updateRoot(home),
|
|
22
|
+
path = join(root, "releases", id);
|
|
23
|
+
// Managed paths cannot be symlinked into an unrelated installation.
|
|
24
|
+
for (const p of [root, join(root, "releases"), path])
|
|
25
|
+
if (existsSync(p) && lstatSync(p).isSymbolicLink())
|
|
26
|
+
throw Error("更新目录无效");
|
|
27
|
+
return path;
|
|
28
|
+
}
|
|
29
|
+
export function readActive(home) {
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(
|
|
32
|
+
readFileSync(join(updateRoot(home), "active.json"), "utf8"),
|
|
33
|
+
);
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function atomicJson(file, value) {
|
|
39
|
+
const tmp = `${file}.${randomUUID()}.partial`;
|
|
40
|
+
try {
|
|
41
|
+
writeFileSync(tmp, JSON.stringify(value), {
|
|
42
|
+
mode: 0o600,
|
|
43
|
+
flag: "wx",
|
|
44
|
+
flush: true,
|
|
45
|
+
});
|
|
46
|
+
renameSync(tmp, file);
|
|
47
|
+
} finally {
|
|
48
|
+
if (existsSync(tmp)) unlinkSync(tmp);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export function writeActive(home, value) {
|
|
52
|
+
const root = updateRoot(home);
|
|
53
|
+
if (value) updatePath(home, value.id);
|
|
54
|
+
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
55
|
+
if (value) atomicJson(join(root, "active.json"), value);
|
|
56
|
+
else if (existsSync(join(root, "active.json")))
|
|
57
|
+
unlinkSync(join(root, "active.json"));
|
|
58
|
+
}
|
|
59
|
+
export function installedRelease(home, id, version) {
|
|
60
|
+
const slot = updatePath(home, id),
|
|
61
|
+
root = join(slot, "node_modules", "luckytri");
|
|
62
|
+
const part = relative(realpathSync(slot), realpathSync(root));
|
|
63
|
+
if (part.startsWith("..") || isAbsolute(part)) throw Error("更新目录无效");
|
|
64
|
+
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
65
|
+
if (
|
|
66
|
+
pkg.name !== "luckytri" ||
|
|
67
|
+
pkg.version !== version ||
|
|
68
|
+
!existsSync(join(root, "server", "index.js")) ||
|
|
69
|
+
!existsSync(join(root, "public", "app", "index.html"))
|
|
70
|
+
)
|
|
71
|
+
throw Error("更新程序校验失败");
|
|
72
|
+
return root;
|
|
73
|
+
}
|
|
74
|
+
export function resolveInstallation(home, basePackage, baseVersion) {
|
|
75
|
+
const active = readActive(home);
|
|
76
|
+
if (active) {
|
|
77
|
+
try {
|
|
78
|
+
// An explicit newer/equal global npm or source install takes precedence.
|
|
79
|
+
if (compareVersions(active.version, baseVersion) > 0)
|
|
80
|
+
return {
|
|
81
|
+
package: installedRelease(home, active.id, active.version),
|
|
82
|
+
version: active.version,
|
|
83
|
+
};
|
|
84
|
+
} catch {
|
|
85
|
+
/* Invalid receipts never route the launcher to arbitrary code. */
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return { package: basePackage, version: baseVersion };
|
|
89
|
+
}
|
|
90
|
+
export function pruneInstallations(home, keep) {
|
|
91
|
+
const root = join(updateRoot(home), "releases");
|
|
92
|
+
if (!existsSync(root)) return;
|
|
93
|
+
for (const entry of readdirSync(root, { withFileTypes: true })) {
|
|
94
|
+
if (
|
|
95
|
+
!entry.isDirectory() ||
|
|
96
|
+
!UPDATE_ID.test(entry.name) ||
|
|
97
|
+
keep.includes(entry.name)
|
|
98
|
+
)
|
|
99
|
+
continue;
|
|
100
|
+
const path = updatePath(home, entry.name),
|
|
101
|
+
part = relative(realpathSync(root), realpathSync(path));
|
|
102
|
+
if (!part || part.startsWith("..") || isAbsolute(part))
|
|
103
|
+
throw Error("更新目录无效");
|
|
104
|
+
// File removal uses unlink, including Unicode/short Windows paths where
|
|
105
|
+
// recursive rm can return without actually removing a lock or directory.
|
|
106
|
+
const remove = (directory) => {
|
|
107
|
+
for (const child of readdirSync(directory, { withFileTypes: true })) {
|
|
108
|
+
const target = join(directory, child.name);
|
|
109
|
+
if (child.isDirectory() && !child.isSymbolicLink()) remove(target);
|
|
110
|
+
else unlinkSync(target);
|
|
111
|
+
}
|
|
112
|
+
rmdirSync(directory);
|
|
113
|
+
};
|
|
114
|
+
remove(path);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -62,7 +62,7 @@ export async function performUpdate(
|
|
|
62
62
|
writeActive(paths.home, { id, version: job.version });
|
|
63
63
|
changed = true;
|
|
64
64
|
child = await start(candidate);
|
|
65
|
-
save("verifying");
|
|
65
|
+
save("verifying", { childPid: child });
|
|
66
66
|
await health(child, job.version);
|
|
67
67
|
save("done", { finished: Date.now() });
|
|
68
68
|
try {
|
|
@@ -115,6 +115,7 @@ export async function performUpdate(
|
|
|
115
115
|
save("error", {
|
|
116
116
|
error: UPDATE_FAILED,
|
|
117
117
|
restored: true,
|
|
118
|
+
childPid: restored,
|
|
118
119
|
finished: Date.now(),
|
|
119
120
|
});
|
|
120
121
|
} catch {
|