Skip to content

feat(tui_v2): 新增 /rename 命令,支持重命名当前会话#359

Open
kkingwing wants to merge 1 commit into
lsdefine:mainfrom
kkingwing:feature/tui-rename-command
Open

feat(tui_v2): 新增 /rename 命令,支持重命名当前会话#359
kkingwing wants to merge 1 commit into
lsdefine:mainfrom
kkingwing:feature/tui-rename-command

Conversation

@kkingwing
Copy link
Copy Markdown

改动内容

  • 在 tuiapp_v2.py 中新增 /rename <name> 命令
  • 支持将当前会话重命名为指定名称,侧边栏即时刷新
  • 参数缺失时给出用法提示

改动文件

  • frontends/tuiapp_v2.py:COMMANDS 列表、handlers 字典、_cmd_rename 方法

用法示例

/rename 我的新会话

测试

  • /rename 无参数 → 显示用法提示 ✅
  • /rename 新名字 → 会话标题更新、侧边栏刷新 ✅

@kkingwing kkingwing force-pushed the feature/tui-rename-command branch from f26762c to e884e25 Compare May 13, 2026 10:15
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant