usta 0.2.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.
- usta/__init__.py +0 -0
- usta/agent.py +319 -0
- usta/api.py +834 -0
- usta/apis.py +103 -0
- usta/attachments.py +60 -0
- usta/audit.py +47 -0
- usta/auth.py +55 -0
- usta/bench.py +904 -0
- usta/bench_tasks/add-feature/check/test_todo.py +37 -0
- usta/bench_tasks/add-feature/repo/test_todo.py +11 -0
- usta/bench_tasks/add-feature/repo/todo.py +10 -0
- usta/bench_tasks/add-feature/task.json +10 -0
- usta/bench_tasks/cli-args/check/test_cli.py +44 -0
- usta/bench_tasks/cli-args/repo/cli.py +2 -0
- usta/bench_tasks/cli-args/task.json +10 -0
- usta/bench_tasks/cross-module-bug/check/test_cart.py +19 -0
- usta/bench_tasks/cross-module-bug/check/test_pricing.py +12 -0
- usta/bench_tasks/cross-module-bug/repo/cart.py +7 -0
- usta/bench_tasks/cross-module-bug/repo/pricing.py +5 -0
- usta/bench_tasks/cross-module-bug/repo/test_cart.py +8 -0
- usta/bench_tasks/cross-module-bug/repo/test_pricing.py +12 -0
- usta/bench_tasks/cross-module-bug/task.json +10 -0
- usta/bench_tasks/csv-quotes/check/test_parse.py +22 -0
- usta/bench_tasks/csv-quotes/repo/parse.py +2 -0
- usta/bench_tasks/csv-quotes/task.json +10 -0
- usta/bench_tasks/deep-merge/check/test_config.py +31 -0
- usta/bench_tasks/deep-merge/repo/config.py +2 -0
- usta/bench_tasks/deep-merge/task.json +10 -0
- usta/bench_tasks/expr-eval/check/test_calc.py +37 -0
- usta/bench_tasks/expr-eval/repo/calc.py +2 -0
- usta/bench_tasks/expr-eval/task.json +10 -0
- usta/bench_tasks/implement-slugify/check/test_slug.py +19 -0
- usta/bench_tasks/implement-slugify/repo/slug.py +2 -0
- usta/bench_tasks/implement-slugify/task.json +10 -0
- usta/bench_tasks/interval-merge/check/test_intervals.py +30 -0
- usta/bench_tasks/interval-merge/repo/intervals.py +2 -0
- usta/bench_tasks/interval-merge/task.json +10 -0
- usta/bench_tasks/leap-dates/check/test_dates.py +34 -0
- usta/bench_tasks/leap-dates/repo/dates.py +15 -0
- usta/bench_tasks/leap-dates/repo/test_dates.py +9 -0
- usta/bench_tasks/leap-dates/task.json +10 -0
- usta/bench_tasks/lru-cache/check/test_lru.py +50 -0
- usta/bench_tasks/lru-cache/repo/lru.py +3 -0
- usta/bench_tasks/lru-cache/task.json +10 -0
- usta/bench_tasks/money-rounding/check/test_money.py +27 -0
- usta/bench_tasks/money-rounding/repo/money.py +7 -0
- usta/bench_tasks/money-rounding/repo/test_money.py +8 -0
- usta/bench_tasks/money-rounding/task.json +10 -0
- usta/bench_tasks/multi-file-rename/check/test_users.py +21 -0
- usta/bench_tasks/multi-file-rename/repo/api.py +5 -0
- usta/bench_tasks/multi-file-rename/repo/greeting.py +5 -0
- usta/bench_tasks/multi-file-rename/repo/report.py +5 -0
- usta/bench_tasks/multi-file-rename/repo/test_users.py +8 -0
- usta/bench_tasks/multi-file-rename/repo/users.py +2 -0
- usta/bench_tasks/multi-file-rename/task.json +10 -0
- usta/bench_tasks/off-by-one/check/test_stats.py +21 -0
- usta/bench_tasks/off-by-one/repo/stats.py +8 -0
- usta/bench_tasks/off-by-one/repo/test_stats.py +8 -0
- usta/bench_tasks/off-by-one/task.json +10 -0
- usta/bench_tasks/text-wrap/check/test_wrap.py +28 -0
- usta/bench_tasks/text-wrap/repo/wrap.py +2 -0
- usta/bench_tasks/text-wrap/task.json +10 -0
- usta/bench_tasks/tiny-case-insensitive/check/test_find.py +17 -0
- usta/bench_tasks/tiny-case-insensitive/repo/find.py +3 -0
- usta/bench_tasks/tiny-case-insensitive/repo/test_find.py +8 -0
- usta/bench_tasks/tiny-case-insensitive/task.json +11 -0
- usta/bench_tasks/tiny-default-sep/check/test_words.py +17 -0
- usta/bench_tasks/tiny-default-sep/repo/test_words.py +8 -0
- usta/bench_tasks/tiny-default-sep/repo/words.py +3 -0
- usta/bench_tasks/tiny-default-sep/task.json +11 -0
- usta/bench_tasks/tiny-greeting/check/test_greet.py +14 -0
- usta/bench_tasks/tiny-greeting/repo/greet.py +3 -0
- usta/bench_tasks/tiny-greeting/repo/test_greet.py +8 -0
- usta/bench_tasks/tiny-greeting/task.json +11 -0
- usta/bench_tasks/tiny-is-even/check/test_parity.py +18 -0
- usta/bench_tasks/tiny-is-even/repo/parity.py +5 -0
- usta/bench_tasks/tiny-is-even/repo/test_parity.py +9 -0
- usta/bench_tasks/tiny-is-even/task.json +11 -0
- usta/bench_tasks/tiny-missing-return/check/test_nums.py +19 -0
- usta/bench_tasks/tiny-missing-return/repo/nums.py +5 -0
- usta/bench_tasks/tiny-missing-return/repo/test_nums.py +8 -0
- usta/bench_tasks/tiny-missing-return/task.json +11 -0
- usta/bench_tasks/tiny-strip-names/check/test_names.py +17 -0
- usta/bench_tasks/tiny-strip-names/repo/names.py +3 -0
- usta/bench_tasks/tiny-strip-names/repo/test_names.py +8 -0
- usta/bench_tasks/tiny-strip-names/task.json +11 -0
- usta/bench_tasks/tiny-swap-args/check/test_pct.py +17 -0
- usta/bench_tasks/tiny-swap-args/repo/pct.py +5 -0
- usta/bench_tasks/tiny-swap-args/repo/test_pct.py +8 -0
- usta/bench_tasks/tiny-swap-args/task.json +11 -0
- usta/bench_tasks/tiny-wrong-operator/check/test_avg.py +17 -0
- usta/bench_tasks/tiny-wrong-operator/repo/avg.py +5 -0
- usta/bench_tasks/tiny-wrong-operator/repo/test_avg.py +8 -0
- usta/bench_tasks/tiny-wrong-operator/task.json +11 -0
- usta/bench_tasks/word-count-fix/check/test_text.py +25 -0
- usta/bench_tasks/word-count-fix/repo/test_text.py +10 -0
- usta/bench_tasks/word-count-fix/repo/text.py +5 -0
- usta/bench_tasks/word-count-fix/task.json +10 -0
- usta/breaker.py +132 -0
- usta/capability.py +643 -0
- usta/cli.py +1358 -0
- usta/context.py +122 -0
- usta/fetch.py +406 -0
- usta/fetch_inner.py +112 -0
- usta/filetree.py +134 -0
- usta/jsonproto.py +155 -0
- usta/lab/__init__.py +4 -0
- usta/lab/env.py +127 -0
- usta/lab/evaluator.py +108 -0
- usta/lab/metrics.py +109 -0
- usta/lab/report.py +124 -0
- usta/lab/runner.py +242 -0
- usta/lab/scenario.py +266 -0
- usta/lab/scenarios/v1.jsonl +25 -0
- usta/lab/scripted.py +47 -0
- usta/mcp.py +344 -0
- usta/mcp_runtime.py +362 -0
- usta/mcp_tools.py +162 -0
- usta/mcpcatalog.py +39 -0
- usta/mcpconfig.py +306 -0
- usta/memory.py +218 -0
- usta/modelctl.py +124 -0
- usta/modelinfo.py +19 -0
- usta/models.py +170 -0
- usta/outline.py +191 -0
- usta/pdf_inner.py +59 -0
- usta/phases.py +267 -0
- usta/policy.py +104 -0
- usta/portal.py +107 -0
- usta/profile.py +177 -0
- usta/projectcfg.py +90 -0
- usta/projects.py +67 -0
- usta/proxy.py +302 -0
- usta/repl.py +590 -0
- usta/rescue.py +66 -0
- usta/sandbox.py +359 -0
- usta/sessions.py +120 -0
- usta/settings.py +93 -0
- usta/skills.py +79 -0
- usta/symbols.py +618 -0
- usta/tasks.py +633 -0
- usta/taxonomy.py +169 -0
- usta/textproto.py +149 -0
- usta/theme.py +104 -0
- usta/tools.py +369 -0
- usta/verify.py +233 -0
- usta/web/app.css +160 -0
- usta/web/app.js +1064 -0
- usta/web/index.html +197 -0
- usta/web/logic.js +175 -0
- usta/workspace.py +236 -0
- usta-0.2.0.dist-info/METADATA +211 -0
- usta-0.2.0.dist-info/RECORD +156 -0
- usta-0.2.0.dist-info/WHEEL +4 -0
- usta-0.2.0.dist-info/entry_points.txt +2 -0
- usta-0.2.0.dist-info/licenses/LICENSE +202 -0
usta/breaker.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""Devre kesici: ajan aynı hatayı ya da aynı yaklaşımı tekrarlıyorsa akışı keser.
|
|
2
|
+
|
|
3
|
+
Küçük modellerin tipik hastalığı: A'yı dener patlar, B'yi dener patlar, bağlam kaydığı için tekrar A'yı
|
|
4
|
+
dener. Burada zekâ modelden alınıp deterministik kurallara bırakılır:
|
|
5
|
+
|
|
6
|
+
- aynı hata imzası, arada bir düzenleme denendikten sonra yeniden görülürse (düzeltme çözmedi),
|
|
7
|
+
- bir dosya daha önce görülmüş bir içeriğe geri dönerse (A→B→A salınımı),
|
|
8
|
+
- aynı araç çağrısı aynı sonuçla art arda 3 kez gelirse
|
|
9
|
+
|
|
10
|
+
devre açılır: çalışma alanı son güvenli duruma (başlangıç ya da son doğrulanmış kontrol noktası) geri
|
|
11
|
+
sarılır ve modele "denenenler" listesi verilir. `max_trips` aşılırsa akış durur ve konu kullanıcıya bırakılır.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import hashlib
|
|
17
|
+
import json
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
from usta.verify import failure_signature
|
|
22
|
+
from usta.workspace import Snapshot, revert, snapshot
|
|
23
|
+
|
|
24
|
+
EDIT_TOOLS = ("write_file", "edit_file")
|
|
25
|
+
MAX_TRIED = 8
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True)
|
|
29
|
+
class Trip:
|
|
30
|
+
reason: str
|
|
31
|
+
tried: list[str]
|
|
32
|
+
final: bool = False
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _h(text: str) -> str:
|
|
36
|
+
return hashlib.sha1(text.encode(), usedforsecurity=False).hexdigest()[:10]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class CircuitBreaker:
|
|
40
|
+
def __init__(self, root: Path, *, max_trips: int = 2, identical_calls: int = 3):
|
|
41
|
+
self.root, self.max_trips, self.identical_calls = Path(root), max_trips, identical_calls
|
|
42
|
+
self._snap: Snapshot | None = None
|
|
43
|
+
self.trips = 0
|
|
44
|
+
self._reset_state()
|
|
45
|
+
|
|
46
|
+
def _reset_state(self) -> None:
|
|
47
|
+
self._seen: dict[str, set[str]] = {} # dosya → görülen içerik parmak izleri
|
|
48
|
+
self._latest: dict[str, str] = {}
|
|
49
|
+
self._fail_edits: dict[
|
|
50
|
+
str, int
|
|
51
|
+
] = {} # hata imzası → o imza görüldüğünde toplam düzenleme sayısı
|
|
52
|
+
self._edits = 0
|
|
53
|
+
self._tried: list[str] = []
|
|
54
|
+
self._last_call: tuple[str, str] | None = None
|
|
55
|
+
self._repeat = 0
|
|
56
|
+
|
|
57
|
+
def start(self) -> None:
|
|
58
|
+
self._snap = snapshot(self.root)
|
|
59
|
+
self.trips = 0
|
|
60
|
+
self._reset_state()
|
|
61
|
+
|
|
62
|
+
def checkpoint(self) -> None:
|
|
63
|
+
"""Doğrulanmış iyi durum: devre açılırsa buraya dönülür; hata hafızası temizlenir."""
|
|
64
|
+
self._snap = snapshot(self.root)
|
|
65
|
+
self._fail_edits.clear()
|
|
66
|
+
|
|
67
|
+
def rewind(self) -> None:
|
|
68
|
+
if self._snap is not None:
|
|
69
|
+
revert(self._snap, self.root)
|
|
70
|
+
self._seen.clear()
|
|
71
|
+
self._latest.clear()
|
|
72
|
+
self._fail_edits.clear()
|
|
73
|
+
self._edits = 0
|
|
74
|
+
self._last_call, self._repeat = None, 0
|
|
75
|
+
|
|
76
|
+
def _trip(self, reason: str) -> Trip:
|
|
77
|
+
self.trips += 1
|
|
78
|
+
return Trip(reason, self._tried[-MAX_TRIED:], final=self.trips > self.max_trips)
|
|
79
|
+
|
|
80
|
+
def observe(self, tool: str, args: dict, result: str) -> Trip | None:
|
|
81
|
+
call = (tool, _h(json.dumps(args, sort_keys=True, default=str)))
|
|
82
|
+
self._repeat = self._repeat + 1 if self._last_call == (*call, _h(result)) else 1
|
|
83
|
+
self._last_call = (*call, _h(result)) # type: ignore[assignment]
|
|
84
|
+
if self._repeat >= self.identical_calls:
|
|
85
|
+
self._tried.append(f"{tool} aynı sonuçla {self._repeat} kez")
|
|
86
|
+
return self._trip(f"aynı çağrı aynı sonuçla {self._repeat} kez tekrarlandı")
|
|
87
|
+
if tool in EDIT_TOOLS and isinstance(args.get("path"), str):
|
|
88
|
+
return self._on_edit(tool, args)
|
|
89
|
+
if tool == "run":
|
|
90
|
+
return self._on_run(args, result)
|
|
91
|
+
return None
|
|
92
|
+
|
|
93
|
+
def _on_edit(self, tool: str, args: dict) -> Trip | None:
|
|
94
|
+
path = args["path"]
|
|
95
|
+
try:
|
|
96
|
+
text = (self.root / path).read_text(errors="replace")
|
|
97
|
+
except OSError:
|
|
98
|
+
text = str(args.get("content") or args.get("new") or "")
|
|
99
|
+
fp = _h(text)
|
|
100
|
+
self._edits += 1
|
|
101
|
+
self._tried.append(f"{tool} {path} (#{fp})")
|
|
102
|
+
seen = self._seen.setdefault(path, set())
|
|
103
|
+
revisit = fp in seen and self._latest.get(path) != fp
|
|
104
|
+
seen.add(fp)
|
|
105
|
+
self._latest[path] = fp
|
|
106
|
+
if revisit:
|
|
107
|
+
return self._trip(f"{path} daha önce denenmiş bir içeriğe geri döndü")
|
|
108
|
+
return None
|
|
109
|
+
|
|
110
|
+
def _on_run(self, args: dict, result: str) -> Trip | None:
|
|
111
|
+
cmd = str(args.get("command", ""))[:80]
|
|
112
|
+
body = result.split("\n", 1)
|
|
113
|
+
code_line = body[0]
|
|
114
|
+
if code_line.startswith("exit_code: 0"):
|
|
115
|
+
self._fail_edits.clear()
|
|
116
|
+
self._tried.append(f"run: {cmd} → geçti")
|
|
117
|
+
return None
|
|
118
|
+
sig = failure_signature(body[1] if len(body) > 1 else result)
|
|
119
|
+
first = next(
|
|
120
|
+
(
|
|
121
|
+
ln.strip()
|
|
122
|
+
for ln in reversed((body[1] if len(body) > 1 else "").splitlines())
|
|
123
|
+
if ln.strip()
|
|
124
|
+
),
|
|
125
|
+
code_line,
|
|
126
|
+
)
|
|
127
|
+
self._tried.append(f"run: {cmd} → hata: {first[:100]}")
|
|
128
|
+
prev = self._fail_edits.get(sig)
|
|
129
|
+
self._fail_edits[sig] = self._edits
|
|
130
|
+
if prev is not None and self._edits > prev: # arada düzeltme denendi ama aynı hata sürüyor
|
|
131
|
+
return self._trip("aynı hata, bir düzeltme denemesinden sonra yeniden görüldü")
|
|
132
|
+
return None
|