diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..77a93be --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,29 @@ +# BVM Repository Instructions for Copilot + +This repository builds and maintains BVM, a cross-platform Bun version manager. + +## Core priorities + +- Preserve cross-platform behavior on macOS, Linux, and Windows. +- Keep shell startup overhead minimal; avoid heavy runtime logic in init paths. +- Maintain per-version global package isolation semantics. +- Prefer small, targeted changes over broad refactors. + +## Implementation rules + +- Command logic belongs in `src/commands/*.ts`; keep router wiring in `src/index.ts`. +- Reuse existing utilities instead of introducing duplicate helpers. +- Never hardcode platform-specific paths without explicit branching. +- For shell/profile changes, preserve BVM managed markers and append-at-end precedence behavior. + +## Validation rules + +- For CLI behavior changes, run relevant tests and smoke checks. +- If changing docs for installation/setup, verify commands still match actual CLI behavior. +- Do not claim success without command output evidence. + +## Safety rules + +- Do not use destructive git commands (`git reset --hard`, force pushes) unless explicitly asked. +- Do not remove user files outside repository scope. +- Treat network-dependent behavior as potentially flaky and provide deterministic fallbacks. diff --git a/.github/instructions/cli.instructions.md b/.github/instructions/cli.instructions.md new file mode 100644 index 0000000..259f821 --- /dev/null +++ b/.github/instructions/cli.instructions.md @@ -0,0 +1,15 @@ +--- +applyTo: "**/*.ts" +--- + +# CLI Code Instructions (BVM) + +- Keep behavior deterministic and cross-platform. +- Use existing command contracts and shared utilities. +- Prefer explicit error messages with actionable fixes. +- Preserve current semantics for: + - version resolution + - `bvm setup` shell integration + - `bvm doctor` diagnostics + - global package isolation per Bun version +- Avoid introducing new dependencies unless they are necessary. diff --git a/.github/instructions/docs.instructions.md b/.github/instructions/docs.instructions.md new file mode 100644 index 0000000..e6e4403 --- /dev/null +++ b/.github/instructions/docs.instructions.md @@ -0,0 +1,14 @@ +--- +applyTo: "**/*.md" +--- + +# Documentation Instructions (BVM) + +- Keep install commands copy-paste ready for macOS/Linux/Windows. +- Ensure English and Chinese docs remain aligned on core behavior. +- Prefer concise, explicit troubleshooting guidance over generic text. +- For AI-facing docs, prioritize: + - direct execution steps + - verification commands + - stable links to markdown mirrors and llms context files +- Do not describe features that are not implemented. diff --git a/.github/instructions/llms.instructions.md b/.github/instructions/llms.instructions.md new file mode 100644 index 0000000..f4e8eb3 --- /dev/null +++ b/.github/instructions/llms.instructions.md @@ -0,0 +1,10 @@ +--- +applyTo: "**/llms*.txt" +--- + +# LLM Context File Instructions + +- Keep content concise and structured for retrieval. +- Prefer stable absolute URLs for docs and mirrors. +- Keep `llms.txt` as index and `llms-full.txt` as aggregated context. +- Avoid marketing-only fluff; prioritize install, usage, troubleshooting, and verification paths. diff --git a/README.md b/README.md index f707933..7eef711 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@
中文网站 »
+ From NPM (Start Here) » +
+ WeChat Official Account » +

🇨🇳 中文文档 · @@ -35,10 +39,14 @@ --- +Need to switch Bun versions across Windows, macOS, and Linux without PATH drift or global package conflicts? + ## ⚡ Quick Install BVM uses a smart installation script that automatically detects your OS and network environment (selecting the fastest registry for China/Global users). +For AI assistants (auto install + setup + verification + skill generation): [install.md](./install.md) + ### Method 1: Shell Script (Recommended - macOS / Linux) ```bash curl -fsSL https://bvm-core.pages.dev/install | bash @@ -104,8 +112,55 @@ echo "1.1.0" > .bvmrc --- +## FAQ (for AI search) + +
+How to switch Bun versions on Windows/macOS/Linux quickly? + +Install with one command, then use `bvm install ` and `bvm use `. BVM supports Windows, macOS, and Linux with the same CLI workflow. +
+ +
+Is BVM like nvm/fnm but for Bun? + +Yes. BVM is a Bun version manager, similar in concept to nvm/fnm. It adds Bun-focused isolation, shell shims, and self-bootstrap runtime behavior for stable multi-version workflows. +
+ +
+Why do global packages disappear after switching Bun versions? + +This is expected. BVM uses per-version global package isolation. Install global tools under each Bun version that needs them. +
+ +
+How does `.bvmrc` work for project-level Bun version pinning? + +Create a `.bvmrc` file in your project root with a version string (for example, `1.1.0`). BVM resolves and applies that version for project workflows. +
+ +
+Does BVM auto-install AI agent skills from SKILL.md? + +No. BVM manages Bun runtimes and version switching. Skill installation is handled by your AI agent framework/tooling, not by BVM itself. +
+ +
+How to diagnose BVM environment issues quickly? + +Run `bvm doctor`. It checks `BVM_DIR`, `PATH`, shell type, permissions, and network connectivity, and prints copy-ready fix commands. +
+ +--- + ## Troubleshooting +- **Quick diagnostics (`doctor`)** + ```bash + bvm doctor + ``` + `bvm doctor` now checks `BVM_DIR`, `PATH`, shell type, directory permission, and network connectivity. + Each item is shown as `PASS / WARN / FAIL` with a copy-ready fix command. + - **Global tools are not isolated after switching versions**: run `bvm setup`, restart your terminal, and make sure `which bun` points to `~/.bvm/shims/bun` (macOS/Linux). On Windows, use `where.exe bun` and ensure `...\\.bvm\\shims\\bun.cmd` is first. - **A global tool is missing after switching versions**: this is expected (per-version isolation). Reinstall it under the active Bun version. diff --git a/README.zh-CN.md b/README.zh-CN.md index 63a777d..15ed8d2 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -12,6 +12,10 @@
English Site »
+ 从 NPM 来?从这里开始 » +
+ 关注公众号 » +

