re-verify-logic

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Logic Verification — Reverse Engineering Phase 2 Critic

逻辑验证 — 逆向工程第二阶段Critic

Verify logic diagrams produced by
re-visualize-logic
against actual source code. Runs as an independent Critic in a separate agent context.
Gate rule: Phase 3 (
re-extract-requirements
) shall not proceed until verification produces a
PASS
or
WARN
verdict for all components.
re-visualize-logic
生成的逻辑图与实际源代码进行比对验证。作为独立的Critic在单独的Agent上下文运行。
准入规则:所有组件的验证结果为
PASS
WARN
之前,不得进入第三阶段(
re-extract-requirements
)。

Three Principles (Critic Perspective)

三大原则(Critic视角)

1. Code is Truth

1. 代码即真相

  • The source code is the sole authority. If the logic diagram says something the code does not confirm, the diagram is wrong.
  • 源代码是唯一权威。如果逻辑图的内容无法被代码证实,则逻辑图存在错误。

2. Traceability to Line

2. 可追溯到行

  • Every line number in the diagram must resolve to actual code. Unresolvable references are hallucinations.
  • 逻辑图中的每一个行号都必须对应到实际代码中。无法解析的引用属于幻觉内容。

3. Behavior over Intent

3. 行为优先于意图

  • Verify what the diagram claims against what the code shows. Do not interpret or justify discrepancies.
  • 将逻辑图的声明与代码实际表现进行比对。不要解释或合理化差异。

Execution

执行步骤

Step 1: Load Artifacts

步骤1:加载工件

Read
docs/reverse/{analysis}/manifest.json
.
Determine which components to verify:
  • If
    component
    argument is provided, verify only that component
  • If omitted, verify all entries in
    phase2.completed
    that have
    verification: null
For each component, read the logic diagram:
docs/reverse/{analysis}/02-logic-{component}.md
读取
docs/reverse/{analysis}/manifest.json
文件。
确定需要验证的组件:
  • 如果提供了
    component
    参数,仅验证该组件
  • 如果未提供,则验证
    phase2.completed
    中所有
    verification: null
    的条目
针对每个组件,读取逻辑图文件:
docs/reverse/{analysis}/02-logic-{component}.md

Step 2: Line Number Verification

步骤2:行号验证

For each node in the Mermaid diagram and each row in the node-to-line mapping table:
  1. Extract the cited line number
  2. Read the source file at that line
  3. Compare the code at that line with the claim
Classify:
  • MATCH: Code at cited line matches the description
  • ⚠️ OFFSET: Code found within ±5 lines
  • MISMATCH: Code at cited line does not match
  • 🚫 HALLUCINATION: Described behavior not found in source at any location
针对Mermaid图中的每个节点以及节点-行号映射表中的每一行:
  1. 提取引用的行号
  2. 读取对应行的源代码
  3. 将该行代码与逻辑图中的声明进行比对
分类结果:
  • 匹配:引用行的代码与描述一致
  • ⚠️ 偏移:在±5行范围内找到对应代码
  • 不匹配:引用行的代码与描述不符
  • 🚫 幻觉:在源代码的任何位置都找不到描述的行为

Step 3: Mermaid Syntax Validation

步骤3:Mermaid语法验证

Check each Mermaid code block for:
  • Valid node definitions and arrow syntax
  • No prohibited characters (
    !=
    ,
    >=
    ,
    []
    ,
    ()
    in text)
  • Parseable structure (matching brackets, valid subgraphs)
