feat(runtime):增加build/plan模式#519
Merged
pionxe merged 6 commits into1024XEngineer:mainfrom May 1, 2026
Merged
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
Completed 4-pass review (code quality, performance, security, documentation).
Noteworthy findings:
- A strict JSON extraction path can fail the whole run when assistant output contains braces or a
"task_completion"mention but no valid JSON object. - Compaction detection now scans and renders the entire transcript on every session load, which can become expensive for long histories.
No additional security or documentation-accuracy issues were identified beyond the inline comments.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Collaborator
Author
|
/code 提高测试覆盖率,并提交PR到fork仓库 |
完成情况已按你的要求提升测试覆盖率并推送到 fork。 本次改动
验证
提交与推送
|
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
test: improve coverage for plan/build runtime changes
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.
Summary
本次改动围绕新增正式的
plan/build后端机制展开,目标是在现有主链路上补齐一套可落地、可持久化、可复用的 planning 语义,让系统不仅能执行任务,也能稳定承载“规划”“计划复用”“计划审批”和“计划完成收口”。本次改动只涉及后端链路:
sessionruntimecontextpromptasset本次不修改
TUI和gateway的现有 contract,只先把后端接口、状态和运行语义补齐。原来存在的问题
当前后端缺少正式的
plan/build模式。系统原本只有统一的执行主链路,没有一套明确的 planning 领域模型、运行阶段语义和 prompt 注入机制来表达下面这些能力:
这意味着“规划”只能散落在消息历史里,无法作为稳定的会话对象被保存、复用和收口,也无法为后续上层接入提供可靠后端基础。
采取的解决方案
本次方案的核心是:
AgentMode表达当前工作模式CurrentPlan表达当前完整计划SummaryView表达默认注入给模型的紧凑计划摘要具体语义如下:
1. 新增正式的
plan/build模式在会话层新增
AgentMode,明确区分:planbuildplan用于分析、调研、创建或重写完整计划。build用于执行任务,不负责重写完整计划。2. 新增会话级
CurrentPlan在会话层新增正式的计划模型,核心包括:
PlanArtifactPlanSpecSummaryViewPlanStatus其中:
PlanSpec表示完整计划正文SummaryView表示摘要视图PlanStatus表示计划生命周期状态Revision与LastFullPlanRevision用于判断全文是否已经重新对齐3. 明确
SummaryView的来源SummaryView不是额外维护的一份独立手写文档,而是围绕PlanSpec生成和归一化出来的紧凑投影。当前实现里,
SummaryView的来源分成两层:summary_candidatePlanSpec确定性投影出来的BuildSummaryView(...)BuildSummaryView(...)本身不是额外的智能摘要算法,而是按固定字段映射从PlanSpec生成摘要:Goal <- PlanSpec.GoalKeySteps <- PlanSpec.StepsConstraints <- PlanSpec.ConstraintsVerify <- PlanSpec.VerifyActiveTodoIDs <- PlanSpec.Todos[*].ID这样做的目的有两个:
因此,执行态默认使用的
SummaryView本质上是“由完整计划字段投影出来、且经过后端归一化兜底”的摘要,而不是另一套独立状态。4. 只允许在
plan模式创建或重写完整计划runtime 现在只会在
plan模式下消费结构化plan_spec + summary_candidate,并创建或重写CurrentPlan。build模式下即使模型输出了类似 planning JSON 的内容,也不会改写CurrentPlan,而是按普通输出处理。5. 补齐
draft / approved / completed生命周期本次把计划状态机补成正式闭环:
draft:当前计划存在,但用户尚未确认当前 revisionapproved:用户已确认当前 revisioncompleted:当前 revision 对应任务已完成并补充这些规则:
plan模式创建或重写计划时,状态统一落为draftApproveCurrentPlan(...),可将draft -> approveddraft和approved都允许在完成条件满足时进入completeddraft6. 用 runtime 状态控制完整计划注入
默认情况下,执行阶段优先注入
SummaryView,避免每轮都发送完整计划。只有在以下状态下,runtime 才会升级为 full plan 注入:
SummaryView不可用CurrentPlan.Revision > LastFullPlanRevisionPlanApprovalPendingFullAlign == truePlanCompletionPendingFullReview == truePlanContextDirty == truePlanRestorePendingAlign == true同时补齐了两类环境触发:
PlanContextDirtyPlanRestorePendingAlign7. 审批和完成后都强制做一次完整对齐
为了让“批准”和“完成”真正影响执行上下文,本次新增两种一次性全文对齐:
draft -> approved后,下一轮强制注入一次 full plancompleted后,下一轮也强制注入一次 full plan 做完成确认对齐完成后,这些一次性标记会被清理,后续回到摘要优先。
8. 收紧 plan/build 提示词
为了避免模型随意改计划,本次同步收紧了两套模板:
plan模式:build模式:plan具体修改范围
session涉及文件:
internal/session/plan.gointernal/session/plan_test.gointernal/session/store.gointernal/session/sqlite_store.gointernal/session/store_test.go本次新增或调整:
AgentModeCurrentPlanPlanArtifact / PlanSpec / SummaryView / PlanStatusLastFullPlanRevisionPlanApprovalPendingFullAlignPlanCompletionPendingFullReviewPlanContextDirtyPlanRestorePendingAlignruntime涉及文件:
internal/runtime/planning.gointernal/runtime/planning_test.gointernal/runtime/run.gointernal/runtime/runtime.gointernal/runtime/plan_approval.gointernal/runtime/runtime_test.gointernal/runtime/session_scheduler.gointernal/runtime/compact.gointernal/runtime/input_prepare.gointernal/runtime/permission.gointernal/runtime/session_mutation.gointernal/runtime/state.gointernal/runtime/budget_models.go本次新增或调整:
plan/build运行阶段判定CurrentPlan的创建、重写、审批、完成推进ApproveCurrentPlan(...)context涉及文件:
internal/context/builder.gointernal/context/builder_test.gointernal/context/source_plan_mode.gointernal/context/types.go本次新增或调整:
BuildInput中的 planning 相关字段Plan Mode和Current Plan的 prompt 投影full_plan_viewpromptasset涉及文件:
internal/promptasset/assets.gointernal/promptasset/assets_test.gointernal/promptasset/templates/context/plan_mode_plan.mdinternal/promptasset/templates/context/plan_mode_build_execute.md本次新增或调整:
plan/build模式模板入口预期收益
用户角度
1. 规划和执行第一次被正式区分
用户后续可以明确地进入“先规划,再执行”或“直接执行”的不同工作流,而不是把规划内容混在普通消息里。
2. 当前计划可以稳定保存和复用
一旦计划形成,用户后续可以围绕同一份
CurrentPlan持续执行、查看摘要、审批 revision、确认完成,而不是每次都重新描述目标。3. 执行态上下文更稳
默认走摘要注入,只有在审批、完成确认、compact 或恢复等需要重新对齐的时候才升级为 full plan,能减少上下文噪音,也更符合长任务执行体验。
4. 计划状态对用户可解释
draft / approved / completed给后续交互提供了明确语义,用户可以理解当前计划是“未确认”“已确认”还是“已完成”,而不是只看到一堆隐式历史消息。开发者角度
1. planning 语义第一次成为正式后端模型
plan/build、CurrentPlan、SummaryView和相关状态位都已经进入 session/runtime/context 的正式结构里,planning 不再依赖零散消息约定。2. 摘要和全文有了统一后端规则
SummaryView现在由summary_candidate和BuildSummaryView(...)两层机制保证;其中后者是对PlanSpec的确定性字段投影,开发侧不需要再假设模型每次都能自己稳定写出可用摘要。3. 全文注入条件可测试、可扩展
full plan 是否注入现在由明确状态驱动,compact/恢复/审批/完成这些行为也都有固定触发点,后续演进不需要再靠自然语言猜测。
4. 为上层接入提供稳定后端锚点
即使当前不修改
TUI/gateway,后端已经具备承载模式切换、计划展示、审批、完成态展示和全文查看的正式基础。TUI / Gateway 后续可接入内容
本次不要求上层立即接入,但后端已经为后续接入预留了清晰能力:
1. 模式切换
上层后续可以显式传递:
planbuild从而驱动不同的 runtime 语义。
2. 当前计划展示
上层后续可以展示
CurrentPlan.Summary,包括:3. 计划审批
后端已经暴露显式接口:
ApproveCurrentPlan(sessionID, planID, revision)上层后续只需要在合适的交互点调用,不必再定义新的后端状态机。
4. 完整计划查看
当前已经有
SummaryView/full_plan_view双层机制,上层后续可以基于这些字段提供“查看摘要”和“查看完整计划”的界面能力。5. 完成态展示
后续可以根据
PlanStatus展示:draftapprovedcompleted并在执行结束后反映当前计划是否已经完成收口。
非目标
本次不处理:
TUI / gateway的实际协议和 UI 改造#511