Repository navigation
fix(byted-web-search): .env 回退路径不再硬编码 ~/.openclaw,新增 XDG 通用路径 - #267
Open
AbelWangYaBo wants to merge 2 commits into
Open
AbelWangYaBo wants to merge 2 commits into
AbelWangYaBo wants to merge 2 commits into
Conversation
The .env fallback paths were hardcoded to OpenClaw-private directories (/root/.openclaw/.env and ~/.openclaw/.env). Together with the skill-root .env -- which lives in a directory managed by the skills CLI and may be wiped on update -- non-OpenClaw users had no agent-agnostic, update-safe place to put WEB_SEARCH_API_KEY. This matters because agents launched as daemons (launchd-managed gateways, GUI apps) do not inherit shell exports, so the currently documented `export WEB_SEARCH_API_KEY` approach does not work for them. Add $XDG_CONFIG_HOME/byted-web-search/.env (falling back to ~/.config/byted-web-search/.env), keeping the existing paths. Because loading uses os.environ.setdefault (first wins), precedence is unchanged for existing OpenClaw users: ~/.openclaw/.env > /root/.openclaw/.env > $XDG_CONFIG_HOME/... Verified with a clean environment (env -i, no shell inheritance): - XDG path only -> key loaded - ~/.openclaw/.env only -> key loaded (backwards compatible) - both present -> OpenClaw wins, behavior unchanged - custom XDG_CONFIG_HOME -> key loaded - none present -> reports missing credentials A cwd .env was deliberately not added: agents may invoke the script from arbitrary project directories, which would let any repository inject environment variables. AI-assisted commit
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.
问题
byted-web-search的.env回退路径硬编码为 OpenClaw 私有目录:配合 skill 根目录
.env(scripts/web_search.py:430),共三处。对非 OpenClaw 用户而言:前两处无效;第三处位于受
skillsCLI 管理的目录内,更新时可能被清除。结果是没有任何一个「跨 Agent 且不被 update 覆盖」的配置位置可用。
影响场景
以守护进程方式启动的 Agent(如 launchd 拉起的网关、GUI 启动的桌面客户端)不继承 shell 中 export 的环境变量,
因此
references/setup-guide.md中「export WEB_SEARCH_API_KEY写入~/.bashrc」的建议对这些 Agent 不生效。修复
新增 XDG 通用路径
$XDG_CONFIG_HOME/byted-web-search/.env(未设置时回落~/.config/byted-web-search/.env),原有路径全部保留。由于加载采用
os.environ.setdefault(先到先得),优先级为:原路径仍排在前面,既有 OpenClaw 用户行为完全不变。同时补充了
references/setup-guide.md的配置说明。验证
在
env -i干净环境下(零 shell 继承,模拟守护进程场景)实测:$XDG_CONFIG_HOME/byted-web-search/.env~/.openclaw/.envXDG_CONFIG_HOME未采纳的方案
不新增 cwd 的
.env:Agent 可能在任意项目目录下调用脚本,从 cwd 读取.env会让任意仓库具备注入环境变量的能力。Generated with AI assistance