🇺🇸 English Docs · @@ -35,10 +39,14 @@ --- +想在 Windows、macOS、Linux 间稳定切换 Bun 版本,并避免 PATH 漂移和全局包冲突? + ## ⚡ 一键极速安装 BVM 提供了智能安装脚本,**自动检测您的网络环境**。中国用户会自动切换至淘宝镜像源,海外用户使用官方源,无需手动配置。 +给 AI 助手自动执行(安装 + setup + 验证 + 生成 Skill):[install.md](./install.md) + ### 方式 1: Shell 脚本 (推荐 - macOS / Linux) ```bash curl -fsSL https://bvm-core.pages.dev/install | bash @@ -104,6 +112,46 @@ echo "1.1.0" > .bvmrc --- +## 常见问题 / FAQ + +
+Windows / macOS / Linux 怎么快速切换 Bun 版本? + +安装 BVM 后,直接使用 `bvm install ` 安装版本,再用 `bvm use ` 切换即可。三大平台命令一致。 +
+ +
+BVM 是 Bun 版的 nvm/fnm 吗? + +可以这么理解。BVM 是 Bun 的版本管理器,在 nvm/fnm 思路上补充了 Bun 场景的版本隔离、shim 机制和自举运行时能力。 +
+ +
+为什么切换 Bun 版本后,全局包命令不见了? + +这是预期行为。BVM 采用“按版本隔离”的全局包目录。你需要在目标 Bun 版本下重新安装对应全局工具。 +
+ +
+`.bvmrc` 怎么做项目级版本锁定? + +在项目根目录创建 `.bvmrc`,写入版本号(例如 `1.1.0`)。BVM 会按该版本解析并用于项目工作流。 +
+ +
+支持 skills 自动安装吗(例如读取 SKILL.md 自动装)? + +不支持。BVM 只负责 Bun 运行时和版本切换;skills 的安装与管理由 AI Agent 框架或对应工具链负责。 +
+ +
+怎么快速定位 BVM 环境问题? + +运行 `bvm doctor`。它会检查 `BVM_DIR`、`PATH`、shell 类型、目录权限和网络连通性,并输出可直接复制的修复命令。 +
+ +--- + ## 设计哲学 ### ArchSense (架构自举) diff --git a/docs/launch/12h-review.md b/docs/launch/12h-review.md new file mode 100644 index 0000000..b2ecd5e --- /dev/null +++ b/docs/launch/12h-review.md @@ -0,0 +1,51 @@ +# BVM 发布后 12 小时复盘记录(点击 / 安装 / 反馈) + +> 使用方式:发布后在 `2h / 6h / 12h` 三个节点更新一次,确保有连续数据。 + +## 发布信息 + +- 发布日期:`YYYY-MM-DD` +- 首发人:`@` +- 渠道:`掘金 / V2EX` +- 首发帖链接(掘金):`` +- 首发帖链接(V2EX):`` + +--- + +## 核心指标记录 + +| 时间点 | 渠道 | 点击(帖子或链接) | 安装(可观测) | 反馈条数 | 正向反馈 | 问题反馈 | 备注 | +|---|---|---:|---:|---:|---:|---:|---| +| T+2h | 掘金 | | | | | | | +| T+2h | V2EX | | | | | | | +| T+6h | 掘金 | | | | | | | +| T+6h | V2EX | | | | | | | +| T+12h | 掘金 | | | | | | | +| T+12h | V2EX | | | | | | | + +--- + +## 评论跟进(12 小时内) + +- [ ] 已回复全部高价值评论(建议 <= 2 小时内首轮响应) +- [ ] 已整理高频问题 Top 3 +- [ ] 已记录下一步改进项(文案 / 文档 / 功能) + +### 高频问题 Top 3 + +1. `` +2. `` +3. `` + +--- + +## 复盘结论 + +- 最有效渠道:`` +- 转化最好内容段落:`` +- 用户最关心问题:`` +- 下一轮迭代动作(最多 3 条): + 1. `` + 2. `` + 3. `` + diff --git a/docs/launch/juejin-first-post.md b/docs/launch/juejin-first-post.md new file mode 100644 index 0000000..d5ed620 --- /dev/null +++ b/docs/launch/juejin-first-post.md @@ -0,0 +1,101 @@ +# 【首发】BVM:把 Bun 版本切换和环境排障压缩成 3 步 + +> 一句话定位:**BVM 专注解决 Bun 多版本切换 + 环境自检两件事,减少“同样命令在不同机器表现不一致”的排查成本。** + +如果你也遇到过这些情况,这篇会很有共鸣: + +- 项目 A 需要旧版 Bun,项目 B 需要新版,来回切时容易把全局环境搞乱。 +- 明明切了版本,但某些全局命令还“残留”或“消失”,问题边界不清晰。 +- 新同学接手项目时,环境状态难统一,沟通里经常是“我这边正常”。 + +我做 BVM 的目标不是做一个“大而全”的工具,而是聚焦两点: + +1. **可预期的版本切换** +2. **可复用的排障路径** + +--- + +## 30 秒演示:安装 → 切换 → doctor + +```bash +# 1) 安装 BVM(macOS / Linux) +curl -fsSL https://bvm-core.pages.dev/install | bash + +# 2) 安装并切换 Bun +bvm install latest +bvm use latest + +# 3) 环境自检 +bvm doctor +``` + +如果你是 Windows: + +```powershell +irm https://bvm-core.pages.dev/install | iex +``` + +--- + +## 为什么我认为这条链路有效 + +### 1) 版本切换成本低 + +常用命令都很直给: + +- `bvm install latest`:装最新稳定版 +- `bvm use `:立即切换当前版本 +- `bvm default `:设置默认版本(新终端生效) +- `bvm ls` / `bvm ls-remote`:本地与远程版本一目了然 + +### 2) 排障入口统一 + +我把“先看哪里”的经验收敛进了 `bvm doctor`,核心是先判断: + +- 当前 shell 走的是不是 BVM shim +- 版本链路是否一致 +- 有没有常见的 PATH / 全局包冲突信号 + +这比“每次现场口述排查步骤”更稳定。 + +### 3) 多项目协作更容易对齐 + +项目根目录放一个 `.bvmrc`,版本期望就能显式化,减少口头同步成本: + +```bash +echo "1.1.0" > .bvmrc +``` + +--- + +## 一个典型场景(真实高频) + +你在项目 X 中安装过全局工具,切到项目 Y 后发现工具行为异常。 +常见原因不是“工具坏了”,而是**版本上下文与全局包归属不一致**。 + +处理路径通常是: + +1. `bvm use <目标版本>` +2. `bvm doctor` 看当前链路状态 +3. 在当前版本下重新安装该全局包 + +这个流程的价值是:**先定位边界,再修复**,避免盲改环境。 + +--- + +## 开源地址 + +- GitHub: +- 文档站: + +--- + +## 我希望收集的反馈(欢迎直接贴命令输出) + +为了把 BVM 打磨成真正“省排障时间”的工具,我最需要这三类反馈: + +1. 你的系统与 shell(macOS/Linux/Windows + bash/zsh/fish/pwsh) +2. 你执行的命令序列 +3. 你看到的关键输出(尤其是 `bvm doctor`) + +我会优先处理这类可复现反馈,并持续改进安装与诊断体验。 diff --git a/docs/launch/promotion-checklist.md b/docs/launch/promotion-checklist.md new file mode 100644 index 0000000..303feff --- /dev/null +++ b/docs/launch/promotion-checklist.md @@ -0,0 +1,64 @@ +# BVM 推广执行清单(今天可发) + +> 目标:当天完成首发、双渠道分发、12 小时复盘闭环。 + +## 0) 基础信息(先填) + +- [ ] 仓库链接:`https://github.com/EricLLLLLL/bvm` +- [ ] 官网/文档:`https://bvm-core.pages.dev` +- [ ] 安装命令(macOS/Linux):`curl -fsSL https://bvm-core.pages.dev/install | bash` +- [ ] 安装命令(Windows):`irm https://bvm-core.pages.dev/install | iex` + +--- + +## 1) 一句定位(解决什么痛点) + +- [ ] 候选 A:`BVM 让 Bun 版本切换和环境排障变成 3 条命令,减少版本冲突和“能跑/不能跑”排查时间。` +- [ ] 候选 B:`BVM 专注 Bun 的版本管理与诊断,帮你稳定切版本、快速定位 PATH/全局包问题。` +- [ ] 最终使用:`________________________________________` + +--- + +## 2) 30 秒演示脚本(安装 → 切换 → doctor) + +- [ ] 录屏前清理终端历史与敏感信息 +- [ ] 演示命令(建议直接复制): + +```bash +# 1) 安装 BVM +curl -fsSL https://bvm-core.pages.dev/install | bash + +# 2) 安装并切换 Bun 版本 +bvm install latest +bvm use latest + +# 3) 一键诊断当前环境 +bvm doctor +``` + +- [ ] 结尾口播(可选):`“30 秒完成安装、切换、排障,Bun 多版本开发更稳。”` + +--- + +## 3) 首发内容(痛点 → 3 步上手 → 链接) + +- [ ] 掘金版文案:见 `docs/launch/juejin-first-post.md` +- [ ] V2EX 版文案:见 `docs/launch/v2ex-first-post.md` +- [ ] 按渠道替换标题、口吻、标签后发布 + +--- + +## 4) 同步发布 + +- [ ] 渠道 1:掘金(开发者成长 + 实操导向) +- [ ] 渠道 2:V2EX(问题导向 + 命令直给) +- [ ] 记录发布时间(北京时间):`____:____` + +--- + +## 5) 12 小时复盘(点击 / 安装 / 反馈) + +- [ ] 复盘模板:`docs/launch/12h-review.md` +- [ ] 发布后 2h / 6h / 12h 更新一次 +- [ ] 回复评论并记录高频问题(至少 3 条) + diff --git a/docs/launch/v2ex-first-post.md b/docs/launch/v2ex-first-post.md new file mode 100644 index 0000000..9a06cce --- /dev/null +++ b/docs/launch/v2ex-first-post.md @@ -0,0 +1,56 @@ +# [开源] BVM:专注 Bun 版本切换 + 环境排障(附最短体验路径) + +TL;DR:如果你在多个项目间切 Bun,或经常遇到 PATH / 全局包不一致问题,BVM 可以把流程收敛成一组固定命令。 + +## 主要解决什么 + +1. 多项目切换 Bun 版本时,环境状态容易混乱 +2. 切完版本后,部分全局命令行为不稳定 +3. 团队协作里,环境问题难快速对齐与复现 + +## 最短体验路径 + +```bash +# macOS / Linux +curl -fsSL https://bvm-core.pages.dev/install | bash + +bvm install latest +bvm use latest +bvm doctor +``` + +Windows: + +```powershell +irm https://bvm-core.pages.dev/install | iex +``` + +## 常用命令(按频率) + +```bash +bvm install # 安装指定版本 +bvm use # 当前终端立即切换 +bvm default # 设置默认版本(新终端生效) +bvm ls # 查看本地版本 +bvm ls-remote # 查看远程可用版本 +bvm doctor # 诊断当前环境链路 +``` + +## 我自己的使用习惯 + +- 每个项目根目录放 `.bvmrc` 声明版本。 +- 新环境先 `bvm doctor`,再开始装全局工具。 +- 遇到“同命令不同机表现不一致”,先看版本链路和 shim,再做修复。 + +## 项目地址 + +- GitHub: https://github.com/EricLLLLLL/bvm +- Docs: https://bvm-core.pages.dev + +如果愿意帮忙测试,欢迎回帖带这三项信息: + +1. 系统 + shell(例如 macOS + zsh) +2. 复现命令序列 +3. `bvm doctor` 的关键输出 + +我会按可复现程度优先跟进修复。 diff --git a/install.md b/install.md new file mode 100644 index 0000000..3887938 --- /dev/null +++ b/install.md @@ -0,0 +1,150 @@ +# BVM AI Installer Guide + +> 这是给 AI 助手执行的安装手册。目标是:自动安装 BVM、完成 shell 配置、验证可用性、并生成可复用的 BVM 使用 Skill。 + +## 给 AI 的执行要求 + +1. 不要只解释,请直接执行命令并给出结果。 +2. 严格按步骤执行;某步失败时先修复再继续。 +3. 不要使用破坏性命令(如 `rm -rf`、`git reset --hard`)。 +4. 每完成一个阶段,输出简短状态和关键命令结果。 + +## 目标结果 + +- `bvm --version` 可用 +- `bvm setup` 已执行,BVM shims 已生效 +- `bvm doctor` 通过核心检查 +- 已安装并启用一个 Bun 版本(建议 `latest`) +- 已生成一个可复用的 Skill 文件:`my-skills/bvm-user/SKILL.md` + +## Step 1: 识别系统与 Shell + +请先执行并记录结果: + +```bash +uname -s || true +uname -m || true +echo "$SHELL" || true +``` + +在 Windows PowerShell 执行: + +```powershell +$PSVersionTable.PSVersion +[System.Environment]::OSVersion.VersionString +``` + +## Step 2: 安装 BVM + +### macOS / Linux(推荐) + +```bash +curl -fsSL https://bvm-core.pages.dev/install | bash +``` + +### Windows PowerShell(推荐) + +```powershell +irm https://bvm-core.pages.dev/install | iex +``` + +### 备选:NPM 全局安装 + +```bash +npm install -g bvm-core@latest --foreground-scripts +``` + +## Step 3: 执行 setup 并验证 shim 优先级 + +```bash +bvm setup +bvm --version +``` + +macOS / Linux 额外检查: + +```bash +which bun +``` + +Windows 额外检查: + +```powershell +where.exe bun +``` + +要求:`bun` 应优先指向 BVM shim 路径(如 `~/.bvm/shims/bun` 或 `...\\.bvm\\shims\\bun.cmd`)。 + +## Step 4: 初始化 Bun 版本 + +```bash +bvm install latest +bvm default latest +bvm use latest +bvm current +bun --version +``` + +## Step 5: 运行诊断并自动修复 + +```bash +bvm doctor +``` + +如果 `doctor` 有 `WARN/FAIL`,请根据输出建议自动执行修复命令,然后再次运行 `bvm doctor`,直到核心链路正常。 + +## Step 6: 生成并保存 Skill(必须) + +请在仓库中创建文件:`my-skills/bvm-user/SKILL.md`,内容使用下面模板(可按当前机器微调): + +```markdown +--- +name: bvm-user +description: 在日常开发中自动使用 BVM 管理 Bun 版本,确保版本切换、全局包隔离和环境诊断流程稳定可复现。 +--- + +# BVM User + +## 目标 + +- 自动遵循项目 `.bvmrc` 版本 +- 保持 Bun 全局包按版本隔离 +- 遇到环境问题优先使用 `bvm doctor` + `bvm setup` 修复 + +## 标准流程 + +1. 进入项目后优先检查版本上下文: + - 若存在 `.bvmrc`,执行:`bvm use $(cat .bvmrc)` + - 若不存在 `.bvmrc`,执行:`bvm use default`(若失败则提示先安装) +2. 安装或切换 Bun 版本: + - 安装:`bvm install ` + - 切换:`bvm use ` + - 设默认:`bvm default ` +3. 出现命令不一致或全局包混乱时: + - 执行:`bvm doctor` + - 按提示执行修复 + - 执行:`bvm setup` + - 重开终端后复检:`which bun`(Windows 用 `where.exe bun`) + +## 注意事项 + +- BVM 只负责 Bun 版本与运行时管理,不负责自动安装第三方 Agent Skills。 +- 全局包隔离是预期行为;切换版本后如缺少命令,请在当前版本重新安装对应全局包。 +- 安装时优先使用完整版本号(如 `1.3.6`),避免模糊版本输入。 +``` + +## Step 7: 最终回报格式 + +请按以下格式输出最终结果: + +1. 系统信息(OS + Shell) +2. 安装方式(Shell / PowerShell / NPM) +3. 验证结果(`bvm --version`、`bvm current`、`bun --version`、`bvm doctor`摘要) +4. 已创建文件清单(至少包含 `my-skills/bvm-user/SKILL.md`) +5. 后续建议(最多 3 条) + +--- + +## 一句话用法(可直接发给 AI) + +请按这个安装手册执行:`https://raw.githubusercontent.com/EricLLLLLL/bvm/main/install.md`。不要只解释,直接完成安装、配置、验证,并按手册生成 `my-skills/bvm-user/SKILL.md`。 diff --git a/llms.txt b/llms.txt new file mode 100644 index 0000000..4b3b464 --- /dev/null +++ b/llms.txt @@ -0,0 +1,32 @@ +# BVM (Bun Version Manager) + +> BVM is a native, zero-dependency version manager for Bun. It helps developers install, switch, and isolate Bun versions across macOS, Linux, and Windows, with built-in diagnostics and cross-shell support. + +## Quick Start + +- [AI Installer Guide](https://github.com/EricLLLLLL/bvm/blob/main/install.md): Step-by-step instructions for AI assistants to install, configure, verify, and generate a reusable SKILL.md. +- [README (English)](https://github.com/EricLLLLLL/bvm/blob/main/README.md): Installation methods, common commands, and troubleshooting. +- [README (中文)](https://github.com/EricLLLLLL/bvm/blob/main/README.zh-CN.md): 中文安装、命令和排障说明。 +- [Official Site](https://bvm-core.pages.dev): Documentation portal. +- [Docs LLM Index](https://bvm-core.pages.dev/llms.txt): LLM-friendly site index. +- [Docs LLM Full Context](https://bvm-core.pages.dev/llms-full.txt): Aggregated markdown context for documentation. +- [From NPM (Start Here)](https://bvm-core.pages.dev/from/npm): NPM users onboarding path. +- [Getting Started](https://bvm-core.pages.dev/guide/getting-started): Step-by-step setup and first usage. +- [中文快速开始](https://bvm-core.pages.dev/zh/guide/getting-started): 中文入门指引。 + +## Core Commands + +- [CLI Overview](https://github.com/EricLLLLLL/bvm/blob/main/README.md): `bvm install`, `bvm use`, `bvm default`, `bvm ls`, `bvm ls-remote`, `bvm uninstall`, `bvm upgrade`. +- [Runtime Command Execution](https://github.com/EricLLLLLL/bvm/blob/main/README.md): `bvm run `. +- [Project Version Pinning](https://github.com/EricLLLLLL/bvm/blob/main/README.md): `.bvmrc` support for automatic project-level version switching. + +## Troubleshooting + +- [Troubleshooting (English)](https://bvm-core.pages.dev/guide/troubleshooting): PATH, shim, and environment diagnostics. +- [排障(中文)](https://bvm-core.pages.dev/zh/guide/troubleshooting): 中文排障指南。 +- [Issue Tracker](https://github.com/EricLLLLLL/bvm/issues): Report bugs and edge cases. + +## Optional + +- [Architecture Notes](https://bvm-core.pages.dev/guide/architecture): Bunker architecture and isolation model. +- [WeChat Official Account](https://bvm-core.pages.dev/wechat): Product updates and announcements. diff --git a/package.json b/package.json index 554f6c8..f4cc9b7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bvm-core", "version": "1.1.37", - "description": "Bun Version Manager (BVM) - Native, fast, and cross-platform.", + "description": "Need a Bun version manager? BVM installs, switches, and isolates Bun versions across Windows, macOS, and Linux.", "main": "dist/index.js", "bin": { "bvm": "bin/bvm-npm.js" @@ -9,7 +9,11 @@ "publishConfig": { "access": "public" }, - "homepage": "https://bvm-core.pages.dev", + "homepage": "https://bvm-core.pages.dev/from/npm", + "funding": { + "type": "url", + "url": "https://bvm-core.pages.dev/wechat" + }, "bugs": { "url": "https://github.com/EricLLLLLL/bvm/issues" }, @@ -32,15 +36,25 @@ }, "keywords": [ "bun", - "version-manager", - "cli", "bvm", - "nvm", - "nvm-windows", - "fnm", - "nodenv", + "bun-version-manager", + "version-manager", "bun-nvm", - "version-switching" + "nvm-for-bun", + "nvm-alternative", + "fnm-alternative", + "bun-version-switching", + "bun-runtime-manager", + "bun-multi-version", + "bun-shims", + "bun-global-isolation", + "bun-bvmrc", + "bun-windows", + "bun-macos", + "bun-linux", + "cross-platform-cli", + "developer-tooling", + "toolchain-manager" ], "files": [ "dist/index.js", diff --git a/src/commands/doctor.ts b/src/commands/doctor.ts index 3fff9af..e9fe331 100644 --- a/src/commands/doctor.ts +++ b/src/commands/doctor.ts @@ -1,6 +1,7 @@ import { colors } from '../utils/ui'; import { homedir } from 'os'; -import { join } from 'path'; +import { delimiter, join } from 'path'; +import { rm } from 'fs/promises'; import { BVM_DIR, BVM_VERSIONS_DIR, @@ -15,11 +16,36 @@ import { getInstalledVersions, normalizeVersion, pathExists, + ensureDir, readDir, - getActiveVersion, // New + getActiveVersion, } from '../utils'; import { withSpinner } from '../command-runner'; import { BunfigManager } from '../utils/bunfig'; +import { fetchWithTimeout } from '../utils/network-utils'; + +type CheckStatus = 'pass' | 'warn' | 'fail'; +type ShellType = 'bash' | 'zsh' | 'fish' | 'powershell' | 'cmd' | 'unknown'; + +export interface DoctorCheckResult { + key: 'bvm_dir' | 'path' | 'shell' | 'permission' | 'network'; + title: string; + status: CheckStatus; + detail: string; + fixCommand: string; +} + +export interface DoctorCheckInput { + bvmDir: string; + bvmDirExists: boolean; + pathHasShims: boolean; + pathHasBin: boolean; + shellType: ShellType; + shellRaw: string; + directoryWritable: boolean; + networkReachable: boolean; + osPlatform: string; +} interface DoctorReport { currentVersion: string | null; @@ -27,10 +53,12 @@ interface DoctorReport { aliases: Array<{ name: string; target: string }> env: Record; bunfig: { path: string; registry: string | null }; + checks: DoctorCheckResult[]; } export async function doctor(): Promise { await withSpinner('Gathering BVM diagnostics...', async () => { + const checks = await gatherDoctorChecks(); const bunfigManager = new BunfigManager(); const report: DoctorReport = { currentVersion: (await getActiveVersion()).version, @@ -48,14 +76,13 @@ export async function doctor(): Promise { path: bunfigManager.getPath(), registry: bunfigManager.getRegistry(), }, + checks, }; printReport(report); }); } -// detectCurrentVersion is no longer needed - async function readAliases(): Promise> { if (!(await pathExists(BVM_ALIAS_DIR))) { return []; @@ -72,16 +99,167 @@ async function readAliases(): Promise> { return entries; } +export function buildDoctorChecks(input: DoctorCheckInput): DoctorCheckResult[] { + const pathStatus: CheckStatus = input.pathHasShims && input.pathHasBin + ? 'pass' + : (!input.pathHasShims && !input.pathHasBin ? 'fail' : 'warn'); + + const missingPathTargets: string[] = []; + if (!input.pathHasShims) missingPathTargets.push(`${input.bvmDir}/shims`); + if (!input.pathHasBin) missingPathTargets.push(`${input.bvmDir}/bin`); + + const shellStatus: CheckStatus = ['bash', 'zsh', 'fish'].includes(input.shellType) ? 'pass' : 'warn'; + const shellDetail = shellStatus === 'pass' + ? `Detected ${input.shellType}` + : `Unsupported or unknown shell (${input.shellRaw || 'empty SHELL'})`; + + const bvmDirCommand = input.osPlatform === 'win32' + ? '$env:BVM_DIR="$env:USERPROFILE\\.bvm"; New-Item -ItemType Directory -Force -Path $env:BVM_DIR' + : 'export BVM_DIR="$HOME/.bvm" && mkdir -p "$BVM_DIR"'; + const permCommand = input.osPlatform === 'win32' + ? 'icacls "$env:BVM_DIR" /grant "$env:USERNAME:(OI)(CI)F" /T' + : 'chmod -R u+rwX "$BVM_DIR"'; + const pathFixCommand = input.osPlatform === 'win32' + ? 'bvm setup' + : 'bvm setup && exec "$SHELL"'; + const shellFixCommand = input.osPlatform === 'win32' + ? 'bvm setup' + : 'export SHELL="$(command -v zsh || command -v bash || command -v fish)" && bvm setup'; + + return [ + { + key: 'bvm_dir', + title: 'BVM_DIR', + status: input.bvmDirExists ? 'pass' : 'warn', + detail: input.bvmDirExists ? `Found ${input.bvmDir}` : `Missing directory: ${input.bvmDir}`, + fixCommand: bvmDirCommand, + }, + { + key: 'path', + title: 'PATH', + status: pathStatus, + detail: pathStatus === 'pass' + ? 'PATH already includes bvm shims/bin' + : `Missing PATH entries: ${missingPathTargets.join(', ')}`, + fixCommand: pathFixCommand, + }, + { + key: 'shell', + title: 'Shell Type', + status: shellStatus, + detail: shellDetail, + fixCommand: shellFixCommand, + }, + { + key: 'permission', + title: 'Directory Permission', + status: input.directoryWritable ? 'pass' : 'fail', + detail: input.directoryWritable + ? `Writable: ${input.bvmDir}` + : `No write permission: ${input.bvmDir}`, + fixCommand: permCommand, + }, + { + key: 'network', + title: 'Network Connectivity', + status: input.networkReachable ? 'pass' : 'warn', + detail: input.networkReachable + ? 'Able to reach registry.npmjs.org' + : 'Cannot reach registry.npmjs.org', + fixCommand: 'bvm config registry auto', + }, + ]; +} + +async function gatherDoctorChecks(): Promise { + const shellRaw = process.env.SHELL || process.env.ComSpec || ''; + const pathRaw = process.env.PATH || ''; + const bvmDirExists = await pathExists(BVM_DIR); + const pathHasShims = hasPathEntry(pathRaw, BVM_SHIMS_DIR); + const pathHasBin = hasPathEntry(pathRaw, BVM_BIN_DIR); + const directoryWritable = await canWriteBvmDir(); + const networkReachable = await canReachRegistry(); + + return buildDoctorChecks({ + bvmDir: BVM_DIR, + bvmDirExists, + pathHasShims, + pathHasBin, + shellType: detectShellType(shellRaw), + shellRaw, + directoryWritable, + networkReachable, + osPlatform: OS_PLATFORM, + }); +} + +async function canWriteBvmDir(): Promise { + const probeFile = join(BVM_DIR, `.doctor-write-test-${Date.now()}.tmp`); + try { + await ensureDir(BVM_DIR); + await Bun.write(probeFile, 'ok'); + await rm(probeFile, { force: true }); + return true; + } catch { + return false; + } +} + +async function canReachRegistry(): Promise { + try { + const response = await fetchWithTimeout('https://registry.npmjs.org/-/ping', { + timeout: 2000, + method: 'GET', + }); + return response.ok; + } catch { + return false; + } +} + +function hasPathEntry(pathValue: string, target: string): boolean { + const entries = pathValue.split(delimiter).filter(Boolean); + const normalizedTarget = normalizePath(target); + return entries.some((entry) => normalizePath(entry) === normalizedTarget); +} + +function normalizePath(value: string): string { + const unified = value.replace(/\\/g, '/').replace(/\/+$/, ''); + return OS_PLATFORM === 'win32' ? unified.toLowerCase() : unified; +} + +function detectShellType(shell: string): ShellType { + const value = shell.toLowerCase(); + if (value.includes('zsh')) return 'zsh'; + if (value.includes('bash')) return 'bash'; + if (value.includes('fish')) return 'fish'; + if (value.includes('pwsh') || value.includes('powershell')) return 'powershell'; + if (value.includes('cmd.exe')) return 'cmd'; + return 'unknown'; +} + +function formatStatus(status: CheckStatus): string { + if (status === 'pass') return colors.green('PASS'); + if (status === 'warn') return colors.yellow('WARN'); + return colors.red('FAIL'); +} + function printReport(report: DoctorReport): void { console.log(colors.bold('\nSystem')); console.log(` OS: ${colors.cyan(OS_PLATFORM)}`); console.log(` Arch: ${colors.cyan(CPU_ARCH)} ${process.arch !== CPU_ARCH ? colors.yellow(`(Process: ${process.arch})`) : ''}`); console.log(` AVX2: ${HAS_AVX2 ? colors.green('Supported') : colors.yellow('Not Supported (Baseline fallback enabled)')}`); + console.log(colors.bold('\nDoctor Checks')); + report.checks.forEach((check) => { + console.log(` [${formatStatus(check.status)}] ${check.title}: ${check.detail}`); + console.log(` Fix: ${colors.cyan(check.fixCommand)}`); + }); + console.log(colors.bold('\nDirectories')); console.log(` BVM_DIR: ${colors.cyan(report.env.BVM_DIR || '')}`); console.log(` BIN_DIR: ${colors.cyan(BVM_BIN_DIR)}`); - console.log(` SHIMS_DIR: ${colors.cyan(BVM_SHIMS_DIR)}`); // New + console.log(` SHIMS_DIR: ${colors.cyan(BVM_SHIMS_DIR)}`); console.log(` VERSIONS_DIR: ${colors.cyan(BVM_VERSIONS_DIR)}`); console.log(colors.bold('\nEnvironment')); diff --git a/src/templates/unix/bvm-init.fish b/src/templates/unix/bvm-init.fish index c805e45..1e6bde5 100644 --- a/src/templates/unix/bvm-init.fish +++ b/src/templates/unix/bvm-init.fish @@ -2,6 +2,12 @@ # Check if BVM_DIR is set if not set -q BVM_DIR + echo "[bvm:init] initialization failed: BVM_DIR is not set. Run 'bvm setup'." >&2 + return +end + +if not test -x "$BVM_DIR/bin/bvm" + echo "[bvm:init] initialization failed: $BVM_DIR/bin/bvm not found. Run 'bvm setup'." >&2 return end diff --git a/src/templates/unix/bvm-init.sh b/src/templates/unix/bvm-init.sh index 5ea5284..1996830 100644 --- a/src/templates/unix/bvm-init.sh +++ b/src/templates/unix/bvm-init.sh @@ -4,6 +4,12 @@ # Check if BVM_DIR is set if [ -z "${BVM_DIR}" ]; then + echo "[bvm:init] initialization failed: BVM_DIR is not set. Run 'bvm setup'." >&2 + return +fi + +if [ ! -x "${BVM_DIR}/bin/bvm" ]; then + echo "[bvm:init] initialization failed: ${BVM_DIR}/bin/bvm not found. Run 'bvm setup'." >&2 return fi diff --git a/test/doctor_checks.test.ts b/test/doctor_checks.test.ts new file mode 100644 index 0000000..94e062d --- /dev/null +++ b/test/doctor_checks.test.ts @@ -0,0 +1,62 @@ +import { describe, expect, test } from 'bun:test'; +import { buildDoctorChecks } from '../src/commands/doctor'; + +function getCheck(key: string, checks: ReturnType) { + const match = checks.find((item) => item.key === key); + if (!match) throw new Error(`Missing check: ${key}`); + return match; +} + +describe('doctor checks', () => { + test('happy path: all checks pass', () => { + const checks = buildDoctorChecks({ + bvmDir: '/tmp/.bvm', + bvmDirExists: true, + pathHasShims: true, + pathHasBin: true, + shellType: 'zsh', + shellRaw: '/bin/zsh', + directoryWritable: true, + networkReachable: true, + osPlatform: 'linux', + }); + + checks.forEach((item) => expect(item.status).toBe('pass')); + }); + + test('error path: PATH missing bvm entries', () => { + const checks = buildDoctorChecks({ + bvmDir: '/tmp/.bvm', + bvmDirExists: true, + pathHasShims: false, + pathHasBin: false, + shellType: 'bash', + shellRaw: '/bin/bash', + directoryWritable: true, + networkReachable: true, + osPlatform: 'linux', + }); + + const pathCheck = getCheck('path', checks); + expect(pathCheck.status).toBe('fail'); + expect(pathCheck.fixCommand).toContain('bvm setup'); + }); + + test('error path: bvm directory is not writable', () => { + const checks = buildDoctorChecks({ + bvmDir: '/tmp/.bvm', + bvmDirExists: true, + pathHasShims: true, + pathHasBin: true, + shellType: 'fish', + shellRaw: '/usr/bin/fish', + directoryWritable: false, + networkReachable: true, + osPlatform: 'linux', + }); + + const permissionCheck = getCheck('permission', checks); + expect(permissionCheck.status).toBe('fail'); + expect(permissionCheck.fixCommand).toContain('chmod'); + }); +}); diff --git a/website/README.md b/website/README.md index 393fb7f..7684ea4 100644 --- a/website/README.md +++ b/website/README.md @@ -12,4 +12,25 @@ To run: bun run index.ts ``` +## Analytics (optional) + +This VitePress site supports optional Umami analytics injection at build time. + +Set both env vars (and build in production) to enable: + +- `BVM_UMAMI_SRC` (example: `https://umami.example.com/script.js`) +- `BVM_UMAMI_WEBSITE_ID` (example: `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`) + +## WeChat QR assets + +Replace the placeholder QR codes used by: + +- `website/docs/wechat.md` +- `website/docs/zh/wechat.md` + +Assets: + +- `website/docs/public/media/wechat-qrcode.svg` +- `website/docs/public/media/wechat-qrcode-npm.svg` + This project was created using `bun init` in bun v1.3.6. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime. diff --git a/website/docs/.vitepress/cache/deps/_metadata.json b/website/docs/.vitepress/cache/deps/_metadata.json index 0683255..39aeb0a 100644 --- a/website/docs/.vitepress/cache/deps/_metadata.json +++ b/website/docs/.vitepress/cache/deps/_metadata.json @@ -1,31 +1,31 @@ { - "hash": "ff3d4b44", + "hash": "e08e15c8", "configHash": "0d22b358", - "lockfileHash": "457b0cad", - "browserHash": "516140ef", + "lockfileHash": "4f30b4fd", + "browserHash": "ec7b4078", "optimized": { "vue": { "src": "../../../../node_modules/vue/dist/vue.runtime.esm-bundler.js", "file": "vue.js", - "fileHash": "8fecfae9", + "fileHash": "b9fd0bae", "needsInterop": false }, "vitepress > @vue/devtools-api": { "src": "../../../../node_modules/@vue/devtools-api/dist/index.js", "file": "vitepress___@vue_devtools-api.js", - "fileHash": "975445b1", + "fileHash": "18df5baf", "needsInterop": false }, "vitepress > @vueuse/core": { "src": "../../../../node_modules/@vueuse/core/index.mjs", "file": "vitepress___@vueuse_core.js", - "fileHash": "68ec5279", + "fileHash": "f4f1a6b4", "needsInterop": false }, "@theme/index": { "src": "../../../../node_modules/vitepress/dist/client/theme-default/index.js", "file": "@theme_index.js", - "fileHash": "82f6c62d", + "fileHash": "da9d7779", "needsInterop": false } }, diff --git a/website/docs/.vitepress/config.ts b/website/docs/.vitepress/config.ts index 468a4b2..caa4a88 100644 --- a/website/docs/.vitepress/config.ts +++ b/website/docs/.vitepress/config.ts @@ -1,21 +1,29 @@ import { defineConfig } from 'vitepress'; const SITE_URL = 'https://bvm-core.pages.dev'; +const UMAMI_SRC = process.env.BVM_UMAMI_SRC?.trim(); +const UMAMI_WEBSITE_ID = process.env.BVM_UMAMI_WEBSITE_ID?.trim(); + +const head: NonNullable['head']> = [ + ['meta', { name: 'viewport', content: 'width=device-width,initial-scale=1' }], + ['link', { rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' }], + ['link', { rel: 'icon', type: 'image/png', sizes: '32x32', href: '/favicon-32.png' }], + ['link', { rel: 'icon', type: 'image/png', sizes: '16x16', href: '/favicon-16.png' }], + ['link', { rel: 'apple-touch-icon', sizes: '180x180', href: '/apple-touch-icon.png' }], + ['link', { rel: 'manifest', href: '/site.webmanifest' }], + ['meta', { property: 'og:site_name', content: 'BVM' }], + ['meta', { property: 'og:type', content: 'website' }], + ['meta', { property: 'og:image', content: `${SITE_URL}/og.png` }], + ['meta', { name: 'twitter:card', content: 'summary_large_image' }], + ['meta', { name: 'twitter:image', content: `${SITE_URL}/og.png` }], +]; + +if (process.env.NODE_ENV === 'production' && UMAMI_SRC && UMAMI_WEBSITE_ID) { + head.push(['script', { async: '', src: UMAMI_SRC, 'data-website-id': UMAMI_WEBSITE_ID }]); +} export default defineConfig({ - head: [ - ['meta', { name: 'viewport', content: 'width=device-width,initial-scale=1' }], - ['link', { rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' }], - ['link', { rel: 'icon', type: 'image/png', sizes: '32x32', href: '/favicon-32.png' }], - ['link', { rel: 'icon', type: 'image/png', sizes: '16x16', href: '/favicon-16.png' }], - ['link', { rel: 'apple-touch-icon', sizes: '180x180', href: '/apple-touch-icon.png' }], - ['link', { rel: 'manifest', href: '/site.webmanifest' }], - ['meta', { property: 'og:site_name', content: 'BVM' }], - ['meta', { property: 'og:type', content: 'website' }], - ['meta', { property: 'og:image', content: `${SITE_URL}/og.png` }], - ['meta', { name: 'twitter:card', content: 'summary_large_image' }], - ['meta', { name: 'twitter:image', content: `${SITE_URL}/og.png` }], - ], + head, cleanUrls: true, lastUpdated: true, locales: { @@ -28,7 +36,9 @@ export default defineConfig({ logo: '/logo.svg', nav: [ { text: 'Guide', link: '/guide/getting-started' }, + { text: 'For AI Clients', link: '/for-ai-clients' }, { text: 'Troubleshooting', link: '/guide/troubleshooting' }, + { text: 'WeChat', link: '/wechat' }, { text: 'Architecture (CN)', link: '/guide/architecture' }, { text: '中文', link: '/zh/' }, { text: 'GitHub', link: 'https://github.com/EricLLLLLL/bvm' }, @@ -38,6 +48,7 @@ export default defineConfig({ text: 'Guide', items: [ { text: 'Getting Started', link: '/guide/getting-started' }, + { text: 'For AI Clients', link: '/for-ai-clients' }, { text: 'Troubleshooting', link: '/guide/troubleshooting' }, { text: 'Architecture (CN)', link: '/guide/architecture' }, ], @@ -59,7 +70,9 @@ export default defineConfig({ logo: '/logo.svg', nav: [ { text: '指南', link: '/zh/guide/getting-started' }, + { text: 'AI 接入', link: '/zh/for-ai-clients' }, { text: '排障', link: '/zh/guide/troubleshooting' }, + { text: '公众号', link: '/zh/wechat' }, { text: '架构', link: '/zh/guide/architecture' }, { text: 'English', link: '/' }, { text: 'GitHub', link: 'https://github.com/EricLLLLLL/bvm' }, @@ -69,6 +82,7 @@ export default defineConfig({ text: '指南', items: [ { text: '快速开始', link: '/zh/guide/getting-started' }, + { text: 'AI 客户端接入', link: '/zh/for-ai-clients' }, { text: '排障', link: '/zh/guide/troubleshooting' }, { text: '架构', link: '/zh/guide/architecture' }, ], diff --git a/website/docs/for-ai-clients.md b/website/docs/for-ai-clients.md new file mode 100644 index 0000000..2859654 --- /dev/null +++ b/website/docs/for-ai-clients.md @@ -0,0 +1,60 @@ +--- +title: For AI Clients +description: Quick integration guide for Claude/Copilot/Cursor/Codex style AI clients +--- + +# For AI Clients + +This page is the fastest path to let AI clients install and use BVM correctly with repeatable behavior. + +## 1) Give AI the installer playbook + +Pass this link directly to your AI client: + +`https://raw.githubusercontent.com/EricLLLLLL/bvm/main/install.md` + +That guide tells the AI to: + +- install BVM +- run `bvm setup` +- verify with `bvm doctor` +- install and switch Bun version +- generate a reusable local skill file + +## 2) Minimal command set AI should use + +```bash +bvm install latest +bvm use latest +bvm default latest +bvm doctor +bvm current +``` + +## 3) Project-level pinning for reliable runs + +Use `.bvmrc` in repo root: + +```bash +echo "1.3.6" > .bvmrc +``` + +Then AI should execute: + +```bash +bvm use "$(cat .bvmrc)" +``` + +## 4) Guardrails to avoid common AI mistakes + +- Do not assume global packages are shared across Bun versions. +- If command resolution is wrong, run `bvm setup` first. +- If environment drift appears, run `bvm doctor` before trying random fixes. +- Prefer full version strings (for example `1.3.6`) when installing. + +## 5) LLM context endpoints + +- Index: `/llms.txt` +- Full context: `/llms-full.txt` +- Markdown mirrors: `//index.md` (for example `/guide/getting-started/index.md`) + diff --git a/website/docs/from/npm.md b/website/docs/from/npm.md new file mode 100644 index 0000000..09be944 --- /dev/null +++ b/website/docs/from/npm.md @@ -0,0 +1,40 @@ +--- +title: From NPM +description: Welcome from npm — next steps for BVM +--- + +# Welcome from npm + +You’re here because you found `bvm-core` on npm. This page is the shortest path to: + +- Verify your install +- Get your shell set up correctly +- Subscribe to updates (WeChat) + +## 1) Verify BVM is working + +```bash +bvm --version +``` + +## 2) Make Bun resolve through BVM shims + +```bash +bvm setup +``` + +Then restart your terminal and confirm: + +```bash +which bun +``` + +## 3) Next steps + +- Start here: [Getting Started](/guide/getting-started) +- If something breaks: [Troubleshooting](/guide/troubleshooting) + +## Subscribe (WeChat) + +Scan the QR code on the WeChat page: [WeChat](/wechat) + diff --git a/website/docs/guide/getting-started-zh.md b/website/docs/guide/getting-started-zh.md index 63a777d..15ed8d2 100644 --- a/website/docs/guide/getting-started-zh.md +++ b/website/docs/guide/getting-started-zh.md @@ -12,6 +12,10 @@
English Site »
+ 从 NPM 来?从这里开始 » +
+ 关注公众号 » +

