feat: 改寫為 Node.js,新增動漫角色建人格、劇場模式與記憶固化條件
腳本全面從 Python 改寫為 Node.js(ESM,只用內建模組,無 npm 依賴): scripts/persona-lib.mjs(核心)、scripts/persona.mjs(CLI)、hooks/*.mjs(六個 hook)、scripts/selftest.mjs(68 項自我測試,全綠)。 新增: - persona-anime skill:用「動漫作品+角色名」建立人格,先上網蒐集至少三個獨立 來源的公開設定,映射成 OpenClaw 的 IDENTITY 五欄位與 SOUL 四段落,再固化成 canon 基礎記憶(每則帶來源 URL)+原作人際關係圖+依角色型別的情緒基線; 必寫 roleplay-frame 界線記憶(非官方、非本人)。 - 劇場模式:invite 後只顯示人格對話(`名字:內容`)。UserPromptSubmit hook 每輪 注入強制規則、Stop hook 完全靜音,CLI 新增 --quiet 與 room script(乾淨對話稿)。 leave 後沒客人自動關閉,也可用 room theater --on/--off 手動切換。 - 短期→長期記憶的成文轉入條件 R1–R6(promotionCandidates)與 candidates 子指令, hook 在達標時提醒固化;長期記憶新增 canon 型別與 rules 欄位。 - 人格改為「由使用者呼叫才載入」:SessionStart hook 只列出可用人格,不自動附身。 其他:版本號改回 0.0.1;README/AGENTS.md 同步更新。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env node
|
||||
// Stop:情緒隨時間衰減、續租、記錄逐字,並在達到「短期→長期」條件時提醒固化。
|
||||
// 劇場模式進行中不發任何提醒(那會破壞「只顯示人格對話」)。
|
||||
|
||||
import { readEvent, respond } from "./_hook.mjs";
|
||||
import * as pl from "../scripts/persona-lib.mjs";
|
||||
|
||||
const event = readEvent();
|
||||
if (!event) process.exit(0);
|
||||
|
||||
const sessionId = event.session_id || "unknown";
|
||||
const data = pl.loadSession(sessionId);
|
||||
const host = data.host;
|
||||
if (!host || !pl.personaExists(host)) process.exit(0);
|
||||
|
||||
pl.heartbeatLock(host, sessionId);
|
||||
const state = pl.decayEmotion(pl.loadEmotion(host));
|
||||
pl.writeJson(pl.emotionPath(host), state);
|
||||
|
||||
const message = event.last_assistant_message || "";
|
||||
if (message) {
|
||||
pl.appendJsonl(pl.journalPath(host), {
|
||||
ts: pl.nowIso(),
|
||||
kind: "utterance",
|
||||
role: "persona",
|
||||
text: message.slice(0, 4000),
|
||||
mood: pl.mood(state),
|
||||
});
|
||||
}
|
||||
|
||||
const out = { suppressOutput: true };
|
||||
const theater = Boolean(data.theater) && (data.rooms || []).length > 0;
|
||||
if (!theater) {
|
||||
const { total, candidates } = pl.promotionCandidates(host);
|
||||
if (candidates.length) {
|
||||
const rules = [...new Set(candidates.flatMap((c) => c.rules))].sort().join("/");
|
||||
out.systemMessage =
|
||||
`[jsc-persona] \`${host}\` 短期記憶 ${total} 筆,${candidates.length} 組已達固化條件(${rules})` +
|
||||
"→ 建議執行 /jsc-persona:persona-memory。";
|
||||
}
|
||||
}
|
||||
respond(out);
|
||||
Reference in New Issue
Block a user