Claude hooks auto-backup: manual (backup_20250720_091250)
This commit is contained in:
parent
9445e09c48
commit
392833187e
135 changed files with 16151 additions and 3439 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -55,14 +55,14 @@ Traditional ML models are trained once and deployed. Shadow learners improve inc
|
|||
The shadow learner identifies several types of patterns:
|
||||
|
||||
**Command Patterns**: Which commands tend to succeed or fail in your environment
|
||||
- `pip install` fails 90% of the time → suggest `pip3 install`
|
||||
- `python script.py` fails on your system → suggest `python3 script.py`
|
||||
- `npm install` without `--save` in certain projects → warn about dependency tracking
|
||||
- `npm install` fails 90% of the time → suggest `npm ci` or check package-lock.json
|
||||
- `node script.js` fails on your system → suggest `node --version` check or use `npx`
|
||||
- `npm install` without `--save-dev` for dev dependencies → warn about production vs development packages
|
||||
|
||||
**Sequence Patterns**: Common workflows and command chains
|
||||
- `git add . && git commit` often follows file edits
|
||||
- `npm install` typically precedes `npm test`
|
||||
- Reading config files often precedes configuration changes
|
||||
- Reading package.json often precedes dependency updates
|
||||
|
||||
**Context Patterns**: Environmental factors that affect command success
|
||||
- Commands fail differently in Docker containers vs. native environments
|
||||
|
|
@ -70,9 +70,9 @@ The shadow learner identifies several types of patterns:
|
|||
- Time-of-day patterns (builds failing during peak hours due to resource contention)
|
||||
|
||||
**Error Patterns**: Common failure modes and their solutions
|
||||
- "Permission denied" errors often require sudo or chmod
|
||||
- "Command not found" errors have specific alternative commands
|
||||
- Network timeouts suggest retry strategies
|
||||
- "Permission denied" errors often require sudo or npm config set prefix
|
||||
- "Command not found" errors suggest missing global packages or PATH issues
|
||||
- Network timeouts suggest retry strategies or alternative registries
|
||||
|
||||
### Confidence Building
|
||||
|
||||
|
|
@ -100,8 +100,8 @@ The shadow learner doesn't just record patterns - it builds confidence scores ba
|
|||
|
||||
The shadow learner develops deep knowledge about your specific development environment:
|
||||
|
||||
- Which Python version is actually available
|
||||
- How package managers are configured
|
||||
- Which Node.js version is actually available
|
||||
- How npm/yarn/pnpm package managers are configured
|
||||
- What development tools are installed and working
|
||||
- How permissions are set up
|
||||
- What network restrictions exist
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ This creates a jarring experience: you're deep in a debugging session, making pr
|
|||
|
||||
### The Repetitive Failure Problem
|
||||
|
||||
Human developers naturally learn from mistakes. Try a command that fails, remember not to do it again, adapt. But each new Claude session starts with no memory of previous failures. You find yourself watching Claude repeat the same mistakes - `pip` instead of `pip3`, `python` instead of `python3`, dangerous operations that you know will fail.
|
||||
Human developers naturally learn from mistakes. Try a command that fails, remember not to do it again, adapt. But each new Claude session starts with no memory of previous failures. You find yourself watching Claude repeat the same mistakes - `npm install` instead of `npm ci`, `node` without proper version checks, dangerous operations that you know will fail.
|
||||
|
||||
This isn't Claude's fault - it's a fundamental limitation of the stateless conversation model. But it creates frustration and inefficiency.
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ You might wonder: why not just train Claude to be better at avoiding these probl
|
|||
|
||||
The answer lies in the fundamental difference between general intelligence and environmental adaptation:
|
||||
|
||||
**General intelligence** (what Claude provides) is knowledge that applies across all contexts - how to write Python, how to use git, how to debug problems.
|
||||
**General intelligence** (what Claude provides) is knowledge that applies across all contexts - how to write JavaScript, how to use git, how to debug problems.
|
||||
|
||||
**Environmental adaptation** (what shadow learning provides) is knowledge specific to your setup - which commands work on your system, what your typical workflows are, what mistakes you commonly make.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue