|
| 1 | +--- |
| 2 | +name: understand-domain |
| 3 | +description: Extract business domain knowledge from a codebase and generate an interactive domain flow graph. Works standalone (lightweight scan) or derives from an existing /understand knowledge graph. |
| 4 | +argument-hint: [--full] |
| 5 | +--- |
| 6 | + |
| 7 | +# /understand-domain |
| 8 | + |
| 9 | +Extracts business domain knowledge — domains, business flows, and process steps — from a codebase and produces an interactive horizontal flow graph in the dashboard. |
| 10 | + |
| 11 | +## How It Works |
| 12 | + |
| 13 | +- If a knowledge graph already exists (`.understand-anything/knowledge-graph.json`), derives domain knowledge from it (cheap, no file scanning) |
| 14 | +- If no knowledge graph exists, performs a lightweight scan: file tree + entry point detection + sampled files |
| 15 | +- Use `--full` flag to force a fresh scan even if a knowledge graph exists |
| 16 | + |
| 17 | +## Instructions |
| 18 | + |
| 19 | +### Phase 1: Detect Existing Graph |
| 20 | + |
| 21 | +1. Check if `.understand-anything/knowledge-graph.json` exists in the current project |
| 22 | +2. If it exists AND `--full` was NOT passed → proceed to Phase 3 (derive from graph) |
| 23 | +3. Otherwise → proceed to Phase 2 (lightweight scan) |
| 24 | + |
| 25 | +### Phase 2: Lightweight Scan (Path 1) |
| 26 | + |
| 27 | +1. Run the preprocessing script bundled with this skill: |
| 28 | + ``` |
| 29 | + python understand-anything-plugin/skills/understand-domain/extract-domain-context.py <project-root> |
| 30 | + ``` |
| 31 | + This outputs `.understand-anything/intermediate/domain-context.json` containing: |
| 32 | + - File tree (respecting `.gitignore`) |
| 33 | + - Detected entry points (HTTP routes, CLI commands, event handlers, cron jobs, exported handlers) |
| 34 | + - File signatures (exports, imports per file) |
| 35 | + - Code snippets for each entry point (signature + first few lines) |
| 36 | +2. Read the generated `domain-context.json` as context for Phase 4 |
| 37 | +3. Proceed to Phase 4 |
| 38 | + |
| 39 | +### Phase 3: Derive from Existing Graph (Path 2) |
| 40 | + |
| 41 | +1. Read `.understand-anything/knowledge-graph.json` |
| 42 | +2. Format the graph data as structured context: |
| 43 | + - All nodes with their types, names, summaries, and tags |
| 44 | + - All edges with their types (especially `calls`, `imports`, `contains`) |
| 45 | + - All layers with their descriptions |
| 46 | + - Tour steps if available |
| 47 | +3. This is the context for the domain analyzer — no file reading needed |
| 48 | +4. Proceed to Phase 4 |
| 49 | + |
| 50 | +### Phase 4: Domain Analysis |
| 51 | + |
| 52 | +1. Read the domain-analyzer agent prompt from `agents/domain-analyzer.md` |
| 53 | +2. Dispatch a subagent with the domain-analyzer prompt + the context from Phase 2 or 3 |
| 54 | +3. The agent writes its output to `.understand-anything/intermediate/domain-analysis.json` |
| 55 | + |
| 56 | +### Phase 5: Validate and Save |
| 57 | + |
| 58 | +1. Read the domain analysis output |
| 59 | +2. Validate using the standard graph validation pipeline (the schema now supports domain/flow/step types) |
| 60 | +3. If validation fails, log warnings but save what's valid (error tolerance) |
| 61 | +4. Save to `.understand-anything/domain-graph.json` |
| 62 | +5. Clean up `.understand-anything/intermediate/domain-analysis.json` |
| 63 | + |
| 64 | +### Phase 6: Launch Dashboard |
| 65 | + |
| 66 | +1. Auto-trigger `/understand-dashboard` to visualize the domain graph |
| 67 | +2. The dashboard will detect `domain-graph.json` and show the domain view by default |
0 commit comments