-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhybrid_cli_demo.py
More file actions
266 lines (199 loc) · 7.83 KB
/
Copy pathhybrid_cli_demo.py
File metadata and controls
266 lines (199 loc) · 7.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
"""Hybrid CLI Demo - Skills + Keywords + Natural Language
Demonstrates three levels of user interaction:
1. Claude Code Skills (/dev, /testing, /workflows)
2. Keywords (commit, test, security)
3. Natural language (automatic routing)
Usage:
python examples/hybrid_cli_demo.py
Copyright 2025 Smart-AI-Memory
Licensed under Fair Source License 0.9
"""
import asyncio
import sys
from pathlib import Path
# Add project to path
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
from empathy_os.cli_router import HybridRouter
def print_section(title: str):
"""Print section header."""
print("\n" + "=" * 70)
print(title)
print("=" * 70)
async def demo_level_1_discovery():
"""Level 1: Discovery using Claude Code skills."""
print_section("LEVEL 1: Claude Code Skills")
examples = [
("/help", "Show all available skills"),
("/dev", "Development tools"),
("/testing", "Testing commands"),
("/workflows", "AI-powered workflows"),
]
router = HybridRouter()
for command, description in examples:
print(f"\n💡 {description}")
print(f" In Claude Code: {command}")
result = await router.route(command)
print(f" → Type: {result['type']}")
print(f" → Skill: {result['skill']}")
print(f" → Args: {result['args'] or '(interactive menu)'}")
print(f" → Instruction: {result['instruction']}")
async def demo_level_2_structured():
"""Level 2: Keyword shortcuts for Skills."""
print_section("LEVEL 2: Keywords → Skills")
examples = [
("commit", "Create a git commit", "Skill: /dev commit"),
("test", "Run test suite", "Skill: /testing run"),
("security", "Run security audit", "Skill: /workflows run security-audit"),
("review", "Code review", "Skill: /dev review"),
]
router = HybridRouter()
for keyword, description, usage in examples:
print(f"\n🎯 {description}")
print(f" Maps to: {usage}")
result = await router.route(keyword)
print(f" → Type: {result['type']}")
print(f" → Skill: {result['skill']}")
print(f" → Args: {result['args']}")
print(f" → Confidence: {result['confidence']:.0%}")
async def demo_level_3_natural_language():
"""Level 3: Natural language routing."""
print_section("LEVEL 3: Natural Language")
examples = [
("I want to commit my changes", "Commit workflow"),
("Run security audit on auth.py", "Security analysis"),
("Generate tests for my new feature", "Test generation"),
("Something's slow in the API", "Performance audit"),
]
router = HybridRouter()
for text, description in examples:
print(f"\n💬 User says: \"{text}\"")
print(f" Expected: {description}")
result = await router.route(text)
print(f" → Type: {result['type']}")
print(f" → Skill: {result['skill']}")
print(f" → Args: {result['args']}")
print(f" → Confidence: {result['confidence']:.0%}")
if result.get("reasoning"):
print(f" → Reasoning: {result['reasoning']}")
async def demo_user_preference_learning():
"""Demo: User preference learning."""
print_section("DEMO: User Preference Learning")
router = HybridRouter()
print("\n📚 Learning from user behavior:")
# Scenario: User types "deploy" and chooses "/release prep"
print("\n1. User types: deploy")
print(" Framework suggests: /release prep")
print(" User confirms: y")
# Learn this preference
router.learn_preference("deploy", "/release prep")
print(" ✅ Learned: deploy → /release prep")
# Next time user types "deploy"
print("\n2. User types: deploy (again)")
result = await router.route("deploy")
if result["type"] == "inferred" and result.get("source") == "learned":
print(f" ✅ Auto-inferred: {result['slash_equivalent']}")
print(f" → Confidence: {result['confidence']:.0%}")
print(f" → Usage count: {router.preferences['deploy'].usage_count}")
else:
print(" ℹ️ No learned preference yet")
async def demo_real_world_flow():
"""Demo: Real-world user flow."""
print_section("DEMO: Real-World User Flow")
print("""
📖 Scenario: Developer's typical workflow
1. Morning: Check what to work on (in Claude Code)
/context status
→ Interactive skill menu shows: memory, current tasks, recent activity
2. Start work: Make code changes
[... editing files ...]
3. Run tests quickly (in Claude Code):
/testing run
→ Interactive test runner with options
→ Test suite executes
4. Tests fail - debug (in Claude Code):
/dev debug "tests failing in auth.py"
→ Interactive Socratic debugging
→ Guides you through root cause analysis
5. Fix bugs, run tests again:
/testing run
→ Tests pass ✅
6. Commit changes (in Claude Code):
/dev commit
→ Guided interactive commit creation
→ Reviews changes, suggests message
7. Pre-commit hook triggers (automation):
$ empathy workflow run security-audit
→ Runs: security-audit workflow
→ Finds 5 issues
→ Chain triggers: bug-predict (auto)
→ Chain suggests: code-review (asks approval)
8. End of day (in Claude Code):
/learning evaluate
→ Analyzes session, suggests improvements
💡 Two interfaces, one framework:
- Claude Code skills for interactive work (/dev, /testing, /workflows)
- Workflow commands for automation (CI/CD, hooks, scripts)
- Natural language routing maps to skills
- Simple and focused! ✨
""")
async def demo_suggestions():
"""Demo: Command suggestions."""
print_section("DEMO: Command Suggestions")
router = HybridRouter()
print("\n🔍 Autocomplete suggestions:")
partial_inputs = ["com", "test", "sec", "rev"]
for partial in partial_inputs:
suggestions = router.get_suggestions(partial)
print(f"\n User types: '{partial}'")
print(" Suggestions:")
for suggestion in suggestions[:3]:
print(f" → {suggestion}")
async def main():
"""Run all demos."""
print("=" * 70)
print("HYBRID CLI DEMO")
print("Empathy Framework - Skills + Keywords + Natural Language")
print("=" * 70)
try:
await demo_level_1_discovery()
await demo_level_2_structured()
await demo_level_3_natural_language()
await demo_user_preference_learning()
await demo_suggestions()
await demo_real_world_flow()
print("\n" + "=" * 70)
print("✅ DEMO COMPLETE")
print("=" * 70)
print("""
🎯 Key Takeaways:
1. **Three Input Methods**
- Claude Code skills: Interactive, guided (/dev, /testing, /workflows)
- Natural language: Router maps to skills ("commit my changes" → /dev commit)
- Workflow automation: CI/CD integration (empathy workflow run <name>)
2. **Learning System**
- Framework learns your preferences
- Repeated usage increases confidence
- Personalized experience over time
3. **Real Integration**
- Skills invoke Claude Code functionality
- Natural language maps to real skill invocations
- No fake slash commands - everything works!
4. **Choose Your Interface**
- Interactive work: Use skills in Claude Code
- Natural language: "commit my changes", "run security audit"
- Automation/CI: empathy workflow run <name>
- All methods work together seamlessly
📚 Next Steps:
1. In Claude Code: /help (discover all skills)
2. In Claude Code: /dev commit (interactive commit)
3. Natural language: "debug the login issue"
4. In CI/CD: empathy workflow run security-audit
""")
except Exception as e:
print(f"\n❌ Error: {e}")
import traceback
traceback.print_exc()
return 1
return 0
if __name__ == "__main__":
sys.exit(asyncio.run(main()))