Skip to content

fix: preserve first prompt through project creation - #5161

Merged
liruifengv merged 1 commit into
MoonshotAI:release/2026-11-20from
kimi-agent-bot:fix/first-prompt-project-create
Nov 20, 2026
Merged

liruifengv merged 1 commit into
MoonshotAI:release/2026-11-20from
kimi-agent-bot:fix/first-prompt-project-create

Conversation

@kimi-agent-bot

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Windows Desktop 首次安装且尚未选择项目时,用户在首页发送首条提示词。新建项目并选择目录后,提示词既未进入会话,也没有保留在输入框中(反馈 ID:e5871a54-b130-44dd-b033-b98519d01074)。

本 PR 将清空时机调整为「确认进入发送 / 排队 / steer 时」。项目受信任时继续创建会话并发送;项目尚未受信任或等待登录时,原提示词在弹窗期间及关闭后持续保留。改动迁移自 MoonshotAI/kimi-code-app#1346,适配合仓后的单一 apps/desktop 渲染代码。

Bug Reproduction Steps

  1. 使用干净配置启动 Desktop,保持无项目、无会话。
  2. 在首页输入提示词并点击发送。
  3. 在「Choose a workspace first」确认框中选择「New project」,选择目录并创建项目。
  4. 原提示词从输入框消失;即使点击「Trust project」,也不会恢复或创建会话。

未登录场景遵循同一问题:输入提示词后点击发送,登录弹窗出现前输入框已被清空,取消登录后无法继续编辑原提示词。

Root Cause

activeSessionId 对外以空字符串 '' 表示「无会话」,但项目创建完成后的保护条件使用 !== null。空字符串因此被误判为「已经切换到其他会话」,待发送提示词不会进入 startSessionAndSendPrompt。

恢复路径还有同一状态契约问题:?? undefined 不会归一化空字符串,导致原草稿的 undefined 与当前会话的 '' 被当成不同会话。逻辑只向原会话存储写入草稿,而不装载到当前 Composer,所以输入框仍为空。

此外,Composer 原先在发出 submit 事件前同步清空。登录、选项目等门槛弹窗期间,用户因此看不到原文。本 PR 从状态契约和清空时机两处作根本修复,不通过额外恢复弹窗前的快照掩盖问题。

Code Changes

核心思路是让 Composer 在门槛判断期间始终保留原文,由 App 在确认进入实际发送管线后清空。清空前比较当前 Composer 与已提交快照,避免清掉等待期间输入的新内容。

 completeWorkspaceCreation
-  activeSessionId !== null  // '' 被误判为其他会话
+  activeSessionId           // 仅非空 ID 才表示已切换会话

 restoreDraftAtOrigin
-  originSid / activeSessionId ?? undefined
+  originSid / activeSessionId || undefined

 Composer submit / queue / steer
-  emit 前 resetAfterDispatch()
+  emit 时保留原文
+  App 确认发送、排队或 steer 后 clearAfterDispatch(snapshot)
  • packages/app-client/src/composables/useAppDialogs.ts:项目已受信任且用户未切换会话时,继续创建会话并发送原提示词;真正发送前触发 Composer 清空。
  • apps/desktop/src/renderer/App.vue:统一归一化原会话与当前会话 ID;只在首次会话发送、已有会话发送或 steer 前清空。发送失败沿用现有草稿恢复机制。
  • apps/desktop/src/renderer/App.vue:异步门槛阶段通过请求 ownership 防止重复提交。进入客户端发送管线后释放当前请求,旧请求的 finally 不会误释新请求。
  • packages/app-components/src/composer/Composer.vue:增加可选的延迟清空模式及 clearAfterDispatch。快照中的正文、附件顺序或浏览器引用备注发生变化时,不清除较新的输入。
  • apps/desktop/src/renderer/components/chat/ChatDock.vue、ConversationPane.vue:传递延迟清空能力,并向 App 暴露确认清空方法。
  • apps/desktop/e2e/core-turn.spec.ts:覆盖正常发送后清空、首次建项各阶段保留并在实际发送后清空、未登录弹窗及 Cancel 后保留。
  • packages/app-client/test/app-dialogs.test.ts:使用生产真实的空字符串状态,覆盖受信任后继续发送及恢复逻辑。
  • packages/app-components/test/composerUndoDraft.test.ts:覆盖确认发送才清空、等待期间的新输入保留、浏览器引用编辑保留。

