Skip to content

fix(vscode): scope New Conversation to the sidebar view - #3037

Open
Win-Hao wants to merge 1 commit into
MoonshotAI:mainfrom
Win-Hao:fix/vscode-new-conversation-scope
Open

Win-Hao wants to merge 1 commit into
MoonshotAI:mainfrom
Win-Hao:fix/vscode-new-conversation-scope

Conversation

@Win-Hao

@Win-Hao Win-Hao commented Aug 18, 2026

Copy link
Copy Markdown

Related Issue

Resolves #3036

Problem

kimi.newConversation 这个命令自己前后两行是矛盾的(apps/vscode/src/extension.ts:116-119):

await vscode.commands.executeCommand("kimi.webview.focus");  // ① 只作用于侧边栏视图
provider?.broadcast(Events.NewConversation, {});             // ② 广播给所有 webview

第 ① 行无条件 reveal 并聚焦 kimi.webview(侧边栏视图专属、由 VS Code 自动生成的命令),第 ② 行却发给每一个已注册的 webview。

结果:只要有 Kimi 对话窗口开在编辑器标签页里,点一下侧边栏标题栏的 +,那些标签页的对话也会被清空,正在流式输出的回合被停掉。而每个视图持有各自独立的 session 和工作目录(BridgeHandler 按 webviewId 分别管理),不应该"一次点击重置全部"。

同一功能的另外两个入口——webview 内部 Header 的 +、以及 Cmd/Ctrl+N 快捷键(webview-ui/src/App.tsx:53-65)——都只影响自己所在的对话窗口。命令这条路径与它们不一致。

复现步骤和动图见关联 issue。

What changed

KimiWebviewProvider:新增 sidebarWebviewId 字段。resolveWebviewView 是唯一创建侧边栏视图的入口,在那里记录 id;视图销毁时清除。清除加了 === webviewId 判断——侧边栏关闭后重开时,VS Code 可能先创建新视图再销毁旧视图,无条件清空会把刚记录的新 id 一起抹掉。

新增 broadcastToSidebar()。定向投递能力本来就有:broadcastInternal 的第三个参数(KimiWebviewProvider.ts:112)就是干这个的,insertEditorMention 一直在逐 webviewId 使用它。这里只是把它接到命令上。

extension.ts:kimi.newConversation 改用 broadcastToSidebar。第 ① 行的 focus 一个字没动——它本来就是这个命令归属侧边栏的自证。

测试:KimiWebviewProvider 此前没有测试文件,因此新建 test/webview-provider.test.ts(无既有文件可归并)。4 个用例:定向事件只到侧边栏、不定向广播仍到所有视图、无侧边栏时丢弃而非群发、侧边栏销毁后不再定向。

以 origin/main 为基线时其中 3 个用例失败;把新方法临时改回不定向的群发也是同样 3 个失败——用例抓的是这个缺陷本身,不只是新方法的存在。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

The kimi.newConversation command reveals and focuses the sidebar view
before it broadcasts, so it is the sidebar's action, yet it delivered the
event to every registered webview. With a Kimi view open as an editor
tab, pressing + in the sidebar also cleared that tab's conversation and
aborted its in-flight turn.

Track the sidebar's webview id and deliver the event only there.
broadcastInternal already takes a target and insertEditorMention already
uses it, and the in-webview Cmd/Ctrl+N shortcut already scopes itself to
the focused view, so the command now matches both.
@changeset-bot

changeset-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 119b40d

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 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

This branch has not been deployed

No deployments
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.

[VSCode] 侧边栏的 New Conversation 会清空所有 Kimi 的对话,包括编辑器标签页里正在进行的对话

1 participant