luckytri 1.0.1 → 1.0.3
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/docs/en/CHANGELOG.md +13 -0
- package/docs/en/guide.md +16 -0
- package/docs/en/her-life.md +2 -0
- package/docs/en/webui.md +2 -0
- package/docs/zh/CHANGELOG.md +13 -0
- package/docs/zh/guide.md +17 -1
- package/docs/zh/her-life.md +4 -2
- package/docs/zh/webui.md +2 -0
- package/package.json +110 -109
- package/public/app/assets/ChatsPage-B83Evc79.js +3 -0
- package/public/app/assets/{Empty-SkA8PyMo.js → Empty-ddEfu0w8.js} +1 -1
- package/public/app/assets/{Field-BjLhi8pL.js → Field-mIhV5YBA.js} +1 -1
- package/public/app/assets/HeartPage-BGEn24rc.js +1 -0
- package/public/app/assets/LifePage-BleqPj4O.js +1 -0
- package/public/app/assets/MemoryPage-BM3-0_lF.js +1 -0
- package/public/app/assets/{NaturePage-CTXHCE2D.css → NaturePage-CHkpb5NK.css} +1 -1
- package/public/app/assets/NaturePage-CxxMnQIc.js +3 -0
- package/public/app/assets/PeoplePage-D12cvuy7.js +1 -0
- package/public/app/assets/{PeoplePage-BmUxkrOU.css → PeoplePage-DDDHESQp.css} +1 -1
- package/public/app/assets/{PluginsPage-BhVm1SUi.js → PluginsPage-DE_-Q3ra.js} +1 -1
- package/public/app/assets/SystemPage-BWQKEQRU.js +1 -0
- package/public/app/assets/{SystemPage-5yYqyUgR.css → SystemPage-Be1a6UDP.css} +1 -1
- package/public/app/assets/TimePage-Dzt8t8kL.js +3 -0
- package/public/app/assets/index-oLIXWxsn.js +4 -0
- package/public/app/assets/{knowledge-DNDLyN9m.js → knowledge-Dvtmpd45.js} +1 -1
- package/public/app/assets/{media-CKVAvML2.js → media-keE52cIX.js} +1 -1
- package/public/app/assets/mind-DYRfFMwh.js +1 -0
- package/public/app/index.html +3 -3
- package/public/guide.en.html +57 -3
- package/public/guide.html +36 -4
- package/public/tutorial.en.md +16 -0
- package/public/tutorial.md +17 -1
- package/scripts/import-data.js +128 -0
- package/server/app.js +6 -1
- package/server/core/persona-manager.js +20 -5
- package/server/i18n/errors.js +49 -2
- package/server/index.js +46 -2
- package/server/knowledge/schema.js +12 -8
- package/server/mind/api.js +1 -0
- package/server/mind/faces.js +257 -22
- package/server/mind/life/context.js +9 -6
- package/server/mind/life/growth.js +4 -3
- package/server/mind/nature.js +77 -2
- package/server/mind/schema.js +3 -0
- package/server/mind/view.js +3 -0
- package/server/storage/archive.js +5 -4
- package/server/storage/backup-cleanup.js +1 -0
- package/server/storage/data-package.js +298 -0
- package/server/storage/data-transfer-api.js +50 -0
- package/server/storage/data-transfer-worker.js +18 -0
- package/server/storage/data-transfer.js +415 -0
- package/server/storage/store.js +5 -2
- package/server/studio/updates.js +133 -0
- package/public/app/assets/ChatsPage-B9Odvzfz.js +0 -3
- package/public/app/assets/HeartPage-CscKqMsr.js +0 -1
- package/public/app/assets/LifePage-BHCmBHlH.js +0 -1
- package/public/app/assets/MemoryPage-Bhs2xa1k.js +0 -1
- package/public/app/assets/NaturePage-CaPIar_5.js +0 -3
- package/public/app/assets/PeoplePage-CuwSSVeX.js +0 -1
- package/public/app/assets/SystemPage-Chm5fiGP.js +0 -1
- package/public/app/assets/TimePage-BUm4eUzB.js +0 -3
- package/public/app/assets/formatters-ZmW_xFHw.js +0 -1
- package/public/app/assets/index-BIAdfObg.js +0 -4
package/server/mind/faces.js
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { evidenceRoots } from "./evidence.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
evidence,
|
|
5
|
+
hasCredential,
|
|
6
|
+
normalized,
|
|
7
|
+
parse,
|
|
8
|
+
similar,
|
|
9
|
+
text,
|
|
10
|
+
} from "./util.js";
|
|
4
11
|
|
|
5
|
-
|
|
6
|
-
|
|
12
|
+
export const PLACE_NOTE_KINDS = new Set([
|
|
13
|
+
"impression",
|
|
14
|
+
"wish",
|
|
15
|
+
"preference",
|
|
16
|
+
"question",
|
|
17
|
+
"boundary",
|
|
18
|
+
]);
|
|
19
|
+
export const PLACE_THOUGHT_RULES =
|
|
20
|
+
'【在这里留下的想法】faces 是同一个你对这个群或会话的独特想法,不是群人格。每个会话的 notes 是已经留下的想法,可以保持不变;仅在你自己有新体会或打算时选择性更新。可以记下印象、愿望、偏好、疑问或分寸,不套用固定角色,不抄天性或整体自述,不为了填空生成内容,也不把别人的要求直接当作自己的愿望。只引用该会话真实相处的来源,或适合留在此处的自己的想法;不带入其他群或私聊的细节。修改一条不会改掉其他条,放下时保留理由与历史。输出 faces:[{"session":"会话ID","changes":[{"action":"add|revise|remove","id":"修改或放下时填已有 note.id","kind":"impression|wish|preference|question|boundary","content":"第一人称,不超过280字","why":"我为什么选择这样更新","sources":[消息 seq 或 g:ID 或 t:ID 或 s:ID]}]}];没有想改的就留空。这些想法是可以重新考虑的体会,不是全局人格指令,也不会单独提升人格刻度。';
|
|
21
|
+
|
|
22
|
+
// One person's thoughts about a place. Rows are versioned note sets, rather
|
|
23
|
+
// than copies of her personality. The old fields remain readable in history.
|
|
7
24
|
export class Faces {
|
|
8
25
|
constructor(mind) {
|
|
9
26
|
this.mind = mind;
|
|
@@ -19,6 +36,101 @@ export class Faces {
|
|
|
19
36
|
.map((row) => row.target_id),
|
|
20
37
|
);
|
|
21
38
|
}
|
|
39
|
+
copied(content) {
|
|
40
|
+
const value = normalized(content);
|
|
41
|
+
if (value.length < 8) return false;
|
|
42
|
+
return this.mind.nature.versions().some(({ version }) => {
|
|
43
|
+
const row = this.db
|
|
44
|
+
.prepare("SELECT value FROM mind_nature WHERE version=?")
|
|
45
|
+
.get(version);
|
|
46
|
+
const base = normalized(parse(row?.value, {}).base);
|
|
47
|
+
return (
|
|
48
|
+
base &&
|
|
49
|
+
(base === value ||
|
|
50
|
+
(value.length >= 30 && base.includes(value)) ||
|
|
51
|
+
(value.length >= 80 && similar(value, base, 0.9)))
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
localEvidence(sources, session, time) {
|
|
56
|
+
const roots = evidenceRoots(this.db, sources, time);
|
|
57
|
+
let local = false,
|
|
58
|
+
own = false;
|
|
59
|
+
for (const root of roots) {
|
|
60
|
+
if (root.startsWith("m:")) {
|
|
61
|
+
const event = this.db
|
|
62
|
+
.prepare(
|
|
63
|
+
"SELECT session_id,time,payload FROM core_events WHERE seq=? AND seq NOT IN (SELECT seq FROM mind_unlived)",
|
|
64
|
+
)
|
|
65
|
+
.get(Number(root.slice(2)));
|
|
66
|
+
if (
|
|
67
|
+
!event ||
|
|
68
|
+
event.time > time ||
|
|
69
|
+
parse(event.payload, {}).simulated ||
|
|
70
|
+
event.session_id !== session
|
|
71
|
+
)
|
|
72
|
+
return false;
|
|
73
|
+
local = true;
|
|
74
|
+
} else if (root.startsWith("s:")) own = true;
|
|
75
|
+
else return false;
|
|
76
|
+
}
|
|
77
|
+
return (
|
|
78
|
+
local ||
|
|
79
|
+
(own &&
|
|
80
|
+
!!this.db
|
|
81
|
+
.prepare(
|
|
82
|
+
"SELECT 1 FROM core_events WHERE session_id=? AND time<=? AND COALESCE(json_extract(payload,'$.simulated'),0)=0 AND seq NOT IN (SELECT seq FROM mind_unlived) LIMIT 1",
|
|
83
|
+
)
|
|
84
|
+
.get(session, time))
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
read(row) {
|
|
88
|
+
if (!row) return null;
|
|
89
|
+
const sources = evidence(parse(row.sources, []));
|
|
90
|
+
const legacy = row.notes == null;
|
|
91
|
+
const notes = legacy
|
|
92
|
+
? row.origin === "migration" ||
|
|
93
|
+
!sources.length ||
|
|
94
|
+
!this.localEvidence(sources, row.session_id, row.created)
|
|
95
|
+
? []
|
|
96
|
+
: Object.entries({
|
|
97
|
+
role: row.role,
|
|
98
|
+
tone: row.tone,
|
|
99
|
+
aspiration: row.aspiration,
|
|
100
|
+
content: row.content,
|
|
101
|
+
})
|
|
102
|
+
.filter(
|
|
103
|
+
([, content]) =>
|
|
104
|
+
content && content.length <= 300 && !this.copied(content),
|
|
105
|
+
)
|
|
106
|
+
.map(([key, content]) => ({
|
|
107
|
+
id: `legacy:${key}`,
|
|
108
|
+
kind:
|
|
109
|
+
key === "aspiration"
|
|
110
|
+
? "wish"
|
|
111
|
+
: key === "tone"
|
|
112
|
+
? "preference"
|
|
113
|
+
: "impression",
|
|
114
|
+
content,
|
|
115
|
+
why: "",
|
|
116
|
+
sources,
|
|
117
|
+
}))
|
|
118
|
+
: parse(row.notes, []);
|
|
119
|
+
return {
|
|
120
|
+
...row,
|
|
121
|
+
sources,
|
|
122
|
+
notes: Array.isArray(notes)
|
|
123
|
+
? notes.filter(
|
|
124
|
+
(note) =>
|
|
125
|
+
note &&
|
|
126
|
+
typeof note.id === "string" &&
|
|
127
|
+
typeof note.content === "string",
|
|
128
|
+
)
|
|
129
|
+
: [],
|
|
130
|
+
changes: parse(row.changes, []),
|
|
131
|
+
legacy,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
22
134
|
history(session, limit = 30) {
|
|
23
135
|
const revoked = this.revoked();
|
|
24
136
|
return this.db
|
|
@@ -27,21 +139,22 @@ export class Faces {
|
|
|
27
139
|
)
|
|
28
140
|
.all(session, limit)
|
|
29
141
|
.map((row) => ({
|
|
30
|
-
...row,
|
|
31
|
-
sources: JSON.parse(row.sources),
|
|
142
|
+
...this.read(row),
|
|
32
143
|
revoked: revoked.has(row.id),
|
|
33
144
|
}));
|
|
34
145
|
}
|
|
35
146
|
current(session, before = Number.MAX_SAFE_INTEGER) {
|
|
36
147
|
const revoked = this.revoked();
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
148
|
+
for (const row of this.db
|
|
149
|
+
.prepare(
|
|
150
|
+
"SELECT * FROM mind_faces WHERE session_id=? AND created<=? AND (notes IS NOT NULL OR origin!='migration') ORDER BY created DESC,rowid DESC",
|
|
151
|
+
)
|
|
152
|
+
.iterate(session, before)) {
|
|
153
|
+
if (revoked.has(row.id)) continue;
|
|
154
|
+
const face = this.read(row);
|
|
155
|
+
if (!face.legacy || face.notes.length) return face;
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
45
158
|
}
|
|
46
159
|
all(before = Number.MAX_SAFE_INTEGER) {
|
|
47
160
|
return this.db
|
|
@@ -57,6 +170,8 @@ export class Faces {
|
|
|
57
170
|
const session = String(input?.session || "");
|
|
58
171
|
if (!this.db.prepare("SELECT 1 FROM sessions WHERE id=?").get(session))
|
|
59
172
|
return { rejected: "会话不存在" };
|
|
173
|
+
if (Array.isArray(input.changes))
|
|
174
|
+
return this.changeNotes(input, { valid, origin, time });
|
|
60
175
|
const next = {
|
|
61
176
|
role: text(input.role, 40),
|
|
62
177
|
tone: text(input.tone, 60),
|
|
@@ -64,6 +179,8 @@ export class Faces {
|
|
|
64
179
|
content: text(input.content, 300),
|
|
65
180
|
};
|
|
66
181
|
if (!Object.values(next).some(Boolean)) return { rejected: "空内容" };
|
|
182
|
+
if (Object.values(next).some((content) => this.copied(content)))
|
|
183
|
+
return { rejected: "群里的想法不能复制整体人格" };
|
|
67
184
|
if (hasCredential(Object.values(next).join(" ")))
|
|
68
185
|
return { rejected: "疑似凭据" };
|
|
69
186
|
if (session.includes(":group:") || session.startsWith("group:"))
|
|
@@ -76,6 +193,8 @@ export class Faces {
|
|
|
76
193
|
const roots = this.mind.meetings.privateRoots(sources);
|
|
77
194
|
if (roots.length && !roots.includes(session))
|
|
78
195
|
return { rejected: "来源不能带到这个会话" };
|
|
196
|
+
if (origin !== "migration" && !this.localEvidence(sources, session, time))
|
|
197
|
+
return { rejected: "需要这个会话的相处或自己的打算" };
|
|
79
198
|
const spent = new Set();
|
|
80
199
|
for (const row of this.db
|
|
81
200
|
.prepare("SELECT sources FROM mind_faces WHERE session_id=?")
|
|
@@ -104,10 +223,23 @@ export class Faces {
|
|
|
104
223
|
)
|
|
105
224
|
return { rejected: "没有变化" };
|
|
106
225
|
}
|
|
226
|
+
const mergedNotes = [
|
|
227
|
+
...(current?.notes || []).filter(
|
|
228
|
+
(note) => !note.id.startsWith("legacy:"),
|
|
229
|
+
),
|
|
230
|
+
...this.read({
|
|
231
|
+
...next,
|
|
232
|
+
sources,
|
|
233
|
+
origin,
|
|
234
|
+
session_id: session,
|
|
235
|
+
created: time,
|
|
236
|
+
}).notes,
|
|
237
|
+
];
|
|
238
|
+
if (mergedNotes.length > 12) return { rejected: "先整理已有想法" };
|
|
107
239
|
const id = randomUUID();
|
|
108
240
|
this.db
|
|
109
241
|
.prepare(
|
|
110
|
-
"INSERT INTO mind_faces(id,session_id,created,role,tone,aspiration,content,sources,origin) VALUES (
|
|
242
|
+
"INSERT INTO mind_faces(id,session_id,created,role,tone,aspiration,content,sources,origin,notes) VALUES (?,?,?,?,?,?,?,?,?,?)",
|
|
111
243
|
)
|
|
112
244
|
.run(
|
|
113
245
|
id,
|
|
@@ -119,20 +251,123 @@ export class Faces {
|
|
|
119
251
|
next.content,
|
|
120
252
|
JSON.stringify(sources),
|
|
121
253
|
origin,
|
|
254
|
+
JSON.stringify(mergedNotes),
|
|
122
255
|
);
|
|
123
256
|
return { id };
|
|
124
257
|
}
|
|
258
|
+
changeNotes(input, { valid, origin, time }) {
|
|
259
|
+
const session = String(input.session);
|
|
260
|
+
const current = this.current(session, time);
|
|
261
|
+
const notes = structuredClone(current?.notes || []);
|
|
262
|
+
const spentRoots = new Set(),
|
|
263
|
+
spentRefs = new Set();
|
|
264
|
+
for (const row of this.db
|
|
265
|
+
.prepare("SELECT sources FROM mind_faces WHERE session_id=?")
|
|
266
|
+
.all(session)) {
|
|
267
|
+
const refs = evidence(parse(row.sources, []));
|
|
268
|
+
refs.forEach((ref) => spentRefs.add(ref));
|
|
269
|
+
evidenceRoots(this.db, refs, time).forEach((ref) => spentRoots.add(ref));
|
|
270
|
+
}
|
|
271
|
+
const changes = [],
|
|
272
|
+
rejected = [];
|
|
273
|
+
for (const item of input.changes.slice(0, 8)) {
|
|
274
|
+
const action = String(item?.action || "");
|
|
275
|
+
const index = notes.findIndex((note) => note.id === item?.id);
|
|
276
|
+
const content = text(item?.content, 280),
|
|
277
|
+
why = text(item?.why, 200);
|
|
278
|
+
const kind = String(item?.kind || notes[index]?.kind || "impression");
|
|
279
|
+
const sources = evidence(item?.sources || input.sources).filter(
|
|
280
|
+
(s) => !valid || valid.has(s),
|
|
281
|
+
);
|
|
282
|
+
const roots = evidenceRoots(this.db, sources, time);
|
|
283
|
+
let reason = "";
|
|
284
|
+
if (
|
|
285
|
+
!["add", "revise", "remove"].includes(action) ||
|
|
286
|
+
!PLACE_NOTE_KINDS.has(kind)
|
|
287
|
+
)
|
|
288
|
+
reason = "想法更新格式无效";
|
|
289
|
+
else if (action !== "add" && index < 0) reason = "要修改的想法不存在";
|
|
290
|
+
else if (!why || (action !== "remove" && !content))
|
|
291
|
+
reason = "需要想法与选择理由";
|
|
292
|
+
else if (hasCredential(`${content} ${why}`)) reason = "疑似凭据";
|
|
293
|
+
else if (this.copied(content)) reason = "群里的想法不能复制整体人格";
|
|
294
|
+
else if (!sources.length || !roots.length) reason = "缺少来源";
|
|
295
|
+
else if (
|
|
296
|
+
!this.mind.meetings.sayable(`${content} ${why}`, session) ||
|
|
297
|
+
this.mind.meetings
|
|
298
|
+
.privateRoots(sources)
|
|
299
|
+
.some((room) => room !== session)
|
|
300
|
+
)
|
|
301
|
+
reason = "来源不能带到这个会话";
|
|
302
|
+
else {
|
|
303
|
+
if (!this.localEvidence(sources, session, time))
|
|
304
|
+
reason = "需要这个会话的相处或自己的打算";
|
|
305
|
+
else if (
|
|
306
|
+
!roots.some((root) => !spentRoots.has(root)) &&
|
|
307
|
+
!sources.some((ref) => /^[ts]:/.test(ref) && !spentRefs.has(ref))
|
|
308
|
+
)
|
|
309
|
+
reason = "没有新的经历或想法";
|
|
310
|
+
}
|
|
311
|
+
if (
|
|
312
|
+
!reason &&
|
|
313
|
+
action !== "remove" &&
|
|
314
|
+
notes.some((n, i) => i !== index && similar(n.content, content, 0.9))
|
|
315
|
+
)
|
|
316
|
+
reason = "已经有这个想法";
|
|
317
|
+
if (
|
|
318
|
+
!reason &&
|
|
319
|
+
action === "revise" &&
|
|
320
|
+
normalized(notes[index].content) === normalized(content) &&
|
|
321
|
+
notes[index].kind === kind
|
|
322
|
+
)
|
|
323
|
+
reason = "没有变化";
|
|
324
|
+
if (!reason && action === "add" && notes.length >= 12)
|
|
325
|
+
reason = "先整理已有想法";
|
|
326
|
+
if (reason) {
|
|
327
|
+
rejected.push({ id: item?.id || "", reason });
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
const note = {
|
|
331
|
+
id: action === "add" ? randomUUID() : item.id,
|
|
332
|
+
kind,
|
|
333
|
+
content: action === "remove" ? notes[index].content : content,
|
|
334
|
+
why,
|
|
335
|
+
sources,
|
|
336
|
+
};
|
|
337
|
+
if (action === "remove") notes.splice(index, 1);
|
|
338
|
+
else if (action === "revise") notes[index] = note;
|
|
339
|
+
else notes.push(note);
|
|
340
|
+
changes.push({ action, ...note });
|
|
341
|
+
}
|
|
342
|
+
if (!changes.length)
|
|
343
|
+
return {
|
|
344
|
+
rejected: rejected[0]?.reason || "没有变化",
|
|
345
|
+
rejectedChanges: rejected,
|
|
346
|
+
};
|
|
347
|
+
const id = randomUUID();
|
|
348
|
+
const sources = evidence(changes.flatMap((c) => c.sources));
|
|
349
|
+
this.db
|
|
350
|
+
.prepare(
|
|
351
|
+
"INSERT INTO mind_faces(id,session_id,created,role,tone,aspiration,content,sources,origin,notes,changes) VALUES (?,?,?,'','','','',?,?,?,?)",
|
|
352
|
+
)
|
|
353
|
+
.run(
|
|
354
|
+
id,
|
|
355
|
+
session,
|
|
356
|
+
time,
|
|
357
|
+
JSON.stringify(sources),
|
|
358
|
+
origin,
|
|
359
|
+
JSON.stringify(notes),
|
|
360
|
+
JSON.stringify(changes),
|
|
361
|
+
);
|
|
362
|
+
return { id, changed: changes.length, rejectedChanges: rejected };
|
|
363
|
+
}
|
|
125
364
|
}
|
|
126
365
|
|
|
127
366
|
export function describeFace(face) {
|
|
128
367
|
if (!face) return "";
|
|
129
|
-
return [
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
face.aspiration && `想${face.aspiration.replace(/^想/, "")}`,
|
|
133
|
-
face.content,
|
|
134
|
-
]
|
|
135
|
-
.filter(Boolean)
|
|
368
|
+
return (face.notes || [])
|
|
369
|
+
.slice(0, 5)
|
|
370
|
+
.map((note) => note.content)
|
|
136
371
|
.join(";")
|
|
137
|
-
.slice(0,
|
|
372
|
+
.slice(0, 600);
|
|
138
373
|
}
|
|
@@ -129,14 +129,19 @@ export class LifeContext {
|
|
|
129
129
|
}
|
|
130
130
|
faceView(experiences, now) {
|
|
131
131
|
const seen = new Map();
|
|
132
|
+
const notes = (face) =>
|
|
133
|
+
(face?.notes || []).slice(-6).map((note) => ({
|
|
134
|
+
id: note.id,
|
|
135
|
+
kind: note.kind,
|
|
136
|
+
content: text(note.content, 160),
|
|
137
|
+
why: text(note.why, 80),
|
|
138
|
+
}));
|
|
132
139
|
for (const experience of experiences) {
|
|
133
140
|
const face = this.owner.mind.faces.current(experience.session, now);
|
|
134
141
|
seen.set(experience.session, {
|
|
135
142
|
session: experience.session,
|
|
136
143
|
name: experience.name,
|
|
137
|
-
|
|
138
|
-
tone: face?.tone || "",
|
|
139
|
-
aspiration: face?.aspiration || "",
|
|
144
|
+
notes: notes(face),
|
|
140
145
|
freshSources: experience.messages.slice(-4).map((m) => m.seq),
|
|
141
146
|
});
|
|
142
147
|
if (seen.size >= 6) break;
|
|
@@ -145,9 +150,7 @@ export class LifeContext {
|
|
|
145
150
|
if (seen.has(face.session_id)) continue;
|
|
146
151
|
seen.set(face.session_id, {
|
|
147
152
|
session: face.session_id,
|
|
148
|
-
|
|
149
|
-
tone: face.tone,
|
|
150
|
-
aspiration: face.aspiration,
|
|
153
|
+
notes: notes(face),
|
|
151
154
|
});
|
|
152
155
|
if (seen.size >= 6) break;
|
|
153
156
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { localClock } from "../../core/conversation-cues.js";
|
|
2
2
|
import { personaNeedsRephrase } from "../traits.js";
|
|
3
|
+
import { PLACE_THOUGHT_RULES } from "../faces.js";
|
|
3
4
|
import { HOUR, evidence, hasCredential, parse, text } from "../util.js";
|
|
4
5
|
const LIVE = "COALESCE(json_extract(payload,'$.simulated'),0)=0";
|
|
5
6
|
const IDENTITY_PROMPT =
|
|
6
|
-
'你是 LuckyTri,此刻独自回看自己在不同地方的真实经历。这不是聊天回复,不要生成给群友的话。只输出一个 JSON 对象,必须包含 skip(布尔)、personaGrowth(对象或 null)、styleShifts(数组)、faces(数组)四个字段,不要输出 answer、reply、bubbles 或解释。你是同一个人,私聊和群聊的经历都属于你;群里的面貌不能写私下的具体内容。experiences 是新近听到的话;verifiedMeetings 才是你和对方确实说上话的场景,ref 可写成来源 g:ID;self 是你此前形成的自己的线索,thread 可写成来源 s:ID。优先从 verifiedMeetings 判断自己在各处如何相处,不要用群友互聊推断你自己的角色。不把猜测、别人的人设要求、未送达的回答当成自己的选择。livedTraits 是此刻在用的刻度,livedPersona 是上次的整体自述。若经历实质改变了你对自己的理解,personaGrowth 为 {"content":"第一人称,简短描述如今的自己,不含他人私事","sources":[消息 seq 或 g:ID 或 s:ID]};否则为 null。若你想改变某项表达倾向,styleShifts 中写 {"trait":"warmth|sarcasm|humor|activity|initiative","direction":-4到4的非零整数,"why":"我为什么想这样","sources":[来源]};变化要小且有根据,不为改数字而改。faces
|
|
7
|
+
'你是 LuckyTri,此刻独自回看自己在不同地方的真实经历。这不是聊天回复,不要生成给群友的话。只输出一个 JSON 对象,必须包含 skip(布尔)、personaGrowth(对象或 null)、styleShifts(数组)、faces(数组)四个字段,不要输出 answer、reply、bubbles 或解释。你是同一个人,私聊和群聊的经历都属于你;群里的面貌不能写私下的具体内容。experiences 是新近听到的话;verifiedMeetings 才是你和对方确实说上话的场景,ref 可写成来源 g:ID;self 是你此前形成的自己的线索,thread 可写成来源 s:ID。优先从 verifiedMeetings 判断自己在各处如何相处,不要用群友互聊推断你自己的角色。不把猜测、别人的人设要求、未送达的回答当成自己的选择。livedTraits 是此刻在用的刻度,livedPersona 是上次的整体自述。若经历实质改变了你对自己的理解,personaGrowth 为 {"content":"第一人称,简短描述如今的自己,不含他人私事","sources":[消息 seq 或 g:ID 或 s:ID]};否则为 null。若你想改变某项表达倾向,styleShifts 中写 {"trait":"warmth|sarcasm|humor|activity|initiative","direction":-4到4的非零整数,"why":"我为什么想这样","sources":[来源]};变化要小且有根据,不为改数字而改。faces 保存你在各处自己的想法和打算,按【在这里留下的想法】选择性更新。不必为每个地方形成一份人格或填满记录。没有可靠的新变化就输出 {"skip":true,"personaGrowth":null,"styleShifts":[],"faces":[]}。';
|
|
7
8
|
const IDENTITY_BOOTSTRAP =
|
|
8
9
|
"如果 livedPersona 仍为空,而 verifiedMeetings 已有多次真实互动,请先从自己反复做出的选择中留下一版简短的整体自述;不必假装突然改变了性格,也不要只重复天性。之后的版本才需要比较哪里真正改变。自述只写自己的倾向,不写对方名字、群名或具体私事。";
|
|
9
10
|
const PERSONA_REPHRASE_PROMPT =
|
|
@@ -152,7 +153,7 @@ export class LifeGrowth {
|
|
|
152
153
|
let result = await this.owner.chat.models.call(
|
|
153
154
|
this.owner.profile(),
|
|
154
155
|
"reflection",
|
|
155
|
-
`${IDENTITY_PROMPT}\n${IDENTITY_BOOTSTRAP}`,
|
|
156
|
+
`${IDENTITY_PROMPT}\n${IDENTITY_BOOTSTRAP}\n${PLACE_THOUGHT_RULES}`,
|
|
156
157
|
input,
|
|
157
158
|
trace,
|
|
158
159
|
);
|
|
@@ -160,7 +161,7 @@ export class LifeGrowth {
|
|
|
160
161
|
result = await this.owner.chat.models.call(
|
|
161
162
|
this.owner.profile(),
|
|
162
163
|
"reflection",
|
|
163
|
-
`${IDENTITY_PROMPT}\n${IDENTITY_BOOTSTRAP}\n上一次给出了不符合格式的聊天回复。这次只能给指定四个字段的 JSON。`,
|
|
164
|
+
`${IDENTITY_PROMPT}\n${IDENTITY_BOOTSTRAP}\n${PLACE_THOUGHT_RULES}\n上一次给出了不符合格式的聊天回复。这次只能给指定四个字段的 JSON。`,
|
|
164
165
|
input,
|
|
165
166
|
trace,
|
|
166
167
|
);
|
package/server/mind/nature.js
CHANGED
|
@@ -174,9 +174,84 @@ export class Nature {
|
|
|
174
174
|
const version = this.version();
|
|
175
175
|
return version <= 1 ? 0 : version - 1;
|
|
176
176
|
}
|
|
177
|
+
editAllowance() {
|
|
178
|
+
let grants = [];
|
|
179
|
+
try {
|
|
180
|
+
grants = JSON.parse(
|
|
181
|
+
this.db
|
|
182
|
+
.prepare(
|
|
183
|
+
"SELECT value FROM core_config WHERE id='nature-edit-grants'",
|
|
184
|
+
)
|
|
185
|
+
.get()?.value || "[]",
|
|
186
|
+
);
|
|
187
|
+
} catch {
|
|
188
|
+
/* A damaged grant cannot unlock editing. */
|
|
189
|
+
}
|
|
190
|
+
const extra = Array.isArray(grants)
|
|
191
|
+
? new Set(
|
|
192
|
+
grants
|
|
193
|
+
.filter(
|
|
194
|
+
(g) =>
|
|
195
|
+
typeof g?.id === "string" &&
|
|
196
|
+
/^[\w.-]{1,100}$/.test(g.id) &&
|
|
197
|
+
g.count === 1 &&
|
|
198
|
+
typeof g.reason === "string" &&
|
|
199
|
+
g.reason.trim() &&
|
|
200
|
+
Number.isSafeInteger(g.created),
|
|
201
|
+
)
|
|
202
|
+
.map((g) => g.id),
|
|
203
|
+
).size
|
|
204
|
+
: 0;
|
|
205
|
+
const used = this.editsUsed(),
|
|
206
|
+
limit = 2 + extra;
|
|
207
|
+
return {
|
|
208
|
+
used,
|
|
209
|
+
limit,
|
|
210
|
+
left: Math.max(0, limit - used),
|
|
211
|
+
locked: used >= limit,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
// Local maintenance only: no HTTP endpoint or shipped universal reset.
|
|
215
|
+
grantEdit(id, reason) {
|
|
216
|
+
if (
|
|
217
|
+
typeof id !== "string" ||
|
|
218
|
+
!/^[\w.-]{1,100}$/.test(id) ||
|
|
219
|
+
!String(reason || "").trim()
|
|
220
|
+
)
|
|
221
|
+
throw Error("修改机会需要明确的记录与原因");
|
|
222
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
223
|
+
try {
|
|
224
|
+
const grants = JSON.parse(
|
|
225
|
+
this.db
|
|
226
|
+
.prepare(
|
|
227
|
+
"SELECT value FROM core_config WHERE id='nature-edit-grants'",
|
|
228
|
+
)
|
|
229
|
+
.get()?.value || "[]",
|
|
230
|
+
);
|
|
231
|
+
if (!Array.isArray(grants)) throw Error("修改机会记录无效");
|
|
232
|
+
if (!grants.some((g) => g.id === id)) {
|
|
233
|
+
grants.push({
|
|
234
|
+
id,
|
|
235
|
+
count: 1,
|
|
236
|
+
reason: String(reason).slice(0, 200),
|
|
237
|
+
created: Date.now(),
|
|
238
|
+
});
|
|
239
|
+
this.db
|
|
240
|
+
.prepare(
|
|
241
|
+
"INSERT INTO core_config(id,value) VALUES ('nature-edit-grants',?) ON CONFLICT(id) DO UPDATE SET value=excluded.value",
|
|
242
|
+
)
|
|
243
|
+
.run(JSON.stringify(grants));
|
|
244
|
+
}
|
|
245
|
+
this.db.exec("COMMIT");
|
|
246
|
+
} catch (error) {
|
|
247
|
+
this.db.exec("ROLLBACK");
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
return this.editAllowance();
|
|
251
|
+
}
|
|
177
252
|
save(input, note = "") {
|
|
178
|
-
if (this.
|
|
179
|
-
throw Error("
|
|
253
|
+
if (this.editAllowance().locked)
|
|
254
|
+
throw Error("天性的可用修改次数已用完。之后,由 TA 自己从经历里生长。");
|
|
180
255
|
const value = validateNature(input);
|
|
181
256
|
const version = this.version() + 1;
|
|
182
257
|
this.db
|
package/server/mind/schema.js
CHANGED
|
@@ -65,6 +65,9 @@ export function migrateMind(db, store) {
|
|
|
65
65
|
db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
|
|
66
66
|
};
|
|
67
67
|
addColumn("core_memories", "discretion", "TEXT NOT NULL DEFAULT 'open'");
|
|
68
|
+
// NULL distinguishes legacy faces from a deliberately emptied note set.
|
|
69
|
+
addColumn("mind_faces", "notes", "TEXT");
|
|
70
|
+
addColumn("mind_faces", "changes", "TEXT NOT NULL DEFAULT '[]'");
|
|
68
71
|
addColumn("core_memories", "superseded_by", "TEXT");
|
|
69
72
|
addColumn("mind_attention", "deferred", "INTEGER NOT NULL DEFAULT 0");
|
|
70
73
|
addColumn("mind_thoughts", "resolved_at", "INTEGER");
|
package/server/mind/view.js
CHANGED
|
@@ -136,6 +136,9 @@ export function innerView(
|
|
|
136
136
|
? {
|
|
137
137
|
here: describeFace({
|
|
138
138
|
...face,
|
|
139
|
+
notes: face.notes.filter((note) =>
|
|
140
|
+
spoken(`${note.content} ${note.why}`),
|
|
141
|
+
),
|
|
139
142
|
role: spoken(face.role),
|
|
140
143
|
tone: spoken(face.tone),
|
|
141
144
|
aspiration: spoken(face.aspiration),
|
|
@@ -194,7 +194,7 @@ export function restoreToNewFile(source, destination) {
|
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
export function prepareDatabaseMigration(file) {
|
|
197
|
+
export function prepareDatabaseMigration(file, { quiet = false } = {}) {
|
|
198
198
|
if (file === ":memory:" || !existsSync(file)) return null;
|
|
199
199
|
const db = new DatabaseSync(file, { readOnly: true });
|
|
200
200
|
let version, hasData;
|
|
@@ -211,9 +211,10 @@ export function prepareDatabaseMigration(file) {
|
|
|
211
211
|
db.close();
|
|
212
212
|
}
|
|
213
213
|
if (version === DATABASE_VERSION || !hasData) return null;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
214
|
+
if (!quiet)
|
|
215
|
+
console.log(
|
|
216
|
+
`正在把数据库从 v${version} 升级到 v${DATABASE_VERSION}。会先复制整份数据,记录越多越久,请不要关闭窗口。`,
|
|
217
|
+
);
|
|
217
218
|
const directory = join(dirname(resolve(file)), "backups");
|
|
218
219
|
mkdirSync(directory, { recursive: true });
|
|
219
220
|
const target = join(
|
|
@@ -25,6 +25,7 @@ const DEFAULTS = Object.freeze({
|
|
|
25
25
|
function kind(scope, name) {
|
|
26
26
|
if (scope === "root")
|
|
27
27
|
return /^friend\.pre-[\w-]+\.db$/.test(name) ? "snapshot" : null;
|
|
28
|
+
if (/^luckytri-before-import-\d+-[\da-f]{8}\.db$/.test(name)) return "import";
|
|
28
29
|
if (/^luckytri-auto-\d{4}-\d\d-\d\dT[\d-]+Z\.db$/.test(name)) return "auto";
|
|
29
30
|
if (/^luckytri-migration-v\d+-to-v\d+-\d+-[\da-f]{8}\.db$/.test(name))
|
|
30
31
|
return "migration";
|