Skip to content

fix(eval): 根除 prompt eval 对 @vesti/ui 的非 UI 运行时依赖#81

Merged
abraxas914 merged 2 commits intomainfrom
codex/pr-content-package-eval-boundary
Mar 28, 2026
Merged

fix(eval): 根除 prompt eval 对 @vesti/ui 的非 UI 运行时依赖#81
abraxas914 merged 2 commits intomainfrom
codex/pr-content-package-eval-boundary

Conversation

@abraxas914
Copy link
Copy Markdown
Owner

背景

当前 pnpm -C frontend eval:prompts --mode=mock --strict 会在 .tmp/eval 运行路径下失败,根因不是 prompt 逻辑本身,而是 frontend 的非 UI 文本链路在运行时依赖了 @vesti/ui

具体表现为:

  • messageContentPackage.ts、prompt/export 等非 UI helper 直接从 @vesti/ui 引纯文本 helper
  • eval 编译到 .tmp/eval 后,以 Node/CJS 从 repo 根附近运行
  • .tmp/eval 无法解析到 frontend/node_modules/@vesti/ui
  • prompt-schema-drift-pr / eval-mock-strict 因此失败

这本质上是一层架构债:非 UI 业务文本链路反向依赖 UI 包。

本次修复

1. 引入非 UI shared 包 @vesti/content-package

  • 新增 packages/vesti-content-package
  • 承接纯文本 content-package helper:
    • formatArtifactDescriptor
    • getArtifactExcerptLines
    • getArtifactExcerptText
    • buildMessageSidecarSummaryLines
    • buildMessagePreviewText
    • buildMessageFallbackDisplayText
  • 采用结构类型,不把整套 frontend / UI message schema 硬耦合进 shared 包
  • 同时输出 ESM + CJS,兼容浏览器 bundling 和 .tmp/eval 的 Node 运行时

2. 切断 frontend 非 UI 链路对 @vesti/ui 的运行时依赖

  • frontend/src/lib/utils/messageContentPackage.ts 保留 AST canonical body 决策
  • sidecar / preview / fallback / export / prompt 文本拼接改走 @vesti/content-package
  • 受影响的非 UI consumer 包括:
    • prompt ingestion
    • export serializers
    • message export package
    • search / fallback display 相关 wrapper

3. 保留 @vesti/ui 的兼容导出

  • @vesti/ui 继续保留原 helper 导出名
  • 但底层实现改为转发到 @vesti/content-package
  • UI surface 无需跟着改调用方式

4. 补齐护栏与 CI

  • 新增 scripts/check-frontend-ui-boundary.mjs
  • 明确禁止 frontend/src/lib/{prompts,services,utils} 直接 import @vesti/ui
  • prompt-schema-drift-pr 改为先安装 workspace 依赖,再跑边界检查和 eval:prompts
  • documents/prompt_engineering/README.md 增补 content-package helper 归属说明

非目标

  • 不改 parser / storage / export schema
  • 不改 attachments[] / citations[] / artifacts[] 契约
  • 不改 reader / capsule / Threads 等 UI 展示行为
  • 不做 NODE_PATH、shim、向 .tmp/evalnode_modules 之类的症状修补

验证

已通过:

  • pnpm -C frontend eval:prompts --mode=mock --strict
  • frontend\\node_modules\\.bin\\tsc.cmd -p frontend\\tsconfig.json --noEmit
  • pnpm -C packages/vesti-ui build
  • pnpm -C frontend build
  • pnpm -C vesti-web build

风险与回滚

主要风险在于:content-package 文本 helper 被抽离后,frontend 与 @vesti/ui 的文本输出如果发生轻微漂移,会影响 prompt / export / snippet 的一致性。

当前通过共享实现已把这类漂移压到最低;如果需要回滚,也可以先回到原来的本地 helper 路径,但不建议再恢复 frontend 非 UI 链路直连 @vesti/ui 的结构。

@abraxas914 abraxas914 merged commit 32ed3de into main Mar 28, 2026
1 check passed
@abraxas914 abraxas914 deleted the codex/pr-content-package-eval-boundary branch March 28, 2026 10:38
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.

1 participant