Skip to content

feat: 空输入时用 Ctrl+C 清除上下文 - #281

Open
somewan820 wants to merge 5 commits into
openpi-dev:mainfrom
somewan820:feat/clear-context-on-ctrl-c
Open

feat: 空输入时用 Ctrl+C 清除上下文#281
somewan820 wants to merge 5 commits into
openpi-dev:mainfrom
somewan820:feat/clear-context-on-ctrl-c

Conversation

@somewan820

Copy link
Copy Markdown
Collaborator

Problem

当前输入框中的 Ctrl+C 只会清空输入内容。当输入框为空时,用户无法快速清除当前会话上下文和历史消息,只能手动输入 /new

Issue: #280

Value

让空输入时的 Ctrl+C 具备与 Codex 类似的上下文清理行为,同时保留有输入内容时的原生编辑体验,便于快速开始新的任务。

Approach

  • 新增 clear-context 扩展,监听 TUI 原始终端输入。
  • 输入框有内容时不拦截 Ctrl+C,继续使用 Pi 原生清空编辑器逻辑。
  • 输入框为空时,将 Ctrl+C 转换为内置 /new 命令并提交。
  • 通过 Pi 原生 newSession 命令路径完成 Session 替换,保留 Pi 的持久化、清理、Transcript 和生命周期处理,不直接修改 Session 文件。
  • 增加有内容和空内容两种行为的自动化测试。

Validation

  • bun run check
  • bun run test
  • 970 个测试通过,1 个跳过,0 个失败。

Impact

  • 用户可见行为:空输入时第一次 Ctrl+C 创建干净的新 Session;有输入时行为不变。
  • 模型上下文:新 Session 不携带旧会话历史。
  • 运行时/生命周期:沿用 Pi 原生 /new 和 Session 生命周期。
  • 持久化数据:不直接重写旧 Session 文件,不改变现有配置。
  • 兼容性风险:仅在 TUI 模式、编辑器为空且按下 Ctrl+C 时生效。

Closes #280

输入框有内容时保留 Pi 原生清空行为,输入框为空时转发到内置 /new 命令创建干净会话。

Closes openpi-dev#280
验证 Pi 创建新 Session 后不会保留旧分支和模型上下文消息。

Refs openpi-dev#280
@somewan820 somewan820 self-assigned this Aug 29, 2026
@somewan820
somewan820 requested review from tt-a1i and a lite review from Copilot August 29, 2026 06:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@tt-a1i tt-a1i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread extensions/clear-context/index.ts Outdated
Comment thread extensions/clear-context/index.ts Outdated
@somewan820
somewan820 requested a review from tt-a1i August 29, 2026 12:35

@tt-a1i tt-a1i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

按精确 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(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 这里保存 previous editor 只用于 shutdown 恢复,运行期间却直接用新的 ClearContextEditor 替换它;如果用户/第三方扩展已经安装自定义 editor,其行为会整段丢失。请通过仓库现有 registerEditorLayer/removeEditorLayer 组合在 base editor 之上,并验证普通输入继续委托给既有 editor。

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.

feat: 空输入时用 Ctrl+C 清除当前上下文

3 participants