Skip to content

feat: 新增面向 AI Coding 的 LLMs 文档生成#3495

Open
alvinhui wants to merge 7 commits into
jdf2e:feat_v4.xfrom
alvinhui:feat/ai-coding
Open

feat: 新增面向 AI Coding 的 LLMs 文档生成#3495
alvinhui wants to merge 7 commits into
jdf2e:feat_v4.xfrom
alvinhui:feat/ai-coding

Conversation

@alvinhui

@alvinhui alvinhui commented Jul 8, 2026

Copy link
Copy Markdown

🤔 这个变动的性质是?

  • 新特性提交
  • 站点、文档改进

🔗 相关 Issue

面向 AI Coding 的能力调研与落地方案
第一步(统一元数据层)+ 第二步(llms.txt 文档入口),落地方案 P0 阶段。

💡 需求背景和解决方案

背景

大模型训练数据有截止时间,而组件库 API 持续演进,AI Coding Agent(Copilot / Cursor / Claude
Code)基于"记忆"生成代码时会出现 API 幻觉、版本错配、约定缺失 三类问题。业界解法(如 Ant
Design)不是训练更好的模型,而是给 Agent
提供一套权威、离线、可程序化查询的事实源,把"猜"变成"查"。

本 MR 落地该方案的地基两步(P0):统一元数据层 + llms.txt 文档入口,且覆盖 NutUI
差异化的 H5 / Taro 双端

方案

① 统一元数据层(单一事实源)

