ln-813-optimization-plan-validator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Paths: File paths (
shared/
,
references/
,
../ln-*
) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root.
路径: 文件路径(
shared/
references/
../ln-*
)是相对于技能仓库根目录的。如果在当前工作目录(CWD)未找到,找到此SKILL.md所在目录并向上一级即为仓库根目录。

ln-813-optimization-plan-validator

ln-813-optimization-plan-validator

Type: L3 Worker Category: 8XX Optimization
Validates optimization plan (performance_map + hypotheses + context) via parallel agent review before committing to code changes. Catches feasibility issues, missing hypotheses, and incorrect conflict mappings before the strike.

类型: L3 Worker 分类: 8XX 优化
在提交代码变更前,通过多Agent并行审核验证优化方案(performance_map + 假设 + 上下文),在执行前发现可行性问题、缺失的假设以及错误的冲突映射。

Overview

概述

AspectDetails
Input
.optimization/{slug}/context.md
(performance_map, hypotheses, suspicion_stack)
OutputVerdict (GO / GO_WITH_CONCERNS / NO_GO), corrected context.md, agent feedback summary
PatternParallel agent review (Codex + Gemini) + own feasibility check → merge → verdict

方面详情
输入
.optimization/{slug}/context.md
(performance_map、假设、疑点栈)
输出结论(GO / GO_WITH_CONCERNS / NO_GO)、修正后的context.md、Agent反馈摘要
模式多Agent并行审核(Codex + Gemini)+ 自主可行性检查 → 合并结果 → 给出结论

Workflow

工作流

Phases: Load Context + Health Check → Materialize for Agents → Launch Agents → Feasibility Check → Merge + Debate → Verdict

阶段: 加载上下文 + 健康检查 → 为Agent准备上下文 → 启动Agent → 可行性检查 → 合并反馈 + 研讨 → 给出结论

Phase 0: Load Context + Health Check

阶段0:加载上下文 + 健康检查

MANDATORY READ: Load
shared/references/agent_review_workflow.md
MANDATORY READ: Load
shared/references/agent_delegation_pattern.md
必读内容: 加载
shared/references/agent_review_workflow.md
必读内容: 加载
shared/references/agent_delegation_pattern.md

Slug Resolution

Slug解析

  • If invoked via Agent with contextStore containing
    slug
    — use directly.
  • If invoked standalone — ask user for
    .optimization/
    target directory or scan for single slug.
  • 如果由包含
    slug
    的contextStore的Agent调用 — 直接使用该slug。
  • 如果独立调用 — 询问用户
    .optimization/
    目标目录或扫描单个slug。

Step 1: Load Context

步骤1:加载上下文

Read
.optimization/{slug}/context.md
from project root. Verify required sections present:
SectionRequiredVerify
Performance MapYes
performance_map.baseline
has measurements
HypothesesYesAt least 1 hypothesis with
files_to_modify
Suspicion StackYesAt least 1 confirmed suspicion
Test CommandYesNon-empty
test_command
If missing → Block: "context.md incomplete — run profiler and researcher first."
从项目根目录读取
.optimization/{slug}/context.md
,验证是否存在所需章节:
章节是否必填验证内容
性能地图
performance_map.baseline
包含测量数据
假设至少1个带有
files_to_modify
的假设
疑点栈至少1个已确认的疑点
测试命令
test_command
非空
若缺失 → 拦截:"context.md不完整 — 请先运行分析器和调研工具。"

Step 2: Agent Health Check

步骤2:Agent健康检查

python shared/agents/agent_runner.py --health-check
  • 0 agents available →
    agents_launched = SKIPPED
    , proceed with own feasibility check only
  • Agents available → continue to Phase 1

python shared/agents/agent_runner.py --health-check
  • 无可用Agent →
    agents_launched = SKIPPED
    ,仅执行自主可行性检查
  • 有可用Agent → 继续阶段1

Phase 1: Materialize Context for Agents

阶段1:为Agent准备上下文

Prepare context for external agents (they cannot read
.optimization/
directly):
  1. Ensure
    .agent-review/
    directory exists (with
    .gitignore
    containing
    *
    )
  2. Copy
    .optimization/{slug}/context.md
    .agent-review/context/{id}_optimization_plan.md
  3. Build per-agent prompts per
    agent_review_workflow.md
    Step: Build Prompt (steps 1-9). Use
    review_base.md
    +
    modes/plan_review.md
为外部Agent准备上下文(它们无法直接读取
.optimization/
):
  1. 确保
    .agent-review/
    目录存在(包含
    *
    .gitignore
    文件)
  2. 复制
    .optimization/{slug}/context.md
    .agent-review/context/{id}_optimization_plan.md
  3. 根据
    agent_review_workflow.md
    的“构建提示”步骤(步骤1-9)为每个Agent构建提示。使用
    review_base.md
    +
    modes/plan_review.md

Optimization-Specific Focus Areas

优化专项关注点

Replace default
{focus_areas}
in prompt with:
MANDATORY READ: Load optimization_review_focus.md
  1. Save per-agent prompts to
    .agent-review/{agent}/{id}_optimization_review_prompt.md

