P2 规划插件 — 在用户 prompt 提交前强制 LLM 先生成结构化 Plan。
实现「先规划后执行」模式,核心能力:
- plan_first:
:before_prompthook 返回{:intervene, directive, state}, 让 LLM 在执行任务前先产出 markdown checklist - 自动解析:
:after_responsehook 尝试用CMDC.Plan.from_markdown/2把 LLM 回复解析成CMDC.Plan结构 - 持续感知:成功解析后通过
{:update_system_context, :plan, section}emit,把Plan.to_prompt_section/1注入到state.dynamic_context_sections, 后续每轮 LLM 调用 system prompt 都会包含 plan 的当前进度 - 事件广播:emit
{:plan_generated, plan}供外部监控/UI 订阅
配置
{CMDC.Plugin.Builtin.Planning,
plan_first: true, # 是否在 prompt 前强制生成 plan
min_prompt_length: 20, # prompt 长度阈值(太短不触发)
directive: "请先把任务拆成 markdown checklist...", # 可选,覆盖默认指令
max_plan_attempts: 2 # 解析失败最多尝试次数
}触发 Hook
:before_prompt— 用户 prompt 提交前,注入规划指令:after_response— 收到 LLM 回复,解析为 Plan
与 Reflection 插件的配合
典型组合:先 Planning(priority 200)→ 执行 → Reflection(priority 400) 评审,整体形成 ADP 推荐的 Plan → Execute → Reflect → Replan 闭环。