Skip to content

New commands: get_scene_insights, get_node_insights#52

Open
ethandaviessmith wants to merge 1 commit intoCoding-Solo:mainfrom
ethandaviessmith:feature/insight-commands
Open

New commands: get_scene_insights, get_node_insights#52
ethandaviessmith wants to merge 1 commit intoCoding-Solo:mainfrom
ethandaviessmith:feature/insight-commands

Conversation

@ethandaviessmith
Copy link

Summary

Complete scene and script behavioral analysis system for Godot projects. Provides deep insights into scene architecture, script patterns, signal flows, and component relationships with minimal overhead.

Enables AI assistants to understand project architecture through comprehensive behavioral analysis - tracking signal emissions, method chains, state management patterns, and inter-component communication. Supports both scene-level analysis (hierarchy + attached scripts) and standalone script analysis.

Use cases: Architecture mapping, refactoring safety checks, signal flow tracing, dependency analysis, pattern detection, debugging scene interactions, and codebase exploration.

Technical Implementation

Scene Analysis (get_scene_insights)
Text-based TSCN parser (headless-compatible, no ResourceLoader dependencies)
Property extraction with script reference resolution via ExtResource mapping
Recursive script collection and behavioral analysis for all attached scripts
Signal connection parsing from scene definitions
Behavioral data aggregation across all scene scripts

Script Analysis (get_node_insights)
GDScript parser extracting class structure, exports, variables, methods, signals
Method body analysis for call patterns, signal emissions, and behavioral flows
Dependency tracking: preload(), load(), ClassDB, type hints, and class references
Scene interaction detection: node queries ($, %, get_node), tree manipulation, scene loading
Local variable type inference for accurate method call classification

Behavioral Intelligence
Pattern detection: initialization, continuous processing, input handling, event-driven, state management (simple)
Method summaries with call profiles (internal/external/builtin methods, signal usage)
Signal flow analysis: definitions, emissions, connections with line numbers
Scene interaction categorization: node queries, tree changes, communication patterns (upward/downward)

Core Functions Added (godot_insights.gd overview)

Entry Points

  • get_scene_insights() - Scene structure + behavioral analysis with script collection
  • get_node_insights() - Script structure + behavioral analysis

Scene Parsing

  • _parse_scene_file() - TSCN parser with ExtResource mapping
  • _scene_collect_and_analyze_scripts() - Recursive script discovery and analysis
  • _scene_resolve_script_reference() - Resolves ExtResource() to actual script paths
  • _scene_build_hierarchy() - Constructs node tree from flat declarations
  • _scene_parse_ext_resource(), _scene_parse_node_declaration(), _scene_parse_signal_connection()

Script Parsing

  • _parse_script_file() - GDScript parser with method body capture
  • _script_parse_method_declaration() - Extracts signatures with parameters and return types
  • _script_parse_variable_declaration() - Handles annotations, type hints, defaults
  • _script_extract_local_var_types() - Infers local variable types from method bodies
  • _script_infer_type_from_literal() - Type inference from literal values

Dependency Analysis

  • _deps_extract_all() - Comprehensive dependency extraction (extends, preload, load, ClassDB, type hints)
  • _deps_get_global_registry() - Global class name resolution via ProjectSettings
  • _deps_extract_class_usages() - Detects registered class usage in code
  • _deps_append_from_type_hints(), _deps_append_from_literals() - Multi-source dependency tracking

Behavioral Analysis

  • _enhance_scene_with_behavioral_analysis() - Aggregates insights from all scene scripts
  • _enhance_script_with_behavioral_analysis() - Enriches script data with patterns and flows
  • _detect_patterns() - Identifies architectural patterns and lifecycle methods
  • _build_method_summaries() - Creates call profiles with internal/external/builtin classification
  • _analyze_scene_usage() - Categorizes node queries, tree manipulation, scene loading, communication
  • _aggregate_insights() - Combines behavioral data across multiple scripts

Signal Intelligence

  • _signals_collect_emissions() - Extracts .emit() and emit_signal() calls with line numbers
  • _signals_extract_from_line() - Parses signal emission patterns
  • _signals_parse_string_literals() - Extracts signal names from string literals

Type Analysis

  • _behavior_is_builtin_call() - Distinguishes builtin methods from custom code using ClassDB
    Variable type registry with class-level, parameter, and local variable tracking
    Method call classification: internal (same script), external (other objects), builtin (engine)

- Implement get_scene_insights for scene file analysis
- Implement get_node_insights for script structure analysis
- Add consolidated behavioral engine (godot_insights.gd)
- Enhance MCP server with new tool handlers
- Update build system for new scripts
- Add comprehensive behavioral analysis capabilities
@ethandaviessmith
Copy link
Author

I wasn't happy with the get_scene_structure PR #48 I put up last month...
Too much bloat in godot_operations.gd, after some testing and iterations decided to break out the code into it's own class, and included insights on nodes (which is called for scripts in scenes) giving the command a better handle on relevant files when analyzing behavior

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.

1 participant