将提示中的默认
{focus_areas}
替换为:
必读内容: 加载 optimization_review_focus.md
  1. 将每个Agent的提示保存至
    .agent-review/{agent}/{id}_optimization_review_prompt.md

Phase 2: Launch Agents (Background)

阶段2:启动Agent(后台运行)

Launch BOTH agents as background Bash tasks:
bash
python shared/agents/agent_runner.py \
  --agent codex-review \
  --prompt-file .agent-review/codex/{id}_optimization_review_prompt.md \
  --output-file .agent-review/codex/{id}_optimization_review.md \
  --cwd {project_root}

python shared/agents/agent_runner.py \
  --agent gemini-review \
  --prompt-file .agent-review/gemini/{id}_optimization_review_prompt.md \
  --output-file .agent-review/gemini/{id}_optimization_review.md \
  --cwd {project_root}
Both run in background (
run_in_background=true
). Proceed to Phase 3 while agents work.

以后台Bash任务启动两个Agent:
bash
python shared/agents/agent_runner.py \
  --agent codex-review \
  --prompt-file .agent-review/codex/{id}_optimization_review_prompt.md \
  --output-file .agent-review/codex/{id}_optimization_review.md \
  --cwd {project_root}

python shared/agents/agent_runner.py \
  --agent gemini-review \
  --prompt-file .agent-review/gemini/{id}_optimization_review_prompt.md \
  --output-file .agent-review/gemini/{id}_optimization_review.md \
  --cwd {project_root}
两者均后台运行(
run_in_background=true
),在Agent运行期间继续阶段3。

Phase 3: Own Feasibility Check (while agents run)

阶段3:自主可行性检查(Agent运行期间)

Perform independent validation of the optimization plan:
CheckHowFail Action
Files existFor each hypothesis: verify every file in
files_to_modify
exists
Flag hypothesis as INVALID
No file conflictsCheck uncontested hypotheses don't modify same file linesFlag overlap as CONCERN
Suspicion coverageCross-reference
suspicion_stack
(confirmed) with hypotheses
Flag uncovered suspicions as MISSING_HYPOTHESIS
Evidence backingEach hypothesis should trace to a profiler finding or research sourceFlag unsupported as WEAK_EVIDENCE
Conflicts correctVerify
conflicts_with
mappings make sense (H1 really makes H3 unnecessary?)
Flag incorrect as BAD_CONFLICT
Fix HierarchyVerify hypotheses ordered Configuration→...→Removal. Flag if top hypothesis is level 4-5CONCERN: "config-level fix may be available"
Removal guardAny "remove feature" hypothesis MUST have paired "optimize feature" alternativeCONCERN: "removal without optimization alternative"
Assumption verificationEach hypothesis's premises — verified by profiler data or just assumed?Flag: "assumption not verified: {premise}"
Depth checkDid profiler go inside all accessible slow services? Check performance_map for surface-level entriesCONCERN: "service X profiled at surface level only"
对优化方案执行独立验证:
检查项检查方式失败处理
文件存在性针对每个假设:验证
files_to_modify
中的所有文件是否存在
将假设标记为INVALID
无文件冲突检查无争议的假设是否修改同一文件的相同行将重叠标记为CONCERN
疑点覆盖交叉对比已确认的
suspicion_stack
与假设
将未覆盖的疑点标记为MISSING_HYPOTHESIS
证据支持每个假设应能追溯到分析器结果或调研来源将无支持的假设标记为WEAK_EVIDENCE
冲突映射正确性验证
conflicts_with
映射是否合理(H1是否真的使H3变得不必要?)
将错误映射标记为BAD_CONFLICT
修复层级验证假设是否按“配置→...→移除”排序。若顶级假设为4-5级则标记关注点:"可能存在配置级修复方案"
移除防护任何“移除功能”的假设必须配有“优化功能”的替代方案关注点:"仅移除未提供优化替代方案"
假设验证每个假设的前提 — 是由分析器数据验证还是仅为假设?标记:"假设未验证:{premise}"
深度检查分析器是否深入了所有可访问的慢服务?检查performance_map是否仅为表层条目关注点:"仅对服务X进行了表层分析"

Output

输出

feasibility_result:
  valid_hypotheses: [H1, H2, H4]
  invalid_hypotheses: [{id: H3, reason: "file not found: src/cache.py"}]
  concerns: [{type: "file_overlap", detail: "H1 and H2 both modify src/api.py"}]
  missing: [{suspicion: "N+1 in loop at handler.py:45", note: "no hypothesis addresses this"}]

feasibility_result:
  valid_hypotheses: [H1, H2, H4]
  invalid_hypotheses: [{id: H3, reason: "file not found: src/cache.py"}]
  concerns: [{type: "file_overlap", detail: "H1 and H2 both modify src/api.py"}]
  missing: [{suspicion: "N+1 in loop at handler.py:45", note: "no hypothesis addresses this"}]

Phase 4: Merge Agent Feedback + Debate

阶段4:合并Agent反馈 + 研讨

Wait for agent results, then merge per
shared/references/agent_review_workflow.md
:
  1. Parse agent suggestions from both result files
  2. Merge with own feasibility findings (Phase 3)
  3. For EACH suggestion: dedup → evaluate → AGREE or DISAGREE (debate per shared workflow)
  4. Apply accepted corrections directly to
    .optimization/{slug}/context.md
    :
    • Remove invalid hypotheses
    • Add warnings to concerns
    • Adjust
      conflicts_with
      if agents found errors
    • Add missing hypotheses if agents identified gaps
Save review summary →
.agent-review/review_history.md
Display:
"Agent Review: codex ({accepted}/{total}), gemini ({accepted}/{total}), {N} corrections applied"

等待Agent结果,然后根据
shared/references/agent_review_workflow.md
合并:
  1. 解析两个结果文件中的Agent建议
  2. 与阶段3的自主可行性检查结果合并
  3. 对每个建议:去重 → 评估 → 同意或不同意(按照共享工作流研讨)
  4. 将已接受的修正直接应用到
    .optimization/{slug}/context.md
    • 移除无效假设
    • 为关注点添加警告
    • 若Agent发现错误则调整
      conflicts_with
    • 若Agent发现缺口则添加缺失的假设
将审核摘要保存至 →
.agent-review/review_history.md
显示:
"Agent审核:codex({已接受}/{总数}),gemini({已接受}/{总数}),已应用{N}项修正"

Phase 5: Verdict

阶段5:结论

VerdictCondition
GOAll hypotheses valid, no critical issues, agents agree plan is feasible
GO_WITH_CONCERNSMinor issues found and documented as warnings in context.md. Safe to proceed
NO_GOCritical feasibility issue (files missing, fundamental approach flaw, both agents reject)
结论条件
GO(执行)所有假设有效,无关键问题,Agents一致认为方案可行
GO_WITH_CONCERNS(带关注点执行)发现轻微问题并在context.md中记录为警告,可安全执行
NO_GO(不执行)存在严重可行性问题(文件缺失、核心方法缺陷、两个Agent均拒绝)

Output

输出

validation_result:
  verdict: "GO" | "GO_WITH_CONCERNS" | "NO_GO"
  corrections_applied: <number>
  hypotheses_removed: [<ids>]
  hypotheses_added: [<ids>]
  concerns: [<list>]
  agent_summary: "codex: PLAN_ACCEPTABLE, gemini: SUGGESTIONS (2 accepted)"
Return verdict to coordinator. On NO_GO: coordinator presents issues to user.

validation_result:
  verdict: "GO" | "GO_WITH_CONCERNS" | "NO_GO"
  corrections_applied: <number>
  hypotheses_removed: [<ids>]
  hypotheses_added: [<ids>]
  concerns: [<list>]
  agent_summary: "codex: PLAN_ACCEPTABLE, gemini: SUGGESTIONS (2 accepted)"
将结论返回给协调器。若为NO_GO:协调器向用户展示问题。

Error Handling

错误处理

ErrorRecovery
Context file missingBlock: "run profiler and researcher first"
Both agents unavailableProceed with own feasibility check only (reduced confidence)
Agent timeoutUse results from available agent + own check
Context file malformedBlock: "context.md missing required sections"

错误恢复方式
上下文文件缺失拦截:"请先运行分析器和调研工具"
两个Agent均不可用仅执行自主可行性检查(置信度降低)
Agent超时使用可用Agent的结果 + 自主检查结果
上下文文件格式错误拦截:"context.md缺失所需章节"

References

参考文档

  • shared/references/agent_review_workflow.md
    — merge + debate protocol
  • shared/references/agent_delegation_pattern.md
    — agent invocation pattern
  • shared/agents/prompt_templates/modes/plan_review.md
    — plan review template
  • optimization_review_focus.md — optimization-specific focus areas

  • shared/references/agent_review_workflow.md
    — 合并 + 研讨协议
  • shared/references/agent_delegation_pattern.md
    — Agent调用模式
  • shared/agents/prompt_templates/modes/plan_review.md
    — 方案审核模板
  • optimization_review_focus.md — 优化专项关注点

Definition of Done

完成标准

  • Context file loaded and validated (all required sections present)
  • Agent health check performed
  • Context materialized to
    .agent-review/
    for agents
  • Both agents launched (or SKIPPED if unavailable)
  • Own feasibility check completed (files exist, no conflicts, evidence backing)
  • Agent results merged and debated
  • Corrections applied to context.md
  • Verdict issued (GO / GO_WITH_CONCERNS / NO_GO)
  • Review summary saved to
    .agent-review/review_history.md

Version: 1.0.0 Last Updated: 2026-03-15
  • 上下文文件已加载并验证(所有必填章节存在)
  • 已执行Agent健康检查
  • 已为Agent准备好上下文并存储至
    .agent-review/
  • 已启动两个Agent(或不可用时标记为SKIPPED)
  • 已完成自主可行性检查(文件存在性、无冲突、证据支持等)
  • 已合并Agent反馈并完成研讨
  • 已将修正应用到context.md
  • 已给出结论(GO / GO_WITH_CONCERNS / NO_GO)
  • 已将审核摘要保存至
    .agent-review/review_history.md

版本: 1.0.0 最后更新: 2026-03-15