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.
Files changed (156) hide show
  1. usta/__init__.py +0 -0
  2. usta/agent.py +319 -0
  3. usta/api.py +834 -0
  4. usta/apis.py +103 -0
  5. usta/attachments.py +60 -0
  6. usta/audit.py +47 -0
  7. usta/auth.py +55 -0
  8. usta/bench.py +904 -0
  9. usta/bench_tasks/add-feature/check/test_todo.py +37 -0
  10. usta/bench_tasks/add-feature/repo/test_todo.py +11 -0
  11. usta/bench_tasks/add-feature/repo/todo.py +10 -0
  12. usta/bench_tasks/add-feature/task.json +10 -0
  13. usta/bench_tasks/cli-args/check/test_cli.py +44 -0
  14. usta/bench_tasks/cli-args/repo/cli.py +2 -0
  15. usta/bench_tasks/cli-args/task.json +10 -0
  16. usta/bench_tasks/cross-module-bug/check/test_cart.py +19 -0
  17. usta/bench_tasks/cross-module-bug/check/test_pricing.py +12 -0
  18. usta/bench_tasks/cross-module-bug/repo/cart.py +7 -0
  19. usta/bench_tasks/cross-module-bug/repo/pricing.py +5 -0
  20. usta/bench_tasks/cross-module-bug/repo/test_cart.py +8 -0
  21. usta/bench_tasks/cross-module-bug/repo/test_pricing.py +12 -0
  22. usta/bench_tasks/cross-module-bug/task.json +10 -0
  23. usta/bench_tasks/csv-quotes/check/test_parse.py +22 -0
  24. usta/bench_tasks/csv-quotes/repo/parse.py +2 -0
  25. usta/bench_tasks/csv-quotes/task.json +10 -0
  26. usta/bench_tasks/deep-merge/check/test_config.py +31 -0
  27. usta/bench_tasks/deep-merge/repo/config.py +2 -0
  28. usta/bench_tasks/deep-merge/task.json +10 -0
  29. usta/bench_tasks/expr-eval/check/test_calc.py +37 -0
  30. usta/bench_tasks/expr-eval/repo/calc.py +2 -0
  31. usta/bench_tasks/expr-eval/task.json +10 -0
  32. usta/bench_tasks/implement-slugify/check/test_slug.py +19 -0
  33. usta/bench_tasks/implement-slugify/repo/slug.py +2 -0
  34. usta/bench_tasks/implement-slugify/task.json +10 -0
  35. usta/bench_tasks/interval-merge/check/test_intervals.py +30 -0
  36. usta/bench_tasks/interval-merge/repo/intervals.py +2 -0
  37. usta/bench_tasks/interval-merge/task.json +10 -0
  38. usta/bench_tasks/leap-dates/check/test_dates.py +34 -0
  39. usta/bench_tasks/leap-dates/repo/dates.py +15 -0
  40. usta/bench_tasks/leap-dates/repo/test_dates.py +9 -0
  41. usta/bench_tasks/leap-dates/task.json +10 -0
  42. usta/bench_tasks/lru-cache/check/test_lru.py +50 -0
  43. usta/bench_tasks/lru-cache/repo/lru.py +3 -0
  44. usta/bench_tasks/lru-cache/task.json +10 -0
  45. usta/bench_tasks/money-rounding/check/test_money.py +27 -0
  46. usta/bench_tasks/money-rounding/repo/money.py +7 -0
  47. usta/bench_tasks/money-rounding/repo/test_money.py +8 -0
  48. usta/bench_tasks/money-rounding/task.json +10 -0
  49. usta/bench_tasks/multi-file-rename/check/test_users.py +21 -0
  50. usta/bench_tasks/multi-file-rename/repo/api.py +5 -0
  51. usta/bench_tasks/multi-file-rename/repo/greeting.py +5 -0
  52. usta/bench_tasks/multi-file-rename/repo/report.py +5 -0
  53. usta/bench_tasks/multi-file-rename/repo/test_users.py +8 -0
  54. usta/bench_tasks/multi-file-rename/repo/users.py +2 -0
  55. usta/bench_tasks/multi-file-rename/task.json +10 -0
  56. usta/bench_tasks/off-by-one/check/test_stats.py +21 -0
  57. usta/bench_tasks/off-by-one/repo/stats.py +8 -0
  58. usta/bench_tasks/off-by-one/repo/test_stats.py +8 -0
  59. usta/bench_tasks/off-by-one/task.json +10 -0
  60. usta/bench_tasks/text-wrap/check/test_wrap.py +28 -0
  61. usta/bench_tasks/text-wrap/repo/wrap.py +2 -0
  62. usta/bench_tasks/text-wrap/task.json +10 -0
  63. usta/bench_tasks/tiny-case-insensitive/check/test_find.py +17 -0
  64. usta/bench_tasks/tiny-case-insensitive/repo/find.py +3 -0
  65. usta/bench_tasks/tiny-case-insensitive/repo/test_find.py +8 -0
  66. usta/bench_tasks/tiny-case-insensitive/task.json +11 -0
  67. usta/bench_tasks/tiny-default-sep/check/test_words.py +17 -0
  68. usta/bench_tasks/tiny-default-sep/repo/test_words.py +8 -0
  69. usta/bench_tasks/tiny-default-sep/repo/words.py +3 -0
  70. usta/bench_tasks/tiny-default-sep/task.json +11 -0
  71. usta/bench_tasks/tiny-greeting/check/test_greet.py +14 -0
  72. usta/bench_tasks/tiny-greeting/repo/greet.py +3 -0
  73. usta/bench_tasks/tiny-greeting/repo/test_greet.py +8 -0
  74. usta/bench_tasks/tiny-greeting/task.json +11 -0
  75. usta/bench_tasks/tiny-is-even/check/test_parity.py +18 -0
  76. usta/bench_tasks/tiny-is-even/repo/parity.py +5 -0
  77. usta/bench_tasks/tiny-is-even/repo/test_parity.py +9 -0
  78. usta/bench_tasks/tiny-is-even/task.json +11 -0
  79. usta/bench_tasks/tiny-missing-return/check/test_nums.py +19 -0
  80. usta/bench_tasks/tiny-missing-return/repo/nums.py +5 -0
  81. usta/bench_tasks/tiny-missing-return/repo/test_nums.py +8 -0
  82. usta/bench_tasks/tiny-missing-return/task.json +11 -0
  83. usta/bench_tasks/tiny-strip-names/check/test_names.py +17 -0
  84. usta/bench_tasks/tiny-strip-names/repo/names.py +3 -0
  85. usta/bench_tasks/tiny-strip-names/repo/test_names.py +8 -0
  86. usta/bench_tasks/tiny-strip-names/task.json +11 -0
  87. usta/bench_tasks/tiny-swap-args/check/test_pct.py +17 -0
  88. usta/bench_tasks/tiny-swap-args/repo/pct.py +5 -0
  89. usta/bench_tasks/tiny-swap-args/repo/test_pct.py +8 -0
  90. usta/bench_tasks/tiny-swap-args/task.json +11 -0
  91. usta/bench_tasks/tiny-wrong-operator/check/test_avg.py +17 -0
  92. usta/bench_tasks/tiny-wrong-operator/repo/avg.py +5 -0
  93. usta/bench_tasks/tiny-wrong-operator/repo/test_avg.py +8 -0
  94. usta/bench_tasks/tiny-wrong-operator/task.json +11 -0
  95. usta/bench_tasks/word-count-fix/check/test_text.py +25 -0
  96. usta/bench_tasks/word-count-fix/repo/test_text.py +10 -0
  97. usta/bench_tasks/word-count-fix/repo/text.py +5 -0
  98. usta/bench_tasks/word-count-fix/task.json +10 -0
  99. usta/breaker.py +132 -0
  100. usta/capability.py +643 -0
  101. usta/cli.py +1358 -0
  102. usta/context.py +122 -0
  103. usta/fetch.py +406 -0
  104. usta/fetch_inner.py +112 -0
  105. usta/filetree.py +134 -0
  106. usta/jsonproto.py +155 -0
  107. usta/lab/__init__.py +4 -0
  108. usta/lab/env.py +127 -0
  109. usta/lab/evaluator.py +108 -0
  110. usta/lab/metrics.py +109 -0
  111. usta/lab/report.py +124 -0
  112. usta/lab/runner.py +242 -0
  113. usta/lab/scenario.py +266 -0
  114. usta/lab/scenarios/v1.jsonl +25 -0
  115. usta/lab/scripted.py +47 -0
  116. usta/mcp.py +344 -0
  117. usta/mcp_runtime.py +362 -0
  118. usta/mcp_tools.py +162 -0
  119. usta/mcpcatalog.py +39 -0
  120. usta/mcpconfig.py +306 -0
  121. usta/memory.py +218 -0
  122. usta/modelctl.py +124 -0
  123. usta/modelinfo.py +19 -0
  124. usta/models.py +170 -0
  125. usta/outline.py +191 -0
  126. usta/pdf_inner.py +59 -0
  127. usta/phases.py +267 -0
  128. usta/policy.py +104 -0
  129. usta/portal.py +107 -0
  130. usta/profile.py +177 -0
  131. usta/projectcfg.py +90 -0
  132. usta/projects.py +67 -0
  133. usta/proxy.py +302 -0
  134. usta/repl.py +590 -0
  135. usta/rescue.py +66 -0
  136. usta/sandbox.py +359 -0
  137. usta/sessions.py +120 -0
  138. usta/settings.py +93 -0
  139. usta/skills.py +79 -0
  140. usta/symbols.py +618 -0
  141. usta/tasks.py +633 -0
  142. usta/taxonomy.py +169 -0
  143. usta/textproto.py +149 -0
  144. usta/theme.py +104 -0
  145. usta/tools.py +369 -0
  146. usta/verify.py +233 -0
  147. usta/web/app.css +160 -0
  148. usta/web/app.js +1064 -0
  149. usta/web/index.html +197 -0
  150. usta/web/logic.js +175 -0
  151. usta/workspace.py +236 -0
  152. usta-0.2.0.dist-info/METADATA +211 -0
  153. usta-0.2.0.dist-info/RECORD +156 -0
  154. usta-0.2.0.dist-info/WHEEL +4 -0
  155. usta-0.2.0.dist-info/entry_points.txt +2 -0
  156. 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