From 4bc4e50c7eb81a33158132a744962f6b4395640d Mon Sep 17 00:00:00 2001 From: Sarosh Quraishi Date: Wed, 20 Aug 2025 11:37:42 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=93=20Complete=20GoF=20Design=20Patter?= =?UTF-8?q?ns=20coverage=20in=20Socratic=20discovery?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add all 23 Gang of Four patterns to /sc:socratic-patterns command - Include comprehensive Socratic questioning for pattern discovery - Add missing structural patterns: Flyweight, Proxy - Add missing behavioral patterns: Chain of Responsibility, Interpreter, Iterator, Mediator, Memento, Visitor - Enhanced discovery methodology with pattern-specific contexts - Complete pattern coverage with intent-focused questioning approach 🔧 Fix SuperClaude entry point import path resolution - Resolve setup module import conflicts - Improve path resolution for local setup directory - Fix installation command execution 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: sarosh.quraishi@gmail.com --- SuperClaude/Commands/socratic-patterns.md | 160 +++++++++++++++++++++- SuperClaude/__main__.py | 37 ++--- 2 files changed, 166 insertions(+), 31 deletions(-) diff --git a/SuperClaude/Commands/socratic-patterns.md b/SuperClaude/Commands/socratic-patterns.md index f487ae5..c69f08b 100644 --- a/SuperClaude/Commands/socratic-patterns.md +++ b/SuperClaude/Commands/socratic-patterns.md @@ -85,6 +85,78 @@ Key behaviors: # "How could you add new product types without changing creation code?" ``` +### Chain of Responsibility Discovery +``` +/sc:socratic-patterns "if (canHandle(request)) { process(); } else { next.handle(request); }" --category behavioral +# Guides discovery through questioning: +# "What happens when this object can't handle the request?" +# "How does the request find someone who can handle it?" +# "What would you do to add a new type of handler?" +``` + +### Iterator Pattern Recognition +``` +/sc:socratic-patterns [collection-traversal-code] --focus structure +# Leads to Iterator pattern discovery: +# "How do you access elements without knowing the internal structure?" +# "What stays the same when you change from Array to LinkedList?" +# "Who's responsible for knowing the current position?" +``` + +### Mediator Pattern Exploration +``` +/sc:socratic-patterns [ui-component-communication] --category behavioral +# Discovers Mediator through questioning: +# "How do these components communicate without knowing about each other?" +# "What happens when you add a new component to the dialog?" +# "Who coordinates the interactions between all these parts?" +``` + +### Flyweight Pattern Discovery +``` +/sc:socratic-patterns [text-editor-character-rendering] --focus structure +# Guides to Flyweight recognition: +# "What data is shared vs unique for each character?" +# "How do you handle thousands of characters efficiently?" +# "What would happen if each character object stored its position?" +``` + +### Proxy Pattern Recognition +``` +/sc:socratic-patterns [remote-object-access] --category structural +# Leads to Proxy pattern discovery: +# "How do you control access to this expensive resource?" +# "What's the difference between the proxy and the real object?" +# "When would you use this instead of accessing directly?" +``` + +### Memento Pattern Exploration +``` +/sc:socratic-patterns [undo-functionality] --focus behavioral +# Discovers Memento through questioning: +# "How do you save state without exposing internal structure?" +# "Who's responsible for managing the saved states?" +# "How do you restore without breaking encapsulation?" +``` + +### Interpreter Pattern Discovery +``` +/sc:socratic-patterns [expression-evaluator] --category behavioral +# Guides to Interpreter recognition: +# "How do you represent each grammar rule as an object?" +# "What happens when you add a new operation to the language?" +# "How does the parse tree get evaluated?" +``` + +### Visitor Pattern Recognition +``` +/sc:socratic-patterns [tree-operations] --focus behavioral +# Leads to Visitor pattern discovery: +# "How do you add new operations without changing the tree nodes?" +# "What's the relationship between the visitor and the elements?" +# "How does double dispatch work here?" +``` + ## Pattern Categories ### Creational Patterns - Object Creation @@ -96,17 +168,25 @@ Key behaviors: ### Structural Patterns - Object Composition - **Adapter**: "How are incompatible interfaces made to work together?" +- **Bridge**: "How is abstraction separated from implementation?" +- **Composite**: "How are individual and composite objects treated uniformly?" - **Decorator**: "How is additional behavior added without changing structure?" - **Facade**: "How is complex subsystem complexity hidden behind simple interface?" -- **Composite**: "How are individual and composite objects treated uniformly?" -- **Bridge**: "How is abstraction separated from implementation?" +- **Flyweight**: "How is memory usage minimized when working with large numbers of similar objects?" +- **Proxy**: "How is access to another object controlled or enhanced?" ### Behavioral Patterns - Object Interaction -- **Observer**: "How are multiple objects notified of state changes?" -- **Strategy**: "How are algorithms made interchangeable?" +- **Chain of Responsibility**: "How is a request passed along a chain until handled?" - **Command**: "How are requests encapsulated as objects?" +- **Interpreter**: "How is a language or notation interpreted and executed?" +- **Iterator**: "How is sequential access provided to elements without exposing structure?" +- **Mediator**: "How do objects interact without referring to each other explicitly?" +- **Memento**: "How is object state captured and restored without violating encapsulation?" +- **Observer**: "How are multiple objects notified of state changes?" - **State**: "How does object behavior change based on internal state?" +- **Strategy**: "How are algorithms made interchangeable?" - **Template Method**: "How is algorithm structure defined with variable steps?" +- **Visitor**: "How are operations added to objects without modifying their structure?" ## Discovery Methodology @@ -155,6 +235,78 @@ flexibility_assessment: - "How does this structure support future changes?" ``` +### Pattern-Specific Discovery Questions + +#### Missing Structural Patterns +```yaml +flyweight_discovery: + context: "Large numbers of similar objects with performance concerns" + key_questions: + - "What data is intrinsic (shared) vs extrinsic (unique) to each object?" + - "How do you handle thousands of similar objects without consuming too much memory?" + - "What happens if you store all state inside each object instance?" + - "How do you separate what varies from what stays constant?" + +proxy_discovery: + context: "Controlled access to another object or resource" + key_questions: + - "How do you control or enhance access to the real object?" + - "What's the difference between the proxy and the actual object?" + - "When would someone use this instead of direct access?" + - "How do you maintain the same interface while adding behavior?" +``` + +#### Missing Behavioral Patterns +```yaml +chain_of_responsibility_discovery: + context: "Request handling along a chain until processed" + key_questions: + - "What happens when this handler can't process the request?" + - "How does the request find the right handler?" + - "How would you add a new type of handler to the chain?" + - "Who decides the order of processing?" + +interpreter_discovery: + context: "Language or expression evaluation systems" + key_questions: + - "How is each grammar rule represented as code?" + - "What happens when you add a new operation to the language?" + - "How do you build and evaluate the parse tree?" + - "Who's responsible for understanding each part of the expression?" + +iterator_discovery: + context: "Sequential access to collection elements" + key_questions: + - "How do you access elements without knowing internal structure?" + - "What stays the same when changing from Array to LinkedList?" + - "Who maintains the current position in traversal?" + - "How do you support multiple simultaneous traversals?" + +mediator_discovery: + context: "Complex interactions between multiple objects" + key_questions: + - "How do these objects communicate without knowing each other?" + - "What happens when you add a new component to the system?" + - "Who coordinates all the interactions?" + - "How do you avoid tight coupling between components?" + +memento_discovery: + context: "State capture and restoration (like undo/redo)" + key_questions: + - "How do you save state without exposing internal structure?" + - "Who's responsible for managing saved states?" + - "How do you restore previous state without breaking encapsulation?" + - "What happens when the object structure changes?" + +visitor_discovery: + context: "Operations on object structures without modification" + key_questions: + - "How do you add new operations without changing existing classes?" + - "What's the relationship between visitor and elements?" + - "How does the object structure collaborate with operations?" + - "What happens when you need different types of traversal?" +``` + ## Learning Outcomes ### Pattern Recognition diff --git a/SuperClaude/__main__.py b/SuperClaude/__main__.py index 0b0ebec..3f9d021 100644 --- a/SuperClaude/__main__.py +++ b/SuperClaude/__main__.py @@ -18,34 +18,17 @@ import difflib from pathlib import Path from typing import Dict, Callable -# Add the 'setup' directory to the Python import path (modern approach) +# Add the local 'setup' directory to the Python import path +current_dir = Path(__file__).parent +project_root = current_dir.parent +setup_dir = project_root / "setup" -try: - # Python 3.9+ preferred way - from importlib.resources import files, as_file - with as_file(files("setup")) as resource: - setup_dir = str(resource) - sys.path.insert(0, setup_dir) -except (ImportError, ModuleNotFoundError, AttributeError): - # Fallback: try to locate setup relative to this file - try: - current_dir = Path(__file__).parent - project_root = current_dir.parent - setup_dir = project_root / "setup" - if setup_dir.exists(): - sys.path.insert(0, str(setup_dir)) - else: - # Last resort: try pkg_resources if available - try: - from pkg_resources import resource_filename - setup_dir = resource_filename('setup', '') - sys.path.insert(0, str(setup_dir)) - except ImportError: - # If all else fails, setup directory should be relative to this file - sys.path.insert(0, str(project_root / "setup")) - except Exception as e: - print(f"Warning: Could not locate setup directory: {e}") - # Continue anyway, imports might still work +# Insert the setup directory at the beginning of sys.path +if setup_dir.exists(): + sys.path.insert(0, str(setup_dir.parent)) +else: + print(f"Warning: Setup directory not found at {setup_dir}") + sys.exit(1) # Try to import utilities from the setup package