🇺🇸 English Docs · @@ -35,10 +39,14 @@ --- +想在 Windows、macOS、Linux 间稳定切换 Bun 版本,并避免 PATH 漂移和全局包冲突? + ## ⚡ 一键极速安装 BVM 提供了智能安装脚本,**自动检测您的网络环境**。中国用户会自动切换至淘宝镜像源,海外用户使用官方源,无需手动配置。 +给 AI 助手自动执行(安装 + setup + 验证 + 生成 Skill):[install.md](./install.md) + ### 方式 1: Shell 脚本 (推荐 - macOS / Linux) ```bash curl -fsSL https://bvm-core.pages.dev/install | bash @@ -104,6 +112,46 @@ echo "1.1.0" > .bvmrc --- +## 常见问题 / FAQ + +
+Windows / macOS / Linux 怎么快速切换 Bun 版本? + +安装 BVM 后,直接使用 `bvm install ` 安装版本,再用 `bvm use ` 切换即可。三大平台命令一致。 +
+ +
+BVM 是 Bun 版的 nvm/fnm 吗? + +可以这么理解。BVM 是 Bun 的版本管理器,在 nvm/fnm 思路上补充了 Bun 场景的版本隔离、shim 机制和自举运行时能力。 +
+ +
+为什么切换 Bun 版本后,全局包命令不见了? + +这是预期行为。BVM 采用“按版本隔离”的全局包目录。你需要在目标 Bun 版本下重新安装对应全局工具。 +
+ +
+`.bvmrc` 怎么做项目级版本锁定? + +在项目根目录创建 `.bvmrc`,写入版本号(例如 `1.1.0`)。BVM 会按该版本解析并用于项目工作流。 +
+ +
+支持 skills 自动安装吗(例如读取 SKILL.md 自动装)? + +不支持。BVM 只负责 Bun 运行时和版本切换;skills 的安装与管理由 AI Agent 框架或对应工具链负责。 +
+ +
+怎么快速定位 BVM 环境问题? + +运行 `bvm doctor`。它会检查 `BVM_DIR`、`PATH`、shell 类型、目录权限和网络连通性,并输出可直接复制的修复命令。 +
+ +--- + ## 设计哲学 ### ArchSense (架构自举) diff --git a/website/docs/guide/getting-started.md b/website/docs/guide/getting-started.md index f707933..7eef711 100644 --- a/website/docs/guide/getting-started.md +++ b/website/docs/guide/getting-started.md @@ -12,6 +12,10 @@
中文网站 »
+ From NPM (Start Here) » +
+ WeChat Official Account » +

