feat(記憶): 行為備註同時進 voice/reactions.md,5.7 完成

Q6 明示「記憶要記那個行為」,而 persona-story 的 voice/reactions.md 存的正是
「事件 → 他做了什麼」。兩邊各存一份就會有人只更新一邊,所以接成同一批資料:
remember --behavior 寫短期記憶時,同一筆也 addVoiceReaction()。

分工:記憶留時間軸(那一天發生過這件事),語氣層供每輪注入(他遇到這種事會怎麼反應)。

只有人格自己的行為進語氣層(role === "persona")。對方做了什麼是記憶,
不是他的反應方式——把使用者的動作寫進 reactions.md 會讓人格學別人的反應。

selftest 709 → 711(行為備註進得去、對方的行為不進去)。
TARGET.md 的 5.7 八個子項目全完成,勾上層。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-03 08:16:04 +00:00
co-authored by Claude Opus 5
parent 0d298cbfce
commit 06774ceb2b
3 changed files with 29 additions and 6 deletions
+13
View File
@@ -783,6 +783,19 @@ commands.remember = ({ flags }) => {
}
pl.rememberShort(slug, entry);
const kept = pl.pruneShortTerm(slug);
// 行為備註與 `voice/reactions.md` 是**同一批資料**(事件 → 他做了什麼),不是各存一份:
// 記憶留時間軸(那一天發生過這件事),語氣層供每輪注入(他遇到這種事會怎麼反應)。
// 只有**人格自己的**行為才進語氣層——對方做了什麼是記憶,不是他的反應方式。
if (entry.behavior && entry.role === "persona") {
const [top] = Object.entries(entry.emotion_deltas)
.filter(([, d]) => Number(d) > 0)
.sort((a, b) => Number(b[1]) - Number(a[1]));
pl.addVoiceReaction(slug, {
event: text,
action: entry.behavior,
emotion: top ? pl.EMOTIONS[top[0]]?.zh || "" : "",
});
}
if (Object.keys(entry.emotion_deltas).length) {
const state = pl.updateEmotion(slug, (s) => pl.applyEmotion(s, entry.emotion_deltas, text.slice(0, 80), { slug }));
pl.appendJsonl(pl.journalPath(slug), {
+9
View File
@@ -1157,6 +1157,15 @@ check("行為備註寫情緒名稱會被擋", (() => {
"--text", "測試行為備註的界線", "--behavior", "覺得害羞"], { expectOk: false });
return out.status !== 0 && String(out.stderr).includes("是情緒不是動作");
})());
check("行為備註同時進 voice/reactions.md(同一批資料,不是各存一份)", (() => {
const r = pl.loadVoice("alpha").reactions;
return r.some((x) => x.action === "把手縮回來" && String(x.event).includes("修得比上次穩"));
})(), JSON.stringify(pl.loadVoice("alpha").reactions.slice(-3)));
check("對方的行為不進語氣層(那是記憶,不是他的反應方式)", (() => {
cli(["remember", "--persona", "alpha", "--session", S_SPEAK, "--role", "user",
"--text", "他把門關上就走了", "--behavior", "把門關上", "--salience", "40"]);
return !pl.loadVoice("alpha").reactions.some((x) => x.action === "把門關上");
})(), JSON.stringify(pl.loadVoice("alpha").reactions.slice(-3)));
// 鬧彆扭的階梯:40 分一句帶過、60 分嘴硬三段式、75 分以上惱羞
console.log("⑥-d 鬧彆扭的階梯與三段式");