Skip to content

feat(tui): support OSC 7501 program status - #4347

Merged
Grapedge merged 10 commits into
mainfrom
osc7501
Oct 26, 2026
Merged

Grapedge merged 10 commits into
mainfrom
osc7501

Conversation

@Grapedge

@Grapedge Grapedge commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

在交互式 TUI 中支持 OSC 7501 根状态与后台子代理记录;分支同时包含 pi-tui 的上游 v1.4.0 baseline。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

baseline
└── packages/pi-tui                 # 同步 upstream v1.4.0 的输入、渲染、颜色和 wheel 更新

OSC 7501
├── packages/pi-tui
│   ├── src/program-status.ts      # id/title 编码、文本限制和 id 校验
│   ├── src/components/image.ts    # 图片转码缓存同时按 MIME 和源数据区分
│   └── src/terminal.ts            # 可选能力、多记录缓存、子树清除、重放和退出清理
├── packages/node-sdk
│   └── src/interaction.ts         # 审批和提问请求暴露 agentId
└── apps/kimi-code
    ├── src/tui/controllers/program-status.ts
    │                              # 根汇总、子记录生命周期、容量和隐私文案
    ├── src/tui/controllers/session-event-handler.ts
    │                              # 嵌套后台任务事件转发
    ├── src/tui/kimi-tui.ts        # Turn、队列、手动 steer、信任和登录接线
    └── src/tui/reverse-rpc        # 审批和提问的子代理归属

根记录按“当前可见阻断 → 仍有 Agent 工作 → 最后结算结果”的优先级汇总。每个后台子代理另有记录;正常停止和直接退出都会清除全部记录。中英文交互指南与环境变量参考同步更新;OSC 7501 包含三个对应 changeset,baseline 另有两个,图片转码缓存修复另有一个。

Behavior Changes and Affected Users

行为 改动前 改动后 受影响人群 退路
pi-tui baseline 使用旧版输入、渲染和终端能力 同步 upstream v1.4.0,包含 CJK autocomplete、Markdown、键盘、fullscreen image、颜色和 wheel 修复 TUI 用户和 pi-tui 消费者 无;这些是缺陷修复,既有 changeset 已覆盖
交互式 TUI 程序状态 发送能力查询但不上报状态 支持根状态与后台子代理记录,覆盖 working、blocked、done、error、idle 和 clear 使用支持 OSC 7501 终端的 TUI 用户 默认自动探测;PI_PROGRAM_STATUS=0 禁用,1 强制上报
后台任务范围 无程序状态记录 只跟踪后台子代理;后台 shell 和 monitor 不参与根汇总或子记录 使用长驻 shell 或 monitor 任务的用户 无需迁移;这些任务继续在 /tasks 中管理
pi-tui 多记录与兼容性 只支持根记录,baseline 的方法要求所有 Terminal 实现补空实现 支持 id/title、子树清除和重放;setProgramStatus 为可选能力 自定义 Terminal 实现和 pi-tui 消费者 不需要的方法仍可省略;旧式实现保持兼容
图片转码缓存 相同 base64 即使声明不同 MIME 也复用第一次转换结果 缓存同时按 MIME 和源数据区分,避免错误复用转换或失败结果 使用非 PNG 图片且可能改变 MIME 声明的 pi-tui 消费者 无需迁移;同 MIME 的缓存与 LRU 行为不变
SDK 交互归属 handler 类型不暴露 agentId approval 和 question 请求以可选字段暴露 agentId 需要区分子代理审批和提问的 SDK 客户端 additive 类型变化,无需迁移
其他客户端和终端协议 kimi -p、desktop、web、ACP 及 OSC 9 / OSC 9;4 的既有行为 不变;本次只接入交互式 TUI,未合并通知或百分比进度通道 print 模式、desktop、web、ACP 用户及通知/进度使用者 无需迁移

对应测试覆盖:

  • baseline 与 pi-tui:1162 项测试通过,1 项跳过;覆盖编码、id 校验、子树清除、stop/start 重放、直接退出清理、旧式 Terminal 兼容,以及相同数据不同 MIME 的转码缓存隔离。
  • TUI 与后台任务:169 个文件、3044 项测试通过;覆盖根汇总、嵌套后台事件、Ctrl-S、子记录生命周期、容量、恢复和隐私。
  • SDK:181 项测试通过,并新增 agentId 公共类型断言。
  • 真实运行:真实 TUI 字节验证覆盖 idle、permission、auth 和 clear;Termy 实测回复 OSC 7501 查询。未将标签栏 badge 视觉展示记为已自动验收。
  • 其他检查:两个包的 typecheck、docs build、git diff --check 均通过;pnpm lint 为 0 errors。

