Repository navigation
feat(prediction): refine next-prompt interactions - #5379
Conversation
🦋 Changeset detectedLatest commit: 13a4068 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 Summary: ✅ CompletedThis 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: 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".
| if (!host.isActiveSession(sessionId)) return; | ||
| latestTurn.value = undefined; | ||
| clearForSession(sessionId); |
There was a problem hiding this comment.
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 👍 / 👎.
| predictionSourceId: turn.turn_id, | ||
| predictionTurnId: turn.ordinal, |
There was a problem hiding this comment.
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 👍 / 👎.
| predictNextPrompt: 'session', | ||
| cancelPromptPrediction: 'session', |
There was a problem hiding this comment.
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 👍 / 👎.
| const prediction = await service.predict({ | ||
| predictionId: body.prediction_id, | ||
| expectedTurnId: body.expected_turn_id, | ||
| }); |
There was a problem hiding this comment.
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 👍 / 👎.
| suggestion.value = { ...current, text: prediction, accepted: false, acceptedRevision: 0, parked: current.parked || !host.hasEmptyInput(current.sessionId) }; | ||
| track('prediction_shown', { |
There was a problem hiding this comment.
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 👍 / 👎.
Screenshots / Recordings
本 PR 将 #5180 原样移植到
release/2026-11-25(相对 base 的代码 diff 与 #5180 完全一致)。以下实拍来自 #5180(脚本化 stub 模型):空输入 placeholder → 预测出现 → 输入隐藏 → 清空召回 → Tab / 右方向键采纳 →show=no回退默认。Desktop 为真实 Electron e2e 截屏,TUI 为真实终端运行。Desktop(Electron e2e)
show=no:回到默认 placeholderTUI(真实终端运行)
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-25tip(f8375e18)为基线 cherry-pick6536e55,无冲突。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。核心结构:
show: "yes" | "no"和message: string,两字段必填且不允许额外字段。无效 JSON、无效字段、空 message 和控制字符不展示;no返回空结果,yes返回校验后的 message。data.prediction: string | null,不改变外部契约。共用 session/service 解析,避免新增重复代码;后台 session 不覆盖当前预测目标。event.loopEnd/resumeLoopEnd)时触发预测;不显示预测中或失败状态;已有预测在空输入时始终展示,placeholder 保留硬件光标和 fake cursor。Behavior Changes and Affected Users
json_schema的show + message;no和无效响应不展示show=no,其余按 schema 返回 JSONVerification
pnpm lint(独立 git worktree,0 警告 0 错误)与check:duplication(基线f8375e18):通过,无新增重复片段。agent-core-v2、kap-server、kimi-code(CLI)、kimi-code-app(Desktop /app-*)TypeScript 类型检查及packages/agent-core-v2/test/features/promptPrediction/promptPrediction.test.ts:通过。next-prompt placeholder recalle2e 与上方截图在 feat(prediction): refine next-prompt interactions #5180(相同代码 diff)中已验证通过;本分支未重跑 Electron e2e。coding-win SSH 连接被重置,本分支未跑 Windows 专项。Checklist
gen-changesetsskill(沿用 feat(prediction): refine next-prompt interactions #5180 已评审的 CLI minor / Desktop patch + minor changeset).gen-docsskill, or this PR needs no doc update(docs/{en,zh}/guides/interaction.md随 feat(prediction): refine next-prompt interactions #5180 一并移植).