re-verify-structure

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Structure Verification — Reverse Engineering Phase 1 Critic

结构验证 — 逆向工程第一阶段Critic

Verify the structure map produced by
re-structure-analysis
against the actual source code. This skill runs as an independent Critic in a separate agent context. It has no access to the Doer's reasoning — only the artifacts.
Gate rule: Phase 2 (
re-visualize-logic
) shall not proceed until this verification produces a
PASS
or
WARN
verdict.
对照实际源代码验证
re-structure-analysis
生成的结构映射。该技能作为独立的Critic在单独的Agent环境中运行,无法访问执行者(Doer)的推理过程——仅能访问工件。
准入规则:第二阶段(
re-visualize-logic
)必须在本验证得出
PASS
WARN
结论后才能启动。

Three Principles (Critic Perspective)

三大原则(Critic视角)

1. Code is Truth

1. 代码即真理

  • The source code is the sole authority. If the structure map says something the code does not confirm, the structure map is wrong.
  • 源代码是唯一权威。如果结构映射中的内容无法得到代码的证实,则结构映射存在错误。

2. Traceability to Line

2. 可追溯到行

  • Every
    file:line
    reference in the structure map must resolve to actual code. Unresolvable references are hallucinations.
  • 结构映射中的每一处
    file:line
    引用都必须能对应到实际代码。无法解析的引用属于幻觉内容(hallucinations)。

3. Behavior over Intent

3. 行为优先于意图

  • Verify what the structure map claims against what the code shows. Do not interpret or justify discrepancies.
  • 对照代码实际内容验证结构映射的声明。不要解读或为差异找借口。

Execution

执行步骤

Step 1: Load Artifacts

步骤1:加载工件

Determine the manifest path:
  • If
    manifest
    argument is provided, use it directly
  • If
    analysis
    argument is provided, derive path as
    docs/reverse/{analysis}/manifest.json
  • At least one of
    manifest
    or
    analysis
    must be provided
Read the manifest and structure map:
{manifest-path}
{analysis-dir}/01-structure-map.md
Extract from the manifest:
  • targets.entry_points
    — original user-specified targets
  • phase1.status
    — must be
    "completed"
    to proceed
  • language
    — for tool strategy
If
phase1.status
is not
"completed"
, report error and stop.
确定清单路径:
  • 如果提供了
    manifest
    参数,直接使用该路径
  • 如果提供了
    analysis
    参数,路径推导为
    docs/reverse/{analysis}/manifest.json
  • 必须至少提供
    manifest
    analysis
    中的一个
读取清单和结构映射:
{manifest-path}
{analysis-dir}/01-structure-map.md
从清单中提取以下信息:
  • targets.entry_points
    — 用户最初指定的目标
  • phase1.status
    — 必须为
    "completed"
    才能继续执行
  • language
    — 用于确定工具策略
如果
phase1.status
不是
"completed"
,则报告错误并停止执行。

Step 2: Reference Verification

步骤2:引用验证

Extract all
file:line
references from the structure map.
For each reference:
  1. File existence: Verify the file exists at the specified path.
  2. Line validity: Read the file and verify the line number is within range.
  3. Content match: Verify the content at the cited line matches the claim in the structure map.
Classify each reference:
CategoryCriteria
✅ VALIDFile exists, line exists, content matches claim
⚠️ INACCURATEFile exists, content found within ±10 lines of cited line
❌ INVALIDFile does not exist, or line number grossly wrong
🚫 HALLUCINATIONComponent described in structure map cannot be found in source code at any location
从结构映射中提取所有
file:line
引用。
对每个引用执行以下检查:
  1. 文件存在性:验证指定路径下的文件是否存在。
  2. 行号有效性:读取文件并验证行号是否在有效范围内。
  3. 内容匹配:验证引用行的内容是否与结构映射中的声明一致。
将每个引用分类:
分类判定标准
✅ VALID文件存在,行号有效,内容与声明匹配
⚠️ INACCURATE文件存在,在引用行的±10行范围内找到对应内容
❌ INVALID文件不存在,或行号严重错误
🚫 HALLUCINATION结构映射中描述的组件在源代码的任何位置都无法找到

Step 3: Completeness Verification

步骤3:完整性验证

Count actual components in the target scope and compare with the structure map.
With Serena:
mcp__serena__search_for_pattern(
    substring_pattern="class |interface |def |function ",
    restrict_search_to_code_files=true
)
Without Serena:
  • Use Grep to count class/function definitions in the target scope
  • Compare with the number listed in the structure map
Calculate coverage:
(listed_in_map / actual_in_source) * 100
CoverageVerdict
>= 95%PASS
90% - 94%WARN
< 90%FAIL
List any components found in source but missing from the structure map.
统计目标范围内的实际组件数量,并与结构映射中的数量进行对比。
使用Serena工具时
mcp__serena__search_for_pattern(
    substring_pattern="class |interface |def |function ",
    restrict_search_to_code_files=true
)
不使用Serena工具时
  • 使用Grep统计目标范围内的类/函数定义数量
  • 与结构映射中列出的数量进行对比
计算覆盖率:
(结构映射中列出的数量 / 源代码中的实际数量) * 100
覆盖率结论
>= 95%PASS
90% - 94%WARN
< 90%FAIL
列出所有在源代码中存在但未被结构映射收录的组件。

Step 4: Mermaid Diagram Validation

步骤4:Mermaid图验证

For each Mermaid code block in the structure map:
  1. Check syntax validity (matching brackets, valid node definitions, valid arrow syntax)
  2. Spot-check 3 nodes/relationships against source code
  3. Document any syntax errors or content inaccuracies
