feat: 空输入时用 Ctrl+C 清除上下文 - #281
Conversation
输入框有内容时保留 Pi 原生清空行为,输入框为空时转发到内置 /new 命令创建干净会话。 Closes openpi-dev#280
验证 Pi 创建新 Session 后不会保留旧分支和模型上下文消息。 Refs openpi-dev#280
tt-a1i
left a comment
There was a problem hiding this comment.
Review summary
Verdict: changes requested. Routing through Pi's built-in /new lifecycle is the right ownership boundary, and the focused tests/checks pass. However, the raw terminal listener runs before TUI focus dispatch, so the implementation currently applies outside the idle main editor and can replace Ctrl+C with Enter inside overlays or while the session is active. The empty check also treats whitespace-only drafts as empty. Please scope interception to the idle main editor, preserve non-idle/overlay native input, and add integration coverage for those paths.
tt-a1i
left a comment
There was a problem hiding this comment.
按精确 head 7371bb3 复核并运行专项测试(4/4 通过)。上一轮 Ctrl+C 的 overlay/忙碌态/空白输入问题已经修复,/new 也继续交给 Pi 生命周期处理。当前剩余阻塞是 Editor 组合:实现直接替换当前 editor factory,Session 期间会让先加载的第三方或其他自定义 Editor 完全失效。仓库已有 extensions/shared/editor-layers.ts 专门保留 base editor 并按序组合多个能力;请把快捷键实现成该 layer 上的 wrapper,并增加“既有自定义 editor 仍收到非 Ctrl+C 输入”的回归测试。
| if (ctx.mode !== "tui") return () => {}; | ||
|
|
||
| const previousEditor = ctx.ui.getEditorComponent(); | ||
| ctx.ui.setEditorComponent( |
There was a problem hiding this comment.
[P1] 这里保存 previous editor 只用于 shutdown 恢复,运行期间却直接用新的 ClearContextEditor 替换它;如果用户/第三方扩展已经安装自定义 editor,其行为会整段丢失。请通过仓库现有 registerEditorLayer/removeEditorLayer 组合在 base editor 之上,并验证普通输入继续委托给既有 editor。
Problem
当前输入框中的
Ctrl+C只会清空输入内容。当输入框为空时,用户无法快速清除当前会话上下文和历史消息,只能手动输入/new。Issue: #280
Value
让空输入时的
Ctrl+C具备与 Codex 类似的上下文清理行为,同时保留有输入内容时的原生编辑体验,便于快速开始新的任务。Approach
clear-context扩展,监听 TUI 原始终端输入。Ctrl+C,继续使用 Pi 原生清空编辑器逻辑。Ctrl+C转换为内置/new命令并提交。newSession命令路径完成 Session 替换,保留 Pi 的持久化、清理、Transcript 和生命周期处理,不直接修改 Session 文件。Validation
bun run checkbun run testImpact
Ctrl+C创建干净的新 Session;有输入时行为不变。/new和 Session 生命周期。Ctrl+C时生效。Closes #280