Skip to content

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

Merged
sailist merged 12 commits into
mainfrom
feat-397-11-19-next-prompt-manual-recall
Nov 24, 2026
Merged

sailist merged 12 commits into
mainfrom
feat-397-11-19-next-prompt-manual-recall

Conversation

@sailist

@sailist sailist commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Screenshots / Recordings

预测状态机全链路实拍(脚本化 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

实验性提示词预测需要统一的结构化输出和连续可用的输入体验。这个 PR 让 Desktop、Web 和 TUI 使用明确的 yes/no + message 预测协议,并在空输入时持续展示已生成的预测,同时去掉预测中、失败和无效默认提示。

Bug Reproduction Steps

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

Root Cause

N/A。

Code Changes

核心结构:

完成 turn 或按 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:GUI 默认 placeholder 仅显示“输入消息…”,不再显示 Tab 提示;不显示预测中或失败状态。已有预测在空输入时始终展示,不再因 accepted / parked 切换提示。Composer 对缺少预测字段的旧 mock 安全读取。
  • TUI:保留默认 Tab to predict,不显示预测中或失败状态;已有预测在空输入时始终展示。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 实验预测提示词消费者 原有预测意图、长度、语言和安全约束保留
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

  • m0-dev:12 个相关测试文件,387/387。
  • 真实 Electron next-prompt placeholder recall:1/1,覆盖结构化 yes/no、默认 placeholder、在途 Tab、重复采纳和右方向键。
  • agent-core-v2、kap-server、CLI、Desktop TypeScript:通过。
  • 完整 lint:通过。
  • CI 等价独立 worktree check:duplication:通过,无新增重复片段。
  • 当前改动 SEA 原生 smoke、codesign 通过;Canary 已构建、安装并进入 ui-ready。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue(无单独 issue,问题与交互目标已在上方完整说明).
  • 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(CLI minor / Desktop patch,采用精简文案).
  • Ran gen-docs skill, or this PR needs no doc update(实验性交互无需额外用户文档).

@changeset-bot

changeset-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7862b84

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 20, 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-24T11:12:51.854683Z 7862b84 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.

@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: 4f89d4ae5c

ℹ️ 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 +125 to +130
function handleTurnEnded(sessionId: string, sourceId: string, turnId: number, completed: boolean): void {
latestTurn.value = undefined;
dismissForSession('new_turn', sessionId);
if (!completed) return;
latestTurn.value = { sessionId, sourceId, turnId };
pending.value = latestTurn.value;

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 Keep prediction turn state scoped to the active session

When a subscribed background session starts or ends a turn, these handlers overwrite the single global latestTurn, even though createConversationPool keeps up to three parked sessions subscribed. For an experimental Desktop/Web user who switches away while another session is running, that background event can erase or replace the active session's prediction target; promptPredictionHasTurn may then show “Press Tab to predict” in the active session while accept() targets the background session and canPredict rejects it. Ignore non-active-session events here or maintain prediction targets per session.

Useful? React with 👍 / 👎.

Comment on lines +230 to +234
if (this.suggestion?.accepted === false) {
return this.suggestion.parked ? 'Type a message… Tab to predict' : this.suggestion.prediction;
}
if (this.latestTurn === undefined) return undefined;
return this.attempted.has(`${this.latestTurn.session.id}:${String(this.latestTurn.turnId)}`) ? undefined : 'Tab to predict';

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 Show the recall hint for an accepted cached prediction

After an experimental TUI user accepts a prediction and clears the editor, handleEditorChange restores the cached prediction and Tab can insert it again, but this branch only renders suggestions whose accepted flag is false. Because the turn is already in attempted, the fallback also returns undefined, leaving the newly supported repeat-recall action completely invisible. Render the recall placeholder for the accepted cached state as well.

Useful? React with 👍 / 👎.

Comment on lines +498 to +499
predictPromptResponseSchema,
cancelPromptPredictionResponseSchema,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Refresh the pinned API contract after adding responses

Adding these response schemas changes the generated OpenAPI contract for the existing /sessions/{tail} action route, but HOST_CONTRACT in packages/kap-server/test/apiSurface.snapshot.test.ts still pins the previous digest. The pins the host API level to the client-visible contract test canonicalizes response schemas and will therefore fail for every run; keep API level 1 if this additive change is compatible, but regenerate and commit the new digest.

Useful? React with 👍 / 👎.

@sailist
sailist force-pushed the feat-397-11-19-next-prompt-manual-recall branch from 2125008 to bee5664 Compare November 20, 2026 07:59
@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026 •

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

commit: 7862b84

@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: bee5664fd2

ℹ️ 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 +744 to +745
watchEffect(() => {
promptPredictionController.refresh();

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 Dismiss predictions when modes become ineligible

When an experimental Desktop/Web user enables Plan or Goal mode from the Add menu while a completed-turn suggestion is cached, canUsePromptPrediction merely hides the suggestion and this effect only calls refresh(). Disabling the mode therefore makes the stale pre-mode suggestion reappear, and an in-flight request is likewise left running rather than cancelled. Watch eligibility transitions and dismiss the prediction when one of these invalidating modes becomes active.

Useful? React with 👍 / 👎.

Comment on lines +1898 to +1899
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 Clear the prediction target when turns are removed

When a Desktop/Web user chooses Edit on an earlier message, the resulting undo emits turns.removed, but onMainTurnsRemoved never clears the target or cached suggestion established here. After the removed prompt is loaded into the composer and then cleared, the prediction derived from the now-undone turn can reappear and be accepted; dismiss predictions whose source turn is among the removed IDs.

AGENTS.md reference: AGENTS.md:L111-L116

Useful? React with 👍 / 👎.

Comment on lines +218 to +223
const promptPredictionIdle = computed(() =>
client.experimentalFlags.value['prompt_prediction'] === true &&
client.promptPredictionHasTurn?.value === true &&
props.placeholderText === undefined &&
!starting.value &&
!isSideChat.value &&

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 Hide keyboard-only prediction controls on touch layouts

On a touch-only mobile Web layout, this condition enables the prediction placeholder and can display “Press Tab to predict,” but the only acceptance paths added by this change are the Tab and ArrowRight key handlers; there is no button, click, or touch action that inserts the suggestion. Either exclude isMobile here or provide a touch affordance and mobile-specific copy.

Useful? React with 👍 / 👎.

| `GET /api/v1/sessions` / `GET /api/v1/sessions/{session_id}` | `baseline` | List sessions across workspaces (`flat` or `by_workspace`, filters incl. `query` over title / last prompt / exact id, pagination) or get one session |
| `POST /api/v1/sessions/{session_id}:wait` | `session_wait` | Wait until `activity !== "turn"`, a pending interaction appears, or `timeout_ms` (`0..60000`, default `15000`) |
| `POST /api/v1/sessions/{session_id}:cancel` | `baseline` | Cancel active turn (`agent_id?`, `include_background?`) |
| `POST /api/v1/sessions/{session_id}:predict-prompt` / `:cancel-prompt-prediction` | `experimental` | Generate or cancel a next-prompt prediction (`prediction_id`, `expected_turn_id`, optional `reason`) |

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 Add a kap-server changeset for the new public actions

These newly documented HTTP actions are externally visible KAP behavior owned by @moonshot-ai/kap-server, but the PR's two changesets only list the CLI and Desktop products. Without an owning-package changeset, the kap-server release and changelog omit the protocol addition; add a technical kap-server entry alongside the product entries.

AGENTS.md reference: AGENTS.md:L128-L135

Useful? React with 👍 / 👎.

promptId: openerPromptId(turn),
ratingTurnId: turn.turn_id,
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 daemon turn number to prediction

When a conversation contains a system or ownerless turn, such as a background-task notification or fork boundary, its ordinal advances even though the agent loop's numeric turn ID does not. The prediction service compares expectedTurnId strictly against that loop ID, so every later request sent from this line is rejected as stale; pass the agent turn's turn_number instead, and skip prediction when it is unavailable.

AGENTS.md reference: AGENTS.md:L111-L116

Useful? React with 👍 / 👎.

@sailist
sailist force-pushed the feat-397-11-19-next-prompt-manual-recall branch from 3997757 to 7b2d689 Compare November 21, 2026 06:42

@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: 7b2d6894e6

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

}
const current = suggestion.value;
if (current === null || (sessionId !== undefined && current.sessionId !== sessionId)) return dismissed;
if (current.accepted && reason === 'escape') return dismissed;

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 Allow Escape to dismiss a recalled prediction

When a Desktop/Web user accepts a prediction, clears the composer, and sees the cached prediction recalled as ghost text, this branch prevents Escape from dismissing it. The suggestion therefore keeps reappearing until a submit, new turn, or session change, unlike an unaccepted suggestion and the equivalent TUI flow; only preserve the accepted cache while it is not being displayed, or let Escape clear it once recalled.

Useful? React with 👍 / 👎.

content: {
messages: historyFromContext([...contextSnapshot, createUserMessage(PROMPT_PREDICTION_INSTRUCTION)]),
},
model: { responseFormat: PROMPT_PREDICTION_RESPONSE_FORMAT },

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 Add the agent-core-v2 changeset

This commit changes @moonshot-ai/agent-core-v2 source behavior by requiring and parsing structured prediction responses, but neither changeset names that library. The repository requires a technical changeset for every non-ignored library source change, so the agent-core-v2 release and changelog would omit this behavior; add a patch entry for that package.

AGENTS.md reference: AGENTS.md:L169-L170

Useful? React with 👍 / 👎.

content: {
messages: historyFromContext([...contextSnapshot, createUserMessage(PROMPT_PREDICTION_INSTRUCTION)]),
},
model: { responseFormat: PROMPT_PREDICTION_RESPONSE_FORMAT },

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 Fall back when the model lacks JSON-schema output

For experimental users whose session uses an OpenAI-compatible gateway or model that does not implement response_format.type=json_schema, this unconditional override turns the previously plain-text prediction call into a rejected request, which predict() catches and silently converts to no suggestion. The model/provider capability is not checked before the OpenAI adapter emits the schema field, so retain a plain-text or JSON-object fallback when structured schema output is unavailable.

Useful? React with 👍 / 👎.

Comment on lines +60 to +61
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 Gate predictions on the target host's feature support

For a Desktop user viewing a session on an SSH host, these methods are routed to the remote daemon, but prediction eligibility is derived from getMeta() on the local daemon. Consequently, enabling the flag only locally sends requests that the remote flag rejects, enabling it only remotely never attempts prediction, and an older API-level-1 remote can reject the newly added action altogether; read or probe prediction support from the session's target host before exposing the interaction.

Useful? React with 👍 / 👎.

Comment on lines +645 to +648
'predict-prompt': {
body: predictPromptRequestSchema,
handle: predictPromptAction,
},

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 Share the one-per-turn result across connected clients

When a TUI and Desktop/Web client are connected to the same session, both request a prediction after the same completion, but this new action reaches one session-scoped service whose first request marks the turn attempted and whose response is returned only to that requester. The other client therefore receives null, and if the winner switches sessions or hides the window, neither client can retry; cache the generated result per turn for later callers or otherwise coordinate ownership across clients.

AGENTS.md reference: AGENTS.md:L111-L116

Useful? React with 👍 / 👎.

@sailist
sailist force-pushed the feat-397-11-19-next-prompt-manual-recall branch from 7b2d689 to f63dfc5 Compare November 23, 2026 07:04

@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: f63dfc541d

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


const promptPredictionController = createPromptPrediction({
api: getKimiWebApi,
isActiveSession: (sessionId) => sessionId === rawState.activeSessionId,

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 cached predictions when switching sessions

When a Desktop/Web user switches away after a suggestion has been generated, this predicate only hides the controller state; nothing clears suggestion, active, or predictionTarget. Returning to the session therefore resurrects the old suggestion, despite the declared behavior that switching sessions clears it. Watch activeSessionId and clear the prediction state for the departing session.

AGENTS.md reference: AGENTS.md:L193-L193

Useful? React with 👍 / 👎.


export const cancelPromptPredictionRequestSchema = z.object({
prediction_id: z.string().min(1),
reason: z.enum([

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reuse the canonical cancellation-reason list

This protocol schema duplicates every value from PROMPT_PREDICTION_CANCEL_REASONS in packages/agent-core-v2/src/features/promptPrediction/promptPrediction.ts; adding a reason to only one list will make the service and KAP validator disagree about valid requests. Since kap-server already depends on agent-core-v2, construct this enum from the exported canonical tuple instead of maintaining a parallel list.

AGENTS.md reference: AGENTS.md:L109-L109

Useful? React with 👍 / 👎.

@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: 192f204777

ℹ️ 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 107 to +108
handlePreInput(data: string): boolean {
if (matchesKey(data, Key.escape)) {
const hadPrediction = this.active !== undefined || this.suggestion !== undefined;
const autocomplete = this.host.state.editor.hasAutocompleteActivity();
this.dismiss('escape');
return hadPrediction && !autocomplete;
}
if (
(matchesKey(data, Key.tab) || matchesKey(data, Key.right)) &&
this.suggestion?.accepted === false &&
this.host.state.editor.inputMode === 'prompt' &&
!this.host.state.editor.hasAutocompleteActivity()
) {
return this.accept(matchesKey(data, Key.right) ? 'right' : 'tab');
if (matchesKey(data, Key.tab) || matchesKey(data, Key.right)) {

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 Restore Escape dismissal for TUI predictions

When an experimental TUI user has a displayed or in-flight prediction and presses Esc, this handler now ignores the key, so a visible suggestion remains cached and a late response can still appear afterward. Fresh evidence in this revision is the TUI-specific removal of the previous Key.escape branch even though the behavior table says Escape remains an invalidation path; restore the clear/cancel behavior for Escape.

AGENTS.md reference: AGENTS.md:L191-L193

Useful? React with 👍 / 👎.

@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: d5e384e868

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


private startPrediction(): boolean {
const target = this.latestTurn;
if (target === undefined || this.host.session !== target.session || !this.canUsePrediction()) return 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 Preserve retries after transient TUI blockers

When a turn completes while a transient blocker such as the session picker, tasks browser, or external editor is active, this one automatic call returns false because canUsePrediction() is false. The same revision removes the later Tab → startPrediction() path, and no eligibility-change callback retries the stored latestTurn; after closing the blocker, the experimental TUI user therefore cannot obtain a prediction for that completed turn. Retain a retry trigger or refresh when prediction becomes eligible again.

AGENTS.md reference: AGENTS.md:L191-L193

Useful? React with 👍 / 👎.

"kimi-code-app": patch
---

Improve prompt prediction interactions.

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 Name the Desktop behavior in the changeset

This generic sentence does not tell Desktop users what changed, even though the patch visibly changes prediction placeholders, hides progress and failure states, and keeps suggestions cached while users type. Because this entry feeds the Desktop release notes, replace it with a concrete user-facing description of the changed interaction rather than the word “Improve.”

AGENTS.md reference: AGENTS.md:L169-L170

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 Record shown telemetry only after the suggestion is visible

When the user types while generation is in flight, this caches the response as parked: true but immediately emits prediction_shown; Composer.vue hides the ghost text while the editor is nonempty, so the experiment records an impression the user never saw, and clearing the draft later shows it without recording the real first impression or timing. The TUI has the same unconditional event after caching a parked result, so emit this event once when the suggestion first becomes renderable.

Useful? React with 👍 / 👎.

@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

!state.appState.planMode &&
state.queuedMessages.length === 0 &&
!state.queuedMessageDispatchPending &&
state.activeDialog === null &&
!state.editorReplacementMounted &&

P2 Badge Clear TUI predictions on invalidating transitions

When an experimental TUI user already has a generated suggestion and then enables Plan mode, queues a message, or opens an editor-replacing dialog, these eligibility checks merely hide it. This patch also removes the handlePlanModeChanged, handleQueueChange, and notifyDisplaced calls, so closing the blocker makes the stale pre-transition suggestion visible and acceptable again even though these transitions are declared to remain invalidation paths; clear the cached and active prediction on those transitions rather than only gating placeholder().

AGENTS.md reference: AGENTS.md:L191-L193

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

@sailist
sailist force-pushed the feat-397-11-19-next-prompt-manual-recall branch from 2749d7d to d7d5a40 Compare November 23, 2026 10:12
Grapedge
Grapedge previously approved these changes Nov 23, 2026
@sailist sailist closed this Nov 23, 2026
@sailist sailist reopened this Nov 23, 2026
@sailist
sailist force-pushed the feat-397-11-19-next-prompt-manual-recall branch from 6e112ec to c1fab65 Compare November 23, 2026 13:39

@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: c1fab65a40

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

async function setPromptPredictionEnabled(on: boolean): Promise<boolean> {
const saved = await updateConfig({ experimental: { prompt_prediction: on } });
if (saved) {
experimentalFlags.value = { ...experimentalFlags.value, prompt_prediction: on };

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 Preserve environment overrides in the Lab switch

When the daemon starts with KIMI_CODE_EXPERIMENTAL_PROMPT_PREDICTION=0, enabling this switch writes the config but cannot override the environment-controlled server flag; nevertheless, this assignment marks the effective client flag as true. The UI then shows the switch as enabled and sends prediction requests that the server silently answers with no prediction until metadata is refreshed or the app restarts. Re-read the effective flag after saving, or prevent the switch from contradicting an environment override.

AGENTS.md reference: AGENTS.md:L121-L124

Useful? React with 👍 / 👎.

}

function handleInput(): void {
clearPending();

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 Retain pending prediction after clearing a draft

When a Desktop/Web user has already started typing the next prompt before the current turn finishes, refresh() leaves the completed turn in pending because the composer is nonempty. Clearing that draft then invokes handleInput(), and this unconditional call deletes the pending target without retrying it, so the generic placeholder returns instead of the prediction automatically appearing as promised in docs/en/guides/interaction.md:15. Keep the pending turn while input is nonempty and refresh it once the composer becomes empty, or generate it immediately in the parked state.

Useful? React with 👍 / 👎.

Comment on lines +108 to +109
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 Coalesce completed turns before starting prediction

When Desktop/Web reconnects after multiple turns completed, onMainPage() reports each fresh completed turn synchronously, so every call here discards the preceding local request and immediately starts another one. In the normal request order the session service accepts the first request and returns null for the second while the first response is ignored because it no longer matches active; the latest turn therefore receives no suggestion and is already marked attempted locally. Coalesce the page to its latest completed turn, or defer the latest target until the active request settles.

Useful? React with 👍 / 👎.

@sailist
sailist force-pushed the feat-397-11-19-next-prompt-manual-recall branch from c1fab65 to 990e812 Compare November 24, 2026 03:47
- move predictions into input placeholders with manual and repeated recall
- preserve in-flight requests and TUI cursor rendering
- hide hints before the first turn and after empty predictions
- use structured yes/no responses for next-prompt prediction
- keep cached suggestions visible after clearing input
- simplify the default placeholder and deduplicate session prediction lookup
@sailist
sailist force-pushed the feat-397-11-19-next-prompt-manual-recall branch from 990e812 to 7862b84 Compare November 24, 2026 11:06

@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: 7862b84f06

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

setText(text: string, opts?: { entries?: AttachmentEntry[] }): void;
setWorkMode(spec: WorkModePillSpec | null): void;
setPlaceholder(text: string): void;
setPlaceholder(text: string, opts?: { allowWhitespace?: boolean }): void;

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 Add changesets for the modified UI libraries

This commit changes source behavior in both @moonshot-ai/app-composer (including this public editor contract) and @moonshot-ai/app-components, but the three added changesets only name the CLI and Desktop products. Neither library is ignored by .changeset/config.json, so their own versions and technical changelogs will omit these changes; add patch entries for both packages.

AGENTS.md reference: AGENTS.md:L170-L171

Useful? React with 👍 / 👎.

@sailist
sailist merged commit 6536e55 into main Nov 24, 2026
24 checks passed
@sailist
sailist deleted the feat-397-11-19-next-prompt-manual-recall branch November 24, 2026 12:18
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 25, 2026
Port upstream 6536e55 (MoonshotAI#5180). Predictions move into the composer
placeholder: a finished turn starts one, typing parks it, clearing the
input shows it again, and Tab/Right Arrow recalls it (also while the
request is still in flight). The engine now asks for a strict yes/no JSON
answer instead of plain text, and the desktop stack gains the prediction
API, Composer integration, telemetry and a Settings > Lab switch.

Fork adaptations:

- pi-tui here has no FAKE_CURSOR_START/END, so custom-editor keeps its
  multi-line ghost renderer and now drives it from a placeholder provider.
  Its truncation and continuation padding became column-aware
  (truncateToWidth/visibleWidth); CJK predictions no longer overflow the
  box and a two-line prediction stays inside the width budget.
- The fork had never wired PromptPredictionController: kimi-tui now
  constructs/disposes/resets it and exposes the turn-ended hook, the
  editor keyboard calls submit/pre-input/change, and the prediction
  starts on the fork's real idle transitions (after finalizeTurn and
  after finishCompaction settles) because this branch carries neither
  loopLifecycleEvents nor streamingUI.finalizeLoopEnd. Upstream's removed
  handlePlanModeChanged/notifyDisplaced/handleQueueChange call sites never
  existed here; plan mode is blocked inside canUsePrediction instead.
- kap-server cancels a predict-prompt request on disconnect through
  reply.raw close plus writableFinished, the fork's existing wait-handler
  idiom, since SessionActionExtra.req carries no raw request object.
- Upstream's new e2e case is dropped: this fork replaced the FakeModel/
  testWithProvider e2e fixtures with its own model stubs, and restoring
  that harness is out of scope for the port.
- Tests use the fork's waitForAssertion/mock helpers instead of vi.waitFor,
  and the sessions test drops upstream's ":abort is unsupported" assertion
  because the fork still routes abort.

Verified:
- bun run typecheck: agent-core-v2, kap-server, apps/kimi-code clean;
  apps/desktop clean except the pre-existing tests/main/browser/
  browser-aot.test.ts TsdownHandle error (file untouched).
- apps/kimi-code: 103 pass / 0 fail (prompt-prediction + custom-editor).
- agent-core-v2 promptPrediction: 1 pass, 52 assertions.
- kap-server sessions: 128 pass / 0 fail; the prediction case passes
  alone (12 assertions).
- app-client workspace-state: 212 pass / 13 fail, the 13 identical to
  HEAD (210 pass / 13 fail); the new setPromptPredictionEnabled cases pass.
- app-core daemon-client 89 pass, app-composer placeholder 10 pass,
  desktop perfTelemetry 5 pass, app-components composerUndoDraft 5 pass.
- check:no-comments OK (2415 files); locale key and placeholder checks OK.
- app-client conversation-events and two app-components composer suites
  fail only because this Bun build lacks vi.resetModules; their HEAD
  versions fail identically, so the committed client-level prediction
  test could not run here. A throwaway probe exercised createPromptPrediction
  through 28 assertions (parking, in-flight recall, revisions, submit,
  failed turns, session isolation) and passed before deletion.
- Cross-package typechecking resolves workspace packages through the
  node_modules junction into the main checkout, so app-components/app-client
  edits were checked by their tests rather than by tsc.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
The last reported source gap for MoonshotAI#5180 was apps/desktop/e2e/composer-writing.spec.ts, an e2e spec. Treat **/e2e/**, **/tests/**, **/*.spec.ts and **/*.spec.tsx as test, then regenerate the baseline.

The baseline now reports source-missing 0, source-partial 11, source-adapted 138. MoonshotAI#5180 is already ported as d4f7ca0; its client hook exists and is imported by useKimiWebClient, so the difference is structural, not missing behavior.

Verified: scripts suite 276 pass; check:no-comments clean.
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