对结构映射中的每个Mermaid代码块执行以下检查:
  1. 检查语法有效性(括号匹配、节点定义合法、箭头语法有效)
  2. 随机抽查3个节点/关系,与源代码进行对比
  3. 记录所有语法错误或内容不准确的问题

Step 5: Internal Consistency Check

步骤5:内部一致性检查

Verify that:
  • Components in dependency diagrams are also listed in component tables
  • Entry points in diagrams match the entry point section
  • File paths are consistent throughout the document
  • targets_for_phase2
    in the manifest references components that exist in the structure map
验证以下内容:
  • 依赖图中的组件也在组件列表中列出
  • 图中的入口点与入口点章节的内容一致
  • 整个文档中的文件路径保持一致
  • 清单中的
    targets_for_phase2
    引用的组件在结构映射中存在

Step 6: Generate Verification Report

步骤6:生成验证报告

Write to
docs/reverse/{analysis}/verification/v1-structure.md
:
markdown
undefined
将报告写入
docs/reverse/{analysis}/verification/v1-structure.md
markdown
undefined

Structure Map Verification Report

结构映射验证报告

Verification Date: {YYYY-MM-DD} Target Document: docs/reverse/{analysis}/01-structure-map.md Verdict: {PASS / WARN / FAIL}
验证日期:{YYYY-MM-DD} 目标文档:docs/reverse/{analysis}/01-structure-map.md 结论:{PASS / WARN / FAIL}

Summary

摘要

CheckResultDetails
Reference Accuracy{✅/⚠️/❌}{valid}/{total} references ({%})
Component Coverage{✅/⚠️/❌}{listed}/{actual} components ({%})
Mermaid Syntax{✅/⚠️/❌}{error_count} errors
Internal Consistency{✅/⚠️/❌}{inconsistency_count} issues
检查项结果详情
引用准确性{✅/⚠️/❌}{有效数量}/{总数量} 引用 (占比{百分比}%)
组件覆盖率{✅/⚠️/❌}{列出数量}/{实际数量} 组件 (占比{百分比}%)
Mermaid语法{✅/⚠️/❌}{错误数量} 个错误
内部一致性{✅/⚠️/❌}{不一致问题数量} 个问题

Verdict

结论说明

{PASS}: Phase 2 may proceed. {WARN}: Minor issues found. Phase 2 may proceed. Corrections recommended. {FAIL}: Critical issues found. Phase 2 must not proceed. Corrections required.
{PASS}:第二阶段可以启动。 {WARN}:发现轻微问题。第二阶段可以启动,建议进行修正。 {FAIL}:发现严重问题。第二阶段不得启动,必须进行修正。

Reference Verification Details

引用验证详情

Invalid References

无效引用

ClaimFile:LineIssueExpected
{claim}{reference}{issue description}{correct reference or "not found"}
声明文件:行问题预期
{声明内容}{引用}{问题描述}{正确引用或“未找到”}

Hallucinations

幻觉内容

  • {component}: {reason it is considered hallucinated}
  • {组件名称}:{被判定为幻觉内容的原因}

Completeness Details

完整性详情

Missing Components

缺失组件

ComponentFileType
{name}{file path}{class/function/interface}
组件文件类型
{名称}{文件路径}{类/函数/接口}

Mermaid Validation

Mermaid图验证

Syntax Errors

语法错误

  • Block {N}: {error description}
  • 代码块{N}:{错误描述}

Content Inaccuracies

内容不准确

  • Node "{node}": {discrepancy}
  • 节点“{节点名称}”:{差异描述}

Internal Consistency Issues

内部一致性问题

  • {description of inconsistency}
  • {不一致问题描述}

Recommendations

建议

  1. [CRITICAL] {fix description}
  2. [HIGH] {fix description}
  3. [MEDIUM] {fix description}
undefined
  1. [CRITICAL] {修复描述}
  2. [HIGH] {修复描述}
  3. [MEDIUM] {修复描述}
undefined

Step 7: Update Manifest

步骤7:更新清单

Read the current manifest, then update:
  • Set
    phase1.verification
    to
    "verification/v1-structure.md"
  • If verdict is
    PASS
    or
    WARN
    : set
    phase1.status
    to
    "verified"
  • If verdict is
    FAIL
    : leave
    phase1.status
    as
    "completed"
    (do not promote)
  • Update
    updated
    timestamp
读取当前清单,然后更新以下内容:
  • phase1.verification
    设置为
    "verification/v1-structure.md"
  • 如果结论为
    PASS
    WARN
    :将
    phase1.status
    设置为
    "verified"
  • 如果结论为
    FAIL
    :保持
    phase1.status
    "completed"
    (不推进阶段)
  • 更新
    updated
    时间戳

Verdict Criteria

结论判定标准

CriterionPASSWARNFAIL
Reference accuracy>= 95%80-94%< 80%
Component coverage>= 95%90-94%< 90%
Mermaid errors01-2>= 3
Hallucinations00>= 1
Any single FAIL criterion results in an overall FAIL verdict.
判定项PASSWARNFAIL
引用准确性>= 95%80-94%< 80%
组件覆盖率>= 95%90-94%< 90%
Mermaid图错误01-2>= 3
幻觉内容00>= 1
任何一项判定为FAIL都会导致整体结论为FAIL。

Prohibited Actions

禁止操作

  • Do NOT modify the structure map document
  • Do NOT modify source code files
  • Do NOT assume missing information — flag it as an issue
  • Do NOT approve documents with FAIL status
  • Do NOT access the Doer's conversation context or reasoning
  • 不得修改结构映射文档
  • 不得修改源代码文件
  • 不得自行补充缺失信息 — 需将其标记为问题
  • 不得批准结论为FAIL的文档
  • 不得访问执行者(Doer)的对话上下文或推理过程 ",