ErrorAI 1.6.0__tar.gz → 1.8.0__tar.gz
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.
- {errorai-1.6.0 → errorai-1.8.0}/ErrorAI.egg-info/PKG-INFO +1 -1
- {errorai-1.6.0 → errorai-1.8.0}/PKG-INFO +1 -1
- errorai-1.8.0/errorai/config.py +167 -0
- {errorai-1.6.0 → errorai-1.8.0}/pyproject.toml +1 -1
- errorai-1.6.0/errorai/config.py +0 -311
- {errorai-1.6.0 → errorai-1.8.0}/ErrorAI.egg-info/SOURCES.txt +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/ErrorAI.egg-info/dependency_links.txt +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/ErrorAI.egg-info/entry_points.txt +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/ErrorAI.egg-info/requires.txt +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/ErrorAI.egg-info/top_level.txt +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/README.md +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/errorai/__init__.py +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/errorai/__main__.py +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/errorai/bootstrap.py +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/errorai/cli.py +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/errorai/compat.py +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/errorai/environment.py +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/errorai/pipeline.py +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/errorai/providers.py +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/errorai/runtime.py +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/errorai/universal.py +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/setup.cfg +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/tests/test_bootstrap.py +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/tests/test_config.py +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/tests/test_runtime.py +0 -0
- {errorai-1.6.0 → errorai-1.8.0}/tests/test_safety.py +0 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field, replace
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
from typing import Any, Dict
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _default_project_root() -> Path:
|
|
11
|
+
"""Prefer the directory of the script actually being run.
|
|
12
|
+
|
|
13
|
+
Path.cwd() is wrong in IDLE (and many IDEs): "Run Module" does not chdir
|
|
14
|
+
into the script's folder, it just sets sys.argv[0] to the script path.
|
|
15
|
+
Falling back to cwd() there means the running file is almost never
|
|
16
|
+
considered "inside" project_root, and every fix silently gets blocked by
|
|
17
|
+
Applier.can_edit().
|
|
18
|
+
"""
|
|
19
|
+
try:
|
|
20
|
+
candidate = sys.argv[0]
|
|
21
|
+
if candidate and Path(candidate).is_file():
|
|
22
|
+
return Path(candidate).resolve().parent
|
|
23
|
+
except Exception:
|
|
24
|
+
pass
|
|
25
|
+
return Path.cwd()
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
import tomllib
|
|
29
|
+
except ModuleNotFoundError: # pragma: no cover - py<3.11 fallback
|
|
30
|
+
import tomli as tomllib
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _default_cache_dir() -> Path:
|
|
34
|
+
try:
|
|
35
|
+
from platformdirs import user_cache_dir
|
|
36
|
+
|
|
37
|
+
return Path(user_cache_dir("errorai", "ErrorAI"))
|
|
38
|
+
except Exception:
|
|
39
|
+
return Path.home() / ".cache" / "errorai"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass(frozen=True)
|
|
43
|
+
class RuntimeConfig:
|
|
44
|
+
auto_watch: bool = True
|
|
45
|
+
safe_mode: bool = True
|
|
46
|
+
dry_run: bool = True
|
|
47
|
+
project_root: Path = field(default_factory=_default_project_root)
|
|
48
|
+
ignore_patterns: tuple[str, ...] = (
|
|
49
|
+
".git",
|
|
50
|
+
"__pycache__",
|
|
51
|
+
".env",
|
|
52
|
+
".venv",
|
|
53
|
+
"venv",
|
|
54
|
+
"node_modules",
|
|
55
|
+
"*.lock",
|
|
56
|
+
".errorai",
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@dataclass(frozen=True)
|
|
61
|
+
class ModelConfig:
|
|
62
|
+
provider: str = "onnx"
|
|
63
|
+
name: str = "onnx-qwen2.5-coder-0.5b"
|
|
64
|
+
repo_id: str = "onnx-community/Qwen2.5-Coder-0.5B-Instruct"
|
|
65
|
+
model_url: str = (
|
|
66
|
+
"https://huggingface.co/onnx-community/Qwen2.5-Coder-0.5B-Instruct/resolve/main/"
|
|
67
|
+
"onnx/model.onnx"
|
|
68
|
+
)
|
|
69
|
+
context_window: int = 4096
|
|
70
|
+
temperature: float = 0.1
|
|
71
|
+
auto_bootstrap: bool = True
|
|
72
|
+
download_timeout: int = 600
|
|
73
|
+
cache_dir: Path = field(default_factory=_default_cache_dir)
|
|
74
|
+
# Only used when provider = "http_api". Sends the errroring line + message
|
|
75
|
+
# to this endpoint instead of running a local model. Opt-in only: unlike
|
|
76
|
+
# the local onnx/llama_cpp providers, this means code leaves the machine.
|
|
77
|
+
http_api_base_url: str = "https://oai.endpoints.kepler.ai.cloud.ovh.net/v1/chat/completions"
|
|
78
|
+
http_api_model: str = "qwen2.5-coder-32b-instruct"
|
|
79
|
+
http_api_timeout: float = 8.0
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@dataclass(frozen=True)
|
|
83
|
+
class ErrorAIConfig:
|
|
84
|
+
runtime: RuntimeConfig = field(default_factory=RuntimeConfig)
|
|
85
|
+
model: ModelConfig = field(default_factory=ModelConfig)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _read_toml(path: Path) -> Dict[str, Any]:
|
|
89
|
+
if not path.exists():
|
|
90
|
+
return {}
|
|
91
|
+
with path.open("rb") as handle:
|
|
92
|
+
return tomllib.load(handle)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _coerce_runtime(base: RuntimeConfig, values: Dict[str, Any]) -> RuntimeConfig:
|
|
96
|
+
data = {}
|
|
97
|
+
for key in ("auto_watch", "safe_mode", "dry_run"):
|
|
98
|
+
if key in values:
|
|
99
|
+
data[key] = bool(values[key])
|
|
100
|
+
if "ignore_patterns" in values:
|
|
101
|
+
data["ignore_patterns"] = tuple(str(v) for v in values["ignore_patterns"])
|
|
102
|
+
if "project_root" in values:
|
|
103
|
+
data["project_root"] = Path(values["project_root"]).resolve()
|
|
104
|
+
return replace(base, **data)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _coerce_model(base: ModelConfig, values: Dict[str, Any]) -> ModelConfig:
|
|
108
|
+
data = {}
|
|
109
|
+
for key in ("provider", "name", "repo_id", "model_url"):
|
|
110
|
+
if key in values:
|
|
111
|
+
data[key] = str(values[key])
|
|
112
|
+
if "context_window" in values:
|
|
113
|
+
data["context_window"] = int(values["context_window"])
|
|
114
|
+
if "temperature" in values:
|
|
115
|
+
data["temperature"] = float(values["temperature"])
|
|
116
|
+
if "auto_bootstrap" in values:
|
|
117
|
+
data["auto_bootstrap"] = bool(values["auto_bootstrap"])
|
|
118
|
+
if "download_timeout" in values:
|
|
119
|
+
data["download_timeout"] = int(values["download_timeout"])
|
|
120
|
+
if "cache_dir" in values:
|
|
121
|
+
data["cache_dir"] = Path(values["cache_dir"]).expanduser().resolve()
|
|
122
|
+
if "http_api_base_url" in values:
|
|
123
|
+
data["http_api_base_url"] = str(values["http_api_base_url"])
|
|
124
|
+
if "http_api_model" in values:
|
|
125
|
+
data["http_api_model"] = str(values["http_api_model"])
|
|
126
|
+
if "http_api_timeout" in values:
|
|
127
|
+
data["http_api_timeout"] = float(values["http_api_timeout"])
|
|
128
|
+
return replace(base, **data)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def load_config(project_root: Path | None = None) -> ErrorAIConfig:
|
|
132
|
+
root = (project_root or Path.cwd()).resolve()
|
|
133
|
+
config = ErrorAIConfig(runtime=RuntimeConfig(project_root=root))
|
|
134
|
+
pyproject = _read_toml(root / "pyproject.toml")
|
|
135
|
+
pyproject_settings = pyproject.get("tool", {}).get("errorai", {})
|
|
136
|
+
local_settings = _read_toml(root / ".errorai.toml")
|
|
137
|
+
|
|
138
|
+
runtime_values = {}
|
|
139
|
+
model_values = {}
|
|
140
|
+
for source in (pyproject_settings, local_settings):
|
|
141
|
+
runtime_values.update(source.get("runtime", {}))
|
|
142
|
+
model_values.update(source.get("model", {}))
|
|
143
|
+
|
|
144
|
+
return ErrorAIConfig(
|
|
145
|
+
runtime=_coerce_runtime(config.runtime, runtime_values),
|
|
146
|
+
model=_coerce_model(config.model, model_values),
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def config_template() -> str:
|
|
151
|
+
return """[runtime]
|
|
152
|
+
auto_watch = true
|
|
153
|
+
safe_mode = true
|
|
154
|
+
dry_run = true
|
|
155
|
+
ignore_patterns = [".git", "__pycache__", ".env", ".venv", "venv", "node_modules", "*.lock", ".errorai"]
|
|
156
|
+
|
|
157
|
+
[model]
|
|
158
|
+
provider = "onnx"
|
|
159
|
+
name = "onnx-default-python-expert"
|
|
160
|
+
context_window = 4096
|
|
161
|
+
temperature = 0.1
|
|
162
|
+
auto_bootstrap = true
|
|
163
|
+
"""
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def autostart_enabled() -> bool:
|
|
167
|
+
return os.environ.get("ERRORAI_AUTOSTART", "1") != "0"
|
errorai-1.6.0/errorai/config.py
DELETED
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from dataclasses import replace
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
import linecache
|
|
6
|
-
import sys
|
|
7
|
-
import threading
|
|
8
|
-
import traceback
|
|
9
|
-
from types import TracebackType
|
|
10
|
-
from typing import Any
|
|
11
|
-
|
|
12
|
-
from .bootstrap import BootstrapStatus, ensure_model, model_status
|
|
13
|
-
from .config import ErrorAIConfig, autostart_enabled, load_config
|
|
14
|
-
from .environment import Capabilities, detect_capabilities
|
|
15
|
-
from .pipeline import Analyzer, Applier, Planner, Reporter, Watcher
|
|
16
|
-
from .providers import ModelProvider, RulesOnlyProvider, HttpApiProvider
|
|
17
|
-
|
|
18
|
-
try:
|
|
19
|
-
from .providers import LlamaCppProvider
|
|
20
|
-
except ImportError: # pragma: no cover - optional dependency
|
|
21
|
-
LlamaCppProvider = None # type: ignore[assignment,misc]
|
|
22
|
-
|
|
23
|
-
try:
|
|
24
|
-
from .providers import OnnxProvider
|
|
25
|
-
except ImportError: # pragma: no cover - optional dependency
|
|
26
|
-
OnnxProvider = None # type: ignore[assignment,misc]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class RuntimeManager:
|
|
30
|
-
_instance: "RuntimeManager | None" = None
|
|
31
|
-
_instance_lock = threading.Lock()
|
|
32
|
-
|
|
33
|
-
def __init__(self) -> None:
|
|
34
|
-
self._init_lock = threading.Lock()
|
|
35
|
-
self._initialized = False
|
|
36
|
-
self.config: ErrorAIConfig | None = None
|
|
37
|
-
self.capabilities: Capabilities | None = None
|
|
38
|
-
self.reporter: Reporter | None = None
|
|
39
|
-
self.analyzer: Analyzer | None = None
|
|
40
|
-
self.planner: Planner | None = None
|
|
41
|
-
self.applier: Applier | None = None
|
|
42
|
-
self.watcher: Watcher | None = None
|
|
43
|
-
self.provider: ModelProvider = RulesOnlyProvider()
|
|
44
|
-
self.bootstrap_status = BootstrapStatus(False, "rules-only", "Not initialized.", None)
|
|
45
|
-
self.mode = "rules-only"
|
|
46
|
-
self._orig_sys_hook = sys.excepthook
|
|
47
|
-
self._orig_thread_hook = getattr(threading, "excepthook", None)
|
|
48
|
-
self._orig_idle_print_exception = None
|
|
49
|
-
self._idle_hook_installed = False
|
|
50
|
-
|
|
51
|
-
@classmethod
|
|
52
|
-
def get_instance(cls) -> "RuntimeManager":
|
|
53
|
-
with cls._instance_lock:
|
|
54
|
-
if cls._instance is None:
|
|
55
|
-
cls._instance = cls()
|
|
56
|
-
return cls._instance
|
|
57
|
-
|
|
58
|
-
def initialize(self, config_override: ErrorAIConfig | None = None) -> "RuntimeManager":
|
|
59
|
-
if not autostart_enabled():
|
|
60
|
-
return self
|
|
61
|
-
with self._init_lock:
|
|
62
|
-
if self._initialized:
|
|
63
|
-
return self
|
|
64
|
-
|
|
65
|
-
self.config = config_override or load_config()
|
|
66
|
-
self.capabilities = detect_capabilities()
|
|
67
|
-
self.reporter = Reporter(self.config.runtime.project_root)
|
|
68
|
-
self.analyzer = Analyzer()
|
|
69
|
-
self.applier = Applier(self.config.runtime)
|
|
70
|
-
if self.config.model.provider in ("onnx", "llama_cpp"):
|
|
71
|
-
self.bootstrap_status = ensure_model(self.config.model, explicit=False)
|
|
72
|
-
else:
|
|
73
|
-
self.bootstrap_status = BootstrapStatus(
|
|
74
|
-
True, "remote", "Using remote HTTP API provider; no local model needed.", None
|
|
75
|
-
)
|
|
76
|
-
self.provider = self._select_provider(self.bootstrap_status)
|
|
77
|
-
self.planner = Planner(self.provider)
|
|
78
|
-
self.watcher = Watcher(self.capabilities, self.reporter)
|
|
79
|
-
self._register_hooks()
|
|
80
|
-
watch_started = False
|
|
81
|
-
if self.config.runtime.auto_watch:
|
|
82
|
-
watch_started = self.watcher.start()
|
|
83
|
-
self.mode = "full" if self.bootstrap_status.ready and watch_started else "analyze-only"
|
|
84
|
-
if not self.bootstrap_status.ready:
|
|
85
|
-
self.mode = "rules-only"
|
|
86
|
-
self.reporter.log(
|
|
87
|
-
"runtime.initialized",
|
|
88
|
-
{
|
|
89
|
-
"environment": self.capabilities.environment,
|
|
90
|
-
"mode": self.mode,
|
|
91
|
-
"model_mode": self.bootstrap_status.mode,
|
|
92
|
-
"idle_hook_installed": self._idle_hook_installed,
|
|
93
|
-
},
|
|
94
|
-
)
|
|
95
|
-
self._initialized = True
|
|
96
|
-
return self
|
|
97
|
-
|
|
98
|
-
def _select_provider(self, status: BootstrapStatus) -> ModelProvider:
|
|
99
|
-
if self.config is None:
|
|
100
|
-
return RulesOnlyProvider()
|
|
101
|
-
|
|
102
|
-
provider_name = self.config.model.provider
|
|
103
|
-
|
|
104
|
-
if provider_name == "http_api":
|
|
105
|
-
return HttpApiProvider(self.config.model)
|
|
106
|
-
|
|
107
|
-
if not status.ready or status.model_path is None:
|
|
108
|
-
return RulesOnlyProvider()
|
|
109
|
-
|
|
110
|
-
if provider_name == "onnx":
|
|
111
|
-
if OnnxProvider is None:
|
|
112
|
-
return RulesOnlyProvider()
|
|
113
|
-
try:
|
|
114
|
-
return OnnxProvider(self.config.model, status.model_path)
|
|
115
|
-
except Exception:
|
|
116
|
-
return RulesOnlyProvider()
|
|
117
|
-
|
|
118
|
-
if provider_name == "llama_cpp":
|
|
119
|
-
if LlamaCppProvider is None:
|
|
120
|
-
return RulesOnlyProvider()
|
|
121
|
-
try:
|
|
122
|
-
return LlamaCppProvider(self.config.model, status.model_path)
|
|
123
|
-
except Exception:
|
|
124
|
-
return RulesOnlyProvider()
|
|
125
|
-
|
|
126
|
-
return RulesOnlyProvider()
|
|
127
|
-
|
|
128
|
-
def _register_hooks(self) -> None:
|
|
129
|
-
self._orig_sys_hook = sys.excepthook
|
|
130
|
-
sys.excepthook = self._sys_excepthook
|
|
131
|
-
if hasattr(threading, "excepthook"):
|
|
132
|
-
self._orig_thread_hook = threading.excepthook
|
|
133
|
-
threading.excepthook = self._thread_excepthook
|
|
134
|
-
|
|
135
|
-
if self.capabilities and self.capabilities.environment == "idle":
|
|
136
|
-
self._install_idle_hook()
|
|
137
|
-
|
|
138
|
-
def _install_idle_hook(self) -> None:
|
|
139
|
-
"""IDLE runs user code inside idlelib.run's own exec/except loop and
|
|
140
|
-
prints tracebacks itself via idlelib.run.print_exception, so the
|
|
141
|
-
exception never reaches sys.excepthook. Patch that function directly.
|
|
142
|
-
"""
|
|
143
|
-
try:
|
|
144
|
-
import idlelib.run as idle_run
|
|
145
|
-
except ImportError: # pragma: no cover - not actually running under IDLE
|
|
146
|
-
return
|
|
147
|
-
|
|
148
|
-
if self._idle_hook_installed:
|
|
149
|
-
return
|
|
150
|
-
|
|
151
|
-
self._orig_idle_print_exception = idle_run.print_exception
|
|
152
|
-
|
|
153
|
-
def patched_print_exception() -> None:
|
|
154
|
-
exc_type, exc_value, exc_tb = sys.exc_info()
|
|
155
|
-
handled = False
|
|
156
|
-
if exc_type is not None:
|
|
157
|
-
handled = self.process_exception(exc_type, exc_value, exc_tb)
|
|
158
|
-
if handled:
|
|
159
|
-
print("[errorai] exception intercepted")
|
|
160
|
-
return
|
|
161
|
-
if self._orig_idle_print_exception is not None:
|
|
162
|
-
self._orig_idle_print_exception()
|
|
163
|
-
|
|
164
|
-
idle_run.print_exception = patched_print_exception
|
|
165
|
-
self._idle_hook_installed = True
|
|
166
|
-
|
|
167
|
-
def _uninstall_idle_hook(self) -> None:
|
|
168
|
-
if not self._idle_hook_installed:
|
|
169
|
-
return
|
|
170
|
-
try:
|
|
171
|
-
import idlelib.run as idle_run
|
|
172
|
-
except ImportError: # pragma: no cover
|
|
173
|
-
self._idle_hook_installed = False
|
|
174
|
-
return
|
|
175
|
-
if self._orig_idle_print_exception is not None:
|
|
176
|
-
idle_run.print_exception = self._orig_idle_print_exception
|
|
177
|
-
self._idle_hook_installed = False
|
|
178
|
-
|
|
179
|
-
def _sys_excepthook(self, exc_type, exc_value, exc_tb):
|
|
180
|
-
handled = self.process_exception(exc_type, exc_value, exc_tb)
|
|
181
|
-
if handled:
|
|
182
|
-
print("[errorai] exception intercepted")
|
|
183
|
-
return
|
|
184
|
-
if self._orig_sys_hook:
|
|
185
|
-
self._orig_sys_hook(exc_type, exc_value, exc_tb)
|
|
186
|
-
|
|
187
|
-
def _thread_excepthook(self, args):
|
|
188
|
-
handled = self.process_exception(args.exc_type, args.exc_value, args.exc_traceback)
|
|
189
|
-
if handled:
|
|
190
|
-
print("[errorai] thread exception intercepted")
|
|
191
|
-
return
|
|
192
|
-
if self._orig_thread_hook:
|
|
193
|
-
self._orig_thread_hook(args)
|
|
194
|
-
|
|
195
|
-
def process_exception(self, exc_type, exc_value, exc_tb: TracebackType | None) -> bool:
|
|
196
|
-
if not exc_tb or not self.analyzer or not self.planner or not self.applier or not self.reporter:
|
|
197
|
-
return False
|
|
198
|
-
tb_list = traceback.extract_tb(exc_tb)
|
|
199
|
-
if not tb_list:
|
|
200
|
-
return False
|
|
201
|
-
frame = tb_list[-1]
|
|
202
|
-
filename = frame.filename
|
|
203
|
-
line = linecache.getline(filename, frame.lineno).strip() if filename else ""
|
|
204
|
-
analysis = self.analyzer.analyze_exception(exc_type, exc_value, exc_tb)
|
|
205
|
-
try:
|
|
206
|
-
plan = self.planner.plan_line_fix(line or frame.line or "", analysis["message"])
|
|
207
|
-
except Exception as provider_exc:
|
|
208
|
-
# Never let a broken/missing model provider raise out of an
|
|
209
|
-
# exception hook -- that can crash the interpreter (or IDLE's
|
|
210
|
-
# subprocess) while it's in the middle of handling an exception.
|
|
211
|
-
self.reporter.log(
|
|
212
|
-
"provider.error",
|
|
213
|
-
{"analysis": analysis, "error": f"{type(provider_exc).__name__}: {provider_exc}"},
|
|
214
|
-
)
|
|
215
|
-
print(f"[errorai] Model provider failed ({type(provider_exc).__name__}: {provider_exc})")
|
|
216
|
-
return False
|
|
217
|
-
|
|
218
|
-
if not plan or not filename or "<" in filename:
|
|
219
|
-
self.reporter.log("exception.analyzed", {"analysis": analysis, "fixed": False})
|
|
220
|
-
print(f"[errorai] Caught {analysis['type']}: {analysis['message']}")
|
|
221
|
-
print("[errorai] No automatic fix rule matched this error.")
|
|
222
|
-
return False
|
|
223
|
-
|
|
224
|
-
print(f"[errorai] Caught {analysis['type']}: {analysis['message']}")
|
|
225
|
-
print(f"[errorai] Suggested fix -> {plan}")
|
|
226
|
-
|
|
227
|
-
if self.capabilities and self.capabilities.can_prompt_user:
|
|
228
|
-
try:
|
|
229
|
-
answer = input("[errorai] Should I fix it [Y/N]: ").strip().lower()
|
|
230
|
-
except (EOFError, OSError):
|
|
231
|
-
answer = "n"
|
|
232
|
-
if answer not in {"y", "yes"}:
|
|
233
|
-
self.reporter.log("exception.declined", {"analysis": analysis})
|
|
234
|
-
print("[errorai] Skipped.")
|
|
235
|
-
return False
|
|
236
|
-
|
|
237
|
-
result = self.applier.apply_line_change(Path(filename), frame.lineno, plan)
|
|
238
|
-
self.reporter.log(
|
|
239
|
-
"exception.handled",
|
|
240
|
-
{
|
|
241
|
-
"analysis": analysis,
|
|
242
|
-
"changed": result.changed,
|
|
243
|
-
"detail": result.detail,
|
|
244
|
-
"preview": result.preview,
|
|
245
|
-
},
|
|
246
|
-
)
|
|
247
|
-
if result.preview and not result.changed:
|
|
248
|
-
print("[errorai] suggested fix (dry-run, not applied):")
|
|
249
|
-
print(result.preview)
|
|
250
|
-
print("[errorai] set dry_run = false in .errorai.toml to auto-apply")
|
|
251
|
-
elif result.changed:
|
|
252
|
-
print(f"[errorai] Applied fix to {filename}:{frame.lineno}")
|
|
253
|
-
return result.changed
|
|
254
|
-
|
|
255
|
-
def status_report(self) -> dict[str, Any]:
|
|
256
|
-
cfg = self.config or load_config()
|
|
257
|
-
caps = self.capabilities or detect_capabilities()
|
|
258
|
-
model = model_status(cfg.model)
|
|
259
|
-
return {
|
|
260
|
-
"environment": caps.environment,
|
|
261
|
-
"can_watch_fs": caps.can_watch_fs,
|
|
262
|
-
"can_apply_patches": caps.can_apply_patches,
|
|
263
|
-
"mode": self.mode,
|
|
264
|
-
"model_ready": model.ready,
|
|
265
|
-
"model_mode": self.bootstrap_status.mode,
|
|
266
|
-
"model_detail": self.bootstrap_status.detail,
|
|
267
|
-
"dry_run": cfg.runtime.dry_run,
|
|
268
|
-
"project_root": str(cfg.runtime.project_root),
|
|
269
|
-
"idle_hook_installed": self._idle_hook_installed,
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
def install_model(self) -> BootstrapStatus:
|
|
273
|
-
if self.config is None:
|
|
274
|
-
self.config = load_config()
|
|
275
|
-
self.bootstrap_status = ensure_model(self.config.model, explicit=True)
|
|
276
|
-
return self.bootstrap_status
|
|
277
|
-
|
|
278
|
-
def configure(self, **overrides) -> None:
|
|
279
|
-
if self.config is None:
|
|
280
|
-
self.config = load_config()
|
|
281
|
-
runtime_values = overrides.get("runtime", {})
|
|
282
|
-
model_values = overrides.get("model", {})
|
|
283
|
-
self.config = ErrorAIConfig(
|
|
284
|
-
runtime=replace(self.config.runtime, **runtime_values),
|
|
285
|
-
model=replace(self.config.model, **model_values),
|
|
286
|
-
)
|
|
287
|
-
|
|
288
|
-
def shutdown(self) -> None:
|
|
289
|
-
sys.excepthook = self._orig_sys_hook
|
|
290
|
-
if hasattr(threading, "excepthook") and self._orig_thread_hook is not None:
|
|
291
|
-
threading.excepthook = self._orig_thread_hook
|
|
292
|
-
self._uninstall_idle_hook()
|
|
293
|
-
self._initialized = False
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
def get_runtime() -> RuntimeManager:
|
|
297
|
-
return RuntimeManager.get_instance()
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
def configure(**overrides) -> RuntimeManager:
|
|
301
|
-
runtime = get_runtime()
|
|
302
|
-
runtime.configure(**overrides)
|
|
303
|
-
return runtime
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
def _reset_for_tests() -> None:
|
|
307
|
-
runtime = RuntimeManager._instance
|
|
308
|
-
if runtime is not None:
|
|
309
|
-
runtime.shutdown()
|
|
310
|
-
RuntimeManager._instance = None
|
|
311
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|