Skip to content

feat(adapters): add /resume command for switching to existing sessions#128

Open
Qubhu wants to merge 1 commit intoNanmiCoder:mainfrom
Qubhu:feat/im-resume-command
Open

feat(adapters): add /resume command for switching to existing sessions#128
Qubhu wants to merge 1 commit intoNanmiCoder:mainfrom
Qubhu:feat/im-resume-command

Conversation

@Qubhu
Copy link
Copy Markdown

@Qubhu Qubhu commented Apr 22, 2026

Summary

  • 在 Telegram 和飞书适配器中新增 /resume 命令,支持 IM 端切换回已有会话,实现 CLI ↔ IM 无缝衔接
  • 支持三种用法:/resume 列出最近会话、/resume <session-id> UUID 前缀匹配、/resume <关键词> 标题模糊搜索
  • 新增 SessionListItem 类型和 listSessions() 方法到 AdapterHttpClient
  • 当前会话以 ✦ 标记,切换前校验 workDirExists

改动文件

文件 改动
adapters/common/http-client.ts 新增 SessionListItem 类型 + listSessions()
adapters/common/format.ts 帮助文本增加 /resume;新增 formatSessionList() + formatRelativeTime()
adapters/telegram/index.ts 实现 /resume 命令、会话选择交互、switchToSession()
adapters/feishu/index.ts 同步实现相同功能
docs/im/resume-command-plan.md 适配方案文档

交互示例

用户: /resume

Bot: 选择会话(回复编号):

1. 本机安装了claude-haha… ✦
   /Users/hcq · 44条消息 · 2分钟前

2. test
   /Users/hcq · 253条消息 · 1小时前

💡 也可直接 /resume <会话ID或关键词>

用户: 1

Bot: ✅ 已切换到会话:本机安装了claude-haha… (4401c2a9)

Test plan

  • /resume 列出最近 10 个会话,当前会话带 ✦ 标记
  • 回复编号可正确切换到目标会话
  • /resume <UUID前缀> 唯一匹配时直接切换
  • /resume <关键词> 标题搜索正常工作
  • 切换后发送消息确认路由到新 session
  • workDir 不存在时拦截提示
  • /new 命令正确清理 pendingSessionSelection 状态

🤖 Generated with Claude Code

Allow IM users (Telegram & Feishu) to resume existing sessions via
/resume command, enabling seamless CLI ↔ IM workflow continuity.

- /resume: list recent 10 sessions with interactive picker
- /resume <session-id>: UUID prefix match, direct switch
- /resume <keyword>: title fuzzy search
- Mark current session with ✦ in picker
- Validate workDirExists before switching
- Add SessionListItem type and listSessions() to AdapterHttpClient

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Apr 22, 2026
@Qubhu
Copy link
Copy Markdown
Author

Qubhu commented Apr 22, 2026

@copilot review and comment

@NanmiCoder
Copy link
Copy Markdown
Owner

@dosubot review and comment

@NanmiCoder
Copy link
Copy Markdown
Owner

@Qubhu hello 感谢你的代码贡献,该功能有相关的实际聊天截图吗,可以贴一下

@dosubot
Copy link
Copy Markdown

dosubot Bot commented Apr 24, 2026

Here's my review of this PR. Note that I couldn't access the actual diff, so this is based on the PR description and analysis of the existing codebase patterns.

Overall: The feature design is solid — three usage modes (list, UUID prefix, keyword search) provide good flexibility, and the workDirExists validation is a nice touch. A few areas worth addressing before merging:


🔴 Critical

  1. Reuse existing SessionListItem type — This type already exists in src/server/sessionService.ts [1] and is re-exported by desktop/src/types/session.ts [2]. Redefining it in http-client.ts risks schema drift. Import from the existing source instead.

  2. Race condition between pending states — The existing pendingProjectSelection pattern [3] uses a simple boolean map. Adding pendingSessionSelection alongside it means both could be active simultaneously, causing ambiguous message routing. Consider unifying into a single state machine with mutual exclusion, and add a TTL (e.g., 5 minutes) so stale pending states don't persist forever if the user never responds.

  3. Authorization check on /resume — The adapters validate users via isAllowedUser() [4]. Make sure /resume is gated behind this check, otherwise unauthorized users could enumerate and switch sessions.

  4. Code duplication between Telegram and Feishu — Both adapters already share a lot of duplicated logic [5] [6]. Adding /resume to both without extracting shared session-management logic will worsen this. Consider extracting a common SessionManager or shared handler in adapters/common/.

⚠️ Medium

  1. formatRelativeTime() already exists — There's a comprehensive implementation in src/utils/format.ts [7] and a simpler one in Sidebar.tsx [8]. Reuse one of these rather than creating a third.

  2. Stale workDirExists — The directory could be deleted between listing and switching. Consider re-validating right before the actual switch.

  3. Path exposure — Full filesystem paths (e.g., /Users/hcq) are shown in IM chat history which may be backed up to cloud. Consider sanitizing with ~ replacement: fullPath.replace(os.homedir(), '~').

  4. Telegram message length — Listing many sessions could exceed Telegram's 4096 character limit [9]. Enforce a display cap (the 10 session limit from the description seems fine) and add a hint like "还有 N 个会话,使用 /resume <关键词> 搜索".

📝 Minor

  1. Switching to current session — If the user picks the session already marked with ✦, short-circuit with a friendly message instead of performing a no-op switch.

  2. Special characters in titles — Session titles may contain Markdown special chars (Telegram) or JSON special chars (Feishu). Make sure to use the existing escape utilities.

  3. UUID prefix minimum length — Very short prefixes (1-2 chars) could match unintended sessions. Consider enforcing a minimum of 4 characters.

  4. Unit tests — The test plan covers integration scenarios well, but consider adding unit tests for formatSessionList(), formatRelativeTime() edge cases (future timestamps, very old dates), and the UUID prefix / keyword matching logic.


The feature itself fills a real gap (CLI ↔ IM session continuity) and the interaction design is clean. Addressing the critical items — especially the state race condition and auth check — would make this merge-ready. 👍

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about cc-haha with Dosu Add Dosu to your team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants