dsh-session-handoff
  
English | 中文
把长会话"交接"到一个干净的新会话。/handoff 用 LLM 总结当前会话最近几轮对话, 在同一工作区创建一个全新会话 + agent(不复制历史),把结构化交接文档作为新会话 第一条消息注入,并自动打开——模型从摘要继续,不用重放整段旧历史。原会话保持不变。
特性
- 一条命令——
/handoff [<N>|all](默认最近 8 轮用户消息;all覆盖全部) - 干净的交接——新会话继承原会话的工作区、模型路由与 agent preset(系统提示 / 工具 / 技能),无上下文臃肿
- 结构化摘要——任务目标 / 当前进度 / 关键决策 / 涉及文件 / 下一步 / 遗留问题
- 自动打开——客户端半区等待新会话就绪后自动跳转(每个子会话只自动打开一次,历史回放不反复跳转)
- 默认就健壮——摘要调用关闭思考(快且省)、超长输入自动保留最新而非报错、finish reason(max-tokens / error / aborted)翻译成可操作的错误
- 零核心改动——只插入一行
dsh.bundle.patch,全部走公开服务
安装
# 1. 从源码构建(或直接下载 release tarball)
npm install && npm run build && npm pack # → dsh-session-handoff-0.2.0.tgz
# 2. 装进 web profile
dsh plugin --profile web add ./dsh-session-handoff-0.2.0.tgz
# 3. 重启并验证挂载
dsh web
dsh --profile web --dump-config | grep handoff
# 期望:# == dsh-session-handoff / - id: handoff / - name: dsh-session-handoff> 开发期源码 link 安装(dsh plugin --profile web add D:/path/to/dsh-session-handoff)要求源码 > 目录的 node_modules 能解析 @deepseek-ai/* peers;正式安装推荐直接用 tarball。
使用
在任意会话输入框敲:
/handoff # 总结最近 8 轮用户消息(默认)
/handoff 20 # 总结最近 20 轮(等价 turns=20)
/handoff all # 总结全部用户消息(等价 turns=all)执行后:
1. 命令卡片显示"正在总结…"; 2. LLM 生成交接文档(目标 / 进度 / 决策 / 文件 / 下一步 / 遗留问题),成为新会话首条消息; 3. 新会话自动打开;原会话原样保留并回链。
> ⚠️ 隐私提示:所选窗口内的对话文本(用户 + 助手消息)会发送给配置的模型用于生成摘要。
配置
- id: handoff
name: dsh-session-handoff
config:
turns: 8 # 提取的用户消息轮数(1–50)
maxInputChars: 24000 # 摘要输入字节上限(超限自动丢弃最旧)
maxTokens: 2000 # 摘要输出 token 上限
reasoningEffort: off # 摘要调用思考强度:off(默认,快省)| high | max | inherit
timeoutMs: 120000 # 摘要调用超时
# provider: deepseek-official # 可选:固定模型路由
# model: deepseek-v4-flash # 必须与 provider 成对不配 provider/model 时,自动使用当前会话最近一次请求的模型路由 (session.requestHeader())。
原理
- 宿主侧(
index.mjs,纯 ESM):只消费公开服务——commands(/handoff 命令)、
llm(ctx.llm.stream,参考官方 session-title-llm)、agents (ctx.agents.create:会话与 agent 一起建,经 agentPresets.mount 继承原会话的 cwd / 模型路由 / agent preset),以及 workspaceRegistry.attachSession(同工作区分组) 与 sessionTitle.rename(handoff: <源标题> 可辨识标题)。
- 客户端侧(
src/client/,tsdown →lib/client.js):handoffconversation node
命中 /handoff 成功事件后自动打开子会话(轮询等待可寻址,localStorage 去重)。
开发
npm install # devDeps:tsdown / typescript / @types/react / vitest / jsdom …
npm test # 19 用例:15 宿主+客户端纯函数 + 4 客户端组件
npm run typecheck
npm run build # tsdown → lib/client.js(CJS factory,官方客户端模块系统形态)
npm pack # prepack 自动 typecheck + build发布清单:仓库加 dsh-plugin GitHub topic → 给 awesome-deepseek-harness 提 PR 收录 → 可选 npm publish。
已知限制
- 交接文档目前只注入会话内,不落盘(
HANDOFF.md留作后续); - 依赖 rc.5 的公开契约,DSH 升级后需按新 rc 复核;
- 自动跳转组件只有纯函数单测,jsdom 组件级测试待补。
License
[MIT](./LICENSE)