🇨🇳 中文文档 · @@ -35,10 +39,14 @@ --- +Need to switch Bun versions across Windows, macOS, and Linux without PATH drift or global package conflicts? + ## ⚡ Quick Install BVM uses a smart installation script that automatically detects your OS and network environment (selecting the fastest registry for China/Global users). +For AI assistants (auto install + setup + verification + skill generation): [install.md](./install.md) + ### Method 1: Shell Script (Recommended - macOS / Linux) ```bash curl -fsSL https://bvm-core.pages.dev/install | bash @@ -104,8 +112,55 @@ echo "1.1.0" > .bvmrc --- +## FAQ (for AI search) + +
+How to switch Bun versions on Windows/macOS/Linux quickly? + +Install with one command, then use `bvm install ` and `bvm use `. BVM supports Windows, macOS, and Linux with the same CLI workflow. +
+ +
+Is BVM like nvm/fnm but for Bun? + +Yes. BVM is a Bun version manager, similar in concept to nvm/fnm. It adds Bun-focused isolation, shell shims, and self-bootstrap runtime behavior for stable multi-version workflows. +
+ +
+Why do global packages disappear after switching Bun versions? + +This is expected. BVM uses per-version global package isolation. Install global tools under each Bun version that needs them. +
+ +
+How does `.bvmrc` work for project-level Bun version pinning? + +Create a `.bvmrc` file in your project root with a version string (for example, `1.1.0`). BVM resolves and applies that version for project workflows. +
+ +
+Does BVM auto-install AI agent skills from SKILL.md? + +No. BVM manages Bun runtimes and version switching. Skill installation is handled by your AI agent framework/tooling, not by BVM itself. +
+ +
+How to diagnose BVM environment issues quickly? + +Run `bvm doctor`. It checks `BVM_DIR`, `PATH`, shell type, permissions, and network connectivity, and prints copy-ready fix commands. +
+ +--- + ## Troubleshooting +- **Quick diagnostics (`doctor`)** + ```bash + bvm doctor + ``` + `bvm doctor` now checks `BVM_DIR`, `PATH`, shell type, directory permission, and network connectivity. + Each item is shown as `PASS / WARN / FAIL` with a copy-ready fix command. + - **Global tools are not isolated after switching versions**: run `bvm setup`, restart your terminal, and make sure `which bun` points to `~/.bvm/shims/bun` (macOS/Linux). On Windows, use `where.exe bun` and ensure `...\\.bvm\\shims\\bun.cmd` is first. - **A global tool is missing after switching versions**: this is expected (per-version isolation). Reinstall it under the active Bun version. diff --git a/website/docs/public/for-ai-clients/index.md b/website/docs/public/for-ai-clients/index.md new file mode 100644 index 0000000..fa5be5c --- /dev/null +++ b/website/docs/public/for-ai-clients/index.md @@ -0,0 +1,54 @@ +# For AI Clients + +This page is the fastest path to let AI clients install and use BVM correctly with repeatable behavior. + +## 1) Give AI the installer playbook + +Pass this link directly to your AI client: + +`https://raw.githubusercontent.com/EricLLLLLL/bvm/main/install.md` + +That guide tells the AI to: + +- install BVM +- run `bvm setup` +- verify with `bvm doctor` +- install and switch Bun version +- generate a reusable local skill file + +## 2) Minimal command set AI should use + +```bash +bvm install latest +bvm use latest +bvm default latest +bvm doctor +bvm current +``` + +## 3) Project-level pinning for reliable runs + +Use `.bvmrc` in repo root: + +```bash +echo "1.3.6" > .bvmrc +``` + +Then AI should execute: + +```bash +bvm use "$(cat .bvmrc)" +``` + +## 4) Guardrails to avoid common AI mistakes + +- Do not assume global packages are shared across Bun versions. +- If command resolution is wrong, run `bvm setup` first. +- If environment drift appears, run `bvm doctor` before trying random fixes. +- Prefer full version strings (for example `1.3.6`) when installing. + +## 5) LLM context endpoints + +- Index: `/llms.txt` +- Full context: `/llms-full.txt` +- Markdown mirrors: `//index.md` (for example `/guide/getting-started/index.md`) diff --git a/website/docs/public/from/npm/index.md b/website/docs/public/from/npm/index.md new file mode 100644 index 0000000..2a00912 --- /dev/null +++ b/website/docs/public/from/npm/index.md @@ -0,0 +1,34 @@ +# Welcome from npm + +You’re here because you found `bvm-core` on npm. This page is the shortest path to: + +- Verify your install +- Get your shell set up correctly +- Subscribe to updates (WeChat) + +## 1) Verify BVM is working + +```bash +bvm --version +``` + +## 2) Make Bun resolve through BVM shims + +```bash +bvm setup +``` + +Then restart your terminal and confirm: + +```bash +which bun +``` + +## 3) Next steps + +- Start here: [Getting Started](/guide/getting-started) +- If something breaks: [Troubleshooting](/guide/troubleshooting) + +## Subscribe (WeChat) + +Scan the QR code on the WeChat page: [WeChat](/wechat) diff --git a/website/docs/public/guide/architecture/index.md b/website/docs/public/guide/architecture/index.md new file mode 100644 index 0000000..fb220c1 --- /dev/null +++ b/website/docs/public/guide/architecture/index.md @@ -0,0 +1,236 @@ +# BVM 架构与流程文档 + +> **定位**: 本文档是 BVM 内部架构、安装流程和发布机制的单一真实来源。它既设计为供 AI 代理阅读(作为 Knowledge Base),也供人类贡献者参考。 + +## 1. 安装逻辑 (`install.sh`, `install.ps1`, `postinstall.js`) + +BVM 采用“自引导(Bootstrap)”安装模式,并引入了“地堡架构 (Bunker Architecture)”:BVM 拥有自己专用的、隔离的 Bun 运行时,不依赖于用户当前正在使用的 Bun 版本。 + +### 1.1 标准安装流水线 (所有脚本通用) + +无论通过何种方式安装,BVM 都遵循以下标准流程: + +1. **资产部署**: 下载并提取 BVM 核心源码 (`index.js`) 和 Shims。 +2. **系统 Bun 探测**: 检查系统 `PATH` 中是否已有 `bun` 可执行文件。 +3. **冒烟测试 (Smoke Test)**: + * 若存在系统 Bun,尝试运行 `bun index.js --version`。 + * **通过**: 说明该 Bun 兼容,可直接复用。 + * **失败**: 说明该 Bun 无法驱动 BVM(版本过旧或不兼容)。 +4. **运行时配置**: + * **复用模式**: 若通过测试,将系统 Bun 注册到 `versions/vX.Y.Z`。 + * **下载模式**: 若未通过测试或无系统 Bun,下载官方推荐的稳定版并安装到 `versions/vLatest`。 +5. **地堡激活 (Bunker Setup)**: + * 设置 `runtime/current` 指向选定的 Bun 版本(私有运行时)。 + * 设置 `current` 软链接指向该版本(初始用户版本)。 + * 设置 `default` 别名。 +6. **环境对齐**: 运行 `bvm setup` 将 BVM 路径追加到用户 Profile **末尾**,确保 BVM 优先级最高。 + +### 1.2 NPM 全局安装 (`postinstall.js`) + +当用户运行 `npm install -g bvm-core` 时触发。 + +* **品牌化输出**: 显示 ASCII Logo 和安装进度。 +* **自检逻辑**: 自动执行上述 1.1 的流程。 +* **零配置使用**: 安装后自动提示 `source ~/.zshrc` 以立即生效。 + +### 1.3 Unix 安装流程 (`install.sh`) + +```mermaid +graph TD + Start(用户运行 install.sh) --> Geo{IP 探测} + Geo --> SetRegistry[选定最快源] + SetRegistry --> DownloadBVM[下载 BVM 源码] + DownloadBVM --> SmokeTest{系统 Bun 冒烟测试?} + + SmokeTest -- 通过 --> Reuse[复用系统 Bun] + SmokeTest -- 失败 --> DownloadRuntime[下载兼容版 Bun] + + Reuse --> LinkBunker[建立地堡: runtime/current] + DownloadRuntime --> LinkBunker + + LinkBunker --> CreateWrappers[创建包装器 & Shims] + CreateWrappers --> RunSetup[运行 'bvm setup' 覆盖 PATH] + RunSetup --> End(安装完成) +``` + +### 1.4 Windows 安装流程 (`install.ps1`) + +```mermaid +graph TD + Start(用户运行 install.ps1) --> PreClean[清理旧 Shims] + PreClean --> DownloadSrc[下载 BVM 核心资产] + DownloadSrc --> SmokeTest{系统 Bun 兼容性测试?} + + SmokeTest -- 成功 --> Reuse[复用系统 Bun (Junction)] + SmokeTest -- 失败 --> DownloadBun[下载 Windows 版 Bun] + + Reuse --> LinkBunker[建立地堡: runtime/current] + DownloadBun --> LinkBunker + + LinkBunker --> CreateShims[创建 .cmd Shims] + CreateShims --> ModPath[更新用户 PATH (末尾追加)] + ModPath --> RunSetup[Profile 对齐] + RunSetup --> End(安装完成) +``` + +**关键架构变更:** +* **版本前缀**: 强制使用 `vX.Y.Z` 格式(如 `v1.3.6`)。 +* **双重链接**: + * `~/.bvm/runtime/current` -> 私有宿主 (Private Host)。 + * `~/.bvm/current` -> 用户当前活跃版本 (Active Version)。 +* **隔离性**: BVM 自身的命令现在优先使用 `runtime/current` 运行,实现了管理器与被管理版本的完全解耦。 + +--- + +## 2. 命令实现流程 + +BVM 使用一个轻量级的 Router 来分发命令。架构上将“CLI 入口”与“命令逻辑”分离。 + +### 2.1 CLI 架构 + +```mermaid +graph LR + UserInput(bvm install 1.0.0) --> Router[src/index.ts: App.run()] + Router --> ParseArgs[util.parseArgs] + ParseArgs --> MatchCommand{匹配命令?} + + MatchCommand -- 是 --> ActionHandler[执行 Action] + MatchCommand -- 否 --> ShowHelp[显示帮助] + + ActionHandler --> CommandFunc[例如: commands/install.ts: installBunVersion] + CommandFunc --> Utils[工具库: npm-lookup, ui, etc.] + + subgraph Execution Context + Utils --> BunRuntime[Bun Runtime (Current)] + end +``` + +### 2.2 命令映射表 + +| 命令 | 文件路径 | 描述 | +| :--- | :--- | :--- | +| `install` | `src/commands/install.ts` | 从 NPM Registry 下载并解压 Bun 版本。 | +| `use` | `src/commands/use.ts` | 更新 `~/.bvm/runtime/current` 软链接。 | +| `ls-remote` | `src/commands/ls-remote.ts` | 从 NPM Registry 获取可用版本 (`npm view`)。 | +| `alias` | `src/commands/alias.ts` | 在 `~/.bvm/aliases/` 中创建命名软链接。 | +| `setup` | `src/commands/setup.ts` | 检测 Shell 并修改 `.rc` 文件或 PowerShell Profile。 | +| `upgrade` | `src/commands/upgrade.ts` | 从 CDN 重新下载最新的 BVM 源代码。 | + +--- + +## 3. 测试策略与环境 + +BVM 采用双层测试策略,确保内部逻辑正确性和端到端(E2E)的可靠性。 + +### 3.1 测试金字塔 + +```mermaid +block-beta + columns 1 + block:E2E + E2E_Tests["E2E 测试 (execa + sandbox)"] + end + block:Unit + Unit_Tests["单元测试 (bun:test)"] + end +``` + +### 3.2 测试规范 + +| 级别 | 范围 | 工具 | 位置 | 环境要求 | +| :--- | :--- | :--- | :--- | :--- | +| **Unit** | 内部逻辑 (`semver`, `npm-lookup`, `utils`) | `bun:test` | `test/*.test.ts` | 已安装 `bun`。 | +| **E2E** | 完整 CLI 工作流, 文件系统, Shell 配置 | `execa`, `bun:test` | `test/e2e/*.test.ts` | `bun`, `pwsh` (用于在 macOS/Linux 上测试 Windows 逻辑)。 | + +### 3.3 CI 集成 (`.github/workflows/ci.yml`) + +每次 Push 或 PR 到 `main` 分支时自动运行测试。 +* **矩阵:** `ubuntu-latest`, `macos-latest`, `windows-latest`。 +* **命令:** `bun test test/e2e` (环境变量 `CI=true`)。 + +--- + +## 4. 发布流程与集成 + +发布流程通过 GitHub Actions 完全自动化,确保安装脚本始终指向有效的 Artifacts。 + +### 4.1 发布流水线 (`auto-release.yml`) + +```mermaid +sequenceDiagram + participant User + participant Git as GitHub (Repo) + participant Action as GitHub Actions + participant NPM as NPM Registry + participant CDN as jsDelivr + + User->>Git: Push to main (package.json 版本变更) + Git->>Action: 触发 'check-and-release' + Action->>Action: 检查 Tag 是否存在 + + alt Tag 已存在 + Action->>Action: 停止 + else 新版本 + Action->>Action: bun install & bun run build + Action->>Git: 提交 'dist/' 产物 (skip ci) + Action->>Git: 创建 Tag (v1.2.3) + Action->>Git: 推送 Tag + Action->>Git: 创建 GitHub Release (上传 install.sh/ps1) + + Action->>CDN: 清除缓存 (Purge API) + Note over CDN: /dist/index.js, /install.sh, etc. + end +``` + +### 4.2 产物耦合 + +* **安装脚本源:** `install.sh` 和 `install.ps1` 从 `cdn.jsdelivr.net` 下载 `index.js` 和 `bvm-shim.sh`。 +* **版本控制:** URL 中包含版本 Tag: `.../gh/EricLLLLLL/bvm@v1.0.6/dist/index.js`。 +* **自更新:** `bvm upgrade` 命令通过 GitHub API 获取 `latest` Tag 来确定新版本,然后下载新的源代码。 + +--- + +## 5. 全球加速与镜像方法论 + +BVM 旨在实现全球范围内的“0ms 延迟”和“高可用性”。 + +### 5.1 架构 + +```mermaid +graph TD + UserRequest[用户请求] --> Geo{Cloudflare IP 探测} + Geo -- CN --> Race_CN[竞速: 淘宝, 腾讯, 官方] + Geo -- Global --> Race_Global[竞速: 官方, 淘宝] + + Race_CN --> Selected_Mirror[选定 Registry] + Race_Global --> Selected_Mirror + + subgraph "静态资源 (BVM 源码)" + UserRequest --> jsDelivr[cdn.jsdelivr.net] + jsDelivr --> Fastly[Fastly Edge] + jsDelivr --> Cloudflare[Cloudflare Edge] + end +``` + +### 5.2 实施规则 + +1. **Geo-Location (IP 探测):** 访问 `https://1.1.1.1/cdn-cgi/trace` 获取用户地理位置 (`loc=CN`)。设置 500ms 超时,快速失败。 +2. **Race Strategy (竞速策略):** 对候选源(npmmirror, tencent, npmjs)并发发起 `HEAD` 请求,选用响应最快的源。 +3. **资源托管:** BVM 不维护自己的后端。所有二进制文件均来源: + * **BVM 逻辑:** GitHub Repo -> jsDelivr CDN。 + * **Bun Runtimes:** 官方 NPM 包 (`@oven/bun-...`) -> 智能选定的 Registry。 +4. **零配置:** 用户无需手动设置 `BVM_MIRROR`。系统“默认智能”。 + +--- + +## 6. 已知限制与技术债 (Known Issues) + +### 6.1 Shim 性能与实现 +* **现状:** Windows Shim (`bun.cmd`) 和 Unix Shim (`bun`) 目前调用 `bvm-shim.js` 来处理逻辑。这意味着每次运行 `bun` 命令都需要启动一次 Bun JS 运行时。 +* **影响:** 相比于原生二进制(Native)或纯 Batch/Shell 实现,存在一定的启动延迟。 +* **计划:** 未来考虑迁移到 Rust/Go 编写的 Native Shim 或纯 CMD/Bash 实现以追求极致性能。 + +### 6.2 Upgrade 命令局限性 +* **现状:** `bvm upgrade` 目前仅更新 `dist/index.js` (CLI 核心逻辑)。 +* **问题:** 它**不会**更新 `bvm-shim.js` 或 Shim 包装器脚本。如果 Shim 逻辑发生变更,用户升级后可能遇到不兼容问题。 +* **规避:** 建议用户在遇到奇怪问题时,重新运行安装脚本进行“覆盖安装”以更新所有组件。 diff --git a/website/docs/public/guide/getting-started/index.md b/website/docs/public/guide/getting-started/index.md new file mode 100644 index 0000000..7eef711 --- /dev/null +++ b/website/docs/public/guide/getting-started/index.md @@ -0,0 +1,181 @@ +# BVM — Bun Version Manager + +
+ + BVM Logo + + +

