cursor-feedback 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [2.1.2](https://github.com/jianger666/cursor-feedback-extension/compare/v2.1.1...v2.1.2) (2026-07-03)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **mcp:** 多窗口/多对话共用进程的反馈路由修复——按窗口查询 + 重复投递去重 + 暂停保护 ([3b3d451](https://github.com/jianger666/cursor-feedback-extension/commit/3b3d451453ee5a04ce29929845d22191116e0f96))
11
+
5
12
  ### [2.1.1](https://github.com/jianger666/cursor-feedback-extension/compare/v2.1.0...v2.1.1) (2026-07-02)
6
13
 
7
14
 
package/dist/extension.js CHANGED
@@ -161,7 +161,12 @@ class FeedbackViewProvider {
161
161
  this._pendingInsert = null;
162
162
  this._activePort = null;
163
163
  this._portScanRange = 20; // 扫描端口范围
164
- this._seenRequestIds = new Set(); // 已处理过的请求 ID
164
+ this._seenRequestIds = new Set(); // 见过的请求 ID(只用于「新鲜提醒」去重,不再挡显示)
165
+ // 本窗口已提交 / 已被外部渠道结束的请求 ID:绝不复显。
166
+ // 与 _seenRequestIds 分开的原因:同窗口多对话并存时(如一个等待被暂停、另一对话又发起新等待),
167
+ // 被覆盖的旧请求在新请求结束后会重新从 server 返回,此时它虽「见过」但没提交过,必须能回到面板;
168
+ // 旧实现用 seen 一刀切挡显示,旧请求就永远回不来了。
169
+ this._resolvedRequestIds = new Set();
165
170
  // 超时续期开关(由侧边栏按钮切换,随轮询同步给 MCP server)
166
171
  this._autoRetry = true;
167
172
  // 飞书配置(持久化在 globalState;secret 会回显给 webview,前端用小眼睛切换明文/掩码)
@@ -336,15 +341,19 @@ class FeedbackViewProvider {
336
341
  // 如果有活跃端口,先尝试只轮询该端口
337
342
  if (this._activePort) {
338
343
  const result = await this._checkPortForRequest(this._activePort);
339
- // 检查是否仍然是我们的 Server(owner 可能是本工作区的子目录:AI 传的 project_directory)
344
+ // 检查是否仍然是我们的 Server。注意:多窗口/多对话共用一个 MCP 进程时,
345
+ // server 的 ownerWorkspace(进程归属,单值)可能是别的窗口——但只要它按窗口
346
+ // 返回了本工作区的请求(request 已在 _checkPortForRequest 里按 projectDir 过滤),
347
+ // 这个端口对本窗口就是有效的,不能因 owner 不匹配而丢弃请求。
340
348
  if (result.connected) {
341
349
  const serverOwner = result.ownerWorkspace ? normalizePath(result.ownerWorkspace) : '';
342
- const isMyServer = !serverOwner || pathsRelated(serverOwner, normalizedCurrentWorkspace);
350
+ const isMyServer = !!result.request || !serverOwner || pathsRelated(serverOwner, normalizedCurrentWorkspace);
343
351
  if (isMyServer) {
344
352
  // 端口仍然有效,保持使用
345
353
  this._debugInfo.connectedPorts = [this._activePort];
346
354
  this._debugInfo.activePort = this._activePort;
347
- if (result.request && !this._seenRequestIds.has(result.request.id)) {
355
+ // 只挡「已提交/已结束」的请求;_handleNewRequest 内部按当前显示态去重,重复调用无害
356
+ if (result.request && !this._resolvedRequestIds.has(result.request.id)) {
348
357
  this._debugInfo.lastStatus = this._t('statusListening', { port: this._activePort });
349
358
  this._handleNewRequest(result.request, this._activePort);
350
359
  this._updateDebugInfo();
@@ -375,14 +384,13 @@ class FeedbackViewProvider {
375
384
  const results = await Promise.all(ports.map(port => this._checkPortForRequest(port)));
376
385
  // 更新已连接的端口列表
377
386
  this._debugInfo.connectedPorts = results.filter(r => r.connected).map(r => r.port);
378
- // 找出属于当前工作区的请求
379
- const myRequests = results.filter(r => {
380
- if (!r.request || this._seenRequestIds.has(r.request.id)) {
381
- return false;
382
- }
383
- const serverOwner = r.ownerWorkspace ? normalizePath(r.ownerWorkspace) : '';
384
- return !serverOwner || pathsRelated(serverOwner, normalizedCurrentWorkspace);
385
- }).sort((a, b) => b.request.timestamp - a.request.timestamp);
387
+ // 找出属于当前工作区的请求(只排除已提交/已结束的;「见过但没提交」的仍要能回到面板)。
388
+ // 不再用 server 进程级 ownerWorkspace 二次过滤:request 已在 _checkPortForRequest
389
+ // 按本窗口工作区过滤过(isPathInWorkspace);多窗口共用一个 MCP 进程时 owner 只反映
390
+ // 首个对话的窗口,按它过滤会把其他窗口的请求全部滤掉(面板不显示、只有飞书收到)。
391
+ const myRequests = results
392
+ .filter(r => !!r.request && !this._resolvedRequestIds.has(r.request.id))
393
+ .sort((a, b) => b.request.timestamp - a.request.timestamp);
386
394
  // 处理最新的请求
387
395
  if (myRequests.length > 0) {
388
396
  const newest = myRequests[0];
@@ -471,41 +479,50 @@ class FeedbackViewProvider {
471
479
  }
472
480
  }
473
481
  /**
474
- * 处理新的反馈请求
482
+ * 处理新的反馈请求。
483
+ * 幂等:同一请求正在显示时重复调用直接跳过;已提交/已结束的绝不复显;
484
+ * 「见过但没提交」的请求(同窗口多对话时被新请求覆盖过)允许重新显示,只是不再重复提醒。
475
485
  */
476
486
  _handleNewRequest(request, port) {
477
- // 如果已经处理过这个请求,跳过
478
- if (this._seenRequestIds.has(request.id)) {
487
+ // 已提交 / 已被外部渠道结束 → 绝不复显(防旧版 server 的 currentRequest 清理滞后导致复弹)
488
+ if (this._resolvedRequestIds.has(request.id)) {
489
+ return;
490
+ }
491
+ // 正在显示的就是它 → 无事可做
492
+ if (this._currentRequest && request.id === this._currentRequest.id) {
479
493
  return;
480
494
  }
481
495
  // 判断是否为"新鲜"请求:创建后 10 秒内被发现
482
496
  const requestAge = Date.now() - request.timestamp;
483
497
  const isFreshRequest = requestAge < 10000; // 10秒内
484
- // 标记为已见过
498
+ // seen 只用于「主动提醒」去重:同一请求只 focus / 系统通知一次,重新回到面板时安静显示
499
+ const alreadySeen = this._seenRequestIds.has(request.id);
485
500
  this._seenRequestIds.add(request.id);
486
501
  // 清理旧的请求 ID(保留最近 100 个)
487
502
  if (this._seenRequestIds.size > 100) {
488
503
  const ids = Array.from(this._seenRequestIds);
489
504
  this._seenRequestIds = new Set(ids.slice(-50));
490
505
  }
491
- if (!this._currentRequest || request.id !== this._currentRequest.id) {
492
- this._currentRequest = request;
493
- this._activePort = port;
494
- this._currentRequestPort = port;
495
- // 「插件通知」主开关(配置 key 历史原因仍叫 systemNotification):关掉后本窗口完全静默——
496
- // 不推送内容、不弹面板、不抢焦点、不发系统通知;连用户之后主动切回 / 打开面板也不显示
497
- // (见 resolveWebviewView 里 ready 与 onDidChangeVisibility 的同款判断)。
498
- // 请求仍记录在 _currentRequest,仅用于去重与外部渠道(飞书 / 超时)resolve 关联。
499
- if (!this._isPluginNotifyEnabled()) {
500
- return;
501
- }
502
- // 开启:推送内容并显示面板
503
- this._showFeedbackRequest(request);
504
- // 只对新鲜请求做主动提醒(聚焦面板 + IDE 提示 + 失焦系统通知)
505
- if (isFreshRequest) {
506
- vscode.commands.executeCommand('cursorFeedback.feedbackView.focus');
507
- this._sendSystemNotification(request);
508
- }
506
+ if (this._resolvedRequestIds.size > 100) {
507
+ const ids = Array.from(this._resolvedRequestIds);
508
+ this._resolvedRequestIds = new Set(ids.slice(-50));
509
+ }
510
+ this._currentRequest = request;
511
+ this._activePort = port;
512
+ this._currentRequestPort = port;
513
+ // 「插件通知」主开关(配置 key 历史原因仍叫 systemNotification):关掉后本窗口完全静默——
514
+ // 不推送内容、不弹面板、不抢焦点、不发系统通知;连用户之后主动切回 / 打开面板也不显示
515
+ // (见 resolveWebviewView 里 ready 与 onDidChangeVisibility 的同款判断)。
516
+ // 请求仍记录在 _currentRequest,仅用于去重与外部渠道(飞书 / 超时)resolve 关联。
517
+ if (!this._isPluginNotifyEnabled()) {
518
+ return;
519
+ }
520
+ // 推送内容并显示面板
521
+ this._showFeedbackRequest(request);
522
+ // 只对「新鲜且首次见到」的请求做主动提醒(聚焦面板 + IDE 提示 + 失焦系统通知)
523
+ if (isFreshRequest && !alreadySeen) {
524
+ vscode.commands.executeCommand('cursorFeedback.feedbackView.focus');
525
+ this._sendSystemNotification(request);
509
526
  }
510
527
  }
511
528
  /**
@@ -687,6 +704,7 @@ class FeedbackViewProvider {
687
704
  if (!this._currentRequest)
688
705
  return;
689
706
  this._seenRequestIds.add(this._currentRequest.id);
707
+ this._resolvedRequestIds.add(this._currentRequest.id);
690
708
  this._currentRequest = null;
691
709
  this._currentRequestPort = null;
692
710
  this._showWaitingState();
@@ -722,6 +740,8 @@ class FeedbackViewProvider {
722
740
  }));
723
741
  const result = JSON.parse(response);
724
742
  if (result.success) {
743
+ // 记入「已提交」:该请求此后绝不复显(server 端清理有滞后,轮询可能还会拿到它)
744
+ this._resolvedRequestIds.add(payload.requestId);
725
745
  this._currentRequest = null;
726
746
  this._currentRequestPort = null;
727
747
  this._showWaitingState();
@@ -907,6 +927,14 @@ class FeedbackViewProvider {
907
927
  payload: { requestId, paused: result.paused, remainingMs: result.remainingMs }
908
928
  });
909
929
  }
930
+ else {
931
+ // 请求已在 server 端结束(超时/被回复)→ 明确提示,不能静默:
932
+ // 用户以为暂停成功离开,实际倒计时早没了,回来发现等待消失会一头雾水
933
+ this._view?.webview.postMessage({
934
+ type: 'toast',
935
+ payload: { text: this._i18n.pauseFailedEnded }
936
+ });
937
+ }
910
938
  }
911
939
  catch {
912
940
  // server 不支持(旧版本)或未连接:静默降级,倒计时照常走
package/dist/i18n/en.json CHANGED
@@ -89,6 +89,7 @@
89
89
  "notifyTestBody": "This is a test notification · click to open Cursor",
90
90
  "toastSubmitted": "✓ Feedback sent",
91
91
  "toastQueued": "✓ Queued — AI will receive it next round",
92
+ "pauseFailedEnded": "Pause failed: this request has already ended (timed out or answered)",
92
93
  "historyBtn": "Feedback history",
93
94
  "historyEmpty": "No history yet — submitted feedback will show up here"
94
95
  }
@@ -180,6 +180,7 @@ function getDefaultMessages() {
180
180
  notifyTestBody: "This is a test notification · click to open Cursor",
181
181
  toastSubmitted: "✓ Feedback sent",
182
182
  toastQueued: "✓ Queued — AI will receive it next round",
183
+ pauseFailedEnded: "Pause failed: this request has already ended (timed out or answered)",
183
184
  historyBtn: "Feedback history",
184
185
  historyEmpty: "No history yet — submitted feedback will show up here"
185
186
  };
@@ -89,6 +89,7 @@
89
89
  "notifyTestBody": "这是一条测试通知 · 点击试试能否唤起 Cursor",
90
90
  "toastSubmitted": "✓ 反馈已发送",
91
91
  "toastQueued": "✓ 已暂存,AI 下一轮将自动收到",
92
+ "pauseFailedEnded": "暂停失败:该请求已结束(超时或已被回复)",
92
93
  "historyBtn": "反馈历史",
93
94
  "historyEmpty": "还没有历史记录,提交过的反馈会出现在这里"
94
95
  }
@@ -257,6 +257,15 @@ class McpFeedbackServer {
257
257
  const envTimeout = process.env.MCP_FEEDBACK_TIMEOUT ? parseInt(process.env.MCP_FEEDBACK_TIMEOUT, 10) : null;
258
258
  const timeout = envTimeout || args?.timeout || 300;
259
259
  const requestId = this.generateRequestId();
260
+ // 重复投递识别:同窗口 + 同 summary + 旧请求还很新 → 视为客户端/传输层对同一次调用的
261
+ // 重复投递(非新一轮),直接 join 旧等待共享结果:不发新卡、不顶旧请求(顶了会让
262
+ // 先到的那次调用收到 SUPERSEDED、AI 误以为被新会话取代而提前收尾)。
263
+ const dup = this.findDuplicatePending(projectDir, summary);
264
+ if (dup) {
265
+ debugLog(`Duplicate delivery detected for request ${dup.id}; joining its wait instead of superseding`);
266
+ const outcome = await new Promise((res) => dup.waiters.push(res));
267
+ return this.outcomeToResult(outcome, dup.id);
268
+ }
260
269
  // 作废上一轮残留的「僵尸」请求:单实例单窗口同时只应有一个活跃反馈请求。
261
270
  // 旧请求多半是对话被压缩 / 客户端取消后还卡在 await 的残留(要等 timeout 才自然结束),
262
271
  // 不清理会让 pendingCount 虚高、全局视角误判「多个窗口在等」
@@ -275,13 +284,14 @@ class McpFeedbackServer {
275
284
  `request project ${normalizedProjectDir} differs and does not rewrite owner`);
276
285
  }
277
286
  // 创建反馈请求
278
- this.currentRequest = {
287
+ const request = {
279
288
  id: requestId,
280
289
  summary,
281
290
  projectDir,
282
291
  timeout,
283
292
  timestamp: Date.now(),
284
293
  };
294
+ this.currentRequest = request;
285
295
  debugLog(`Feedback request created: ${requestId}`);
286
296
  debugLog(`Summary: ${summary}`);
287
297
  debugLog(`Project: ${projectDir}`);
@@ -293,79 +303,8 @@ class McpFeedbackServer {
293
303
  }
294
304
  try {
295
305
  // 等待用户反馈
296
- const outcome = await this.waitForFeedback(requestId, timeout * 1000, projectDir);
297
- // 被同窗口/同进程的新一轮请求取代:安静结束,绝不能重试(否则多 agent 互相取消、忙等刷屏)。
298
- if (outcome.kind === 'superseded') {
299
- debugLog(`Request ${requestId} superseded by a newer request; ending this turn quietly`);
300
- return {
301
- content: [
302
- {
303
- type: 'text',
304
- text: '[SUPERSEDED] This feedback request was replaced by a newer interactive_feedback call (the same workspace started a new round, or another agent shares this MCP process). Do NOT call interactive_feedback again for this turn — just end your turn quietly. 【本反馈请求已被同窗口/同进程的新请求取代:不要再次调用 interactive_feedback,安静结束本轮,切勿重试。】',
305
- },
306
- ],
307
- };
308
- }
309
- if (outcome.kind === 'timeout') {
310
- debugLog('Feedback wait window elapsed without user input');
311
- // 超时续期开关:MCP_AUTO_RETRY=false 时关闭(超时即结束),默认开启(超时返回续期提醒)。
312
- // 关键:这里【绝不能】说成 "cancelled"——那会让 AI 误以为用户主动取消而结束对话,
313
- // 这正是“超时后 AI 直接收尾、不再续命”的根因。改为明确区分“超时 ≠ 取消”。
314
- const autoRetry = this.effectiveAutoRetry();
315
- const timeoutMessage = autoRetry
316
- ? '[TIMEOUT_KEEP_WAITING] No feedback was submitted within the wait window. This is a TIMEOUT, NOT a cancellation — the user is most likely still away from the keyboard. You MUST immediately call the interactive_feedback tool again with the same project_directory to keep waiting. Do NOT end the conversation, do NOT summarize the task as finished. Only stop calling it when the user EXPLICITLY tells you to stop. 【这是超时续期,并非用户取消:请立即用相同 project_directory 再次调用 interactive_feedback 继续等待,不要结束对话、不要当作任务完成。】'
317
- : '[TIMEOUT_END] No feedback was submitted within the wait window and timeout auto-continue is disabled (MCP_AUTO_RETRY=false). You may end this turn now. 【超时未收到反馈,且已关闭超时续期(MCP_AUTO_RETRY=false),可以结束本轮。】';
318
- return {
319
- content: [
320
- {
321
- type: 'text',
322
- text: timeoutMessage,
323
- },
324
- ],
325
- };
326
- }
327
- const result = outcome.data;
328
- debugLog(`Received feedback: ${result.interactive_feedback?.substring(0, 100)}...`);
329
- const contentItems = [];
330
- // 构建反馈文本
331
- let feedbackText = '';
332
- // 添加文字反馈
333
- if (result.interactive_feedback) {
334
- feedbackText += `=== User Feedback ===\n${result.interactive_feedback}`;
335
- }
336
- // 添加附加文件路径
337
- if (result.attachedFiles && result.attachedFiles.length > 0) {
338
- debugLog(`Processing ${result.attachedFiles.length} attached files`);
339
- feedbackText += `\n\n=== Attached Files ===\n`;
340
- for (const filePath of result.attachedFiles) {
341
- feedbackText += `${filePath}\n`;
342
- }
343
- feedbackText += `\nPlease read the above files to understand the context.`;
344
- }
345
- if (feedbackText) {
346
- contentItems.push({
347
- type: 'text',
348
- text: feedbackText,
349
- });
350
- }
351
- // 添加图片
352
- if (result.images && result.images.length > 0) {
353
- debugLog(`Processing ${result.images.length} images`);
354
- for (const img of result.images) {
355
- contentItems.push({
356
- type: 'image',
357
- data: img.data,
358
- mimeType: this.getMimeType(img.name),
359
- });
360
- }
361
- }
362
- if (contentItems.length === 0) {
363
- contentItems.push({
364
- type: 'text',
365
- text: 'User did not provide any feedback.',
366
- });
367
- }
368
- return { content: contentItems };
306
+ const outcome = await this.waitForFeedback(request, timeout * 1000);
307
+ return this.outcomeToResult(outcome, requestId);
369
308
  }
370
309
  catch (error) {
371
310
  debugLog(`Error collecting feedback: ${error}`);
@@ -456,9 +395,14 @@ class McpFeedbackServer {
456
395
  }
457
396
  }
458
397
  else {
459
- // 多个窗口在等不猜。项目名可能重复(同一项目开多窗口),逐项列出也无法区分,
460
- // 故不逐项列,直接引导用户去点想回复的那张卡片——回复哪张就精确回到哪个窗口。
461
- this.feishu.replyText(chatId, `当前有 ${globalCount} 个窗口在等反馈,没法自动判断你要回复哪个。\n请直接在你想回复的那张卡片上点「回复」再发,回复哪张就回到哪个窗口。`);
398
+ // 多个等待并存不猜。注意措辞:多个等待可能来自同一窗口的多个对话(用户实测
399
+ // 「只开了一个窗口却提示多窗口」造成困惑),按「反馈请求」计数并列出项目名,
400
+ // 引导用户去点想回复的那张卡片——回复哪张就精确回到哪个请求。
401
+ const names = [
402
+ ...localPending.map((p) => this.projectName(p.projectDir)),
403
+ ...remote.flatMap((r) => r.list.map((x) => x.projectName)),
404
+ ];
405
+ this.feishu.replyText(chatId, `当前有 ${globalCount} 个反馈请求在等待(${names.join('、')}),可能来自不同窗口或同一窗口的多个对话,没法自动判断你要回复哪个。\n请在你想回复的那张卡片上点「回复」再发,回复哪张就送达哪个请求。`);
462
406
  }
463
407
  });
464
408
  }
@@ -612,17 +556,121 @@ class McpFeedbackServer {
612
556
  for (const [reqId, pending] of this.pendingRequests) {
613
557
  if (this.normalizePath(pending.projectDir) !== owner)
614
558
  continue;
559
+ // 用户显式暂停的等待不作废:暂停 = 用户明确表达「保住这轮、等我回来」,
560
+ // 不是僵尸残留。同窗口新旧请求并存时,/api/feedback/current 按「未暂停优先」
561
+ // 返回,active 的结束后暂停中的会重新回到面板,可恢复可提交。
562
+ if (pending.paused)
563
+ continue;
615
564
  clearTimeout(pending.timeout);
616
565
  pending.resolve(null); // → superseded:旧 await 安静结束,不触发重试
617
566
  this.feishu.clearPending(reqId);
618
567
  this.pendingRequests.delete(reqId);
619
568
  }
620
569
  }
570
+ findDuplicatePending(projectDir, summary) {
571
+ const owner = this.normalizePath(projectDir);
572
+ for (const [id, pending] of this.pendingRequests) {
573
+ if (this.normalizePath(pending.projectDir) !== owner)
574
+ continue;
575
+ if (pending.request.summary !== summary)
576
+ continue;
577
+ if (Date.now() - pending.request.timestamp > McpFeedbackServer.DUP_JOIN_MS)
578
+ continue;
579
+ return { id, waiters: pending.waiters };
580
+ }
581
+ return null;
582
+ }
583
+ /**
584
+ * 把等待结果翻译成 MCP 工具响应(主等待与重复投递 join 的等待共用同一段收尾语义)。
585
+ */
586
+ outcomeToResult(outcome, requestId) {
587
+ // 被同窗口/同进程的新一轮请求取代:安静结束,绝不能重试(否则多 agent 互相取消、忙等刷屏)。
588
+ if (outcome.kind === 'superseded') {
589
+ debugLog(`Request ${requestId} superseded by a newer request; ending this turn quietly`);
590
+ return {
591
+ content: [
592
+ {
593
+ type: 'text',
594
+ text: '[SUPERSEDED] This feedback request was replaced by a newer interactive_feedback call (the same workspace started a new round, or another agent shares this MCP process). Do NOT call interactive_feedback again for this turn — just end your turn quietly. 【本反馈请求已被同窗口/同进程的新请求取代:不要再次调用 interactive_feedback,安静结束本轮,切勿重试。】',
595
+ },
596
+ ],
597
+ };
598
+ }
599
+ if (outcome.kind === 'timeout') {
600
+ debugLog('Feedback wait window elapsed without user input');
601
+ // 超时续期开关:MCP_AUTO_RETRY=false 时关闭(超时即结束),默认开启(超时返回续期提醒)。
602
+ // 关键:这里【绝不能】说成 "cancelled"——那会让 AI 误以为用户主动取消而结束对话,
603
+ // 这正是“超时后 AI 直接收尾、不再续命”的根因。改为明确区分“超时 ≠ 取消”。
604
+ const autoRetry = this.effectiveAutoRetry();
605
+ const timeoutMessage = autoRetry
606
+ ? '[TIMEOUT_KEEP_WAITING] No feedback was submitted within the wait window. This is a TIMEOUT, NOT a cancellation — the user is most likely still away from the keyboard. You MUST immediately call the interactive_feedback tool again with the same project_directory to keep waiting. Do NOT end the conversation, do NOT summarize the task as finished. Only stop calling it when the user EXPLICITLY tells you to stop. 【这是超时续期,并非用户取消:请立即用相同 project_directory 再次调用 interactive_feedback 继续等待,不要结束对话、不要当作任务完成。】'
607
+ : '[TIMEOUT_END] No feedback was submitted within the wait window and timeout auto-continue is disabled (MCP_AUTO_RETRY=false). You may end this turn now. 【超时未收到反馈,且已关闭超时续期(MCP_AUTO_RETRY=false),可以结束本轮。】';
608
+ return {
609
+ content: [
610
+ {
611
+ type: 'text',
612
+ text: timeoutMessage,
613
+ },
614
+ ],
615
+ };
616
+ }
617
+ const result = outcome.data;
618
+ debugLog(`Received feedback: ${result.interactive_feedback?.substring(0, 100)}...`);
619
+ const contentItems = [];
620
+ // 构建反馈文本
621
+ let feedbackText = '';
622
+ // 添加文字反馈
623
+ if (result.interactive_feedback) {
624
+ feedbackText += `=== User Feedback ===\n${result.interactive_feedback}`;
625
+ }
626
+ // 添加附加文件路径
627
+ if (result.attachedFiles && result.attachedFiles.length > 0) {
628
+ debugLog(`Processing ${result.attachedFiles.length} attached files`);
629
+ feedbackText += `\n\n=== Attached Files ===\n`;
630
+ for (const filePath of result.attachedFiles) {
631
+ feedbackText += `${filePath}\n`;
632
+ }
633
+ feedbackText += `\nPlease read the above files to understand the context.`;
634
+ }
635
+ if (feedbackText) {
636
+ contentItems.push({
637
+ type: 'text',
638
+ text: feedbackText,
639
+ });
640
+ }
641
+ // 添加图片
642
+ if (result.images && result.images.length > 0) {
643
+ debugLog(`Processing ${result.images.length} images`);
644
+ for (const img of result.images) {
645
+ contentItems.push({
646
+ type: 'image',
647
+ data: img.data,
648
+ mimeType: this.getMimeType(img.name),
649
+ });
650
+ }
651
+ }
652
+ if (contentItems.length === 0) {
653
+ contentItems.push({
654
+ type: 'text',
655
+ text: 'User did not provide any feedback.',
656
+ });
657
+ }
658
+ return { content: contentItems };
659
+ }
621
660
  /**
622
- * 等待用户反馈
661
+ * 等待用户反馈:注册 pending 并挂起,结果通过 waiters 广播——
662
+ * 首个调用与后续 join 进来的重复投递调用都会收到同一份结果。
623
663
  */
624
- waitForFeedback(requestId, timeoutMs, projectDir) {
664
+ waitForFeedback(request, timeoutMs) {
625
665
  return new Promise((resolve) => {
666
+ const requestId = request.id;
667
+ const projectDir = request.projectDir;
668
+ const waiters = [resolve];
669
+ // 广播给所有 waiter(splice 清空防重复触发:timeout 与 resolve 竞态时只结算一次)
670
+ const settle = (outcome) => {
671
+ for (const w of waiters.splice(0))
672
+ w(outcome);
673
+ };
626
674
  const onTimeout = () => {
627
675
  debugLog(`Request ${requestId} timed out`);
628
676
  this.pendingRequests.delete(requestId);
@@ -633,22 +681,24 @@ class McpFeedbackServer {
633
681
  this.recentlyTimedOut.delete(id);
634
682
  }
635
683
  // 飞书侧的清理统一交给 handleInteractiveFeedback 的 finally(clearPending),这里不再重复。
636
- resolve({ kind: 'timeout' });
684
+ settle({ kind: 'timeout' });
637
685
  };
638
686
  const timeout = setTimeout(onTimeout, timeoutMs);
639
687
  this.pendingRequests.set(requestId, {
640
688
  // resolve 包一层:沿用「外部 resolve(feedback) / resolve(null)」旧约定,
641
689
  // 但 null 一律映射为 superseded(被同进程新请求取代),绝不再走「超时重试」路径。
642
690
  resolve: (value) => {
643
- resolve(value === null ? { kind: 'superseded' } : { kind: 'feedback', data: value });
691
+ settle(value === null ? { kind: 'superseded' } : { kind: 'feedback', data: value });
644
692
  },
645
- reject: () => resolve({ kind: 'superseded' }),
693
+ reject: () => settle({ kind: 'superseded' }),
646
694
  timeout,
647
695
  projectDir,
648
696
  onTimeout,
649
697
  deadline: Date.now() + timeoutMs,
650
698
  paused: false,
651
699
  remainingMs: timeoutMs,
700
+ request,
701
+ waiters,
652
702
  });
653
703
  // 抢跑兑现:空窗期的面板提交(优先,用户显式点了发送)与飞书暂存消息,
654
704
  // 本轮 pending 一注册立即作为回复提交
@@ -683,20 +733,45 @@ class McpFeedbackServer {
683
733
  remainingMs: p.paused ? p.remainingMs : Math.max(0, p.deadline - Date.now()),
684
734
  };
685
735
  }
686
- /** 当前请求的暂停态快照(随 /api/feedback/current 下发,供面板重建后恢复显示) */
687
- getPauseState() {
688
- const cur = this.currentRequest;
689
- if (!cur)
736
+ /** 指定请求的暂停态快照(随 /api/feedback/current 下发,供面板重建后恢复显示) */
737
+ getPauseStateFor(requestId) {
738
+ if (!requestId)
690
739
  return null;
691
- const p = this.pendingRequests.get(cur.id);
740
+ const p = this.pendingRequests.get(requestId);
692
741
  if (!p)
693
742
  return null;
694
743
  return {
695
- requestId: cur.id,
744
+ requestId,
696
745
  paused: p.paused,
697
746
  remainingMs: p.paused ? p.remainingMs : Math.max(0, p.deadline - Date.now()),
698
747
  };
699
748
  }
749
+ /**
750
+ * 按窗口(workspace)从 pendingRequests 挑该窗口该看到的请求。
751
+ * 修复「多窗口共用一个 MCP 进程时 currentRequest 单值槽互相覆盖、被覆盖的窗口面板
752
+ * 显示不出自己的等待(只有飞书收到)」:每个窗口轮询时按自己的路径取自己的请求。
753
+ * 多个匹配时:未暂停的优先(active 请求先服务);同暂停态取最新——active 的结束后
754
+ * 暂停中的会自然回到面板,用户可恢复。
755
+ */
756
+ pickRequestForWorkspace(normalizedWs) {
757
+ let best = null;
758
+ for (const [, p] of this.pendingRequests) {
759
+ if (!this.pathsRelated(this.normalizePath(p.projectDir), normalizedWs))
760
+ continue;
761
+ if (!best) {
762
+ best = p;
763
+ continue;
764
+ }
765
+ if (best.paused !== p.paused) {
766
+ if (best.paused)
767
+ best = p;
768
+ continue;
769
+ }
770
+ if (p.request.timestamp > best.request.timestamp)
771
+ best = p;
772
+ }
773
+ return best ? best.request : null;
774
+ }
700
775
  /**
701
776
  * 写入/合并抢跑暂存:短时间内连发多条(含图文拆条后超出合并窗口的)合并为一条,
702
777
  * 绝不让后一条覆盖前一条(旧实现会把第一条静默丢掉)。
@@ -963,6 +1038,7 @@ class McpFeedbackServer {
963
1038
  if (req.method === 'GET' && req.url?.startsWith('/api/feedback/current')) {
964
1039
  // autoRetry 不再从轮询 query 同步(曾致多窗口互相覆盖、抖动):
965
1040
  // 改由 POST /api/settings/autoRetry 广播 + 磁盘真相源,poll 只回读做 UI 回显。
1041
+ let pollWs = '';
966
1042
  try {
967
1043
  const u = new URL(req.url, 'http://127.0.0.1');
968
1044
  // 「我的窗口」心跳:仅当轮询带的 workspace 匹配本实例归属时刷新。
@@ -971,6 +1047,7 @@ class McpFeedbackServer {
971
1047
  // 匹配放宽为「路径互为前缀」:AI 传的 project_directory 可能是窗口工作区的子目录。
972
1048
  // 命中即确认 owner 身份(ownerConfirmed),此后 owner 不再被后续调用改写。
973
1049
  const ws = this.normalizePath(u.searchParams.get('workspace') || '');
1050
+ pollWs = ws;
974
1051
  if (ws && this.ownerWorkspace && this.pathsRelated(ws, this.ownerWorkspace)) {
975
1052
  this.lastOwnerPollTime = Date.now();
976
1053
  this.everOwnerPolled = true;
@@ -980,16 +1057,19 @@ class McpFeedbackServer {
980
1057
  catch {
981
1058
  // 忽略解析错误
982
1059
  }
1060
+ // 按窗口挑请求:多窗口/多对话共用本进程时各窗口各看各的等待,互不覆盖。
1061
+ // 不带 workspace(无工作区窗口 / 旧版插件)时回退全局 currentRequest 老行为。
1062
+ const chosen = pollWs ? this.pickRequestForWorkspace(pollWs) : (this.currentRequest || null);
983
1063
  res.writeHead(200, { 'Content-Type': 'application/json' });
984
- // 返回当前请求、ownerWorkspace、startTime,以及当前生效的 autoRetry(供 UI 初始同步)
1064
+ // 返回该窗口的请求、ownerWorkspace、startTime,以及当前生效的 autoRetry(供 UI 初始同步)
985
1065
  res.end(JSON.stringify({
986
- request: this.currentRequest || null,
1066
+ request: chosen,
987
1067
  ownerWorkspace: this.ownerWorkspace,
988
1068
  startTime: this.startTime,
989
1069
  autoRetry: this.autoRetryOverride !== null ? this.autoRetryOverride : (process.env.MCP_AUTO_RETRY !== 'false'),
990
1070
  feishu: this.feishu.getStatus(),
991
1071
  feishuResolvedId: (this.lastFeishuResolved && Date.now() - this.lastFeishuResolved.at < 30000) ? this.lastFeishuResolved.id : null,
992
- pause: this.getPauseState(),
1072
+ pause: this.getPauseStateFor(chosen?.id),
993
1073
  }));
994
1074
  return;
995
1075
  }
@@ -1441,6 +1521,12 @@ McpFeedbackServer.REJOIN_TTL_MS = 15000;
1441
1521
  *(只剩别的窗口在扫端口)→ 视为我的窗口已关、本实例是僵尸:不再上报 pending,避免污染全局计数。
1442
1522
  */
1443
1523
  McpFeedbackServer.OWNER_IDLE_MS = 12000;
1524
+ /**
1525
+ * 查找可 join 的「重复投递」等待:同窗口 + 同 summary + 注册时间在 DUP_JOIN_MS 内。
1526
+ * AI 每一轮的 summary 几乎不可能与上一轮一字不差,短窗口内完全相同基本可断定为
1527
+ * 客户端/传输层对同一次 tool call 的重复投递。
1528
+ */
1529
+ McpFeedbackServer.DUP_JOIN_MS = 90000;
1444
1530
  // 主函数
1445
1531
  async function main() {
1446
1532
  const port = 61927;
@@ -1263,6 +1263,11 @@
1263
1263
  ? (i18n.toastQueued || 'Queued — will be delivered to AI next round')
1264
1264
  : (i18n.toastSubmitted || 'Feedback sent'));
1265
1265
  break;
1266
+
1267
+ case 'toast':
1268
+ // extension 侧的通用轻提示(如暂停失败:请求已结束)
1269
+ if (message.payload && message.payload.text) showToast(message.payload.text);
1270
+ break;
1266
1271
  }
1267
1272
  });
1268
1273
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "cursor-feedback",
3
3
  "displayName": "Cursor Feedback",
4
4
  "description": "One Cursor conversation, unlimited AI interactions - Save your monthly request quota! Interactive feedback loop for AI chat via MCP",
5
- "version": "2.1.1",
5
+ "version": "2.1.2",
6
6
  "icon": "icon.png",
7
7
  "author": "jianger666",
8
8
  "license": "MIT",