Skip to content

feat: add business domain knowledge extraction and visualization#66

Merged
Lum1104 merged 30 commits intomainfrom
feat/business-knowledge
Apr 2, 2026
Merged

feat: add business domain knowledge extraction and visualization#66
Lum1104 merged 30 commits intomainfrom
feat/business-knowledge

Conversation

@Lum1104
Copy link
Copy Markdown
Owner

@Lum1104 Lum1104 commented Apr 2, 2026

Summary

  • Core types: Added domain/flow/step node types, contains_flow/flow_step/cross_domain edge types, DomainMeta interface, Zod schema updates with aliases and .passthrough(), plus saveDomainGraph/loadDomainGraph persistence and node ID normalization
  • Dashboard: New domain graph view with DomainClusterNode, FlowNode, StepNode components, DomainGraphView with overview/detail modes (dagre LR layout), view mode toggle pill, domain-aware NodeInfo sidebar, and Vite dev server serving domain-graph.json
  • Agent & Skill: domain-analyzer agent definition for LLM-driven domain extraction, /understand-domain skill with two analysis paths (derive from existing graph or lightweight scan)

Implements #61.

Test Plan

  • Core: 390 tests pass (23 test files) including 15 new domain-specific tests
  • Core build: Clean TypeScript compilation
  • Dashboard build: 468 modules, 0 errors
  • Manual: Run /understand-domain on a sample project and verify domain graph renders in dashboard
  • Manual: Toggle between Domain and Structural views
  • Manual: Click domain nodes to drill into flow/step detail view
  • Manual: Verify NodeInfo sidebar shows domain-specific details

🤖 Generated with Claude Code

Lum1104 and others added 18 commits April 2, 2026 11:08
… business domain knowledge

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…sistence test

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…h, activeDomainId)

Add ViewMode type, DOMAIN_EDGE_TYPES, and domain/flow/step entries to
dashboard store, CustomNode, GraphView, and NodeInfo Record maps so the
dashboard compiles with the new core domain node and edge types.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…add category comment

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…butes to view toggle

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…views

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… imports in DomainGraphView

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ep nodes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…are NodeInfo

Remove unnecessary `as any` and `as string[]` casts by using the properly
typed DomainMeta interface. Fix historyNodes and childNodes to resolve from
activeGraph instead of graph so domain view mode works correctly. Use
type-narrowing filters to eliminate non-null assertions. Add early return
guard for step nodes with no filePath.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…dge extraction

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e8b99bc9e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +220 to +222
viewMode: "structural" as const,
domainGraph: null,
activeDomainId: null,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve domain graph state when setting structural graph

Dashboard fetches /knowledge-graph.json and /domain-graph.json in parallel, but setGraph unconditionally resets viewMode and clears domainGraph. If the domain graph arrives first (common when the structural graph is larger), a later structural response wipes it out, so the Domain toggle/view disappears until a full reload. This makes the new domain view nondeterministic based on response timing.

Useful? React with 👍 / 👎.

@Lum1104
Copy link
Copy Markdown
Owner Author

Lum1104 commented Apr 2, 2026

Code review

Found 3 issues:

  1. Race condition: setGraph wipes domainGraph on parallel fetch — Both knowledge-graph.json and domain-graph.json are fetched in independent useEffect hooks on mount. If domain-graph.json resolves first, setDomainGraph stores it, but then setGraph runs and resets domainGraph: null (line 221), silently destroying the loaded domain graph. The view mode toggle disappears with no error.

nodeHistory: [],
viewMode: "structural" as const,
domainGraph: null,
activeDomainId: null,
});

Fetch sites:

if (result.success && result.data) {
setGraph(result.data);
setGraphIssues(result.issues);

useEffect(() => {
fetch(tokenUrl("/domain-graph.json", accessToken))
.then((res) => {
if (!res.ok) return null;
return res.json();
})
.then((data: unknown) => {

  1. workflow/action aliases silently repurposed — breaking changeworkflow was previously aliased to "pipeline" (for CI/CD workflows) and is now changed to "flow" (a domain node type). Similarly action changed from "pipeline" to "step". Any existing LLM-generated graphs using "workflow" for CI/CD pipeline concepts will now silently produce "flow" nodes (business domain type) instead of "pipeline" nodes, corrupting structural knowledge graphs.

business_domain: "domain",
process: "flow",
workflow: "flow",
action: "step",
task: "step",

  1. Double-click handler fires twice on DomainClusterNode — Both the DomainClusterNode component's own onDoubleClick (line 31) and ReactFlow's onNodeDoubleClick callback (line 169) call navigateToDomain for the same event, causing the store action to execute twice per double-click.

onClick={() => selectNode(data.domainId)}
onDoubleClick={() => navigateToDomain(data.domainId)}
>

const onNodeDoubleClick = useCallback(
(_: React.MouseEvent, node: Node) => {
if (node.type === "domain-cluster" && node.data && "domainId" in node.data) {
navigateToDomain(node.data.domainId as string);
}
},
[navigateToDomain],

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

Lum1104 and others added 10 commits April 2, 2026 14:52
- Fix race condition: setGraph no longer wipes domainGraph on parallel fetch
- Remove workflow/action aliases that conflicted with pipeline type
- Remove duplicate onNodeDoubleClick handler in DomainGraphView
- Add clearActiveDomain store action (replaces direct setState call)
- Remove auto-switch to domain viewMode in setDomainGraph
- Add DomainMetaSchema Zod validation for domainMeta fields
- Add Array.isArray guards for domainMeta collections in NodeInfo
- Remove as-any cast in getDomainMeta (use typed domainMeta directly)
- Add "domain" filter category for domain/flow/step nodes
- Keep flow discriminator in step ID normalization to prevent collisions
- Update SKILL.md Phase 2 to use tool-based scanning (no missing script)
- Update EDGE_LABELS comment to reflect 29 edge types
- Bump version to 2.1.0 in all 4 required files

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…scanning

Python preprocessing script for /understand-domain Phase 2 (standalone path).
Scans a project and produces a structured JSON context file containing:
- File tree (respects .gitignore)
- Entry points (HTTP routes, CLI commands, events, cron, handlers)
- File signatures (exports, imports, previews) prioritized by business logic
- Project metadata (package.json, README, etc.)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Remove direction-inverting `implemented_by` alias (same pattern as fd0df15)
- Replace ambiguous `process` alias with `business_process`
- Fix duplicate React Flow edge IDs in DomainGraphView
- Fix navigateToDomain clearing selectedNodeId and losing history
- Preserve domain viewMode when structural graph loads after domain graph
- Add domain/flow/step to fileLevelTypes in GraphView
- Add domain edge category to EDGE_CATEGORY_MAP
- Extend COMPLEXITY_STRING_MAP with trivial/basic/mid/average/advanced
- Normalize string complexity values in normalizeBatchOutput (not just numeric)
- Infer node type from ID prefix in edge fallback normalization
- Include flow discriminator in bare-path step ID normalization
- Clean up domain-context.json intermediate file in SKILL.md

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rity

Prompt templates (file-analyzer, project-scanner, architecture-analyzer,
tour-builder, graph-reviewer) were being compressed by the orchestrator
when dispatched as subagent prompts, causing function/class extraction
to be silently skipped. Moving them to agents/ ensures the framework
loads the full prompt without compression.

- Move 5 prompt templates from skills/understand/ to agents/
- Update SKILL.md to reference agent definitions instead of templates
- Set all agent models to `inherit` for cross-platform compatibility
- Update CLAUDE.md to reflect new agent model policy

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Delete the 5 prompt template files from skills/understand/ now that
they live in agents/. Update auto-update-prompt.md hook to reference
agent definitions instead of deleted prompt files.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ndate

The previous wording ("MUST have sub-nodes") implied every code file
must produce function nodes, which is wrong for files without significant
functions. Now correctly states: if significant functions exist in the
script output, you must create nodes for them.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
knowledge-graph-guide.md (6 issues):
- Fix node types (5→16), edge types (18→29), tour schema (nodeId→nodeIds)
- Add domain graph documentation, jq examples, expand content

graph-reviewer.md (5 issues):
- Add domain node types (domain/flow/step) and edge types (contains_flow/flow_step/cross_domain)
- Relax layers/tour requirements for domain graphs
- Soften Check 8 (remove overly strict config/resource/endpoint checks)

domain-analyzer.md (6 issues):
- Add input format specification, output file path, writing results section
- Add critical constraints section with validation rules
- Fix flow_step weight scheme to stay within 0-1 range
- Change from "respond with JSON" to write-to-file pattern

file-analyzer.md (6 issues):
- Fix node type count description (13→accurate text)
- Recommend Node.js over bash for extraction scripts
- Replace "validate mentally" with actionable JSON validation instruction
- Clarify exports vs contains edge relationship
- Trim redundant tag guidance section
- Document why direction is always forward

architecture-analyzer.md (4 issues):
- Allow Python fallback for script language
- Clarify allEdges excludes sub-file edges
- Define "common prefix" algorithm for directory grouping
- Add layer count validation and empty group handling

tour-builder.md (2 issues):
- Fix BFS to start from code entry point, not README
- Allow Python fallback for script language

project-scanner.md (4 issues):
- Clarify exclusions match full directory segments, not substrings
- Stop excluding *.d.ts (may be hand-written)
- Add .env secret leak warning
- Document $PROJECT_ROOT variable, prefer Node.js

Cross-agent (3 issues):
- Consistent "prefer Node.js; fall back to Python" across all agents
- Schema type/count consistency across all agents
- Domain graph compatibility with graph-reviewer

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Function and class nodes were invisible in the graph because they
are not directly assigned to layers (only file-level nodes are).
Expand layer membership by following `contains` edges from file nodes
in the active layer to include their child function/class nodes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1. Add infrastructure edge category to EDGE_CATEGORY_MAP for 8 missing
   edge types (deploys, serves, provisions, triggers, migrates, documents,
   routes, defines_schema) — previously unfiltered regardless of toggles

2. navigateToDomain now switches viewMode to "domain" — previously
   clicking flow buttons from structural mode was a silent no-op

3. ExportMenu JSON export for non-technical persona now keeps all
   file-level types — previously dropped config/document/service/etc.

4. ProjectOverview category breakdown now includes module/concept in
   Code and domain/flow/step in new Domain category

5. SearchBar type badge colors now cover all 16 node types — previously
   only 5 had colors, rest fell back to file color

6. PathFinder BFS now traverses edges bidirectionally — previously
   only followed forward direction, missing valid reverse paths

7. GraphView node filtering consolidated into single authoritative
   type set — previously fileLevelTypes and persona conditions were
   separate lists that could drift

8. SelectedNodeFitView delayed 100ms to run after layer-level fitView
   on search-click navigation — previously layer fit clobbered node fit

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Lum1104 and others added 2 commits April 3, 2026 00:10
Add /understand-domain command, domain-analyzer agent, and two new
feature entries (Business Domain Knowledge + Structural/Domain Views)
to all 5 README versions: English, Simplified Chinese, Traditional
Chinese, Japanese, and Turkish.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Instead of truncating cross_domain edge labels, compute ranksep from
the longest label length (~6px/char) so dagre spaces nodes further
apart. Also add label background for readability, and support
spacingOverrides parameter in applyDagreLayout.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Lum1104 Lum1104 merged commit 2ec1c37 into main Apr 2, 2026
1 check passed
@Lum1104 Lum1104 deleted the feat/business-knowledge branch April 2, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

java代码仓看不到函数信息 无法正确的生成Project Overview 业务领域知识提炼 User feedback

1 participant