The Native, Zero-Dependency Version Manager for Bun

+ +

+ Official Website & Documentation » +
+ 中文网站 » +
+ From NPM (Start Here) » +
+ WeChat Official Account » +
+
+ 🇨🇳 中文文档 + · + Report Bug + · + Request Feature +

+ +

+ + Release + + + License + + + Platform + +

+
+ +--- + +Need to switch Bun versions across Windows, macOS, and Linux without PATH drift or global package conflicts? + +## ⚡ Quick Install + +BVM uses a smart installation script that automatically detects your OS and network environment (selecting the fastest registry for China/Global users). + +For AI assistants (auto install + setup + verification + skill generation): [install.md](./install.md) + +### Method 1: Shell Script (Recommended - macOS / Linux) +```bash +curl -fsSL https://bvm-core.pages.dev/install | bash +``` + +### Method 2: PowerShell (Recommended - Windows) +```powershell +irm https://bvm-core.pages.dev/install | iex +``` + +### Method 3: NPM (Optional) +```bash +npm install -g bvm-core@latest --foreground-scripts +``` + +--- + +## Key Features + +- **🚀 Zero Latency**: Shim-based design ensures ~0ms shell startup overhead. +- **🛡️ Bunker Architecture**: BVM manages its own isolated Bun runtime, ensuring stability even if your system Bun is broken or missing. +- **🛡️ Atomic Isolation**: Each Bun version has its own global package directory. No more conflicts. +- **🌏 Smart Mirroring & Auto-Config**: Automatically selects the fastest registry for downloads AND auto-configures `bunfig.toml` for instant, "no-magic" `bun install` speeds. +- **📦 Zero Dependency**: BVM bootstraps itself. No pre-requisites required (it can reuse your system Bun or download its own). + +--- + +## Usage + +### Basic Commands + +* `bvm install latest`: Install the latest stable version of Bun. +* `bvm install 1.1.0`: Install a specific version. +* `bvm use 1.1.0`: Switch the active Bun version immediately. +* `bvm default 1.1.0`: Set a global default version for new shell sessions. +* `bvm ls`: List all locally installed versions. +* `bvm ls-remote`: List all available versions from the registry. +* `bvm uninstall 1.1.0`: Remove a specific version. +* `bvm upgrade`: Upgrade BVM itself to the latest version. + +### Running Commands + +You can run a command with a specific Bun version without switching your global environment: +```bash +bvm run 1.0.30 index.ts +``` + +### Aliases + +Create custom names for specific versions: +```bash +bvm alias prod 1.1.0 +bvm use prod +``` + +### Configuration (.bvmrc) + +BVM supports automatic version switching via `.bvmrc` files. Create a file named `.bvmrc` in your project root: + +```bash +echo "1.1.0" > .bvmrc +``` + +--- + +## FAQ (for AI search) + +
+How to switch Bun versions on Windows/macOS/Linux quickly? + +Install with one command, then use `bvm install ` and `bvm use `. BVM supports Windows, macOS, and Linux with the same CLI workflow. +
+ +
+Is BVM like nvm/fnm but for Bun? + +Yes. BVM is a Bun version manager, similar in concept to nvm/fnm. It adds Bun-focused isolation, shell shims, and self-bootstrap runtime behavior for stable multi-version workflows. +
+ +
+Why do global packages disappear after switching Bun versions? + +This is expected. BVM uses per-version global package isolation. Install global tools under each Bun version that needs them. +
+ +
+How does `.bvmrc` work for project-level Bun version pinning? + +Create a `.bvmrc` file in your project root with a version string (for example, `1.1.0`). BVM resolves and applies that version for project workflows. +
+ +
+Does BVM auto-install AI agent skills from SKILL.md? + +No. BVM manages Bun runtimes and version switching. Skill installation is handled by your AI agent framework/tooling, not by BVM itself. +
+ +
+How to diagnose BVM environment issues quickly? + +Run `bvm doctor`. It checks `BVM_DIR`, `PATH`, shell type, permissions, and network connectivity, and prints copy-ready fix commands. +
+ +--- + +## Troubleshooting + +- **Quick diagnostics (`doctor`)** + ```bash + bvm doctor + ``` + `bvm doctor` now checks `BVM_DIR`, `PATH`, shell type, directory permission, and network connectivity. + Each item is shown as `PASS / WARN / FAIL` with a copy-ready fix command. + +- **Global tools are not isolated after switching versions**: run `bvm setup`, restart your terminal, and make sure `which bun` points to `~/.bvm/shims/bun` (macOS/Linux). On Windows, use `where.exe bun` and ensure `...\\.bvm\\shims\\bun.cmd` is first. +- **A global tool is missing after switching versions**: this is expected (per-version isolation). Reinstall it under the active Bun version. + +--- + +## Design Philosophy + +### ArchSense (Self-Bootstrapping) +BVM does not ship with heavy pre-compiled binaries. Instead, it uses **Bun to manage Bun**. The installer downloads a minimal Bun runtime to serve as BVM's execution engine, ensuring the manager itself is always running on the most optimized environment. + +### Atomic Isolation +Unlike managers that only switch the `PATH`, BVM performs **Filesystem-level Locking**. It dynamically injects a unique `BUN_INSTALL` path for every version, ensuring that global packages installed in one version never conflict with another. + +--- + +## License + +MIT © [EricLLLLLL](https://github.com/EricLLLLLL) diff --git a/website/docs/public/guide/troubleshooting/index.md b/website/docs/public/guide/troubleshooting/index.md new file mode 100644 index 0000000..e86633f --- /dev/null +++ b/website/docs/public/guide/troubleshooting/index.md @@ -0,0 +1,68 @@ +# Troubleshooting + +## 1) Global installs are not isolated (tools appear after switching versions) + +If `bun install -g` creates or uses `~/.bun`, it usually means your shell is not picking up **BVM shims first**. + +### Fix + +1. Run: + +```bash +bvm setup +``` + +2. Restart your terminal (or reload your shell config). + +3. Verify: + +```bash +which bun +``` + +Expected: it should point to `~/.bvm/shims/bun` (macOS/Linux). + +## 2) On Windows, `which` is not available + +Use PowerShell built-ins: + +```powershell +Get-Command bun +Get-Command cowsay +where.exe bun +where.exe cowsay +``` + +Expected: `where.exe bun` should list `...\.bvm\shims\bun.cmd` before `...\.bvm\current\bin\bun.exe`. + +## 3) I installed a global tool but it is not found + +BVM isolates global tools **per Bun version**. After switching versions, a global tool may be missing by design. + +### What to do + +- Reinstall it under the active version: + +```bash +bun install -g +``` + +- If your shell caches commands, refresh it: + - macOS/Linux: open a new terminal, or run `hash -r` + - Windows PowerShell: open a new PowerShell + +If needed, you can manually regenerate shims: + +```bash +bvm rehash +``` + +## 4) PowerShell script execution is blocked + +If `install.ps1` fails due to policy restrictions, run this in PowerShell: + +```powershell +Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned +``` + +Then retry the installer. diff --git a/website/docs/public/index.md b/website/docs/public/index.md new file mode 100644 index 0000000..15b13e7 --- /dev/null +++ b/website/docs/public/index.md @@ -0,0 +1,84 @@ +
+

One-Line Installation

+ + + + + +
+
+ NPM (Optional) +
+
+ {{ npmCommand }} + +
+
+
+ +
+

Install methods (choose the best fit)

+ + + + + + + + + + + + + + + + + + + + + + + + + +
MethodBest forNotes
Shell (macOS/Linux)Most usersFastest mirror + auto setup
PowerShell (Windows)Windows devSame flow as Unix installer
NPMAlready using NodeRuns postinstall; reopen terminal may be needed
+
+ +
+
+
Having trouble with global isolation?
+
If tools still come from ~/.bun, run bvm setup and verify which bun points to BVM shims.
+ Open Troubleshooting → +
+
+ +
+

Install methods (animated)

+ +
diff --git a/website/docs/public/llms-full.txt b/website/docs/public/llms-full.txt new file mode 100644 index 0000000..550147c --- /dev/null +++ b/website/docs/public/llms-full.txt @@ -0,0 +1,873 @@ +# BVM Docs — llms-full + +> Aggregated markdown context for BVM documentation. Source pages and mirror links are included per section. + +## Included Pages + +- EN · From NPM: https://bvm-core.pages.dev/from/npm +- EN · Getting Started: https://bvm-core.pages.dev/guide/getting-started +- EN · Troubleshooting: https://bvm-core.pages.dev/guide/troubleshooting +- EN · Architecture: https://bvm-core.pages.dev/guide/architecture +- EN · For AI Clients: https://bvm-core.pages.dev/for-ai-clients +- ZH · 来自 NPM: https://bvm-core.pages.dev/zh/from/npm +- ZH · 快速开始: https://bvm-core.pages.dev/zh/guide/getting-started +- ZH · 排障: https://bvm-core.pages.dev/zh/guide/troubleshooting +- ZH · 架构: https://bvm-core.pages.dev/zh/guide/architecture +- ZH · AI 客户端接入: https://bvm-core.pages.dev/zh/for-ai-clients + +--- + +## From NPM (EN) + +- URL: https://bvm-core.pages.dev/from/npm +- Mirror: https://bvm-core.pages.dev/from/npm/index.md + +# Welcome from npm + +You’re here because you found `bvm-core` on npm. This page is the shortest path to: + +- Verify your install +- Get your shell set up correctly +- Subscribe to updates (WeChat) + +## 1) Verify BVM is working + +```bash +bvm --version +``` + +## 2) Make Bun resolve through BVM shims + +```bash +bvm setup +``` + +Then restart your terminal and confirm: + +```bash +which bun +``` + +## 3) Next steps + +- Start here: [Getting Started](/guide/getting-started) +- If something breaks: [Troubleshooting](/guide/troubleshooting) + +## Subscribe (WeChat) + +Scan the QR code on the WeChat page: [WeChat](/wechat) + +--- + +## Getting Started (EN) + +- URL: https://bvm-core.pages.dev/guide/getting-started +- Mirror: https://bvm-core.pages.dev/guide/getting-started/index.md + +# BVM — Bun Version Manager + +
+ + BVM Logo + + +

The Native, Zero-Dependency Version Manager for Bun

+ +

+ Official Website & Documentation » +
+ 中文网站 » +
+ From NPM (Start Here) » +
+ WeChat Official Account » +
+
+ 🇨🇳 中文文档 + · + Report Bug + · + Request Feature +

+ +

+ + Release + + + License + + + Platform + +