Checklist

  • I have read the CONTRIBUTING document.
  • No separate issue; the requirement is described above.
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8f1f258

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@moonshot-ai/kimi-code-sdk Minor
@moonshot-ai/pi-tui Minor
@moonshot-ai/kimi-code Minor
kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T13:20:05.974629Z 8f1f258 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@8f1f258
npx https://pkg.pr.new/@moonshot-ai/kimi-code@8f1f258

commit: 8f1f258

@github-actions

Copy link
Copy Markdown
Contributor

❌ Nix build failed

Hash mismatch in pnpmDeps:

Hash
specified sha256-1no6CVTIvsGgNuqbMVvgoOsj6/oh+Ng69mFFgxaxtAk=
got sha256-fvtkW8HSacFek+jT0t7v3WcYsSTfI22+4kDEyEYHFlY=

Please update flake.nix with the got hash.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ffa738231

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/pi-tui/src/components/image.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: caa9ffba44

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/pi-tui/src/tui.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ffca4e7d5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/pi-tui/src/tui.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c936ad328d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/pi-tui/src/autocomplete.ts Resolved
@Grapedge

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 7b06a9541a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

liruifengv
liruifengv previously approved these changes Oct 26, 2026
@Grapedge
Grapedge merged commit b3c6e0a into main Oct 26, 2026
16 checks passed
@Grapedge
Grapedge deleted the osc7501 branch October 26, 2026 13:05

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f1f25814a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +171 to +175
this.host.programStatus?.startSubagent({
agentId: event.subagentId,
title: event.description ?? event.subagentName,
taskId: event.taskId,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear aborted foreground subagent status records

When a turn is cancelled while a foreground-only subagent is running, v2 emits no completed, failed, or cancelled lifecycle event for that child, so this new working record is never settled or removed. handleTurnEnd already compensates for the same lifecycle gap by dropping foreground-only activity records, but later turns only clear settled program-status children; the stale child therefore remains working until the session resets. Remove foreground-only program-status children when their owning turn ends while preserving agents represented by background-task state.

Useful? React with 👍 / 👎.

// Flushing it would turn a delayed tail into text and an OSC's BEL
// terminator into Ctrl+G (the external editor shortcut). Other input,
// including Alt+] followed by text, must retain bounded recovery.
if (TERMINAL_REPLY_HEADER_PATTERN.test(this.buffer)) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Bound incomplete terminal-reply buffering

If a recognized OSC/DCS/APC reply is truncated after its header—for example, an OSC 7501 reply loses its BEL/ST terminator—this return leaves the buffer without any timeout. Subsequent printable keys, Enter, and Ctrl-C are appended to the unterminated control string and never emitted; recovery requires another ESC/CAN/SUB and discards the intervening input. Keep a bounded stale-reply timeout that discards the incomplete reply, with a regression test for input recovery.

AGENTS.md reference: packages/pi-tui/AGENTS.md:L11-L15

Useful? React with 👍 / 👎.

Comment on lines +4830 to +4833
this.mountEditorReplacement(panel, undefined, () => {
this.activeApprovalPanel = undefined;
this.patchLivePane({ pendingApproval: null });
this.approvalController.cancelAll('Approval panel displaced', false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear prompt state when displacing reverse-RPC panels

When a non-RPC panel replaces an approval and no other reverse-RPC prompt is queued, this callback cancels through the new dismiss path rather than hideApprovalPanel, so notifications.setPrompt(false) never runs; the analogous question callback has the same problem. On short fullscreen terminals, the Updates panel consequently remains folded as though a prompt still needs its rows after the prompt is gone. Clear the prompt bookkeeping during displacement without restoring the editor.

Useful? React with 👍 / 👎.

// When the last shell command finishes, leave the shell streaming phase,
// release one queued message (if any), and refresh the activity pane.
if (this.shellOutputStreams.size === 0) {
this.programStatus.finishShell();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Report nonzero shell exits as errors

When a foreground shell command completes normally with isError: true—the resolved result used by ShellCommandService for a nonzero exit—this unconditional call records the outcome as idle. Only promise rejection calls failRequest, so OSC 7501 reports success-like idle status even though the transcript marks the command as failed. Select the error or successful completion path from isError before clearing the shell phase.

Useful? React with 👍 / 👎.

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.

2 participants