新仓的 Web 与 Desktop 已共用 apps/desktop/src/renderer,因此不再需要旧仓 apps/web 的平行修改。命令和 side chat 的默认清空行为不变。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
无项目时发送首条提示词 弹窗出现前清空;建项后可能丢失 选项目、创建及信任阶段持续保留;实际发送后才清空 Desktop / Web 的首次使用用户;旧行为会丢草稿,无有效依赖 无需;发送失败仍恢复草稿
未登录时发送提示词 登录弹窗出现前清空 登录弹窗及 Cancel 后保留 未登录或模型配置未完成的 Desktop / Web 用户 无需;可继续编辑或再次发送
已受信任项目自动发送 '' 被当成其他会话,待发送提示词不进入会话 空字符串统一视为无会话,继续创建会话并发送 首次建项且项目已受信任的用户 无需;修正原状态契约
正常发送、排队、steer Composer 在 App 处理前清空 App 确认进入对应发送管线时清空 已有会话的 Desktop / Web 用户 无需;发送失败恢复机制不变
异步等待期间继续输入 旧请求完成时可能清空较新的输入 当前内容与提交快照不一致时保留新输入 在登录、建项或信任等待期间继续编辑的用户 无需;保护新草稿
命令与 side chat 按原时机清空 不变 使用命令和 side chat 的用户 不适用

