RuntimeLoop 44 参数构造函数收进 config dataclass(不拆类;排 #97 之后) #105
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
RuntimeLoop有 42 个方法、43 个构造参数(全部 keyword-only,构造函数本身约 100 行纯搬运self._x = x)。其中一大批字段只被恰好一个方法读(实测,精确名单以实现期按下方类型规则过滤后为准):
_typing_base_delay/_typing_per_char_delay/_typing_energy_jitter只给_typing_delay;_recall_half_life_seconds/_recall_weights只给_scored_events;_familiarity_*三个只给run;_delegate_max_rounds只给_run_delegated_task……它们不是对象状态,是被提升到构造函数的 config 常量。 这是 Ousterhout 意义上的宽接口——一个 43 参数的构造函数,是这个类对外最宽的那一面。
为什么这不是「拆 RuntimeLoop」
明确不拆类。 结构实测的结论是
RuntimeLoop是真深模块:6 个公开方法 / 42 个方法(run/run_callback/run_light/run_environment_signal/run_immediate_followup/assemble_context,其余 36 个只被类内调用);16 个工具 handler 共享同一个_TurnState,而那是 ADR-0012 pre-send regime 的真不变量(send_message本轮只入队不发,同轮self_recall/edit要在真发出前拦下改写)。拆开就得把_TurnState+_storage+_egress+_capabilities全部跨新边界传——把深模块换成浅模块。三份独立评估方案在这一点上罕见地一致。本票只收窄构造接口,一行业务逻辑都不动。
爆炸半径(已实测,很小)
RuntimeLoop(全仓只有 2 个构造点:src/nonebot_plugin_arise/loop_factory.py(_build_runtime_loop内)__init__.py搬到这里,模块 docstring 已点名本票)tests/runtime_loop_helpers.py(make_loop内)20 个测试文件用的是
make_loop,不直接构造RuntimeLoop。所以改动 = 签名 + 2 个调用点 + 内部读改成self._config.x,机械且可控。Acceptance criteria
reflection.ReflectionCycleConfig既有先例——那次正是把可调参数收进 config 对象)。llm_client/egress/storage/embedding_client/persona/get_tools/sleep/silence_window/delegate_task_registry/delegate_llm_client(原例子誤把它和delegate_max_rounds并列,它是LLMClient依赖,不是调参常量)/report_recalled_events/report_pending_intents(回调)/interaction_renderers(host 注入的 registry,tag_renderers同理但它是多方法读,本来就不在候选里)。Config/env 派生的标量、frozenset,以及像recall_weights、fallback_multimodal_models这样由 config 组装出的复合值对象。RuntimeLoop的 6 个公开方法签名一行不改(run/run_callback/run_light/run_environment_signal/run_immediate_followup/assemble_context);42 个方法的行为一行不改。make_loop保持既有的「可选 kwarg + 内部默认值兜底」形状,不改变它返回的元组签名(issue #55 建立的先例:给RuntimeLoop加必需参数时,测试侧靠make_loop兜底,20 个测试文件不受影响)。Not in scope
RuntimeLoop类(理由见上,三份评估一致)。storage.py(#97 已判:只买可导航性,不够格;重评触发条件见 #97 评论)。__init__.py的拆分本身(#97 的任务一,已落地)。