- name
- Function_and_Class_Knowledge_Graph_with_Hooks_v2.0
- version
- 2
- description
- Extends the App Development Blueprint Protocol v2.0 with a "Function & Class Knowledge Graph" mechanism.
Uses functions and classes as core graph nodes to build a complete code-structure knowledge graph
(including inheritance, methods, and dependencies), with hooks for automated triggering, expansion, and updates.
Applicable to OOP languages (Python, Java, TypeScript, Dart, etc.).
- tags
- ["coding-agent","knowledge-graph","class-function-graph","hook","blueprint","oop","ast-parsing"]
- author
- Cosmic Master Brain
- requires
- ["App_Development_Blueprint_Protocol_v2.0","Function_Knowledge_Graph_with_Hooks_v1.0"]
# Function and Class Knowledge Graph with Hooks v2.0 Skill
## Core Mission
During the blueprint planning phase, handle not only functions but also **Classes** simultaneously,
building a more complete code-structure knowledge graph that lets an AI Agent precisely manage
object-oriented design, method encapsulation, inheritance relationships, and dependencies.
## Graph Structure Definition (Extended)
- **Nodes**:
- **Class**: name, responsibility, base class (inheritance), attributes, state (new / existing / modified)
- **Method / Function**: name, responsibility, inputs/outputs, owning class (if a method)
- **Module / File** (if applicable)
- **Spec / Concept**
- **Edges / Relationships** (class-related additions):
- `DEFINES` → Class defines a Method / Function
- `INHERITS_FROM` → Class inherits from another class
- `CONTAINS` → Class contains an Attribute / Method
- `CALLS` → Method / Function calls another Method / Function
- `DEPENDS_ON` → Depends on an existing Class / Function
- `REFERENCES` → References an external library or existing content
- `UPDATES / IMPACTS` → Modification impact scope
- `HOOK_TRIGGER` → Linked to a specific hook
- **Visualization**: Use Mermaid `flowchart TD` or `graph TD`; distinguish classes (rectangles) from functions/methods (ellipses).
## Hook Mechanism (Extended)
1. **pre_blueprint_hook**: Scans existing code, automatically extracts classes, methods, and functions, and adds them to the graph.
2. **on_class_added_hook**: When a new Class is added, auto-inserts it into the graph and checks inheritance / attributes.
3. **on_method_added_hook**: When a new Method is added, creates a `DEFINES` edge linking it to its owning Class.
4. **on_reference_detected_hook**: When an existing Class / Method is detected, immediately expands its full code (Phase 2).
5. **pre_implementation_hook**: Validates class-method consistency and dependency completeness.
6. **post_update_hook**: After any Class or Method modification, updates the graph and computes impact scope (including the inheritance tree).
7. **visualization_hook**: Outputs the complete Mermaid graph (distinguishing classes from functions).
## Integration Flow with App Development Blueprint Protocol v2.0 (auto-executed)
- **Phase 1**: After producing the **Function & Class Inventory**, immediately build and output the knowledge graph (text + Mermaid).
- **Phase 2**: Trigger `on_reference_detected_hook` — automatically expand full code of existing Classes / Methods (including constructors, attributes, methods, etc.).
- **Phase 3**: Produce a formal spec for each Class / Method; add a "relationships in the graph" field.
- **Phase 4**: Trigger relevant hooks, implement each Class / Method one at a time, and update the graph in real time.
- **Final**: Output the complete graph visualization + hook list + main entry point + recommended unit-test structure.
## Usage Rules
- At the start of every task, output: "**Function_and_Class_Knowledge_Graph_with_Hooks_v2.0 + App_Development_Blueprint_Protocol_v2.0 activated**".
- For OOP languages, organize at the Class level first, then decompose into Methods.
- When existing code is provided, automatically trigger `pre_blueprint_hook` for extraction.
- Hooks can be customized per project (e.g., add `on_inheritance_check_hook`).
## Trigger Phrases
"Use the Function & Class Knowledge Graph v2.0 to develop XXX App", "Activate v2.0 Skill", or describe your app requirements directly.
Ver en GitHub