新增 scripts/build-meta.mjs,以 src/config.json
为遍历入口,聚合四处分散数据为一份自描述、机器友好的中间产物 meta/components.json

  • 基本信息(name / cName / version / taro / 分类)← config.json
  • Props/Ref 表(把中文位置式列 第一~四列 语义化为 prop/desc/type/default,按表分组并标注
    kind)← scripts/properties.json
  • Demo 列表(扫描 demos/{h5,taro}/*.tsx)、四语言/端文档路径、Design
    Token(按最长前缀归属组件)
  • 内建质量校验:孤儿 API、缺列行、重复 prop、缺文档等 WARNING

覆盖 106 个组件(85 个含 API 表、105 个全局 Token),后续 llms.txt / CLI / MCP
全部读这一份,改一处全链路生效。

② llms.txt 文档入口(H5 + Taro 双端)

新增 scripts/build-llms.mjs + scripts/site/vite-plugin-llms.mjs,读 meta 产出遵循
llmstxt.org 标准的文档入口:

  • llms.txt —— 导航索引(H1 → 摘要 → 分类 → 各组件 .md 链接)
  • llms-full-cn.txt / llms-full.txt —— 全部文档拼接单文件,可整体注入上下文
  • 单组件 .md 路由 —— 构建时经 emitFile 落到 <base>/components/<id>.md,dev
    时中间件实时返回,供 Agent 按需精确拉取纯文档原文

双端参数化:通过 PLATFORMS 配置区分 H5(/h5/react/4x,用 doc.md,含中英文)与
Taro(/taro/react/4x,用 doc.taro.md,仅中文)。⚠️ Taro 站严格使用 Taro 端文档而非复用
H5——两端存在实质 API 差异(包名 @nutui/nutui-react-taro、按钮类型 6 vs 7
种等),复用会给小程序端 AI 喂错 API。

③ 工程约定:产物不落库,构建时自动生成

meta 及 llms 均为派生产物,不进 git:

  • .gitignore 忽略整个 /meta/
  • package.json 新增 prebuild:site / prebuild:taro:site 钩子,build:site /
    build:taro:site 前自动 generate:meta && generate:llms,CI 无需改动

验证(清空 meta 从零构建)

校验项 H5 站 Taro 站
构建退出码 0 0
emitted 文件数 91 90(无英文全量,符合 Taro 无英文文档)
单组件 md 数 88 88
button.md 导入语句 @nutui/nutui-react @nutui/nutui-react-taro
llms.txt 链接指向 /h5/react/4x /taro/react/4x

交叉验证两端 button.md 内容确实不同(各取对应端文档)。

涉及文件

  • scripts/build-meta.mjs(新增)—— 元数据聚合器
  • scripts/build-llms.mjs(新增)—— llms 产物生成器,双端参数化
  • scripts/site/vite-plugin-llms.mjs(新增)—— 站点构建/dev 期产出单组件 md 与 llms 文件
  • vite.config.site.mts / vite.config.site.taro.mts —— 挂载插件(分别传 platform: h5 /
    taro)
  • package.json —— generate:meta / generate:llms 脚本 + prebuild 钩子
  • .gitignore —— 忽略 /meta/ 派生产物

☑️ 请求合并前的自查清单

  • 文档已补充或无须补充(本 MR 即为文档基建,无组件文档变更)
  • 代码演示已提供或无须提供(无组件改动,无须演示)
  • TypeScript 定义已补充或无须补充(纯脚本,无组件类型变更)
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

alvinhui and others added 2 commits July 8, 2026 19:06
- Introduced a new script `build-meta.mjs` to aggregate component metadata from various sources.
- Added a new command `generate:meta` in `package.json` to run the metadata generation.
- Created `meta/components.json` to store the generated component metadata, including categories and global tokens.
@github-actions github-actions Bot added the action:review This PR needs more reviews (less than 2 approvals) label Jul 8, 2026
@alvinhui alvinhui changed the title feat: 新增面向 AI Coding 的组件元数据与 LLMs 文档生成体系Feat/ai coding feat: 新增面向 AI Coding 的组件元数据与 LLMs 文档生成体系 Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

新增元数据聚合脚本与 llms 文档产物生成脚本,并将相关产物接入 Vite 文档站构建/开发流程,同时补充对应 npm 脚本与忽略规则。

Changes

LLM 文档生成与集成

Layer / File(s) Summary
组件元数据聚合脚本 build-meta.mjs
scripts/build-meta.mjs
聚合 configpropertiesvariables.scss 及各组件 demos/docs/spec,校验并生成 meta/components.json,含 orphan、缺列、重复 prop 等告警。
llms 文本产物生成脚本 build-llms.mjs
scripts/build-llms.mjs
读取 meta/components.json,导出 loadMetagenerateLlmsTxtgenerateLlmsFull,生成 llms.txtllms-full-cn.txtllms-full.txt 并写入 meta 目录。
Vite 插件集成与站点配置
scripts/site/vite-plugin-llms.mjs, vite.config.site.mts, package.json, .gitignore
新增 llmsPlugin 在构建时 emitFile、开发时中间件实时响应 llms 相关请求;vite.config.site.mts 接入该插件;package.json 新增 generate:meta/generate:llms 脚本;.gitignore 忽略生成的 llms*.txt 产物。

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: xiaoyatong, oasis-cloud

Poem

小兔敲键盘,脚步轻又欢,
meta 汇一处,文档排成篇。
llms 乘风起,插件守门前,
该忽略的落叶,就让它去远。
🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed 标题与主要变更一致,准确概括了新增面向 AI Coding 的 LLMs 文档生成能力。
Description check ✅ Passed 描述覆盖了性质、相关 Issue、背景方案和自查清单,结构基本符合模板要求。
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
scripts/site/vite-plugin-llms.mjs (1)

58-76: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

dev 模式下每次请求都重新调用 collectFiles() 读取全部文件

collectFiles() 会读取 meta/components.json、所有组件 doc.md,并调用 generateLlmsFull 拼接两份全量文档。在 dev 模式下,每次命中 llms 路由的请求都触发完整的磁盘 I/O 和字符串拼接,组件数量较多时会有明显延迟。

建议在 dev 中间件内加一层简单的内存缓存,配合 server.watchermeta/components.jsondoc.md 变更时失效:

♻️ 基于 watcher 的缓存方案
     configureServer(server) {
       const base = SITE_BASE.replace(/\/$/, '')
+      let cache = null
+      const invalidate = () => { cache = null }
+      server.watcher.add(path.join(ROOT, 'meta/components.json'))
+      server.watcher.on('change', (f) => {
+        if (f.endsWith('meta/components.json') || f.endsWith('.md')) invalidate()
+      })
       server.middlewares.use((req, res, next) => {
         // ... existing URL parsing ...
         if (!isTarget) return next()
-        const files = collectFiles()
+        if (!cache) cache = collectFiles()
+        const files = cache
         if (!(key in files)) return next()
         res.setHeader('Content-Type', contentType(key))
         res.end(files[key])
       })
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/site/vite-plugin-llms.mjs` around lines 58 - 76, The dev middleware
in configureServer is rebuilding llms content on every request by calling
collectFiles(), which causes repeated disk I/O and expensive generation work.
Add a simple in-memory cache around the file map used by the middleware, and
invalidate that cache from server.watcher when meta/components.json or any
component doc.md changes. Keep the routing logic in configureServer unchanged,
but make the request path read from the cached result instead of recomputing it
each time.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/build-llms.mjs`:
- Around line 70-89: The full-document generator in generateLlmsFull currently
hardcodes SUMMARY, so the English output mixes an English title with a Chinese
summary. Add a language-specific summary constant or mapping and switch the
block that builds parts in generateLlmsFull based on lang (alongside the
existing title selection) so generateLlmsFull(meta, 'enUS') uses an English
summary while other locales keep the current Chinese text.
- Around line 111-113: 入口判断在 Windows 下会因为 file URL 格式不匹配而失效,导致 main() 不执行;请在
scripts/build-llms.mjs 的入口检测逻辑中,将 import.meta.url 与通过
pathToFileURL(process.argv[1]).href 生成的 URL 进行比较,确保跨平台一致。定位时关注 main() 以及当前的
import.meta.url 条件判断。

In `@scripts/build-meta.mjs`:
- Around line 141-148: The parseTokens default-value handling is stripping a
trailing right parenthesis from already complete values, which breaks
function-style CSS defaults. In parseTokens inside build-meta.mjs, remove the
extra .replace(/\)\s*$/, '') cleanup when deriving def from m[3], and keep the
captured default value intact so tokens like rgba(...), scale-px(...), and
var(...) remain valid in meta/components.json.

---

Nitpick comments:
In `@scripts/site/vite-plugin-llms.mjs`:
- Around line 58-76: The dev middleware in configureServer is rebuilding llms
content on every request by calling collectFiles(), which causes repeated disk
I/O and expensive generation work. Add a simple in-memory cache around the file
map used by the middleware, and invalidate that cache from server.watcher when
meta/components.json or any component doc.md changes. Keep the routing logic in
configureServer unchanged, but make the request path read from the cached result
instead of recomputing it each time.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8e43d8b2-95da-416d-b942-8abb97708b3e

📥 Commits

Reviewing files that changed from the base of the PR and between 79f7ea1 and 9f4a7e8.

📒 Files selected for processing (7)
  • .gitignore
  • meta/components.json
  • package.json
  • scripts/build-llms.mjs
  • scripts/build-meta.mjs
  • scripts/site/vite-plugin-llms.mjs
  • vite.config.site.mts

Comment thread scripts/build-llms.mjs Outdated
Comment thread scripts/build-llms.mjs Outdated
Comment thread scripts/build-meta.mjs Outdated
@xiaoyatong

Copy link
Copy Markdown
Collaborator

1、meta的数据只能这么大么,有没有其他方式
2、增量代码怎么生效呢是不是可以自动化工作流

@alvinhui

alvinhui commented Jul 9, 2026

Copy link
Copy Markdown
Author

1、meta的数据只能这么大么,有没有其他方式 2、增量代码怎么生效呢是不是可以自动化工作流

  1. 作为生成 LLMs 的中间产物,不落库
  2. 已通过 pre 加入到文档构建的工作流

@alvinhui alvinhui changed the title feat: 新增面向 AI Coding 的组件元数据与 LLMs 文档生成体系 feat: 新增面向 AI Coding 的 LLMs 文档生成 Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action:review This PR needs more reviews (less than 2 approvals) size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants