SourceIndex 0.1.4__tar.gz → 0.1.6__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.
- {sourceindex-0.1.4 → sourceindex-0.1.6}/GETTING_STARTED.md +6 -5
- {sourceindex-0.1.4 → sourceindex-0.1.6}/PKG-INFO +8 -6
- {sourceindex-0.1.4 → sourceindex-0.1.6}/pyproject.toml +8 -1
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/__init__.py +1 -1
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/build/__init__.py +67 -13
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/build/indexer.py +2 -1
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/build/linerange/anchor.py +34 -14
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/build/linerange/treesitter.py +1 -1
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/build/state.py +9 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/cli/__init__.py +24 -6
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/cli/commands.py +56 -3
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/cli/install.py +452 -137
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/lib/backend.py +49 -11
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/lib/llm.py +38 -1
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/lib/log.py +17 -13
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/search/__init__.py +167 -59
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/search/passes.py +34 -3
- sourceindex-0.1.6/sourceindex/server.py +172 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/.gitignore +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/LICENSE +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/build/linerange/__init__.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/build/linerange/python_ast.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/build/prompts.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/build/walker.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/claudecode/__init__.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/claudecode/savings.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/claudecode/savings_summary.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/claudecode/statusline.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/cli/__main__.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/cli/api_key.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/cli/consent.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/cli/upgrade.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/daemon/__init__.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/daemon/client.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/daemon/crypto.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/daemon/keyring_store.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/daemon/lifecycle.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/daemon/protocol.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/daemon/server.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/daemon/store.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/lib/__init__.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/lib/cost.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/lib/env.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/lib/errors.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/lib/git.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/lib/languages.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/lib/registry.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/lib/timing.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/search/experiments.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/search/imports.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/search/prompts.py +0 -0
- {sourceindex-0.1.4 → sourceindex-0.1.6}/sourceindex/search/roadmap.py +0 -0
|
@@ -36,11 +36,12 @@ sourceindex init opencode # set up opencode only
|
|
|
36
36
|
sourceindex init codex # set up Codex only
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
It'll prompt for the key, set up some git hooks plus a subagent
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
It'll prompt for the key, set up some git hooks plus a subagent (Claude
|
|
40
|
+
Code, opencode) or an MCP server registration (Codex) for the coding agent
|
|
41
|
+
your repo already uses (a `CLAUDE.md` or `.claude/` means Claude Code; a
|
|
42
|
+
`.opencode/` means opencode; a `.codex/` means Codex; an `AGENTS.md` alone
|
|
43
|
+
means both opencode and Codex; none of those means Claude Code), and scan
|
|
44
|
+
your repo. A few minutes, once per repo. You can also name
|
|
44
45
|
several at once (`sourceindex init claude opencode codex`), and it's safe
|
|
45
46
|
to re-run init later to add another agent.
|
|
46
47
|
If you don't have a `CLAUDE.md` (Claude Code) or `AGENTS.md` (opencode,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: SourceIndex
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Summary: Codebase index for agentic coding
|
|
5
5
|
Author: MANTEON PTE. LTD.
|
|
6
6
|
License-Expression: LicenseRef-Proprietary
|
|
@@ -13,6 +13,7 @@ Requires-Python: >=3.10
|
|
|
13
13
|
Requires-Dist: cryptography>=42
|
|
14
14
|
Requires-Dist: keyring>=24
|
|
15
15
|
Requires-Dist: litellm>=1.50
|
|
16
|
+
Requires-Dist: mcp<2,>=1.2.0
|
|
16
17
|
Requires-Dist: tree-sitter-c>=0.23
|
|
17
18
|
Requires-Dist: tree-sitter-cpp>=0.23
|
|
18
19
|
Requires-Dist: tree-sitter-go>=0.23
|
|
@@ -66,11 +67,12 @@ sourceindex init opencode # set up opencode only
|
|
|
66
67
|
sourceindex init codex # set up Codex only
|
|
67
68
|
```
|
|
68
69
|
|
|
69
|
-
It'll prompt for the key, set up some git hooks plus a subagent
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
It'll prompt for the key, set up some git hooks plus a subagent (Claude
|
|
71
|
+
Code, opencode) or an MCP server registration (Codex) for the coding agent
|
|
72
|
+
your repo already uses (a `CLAUDE.md` or `.claude/` means Claude Code; a
|
|
73
|
+
`.opencode/` means opencode; a `.codex/` means Codex; an `AGENTS.md` alone
|
|
74
|
+
means both opencode and Codex; none of those means Claude Code), and scan
|
|
75
|
+
your repo. A few minutes, once per repo. You can also name
|
|
74
76
|
several at once (`sourceindex init claude opencode codex`), and it's safe
|
|
75
77
|
to re-run init later to add another agent.
|
|
76
78
|
If you don't have a `CLAUDE.md` (Claude Code) or `AGENTS.md` (opencode,
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "SourceIndex"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.6"
|
|
8
8
|
description = "Codebase index for agentic coding"
|
|
9
9
|
readme = "GETTING_STARTED.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -31,6 +31,13 @@ dependencies = [
|
|
|
31
31
|
# OS keychain wrapper. Fallback path to a 0600 file is supported if no
|
|
32
32
|
# keyring backend is present (Docker, headless CI) — install never fails.
|
|
33
33
|
"keyring>=24",
|
|
34
|
+
# MCP server for the Codex integration (`sourceindex serve`, registered in
|
|
35
|
+
# .codex/config.toml by `sourceindex init codex`). Hard dep, not an extra:
|
|
36
|
+
# `pip install sourceindex && sourceindex init codex` must work in one step,
|
|
37
|
+
# and litellm already pulls the heavy transitives (pydantic, httpx).
|
|
38
|
+
# Floor 1.2.0: mcp.server.fastmcp only merged into the SDK there — 1.0/1.1
|
|
39
|
+
# resolve fine but leave `sourceindex serve` unable to import FastMCP.
|
|
40
|
+
"mcp>=1.2.0,<2",
|
|
34
41
|
# Per-language grammars for the languages in build/linerange/treesitter.py
|
|
35
42
|
# LANG_CFG. Each wheel is ~60-330 KB; collectively ~3 MB vs 183 MB for
|
|
36
43
|
# the all-in-one tree-sitter-language-pack. Languages added later that
|
|
@@ -29,6 +29,8 @@ from .indexer import (
|
|
|
29
29
|
)
|
|
30
30
|
from .state import (
|
|
31
31
|
BUILD_META_FILENAME,
|
|
32
|
+
SUMMARY_FAILED_PLACEHOLDER,
|
|
33
|
+
details_exists,
|
|
32
34
|
load_file_index,
|
|
33
35
|
load_summary_cache,
|
|
34
36
|
merge_build_meta,
|
|
@@ -171,6 +173,7 @@ def build_index_with_store(
|
|
|
171
173
|
|
|
172
174
|
cache_hits = len(oneliners)
|
|
173
175
|
cache_misses = len(needs_llm)
|
|
176
|
+
files_failed = 0
|
|
174
177
|
_log.info(
|
|
175
178
|
f"Summary cache: {cache_hits} hits, {cache_misses} misses.",
|
|
176
179
|
extra={
|
|
@@ -195,7 +198,7 @@ def build_index_with_store(
|
|
|
195
198
|
)
|
|
196
199
|
total_usage.add(batch_usage)
|
|
197
200
|
|
|
198
|
-
emit_status("[finalize] writing
|
|
201
|
+
emit_status("[finalize] writing file details and saving cache...")
|
|
199
202
|
for rel_path in needs_llm:
|
|
200
203
|
h = file_hashes[rel_path]
|
|
201
204
|
if h in hash_to_parsed:
|
|
@@ -205,7 +208,11 @@ def build_index_with_store(
|
|
|
205
208
|
if file_langs[rel_path].build_tier2:
|
|
206
209
|
write_details(store, rel_path, functions)
|
|
207
210
|
else:
|
|
208
|
-
|
|
211
|
+
# Keep the file visible in index.md (search can still
|
|
212
|
+
# whole-file-inject it) but never cache the failure or
|
|
213
|
+
# record it in the file index — the next run retries it.
|
|
214
|
+
files_failed += 1
|
|
215
|
+
oneliners[rel_path] = SUMMARY_FAILED_PLACEHOLDER
|
|
209
216
|
if file_langs[rel_path].build_tier2:
|
|
210
217
|
write_details(store, rel_path, "")
|
|
211
218
|
else:
|
|
@@ -215,10 +222,13 @@ def build_index_with_store(
|
|
|
215
222
|
oneliner, functions, usage = index_file(content, rel_path, lang, model=model, api_key=api_key)
|
|
216
223
|
total_usage.add(usage)
|
|
217
224
|
oneliners[rel_path] = oneliner
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
225
|
+
if oneliner == SUMMARY_FAILED_PLACEHOLDER:
|
|
226
|
+
files_failed += 1
|
|
227
|
+
else:
|
|
228
|
+
summary_cache[file_hashes[rel_path]] = {
|
|
229
|
+
"oneliner": oneliner,
|
|
230
|
+
"functions": functions,
|
|
231
|
+
}
|
|
222
232
|
if lang.build_tier2:
|
|
223
233
|
write_details(store, rel_path, functions)
|
|
224
234
|
|
|
@@ -235,7 +245,7 @@ def build_index_with_store(
|
|
|
235
245
|
|
|
236
246
|
file_index_map: dict[str, dict] = {}
|
|
237
247
|
for rel_path in source_files:
|
|
238
|
-
if rel_path
|
|
248
|
+
if oneliners.get(rel_path) in (None, SUMMARY_FAILED_PLACEHOLDER):
|
|
239
249
|
continue
|
|
240
250
|
try:
|
|
241
251
|
mtime = (repo_root / rel_path).stat().st_mtime_ns
|
|
@@ -259,6 +269,17 @@ def build_index_with_store(
|
|
|
259
269
|
started_at=started_at,
|
|
260
270
|
)
|
|
261
271
|
|
|
272
|
+
if files_failed:
|
|
273
|
+
_log.error(
|
|
274
|
+
f"{files_failed} of {cache_misses} files failed to index — their "
|
|
275
|
+
"summaries were not cached and will be retried on the next "
|
|
276
|
+
"update. Check the model and API key if this persists.",
|
|
277
|
+
extra={
|
|
278
|
+
"event": "build.files_failed",
|
|
279
|
+
"files_failed": files_failed,
|
|
280
|
+
"files_attempted": cache_misses,
|
|
281
|
+
},
|
|
282
|
+
)
|
|
262
283
|
_log.info(
|
|
263
284
|
f"Done. Index: {store.path_for('index.md')} ({len(index_lines)} files, "
|
|
264
285
|
f"{cache_hits} from cache)",
|
|
@@ -268,6 +289,7 @@ def build_index_with_store(
|
|
|
268
289
|
"files_in_index": len(index_lines),
|
|
269
290
|
"files_indexed": cache_misses,
|
|
270
291
|
"files_from_cache": cache_hits,
|
|
292
|
+
"files_failed": files_failed,
|
|
271
293
|
"elapsed_s": round(elapsed_s, 3),
|
|
272
294
|
"input_tokens": total_usage.input_tokens,
|
|
273
295
|
"output_tokens": total_usage.output_tokens,
|
|
@@ -277,6 +299,7 @@ def build_index_with_store(
|
|
|
277
299
|
return {
|
|
278
300
|
"files_indexed": cache_misses,
|
|
279
301
|
"files_from_cache": cache_hits,
|
|
302
|
+
"files_failed": files_failed,
|
|
280
303
|
"cost_usd": round(total_usage.cost_usd, 6),
|
|
281
304
|
"elapsed_s": round(elapsed_s, 3),
|
|
282
305
|
}
|
|
@@ -367,6 +390,7 @@ def update_index_with_store(
|
|
|
367
390
|
start_time = time.time()
|
|
368
391
|
total_usage = LLMUsage()
|
|
369
392
|
files_indexed = 0
|
|
393
|
+
files_failed = 0
|
|
370
394
|
summary_cache = load_summary_cache(store)
|
|
371
395
|
file_index_map = load_file_index(store) if persist_file_index else {}
|
|
372
396
|
|
|
@@ -443,13 +467,21 @@ def update_index_with_store(
|
|
|
443
467
|
for rel_path, (_, lang, mtime_ns, h) in needs_llm.items():
|
|
444
468
|
if h in hash_to_parsed:
|
|
445
469
|
oneliner, functions = hash_to_parsed[h]
|
|
470
|
+
if lang.build_tier2:
|
|
471
|
+
write_details(store, rel_path, functions)
|
|
472
|
+
existing_index[rel_path] = oneliner
|
|
473
|
+
file_index_map[rel_path] = {"mtime_ns": mtime_ns, "hash": h}
|
|
474
|
+
files_indexed += 1
|
|
446
475
|
else:
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
476
|
+
# A failed call must not poison state: keep the previous
|
|
477
|
+
# tier-1 line and tier-2 details (stale beats absent), and
|
|
478
|
+
# leave the file-index record untouched so the next update
|
|
479
|
+
# retries this file.
|
|
480
|
+
files_failed += 1
|
|
481
|
+
if rel_path not in existing_index:
|
|
482
|
+
existing_index[rel_path] = SUMMARY_FAILED_PLACEHOLDER
|
|
483
|
+
if lang.build_tier2 and not details_exists(store, rel_path):
|
|
484
|
+
write_details(store, rel_path, "")
|
|
453
485
|
else:
|
|
454
486
|
for rel_path, (content, lang, mtime_ns, h) in needs_llm.items():
|
|
455
487
|
_log.info(
|
|
@@ -458,6 +490,16 @@ def update_index_with_store(
|
|
|
458
490
|
)
|
|
459
491
|
oneliner, functions, usage = index_file(content, rel_path, lang, model=model, api_key=api_key)
|
|
460
492
|
total_usage.add(usage)
|
|
493
|
+
if oneliner == SUMMARY_FAILED_PLACEHOLDER:
|
|
494
|
+
# See the batch-path comment: never cache or overwrite good
|
|
495
|
+
# state with a failure; skip the file-index record so the
|
|
496
|
+
# next update retries this file.
|
|
497
|
+
files_failed += 1
|
|
498
|
+
if rel_path not in existing_index:
|
|
499
|
+
existing_index[rel_path] = oneliner
|
|
500
|
+
if lang.build_tier2 and not details_exists(store, rel_path):
|
|
501
|
+
write_details(store, rel_path, "")
|
|
502
|
+
continue
|
|
461
503
|
files_indexed += 1
|
|
462
504
|
summary_cache[h] = {"oneliner": oneliner, "functions": functions}
|
|
463
505
|
if lang.build_tier2:
|
|
@@ -481,12 +523,23 @@ def update_index_with_store(
|
|
|
481
523
|
started_at=started_at,
|
|
482
524
|
)
|
|
483
525
|
|
|
526
|
+
if files_failed:
|
|
527
|
+
_log.error(
|
|
528
|
+
f"{files_failed} file(s) failed to index during update — kept "
|
|
529
|
+
"their previous entries; they will be retried on the next "
|
|
530
|
+
"update. Check the model and API key if this persists.",
|
|
531
|
+
extra={
|
|
532
|
+
"event": "update.files_failed",
|
|
533
|
+
"files_failed": files_failed,
|
|
534
|
+
},
|
|
535
|
+
)
|
|
484
536
|
_log.info(
|
|
485
537
|
f"Updated {len(changed_files)} files.",
|
|
486
538
|
extra={
|
|
487
539
|
"event": "update.done",
|
|
488
540
|
"changed_count": len(changed_files),
|
|
489
541
|
"files_indexed": files_indexed,
|
|
542
|
+
"files_failed": files_failed,
|
|
490
543
|
"elapsed_s": round(elapsed_s, 3),
|
|
491
544
|
"input_tokens": total_usage.input_tokens,
|
|
492
545
|
"output_tokens": total_usage.output_tokens,
|
|
@@ -495,6 +548,7 @@ def update_index_with_store(
|
|
|
495
548
|
)
|
|
496
549
|
return {
|
|
497
550
|
"files_indexed": files_indexed,
|
|
551
|
+
"files_failed": files_failed,
|
|
498
552
|
"elapsed_s": round(elapsed_s, 3),
|
|
499
553
|
"cost_usd": round(total_usage.cost_usd, 6),
|
|
500
554
|
}
|
|
@@ -26,6 +26,7 @@ from ..lib.llm import LLMUsage, call_llm
|
|
|
26
26
|
from ..lib.log import get_logger
|
|
27
27
|
from .linerange import fix_functions_for_language
|
|
28
28
|
from .prompts import prompt_for
|
|
29
|
+
from .state import SUMMARY_FAILED_PLACEHOLDER
|
|
29
30
|
|
|
30
31
|
_log = get_logger(__name__)
|
|
31
32
|
|
|
@@ -140,7 +141,7 @@ def index_file(
|
|
|
140
141
|
f" LLM failed for {relative_path}, skipping",
|
|
141
142
|
extra={"event": "llm.failed", "path": relative_path},
|
|
142
143
|
)
|
|
143
|
-
return
|
|
144
|
+
return SUMMARY_FAILED_PLACEHOLDER, "", total_usage
|
|
144
145
|
|
|
145
146
|
|
|
146
147
|
# ── Batch dispatch ─────────────────────────────────────────────────────────
|
|
@@ -67,21 +67,28 @@ _TRAILING_SUFFIXES = (
|
|
|
67
67
|
_RECEIVER_RE = re.compile(r"^\([^)]*\)\s*\.") # Go receiver: (b *Backend).foo
|
|
68
68
|
|
|
69
69
|
|
|
70
|
-
def
|
|
71
|
-
"""
|
|
72
|
-
|
|
70
|
+
def _normalize_core(qn: str) -> str:
|
|
71
|
+
"""Separator/decoration normalization only — no accessor-suffix stripping,
|
|
72
|
+
so a genuine method named ``get``/``set`` keeps its qualified name."""
|
|
73
73
|
qn = qn.strip()
|
|
74
74
|
qn = _RECEIVER_RE.sub("", qn) # "(b *Backend).foo" -> "foo"
|
|
75
75
|
qn = qn.replace("::", ".").replace("#", ".")
|
|
76
76
|
if " " in qn:
|
|
77
77
|
qn = qn.split()[-1]
|
|
78
|
+
while ".." in qn:
|
|
79
|
+
qn = qn.replace("..", ".")
|
|
80
|
+
return qn.strip(".")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def normalize_name(qn: str) -> str:
|
|
84
|
+
"""Normalize separators to ``.``, drop receiver parens / keyword prefixes /
|
|
85
|
+
accessor suffixes, so lookup keys converge across LLM naming styles."""
|
|
86
|
+
qn = _normalize_core(qn)
|
|
78
87
|
while qn.endswith(_TRAILING_SUFFIXES):
|
|
79
88
|
for suf in _TRAILING_SUFFIXES:
|
|
80
89
|
if qn.endswith(suf):
|
|
81
90
|
qn = qn[: -len(suf)]
|
|
82
91
|
break
|
|
83
|
-
while ".." in qn:
|
|
84
|
-
qn = qn.replace("..", ".")
|
|
85
92
|
return qn.strip(".")
|
|
86
93
|
|
|
87
94
|
|
|
@@ -113,19 +120,32 @@ def _strict_name(name: str) -> bool:
|
|
|
113
120
|
|
|
114
121
|
|
|
115
122
|
def _lookup(truth: Truth, qn: str) -> List[Range]:
|
|
116
|
-
"""Qualified match first; peel leading segments; finally bare name.
|
|
123
|
+
"""Qualified match first; peel leading segments; finally bare name.
|
|
124
|
+
|
|
125
|
+
The un-suffix-stripped name is tried before the accessor-stripped one:
|
|
126
|
+
``TTLCache.get`` is a real Python method and must hit its own truth
|
|
127
|
+
entry, while a Kotlin/C# accessor ``Foo.bar.get`` (no such entry) still
|
|
128
|
+
falls through to ``Foo.bar``."""
|
|
129
|
+
core = _normalize_core(qn)
|
|
117
130
|
norm = normalize_name(qn)
|
|
131
|
+
tried: set[str] = set()
|
|
132
|
+
for cand in (core, norm):
|
|
133
|
+
if not cand or cand in tried:
|
|
134
|
+
continue
|
|
135
|
+
tried.add(cand)
|
|
136
|
+
if cand in truth:
|
|
137
|
+
return truth[cand]
|
|
138
|
+
parts = cand.split(".")
|
|
139
|
+
# Peel LLM-invented leading prefixes (mypkg.Foo.bar -> Foo.bar), but
|
|
140
|
+
# only accept still-qualified suffixes here — the bare tail is gated
|
|
141
|
+
# below.
|
|
142
|
+
for i in range(1, len(parts)):
|
|
143
|
+
suffix = ".".join(parts[i:])
|
|
144
|
+
if "." in suffix and suffix in truth:
|
|
145
|
+
return truth[suffix]
|
|
118
146
|
if not norm:
|
|
119
147
|
return []
|
|
120
|
-
if norm in truth:
|
|
121
|
-
return truth[norm]
|
|
122
148
|
parts = norm.split(".")
|
|
123
|
-
# Peel LLM-invented leading prefixes (mypkg.Foo.bar -> Foo.bar), but only
|
|
124
|
-
# accept still-qualified suffixes here — the bare tail is gated below.
|
|
125
|
-
for i in range(1, len(parts)):
|
|
126
|
-
suffix = ".".join(parts[i:])
|
|
127
|
-
if "." in suffix and suffix in truth:
|
|
128
|
-
return truth[suffix]
|
|
129
149
|
# Bare-name fallback — but NOT when the entry's own container exists in
|
|
130
150
|
# truth: then this member genuinely isn't defined there (generated or
|
|
131
151
|
# hallucinated), and borrowing a same-named member of another container
|
|
@@ -97,7 +97,7 @@ def _warn_missing_grammar(language_key: str, grammar: str, exc: BaseException) -
|
|
|
97
97
|
pkg = f"tree-sitter-{grammar}"
|
|
98
98
|
_log.warning(
|
|
99
99
|
f"grammar package '{pkg}' not available for {language_key} "
|
|
100
|
-
f"({type(exc).__name__});
|
|
100
|
+
f"({type(exc).__name__}); line ranges for this language will use "
|
|
101
101
|
f"LLM output as-is (less accurate). Install with `pip install {pkg}` "
|
|
102
102
|
f"or set {_AUTO_INSTALL_ENV}=1 to auto-install on first use.",
|
|
103
103
|
extra={
|
|
@@ -35,6 +35,11 @@ BUILD_META_FILENAME = "build_meta.json"
|
|
|
35
35
|
# matches against this exact string to classify a file as un-indexed.
|
|
36
36
|
INDEXING_FAILED_PLACEHOLDER = "(LLM indexing failed)"
|
|
37
37
|
|
|
38
|
+
# Tier-1 oneliner used in index.md when the summary call failed. Shown to
|
|
39
|
+
# search so the file stays listed (and whole-file-injectable), but must never
|
|
40
|
+
# be treated as a valid cached summary — a failure is retried, not reused.
|
|
41
|
+
SUMMARY_FAILED_PLACEHOLDER = "(LLM summary failed)"
|
|
42
|
+
|
|
38
43
|
|
|
39
44
|
# ── Summary cache ──────────────────────────────────────────────────────────
|
|
40
45
|
|
|
@@ -149,6 +154,10 @@ def try_summary_cache_hit(
|
|
|
149
154
|
cached = summary_cache.get(content_hash)
|
|
150
155
|
if not cached or not cached.get("oneliner"):
|
|
151
156
|
return None
|
|
157
|
+
# Caches written before failures were excluded may hold the failure
|
|
158
|
+
# marker; treating it as a hit made a single bad build sticky forever.
|
|
159
|
+
if cached["oneliner"] == SUMMARY_FAILED_PLACEHOLDER:
|
|
160
|
+
return None
|
|
152
161
|
oneliner = cached["oneliner"]
|
|
153
162
|
functions = cached.get("functions", "")
|
|
154
163
|
if not lang.build_tier2:
|
|
@@ -7,6 +7,7 @@ Usage:
|
|
|
7
7
|
sourceindex api-key set
|
|
8
8
|
sourceindex api-key set --local [--repo-root PATH]
|
|
9
9
|
sourceindex search [--repo-root PATH] QUERY
|
|
10
|
+
sourceindex serve [--repo-root PATH]
|
|
10
11
|
sourceindex report-savings # Stop-hook entry point; reads payload JSON from stdin
|
|
11
12
|
sourceindex statusline # statusLine entry point; reads payload JSON from stdin
|
|
12
13
|
"""
|
|
@@ -29,6 +30,7 @@ from .commands import (
|
|
|
29
30
|
cmd_report_savings,
|
|
30
31
|
cmd_savings_summary,
|
|
31
32
|
cmd_search,
|
|
33
|
+
cmd_serve,
|
|
32
34
|
cmd_statusline,
|
|
33
35
|
cmd_update,
|
|
34
36
|
cmd_usage,
|
|
@@ -40,7 +42,7 @@ _LOG_LEVELS = ("DEBUG", "INFO", "WARNING", "ERROR")
|
|
|
40
42
|
# Commands that do real backend/LLM work — the only ones that attach the error
|
|
41
43
|
# upload handler. Others skip it so lightweight/read-only paths don't spin up
|
|
42
44
|
# the background sender thread. (The gate itself is litellm-free.)
|
|
43
|
-
_UPLOAD_COMMANDS = frozenset({"init", "update", "search", "deinit", "daemon"})
|
|
45
|
+
_UPLOAD_COMMANDS = frozenset({"init", "update", "serve", "search", "deinit", "daemon"})
|
|
44
46
|
|
|
45
47
|
|
|
46
48
|
def _add_log_flags(parser: argparse.ArgumentParser) -> None:
|
|
@@ -81,7 +83,7 @@ def _resolve_log_level(args: argparse.Namespace) -> str | None:
|
|
|
81
83
|
def main() -> None:
|
|
82
84
|
parser = argparse.ArgumentParser(prog="sourceindex", description="Codebase index for agentic coding")
|
|
83
85
|
public_commands = (
|
|
84
|
-
"init,update,daemon,deinit,install-hooks,usage,api-key,search,"
|
|
86
|
+
"init,update,daemon,deinit,install-hooks,usage,api-key,search,serve,"
|
|
85
87
|
"report-savings,statusline,savings-summary"
|
|
86
88
|
)
|
|
87
89
|
sub = parser.add_subparsers(dest="command", metavar="{" + public_commands + "}")
|
|
@@ -116,8 +118,9 @@ def main() -> None:
|
|
|
116
118
|
# render --help, ballooning `sourceindex statusline` startup.
|
|
117
119
|
from .. import REALTIME_MAX_WORKERS as _DEFAULT_WORKERS
|
|
118
120
|
workers_help = (
|
|
119
|
-
f"Max concurrent LLM requests (default: {_DEFAULT_WORKERS}
|
|
120
|
-
"
|
|
121
|
+
f"Max concurrent LLM requests (default: {_DEFAULT_WORKERS}; for init, "
|
|
122
|
+
"the backend may tune this default). Pool is auto-capped at "
|
|
123
|
+
"min(workers, file_count). Lower if your provider "
|
|
121
124
|
"key has tight rate limits or your machine has limited file descriptors."
|
|
122
125
|
)
|
|
123
126
|
|
|
@@ -147,7 +150,11 @@ def main() -> None:
|
|
|
147
150
|
)
|
|
148
151
|
p_init.add_argument("--languages", default=None, help=lang_help)
|
|
149
152
|
p_init.add_argument("--model", default=_DEFAULT_BUILD_MODEL, help=build_model_help)
|
|
150
|
-
|
|
153
|
+
# default=None, not _DEFAULT_WORKERS: cmd_init must be able to tell an
|
|
154
|
+
# explicit --workers (always wins) from "unset" (backend init_workers may
|
|
155
|
+
# tune it; else the daemon-side default of 128 applies). update keeps the
|
|
156
|
+
# literal default — the backend knob is init-only by design.
|
|
157
|
+
p_init.add_argument("--workers", type=int, default=None, help=workers_help)
|
|
151
158
|
p_init.add_argument(
|
|
152
159
|
"--allow-dump",
|
|
153
160
|
action="store_true",
|
|
@@ -281,6 +288,15 @@ def main() -> None:
|
|
|
281
288
|
help="Prompt mode: 'implement' (feature work, default) or 'qa' (read-only question answering).")
|
|
282
289
|
p_search.add_argument("--output", default=None, help="Write the roadmap to this path instead of the default INDEX_DIR/sourceindex-output-<pid>-<nonce>.txt (unique per invocation, so concurrent searches never clobber each other). Use it when a caller needs a predictable path — e.g. the sourceindex-bare eval variant points this at its own scratch dir.")
|
|
283
290
|
|
|
291
|
+
p_serve = sub.add_parser(
|
|
292
|
+
"serve",
|
|
293
|
+
help="Start the MCP stdio server used by Codex (registered in "
|
|
294
|
+
".codex/config.toml by `sourceindex init codex`).",
|
|
295
|
+
parents=[log_parent],
|
|
296
|
+
)
|
|
297
|
+
p_serve.add_argument("--repo-root", default=".", help="Repository root (default: .)")
|
|
298
|
+
p_serve.add_argument("--index-dir", default=None, help="Index directory (default: REPO_ROOT/.sourceindex)")
|
|
299
|
+
|
|
284
300
|
sub.add_parser(
|
|
285
301
|
"report-savings",
|
|
286
302
|
help="Claude Code Stop-hook entry point: reads payload JSON from stdin and persists the per-session savings ledger.",
|
|
@@ -347,7 +363,7 @@ def main() -> None:
|
|
|
347
363
|
# `log` is intentionally excluded — it's a read-only viewer over the
|
|
348
364
|
# log file, and recording each invocation pollutes the file it's
|
|
349
365
|
# about to print.
|
|
350
|
-
if args.command in ("init", "update", "search", "install-hooks", "dump", "daemon", "deinit", "api-key"):
|
|
366
|
+
if args.command in ("init", "update", "search", "serve", "install-hooks", "dump", "daemon", "deinit", "api-key"):
|
|
351
367
|
get_logger(__name__).debug(
|
|
352
368
|
"CLI invocation",
|
|
353
369
|
extra={
|
|
@@ -366,6 +382,8 @@ def main() -> None:
|
|
|
366
382
|
cmd_install_hooks(args)
|
|
367
383
|
elif args.command == "search":
|
|
368
384
|
cmd_search(args)
|
|
385
|
+
elif args.command == "serve":
|
|
386
|
+
cmd_serve(args)
|
|
369
387
|
elif args.command == "report-savings":
|
|
370
388
|
cmd_report_savings(args)
|
|
371
389
|
elif args.command == "statusline":
|
|
@@ -32,6 +32,7 @@ from .install import (
|
|
|
32
32
|
_detect_agents,
|
|
33
33
|
_ensure_gitignored,
|
|
34
34
|
_install_hooks,
|
|
35
|
+
_remove_codex_mcp_config,
|
|
35
36
|
)
|
|
36
37
|
from .upgrade import schedule_auto_upgrade
|
|
37
38
|
|
|
@@ -127,7 +128,13 @@ def cmd_init(args: argparse.Namespace) -> None:
|
|
|
127
128
|
_persist_global_api_key(api_key)
|
|
128
129
|
_ensure_gitignored(repo_root)
|
|
129
130
|
|
|
130
|
-
|
|
131
|
+
remote = apply_remote_config(index_dir=index_dir, default_model=args.model)
|
|
132
|
+
model = remote.build
|
|
133
|
+
# Explicit --workers always wins, then the backend's init_workers; None
|
|
134
|
+
# defers to the daemon-side default (128). `is not None` rather than `or`
|
|
135
|
+
# so an explicit --workers 0 keeps today's behavior (0 -> 128 downstream
|
|
136
|
+
# via `workers or REALTIME_MAX_WORKERS`).
|
|
137
|
+
workers = args.workers if args.workers is not None else remote.init_workers
|
|
131
138
|
|
|
132
139
|
_log.info("Installing git hooks")
|
|
133
140
|
_install_hooks(repo_root)
|
|
@@ -177,12 +184,40 @@ def cmd_init(args: argparse.Namespace) -> None:
|
|
|
177
184
|
_mirror_daemon_progress(idx.repo_hash):
|
|
178
185
|
result = client.init(
|
|
179
186
|
api_key=api_key, model=model,
|
|
180
|
-
languages=lang_strings, workers=
|
|
187
|
+
languages=lang_strings, workers=workers,
|
|
181
188
|
)
|
|
182
189
|
_log.info(
|
|
183
190
|
f"Index written to {index_dir}",
|
|
184
191
|
extra={"event": "init.done", "index_dir": str(index_dir), **result},
|
|
185
192
|
)
|
|
193
|
+
_exit_on_index_failures(result, command="init")
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def _exit_on_index_failures(result: dict, *, command: str) -> None:
|
|
197
|
+
"""Surface per-file LLM failures on the console. The daemon logs them,
|
|
198
|
+
but its log never reaches the terminal — without this a fully-failed
|
|
199
|
+
build still printed only success lines and exited 0."""
|
|
200
|
+
failed = int(result.get("files_failed") or 0)
|
|
201
|
+
if not failed:
|
|
202
|
+
return
|
|
203
|
+
# init's files_indexed counts attempts (cache misses); update's counts
|
|
204
|
+
# successes — both schemas predate files_failed and are read by
|
|
205
|
+
# eval_summarize.py, so normalize here instead of changing them.
|
|
206
|
+
attempted = int(result.get("files_indexed") or 0)
|
|
207
|
+
if command == "update":
|
|
208
|
+
attempted += failed
|
|
209
|
+
_log.error(
|
|
210
|
+
f"{failed} of {attempted} files failed to index; they will be "
|
|
211
|
+
"retried on the next update. Check the model and API key if this "
|
|
212
|
+
"persists (see the log in the index directory for details).",
|
|
213
|
+
extra={
|
|
214
|
+
"event": f"{command}.files_failed",
|
|
215
|
+
"files_failed": failed,
|
|
216
|
+
"files_attempted": attempted,
|
|
217
|
+
},
|
|
218
|
+
)
|
|
219
|
+
if failed >= attempted:
|
|
220
|
+
raise SystemExit(1)
|
|
186
221
|
|
|
187
222
|
|
|
188
223
|
def cmd_install_hooks(args: argparse.Namespace) -> None:
|
|
@@ -222,11 +257,13 @@ def cmd_update(args: argparse.Namespace) -> None:
|
|
|
222
257
|
f"Index written to {index_dir}",
|
|
223
258
|
extra={"event": "init.done", "index_dir": str(index_dir), **result},
|
|
224
259
|
)
|
|
260
|
+
_exit_on_index_failures(result, command="init")
|
|
225
261
|
else:
|
|
226
|
-
client.update(
|
|
262
|
+
result = client.update(
|
|
227
263
|
api_key=api_key, model=model,
|
|
228
264
|
languages=lang_strings, workers=args.workers,
|
|
229
265
|
)
|
|
266
|
+
_exit_on_index_failures(result or {}, command="update")
|
|
230
267
|
|
|
231
268
|
|
|
232
269
|
def _clear_local_api_key_override(repo_root: Path) -> None:
|
|
@@ -302,6 +339,19 @@ def cmd_api_key_set(args: argparse.Namespace) -> None:
|
|
|
302
339
|
_persist_api_key(idx.path, api_key)
|
|
303
340
|
|
|
304
341
|
|
|
342
|
+
def cmd_serve(args: argparse.Namespace) -> None:
|
|
343
|
+
"""Long-lived MCP stdio server (the Codex delivery shape).
|
|
344
|
+
|
|
345
|
+
schedule_auto_upgrade registers on atexit, so it fires when the Codex
|
|
346
|
+
session ends — codex-only users never run `search`/`update`, making this
|
|
347
|
+
their only auto-upgrade ride-along.
|
|
348
|
+
"""
|
|
349
|
+
from ..server import run_server
|
|
350
|
+
|
|
351
|
+
schedule_auto_upgrade()
|
|
352
|
+
run_server(Path(args.repo_root).resolve(), args.index_dir)
|
|
353
|
+
|
|
354
|
+
|
|
305
355
|
ROADMAP_FILENAME_PREFIX = "sourceindex-output"
|
|
306
356
|
|
|
307
357
|
# Roadmaps are read immediately after the completion signal prints; anything
|
|
@@ -508,6 +558,9 @@ def _deinit_one(repo_root: Path, repo_hash: str) -> dict:
|
|
|
508
558
|
daemon_stopped = lifecycle.stop_daemon(repo_root)
|
|
509
559
|
delete_key(repo_hash)
|
|
510
560
|
lifecycle.cleanup_stale_files(repo_hash)
|
|
561
|
+
# The codex MCP registration is not inert once the index is gone — it
|
|
562
|
+
# spawns a failing `sourceindex serve` at every Codex session start.
|
|
563
|
+
_remove_codex_mcp_config(repo_root)
|
|
511
564
|
index_removed = False
|
|
512
565
|
idx_path = IndexDir.for_repo(repo_root).path
|
|
513
566
|
if idx_path.exists():
|