perf: fixRequestContents 增加快速路径并将诊断日志放到 debug 之后 (#32)#39
Open
appergb wants to merge 24 commits into
Open
Conversation
- 新增 MermaidBlock 组件,支持流式感知的异步渲染 - 流式阶段防抖 300ms,代码块闭合后立即渲染 - 渲染失败时回退到上次成功的 SVG,避免图表消失 - 通过 MutationObserver 监听 VSCode 主题切换并重新渲染 - 将 markdownComponents 重构为 MarkdownRenderer(React.memo + useMemo) 稳定流式输出期间的组件引用,避免每次 token 更新导致 MermaidBlock 卸载重建和 SVG 闪烁 - 修复自动滚动逻辑,通过 ResizeObserver 捕获异步内容高度变化, 并用 scrollHeight 守卫排除内容缩小导致的误判 - webview 新增 mermaid@11.13.0 依赖 - 新增 .mermaid-block 和 .mermaid-error-badge 样式 Signed-off-by: huangdengdui <huangdengdui@cmcm.com>
Signed-off-by: huangdengdui <huangdengdui@cmcm.com>
统一要求 AI 在响应中使用相对路径+行号格式引用文件 (如 src/routes/index.ts:42),便于 VSCode 等 IDE 插件场景将文件引用渲染为可点击的跳转链接。 涉及:cursor、claude-code、gemini3、vscode、default 风格 Signed-off-by: huangdengdui <huangdengdui@cmcm.com>
工具通过提示词告知大模型 new_string 是"精确字面文本",没有特殊符号限制。 但实现使用 JS 的 String.prototype.replaceAll(string, string), 该方法会将替换字符串中的 $'、$`、$& 等特殊模式展开: 例如 $' 展开为匹配位置之后的所有内容,导致文件内容静默损坏, 工具却仍返回"Successfully modified",大模型无法感知错误。 这与给大模型的使用描述提示词不符。 将替换参数改为函数形式 replaceAll(oldString, () => newString), 函数返回值不触发任何特殊模式解析,使实现与使用描述保持一致。 Signed-off-by: huangdengdui <huangdengdui@cmcm.com>
根本原因:
config.initialize() 通过 setImmediate 异步触发 discoverMcpToolsAsync(),
工具发现完成后结果存入全局缓存 globalDiscoveredTools。但 waitForMcpDiscovery()
仅等待发现状态变为 COMPLETED,从未将缓存中的工具同步到当前 toolRegistry
实例,导致非交互模式下 toolRegistry.getFunctionDeclarations() 始终只返回
内置工具,AI 无法感知和调用任何 MCP 工具。
修复方案:
- waitForMcpDiscovery 新增 config 参数
- 三种状态(COMPLETED/NOT_STARTED/IN_PROGRESS)均在等待后调用
toolRegistry.discoverMcpTools(),触发从全局缓存的同步
- 新增 waitForMCPDiscoveryComplete 导入
Signed-off-by: huangdengdui <huangdengdui@cmcm.com>
Signed-off-by: huangdengdui <huangdengdui@cmcm.com>
…onStarAI#32) fixRequestContents runs on every send (sendMessage/sendMessageStream) and walks the full history several times to repair function call/response pairing. It also emitted ~8 ungated console.log/warn calls on the normal path; in the CLI those flow through ConsolePatcher into React state and add render pressure. Two surgical changes (the correctness-critical pairing logic is untouched): - Fast path: detect in the existing first pass whether the history contains any functionCall or functionResponse. When it has neither, the remaining passes are a structural no-op, so return the (already freshly-copied) input directly and skip the repeated O(n×p) scans. - Gate all eight diagnostic console.log/warn statements behind config.getDebugMode() (the pattern already used elsewhere). None are console.error; they are fix-up diagnostics that should be opt-in. Adds tests for the fast-path early-out, behavior preservation (orphaned functionResponse still dropped) with logs silent when debug is off, and logs emitted when debug is on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 issue
Closes #32
问题
fixRequestContents()在每次发送(sendMessage/sendMessageStream)时对全历史做多趟扫描以修复 function call/response 配对;并在正常路径上打印约 8 处未门控的console.log/console.warn。在 CLI 下这些日志会经ConsolePatcher进入 React 状态,加重渲染压力。改动(不触碰关键的配对修复逻辑)
functionCall/functionResponse。两者皆无时,后续所有趟次都是结构性 no-op —— 直接返回输入(调用方传入的本就是getHistory(true)的全新拷贝,返回原引用安全),跳过重复的O(n×p)扫描。console.log/warn放到this.config.getDebugMode()之后(仓库其他地方已有此模式)。这些都不是console.error,而是 fix-up 诊断,应为 opt-in。测试
geminiChat.test.ts):npx vitest run packages/core/src/core/geminiChat.test.ts→ 25 passed。npm run typecheck --workspace=packages/core→ 通过。