Repository navigation
fix(tui): track steer read state across turns - #4627
Conversation
A steer message stays faint until turn.steer matches its text. A rejected steer returns to solid text and keeps the error.
🦋 Changeset detectedLatest commit: 0b816e2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27e2ca9685
ℹ️ 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".
There was a problem hiding this comment.
🟡 Changes recommended
Steer acknowledgment matching can consume stale entries and fail for image-only or augmented/merged inputs, leaving accepted messages and summaries incorrectly dimmed.
3 open issues
What changed in this PR
本 PR 为终端中注入当前轮次的消息增加待接收状态:文字先显示为淡色,收到 turn.steer 确认或发送失败后恢复实色,帮助用户区分提交与接收。
Changes:
- 跟踪 steer 提交,并根据确认事件更新消息状态。
- 为用户消息正文和吸顶摘要应用淡色效果,不改变图片显示。
- 增加匹配、渲染及失败恢复测试,同步中英文文档和 changeset。
| File | Description |
|---|---|
docs/zh/reference/tools.md |
补充等待期间注入文字的淡色说明。 |
docs/zh/reference/keyboard.md |
说明 Ctrl-S 消息接收前的显示状态。 |
docs/en/reference/tools.md |
同步英文工具行为说明。 |
docs/en/reference/keyboard.md |
同步英文快捷键说明。 |
apps/kimi-code/test/tui/utils/steer-input.test.ts |
增加确认文本匹配测试。 |
apps/kimi-code/test/tui/kimi-tui-message-flow.test.ts |
覆盖 Ctrl-S 确认及失败后的显示恢复。 |
apps/kimi-code/test/tui/components/messages/sticky-user-message.test.ts |
验证吸顶摘要的淡色状态。 |
apps/kimi-code/src/tui/utils/steer-delivery.ts |
新增文本提取与待确认批次匹配逻辑。 |
apps/kimi-code/src/tui/types.ts |
为消息条目增加待接收标记。 |
apps/kimi-code/src/tui/kimi-tui.ts |
管理提交跟踪、确认和失败恢复。 |
apps/kimi-code/src/tui/controllers/session-event-handler.ts |
转交 turn.steer 确认事件。 |
apps/kimi-code/src/tui/components/messages/user-message.ts |
根据待接收状态渲染淡色文字。 |
apps/kimi-code/src/tui/components/messages/sticky-user-message.ts |
让吸顶摘要同步消息的淡色状态。 |
.changeset/fade-steer-until-accepted.md |
记录用户可见的显示行为变化。 |
Review effort: Balanced
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dc16d2a59b
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fdef0602de
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 787dfd16c1
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: af124ffaf8
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8f862bea04
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0b816e2fe7
ℹ️ 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".
…ng turn First slice of upstream MoonshotAI/kimi-code a5724dd (MoonshotAI#4627): the engine now tells the caller what happened to a steer instead of returning undefined. IAgentPromptChannel.submitSteer returns SteerResult: prompt id, creation time, state (running / queued / blocked) and a steered flag that is true only when the prompt was accepted into the turn that was already running. A steer submitted while the loop is running-but-not-steerable, paused, or has a queue returns 'queued' immediately instead of blocking; a blocked handle returns 'blocked'; the promptWithSkills result carries the same optional steered flag. evaluateSettle now mirrors drained nudges when the turn ends without a current step, so a consumed steer is projected even when the turn is cancelled, filtered, step-capped, stopped, failed, or completed between steps. Local note: this fork's promptWithSkills already had the queued/blocked result states; only the steered flag was missing there. Verified: engine/app/kap-server typechecks clean; prompt, loop and skill suites 304 pass (8 snapshots). The SDK and TUI halves of MoonshotAI#4627 follow in the next commit; the ledger row stays in_progress until they land.
Port of upstream MoonshotAI/kimi-code a5724dd (MoonshotAI#4627). A steer was rendered at full intensity the moment it was submitted, so a user could not tell whether the agent had actually picked it up — and a steer that an interrupted turn carried into the next turn looked delivered long before the new turn started. Engine: `IAgentPromptChannel.submitSteer` and `IAgentSkillService.promptWithSkills` resolve with `SteerResult` — the submission's `prompt_id`, `created_at`, `state` (`running` / `queued` / `blocked`) and `steered`, which is true only when the running turn took the text. `evaluateSettle` mirrors drained nudges back onto the turn so a consumed steer is reported once. Wire: `steerResultSchema` replaces the `maybe(promptLaunchResultSchema)` output of `agentPromptService.submitSteer`, and the SDK maps it to `PromptSubmissionResult`. TUI: `SteerDelivery` keeps each submitted batch faded (`currentTheme.fade`) until its prompt id comes back on `turn.steer`, `turn.prompt`, `turn.started` or `prompt.completed`, or the text matches the legacy `turn.steer` payload for engines that carry no ids. Matching is boundary-aware, so a short steer cannot be confirmed by a substring of a different message, and the prompt-id path keeps a stale id from stealing a later submission of the same text. Local-form notes: - `KimiTUI` has no `dispatchPreparedInput`: message dispatch lives in `MessageDispatchController`, so the state machine sits there and `KimiTUI` only exposes the four `SessionEventHost` hooks. - The fork carries two `steerMessage` implementations (`KimiTUI` and `MessageDispatchController`); both are wired, because the automatic queue drain and the manual Ctrl-S path each call one. - `SteerResult` is imported through the package root, matching the facade's existing `PromptLaunchResult` alias style. - `AgentEvent` does not include `turn.prompt` / `turn.steer`, so the handler narrows them through the same `object` guards upstream uses instead of widening the public union. - `promptWithSkills` / `steer` drop `async` on both SDK entry points because they now just return the inner promise; keeping `async` adds `require-await` warnings. Restored a local regression on the way: `event-mapper` dropped `prompt.completed` entirely, so a v2 gate-blocked or rejected prompt could not settle a client. The type is forwarded again with the upstream `blocked|failed` filter. Verified: apps/kimi-code and klient typecheck clean; klient 32 tests, node-sdk session suites 22 pass (16 on the post-async re-run), sdk-rpc-client-v2 78 pass / 3 skip, kimi-tui message flow 420 pass — all green. check:no-comments, check:no-hardcoded-prose, check:locale-keys and check:t-coverage pass. Reverting the `steerPending` clear in `setSteerEntriesPending` reddens four of the new cases (goal-queue confirmation, `blocked` release, `failed` release, same-text takeover) and restoring it turns them green again. Pre-existing, unchanged: node-sdk's own `tsc` reports `#/errors` member errors from agent-core-v2's path aliases.
The harness's `steer` facade still re-implemented the pre-MoonshotAI#4627 behavior: it submitted through `IAgentLoopService` and answered `{turn_id}` on launch, `undefined` otherwise. The engine now answers a `SteerResult` with the submission's state and whether the running turn took the text, so the facade follows upstream and delegates to `IAgentPromptChannel.submitSteer`. `activateSkill`'s steer cases now pin `steered: true` for a merged steer and `steered: false` for a queued one, which is the signal the TUI's fade-until-read state machine consumes. Verified: agent-core-v2 typecheck clean; prompt + skill suites 185 pass, loop + task suites 373 pass / 1 skip, no failures.
The steer read state lands in full: the engine answers `SteerResult`, the wire and SDK carry `PromptSubmissionResult`, and the TUI keeps each steer faded until its own prompt id (or, on engines without ids, its text) comes back on `turn.steer` / `turn.prompt` / `turn.started` / `prompt.completed`. Probe: `fades a Ctrl-S steer until turn.steer` in the kimi-tui message-flow suite, which drives a real Ctrl-S submission through the editor and asserts the fade appears and clears on the event.

Requirement or Bug
终端 steer 目前主要靠消息正文识别
turn.steer。取消后转入后续轮次、goal continuation 的普通队列、相同正文、多客户端、skill/媒体转换,以及 drain 后立即取消时,确认可能缺失或配错,表现为消息误恢复或永久淡化。这个 PR 让终端使用 core 已有的
promptId追踪投递,直到 core 真正消费消息才恢复实色,并补齐 blocked、失败和 reload 的退出路径。无独立关联 issue。Bug Reproduction Steps
turn.ended清空待确认记录,却不恢复消息上的淡化标记;后续turn.prompt也不会被识别。void,终端一直等待不会到来的turn.steer。turn.steer确认。上述路径均已固化成回归测试;真实终端另用本地 provider 验证了正常 steer 的淡化与恢复。
Root Cause
根因有三层,属于根本性修复而不是增加延迟或隐藏错误:
promptId,但Session.steer()/promptWithSkills()把身份和提交状态丢成了void,终端只能用正文关联。turn.steer当唯一已读事件,并在turn.ended清空关联记录;后续新轮和普通队列没有确认出口。Code Changes
**核心思路:**复用 core 已生成的 id,不新增客户端 id 协议。提交结果告诉终端该等当前轮注入还是自己的新轮;事件里的 id 决定何时恢复实色。正文仅用于无 id 事件和 seeded 合并消息的兼容回退。
promptIdstaterunning/queued/blocked保持原含义steeredtrue等turn.steer;false且 queued 等自己的新轮flowchart TD A[提交 steer] --> B{core 返回状态} B -->|steered| C[等待 turn.steer.promptIds] B -->|queued| D[等待 turn.prompt / turn.started 的 promptId] B -->|普通新轮| E[按普通 prompt 显示] B -->|blocked / error / reload| F[释放本地未读状态] C --> G[恢复实色] D --> G H[消费事件先到] --> I[按 id 暂存并在 RPC 返回后核销] I --> G正常 tracked turn 仍走原来的
turn.steer,只是主匹配键从正文换成 id。turn.ended不再清空关联;直接开启普通新轮仍保持实色。公开Event联合没有增加成员,TUI 使用严格运行时守卫,因此 SDK 使用者的穷尽switch不需要新增分支。queued 提交在后续 prompt gate 被 rejected 时,复用
prompt.completed(blocked|failed)按 id 释放本地未读状态;failed 现在也通过 SDK mapper,成功完成的prompt.completed(completed)仍不透传。blocked 的 turn finalize 行为保持不变。关键决策:
promptId和提交状态turn.prompt/turn.startedturn.steerEvent联合不变,TUI 做严格守卫steered输出字段可选,SDK 映射为布尔值阅读指南:
packages/agent-core-v2/src/agent/loop/promptChannel.ts:普通 steer 的 id、queued / blocked / running 与steered返回逻辑。packages/agent-core-v2/src/features/skill/skillService.ts:skill steer 使用同一提交语义。packages/node-sdk/src/session.ts与sdk-rpc-client-v2.ts:SDK 的PromptSubmissionResult和 snake_case → camelCase 映射。apps/kimi-code/src/tui/kimi-tui.ts:pending 记录、早到 id、跨轮确认与失败 / reload 收尾。apps/kimi-code/src/tui/controllers/session-event-handler.ts:当前轮和后续轮事件入口。packages/agent-core-v2/src/agent/loop/loopService.ts:仅在确定结束的 settle 分支补 mirror,不影响正常 continuation。klient contract、facade、事件转发、测试和双语用户文档主要是接线和回归覆盖,可以略读。
Screenshots / Recordings
以下快照来自本 PR 分支的真实 CLI:本地 provider 保持第一轮请求时提交 Ctrl-S,再释放响应。图片只从终端 ANSI 快照渲染同一条中性示例消息,不包含工作区路径、会话 id 或凭据;左侧原始输出包含
ESC[2m,右侧不包含。请求日志同时确认第二次模型调用包含
focus on tests,且只出现一次。Behavior Changes and Affected Users
turn.steerpromptId等到 core 注入后恢复实色turn.ended清掉关联,可能永久淡化turn.prompt/turn.started确认turn.steerSession.steer()返回值Promise<void>;untracked queued 也无可观察身份PromptSubmissionResult,含promptId/state/steeredundefined的外部脚本会观察到新对象stateSession.promptWithSkills()返回值Promise<void>steered时仍可读turn.prompt/turn.steer事件联合Event做穷尽switch的 TypeScript 用户turn.steer对应覆盖:core prompt queue 测 accepted、untracked queued、blocked、drain-cancel 和 seeded 新轮;skill 测试测 accepted / queued;klient 测试保留旧输出兼容;SDK 测试测返回值映射、事件 id 转发和 blocked / failed 透传;TUI 测试测真实 ANSI 外观、错误 id、同文本、跨轮、goal queued、提交时 blocked、queued 后 rejected 和 reload。
验证命令与结果
pnpm lint:0 errors(仓库现有 warnings)。f2db5f9c2在 queued 后被真实 hook 拒绝,消息行仍为ESC[1;2m;当前修复版本恢复为ESC[1m。两次均保存了 provider 请求、hook 调用和 ANSI 屏幕证据。blocked 为真实运行复现;failed 由 SDK mapper 与 TUI 回归覆盖,不将其表述为真实运行复现。rpc.result(queued)先于prompt.completed(blocked)(约 44–74ms),最终消息行均无 dim,未复现该竞态,因此未增加 rejected-id buffer。Checklist
/approve). 无独立关联 issue。gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.