feat(tui_v2): 新增 /rename 命令,支持重命名当前会话#359
Open
kkingwing wants to merge 1 commit into
Open
Conversation
f26762c to
e884e25
Compare
shenhao-stu
added a commit
to shenhao-stu/GenericAgent
that referenced
this pull request
May 15, 2026
Two pieces of follow-up to lsdefine#359 → /rename / /continue <name>: 1. Bug fixes for /rename + /continue <name>: - Reproduced two failure modes the user hit: (a) /rename right after launch (no log file yet) → path_for() returned None because of an isfile check; (b) /rename then any /new or /continue snapshots the log out from under the entry → restore reads the now-empty file and reports "为空或格式不符". - frontends/session_names.py: - new _resolve_basename() falls back to the most recent non-empty model_responses_snapshot_<same_pid>_*.txt when the live log is missing/empty. Mirrors codex's behaviour of treating the title as an attribute of the conversation, not a single file. - path_for() gains exclude_pid so /continue <self-name> doesn't resolve back to the current PID. - new migrate(old, new) re-anchors a name onto a different log basename; called from _do_continue_restore so the restored conversation's name follows the actively-written log instead of the cold source file. - frontends/tuiapp_v2.py: - _cmd_rename now os.makedirs + touches the log file so the entry is meaningful from the very first /rename. - _cmd_continue with a name token: excludes current PID via path_for, then if the same name lives on the current PID's log (just-renamed), prints "✅ 当前已在 'X' 会话中" instead of trying a destructive restore. - _do_continue_restore migrates the name from source path to _current_log_path() after restore so /rename and lookups follow the active log on the next round. 2. /cost — per-session token usage: - frontends/cost_tracker.py (new): per-thread TokenStats accumulator with install() that wraps llmcore._record_usage AND llmcore.print. The print hook captures Anthropic SSE's [Output] tokens=N line (which never goes through _record_usage). All three API modes (messages/chat_completions/responses) handled. llmcore stays untouched. - tuiapp_v2.py: - /cost in COMMANDS + _handlers; install() called from GenericAgentTUI.__init__ once. - /cost shows the active session's req/in/out/cache+/cache↻/hit%; /cost all enumerates every tracked thread. verification (Monitor pass): 14 checks across rename bug fixes (5), chip rendering (3), /cost capture for messages+SSE+chat+responses (3), and PR lsdefine#389 coexistence (3 — input fields, InputArea methods, /rename + /continue same-session). cross-process restart proof retained.
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.
改动内容
/rename <name>命令改动文件
frontends/tuiapp_v2.py:COMMANDS 列表、handlers 字典、_cmd_rename 方法用法示例
/rename 我的新会话
测试
/rename无参数 → 显示用法提示 ✅/rename 新名字→ 会话标题更新、侧边栏刷新 ✅