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.
📌 简要说明(TLDR)
本次 PR 实现了两大核心能力,旨在提升 非交互模式下 Qwen 工具链在对话连贯性与执行透明度方面的体验:
✅ 会话持久化(Session Persistence)
新增
--session <ID>
参数,支持跨命令保持对话上下文,用户可进行多轮渐进式对话生码。✅ 增强调试输出(Verbose Output Control)
新增
--verbose-to-stdout
选项,允许将工具调用日志输出至 stdout,便于前端集成、日志归集与流式 UI 展示。这两项能力共同解决了当前工具在非交互模式下“交互无记忆、执行无过程”的核心痛点,为产品化落地奠定基础。
🧠 深入探讨(Dive Deeper)
1. Session 持久化设计
~/.qwen_sessions/<ID>.json
sessionId
、createdAt
、updatedAt
、history
(对话记录)、projectPath
geminiClient.setHistory()
恢复上下文session list/info/delete
等管理命令(已实现)2. Verbose 输出控制设计
--verbose
→ stderr(默认,适合终端调试)--verbose --verbose-to-stdout
→ stdout(适合前端/UI/日志系统)--verbose-to-stdout
必须搭配--verbose
使用,避免误用console.error
→process.stdout.write
,确保结构化日志与模型响应同流输出👀 审阅者测试计划(Reviewer Test Plan)
请拉取本分支后,按以下步骤验证功能:
✅ Session 功能测试
✅ Verbose 输出控制测试
🧪 推荐测试用例
--verbose-to-stdout
并grep
关键词--debug
查看 session 文件读写日志✅ 测试矩阵(Testing Matrix)
🔗 关联问题 / bugs
Resolves #628
🎯 预期收益(Impact Summary)
🧩 实施细节(Implementation Notes)
Session 机制
path.join(os.homedir(), '.qwen_sessions',
${sessionId}.json)
execute()
前拦截并处理 sessiongeminiClient.setHistory(session.history)
实现上下文恢复fs.writeFileSync
+ try-catch 确保数据不丢失Verbose 输出控制
if (verboseToStdout && !verbose)
→ 报错退出logVerbose()
函数,根据标志选择console.error
或process.stdout.write
扩展性设计
--session clear --older-than 7d
等📚 使用示例(补充)
多轮对话生码
前端集成流式输出
审计日志归档
🎉 总结
本 PR 不仅实现了 Issue 中提出的全部功能需求,更在错误处理、跨平台兼容、扩展性设计上做了充分考虑。代码通过完整类型检查,与现有功能 100% 兼容,测试覆盖核心场景。
欢迎 Reviewer 按上述测试计划验证,有任何问题我随时响应!