Skip to content

refactor: remove unused session terminal service - #4333

Merged
wbxl2000 merged 3 commits into
mainfrom
qer/remove-session-terminals
Oct 22, 2026
Merged

wbxl2000 merged 3 commits into
mainfrom
qer/remove-session-terminals

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

删除 server 与引擎里已经无法使用、也没有客户端在用的会话终端(PTY)功能。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

现状:v1 WebSocket 连接的分发只处理 pong / client_hello / subscribe / subscribe_v2 / unsubscribe / unsubscribe_v2,terminal_attach / terminal_input / terminal_resize / terminal_detach / terminal_close 落到 default 被静默丢弃,也从不推送 terminal_output / terminal_exit。REST 仍能创建、列出、关闭 PTY,但终端的输入输出没法收发。web 没有终端入口,desktop 用自己的 Electron PTY,都不走这条链路。

整条链路一起删:

 packages/kap-server/src/
 ├── protocol/
-│   ├── rest-terminal.ts
 │   ├── ws-control.ts        # drop terminal_* message/ack schemas and operation entries
 │   ├── rest-meta.ts         # drop capabilities.terminal
 │   ├── error-codes.ts       # drop TERMINAL_NOT_FOUND (40414)
 │   └── events-zod.ts        # drop 'terminal.not_found'
 ├── routes/
-│   ├── terminals.ts
 │   ├── registerApiV1Routes.ts  # drop enableTerminals option
 │   └── meta.ts
 └── start.ts                 # drop enableTerminals and the OpenAPI "terminals" tag
 packages/agent-core-v2/src/
 ├── session/
-│   └── terminal/terminalService.ts
 ├── os/
-│   ├── interface/terminal.ts
-│   ├── interface/terminalErrors.ts
-│   └── backends/node-local/hostTerminalService.ts
 ├── runtime/                 # RuntimeCapability loses 'terminal'; Runtime loses .terminal
 └── app/sessionManager/sessionManagerService.ts

会话空闲回收的保留条件少了"有运行中的终端"一项:

 retained(handle)
-  if any terminal is running: return true
   if any agent has cron tasks: return true
   return busy || pending interaction

依赖:agent-core-v2 的 dependencies 和 CLI 的 optionalDependencies 去掉 node-pty,根 postinstall(scripts/fix-node-pty-perms.mjs)一并删除。desktop 的原生终端在 code-app 侧自带 node-pty,不受影响。

测试与文档:删掉 kap-server/test/terminals.test.ts、agent-core-v2/test/session/terminal/、klient/test/e2e/legacy/terminal.test.ts 和 klient e2e harness 里的终端方法;runtime 相关测试里的 'terminal' capability 换成现有能力;apiSurface 快照少 4 条终端路由;docs/{en,zh}/reference/server-api.md 删除"终端"一节和 capabilities 里的 terminal(该节提到的 --allow-remote-terminals 早已不存在)。

flake.nix 的 pnpmDeps hash 已按 Nix Build CI 给出的值随 lockfile 更新。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
GET/POST /api/v1/sessions/{session_id}/terminals、GET .../terminals/{terminal_id}、POST .../terminals/{terminal_id}:close loopback 绑定时可用,能创建 / 列出 / 关闭 PTY 404 无已知客户端:web 与 desktop 都不调用;按 server-api.md 自写脚本的外部调用方只能管理生命周期,拿不到输入输出 无,能力整体移除
WS 发送 terminal_* 控制消息 静默忽略,无 ack 静默忽略,无 ack(不变) — —
GET /api/v1/meta 的 capabilities 含 terminal: true 不含 terminal 无客户端读取该字段(code-app 侧无引用) 无
AsyncAPI 文档 列出 5 个 terminal_* 控制操作 不再列出 按文档生成客户端的外部调用方 无
会话空闲回收 有运行中的终端时保留会话 不再考虑终端(已无法创建) — —
CLI 安装 拉取 node-pty 原生可选依赖 不再拉取 — —

终端 REST 接口删除后没有退路;现有客户端都感知不到这些接口,所以本 PR 不写 changeset。这两点需要维护者在 PR 里确认。

code-app 侧同步删除了客户端里对应的死代码:MoonshotAI/kimi-code-app#948。两边互不依赖,合入顺序不限。

受影响模块与验证:

  • kap-server:apiSurface 快照更新;securityExposure.test.ts 去掉终端路由断言,保留 shutdown 断言。
  • agent-core-v2:sessionManagerService.test.ts 的保留条件用例去掉终端两条,其余不变;runtimeRegistry.test.ts 的 degraded 用例改用 fs 运行时缺少 process 的组合。
  • pnpm typecheck、pnpm lint(0 error)、node scripts/check-nix-workspace.mjs 通过;pnpm vitest run packages/kap-server packages/agent-core-v2 packages/acp-server packages/klient 中 9096 个用例通过,唯一失败的 test/tool/tool.test.ts > returns the spawned agent id when a foreground subagent times out 在 origin/main 上同样失败,与本 PR 无关。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • 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.

The terminal_* WebSocket controls lost their dispatch when the v1 connection was rewritten, so terminals could be created over REST but never attached, written to, or resized. No client uses them: the web UI has no terminal and the desktop app runs its own native PTY. Remove the REST routes, WebSocket schemas, meta capability, error code, session terminal service, host PTY backend, runtime terminal capability, and the node-pty dependency.
@changeset-bot

changeset-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f17e4e8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a 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-22T11:47:58.120091Z f17e4e8 Manual request
ℹ️ 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@f17e4e8
npx https://pkg.pr.new/@moonshot-ai/kimi-code@f17e4e8

commit: f17e4e8

@github-actions

Copy link
Copy Markdown
Contributor

❌ Nix build failed

Hash mismatch in pnpmDeps:

Hash
specified sha256-Abu/VvIm8BcAi5nf2/4W7tj9o3hsW5ZrNaj/VVOlaeM=
got sha256-1no6CVTIvsGgNuqbMVvgoOsj6/oh+Ng69mFFgxaxtAk=

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: 0049f2f90d

ℹ️ 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".

@wbxl2000

Copy link
Copy Markdown
Collaborator Author

@codex review

上一轮唯一的 P1(认为 kimi web 的终端面板会因路由删除而 404)经核实是误报,已回复并 resolve:

  • apps/kimi-code/dist-web 里没有终端 UI:bundle 中没有 xterm,toggleTerminal 只出现在共享 i18n 的中英文案里,没有按钮或快捷键引用它。
  • 命中的 /terminals 与 terminal_* 请求位于 web 的 daemon API 客户端,没有调用方,是死代码;code-app 侧已在 MoonshotAI/kimi-code-app#948 删除,下次常规同步 dist-web 时随之消失。本 PR 不夹带 dist-web 同步,以免混入其他 web 改动。
  • 即使被调用,删除前这些接口也只能创建 PTY,terminal_* 控制消息在 v1 WebSocket 分发里被静默丢弃,无法收发输入输出,用户侧没有可感知的变化。

另外,上一轮评审之后新增了一个提交,按 Nix CI 给出的值更新了 flake.nix 的 pnpmDeps hash。请基于最新提交重新评审。

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: f17e4e8180

ℹ️ 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".

@wbxl2000
wbxl2000 merged commit 79a76ea into main Oct 22, 2026
16 checks passed
@wbxl2000
wbxl2000 deleted the qer/remove-session-terminals branch October 22, 2026 11:57
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.

3 participants