Skip to content

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

Merged
tt-a1i merged 7 commits into
openpi-dev:mainfrom
somewan820:feat/clear-context-on-ctrl-c
Aug 30, 2026
Merged

tt-a1i merged 7 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 Resolved
Comment thread extensions/clear-context/index.ts Resolved
@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 输入”的回归测试。

Comment thread extensions/clear-context/index.ts Resolved
@somewan820
somewan820 requested a review from tt-a1i August 30, 2026 05:07

@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.

Re-reviewed exact head dc6cc2f after updating onto main a05c981. The prior editor-composition blocker is resolved by registering a bounded editor layer that preserves the base editor and forwards non-target input. Focused tests cover idle/empty-only activation, whitespace drafts, existing editor forwarding, and Pi /new session history. Local validation passed: focused 6/6, bun run check, 1058 Node tests passed with 1 platform skip, and 30/30 Vitest tests. A real isolated Pi 0.84.3 TUI smoke loaded only this exact-head extension: non-empty and whitespace Ctrl+C preserved native clearing, while empty Ctrl+C visibly started a new session. Fresh required CI passed on Node 22.19.0, Node 24, and Windows. No blocking findings.

@tt-a1i
tt-a1i merged commit ba26d32 into openpi-dev:main Aug 30, 2026
4 checks passed
agnitum2009 pushed a commit to agnitum2009/openpi that referenced this pull request Sep 3, 2026
* feat: 空输入时用 Ctrl+C 清除上下文

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

Closes openpi-dev#280

* test: 补充 Ctrl+C 清除上下文集成断言

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

Refs openpi-dev#280

* fix: scope clear context shortcut to editor

* fix: support node strip-only test runner

* fix(clear-context): compose shortcut with editor layers

---------

Co-authored-by: tt-a1i <[email protected]>
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