feat: add /resume command and fix /compact to preserve session ID#34
Open
UnknownJackMe wants to merge 1 commit into
Open
feat: add /resume command and fix /compact to preserve session ID#34UnknownJackMe wants to merge 1 commit into
UnknownJackMe wants to merge 1 commit into
Conversation
/resume (no args): lists recent conversations for the current working directory, showing custom /rename titles, first user message, timestamp, and message count — matching what Claude Code's own /resume picker shows. /resume <N>: switches the active session to entry N from the list. /resume <uuid>: switches by full session ID. Session labels are read directly from the .jsonl transcript files so custom-title (set by /rename) takes priority; falls back to the first real user message, then the summary field. /compact is rewritten to call `claude -p /compact --resume <sessionId>` instead of clearing the session ID. This triggers Claude Code's native compaction: the conversation is summarised in-place, token usage drops dramatically, and the session ID is preserved — the next message continues the same session with full context compressed. The stream-json output is parsed for the compact_boundary event to extract pre/post token counts, which are reported back to WeChat.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改动内容
新增:
/resume命令列出并恢复当前工作目录(
/cwd所指定的目录)下的历史对话。用法:
/resume— 列出最近 15 条历史对话,按最后修改时间倒序排列/resume <编号>— 恢复列表中第 N 条对话/resume <uuid>— 通过完整 session ID 恢复标题显示逻辑:
直接读取每个 session 的
.jsonl文件来提取标签,优先级与 Claude Code 自带的/resume选择器保持一致:/rename设置的自定义标题(读取最新的custom-title事件)sessions-index.json的summary字段系统注入的噪音(
<local-command-caveat>块、[csb injected]标记等)会被自动过滤。修复:
/compact现在保持 session ID 不变原来的
/compact实现只是清除了sdkSessionId,效果等同于/clear——开启一个没有任何上下文的全新会话。修复后改为调用
claude -p /compact --resume <sessionId>,触发 Claude Code 的原生压缩机制:同时解析 stream-json 输出中的
compact_boundary事件,提取压缩前后的 token 数,并通过微信反馈给用户:实现细节
src/commands/handlers.ts:新增handleResume(),含 session 索引解析逻辑;重写handleCompact()返回{ compactSession: true }src/commands/router.ts:注册resume分支;在CommandResult中新增compactSession字段src/claude/provider.ts:解析compact_boundary系统事件,将 token 统计以哨兵字符串__compact__:pre:post注入返回值src/main.ts:新增compactSession分发分支和对应的异步函数compactSession()