AgentSkillsCN

graph-view

当用户提出“2Graph”、“分析关系”、“寻找模式”、“分解为图”、“识别基序”、“绘制依赖关系”、“可视化关联”、“理解结构”、“保持连贯性”等需求,或提及图分析、依赖关系映射、连贯性检查、结构模式识别时,应使用此技能。

SKILL.md
--- frontmatter
name: graph-view
description: This skill should be used when the user asks to "2graph", "analyze relationships",
  "find patterns", "decompose into graph", "identify motifs", "map dependencies",
  "visualize connections", "understand structure", "--cohere", or mentions graph analysis,
  dependency mapping, coherence checking, or structural pattern recognition.

Graph View

Analyze any domain as a graph. Identify nodes, relationships, and structural patterns.

Workflow

code
1. BUILD       Nodes → Edges → Matrix
2. ANALYZE     Layers, Motifs, [Cohere]
3. INTERPRET   Domain insights

Phase 1: Build

Construct the graph representation.

Decompose

Identify discrete entities in the domain. Each node should be:

  • Nameable with a short identifier
  • Distinguishable from other nodes
  • At consistent granularity

Node Types by Domain

DomainNode Types
CodeModules, classes, functions, files
SystemsServices, components, databases
ConceptsIdeas, terms, principles
DataTables, entities, schemas
ProcessSteps, stages, milestones
OrganizationTeams, roles, departments

Relate

Identify connections between nodes. For each edge, determine:

  • Direction (A → B, B → A, or A ↔ B)
  • Type (what kind of relationship)
  • Strength (strong, normal, weak)

Edge Types by Domain

DomainEdge Types
Codeimports, calls, inherits, implements
Systemscalls, reads, writes, depends
Conceptsrequires, implies, contradicts, refines
Datareferences, contains, derives
Processprecedes, enables, blocks
Organizationreports-to, collaborates, owns

Matrix

Build adjacency matrix (Design Structure Matrix). Rows depend on columns.

code
        │ A │ B │ C │ D │
    ────┼───┼───┼───┼───┤
    A   │   │ → │   │   │   A depends on B
    B   │   │   │ → │   │   B depends on C
    C   │   │   │   │ → │   C depends on D
    D   │ ⇄ │   │   │   │   D mutual with A

Notation

SymbolMeaning
Dependency (row depends on column)
Mutual dependency (cycle)
Weak dependency
(empty)No relationship

Matrix Properties

Compute for each node:

  • In-degree: Count of → pointing to node (column sum)
  • Out-degree: Count of → pointing from node (row sum)
  • Degree: In-degree + Out-degree

Phase 2: Analyze

Find structural patterns. Use Operations/Queries as needed.

Layering

Compute dependency layers for DAG structure.

code
layer(n) = 0                           if in_degree(n) = 0
layer(n) = 1 + max(layer(d) for d in deps(n))  otherwise

Layer violation: Edge from higher layer to lower layer (e.g., layer 3 → layer 1) indicates architectural inversion.

Operations (tool)

Transform graphs as needed.

OpSyntaxEffect
filterG[predicate]Subgraph matching condition
projectG.nodes(type)Extract node subset by type
aggregateG.cluster(attr)Merge nodes sharing attribute
invertG.TReverse all edge directions
composeG1 ∘ G2Overlay graphs, union edges
diffG1 - G2Edges in G1 not in G2

Queries (tool)

Answer structural questions.

QueryExpressionReturns
Reachabilitypath(A, B) ≠ ∅Can A reach B?
Impactdescendants(A)What does A affect?
Dependenciesancestors(A)What does A require?
Criticalitycomponents(G - A)What breaks if A removed?
Shortest pathdist(A, B)Minimum hops A→B
Common ancestorLCA(A, B)Nearest shared dependency

Motifs

Detect structural patterns. See references/motifs.md for full catalog.

Node-level:

  • Hub: Degree > 2× average
  • Source: In-degree = 0, out-degree > 0
  • Sink: Out-degree = 0, in-degree > 0
  • Bridge: Removal disconnects graph
  • Isolate: Degree = 0

Cluster-level:

  • Clique: Every node connects to every other
  • Star: One hub, many leaves
  • Chain: Linear sequence A → B → C
  • Cycle: Circular path A → B → C → A
  • Community: Dense internal, sparse external connections

Global:

  • Tree: DAG with single root
  • Layered: Nodes fall into dependency layers
  • Tangled: High cycle count, poor layering

Cohere (optional)

See references/cohere.md. Only when --cohere specified.


Phase 3: Interpret

Translate patterns to domain meaning.

PatternIndicatesAction
HubCritical component, cascade riskExtract interface, add redundancy
BridgeSingle point of failureAdd alternate path
CycleTight coupling, init complexityBreak via interface or accept
CommunityNatural boundaryAlign with team/module
SourceEntry point, no depsAPI surface candidate
SinkTerminal, no dependentsOutput/logging layer
IsolateDead code or missing edgeRemove or connect

Output Format

markdown
# Graph Analysis: {domain}

## Nodes
| ID | Name | Type |
## Relationships
| From | To | Type | Strength |
## Matrix
(adjacency matrix with → ⇄ ○ symbols)
## Layers
| Layer | Nodes |
## Motifs
- Hubs: {nodes}
- Bridges: {nodes}
- Cycles: {node sets}
- Communities: {clusters}
## Metrics
| Metric | Value |
## Insights
(numbered interpretations)
## Coherence (--cohere only)
(violations and resolutions)

Metrics

MetricFormulaInterpretation
DensityE / (N × (N-1))<0.1 sparse, >0.3 dense
Avg Degree2E / NTypical connectivity
Clusteringtriangles / possibleLocal density
ModularityQ = Σ(e_ii - a_i²)Community strength
Diametermax(shortest paths)Graph spread

Verification

Check analysis quality:

code
V-NODE: Every entity is a node (no implicit actors)
V-EDGE: Every relationship is an edge (no hidden deps)
V-TYPE: Edge types are consistent within domain
V-MOTIF: All cycles and clusters documented
V-INSIGHT: Patterns have domain-specific interpretation