siftcode 0.3.1__py3-none-any.whl → 0.4.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.
- siftcode/_version.py +2 -2
- siftcode/cli.py +126 -29
- siftcode/core/analyzer.py +64 -8
- siftcode/core/config.py +71 -5
- siftcode/core/llm.py +147 -12
- siftcode/core/manual.py +28 -1
- siftcode/gui/analyzer_view.py +12 -0
- siftcode/gui/settings_view.py +59 -1
- {siftcode-0.3.1.dist-info → siftcode-0.4.0.dist-info}/METADATA +154 -27
- {siftcode-0.3.1.dist-info → siftcode-0.4.0.dist-info}/RECORD +14 -14
- {siftcode-0.3.1.dist-info → siftcode-0.4.0.dist-info}/WHEEL +0 -0
- {siftcode-0.3.1.dist-info → siftcode-0.4.0.dist-info}/entry_points.txt +0 -0
- {siftcode-0.3.1.dist-info → siftcode-0.4.0.dist-info}/licenses/LICENSE +0 -0
- {siftcode-0.3.1.dist-info → siftcode-0.4.0.dist-info}/top_level.txt +0 -0
siftcode/_version.py
CHANGED
|
@@ -38,9 +38,9 @@ __all__ = [
|
|
|
38
38
|
]
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
__version__ = "0.
|
|
41
|
+
__version__ = "0.4.0"
|
|
42
42
|
__version_info__ = tuple(int(p) for p in __version__.split(".") if p.isdigit())
|
|
43
|
-
__release_date__ = "2026-
|
|
43
|
+
__release_date__ = "2026-11-12"
|
|
44
44
|
__status__ = "beta"
|
|
45
45
|
|
|
46
46
|
APP_ID = "io.codeberg.lahtis.Siftcode"
|
siftcode/cli.py
CHANGED
|
@@ -38,13 +38,17 @@ from siftcode.core.analyzer import ProjectAnalyzer
|
|
|
38
38
|
from siftcode.core.cache import AnalysisCache
|
|
39
39
|
from siftcode.core.config import (
|
|
40
40
|
PROJECTS_DIR,
|
|
41
|
+
ModelConfig,
|
|
41
42
|
ProjectConfig,
|
|
42
43
|
delete_project,
|
|
43
44
|
list_projects,
|
|
44
45
|
load_project,
|
|
45
46
|
save_project,
|
|
46
47
|
)
|
|
47
|
-
from siftcode.core.llm import
|
|
48
|
+
from siftcode.core.llm import (
|
|
49
|
+
LLMError,
|
|
50
|
+
OllamaClient,
|
|
51
|
+
)
|
|
48
52
|
from siftcode.core.manual import SpecGenerator
|
|
49
53
|
|
|
50
54
|
|
|
@@ -96,21 +100,65 @@ def _resolve_project(name_or_path: str) -> ProjectConfig:
|
|
|
96
100
|
)
|
|
97
101
|
|
|
98
102
|
|
|
99
|
-
def
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
f"error: cannot reach Ollama at {client.config.ollama_url}\n"
|
|
103
|
-
f"hint: make sure the Ollama server is running.\n"
|
|
104
|
-
f" Try: ollama serve"
|
|
105
|
-
)
|
|
103
|
+
def _parse_model_stages(specs: list[str]) -> dict[str, str]:
|
|
104
|
+
"""
|
|
105
|
+
Parse --model-stage STAGE=MODEL arguments into a dict.
|
|
106
106
|
|
|
107
|
+
Raises ValueError with a user-friendly message if any spec is
|
|
108
|
+
malformed. Used by cmd_analyze before config.validate() so the
|
|
109
|
+
error is reported as a CLI error (exit 2) rather than a config
|
|
110
|
+
validation error.
|
|
111
|
+
"""
|
|
112
|
+
stages: dict[str, str] = {}
|
|
113
|
+
for spec in specs:
|
|
114
|
+
if "=" not in spec:
|
|
115
|
+
raise ValueError(
|
|
116
|
+
f"--model-stage requires STAGE=MODEL, got {spec!r}.\n"
|
|
117
|
+
f"Valid stages: {', '.join(ModelConfig.VALID_STAGES)}"
|
|
118
|
+
)
|
|
119
|
+
stage, _, model_name = spec.partition("=")
|
|
120
|
+
stage = stage.strip()
|
|
121
|
+
model_name = model_name.strip()
|
|
122
|
+
if not stage or not model_name:
|
|
123
|
+
raise ValueError(
|
|
124
|
+
f"--model-stage requires STAGE=MODEL, got {spec!r}.\n"
|
|
125
|
+
f"Valid stages: {', '.join(ModelConfig.VALID_STAGES)}"
|
|
126
|
+
)
|
|
127
|
+
if stage not in ModelConfig.VALID_STAGES:
|
|
128
|
+
raise ValueError(
|
|
129
|
+
f"unknown stage '{stage}' in --model-stage.\n"
|
|
130
|
+
f"Valid stages: {', '.join(ModelConfig.VALID_STAGES)}"
|
|
131
|
+
)
|
|
132
|
+
stages[stage] = model_name
|
|
133
|
+
return stages
|
|
107
134
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
135
|
+
|
|
136
|
+
def _check_ollama(client: OllamaClient, config: ProjectConfig) -> None:
|
|
137
|
+
"""
|
|
138
|
+
Verify Ollama is reachable AND all configured models are installed.
|
|
139
|
+
|
|
140
|
+
The actual diagnosis (DNS vs refused vs timeout) is done by
|
|
141
|
+
OllamaClient.check_connection() in llm.py, so both the CLI and
|
|
142
|
+
the GUI get the same user-friendly messages from one place.
|
|
143
|
+
|
|
144
|
+
All models referenced by config.model.stages are checked here
|
|
145
|
+
so a missing model fails at startup, not 20 minutes into a run
|
|
146
|
+
when the guide stage tries to load it.
|
|
147
|
+
"""
|
|
148
|
+
try:
|
|
149
|
+
client.check_connection()
|
|
150
|
+
except LLMError as e:
|
|
151
|
+
raise SystemExit(f"error: {e}")
|
|
152
|
+
|
|
153
|
+
# Collect every model the run will use: the default plus any
|
|
154
|
+
# stage-specific overrides.
|
|
155
|
+
models = {config.model.name} | set(config.model.stages.values())
|
|
156
|
+
for model in sorted(models):
|
|
157
|
+
if not client.has_model(model):
|
|
158
|
+
raise SystemExit(
|
|
159
|
+
f"error: model '{model}' is not installed in Ollama\n"
|
|
160
|
+
f"hint: install it with: ollama pull {model}"
|
|
161
|
+
)
|
|
114
162
|
|
|
115
163
|
|
|
116
164
|
def _print_progress(progress) -> None:
|
|
@@ -191,9 +239,23 @@ def cmd_analyze(args: argparse.Namespace) -> int:
|
|
|
191
239
|
config.model.name = args.model
|
|
192
240
|
if args.num_ctx:
|
|
193
241
|
config.model.num_ctx = args.num_ctx
|
|
242
|
+
if getattr(args, "spec_num_ctx", None):
|
|
243
|
+
config.model.spec_num_ctx = args.spec_num_ctx
|
|
194
244
|
if args.timeout:
|
|
195
245
|
config.model.timeout = args.timeout
|
|
196
246
|
|
|
247
|
+
# Parse --model-stage arguments into config.model.stages. Done
|
|
248
|
+
# before validate() so malformed specs are reported as CLI errors
|
|
249
|
+
# (exit 2) rather than config validation errors.
|
|
250
|
+
if getattr(args, "model_stage", None):
|
|
251
|
+
try:
|
|
252
|
+
config.model.stages.update(
|
|
253
|
+
_parse_model_stages(args.model_stage)
|
|
254
|
+
)
|
|
255
|
+
except ValueError as e:
|
|
256
|
+
print(f"error: {e}", file=sys.stderr)
|
|
257
|
+
return 2
|
|
258
|
+
|
|
197
259
|
# Validate BEFORE persisting, so we never save a broken config.
|
|
198
260
|
config.validate()
|
|
199
261
|
|
|
@@ -202,7 +264,7 @@ def cmd_analyze(args: argparse.Namespace) -> int:
|
|
|
202
264
|
try:
|
|
203
265
|
load_project(config.name)
|
|
204
266
|
save_project(config)
|
|
205
|
-
logger.info(
|
|
267
|
+
logger.info("Updated saved project '%s'", config.name)
|
|
206
268
|
except FileNotFoundError:
|
|
207
269
|
pass
|
|
208
270
|
except ValueError as e:
|
|
@@ -215,17 +277,20 @@ def cmd_analyze(args: argparse.Namespace) -> int:
|
|
|
215
277
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
216
278
|
|
|
217
279
|
client = OllamaClient(config.model)
|
|
218
|
-
_check_ollama(client)
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
logger.info(
|
|
222
|
-
|
|
223
|
-
|
|
280
|
+
_check_ollama(client, config)
|
|
281
|
+
|
|
282
|
+
logger.info("Analyzing: %s", config.path)
|
|
283
|
+
logger.info("Model: %s", config.model.name)
|
|
284
|
+
if config.model.stages:
|
|
285
|
+
for stage, model_name in sorted(config.model.stages.items()):
|
|
286
|
+
logger.info(" %-12s %s", f"{stage}:", model_name)
|
|
287
|
+
logger.info("Context: %d tokens", config.model.num_ctx)
|
|
288
|
+
if args.advanced:
|
|
289
|
+
logger.info("Spec ctx: %d tokens", config.model.spec_num_ctx)
|
|
224
290
|
|
|
225
291
|
# One timestamp for the whole run: findings/guide/specs all share it.
|
|
226
292
|
run_stamp = _stamp()
|
|
227
293
|
project_stem = _safe_stem(config.name)
|
|
228
|
-
is_tty = sys.stdout.isatty()
|
|
229
294
|
|
|
230
295
|
# ------------------------------------------------------------------
|
|
231
296
|
# Advanced per-file specification mode
|
|
@@ -257,12 +322,14 @@ def cmd_analyze(args: argparse.Namespace) -> int:
|
|
|
257
322
|
filled = int(bar_width * fraction)
|
|
258
323
|
bar = "█" * filled + "░" * (bar_width - filled)
|
|
259
324
|
msg = f" [{bar}] {fraction * 100:5.1f}% ({current}/{total}) {rel}"
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
325
|
+
|
|
326
|
+
cols = shutil.get_terminal_size().columns
|
|
327
|
+
if len(msg) > cols - 1:
|
|
328
|
+
msg = msg[: cols - 4] + "..."
|
|
329
|
+
|
|
330
|
+
print(f"\r\033[K{msg}", end="", file=sys.stderr, flush=True)
|
|
331
|
+
if fraction >= 1.0:
|
|
332
|
+
print(file=sys.stderr)
|
|
266
333
|
|
|
267
334
|
try:
|
|
268
335
|
specs_dict = spec_gen.generate_project_specs(
|
|
@@ -402,6 +469,11 @@ def cmd_list(args: argparse.Namespace) -> int:
|
|
|
402
469
|
print(f" {marker} {p.name}")
|
|
403
470
|
print(f" path: {p.path}")
|
|
404
471
|
print(f" model: {p.model.name}")
|
|
472
|
+
if p.model.stages:
|
|
473
|
+
stages_str = ", ".join(
|
|
474
|
+
f"{s}={m}" for s, m in sorted(p.model.stages.items())
|
|
475
|
+
)
|
|
476
|
+
print(f" stages: {stages_str}")
|
|
405
477
|
print(f" last run: {last}")
|
|
406
478
|
if p.notes:
|
|
407
479
|
print(f" notes: {p.notes}")
|
|
@@ -429,8 +501,17 @@ def cmd_show(args: argparse.Namespace) -> int:
|
|
|
429
501
|
print()
|
|
430
502
|
print("Model:")
|
|
431
503
|
print(f" Name: {config.model.name}")
|
|
504
|
+
if config.model.stages:
|
|
505
|
+
print(" Stages:")
|
|
506
|
+
for stage in ModelConfig.VALID_STAGES:
|
|
507
|
+
override = config.model.stages.get(stage, "")
|
|
508
|
+
if override:
|
|
509
|
+
print(f" {stage:12s} {override}")
|
|
510
|
+
else:
|
|
511
|
+
print(f" {stage:12s} (default)")
|
|
432
512
|
print(f" Ollama URL: {config.model.ollama_url}")
|
|
433
513
|
print(f" num_ctx: {config.model.num_ctx}")
|
|
514
|
+
print(f" spec_num_ctx: {config.model.spec_num_ctx}")
|
|
434
515
|
print(f" temperature: {config.model.temperature}")
|
|
435
516
|
print(f" timeout: {config.model.timeout}s")
|
|
436
517
|
print()
|
|
@@ -554,12 +635,28 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
554
635
|
)
|
|
555
636
|
p_analyze.add_argument(
|
|
556
637
|
"-m", "--model",
|
|
557
|
-
help="Override LLM model (e.g. qwen2.5-coder:14b)"
|
|
638
|
+
help="Override LLM model for all stages (e.g. qwen2.5-coder:14b). "
|
|
639
|
+
"With 24 GB+ VRAM, use --model-stage for per-stage overrides.",
|
|
640
|
+
)
|
|
641
|
+
p_analyze.add_argument(
|
|
642
|
+
"--model-stage",
|
|
643
|
+
action="append",
|
|
644
|
+
default=[],
|
|
645
|
+
metavar="STAGE=MODEL",
|
|
646
|
+
help="Override model for a specific stage (repeatable). "
|
|
647
|
+
"Valid stages: root, file, directories, guide. "
|
|
648
|
+
"Example: --model-stage guide=qwen2.5-coder:32b",
|
|
558
649
|
)
|
|
559
650
|
p_analyze.add_argument(
|
|
560
651
|
"--num-ctx", type=int,
|
|
561
652
|
help="Override context length in tokens",
|
|
562
653
|
)
|
|
654
|
+
p_analyze.add_argument(
|
|
655
|
+
"--spec-num-ctx", type=int,
|
|
656
|
+
help="Context length for --advanced per-file specs "
|
|
657
|
+
"(default: 16384). Lower this on GPUs with limited VRAM "
|
|
658
|
+
"to keep the model fully on the GPU.",
|
|
659
|
+
)
|
|
563
660
|
p_analyze.add_argument(
|
|
564
661
|
"--timeout", type=int,
|
|
565
662
|
help="Override per-request timeout in seconds",
|
siftcode/core/analyzer.py
CHANGED
|
@@ -12,7 +12,7 @@ from __future__ import annotations
|
|
|
12
12
|
|
|
13
13
|
import json
|
|
14
14
|
import logging
|
|
15
|
-
from dataclasses import dataclass, field
|
|
15
|
+
from dataclasses import dataclass, field, replace
|
|
16
16
|
from datetime import datetime
|
|
17
17
|
from pathlib import Path
|
|
18
18
|
from typing import Iterator
|
|
@@ -115,8 +115,26 @@ class ProjectAnalyzer:
|
|
|
115
115
|
|
|
116
116
|
findings = analyzer.findings
|
|
117
117
|
findings.save(Path("findings.json"))
|
|
118
|
+
|
|
119
|
+
Multi-model support:
|
|
120
|
+
|
|
121
|
+
The model used for each stage can be overridden via
|
|
122
|
+
config.model.stages. For example, a 24 GB GPU can use a
|
|
123
|
+
small model for per-file analysis and a larger one for the
|
|
124
|
+
root summary and the final guide:
|
|
125
|
+
|
|
126
|
+
config.model.stages = {
|
|
127
|
+
"root": "qwen2.5-coder:32b",
|
|
128
|
+
"guide": "qwen2.5-coder:32b",
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
Stages without an override fall back to config.model.name.
|
|
118
132
|
"""
|
|
119
133
|
|
|
134
|
+
# Analysis stages, in pipeline order. Kept in sync with
|
|
135
|
+
# ModelConfig.VALID_STAGES; if you add a stage here, add it there too.
|
|
136
|
+
STAGES: tuple[str, ...] = ("root", "file", "directories", "guide")
|
|
137
|
+
|
|
120
138
|
# Fraction of total work allocated to each phase
|
|
121
139
|
ROOT_WEIGHT = 0.05
|
|
122
140
|
FILES_WEIGHT = 0.70
|
|
@@ -142,7 +160,12 @@ class ProjectAnalyzer:
|
|
|
142
160
|
cache: AnalysisCache | None = None,
|
|
143
161
|
) -> None:
|
|
144
162
|
self.config = config
|
|
163
|
+
# The caller-provided client is registered under the default
|
|
164
|
+
# model name, so we never re-create it. Additional clients for
|
|
165
|
+
# stage-specific models are created lazily by _client_for().
|
|
145
166
|
self.client = client
|
|
167
|
+
self._clients: dict[str, OllamaClient] = {config.model.name: client}
|
|
168
|
+
|
|
146
169
|
# Create a default cache unless caller provides one
|
|
147
170
|
self.cache = cache if cache is not None else AnalysisCache(
|
|
148
171
|
enabled=config.analysis.use_cache,
|
|
@@ -152,6 +175,39 @@ class ProjectAnalyzer:
|
|
|
152
175
|
# Log-related paths (set on analyze_project())
|
|
153
176
|
self._log_dir: Path | None = None
|
|
154
177
|
|
|
178
|
+
# ------------------------------------------------------------------
|
|
179
|
+
# Multi-model helpers
|
|
180
|
+
# ------------------------------------------------------------------
|
|
181
|
+
|
|
182
|
+
def model_for(self, stage: str) -> str:
|
|
183
|
+
"""
|
|
184
|
+
Return the model name to use for a given analysis stage.
|
|
185
|
+
|
|
186
|
+
Stages with an entry in config.model.stages use that model;
|
|
187
|
+
all others fall back to config.model.name. This makes
|
|
188
|
+
multi-model support purely opt-in: an empty `stages` dict
|
|
189
|
+
(the default) behaves exactly like the single-model case.
|
|
190
|
+
"""
|
|
191
|
+
return self.config.model.stages.get(stage, self.config.model.name)
|
|
192
|
+
|
|
193
|
+
def _client_for(self, stage: str) -> OllamaClient:
|
|
194
|
+
"""
|
|
195
|
+
Return the OllamaClient for a given stage.
|
|
196
|
+
|
|
197
|
+
Clients are cached per model name, so repeated calls for the
|
|
198
|
+
same stage (or for different stages that happen to share a
|
|
199
|
+
model) reuse the same client — and therefore the same
|
|
200
|
+
HTTP connection pool and retry state.
|
|
201
|
+
"""
|
|
202
|
+
name = self.model_for(stage)
|
|
203
|
+
if name not in self._clients:
|
|
204
|
+
# dataclasses.replace preserves ollama_url, num_ctx,
|
|
205
|
+
# temperature, timeout, etc. — only the model name changes.
|
|
206
|
+
self._clients[name] = OllamaClient(
|
|
207
|
+
replace(self.config.model, name=name)
|
|
208
|
+
)
|
|
209
|
+
return self._clients[name]
|
|
210
|
+
|
|
155
211
|
# ------------------------------------------------------------------
|
|
156
212
|
# Public API
|
|
157
213
|
# ------------------------------------------------------------------
|
|
@@ -247,7 +303,7 @@ class ProjectAnalyzer:
|
|
|
247
303
|
f"{manifest}"
|
|
248
304
|
)
|
|
249
305
|
key = string_hash(key_input)
|
|
250
|
-
model = self.
|
|
306
|
+
model = self.model_for("root")
|
|
251
307
|
|
|
252
308
|
cached = self.cache.get_root(key, model=model)
|
|
253
309
|
if cached is not None:
|
|
@@ -261,7 +317,7 @@ class ProjectAnalyzer:
|
|
|
261
317
|
)
|
|
262
318
|
|
|
263
319
|
try:
|
|
264
|
-
response = self.
|
|
320
|
+
response = self._client_for("root").chat(
|
|
265
321
|
system=prompts.SYSTEM_ROOT,
|
|
266
322
|
user=user_prompt,
|
|
267
323
|
)
|
|
@@ -387,7 +443,7 @@ class ProjectAnalyzer:
|
|
|
387
443
|
|
|
388
444
|
content = self._truncate(content, self.config.analysis.max_file_chars)
|
|
389
445
|
|
|
390
|
-
model = self.
|
|
446
|
+
model = self.model_for("file")
|
|
391
447
|
# Context is built BEFORE the cache lookup so that the cache key
|
|
392
448
|
# reflects the same context the LLM would actually see. This
|
|
393
449
|
# avoids stale cache hits when, e.g., the root summary or a
|
|
@@ -410,7 +466,7 @@ class ProjectAnalyzer:
|
|
|
410
466
|
)
|
|
411
467
|
|
|
412
468
|
try:
|
|
413
|
-
response = self.
|
|
469
|
+
response = self._client_for("file").chat(
|
|
414
470
|
system=prompts.SYSTEM_FILE,
|
|
415
471
|
user=user_prompt,
|
|
416
472
|
)
|
|
@@ -523,7 +579,7 @@ class ProjectAnalyzer:
|
|
|
523
579
|
return # no summaries, skip
|
|
524
580
|
|
|
525
581
|
file_summaries = "\n".join(parts)
|
|
526
|
-
model = self.
|
|
582
|
+
model = self.model_for("directories")
|
|
527
583
|
|
|
528
584
|
# Cache key: prompt version + directory path + hash of the
|
|
529
585
|
# file summaries we're feeding the LLM. If any file summary
|
|
@@ -546,7 +602,7 @@ class ProjectAnalyzer:
|
|
|
546
602
|
)
|
|
547
603
|
|
|
548
604
|
try:
|
|
549
|
-
response = self.
|
|
605
|
+
response = self._client_for("directories").chat(
|
|
550
606
|
system=prompts.SYSTEM_DIRECTORY,
|
|
551
607
|
user=user_prompt,
|
|
552
608
|
)
|
|
@@ -575,7 +631,7 @@ class ProjectAnalyzer:
|
|
|
575
631
|
)
|
|
576
632
|
|
|
577
633
|
try:
|
|
578
|
-
response = self.
|
|
634
|
+
response = self._client_for("guide").chat(
|
|
579
635
|
system=prompts.SYSTEM_GUIDE,
|
|
580
636
|
user=user_prompt,
|
|
581
637
|
max_tokens=self.config.model.max_tokens_guide,
|
siftcode/core/config.py
CHANGED
|
@@ -11,7 +11,7 @@ import re
|
|
|
11
11
|
import tomllib
|
|
12
12
|
from dataclasses import dataclass, field, asdict
|
|
13
13
|
from pathlib import Path
|
|
14
|
-
from typing import Any
|
|
14
|
+
from typing import Any, ClassVar
|
|
15
15
|
|
|
16
16
|
import tomli_w
|
|
17
17
|
from platformdirs import user_config_dir, user_cache_dir
|
|
@@ -76,6 +76,8 @@ DEFAULT_EXCLUSIONS = [
|
|
|
76
76
|
".pdf", ".zip", ".tar", ".gz", ".whl", ".so", ".dll", ".exe",
|
|
77
77
|
".ttf", ".otf", ".woff", ".woff2",
|
|
78
78
|
".pyc", ".pyo",
|
|
79
|
+
# Database files (binary, not analyzable as text)
|
|
80
|
+
".sqlite", ".sqlite3", ".db", ".db3", ".mdb",
|
|
79
81
|
# Lock files
|
|
80
82
|
".lock",
|
|
81
83
|
# Coverage data
|
|
@@ -96,16 +98,56 @@ DEFAULT_EXCLUSIONS = [
|
|
|
96
98
|
|
|
97
99
|
@dataclass
|
|
98
100
|
class ModelConfig:
|
|
99
|
-
"""
|
|
101
|
+
"""
|
|
102
|
+
LLM settings for a single analysis run.
|
|
103
|
+
|
|
104
|
+
`name` is the default model used for every analysis stage. The
|
|
105
|
+
`stages` dict allows per-stage overrides without touching the rest
|
|
106
|
+
of the config. Stages that are not present in `stages` fall back
|
|
107
|
+
to `name`.
|
|
108
|
+
|
|
109
|
+
Example TOML:
|
|
110
|
+
|
|
111
|
+
[model]
|
|
112
|
+
name = "qwen2.5-coder:14b"
|
|
113
|
+
num_ctx = 8192
|
|
114
|
+
|
|
115
|
+
[model.stages]
|
|
116
|
+
root = "qwen2.5-coder:32b"
|
|
117
|
+
guide = "qwen2.5-coder:32b"
|
|
118
|
+
"""
|
|
100
119
|
|
|
101
120
|
name: str = "qwen2.5-coder:14b"
|
|
102
|
-
ollama_url: str = "http://
|
|
103
|
-
num_ctx: int =
|
|
121
|
+
ollama_url: str = "http://127.0.0.1:11434"
|
|
122
|
+
num_ctx: int = 8192
|
|
104
123
|
temperature: float = 0.0
|
|
105
|
-
timeout: int =
|
|
124
|
+
timeout: int = 600
|
|
106
125
|
max_tokens_file: int = 1000
|
|
107
126
|
max_tokens_guide: int = 8000
|
|
108
127
|
|
|
128
|
+
# Context length specifically for --advanced per-file specs.
|
|
129
|
+
# Specs are long-form documents (overview, class reference, test
|
|
130
|
+
# matrix) and need more room than the regular num_ctx. Lower this
|
|
131
|
+
# on GPUs with limited VRAM to keep the whole model on the GPU.
|
|
132
|
+
spec_num_ctx: int = 16384
|
|
133
|
+
|
|
134
|
+
# Per-stage model overrides. Empty by default — every stage uses
|
|
135
|
+
# `name` unless explicitly overridden.
|
|
136
|
+
stages: dict[str, str] = field(default_factory=dict)
|
|
137
|
+
|
|
138
|
+
# Stages that may appear as keys in `stages`. Kept in sync with
|
|
139
|
+
# ProjectAnalyzer's analysis pipeline. Unknown keys are rejected
|
|
140
|
+
# in validate() so a typo like "gudie" is caught immediately
|
|
141
|
+
# instead of silently being ignored.
|
|
142
|
+
#
|
|
143
|
+
# ClassVar is essential: without it, dataclasses.asdict() would
|
|
144
|
+
# copy VALID_STAGES into every saved TOML file, and
|
|
145
|
+
# ModelConfig(**model_data) would then receive it as a keyword
|
|
146
|
+
# argument — which the constructor does not accept.
|
|
147
|
+
VALID_STAGES: ClassVar[tuple[str, ...]] = (
|
|
148
|
+
"root", "file", "directories", "guide"
|
|
149
|
+
)
|
|
150
|
+
|
|
109
151
|
def validate(self) -> None:
|
|
110
152
|
"""Raise ValueError if any field is out of acceptable range."""
|
|
111
153
|
if not isinstance(self.name, str) or not self.name.strip():
|
|
@@ -125,6 +167,30 @@ class ModelConfig:
|
|
|
125
167
|
f"ollama_url must start with http:// or https://, "
|
|
126
168
|
f"got {self.ollama_url}"
|
|
127
169
|
)
|
|
170
|
+
if self.spec_num_ctx < 512 or self.spec_num_ctx > 131072:
|
|
171
|
+
raise ValueError(
|
|
172
|
+
f"spec_num_ctx must be between 512 and 131072, "
|
|
173
|
+
f"got {self.spec_num_ctx}"
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
# Validate per-stage overrides. Unknown keys are almost always
|
|
177
|
+
# typos; rejecting them early is far cheaper than debugging why
|
|
178
|
+
# an override "didn't take effect" twenty minutes into a run.
|
|
179
|
+
if not isinstance(self.stages, dict):
|
|
180
|
+
raise ValueError(
|
|
181
|
+
f"model.stages must be a table, "
|
|
182
|
+
f"got {type(self.stages).__name__}"
|
|
183
|
+
)
|
|
184
|
+
for stage, model_name in self.stages.items():
|
|
185
|
+
if stage not in self.VALID_STAGES:
|
|
186
|
+
raise ValueError(
|
|
187
|
+
f"model.stages contains unknown stage '{stage}'. "
|
|
188
|
+
f"Valid stages: {', '.join(self.VALID_STAGES)}"
|
|
189
|
+
)
|
|
190
|
+
if not isinstance(model_name, str) or not model_name.strip():
|
|
191
|
+
raise ValueError(
|
|
192
|
+
f"model.stages['{stage}'] must be a non-empty string"
|
|
193
|
+
)
|
|
128
194
|
|
|
129
195
|
|
|
130
196
|
@dataclass
|
siftcode/core/llm.py
CHANGED
|
@@ -11,6 +11,7 @@ No GTK dependencies — this module is testable in isolation.
|
|
|
11
11
|
from __future__ import annotations
|
|
12
12
|
|
|
13
13
|
import logging
|
|
14
|
+
import socket
|
|
14
15
|
import time
|
|
15
16
|
from dataclasses import dataclass
|
|
16
17
|
from typing import Any
|
|
@@ -106,11 +107,18 @@ class OllamaClient:
|
|
|
106
107
|
|
|
107
108
|
# Retry configuration
|
|
108
109
|
MAX_RETRIES = 3
|
|
109
|
-
RETRY_BACKOFF =
|
|
110
|
+
RETRY_BACKOFF = 0.5 # seconds, multiplied by attempt number
|
|
111
|
+
|
|
112
|
+
# Circuit breaker: after this many consecutive connection errors,
|
|
113
|
+
# stop trying. Ollama is either down or unreachable; retrying every
|
|
114
|
+
# remaining file would waste minutes of the user's time.
|
|
115
|
+
CIRCUIT_BREAKER_THRESHOLD = 5
|
|
110
116
|
|
|
111
117
|
def __init__(self, config: ModelConfig) -> None:
|
|
112
118
|
self.config = config
|
|
113
119
|
self._session = requests.Session()
|
|
120
|
+
self._consecutive_connection_errors = 0
|
|
121
|
+
self._circuit_open = False
|
|
114
122
|
|
|
115
123
|
# ------------------------------------------------------------------
|
|
116
124
|
# Public API
|
|
@@ -260,6 +268,106 @@ class OllamaClient:
|
|
|
260
268
|
return False
|
|
261
269
|
return any(name == m or m.startswith(name + ":") for m in available)
|
|
262
270
|
|
|
271
|
+
def ping(self) -> None:
|
|
272
|
+
"""
|
|
273
|
+
Raise on connection failure instead of returning bool.
|
|
274
|
+
|
|
275
|
+
Unlike is_available(), this method does not swallow the
|
|
276
|
+
underlying error: callers can inspect __cause__ to distinguish
|
|
277
|
+
DNS failures from refused connections and timeouts.
|
|
278
|
+
|
|
279
|
+
Raises:
|
|
280
|
+
LLMConnectionError: DNS failure, refused connection, or other
|
|
281
|
+
network error. The original exception is chained via
|
|
282
|
+
__cause__ so callers can inspect the root cause.
|
|
283
|
+
LLMTimeoutError: Server did not respond within 5 seconds.
|
|
284
|
+
"""
|
|
285
|
+
url = f"{self.config.ollama_url.rstrip('/')}/api/tags"
|
|
286
|
+
try:
|
|
287
|
+
self._session.get(url, timeout=5).raise_for_status()
|
|
288
|
+
except requests.Timeout as e:
|
|
289
|
+
raise LLMTimeoutError(f"Ollama at {url} timed out") from e
|
|
290
|
+
except requests.ConnectionError as e:
|
|
291
|
+
raise LLMConnectionError(
|
|
292
|
+
f"Cannot connect to Ollama at {url}: {e}"
|
|
293
|
+
) from e
|
|
294
|
+
except requests.RequestException as e:
|
|
295
|
+
raise LLMConnectionError(
|
|
296
|
+
f"Ollama request failed: {e}"
|
|
297
|
+
) from e
|
|
298
|
+
|
|
299
|
+
def check_connection(self) -> None:
|
|
300
|
+
"""
|
|
301
|
+
Verify Ollama is reachable before an analysis run.
|
|
302
|
+
|
|
303
|
+
Raises LLMConnectionError or LLMTimeoutError with a message
|
|
304
|
+
suitable for showing directly to the user. Distinguishes DNS
|
|
305
|
+
failures from refused connections so the user is not told to
|
|
306
|
+
"run ollama serve" when the real problem is that 'localhost'
|
|
307
|
+
does not resolve in their environment.
|
|
308
|
+
|
|
309
|
+
Both the CLI and the GUI call this before starting an analysis,
|
|
310
|
+
so users see a clear error immediately instead of waiting for
|
|
311
|
+
per-file retries to exhaust.
|
|
312
|
+
"""
|
|
313
|
+
url = self.config.ollama_url
|
|
314
|
+
try:
|
|
315
|
+
self.ping()
|
|
316
|
+
except LLMTimeoutError:
|
|
317
|
+
# Already has a good message: "Ollama at ... timed out"
|
|
318
|
+
raise
|
|
319
|
+
except LLMConnectionError as e:
|
|
320
|
+
root = self._find_root_cause(e)
|
|
321
|
+
|
|
322
|
+
if isinstance(root, socket.gaierror):
|
|
323
|
+
host = url.split("//")[-1].split(":")[0]
|
|
324
|
+
raise LLMConnectionError(
|
|
325
|
+
f"Cannot resolve hostname '{host}' in Ollama URL ({url}).\n"
|
|
326
|
+
f"DNS error: {root}\n"
|
|
327
|
+
f"Try 127.0.0.1 instead of localhost."
|
|
328
|
+
) from e
|
|
329
|
+
|
|
330
|
+
if isinstance(root, ConnectionRefusedError):
|
|
331
|
+
raise LLMConnectionError(
|
|
332
|
+
f"Ollama is not listening at {url}.\n"
|
|
333
|
+
f"Start it with: ollama serve"
|
|
334
|
+
) from e
|
|
335
|
+
|
|
336
|
+
# Fallback: requests/urllib3 may swallow the socket error
|
|
337
|
+
# object and only keep its message. Match on the errno text.
|
|
338
|
+
# [Errno 111] is ECONNREFUSED on Linux; the English phrase
|
|
339
|
+
# "connection refused" appears on other platforms.
|
|
340
|
+
msg = str(e)
|
|
341
|
+
if "[Errno 111]" in msg or "refused" in msg.lower():
|
|
342
|
+
raise LLMConnectionError(
|
|
343
|
+
f"Ollama is not listening at {url}.\n"
|
|
344
|
+
f"Start it with: ollama serve"
|
|
345
|
+
) from e
|
|
346
|
+
|
|
347
|
+
# Unknown cause: re-raise with the original message
|
|
348
|
+
# (already descriptive enough for the user)
|
|
349
|
+
raise
|
|
350
|
+
|
|
351
|
+
@staticmethod
|
|
352
|
+
def _find_root_cause(exc: BaseException) -> BaseException | None:
|
|
353
|
+
"""
|
|
354
|
+
Walk the exception chain looking for a socket-level root cause.
|
|
355
|
+
|
|
356
|
+
requests wraps socket errors in several layers, and depending
|
|
357
|
+
on the requests/urllib3 version the socket error may be
|
|
358
|
+
attached via __cause__ OR __context__. We follow both, guarded
|
|
359
|
+
by a visited-set to protect against self-referential chains.
|
|
360
|
+
"""
|
|
361
|
+
visited: set[int] = set()
|
|
362
|
+
cause: BaseException | None = exc
|
|
363
|
+
while cause is not None and id(cause) not in visited:
|
|
364
|
+
visited.add(id(cause))
|
|
365
|
+
if isinstance(cause, (socket.gaierror, ConnectionRefusedError)):
|
|
366
|
+
return cause
|
|
367
|
+
# Prefer __cause__ (explicit chaining), fall back to __context__
|
|
368
|
+
cause = cause.__cause__ or cause.__context__
|
|
369
|
+
return None
|
|
370
|
+
|
|
263
371
|
# ------------------------------------------------------------------
|
|
264
372
|
# Internal
|
|
265
373
|
# ------------------------------------------------------------------
|
|
@@ -271,13 +379,27 @@ class OllamaClient:
|
|
|
271
379
|
timeout: int,
|
|
272
380
|
model_name: str,
|
|
273
381
|
) -> dict[str, Any]:
|
|
274
|
-
"""
|
|
382
|
+
"""
|
|
383
|
+
POST with retry on transient errors. Does not retry on 4xx,
|
|
384
|
+
does not retry on connection errors (those are almost always
|
|
385
|
+
persistent — Ollama down, wrong port, DNS failure).
|
|
386
|
+
"""
|
|
387
|
+
if self._circuit_open:
|
|
388
|
+
raise LLMConnectionError(
|
|
389
|
+
f"Ollama connection lost after "
|
|
390
|
+
f"{self._consecutive_connection_errors} consecutive "
|
|
391
|
+
f"connection errors. Aborting further requests to avoid "
|
|
392
|
+
f"waiting for timeouts on every file. Check that Ollama "
|
|
393
|
+
f"is running at {self.config.ollama_url} and try again."
|
|
394
|
+
)
|
|
395
|
+
|
|
275
396
|
last_error: Exception | None = None
|
|
276
397
|
|
|
277
398
|
for attempt in range(1, self.MAX_RETRIES + 1):
|
|
278
399
|
try:
|
|
279
400
|
r = self._session.post(url, json=payload, timeout=timeout)
|
|
280
401
|
except requests.Timeout as e:
|
|
402
|
+
# Timeouts are often transient (model loading, CPU spike)
|
|
281
403
|
last_error = LLMTimeoutError(
|
|
282
404
|
f"Request to {url} timed out after {timeout}s "
|
|
283
405
|
f"(attempt {attempt}/{self.MAX_RETRIES})"
|
|
@@ -292,23 +414,32 @@ class OllamaClient:
|
|
|
292
414
|
raise last_error from e
|
|
293
415
|
|
|
294
416
|
except requests.ConnectionError as e:
|
|
295
|
-
|
|
417
|
+
# Connection errors are almost always persistent:
|
|
418
|
+
# Ollama not running, wrong port, DNS failure. Retrying
|
|
419
|
+
# 42 files × 3 attempts just wastes the user's time.
|
|
420
|
+
# Instead, increment the circuit-breaker counter and
|
|
421
|
+
# fail fast.
|
|
422
|
+
self._consecutive_connection_errors += 1
|
|
423
|
+
if self._consecutive_connection_errors >= self.CIRCUIT_BREAKER_THRESHOLD:
|
|
424
|
+
self._circuit_open = True
|
|
425
|
+
logger.error(
|
|
426
|
+
"Circuit breaker open after %d consecutive "
|
|
427
|
+
"connection errors. Further requests will fail "
|
|
428
|
+
"immediately.",
|
|
429
|
+
self._consecutive_connection_errors,
|
|
430
|
+
)
|
|
431
|
+
raise LLMConnectionError(
|
|
296
432
|
f"Cannot connect to Ollama at {url}: {e}"
|
|
297
|
-
)
|
|
298
|
-
logger.warning(
|
|
299
|
-
"Chat attempt %d/%d connection error: %s",
|
|
300
|
-
attempt, self.MAX_RETRIES, e,
|
|
301
|
-
)
|
|
302
|
-
if attempt < self.MAX_RETRIES:
|
|
303
|
-
time.sleep(self.RETRY_BACKOFF * attempt)
|
|
304
|
-
continue
|
|
305
|
-
raise last_error from e
|
|
433
|
+
) from e
|
|
306
434
|
|
|
307
435
|
except requests.RequestException as e:
|
|
308
436
|
raise LLMConnectionError(
|
|
309
437
|
f"Unexpected request error to {url}: {e}"
|
|
310
438
|
) from e
|
|
311
439
|
|
|
440
|
+
# Success — reset the circuit breaker
|
|
441
|
+
self._consecutive_connection_errors = 0
|
|
442
|
+
|
|
312
443
|
# HTTP-level error handling (no retry)
|
|
313
444
|
if r.status_code == 404:
|
|
314
445
|
# Ollama returns 404 when the model is missing. The
|
|
@@ -338,6 +469,10 @@ class OllamaClient:
|
|
|
338
469
|
f"All {self.MAX_RETRIES} retries failed: {last_error}"
|
|
339
470
|
)
|
|
340
471
|
|
|
472
|
+
# ------------------------------------------------------------------
|
|
473
|
+
# Context manager / cleanup
|
|
474
|
+
# ------------------------------------------------------------------
|
|
475
|
+
|
|
341
476
|
def close(self) -> None:
|
|
342
477
|
"""Close the underlying HTTP session."""
|
|
343
478
|
self._session.close()
|
siftcode/core/manual.py
CHANGED
|
@@ -118,6 +118,23 @@ class SpecGenerator:
|
|
|
118
118
|
self.license_name = license_name or project_meta.get("license") or "Not specified"
|
|
119
119
|
self.version = version or project_meta.get("version") or "0.1.0"
|
|
120
120
|
|
|
121
|
+
# ------------------------------------------------------------------
|
|
122
|
+
# Multi-model helper
|
|
123
|
+
# ------------------------------------------------------------------
|
|
124
|
+
|
|
125
|
+
def _model_for(self, stage: str) -> str:
|
|
126
|
+
"""
|
|
127
|
+
Resolve the model name for a stage, honouring stage overrides.
|
|
128
|
+
|
|
129
|
+
The spec generator always runs in the 'file' stage: it produces
|
|
130
|
+
one document per source file. If the user has configured a
|
|
131
|
+
file-stage override (e.g. --model-stage file=qwen2.5-coder:32b),
|
|
132
|
+
that model is used. Otherwise we fall back to the project default.
|
|
133
|
+
"""
|
|
134
|
+
return self.config.model.stages.get(
|
|
135
|
+
stage, self.config.model.name
|
|
136
|
+
)
|
|
137
|
+
|
|
121
138
|
# ------------------------------------------------------------------
|
|
122
139
|
# Metadata detection
|
|
123
140
|
# ------------------------------------------------------------------
|
|
@@ -248,7 +265,10 @@ class SpecGenerator:
|
|
|
248
265
|
|
|
249
266
|
rel_path = self._safe_rel(file_path)
|
|
250
267
|
|
|
251
|
-
|
|
268
|
+
# Use the 'file' stage model. Advanced specs are still a
|
|
269
|
+
# per-file task, so a file-stage override (e.g. a larger model
|
|
270
|
+
# for more detailed specs) applies here as well.
|
|
271
|
+
model = self._model_for("file")
|
|
252
272
|
key = self._spec_cache_key(file_path, rel_path)
|
|
253
273
|
|
|
254
274
|
cached = self.cache.get_file(key, model=model)
|
|
@@ -268,9 +288,16 @@ class SpecGenerator:
|
|
|
268
288
|
)
|
|
269
289
|
|
|
270
290
|
try:
|
|
291
|
+
# Specs are long-form documents: they need more context
|
|
292
|
+
# than the regular per-file summaries. The value comes from
|
|
293
|
+
# config.model.spec_num_ctx (default 16384) and can be
|
|
294
|
+
# overridden per run with --spec-num-ctx.
|
|
271
295
|
response = self.client.chat(
|
|
272
296
|
system=system_prompt,
|
|
273
297
|
user=f"Source code to analyze:\n\n```python\n{source_code}\n```",
|
|
298
|
+
model=model,
|
|
299
|
+
num_ctx=self.config.model.spec_num_ctx,
|
|
300
|
+
max_tokens=self.config.model.max_tokens_guide,
|
|
274
301
|
)
|
|
275
302
|
spec_content = response.text.strip()
|
|
276
303
|
self.cache.put_file(
|
siftcode/gui/analyzer_view.py
CHANGED
|
@@ -398,6 +398,18 @@ class AnalyzerView(Adw.Bin):
|
|
|
398
398
|
return
|
|
399
399
|
|
|
400
400
|
client = OllamaClient(self._config.model)
|
|
401
|
+
|
|
402
|
+
# Fail fast if Ollama is unreachable, instead of retrying
|
|
403
|
+
# three times per file for 42 files (~4 min of waiting).
|
|
404
|
+
# check_connection() gives a user-friendly message that
|
|
405
|
+
# distinguishes DNS failures from refused connections.
|
|
406
|
+
try:
|
|
407
|
+
client.check_connection()
|
|
408
|
+
except LLMError as e:
|
|
409
|
+
logger.error("Ollama unreachable before analysis: %s", e)
|
|
410
|
+
task.return_error(GLib.Error(str(e)))
|
|
411
|
+
return
|
|
412
|
+
|
|
401
413
|
analyzer = ProjectAnalyzer(self._config, client)
|
|
402
414
|
self._analyzer = analyzer
|
|
403
415
|
|
siftcode/gui/settings_view.py
CHANGED
|
@@ -3,6 +3,10 @@ Settings view — edit a project's configuration.
|
|
|
3
3
|
|
|
4
4
|
Phase 3: basic fields, model settings, analysis settings.
|
|
5
5
|
Phase 4: Analyze button hands off to the analyzer view.
|
|
6
|
+
|
|
7
|
+
Multi-model support: per-stage model overrides are exposed in an
|
|
8
|
+
expander row under the Model group. Empty fields fall back to the
|
|
9
|
+
default model name.
|
|
6
10
|
"""
|
|
7
11
|
|
|
8
12
|
from __future__ import annotations
|
|
@@ -179,7 +183,11 @@ class SettingsView(Adw.Bin):
|
|
|
179
183
|
def _build_model_group(self) -> Adw.PreferencesGroup:
|
|
180
184
|
group = Adw.PreferencesGroup()
|
|
181
185
|
group.set_title("Model")
|
|
182
|
-
group.set_description(
|
|
186
|
+
group.set_description(
|
|
187
|
+
"LLM settings used when analyzing this project. "
|
|
188
|
+
"Stage overrides let you use a different model for specific "
|
|
189
|
+
"parts of the analysis."
|
|
190
|
+
)
|
|
183
191
|
|
|
184
192
|
self._model_row = Adw.EntryRow()
|
|
185
193
|
self._model_row.set_title("Model name")
|
|
@@ -210,8 +218,49 @@ class SettingsView(Adw.Bin):
|
|
|
210
218
|
self._timeout_row.set_value(self._config.model.timeout)
|
|
211
219
|
group.add(self._timeout_row)
|
|
212
220
|
|
|
221
|
+
# --- Per-stage model overrides (multi-model support) ----------
|
|
222
|
+
# Empty fields fall back to the default model above. The
|
|
223
|
+
# expander stays collapsed unless at least one stage is set, so
|
|
224
|
+
# the common single-model case stays uncluttered.
|
|
225
|
+
self._stages_rows: dict[str, Adw.EntryRow] = {}
|
|
226
|
+
self._stages_expander = Adw.ExpanderRow()
|
|
227
|
+
self._stages_expander.set_title("Per-stage models")
|
|
228
|
+
self._stages_expander.set_subtitle(self._stages_subtitle())
|
|
229
|
+
self._stages_expander.set_expanded(bool(self._config.model.stages))
|
|
230
|
+
|
|
231
|
+
for stage in ("root", "file", "directories", "guide"):
|
|
232
|
+
row = Adw.EntryRow()
|
|
233
|
+
row.set_title(stage.capitalize())
|
|
234
|
+
row.set_text(self._config.model.stages.get(stage, ""))
|
|
235
|
+
row.connect("changed", lambda _r: self._update_stages_subtitle())
|
|
236
|
+
self._stages_rows[stage] = row
|
|
237
|
+
self._stages_expander.add_row(row)
|
|
238
|
+
|
|
239
|
+
group.add(self._stages_expander)
|
|
240
|
+
|
|
213
241
|
return group
|
|
214
242
|
|
|
243
|
+
def _stages_subtitle(self) -> str:
|
|
244
|
+
"""Return a short description of how many stages are overridden."""
|
|
245
|
+
if not self._config:
|
|
246
|
+
return "Leave empty to use the default model"
|
|
247
|
+
count = len(self._config.model.stages)
|
|
248
|
+
if count == 0:
|
|
249
|
+
return "All stages use the default model"
|
|
250
|
+
return f"{count} of 4 stages overridden"
|
|
251
|
+
|
|
252
|
+
def _update_stages_subtitle(self) -> None:
|
|
253
|
+
"""Recompute the expander subtitle from the current row values."""
|
|
254
|
+
if not self._config:
|
|
255
|
+
return
|
|
256
|
+
count = sum(
|
|
257
|
+
1 for row in self._stages_rows.values() if row.get_text().strip()
|
|
258
|
+
)
|
|
259
|
+
if count == 0:
|
|
260
|
+
self._stages_expander.set_subtitle("All stages use the default model")
|
|
261
|
+
else:
|
|
262
|
+
self._stages_expander.set_subtitle(f"{count} of 4 stages overridden")
|
|
263
|
+
|
|
215
264
|
def _build_analysis_group(self) -> Adw.PreferencesGroup:
|
|
216
265
|
group = Adw.PreferencesGroup()
|
|
217
266
|
group.set_title("Analysis")
|
|
@@ -345,6 +394,15 @@ class SettingsView(Adw.Bin):
|
|
|
345
394
|
self._config.model.temperature = float(self._temp_row.get_value())
|
|
346
395
|
self._config.model.timeout = int(self._timeout_row.get_value())
|
|
347
396
|
|
|
397
|
+
# Per-stage model overrides — only include non-empty entries.
|
|
398
|
+
# A blank field means "use the default model for this stage".
|
|
399
|
+
stages: dict[str, str] = {}
|
|
400
|
+
for stage, row in self._stages_rows.items():
|
|
401
|
+
value = row.get_text().strip()
|
|
402
|
+
if value:
|
|
403
|
+
stages[stage] = value
|
|
404
|
+
self._config.model.stages = stages
|
|
405
|
+
|
|
348
406
|
# Analysis settings
|
|
349
407
|
self._config.analysis.use_cache = self._cache_row.get_active()
|
|
350
408
|
self._config.analysis.max_file_chars = int(self._max_chars_row.get_value())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: siftcode
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Local LLM-powered code analysis and developer guide generator
|
|
5
5
|
Author-email: Tuomas Lähteenmäki <lahtis@gmail.com>
|
|
6
6
|
License-Expression: GPL-3.0-or-later
|
|
@@ -76,7 +76,7 @@ generated in minutes.
|
|
|
76
76
|
- **Configurable per project**: model, context size, temperature, file
|
|
77
77
|
exclusions, and cache settings are all saved per project
|
|
78
78
|
- **Two front-ends**: a modern GTK4 + libadwaita GUI and a scriptable CLI
|
|
79
|
-
- **Tested**:
|
|
79
|
+
- **Tested**: 353 unit tests, 79 % overall coverage (88–100 % for core modules)
|
|
80
80
|
|
|
81
81
|
---
|
|
82
82
|
|
|
@@ -120,12 +120,20 @@ GPU and the model you choose.
|
|
|
120
120
|
|---|---|---|---|---|
|
|
121
121
|
| `qwen2.5-coder:7b` | ~5 GB | ~3 min | Basic | Small projects, laptops |
|
|
122
122
|
| **`qwen2.5-coder:14b`** | **~10 GB** | **~7 min** | **Good** | **Recommended default** |
|
|
123
|
-
| `qwen2.5-coder:32b` | ~22 GB | ~33 min | Excellent |
|
|
123
|
+
| `qwen2.5-coder:32b` | ~22 GB | ~33 min | Excellent | 24 GB+ GPUs, best quality |
|
|
124
|
+
|
|
125
|
+
**Quick rule of thumb by VRAM:**
|
|
126
|
+
|
|
127
|
+
- **< 8 GB** → use `7b`, or accept slow CPU-only runs
|
|
128
|
+
- **8–16 GB** → use `14b`; it's the sweet spot for most projects
|
|
129
|
+
- **24 GB+** → use `32b`. It fits comfortably (e.g. Quadro P6000,
|
|
130
|
+
RTX 3090, RTX 4090) and produces noticeably fewer hallucinations —
|
|
131
|
+
in particular it stops inventing files like `setup.py` in modern
|
|
132
|
+
`pyproject.toml` projects.
|
|
124
133
|
|
|
125
134
|
For CUDA GPUs, ensure your driver is recent enough for your Ollama
|
|
126
135
|
build. CPU-only operation works but is slow (expect 5–15× longer runs).
|
|
127
136
|
|
|
128
|
-
|
|
129
137
|
**Observations from real runs:**
|
|
130
138
|
|
|
131
139
|
- **14B** produces a comprehensive guide in ~7 minutes. It occasionally
|
|
@@ -136,38 +144,138 @@ build. CPU-only operation works but is slow (expect 5–15× longer runs).
|
|
|
136
144
|
concise and may skip smaller files.
|
|
137
145
|
- **7B** is useful for small projects or when you need a quick pass.
|
|
138
146
|
|
|
139
|
-
|
|
140
|
-
|
|
147
|
+
### Context length
|
|
148
|
+
|
|
149
|
+
The default `num_ctx` is **8192** tokens, which fits the default 14B
|
|
150
|
+
model on a 10 GB GPU comfortably.
|
|
151
|
+
|
|
152
|
+
**When to raise it:** The guide generation prompt includes the root
|
|
153
|
+
summary, all directory summaries, and all file summaries. For a
|
|
154
|
+
40-file project, this can be ~23,000 tokens. With `num_ctx=8192`,
|
|
155
|
+
Ollama truncates the context and the model may not see most of the
|
|
156
|
+
files — the guide ends up mentioning only a handful of modules.
|
|
157
|
+
|
|
158
|
+
If you have the VRAM, raise it per project:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
siftcode analyze myproject --num-ctx 32768
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Multi-model support
|
|
165
|
+
|
|
166
|
+
Different analysis stages have different needs. Per-file summaries
|
|
167
|
+
are simple tasks where a small model excels; the root summary and
|
|
168
|
+
the final guide require broader reasoning and benefit from a larger
|
|
169
|
+
model. Siftcode lets you assign a different model to each stage.
|
|
170
|
+
|
|
171
|
+
Stages: `root`, `file`, `directories`, `guide`.
|
|
172
|
+
|
|
173
|
+
**With a 24 GB GPU** (Quadro P6000, RTX 3090, RTX 4090), the best
|
|
174
|
+
configuration is:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
siftcode analyze myproject \
|
|
178
|
+
--model-stage root=qwen2.5-coder:32b \
|
|
179
|
+
--model-stage guide=qwen2.5-coder:32b
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
This takes ~9 minutes instead of ~33 (32B on every file) or
|
|
183
|
+
~7 (14B everywhere), and gives most of the quality benefit: the
|
|
184
|
+
32B model handles the two stages where its broader reasoning
|
|
185
|
+
matters most, while 14B handles the file summaries where speed
|
|
186
|
+
matters more than depth.
|
|
187
|
+
|
|
188
|
+
Persist the configuration so you don't have to type it every
|
|
189
|
+
time — the stage overrides are saved to the project's TOML file:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
siftcode analyze myproject --model-stage guide=qwen2.5-coder:32b
|
|
193
|
+
siftcode show myproject
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
```text
|
|
197
|
+
Model:
|
|
198
|
+
Name: qwen2.5-coder:14b
|
|
199
|
+
Stages:
|
|
200
|
+
root (default)
|
|
201
|
+
file (default)
|
|
202
|
+
directories (default)
|
|
203
|
+
guide qwen2.5-coder:32b
|
|
204
|
+
Ollama URL: http://127.0.0.1:11434
|
|
205
|
+
num_ctx: 8192
|
|
206
|
+
spec_num_ctx: 16384
|
|
207
|
+
temperature: 0.0
|
|
208
|
+
timeout: 600s
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
You can also edit the TOML directly:
|
|
212
|
+
```toml
|
|
213
|
+
[model]
|
|
214
|
+
name = "qwen2.5-coder:14b"
|
|
215
|
+
|
|
216
|
+
[model.stages]
|
|
217
|
+
root = "qwen2.5-coder:32b"
|
|
218
|
+
guide = "qwen2.5-coder:32b"
|
|
219
|
+
```
|
|
220
|
+
How the cache behaves: the cache is keyed per model, so
|
|
221
|
+
switching a single stage's model does not invalidate the other
|
|
222
|
+
stages' cached results. If you later re-run with the same stage
|
|
223
|
+
models, the previous summaries are reused — you only pay for the
|
|
224
|
+
stages you actually changed.
|
|
225
|
+
|
|
226
|
+
Shortcut: to use the same model for every stage, use --model:
|
|
227
|
+
```bash
|
|
228
|
+
siftcode analyze myproject --model qwen2.5-coder:32b
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**Tip — keeping both models loaded:** If you have enough VRAM to
|
|
232
|
+
hold both 14B and 32B simultaneously (~32 GB VRAM total), you can
|
|
233
|
+
avoid model reloads between stages:
|
|
141
234
|
|
|
142
235
|
```bash
|
|
143
236
|
export OLLAMA_MAX_LOADED_MODELS=2
|
|
144
237
|
export OLLAMA_KV_CACHE_TYPE=q8_0
|
|
145
238
|
```
|
|
146
239
|
|
|
147
|
-
|
|
148
|
-
guide without reloading models from disk.
|
|
240
|
+
---
|
|
149
241
|
|
|
150
|
-
|
|
151
|
-
build. CPU-only operation works but is slow (expect 5–15× longer runs).
|
|
242
|
+
### Advanced per-file specifications (`--advanced`)
|
|
152
243
|
|
|
153
|
-
|
|
244
|
+
The `--advanced` flag generates a detailed technical specification for
|
|
245
|
+
each source file instead of the usual developer guide. Specs are much
|
|
246
|
+
longer than regular file summaries, so they use a separate context
|
|
247
|
+
length: `spec_num_ctx` (default **16384**).
|
|
154
248
|
|
|
155
|
-
|
|
249
|
+
**On a 24 GB GPU**, 32B Q4_K_M plus a 16k KV cache is right at the
|
|
250
|
+
VRAM limit — Ollama offloads ~4% of the model to the CPU, which roughly
|
|
251
|
+
doubles the run time. Lowering the spec context to 12k keeps the whole
|
|
252
|
+
model on the GPU:
|
|
156
253
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
modules.
|
|
254
|
+
```bash
|
|
255
|
+
siftcode analyze myproject --advanced \
|
|
256
|
+
--model-stage file=qwen2.5-coder:32b \
|
|
257
|
+
--spec-num-ctx 12288
|
|
258
|
+
```
|
|
163
259
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
`cache.py`, `cli.py`, and all GUI views.
|
|
260
|
+
Verify with `ollama ps`: the `PROCESSOR` column should read `100% GPU`.
|
|
261
|
+
If it shows any CPU percentage, lower `--spec-num-ctx` further
|
|
262
|
+
(10240, 8192) until the model fits entirely on the GPU.
|
|
168
263
|
|
|
169
|
-
|
|
170
|
-
|
|
264
|
+
`spec_num_ctx` is saved per project, so you only need the flag once:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
siftcode analyze myproject --advanced \
|
|
268
|
+
--model-stage file=qwen2.5-coder:32b \
|
|
269
|
+
--spec-num-ctx 12288
|
|
270
|
+
siftcode show myproject
|
|
271
|
+
# → spec_num_ctx: 12288
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
> **Note:** `--advanced` mode with a 32B model is very slow (one
|
|
275
|
+
> document per file, each taking 10+ minutes on a 24 GB GPU). For
|
|
276
|
+
> projects with more than ~10 files, use the default 14B model:
|
|
277
|
+
>
|
|
278
|
+
> siftcode analyze myproject --advanced
|
|
171
279
|
|
|
172
280
|
---
|
|
173
281
|
|
|
@@ -191,8 +299,6 @@ pip install -e ".[dev]"
|
|
|
191
299
|
|
|
192
300
|
```bash
|
|
193
301
|
siftcode --version
|
|
194
|
-
|
|
195
|
-
|
|
196
302
|
siftcode about
|
|
197
303
|
# → prints version, author, and license
|
|
198
304
|
```
|
|
@@ -248,6 +354,11 @@ siftcode analyze "My Project" --output ~/siftcode-output
|
|
|
248
354
|
# Analyze it with advanced per-file technical specifications
|
|
249
355
|
siftcode analyze "My Project" --output ~/siftcode-output --advanced
|
|
250
356
|
|
|
357
|
+
# Advanced + multi-model: 32B for specs, 14B for the rest
|
|
358
|
+
siftcode analyze "My Project" --advanced \
|
|
359
|
+
--model-stage file=qwen2.5-coder:32b \
|
|
360
|
+
--spec-num-ctx 12288
|
|
361
|
+
|
|
251
362
|
# Delete a project
|
|
252
363
|
siftcode delete "My Project"
|
|
253
364
|
```
|
|
@@ -272,7 +383,7 @@ siftcode cache gc --days 30 # prune entries unused for 30 days
|
|
|
272
383
|
|
|
273
384
|
### Output
|
|
274
385
|
|
|
275
|
-
Analysis produces
|
|
386
|
+
Analysis produces these files in the output directory:
|
|
276
387
|
|
|
277
388
|
- `findings_<project>_<timestamp>.json` — raw structured findings (root, directories, files, errors)
|
|
278
389
|
- `guide_<project>_<timestamp>.md` — the generated developer guide
|
|
@@ -308,6 +419,22 @@ human-readable and can be edited by hand if you prefer.
|
|
|
308
419
|
|
|
309
420
|
---
|
|
310
421
|
|
|
422
|
+
### Default exclusions
|
|
423
|
+
|
|
424
|
+
The default exclusion list already covers:
|
|
425
|
+
|
|
426
|
+
- Version control directories (`.git`, `.venv`, `node_modules`)
|
|
427
|
+
- Build artifacts (`build`, `dist`, `.pytest_cache`)
|
|
428
|
+
- Documentation directories (`docs`, `doc`)
|
|
429
|
+
- Binary file suffixes (`.png`, `.jpg`, `.zip`, `.so`)
|
|
430
|
+
- **Database files** (`.sqlite`, `.sqlite3`, `.db`, `.db3`, `.mdb`)
|
|
431
|
+
- Editor configs (`.editorconfig`, `.env`)
|
|
432
|
+
|
|
433
|
+
You can add or remove patterns per project from the GUI, or by editing
|
|
434
|
+
the `analysis.exclude` list in the project's TOML file.
|
|
435
|
+
|
|
436
|
+
---
|
|
437
|
+
|
|
311
438
|
## How it works
|
|
312
439
|
|
|
313
440
|
1. **Root analysis** — the LLM sees the project tree and infers the
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
siftcode/__init__.py,sha256=eWKi28_VhYdUSDKY4WnOz7-X7fUDuRexXnjsdG8sb0Q,122
|
|
2
2
|
siftcode/__main__.py,sha256=Y4sl9JXs-nTkFB-8hpLVaHANuLaJMPEAzVzAoSFeJKc,173
|
|
3
|
-
siftcode/_version.py,sha256=
|
|
4
|
-
siftcode/cli.py,sha256=
|
|
3
|
+
siftcode/_version.py,sha256=1Tdb3CLFFhxX98b8egkUUQWIEsnrP8V_JehLX_1teks,2904
|
|
4
|
+
siftcode/cli.py,sha256=bn6d4mkudNQz3CKGfk_fhQe6CXNYSy8QQ-1pbw7Ud8I,25201
|
|
5
5
|
siftcode/core/__init__.py,sha256=jIb7jnkBf9Wx4VGPiFvX2FE7_8O49qvbQuI7sJ330ZA,79
|
|
6
|
-
siftcode/core/analyzer.py,sha256=
|
|
6
|
+
siftcode/core/analyzer.py,sha256=MDn3LBCXSUhKKMeg5jEHzAsaSuBMIQ8zwIa9B9p-kJg,25413
|
|
7
7
|
siftcode/core/cache.py,sha256=ZqH-y3p79nLERSLqGc35j_RIUlcccOY40N2oWQtx5qM,11765
|
|
8
|
-
siftcode/core/config.py,sha256=
|
|
9
|
-
siftcode/core/llm.py,sha256=
|
|
10
|
-
siftcode/core/manual.py,sha256=
|
|
8
|
+
siftcode/core/config.py,sha256=pzO-4vZy3VQufM4y6iwUk4_B1DZYPN7QZpxGHIuwq1M,13810
|
|
9
|
+
siftcode/core/llm.py,sha256=8uV0yLUXs65gaDClczlRc9xrOW1Gmc16KylxU8eIjFE,17329
|
|
10
|
+
siftcode/core/manual.py,sha256=Ely8Vyf8FGVf2lCGKfd1rFux4T2q6vFcnd-Vm1m0kyc,15735
|
|
11
11
|
siftcode/core/prompts.py,sha256=t9j8SKMThaev0lu_QNmqp_5q1lv_AQbjc5wlhqwRVBg,8204
|
|
12
12
|
siftcode/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
13
|
siftcode/data/siftcode-logo.png,sha256=uCkXCVWO1KHxDI6P8BOmPRYc7qWuKKz6sVzFaDKJKt4,398215
|
|
@@ -15,20 +15,20 @@ siftcode/data/hicolor/128x128/apps/siftcode-logo.png,sha256=1M9cW16qIAvoLO8E07Lw
|
|
|
15
15
|
siftcode/data/hicolor/256x256/apps/siftcode-logo.png,sha256=pHymnyB50wZeU6eRmMU1Lhw0gb6jynINoObArEK973I,26369
|
|
16
16
|
siftcode/data/hicolor/48x48/apps/siftcode-logo.png,sha256=Aie5cANsiS7Sf0oKvIo9P2XUbYEL-iFZblVKWELvNdg,2310
|
|
17
17
|
siftcode/gui/__init__.py,sha256=FdSyFK0bIl2MntObtg797_3PTZCx4PTOTqhCoAp_CFY,389
|
|
18
|
-
siftcode/gui/analyzer_view.py,sha256=
|
|
18
|
+
siftcode/gui/analyzer_view.py,sha256=mE4wJzrIzxTbnqk4-HVTllaPDQk4kUkoanVwXxKnhzA,21718
|
|
19
19
|
siftcode/gui/app.py,sha256=0Hfh1sZZ2el7ZwYDf9h3M1BORq0X_DXg3TN6i6VggfU,7497
|
|
20
20
|
siftcode/gui/guide_window.py,sha256=6SGMj5jjUDYAQwjb8c7oGEN-pL9onooj_S4CnMmnkEc,2689
|
|
21
21
|
siftcode/gui/project_list.py,sha256=rswzN_xZdzij-C0cIy0GS9AYNrfqS9lXyqMRDGbsMAo,5222
|
|
22
|
-
siftcode/gui/settings_view.py,sha256=
|
|
22
|
+
siftcode/gui/settings_view.py,sha256=VszP2L60ajLuIt7NfIDLW-lqyYNT47US0p2OH1kBpBU,18350
|
|
23
23
|
siftcode/gui/window.py,sha256=hVVGMyjDSNabfHGc7Qj2d_PFRZfmVTNI9PUXNgO41r8,15202
|
|
24
24
|
siftcode/gui/widgets/__init__.py,sha256=H_ttgUQfiRQRl_3y65K5sthEYSK_cycnRJ0jpcZA7ks,41
|
|
25
25
|
siftcode/gui/widgets/exclusion_list.py,sha256=i0wb0mXOuFOXbo2D-tbE7oQxT9ilpE8fpa7cC-s7Dlk,5799
|
|
26
26
|
siftcode/gui/widgets/log_view.py,sha256=h72YVJL8Z6_jCM0KW_s5e68OIGKe9oycIxo5L9aMN8Y,3646
|
|
27
27
|
siftcode/gui/widgets/markdown_view.py,sha256=g1EWCb9ylbdEMKso31sHNL26qcbJmwo_Y6jj1X3n_14,6965
|
|
28
28
|
siftcode/gui/widgets/project_row.py,sha256=agZ1huT-UvsrJQjotm8D0ax93j-PIZniSvvR5cjO1Hc,4724
|
|
29
|
-
siftcode-0.
|
|
30
|
-
siftcode-0.
|
|
31
|
-
siftcode-0.
|
|
32
|
-
siftcode-0.
|
|
33
|
-
siftcode-0.
|
|
34
|
-
siftcode-0.
|
|
29
|
+
siftcode-0.4.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
30
|
+
siftcode-0.4.0.dist-info/METADATA,sha256=4u4o8xYEFVGypQWWiZlJzkP1EzQEXgxCAwZlAv4Xbi8,17731
|
|
31
|
+
siftcode-0.4.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
32
|
+
siftcode-0.4.0.dist-info/entry_points.txt,sha256=d1JirDrfmZ92Bdh2SmmvfiZiidfj-OlQwBClRFopFsI,104
|
|
33
|
+
siftcode-0.4.0.dist-info/top_level.txt,sha256=vu-_jUd_mpqNGL621YYXUQJLY7MVDFBr_lJ9qZmVJxQ,9
|
|
34
|
+
siftcode-0.4.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|