understand-domain

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/understand-domain

/understand-domain

Extracts business domain knowledge — domains, business flows, and process steps — from a codebase and produces an interactive horizontal flow graph in the dashboard.
从代码库中提取业务领域知识——包括领域、业务流程和处理步骤——并在仪表板中生成交互式水平流程图。

How It Works

工作原理

  • If a knowledge graph already exists (
    .understand-anything/knowledge-graph.json
    ), derives domain knowledge from it (cheap, no file scanning)
  • If no knowledge graph exists, performs a lightweight scan: file tree + entry point detection + sampled files
  • Use
    --full
    flag to force a fresh scan even if a knowledge graph exists
  • 如果已存在知识图谱(
    .understand-anything/knowledge-graph.json
    ),则基于该图谱推导领域知识(成本低,无需扫描文件)
  • 如果不存在知识图谱,则执行轻量扫描:文件树+入口点检测+抽样文件
  • 使用
    --full
    flag可强制执行全新扫描,即便已有知识图谱也不例外

Instructions

使用说明

Phase 1: Detect Existing Graph

阶段1:检测已有图谱

  1. Check if
    .understand-anything/knowledge-graph.json
    exists in the current project
  2. If it exists AND
    --full
    was NOT passed → proceed to Phase 3 (derive from graph)
  3. Otherwise → proceed to Phase 2 (lightweight scan)
  1. 检查当前项目中是否存在
    .understand-anything/knowledge-graph.json
  2. 如果文件存在且未传入
    --full
    参数 → 进入阶段3(基于图谱推导)
  3. 否则 → 进入阶段2(轻量扫描)

Phase 2: Lightweight Scan (Path 1)

阶段2:轻量扫描(路径1)

The preprocessing script does NOT produce a domain graph — it produces raw material (file tree, entry points, exports/imports) so the domain-analyzer agent can focus on the actual domain analysis instead of spending dozens of tool calls exploring the codebase. Think of it as a cheat sheet: cheap Python preprocessing → expensive LLM gets a clean, small input → better results for less cost.
  1. Run the preprocessing script bundled with this skill:
    python ./extract-domain-context.py <project-root>
    This outputs
    <project-root>/.understand-anything/intermediate/domain-context.json
    containing:
    • File tree (respecting
      .gitignore
      )
    • Detected entry points (HTTP routes, CLI commands, event handlers, cron jobs, exported handlers)
    • File signatures (exports, imports per file)
    • Code snippets for each entry point (signature + first few lines)
    • Project metadata (package.json, README, etc.)
  2. Read the generated
    domain-context.json
    as context for Phase 4
  3. Proceed to Phase 4
预处理脚本不会生成领域图谱,它会生成原始素材(文件树、入口点、导出/导入项),这样domain-analyzer agent就能聚焦于实际的领域分析,而不需要花费几十次工具调用探索代码库。你可以把它看作一份备忘录:低成本的Python预处理 → 昂贵的LLM获得干净、体量小的输入 → 成本更低,效果更好。
  1. 运行该skill内置的预处理脚本:
    python ./extract-domain-context.py <project-root>
    命令会输出
    <project-root>/.understand-anything/intermediate/domain-context.json
    ,包含以下内容:
    • 文件树(遵循
      .gitignore
      规则)
    • 检测到的入口点(HTTP路由、CLI命令、事件处理器、定时任务、导出的处理器)
    • 文件特征(每个文件的导出、导入项)
    • 每个入口点的代码片段(特征定义+前几行代码)
    • 项目元数据(package.json、README等)
  2. 读取生成的
    domain-context.json
    作为阶段4的上下文
  3. 进入阶段4

Phase 3: Derive from Existing Graph (Path 2)

阶段3:基于已有图谱推导(路径2)

  1. Read
    .understand-anything/knowledge-graph.json
  2. Format the graph data as structured context:
    • All nodes with their types, names, summaries, and tags
    • All edges with their types (especially
      calls
      ,
      imports
      ,
      contains
      )
    • All layers with their descriptions
    • Tour steps if available
  3. This is the context for the domain analyzer — no file reading needed
  4. Proceed to Phase 4
  1. 读取
    .understand-anything/knowledge-graph.json
  2. 将图谱数据格式化为结构化上下文:
    • 所有节点及其类型、名称、摘要和标签
    • 所有边及其类型(尤其是
      calls
      imports
      contains
    • 所有分层及其描述
    • 导览步骤(如果有)
  3. 以上内容就是领域分析器的上下文,无需读取任何文件
  4. 进入阶段4

Phase 4: Domain Analysis

阶段4:领域分析

  1. Read the domain-analyzer agent prompt from
    agents/domain-analyzer.md
  2. Dispatch a subagent with the domain-analyzer prompt + the context from Phase 2 or 3
  3. The agent writes its output to
    .understand-anything/intermediate/domain-analysis.json
  1. agents/domain-analyzer.md
    读取domain-analyzer agent的提示词
  2. 分配子agent,传入domain-analyzer提示词+阶段2或阶段3生成的上下文
  3. Agent会将输出写入
    .understand-anything/intermediate/domain-analysis.json

Phase 5: Validate and Save

阶段5:验证与保存

  1. Read the domain analysis output
  2. Validate using the standard graph validation pipeline (the schema now supports domain/flow/step types)
  3. If validation fails, log warnings but save what's valid (error tolerance)
  4. Save to
    .understand-anything/domain-graph.json
  5. Clean up
    .understand-anything/intermediate/domain-analysis.json
    and
    .understand-anything/intermediate/domain-context.json
  1. 读取领域分析输出
  2. 使用标准图谱验证管道进行验证(当前schema已支持domain/flow/step类型)
  3. 如果验证失败,记录警告但保存所有有效内容(容错机制)
  4. 保存到
    .understand-anything/domain-graph.json
  5. 清理
    .understand-anything/intermediate/domain-analysis.json
    .understand-anything/intermediate/domain-context.json

Phase 6: Launch Dashboard

阶段6:启动仪表板

  1. Auto-trigger
    /understand-dashboard
    to visualize the domain graph
  2. The dashboard will detect
    domain-graph.json
    and show the domain view by default
  1. 自动触发
    /understand-dashboard
    可视化领域图谱
  2. 仪表板会检测
    domain-graph.json
    ,默认展示领域视图