Repository navigation
feat(docs): add llms.txt and raw Markdown endpoints - #10679
Open
mantoujun12 wants to merge 2 commits into
Open
mantoujun12 wants to merge 2 commits into
mantoujun12 wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 6 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path=".github/workflows/docs_ci.yml" line_range="20" />
<code_context>
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v7
+
+ - name: Setup pnpm
</code_context>
<issue_to_address>
**Pull requests can steal CI token**
When an untrusted pull request changes the documentation scripts or other code executed by the workflow, `actions/checkout` persists the `GITHUB_TOKEN` in the local Git configuration, and the workflow later runs PR-controlled generator, test, and build code. A malicious PR can read and exfiltrate that token, then use the repository permissions it carries.
Grant the workflow only `contents: read` and set `persist-credentials: false` on checkout.
</issue_to_address>
### Comment 2
<location path="docs/scripts/generate-llms.mjs" line_range="833" />
<code_context>
+
+ const rawRoot = join(publicDir, "raw");
+ await mkdir(publicDir, { recursive: true });
+ await rm(rawRoot, { recursive: true, force: true });
+ await Promise.all(
+ ["llms.txt", "llms-full.txt", "llms-zh.txt", "llms-en.txt"].map(
</code_context>
<issue_to_address>
**Generated docs become inconsistent**
When generator runs overlap, or a run stops after removing existing outputs, `generateLlms` removes `public/raw` and the index files before writing replacements, so concurrent runs can delete each other’s files and a failed run leaves partial outputs. Callers see failed builds or inconsistent generated docs.
Write outputs to a staging location and publish them atomically, or serialize generator runs.
</issue_to_address>
### Comment 3
<location path="docs/scripts/generate-llms.mjs" line_range="510" />
<code_context>
+function resolveInternalLink(target, document) {
+ if (
+ !target ||
+ target.startsWith("#") ||
+ target.startsWith("//") ||
+ /^[A-Za-z][A-Za-z0-9+.-]*:/.test(target)
</code_context>
<issue_to_address>
**Fragment links reach wrong sections**
When a full-text output contains a fragment-only link and duplicate heading IDs, `resolveInternalLink` leaves fragment-only links unchanged, so concatenated full-text pages resolve them against the aggregate document; readers land on another page’s section or the wrong section.
Rewrite fragment-only links to target the page they came from, rather than leaving them relative to the aggregate document.
</issue_to_address>
### Comment 4
<location path="docs/scripts/generate-llms.mjs" line_range="526" />
<code_context>
+
+ let sitePath;
+ if (pathname.startsWith("/")) {
+ sitePath = cleanSitePath(pathname);
+ } else {
+ const languagePrefix = document.language === "en" ? "/en" : "";
</code_context>
<issue_to_address>
**English links target Chinese pages**
When an English Markdown page links to an English documentation page using a site-root path without an `/en/` prefix, `resolveInternalLink` leaves the English locale prefix off the generated URL, so readers following these links from the English full-text output land on the Chinese pages.
Resolve site-root documentation links with the source page’s locale while leaving root-level asset URLs unchanged.
</issue_to_address>
### Comment 5
<location path="docs/scripts/generate-llms.mjs" line_range="117-121" />
<code_context>
+ * @param {string} pathname Absolute site path.
+ * @returns {string} URL-safe site path.
+ */
+function encodeSitePath(pathname) {
+ return encodeURI(pathname)
+ .replaceAll("(", "%28")
+ .replaceAll(")", "%29");
+}
+
+/**
</code_context>
<issue_to_address>
**Encoded links break on fetch**
When a Markdown document links to a page using a percent-encoded path, such as `guide%20page.md`, `resolveInternalLink` passes percent-encoded paths such as `guide%20page.md` to `publicUrl`, and `encodeSitePath` encodes the `%` again, producing `%2520`. The generated full-text link then points to a nonexistent URL.
Normalize or decode URL escapes in the path before encoding it for the generated URL, while preserving literal percent characters safely.
</issue_to_address>
### Comment 6
<location path="docs/scripts/generate-llms.mjs" line_range="118-121" />
<code_context>
+ * @returns {string} URL-safe site path.
+ */
+function encodeSitePath(pathname) {
+ return encodeURI(pathname)
+ .replaceAll("(", "%28")
+ .replaceAll(")", "%29");
+}
+
+/**
</code_context>
<issue_to_address>
**Reserved filename characters break links**
When a Markdown filename contains `#` or `?`, `encodeSitePath` uses `encodeURI`, which leaves `#` and `?` unescaped in path segments. A generated raw or canonical link for a Markdown filename containing either character is parsed as a fragment or query instead of addressing that file, so callers cannot fetch it through the advertised URL.
Encode each path segment so reserved filename characters are percent-encoded while `/` remains a separator.
</issue_to_address>Sourcery assessment
Approval pending. 6 findings to address first.
Blocking findings: .github/workflows/docs_ci.yml:20, docs/scripts/generate-llms.mjs:833, docs/scripts/generate-llms.mjs:510, docs/scripts/generate-llms.mjs:526, docs/scripts/generate-llms.mjs:121, and 1 more
Collaborator
Author
|
已按本轮代码评审意见完成修复,提交:dc786e781。 修复内容
验证结果
|
This branch has not been deployed
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.
Close #10676
本 PR 为 AstrBot 文档站增加面向 AI Agent 的内容发现与读取能力,解决 AI 工具只能抓取 HTML、需要自行遍历页面以及重复解析导航栏等问题。
主要效果:
/llms.txt文档索引。/llms-full.txt以及按语言拆分的完整文档。/raw/zh/...md、/raw/en/...md单篇 Markdown 原文。rel="alternate" type="text/markdown",方便 AI 工具发现原文。Modifications / 改动点
新增公开入口
/llms.txt/llms-full.txt/llms-zh.txt/llms-en.txt/raw/zh/<path>.md/raw/en/<path>.md生成结果示例:
llms.txtllms-full.txtllms-zh.txtllms-en.txt两个
layout: false/ noindex 重定向占位页可以从 raw URL 直接访问,但不会进入 Agent 索引和完整文档,避免推荐过时入口。核心改动
zh/index.md→/,zh/dev/x.md→/dev/x,en/dev/x.md→/en/dev/xdocs/zh/**/*.md和docs/en/**/*.md,按 Unicode 码点稳定排序draft: true页面不生成任何公开产物layout: false页面不进入索引和完整文档<script setup>和 VitePress 容器围栏,保留提示文本及代码内容public/raw和四个生成文本,不触碰其他静态资源srcExclude禁止 VitePress 将 raw Markdown 当作 Vue 页面编译transformPageData读取原始filePath,正确兼容中文 rewrite 路由public/raw加入.gitignore,不提交生成结果涉及文件
docs/scripts/generate-llms.mjsdocs/tests/generate-llms.test.mjsdocs/.vitepress/config.mjsdocs/package.jsondocs:generate、docs:test,并在 dev/build 前生成文件docs/README.md.github/workflows/docs_ci.yml.gitignore可供维护者裁剪的范围
以下功能可以独立调整,不需要整体回退本 PR。请在 Review 中直接标注需要保留或删除的编号。
/llms.txt、/llms-full.txt、raw Markdown/llms-zh.txt、/llms-en.txt/llms-full.txttransformPageData,raw 入口仍可用llms.txt按一级目录分组并提取首段docs/README.md增加入口说明Screenshots or Test Results / 运行截图或测试结果
本次没有人类阅读界面的视觉改动,因此不提供页面截图。
测试命令
pnpm run docs:testpnpm run docs:buildgit diff --check产物检查
llms.txt中的 raw 链接llms.txt中的站内链接测试覆盖
/en路由和嵌套index.md路由。layout: false过滤。部署后待验证
本次未执行线上发布。文档站部署后建议补做以下冒烟检查:
/llms.txttext/plain/llms-full.txttext/plain/raw/zh/dev/star/plugin-new.mdtext/markdown/raw/en/dev/star/plugin-new.mdtext/markdown/dev/star/plugin-new.htmlChecklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
📚 I checked the affected WebUI instructions and screenshots in
docs/zhanddocs/enagainst the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog./ 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新
docs/zh和docs/en的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Provide deterministic AI-agent documentation indexes and raw Markdown access alongside automated validation for the documentation site.
New Features:
/llms.txt, language-specific and combined full-text indexes, and raw Markdown endpoints.Enhancements:
CI:
Documentation:
Tests:
Chores: