fix(yaml): guard Bun YAML parser availability
## Bug 详情
Windows 下通过 npm shim 执行 csc 时,/agents 只显示 built-in agents,User agents 和 Project agents 未加载;debug 日志中 agents 和 skills 的 frontmatter 均报 Cannot read properties of undefined (reading 'parse')。
## 根因
csc.cmd 实际通过 Node 执行 dist/cli-node.js。Node 入口注入了 globalThis.Bun polyfill,但该 polyfill 不包含 Bun.YAML。parseYaml 只判断 Bun 对象存在,导致误调用 Bun.YAML.parse。
## 修复方案
将 Bun 分支改为能力检测,仅在 Bun.YAML.parse 存在时使用 Bun 内置 YAML 解析器,否则回退到 yaml npm 包。
## 变更要点
- 为 parseYaml 增加 Bun.YAML.parse 可用性判断
- 保持真实 Bun runtime 使用 Bun.YAML.parse
- 保持 Node 入口使用 require('yaml').parse 回退
## 自测
- bun 下验证 parseYaml 可解析基础 frontmatter
- Node 下验证 yaml 包可解析基础 frontmatter
- bun run typecheck 已运行,但失败于仓库既有无关类型错误
This commit is contained in:
parent
602efce18a
commit
a506e933a9
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
export function parseYaml(input: string): unknown {
|
||||
if (typeof Bun !== 'undefined') {
|
||||
if (typeof Bun !== 'undefined' && Bun.YAML?.parse) {
|
||||
return Bun.YAML.parse(input)
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user