Claude hooks auto-backup: manual (backup_20250720_091250)

This commit is contained in:
Ryan Malloy 2025-07-20 03:12:51 -06:00
parent 9445e09c48
commit 392833187e
135 changed files with 16151 additions and 3439 deletions

View file

@ -150,27 +150,30 @@ This feedback loop is what transforms Claude from a stateless assistant into an
The shadow learner implements a classic observer pattern, but with sophisticated intelligence:
```python
class ShadowLearner:
def observe(self, execution: ToolExecution):
# Extract patterns from execution
patterns = self.extract_patterns(execution)
```javascript
class ShadowLearner {
observe(execution) {
// Extract patterns from execution
const patterns = this.extractPatterns(execution);
# Update confidence scores
self.update_confidence(patterns)
// Update confidence scores
this.updateConfidence(patterns);
# Store new knowledge
self.knowledge_base.update(patterns)
// Store new knowledge
this.knowledgeBase.update(patterns);
}
def predict(self, proposed_action):
# Match against known patterns
similar_patterns = self.find_similar(proposed_action)
predict(proposedAction) {
// Match against known patterns
const similarPatterns = this.findSimilar(proposedAction);
# Calculate confidence
confidence = self.calculate_confidence(similar_patterns)
// Calculate confidence
const confidence = this.calculateConfidence(similarPatterns);
# Return prediction
return Prediction(confidence, similar_patterns)
// Return prediction
return new Prediction(confidence, similarPatterns);
}
}
```
The key insight is that the learner doesn't just record what happened - it actively builds predictive models that can guide future decisions.
@ -179,26 +182,29 @@ The key insight is that the learner doesn't just record what happened - it activ
The context monitor implements a resource management pattern, treating Claude's context as a finite resource that must be carefully managed:
```python
class ContextMonitor:
def estimate_usage(self):
# Multiple estimation strategies
estimates = [
self.token_based_estimate(),
self.activity_based_estimate(),
self.time_based_estimate()
]
```javascript
class ContextMonitor {
estimateUsage() {
// Multiple estimation strategies
const estimates = [
this.tokenBasedEstimate(),
this.activityBasedEstimate(),
this.timeBasedEstimate()
];
# Weighted combination
return self.combine_estimates(estimates)
// Weighted combination
return this.combineEstimates(estimates);
}
def should_backup(self):
usage = self.estimate_usage()
shouldBackup() {
const usage = this.estimateUsage();
# Adaptive thresholds based on session complexity
threshold = self.calculate_threshold()
// Adaptive thresholds based on session complexity
const threshold = this.calculateThreshold();
return usage > threshold
return usage > threshold;
}
}
```
This architectural approach means the system can make intelligent decisions about when to intervene, rather than using simple rule-based triggers.
@ -207,25 +213,31 @@ This architectural approach means the system can make intelligent decisions abou
The backup manager implements a strategy pattern, using different backup approaches based on circumstances:
```python
class BackupManager:
def __init__(self):
self.strategies = [
GitBackupStrategy(),
FilesystemBackupStrategy(),
EmergencyBackupStrategy()
]
```javascript
class BackupManager {
constructor() {
this.strategies = [
new GitBackupStrategy(),
new FilesystemBackupStrategy(),
new EmergencyBackupStrategy()
];
}
def execute_backup(self, context):
for strategy in self.strategies:
try:
result = strategy.backup(context)
if result.success:
return result
except Exception:
continue # Try next strategy
async executeBackup(context) {
for (const strategy of this.strategies) {
try {
const result = await strategy.backup(context);
if (result.success) {
return result;
}
} catch (error) {
continue; // Try next strategy
}
}
return self.emergency_backup(context)
return this.emergencyBackup(context);
}
}
```
This ensures that backups almost always succeed, gracefully degrading to simpler approaches when sophisticated methods fail.