Skip to content

feat(prediction): refine next-prompt interactions - #5379

Merged
sailist merged 1 commit into
release/2026-11-25from
feat-451-11-25-next-prompt-release-11-25
Nov 25, 2026
Merged

sailist merged 1 commit into
release/2026-11-25from
feat-451-11-25-next-prompt-release-11-25

Conversation

@sailist

@sailist sailist commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Screenshots / Recordings

本 PR 将 #5180 原样移植到 release/2026-11-25(相对 base 的代码 diff 与 #5180 完全一致)。以下实拍来自 #5180(脚本化 stub 模型):空输入 placeholder → 预测出现 → 输入隐藏 → 清空召回 → Tab / 右方向键采纳 → show=no 回退默认。Desktop 为真实 Electron e2e 截屏,TUI 为真实终端运行。

Desktop(Electron e2e)

状态 截图
首条消息前:默认 placeholder,无预测提示 app idle placeholder
预测在途:无「预测中」提示 app in-flight
预测到达:直接占用空输入 placeholder app prediction placeholder
输入草稿:placeholder 隐藏,真实输入优先 app typing hides
清空输入:预测召回 app clearing recalls
Tab 采纳为真实文本,Enter 才发送 app tab accepts
下一轮 show=no:回到默认 placeholder app show no

TUI(真实终端运行)

状态 截图
启动:空编辑器,无预测提示 tui startup
turn 完成:预测以 placeholder 显示,保留硬件光标 tui prediction placeholder
输入草稿:预测隐藏 tui typing hides
清空输入:预测召回 tui clearing recalls
Tab 采纳为真实文本,不自动发送 tui tab accepts
下一轮 show=no:编辑器回到空态 tui show no

Requirement or Bug

将已合入 main 的 #5180(squash 提交 6536e55)移植到 release/2026-11-25,随 11-25 发版一起发布。实验性提示词预测需要统一的结构化输出和连续可用的输入体验:Desktop、Web 和 TUI 使用明确的 yes/no + message 预测协议,并在空输入时持续展示已生成的预测,同时去掉预测中、失败和无效默认提示。

Bug Reproduction Steps

N/A(交互能力改进的发版移植,不是单一缺陷修复)。

Root Cause

N/A。

Code Changes

移植方式:以 release/2026-11-25 tip(f8375e18)为基线 cherry-pick 6536e55,无冲突。release/2026-11-25 已通过 #5369 带入 #5141、#5337(loop.drained/loop.idle → turn.ended 的 loopEnd 信息)与 #5231,因此 #5180 依赖的 event.loopEnd / resumeLoopEnd 已在 release 分支就位。移植后的文件树与 main 上 6536e55 对比,差异仅为 release 分支已有的 #5352 / #5353 / #5354 / #5369 / #5370。

核心结构:

完成 turn(loopEnd)或按 Tab / 右方向键
  → kap-server 请求模型(严格 json_schema)
  → show=no / 无效响应:返回 null
  → show=yes:返回校验后的 message
  → 客户端缓存并在空输入时持续显示
  → Tab / 右方向键重复采纳,不新增请求
  • 结构化预测协议:模型响应只允许 show: "yes" | "no" 和 message: string,两字段必填且不允许额外字段。无效 JSON、无效字段、空 message 和控制字符不展示;no 返回空结果,yes 返回校验后的 message。
  • kap-server 与客户端链路:恢复 next-prompt 预测和取消 action,保持 HTTP 响应为统一的 data.prediction: string | null,不改变外部契约。共用 session/service 解析,避免新增重复代码;后台 session 不覆盖当前预测目标。
  • Desktop / Web:新增 Settings > Lab 的提示词预测开关;GUI 默认 placeholder 仅显示“输入消息…”,不再显示 Tab 提示;不显示预测中或失败状态。已有预测在空输入时始终展示,不再因 accepted / parked 切换提示。Composer 对缺少预测字段的旧 mock 安全读取。
  • TUI:loop 进入 idle(event.loopEnd / resumeLoopEnd)时触发预测;不显示预测中或失败状态;已有预测在空输入时始终展示,placeholder 保留硬件光标和 fake cursor。
  • 生命周期:真实输入不取消在途请求;Tab 可等待同一请求并按 acceptance revision 重复采纳。Esc、发送、新 turn、切 session、dialog、queue、plan 等原失效入口保持有效。没有新增第三方依赖。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
模型输出 纯文本建议或空输出 严格 json_schema 的 show + message;no 和无效响应不展示 实验预测模型及各协议调用方 实验开关默认关闭;不支持或失败时返回 null
预测提示文本 “Stay silent …” / “Reply with ONLY one suggestion as plain text …” 不明确下一步时使用 show=no,其余按 schema 返回 JSON 实验预测提示词消费者 原有预测意图、长度、语言和安全约束保留
Desktop 设置 Lab 中无提示词预测开关 Settings > Lab 新增 prompt prediction 开关(en/zh) Desktop 实验功能用户 开关默认关闭
GUI 默认 placeholder “输入消息… 按 Tab 预测提示词” 仅“输入消息…” Desktop / Web 实验功能用户 用户已确认;Tab / 右方向键功能仍可使用
预测中与失败 显示“正在预测中”或错误状态 不显示预测中或失败提示 Desktop / Web / TUI 用户 请求中沿用默认提示,失败和空结果恢复普通 placeholder
已生成预测的空输入展示 accepted / parked 后切换为 Tab 提示 始终显示预测文本,可重复采纳且不新增请求 需要连续编辑和复用预测的用户 Esc、发送、新 turn 等原取消入口不变
首条消息与空结果 可能出现无效预测提示 不显示预测提示,也不接管 Tab 首个会话、空响应和预测失败用户 下一个有效 turn 可重新预测
在途请求期间输入 输入取消请求,晚到结果被丢弃 请求继续完成并缓存,清空后展示 希望边输入边保留预测的用户 发送、新 turn、切 session 等原取消入口不变
TUI placeholder 与光标 placeholder 可能破坏光标标记 内联展示并保留硬件光标和 fake cursor TUI 用户 非焦点状态仍按原规则隐藏光标
KAP predict-prompt action 曾被移除,客户端无法调用 恢复 action,响应保持 `data.prediction: string null` Desktop / Web / TUI 及 KAP 调用方

