understand-explain

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/understand-explain

/understand-explain

Provide a thorough, in-depth explanation of a specific code component.
提供对特定代码组件的全面、深度解析。

Graph Structure Reference

知识图谱结构参考

The knowledge graph JSON has this structure:
  • project
    — {name, description, languages, frameworks, analyzedAt, gitCommitHash}
  • nodes[]
    — each has {id, type, name, filePath, summary, tags[], complexity, languageNotes?}
    • Node types: file, function, class, module, concept
    • IDs:
      file:path
      ,
      func:path:name
      ,
      class:path:name
  • edges[]
    — each has {source, target, type, direction, weight}
    • Key types: imports, contains, calls, depends_on
  • layers[]
    — each has {id, name, description, nodeIds[]}
  • tour[]
    — each has {order, title, description, nodeIds[]}
知识图谱JSON的结构如下:
  • project
    — {name, description, languages, frameworks, analyzedAt, gitCommitHash}
  • nodes[]
    — 每个节点包含{id, type, name, filePath, summary, tags[], complexity, languageNotes?}
    • 节点类型:file(文件)、function(函数)、class(类)、module(模块)、concept(概念)
    • ID格式:
      file:path
      func:path:name
      class:path:name
  • edges[]
    — 每条边包含{source, target, type, direction, weight}
    • 主要边类型:imports(导入)、contains(包含)、calls(调用)、depends_on(依赖)
  • layers[]
    — 每个层级包含{id, name, description, nodeIds[]}
  • tour[]
    — 每个导览项包含{order, title, description, nodeIds[]}

How to Read Efficiently

高效阅读指南

  1. Use Grep to search within the JSON for relevant entries BEFORE reading the full file
  2. Only read sections you need — don't dump the entire graph into context
  3. Node names and summaries are the most useful fields for understanding
  4. Edges tell you how components connect — follow imports and calls for dependency chains
  1. 在阅读完整文件之前,先用Grep在JSON中搜索相关条目
  2. 只阅读你需要的部分——不要把整个图谱都加载到上下文里
  3. 节点名称和摘要部分是理解内容最有用的字段
  4. 边信息告诉你组件之间的关联——通过导入和调用关系追踪依赖链

Instructions

操作步骤

  1. Check that
    .understand-anything/knowledge-graph.json
    exists. If not, tell the user to run
    /understand
    first.
  2. Find the target node — use Grep to search the knowledge graph for the component: "$ARGUMENTS"
    • For file paths (e.g.,
      src/auth/login.ts
      ): search for
      "filePath"
      matches
    • For function notation (e.g.,
      src/auth/login.ts:verifyToken
      ): search for the function name in
      "name"
      fields filtered by the file path
    • Note the exact node
      id
      ,
      type
      ,
      summary
      ,
      tags
      , and
      complexity
  3. Find all connected edges — Grep for the target node's ID in the edges section:
    • "source"
      matches → things this node calls/imports/depends on (outgoing)
    • "target"
      matches → things that call/import/depend on this node (incoming)
    • Note the connected node IDs and edge types
  4. Read connected nodes — for each connected node ID from step 3, Grep for those IDs in the nodes section to get their
    name
    ,
    summary
    , and
    type
    . This builds the component's neighborhood.
  5. Identify the layer — Grep for the target node's ID in the
    "layers"
    section to find which architectural layer it belongs to and that layer's description.
  6. Read the actual source file — Read the source file at the node's
    filePath
    for the deep-dive analysis.
  7. Explain the component in context:
    • Its role in the architecture (which layer, why it exists)
    • Internal structure (functions, classes it contains — from
      contains
      edges)
    • External connections (what it imports, what calls it, what it depends on — from edges)
    • Data flow (inputs → processing → outputs — from source code)
    • Explain clearly, assuming the reader may not know the programming language
    • Highlight any patterns, idioms, or complexity worth understanding
  1. 检查
    .understand-anything/knowledge-graph.json
    是否存在。如果不存在,告知用户先运行
    /understand
    命令。
  2. 定位目标节点——使用Grep在知识图谱中搜索目标组件:"$ARGUMENTS"
    • 对于文件路径(例如
      src/auth/login.ts
      ):搜索匹配
      "filePath"
      的条目
    • 对于函数标识(例如
      src/auth/login.ts:verifyToken
      ):在指定文件路径过滤后的
      "name"
      字段中搜索函数名称
    • 记录目标节点的准确
      id
      type
      summary
      tags
      complexity
  3. 查找所有关联边——在边信息部分搜索目标节点的ID:
    • 匹配
      "source"
      的条目 → 该节点调用/导入/依赖的对象(向外关联)
    • 匹配
      "target"
      的条目 → 调用/导入/依赖该节点的对象(向内关联)
    • 记录关联节点的ID和边类型
  4. 查看关联节点——针对步骤3中找到的每个关联节点ID,在节点部分搜索这些ID,获取它们的
    name
    summary
    type
    。以此构建目标组件的关联网络。
  5. 确定所属层级——在
    "layers"
    部分搜索目标节点的ID,找到它所属的架构层级以及该层级的描述。
  6. 查看实际源代码文件——打开节点
    filePath
    对应的源代码文件,进行深度分析。
  7. 结合上下文解析组件
    • 它在架构中的角色(所属层级,存在的意义)
    • 内部结构(包含的函数、类——来自
      contains
      边信息)
    • 外部关联(它导入的内容、调用它的对象、它依赖的对象——来自边信息)
    • 数据流(输入→处理→输出——来自源代码)
    • 解释要清晰,假设读者可能不熟悉该编程语言
    • 突出任何值得关注的模式、惯用写法或复杂度要点