Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .env.example +22 -0
- README.md +120 -79
- data/knowledge/skills/git_skills.md +172 -0
- data/knowledge/skills/javascript_skills.md +140 -0
- data/knowledge/skills/python_skills.md +107 -0
- data/knowledge/skills/react_skills.md +163 -0
- data/knowledge/skills/sql_skills.md +180 -0
- data/knowledge/updates/changelog_v1.0.md +58 -0
- data/knowledge/updates/deprecations.md +127 -0
- data/knowledge/updates/roadmap.md +98 -0
- data/knowledge/updates/whats_new_2025.md +67 -0
- data/knowledge/webs/graphql_basics.md +216 -0
- data/knowledge/webs/http_status_codes.md +170 -0
- data/knowledge/webs/rest_api_design.md +144 -0
- data/knowledge/webs/websocket_protocol.md +170 -0
- docs/animation_gallery.md +139 -0
- docs/contributing.md +170 -0
- docs/installation.md +97 -0
- docs/usage.md +146 -0
- examples/demo_animation.py +106 -0
- examples/demo_skill_query.py +102 -0
- examples/demo_thanking.py +95 -0
- requirements.txt +7 -0
- scripts/build_markdown_index.py +155 -0
- scripts/generate_thanks.py +87 -0
- scripts/update_knowledge.py +38 -0
- setup.py +48 -0
- src/__init__.py +10 -0
- src/animations/__init__.py +15 -0
- src/animations/config.py +54 -0
- src/animations/particle_effect.py +177 -0
- src/animations/progress_bar.py +145 -0
- src/animations/spinner.py +89 -0
- src/animations/typing_effect.py +141 -0
- src/cli/__init__.py +7 -0
- src/cli/commands.py +181 -0
- src/cli/interactive.py +164 -0
- src/cli/main.py +82 -0
- src/core/__init__.py +7 -0
- src/core/agent.py +146 -0
- src/core/executor.py +233 -0
- src/core/validator.py +162 -0
- src/knowledge/__init__.py +8 -0
- src/knowledge/cache_manager.py +151 -0
- src/knowledge/local_kb.py +115 -0
- src/knowledge/version_tracker.py +129 -0
- src/knowledge/web_updater.py +154 -0
- src/ui/__init__.py +7 -0
- src/ui/colors.py +195 -0
- src/ui/feedback.py +73 -0
.env.example
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# API Keys
|
| 2 |
+
OPENAI_API_KEY=your_openai_api_key_here
|
| 3 |
+
ANTHROPIC_API_KEY=your_anthropic_api_key_here
|
| 4 |
+
|
| 5 |
+
# Database
|
| 6 |
+
DATABASE_URL=sqlite:///./data/burme_coder.db
|
| 7 |
+
|
| 8 |
+
# Cache
|
| 9 |
+
CACHE_DIR=./data/cache
|
| 10 |
+
CACHE_TTL=3600
|
| 11 |
+
|
| 12 |
+
# Animation Settings
|
| 13 |
+
ANIMATION_SPEED=0.05
|
| 14 |
+
ANIMATION_COLOR=true
|
| 15 |
+
|
| 16 |
+
# Knowledge Base
|
| 17 |
+
KNOWLEDGE_DIR=./data/knowledge
|
| 18 |
+
ENABLE_WEB_UPDATE=false
|
| 19 |
+
|
| 20 |
+
# Logging
|
| 21 |
+
LOG_LEVEL=INFO
|
| 22 |
+
LOG_FILE=./logs/burme_coder.log
|
README.md
CHANGED
|
@@ -1,88 +1,129 @@
|
|
| 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 |
```python
|
| 71 |
-
from
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
-
#
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
print(example['response'])
|
| 80 |
```
|
| 81 |
|
| 82 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🧑💻 Burme-Coder-Max
|
| 2 |
+
|
| 3 |
+
Expert Myanmar AI coding agent - မြန်မာဘာသာဖြင့် ကုဒ်ရေးသင်တန်း AI Agent
|
| 4 |
+
|
| 5 |
+
## 🎯 အဓိက လုပ်ဆောင်ချက်များ
|
| 6 |
+
|
| 7 |
+
- **🗣️ မြန်မာဘာသာ**: မြန်မာစာနဲ့ ကုဒ်ရေးသင်တန်း ပေးနိုင်
|
| 8 |
+
- **💻 Code Examples**: Python, JavaScript, TypeScript, SQL, Go, Rust နဲ့ အခြားဘာသာစကားများ
|
| 9 |
+
- **✨ Terminal Animations**: Spinners, progress bars, particle effects
|
| 10 |
+
- **📚 Knowledge Base**: Local markdown files + web updates
|
| 11 |
+
- **🔄 Auto Update**: Web scraping ကနေ knowledge update
|
| 12 |
+
|
| 13 |
+
## 📦 Installation
|
| 14 |
+
|
| 15 |
+
```bash
|
| 16 |
+
pip install burme-coder-max
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
သို့မဟုတ် source ကနေ install:
|
| 20 |
+
|
| 21 |
+
```bash
|
| 22 |
+
git clone https://github.com/amkyawdev/burme-coder-max.git
|
| 23 |
+
cd burme-coder-max
|
| 24 |
+
pip install -e .
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
## 🚀 Usage
|
| 28 |
+
|
| 29 |
+
### CLI Mode
|
| 30 |
+
|
| 31 |
+
```bash
|
| 32 |
+
burme-coder ask "Python list sorting လုပ်နည်း"
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
### Interactive Mode
|
| 36 |
+
|
| 37 |
+
```bash
|
| 38 |
+
burme-coder interactive
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
### Train Mode
|
| 42 |
+
|
| 43 |
+
```bash
|
| 44 |
+
burme-coder train --data ./data/trajectories
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
## 📁 Project Structure
|
| 48 |
+
|
| 49 |
+
```
|
| 50 |
+
burme-coder-max/
|
| 51 |
+
├── src/
|
| 52 |
+
│ ├── core/ # Agent logic
|
| 53 |
+
│ ├── cli/ # Command line
|
| 54 |
+
│ ├── animations/ # Terminal animations
|
| 55 |
+
│ ├── ui/ # User interface
|
| 56 |
+
│ ├── knowledge/ # Knowledge base
|
| 57 |
+
│ └── utils/ # Utilities
|
| 58 |
+
├── data/
|
| 59 |
+
│ ├── knowledge/ # Markdown files
|
| 60 |
+
│ └── trajectories/ # Training data
|
| 61 |
+
└── tests/ # Unit tests
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
## 🎨 Animations
|
| 65 |
+
|
| 66 |
+
```python
|
| 67 |
+
from animations import Spinner, ProgressBar, TypingEffect
|
| 68 |
+
|
| 69 |
+
# Spinner
|
| 70 |
+
with Spinner("Loading..."):
|
| 71 |
+
do_something()
|
| 72 |
+
|
| 73 |
+
# Progress Bar
|
| 74 |
+
for i in ProgressBar(range(100), description="Processing"):
|
| 75 |
+
process(i)
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
## 🙏 Thanking System
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
from ui.thanking import ThankYou, Appreciation
|
| 82 |
+
|
| 83 |
+
# Simple thank you
|
| 84 |
+
ThankYou.show()
|
| 85 |
+
|
| 86 |
+
# Detailed appreciation
|
| 87 |
+
Appreciation.show("Python decorator")
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## 📚 Knowledge Base
|
| 91 |
|
| 92 |
```python
|
| 93 |
+
from knowledge import LocalKB, WebUpdater
|
| 94 |
|
| 95 |
+
# Local search
|
| 96 |
+
kb = LocalKB()
|
| 97 |
+
results = kb.search("python decorators")
|
| 98 |
|
| 99 |
+
# Web update
|
| 100 |
+
updater = WebUpdater()
|
| 101 |
+
updater.update_from_web()
|
|
|
|
| 102 |
```
|
| 103 |
|
| 104 |
+
## ⚙️ Configuration
|
| 105 |
+
|
| 106 |
+
`.env.example` ကို `.env` အနေဖြင့် ကော်ပြန်ပြင်:
|
| 107 |
+
|
| 108 |
+
```bash
|
| 109 |
+
cp .env.example .env
|
| 110 |
+
# Then edit .env with your API keys
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
## 🧪 Testing
|
| 114 |
+
|
| 115 |
+
```bash
|
| 116 |
+
pytest tests/ -v
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
## 📄 License
|
| 120 |
+
|
| 121 |
+
MIT License - အသုံးပြုခွင့်အခ� Free
|
| 122 |
|
| 123 |
+
## 👨💻 Author
|
| 124 |
|
| 125 |
+
**amkyawdev** - AI Developer
|
| 126 |
|
| 127 |
+
- 🌐 Website: https://amkyawdev.com
|
| 128 |
+
- 💻 GitHub: https://github.com/amkyawdev
|
| 129 |
+
- 🤗 HuggingFace: https://huggingface.co/amkyawdev
|
data/knowledge/skills/git_skills.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Git Skills
|
| 2 |
+
|
| 3 |
+
## Setup & Config
|
| 4 |
+
|
| 5 |
+
```bash
|
| 6 |
+
# Configure user
|
| 7 |
+
git config --global user.name "Your Name"
|
| 8 |
+
git config --global user.email "your@email.com"
|
| 9 |
+
|
| 10 |
+
# Configure editor
|
| 11 |
+
git config --global core.editor vim
|
| 12 |
+
|
| 13 |
+
# List config
|
| 14 |
+
git config --list
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
## Basic Commands
|
| 18 |
+
|
| 19 |
+
### Status & Logs
|
| 20 |
+
```bash
|
| 21 |
+
git status # Show working tree status
|
| 22 |
+
git status -s # Short format
|
| 23 |
+
git log # Show commit history
|
| 24 |
+
git log --oneline # Compact log
|
| 25 |
+
git log -n 5 # Last 5 commits
|
| 26 |
+
git log --graph # Visual branch graph
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
### Add & Commit
|
| 30 |
+
```bash
|
| 31 |
+
git add file.txt # Stage single file
|
| 32 |
+
git add . # Stage all changes
|
| 33 |
+
git add -p # Interactive staging
|
| 34 |
+
git commit -m "message" # Commit with message
|
| 35 |
+
git commit -am "message" # Add + commit (tracked files)
|
| 36 |
+
git commit --amend # Modify last commit
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
### Branching
|
| 40 |
+
```bash
|
| 41 |
+
git branch # List branches
|
| 42 |
+
git branch feature/login # Create branch
|
| 43 |
+
git checkout feature/login # Switch to branch
|
| 44 |
+
git switch -c feature/login # Create and switch (modern)
|
| 45 |
+
git branch -d feature/login # Delete branch
|
| 46 |
+
git branch -m new-name # Rename current branch
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
### Merging
|
| 50 |
+
```bash
|
| 51 |
+
git checkout main
|
| 52 |
+
git merge feature/login # Merge feature into main
|
| 53 |
+
git merge --no-ff feature # No fast-forward merge
|
| 54 |
+
git merge --squash feature # Squash commits
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
### Rebasing
|
| 58 |
+
```bash
|
| 59 |
+
git rebase main # Rebase onto main
|
| 60 |
+
git rebase -i HEAD~3 # Interactive rebase
|
| 61 |
+
git rebase --continue
|
| 62 |
+
git rebase --abort
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
## Remote Operations
|
| 66 |
+
|
| 67 |
+
### Push & Pull
|
| 68 |
+
```bash
|
| 69 |
+
git push origin main # Push to remote
|
| 70 |
+
git push -u origin feature # Push with upstream
|
| 71 |
+
git push --force # Force push (use carefully)
|
| 72 |
+
git pull # Pull and merge
|
| 73 |
+
git pull --rebase # Pull with rebase
|
| 74 |
+
git fetch # Fetch without merge
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
### Remote Management
|
| 78 |
+
```bash
|
| 79 |
+
git remote -v # List remotes
|
| 80 |
+
git remote add origin url # Add remote
|
| 81 |
+
git remote remove origin # Remove remote
|
| 82 |
+
git remote rename origin upstream
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
## Advanced Operations
|
| 86 |
+
|
| 87 |
+
### Stashing
|
| 88 |
+
```bash
|
| 89 |
+
git stash # Stash changes
|
| 90 |
+
git stash pop # Apply and remove stash
|
| 91 |
+
git stash apply # Apply without removing
|
| 92 |
+
git stash list # List stashes
|
| 93 |
+
git stash drop # Delete stash
|
| 94 |
+
git stash -u # Include untracked files
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
### Resetting
|
| 98 |
+
```bash
|
| 99 |
+
git reset HEAD~1 # Reset to commit before last
|
| 100 |
+
git reset --soft HEAD~1 # Keep changes staged
|
| 101 |
+
git reset --hard HEAD~1 # Discard all changes
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
### Cherry Picking
|
| 105 |
+
```bash
|
| 106 |
+
git cherry-pick abc123 # Cherry-pick single commit
|
| 107 |
+
git cherry-pick abc123 def456 # Multiple commits
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
### Tagging
|
| 111 |
+
```bash
|
| 112 |
+
git tag v1.0.0 # Create tag
|
| 113 |
+
git tag -a v1.0.0 -m "Release 1.0" # Annotated tag
|
| 114 |
+
git push origin v1.0.0 # Push tag
|
| 115 |
+
git tag -d v1.0.0 # Delete local tag
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
## Workflow Examples
|
| 119 |
+
|
| 120 |
+
### Feature Branch Workflow
|
| 121 |
+
```bash
|
| 122 |
+
git checkout -b feature/new-feature
|
| 123 |
+
# Make changes
|
| 124 |
+
git add .
|
| 125 |
+
git commit -m "Add new feature"
|
| 126 |
+
git push -u origin feature/new-feature
|
| 127 |
+
# Create PR on GitHub/GitLab
|
| 128 |
+
# After PR merged
|
| 129 |
+
git checkout main
|
| 130 |
+
git pull origin main
|
| 131 |
+
git branch -d feature/new-feature
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
### Hotfix Workflow
|
| 135 |
+
```bash
|
| 136 |
+
git checkout main
|
| 137 |
+
git pull
|
| 138 |
+
git checkout -b hotfix/bug-fix
|
| 139 |
+
# Fix the bug
|
| 140 |
+
git commit -am "Fix critical bug"
|
| 141 |
+
git checkout main
|
| 142 |
+
git merge --no-ff hotfix/bug-fix
|
| 143 |
+
git push origin main
|
| 144 |
+
git branch -d hotfix/bug-fix
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
## Finding & Fixing Issues
|
| 148 |
+
|
| 149 |
+
### Blame & Show
|
| 150 |
+
```bash
|
| 151 |
+
git blame file.txt # Show who changed what
|
| 152 |
+
git show abc123 # Show commit details
|
| 153 |
+
git show abc123:file.txt # Show file at commit
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
### Bisect (Find Bug)
|
| 157 |
+
```bash
|
| 158 |
+
git bisect start
|
| 159 |
+
git bisect bad HEAD
|
| 160 |
+
git bisect good abc123
|
| 161 |
+
# Test...
|
| 162 |
+
git bisect good # or git bisect bad
|
| 163 |
+
git bisect reset
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
### Diff
|
| 167 |
+
```bash
|
| 168 |
+
git diff # Unstaged changes
|
| 169 |
+
git diff --staged # Staged changes
|
| 170 |
+
git diff HEAD~1 # vs previous commit
|
| 171 |
+
git diff main...feature # Changes in feature branch
|
| 172 |
+
```
|
data/knowledge/skills/javascript_skills.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# JavaScript Skills
|
| 2 |
+
|
| 3 |
+
## Variables & Types
|
| 4 |
+
|
| 5 |
+
### Variables
|
| 6 |
+
```javascript
|
| 7 |
+
// Variables
|
| 8 |
+
let name = "JavaScript";
|
| 9 |
+
const PI = 3.14159;
|
| 10 |
+
var oldStyle = "deprecated";
|
| 11 |
+
|
| 12 |
+
// Types
|
| 13 |
+
typeof name; // "string"
|
| 14 |
+
typeof 42; // "number"
|
| 15 |
+
typeof true; // "boolean"
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
## Functions
|
| 19 |
+
|
| 20 |
+
### Regular Function
|
| 21 |
+
```javascript
|
| 22 |
+
function greet(name) {
|
| 23 |
+
return `Hello, ${name}!`;
|
| 24 |
+
}
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
### Arrow Function
|
| 28 |
+
```javascript
|
| 29 |
+
const greet = (name) => `Hello, ${name}!`;
|
| 30 |
+
|
| 31 |
+
// Multi-line
|
| 32 |
+
const multiply = (a, b) => {
|
| 33 |
+
return a * b;
|
| 34 |
+
};
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
### Callback
|
| 38 |
+
```javascript
|
| 39 |
+
const processData = (data, callback) => {
|
| 40 |
+
const result = doSomething(data);
|
| 41 |
+
callback(result);
|
| 42 |
+
};
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
## Arrays
|
| 46 |
+
|
| 47 |
+
### Array Methods
|
| 48 |
+
```javascript
|
| 49 |
+
const arr = [1, 2, 3, 4, 5];
|
| 50 |
+
|
| 51 |
+
// map - transform
|
| 52 |
+
arr.map(x => x * 2); // [2, 4, 6, 8, 10]
|
| 53 |
+
|
| 54 |
+
// filter - select
|
| 55 |
+
arr.filter(x => x > 2); // [3, 4, 5]
|
| 56 |
+
|
| 57 |
+
// reduce - accumulate
|
| 58 |
+
arr.reduce((sum, x) => sum + x, 0); // 15
|
| 59 |
+
|
| 60 |
+
// find - search
|
| 61 |
+
arr.find(x => x === 3); // 3
|
| 62 |
+
|
| 63 |
+
// forEach - iterate
|
| 64 |
+
arr.forEach(x => console.log(x));
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
## Objects & Destructuring
|
| 68 |
+
|
| 69 |
+
### Object
|
| 70 |
+
```javascript
|
| 71 |
+
const person = {
|
| 72 |
+
name: "John",
|
| 73 |
+
age: 30,
|
| 74 |
+
greet() {
|
| 75 |
+
return `Hello, I'm ${this.name}`;
|
| 76 |
+
}
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
// Access
|
| 80 |
+
person.name;
|
| 81 |
+
person['age'];
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
### Destructuring
|
| 85 |
+
```javascript
|
| 86 |
+
const { name, age } = person;
|
| 87 |
+
const [first, second] = arr;
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## Async/Await & Promise
|
| 91 |
+
|
| 92 |
+
### Promise
|
| 93 |
+
```javascript
|
| 94 |
+
const fetchData = () => {
|
| 95 |
+
return new Promise((resolve, reject) => {
|
| 96 |
+
setTimeout(() => {
|
| 97 |
+
resolve("data");
|
| 98 |
+
}, 1000);
|
| 99 |
+
});
|
| 100 |
+
};
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
### Async/Await
|
| 104 |
+
```javascript
|
| 105 |
+
const getData = async () => {
|
| 106 |
+
try {
|
| 107 |
+
const response = await fetch(url);
|
| 108 |
+
const data = await response.json();
|
| 109 |
+
return data;
|
| 110 |
+
} catch (error) {
|
| 111 |
+
console.error(error);
|
| 112 |
+
}
|
| 113 |
+
};
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
### Promise.all
|
| 117 |
+
```javascript
|
| 118 |
+
const [result1, result2] = await Promise.all([
|
| 119 |
+
fetch(url1),
|
| 120 |
+
fetch(url2)
|
| 121 |
+
]);
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
## Common Patterns
|
| 125 |
+
|
| 126 |
+
### Optional Chaining
|
| 127 |
+
```javascript
|
| 128 |
+
const value = obj?.nested?.property ?? "default";
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
### Nullish Coalescing
|
| 132 |
+
```javascript
|
| 133 |
+
const value = input ?? "default value";
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
### Spread Operator
|
| 137 |
+
```javascript
|
| 138 |
+
const merged = { ...obj1, ...obj2 };
|
| 139 |
+
const combined = [...arr1, ...arr2];
|
| 140 |
+
```
|
data/knowledge/skills/python_skills.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python Skills
|
| 2 |
+
|
| 3 |
+
## Python Basics
|
| 4 |
+
|
| 5 |
+
### Variables
|
| 6 |
+
```python
|
| 7 |
+
name = "Python"
|
| 8 |
+
age = 25
|
| 9 |
+
is_active = True
|
| 10 |
+
```
|
| 11 |
+
|
| 12 |
+
### Data Types
|
| 13 |
+
- **int** - Integer: `42`
|
| 14 |
+
- **float** - Decimal: `3.14`
|
| 15 |
+
- **str** - String: `"Hello"`
|
| 16 |
+
- **bool** - Boolean: `True/False`
|
| 17 |
+
- **list** - List: `[1, 2, 3]`
|
| 18 |
+
- **dict** - Dictionary: `{"key": "value"}`
|
| 19 |
+
|
| 20 |
+
### Functions
|
| 21 |
+
```python
|
| 22 |
+
def greet(name: str) -> str:
|
| 23 |
+
"""Return a greeting message."""
|
| 24 |
+
return f"Hello, {name}!"
|
| 25 |
+
|
| 26 |
+
# Lambda function
|
| 27 |
+
square = lambda x: x ** 2
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
### Control Flow
|
| 31 |
+
```python
|
| 32 |
+
if condition:
|
| 33 |
+
do_something()
|
| 34 |
+
elif other_condition:
|
| 35 |
+
do_other()
|
| 36 |
+
else:
|
| 37 |
+
do_default()
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
### Loops
|
| 41 |
+
```python
|
| 42 |
+
# For loop
|
| 43 |
+
for item in items:
|
| 44 |
+
print(item)
|
| 45 |
+
|
| 46 |
+
# While loop
|
| 47 |
+
while condition:
|
| 48 |
+
do_something()
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
## Advanced Topics
|
| 52 |
+
|
| 53 |
+
### Decorators
|
| 54 |
+
```python
|
| 55 |
+
def my_decorator(func):
|
| 56 |
+
def wrapper():
|
| 57 |
+
print("Before")
|
| 58 |
+
func()
|
| 59 |
+
print("After")
|
| 60 |
+
return wrapper
|
| 61 |
+
|
| 62 |
+
@my_decorator
|
| 63 |
+
def say_hello():
|
| 64 |
+
print("Hello!")
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
### Classes
|
| 68 |
+
```python
|
| 69 |
+
class Person:
|
| 70 |
+
def __init__(self, name: str, age: int):
|
| 71 |
+
self.name = name
|
| 72 |
+
self.age = age
|
| 73 |
+
|
| 74 |
+
def __str__(self) -> str:
|
| 75 |
+
return f"{self.name}, {self.age} years old"
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
### Exception Handling
|
| 79 |
+
```python
|
| 80 |
+
try:
|
| 81 |
+
result = risky_operation()
|
| 82 |
+
except ValueError as e:
|
| 83 |
+
print(f"Error: {e}")
|
| 84 |
+
finally:
|
| 85 |
+
cleanup()
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
### List Comprehensions
|
| 89 |
+
```python
|
| 90 |
+
squares = [x**2 for x in range(10)]
|
| 91 |
+
evens = [x for x in range(20) if x % 2 == 0]
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### Context Managers
|
| 95 |
+
```python
|
| 96 |
+
with open('file.txt', 'r') as f:
|
| 97 |
+
content = f.read()
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
### Async/Await (asyncio)
|
| 101 |
+
```python
|
| 102 |
+
import asyncio
|
| 103 |
+
|
| 104 |
+
async def fetch_data():
|
| 105 |
+
await asyncio.sleep(1)
|
| 106 |
+
return "data"
|
| 107 |
+
```
|
data/knowledge/skills/react_skills.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# React Skills
|
| 2 |
+
|
| 3 |
+
## Hooks
|
| 4 |
+
|
| 5 |
+
### useState
|
| 6 |
+
```jsx
|
| 7 |
+
import { useState } from 'react';
|
| 8 |
+
|
| 9 |
+
function Counter() {
|
| 10 |
+
const [count, setCount] = useState(0);
|
| 11 |
+
|
| 12 |
+
return (
|
| 13 |
+
<div>
|
| 14 |
+
<p>Count: {count}</p>
|
| 15 |
+
<button onClick={() => setCount(count + 1)}>
|
| 16 |
+
Increment
|
| 17 |
+
</button>
|
| 18 |
+
</div>
|
| 19 |
+
);
|
| 20 |
+
}
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
### useEffect
|
| 24 |
+
```jsx
|
| 25 |
+
import { useState, useEffect } from 'react';
|
| 26 |
+
|
| 27 |
+
function DataFetcher({ url }) {
|
| 28 |
+
const [data, setData] = useState(null);
|
| 29 |
+
const [loading, setLoading] = useState(true);
|
| 30 |
+
|
| 31 |
+
useEffect(() => {
|
| 32 |
+
fetch(url)
|
| 33 |
+
.then(res => res.json())
|
| 34 |
+
.then(data => {
|
| 35 |
+
setData(data);
|
| 36 |
+
setLoading(false);
|
| 37 |
+
});
|
| 38 |
+
}, [url]);
|
| 39 |
+
|
| 40 |
+
return loading ? <p>Loading...</p> : <div>{data}</div>;
|
| 41 |
+
}
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
### useContext
|
| 45 |
+
```jsx
|
| 46 |
+
import { createContext, useContext } from 'react';
|
| 47 |
+
|
| 48 |
+
const ThemeContext = createContext('light');
|
| 49 |
+
|
| 50 |
+
function App() {
|
| 51 |
+
return (
|
| 52 |
+
<ThemeContext.Provider value="dark">
|
| 53 |
+
<Child />
|
| 54 |
+
</ThemeContext.Provider>
|
| 55 |
+
);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
function Child() {
|
| 59 |
+
const theme = useContext(ThemeContext);
|
| 60 |
+
return <div className={theme}>Theme: {theme}</div>;
|
| 61 |
+
}
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
### useReducer
|
| 65 |
+
```jsx
|
| 66 |
+
import { useReducer } from 'react';
|
| 67 |
+
|
| 68 |
+
const initialState = { count: 0 };
|
| 69 |
+
|
| 70 |
+
function reducer(state, action) {
|
| 71 |
+
switch (action.type) {
|
| 72 |
+
case 'increment':
|
| 73 |
+
return { count: state.count + 1 };
|
| 74 |
+
case 'decrement':
|
| 75 |
+
return { count: state.count - 1 };
|
| 76 |
+
default:
|
| 77 |
+
return state;
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
function Counter() {
|
| 82 |
+
const [state, dispatch] = useReducer(reducer, initialState);
|
| 83 |
+
|
| 84 |
+
return (
|
| 85 |
+
<div>
|
| 86 |
+
<p>{state.count}</p>
|
| 87 |
+
<button onClick={() => dispatch({ type: 'increment' })}>
|
| 88 |
+
+
|
| 89 |
+
</button>
|
| 90 |
+
</div>
|
| 91 |
+
);
|
| 92 |
+
}
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
### Custom Hooks
|
| 96 |
+
```jsx
|
| 97 |
+
function useLocalStorage(key, initialValue) {
|
| 98 |
+
const [storedValue, setStoredValue] = useState(() => {
|
| 99 |
+
try {
|
| 100 |
+
const item = window.localStorage.getItem(key);
|
| 101 |
+
return item ? JSON.parse(item) : initialValue;
|
| 102 |
+
} catch (error) {
|
| 103 |
+
return initialValue;
|
| 104 |
+
}
|
| 105 |
+
});
|
| 106 |
+
|
| 107 |
+
const setValue = (value) => {
|
| 108 |
+
setStoredValue(value);
|
| 109 |
+
window.localStorage.setItem(key, JSON.stringify(value));
|
| 110 |
+
};
|
| 111 |
+
|
| 112 |
+
return [storedValue, setValue];
|
| 113 |
+
}
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
## Components
|
| 117 |
+
|
| 118 |
+
### Functional Component
|
| 119 |
+
```jsx
|
| 120 |
+
function Welcome({ name, age }) {
|
| 121 |
+
return (
|
| 122 |
+
<div className="welcome">
|
| 123 |
+
<h1>Hello, {name}!</h1>
|
| 124 |
+
<p>Age: {age}</p>
|
| 125 |
+
</div>
|
| 126 |
+
);
|
| 127 |
+
}
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
### Props
|
| 131 |
+
```jsx
|
| 132 |
+
// Parent
|
| 133 |
+
<Welcome name="John" age={30} />
|
| 134 |
+
|
| 135 |
+
// Child - receieves props
|
| 136 |
+
function Welcome(props) {
|
| 137 |
+
return <h1>Hello {props.name}</h1>;
|
| 138 |
+
}
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
## Forms
|
| 142 |
+
|
| 143 |
+
### Controlled Input
|
| 144 |
+
```jsx
|
| 145 |
+
function Form() {
|
| 146 |
+
const [name, setName] = useState('');
|
| 147 |
+
|
| 148 |
+
const handleSubmit = (e) => {
|
| 149 |
+
e.preventDefault();
|
| 150 |
+
console.log(name);
|
| 151 |
+
};
|
| 152 |
+
|
| 153 |
+
return (
|
| 154 |
+
<form onSubmit={handleSubmit}>
|
| 155 |
+
<input
|
| 156 |
+
value={name}
|
| 157 |
+
onChange={(e) => setName(e.target.value)}
|
| 158 |
+
/>
|
| 159 |
+
<button type="submit">Submit</button>
|
| 160 |
+
</form>
|
| 161 |
+
);
|
| 162 |
+
}
|
| 163 |
+
```
|
data/knowledge/skills/sql_skills.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SQL Skills
|
| 2 |
+
|
| 3 |
+
## Basic Queries
|
| 4 |
+
|
| 5 |
+
### SELECT
|
| 6 |
+
```sql
|
| 7 |
+
-- All columns
|
| 8 |
+
SELECT * FROM users;
|
| 9 |
+
|
| 10 |
+
-- Specific columns
|
| 11 |
+
SELECT name, email, created_at FROM users;
|
| 12 |
+
|
| 13 |
+
-- With alias
|
| 14 |
+
SELECT name AS user_name FROM users;
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
### WHERE
|
| 18 |
+
```sql
|
| 19 |
+
SELECT * FROM products WHERE price > 100;
|
| 20 |
+
|
| 21 |
+
SELECT * FROM users
|
| 22 |
+
WHERE age >= 18 AND status = 'active';
|
| 23 |
+
|
| 24 |
+
SELECT * FROM orders
|
| 25 |
+
WHERE created_at BETWEEN '2024-01-01' AND '2024-12-31';
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
### ORDER BY
|
| 29 |
+
```sql
|
| 30 |
+
SELECT * FROM products
|
| 31 |
+
ORDER BY price ASC;
|
| 32 |
+
|
| 33 |
+
SELECT * FROM users
|
| 34 |
+
ORDER BY created_at DESC, name ASC;
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
### LIMIT
|
| 38 |
+
```sql
|
| 39 |
+
SELECT * FROM users LIMIT 10;
|
| 40 |
+
|
| 41 |
+
SELECT * FROM products
|
| 42 |
+
ORDER BY price DESC LIMIT 5;
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
## JOIN Operations
|
| 46 |
+
|
| 47 |
+
### INNER JOIN
|
| 48 |
+
```sql
|
| 49 |
+
SELECT u.name, o.order_id, o.total
|
| 50 |
+
FROM users u
|
| 51 |
+
INNER JOIN orders o ON u.id = o.user_id;
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
### LEFT JOIN
|
| 55 |
+
```sql
|
| 56 |
+
SELECT u.name, o.order_id
|
| 57 |
+
FROM users u
|
| 58 |
+
LEFT JOIN orders o ON u.id = o.user_id;
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
### RIGHT JOIN
|
| 62 |
+
```sql
|
| 63 |
+
SELECT u.name, o.order_id
|
| 64 |
+
FROM users u
|
| 65 |
+
RIGHT JOIN orders o ON u.id = o.user_id;
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
### Multiple JOINs
|
| 69 |
+
```sql
|
| 70 |
+
SELECT u.name, o.order_id, p.product_name
|
| 71 |
+
FROM users u
|
| 72 |
+
INNER JOIN orders o ON u.id = o.user_id
|
| 73 |
+
INNER JOIN order_items oi ON o.id = oi.order_id
|
| 74 |
+
INNER JOIN products p ON oi.product_id = p.id;
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
## Aggregations
|
| 78 |
+
|
| 79 |
+
### COUNT, SUM, AVG, MIN, MAX
|
| 80 |
+
```sql
|
| 81 |
+
SELECT COUNT(*) FROM users;
|
| 82 |
+
SELECT SUM(amount) FROM orders;
|
| 83 |
+
SELECT AVG(price) FROM products;
|
| 84 |
+
SELECT MIN(created_at) FROM orders;
|
| 85 |
+
SELECT MAX(price) FROM products;
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
### GROUP BY
|
| 89 |
+
```sql
|
| 90 |
+
SELECT category, COUNT(*) as count
|
| 91 |
+
FROM products
|
| 92 |
+
GROUP BY category;
|
| 93 |
+
|
| 94 |
+
SELECT user_id, SUM(total) as total_spent
|
| 95 |
+
FROM orders
|
| 96 |
+
GROUP BY user_id
|
| 97 |
+
HAVING SUM(total) > 1000;
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
## Subqueries
|
| 101 |
+
```sql
|
| 102 |
+
-- In WHERE
|
| 103 |
+
SELECT * FROM products
|
| 104 |
+
WHERE price > (SELECT AVG(price) FROM products);
|
| 105 |
+
|
| 106 |
+
-- In FROM
|
| 107 |
+
SELECT category, avg_price
|
| 108 |
+
FROM (
|
| 109 |
+
SELECT category, AVG(price) as avg_price
|
| 110 |
+
FROM products
|
| 111 |
+
GROUP BY category
|
| 112 |
+
) AS stats;
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
## INSERT, UPDATE, DELETE
|
| 116 |
+
|
| 117 |
+
### INSERT
|
| 118 |
+
```sql
|
| 119 |
+
INSERT INTO users (name, email, age)
|
| 120 |
+
VALUES ('John', 'john@email.com', 25);
|
| 121 |
+
|
| 122 |
+
INSERT INTO users (name, email)
|
| 123 |
+
SELECT name, email FROM temp_users;
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
### UPDATE
|
| 127 |
+
```sql
|
| 128 |
+
UPDATE users
|
| 129 |
+
SET age = 26, status = 'active'
|
| 130 |
+
WHERE id = 1;
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
### DELETE
|
| 134 |
+
```sql
|
| 135 |
+
DELETE FROM users WHERE id = 1;
|
| 136 |
+
|
| 137 |
+
DELETE FROM orders
|
| 138 |
+
WHERE created_at < '2024-01-01';
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
## Common Patterns
|
| 142 |
+
|
| 143 |
+
### Finding Duplicates
|
| 144 |
+
```sql
|
| 145 |
+
SELECT email, COUNT(*) as count
|
| 146 |
+
FROM users
|
| 147 |
+
GROUP BY email
|
| 148 |
+
HAVING COUNT(*) > 1;
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
### Second Highest
|
| 152 |
+
```sql
|
| 153 |
+
SELECT MAX(salary) FROM employees
|
| 154 |
+
WHERE salary < (SELECT MAX(salary) FROM employees);
|
| 155 |
+
|
| 156 |
+
-- Or using OFFSET
|
| 157 |
+
SELECT salary FROM employees
|
| 158 |
+
ORDER BY salary DESC LIMIT 1 OFFSET 1;
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
### Date Functions
|
| 162 |
+
```sql
|
| 163 |
+
SELECT DATE(created_at) as date, COUNT(*) as orders
|
| 164 |
+
FROM orders
|
| 165 |
+
GROUP BY DATE(created_at);
|
| 166 |
+
|
| 167 |
+
SELECT * FROM orders
|
| 168 |
+
WHERE EXTRACT(YEAR FROM created_at) = 2024;
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
### Case Statement
|
| 172 |
+
```sql
|
| 173 |
+
SELECT name,
|
| 174 |
+
CASE
|
| 175 |
+
WHEN age < 18 THEN 'Minor'
|
| 176 |
+
WHEN age < 65 THEN 'Adult'
|
| 177 |
+
ELSE 'Senior'
|
| 178 |
+
END as age_group
|
| 179 |
+
FROM users;
|
| 180 |
+
```
|
data/knowledge/updates/changelog_v1.0.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Changelog v1.0.0
|
| 2 |
+
|
| 3 |
+
## Version 1.0.0 - Initial Release
|
| 4 |
+
**Date:** January 1, 2025
|
| 5 |
+
|
| 6 |
+
### New Features
|
| 7 |
+
- ✅ Core agent functionality
|
| 8 |
+
- ✅ Myanmar language support
|
| 9 |
+
- ✅ Terminal animations (spinners, progress bars)
|
| 10 |
+
- ✅ Knowledge base with markdown files
|
| 11 |
+
- ✅ Interactive CLI mode
|
| 12 |
+
- ✅ Local knowledge search
|
| 13 |
+
- ✅ Code validation
|
| 14 |
+
|
| 15 |
+
### Modules Added
|
| 16 |
+
- `src/core/` - Agent, executor, validator
|
| 17 |
+
- `src/cli/` - Command line interface
|
| 18 |
+
- `src/animations/` - Terminal animations
|
| 19 |
+
- `src/ui/` - User interface components
|
| 20 |
+
- `src/knowledge/` - Knowledge management
|
| 21 |
+
- `src/utils/` - Utility functions
|
| 22 |
+
|
| 23 |
+
### Skills Coverage
|
| 24 |
+
- Python
|
| 25 |
+
- JavaScript
|
| 26 |
+
- TypeScript
|
| 27 |
+
- React
|
| 28 |
+
- SQL
|
| 29 |
+
- Git
|
| 30 |
+
- REST API
|
| 31 |
+
- WebSocket
|
| 32 |
+
- GraphQL
|
| 33 |
+
|
| 34 |
+
### Known Issues
|
| 35 |
+
- None
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## Version 0.9.0 - Beta Preview
|
| 40 |
+
**Date:** December 15, 2024
|
| 41 |
+
|
| 42 |
+
### Features
|
| 43 |
+
- Prototype agent
|
| 44 |
+
- Basic animations
|
| 45 |
+
- Initial skill set
|
| 46 |
+
|
| 47 |
+
### Changes
|
| 48 |
+
- Migrated to argparse → Click
|
| 49 |
+
- Added Rich library for better UI
|
| 50 |
+
|
| 51 |
+
---
|
| 52 |
+
|
| 53 |
+
## Version 0.5.0 - Alpha
|
| 54 |
+
**Date:** December 1, 2024
|
| 55 |
+
|
| 56 |
+
### Initial Development
|
| 57 |
+
- Project setup
|
| 58 |
+
- Basic structure
|
data/knowledge/updates/deprecations.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Deprecations
|
| 2 |
+
|
| 3 |
+
## Overview
|
| 4 |
+
|
| 5 |
+
This document tracks deprecated features and their removal schedule.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## Version 1.0.0 Deprecations
|
| 10 |
+
|
| 11 |
+
### Legacy Animation API
|
| 12 |
+
**Deprecated:** v1.0.0
|
| 13 |
+
**Will be removed:** v1.2.0
|
| 14 |
+
|
| 15 |
+
Old way (deprecated):
|
| 16 |
+
```python
|
| 17 |
+
from animations import OldSpinner
|
| 18 |
+
s = OldSpinner()
|
| 19 |
+
s.start()
|
| 20 |
+
```
|
| 21 |
+
|
| 22 |
+
New way (recommended):
|
| 23 |
+
```python
|
| 24 |
+
from animations import Spinner
|
| 25 |
+
with Spinner("Loading..."):
|
| 26 |
+
do_something()
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
---
|
| 30 |
+
|
| 31 |
+
## Version 0.9.0 Deprecations
|
| 32 |
+
|
| 33 |
+
### Python 3.7 Support
|
| 34 |
+
**Deprecated:** v0.9.0
|
| 35 |
+
**Will be removed:** v2.0.0
|
| 36 |
+
|
| 37 |
+
Python 3 support timeline:
|
| 38 |
+
- Python 3.7 - Deprecated in v0.9.0
|
| 39 |
+
- Python 3.8 - Supported
|
| 40 |
+
- Python 3.9 - Supported
|
| 41 |
+
- Python 3.10 - Supported
|
| 42 |
+
- Python 3.11 - Supported
|
| 43 |
+
- Python 3.12 - Planned support
|
| 44 |
+
|
| 45 |
+
### Legacy CLI format
|
| 46 |
+
**Deprecated:** v0.9.0
|
| 47 |
+
**Will be removed:** v1.1.0
|
| 48 |
+
|
| 49 |
+
Old CLI (deprecated):
|
| 50 |
+
```bash
|
| 51 |
+
burme-coder run "question"
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
New CLI (recommended):
|
| 55 |
+
```bash
|
| 56 |
+
burme-coder ask "question"
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## Migration Guides
|
| 62 |
+
|
| 63 |
+
### From v0.9.x to v1.0.0
|
| 64 |
+
|
| 65 |
+
1. **Update dependencies:**
|
| 66 |
+
```bash
|
| 67 |
+
pip install --upgrade burme-coder-max
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
2. **Update CLI commands:**
|
| 71 |
+
```bash
|
| 72 |
+
# Old (deprecated)
|
| 73 |
+
burme-coder run "question"
|
| 74 |
+
|
| 75 |
+
# New
|
| 76 |
+
burme-coder ask "question"
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
3. **Update animation imports:**
|
| 80 |
+
```python
|
| 81 |
+
# Old (deprecated)
|
| 82 |
+
from animations import OldSpinner
|
| 83 |
+
|
| 84 |
+
# New
|
| 85 |
+
from animations import Spinner
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
+
|
| 90 |
+
## Removed Features
|
| 91 |
+
|
| 92 |
+
### v1.0.0
|
| 93 |
+
No features removed in v1.0.0 (initial release)
|
| 94 |
+
|
| 95 |
+
### Planned Removals
|
| 96 |
+
| Feature | Version | Reason |
|
| 97 |
+
|---------|---------|--------|
|
| 98 |
+
| OldSpinner class | v1.2.0 | Improved API |
|
| 99 |
+
| Python 3.7 | v2.0.0 | Security |
|
| 100 |
+
| Legacy CLI | v1.1.0 | Clarity |
|
| 101 |
+
|
| 102 |
+
---
|
| 103 |
+
|
| 104 |
+
## Best Practices
|
| 105 |
+
|
| 106 |
+
1. Always use recommended patterns
|
| 107 |
+
2. Check deprecation warnings
|
| 108 |
+
3. Update before major version changes
|
| 109 |
+
4. Report issues if migration is difficult
|
| 110 |
+
|
| 111 |
+
### Enable Deprecation Warnings
|
| 112 |
+
```python
|
| 113 |
+
import warnings
|
| 114 |
+
warnings.filterwarnings('default', category=DeprecationWarning)
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
---
|
| 118 |
+
|
| 119 |
+
## Questions?
|
| 120 |
+
|
| 121 |
+
If you have questions about deprecations:
|
| 122 |
+
- 📧 Email: contact@amkyawdev.com
|
| 123 |
+
- 💬 GitHub Discussions
|
| 124 |
+
|
| 125 |
+
---
|
| 126 |
+
|
| 127 |
+
*Last updated: January 2025*
|
data/knowledge/updates/roadmap.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Project Roadmap
|
| 2 |
+
|
| 3 |
+
## Overview
|
| 4 |
+
|
| 5 |
+
This roadmap outlines the planned development for Burme-Coder-Max.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## Version 1.1.0 - Enhanced Animations
|
| 10 |
+
**Target:** Q2 2025
|
| 11 |
+
|
| 12 |
+
### Features
|
| 13 |
+
- [ ] Particle effects with custom colors
|
| 14 |
+
- [ ] Progress bar with ETA display
|
| 15 |
+
- [ ] Terminal-based charts
|
| 16 |
+
- [ ] Custom animation themes
|
| 17 |
+
- [ ] Animation presets
|
| 18 |
+
|
| 19 |
+
### Improvements
|
| 20 |
+
- [ ] Faster animation rendering
|
| 21 |
+
- [ ] Reduced CPU usage
|
| 22 |
+
- [ ] Better cross-terminal support
|
| 23 |
+
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## Version 1.2.0 - Web Interface
|
| 27 |
+
**Target:** Q3 2025
|
| 28 |
+
|
| 29 |
+
### Features
|
| 30 |
+
- [ ] Web dashboard
|
| 31 |
+
- [ ] REST API server
|
| 32 |
+
- [ ] WebSocket real-time updates
|
| 33 |
+
- [ ] User authentication
|
| 34 |
+
- [ ] History tracking
|
| 35 |
+
|
| 36 |
+
### Technical
|
| 37 |
+
- [ ] FastAPI integration
|
| 38 |
+
- [ ] Redis caching
|
| 39 |
+
- [ ] PostgreSQL database
|
| 40 |
+
- [ ] Docker deployment
|
| 41 |
+
|
| 42 |
+
---
|
| 43 |
+
|
| 44 |
+
## Version 1.3.0 - Advanced Intelligence
|
| 45 |
+
**Target:** Q4 2025
|
| 46 |
+
|
| 47 |
+
### Features
|
| 48 |
+
- [ ] Code generation with GPT-4
|
| 49 |
+
- [ ] Multi-model support
|
| 50 |
+
- [ ] Context-aware suggestions
|
| 51 |
+
- [ ] Learning from user feedback
|
| 52 |
+
- [ ] Custom personality settings
|
| 53 |
+
|
| 54 |
+
### Training
|
| 55 |
+
- [ ] Fine-tuning on Myanmar code
|
| 56 |
+
- [ ] Custom skill training
|
| 57 |
+
- [ ] Domain-specific models
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## Version 2.0.0 - Production Release
|
| 62 |
+
**Target:** 2026
|
| 63 |
+
|
| 64 |
+
### Infrastructure
|
| 65 |
+
- [ ] Cloud deployment
|
| 66 |
+
- [ ] Auto-scaling
|
| 67 |
+
- [ ] CDN integration
|
| 68 |
+
- [ ] SLA guarantees
|
| 69 |
+
|
| 70 |
+
### Enterprise Features
|
| 71 |
+
- [ ] Team collaboration
|
| 72 |
+
- [ ] Organization management
|
| 73 |
+
- [ ] Usage analytics
|
| 74 |
+
- [ ] Custom branding
|
| 75 |
+
- [ ] API rate limits
|
| 76 |
+
|
| 77 |
+
---
|
| 78 |
+
|
| 79 |
+
## Deprecation Timeline
|
| 80 |
+
|
| 81 |
+
| Feature | Deprecated | Removed |
|
| 82 |
+
|---------|------------|---------|
|
| 83 |
+
| Old animation API | v1.0.0 | v1.2.0 |
|
| 84 |
+
| Python 3.7 support | v1.1.0 | v2.0.0 |
|
| 85 |
+
| Legacy CLI format | v1.0.0 | v1.1.0 |
|
| 86 |
+
|
| 87 |
+
---
|
| 88 |
+
|
| 89 |
+
## Feedback
|
| 90 |
+
|
| 91 |
+
We value your input! Please share your feedback:
|
| 92 |
+
- 📧 Email: contact@amkyawdev.com
|
| 93 |
+
- 💬 GitHub Issues
|
| 94 |
+
- 🤝 Community Discord
|
| 95 |
+
|
| 96 |
+
---
|
| 97 |
+
|
| 98 |
+
*Last updated: January 2025*
|
data/knowledge/updates/whats_new_2025.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# What's New in 2025
|
| 2 |
+
|
| 3 |
+
## Latest Updates
|
| 4 |
+
|
| 5 |
+
### January 2025 - v1.0.0 Release
|
| 6 |
+
- 🎉 Full release with all core features
|
| 7 |
+
- 📚 Comprehensive documentation
|
| 8 |
+
- ✨ New terminal animations
|
| 9 |
+
- 🔧 Improved code validator
|
| 10 |
+
- 🌐 Web knowledge updater
|
| 11 |
+
|
| 12 |
+
### December 2024 - v0.9.0 Beta
|
| 13 |
+
- 🚀 Performance improvements
|
| 14 |
+
- 🎨 Enhanced UI with Rich library
|
| 15 |
+
- 💬 Better interactive mode
|
| 16 |
+
- 🐛 Bug fixes
|
| 17 |
+
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
## Roadmap Highlights
|
| 21 |
+
|
| 22 |
+
### Coming Soon (v1.1.0)
|
| 23 |
+
- ⭐ Enhanced animation effects
|
| 24 |
+
- 📱 Web interface
|
| 25 |
+
- 🔌 REST API server
|
| 26 |
+
|
| 27 |
+
### Planned (v1.2.0)
|
| 28 |
+
- 🌐 Cloud sync
|
| 29 |
+
- 🤖 Model fine-tuning
|
| 30 |
+
- 📊 Analytics dashboard
|
| 31 |
+
|
| 32 |
+
### Future (v2.0.0)
|
| 33 |
+
- 🚀 Production deployment
|
| 34 |
+
- 🔒 Enhanced security
|
| 35 |
+
- 📦 Plugin system
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## How to Stay Updated
|
| 40 |
+
|
| 41 |
+
```bash
|
| 42 |
+
# Check current version
|
| 43 |
+
burme-coder --version
|
| 44 |
+
|
| 45 |
+
# Update to latest
|
| 46 |
+
pip install --upgrade burme-coder-max
|
| 47 |
+
|
| 48 |
+
# View changelog
|
| 49 |
+
burme-coder changelog
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
---
|
| 53 |
+
|
| 54 |
+
## Community Highlights
|
| 55 |
+
|
| 56 |
+
### Top Contributors
|
| 57 |
+
Thank you to all contributors who helped shape this project!
|
| 58 |
+
|
| 59 |
+
### Featured Projects
|
| 60 |
+
Projects built with Burme-Coder-Max:
|
| 61 |
+
- 🔨 Myanmar coding tutorials
|
| 62 |
+
- 📚 Educational chatbots
|
| 63 |
+
- 🎮 CLI productivity tools
|
| 64 |
+
|
| 65 |
+
---
|
| 66 |
+
|
| 67 |
+
*Last updated: January 2025*
|
data/knowledge/webs/graphql_basics.md
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GraphQL Basics
|
| 2 |
+
|
| 3 |
+
## What is GraphQL?
|
| 4 |
+
|
| 5 |
+
GraphQL is a query language for APIs that allows clients to request exactly the data they need.
|
| 6 |
+
|
| 7 |
+
## Core Concepts
|
| 8 |
+
|
| 9 |
+
### Schema & Types
|
| 10 |
+
```graphql
|
| 11 |
+
type User {
|
| 12 |
+
id: ID!
|
| 13 |
+
name: String!
|
| 14 |
+
email: String
|
| 15 |
+
age: Int
|
| 16 |
+
posts: [Post!]!
|
| 17 |
+
createdAt: DateTime!
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
type Post {
|
| 21 |
+
id: ID!
|
| 22 |
+
title: String!
|
| 23 |
+
content: String
|
| 24 |
+
author: User!
|
| 25 |
+
comments: [Comment!]!
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
type Query {
|
| 29 |
+
user(id: ID!): User
|
| 30 |
+
users(limit: Int = 10): [User!]!
|
| 31 |
+
post(id: ID!): Post
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
type Mutation {
|
| 35 |
+
createUser(name: String!, email: String!): User!
|
| 36 |
+
updateUser(id: ID!, name: String): User!
|
| 37 |
+
deleteUser(id: ID!): Boolean!
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
type Subscription {
|
| 41 |
+
userCreated: User!
|
| 42 |
+
postUpdated(id: ID!): Post!
|
| 43 |
+
}
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
### Queries
|
| 47 |
+
```graphql
|
| 48 |
+
# Fetch single user
|
| 49 |
+
query GetUser($id: ID!) {
|
| 50 |
+
user(id: $id) {
|
| 51 |
+
name
|
| 52 |
+
email
|
| 53 |
+
posts {
|
| 54 |
+
title
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
# Fetch multiple users with filtering
|
| 60 |
+
query GetUsers($limit: Int) {
|
| 61 |
+
users(limit: $limit) {
|
| 62 |
+
id
|
| 63 |
+
name
|
| 64 |
+
email
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
### Mutations
|
| 70 |
+
```graphql
|
| 71 |
+
mutation CreateUser($name: String!, $email: String!) {
|
| 72 |
+
createUser(name: $name, email: $email) {
|
| 73 |
+
id
|
| 74 |
+
name
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
mutation UpdatePost($id: ID!, $title: String!) {
|
| 79 |
+
updatePost(id: $id, title: $title) {
|
| 80 |
+
id
|
| 81 |
+
title
|
| 82 |
+
updatedAt
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
### Variables
|
| 88 |
+
```json
|
| 89 |
+
{
|
| 90 |
+
"id": "123",
|
| 91 |
+
"name": "John",
|
| 92 |
+
"email": "john@example.com"
|
| 93 |
+
}
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
## Implementation (Node.js + Apollo)
|
| 97 |
+
|
| 98 |
+
### Basic Server
|
| 99 |
+
```javascript
|
| 100 |
+
const { ApolloServer, gql } = require('apollo-server');
|
| 101 |
+
const { GraphQLScalarType, Kind } = require('graphql');
|
| 102 |
+
|
| 103 |
+
const typeDefs = gql`
|
| 104 |
+
scalar DateTime
|
| 105 |
+
|
| 106 |
+
type User {
|
| 107 |
+
id: ID!
|
| 108 |
+
name: String!
|
| 109 |
+
email: String!
|
| 110 |
+
createdAt: DateTime!
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
type Query {
|
| 114 |
+
users: [User!]!
|
| 115 |
+
user(id: ID!): User
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
type Mutation {
|
| 119 |
+
createUser(name: String!, email: String!): User!
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
type Subscription {
|
| 123 |
+
userCreated: User!
|
| 124 |
+
}
|
| 125 |
+
`;
|
| 126 |
+
|
| 127 |
+
const resolvers = {
|
| 128 |
+
DateTime: new GraphQLScalarType({
|
| 129 |
+
name: 'DateTime',
|
| 130 |
+
serialize(value) {
|
| 131 |
+
return value.toISOString();
|
| 132 |
+
},
|
| 133 |
+
parseValue(value) {
|
| 134 |
+
return new Date(value);
|
| 135 |
+
}
|
| 136 |
+
}),
|
| 137 |
+
|
| 138 |
+
Query: {
|
| 139 |
+
users: () => users,
|
| 140 |
+
user: (_, { id }) => users.find(u => u.id === id),
|
| 141 |
+
},
|
| 142 |
+
|
| 143 |
+
Mutation: {
|
| 144 |
+
createUser: (_, { name, email }) => {
|
| 145 |
+
const newUser = {
|
| 146 |
+
id: String(users.length + 1),
|
| 147 |
+
name,
|
| 148 |
+
email,
|
| 149 |
+
createdAt: new Date()
|
| 150 |
+
};
|
| 151 |
+
users.push(newUser);
|
| 152 |
+
return newUser;
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
};
|
| 156 |
+
|
| 157 |
+
const server = new ApolloServer({ typeDefs, effectors });
|
| 158 |
+
server.listen().then(({ url }) => {
|
| 159 |
+
console.log(`Server ready at ${url}`);
|
| 160 |
+
});
|
| 161 |
+
```
|
| 162 |
+
|
| 163 |
+
### Client (React)
|
| 164 |
+
```javascript
|
| 165 |
+
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
|
| 166 |
+
|
| 167 |
+
const client = new ApolloClient({
|
| 168 |
+
uri: 'http://localhost:4000/graphql',
|
| 169 |
+
cache: new InMemoryCache()
|
| 170 |
+
});
|
| 171 |
+
|
| 172 |
+
const GET_USERS = gql`
|
| 173 |
+
query GetUsers {
|
| 174 |
+
users {
|
| 175 |
+
id
|
| 176 |
+
name
|
| 177 |
+
email
|
| 178 |
+
}
|
| 179 |
+
}
|
| 180 |
+
`;
|
| 181 |
+
|
| 182 |
+
function App() {
|
| 183 |
+
const { loading, error, data } = useQuery(GET_USERS);
|
| 184 |
+
|
| 185 |
+
if (loading) return <p>Loading...</p>;
|
| 186 |
+
if (error) return <p>Error: {error.message}</p>;
|
| 187 |
+
|
| 188 |
+
return (
|
| 189 |
+
<div>
|
| 190 |
+
{data.users.map(user => (
|
| 191 |
+
<div key={user.id}>{user.name}</div>
|
| 192 |
+
))}
|
| 193 |
+
</div>
|
| 194 |
+
);
|
| 195 |
+
}
|
| 196 |
+
```
|
| 197 |
+
|
| 198 |
+
## GraphQL vs REST
|
| 199 |
+
|
| 200 |
+
| Feature | GraphQL | REST |
|
| 201 |
+
|---------|---------|------|
|
| 202 |
+
| Data fetching | Single request | Multiple endpoints |
|
| 203 |
+
| Over-fetching | No | Yes |
|
| 204 |
+
| Under-fetching | No | Sometimes |
|
| 205 |
+
| Type safety | Yes (schema) | No |
|
| 206 |
+
| Learning curve | Higher | Lower |
|
| 207 |
+
| Caching | Manual | Automatic |
|
| 208 |
+
| File uploads | Complex | Simple |
|
| 209 |
+
|
| 210 |
+
## Best Practices
|
| 211 |
+
|
| 212 |
+
1. **N+1 Problem** - Use DataLoader for batching
|
| 213 |
+
2. **Pagination** - Use cursor-based pagination
|
| 214 |
+
3. **Error Handling** - Return meaningful errors
|
| 215 |
+
4. **Security** - Implement depth limiting
|
| 216 |
+
5. **Performance** - Consider query cost analysis
|
data/knowledge/webs/http_status_codes.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# HTTP Status Codes
|
| 2 |
+
|
| 3 |
+
## Success Codes (2xx)
|
| 4 |
+
|
| 5 |
+
| Code | Name | Description |
|
| 6 |
+
|------|------|-------------|
|
| 7 |
+
| 200 | OK | Standard success response |
|
| 8 |
+
| 201 | Created | Resource successfully created |
|
| 9 |
+
| 202 | Accepted | Request accepted for processing |
|
| 10 |
+
| 204 | No Content | Success with no body |
|
| 11 |
+
| 206 | Partial Content | Returning partial data |
|
| 12 |
+
|
| 13 |
+
## Redirection Codes (3xx)
|
| 14 |
+
|
| 15 |
+
| Code | Name | Description |
|
| 16 |
+
|------|------|-------------|
|
| 17 |
+
| 301 | Moved Permanently | Resource moved permanently |
|
| 18 |
+
| 302 | Found | Temporary redirect |
|
| 19 |
+
| 303 | See Other | Redirect to different URL |
|
| 20 |
+
| 304 | Not Modified | Use cached version |
|
| 21 |
+
| 307 | Temporary Redirect | Temporary redirect |
|
| 22 |
+
| 308 | Permanent Redirect | Permanent redirect |
|
| 23 |
+
|
| 24 |
+
## Client Error Codes (4xx)
|
| 25 |
+
|
| 26 |
+
| Code | Name | Description |
|
| 27 |
+
|------|------|-------------|
|
| 28 |
+
| 400 | Bad Request | Invalid request syntax |
|
| 29 |
+
| 401 | Unauthorized | Authentication required |
|
| 30 |
+
| 402 | Payment Required | Reserved for future use |
|
| 31 |
+
| 403 | Forbidden | Authenticated but not permitted |
|
| 32 |
+
| 404 | Not Found | Resource doesn't exist |
|
| 33 |
+
| 405 | Method Not Allowed | HTTP method not supported |
|
| 34 |
+
| 406 | Not Acceptable | Cannot produce acceptable response |
|
| 35 |
+
| 408 | Request Timeout | Client took too long |
|
| 36 |
+
| 409 | Conflict | Request conflicts with state |
|
| 37 |
+
| 410 | Gone | Resource permanently removed |
|
| 38 |
+
| 413 | Payload Too Large | Request body exceeds limit |
|
| 39 |
+
| 414 | URI Too Long | URL exceeds max length |
|
| 40 |
+
| 415 | Unsupported Media Type | Invalid content type |
|
| 41 |
+
| 422 | Unprocessable Entity | Validation failed |
|
| 42 |
+
| 429 | Too Many Requests | Rate limit exceeded |
|
| 43 |
+
|
| 44 |
+
## Server Error Codes (5xx)
|
| 45 |
+
|
| 46 |
+
| Code | Name | Description |
|
| 47 |
+
|------|------|-------------|
|
| 48 |
+
| 500 | Internal Server Error | Generic server error |
|
| 49 |
+
| 501 | Not Implemented | Feature not implemented |
|
| 50 |
+
| 502 | Bad Gateway | Invalid response from gateway |
|
| 51 |
+
| 503 | Service Unavailable | Server temporarily down |
|
| 52 |
+
| 504 | Gateway Timeout | Gateway timeout |
|
| 53 |
+
| 507 | Insufficient Storage | Storage limit reached |
|
| 54 |
+
| 511 | Network Authentication | Requires auth on network |
|
| 55 |
+
|
| 56 |
+
## Common Use Cases
|
| 57 |
+
|
| 58 |
+
### 200 OK
|
| 59 |
+
```json
|
| 60 |
+
// Standard response
|
| 61 |
+
{
|
| 62 |
+
"data": {...}
|
| 63 |
+
}
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
### 201 Created
|
| 67 |
+
```json
|
| 68 |
+
// With created resource
|
| 69 |
+
{
|
| 70 |
+
"data": {
|
| 71 |
+
"id": 123,
|
| 72 |
+
"name": "New Item"
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
// Headers: Location: /resources/123
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
### 400 Bad Request
|
| 79 |
+
```json
|
| 80 |
+
{
|
| 81 |
+
"error": {
|
| 82 |
+
"code": "VALIDATION_ERROR",
|
| 83 |
+
"message": "Invalid input",
|
| 84 |
+
"details": [...]
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
### 401 Unauthorized
|
| 90 |
+
```json
|
| 91 |
+
{
|
| 92 |
+
"error": {
|
| 93 |
+
"code": "AUTH_REQUIRED",
|
| 94 |
+
"message": "Please login to continue"
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
### 403 Forbidden
|
| 100 |
+
```json
|
| 101 |
+
{
|
| 102 |
+
"error": {
|
| 103 |
+
"code": "PERMISSION_DENIED",
|
| 104 |
+
"message": "You don't have access to this resource"
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
### 404 Not Found
|
| 110 |
+
```json
|
| 111 |
+
{
|
| 112 |
+
"error": {
|
| 113 |
+
"code": "NOT_FOUND",
|
| 114 |
+
"message": "Resource not found"
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
### 429 Too Many Requests
|
| 120 |
+
```json
|
| 121 |
+
{
|
| 122 |
+
"error": {
|
| 123 |
+
"code": "RATE_LIMITED",
|
| 124 |
+
"message": "Too many requests",
|
| 125 |
+
"retryAfter": 60
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
// Headers: Retry-After: 60
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
### 500 Internal Server Error
|
| 132 |
+
```json
|
| 133 |
+
{
|
| 134 |
+
"error": {
|
| 135 |
+
"code": "INTERNAL_ERROR",
|
| 136 |
+
"message": "Something went wrong"
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
## Response Headers
|
| 142 |
+
|
| 143 |
+
### Standard Headers
|
| 144 |
+
```
|
| 145 |
+
Content-Type: application/json
|
| 146 |
+
Content-Length: 1234
|
| 147 |
+
Connection: keep-alive
|
| 148 |
+
Cache-Control: max-age=3600
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
### Rate Limiting Headers
|
| 152 |
+
```
|
| 153 |
+
X-RateLimit-Limit: 100
|
| 154 |
+
X-RateLimit-Remaining: 95
|
| 155 |
+
X-RateLimit-Reset: 1640000000
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
### Pagination Headers
|
| 159 |
+
```
|
| 160 |
+
Link: <https://api.com/users?page=2>; rel="next",
|
| 161 |
+
<https://api.com/users?page=5>; rel="last"
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
## Security Best Practices
|
| 165 |
+
|
| 166 |
+
1. Never reveal internal error details in production
|
| 167 |
+
2. Use generic error messages for 500 errors
|
| 168 |
+
3. Log detailed errors server-side
|
| 169 |
+
4. Return appropriate status codes
|
| 170 |
+
5. Include error codes for client handling
|
data/knowledge/webs/rest_api_design.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# REST API Design
|
| 2 |
+
|
| 3 |
+
## HTTP Methods
|
| 4 |
+
|
| 5 |
+
| Method | Purpose | Example |
|
| 6 |
+
|--------|---------|---------|
|
| 7 |
+
| GET | Retrieve data | `GET /users` |
|
| 8 |
+
| POST | Create new resource | `POST /users` |
|
| 9 |
+
| PUT | Replace entire resource | `PUT /users/1` |
|
| 10 |
+
| PATCH | Partial update | `PATCH /users/1` |
|
| 11 |
+
| DELETE | Remove resource | `DELETE /users/1` |
|
| 12 |
+
|
| 13 |
+
## URL Structure
|
| 14 |
+
|
| 15 |
+
```
|
| 16 |
+
https://api.example.com/v1/users/123/posts?page=1&limit=10
|
| 17 |
+
│ │ │ │ │
|
| 18 |
+
│ │ │ │ └── Query Parameters
|
| 19 |
+
│ │ │ └── Resource ID
|
| 20 |
+
│ │ └── Collection
|
| 21 |
+
│ └── Version
|
| 22 |
+
└── Base URL
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
## Status Codes
|
| 26 |
+
|
| 27 |
+
### Success
|
| 28 |
+
- `200 OK` - Request succeeded
|
| 29 |
+
- `201 Created` - Resource created
|
| 30 |
+
- `204 No Content` - Success, no body (DELETE)
|
| 31 |
+
|
| 32 |
+
### Client Errors
|
| 33 |
+
- `400 Bad Request` - Invalid input
|
| 34 |
+
- `401 Unauthorized` - Authentication required
|
| 35 |
+
- `403 Forbidden` - Authenticated but not permitted
|
| 36 |
+
- `404 Not Found` - Resource doesn't exist
|
| 37 |
+
- `422 Unprocessable Entity` - Validation error
|
| 38 |
+
|
| 39 |
+
### Server Errors
|
| 40 |
+
- `500 Internal Server Error` - Server error
|
| 41 |
+
- `502 Bad Gateway` - Gateway error
|
| 42 |
+
- `503 Service Unavailable` - Server down
|
| 43 |
+
|
| 44 |
+
## Best Practices
|
| 45 |
+
|
| 46 |
+
### Request
|
| 47 |
+
```http
|
| 48 |
+
GET /api/v1/users?status=active&sort=-created_at
|
| 49 |
+
Accept: application/json
|
| 50 |
+
Authorization: Bearer <token>
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
### Response
|
| 54 |
+
```json
|
| 55 |
+
{
|
| 56 |
+
"data": [
|
| 57 |
+
{
|
| 58 |
+
"id": 1,
|
| 59 |
+
"name": "John",
|
| 60 |
+
"email": "john@example.com"
|
| 61 |
+
}
|
| 62 |
+
],
|
| 63 |
+
"meta": {
|
| 64 |
+
"page": 1,
|
| 65 |
+
"per_page": 20,
|
| 66 |
+
"total": 100
|
| 67 |
+
},
|
| 68 |
+
"links": {
|
| 69 |
+
"self": "/api/v1/users?page=1",
|
| 70 |
+
"next": "/api/v1/users?page=2"
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
### Error Response
|
| 76 |
+
```json
|
| 77 |
+
{
|
| 78 |
+
"error": {
|
| 79 |
+
"code": "VALIDATION_ERROR",
|
| 80 |
+
"message": "Invalid input data",
|
| 81 |
+
"details": [
|
| 82 |
+
{
|
| 83 |
+
"field": "email",
|
| 84 |
+
"message": "Invalid email format"
|
| 85 |
+
}
|
| 86 |
+
]
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
## REST API Example (Node.js/Express)
|
| 92 |
+
|
| 93 |
+
### Basic Setup
|
| 94 |
+
```javascript
|
| 95 |
+
const express = require('express');
|
| 96 |
+
const app = express();
|
| 97 |
+
|
| 98 |
+
app.use(express.json());
|
| 99 |
+
|
| 100 |
+
// GET all users
|
| 101 |
+
app.get('/api/v1/users', (req, res) => {
|
| 102 |
+
res.json({ data: users });
|
| 103 |
+
});
|
| 104 |
+
|
| 105 |
+
// GET single user
|
| 106 |
+
app.get('/api/v1/users/:id', (req, res) => {
|
| 107 |
+
const user = users.find(u => u.id === parseInt(req.params.id));
|
| 108 |
+
if (!user) return res.status(404).json({ error: 'Not found' });
|
| 109 |
+
res.json({ data: user });
|
| 110 |
+
});
|
| 111 |
+
|
| 112 |
+
// POST create user
|
| 113 |
+
app.post('/api/v1/users', (req, res) => {
|
| 114 |
+
const { name, email } = req.body;
|
| 115 |
+
// Validation
|
| 116 |
+
if (!name || !email) {
|
| 117 |
+
return res.status(400).json({ error: 'Missing fields' });
|
| 118 |
+
}
|
| 119 |
+
// Create
|
| 120 |
+
const newUser = { id: users.length + 1, name, email };
|
| 121 |
+
users.push(newUser);
|
| 122 |
+
res.status(201).json({ data: newUser });
|
| 123 |
+
});
|
| 124 |
+
|
| 125 |
+
// PUT update user
|
| 126 |
+
app.put('/api/v1/users/:id', (req, res) => {
|
| 127 |
+
const user = users.find(u => u.id === parseInt(req.params.id));
|
| 128 |
+
if (!user) return res.status(404).json({ error: 'Not found' });
|
| 129 |
+
|
| 130 |
+
const { name, email } = req.body;
|
| 131 |
+
user.name = name || user.name;
|
| 132 |
+
user.email = email || user.email;
|
| 133 |
+
res.json({ data: user });
|
| 134 |
+
});
|
| 135 |
+
|
| 136 |
+
// DELETE user
|
| 137 |
+
app.delete('/api/v1/users/:id', (req, res) => {
|
| 138 |
+
const index = users.findIndex(u => u.id === parseInt(req.params.id));
|
| 139 |
+
if (index === -1) return res.status(404).json({ error: 'Not found' });
|
| 140 |
+
|
| 141 |
+
users.splice(index, 1);
|
| 142 |
+
res.status(204).send();
|
| 143 |
+
});
|
| 144 |
+
```
|
data/knowledge/webs/websocket_protocol.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# WebSocket Protocol
|
| 2 |
+
|
| 3 |
+
## What is WebSocket?
|
| 4 |
+
|
| 5 |
+
WebSocket provides full-duplex communication channels over a single TCP connection. Unlike HTTP, WebSocket allows real-time bidirectional communication.
|
| 6 |
+
|
| 7 |
+
## Connection Flow
|
| 8 |
+
|
| 9 |
+
```
|
| 10 |
+
Client Server
|
| 11 |
+
│ │
|
| 12 |
+
│──── HTTP Upgrade Request ────▶│
|
| 13 |
+
│ Upgrade: websocket │
|
| 14 |
+
│ │
|
| 15 |
+
│◀─── HTTP 101 Switching -------│
|
| 16 |
+
│ Protocol: ws │
|
| 17 |
+
│ │
|
| 18 |
+
│◀═════ WebSocket Open ═════════▶│
|
| 19 |
+
│ │
|
| 20 |
+
│◀═════ Messages ══════════════▶│
|
| 21 |
+
│ │
|
| 22 |
+
│◀═════ Connection Close ═══════▶│
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
## WebSocket Headers
|
| 26 |
+
|
| 27 |
+
### Upgrade Request
|
| 28 |
+
```
|
| 29 |
+
GET /ws HTTP/1.1
|
| 30 |
+
Host: api.example.com
|
| 31 |
+
Upgrade: websocket
|
| 32 |
+
Connection: Upgrade
|
| 33 |
+
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
|
| 34 |
+
Sec-WebSocket-Version: 13
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
### Server Response
|
| 38 |
+
```
|
| 39 |
+
HTTP/1.1 101 Switching Protocols
|
| 40 |
+
Upgrade: websocket
|
| 41 |
+
Connection: Upgrade
|
| 42 |
+
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
## Implementation Examples
|
| 46 |
+
|
| 47 |
+
### Server (Node.js + ws)
|
| 48 |
+
```javascript
|
| 49 |
+
const WebSocket = require('ws');
|
| 50 |
+
const wss = new WebSocket.Server({ port: 8080 });
|
| 51 |
+
|
| 52 |
+
wss.on('connection', (ws) => {
|
| 53 |
+
console.log('Client connected');
|
| 54 |
+
|
| 55 |
+
ws.on('message', (message) => {
|
| 56 |
+
console.log('Received:', message.toString());
|
| 57 |
+
ws.send('Echo: ' + message);
|
| 58 |
+
});
|
| 59 |
+
|
| 60 |
+
ws.on('close', () => {
|
| 61 |
+
console.log('Client disconnected');
|
| 62 |
+
});
|
| 63 |
+
|
| 64 |
+
// Send periodic message
|
| 65 |
+
const interval = setInterval(() => {
|
| 66 |
+
ws.send('Ping: ' + Date.now());
|
| 67 |
+
}, 30000);
|
| 68 |
+
|
| 69 |
+
ws.on('close', () => clearInterval(interval));
|
| 70 |
+
});
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
### Client (Browser)
|
| 74 |
+
```javascript
|
| 75 |
+
const ws = new WebSocket('ws://localhost:8080');
|
| 76 |
+
|
| 77 |
+
ws.onopen = () => {
|
| 78 |
+
console.log('Connected to WebSocket');
|
| 79 |
+
ws.send('Hello Server!');
|
| 80 |
+
};
|
| 81 |
+
|
| 82 |
+
ws.onmessage = (event) => {
|
| 83 |
+
console.log('Received:', event.data);
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
ws.onerror = (error) => {
|
| 87 |
+
console.error('WebSocket error:', error);
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
ws.onclose = () => {
|
| 91 |
+
console.log('Disconnected');
|
| 92 |
+
};
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
### Client (Python)
|
| 96 |
+
```python
|
| 97 |
+
import asyncio
|
| 98 |
+
import websockets
|
| 99 |
+
|
| 100 |
+
async def main():
|
| 101 |
+
async with websockets.connect('ws://localhost:8080') as ws:
|
| 102 |
+
await ws.send('Hello Server!')
|
| 103 |
+
response = await ws.recv()
|
| 104 |
+
print(f"Received: {response}")
|
| 105 |
+
|
| 106 |
+
asyncio.run(main())
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
## Socket.IO (Higher Level)
|
| 110 |
+
|
| 111 |
+
### Server
|
| 112 |
+
```javascript
|
| 113 |
+
const { Server } = require('socket.io');
|
| 114 |
+
const io = new Server(3000, {
|
| 115 |
+
cors: { origin: '*' }
|
| 116 |
+
});
|
| 117 |
+
|
| 118 |
+
io.on('connection', (socket) => {
|
| 119 |
+
console.log('User connected:', socket.id);
|
| 120 |
+
|
| 121 |
+
socket.on('message', (data) => {
|
| 122 |
+
console.log('Message:', data);
|
| 123 |
+
io.emit('message', data);
|
| 124 |
+
});
|
| 125 |
+
|
| 126 |
+
socket.on('disconnect', () => {
|
| 127 |
+
console.log('User disconnected');
|
| 128 |
+
});
|
| 129 |
+
|
| 130 |
+
socket.on('join-room', (room) => {
|
| 131 |
+
socket.join(room);
|
| 132 |
+
socket.to(room).emit('user-joined', socket.id);
|
| 133 |
+
});
|
| 134 |
+
});
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
### Client
|
| 138 |
+
```javascript
|
| 139 |
+
import { io } from 'socket.io-client';
|
| 140 |
+
|
| 141 |
+
const socket = io('http://localhost:3000');
|
| 142 |
+
|
| 143 |
+
socket.on('connect', () => {
|
| 144 |
+
console.log('Connected:', socket.id);
|
| 145 |
+
socket.emit('message', 'Hello everyone!');
|
| 146 |
+
});
|
| 147 |
+
|
| 148 |
+
socket.on('message', (data) => {
|
| 149 |
+
console.log('Received:', data);
|
| 150 |
+
});
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
## WebSocket vs HTTP
|
| 154 |
+
|
| 155 |
+
| Aspect | WebSocket | HTTP |
|
| 156 |
+
|--------|----------|------|
|
| 157 |
+
| Connection | Persistent | Request-Response |
|
| 158 |
+
| Direction | Bidirectional | Client → Server |
|
| 159 |
+
| Overhead | Low (after handshake) | High (headers each request) |
|
| 160 |
+
| Use Case | Real-time apps | REST APIs, simple requests |
|
| 161 |
+
| Browser Support | Modern browsers | All browsers |
|
| 162 |
+
|
| 163 |
+
## Best Practices
|
| 164 |
+
|
| 165 |
+
1. **Heartbeat/Ping-Pong** - Keep connections alive
|
| 166 |
+
2. **Reconnection Logic** - Handle connection drops
|
| 167 |
+
3. **Message Queueing** - Queue messages during disconnect
|
| 168 |
+
4. **Authentication** - Validate on connection
|
| 169 |
+
5. **Rate Limiting** - Prevent abuse
|
| 170 |
+
6. **Compression** - Consider permessage-deflate
|
docs/animation_gallery.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Documentation: Animation Gallery"""
|
| 2 |
+
|
| 3 |
+
# Animation Gallery
|
| 4 |
+
|
| 5 |
+
A showcase of all available terminal animations in Burme-Coder-Max.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## 1. Loading Spinner
|
| 10 |
+
|
| 11 |
+
Display a spinning indicator while waiting.
|
| 12 |
+
|
| 13 |
+
```python
|
| 14 |
+
from animations import Spinner
|
| 15 |
+
|
| 16 |
+
with Spinner("Loading..."):
|
| 17 |
+
do_something()
|
| 18 |
+
```
|
| 19 |
+
|
| 20 |
+
**Custom message:**
|
| 21 |
+
```python
|
| 22 |
+
spinner = Spinner("Processing your request...")
|
| 23 |
+
spinner.start()
|
| 24 |
+
# ... do work
|
| 25 |
+
spinner.stop()
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
---
|
| 29 |
+
|
| 30 |
+
## 2. Progress Bar
|
| 31 |
+
|
| 32 |
+
Show progress for long-running operations.
|
| 33 |
+
|
| 34 |
+
```python
|
| 35 |
+
from animations import ProgressBar
|
| 36 |
+
|
| 37 |
+
for i in ProgressBar(range(100), description="Downloading"):
|
| 38 |
+
download(i)
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
**Custom configuration:**
|
| 42 |
+
```python
|
| 43 |
+
from animations.progress_bar import ProgressBarConfig
|
| 44 |
+
|
| 45 |
+
config = ProgressBarConfig(
|
| 46 |
+
width=60,
|
| 47 |
+
fill_char="█",
|
| 48 |
+
empty_char="░"
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
progress = ProgressBar(
|
| 52 |
+
total=50,
|
| 53 |
+
config=config,
|
| 54 |
+
description="Uploading"
|
| 55 |
+
)
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
---
|
| 59 |
+
|
| 60 |
+
## 3. Typing Effect
|
| 61 |
+
|
| 62 |
+
Typewriter-style text animation.
|
| 63 |
+
|
| 64 |
+
```python
|
| 65 |
+
from animations import TypingEffect
|
| 66 |
+
|
| 67 |
+
effect = TypingEffect("Hello, World!")
|
| 68 |
+
effect.animate()
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
**Speed variants:**
|
| 72 |
+
```python
|
| 73 |
+
from animations import SlowTypingEffect, FastTypingEffect
|
| 74 |
+
|
| 75 |
+
SlowTypingEffect("Slow text").animate()
|
| 76 |
+
FastTypingEffect("Fast text").animate()
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
---
|
| 80 |
+
|
| 81 |
+
## 4. Particle Burst
|
| 82 |
+
|
| 83 |
+
Celebration effect with particles.
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
from animations import ParticleBurst
|
| 87 |
+
|
| 88 |
+
burst = ParticleBurst(count=50)
|
| 89 |
+
burst.explode()
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
**Custom position:**
|
| 93 |
+
```python
|
| 94 |
+
burst = ParticleBurst(center_x=60, center_y=15)
|
| 95 |
+
burst.explode()
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
---
|
| 99 |
+
|
| 100 |
+
## 5. Confetti
|
| 101 |
+
|
| 102 |
+
Lightweight celebration effect.
|
| 103 |
+
|
| 104 |
+
```python
|
| 105 |
+
from animations.particle_effect import SimpleConfetti
|
| 106 |
+
|
| 107 |
+
confetti = SimpleConfetti(duration=2.0)
|
| 108 |
+
confetti.show()
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
---
|
| 112 |
+
|
| 113 |
+
## Preview Script
|
| 114 |
+
|
| 115 |
+
Run all animations:
|
| 116 |
+
|
| 117 |
+
```bash
|
| 118 |
+
python scripts/preview_animations.py
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
---
|
| 122 |
+
|
| 123 |
+
## Configuration
|
| 124 |
+
|
| 125 |
+
Edit animation settings in `.env`:
|
| 126 |
+
|
| 127 |
+
```bash
|
| 128 |
+
ANIMATION_SPEED=0.05
|
| 129 |
+
ANIMATION_COLOR=true
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
Or in code:
|
| 133 |
+
|
| 134 |
+
```python
|
| 135 |
+
from animations.config import AnimationConfig
|
| 136 |
+
|
| 137 |
+
config = AnimationConfig(speed=0.03, color_enabled=False)
|
| 138 |
+
spinner = Spinner(config=config)
|
| 139 |
+
```
|
docs/contributing.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Documentation: Contributing Guide"""
|
| 2 |
+
|
| 3 |
+
# Contributing to Burme-Coder-Max
|
| 4 |
+
|
| 5 |
+
We welcome contributions! This guide covers how to contribute.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## Ways to Contribute
|
| 10 |
+
|
| 11 |
+
- 🐛 Report bugs
|
| 12 |
+
- 💡 Suggest features
|
| 13 |
+
- 📝 Improve documentation
|
| 14 |
+
- 🔧 Submit code changes
|
| 15 |
+
- ✅ Test new features
|
| 16 |
+
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
## Development Setup
|
| 20 |
+
|
| 21 |
+
### 1. Fork and Clone
|
| 22 |
+
|
| 23 |
+
```bash
|
| 24 |
+
git clone https://github.com/YOUR_USERNAME/burme-coder-max.git
|
| 25 |
+
cd burme-coder-max
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
### 2. Create Virtual Environment
|
| 29 |
+
|
| 30 |
+
```bash
|
| 31 |
+
python -m venv venv
|
| 32 |
+
source venv/bin/activate # Linux/Mac
|
| 33 |
+
# or
|
| 34 |
+
venv\Scripts\activate # Windows
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
### 3. Install Dependencies
|
| 38 |
+
|
| 39 |
+
```bash
|
| 40 |
+
pip install -e ".[dev]"
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
### 4. Install Pre-commit Hooks
|
| 44 |
+
|
| 45 |
+
```bash
|
| 46 |
+
pre-commit install
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
---
|
| 50 |
+
|
| 51 |
+
## Making Changes
|
| 52 |
+
|
| 53 |
+
### 1. Create a Branch
|
| 54 |
+
|
| 55 |
+
```bash
|
| 56 |
+
git checkout -b feature/my-feature
|
| 57 |
+
# or
|
| 58 |
+
git checkout -b fix/my-bug
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
### 2. Make Your Changes
|
| 62 |
+
|
| 63 |
+
- Follow existing code style
|
| 64 |
+
- Add tests for new features
|
| 65 |
+
- Update documentation
|
| 66 |
+
|
| 67 |
+
### 3. Run Tests
|
| 68 |
+
|
| 69 |
+
```bash
|
| 70 |
+
pytest tests/ -v
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
### 4. Run Linters
|
| 74 |
+
|
| 75 |
+
```bash
|
| 76 |
+
black src/ tests/
|
| 77 |
+
mypy src/
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
---
|
| 81 |
+
|
| 82 |
+
## Code Style
|
| 83 |
+
|
| 84 |
+
- Follow PEP 8
|
| 85 |
+
- Use type hints
|
| 86 |
+
- Add docstrings
|
| 87 |
+
- Keep functions small and focused
|
| 88 |
+
|
| 89 |
+
### Example
|
| 90 |
+
|
| 91 |
+
```python
|
| 92 |
+
from typing import List, Optional
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def search_knowledge(query: str, category: Optional[str] = None) -> List[dict]:
|
| 96 |
+
"""
|
| 97 |
+
Search the knowledge base for relevant content.
|
| 98 |
+
|
| 99 |
+
Args:
|
| 100 |
+
query: Search query string
|
| 101 |
+
category: Optional category filter
|
| 102 |
+
|
| 103 |
+
Returns:
|
| 104 |
+
List of matching entries
|
| 105 |
+
"""
|
| 106 |
+
# implementation
|
| 107 |
+
pass
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
---
|
| 111 |
+
|
| 112 |
+
## Commit Messages
|
| 113 |
+
|
| 114 |
+
Format:
|
| 115 |
+
|
| 116 |
+
```
|
| 117 |
+
type: Short description
|
| 118 |
+
|
| 119 |
+
Longer explanation if needed.
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
Types:
|
| 123 |
+
- `feat:` New feature
|
| 124 |
+
- `fix:` Bug fix
|
| 125 |
+
- `docs:` Documentation
|
| 126 |
+
- `style:` Formatting
|
| 127 |
+
- `refactor:` Code restructuring
|
| 128 |
+
- `test:` Tests
|
| 129 |
+
- `chore:` maintenance
|
| 130 |
+
|
| 131 |
+
Example:
|
| 132 |
+
```
|
| 133 |
+
feat: Add particle burst animation
|
| 134 |
+
|
| 135 |
+
Add celebration effect with customizable particle count.
|
| 136 |
+
Fixes #12
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
---
|
| 140 |
+
|
| 141 |
+
## Pull Request Process
|
| 142 |
+
|
| 143 |
+
1. Update documentation for new features
|
| 144 |
+
2. Add tests
|
| 145 |
+
3. Ensure all tests pass
|
| 146 |
+
4. Update CHANGELOG.md
|
| 147 |
+
5. Submit PR with clear description
|
| 148 |
+
|
| 149 |
+
---
|
| 150 |
+
|
| 151 |
+
## Reporting Issues
|
| 152 |
+
|
| 153 |
+
When reporting bugs:
|
| 154 |
+
- Describe the issue clearly
|
| 155 |
+
- Steps to reproduce
|
| 156 |
+
- Expected vs actual behavior
|
| 157 |
+
- Python version and OS
|
| 158 |
+
- Error messages
|
| 159 |
+
|
| 160 |
+
---
|
| 161 |
+
|
| 162 |
+
## Questions?
|
| 163 |
+
|
| 164 |
+
- 📧 Email: contact@amkyawdev.com
|
| 165 |
+
- 💬 GitHub Discussions
|
| 166 |
+
- 🤝 Community Discord
|
| 167 |
+
|
| 168 |
+
---
|
| 169 |
+
|
| 170 |
+
Thank you for contributing! 🙏
|
docs/installation.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Documentation: Installation Guide"""
|
| 2 |
+
|
| 3 |
+
# Installation Guide - Burme-Coder-Max
|
| 4 |
+
|
| 5 |
+
## Prerequisites
|
| 6 |
+
|
| 7 |
+
- Python 3.8 or higher
|
| 8 |
+
- pip package manager
|
| 9 |
+
|
| 10 |
+
## Installation Methods
|
| 11 |
+
|
| 12 |
+
### Method 1: pip install (Recommended)
|
| 13 |
+
|
| 14 |
+
```bash
|
| 15 |
+
pip install burme-coder-max
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
### Method 2: From source
|
| 19 |
+
|
| 20 |
+
```bash
|
| 21 |
+
git clone https://github.com/amkyawdev/burme-coder-max.git
|
| 22 |
+
cd burme-coder-max
|
| 23 |
+
pip install -e .
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
### Method 3: Development install
|
| 27 |
+
|
| 28 |
+
```bash
|
| 29 |
+
git clone https://github.com/amkyawdev/burme-coder-max.git
|
| 30 |
+
cd burme-coder-max
|
| 31 |
+
pip install -e ".[dev]"
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
## Verify Installation
|
| 35 |
+
|
| 36 |
+
```bash
|
| 37 |
+
burme-coder --version
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
Expected output:
|
| 41 |
+
```
|
| 42 |
+
burme-coder-max 1.0.0
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
## Configuration
|
| 46 |
+
|
| 47 |
+
1. Copy `.env.example` to `.env`:
|
| 48 |
+
```bash
|
| 49 |
+
cp .env.example .env
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
2. Edit `.env` with your settings:
|
| 53 |
+
```bash
|
| 54 |
+
nano .env
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
### Required Environment Variables
|
| 58 |
+
|
| 59 |
+
| Variable | Description | Required |
|
| 60 |
+
|----------|-------------|----------|
|
| 61 |
+
| OPENAI_API_KEY | OpenAI API key for AI responses | Yes |
|
| 62 |
+
| DATABASE_URL | Database connection string | No |
|
| 63 |
+
|
| 64 |
+
## Dependencies
|
| 65 |
+
|
| 66 |
+
See `requirements.txt` for full dependency list.
|
| 67 |
+
|
| 68 |
+
Main dependencies:
|
| 69 |
+
- click >= 8.0.0
|
| 70 |
+
- rich >= 13.0.0
|
| 71 |
+
- requests >= 2.28.0
|
| 72 |
+
- pydantic >= 2.0.0
|
| 73 |
+
|
| 74 |
+
## Troubleshooting
|
| 75 |
+
|
| 76 |
+
### Installation fails
|
| 77 |
+
- Check Python version: `python --version`
|
| 78 |
+
- Upgrade pip: `pip install --upgrade pip`
|
| 79 |
+
- Try in virtual environment
|
| 80 |
+
|
| 81 |
+
### Module not found
|
| 82 |
+
- Reinstall: `pip install --force-reinstall burme-coder-max`
|
| 83 |
+
- Check PATH
|
| 84 |
+
|
| 85 |
+
### Permission denied
|
| 86 |
+
- Use `--user` flag: `pip install --user burme-coder-max`
|
| 87 |
+
- Or use virtual environment
|
| 88 |
+
|
| 89 |
+
## Uninstall
|
| 90 |
+
|
| 91 |
+
```bash
|
| 92 |
+
pip uninstall burme-coder-max
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
## Next Steps
|
| 96 |
+
|
| 97 |
+
See [usage.md](usage.md) for how to use burme-coder-max.
|
docs/usage.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Documentation: Usage Guide"""
|
| 2 |
+
|
| 3 |
+
# Usage Guide - Burme-Coder-Max
|
| 4 |
+
|
| 5 |
+
## Quick Start
|
| 6 |
+
|
| 7 |
+
### Ask a Question
|
| 8 |
+
|
| 9 |
+
```bash
|
| 10 |
+
burme-coder ask "Python decorator hta ya py"
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
### Interactive Mode
|
| 14 |
+
|
| 15 |
+
```bash
|
| 16 |
+
burme-coder interactive
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
### Train Agent
|
| 20 |
+
|
| 21 |
+
```bash
|
| 22 |
+
burme-coder train --data ./data/trajectories
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
## CLI Commands
|
| 26 |
+
|
| 27 |
+
### `ask` - Ask a single question
|
| 28 |
+
|
| 29 |
+
```bash
|
| 30 |
+
burme-coder ask [INSTRUCTION] [OPTIONS]
|
| 31 |
+
|
| 32 |
+
Options:
|
| 33 |
+
--model TEXT AI model to use (default: gpt-4)
|
| 34 |
+
--verbose Show detailed output
|
| 35 |
+
--output, -o Save response to file
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
### `interactive` - Start chat mode
|
| 39 |
+
|
| 40 |
+
```bash
|
| 41 |
+
burme-coder interactive
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
Interactive commands:
|
| 45 |
+
- `exit` - Quit
|
| 46 |
+
- `clear` - Clear history
|
| 47 |
+
- `help` - Show help
|
| 48 |
+
- `history` - Show conversation history
|
| 49 |
+
|
| 50 |
+
### `train` - Train on trajectories
|
| 51 |
+
|
| 52 |
+
```bash
|
| 53 |
+
burme-coder train [OPTIONS]
|
| 54 |
+
|
| 55 |
+
Options:
|
| 56 |
+
--data TEXT Training data directory (default: ./data/trajectories)
|
| 57 |
+
--epochs INT Number of epochs (default: 10)
|
| 58 |
+
--batch-size INT Batch size (default: 4)
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
### `eval` - Evaluate performance
|
| 62 |
+
|
| 63 |
+
```bash
|
| 64 |
+
burme-coder eval --data ./data/trajectories
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
## Python API
|
| 68 |
+
|
| 69 |
+
### Import and Use Agent
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
from burme_coder.core import CoderAgent
|
| 73 |
+
|
| 74 |
+
agent = CoderAgent(model="gpt-4")
|
| 75 |
+
response = agent.generate_response("Python list sorting hta ya")
|
| 76 |
+
|
| 77 |
+
print(response["response"])
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### Use Animations
|
| 81 |
+
|
| 82 |
+
```python
|
| 83 |
+
from burme_coder.animations import Spinner, ProgressBar
|
| 84 |
+
|
| 85 |
+
with Spinner("Loading"):
|
| 86 |
+
do_something()
|
| 87 |
+
|
| 88 |
+
for i in ProgressBar(range(100)):
|
| 89 |
+
process(i)
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
### Use Thanking System
|
| 93 |
+
|
| 94 |
+
```python
|
| 95 |
+
from burme_coder.ui.thanking import ThankYou
|
| 96 |
+
|
| 97 |
+
ThankYou.show()
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
## Configuration
|
| 101 |
+
|
| 102 |
+
Edit `.env` file:
|
| 103 |
+
|
| 104 |
+
```bash
|
| 105 |
+
# API Keys
|
| 106 |
+
OPENAI_API_KEY=sk-your-key-here
|
| 107 |
+
|
| 108 |
+
# Animation Settings
|
| 109 |
+
ANIMATION_SPEED=0.05
|
| 110 |
+
ANIMATION_COLOR=true
|
| 111 |
+
|
| 112 |
+
# Cache Settings
|
| 113 |
+
CACHE_DIR=./data/cache
|
| 114 |
+
CACHE_TTL=3600
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
## Knowledge Base
|
| 118 |
+
|
| 119 |
+
Search local knowledge:
|
| 120 |
+
|
| 121 |
+
```python
|
| 122 |
+
from burme_coder.knowledge import LocalKB
|
| 123 |
+
|
| 124 |
+
kb = LocalKB()
|
| 125 |
+
results = kb.search("python decorators")
|
| 126 |
+
|
| 127 |
+
for result in results:
|
| 128 |
+
print(result["snippet"])
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
Update from web:
|
| 132 |
+
|
| 133 |
+
```python
|
| 134 |
+
from burme_coder.knowledge import WebUpdater
|
| 135 |
+
|
| 136 |
+
updater = WebUpdater()
|
| 137 |
+
updater.update_markdown_files("./data/knowledge/skills")
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
## Examples
|
| 141 |
+
|
| 142 |
+
See `examples/` directory for more examples:
|
| 143 |
+
|
| 144 |
+
- `demo_animation.py` - Animation demonstrations
|
| 145 |
+
- `demo_thanking.py` - Thanking system examples
|
| 146 |
+
- `demo_skill_query.py` - Knowledge base queries
|
examples/demo_animation.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Demo: Animation Gallery
|
| 2 |
+
|
| 3 |
+
This script demonstrates all available animations in Burme-Coder-Max.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import sys
|
| 7 |
+
import time
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
|
| 11 |
+
|
| 12 |
+
from animations import Spinner, ProgressBar, ParticleBurst, TypingEffect
|
| 13 |
+
from animations.particle_effect import SimpleConfetti
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def demo_spinner():
|
| 17 |
+
"""Demonstrate spinner animation."""
|
| 18 |
+
print("\n🔄 Loading Spinner Demo")
|
| 19 |
+
print("=" * 40)
|
| 20 |
+
|
| 21 |
+
print("\nBasic spinner:")
|
| 22 |
+
with Spinner("Processing your request"):
|
| 23 |
+
for _ in range(20):
|
| 24 |
+
time.sleep(0.05)
|
| 25 |
+
|
| 26 |
+
print("✓ Complete!\n")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def demo_progress():
|
| 30 |
+
"""Demonstrate progress bar animation."""
|
| 31 |
+
print("\n📊 Progress Bar Demo")
|
| 32 |
+
print("=" * 40)
|
| 33 |
+
|
| 34 |
+
print("\nDefault progress bar:")
|
| 35 |
+
for i in ProgressBar(range(50), description="Downloading"):
|
| 36 |
+
time.sleep(0.03)
|
| 37 |
+
|
| 38 |
+
print("✦ Progress bar demo complete!\n")
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def demo_particles():
|
| 42 |
+
"""Demonstrate particle burst effect."""
|
| 43 |
+
print("\n✨ Particle Burst Demo")
|
| 44 |
+
print("=" * 40)
|
| 45 |
+
|
| 46 |
+
print("\n🎉 Celebration effect:")
|
| 47 |
+
burst = ParticleBurst(count=40)
|
| 48 |
+
burst.center_x = 50
|
| 49 |
+
burst.center_y = 12
|
| 50 |
+
burst.explode()
|
| 51 |
+
|
| 52 |
+
print("✦ Particle burst complete!\n")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def demo_typing():
|
| 56 |
+
"""Demonstrate typing effect."""
|
| 57 |
+
print("\n⌨️ Typing Effect Demo")
|
| 58 |
+
print("=" * 40)
|
| 59 |
+
|
| 60 |
+
effect = TypingEffect("Hello from Burme-Coder-Max! 🧑💻", delay=0.06)
|
| 61 |
+
effect.animate()
|
| 62 |
+
|
| 63 |
+
print()
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def demo_confetti():
|
| 67 |
+
"""Demonstrate confetti effect."""
|
| 68 |
+
print("\n🎊 Confetti Demo")
|
| 69 |
+
print("=" * 40)
|
| 70 |
+
|
| 71 |
+
confetti = SimpleConfetti(duration=1.5)
|
| 72 |
+
confetti.show()
|
| 73 |
+
|
| 74 |
+
print()
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def main():
|
| 78 |
+
"""Run all animation demos."""
|
| 79 |
+
print()
|
| 80 |
+
print("╔" + "═" * 48 + "╗")
|
| 81 |
+
print("║" + " 🎨 ANIMATION GALLERY ".center(48) + "║")
|
| 82 |
+
print("╚" + "═" * 48 + "╝")
|
| 83 |
+
|
| 84 |
+
demos = [
|
| 85 |
+
("Spinner", demo_spinner),
|
| 86 |
+
("Progress Bar", demo_progress),
|
| 87 |
+
("Particle Burst", demo_particles),
|
| 88 |
+
("Typing Effect", demo_typing),
|
| 89 |
+
("Confetti", demo_confetti),
|
| 90 |
+
]
|
| 91 |
+
|
| 92 |
+
for name, demo_func in demos:
|
| 93 |
+
try:
|
| 94 |
+
demo_func()
|
| 95 |
+
time.sleep(0.3)
|
| 96 |
+
except KeyboardInterrupt:
|
| 97 |
+
print("\n\nInterrupted by user")
|
| 98 |
+
break
|
| 99 |
+
|
| 100 |
+
print("╔" + "═" * 48 + "╗")
|
| 101 |
+
print("║" + " ✨ DEMO COMPLETE ".center(48) + "║")
|
| 102 |
+
print("╚" + "═" * 48 + "╝")
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
if __name__ == "__main__":
|
| 106 |
+
main()
|
examples/demo_skill_query.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Demo: Skill Query
|
| 2 |
+
|
| 3 |
+
This script demonstrates how to query the knowledge base.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import sys
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
|
| 10 |
+
|
| 11 |
+
from knowledge import LocalKB
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def demo_basic_search():
|
| 15 |
+
"""Demonstrate basic knowledge search."""
|
| 16 |
+
print("\n🔍 Basic Knowledge Search")
|
| 17 |
+
print("=" * 40)
|
| 18 |
+
|
| 19 |
+
kb = LocalKB()
|
| 20 |
+
|
| 21 |
+
print("\nSearch for: 'python decorator' ")
|
| 22 |
+
results = kb.search("python decorator")
|
| 23 |
+
|
| 24 |
+
if results:
|
| 25 |
+
print(f"\nFound {len(results)} results:")
|
| 26 |
+
for i, result in enumerate(results[:5], 1):
|
| 27 |
+
print(f"\n{i}. {result['source']} (line {result['line']})")
|
| 28 |
+
print(f" {result['snippet'][:100]}...")
|
| 29 |
+
else:
|
| 30 |
+
print("\nNo results found")
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def demo_topic_search():
|
| 34 |
+
"""Demonstrate topic-specific search."""
|
| 35 |
+
print("\n📚 Topic Search")
|
| 36 |
+
print("=" * 40)
|
| 37 |
+
|
| 38 |
+
kb = LocalKB()
|
| 39 |
+
|
| 40 |
+
topics = kb.get_all_topics()
|
| 41 |
+
print("\nAvailable topics:")
|
| 42 |
+
for topic in topics:
|
| 43 |
+
print(f" - {topic}")
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def demo_random_entry():
|
| 47 |
+
"""Demonstrate getting random knowledge entry."""
|
| 48 |
+
print("\n🎲 Random Knowledge Entry")
|
| 49 |
+
print("=" * 40)
|
| 50 |
+
|
| 51 |
+
kb = LocalKB()
|
| 52 |
+
entry = kb.get_random_entry()
|
| 53 |
+
|
| 54 |
+
if entry:
|
| 55 |
+
print(f"\nRandom entry from: {entry['source']}")
|
| 56 |
+
print("\n---")
|
| 57 |
+
print(entry["content"][:300])
|
| 58 |
+
print("---")
|
| 59 |
+
else:
|
| 60 |
+
print("\nNo entries available")
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def demo_skill_file_access():
|
| 64 |
+
"""Demonstrate accessing specific skill files."""
|
| 65 |
+
print("\n📁 Skill File Access")
|
| 66 |
+
print("=" * 40)
|
| 67 |
+
|
| 68 |
+
kb = LocalKB()
|
| 69 |
+
|
| 70 |
+
content = kb.get_content("python")
|
| 71 |
+
if content:
|
| 72 |
+
print("\nPython skills content (preview):")
|
| 73 |
+
print(content[:500])
|
| 74 |
+
else:
|
| 75 |
+
print("\nPython skills file not found")
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def main():
|
| 79 |
+
"""Run all knowledge base demos."""
|
| 80 |
+
print()
|
| 81 |
+
print("╔" + "═" * 48 + "╗")
|
| 82 |
+
print("║" + " 📚 KNOWLEDGE BASE DEMO ".center(48) + "║")
|
| 83 |
+
print("╚" + "═" * 48 + "╝")
|
| 84 |
+
|
| 85 |
+
demos = [
|
| 86 |
+
("Topic List", demo_topic_search),
|
| 87 |
+
("Basic Search", demo_basic_search),
|
| 88 |
+
("Skill Files", demo_skill_file_access),
|
| 89 |
+
("Random Entry", demo_random_entry),
|
| 90 |
+
]
|
| 91 |
+
|
| 92 |
+
for name, demo_func in demos:
|
| 93 |
+
input(f"\n[Press Enter for '{name}' demo]")
|
| 94 |
+
demo_func()
|
| 95 |
+
|
| 96 |
+
print("\n" + "═" * 48)
|
| 97 |
+
print("✨ Demo complete! Explore the knowledge base!")
|
| 98 |
+
print("═" * 48)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
if __name__ == "__main__":
|
| 102 |
+
main()
|
examples/demo_thanking.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Demo: Thanking System
|
| 2 |
+
|
| 3 |
+
This script demonstrates the thanking system in Burme-Coder-Max.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import sys
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
|
| 10 |
+
|
| 11 |
+
from ui.thanking import ThankYou, Appreciation, CreditDisplay
|
| 12 |
+
from ui.thanking.thank_you import quick_thank
|
| 13 |
+
from ui.thanking.appreciation import show_custom_appreciation
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def demo_basic_thanks():
|
| 17 |
+
"""Demonstrate basic thank you messages."""
|
| 18 |
+
print("\n🙏 Basic Thank You Messages")
|
| 19 |
+
print("=" * 40)
|
| 20 |
+
|
| 21 |
+
ThankYou.show()
|
| 22 |
+
ThankYou.show_animation()
|
| 23 |
+
ThankYou.show_with_emoji("⭐")
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def demo_emoji_variations():
|
| 27 |
+
"""Demonstrate different emoji options."""
|
| 28 |
+
print("\n⭐ Emoji Variations")
|
| 29 |
+
print("=" * 40)
|
| 30 |
+
|
| 31 |
+
emojis = ["🙏", "💖", "🎉", "✨", "⭐", "🌟", "💫"]
|
| 32 |
+
for emoji in emojis:
|
| 33 |
+
ThankYou.show_with_emoji(emoji)
|
| 34 |
+
print()
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def demo_custom_appreciation():
|
| 38 |
+
"""Demonstrate custom appreciation."""
|
| 39 |
+
print("\n🏆 Custom Appreciation")
|
| 40 |
+
print("=" * 40)
|
| 41 |
+
|
| 42 |
+
show_custom_appreciation(
|
| 43 |
+
title="Learning Milestone",
|
| 44 |
+
message="Congratulations on completing Python basics!",
|
| 45 |
+
badges=["Python Novice", "First Function", "Loop Master"],
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def demo_detailed_appreciation():
|
| 50 |
+
"""Demonstrate detailed appreciation."""
|
| 51 |
+
print("\n📝 Detailed Appreciation")
|
| 52 |
+
print("=" * 40)
|
| 53 |
+
|
| 54 |
+
Appreciation.show("Python decorators")
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def demo_credit_display():
|
| 58 |
+
"""Demonstrate credits."""
|
| 59 |
+
print("\n📜 Credits Display")
|
| 60 |
+
print("=" * 40)
|
| 61 |
+
|
| 62 |
+
CreditDisplay.show_simple()
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def demo_quick_thank():
|
| 66 |
+
"""Demonstrate quick thank."""
|
| 67 |
+
print("\n⚡ Quick Thank")
|
| 68 |
+
print("=" * 40)
|
| 69 |
+
|
| 70 |
+
quick_thank()
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def main():
|
| 74 |
+
"""Run all thanking demos."""
|
| 75 |
+
print()
|
| 76 |
+
print("╔" + "═" * 48 + "╗")
|
| 77 |
+
print("║" + " 🙏 THANKING SYSTEM DEMO ".center(48) + "║")
|
| 78 |
+
print("╚" + "═" * 48 + "╝")
|
| 79 |
+
|
| 80 |
+
demos = [
|
| 81 |
+
("Basic Thanks", demo_basic_thanks),
|
| 82 |
+
("Emoji Variations", demo_emoji_variations),
|
| 83 |
+
("Custom Appreciation", demo_custom_appreciation),
|
| 84 |
+
("Detailed Appreciation", demo_detailed_appreciation),
|
| 85 |
+
("Credits", demo_credit_display),
|
| 86 |
+
("Quick Thank", demo_quick_thank),
|
| 87 |
+
]
|
| 88 |
+
|
| 89 |
+
for name, demo_func in demos:
|
| 90 |
+
input(f"\n[Press Enter for '{name}' demo]")
|
| 91 |
+
demo_func()
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
if __name__ == "__main__":
|
| 95 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
click>=8.0.0
|
| 2 |
+
rich>=13.0.0
|
| 3 |
+
requests>=2.28.0
|
| 4 |
+
beautifulsoup4>=4.11.0
|
| 5 |
+
lxml>=4.9.0
|
| 6 |
+
pydantic>=2.0.0
|
| 7 |
+
tqdm>=4.65.0
|
scripts/build_markdown_index.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Build markdown index for fast searching"""
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from typing import Dict, List
|
| 6 |
+
|
| 7 |
+
sys.path.insert(0, str(Path(__file__).parent.parent))
|
| 8 |
+
|
| 9 |
+
from src.utils import MarkdownParser
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class MarkdownIndexBuilder:
|
| 13 |
+
"""Build searchable index from markdown files"""
|
| 14 |
+
|
| 15 |
+
def __init__(self, knowledge_dir: Path, output_file: Path):
|
| 16 |
+
self.knowledge_dir = Path(knowledge_dir)
|
| 17 |
+
self.output_file = Path(output_file)
|
| 18 |
+
self.index: Dict = {
|
| 19 |
+
"files": [],
|
| 20 |
+
"headings": [],
|
| 21 |
+
"code_blocks": [],
|
| 22 |
+
"keywords": {},
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
def build(self):
|
| 26 |
+
"""Build index from all markdown files"""
|
| 27 |
+
print("🔍 Building markdown index...")
|
| 28 |
+
|
| 29 |
+
md_files = list(self.knowledge_dir.rglob("*.md"))
|
| 30 |
+
print(f"Found {len(md_files)} markdown files")
|
| 31 |
+
|
| 32 |
+
for md_file in md_files:
|
| 33 |
+
self._index_file(md_file)
|
| 34 |
+
|
| 35 |
+
self._save_index()
|
| 36 |
+
print(f"✓ Index saved to {self.output_file}")
|
| 37 |
+
|
| 38 |
+
def _index_file(self, file_path: Path):
|
| 39 |
+
"""Index a single markdown file"""
|
| 40 |
+
parser = MarkdownParser.from_file(str(file_path))
|
| 41 |
+
|
| 42 |
+
relative_path = file_path.relative_to(self.knowledge_dir.parent)
|
| 43 |
+
file_info = {
|
| 44 |
+
"path": str(relative_path),
|
| 45 |
+
"name": file_path.name,
|
| 46 |
+
"stem": file_path.stem,
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
headings = parser.extract_headings()
|
| 50 |
+
for heading in headings:
|
| 51 |
+
self.index["headings"].append(
|
| 52 |
+
{
|
| 53 |
+
"file": str(relative_path),
|
| 54 |
+
"level": heading.level,
|
| 55 |
+
"text": heading.text,
|
| 56 |
+
"line": heading.line,
|
| 57 |
+
}
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
code_blocks = parser.extract_code_blocks()
|
| 61 |
+
for block in code_blocks:
|
| 62 |
+
self.index["code_blocks"].append(
|
| 63 |
+
{
|
| 64 |
+
"file": str(relative_path),
|
| 65 |
+
"language": block.language,
|
| 66 |
+
"preview": block.content[:100],
|
| 67 |
+
"line": block.start_line,
|
| 68 |
+
}
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
plain_text = parser.convert_to_plain_text()
|
| 72 |
+
for word in self._extract_keywords(plain_text):
|
| 73 |
+
if word not in self.index["keywords"]:
|
| 74 |
+
self.index["keywords"][word] = []
|
| 75 |
+
self.index["keywords"][word].append(str(relative_path))
|
| 76 |
+
|
| 77 |
+
self.index["files"].append(file_info)
|
| 78 |
+
|
| 79 |
+
print(f" ✓ Indexed: {file_path.name}")
|
| 80 |
+
|
| 81 |
+
def _extract_keywords(self, text: str) -> List[str]:
|
| 82 |
+
"""Extract important keywords from text"""
|
| 83 |
+
import re
|
| 84 |
+
|
| 85 |
+
words = re.findall(r"\b[a-zA-Z_]{3,}\b", text.lower())
|
| 86 |
+
|
| 87 |
+
common_words = {
|
| 88 |
+
"the",
|
| 89 |
+
"and",
|
| 90 |
+
"for",
|
| 91 |
+
"this",
|
| 92 |
+
"that",
|
| 93 |
+
"with",
|
| 94 |
+
"from",
|
| 95 |
+
"your",
|
| 96 |
+
}
|
| 97 |
+
keywords = [w for w in words if w not in common_words]
|
| 98 |
+
|
| 99 |
+
from collections import Counter
|
| 100 |
+
|
| 101 |
+
word_freq = Counter(keywords)
|
| 102 |
+
return [w for w, _ in word_freq.most_common(100)]
|
| 103 |
+
|
| 104 |
+
def _save_index(self):
|
| 105 |
+
"""Save index to JSON file"""
|
| 106 |
+
self.output_file.parent.mkdir(parents=True, exist_ok=True)
|
| 107 |
+
with open(self.output_file, "w", encoding="utf-8") as f:
|
| 108 |
+
json.dump(self.index, f, indent=2, ensure_ascii=False)
|
| 109 |
+
|
| 110 |
+
def search(self, query: str) -> List[Dict]:
|
| 111 |
+
"""Search the index"""
|
| 112 |
+
with open(self.output_file, "r", encoding="utf-8") as f:
|
| 113 |
+
index = json.load(f)
|
| 114 |
+
|
| 115 |
+
results = []
|
| 116 |
+
query_lower = query.lower()
|
| 117 |
+
|
| 118 |
+
for heading in index["headings"]:
|
| 119 |
+
if query_lower in heading["text"].lower():
|
| 120 |
+
results.append(
|
| 121 |
+
{
|
| 122 |
+
"type": "heading",
|
| 123 |
+
"file": heading["file"],
|
| 124 |
+
"text": heading["text"],
|
| 125 |
+
"line": heading["line"],
|
| 126 |
+
}
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
for code in index["code_blocks"]:
|
| 130 |
+
if query_lower in code["preview"].lower():
|
| 131 |
+
results.append(
|
| 132 |
+
{
|
| 133 |
+
"type": "code",
|
| 134 |
+
"file": code["file"],
|
| 135 |
+
"language": code["language"],
|
| 136 |
+
"preview": code["preview"],
|
| 137 |
+
"line": code["line"],
|
| 138 |
+
}
|
| 139 |
+
)
|
| 140 |
+
|
| 141 |
+
return results
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
import sys
|
| 145 |
+
|
| 146 |
+
if __name__ == "__main__":
|
| 147 |
+
base_dir = Path(__file__).parent.parent
|
| 148 |
+
knowledge_dir = base_dir / "data" / "knowledge"
|
| 149 |
+
output_file = base_dir / "data" / "cache" / "markdown_index.json"
|
| 150 |
+
|
| 151 |
+
builder = MarkdownIndexBuilder(knowledge_dir, output_file)
|
| 152 |
+
builder.build()
|
| 153 |
+
|
| 154 |
+
print("\n📋 Search index built successfully!")
|
| 155 |
+
print(f"📁 Output: {output_file}")
|
scripts/generate_thanks.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Thanking Message Generator"""
|
| 2 |
+
|
| 3 |
+
import random
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class ThankingMessageGenerator:
|
| 8 |
+
"""Generate variety of thank you messages"""
|
| 9 |
+
|
| 10 |
+
EMOJIS = ["🙏", "💖", "⭐", "✨", "🌟", "💫", "🎉", "🙏"]
|
| 11 |
+
|
| 12 |
+
GREETINGS = [
|
| 13 |
+
"Thank you for using",
|
| 14 |
+
"Appreciate your interest in",
|
| 15 |
+
"Grateful for your support of",
|
| 16 |
+
"Thanks for trying",
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
PRODUCT_NAME = "Burme-Coder-Max"
|
| 20 |
+
|
| 21 |
+
FOLLOW_UPS = [
|
| 22 |
+
"Keep coding!",
|
| 23 |
+
"Happy coding!",
|
| 24 |
+
"Let me know if you need more help!",
|
| 25 |
+
"Feel free to ask follow-up questions!",
|
| 26 |
+
"Happy learning!",
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
@classmethod
|
| 30 |
+
def generate(cls, include_emoji: bool = True) -> str:
|
| 31 |
+
"""Generate a random thank you message"""
|
| 32 |
+
parts = []
|
| 33 |
+
|
| 34 |
+
if include_emoji:
|
| 35 |
+
parts.append(random.choice(cls.EMOJIS))
|
| 36 |
+
parts.append(" ")
|
| 37 |
+
|
| 38 |
+
parts.append(random.choice(cls.GREETINGS))
|
| 39 |
+
parts.append(" ")
|
| 40 |
+
parts.append(cls.PRODUCT_NAME)
|
| 41 |
+
parts.append("!")
|
| 42 |
+
|
| 43 |
+
if random.random() > 0.5:
|
| 44 |
+
parts.append("\n")
|
| 45 |
+
parts.append(random.choice(cls.FOLLOW_UPS))
|
| 46 |
+
|
| 47 |
+
return "".join(parts)
|
| 48 |
+
|
| 49 |
+
@classmethod
|
| 50 |
+
def generate_detailed(cls, topic: str = None) -> dict:
|
| 51 |
+
"""Generate detailed appreciation message"""
|
| 52 |
+
return {
|
| 53 |
+
"message": cls.generate(),
|
| 54 |
+
"topic": topic,
|
| 55 |
+
"timestamp": datetime.now().isoformat(),
|
| 56 |
+
"emoji": random.choice(cls.EMOJIS),
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
@classmethod
|
| 60 |
+
def generate_stack(cls, count: int = 3) -> list:
|
| 61 |
+
"""Generate multiple thank you messages"""
|
| 62 |
+
return [cls.generate() for _ in range(count)]
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def main():
|
| 66 |
+
"""Demo the thank you generator"""
|
| 67 |
+
print("=== Thanking Message Generator ===\n")
|
| 68 |
+
|
| 69 |
+
generator = ThankingMessageGenerator()
|
| 70 |
+
|
| 71 |
+
print("Single message:")
|
| 72 |
+
print(generator.generate())
|
| 73 |
+
print()
|
| 74 |
+
|
| 75 |
+
print("With topic:")
|
| 76 |
+
detailed = generator.generate_detailed("Python decorators")
|
| 77 |
+
print(detailed["message"])
|
| 78 |
+
print(f"Topic: {detailed['topic']}")
|
| 79 |
+
print()
|
| 80 |
+
|
| 81 |
+
print("Multiple messages (stack):")
|
| 82 |
+
for i, msg in enumerate(generator.generate_stack(3), 1):
|
| 83 |
+
print(f"{i}. {msg}")
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
if __name__ == "__main__":
|
| 87 |
+
main()
|
scripts/update_knowledge.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Web-based Knowledge Update Script"""
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
sys.path.insert(0, str(Path(__file__).parent.parent))
|
| 7 |
+
|
| 8 |
+
from src.knowledge import WebUpdater, LocalKB
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def main():
|
| 12 |
+
"""Update knowledge from web sources"""
|
| 13 |
+
print("🌐 Burme-Coder-Max Web Updater")
|
| 14 |
+
print("=" * 40)
|
| 15 |
+
|
| 16 |
+
updater = WebUpdater()
|
| 17 |
+
|
| 18 |
+
print("\nFetching content from web sources...")
|
| 19 |
+
results = updater.fetch_all()
|
| 20 |
+
|
| 21 |
+
print(f"\n✓ Fetched {len(results)} sources:")
|
| 22 |
+
for name in results.keys():
|
| 23 |
+
print(f" - {name}")
|
| 24 |
+
|
| 25 |
+
output_dir = Path(__file__).parent.parent / "data" / "knowledge" / "skills"
|
| 26 |
+
|
| 27 |
+
print(f"\nUpdating markdown files to {output_dir}...")
|
| 28 |
+
updated = updater.update_markdown_files(output_dir, force=False)
|
| 29 |
+
|
| 30 |
+
print(f"✓ Updated {len(updated)} files:")
|
| 31 |
+
for name in updated:
|
| 32 |
+
print(f" - {name}")
|
| 33 |
+
|
| 34 |
+
print("\n✅ Knowledge update complete!")
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
main()
|
setup.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""burme-coder-max: Myanmar AI Coding Agent Package"""
|
| 2 |
+
from setuptools import setup, find_packages
|
| 3 |
+
|
| 4 |
+
setup(
|
| 5 |
+
name="burme-coder-max",
|
| 6 |
+
version="1.0.0",
|
| 7 |
+
author="amkyawdev",
|
| 8 |
+
author_email="contact@amkyawdev.com",
|
| 9 |
+
description="Expert Myanmar AI coding agent with terminal animations",
|
| 10 |
+
long_description=open("README.md", "r", encoding="utf-8").read(),
|
| 11 |
+
long_description_content_type="text/markdown",
|
| 12 |
+
url="https://huggingface.co/datasets/amkyawdev/burme-coder-max",
|
| 13 |
+
packages=find_packages(where="src"),
|
| 14 |
+
package_dir={"": "src"},
|
| 15 |
+
classifiers=[
|
| 16 |
+
"Development Status :: 4 - Beta",
|
| 17 |
+
"Intended Audience :: Developers",
|
| 18 |
+
"License :: OSI Approved :: MIT License",
|
| 19 |
+
"Programming Language :: Python :: 3",
|
| 20 |
+
"Programming Language :: Python :: 3.8",
|
| 21 |
+
"Programming Language :: Python :: 3.9",
|
| 22 |
+
"Programming Language :: Python :: 3.10",
|
| 23 |
+
"Programming Language :: Python :: 3.11",
|
| 24 |
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
| 25 |
+
],
|
| 26 |
+
python_requires=">=3.8",
|
| 27 |
+
install_requires=[
|
| 28 |
+
"click>=8.0.0",
|
| 29 |
+
"rich>=13.0.0",
|
| 30 |
+
"requests>=2.28.0",
|
| 31 |
+
"beautifulsoup4>=4.11.0",
|
| 32 |
+
"lxml>=4.9.0",
|
| 33 |
+
"pydantic>=2.0.0",
|
| 34 |
+
],
|
| 35 |
+
extras_require={
|
| 36 |
+
"dev": [
|
| 37 |
+
"pytest>=7.0.0",
|
| 38 |
+
"pytest-asyncio>=0.21.0",
|
| 39 |
+
"black>=23.0.0",
|
| 40 |
+
"mypy>=1.0.0",
|
| 41 |
+
],
|
| 42 |
+
},
|
| 43 |
+
entry_points={
|
| 44 |
+
"console_scripts": [
|
| 45 |
+
"burme-coder=cli.main:main",
|
| 46 |
+
],
|
| 47 |
+
},
|
| 48 |
+
)
|
src/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""burme-coder-max: Myanmar AI Coding Agent Package"""
|
| 2 |
+
|
| 3 |
+
__version__ = "1.0.0"
|
| 4 |
+
__author__ = "amkyawdev"
|
| 5 |
+
|
| 6 |
+
from src.core import agent, executor, validator
|
| 7 |
+
from src.cli import main
|
| 8 |
+
from src.animations import Spinner, ProgressBar, TypingEffect
|
| 9 |
+
from src.ui import colors, layout, thanking
|
| 10 |
+
from src.knowledge import LocalKB, WebUpdater
|
src/animations/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Animations module - Terminal visual effects"""
|
| 2 |
+
|
| 3 |
+
from .spinner import Spinner
|
| 4 |
+
from .progress_bar import ProgressBar
|
| 5 |
+
from .particle_effect import ParticleBurst
|
| 6 |
+
from .typing_effect import TypingEffect
|
| 7 |
+
from .config import AnimationConfig
|
| 8 |
+
|
| 9 |
+
__all__ = [
|
| 10 |
+
"Spinner",
|
| 11 |
+
"ProgressBar",
|
| 12 |
+
"ParticleBurst",
|
| 13 |
+
"TypingEffect",
|
| 14 |
+
"AnimationConfig",
|
| 15 |
+
]
|
src/animations/config.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Animation Configuration"""
|
| 2 |
+
|
| 3 |
+
from dataclasses import dataclass
|
| 4 |
+
from enum import Enum
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class ColorMode(Enum):
|
| 8 |
+
"""Color mode options"""
|
| 9 |
+
|
| 10 |
+
AUTO = "auto"
|
| 11 |
+
ALWAYS = "always"
|
| 12 |
+
NEVER = "never"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@dataclass
|
| 16 |
+
class AnimationConfig:
|
| 17 |
+
"""Configuration for terminal animations"""
|
| 18 |
+
|
| 19 |
+
speed: float = 0.05
|
| 20 |
+
color_enabled: bool = True
|
| 21 |
+
color_mode: ColorMode = ColorMode.AUTO
|
| 22 |
+
default_frames: int = 30
|
| 23 |
+
particle_count: int = 50
|
| 24 |
+
|
| 25 |
+
SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
|
| 26 |
+
|
| 27 |
+
PROGRESS_CHARS = "█▓▒░"
|
| 28 |
+
|
| 29 |
+
@classmethod
|
| 30 |
+
def from_env(cls) -> "AnimationConfig":
|
| 31 |
+
"""Create config from environment variables"""
|
| 32 |
+
import os
|
| 33 |
+
|
| 34 |
+
return cls(
|
| 35 |
+
speed=float(os.getenv("ANIMATION_SPEED", "0.05")),
|
| 36 |
+
color_enabled=os.getenv("ANIMATION_COLOR", "true").lower() == "true",
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
def should_use_color(self) -> bool:
|
| 40 |
+
"""Check if color should be used"""
|
| 41 |
+
if not self.color_enabled:
|
| 42 |
+
return False
|
| 43 |
+
|
| 44 |
+
if self.color_mode == ColorMode.ALWAYS:
|
| 45 |
+
return True
|
| 46 |
+
elif self.color_mode == ColorMode.NEVER:
|
| 47 |
+
return False
|
| 48 |
+
else:
|
| 49 |
+
import sys
|
| 50 |
+
|
| 51 |
+
return sys.stdout.isatty()
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
DEFAULT_CONFIG = AnimationConfig()
|
src/animations/particle_effect.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Particle Burst Effect - Celebration animations"""
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
import time
|
| 5 |
+
import random
|
| 6 |
+
import threading
|
| 7 |
+
from typing import Optional, Tuple
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
|
| 10 |
+
from .config import DEFAULT_CONFIG, AnimationConfig
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@dataclass
|
| 14 |
+
class Particle:
|
| 15 |
+
"""Individual particle for burst effect"""
|
| 16 |
+
|
| 17 |
+
x: float
|
| 18 |
+
y: float
|
| 19 |
+
vx: float
|
| 20 |
+
vy: float
|
| 21 |
+
char: str
|
| 22 |
+
color: str
|
| 23 |
+
lifetime: int
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class ParticleBurst:
|
| 27 |
+
"""Create particle burst celebration effect"""
|
| 28 |
+
|
| 29 |
+
PARTICLE_CHARS = ["*", "✦", "◆", "●", "○", "✿", "❀", "★", "☆", "◇", "□", "○"]
|
| 30 |
+
COLORS = [
|
| 31 |
+
"\033[91m",
|
| 32 |
+
"\033[92m",
|
| 33 |
+
"\033[93m",
|
| 34 |
+
"\033[94m",
|
| 35 |
+
"\033[95m",
|
| 36 |
+
"\033[96m",
|
| 37 |
+
"\033[97m",
|
| 38 |
+
]
|
| 39 |
+
RESET = "\033[0m"
|
| 40 |
+
|
| 41 |
+
def __init__(
|
| 42 |
+
self,
|
| 43 |
+
center_x: Optional[int] = None,
|
| 44 |
+
center_y: Optional[int] = None,
|
| 45 |
+
count: int = 50,
|
| 46 |
+
config: Optional[AnimationConfig] = None,
|
| 47 |
+
):
|
| 48 |
+
self.center_x = center_x or 40
|
| 49 |
+
self.center_y = center_y or 10
|
| 50 |
+
self.count = count
|
| 51 |
+
self.config = config or DEFAULT_CONFIG
|
| 52 |
+
self.particles: list[Particle] = []
|
| 53 |
+
self.running = False
|
| 54 |
+
|
| 55 |
+
def _create_particle(self) -> Particle:
|
| 56 |
+
"""Create a single particle"""
|
| 57 |
+
angle = random.uniform(0, 2 * 3.14159)
|
| 58 |
+
speed = random.uniform(0.5, 2.0)
|
| 59 |
+
|
| 60 |
+
return Particle(
|
| 61 |
+
x=self.center_x,
|
| 62 |
+
y=self.center_y,
|
| 63 |
+
vx=random.uniform(-1, 1) + (1 if angle < 3.14159 else -1),
|
| 64 |
+
vy=random.uniform(-2, 0),
|
| 65 |
+
char=random.choice(self.PARTICLE_CHARS),
|
| 66 |
+
color=random.choice(self.COLORS),
|
| 67 |
+
lifetime=random.randint(20, 40),
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
def _animate(self):
|
| 71 |
+
"""Animate particle system"""
|
| 72 |
+
self.particles = [self._create_particle() for _ in range(self.count)]
|
| 73 |
+
self.running = True
|
| 74 |
+
|
| 75 |
+
while self.running and self.particles:
|
| 76 |
+
lines = []
|
| 77 |
+
max_y = 0
|
| 78 |
+
|
| 79 |
+
for particle in self.particles[:]:
|
| 80 |
+
particle.x += particle.vx
|
| 81 |
+
particle.y += particle.vy
|
| 82 |
+
particle.vy += 0.1
|
| 83 |
+
particle.lifetime -= 1
|
| 84 |
+
|
| 85 |
+
if particle.lifetime <= 0 or particle.y > 50:
|
| 86 |
+
self.particles.remove(particle)
|
| 87 |
+
continue
|
| 88 |
+
|
| 89 |
+
x_pos = max(0, int(particle.x))
|
| 90 |
+
y_pos = max(0, int(particle.y))
|
| 91 |
+
max_y = max(max_y, y_pos)
|
| 92 |
+
|
| 93 |
+
line_content = " " * x_pos + particle.color + particle.char + self.RESET
|
| 94 |
+
lines.append((y_pos, line_content))
|
| 95 |
+
|
| 96 |
+
if not lines:
|
| 97 |
+
break
|
| 98 |
+
|
| 99 |
+
lines.sort(key=lambda x: x[0])
|
| 100 |
+
|
| 101 |
+
sys.stdout.write("\033[2J")
|
| 102 |
+
sys.stdout.write("\033[H")
|
| 103 |
+
|
| 104 |
+
for y, content in lines:
|
| 105 |
+
sys.stdout.write(content + "\n")
|
| 106 |
+
|
| 107 |
+
for _ in range(max(0, 20 - max_y)):
|
| 108 |
+
sys.stdout.write("\n")
|
| 109 |
+
|
| 110 |
+
sys.stdout.flush()
|
| 111 |
+
time.sleep(0.05)
|
| 112 |
+
|
| 113 |
+
sys.stdout.write("\033[2J")
|
| 114 |
+
sys.stdout.write("\033[H")
|
| 115 |
+
sys.stdout.flush()
|
| 116 |
+
|
| 117 |
+
def explode(self):
|
| 118 |
+
"""Trigger the burst animation"""
|
| 119 |
+
thread = threading.Thread(target=self._animate, daemon=True)
|
| 120 |
+
thread.start()
|
| 121 |
+
thread.join()
|
| 122 |
+
|
| 123 |
+
@staticmethod
|
| 124 |
+
def explode_at(message: str, times: int = 3):
|
| 125 |
+
"""Show explosion effect around a message"""
|
| 126 |
+
for _ in range(times):
|
| 127 |
+
burst = ParticleBurst(count=30)
|
| 128 |
+
burst.center_x = 50
|
| 129 |
+
burst.center_y = 15
|
| 130 |
+
burst.explode()
|
| 131 |
+
time.sleep(0.3)
|
| 132 |
+
|
| 133 |
+
print(message)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
class SimpleConfetti:
|
| 137 |
+
"""Lightweight confetti effect"""
|
| 138 |
+
|
| 139 |
+
CONFETTI = ["🎉", "🎊", "✨", "💫", "⭐", "🌟", "🎈", "🎁"]
|
| 140 |
+
|
| 141 |
+
def __init__(self, duration: float = 2.0):
|
| 142 |
+
self.duration = duration
|
| 143 |
+
self.end_time = 0
|
| 144 |
+
|
| 145 |
+
def __iter__(self):
|
| 146 |
+
"""Generate confetti frames"""
|
| 147 |
+
self.end_time = time.time() + self.duration
|
| 148 |
+
while time.time() < self.end_time:
|
| 149 |
+
confetti = " ".join(random.choices(self.CONFETTI, k=random.randint(5, 15)))
|
| 150 |
+
yield f"\r{confetti}"
|
| 151 |
+
time.sleep(0.2)
|
| 152 |
+
|
| 153 |
+
yield "\r" + " " * 50 + "\r"
|
| 154 |
+
|
| 155 |
+
def show(self):
|
| 156 |
+
"""Display confetti"""
|
| 157 |
+
try:
|
| 158 |
+
for frame in self:
|
| 159 |
+
sys.stdout.write(frame)
|
| 160 |
+
sys.stdout.flush()
|
| 161 |
+
except KeyboardInterrupt:
|
| 162 |
+
pass
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
class ThankYouBurst:
|
| 166 |
+
"""Special burst for thank you messages"""
|
| 167 |
+
|
| 168 |
+
@staticmethod
|
| 169 |
+
def show():
|
| 170 |
+
"""Show thank you burst animation"""
|
| 171 |
+
ParticleBurst.explode_at("🙏 Thank You! 🙏", times=3)
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def celebration(message: str = "🎉"):
|
| 175 |
+
"""Quick celebration effect"""
|
| 176 |
+
SimpleConfetti(duration=1.5).show()
|
| 177 |
+
print(message)
|
src/animations/progress_bar.py
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Progress Bar - Show progress for long operations"""
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
import time
|
| 5 |
+
from typing import Iterable, Optional, Union
|
| 6 |
+
from dataclasses import dataclass
|
| 7 |
+
|
| 8 |
+
from .config import DEFAULT_CONFIG, AnimationConfig
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@dataclass
|
| 12 |
+
class ProgressBarConfig:
|
| 13 |
+
"""Configuration for progress bar appearance"""
|
| 14 |
+
|
| 15 |
+
width: int = 40
|
| 16 |
+
fill_char: str = "█"
|
| 17 |
+
empty_char: str = "░"
|
| 18 |
+
show_percentage: bool = True
|
| 19 |
+
show_count: bool = True
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class ProgressBar:
|
| 23 |
+
"""Customizable progress bar for terminal"""
|
| 24 |
+
|
| 25 |
+
def __init__(
|
| 26 |
+
self,
|
| 27 |
+
iterable: Optional[Iterable] = None,
|
| 28 |
+
total: Optional[int] = None,
|
| 29 |
+
description: str = "Progress",
|
| 30 |
+
config: Optional[ProgressBarConfig] = None,
|
| 31 |
+
animation_config: Optional[AnimationConfig] = None,
|
| 32 |
+
):
|
| 33 |
+
self.iterable = iterable
|
| 34 |
+
self.total = total if total is not None else len(iterable) if iterable else 100
|
| 35 |
+
self.description = description
|
| 36 |
+
self.progress_config = config or ProgressBarConfig()
|
| 37 |
+
self.animation_config = animation_config or DEFAULT_CONFIG
|
| 38 |
+
|
| 39 |
+
self.current = 0
|
| 40 |
+
self.start_time = time.time()
|
| 41 |
+
|
| 42 |
+
def __iter__(self):
|
| 43 |
+
"""Make ProgressBar iterable"""
|
| 44 |
+
for item in self.iterable or range(self.total):
|
| 45 |
+
yield item
|
| 46 |
+
self.update(self.current + 1)
|
| 47 |
+
|
| 48 |
+
def update(self, current: int):
|
| 49 |
+
"""Update progress bar to new value"""
|
| 50 |
+
self.current = min(current, self.total)
|
| 51 |
+
self._render()
|
| 52 |
+
|
| 53 |
+
def _render(self):
|
| 54 |
+
"""Render the progress bar"""
|
| 55 |
+
percentage = self.current / self.total if self.total > 0 else 0
|
| 56 |
+
filled_len = int(self.progress_config.width * percentage)
|
| 57 |
+
empty_len = self.progress_config.width - filled_len
|
| 58 |
+
|
| 59 |
+
bar = (
|
| 60 |
+
self.progress_config.fill_char * filled_len
|
| 61 |
+
+ self.progress_config.empty_char * empty_len
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
if self.progress_config.show_percentage:
|
| 65 |
+
pct_str = f" {percentage * 100:.1f}%"
|
| 66 |
+
else:
|
| 67 |
+
pct_str = ""
|
| 68 |
+
|
| 69 |
+
if self.progress_config.show_count:
|
| 70 |
+
count_str = f" [{self.current}/{self.total}]"
|
| 71 |
+
else:
|
| 72 |
+
count_str = ""
|
| 73 |
+
|
| 74 |
+
elapsed = time.time() - self.start_time
|
| 75 |
+
if self.current > 0:
|
| 76 |
+
rate = self.current / elapsed
|
| 77 |
+
eta = (self.total - self.current) / rate if rate > 0 else 0
|
| 78 |
+
rate_str = f" ETA: {eta:.1f}s"
|
| 79 |
+
else:
|
| 80 |
+
rate_str = ""
|
| 81 |
+
|
| 82 |
+
line = f"\r{self.description}: |{bar}|{pct_str}{count_str}{rate_str}"
|
| 83 |
+
sys.stdout.write(line)
|
| 84 |
+
sys.stdout.flush()
|
| 85 |
+
|
| 86 |
+
if self.current >= self.total:
|
| 87 |
+
sys.stdout.write("\n")
|
| 88 |
+
|
| 89 |
+
def set_description(self, description: str):
|
| 90 |
+
"""Update the description"""
|
| 91 |
+
self.description = description
|
| 92 |
+
|
| 93 |
+
@property
|
| 94 |
+
def percent(self) -> float:
|
| 95 |
+
"""Get current percentage"""
|
| 96 |
+
return self.current / self.total if self.total > 0 else 0
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
class DownloadProgressBar(ProgressBar):
|
| 100 |
+
"""Progress bar designed for file downloads"""
|
| 101 |
+
|
| 102 |
+
def __init__(self, total_bytes: int, filename: str = "file"):
|
| 103 |
+
super().__init__(
|
| 104 |
+
total=total_bytes,
|
| 105 |
+
description=f"Downloading {filename}",
|
| 106 |
+
)
|
| 107 |
+
self.total_bytes = total_bytes
|
| 108 |
+
|
| 109 |
+
def update_bytes(self, current_bytes: int):
|
| 110 |
+
"""Update with byte count"""
|
| 111 |
+
self.update(current_bytes)
|
| 112 |
+
|
| 113 |
+
def _render(self):
|
| 114 |
+
"""Custom render for byte-based progress"""
|
| 115 |
+
percentage = self.current / self.total if self.total > 0 else 0
|
| 116 |
+
filled_len = int(self.progress_config.width * percentage)
|
| 117 |
+
bar = self.progress_config.fill_char * filled_len
|
| 118 |
+
|
| 119 |
+
current_mb = self.current / (1024 * 1024)
|
| 120 |
+
total_mb = self.total / (1024 * 1024)
|
| 121 |
+
|
| 122 |
+
line = f"\r{self.description}: {current_mb:.1f}/{total_mb:.1f} MB |{bar}| {percentage * 100:.1f}%"
|
| 123 |
+
sys.stdout.write(line)
|
| 124 |
+
sys.stdout.flush()
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
class InfiniteProgressBar:
|
| 128 |
+
"""Infinite looping progress bar"""
|
| 129 |
+
|
| 130 |
+
CHARS = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
|
| 131 |
+
PROGRESS = " █▓▒░"
|
| 132 |
+
|
| 133 |
+
def __init__(self, description: str = "Working"):
|
| 134 |
+
self.description = description
|
| 135 |
+
self.frame = 0
|
| 136 |
+
|
| 137 |
+
def spin(self):
|
| 138 |
+
"""Generate next frame"""
|
| 139 |
+
char = self.CHARS[self.frame % len(self.CHARS)]
|
| 140 |
+
self.frame += 1
|
| 141 |
+
return f"\r{char} {self.description}..."
|
| 142 |
+
|
| 143 |
+
def reset(self):
|
| 144 |
+
"""Reset frame counter"""
|
| 145 |
+
self.frame = 0
|
src/animations/spinner.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Loading Spinner - Show loading state"""
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
import time
|
| 5 |
+
import threading
|
| 6 |
+
from typing import Optional
|
| 7 |
+
from contextlib import contextmanager
|
| 8 |
+
|
| 9 |
+
from .config import DEFAULT_CONFIG, AnimationConfig
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class Spinner:
|
| 13 |
+
"""Animated loading spinner for terminal"""
|
| 14 |
+
|
| 15 |
+
FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
|
| 16 |
+
|
| 17 |
+
def __init__(self, message: str = "Loading", config: Optional[AnimationConfig] = None):
|
| 18 |
+
self.message = message
|
| 19 |
+
self.config = config or DEFAULT_CONFIG
|
| 20 |
+
self.running = False
|
| 21 |
+
self.thread: Optional[threading.Thread] = None
|
| 22 |
+
self.frame_index = 0
|
| 23 |
+
|
| 24 |
+
def _spin(self):
|
| 25 |
+
"""Internal spin loop"""
|
| 26 |
+
while self.running:
|
| 27 |
+
frame = self.SPINNER_FRAMES[self.frame_index % len(self.SPINNER_FRAMES)]
|
| 28 |
+
sys.stdout.write(f"\r{self.config.speed} {frame} {self.message}...")
|
| 29 |
+
sys.stdout.flush()
|
| 30 |
+
time.sleep(self.config.speed)
|
| 31 |
+
self.frame_index += 1
|
| 32 |
+
|
| 33 |
+
sys.stdout.write("\r" + " " * (len(self.message) + 10))
|
| 34 |
+
sys.stdout.write("\r")
|
| 35 |
+
sys.stdout.flush()
|
| 36 |
+
|
| 37 |
+
def start(self):
|
| 38 |
+
"""Start the spinner animation"""
|
| 39 |
+
self.running = True
|
| 40 |
+
self.thread = threading.Thread(target=self._spin, daemon=True)
|
| 41 |
+
self.thread.start()
|
| 42 |
+
|
| 43 |
+
def stop(self):
|
| 44 |
+
"""Stop the spinner animation"""
|
| 45 |
+
self.running = False
|
| 46 |
+
if self.thread:
|
| 47 |
+
self.thread.join(timeout=0.5)
|
| 48 |
+
|
| 49 |
+
@contextmanager
|
| 50 |
+
def __call__(self):
|
| 51 |
+
"""Context manager for spinner"""
|
| 52 |
+
try:
|
| 53 |
+
self.start()
|
| 54 |
+
yield self
|
| 55 |
+
finally:
|
| 56 |
+
self.stop()
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class SimpleSpinner:
|
| 60 |
+
"""Simple spinner without threading"""
|
| 61 |
+
|
| 62 |
+
def __init__(self, message: str = "Loading"):
|
| 63 |
+
self.message = message
|
| 64 |
+
self.frame_index = 0
|
| 65 |
+
|
| 66 |
+
def spin(self) -> str:
|
| 67 |
+
"""Get next spin frame"""
|
| 68 |
+
frame = Spinner.FRAMES[self.frame_index % len(Spinner.FRAMES)]
|
| 69 |
+
self.frame_index += 1
|
| 70 |
+
return f"\r{frame} {self.message}..."
|
| 71 |
+
|
| 72 |
+
def reset(self):
|
| 73 |
+
"""Reset spinner state"""
|
| 74 |
+
self.frame_index = 0
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def spinning(message: str = "Loading", duration: float = 2.0):
|
| 78 |
+
"""Simple spinning animation for a duration"""
|
| 79 |
+
spinner = SimpleSpinner(message)
|
| 80 |
+
end_time = time.time() + duration
|
| 81 |
+
|
| 82 |
+
while time.time() < end_time:
|
| 83 |
+
sys.stdout.write(spinner.spin())
|
| 84 |
+
sys.stdout.flush()
|
| 85 |
+
time.sleep(0.1)
|
| 86 |
+
|
| 87 |
+
sys.stdout.write("\r" + " " * (len(message) + 10))
|
| 88 |
+
sys.stdout.write("\r")
|
| 89 |
+
sys.stdout.flush()
|
src/animations/typing_effect.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Typing Effect - Typewriter animation"""
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
import time
|
| 5 |
+
from typing import Optional, Callable
|
| 6 |
+
from contextlib import contextmanager
|
| 7 |
+
|
| 8 |
+
from .config import DEFAULT_CONFIG, AnimationConfig
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class TypingEffect:
|
| 12 |
+
"""Typewriter-style text animation"""
|
| 13 |
+
|
| 14 |
+
def __init__(
|
| 15 |
+
self,
|
| 16 |
+
text: str = "",
|
| 17 |
+
delay: Optional[float] = None,
|
| 18 |
+
config: Optional[AnimationConfig] = None,
|
| 19 |
+
):
|
| 20 |
+
self.text = text
|
| 21 |
+
self.config = config or DEFAULT_CONFIG
|
| 22 |
+
self.delay = delay if delay is not None else self.config.speed
|
| 23 |
+
self.cursor = "█"
|
| 24 |
+
self.blink_delay = 0.3
|
| 25 |
+
|
| 26 |
+
def animate(self) -> str:
|
| 27 |
+
"""Animate typing the text and return result"""
|
| 28 |
+
result = ""
|
| 29 |
+
cursor_on = True
|
| 30 |
+
|
| 31 |
+
for i, char in enumerate(self.text):
|
| 32 |
+
result += char
|
| 33 |
+
cursor_str = self.cursor if cursor_on else " "
|
| 34 |
+
sys.stdout.write(f"\r{result}{cursor_str}")
|
| 35 |
+
sys.stdout.flush()
|
| 36 |
+
|
| 37 |
+
time.sleep(self.delay)
|
| 38 |
+
cursor_on = not cursor_on
|
| 39 |
+
|
| 40 |
+
sys.stdout.write(f"\r{result} \n")
|
| 41 |
+
sys.stdout.flush()
|
| 42 |
+
|
| 43 |
+
return result
|
| 44 |
+
|
| 45 |
+
def animate_with_callback(
|
| 46 |
+
self, callback: Callable[[str], None], interval: float = 1.0
|
| 47 |
+
):
|
| 48 |
+
"""Animate text and call callback at intervals"""
|
| 49 |
+
result = ""
|
| 50 |
+
callback_count = 0
|
| 51 |
+
|
| 52 |
+
for char in self.text:
|
| 53 |
+
result += char
|
| 54 |
+
callback_count += 1
|
| 55 |
+
|
| 56 |
+
sys.stdout.write(f"\r{result}")
|
| 57 |
+
sys.stdout.flush()
|
| 58 |
+
|
| 59 |
+
if callback_count % int(interval / self.delay) == 0:
|
| 60 |
+
callback(result)
|
| 61 |
+
|
| 62 |
+
time.sleep(self.delay)
|
| 63 |
+
|
| 64 |
+
sys.stdout.write(f"\r{result} \n")
|
| 65 |
+
sys.stdout.flush()
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
class SlowTypingEffect(TypingEffect):
|
| 69 |
+
"""Slow typewriter effect for dramatic effect"""
|
| 70 |
+
|
| 71 |
+
def __init__(self, text: str = ""):
|
| 72 |
+
super().__init__(text=text, delay=0.1)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class FastTypingEffect(TypingEffect):
|
| 76 |
+
"""Fast typewriter effect"""
|
| 77 |
+
|
| 78 |
+
def __init__(self, text: str = ""):
|
| 79 |
+
super().__init__(text=text, delay=0.01)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class CodeTypingEffect(TypingEffect):
|
| 83 |
+
"""Typing effect optimized for code"""
|
| 84 |
+
|
| 85 |
+
def __init__(self, text: str = ""):
|
| 86 |
+
super().__init__(text=text, delay=0.005)
|
| 87 |
+
|
| 88 |
+
def __call__(self):
|
| 89 |
+
return self.animate()
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
@contextmanager
|
| 93 |
+
def typing_context(text: str, delay: float = 0.05):
|
| 94 |
+
"""Context manager for typing effect"""
|
| 95 |
+
effect = TypingEffect(text=text, delay=delay)
|
| 96 |
+
print(f"\r{text[:10]}...", end="", flush=True)
|
| 97 |
+
|
| 98 |
+
try:
|
| 99 |
+
yield effect
|
| 100 |
+
finally:
|
| 101 |
+
for _ in range(len(text) + 5):
|
| 102 |
+
sys.stdout.write("\b \b")
|
| 103 |
+
sys.stdout.flush()
|
| 104 |
+
sys.stdout.flush()
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
class LiveTypingDisplay:
|
| 108 |
+
"""Display that shows typing in real-time"""
|
| 109 |
+
|
| 110 |
+
def __init__(self):
|
| 111 |
+
self.content = ""
|
| 112 |
+
|
| 113 |
+
def append(self, char: str):
|
| 114 |
+
"""Append character and update display"""
|
| 115 |
+
self.content += char
|
| 116 |
+
sys.stdout.write(char)
|
| 117 |
+
sys.stdout.flush()
|
| 118 |
+
|
| 119 |
+
def append_many(self, text: str):
|
| 120 |
+
"""Append multiple characters"""
|
| 121 |
+
for char in text:
|
| 122 |
+
self.append(char)
|
| 123 |
+
|
| 124 |
+
def clear(self):
|
| 125 |
+
"""Clear the display"""
|
| 126 |
+
self.content = ""
|
| 127 |
+
sys.stdout.write("\033[2K\r")
|
| 128 |
+
sys.stdout.flush()
|
| 129 |
+
|
| 130 |
+
def backspace(self, count: int = 1):
|
| 131 |
+
"""Backspace characters"""
|
| 132 |
+
self.content = self.content[:-count]
|
| 133 |
+
backspace_seq = "\b \b" * count
|
| 134 |
+
sys.stdout.write(backspace_seq)
|
| 135 |
+
sys.stdout.flush()
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def type_text(text: str, delay: float = 0.05):
|
| 139 |
+
"""Quick function to type text to terminal"""
|
| 140 |
+
effect = TypingEffect(text=text, delay=delay)
|
| 141 |
+
return effect.animate()
|
src/cli/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""CLI module initialization"""
|
| 2 |
+
|
| 3 |
+
from .main import main
|
| 4 |
+
from .commands import run_command, train_command, eval_command
|
| 5 |
+
from .interactive import InteractiveMode
|
| 6 |
+
|
| 7 |
+
__all__ = ["main", "run_command", "train_command", "eval_command", "InteractiveMode"]
|
src/cli/commands.py
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""CLI Commands - run, train, eval"""
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import time
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from typing import Optional
|
| 7 |
+
|
| 8 |
+
import click
|
| 9 |
+
from rich.console import Console
|
| 10 |
+
from rich.progress import Progress, SpinnerColumn, TextColumn
|
| 11 |
+
|
| 12 |
+
from src.core import CoderAgent, ResponseValidator
|
| 13 |
+
from src.animations import Spinner, ProgressBar
|
| 14 |
+
from src.knowledge import LocalKB
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
console = Console()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@click.command()
|
| 21 |
+
@click.argument("instruction")
|
| 22 |
+
@click.option("--model", default="gpt-4", help="AI model")
|
| 23 |
+
@click.option("--output", "-o", help="Output file for response")
|
| 24 |
+
@click.option("--validate/--no-validate", default=True, help="Validate response")
|
| 25 |
+
def run_command(instruction: str, model: str, output: Optional[str], validate: bool):
|
| 26 |
+
"""Run a single instruction and display response"""
|
| 27 |
+
agent = CoderAgent(model=model)
|
| 28 |
+
validator = ResponseValidator()
|
| 29 |
+
|
| 30 |
+
console.print(f"[bold cyan]Question:[/bold cyan] {instruction}\n")
|
| 31 |
+
|
| 32 |
+
with Spinner("Generating response..."):
|
| 33 |
+
response = agent.generate_response(instruction)
|
| 34 |
+
|
| 35 |
+
console.print("[bold green]Response:[/bold green]")
|
| 36 |
+
console.print(response["response"])
|
| 37 |
+
|
| 38 |
+
if validate:
|
| 39 |
+
console.print("\n[bold yellow]Validating...[/bold yellow]")
|
| 40 |
+
result = validator.validate(response["response"], instruction)
|
| 41 |
+
console.print(f"Quality: [bold]{result.quality.value}[/bold]")
|
| 42 |
+
console.print(f"Score: [bold]{result.score:.2f}[/bold]")
|
| 43 |
+
|
| 44 |
+
if result.issues:
|
| 45 |
+
console.print("[bold red]Issues:[/bold red]")
|
| 46 |
+
for issue in result.issues:
|
| 47 |
+
console.print(f" - {issue}")
|
| 48 |
+
|
| 49 |
+
if output:
|
| 50 |
+
Path(output).write_text(response["response"], encoding="utf-8")
|
| 51 |
+
console.print(f"\n[green]Response saved to {output}[/green]")
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
@click.command()
|
| 55 |
+
@click.argument("data_dir")
|
| 56 |
+
@click.option("--epochs", default=10, help="Training epochs")
|
| 57 |
+
@click.option("--batch-size", default=4, help="Batch size")
|
| 58 |
+
def train_command(data_dir: str, epochs: int, batch_size: int):
|
| 59 |
+
"""Train agent on trajectory data"""
|
| 60 |
+
console.print("[bold cyan]Training Agent...[/bold cyan]\n")
|
| 61 |
+
|
| 62 |
+
data_path = Path(data_dir)
|
| 63 |
+
if not data_path.exists():
|
| 64 |
+
console.print(f"[bold red]Error:[/bold red] {data_dir} not found")
|
| 65 |
+
return
|
| 66 |
+
|
| 67 |
+
trajectory_files = list(data_path.glob("*.jsonl"))
|
| 68 |
+
if not trajectory_files:
|
| 69 |
+
console.print(f"[bold red]Error:[/bold red] No trajectory files in {data_dir}")
|
| 70 |
+
return
|
| 71 |
+
|
| 72 |
+
console.print(f"Found {len(trajectory_files)} trajectory files\n")
|
| 73 |
+
|
| 74 |
+
for epoch in range(epochs):
|
| 75 |
+
console.print(f"[bold cyan]Epoch {epoch + 1}/{epochs}[/bold cyan]")
|
| 76 |
+
|
| 77 |
+
with Progress(
|
| 78 |
+
SpinnerColumn(),
|
| 79 |
+
TextColumn("[progress.description]{task.description}"),
|
| 80 |
+
console=console,
|
| 81 |
+
) as progress:
|
| 82 |
+
task = progress.add_task("Processing...", total=len(trajectory_files))
|
| 83 |
+
|
| 84 |
+
for traj_file in trajectory_files:
|
| 85 |
+
progress.update(task, advance=1)
|
| 86 |
+
|
| 87 |
+
with open(traj_file, "r", encoding="utf-8") as f:
|
| 88 |
+
for line in f:
|
| 89 |
+
data = json.loads(line)
|
| 90 |
+
# Process trajectory data
|
| 91 |
+
pass
|
| 92 |
+
|
| 93 |
+
time.sleep(0.5)
|
| 94 |
+
|
| 95 |
+
console.print("\n[bold green]Training completed![/bold green]")
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
@click.command()
|
| 99 |
+
@click.argument("data_dir")
|
| 100 |
+
@click.option("--verbose", is_flag=True, help="Show detailed results")
|
| 101 |
+
def eval_command(data_dir: str, verbose: bool):
|
| 102 |
+
"""Evaluate agent on test data"""
|
| 103 |
+
console.print("[bold cyan]Evaluating Agent...[/bold cyan]\n")
|
| 104 |
+
|
| 105 |
+
data_path = Path(data_dir)
|
| 106 |
+
if not data_path.exists():
|
| 107 |
+
console.print(f"[bold red]Error:[/bold red] {data_dir} not found")
|
| 108 |
+
return
|
| 109 |
+
|
| 110 |
+
kb = LocalKB()
|
| 111 |
+
|
| 112 |
+
test_queries = [
|
| 113 |
+
"Python decorator hta ya py",
|
| 114 |
+
"JavaScript async/await hta ya",
|
| 115 |
+
"SQL JOIN operations hta ya",
|
| 116 |
+
"React useState lo useEffect hta ya",
|
| 117 |
+
]
|
| 118 |
+
|
| 119 |
+
agent = CoderAgent()
|
| 120 |
+
validator = ResponseValidator()
|
| 121 |
+
|
| 122 |
+
results = []
|
| 123 |
+
with Progress(
|
| 124 |
+
SpinnerColumn(), TextColumn("[progress.description]{task.description}"), console=console
|
| 125 |
+
) as progress:
|
| 126 |
+
task = progress.add_task("Testing...", total=len(test_queries))
|
| 127 |
+
|
| 128 |
+
for query in test_queries:
|
| 129 |
+
progress.update(task, description=f"Testing: {query[:30]}...")
|
| 130 |
+
|
| 131 |
+
response = agent.generate_response(query)
|
| 132 |
+
validation = validator.validate(response["response"], query)
|
| 133 |
+
|
| 134 |
+
results.append(
|
| 135 |
+
{
|
| 136 |
+
"query": query,
|
| 137 |
+
"quality": validation.quality.value,
|
| 138 |
+
"score": validation.score,
|
| 139 |
+
"issues": len(validation.issues),
|
| 140 |
+
}
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
progress.update(task, advance=1)
|
| 144 |
+
|
| 145 |
+
console.print("\n[bold]Evaluation Results:[/bold]\n")
|
| 146 |
+
|
| 147 |
+
total_score = sum(r["score"] for r in results)
|
| 148 |
+
avg_score = total_score / len(results) if results else 0
|
| 149 |
+
|
| 150 |
+
console.print(f"Average Score: [bold]{avg_score:.2f}[/bold]\n")
|
| 151 |
+
|
| 152 |
+
for r in results:
|
| 153 |
+
color = "green" if r["score"] >= 0.6 else "yellow" if r["score"] >= 0.4 else "red"
|
| 154 |
+
console.print(f"[{color}]{r['query']}:[/{color}] {r['score']:.2f} ({r['quality']})")
|
| 155 |
+
|
| 156 |
+
if verbose and r["issues"] > 0:
|
| 157 |
+
console.print(f" Issues: {r['issues']}")
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
@click.command()
|
| 161 |
+
@click.argument("query")
|
| 162 |
+
def search_command(query: str):
|
| 163 |
+
"""Search knowledge base"""
|
| 164 |
+
kb = LocalKB()
|
| 165 |
+
results = kb.search(query)
|
| 166 |
+
|
| 167 |
+
if not results:
|
| 168 |
+
console.print("[yellow]No results found[/yellow]")
|
| 169 |
+
return
|
| 170 |
+
|
| 171 |
+
for result in results:
|
| 172 |
+
console.print(f"[bold cyan]{result['source']}[/bold cyan]")
|
| 173 |
+
console.print(result["content"][:200])
|
| 174 |
+
console.print()
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
@click.command()
|
| 178 |
+
@click.argument("question")
|
| 179 |
+
def ask_command(question: str):
|
| 180 |
+
"""Ask a question (alias for run)"""
|
| 181 |
+
run_command.callback(question, model="gpt-4", output=None, validate=True)
|
src/cli/interactive.py
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Interactive Mode - Chat with the Agent"""
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
from rich.console import Console
|
| 5 |
+
from rich.prompt import Prompt, Confirm
|
| 6 |
+
from rich.panel import Panel
|
| 7 |
+
from rich.syntax import Syntax
|
| 8 |
+
|
| 9 |
+
from src.core import CoderAgent
|
| 10 |
+
from src.animations import TypingEffect
|
| 11 |
+
from src.ui.thanking import ThankYou, Appreciation
|
| 12 |
+
from src.ui.layout import ChatboxLayout
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class InteractiveMode:
|
| 16 |
+
"""Interactive chat mode with the coder agent"""
|
| 17 |
+
|
| 18 |
+
def __init__(self):
|
| 19 |
+
self.console = Console()
|
| 20 |
+
self.agent = CoderAgent()
|
| 21 |
+
self.layout = ChatboxLayout()
|
| 22 |
+
self.running = False
|
| 23 |
+
self.history: list[dict] = []
|
| 24 |
+
|
| 25 |
+
def start(self):
|
| 26 |
+
"""Start the interactive session"""
|
| 27 |
+
self.running = True
|
| 28 |
+
|
| 29 |
+
self.console.print(Panel.fit(
|
| 30 |
+
"[bold cyan]🧑💻 Burme-Coder-Max Interactive Mode[/bold cyan]\n"
|
| 31 |
+
"Type 'exit' to quit, 'clear' to clear history, 'help' for commands",
|
| 32 |
+
border_style="cyan",
|
| 33 |
+
))
|
| 34 |
+
|
| 35 |
+
while self.running:
|
| 36 |
+
try:
|
| 37 |
+
user_input = Prompt.ask("\n[bold green]You[/bold green]")
|
| 38 |
+
|
| 39 |
+
if not user_input.strip():
|
| 40 |
+
continue
|
| 41 |
+
|
| 42 |
+
self._handle_command(user_input)
|
| 43 |
+
|
| 44 |
+
except KeyboardInterrupt:
|
| 45 |
+
self.console.print("\n[yellow]Interrupted. Type 'exit' to quit.[/yellow]")
|
| 46 |
+
except EOFError:
|
| 47 |
+
self._exit()
|
| 48 |
+
|
| 49 |
+
def _handle_command(self, user_input: str):
|
| 50 |
+
"""Handle user input or commands"""
|
| 51 |
+
cmd = user_input.strip().lower()
|
| 52 |
+
|
| 53 |
+
if cmd == "exit":
|
| 54 |
+
self._exit()
|
| 55 |
+
elif cmd == "clear":
|
| 56 |
+
self._clear_history()
|
| 57 |
+
elif cmd == "help":
|
| 58 |
+
self._show_help()
|
| 59 |
+
elif cmd == "history":
|
| 60 |
+
self._show_history()
|
| 61 |
+
elif cmd == "thank":
|
| 62 |
+
ThankYou.show()
|
| 63 |
+
elif cmd.startswith("/"):
|
| 64 |
+
self._handle_slash_command(user_input)
|
| 65 |
+
else:
|
| 66 |
+
self._generate_response(user_input)
|
| 67 |
+
|
| 68 |
+
def _generate_response(self, instruction: str):
|
| 69 |
+
"""Generate and display response"""
|
| 70 |
+
self.console.print()
|
| 71 |
+
|
| 72 |
+
with TypingEffect("[bold blue]Agent[/bold blue] thinking..."):
|
| 73 |
+
response = self.agent.generate_response(instruction)
|
| 74 |
+
|
| 75 |
+
self.console.print()
|
| 76 |
+
|
| 77 |
+
if response["response"].startswith("#") or "```" in response["response"]:
|
| 78 |
+
self.console.print(Panel(
|
| 79 |
+
response["response"],
|
| 80 |
+
title="Response",
|
| 81 |
+
border_style="blue",
|
| 82 |
+
))
|
| 83 |
+
else:
|
| 84 |
+
self.console.print(response["response"])
|
| 85 |
+
|
| 86 |
+
self.history.append({
|
| 87 |
+
"role": "user",
|
| 88 |
+
"content": instruction,
|
| 89 |
+
"response": response["response"]
|
| 90 |
+
})
|
| 91 |
+
|
| 92 |
+
def _handle_slash_command(self, user_input: str):
|
| 93 |
+
"""Handle slash commands"""
|
| 94 |
+
parts = user_input.split(maxsplit=1)
|
| 95 |
+
cmd = parts[0]
|
| 96 |
+
args = parts[1] if len(parts) > 1 else ""
|
| 97 |
+
|
| 98 |
+
if cmd == "/search":
|
| 99 |
+
from src.knowledge import LocalKB
|
| 100 |
+
if args:
|
| 101 |
+
kb = LocalKB()
|
| 102 |
+
results = kb.search(args)
|
| 103 |
+
self.console.print(f"\n[cyan]Search results for '{args}':[/cyan]")
|
| 104 |
+
for r in results[:5]:
|
| 105 |
+
self.console.print(f" - {r['source']}")
|
| 106 |
+
else:
|
| 107 |
+
self.console.print("[yellow]Usage: /search <query>[/yellow]")
|
| 108 |
+
|
| 109 |
+
elif cmd == "/model":
|
| 110 |
+
if args:
|
| 111 |
+
self.console.print(f"[green]Switching to model: {args}[/green]")
|
| 112 |
+
self.agent = CoderAgent(model=args)
|
| 113 |
+
else:
|
| 114 |
+
self.console.print(f"[cyan]Current model: {self.agent.model}[/cyan]")
|
| 115 |
+
|
| 116 |
+
elif cmd == "/reset":
|
| 117 |
+
self.agent.reset()
|
| 118 |
+
self.console.print("[green]Agent reset successfully[/green]")
|
| 119 |
+
|
| 120 |
+
else:
|
| 121 |
+
self.console.print(f"[yellow]Unknown command: {cmd}[/yellow]")
|
| 122 |
+
|
| 123 |
+
def _show_help(self):
|
| 124 |
+
"""Show help message"""
|
| 125 |
+
help_text = """
|
| 126 |
+
[bold cyan]Available Commands:[/bold cyan]
|
| 127 |
+
|
| 128 |
+
[green]exit[/green] - Exit interactive mode
|
| 129 |
+
[green]clear[/green] - Clear conversation history
|
| 130 |
+
[green]history[/green] - Show conversation history
|
| 131 |
+
[green]thank[/green] - Show thank you animation
|
| 132 |
+
[green]help[/green] - Show this help message
|
| 133 |
+
|
| 134 |
+
[yellow]/search <query>[/yellow] - Search knowledge base
|
| 135 |
+
[yellow]/model <name>[/yellow] - Switch AI model
|
| 136 |
+
[yellow]/reset[/yellow] - Reset agent state
|
| 137 |
+
"""
|
| 138 |
+
self.console.print(help_text)
|
| 139 |
+
|
| 140 |
+
def _show_history(self):
|
| 141 |
+
"""Show conversation history"""
|
| 142 |
+
if not self.history:
|
| 143 |
+
self.console.print("[yellow]No conversation history[/yellow]")
|
| 144 |
+
return
|
| 145 |
+
|
| 146 |
+
self.console.print(f"\n[bold cyan]Conversation History ({len(self.history)} exchanges):[/bold cyan]\n")
|
| 147 |
+
|
| 148 |
+
for i, item in enumerate(self.history[-10:], 1):
|
| 149 |
+
self.console.print(f"[dim]{i}.[/dim] [green]Q:[/green] {item['content'][:50]}...")
|
| 150 |
+
self.console.print(f" [blue]A:[/blue] {item['response'][:50]}...\n")
|
| 151 |
+
|
| 152 |
+
def _clear_history(self):
|
| 153 |
+
"""Clear conversation history"""
|
| 154 |
+
self.history = []
|
| 155 |
+
self.agent.reset()
|
| 156 |
+
self.console.print("[green]History cleared[/green]")
|
| 157 |
+
|
| 158 |
+
def _exit(self):
|
| 159 |
+
"""Exit interactive mode"""
|
| 160 |
+
if Confirm.ask("Do you want to show appreciation?"):
|
| 161 |
+
Appreciation.show("interactive session")
|
| 162 |
+
|
| 163 |
+
self.running = False
|
| 164 |
+
self.console.print("[cyan]Goodbye! 👋[/cyan]")
|
src/cli/main.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Main CLI Entry Point"""
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
import click
|
| 5 |
+
from rich.console import Console
|
| 6 |
+
|
| 7 |
+
from .commands import run_command, train_command, eval_command
|
| 8 |
+
from .interactive import InteractiveMode
|
| 9 |
+
|
| 10 |
+
console = Console()
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@click.group()
|
| 14 |
+
@click.version_option(version="1.0.0")
|
| 15 |
+
def main():
|
| 16 |
+
"""🧑💻 Burme-Coder-Max - Myanmar AI Coding Agent"""
|
| 17 |
+
pass
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@main.command()
|
| 21 |
+
@click.argument("instruction")
|
| 22 |
+
@click.option("--model", default="gpt-4", help="AI model to use")
|
| 23 |
+
@click.option("--verbose", is_flag=True, help="Verbose output")
|
| 24 |
+
def ask(instruction: str, model: str, verbose: bool):
|
| 25 |
+
"""Ask a coding question in Burmese or English"""
|
| 26 |
+
from src.core import CoderAgent
|
| 27 |
+
from src.animations import Spinner
|
| 28 |
+
from src.ui.thanking import ThankYou
|
| 29 |
+
|
| 30 |
+
agent = CoderAgent(model=model)
|
| 31 |
+
|
| 32 |
+
with Spinner("Thinking..."):
|
| 33 |
+
response = agent.generate_response(instruction)
|
| 34 |
+
|
| 35 |
+
console.print(response["response"])
|
| 36 |
+
|
| 37 |
+
if verbose:
|
| 38 |
+
console.print(f"\n[dim]Session: {response['session_id']}[/dim]")
|
| 39 |
+
console.print(f"[dim]Model: {response['model']}[/dim]")
|
| 40 |
+
|
| 41 |
+
ThankYou.show()
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
@main.command()
|
| 45 |
+
@click.option("--host", default="0.0.0.0", help="Host to bind")
|
| 46 |
+
@click.option("--port", default=5000, help="Port to bind")
|
| 47 |
+
def serve(host: str, port: int):
|
| 48 |
+
"""Start API server"""
|
| 49 |
+
console.print(f"[green]Starting server on {host}:{port}...[/green]")
|
| 50 |
+
console.print("[yellow]API server not yet implemented[/yellow]")
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
@main.command()
|
| 54 |
+
def interactive():
|
| 55 |
+
"""Start interactive mode"""
|
| 56 |
+
mode = InteractiveMode()
|
| 57 |
+
mode.start()
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
@main.command()
|
| 61 |
+
@click.option("--data", default="./data/trajectories", help="Training data directory")
|
| 62 |
+
@click.option("--epochs", default=10, help="Number of epochs")
|
| 63 |
+
def train(data: str, epochs: int):
|
| 64 |
+
"""Train the agent on trajectories"""
|
| 65 |
+
train_command(data, epochs)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
@main.command()
|
| 69 |
+
@click.option("--data", default="./data/trajectories", help="Evaluation data")
|
| 70 |
+
def eval(data: str):
|
| 71 |
+
"""Evaluate agent performance"""
|
| 72 |
+
eval_command(data)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
# Register subcommands
|
| 76 |
+
main.add_command(run_command)
|
| 77 |
+
main.add_command(train_command)
|
| 78 |
+
main.add_command(eval_command)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__":
|
| 82 |
+
main()
|
src/core/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Core module initialization"""
|
| 2 |
+
|
| 3 |
+
from .agent import CoderAgent
|
| 4 |
+
from .executor import CodeExecutor
|
| 5 |
+
from .validator import ResponseValidator
|
| 6 |
+
|
| 7 |
+
__all__ = ["CoderAgent", "CodeExecutor", "ResponseValidator"]
|
src/core/agent.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Coder Agent - Main AI Brain for Myanmar Coding Assistant"""
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import time
|
| 5 |
+
from typing import Dict, List, Optional, Any
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class CoderAgent:
|
| 10 |
+
"""Expert Myanmar AI coding agent with advanced knowledge"""
|
| 11 |
+
|
| 12 |
+
SYSTEM_PROMPTS = [
|
| 13 |
+
"You are an expert programmer with advanced knowledge in: Python, JavaScript, TypeScript, Java, C++, Go, Rust, etc.",
|
| 14 |
+
"You are a senior security reviewer. Analyze code for vulnerabilities and provide secure version with Myanmar explanation.",
|
| 15 |
+
"You are a testing expert. Generate comprehensive unit tests for the given function using pytest.",
|
| 16 |
+
"You are a GUI and game development expert. Provide complete, runnable code with Myanmar explanations.",
|
| 17 |
+
"You are an expert Myanmar AI coding agent. Answer in Myanmar language and provide code examples when needed.",
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
def __init__(
|
| 21 |
+
self,
|
| 22 |
+
model: str = "gpt-4",
|
| 23 |
+
temperature: float = 0.7,
|
| 24 |
+
max_tokens: int = 2048,
|
| 25 |
+
knowledge_dir: Optional[str] = None,
|
| 26 |
+
):
|
| 27 |
+
self.model = model
|
| 28 |
+
self.temperature = temperature
|
| 29 |
+
self.max_tokens = max_tokens
|
| 30 |
+
self.knowledge_dir = Path(knowledge_dir) if knowledge_dir else None
|
| 31 |
+
self.conversation_history: List[Dict[str, str]] = []
|
| 32 |
+
self.session_id = self._generate_session_id()
|
| 33 |
+
|
| 34 |
+
def _generate_session_id(self) -> str:
|
| 35 |
+
"""Generate unique session ID"""
|
| 36 |
+
return f"session_{int(time.time())}_{id(self)}"
|
| 37 |
+
|
| 38 |
+
def set_system_prompt(self, prompt: str) -> None:
|
| 39 |
+
"""Set custom system prompt"""
|
| 40 |
+
self.system_prompt = prompt
|
| 41 |
+
|
| 42 |
+
def generate_response(
|
| 43 |
+
self, instruction: str, context: Optional[Dict[str, Any]] = None
|
| 44 |
+
) -> Dict[str, Any]:
|
| 45 |
+
"""Generate code response for the given instruction"""
|
| 46 |
+
self.conversation_history.append({"role": "user", "content": instruction})
|
| 47 |
+
|
| 48 |
+
response = {
|
| 49 |
+
"session_id": self.session_id,
|
| 50 |
+
"instruction": instruction,
|
| 51 |
+
"response": self._generate_code_response(instruction, context),
|
| 52 |
+
"timestamp": time.time(),
|
| 53 |
+
"model": self.model,
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
self.conversation_history.append(
|
| 57 |
+
{"role": "assistant", "content": response["response"]}
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
return response
|
| 61 |
+
|
| 62 |
+
def _generate_code_response(
|
| 63 |
+
self, instruction: str, context: Optional[Dict[str, Any]]
|
| 64 |
+
) -> str:
|
| 65 |
+
"""Internal method to generate code response"""
|
| 66 |
+
if self.knowledge_dir:
|
| 67 |
+
knowledge_content = self._check_knowledge_base(instruction)
|
| 68 |
+
if knowledge_content:
|
| 69 |
+
return knowledge_content
|
| 70 |
+
|
| 71 |
+
return self._get_fallback_response(instruction)
|
| 72 |
+
|
| 73 |
+
def _check_knowledge_base(self, instruction: str) -> Optional[str]:
|
| 74 |
+
"""Check local knowledge base for relevant content"""
|
| 75 |
+
if not self.knowledge_dir:
|
| 76 |
+
return None
|
| 77 |
+
|
| 78 |
+
keywords = self._extract_keywords(instruction)
|
| 79 |
+
for keyword in keywords:
|
| 80 |
+
kb_file = self.knowledge_dir / f"{keyword}_skills.md"
|
| 81 |
+
if kb_file.exists():
|
| 82 |
+
return self._parse_markdown_file(kb_file)
|
| 83 |
+
|
| 84 |
+
return None
|
| 85 |
+
|
| 86 |
+
def _extract_keywords(self, text: str) -> List[str]:
|
| 87 |
+
"""Extract keywords from instruction"""
|
| 88 |
+
common_langs = ["python", "javascript", "typescript", "java", "go", "rust", "sql"]
|
| 89 |
+
return [w for w in common_langs if w in text.lower()]
|
| 90 |
+
|
| 91 |
+
def _parse_markdown_file(self, file_path: Path) -> str:
|
| 92 |
+
"""Parse markdown file and extract content"""
|
| 93 |
+
content = file_path.read_text(encoding="utf-8")
|
| 94 |
+
lines = content.split("\n")
|
| 95 |
+
return "\n".join(lines[:20])
|
| 96 |
+
|
| 97 |
+
def _get_fallback_response(self, instruction: str) -> str:
|
| 98 |
+
"""Get fallback response based on instruction"""
|
| 99 |
+
instruction_lower = instruction.lower()
|
| 100 |
+
|
| 101 |
+
if "python" in instruction_lower:
|
| 102 |
+
return self._get_python_response(instruction)
|
| 103 |
+
elif "javascript" in instruction_lower or "js" in instruction_lower:
|
| 104 |
+
return self._get_javascript_response(instruction)
|
| 105 |
+
elif "sql" in instruction_lower:
|
| 106 |
+
return self._get_sql_response(instruction)
|
| 107 |
+
else:
|
| 108 |
+
return self._get_general_response(instruction)
|
| 109 |
+
|
| 110 |
+
def _get_python_response(self, instruction: str) -> str:
|
| 111 |
+
"""Generate Python response"""
|
| 112 |
+
return "# Python Code\n# TODO: Implement based on instruction"
|
| 113 |
+
|
| 114 |
+
def _get_javascript_response(self, instruction: str) -> str:
|
| 115 |
+
"""Generate JavaScript response"""
|
| 116 |
+
return "// JavaScript Code\n// TODO: Implement based on instruction"
|
| 117 |
+
|
| 118 |
+
def _get_sql_response(self, instruction: str) -> str:
|
| 119 |
+
"""Generate SQL response"""
|
| 120 |
+
return "-- SQL Query\n-- TODO: Implement based on instruction"
|
| 121 |
+
|
| 122 |
+
def _get_general_response(self, instruction: str) -> str:
|
| 123 |
+
"""Generate general response"""
|
| 124 |
+
return "# Code\n# TODO: Implement based on instruction"
|
| 125 |
+
|
| 126 |
+
def get_trajectory(self) -> Dict[str, Any]:
|
| 127 |
+
"""Get conversation trajectory for training"""
|
| 128 |
+
return {
|
| 129 |
+
"session_id": self.session_id,
|
| 130 |
+
"history": self.conversation_history,
|
| 131 |
+
"timestamp": time.time(),
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
def save_trajectory(self, path: str) -> None:
|
| 135 |
+
"""Save conversation trajectory to file"""
|
| 136 |
+
trajectory = self.get_trajectory()
|
| 137 |
+
file_path = Path(path) / f"session_{int(time.time())}.jsonl"
|
| 138 |
+
file_path.parent.mkdir(parents=True, exist_ok=True)
|
| 139 |
+
|
| 140 |
+
with open(file_path, "w", encoding="utf-8") as f:
|
| 141 |
+
f.write(json.dumps(trajectory, ensure_ascii=False) + "\n")
|
| 142 |
+
|
| 143 |
+
def reset(self) -> None:
|
| 144 |
+
"""Reset agent state"""
|
| 145 |
+
self.conversation_history = []
|
| 146 |
+
self.session_id = self._generate_session_id()
|
src/core/executor.py
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Code Execution Engine"""
|
| 2 |
+
|
| 3 |
+
import subprocess
|
| 4 |
+
import sys
|
| 5 |
+
import ast
|
| 6 |
+
import re
|
| 7 |
+
from typing import Dict, Optional, Any
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@dataclass
|
| 12 |
+
class ExecutionResult:
|
| 13 |
+
"""Code execution result container"""
|
| 14 |
+
|
| 15 |
+
success: bool
|
| 16 |
+
output: str
|
| 17 |
+
error: Optional[str] = None
|
| 18 |
+
execution_time: float = 0.0
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class CodeExecutor:
|
| 22 |
+
"""Execute code in various programming languages"""
|
| 23 |
+
|
| 24 |
+
SUPPORTED_LANGUAGES = ["python", "javascript", "typescript", "sql", "bash"]
|
| 25 |
+
|
| 26 |
+
def __init__(self, timeout: int = 30, sandbox: bool = True):
|
| 27 |
+
self.timeout = timeout
|
| 28 |
+
self.sandbox = sandbox
|
| 29 |
+
self.execution_count = 0
|
| 30 |
+
|
| 31 |
+
def execute(self, code: str, language: str = "python") -> ExecutionResult:
|
| 32 |
+
"""Execute code and return result"""
|
| 33 |
+
if language not in self.SUPPORTED_LANGUAGES:
|
| 34 |
+
return ExecutionResult(
|
| 35 |
+
success=False,
|
| 36 |
+
output="",
|
| 37 |
+
error=f"Unsupported language: {language}",
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
if self._contains_malicious_code(code):
|
| 41 |
+
return ExecutionResult(
|
| 42 |
+
success=False,
|
| 43 |
+
output="",
|
| 44 |
+
error="Potentially malicious code detected",
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
self.execution_count += 1
|
| 48 |
+
|
| 49 |
+
if language == "python":
|
| 50 |
+
return self._execute_python(code)
|
| 51 |
+
elif language == "javascript":
|
| 52 |
+
return self._execute_javascript(code)
|
| 53 |
+
elif language == "sql":
|
| 54 |
+
return self._execute_sql(code)
|
| 55 |
+
elif language == "bash":
|
| 56 |
+
return self._execute_bash(code)
|
| 57 |
+
|
| 58 |
+
return ExecutionResult(success=False, output="", error="Execution failed")
|
| 59 |
+
|
| 60 |
+
def _contains_malicious_code(self, code: str) -> bool:
|
| 61 |
+
"""Check for potentially malicious patterns"""
|
| 62 |
+
dangerous_patterns = [
|
| 63 |
+
r"__import__\s*\(",
|
| 64 |
+
r"exec\s*\(",
|
| 65 |
+
r"eval\s*\(",
|
| 66 |
+
r"subprocess\s*\(.*shell\s*=\s*True",
|
| 67 |
+
r"os\.system\s*\(",
|
| 68 |
+
r"shutil\.rmtree",
|
| 69 |
+
r"open\s*\([^)]*['\"][wr]",
|
| 70 |
+
]
|
| 71 |
+
|
| 72 |
+
for pattern in dangerous_patterns:
|
| 73 |
+
if re.search(pattern, code):
|
| 74 |
+
return True
|
| 75 |
+
|
| 76 |
+
return False
|
| 77 |
+
|
| 78 |
+
def _execute_python(self, code: str) -> ExecutionResult:
|
| 79 |
+
"""Execute Python code"""
|
| 80 |
+
import time
|
| 81 |
+
|
| 82 |
+
start_time = time.time()
|
| 83 |
+
|
| 84 |
+
try:
|
| 85 |
+
tree = ast.parse(code)
|
| 86 |
+
namespace: Dict[str, Any] = {}
|
| 87 |
+
exec(compile(tree, "<string>", "exec"), namespace)
|
| 88 |
+
|
| 89 |
+
output = self._capture_output(namespace)
|
| 90 |
+
execution_time = time.time() - start_time
|
| 91 |
+
|
| 92 |
+
return ExecutionResult(
|
| 93 |
+
success=True, output=output, execution_time=execution_time
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
except SyntaxError as e:
|
| 97 |
+
return ExecutionResult(
|
| 98 |
+
success=False,
|
| 99 |
+
output="",
|
| 100 |
+
error=f"Syntax Error: {e}",
|
| 101 |
+
execution_time=time.time() - start_time,
|
| 102 |
+
)
|
| 103 |
+
except Exception as e:
|
| 104 |
+
return ExecutionResult(
|
| 105 |
+
success=False,
|
| 106 |
+
output="",
|
| 107 |
+
error=f"Runtime Error: {e}",
|
| 108 |
+
execution_time=time.time() - start_time,
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
def _capture_output(self, namespace: Dict[str, Any]) -> str:
|
| 112 |
+
"""Capture relevant output from namespace"""
|
| 113 |
+
output_lines = []
|
| 114 |
+
|
| 115 |
+
if "result" in namespace:
|
| 116 |
+
output_lines.append(str(namespace["result"]))
|
| 117 |
+
|
| 118 |
+
for key, value in namespace.items():
|
| 119 |
+
if key.startswith("output_"):
|
| 120 |
+
output_lines.append(f"{key}: {value}")
|
| 121 |
+
|
| 122 |
+
return "\n".join(output_lines) if output_lines else "Code executed successfully"
|
| 123 |
+
|
| 124 |
+
def _execute_javascript(self, code: str) -> ExecutionResult:
|
| 125 |
+
"""Execute JavaScript code using Node.js"""
|
| 126 |
+
import tempfile
|
| 127 |
+
import time
|
| 128 |
+
|
| 129 |
+
start_time = time.time()
|
| 130 |
+
|
| 131 |
+
with tempfile.NamedTemporaryFile(
|
| 132 |
+
mode="w", suffix=".js", delete=False
|
| 133 |
+
) as f:
|
| 134 |
+
f.write(code)
|
| 135 |
+
temp_file = f.name
|
| 136 |
+
|
| 137 |
+
try:
|
| 138 |
+
result = subprocess.run(
|
| 139 |
+
["node", temp_file],
|
| 140 |
+
capture_output=True,
|
| 141 |
+
text=True,
|
| 142 |
+
timeout=self.timeout,
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
if result.returncode == 0:
|
| 146 |
+
return ExecutionResult(
|
| 147 |
+
success=True,
|
| 148 |
+
output=result.stdout,
|
| 149 |
+
execution_time=time.time() - start_time,
|
| 150 |
+
)
|
| 151 |
+
else:
|
| 152 |
+
return ExecutionResult(
|
| 153 |
+
success=False,
|
| 154 |
+
output="",
|
| 155 |
+
error=result.stderr,
|
| 156 |
+
execution_time=time.time() - start_time,
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
except subprocess.TimeoutExpired:
|
| 160 |
+
return ExecutionResult(
|
| 161 |
+
success=False,
|
| 162 |
+
output="",
|
| 163 |
+
error=f"Execution timed out after {self.timeout}s",
|
| 164 |
+
execution_time=time.time() - start_time,
|
| 165 |
+
)
|
| 166 |
+
except FileNotFoundError:
|
| 167 |
+
return ExecutionResult(
|
| 168 |
+
success=False,
|
| 169 |
+
output="",
|
| 170 |
+
error="Node.js not found. Please install Node.js to execute JavaScript.",
|
| 171 |
+
execution_time=time.time() - start_time,
|
| 172 |
+
)
|
| 173 |
+
finally:
|
| 174 |
+
import os
|
| 175 |
+
|
| 176 |
+
os.unlink(temp_file)
|
| 177 |
+
|
| 178 |
+
def _execute_sql(self, code: str) -> ExecutionResult:
|
| 179 |
+
"""Execute SQL query"""
|
| 180 |
+
import time
|
| 181 |
+
|
| 182 |
+
start_time = time.time()
|
| 183 |
+
|
| 184 |
+
return ExecutionResult(
|
| 185 |
+
success=True,
|
| 186 |
+
output=f"SQL query would be executed:\n{code}",
|
| 187 |
+
execution_time=time.time() - start_time,
|
| 188 |
+
)
|
| 189 |
+
|
| 190 |
+
def _execute_bash(self, code: str) -> ExecutionResult:
|
| 191 |
+
"""Execute bash command"""
|
| 192 |
+
import time
|
| 193 |
+
|
| 194 |
+
start_time = time.time()
|
| 195 |
+
|
| 196 |
+
if self.sandbox:
|
| 197 |
+
return ExecutionResult(
|
| 198 |
+
success=False,
|
| 199 |
+
output="",
|
| 200 |
+
error="Bash execution is disabled in sandbox mode",
|
| 201 |
+
execution_time=time.time() - start_time,
|
| 202 |
+
)
|
| 203 |
+
|
| 204 |
+
try:
|
| 205 |
+
result = subprocess.run(
|
| 206 |
+
code, shell=True, capture_output=True, text=True, timeout=self.timeout
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
return ExecutionResult(
|
| 210 |
+
success=result.returncode == 0,
|
| 211 |
+
output=result.stdout,
|
| 212 |
+
error=result.stderr if result.returncode != 0 else None,
|
| 213 |
+
execution_time=time.time() - start_time,
|
| 214 |
+
)
|
| 215 |
+
|
| 216 |
+
except subprocess.TimeoutExpired:
|
| 217 |
+
return ExecutionResult(
|
| 218 |
+
success=False,
|
| 219 |
+
output="",
|
| 220 |
+
error=f"Command timed out after {self.timeout}s",
|
| 221 |
+
execution_time=time.time() - start_time,
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
def validate_syntax(self, code: str, language: str) -> tuple[bool, Optional[str]]:
|
| 225 |
+
"""Validate code syntax without execution"""
|
| 226 |
+
if language == "python":
|
| 227 |
+
try:
|
| 228 |
+
ast.parse(code)
|
| 229 |
+
return True, None
|
| 230 |
+
except SyntaxError as e:
|
| 231 |
+
return False, str(e)
|
| 232 |
+
|
| 233 |
+
return True, None
|
src/core/validator.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Response Validator - Validate AI generated responses"""
|
| 2 |
+
|
| 3 |
+
import re
|
| 4 |
+
from typing import Dict, List, Optional, Tuple
|
| 5 |
+
from dataclasses import dataclass
|
| 6 |
+
from enum import Enum
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class ResponseQuality(Enum):
|
| 10 |
+
"""Response quality levels"""
|
| 11 |
+
|
| 12 |
+
EXCELLENT = "excellent"
|
| 13 |
+
GOOD = "good"
|
| 14 |
+
ADEQUATE = "adequate"
|
| 15 |
+
POOR = "poor"
|
| 16 |
+
INVALID = "invalid"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@dataclass
|
| 20 |
+
class ValidationResult:
|
| 21 |
+
"""Validation result container"""
|
| 22 |
+
|
| 23 |
+
quality: ResponseQuality
|
| 24 |
+
score: float
|
| 25 |
+
issues: List[str]
|
| 26 |
+
suggestions: List[str]
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class ResponseValidator:
|
| 30 |
+
"""Validate AI generated code responses"""
|
| 31 |
+
|
| 32 |
+
def __init__(self):
|
| 33 |
+
self.min_code_length = 50
|
| 34 |
+
self.max_issues = 3
|
| 35 |
+
self.quality_threshold = 0.6
|
| 36 |
+
|
| 37 |
+
def validate(self, response: str, instruction: str) -> ValidationResult:
|
| 38 |
+
"""Validate response quality"""
|
| 39 |
+
issues: List[str] = []
|
| 40 |
+
suggestions: List[str] = []
|
| 41 |
+
score = 1.0
|
| 42 |
+
|
| 43 |
+
if len(response) < self.min_code_length:
|
| 44 |
+
issues.append("Response too short")
|
| 45 |
+
score -= 0.3
|
| 46 |
+
|
| 47 |
+
if not self._contains_code(response):
|
| 48 |
+
issues.append("No code block found in response")
|
| 49 |
+
score -= 0.5
|
| 50 |
+
|
| 51 |
+
if not self._is_relevant(response, instruction):
|
| 52 |
+
issues.append("Response may not address the instruction")
|
| 53 |
+
score -= 0.2
|
| 54 |
+
|
| 55 |
+
if self._has_obvious_errors(response):
|
| 56 |
+
issues.append("Potential errors detected in code")
|
| 57 |
+
score -= 0.2
|
| 58 |
+
|
| 59 |
+
code_blocks = self._extract_code_blocks(response)
|
| 60 |
+
for i, block in enumerate(code_blocks):
|
| 61 |
+
if block_language := self._detect_language(block):
|
| 62 |
+
lang_issues = self._check_language_specific(block, block_language)
|
| 63 |
+
issues.extend([f"Block {i+1}: {issue}" for issue in lang_issues])
|
| 64 |
+
|
| 65 |
+
if not issues:
|
| 66 |
+
suggestions.append("Response looks good!")
|
| 67 |
+
else:
|
| 68 |
+
suggestions.append("Consider adding more explanatory comments")
|
| 69 |
+
|
| 70 |
+
quality = self._determine_quality(score, issues)
|
| 71 |
+
|
| 72 |
+
return ValidationResult(
|
| 73 |
+
quality=quality, score=max(0, score), issues=issues, suggestions=suggestions
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
def _contains_code(self, response: str) -> bool:
|
| 77 |
+
"""Check if response contains code blocks"""
|
| 78 |
+
return bool(re.search(r"```[\s\S]*?```", response))
|
| 79 |
+
|
| 80 |
+
def _is_relevant(self, response: str, instruction: str) -> bool:
|
| 81 |
+
"""Check if response is relevant to instruction"""
|
| 82 |
+
instruction_words = set(
|
| 83 |
+
re.findall(r"\b\w+\b", instruction.lower())
|
| 84 |
+
)
|
| 85 |
+
response_words = set(re.findall(r"\b\w+\b", response.lower()))
|
| 86 |
+
overlap = instruction_words & response_words
|
| 87 |
+
|
| 88 |
+
return len(overlap) >= min(3, len(instruction_words) * 0.3)
|
| 89 |
+
|
| 90 |
+
def _has_obvious_errors(self, response: str) -> bool:
|
| 91 |
+
"""Check for obvious code errors"""
|
| 92 |
+
error_patterns = [
|
| 93 |
+
r"undefined\s+variable",
|
| 94 |
+
r"cannot\s+find\s+module",
|
| 95 |
+
r"syntax\s+error",
|
| 96 |
+
r"indentation\s+error",
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
for pattern in error_patterns:
|
| 100 |
+
if re.search(pattern, response, re.IGNORECASE):
|
| 101 |
+
return True
|
| 102 |
+
|
| 103 |
+
return False
|
| 104 |
+
|
| 105 |
+
def _extract_code_blocks(self, response: str) -> List[str]:
|
| 106 |
+
"""Extract all code blocks from response"""
|
| 107 |
+
pattern = r"```[\w]*\n?([\s\S]*?)```"
|
| 108 |
+
matches = re.findall(pattern, response)
|
| 109 |
+
return [match.strip() for match in matches]
|
| 110 |
+
|
| 111 |
+
def _detect_language(self, code: str) -> Optional[str]:
|
| 112 |
+
"""Detect programming language from code"""
|
| 113 |
+
language_signatures = {
|
| 114 |
+
"python": [r"def\s+\w+\s*\(", r"import\s+\w+", r"if\s+__name__"],
|
| 115 |
+
"javascript": [r"const\s+\w+", r"function\s+\w+\s*\(", r"=>\s*{"],
|
| 116 |
+
"typescript": [r":\s*(string|number|boolean)\b", r"interface\s+\w+"],
|
| 117 |
+
"java": [r"public\s+class\s+\w+", r"System\.out\.println"],
|
| 118 |
+
"sql": [r"SELECT\s+.+\s+FROM", r"INSERT\s+INTO", r"CREATE\s+TABLE"],
|
| 119 |
+
"bash": [r"#!/bin/bash", r"echo\s+", r"\$\w+"],
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
for lang, patterns in language_signatures.items():
|
| 123 |
+
if any(re.search(p, code) for p in patterns):
|
| 124 |
+
return lang
|
| 125 |
+
|
| 126 |
+
return None
|
| 127 |
+
|
| 128 |
+
def _check_language_specific(self, code: str, language: str) -> List[str]:
|
| 129 |
+
"""Language-specific validation checks"""
|
| 130 |
+
issues = []
|
| 131 |
+
|
| 132 |
+
if language == "python":
|
| 133 |
+
if re.search(r"def\s+\w+\s*\([^)]*$", code):
|
| 134 |
+
issues.append("Missing colon at end of function definition")
|
| 135 |
+
|
| 136 |
+
if language == "javascript":
|
| 137 |
+
if re.search(r"const\s+\w+\s*=\s*\w+\s*\+\s*['\"]\s*['\"]", code):
|
| 138 |
+
issues.append("Empty string concatenation detected")
|
| 139 |
+
|
| 140 |
+
return issues
|
| 141 |
+
|
| 142 |
+
def _determine_quality(
|
| 143 |
+
self, score: float, issues: List[str]
|
| 144 |
+
) -> ResponseQuality:
|
| 145 |
+
"""Determine response quality based on score and issues"""
|
| 146 |
+
if score <= 0:
|
| 147 |
+
return ResponseQuality.INVALID
|
| 148 |
+
elif score >= 0.8 and len(issues) == 0:
|
| 149 |
+
return ResponseQuality.EXCELLENT
|
| 150 |
+
elif score >= 0.6:
|
| 151 |
+
return ResponseQuality.GOOD
|
| 152 |
+
elif score >= 0.4:
|
| 153 |
+
return ResponseQuality.ADEQUATE
|
| 154 |
+
else:
|
| 155 |
+
return ResponseQuality.POOR
|
| 156 |
+
|
| 157 |
+
def validate_multiple(
|
| 158 |
+
self, responses: List[str], instruction: str
|
| 159 |
+
) -> List[ValidationResult]:
|
| 160 |
+
"""Validate multiple responses and rank them"""
|
| 161 |
+
results = [self.validate(resp, instruction) for resp in responses]
|
| 162 |
+
return sorted(results, key=lambda r: r.score, reverse=True)
|
src/knowledge/__init__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Knowledge module - Local KB and Web Updater"""
|
| 2 |
+
|
| 3 |
+
from .local_kb import LocalKB
|
| 4 |
+
from .web_updater import WebUpdater
|
| 5 |
+
from .version_tracker import VersionTracker
|
| 6 |
+
from .cache_manager import CacheManager
|
| 7 |
+
|
| 8 |
+
__all__ = ["LocalKB", "WebUpdater", "VersionTracker", "CacheManager"]
|
src/knowledge/cache_manager.py
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Cache Manager - Handle application caching"""
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import time
|
| 5 |
+
import shutil
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from typing import Any, Optional, Dict
|
| 8 |
+
from dataclasses import dataclass, field
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@dataclass
|
| 12 |
+
class CacheEntry:
|
| 13 |
+
"""Single cache entry"""
|
| 14 |
+
|
| 15 |
+
key: str
|
| 16 |
+
value: Any
|
| 17 |
+
created_at: float = field(default_factory=time.time)
|
| 18 |
+
expires_at: Optional[float] = None
|
| 19 |
+
hits: int = 0
|
| 20 |
+
|
| 21 |
+
def is_expired(self) -> bool:
|
| 22 |
+
"""Check if entry has expired"""
|
| 23 |
+
if self.expires_at is None:
|
| 24 |
+
return False
|
| 25 |
+
return time.time() > self.expires_at
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class CacheManager:
|
| 29 |
+
"""Manage application cache"""
|
| 30 |
+
|
| 31 |
+
def __init__(self, cache_dir: Optional[str] = None, default_ttl: int = 3600):
|
| 32 |
+
if cache_dir:
|
| 33 |
+
self.cache_dir = Path(cache_dir)
|
| 34 |
+
else:
|
| 35 |
+
self.cache_dir = Path.home() / ".burme_coder" / "cache"
|
| 36 |
+
|
| 37 |
+
self.cache_dir.mkdir(parents=True, exist_ok=True)
|
| 38 |
+
self.default_ttl = default_ttl
|
| 39 |
+
self.memory_cache: Dict[str, CacheEntry] = {}
|
| 40 |
+
|
| 41 |
+
def get(self, key: str, use_memory: bool = True) -> Optional[Any]:
|
| 42 |
+
"""Get value from cache"""
|
| 43 |
+
if use_memory and key in self.memory_cache:
|
| 44 |
+
entry = self.memory_cache[key]
|
| 45 |
+
if not entry.is_expired():
|
| 46 |
+
entry.hits += 1
|
| 47 |
+
return entry.value
|
| 48 |
+
else:
|
| 49 |
+
del self.memory_cache[key]
|
| 50 |
+
|
| 51 |
+
cache_file = self._get_cache_file(key)
|
| 52 |
+
if cache_file and cache_file.exists():
|
| 53 |
+
try:
|
| 54 |
+
data = json.loads(cache_file.read_text(encoding="utf-8"))
|
| 55 |
+
entry = CacheEntry(
|
| 56 |
+
key=key,
|
| 57 |
+
value=data["value"],
|
| 58 |
+
created_at=data.get("created_at", time.time()),
|
| 59 |
+
expires_at=data.get("expires_at"),
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
if not entry.is_expired():
|
| 63 |
+
return entry.value
|
| 64 |
+
else:
|
| 65 |
+
cache_file.unlink()
|
| 66 |
+
except (json.JSONDecodeError, KeyError):
|
| 67 |
+
pass
|
| 68 |
+
|
| 69 |
+
return None
|
| 70 |
+
|
| 71 |
+
def set(
|
| 72 |
+
self, key: str, value: Any, ttl: Optional[int] = None, use_memory: bool = True
|
| 73 |
+
):
|
| 74 |
+
"""Set value in cache"""
|
| 75 |
+
ttl = ttl if ttl is not None else self.default_ttl
|
| 76 |
+
expires_at = time.time() + ttl if ttl > 0 else None
|
| 77 |
+
|
| 78 |
+
if use_memory:
|
| 79 |
+
self.memory_cache[key] = CacheEntry(key=key, value=value, expires_at=expires_at)
|
| 80 |
+
|
| 81 |
+
cache_file = self._get_cache_file(key)
|
| 82 |
+
if cache_file:
|
| 83 |
+
cache_data = {
|
| 84 |
+
"key": key,
|
| 85 |
+
"value": value,
|
| 86 |
+
"created_at": time.time(),
|
| 87 |
+
"expires_at": expires_at,
|
| 88 |
+
}
|
| 89 |
+
cache_file.write_text(json.dumps(cache_data), encoding="utf-8")
|
| 90 |
+
|
| 91 |
+
def delete(self, key: str):
|
| 92 |
+
"""Delete cache entry"""
|
| 93 |
+
if key in self.memory_cache:
|
| 94 |
+
del self.memory_cache[key]
|
| 95 |
+
|
| 96 |
+
cache_file = self._get_cache_file(key)
|
| 97 |
+
if cache_file and cache_file.exists():
|
| 98 |
+
cache_file.unlink()
|
| 99 |
+
|
| 100 |
+
def clear(self, pattern: Optional[str] = None):
|
| 101 |
+
"""Clear cache entries"""
|
| 102 |
+
if pattern:
|
| 103 |
+
for cache_file in self.cache_dir.glob(f"{pattern}*"):
|
| 104 |
+
cache_file.unlink()
|
| 105 |
+
else:
|
| 106 |
+
for cache_file in self.cache_dir.glob("*.json"):
|
| 107 |
+
cache_file.unlink()
|
| 108 |
+
self.memory_cache.clear()
|
| 109 |
+
|
| 110 |
+
def cleanup_expired(self):
|
| 111 |
+
"""Remove all expired entries"""
|
| 112 |
+
expired_keys = [k for k, v in self.memory_cache.items() if v.is_expired()]
|
| 113 |
+
for key in expired_keys:
|
| 114 |
+
del self.memory_cache[key]
|
| 115 |
+
|
| 116 |
+
for cache_file in self.cache_dir.glob("*.json"):
|
| 117 |
+
try:
|
| 118 |
+
data = json.loads(cache_file.read_text(encoding="utf-8"))
|
| 119 |
+
if data.get("expires_at") and time.time() > data["expires_at"]:
|
| 120 |
+
cache_file.unlink()
|
| 121 |
+
except (json.JSONDecodeError, KeyError):
|
| 122 |
+
pass
|
| 123 |
+
|
| 124 |
+
def get_stats(self) -> Dict:
|
| 125 |
+
"""Get cache statistics"""
|
| 126 |
+
total_hits = sum(e.hits for e in self.memory_cache.values())
|
| 127 |
+
entries_count = len(self.memory_cache)
|
| 128 |
+
disk_files = len(list(self.cache_dir.glob("*.json")))
|
| 129 |
+
|
| 130 |
+
return {
|
| 131 |
+
"memory_entries": entries_count,
|
| 132 |
+
"disk_files": disk_files,
|
| 133 |
+
"total_hits": total_hits,
|
| 134 |
+
"cache_dir": str(self.cache_dir),
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
def _get_cache_file(self, key: str) -> Optional[Path]:
|
| 138 |
+
"""Get cache file path for key"""
|
| 139 |
+
safe_key = "".join(c if c.isalnum() or c in "-_" else "_" for c in key)
|
| 140 |
+
if len(safe_key) > 50:
|
| 141 |
+
import hashlib
|
| 142 |
+
safe_key = hashlib.md5(key.encode()).hexdigest()
|
| 143 |
+
|
| 144 |
+
return self.cache_dir / f"{safe_key}.json"
|
| 145 |
+
|
| 146 |
+
def clear_all(self):
|
| 147 |
+
"""Clear all caches including memory"""
|
| 148 |
+
self.memory_cache.clear()
|
| 149 |
+
if self.cache_dir.exists():
|
| 150 |
+
shutil.rmtree(self.cache_dir)
|
| 151 |
+
self.cache_dir.mkdir(parents=True, exist_ok=True)
|
src/knowledge/local_kb.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Local Knowledge Base - Search markdown files"""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import json
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from typing import List, Dict, Optional
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class LocalKB:
|
| 10 |
+
"""Local knowledge base for markdown files"""
|
| 11 |
+
|
| 12 |
+
def __init__(self, base_dir: Optional[str] = None):
|
| 13 |
+
if base_dir:
|
| 14 |
+
self.base_dir = Path(base_dir)
|
| 15 |
+
else:
|
| 16 |
+
self.base_dir = Path(__file__).parent.parent.parent / "data" / "knowledge"
|
| 17 |
+
|
| 18 |
+
self.skills_dir = self.base_dir / "skills"
|
| 19 |
+
self.webs_dir = self.base_dir / "webs"
|
| 20 |
+
self.updates_dir = self.base_dir / "updates"
|
| 21 |
+
|
| 22 |
+
self._ensure_directories()
|
| 23 |
+
|
| 24 |
+
def _ensure_directories(self):
|
| 25 |
+
"""Create necessary directories if they don't exist"""
|
| 26 |
+
for directory in [self.skills_dir, self.webs_dir, self.updates_dir]:
|
| 27 |
+
directory.mkdir(parents=True, exist_ok=True)
|
| 28 |
+
|
| 29 |
+
def search(self, query: str, category: Optional[str] = None) -> List[Dict]:
|
| 30 |
+
"""Search knowledge base for query"""
|
| 31 |
+
results = []
|
| 32 |
+
|
| 33 |
+
if category == "skills" or category is None:
|
| 34 |
+
results.extend(self._search_directory(self.skills_dir, query))
|
| 35 |
+
|
| 36 |
+
if category == "webs" or category is None:
|
| 37 |
+
results.extend(self._search_directory(self.webs_dir, query))
|
| 38 |
+
|
| 39 |
+
if category == "updates" or category is None:
|
| 40 |
+
results.extend(self._search_directory(self.updates_dir, query))
|
| 41 |
+
|
| 42 |
+
return results
|
| 43 |
+
|
| 44 |
+
def _search_directory(self, directory: Path, query: str) -> List[Dict]:
|
| 45 |
+
"""Search files in a directory"""
|
| 46 |
+
results = []
|
| 47 |
+
query_lower = query.lower()
|
| 48 |
+
|
| 49 |
+
for md_file in directory.glob("*.md"):
|
| 50 |
+
content = md_file.read_text(encoding="utf-8")
|
| 51 |
+
lines = content.split("\n")
|
| 52 |
+
|
| 53 |
+
for i, line in enumerate(lines):
|
| 54 |
+
if query_lower in line.lower():
|
| 55 |
+
start = max(0, i - 2)
|
| 56 |
+
end = min(len(lines), i + 5)
|
| 57 |
+
snippet = "\n".join(lines[start:end])
|
| 58 |
+
|
| 59 |
+
results.append(
|
| 60 |
+
{
|
| 61 |
+
"source": md_file.name,
|
| 62 |
+
"line": i + 1,
|
| 63 |
+
"snippet": snippet,
|
| 64 |
+
"relevance": self._calculate_relevance(line, query),
|
| 65 |
+
}
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
return sorted(results, key=lambda x: x["relevance"], reverse=True)
|
| 69 |
+
|
| 70 |
+
def _calculate_relevance(self, text: str, query: str) -> float:
|
| 71 |
+
"""Calculate relevance score"""
|
| 72 |
+
text_lower = text.lower()
|
| 73 |
+
query_lower = query.lower()
|
| 74 |
+
|
| 75 |
+
if query_lower in text_lower:
|
| 76 |
+
return 1.0
|
| 77 |
+
|
| 78 |
+
query_words = query_lower.split()
|
| 79 |
+
matches = sum(1 for word in query_words if word in text_lower)
|
| 80 |
+
return matches / len(query_words) if query_words else 0
|
| 81 |
+
|
| 82 |
+
def get_all_topics(self) -> List[str]:
|
| 83 |
+
"""Get list of all available topics"""
|
| 84 |
+
topics = []
|
| 85 |
+
|
| 86 |
+
for md_file in self.skills_dir.glob("*.md"):
|
| 87 |
+
topics.append(md_file.stem.replace("_", " ").title())
|
| 88 |
+
|
| 89 |
+
return sorted(topics)
|
| 90 |
+
|
| 91 |
+
def get_content(self, topic: str) -> Optional[str]:
|
| 92 |
+
"""Get content for a specific topic"""
|
| 93 |
+
topic_file = self.skills_dir / f"{topic.lower().replace(' ', '_')}.md"
|
| 94 |
+
|
| 95 |
+
if topic_file.exists():
|
| 96 |
+
return topic_file.read_text(encoding="utf-8")
|
| 97 |
+
|
| 98 |
+
for md_file in self.skills_dir.glob("*.md"):
|
| 99 |
+
if topic.lower() in md_file.stem.lower():
|
| 100 |
+
return md_file.read_text(encoding="utf-8")
|
| 101 |
+
|
| 102 |
+
return None
|
| 103 |
+
|
| 104 |
+
def get_random_entry(self) -> Optional[Dict]:
|
| 105 |
+
"""Get a random knowledge entry"""
|
| 106 |
+
import random
|
| 107 |
+
|
| 108 |
+
files = list(self.skills_dir.glob("*.md"))
|
| 109 |
+
if not files:
|
| 110 |
+
return None
|
| 111 |
+
|
| 112 |
+
file = random.choice(files)
|
| 113 |
+
content = file.read_text(encoding="utf-8")
|
| 114 |
+
|
| 115 |
+
return {"source": file.name, "content": content}
|
src/knowledge/version_tracker.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Version Tracker - Track versions and changelog"""
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from typing import List, Dict, Optional
|
| 6 |
+
from dataclasses import dataclass
|
| 7 |
+
from datetime import datetime
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@dataclass
|
| 11 |
+
class Change:
|
| 12 |
+
"""Represents a single change entry"""
|
| 13 |
+
|
| 14 |
+
version: str
|
| 15 |
+
change_type: str
|
| 16 |
+
description: str
|
| 17 |
+
date: str
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class VersionTracker:
|
| 21 |
+
"""Track software versions and changelog"""
|
| 22 |
+
|
| 23 |
+
CURRENT_VERSION = "1.0.0"
|
| 24 |
+
VERSION_FILE = "version.json"
|
| 25 |
+
|
| 26 |
+
CHANGELOG = [
|
| 27 |
+
{
|
| 28 |
+
"version": "1.0.0",
|
| 29 |
+
"date": "2025-01-01",
|
| 30 |
+
"changes": [
|
| 31 |
+
"Initial release",
|
| 32 |
+
"Core agent functionality",
|
| 33 |
+
"Terminal animations",
|
| 34 |
+
"Knowledge base integration",
|
| 35 |
+
],
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"version": "0.9.0",
|
| 39 |
+
"date": "2024-12-15",
|
| 40 |
+
"changes": [
|
| 41 |
+
"Beta release",
|
| 42 |
+
"Myanmar language support",
|
| 43 |
+
"Basic animations",
|
| 44 |
+
],
|
| 45 |
+
},
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
def __init__(self, data_dir: Optional[Path] = None):
|
| 49 |
+
if data_dir:
|
| 50 |
+
self.data_dir = data_dir
|
| 51 |
+
else:
|
| 52 |
+
self.data_dir = Path.home() / ".burme_coder"
|
| 53 |
+
|
| 54 |
+
self.data_dir.mkdir(parents=True, exist_ok=True)
|
| 55 |
+
self._ensure_version_file()
|
| 56 |
+
|
| 57 |
+
def _ensure_version_file(self):
|
| 58 |
+
"""Ensure version tracking file exists"""
|
| 59 |
+
version_file = self.data_dir / self.VERSION_FILE
|
| 60 |
+
|
| 61 |
+
if not version_file.exists():
|
| 62 |
+
version_file.write_text(
|
| 63 |
+
json.dumps({"version": self.CURRENT_VERSION, "last_updated": datetime.now().isoformat()}, indent=2)
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
def get_current_version(self) -> str:
|
| 67 |
+
"""Get current version"""
|
| 68 |
+
return self.CURRENT_VERSION
|
| 69 |
+
|
| 70 |
+
def get_changelog(self) -> List[Dict]:
|
| 71 |
+
"""Get full changelog"""
|
| 72 |
+
return self.CHANGELOG
|
| 73 |
+
|
| 74 |
+
def get_changes_for_version(self, version: str) -> Optional[Dict]:
|
| 75 |
+
"""Get changes for a specific version"""
|
| 76 |
+
for entry in self.CHANGELOG:
|
| 77 |
+
if entry["version"] == version:
|
| 78 |
+
return entry
|
| 79 |
+
return None
|
| 80 |
+
|
| 81 |
+
def is_update_available(self, remote_version: str) -> bool:
|
| 82 |
+
"""Check if update is available"""
|
| 83 |
+
current = self._version_tuple(self.CURRENT_VERSION)
|
| 84 |
+
remote = self._version_tuple(remote_version)
|
| 85 |
+
return remote > current
|
| 86 |
+
|
| 87 |
+
def _version_tuple(self, version: str) -> tuple:
|
| 88 |
+
"""Convert version string to tuple for comparison"""
|
| 89 |
+
parts = version.replace("-", ".").split(".")
|
| 90 |
+
return tuple(int(p) if p.isdigit() else 0 for p in parts)
|
| 91 |
+
|
| 92 |
+
def get_roadmap(self) -> List[Dict]:
|
| 93 |
+
"""Get project roadmap"""
|
| 94 |
+
return [
|
| 95 |
+
{
|
| 96 |
+
"version": "1.1.0",
|
| 97 |
+
"planned_features": [
|
| 98 |
+
"Enhanced animations",
|
| 99 |
+
"More language support",
|
| 100 |
+
"Improved knowledge base",
|
| 101 |
+
],
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"version": "1.2.0",
|
| 105 |
+
"planned_features": [
|
| 106 |
+
"API server",
|
| 107 |
+
"Web interface",
|
| 108 |
+
"REST API",
|
| 109 |
+
],
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"version": "2.0.0",
|
| 113 |
+
"planned_features": [
|
| 114 |
+
"Full model training",
|
| 115 |
+
"Production deployment",
|
| 116 |
+
],
|
| 117 |
+
},
|
| 118 |
+
]
|
| 119 |
+
|
| 120 |
+
def get_deprecations(self) -> List[Dict]:
|
| 121 |
+
"""Get list of deprecated features"""
|
| 122 |
+
return [
|
| 123 |
+
{
|
| 124 |
+
"feature": "old_animation_api",
|
| 125 |
+
"version": "0.9.0",
|
| 126 |
+
"replacement": "new_animation_api",
|
| 127 |
+
"removal_version": "1.2.0",
|
| 128 |
+
}
|
| 129 |
+
]
|
src/knowledge/web_updater.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Web Updater - Update knowledge from web sources"""
|
| 2 |
+
|
| 3 |
+
import re
|
| 4 |
+
import time
|
| 5 |
+
import hashlib
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from typing import Optional, List, Dict
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
|
| 11 |
+
import requests
|
| 12 |
+
from bs4 import BeautifulSoup
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@dataclass
|
| 16 |
+
class WebSource:
|
| 17 |
+
"""Web source configuration"""
|
| 18 |
+
|
| 19 |
+
name: str
|
| 20 |
+
url: str
|
| 21 |
+
selector: str = "article"
|
| 22 |
+
update_interval: int = 3600
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class WebUpdater:
|
| 26 |
+
"""Update knowledge from web sources"""
|
| 27 |
+
|
| 28 |
+
DEFAULT_SOURCES = [
|
| 29 |
+
WebSource(
|
| 30 |
+
name="python_docs",
|
| 31 |
+
url="https://docs.python.org/3/",
|
| 32 |
+
selector="main",
|
| 33 |
+
),
|
| 34 |
+
WebSource(
|
| 35 |
+
name="javascript_docs",
|
| 36 |
+
url="https://developer.mozilla.org/en-US/docs/Web/JavaScript",
|
| 37 |
+
selector="article",
|
| 38 |
+
),
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
def __init__(self, cache_dir: Optional[str] = None):
|
| 42 |
+
if cache_dir:
|
| 43 |
+
self.cache_dir = Path(cache_dir)
|
| 44 |
+
else:
|
| 45 |
+
self.cache_dir = Path.home() / ".burme_coder" / "cache"
|
| 46 |
+
|
| 47 |
+
self.cache_dir.mkdir(parents=True, exist_ok=True)
|
| 48 |
+
self.last_fetch: Dict[str, datetime] = {}
|
| 49 |
+
|
| 50 |
+
def fetch_content(self, source: WebSource) -> Optional[str]:
|
| 51 |
+
"""Fetch content from a web source"""
|
| 52 |
+
cache_file = self.cache_dir / f"{source.name}.html"
|
| 53 |
+
|
| 54 |
+
if self._is_cache_valid(cache_file):
|
| 55 |
+
return cache_file.read_text(encoding="utf-8")
|
| 56 |
+
|
| 57 |
+
try:
|
| 58 |
+
response = requests.get(
|
| 59 |
+
source.url, timeout=30, headers={"User-Agent": "Burme-Coder/1.0"}
|
| 60 |
+
)
|
| 61 |
+
response.raise_for_status()
|
| 62 |
+
|
| 63 |
+
soup = BeautifulSoup(response.text, "lxml")
|
| 64 |
+
content_tag = soup.select_one(source.selector)
|
| 65 |
+
|
| 66 |
+
if content_tag:
|
| 67 |
+
text = self._clean_text(content_tag.get_text())
|
| 68 |
+
cache_file.write_text(text, encoding="utf-8")
|
| 69 |
+
self.last_fetch[source.name] = datetime.now()
|
| 70 |
+
return text
|
| 71 |
+
|
| 72 |
+
except requests.RequestException as e:
|
| 73 |
+
print(f"Error fetching {source.name}: {e}")
|
| 74 |
+
|
| 75 |
+
return None
|
| 76 |
+
|
| 77 |
+
def _is_cache_valid(self, cache_file: Path, max_age: int = 3600) -> bool:
|
| 78 |
+
"""Check if cache file is still valid"""
|
| 79 |
+
if not cache_file.exists():
|
| 80 |
+
return False
|
| 81 |
+
|
| 82 |
+
mtime = datetime.fromtimestamp(cache_file.stat().st_mtime)
|
| 83 |
+
age = (datetime.now() - mtime).total_seconds()
|
| 84 |
+
|
| 85 |
+
return age < max_age
|
| 86 |
+
|
| 87 |
+
def _clean_text(self, text: str) -> str:
|
| 88 |
+
"""Clean and format text content"""
|
| 89 |
+
text = re.sub(r"\n{3,}", "\n\n", text)
|
| 90 |
+
text = re.sub(r" {2,}", " ", text)
|
| 91 |
+
return text.strip()
|
| 92 |
+
|
| 93 |
+
def fetch_all(self) -> Dict[str, str]:
|
| 94 |
+
"""Fetch content from all configured sources"""
|
| 95 |
+
results = {}
|
| 96 |
+
|
| 97 |
+
for source in self.DEFAULT_SOURCES:
|
| 98 |
+
content = self.fetch_content(source)
|
| 99 |
+
if content:
|
| 100 |
+
results[source.name] = content
|
| 101 |
+
|
| 102 |
+
return results
|
| 103 |
+
|
| 104 |
+
def update_markdown_files(
|
| 105 |
+
self, output_dir: Path, force: bool = False
|
| 106 |
+
) -> List[str]:
|
| 107 |
+
"""Update markdown files from web sources"""
|
| 108 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 109 |
+
updated_files = []
|
| 110 |
+
|
| 111 |
+
for source in self.DEFAULT_SOURCES:
|
| 112 |
+
content = self.fetch_content(source)
|
| 113 |
+
|
| 114 |
+
if content:
|
| 115 |
+
md_file = output_dir / f"{source.name}.md"
|
| 116 |
+
|
| 117 |
+
if md_file.exists() and not force:
|
| 118 |
+
if self._content_changed(md_file, content):
|
| 119 |
+
md_file.write_text(content, encoding="utf-8")
|
| 120 |
+
updated_files.append(md_file.name)
|
| 121 |
+
else:
|
| 122 |
+
md_file.write_text(content, encoding="utf-8")
|
| 123 |
+
updated_files.append(md_file.name)
|
| 124 |
+
|
| 125 |
+
return updated_files
|
| 126 |
+
|
| 127 |
+
def _content_changed(self, file: Path, new_content: str) -> bool:
|
| 128 |
+
"""Check if content has changed"""
|
| 129 |
+
old_content = file.read_text(encoding="utf-8")
|
| 130 |
+
old_hash = hashlib.md5(old_content.encode()).hexdigest()
|
| 131 |
+
new_hash = hashlib.md5(new_content.encode()).hexdigest()
|
| 132 |
+
return old_hash != new_hash
|
| 133 |
+
|
| 134 |
+
def scrape_url(self, url: str, selectors: List[str]) -> Optional[str]:
|
| 135 |
+
"""Scrape specific content from a URL"""
|
| 136 |
+
try:
|
| 137 |
+
response = requests.get(url, timeout=30)
|
| 138 |
+
response.raise_for_status()
|
| 139 |
+
|
| 140 |
+
soup = BeautifulSoup(response.text, "lxml")
|
| 141 |
+
|
| 142 |
+
for selector in selectors:
|
| 143 |
+
element = soup.select_one(selector)
|
| 144 |
+
if element:
|
| 145 |
+
return self._clean_text(element.get_text())
|
| 146 |
+
|
| 147 |
+
except requests.RequestException as e:
|
| 148 |
+
print(f"Error scraping {url}: {e}")
|
| 149 |
+
|
| 150 |
+
return None
|
| 151 |
+
|
| 152 |
+
def get_last_fetch_time(self, source_name: str) -> Optional[datetime]:
|
| 153 |
+
"""Get the last fetch time for a source"""
|
| 154 |
+
return self.last_fetch.get(source_name)
|
src/ui/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""UI module - Colors, Layout, and Thanking System"""
|
| 2 |
+
|
| 3 |
+
from . import colors
|
| 4 |
+
from . import layout
|
| 5 |
+
from . import thanking
|
| 6 |
+
|
| 7 |
+
__all__ = ["colors", "layout", "thanking"]
|
src/ui/colors.py
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""ANSI Color Codes for Terminal Output"""
|
| 2 |
+
|
| 3 |
+
from enum import Enum
|
| 4 |
+
from typing import Optional
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class Colors(Enum):
|
| 8 |
+
"""Standard ANSI color codes"""
|
| 9 |
+
|
| 10 |
+
RESET = "\033[0m"
|
| 11 |
+
BOLD = "\033[1m"
|
| 12 |
+
DIM = "\033[2m"
|
| 13 |
+
ITALIC = "\033[3m"
|
| 14 |
+
UNDERLINE = "\033[4m"
|
| 15 |
+
|
| 16 |
+
BLACK = "\033[30m"
|
| 17 |
+
RED = "\033[31m"
|
| 18 |
+
GREEN = "\033[32m"
|
| 19 |
+
YELLOW = "\033[33m"
|
| 20 |
+
BLUE = "\033[34m"
|
| 21 |
+
MAGENTA = "\033[35m"
|
| 22 |
+
CYAN = "\033[36m"
|
| 23 |
+
WHITE = "\033[37m"
|
| 24 |
+
|
| 25 |
+
BG_BLACK = "\033[40m"
|
| 26 |
+
BG_RED = "\033[41m"
|
| 27 |
+
BG_GREEN = "\033[42m"
|
| 28 |
+
BG_YELLOW = "\033[43m"
|
| 29 |
+
BG_BLUE = "\033[44m"
|
| 30 |
+
BG_MAGENTA = "\033[45m"
|
| 31 |
+
BG_CYAN = "\033[46m"
|
| 32 |
+
BG_WHITE = "\033[47m"
|
| 33 |
+
|
| 34 |
+
BRIGHT_BLACK = "\033[90m"
|
| 35 |
+
BRIGHT_RED = "\033[91m"
|
| 36 |
+
BRIGHT_GREEN = "\033[92m"
|
| 37 |
+
BRIGHT_YELLOW = "\033[93m"
|
| 38 |
+
BRIGHT_BLUE = "\033[94m"
|
| 39 |
+
BRIGHT_MAGENTA = "\033[95m"
|
| 40 |
+
BRIGHT_CYAN = "\033[96m"
|
| 41 |
+
BRIGHT_WHITE = "\033[97m"
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class ColorStr:
|
| 45 |
+
"""String with color formatting"""
|
| 46 |
+
|
| 47 |
+
def __init__(self, text: str, color: Optional[str] = None):
|
| 48 |
+
self.text = text
|
| 49 |
+
self.color = color or ""
|
| 50 |
+
|
| 51 |
+
def __str__(self) -> str:
|
| 52 |
+
if self.color:
|
| 53 |
+
return f"{self.color}{self.text}{Colors.RESET.value}"
|
| 54 |
+
return self.text
|
| 55 |
+
|
| 56 |
+
def __repr__(self) -> str:
|
| 57 |
+
return f"ColorStr({self.text!r}, {self.color!r})"
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def colorize(text: str, *styles: str) -> str:
|
| 61 |
+
"""Add color/styling to text"""
|
| 62 |
+
style_codes = []
|
| 63 |
+
for style in styles:
|
| 64 |
+
style = style.upper().replace("_", "-")
|
| 65 |
+
try:
|
| 66 |
+
style_codes.append(getattr(Colors, style).value)
|
| 67 |
+
except AttributeError:
|
| 68 |
+
pass
|
| 69 |
+
|
| 70 |
+
return "".join(style_codes) + text + Colors.RESET.value
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def red(text: str) -> str:
|
| 74 |
+
"""Red colored text"""
|
| 75 |
+
return colorize(text, "RED")
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def green(text: str) -> str:
|
| 79 |
+
"""Green colored text"""
|
| 80 |
+
return colorize(text, "GREEN")
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def yellow(text: str) -> str:
|
| 84 |
+
"""Yellow colored text"""
|
| 85 |
+
return colorize(text, "YELLOW")
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def blue(text: str) -> str:
|
| 89 |
+
"""Blue colored text"""
|
| 90 |
+
return colorize(text, "BLUE")
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def magenta(text: str) -> str:
|
| 94 |
+
"""Magenta colored text"""
|
| 95 |
+
return colorize(text, "MAGENTA")
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def cyan(text: str) -> str:
|
| 99 |
+
"""Cyan colored text"""
|
| 100 |
+
return colorize(text, "CYAN")
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def bold(text: str) -> str:
|
| 104 |
+
"""Bold text"""
|
| 105 |
+
return colorize(text, "BOLD")
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def dim(text: str) -> str:
|
| 109 |
+
"""Dim text"""
|
| 110 |
+
return colorize(text, "DIM")
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def error(text: str) -> str:
|
| 114 |
+
"""Error styled text (red bold)"""
|
| 115 |
+
return colorize(text, "BOLD", "RED")
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def success(text: str) -> str:
|
| 119 |
+
"""Success styled text (green bold)"""
|
| 120 |
+
return colorize(text, "BOLD", "GREEN")
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def warning(text: str) -> str:
|
| 124 |
+
"""Warning styled text (yellow)"""
|
| 125 |
+
return colorize(text, "YELLOW")
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def info(text: str) -> str:
|
| 129 |
+
"""Info styled text (cyan)"""
|
| 130 |
+
return colorize(text, "CYAN")
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def code(text: str) -> str:
|
| 134 |
+
"""Code styled text"""
|
| 135 |
+
return colorize(text, "DIM", "CYAN")
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def header(text: str) -> str:
|
| 139 |
+
"""Header styled text"""
|
| 140 |
+
return colorize(text, "BOLD", "CYAN")
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def prompt(text: str) -> str:
|
| 144 |
+
"""Prompt styled text (green)"""
|
| 145 |
+
return colorize(text, "BOLD", "GREEN")
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def clear_line():
|
| 149 |
+
"""Clear current line in terminal"""
|
| 150 |
+
print("\033[2K\r", end="")
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def move.cursor_up(lines: int = 1):
|
| 154 |
+
"""Move cursor up"""
|
| 155 |
+
print(f"\033[{lines}A", end="")
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def move_cursor_down(lines: int = 1):
|
| 159 |
+
"""Move cursor down"""
|
| 160 |
+
print(f"\033[{lines}B", end="")
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def move_cursor_right(cols: int = 1):
|
| 164 |
+
"""Move cursor right"""
|
| 165 |
+
print(f"\033[{cols}C", end="")
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def move_cursor_left(cols: int = 1):
|
| 169 |
+
"""Move cursor left"""
|
| 170 |
+
print(f"\033[{cols}D", end="")
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
def save_cursor_position():
|
| 174 |
+
"""Save cursor position"""
|
| 175 |
+
print("\033[s", end="")
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def restore_cursor_position():
|
| 179 |
+
"""Restore cursor position"""
|
| 180 |
+
print("\033[u", end="")
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def clear_screen():
|
| 184 |
+
"""Clear entire screen"""
|
| 185 |
+
print("\033[2J", end="")
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def hide_cursor():
|
| 189 |
+
"""Hide cursor"""
|
| 190 |
+
print("\033[?25l", end="")
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def show_cursor():
|
| 194 |
+
"""Show cursor"""
|
| 195 |
+
print("\033[?25h", end="")
|
src/ui/feedback.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""User Feedback Handler"""
|
| 2 |
+
|
| 3 |
+
import time
|
| 4 |
+
from typing import Optional, Dict
|
| 5 |
+
from enum import Enum
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class FeedbackType(Enum):
|
| 9 |
+
"""Types of user feedback"""
|
| 10 |
+
|
| 11 |
+
POSITIVE = "positive"
|
| 12 |
+
NEGATIVE = "negative"
|
| 13 |
+
NEUTRAL = "neutral"
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class FeedbackHandler:
|
| 17 |
+
"""Handle user feedback"""
|
| 18 |
+
|
| 19 |
+
def __init__(self):
|
| 20 |
+
self.feedback_history: list[Dict] = []
|
| 21 |
+
|
| 22 |
+
def collect_feedback(
|
| 23 |
+
self, response_id: str, helpful: bool, comment: Optional[str] = None
|
| 24 |
+
):
|
| 25 |
+
"""Collect user feedback"""
|
| 26 |
+
feedback = {
|
| 27 |
+
"response_id": response_id,
|
| 28 |
+
"helpful": helpful,
|
| 29 |
+
"comment": comment,
|
| 30 |
+
"timestamp": time.time(),
|
| 31 |
+
}
|
| 32 |
+
self.feedback_history.append(feedback)
|
| 33 |
+
return feedback
|
| 34 |
+
|
| 35 |
+
def get_average_rating(self) -> float:
|
| 36 |
+
"""Calculate average feedback rating"""
|
| 37 |
+
if not self.feedback_history:
|
| 38 |
+
return 0.0
|
| 39 |
+
|
| 40 |
+
positive = sum(1 for f in self.feedback_history if f["helpful"])
|
| 41 |
+
return positive / len(self.feedback_history)
|
| 42 |
+
|
| 43 |
+
def show_feedback_prompt(self):
|
| 44 |
+
"""Show feedback prompt"""
|
| 45 |
+
print("\n[bold cyan]Was this response helpful?[/bold cyan]")
|
| 46 |
+
print(" [green]1.[/green] Yes 👍")
|
| 47 |
+
print(" [red]2.[/red] No 👎")
|
| 48 |
+
print(" [yellow]3.[/yellow] Skip ⏭️")
|
| 49 |
+
|
| 50 |
+
def process_quick_feedback(self, rating: int) -> Dict:
|
| 51 |
+
"""Process quick feedback"""
|
| 52 |
+
feedback_map = {
|
| 53 |
+
1: (True, "positive"),
|
| 54 |
+
2: (False, "negative"),
|
| 55 |
+
3: (None, "neutral"),
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
helpful, ftype = feedback_map.get(rating, (None, "neutral"))
|
| 59 |
+
|
| 60 |
+
if helpful is not None:
|
| 61 |
+
return self.collect_feedback(
|
| 62 |
+
f"response_{int(time.time())}", helpful=helpful
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
return {"type": "skipped"}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def quick_feedback_prompt():
|
| 69 |
+
"""Quick feedback prompt"""
|
| 70 |
+
print("\n📊 Quick Feedback:")
|
| 71 |
+
print(" 👍 This helped!")
|
| 72 |
+
print(" 👎 Needs improvement")
|
| 73 |
+
print(" ⏭️ Skip")
|