Repository navigation
fix(hooks): CLI 优先使用自身依赖而非宿主 PYTHONPATH - #74
Merged
Merged
Conversation
Hermes 钩子继承它自己的 PYTHONPATH,Keepygaga 会加载为 Python 3.14 构建的 pydantic_core,导致 Profile 和 Preferences 注入失败。CLI 在加载依赖前去掉这个变量 及其 sys.path 项,钩子始终使用随 Keepygaga 安装的依赖。 同时把 Python 3.14 加入 CI 矩阵和分类器。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
按评审意见修正:路径规范化后再比较,宿主路径挪到末尾而不是删除,与自身 site-packages 重合时不再崩溃,也不再修改 os.environ。测试改用真实配置并断言注入成功。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
评审记录
Findings
定向复核在 验证
剩余风险
|
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.
问题
Hermes 的
pre_llm_call钩子每次都报cannot import name 'ArgsKwargs' from 'pydantic_core._pydantic_core',Profile 和 Preferences 注入失败。Hermes 跑在 Python 3.14 上,并用
PYTHONPATH指向自己的依赖目录,钩子继承了这个变量。Keepygaga 跑在 3.12 上时会加载 3.14 版的pydantic_core,二进制模块加载失败。把 Keepygaga 升到 3.14 后报错会消失,但钩子实际用的是 Hermes 的pydantic和mcp,问题只是被掩盖。改动
main()开头把PYTHONPATH对应的项挪到sys.path末尾,路径规范化后再比较。cli.py顶层只导入标准库,第三方依赖都在这之后才加载。写入宿主配置的钩子命令不变。site-packages重合时不会崩溃。docs/hooks/hermes.md补充这一行为。验证
pytest都是 364 通过、4 跳过;ruff check、pyright、scripts/smoke_mcp_server.py通过。PYTHONPATH、在 3.12 环境运行:注入正常,pydantic来自 Keepygaga 自己的环境。未覆盖
keepygaga-mcp入口没有这层处理,它在模块顶层就导入mcp和pydantic。Hermes 下 MCP 一直正常,这个入口要改需另开任务。PYTHONPATH同时含宿主依赖和自身site-packages时,宿主路径仍排在前面。🤖 Generated with Claude Code