feat(hooks): SessionStart 注入人格的 AGENTS.md 操作規則
新增 pl.opsBrief(slug):把該人格的 AGENTS.md 全文包成 <persona-ops> 區塊, 由 SessionStart hook 在「接續人格」與「預設人格自動載入」兩條分支各注入一次。 刻意不放進 turnContext——操作規則是低頻的「怎麼做事」,每輪重貼只是燒 context。 超過 OPS_BRIEF_MAX_CHARS(6000)會截斷並指路回原檔;檔案不存在時回空字串。 這讓「這個人格自己的工具箱」可以寫在 AGENTS.md 裡跟著人格走(AGENTS.md 本來 就在 sync 的 wiki 白名單內),不必落在機器本機的 ~/.claude/agents。 selftest 補 5 條:全文注入、指路原檔、不進 turnContext、檔案不存在回空、 超長截斷。全套 345 項通過。
This commit is contained in:
@@ -37,6 +37,17 @@ const lines = [
|
||||
" 4. 禁止直接讀寫非當前人格的目錄,hook 會擋下(跨人格資料隔離)。",
|
||||
];
|
||||
|
||||
/**
|
||||
* 把 AGENTS.md(操作規則)注入一次。
|
||||
*
|
||||
* 放這裡而不是 turnContext:它是低頻的「怎麼做事」,開機讀一次就夠,
|
||||
* 每輪重貼只是浪費 context。人格自己的工具箱(例如六把劍)寫在裡面就會跟著人格走。
|
||||
*/
|
||||
function pushOps(slug) {
|
||||
const ops = pl.opsBrief(slug);
|
||||
if (ops) lines.push(ops);
|
||||
}
|
||||
|
||||
/** 列出可用人格,讓使用者挑(沒有預設人格、或預設人格載入失敗時用)。 */
|
||||
function listAvailable() {
|
||||
const personas = pl.listPersonas();
|
||||
@@ -58,6 +69,7 @@ if (host && pl.personaExists(host)) {
|
||||
pl.acquireLock(host, sessionId, { cwd });
|
||||
lines.push(`已接續人格 \`${host}\`(session 恢復:${source})。`);
|
||||
lines.push(pl.turnContext(host, sessionId));
|
||||
pushOps(host);
|
||||
} catch (err) {
|
||||
lines.push(`⚠ 無法接續人格 \`${host}\`:${err.message}`);
|
||||
}
|
||||
@@ -75,6 +87,7 @@ if (host && pl.personaExists(host)) {
|
||||
lines.push("請照 /jsc-persona:persona-chat 的每輪流程走(語意分析→情緒→回想→3 句內回覆→記憶回寫)。");
|
||||
lines.push("提醒:這次是本機自動載入,沒有從 Gitea 拉最新狀態;若可能在別台機器動過,先 `sync pull`。");
|
||||
lines.push(pl.turnContext(wanted, sessionId));
|
||||
pushOps(wanted);
|
||||
} catch (err) {
|
||||
lines.push(`⚠ 預設人格 \`${wanted}\` 自動載入失敗:${err.message}`);
|
||||
lines.push("不要自作主張 `--takeover`——先把 owner 與最後心跳告訴使用者,讓他決定。");
|
||||
|
||||
Reference in New Issue
Block a user