受影响模块为 Desktop / Web 的 Composer、会话发送、项目创建、登录门槛与草稿恢复。单元测试覆盖状态归一化、确认清空、重复提交保护及新输入保护;Desktop E2E 用例覆盖正常发送、建项和未登录路径。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue(本次来自群内反馈,暂无 GitHub 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, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update(本次为既有交互的缺陷修复,无需新增用户文档)。
迁移后的本地验证
pnpm exec vitest run --reporter=agent \
  packages/app-components/test/composerUndoDraft.test.ts \
  packages/app-client/test/app-dialogs.test.ts \
  packages/app-client/test/draft-restore.test.ts
结果:3 个测试文件、25 项测试全部通过。

同一批测试对未修复源码运行:
结果:5 项按预期失败,覆盖建项后发送及延迟清空契约。

pnpm --filter kimi-code-app run typecheck
结果:通过。

pnpm lint
结果:通过,0 warnings / 0 errors。

xvfb-run ... pnpm e2e:desktop:headless -- core-turn --no-build --no-deps --retries=0
结果:首次建项场景通过;正常发送场景在重启阶段、未登录场景在启动阶段遇到
Linux 夹具的 Browser MCP 日志监听竞态。应用日志已输出 MCP 地址,但夹具未捕获。
按本次迁移要求,未继续执行双端 E2E。

旧仓的双端定向 E2E、常规 CI 与 Windows 真机验证记录见 MoonshotAI/kimi-code-app#1346。

@changeset-bot

changeset-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4fd6197

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

This PR includes changesets to release 1 package
Name Type
kimi-code-app Patch

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-20T03:25:20.821051Z 418a3c1 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.

@liruifengv
liruifengv changed the base branch from main to release/2026-11-20 November 20, 2026 03:19
@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@4fd6197
npx https://pkg.pr.new/@moonshot-ai/kimi-code@4fd6197

commit: 4fd6197

@kimi-agent-bot
kimi-agent-bot force-pushed the fix/first-prompt-project-create branch from 418a3c1 to 4fd6197 Compare November 20, 2026 03:21
@liruifengv
liruifengv merged commit 55c7c7b into MoonshotAI:release/2026-11-20 Nov 20, 2026
17 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 20, 2026
Grapedge added a commit that referenced this pull request Nov 23, 2026
* fix(core): add Claude 5 output token ceilings (#5096)

* fix(core): add Claude 5 output token ceilings

* chore: add Claude 5 output ceiling changeset

* fix(markdown): keep table actions inside clipped containers (#5098)

* fix(markdown): keep table actions inside clipped containers

* fix(markdown): observe table action clipping ancestors

---------

Co-authored-by: kimi-agent-bot <[email protected]>

* fix(hosts): keep project lists usable with SSH hosts (#5102)

* ci: release packages (#5094)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: preserve first prompt through project creation (#5161)

Co-authored-by: kimi-agent-bot <[email protected]>

* fix(agent-core-v2): align fork slicing with restored turn ids (#5165)

* fix(agent-core-v2): align fork slicing with restored turn ids

* chore: add restored fork fix changeset

* fix(core): prevent AJV diagnostics from polluting TUI input (#5168)

* refactor(core): route AJV logs through utils logger

* chore(core): add AJV logger changeset

* chore(core): clarify AJV logger changeset

* fix: support UUID generation in insecure browser contexts (#5173)

* fix: support UUID generation in insecure browser contexts

* chore: update pnpm deps hash

* fix: resolve crypto bindings in UUID lint rule

---------

Co-authored-by: kimi-agent-bot <[email protected]>

* fix(client): keep draft thinking effort after sending (#5170)

* fix(client): keep draft thinking effort after sending

* chore: add cli changeset for draft thinking fix

* test(client): use function stub for websocket in thinking test

* fix(client): preserve thinking effort during model normalization

* fix(client): reconcile profile updates and model fallbacks

* fix(client): scope draft thinking preservation

* fix(tui): defer queued prompts until the loop drains (#5166)

* fix(tui): defer queued prompts until the loop drains

- add core and v2 drained/idle lifecycle events
- consume reminder-only queues without starting a model turn
- gate TUI queue dispatch and completion notifications on lifecycle state
- document notification-handoff queue behavior and add a CLI patch changeset

* fix(tui): close loop lifecycle races

- emit idle only after the current macro is revalidated
- keep queued input pending through compaction and delayed dispatch
- reject stale idle after new work starts

* fix(loop): correlate lifecycle events by generation

- track macro generations in the core and v2 loop state
- replace TUI macro inference with event-generation correlation
- preserve compaction guards for queued dispatch

* fix(desktop): simplify multi-select folder picker actions (#5174)

* fix(kap-server): report :wait settled only after the session is on disk (#5176)

:wait settled as soon as the turn left the in-memory activity view, but
the engine writes wire records through a batched log that flushes in a
later task. A server killed right after :wait reported idle could lose
the end of the finished turn.

Before it replies with a settled session, :wait now flushes the wire of
every agent in the session and drains pending metadata writes. A failed
write surfaces as an error instead of a settled reply. The KAP guide
states the guarantee. A new test in sessions.test.ts slows down the disk
write of the turn end and checks that the record is on disk when :wait
returns.

(cherry picked from commit fc33c6d)

Co-authored-by: kai <[email protected]>

* ci: release packages (#5163)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(client): keep config-derived draft thinking effort after sending (#5191)

Co-authored-by: liruifengv <[email protected]>

* ci: release packages (#5192)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(kap-server): resume sessions with unavailable models (#5212)

* fix(kap-server): resume sessions with unavailable models

* fix: let users replace unavailable session models

* fix: scope unavailable model recovery state

---------

Co-authored-by: kimi-agent-bot <[email protected]>

* fix(plugins): detect MCP OAuth with targeted probes (#5197)

* fix(plugins): detect MCP OAuth with targeted probes

* fix(plugins): use the MCP inspect route

* fix(plugins): preserve OAuth requirements across inspection and disconnect

* fix(chat): show pending MCP browser authorization (#5246)

* fix(chat): show pending MCP browser authorization

* fix(chat): resolve MCP authorization lint findings

* fix(chat): preserve MCP authorization failure details

* fix(mcp): preserve cancellation during OAuth reconnect

* fix(desktop): cache feedback form per host and let reply reasons wrap (#5303)

* ci: release packages (#5232)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* test: port removed-model recovery coverage to testkit

* test: dedupe anthropic output ceiling cases

---------

Co-authored-by: Haozhe <[email protected]>
Co-authored-by: kimi-agent-bot <[email protected]>
Co-authored-by: 7Sageer <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: kimi-agent-bot <[email protected]>
Co-authored-by: liruifengv <[email protected]>
Co-authored-by: qer <[email protected]>
Co-authored-by: kai <[email protected]>
Co-authored-by: Luyu Cheng <[email protected]>
Co-authored-by: grapedge <[email protected]>
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