Repository navigation
fix: stop setup from deleting vaults and fix agent config generation - #16
Merged
Merged
Conversation
Data safety - setup.sh no longer runs `rm -rf` on an existing vault. It used to do so at step 1, before Node.js and npm were checked, so any later failure left the user with nothing. An existing directory now offers "keep notes, refresh rules/skills" (new --keep-existing, reuses upgrade.sh) or "rename old dir as backup, then create" (what --overwrite-existing now does). All file changes happen in step 5. - Dangerous-path check resolves `..` and symlinks and also blocks Desktop, Documents, Downloads and friends. - uninstall.sh --remove-vault only deletes a directory that contains AGENTS.md and wiki/, and refuses HOME / Desktop. - upgrade.sh keeps a user-edited AI_CONFIG.md and writes the new template to AI_CONFIG.md.new; skills and helper scripts are synced one by one instead of `rsync --delete`, so user-added files survive. Config correctness - `--provider skip` aborted setup: write_agent_config returned 1 under `set -e`, so the plugin config and final instructions never ran. - Claude Code now uses the Anthropic-compatible endpoints of Zhipu, DeepSeek and OpenRouter (it was given OpenAI-compatible URLs). OpenAI / Google are rejected up front instead of writing a config with an empty base URL. - OpenCode / Claude Code / Pi JSON configs are merged via node instead of overwritten, so existing settings (permissions, hooks, other providers) survive, and keys with quotes or backslashes cannot break the JSON. Files holding API keys and their backups are chmod 600. - Codex: `model` holds only the model name (was `provider/model`), Anthropic / Google get their OpenAI-compatible base URLs, dead code removed, and the API key is no longer echoed to the terminal. - User-level skills (~/.codex/skills, ~/.pi/skills) are no longer nested under skills/skill when the directory already exists. Robustness - An OpenCLI install failure no longer aborts the whole setup. - sudo is used only when the npm global directory is not writable; failures suggest the npmmirror registry. - Interactive provider input is validated. - upgrade.sh / uninstall.sh detect the agent from the vault when --agent is omitted instead of silently assuming opencode. - opencode-obsidian-doctor.sh no longer crashes on macOS /bin/bash 3.2 (mapfile, empty array under set -u). - Braced variables that are followed by full-width punctuation, which bash 3.2 otherwise reads as part of the variable name. Tests and docs - Add tests/smoke-test.sh: runs setup / upgrade / uninstall / doctor in a throwaway HOME with stubbed npm, agent CLIs and sudo (13 scenarios). - CI runs it on Linux and with macOS /bin/bash 3.2. - Update CHANGELOG, README (zh/en), GUIDE_FOR_AI.md and the troubleshooting docs to match.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 变更描述 / Change Description
修复
setup.sh会删除用户已有知识库的问题,以及各 agent 配置生成中的几处错误;新增端到端冒烟测试,CI 覆盖 macOS 自带的/bin/bash3.2。最严重的问题:重跑 setup 会删掉笔记
目录已存在时选「覆盖」,脚本会
rm -rf整个知识库,而且是在第 1 步——检查 Node.js、安装依赖之前。后面任何一步失败,用户就什么都不剩了。README 和 GUIDE_FOR_AI.md 推荐给 AI 代部署用的--overwrite-existing也走这条路,而 docs/agents.md 写的是「切换 agent 不会删除笔记」。现在目录已存在时三选一:
--keep-existing,复用upgrade.sh)<目录>.backup-时间戳,再新建(--overwrite-existing现在是这个行为)所有文件操作挪到第 5 步,依赖装好之后才执行。
配置生成的错误
--provider skip会让 setup 中途退出:write_agent_config跳过时返回 1,在set -e下直接终止,Obsidian 插件配置和最后的说明都不会生成。README 里的 dry-run 示例就会触发。Claude Code 连不上第三方:智谱 / DeepSeek / OpenRouter 写的是 OpenAI 兼容地址。改为各自的 Anthropic 兼容端点:
ANTHROPIC_BASE_URLhttps://open.bigmodel.cn/api/anthropichttps://api.deepseek.com/anthropichttps://openrouter.ai/apiOpenAI / Google 没有这种端点,之前会生成
ANTHROPIC_BASE_URL: ""的配置,现在开始前直接拒绝。~/.claude/settings.json被整个覆盖:用户的权限、hooks 等只剩在备份里。OpenCode / Claude Code / Pi 的 JSON 配置现在用 node 合并写入,只改模型和 Key;也解决了 Key 里有引号、反斜杠会写坏 JSON 的问题。含 Key 的文件和备份权限改为 600。Codex:
model写成了provider/model;Anthropic / Google 的base_url为空;有一段被立即覆盖的死代码;配置完成后在终端明文打印 API Key(README 让用户截图终端报错发 Issue)。用户级技能目录:
~/.codex/skills已存在时,cp -R会把技能嵌套复制到skills/skill/;upgrade.sh的rsync --delete会清掉用户自己装的其他技能。改为按技能名逐个同步。其他
upgrade.sh每次都用模板覆盖AI_CONFIG.md(头部注释写的是「逐字段保留」)。现在用户改过就原样保留,新模板另存为AI_CONFIG.md.new;与模板历史版本完全一致(从没改过)的直接更新。upgrade.sh/uninstall.sh不传--agent时默认 opencode,Claude Code 用户会升级或卸载错对象。改为按 vault 自动识别,识别不了就要求显式指定。uninstall.sh --remove-vault没有路径保护。现在只删含AGENTS.md和wiki/的目录,并拒绝主目录、桌面等。opencode-obsidian-doctor.sh在 bash 3.2 下崩溃(mapfile不存在;空数组在set -u下报错)。verify.sh(doctor 只适用于 opencode-obsidian)。🏷️ 变更类型 / Type of Change
--keep-existing)🧪 测试清单 / Testing Checklist
测试详情 / Testing Details
新增
tests/smoke-test.sh:在临时 HOME 里运行真实脚本,用桩命令替代 npm、各 agent CLI 和 sudo,不联网、不碰真实配置。共 13 组场景:settings.json、Key 不出现在输出里);Pi 没有单独的配置用例--provider skip能跑完--overwrite-existing改名备份、--keep-existing保留笔记并切换 agent、不带参数时拒绝处理已有目录桌面/..--dry-run不写任何文件upgrade.sh自动识别 agent、刷新技能、保留用户技能、补回缺失文件uninstall.sh --remove-vault拒绝非知识库目录、正常删除真知识库在 macOS
/bin/bash3.2.57 下全部通过。测试过程中还发现一个 bash 3.2 特有的问题:$VAR后面紧跟全角标点(如$AGENT_CHOICE()时,全角字符的第一个字节会被当成变量名的一部分,报 unbound variable。已改成${VAR},并确认脚本里没有其他同类写法。CI 新增
macos-system-bashjob,专门用/bin/bash3.2 跑冒烟测试——普通用户在 Mac 上实际用的就是它,而原有的 Ubuntu job 用的是 bash 5,覆盖不到。如果是,请说明 / If yes, please explain:
--overwrite-existing:从「删除旧目录」改为「旧目录改名备份」。旧目录会留在<目录>.backup-时间戳,需要时手动删除。upgrade.sh/uninstall.sh不传--agent时不再默认 opencode:按 vault 自动识别,识别不了(codex / pi)会报错要求指定。README 示例本来就带--agent,不受影响。--agent claude-code配--provider openai|google现在直接报错(之前生成的配置本来就用不了)。upgrade.sh不再覆盖用户改过的AI_CONFIG.md,新模板写到AI_CONFIG.md.new。model改为别名opus(始终指向最新的 Opus),不再固定版本号。📝 补充说明 / Additional Notes
没有真机验证的部分:冒烟测试只检查生成的配置内容,没有真的连接各服务商。上面三个 Anthropic 兼容端点建议用真实 Key 各试一次。
这个 PR 没有改的(发现了但无法核实,留给维护者判断):
setup.sh顶部注释写的是 2026-06 核对)~/.pi/config.json和~/.pi/skills路径可能与 Pi 实际的目录结构不一致data.json的字段名(cliPathsByHost等)没有对照插件源码核实~/.zshrc里的变量,插件内可能无法认证✅ 提交前检查 / Pre-Submission Checklist
👥 审核者注意 / For Reviewers
建议重点看:
setup.sh第 1 步和第 5 步:目录处理从「立即删除」改为「先决定、后执行」update_json_file():所有 JSON 配置都经过它,用 node 读取-合并-写回scripts/upgrade.sh的is_unmodified_template_copy():用 git 历史判断用户是否改过AI_CONFIG.md;仓库不是 git clone(ZIP 下载)时一律按「改过」处理