feat: add florida module for unified hedging and monitoring
This commit is contained in:
134
florida/tools/commit_formatter.py
Normal file
134
florida/tools/commit_formatter.py
Normal file
@ -0,0 +1,134 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Commit Formatter for Git Agent
|
||||
Formats detailed commit messages for backup commits
|
||||
"""
|
||||
|
||||
import os
|
||||
from datetime import datetime, timezone
|
||||
from typing import Dict, Any
|
||||
|
||||
class CommitFormatter:
|
||||
"""Formats detailed commit messages for backup commits"""
|
||||
|
||||
def __init__(self, config: Dict[str, Any], logger):
|
||||
self.config = config
|
||||
self.logger = logger
|
||||
self.project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
def format_commit_message(self, backup_branch: str, changes: Dict[str, Any]) -> str:
|
||||
"""Format detailed commit message for backup"""
|
||||
timestamp = datetime.now(timezone.utc)
|
||||
|
||||
# Basic info
|
||||
file_count = len(changes['files'])
|
||||
backup_number = self._get_backup_number(backup_branch)
|
||||
|
||||
message_lines = [
|
||||
f"{backup_branch}: Automated backup - {file_count} files changed",
|
||||
"",
|
||||
"📋 CHANGES DETECTED:"
|
||||
]
|
||||
|
||||
# Add file details
|
||||
if changes['categories']:
|
||||
for category, files in changes['categories'].items():
|
||||
if files:
|
||||
message_lines.append(f"├── {category.upper()} ({len(files)} files)")
|
||||
for file_info in files:
|
||||
status_icon = self._get_status_icon(file_info['status'])
|
||||
line_info = self._get_line_changes(file_info)
|
||||
filename = os.path.basename(file_info['path'])
|
||||
message_lines.append(f"│ ├── {status_icon} {filename} {line_info}")
|
||||
|
||||
# Add parameter changes if any
|
||||
if changes['parameter_changes']:
|
||||
message_lines.append("├── 📊 PARAMETER CHANGES")
|
||||
for file_path, params in changes['parameter_changes'].items():
|
||||
filename = os.path.basename(file_path)
|
||||
message_lines.append(f"│ ├── 📄 {filename}")
|
||||
for param_name, param_info in params.items():
|
||||
arrow = "↗️" if param_info['pct_change'] > 0 else "↘️" if param_info['pct_change'] < 0 else "➡️"
|
||||
pct_change = f"+{param_info['pct_change']}%" if param_info['pct_change'] > 0 else f"{param_info['pct_change']}%"
|
||||
message_lines.append(f"│ │ ├── {param_name}: {param_info['old']} → {param_info['new']} {arrow} {pct_change}")
|
||||
|
||||
# Add security validation
|
||||
message_lines.extend([
|
||||
"├── 🔒 SECURITY VALIDATION",
|
||||
"│ ├── .env files: Correctly excluded",
|
||||
"│ ├── *.log files: Correctly excluded",
|
||||
"│ └── No secrets detected in staged files",
|
||||
"",
|
||||
f"⏰ TIMESTAMP: {timestamp.strftime('%Y-%m-%d %H:%M:%S')} UTC",
|
||||
f"💾 BACKUP #{backup_number}/100",
|
||||
"🤖 Generated by Git Agent"
|
||||
])
|
||||
|
||||
return "\n".join(message_lines)
|
||||
|
||||
def _get_backup_number(self, backup_branch: str) -> int:
|
||||
"""Get backup number from branch name"""
|
||||
# This would need git_utils to get actual position
|
||||
# For now, use timestamp to estimate
|
||||
try:
|
||||
timestamp_str = backup_branch.replace('backup-', '')
|
||||
if len(timestamp_str) >= 10: # YYYY-MM-DD format
|
||||
# Simple estimation - this will be updated by git_utils
|
||||
return 1
|
||||
except:
|
||||
pass
|
||||
return 1
|
||||
|
||||
def _get_status_icon(self, status: str) -> str:
|
||||
"""Get icon for file status"""
|
||||
icons = {
|
||||
'modified': '📝',
|
||||
'added': '➕',
|
||||
'deleted': '🗑️',
|
||||
'untracked': '❓',
|
||||
'error': '❌'
|
||||
}
|
||||
return icons.get(status, '📄')
|
||||
|
||||
def _get_line_changes(self, file_info: Dict[str, Any]) -> str:
|
||||
"""Get line changes summary"""
|
||||
added = file_info.get('lines_added', 0)
|
||||
deleted = file_info.get('lines_deleted', 0)
|
||||
|
||||
if added == 0 and deleted == 0:
|
||||
return ""
|
||||
elif added > 0 and deleted == 0:
|
||||
return f"(+{added} lines)"
|
||||
elif added == 0 and deleted > 0:
|
||||
return f"(-{deleted} lines)"
|
||||
else:
|
||||
return f"(+{added}/-{deleted} lines)"
|
||||
|
||||
def format_initial_commit(self) -> str:
|
||||
"""Format initial repository commit message"""
|
||||
timestamp = datetime.now(timezone.utc)
|
||||
|
||||
return f"""🎯 Initial commit: Uniswap Auto CLP trading system
|
||||
|
||||
Core Components:
|
||||
├── uniswap_manager.py: V3 concentrated liquidity position manager
|
||||
├── clp_hedger.py: Hyperliquid perpetuals hedging bot
|
||||
├── requirements.txt: Python dependencies
|
||||
├── .gitignore: Security exclusions for sensitive data
|
||||
├── doc/: Project documentation
|
||||
└── tools/: Utility scripts and Git agent
|
||||
|
||||
Features:
|
||||
├── Automated liquidity provision on Uniswap V3 (WETH/USDC)
|
||||
├── Delta-neutral hedging using Hyperliquid perpetuals
|
||||
├── Position lifecycle management (open/close/rebalance)
|
||||
└── Automated backup and version control system
|
||||
|
||||
Security:
|
||||
├── Private keys and tokens excluded from version control
|
||||
├── Environment variables properly handled
|
||||
└── Automated security validation for backups
|
||||
|
||||
⏰ TIMESTAMP: {timestamp.strftime('%Y-%m-%d %H:%M:%S')} UTC
|
||||
🚀 Ready for automated backups
|
||||
"""
|
||||
Reference in New Issue
Block a user