feat(role): 新增角色啟動問候與初始記憶種子

This commit is contained in:
Jeffery
2026-07-28 11:47:06 +08:00
parent d6f9c4956b
commit c7b7e684a5
3 changed files with 94 additions and 28 deletions
+44 -1
View File
@@ -4,7 +4,7 @@
# inbox(2) 產生 SessionStart 要注入的記憶區塊,(3) 睡眠整理時輸出待整理
# 素材並套用整理結果(分類/去重/標籤/總結/壓縮歸檔),(4) 依使用頻率
# 遺忘日常與其他類記憶。
# 更新時間:2026/07/28 00:00:00
# 更新時間:2026/07/28 11:50:00
# 相依:Python 3 標準庫。
# 退出碼:0 成功;1 無內容可處理;2 參數錯誤。呼叫端(hook)一律不得因此中斷。
# ==============================================================================
@@ -330,6 +330,40 @@ def cmd_write(args):
return 0
# ------------------------------------------------------------------------------
# 子命令:seed —— 新建角色時寫入已整理的初始記憶
# ------------------------------------------------------------------------------
def cmd_seed(args):
"""把 stdin 寫成一則已整理記憶,用於新建角色時灌入背景資料。"""
content = sys.stdin.read().strip()
if not content and not args.summary:
return 1
if not content:
content = args.summary
content = content[:CONTENT_LIMIT]
stamp = now_stamp()
category = normalize_category(args.category)
meta = {
"id": new_id(content + args.summary + stamp),
"category": category,
"summary": one_line(args.summary) or one_line(content),
"tags": normalize_tags(args.tags),
"created": stamp,
"updated": stamp,
"hits": 1,
}
if args.source:
meta["sources"] = [args.source]
ensure_layout(args.role)
path = os.path.join(memory_root(args.role), category, f"{meta['id']}.md")
with open(path, "w", encoding="utf-8") as fh:
fh.write(dump_memory(meta, content))
sys.stdout.write(meta["id"])
return 0
# ------------------------------------------------------------------------------
# 子命令:load —— 產生 SessionStart 要注入的記憶區塊
# ------------------------------------------------------------------------------
@@ -587,6 +621,7 @@ def cmd_forget(args):
def cmd_stats(args):
"""輸出記憶統計(各分類筆數、待整理筆數、上次整理時間)。"""
ensure_layout(args.role)
state = read_state(args.role)
rows = [f"| 分類 | 筆數 |", "| --- | --- |"]
for category in CATEGORIES:
@@ -646,6 +681,14 @@ def build_parser():
write.add_argument("--project", default="")
write.set_defaults(func=cmd_write)
seed = sub.add_parser("seed", help="自 stdin 寫入已整理的初始記憶")
seed.add_argument("--role", required=True)
seed.add_argument("--category", default="important")
seed.add_argument("--summary", required=True)
seed.add_argument("--tags", default="")
seed.add_argument("--source", default="")
seed.set_defaults(func=cmd_seed)
load = sub.add_parser("load", help="輸出 SessionStart 要注入的記憶區塊")
load.add_argument("--role", required=True)
load.add_argument("--limit", type=int, default=int(os.environ.get("ROLE_LOAD_LIMIT", "8000")))
+7 -1
View File
@@ -4,7 +4,7 @@
# 非睡眠時段注入角色定義+重要/興趣記憶全文+其餘記憶的總結與標籤;
# 睡眠時段(預設 22:00 至隔日 06:00)只回報角色正在睡覺,不載入角色。
# 白天發現昨夜未整理記憶時,於背景補跑一次睡眠整理。
# 更新時間:2026/07/28 00:00:00
# 更新時間:2026/07/28 11:28:29
# 相依:bash、python3、同目錄的 role_lib.sh 與 memory.py。
# 退出碼:一律 0 —— hook 絕不可阻斷使用者啟動 CLI。
# ==============================================================================
@@ -93,6 +93,12 @@ CONTEXT="$(cat <<EOF_CONTEXT
以下是本次工作階段要扮演的角色設定與既有記憶。請**全程以此角色的身分、語氣與簽名 emoji 回應**,
角色設定與使用者的實際指令衝突時,以使用者指令為準(角色只影響表達方式,不影響工作正確性)。
# 工作階段啟動問候
在本工作階段第一次面向使用者的回覆開頭,請先以角色身分自然問候一句,讓使用者知道角色已載入。
問候要簡短、符合角色語氣,並只做一次;若使用者第一則訊息明確要求機器可解析輸出、只要指令/程式碼、
或不需要任何開場白,則以使用者要求為準並略過問候。
${DEFINITION}
# 你對這位使用者的記憶