+
+ +--- + +Need to switch Bun versions across Windows, macOS, and Linux without PATH drift or global package conflicts? + +## ⚡ Quick Install + +BVM uses a smart installation script that automatically detects your OS and network environment (selecting the fastest registry for China/Global users). + +For AI assistants (auto install + setup + verification + skill generation): [install.md](./install.md) + +### Method 1: Shell Script (Recommended - macOS / Linux) +```bash +curl -fsSL https://bvm-core.pages.dev/install | bash +``` + +### Method 2: PowerShell (Recommended - Windows) +```powershell +irm https://bvm-core.pages.dev/install | iex +``` + +### Method 3: NPM (Optional) +```bash +npm install -g bvm-core@latest --foreground-scripts +``` + +--- + +## Key Features + +- **🚀 Zero Latency**: Shim-based design ensures ~0ms shell startup overhead. +- **🛡️ Bunker Architecture**: BVM manages its own isolated Bun runtime, ensuring stability even if your system Bun is broken or missing. +- **🛡️ Atomic Isolation**: Each Bun version has its own global package directory. No more conflicts. +- **🌏 Smart Mirroring & Auto-Config**: Automatically selects the fastest registry for downloads AND auto-configures `bunfig.toml` for instant, "no-magic" `bun install` speeds. +- **📦 Zero Dependency**: BVM bootstraps itself. No pre-requisites required (it can reuse your system Bun or download its own). + +--- + +## Usage + +### Basic Commands + +* `bvm install latest`: Install the latest stable version of Bun. +* `bvm install 1.1.0`: Install a specific version. +* `bvm use 1.1.0`: Switch the active Bun version immediately. +* `bvm default 1.1.0`: Set a global default version for new shell sessions. +* `bvm ls`: List all locally installed versions. +* `bvm ls-remote`: List all available versions from the registry. +* `bvm uninstall 1.1.0`: Remove a specific version. +* `bvm upgrade`: Upgrade BVM itself to the latest version. + +### Running Commands + +You can run a command with a specific Bun version without switching your global environment: +```bash +bvm run 1.0.30 index.ts +``` + +### Aliases + +Create custom names for specific versions: +```bash +bvm alias prod 1.1.0 +bvm use prod +``` + +### Configuration (.bvmrc) + +BVM supports automatic version switching via `.bvmrc` files. Create a file named `.bvmrc` in your project root: + +```bash +echo "1.1.0" > .bvmrc +``` + +--- + +## FAQ (for AI search) + +
+How to switch Bun versions on Windows/macOS/Linux quickly? + +Install with one command, then use `bvm install ` and `bvm use `. BVM supports Windows, macOS, and Linux with the same CLI workflow. +
+ +
+Is BVM like nvm/fnm but for Bun? + +Yes. BVM is a Bun version manager, similar in concept to nvm/fnm. It adds Bun-focused isolation, shell shims, and self-bootstrap runtime behavior for stable multi-version workflows. +
+ +
+Why do global packages disappear after switching Bun versions? + +This is expected. BVM uses per-version global package isolation. Install global tools under each Bun version that needs them. +
+ +
+How does `.bvmrc` work for project-level Bun version pinning? + +Create a `.bvmrc` file in your project root with a version string (for example, `1.1.0`). BVM resolves and applies that version for project workflows. +
+ +
+Does BVM auto-install AI agent skills from SKILL.md? + +No. BVM manages Bun runtimes and version switching. Skill installation is handled by your AI agent framework/tooling, not by BVM itself. +
+ +
+How to diagnose BVM environment issues quickly? + +Run `bvm doctor`. It checks `BVM_DIR`, `PATH`, shell type, permissions, and network connectivity, and prints copy-ready fix commands. +
+ +--- + +## Troubleshooting + +- **Quick diagnostics (`doctor`)** + ```bash + bvm doctor + ``` + `bvm doctor` now checks `BVM_DIR`, `PATH`, shell type, directory permission, and network connectivity. + Each item is shown as `PASS / WARN / FAIL` with a copy-ready fix command. + +- **Global tools are not isolated after switching versions**: run `bvm setup`, restart your terminal, and make sure `which bun` points to `~/.bvm/shims/bun` (macOS/Linux). On Windows, use `where.exe bun` and ensure `...\\.bvm\\shims\\bun.cmd` is first. +- **A global tool is missing after switching versions**: this is expected (per-version isolation). Reinstall it under the active Bun version. + +--- + +## Design Philosophy + +### ArchSense (Self-Bootstrapping) +BVM does not ship with heavy pre-compiled binaries. Instead, it uses **Bun to manage Bun**. The installer downloads a minimal Bun runtime to serve as BVM's execution engine, ensuring the manager itself is always running on the most optimized environment. + +### Atomic Isolation +Unlike managers that only switch the `PATH`, BVM performs **Filesystem-level Locking**. It dynamically injects a unique `BUN_INSTALL` path for every version, ensuring that global packages installed in one version never conflict with another. + +--- + +## License + +MIT © [EricLLLLLL](https://github.com/EricLLLLLL) + +--- + +## Troubleshooting (EN) + +- URL: https://bvm-core.pages.dev/guide/troubleshooting +- Mirror: https://bvm-core.pages.dev/guide/troubleshooting/index.md + +# Troubleshooting + +## 1) Global installs are not isolated (tools appear after switching versions) + +If `bun install -g` creates or uses `~/.bun`, it usually means your shell is not picking up **BVM shims first**. + +### Fix + +1. Run: + +```bash +bvm setup +``` + +2. Restart your terminal (or reload your shell config). + +3. Verify: + +```bash +which bun +``` + +Expected: it should point to `~/.bvm/shims/bun` (macOS/Linux). + +## 2) On Windows, `which` is not available + +Use PowerShell built-ins: + +```powershell +Get-Command bun +Get-Command cowsay +where.exe bun +where.exe cowsay +``` + +Expected: `where.exe bun` should list `...\.bvm\shims\bun.cmd` before `...\.bvm\current\bin\bun.exe`. + +## 3) I installed a global tool but it is not found + +BVM isolates global tools **per Bun version**. After switching versions, a global tool may be missing by design. + +### What to do + +- Reinstall it under the active version: + +```bash +bun install -g +``` + +- If your shell caches commands, refresh it: + - macOS/Linux: open a new terminal, or run `hash -r` + - Windows PowerShell: open a new PowerShell + +If needed, you can manually regenerate shims: + +```bash +bvm rehash +``` + +## 4) PowerShell script execution is blocked + +If `install.ps1` fails due to policy restrictions, run this in PowerShell: + +```powershell +Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned +``` + +Then retry the installer. + +--- + +## Architecture (EN) + +- URL: https://bvm-core.pages.dev/guide/architecture +- Mirror: https://bvm-core.pages.dev/guide/architecture/index.md + +# BVM 架构与流程文档 + +> **定位**: 本文档是 BVM 内部架构、安装流程和发布机制的单一真实来源。它既设计为供 AI 代理阅读(作为 Knowledge Base),也供人类贡献者参考。 + +## 1. 安装逻辑 (`install.sh`, `install.ps1`, `postinstall.js`) + +BVM 采用“自引导(Bootstrap)”安装模式,并引入了“地堡架构 (Bunker Architecture)”:BVM 拥有自己专用的、隔离的 Bun 运行时,不依赖于用户当前正在使用的 Bun 版本。 + +### 1.1 标准安装流水线 (所有脚本通用) + +无论通过何种方式安装,BVM 都遵循以下标准流程: + +1. **资产部署**: 下载并提取 BVM 核心源码 (`index.js`) 和 Shims。 +2. **系统 Bun 探测**: 检查系统 `PATH` 中是否已有 `bun` 可执行文件。 +3. **冒烟测试 (Smoke Test)**: + * 若存在系统 Bun,尝试运行 `bun index.js --version`。 + * **通过**: 说明该 Bun 兼容,可直接复用。 + * **失败**: 说明该 Bun 无法驱动 BVM(版本过旧或不兼容)。 +4. **运行时配置**: + * **复用模式**: 若通过测试,将系统 Bun 注册到 `versions/vX.Y.Z`。 + * **下载模式**: 若未通过测试或无系统 Bun,下载官方推荐的稳定版并安装到 `versions/vLatest`。 +5. **地堡激活 (Bunker Setup)**: + * 设置 `runtime/current` 指向选定的 Bun 版本(私有运行时)。 + * 设置 `current` 软链接指向该版本(初始用户版本)。 + * 设置 `default` 别名。 +6. **环境对齐**: 运行 `bvm setup` 将 BVM 路径追加到用户 Profile **末尾**,确保 BVM 优先级最高。 + +### 1.2 NPM 全局安装 (`postinstall.js`) + +当用户运行 `npm install -g bvm-core` 时触发。 + +* **品牌化输出**: 显示 ASCII Logo 和安装进度。 +* **自检逻辑**: 自动执行上述 1.1 的流程。 +* **零配置使用**: 安装后自动提示 `source ~/.zshrc` 以立即生效。 + +### 1.3 Unix 安装流程 (`install.sh`) + +```mermaid +graph TD + Start(用户运行 install.sh) --> Geo{IP 探测} + Geo --> SetRegistry[选定最快源] + SetRegistry --> DownloadBVM[下载 BVM 源码] + DownloadBVM --> SmokeTest{系统 Bun 冒烟测试?} + + SmokeTest -- 通过 --> Reuse[复用系统 Bun] + SmokeTest -- 失败 --> DownloadRuntime[下载兼容版 Bun] + + Reuse --> LinkBunker[建立地堡: runtime/current] + DownloadRuntime --> LinkBunker + + LinkBunker --> CreateWrappers[创建包装器 & Shims] + CreateWrappers --> RunSetup[运行 'bvm setup' 覆盖 PATH] + RunSetup --> End(安装完成) +``` + +### 1.4 Windows 安装流程 (`install.ps1`) + +```mermaid +graph TD + Start(用户运行 install.ps1) --> PreClean[清理旧 Shims] + PreClean --> DownloadSrc[下载 BVM 核心资产] + DownloadSrc --> SmokeTest{系统 Bun 兼容性测试?} + + SmokeTest -- 成功 --> Reuse[复用系统 Bun (Junction)] + SmokeTest -- 失败 --> DownloadBun[下载 Windows 版 Bun] + + Reuse --> LinkBunker[建立地堡: runtime/current] + DownloadBun --> LinkBunker + + LinkBunker --> CreateShims[创建 .cmd Shims] + CreateShims --> ModPath[更新用户 PATH (末尾追加)] + ModPath --> RunSetup[Profile 对齐] + RunSetup --> End(安装完成) +``` + +**关键架构变更:** +* **版本前缀**: 强制使用 `vX.Y.Z` 格式(如 `v1.3.6`)。 +* **双重链接**: + * `~/.bvm/runtime/current` -> 私有宿主 (Private Host)。 + * `~/.bvm/current` -> 用户当前活跃版本 (Active Version)。 +* **隔离性**: BVM 自身的命令现在优先使用 `runtime/current` 运行,实现了管理器与被管理版本的完全解耦。 + +--- + +## 2. 命令实现流程 + +BVM 使用一个轻量级的 Router 来分发命令。架构上将“CLI 入口”与“命令逻辑”分离。 + +### 2.1 CLI 架构 + +```mermaid +graph LR + UserInput(bvm install 1.0.0) --> Router[src/index.ts: App.run()] + Router --> ParseArgs[util.parseArgs] + ParseArgs --> MatchCommand{匹配命令?} + + MatchCommand -- 是 --> ActionHandler[执行 Action] + MatchCommand -- 否 --> ShowHelp[显示帮助] + + ActionHandler --> CommandFunc[例如: commands/install.ts: installBunVersion] + CommandFunc --> Utils[工具库: npm-lookup, ui, etc.] + + subgraph Execution Context + Utils --> BunRuntime[Bun Runtime (Current)] + end +``` + +### 2.2 命令映射表 + +| 命令 | 文件路径 | 描述 | +| :--- | :--- | :--- | +| `install` | `src/commands/install.ts` | 从 NPM Registry 下载并解压 Bun 版本。 | +| `use` | `src/commands/use.ts` | 更新 `~/.bvm/runtime/current` 软链接。 | +| `ls-remote` | `src/commands/ls-remote.ts` | 从 NPM Registry 获取可用版本 (`npm view`)。 | +| `alias` | `src/commands/alias.ts` | 在 `~/.bvm/aliases/` 中创建命名软链接。 | +| `setup` | `src/commands/setup.ts` | 检测 Shell 并修改 `.rc` 文件或 PowerShell Profile。 | +| `upgrade` | `src/commands/upgrade.ts` | 从 CDN 重新下载最新的 BVM 源代码。 | + +--- + +## 3. 测试策略与环境 + +BVM 采用双层测试策略,确保内部逻辑正确性和端到端(E2E)的可靠性。 + +### 3.1 测试金字塔 + +```mermaid +block-beta + columns 1 + block:E2E + E2E_Tests["E2E 测试 (execa + sandbox)"] + end + block:Unit + Unit_Tests["单元测试 (bun:test)"] + end +``` + +### 3.2 测试规范 + +| 级别 | 范围 | 工具 | 位置 | 环境要求 | +| :--- | :--- | :--- | :--- | :--- | +| **Unit** | 内部逻辑 (`semver`, `npm-lookup`, `utils`) | `bun:test` | `test/*.test.ts` | 已安装 `bun`。 | +| **E2E** | 完整 CLI 工作流, 文件系统, Shell 配置 | `execa`, `bun:test` | `test/e2e/*.test.ts` | `bun`, `pwsh` (用于在 macOS/Linux 上测试 Windows 逻辑)。 | + +### 3.3 CI 集成 (`.github/workflows/ci.yml`) + +每次 Push 或 PR 到 `main` 分支时自动运行测试。 +* **矩阵:** `ubuntu-latest`, `macos-latest`, `windows-latest`。 +* **命令:** `bun test test/e2e` (环境变量 `CI=true`)。 + +--- + +## 4. 发布流程与集成 + +发布流程通过 GitHub Actions 完全自动化,确保安装脚本始终指向有效的 Artifacts。 + +### 4.1 发布流水线 (`auto-release.yml`) + +```mermaid +sequenceDiagram + participant User + participant Git as GitHub (Repo) + participant Action as GitHub Actions + participant NPM as NPM Registry + participant CDN as jsDelivr + + User->>Git: Push to main (package.json 版本变更) + Git->>Action: 触发 'check-and-release' + Action->>Action: 检查 Tag 是否存在 + + alt Tag 已存在 + Action->>Action: 停止 + else 新版本 + Action->>Action: bun install & bun run build + Action->>Git: 提交 'dist/' 产物 (skip ci) + Action->>Git: 创建 Tag (v1.2.3) + Action->>Git: 推送 Tag + Action->>Git: 创建 GitHub Release (上传 install.sh/ps1) + + Action->>CDN: 清除缓存 (Purge API) + Note over CDN: /dist/index.js, /install.sh, etc. + end +``` + +### 4.2 产物耦合 + +* **安装脚本源:** `install.sh` 和 `install.ps1` 从 `cdn.jsdelivr.net` 下载 `index.js` 和 `bvm-shim.sh`。 +* **版本控制:** URL 中包含版本 Tag: `.../gh/EricLLLLLL/bvm@v1.0.6/dist/index.js`。 +* **自更新:** `bvm upgrade` 命令通过 GitHub API 获取 `latest` Tag 来确定新版本,然后下载新的源代码。 + +--- + +## 5. 全球加速与镜像方法论 + +BVM 旨在实现全球范围内的“0ms 延迟”和“高可用性”。 + +### 5.1 架构 + +```mermaid +graph TD + UserRequest[用户请求] --> Geo{Cloudflare IP 探测} + Geo -- CN --> Race_CN[竞速: 淘宝, 腾讯, 官方] + Geo -- Global --> Race_Global[竞速: 官方, 淘宝] + + Race_CN --> Selected_Mirror[选定 Registry] + Race_Global --> Selected_Mirror + + subgraph "静态资源 (BVM 源码)" + UserRequest --> jsDelivr[cdn.jsdelivr.net] + jsDelivr --> Fastly[Fastly Edge] + jsDelivr --> Cloudflare[Cloudflare Edge] + end +``` + +### 5.2 实施规则 + +1. **Geo-Location (IP 探测):** 访问 `https://1.1.1.1/cdn-cgi/trace` 获取用户地理位置 (`loc=CN`)。设置 500ms 超时,快速失败。 +2. **Race Strategy (竞速策略):** 对候选源(npmmirror, tencent, npmjs)并发发起 `HEAD` 请求,选用响应最快的源。 +3. **资源托管:** BVM 不维护自己的后端。所有二进制文件均来源: + * **BVM 逻辑:** GitHub Repo -> jsDelivr CDN。 + * **Bun Runtimes:** 官方 NPM 包 (`@oven/bun-...`) -> 智能选定的 Registry。 +4. **零配置:** 用户无需手动设置 `BVM_MIRROR`。系统“默认智能”。 + +--- + +## 6. 已知限制与技术债 (Known Issues) + +### 6.1 Shim 性能与实现 +* **现状:** Windows Shim (`bun.cmd`) 和 Unix Shim (`bun`) 目前调用 `bvm-shim.js` 来处理逻辑。这意味着每次运行 `bun` 命令都需要启动一次 Bun JS 运行时。 +* **影响:** 相比于原生二进制(Native)或纯 Batch/Shell 实现,存在一定的启动延迟。 +* **计划:** 未来考虑迁移到 Rust/Go 编写的 Native Shim 或纯 CMD/Bash 实现以追求极致性能。 + +### 6.2 Upgrade 命令局限性 +* **现状:** `bvm upgrade` 目前仅更新 `dist/index.js` (CLI 核心逻辑)。 +* **问题:** 它**不会**更新 `bvm-shim.js` 或 Shim 包装器脚本。如果 Shim 逻辑发生变更,用户升级后可能遇到不兼容问题。 +* **规避:** 建议用户在遇到奇怪问题时,重新运行安装脚本进行“覆盖安装”以更新所有组件。 + +--- + +## For AI Clients (EN) + +- URL: https://bvm-core.pages.dev/for-ai-clients +- Mirror: https://bvm-core.pages.dev/for-ai-clients/index.md + +# For AI Clients + +This page is the fastest path to let AI clients install and use BVM correctly with repeatable behavior. + +## 1) Give AI the installer playbook + +Pass this link directly to your AI client: + +`https://raw.githubusercontent.com/EricLLLLLL/bvm/main/install.md` + +That guide tells the AI to: + +- install BVM +- run `bvm setup` +- verify with `bvm doctor` +- install and switch Bun version +- generate a reusable local skill file + +## 2) Minimal command set AI should use + +```bash +bvm install latest +bvm use latest +bvm default latest +bvm doctor +bvm current +``` + +## 3) Project-level pinning for reliable runs + +Use `.bvmrc` in repo root: + +```bash +echo "1.3.6" > .bvmrc +``` + +Then AI should execute: + +```bash +bvm use "$(cat .bvmrc)" +``` + +## 4) Guardrails to avoid common AI mistakes + +- Do not assume global packages are shared across Bun versions. +- If command resolution is wrong, run `bvm setup` first. +- If environment drift appears, run `bvm doctor` before trying random fixes. +- Prefer full version strings (for example `1.3.6`) when installing. + +## 5) LLM context endpoints + +- Index: `/llms.txt` +- Full context: `/llms-full.txt` +- Markdown mirrors: `//index.md` (for example `/guide/getting-started/index.md`) + +--- + +## 来自 NPM (ZH) + +- URL: https://bvm-core.pages.dev/zh/from/npm +- Mirror: https://bvm-core.pages.dev/zh/from/npm/index.md + +# 欢迎从 NPM 进入 + +你大概率是在 npm 上看到 `bvm-core` 后点进来的。这一页给你最短路径: + +- 快速验证安装是否成功 +- 正确完成 shell setup +- 关注公众号获取更新 + +## 1)验证是否可用 + +```bash +bvm --version +``` + +## 2)让 Bun 通过 BVM shims 生效 + +```bash +bvm setup +``` + +重启终端后确认: + +```bash +which bun +``` + +## 3)下一步 + +- 快速开始:[Getting Started](/zh/guide/getting-started) +- 出问题先看:[Troubleshooting](/zh/guide/troubleshooting) + +## 订阅更新(公众号) + +去公众号页扫码关注:[公众号](/zh/wechat) + +--- + +## 快速开始 (ZH) + +- URL: https://bvm-core.pages.dev/zh/guide/getting-started +- Mirror: https://bvm-core.pages.dev/zh/guide/getting-started/index.md + +# BVM — Bun 版本管理器 + +## 安装 + +### 方式 1:Shell(macOS / Linux,推荐) + +```bash +curl -fsSL https://bvm-core.pages.dev/install | bash +``` + +### 方式 2:PowerShell(Windows,推荐) + +```powershell +irm https://bvm-core.pages.dev/install | iex +``` + +### 方式 3:NPM(可选) + +```bash +npm install -g bvm-core@latest --foreground-scripts +``` + +安装完成后建议: + +1. 重启终端(或重新加载 shell 配置) +2. 运行 `bvm --version` 验证 +3. 如果全局包隔离不生效,先执行一次 `bvm setup`(见「排障」) + +## 常用命令 + +- `bvm install latest`:安装最新稳定版 Bun +- `bvm install 1.3.3`:安装指定版本 +- `bvm use 1.3.3`:立即切换活跃版本(全终端生效) +- `bvm shell 1.3.3`:仅对当前 shell 会话生效 +- `bvm default 1.3.3`:设置全局默认版本 +- `bvm ls`:查看本地已安装 +- `bvm uninstall 1.3.3`:卸载版本 +- `bvm upgrade`:升级 bvm 本身 + +## 全局包隔离(你需要知道的) + +- `bun install -g` 安装的全局命令是 **按 Bun 版本隔离** 的。 +- 切换版本后看不到之前的全局命令是正常的(你需要在新版本下重新装一次)。 +- `bvm` 会在必要时自动 `rehash`,但你也可以手动运行 `bvm rehash` 重新生成 shims。 + +--- + +## 排障 (ZH) + +- URL: https://bvm-core.pages.dev/zh/guide/troubleshooting +- Mirror: https://bvm-core.pages.dev/zh/guide/troubleshooting/index.md + +# 排障 + +## 1)全局包没有隔离(切换版本后还有 pm2/cowsay 等) + +如果 `bun install -g` 写到了 `~/.bun`,通常说明当前 shell 没有优先命中 **BVM shims**。 + +### 修复 + +1. 运行: + +```bash +bvm setup +``` + +2. 重启终端(或重新加载 shell 配置) + +3. 验证(macOS/Linux): + +```bash +which bun +``` + +期望:指向 `~/.bvm/shims/bun`。 + +## 2)Windows 没有 `which` + +用 PowerShell 的命令: + +```powershell +Get-Command bun +Get-Command cowsay +where.exe bun +where.exe cowsay +``` + +期望:`where.exe bun` 里 `...\ .bvm\shims\bun.cmd` 排在 `...\ .bvm\current\bin\bun.exe` 前面。 + +## 3)安装了全局工具但找不到 + +BVM 的全局工具是 **按 Bun 版本隔离** 的。切换版本后找不到是预期行为。 + +### 处理方式 + +- 在当前版本下重新安装: + +```bash +bun install -g +``` + +- 必要时手动重建 shims: + +```bash +bvm rehash +``` + +## 4)PowerShell 执行策略拦截安装脚本 + +如果 `install.ps1` 被策略阻止,可以在 PowerShell 里执行: + +```powershell +Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned +``` + +再重试安装。 + +--- + +## 架构 (ZH) + +- URL: https://bvm-core.pages.dev/zh/guide/architecture +- Mirror: https://bvm-core.pages.dev/zh/guide/architecture/index.md + +# BVM 架构与流程文档 + +> **定位**: 本文档是 BVM 内部架构、安装流程和发布机制的单一真实来源。它既设计为供 AI 代理阅读(作为 Knowledge Base),也供人类贡献者参考。 + +本页与 `/guide/architecture` 内容一致,专门提供在中文站点 `/zh/` 下的稳定路径,便于中英文同域部署与语言切换。 + +- 继续阅读:请访问 `/guide/architecture` + +--- + +## AI 客户端接入 (ZH) + +- URL: https://bvm-core.pages.dev/zh/for-ai-clients +- Mirror: https://bvm-core.pages.dev/zh/for-ai-clients/index.md + +# AI 客户端接入 + +这页用于让 AI 客户端稳定安装并正确使用 BVM,减少误操作。 + +## 1)先把安装手册丢给 AI + +直接给 AI 这个链接: + +`https://raw.githubusercontent.com/EricLLLLLL/bvm/main/install.md` + +该手册会要求 AI: + +- 安装 BVM +- 执行 `bvm setup` +- 用 `bvm doctor` 验证 +- 安装并切换 Bun 版本 +- 生成可复用的本地 Skill 文件 + +## 2)AI 应优先使用的最小命令集 + +```bash +bvm install latest +bvm use latest +bvm default latest +bvm doctor +bvm current +``` + +## 3)用 `.bvmrc` 固定项目版本 + +在仓库根目录: + +```bash +echo "1.3.6" > .bvmrc +``` + +然后让 AI 执行: + +```bash +bvm use "$(cat .bvmrc)" +``` + +## 4)避免 AI 常见误区 + +- 不要假设全局包在不同 Bun 版本之间共享。 +- 命令路径不对时,先执行 `bvm setup`。 +- 环境异常先跑 `bvm doctor`,不要直接盲改。 +- 安装时优先写完整版本号(例如 `1.3.6`)。 + +## 5)LLM 上下文入口 + +- 索引:`/llms.txt` +- 全量聚合:`/llms-full.txt` +- Markdown 镜像:`//index.md`(例如 `/guide/getting-started/index.md`) + diff --git a/website/docs/public/llms.txt b/website/docs/public/llms.txt new file mode 100644 index 0000000..2c60e6e --- /dev/null +++ b/website/docs/public/llms.txt @@ -0,0 +1,32 @@ +# BVM Documentation + +> LLM-friendly index for BVM docs. Use page Markdown mirrors (`/xxx/index.md`) for cleaner context, or use the full aggregate file. + +## Primary Context + +- [LLMs Full Context](https://bvm-core.pages.dev/llms-full.txt): Full combined documentation for retrieval and long-context models. + +## English Docs + +- [Home](https://bvm-core.pages.dev/): Mirror at [/index.md](https://bvm-core.pages.dev/index.md) +- [From NPM](https://bvm-core.pages.dev/from/npm): Mirror at [/from/npm/index.md](https://bvm-core.pages.dev/from/npm/index.md) +- [WeChat](https://bvm-core.pages.dev/wechat): Mirror at [/wechat/index.md](https://bvm-core.pages.dev/wechat/index.md) +- [Getting Started](https://bvm-core.pages.dev/guide/getting-started): Mirror at [/guide/getting-started/index.md](https://bvm-core.pages.dev/guide/getting-started/index.md) +- [Troubleshooting](https://bvm-core.pages.dev/guide/troubleshooting): Mirror at [/guide/troubleshooting/index.md](https://bvm-core.pages.dev/guide/troubleshooting/index.md) +- [Architecture](https://bvm-core.pages.dev/guide/architecture): Mirror at [/guide/architecture/index.md](https://bvm-core.pages.dev/guide/architecture/index.md) +- [For AI Clients](https://bvm-core.pages.dev/for-ai-clients): Mirror at [/for-ai-clients/index.md](https://bvm-core.pages.dev/for-ai-clients/index.md) + +## 中文文档 + +- [首页](https://bvm-core.pages.dev/zh/): 镜像 [/zh/index.md](https://bvm-core.pages.dev/zh/index.md) +- [来自 NPM](https://bvm-core.pages.dev/zh/from/npm): 镜像 [/zh/from/npm/index.md](https://bvm-core.pages.dev/zh/from/npm/index.md) +- [公众号](https://bvm-core.pages.dev/zh/wechat): 镜像 [/zh/wechat/index.md](https://bvm-core.pages.dev/zh/wechat/index.md) +- [快速开始](https://bvm-core.pages.dev/zh/guide/getting-started): 镜像 [/zh/guide/getting-started/index.md](https://bvm-core.pages.dev/zh/guide/getting-started/index.md) +- [排障](https://bvm-core.pages.dev/zh/guide/troubleshooting): 镜像 [/zh/guide/troubleshooting/index.md](https://bvm-core.pages.dev/zh/guide/troubleshooting/index.md) +- [架构](https://bvm-core.pages.dev/zh/guide/architecture): 镜像 [/zh/guide/architecture/index.md](https://bvm-core.pages.dev/zh/guide/architecture/index.md) +- [AI 客户端接入](https://bvm-core.pages.dev/zh/for-ai-clients): 镜像 [/zh/for-ai-clients/index.md](https://bvm-core.pages.dev/zh/for-ai-clients/index.md) + +## Optional + +- [GitHub Repository](https://github.com/EricLLLLLL/bvm) +- [AI Installer Guide](https://github.com/EricLLLLLL/bvm/blob/main/install.md) diff --git a/website/docs/public/media/wechat-qrcode-npm.svg b/website/docs/public/media/wechat-qrcode-npm.svg new file mode 100644 index 0000000..8a61530 --- /dev/null +++ b/website/docs/public/media/wechat-qrcode-npm.svg @@ -0,0 +1,18 @@ + + + + + WeChat QR Code + NPM Channel + Replace this placeholder + with your channel QR + + + + + website/docs/public/media + /wechat-qrcode-npm.svg + + + + diff --git a/website/docs/public/media/wechat-qrcode.svg b/website/docs/public/media/wechat-qrcode.svg new file mode 100644 index 0000000..5c0933b --- /dev/null +++ b/website/docs/public/media/wechat-qrcode.svg @@ -0,0 +1,17 @@ + + + + + WeChat QR Code + Replace this placeholder + with your Official Account QR + + + + + website/docs/public/media + /wechat-qrcode.svg + + + + diff --git a/website/docs/public/wechat/index.md b/website/docs/public/wechat/index.md new file mode 100644 index 0000000..8b34fd5 --- /dev/null +++ b/website/docs/public/wechat/index.md @@ -0,0 +1,26 @@ +# WeChat Official Account + +Follow the BVM WeChat Official Account (公众号) to get: + +- Release notes and breaking changes +- Troubleshooting playbooks (Windows/macOS/Linux) +- Mirror/registry strategy updates (CN/Global) + +## Scan to follow + +> Replace the placeholder image with your real QR code: +> `website/docs/public/media/wechat-qrcode.svg` + +
+ BVM WeChat QR Code +
+ +## Coming from NPM? + +If you reached here from the npm package page, use the “NPM channel” QR code for better attribution: + +> Replace: `website/docs/public/media/wechat-qrcode-npm.svg` + +
+ BVM WeChat QR Code (NPM Channel) +
diff --git a/website/docs/public/zh/for-ai-clients/index.md b/website/docs/public/zh/for-ai-clients/index.md new file mode 100644 index 0000000..19fe08a --- /dev/null +++ b/website/docs/public/zh/for-ai-clients/index.md @@ -0,0 +1,54 @@ +# AI 客户端接入 + +这页用于让 AI 客户端稳定安装并正确使用 BVM,减少误操作。 + +## 1)先把安装手册丢给 AI + +直接给 AI 这个链接: + +`https://raw.githubusercontent.com/EricLLLLLL/bvm/main/install.md` + +该手册会要求 AI: + +- 安装 BVM +- 执行 `bvm setup` +- 用 `bvm doctor` 验证 +- 安装并切换 Bun 版本 +- 生成可复用的本地 Skill 文件 + +## 2)AI 应优先使用的最小命令集 + +```bash +bvm install latest +bvm use latest +bvm default latest +bvm doctor +bvm current +``` + +## 3)用 `.bvmrc` 固定项目版本 + +在仓库根目录: + +```bash +echo "1.3.6" > .bvmrc +``` + +然后让 AI 执行: + +```bash +bvm use "$(cat .bvmrc)" +``` + +## 4)避免 AI 常见误区 + +- 不要假设全局包在不同 Bun 版本之间共享。 +- 命令路径不对时,先执行 `bvm setup`。 +- 环境异常先跑 `bvm doctor`,不要直接盲改。 +- 安装时优先写完整版本号(例如 `1.3.6`)。 + +## 5)LLM 上下文入口 + +- 索引:`/llms.txt` +- 全量聚合:`/llms-full.txt` +- Markdown 镜像:`//index.md`(例如 `/guide/getting-started/index.md`) diff --git a/website/docs/public/zh/from/npm/index.md b/website/docs/public/zh/from/npm/index.md new file mode 100644 index 0000000..fddad4e --- /dev/null +++ b/website/docs/public/zh/from/npm/index.md @@ -0,0 +1,34 @@ +# 欢迎从 NPM 进入 + +你大概率是在 npm 上看到 `bvm-core` 后点进来的。这一页给你最短路径: + +- 快速验证安装是否成功 +- 正确完成 shell setup +- 关注公众号获取更新 + +## 1)验证是否可用 + +```bash +bvm --version +``` + +## 2)让 Bun 通过 BVM shims 生效 + +```bash +bvm setup +``` + +重启终端后确认: + +```bash +which bun +``` + +## 3)下一步 + +- 快速开始:[Getting Started](/zh/guide/getting-started) +- 出问题先看:[Troubleshooting](/zh/guide/troubleshooting) + +## 订阅更新(公众号) + +去公众号页扫码关注:[公众号](/zh/wechat) diff --git a/website/docs/public/zh/guide/architecture/index.md b/website/docs/public/zh/guide/architecture/index.md new file mode 100644 index 0000000..c3fb7e8 --- /dev/null +++ b/website/docs/public/zh/guide/architecture/index.md @@ -0,0 +1,7 @@ +# BVM 架构与流程文档 + +> **定位**: 本文档是 BVM 内部架构、安装流程和发布机制的单一真实来源。它既设计为供 AI 代理阅读(作为 Knowledge Base),也供人类贡献者参考。 + +本页与 `/guide/architecture` 内容一致,专门提供在中文站点 `/zh/` 下的稳定路径,便于中英文同域部署与语言切换。 + +- 继续阅读:请访问 `/guide/architecture` diff --git a/website/docs/public/zh/guide/getting-started/index.md b/website/docs/public/zh/guide/getting-started/index.md new file mode 100644 index 0000000..8a88ae6 --- /dev/null +++ b/website/docs/public/zh/guide/getting-started/index.md @@ -0,0 +1,44 @@ +# BVM — Bun 版本管理器 + +## 安装 + +### 方式 1:Shell(macOS / Linux,推荐) + +```bash +curl -fsSL https://bvm-core.pages.dev/install | bash +``` + +### 方式 2:PowerShell(Windows,推荐) + +```powershell +irm https://bvm-core.pages.dev/install | iex +``` + +### 方式 3:NPM(可选) + +```bash +npm install -g bvm-core@latest --foreground-scripts +``` + +安装完成后建议: + +1. 重启终端(或重新加载 shell 配置) +2. 运行 `bvm --version` 验证 +3. 如果全局包隔离不生效,先执行一次 `bvm setup`(见「排障」) + +## 常用命令 + +- `bvm install latest`:安装最新稳定版 Bun +- `bvm install 1.3.3`:安装指定版本 +- `bvm use 1.3.3`:立即切换活跃版本(全终端生效) +- `bvm shell 1.3.3`:仅对当前 shell 会话生效 +- `bvm default 1.3.3`:设置全局默认版本 +- `bvm ls`:查看本地已安装 +- `bvm uninstall 1.3.3`:卸载版本 +- `bvm upgrade`:升级 bvm 本身 + +## 全局包隔离(你需要知道的) + +- `bun install -g` 安装的全局命令是 **按 Bun 版本隔离** 的。 +- 切换版本后看不到之前的全局命令是正常的(你需要在新版本下重新装一次)。 +- `bvm` 会在必要时自动 `rehash`,但你也可以手动运行 `bvm rehash` 重新生成 shims。 diff --git a/website/docs/public/zh/guide/troubleshooting/index.md b/website/docs/public/zh/guide/troubleshooting/index.md new file mode 100644 index 0000000..8eea7cf --- /dev/null +++ b/website/docs/public/zh/guide/troubleshooting/index.md @@ -0,0 +1,64 @@ +# 排障 + +## 1)全局包没有隔离(切换版本后还有 pm2/cowsay 等) + +如果 `bun install -g` 写到了 `~/.bun`,通常说明当前 shell 没有优先命中 **BVM shims**。 + +### 修复 + +1. 运行: + +```bash +bvm setup +``` + +2. 重启终端(或重新加载 shell 配置) + +3. 验证(macOS/Linux): + +```bash +which bun +``` + +期望:指向 `~/.bvm/shims/bun`。 + +## 2)Windows 没有 `which` + +用 PowerShell 的命令: + +```powershell +Get-Command bun +Get-Command cowsay +where.exe bun +where.exe cowsay +``` + +期望:`where.exe bun` 里 `...\ .bvm\shims\bun.cmd` 排在 `...\ .bvm\current\bin\bun.exe` 前面。 + +## 3)安装了全局工具但找不到 + +BVM 的全局工具是 **按 Bun 版本隔离** 的。切换版本后找不到是预期行为。 + +### 处理方式 + +- 在当前版本下重新安装: + +```bash +bun install -g +``` + +- 必要时手动重建 shims: + +```bash +bvm rehash +``` + +## 4)PowerShell 执行策略拦截安装脚本 + +如果 `install.ps1` 被策略阻止,可以在 PowerShell 里执行: + +```powershell +Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned +``` + +再重试安装。 diff --git a/website/docs/public/zh/index.md b/website/docs/public/zh/index.md new file mode 100644 index 0000000..f7b00bc --- /dev/null +++ b/website/docs/public/zh/index.md @@ -0,0 +1,84 @@ +
+

