Conversation
MaiBot 1.2 起 Host 会为插件分配统一持久化目录 (data/plugins/<plugin_id>/),并对源码目录下的 data/ 打印旧式用法警告。 本插件此前无视 ctx.paths,把数据写死在 plugins/<dir>/data/,导致: - 每次启动触发 "检测到旧式数据目录" 警告; - 数据落在插件源码树内,git pull / 重装 / 重新 clone 会连带丢失 (实测本机已有 16 条 goals)。 改动: - plugin.py: on_load 解析 ctx.paths.data_dir 并缓存到 _data_dir; 另加一次性迁移——旧 data/ 存在且目标无 goals.db 时整体复制过去 (复制而非移动,旧文件保留作回退;失败不阻断加载)。 同时用统一目录初始化 GoalManager 单例,否则各 service 经 get_goal_manager() 会写回旧目录。 - get_goal_manager() 增加可选 data_dir 参数(仅在首次创建单例时生效)。 - schedule_generator / cleanup_service / tools_service: llm_logs 目录 改从 _data_dir 取。 - auto_scheduler: next_day_prompt.json 缓存改从 _data_dir 取。 - schedule_image_generator: generate_schedule_image 增加 output_dir 参数, 由 command_service 传入 _data_dir/images。 无 ctx(单测/standalone) 时全部回退源码 data/,行为不变。 插件自带 20 项冒烟测试全通过。
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.
问题
MaiBot 1.2 起 Host 会为插件分配统一持久化目录,并在插件源码目录存在
data/时于每次启动打印:Host 只警告、不迁移(
src/plugin_runtime/runner/runner_main.py:793),规范做法是插件读取self.ctx.paths.data_dir(由plugin_paths.py:46分配)。但本插件全仓库未引用过ctx.paths,路径写死在:结果:
data/plugins/<plugin_id>/虽然被 Host 建出来了,但始终为空,警告每次启动必现;git pull、重装或重新 clone 就会连带丢失。本机实测旧库已有 16 条 goals;goals.db并继续使用它。除
goals.db外,还有 4 处数据/产物同样挂在源码目录:llm_logs/(3 处调用点)、next_day_prompt.json、images/schedule_today.jpg。改动
plugin.py:on_load改为解析ctx.paths.data_dir并缓存到self._data_dir(__init__先给源码目录兜底,保证单测/standalone 行为不变)。新增一次性迁移_migrate_legacy_data():旧data/存在且目标尚无goals.db时整体复制过去——用复制而非移动,旧文件保留作回退,迁移失败只告警、不阻断加载。plugin.py:用统一目录初始化GoalManager单例。这一步必须做——各 service 都经get_goal_manager()取单例,若不在on_load固定其数据位置,仍会写回旧目录。planner/goal_manager.py:get_goal_manager()增加可选data_dir参数,仅在首次创建单例时生效。schedule_generator.py/cleanup_service.py/tools_service.py:llm_logs目录改从_data_dir取。planner/auto_scheduler.py:next_day_prompt.json缓存改从_data_dir取。utils/schedule_image_generator.py:generate_schedule_image()增加output_dir参数,由command_service传入_data_dir/images。无
ctx(单测 / standalone)时全部回退源码目录data/,现有用法不受影响。验证
tests/run_smoke.py,20/20)。spec_from_file_location+submodule_search_locations)导入插件、注入真实PluginContext,做了两层验证:_resolve_data_dir的优先级与回退、迁移的复制语义与幂等性(目标已存在则不覆盖)、以及on_load后goals.db确实落在统一目录、GoalManager单例绑定正确。pragma integrity_check = ok,16 条 goals 与目标名逐一比对一致,llm_logs19 个文件全部到位。备注
本 PR 只含上述改动,不含仓库既有工作区里那份
model=→task_name=的本地修复(对应 #18)。合并后首次启动会自动把旧
data/复制到统一目录;确认无误后即可手动删除源码目录下的data/,警告随之消失。