rsi-loop 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rsi_loop/__init__.py +10 -0
- rsi_loop/analyzer.py +203 -0
- rsi_loop/fixer.py +139 -0
- rsi_loop/integrations/__init__.py +1 -0
- rsi_loop/integrations/claude_code.py +105 -0
- rsi_loop/integrations/generic.py +67 -0
- rsi_loop/integrations/webhook.py +62 -0
- rsi_loop/loop.py +71 -0
- rsi_loop/observer.py +122 -0
- rsi_loop/types.py +200 -0
- rsi_loop-0.1.0.dist-info/METADATA +151 -0
- rsi_loop-0.1.0.dist-info/RECORD +14 -0
- rsi_loop-0.1.0.dist-info/WHEEL +4 -0
- rsi_loop-0.1.0.dist-info/licenses/LICENSE +189 -0
rsi_loop/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""RSI Loop — Universal self-improvement loop for AI agents."""
|
|
2
|
+
|
|
3
|
+
from rsi_loop.analyzer import Analyzer
|
|
4
|
+
from rsi_loop.fixer import Fixer
|
|
5
|
+
from rsi_loop.loop import RSILoop
|
|
6
|
+
from rsi_loop.observer import Observer
|
|
7
|
+
from rsi_loop.types import Config, Fix, Outcome, Pattern
|
|
8
|
+
|
|
9
|
+
__version__ = "0.1.0"
|
|
10
|
+
__all__ = ["RSILoop", "Observer", "Analyzer", "Fixer", "Config", "Outcome", "Pattern", "Fix"]
|
rsi_loop/analyzer.py
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"""Analyzer — Detect improvement patterns from recorded outcomes."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from collections import defaultdict
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from rsi_loop.observer import Observer
|
|
10
|
+
from rsi_loop.types import HIGH_SEVERITY_ISSUES, Config, Outcome, Pattern
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Category classification by issue
|
|
14
|
+
_ISSUE_CATEGORIES: dict[str, str] = {
|
|
15
|
+
"skill_gap": "skill_gap", "missing_tool": "skill_gap", "wrong_output": "skill_gap",
|
|
16
|
+
"rate_limit": "model_routing", "model_fallback": "model_routing",
|
|
17
|
+
"wrong_model_tier": "model_routing", "slow_response": "model_routing",
|
|
18
|
+
"context_loss": "memory_continuity", "memory_miss": "memory_continuity",
|
|
19
|
+
"compaction_lost_context": "memory_continuity",
|
|
20
|
+
"repeated_mistake": "behavior_pattern", "over_confirmation": "behavior_pattern",
|
|
21
|
+
"bad_routing": "behavior_pattern",
|
|
22
|
+
"tool_error": "tool_reliability", "timeout": "tool_reliability",
|
|
23
|
+
"empty_response": "tool_reliability",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
# Suggested actions by category
|
|
27
|
+
_CATEGORY_ACTIONS: dict[str, str] = {
|
|
28
|
+
"skill_gap": "Create or improve relevant skill/tool",
|
|
29
|
+
"model_routing": "Update model routing configuration",
|
|
30
|
+
"memory_continuity": "Improve memory and context protocols",
|
|
31
|
+
"behavior_pattern": "Update agent behavior rules",
|
|
32
|
+
"tool_reliability": "Add retry logic or fallback tools",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
# Cross-source correlation pairs
|
|
36
|
+
_CORRELATED_ISSUES: dict[frozenset[str], str] = {
|
|
37
|
+
frozenset({"session_reset", "context_loss"}): "context_management",
|
|
38
|
+
frozenset({"cost_overrun", "wrong_model_tier"}): "model_routing",
|
|
39
|
+
frozenset({"empty_response", "tool_error"}): "tool_reliability",
|
|
40
|
+
frozenset({"hydration_fail", "context_loss"}): "session_recovery",
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class Analyzer:
|
|
45
|
+
"""Detects improvement patterns from recorded outcomes."""
|
|
46
|
+
|
|
47
|
+
def __init__(self, config: Config | None = None, observer: Observer | None = None) -> None:
|
|
48
|
+
self.config = config or Config()
|
|
49
|
+
self.observer = observer or Observer(self.config)
|
|
50
|
+
self._data_dir = Path(self.config.data_dir)
|
|
51
|
+
self._patterns_file = self._data_dir / "patterns.json"
|
|
52
|
+
|
|
53
|
+
def analyze(self, days: int | None = None) -> list[Pattern]:
|
|
54
|
+
"""Scan outcomes and detect patterns. Returns ranked list by impact."""
|
|
55
|
+
window = days or self.config.analysis_window_days
|
|
56
|
+
outcomes = self.observer.load_outcomes(days=window)
|
|
57
|
+
if not outcomes:
|
|
58
|
+
return []
|
|
59
|
+
|
|
60
|
+
patterns: list[Pattern] = []
|
|
61
|
+
total = len(outcomes)
|
|
62
|
+
|
|
63
|
+
# ── Group by (task_type, issue) ────────────────────────────────────────
|
|
64
|
+
groups: dict[tuple[str, str], list[Outcome]] = defaultdict(list)
|
|
65
|
+
for o in outcomes:
|
|
66
|
+
issues = o.issues or ["none"]
|
|
67
|
+
for issue in issues:
|
|
68
|
+
groups[(o.task_type, issue)].append(o)
|
|
69
|
+
|
|
70
|
+
for (task, issue), group in groups.items():
|
|
71
|
+
n = len(group)
|
|
72
|
+
min_threshold = 1 if issue in HIGH_SEVERITY_ISSUES else 2
|
|
73
|
+
if n < min_threshold:
|
|
74
|
+
continue
|
|
75
|
+
|
|
76
|
+
failures = [o for o in group if not o.success]
|
|
77
|
+
failure_rate = len(failures) / n
|
|
78
|
+
avg_quality = sum(o.quality for o in group) / n
|
|
79
|
+
quality_deficit = 5.0 - avg_quality
|
|
80
|
+
impact = (n / total) * quality_deficit
|
|
81
|
+
|
|
82
|
+
category = _ISSUE_CATEGORIES.get(issue, "other")
|
|
83
|
+
action = _CATEGORY_ACTIONS.get(category, "Investigate and address")
|
|
84
|
+
sources = sorted(set(o.source for o in group))
|
|
85
|
+
errors = [o.error_message for o in group if o.error_message][:3]
|
|
86
|
+
timestamps = sorted(o.timestamp for o in group)
|
|
87
|
+
|
|
88
|
+
patterns.append(Pattern(
|
|
89
|
+
id=f"{task[:8]}-{issue[:8]}-{n}",
|
|
90
|
+
category=category,
|
|
91
|
+
task_type=task,
|
|
92
|
+
issue=issue,
|
|
93
|
+
frequency=n,
|
|
94
|
+
impact_score=impact,
|
|
95
|
+
failure_rate=failure_rate,
|
|
96
|
+
description=f"In '{task}' tasks, '{issue}' occurs {n}x "
|
|
97
|
+
f"with {failure_rate:.0%} failure rate",
|
|
98
|
+
sample_errors=errors,
|
|
99
|
+
suggested_action=action,
|
|
100
|
+
sources=sources,
|
|
101
|
+
first_seen=timestamps[0] if timestamps else "",
|
|
102
|
+
last_seen=timestamps[-1] if timestamps else "",
|
|
103
|
+
))
|
|
104
|
+
|
|
105
|
+
# ── Error message clustering ──────────────────────────────────────────
|
|
106
|
+
error_groups: dict[str, list[Outcome]] = defaultdict(list)
|
|
107
|
+
for o in outcomes:
|
|
108
|
+
if o.error_message:
|
|
109
|
+
norm = Observer.normalize_error(o.error_message)
|
|
110
|
+
error_groups[norm].append(o)
|
|
111
|
+
|
|
112
|
+
for norm_err, err_outcomes in error_groups.items():
|
|
113
|
+
if len(err_outcomes) < 2:
|
|
114
|
+
continue
|
|
115
|
+
n = len(err_outcomes)
|
|
116
|
+
failures = [o for o in err_outcomes if not o.success]
|
|
117
|
+
avg_quality = sum(o.quality for o in err_outcomes) / n
|
|
118
|
+
quality_deficit = 5.0 - avg_quality
|
|
119
|
+
impact = (n / total) * quality_deficit
|
|
120
|
+
sources = sorted(set(o.source for o in err_outcomes))
|
|
121
|
+
|
|
122
|
+
patterns.append(Pattern(
|
|
123
|
+
id=f"err-{hash(norm_err) % 99999:05d}-{n}",
|
|
124
|
+
category="error_cluster",
|
|
125
|
+
task_type="mixed",
|
|
126
|
+
issue="error_cluster",
|
|
127
|
+
frequency=n,
|
|
128
|
+
impact_score=impact,
|
|
129
|
+
failure_rate=len(failures) / n,
|
|
130
|
+
description=f"Error cluster ({n}x): {norm_err[:60]}",
|
|
131
|
+
sample_errors=[o.error_message for o in err_outcomes[:3]],
|
|
132
|
+
suggested_action="Investigate common error pattern",
|
|
133
|
+
sources=sources,
|
|
134
|
+
))
|
|
135
|
+
|
|
136
|
+
# ── Recurrence detection ──────────────────────────────────────────────
|
|
137
|
+
prev_patterns = self._load_previous_patterns()
|
|
138
|
+
for p in patterns:
|
|
139
|
+
key = (p.task_type, p.issue)
|
|
140
|
+
if key in prev_patterns:
|
|
141
|
+
p.recurring = True
|
|
142
|
+
prev_freq = prev_patterns[key].get("frequency", 0)
|
|
143
|
+
p.trend = "increasing" if p.frequency > prev_freq else "stable"
|
|
144
|
+
|
|
145
|
+
# Sort by impact
|
|
146
|
+
patterns.sort(key=lambda p: -p.impact_score)
|
|
147
|
+
patterns = patterns[:20]
|
|
148
|
+
|
|
149
|
+
# Save for next cycle's recurrence detection
|
|
150
|
+
self._save_patterns(patterns)
|
|
151
|
+
return patterns
|
|
152
|
+
|
|
153
|
+
def health_score(self, days: int | None = None) -> float:
|
|
154
|
+
"""Compute overall health score: 0.0 (broken) to 1.0 (healthy)."""
|
|
155
|
+
outcomes = self.observer.load_outcomes(days=days or self.config.analysis_window_days)
|
|
156
|
+
if not outcomes:
|
|
157
|
+
return 1.0 # No data = assume healthy
|
|
158
|
+
|
|
159
|
+
total_success = sum(1 for o in outcomes if o.success)
|
|
160
|
+
avg_quality = sum(o.quality for o in outcomes) / len(outcomes)
|
|
161
|
+
return round((total_success / len(outcomes)) * (avg_quality / 5.0), 3)
|
|
162
|
+
|
|
163
|
+
def cross_source_correlations(self, days: int | None = None) -> list[dict]:
|
|
164
|
+
"""Detect correlated issues appearing across different sources."""
|
|
165
|
+
outcomes = self.observer.load_outcomes(days=days or self.config.analysis_window_days)
|
|
166
|
+
issue_sources: dict[str, set[str]] = defaultdict(set)
|
|
167
|
+
for o in outcomes:
|
|
168
|
+
for issue in o.issues:
|
|
169
|
+
issue_sources[issue].add(o.source)
|
|
170
|
+
|
|
171
|
+
active = set(issue_sources.keys())
|
|
172
|
+
correlations = []
|
|
173
|
+
for pair, name in _CORRELATED_ISSUES.items():
|
|
174
|
+
if pair.issubset(active):
|
|
175
|
+
all_sources: set[str] = set()
|
|
176
|
+
for iss in pair:
|
|
177
|
+
all_sources.update(issue_sources[iss])
|
|
178
|
+
if len(all_sources) > 1:
|
|
179
|
+
correlations.append({
|
|
180
|
+
"issues": sorted(pair),
|
|
181
|
+
"correlation": name,
|
|
182
|
+
"sources": sorted(all_sources),
|
|
183
|
+
})
|
|
184
|
+
return correlations
|
|
185
|
+
|
|
186
|
+
def _load_previous_patterns(self) -> dict[tuple[str, str], dict]:
|
|
187
|
+
if not self._patterns_file.exists():
|
|
188
|
+
return {}
|
|
189
|
+
try:
|
|
190
|
+
with open(self._patterns_file) as f:
|
|
191
|
+
data = json.load(f)
|
|
192
|
+
return {
|
|
193
|
+
(p.get("task_type", ""), p.get("issue", "")): p
|
|
194
|
+
for p in data.get("patterns", [])
|
|
195
|
+
}
|
|
196
|
+
except (json.JSONDecodeError, OSError):
|
|
197
|
+
return {}
|
|
198
|
+
|
|
199
|
+
def _save_patterns(self, patterns: list[Pattern]) -> None:
|
|
200
|
+
self._data_dir.mkdir(parents=True, exist_ok=True)
|
|
201
|
+
data = {"patterns": [p.to_dict() for p in patterns]}
|
|
202
|
+
with open(self._patterns_file, "w") as f:
|
|
203
|
+
json.dump(data, f, indent=2)
|
rsi_loop/fixer.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""Fixer — Generate and apply fixes for detected patterns."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from rsi_loop.types import Config, Fix, Pattern
|
|
9
|
+
|
|
10
|
+
# Issue → fix template mapping
|
|
11
|
+
_FIX_TEMPLATES: dict[str, dict[str, str]] = {
|
|
12
|
+
"rate_limit": {
|
|
13
|
+
"type": "retry_logic",
|
|
14
|
+
"description": "Add/increase retry backoff for rate-limited endpoints",
|
|
15
|
+
},
|
|
16
|
+
"model_fallback": {
|
|
17
|
+
"type": "routing_config",
|
|
18
|
+
"description": "Update model fallback chain configuration",
|
|
19
|
+
},
|
|
20
|
+
"wrong_model_tier": {
|
|
21
|
+
"type": "routing_config",
|
|
22
|
+
"description": "Adjust tier classification thresholds",
|
|
23
|
+
},
|
|
24
|
+
"cost_overrun": {
|
|
25
|
+
"type": "routing_config",
|
|
26
|
+
"description": "Lower cost ceiling or adjust model routing",
|
|
27
|
+
},
|
|
28
|
+
"slow_response": {
|
|
29
|
+
"type": "threshold_tuning",
|
|
30
|
+
"description": "Increase timeout thresholds or add circuit breaker",
|
|
31
|
+
},
|
|
32
|
+
"timeout": {
|
|
33
|
+
"type": "threshold_tuning",
|
|
34
|
+
"description": "Increase timeout thresholds or add circuit breaker",
|
|
35
|
+
},
|
|
36
|
+
"empty_response": {
|
|
37
|
+
"type": "retry_logic",
|
|
38
|
+
"description": "Add empty-response detection and retry",
|
|
39
|
+
},
|
|
40
|
+
"session_reset": {
|
|
41
|
+
"type": "investigation",
|
|
42
|
+
"description": "Investigate context management protocols",
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class Fixer:
|
|
48
|
+
"""Generates fix proposals for detected patterns.
|
|
49
|
+
|
|
50
|
+
Safe categories are auto-applicable; everything else produces a proposal
|
|
51
|
+
saved to disk for human review.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(self, config: Config | None = None) -> None:
|
|
55
|
+
self.config = config or Config()
|
|
56
|
+
self._data_dir = Path(self.config.data_dir)
|
|
57
|
+
self._proposals_dir = self._data_dir / "proposals"
|
|
58
|
+
|
|
59
|
+
def propose(self, pattern: Pattern) -> Fix:
|
|
60
|
+
"""Generate a fix proposal for a detected pattern."""
|
|
61
|
+
template = _FIX_TEMPLATES.get(pattern.issue, {})
|
|
62
|
+
fix_type = template.get("type", "investigation")
|
|
63
|
+
description = template.get(
|
|
64
|
+
"description",
|
|
65
|
+
f"Address '{pattern.issue}' in '{pattern.task_type}' tasks",
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
is_safe = fix_type in self.config.safe_categories
|
|
69
|
+
|
|
70
|
+
changes: list[dict[str, str]] = []
|
|
71
|
+
if fix_type == "routing_config":
|
|
72
|
+
changes.append({
|
|
73
|
+
"target": "model routing config",
|
|
74
|
+
"action": "Review and adjust routing thresholds",
|
|
75
|
+
"detail": f"Pattern '{pattern.issue}' suggests routing misconfiguration",
|
|
76
|
+
})
|
|
77
|
+
elif fix_type == "retry_logic":
|
|
78
|
+
changes.append({
|
|
79
|
+
"target": "relevant integration code",
|
|
80
|
+
"action": f"Add retry with backoff for '{pattern.issue}' errors",
|
|
81
|
+
"detail": f"Detected {pattern.frequency}x occurrences",
|
|
82
|
+
})
|
|
83
|
+
elif fix_type == "threshold_tuning":
|
|
84
|
+
changes.append({
|
|
85
|
+
"target": "relevant config",
|
|
86
|
+
"action": f"Adjust thresholds to reduce '{pattern.issue}'",
|
|
87
|
+
"detail": f"Current failure rate: {pattern.failure_rate:.0%}",
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
return Fix(
|
|
91
|
+
pattern_id=pattern.id,
|
|
92
|
+
type="auto" if is_safe else "manual",
|
|
93
|
+
status="proposed" if is_safe else "draft",
|
|
94
|
+
target=changes[0]["target"] if changes else "",
|
|
95
|
+
changes=changes,
|
|
96
|
+
safe_category=fix_type if is_safe else "",
|
|
97
|
+
description=description,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def apply_if_safe(self, fix: Fix) -> bool:
|
|
101
|
+
"""Auto-apply if the fix is in a safe category. Returns True if applied.
|
|
102
|
+
|
|
103
|
+
Note: Even "safe" fixes only get their status updated and saved as a
|
|
104
|
+
proposal. Actual code/config changes require agent-specific implementation.
|
|
105
|
+
"""
|
|
106
|
+
if fix.safe_category and fix.safe_category in self.config.safe_categories:
|
|
107
|
+
fix.status = "applied"
|
|
108
|
+
self._save_proposal(fix)
|
|
109
|
+
return True
|
|
110
|
+
|
|
111
|
+
fix.status = "draft"
|
|
112
|
+
self._save_proposal(fix)
|
|
113
|
+
return False
|
|
114
|
+
|
|
115
|
+
def propose_and_apply(self, pattern: Pattern) -> Fix:
|
|
116
|
+
"""Convenience: propose a fix and auto-apply if safe."""
|
|
117
|
+
fix = self.propose(pattern)
|
|
118
|
+
self.apply_if_safe(fix)
|
|
119
|
+
return fix
|
|
120
|
+
|
|
121
|
+
def load_proposals(self) -> list[Fix]:
|
|
122
|
+
"""Load all saved fix proposals."""
|
|
123
|
+
if not self._proposals_dir.exists():
|
|
124
|
+
return []
|
|
125
|
+
proposals: list[Fix] = []
|
|
126
|
+
for path in sorted(self._proposals_dir.glob("*.json")):
|
|
127
|
+
try:
|
|
128
|
+
with open(path) as f:
|
|
129
|
+
proposals.append(Fix.from_dict(json.load(f)))
|
|
130
|
+
except (json.JSONDecodeError, OSError):
|
|
131
|
+
continue
|
|
132
|
+
return proposals
|
|
133
|
+
|
|
134
|
+
def _save_proposal(self, fix: Fix) -> Path:
|
|
135
|
+
self._proposals_dir.mkdir(parents=True, exist_ok=True)
|
|
136
|
+
path = self._proposals_dir / f"{fix.id}.json"
|
|
137
|
+
with open(path, "w") as f:
|
|
138
|
+
json.dump(fix.to_dict(), f, indent=2)
|
|
139
|
+
return path
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""RSI Loop integrations for various agent frameworks."""
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""Claude Code / OpenClaw adapter for RSI Loop."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from rsi_loop.loop import RSILoop
|
|
6
|
+
from rsi_loop.types import Config, Outcome
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ClaudeCodeAdapter:
|
|
10
|
+
"""Wraps RSI Loop for Claude Code and OpenClaw agents.
|
|
11
|
+
|
|
12
|
+
Provides high-level methods matching common agent lifecycle events:
|
|
13
|
+
task completion, session resets, model fallbacks, etc.
|
|
14
|
+
|
|
15
|
+
Usage::
|
|
16
|
+
|
|
17
|
+
adapter = ClaudeCodeAdapter(data_dir="./rsi_data")
|
|
18
|
+
adapter.on_task_complete("code_review", success=True, model="sonnet-4.6")
|
|
19
|
+
adapter.on_model_fallback("opus-4", "sonnet-4.6", "rate_limit")
|
|
20
|
+
adapter.on_session_reset()
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(self, data_dir: str = "./rsi_data", **config_kwargs) -> None:
|
|
24
|
+
self.loop = RSILoop(Config(data_dir=data_dir, **config_kwargs))
|
|
25
|
+
|
|
26
|
+
def on_task_complete(
|
|
27
|
+
self,
|
|
28
|
+
task: str,
|
|
29
|
+
success: bool = True,
|
|
30
|
+
error: str | None = None,
|
|
31
|
+
model: str | None = None,
|
|
32
|
+
duration_ms: int | None = None,
|
|
33
|
+
quality: int = 3,
|
|
34
|
+
notes: str = "",
|
|
35
|
+
) -> Outcome:
|
|
36
|
+
"""Record a completed task outcome."""
|
|
37
|
+
return self.loop.observer.record_simple(
|
|
38
|
+
task=task,
|
|
39
|
+
success=success,
|
|
40
|
+
error=error,
|
|
41
|
+
model=model,
|
|
42
|
+
duration_ms=duration_ms,
|
|
43
|
+
quality=quality,
|
|
44
|
+
source="openclaw",
|
|
45
|
+
notes=notes,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
def on_session_reset(self, notes: str = "") -> Outcome:
|
|
49
|
+
"""Record a session reset event."""
|
|
50
|
+
return self.loop.observer.record_simple(
|
|
51
|
+
task="session_management",
|
|
52
|
+
success=False,
|
|
53
|
+
error="Session reset — context lost",
|
|
54
|
+
source="openclaw",
|
|
55
|
+
quality=1,
|
|
56
|
+
notes=notes,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
def on_model_fallback(
|
|
60
|
+
self,
|
|
61
|
+
from_model: str,
|
|
62
|
+
to_model: str,
|
|
63
|
+
reason: str = "unavailable",
|
|
64
|
+
) -> Outcome:
|
|
65
|
+
"""Record a model fallback event."""
|
|
66
|
+
return self.loop.observer.record_simple(
|
|
67
|
+
task="model_routing",
|
|
68
|
+
success=True,
|
|
69
|
+
error=f"Model fallback: {from_model} → {to_model} ({reason})",
|
|
70
|
+
model=to_model,
|
|
71
|
+
source="openclaw",
|
|
72
|
+
quality=2,
|
|
73
|
+
notes=f"Fell back from {from_model} to {to_model}: {reason}",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
def on_cron_failure(self, job_name: str, error: str) -> Outcome:
|
|
77
|
+
"""Record a cron job failure."""
|
|
78
|
+
return self.loop.observer.record_simple(
|
|
79
|
+
task="cron_management",
|
|
80
|
+
success=False,
|
|
81
|
+
error=error,
|
|
82
|
+
source="openclaw",
|
|
83
|
+
quality=1,
|
|
84
|
+
notes=f"Cron job '{job_name}' failed",
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def on_subagent_failure(self, label: str, error: str, model: str = "") -> Outcome:
|
|
88
|
+
"""Record a sub-agent failure."""
|
|
89
|
+
return self.loop.observer.record_simple(
|
|
90
|
+
task="subagent_management",
|
|
91
|
+
success=False,
|
|
92
|
+
error=error,
|
|
93
|
+
model=model,
|
|
94
|
+
source="openclaw",
|
|
95
|
+
quality=1,
|
|
96
|
+
notes=f"Sub-agent '{label}' failed",
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
def run_cycle(self):
|
|
100
|
+
"""Run an improvement cycle."""
|
|
101
|
+
return self.loop.run_cycle()
|
|
102
|
+
|
|
103
|
+
def health_score(self) -> float:
|
|
104
|
+
"""Get current health score."""
|
|
105
|
+
return self.loop.health_score()
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Generic file-based adapter — works with any agent."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from rsi_loop.loop import RSILoop
|
|
9
|
+
from rsi_loop.types import Config, Outcome
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class GenericAdapter:
|
|
13
|
+
"""File-based adapter. Drop JSON files into a watch directory and RSI picks them up.
|
|
14
|
+
|
|
15
|
+
Any agent can write a JSON file like::
|
|
16
|
+
|
|
17
|
+
{"task": "search", "success": false, "error": "timeout after 30s"}
|
|
18
|
+
|
|
19
|
+
Then call ``adapter.poll()`` to ingest new files.
|
|
20
|
+
|
|
21
|
+
Usage::
|
|
22
|
+
|
|
23
|
+
adapter = GenericAdapter(watch_dir="./rsi_inbox")
|
|
24
|
+
# Agent drops JSON files into ./rsi_inbox/
|
|
25
|
+
outcomes = adapter.poll()
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
watch_dir: str = "./rsi_inbox",
|
|
31
|
+
data_dir: str = "./rsi_data",
|
|
32
|
+
**config_kwargs,
|
|
33
|
+
) -> None:
|
|
34
|
+
self._watch_dir = Path(watch_dir)
|
|
35
|
+
self.loop = RSILoop(Config(data_dir=data_dir, **config_kwargs))
|
|
36
|
+
self._processed_dir = self._watch_dir / ".processed"
|
|
37
|
+
|
|
38
|
+
def poll(self) -> list[Outcome]:
|
|
39
|
+
"""Scan watch_dir for new JSON files, ingest them, move to .processed/."""
|
|
40
|
+
if not self._watch_dir.exists():
|
|
41
|
+
return []
|
|
42
|
+
|
|
43
|
+
self._processed_dir.mkdir(parents=True, exist_ok=True)
|
|
44
|
+
outcomes: list[Outcome] = []
|
|
45
|
+
|
|
46
|
+
for path in sorted(self._watch_dir.glob("*.json")):
|
|
47
|
+
if path.name.startswith("."):
|
|
48
|
+
continue
|
|
49
|
+
try:
|
|
50
|
+
with open(path) as f:
|
|
51
|
+
data = json.load(f)
|
|
52
|
+
outcome = Outcome.from_dict(data)
|
|
53
|
+
self.loop.observer.record(outcome)
|
|
54
|
+
outcomes.append(outcome)
|
|
55
|
+
path.rename(self._processed_dir / path.name)
|
|
56
|
+
except (json.JSONDecodeError, OSError):
|
|
57
|
+
continue
|
|
58
|
+
|
|
59
|
+
return outcomes
|
|
60
|
+
|
|
61
|
+
def run_cycle(self):
|
|
62
|
+
"""Poll + analyze + fix."""
|
|
63
|
+
self.poll()
|
|
64
|
+
return self.loop.run_cycle()
|
|
65
|
+
|
|
66
|
+
def health_score(self) -> float:
|
|
67
|
+
return self.loop.health_score()
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""HTTP webhook adapter — POST outcomes to RSI Loop."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from rsi_loop.loop import RSILoop
|
|
6
|
+
from rsi_loop.types import Config, Outcome
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class WebhookAdapter:
|
|
10
|
+
"""HTTP endpoint adapter for RSI Loop.
|
|
11
|
+
|
|
12
|
+
Creates a Flask app with endpoints::
|
|
13
|
+
|
|
14
|
+
POST /observe — Record an outcome (JSON body)
|
|
15
|
+
GET /health — Get current health score
|
|
16
|
+
GET /patterns — Get detected patterns
|
|
17
|
+
|
|
18
|
+
Usage::
|
|
19
|
+
|
|
20
|
+
from rsi_loop.integrations.webhook import WebhookAdapter
|
|
21
|
+
app = WebhookAdapter(data_dir="./rsi_data").create_app()
|
|
22
|
+
app.run(port=8900)
|
|
23
|
+
|
|
24
|
+
Requires ``flask`` (install with ``uv add rsi-loop[webhook]``).
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, data_dir: str = "./rsi_data", **config_kwargs) -> None:
|
|
28
|
+
self.loop = RSILoop(Config(data_dir=data_dir, **config_kwargs))
|
|
29
|
+
|
|
30
|
+
def create_app(self):
|
|
31
|
+
"""Create and return a Flask app with RSI Loop endpoints."""
|
|
32
|
+
try:
|
|
33
|
+
from flask import Flask, jsonify, request
|
|
34
|
+
except ImportError:
|
|
35
|
+
raise ImportError(
|
|
36
|
+
"Flask is required for the webhook adapter. "
|
|
37
|
+
"Install with: uv add rsi-loop[webhook]"
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
app = Flask("rsi_loop_webhook")
|
|
41
|
+
|
|
42
|
+
@app.post("/observe")
|
|
43
|
+
def observe():
|
|
44
|
+
data = request.get_json(force=True)
|
|
45
|
+
outcome = Outcome.from_dict(data)
|
|
46
|
+
recorded = self.loop.observer.record(outcome)
|
|
47
|
+
return jsonify({"id": recorded.id, "issues": recorded.issues}), 201
|
|
48
|
+
|
|
49
|
+
@app.get("/health")
|
|
50
|
+
def health():
|
|
51
|
+
score = self.loop.health_score()
|
|
52
|
+
return jsonify({"health_score": score})
|
|
53
|
+
|
|
54
|
+
@app.get("/patterns")
|
|
55
|
+
def patterns():
|
|
56
|
+
pats = self.loop.run_cycle()
|
|
57
|
+
return jsonify({
|
|
58
|
+
"health_score": self.loop.health_score(),
|
|
59
|
+
"patterns": [p.to_dict() for p in pats],
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
return app
|
rsi_loop/loop.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""RSILoop — The main recursive self-improvement loop."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import threading
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
from rsi_loop.analyzer import Analyzer
|
|
9
|
+
from rsi_loop.fixer import Fixer
|
|
10
|
+
from rsi_loop.observer import Observer
|
|
11
|
+
from rsi_loop.types import Config, Fix, Pattern
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class RSILoop:
|
|
15
|
+
"""Universal self-improvement loop: observe → analyze → fix → verify.
|
|
16
|
+
|
|
17
|
+
Usage::
|
|
18
|
+
|
|
19
|
+
loop = RSILoop()
|
|
20
|
+
loop.observer.record_simple("code_gen", success=True, model="sonnet-4.6")
|
|
21
|
+
patterns = loop.run_cycle()
|
|
22
|
+
print(loop.health_score())
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(self, config: Config | None = None) -> None:
|
|
26
|
+
self.config = config or Config()
|
|
27
|
+
self.observer = Observer(self.config)
|
|
28
|
+
self.analyzer = Analyzer(self.config, observer=self.observer)
|
|
29
|
+
self.fixer = Fixer(self.config)
|
|
30
|
+
self._background_thread: threading.Thread | None = None
|
|
31
|
+
self._stop_event = threading.Event()
|
|
32
|
+
|
|
33
|
+
def run_cycle(self) -> list[Pattern]:
|
|
34
|
+
"""Run one observe → analyze → fix cycle. Returns detected patterns."""
|
|
35
|
+
patterns = self.analyzer.analyze()
|
|
36
|
+
for pattern in patterns:
|
|
37
|
+
self.fixer.propose_and_apply(pattern)
|
|
38
|
+
return patterns
|
|
39
|
+
|
|
40
|
+
def health_score(self) -> float:
|
|
41
|
+
"""Current health score: 0.0 (broken) to 1.0 (healthy)."""
|
|
42
|
+
return self.analyzer.health_score()
|
|
43
|
+
|
|
44
|
+
def patterns(self) -> list[Pattern]:
|
|
45
|
+
"""Run analysis and return current patterns."""
|
|
46
|
+
return self.analyzer.analyze()
|
|
47
|
+
|
|
48
|
+
def fixes(self) -> list[Fix]:
|
|
49
|
+
"""Return all saved fix proposals."""
|
|
50
|
+
return self.fixer.load_proposals()
|
|
51
|
+
|
|
52
|
+
def start_background(self, interval_seconds: int = 3600) -> None:
|
|
53
|
+
"""Start the improvement loop in a background thread."""
|
|
54
|
+
if self._background_thread and self._background_thread.is_alive():
|
|
55
|
+
return
|
|
56
|
+
self._stop_event.clear()
|
|
57
|
+
|
|
58
|
+
def _loop() -> None:
|
|
59
|
+
while not self._stop_event.is_set():
|
|
60
|
+
self.run_cycle()
|
|
61
|
+
self._stop_event.wait(timeout=interval_seconds)
|
|
62
|
+
|
|
63
|
+
self._background_thread = threading.Thread(target=_loop, daemon=True)
|
|
64
|
+
self._background_thread.start()
|
|
65
|
+
|
|
66
|
+
def stop_background(self) -> None:
|
|
67
|
+
"""Stop the background loop."""
|
|
68
|
+
self._stop_event.set()
|
|
69
|
+
if self._background_thread:
|
|
70
|
+
self._background_thread.join(timeout=5)
|
|
71
|
+
self._background_thread = None
|
rsi_loop/observer.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Observer — Record task outcomes and auto-classify issues."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from rsi_loop.types import ERROR_CLASSIFIERS, Config, Outcome
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Observer:
|
|
13
|
+
"""Records agent task outcomes to a JSONL store.
|
|
14
|
+
|
|
15
|
+
Framework-agnostic: works with any agent that can call ``record()``
|
|
16
|
+
or ``record_simple()`` after each task.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, config: Config | None = None) -> None:
|
|
20
|
+
self.config = config or Config()
|
|
21
|
+
self._data_dir = Path(self.config.data_dir)
|
|
22
|
+
self._outcomes_file = self._data_dir / "outcomes.jsonl"
|
|
23
|
+
|
|
24
|
+
def record(self, outcome: Outcome) -> Outcome:
|
|
25
|
+
"""Record a full Outcome object. Auto-classifies issues from error_message."""
|
|
26
|
+
if outcome.error_message and not outcome.issues:
|
|
27
|
+
outcome.issues = self._classify_error(outcome.error_message)
|
|
28
|
+
outcome.quality = max(1, min(5, outcome.quality))
|
|
29
|
+
|
|
30
|
+
self._data_dir.mkdir(parents=True, exist_ok=True)
|
|
31
|
+
with open(self._outcomes_file, "a") as f:
|
|
32
|
+
f.write(json.dumps(outcome.to_dict()) + "\n")
|
|
33
|
+
return outcome
|
|
34
|
+
|
|
35
|
+
def record_simple(
|
|
36
|
+
self,
|
|
37
|
+
task: str,
|
|
38
|
+
success: bool = True,
|
|
39
|
+
error: str | None = None,
|
|
40
|
+
model: str | None = None,
|
|
41
|
+
duration_ms: int | None = None,
|
|
42
|
+
quality: int = 3,
|
|
43
|
+
source: str = "generic",
|
|
44
|
+
tags: list[str] | None = None,
|
|
45
|
+
notes: str = "",
|
|
46
|
+
) -> Outcome:
|
|
47
|
+
"""Convenience method — record an outcome with minimal arguments."""
|
|
48
|
+
issues: list[str] = []
|
|
49
|
+
if error:
|
|
50
|
+
issues = self._classify_error(error)
|
|
51
|
+
if not success and not issues:
|
|
52
|
+
issues = ["other"]
|
|
53
|
+
|
|
54
|
+
outcome = Outcome(
|
|
55
|
+
source=source,
|
|
56
|
+
task_type=task,
|
|
57
|
+
success=success,
|
|
58
|
+
quality=quality if success else min(quality, 2),
|
|
59
|
+
issues=issues,
|
|
60
|
+
error_message=error or "",
|
|
61
|
+
model=model or "",
|
|
62
|
+
duration_ms=duration_ms or 0,
|
|
63
|
+
notes=notes,
|
|
64
|
+
tags=tags or [],
|
|
65
|
+
)
|
|
66
|
+
return self.record(outcome)
|
|
67
|
+
|
|
68
|
+
def load_outcomes(self, days: int | None = None) -> list[Outcome]:
|
|
69
|
+
"""Load outcomes from the JSONL store, optionally filtered by recency."""
|
|
70
|
+
if not self._outcomes_file.exists():
|
|
71
|
+
return []
|
|
72
|
+
|
|
73
|
+
import time
|
|
74
|
+
from datetime import datetime
|
|
75
|
+
|
|
76
|
+
cutoff = time.time() - ((days or self.config.analysis_window_days) * 86400)
|
|
77
|
+
outcomes: list[Outcome] = []
|
|
78
|
+
|
|
79
|
+
with open(self._outcomes_file) as f:
|
|
80
|
+
for line in f:
|
|
81
|
+
line = line.strip()
|
|
82
|
+
if not line:
|
|
83
|
+
continue
|
|
84
|
+
try:
|
|
85
|
+
data = json.loads(line)
|
|
86
|
+
ts_str = data.get("ts", data.get("timestamp", ""))
|
|
87
|
+
if ts_str:
|
|
88
|
+
ts = datetime.fromisoformat(ts_str).timestamp()
|
|
89
|
+
if ts < cutoff:
|
|
90
|
+
continue
|
|
91
|
+
outcomes.append(Outcome.from_dict(data))
|
|
92
|
+
except (json.JSONDecodeError, ValueError):
|
|
93
|
+
continue
|
|
94
|
+
return outcomes
|
|
95
|
+
|
|
96
|
+
def recurrences(self, threshold: int | None = None) -> dict[str, int]:
|
|
97
|
+
"""Return issues that recur >= threshold times in the analysis window."""
|
|
98
|
+
thresh = threshold or self.config.recurrence_threshold
|
|
99
|
+
outcomes = self.load_outcomes()
|
|
100
|
+
counts: dict[str, int] = {}
|
|
101
|
+
for o in outcomes:
|
|
102
|
+
for issue in o.issues:
|
|
103
|
+
counts[issue] = counts.get(issue, 0) + 1
|
|
104
|
+
return {issue: count for issue, count in counts.items() if count >= thresh}
|
|
105
|
+
|
|
106
|
+
@staticmethod
|
|
107
|
+
def _classify_error(error: str) -> list[str]:
|
|
108
|
+
"""Auto-classify an error message into issue types."""
|
|
109
|
+
lower = error.lower()
|
|
110
|
+
issues: list[str] = []
|
|
111
|
+
for keywords, issue_type in ERROR_CLASSIFIERS:
|
|
112
|
+
if any(kw in lower for kw in keywords):
|
|
113
|
+
issues.append(issue_type)
|
|
114
|
+
return issues or ["other"]
|
|
115
|
+
|
|
116
|
+
@staticmethod
|
|
117
|
+
def normalize_error(error: str) -> str:
|
|
118
|
+
"""Normalize an error message for clustering (strip IDs, numbers)."""
|
|
119
|
+
normalized = error.lower().strip()
|
|
120
|
+
normalized = re.sub(r"[0-9a-f]{8,}", "<ID>", normalized)
|
|
121
|
+
normalized = re.sub(r"\d+", "<N>", normalized)
|
|
122
|
+
return normalized[:120]
|
rsi_loop/types.py
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"""Core data types for RSI Loop."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import uuid
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from datetime import datetime, timezone
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _utcnow() -> str:
|
|
12
|
+
return datetime.now(timezone.utc).isoformat()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _short_id() -> str:
|
|
16
|
+
return str(uuid.uuid4())[:8]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# ── Issue taxonomy ─────────────────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
ISSUE_TYPES: set[str] = {
|
|
22
|
+
# Model / routing
|
|
23
|
+
"rate_limit", "model_fallback", "wrong_model_tier", "cost_overrun",
|
|
24
|
+
"bad_routing", "slow_response",
|
|
25
|
+
# Tool / execution
|
|
26
|
+
"tool_error", "empty_response", "missing_tool", "incomplete_task",
|
|
27
|
+
# Output quality
|
|
28
|
+
"wrong_output",
|
|
29
|
+
# Memory / context
|
|
30
|
+
"context_loss", "memory_miss", "compaction_lost_context", "session_reset",
|
|
31
|
+
"hydration_fail",
|
|
32
|
+
# Self-governance
|
|
33
|
+
"over_confirmation", "repeated_mistake", "skill_gap", "wal_miss",
|
|
34
|
+
# Timeout
|
|
35
|
+
"timeout",
|
|
36
|
+
# Catch-all
|
|
37
|
+
"other",
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
HIGH_SEVERITY_ISSUES: set[str] = {
|
|
41
|
+
"tool_error", "wrong_output", "empty_response",
|
|
42
|
+
"session_reset", "cost_overrun", "wal_miss",
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# ── Error keyword → issue mapping for auto-classification ─────────────────────
|
|
46
|
+
|
|
47
|
+
ERROR_CLASSIFIERS: list[tuple[list[str], str]] = [
|
|
48
|
+
(["rate limit", "429", "too many requests", "quota exceeded"], "rate_limit"),
|
|
49
|
+
(["timeout", "timed out", "deadline exceeded"], "timeout"),
|
|
50
|
+
(["empty response", "empty reply", "no output", "null response"], "empty_response"),
|
|
51
|
+
(["context length", "token limit", "context window", "too long"], "context_loss"),
|
|
52
|
+
(["session reset", "session expired", "compaction"], "session_reset"),
|
|
53
|
+
(["model unavailable", "model not found", "fallback"], "model_fallback"),
|
|
54
|
+
(["permission denied", "unauthorized", "forbidden", "403"], "tool_error"),
|
|
55
|
+
(["not found", "404", "missing"], "missing_tool"),
|
|
56
|
+
(["connection refused", "connection reset", "network error"], "tool_error"),
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@dataclass
|
|
61
|
+
class Outcome:
|
|
62
|
+
"""A single task outcome recorded by an agent."""
|
|
63
|
+
|
|
64
|
+
id: str = field(default_factory=_short_id)
|
|
65
|
+
timestamp: str = field(default_factory=_utcnow)
|
|
66
|
+
source: str = "generic"
|
|
67
|
+
task_type: str = "unknown"
|
|
68
|
+
success: bool = True
|
|
69
|
+
quality: int = 3 # 1-5
|
|
70
|
+
issues: list[str] = field(default_factory=list)
|
|
71
|
+
error_message: str = ""
|
|
72
|
+
model: str = ""
|
|
73
|
+
duration_ms: int = 0
|
|
74
|
+
notes: str = ""
|
|
75
|
+
tags: list[str] = field(default_factory=list)
|
|
76
|
+
metadata: dict[str, Any] = field(default_factory=dict)
|
|
77
|
+
|
|
78
|
+
def to_dict(self) -> dict[str, Any]:
|
|
79
|
+
return {
|
|
80
|
+
"id": self.id,
|
|
81
|
+
"ts": self.timestamp,
|
|
82
|
+
"source": self.source,
|
|
83
|
+
"task_type": self.task_type,
|
|
84
|
+
"success": self.success,
|
|
85
|
+
"quality": max(1, min(5, self.quality)),
|
|
86
|
+
"issues": self.issues,
|
|
87
|
+
"error_message": self.error_message,
|
|
88
|
+
"model": self.model,
|
|
89
|
+
"duration_ms": self.duration_ms,
|
|
90
|
+
"notes": self.notes,
|
|
91
|
+
"tags": self.tags,
|
|
92
|
+
"metadata": self.metadata,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@classmethod
|
|
96
|
+
def from_dict(cls, data: dict[str, Any]) -> Outcome:
|
|
97
|
+
return cls(
|
|
98
|
+
id=data.get("id", _short_id()),
|
|
99
|
+
timestamp=data.get("ts", data.get("timestamp", _utcnow())),
|
|
100
|
+
source=data.get("source", "generic"),
|
|
101
|
+
task_type=data.get("task_type", data.get("task", "unknown")),
|
|
102
|
+
success=data.get("success", True),
|
|
103
|
+
quality=data.get("quality", 3),
|
|
104
|
+
issues=data.get("issues", []),
|
|
105
|
+
error_message=data.get("error_message", data.get("error_msg", data.get("error", ""))),
|
|
106
|
+
model=data.get("model", ""),
|
|
107
|
+
duration_ms=data.get("duration_ms", 0),
|
|
108
|
+
notes=data.get("notes", ""),
|
|
109
|
+
tags=data.get("tags", []),
|
|
110
|
+
metadata=data.get("metadata", {}),
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@dataclass
|
|
115
|
+
class Pattern:
|
|
116
|
+
"""A detected improvement pattern from analyzed outcomes."""
|
|
117
|
+
|
|
118
|
+
id: str = field(default_factory=_short_id)
|
|
119
|
+
category: str = "other"
|
|
120
|
+
task_type: str = "unknown"
|
|
121
|
+
issue: str = "other"
|
|
122
|
+
frequency: int = 0
|
|
123
|
+
impact_score: float = 0.0
|
|
124
|
+
failure_rate: float = 0.0
|
|
125
|
+
description: str = ""
|
|
126
|
+
sample_errors: list[str] = field(default_factory=list)
|
|
127
|
+
suggested_action: str = ""
|
|
128
|
+
sources: list[str] = field(default_factory=list)
|
|
129
|
+
first_seen: str = field(default_factory=_utcnow)
|
|
130
|
+
last_seen: str = field(default_factory=_utcnow)
|
|
131
|
+
recurring: bool = False
|
|
132
|
+
trend: str = "new" # new, stable, increasing, decreasing
|
|
133
|
+
|
|
134
|
+
def to_dict(self) -> dict[str, Any]:
|
|
135
|
+
return {
|
|
136
|
+
"id": self.id,
|
|
137
|
+
"category": self.category,
|
|
138
|
+
"task_type": self.task_type,
|
|
139
|
+
"issue": self.issue,
|
|
140
|
+
"frequency": self.frequency,
|
|
141
|
+
"impact_score": round(self.impact_score, 4),
|
|
142
|
+
"failure_rate": round(self.failure_rate, 3),
|
|
143
|
+
"description": self.description,
|
|
144
|
+
"sample_errors": self.sample_errors,
|
|
145
|
+
"suggested_action": self.suggested_action,
|
|
146
|
+
"sources": self.sources,
|
|
147
|
+
"first_seen": self.first_seen,
|
|
148
|
+
"last_seen": self.last_seen,
|
|
149
|
+
"recurring": self.recurring,
|
|
150
|
+
"trend": self.trend,
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@classmethod
|
|
154
|
+
def from_dict(cls, data: dict[str, Any]) -> Pattern:
|
|
155
|
+
return cls(**{k: v for k, v in data.items() if k in cls.__dataclass_fields__})
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@dataclass
|
|
159
|
+
class Fix:
|
|
160
|
+
"""A fix proposal or applied fix for a detected pattern."""
|
|
161
|
+
|
|
162
|
+
id: str = field(default_factory=_short_id)
|
|
163
|
+
pattern_id: str = ""
|
|
164
|
+
type: str = "manual" # auto or manual
|
|
165
|
+
status: str = "draft" # draft, proposed, applied, rejected
|
|
166
|
+
target: str = "" # what to fix (file, config, etc.)
|
|
167
|
+
changes: list[dict[str, str]] = field(default_factory=list)
|
|
168
|
+
safe_category: str = ""
|
|
169
|
+
description: str = ""
|
|
170
|
+
created_at: str = field(default_factory=_utcnow)
|
|
171
|
+
|
|
172
|
+
def to_dict(self) -> dict[str, Any]:
|
|
173
|
+
return {
|
|
174
|
+
"id": self.id,
|
|
175
|
+
"pattern_id": self.pattern_id,
|
|
176
|
+
"type": self.type,
|
|
177
|
+
"status": self.status,
|
|
178
|
+
"target": self.target,
|
|
179
|
+
"changes": self.changes,
|
|
180
|
+
"safe_category": self.safe_category,
|
|
181
|
+
"description": self.description,
|
|
182
|
+
"created_at": self.created_at,
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
@classmethod
|
|
186
|
+
def from_dict(cls, data: dict[str, Any]) -> Fix:
|
|
187
|
+
return cls(**{k: v for k, v in data.items() if k in cls.__dataclass_fields__})
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
@dataclass
|
|
191
|
+
class Config:
|
|
192
|
+
"""Configuration for RSI Loop."""
|
|
193
|
+
|
|
194
|
+
data_dir: str = "./rsi_data"
|
|
195
|
+
analysis_window_days: int = 7
|
|
196
|
+
recurrence_threshold: int = 3
|
|
197
|
+
auto_fix_enabled: bool = True
|
|
198
|
+
safe_categories: list[str] = field(
|
|
199
|
+
default_factory=lambda: ["routing_config", "threshold_tuning", "retry_logic"]
|
|
200
|
+
)
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rsi-loop
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Universal self-improvement loop for AI agents. Observe → Analyze → Fix → Verify.
|
|
5
|
+
Project-URL: Homepage, https://github.com/clawinfra/rsi-loop
|
|
6
|
+
Project-URL: Repository, https://github.com/clawinfra/rsi-loop
|
|
7
|
+
Project-URL: Issues, https://github.com/clawinfra/rsi-loop/issues
|
|
8
|
+
Author-email: ClawInfra <alex.chen31337@gmail.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agents,ai,feedback-loop,rsi,self-improvement
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
23
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
24
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
25
|
+
Provides-Extra: webhook
|
|
26
|
+
Requires-Dist: flask>=3.0; extra == 'webhook'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# 🔄 RSI Loop
|
|
30
|
+
|
|
31
|
+
[](https://github.com/clawinfra/rsi-loop/actions/workflows/ci.yml)
|
|
32
|
+
[](LICENSE)
|
|
33
|
+
[](https://python.org)
|
|
34
|
+
|
|
35
|
+
**Every AI agent makes mistakes. RSI Loop makes them learn.**
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## The Problem
|
|
40
|
+
|
|
41
|
+
AI agents repeat the same failures. They hit rate limits, return empty responses, lose context, pick the wrong model — and do it all again next session. There's no feedback loop. No memory of what went wrong. No automatic improvement.
|
|
42
|
+
|
|
43
|
+
RSI Loop is the missing primitive: a universal **recursive self-improvement** loop that works with *any* agent framework.
|
|
44
|
+
|
|
45
|
+
## How It Works
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
|
|
49
|
+
│ OBSERVE │────▶│ ANALYZE │────▶│ FIX │────▶│ VERIFY │
|
|
50
|
+
│ │ │ │ │ │ │ │
|
|
51
|
+
│ Record │ │ Detect │ │ Generate │ │ Check │
|
|
52
|
+
│ outcomes │ │ patterns │ │ & apply │ │ health │
|
|
53
|
+
└──────────┘ └──────────┘ └──────────┘ └────┬─────┘
|
|
54
|
+
▲ │
|
|
55
|
+
└───────────────────────────────────────────────────┘
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
1. **Observe** — Record task outcomes: success/failure, quality, errors, model used, duration
|
|
59
|
+
2. **Analyze** — Detect patterns: recurring failures, error clusters, cross-source correlations
|
|
60
|
+
3. **Fix** — Auto-fix safe categories (routing, retries, thresholds); propose fixes for the rest
|
|
61
|
+
4. **Verify** — Track health score over time; confirm fixes reduced failure rates
|
|
62
|
+
|
|
63
|
+
## Quick Start
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
uv add rsi-loop
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
> **Not using uv?** `uv add rsi-loop` works too.
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from rsi_loop import RSILoop
|
|
73
|
+
|
|
74
|
+
loop = RSILoop()
|
|
75
|
+
loop.observer.record_simple("code_generation", success=True, model="sonnet-4.6")
|
|
76
|
+
loop.observer.record_simple("api_call", success=False, error="429 Too Many Requests")
|
|
77
|
+
loop.observer.record_simple("api_call", success=False, error="429 Too Many Requests")
|
|
78
|
+
loop.observer.record_simple("api_call", success=False, error="429 Too Many Requests")
|
|
79
|
+
|
|
80
|
+
# Run improvement cycle
|
|
81
|
+
patterns = loop.run_cycle()
|
|
82
|
+
print(f"Health: {loop.health_score():.0%}")
|
|
83
|
+
print(f"Patterns found: {len(patterns)}")
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Framework Integrations
|
|
87
|
+
|
|
88
|
+
### Claude Code / OpenClaw
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from rsi_loop.integrations.claude_code import ClaudeCodeAdapter
|
|
92
|
+
|
|
93
|
+
adapter = ClaudeCodeAdapter(data_dir="./rsi_data")
|
|
94
|
+
adapter.on_task_complete("code_review", success=True, model="claude-sonnet-4")
|
|
95
|
+
adapter.on_model_fallback("claude-opus-4", "claude-sonnet-4", "rate_limit")
|
|
96
|
+
adapter.on_session_reset()
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Generic (File-Based)
|
|
100
|
+
|
|
101
|
+
Drop JSON files into a watch directory — works with any agent:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from rsi_loop.integrations.generic import GenericAdapter
|
|
105
|
+
|
|
106
|
+
adapter = GenericAdapter(watch_dir="./rsi_inbox")
|
|
107
|
+
# Your agent writes: {"task": "search", "success": false, "error": "timeout"}
|
|
108
|
+
# RSI picks it up automatically
|
|
109
|
+
outcomes = adapter.poll()
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Webhook
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from rsi_loop.integrations.webhook import WebhookAdapter
|
|
116
|
+
|
|
117
|
+
app = WebhookAdapter(data_dir="./rsi_data").create_app()
|
|
118
|
+
# POST /observe {"task": "code_gen", "success": true, "quality": 4}
|
|
119
|
+
# GET /health
|
|
120
|
+
# GET /patterns
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Features
|
|
124
|
+
|
|
125
|
+
- **Auto-classification** — Categorizes errors automatically: rate_limit, empty_response, timeout, context_loss, etc.
|
|
126
|
+
- **Recurrence detection** — Flags issues that repeat 3+ times within the analysis window
|
|
127
|
+
- **Health scoring** — 0.0 (broken) to 1.0 (healthy), recency-weighted
|
|
128
|
+
- **Cross-source correlation** — Detects related issues across different agent sources
|
|
129
|
+
- **Error clustering** — Groups similar error messages even with different IDs/numbers
|
|
130
|
+
- **Safe auto-fix** — Automatically applies fixes for safe categories (routing, retries, thresholds)
|
|
131
|
+
- **Fix proposals** — Generates detailed proposals for unsafe categories, saved for human review
|
|
132
|
+
- **Background loop** — Run continuous improvement cycles in a background thread
|
|
133
|
+
- **Framework-agnostic** — Works with Claude Code, Cursor, Codex, or any custom agent
|
|
134
|
+
- **Zero dependencies** — Core package has no external dependencies (integrations optional)
|
|
135
|
+
|
|
136
|
+
## Documentation
|
|
137
|
+
|
|
138
|
+
- [Architecture](docs/architecture.md) — How RSI Loop works internally
|
|
139
|
+
- [Source Taxonomy](docs/sources.md) — Source classification and cross-source correlation
|
|
140
|
+
- [Auto-Fix](docs/auto_fix.md) — How auto-fix works, safe categories, and fix templates
|
|
141
|
+
|
|
142
|
+
## Examples
|
|
143
|
+
|
|
144
|
+
- [Claude Code Setup](examples/claude_code_setup.md)
|
|
145
|
+
- [Cursor Setup](examples/cursor_setup.md)
|
|
146
|
+
- [Generic Agent Setup](examples/generic_agent_setup.md)
|
|
147
|
+
- [Quick Start Script](examples/quick_start.py)
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
Built by [ClawInfra](https://github.com/clawinfra) — infrastructure for autonomous agents.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
rsi_loop/__init__.py,sha256=xoBKdpYqzgnKvXXD7tjERIyJcOv1-TJlK2oYBbrt_6g,386
|
|
2
|
+
rsi_loop/analyzer.py,sha256=MnRLOs6X1Rs3ra7YOm_kD1GJbdbupqDBZ2_-InGNLDc,8835
|
|
3
|
+
rsi_loop/fixer.py,sha256=eEp5IZrZ9zNhCifAiQyTYvp2_Sr9ntGR1BBElvxRQsw,4969
|
|
4
|
+
rsi_loop/loop.py,sha256=Xc43AIX1tbme8FQyYIsl_pmcuSPrGj__EJCITwkuJFg,2439
|
|
5
|
+
rsi_loop/observer.py,sha256=Lh_I5cO1yUFN7YTvw-j2jh8wnyn9xdfwgUgczb3btZU,4412
|
|
6
|
+
rsi_loop/types.py,sha256=2I2ZNda2Jtf4KVa_x4LIPKt9w3UGS4GGLTG8trH6Azw,6963
|
|
7
|
+
rsi_loop/integrations/__init__.py,sha256=JSPouQ24Eh5HTM87q8qXvqy49YHHN1hT5B-oIzZNPGA,58
|
|
8
|
+
rsi_loop/integrations/claude_code.py,sha256=IMfD84MalrWX3trIz9YP4yB9kggSlhZbc9GiaN69A6Q,3298
|
|
9
|
+
rsi_loop/integrations/generic.py,sha256=DKTFd3bFuX9Z7prbZ_Pt9Ff-2TE6ghhI8Xzg68ZUXv4,2000
|
|
10
|
+
rsi_loop/integrations/webhook.py,sha256=Gd-BQIdwBYOC3nEHDpOF1y_SgIjQx78KyX1GdFL-jI4,1948
|
|
11
|
+
rsi_loop-0.1.0.dist-info/METADATA,sha256=I9ceHSvsRE2L_f6kTpz1yNuaEhqyI0CWIeWjCUgkhJc,6443
|
|
12
|
+
rsi_loop-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
13
|
+
rsi_loop-0.1.0.dist-info/licenses/LICENSE,sha256=LlChPFyYuWPCh9cEjOBZNi8ALYoJtQSp7SEWzlpfi50,10707
|
|
14
|
+
rsi_loop-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean any work of authorship, including
|
|
48
|
+
the original version of the Work and any modifications or additions
|
|
49
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
50
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
51
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
52
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
53
|
+
means any form of electronic, verbal, or written communication sent
|
|
54
|
+
to the Licensor or its representatives, including but not limited to
|
|
55
|
+
communication on electronic mailing lists, source code control systems,
|
|
56
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
57
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
58
|
+
excluding communication that is conspicuously marked or otherwise
|
|
59
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
60
|
+
|
|
61
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
62
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
63
|
+
subsequently incorporated within the Work.
|
|
64
|
+
|
|
65
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
66
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
67
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
68
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
69
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
70
|
+
Work and such Derivative Works in Source or Object form.
|
|
71
|
+
|
|
72
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
73
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
74
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
75
|
+
(except as stated in this section) patent license to make, have made,
|
|
76
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
77
|
+
where such license applies only to those patent claims licensable
|
|
78
|
+
by such Contributor that are necessarily infringed by their
|
|
79
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
80
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
81
|
+
institute patent litigation against any entity (including a
|
|
82
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
83
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
84
|
+
or contributory patent infringement, then any patent licenses
|
|
85
|
+
granted to You under this License for that Work shall terminate
|
|
86
|
+
as of the date such litigation is filed.
|
|
87
|
+
|
|
88
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
89
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
90
|
+
modifications, and in Source or Object form, provided that You
|
|
91
|
+
meet the following conditions:
|
|
92
|
+
|
|
93
|
+
(a) You must give any other recipients of the Work or
|
|
94
|
+
Derivative Works a copy of this License; and
|
|
95
|
+
|
|
96
|
+
(b) You must cause any modified files to carry prominent notices
|
|
97
|
+
stating that You changed the files; and
|
|
98
|
+
|
|
99
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
100
|
+
that You distribute, all copyright, patent, trademark, and
|
|
101
|
+
attribution notices from the Source form of the Work,
|
|
102
|
+
excluding those notices that do not pertain to any part of
|
|
103
|
+
the Derivative Works; and
|
|
104
|
+
|
|
105
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
106
|
+
distribution, then any Derivative Works that You distribute must
|
|
107
|
+
include a readable copy of the attribution notices contained
|
|
108
|
+
within such NOTICE file, excluding any notices that do not
|
|
109
|
+
pertain to any part of the Derivative Works, in at least one
|
|
110
|
+
of the following places: within a NOTICE text file distributed
|
|
111
|
+
as part of the Derivative Works; within the Source form or
|
|
112
|
+
documentation, if provided along with the Derivative Works; or,
|
|
113
|
+
within a display generated by the Derivative Works, if and
|
|
114
|
+
wherever such third-party notices normally appear. The contents
|
|
115
|
+
of the NOTICE file are for informational purposes only and
|
|
116
|
+
do not modify the License. You may add Your own attribution
|
|
117
|
+
notices within Derivative Works that You distribute, alongside
|
|
118
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
119
|
+
that such additional attribution notices cannot be construed
|
|
120
|
+
as modifying the License.
|
|
121
|
+
|
|
122
|
+
You may add Your own copyright statement to Your modifications and
|
|
123
|
+
may provide additional or different license terms and conditions
|
|
124
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
125
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
126
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
127
|
+
the conditions stated in this License.
|
|
128
|
+
|
|
129
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
130
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
131
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
132
|
+
this License, without any additional terms or conditions.
|
|
133
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
134
|
+
the terms of any separate license agreement you may have executed
|
|
135
|
+
with Licensor regarding such Contributions.
|
|
136
|
+
|
|
137
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
138
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
139
|
+
except as required for reasonable and customary use in describing the
|
|
140
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
141
|
+
|
|
142
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
143
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
144
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
145
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
146
|
+
implied, including, without limitation, any warranties or conditions
|
|
147
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
148
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
149
|
+
appropriateness of using or redistributing the Work and assume any
|
|
150
|
+
risks associated with Your exercise of permissions under this License.
|
|
151
|
+
|
|
152
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
153
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
154
|
+
unless required by applicable law (such as deliberate and grossly
|
|
155
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
156
|
+
liable to You for damages, including any direct, indirect, special,
|
|
157
|
+
incidental, or consequential damages of any character arising as a
|
|
158
|
+
result of this License or out of the use or inability to use the
|
|
159
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
160
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
161
|
+
other commercial damages or losses), even if such Contributor
|
|
162
|
+
has been advised of the possibility of such damages.
|
|
163
|
+
|
|
164
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
165
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
166
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
167
|
+
or other liability obligations and/or rights consistent with this
|
|
168
|
+
License. However, in accepting such obligations, You may act only
|
|
169
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
170
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
171
|
+
defend, and hold each Contributor harmless for any liability
|
|
172
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
173
|
+
of your accepting any such warranty or additional liability.
|
|
174
|
+
|
|
175
|
+
END OF TERMS AND CONDITIONS
|
|
176
|
+
|
|
177
|
+
Copyright 2026 ClawInfra
|
|
178
|
+
|
|
179
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
180
|
+
you may not use this file except in compliance with the License.
|
|
181
|
+
You may obtain a copy of the License at
|
|
182
|
+
|
|
183
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
184
|
+
|
|
185
|
+
Unless required by applicable law or agreed to in writing, software
|
|
186
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
187
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
188
|
+
See the License for the specific language governing permissions and
|
|
189
|
+
limitations under the License.
|