检查每个Mermaid代码块:
  • 有效的节点定义和箭头语法
  • 无禁用字符(文本中不得包含
    !=
    >=
    []
    ()
  • 可解析的结构(括号匹配、有效的子图)

Step 4: Completeness Check

步骤4:完整性检查

Compare the logic diagram against the source method:
  • Count control flow branches in source (if/else, switch cases, loops)
  • Count corresponding nodes in the diagram
  • Flag missing branches
Check side effects documentation:
  • Grep source for database operations, network calls, file I/O, logging
  • Verify each is documented in the side effects summary
将逻辑图与源代码方法进行比对:
  • 统计源代码中的控制流分支(if/else、switch分支、循环)
  • 统计逻辑图中对应的节点数量
  • 标记缺失的分支
检查副作用文档:
  • 用Grep工具搜索源代码中的数据库操作、网络调用、文件I/O、日志记录
  • 验证每一项都在副作用摘要中有记录

Step 5: Generate Verification Report

步骤5:生成验证报告

Write to
docs/reverse/{analysis}/verification/v2-logic-{component}.md
:
markdown
undefined
写入文件
docs/reverse/{analysis}/verification/v2-logic-{component}.md
markdown
undefined

Logic Diagram Verification: {component}

Logic Diagram Verification: {component}

Verification Date: {YYYY-MM-DD} Target Document: 02-logic-{component}.md Verdict: {PASS / WARN / FAIL}
Verification Date: {YYYY-MM-DD} Target Document: 02-logic-{component}.md Verdict: {PASS / WARN / FAIL}

Summary

Summary

CheckResultDetails
Line Number Accuracy{✅/⚠️/❌}{match}/{total} nodes ({%})
Mermaid Syntax{✅/⚠️/❌}{error_count} errors
Branch Coverage{✅/⚠️/❌}{covered}/{total} branches ({%})
Side Effects{✅/⚠️/❌}{documented}/{total} side effects ({%})
CheckResultDetails
Line Number Accuracy{✅/⚠️/❌}{match}/{total} nodes ({%})
Mermaid Syntax{✅/⚠️/❌}{error_count} errors
Branch Coverage{✅/⚠️/❌}{covered}/{total} branches ({%})
Side Effects{✅/⚠️/❌}{documented}/{total} side effects ({%})

Verdict

Verdict

{PASS/WARN/FAIL}: {explanation}
{PASS/WARN/FAIL}: {explanation}

Details

Details

Line Number Issues

Line Number Issues

NodeClaimed LineActual LineIssue
NodeClaimed LineActual LineIssue

Missing Branches

Missing Branches

  • {description of missing branch at file:line}
  • {description of missing branch at file:line}

Missing Side Effects

Missing Side Effects

  • {description of undocumented side effect at file:line}
  • {description of undocumented side effect at file:line}

Recommendations

Recommendations

  1. [{severity}] {fix description}
undefined
  1. [{severity}] {fix description}
undefined

Step 6: Update Manifest

步骤6:更新清单

For each verified component:
  • Update
    phase2.completed[].verification
    to
    "verification/v2-logic-{component}.md"
After all components are verified:
  • If all verdicts are PASS or WARN: set
    phase2.status
    to
    "verified"
  • If any verdict is FAIL: leave
    phase2.status
    as
    "completed"
  • Update
    updated
    timestamp
针对每个已验证的组件:
  • phase2.completed[].verification
    更新为
    "verification/v2-logic-{component}.md"
所有组件验证完成后:
  • 如果所有结果均为PASS或WARN:将
    phase2.status
    设置为
    "verified"
  • 如果存在任何FAIL结果:保持
    phase2.status
    "completed"
  • 更新
    updated
    时间戳

Verdict Criteria

结果判定标准

CriterionPASSWARNFAIL
Line number accuracy>= 95% match80-94%< 80%
Mermaid syntax errors01-2>= 3
Branch coverage>= 90%75-89%< 75%
Side effect documentation100%>= 80%< 80%
Hallucinations00>= 1
Any single FAIL criterion results in overall FAIL.
判定项PASSWARNFAIL
行号准确率>= 95%匹配80-94%< 80%
Mermaid语法错误数01-2>=3
分支覆盖率>=90%75-89%<75%
副作用文档覆盖率100%>=80%<80%
幻觉内容数00>=1
任何单项判定为FAIL则整体结果为FAIL。

Prohibited Actions

禁止操作

  • Do NOT modify logic diagram documents
  • Do NOT modify source code files
  • Do NOT approve documents with FAIL status
  • Do NOT access the Doer's conversation context
  • 不得修改逻辑图文档
  • 不得修改源代码文件
  • 不得批准结果为FAIL的文档
  • 不得访问Doer的对话上下文