feat(memory): M1 会话收口——4h 空闲自动下班 + 定时即下班(brief 模板碎片)

微信通道拟人化第二里程碑:会话=工作台,收口=下班记日记。

- 空闲收口:扫描器扩为会话闲置双阶段(sweepIdleSessions)——30min held 归档(原有)
  + 4h(memory.wrap_idle_ms 可配,0=关)无更新且未收口的 held/completed 会话,
  后台异步 journalFragment 摘要落碎片(fire-and-forget 不阻塞消息路径),
  顺手归档 + 删 channel_sessions 绑定行——微信下条消息经 ensureSession 自然新建
  工作台;用户抢先复活(active)则不撤台。updated_at 门槛越过即永远成立,
  「不重复收口」靠 sessions.journaled_at 物理标记(防陈年 completed 每轮烧 LLM)。
- 定时即下班:schedule 工具 create 新增 brief 参数(一句话任务人话描述,进 schema),
  scheduler.createTask 落库;工具只打 run.taskWrap 标记,收口在 finalize done 广播后
  (attachBus 监听已同步捕获绑定入队投递,删绑定不影响本次回复送达)——
  brief 纯模板碎片零 LLM 落收口当日条目 + journaled 占坑(任务会话从此退出 4h 流程,
  任务执行痕迹不落日记,「任务是什么+成果文件」即可回溯全貌)+ 解绑退位。
- 碎片时间线定稿:入【收口当日】而非会话创建日(长跨度会话不会落进已裁掉的旧日期)。
- 网页/微信统一碎片(用户级共享),解绑只对通道会话生效(网页无绑定行 DELETE 空操作)。
  /new /switch /clear 不产碎片;/clear 重置 journaled(清空=撕掉作业,可再收口)。
- 记忆关闭(retain_days=0)时定时收口整体不执行:没有日记的下班没有意义,不抽工作台。

上电探针 6 项全过(brief 落库/钩子标记/journaled 占坑/归档/当日条目/解绑),探针已清理。
M2(新会话注入日记)下一棒。
This commit is contained in:
2026-09-29 11:18:16 +08:00
parent 8acc1bf508
commit 01ec42a197
8 changed files with 135 additions and 39 deletions
+5 -1
View File
@@ -235,7 +235,7 @@
"type": "function",
"function": {
"name": "schedule",
"description": "Manage the recurring scheduled task bound to the CURRENT session. At most one task per session; it is deleted together with the session. At each trigger, the prompt is sent to this session as a new user message. Schedule times are interpreted in Asia/Shanghai (UTC+8). Call this ONLY when the user explicitly asks for something to run periodically or at a specific time.\n\nop=get No arguments.\nop=create Requires cron_expr and prompt.\nop=update Requires at least one of cron_expr, prompt; only the given fields change.\nop=delete No arguments.",
"description": "Manage the recurring scheduled task bound to the CURRENT session. At most one task per session; it is deleted together with the session. At each trigger, the prompt is sent to this session as a new user message. Schedule times are interpreted in Asia/Shanghai (UTC+8). Call this ONLY when the user explicitly asks for something to run periodically or at a specific time.\n\nop=get No arguments.\nop=create Requires cron_expr, prompt and brief.\nop=update Requires at least one of cron_expr, prompt; only the given fields change.\nop=delete No arguments.",
"parameters": {
"type": "object",
"required": [
@@ -259,6 +259,10 @@
"prompt": {
"type": "string",
"description": "The message to send to this session at each trigger. Write it as a self-contained instruction: previous conversation history is archived before each run, so this prompt is the only input the model will see. The output stays in this session for the user to view; if it must reach the user proactively, state how in the prompt (e.g. via a skill or webhook). Required with op=create; optional with op=update."
},
"brief": {
"type": "string",
"description": "One short plain-language line (<= 40 chars) saying what this task actually accomplishes, e.g. 'collect and produce a daily news PDF report'. It is written into the assistant's long-term memory diary so the recurring job can be recalled later. Required with op=create."
}
}
}