Verification

  • 本地完整 pnpm lint(独立 git worktree,0 警告 0 错误)与 check:duplication(基线 f8375e18):通过,无新增重复片段。
  • 本机(macOS)受影响的 TUI / kap-server / app-client / app-components / app-composer / app-core / desktop 12 个测试文件:614/614 通过。
  • m0-dev:agent-core-v2、kap-server、kimi-code(CLI)、kimi-code-app(Desktop / app-*)TypeScript 类型检查及 packages/agent-core-v2/test/features/promptPrediction/promptPrediction.test.ts:通过。
  • 真实 Electron next-prompt placeholder recall e2e 与上方截图在 feat(prediction): refine next-prompt interactions #5180(相同代码 diff)中已验证通过;本分支未重跑 Electron e2e。coding-win SSH 连接被重置,本分支未跑 Windows 专项。

Checklist

@changeset-bot

changeset-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 13a4068

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

This PR includes changesets to release 2 packages
Name Type
kimi-code-app Minor
@moonshot-ai/kimi-code Minor

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 Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T04:38:19.055273Z 13a4068 PR opened
ℹ️ 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 Nov 25, 2026

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

commit: 13a4068

@sailist
sailist merged commit 9fed8eb into release/2026-11-25 Nov 25, 2026
24 checks passed
@sailist
sailist deleted the feat-451-11-25-next-prompt-release-11-25 branch November 25, 2026 04:37

@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: 13a4068d2a

ℹ️ 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 +63 to +65
if (!host.isActiveSession(sessionId)) return;
latestTurn.value = undefined;
clearForSession(sessionId);

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 Invalidate predictions when inactive sessions advance

When a user leaves session A with a cached suggestion and another connected client starts a new turn in A, this early return ignores both that turn start and its eventual end because A is not currently active. Returning to A then exposes the suggestion generated before the newer turn, so it can be accepted despite no longer matching the conversation. Clear state belonging to sessionId before ignoring background-session events, while still avoiding a new prediction request for an inactive session.

AGENTS.md reference: AGENTS.md:L112-L118

Useful? React with 👍 / 👎.

Comment on lines +1938 to +1939
predictionSourceId: turn.turn_id,
predictionTurnId: turn.ordinal,

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 Pass the engine turn number to prediction

After a compaction or fork boundary adds a system turn, the conversation ordinal diverges from the engine turn ID stored in turn_number. SessionPromptPredictionService.sourceTurnMatches compares expected_turn_id with the engine's lastEnded.turnId, so passing ordinal makes every later Desktop/Web prediction return null silently. Pass turn.turn_number when available rather than the display ordinal.

AGENTS.md reference: AGENTS.md:L112-L117

Useful? React with 👍 / 👎.

Comment on lines +64 to +65
predictNextPrompt: 'session',
cancelPromptPrediction: 'session',

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 Route prediction enablement to the session host

For a session on a configured remote host, these calls are routed to the remote daemon, but getMeta, getConfig, and setConfig remain local. Consequently, enabling Settings > Lab > Prompt prediction updates the local flag and makes the UI issue requests, while the remote session's independent IFlagService still rejects them and returns null; the switch appears enabled but the feature never works. Use the session host's effective flag or make the configuration update host-scoped.

Useful? React with 👍 / 👎.

Comment on lines +1138 to +1141
const prediction = await service.predict({
predictionId: body.prediction_id,
expectedTurnId: body.expected_turn_id,
});

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 Coalesce concurrent prediction requests per turn

When two clients observe the same completed turn, both call this new endpoint with different prediction IDs, but the singleton SessionPromptPredictionService.predict returns null to whichever request arrives while the first is active and records the turn as attempted, preventing a later retry. Thus only one of Desktop, Web, or TUI receives the shared-context suggestion for that turn. Coalesce requests by expected_turn_id or cache and fan out the completed result.

AGENTS.md reference: AGENTS.md:L112-L117

Useful? React with 👍 / 👎.

Comment on lines +91 to +92
suggestion.value = { ...current, text: prediction, accepted: false, acceptedRevision: 0, parked: current.parked || !host.hasEmptyInput(current.sessionId) };
track('prediction_shown', {

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 Emit shown telemetry only when the prediction is visible

If the user starts typing while the request is in flight, this stores the result with parked: true, so the placeholder remains hidden, but immediately emits prediction_shown anyway; the TUI mirrors this at apps/kimi-code/src/tui/controllers/prompt-prediction.ts:87-100. If the user submits or starts another turn without clearing the draft, the prediction is never displayed, yet it is counted as an impression, inflating exposure and understating the acceptance rate. Emit this event only on the first transition where the cached prediction is actually eligible to render.

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.

1 participant