一键安装

+ + + + + +
+
+ NPM(可选) +
+
+ {{ npmCommand }} + +
+
+
+ +
+

安装方式对比(怎么选)

+ + + + + + + + + + + + + + + + + + + + + + + + + +
方式适合谁备注
Shell(macOS/Linux)大多数用户自动竞速选最快源 + 自动 setup
PowerShell(Windows)Windows 开发与 Unix 安装体验一致
NPM已在用 Node/NPM依赖 postinstall;可能需要重开终端
+
+ +
+
+
全局隔离不生效?
+
如果命令仍来自 ~/.bun,请运行一次 bvm setup,然后检查 which bun 是否命中 BVM shims。
+ 打开排障文档 → +
+
+ +
+

安装方式对比(动画)

+ +
diff --git a/website/docs/public/zh/wechat/index.md b/website/docs/public/zh/wechat/index.md new file mode 100644 index 0000000..1f1d79b --- /dev/null +++ b/website/docs/public/zh/wechat/index.md @@ -0,0 +1,27 @@ +# BVM 微信公众号 + +关注公众号可以获得: + +- 版本更新与破坏性变更提醒 +- 排障手册(Windows / macOS / Linux) +- 镜像/registry 策略变化(国内/海外) + +## 扫码关注 + +> 请将占位图替换为真实二维码: +> `website/docs/public/media/wechat-qrcode.svg` + +
+ BVM 微信公众号二维码 +
+ +## 从 NPM 来的? + +如果你从 npm 包页面进来,建议使用 “NPM 渠道码” 方便归因: + +> 请将占位图替换为真实渠道码: +> `website/docs/public/media/wechat-qrcode-npm.svg` + +
+ BVM 微信公众号二维码(NPM 渠道) +
diff --git a/website/docs/wechat.md b/website/docs/wechat.md new file mode 100644 index 0000000..c3c71b1 --- /dev/null +++ b/website/docs/wechat.md @@ -0,0 +1,46 @@ +--- +title: WeChat +description: Follow BVM on WeChat Official Account +--- + +# WeChat Official Account + +Follow the BVM WeChat Official Account (公众号) to get: + +- Release notes and breaking changes +- Troubleshooting playbooks (Windows/macOS/Linux) +- Mirror/registry strategy updates (CN/Global) + +## Scan to follow + +> Replace the placeholder image with your real QR code: +> `website/docs/public/media/wechat-qrcode.svg` + +
+ BVM WeChat QR Code +
+ +## Coming from NPM? + +If you reached here from the npm package page, use the “NPM channel” QR code for better attribution: + +> Replace: `website/docs/public/media/wechat-qrcode-npm.svg` + +
+ BVM WeChat QR Code (NPM Channel) +
+ + + diff --git a/website/docs/zh/for-ai-clients.md b/website/docs/zh/for-ai-clients.md new file mode 100644 index 0000000..d8171a4 --- /dev/null +++ b/website/docs/zh/for-ai-clients.md @@ -0,0 +1,60 @@ +--- +title: AI 客户端接入 +description: 面向 Claude/Copilot/Cursor/Codex 等 AI 客户端的快速接入指南 +--- + +# AI 客户端接入 + +这页用于让 AI 客户端稳定安装并正确使用 BVM,减少误操作。 + +## 1)先把安装手册丢给 AI + +直接给 AI 这个链接: + +`https://raw.githubusercontent.com/EricLLLLLL/bvm/main/install.md` + +该手册会要求 AI: + +- 安装 BVM +- 执行 `bvm setup` +- 用 `bvm doctor` 验证 +- 安装并切换 Bun 版本 +- 生成可复用的本地 Skill 文件 + +## 2)AI 应优先使用的最小命令集 + +```bash +bvm install latest +bvm use latest +bvm default latest +bvm doctor +bvm current +``` + +## 3)用 `.bvmrc` 固定项目版本 + +在仓库根目录: + +```bash +echo "1.3.6" > .bvmrc +``` + +然后让 AI 执行: + +```bash +bvm use "$(cat .bvmrc)" +``` + +## 4)避免 AI 常见误区 + +- 不要假设全局包在不同 Bun 版本之间共享。 +- 命令路径不对时,先执行 `bvm setup`。 +- 环境异常先跑 `bvm doctor`,不要直接盲改。 +- 安装时优先写完整版本号(例如 `1.3.6`)。 + +## 5)LLM 上下文入口 + +- 索引:`/llms.txt` +- 全量聚合:`/llms-full.txt` +- Markdown 镜像:`//index.md`(例如 `/guide/getting-started/index.md`) + diff --git a/website/docs/zh/from/npm.md b/website/docs/zh/from/npm.md new file mode 100644 index 0000000..7981c2b --- /dev/null +++ b/website/docs/zh/from/npm.md @@ -0,0 +1,40 @@ +--- +title: 来自 NPM +description: 从 npm 进入 BVM 的下一步 +--- + +# 欢迎从 NPM 进入 + +你大概率是在 npm 上看到 `bvm-core` 后点进来的。这一页给你最短路径: + +- 快速验证安装是否成功 +- 正确完成 shell setup +- 关注公众号获取更新 + +## 1)验证是否可用 + +```bash +bvm --version +``` + +## 2)让 Bun 通过 BVM shims 生效 + +```bash +bvm setup +``` + +重启终端后确认: + +```bash +which bun +``` + +## 3)下一步 + +- 快速开始:[Getting Started](/zh/guide/getting-started) +- 出问题先看:[Troubleshooting](/zh/guide/troubleshooting) + +## 订阅更新(公众号) + +去公众号页扫码关注:[公众号](/zh/wechat) + diff --git a/website/docs/zh/wechat.md b/website/docs/zh/wechat.md new file mode 100644 index 0000000..e4f6634 --- /dev/null +++ b/website/docs/zh/wechat.md @@ -0,0 +1,47 @@ +--- +title: 公众号 +description: 关注 BVM 微信公众号 +--- + +# BVM 微信公众号 + +关注公众号可以获得: + +- 版本更新与破坏性变更提醒 +- 排障手册(Windows / macOS / Linux) +- 镜像/registry 策略变化(国内/海外) + +## 扫码关注 + +> 请将占位图替换为真实二维码: +> `website/docs/public/media/wechat-qrcode.svg` + +
+ BVM 微信公众号二维码 +
+ +## 从 NPM 来的? + +如果你从 npm 包页面进来,建议使用 “NPM 渠道码” 方便归因: + +> 请将占位图替换为真实渠道码: +> `website/docs/public/media/wechat-qrcode-npm.svg` + +
+ BVM 微信公众号二维码(NPM 渠道) +
+ + + diff --git a/website/generate-ai-docs.ts b/website/generate-ai-docs.ts new file mode 100644 index 0000000..e9e037c --- /dev/null +++ b/website/generate-ai-docs.ts @@ -0,0 +1,165 @@ +import { mkdir, readFile, writeFile } from 'node:fs/promises'; +import { dirname, join } from 'node:path'; + +type DocPage = { + source: string; + route: string; + title: string; + locale: 'en' | 'zh'; + includeInFull?: boolean; +}; + +const docsRoot = join(import.meta.dir, 'docs'); +const publicRoot = join(docsRoot, 'public'); + +const docPages: DocPage[] = [ + { source: 'index.md', route: '/', title: 'Home', locale: 'en', includeInFull: false }, + { source: 'from/npm.md', route: '/from/npm', title: 'From NPM', locale: 'en' }, + { source: 'wechat.md', route: '/wechat', title: 'WeChat', locale: 'en', includeInFull: false }, + { source: 'guide/getting-started.md', route: '/guide/getting-started', title: 'Getting Started', locale: 'en' }, + { source: 'guide/troubleshooting.md', route: '/guide/troubleshooting', title: 'Troubleshooting', locale: 'en' }, + { source: 'guide/architecture.md', route: '/guide/architecture', title: 'Architecture', locale: 'en' }, + { source: 'for-ai-clients.md', route: '/for-ai-clients', title: 'For AI Clients', locale: 'en' }, + { source: 'zh/index.md', route: '/zh/', title: '首页', locale: 'zh', includeInFull: false }, + { source: 'zh/from/npm.md', route: '/zh/from/npm', title: '来自 NPM', locale: 'zh' }, + { source: 'zh/wechat.md', route: '/zh/wechat', title: '公众号', locale: 'zh', includeInFull: false }, + { source: 'zh/guide/getting-started.md', route: '/zh/guide/getting-started', title: '快速开始', locale: 'zh' }, + { source: 'zh/guide/troubleshooting.md', route: '/zh/guide/troubleshooting', title: '排障', locale: 'zh' }, + { source: 'zh/guide/architecture.md', route: '/zh/guide/architecture', title: '架构', locale: 'zh' }, + { source: 'zh/for-ai-clients.md', route: '/zh/for-ai-clients', title: 'AI 客户端接入', locale: 'zh' }, +]; + +function stripFrontmatter(markdown: string): string { + if (!markdown.startsWith('---\n')) { + return markdown.trim(); + } + const end = markdown.indexOf('\n---\n', 4); + if (end === -1) { + return markdown.trim(); + } + return markdown.slice(end + 5).trim(); +} + +function sanitizeMarkdown(markdown: string): string { + const withoutScripts = markdown.replace(//gi, ''); + const withoutStyles = withoutScripts.replace(//gi, ''); + return withoutStyles.replace(/\n{3,}/g, '\n\n').trim(); +} + +function routeToMirrorPath(route: string): string { + const normalized = route.replace(/^\//, '').replace(/\/$/, ''); + if (!normalized) { + return join(publicRoot, 'index.md'); + } + return join(publicRoot, normalized, 'index.md'); +} + +function joinUrl(base: string, path: string): string { + return `${base}${path}`; +} + +async function ensureParentDir(filePath: string): Promise { + await mkdir(dirname(filePath), { recursive: true }); +} + +async function generateMirrors(siteUrl: string): Promise> { + const outputs: Array<{ page: DocPage; content: string; mirrorUrl: string; pageUrl: string }> = []; + + for (const page of docPages) { + const sourcePath = join(docsRoot, page.source); + const raw = await readFile(sourcePath, 'utf8'); + const content = sanitizeMarkdown(stripFrontmatter(raw)); + const mirrorPath = routeToMirrorPath(page.route); + + await ensureParentDir(mirrorPath); + await writeFile(mirrorPath, `${content}\n`, 'utf8'); + + const pageUrl = joinUrl(siteUrl, page.route === '/' ? '/' : page.route); + const mirrorUrl = joinUrl(siteUrl, page.route === '/' ? '/index.md' : `${page.route.replace(/\/$/, '')}/index.md`); + outputs.push({ page, content, mirrorUrl, pageUrl }); + } + + return outputs; +} + +function buildLlmsTxt(entries: Array<{ page: DocPage; mirrorUrl: string; pageUrl: string }>, siteUrl: string): string { + const enEntries = entries.filter((entry) => entry.page.locale === 'en'); + const zhEntries = entries.filter((entry) => entry.page.locale === 'zh'); + + const lines: string[] = []; + lines.push('# BVM Documentation'); + lines.push(''); + lines.push('> LLM-friendly index for BVM docs. Use page Markdown mirrors (`/xxx/index.md`) for cleaner context, or use the full aggregate file.'); + lines.push(''); + lines.push('## Primary Context'); + lines.push(''); + lines.push(`- [LLMs Full Context](${siteUrl}/llms-full.txt): Full combined documentation for retrieval and long-context models.`); + lines.push(''); + lines.push('## English Docs'); + lines.push(''); + for (const entry of enEntries) { + lines.push(`- [${entry.page.title}](${entry.pageUrl}): Mirror at [${entry.page.route === '/' ? '/index.md' : `${entry.page.route.replace(/\/$/, '')}/index.md`}](${entry.mirrorUrl})`); + } + lines.push(''); + lines.push('## 中文文档'); + lines.push(''); + for (const entry of zhEntries) { + lines.push(`- [${entry.page.title}](${entry.pageUrl}): 镜像 [${entry.page.route.replace(/\/$/, '')}/index.md](${entry.mirrorUrl})`); + } + lines.push(''); + lines.push('## Optional'); + lines.push(''); + lines.push(`- [GitHub Repository](https://github.com/EricLLLLLL/bvm)`); + lines.push(`- [AI Installer Guide](https://github.com/EricLLLLLL/bvm/blob/main/install.md)`); + + return `${lines.join('\n')}\n`; +} + +function buildLlmsFull(entries: Array<{ page: DocPage; content: string; pageUrl: string; mirrorUrl: string }>): string { + const fullEntries = entries.filter((entry) => entry.page.includeInFull !== false); + const lines: string[] = []; + lines.push('# BVM Docs — llms-full'); + lines.push(''); + lines.push('> Aggregated markdown context for BVM documentation. Source pages and mirror links are included per section.'); + lines.push(''); + lines.push('## Included Pages'); + lines.push(''); + for (const entry of fullEntries) { + lines.push(`- ${entry.page.locale.toUpperCase()} · ${entry.page.title}: ${entry.pageUrl}`); + } + lines.push(''); + + for (const entry of fullEntries) { + lines.push('---'); + lines.push(''); + lines.push(`## ${entry.page.title} (${entry.page.locale.toUpperCase()})`); + lines.push(''); + lines.push(`- URL: ${entry.pageUrl}`); + lines.push(`- Mirror: ${entry.mirrorUrl}`); + lines.push(''); + lines.push(entry.content); + lines.push(''); + } + + return `${lines.join('\n')}\n`; +} + +async function main(): Promise { + const siteUrl = 'https://bvm-core.pages.dev'; + const entries = await generateMirrors(siteUrl); + + const llmsTxtPath = join(publicRoot, 'llms.txt'); + const llmsFullPath = join(publicRoot, 'llms-full.txt'); + + await writeFile(llmsTxtPath, buildLlmsTxt(entries, siteUrl), 'utf8'); + await writeFile(llmsFullPath, buildLlmsFull(entries), 'utf8'); + + console.log(`✅ Generated ${entries.length} markdown mirrors`); + console.log('✅ Generated website/docs/public/llms.txt'); + console.log('✅ Generated website/docs/public/llms-full.txt'); +} + +main().catch((err) => { + console.error('❌ AI docs generation failed:', err instanceof Error ? err.message : String(err)); + process.exit(1); +}); diff --git a/website/package.json b/website/package.json index 6e60612..fa65131 100644 --- a/website/package.json +++ b/website/package.json @@ -5,8 +5,9 @@ "private": true, "scripts": { "sync-docs": "bun run sync-docs.ts", - "dev": "bun run sync-docs && vitepress dev docs", - "build": "bun run sync-docs && vitepress build docs", + "gen:ai-docs": "bun run generate-ai-docs.ts", + "dev": "bun run sync-docs && bun run gen:ai-docs && vitepress dev docs", + "build": "bun run sync-docs && bun run gen:ai-docs && vitepress build docs", "preview": "vitepress preview docs", "gen:favicons": "node scripts/generate-favicons.mjs", "gen:og": "node scripts/generate-og.mjs",