fix: script returns empty when model response lacks code block markers#173
Open
ChasingLight wants to merge 4 commits into
Open
fix: script returns empty when model response lacks code block markers#173ChasingLight wants to merge 4 commits into
ChasingLight wants to merge 4 commits into
Conversation
问题根因: readData 函数要求模型返回 ```lang\n 格式的代码块标记才会开始收集内容。 当模型(尤其非 OpenAI 模型)未使用代码块包裹命令时,dataStart 永远为 false, readScript 返回空字符串,导致后续 getExplanation 用空脚本调用模型,产生无关的幻觉输出。 同时 readScript 和 readInfo 共享同一个 async generator,readScript 消费完流后 readInfo 必然返回空,虽然 explainInSecondRequest=true 使其影响有限,但属于逻辑错误。 解决思路: 1. readData 增加 fallback:流结束时若未匹配到代码块标记,将 buffer 内容 去除 exclusion 模式后作为结果返回,兼容无代码块的模型响应 2. getScriptAndInfo 移除无效的 readInfo(共享流 + explainInSecondRequest=true 使其永远不会被用到) 3. prompt.ts 移除 readInfo 相关逻辑,直接走 getExplanation 第二次请求 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…same chunk 当模型将代码块标记和命令在同一 chunk 中返回时,buffer 被清空导致命令丢失。 改为在匹配到代码块开头后,提取标记之后的内容并加入 data。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…patibility 问题根因: prompt 要求模型用三个反引号包裹命令,但不同模型(DeepSeek、Qwen-Plus)的 代码块格式不统一(有/无语言标识、有/无换行),导致解析逻辑反复出问题。 Qwen-Plus 返回 ```ipconfig...``` 无换行,正则 /```[a-zA-Z]*/ 会把 ipconfig 当作语言标识符一起吃掉,导致脚本为空或残缺。 解决思路: 1. 修改 prompt:不再要求代码块包裹,直接返回命令原文 2. 简化 readData:移除所有代码块检测/解析逻辑,只收集内容 + trim 3. 清理无用代码:删除 shellCodeExclusions、extractCommand、stripRegexPatterns 引用 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 新增 extractCommand() 函数,兼容非 OpenAI 模型返回的三种格式: 标准代码块、无换行代码块、纯文本 - 在主提示和修订流程中均应用 extractCommand 提取命令 - 包名从 @builder.io/ai-shell 更名为 @jadenoliver/ai-shell Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
问题根因:
readData 函数要求模型返回 ```lang\n 格式的代码块标记才会开始收集内容。
当模型(尤其非 OpenAI 模型)未使用代码块包裹命令时,dataStart 永远为 false, readScript 返回空字符串,导致后续 getExplanation 用空脚本调用模型,产生无关的幻觉输出。
同时 readScript 和 readInfo 共享同一个 async generator,readScript 消费完流后 readInfo 必然返回空,虽然 explainInSecondRequest=true 使其影响有限,但属于逻辑错误。
解决思路: